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.cjs
CHANGED
|
@@ -1094,10 +1094,7 @@ async function createSession(config) {
|
|
|
1094
1094
|
stateManager.run();
|
|
1095
1095
|
}
|
|
1096
1096
|
);
|
|
1097
|
-
const lifecycle = resolveSessionLifecycle(
|
|
1098
|
-
sandboxInit,
|
|
1099
|
-
sandboxShutdown
|
|
1100
|
-
);
|
|
1097
|
+
const lifecycle = resolveSessionLifecycle(sandboxInit, sandboxShutdown);
|
|
1101
1098
|
const sandboxMode = lifecycle.mode;
|
|
1102
1099
|
const resolvedShutdown = lifecycle.shutdown;
|
|
1103
1100
|
let sandboxId;
|
|
@@ -1172,6 +1169,34 @@ async function createSession(config) {
|
|
|
1172
1169
|
...baseSnapshot && { baseSnapshot }
|
|
1173
1170
|
});
|
|
1174
1171
|
}
|
|
1172
|
+
const sessionStartMs = Date.now();
|
|
1173
|
+
const systemPrompt = stateManager.getSystemPrompt();
|
|
1174
|
+
const rehydrateFromSlice = (slice) => {
|
|
1175
|
+
stateManager.mergeUpdate({
|
|
1176
|
+
tasks: new Map(slice.tasks),
|
|
1177
|
+
...slice.custom
|
|
1178
|
+
});
|
|
1179
|
+
};
|
|
1180
|
+
if (threadMode === "fork" && sourceThreadId) {
|
|
1181
|
+
await forkThread(sourceThreadId, threadId, threadKey);
|
|
1182
|
+
const forkedSlice = await loadThreadState(threadId, threadKey);
|
|
1183
|
+
if (forkedSlice) rehydrateFromSlice(forkedSlice);
|
|
1184
|
+
} else if (threadMode === "continue") {
|
|
1185
|
+
const continuedSlice = await loadThreadState(threadId, threadKey);
|
|
1186
|
+
if (continuedSlice) rehydrateFromSlice(continuedSlice);
|
|
1187
|
+
} else {
|
|
1188
|
+
if (appendSystemPrompt) {
|
|
1189
|
+
if (systemPrompt == null || typeof systemPrompt === "string" && systemPrompt.trim() === "") {
|
|
1190
|
+
throw workflow.ApplicationFailure.create({
|
|
1191
|
+
message: "No system prompt in state",
|
|
1192
|
+
nonRetryable: true
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
await appendSystemMessage(threadId, workflow.uuid4(), systemPrompt, threadKey);
|
|
1196
|
+
} else {
|
|
1197
|
+
await initializeThread(threadId, threadKey);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1175
1200
|
if (virtualFsConfig) {
|
|
1176
1201
|
if (!virtualFsOps) {
|
|
1177
1202
|
throw workflow.ApplicationFailure.create({
|
|
@@ -1208,6 +1233,14 @@ async function createSession(config) {
|
|
|
1208
1233
|
...skillFiles && { inlineFiles: skillFiles }
|
|
1209
1234
|
});
|
|
1210
1235
|
}
|
|
1236
|
+
await appendHumanMessage(
|
|
1237
|
+
threadId,
|
|
1238
|
+
workflow.uuid4(),
|
|
1239
|
+
await buildContextMessage(),
|
|
1240
|
+
threadKey
|
|
1241
|
+
);
|
|
1242
|
+
let exitReason = "completed";
|
|
1243
|
+
let finalMessage = null;
|
|
1211
1244
|
if (hooks.onSessionStart) {
|
|
1212
1245
|
await hooks.onSessionStart({
|
|
1213
1246
|
threadId,
|
|
@@ -1222,42 +1255,6 @@ async function createSession(config) {
|
|
|
1222
1255
|
maxTurns,
|
|
1223
1256
|
...sandboxId && { sandboxId }
|
|
1224
1257
|
});
|
|
1225
|
-
const sessionStartMs = Date.now();
|
|
1226
|
-
const systemPrompt = stateManager.getSystemPrompt();
|
|
1227
|
-
const rehydrateFromSlice = (slice) => {
|
|
1228
|
-
stateManager.mergeUpdate({
|
|
1229
|
-
tasks: new Map(slice.tasks),
|
|
1230
|
-
...slice.custom
|
|
1231
|
-
});
|
|
1232
|
-
};
|
|
1233
|
-
if (threadMode === "fork" && sourceThreadId) {
|
|
1234
|
-
await forkThread(sourceThreadId, threadId, threadKey);
|
|
1235
|
-
const forkedSlice = await loadThreadState(threadId, threadKey);
|
|
1236
|
-
if (forkedSlice) rehydrateFromSlice(forkedSlice);
|
|
1237
|
-
} else if (threadMode === "continue") {
|
|
1238
|
-
const continuedSlice = await loadThreadState(threadId, threadKey);
|
|
1239
|
-
if (continuedSlice) rehydrateFromSlice(continuedSlice);
|
|
1240
|
-
} else {
|
|
1241
|
-
if (appendSystemPrompt) {
|
|
1242
|
-
if (systemPrompt == null || typeof systemPrompt === "string" && systemPrompt.trim() === "") {
|
|
1243
|
-
throw workflow.ApplicationFailure.create({
|
|
1244
|
-
message: "No system prompt in state",
|
|
1245
|
-
nonRetryable: true
|
|
1246
|
-
});
|
|
1247
|
-
}
|
|
1248
|
-
await appendSystemMessage(threadId, workflow.uuid4(), systemPrompt, threadKey);
|
|
1249
|
-
} else {
|
|
1250
|
-
await initializeThread(threadId, threadKey);
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
await appendHumanMessage(
|
|
1254
|
-
threadId,
|
|
1255
|
-
workflow.uuid4(),
|
|
1256
|
-
await buildContextMessage(),
|
|
1257
|
-
threadKey
|
|
1258
|
-
);
|
|
1259
|
-
let exitReason = "completed";
|
|
1260
|
-
let finalMessage = null;
|
|
1261
1258
|
try {
|
|
1262
1259
|
let assistantId;
|
|
1263
1260
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
@@ -1451,6 +1448,22 @@ function getThreadMetaKey(threadKey, threadId) {
|
|
|
1451
1448
|
function isTerminalStatus(status) {
|
|
1452
1449
|
return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
|
|
1453
1450
|
}
|
|
1451
|
+
var RESERVED_STATE_KEYS = [
|
|
1452
|
+
"status",
|
|
1453
|
+
"version",
|
|
1454
|
+
"turns",
|
|
1455
|
+
"tasks",
|
|
1456
|
+
"tools",
|
|
1457
|
+
"systemPrompt",
|
|
1458
|
+
"fileTree",
|
|
1459
|
+
"inlineFiles",
|
|
1460
|
+
"virtualFsCtx",
|
|
1461
|
+
"totalInputTokens",
|
|
1462
|
+
"totalOutputTokens",
|
|
1463
|
+
"totalReasonTokens",
|
|
1464
|
+
"cachedWriteTokens",
|
|
1465
|
+
"cachedReadTokens"
|
|
1466
|
+
];
|
|
1454
1467
|
function createAgentStateManager({
|
|
1455
1468
|
initialState
|
|
1456
1469
|
}) {
|
|
@@ -1604,9 +1617,16 @@ function createAgentStateManager({
|
|
|
1604
1617
|
return deleted;
|
|
1605
1618
|
},
|
|
1606
1619
|
getPersistedSlice() {
|
|
1620
|
+
const source = customState;
|
|
1621
|
+
const custom2 = {};
|
|
1622
|
+
const reserved = new Set(RESERVED_STATE_KEYS);
|
|
1623
|
+
for (const [key, value] of Object.entries(source)) {
|
|
1624
|
+
if (reserved.has(key)) continue;
|
|
1625
|
+
custom2[key] = value;
|
|
1626
|
+
}
|
|
1607
1627
|
return {
|
|
1608
1628
|
tasks: Array.from(tasks.entries()),
|
|
1609
|
-
custom:
|
|
1629
|
+
custom: custom2
|
|
1610
1630
|
};
|
|
1611
1631
|
},
|
|
1612
1632
|
updateUsage(usage) {
|