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/$%7BsvgDataUrl%7D?q=function&page=36&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 31479 results for "function"(4277ms)

web-gui-lmemmain.js5 matches

@paramunoβ€’Updated 2 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 2 days ago
1export default async function(req: Request): Promise<Response> {
2 return Response.json({ ok: true });
3}

newsletter-to-feedmain.tsx1 match

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

filterFeedslifeInStitches.tsx2 matches

@ljusβ€’Updated 2 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 2 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;
1import { sqlite } from "https://esm.town/v/std/sqlite?v=6";
2
3export async function ensureGlobalRateLimitTableExists(tableName: string) {
4 console.debug(`Ensuring table ${tableName} exists`);
5 await sqlite.execute({

vtEditorFiles-fixvaltown.mdc12 matches

@nbbaierβ€’Updated 2 days ago
9
10- Ask clarifying questions when requirements are ambiguous
11- Provide complete, functional solutions rather than skeleton implementations
12- Test your logic against edge cases before presenting the final solution
13- Ensure all code follows Val Town's specific platform requirements
22- **Never bake in secrets into the code** - always use environment variables
23- Include comments explaining complex logic (avoid commenting obvious operations)
24- Follow modern ES6+ conventions and functional programming practices if possible
25
26## Types of triggers
33
34```ts
35export default async function (req: Request) {
36 return new Response("Hello World");
37}
45
46```ts
47export default async function () {
48 // Scheduled task code
49}
57
58```ts
59export default async function (email: Email) {
60 // Process email
61}
65## Val Town Standard Libraries
66
67Val Town provides several hosted services and utility functions.
68
69### Blob Storage
119```
120
121## Val Town Utility Functions
122
123Val Town provides several utility functions to help with common project tasks.
124
125### Importing Utilities
181β”‚ β”œβ”€β”€ database/
182β”‚ β”‚ β”œβ”€β”€ migrations.ts # Schema definitions
183β”‚ β”‚ β”œβ”€β”€ queries.ts # DB query functions
184β”‚ β”‚ └── README.md
185β”‚ └── routes/ # Route modules
200└── shared/
201 β”œβ”€β”€ README.md
202 └── utils.ts # Shared types and functions
203```
204
208- Main entry point should be `backend/index.ts`
209- Do NOT use Hono serveStatic middleware
210- **Static asset serving:** Use the utility functions to read and serve project files:
211 ```ts
212 import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
242- Run migrations on startup or comment out for performance
243- Change table names when modifying schemas rather than altering
244- Export clear query functions with proper TypeScript typing
245
246## Common Gotchas and Solutions

blobcheckmain.tsx1 match

@arequipeβ€’Updated 2 days ago
1export default async function(request: Request): Promise<Response> {
2 const BLOB_NAME = "sat-catalogs.db";
3

GIthubProfileindex.tsx1 match

@anand_gβ€’Updated 2 days ago
60}
61
62// Utility functions
63const formatDate = (dateString: string): string => {
64 return new Date(dateString).toLocaleDateString('en-US', {
tuna

tuna9 file matches

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

getFileEmail4 file matches

@shouserβ€’Updated 1 month 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.