fix(ai): context extraction only on the user's own key; vendors by id (main green again) - #205
Merged
Merged
Conversation
main has been red since #203 bumped @bitbaum/ai-kit to 1.10, which put Gemini second in freeChain('BOTSMANN'). vendorChain() indexed [1] for OpenRouter, so a BYOK OpenRouter user's key would have been sent down the Gemini link. Look vendors up by id instead (code and both tests). Also clears the rest of the red verify from the same bump: prettier 3.x reformat of six files and the new next lint rule on relative window.location.href assignments (sign-out keeps its full reload). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Every professional-chat turn fired a second, unasked model call (extractAndSaveContext, fire-and-forget after the answer) on the shared free-tier Groq key. Standing rule (2026-09-25): free-tier keys are spent only when a person deliberately asks. Extraction now requires the user's own key and uses their provider; without one it returns before any call. Adds tests/__tests__/no-free-background-ai.test.ts: walks the import graph from the timer route (/api/rebuild, appcron-botsmann-rebuild), /api/warmup and /api/health and fails if any reaches a model client. Proven by mutation: importing lib/nlp into /api/rebuild fails it, and dropping the own-key guard fails the three new extractor cases. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
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.
There are two commits here. The first one gets
maingreen again so the second one can deploy.1.
fix(ai): context extraction runs only on the user's own keyAfter every professional-chat turn,
extractAndSaveContextfired a second model call (fire-and-forget, after the answer) on the shared free-tier Groq key. Nobody asked for that call. Standing rule (2026-09-25): free-tier keys are spent only when a person deliberately asks. Extraction now needs the user's own key and uses their provider. Without one it returns before making any call.New test
tests/__tests__/no-free-background-ai.test.tswalks the import graph from:/api/rebuild, which the box timerappcron-botsmann-rebuildcalls daily/api/warmup/api/healthIt fails if any of them reaches a model client. The walker gets checked against a synthetic graph first, so a walker that finds nothing can't pass.
I checked both guards by mutation. Each change below failed the tests (4 red):
@/lib/nlpinto/api/rebuildfails the graph testif (!own.apiKey) return 0;fails the 3 new extractor casesFindings so far:
/api/rebuildonly revalidates/blog, and/api/warmupruns local Transformers.js embeddings. Neither spends a free-tier key.2.
fix(ai): pick chain vendors by id, and make main green againmainhas been red since #203. That PR bumped ai-kit to 1.10, which put Gemini second infreeChain('BOTSMANN').vendorChain(1, …)was meant to pick OpenRouter, so a BYOK OpenRouter key would have gone down the Gemini link. Vendors are now looked up by id, in the code and in both tests. The same bump broke two other things, fixed here: a prettier reformat and the new next lint rule against relativewindow.location.href.pnpm run verifyis green locally: format, lint, typecheck, selfhost check, 306 tests, build.🤖 Generated with Claude Code