@agentclientprotocol/claude-agent-acp 0.113.1-preview.9 → 0.114.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/README.md +2 -0
- 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/transcript-scan.d.ts +13 -3
- package/dist/session-index/transcript-scan.d.ts.map +1 -1
- package/dist/session-index/transcript-scan.js +21 -5
- package/dist/session-mode.d.ts +31 -2
- package/dist/session-mode.d.ts.map +1 -1
- package/dist/session-mode.js +35 -5
- 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 +4 -1
- package/dist/session-ultracode.d.ts.map +1 -1
- package/dist/session-ultracode.js +14 -25
- package/dist/settings.d.ts +34 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +55 -4
- 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 +6 -0
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +146 -72
- 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 +62 -27
- package/dist/v2/config.d.ts +6 -5
- package/dist/v2/config.d.ts.map +1 -1
- package/dist/v2/config.js +4 -1
- 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/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 +1 -1
package/dist/session-model.js
CHANGED
|
@@ -602,7 +602,9 @@ export function withCurrentModelInfo(allowedModels, sdkModels, currentModelId) {
|
|
|
602
602
|
function isPreModelSwitchHookBlock(error) {
|
|
603
603
|
return error instanceof Error && error.message.includes("blocked by a PreModelSwitch hook");
|
|
604
604
|
}
|
|
605
|
-
export async function getAvailableModels(query, models, sdkModels, settingsManager, logger, isResumedSession, sessionId, resumedModelHint, narrowedByGateway = false
|
|
605
|
+
export async function getAvailableModels(query, models, sdkModels, settingsManager, logger, isResumedSession, sessionId, resumedModelHint, narrowedByGateway = false,
|
|
606
|
+
/** Claude Code's `get_settings` answer for this query, read after `initialize`. */
|
|
607
|
+
cliSettings) {
|
|
606
608
|
// A gateway that lists none of the SDK's models leaves none to offer
|
|
607
609
|
// (`narrowToGatewayModels`). The session stays on the model the SDK runs,
|
|
608
610
|
// and the gateway refuses its requests.
|
|
@@ -612,7 +614,13 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
612
614
|
currentModelId: (isResumedSession && resumedModelHint) || sdkModels[0]?.value || "default",
|
|
613
615
|
};
|
|
614
616
|
}
|
|
615
|
-
|
|
617
|
+
// The `model` setting as the running CLI resolved it, which also counts the
|
|
618
|
+
// tiers that `settingsManager` does not read (the `settings` option of the
|
|
619
|
+
// query). Without the CLI's answer, the settings of this process.
|
|
620
|
+
const settings = cliSettings?.effective ?? settingsManager.getSettings();
|
|
621
|
+
const appliedModel = typeof cliSettings?.applied?.model === "string" && cliSettings.applied.model.trim()
|
|
622
|
+
? cliSettings.applied.model
|
|
623
|
+
: undefined;
|
|
616
624
|
let currentModel = models[0];
|
|
617
625
|
let resolvedFromInput;
|
|
618
626
|
// Model priority (highest to lowest):
|
|
@@ -644,7 +652,7 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
644
652
|
currentModel = resumedModelHint ? matchResumedModel(models, resumedModelHint) : currentModel;
|
|
645
653
|
}
|
|
646
654
|
// Skip the setModel round-trip when we can prove the SDK has already landed
|
|
647
|
-
// on the same model.
|
|
655
|
+
// on the same model. Three cases qualify:
|
|
648
656
|
// (a) No override applied — currentModel is the SDK's own default (or, on
|
|
649
657
|
// resume, the live model read back from the SDK above); nothing to sync.
|
|
650
658
|
// (b) The resolver returned the user's input verbatim AND that value exists
|
|
@@ -654,6 +662,8 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
654
662
|
// This only holds for fresh sessions: a resumed session lands on the
|
|
655
663
|
// transcript's model regardless of env/settings, so the override must
|
|
656
664
|
// be re-asserted to keep the reported model truthful.
|
|
665
|
+
// (c) The CLI reports that it runs the model that `currentModel` resolves
|
|
666
|
+
// to (`cliRunsSelectedModel` below), on a fresh or a resumed session.
|
|
657
667
|
// Anything else (fuzzy match, allowlist-synthesized value, alias) gets a
|
|
658
668
|
// setModel call so we don't drift from the user's intended pin.
|
|
659
669
|
// Case (a) does not hold when `narrowToGatewayModels` left the SDK on a
|
|
@@ -680,7 +690,19 @@ export async function getAvailableModels(query, models, sdkModels, settingsManag
|
|
|
680
690
|
}
|
|
681
691
|
// When the switch fails, the SDK stays on the model it ran before it.
|
|
682
692
|
const modelBeforeSwitch = () => switchToListed && sdkDefault !== undefined ? sdkDefault : models[0];
|
|
683
|
-
|
|
693
|
+
// `applied.model` is the model that the CLI runs: `claude-sonnet-5-5` for a
|
|
694
|
+
// `claude-sonnet-5-5[1m]` pin (it drops the hint of a model whose only
|
|
695
|
+
// window is 1M), `claude-sonnet-4-6[1m]` for the 1M lane of a model that
|
|
696
|
+
// also has a 200k one. The ids are compared with their hints, so a session
|
|
697
|
+
// on the 200k lane still gets a `[1m]` row set. On a resumed session the
|
|
698
|
+
// CLI has restored the transcript's model before it answers `get_settings`
|
|
699
|
+
// (seen on 2.1.333); nothing here enforces that order.
|
|
700
|
+
const cliRunsSelectedModel = appliedModel !== undefined &&
|
|
701
|
+
sdkSawSameValue &&
|
|
702
|
+
canonicalizeModelId(currentModel.resolvedModel ?? currentModel.value) ===
|
|
703
|
+
canonicalizeModelId(appliedModel);
|
|
704
|
+
const skipSetModel = cliRunsSelectedModel ||
|
|
705
|
+
(resolvedFromInput === undefined && !switchToListed) ||
|
|
684
706
|
(!isResumedSession && currentModel.value === resolvedFromInput && sdkSawSameValue);
|
|
685
707
|
if (!skipSetModel) {
|
|
686
708
|
const setModelStartedAt = performance.now();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const SESSION_READ_METHOD = "_session/read";
|
|
2
|
+
export declare const SESSION_READ_CAPABILITY: {
|
|
3
|
+
readonly supported: true;
|
|
4
|
+
};
|
|
5
|
+
export type SessionReadFrame = {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
update: {
|
|
8
|
+
sessionUpdate: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
type ReadOptions = {
|
|
14
|
+
protocol: 1 | 2;
|
|
15
|
+
capabilities: unknown;
|
|
16
|
+
cursors: boolean;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
isOpen(sessionId: string): boolean;
|
|
19
|
+
replay(sessionId: string, cwd: string | undefined): Promise<{
|
|
20
|
+
frames: SessionReadFrame[];
|
|
21
|
+
cwd: string;
|
|
22
|
+
historyEnd?: number;
|
|
23
|
+
title?: string;
|
|
24
|
+
}>;
|
|
25
|
+
send(frame: SessionReadFrame): Promise<void> | void;
|
|
26
|
+
};
|
|
27
|
+
/** The SDK follows parent links in these records, including the branch selected by rewind.json. */
|
|
28
|
+
export declare function readSessionTranscript(sessionId: string, cwd?: string): Promise<{
|
|
29
|
+
messages: import("@anthropic-ai/claude-agent-sdk").SessionMessage[];
|
|
30
|
+
cwd: string;
|
|
31
|
+
transcript: string;
|
|
32
|
+
title: string | undefined;
|
|
33
|
+
}>;
|
|
34
|
+
/** A read owns only a replay on this connection. Closing it invalidates the pending delivery. */
|
|
35
|
+
export declare class SessionReads {
|
|
36
|
+
private readonly active;
|
|
37
|
+
private readonly transitions;
|
|
38
|
+
/** Reserve a session before load, resume, close or delete can yield. */
|
|
39
|
+
transition<T>(sessionId: string | undefined, kind: "open" | "close", run: () => Promise<T>): Promise<T>;
|
|
40
|
+
read(params: unknown, options: ReadOptions): Promise<{
|
|
41
|
+
cursorId?: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=session-read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-read.d.ts","sourceRoot":"","sources":["../src/session-read.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,uBAAuB;;CAA+B,CAAC;AAEpE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC1D,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAcF,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,GAAG,SAAS,GACtB,OAAO,CAAC;QAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7F,IAAI,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACrD,CAAC;AAEF,mGAAmG;AACnG,wBAAsB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;;;;;GA2C1E;AA2ID,iGAAiG;AACjG,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+C;IAEtE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6B;IAEzD,wEAAwE;IAClE,UAAU,CAAC,CAAC,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC;IAiBP,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CA8GlF"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
+
import { getSessionMessages } from "@anthropic-ai/claude-agent-sdk";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { open } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
8
|
+
import { claudeConfigDir, isSessionId } from "./paths.js";
|
|
9
|
+
import { findTranscript, readHistoryAcrossCompactions, readTranscriptEntriesOf, } from "./resumed-session.js";
|
|
10
|
+
import { LastReportedEntity } from "./session-cursors.js";
|
|
11
|
+
import { readHeadTailOf, readRecentCustomTitle, } from "./session-index/transcript-scan.js";
|
|
12
|
+
import { sanitizeTitle } from "./session-titles.js";
|
|
13
|
+
import { cutAtRewindPoint } from "./session-rewind.js";
|
|
14
|
+
export const SESSION_READ_METHOD = "_session/read";
|
|
15
|
+
export const SESSION_READ_CAPABILITY = { supported: true };
|
|
16
|
+
const request = z.object({
|
|
17
|
+
sessionId: z.string().trim().min(1),
|
|
18
|
+
_meta: z.record(z.string(), z.unknown()).nullish(),
|
|
19
|
+
cwd: z.string().refine(path.isAbsolute, "cwd must be an absolute path").nullish(),
|
|
20
|
+
replayFrom: z
|
|
21
|
+
.discriminatedUnion("type", [
|
|
22
|
+
z.object({ type: z.literal("start") }),
|
|
23
|
+
z.object({ type: z.literal("cursor"), cursorId: z.unknown().optional() }),
|
|
24
|
+
])
|
|
25
|
+
.nullish(),
|
|
26
|
+
});
|
|
27
|
+
/** The SDK follows parent links in these records, including the branch selected by rewind.json. */
|
|
28
|
+
export async function readSessionTranscript(sessionId, cwd) {
|
|
29
|
+
if (!isSessionId(sessionId)) {
|
|
30
|
+
throw RequestError.invalidParams({ sessionId }, "Read the root Claude session by its UUID.");
|
|
31
|
+
}
|
|
32
|
+
const transcript = await findTranscript(sessionId, { strict: true });
|
|
33
|
+
if (!transcript)
|
|
34
|
+
throw RequestError.sessionNotFound(sessionId);
|
|
35
|
+
const handle = await open(transcript, "r");
|
|
36
|
+
let headTail;
|
|
37
|
+
let records;
|
|
38
|
+
try {
|
|
39
|
+
const { size } = await handle.stat();
|
|
40
|
+
headTail = await readHeadTailOf(handle, size);
|
|
41
|
+
records = await readTranscriptEntriesOf(transcript, handle, size);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await handle.close();
|
|
45
|
+
}
|
|
46
|
+
const title = records[0]?.isSidechain === true
|
|
47
|
+
? undefined
|
|
48
|
+
: ((await readRecentCustomTitle(transcript, headTail, { strict: true })) ??
|
|
49
|
+
lastRecordedTitle(records, "custom-title", "customTitle") ??
|
|
50
|
+
lastRecordedTitle(records, "ai-title", "aiTitle"));
|
|
51
|
+
const dir = cwd ?? records.find((r) => typeof r.cwd === "string" && path.isAbsolute(r.cwd))?.cwd;
|
|
52
|
+
const effectiveCwd = typeof dir === "string" ? dir : process.cwd();
|
|
53
|
+
const options = {
|
|
54
|
+
dir: effectiveCwd,
|
|
55
|
+
sessionStore: { append: async () => { }, load: async () => records },
|
|
56
|
+
};
|
|
57
|
+
const chain = await getSessionMessages(sessionId, options);
|
|
58
|
+
const retained = await cutAtRewindPoint(sessionId, chain, undefined, { transcript });
|
|
59
|
+
const messages = await readHistoryAcrossCompactions(sessionId, retained, undefined, effectiveCwd, records);
|
|
60
|
+
return {
|
|
61
|
+
messages,
|
|
62
|
+
cwd: effectiveCwd,
|
|
63
|
+
transcript,
|
|
64
|
+
title: title && sanitizeTitle(title),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The `field` of the last `type` record of the snapshot, undefined when it is
|
|
69
|
+
* empty. The SDK reads the head and tail 64 KB windows instead, so a large
|
|
70
|
+
* tool result appended after the last `ai-title` would hide it from the read
|
|
71
|
+
* and change the title of an unchanged session.
|
|
72
|
+
*/
|
|
73
|
+
function lastRecordedTitle(records, type, field) {
|
|
74
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
75
|
+
const record = records[i];
|
|
76
|
+
const value = record.type === type ? record[field] : undefined;
|
|
77
|
+
if (typeof value === "string")
|
|
78
|
+
return value || undefined;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
function invalidCursor() {
|
|
83
|
+
return RequestError.invalidParams({ reason: "invalid_cursor" }, "This cursor cannot continue the replay. Read from start.");
|
|
84
|
+
}
|
|
85
|
+
function alreadyOpen(sessionId) {
|
|
86
|
+
return RequestError.invalidRequest({ reason: "session_already_open", sessionId }, "The session is open or changing on this connection. Retry after it closes.");
|
|
87
|
+
}
|
|
88
|
+
function json(value) {
|
|
89
|
+
return JSON.stringify(value, (_key, member) => member && typeof member === "object" && !Array.isArray(member)
|
|
90
|
+
? Object.fromEntries(Object.keys(member)
|
|
91
|
+
.sort()
|
|
92
|
+
.map((key) => [key, member[key]]))
|
|
93
|
+
: member);
|
|
94
|
+
}
|
|
95
|
+
function digest(value) {
|
|
96
|
+
return createHash("sha256").update(value).digest("base64url");
|
|
97
|
+
}
|
|
98
|
+
// A cursor carries the number of delivered updates per session. Its digest binds
|
|
99
|
+
// those counts to the rendering options, exact history prefixes and post-replay metadata.
|
|
100
|
+
const lengths = z.record(z.string(), z.int().nonnegative());
|
|
101
|
+
function decodeLengths(id) {
|
|
102
|
+
const match = /^read:v1:[\w-]{43}\.([\w-]+)$/.exec(id);
|
|
103
|
+
if (match) {
|
|
104
|
+
try {
|
|
105
|
+
return new Map(Object.entries(lengths.parse(JSON.parse(Buffer.from(match[1], "base64url").toString("utf8")))));
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
/* Invalid and expired cursors have the same recovery. */
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
throw invalidCursor();
|
|
112
|
+
}
|
|
113
|
+
function snapshot(frames, root, protocol, scope, previous, historyEnd = frames.length) {
|
|
114
|
+
const saved = previous ? decodeLengths(previous) : new Map();
|
|
115
|
+
const streams = new Map();
|
|
116
|
+
const entities = new LastReportedEntity();
|
|
117
|
+
const outgoing = [];
|
|
118
|
+
for (const [index, frame] of frames.entries()) {
|
|
119
|
+
const { sessionId, update } = frame;
|
|
120
|
+
// The renderer emits each child's final state on its parent after all messages.
|
|
121
|
+
// A later parent message precedes that same state in the next full replay.
|
|
122
|
+
const boundary = update.sessionUpdate === "replay_complete";
|
|
123
|
+
const key = index < historyEnd || boundary
|
|
124
|
+
? sessionId
|
|
125
|
+
: json([sessionId, update.sessionUpdate, update.sessionId ?? update.subagentSessionId]);
|
|
126
|
+
let stream = streams.get(key);
|
|
127
|
+
if (!stream) {
|
|
128
|
+
stream = {
|
|
129
|
+
count: 0,
|
|
130
|
+
history: createHash("sha256"),
|
|
131
|
+
prefix: digest(""),
|
|
132
|
+
};
|
|
133
|
+
streams.set(key, stream);
|
|
134
|
+
}
|
|
135
|
+
const before = saved.get(key);
|
|
136
|
+
if (boundary) {
|
|
137
|
+
if (before === undefined || sessionId === root || stream.count > before)
|
|
138
|
+
outgoing.push(frame);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
stream.history.update(json(frame) + "\n");
|
|
142
|
+
stream.count++;
|
|
143
|
+
if (stream.count === before)
|
|
144
|
+
stream.prefix = stream.history.copy().digest("base64url");
|
|
145
|
+
if (before === undefined || stream.count > before)
|
|
146
|
+
outgoing.push(frame);
|
|
147
|
+
entities.sending(frame, protocol);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function cursor(prefix) {
|
|
151
|
+
const counts = new Map();
|
|
152
|
+
const hashes = new Map();
|
|
153
|
+
for (const [id, stream] of streams) {
|
|
154
|
+
const count = prefix ? saved.get(id) : stream.count;
|
|
155
|
+
if (count === undefined)
|
|
156
|
+
continue;
|
|
157
|
+
if (count > stream.count)
|
|
158
|
+
throw invalidCursor();
|
|
159
|
+
counts.set(id, count);
|
|
160
|
+
hashes.set(id, prefix ? stream.prefix : stream.history.copy().digest("base64url"));
|
|
161
|
+
}
|
|
162
|
+
const encoded = Buffer.from(json(Object.fromEntries(counts))).toString("base64url");
|
|
163
|
+
return "read:v1:" + digest(json([scope, encoded, Object.fromEntries(hashes)])) + "." + encoded;
|
|
164
|
+
}
|
|
165
|
+
if (previous && cursor(true) !== previous)
|
|
166
|
+
throw invalidCursor();
|
|
167
|
+
const anchor = entities.after(root);
|
|
168
|
+
if (previous && !anchor)
|
|
169
|
+
throw invalidCursor();
|
|
170
|
+
return { outgoing, anchor, cursorId: anchor ? cursor(false) : undefined };
|
|
171
|
+
}
|
|
172
|
+
/** A read owns only a replay on this connection. Closing it invalidates the pending delivery. */
|
|
173
|
+
export class SessionReads {
|
|
174
|
+
active = new Map();
|
|
175
|
+
transitions = new Map();
|
|
176
|
+
/** Reserve a session before load, resume, close or delete can yield. */
|
|
177
|
+
async transition(sessionId, kind, run) {
|
|
178
|
+
if (sessionId === undefined)
|
|
179
|
+
return run();
|
|
180
|
+
const read = this.active.get(sessionId);
|
|
181
|
+
if (read) {
|
|
182
|
+
if (kind === "open")
|
|
183
|
+
throw alreadyOpen(sessionId);
|
|
184
|
+
read.invalidated = true;
|
|
185
|
+
}
|
|
186
|
+
this.transitions.set(sessionId, (this.transitions.get(sessionId) ?? 0) + 1);
|
|
187
|
+
try {
|
|
188
|
+
return await run();
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
const remaining = this.transitions.get(sessionId) - 1;
|
|
192
|
+
if (remaining === 0)
|
|
193
|
+
this.transitions.delete(sessionId);
|
|
194
|
+
else
|
|
195
|
+
this.transitions.set(sessionId, remaining);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async read(params, options) {
|
|
199
|
+
const parsed = request.safeParse(params);
|
|
200
|
+
if (!parsed.success)
|
|
201
|
+
throw RequestError.invalidParams(undefined, parsed.error.issues[0]?.message);
|
|
202
|
+
const { sessionId, cwd, replayFrom } = parsed.data;
|
|
203
|
+
const previous = replayFrom?.type === "cursor" ? replayFrom.cursorId : undefined;
|
|
204
|
+
if (replayFrom?.type === "cursor" &&
|
|
205
|
+
(typeof previous !== "string" || !previous || !options.cursors))
|
|
206
|
+
throw invalidCursor();
|
|
207
|
+
const cursor = typeof previous === "string" ? previous : undefined;
|
|
208
|
+
if (this.active.has(sessionId))
|
|
209
|
+
throw alreadyOpen(sessionId);
|
|
210
|
+
const read = { invalidated: false };
|
|
211
|
+
const check = () => {
|
|
212
|
+
if (options.signal?.aborted)
|
|
213
|
+
throw RequestError.requestCancelled();
|
|
214
|
+
if (read.invalidated || this.transitions.has(sessionId) || options.isOpen(sessionId))
|
|
215
|
+
throw alreadyOpen(sessionId);
|
|
216
|
+
};
|
|
217
|
+
check();
|
|
218
|
+
this.active.set(sessionId, read);
|
|
219
|
+
const replay = async () => {
|
|
220
|
+
try {
|
|
221
|
+
const view = await options.replay(sessionId, cwd ?? undefined);
|
|
222
|
+
if (options.protocol === 1 && view.title)
|
|
223
|
+
view.frames.push({
|
|
224
|
+
sessionId,
|
|
225
|
+
update: { sessionUpdate: "session_info_update", title: view.title },
|
|
226
|
+
});
|
|
227
|
+
return view;
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
check();
|
|
231
|
+
if (error instanceof RequestError)
|
|
232
|
+
throw error;
|
|
233
|
+
const file = error?.path;
|
|
234
|
+
throw RequestError.internalError({
|
|
235
|
+
sessionId,
|
|
236
|
+
reason: "history_read_failed",
|
|
237
|
+
retryable: true,
|
|
238
|
+
...(file && { paths: [file] }),
|
|
239
|
+
}, `Could not read the history of ${sessionId}. Retry the read. ${String(error)}`);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
try {
|
|
243
|
+
const { frames, cwd: effectiveCwd, historyEnd, title } = await replay();
|
|
244
|
+
check();
|
|
245
|
+
let outgoing = frames;
|
|
246
|
+
let cursorId;
|
|
247
|
+
const useCursor = options.cursors && replayFrom != null;
|
|
248
|
+
if (useCursor) {
|
|
249
|
+
const scope = json([
|
|
250
|
+
sessionId,
|
|
251
|
+
effectiveCwd,
|
|
252
|
+
claudeConfigDir(),
|
|
253
|
+
options.protocol,
|
|
254
|
+
options.capabilities,
|
|
255
|
+
packageJson.version,
|
|
256
|
+
]);
|
|
257
|
+
const next = snapshot(frames, sessionId, options.protocol, scope, cursor, historyEnd);
|
|
258
|
+
outgoing = next.outgoing;
|
|
259
|
+
cursorId = next.cursorId;
|
|
260
|
+
if (cursorId && cursorId !== cursor) {
|
|
261
|
+
// A terminal can append or rewind between the reads of the root and a child.
|
|
262
|
+
const again = await replay();
|
|
263
|
+
check();
|
|
264
|
+
if (again.cwd !== effectiveCwd ||
|
|
265
|
+
again.historyEnd !== historyEnd ||
|
|
266
|
+
frames.length !== again.frames.length ||
|
|
267
|
+
frames.some((frame, i) => json(frame) !== json(again.frames[i]))) {
|
|
268
|
+
throw RequestError.internalError({ sessionId, retryable: true }, "History changed during the read. Retry with the last successful cursor.");
|
|
269
|
+
}
|
|
270
|
+
const end = outgoing.findIndex((frame) => frame.sessionId === sessionId && frame.update.sessionUpdate === "replay_complete");
|
|
271
|
+
outgoing.splice(end < 0 ? outgoing.length : end, 0, {
|
|
272
|
+
sessionId,
|
|
273
|
+
update: {
|
|
274
|
+
sessionUpdate: "cursor_update",
|
|
275
|
+
cursorId,
|
|
276
|
+
anchor: next.anchor,
|
|
277
|
+
capabilities: { read: {} },
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// On v2 the title is current session info, outside the replay cursor.
|
|
283
|
+
if (options.protocol === 2 && (title || useCursor)) {
|
|
284
|
+
outgoing.push({
|
|
285
|
+
sessionId,
|
|
286
|
+
update: { sessionUpdate: "session_info_update", title: title || null },
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
for (const frame of outgoing) {
|
|
290
|
+
check();
|
|
291
|
+
await options.send(frame);
|
|
292
|
+
}
|
|
293
|
+
check();
|
|
294
|
+
return cursorId ? { cursorId } : {};
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
this.active.delete(sessionId);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
package/dist/session-rewind.d.ts
CHANGED
|
@@ -97,7 +97,9 @@ export declare function loadRewindableHistory(sessionId: string, logger?: Logger
|
|
|
97
97
|
*/
|
|
98
98
|
export declare function cutAtRewindPoint<M extends {
|
|
99
99
|
uuid?: string | null;
|
|
100
|
-
}>(sessionId: string, stored: readonly M[], logger?: Logger
|
|
100
|
+
}>(sessionId: string, stored: readonly M[], logger?: Logger, options?: {
|
|
101
|
+
transcript: string;
|
|
102
|
+
}): Promise<M[]>;
|
|
101
103
|
/**
|
|
102
104
|
* The entry that a fork of the whole of `sessionId` ends at while a rewind is
|
|
103
105
|
* pending, or undefined when there is none: the newest leaf then still lies in
|
|
@@ -136,7 +138,9 @@ export declare function writeRewindPoint(sessionId: string, point: RewindPoint):
|
|
|
136
138
|
* parsed fails with an internal error: reading it as "no rewind" would show or
|
|
137
139
|
* resume the dropped turns. The file stays, so the client can retry.
|
|
138
140
|
*/
|
|
139
|
-
export declare function readRewindPoint(sessionId: string, logger?: Logger
|
|
141
|
+
export declare function readRewindPoint(sessionId: string, logger?: Logger, options?: {
|
|
142
|
+
transcript: string;
|
|
143
|
+
}): Promise<RewindPoint | undefined>;
|
|
140
144
|
/** Removes the record of the last rewind. */
|
|
141
145
|
export declare function clearRewindPoint(sessionId: string): Promise<void>;
|
|
142
146
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-rewind.d.ts","sourceRoot":"","sources":["../src/session-rewind.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,gCAAgC,CAAC;AAaxC,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,+CAA+C;AAC/C,MAAM,MAAM,oBAAoB;AAC9B,gDAAgD;AAC9C,MAAM;AACR,gDAAgD;GAC9C,gBAAgB;AAClB,uEAAuE;GACrE,kBAAkB;AACpB,qEA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,CACnC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,GAC/B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CA+BlC;AAED,6CAA6C;AAC7C,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuB7B"}
|
package/dist/session-rewind.js
CHANGED
|
@@ -194,8 +194,8 @@ export async function loadRewindableHistory(sessionId, logger) {
|
|
|
194
194
|
* that a pending rewind dropped. Cut before reading across compactions: the
|
|
195
195
|
* newest leaf is the last retained message.
|
|
196
196
|
*/
|
|
197
|
-
export async function cutAtRewindPoint(sessionId, stored, logger) {
|
|
198
|
-
return activeSessionMessages(stored, await readRewindPoint(sessionId, logger));
|
|
197
|
+
export async function cutAtRewindPoint(sessionId, stored, logger, options) {
|
|
198
|
+
return activeSessionMessages(stored, await readRewindPoint(sessionId, logger, options));
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* The entry that a fork of the whole of `sessionId` ends at while a rewind is
|
|
@@ -272,9 +272,11 @@ export async function writeRewindPoint(sessionId, point) {
|
|
|
272
272
|
* parsed fails with an internal error: reading it as "no rewind" would show or
|
|
273
273
|
* resume the dropped turns. The file stays, so the client can retry.
|
|
274
274
|
*/
|
|
275
|
-
export async function readRewindPoint(sessionId, logger) {
|
|
275
|
+
export async function readRewindPoint(sessionId, logger, options) {
|
|
276
276
|
try {
|
|
277
|
-
const file =
|
|
277
|
+
const file = options
|
|
278
|
+
? path.join(path.dirname(options.transcript), sessionId, "rewind.json")
|
|
279
|
+
: await rewindPointFile(sessionId);
|
|
278
280
|
if (!file)
|
|
279
281
|
return undefined;
|
|
280
282
|
let point;
|
|
@@ -293,6 +295,13 @@ export async function readRewindPoint(sessionId, logger) {
|
|
|
293
295
|
return { resumeSessionAt, droppedPromptUuid };
|
|
294
296
|
}
|
|
295
297
|
catch (error) {
|
|
298
|
+
if (options) {
|
|
299
|
+
if (typeof error?.path === "string")
|
|
300
|
+
throw error;
|
|
301
|
+
throw Object.assign(new Error("Failed to read the rewind point", { cause: error }), {
|
|
302
|
+
path: path.join(path.dirname(options.transcript), sessionId, "rewind.json"),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
296
305
|
logger?.error(`Failed to read the rewind point of session ${sessionId}:`, error);
|
|
297
306
|
throw RequestError.internalError(undefined, `Session ${sessionId} was rewound, but its rewind point cannot be read (${error instanceof Error ? error.message : String(error)}). Try again.`);
|
|
298
307
|
}
|
|
@@ -25,7 +25,10 @@ export type SettingsReport = {
|
|
|
25
25
|
settingsErrors: SDKSettingsParseError[];
|
|
26
26
|
};
|
|
27
27
|
/** Ask the CLI whether ultracode is available and requested for the session,
|
|
28
|
-
* and which settings files it skipped.
|
|
28
|
+
* and which settings files it skipped. Its own request, after the session's
|
|
29
|
+
* model is settled: `applied.ultracodeAvailable` is for the model that the
|
|
30
|
+
* CLI runs at the request, and `getAvailableModels` can have set another one
|
|
31
|
+
* since the start's first `get_settings` answer (`followQueryPolicy`). */
|
|
29
32
|
export declare function readSettingsReport(query: Query): Promise<SettingsReport>;
|
|
30
33
|
/** The CLI supports ultracode on exactly the models that support `xhigh`
|
|
31
34
|
* effort (both use the same capability check), and `supportedEffortLevels`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-ultracode.d.ts","sourceRoot":"","sources":["../src/session-ultracode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC9B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAA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M,oBAAoB,GAAG;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;8DAC8D;AAC9D,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,OAAO,GACxB,mBAAmB,CAqBrB;AAED;qEACqE;AACrE,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAStF"}
|
|
@@ -1,40 +1,29 @@
|
|
|
1
1
|
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
2
2
|
import { ULTRACODE_CONFIG_ID } from "./session-config-ids.js";
|
|
3
|
+
import { readQuerySettings } from "./query-settings.js";
|
|
3
4
|
export { ULTRACODE_CONFIG_ID } from "./session-config-ids.js";
|
|
4
5
|
/** Select-fallback values for clients without boolean config options. */
|
|
5
6
|
export const ULTRACODE_ON = "on";
|
|
6
7
|
export const ULTRACODE_OFF = "off";
|
|
7
8
|
const ULTRACODE_DESCRIPTION = "Dynamic workflows on every task, at any effort level";
|
|
8
|
-
const NO_REPORT = { ultracode: undefined, settingsErrors: [] };
|
|
9
9
|
/** Ask the CLI whether ultracode is available and requested for the session,
|
|
10
|
-
* and which settings files it skipped.
|
|
10
|
+
* and which settings files it skipped. Its own request, after the session's
|
|
11
|
+
* model is settled: `applied.ultracodeAvailable` is for the model that the
|
|
12
|
+
* CLI runs at the request, and `getAvailableModels` can have set another one
|
|
13
|
+
* since the start's first `get_settings` answer (`followQueryPolicy`). */
|
|
11
14
|
export async function readSettingsReport(query) {
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
response = await getSettings.call(query);
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
return NO_REPORT;
|
|
21
|
-
}
|
|
15
|
+
const settings = await readQuerySettings(query);
|
|
16
|
+
if (!settings)
|
|
17
|
+
return { ultracode: undefined, settingsErrors: [] };
|
|
18
|
+
const applied = settings.applied;
|
|
22
19
|
return {
|
|
23
|
-
ultracode: {
|
|
24
|
-
|
|
20
|
+
ultracode: {
|
|
21
|
+
available: typeof applied?.ultracodeAvailable === "boolean" ? applied.ultracodeAvailable : undefined,
|
|
22
|
+
requested: typeof applied?.ultracodeRequested === "boolean" ? applied.ultracodeRequested : undefined,
|
|
23
|
+
},
|
|
24
|
+
settingsErrors: settings.errors ?? [],
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
function parseAvailable(response) {
|
|
28
|
-
const value = response?.applied?.ultracodeAvailable;
|
|
29
|
-
return typeof value === "boolean" ? value : undefined;
|
|
30
|
-
}
|
|
31
|
-
function parseRequested(response) {
|
|
32
|
-
const value = response?.applied?.ultracodeRequested;
|
|
33
|
-
return typeof value === "boolean" ? value : undefined;
|
|
34
|
-
}
|
|
35
|
-
function parseSettingsErrors(response) {
|
|
36
|
-
return response?.errors ?? [];
|
|
37
|
-
}
|
|
38
27
|
/** The CLI supports ultracode on exactly the models that support `xhigh`
|
|
39
28
|
* effort (both use the same capability check), and `supportedEffortLevels`
|
|
40
29
|
* lists `xhigh` only for those models. E.g. Opus 4.7+, Sonnet 5+ and Haiku
|
package/dist/settings.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export interface SettingsManagerOptions {
|
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
type ModelSelectionSettings = Pick<Settings, "availableModels" | "modelOverrides">;
|
|
10
|
+
/**
|
|
11
|
+
* Reads the policy tier that the session's Claude Code applies now (see
|
|
12
|
+
* `SettingsManager.followCliPolicy`). Undefined when it reports none, or when
|
|
13
|
+
* it cannot be asked.
|
|
14
|
+
*/
|
|
15
|
+
export type CliPolicyReader = () => Promise<Settings | undefined>;
|
|
10
16
|
/** The settings that decide whether Claude Code compacts (see `idle-compaction.ts`). */
|
|
11
17
|
export type CompactionSettings = {
|
|
12
18
|
idleCompaction?: boolean;
|
|
@@ -30,6 +36,12 @@ export declare class SettingsManager {
|
|
|
30
36
|
private managedApiKeyHelper?;
|
|
31
37
|
private managedCompactionSettings;
|
|
32
38
|
private managedShowClearContextOnPlanAccept?;
|
|
39
|
+
/** Asked at every load once the session's CLI runs (see {@link followCliPolicy}). */
|
|
40
|
+
private readCliPolicy?;
|
|
41
|
+
/** Whether the last load resolved with a policy tier that the CLI reported. */
|
|
42
|
+
private cliPolicyApplied;
|
|
43
|
+
/** The load that was started last. The next one starts when it has ended. */
|
|
44
|
+
private loading;
|
|
33
45
|
/** The policy sources last logged as not loaded (see {@link unloadedPolicySources}). */
|
|
34
46
|
private unloadedPolicy?;
|
|
35
47
|
private watchers;
|
|
@@ -49,6 +61,12 @@ export declare class SettingsManager {
|
|
|
49
61
|
* containing directories means we pick up file creation as well as edits.
|
|
50
62
|
*/
|
|
51
63
|
private getWatchedPaths;
|
|
64
|
+
/**
|
|
65
|
+
* Loads the settings after every load that was started before this one.
|
|
66
|
+
* Loads that overlap could end in another order than they started in, and
|
|
67
|
+
* the settings of the older one would stay.
|
|
68
|
+
*/
|
|
69
|
+
private load;
|
|
52
70
|
/**
|
|
53
71
|
* Resolves the effective settings via the SDK and applies the CLI's trust
|
|
54
72
|
* filter for escalating `permissions.defaultMode` values.
|
|
@@ -62,6 +80,22 @@ export declare class SettingsManager {
|
|
|
62
80
|
* Handles settings file changes with debouncing to avoid rapid reloads
|
|
63
81
|
*/
|
|
64
82
|
private handleSettingsChange;
|
|
83
|
+
/**
|
|
84
|
+
* Resolves the settings with the policy tier that the session's CLI
|
|
85
|
+
* reports, now (`current`, which the caller has just read) and at every
|
|
86
|
+
* later load (`read`). `resolveSettings` in this process does not read the
|
|
87
|
+
* remote managed settings that the CLI applies (SDK 0.3.333), and then
|
|
88
|
+
* every value read here (the model, the effort, the bypass and auto mode
|
|
89
|
+
* locks, the model allowlist) is the user's own instead of the policy's.
|
|
90
|
+
* What the CLI reports is the tier that it applies, so it goes in as the
|
|
91
|
+
* server-managed tier.
|
|
92
|
+
*
|
|
93
|
+
* `read` is asked again at each load and its last answer is not kept, so a
|
|
94
|
+
* load after a settings file change resolves with the policy of that
|
|
95
|
+
* moment. Without an answer the load resolves the settings of this process
|
|
96
|
+
* alone.
|
|
97
|
+
*/
|
|
98
|
+
followCliPolicy(read: CliPolicyReader, current: Settings | undefined): Promise<void>;
|
|
65
99
|
/**
|
|
66
100
|
* Returns the current merged settings
|
|
67
101
|
*/
|
package/dist/settings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,gCAAgC,CAAC;AA2BxC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;KAAE,CAAC;CAC7E;AAED,KAAK,sBAAsB,GAAG,IAAI,CAAC,QAAQ,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,CAAC;AAEnF,wFAAwF;AACxF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,oBAAoB,CAA8B;IAC1D,OAAO,CAAC,mBAAmB,CAAC,CA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