@agentclientprotocol/claude-agent-acp 0.85.2-preview.2 → 0.85.2-preview.20
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 +1 -0
- package/dist/acp-agent.d.ts +100 -23
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +528 -183
- package/dist/air-extension.d.ts +2 -0
- package/dist/air-extension.d.ts.map +1 -1
- package/dist/air-extension.js +2 -0
- package/dist/clear-context-coordinator.d.ts +1 -0
- package/dist/clear-context-coordinator.d.ts.map +1 -1
- package/dist/clear-context-coordinator.js +2 -1
- package/dist/diff.d.ts +45 -8
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +111 -30
- package/dist/mcp-command.d.ts +51 -0
- package/dist/mcp-command.d.ts.map +1 -0
- package/dist/mcp-command.js +321 -0
- package/dist/permissions/presentation.d.ts +17 -2
- package/dist/permissions/presentation.d.ts.map +1 -1
- package/dist/permissions/presentation.js +4 -0
- package/dist/resumed-session.d.ts +16 -6
- package/dist/resumed-session.d.ts.map +1 -1
- package/dist/resumed-session.js +91 -25
- package/dist/session-config-ids.d.ts +1 -0
- package/dist/session-config-ids.d.ts.map +1 -1
- package/dist/session-config-ids.js +1 -0
- package/dist/session-mode.d.ts +14 -0
- package/dist/session-mode.d.ts.map +1 -1
- package/dist/session-mode.js +22 -0
- package/dist/tool-calls/client-capabilities.d.ts +20 -2
- package/dist/tool-calls/client-capabilities.d.ts.map +1 -1
- package/dist/tool-calls/client-capabilities.js +14 -4
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +3 -2
- package/dist/tool-calls/reporters/file-edit.d.ts +1 -1
- package/dist/tool-calls/reporters/file-edit.d.ts.map +1 -1
- package/dist/tool-calls/reporters/file-edit.js +20 -14
- package/dist/turn-events.d.ts +11 -5
- package/dist/turn-events.d.ts.map +1 -1
- package/dist/usage-markdown.d.ts +2 -0
- package/dist/usage-markdown.d.ts.map +1 -1
- package/dist/usage-markdown.js +2 -1
- package/dist/utils.d.ts +12 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +121 -17
- package/dist/v2/initialize.d.ts +2 -5
- package/dist/v2/initialize.d.ts.map +1 -1
- package/dist/v2/initialize.js +23 -6
- package/dist/v2/permission.d.ts +25 -0
- package/dist/v2/permission.d.ts.map +1 -0
- package/dist/v2/permission.js +38 -0
- package/dist/v2/prompt.d.ts +47 -0
- package/dist/v2/prompt.d.ts.map +1 -0
- package/dist/v2/prompt.js +153 -0
- package/dist/v2/session-update.d.ts +6 -0
- package/dist/v2/session-update.d.ts.map +1 -1
- package/dist/v2/session-update.js +27 -0
- package/dist/v2/session.d.ts +15 -4
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +20 -6
- package/dist/v2/terminal.d.ts +42 -0
- package/dist/v2/terminal.d.ts.map +1 -0
- package/dist/v2/terminal.js +95 -0
- package/dist/v2/tool-call.d.ts +38 -0
- package/dist/v2/tool-call.d.ts.map +1 -0
- package/dist/v2/tool-call.js +49 -0
- package/package.json +2 -2
package/dist/session-mode.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RequestError, } from "@agentclientprotocol/sdk";
|
|
2
2
|
import { AIR_KIND_KEY, airOnlyMeta } from "./air-extension.js";
|
|
3
|
+
import { resolvePermissionMode } from "./permissions/modes.js";
|
|
3
4
|
import { noticeOrTranscriptUpdate, noticeTranscriptText, sentenceCase, } from "./session-notices.js";
|
|
4
5
|
export const MODE_CONFIG_ID = "mode";
|
|
5
6
|
export const AUTO_MODE_FALLBACK = "acceptEdits";
|
|
@@ -11,6 +12,27 @@ const AUTO_MODE_FALLBACK_NOTICE = {
|
|
|
11
12
|
title: "Auto mode unavailable",
|
|
12
13
|
description: sentenceCase(AUTO_MODE_FALLBACK_REASON),
|
|
13
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* The permission mode a new Claude query starts in.
|
|
17
|
+
*
|
|
18
|
+
* An explicit mode wins. A resume or a load continues in the mode of the last
|
|
19
|
+
* user record of the transcript. If that mode is unknown or not available now,
|
|
20
|
+
* for example bypass, the session starts in `defaultMode` of the settings.
|
|
21
|
+
*/
|
|
22
|
+
export function resolveInitialPermissionMode(sources, logger, allowBypass) {
|
|
23
|
+
if (sources.explicit !== undefined) {
|
|
24
|
+
return resolvePermissionMode(sources.explicit, logger, allowBypass);
|
|
25
|
+
}
|
|
26
|
+
if (sources.resumed !== undefined) {
|
|
27
|
+
let rejected = false;
|
|
28
|
+
const mode = resolvePermissionMode(sources.resumed, { error: () => (rejected = true) }, allowBypass);
|
|
29
|
+
if (!rejected)
|
|
30
|
+
return mode;
|
|
31
|
+
logger.error(`Ignoring permission mode "${sources.resumed}" of the resumed transcript: ` +
|
|
32
|
+
`not available in this session.`);
|
|
33
|
+
}
|
|
34
|
+
return resolvePermissionMode(sources.defaultMode, logger, allowBypass);
|
|
35
|
+
}
|
|
14
36
|
/** Owns session-mode policy and the ACP/SDK synchronization it requires. */
|
|
15
37
|
export class SessionModeManager {
|
|
16
38
|
options;
|
|
@@ -16,6 +16,14 @@ export declare class ClientCapabilities {
|
|
|
16
16
|
readonly diffPatch: boolean;
|
|
17
17
|
/** The capabilities that only JetBrains AIR declares. */
|
|
18
18
|
readonly air: AirCapabilities;
|
|
19
|
+
/**
|
|
20
|
+
* The client speaks ACP v2. Its diffs carry structured `changes` and an
|
|
21
|
+
* optional git patch, which a v1 diff cannot express. Only the v2 surface
|
|
22
|
+
* sets this, never the capabilities that a client sends. A v2 client also
|
|
23
|
+
* takes the terminal extension (`terminalOutput`), which the v2 surface
|
|
24
|
+
* sends as display terminals.
|
|
25
|
+
*/
|
|
26
|
+
readonly v2: boolean;
|
|
19
27
|
constructor(
|
|
20
28
|
/** The client renders a terminal from `_meta.terminal_info`, `terminal_output`, and `terminal_exit`. */
|
|
21
29
|
terminalOutput?: boolean,
|
|
@@ -24,8 +32,18 @@ export declare class ClientCapabilities {
|
|
|
24
32
|
/** The client accepts an exact git patch in a diff (`jetbrains.air` `diffPatch`). */
|
|
25
33
|
diffPatch?: boolean,
|
|
26
34
|
/** The capabilities that only JetBrains AIR declares. */
|
|
27
|
-
air?: AirCapabilities
|
|
28
|
-
|
|
35
|
+
air?: AirCapabilities,
|
|
36
|
+
/**
|
|
37
|
+
* The client speaks ACP v2. Its diffs carry structured `changes` and an
|
|
38
|
+
* optional git patch, which a v1 diff cannot express. Only the v2 surface
|
|
39
|
+
* sets this, never the capabilities that a client sends. A v2 client also
|
|
40
|
+
* takes the terminal extension (`terminalOutput`), which the v2 surface
|
|
41
|
+
* sends as display terminals.
|
|
42
|
+
*/
|
|
43
|
+
v2?: boolean);
|
|
44
|
+
static from(capabilities: AcpClientCapabilities | null | undefined, { v2 }?: {
|
|
45
|
+
v2?: boolean;
|
|
46
|
+
}): ClientCapabilities;
|
|
29
47
|
}
|
|
30
48
|
/** The capabilities of JetBrains AIR, read from `_meta.jetbrains.air`. */
|
|
31
49
|
export interface AirCapabilities {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-capabilities.d.ts","sourceRoot":"","sources":["../../src/tool-calls/client-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,IAAI,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAS5F;;;;;;;GAOG;AACH,qBAAa,kBAAkB;IAE3B,wGAAwG;IACxG,QAAQ,CAAC,cAAc,EAAE,OAAO;IAChC,4FAA4F;IAC5F,QAAQ,CAAC,mBAAmB,EAAE,OAAO;IACrC,qFAAqF;IACrF,QAAQ,CAAC,SAAS,EAAE,OAAO;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,GAAG,EAAE,eAAe;;
|
|
1
|
+
{"version":3,"file":"client-capabilities.d.ts","sourceRoot":"","sources":["../../src/tool-calls/client-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,IAAI,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAS5F;;;;;;;GAOG;AACH,qBAAa,kBAAkB;IAE3B,wGAAwG;IACxG,QAAQ,CAAC,cAAc,EAAE,OAAO;IAChC,4FAA4F;IAC5F,QAAQ,CAAC,mBAAmB,EAAE,OAAO;IACrC,qFAAqF;IACrF,QAAQ,CAAC,SAAS,EAAE,OAAO;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,GAAG,EAAE,eAAe;IAC7B;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,EAAE,OAAO;;IAfpB,wGAAwG;IAC/F,cAAc,GAAE,OAAe;IACxC,4FAA4F;IACnF,mBAAmB,GAAE,OAAe;IAC7C,qFAAqF;IAC5E,SAAS,GAAE,OAAe;IACnC,yDAAyD;IAChD,GAAG,GAAE,eAAwB;IACtC;;;;;;OAMG;IACM,EAAE,GAAE,OAAe;IAG9B,MAAM,CAAC,IAAI,CACT,YAAY,EAAE,qBAAqB,GAAG,IAAI,GAAG,SAAS,EACtD,EAAE,EAAU,EAAE,GAAE;QAAE,EAAE,CAAC,EAAE,OAAO,CAAA;KAAO,GACpC,kBAAkB;CAkBtB;AAED,0EAA0E;AAC1E,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B"}
|
|
@@ -12,6 +12,7 @@ export class ClientCapabilities {
|
|
|
12
12
|
terminalOutputDelta;
|
|
13
13
|
diffPatch;
|
|
14
14
|
air;
|
|
15
|
+
v2;
|
|
15
16
|
constructor(
|
|
16
17
|
/** The client renders a terminal from `_meta.terminal_info`, `terminal_output`, and `terminal_exit`. */
|
|
17
18
|
terminalOutput = false,
|
|
@@ -20,20 +21,29 @@ export class ClientCapabilities {
|
|
|
20
21
|
/** The client accepts an exact git patch in a diff (`jetbrains.air` `diffPatch`). */
|
|
21
22
|
diffPatch = false,
|
|
22
23
|
/** The capabilities that only JetBrains AIR declares. */
|
|
23
|
-
air = NO_AIR
|
|
24
|
+
air = NO_AIR,
|
|
25
|
+
/**
|
|
26
|
+
* The client speaks ACP v2. Its diffs carry structured `changes` and an
|
|
27
|
+
* optional git patch, which a v1 diff cannot express. Only the v2 surface
|
|
28
|
+
* sets this, never the capabilities that a client sends. A v2 client also
|
|
29
|
+
* takes the terminal extension (`terminalOutput`), which the v2 surface
|
|
30
|
+
* sends as display terminals.
|
|
31
|
+
*/
|
|
32
|
+
v2 = false) {
|
|
24
33
|
this.terminalOutput = terminalOutput;
|
|
25
34
|
this.terminalOutputDelta = terminalOutputDelta;
|
|
26
35
|
this.diffPatch = diffPatch;
|
|
27
36
|
this.air = air;
|
|
37
|
+
this.v2 = v2;
|
|
28
38
|
}
|
|
29
|
-
static from(capabilities) {
|
|
39
|
+
static from(capabilities, { v2 = false } = {}) {
|
|
30
40
|
const meta = capabilities?._meta;
|
|
31
41
|
const terminalOutputDelta = meta?.["terminal_output_delta"] === true;
|
|
32
|
-
return new ClientCapabilities(terminalOutputDelta || meta?.["terminal_output"] === true, terminalOutputDelta, clientSupportsAirCapability(capabilities, AIR_DIFF_PATCH_CAPABILITY), {
|
|
42
|
+
return new ClientCapabilities(v2 || terminalOutputDelta || meta?.["terminal_output"] === true, terminalOutputDelta, clientSupportsAirCapability(capabilities, AIR_DIFF_PATCH_CAPABILITY), {
|
|
33
43
|
client: isAirClient(capabilities),
|
|
34
44
|
rawInputRendering: clientSupportsAirCapability(capabilities, AIR_RAW_INPUT_RENDERING_CAPABILITY),
|
|
35
45
|
planFile: clientSupportsAirCapability(capabilities, AIR_PLAN_FILE_CAPABILITY),
|
|
36
|
-
});
|
|
46
|
+
}, v2);
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
const NO_AIR = {
|
|
@@ -1 +1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BlB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO;IAgBzD;;;;OAIG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,eAAe,EAAE;IAS1E;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,cAAc;CA0BtF"}
|
|
@@ -118,8 +118,9 @@ export class AcpToolCallRenderer {
|
|
|
118
118
|
permissionToolCall(toolUse, options = {}) {
|
|
119
119
|
const facts = this.facts(toolUse, options.cwd);
|
|
120
120
|
if (!this.capabilities.air.client) {
|
|
121
|
-
// The upstream shape: the whole tool call again.
|
|
122
|
-
|
|
121
|
+
// The upstream shape: the whole tool call again. A v2 client also gets
|
|
122
|
+
// the exact preview patch, which the tool call does not show.
|
|
123
|
+
const content = options.previewContent ?? this.toolUseContent(toolUse.id, facts);
|
|
123
124
|
const locations = [...(facts.locations ?? []), ...(options.extraLocations ?? [])];
|
|
124
125
|
return {
|
|
125
126
|
toolCallId: toolUse.id,
|
|
@@ -22,7 +22,7 @@ type NormalizedWriteInput = Partial<FileWriteInput> & {
|
|
|
22
22
|
export declare function normalizeWriteInput(input: unknown): NormalizedWriteInput | undefined;
|
|
23
23
|
/** Edit: the diff holds the old and the new text. */
|
|
24
24
|
export declare class EditReporter implements ToolReporter {
|
|
25
|
-
toolUse(input: unknown, { cwd }: ToolUseContext): ToolUseFacts;
|
|
25
|
+
toolUse(input: unknown, { cwd, capabilities }: ToolUseContext): ToolUseFacts;
|
|
26
26
|
toolResult(): ToolResultFacts;
|
|
27
27
|
hookResult(toolResponse: unknown, context: ToolUseContext): Promise<ToolResultFacts>;
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-edit.d.ts","sourceRoot":"","sources":["../../../src/tool-calls/reporters/file-edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EAEf,MAAM,6CAA6C,CAAC;
|
|
1
|
+
{"version":3,"file":"file-edit.d.ts","sourceRoot":"","sources":["../../../src/tool-calls/reporters/file-edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EAEf,MAAM,6CAA6C,CAAC;AAQrD,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACb,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,qBAAa,aAAc,YAAW,YAAY;IAChD,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,cAAc,GAAG,YAAY;IAoCpF,UAAU,IAAI,eAAe;IAI7B,UAAU,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAGrF;AAED,yFAAyF;AACzF,KAAK,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAI9E;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CAYpF;AAED,qDAAqD;AACrD,qBAAa,YAAa,YAAW,YAAY;IAC/C,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,cAAc,GAAG,YAAY;IA0B5E,UAAU,IAAI,eAAe;IAI7B,UAAU,CAAC,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;CAGrF;AAyCD;;;;;;;GAOG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,YAAY,EAAE,EAAE,cAAc,GAAG,YAAY;IAsB5E;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe;CAMxD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { patchUpdateFromDiffToolResponse, toolUpdateFromDiffToolResponse } from "../../diff.js";
|
|
1
|
+
import { patchUpdateFromDiffToolResponse, toolUpdateFromDiffToolResponse, v2UpdateFromDiffToolResponse, } from "../../diff.js";
|
|
2
2
|
import { markdownEscape, resultText, textContent, toDisplayPath } from "../content.js";
|
|
3
3
|
/**
|
|
4
4
|
* Write: the diff holds the file text. The PostToolUse hook sends the final
|
|
@@ -14,12 +14,15 @@ export class WriteReporter {
|
|
|
14
14
|
locations: write?.file_path ? [{ path: write.file_path }] : [],
|
|
15
15
|
};
|
|
16
16
|
if (write?.file_path) {
|
|
17
|
-
// A negotiated client
|
|
18
|
-
// from the PostToolUse hook. The input does not tell
|
|
19
|
-
// exists, so the live tool call shows no diff: a diff
|
|
20
|
-
// text would claim a creation. The adapter reads the
|
|
21
|
-
// preview. A replay has no preview and no hook, so it
|
|
22
|
-
|
|
17
|
+
// A negotiated client and a v2 client get the exact patch from the
|
|
18
|
+
// approval preview or from the PostToolUse hook. The input does not tell
|
|
19
|
+
// whether the file exists, so the live tool call shows no diff: a diff
|
|
20
|
+
// without the old text would claim a creation. The adapter reads the
|
|
21
|
+
// file only for the preview. A replay has no preview and no hook, so it
|
|
22
|
+
// keeps the diff, except for a v2 client: a v2 diff names the operation,
|
|
23
|
+
// which the input does not tell.
|
|
24
|
+
const inputDiff = capabilities.v2 ? false : !capabilities.diffPatch || replay;
|
|
25
|
+
if (inputDiff) {
|
|
23
26
|
facts.change = [
|
|
24
27
|
{
|
|
25
28
|
type: "diff",
|
|
@@ -68,7 +71,7 @@ export function normalizeWriteInput(input) {
|
|
|
68
71
|
}
|
|
69
72
|
/** Edit: the diff holds the old and the new text. */
|
|
70
73
|
export class EditReporter {
|
|
71
|
-
toolUse(input, { cwd }) {
|
|
74
|
+
toolUse(input, { cwd, capabilities }) {
|
|
72
75
|
const edit = input;
|
|
73
76
|
const displayPath = edit?.file_path ? toDisplayPath(edit.file_path, cwd) : undefined;
|
|
74
77
|
const facts = {
|
|
@@ -76,10 +79,11 @@ export class EditReporter {
|
|
|
76
79
|
kind: "edit",
|
|
77
80
|
locations: edit?.file_path ? [{ path: edit.file_path }] : [],
|
|
78
81
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
// The standard diff, also for a client that negotiated patches: the input
|
|
83
|
+
// holds a snippet, not the file, so a patch would need line numbers that
|
|
84
|
+
// the adapter does not know here. A v2 diff cannot hold a snippet, so a v2
|
|
85
|
+
// client gets the patch from the PostToolUse hook alone.
|
|
86
|
+
if (edit?.file_path && (edit.old_string || edit.new_string) && !capabilities.v2) {
|
|
83
87
|
facts.change = [
|
|
84
88
|
{
|
|
85
89
|
type: "diff",
|
|
@@ -104,12 +108,14 @@ export class EditReporter {
|
|
|
104
108
|
* PostToolUse `tool_response`. For Write it replaces the optimistic creation
|
|
105
109
|
* diff with the real diff of an updated file. A negotiated client gets an
|
|
106
110
|
* exact git patch built from the written file, or the standard diff when none
|
|
107
|
-
* can be built.
|
|
111
|
+
* can be built. A v2 client gets a v2 diff.
|
|
108
112
|
*/
|
|
109
113
|
async function finalChange(toolResponse, { capabilities }) {
|
|
114
|
+
if (capabilities.v2)
|
|
115
|
+
return v2UpdateFromDiffToolResponse(toolResponse);
|
|
110
116
|
if (!capabilities.diffPatch)
|
|
111
117
|
return toolUpdateFromDiffToolResponse(toolResponse);
|
|
112
|
-
const patch = await patchUpdateFromDiffToolResponse(toolResponse);
|
|
118
|
+
const patch = await patchUpdateFromDiffToolResponse(toolResponse, "air");
|
|
113
119
|
if (patch)
|
|
114
120
|
return patch;
|
|
115
121
|
const created = createdFileDiff(toolResponse);
|
package/dist/turn-events.d.ts
CHANGED
|
@@ -13,9 +13,14 @@ export interface TurnEvents {
|
|
|
13
13
|
/**
|
|
14
14
|
* Claude Code took the prompt in as the user message `messageId` of the
|
|
15
15
|
* conversation. Reported at most once per turn, and never after
|
|
16
|
-
* {@link ended} or {@link failed}.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* {@link ended} or {@link failed}.
|
|
17
|
+
*
|
|
18
|
+
* When Claude Code reports command lifecycles (`msg_lifecycle_v1`), that is
|
|
19
|
+
* when the prompt starts a turn, before the turn's output. Otherwise, and
|
|
20
|
+
* while another turn is still active (held for its background work,
|
|
21
|
+
* steered, or cancelled but not yet ended), it is the prompt's echo, after
|
|
22
|
+
* that turn ended; for a command Claude Code does not echo (such as
|
|
23
|
+
* `/compact`), it is the command's result, after any output it streamed.
|
|
19
24
|
*/
|
|
20
25
|
inserted(messageId: string): void;
|
|
21
26
|
/**
|
|
@@ -37,9 +42,10 @@ export interface TurnEvents {
|
|
|
37
42
|
ended(outcome: TurnOutcome): void;
|
|
38
43
|
/**
|
|
39
44
|
* The turn failed. Without {@link inserted} before, Claude Code was not seen
|
|
40
|
-
* taking the prompt in.
|
|
45
|
+
* taking the prompt in. `title`, when the agent has one, describes the
|
|
46
|
+
* failure for the user in plain text, such as "API Error: 529 Overloaded".
|
|
41
47
|
*/
|
|
42
|
-
failed(error: unknown): void;
|
|
48
|
+
failed(error: unknown, title?: string): void;
|
|
43
49
|
}
|
|
44
50
|
/** Why a turn ended. Every ACP version has these reasons. */
|
|
45
51
|
export type StopReason = "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-events.d.ts","sourceRoot":"","sources":["../src/turn-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,UAAU;IACzB
|
|
1
|
+
{"version":3,"file":"turn-events.d.ts","sourceRoot":"","sources":["../src/turn-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC;;;;;OAKG;IACH,YAAY,IAAI,IAAI,CAAC;IACrB;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9C;AAED,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,mBAAmB,GAAG,SAAS,GAAG,WAAW,CAAC;AAEnG,wBAAwB;AACxB,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,EAAE,UAAU,CAAC;IACvB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC"}
|
package/dist/usage-markdown.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { SDKControlGetUsageResponse } from "@anthropic-ai/claude-agent-sdk"
|
|
|
2
2
|
/** Validate the experimental SDK response at the runtime boundary. */
|
|
3
3
|
export declare function parseUsageResponse(value: unknown): SDKControlGetUsageResponse | null;
|
|
4
4
|
export declare function isUsageCommandText(text: string): boolean;
|
|
5
|
+
/** Escape the Markdown syntax characters of `value` and fold its line breaks. */
|
|
6
|
+
export declare function escapeMarkdown(value: string): string;
|
|
5
7
|
/** Render the SDK's structured `/usage` response as Markdown. */
|
|
6
8
|
export declare function formatUsageResponse(usage: SDKControlGetUsageResponse): string;
|
|
7
9
|
//# sourceMappingURL=usage-markdown.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-markdown.d.ts","sourceRoot":"","sources":["../src/usage-markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AA8DjF,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,0BAA0B,GAAG,IAAI,CAMpF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;
|
|
1
|
+
{"version":3,"file":"usage-markdown.d.ts","sourceRoot":"","sources":["../src/usage-markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AA8DjF,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,0BAA0B,GAAG,IAAI,CAMpF;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AASD,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AA+DD,iEAAiE;AACjE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,0BAA0B,GAAG,MAAM,CAiE7E"}
|
package/dist/usage-markdown.js
CHANGED
|
@@ -71,7 +71,8 @@ function usageBar(percent) {
|
|
|
71
71
|
const filled = clamped === 0 ? 0 : Math.max(1, Math.round((clamped / 100) * cells));
|
|
72
72
|
return `${"█".repeat(filled)}${"░".repeat(cells - filled)}`;
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
/** Escape the Markdown syntax characters of `value` and fold its line breaks. */
|
|
75
|
+
export function escapeMarkdown(value) {
|
|
75
76
|
return value.replace(/([\\`*_[\]<>|])/g, "\\$1").replace(/[\r\n]+/g, " ");
|
|
76
77
|
}
|
|
77
78
|
function formatDuration(milliseconds) {
|
package/dist/utils.d.ts
CHANGED
|
@@ -13,4 +13,16 @@ export declare function nodeToWebWritable(nodeStream: Writable): WritableStream<
|
|
|
13
13
|
export declare function nodeToWebReadable(nodeStream: Readable): ReadableStream<Uint8Array>;
|
|
14
14
|
export declare function unreachable(value: never, logger?: Logger): void;
|
|
15
15
|
export declare function sleep(time: number): Promise<void>;
|
|
16
|
+
/** The outcome of {@link raceTimeoutAndAbort}. */
|
|
17
|
+
export type RaceOutcome<T> = {
|
|
18
|
+
type: "done";
|
|
19
|
+
value: T;
|
|
20
|
+
} | {
|
|
21
|
+
type: "timeout";
|
|
22
|
+
} | {
|
|
23
|
+
type: "aborted";
|
|
24
|
+
};
|
|
25
|
+
/** Wait for `promise` until `timeoutMs` passes or `signal` aborts. A rejection
|
|
26
|
+
* of `promise` rejects the result. The timer does not keep the process alive. */
|
|
27
|
+
export declare function raceTimeoutAndAbort<T>(promise: Promise<T>, timeoutMs: number, signal: AbortSignal): Promise<RaceOutcome<T>>;
|
|
16
28
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,qBAAa,QAAQ,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,IAAI,CAAS;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ED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjD;AAED,kDAAkD;AAClD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEpG;kFACkF;AAClF,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAoBzB"}
|
package/dist/utils.js
CHANGED
|
@@ -79,3 +79,31 @@ export function unreachable(value, logger = console) {
|
|
|
79
79
|
export function sleep(time) {
|
|
80
80
|
return new Promise((resolve) => setTimeout(resolve, time));
|
|
81
81
|
}
|
|
82
|
+
/** Wait for `promise` until `timeoutMs` passes or `signal` aborts. A rejection
|
|
83
|
+
* of `promise` rejects the result. The timer does not keep the process alive. */
|
|
84
|
+
export async function raceTimeoutAndAbort(promise, timeoutMs, signal) {
|
|
85
|
+
let timeout;
|
|
86
|
+
let onAbort;
|
|
87
|
+
try {
|
|
88
|
+
return await Promise.race([
|
|
89
|
+
promise.then((value) => ({ type: "done", value })),
|
|
90
|
+
new Promise((resolve) => {
|
|
91
|
+
timeout = setTimeout(() => resolve({ type: "timeout" }), timeoutMs);
|
|
92
|
+
timeout.unref?.();
|
|
93
|
+
}),
|
|
94
|
+
new Promise((resolve) => {
|
|
95
|
+
onAbort = () => resolve({ type: "aborted" });
|
|
96
|
+
if (signal.aborted)
|
|
97
|
+
onAbort();
|
|
98
|
+
else
|
|
99
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
100
|
+
}),
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
if (timeout)
|
|
105
|
+
clearTimeout(timeout);
|
|
106
|
+
if (onAbort)
|
|
107
|
+
signal.removeEventListener("abort", onAbort);
|
|
108
|
+
}
|
|
109
|
+
}
|
package/dist/v2/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/v2/agent.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAkB,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAiB9E;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GACvC,EAAE,CAAC,QAAQ,CA6Cb"}
|
package/dist/v2/agent.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
2
2
|
import { ClaudeAcpAgent } from "../acp-agent.js";
|
|
3
3
|
import { v1InitializeRequest, v2InitializeResponse } from "./initialize.js";
|
|
4
|
-
import {
|
|
4
|
+
import { v1PermissionResponse, v2PermissionRequest } from "./permission.js";
|
|
5
|
+
import { v2Prompt } from "./prompt.js";
|
|
6
|
+
import { v1NewSessionRequest, v1RestoreSessionRequest, v1SetSessionConfigOptionRequest, v2ConfigOptions, v2NewSessionResponse, v2ResumeSessionResponse, } from "./session.js";
|
|
5
7
|
import { v2SessionUpdate } from "./session-update.js";
|
|
8
|
+
import { V2Terminals } from "./terminal.js";
|
|
6
9
|
/**
|
|
7
10
|
* The ACP v2 surface, for one connection.
|
|
8
11
|
*
|
|
@@ -12,10 +15,12 @@ import { v2SessionUpdate } from "./session-update.js";
|
|
|
12
15
|
*/
|
|
13
16
|
export function v2AgentApp(logger, onAgent) {
|
|
14
17
|
let agent;
|
|
18
|
+
let client;
|
|
15
19
|
return v2
|
|
16
20
|
.agent({ name: "claude-code-acp" })
|
|
17
21
|
.onConnect((connection) => {
|
|
18
|
-
|
|
22
|
+
client = new V2ClientConnection(connection.client, logger ?? console);
|
|
23
|
+
agent = new ClaudeAcpAgent(client, logger, { v2: true });
|
|
19
24
|
onAgent(agent);
|
|
20
25
|
})
|
|
21
26
|
.onRequest(v2.methods.agent.initialize, async ({ params }) => v2InitializeResponse(await agent.initialize(v1InitializeRequest(params))))
|
|
@@ -23,25 +28,75 @@ export function v2AgentApp(logger, onAgent) {
|
|
|
23
28
|
.onRequest(v2.methods.agent.auth.logout, ({ params }) => agent.logout(params))
|
|
24
29
|
.onRequest(v2.methods.agent.session.new, async ({ params }) => v2NewSessionResponse(await agent.newSession(v1NewSessionRequest(params))))
|
|
25
30
|
.onRequest(v2.methods.agent.session.list, ({ params }) => agent.listSessions(params))
|
|
26
|
-
.onRequest(v2.methods.agent.session.resume, async ({ params }) =>
|
|
27
|
-
|
|
31
|
+
.onRequest(v2.methods.agent.session.resume, async ({ params }) => {
|
|
32
|
+
const restore = v1RestoreSessionRequest(params);
|
|
33
|
+
return v2ResumeSessionResponse(restore.method === "resume"
|
|
34
|
+
? await agent.resumeSession(restore.request)
|
|
35
|
+
: await client.replaying(params.sessionId, () => agent.loadSession(restore.request)));
|
|
36
|
+
})
|
|
37
|
+
.onRequest(v2.methods.agent.session.close, async ({ params }) => {
|
|
38
|
+
const response = await agent.closeSession(params);
|
|
39
|
+
client.terminals.forget(params.sessionId);
|
|
40
|
+
return response;
|
|
41
|
+
})
|
|
28
42
|
.onRequest(v2.methods.agent.session.delete, ({ params }) => agent.deleteSession(params))
|
|
29
43
|
.onRequest(v2.methods.agent.session.setConfigOption, async ({ params }) => {
|
|
30
44
|
const { configOptions, ...response } = await agent.setSessionConfigOption(v1SetSessionConfigOptionRequest(params));
|
|
31
45
|
return { ...response, configOptions: v2ConfigOptions(configOptions) };
|
|
32
|
-
})
|
|
46
|
+
})
|
|
47
|
+
.onRequest(v2.methods.agent.session.prompt, ({ params }) => v2Prompt(agent, params, (update) => {
|
|
48
|
+
void client.send({ sessionId: params.sessionId, update });
|
|
49
|
+
}))
|
|
50
|
+
.onNotification(v2.methods.agent.session.cancel, ({ params }) => agent.cancel(params));
|
|
33
51
|
}
|
|
34
52
|
/**
|
|
35
53
|
* The {@link AcpClient} of an ACP v2 connection: it sends the v1 messages of
|
|
36
54
|
* the agent as v2 messages.
|
|
37
|
-
*
|
|
38
|
-
* The v2 surface does not serve prompts yet, so permission requests, which
|
|
39
|
-
* only a prompt turn makes, still reject.
|
|
40
55
|
*/
|
|
41
56
|
class V2ClientConnection {
|
|
42
57
|
ctx;
|
|
43
|
-
|
|
58
|
+
logger;
|
|
59
|
+
/**
|
|
60
|
+
* The sessions whose history replays, each with the messages that the
|
|
61
|
+
* replay has cleared so far.
|
|
62
|
+
*/
|
|
63
|
+
replays = new Map();
|
|
64
|
+
/** The display terminals of the commands that the agent runs. */
|
|
65
|
+
terminals = new V2Terminals();
|
|
66
|
+
constructor(ctx, logger) {
|
|
44
67
|
this.ctx = ctx;
|
|
68
|
+
this.logger = logger;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Runs `restore`, which replays the history of `sessionId`.
|
|
72
|
+
*
|
|
73
|
+
* The agent replays messages as chunks. A v2 client may still hold a
|
|
74
|
+
* replayed message, and chunks append, so before the first replayed chunk of
|
|
75
|
+
* each message the client gets the message with no content, which clears it,
|
|
76
|
+
* as v2 requires of a message replayed as chunks.
|
|
77
|
+
*/
|
|
78
|
+
async replaying(sessionId, restore) {
|
|
79
|
+
this.replays.set(sessionId, new Set());
|
|
80
|
+
try {
|
|
81
|
+
return await restore();
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
this.replays.delete(sessionId);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sends a v2 session update, and logs rather than rejects when that fails.
|
|
89
|
+
* It and {@link sessionUpdate} hand updates to the connection synchronously,
|
|
90
|
+
* so they go out in the order of the calls. The agent's consumer awaits each
|
|
91
|
+
* of its updates before it reports the next turn event, so a turn's state
|
|
92
|
+
* follows the output that came before it. (An update the consumer is still
|
|
93
|
+
* routing can be overtaken by an event from elsewhere, such as a permission
|
|
94
|
+
* request opening.)
|
|
95
|
+
*/
|
|
96
|
+
send(notification) {
|
|
97
|
+
return this.ctx.notify(v2.methods.client.session.update, notification).catch((error) => {
|
|
98
|
+
this.logger.error(`Failed to send a ${notification.update.sessionUpdate} update:`, error);
|
|
99
|
+
});
|
|
45
100
|
}
|
|
46
101
|
extNotification(method, params) {
|
|
47
102
|
if (!isExtensionMethod(method)) {
|
|
@@ -50,16 +105,48 @@ class V2ClientConnection {
|
|
|
50
105
|
return this.ctx.notify(method, params);
|
|
51
106
|
}
|
|
52
107
|
async sessionUpdate({ update, ...notification }) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
108
|
+
const updates = this.v2Updates(notification.sessionId, update).flatMap((v2Update) => {
|
|
109
|
+
const clear = this.replayClear(notification.sessionId, v2Update);
|
|
110
|
+
return clear ? [clear, v2Update] : [v2Update];
|
|
111
|
+
});
|
|
112
|
+
// Every update goes to the connection before any is awaited, so an update
|
|
113
|
+
// that another call sends meanwhile cannot come between them.
|
|
114
|
+
await Promise.all(updates.map((v2Update) => this.ctx.notify(v2.methods.client.session.update, { ...notification, update: v2Update })));
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The v2 updates of a v1 update: for a tool call report, the updates of its
|
|
118
|
+
* terminal first, then the report itself (see {@link V2Terminals}).
|
|
119
|
+
*/
|
|
120
|
+
v2Updates(sessionId, update) {
|
|
121
|
+
if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update") {
|
|
122
|
+
const v2Update = v2SessionUpdate(update);
|
|
123
|
+
return v2Update ? [v2Update] : [];
|
|
59
124
|
}
|
|
125
|
+
const { terminal, report } = this.terminals.split(sessionId, update);
|
|
126
|
+
const reportUpdate = report && v2SessionUpdate(report);
|
|
127
|
+
return [...terminal, ...(reportUpdate ? [reportUpdate] : [])];
|
|
60
128
|
}
|
|
61
|
-
|
|
62
|
-
|
|
129
|
+
/**
|
|
130
|
+
* The update that clears the message of a replayed chunk, when it is the
|
|
131
|
+
* first replayed chunk of that message (see {@link replaying}).
|
|
132
|
+
*/
|
|
133
|
+
replayClear(sessionId, update) {
|
|
134
|
+
const cleared = this.replays.get(sessionId);
|
|
135
|
+
if (!cleared)
|
|
136
|
+
return undefined;
|
|
137
|
+
const kind = MESSAGE_OF_CHUNK.get(update.sessionUpdate);
|
|
138
|
+
if (!kind)
|
|
139
|
+
return undefined;
|
|
140
|
+
const { messageId } = update;
|
|
141
|
+
const key = `${kind} ${messageId}`;
|
|
142
|
+
if (cleared.has(key))
|
|
143
|
+
return undefined;
|
|
144
|
+
cleared.add(key);
|
|
145
|
+
return emptyMessage(kind, messageId);
|
|
146
|
+
}
|
|
147
|
+
async requestPermission(params, signal) {
|
|
148
|
+
const response = await this.ctx.request(v2.methods.client.session.requestPermission, v2PermissionRequest(params), { cancellationSignal: signal });
|
|
149
|
+
return v1PermissionResponse(response);
|
|
63
150
|
}
|
|
64
151
|
// Elicitation is the same in v1 and v2.
|
|
65
152
|
createElicitation(params, signal) {
|
|
@@ -81,6 +168,23 @@ class V2ClientConnection {
|
|
|
81
168
|
return Promise.reject(new Error("ACP v2 has no client file system"));
|
|
82
169
|
}
|
|
83
170
|
}
|
|
171
|
+
/** The message update of each message chunk. */
|
|
172
|
+
const MESSAGE_OF_CHUNK = new Map([
|
|
173
|
+
["user_message_chunk", "user_message"],
|
|
174
|
+
["agent_message_chunk", "agent_message"],
|
|
175
|
+
["agent_thought_chunk", "agent_thought"],
|
|
176
|
+
]);
|
|
177
|
+
function emptyMessage(kind, messageId) {
|
|
178
|
+
const message = { messageId, content: [] };
|
|
179
|
+
switch (kind) {
|
|
180
|
+
case "user_message":
|
|
181
|
+
return { ...message, sessionUpdate: kind };
|
|
182
|
+
case "agent_message":
|
|
183
|
+
return { ...message, sessionUpdate: kind };
|
|
184
|
+
default:
|
|
185
|
+
return { ...message, sessionUpdate: kind };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
84
188
|
function isExtensionMethod(method) {
|
|
85
189
|
return method.startsWith("_");
|
|
86
190
|
}
|
package/dist/v2/initialize.d.ts
CHANGED
|
@@ -14,11 +14,8 @@ export declare function v1InitializeRequest(request: v2.InitializeRequest): Init
|
|
|
14
14
|
/**
|
|
15
15
|
* The v2 `initialize` response for the v1 response of the agent.
|
|
16
16
|
*
|
|
17
|
-
* It
|
|
18
|
-
*
|
|
19
|
-
* `resume`, `close`, `prompt`, `cancel`, and `update`), and the v2 surface of
|
|
20
|
-
* the adapter does not serve it yet. Nor does it advertise the unstable
|
|
21
|
-
* `providers` methods, which the v2 surface does not serve yet either.
|
|
17
|
+
* It does not advertise the unstable `providers` methods, which the v2
|
|
18
|
+
* surface does not serve yet.
|
|
22
19
|
*/
|
|
23
20
|
export declare function v2InitializeResponse(response: InitializeResponse): v2.InitializeResponse;
|
|
24
21
|
//# sourceMappingURL=initialize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../src/v2/initialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAE/D,0DAA0D;AAC1D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,GAAG,iBAAiB,CAwBpF;AAED
|
|
1
|
+
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../src/v2/initialize.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAE/D,0DAA0D;AAC1D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC,iBAAiB,GAAG,iBAAiB,CAwBpF;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,EAAE,CAAC,kBAAkB,CAiBxF"}
|