136 let type_: "file" | "http" | "script";
137 if (path.includes("backend/index.ts")) type_ = "http";
138 if (file_text?.includes("export default app.fetch")) type_ = "http";
139 if ([".ts", ".tsx", ".js", ".jsx"].some(ext => path.endsWith(ext))) {
140 type_ = "script";
234
235 // Inject data to avoid extra round-trips
236 const initialData = await fetchInitialData();
237 const dataScript = `<script>
238 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
281
2825. **API Design:**
283 - `fetch` handler is the entry point for HTTP vals
284 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
285
2866. **Hono Peculiarities:**
106 }
107
108 // If there are selected files, fetch their content and add them to the messages
109 if (selectedFiles && selectedFiles.length > 0) {
110 const vt = new ValTown({ bearerToken });
126 fileContents += `## File: ${filePath}\n\`\`\`\n${fileWithLinesNumbers(content)}\n\`\`\`\n\n`;
127 } catch (error) {
128 console.error(`Error fetching file ${filePath}:`, error);
129 fileContents += `## File: ${filePath}\nError: Could not fetch file content\n\n`;
130 }
131 }
56 row.parentNode.insertBefore(newRow, row.nextSibling);
57
58 // Fetch the inference calls data
59 fetch('/api/inference-calls?usage_id=' + usageId)
60 .then(response => response.json())
61 .then(data => {
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});
205});
206
207export default app.fetch;
208
21
22// This is the entry point for HTTP vals
23export default app.fetch;
24
239
240 // Inject data to avoid extra round-trips
241 const initialData = await fetchInitialData();
242 const dataScript = `<script>
243 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
286
2875. **API Design:**
288 - `fetch` handler is the entry point for HTTP vals
289 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
290
291
44 files={project.data?.files}
45 branchId={branchId}
46 refetch={project.refetch}
47 />
48 </>
54 files,
55 branchId,
56 refetch,
57}: {
58 project: any;
59 files: any[];
60 branchId: string;
61 refetch: () => void;
62}) {
63 const [images, setImages] = useState<(string | null)[]>([]);
88 if (!messages?.length) return;
89 let last = messages.at(-1);
90 if (shouldRefetch(last)) {
91 refetch();
92 }
93 }, [messages]);
163}
164
165function shouldRefetch(message) {
166 for (let i = 0; i < message?.parts?.length; i++) {
167 let part = message.parts[i];
170 case "str_replace_editor":
171 if (part.toolInvocation?.args?.command === "create") {
172 // console.log("REFETCH (create)");
173 return true;
174 }
176 case "delete_file":
177 case "change_val_type":
178 // console.log("REFETCH (change type or delete)");
179 return true;
180 }