feat: ai chat added, login flow still broken

This commit is contained in:
2026-02-11 18:00:37 +01:00
parent 258e313f0e
commit 870bec4dcd
21 changed files with 3174 additions and 25 deletions

View File

@@ -410,6 +410,34 @@ export class DatabaseConnection {
args: ['default', 'Default Project', 'default', 'Your first blog project', now, now, 1],
});
}
// Create chat_conversations table for AI chat persistence
await this.localClient.execute(`
CREATE TABLE IF NOT EXISTS chat_conversations (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
model TEXT,
copilot_session_id TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
)
`);
await this.localClient.execute('CREATE INDEX IF NOT EXISTS idx_chat_conversations_updated_at ON chat_conversations(updated_at)');
// Create chat_messages table for storing conversation messages
await this.localClient.execute(`
CREATE TABLE IF NOT EXISTS chat_messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
conversation_id TEXT NOT NULL,
role TEXT NOT NULL,
content TEXT,
tool_call_id TEXT,
tool_calls TEXT,
created_at INTEGER NOT NULL,
FOREIGN KEY (conversation_id) REFERENCES chat_conversations(id) ON DELETE CASCADE
)
`);
await this.localClient.execute('CREATE INDEX IF NOT EXISTS idx_chat_messages_conversation_id ON chat_messages(conversation_id)');
}
async close(): Promise<void> {

View File

@@ -108,6 +108,27 @@ export const tags = sqliteTable('tags', {
projectNameIdx: uniqueIndex('tags_project_name_idx').on(table.projectId, table.name),
}));
// Chat conversations table - stores AI chat sessions
export const chatConversations = sqliteTable('chat_conversations', {
id: text('id').primaryKey(),
title: text('title').notNull(),
model: text('model'), // Model used for this conversation
copilotSessionId: text('copilot_session_id'), // Copilot SDK session ID for resuming
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull(),
});
// Chat messages table - stores messages within conversations
export const chatMessages = sqliteTable('chat_messages', {
id: integer('id').primaryKey({ autoIncrement: true }),
conversationId: text('conversation_id').notNull(),
role: text('role', { enum: ['system', 'user', 'assistant', 'tool'] }).notNull(),
content: text('content'),
toolCallId: text('tool_call_id'), // For tool responses
toolCalls: text('tool_calls'), // JSON array of tool calls
createdAt: integer('created_at', { mode: 'timestamp' }).notNull(),
});
// Types for TypeScript
export type Project = typeof projects.$inferSelect;
export type NewProject = typeof projects.$inferInsert;
@@ -123,3 +144,7 @@ export type PostLink = typeof postLinks.$inferSelect;
export type NewPostLink = typeof postLinks.$inferInsert;
export type Tag = typeof tags.$inferSelect;
export type NewTag = typeof tags.$inferInsert;
export type ChatConversation = typeof chatConversations.$inferSelect;
export type NewChatConversation = typeof chatConversations.$inferInsert;
export type ChatMessage = typeof chatMessages.$inferSelect;
export type NewChatMessage = typeof chatMessages.$inferInsert;