9);
10
11async function loader({ bearerToken }: { bearerToken: string }) {
12 const data = await (await fetch("/api/projects-loader", {
13 headers: {
18}
19
20export function Projects({ bearerToken, setProject }: { bearerToken: string; setProject: any }) {
21 const [loaderData, setLoaderData] = useState<any>();
22 const [isLoading, setIsLoading] = useState<boolean>(true);
2import React, { useEffect, useState } from "https://esm.sh/react@18.2.0?dev";
3
4export function CreateProjectModal({
5 isOpen,
6 onClose,
14}
15
16export function Layout({ title, post, children }: LayoutProps) {
17 return (
18 <html lang="en">
3import React, { useEffect, useState } from "https://esm.sh/react@18.2.0";
4
5function App() {
6 const [longUrl, setLongUrl] = useState("");
7 const [shortUrls, setShortUrls] = useState([]);
60}
61
62function client() {
63 createRoot(document.getElementById("root")).render(<App />);
64}
65if (typeof document !== "undefined") { client(); }
66
67export default async function server(request: Request): Promise<Response> {
68 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
69 const SCHEMA_VERSION = 1;
141}
142
143function generateShortCode() {
144 const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
145 let result = "";
31 <h3 className="font-medium">Data Loading</h3>
32 <p className="text-gray-700">
33 React Router 7 provides improved data loading capabilities with loader functions.
34 </p>
35 </div>
38 <h3 className="font-medium">Form Handling</h3>
39 <p className="text-gray-700">
40 Enhanced form handling with action functions for form submissions.
41 </p>
42 </div>
109};
110
111export function Chat({
112 project,
113 bearerToken,
199 const toolCalls = message.toolCalls || [];
200 for (const toolCall of toolCalls) {
201 if (toolCall.type === "function" &&
202 toolCall.function?.name === "str_replace_editor" &&
203 toolCall.function?.output) {
204 try {
205 // Try to parse the output as JSON
206 const output = typeof toolCall.function.output === 'string'
207 ? JSON.parse(toolCall.function.output)
208 : toolCall.function.output;
209
210 // If the output contains a modifiedFile property, update the lastModifiedFile state
252 // Custom stop handler that also handles UI elements (timer and spinner)
253 const handleStop = React.useCallback(() => {
254 // Call the original stop function
255 stop();
256
271 }, [stop, pendingMessageId, soundEnabled]);
272
273 // Update the custom stop function ref when the dependencies change
274 React.useEffect(() => {
275 customStopRef.current = handleStop;
290 }, [running]);
291
292 // Function to handle reverting changes
293 const handleRevert = async () => {
294 if (!lastModifiedFile || isReverting) return;
4 * @returns A random alphanumeric string
5 */
6export function generateShortCode(length: number = 6): string {
7 const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
8 let result = '';
34 * @returns Formatted date string
35 */
36export function formatDate(dateString: string | null): string {
37 if (!dateString) return 'Never';
38
60 * @returns Truncated string with ellipsis if needed
61 */
62export function truncate(str: string, maxLength: number = 50): string {
63 if (str.length <= maxLength) return str;
64 return str.substring(0, maxLength - 3) + '...';
17
18// Create the database table
19export async function createTable(): Promise<void> {
20 await sqlite.execute(`
21 CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
37
38// Save a new URL
39export async function saveUrl(shortCode: string, originalUrl: string): Promise<void> {
40 const now = new Date().toISOString();
41
48
49// Get the original URL for a short code and increment visit count
50export async function getOriginalUrl(shortCode: string): Promise<string | null> {
51 // First, get the original URL
52 const result = await sqlite.execute(
72
73// Get stats for a URL
74export async function getUrlStats(shortCode: string): Promise<UrlRecord | null> {
75 const result = await sqlite.execute(
76 `SELECT
94
95// List all URLs with pagination
96export async function listUrls(limit: number = 10, offset: number = 0): Promise<UrlRecord[]> {
97 const result = await sqlite.execute(
98 `SELECT
177
178// For HTTP vals, render the component
179export default function() {
180 const html = `
181<!DOCTYPE html>
6import { Projects } from "./Projects.tsx";
7
8function safeParse(s: string) {
9 try {
10 return JSON.parse(s);
14}
15
16export function App() {
17 const [bearerToken, setBearerToken] = useLocalStorage("bearer", "");
18 const [anthropicApiKey, setAnthropicApiKey] = useLocalStorage("anthropic_api_key", "");
20 const [project, setProject_] = useState(safeParse(projectJSON));
21
22 function setProject(p: any) {
23 setProject_(p);
24 setProjectJSON(JSON.stringify(p));
25 }
26
27 function handleLogout() {
28 setBearerToken("");
29 // Keep the anthropic API key in case the user wants to reuse it