Skip to content

feat(chat): let Admins choose Chat's model providers, and keep OpenRouter calls off data collection (W4-34, 00469) - #2036

Merged
gkhngyk merged 13 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-model-providers
Nov 5, 2026
Merged

gkhngyk merged 13 commits into
ansvisor:mainfrom
cihan-gyk:feature/chat-model-providers

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Admins choose which model providers Chat may use, and Chat's OpenRouter calls ask for providers that keep no data (Wave 4 plan, EK · W4-34). Owner decision, 2026-11-02 evening: "a US company doing business globally".

  • Settings › Chat › Model providers:

    • Anthropic is always on, because Auto runs on its models.
    • OpenAI and Google are on by default.
    • DeepSeek is off by default.

    An Admin turns each on or off; everyone else reads it. Each change goes in the Activity log ("Turned off OpenAI models in Chat").

  • Data: chat_settings.model_providers jsonb (00469) keeps the Admin's choices. A provider not chosen takes its default from lib/chat/model-providers.ts, so a provider added later needs no migration. A provider not on the list is off.

  • Enforced on the server:

    • a provider that is off has no model in the model menu (/api/chat/models);
    • the engine runs Auto in place of one of its models, for a person's chat, an agent and a scheduled run alike. It checks once per run and says so in one step: "Ran on Auto · Your Admin turned off this model's provider".
  • OpenRouter (lib/agent/openrouter.ts, used by buildAgentModel, so Chat's and the Agent's OpenRouter calls):

    • every request carries provider.data_collection: "deny";
    • a DeepSeek model runs only on US or EU hosts (provider.only, no fallbacks): DeepInfra, Together, Fireworks, Parasail, Crusoe, Azure and Nebius. The list was checked against OpenRouter's providers list on 2026-11-03.
    • The API server's analysis calls (server/src/lib/ai-provider.js) are not changed. A note on checking their models with deny comes separately.
  • Help: "Model providers" in help/settings/chat-rules.md (approved: false).

Today only Claude models are offered, so no model can be turned off yet. The switch matters once W4-35 adds tested GPT, Gemini or DeepSeek models.

Stacked on #2033. Merged, not rebased.

Related issue

None. Chat Wave 4 plan, EK · W4-34.

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. As an Admin, open Settings › Chat. Model providers lists Anthropic (no switch, "Always on"), OpenAI and Google (on) and DeepSeek (off, with the US or EU note).
  2. Turn DeepSeek on: the toast says so, and the Activity log has "Turned on DeepSeek models in Chat".
  3. As a Manager, you see On or Off with no switches.
  4. cd web && yarn vitest run src/lib/chat/model-providers.test.ts src/lib/agent src/lib/chat/model-menu.test.ts src/app/api/chat/models src/lib/actions/chat-settings.test.ts src/components/chat-access src/lib/chat/engine.test.ts -t "provider"

Needs migration on prod: 00469, after 00468.

No new environment variables.

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)

Screens: shown to the owner in a local preview (1024px, light and dark) and approved on 2026-11-03.

CI passed on this branch (82fc1b7), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41528322634): 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 4 commits November 2, 2026 23:59
…uter calls off data collection (W4-34, 00469)

- Settings › Chat gets Model providers: Anthropic (always on, Auto runs on
  it), OpenAI, Google and DeepSeek (off by default), each on or off for an
  Admin, logged in the Activity log. chat_settings.model_providers (00469)
  keeps the choices; a provider not chosen takes its default in the web.
- A provider that is off has no model in the model menu, and the engine
  runs Auto in place of one of its models, for chats, agents and scheduled
  runs, with "Ran on Auto · Your Admin turned off this model's provider".
- Chat's and the Agent's OpenRouter calls ask for providers that keep no
  data (provider.data_collection: "deny"); a DeepSeek model runs only on
  US or EU hosts, with no fallback. The API server's analysis calls are
  unchanged.
- Help: help/settings/chat-rules.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… OpenRouter's list (W4-34)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 5 commits November 3, 2026 05:19
# Conflicts:
#	web/src/app/api/chat/models/route.test.ts
#	web/src/app/api/chat/models/route.ts
#	web/src/lib/chat/model-menu.ts
…s as off

Auto on another provider's own key ran on that key's model even when an
Admin turned its maker off in Settings > Chat (DeepSeek through
OpenRouter, or OpenAI through an OpenAI or Azure key). resolveChatModels
now maps the own key's model to its maker and stops the run with a clear
error when that provider is off, rather than send the run there or move
to Ansvisor's key by itself.

A failed read of the provider choices now turns every provider that can
be turned off off, instead of falling back to the defaults.
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Nov 3, 2026
…odels whose maker an Admin turned off

