5export const MESSAGES_TABLE = "opentownie_messages";
6
7export interface DatabaseUser {
8 id: string;
9 username: string;
13}
14
15export interface DatabaseThread {
16 id: string;
17 user_id: string;
22}
23
24export interface DatabaseMessage {
25 id: number;
26 thread_id: string;
2import { createMiddleware } from "npm:hono/factory";
3import { type User } from "../../shared/types.ts";
4import { getOrCreateUser } from "../database/queries.ts";
5
6export const auth = createMiddleware<{
3import { convertToCoreMessages, type CoreUserMessage, streamText } from "npm:ai";
4import { Hono } from "npm:hono";
5import { createThread, saveMessage } from "../database/queries.ts";
6import { getTextEditorTool, makeChangeValTypeTool, makeDeleteTool, thinkTool } from "../tools/index.ts";
7import fileWithLinesNumbers from "../utils/fileWithLinesNumbers.ts";
1import { Hono } from "npm:hono";
2import { createAnthropic } from "npm:@ai-sdk/anthropic";
3import { updateThreadName } from "../database/queries.ts";
4
5export async function generateThreadName(apiKey, firstMessage, anthropicApiKey) {
30- [ ] add triggers to sidebar
31- [ ] add upload from SQL, CSV and JSON
32- [ ] add ability to connect to a non-val town Turso database
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
1import express from 'express';
2import { getMessages, getLinks, getCategories, updateLinkCategory } from './database.js';
3import { Configuration, OpenAIApi } from 'openai';
4import 'dotenv/config';
1import { getMessages, getLinks } from './database.js';
2import { analyzeConversation, categorizeContent, summarizeConversation } from './anthropic-service.js';
3import 'dotenv/config';
1import { Client, Events, GatewayIntentBits } from 'discord.js';
2import 'dotenv/config';
3import { saveDMMessages } from './database.js';
4
5/**
89 console.log(`Fetched ${messages.length} messages`);
90
91 // Save messages to database
92 await saveDMMessages(messages);
93
5## Features
6
7- **Message History Storage**: Securely stores your DM history in a SQLite database
8- **Link Detection & Categorization**: Automatically detects and categorizes links shared in conversations
9- **AI-Powered Querying**: Ask natural language questions about your conversation history
53 - `OPENAI_API_KEY`: Your OpenAI API key
54
555. Initialize the database
56 ```
57 node index.js
124- `/analyze [query]`: Analyze your conversation with AI
125
126## Database Schema
127
128The application uses a SQLite database with the following tables:
129
130- `messages`: Stores all DM messages
148- OpenAI for AI-powered querying
149- Val.town for hosting and scheduling
150- Better-SQLite3 for database management
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