All documentation

AI Admin Guide

/admin/ai/* — every platform admin role can read this section (same as the rest of the Operations Center); mutations require the manage_ai capability (admin/super_admin only — see docs/AI_SECURITY.md). Data layer: src/lib/admin/ai-queries.ts, same pattern as every other src/lib/admin/*-queries.ts file.

Overview — /admin/ai

30-day KPIs (cost, tokens, calls, success rate), a provider-status grid, cost-by-provider breakdown, and the tail of ai-*-component errors from the in-memory logger (src/lib/observability/logger.ts — resets on process restart, same constraint as /admin/monitoring).

Providers — /admin/ai/providers

One row per AI_PROVIDERS catalog entry (src/lib/ai/registry/ providers.ts): live healthCheck() status (healthy / degraded / unreachable / unconfigured), whether it's configured, which env var enables it, latency, and any health-check message. An unconfigured provider shows unconfigured from a real StubAIProvider, never a crash — see docs/AI_PROVIDER_GUIDE.md.

Cost — /admin/ai/cost

14-day daily cost/call trend (bar charts, reusing the existing BarChart component — no new charting library), 30-day totals, and cost/calls broken down by provider, feature, and model. All figures come from ai_usage_events, written once per provider call by AIProviderManager via calculateCost(). See docs/AI_COST_GUIDE.md for the pricing-accuracy disclaimer behind every number here.

Prompts — /admin/ai/prompts

Every code-defined default prompt (PROMPT_DEFAULTS, src/lib/ai/ prompts/index.ts) paired with its optional DB override (ai_prompt_templates) — the same "global default + admin override" shape as Feature Flags. Expand "Code default" to see the shipped prompt text; a role with manage_ai can add/edit/clear an override inline. An override takes effect on the next AI call for that prompt key — no redeploy needed, since AIPromptManager.resolve() reads the DB row at render time. Every override write is audit-logged (admin_ai_prompt_updated).

Conversations — /admin/ai/conversations

Paginated conversation metadata browser: user, feature, message count, created/updated timestamps. Message content is never decrypted here by design — see docs/AI_SECURITY.md's Conversation encryption section. Use this to spot unusually long or frequent conversations, not to review what was said.

What's intentionally not here

  • No live token-by-token conversation viewer (would require decrypting

content — deliberately out of scope).

  • No per-organization AI spend breakdown beyond what costByFeature

already implies — ai_usage_events doesn't carry organization_id today (features are user-scoped, not org-scoped, the same as ai_coach/ai_journal/ai_news billing gates); adding one would be a straightforward additive migration if org-level AI cost reporting becomes a requirement.

  • No RAG knowledge-base re-indexing UI — KnowledgeIngestionService is

invoked programmatically today, not from an admin page.