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/$1?q=function&page=41&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 29279 results for "function"(1020ms)

Townschema.tsx2 matches

@loading•Updated 22 hours 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}`);

Townrequests.ts5 matches

@loading•Updated 22 hours 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);

Townrequests.ts4 matches

@loading•Updated 22 hours 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

Townqueries.tsx6 matches

@loading•Updated 22 hours 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,

TownProjectsRoute.tsx3 matches

@loading•Updated 22 hours ago
5import { Footer } from "./Footer.tsx";
6
7export function ProjectsRoute() {
8 const projects = useProjects();
9
37}
38
39function ProjectCard({
40 user,
41 project,
75}
76
77function Privacy({ privacy }: { privacy: "public" | "unlisted" | "private" }) {
78 switch (privacy) {
79 case "public":

TownPreviewFrame.tsx4 matches

@loading•Updated 22 hours ago
9}
10
11export function PreviewFrame(props: PreviewProps) {
12 const previewKey = useRef<string>("new-chat");
13 const [count, setCount] = useState<number>(0);
73const TSRE = /\/$/;
74
75function URLInput({ url, pathname, setPathname }) {
76 const prefix = url.replace(TSRE, "");
77 return (
90}
91
92function PreviewSelect({ index, setIndex, files }) {
93 return (
94 <div>
116}
117
118function usePreviewURL({ files }) {
119 const [index, setIndex] = useState<number>(0);
120 const htmlVals = files?.filter(file => file.links?.endpoint !== undefined);

Townpagination.ts5 matches

@loading•Updated 22 hours ago
21 * Parse pagination parameters from URL
22 */
23export function getPaginationParams(url: URL): { page: number; pageSize: number } {
24 const page = parseInt(url.searchParams.get("page") || "1", 10);
25 const pageSize = parseInt(url.searchParams.get("pageSize") || "50", 10);
35 * Calculate pagination metadata
36 */
37export function calculatePagination(params: PaginationParams): PaginationResult {
38 const totalPages = Math.ceil(params.totalItems / params.pageSize);
39
51 * Generate SQL LIMIT and OFFSET clauses for pagination
52 */
53export function getPaginationSQL(page: number, pageSize: number): string {
54 const offset = (page - 1) * pageSize;
55 return `LIMIT ${pageSize} OFFSET ${offset}`;
59 * Generate HTML for pagination controls
60 */
61export function renderPaginationControls(pagination: PaginationResult, baseUrl: string): string {
62 const url = new URL(baseUrl);
63
64 // Function to generate page URL
65 const getPageUrl = (page: number) => {
66 url.searchParams.set("page", page.toString());

TownNotFoundRoute.tsx1 match

@loading•Updated 22 hours ago
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
2
3export function NotFoundRoute () {
4 return (
5 <div className="container">Page not found</div>

TownNewProjectRoute.tsx2 matches

@loading•Updated 22 hours ago
4import { useCreateProject } from "../hooks/useCreateProject.tsx";
5
6export function NewProjectRoute () {
7 const [name, setName] = useState("");
8 const [privacy, setPrivacy] = useState("public");
65]
66
67function PrivacyRadios ({
68 value,
69 onChange,

TownMessages.tsx9 matches

@loading•Updated 22 hours ago
23});
24
25export function Messages ({
26 messages,
27 messageEndTimes,
58}
59
60function Message ({
61 message,
62 messageEndTimes,
86}
87
88function AssistantMessage ({ message, messageEndTimes, running }: {
89 message: Message;
90 messageEndTimes: Record<string, number>;
107}
108
109function Part ({ part }) {
110 switch (part.type) {
111 case "text":
122}
123
124function TextPart ({ part }) {
125 return (
126 <ReactMarkdown>
130}
131
132function Details ({ open, onClick, children, summary }) {
133 return (
134 <details
148}
149
150function ToolPart ({ part }) {
151 const { openSummaries, setOpenSummaries } = useContext(MessageContext);
152 const {
312}
313
314function EditorToolPart ({ part }) {
315 const { openSummaries, setOpenSummaries } = useContext(MessageContext);
316 const {
379}
380
381function UserMessage ({ message }: {
382 message: Message;
383}) {
tuna

tuna9 file matches

@jxnblk•Updated 1 day 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.