Skip to content

feat(chat): run Chat on the model and effort picked in the menu (W4-03) - #2032

Merged
gkhngyk merged 20 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-engine-model
Nov 4, 2026
Merged

gkhngyk merged 20 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-engine-model

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Chat's engine runs on the model and effort picked in the model menu (CHAT-16 items 5, 12 and 23; Wave 4 plan W4-03). Until now it always picked Auto's models (agent-driver.ts said so).

  • Models (engine-model.ts):
    • Auto stays: Haiku 5.5 reads, Sonnet 5.5 writes.
    • A Claude model picked in the menu does both phases on an Anthropic key: Ansvisor's, or the workspace's own Anthropic key. Its budget is priced by its catalog id.
    • A model through OpenRouter runs in one phase on OPENROUTER_API_KEY. None is offered at launch (decision 1 B); without the key the run takes Auto, and the menu leaves such models out.
    • Another provider's own key keeps running its own model, as before. W4-06 routes picks by provider.
  • Effort: Claude's own effort setting.
    • Normal leaves the model's default (medium on Haiku and Opus 5.5, high on Sonnet 5.5).
    • High is one level up: high, or xhigh on Sonnet.
    • Max is max.
    • High and Max get 1.5x / 2x room to write, for the thinking, and the reads' budget already scales with effort (readBudget).
    • On OpenRouter, effort becomes reasoningEffort.
  • Checked again as the run opens (runModelChoice):
    • the plan, so the free trial runs Auto at Normal (runChoiceOf);
    • once a run, the catalog (W4-01's selected). A dropped model runs Auto, and the run says so in one step: "Ran on Auto · The model this chat used is no longer available". If the check can't be read, the model is kept.
  • Agents: their saved model and effort (already written to chat_runs by agent-driver.ts) now run the same way, under the same plan check.
  • engine.ts gets only the thin connection: runModelChoice, the one step, and the choice passed to resolveChatModels.

Stacked on #2031. Merges together with W4-01 and W4-02.

Related issue

None. Chat Wave 4 plan, W4-03.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Pick Sonnet 5.5 at High in the model menu and ask a question. The staff Debug view shows the run's model and effort.
  2. cd web && yarn vitest run src/lib/chat/engine-model.test.ts src/lib/chat/engine.test.ts -t "model".

Opus 5.5 is hidden (tested: false, W4-01) until a real run of Chat's test set passes (W4-35); an agent or chat saved on it runs Auto, with no catalog check.

No migration. Optional new web environment variable: OPENROUTER_API_KEY. No offered model uses it at launch.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (1d3a2cc), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41525031207): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

cihan-gyk and others added 12 commits November 2, 2026 15:14
# Conflicts:
#	server/src/lib/brand-access-policies.test.js
#	supabase/schema.sql
#	web/src/lib/chat/schema.test.ts
#	web/src/types/supabase.ts
… tone, never a price (W4-01)

- The daily price sync keeps each model's supported parameters and context
  length (00462).
- The API server answers GET /api/internal/chat/models with the offered
  models' multiplier labels, a tone (green under 1x, amber from 3x), whether
  the price moves by the hour, whether the catalog dropped a model, the count
  of chat models that can call tools and the last sync. CRON_SECRET only,
  not counted by the per-IP limiter.
- The web offers Claude's three tested models (lib/chat/models.ts, Wave 4
  decision 1 B) and answers GET /api/chat/models, with "Your key" on the own
  key's models; it still lists them when the API server doesn't answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…4-02)

- The model button opens the menu: Auto (Default, Haiku 5.5 reads, Sonnet
  5.5 writes, 1x), the offered models with their multipliers (green under
  1x, amber from 3x), "Prices from OpenRouter, updated today. 1x = Auto.",
  Effort (Normal, High, Max), the own-key row, the month's AI usage with its
  reset, and the plan. No dollar anywhere.
- The pick goes with each message of the chat and is kept on its run; a
  chat opens on its latest run's pick, a new one on Auto.
- The server checks it again as the run starts: an offered model only, and
  Auto at Normal in the free trial (Wave 4 decision 2 B).
