212});
213
214export default app.fetch;
21
22// This is the entry point for HTTP vals
23export default app.fetch;
24
1import { makeChangeValTypeTool } from "./change-val-type.ts";
2import { makeFetchTool } from "./fetch.ts";
3import { makeTextEditorTool } from "./text-editor.ts";
4import { thinkTool } from "./think.ts";
7 makeTextEditorTool,
8 makeChangeValTypeTool,
9 makeFetchTool,
10 thinkTool
11};
11 * Creates a tool for making HTTP requests to vals in a Val Town project
12 */
13export const makeFetchTool = (
14 { bearerToken, project, branch_id }: { bearerToken?: string; project?: any; branch_id?: string } = {},
15) =>
16 tool({
17 name: "fetch",
18 description: "Make an HTTP request to a Val Town val and return the response. Useful for testing HTTP vals.",
19 parameters: z.object({
68 return {
69 type: "error",
70 message: `Error fetching val at path '${valPath}': ${error.message}`,
71 };
72 }
83 return {
84 type: "error",
85 message: `The val at path '${valPath}' is not an HTTP val. Only HTTP vals can be called with fetch.`,
86 };
87 }
111 let response;
112 try {
113 response = await fetch(valEndpoint + urlPath, options);
114 } catch (error: any) {
115 // Return error information
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
49 files={project.data?.files}
50 branchId={branchId}
51 refetch={project.refetch}
52 />
53 </ProjectContext>
59 files,
60 branchId,
61 refetch,
62}: {
63 project: any;
64 files: any[];
65 branchId: string;
66 refetch: () => void;
67}) {
68 const [images, setImages] = useState<(string|null)[]>([]);
94 if (!messages?.length) return;
95 let last = messages.at(-1);
96 if (shouldRefetch(last)) {
97 refetch();
98 }
99 }, [messages]);
194}
195
196function shouldRefetch (message) {
197 for (let i = 0; i < message?.parts?.length; i++) {
198 let part = message.parts[i];
32 return;
33 }
34 branches.refetch();
35 if (res?.branch?.id) {
36 navigate(`/chat/${projectId}/branch/${res.branch.id}`);
1import { fetchAndPostCommits } from "./process-commits.tsx";
2
3/**
10 if (lastRunAt instanceof Date && lastRunAt.getTime() <= now.getTime()) {
11 const sinceTimestamp = lastRunAt.toISOString();
12 await fetchAndPostCommits(sinceTimestamp, untilTimestamp);
13 } else {
14 console.log("Skipped commit fetching: No valid or previous lastRunAt.");
15 }
16}
42 });
43
44 // Fetch weather data for map points
45 fetchMapWeatherData();
46
47 return () => {
189 }, [onLocationSelect]);
190
191 const fetchMapWeatherData = async () => {
192 try {
193 setLoading(true);
194 const response = await fetch('/api/weather/map');
195 if (response.ok) {
196 const data = await response.json();
198 }
199 } catch (error) {
200 console.error('Failed to fetch map weather data:', error);
201 } finally {
202 setLoading(false);
320 const setTimeout = undefined;
321 const setInterval = undefined;
322 const fetch = undefined;
323 const XMLHttpRequest = undefined;
324