mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-20 07:15:51 +00:00
fix: ACP NewSessionResponse 恢复返回 models 字段
67fdd4ca 那次合规审计误将 models 从响应里移除,但 SDK 0.19.2 的 schema 实际允许 models?: SessionModelState | null(标注 UNSTABLE 仅表示"未来可能变",并非 "agent 禁止返回")。标准 ACP 客户端(Cursor/Zed/VS Code/RCS)依赖此字段填充 模型选择器 —— 缺失会导致客户端 supportsModelSelection=false,模型切换 UI 不可用。 - createSessionMethod: return 里加回 models - sessionLifecycle: getOrCreateSession 两处 return 透传 models(resume/load 路径) - agent.test: 更新过时的 "models omitted for v1 compliance" 断言 Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
This commit is contained in:
@@ -325,13 +325,17 @@ describe('AcpAgent', () => {
|
||||
expect(res.sessionId.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
test('returns modes and configOptions (models omitted for v1 compliance)', async () => {
|
||||
test('returns modes, configOptions, and models (clients need models to populate selector)', async () => {
|
||||
const agent = new AcpAgent(makeConn())
|
||||
const res = await agent.newSession({ cwd: '/tmp' } as any)
|
||||
expect(res.modes).toBeDefined()
|
||||
expect(res.configOptions).toBeDefined()
|
||||
// Stable v1 NewSessionResponse does not define `models`
|
||||
expect((res as any).models).toBeUndefined()
|
||||
// SDK 0.19.2 marks NewSessionResponse.models as UNSTABLE but the schema allows it, and
|
||||
// standard clients (Cursor/Zed/VS Code) read it to populate the model selector. Omitting
|
||||
// it forces supportsModelSelection=false on the client.
|
||||
expect(res.models).toBeDefined()
|
||||
expect(Array.isArray(res.models!.availableModels)).toBe(true)
|
||||
expect(typeof res.models!.currentModelId).toBe('string')
|
||||
})
|
||||
|
||||
test('each call returns a unique sessionId', async () => {
|
||||
@@ -865,8 +869,8 @@ describe('AcpAgent', () => {
|
||||
} as any)
|
||||
expect(agent.sessions.has(requestedId)).toBe(true)
|
||||
expect(res.modes).toBeDefined()
|
||||
// models is omitted for v1 compliance
|
||||
expect((res as any).models).toBeUndefined()
|
||||
// resume also returns models so clients can render the selector after reconnect.
|
||||
expect(res.models).toBeDefined()
|
||||
})
|
||||
|
||||
test('reuses existing session when sessionId matches and fingerprint unchanged', async () => {
|
||||
|
||||
@@ -270,11 +270,16 @@ async function createSession(
|
||||
|
||||
this.sessions.set(sessionId, session)
|
||||
|
||||
// Stable v1 NewSessionResponse only defines sessionId/modes/configOptions.
|
||||
// `models` is a draft/unstable field — omit it for v1 compliance.
|
||||
// Return models even though SDK 0.19.2 marks it UNSTABLE. The schema does allow the field
|
||||
// (NewSessionResponse.models?: SessionModelState | null), and standard clients (Cursor/Zed/
|
||||
// VS Code ACP) rely on it to populate the model selector — omitting it forces
|
||||
// supportsModelSelection=false on the client and the user can never switch models.
|
||||
// The UNSTABLE marker only means "this field may change in a future schema version", not
|
||||
// "agents MUST NOT return it". The previous "v1 compliance" omission was overzealous.
|
||||
return {
|
||||
sessionId,
|
||||
modes,
|
||||
models,
|
||||
configOptions,
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -79,6 +79,9 @@ async function getOrCreateSession(
|
||||
return {
|
||||
sessionId: params.sessionId,
|
||||
modes: existingSession.modes,
|
||||
// Carry models over on reconnect so the client keeps its model selector
|
||||
// populated (standard clients gate supportsModelSelection on this field).
|
||||
models: existingSession.models,
|
||||
configOptions: existingSession.configOptions,
|
||||
}
|
||||
}
|
||||
@@ -150,6 +153,8 @@ async function getOrCreateSession(
|
||||
return {
|
||||
sessionId: response.sessionId,
|
||||
modes: response.modes,
|
||||
// createSession already returns models; pass it through. Same reason as above.
|
||||
models: response.models,
|
||||
configOptions: response.configOptions,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user