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?q=api&page=8&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=api

Returns an array of strings in format "username" or "username/projectName"

Found 11519 results for "api"(3438ms)

TownieuseBranches.tsx1 match

@std•Updated 1 day ago
2import { useAuth } from "./useAuth.tsx";
3
4const ENDPOINT = "/api/project-branches";
5
6export function useBranches (projectId: string) {

TownieuseAuth.tsx12 matches

@std•Updated 1 day ago
3
4const TOKEN_KEY = "bearer";
5const ANTHROPIC_KEY = "anthropic_api_key";
6
7export function useAuth () {
8 const [token, setToken, removeToken] = useLocalStorage(TOKEN_KEY, "");
9 const [anthropicApiKey, setAnthropicApiKey, removeAnthropicApiKey] = useLocalStorage(ANTHROPIC_KEY, "");
10 const [error, setError] = useState(null);
11
12 const isAuthenticated = !!token && !!anthropicApiKey;
13
14 const authenticate = async (valTownAPIKey: string, anthropicKey: string) => {
15 // replace all this with oauth when it's ready
16 try {
17 const res = await fetch("/api/user", {
18 headers: {
19 "Authorization": "Bearer " + valTownAPIKey,
20 },
21 });
25 setError(data.error);
26 removeToken();
27 removeAnthropicApiKey();
28 return;
29 }
30 setError(null);
31 setToken(valTownAPIKey);
32 setAnthropicApiKey(anthropicKey);
33 } catch (e) {
34 console.error(e);
35 setError(e.error);
36 removeToken();
37 removeAnthropicApiKey();
38 }
39 }
41 const logOut = () => {
42 removeToken();
43 removeAnthropicApiKey();
44 }
45
50 logOut,
51 token,
52 anthropicApiKey,
53 };
54}

Towniesystem_prompt.txt10 matches

