Skip to content

Commit 5d37374

Browse files
feat(service-settings): Setup → AI takes several providers, a model list each, one default and one structured-output model (#37696)
<!-- claude-projects-attribution: {"github_login":"hotlong"} --> _Requested by **Jack** · [project thread](https://claude.ai/code/project/chan_01EF41AQooqveF2DGD8nqPzS?thread=cmsg_01EF41AQooqveF2DGD8nqPzSH5VNV5CG7X8iMbPHYZ6PJm)_ Fixes #37683 ## What changes Setup → AI (`ai` settings namespace, `packages/services/service-settings`) goes from "pick one provider" to several providers at once. Only existing specifier kinds are used (`select`, `toggle`, `text`, `textarea`, `password`, `action_button`); no `packages/spec` change. - **Providers on/off.** `provider` keeps its key and stored values and becomes the **default provider**, always on. Every other provider gets a `<provider>_enabled` toggle in the Providers section (hidden for the default provider). Each provider section shows while it is the default or turned on (`${data.provider === 'x' || data.x_enabled === true}`). - **A model list per provider.** `<provider>_model` stays the provider's first model; new `<provider>_models` (textarea) lists further ids, one per line (a comma also separates). The gateway and Cloudflare lists keep their `provider/model` pattern per id. - **Keys unchanged.** One encrypted `password` field per provider, as before; no read echoes a value (pinned at the route). - **One default model, one structured-output model.** `default_model` (one of the default provider's models; blank = its first model) and `structured_output_provider` + `structured_output_model` (a separate knob; blank provider = the default provider, blank model = that provider's first model). - **Save rule.** A write predicate on the model keys (`registerAiModelRules`, registered by `SettingsServicePlugin` beside the manifest) judges the state after the whole save and refuses with `SETTINGS_VALIDATION` / `invalid_value`, `constraint.rule` naming the rule: `default_model_not_listed`, `default_model_without_provider`, `structured_output_provider_off`, `structured_output_model_not_listed`, `structured_output_model_without_provider`. A breach is refused once, at the first of its keys the save changes (the chosen model first), so a save that drops the default model from its list is refused at that list. Refusal copy is a module-local table in the eleven platform languages, held by `settings-copy-locale.test.ts`. - **Test connection per provider.** `test_<provider>` action buttons in each section; the default handler is the `ai/test` form check run for that provider (`aiProviderTestActionHandlers`, in the plugin's default map). The cloud host registers the live handlers over them. - **Reader for the runtime.** `resolveAiModelConfiguration(values)` (exported with `parseAiModelList`, `aiModelRuleBreaches`, `registerAiModelRules`, `AI_PROVIDERS`) returns the providers that are on with their models, the default model and the structured-output model. - **Hosted projection.** The new keys and the nine `test_<provider>` actions join the `ai` hidden set in `cloud-managed-settings.ts`; the served set is unchanged. - Translations for every new group, key, help and action in all eleven bundles; the `provider` group and label now read "Providers" / "Default provider". ## Why Phase 1 of objectstack-ai/cloud#5055 (「第一阶段先能把多个模型配置上」): a private Enterprise deployment can configure several models and the runtime can use them. No tiers, no sentinel values, no per-org keys. Fallback happens only at configuration time (the save rule); the resolver hands the runtime exactly the listed models. ### Legacy values A deployment that stored `provider` + `<provider>_model` before this reads unchanged, with no data rewrite: that provider on, that model its only model and the default (pinned: stored `provider: deepseek` + `deepseek_model` resolves to one provider, `deepseek-reasoner` default; a provider left at the manifest model resolves to that model). The cloud consumer (`packages/service-ai/src/plugin.ts` `buildAdapterFromValues`, live `ai/test`) still reads `provider` + `<provider>_model` exactly as before, so its boot behaviour does not move until its own card of cloud#5055 adopts `resolveAiModelConfiguration` after a pin move. ### Premise check Card premise re-run on `origin/main` 6d106a1: `git grep -n "key: 'provider'" -- packages/services/service-settings/src/manifests/ai.manifest.ts` → 1 hit (`:51`). Holds. Clause-②: yes (widening) Metadata-protocol: added ## Verification Local, `packages/services/service-settings` (deps built with `turbo run build --filter='@objectstack/service-settings^...'`): - `pnpm --filter @objectstack/service-settings typecheck` → clean - `pnpm --filter @objectstack/service-settings test` → 77 files, 1538 tests passed - New pins in `src/manifests/ai.manifest.test.ts` (13): two providers with two models each validate and resolve; a default outside the enabled models is refused with `constraint.rule: 'default_model_not_listed'`; a later list change that drops the default is refused at that list; structured-output provider off / model not listed refused; refusal in the caller's language; legacy single-provider values read as one provider with its model as default; no key value in the GET/PUT answers, and the refusal is `400 SETTINGS_VALIDATION` at the route; each provider's test handler checks that provider; the plugin registers the rule on every model key and the per-provider handlers. - `settings-visibility-declaration.pin.test.ts` corpus count 83 → 110 (27 new predicates: toggle, list and test button per provider), with the reason in place. - Derived gate families (`dispatch-gates.mjs --commands`): 72 derived, 70 run with exit 0, 2 NOT-MEASURED on their own prerequisite refusal (exit 3: `check:dual-build-cjs-loads` needs the full workspace build; `check-plugin-teardown-shape.mjs --self-test` did not reach its verdict in this tree), both left to CI. `dispatch-gates --ran` reconciles 72/72. - `eslint --no-inline-config` over the changed `.ts` files → clean. - `overlap-check`: merges cleanly with `origin/main`; textual conflict with #37668 (knowledge settings) only in the `visible` corpus count line of `settings-visibility-declaration.pin.test.ts` (83 → 79 there, 83 → 110 here). Whichever lands second sets it to 106. Not a #5027 / #5024 PR. ## Acceptance notes - The global "Test connection" (`ai/test`) still tests the default provider; the per-provider buttons sit in each section. - The console renders `textarea` with no pattern hint; a malformed list id is refused at save with `invalid_format`. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. (Not touched.) - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01Q4EjjNppk7ewjwv9pfTYgc)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Q4EjjNppk7ewjwv9pfTYgc <!-- signed: epic:#5055#1 · hotlong · session_01Q4EjjNppk7ewjwv9pfTYgc --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6b60f88 commit 5d37374

21 files changed

Lines changed: 1421 additions & 124 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@objectstack/service-settings': minor
3+
---
4+
5+
feat(service-settings): Setup → AI takes several providers at once, a model list per provider, one default model and one structured-output model
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: added
9+
10+
The `ai` settings page chose one provider. It now lets several be on at once. `provider` keeps its key and its stored values and becomes the default provider, always on; every other provider is turned on with its new `<provider>_enabled` toggle, and its section shows while it is on. Each provider keeps its one encrypted key field, never echoed by a read, and gains `<provider>_models`, further model ids one per line beside its existing `<provider>_model`, and its own "Test connection" (`ai/test_<provider>`, a form check until the AI runtime registers the live one). `default_model` picks the default model among the default provider's models, and `structured_output_provider` / `structured_output_model` pick the model strict structured-output calls use, a knob separate from the default model; a blank value means the provider's first model.
11+
12+
A save is refused (`SETTINGS_VALIDATION`, `invalid_value` at the key it changes, `constraint.rule` naming the rule) when the default model is not among the default provider's models, when the structured-output provider is off, or when the structured-output model is not among its provider's models. The refusal is written in the caller's language.
13+
14+
Values stored before these keys existed read unchanged and need no rewrite: a stored `provider` with its `<provider>_model` and none of the new keys is that provider on, that model its only model and the default. `resolveAiModelConfiguration(values)`, exported with `parseAiModelList`, `aiModelRuleBreaches` and `registerAiModelRules`, reads the configuration that way for the AI runtime: the providers that are on with their models, the default model and the structured-output model.

‎packages/services/service-settings/src/cloud-managed-settings.ts‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ export interface CloudManagedNamespaceRule {
6161
/**
6262
* The hosted projection. ONE table, read by every door.
6363
*
64-
* `ai` hides per key: the provider and its per-provider sections (model and
65-
* credentials), the generation defaults (temperature, max output, timeout) and
66-
* the embedder (its provider, model and credentials). The conversation-title
67-
* and observability keys stay served. Its `test` / `test_embedder` buttons
68-
* exercise the hidden credentials, and `reset` clears every stored `ai` row,
69-
* hidden ones included, so all three are refused.
64+
* `ai` hides per key: the providers, the default and structured-output models
65+
* and the per-provider sections (models and credentials), the generation
66+
* defaults (temperature, max output, timeout) and the embedder (its provider,
67+
* model and credentials). The conversation-title
68+
* and observability keys stay served. Its `test` / `test_embedder` buttons and
69+
* each provider's `test_<provider>` exercise the hidden credentials, and `reset`
70+
* clears every stored `ai` row, hidden ones included, so all of them are refused.
7071
*/
7172
export const CLOUD_MANAGED_HIDDEN_SETTINGS: Readonly<Record<string, CloudManagedNamespaceRule>> = Object.freeze({
7273
storage: {
@@ -76,21 +77,28 @@ export const CLOUD_MANAGED_HIDDEN_SETTINGS: Readonly<Record<string, CloudManaged
7677
},
7778
ai: {
7879
keys: Object.freeze([
79-
'provider',
80-
'gateway_model', 'gateway_api_key',
81-
'openai_api_key', 'openai_model', 'openai_base_url',
82-
'anthropic_api_key', 'anthropic_model',
83-
'google_api_key', 'google_model',
84-
'deepseek_api_key', 'deepseek_model',
85-
'dashscope_api_key', 'dashscope_model',
86-
'cloudflare_account_id', 'cloudflare_gateway_id', 'cloudflare_api_key', 'cloudflare_model',
87-
'siliconflow_api_key', 'siliconflow_model',
88-
'openrouter_api_key', 'openrouter_model',
80+
'provider', 'default_model',
81+
'gateway_enabled', 'openai_enabled', 'anthropic_enabled', 'google_enabled', 'deepseek_enabled',
82+
'dashscope_enabled', 'cloudflare_enabled', 'siliconflow_enabled', 'openrouter_enabled',
83+
'gateway_model', 'gateway_models', 'gateway_api_key',
84+
'openai_api_key', 'openai_model', 'openai_models', 'openai_base_url',
85+
'anthropic_api_key', 'anthropic_model', 'anthropic_models',
86+
'google_api_key', 'google_model', 'google_models',
87+
'deepseek_api_key', 'deepseek_model', 'deepseek_models',
88+
'dashscope_api_key', 'dashscope_model', 'dashscope_models',
89+
'cloudflare_account_id', 'cloudflare_gateway_id', 'cloudflare_api_key', 'cloudflare_model', 'cloudflare_models',
90+
'siliconflow_api_key', 'siliconflow_model', 'siliconflow_models',
91+
'openrouter_api_key', 'openrouter_model', 'openrouter_models',
92+
'structured_output_provider', 'structured_output_model',
8993
'temperature', 'max_tokens', 'request_timeout_ms',
9094
'embedder_provider', 'embedder_api_key', 'embedder_model', 'embedder_base_url',
9195
'embedder_dimensions', 'embedder_batch_size',
9296
]),
93-
actions: Object.freeze(['test', 'test_embedder', 'reset']),
97+
actions: Object.freeze([
98+
'test', 'test_embedder', 'reset',
99+
'test_gateway', 'test_openai', 'test_anthropic', 'test_google', 'test_deepseek',
100+
'test_dashscope', 'test_cloudflare', 'test_siliconflow', 'test_openrouter',
101+
]),
94102
provides: 'the AI provider, its model and credentials',
95103
},
96104
});

‎packages/services/service-settings/src/index.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ export {
189189
aiEmbedderSettingsSpecifiers,
190190
withAiEmbedderSection,
191191
aiTestEmbedderActionHandler,
192+
// The `ai` model configuration — the providers that are on, their models,
193+
// the default and structured-output models — as the AI runtime reads it,
194+
// and the save rule that keeps the chosen models among them.
195+
AI_PROVIDERS,
196+
resolveAiModelConfiguration,
197+
aiModelRuleBreaches,
198+
parseAiModelList,
199+
registerAiModelRules,
200+
type AiProviderId,
201+
type AiProviderModels,
202+
type AiModelChoice,
203+
type AiModelConfiguration,
204+
type AiModelRule,
205+
type AiModelRuleBreach,
192206
} from './manifests/index.js';
193207

194208
// Re-export the spec types for convenience so plugin authors only need

0 commit comments

Comments
 (0)