Skip to content

AI Chat: streaming, file attachments, model switcher, migration fix#150

Draft
Copilot wants to merge 8 commits intomainfrom
copilot/add-ai-chat-ui
Draft

AI Chat: streaming, file attachments, model switcher, migration fix#150
Copilot wants to merge 8 commits intomainfrom
copilot/add-ai-chat-ui

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 29, 2026

AI chat was missing streaming support, file attachments, and the AI tables (ai_conversations, ai_messages) were not registered in schemas-helper.ts — meaning autoInit would never create them.

Migration fix (bug)

aiConversationsTable and aiMessagesTable were missing from getAllSchemas() in schemas-helper.ts. Models were registered in db-utils.ts and exported from schema.ts, but autoInit uses schemas-helper.ts — so the tables were silently skipped during POST /api/ottaorm/init.

Streaming responses

New POST /api/ai/chat/stream endpoint. Workers AI uses real SSE via textGenerationStream(); other providers (OpenAI/Anthropic via AI Gateway) fall back to non-streaming with an SSE wrapper. The assistant message is saved after the stream completes.

Frontend reads the stream token-by-token with a ReadableStream reader, rendering incrementally with a cursor indicator. Old POST /api/ai/chat still works as fallback.

File attachments

Added attachments column to ai_messages (nullable JSON string: Array<{ url, name, type, size? }>). Both streaming and non-streaming endpoints accept attachments. Frontend uploads via existing /api/upload, shows pending previews, and renders images inline / files as links in message bubbles.

Model quick-switcher

Model list endpoint and settings panel already existed. Added a compact model dropdown directly in the chat header so users can switch without opening settings.

Files changed

  • ottabase/db/schemas-helper.ts — register AI tables for autoInit
  • ottabase/models/AiMessage.schema.ts — add attachments column
  • ottabase/models/AiMessage.ts — add attachments to writable/fields
  • worker/routes/ai-chat.ts — add handleAiChatStream, accept attachments
  • worker/routes/router.ts — register /api/ai/chat/stream
  • src/pages/ai/AiChatPage.tsx — streaming UI, attachment upload/preview, model switcher
  • src/__tests__/ai-chat.test.ts — tests for new schema columns, stream export, migration registration

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Implement AI chat interface for admin and demo page feat: AI chat interface with conversation history, admin settings, and OttaORM persistence Mar 29, 2026
Copilot AI requested a review from thinkdj March 29, 2026 17:29
Co-authored-by: thinkdj <688055+thinkdj@users.noreply.github.com>
Copilot AI changed the title feat: AI chat interface with conversation history, admin settings, and OttaORM persistence Merge latest origin/main into copilot/add-ai-chat-ui Mar 30, 2026
…n registration

- Fix AI tables (ai_conversations, ai_messages) missing from schemas-helper autoInit
- Add POST /api/ai/chat/stream endpoint with SSE streaming for Workers AI
- Add attachments column to ai_messages schema for multimodal file uploads
- Add file attachment UI (upload via /api/upload, preview in chat)
- Add model quick-switcher dropdown in chat header
- Add streaming response rendering with token-by-token display
- Update tests for new schema columns and migration registration

Agent-Logs-Url: https://github.com/thinkdj/ottabase/sessions/abbda454-d313-4dce-8a97-2ddf57f2b60b
Copilot AI changed the title Merge latest origin/main into copilot/add-ai-chat-ui AI Chat: streaming, file attachments, model switcher, migration fix Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants