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