From fc0210c2fdd3194754dbe1eeff094e3038ffecbc Mon Sep 17 00:00:00 2001 From: Alex Sadleir Date: Thu, 22 Jan 2026 15:11:09 +1100 Subject: [PATCH] fix(acp): rename setSessionModel to unstable_setSessionModel (#9940) --- packages/opencode/src/acp/agent.ts | 2 +- .../opencode/test/acp/agent-interface.test.ts | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 packages/opencode/test/acp/agent-interface.test.ts diff --git a/packages/opencode/src/acp/agent.ts b/packages/opencode/src/acp/agent.ts index e165509b9..d4d556485 100644 --- a/packages/opencode/src/acp/agent.ts +++ b/packages/opencode/src/acp/agent.ts @@ -1084,7 +1084,7 @@ export namespace ACP { } } - async setSessionModel(params: SetSessionModelRequest) { + async unstable_setSessionModel(params: SetSessionModelRequest) { const session = this.sessionManager.get(params.sessionId) const model = Provider.parseModel(params.modelId) diff --git a/packages/opencode/test/acp/agent-interface.test.ts b/packages/opencode/test/acp/agent-interface.test.ts new file mode 100644 index 000000000..a915d30eb --- /dev/null +++ b/packages/opencode/test/acp/agent-interface.test.ts @@ -0,0 +1,51 @@ +import { describe, expect, test } from "bun:test" +import { ACP } from "../../src/acp/agent" +import type { Agent as ACPAgent } from "@agentclientprotocol/sdk" + +/** + * Type-level test: This line will fail to compile if ACP.Agent + * doesn't properly implement the ACPAgent interface. + * + * The SDK checks for methods like `agent.unstable_setSessionModel` at runtime + * and throws "Method not found" if they're missing. TypeScript allows optional + * interface methods to be omitted, but the SDK still expects them. + * + * @see https://github.com/agentclientprotocol/typescript-sdk/commit/7072d3f + */ +type _AssertAgentImplementsACPAgent = ACP.Agent extends ACPAgent ? true : never +const _typeCheck: _AssertAgentImplementsACPAgent = true + +/** + * Runtime verification that optional methods the SDK expects are actually implemented. + * The SDK's router checks `if (!agent.methodName)` and throws MethodNotFound if missing. + */ +describe("acp.agent interface compliance", () => { + // Extract method names from the ACPAgent interface type + type ACPAgentMethods = keyof ACPAgent + + // Methods that the SDK's router explicitly checks for at runtime + const sdkCheckedMethods: ACPAgentMethods[] = [ + // Required + "initialize", + "newSession", + "prompt", + "cancel", + // Optional but checked by SDK router + "loadSession", + "setSessionMode", + "authenticate", + // Unstable - SDK checks these with unstable_ prefix + "unstable_listSessions", + "unstable_forkSession", + "unstable_resumeSession", + "unstable_setSessionModel", + ] + + test("Agent implements all SDK-checked methods", () => { + for (const method of sdkCheckedMethods) { + expect(typeof ACP.Agent.prototype[method as keyof typeof ACP.Agent.prototype], `Missing method: ${method}`).toBe( + "function", + ) + } + }) +})