@workerdeck/core 2.2.0 → 2.3.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/build/index.d.mts +3 -0
- package/build/index.mjs +82 -2
- package/build/index.mjs.map +1 -1
- package/package.json +3 -3
package/build/index.d.mts
CHANGED
|
@@ -139,6 +139,7 @@ type SessionInfoFn = (sdkSessionId: string, options: {
|
|
|
139
139
|
dir?: string;
|
|
140
140
|
}) => Promise<SDKSessionInfo | undefined>;
|
|
141
141
|
type SessionRunnerConfig = CreateSessionRequest & {
|
|
142
|
+
epoch?: number;
|
|
142
143
|
queryFn?: QueryFn;
|
|
143
144
|
env?: Record<string, string | undefined>;
|
|
144
145
|
pathToClaudeCodeExecutable?: string;
|
|
@@ -189,6 +190,7 @@ declare function truncateResultBlocks(event: SessionEvent): SessionEvent;
|
|
|
189
190
|
//#endregion
|
|
190
191
|
//#region src/engines/provider/runner.d.ts
|
|
191
192
|
type AiSdkRunnerConfig = Omit<CreateSessionRequest, 'cwd'> & {
|
|
193
|
+
epoch?: number;
|
|
192
194
|
cwd?: string;
|
|
193
195
|
languageModel: LanguageModel$1;
|
|
194
196
|
tools?: ToolSet$1;
|
|
@@ -753,6 +755,7 @@ declare const CODEX_CATALOG: ModelCatalog;
|
|
|
753
755
|
//#endregion
|
|
754
756
|
//#region src/engines/codex/runner.d.ts
|
|
755
757
|
type CodexRunnerConfig = CreateSessionRequest & {
|
|
758
|
+
epoch?: number;
|
|
756
759
|
connectFn: AppServerConnectFn;
|
|
757
760
|
env?: Record<string, string | undefined>;
|
|
758
761
|
codexHome?: string;
|
package/build/index.mjs
CHANGED
|
@@ -924,6 +924,9 @@ var SessionRunner = class {
|
|
|
924
924
|
#numTurns;
|
|
925
925
|
#input = new InputQueue();
|
|
926
926
|
#pendingLocalCommands = [];
|
|
927
|
+
#compactionId;
|
|
928
|
+
#compactionTurns = 0;
|
|
929
|
+
#idleWhileCompacting = false;
|
|
927
930
|
#query;
|
|
928
931
|
#capabilitiesEmitted = false;
|
|
929
932
|
#subscriptionType;
|
|
@@ -968,6 +971,7 @@ var SessionRunner = class {
|
|
|
968
971
|
canBypassPermissions: this.#config.permissionMode === "bypassPermissions" || this.#config.allowDangerouslySkipPermissions === true,
|
|
969
972
|
apiKeySource: this.#apiKeySource,
|
|
970
973
|
createdAt: this.createdAt,
|
|
974
|
+
epoch: this.#config.epoch,
|
|
971
975
|
lastSeq: this.#log.seq,
|
|
972
976
|
activityCount: this.#log.activityCount,
|
|
973
977
|
proseCount: this.#log.proseCount,
|
|
@@ -1250,6 +1254,17 @@ var SessionRunner = class {
|
|
|
1250
1254
|
else if (msg.state === "running") this.#setStatus("running");
|
|
1251
1255
|
return;
|
|
1252
1256
|
}
|
|
1257
|
+
if (msg.type === "system" && msg.subtype === "status") this.#handleCompactionStatus(msg);
|
|
1258
|
+
if (msg.type === "system" && msg.subtype === "compact_boundary") {
|
|
1259
|
+
const meta = msg.compact_metadata;
|
|
1260
|
+
this.#settleCompaction({
|
|
1261
|
+
trigger: meta.trigger,
|
|
1262
|
+
preTokens: meta.pre_tokens,
|
|
1263
|
+
postTokens: meta.post_tokens
|
|
1264
|
+
}, msg.uuid);
|
|
1265
|
+
this.#fetchContextUsage();
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1253
1268
|
const body = normalizeSdkMessage(msg);
|
|
1254
1269
|
if (body) {
|
|
1255
1270
|
this.#emit(body);
|
|
@@ -1259,6 +1274,8 @@ var SessionRunner = class {
|
|
|
1259
1274
|
this.#fetchContextUsage();
|
|
1260
1275
|
}
|
|
1261
1276
|
if (body.type === "turn_result") {
|
|
1277
|
+
this.#compactionTurns += 1;
|
|
1278
|
+
if (this.#compactionTurns > 1) this.#settleCompaction();
|
|
1262
1279
|
this.#totalCostUsd = body.totalCostUsd;
|
|
1263
1280
|
this.#numTurns = body.numTurns;
|
|
1264
1281
|
if (this.#pending.size === 0) this.#setStatus("idle");
|
|
@@ -1269,6 +1286,32 @@ var SessionRunner = class {
|
|
|
1269
1286
|
}
|
|
1270
1287
|
}
|
|
1271
1288
|
}
|
|
1289
|
+
#handleCompactionStatus(msg) {
|
|
1290
|
+
if (msg.status === "compacting") {
|
|
1291
|
+
this.#compactionId ??= randomUUID();
|
|
1292
|
+
this.#compactionTurns = 0;
|
|
1293
|
+
this.#emit({
|
|
1294
|
+
type: "context_compacted",
|
|
1295
|
+
uuid: this.#compactionId,
|
|
1296
|
+
pending: true
|
|
1297
|
+
});
|
|
1298
|
+
this.#setStatus("running");
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
if (msg.compact_result === "failed") this.#settleCompaction({ error: msg.compact_error ?? "the engine reported no reason" });
|
|
1302
|
+
}
|
|
1303
|
+
#settleCompaction(settled = {}, boundaryUuid) {
|
|
1304
|
+
const uuid = this.#compactionId ?? boundaryUuid;
|
|
1305
|
+
if (uuid === void 0) return;
|
|
1306
|
+
this.#compactionId = void 0;
|
|
1307
|
+
this.#emit({
|
|
1308
|
+
type: "context_compacted",
|
|
1309
|
+
uuid,
|
|
1310
|
+
...settled
|
|
1311
|
+
});
|
|
1312
|
+
if (this.#idleWhileCompacting && this.#pending.size === 0) this.#setStatus("idle");
|
|
1313
|
+
this.#idleWhileCompacting = false;
|
|
1314
|
+
}
|
|
1272
1315
|
async #fetchToolTitles() {
|
|
1273
1316
|
const servers = await this.mcpServers().catch(() => void 0);
|
|
1274
1317
|
if (this.#closed || !servers) return;
|
|
@@ -1464,6 +1507,11 @@ var SessionRunner = class {
|
|
|
1464
1507
|
}
|
|
1465
1508
|
}
|
|
1466
1509
|
#setStatus(status, detail) {
|
|
1510
|
+
if (status === "idle" && this.#compactionId !== void 0) {
|
|
1511
|
+
this.#idleWhileCompacting = true;
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
this.#idleWhileCompacting = false;
|
|
1467
1515
|
if (this.#status === status && this.#statusDetail === detail) return;
|
|
1468
1516
|
if (this.#status === "closed" || this.#status === "failed") return;
|
|
1469
1517
|
this.#status = status;
|
|
@@ -1595,6 +1643,7 @@ var AiSdkRunner = class {
|
|
|
1595
1643
|
model: this.#modelId(),
|
|
1596
1644
|
permissionMode: this.#permissionMode,
|
|
1597
1645
|
createdAt: this.createdAt,
|
|
1646
|
+
epoch: this.#config.epoch,
|
|
1598
1647
|
lastSeq: this.#log.seq,
|
|
1599
1648
|
activityCount: this.#log.activityCount,
|
|
1600
1649
|
proseCount: this.#log.proseCount,
|
|
@@ -1771,7 +1820,7 @@ var AiSdkRunner = class {
|
|
|
1771
1820
|
behavior: "allow",
|
|
1772
1821
|
resolvedBy: source
|
|
1773
1822
|
});
|
|
1774
|
-
this.#dispatchSingle(approval.toolCallId);
|
|
1823
|
+
this.#dispatchSingle(approval.toolCallId, decision.updatedInput);
|
|
1775
1824
|
} else {
|
|
1776
1825
|
const message = decision.message ?? "Permission denied by user";
|
|
1777
1826
|
this.#emit({
|
|
@@ -1972,15 +2021,32 @@ var AiSdkRunner = class {
|
|
|
1972
2021
|
if (anyAwaiting) this.#setStatus("awaiting_approval");
|
|
1973
2022
|
if (anyDeferred) Promise.allSettled(inFlight).then(() => this.#announceParked());
|
|
1974
2023
|
}
|
|
1975
|
-
#dispatchSingle(toolCallId) {
|
|
2024
|
+
#dispatchSingle(toolCallId, updatedInput) {
|
|
1976
2025
|
const executor = this.#config.executor;
|
|
1977
2026
|
if (!executor) return;
|
|
1978
2027
|
const call = this.#pendingToolCalls.get(toolCallId);
|
|
1979
2028
|
if (!call || this.#dispatched.has(toolCallId)) return;
|
|
2029
|
+
if (updatedInput !== void 0) this.#amendToolInput(call, updatedInput);
|
|
1980
2030
|
this.#dispatched.add(toolCallId);
|
|
1981
2031
|
const dispatched = this.#dispatchCall(executor, call);
|
|
1982
2032
|
if (dispatched.deferred) dispatched.promise.then(() => this.#announceParked());
|
|
1983
2033
|
}
|
|
2034
|
+
#amendToolInput(call, input) {
|
|
2035
|
+
call.input = input;
|
|
2036
|
+
for (let i = this.#messages.length - 1; i >= 0; i--) {
|
|
2037
|
+
const message = this.#messages[i];
|
|
2038
|
+
if (message.role !== "assistant" || !Array.isArray(message.content) || !message.content.some((part) => callsTool(part, call.toolCallId))) continue;
|
|
2039
|
+
const content = message.content.map((part) => callsTool(part, call.toolCallId) ? {
|
|
2040
|
+
...part,
|
|
2041
|
+
input
|
|
2042
|
+
} : part);
|
|
2043
|
+
this.#messages[i] = {
|
|
2044
|
+
...message,
|
|
2045
|
+
content
|
|
2046
|
+
};
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
1984
2050
|
#dispatchCall(executor, call) {
|
|
1985
2051
|
const toolCall = {
|
|
1986
2052
|
executionId: call.toolCallId,
|
|
@@ -2324,6 +2390,9 @@ function textValue(output) {
|
|
|
2324
2390
|
function errorText(error) {
|
|
2325
2391
|
return error instanceof Error ? error.message : String(error);
|
|
2326
2392
|
}
|
|
2393
|
+
function callsTool(part, toolCallId) {
|
|
2394
|
+
return part.type === "tool-call" && part.toolCallId === toolCallId;
|
|
2395
|
+
}
|
|
2327
2396
|
//#endregion
|
|
2328
2397
|
//#region src/engines/claude/auth.ts
|
|
2329
2398
|
function resolveBundledClaudeExecutable() {
|
|
@@ -4196,6 +4265,7 @@ var CodexRunner = class {
|
|
|
4196
4265
|
permissionMode: this.#permissionMode,
|
|
4197
4266
|
canBypassPermissions: true,
|
|
4198
4267
|
createdAt: this.createdAt,
|
|
4268
|
+
epoch: this.#config.epoch,
|
|
4199
4269
|
lastSeq: this.#log.seq,
|
|
4200
4270
|
activityCount: this.#log.activityCount,
|
|
4201
4271
|
proseCount: this.#log.proseCount,
|
|
@@ -5015,6 +5085,16 @@ var CodexRunner = class {
|
|
|
5015
5085
|
this.#emitToolUse(id, `mcp__${item.server}__${item.tool}`, item.arguments, agent);
|
|
5016
5086
|
return;
|
|
5017
5087
|
}
|
|
5088
|
+
if (item.type === "contextCompaction" && !active.toolUseEmitted.has(id)) {
|
|
5089
|
+
active.toolUseEmitted.add(id);
|
|
5090
|
+
this.#emit({
|
|
5091
|
+
type: "context_compacted",
|
|
5092
|
+
uuid: id,
|
|
5093
|
+
pending: true,
|
|
5094
|
+
parentToolUseId: agent?.toolUseId ?? null
|
|
5095
|
+
});
|
|
5096
|
+
return;
|
|
5097
|
+
}
|
|
5018
5098
|
if (item.type === "collabAgentToolCall" && !active.toolUseEmitted.has(id)) {
|
|
5019
5099
|
active.toolUseEmitted.add(id);
|
|
5020
5100
|
this.#emitToolUse(id, CODEX_COLLAB_TOOL, collabInput(item), agent);
|