Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$2?q=function&page=43&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 31553 results for "function"(3944ms)

TracesStreamhttp.tsx1 match

@wolfβ€’Updated 3 days ago
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true });
3}

tuempresanew-file-7566.tsx1 match

@arequipeβ€’Updated 3 days ago
2import { sqlite } from "https://esm.town/v/std/sqlite";
3
4export default async function listSatCatalogTables() {
5 const BLOB_NAME = "sat-catalogs.db";
6 let responseMessage = "";

testindex.tsx8 matches

@paramunoβ€’Updated 3 days ago
3import "https://cdn.jsdelivr.net/npm/tweakpane@3.1.1/dist/tweakpane.min.js";
4
5// 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}
125
126function updateState(
127 name: string,
128 componentType: string,
203
204// Ensure parseData is defined only once
205function parseData(
206 componentType: string,
207 size: number,
329}
330
331function sendUpdatedTDState(
332 ws: WebSocket | null,
333 info: ProjectInfo,
347}
348
349function App() {
350 const [project, setProject] = useState<ProjectInfo>({});
351 const [projectSchema, setProjectSchema] = useState<ProjectSchema>({});
491 });
492
493 // Update state using functional updates to ensure latest state
494 setProject((prev) => ({ ...prev, [componentName]: info }));
495 setProjectSchema((prev) => ({ ...prev, [componentName]: schema }));
643
644// Val Town entry point
645export default function() {
646 return new Response(
647 render(<App />),

basic-html-starterscript.js1 match

@ashryanioβ€’Updated 3 days ago
14scene.add(butterfly);
15
16renderer.setAnimationLoop(function animate(time) {
17 renderer.render(scene, camera);
18 butterfly.rotation.y += 0.01;

web-gui-lmemmain.js5 matches

@paramunoβ€’Updated 3 days ago
16
17// Handles updating the state used for TD componenets
18function updateState(name, componentType, params, value, stateChanges) {
19 if (componentType === "XY") {
20 params[name + "x"][0] = value["x"];
89
90// retrieves data and ui settings for a provided element
91function parseData(componentType, size, info, par, name, useMinMax) {
92 let data = {};
93 let dataParams = {};
192
193// data
194function updateGui(schema, newInfo, componentName, params, useMinMax) {
195 for (const [key, val] of Object.entries(newInfo)) {
196 let componentTypes = projectTypes[componentName];
222}
223
224function initGUI(schema, info, componentName, params, expanded, useMinMax) {
225 if (componentName in project) return;
226 const f1 = pane.addFolder({
321}
322
323function sendUpdatedTDState(ws, info, componentName, pulse = []) {
324 ws.send(
325 JSON.stringify({

untitled-4599main.tsx1 match

@stevekrouseβ€’Updated 4 days ago
1export default async function(req: Request): Promise<Response> {
2 return Response.json({ ok: true });
3}

newsletter-to-feedmain.tsx1 match

@nbbaierβ€’Updated 4 days ago
1export default async function (e: Email) {
2 console.log(e);
3}

filterFeedslifeInStitches.tsx2 matches

@ljusβ€’Updated 4 days ago
3
4const videoFeed = "https://www.youtube.com/feeds/videos.xml?channel_id=UC3TpyhwXdKXh_TcBC27QQaw";
5export async function parseFeedFromUrl(url: string) {
6 const response = await fetch(url);
7 const xml = await response.text();
19}
20
21export async function getStitchesFeed() {
22 const result = await parseFeedFromUrl(videoFeed);
23 for (const entry of result.feed.entries) {
4
5- 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
20
21## Types of triggers
28
29```ts
30export default async function (req: Request) {
31 return new Response("Hello World");
32}
42
43```ts
44export default async function () {
45 // Scheduled task code
46}
56
57```ts
58export default async function (email: Email) {
59 // Process email
60}
66## Val Town Standard Libraries
67
68Val Town provides several hosted services and utility functions.
69
70### Blob Storage
123
124Message 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```
148
149## Val Town Utility Functions
150
151Val Town provides several utility functions to help with common project tasks.
152
153### 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```
250
253- 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
257 import { 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
290
291### AI/LLM Agent implementations
292
293Implement AI agent functionalities using LangGraph. To support multi-turn conversations, persist the graph state using Turso (Val Town’s SQLite).
294
295```ts
307
308// Persist & retrieve graph state
309async function loadState(sessionId: string) {
310 const rows = await sqlite.execute("SELECT state FROM sessions WHERE id = ?", [sessionId]);
311 return rows.length ? JSON.parse(rows[0].state) : null;
312}
313
314async function saveState(sessionId: string, state: any) {
315 const stateJson = JSON.stringify(state);
316 await sqlite.execute("INSERT OR REPLACE INTO sessions(id, state) VALUES (?, ?)", [sessionId, stateJson]);
325
326// Entry point
327export default async function (req: Request) {
328 const { sessionId = uuid(), message } = await req.json();
329 const graph = createGraph();

bluesky-jaws-1975main.tsx6 matches

@cheersderekβ€’Updated 4 days ago
12
13// load bluesky session
14async function getBlueskySession() {
15 // let data = fs.readFileSync('./data/session.json', 'utf8');
16 const app_vars = await turso.execute("SELECT * FROM film_script_bots WHERE bot_name = ? LIMIT 1", [
26
27// save bluesky session
28async function saveBlueskySession(data) {
29 data = JSON.stringify(data);
30 // fs.writeFileSync('./data/session.json', data);
36
37// load last track
38async function getNextLine() {
39 // let rawdata = fs.readFileSync('./data/latest.txt', 'utf8');
40 const app_vars = await turso.execute("SELECT * FROM film_script_bots WHERE bot_name = ? LIMIT 1", [
49
50// save last track
51async function saveNextLine(data) {
52 // fs.writeFileSync('./data/latest.txt', data);
53 const 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) {
62 console.log(text);
63
118}
119
120async function do_next_line() {
121 // script file
122 let script_file = process.env.MOVIE_SCRIPT_FILE;
tuna

tuna9 file matches

@jxnblkβ€’Updated 2 weeks ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouserβ€’Updated 2 months ago
A helper function to build a file's email
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.