use-acp 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -99,10 +99,13 @@ pnpm dev # run demo, http://localhost:5173
99
99
 
100
100
  ```bash
101
101
  # Gemini ACP
102
- npx -y stdio-to-ws --stdio "npx @google/gemini-cli --experimental-acp" --outputTransport ws
102
+ npx -y stdio-to-ws "npx @google/gemini-cli --experimental-acp"
103
103
 
104
104
  # Claude Code ACP
105
- npx -y stdio-to-ws --stdio "npx @zed-industries/claude-code-acp" --outputTransport ws
105
+ npx -y stdio-to-ws "npx @zed-industries/claude-code-acp"
106
+
107
+ # Codex ACP
108
+ npx -y stdio-to-ws "npx @zed-industries/codex-acp"
106
109
  ```
107
110
 
108
111
  ## License
@@ -1,7 +1,9 @@
1
- import type { Agent, AuthenticateRequest, CancelNotification, Client, InitializeRequest, InitializeResponse, LoadSessionRequest, LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, ReadTextFileRequest, ReadTextFileResponse, RequestPermissionRequest, RequestPermissionResponse, SessionNotification, SetSessionModeRequest, WriteTextFileRequest, WriteTextFileResponse } from "@zed-industries/agent-client-protocol";
1
+ import type { Agent, AuthenticateRequest, CancelNotification, Client, InitializeRequest, InitializeResponse, LoadSessionRequest, LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, ReadTextFileRequest, ReadTextFileResponse, RequestPermissionRequest, RequestPermissionResponse, SessionNotification, SetSessionModelRequest, SetSessionModelResponse, SetSessionModeRequest, WriteTextFileRequest, WriteTextFileResponse } from "@agentclientprotocol/sdk";
2
+ import { JsonRpcError } from "../utils/jsonrpc-error.js";
2
3
  export interface AcpClientOptions {
3
4
  onRequestPermission: (params: IdentifiedPermissionRequest) => void;
4
5
  onSessionNotification: (params: SessionNotification) => void;
6
+ onRpcError?: (error: JsonRpcError) => void;
5
7
  readTextFile?: (params: ReadTextFileRequest) => Promise<ReadTextFileResponse>;
6
8
  writeTextFile?: (params: WriteTextFileRequest) => Promise<WriteTextFileResponse>;
7
9
  }
@@ -26,14 +28,21 @@ type ListeningAgentCallbacks = {
26
28
  [K in keyof RequiredAgent as `on_${string & K}_response`]: RequiredAgent[K] extends (...args: any[]) => infer R ? (response: Awaited<R>, request: Parameters<RequiredAgent[K]>[0]) => void : never;
27
29
  } & {
28
30
  [K in keyof RequiredAgent as `on_${string & K}_start`]: RequiredAgent[K] extends (...args: any[]) => unknown ? (request: Parameters<RequiredAgent[K]>[0]) => void : never;
29
- } & {};
31
+ } & {
32
+ on_rpc_error?: (error: JsonRpcError) => void;
33
+ };
30
34
  export declare class ListeningAgent implements Required<Agent> {
31
35
  private readonly agent;
32
36
  private readonly callbacks;
33
37
  constructor(agent: Agent, callbacks: Partial<ListeningAgentCallbacks>);
38
+ /**
39
+ * Wraps an async agent call with JSON-RPC error handling
40
+ */
41
+ private handleCatchRpcError;
34
42
  extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>>;
35
43
  extNotification(method: string, params: Record<string, unknown>): Promise<void>;
36
- setSessionMode(params: SetSessionModeRequest): Promise<void | import("@zed-industries/agent-client-protocol").SetSessionModeResponse | undefined>;
44
+ setSessionMode(params: SetSessionModeRequest): Promise<void | import("@agentclientprotocol/sdk").SetSessionModeResponse | undefined>;
45
+ setSessionModel(params: SetSessionModelRequest): Promise<SetSessionModelResponse | void>;
37
46
  initialize(params: InitializeRequest): Promise<InitializeResponse>;
38
47
  newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
39
48
  loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"acp-client.d.ts","sourceRoot":"","sources":["../../src/client/acp-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,mBAAmB,EACnB,kBAAkB,EAClB,MAAM,EACN,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAA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AE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAYrE,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxD,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAOtD,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxD"}
@@ -1,4 +1,5 @@
1
1
  import { Deferred } from "../utils/deferred.js";
2
+ import { JsonRpcError, JsonRpcErrorCodes } from "../utils/jsonrpc-error.js";
2
3
  export class AcpClient {
3
4
  agent;
4
5
  options;
@@ -44,6 +45,36 @@ export class AcpClient {
44
45
  }
45
46
  }
46
47
  }
48
+ /**
49
+ * Try to extract JSON-RPC error from any error object
50
+ */
51
+ function toJsonRpcError(error) {
52
+ if (error instanceof JsonRpcError) {
53
+ return error;
54
+ }
55
+ if (error instanceof Error) {
56
+ return new JsonRpcError({
57
+ code: JsonRpcErrorCodes.INTERNAL_ERROR,
58
+ message: error.message,
59
+ data: error.stack,
60
+ });
61
+ }
62
+ // Check if it's an error object with code, message, and optionally data
63
+ if (error &&
64
+ typeof error === "object" &&
65
+ "code" in error &&
66
+ "message" in error &&
67
+ typeof error.code === "number" &&
68
+ typeof error.message === "string") {
69
+ const errorObj = error;
70
+ return new JsonRpcError({
71
+ code: errorObj.code,
72
+ message: errorObj.message,
73
+ data: errorObj.data,
74
+ }, undefined);
75
+ }
76
+ return null;
77
+ }
47
78
  export class ListeningAgent {
48
79
  agent;
49
80
  callbacks;
@@ -51,6 +82,22 @@ export class ListeningAgent {
51
82
  this.agent = agent;
52
83
  this.callbacks = callbacks;
53
84
  }
85
+ /**
86
+ * Wraps an async agent call with JSON-RPC error handling
87
+ */
88
+ handleCatchRpcError(methodName) {
89
+ return (error) => {
90
+ // Try to extract JSON-RPC error
91
+ const jsonRpcError = toJsonRpcError(error);
92
+ if (jsonRpcError) {
93
+ console.error(`[acp] JSON-RPC error in ${methodName}:`, jsonRpcError);
94
+ this.callbacks.on_rpc_error?.(jsonRpcError);
95
+ throw jsonRpcError;
96
+ }
97
+ // Re-throw if not a JSON-RPC error
98
+ throw error;
99
+ };
100
+ }
54
101
  extMethod(method, params) {
55
102
  if (this.agent.extMethod) {
56
103
  return this.agent.extMethod(method, params);
@@ -65,53 +112,62 @@ export class ListeningAgent {
65
112
  }
66
113
  async setSessionMode(params) {
67
114
  this.callbacks.on_setSessionMode_start?.(params);
68
- return this.agent.setSessionMode?.(params).then((response) => {
69
- this.callbacks.on_setSessionMode_response?.(response, params);
70
- return response;
71
- });
115
+ const response = await this.agent
116
+ .setSessionMode?.(params)
117
+ .catch(this.handleCatchRpcError("setSessionMode"));
118
+ this.callbacks.on_setSessionMode_response?.(response, params);
119
+ return response;
120
+ }
121
+ async setSessionModel(params) {
122
+ this.callbacks.on_setSessionModel_start?.(params);
123
+ const result = await this.agent
124
+ .setSessionModel?.(params)
125
+ .catch(this.handleCatchRpcError("setSessionModel"));
126
+ this.callbacks.on_setSessionModel_response?.(result, params);
127
+ return result;
72
128
  }
73
129
  async initialize(params) {
74
130
  this.callbacks.on_initialize_start?.(params);
75
- return this.agent.initialize(params).then((response) => {
76
- this.callbacks.on_initialize_response?.(response, params);
77
- return response;
78
- });
131
+ const response = await this.agent
132
+ .initialize(params)
133
+ .catch(this.handleCatchRpcError("initialize"));
134
+ this.callbacks.on_initialize_response?.(response, params);
135
+ return response;
79
136
  }
80
137
  async newSession(params) {
81
138
  this.callbacks.on_newSession_start?.(params);
82
- return this.agent.newSession(params).then((response) => {
83
- this.callbacks.on_newSession_response?.(response, params);
84
- return response;
85
- });
139
+ const response = await this.agent
140
+ .newSession(params)
141
+ .catch(this.handleCatchRpcError("newSession"));
142
+ this.callbacks.on_newSession_response?.(response, params);
143
+ return response;
86
144
  }
87
145
  async loadSession(params) {
88
146
  this.callbacks.on_loadSession_start?.(params);
89
147
  if (this.agent.loadSession) {
90
- return this.agent.loadSession(params).then((response) => {
91
- this.callbacks.on_loadSession_response?.(response, params);
92
- return response;
93
- });
148
+ const response = await this.agent
149
+ .loadSession(params)
150
+ .catch(this.handleCatchRpcError("loadSession"));
151
+ this.callbacks.on_loadSession_response?.(response, params);
152
+ return response;
94
153
  }
95
154
  throw new Error("Agent does not support loadSession capability");
96
155
  }
97
156
  async authenticate(params) {
98
157
  this.callbacks.on_authenticate_start?.(params);
99
- return this.agent.authenticate(params).then(() => {
100
- this.callbacks.on_authenticate_response?.(undefined, params);
101
- });
158
+ await this.agent.authenticate(params).catch(this.handleCatchRpcError("authenticate"));
159
+ this.callbacks.on_authenticate_response?.(undefined, params);
102
160
  }
103
161
  async prompt(params) {
104
162
  this.callbacks.on_prompt_start?.(params);
105
- return this.agent.prompt(params).then((response) => {
106
- this.callbacks.on_prompt_response?.(response, params);
107
- return response;
108
- });
163
+ const response = await this.agent.prompt(params).catch(this.handleCatchRpcError("prompt"));
164
+ this.callbacks.on_prompt_response?.(response, params);
165
+ return response;
109
166
  }
110
167
  async cancel(params) {
111
168
  this.callbacks.on_cancel_start?.(params);
112
- return this.agent.cancel(params).then(() => {
113
- this.callbacks.on_cancel_response?.(undefined, params);
114
- });
169
+ await this.agent.cancel(params).catch(this.handleCatchRpcError("cancel"));
170
+ this.callbacks.on_cancel_response?.(undefined, params);
115
171
  }
116
172
  }
117
173
  //# sourceMappingURL=acp-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"acp-client.js","sourceRoot":"","sources":["../../src/client/acp-client.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAehD,MAAM,OAAO,SAAS;IACb,KAAK,CAAQ;IACH,OAAO,CAAmB;IAC1B,kBAAkB,GAAG,IAAI,GAAG,EAG1C,CAAC;IAEJ,YAAY,KAAY,EAAE,OAAyB;QACjD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CA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AC;QACD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,MAA2B;QAC5C,IAAI,CAAC,SAAS,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAC/C,IAAI,CAAC,SAAS,CAAC,wBAAwB,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,MAAqB;QAChC,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjD,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACtD,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,MAA0B;QACrC,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACzC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n Agent,\n AuthenticateRequest,\n CancelNotification,\n Client,\n InitializeRequest,\n InitializeResponse,\n LoadSessionRequest,\n LoadSessionResponse,\n NewSessionRequest,\n NewSessionResponse,\n PromptRequest,\n PromptResponse,\n ReadTextFileRequest,\n ReadTextFileResponse,\n RequestPermissionRequest,\n RequestPermissionResponse,\n SessionNotification,\n SetSessionModeRequest,\n WriteTextFileRequest,\n WriteTextFileResponse,\n} from \"@zed-industries/agent-client-protocol\";\nimport { Deferred } from \"../utils/deferred.js\";\n\nexport interface AcpClientOptions {\n onRequestPermission: (params: IdentifiedPermissionRequest) => void;\n onSessionNotification: (params: SessionNotification) => void;\n readTextFile?: (params: ReadTextFileRequest) => Promise<ReadTextFileResponse>;\n writeTextFile?: (params: WriteTextFileRequest) => Promise<WriteTextFileResponse>;\n}\n\nexport interface IdentifiedPermissionRequest extends RequestPermissionRequest {\n deferredId: string;\n}\n\nexport type PermissionRequestId = IdentifiedPermissionRequest[\"deferredId\"];\n\nexport class AcpClient implements Client {\n public agent: Agent;\n private readonly options: AcpClientOptions;\n private readonly pendingPermissions = new Map<\n PermissionRequestId,\n Deferred<RequestPermissionResponse>\n >();\n\n constructor(agent: Agent, options: AcpClientOptions) {\n this.agent = agent;\n this.options = options;\n }\n\n async sessionUpdate(params: SessionNotification): Promise<void> {\n this.options.onSessionNotification(params);\n }\n\n async writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse> {\n if (this.options.writeTextFile) {\n return this.options.writeTextFile(params);\n }\n throw new Error(\"Write text file handler not implemented\");\n }\n\n async readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse> {\n if (this.options.readTextFile) {\n return this.options.readTextFile(params);\n }\n throw new Error(\"Read text file handler not implemented\");\n }\n\n async requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse> {\n const permissionId: PermissionRequestId = `${Date.now()}-${Math.random()}`;\n const deferred = new Deferred<RequestPermissionResponse>();\n\n this.pendingPermissions.set(permissionId, deferred);\n this.options.onRequestPermission({ ...params, deferredId: permissionId });\n\n return deferred.promise;\n }\n\n resolvePermission(permissionId: PermissionRequestId, response: RequestPermissionResponse) {\n const deferred = this.pendingPermissions.get(permissionId);\n if (deferred) {\n this.pendingPermissions.delete(permissionId);\n deferred.resolve(response);\n }\n }\n\n rejectPermission(permissionId: PermissionRequestId, error: Error) {\n const deferred = this.pendingPermissions.get(permissionId);\n if (deferred) {\n this.pendingPermissions.delete(permissionId);\n deferred.reject(error);\n }\n }\n}\n\ntype RequiredAgent = Required<Agent>;\n\ntype ListeningAgentCallbacks = {\n [K in keyof RequiredAgent as `on_${string & K}_response`]: RequiredAgent[K] extends (\n // biome-ignore lint/suspicious/noExplicitAny: any for typing\n ...args: any[]\n ) => infer R\n ? (response: Awaited<R>, request: Parameters<RequiredAgent[K]>[0]) => void\n : never;\n} & {\n [K in keyof RequiredAgent as `on_${string & K}_start`]: RequiredAgent[K] extends (\n // biome-ignore lint/suspicious/noExplicitAny: any for typing\n ...args: any[]\n ) => unknown\n ? (request: Parameters<RequiredAgent[K]>[0]) => void\n : never;\n} & {};\n\nexport class ListeningAgent implements Required<Agent> {\n constructor(\n private readonly agent: Agent,\n private readonly callbacks: Partial<ListeningAgentCallbacks>,\n ) {}\n\n extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>> {\n if (this.agent.extMethod) {\n return this.agent.extMethod(method, params);\n }\n return Promise.resolve({});\n }\n extNotification(method: string, params: Record<string, unknown>): Promise<void> {\n if (this.agent.extNotification) {\n return this.agent.extNotification(method, params);\n }\n return Promise.resolve();\n }\n\n async setSessionMode(params: SetSessionModeRequest) {\n this.callbacks.on_setSessionMode_start?.(params);\n return this.agent.setSessionMode?.(params).then((response) => {\n this.callbacks.on_setSessionMode_response?.(response, params);\n return response;\n });\n }\n\n async initialize(params: InitializeRequest): Promise<InitializeResponse> {\n this.callbacks.on_initialize_start?.(params);\n return this.agent.initialize(params).then((response) => {\n this.callbacks.on_initialize_response?.(response, params);\n return response;\n });\n }\n async newSession(params: NewSessionRequest): Promise<NewSessionResponse> {\n this.callbacks.on_newSession_start?.(params);\n return this.agent.newSession(params).then((response) => {\n this.callbacks.on_newSession_response?.(response, params);\n return response;\n });\n }\n\n async loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse> {\n this.callbacks.on_loadSession_start?.(params);\n if (this.agent.loadSession) {\n return this.agent.loadSession(params).then((response) => {\n this.callbacks.on_loadSession_response?.(response, params);\n return response;\n });\n }\n throw new Error(\"Agent does not support loadSession capability\");\n }\n\n async authenticate(params: AuthenticateRequest): Promise<void> {\n this.callbacks.on_authenticate_start?.(params);\n return this.agent.authenticate(params).then(() => {\n this.callbacks.on_authenticate_response?.(undefined, params);\n });\n }\n async prompt(params: PromptRequest): Promise<PromptResponse> {\n this.callbacks.on_prompt_start?.(params);\n return this.agent.prompt(params).then((response) => {\n this.callbacks.on_prompt_response?.(response, params);\n return response;\n });\n }\n async cancel(params: CancelNotification): Promise<void> {\n this.callbacks.on_cancel_start?.(params);\n return this.agent.cancel(params).then(() => {\n this.callbacks.on_cancel_response?.(undefined, params);\n });\n }\n}\n"]}
1
+ {"version":3,"file":"acp-client.js","sourceRoot":"","sources":["../../src/client/acp-client.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAgB5E,MAAM,OAAO,SAAS;IACb,KAAK,CAAQ;IACH,OAAO,CAAmB;IAC1B,kBAAkB,GAAG,IAAI,GAAG,EAG1C,CAAC;IAEJ,YAAY,KAAY,EAAE,OAAyB;QACjD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAA2B;QAC7C,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAA4B;QAC9C,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;QACD,MA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CAAC,CAAC;IACzD,CAAC;CACF","sourcesContent":["import type {\n Agent,\n AuthenticateRequest,\n CancelNotification,\n Client,\n InitializeRequest,\n InitializeResponse,\n LoadSessionRequest,\n LoadSessionResponse,\n NewSessionRequest,\n NewSessionResponse,\n PromptRequest,\n PromptResponse,\n ReadTextFileRequest,\n ReadTextFileResponse,\n RequestPermissionRequest,\n RequestPermissionResponse,\n SessionNotification,\n SetSessionModelRequest,\n SetSessionModelResponse,\n SetSessionModeRequest,\n WriteTextFileRequest,\n WriteTextFileResponse,\n} from \"@agentclientprotocol/sdk\";\nimport { Deferred } from \"../utils/deferred.js\";\nimport { JsonRpcError, JsonRpcErrorCodes } from \"../utils/jsonrpc-error.js\";\n\nexport interface AcpClientOptions {\n onRequestPermission: (params: IdentifiedPermissionRequest) => void;\n onSessionNotification: (params: SessionNotification) => void;\n onRpcError?: (error: JsonRpcError) => void;\n readTextFile?: (params: ReadTextFileRequest) => Promise<ReadTextFileResponse>;\n writeTextFile?: (params: WriteTextFileRequest) => Promise<WriteTextFileResponse>;\n}\n\nexport interface IdentifiedPermissionRequest extends RequestPermissionRequest {\n deferredId: string;\n}\n\nexport type PermissionRequestId = IdentifiedPermissionRequest[\"deferredId\"];\n\nexport class AcpClient implements Client {\n public agent: Agent;\n private readonly options: AcpClientOptions;\n private readonly pendingPermissions = new Map<\n PermissionRequestId,\n Deferred<RequestPermissionResponse>\n >();\n\n constructor(agent: Agent, options: AcpClientOptions) {\n this.agent = agent;\n this.options = options;\n }\n\n async sessionUpdate(params: SessionNotification): Promise<void> {\n this.options.onSessionNotification(params);\n }\n\n async writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse> {\n if (this.options.writeTextFile) {\n return this.options.writeTextFile(params);\n }\n throw new Error(\"Write text file handler not implemented\");\n }\n\n async readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse> {\n if (this.options.readTextFile) {\n return this.options.readTextFile(params);\n }\n throw new Error(\"Read text file handler not implemented\");\n }\n\n async requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse> {\n const permissionId: PermissionRequestId = `${Date.now()}-${Math.random()}`;\n const deferred = new Deferred<RequestPermissionResponse>();\n\n this.pendingPermissions.set(permissionId, deferred);\n this.options.onRequestPermission({ ...params, deferredId: permissionId });\n\n return deferred.promise;\n }\n\n resolvePermission(permissionId: PermissionRequestId, response: RequestPermissionResponse) {\n const deferred = this.pendingPermissions.get(permissionId);\n if (deferred) {\n this.pendingPermissions.delete(permissionId);\n deferred.resolve(response);\n }\n }\n\n rejectPermission(permissionId: PermissionRequestId, error: Error) {\n const deferred = this.pendingPermissions.get(permissionId);\n if (deferred) {\n this.pendingPermissions.delete(permissionId);\n deferred.reject(error);\n }\n }\n}\n\ntype RequiredAgent = Required<Agent>;\n\ntype ListeningAgentCallbacks = {\n [K in keyof RequiredAgent as `on_${string & K}_response`]: RequiredAgent[K] extends (\n // biome-ignore lint/suspicious/noExplicitAny: any for typing\n ...args: any[]\n ) => infer R\n ? (response: Awaited<R>, request: Parameters<RequiredAgent[K]>[0]) => void\n : never;\n} & {\n [K in keyof RequiredAgent as `on_${string & K}_start`]: RequiredAgent[K] extends (\n // biome-ignore lint/suspicious/noExplicitAny: any for typing\n ...args: any[]\n ) => unknown\n ? (request: Parameters<RequiredAgent[K]>[0]) => void\n : never;\n} & {\n on_rpc_error?: (error: JsonRpcError) => void;\n};\n\n/**\n * Try to extract JSON-RPC error from any error object\n */\nfunction toJsonRpcError(error: unknown): JsonRpcError | null {\n if (error instanceof JsonRpcError) {\n return error;\n }\n\n if (error instanceof Error) {\n return new JsonRpcError({\n code: JsonRpcErrorCodes.INTERNAL_ERROR,\n message: error.message,\n data: error.stack,\n });\n }\n\n // Check if it's an error object with code, message, and optionally data\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n \"message\" in error &&\n typeof (error as { code: unknown }).code === \"number\" &&\n typeof (error as { message: unknown }).message === \"string\"\n ) {\n const errorObj = error as Record<string, unknown>;\n return new JsonRpcError(\n {\n code: errorObj.code as number,\n message: errorObj.message as string,\n data: errorObj.data,\n },\n undefined,\n );\n }\n\n return null;\n}\n\nexport class ListeningAgent implements Required<Agent> {\n constructor(\n private readonly agent: Agent,\n private readonly callbacks: Partial<ListeningAgentCallbacks>,\n ) {}\n\n /**\n * Wraps an async agent call with JSON-RPC error handling\n */\n private handleCatchRpcError(methodName: string) {\n return (error: unknown) => {\n // Try to extract JSON-RPC error\n const jsonRpcError = toJsonRpcError(error);\n if (jsonRpcError) {\n console.error(`[acp] JSON-RPC error in ${methodName}:`, jsonRpcError);\n this.callbacks.on_rpc_error?.(jsonRpcError);\n throw jsonRpcError;\n }\n // Re-throw if not a JSON-RPC error\n throw error;\n };\n }\n\n extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>> {\n if (this.agent.extMethod) {\n return this.agent.extMethod(method, params);\n }\n return Promise.resolve({});\n }\n extNotification(method: string, params: Record<string, unknown>): Promise<void> {\n if (this.agent.extNotification) {\n return this.agent.extNotification(method, params);\n }\n return Promise.resolve();\n }\n\n async setSessionMode(params: SetSessionModeRequest) {\n this.callbacks.on_setSessionMode_start?.(params);\n const response = await this.agent\n .setSessionMode?.(params)\n .catch(this.handleCatchRpcError(\"setSessionMode\"));\n this.callbacks.on_setSessionMode_response?.(response, params);\n return response;\n }\n\n async setSessionModel(\n params: SetSessionModelRequest,\n // biome-ignore lint/suspicious/noConfusingVoidType: Matches Agent interface signature\n ): Promise<SetSessionModelResponse | void> {\n this.callbacks.on_setSessionModel_start?.(params);\n const result = await this.agent\n .setSessionModel?.(params)\n .catch(this.handleCatchRpcError(\"setSessionModel\"));\n this.callbacks.on_setSessionModel_response?.(result, params);\n return result;\n }\n\n async initialize(params: InitializeRequest): Promise<InitializeResponse> {\n this.callbacks.on_initialize_start?.(params);\n const response = await this.agent\n .initialize(params)\n .catch(this.handleCatchRpcError(\"initialize\"));\n this.callbacks.on_initialize_response?.(response, params);\n return response;\n }\n\n async newSession(params: NewSessionRequest): Promise<NewSessionResponse> {\n this.callbacks.on_newSession_start?.(params);\n const response = await this.agent\n .newSession(params)\n .catch(this.handleCatchRpcError(\"newSession\"));\n this.callbacks.on_newSession_response?.(response, params);\n return response;\n }\n\n async loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse> {\n this.callbacks.on_loadSession_start?.(params);\n if (this.agent.loadSession) {\n const response = await this.agent\n .loadSession(params)\n .catch(this.handleCatchRpcError(\"loadSession\"));\n this.callbacks.on_loadSession_response?.(response, params);\n return response;\n }\n throw new Error(\"Agent does not support loadSession capability\");\n }\n\n async authenticate(params: AuthenticateRequest): Promise<void> {\n this.callbacks.on_authenticate_start?.(params);\n await this.agent.authenticate(params).catch(this.handleCatchRpcError(\"authenticate\"));\n this.callbacks.on_authenticate_response?.(undefined, params);\n }\n\n async prompt(params: PromptRequest): Promise<PromptResponse> {\n this.callbacks.on_prompt_start?.(params);\n const response = await this.agent.prompt(params).catch(this.handleCatchRpcError(\"prompt\"));\n this.callbacks.on_prompt_response?.(response, params);\n return response;\n }\n\n async cancel(params: CancelNotification): Promise<void> {\n this.callbacks.on_cancel_start?.(params);\n await this.agent.cancel(params).catch(this.handleCatchRpcError(\"cancel\"));\n this.callbacks.on_cancel_response?.(undefined, params);\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { SessionNotification, ToolCallContent } from "@zed-industries/agent-client-protocol";
1
+ import type { SessionNotification, ToolCallContent } from "@agentclientprotocol/sdk";
2
2
  export type SessionUpdate = SessionNotification["update"];
3
3
  export type AgentMessageChunkNotification = Extract<SessionUpdate, {
4
4
  sessionUpdate: "agent_message_chunk";
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAElG,MAAM,MAAM,aAAa,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAE1D,MAAM,M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O,CAAC,aAAa,EAAE;IAAE,aAAa,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AACnF,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,aAAa,EAAE;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAC3F,MAAM,MAAM,4BAA4B,GAAG,OAAO,CAChD,aAAa,EACb;IAAE,aAAa,EAAE,oBAAoB,CAAA;CAAE,CACxC,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,aAAa,EAAE;IAAE,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AACjF,MAAM,MAAM,mBAAmB,GAAG,6BAA6B,CAAC,SAAS,CAAC,CAAC;AAC3E,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,eAAe,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SessionNotification, ToolCallContent } from \"@zed-industries/agent-client-protocol\";\n\nexport type SessionUpdate = SessionNotification[\"update\"];\n\nexport type AgentMessageChunkNotification = Extract<\n SessionUpdate,\n { sessionUpdate: \"agent_message_chunk\" }\n>;\nexport type AgentThoughtChunkNotification = Extract<\n SessionUpdate,\n { sessionUpdate: \"agent_thought_chunk\" }\n>;\nexport type ToolCallStart = Extract<SessionUpdate, { sessionUpdate: \"tool_call\" }>;\nexport type ToolCallUpdate = Extract<SessionUpdate, { sessionUpdate: \"tool_call_update\" }>;\nexport type UserMessageChunkNotification = Extract<\n SessionUpdate,\n { sessionUpdate: \"user_message_chunk\" }\n>;\nexport type PlanNotification = Extract<SessionUpdate, { sessionUpdate: \"plan\" }>;\nexport type NotificationContent = AgentMessageChunkNotification[\"content\"];\nexport type ToolCallDiff = Extract<ToolCallContent, { type: \"diff\" }>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { SessionNotification, ToolCallContent } from \"@agentclientprotocol/sdk\";\n\nexport type SessionUpdate = SessionNotification[\"update\"];\n\nexport type AgentMessageChunkNotification = Extract<\n SessionUpdate,\n { sessionUpdate: \"agent_message_chunk\" }\n>;\nexport type AgentThoughtChunkNotification = Extract<\n SessionUpdate,\n { sessionUpdate: \"agent_thought_chunk\" }\n>;\nexport type ToolCallStart = Extract<SessionUpdate, { sessionUpdate: \"tool_call\" }>;\nexport type ToolCallUpdate = Extract<SessionUpdate, { sessionUpdate: \"tool_call_update\" }>;\nexport type UserMessageChunkNotification = Extract<\n SessionUpdate,\n { sessionUpdate: \"user_message_chunk\" }\n>;\nexport type PlanNotification = Extract<SessionUpdate, { sessionUpdate: \"plan\" }>;\nexport type NotificationContent = AgentMessageChunkNotification[\"content\"];\nexport type ToolCallDiff = Extract<ToolCallContent, { type: \"diff\" }>;\n"]}
@@ -1,4 +1,4 @@
1
- import { type Agent, type AgentCapabilities, type AvailableCommand, type McpServer, type RequestPermissionResponse, type SessionModeState } from "@zed-industries/agent-client-protocol";
1
+ import { type Agent, type AgentCapabilities, type AvailableCommand, type McpServer, type RequestPermissionResponse, type SessionModeState } from "@agentclientprotocol/sdk";
2
2
  import { type AcpClientOptions, type IdentifiedPermissionRequest } from "../client/acp-client.js";
3
3
  import type { ConnectionState, NotificationEvent, SessionId } from "../state/types.js";
4
4
  export interface UseAcpClientOptions {
@@ -18,6 +18,7 @@ export interface UseAcpClientReturn {
18
18
  disconnect: () => void;
19
19
  connectionState: ConnectionState;
20
20
  activeSessionId: SessionId | null;
21
+ setActiveSessionId: (sessionId: SessionId | null) => void;
21
22
  notifications: NotificationEvent[];
22
23
  clearNotifications: () => void;
23
24
  isSessionLoading: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"use-acp-client.d.ts","sourceRoot":"","sources":["../../src/hooks/use-acp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,K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SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1D,aAAa,EAAE,iBAAiB,EAAE,CAAC;IACnC,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,gBAAgB,EAAE,OAAO,CAAC;IAG1B,iBAAiB,EAAE,2BAA2B,GAAG,IAAI,CAAC;IACtD,iBAAiB,EAAE,CAAC,QAAQ,EAAE,yBAAyB,KAAK,IAAI,CAAC;IACjE,gBAAgB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAGzC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAG5C,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IAGtC,WAAW,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,CAAC;CAClD;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAuO7E"}
@@ -1,4 +1,4 @@
1
- import { ClientSideConnection, } from "@zed-industries/agent-client-protocol";
1
+ import { ClientSideConnection, ndJsonStream, } from "@agentclientprotocol/sdk";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { AcpClient, ListeningAgent, } from "../client/acp-client.js";
4
4
  import { MultiWebSocketManager } from "../connection/websocket-manager.js";
@@ -68,10 +68,14 @@ export function useAcpClient(options) {
68
68
  clientOptions?.onSessionNotification?.(params);
69
69
  handleSessionNotification(params);
70
70
  },
71
+ onRpcError: (error) => {
72
+ clientOptions?.onRpcError?.(error);
73
+ handleError(error, wsUrl);
74
+ },
71
75
  });
72
76
  acpClientRef.current = acpClient;
73
77
  return acpClient;
74
- }, writable, readable);
78
+ }, ndJsonStream(writable, readable));
75
79
  const listeningAgent = new ListeningAgent(agent, {
76
80
  on_initialize_response: (response) => {
77
81
  const capabilities = response.agentCapabilities;
@@ -110,6 +114,7 @@ export function useAcpClient(options) {
110
114
  const sessionId = params.sessionId;
111
115
  setActiveModeId(sessionId, params.modeId);
112
116
  },
117
+ on_rpc_error: (error) => handleError(error, wsUrl),
113
118
  });
114
119
  setAgent(listeningAgent);
115
120
  });
