feat(ai): Paperclip-style env-var provider presets + zero-config local default

Two product decisions from tonight:

1. Public AI providers can now be published by an admin as named presets
   (lib/ai/types.ts's PublicAiPreset: name/baseUrl/model/apiKeyEnvVar).
   The admin names an env var, never a secret value - the actual key is
   whatever ops has set in the server's real environment, same custody
   model as the existing AI_SERVER_BASE_URL var. A new server route
   (app/api/ai/public/chat) resolves it and makes the call itself, which
   also sidesteps the CORS/wrong-base-URL failure class chatPublic hit
   earlier tonight. Users pick a preset from a dropdown in Settings -
   Answer with - no key field at all; personal BYOK (paste your own key)
   stays available as a secondary "Add your own key" option, not removed.
   Admin UI: new "Public - org-managed presets" card in the AI policy tab.

2. AI now defaults ON instead of requiring setup (lib/ai/auto-provision.ts):
   on first load, if no provider is chosen yet, probe OpenCode (this app
   auto-spawns `opencode serve` itself, so it's the one local option with
   zero external install step) then Ollama via the existing auto-discovery,
   and adopt whichever answers. Never overrides an explicit choice - only
   fires while provider is still null. Wired into both AI entry points
   (the Ask button and the Settings pane) so it resolves before either
   renders its "not configured" state.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Bernd Rodler
2026-08-07 14:01:00 +02:00
co-authored by Claude Sonnet 5
parent 1aa0a4686b
commit f121678e2a
13 changed files with 580 additions and 17 deletions
+19
View File
@@ -48,6 +48,24 @@ function validate(body: Partial<AiConsoleConfig>): string | null {
return 'publicProviderAllowlist must be an array of strings or null';
}
}
if (body.publicPresets !== undefined) {
if (!Array.isArray(body.publicPresets)) return 'publicPresets must be an array';
const ids = new Set<string>();
for (const preset of body.publicPresets) {
if (
typeof preset !== 'object' || preset === null ||
typeof preset.id !== 'string' || !preset.id ||
typeof preset.name !== 'string' || !preset.name ||
typeof preset.baseUrl !== 'string' || !preset.baseUrl ||
typeof preset.model !== 'string' || !preset.model ||
typeof preset.apiKeyEnvVar !== 'string' || !preset.apiKeyEnvVar
) {
return 'each publicPresets entry needs non-empty id, name, baseUrl, model, apiKeyEnvVar';
}
if (ids.has(preset.id)) return `duplicate publicPresets id "${preset.id}"`;
ids.add(preset.id);
}
}
if (body.retrievalEnabled !== undefined && typeof body.retrievalEnabled !== 'boolean') {
return 'retrievalEnabled must be a boolean';
}
@@ -83,6 +101,7 @@ export async function PUT(request: NextRequest) {
consentVersion: next.consent?.version ?? null,
serverModelAllowlistCount: next.serverModelAllowlist?.length ?? null,
publicProviderAllowlistCount: next.publicProviderAllowlist?.length ?? null,
publicPresetsCount: next.publicPresets.length,
}, ip);
return NextResponse.json(next);
} catch (error) {