Skip to content

Chat always runs the saved model, so Free models can't turn into the paid router - #16

Open
GrantCharge wants to merge 1 commit into
nextwork-projects:mainfrom
GrantCharge:fix/chat-uses-saved-model-upstream
Open

GrantCharge wants to merge 1 commit into
nextwork-projects:mainfrom
GrantCharge:fix/chat-uses-saved-model-upstream

Conversation

@GrantCharge

Copy link
Copy Markdown

Fixes #15

Problem

After switching OpenRouter back to Free models, an already-open chat panel kept sending its older pick, openrouter/auto ("uses your credits"). chatProvider trusted what the panel sent over the saved user_metadata.ai_model. So the Connect page said "Free models" and chat still spent credits.

Change

  • src/lib/llm/models.ts: new chatChoice(saved, asked). The saved choice wins. The panel's choice is used only when nothing is saved.
  • src/lib/llm/gate.ts: chatProvider uses chatChoice.
  • src/app/api/assistant/route.ts: comment updated.
  • src/components/Assistant.tsx:
    • saveChoice tells an open panel about the new pick, so a pick on Connect your AI or Settings shows in the header at once.
    • The panel reloads the saved choice on open and when the tab regains focus.
    • A pick made in the chat header is saved before the next question is sent.
  • src/lib/llm/models.test.ts: tests for chatChoice, including a stale openrouter/auto panel against a saved free choice.

Check-ins and the money plan already used the saved choice (pickProvider), so they are unchanged.

Tests

  • node src/lib/llm/models.test.ts passes. config and dispatch tests still pass.
  • tsc --noEmit and eslint pass on the changed files.
  • Not tested by hand in a running app.

Notes

  • Behaviour change: a model chosen only in the chat header is saved first, so it persists as the default for check-ins and the plan too. That was already true; the save now finishes before the question goes out.

🤖 Generated with Claude Code

…paid router

An open chat panel kept sending its older pick (openrouter/auto) after the user
switched to Free models elsewhere, and chatProvider trusted it over the saved
user_metadata.ai_model. The saved choice now wins; the panel's choice counts only
when nothing is saved. The panel also follows picks made on other pages, reloads
the saved choice on open and on tab focus, and saves its own pick before the next
question goes out.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat keeps using OpenRouter's paid router after switching back to Free models

1 participant