-
-
Save remorses/ddec691b72cef0ae128dc440505596f6 to your computer and use it in GitHub Desktop.
ACP session/list and session/resume smoke test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bun | |
| // Smoke test for ACP session/list and session/resume | |
| import { fileURLToPath } from "node:url" | |
| import { ClientSideConnection, ndJsonStream, type SessionNotification } from "@agentclientprotocol/sdk" | |
| const cwd = fileURLToPath(new URL("..", import.meta.url)) | |
| const proc = Bun.spawn(["bun", "--conditions=browser", "./src/index.ts", "acp"], { | |
| cwd, | |
| stdin: "pipe", | |
| stdout: "pipe", | |
| stderr: "inherit", | |
| }) | |
| const stdin = new WritableStream<Uint8Array>({ | |
| write: (chunk) => { | |
| proc.stdin.write(chunk) | |
| }, | |
| }) | |
| const stream = ndJsonStream(stdin, proc.stdout) | |
| const updates: SessionNotification[] = [] | |
| const client = new ClientSideConnection( | |
| () => ({ | |
| async sessionUpdate(params: SessionNotification) { | |
| updates.push(params) | |
| }, | |
| async requestPermission() { | |
| return { outcome: { outcome: "cancelled" as const } } | |
| }, | |
| }), | |
| stream, | |
| ) | |
| const init = await client.initialize({ | |
| protocolVersion: 1, | |
| clientCapabilities: {}, | |
| }) | |
| console.log("initialized", init.protocolVersion) | |
| const listed = await client.unstable_listSessions({ cwd }) | |
| console.log("listed", listed.sessions.length, "sessions") | |
| const sessionId = listed.sessions[0]?.sessionId | |
| if (!sessionId) throw new Error("No sessions to resume") | |
| const resumed = await client.unstable_resumeSession({ | |
| cwd, | |
| sessionId, | |
| mcpServers: [], | |
| }) | |
| console.log("resumed session", sessionId, "mode:", resumed.modes?.currentModeId ?? "unknown") | |
| console.log("updates received:", updates.length) | |
| console.log("session/list and session/resume work!") | |
| proc.kill() | |
| await proc.exited |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment