23 · In-app assistant chat
The same assistant as the email one, inside the plan portal: Assistant in the nav and a chat bubble (✦) on every page. Same model (ASSISTANT_MODEL), same key, same planner tools. Code: worker/src/chat.js, worker/src/routes/chat.js; UI frontend/src/pages/Assistant.tsx and components/chat/. Migration 0014.
“Ask about the plan, tell it what’s changed, or attach a quote or invoice to file.” Examples in the empty chat: “What’s still to pay this month?”, “Add a task to book the cake tasting”, or attach a quote and ask it to file it. “You’ll both see this chat.”
Replies
- Sending a message (
POST /api/chat/conversations/:id/messages) waits for the reply (“Thinking…”, “The assistant is replying…”). It runs in the request and is kept alive withwaitUntil, so the reply still lands for both of you if the page is closed mid-way. A reply stuck for 10 minutes is marked failed. - Up to 8,000 characters per message; the last 40 messages are sent as history.
CHAT_DAILY_LIMIT(default 200) assistant replies per day.- Without
ANTHROPIC_API_KEY: “The AI isn’t switched on yet” — chats still work between the two of you; nobody replies. ASSISTANT_DRY_RUN=1: it replies but saves nothing (Simulation badge).
Attachments
Up to 5 PDFs or photos per message, 4 MB each; big photos are shrunk in the browser first (“Attach a PDF or photo”). They go to Claude with that message only. Only the file names are stored, never the files.
It changes the plan, with Confirm cards
Ordinary changes are made straight away and listed under the message (“Changes made”). Marking a payment paid, a payment with a paid date, any delete, and changing master Setup appear as a Proposed change card with Confirm / Cancel (chat_pending, POST /api/chat/pending/:code/confirm|cancel). The change only runs when one of you presses Confirm; the model can’t confirm its own proposals. Status: pending / confirmed / cancelled / failed, with who resolved it.
It asks you questions
Question cards have tap-to-answer options, or “Or type your own answer…”. Either of you can answer, once.
| Where questions come from | Details |
|---|---|
Mid-conversation (ask_couple tool) |
when it needs something only you know; up to 3 per turn; one clear question per call, with short options when it’s one of a few choices |
| Daily check-in | at CHAT_CHECKIN_TIME UK time (default the brief’s time, else 08:00). It reviews the plan read-only and posts a “Questions from your planner” chat only when something is worth asking (up to 5), never repeating a recent question. CHAT_CHECKIN=off stops check-ins. |
| Any questions for us? button | runs a check-in on demand (POST /api/chat/checkin). If questions are still open it opens those instead of asking more. “Nothing to ask right now. The plan looks complete.” |
| Launch review (once) | the first cron run with this code did a fuller review (“Getting started: a few questions”, up to 8). Recorded in settings.chat_launch_checkin and never repeats (retried up to 3 times only if the model fails). |
From the email assistant (ask_in_app) |
the question appears in that email’s chat and can be answered there instead of by reply |
- Skip (“Not relevant: close it without answering, and don’t ask again”) marks a question skipped and by whom; check-ins are told never to ask it again (
POST /api/chat/questions/:messageId/:questionId/skip). - No pile-ups: the daily check-in waits while any questions from the past 7 days are still open; only one check-in runs at a time (
settings.chat_checkin_lock, 3-minute lock); one check-in per day (chat_checkin_last_date). - Answering a question sends it as a reply linked to that question (
reply_to).
The Assistant page
Chat list (Archived toggle), New chat, Any questions for us?, Notifications (notebook 24), Usage & cost (notebook 25), “← Back to chats”.
Routes
GET/PUT /api/chat/me (who you are, AI and push status, notification settings; PUT sets display name and/or notify), GET /api/chat/unread, GET/POST /api/chat/conversations, GET/PATCH /api/chat/conversations/:id, POST …/:id/messages, POST /api/chat/pending/:code/confirm|cancel, POST /api/chat/questions/:messageId/:questionId/skip, POST /api/chat/checkin.
Tables
chat_conversations (title, kind, source_ref, created_by, archived), chat_messages (role user / assistant / event, author, text, status done / thinking / failed, actions, attachment names, questions JSON, reply_to, tokens, dry_run), chat_pending, chat_reads. Test suite: worker/test-chat.mjs.