@posthog/agent 1.25.0 → 1.26.0
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/dist/_virtual/_tslib.js +74 -0
- package/dist/_virtual/_tslib.js.map +1 -0
- package/dist/_virtual/index.js +2 -2
- package/dist/_virtual/index2.js +2 -2
- package/dist/_virtual/index8.js +2 -2
- package/dist/_virtual/index9.js +2 -2
- package/dist/node_modules/@agentclientprotocol/sdk/dist/acp.js +284 -3
- package/dist/node_modules/@agentclientprotocol/sdk/dist/acp.js.map +1 -1
- package/dist/node_modules/@agentclientprotocol/sdk/dist/schema.js +2 -1
- package/dist/node_modules/@agentclientprotocol/sdk/dist/schema.js.map +1 -1
- package/dist/node_modules/ajv/dist/ajv.js +1 -1
- package/dist/node_modules/ajv/dist/compile/codegen/index.js +1 -1
- package/dist/node_modules/ajv/dist/compile/validate/index.js +1 -1
- package/dist/node_modules/ajv/dist/vocabularies/discriminator/index.js +1 -1
- package/dist/node_modules/ajv-formats/dist/index.js +1 -1
- package/dist/package.json.js +1 -1
- package/dist/src/adapters/claude/claude.d.ts.map +1 -1
- package/dist/src/adapters/claude/claude.js +21 -5
- package/dist/src/adapters/claude/claude.js.map +1 -1
- package/dist/src/adapters/claude/mcp-server.js +105 -92
- package/dist/src/adapters/claude/mcp-server.js.map +1 -1
- package/dist/src/adapters/claude/tools.d.ts.map +1 -1
- package/dist/src/adapters/claude/tools.js +8 -1
- package/dist/src/adapters/claude/tools.js.map +1 -1
- package/dist/src/agent.d.ts +7 -1
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +151 -0
- package/dist/src/agent.js.map +1 -1
- package/dist/src/session-store.d.ts +7 -2
- package/dist/src/session-store.d.ts.map +1 -1
- package/dist/src/session-store.js +11 -0
- package/dist/src/session-store.js.map +1 -1
- package/dist/src/worktree-manager.d.ts.map +1 -1
- package/dist/src/worktree-manager.js +3 -5
- package/dist/src/worktree-manager.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/claude/claude.ts +21 -5
- package/src/adapters/claude/tools.ts +8 -1
- package/src/agent.ts +213 -1
- package/src/session-store.ts +18 -3
- package/src/worktree-manager.ts +4 -7
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function __addDisposableResource(env, value, async) {
|
|
19
|
+
if (value !== null && value !== void 0) {
|
|
20
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
21
|
+
var dispose, inner;
|
|
22
|
+
if (async) {
|
|
23
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
24
|
+
dispose = value[Symbol.asyncDispose];
|
|
25
|
+
}
|
|
26
|
+
if (dispose === void 0) {
|
|
27
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
28
|
+
dispose = value[Symbol.dispose];
|
|
29
|
+
if (async) inner = dispose;
|
|
30
|
+
}
|
|
31
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
32
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
33
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
34
|
+
}
|
|
35
|
+
else if (async) {
|
|
36
|
+
env.stack.push({ async: true });
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
43
|
+
var e = new Error(message);
|
|
44
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function __disposeResources(env) {
|
|
48
|
+
function fail(e) {
|
|
49
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
50
|
+
env.hasError = true;
|
|
51
|
+
}
|
|
52
|
+
var r, s = 0;
|
|
53
|
+
function next() {
|
|
54
|
+
while (r = env.stack.pop()) {
|
|
55
|
+
try {
|
|
56
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
57
|
+
if (r.dispose) {
|
|
58
|
+
var result = r.dispose.call(r.value);
|
|
59
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
60
|
+
}
|
|
61
|
+
else s |= 1;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
fail(e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
68
|
+
if (env.hasError) throw env.error;
|
|
69
|
+
}
|
|
70
|
+
return next();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { __addDisposableResource, __disposeResources };
|
|
74
|
+
//# sourceMappingURL=_tslib.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_tslib.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/_virtual/index.js
CHANGED
package/dist/_virtual/index2.js
CHANGED
package/dist/_virtual/index8.js
CHANGED
package/dist/_virtual/index9.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { CLIENT_METHODS, AGENT_METHODS, setSessionModelRequestSchema, promptRequestSchema, authenticateRequestSchema, setSessionModeRequestSchema, loadSessionRequestSchema, newSessionRequestSchema, initializeRequestSchema, cancelNotificationSchema } from './schema.js';
|
|
3
|
-
export { agentCapabilitiesSchema, agentNotificationSchema, agentOutgoingMessageSchema, agentRequestSchema, agentResponseSchema, annotationsSchema, authMethodSchema, authenticateResponseSchema, availableCommandInputSchema, availableCommandSchema, blobResourceContentsSchema, clientCapabilitiesSchema, clientNotificationSchema, clientOutgoingMessageSchema, clientRequestSchema, clientResponseSchema, contentBlockSchema,
|
|
2
|
+
import { CLIENT_METHODS, AGENT_METHODS, setSessionModelRequestSchema, promptRequestSchema, authenticateRequestSchema, setSessionModeRequestSchema, loadSessionRequestSchema, newSessionRequestSchema, initializeRequestSchema, cancelNotificationSchema, killTerminalCommandRequestSchema, waitForTerminalExitRequestSchema, releaseTerminalRequestSchema, terminalOutputRequestSchema, createTerminalRequestSchema, requestPermissionRequestSchema, readTextFileRequestSchema, writeTextFileRequestSchema, sessionNotificationSchema } from './schema.js';
|
|
3
|
+
export { PROTOCOL_VERSION, agentCapabilitiesSchema, agentNotificationSchema, agentOutgoingMessageSchema, agentRequestSchema, agentResponseSchema, annotationsSchema, authMethodSchema, authenticateResponseSchema, availableCommandInputSchema, availableCommandSchema, blobResourceContentsSchema, clientCapabilitiesSchema, clientNotificationSchema, clientOutgoingMessageSchema, clientRequestSchema, clientResponseSchema, contentBlockSchema, createTerminalResponseSchema, embeddedResourceResourceSchema, envVariableSchema, errorSchema, extMethodRequest1Schema, extMethodRequestSchema, extMethodResponse1Schema, extMethodResponseSchema, extNotification1Schema, extNotificationSchema, fileSystemCapabilitySchema, httpHeaderSchema, implementationSchema, initializeResponseSchema, killTerminalResponseSchema, loadSessionResponseSchema, mcpCapabilitiesSchema, mcpServerSchema, modelInfoSchema, newSessionResponseSchema, notification1Schema, notificationSchema, null1Schema, nullSchema, number1Schema, numberSchema, permissionOptionSchema, planEntrySchema, promptCapabilitiesSchema, promptResponseSchema, readTextFileResponseSchema, releaseTerminalResponseSchema, request1Schema, requestPermissionResponseSchema, requestSchema, response1Schema, responseSchema, roleSchema, sessionModeIdSchema, sessionModeSchema, sessionModeStateSchema, sessionModelStateSchema, setSessionModeResponseSchema, setSessionModelResponseSchema, stdioSchema, string1Schema, stringSchema, terminalExitStatusSchema, terminalOutputResponseSchema, textResourceContentsSchema, toolCallContentSchema, toolCallLocationSchema, toolCallStatusSchema, toolKindSchema, unstructuredCommandInputSchema, waitForTerminalExitResponseSchema, writeTextFileResponseSchema } from './schema.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* An agent-side connection to a client.
|
|
@@ -314,6 +314,287 @@ class TerminalHandle {
|
|
|
314
314
|
await this.release();
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* A client-side connection to an agent.
|
|
319
|
+
*
|
|
320
|
+
* This class provides the client's view of an ACP connection, allowing
|
|
321
|
+
* clients (such as code editors) to communicate with agents. It implements
|
|
322
|
+
* the {@link Agent} interface to provide methods for initializing sessions, sending
|
|
323
|
+
* prompts, and managing the agent lifecycle.
|
|
324
|
+
*
|
|
325
|
+
* See protocol docs: [Client](https://agentclientprotocol.com/protocol/overview#client)
|
|
326
|
+
*/
|
|
327
|
+
class ClientSideConnection {
|
|
328
|
+
#connection;
|
|
329
|
+
/**
|
|
330
|
+
* Creates a new client-side connection to an agent.
|
|
331
|
+
*
|
|
332
|
+
* This establishes the communication channel between a client and agent
|
|
333
|
+
* following the ACP specification.
|
|
334
|
+
*
|
|
335
|
+
* @param toClient - A function that creates a Client handler to process incoming agent requests
|
|
336
|
+
* @param stream - The bidirectional message stream for communication. Typically created using
|
|
337
|
+
* {@link ndJsonStream} for stdio-based connections.
|
|
338
|
+
*
|
|
339
|
+
* See protocol docs: [Communication Model](https://agentclientprotocol.com/protocol/overview#communication-model)
|
|
340
|
+
*/
|
|
341
|
+
constructor(toClient, stream) {
|
|
342
|
+
const client = toClient(this);
|
|
343
|
+
const requestHandler = async (method, params) => {
|
|
344
|
+
switch (method) {
|
|
345
|
+
case CLIENT_METHODS.fs_write_text_file: {
|
|
346
|
+
const validatedParams = writeTextFileRequestSchema.parse(params);
|
|
347
|
+
return client.writeTextFile?.(validatedParams);
|
|
348
|
+
}
|
|
349
|
+
case CLIENT_METHODS.fs_read_text_file: {
|
|
350
|
+
const validatedParams = readTextFileRequestSchema.parse(params);
|
|
351
|
+
return client.readTextFile?.(validatedParams);
|
|
352
|
+
}
|
|
353
|
+
case CLIENT_METHODS.session_request_permission: {
|
|
354
|
+
const validatedParams = requestPermissionRequestSchema.parse(params);
|
|
355
|
+
return client.requestPermission(validatedParams);
|
|
356
|
+
}
|
|
357
|
+
case CLIENT_METHODS.terminal_create: {
|
|
358
|
+
const validatedParams = createTerminalRequestSchema.parse(params);
|
|
359
|
+
return client.createTerminal?.(validatedParams);
|
|
360
|
+
}
|
|
361
|
+
case CLIENT_METHODS.terminal_output: {
|
|
362
|
+
const validatedParams = terminalOutputRequestSchema.parse(params);
|
|
363
|
+
return client.terminalOutput?.(validatedParams);
|
|
364
|
+
}
|
|
365
|
+
case CLIENT_METHODS.terminal_release: {
|
|
366
|
+
const validatedParams = releaseTerminalRequestSchema.parse(params);
|
|
367
|
+
const result = await client.releaseTerminal?.(validatedParams);
|
|
368
|
+
return result ?? {};
|
|
369
|
+
}
|
|
370
|
+
case CLIENT_METHODS.terminal_wait_for_exit: {
|
|
371
|
+
const validatedParams = waitForTerminalExitRequestSchema.parse(params);
|
|
372
|
+
return client.waitForTerminalExit?.(validatedParams);
|
|
373
|
+
}
|
|
374
|
+
case CLIENT_METHODS.terminal_kill: {
|
|
375
|
+
const validatedParams = killTerminalCommandRequestSchema.parse(params);
|
|
376
|
+
const result = await client.killTerminal?.(validatedParams);
|
|
377
|
+
return result ?? {};
|
|
378
|
+
}
|
|
379
|
+
default:
|
|
380
|
+
// Handle extension methods (any method starting with '_')
|
|
381
|
+
if (method.startsWith("_")) {
|
|
382
|
+
const customMethod = method.substring(1);
|
|
383
|
+
if (!client.extMethod) {
|
|
384
|
+
throw RequestError.methodNotFound(method);
|
|
385
|
+
}
|
|
386
|
+
return client.extMethod(customMethod, params);
|
|
387
|
+
}
|
|
388
|
+
throw RequestError.methodNotFound(method);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const notificationHandler = async (method, params) => {
|
|
392
|
+
switch (method) {
|
|
393
|
+
case CLIENT_METHODS.session_update: {
|
|
394
|
+
const validatedParams = sessionNotificationSchema.parse(params);
|
|
395
|
+
return client.sessionUpdate(validatedParams);
|
|
396
|
+
}
|
|
397
|
+
default:
|
|
398
|
+
// Handle extension notifications (any method starting with '_')
|
|
399
|
+
if (method.startsWith("_")) {
|
|
400
|
+
const customMethod = method.substring(1);
|
|
401
|
+
if (!client.extNotification) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
return client.extNotification(customMethod, params);
|
|
405
|
+
}
|
|
406
|
+
throw RequestError.methodNotFound(method);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
this.#connection = new Connection(requestHandler, notificationHandler, stream);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Establishes the connection with a client and negotiates protocol capabilities.
|
|
413
|
+
*
|
|
414
|
+
* This method is called once at the beginning of the connection to:
|
|
415
|
+
* - Negotiate the protocol version to use
|
|
416
|
+
* - Exchange capability information between client and agent
|
|
417
|
+
* - Determine available authentication methods
|
|
418
|
+
*
|
|
419
|
+
* The agent should respond with its supported protocol version and capabilities.
|
|
420
|
+
*
|
|
421
|
+
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
422
|
+
*/
|
|
423
|
+
async initialize(params) {
|
|
424
|
+
return await this.#connection.sendRequest(AGENT_METHODS.initialize, params);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Creates a new conversation session with the agent.
|
|
428
|
+
*
|
|
429
|
+
* Sessions represent independent conversation contexts with their own history and state.
|
|
430
|
+
*
|
|
431
|
+
* The agent should:
|
|
432
|
+
* - Create a new session context
|
|
433
|
+
* - Connect to any specified MCP servers
|
|
434
|
+
* - Return a unique session ID for future requests
|
|
435
|
+
*
|
|
436
|
+
* May return an `auth_required` error if the agent requires authentication.
|
|
437
|
+
*
|
|
438
|
+
* See protocol docs: [Session Setup](https://agentclientprotocol.com/protocol/session-setup)
|
|
439
|
+
*/
|
|
440
|
+
async newSession(params) {
|
|
441
|
+
return await this.#connection.sendRequest(AGENT_METHODS.session_new, params);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Loads an existing session to resume a previous conversation.
|
|
445
|
+
*
|
|
446
|
+
* This method is only available if the agent advertises the `loadSession` capability.
|
|
447
|
+
*
|
|
448
|
+
* The agent should:
|
|
449
|
+
* - Restore the session context and conversation history
|
|
450
|
+
* - Connect to the specified MCP servers
|
|
451
|
+
* - Stream the entire conversation history back to the client via notifications
|
|
452
|
+
*
|
|
453
|
+
* See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions)
|
|
454
|
+
*/
|
|
455
|
+
async loadSession(params) {
|
|
456
|
+
return ((await this.#connection.sendRequest(AGENT_METHODS.session_load, params)) ?? {});
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Sets the operational mode for a session.
|
|
460
|
+
*
|
|
461
|
+
* Allows switching between different agent modes (e.g., "ask", "architect", "code")
|
|
462
|
+
* that affect system prompts, tool availability, and permission behaviors.
|
|
463
|
+
*
|
|
464
|
+
* The mode must be one of the modes advertised in `availableModes` during session
|
|
465
|
+
* creation or loading. Agents may also change modes autonomously and notify the
|
|
466
|
+
* client via `current_mode_update` notifications.
|
|
467
|
+
*
|
|
468
|
+
* This method can be called at any time during a session, whether the Agent is
|
|
469
|
+
* idle or actively generating a turn.
|
|
470
|
+
*
|
|
471
|
+
* See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
|
|
472
|
+
*/
|
|
473
|
+
async setSessionMode(params) {
|
|
474
|
+
return ((await this.#connection.sendRequest(AGENT_METHODS.session_set_mode, params)) ?? {});
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* **UNSTABLE**
|
|
478
|
+
*
|
|
479
|
+
* This capability is not part of the spec yet, and may be removed or changed at any point.
|
|
480
|
+
*
|
|
481
|
+
* Select a model for a given session.
|
|
482
|
+
*/
|
|
483
|
+
async setSessionModel(params) {
|
|
484
|
+
return ((await this.#connection.sendRequest(AGENT_METHODS.session_set_model, params)) ?? {});
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Authenticates the client using the specified authentication method.
|
|
488
|
+
*
|
|
489
|
+
* Called when the agent requires authentication before allowing session creation.
|
|
490
|
+
* The client provides the authentication method ID that was advertised during initialization.
|
|
491
|
+
*
|
|
492
|
+
* After successful authentication, the client can proceed to create sessions with
|
|
493
|
+
* `newSession` without receiving an `auth_required` error.
|
|
494
|
+
*
|
|
495
|
+
* See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization)
|
|
496
|
+
*/
|
|
497
|
+
async authenticate(params) {
|
|
498
|
+
return ((await this.#connection.sendRequest(AGENT_METHODS.authenticate, params)) ?? {});
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Processes a user prompt within a session.
|
|
502
|
+
*
|
|
503
|
+
* This method handles the whole lifecycle of a prompt:
|
|
504
|
+
* - Receives user messages with optional context (files, images, etc.)
|
|
505
|
+
* - Processes the prompt using language models
|
|
506
|
+
* - Reports language model content and tool calls to the Clients
|
|
507
|
+
* - Requests permission to run tools
|
|
508
|
+
* - Executes any requested tool calls
|
|
509
|
+
* - Returns when the turn is complete with a stop reason
|
|
510
|
+
*
|
|
511
|
+
* See protocol docs: [Prompt Turn](https://agentclientprotocol.com/protocol/prompt-turn)
|
|
512
|
+
*/
|
|
513
|
+
async prompt(params) {
|
|
514
|
+
return await this.#connection.sendRequest(AGENT_METHODS.session_prompt, params);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Cancels ongoing operations for a session.
|
|
518
|
+
*
|
|
519
|
+
* This is a notification sent by the client to cancel an ongoing prompt turn.
|
|
520
|
+
*
|
|
521
|
+
* Upon receiving this notification, the Agent SHOULD:
|
|
522
|
+
* - Stop all language model requests as soon as possible
|
|
523
|
+
* - Abort all tool call invocations in progress
|
|
524
|
+
* - Send any pending `session/update` notifications
|
|
525
|
+
* - Respond to the original `session/prompt` request with `StopReason::Cancelled`
|
|
526
|
+
*
|
|
527
|
+
* See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation)
|
|
528
|
+
*/
|
|
529
|
+
async cancel(params) {
|
|
530
|
+
return await this.#connection.sendNotification(AGENT_METHODS.session_cancel, params);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Extension method
|
|
534
|
+
*
|
|
535
|
+
* Allows the Client to send an arbitrary request that is not part of the ACP spec.
|
|
536
|
+
*/
|
|
537
|
+
async extMethod(method, params) {
|
|
538
|
+
return await this.#connection.sendRequest(`_${method}`, params);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Extension notification
|
|
542
|
+
*
|
|
543
|
+
* Allows the Client to send an arbitrary notification that is not part of the ACP spec.
|
|
544
|
+
*/
|
|
545
|
+
async extNotification(method, params) {
|
|
546
|
+
return await this.#connection.sendNotification(`_${method}`, params);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* AbortSignal that aborts when the connection closes.
|
|
550
|
+
*
|
|
551
|
+
* This signal can be used to:
|
|
552
|
+
* - Listen for connection closure: `connection.signal.addEventListener('abort', () => {...})`
|
|
553
|
+
* - Check connection status synchronously: `if (connection.signal.aborted) {...}`
|
|
554
|
+
* - Pass to other APIs (fetch, setTimeout) for automatic cancellation
|
|
555
|
+
*
|
|
556
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```typescript
|
|
560
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
561
|
+
*
|
|
562
|
+
* // Listen for closure
|
|
563
|
+
* connection.signal.addEventListener('abort', () => {
|
|
564
|
+
* console.log('Connection closed - performing cleanup');
|
|
565
|
+
* });
|
|
566
|
+
*
|
|
567
|
+
* // Check status
|
|
568
|
+
* if (connection.signal.aborted) {
|
|
569
|
+
* console.log('Connection is already closed');
|
|
570
|
+
* }
|
|
571
|
+
*
|
|
572
|
+
* // Pass to other APIs
|
|
573
|
+
* fetch(url, { signal: connection.signal });
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
get signal() {
|
|
577
|
+
return this.#connection.signal;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Promise that resolves when the connection closes.
|
|
581
|
+
*
|
|
582
|
+
* The connection closes when the underlying stream ends, either normally or due to an error.
|
|
583
|
+
* Once closed, the connection cannot send or receive any more messages.
|
|
584
|
+
*
|
|
585
|
+
* This is useful for async/await style cleanup:
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```typescript
|
|
589
|
+
* const connection = new ClientSideConnection(client, stream);
|
|
590
|
+
* await connection.closed;
|
|
591
|
+
* console.log('Connection closed - performing cleanup');
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
get closed() {
|
|
595
|
+
return this.#connection.closed;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
317
598
|
class Connection {
|
|
318
599
|
#pendingResponses = new Map();
|
|
319
600
|
#nextRequestId = 0;
|
|
@@ -606,5 +887,5 @@ class RequestError extends Error {
|
|
|
606
887
|
}
|
|
607
888
|
}
|
|
608
889
|
|
|
609
|
-
export { AGENT_METHODS, AgentSideConnection, CLIENT_METHODS, RequestError, TerminalHandle, authenticateRequestSchema, cancelNotificationSchema, initializeRequestSchema, loadSessionRequestSchema, newSessionRequestSchema, promptRequestSchema, setSessionModeRequestSchema, setSessionModelRequestSchema };
|
|
890
|
+
export { AGENT_METHODS, AgentSideConnection, CLIENT_METHODS, ClientSideConnection, RequestError, TerminalHandle, authenticateRequestSchema, cancelNotificationSchema, createTerminalRequestSchema, initializeRequestSchema, killTerminalCommandRequestSchema, loadSessionRequestSchema, newSessionRequestSchema, promptRequestSchema, readTextFileRequestSchema, releaseTerminalRequestSchema, requestPermissionRequestSchema, sessionNotificationSchema, setSessionModeRequestSchema, setSessionModelRequestSchema, terminalOutputRequestSchema, waitForTerminalExitRequestSchema, writeTextFileRequestSchema };
|
|
610
891
|
//# sourceMappingURL=acp.js.map
|