claude-code-acp-ts 0.38.2 → 0.52.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/acp-agent.d.ts +243 -30
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +1436 -268
- package/dist/elicitation.d.ts +82 -0
- package/dist/elicitation.d.ts.map +1 -0
- package/dist/elicitation.js +211 -0
- package/dist/index.js +7 -4
- package/dist/settings.js +9 -6
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +34 -7
- package/dist/utils.js +3 -5
- package/package.json +18 -14
package/dist/acp-agent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CanUseTool, ModelInfo, Options, PermissionMode, PermissionUpdate, Query, SDKMessageOrigin, SDKPartialAssistantMessage, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
1
|
+
import { AuthenticateRequest, CancelNotification, ClientCapabilities, CompleteElicitationNotification, CreateElicitationRequest, CreateElicitationResponse, ForkSessionRequest, ForkSessionResponse, InitializeRequest, InitializeResponse, ListSessionsRequest, ListSessionsResponse, LoadSessionRequest, LoadSessionResponse, LogoutRequest, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, ReadTextFileRequest, ReadTextFileResponse, RequestPermissionRequest, RequestPermissionResponse, ResumeSessionRequest, ResumeSessionResponse, SessionConfigOption, SessionModeState, SessionNotification, SetSessionConfigOptionRequest, SetSessionConfigOptionResponse, SetSessionModeRequest, SetSessionModeResponse, CloseSessionRequest, CloseSessionResponse, DeleteSessionRequest, DeleteSessionResponse, WriteTextFileRequest, WriteTextFileResponse } from "@agentclientprotocol/sdk";
|
|
2
|
+
import { AgentInfo, CanUseTool, ModelInfo, Options, PermissionMode, PermissionUpdate, Query, SDKMessageOrigin, SDKPartialAssistantMessage, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
3
3
|
import { ContentBlockParam } from "@anthropic-ai/sdk/resources";
|
|
4
4
|
import { BetaContentBlock, BetaRawContentBlockDelta } from "@anthropic-ai/sdk/resources/beta.mjs";
|
|
5
5
|
import { SettingsManager } from "./settings.js";
|
|
@@ -19,10 +19,66 @@ type AccumulatedUsage = {
|
|
|
19
19
|
cachedReadTokens: number;
|
|
20
20
|
cachedWriteTokens: number;
|
|
21
21
|
};
|
|
22
|
+
/** Internal model-selection state. Mirrors the shape the ACP SDK exposed as
|
|
23
|
+
* `SessionModelState` before model selection moved entirely into
|
|
24
|
+
* `SessionConfigOption` (category "model"). Retained internally to track the
|
|
25
|
+
* current model and build the "model" config option. */
|
|
26
|
+
type SessionModelState = {
|
|
27
|
+
availableModels: Array<{
|
|
28
|
+
modelId: string;
|
|
29
|
+
name: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
}>;
|
|
32
|
+
currentModelId: string;
|
|
33
|
+
};
|
|
34
|
+
/** One in-flight `prompt()` call. A persistent per-session consumer (see
|
|
35
|
+
* `runConsumer`) drains the SDK query stream for the whole session and settles
|
|
36
|
+
* each Turn's deferred when that turn's outcome is known, so `prompt()` itself
|
|
37
|
+
* holds no loop. Turns are processed FIFO: the SDK echoes queued user messages
|
|
38
|
+
* back in submission order, so `turnQueue[0]` is the turn currently running. */
|
|
39
|
+
type Turn = {
|
|
40
|
+
/** uuid stamped on the pushed `SDKUserMessage`; the SDK echoes it back so the
|
|
41
|
+
* consumer can match the replayed user message to this turn. */
|
|
42
|
+
promptUuid: string;
|
|
43
|
+
/** Local-only slash commands (e.g. `/clear`) return a result without an echo,
|
|
44
|
+
* so the consumer can't promote them via the replay; it falls back to
|
|
45
|
+
* promoting the queue head when the result arrives. */
|
|
46
|
+
isLocalOnlyCommand: boolean;
|
|
47
|
+
/** Set once the deferred has been resolved/rejected, so the consumer never
|
|
48
|
+
* settles a turn twice (idle + handoff + stream-end can all race). */
|
|
49
|
+
settled: boolean;
|
|
50
|
+
resolve: (response: PromptResponse) => void;
|
|
51
|
+
reject: (error: unknown) => void;
|
|
52
|
+
};
|
|
22
53
|
type Session = {
|
|
23
54
|
query: Query;
|
|
24
55
|
input: Pushable<SDKUserMessage>;
|
|
25
56
|
cancelled: boolean;
|
|
57
|
+
/** FIFO of in-flight prompts. The head is the turn the SDK is currently
|
|
58
|
+
* processing; later entries are queued and will be echoed in order. */
|
|
59
|
+
turnQueue?: Turn[];
|
|
60
|
+
/** The turn whose messages the consumer is currently attributing output to
|
|
61
|
+
* (the head of `turnQueue` once its user message has been echoed). */
|
|
62
|
+
activeTurn?: Turn | null;
|
|
63
|
+
/** Count of result messages the consumer should treat as orphans and skip
|
|
64
|
+
* (not promote/attribute to the current head). When cancel() settles+removes
|
|
65
|
+
* a queued turn, that turn's user message was already pushed to the SDK, so
|
|
66
|
+
* the SDK still runs it and emits a result with no uuid we can match. Because
|
|
67
|
+
* the SDK processes input FIFO, those orphan results arrive (in submission
|
|
68
|
+
* order) before the next live turn's, so skipping exactly this many leaves
|
|
69
|
+
* the genuine head untouched. Reset to 0 on every activation as a backstop
|
|
70
|
+
* against an SDK that drops queued input on interrupt (no orphan emitted). */
|
|
71
|
+
pendingOrphanResults?: number;
|
|
72
|
+
/** The long-lived consumer task. Lazily started on the first `prompt()` and
|
|
73
|
+
* kept alive for the session so between-turn/background messages are still
|
|
74
|
+
* drained and forwarded. */
|
|
75
|
+
consumer?: Promise<void>;
|
|
76
|
+
/** Set once the SDK query stream has terminated (it ran to `done` or threw a
|
|
77
|
+
* non-process error). The query iterator is not reusable afterward, so a
|
|
78
|
+
* later `prompt()` rejects instead of enqueueing onto a dead stream and
|
|
79
|
+
* hanging (or silently restarting a consumer that resolves `end_turn`
|
|
80
|
+
* without ever reaching the model). */
|
|
81
|
+
queryClosed?: boolean;
|
|
26
82
|
cwd: string;
|
|
27
83
|
/** Serialized snapshot of session-defining params (cwd, mcpServers) used to
|
|
28
84
|
* detect when loadSession/resumeSession is called with changed values. */
|
|
@@ -33,13 +89,26 @@ type Session = {
|
|
|
33
89
|
models: SessionModelState;
|
|
34
90
|
modelInfos: ModelInfo[];
|
|
35
91
|
configOptions: SessionConfigOption[];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
92
|
+
/** Custom main-thread agent personas the user (or a plugin/project) has
|
|
93
|
+
* configured, discovered via `supportedAgents()` with Claude Code's built-in
|
|
94
|
+
* subagents filtered out. Empty when none are configured, in which case the
|
|
95
|
+
* "agent" config option is omitted entirely. */
|
|
96
|
+
agents: AgentInfo[];
|
|
97
|
+
/** The currently selected main-thread agent name, or "default" for the
|
|
98
|
+
* standard Claude Code agent (no `agent` flag applied). */
|
|
99
|
+
currentAgent: string;
|
|
42
100
|
abortController: AbortController;
|
|
101
|
+
/** Signal the consumer races `query.next()` against. Aborted by cancel()
|
|
102
|
+
* (after a grace period) to force the active turn to settle "cancelled" when
|
|
103
|
+
* the SDK is wedged and `query.next()` never yields again (issue #680).
|
|
104
|
+
* Distinct from `abortController`: this only wakes the consumer; it does NOT
|
|
105
|
+
* touch the SDK query/subprocess. The consumer re-arms it after each fire.
|
|
106
|
+
* Undefined until the consumer is started by the first prompt. */
|
|
107
|
+
cancelController?: AbortController;
|
|
108
|
+
/** Pending grace-period timer that aborts `cancelController`. Cleared when the
|
|
109
|
+
* active turn settles normally so the backstop never fires after a clean
|
|
110
|
+
* cancel. */
|
|
111
|
+
forceCancelTimer?: ReturnType<typeof setTimeout>;
|
|
43
112
|
emitRawSDKMessages: boolean | SDKMessageFilter[];
|
|
44
113
|
/** Context window size of the last top-level assistant model, carried across
|
|
45
114
|
* prompts so mid-stream usage_update notifications report a correct `size`
|
|
@@ -50,14 +119,36 @@ type Session = {
|
|
|
50
119
|
/** Accumulated task list for the session, keyed by task ID. Task IDs are
|
|
51
120
|
* per-session, so this state must not be shared across sessions. */
|
|
52
121
|
taskState: TaskState;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
122
|
+
/** Last session title we pushed to the client via `session_info_update`.
|
|
123
|
+
* The SDK auto-generates a title in a background task and persists it to the
|
|
124
|
+
* session file; we poll it on each turn-end (`session_state_changed: idle`)
|
|
125
|
+
* and only notify the client when it actually changes. Undefined until the
|
|
126
|
+
* first title is observed. */
|
|
127
|
+
lastTitle?: string;
|
|
128
|
+
/** Caches `tool_use` blocks by id so the matching `tool_result` can recover
|
|
129
|
+
* the tool name/input when mapping it to a `tool_call_update`. Per-session
|
|
130
|
+
* (tool_use ids are only unique within a session) and pruned at
|
|
131
|
+
* `tool_result` time so a long-running session doesn't accumulate every
|
|
132
|
+
* tool call for its whole lifetime. */
|
|
133
|
+
toolUseCache: ToolUseCache;
|
|
134
|
+
/** Maps the ACP `messageId` we expose to clients (see `messageIdForGrouping`)
|
|
135
|
+
* to the SDK message uuid that the Agent SDK's rewind/resume APIs key on
|
|
136
|
+
* (`Query.rewindFiles` takes a user-message uuid; `resumeSessionAt` takes an
|
|
137
|
+
* `SDKAssistantMessage.uuid`). For assistant turns the two differ — the ACP
|
|
138
|
+
* id is the Anthropic API message id (`msg_…`), available at `message_start`
|
|
139
|
+
* so streamed chunks can carry it, while the uuid only arrives on the
|
|
140
|
+
* consolidated message — so a client can only ask to rewind/fork by the id it
|
|
141
|
+
* was given, and we need this table to translate it back.
|
|
142
|
+
*
|
|
143
|
+
* Populated as a byproduct of the message loop (the consolidated message
|
|
144
|
+
* carries both ids) and of `replaySessionHistory` on load, so no extra
|
|
145
|
+
* `getSessionMessages` read is needed at rewind time. Last-write-wins
|
|
146
|
+
* naturally yields the turn-boundary uuid when one `msg_…` spans several
|
|
147
|
+
* content-block messages.
|
|
148
|
+
*
|
|
149
|
+
* NOT READ YET — recorded now so the mapping exists if/when we wire up
|
|
150
|
+
* fork/rewind. */
|
|
151
|
+
messageIdToUuid: Map<string, string>;
|
|
61
152
|
};
|
|
62
153
|
export type SDKMessageFilter = {
|
|
63
154
|
type: string;
|
|
@@ -160,68 +251,190 @@ export declare function resolvePermissionMode(defaultMode?: unknown, logger?: Lo
|
|
|
160
251
|
* tool so "Always Allow" is never a blank check without disclosure.
|
|
161
252
|
*/
|
|
162
253
|
export declare function describeAlwaysAllow(suggestions: PermissionUpdate[] | undefined, toolName: string): string;
|
|
163
|
-
|
|
254
|
+
/**
|
|
255
|
+
* Client-facing surface the agent calls back into. This is the subset of ACP
|
|
256
|
+
* client methods the agent actually uses, expressed as a narrow interface so
|
|
257
|
+
* tests can supply lightweight mocks. In production it is backed by
|
|
258
|
+
* {@link ClientConnection} over the SDK's typed `AgentContext`.
|
|
259
|
+
*/
|
|
260
|
+
export interface AcpClient {
|
|
261
|
+
sessionUpdate(params: SessionNotification): Promise<void>;
|
|
262
|
+
/** `signal`, when aborted, sends `$/cancel_request` for the in-flight
|
|
263
|
+
* permission request so the client can dismiss its prompt (and settle our
|
|
264
|
+
* await) instead of leaving the dialog open after the turn was cancelled. */
|
|
265
|
+
requestPermission(params: RequestPermissionRequest, signal?: AbortSignal): Promise<RequestPermissionResponse>;
|
|
266
|
+
readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
|
|
267
|
+
writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
|
|
268
|
+
/** `signal`, when aborted, sends `$/cancel_request` for the in-flight
|
|
269
|
+
* elicitation so the client can dismiss its prompt and settle our await. */
|
|
270
|
+
unstable_createElicitation(params: CreateElicitationRequest, signal?: AbortSignal): Promise<CreateElicitationResponse>;
|
|
271
|
+
unstable_completeElicitation(params: CompleteElicitationNotification): Promise<void>;
|
|
272
|
+
/** Send a custom (extension) notification, e.g. `_claude/sdkMessage`. */
|
|
273
|
+
extNotification(method: string, params: Record<string, unknown>): Promise<void>;
|
|
274
|
+
}
|
|
275
|
+
export declare class ClaudeAcpAgent {
|
|
164
276
|
sessions: {
|
|
165
277
|
[key: string]: Session;
|
|
166
278
|
};
|
|
167
|
-
client:
|
|
168
|
-
toolUseCache: ToolUseCache;
|
|
169
|
-
backgroundTerminals: {
|
|
170
|
-
[key: string]: BackgroundTerminal;
|
|
171
|
-
};
|
|
279
|
+
client: AcpClient;
|
|
172
280
|
clientCapabilities?: ClientCapabilities;
|
|
173
281
|
logger: Logger;
|
|
174
282
|
gatewayAuthRequest?: GatewayAuthRequest;
|
|
175
|
-
|
|
283
|
+
/** Grace period before a `session/cancel` forces a wedged prompt loop to
|
|
284
|
+
* return "cancelled". See {@link DEFAULT_FORCE_CANCEL_GRACE_MS}. Mutable so
|
|
285
|
+
* tests can shrink it. */
|
|
286
|
+
forceCancelGraceMs: number;
|
|
287
|
+
constructor(client: AcpClient, logger?: Logger);
|
|
176
288
|
initialize(request: InitializeRequest): Promise<InitializeResponse>;
|
|
177
289
|
newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
|
|
178
290
|
unstable_forkSession(params: ForkSessionRequest): Promise<ForkSessionResponse>;
|
|
179
291
|
resumeSession(params: ResumeSessionRequest): Promise<ResumeSessionResponse>;
|
|
180
292
|
loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse>;
|
|
181
293
|
listSessions(params: ListSessionsRequest): Promise<ListSessionsResponse>;
|
|
294
|
+
/** Read the SDK-maintained title for a session and, if it changed since the
|
|
295
|
+
* last time we looked, notify the client with a `session_info_update`. The
|
|
296
|
+
* SDK has no push event for the title it auto-generates in the background, so
|
|
297
|
+
* we pull it at turn-end. A missing session file or read error is non-fatal:
|
|
298
|
+
* the title is best-effort and another turn will retry. */
|
|
299
|
+
private maybeUpdateSessionTitle;
|
|
182
300
|
authenticate(_params: AuthenticateRequest): Promise<void>;
|
|
301
|
+
logout(_params: LogoutRequest): Promise<void>;
|
|
183
302
|
prompt(params: PromptRequest): Promise<PromptResponse>;
|
|
303
|
+
/** Lazily start the per-session consumer that drains the SDK query stream for
|
|
304
|
+
* the session's whole life. Idempotent: only the first `prompt()` starts it. */
|
|
305
|
+
private ensureConsumer;
|
|
306
|
+
/** The single, long-lived consumer of the SDK query stream for a session. It
|
|
307
|
+
* forwards every message as ACP `sessionUpdate`s (so background/between-turn
|
|
308
|
+
* output streams live, not just while a prompt is awaiting) and settles each
|
|
309
|
+
* Turn's deferred when that turn ends. Replaces the per-prompt message loop;
|
|
310
|
+
* `params` only carries the (session-invariant) `sessionId`. */
|
|
311
|
+
private runConsumer;
|
|
184
312
|
cancel(params: CancelNotification): Promise<void>;
|
|
185
|
-
/**
|
|
186
|
-
*
|
|
313
|
+
/** Mark a session's SDK query stream as permanently ended and release the
|
|
314
|
+
* resources tied to it: drop the consumer handle, dispose the settings
|
|
315
|
+
* watchers, end the input stream, and close the query (which terminates the
|
|
316
|
+
* subprocess). The query iterator is not revivable, so `prompt()`/`cancel()`
|
|
317
|
+
* consult `queryClosed` and fail/short-circuit instead of acting on a dead
|
|
318
|
+
* stream. Idempotent (guarded by `queryClosed`), so the consumer's done/error
|
|
319
|
+
* paths and a later `teardownSession` can all call it without double-releasing.
|
|
320
|
+
*
|
|
321
|
+
* Deliberately does NOT abort `session.abortController`: that controller may be
|
|
322
|
+
* CLIENT-supplied (`_meta.claudeCode.options.abortController`) and reused, so
|
|
323
|
+
* aborting it on a spontaneous stream end would cancel the client's own work
|
|
324
|
+
* or make a sibling session born aborted. `query.close()` already terminates
|
|
325
|
+
* the subprocess; aborting the signal belongs in `teardownSession` (explicit
|
|
326
|
+
* destroy), not here. Also does NOT remove the session from the map — that is
|
|
327
|
+
* `teardownSession`'s job — so prompt() can still answer with a clear "session
|
|
328
|
+
* ended" error after an unexpected stream close. The leftover session object
|
|
329
|
+
* is a lightweight husk (its heavy resources are released here) and is evicted
|
|
330
|
+
* on the next closeSession/deleteSession or when the connection's `dispose()`
|
|
331
|
+
* runs. */
|
|
332
|
+
private closeQueryStream;
|
|
333
|
+
/** Cleanly tear down a session: cancel in-flight work, release stream
|
|
334
|
+
* resources, and remove it from the session map. */
|
|
187
335
|
private teardownSession;
|
|
188
336
|
/** Tear down all active sessions. Called when the ACP connection closes. */
|
|
189
337
|
dispose(): Promise<void>;
|
|
190
338
|
closeSession(params: CloseSessionRequest): Promise<CloseSessionResponse>;
|
|
191
|
-
|
|
192
|
-
unstable_setSessionModel(params: SetSessionModelRequest): Promise<SetSessionModelResponse | void>;
|
|
339
|
+
deleteSession(params: DeleteSessionRequest): Promise<DeleteSessionResponse>;
|
|
193
340
|
setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
|
|
194
341
|
setSessionConfigOption(params: SetSessionConfigOptionRequest): Promise<SetSessionConfigOptionResponse>;
|
|
195
342
|
private applySessionMode;
|
|
196
343
|
private replaySessionHistory;
|
|
197
344
|
readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
|
|
198
345
|
writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
|
|
346
|
+
/** Forward a permission request to the client, wiring the tool call's
|
|
347
|
+
* `signal` through as a `cancellationSignal`. When the turn is cancelled
|
|
348
|
+
* while the client's prompt is still open the signal aborts, the SDK sends
|
|
349
|
+
* `$/cancel_request`, and the client settles the request (a `cancelled`
|
|
350
|
+
* outcome or a `requestCancelled` rejection). Either way we surface the same
|
|
351
|
+
* "Tool use aborted" the callers already expect, so a cancelled dialog no
|
|
352
|
+
* longer leaves the `await` hanging. */
|
|
353
|
+
private requestPermissionFromClient;
|
|
199
354
|
canUseTool(sessionId: string): CanUseTool;
|
|
355
|
+
/**
|
|
356
|
+
* Handle elicitation requests that originate from MCP servers by forwarding
|
|
357
|
+
* them to the client over ACP. Modes the client did not advertise (or
|
|
358
|
+
* requests we can't represent) are declined.
|
|
359
|
+
*/
|
|
360
|
+
private handleMcpElicitation;
|
|
361
|
+
/**
|
|
362
|
+
* Present the built-in AskUserQuestion tool's questions as an ACP form
|
|
363
|
+
* elicitation and return the answers as the tool's `updatedInput`. Called from
|
|
364
|
+
* `canUseTool` since that is where the SDK routes the tool's permission check.
|
|
365
|
+
*/
|
|
366
|
+
private handleAskUserQuestion;
|
|
200
367
|
private sendAvailableCommandsUpdate;
|
|
201
368
|
private updateConfigOption;
|
|
202
369
|
private applyConfigOptionValue;
|
|
203
370
|
private getOrCreateSession;
|
|
371
|
+
/**
|
|
372
|
+
* Ensures the requested `cwd` is an absolute path that points at an existing
|
|
373
|
+
* directory before we create a session. Throws an `invalidParams` error with
|
|
374
|
+
* an actionable message so clients (e.g. Zed) can surface it to the user
|
|
375
|
+
* instead of failing later with an opaque SDK error.
|
|
376
|
+
*/
|
|
377
|
+
private validateCwd;
|
|
204
378
|
private createSession;
|
|
205
379
|
}
|
|
380
|
+
export declare const BUILTIN_AGENT_NAMES: Set<string>;
|
|
381
|
+
export declare const DEFAULT_AGENT_ID = "default";
|
|
382
|
+
/** Discover user/plugin/project-configured main-thread agents, excluding the
|
|
383
|
+
* built-in subagents and the reserved "default" sentinel. Returns an empty
|
|
384
|
+
* list if discovery fails so a flaky control request never blocks session
|
|
385
|
+
* creation. */
|
|
386
|
+
export declare function discoverCustomAgents(q: Query): Promise<AgentInfo[]>;
|
|
387
|
+
export declare function buildConfigOptions(modes: SessionModeState, models: SessionModelState, modelInfos: ModelInfo[], currentEffortLevel?: string, agents?: AgentInfo[], currentAgent?: string): SessionConfigOption[];
|
|
206
388
|
export declare function promptToClaude(prompt: PromptRequest): SDKUserMessage;
|
|
389
|
+
/**
|
|
390
|
+
* Resolves the ACP `messageId` for a Claude SDK message (live) or a persisted
|
|
391
|
+
* transcript message (replay) so chunk grouping is identical in both views.
|
|
392
|
+
*
|
|
393
|
+
* Assistant turns are keyed by the Anthropic API message id (`message.id`),
|
|
394
|
+
* which is identical at `message_start`, on the consolidated assistant message,
|
|
395
|
+
* and in the persisted transcript — unlike the per-`stream_event` uuid, which is
|
|
396
|
+
* unique per event and never persisted. User messages have no API id, but they
|
|
397
|
+
* are never streamed, so their (stable) SDK uuid is used instead. ACP message
|
|
398
|
+
* ids are opaque strings, so no particular format is required.
|
|
399
|
+
*/
|
|
400
|
+
export declare function messageIdForGrouping(message: {
|
|
401
|
+
type?: string;
|
|
402
|
+
uuid?: string | null;
|
|
403
|
+
message?: unknown;
|
|
404
|
+
}): string | undefined;
|
|
207
405
|
/**
|
|
208
406
|
* Convert an SDKAssistantMessage (Claude) to a SessionNotification (ACP).
|
|
209
407
|
* Only handles text, image, and thinking chunks for now.
|
|
210
408
|
*/
|
|
211
|
-
export declare function toAcpNotifications(content: string | ContentBlockParam[] | BetaContentBlock[] | BetaRawContentBlockDelta[], role: "assistant" | "user", sessionId: string, toolUseCache: ToolUseCache, client:
|
|
409
|
+
export declare function toAcpNotifications(content: string | ContentBlockParam[] | BetaContentBlock[] | BetaRawContentBlockDelta[], role: "assistant" | "user", sessionId: string, toolUseCache: ToolUseCache, client: AcpClient, logger: Logger, options?: {
|
|
212
410
|
registerHooks?: boolean;
|
|
213
411
|
clientCapabilities?: ClientCapabilities;
|
|
214
412
|
parentToolUseId?: string | null;
|
|
215
413
|
cwd?: string;
|
|
216
414
|
taskState?: TaskState;
|
|
415
|
+
messageId?: string;
|
|
217
416
|
}): SessionNotification[];
|
|
218
|
-
export declare function streamEventToAcpNotifications(message: SDKPartialAssistantMessage, sessionId: string, toolUseCache: ToolUseCache, client:
|
|
417
|
+
export declare function streamEventToAcpNotifications(message: SDKPartialAssistantMessage, sessionId: string, toolUseCache: ToolUseCache, client: AcpClient, logger: Logger, options?: {
|
|
219
418
|
clientCapabilities?: ClientCapabilities;
|
|
220
419
|
cwd?: string;
|
|
221
420
|
taskState?: TaskState;
|
|
421
|
+
messageId?: string;
|
|
222
422
|
}): SessionNotification[];
|
|
423
|
+
/** Run a `session/prompt` while honoring `$/cancel_request` for it. ACP clients
|
|
424
|
+
* normally stop a turn with the `session/cancel` notification, but `signal`
|
|
425
|
+
* (the prompt request's abort signal) also fires when the client sends the
|
|
426
|
+
* generic `$/cancel_request` for this prompt — the protocol's complementary
|
|
427
|
+
* cancellation fallback. Route that to the same `agent.cancel` path so a client
|
|
428
|
+
* using only the generic mechanism still stops the turn (and the prompt
|
|
429
|
+
* resolves "cancelled" instead of running to completion).
|
|
430
|
+
*
|
|
431
|
+
* The listener is scoped to this call: once the prompt settles it is removed,
|
|
432
|
+
* so a later teardown-time abort of the (per-request) signal can't cancel a
|
|
433
|
+
* subsequent turn. `signal` also aborts on connection close, in which case
|
|
434
|
+
* cancelling the in-flight turn is the desired behavior anyway. */
|
|
435
|
+
export declare function runPromptWithCancellation(agent: Pick<ClaudeAcpAgent, "prompt" | "cancel" | "logger">, params: PromptRequest, signal: AbortSignal): Promise<PromptResponse>;
|
|
223
436
|
export declare function runAcp(): {
|
|
224
|
-
connection:
|
|
437
|
+
connection: import("@agentclientprotocol/sdk").AgentConnection;
|
|
225
438
|
agent: ClaudeAcpAgent;
|
|
226
439
|
};
|
|
227
440
|
export {};
|
package/dist/acp-agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acp-agent.d.ts","sourceRoot":"","sources":["../src/acp-agent.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"acp-agent.d.ts","sourceRoot":"","sources":["../src/acp-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EAGnB,kBAAkB,EAClB,kBAAkB,EAClB,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EAGb,iBAAiB,EACjB,kBAAkB,EAElB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EAEpB,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,6BAA6B,EAC7B,8BAA8B,EAC9B,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,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