Review on ansvisor#2103:
- generate_image no longer says "never refuse": it says don't claim Chat
  can't make images, and keeps Chat's rules (no real person's likeness, no
  insulting or misleading imagery of a competitor or anyone, no trademark
  the brand doesn't own).
- The provider switches of Settings › Chat (W4-34) apply to images: the
  model question offers only models whose maker is on, the precheck and
  the request refuse one that is off, and with every maker off Chat says
  it can't make images here. model-providers.ts is ansvisor#2036's, as it is.
- A request every provider refused, billing nothing, lets its hold go;
  picking an image of a set takes its own type and format.

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

# Conflicts:
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/lib/chat/engine.test.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.

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.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 4, 2026 17:26

The merge-base changed after approval.

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.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 4, 2026 20:43

The merge-base changed after approval.

@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 be46ae6 into ansvisor:main Nov 5, 2026
12 checks passed
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 5, 2026
ansvisor#2036 (model providers) changed model-menu.ts's imports; keep both its
provider imports and this branch's pickedModelOwnKey. The agent form
offers only Anthropic models (Auto, Fast, Best writing), which the
provider switches can't turn off, so the key line needs no change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
gkhngyk pushed a commit that referenced this pull request Nov 5, 2026
… Files (W4-08, 00476, 00477) (#2103)

* feat(chat): make images in Chat, pick one from the set and keep it in Files (W4-08, 00476)

Chat makes images now instead of refusing (CHAT-15 §E). Before the first
image of a chat it asks which image model to use, the options read from
the price data: the cheapest first and recommended, each with its
multiplier and its share of the monthly AI limit per image ("Your key"
on the workspace's own OpenRouter key). Each request makes four images
at 1K after a cost card that says how many, on which model, and their
share. When the limit left covers only some, the parts check asks first
("Create 1 image now"), with no image made before the answer.

The images run on OpenRouter, held and charged through W4-07's metering
at the provider's real cost, and are filed as one set in Files. Its card
shows every image, the selected one marked; the person picks another in
their own chat and downloads it as PNG, converted in the browser.

The engine change is thin: the parts check counts images at their
model's price, and a deliverable that filed itself is named, not filed
again. 00476 lets chat-files take JPEG, which Google's image models send.

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

* fix(chat): file JPEG image sets, check the AI limit before the card, and round image multipliers (00477)

Found in the preview of W4-08:
- chat_files' formats check knew PNG and WebP only, so a set of JPEG
  images (Google's image models) wasn't filed: 00477 adds 'jpg'.
- The model may skip the parts check: when the AI limit left covers only
  some of the images, the request's own check now sends it there before
  the card, so the person is asked first.
- Shares come rounded to two decimals, so Nano Banana 2 read 2.1x:
  multipliers are whole from 2x, as CHAT-16 item 11 writes them.

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

* refactor(chat): keep whose key images run on and each model's cost in images/access.ts

The Content Editor's images (W4-09) need the same: the workspace's own
OpenRouter key or Ansvisor's, and the image models with their multipliers
and shares. They move out of chat-images.ts as they are, with their tests.

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

* test(chat): read the saved image by its fields, as Node 20's Blob isn't jsdom's

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

* fix(chat): keep Chat's rules on image requests, and leave out image models whose maker an Admin turned off

Review on #2103:
- generate_image no longer says "never refuse": it says don't claim Chat
  can't make images, and keeps Chat's rules (no real person's likeness, no
  insulting or misleading imagery of a competitor or anyone, no trademark
  the brand doesn't own).
- The provider switches of Settings › Chat (W4-34) apply to images: the
  model question offers only models whose maker is on, the precheck and
  the request refuse one that is off, and with every maker off Chat says
  it can't make images here. model-providers.ts is #2036's, as it is.
- A request every provider refused, billing nothing, lets its hold go;
  picking an image of a set takes its own type and format.

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

* fix(chat): keep the image option's words in chatEngine.partial

A merge left two "partial" blocks in en.json, and the second, without
createImages, replaced the first, so typecheck failed in partial-limit.ts.
The duplicate is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3

* chore(chat): document image making on main's existing OPENROUTER_API_KEY entry

Main already lists OPENROUTER_API_KEY for Chat's model menu (W4-03), so
the merge left the key twice in web/.env.example. Chat's images now join
that entry's comment instead of a second key line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3

* fix(content-editor): refuse an AI image model whose maker an Admin turned off (W4-34)

The editor's image list already hides such a model (imageModelOptions),
but POST /api/content/drafts/{id}/images still ran any listed model. It
now checks imageModelOn first, as Chat's image precheck does, and refuses
before anything is held, charged or sent to the provider: 409 with
{ ok: false, code: 'provider_off', model }, and the panel says the
model's maker is turned off in Settings › Chat. A failed read refuses too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMenyNyxsr2Doq4CaQ3

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants