fix(providers): apply the review of PR #988

Five reviewers (Fable 5.1, Opus 5.5, Sonnet 5.5, Codex GPT-6 Astra, Codex
GPT-6.1 Sol) found no behavior or security regression; this commit applies
what they asked for.

Settings dialog: the automatic model list fetch only fills the list, which
waits behind 'Browse models'; it no longer opens the picker (the modal picker
took the focus from whatever the user was typing) and shows no error of its
own. One list request per provider at a time, so a click during the automatic
fetch sends nothing twice; the baseline that detects freshly entered
credentials is taken on every visit of a provider page; SGLang's prefilled
local example URL triggers no fetch. Entries saved with Azure's old
placeholder URL still count as having no URL. The base URL field of Azure and
of the custom preset is labelled required (new dictionary key baseUrlRequired).

Smaller code: the PROVIDER_INFO alias is gone (three files and the tests
import PROVIDERS), as are three logo values no code read, two unused type
re-exports, three unused exports and SINGLE_SYSTEM_PROVIDERS (the chat route
reads the record). Renamed for clarity: REQUIRED_KEY_VARS, requiredKeyEnv,
configuredUrl, LocalizedText. Seven stale comments rewritten; the custom
preset's note shortened.

Tests: the matrix gains six override shapes (a Vertex key alone, AWS keys with
a session token, headers with a URL, a trusted URL with a key, a key with a
server model's URL variable, '/' alone), 5843 rows; the new rows were
regenerated on the pre-refactor code and match it. The matrix and the server
credential tests clear every variable they read; the admin variable table
covers every provider; a test that derived its expectation from the function
under test is gone; the singleSystem, listNeedsNoKey, sdkKnowsEndpoint and
auto-detection sets are spelled out.

Docs: the READMEs say 25 providers and name the OpenAI-compatible preset; the
AI_PROVIDER lists are complete; the Azure example URL has its /openai suffix;
'Adding a Provider' names the tests to update.
This commit is contained in:
dayuan.jiang
2026-10-12 21:17:51 +09:00
parent 65625ba212
commit 75ffc32a49
29 changed files with 1880 additions and 161 deletions
+1 -1
View File
@@ -151,7 +151,7 @@ npm run dev
### 模型与服务商
支持 AWS Bedrock(默认)、OpenAI、Anthropic、Google AI、Google Vertex AI、Azure OpenAI、Ollama、OpenRouter、AIHubMix、DeepSeek、SiliconFlow、SGLang、Vercel AI Gateway、腾讯云 EdgeOne、字节跳动豆包、ModelScope、智谱 GLM、通义千问、七牛云、Kimi、MiniMax、Novita、小米 MiMo、Atlas Cloud 共 24 家。各家的环境变量和注意事项见[服务商配置指南](./ai-providers.md)。
支持 AWS Bedrock(默认)、OpenAI、Anthropic、Google AI、Google Vertex AI、Azure OpenAI、Ollama、OpenRouter、AIHubMix、DeepSeek、SiliconFlow、SGLang、Vercel AI Gateway、腾讯云 EdgeOne、字节跳动豆包、ModelScope、智谱 GLM、通义千问、七牛云、Kimi、MiniMax、Novita、小米 MiMo、Atlas Cloud,以及一个可填任意地址的 OpenAI 兼容预设(vLLM、LM Studio、网关),共 25 家。各家的环境变量和注意事项见[服务商配置指南](./ai-providers.md)。
**选哪个模型**:这项任务要生成格式严格的长文本(draw.io XML),请选能力较强的模型,小模型容易画出错误的图。
+4 -3
View File
@@ -132,7 +132,7 @@ AI_MODEL=your-deployment-name
```bash
AZURE_API_KEY=your_api_key
AZURE_BASE_URL=https://your-resource.openai.azure.com # AZURE_RESOURCE_NAME 的替代方案
AZURE_BASE_URL=https://your-resource.openai.azure.com/openai # AZURE_RESOURCE_NAME 的替代方案
AI_MODEL=your-deployment-name
```
@@ -325,7 +325,7 @@ MIMO_BASE_URL=https://token-plan-cn.xiaomimimo.com/v1
### 任何 OpenAI 兼容接口(custom)
上面没有列出的服务(vLLM、LM Studio、LiteLLM、API 网关),在设置里选择 **OpenAI-compatible**,填入它的地址和 key;服务端不校验 key 时填任意非空内容即可。多条 system 消息会合并成一条(开源模型的对话模板通常要求这样),`<think>` 里的推理内容会从回复里分离出来。
上面没有列出的服务(vLLM、LM Studio、LiteLLM、API 网关),在设置里选择 **OpenAI-compatible**,填入它的地址和 Key;服务端不校验 key 时填任意非空内容即可。多条 system 消息会合并成一条(开源模型的对话模板通常要求这样),`<think>` 里的推理内容会从回复里分离出来。
```bash
CUSTOM_API_KEY=your_api_key
@@ -342,7 +342,7 @@ AI_MODEL=your_model_id
如果您配置了**多个** API 密钥,则必须显式设置 `AI_PROVIDER`:
```bash
AI_PROVIDER=google # 或:openai, anthropic, aihubmix, deepseek, siliconflow, doubao, azure, bedrock, openrouter, ollama, gateway, sglang, modelscope, minimax, glm, qwen, kimi, qiniu, mimo
AI_PROVIDER=google # 或:openai, anthropic, google, vertexai, azure, bedrock, ollama, openrouter, aihubmix, deepseek, siliconflow, sglang, gateway, edgeone, doubao, modelscope, glm, qwen, qiniu, kimi, minimax, novita, mimo, atlascloud, custom
```
## 服务端多模型配置
@@ -466,3 +466,4 @@ TEMPERATURE=0 # 输出更具确定性(推荐用于图表)
需要在地址输入框下方显示提示,或在选择器里显示说明的服务商,在记录里加 `baseUrlHint` 或 `note` 对象,四种界面语言(`en`、`zh`、`ja`、`zh-Hant`)都要写。不能在线列出模型的服务商不写 `modelList`,改写一个短的 `models` 列表。
2. 在 `env.example` 里加上 `ACME_API_KEY` 和 `ACME_BASE_URL`(有一个单元测试检查每条记录的变量名都出现在里面)。
3. 在 `docs/en`、`docs/cn`、`docs/ja` 的本文档里各加一节说明。
4. 把它加进 `tests/unit/provider-matrix.test.ts` 开头的两个清单(`MATRIX_PROVIDERS` 和 `MATRIX_MODEL_IDS`),用 `npx vitest run tests/unit/provider-matrix.test.ts -u` 重新生成行为快照;新增的行都属于这家服务商,已有的行不能变。`tests/unit/providers.test.ts` 写明了选择器的分组和会改变服务端行为的服务商集合(自动检测、只接受一条 system 消息),也要加进去。三份 README 里的服务商数量和本文档的 `AI_PROVIDER` 可选值清单同样要改。
+3 -2
View File
@@ -147,7 +147,7 @@ Or use a custom endpoint instead of resource name:
```bash
AZURE_API_KEY=your_api_key
AZURE_BASE_URL=https://your-resource.openai.azure.com # Alternative to AZURE_RESOURCE_NAME
AZURE_BASE_URL=https://your-resource.openai.azure.com/openai # Alternative to AZURE_RESOURCE_NAME
AI_MODEL=your-deployment-name
```
@@ -357,7 +357,7 @@ If you only configure **one** provider's API key, the system will automatically
If you configure **multiple** API keys, you must explicitly set `AI_PROVIDER`:
```bash
AI_PROVIDER=google # or: openai, anthropic, aihubmix, deepseek, siliconflow, doubao, azure, bedrock, openrouter, ollama, gateway, sglang, modelscope, minimax, glm, qwen, kimi, qiniu, mimo
AI_PROVIDER=google # or: openai, anthropic, google, vertexai, azure, bedrock, ollama, openrouter, aihubmix, deepseek, siliconflow, sglang, gateway, edgeone, doubao, modelscope, glm, qwen, qiniu, kimi, minimax, novita, mimo, atlascloud, custom
```
## Server-Side Multi-Model Configuration
@@ -481,3 +481,4 @@ Every fact about a provider lives in one record in `lib/providers.ts`: which AI
A provider that needs a hint under its base URL field, or a note in the picker, gets a `baseUrlHint` or `note` object with all four UI languages (`en`, `zh`, `ja`, `zh-Hant`). Providers that cannot list their models online keep a short `models` list instead of `modelList`.
2. Add `ACME_API_KEY` and `ACME_BASE_URL` to `env.example` (a unit test checks that every record's variables appear there).
3. Add a section for it to this document in `docs/en`, `docs/cn` and `docs/ja`.
4. Add it to the two lists at the top of `tests/unit/provider-matrix.test.ts` (`MATRIX_PROVIDERS` and `MATRIX_MODEL_IDS`) and regenerate the behavior snapshot with `npx vitest run tests/unit/provider-matrix.test.ts -u`; the new rows are the provider's, the existing rows must not change. `tests/unit/providers.test.ts` spells out the picker's groups and the provider sets that change what the server does (auto-detection, single system message), so add it there too. The provider count in the three READMEs and the `AI_PROVIDER` list in this document change as well.
+1 -1
View File
@@ -151,7 +151,7 @@ npm run dev
### モデルとプロバイダー
AWS Bedrock(既定)、OpenAI、Anthropic、Google AI、Google Vertex AI、Azure OpenAI、Ollama、OpenRouter、AIHubMix、DeepSeek、SiliconFlow、SGLang、Vercel AI Gateway、Tencent EdgeOne、ByteDance Doubao、ModelScope、Zhipu GLM、Qwen、Qiniu、Kimi、MiniMax、Novita、Xiaomi MiMo、Atlas Cloud の 24 プロバイダーに対応しています。各プロバイダーの環境変数と注意点は[プロバイダー設定ガイド](./ai-providers.md)にあります。
AWS Bedrock(既定)、OpenAI、Anthropic、Google AI、Google Vertex AI、Azure OpenAI、Ollama、OpenRouter、AIHubMix、DeepSeek、SiliconFlow、SGLang、Vercel AI Gateway、Tencent EdgeOne、ByteDance Doubao、ModelScope、Zhipu GLM、Qwen、Qiniu、Kimi、MiniMax、Novita、Xiaomi MiMo、Atlas Cloud、および任意の URL を使える OpenAI 互換プリセット(vLLM、LM Studio、ゲートウェイ)の 25 プロバイダーに対応しています。各プロバイダーの環境変数と注意点は[プロバイダー設定ガイド](./ai-providers.md)にあります。
**どのモデルを選ぶか**:厳密な形式の長いテキスト(draw.io の XML)を生成するタスクなので、能力の高いモデルを選んでください。小さなモデルは壊れた図を出しがちです。
+3 -2
View File
@@ -132,7 +132,7 @@ AI_MODEL=your-deployment-name
```bash
AZURE_API_KEY=your_api_key
AZURE_BASE_URL=https://your-resource.openai.azure.com # AZURE_RESOURCE_NAME の代替
AZURE_BASE_URL=https://your-resource.openai.azure.com/openai # AZURE_RESOURCE_NAME の代替
AI_MODEL=your-deployment-name
```
@@ -342,7 +342,7 @@ AI_MODEL=your_model_id
**複数**の API キーを設定する場合は、`AI_PROVIDER` を明示的に設定する必要があります:
```bash
AI_PROVIDER=google # または: openai, anthropic, aihubmix, deepseek, siliconflow, doubao, azure, bedrock, openrouter, ollama, gateway, sglang, modelscope, minimax, glm, qwen, kimi, qiniu, mimo
AI_PROVIDER=google # または: openai, anthropic, google, vertexai, azure, bedrock, ollama, openrouter, aihubmix, deepseek, siliconflow, sglang, gateway, edgeone, doubao, modelscope, glm, qwen, qiniu, kimi, minimax, novita, mimo, atlascloud, custom
```
## サーバーサイドマルチモデル設定
@@ -466,3 +466,4 @@ TEMPERATURE=0 # より決定論的な出力(ダイアグラムに推奨)
ベース URL 欄の下にヒントを表示したい、またはピッカーに注記を表示したいプロバイダーには、4 つの UI 言語(`en`、`zh`、`ja`、`zh-Hant`)をすべて含む `baseUrlHint` または `note` オブジェクトを追加します。モデル一覧をオンラインで取得できないプロバイダーは、`modelList` の代わりに短い `models` リストを持ちます。
2. `env.example` に `ACME_API_KEY` と `ACME_BASE_URL` を追加します(各レコードの変数名がそこに現れることをユニットテストが確認します)。
3. `docs/en`、`docs/cn`、`docs/ja` のこのドキュメントにセクションを追加します。
4. `tests/unit/provider-matrix.test.ts` 先頭の 2 つのリスト(`MATRIX_PROVIDERS` と `MATRIX_MODEL_IDS`)に追加し、`npx vitest run tests/unit/provider-matrix.test.ts -u` で動作スナップショットを再生成します。追加される行はこのプロバイダーのものだけで、既存の行は変わってはいけません。`tests/unit/providers.test.ts` にはピッカーのグループと、サーバーの動作を変えるプロバイダーの集合(自動検出、system メッセージが 1 つだけ)が書き出されているので、そこにも追加します。3 つの README のプロバイダー数と、このドキュメントの `AI_PROVIDER` の選択肢一覧も更新します。
+15
View File
@@ -740,3 +740,18 @@ Docker:.github/workflows/docker-build.yml 在每个 PR 上已经构建 standal
8. 行数:lib/ai-providers.ts 1305、lib/types/model-config.ts 180、lib/provider-setup.ts 85、lib/provider-models.ts 251、lib/admin/providers.ts 306、lib/providers.ts 559,合计 2686 行,改动前 2594 行。方案估计约 2430。多出的部分是记录字段的注释(ProviderDef 的 20 个字段各有说明)、resolveEndpoint 里保留的安全规则说明、custom 记录和 Azure 的地址提示。本方案的收益在改动面和单点决策,行数上没有收益,这一点与第 7 节的说明一致。
核对结果:单元测试 66 个文件 749 个用例全部通过(含 tests/unit/canvas-import-boundary.test.ts,它在 worktree 里安装 node_modules 后才能通过);`tsc --noEmit` 无错;`biome ci` 无错误,37 条警告全部在未改动的文件里;e2e 五个文件 65 个用例通过(settings-providers 27、settings-bedrock 8、provider-models 20、model-test 2、settings-tabs-sync 8),其中"the provider list shows what needs attention"在并行运行时超时一次,单独运行通过。层外按 provider 名的判断剩 6 处,全部在 lib/admin/providers.ts 的 deriveEnvUpdates 和 derivedEnvKeys 里。真实 key 的检查(第 5.6 节)没有做:这台机器上只有 Bedrock 的 AWS 凭据,重构前已用它跑通过 GPT-6 Luna 和 Claude Haiku 4.5 两次连接测试,重构后待所有者按清单验收。
### 合并前评审(2026-10-12)
PR #988 由五个模型评审(Fable 5.1、Opus 5.5、Sonnet 5.5、Codex GPT-6 Astra、Codex GPT-6.1 Sol),同一份清单的五种表述。五份都没有发现行为回退或安全问题:Astra 用程序重建旧逻辑比对了 291,600 个输入组合,Sonnet 把旧代码解包后重新生成快照并比对了 43,200 个配额组合,Sol 比对了 4,512 个,Fable 和 Opus 逐段人工比对。合并后的逐条结论在 PR 的评审记录里;按它们改了以下内容:
- 自动拉取模型列表只填充列表,不再打开选择器,失败也不显示错误(五位都指出弹出的模态选择器会抢走正在输入的焦点);同一服务商同时只发一个列表请求;回到列表再进入同一家时重新记录基线;SGLang 预填的本地示例地址不触发拉取。
- 旧配置里保存着 Azure 占位地址的条目仍判为"未填地址"(hasCredentials 里两行兼容判断)。
- custom 和 Azure 的地址输入框标签改为"必填"(新字典键 baseUrlRequired)。
- PROVIDER_INFO 别名删除,三个源文件和四个测试改用 PROVIDERS;bedrock、doubao、sglang 记录里不会被读到的 logo 删除;ModelListStyle、ProviderGroupId 的再导出和 KeySource、Endpoint、resolveEndpoint 的导出删除;SINGLE_SYSTEM_PROVIDERS 删除,聊天路由直接读 singleSystem。
- 改名:PROVIDER_ENV_VARS 改为 REQUIRED_KEY_VARS,serverCredentialError 的局部变量 keyEnv 改为 requiredKeyEnv,resolveEndpoint 的局部变量 configuredBaseURL 改为 configuredUrl,类型 Copy 改为 LocalizedText;七处过时注释改写。
- 测试:快照矩阵加 6 种输入形状(只带 Vertex key、带会话令牌的 AWS 密钥对、请求头加地址、可信地址加 key、key 加服务器模型自己的地址变量、只有 "/"),共 22 种,5843 行;新增的 1566 行在 99ced88 的旧代码上重新生成后逐行相同,差异只有 custom 的 200 行和两段报错文案的顺序。矩阵测试和服务器凭据测试清理全部相关环境变量;管理面板变量名测试覆盖 custom 并与 PROVIDER_NAMES 比对;用被测函数公式算期望值的用例删除;singleSystem、listNeedsNoKey、sdkKnowsEndpoint 三个集合和参与自动检测的 22 家逐一写明。
- 文档:三份 README 改为 25 家并提到 OpenAI 兼容预设;三份服务商文档的 AI_PROVIDER 可选值补全、Azure 示例地址补 /openai 后缀、"新增服务商"加第 4 步(要同步的测试)。
- 两个重构之前就有的问题单独提交:重定向守卫跨域时同时清掉 x-access-code;edgeOneEndpoint 只在请求的 Origin 头与 Host 或 X-Forwarded-Host 相符时采用它,否则用请求地址自己的 origin。
评审者指出但有意不改的:另外三段报错文案和管理面板下拉框的顺序随记录顺序变化(待决问题 2 已接受);服务器配置里原型链名字从放行变为拒绝(收紧);日志少了候选 key 数量;usesServerCredentials 对数组变量多抽一次随机数;fixedCredentials、ownRequestPath、listNeedsNoKey 可由其他字段推出但保留为显式事实。