@deepailab/dal-remote-daemon 0.1.0 → 0.1.1

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.
Files changed (59) hide show
  1. package/NOTICE +21 -1
  2. package/THIRD-PARTY-NOTICES.md +192 -0
  3. package/node_modules/@deepailab/dal-remote-server/NOTICE +21 -1
  4. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/acp-agent.js +9 -5
  5. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/claude/query.js +3 -2
  6. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/claude/rewind.js +2 -2
  7. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/cursor-acp-agent.js +13 -9
  8. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/opencode/event-consumer.js +2 -2
  9. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/opencode/v2/runtime.js +2 -1
  10. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/opencode-agent.js +2 -2
  11. package/node_modules/@deepailab/dal-remote-server/dist/server/server/agent/providers/provider-sdk.js +46 -0
  12. package/node_modules/@deepailab/dal-remote-server/package.json +2 -5
  13. package/node_modules/@getpaseo/client/NOTICE +21 -1
  14. package/node_modules/@getpaseo/client/package.json +2 -1
  15. package/node_modules/@getpaseo/highlight/NOTICE +21 -1
  16. package/node_modules/@getpaseo/highlight/package.json +2 -1
  17. package/node_modules/@getpaseo/plugin/NOTICE +21 -1
  18. package/node_modules/@getpaseo/plugin/package.json +2 -1
  19. package/node_modules/@getpaseo/protocol/NOTICE +21 -1
  20. package/node_modules/@getpaseo/protocol/package.json +2 -1
  21. package/node_modules/@getpaseo/relay/NOTICE +21 -1
  22. package/node_modules/@getpaseo/relay/package.json +2 -1
  23. package/package.json +3 -8
  24. package/node_modules/@agentclientprotocol/sdk/LICENSE +0 -191
  25. package/node_modules/@agentclientprotocol/sdk/dist/acp.js +0 -1001
  26. package/node_modules/@agentclientprotocol/sdk/dist/schema/index.js +0 -32
  27. package/node_modules/@agentclientprotocol/sdk/dist/schema/zod.gen.js +0 -2054
  28. package/node_modules/@agentclientprotocol/sdk/dist/stream.js +0 -64
  29. package/node_modules/@agentclientprotocol/sdk/package.json +0 -33
  30. package/node_modules/@anthropic-ai/claude-agent-sdk/LICENSE.md +0 -1
  31. package/node_modules/@anthropic-ai/claude-agent-sdk/package.json +0 -74
  32. package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +0 -165
  33. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/error-interceptor.js +0 -43
  34. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/client.js +0 -78
  35. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/client/client.gen.js +0 -232
  36. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/client/index.js +0 -6
  37. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/client/utils.gen.js +0 -226
  38. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/client.gen.js +0 -3
  39. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/core/auth.gen.js +0 -14
  40. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/core/bodySerializer.gen.js +0 -57
  41. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/core/params.gen.js +0 -102
  42. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/core/pathSerializer.gen.js +0 -106
  43. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/core/queryKeySerializer.gen.js +0 -93
  44. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/core/serverSentEvents.gen.js +0 -139
  45. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/core/utils.gen.js +0 -87
  46. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/sdk.gen.js +0 -3176
  47. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/dist/v2/gen/types.gen.js +0 -2
  48. package/node_modules/@deepailab/dal-remote-server/node_modules/@opencode-ai/sdk/package.json +0 -43
  49. package/node_modules/@opencode/client/dist/chunks/service-contender-1tbj6z39.js +0 -81
  50. package/node_modules/@opencode/client/dist/chunks/service-contender-4tveyqeh.js +0 -34
  51. package/node_modules/@opencode/client/dist/chunks/service-contender-7p1wryha.js +0 -30
  52. package/node_modules/@opencode/client/dist/chunks/service-contender-9rqn6x4v.js +0 -16
  53. package/node_modules/@opencode/client/dist/chunks/service-contender-frbwqjmf.js +0 -145
  54. package/node_modules/@opencode/client/dist/chunks/service-contender-m2eywc8w.js +0 -0
  55. package/node_modules/@opencode/client/dist/chunks/service-contender-n3c99vt5.js +0 -11
  56. package/node_modules/@opencode/client/dist/chunks/service-contender-radw39tv.js +0 -1402
  57. package/node_modules/@opencode/client/dist/chunks/service-contender-vyas3vgt.js +0 -0
  58. package/node_modules/@opencode/client/dist/promise/index.js +0 -79
  59. package/node_modules/@opencode/client/package.json +0 -54
