feat(sdk): add get_available_models() to Python and TypeScript SDKs - #6460
feat(sdk): add get_available_models() to Python and TypeScript SDKs#6460juhuan wants to merge 1 commit into
Conversation
Add a new control request `get_available_models` that returns the list of models available for the current auth type. The CLI's SystemController handles the request by calling config.getAvailableModels() and returning id, label, description, and isVision for each model. Both SDKs expose this as a runtime method on the Query class.
|
Thanks for the PR! Template looks good ✓ Problem: This is a real gap — SDK users currently have no programmatic way to discover available models. The Direction: Clean alignment with the SDK's mission as a programmatic interface to the CLI. The Size: Cross-package (CLI + Python SDK + TypeScript SDK) but small and focused. 70 production logic lines + 44 test lines. Well within bounds. Approach: The implementation closely follows the existing Moving on to code review and testing. 🔍 中文说明感谢贡献! 模板完整 ✓ 问题:这是一个真实的缺口——SDK 用户目前没有编程方式查询可用模型。 方向:与 SDK 作为 CLI 编程接口的定位高度一致。 规模:跨包(CLI + Python SDK + TypeScript SDK)但很小且聚焦。70 行生产代码 + 44 行测试。在合理范围内。 方案:实现紧密跟随已有的 进入代码审查和测试 🔍 — Qwen Code · qwen3.7-max |
2a. Code ReviewIndependent proposal: To expose model discovery to SDKs, I'd add a Comparison with the PR: The implementation matches this proposal exactly. Every file change follows the established Correctness: Clean. The No critical blockers. No AGENTS.md violations. The code is straightforward, minimal, and follows existing conventions. 2b. TestingThis is a pure SDK protocol addition — no TUI change, no CLI behavior change. tmux testing is not applicable here. Unit tests are the appropriate verification. CLI — ControlDispatcher (37/37 pass ✅)TypeScript SDK — Query (55/55 pass ✅)Python SDK — Transport (new test pass ✅, 4 pre-existing failures unrelated)The 4 failures are pre-existing — they require Typecheck中文说明2a. 代码审查独立提案: 要将模型发现暴露给 SDK,我会添加 与 PR 对比: 实现完全匹配此提案。每个文件改动都遵循已有的 正确性: 无问题。 无关键阻塞。无 AGENTS.md 违规。 代码简洁、最小,遵循已有约定。 2b. 测试这是纯 SDK 协议添加——无 TUI 变更,无 CLI 行为变更。tmux 测试不适用。单元测试是正确的验证方式。
— Qwen Code · qwen3.7-max |
|
This is a clean, well-scoped SDK feature. The implementation follows the existing The problem is real: SDK users can call One observation for the maintainer's awareness: the response maps only four fields from LGTM. ✅ 中文说明这是一个干净、范围合理的 SDK 功能。实现在每个细节上都遵循已有的 问题是真实的:SDK 用户可以调用 一个供维护者注意的观察:响应只映射了 LGTM. ✅ — Qwen Code · qwen3.7-max |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship. ✅
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
No review findings. Downgraded from Approve to Comment: CI still running.
— qwen3.7-max via Qwen Code /review
💡 Suggestion: Consolidate SDK PRsHi @juhuan, thanks for the comprehensive SDK work! We noticed you have 15 open PRs that all modify the same core files ( The problem
Suggestion: regroup into 2 PRsWe recommend closing the current 15 PRs and reopening them as 2 consolidated PRs: PR 1 — Covers pure SDK-side option additions (~9 current PRs):
PR 2 — Covers features that also involve CLI-side
This keeps a reasonable separation of concerns while eliminating the merge-conflict chain and making review much more manageable. /cc @juhuan |
|
Closing in favor of consolidated PRs (see suggestion comment above). Please reopen as 2 grouped PRs. |
What this PR does
Adds a new
get_available_modelscontrol request that lets both SDKs query the list of models available for the current auth type at runtime. The CLI'sSystemControllerhandles the request by callingconfig.getAvailableModels()and returning each model'sid,label,description, andisVisionfields.Changes by package
CLI (
packages/cli):nonInteractive/types.ts— addedCLIControlGetAvailableModelsRequesttype and included it inControlRequestPayloadnonInteractive/control/ControlDispatcher.ts— routesget_available_modelstoSystemControllernonInteractive/control/controllers/systemController.ts— addedhandleGetAvailableModelshandler that callsconfig.getAvailableModels(); addedcan_get_available_modelscapability to the initialize responsePython SDK (
packages/sdk-python):protocol.py— addedCLIControlGetAvailableModelsRequestTypedDict and included it inControlRequestPayloadquery.py— addedget_available_models()async method onQueryTypeScript SDK (
packages/sdk-typescript):types/protocol.ts— addedGET_AVAILABLE_MODELStoControlRequestTypeenumquery/Query.ts— addedgetAvailableModels()async method onQueryWhy it's needed
Without a way to query available models, SDK users have no programmatic way to discover which models they can use or switch to. The CLI's
/modelinteractive command already shows this list, but neither SDK exposed it. This method complements the existingset_model()/setModel()runtime method — users can now list available models and then switch to one.Reviewer Test Plan
How to verify
Python SDK:
cd packages/sdk-python && PYTHONPATH=src python3 -m pytest tests/unit/test_transport.py -v— 36 tests pass, including the newtest_get_available_models_protocol_typeTypeScript SDK:
cd packages/sdk-typescript && npx vitest run test/unit/Query.test.ts— 55 tests passquery.getAvailableModels()sends a control request with subtypeget_available_modelsCLI:
cd packages/cli && npx vitest run src/nonInteractive/control/ControlDispatcher.test.ts— includes new testshould route get_available_models request to system controllerhttpspackage inpackages/core/src/telemetry. This is unrelated to this PR.Evidence (Before & After)
N/A — SDK method addition, no user-visible TUI change
Tested on
Environment
Unit tests only: Python 3.11 with pytest 9.1, Node.js 22 with vitest 1.6
Risk & Scope
ControlDispatcher. If a SDK sends this request to an older CLI version that doesn't recognizeget_available_models, the CLI will return an "Unknown control request subtype" error. This is expected and backward-compatible — the SDK should handle this gracefully (the method returnsdict | None).config.getAvailableModels()which is already well-tested in the core package.Linked Issues
Related to #4158
中文说明
本 PR 做了什么
新增
get_available_models控制请求,允许两个 SDK 在运行时查询当前认证类型下可用的模型列表。CLI 的SystemController通过调用config.getAvailableModels()处理请求,返回每个模型的id、label、description和isVision字段。为什么需要
SDK 用户此前无法通过编程方式查询可用模型列表。CLI 的
/model交互命令已展示此列表,但 SDK 未暴露。该方法与已有的set_model()/setModel()运行时方法配合使用——用户可以先列出可用模型再切换。风险与范围
ControlDispatcher新增了控制请求子类型。如果 SDK 向不支持该子类型的旧版 CLI 发送请求,CLI 会返回"Unknown control request subtype"错误。这是预期的向后兼容行为。config.getAvailableModels()已在 core 包中有充分测试。