feat: keyless demo mode (canned first-run answers instead of a 401) - #28
Open
amal66 wants to merge 1 commit into
Open
feat: keyless demo mode (canned first-run answers instead of a 401)#28amal66 wants to merge 1 commit into
amal66 wants to merge 1 commit into
Conversation
Add a built-in keyless "demo" provider (lib/llm/providers/demo.ts, DEMO_MODEL = "mike-demo") that answers with a canned, context-aware placeholder plus a nudge to configure a key. The chat stream route falls back to it automatically when the chosen model's provider has no env or per-user key (resolveDemoFallback in routes/chat.ts). Frontend: "Demo (no key needed)" entry in the model dropdown, silent demo fallback on send in ChatInput (replaces the blocking ApiKeyMissingPopup), and a dismissible global ApiKeyBanner while no provider key is configured. Ported from the amal66/mike monorepo fork (origin/main, b3166dd); mechanical translation into the backend/ + frontend/ layout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEguyEgXa9JjCciXCcVemC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a built-in, keyless "demo" provider so a brand-new instance answers its first question with a canned, context-aware placeholder — plus a nudge to configure a key — instead of a raw provider 401. First-run users and zero-setup demos work with no API keys at all.
Changes
Backend:
backend/src/lib/llm/providers/demo.ts(new): demo provider registered via the registry (registerProvider+registerApiKeyProvider("demo", [])). Builds a deterministic, clearly-labelled reply that echoes the user's question, names any document filenames it can spot in the prompt, explains what a real model would do, and points at Settings → API Keys. No network call — works offline.backend/src/lib/llm/models.ts:DEMO_MODEL = "mike-demo".backend/src/lib/llm/index.ts:setupDemo()registered alongside the built-in providers.backend/src/routes/chat.ts:resolveDemoFallback()— if the requested model's provider has no env or per-user key, the chat stream runs onDEMO_MODELinstead of failing; an explicitly selected demo model or a keyed provider is returned unchanged.Frontend:
ModelToggle.tsx: "Demo (no key needed)" entry (newDemogroup) in the model dropdown.ChatInput.tsx: sending with an unavailable model silently falls back to the demo model instead of opening the blockingApiKeyMissingPopup(the popup remains in use for tabular reviews).components/shared/ApiKeyBanner.tsx(new) +(pages)/layout.tsx: dismissible global banner ("No AI provider key is set up… answering in demo mode") shown while no model provider key is configured; hidden on/accountpages; dismissal is per tab session.lib/modelAvailability.ts: the demo model is always available; theDemogroup maps to no key provider.Why
Today a fresh install (or a self-hoster who hasn't added a key yet) hits a hard error on the very first message. With demo mode, first-run users and journalist demos work with zero API keys: they get an immediate, clearly-labelled placeholder answer and two consistent nudges (the demo reply itself and the banner) toward Settings → API Keys. Documents never leave the workspace until a real key is added.
Testing
npm run build --prefix backend— passes (tsc, no errors).npm run build --prefix frontend— passes (next build;.env.localcreated from.env.local.example).npx vitest run src/lib/llm/__tests__— 20 tests passing (registry + models, from refactor: table-driven LLM provider registry #27).providerForModel("mike-demo") === "demo";streamChatWithTools({ model: DEMO_MODEL, ... })streams the full reply throughonContentDelta, labels it Demo mode, and namesnda.pdffrom the prompt;completeTextreturns the truncated question for title generation.npm install --no-save vitest); tests are ready to run atop a test-harness PR once one lands.Provenance
All changes are mechanical ports of code in amal66/mike@origin/main (commit b3166dd); exceptions:
chat.routes.ts→routes/chat.tsindemo.ts;apps/api/...→backend/...inModelToggle.tsx).resolveEffectiveTabularModeladdition tomodelAvailability.tsand itsFullScreenLoaderchange inlayout.tsxbelong to unrelated fork features and were not ported.Credits & prior art
🤖 Generated with Claude Code
https://claude.ai/code/session_01CEguyEgXa9JjCciXCcVemC