@@ -1,1001 +0,0 @@
1
- import { z } from "zod/v4";
2
- import * as schema from "./schema/index.js";
3
- import * as validate from "./schema/zod.gen.js";
4
- export * from "./schema/index.js";
5
- export * from "./stream.js";
6
- /**
7
- * An agent-side connection to a client.
8
- *
9
- * This class provides the agent's view of an ACP connection, allowing
10
- * agents to communicate with clients. It implements the {@link Client} interface
11
- * to provide methods for requesting permissions, accessing the file system,
12
- * and sending session updates.
13
- *
14
- * See protocol docs: [Agent](https://agentclientprotocol.com/protocol/overview#agent)
15
- */
16
- export class AgentSideConnection {
17
- #connection;
18
- /**
19
- * Creates a new agent-side connection to a client.
20
- *
21
- * This establishes the communication channel from the agent's perspective
22
- * following the ACP specification.
23
- *
24
- * @param toAgent - A function that creates an Agent handler to process incoming client requests
25
- * @param stream - The bidirectional message stream for communication. Typically created using
26
- * {@link ndJsonStream} for stdio-based connections.
27
- *
28
- * See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
29
- */
30
- constructor(toAgent, stream) {
31
- const agent = toAgent(this);
32
- const requestHandler = async (method, params) => {
33
- switch (method) {
34
- case schema.AGENT_METHODS.initialize: {
35
- const validatedParams = validate.zInitializeRequest.parse(params);
36
- return agent.initialize(validatedParams);
37
- }
38
- case schema.AGENT_METHODS.session_new: {
39
- const validatedParams = validate.zNewSessionRequest.parse(params);
40
- return agent.newSession(validatedParams);
41
- }
42
- case schema.AGENT_METHODS.session_load: {
43
- if (!agent.loadSession) {
44
- throw RequestError.methodNotFound(method);
45
- }
46
- const validatedParams = validate.zLoadSessionRequest.parse(params);
47
- return agent.loadSession(validatedParams);
48
- }
49
- case schema.AGENT_METHODS.session_list: {
50
- if (!agent.listSessions) {
51
- throw RequestError.methodNotFound(method);
52
- }
53
- const validatedParams = validate.zListSessionsRequest.parse(params);
54
- return agent.listSessions(validatedParams);
55
- }
56
- case schema.AGENT_METHODS.session_fork: {
57
- if (!agent.unstable_forkSession) {
58
- throw RequestError.methodNotFound(method);
59
- }
60
- const validatedParams = validate.zForkSessionRequest.parse(params);
61
- return agent.unstable_forkSession(validatedParams);
62
- }
63
- case schema.AGENT_METHODS.session_resume: {
64
- if (!agent.unstable_resumeSession) {
65
- throw RequestError.methodNotFound(method);
66
- }
67
- const validatedParams = validate.zResumeSessionRequest.parse(params);
68
- return agent.unstable_resumeSession(validatedParams);
69
- }
70
- case schema.AGENT_METHODS.session_close: {
71
- if (!agent.unstable_closeSession) {
72
- throw RequestError.methodNotFound(method);
73
- }
74
- const validatedParams = validate.zCloseSessionRequest.parse(params);
75
- return agent.unstable_closeSession(validatedParams);
76
- }
77
- case schema.AGENT_METHODS.session_set_mode: {
78
- if (!agent.setSessionMode) {
79
- throw RequestError.methodNotFound(method);
80
- }
81
- const validatedParams = validate.zSetSessionModeRequest.parse(params);
82
- const result = await agent.setSessionMode(validatedParams);
83
- return result ?? {};
84
- }
85
- case schema.AGENT_METHODS.authenticate: {
86
- const validatedParams = validate.zAuthenticateRequest.parse(params);
87
- const result = await agent.authenticate(validatedParams);
88
- return result ?? {};
89
- }
90
- case schema.AGENT_METHODS.logout: {
91
- if (!agent.unstable_logout) {
92
- throw RequestError.methodNotFound(method);
93
- }
94
- const validatedParams = validate.zLogoutRequest.parse(params);
95
- const result = await agent.unstable_logout(validatedParams);
96
- return result ?? {};
97
- }
98
- case schema.AGENT_METHODS.session_prompt: {
99
- const validatedParams = validate.zPromptRequest.parse(params);
100
- return agent.prompt(validatedParams);
101
- }
102
- case schema.AGENT_METHODS.session_set_model: {
103
- if (!agent.unstable_setSessionModel) {
104
- throw RequestError.methodNotFound(method);
105
- }
106
- const validatedParams = validate.zSetSessionModelRequest.parse(params);
107
- const result = await agent.unstable_setSessionModel(validatedParams);
108
- return result ?? {};
109
- }
110
- case schema.AGENT_METHODS.session_set_config_option: {
111
- if (!agent.setSessionConfigOption) {
112
- throw RequestError.methodNotFound(method);
113
- }
114
- const validatedParams = validate.zSetSessionConfigOptionRequest.parse(params);
115
- return agent.setSessionConfigOption(validatedParams);
116
- }
117
- default:
118
- if (agent.extMethod) {
119
- return agent.extMethod(method, params);
120
- }
121
- throw RequestError.methodNotFound(method);
122
- }
123
- };
124
- const notificationHandler = async (method, params) => {
125
- switch (method) {
126
- case schema.AGENT_METHODS.session_cancel: {
127
- const validatedParams = validate.zCancelNotification.parse(params);
128
- return agent.cancel(validatedParams);
129
- }
130
- default:
131
- if (agent.extNotification) {
132
- return agent.extNotification(method, params);
133
- }
134
- throw RequestError.methodNotFound(method);
135
- }
136
- };
137
- this.#connection = new Connection(requestHandler, notificationHandler, stream);
138
- }
139
- /**
140
- * Handles session update notifications from the agent.
141
- *
142
- * This is a notification endpoint (no response expected) that sends
143
- * real-time updates about session progress, including message chunks,
144
- * tool calls, and execution plans.
145
- *
146
- * Note: Clients SHOULD continue accepting tool call updates even after
147
- * sending a `session/cancel` notification, as the agent may send final
148
- * updates before responding with the cancelled stop reason.
149
- *
150
- * See protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output)
151
- */
152
- async sessionUpdate(params) {
153
- return await this.#connection.sendNotification(schema.CLIENT_METHODS.session_update, params);
154
- }
155
- /**
156
- * Requests permission from the user for a tool call operation.
157
- *
158
- * Called by the agent when it needs user authorization before executing
159
- * a potentially sensitive operation. The client should present the options
160
- * to the user and return their decision.
161
- *
162
- * If the client cancels the prompt turn via `session/cancel`, it MUST
163
- * respond to this request with `RequestPermissionOutcome::Cancelled`.
164
- *
165
- * See protocol docs: [Requesting Permission](https://agentclientprotocol.com/protocol/tool-calls#requesting-permission)
166
- */
167
- async requestPermission(params) {
168
- return await this.#connection.sendRequest(schema.CLIENT_METHODS.session_request_permission, params);
169
- }
170
- /**
171
- * Reads content from a text file in the client's file system.
172
- *
173
- * Only available if the client advertises the `fs.readTextFile` capability.
174
- * Allows the agent to access file contents within the client's environment.
175
- *
176
- * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
177
- */
178
- async readTextFile(params) {
179
- return await this.#connection.sendRequest(schema.CLIENT_METHODS.fs_read_text_file, params);
180
- }
181
- /**
182
- * Writes content to a text file in the client's file system.
183
- *
184
- * Only available if the client advertises the `fs.writeTextFile` capability.
185
- * Allows the agent to create or modify files within the client's environment.
186
- *
187
- * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
188
- */
189
- async writeTextFile(params) {
190
- return ((await this.#connection.sendRequest(schema.CLIENT_METHODS.fs_write_text_file, params)) ?? {});
191
- }
192
- /**
193
- * Executes a command in a new terminal.
194
- *
195
- * Returns a `TerminalHandle` that can be used to get output, wait for exit,
196
- * kill the command, or release the terminal.
197
- *
198
- * The terminal can also be embedded in tool calls by using its ID in
199
- * `ToolCallContent` with type "terminal".
200
- *
201
- * @param params - The terminal creation parameters
202
- * @returns A handle to control and monitor the terminal
203
- */
204
- async createTerminal(params) {
205
- const response = await this.#connection.sendRequest(schema.CLIENT_METHODS.terminal_create, params);
206
- return new TerminalHandle(response.terminalId, params.sessionId, this.#connection);
207
- }
208
- /**
209
- * Extension method
210
- *
211
- * Allows the Agent to send an arbitrary request that is not part of the ACP spec.
212
- */
213
- async extMethod(method, params) {
214
- return await this.#connection.sendRequest(method, params);
215
- }
216
- /**
217
- * Extension notification
218
- *
219
- * Allows the Agent to send an arbitrary notification that is not part of the ACP spec.
220
- */
221
- async extNotification(method, params) {
222
- return await this.#connection.sendNotification(method, params);
223
- }
224
- /**
225
- * AbortSignal that aborts when the connection closes.
226
- *
227
- * This signal can be used to:
228
- * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
229
- * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
230
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
231
- *
232
- * The connection closes when the underlying stream ends, either normally or due to an error.
233
- *
234
- * @example
235
- * ```typescript
236
- * const connection = new AgentSideConnection(agent, stream);
237
- *
238
- * // Listen for closure
239
- * connection.signal.addEventListener('abort', () => {
240
- * console.log('Connection closed - performing cleanup');
241
- * });
242
- *
243
- * // Check status
244
- * if (connection.signal.aborted) {
245
- * console.log('Connection is already closed');
246
- * }
247
- *
248
- * // Pass to other APIs
249
- * fetch(url, { signal: connection.signal });
250
- * ```
251
- */
252
- get signal() {
253
- return this.#connection.signal;
254
- }
255
- /**
256
- * Promise that resolves when the connection closes.
257
- *
258
- * The connection closes when the underlying stream ends, either normally or due to an error.
259
- * Once closed, the connection cannot send or receive any more messages.
260
- *
261
- * This is useful for async/await style cleanup:
262
- *
263
- * @example
264
- * ```typescript
265
- * const connection = new AgentSideConnection(agent, stream);
266
- * await connection.closed;
267
- * console.log('Connection closed - performing cleanup');
268
- * ```
269
- */
270
- get closed() {
271
- return this.#connection.closed;
272
- }
273
- }
274
- /**
275
- * Handle for controlling and monitoring a terminal created via `createTerminal`.
276
- *
277
- * Provides methods to:
278
- * - Get current output without waiting
279
- * - Wait for command completion
280
- * - Kill the running command
281
- * - Release terminal resources
282
- *
283
- * **Important:** Always call `release()` when done with the terminal to free resources.
284
-
285
- * The terminal supports async disposal via `Symbol.asyncDispose` for automatic cleanup.
286
-
287
- * You can use `await using` to ensure the terminal is automatically released when it
288
- * goes out of scope.
289
- */
290
- export class TerminalHandle {
291
- id;
292
- #sessionId;
293
- #connection;
294
- constructor(id, sessionId, conn) {
295
- this.id = id;
296
- this.#sessionId = sessionId;
297
- this.#connection = conn;
298
- }
299
- /**
300
- * Gets the current terminal output without waiting for the command to exit.
301
- */
302
- async currentOutput() {
303
- return await this.#connection.sendRequest(schema.CLIENT_METHODS.terminal_output, {
304
- sessionId: this.#sessionId,
305
- terminalId: this.id,
306
- });
307
- }
308
- /**
309
- * Waits for the terminal command to complete and returns its exit status.
310
- */
311
- async waitForExit() {
312
- return await this.#connection.sendRequest(schema.CLIENT_METHODS.terminal_wait_for_exit, {
313
- sessionId: this.#sessionId,
314
- terminalId: this.id,
315
- });
316
- }
317
- /**
318
- * Kills the terminal command without releasing the terminal.
319
- *
320
- * The terminal remains valid after killing, allowing you to:
321
- * - Get the final output with `currentOutput()`
322
- * - Check the exit status
323
- * - Release the terminal when done
324
- *
325
- * Useful for implementing timeouts or cancellation.
326
- */
327
- async kill() {
328
- return ((await this.#connection.sendRequest(schema.CLIENT_METHODS.terminal_kill, {
329
- sessionId: this.#sessionId,
330
- terminalId: this.id,
331
- })) ?? {});
332
- }
333
- /**
334
- * Releases the terminal and frees all associated resources.
335
- *
336
- * If the command is still running, it will be killed.
337
- * After release, the terminal ID becomes invalid and cannot be used
338
- * with other terminal methods.
339
- *
340
- * Tool calls that already reference this terminal will continue to
341
- * display its output.
342
- *
343
- * **Important:** Always call this method when done with the terminal.
344
- */
345
- async release() {
346
- return ((await this.#connection.sendRequest(schema.CLIENT_METHODS.terminal_release, {
347
- sessionId: this.#sessionId,
348
- terminalId: this.id,
349
- })) ?? {});
350
- }
351
- async [Symbol.asyncDispose]() {
352
- await this.release();
353
- }
354
- }
355
- /**
356
- * A client-side connection to an agent.
357
- *
358
- * This class provides the client's view of an ACP connection, allowing
359
- * clients (such as code editors) to communicate with agents. It implements
360
- * the {@link Agent} interface to provide methods for initializing sessions, sending
361
- * prompts, and managing the agent lifecycle.
362
- *
363
- * See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
364
- */
365
- export class ClientSideConnection {
366
- #connection;
367
- /**
368
- * Creates a new client-side connection to an agent.
369
- *
370
- * This establishes the communication channel between a client and agent
371
- * following the ACP specification.
372
- *
373
- * @param toClient - A function that creates a Client handler to process incoming agent requests
374
- * @param stream - The bidirectional message stream for communication. Typically created using
375
- * {@link ndJsonStream} for stdio-based connections.
376
- *
377
- * See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
378
- */
379
- constructor(toClient, stream) {
380
- const client = toClient(this);
381
- const requestHandler = async (method, params) => {
382
- switch (method) {
383
- case schema.CLIENT_METHODS.fs_write_text_file: {
384
- const validatedParams = validate.zWriteTextFileRequest.parse(params);
385
- return client.writeTextFile?.(validatedParams);
386
- }
387
- case schema.CLIENT_METHODS.fs_read_text_file: {
388
- const validatedParams = validate.zReadTextFileRequest.parse(params);
389
- return client.readTextFile?.(validatedParams);
390
- }
391
- case schema.CLIENT_METHODS.session_request_permission: {
392
- const validatedParams = validate.zRequestPermissionRequest.parse(params);
393
- return client.requestPermission(validatedParams);
394
- }
395
- case schema.CLIENT_METHODS.terminal_create: {
396
- const validatedParams = validate.zCreateTerminalRequest.parse(params);
397
- return client.createTerminal?.(validatedParams);
398
- }
399
- case schema.CLIENT_METHODS.terminal_output: {
400
- const validatedParams = validate.zTerminalOutputRequest.parse(params);
401
- return client.terminalOutput?.(validatedParams);
402
- }
403
- case schema.CLIENT_METHODS.terminal_release: {
404
- const validatedParams = validate.zReleaseTerminalRequest.parse(params);
405
- const result = await client.releaseTerminal?.(validatedParams);
406
- return result ?? {};
407
- }
408
- case schema.CLIENT_METHODS.terminal_wait_for_exit: {
409
- const validatedParams = validate.zWaitForTerminalExitRequest.parse(params);
410
- return client.waitForTerminalExit?.(validatedParams);
411
- }
412
- case schema.CLIENT_METHODS.terminal_kill: {
413
- const validatedParams = validate.zKillTerminalRequest.parse(params);
414
- const result = await client.killTerminal?.(validatedParams);
415
- return result ?? {};
416
- }
417
- default:
418
- if (client.extMethod) {
419
- return client.extMethod(method, params);
420
- }
421
- throw RequestError.methodNotFound(method);
422
- }
423
- };
424
- const notificationHandler = async (method, params) => {
425
- switch (method) {
426
- case schema.CLIENT_METHODS.session_update: {
427
- const validatedParams = validate.zSessionNotification.parse(params);
428
- return client.sessionUpdate(validatedParams);
429
- }
430
- default:
431
- if (client.extNotification) {
432
- return client.extNotification(method, params);
433
- }
434
- throw RequestError.methodNotFound(method);
435
- }
436
- };
437
- this.#connection = new Connection(requestHandler, notificationHandler, stream);
438
- }
439
- /**
440
- * Establishes the connection with a client and negotiates protocol capabilities.
441
- *
442
- * This method is called once at the beginning of the connection to:
443
- * - Negotiate the protocol version to use
444
- * - Exchange capability information between client and agent
445
- * - Determine available authentication methods
446
- *
447
- * The agent should respond with its supported protocol version and capabilities.
448
- *
449
- * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
450
- */
451
- async initialize(params) {
452
- return await this.#connection.sendRequest(schema.AGENT_METHODS.initialize, params);
453
- }
454
- /**
455
- * Creates a new conversation session with the agent.
456
- *
457
- * Sessions represent independent conversation contexts with their own history and state.
458
- *
459
- * The agent should:
460
- * - Create a new session context
461
- * - Connect to any specified MCP servers
462
- * - Return a unique session ID for future requests
463
- *
464
- * May return an `auth_required` error if the agent requires authentication.
465
- *
466
- * See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
467
- */
468
- async newSession(params) {
469
- return await this.#connection.sendRequest(schema.AGENT_METHODS.session_new, params);
470
- }
471
- /**
472
- * Loads an existing session to resume a previous conversation.
473
- *
474
- * This method is only available if the agent advertises the `loadSession` capability.
475
- *
476
- * The agent should:
477
- * - Restore the session context and conversation history
478
- * - Connect to the specified MCP servers
479
- * - Stream the entire conversation history back to the client via notifications
480
- *
481
- * See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
482
- */
483
- async loadSession(params) {
484
- return ((await this.#connection.sendRequest(schema.AGENT_METHODS.session_load, params)) ?? {});
485
- }
486
- /**
487
- * **UNSTABLE**
488
- *
489
- * This capability is not part of the spec yet, and may be removed or changed at any point.
490
- *
491
- * Forks an existing session to create a new independent session.
492
- *
493
- * Creates a new session based on the context of an existing one, allowing
494
- * operations like generating summaries without affecting the original session's history.
495
- *
496
- * This method is only available if the agent advertises the `session.fork` capability.
497
- *
498
- * @experimental
499
- */
500
- async unstable_forkSession(params) {
501
- return await this.#connection.sendRequest(schema.AGENT_METHODS.session_fork, params);
502
- }
503
- /**
504
- * Lists existing sessions from the agent.
505
- *
506
- * This method is only available if the agent advertises the `listSessions` capability.
507
- *
508
- * Returns a list of sessions with metadata like session ID, working directory,
509
- * title, and last update time. Supports filtering by working directory and
510
- * cursor-based pagination.
511
- */
512
- async listSessions(params) {
513
- return await this.#connection.sendRequest(schema.AGENT_METHODS.session_list, params);
514
- }
515
- /**
516
- * **UNSTABLE**
517
- *
518
- * This capability is not part of the spec yet, and may be removed or changed at any point.
519
- *
520
- * Resumes an existing session without returning previous messages.
521
- *
522
- * This method is only available if the agent advertises the `session.resume` capability.
523
- *
524
- * The agent should resume the session context, allowing the conversation to continue
525
- * without replaying the message history (unlike `session/load`).
526
- *
527
- * @experimental
528
- */
529
- async unstable_resumeSession(params) {
530
- return await this.#connection.sendRequest(schema.AGENT_METHODS.session_resume, params);
531
- }
532
- /**
533
- * **UNSTABLE**
534
- *
535
- * This capability is not part of the spec yet, and may be removed or changed at any point.
536
- *
537
- * Closes an active session and frees up any resources associated with it.
538
- *
539
- * This method is only available if the agent advertises the `session.close` capability.
540
- *
541
- * The agent must cancel any ongoing work (as if `session/cancel` was called)
542
- * and then free up any resources associated with the session.
543
- *
544
- * @experimental
545
- */
546
- async unstable_closeSession(params) {
547
- return await this.#connection.sendRequest(schema.AGENT_METHODS.session_close, params);
548
- }
549
- /**
550
- * Sets the operational mode for a session.
551
- *
552
- * Allows switching between different agent modes (e.g., "ask", "architect", "code")
553
- * that affect system prompts, tool availability, and permission behaviors.
554
- *
555
- * The mode must be one of the modes advertised in `availableModes` during session
556
- * creation or loading. Agents may also change modes autonomously and notify the
557
- * client via `current_mode_update` notifications.
558
- *
559
- * This method can be called at any time during a session, whether the Agent is
560
- * idle or actively generating a turn.
561
- *
562
- * See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
563
- */
564
- async setSessionMode(params) {
565
- return ((await this.#connection.sendRequest(schema.AGENT_METHODS.session_set_mode, params)) ?? {});
566
- }
567
- /**
568
- * **UNSTABLE**
569
- *
570
- * This capability is not part of the spec yet, and may be removed or changed at any point.
571
- *
572
- * Select a model for a given session.
573
- *
574
- * @experimental
575
- */
576
- async unstable_setSessionModel(params) {
577
- return ((await this.#connection.sendRequest(schema.AGENT_METHODS.session_set_model, params)) ?? {});
578
- }
579
- /**
580
- * Set a configuration option for a given session.
581
- *
582
- * The response contains the full set of configuration options and their current values,
583
- * as changing one option may affect the available values or state of other options.
584
- */
585
- async setSessionConfigOption(params) {
586
- return await this.#connection.sendRequest(schema.AGENT_METHODS.session_set_config_option, params);
587
- }
588
- /**
589
- * Authenticates the client using the specified authentication method.
590
- *
591
- * Called when the agent requires authentication before allowing session creation.
592
- * The client provides the authentication method ID that was advertised during initialization.
593
- *
594
- * After successful authentication, the client can proceed to create sessions with
595
- * `newSession` without receiving an `auth_required` error.
596
- *
597
- * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
598
- */
599
- async authenticate(params) {
600
- return ((await this.#connection.sendRequest(schema.AGENT_METHODS.authenticate, params)) ?? {});
601
- }
602
- /**
603
- * Terminates the current authenticated session.
604
- *
605
- * **UNSTABLE**: This capability is not part of the spec yet, and may be removed or changed at any point.
606
- *
607
- * @experimental
608
- */
609
- async unstable_logout(params) {
610
- return ((await this.#connection.sendRequest(schema.AGENT_METHODS.logout, params)) ?? {});
611
- }
612
- /**
613
- * Processes a user prompt within a session.
614
- *
615
- * This method handles the whole lifecycle of a prompt:
616
- * - Receives user messages with optional context (files, images, etc.)
617
- * - Processes the prompt using language models
618
- * - Reports language model content and tool calls to the Clients
619
- * - Requests permission to run tools
620
- * - Executes any requested tool calls
621
- * - Returns when the turn is complete with a stop reason
622
- *
623
- * See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
624
- */
625
- async prompt(params) {
626
- return await this.#connection.sendRequest(schema.AGENT_METHODS.session_prompt, params);
627
- }
628
- /**
629
- * Cancels ongoing operations for a session.
630
- *
631
- * This is a notification sent by the client to cancel an ongoing prompt turn.
632
- *
633
- * Upon receiving this notification, the Agent SHOULD:
634
- * - Stop all language model requests as soon as possible
635
- * - Abort all tool call invocations in progress
636
- * - Send any pending `session/update` notifications
637
- * - Respond to the original `session/prompt` request with `StopReason::Cancelled`
638
- *
639
- * See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
640
- */
641
- async cancel(params) {
642
- return await this.#connection.sendNotification(schema.AGENT_METHODS.session_cancel, params);
643
- }
644
- /**
645
- * Extension method
646
- *
647
- * Allows the Client to send an arbitrary request that is not part of the ACP spec.
648
- */
649
- async extMethod(method, params) {
650
- return await this.#connection.sendRequest(method, params);
651
- }
652
- /**
653
- * Extension notification
654
- *
655
- * Allows the Client to send an arbitrary notification that is not part of the ACP spec.
656
- */
657
- async extNotification(method, params) {
658
- return await this.#connection.sendNotification(method, params);
659
- }
660
- /**
661
- * AbortSignal that aborts when the connection closes.
662
- *
663
- * This signal can be used to:
664
- * - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
665
- * - Check connection status synchronously: `if (connection.signal.aborted) {...}`
666
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
667
- *
668
- * The connection closes when the underlying stream ends, either normally or due to an error.
669
- *
670
- * @example
671
- * ```typescript
672
- * const connection = new ClientSideConnection(client, stream);
673
- *
674
- * // Listen for closure
675
- * connection.signal.addEventListener('abort', () => {
676
- * console.log('Connection closed - performing cleanup');
677
- * });
678
- *
679
- * // Check status
680
- * if (connection.signal.aborted) {
681
- * console.log('Connection is already closed');
682
- * }
683
- *
684
- * // Pass to other APIs
685
- * fetch(url, { signal: connection.signal });
686
- * ```
687
- */
688
- get signal() {
689
- return this.#connection.signal;
690
- }
691
- /**
692
- * Promise that resolves when the connection closes.
693
- *
694
- * The connection closes when the underlying stream ends, either normally or due to an error.
695
- * Once closed, the connection cannot send or receive any more messages.
696
- *
697
- * This is useful for async/await style cleanup:
698
- *
699
- * @example
700
- * ```typescript
701
- * const connection = new ClientSideConnection(client, stream);
702
- * await connection.closed;
703
- * console.log('Connection closed - performing cleanup');
704
- * ```
705
- */
706
- get closed() {
707
- return this.#connection.closed;
708
- }
709
- }
710
- class Connection {
711
- #pendingResponses = new Map();
712
- #nextRequestId = 0;
713
- #requestHandler;
714
- #notificationHandler;
715
- #stream;
716
- #writeQueue = Promise.resolve();
717
- #abortController = new AbortController();
718
- #closedPromise;
719
- constructor(requestHandler, notificationHandler, stream) {
720
- this.#requestHandler = requestHandler;
721
- this.#notificationHandler = notificationHandler;
722
- this.#stream = stream;
723
- this.#closedPromise = new Promise((resolve) => {
724
- this.#abortController.signal.addEventListener("abort", () => resolve());
725
- });
726
- this.#receive();
727
- }
728
- /**
729
- * AbortSignal that aborts when the connection closes.
730
- *
731
- * This signal can be used to:
732
- * - Listen for connection closure via event listeners
733
- * - Check connection status synchronously with `signal.aborted`
734
- * - Pass to other APIs (fetch, setTimeout) for automatic cancellation
735
- */
736
- get signal() {
737
- return this.#abortController.signal;
738
- }
739
- /**
740
- * Promise that resolves when the connection closes.
741
- *
742
- * The connection closes when the underlying stream ends, either normally
743
- * or due to an error. Once closed, the connection cannot send or receive
744
- * any more messages.
745
- *
746
- * @example
747
- * ```typescript
748
- * const connection = new ClientSideConnection(client, stream);
749
- * await connection.closed;
750
- * console.log('Connection closed - performing cleanup');
751
- * ```
752
- */
753
- get closed() {
754
- return this.#closedPromise;
755
- }
756
- async #receive() {
757
- const reader = this.#stream.readable.getReader();
758
- try {
759
- while (true) {
760
- const { value: message, done } = await reader.read();
761
- if (done) {
762
- break;
763
- }
764
- if (!message) {
765
- continue;
766
- }
767
- try {
768
- this.#processMessage(message);
769
- }
770
- catch (err) {
771
- console.error("Unexpected error during message processing:", message, err);
772
- // Only send error response if the message had an id (was a request)
773
- if ("id" in message && message.id !== undefined) {
774
- this.#sendMessage({
775
- jsonrpc: "2.0",
776
- id: message.id,
777
- error: {
778
- code: -32700,
779
- message: "Parse error",
780
- },
781
- });
782
- }
783
- }
784
- }
785
- }
786
- finally {
787
- reader.releaseLock();
788
- this.#abortController.abort();
789
- }
790
- }
791
- async #processMessage(message) {
792
- if ("method" in message && "id" in message) {
793
- // It's a request
794
- const response = await this.#tryCallRequestHandler(message.method, message.params);
795
- if ("error" in response) {
796
- console.error("Error handling request", message, response.error);
797
- }
798
- await this.#sendMessage({
799
- jsonrpc: "2.0",
800
- id: message.id,
801
- ...response,
802
- });
803
- }
804
- else if ("method" in message) {
805
- // It's a notification
806
- const response = await this.#tryCallNotificationHandler(message.method, message.params);
807
- if ("error" in response) {
808
- console.error("Error handling notification", message, response.error);
809
- }
810
- }
811
- else if ("id" in message) {
812
- // It's a response
813
- this.#handleResponse(message);
814
- }
815
- else {
816
- console.error("Invalid message", { message });
817
- }
818
- }
819
- async #tryCallRequestHandler(method, params) {
820
- try {
821
- const result = await this.#requestHandler(method, params);
822
- return { result: result ?? null };
823
- }
824
- catch (error) {
825
- if (error instanceof RequestError) {
826
- return error.toResult();
827
- }
828
- if (error instanceof z.ZodError) {
829
- return RequestError.invalidParams(error.format()).toResult();
830
- }
831
- let details;
832
- if (error instanceof Error) {
833
- details = error.message;
834
- }
835
- else if (typeof error === "object" &&
836
- error != null &&
837
- "message" in error &&
838
- typeof error.message === "string") {
839
- details = error.message;
840
- }
841
- try {
842
- return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
843
- }
844
- catch {
845
- return RequestError.internalError({ details }).toResult();
846
- }
847
- }
848
- }
849
- async #tryCallNotificationHandler(method, params) {
850
- try {
851
- await this.#notificationHandler(method, params);
852
- return { result: null };
853
- }
854
- catch (error) {
855
- if (error instanceof RequestError) {
856
- return error.toResult();
857
- }
858
- if (error instanceof z.ZodError) {
859
- return RequestError.invalidParams(error.format()).toResult();
860
- }
861
- let details;
862
- if (error instanceof Error) {
863
- details = error.message;
864
- }
865
- else if (typeof error === "object" &&
866
- error != null &&
867
- "message" in error &&
868
- typeof error.message === "string") {
869
- details = error.message;
870
- }
871
- try {
872
- return RequestError.internalError(details ? JSON.parse(details) : {}).toResult();
873
- }
874
- catch {
875
- return RequestError.internalError({ details }).toResult();
876
- }
877
- }
878
- }
879
- #handleResponse(response) {
880
- const pendingResponse = this.#pendingResponses.get(response.id);
881
- if (pendingResponse) {
882
- if ("result" in response) {
883
- pendingResponse.resolve(response.result);
884
- }
885
- else if ("error" in response) {
886
- pendingResponse.reject(response.error);
887
- }
888
- this.#pendingResponses.delete(response.id);
889
- }
890
- else {
891
- console.error("Got response to unknown request", response.id);
892
- }
893
- }
894
- async sendRequest(method, params) {
895
- const id = this.#nextRequestId++;
896
- const responsePromise = new Promise((resolve, reject) => {
897
- this.#pendingResponses.set(id, { resolve, reject });
898
- });
899
- await this.#sendMessage({ jsonrpc: "2.0", id, method, params });
900
- return responsePromise;
901
- }
902
- async sendNotification(method, params) {
903
- await this.#sendMessage({ jsonrpc: "2.0", method, params });
904
- }
905
- async #sendMessage(message) {
906
- this.#writeQueue = this.#writeQueue
907
- .then(async () => {
908
- const writer = this.#stream.writable.getWriter();
909
- try {
910
- await writer.write(message);
911
- }
912
- finally {
913
- writer.releaseLock();
914
- }
915
- })
916
- .catch((error) => {
917
- // Continue processing writes on error
918
- console.error("ACP write error:", error);
919
- });
920
- return this.#writeQueue;
921
- }
922
- }
923
- /**
924
- * JSON-RPC error object.
925
- *
926
- * Represents an error that occurred during method execution, following the
927
- * JSON-RPC 2.0 error object specification with optional additional data.
928
- *
929
- * See protocol docs: [JSON-RPC Error Object](https://www.jsonrpc.org/specification#error_object)
930
- */
931
- export class RequestError extends Error {
932
- code;
933
- data;
934
- constructor(code, message, data) {
935
- super(message);
936
- this.code = code;
937
- this.name = "RequestError";
938
- this.data = data;
939
- }
940
- /**
941
- * Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
942
- */
943
- static parseError(data, additionalMessage) {
944
- return new RequestError(-32700, `Parse error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
945
- }
946
- /**
947
- * The JSON sent is not a valid Request object.
948
- */
949
- static invalidRequest(data, additionalMessage) {
950
- return new RequestError(-32600, `Invalid request${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
951
- }
952
- /**
953
- * The method does not exist / is not available.
954
- */
955
- static methodNotFound(method) {
956
- return new RequestError(-32601, `"Method not found": ${method}`, {
957
- method,
958
- });
959
- }
960
- /**
961
- * Invalid method parameter(s).
962
- */
963
- static invalidParams(data, additionalMessage) {
964
- return new RequestError(-32602, `Invalid params${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
965
- }
966
- /**
967
- * Internal JSON-RPC error.
968
- */
969
- static internalError(data, additionalMessage) {
970
- return new RequestError(-32603, `Internal error${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
971
- }
972
- /**
973
- * Authentication required.
974
- */
975
- static authRequired(data, additionalMessage) {
976
- return new RequestError(-32000, `Authentication required${additionalMessage ? `: ${additionalMessage}` : ""}`, data);
977
- }
978
- /**
979
- * Resource, such as a file, was not found
980
- */
981
- static resourceNotFound(uri) {
982
- return new RequestError(-32002, `Resource not found${uri ? `: ${uri}` : ""}`, uri && { uri });
983
- }
984
- toResult() {
985
- return {
986
- error: {
987
- code: this.code,
988
- message: this.message,
989
- data: this.data,
990
- },
991
- };
992
- }
993
- toErrorResponse() {
994
- return {
995
- code: this.code,
996
- message: this.message,
997
- data: this.data,
998
- };
999
- }
1000
- }
1001
- //# sourceMappingURL=acp.js.map