1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { runMigrations } from "./database/migrations.ts";
4import {
5 createToken,
10 getRecentLogs,
11 clearAllTokens
12} from "./database/queries.ts";
13
14const app = new Hono();
19});
20
21// Initialize database on startup
22await runMigrations();
23
116});
117
118// Clear all tokens (reset database)
119app.delete("/api/tokens", async c => {
120 const deletedCount = await clearAllTokens();
121 await logTerminalEntry('warning', `Database reset: ${deletedCount} tokens cleared`, 'system');
122
123 return c.json({
124 success: true,
125 message: `Cleared ${deletedCount} tokens from database`
126 });
127});
138 heist_method: "Municipal Override Key",
139 status: "SUCCESSFUL",
140 vault_location: "Secure Civic Database",
141 warning: "Civic authorities have been notified"
142 };
164 status: 'healthy',
165 timestamp: new Date().toISOString(),
166 database: 'connected',
167 total_tokens: stats.total_tokens
168 });
5
6export async function runMigrations() {
7 console.log('๐ง Running database migrations...');
8
9 // Create tokens table
44 `);
45
46 console.log('โ
Database migrations completed');
47}
48
9- [ ] make it one click to branch off like old jp townie demos
10- [ ] opentownie as a pr bot
11- [ ] give it the ability to see its own client-side and server-side logs by building a middleware that shoves them into a SQL light database date and then give it a tool to access them
12- [ ] do a browser use or screenshot thing to give it access to its own visual output
13- [ ] Have it default to creating a new branch off main
7export const thinkTool = tool({
8 description:
9 "Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.",
10 parameters: z.object({
11 thought: z.string().describe("A thought to think about."),
174```
175โโโ backend/
176โ โโโ database/
177โ โ โโโ migrations.ts # Schema definitions
178โ โ โโโ queries.ts # DB query functions
234 ```
235
236### Database Patterns
237- Run migrations on startup or comment out for performance
238- Change table names when modifying schemas rather than altering
1import { Hono } from "npm:hono";
2import Stripe from "npm:stripe";
3import { addCredits } from "../database/queries.tsx";
4import { getEnvVarName } from "../../shared/is-prod-branch.ts";
5
13 finishTrackingUsage,
14 calculatePartialUsageFromInferenceCalls,
15} from "../database/queries.tsx";
16import { makeChangeValTypeTool, makeFetchTool, makeTextEditorTool, makeTracesTool } from "../tools/index.ts";
17import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
6const PRICE_MULTIPLIER = 1.5;
7
8// Eventually we'll have a user database,
9// but in the meantime, we can cache user info in memory
10const userIdCache: { [key: string]: any } = {};
1import { Hono } from "npm:hono";
2import Stripe from "npm:stripe";
3import { getUser } from "../database/queries.tsx";
4import { getEnvVarName } from "../../shared/is-prod-branch.ts";
5
198```
199โโโ backend/
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
257 ```
258
259### Database Patterns
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering