Repository navigation
feat(dashboard): 模型选择从自由输入改为下拉探测 - #977
Conversation
- 适配器层新增可选 detectModels hook(fail-soft 契约):traex/codex/codex-app/coco 实现 live 枚举(各自的 debug models 命令,输出同构 JSON,共享 parse); claude-code 无枚举接口,静态 alias 列表更新至 5 代(fable/opus/sonnet/haiku + 全名) - 新增 services/model-catalog.ts:静态候选 shell-free 同步取 + live 探测按需调用, TTL 缓存 10 分钟 + in-flight 去重 + 失败回退静态,全程 fail-soft - /api/cli-options 每 option 下发静态 modelChoices;新增 GET /api/cli-options/models 只探测当前选中 CLI(不做全量扫描),返回静态+live 合并去重结果 - dashboard Agent 配置与 onboarding 表单的模型框改用 ModelPickerField: searchable 下拉(复用 DropdownMenu)+「自定义模型…」自由输入(datalist 自动补全) + live 探测状态提示;当前值不在候选中时作为额外选项可见,旧配置不丢 Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 158b664be7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // stale 标志防卸载/竞态:cliKey 快速切换时旧响应不得覆盖新 CLI 的候选。 | ||
| let stale = false; | ||
| setDetectingModels(true); | ||
| fetchDetectedModels(cliKey) |
There was a problem hiding this comment.
Clear detected models when the CLI key changes
When a user switches from one non-TTADK CLI to another, detectedModels retains the previous CLI's response until the new request completes. During that window, mergeModelCandidates combines the new static choices with the old live catalogue, so the picker can offer and save a model belonging to the previous CLI; the onboarding implementation has the same state transition. Clear the detected result before starting each new-key request.
AGENTS.md reference: AGENTS.md:L64-L64
Useful? React with 👍 / 👎.
| const promise = (async (): Promise<readonly string[] | null> => { | ||
| try { | ||
| const adapter = factory(opt.cliId); | ||
| // 适配器未声明 detectModels = 该 CLI 无法枚举模型 → null。 | ||
| const models = adapter.detectModels ? await adapter.detectModels() : null; |
There was a problem hiding this comment.
Probe the bot's configured CLI runtime
For an existing bot configured with cliRuntime.executable or the legacy cliPathOverride, this constructs the default adapter from only cliId, so model discovery executes the daemon's default binary rather than the binary the worker will launch (the worker passes cfg.cliPathOverride to createCliAdapterSync). The resulting dropdown can therefore advertise models unavailable to the selected custom runtime, and editing the runtime does not trigger another probe because the request is keyed only by the selection key. Include the effective runtime/path in discovery or suppress live results for custom runtimes.
AGENTS.md reference: AGENTS.md:L64-L67
Useful? React with 👍 / 👎.
|
🚀 Released in v3.17.0 |
改了什么
Dashboard「Bot 配置 → Agent 配置」和「添加机器人」表单的模型输入从自由文本改为下拉选择 + 可自定义:
src/services/model-catalog.ts,新增):静态候选(适配器modelChoices,shell-free 同步取)+ live 探测(适配器可选detectModelshook,按需调用、TTL 缓存 10 分钟、in-flight 去重、失败回退静态),全程 fail-softdetectModels()hook(types.ts),契约:fail-soft、≤10s 单进程、输出缓冲 cappedtraex/codex/codex-app/coco实现 live 枚举(各自的debug models命令,输出同构 JSON,共享model-catalog-json.ts解析)claude-code无枚举接口(CLI 不暴露模型目录),静态 alias 列表更新至 5 代(fable/opus/sonnet/haiku + 全名)codex静态列表更新为当前目录快照(旧值 gpt-5-codex/o3-mini 已下线)GET /api/cli-options每 option 下发静态modelChoicesGET /api/cli-options/models?key=<选择键>:只探测当前选中 CLI(不做全量扫描),返回静态+live 合并去重结果ModelPickerField(复用 searchableDropdownMenu):下拉候选 +「自定义模型…」切自由输入(datalist 自动补全)+ live 探测状态提示;当前值不在候选中时作为额外选项可见,旧配置不丢为什么
模型名得用户自己记、自己打,体验差且容易拼错。适配器层本来就有
modelChoices(Lark 配置卡片和botmux setup已用),但没暴露给 dashboard;部分 CLI(traex/codex/coco)还支持debug modelslive 枚举,一并接上。影响面评估
/api/cli-options现在会构造全部 20+ 适配器取 modelChoices——适配器构造 shell-free(resolvedBin 懒解析),单选项构造失败只降级该项为[],不影响整包detectModels仅 dashboard 按需调用/api/cli-options同级(token-gated,不在 PUBLIC_READ_PATHS)测试验证
pnpm build:tsc + dashboard bundle + audit 通过pnpm test(全量 unit):17793 通过 / 17 跳过 / 0 失败(1062 文件)test/model-catalog.test.ts(21 例):静态候选五类 key、合并去重、TTL 缓存、in-flight 去重、失败重试test/dashboard-cli-options-models.test.ts(9 例):400 谓词 + 200 响应 shapetest/model-catalog-json.test.ts(6 例):共享 parse(visibility 过滤、坏元素跳过、非法 JSON)test/traex-detect-models.test.ts(4 例)+test/codex-coco-detect-models.test.ts(9 例):spawn 参数、fail-softtest/dashboard-bot-defaults-model-picker.test.ts(17 例):组件挂载、两处使用、旧 input 移除、i18n key、纯函数test/dashboard-bot-defaults-cliid.test.ts的 fetch mock 过滤探测请求(13 例回归)UI 截图
ModelPickerField 四种状态(真实 dashboard CSS,候选为 codex live 探测结果):