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/?q=function&page=1&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 29731 results for "function"(1848ms)

Upgrade to Deno728 words

https://docs.val.town/upgrading/upgrade-to-deno/
removed” Contact us if you need this functionality. Promises are not recursively resolved between functions. Section titled “Promises are not recursively resolved between functions” In the prior runtime, all values

Sections

User-defined functions can be synchronous 🥳

User-defined functions can be synchronous 🥳 Section titled “User-defined functions can be synchronous 🥳” In the old runtime, you would need to await the call to any @user.function. That is

setTimeout has been removed

setTimeout has been removed. Section titled “setTimeout has been removed” Contact us if you need this functionality.

Promises are not recursively resolved between functions

recursively resolved between functions. Section titled “Promises are not recursively resolved between functions” In the prior runtime, all values were recursively awaited. This means that if you returned an array

Cron evaluations has 0 arguments where it used to have 1

purple). This does not affect that fact that crons pass the Interval object to the function that has been scheduled, which allows you to get the lastRunAt value of the

Express to HTTP migration341 words

https://docs.val.town/troubleshooting/express-to-http-migration/
for the express versus HTTP types: // Express handler. export function handler(req, res) { res.send("Hello world"); } // HTTP handler. export function handler(req) { return new Response("Hello world"); } The

Sections

Parameters

for the express versus HTTP types: // Express handler. export function handler(req, res) { res.send("Hello world"); } // HTTP handler. export function handler(req) { return new Response("Hello world"); }

The response object

other details by chaining functions off of the response object, with the HTTP type, these are options you set for the Response object. // Express handler. export function handler(req, res)

The request object

string parameters, will require different code: // Express handler. export function handler(req, res) { res.send(req.query.name); } // HTTP handler. export function handler(req) { return new Response(new URL(req.url).searchParams.get("name")); }

Exports121 words

https://docs.val.town/troubleshooting/exports/
the function to run when that val is triggered. If your val has multiple exports, then we require one of them to the default export, which will be the function

Sections

Exports

the function to run when that val is triggered. If your val has multiple exports, then we require one of them to the default export, which will be the function

HTTP99 words

https://docs.val.town/vals/http/
Peko. These handlers need to export a function that takes a Request object as the first parameter and returns a Response object. The function can be asynchronous. Basic examples Routing

Sections

HTTP

Peko. These handlers need to export a function that takes a Request object as the first parameter and returns a Response object. The function can be asynchronous. Basic examples Routing

Save HTML form data386 words

https://docs.val.town/guides/save-html-form-data/
web browser, the server (your val function) gets sent a GET request. You can check the HTTP method using req.method and change how your val function responds. See Web forms

Sections

Create an HTTP trigger

Create an HTTP trigger. Section titled “Create an HTTP trigger” Write a val function that accepts a Request and returns a Response.

Host your form on Val Town

web browser, the server (your val function) gets sent a GET request. You can check the HTTP method using req.method and change how your val function responds. See Web forms

Early Return478 words