@@ -157,6 +162,8 @@ export function useAcpClient(options) {
157
162
  // Auto-connect on mount if specified
158
163
  // biome-ignore lint/correctness/useExhaustiveDependencies: Don't include connect/disconnect to avoid re-connecting on every render
159
164
  useEffect(() => {
165
+ // Reset the active session id as the connection is being established
166
+ setActiveSessionId(null);
160
167
  if (autoConnect) {
161
168
  void connect().catch(console.error);
162
169
  }
@@ -173,6 +180,7 @@ export function useAcpClient(options) {
173
180
  isSessionLoading,
174
181
  clearNotifications,
175
182
  pendingPermission,
183
+ setActiveSessionId,
176
184
  resolvePermission,
177
185
  rejectPermission: rejectPermissionCallback,
178
186
  agent: agent,
@@ -1 +1 @@
1
- {"version":3,"file":"use-acp-client.js","sourceRoot":"","sources":["../../src/hooks/use-acp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,oBAAoB,GAKrB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,SAAS,EAGT,cAAc,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAgD3D,MAAM,UAAU,YAAY,CAAC,OAA4B;IACvD,MAAM,EACJ,KAAK,EACL,WAAW,GAAG,IAAI,EAClB,iBAAiB,GAAG,CAAC,EACrB,cAAc,GAAG,IAAI,EACrB,aAAa,GAAG,EAAE,GACnB,GAAG,OAAO,CAAC;IAEZ,MAAM,EACJ,aAAa,EACb,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,mBA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Aa,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;QAC1E,gBAAgB;QAChB,kBAAkB;QAClB,iBAAiB;QACjB,iBAAiB;QACjB,gBAAgB,EAAE,wBAAwB;QAC1C,KAAK,EAAE,KAAK;QACZ,iBAAiB;QACjB,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI;QACnE,iBAAiB;KAClB,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Agent,\n type AgentCapabilities,\n type AvailableCommand,\n ClientSideConnection,\n type McpServer,\n type RequestPermissionResponse,\n type SessionModeState,\n type SessionNotification,\n} from \"@zed-industries/agent-client-protocol\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n AcpClient,\n type AcpClientOptions,\n type IdentifiedPermissionRequest,\n ListeningAgent,\n} from \"../client/acp-client.js\";\nimport { MultiWebSocketManager } from \"../connection/websocket-manager.js\";\nimport { useAcpStore } from \"../state/atoms.js\";\nimport type {\n ConnectionState,\n ConnectionUrl,\n NotificationEvent,\n SessionId,\n} from \"../state/types.js\";\nimport { useEventCallback } from \"./use-event-callback.js\";\n\nexport interface UseAcpClientOptions {\n // Connection management\n wsUrl: string;\n autoConnect?: boolean;\n reconnectAttempts?: number;\n reconnectDelay?: number;\n\n // Client options\n clientOptions?: Partial<AcpClientOptions>;\n\n // Session management\n initialSessionId?: string | null;\n sessionParams?: {\n cwd?: string;\n mcpServers?: McpServer[];\n };\n}\n\nexport interface UseAcpClientReturn {\n // Connection management\n connect: () => Promise<void>;\n disconnect: () => void;\n connectionState: ConnectionState;\n\n // State management\n activeSessionId: SessionId | null;\n notifications: NotificationEvent[];\n clearNotifications: () => void;\n isSessionLoading: boolean;\n\n // Permission handling\n pendingPermission: IdentifiedPermissionRequest | null;\n resolvePermission: (response: RequestPermissionResponse) => void;\n rejectPermission: (error: Error) => void;\n\n // ACP connection\n agent: Agent | null;\n agentCapabilities: AgentCapabilities | null;\n\n // Slash commands support\n availableCommands: AvailableCommand[];\n\n // Session modes\n sessionMode: SessionModeState | null | undefined;\n}\n\nexport function useAcpClient(options: UseAcpClientOptions): UseAcpClientReturn {\n const {\n wsUrl,\n autoConnect = true,\n reconnectAttempts = 3,\n reconnectDelay = 2000,\n clientOptions = {},\n } = options;\n\n const {\n getConnection,\n notifications,\n activeSessionId,\n agentCapabilities,\n sessionModes,\n setActiveModeId,\n setModeState,\n setActiveSessionId,\n setConnection,\n setActiveConnection,\n addNotification,\n clearNotifications,\n } = useAcpStore();\n\n // State\n const [pendingPermission, setPendingPermission] = useState<IdentifiedPermissionRequest | null>(\n null,\n );\n const [agent, setAgent] = useState<Agent | null>(null);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n const [availableCommands, setAvailableCommands] = useState<AvailableCommand[]>([]);\n\n // Refs\n const multiWsManagerRef = useRef<MultiWebSocketManager | null>(null);\n const acpClientRef = useRef<AcpClient | null>(null);\n const lastProcessedSessionId = useRef<SessionId | null>(null);\n const sessionCreationInProgress = useRef<boolean>(false);\n\n // Handlers\n const handleConnectionStateChange = useEventCallback(\n (state: ConnectionState, url: ConnectionUrl) => {\n setConnection(url, state);\n addNotification({\n type: \"connection_change\",\n data: state,\n });\n },\n );\n\n const handleError = useEventCallback((error: Error, _url: ConnectionUrl) => {\n addNotification({\n type: \"error\",\n data: error,\n });\n });\n\n const handleSessionNotification = useEventCallback((notification: SessionNotification) => {\n addNotification({\n type: \"session_notification\",\n data: notification,\n });\n\n // Handle available commands updates\n if (notification.update.sessionUpdate === \"available_commands_update\") {\n setAvailableCommands(notification.update.availableCommands);\n }\n });\n\n const handleRequestPermission = useEventCallback((params: IdentifiedPermissionRequest) => {\n setPendingPermission(params);\n });\n\n const connect = useEventCallback(async () => {\n if (!multiWsManagerRef.current) {\n multiWsManagerRef.current = new MultiWebSocketManager({\n onConnectionStateChange: handleConnectionStateChange,\n onError: handleError,\n reconnectAttempts: reconnectAttempts,\n reconnectDelay: reconnectDelay,\n });\n }\n\n setActiveConnection(wsUrl);\n const { readable, writable } = await multiWsManagerRef.current.connect(wsUrl);\n\n // Initialize the connection\n const agent = new ClientSideConnection(\n (agent) => {\n // Initialize the ACP client\n const acpClient = new AcpClient(agent, {\n ...clientOptions,\n onRequestPermission: (params) => {\n clientOptions?.onRequestPermission?.(params);\n handleRequestPermission(params);\n },\n onSessionNotification: (params) => {\n clientOptions?.onSessionNotification?.(params);\n handleSessionNotification(params);\n },\n });\n acpClientRef.current = acpClient;\n return acpClient;\n },\n writable,\n readable as ReadableStream<Uint8Array>,\n );\n\n const listeningAgent: Agent = new ListeningAgent(agent, {\n on_initialize_response: (response) => {\n const capabilities = response.agentCapabilities;\n console.log(\"[acp] Agent capabilities\", capabilities);\n const connectionState = getConnection(wsUrl);\n setConnection(wsUrl, connectionState.state, capabilities);\n },\n on_newSession_response: (response) => {\n console.log(\"[acp] New session created\", response);\n const sessionId = response.sessionId as SessionId;\n setActiveSessionId(sessionId);\n setModeState(sessionId, response.modes);\n },\n on_loadSession_response: (response, params) => {\n console.log(\"[acp] Session resumed\", params);\n const sessionId = params.sessionId as SessionId;\n setActiveSessionId(sessionId);\n setModeState(sessionId, response.modes);\n },\n on_prompt_start: (params) => {\n for (const prompt of params.prompt) {\n addNotification({\n type: \"session_notification\",\n data: {\n sessionId: params.sessionId,\n update: {\n sessionUpdate: \"user_message_chunk\",\n content: prompt,\n },\n },\n });\n }\n },\n on_setSessionMode_start: (params) => {\n console.log(\"[acp] Session mode set\", params);\n const sessionId = params.sessionId as SessionId;\n setActiveModeId(sessionId, params.modeId);\n },\n });\n\n setAgent(listeningAgent);\n });\n\n const disconnect = useEventCallback((url?: ConnectionUrl) => {\n const targetUrl = url || wsUrl;\n\n if (multiWsManagerRef.current) {\n if (url) {\n multiWsManagerRef.current.disconnect(url);\n } else {\n // Disconnect the current URL specifically instead of all connections\n multiWsManagerRef.current.disconnect(targetUrl);\n multiWsManagerRef.current = null;\n acpClientRef.current = null;\n setAgent(null);\n }\n }\n\n if (!url) {\n setPendingPermission(null);\n setAvailableCommands([]);\n // Reset session creation safeguards on full disconnect\n sessionCreationInProgress.current = false;\n lastProcessedSessionId.current = null;\n setIsSessionLoading(false);\n }\n });\n\n const resolvePermission = useEventCallback((response: RequestPermissionResponse) => {\n if (pendingPermission && acpClientRef.current) {\n const permissionId = pendingPermission.deferredId;\n if (permissionId) {\n acpClientRef.current.resolvePermission(permissionId, response);\n }\n }\n setPendingPermission(null);\n });\n\n const rejectPermissionCallback = useEventCallback((error: Error) => {\n if (pendingPermission && acpClientRef.current) {\n const permissionId = pendingPermission.deferredId;\n if (permissionId) {\n acpClientRef.current.rejectPermission(permissionId, error);\n }\n }\n setPendingPermission(null);\n });\n\n // Auto-connect on mount if specified\n // biome-ignore lint/correctness/useExhaustiveDependencies: Don't include connect/disconnect to avoid re-connecting on every render\n useEffect(() => {\n if (autoConnect) {\n void connect().catch(console.error);\n }\n\n return () => {\n disconnect();\n };\n }, [autoConnect, wsUrl]);\n\n return {\n connect,\n disconnect,\n connectionState: getConnection(wsUrl).state,\n activeSessionId,\n notifications: activeSessionId ? notifications[activeSessionId] || [] : [],\n isSessionLoading,\n clearNotifications,\n pendingPermission,\n resolvePermission,\n rejectPermission: rejectPermissionCallback,\n agent: agent,\n agentCapabilities,\n sessionMode: activeSessionId ? sessionModes[activeSessionId] : null,\n availableCommands,\n };\n}\n"]}
1
+ {"version":3,"file":"use-acp-client.js","sourceRoot":"","sources":["../../src/hooks/use-acp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,oBAAoB,EAEpB,YAAY,GAIb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,SAAS,EAGT,cAAc,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAA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iBAAiB,CAAC,UAAU,CAAC;YAClD,IAAI,YAAY,EAAE,CAAC;gBACjB,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,qCAAqC;IACrC,mIAAmI;IACnI,SAAS,CAAC,GAAG,EAAE;QACb,qEAAqE;QACrE,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAEzB,IAAI,WAAW,EAAE,CAAC;YAChB,KAAK,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,GAAG,EAAE;YACV,UAAU,EAAE,CAAC;QACf,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAEzB,OAAO;QACL,OAAO;QACP,UAAU;QACV,eAAe,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,KAAK;QAC3C,eAAe;QACf,aAAa,EAAE,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;QAC1E,gBAAgB;QAChB,kBAAkB;QAClB,iBAAiB;QACjB,kBAAkB;QAClB,iBAAiB;QACjB,gBAAgB,EAAE,wBAAwB;QAC1C,KAAK,EAAE,KAAK;QACZ,iBAAiB;QACjB,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI;QACnE,iBAAiB;KAClB,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Agent,\n type AgentCapabilities,\n type AvailableCommand,\n ClientSideConnection,\n type McpServer,\n ndJsonStream,\n type RequestPermissionResponse,\n type SessionModeState,\n type SessionNotification,\n} from \"@agentclientprotocol/sdk\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n AcpClient,\n type AcpClientOptions,\n type IdentifiedPermissionRequest,\n ListeningAgent,\n} from \"../client/acp-client.js\";\nimport { MultiWebSocketManager } from \"../connection/websocket-manager.js\";\nimport { useAcpStore } from \"../state/atoms.js\";\nimport type {\n ConnectionState,\n ConnectionUrl,\n NotificationEvent,\n SessionId,\n} from \"../state/types.js\";\nimport { useEventCallback } from \"./use-event-callback.js\";\n\nexport interface UseAcpClientOptions {\n // Connection management\n wsUrl: string;\n autoConnect?: boolean;\n reconnectAttempts?: number;\n reconnectDelay?: number;\n\n // Client options\n clientOptions?: Partial<AcpClientOptions>;\n\n // Session management\n initialSessionId?: string | null;\n sessionParams?: {\n cwd?: string;\n mcpServers?: McpServer[];\n };\n}\n\nexport interface UseAcpClientReturn {\n // Connection management\n connect: () => Promise<void>;\n disconnect: () => void;\n connectionState: ConnectionState;\n\n // State management\n activeSessionId: SessionId | null;\n setActiveSessionId: (sessionId: SessionId | null) => void;\n notifications: NotificationEvent[];\n clearNotifications: () => void;\n isSessionLoading: boolean;\n\n // Permission handling\n pendingPermission: IdentifiedPermissionRequest | null;\n resolvePermission: (response: RequestPermissionResponse) => void;\n rejectPermission: (error: Error) => void;\n\n // ACP connection\n agent: Agent | null;\n agentCapabilities: AgentCapabilities | null;\n\n // Slash commands support\n availableCommands: AvailableCommand[];\n\n // Session modes\n sessionMode: SessionModeState | null | undefined;\n}\n\nexport function useAcpClient(options: UseAcpClientOptions): UseAcpClientReturn {\n const {\n wsUrl,\n autoConnect = true,\n reconnectAttempts = 3,\n reconnectDelay = 2000,\n clientOptions = {},\n } = options;\n\n const {\n getConnection,\n notifications,\n activeSessionId,\n agentCapabilities,\n sessionModes,\n setActiveModeId,\n setModeState,\n setActiveSessionId,\n setConnection,\n setActiveConnection,\n addNotification,\n clearNotifications,\n } = useAcpStore();\n\n // State\n const [pendingPermission, setPendingPermission] = useState<IdentifiedPermissionRequest | null>(\n null,\n );\n const [agent, setAgent] = useState<Agent | null>(null);\n const [isSessionLoading, setIsSessionLoading] = useState(false);\n const [availableCommands, setAvailableCommands] = useState<AvailableCommand[]>([]);\n\n // Refs\n const multiWsManagerRef = useRef<MultiWebSocketManager | null>(null);\n const acpClientRef = useRef<AcpClient | null>(null);\n const lastProcessedSessionId = useRef<SessionId | null>(null);\n const sessionCreationInProgress = useRef<boolean>(false);\n\n // Handlers\n const handleConnectionStateChange = useEventCallback(\n (state: ConnectionState, url: ConnectionUrl) => {\n setConnection(url, state);\n addNotification({\n type: \"connection_change\",\n data: state,\n });\n },\n );\n\n const handleError = useEventCallback((error: Error, _url: ConnectionUrl) => {\n addNotification({\n type: \"error\",\n data: error,\n });\n });\n\n const handleSessionNotification = useEventCallback((notification: SessionNotification) => {\n addNotification({\n type: \"session_notification\",\n data: notification,\n });\n\n // Handle available commands updates\n if (notification.update.sessionUpdate === \"available_commands_update\") {\n setAvailableCommands(notification.update.availableCommands);\n }\n });\n\n const handleRequestPermission = useEventCallback((params: IdentifiedPermissionRequest) => {\n setPendingPermission(params);\n });\n\n const connect = useEventCallback(async () => {\n if (!multiWsManagerRef.current) {\n multiWsManagerRef.current = new MultiWebSocketManager({\n onConnectionStateChange: handleConnectionStateChange,\n onError: handleError,\n reconnectAttempts: reconnectAttempts,\n reconnectDelay: reconnectDelay,\n });\n }\n\n setActiveConnection(wsUrl);\n const { readable, writable } = await multiWsManagerRef.current.connect(wsUrl);\n\n // Initialize the connection\n const agent = new ClientSideConnection(\n (agent) => {\n // Initialize the ACP client\n const acpClient = new AcpClient(agent, {\n ...clientOptions,\n onRequestPermission: (params) => {\n clientOptions?.onRequestPermission?.(params);\n handleRequestPermission(params);\n },\n onSessionNotification: (params) => {\n clientOptions?.onSessionNotification?.(params);\n handleSessionNotification(params);\n },\n onRpcError: (error) => {\n clientOptions?.onRpcError?.(error);\n handleError(error, wsUrl);\n },\n });\n acpClientRef.current = acpClient;\n return acpClient;\n },\n ndJsonStream(writable, readable as ReadableStream<Uint8Array>),\n );\n\n const listeningAgent: Agent = new ListeningAgent(agent, {\n on_initialize_response: (response) => {\n const capabilities = response.agentCapabilities;\n console.log(\"[acp] Agent capabilities\", capabilities);\n const connectionState = getConnection(wsUrl);\n setConnection(wsUrl, connectionState.state, capabilities);\n },\n on_newSession_response: (response) => {\n console.log(\"[acp] New session created\", response);\n const sessionId = response.sessionId as SessionId;\n setActiveSessionId(sessionId);\n setModeState(sessionId, response.modes);\n },\n on_loadSession_response: (response, params) => {\n console.log(\"[acp] Session resumed\", params);\n const sessionId = params.sessionId as SessionId;\n setActiveSessionId(sessionId);\n setModeState(sessionId, response.modes);\n },\n on_prompt_start: (params) => {\n for (const prompt of params.prompt) {\n addNotification({\n type: \"session_notification\",\n data: {\n sessionId: params.sessionId,\n update: {\n sessionUpdate: \"user_message_chunk\",\n content: prompt,\n },\n },\n });\n }\n },\n on_setSessionMode_start: (params) => {\n console.log(\"[acp] Session mode set\", params);\n const sessionId = params.sessionId as SessionId;\n setActiveModeId(sessionId, params.modeId);\n },\n on_rpc_error: (error) => handleError(error, wsUrl),\n });\n\n setAgent(listeningAgent);\n });\n\n const disconnect = useEventCallback((url?: ConnectionUrl) => {\n const targetUrl = url || wsUrl;\n\n if (multiWsManagerRef.current) {\n if (url) {\n multiWsManagerRef.current.disconnect(url);\n } else {\n // Disconnect the current URL specifically instead of all connections\n multiWsManagerRef.current.disconnect(targetUrl);\n multiWsManagerRef.current = null;\n acpClientRef.current = null;\n setAgent(null);\n }\n }\n\n if (!url) {\n setPendingPermission(null);\n setAvailableCommands([]);\n // Reset session creation safeguards on full disconnect\n sessionCreationInProgress.current = false;\n lastProcessedSessionId.current = null;\n setIsSessionLoading(false);\n }\n });\n\n const resolvePermission = useEventCallback((response: RequestPermissionResponse) => {\n if (pendingPermission && acpClientRef.current) {\n const permissionId = pendingPermission.deferredId;\n if (permissionId) {\n acpClientRef.current.resolvePermission(permissionId, response);\n }\n }\n setPendingPermission(null);\n });\n\n const rejectPermissionCallback = useEventCallback((error: Error) => {\n if (pendingPermission && acpClientRef.current) {\n const permissionId = pendingPermission.deferredId;\n if (permissionId) {\n acpClientRef.current.rejectPermission(permissionId, error);\n }\n }\n setPendingPermission(null);\n });\n\n // Auto-connect on mount if specified\n // biome-ignore lint/correctness/useExhaustiveDependencies: Don't include connect/disconnect to avoid re-connecting on every render\n useEffect(() => {\n // Reset the active session id as the connection is being established\n setActiveSessionId(null);\n\n if (autoConnect) {\n void connect().catch(console.error);\n }\n\n return () => {\n disconnect();\n };\n }, [autoConnect, wsUrl]);\n\n return {\n connect,\n disconnect,\n connectionState: getConnection(wsUrl).state,\n activeSessionId,\n notifications: activeSessionId ? notifications[activeSessionId] || [] : [],\n isSessionLoading,\n clearNotifications,\n pendingPermission,\n setActiveSessionId,\n resolvePermission,\n rejectPermission: rejectPermissionCallback,\n agent: agent,\n agentCapabilities,\n sessionMode: activeSessionId ? sessionModes[activeSessionId] : null,\n availableCommands,\n };\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./hooks/use-acp-client.js";
2
2
  export { useAcpStore } from "./state/atoms.js";
3
+ export type { NotificationEvent, NotificationEventData } from "./state/types.js";
3
4
  export { groupNotifications, mergeToolCalls, } from "./state/utils.js";
5
+ export { JsonRpcError, JsonRpcErrorCodes, } from "./utils/jsonrpc-error.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,cAAc,GACf,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EACL,kBAAkB,EAClB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,YAAY,EACZ,iBAAiB,GAClB,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./hooks/use-acp-client.js";
2
2
  export { useAcpStore } from "./state/atoms.js";
3
3
  export { groupNotifications, mergeToolCalls, } from "./state/utils.js";
4
+ export { JsonRpcError, JsonRpcErrorCodes, } from "./utils/jsonrpc-error.js";
4
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,kBAAkB,EAClB,cAAc,GACf,MAAM,kBAAkB,CAAC","sourcesContent":["export * from \"./hooks/use-acp-client.js\";\nexport { useAcpStore } from \"./state/atoms.js\";\nexport {\n groupNotifications,\n mergeToolCalls,\n} from \"./state/utils.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EACL,kBAAkB,EAClB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,YAAY,EACZ,iBAAiB,GAClB,MAAM,0BAA0B,CAAC","sourcesContent":["export * from \"./hooks/use-acp-client.js\";\nexport { useAcpStore } from \"./state/atoms.js\";\nexport type { NotificationEvent, NotificationEventData } from \"./state/types.js\";\nexport {\n groupNotifications,\n mergeToolCalls,\n} from \"./state/utils.js\";\nexport {\n JsonRpcError,\n JsonRpcErrorCodes,\n} from \"./utils/jsonrpc-error.js\";\n"]}
@@ -1,4 +1,4 @@
1
- import type { AgentCapabilities, SessionModeId, SessionModeState } from "@zed-industries/agent-client-protocol";
1
+ import type { AgentCapabilities, SessionModeId, SessionModeState } from "@agentclientprotocol/sdk";
2
2
  import type { Connection, ConnectionState, ConnectionUrl, NotificationEvent, NotificationEventData, SessionId } from "./types.js";
3
3
  interface AcpState {
4
4
  connections: Record<ConnectionUrl, Connection>;
@@ -1 +1 @@
1
- {"version":3,"file":"atoms.d.ts","sourceRoot":"","sources":["../../src/state/atoms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EACjB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,UAAU,QAAQ;IAEhB,WAAW,EAAE,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAC/C,mBAAmB,EAAE,aAAa,GAAG,IAAI,CAAC;IAG1C,eAAe,EAAE,eAAe,CAAC;IACjC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAG5C,eAAe,EAAE,SAAS,GAAG,IAAI,CAAC;IAClC,aAAa,EAAE,MAAM,CAAC,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC;IACtD,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAGrE,aAAa,EAAE,CACb,GAAG,EAAE,aAAa,EAClB,KAAK,EAAE,eAAe,EACtB,YAAY,CAAC,EAAE,iBAAiB,GAAG,IAAI,KACpC,IAAI,CAAC;IACV,mBAAmB,EAAE,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,KAAK,IAAI,CAAC;IACzD,gBAAgB,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,CAAC;IAG/C,kBAAkB,EAAE,CAAC,KAAK,EAAE,e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IAC/E,CAAC;IAED,aAAa,EAAE,CAAC,GAAW,EAAE,EAAE;QAC7B,MAAM,EAAE,WAAW,EAAE,GAAG,GAAG,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC5F,CAAC;CACF,CAAC,CAAC,CAAC","sourcesContent":["import type {\n AgentCapabilities,\n SessionModeId,\n SessionModeState,\n} from \"@zed-industries/agent-client-protocol\";\nimport { create } from \"zustand\";\nimport type {\n Connection,\n ConnectionState,\n ConnectionUrl,\n NotificationEvent,\n NotificationEventData,\n SessionId,\n} from \"./types.js\";\n\ninterface AcpState {\n // Multi-connection support\n connections: Record<ConnectionUrl, Connection>;\n activeConnectionUrl: ConnectionUrl | null;\n\n // Legacy single-connection interface (for backward compatibility)\n connectionState: ConnectionState;\n agentCapabilities: AgentCapabilities | null;\n\n // Session management\n activeSessionId: SessionId | null;\n notifications: Record<SessionId, NotificationEvent[]>;\n sessionModes: Record<SessionId, SessionModeState | null | undefined>;\n\n // Connection management\n setConnection: (\n url: ConnectionUrl,\n state: ConnectionState,\n capabilities?: AgentCapabilities | null,\n ) => void;\n setActiveConnection: (url: ConnectionUrl | null) => void;\n removeConnection: (url: ConnectionUrl) => void;\n\n // Legacy methods (for backward compatibility)\n setConnectionState: (state: ConnectionState) => void;\n setAgentCapabilities: (capabilities: AgentCapabilities | null) => void;\n\n // Session methods\n setActiveSessionId: (sessionId: SessionId | null) => void;\n setActiveModeId: (sessionId: SessionId, modeId: SessionModeId | null | undefined) => void;\n setModeState: (sessionId: SessionId, modeState: SessionModeState | null | undefined) => void;\n addNotification: (notification: NotificationEventData) => void;\n clearNotifications: (sessionId?: SessionId) => void;\n getActiveNotifications: () => NotificationEvent[];\n\n // Getters\n getActiveConnection: () => Connection | null;\n getConnection: (url: ConnectionUrl) => Connection;\n}\n\nexport const useAcpStore = create<AcpState>((set, get) => ({\n // Multi-connection state\n connections: {},\n activeConnectionUrl: null,\n\n // Legacy state\n connectionState: { status: \"disconnected\" },\n agentCapabilities: null,\n\n // Session state\n activeSessionId: null,\n notifications: {},\n sessionModes: {},\n\n // Connection management\n setConnection: (\n url: ConnectionUrl,\n state: ConnectionState,\n capabilities?: AgentCapabilities | null,\n ) => {\n set((prev) => ({\n connections: {\n ...prev.connections,\n [url]: {\n url,\n state,\n capabilities: capabilities ?? prev.connections[url]?.capabilities ?? null,\n },\n },\n // Update legacy state if this is the active connection\n ...(prev.activeConnectionUrl === url && {\n connectionState: state,\n agentCapabilities: capabilities ?? prev.connections[url]?.capabilities ?? null,\n }),\n }));\n },\n\n setActiveConnection: (url: ConnectionUrl | null) => {\n set((prev) => {\n const activeConnection = url ? prev.connections[url] : null;\n return {\n activeConnectionUrl: url,\n connectionState: activeConnection?.state ?? { status: \"disconnected\" },\n agentCapabilities: activeConnection?.capabilities ?? null,\n };\n });\n },\n\n removeConnection: (url: ConnectionUrl) => {\n set((prev) => {\n const newConnections = { ...prev.connections };\n delete newConnections[url];\n const newActiveUrl = prev.activeConnectionUrl === url ? null : prev.activeConnectionUrl;\n const activeConnection = newActiveUrl ? newConnections[newActiveUrl] : null;\n return {\n connections: newConnections,\n activeConnectionUrl: newActiveUrl,\n connectionState: activeConnection?.state ?? { status: \"disconnected\" },\n agentCapabilities: activeConnection?.capabilities ?? null,\n };\n });\n },\n\n // Legacy methods (for backward compatibility)\n setConnectionState: (connectionState: ConnectionState) => {\n set({ connectionState });\n const { activeConnectionUrl } = get();\n if (activeConnectionUrl) {\n get().setConnection(activeConnectionUrl, connectionState);\n }\n },\n\n setAgentCapabilities: (agentCapabilities: AgentCapabilities | null) => {\n set({ agentCapabilities });\n const { activeConnectionUrl } = get();\n if (activeConnectionUrl) {\n get().setConnection(activeConnectionUrl, get().connectionState, agentCapabilities);\n }\n },\n\n setActiveSessionId: (sessionId: SessionId | null) => {\n set({ activeSessionId: sessionId });\n },\n\n setActiveModeId: (sessionId: SessionId, modeId: SessionModeId | null | undefined) => {\n set((prev) => {\n const prevMode = prev.sessionModes[sessionId];\n return {\n sessionModes: {\n ...prev.sessionModes,\n [sessionId]: { ...prevMode, currentModeId: modeId },\n },\n };\n });\n },\n\n setModeState: (sessionId: SessionId, modeState: SessionModeState | null | undefined) => {\n set((prev) => {\n return {\n sessionModes: { ...prev.sessionModes, [sessionId]: modeState },\n };\n });\n },\n\n addNotification: (notification: NotificationEventData) => {\n const current = get().notifications;\n const sessionId = get().activeSessionId;\n if (!sessionId) {\n return;\n }\n const newNotification: NotificationEvent = {\n ...notification,\n id: `${Date.now()}-${Math.random()}`,\n timestamp: Date.now(),\n };\n\n const sessionNotifications = current[sessionId] || [];\n const updated = {\n ...current,\n [sessionId]: [...sessionNotifications, newNotification],\n };\n set({ notifications: updated });\n },\n\n clearNotifications: (sessionId?: SessionId) => {\n if (sessionId) {\n const current = get().notifications;\n const updated = { ...current };\n delete updated[sessionId];\n set({ notifications: updated });\n } else {\n set({ notifications: {} });\n }\n },\n\n getActiveNotifications: () => {\n const { activeSessionId, notifications } = get();\n return activeSessionId ? notifications[activeSessionId] || [] : [];\n },\n\n // Getters\n getActiveConnection: () => {\n const { activeConnectionUrl, connections } = get();\n return activeConnectionUrl ? connections[activeConnectionUrl] || null : null;\n },\n\n getConnection: (url: string) => {\n const { connections } = get();\n return connections[url] || { url, state: { status: \"disconnected\" }, capabilities: null };\n },\n}));\n"]}
1
+ {"version":3,"file":"atoms.js","sourceRoot":"","sources":["../../src/state/atoms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAkDjC,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACzD,yBAAyB;IACzB,WAAW,EAAE,EAAE;IACf,mBAAmB,EAAE,IAAI;IAEzB,eAAe;IACf,eAAe,EAAE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, SessionModeState } from \"@agentclientprotocol/sdk\";\nimport { create } from \"zustand\";\nimport type {\n Connection,\n ConnectionState,\n ConnectionUrl,\n NotificationEvent,\n NotificationEventData,\n SessionId,\n} from \"./types.js\";\n\ninterface AcpState {\n // Multi-connection support\n connections: Record<ConnectionUrl, Connection>;\n activeConnectionUrl: ConnectionUrl | null;\n\n // Legacy single-connection interface (for backward compatibility)\n connectionState: ConnectionState;\n agentCapabilities: AgentCapabilities | null;\n\n // Session management\n activeSessionId: SessionId | null;\n notifications: Record<SessionId, NotificationEvent[]>;\n sessionModes: Record<SessionId, SessionModeState | null | undefined>;\n\n // Connection management\n setConnection: (\n url: ConnectionUrl,\n state: ConnectionState,\n capabilities?: AgentCapabilities | null,\n ) => void;\n setActiveConnection: (url: ConnectionUrl | null) => void;\n removeConnection: (url: ConnectionUrl) => void;\n\n // Legacy methods (for backward compatibility)\n setConnectionState: (state: ConnectionState) => void;\n setAgentCapabilities: (capabilities: AgentCapabilities | null) => void;\n\n // Session methods\n setActiveSessionId: (sessionId: SessionId | null) => void;\n setActiveModeId: (sessionId: SessionId, modeId: SessionModeId | null | undefined) => void;\n setModeState: (sessionId: SessionId, modeState: SessionModeState | null | undefined) => void;\n addNotification: (notification: NotificationEventData) => void;\n clearNotifications: (sessionId?: SessionId) => void;\n getActiveNotifications: () => NotificationEvent[];\n\n // Getters\n getActiveConnection: () => Connection | null;\n getConnection: (url: ConnectionUrl) => Connection;\n}\n\nexport const useAcpStore = create<AcpState>((set, get) => ({\n // Multi-connection state\n connections: {},\n activeConnectionUrl: null,\n\n // Legacy state\n connectionState: { status: \"disconnected\" },\n agentCapabilities: null,\n\n // Session state\n activeSessionId: null,\n notifications: {},\n sessionModes: {},\n\n // Connection management\n setConnection: (\n url: ConnectionUrl,\n state: ConnectionState,\n capabilities?: AgentCapabilities | null,\n ) => {\n set((prev) => ({\n connections: {\n ...prev.connections,\n [url]: {\n url,\n state,\n capabilities: capabilities ?? prev.connections[url]?.capabilities ?? null,\n },\n },\n // Update legacy state if this is the active connection\n ...(prev.activeConnectionUrl === url && {\n connectionState: state,\n agentCapabilities: capabilities ?? prev.connections[url]?.capabilities ?? null,\n }),\n }));\n },\n\n setActiveConnection: (url: ConnectionUrl | null) => {\n set((prev) => {\n const activeConnection = url ? prev.connections[url] : null;\n return {\n activeConnectionUrl: url,\n connectionState: activeConnection?.state ?? { status: \"disconnected\" },\n agentCapabilities: activeConnection?.capabilities ?? null,\n };\n });\n },\n\n removeConnection: (url: ConnectionUrl) => {\n set((prev) => {\n const newConnections = { ...prev.connections };\n delete newConnections[url];\n const newActiveUrl = prev.activeConnectionUrl === url ? null : prev.activeConnectionUrl;\n const activeConnection = newActiveUrl ? newConnections[newActiveUrl] : null;\n return {\n connections: newConnections,\n activeConnectionUrl: newActiveUrl,\n connectionState: activeConnection?.state ?? { status: \"disconnected\" },\n agentCapabilities: activeConnection?.capabilities ?? null,\n };\n });\n },\n\n // Legacy methods (for backward compatibility)\n setConnectionState: (connectionState: ConnectionState) => {\n set({ connectionState });\n const { activeConnectionUrl } = get();\n if (activeConnectionUrl) {\n get().setConnection(activeConnectionUrl, connectionState);\n }\n },\n\n setAgentCapabilities: (agentCapabilities: AgentCapabilities | null) => {\n set({ agentCapabilities });\n const { activeConnectionUrl } = get();\n if (activeConnectionUrl) {\n get().setConnection(activeConnectionUrl, get().connectionState, agentCapabilities);\n }\n },\n\n setActiveSessionId: (sessionId: SessionId | null) => {\n set({ activeSessionId: sessionId });\n },\n\n setActiveModeId: (sessionId: SessionId, modeId: SessionModeId | null | undefined) => {\n set((prev) => {\n const prevMode = prev.sessionModes[sessionId];\n return {\n sessionModes: {\n ...prev.sessionModes,\n [sessionId]: { ...prevMode, currentModeId: modeId },\n },\n };\n });\n },\n\n setModeState: (sessionId: SessionId, modeState: SessionModeState | null | undefined) => {\n set((prev) => {\n return {\n sessionModes: { ...prev.sessionModes, [sessionId]: modeState },\n };\n });\n },\n\n addNotification: (notification: NotificationEventData) => {\n const current = get().notifications;\n const sessionId = get().activeSessionId;\n if (!sessionId) {\n return;\n }\n const newNotification: NotificationEvent = {\n ...notification,\n id: `${Date.now()}-${Math.random()}`,\n timestamp: Date.now(),\n };\n\n const sessionNotifications = current[sessionId] || [];\n const updated = {\n ...current,\n [sessionId]: [...sessionNotifications, newNotification],\n };\n set({ notifications: updated });\n },\n\n clearNotifications: (sessionId?: SessionId) => {\n if (sessionId) {\n const current = get().notifications;\n const updated = { ...current };\n delete updated[sessionId];\n set({ notifications: updated });\n } else {\n set({ notifications: {} });\n }\n },\n\n getActiveNotifications: () => {\n const { activeSessionId, notifications } = get();\n return activeSessionId ? notifications[activeSessionId] || [] : [];\n },\n\n // Getters\n getActiveConnection: () => {\n const { activeConnectionUrl, connections } = get();\n return activeConnectionUrl ? connections[activeConnectionUrl] || null : null;\n },\n\n getConnection: (url: string) => {\n const { connections } = get();\n return connections[url] || { url, state: { status: \"disconnected\" }, capabilities: null };\n },\n}));\n"]}
@@ -1,4 +1,4 @@
1
- import type { AgentCapabilities, SessionNotification } from "@zed-industries/agent-client-protocol";
1
+ import type { AgentCapabilities, SessionNotification } from "@agentclientprotocol/sdk";
2
2
  export type AgentId = string & {
3
3
  __brand: "AgentId";
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/state/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAEpG,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,CAAC;IAC9D,KAAK,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,MAAM,MAAM,qBAAqB,GAC7B;IACE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,IAAI,EAAE,mBAAmB,CAAC;CAC3B,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,IAAI,EAAE,eAAe,CAAC;CACvB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,KAAK,CAAC;CACb,CAAC;AAEN,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/state/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentCapabilities, SessionNotification } from \"@zed-industries/agent-client-protocol\";\n\nexport type AgentId = string & { __brand: \"AgentId\" };\nexport type SessionId = string & { __brand: \"SessionId\" };\nexport type ConnectionUrl = string;\n\nexport interface ConnectionState {\n status: \"disconnected\" | \"connecting\" | \"connected\" | \"error\";\n error?: string;\n url?: string;\n}\n\nexport interface Connection {\n url: string;\n state: ConnectionState;\n capabilities: AgentCapabilities | null;\n}\n\nexport type NotificationEventData =\n | {\n type: \"session_notification\";\n data: SessionNotification;\n }\n | {\n type: \"connection_change\";\n data: ConnectionState;\n }\n | {\n type: \"error\";\n data: Error;\n };\n\nexport type NotificationEvent = {\n id: string;\n timestamp: number;\n} & NotificationEventData;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/state/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentCapabilities, SessionNotification } from \"@agentclientprotocol/sdk\";\n\nexport type AgentId = string & { __brand: \"AgentId\" };\nexport type SessionId = string & { __brand: \"SessionId\" };\nexport type ConnectionUrl = string;\n\nexport interface ConnectionState {\n status: \"disconnected\" | \"connecting\" | \"connected\" | \"error\";\n error?: string;\n url?: string;\n}\n\nexport interface Connection {\n url: string;\n state: ConnectionState;\n capabilities: AgentCapabilities | null;\n}\n\nexport type NotificationEventData =\n | {\n type: \"session_notification\";\n data: SessionNotification;\n }\n | {\n type: \"connection_change\";\n data: ConnectionState;\n }\n | {\n type: \"error\";\n data: Error;\n };\n\nexport type NotificationEvent = {\n id: string;\n timestamp: number;\n} & NotificationEventData;\n"]}
@@ -1,4 +1,4 @@
1
- import type { ToolCallUpdate } from "@zed-industries/agent-client-protocol";
1
+ import type { ToolCallUpdate } from "@agentclientprotocol/sdk";
2
2
  import type { NotificationEvent } from "./types.js";
3
3
  /**
4
4
  * Group notifications by their type
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAG5E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,EAAE,EAAE,CAW5F;AAmBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAoBxE"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,EAAE,EAAE,CAW5F;AAmBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAoBxE"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;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G,GAAG,IAAI,GAAG,EAA4B,CAAC;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC/B,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1B,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,0BAA0B,CAAC,CAAC;QAC3D,OAAO;YACL,GAAG,KAAK;YACR,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM;YAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACpE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;YACxD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;SAC5B,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ToolCallUpdate } from \"@zed-industries/agent-client-protocol\";\nimport type { SessionUpdate } from \"../client/types.js\";\nimport { invariant } from \"../utils/never.js\";\nimport type { NotificationEvent } from \"./types.js\";\n\n/**\n * Group notifications by their type\n */\nexport function groupNotifications(notifications: NotificationEvent[]): NotificationEvent[][] {\n const result: NotificationEvent[][] = [];\n for (const notification of notifications) {\n const lastGroup = result[result.length - 1];\n if (lastGroup && isSameType(lastGroup.at(0), notification)) {\n lastGroup.push(notification);\n } else {\n result.push([notification]);\n }\n }\n return result;\n}\n\nconst TOOL_TYPES: SessionUpdate[\"sessionUpdate\"][] = [\"tool_call\", \"tool_call_update\"];\n\nfunction isSameType(a: NotificationEvent | undefined, b: NotificationEvent): boolean {\n if (!a) return false;\n if (a.type === \"session_notification\" && b.type === \"session_notification\") {\n // Group tool calls together (may have multiple tool-ids)\n if (\n TOOL_TYPES.includes(a.data.update.sessionUpdate) &&\n TOOL_TYPES.includes(b.data.update.sessionUpdate)\n ) {\n return true;\n }\n return a.data.update.sessionUpdate === b.data.update.sessionUpdate;\n }\n return a.type === b.type;\n}\n\nexport function mergeToolCalls(calls: ToolCallUpdate[]): ToolCallUpdate[] {\n const map = new Map<string, ToolCallUpdate[]>();\n for (const call of calls) {\n if (!map.has(call.toolCallId)) {\n map.set(call.toolCallId, []);\n }\n map.get(call.toolCallId)?.push(call);\n }\n return Array.from(map.values()).map((calls) => {\n const first = calls.at(0);\n invariant(!!first?.toolCallId, \"Tool call ID is required\");\n return {\n ...first,\n toolCallId: first.toolCallId,\n status: calls.at(-1)?.status,\n rawOutput: Object.assign({}, ...calls.map((call) => call.rawOutput)),\n locations: calls.flatMap((call) => call.locations || []),\n content: calls.flatMap((call) => call.content || []),\n } satisfies ToolCallUpdate;\n });\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/state/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,aAAkC;IACnE,MAAM,MAAM,GAA0B,EAAE,CAA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IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC/B,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1B,SAAS,CAAC,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,0BAA0B,CAAC,CAAC;QAC3D,OAAO;YACL,GAAG,KAAK;YACR,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM;YAC5B,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACpE,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;YACxD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;SAC5B,CAAC;IAC7B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ToolCallUpdate } from \"@agentclientprotocol/sdk\";\nimport type { SessionUpdate } from \"../client/types.js\";\nimport { invariant } from \"../utils/never.js\";\nimport type { NotificationEvent } from \"./types.js\";\n\n/**\n * Group notifications by their type\n */\nexport function groupNotifications(notifications: NotificationEvent[]): NotificationEvent[][] {\n const result: NotificationEvent[][] = [];\n for (const notification of notifications) {\n const lastGroup = result[result.length - 1];\n if (lastGroup && isSameType(lastGroup.at(0), notification)) {\n lastGroup.push(notification);\n } else {\n result.push([notification]);\n }\n }\n return result;\n}\n\nconst TOOL_TYPES: SessionUpdate[\"sessionUpdate\"][] = [\"tool_call\", \"tool_call_update\"];\n\nfunction isSameType(a: NotificationEvent | undefined, b: NotificationEvent): boolean {\n if (!a) return false;\n if (a.type === \"session_notification\" && b.type === \"session_notification\") {\n // Group tool calls together (may have multiple tool-ids)\n if (\n TOOL_TYPES.includes(a.data.update.sessionUpdate) &&\n TOOL_TYPES.includes(b.data.update.sessionUpdate)\n ) {\n return true;\n }\n return a.data.update.sessionUpdate === b.data.update.sessionUpdate;\n }\n return a.type === b.type;\n}\n\nexport function mergeToolCalls(calls: ToolCallUpdate[]): ToolCallUpdate[] {\n const map = new Map<string, ToolCallUpdate[]>();\n for (const call of calls) {\n if (!map.has(call.toolCallId)) {\n map.set(call.toolCallId, []);\n }\n map.get(call.toolCallId)?.push(call);\n }\n return Array.from(map.values()).map((calls) => {\n const first = calls.at(0);\n invariant(!!first?.toolCallId, \"Tool call ID is required\");\n return {\n ...first,\n toolCallId: first.toolCallId,\n status: calls.at(-1)?.status,\n rawOutput: Object.assign({}, ...calls.map((call) => call.rawOutput)),\n locations: calls.flatMap((call) => call.locations || []),\n content: calls.flatMap((call) => call.content || []),\n } satisfies ToolCallUpdate;\n });\n}\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * JSON-RPC 2.0 error structure
3
+ */
4
+ export interface JsonRpcErrorData {
5
+ code: number;
6
+ message: string;
7
+ data?: unknown;
8
+ }
9
+ /**
10
+ * JSON-RPC 2.0 error response
11
+ */
12
+ export interface JsonRpcErrorResponse {
13
+ jsonrpc: "2.0";
14
+ id: number | string | null;
15
+ error: JsonRpcErrorData;
16
+ }
17
+ /**
18
+ * Custom Error class for JSON-RPC errors
19
+ */
20
+ export declare class JsonRpcError extends Error {
21
+ readonly code: number;
22
+ readonly data?: unknown;
23
+ readonly id?: number | string | null;
24
+ constructor(error: JsonRpcErrorData, id?: number | string | null);
25
+ /**
26
+ * Check if an error is a JSON-RPC error
27
+ */
28
+ static isJsonRpcError(error: unknown): error is JsonRpcError;
29
+ /**
30
+ * Convert to a plain object
31
+ */
32
+ toJSON(): JsonRpcErrorResponse;
33
+ }
34
+ /**
35
+ * Standard JSON-RPC error codes
36
+ */
37
+ export declare const JsonRpcErrorCodes: {
38
+ readonly PARSE_ERROR: -32700;
39
+ readonly INVALID_REQUEST: -32600;
40
+ readonly METHOD_NOT_FOUND: -32601;
41
+ readonly INVALID_PARAMS: -32602;
42
+ readonly INTERNAL_ERROR: -32603;
43
+ };
44
+ //# sourceMappingURL=jsonrpc-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonrpc-error.d.ts","sourceRoot":"","sources":["../../src/utils/jsonrpc-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,IAAI,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAgB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;gBAEhC,KAAK,EAAE,gBAAgB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQhE;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY;IAI5D;;OAEG;IACH,MAAM,IAAI,oBAAoB;CAW/B;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;CAMpB,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Custom Error class for JSON-RPC errors
3
+ */
4
+ export class JsonRpcError extends Error {
5
+ code;
6
+ data;
7
+ id;
8
+ constructor(error, id) {
9
+ super(error.message);
10
+ this.name = "JsonRpcError";
11
+ this.code = error.code;
12
+ this.data = error.data;
13
+ this.id = id;
14
+ }
15
+ /**
16
+ * Check if an error is a JSON-RPC error
17
+ */
18
+ static isJsonRpcError(error) {
19
+ return error instanceof JsonRpcError;
20
+ }
21
+ /**
22
+ * Convert to a plain object
23
+ */
24
+ toJSON() {
25
+ return {
26
+ jsonrpc: "2.0",
27
+ id: this.id ?? null,
28
+ error: {
29
+ code: this.code,
30
+ message: this.message,
31
+ data: this.data,
32
+ },
33
+ };
34
+ }
35
+ }
36
+ /**
37
+ * Standard JSON-RPC error codes
38
+ */
39
+ export const JsonRpcErrorCodes = {
40
+ PARSE_ERROR: -32700,
41
+ INVALID_REQUEST: -32600,
42
+ METHOD_NOT_FOUND: -32601,
43
+ INVALID_PARAMS: -32602,
44
+ INTERNAL_ERROR: -32603,
45
+ };
46
+ //# sourceMappingURL=jsonrpc-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonrpc-error.js","sourceRoot":"","sources":["../../src/utils/jsonrpc-error.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrB,IAAI,CAAS;IACb,IAAI,CAAW;IACf,EAAE,CAA0B;IAE5C,YAAY,KAAuB,EAAE,EAA2B;QAC9D,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,KAAc;QAClC,OAAO,KAAK,YAAY,YAAY,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,CAAC,EAAE,IAAI,IAAI;YACnB,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;SACF,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,WAAW,EAAE,CAAC,KAAK;IACnB,eAAe,EAAE,CAAC,KAAK;IACvB,gBAAgB,EAAE,CAAC,KAAK;IACxB,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;CACd,CAAC","sourcesContent":["/**\n * JSON-RPC 2.0 error structure\n */\nexport interface JsonRpcErrorData {\n code: number;\n message: string;\n data?: unknown;\n}\n\n/**\n * JSON-RPC 2.0 error response\n */\nexport interface JsonRpcErrorResponse {\n jsonrpc: \"2.0\";\n id: number | string | null;\n error: JsonRpcErrorData;\n}\n\n/**\n * Custom Error class for JSON-RPC errors\n */\nexport class JsonRpcError extends Error {\n public readonly code: number;\n public readonly data?: unknown;\n public readonly id?: number | string | null;\n\n constructor(error: JsonRpcErrorData, id?: number | string | null) {\n super(error.message);\n this.name = \"JsonRpcError\";\n this.code = error.code;\n this.data = error.data;\n this.id = id;\n }\n\n /**\n * Check if an error is a JSON-RPC error\n */\n static isJsonRpcError(error: unknown): error is JsonRpcError {\n return error instanceof JsonRpcError;\n }\n\n /**\n * Convert to a plain object\n */\n toJSON(): JsonRpcErrorResponse {\n return {\n jsonrpc: \"2.0\",\n id: this.id ?? null,\n error: {\n code: this.code,\n message: this.message,\n data: this.data,\n },\n };\n }\n}\n\n/**\n * Standard JSON-RPC error codes\n */\nexport const JsonRpcErrorCodes = {\n PARSE_ERROR: -32700,\n INVALID_REQUEST: -32600,\n METHOD_NOT_FOUND: -32601,\n INVALID_PARAMS: -32602,\n INTERNAL_ERROR: -32603,\n} as const;\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "use-acp",
4
- "version": "0.2.3",
4
+ "version": "0.2.5",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -63,7 +63,7 @@
63
63
  ]
64
64
  },
65
65
  "dependencies": {
66
- "@zed-industries/agent-client-protocol": "^0.3.1",
66
+ "@agentclientprotocol/sdk": "^0.4.9",
67
67
  "zustand": "^5.0.2"
68
68
  },
69
69
  "scripts": {