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/image-url.jpg%20%22Optional%20title%22?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 40264 results for "function"(783ms)

untitled-1482main.ts1 match

@matthamlinโ€ขUpdated 58 mins ago
15
16// // Learn more: https://docs.val.town/vals/http/
17// export default async function (req: Request): Promise<Response> {
18// return app.fetch(req);
19// }
bible-mcp

bible-mcputils.ts2 matches

@cameronpakโ€ขUpdated 1 hour ago
101const BookSchema = z.enum(BIBLE_BOOKS);
102
103// Function to convert book names to API format
104function normalizeBookName(bookName: string): string {
105 // Simple mapping for common books - the API uses standard abbreviations
106 const bookMap: { [key: string]: string } = {
bible-mcp

bible-mcpAGENTS.md12 matches

@cameronpakโ€ขUpdated 1 hour ago
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
120```
121
122## Val Town Utility Functions
123
124Val Town provides several utility functions to help with common project tasks.
125
126### Importing Utilities
200โ”‚ โ”œโ”€โ”€ database/
201โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
202โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
203โ”‚ โ”‚ โ””โ”€โ”€ README.md
204โ”‚ โ””โ”€โ”€ routes/ # Route modules
219โ””โ”€โ”€ shared/
220 โ”œโ”€โ”€ README.md
221 โ””โ”€โ”€ utils.ts # Shared types and functions
222```
223
226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229 ```ts
230 import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263
264## Common Gotchas and Solutions

hello-realtimeutils.ts3 matches

@jplhomerโ€ขUpdated 1 hour ago
6
7// Builds the URL for a Realtime API endpoint.
8export function makeUrl(callId?: string, action?: string) {
9 let url = REALTIME_BASE_URL;
10 if (!callId) {
22
23// Builds the headers for a Realtime API endpoint.
24export function makeHeaders(contentType?: string) {
25 const obj: Record<string, string> = {
26 Authorization: `Bearer ${OPENAI_API_KEY}`,
31
32// Debug helper for printing Realtime API errors.
33export async function getErrorText(resp: Response) {
34 const errBody = await resp.text().catch(() => "<no body>");
35 return `${resp.status} ${resp.statusText}: ${errBody}`;

hello-realtimeobserver.ts1 match

@jplhomerโ€ขUpdated 1 hour ago
48 }
49 switch (message.type) {
50 case "response.function_call_arguments.done":
51 this.handler.onTool(message.name, message.arguments);
52 break;

hello-realtimeindex.html5 matches

@jplhomerโ€ขUpdated 1 hour ago
193 let callStartTime = null;
194
195 function formatTimestamp() {
196 if (!callStartTime) {
197 return "00:00.000";
208 }
209
210 function log(...args) {
211 const timestamp = formatTimestamp();
212 const message = args.map(
224 }
225
226 function setStatus(status, ledState = "disconnected") {
227 statusTextEl.textContent = status;
228 statusLedEl.className = `status-led ${ledState}`;
243 }
244
245 async function start() {
246 if (pc) {
247 // If already connected, this is a stop action
348 }
349
350 async function stop() {
351 log("Stopping voice agent connection");
352 setStatus("Disconnecting...", "connecting");

hello-realtimeagent.ts5 matches

@jplhomerโ€ขUpdated 1 hour ago
11 apologize and say you can't help with that.
12 When the user says goodbye or you think the call is over, say a brief goodbye and then
13 invoke the end_call function.
14 ---
15 Short summary:
34const VOICE = "marin";
35const HANGUP_TOOL = {
36 type: "function",
37 name: "end_call",
38 description: `
39 Use this function to hang up the call when the user says goodbye
40 or otherwise indicates they are about to end the call.`,
41};
42
43// Builds the declarative session configuration for a Realtime API session.
44export function makeSession() {
45 return {
46 type: "realtime",
104
105// Creates the runtime handler for the session.
106export function createHandler(client: ObserverClient, callId: string) {
107 return new AgentHandler(client, callId);
108}

SonarPost.tsx8 matches

@moeโ€ขUpdated 3 hours ago
10import { formatDateRelative, formatNumber, PaddedSpinner, Button } from './ui.tsx'
11
12export function Post({ cast, display = 'default', hideSeparator = false }) {
13 const navigate = useNavigate()
14
48}
49
50function PostMedia({ cast }) {
51 const images = cast.embeds?.filter((embed) => !!embed?.metadata?.image)
52 const videos = cast.embeds?.filter((embed) => !!embed?.metadata?.video)
105}
106
107function PostEmbeds({ cast }) {
108 const frames = cast.embeds?.filter((embed) => !!embed?.metadata?.frame)
109 const urls = cast.embeds?.filter((embed) => !!embed?.metadata?.html && !embed?.metadata?.frame)
144}
145
146function PostPostedFrom({ cast, display = 'default' }) {
147 if (display != 'expanded') return null
148 if (!cast) return null
151}
152
153function PostInteractions({ cast, display = 'default' }) {
154 const hideInteractions = ['quote', 'sub-comment', 'preview'].includes(display)
155 if (!cast || hideInteractions) return null
179}
180
181export function Feed({
182 queryKey,
183 queryFn,
221}
222
223function FeedItems({ feed, display, renderItem = undefined, containerClass = 'flex flex-col' }) {
224 if (renderItem) {
225 return <div className={containerClass}>{feed?.map((item) => renderItem(item))}</div>
245}
246
247export function SmallMediaPost({ cast }) {
248 const navigate = useNavigate()
249 const [isFullscreen, setIsFullscreen] = useState(false)

SonarMiniAppsScreen.tsx3 matches

@moeโ€ขUpdated 3 hours ago
8import { Feed } from '../components/Post.tsx'
9
10export function MiniAppsScreen() {
11 return (
12 <div>
22}
23
24function MiniAppsList() {
25 return (
26 <Feed
33}
34
35function MiniApp({ miniapp }) {
36 const { fcsdk, context } = useFarcasterMiniApp()
37

Sonarui.tsx16 matches

@moeโ€ขUpdated 3 hours ago
4import { NavLink, Outlet } from 'https://esm.sh/react-router@7'
5
6export function Section({ children, ...props }: any) {
7 const sectionClass = `p-5 rounded-3xl bg-neutral-400/15 ${props.className || ''}`
8 return (
98}
99
100// export function Input(props: any) {
101// const inputClass = "dark:bg-white dark:text-black bg-black text-white rounded-md px-3 py-1 ";
102// return <input class={inputClass} {...props} />;
103// }
104
105// export function Button(props: any) {
106// const buttonClass = "dark:bg-white dark:text-black bg-black text-white rounded-md px-3 py-1 ";
107// return <button class={buttonClass} {...props} />;
108// }
109
110export function Sheet({ children, showSheet, setShowSheet }: any) {
111 return (
112 <>
125}
126
127export function MonoButton(props: any) {
128 return (
129 <Button {...props}>
133}
134
135export function MonoButtonWithStatus(props: any) {
136 const [status, setStatus] = useState<any>()
137 const handleClick = async () => {
154}
155
156export function Separator({ className = '' }) {
157 return <div className={`border-b border-neutral-400/25 ${className}`}></div>
158}
159
160export function PaddedSpinner() {
161 return (
162 <div className="flex flex-row items-center justify-center p-4 opacity-50 h-32">
166}
167
168export function PaddedError({ message }) {
169 return (
170 <div className="flex flex-row items-center justify-center p-4 opacity-50 h-32">
174}
175
176export function StatsRows({ stats }) {
177 return (
178 <div className="flex flex-col ">
190}
191
192export function Debug({ title, data, className = '' }) {
193 return (
194 <div className={className}>
199}
200
201export function NavTabs({ navLinks }) {
202 return (
203 <>
222}
223
224export function NavOutlet({ navLinks }) {
225 return (
226 <>
235//////////
236
237export function formatJSON(json: any) {
238 return JSON.stringify(json, null, 2)
239}
263}
264
265export function BackButton() {
266 return <ArrowLeft className="w-5 h-5 m-2 cursor-pointer opacity-50" onClick={() => (window.location.href = '/')} />
267}
268
269export function ShareButton({ onClick }) {
270 return <Share className="w-5 h-5 m-2 cursor-pointer opacity-50" onClick={onClick} />
271}

ratelimit4 file matches

@unkeyโ€ขUpdated 1 month ago
Rate limit your serverless functions

discordWebhook2 file matches

@stevekrouseโ€ขUpdated 2 months ago
Helper function to send Discord messages
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.