233
234 // Inject data to avoid extra round-trips
235 const initialData = await fetchInitialData();
236 const dataScript = `<script>
237 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
280
2815. **API Design:**
282 - `fetch` handler is the entry point for HTTP vals
283 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
87 }
88
89 // If there are selected files, fetch their content and add them to the messages
90 if (selectedFiles && selectedFiles.length > 0) {
91 const vt = new ValTown({ bearerToken });
107 fileContents += `## File: ${filePath}\n\`\`\`\n${fileWithLinesNumbers(content)}\n\`\`\`\n\n`;
108 } catch (error) {
109 console.error(`Error fetching file ${filePath}:`, error);
110 fileContents += `## File: ${filePath}\nError: Could not fetch file content\n\n`;
111 }
112 }
30 return c.json({ files: files.data });
31 } catch (error) {
32 console.error("Error fetching project files:", error);
33 return Response.json({ error: "Failed to fetch project files" }, { status: 500 });
34 }
35});
21 return c.json({ branches: branches.data });
22 } catch (error) {
23 console.error("Error fetching branches:", error);
24 return Response.json({ error: "Failed to fetch branches" }, { status: 500 });
25 }
26});
4
5export function LayoutRoute () {
6 // TODO fetch here because we're not doing any caching
7 // and we want the user data in the header ?
8 // const projects = useProjects();
62});
63
64export default app.fetch;
65
21
22// This is the entry point for HTTP vals
23export default app.fetch;
24
46 files={project.data?.files}
47 branchId={branchId}
48 refetch={project.refetch}
49 />
50 </>
56 files,
57 branchId,
58 refetch,
59}: {
60 project: any;
61 files: any[];
62 branchId: string;
63 refetch: () => void;
64}) {
65 const { token, anthropicApiKey } = useAuth();
93 if (!messages?.length) return;
94 let last = messages.at(-1);
95 if (shouldRefetch(last)) {
96 refetch();
97 }
98 }, [messages]);
177}
178
179function shouldRefetch (message) {
180 for (let i = 0; i < message?.parts?.length; i++) {
181 let part = message.parts[i];
184 case "str_replace_editor":
185 if (part.toolInvocation?.args?.command === "create") {
186 // console.log("REFETCH (create)");
187 return true;
188 }
190 case "delete_file":
191 case "change_val_type":
192 // console.log("REFETCH (change type or delete)");
193 return true;
194 }
33 return;
34 }
35 branches.refetch();
36 if (res?.branch?.id) {
37 navigate(`/chat/${projectId}/branch/${res.branch.id}`);
10 files.append("uuid", uuid);
11 files.append("token", key);
12 const upload = await fetch(
13 `https://temptemp-workers.web.val.run/pushCode?uuid=${uuid}&token=${key}`,
14 {