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/$%7Bart_info.art.src%7D?q=function&page=1683&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 34005 results for "function"(8488ms)

3import { updateThreadName } from "../database/queries.ts";
4
5export async function generateThreadName(apiKey, firstMessage, anthropicApiKey) {
6 const anthropic = createAnthropic({
7 apiKey,

OpenTownie_jacksoncalculate-cost.ts1 match

@stevekrouse•Updated 2 months ago
5const CACHE_WRITE_RATE = 3.75; // $3.75 per M cache-write tokens :contentReference[oaicite:3]{index=3}
6
7export function calculateCost({
8 input_tokens,
9 completed_tokens,

live-reloadutils.ts8 matches

@stevekrouse•Updated 2 months ago
12 * @throws {Error} If the specified branch is not found
13 */
14export async function getProjectIds(importMetaUrl: string) {
15 const {
16 name: projectName,
28}
29
30async function projectLastUpdated({ project_id, branch_id }: { project_id: string; branch_id: string }) {
31 const { updatedAt, version } = await client.projects.branches.retrieve(
32 project_id,
36}
37
38async function wait(ms: number) {
39 return new Promise(resolve => setTimeout(resolve, ms));
40}
49 * @returns {Promise} A new promise with timeout behavior
50 */
51export function timeout<T>(
52 promise: Promise<T>,
53 timeoutMs: number,
66}
67
68export async function longPollLastUpdated({
69 version,
70 project_id,
98 * the full text response.
99 *
100 * @param handler The original fetch handler function
101 * @param html The HTML content to inject
102 * @returns A new fetch handler with HTML rewriting
103 */
104export function injectHTML(
105 handler: (request: Request) => Promise<Response>,
106 html: string,
112}
113
114export async function injectHTMLResponse(
115 response: Response,
116 html: string,

minemain.tsx3 matches

@yassinreg•Updated 2 months ago
3import React, { useState } from "https://esm.sh/react@18.2.0";
4
5function App() {
6 const [file, setFile] = useState<File | null>(null);
7 const [feedback, setFeedback] = useState<string | null>(null);
117};
118
119function client() {
120 createRoot(document.getElementById("root")).render(<App />);
121}
122if (typeof document !== "undefined") { client(); }
123
124export default async function server(request: Request): Promise<Response> {
125 if (request.method === "POST") {
126 try {

sqliteExplorerAppREADME.md1 match

@skynocover•Updated 2 months ago
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
35- [x] add export to CSV, and JSON (CSV and JSON helper functions written in [this val](https://www.val.town/v/nbbaier/sqliteExportHelpers). Thanks to @pomdtr for merging the initial version!)
36- [x] add listener for cmd+enter to submit query

Lairmain.tsx13 matches

@Get•Updated 2 months ago
25 mandateId: string;
26 taskId: string;
27 log: LogFunction;
28 // Could add other shared resources here (e.g., config, shared memory access)
29}
30
31/** Defines the function signature for any agent. */
32type AgentFunction<InputPayload = any, OutputPayload = any> = (
33 input: AgentInput<InputPayload>,
34 context: AgentContext,
73// --- Logging ---
74
75type LogFunction = (level: LogLevel, component: string, message: string, details?: any) => void;
76type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR" | "SUCCESS";
77
101 }
102
103 createLogFunction(mandateId: string, baseComponent?: string): LogFunction {
104 return (level, component, message, details) => {
105 const entry: Omit<LogEntry, 'timestamp' | 'taskId'> = {
132
133class AgentRegistry {
134 private agents: Map<string, AgentFunction<any, any>> = new Map();
135
136 register<InputPayload, OutputPayload>(
137 name: string,
138 agentFn: AgentFunction<InputPayload, OutputPayload>,
139 ): void {
140 if (this.agents.has(name)) {
145 }
146
147 getAgent(name: string): AgentFunction<any, any> | undefined {
148 return this.agents.get(name);
149 }
174 ): Promise<WorkflowResult<FinalPayload>> {
175 const mandateId = `M-${Date.now()}-${definition.id}`;
176 const log = this.logger.createLogFunction(mandateId, 'WorkflowEngine');
177 const stepResults = new Map<string, AgentOutput<any>>(); // Store outputs of successful steps
178
272
273// Agent 1: Summarizer (modified for new signature)
274async function summarizerAgent(
275 input: AgentInput<{ textToSummarize: string }>,
276 context: AgentContext,
297
298// Agent 2: Fetch External Data (modified for new signature)
299async function fetchAgent(
300 input: AgentInput<{ url?: string }>, // Optionally allow URL via input
301 context: AgentContext,
362// agentRegistry.register("sentimentAnalyzer", sentimentAgent);
363
364function generateHtmlShell() {
365 // Same HTML shell as before - no changes needed here
366 return `<!DOCTYPE html>
446
447// Val Town Entry Point (or adapt for Node.js/Deno/Bun)
448export default async function(req: Request): Promise<Response> {
449 // Clear logs for each new request to avoid mixing logs between runs
450 globalLogger.clear();

hn_job_analyzerhnService.ts11 matches

@prashamtrivedi•Updated 2 months ago
1export async function fetchHiringPosts(postId?: number): Promise<any[]> {
2 try {
3 // If no post ID is provided, find the latest "Who is hiring" post
24}
25
26export async function fetchWantToBeHiredPosts(postId?: number): Promise<any[]> {
27 try {
28 // If no post ID is provided, find the latest "Who wants to be hired" post
49}
50
51export async function fetchFreelancerPosts(postId?: number): Promise<any[]> {
52 try {
53 // If no post ID is provided, find the latest "Freelancer? Seeking Freelancer?" post
74}
75
76// Helper function to fetch an item from the HN API
77async function fetchItem(id: number): Promise<any> {
78 const response = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
79 return await response.json();
80}
81
82// Helper function to find the latest "Who is hiring" post
83async function findLatestHiringPostId(): Promise<number> {
84 try {
85 // First, get the latest stories
112}
113
114// Helper function to find the latest "Who wants to be hired" post
115async function findLatestWantToBeHiredPostId(): Promise<number> {
116 try {
117 // First, get the latest stories
144}
145
146// Helper function to find the latest "Freelancer? Seeking Freelancer?" post
147async function findLatestFreelancerPostId(): Promise<number> {
148 try {
149 // First, get the latest stories

hn_job_analyzeraiAnalyzer.ts4 matches

@prashamtrivedi•Updated 2 months ago
8});
9
10// Function to analyze job opportunities
11export async function analyzeJobOpportunities(hiringPosts: any[], freelancerPosts: any[], resumeData: any): Promise<string> {
12 try {
13 // Prepare content for analysis
53}
54
55// Function to analyze competition
56export async function analyzeCompetition(wantToBeHiredPosts: any[], freelancerPosts: any[], resumeData: any): Promise<string> {
57 try {
58 // Prepare content for analysis

hn_job_analyzerutils.ts4 matches

@prashamtrivedi•Updated 2 months ago
1export function formatDate(date: Date): string {
2 return date.toISOString().split('T')[0];
3}
4
5export function getCurrentMonth(): string {
6 const months = [
7 'January', 'February', 'March', 'April', 'May', 'June',
13}
14
15export function getCurrentYear(): number {
16 return new Date().getFullYear();
17}
18
19export function sanitizeHTML(text: string): string {
20 return text
21 .replace(/&/g, '&amp;')

discord-botapi-server.js4 matches

@boucher•Updated 2 months ago
15
16/**
17 * Function to analyze messages with OpenAI
18 * @param {Array} messages - Array of message objects
19 * @param {string} query - User query to analyze messages with
20 * @returns {Object} - OpenAI response
21 */
22async function analyzeMessagesWithAI(messages, query) {
23 try {
24 // Format messages for OpenAI
179
180/**
181 * Val.town handler function for HTTP requests
182 * This will be exposed as a Val.town HTTP endpoint
183 */
184export default async function handler(req, res) {
185 // Create a simple adapter to route the request through Express
186 return new Promise((resolve, reject) => {

discordWebhook2 file matches

@stevekrouse•Updated 1 week ago
Helper function to send Discord messages
tuna

tuna9 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.