@std•Updated 1 day ago
13- Generate code in TypeScript or TSX
14- Add appropriate TypeScript types and interfaces for all data structures
15- Prefer official SDKs or libraries than writing API calls directly
16- Ask the user to supply API or library documentation if you are at all unsure about it
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
23### 1. HTTP Trigger
24
25- Create web APIs and endpoints
26- Handle HTTP requests and responses
27- Example structure:
167However, it's *extremely importing* to note that `parseProject` and other Standard Library utilities ONLY RUN ON THE SERVER.
168If you need access to this data on the client, run it in the server and pass it to the client by splicing it into the HTML page
169or by making an API request for it.
170
171## Val Town Platform Specifics
175- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
176- **Storage:** DO NOT use the Deno KV module for storage
177- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
178- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
179- **View Source:** Add a view source link by importing & using `import.meta.url.replace("ems.sh", "val.town)"` (or passing this data to the client) and include `target="_top"` attribute
180- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
181- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context
182- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
183- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
184- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
218### Backend (Hono) Best Practices
219
220- Hono is the recommended API framework
221- Main entry point should be `backend/index.ts`
222- **Static asset serving:** Use the utility functions to read and serve project files:
242 });
243 ```
244- Create RESTful API routes for CRUD operations
245- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
246 ```ts
279 - For files in the project, use `readFile` helpers
280
2815. **API Design:**
282 - `fetch` handler is the entry point for HTTP vals
283 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`

TowniesoundEffects.ts4 matches

@std•Updated 1 day ago
4
5/**
6 * Plays a bell sound notification using the Web Audio API
7 * @returns A Promise that resolves when the sound has started playing
8 */
13 const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
14 if (!AudioContext) {
15 console.warn("Web Audio API not supported in this browser");
16 resolve();
17 return;
65
66/**
67 * Plays a simple notification sound using the Web Audio API
68 * This is a simpler, shorter bell sound
69 * @returns A Promise that resolves when the sound has started playing
75 const AudioContext = window.AudioContext || (window as any).webkitAudioContext;
76 if (!AudioContext) {
77 console.warn("Web Audio API not supported in this browser");
78 resolve();
79 return;

Towniesend-message.ts11 matches

@std•Updated 1 day ago
19 }
20
21 const { messages, project, branchId, anthropicApiKey, selectedFiles, images } = await c.req.json();
22 console.log("Original messages:", JSON.stringify(messages, null, 2));
23 console.log("Images received:", JSON.stringify(images, null, 2));
24
25 // Check if API key is available
26 if (!anthropicApiKey) {
27 return Response.json({
28 error: "Anthropic API key is required. Please log out and add your Anthropic API key to use this app.",
29 }, { status: 400 });
30 }
31
32 let apiKey;
33 if (!anthropicApiKey) {
34 return Response.json({
35 error: "Anthropic API key is required. Please log out and add your Anthropic API key to use this app.",
36 }, { status: 400 });
37 } else if (anthropicApiKey === Deno.env.get("PASSWORD")) {
38 apiKey = Deno.env.get("PROVIDED_ANTHROPIC_API_KEY");
39 } else {
40 apiKey = anthropicApiKey;
41 }
42
43 const anthropic = createAnthropic({
44 apiKey,
45 });
46

TownieREADME.md11 matches

@std•Updated 1 day ago
9- **File Browser**: Select specific files to include in the context window for more focused AI assistance
10- **Branch Management**: View, select, and create branches without leaving the app
11- **Cost Tracking**: See estimated API usage costs for each interaction
12- **Sound Notifications**: Get alerted when Claude finishes responding
13- **Mobile-Friendly**: Works on both desktop and mobile devices
15## How It Works
16
171. **Login**: Authenticate with your Val Town API token and Anthropic API key
182. **Select a Project**: Choose which Val Town project you want to work on
193. **Select Files**: Browse your project files and select which ones to include in the context window
25### Prerequisites
26
27- A Val Town account with API access
28- An Anthropic API key (Claude 3.7 Sonnet)
29
30### Setup
31
321. Visit the OpenTownie app
332. Enter your Val Town API token (with `projects:write` and `users:read` permissions)
343. Enter your Anthropic API key
354. Click "Login" to access your projects
36
48- React frontend with TypeScript
49- React Router
50- Hono API server backend
51- Web Audio API for sound notifications
52- AI SDK for Claude integration
53
54The application proxies requests to the Anthropic API and Val Town API, allowing Claude to view and edit your project files directly.
55
56## Privacy & Security
57
58- Your Val Town API token and Anthropic API key are stored locally in your browser
59- No data is stored on our servers
60- All communication with the APIs is done directly from your browser
61

TowniePreview.tsx1 match

@std•Updated 1 day ago
90 value={customPath}
91 onChange={handlePathChange}
92 placeholder="Path (e.g., /api/data)"
93 />
94 </div>

TownieLoginRoute.tsx7 matches

@std•Updated 1 day ago
8 const { isAuthenticated, authenticate, error } = useAuth();
9 const [tokenValue, setTokenValue] = useState("");
10 const [apiKey, setApiKey] = useState("");
11 // const [invalid, setInvalid] = useState(""); // TODO
12
13 const handleSubmit = (e) => {
14 e.preventDefault();
15 authenticate(tokenValue, apiKey);
16 }
17
36 >
37 <div>
38 <label htmlFor="valtown-token" className="label">Val Town API Token</label>
39 <input
40 type="password"
48 </div>
49 <div>
50 <label htmlFor="anthropic-api-key" className="label">Anthropic API Key</label>
51 <input
52 type="password"
53 id="anthropic-api-key"
54 name="anthropic-key"
55 value={apiKey}
56 onChange={e => {
57 setApiKey(e.target.value);
58 }}
59 />

Townieindex.ts2 matches

@std•Updated 1 day ago
11app.get("*", async (c, next) => {
12 const path = c.req.path;
13 if (path.startsWith("/api/") || c.req.header("Accept")?.includes("application/json")) {
14 return next();
15 }
21});
22
23app.route("/api", backend);
24app.get("/frontend/*", c => {
25 return serveFile(c.req.path, import.meta.url);

TownieHome.tsx6 matches

@std•Updated 1 day ago
48 </h2>
49 <ol>
50 <li>Login with your Val Town API token</li>
51 <li>Add your Anthropic API key</li>
52 <li>Select a project to work on</li>
53 <li>Chat with Claude about your code</li>
86 </div>
87 <h3>Cost Tracking</h3>
88 <p>See estimated API usage costs for each interaction</p>
89 </div>
90 </section>
99 <ul>
100 <li>React frontend with TypeScript</li>
101 <li>Hono API server backend</li>
102 <li>Web Audio API for sound notifications</li>
103 <li>AI SDK for Claude integration</li>
104 </ul>
105 <p >
106 The application proxies requests to the Anthropic API and Val Town API, allowing Claude to view and edit your project files directly.
107 </p>
108 <div >

gptApiTemplate2 file matches

@charmaine•Updated 1 day ago

mod-interview-api1 file match

@twschiller•Updated 1 day ago
aquapi
apiv1