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";
103 }
104
105 // If there are selected files, fetch their content and add them to the messages
106 if (selectedFiles && selectedFiles.length > 0) {
107 const vt = new ValTown({ bearerToken });
123 fileContents += `## File: ${filePath}\n\`\`\`\n${fileWithLinesNumbers(content)}\n\`\`\`\n\n`;
124 } catch (error) {
125 console.error(`Error fetching file ${filePath}:`, error);
126 fileContents += `## File: ${filePath}\nError: Could not fetch file content\n\n`;
127 }
128 }
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});
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();
21
22// This is the entry point for HTTP vals
23export default app.fetch;
24
45 files={project.data?.files}
46 branchId={branchId}
47 refetch={project.refetch}
48 />
49 </>
55 files,
56 branchId,
57 refetch,
58}: {
59 project: any;
60 files: any[];
61 branchId: string;
62 refetch: () => void;
63}) {
64 const [images, setImages] = useState<(string|null)[]>([]);
89 if (!messages?.length) return;
90 let last = messages.at(-1);
91 if (shouldRefetch(last)) {
92 refetch();
93 }
94 }, [messages]);
173}
174
175function shouldRefetch (message) {
176 for (let i = 0; i < message?.parts?.length; i++) {
177 let part = message.parts[i];
180 case "str_replace_editor":
181 if (part.toolInvocation?.args?.command === "create") {
182 // console.log("REFETCH (create)");
183 return true;
184 }
186 case "delete_file":
187 case "change_val_type":
188 // console.log("REFETCH (change type or delete)");
189 return true;
190 }
37
38 try {
39 const response = await fetch("/submit", {
40 method: "POST",
41 headers: {
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({