Commit 294eca0
ai runtime: provider-agnostic stack, settings UI, site editor rewire
Replaces the ambient-only Claude Agent SDK handler with a unified AI
runtime at `server/ai/`:
- drivers: Anthropic (claude-agent-sdk), OpenAI (@openai/agents),
Ollama placeholder. All API-key authed; selected via a per-call
`OpenAIProvider` / `Options.env` injection — never the process env.
- credentials: AES-256-GCM at-rest encryption via Bun's
crypto.subtle; master key from PAGE_BUILDER_SECRET_KEY env (dev
fallback to .tmp/secret.key). CredentialView is the only shape
that crosses the wire (gated by ai-credentials-never-leak).
- tools: site-scope toolset (port of the 22 page-builder tools) as
TypeBox `AiTool[]`, scoped via `selectToolsForScope`. Anthropic
driver translates TypeBox → Zod for the SDK's tool() API; OpenAI
driver translates straight to JSON Schema.
- conversations: ai_conversations + ai_messages tables (per user +
scope), with a nightly purge tick for soft-deleted rows > 30d.
- handlers: POST /admin/api/ai/chat/:scope (NDJSON stream),
/tool-result, /credentials CRUD, /conversations CRUD,
/providers/:id/models, /defaults/:scope. All capability-gated.
- admin UI: /admin/ai workspace with Providers + Defaults tabs;
site editor's AI panel now POSTs /admin/api/ai/chat/site with a
lazily-created conversation row and a model/credential picker
sourced from the site default. Popovers use the existing
ContextMenu primitive for proper anchoring + auto-flip.
- three new capabilities: ai.use, ai.providers.manage,
ai.audit.read.
- architecture gates: ai-driver-isolation, ai-credentials-never-leak,
ai-tools-typebox-only, ai-handlers-capability-gated.
The legacy `server/handlers/agent/*` and its five gate tests are
deleted; their behaviour now lives in `server/ai/` + the new gates.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 0bf08c8 commit 294eca0
78 files changed
Lines changed: 9902 additions & 2346 deletions
File tree
- docs/plans
- scripts
- server
- ai
- conversations
- credentials
- defaults
- drivers
- handlers
- runtime
- tools
- site
- auth
- db
- handlers/agent
- src
- __tests__
- agent
- architecture
- admin
- ai
- pages
- ai
- tabs
- site
- agent
- panels/AgentPanel
- toolbar
- core
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
50 | 62 | | |
51 | 63 | | |
52 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments