Skip to content

feat(dashboard): 模型选择从自由输入改为下拉探测 - #977

Merged
deepcoldy merged 1 commit into
deepcoldy:masterfrom
ITcathyh:feat/dashboard-model-picker
Aug 23, 2026
Merged

deepcoldy merged 1 commit into
deepcoldy:masterfrom
ITcathyh:feat/dashboard-model-picker

Conversation

@ITcathyh

Copy link
Copy Markdown
Contributor

改了什么

Dashboard「Bot 配置 → Agent 配置」和「添加机器人」表单的模型输入从自由文本改为下拉选择 + 可自定义:

  • 模型目录服务(src/services/model-catalog.ts,新增):静态候选(适配器 modelChoices,shell-free 同步取)+ live 探测(适配器可选 detectModels hook,按需调用、TTL 缓存 10 分钟、in-flight 去重、失败回退静态),全程 fail-soft
  • 适配器层:
    • 新增可选 detectModels() hook(types.ts),契约:fail-soft、≤10s 单进程、输出缓冲 capped
    • traex / 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 已下线)
  • API:
    • GET /api/cli-options 每 option 下发静态 modelChoices
    • 新增 GET /api/cli-options/models?key=<选择键>:只探测当前选中 CLI(不做全量扫描),返回静态+live 合并去重结果
  • 前端:新 ModelPickerField(复用 searchable DropdownMenu):下拉候选 +「自定义模型…」切自由输入(datalist 自动补全)+ live 探测状态提示;当前值不在候选中时作为额外选项可见,旧配置不丢

为什么

模型名得用户自己记、自己打,体验差且容易拼错。适配器层本来就有 modelChoices(Lark 配置卡片和 botmux setup 已用),但没暴露给 dashboard;部分 CLI(traex/codex/coco)还支持 debug models live 枚举,一并接上。

影响面评估

  • 跨 CLI:/api/cli-options 现在会构造全部 20+ 适配器取 modelChoices——适配器构造 shell-free(resolvedBin 懒解析),单选项构造失败只降级该项为 [],不影响整包
  • 跨会话类型:不改 worker/session 启动路径,detectModels 仅 dashboard 按需调用
  • 跨后端:PtyBackend/TmuxBackend 均不受影响
  • API 兼容:纯增量(新字段 + 新端点),现有消费方忽略未知字段
  • 鉴权:新端点与 /api/cli-options 同级(token-gated,不在 PUBLIC_READ_PATHS)
  • Lark 卡片 / setup:不动(它们已用 modelChoices)

测试验证

  • 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 响应 shape
    • test/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-soft
    • test/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 探测结果):

ModelPickerField

- 适配器层新增可选 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]>
@ITcathyh
ITcathyh requested a review from deepcoldy as a code owner August 23, 2026 08:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +1748 to +1751
// stale 标志防卸载/竞态:cliKey 快速切换时旧响应不得覆盖新 CLI 的候选。
let stale = false;
setDetectingModels(true);
fetchDetectedModels(cliKey)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines +97 to +101
const promise = (async (): Promise<readonly string[] | null> => {
try {
const adapter = factory(opt.cliId);
// 适配器未声明 detectModels = 该 CLI 无法枚举模型 → null。
const models = adapter.detectModels ? await adapter.detectModels() : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.17.0

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.

2 participants