@botiverse/oar 0.15.2 → 0.16.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 +4 -3
- package/dist/observe/tool-activity.d.ts +9 -2
- package/dist/observe/tool-activity.d.ts.map +1 -1
- package/dist/observe/tool-activity.js +34 -9
- package/dist/observe/tool-activity.js.map +1 -1
- package/dist/observe/tool-groups.d.ts.map +1 -1
- package/dist/observe/tool-groups.js +1 -0
- package/dist/observe/tool-groups.js.map +1 -1
- package/dist/runtimes/cursor/index.d.ts +6 -3
- package/dist/runtimes/cursor/index.d.ts.map +1 -1
- package/dist/runtimes/cursor/index.js +6 -3
- package/dist/runtimes/cursor/index.js.map +1 -1
- package/dist/runtimes/cursor/installation.d.ts +7 -6
- package/dist/runtimes/cursor/installation.d.ts.map +1 -1
- package/dist/runtimes/cursor/installation.js +35 -13
- package/dist/runtimes/cursor/installation.js.map +1 -1
- package/dist/runtimes/cursor/list-models.d.ts +7 -8
- package/dist/runtimes/cursor/list-models.d.ts.map +1 -1
- package/dist/runtimes/cursor/list-models.js +50 -82
- package/dist/runtimes/cursor/list-models.js.map +1 -1
- package/dist/runtimes/cursor/model.d.ts +25 -0
- package/dist/runtimes/cursor/model.d.ts.map +1 -0
- package/dist/runtimes/cursor/model.js +98 -0
- package/dist/runtimes/cursor/model.js.map +1 -0
- package/dist/runtimes/cursor/projection.d.ts +40 -0
- package/dist/runtimes/cursor/projection.d.ts.map +1 -0
- package/dist/runtimes/cursor/projection.js +205 -0
- package/dist/runtimes/cursor/projection.js.map +1 -0
- package/dist/runtimes/cursor/run.d.ts +33 -0
- package/dist/runtimes/cursor/run.d.ts.map +1 -0
- package/dist/runtimes/cursor/run.js +68 -0
- package/dist/runtimes/cursor/run.js.map +1 -0
- package/dist/runtimes/cursor/sdk.d.ts +64 -0
- package/dist/runtimes/cursor/sdk.d.ts.map +1 -0
- package/dist/runtimes/cursor/sdk.js +50 -0
- package/dist/runtimes/cursor/sdk.js.map +1 -0
- package/dist/runtimes/cursor/session.d.ts +4 -37
- package/dist/runtimes/cursor/session.d.ts.map +1 -1
- package/dist/runtimes/cursor/session.js +265 -71
- package/dist/runtimes/cursor/session.js.map +1 -1
- package/dist/shared/acp/client-app.d.ts +0 -2
- package/dist/shared/acp/client-app.d.ts.map +1 -1
- package/dist/shared/acp/client-app.js +1 -8
- package/dist/shared/acp/client-app.js.map +1 -1
- package/dist/shared/acp/effort.d.ts +1 -1
- package/dist/shared/acp/effort.js +1 -1
- package/dist/shared/acp/model.d.ts +5 -8
- package/dist/shared/acp/model.d.ts.map +1 -1
- package/dist/shared/acp/model.js +6 -14
- package/dist/shared/acp/model.js.map +1 -1
- package/dist/shared/acp/process.d.ts +0 -2
- package/dist/shared/acp/process.d.ts.map +1 -1
- package/dist/shared/acp/process.js +2 -7
- package/dist/shared/acp/process.js.map +1 -1
- package/dist/shared/acp/profile.d.ts +2 -17
- package/dist/shared/acp/profile.d.ts.map +1 -1
- package/dist/shared/acp/profile.js +1 -5
- package/dist/shared/acp/profile.js.map +1 -1
- package/dist/shared/acp/records.d.ts +1 -3
- package/dist/shared/acp/records.d.ts.map +1 -1
- package/dist/shared/acp/records.js +6 -14
- package/dist/shared/acp/records.js.map +1 -1
- package/dist/shared/acp/session.d.ts.map +1 -1
- package/dist/shared/acp/session.js +1 -6
- package/dist/shared/acp/session.js.map +1 -1
- package/dist/shared/failure-class.js +1 -1
- package/dist/shared/failure-class.js.map +1 -1
- package/dist/shared/update.d.ts +1 -1
- package/dist/shared/update.d.ts.map +1 -1
- package/dist/shared/update.js +3 -4
- package/dist/shared/update.js.map +1 -1
- package/package.json +6 -5
- package/dist/runtimes/cursor/update.d.ts +0 -19
- package/dist/runtimes/cursor/update.d.ts.map +0 -1
- package/dist/runtimes/cursor/update.js +0 -88
- package/dist/runtimes/cursor/update.js.map +0 -1
- package/dist/shared/acp/vendor-updates.d.ts +0 -7
- package/dist/shared/acp/vendor-updates.d.ts.map +0 -1
- package/dist/shared/acp/vendor-updates.js +0 -46
- package/dist/shared/acp/vendor-updates.js.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor's catalog (`Cursor.models.list()`, SDK 1.0.35) gives each model its
|
|
3
|
+
* own parameters, and the reasoning one has a different id per family:
|
|
4
|
+
* `effort` (Claude 5, Grok 4.6), `reasoning` (GPT), `reasoning_effort`
|
|
5
|
+
* (Grok 4.7, Gemini 3.8, Claude Sonnet 5.5). Several Claude models also have
|
|
6
|
+
* a `thinking` on/off switch; the level menu wins over it, and a model whose
|
|
7
|
+
* only reasoning parameter is the switch (claude-haiku-4-5) keeps it.
|
|
8
|
+
*/
|
|
9
|
+
const LEVEL_PARAMETERS = ["effort", "reasoning", "reasoning_effort"];
|
|
10
|
+
const SWITCH_PARAMETER = "thinking";
|
|
11
|
+
const EFFORT_PARAMETERS = [...LEVEL_PARAMETERS, SWITCH_PARAMETER];
|
|
12
|
+
/** The catalog's "Auto" entry; a local agent needs a model, and this is the one Cursor picks for the user. */
|
|
13
|
+
export const CURSOR_DEFAULT_MODEL = "default";
|
|
14
|
+
export function cursorEffortParameter(model) {
|
|
15
|
+
const parameters = model.parameters ?? [];
|
|
16
|
+
for (const id of EFFORT_PARAMETERS) {
|
|
17
|
+
const parameter = parameters.find((entry) => entry.id === id);
|
|
18
|
+
if (parameter !== undefined) {
|
|
19
|
+
return { id, levels: parameter.values.map((value) => value.value) };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/** The effort a selection carries, by the same parameter preference. */
|
|
25
|
+
export function cursorSelectionEffort(selection) {
|
|
26
|
+
const params = selection?.params ?? [];
|
|
27
|
+
for (const id of EFFORT_PARAMETERS) {
|
|
28
|
+
const param = params.find((entry) => entry.id === id);
|
|
29
|
+
if (param !== undefined) {
|
|
30
|
+
return param.value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function findModel(models, id) {
|
|
36
|
+
return models.find((model) => model.id === id || model.aliases?.includes(id) === true);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The selection a session opens with. A local agent always needs one, and a
|
|
40
|
+
* resumed agent does not restore its own, so on resume without a model the
|
|
41
|
+
* agent's latest recorded run says what it ran. A requested effort is
|
|
42
|
+
* checked against the model's own parameter menu, because the SDK passes an
|
|
43
|
+
* unknown value through unchecked and reports it back as given (probed
|
|
44
|
+
* 2026-10-03: `reasoning: "ludicrous"` ran and came back verbatim). It
|
|
45
|
+
* replaces only that parameter: the other parameters stay as the resumed run
|
|
46
|
+
* had them, or as the catalog's default variant sets them (a `thinking`
|
|
47
|
+
* switch stays on beside an `effort` level).
|
|
48
|
+
*/
|
|
49
|
+
/** Options the SDK cannot honor, refused before anything opens. */
|
|
50
|
+
export function validateCursorOptions(options) {
|
|
51
|
+
if (options.systemPrompt !== undefined || options.appendSystemPrompt !== undefined) {
|
|
52
|
+
// SDK 1.0.35 types a `systemPrompt`, but a local agent's run fails with
|
|
53
|
+
// "unknown option '--system-prompt'" (probed 2026-10-03), and there is no append.
|
|
54
|
+
throw new Error("Cursor's SDK runs no system prompt override for a local agent");
|
|
55
|
+
}
|
|
56
|
+
if (options.env !== undefined && Object.keys(options.env).length > 0) {
|
|
57
|
+
throw new Error("Cursor runs in this process and its SDK takes no environment for the agent's tools; SessionOptions.env is unsupported");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export async function cursorModelSelection(sdk, options) {
|
|
61
|
+
const base = options.model === undefined && options.resume !== undefined
|
|
62
|
+
? await latestRunModel(sdk, options.resume, options.cwd)
|
|
63
|
+
: undefined;
|
|
64
|
+
const id = options.model ?? base?.id ?? CURSOR_DEFAULT_MODEL;
|
|
65
|
+
if (options.effort === undefined) {
|
|
66
|
+
return base ?? { id };
|
|
67
|
+
}
|
|
68
|
+
const model = findModel(await sdk.Cursor.models.list(), id);
|
|
69
|
+
if (model === undefined) {
|
|
70
|
+
throw new Error(`Cursor does not list model ${id}, so effort ${options.effort} cannot be checked`);
|
|
71
|
+
}
|
|
72
|
+
const parameter = cursorEffortParameter(model);
|
|
73
|
+
if (parameter === null) {
|
|
74
|
+
throw new Error(`Cursor model ${model.id} has no effort setting; requested effort ${options.effort}`);
|
|
75
|
+
}
|
|
76
|
+
if (!parameter.levels.includes(options.effort)) {
|
|
77
|
+
throw new Error(`Cursor model ${model.id} does not offer effort ${options.effort}; it lists ${parameter.levels.join(", ")}`);
|
|
78
|
+
}
|
|
79
|
+
const others = base?.params ?? model.variants?.find((variant) => variant.isDefault === true)?.params ?? [];
|
|
80
|
+
const kept = others.filter((param) => param.id !== parameter.id);
|
|
81
|
+
return { id: model.id, params: [...kept, { id: parameter.id, value: options.effort }] };
|
|
82
|
+
}
|
|
83
|
+
async function latestRunModel(sdk, agentId, cwd) {
|
|
84
|
+
let latest = null;
|
|
85
|
+
let cursor = null;
|
|
86
|
+
do {
|
|
87
|
+
// oxlint-disable-next-line no-await-in-loop -- pages are sequential by construction.
|
|
88
|
+
const page = await sdk.Agent.listRuns(agentId, { runtime: "local", cwd, ...(cursor === null ? {} : { cursor }) });
|
|
89
|
+
for (const run of page.items) {
|
|
90
|
+
if (run.model !== undefined && (latest === null || (run.createdAt ?? 0) >= (latest.createdAt ?? 0))) {
|
|
91
|
+
latest = run;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
cursor = page.nextCursor === undefined || page.nextCursor === "" ? null : page.nextCursor;
|
|
95
|
+
} while (cursor !== null);
|
|
96
|
+
return latest?.model;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../src/runtimes/cursor/model.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,kBAAkB,CA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AC;QACF,qFAAqF;QACrF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;QAClH,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpG,MAAM,GAAG,GAAG,CAAC;YACf,CAAC;QACH,CAAC;QACD,MAAM,GAAG,IAAI,CAAC,UAAU,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IAC5F,CAAC,QAAQ,MAAM,KAAK,IAAI,EAAE;IAC1B,OAAO,MAAM,EAAE,KAAK,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RuntimeEventBody, TokenTotals, ToolOutputPart } from "../../contracts/session.js";
|
|
2
|
+
import { type JsonRecord } from "../../shared/json.js";
|
|
3
|
+
import type { ModelSelection } from "./sdk.js";
|
|
4
|
+
/** `tokens`: cumulative per agent path, so usage events stay summable. */
|
|
5
|
+
export interface CursorProjectionState {
|
|
6
|
+
readonly tokens: ReadonlyMap<string, TokenTotals>;
|
|
7
|
+
}
|
|
8
|
+
export declare const initialCursorProjection: CursorProjectionState;
|
|
9
|
+
export interface CursorFrame {
|
|
10
|
+
readonly type: string;
|
|
11
|
+
readonly native: unknown;
|
|
12
|
+
readonly events: readonly RuntimeEventBody[];
|
|
13
|
+
/** The sub-agent a subagent's update came from: the `task` call ids, outermost first. */
|
|
14
|
+
readonly agentPath: readonly string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A tool result as content parts. Shell output is its stdout and stderr, a
|
|
18
|
+
* read is the file text, an edit is its diff, a failure is its message;
|
|
19
|
+
* every other result is kept whole as one `other` part.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cursorToolContent(tool: string, result: JsonRecord | null): readonly ToolOutputPart[] | undefined;
|
|
22
|
+
/** One `onDelta` update as one frame, attributed to the subagent it came from. */
|
|
23
|
+
export declare function foldCursorDelta(state: CursorProjectionState, native: unknown): {
|
|
24
|
+
readonly state: CursorProjectionState;
|
|
25
|
+
readonly frame: CursorFrame;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The agent as the SDK holds it after open: its id and model selection (the
|
|
29
|
+
* SDK has resolved an alias to the catalog id, `composer` → `composer-2.5`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function cursorOpenedFrame(agentId: string, model: ModelSelection | undefined): CursorFrame;
|
|
32
|
+
/**
|
|
33
|
+
* `run.wait()`'s answer: the run's status is the turn's outcome (`finished`,
|
|
34
|
+
* `cancelled`, `error` with the SDK's message), and its `model` is what the
|
|
35
|
+
* SDK records the run ran with.
|
|
36
|
+
*/
|
|
37
|
+
export declare function cursorRunResultFrame(result: unknown): CursorFrame;
|
|
38
|
+
/** `run.wait()` rejected instead of answering: the SDK's own message ends the turn. */
|
|
39
|
+
export declare function cursorRunFailedFrame(message: string): CursorFrame;
|
|
40
|
+
//# sourceMappingURL=projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/runtimes/cursor/projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,cAAc,EAAe,MAAM,4BAA4B,CAAC;AAE7G,OAAO,EAAsB,KAA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|
3
|
+
import { toolContent } from "../../shared/tool-output.js";
|
|
4
|
+
import { cursorSelectionEffort } from "./model.js";
|
|
5
|
+
export const initialCursorProjection = { tokens: new Map() };
|
|
6
|
+
/**
|
|
7
|
+
* A subagent speaks through its `task` call: `tool-call-delta` carries the
|
|
8
|
+
* child's own update under `taskUpdate`, keyed by the call id (probed
|
|
9
|
+
* 2026-10-03: the child's thinking, tool calls and text all arrive this way).
|
|
10
|
+
* SDK 1.0.35's schema allows no `tool-call-delta` inside a `taskUpdate`; if
|
|
11
|
+
* one ever came, it is unwrapped the same way, one call id deeper.
|
|
12
|
+
*/
|
|
13
|
+
function innermost(update, path) {
|
|
14
|
+
const nested = asRecord(update.taskUpdate);
|
|
15
|
+
if (update.type === "tool-call-delta" && typeof update.callId === "string" && nested !== null) {
|
|
16
|
+
return innermost(nested, [...path, update.callId]);
|
|
17
|
+
}
|
|
18
|
+
return { update, path };
|
|
19
|
+
}
|
|
20
|
+
const pathKey = (path) => path.join("/");
|
|
21
|
+
const text = (value) => (typeof value === "string" && value.length > 0 ? value : undefined);
|
|
22
|
+
/**
|
|
23
|
+
* A tool result as content parts. Shell output is its stdout and stderr, a
|
|
24
|
+
* read is the file text, an edit is its diff, a failure is its message;
|
|
25
|
+
* every other result is kept whole as one `other` part.
|
|
26
|
+
*/
|
|
27
|
+
export function cursorToolContent(tool, result) {
|
|
28
|
+
if (result === null) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (result.status === "error") {
|
|
32
|
+
const message = text(asRecord(result.error)?.message) ?? text(result.error);
|
|
33
|
+
return message === undefined ? toolContent(result.error) : [{ type: "text", text: message }];
|
|
34
|
+
}
|
|
35
|
+
const value = asRecord(result.value);
|
|
36
|
+
const parts = [];
|
|
37
|
+
const add = (part) => {
|
|
38
|
+
const found = text(part);
|
|
39
|
+
if (found !== undefined) {
|
|
40
|
+
parts.push({ type: "text", text: found });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
switch (tool) {
|
|
44
|
+
case "shell":
|
|
45
|
+
add(value?.stdout);
|
|
46
|
+
add(value?.stderr);
|
|
47
|
+
// The command ran and printed nothing: a result, with empty text.
|
|
48
|
+
return parts.length === 0 ? [{ type: "text", text: "" }] : parts;
|
|
49
|
+
case "read":
|
|
50
|
+
add(value?.content);
|
|
51
|
+
break;
|
|
52
|
+
case "edit":
|
|
53
|
+
case "write":
|
|
54
|
+
add(value?.diffString);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return parts.length > 0 ? parts : toolContent(result.value);
|
|
60
|
+
}
|
|
61
|
+
function toolOutcome(status) {
|
|
62
|
+
if (status === "success") {
|
|
63
|
+
return "ok";
|
|
64
|
+
}
|
|
65
|
+
return status === "error" ? "failed" : undefined;
|
|
66
|
+
}
|
|
67
|
+
/** A shell's exit code, or `null` when cursor names the signal that ended it. */
|
|
68
|
+
function shellExit(tool, result) {
|
|
69
|
+
const value = tool === "shell" && result?.status === "success" ? asRecord(result.value) : null;
|
|
70
|
+
if (value === null) {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
if (typeof value.signal === "string" && value.signal !== "") {
|
|
74
|
+
return { exitCode: null };
|
|
75
|
+
}
|
|
76
|
+
const exitCode = asNumber(value.exitCode);
|
|
77
|
+
return exitCode === null ? {} : { exitCode };
|
|
78
|
+
}
|
|
79
|
+
function toolEnded(update) {
|
|
80
|
+
const callId = text(update.callId);
|
|
81
|
+
if (callId === undefined) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const call = asRecord(update.toolCall);
|
|
85
|
+
const tool = text(call?.type) ?? "unknown";
|
|
86
|
+
const result = asRecord(call?.result);
|
|
87
|
+
const content = cursorToolContent(tool, result);
|
|
88
|
+
const outcome = toolOutcome(result?.status);
|
|
89
|
+
return {
|
|
90
|
+
kind: "tool_call_ended",
|
|
91
|
+
callId,
|
|
92
|
+
...(content === undefined ? {} : { content }),
|
|
93
|
+
...(outcome === undefined ? {} : { result: outcome }),
|
|
94
|
+
...shellExit(tool, result),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function eventsOf(state, update, path) {
|
|
98
|
+
switch (update.type) {
|
|
99
|
+
case "text-delta": {
|
|
100
|
+
const delta = text(update.text);
|
|
101
|
+
return { state, events: delta === undefined ? [] : [{ kind: "text_delta", text: delta }] };
|
|
102
|
+
}
|
|
103
|
+
case "thinking-delta": {
|
|
104
|
+
const delta = text(update.text);
|
|
105
|
+
return { state, events: delta === undefined ? [] : [{ kind: "reasoning", content: { kind: "text", text: delta } }] };
|
|
106
|
+
}
|
|
107
|
+
case "tool-call-started": {
|
|
108
|
+
const callId = text(update.callId);
|
|
109
|
+
const call = asRecord(update.toolCall);
|
|
110
|
+
if (callId === undefined) {
|
|
111
|
+
return { state, events: [] };
|
|
112
|
+
}
|
|
113
|
+
const started = { kind: "tool_call_started", callId, tool: text(call?.type) ?? "unknown" };
|
|
114
|
+
return { state, events: [call?.args === undefined ? started : { ...started, input: JSON.stringify(call.args) }] };
|
|
115
|
+
}
|
|
116
|
+
case "tool-call-completed": {
|
|
117
|
+
const ended = toolEnded(update);
|
|
118
|
+
return { state, events: ended === null ? [] : [ended] };
|
|
119
|
+
}
|
|
120
|
+
case "user-message-appended": {
|
|
121
|
+
// A user message entered the conversation (a delivered steer, probed):
|
|
122
|
+
// text only, so no input id is claimed (docs/spec/conversation.md).
|
|
123
|
+
const input = asRecord(update.userMessage)?.text;
|
|
124
|
+
return { state, events: typeof input === "string" ? [{ kind: "user_message", input, evidence: "conversation" }] : [] };
|
|
125
|
+
}
|
|
126
|
+
case "turn-ended": {
|
|
127
|
+
const usage = asRecord(update.usage);
|
|
128
|
+
if (usage === null) {
|
|
129
|
+
return { state, events: [] };
|
|
130
|
+
}
|
|
131
|
+
const previous = state.tokens.get(pathKey(path)) ?? { input: 0, output: 0 };
|
|
132
|
+
// `inputTokens` excludes cache reads and writes (totalTokens is the sum
|
|
133
|
+
// of all four), so input counts them back in, as claude's and pi's do.
|
|
134
|
+
const tokens = {
|
|
135
|
+
input: previous.input + (asNumber(usage.inputTokens) ?? 0) + (asNumber(usage.cacheReadTokens) ?? 0) + (asNumber(usage.cacheWriteTokens) ?? 0),
|
|
136
|
+
output: previous.output + (asNumber(usage.outputTokens) ?? 0),
|
|
137
|
+
};
|
|
138
|
+
return { state: { tokens: new Map([...state.tokens, [pathKey(path), tokens]]) }, events: [{ kind: "usage", usage: { tokens } }] };
|
|
139
|
+
}
|
|
140
|
+
default:
|
|
141
|
+
return { state, events: [] };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** One `onDelta` update as one frame, attributed to the subagent it came from. */
|
|
145
|
+
export function foldCursorDelta(state, native) {
|
|
146
|
+
const outer = asRecord(native) ?? {};
|
|
147
|
+
const { update, path } = innermost(outer, []);
|
|
148
|
+
const read = eventsOf(state, update, path);
|
|
149
|
+
return { state: read.state, frame: { type: text(outer.type) ?? "unknown", native, events: read.events, agentPath: path } };
|
|
150
|
+
}
|
|
151
|
+
function selectionEvents(selection) {
|
|
152
|
+
if (selection === undefined) {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
const effort = cursorSelectionEffort(selection);
|
|
156
|
+
return [{ kind: "model", model: selection.id }, ...(effort === null ? [] : [{ kind: "effort", effort }])];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The agent as the SDK holds it after open: its id and model selection (the
|
|
160
|
+
* SDK has resolved an alias to the catalog id, `composer` → `composer-2.5`).
|
|
161
|
+
*/
|
|
162
|
+
export function cursorOpenedFrame(agentId, model) {
|
|
163
|
+
return { type: "cursor/agent_opened", native: { agentId, model }, events: selectionEvents(model), agentPath: [] };
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* `run.wait()`'s answer: the run's status is the turn's outcome (`finished`,
|
|
167
|
+
* `cancelled`, `error` with the SDK's message), and its `model` is what the
|
|
168
|
+
* SDK records the run ran with.
|
|
169
|
+
*/
|
|
170
|
+
export function cursorRunResultFrame(result) {
|
|
171
|
+
const record = asRecord(result) ?? {};
|
|
172
|
+
const model = asRecord(record.model);
|
|
173
|
+
const selection = typeof model?.id === "string"
|
|
174
|
+
? {
|
|
175
|
+
id: model.id,
|
|
176
|
+
params: (Array.isArray(model.params) ? model.params : []).flatMap((param) => {
|
|
177
|
+
const entry = asRecord(param);
|
|
178
|
+
return typeof entry?.id === "string" && typeof entry.value === "string" ? [{ id: entry.id, value: entry.value }] : [];
|
|
179
|
+
}),
|
|
180
|
+
}
|
|
181
|
+
: undefined;
|
|
182
|
+
return { type: "cursor/run_result", native: result, events: [...selectionEvents(selection), { kind: "turn_ended", outcome: runOutcome(record) }], agentPath: [] };
|
|
183
|
+
}
|
|
184
|
+
function runOutcome(result) {
|
|
185
|
+
switch (result.status) {
|
|
186
|
+
case "finished":
|
|
187
|
+
return { kind: "completed" };
|
|
188
|
+
case "cancelled":
|
|
189
|
+
return { kind: "aborted" };
|
|
190
|
+
default: {
|
|
191
|
+
const reason = text(asRecord(result.error)?.message) ?? `cursor run ended with status ${String(result.status)}`;
|
|
192
|
+
return { kind: "failed", reason, failure: classifyFailure(reason) };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/** `run.wait()` rejected instead of answering: the SDK's own message ends the turn. */
|
|
197
|
+
export function cursorRunFailedFrame(message) {
|
|
198
|
+
return {
|
|
199
|
+
type: "cursor/run_failed",
|
|
200
|
+
native: { message },
|
|
201
|
+
events: [{ kind: "turn_ended", outcome: { kind: "failed", reason: message, failure: classifyFailure(message) } }],
|
|
202
|
+
agentPath: [],
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/runtimes/cursor/projection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+B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AAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC7B,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,IAAI,gCAAgC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAChH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QACtE,CAAC;IACH,CAAC;AACH,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,MAAM,EAAE,EAAE,OAAO,EAAE;QACnB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;QACjH,SAAS,EAAE,EAAE;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ResponseBody } from "../../contracts/session.js";
|
|
2
|
+
import { type CursorFrame } from "./projection.js";
|
|
3
|
+
import type { CursorRun } from "./sdk.js";
|
|
4
|
+
export interface ActiveRun {
|
|
5
|
+
readonly run: CursorRun;
|
|
6
|
+
/** Settles once the run's end is in the stream. */
|
|
7
|
+
readonly ended: Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One `send` on its way to a run. The prompt's answer waits on `decided`;
|
|
11
|
+
* an abort that arrives first is held in `abortRequested`; a dispose or the
|
|
12
|
+
* send deadline gives the launch up, and a run the SDK returns after that is
|
|
13
|
+
* stopped rather than adopted. Each launch is its own object, so a later one
|
|
14
|
+
* never reads or clears an earlier one's state.
|
|
15
|
+
*/
|
|
16
|
+
export interface Launch {
|
|
17
|
+
state: "sending" | "sent" | "failed" | "given_up";
|
|
18
|
+
abortRequested: boolean;
|
|
19
|
+
current: ActiveRun | null;
|
|
20
|
+
/** Why it was not sent: the SDK's error, or the reason it was given up. */
|
|
21
|
+
reason: string;
|
|
22
|
+
readonly decided: Promise<void>;
|
|
23
|
+
readonly decide: () => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function newLaunch(): Launch;
|
|
26
|
+
export declare function giveUp(launch: Launch, reason: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* A run the SDK returned after its launch was given up: it did start, so it
|
|
29
|
+
* is stopped, and its end still enters the stream.
|
|
30
|
+
*/
|
|
31
|
+
export declare function stopOrphan(run: CursorRun, record: (frame: CursorFrame) => void): void;
|
|
32
|
+
export declare function steerRun(current: ActiveRun, input: string): Promise<ResponseBody>;
|
|
33
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/runtimes/cursor/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAA8C,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,UAAU,CAAC;AAE3D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;IAClD,cAAc,EAAE,OAAO,CAAC;IACxB,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC;IAC1B,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED,wBAAgB,SAAS,IAAI,MAAM,CAGlC;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAM3D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI,CAarF;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAiCvF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { cursorRunFailedFrame, cursorRunResultFrame } from "./projection.js";
|
|
2
|
+
export function newLaunch() {
|
|
3
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
4
|
+
return { state: "sending", abortRequested: false, current: null, reason: "", decided: promise, decide: resolve };
|
|
5
|
+
}
|
|
6
|
+
export function giveUp(launch, reason) {
|
|
7
|
+
if (launch.state === "sending") {
|
|
8
|
+
launch.state = "given_up";
|
|
9
|
+
launch.reason = reason;
|
|
10
|
+
launch.decide();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A run the SDK returned after its launch was given up: it did start, so it
|
|
15
|
+
* is stopped, and its end still enters the stream.
|
|
16
|
+
*/
|
|
17
|
+
export function stopOrphan(run, record) {
|
|
18
|
+
void (async () => {
|
|
19
|
+
try {
|
|
20
|
+
await run.cancel();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// It may have ended on its own.
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
record(cursorRunResultFrame(await run.wait()));
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
record(cursorRunFailedFrame(error instanceof Error ? error.message : String(error)));
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
}
|
|
33
|
+
export async function steerRun(current, input) {
|
|
34
|
+
const steer = current.run.steer?.bind(current.run);
|
|
35
|
+
if (steer === undefined) {
|
|
36
|
+
return { kind: "rejected", code: "unsupported", reason: "not_steerable: this cursor run takes no mid-run input" };
|
|
37
|
+
}
|
|
38
|
+
// `run.steer` settles once the agent took the text ("complete_delivered")
|
|
39
|
+
// or handed it back ("revert_to_followup"); a run that ends first must
|
|
40
|
+
// not leave the request unanswered, and a steer it outran must not reject
|
|
41
|
+
// unobserved.
|
|
42
|
+
const delivery = (async () => {
|
|
43
|
+
try {
|
|
44
|
+
return await steer(input);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
const runEnded = (async () => {
|
|
51
|
+
await current.ended;
|
|
52
|
+
return null;
|
|
53
|
+
})();
|
|
54
|
+
const ack = await Promise.race([delivery, runEnded]);
|
|
55
|
+
if (ack instanceof Error) {
|
|
56
|
+
throw ack;
|
|
57
|
+
}
|
|
58
|
+
if (ack === "complete_delivered") {
|
|
59
|
+
return { kind: "accepted", native: { ack } };
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
kind: "rejected",
|
|
63
|
+
code: "runtime_refused",
|
|
64
|
+
reason: ack === null ? "not_steerable: the run ended before cursor took the input" : `not_steerable: cursor handed the input back (${ack})`,
|
|
65
|
+
...(ack === null ? {} : { native: { ack } }),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/runtimes/cursor/run.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAoB,MAAM,iBAAiB,CAAC;AA0B/F,MAAM,UAAU,SAAS;IACvB,MAAM,EAAE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AG,EAAE,EAAE,CAAC;KAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ModelListItem, ModelSelection, RunResult, SDKUserMessage, SteerAckOutcome } from "@cursor/sdk";
|
|
2
|
+
export type { ModelListItem, ModelSelection, RunResult, SteerAckOutcome } from "@cursor/sdk";
|
|
3
|
+
export type CursorDeltaListener = (args: {
|
|
4
|
+
readonly update: unknown;
|
|
5
|
+
}) => void;
|
|
6
|
+
/** One send: a run of the agent loop until the agent ends it. */
|
|
7
|
+
export interface CursorRun {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
/** Settles with the run's status once it ends (finished, error or cancelled). */
|
|
10
|
+
wait(): Promise<RunResult>;
|
|
11
|
+
cancel(): Promise<void>;
|
|
12
|
+
/** Present on runs that take mid-run input; settles once the agent took the text or handed it back. */
|
|
13
|
+
steer?(text: string): Promise<SteerAckOutcome>;
|
|
14
|
+
}
|
|
15
|
+
export interface CursorAgent {
|
|
16
|
+
readonly agentId: string;
|
|
17
|
+
readonly model: ModelSelection | undefined;
|
|
18
|
+
/** `local.force` takes the agent over from a run its store still holds as active. */
|
|
19
|
+
send(message: string | SDKUserMessage, options: {
|
|
20
|
+
readonly onDelta: CursorDeltaListener;
|
|
21
|
+
readonly local?: {
|
|
22
|
+
readonly force: boolean;
|
|
23
|
+
};
|
|
24
|
+
}): Promise<CursorRun>;
|
|
25
|
+
close(): void;
|
|
26
|
+
}
|
|
27
|
+
export interface CursorAgentOptions {
|
|
28
|
+
readonly model: ModelSelection;
|
|
29
|
+
readonly local: {
|
|
30
|
+
readonly cwd: string;
|
|
31
|
+
readonly sandboxOptions: {
|
|
32
|
+
readonly enabled: boolean;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface CursorSdk {
|
|
37
|
+
readonly Agent: {
|
|
38
|
+
create(options: CursorAgentOptions): Promise<CursorAgent>;
|
|
39
|
+
resume(agentId: string, options: CursorAgentOptions): Promise<CursorAgent>;
|
|
40
|
+
listRuns(agentId: string, options: {
|
|
41
|
+
readonly runtime: "local";
|
|
42
|
+
readonly cwd: string;
|
|
43
|
+
readonly cursor?: string;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
readonly items: readonly {
|
|
46
|
+
readonly model?: ModelSelection;
|
|
47
|
+
readonly createdAt?: number;
|
|
48
|
+
}[];
|
|
49
|
+
readonly nextCursor?: string;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
readonly Cursor: {
|
|
53
|
+
readonly models: {
|
|
54
|
+
list(): Promise<readonly ModelListItem[]>;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The SDK is loaded on first use, not with OAR: it is a large bundle with a
|
|
60
|
+
* native companion package per platform, and a host that never opens cursor
|
|
61
|
+
* should not pay for it.
|
|
62
|
+
*/
|
|
63
|
+
export declare function loadCursorSdk(): Promise<CursorSdk>;
|
|
64
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../../src/runtimes/cursor/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE7G,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAS7F,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,KAAK,IAAI,CAAC;AAE/E,iEAAiE;AACjE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,IAAI,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3B,MAAM,IAAI,OAA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,CAAC;YACzH,QAAQ,CAAC,KAAK,EAAE,SAAS;gBAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;gBAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;aAAE,EAAE,CAAC;YAC5F,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;SAC9B,CAAC,CAAC;KACJ,CAAC;IACF,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,MAAM,EAAE;YAAE,IAAI,IAAI,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAA;SAAE,CAAC;KAChE,CAAC;CACH;AAyCD;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,SAAS,CAAC,CAIxD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
let loading = null;
|
|
4
|
+
/**
|
|
5
|
+
* The SDK's native companion (`@cursor/sdk-<platform>-<arch>`: ripgrep and
|
|
6
|
+
* the tree-sitter shell parser) is found by walking up from the host's entry
|
|
7
|
+
* script for `node_modules/<package>`, which misses it in any layout that
|
|
8
|
+
* does not hoist it (pnpm's, a bundled host): the agent then warns "tree-sitter
|
|
9
|
+
* natives are unavailable" and searches without its own ripgrep. Resolved
|
|
10
|
+
* from the SDK itself, the package is found wherever it was installed, and
|
|
11
|
+
* the SDK's own variables point at it, unless the host set them.
|
|
12
|
+
*/
|
|
13
|
+
function nativePackageRoot() {
|
|
14
|
+
try {
|
|
15
|
+
const fromSdk = createRequire(import.meta.resolve("@cursor/sdk"));
|
|
16
|
+
return path.dirname(fromSdk.resolve(`@cursor/sdk-${process.platform}-${process.arch}/package.json`));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function pointSdkAtNativePackage() {
|
|
23
|
+
const root = nativePackageRoot();
|
|
24
|
+
if (root === null) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
process.env.CURSOR_TREE_SITTER_VENDOR_DIR ??= path.join(root, "vendor");
|
|
28
|
+
process.env.CURSOR_RIPGREP_PATH ??= path.join(root, "bin", process.platform === "win32" ? "rg.exe" : "rg");
|
|
29
|
+
}
|
|
30
|
+
async function importSdk() {
|
|
31
|
+
try {
|
|
32
|
+
pointSdkAtNativePackage();
|
|
33
|
+
return await import("@cursor/sdk");
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
loading = null;
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The SDK is loaded on first use, not with OAR: it is a large bundle with a
|
|
42
|
+
* native companion package per platform, and a host that never opens cursor
|
|
43
|
+
* should not pay for it.
|
|
44
|
+
*/
|
|
45
|
+
export async function loadCursorSdk() {
|
|
46
|
+
loading ??= importSdk();
|
|
47
|
+
const sdk = await loading;
|
|
48
|
+
return sdk;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../../src/runtimes/cursor/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAmD7B,IAAI,OAAO,GAA8B,IAAI,CAAC;AAE9C;;;;;;;;GAQG;AACH,SAAS,iBAAiB;IACxB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC;IACvG,CAAC;IAAC,MAAM,CAAC;QACP,O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