d2b8ab8fe8
Phase 4: Full chat system with SSE streaming, note-aware context, and conversation persistence. Backend: - Migration 0005: conversations + messages tables with FKs and indexes - Conversation/Message SQLAlchemy models with relationships - LLM service: ensure_model (auto-pull on startup), stream_chat (NDJSON), generate_completion, fetch_url_content (HTML stripping), build_context (keyword extraction, related note search, URL content injection) - Chat service: conversation CRUD, save_response_as_note, summarize_conversation_as_note - Chat routes blueprint: 9 endpoints including SSE streaming for messages, save/summarize as note, Ollama model listing - Auto-pull llama3.1 model on app startup (non-blocking) Frontend: - apiStreamPost: SSE client using fetch + ReadableStream - Chat Pinia store with streaming state management - ChatView: dedicated /chat page with conversation sidebar + message thread - ChatPanel: slide-out panel with contextNoteId from current route - ChatMessage: markdown-rendered message bubble with "Save as Note" action - Updated AppHeader with Chat nav link + panel toggle button - Updated App.vue to mount ChatPanel with route-derived context - Added /chat and /chat/:id routes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
"""add chat tables
|
|
|
|
Revision ID: 0005
|
|
Revises: 0004
|
|
Create Date: 2025-01-01 00:00:00.000000
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = "0005"
|
|
down_revision = "0004"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"conversations",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("title", sa.Text(), nullable=False, server_default=""),
|
|
sa.Column("model", sa.Text(), nullable=False, server_default=""),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.func.now(),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"updated_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.func.now(),
|
|
nullable=False,
|
|
),
|
|
)
|
|
|
|
op.create_table(
|
|
"messages",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column(
|
|
"conversation_id",
|
|
sa.Integer(),
|
|
sa.ForeignKey("conversations.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
),
|
|
sa.Column("role", sa.Text(), nullable=False),
|
|
sa.Column("content", sa.Text(), nullable=False, server_default=""),
|
|
sa.Column(
|
|
"context_note_id",
|
|
sa.Integer(),
|
|
sa.ForeignKey("notes.id", ondelete="SET NULL"),
|
|
nullable=True,
|
|
),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.func.now(),
|
|
nullable=False,
|
|
),
|
|
)
|
|
|
|
op.create_index("ix_messages_conversation_id", "messages", ["conversation_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index("ix_messages_conversation_id", table_name="messages")
|
|
op.drop_table("messages")
|
|
op.drop_table("conversations")
|