vtEditorFilesAGENTS.md2 matches
198```
199โโโ backend/
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
257```
258259### Database Patterns
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
177},
178parent: {
179type: "database_id" | "page_id",
180database_id?: string,
181page_id?: string
182},
233{
234id: string,
235type: "paragraph" | "heading_1" | "heading_2" | "heading_3" | "bulleted_list_item" | "numbered_list_item" | "to_do" | "toggle" | "child_page" | "child_database" | "embed" | "image" | "video" | "file" | "pdf" | "bookmark" | "callout" | "quote" | "equation" | "divider" | "table_of_contents" | "column" | "column_list" | "link_preview" | "synced_block" | "template" | "link_to_page" | "table" | "table_row" | "unsupported",
236created_time: string,
237last_edited_time: string,
1152. Fetches Notion page data
1163. Extracts assigned person ID from "Assigned" property
1174. Queries agents database for matching agents
1185. Clears current demo's agent blob
1196. Removes assigned agents from other demo blobs (prevents double-assignment)
130"agentsAssigned": 1,
131"agentBlobUpdated": true,
132"note": "Agents removed from other demo blobs and Notion database cleanup will be handled by cron jobs",
133"timestamp": "2024-01-01T00:00:00.000Z"
134}
164```
165166500 - Missing agents database configuration:
167```json
168{
30}
3132// Re-export all database services
33export {
34getDatabases,
35getDatabaseById,
36getDatabasePages,
37findUserByEmail,
38createUserRecord,
39findAgentsAssignedToDemo
40} from './database.service.ts';
4142// Re-export all page services
1import { notion, createSuccessResponse, createErrorResponse, type NotionServiceResponse } from './index.ts';
23export async function getDatabases(): Promise<NotionServiceResponse> {
4try {
5const response = await notion.search({
6filter: {
7property: "object",
8value: "database"
9}
10});
15}
1617export async function getDatabaseById(databaseId: string): Promise<NotionServiceResponse> {
18try {
19const response = await notion.databases.retrieve({
20database_id: databaseId,
21});
22return createSuccessResponse(response);
26}
2728export async function getDatabasePages(databaseId: string): Promise<NotionServiceResponse> {
29try {
30const response = await notion.databases.query({
31database_id: databaseId,
32});
33return createSuccessResponse(response);
37}
3839export async function findUserByEmail(databaseId: string, email: string): Promise<NotionServiceResponse> {
40try {
41const response = await notion.databases.query({
42database_id: databaseId,
43filter: {
44property: "Email",
54}
5556export async function createUserRecord(databaseId: string, email: string): Promise<NotionServiceResponse> {
57try {
58const response = await notion.pages.create({
59parent: {
60database_id: databaseId
61},
62properties: {
72}
7374export async function findAgentsAssignedToDemo(databaseId: string, demoPageId: string): Promise<NotionServiceResponse> {
75try {
76const response = await notion.databases.query({
77database_id: databaseId,
78filter: {
79property: "Glimpse demos",
8485### **Service Layer** (External Integrations)
86- Handles external API calls (Notion, databases)
87- Manages data persistence
88- Returns structured results with success/error information
108- `GET /glimpse/login` - User-specific login redirect
109- Requires user authentication (Google OAuth via LastLogin)
110- Looks up authenticated user's email in `GLANCE_DEMOS_DB_ID` database
111- If user found: Redirects to user's personal path (from Path property)
112- If user not found: Creates new user record and redirects to `/glimpse/thanks`
113- Shows detailed error information for debugging database structure issues
114115- `GET /glimpse/thanks` - New user welcome page
2132141. **Authentication**: User must be authenticated via Google OAuth (handled by LastLogin)
2152. **Database Lookup**: System queries `GLANCE_DEMOS_DB_ID` database for user's email
2163. **User Creation**: If not found, creates new user record with email address
2174. **Welcome Page**: Redirects to `/glimpse/thanks` with next steps information
2196. **User Return**: User can return to `/glimpse/login` once URL is configured
220221### Database Requirements for Login
222223The `GLANCE_DEMOS_DB_ID` database must contain:
224- **Email property**: Contains user's email address (exact match with authenticated email)
225- **Path property**: Contains user's redirect path in format `/glimpse/:id` (optional for new users)
231The login endpoint provides detailed error information for debugging:
232- Missing environment variables
233- Database query failures
234- User creation failures (falls back to access denied page)
235- Invalid or missing Path properties
2732. Retrieves page properties to extract Assigned and Viewing properties
2743. **Checks if Viewing property is true** - if not, skips assignment and logs result
2754. Queries `GLANCE_AGENTS_DB_ID` database for agents with matching Assigned property
2765. **STEP 1: Clear Current Demo Blob** - Immediately clears the agent blob for this demo
2776. **STEP 2: Find New Agents** - Queries agents database by Assigned property
2787. **STEP 3: Collect Agent Data** - Fetches complete agent information and validates
2798. **STEP 4: Clear Agents from Other Demo Blobs** - Removes agents from any other demo blobs to prevent double-assignment
283- **Immediate Updates**: Agent blob is updated immediately for fast frontend response
284- **Multi-Blob Clearing**: Ensures agents only appear in one demo blob at a time
285- **Eventual Consistency**: Cron jobs handle Notion database cleanup in the background
286- **No Manual Unassignment**: Assignments are cleared automatically when `Viewing = false`
287- **Reliable**: Blob operations are simpler and more reliable than complex relation management
325- Page must have a **Viewing property set to true** (assignment only occurs for actively viewed pages)
326- Page must have an Assigned property with assigned person
327- Agents database must have pages with Assigned properties matching the assigned person
328- Original page must have a "Glimpse agents" relation property
329- Agent pages must have a "Glimpse demos" relation property
394395**Performance Benefits:**
396- **Fast Execution**: Blob scanning is faster than database queries
397- **Targeted Processing**: Only processes pages with empty agent arrays
398- **Resource Efficient**: Minimal API calls to Notion
433434Configure these environment variables for full functionality:
435- `GLANCE_DEMOS_DB_ID` - Notion database ID for demos
436- `GLANCE_CONTENT_DB_ID` - Notion database ID for content
437- `GLANCE_INTERACTIONS_DB_ID` - Notion database ID for interactions
438- `GLANCE_AGENTS_DB_ID` - Notion database ID for agents
439- `NOTION_API_KEY` - Notion API key for database access
440- `NOTION_WEBHOOK_SECRET` - Secret key for webhook authentication
441452### **Blob Storage + Notion Sync**
453- **Fast blob updates**: Page viewing status stored in Val Town blob storage for instant response (~100ms)
454- **Immediate Notion sync**: When users start viewing pages, Notion database is updated immediately
455- **Automatic cleanup**: Cron job runs every minute to mark stale sessions (>1 minute old) as not viewing
456517- **Content**: Must exactly match the authenticated user's email address
518519### **Notion Database Schema**
520Pages in your Notion databases should include these properties for viewing analytics:
521- **Email** (Email or Rich Text) - **Required** for authorization
522- **Session start** (Date) - **Primary viewing status**: Currently viewing + when session began
34export async function createTables() {
5// Uncomment to reset database
6await db.run(sql`DROP TABLE IF EXISTS messages`);
7// Create messages table
13}
1415// Get the Glance Demos database ID from environment
16const databaseId = Deno.env.get("GLANCE_DEMOS_DB_ID");
1718if (!databaseId) {
19return c.json({
20error: "Database configuration missing",
21details: "GLANCE_DEMOS_DB_ID environment variable not set",
22userEmail: userEmail,
2526try {
27// Find user by email in the database
28const result = await findUserByEmail(databaseId, userEmail);
2930if (!result.success) {
31return c.json({
32error: "Failed to query user database",
33details: result.error,
34userEmail: userEmail,
35databaseId: databaseId,
36}, 500);
37}
42console.log(`Creating new user record for: ${userEmail}`);
4344const createResult = await createUserRecord(databaseId, userEmail);
4546if (!createResult.success) {
181details: error.message,
182userEmail: userEmail,
183databaseId: databaseId,
184}, 500);
185}
cerebras_codermain.tsx2 matches
1import { serveFile } from "https://esm.town/v/std/utils/index.ts";
2import { generateCode } from "./backend/generate-code.ts";
3import { createTables } from "./database/migrations.ts";
4import {
5createProject,
7getNextVersionNumber,
8insertVersion,
9} from "./database/queries.ts";
1011await createTables();
krazyy-cam-configmain.ts2 matches
90// ---- Query Firestore publicLenses ----
91const pubDocRes = await fetch(
92`https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents/publicLenses/${id}`,
93{ headers: { Authorization: `Bearer ${access_token}` } },
94);
106// ---- Query Firestore private user doc ----
107const privDocRes = await fetch(
108`https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents/users/${owner}/lenses/${id}`,
109{ headers: { Authorization: `Bearer ${access_token}` } },
110);