zeitlich 0.2.43 → 0.2.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +61 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -41
- package/dist/index.js.map +1 -1
- package/dist/workflow.cjs +61 -41
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.js +61 -41
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/session/session.ts +53 -51
- package/src/lib/state/manager.integration.test.ts +27 -0
- package/src/lib/state/manager.ts +39 -1
package/dist/workflow.js
CHANGED
|
@@ -1088,10 +1088,7 @@ async function createSession(config) {
|
|
|
1088
1088
|
stateManager.run();
|
|
1089
1089
|
}
|
|
1090
1090
|
);
|
|
1091
|
-
const lifecycle = resolveSessionLifecycle(
|
|
1092
|
-
sandboxInit,
|
|
1093
|
-
sandboxShutdown
|
|
1094
|
-
);
|
|
1091
|
+
const lifecycle = resolveSessionLifecycle(sandboxInit, sandboxShutdown);
|
|
1095
1092
|
const sandboxMode = lifecycle.mode;
|
|
1096
1093
|
const resolvedShutdown = lifecycle.shutdown;
|
|
1097
1094
|
let sandboxId;
|
|
@@ -1166,6 +1163,34 @@ async function createSession(config) {
|
|
|
1166
1163
|
...baseSnapshot && { baseSnapshot }
|
|
1167
1164
|
});
|
|
1168
1165
|
}
|
|
1166
|
+
const sessionStartMs = Date.now();
|
|
1167
|
+
const systemPrompt = stateManager.getSystemPrompt();
|
|
1168
|
+
const rehydrateFromSlice = (slice) => {
|
|
1169
|
+
stateManager.mergeUpdate({
|
|
1170
|
+
tasks: new Map(slice.tasks),
|
|
1171
|
+
...slice.custom
|
|
1172
|
+
});
|
|
1173
|
+
};
|
|
1174
|
+
if (threadMode === "fork" && sourceThreadId) {
|
|
1175
|
+
await forkThread(sourceThreadId, threadId, threadKey);
|
|
1176
|
+
const forkedSlice = await loadThreadState(threadId, threadKey);
|
|
1177
|
+
if (forkedSlice) rehydrateFromSlice(forkedSlice);
|
|
1178
|
+
} else if (threadMode === "continue") {
|
|
1179
|
+
const continuedSlice = await loadThreadState(threadId, threadKey);
|
|
1180
|
+
if (continuedSlice) rehydrateFromSlice(continuedSlice);
|
|
1181
|
+
} else {
|
|
1182
|
+
if (appendSystemPrompt) {
|
|
1183
|
+
if (systemPrompt == null || typeof systemPrompt === "string" && systemPrompt.trim() === "") {
|
|
1184
|
+
throw ApplicationFailure.create({
|
|
1185
|
+
message: "No system prompt in state",
|
|
1186
|
+
nonRetryable: true
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
await appendSystemMessage(threadId, uuid4(), systemPrompt, threadKey);
|
|
1190
|
+
} else {
|
|
1191
|
+
await initializeThread(threadId, threadKey);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1169
1194
|
if (virtualFsConfig) {
|
|
1170
1195
|
if (!virtualFsOps) {
|
|
1171
1196
|
throw ApplicationFailure.create({
|
|
@@ -1202,6 +1227,14 @@ async function createSession(config) {
|
|
|
1202
1227
|
...skillFiles && { inlineFiles: skillFiles }
|
|
1203
1228
|
});
|
|
1204
1229
|
}
|
|
1230
|
+
await appendHumanMessage(
|
|
1231
|
+
threadId,
|
|
1232
|
+
uuid4(),
|
|
1233
|
+
await buildContextMessage(),
|
|
1234
|
+
threadKey
|
|
1235
|
+
);
|
|
1236
|
+
let exitReason = "completed";
|
|
1237
|
+
let finalMessage = null;
|
|
1205
1238
|
if (hooks.onSessionStart) {
|
|
1206
1239
|
await hooks.onSessionStart({
|
|
1207
1240
|
threadId,
|
|
@@ -1216,42 +1249,6 @@ async function createSession(config) {
|
|
|
1216
1249
|
maxTurns,
|
|
1217
1250
|
...sandboxId && { sandboxId }
|
|
1218
1251
|
});
|
|
1219
|
-
const sessionStartMs = Date.now();
|
|
1220
|
-
const systemPrompt = stateManager.getSystemPrompt();
|
|
1221
|
-
const rehydrateFromSlice = (slice) => {
|
|
1222
|
-
stateManager.mergeUpdate({
|
|
1223
|
-
tasks: new Map(slice.tasks),
|
|
1224
|
-
...slice.custom
|
|
1225
|
-
});
|
|
1226
|
-
};
|
|
1227
|
-
if (threadMode === "fork" && sourceThreadId) {
|
|
1228
|
-
await forkThread(sourceThreadId, threadId, threadKey);
|
|
1229
|
-
const forkedSlice = await loadThreadState(threadId, threadKey);
|
|
1230
|
-
if (forkedSlice) rehydrateFromSlice(forkedSlice);
|
|
1231
|
-
} else if (threadMode === "continue") {
|
|
1232
|
-
const continuedSlice = await loadThreadState(threadId, threadKey);
|
|
1233
|
-
if (continuedSlice) rehydrateFromSlice(continuedSlice);
|
|
1234
|
-
} else {
|
|
1235
|
-
if (appendSystemPrompt) {
|
|
1236
|
-
if (systemPrompt == null || typeof systemPrompt === "string" && systemPrompt.trim() === "") {
|
|
1237
|
-
throw ApplicationFailure.create({
|
|
1238
|
-
message: "No system prompt in state",
|
|
1239
|
-
nonRetryable: true
|
|
1240
|
-
});
|
|
1241
|
-
}
|
|
1242
|
-
await appendSystemMessage(threadId, uuid4(), systemPrompt, threadKey);
|
|
1243
|
-
} else {
|
|
1244
|
-
await initializeThread(threadId, threadKey);
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
await appendHumanMessage(
|
|
1248
|
-
threadId,
|
|
1249
|
-
uuid4(),
|
|
1250
|
-
await buildContextMessage(),
|
|
1251
|
-
threadKey
|
|
1252
|
-
);
|
|
1253
|
-
let exitReason = "completed";
|
|
1254
|
-
let finalMessage = null;
|
|
1255
1252
|
try {
|
|
1256
1253
|
let assistantId;
|
|
1257
1254
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
@@ -1445,6 +1442,22 @@ function getThreadMetaKey(threadKey, threadId) {
|
|
|
1445
1442
|
function isTerminalStatus(status) {
|
|
1446
1443
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
1447
1444
|
}
|
|
1445
|
+
var RESERVED_STATE_KEYS = [
|
|
1446
|
+
"status",
|
|
1447
|
+
"version",
|
|
1448
|
+
"turns",
|
|
1449
|
+
"tasks",
|
|
1450
|
+
"tools",
|
|
1451
|
+
"systemPrompt",
|
|
1452
|
+
"fileTree",
|
|
1453
|
+
"inlineFiles",
|
|
1454
|
+
"virtualFsCtx",
|
|
1455
|
+
"totalInputTokens",
|
|
1456
|
+
"totalOutputTokens",
|
|
1457
|
+
"totalReasonTokens",
|
|
1458
|
+
"cachedWriteTokens",
|
|
1459
|
+
"cachedReadTokens"
|
|
1460
|
+
];
|
|
1448
1461
|
function createAgentStateManager({
|
|
1449
1462
|
initialState
|
|
1450
1463
|
}) {
|
|
@@ -1598,9 +1611,16 @@ function createAgentStateManager({
|
|
|
1598
1611
|
return deleted;
|
|
1599
1612
|
},
|
|
1600
1613
|
getPersistedSlice() {
|
|
1614
|
+
const source = customState;
|
|
1615
|
+
const custom2 = {};
|
|
1616
|
+
const reserved = new Set(RESERVED_STATE_KEYS);
|
|
1617
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1618
|
+
if (reserved.has(key)) continue;
|
|
1619
|
+
custom2[key] = value;
|
|
1620
|
+
}
|
|
1601
1621
|
return {
|
|
1602
1622
|
tasks: Array.from(tasks.entries()),
|
|
1603
|
-
custom:
|
|
1623
|
+
custom: custom2
|
|
1604
1624
|
};
|
|
1605
1625
|
},
|
|
1606
1626
|
updateUsage(usage) {
|