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
3// Import route modules
4import cobrowse from "./cobrowse.api.routes.ts";
5import database from "./database.api.routes.ts";
6import demo from "./demo.api.routes.ts";
7import page from "./page.api.routes.ts";
12
13// mount routes
14app.route("/db", database);
15app.route("/page", page);
16app.route("/cobrowse", cobrowse);
7
8export async function getDemoInteractions(pageId: string) {
9 const databaseId = Deno.env.get("GLANCE_INTERACTIONS_DB_ID");
10
11 if (!databaseId) {
12 throw new Error(
13 "GLANCE_INTERACTIONS_DB_ID environment variable is not set"
16
17 try {
18 const response = await notion.databases.query({
19 database_id: databaseId,
20 filter: {
21 property: "Glancer demos", // the property in the Glancer interactions database related to the "Glancer demos" database
22 relation: {
23 contains: pageId, // the "Glancer demos" property holds the page id of the "Glancer demo" to which it is related
40
41export async function getAllInteractionsPages() {
42 const databaseId = Deno.env.get("GLANCE_INTERACTIONS_DB_ID");
43
44 if (!databaseId) {
45 throw new Error(
46 "GLANCE_INTERACTIONS_DB_ID environment variable is not set"
49
50 try {
51 const response = await notion.databases.query({
52 database_id: databaseId,
53 });
54
70
71export async function getAllInteractionsPagesWithPagination() {
72 const databaseId = Deno.env.get("GLANCE_INTERACTIONS_DB_ID");
73
74 if (!databaseId) {
75 throw new Error(
76 "GLANCE_INTERACTIONS_DB_ID environment variable is not set"
84
85 while (hasMore) {
86 const response = await notion.databases.query({
87 database_id: databaseId,
88 start_cursor: startCursor,
89 });
10 const page = await notion.pages.create({
11 parent: {
12 database_id: Deno.env.get("GLANCE_INTERACTIONS_DB_ID"),
13 },
14 properties: {
12 console.log(data);
13 try {
14 // create a database page in the interactions database
15 const page = await setAction(data);
16 // console.log(page);
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
17 insertInferenceCall,
18 startTrackingUsage,
19} from "../database/queries.tsx";
20import {
21 makeChangeValTypeTool,