@agentclientprotocol/claude-agent-acp 0.113.1-preview.1 → 0.113.1-preview.11
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 +5 -3
- package/dist/async-tasks.d.ts +27 -0
- package/dist/async-tasks.d.ts.map +1 -1
- package/dist/async-tasks.js +36 -0
- package/dist/claude-cli.d.ts +22 -16
- package/dist/claude-cli.d.ts.map +1 -1
- package/dist/claude-cli.js +40 -18
- package/dist/mcp-oauth.d.ts +3 -2
- package/dist/mcp-oauth.d.ts.map +1 -1
- package/dist/mcp-oauth.js +65 -27
- package/dist/query-settings.d.ts +42 -0
- package/dist/query-settings.d.ts.map +1 -0
- package/dist/query-settings.js +43 -0
- package/dist/resumed-session.d.ts +9 -2
- package/dist/resumed-session.d.ts.map +1 -1
- package/dist/resumed-session.js +51 -7
- package/dist/sdk-to-acp.js +4 -2
- package/dist/session-cursors.d.ts +1 -1
- package/dist/session-cursors.d.ts.map +1 -1
- package/dist/session-cursors.js +8 -2
- package/dist/session-index/service.d.ts.map +1 -1
- package/dist/session-index/service.js +9 -17
- package/dist/session-index/session-index.d.ts +1 -13
- package/dist/session-index/session-index.d.ts.map +1 -1
- package/dist/session-index/session-index.js +3 -29
- package/dist/session-index/transcript-scan.d.ts +17 -4
- package/dist/session-index/transcript-scan.d.ts.map +1 -1
- package/dist/session-index/transcript-scan.js +44 -3
- package/dist/session-mode.d.ts +69 -3
- package/dist/session-mode.d.ts.map +1 -1
- package/dist/session-mode.js +103 -15
- package/dist/session-model.d.ts +4 -1
- package/dist/session-model.d.ts.map +1 -1
- package/dist/session-model.js +26 -4
- package/dist/session-read.d.ts +45 -0
- package/dist/session-read.d.ts.map +1 -0
- package/dist/session-read.js +300 -0
- package/dist/session-rewind.d.ts +6 -2
- package/dist/session-rewind.d.ts.map +1 -1
- package/dist/session-rewind.js +13 -4
- package/dist/session-ultracode.d.ts +17 -5
- package/dist/session-ultracode.d.ts.map +1 -1
- package/dist/session-ultracode.js +16 -15
- package/dist/settings.d.ts +34 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +55 -4
- package/dist/startup-failure.d.ts +11 -1
- package/dist/startup-failure.d.ts.map +1 -1
- package/dist/startup-failure.js +33 -1
- package/dist/subagent-history.d.ts +9 -1
- package/dist/subagent-history.d.ts.map +1 -1
- package/dist/subagent-history.js +55 -13
- package/dist/v1/acp-agent.d.ts +8 -1
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +189 -94
- package/dist/v1/async-task-stop.d.ts +31 -0
- package/dist/v1/async-task-stop.d.ts.map +1 -1
- package/dist/v1/async-task-stop.js +41 -0
- package/dist/v1/session-read.d.ts +31 -0
- package/dist/v1/session-read.d.ts.map +1 -0
- package/dist/v1/session-read.js +62 -0
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +72 -29
- package/dist/v2/commands.d.ts +8 -3
- package/dist/v2/commands.d.ts.map +1 -1
- package/dist/v2/commands.js +4 -3
- package/dist/v2/config.d.ts +9 -8
- package/dist/v2/config.d.ts.map +1 -1
- package/dist/v2/config.js +15 -10
- package/dist/v2/session-read.d.ts +11 -0
- package/dist/v2/session-read.d.ts.map +1 -0
- package/dist/v2/session-read.js +28 -0
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +19 -2
- package/dist/v2/setup.d.ts +4 -1
- package/dist/v2/setup.d.ts.map +1 -1
- package/dist/v2/setup.js +4 -2
- package/dist/v2/stream.d.ts +9 -13
- package/dist/v2/stream.d.ts.map +1 -1
- package/dist/v2/stream.js +10 -9
- package/dist/v2/subagent-replay.d.ts +16 -4
- package/dist/v2/subagent-replay.d.ts.map +1 -1
- package/dist/v2/subagent-replay.js +22 -10
- package/dist/v2/tasks.d.ts.map +1 -1
- package/dist/v2/tasks.js +5 -3
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -48,9 +48,9 @@ Claude CLI (`claude`) it runs. Keep them in the same directory; a symlink to
|
|
|
48
48
|
instead, set `CLAUDE_CODE_EXECUTABLE`. On Alpine, install `libgcc` and
|
|
49
49
|
`libstdc++` first.
|
|
50
50
|
|
|
51
|
-
A CLI named with `CLAUDE_CODE_EXECUTABLE`
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
A CLI named with `CLAUDE_CODE_EXECUTABLE` must be Claude Code 2.1.328 or newer:
|
|
52
|
+
the adapter sends a session's MCP servers and settings to Claude Code over
|
|
53
|
+
stdin. With an older one, a session that has either does not start.
|
|
54
54
|
|
|
55
55
|
To build one for your machine (needs [Bun](https://bun.sh)) and check it:
|
|
56
56
|
|
|
@@ -85,6 +85,8 @@ is inserted once, and the retry gets the first `messageId`. The key is known for
|
|
|
85
85
|
Code stores the message, also after a restart. A prompt that Claude Code does not store, such as a
|
|
86
86
|
local command, keeps its key until `session/close` or the end of the connection.
|
|
87
87
|
|
|
88
|
+
A client can [read and follow a stored session](docs/session-read.md) through `_session/read` while a terminal continues writing it.
|
|
89
|
+
|
|
88
90
|
The adapter announces a session cursor (`cursor_update`) before each user message that follows
|
|
89
91
|
another entry of the conversation, live and in a replay. `session/fork` with its `cursorId` copies
|
|
90
92
|
the history before that message, and fails with `-32602` for any other `cursorId`. A v1 client gets
|
package/dist/async-tasks.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SDKMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
1
2
|
import type { ClientCapabilities } from "@agentclientprotocol/sdk/unstable";
|
|
2
3
|
import type { AcpSessionNotification, AsyncTaskState } from "./acp-subagents.js";
|
|
3
4
|
type Publish = (notification: AcpSessionNotification) => Promise<void>;
|
|
@@ -102,6 +103,12 @@ export declare class AsyncTaskRuntime {
|
|
|
102
103
|
private readonly outputPathsByToolCall;
|
|
103
104
|
/** The task of the autonomous turn that runs now. */
|
|
104
105
|
private autonomousTurn?;
|
|
106
|
+
/**
|
|
107
|
+
* Whether a stop interrupted the autonomous turn and its aborted result has
|
|
108
|
+
* not come yet. Stopping ends the task, so this is the only trace that the
|
|
109
|
+
* result belongs to that turn, see {@link startedByClaudeCode}.
|
|
110
|
+
*/
|
|
111
|
+
private interruptedTurnResultOwed;
|
|
105
112
|
/** The summary of the last task notification, which usually starts the next autonomous turn. */
|
|
106
113
|
private lastNotificationSummary?;
|
|
107
114
|
constructor(enabled: boolean, sessionId: string, publish: Publish,
|
|
@@ -154,6 +161,26 @@ export declare class AsyncTaskRuntime {
|
|
|
154
161
|
get autonomousTurnOpen(): boolean;
|
|
155
162
|
/** Ends the task of the autonomous turn that runs now, if there is one. */
|
|
156
163
|
autonomousTurnEnded(state: "completed" | "failed"): Promise<void>;
|
|
164
|
+
/** A stop is about to interrupt the autonomous turn: its aborted result is owed. */
|
|
165
|
+
autonomousTurnInterrupting(): void;
|
|
166
|
+
/** The interrupt failed, so the turn goes on and no aborted result is owed. */
|
|
167
|
+
autonomousTurnInterruptFailed(): void;
|
|
168
|
+
/**
|
|
169
|
+
* Whether Claude Code started the work that a result reports: the result has
|
|
170
|
+
* an autonomous origin, or it is the aborted result that a stop owes. Call it
|
|
171
|
+
* for every result: the first one after the stop ends the debt, even when
|
|
172
|
+
* the result has an autonomous origin. A turn that a scheduler fire started
|
|
173
|
+
* has results with no `origin`, so the origin cannot tell it from a waiting
|
|
174
|
+
* prompt's result. The first result is the turn's when it is aborted and
|
|
175
|
+
* names no waiting prompt (`answersPrompt`). A non-aborted result means the
|
|
176
|
+
* interrupted turn finished without an aborted result, and one that names a
|
|
177
|
+
* waiting prompt means the turn took the prompt in; neither is the turn's.
|
|
178
|
+
* This relies on the CLI emitting the interrupted turn's result before the
|
|
179
|
+
* next turn's, which nothing enforces here.
|
|
180
|
+
*/
|
|
181
|
+
startedByClaudeCode(result: Extract<SDKMessage, {
|
|
182
|
+
type: "result";
|
|
183
|
+
}>, answersPrompt: boolean): boolean;
|
|
157
184
|
/** Whether the task stands for an autonomous turn, which a stop interrupts. */
|
|
158
185
|
isAutonomousTurn(taskId: string): boolean;
|
|
159
186
|
/** Whether a task of the tool call went to the background, so the client gets it. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-tasks.d.ts","sourceRoot":"","sources":["../src/async-tasks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"async-tasks.d.ts","sourceRoot":"","sources":["../src/async-tasks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAKjF,KAAK,OAAO,GAAG,CAAC,YAAY,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AACvE,qEAAqE;AACrE,KAAK,KAAK,GAAG,CAAC,YAAY,EAAE,sBAAsB,KAAK,sBAAsB,GAAG,IAAI,CAAC;AA4CrF,KAAK,YAAY,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAI5D,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACx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F;YAC1E,YAAY;IAmB1B,yEAAyE;YAC3D,IAAI;CAKnB;AAyBD;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,OAAO,EACtB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,EAC1D,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GACxD,CAAC,gBAAgB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,SAAS,CA6CzE;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,EAC1D,OAAO,EAAE,gBAAgB,EACzB,cAAc,CAAC,EAAE,gBAAgB,GAChC,GAAG,CAAC,MAAM,CAAC,CAmBb"}
|
package/dist/async-tasks.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { AIR_ASYNC_TASKS_CAPABILITY, clientSupportsAirCapability } from "./air-extension.js";
|
|
3
|
+
import { AUTONOMOUS_RESULT_ORIGINS, isAbortedResult } from "./result-end.js";
|
|
3
4
|
import { noticeOrTranscriptUpdate } from "./session-notices.js";
|
|
4
5
|
const MAX_TOOL_RESULT_PATHS = 500;
|
|
5
6
|
/** Reads the display fields supplied by a task progress report. */
|
|
@@ -39,6 +40,12 @@ export class AsyncTaskRuntime {
|
|
|
39
40
|
outputPathsByToolCall = new Map();
|
|
40
41
|
/** The task of the autonomous turn that runs now. */
|
|
41
42
|
autonomousTurn;
|
|
43
|
+
/**
|
|
44
|
+
* Whether a stop interrupted the autonomous turn and its aborted result has
|
|
45
|
+
* not come yet. Stopping ends the task, so this is the only trace that the
|
|
46
|
+
* result belongs to that turn, see {@link startedByClaudeCode}.
|
|
47
|
+
*/
|
|
48
|
+
interruptedTurnResultOwed = false;
|
|
42
49
|
/** The summary of the last task notification, which usually starts the next autonomous turn. */
|
|
43
50
|
lastNotificationSummary;
|
|
44
51
|
constructor(enabled, sessionId, publish,
|
|
@@ -262,6 +269,7 @@ export class AsyncTaskRuntime {
|
|
|
262
269
|
}
|
|
263
270
|
async finishAll(state) {
|
|
264
271
|
this.autonomousTurn = undefined;
|
|
272
|
+
this.interruptedTurnResultOwed = false;
|
|
265
273
|
const errors = [];
|
|
266
274
|
for (const task of this.tasks.values()) {
|
|
267
275
|
if ((task.announced || task.held) && !task.ignored && !isTerminal(task.state)) {
|
|
@@ -366,6 +374,33 @@ export class AsyncTaskRuntime {
|
|
|
366
374
|
this.autonomousTurn = undefined;
|
|
367
375
|
await this.finish(task, state, undefined, "event");
|
|
368
376
|
}
|
|
377
|
+
/** A stop is about to interrupt the autonomous turn: its aborted result is owed. */
|
|
378
|
+
autonomousTurnInterrupting() {
|
|
379
|
+
this.interruptedTurnResultOwed = true;
|
|
380
|
+
}
|
|
381
|
+
/** The interrupt failed, so the turn goes on and no aborted result is owed. */
|
|
382
|
+
autonomousTurnInterruptFailed() {
|
|
383
|
+
this.interruptedTurnResultOwed = false;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Whether Claude Code started the work that a result reports: the result has
|
|
387
|
+
* an autonomous origin, or it is the aborted result that a stop owes. Call it
|
|
388
|
+
* for every result: the first one after the stop ends the debt, even when
|
|
389
|
+
* the result has an autonomous origin. A turn that a scheduler fire started
|
|
390
|
+
* has results with no `origin`, so the origin cannot tell it from a waiting
|
|
391
|
+
* prompt's result. The first result is the turn's when it is aborted and
|
|
392
|
+
* names no waiting prompt (`answersPrompt`). A non-aborted result means the
|
|
393
|
+
* interrupted turn finished without an aborted result, and one that names a
|
|
394
|
+
* waiting prompt means the turn took the prompt in; neither is the turn's.
|
|
395
|
+
* This relies on the CLI emitting the interrupted turn's result before the
|
|
396
|
+
* next turn's, which nothing enforces here.
|
|
397
|
+
*/
|
|
398
|
+
startedByClaudeCode(result, answersPrompt) {
|
|
399
|
+
const owed = this.interruptedTurnResultOwed;
|
|
400
|
+
this.interruptedTurnResultOwed = false;
|
|
401
|
+
return ((result.origin != null && AUTONOMOUS_RESULT_ORIGINS.has(result.origin.kind)) ||
|
|
402
|
+
(owed && isAbortedResult(result) && !answersPrompt));
|
|
403
|
+
}
|
|
369
404
|
/** Whether the task stands for an autonomous turn, which a stop interrupts. */
|
|
370
405
|
isAutonomousTurn(taskId) {
|
|
371
406
|
return this.tasks.get(taskId)?.autonomousTurn === true;
|
|
@@ -425,6 +460,7 @@ export class AsyncTaskRuntime {
|
|
|
425
460
|
this.tasks.clear();
|
|
426
461
|
this.outputPathsByToolCall.clear();
|
|
427
462
|
this.autonomousTurn = undefined;
|
|
463
|
+
this.interruptedTurnResultOwed = false;
|
|
428
464
|
this.lastNotificationSummary = undefined;
|
|
429
465
|
}
|
|
430
466
|
/**
|
package/dist/claude-cli.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
1
2
|
import type { Options } from "@anthropic-ai/claude-agent-sdk";
|
|
2
3
|
/**
|
|
3
4
|
* Called by the executable's entry (`src/binary-entry.ts`) before the agent
|
|
@@ -20,31 +21,36 @@ export declare function isRemoteSession(clientExtraArgs: Options["extraArgs"]):
|
|
|
20
21
|
* The SDK options that say how a session's MCP servers and its `settings`
|
|
21
22
|
* reach the CLI of {@link claudeCliPath}. A client's own options replace them.
|
|
22
23
|
*
|
|
23
|
-
* - `'initialize'
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* sends its MCP servers in the flag for the same reason.
|
|
24
|
+
* - `'initialize'`: over stdin, in the SDK's initialize request. That needs
|
|
25
|
+
* Claude Code 2.1.326 for the MCP servers and 2.1.328 for the settings. The
|
|
26
|
+
* CLI that the adapter ships is newer. An older CLI that
|
|
27
|
+
* `CLAUDE_CODE_EXECUTABLE` names fails the session at startup, with the
|
|
28
|
+
* error of {@link outdatedCliError}.
|
|
29
|
+
* - `settings` are `'argv'`, in the `--settings` flag, when the client's
|
|
30
|
+
* `extraArgs` hold `settings`: Claude Code refuses to start with both
|
|
31
|
+
* ("--initialize-fields=settings cannot be used with --settings"), and in
|
|
32
|
+
* the flag the `settings` option replaces that argument. They are `'argv'`
|
|
33
|
+
* too with `sdk-url` in the `extraArgs`: such a session cannot read the
|
|
34
|
+
* request at launch, and the SDK sends its MCP servers in the flag for the
|
|
35
|
+
* same reason.
|
|
36
36
|
*
|
|
37
37
|
* The SDK reads `settingsDelivery` (0.3.328) but does not declare it in
|
|
38
38
|
* `sdk.d.ts`, so nothing fails to compile if a later SDK drops it. The v2
|
|
39
39
|
* integration tests check the delivery against the real CLI.
|
|
40
40
|
*
|
|
41
|
-
* `mcpServersDelivery` is
|
|
42
|
-
*
|
|
43
|
-
* `DeprecationWarning` when a session has MCP servers and the option is unset.
|
|
41
|
+
* `mcpServersDelivery` is set although `'initialize'` is the SDK's default
|
|
42
|
+
* since 0.3.333: the delivery then does not change with the SDK's default.
|
|
44
43
|
*/
|
|
45
44
|
export declare function cliDelivery(clientExtraArgs: Options["extraArgs"]): {
|
|
46
45
|
mcpServersDelivery: Delivery;
|
|
47
46
|
settingsDelivery: Delivery;
|
|
48
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* The error for a session that did not start because the CLI that
|
|
50
|
+
* `CLAUDE_CODE_EXECUTABLE` names is too old (see {@link cliDelivery}), with
|
|
51
|
+
* the failure's own text in `data.details`. Undefined for any other failure,
|
|
52
|
+
* and without `CLAUDE_CODE_EXECUTABLE`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function outdatedCliError(error: unknown): RequestError | undefined;
|
|
49
55
|
export {};
|
|
50
56
|
//# sourceMappingURL=claude-cli.d.ts.map
|
package/dist/claude-cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-cli.d.ts","sourceRoot":"","sources":["../src/claude-cli.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAM9D;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAQrD;AAED,sGAAsG;AACtG,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAE3D,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAI9E;AAED
|
|
1
|
+
{"version":3,"file":"claude-cli.d.ts","sourceRoot":"","sources":["../src/claude-cli.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAM9D;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAQrD;AAED,sGAAsG;AACtG,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAE3D,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAI9E;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG;IAClE,kBAAkB,EAAE,QAAQ,CAAC;IAC7B,gBAAgB,EAAE,QAAQ,CAAC;CAC5B,CAMA;AAYD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAOzE"}
|
package/dist/claude-cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
+
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
3
4
|
const CLI_FILE_NAME = process.platform === "win32" ? "claude.exe" : "claude";
|
|
4
5
|
let bundledCliDirectory;
|
|
5
6
|
/**
|
|
@@ -33,32 +34,53 @@ export function isRemoteSession(clientExtraArgs) {
|
|
|
33
34
|
* The SDK options that say how a session's MCP servers and its `settings`
|
|
34
35
|
* reach the CLI of {@link claudeCliPath}. A client's own options replace them.
|
|
35
36
|
*
|
|
36
|
-
* - `'initialize'
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* sends its MCP servers in the flag for the same reason.
|
|
37
|
+
* - `'initialize'`: over stdin, in the SDK's initialize request. That needs
|
|
38
|
+
* Claude Code 2.1.326 for the MCP servers and 2.1.328 for the settings. The
|
|
39
|
+
* CLI that the adapter ships is newer. An older CLI that
|
|
40
|
+
* `CLAUDE_CODE_EXECUTABLE` names fails the session at startup, with the
|
|
41
|
+
* error of {@link outdatedCliError}.
|
|
42
|
+
* - `settings` are `'argv'`, in the `--settings` flag, when the client's
|
|
43
|
+
* `extraArgs` hold `settings`: Claude Code refuses to start with both
|
|
44
|
+
* ("--initialize-fields=settings cannot be used with --settings"), and in
|
|
45
|
+
* the flag the `settings` option replaces that argument. They are `'argv'`
|
|
46
|
+
* too with `sdk-url` in the `extraArgs`: such a session cannot read the
|
|
47
|
+
* request at launch, and the SDK sends its MCP servers in the flag for the
|
|
48
|
+
* same reason.
|
|
49
49
|
*
|
|
50
50
|
* The SDK reads `settingsDelivery` (0.3.328) but does not declare it in
|
|
51
51
|
* `sdk.d.ts`, so nothing fails to compile if a later SDK drops it. The v2
|
|
52
52
|
* integration tests check the delivery against the real CLI.
|
|
53
53
|
*
|
|
54
|
-
* `mcpServersDelivery` is
|
|
55
|
-
*
|
|
56
|
-
* `DeprecationWarning` when a session has MCP servers and the option is unset.
|
|
54
|
+
* `mcpServersDelivery` is set although `'initialize'` is the SDK's default
|
|
55
|
+
* since 0.3.333: the delivery then does not change with the SDK's default.
|
|
57
56
|
*/
|
|
58
57
|
export function cliDelivery(clientExtraArgs) {
|
|
59
|
-
const delivery = process.env.CLAUDE_CODE_EXECUTABLE ? "argv" : "initialize";
|
|
60
58
|
const settingsInFlag = "settings" in (clientExtraArgs ?? {}) || isRemoteSession(clientExtraArgs);
|
|
61
|
-
return {
|
|
59
|
+
return {
|
|
60
|
+
mcpServersDelivery: "initialize",
|
|
61
|
+
settingsDelivery: settingsInFlag ? "argv" : "initialize",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* How the start of a Claude Code that cannot take a session's MCP servers or
|
|
66
|
+
* settings over stdin fails:
|
|
67
|
+
* - before 2.1.326, with MCP servers: the SDK ends the session, "This Claude
|
|
68
|
+
* Code (version 2.1.323) is too old to read MCP servers over stdin, …";
|
|
69
|
+
* - before 2.1.328, with settings: the CLI exits, "error: unknown option
|
|
70
|
+
* '--initialize-fields=settings'".
|
|
71
|
+
*/
|
|
72
|
+
const OUTDATED_CLI = /is too old to read MCP servers|unknown option '--initialize-fields/;
|
|
73
|
+
/**
|
|
74
|
+
* The error for a session that did not start because the CLI that
|
|
75
|
+
* `CLAUDE_CODE_EXECUTABLE` names is too old (see {@link cliDelivery}), with
|
|
76
|
+
* the failure's own text in `data.details`. Undefined for any other failure,
|
|
77
|
+
* and without `CLAUDE_CODE_EXECUTABLE`.
|
|
78
|
+
*/
|
|
79
|
+
export function outdatedCliError(error) {
|
|
80
|
+
const named = process.env.CLAUDE_CODE_EXECUTABLE;
|
|
81
|
+
if (!named || !(error instanceof Error) || !OUTDATED_CLI.test(error.message))
|
|
82
|
+
return undefined;
|
|
83
|
+
return RequestError.internalError({ details: error.message }, `The Claude Code that CLAUDE_CODE_EXECUTABLE names (${named}) is too old: it cannot take a session's MCP servers and settings over stdin. Update it to 2.1.328 or newer, or unset CLAUDE_CODE_EXECUTABLE to use the Claude Code that comes with the adapter.`);
|
|
62
84
|
}
|
|
63
85
|
function bundledClaudeCliPath(directory) {
|
|
64
86
|
const path = join(directory, CLI_FILE_NAME);
|
package/dist/mcp-oauth.d.ts
CHANGED
|
@@ -35,8 +35,9 @@ export type McpOAuthSession = {
|
|
|
35
35
|
readonly closed: AbortSignal;
|
|
36
36
|
};
|
|
37
37
|
/** Start OAuth in the background for the servers in `requestedServers` that
|
|
38
|
-
* Claude reports as needing authentication.
|
|
39
|
-
*
|
|
38
|
+
* Claude reports as needing authentication. While an OAuth run of the
|
|
39
|
+
* session is in progress, the servers join it: it checks them after the
|
|
40
|
+
* sign-in that it waits for now. */
|
|
40
41
|
export declare function startMcpServerAuthentication(client: McpOAuthClient, session: McpOAuthSession, requestedServers: Set<string>): void;
|
|
41
42
|
/** Wait for a polling interval, resolving false when the session is aborted. */
|
|
42
43
|
export declare function waitUnlessAborted(milliseconds: number, signal: AbortSignal): Promise<boolean>;
|
package/dist/mcp-oauth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-oauth.d.ts","sourceRoot":"","sources":["../src/mcp-oauth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mcp-oau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;IAC3B,wEAAwE;IACxE,YAAY,IAAI,KAAK,GAAG,SAAS,CAAC;IAClC,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B,CAAC;AAKF;;;qCAGqC;AACrC,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,eAAe,EACxB,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,GAC5B,IAAI,CAiBN;AA0ID,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAa7F"}
|
package/dist/mcp-oauth.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OAuth for the MCP servers that Claude Code reports as `needs-auth`, as an
|
|
3
|
-
* ACP URL elicitation. Protocol-neutral: the v1 core and the v2 core
|
|
4
|
-
*
|
|
3
|
+
* ACP URL elicitation. Protocol-neutral: the v1 core and the v2 core start it
|
|
4
|
+
* for the session's ACP servers once a session's setup response is sent, and
|
|
5
|
+
* for the servers that a `/mcp reconnect` tried once its output is sent.
|
|
5
6
|
*/
|
|
6
7
|
import { randomUUID } from "node:crypto";
|
|
7
8
|
/** Claude Code keeps the OAuth callback listener open in the background after
|
|
@@ -13,47 +14,84 @@ const MCP_OAUTH_TIMEOUT_MS = 10 * 60_000;
|
|
|
13
14
|
export function supportsMcpOAuth(query) {
|
|
14
15
|
return typeof query.mcpAuthenticate === "function";
|
|
15
16
|
}
|
|
17
|
+
/** The servers that the session's OAuth run has yet to check, by session key. */
|
|
16
18
|
const mcpAuthentications = new WeakMap();
|
|
17
19
|
/** Start OAuth in the background for the servers in `requestedServers` that
|
|
18
|
-
* Claude reports as needing authentication.
|
|
19
|
-
*
|
|
20
|
+
* Claude reports as needing authentication. While an OAuth run of the
|
|
21
|
+
* session is in progress, the servers join it: it checks them after the
|
|
22
|
+
* sign-in that it waits for now. */
|
|
20
23
|
export function startMcpServerAuthentication(client, session, requestedServers) {
|
|
21
24
|
if (!client.urlElicitation || requestedServers.size === 0)
|
|
22
25
|
return;
|
|
23
26
|
const query = session.currentQuery();
|
|
24
|
-
if (!query
|
|
27
|
+
if (!query)
|
|
25
28
|
return;
|
|
26
|
-
const
|
|
27
|
-
|
|
29
|
+
const running = mcpAuthentications.get(session.key);
|
|
30
|
+
if (running) {
|
|
31
|
+
for (const name of requestedServers)
|
|
32
|
+
running.add(name);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const wanted = new Set(requestedServers);
|
|
36
|
+
mcpAuthentications.set(session.key, wanted);
|
|
37
|
+
authenticateMcpServers(client, session, query, wanted).catch((error) => {
|
|
28
38
|
if (!session.closed.aborted) {
|
|
29
39
|
client.logger.error(`Failed to inspect MCP servers for OAuth: ${error}`);
|
|
30
40
|
}
|
|
31
|
-
})
|
|
32
|
-
.finally(() => {
|
|
33
|
-
if (mcpAuthentications.get(session.key) === authentication) {
|
|
34
|
-
mcpAuthentications.delete(session.key);
|
|
35
|
-
}
|
|
36
41
|
});
|
|
37
|
-
mcpAuthentications.set(session.key, authentication);
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
/** Signs in to the servers of `wanted` that need it, until `wanted` is empty.
|
|
44
|
+
* A server that reads `pending` stays in `wanted`: Claude Code connects the
|
|
45
|
+
* servers in the background, so right after a warm `session/new` a server
|
|
46
|
+
* that needs OAuth still reads `pending`. The run stops waiting for it
|
|
47
|
+
* {@link MCP_OAUTH_TIMEOUT_MS} after the run started, or when the session
|
|
48
|
+
* closes or its query is replaced. The run leaves `mcpAuthentications` in the same synchronous step
|
|
49
|
+
* that finds `wanted` empty, so a server added later starts a new run. */
|
|
50
|
+
async function authenticateMcpServers(client, session, query, wanted) {
|
|
51
|
+
try {
|
|
52
|
+
if (!supportsMcpOAuth(query)) {
|
|
53
|
+
client.logger.error("The Claude Agent SDK does not expose MCP OAuth authentication.");
|
|
54
|
+
return;
|
|
50
55
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
const deadline = Date.now() + MCP_OAUTH_TIMEOUT_MS;
|
|
57
|
+
while (wanted.size > 0) {
|
|
58
|
+
if (session.currentQuery() !== query)
|
|
59
|
+
return;
|
|
60
|
+
// A server that joins during the read is checked by the next one.
|
|
61
|
+
const checked = [...wanted];
|
|
62
|
+
const statuses = new Map((await query.mcpServerStatus()).map((status) => [status.name, status.status]));
|
|
63
|
+
const settled = checked.filter((name) => statuses.get(name) !== "pending");
|
|
64
|
+
for (const name of settled)
|
|
65
|
+
wanted.delete(name);
|
|
66
|
+
for (const name of settled) {
|
|
67
|
+
if (statuses.get(name) !== "needs-auth")
|
|
68
|
+
continue;
|
|
69
|
+
if (session.currentQuery() !== query)
|
|
70
|
+
return;
|
|
71
|
+
try {
|
|
72
|
+
await authenticateMcpServer(client, session, query, name);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (session.currentQuery() && !session.closed.aborted) {
|
|
76
|
+
client.logger.error(`Failed to authenticate MCP server ${name}: ${error}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
54
79
|
}
|
|
80
|
+
// Wait only when every server left read `pending`; read again at once
|
|
81
|
+
// for one that joined meanwhile.
|
|
82
|
+
const onlyPending = [...wanted].every((name) => checked.includes(name) && !settled.includes(name));
|
|
83
|
+
if (wanted.size === 0 || !onlyPending)
|
|
84
|
+
continue;
|
|
85
|
+
if (Date.now() >= deadline)
|
|
86
|
+
return;
|
|
87
|
+
if (!(await waitUnlessAborted(MCP_OAUTH_STATUS_POLL_MS, session.closed)))
|
|
88
|
+
return;
|
|
55
89
|
}
|
|
56
90
|
}
|
|
91
|
+
finally {
|
|
92
|
+
if (mcpAuthentications.get(session.key) === wanted)
|
|
93
|
+
mcpAuthentications.delete(session.key);
|
|
94
|
+
}
|
|
57
95
|
}
|
|
58
96
|
/** Bridge Claude Code's startup MCP OAuth control to ACP URL elicitation.
|
|
59
97
|
* Claude opens and owns the localhost callback listener; the ACP client only
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Query, SDKSettingsParseError, Settings } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import type { SettingsManager } from "./settings.js";
|
|
3
|
+
/** The fields used from Claude Code's `get_settings` control response. */
|
|
4
|
+
export type QuerySettings = {
|
|
5
|
+
effective?: Settings;
|
|
6
|
+
sources?: Array<{
|
|
7
|
+
source?: unknown;
|
|
8
|
+
settings?: Settings;
|
|
9
|
+
}>;
|
|
10
|
+
applied?: {
|
|
11
|
+
model?: unknown;
|
|
12
|
+
ultracodeAvailable?: unknown;
|
|
13
|
+
ultracodeRequested?: unknown;
|
|
14
|
+
};
|
|
15
|
+
errors?: SDKSettingsParseError[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Claude Code's answer to `get_settings`. Undefined when the SDK has no
|
|
19
|
+
* `getSettings` or the request fails; a failure is logged when a `logger` is
|
|
20
|
+
* given.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readQuerySettings(query: Query, logger?: {
|
|
23
|
+
error: (...args: unknown[]) => void;
|
|
24
|
+
}): Promise<QuerySettings | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* The policy tier the running CLI applies: its managed settings, remote ones
|
|
27
|
+
* included. Undefined when the CLI reports none.
|
|
28
|
+
*/
|
|
29
|
+
export declare function cliPolicySettings(report: QuerySettings | undefined): Settings | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Reads the settings that the query's Claude Code applies, once it has
|
|
32
|
+
* answered `initialize`, and has `settings` follow its policy tier from then
|
|
33
|
+
* on (see `SettingsManager.followCliPolicy`). Call it before the first reader
|
|
34
|
+
* of a value that a policy can set, such as the `apiKeyHelper` of the
|
|
35
|
+
* session's identity. Returns the answer that it read, for the start's other
|
|
36
|
+
* readers (`getAvailableModels`), or undefined without one: the settings then
|
|
37
|
+
* stay those of this process, and the failure is logged.
|
|
38
|
+
*/
|
|
39
|
+
export declare function followQueryPolicy(query: Query, settings: Pick<SettingsManager, "followCliPolicy">, logger: {
|
|
40
|
+
error: (...args: unknown[]) => void;
|
|
41
|
+
}): Promise<QuerySettings | undefined>;
|
|
42
|
+
//# sourceMappingURL=query-settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-settings.d.ts","sourceRoot":"","sources":["../src/query-settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC7F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;IAC3D,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B,CAAC;IACF,MAAM,CAAC,EAAE,qBAAqB,EAAE,CAAC;CAClC,CAAC;AAMF;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,EACZ,MAAM,CAAC,EAAE;IAAE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CAAE,GAC/C,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CASpC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAKzF;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,IAAI,CAAC,eAAe,EAAE,iBAAiB,CAAC,EAClD,MAAM,EAAE;IAAE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CAAE,GAC9C,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAQpC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code's answer to `get_settings`. Undefined when the SDK has no
|
|
3
|
+
* `getSettings` or the request fails; a failure is logged when a `logger` is
|
|
4
|
+
* given.
|
|
5
|
+
*/
|
|
6
|
+
export async function readQuerySettings(query, logger) {
|
|
7
|
+
const getSettings = query.getSettings;
|
|
8
|
+
if (typeof getSettings !== "function")
|
|
9
|
+
return undefined;
|
|
10
|
+
try {
|
|
11
|
+
return await getSettings.call(query);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
logger?.error("Failed to read the settings that Claude Code applies:", error);
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The policy tier the running CLI applies: its managed settings, remote ones
|
|
20
|
+
* included. Undefined when the CLI reports none.
|
|
21
|
+
*/
|
|
22
|
+
export function cliPolicySettings(report) {
|
|
23
|
+
const sources = Array.isArray(report?.sources) ? report.sources : [];
|
|
24
|
+
const policy = sources.find((entry) => entry?.source === "policySettings")?.settings;
|
|
25
|
+
if (!policy || typeof policy !== "object" || Object.keys(policy).length === 0)
|
|
26
|
+
return undefined;
|
|
27
|
+
return policy;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads the settings that the query's Claude Code applies, once it has
|
|
31
|
+
* answered `initialize`, and has `settings` follow its policy tier from then
|
|
32
|
+
* on (see `SettingsManager.followCliPolicy`). Call it before the first reader
|
|
33
|
+
* of a value that a policy can set, such as the `apiKeyHelper` of the
|
|
34
|
+
* session's identity. Returns the answer that it read, for the start's other
|
|
35
|
+
* readers (`getAvailableModels`), or undefined without one: the settings then
|
|
36
|
+
* stay those of this process, and the failure is logged.
|
|
37
|
+
*/
|
|
38
|
+
export async function followQueryPolicy(query, settings, logger) {
|
|
39
|
+
const read = () => readQuerySettings(query, logger);
|
|
40
|
+
const report = await read();
|
|
41
|
+
await settings.followCliPolicy(async () => cliPolicySettings(await read()), cliPolicySettings(report));
|
|
42
|
+
return report;
|
|
43
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SessionMessage, type SessionStoreEntry } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { type FileHandle } from "node:fs/promises";
|
|
2
3
|
type ResumeLogger = {
|
|
3
4
|
log: (...args: unknown[]) => void;
|
|
4
5
|
error: (...args: unknown[]) => void;
|
|
@@ -39,7 +40,7 @@ export declare function readResumedSession(sessionId: string, logger?: ResumeLog
|
|
|
39
40
|
* the chain loops and ends there. Without it, the kept messages stay where
|
|
40
41
|
* they were said, before the boundary.
|
|
41
42
|
*/
|
|
42
|
-
export declare function readHistoryAcrossCompactions(sessionId: string, messages: SessionMessage[], logger?: ResumeLogger, dir?: string): Promise<SessionMessage[]>;
|
|
43
|
+
export declare function readHistoryAcrossCompactions(sessionId: string, messages: SessionMessage[], logger?: ResumeLogger, dir?: string, snapshot?: SessionStoreEntry[]): Promise<SessionMessage[]>;
|
|
43
44
|
/** Every record of a session's transcript, including the inactive branches
|
|
44
45
|
* and the history before a compaction that `getSessionMessages` leaves out.
|
|
45
46
|
* Without `dir`, all project directories are searched. */
|
|
@@ -64,6 +65,12 @@ export type ResumedTail = {
|
|
|
64
65
|
*/
|
|
65
66
|
export declare function readResumedTail(sessionId: string, logger?: ResumeLogger, withModel?: boolean): Promise<ResumedTail>;
|
|
66
67
|
/** The local transcript of a session in any project directory, as the SDK looks it up. */
|
|
67
|
-
export declare function findTranscript(sessionId: string
|
|
68
|
+
export declare function findTranscript(sessionId: string, options?: {
|
|
69
|
+
strict: boolean;
|
|
70
|
+
}): Promise<string | undefined>;
|
|
71
|
+
/** Read the records once so the SDK projects the active branch and its compactions
|
|
72
|
+
* from the same bytes. An unfinished JSON line can be completed by the next poll. */
|
|
73
|
+
export declare function readTranscriptEntries(file: string): Promise<SessionStoreEntry[]>;
|
|
74
|
+
export declare function readTranscriptEntriesOf(file: string, handle: FileHandle, size: number): Promise<SessionStoreEntry[]>;
|
|
68
75
|
export {};
|
|
69
76
|
//# sourceMappingURL=resumed-session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resumed-session.d.ts","sourceRoot":"","sources":["../src/resumed-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAEnB,KAAK,iBAAiB,EACvB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"resumed-session.d.ts","sourceRoot":"","sources":["../src/resumed-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAEnB,KAAK,iBAAiB,EACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAyB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAU1E,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAClC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;iDAGiD;AACjD,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,MAAM,GAAG,SAAS,CAgBzF;AASD;uEACuE;AACvE,wBAAsB,kBAAkB,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