https://docs.val.town/vals/http/early-return/
set up a queue” In your early-returning HTTP file: early-returning.tsRun in Val Town ↗ async function handle(request: Request) { // Send off the relevant data a queue HTTP file. //

Sections

How to set up a queue

a queue” In your early-returning HTTP file: early-returning.tsRun in Val Town ↗ async function handle(request: Request) { // Send off the relevant data a queue HTTP file. // This `fetch`

Promises should otherwise be awaited

- besides this narrow use-case, errors that occur in promises won’t be properly handled and functions may run out-of-order. For example, if you use fetch to request some resource, but

Your first scheduled cron628 words

https://docs.val.town/quickstarts/first-cron/
The default code will look like this: weatherNotifier.ts export default async function (interval: Interval) { // your code… } This function will be run on a schedule. By default, this

Sections

Step 2: Set up a Cron Trigger

The default code will look like this: weatherNotifier.ts export default async function (interval: Interval) { // your code… } This function will be run on a schedule. By default, this

Step 3: Get the weather

Step 3Run in Val Town ↗ import { getWeather } from "https://esm.town/v/stevekrouse/getWeather"; export default async function (interval: Interval) { let weather = await getWeather("Brooklyn, NY"); console.log(weather.current_condition[0].FeelsLikeF); } Replace Brooklyn, NY

Step 4: Send yourself an email

import { email } from "https://esm.town/v/std/email"; import { getWeather } from "https://esm.town/v/stevekrouse/getWeather"; export default async function (interval: Interval) { let weather = await getWeather("Brooklyn, NY"); let feelsLike = weather.current_condition[0].FeelsLikeF; let

Next steps

updates to Discord. weather_forecast_in_the_morning - weather forecast on Telegram. weatherBot - OpenAI Weather Bot via function calling. aqi - email alerts when AQI is unhealthy near you. …add yours here!

Proxied fetch210 words

https://docs.val.town/std/fetch/
contains an alternative version, std/fetch, that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from std/fetch reroutes requests using a proxy vendor so that requests obtain

Sections

Proxied fetch

contains an alternative version, std/fetch, that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from std/fetch reroutes requests using a proxy vendor so that requests obtain

CORS387 words

https://docs.val.town/troubleshooting/cors/
Configuration. Section titled “Example: Custom CORS Configuration” Custom CorsRun in Val Town ↗ export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "https://specific-domain.com", "Access-Control-Allow-Methods": "GET,POST", }, });

Sections

Example: Custom CORS Configuration

Example: Custom CORS Configuration. Section titled “Example: Custom CORS Configuration” Custom CorsRun in Val Town ↗ export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "https://specific-domain.com", "Access-Control-Allow-Methods":

Example: Handling Preflight Requests

Example: Handling Preflight Requests. Section titled “Example: Handling Preflight Requests” For complete control over CORS behavior, you can handle OPTIONS requests explicitly: Handle Preflight Request export async function myEndpoint(req) {

Removing CORS Headers

we won’t add any custom CORS headers to your request. Remove CORS Headers export async function myEndpoint() { return new Response("Hello", { headers: { "Access-Control-Allow-Origin": "", // The minimum possible

Migrating Deprecated HTTP Vals557 words

https://docs.val.town/troubleshooting/migrating-deprecated-http-vals/
return a different random number on each request: const randomValue = Math.random(); export default async function (req: Request): Promise<Response> { return Response.json({ randomValue }); } Run in Val Town. Terminal

Sections

Accidentally re-using values.

return a different random number on each request: const randomValue = Math.random(); export default async function (req: Request): Promise<Response> { return Response.json({ randomValue }); } Run in Val Town. Terminal

Intentionally caching values for performance!

data fetching. const expensiveData = await fetchLargeDataset(); const cache = new Map(); export default async function (req: Request): Promise<Response> { const url = new URL(req.url); const key = url.searchParams.get("key"); if

Migration Checklist

be safely cached. Move variables that need to be unique per request inside the handler function. Consider opportunities to improve performance by intentionally caching expensive computations or initializations. Test your

YohhansMProfilemain.tsx2 matches

@pureheart•Updated 13 mins ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(
22 <p style='color: gray; text-align: center;'>Redirecting...</p>
23 \`;
24 setTimeout(function() {
25 window.location.href = "https://google.com";
26 }, 3000); // 3-second delay

workflowmain.tsx16 matches

@svc•Updated 16 mins ago
33 * Utility to create a standardized ACP object.
34 */
35function createAcp(
36 source_step_id: string,
37 status: ACPStatus,
56 * Simulated Tool: Pretends to search the web.
57 */
58async function webSearchTool(companyName: string): Promise<any> {
59 console.log(`TOOL: Searching for "${companyName}"...`);
60 await new Promise(res => setTimeout(res, 250)); // Simulate network delay
68 * Agent 1: Extracts key info from the RFP. (Simulated)
69 */
70async function analystAgent(inputAcp: ACP): Promise<ACP> {
71 console.log("AGENT: Analyst Agent running...");
72 const rfpText = inputAcp.payload.content as string;
83 * Agent 2: Uses a tool to research the company. (Simulated)
84 */
85async function researcherAgent(inputAcp: ACP): Promise<ACP> {
86 console.log("AGENT: Researcher Agent running...");
87 const companyName = inputAcp.payload.content.company_name;
93 * Agents 3, 4, 5: The collaborative writers. (Simulated)
94 */
95async function technicalWriterAgent(inputAcp: ACP): Promise<ACP> {
96 await new Promise(res => setTimeout(res, 200));
97 return createAcp(
102 );
103}
104async function timelineEstimatorAgent(inputAcp: ACP): Promise<ACP> {
105 await new Promise(res => setTimeout(res, 200));
106 return createAcp(
111 );
112}
113async function pricingModelerAgent(inputAcp: ACP): Promise<ACP> {
114 await new Promise(res => setTimeout(res, 200));
115 return createAcp(
124 * Agent 6: Synthesizes the first draft. (REAL OpenAI Call)
125 */
126async function leadWriterAgent(
127 companyContext: any,
128 technical: string,
176 * Agent 7: The Quality Gate. (Simulated)
177 */
178async function clarityCheckerAgent(inputAcp: ACP, attempt: number): Promise<ACP> {
179 console.log(`AGENT: Clarity Checker Agent running (Attempt #${attempt})...`);
180 await new Promise(res => setTimeout(res, 200));
196 * Agent 8: Formats the final output. (Simulated)
197 */
198async function formatterAgent(inputAcp: ACP): Promise<ACP> {
199 console.log("AGENT: Formatter Agent running...");
200 const text = inputAcp.payload.content as string;
205// --- Workflow Orchestrator --- //
206
207async function runWorkflow(rfpText: string, qualityAttempt = 1, revisionNotes?: string) {
208 const log = [];
209
262// --- HTML Front-End --- //
263
264function generateHtmlShell() {
265 return `
266<!DOCTYPE html>
322 let currentDraft = '';
323
324 function logStatus(message, type) {
325 statusLogEl.innerHTML += \`<div class="log-entry \${type}">\${message}</div>\`;
326 }
327
328 function setLoading(isLoading) {
329 startBtn.disabled = isLoading;
330 approveBtn.disabled = isLoading;
373 approveBtn.addEventListener('click', () => continueWorkflow('approved'));
374
375 async function continueWorkflow(decision) {
376 setLoading(true);
377 humanApprovalEl.style.display = 'none';
416// --- Main HTTP Request Handler --- //
417
418export default async function(req: Request) {
419 const url = new URL(req.url);
420 const action = url.searchParams.get("action");
tuna

tuna9 file matches

@jxnblk•Updated 4 days 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.