Add the Superbrain assistant: ephemeral chat drawer with automation proposals
release gate / check (push) Failing after 6m21s

The A+B slice: one conversation surface for questions AND automations.

Backend: POST /api/ai/chat — ephemeral multi-turn chat through the same
per-user AI resolution as everything else (BYO key -> plan-gated server
key -> 428). The server is stateless per request: the browser owns
history, the handler caps it anyway (40 messages accepted, last 20 used,
8k chars each, last turn must be the user's). Per-user rate limit
(30/hour, keyed on the account not the IP) and a 50-second budget inside
the proxy's 55s window.

The chat system prompt embeds agent.AutomationSchema — the SAME contract
text the compiler uses — so chat proposals and compiled tasks can never
drift. The model answers in a {reply, automation|null} JSON envelope; a
proposal reaches the client only if its spec passes agent.ValidateSpec
(invalid ones are dropped silently, the reply survives), and model-
invented channelIds are scrubbed so the UI always picks from the user's
real channels. A model that ignores the envelope degrades gracefully: raw
text becomes the reply, no proposal.

Web: components/assistant.tsx — floating launcher on every signed-in
screen (mounted once in AppShellWrapper so conversations survive in-app
navigation), Sheet drawer with markdown rendering (house ReactMarkdown +
remarkGfm pattern), proposal cards (channel picker for notify, editable
recipient for email, Create automation -> the regular tasks endpoint),
and Save to page (Markdown transcript into Pages — the only persistence,
by design). Enter sends, Shift+Enter newline.

Tests: envelope parsing, valid proposal + channelId scrub, invalid-spec
drop with reply intact, non-JSON graceful fallback, request validation
(empty/assistant-last/system-role), multi-turn passthrough, 428 path.
Full suite green (-race); web lint/SSR-eslint/build clean.

Docs: API.md chat endpoint, RUNNING.md 'two doors' framing (drawer +
Settings), README feature bullet, plan/notes docs updated.
This commit is contained in:
Andrew S Erwin
2026-10-28 19:38:45 -05:00
parent 167f74c6b4
commit 0848453732
8 changed files with 547 additions and 10 deletions
+1
View File
@@ -299,6 +299,7 @@ BYO-only) → else 428. Budgets are per user (`ai:user:<id>`) or shared
| DELETE | `/api/ai/config` | `{ok:true}` |
| POST | `/api/ai/test` | One probe completion through the resolved config → `{ok,source,model,reply}`; 428 when nothing is available; 502 with a truncated provider error |
| GET | `/api/ai/status` | `{userConfigured,userEnabled,serverAvailable,effective,plan}` — `serverAvailable` is already plan-gated; no secrets |
| POST | `/api/ai/chat` | Assistant chat (ephemeral; the browser owns history). `{messages:[{role:user\|assistant,content}]}` (≤40 sent, last 20 used, ≤8000 chars each, last must be `user`) → `{reply, proposal?}`. `proposal` = `{name,spec,summary}` when the model suggested an automation whose spec passes `agent.ValidateSpec` (invalid proposals are silently dropped; model-supplied `channelId`s are scrubbed — the UI picks real channels). Confirming a proposal is a regular `POST /api/agent/tasks`. Per-user limited (30/hour); 428 without AI; 50-second budget inside the proxy window |
| GET | `/api/alerts/check` | Undismissed bookmarks due within 15 minutes, soonest first |
| DELETE | `/api/alerts/{bookmarkId}` | `{ok:true}`; sets `alertSent` |
| GET | `/api/contacts` | Synced contacts with `_count.bookmarks` |