- Help: help/chat/models.md (approved: false).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A Claude model picked in the menu reads and writes on an Anthropic key;
  Auto keeps Haiku reading and Sonnet writing. A model through OpenRouter
  (none offered yet) runs in one phase on OPENROUTER_API_KEY, and without
  it the run takes Auto. Another provider's own key keeps its model.
- Effort is Claude's own setting (Normal: the model's default; High: one
  level up; Max: max), with 1.5x / 2x room to write, and the reads' budget
  as before.
- The run's pick is checked again as it opens: the plan (Auto in the free
  trial), and once against the catalog: a dropped model runs Auto, with one
  "Ran on Auto" step.
- An agent's saved model and effort run the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…un, Opus 5.5 hidden for now (W4-01)

Each model Chat may run is listed with `tested`; only tested ones are
offered in the menu, asked of the price catalog, or accepted by the engine,
and a chat or agent that picked one not tested runs Auto. At launch that is
Haiku 5.5 and Sonnet 5.5; Opus 5.5 waits for its run of the test set (owner,
2026-11-02).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Opus 5.5 hidden until tested: a pick of a model not offered, kept from
before, now runs Auto instead of being refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Opus 5.5 hidden until tested: a saved pick of it (an agent's, or a chat's)
runs Auto, with no catalog check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…their own mounts (W4-01)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 2, 2026
cihan-gyk and others added 5 commits November 3, 2026 04:55
…ature/chat-model-catalog

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…talog, keeping the branch's tree

The squash's tree equals feature/chat-wave4-db's final head, merged just before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at-model-menu

Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	web/src/components/chat/composer/chat-composer.tsx
#	web/src/lib/chat/engine.ts
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Nov 3, 2026
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
…menu

# Conflicts:
#	web/src/app/api/chat/models/route.test.ts
#	web/src/app/api/chat/models/route.ts
#	web/src/components/chat/composer/chat-composer.tsx
#	web/src/lib/chat/engine.ts
#	web/src/lib/chat/model-menu.test.ts
#	web/src/lib/chat/models.ts
# Conflicts:
#	web/src/lib/chat/agent-driver.ts
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
gkhngyk
gkhngyk previously approved these changes Nov 4, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

…-model

# Conflicts:
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit 494e0d3 into ansvisor:main Nov 4, 2026
7 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 5, 2026
The Agent Center article had "Let an agent publish on its own" twice,
from two pull requests. Merge them into one section that keeps both
sections' facts: publishing new pages on Webflow, WordPress and Wix as
well as CMS drafts, the two switches with Full auto, the Manager's
read-only switch, At most a day (1 to 20, 5 by default), the reasons a
page still waits for a click, and the reset after a change. Add that it
needs Growth and up and only shows where the workspace has it.

"On your own AI key" said every agent runs on the workspace's own key.
Since agents run on their own model (#2032) and a picked model runs on
its provider's key, then the OpenRouter key, then the AI limit (#2033),
that holds for agents on Auto only: say so.


Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

Co-authored-by: Claude <[email protected]>
gkhngyk pushed a commit that referenced this pull request Nov 5, 2026
The Model step of the agent form (Agent Center > new or edit agent) said
"Runs on your {provider} key" from Auto's key alone. Since #2032 an agent
runs on its own model, and since #2033 a picked model runs on the key for
its provider, then the workspace's OpenRouter key, then Ansvisor's key on
the monthly AI limit. So an agent on Fast or Best writing in a workspace
whose own key is OpenAI ran on the AI limit while the form said OpenAI.

The line and Max per run's note now follow the model the form has chosen,
as the engine picks its key:
- Auto: the key Auto runs on, else the monthly AI limit;
- a picked model: the own key for its provider, else the OpenRouter key,
  else the monthly AI limit;
- the free trial, and a model no longer offered, run Auto: Auto's key.

The order lives in one place: pickedModelKeyOrder and pickedModelOwnKey
(lib/chat/models.ts, safe in the browser). resolvePickedModelKey loops
over pickedModelKeyOrder, the model menu's "Your key" uses
pickedModelOwnKey, and the form's modelKeyProvider uses it with
runChoiceOf. The form's setup carries the providers of the own keys for
Chat (ownChatKeyProviders, no key decrypted) and whether the plan runs a
picked model (modelChoiceOpen).


Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

Co-authored-by: Claude <[email protected]>
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.

3 participants