sqlite_adminREADME.md1 match
9To use it on your own Val Town SQLite database, [fork it](https://www.val.town/v/stevekrouse/sqlite_admin/fork) to your account.
1011It uses [basic authentication](https://www.val.town/v/pomdtr/basicAuth) with your [Val Town API Token](https://www.val.town/settings/api) as the password (leave the username field blank).
1213Migrated from folder: utils/sqlite_admin/sqlite_admin
tanstackReactHonoExampleindex.ts3 matches
18app.get("/shared/**/*", (c) => serveFile(c.req.path, import.meta.url));
1920// API endpoints
21app.get("/api/messages", async (c) => {
22const messages = await getMessages();
23return c.json(messages);
24});
2526app.post("/api/messages", async (c) => {
27const { content } = await c.req.json();
28
tanstackReactHonoExampleREADME.md3 matches
38```
3940## API Endpoints
4142- `GET /` - Serves the React application with initial data
43- `GET /api/messages` - Fetch all messages (JSON)
44- `POST /api/messages` - Create a new message
45- `GET /public/**` - Static assets (CSS, JS, etc.)
46- `/*` - All other routes handled by TanStack Router
tanstackReactHonoExampleREADME.md5 matches
8## Hono
910This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
1112## Serving assets to the frontend
20### `index.html`
2122The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
2324We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
2526## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors
3132Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.
tanstackReactHonoExamplequeries.ts2 matches
7queryKey: ["messages"],
8queryFn: async () => {
9const response = await fetch("/api/messages");
10if (!response.ok) {
11throw new Error("Failed to fetch messages");
25return useMutation({
26mutationFn: async (content: string) => {
27const response = await fetch("/api/messages", {
28method: "POST",
29headers: { "Content-Type": "application/json" },
ChatHTMLRenderer.tsx23 matches
9}
1011interface MCPContextAPI {
12// Tool operations
13listTools: () => Promise<any[]>;
37* - Renders HTML in a secure iframe
38* - Provides fullscreen enter/exit affordances
39* - Exposes MCP context API to iframe content
40* - Handles iframe communication via postMessage
41*/
46const [isLoading, setIsLoading] = useState(true);
4748// Create MCP context API that will be exposed to iframe
49const createMCPContext = useCallback((): MCPContextAPI => {
50const findClientByName = (serverName: string) => {
51console.log("[MCP/Browser Renderer] Finding client by name:", serverName, mcpClients);
210const { type, id, method, args } = event.data;
211212if (type !== "mcp-api-call") {
213return;
214}
219220if (typeof methodFunc !== "function") {
221throw new Error(`Unknown MCP API method: ${method}`);
222}
223225226iframe.contentWindow?.postMessage({
227type: "mcp-api-response",
228id,
229success: true,
232} catch (error) {
233iframe.contentWindow?.postMessage({
234type: "mcp-api-response",
235id,
236success: false,
252</script>
253<script>
254// MCP Context API for iframe content
255window.mcpContext = {
256// Async wrapper for postMessage communication
257async callAPI(method, ...args) {
258return new Promise((resolve, reject) => {
259const id = Math.random().toString(36).substr(2, 9);
260
261const handleResponse = (event) => {
262if (event.data.type === 'mcp-api-response' && event.data.id === id) {
263window.removeEventListener('message', handleResponse);
264if (event.data.success) {
273
274window.parent.postMessage({
275type: 'mcp-api-call',
276id,
277method,
282setTimeout(() => {
283window.removeEventListener('message', handleResponse);
284reject(new Error('MCP API call timeout'));
285}, 30000);
286});
288
289// Convenience methods
290async listTools() { return this.callAPI('listTools'); },
291async callTool(serverName, toolName, args) { return this.callAPI('callTool', serverName, toolName, args); },
292async listPrompts() { return this.callAPI('listPrompts'); },
293async getPrompt(serverName, promptName, args) { return this.callAPI('getPrompt', serverName, promptName, args); },
294async listResources() { return this.callAPI('listResources'); },
295async readResource(serverName, uri) { return this.callAPI('readResource', serverName, uri); },
296log(level, message, data) { this.callAPI('log', level, message, data); },
297requestFullscreen() { this.callAPI('requestFullscreen'); },
298exitFullscreen() { this.callAPI('exitFullscreen'); },
299async isFullscreen() { return this.callAPI('isFullscreen'); }
300};
301
73<script>
74(function() {
75const API_URL = '${sourceUrl}';
76const STORE_KEYS = { projects: 'aura_projects_v1', tasks: 'aura_tasks_v1' };
77const ACTIVE_TASK_WARNING_THRESHOLD = 50;
253addMessageToChat('ai', 'Aura is thinking...');
254try {
255const res = await fetch(\`\${API_URL}?action=chat\`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: userMessage, tasks, projects, history: conversationHistory.slice(-4) }) });
256if (!res.ok) {
257const err = await res.json();
284toggleLoading(btn, true);
285try {
286const res = await fetch(\`\${API_URL}?action=synthesizeProject\`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ goal }) });
287if (!res.ok) {
288const err = await res.json();
317toggleLoading(btn, true);
318try {
319const res = await fetch(\`\${API_URL}?action=getDailyReschedule\`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ tasks: todayTasks }) });
320if (!res.ok) {
321const err = await res.json();
anthropicProxyREADME.md1 match
1This Val will proxy anthropic HTTP requests from some frontend client, like langchain, so that you can utilize anthropic apis from the browser.
23Convert it to an HTTP val in order to use it (you may want to setup an ENV var / header to protect the endpoint with a secret key)
anthropicProxymain.tsx6 matches
13}
1415// Check that your valtown API key is sent in the 'x-authorization' header
16// Delete this line if you don't mind other parties hitting this endpoint
17if (req.headers.get("x-authorization") !== Deno.env.get("valtown")) {
24try {
25const body = await req.json();
26const apiKey = req.headers.get("x-api-key");
2728if (!body) {
30}
3132if (!apiKey) {
33throw new Error("No API key provided");
34}
3536const anthropic = new Anthropic({ apiKey });
3738if (body?.stream) {
57}
58} catch (e) {
59if (e instanceof Anthropic.APIError) {
60return Response.json(e.error, { status: e.status });
61}
cardamonRecipeForm.tsx5 matches
97switch (parseMode) {
98case 'url':
99endpoint = '/api/parse/url';
100requestData = { type: 'url', content: parseInput };
101break;
102case 'text':
103endpoint = '/api/parse/text';
104requestData = { type: 'url', content: parseInput }; // Note: backend expects 'url' type for text parsing
105break;
110
111if (uploadedFile.type.startsWith('image/')) {
112endpoint = '/api/parse/image';
113requestData = { type: 'image', content: parseInput };
114} else if (uploadedFile.type === 'application/pdf') {
115endpoint = '/api/parse/pdf';
116requestData = { type: 'pdf', content: parseInput };
117} else {
198};
199200const url = isEditing ? `/api/recipes/${recipe.id}` : '/api/recipes';
201const method = isEditing ? 'PUT' : 'POST';
202