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
10 overLimit,
11 startTrackingUsage,
12} from "../database/queries.tsx";
13import { makeChangeValTypeTool, makeFetchTool, makeTextEditorTool } from "../tools/index.ts";
14import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
4import { INFERENCE_CALLS_TABLE, USAGE_TABLE } from "./schema.tsx";
5
6// Eventually we'll have a user database,
7// but in the meantime, we can cache user info in memory
8const userIdCache: { [key: string]: any } = {};
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
9- The **client-side entrypoint** is `/frontend/index.html`, which in turn imports `/frontend/index.tsx`, which in turn imports the React app from `/frontend/components/App.tsx`.
10
11[React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a fuller featured example project, with a SQLite database table, queries, client-side CSS and a favicon, and some shared code that runs on both client and server.
12
13This is a test
12const app = new Hono();
13
14// Endpoint to get all pages from a specified database
15app.get("/:id", async (c) => {
16 try {
39 return c.html(html);
40 } catch (error) {
41 console.error("Error querying database:", error);
42 return c.html(
43 `
45 <body>
46 <h1>Error</h1>
47 <p>Failed to query database: ${error.message}</p>
48 </body>
49 </html>
57app.get("/:id/filtered", async (c) => {
58 try {
59 const databaseId = c.req.param("id");
60 const statusValue = c.req.query("status") || "Embed ready";
61
62 if (!databaseId) {
63 return c.html(
64 `
66 <body>
67 <h1>Error</h1>
68 <p>Missing required parameter: database ID</p>
69 </body>
70 </html>
74 }
75
76 // Query the database with a filter for the specified status
77 // Using select type for the Status property
78 const response = await notion.databases.query({
79 database_id: databaseId,
80 filter: {
81 property: "Status",
101 return c.html(html);
102 } catch (error) {
103 console.error("Error querying database:", error);
104 return c.html(
105 `
107 <body>
108 <h1>Error</h1>
109 <p>Failed to query database: ${error.message}</p>
110 </body>
111 </html>
122 <body>
123 <h1>Showcase HTML API</h1>
124 <p>Use /showcase-html/:database_id to get all pages from a database as HTML</p>
125 </body>
126 </html>
10// update the cache that was saved to blob storage by the /cache route
11export default async function(interval: Interval) {
12 // build key fragment to find the blob with the database cache in it
13 const blobKey = [
14 "cache", // this matches the path that sets the blob and tells us what the purpose of this blob is
15 "db", // we added this bit to the key when we saved it so that we know is a database cache when we look at blob storage
16 ].join("--");
17 // get blob with database JSON
18 const blobKeys = await blob.list(blobKey); // array of keys that start with the blobKey fragment
19 // console.log(blobKeys[0]);
20 const databaseId = blobKeys[0].key.split("--").pop();
21 // console.log(databaseId);
22 // Query the database without any filters to get all pages
23 const response = await notion.databases.query({
24 database_id: databaseId,
25 filter: {
26 property: "Publication status",
10// update the cache that was saved to blob storage by the /cache route
11export default async function(interval: Interval) {
12 // build key fragment to find the blob with the database cache in it
13 const blobKey = [
14 "cache", // this matches the path that sets the blob and tells us what the purpose of this blob is
15 "db", // we added this bit to the key when we saved it so that we know is a database cache when we look at blob storage
16 ].join("--");
17 // get blob with database JSON
18 const blobKeys = await blob.list(blobKey); // array of keys that start with the blobKey fragment
19 // console.log(blobKeys[0]);
20 const databaseId = blobKeys[0].key.split("--").pop();
21 // console.log(databaseId);
22 // Query the database without any filters to get all pages
23 const response = await notion.databases.query({
24 database_id: databaseId,
25 filter: {
26 property: "Publication status",
4
5* `index.ts` - this is the **entrypoint** for this whole project
6* `database/` - this contains the code for interfacing with the app's SQLite database table
7
8## Hono
26## CRUD API Routes
27
28This 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.
29
30## Errors