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 CHANGED
@@ -1098,10 +1098,7 @@ async function createSession(config) {
1098
1098
  stateManager.run();
1099
1099
  }
1100
1100
  );
1101
- const lifecycle = resolveSessionLifecycle(
1102
- sandboxInit,
1103
- sandboxShutdown
1104
- );
1101
+ const lifecycle = resolveSessionLifecycle(sandboxInit, sandboxShutdown);
1105
1102
  const sandboxMode = lifecycle.mode;
1106
1103
  const resolvedShutdown = lifecycle.shutdown;
1107
1104
  let sandboxId;
@@ -1176,6 +1173,34 @@ async function createSession(config) {
1176
1173
  ...baseSnapshot && { baseSnapshot }
1177
1174
  });
1178
1175
  }
1176
+ const sessionStartMs = Date.now();
1177
+ const systemPrompt = stateManager.getSystemPrompt();
1178
+ const rehydrateFromSlice = (slice) => {
1179
+ stateManager.mergeUpdate({
1180
+ tasks: new Map(slice.tasks),
1181
+ ...slice.custom
1182
+ });
1183
+ };
1184
+ if (threadMode === "fork" && sourceThreadId) {
1185
+ await forkThread(sourceThreadId, threadId, threadKey);
1186
+ const forkedSlice = await loadThreadState(threadId, threadKey);
1187
+ if (forkedSlice) rehydrateFromSlice(forkedSlice);
1188
+ } else if (threadMode === "continue") {
1189
+ const continuedSlice = await loadThreadState(threadId, threadKey);
1190
+ if (continuedSlice) rehydrateFromSlice(continuedSlice);
1191
+ } else {
1192
+ if (appendSystemPrompt) {
1193
+ if (systemPrompt == null || typeof systemPrompt === "string" && systemPrompt.trim() === "") {
1194
+ throw workflow.ApplicationFailure.create({
1195
+ message: "No system prompt in state",
1196
+ nonRetryable: true
1197
+ });
1198
+ }
1199
+ await appendSystemMessage(threadId, workflow.uuid4(), systemPrompt, threadKey);
1200
+ } else {
1201
+ await initializeThread(threadId, threadKey);
1202
+ }
1203
+ }
1179
1204
  if (virtualFsConfig) {
1180
1205
  if (!virtualFsOps) {
1181
1206
  throw workflow.ApplicationFailure.create({
@@ -1212,6 +1237,14 @@ async function createSession(config) {
1212
1237
  ...skillFiles && { inlineFiles: skillFiles }
1213
1238
  });
1214
1239
  }
1240
+ await appendHumanMessage(
1241
+ threadId,
1242
+ workflow.uuid4(),
1243
+ await buildContextMessage(),
1244
+ threadKey
1245
+ );
1246
+ let exitReason = "completed";
1247
+ let finalMessage = null;
1215
1248
  if (hooks.onSessionStart) {
1216
1249
  await hooks.onSessionStart({
1217
1250
  threadId,
@@ -1226,42 +1259,6 @@ async function createSession(config) {
1226
1259
  maxTurns,
1227
1260
  ...sandboxId && { sandboxId }
1228
1261
  });
1229
- const sessionStartMs = Date.now();
1230
- const systemPrompt = stateManager.getSystemPrompt();
1231
- const rehydrateFromSlice = (slice) => {
1232
- stateManager.mergeUpdate({
1233
- tasks: new Map(slice.tasks),
1234
- ...slice.custom
1235
- });
1236
- };
1237
- if (threadMode === "fork" && sourceThreadId) {
1238
- await forkThread(sourceThreadId, threadId, threadKey);
1239
- const forkedSlice = await loadThreadState(threadId, threadKey);
1240
- if (forkedSlice) rehydrateFromSlice(forkedSlice);
1241
- } else if (threadMode === "continue") {
1242
- const continuedSlice = await loadThreadState(threadId, threadKey);
1243
- if (continuedSlice) rehydrateFromSlice(continuedSlice);
1244
- } else {
1245
- if (appendSystemPrompt) {
1246
- if (systemPrompt == null || typeof systemPrompt === "string" && systemPrompt.trim() === "") {
1247
- throw workflow.ApplicationFailure.create({
1248
- message: "No system prompt in state",
1249
- nonRetryable: true
1250
- });
1251
- }
1252
- await appendSystemMessage(threadId, workflow.uuid4(), systemPrompt, threadKey);
1253
- } else {
1254
- await initializeThread(threadId, threadKey);
1255
- }
1256
- }
1257
- await appendHumanMessage(
1258
- threadId,
1259
- workflow.uuid4(),
1260
- await buildContextMessage(),
1261
- threadKey
1262
- );
1263
- let exitReason = "completed";
1264
- let finalMessage = null;
1265
1262
  try {
1266
1263
  let assistantId;
1267
1264
  while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
@@ -1458,6 +1455,22 @@ function getThreadStateKey(threadKey, threadId) {
1458
1455
  function isTerminalStatus(status) {
1459
1456
  return status === "COMPLETED" || status === "FAILED" || status === "CANCELLED";
1460
1457
  }
1458
+ var RESERVED_STATE_KEYS = [
1459
+ "status",
1460
+ "version",
1461
+ "turns",
1462
+ "tasks",
1463
+ "tools",
1464
+ "systemPrompt",
1465
+ "fileTree",
1466
+ "inlineFiles",
1467
+ "virtualFsCtx",
1468
+ "totalInputTokens",
1469
+ "totalOutputTokens",
1470
+ "totalReasonTokens",
1471
+ "cachedWriteTokens",
1472
+ "cachedReadTokens"
1473
+ ];
1461
1474
  function createAgentStateManager({
1462
1475
  initialState
1463
1476
  }) {
@@ -1611,9 +1624,16 @@ function createAgentStateManager({
1611
1624
  return deleted;
1612
1625
  },
1613
1626
  getPersistedSlice() {
1627
+ const source = customState;
1628
+ const custom2 = {};
1629
+ const reserved = new Set(RESERVED_STATE_KEYS);
1630
+ for (const [key, value] of Object.entries(source)) {
1631
+ if (reserved.has(key)) continue;
1632
+ custom2[key] = value;
1633
+ }
1614
1634
  return {
1615
1635
  tasks: Array.from(tasks.entries()),
1616
- custom: { ...customState }
1636
+ custom: custom2
1617
1637
  };
1618
1638
  },
1619
1639
  updateUsage(usage) {