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=75&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 23503 results for "function"(1599ms)

TownieuseChatLogic.ts1 match

@tsuchi_yaโ€ขUpdated 3 days ago
11}
12
13export function useChatLogic({
14 project,
15 branchId,

TownieuseBranches.tsx1 match

@tsuchi_yaโ€ขUpdated 3 days ago
3const ENDPOINT = "/api/project-branches";
4
5export function useBranches (projectId: string) {
6 const [data, setData] = useState<any>(null);
7 const [loading, setLoading] = useState(true);

Townietext-editor.ts1 match

@tsuchi_yaโ€ขUpdated 3 days ago
4import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
5
6function printFileType(file: any) {
7 if (file.type === "interval")
8 return " (cron)";

Towniesystem_prompt.txt12 matches

@tsuchi_yaโ€ขUpdated 3 days 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}
40
41```ts
42export default async function () {
43 // Scheduled task code
44}
52
53```ts
54export default async function (email: Email) {
55 // Process email
56}
60## Val Town Standard Libraries
61
62Val Town provides several hosted services and utility functions.
63
64### Blob Storage
114```
115
116## Val Town Utility Functions
117
118Val Town provides several utility functions to help with common project tasks.
119
120### Importing Utilities
176โ”‚ โ”œโ”€โ”€ database/
177โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
178โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
179โ”‚ โ”‚ โ””โ”€โ”€ README.md
180โ”‚ โ””โ”€โ”€ routes/ # Route modules
195โ””โ”€โ”€ shared/
196 โ”œโ”€โ”€ README.md
197 โ””โ”€โ”€ utils.ts # Shared types and functions
198```
199
203- Main entry point should be `backend/index.ts`
204- Do NOT use Hono serveStatic middleware
205- **Static asset serving:** Use the utility functions to read and serve project files:
206 ```ts
207 import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
237- Run migrations on startup or comment out for performance
238- Change table names when modifying schemas rather than altering
239- Export clear query functions with proper TypeScript typing
240
241## Common Gotchas and Solutions

Towniestyles.css2 matches

@tsuchi_yaโ€ขUpdated 3 days ago
241 transition-property: background-color;
242 transition-duration: 400ms;
243 transition-timing-function: linear;
244}
245
875 transition-property: color, background-color, border-color, opacity;
876 transition-duration: 200ms;
877 transition-timing-function: ease-in-out;
878}
879

TowniesoundEffects.ts3 matches

@tsuchi_yaโ€ขUpdated 3 days ago
1/**
2 * Sound effects utility functions for the application
3 */
4
7 * @returns A Promise that resolves when the sound has started playing
8 */
9export function playBellSound(): Promise<void> {
10 return new Promise((resolve) => {
11 try {
69 * @returns A Promise that resolves when the sound has started playing
70 */
71export function playSimpleNotification(): Promise<void> {
72 return new Promise((resolve) => {
73 try {

Townieschema.tsx2 matches

@tsuchi_yaโ€ขUpdated 3 days ago
22}
23
24async function createTables() {
25 // archive a table
26 // await sqlite.execute(
68}
69
70async function deleteTables() {
71 await sqlite.execute(`DROP TABLE IF EXISTS ${USAGE_TABLE}`);
72 await sqlite.execute(`DROP TABLE IF EXISTS ${INFERENCE_CALLS_TABLE}`);

Townierequests.ts5 matches

@tsuchi_yaโ€ขUpdated 3 days ago
29}
30
31export function renderRequests(data: RequestRow[], pagination: PaginationData, baseUrl: string): string {
32 // Calculate totals
33 const totalRequests = pagination.totalItems;
39 // Client-side script for collapsible rows
40 const script = `
41 // Function to toggle inference details
42 function toggleInferenceDetails(usageId) {
43 const detailsElement = document.getElementById('inference-' + usageId);
44
153
154 // Add click event listeners to all collapsible rows
155 document.addEventListener('DOMContentLoaded', function() {
156 document.querySelectorAll('.collapsible').forEach(row => {
157 row.addEventListener('click', function() {
158 const usageId = this.getAttribute('data-id');
159 toggleInferenceDetails(usageId);

Townierequests.ts4 matches

@tsuchi_yaโ€ขUpdated 3 days ago
6 * Get paginated usage requests
7 */
8export async function getRequests(url: URL) {
9 const { page, pageSize } = getPaginationParams(url);
10
35 * Get a single request by ID
36 */
37export async function getRequestById(id: string) {
38 const result = await sqlite.execute(`
39 SELECT * FROM ${USAGE_TABLE}
51 * Get inference calls for a specific usage request
52 */
53export async function getInferenceCallsForRequest(usageId: string) {
54 const result = await sqlite.execute(`
55 SELECT
75 * Calculate totals from inference calls for a request
76 */
77export async function getInferenceTotalsForRequest(usageId: string) {
78 const calls = await getInferenceCallsForRequest(usageId);
79

Towniequeries.tsx6 matches

@tsuchi_yaโ€ขUpdated 3 days ago
7// but in the meantime, we can cache user info in memory
8const userIdCache: { [key: string]: any } = {};
9export async function getUser(bearerToken: string) {
10 if (userIdCache[bearerToken]) return userIdCache[bearerToken];
11
16}
17
18async function last24Hours(userId: string) {
19 const usage = await sqlite.execute(
20 `SELECT
45 "lightweight": 10, // brad noble, added temporarily for prep for town hall on 5/21/25
46};
47export async function overLimit(bearerToken: string) {
48 const user = await getUser(bearerToken);
49 const last24HourUsage = await last24Hours(user.id);
54}
55
56export async function insertInferenceCall({
57 usage_id,
58 input_tokens,
108}
109
110export async function startTrackingUsage({
111 bearerToken,
112 val_id,
150}
151
152export async function finishTrackingUsage({
153 rowid,
154 input_tokens,

getFileEmail4 file matches

@shouserโ€ขUpdated 1 month ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblkโ€ขUpdated 1 month ago
Simple functional CSS library for Val Town
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.