262. **Set the environment variable:**
27 - In your Val Town environment, set `VALTOWN_API_TOKEN` to your API token
28 - The app will automatically fetch and display your vals
29
303. **Access the inspector:**
48 ];
49 }
50 let tone = await fetch('https://www.joshbeckman.org/llms/prompts/tone.txt').then(res => res.text());
51 let system = `You are a helpful assistant that provides feedback on blog posts.\n${tone}`;
52 console.log(new Date().toISOString(), "calling for messages");
13 const url = `https://api.coingecko.com/api/v3/coins/markets`
14 + `?vs_currency=aud&ids=${ids}&sparkline=true`;
15 const coins = await fetch(url, { headers: { "x-cg-demo-api-key": CG } }).then(r => r.json());
16
17 coins.forEach((c: any) => {
23
24 /* 2 â–¸ Stocks + FX via Google Sheet ------------------------------ */
25 const csv = await fetch(SHEET).then(r => r.text());
26 csv.trim().split("\n").slice(1).forEach(line => {
27 let [sym, last, vsLow] = line.split(",").map(s => s.trim());
10 + `/market_chart?vs_currency=aud&days=365&interval=daily`;
11
12 const j = await fetch(url).then(r => r.json());
13 const series = Array.isArray(j.prices) ? j.prices : [];
14
11import {Hono} from "npm:hono"
12import {cors} from "npm:hono/cors"
13import {toFetchResponse, toReqRes} from "npm:fetch-to-node"
14import {registerPromptsTools, registerTools} from "./registerTools.ts"
15import {loadConfig} from "./config.ts"
94 })
95
96 // Convert Node.js response back to Fetch response
97 return toFetchResponse(res)
98
99 } catch (error) {
113
114
115export default app.fetch
12
13 // check the boolean to see if a Glancer has enabled the link to start a cobrowsing session
14 const resp = await fetch("/api/cobrowse/" + window.__DEMO_ID__, {
15 method: "GET",
16 headers: {
77```
78
795. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
80```ts
81const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
82```
83
206
207 // Inject data to avoid extra round-trips
208 const initialData = await fetchInitialData();
209 const dataScript = `<script>
210 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
264
2655. **API Design:**
266 - `fetch` handler is the entry point for HTTP vals
267 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
268 - Properly handle CORS if needed for external access
269
230
231 // Inject data to avoid extra round-trips
232 const initialData = await fetchInitialData();
233 const dataScript = `<script>
234 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
277
2785. **API Design:**
279 - `fetch` handler is the entry point for HTTP vals
280 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
281
282## Val Town MCP Tools
155 * The main App component is rendered on the client.
156 * No server-side-specific code should be included in the App.
157 * Use fetch to communicate with the backend server portion.
158 */
159function App() {
178 * Server-only code
179 * Any code that is meant to run on the server should be included in the server function.
180 * This can include endpoints that the client side component can send fetch requests to.
181 */
182export default async function server(request: Request): Promise<Response> {
196 }
197
198 const response = await fetch(
199 `${config.apiBase}/v2/vals/${valId}/files/content${queryParams}`,
200 {