TracesStreamhttp.tsx1 match
1export default async function (req: Request): Promise<Response> {
2return Response.json({ ok: true });
3}
tuempresanew-file-7566.tsx1 match
2import { sqlite } from "https://esm.town/v/std/sqlite";
34export default async function listSatCatalogTables() {
5const BLOB_NAME = "sat-catalogs.db";
6let responseMessage = "";
3import "https://cdn.jsdelivr.net/npm/tweakpane@3.1.1/dist/tweakpane.min.js";
45// Revert to separate imports for core Preact functions and hooks,
6// AND try a slightly older, known-stable Preact version (10.15.1).
7import { render } from "https://esm.sh/preact@10.15.1";
18// For now, let's just make sure the Tweakpane specific styles are still applied.
19// You might need to serve style.css as a separate file in your Val Town project
20// or embed it using a <style> tag in the render function.
21const TWEAKPANE_CSS = `
22.tp-dfwv {
124}
125126function updateState(
127name: string,
128componentType: string,
203204// Ensure parseData is defined only once
205function parseData(
206componentType: string,
207size: number,
329}
330331function sendUpdatedTDState(
332ws: WebSocket | null,
333info: ProjectInfo,
347}
348349function App() {
350const [project, setProject] = useState<ProjectInfo>({});
351const [projectSchema, setProjectSchema] = useState<ProjectSchema>({});
491});
492493// Update state using functional updates to ensure latest state
494setProject((prev) => ({ ...prev, [componentName]: info }));
495setProjectSchema((prev) => ({ ...prev, [componentName]: schema }));
643644// Val Town entry point
645export default function() {
646return new Response(
647render(<App />),
basic-html-starterscript.js1 match
14scene.add(butterfly);
1516renderer.setAnimationLoop(function animate(time) {
17renderer.render(scene, camera);
18butterfly.rotation.y += 0.01;
web-gui-lmemmain.js5 matches
1617// Handles updating the state used for TD componenets
18function updateState(name, componentType, params, value, stateChanges) {
19if (componentType === "XY") {
20params[name + "x"][0] = value["x"];
8990// retrieves data and ui settings for a provided element
91function parseData(componentType, size, info, par, name, useMinMax) {
92let data = {};
93let dataParams = {};
192193// data
194function updateGui(schema, newInfo, componentName, params, useMinMax) {
195for (const [key, val] of Object.entries(newInfo)) {
196let componentTypes = projectTypes[componentName];
222}
223224function initGUI(schema, info, componentName, params, expanded, useMinMax) {
225if (componentName in project) return;
226const f1 = pane.addFolder({
321}
322323function sendUpdatedTDState(ws, info, componentName, pulse = []) {
324ws.send(
325JSON.stringify({
untitled-4599main.tsx1 match
1export default async function(req: Request): Promise<Response> {
2return Response.json({ ok: true });
3}
newsletter-to-feedmain.tsx1 match
1export default async function (e: Email) {
2console.log(e);
3}
filterFeedslifeInStitches.tsx2 matches
34const videoFeed = "https://www.youtube.com/feeds/videos.xml?channel_id=UC3TpyhwXdKXh_TcBC27QQaw";
5export async function parseFeedFromUrl(url: string) {
6const response = await fetch(url);
7const xml = await response.text();
19}
2021export async function getStitchesFeed() {
22const result = await parseFeedFromUrl(videoFeed);
23for (const entry of result.feed.entries) {
45- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
2021## Types of triggers
2829```ts
30export default async function (req: Request) {
31return new Response("Hello World");
32}
4243```ts
44export default async function () {
45// Scheduled task code
46}
5657```ts
58export default async function (email: Email) {
59// Process email
60}
66## Val Town Standard Libraries
6768Val Town provides several hosted services and utility functions.
6970### Blob Storage
123124Message Type: Defines the structure for chat messages (role and content).
125ChatOpenAI(model: string): Factory function returning an object with an invoke(messages) method. This method sends an array of messages to the specified OpenAI chat model and returns the assistant's response.
126GlobalRateLimitedChatOpenAI(model: string, requestsPerSecond: number): Decorator for ChatOpenAI that enforces a global rate limit (requests per second) using a persistent SQLite table.
127GlobalRateLimiter: Class that implements the rate limiting logic. It checks the number of requests in the current time window and throws an error if the limit is exceeded. It uses a table (global_rate_limit_1) in Val Town's SQLite.
147```
148149## Val Town Utility Functions
150151Val Town provides several utility functions to help with common project tasks.
152153### Importing Utilities
227β βββ database/
228β β βββ migrations.ts # Schema definitions
229β β βββ queries.ts # DB query functions
230β β βββ README.md
231β βββ routes/ # Route modules
246βββ shared/
247βββ README.md
248βββ utils.ts # Shared types and functions
249```
250253- Hono is the recommended API framework
254- Main entry point should be `backend/index.ts`
255- **Static asset serving:** Use the utility functions to read and serve project files:
256```ts
257import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
287- Run migrations on startup or comment out for performance
288- Change table names when modifying schemas rather than altering
289- Export clear query functions with proper TypeScript typing
290291### AI/LLM Agent implementations
292293Implement AI agent functionalities using LangGraph. To support multi-turn conversations, persist the graph state using Turso (Val Townβs SQLite).
294295```ts
307308// Persist & retrieve graph state
309async function loadState(sessionId: string) {
310const rows = await sqlite.execute("SELECT state FROM sessions WHERE id = ?", [sessionId]);
311return rows.length ? JSON.parse(rows[0].state) : null;
312}
313314async function saveState(sessionId: string, state: any) {
315const stateJson = JSON.stringify(state);
316await sqlite.execute("INSERT OR REPLACE INTO sessions(id, state) VALUES (?, ?)", [sessionId, stateJson]);
325326// Entry point
327export default async function (req: Request) {
328const { sessionId = uuid(), message } = await req.json();
329const graph = createGraph();
bluesky-jaws-1975main.tsx6 matches
1213// load bluesky session
14async function getBlueskySession() {
15// let data = fs.readFileSync('./data/session.json', 'utf8');
16const app_vars = await turso.execute("SELECT * FROM film_script_bots WHERE bot_name = ? LIMIT 1", [
2627// save bluesky session
28async function saveBlueskySession(data) {
29data = JSON.stringify(data);
30// fs.writeFileSync('./data/session.json', data);
3637// load last track
38async function getNextLine() {
39// let rawdata = fs.readFileSync('./data/latest.txt', 'utf8');
40const app_vars = await turso.execute("SELECT * FROM film_script_bots WHERE bot_name = ? LIMIT 1", [
4950// save last track
51async function saveNextLine(data) {
52// fs.writeFileSync('./data/latest.txt', data);
53const app_vars = await turso.execute("UPDATE film_script_bots SET next_line = ? WHERE bot_name = ?", [
59// bluesky rate limits
60// https://atproto.com/blog/rate-limits-pds-v3
61async function sendPost(text) {
62console.log(text);
63118}
119120async function do_next_line() {
121// script file
122let script_file = process.env.MOVIE_SCRIPT_FILE;