zeitlich 0.2.40 → 0.2.41

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.
Files changed (64) hide show
  1. package/README.md +12 -1
  2. package/dist/{activities-CULxRzJ1.d.ts → activities-D_g13S3y.d.ts} +2 -2
  3. package/dist/{activities-CvUrG3YG.d.cts → activities-qUflxmfS.d.cts} +2 -2
  4. package/dist/adapters/sandbox/e2b/index.cjs +12 -3
  5. package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
  6. package/dist/adapters/sandbox/e2b/index.d.cts +35 -2
  7. package/dist/adapters/sandbox/e2b/index.d.ts +35 -2
  8. package/dist/adapters/sandbox/e2b/index.js +13 -4
  9. package/dist/adapters/sandbox/e2b/index.js.map +1 -1
  10. package/dist/adapters/thread/anthropic/index.d.cts +5 -5
  11. package/dist/adapters/thread/anthropic/index.d.ts +5 -5
  12. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  13. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  14. package/dist/adapters/thread/google-genai/index.d.cts +5 -5
  15. package/dist/adapters/thread/google-genai/index.d.ts +5 -5
  16. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
  17. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
  18. package/dist/adapters/thread/langchain/index.d.cts +5 -5
  19. package/dist/adapters/thread/langchain/index.d.ts +5 -5
  20. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  21. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  22. package/dist/index.cjs +92 -49
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +35 -9
  25. package/dist/index.d.ts +35 -9
  26. package/dist/index.js +93 -50
  27. package/dist/index.js.map +1 -1
  28. package/dist/{proxy-wZufFfBh.d.ts → proxy-BbcgoXg1.d.ts} +1 -1
  29. package/dist/{proxy-5EbwzaY4.d.cts → proxy-D7mvDEO6.d.cts} +1 -1
  30. package/dist/{thread-manager-BqBAIsED.d.ts → thread-manager-CTXPCu9W.d.ts} +2 -2
  31. package/dist/{thread-manager-BNiIt5r8.d.ts → thread-manager-Dqstsw4i.d.ts} +2 -2
  32. package/dist/{thread-manager-BoN5DOvG.d.cts → thread-manager-DrWfVjlj.d.cts} +2 -2
  33. package/dist/{thread-manager-DF8WuCRs.d.cts → thread-manager-cLhDhRRc.d.cts} +2 -2
  34. package/dist/{types-DeQH84C_.d.ts → types-BqTmyH31.d.ts} +42 -3
  35. package/dist/{types-CuISs0Ub.d.cts → types-CdvcmXb6.d.cts} +1 -1
  36. package/dist/{types-C7OoY7h8.d.ts → types-CjF1_Idx.d.ts} +1 -1
  37. package/dist/{types-Cn2r3ol3.d.cts → types-DjaQKUJx.d.cts} +42 -3
  38. package/dist/{workflow-DhplIN65.d.cts → workflow-CuqxgS6X.d.cts} +1 -1
  39. package/dist/{workflow-C2MZZj5K.d.ts → workflow-N1MNDoul.d.ts} +1 -1
  40. package/dist/workflow.cjs +39 -31
  41. package/dist/workflow.cjs.map +1 -1
  42. package/dist/workflow.d.cts +3 -3
  43. package/dist/workflow.d.ts +3 -3
  44. package/dist/workflow.js +40 -32
  45. package/dist/workflow.js.map +1 -1
  46. package/package.json +15 -6
  47. package/src/adapters/sandbox/e2b/README.md +81 -0
  48. package/src/adapters/sandbox/e2b/index.ts +32 -5
  49. package/src/adapters/sandbox/e2b/keep-alive.test.ts +115 -0
  50. package/src/adapters/sandbox/e2b/types.ts +34 -2
  51. package/src/index.ts +1 -1
  52. package/src/lib/session/session.integration.test.ts +58 -0
  53. package/src/lib/session/session.ts +12 -15
  54. package/src/lib/session/types.ts +8 -3
  55. package/src/lib/subagent/subagent.integration.test.ts +2 -0
  56. package/src/lib/subagent/types.ts +8 -0
  57. package/src/lib/subagent/workflow.ts +11 -1
  58. package/src/lib/tool-router/auto-append-sandbox.integration.test.ts +158 -0
  59. package/src/lib/tool-router/index.ts +1 -1
  60. package/src/lib/tool-router/with-sandbox.ts +45 -2
  61. package/src/lib/virtual-fs/filesystem.ts +41 -16
  62. package/src/lib/virtual-fs/types.ts +19 -0
  63. package/src/lib/virtual-fs/virtual-fs.test.ts +204 -1
  64. package/src/tools/read-file/handler.test.ts +83 -0
@@ -1,5 +1,5 @@
1
1
  import { proxyActivities, ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from './types-DeQH84C_.js';
2
+ import { T as ThreadOps } from './types-BqTmyH31.js';
3
3
 
4
4
  /**
5
5
  * Shared proxy helper for thread operations.
@@ -1,5 +1,5 @@
1
1
  import { proxyActivities, ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from './types-Cn2r3ol3.cjs';
2
+ import { T as ThreadOps } from './types-DjaQKUJx.cjs';
3
3
 
4
4
  /**
5
5
  * Shared proxy helper for thread operations.
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
- import { J as JsonValue } from './types-DeQH84C_.js';
2
+ import { J as JsonValue } from './types-BqTmyH31.js';
3
3
  import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-C7OoY7h8.js';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CjF1_Idx.js';
5
5
 
6
6
  /** SDK-native content type for LangChain human messages */
7
7
  type LangChainContent = string | MessageContent;
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { J as JsonValue } from './types-DeQH84C_.js';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-C7OoY7h8.js';
3
+ import { J as JsonValue } from './types-BqTmyH31.js';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CjF1_Idx.js';
5
5
 
6
6
  /** SDK-native content type for Anthropic human messages */
7
7
  type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
- import { J as JsonValue } from './types-Cn2r3ol3.cjs';
2
+ import { J as JsonValue } from './types-DjaQKUJx.cjs';
3
3
  import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CuISs0Ub.cjs';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CdvcmXb6.cjs';
5
5
 
6
6
  /** SDK-native content type for LangChain human messages */
7
7
  type LangChainContent = string | MessageContent;
@@ -1,7 +1,7 @@
1
1
  import Redis from 'ioredis';
2
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { J as JsonValue } from './types-Cn2r3ol3.cjs';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CuISs0Ub.cjs';
3
+ import { J as JsonValue } from './types-DjaQKUJx.cjs';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CdvcmXb6.cjs';
5
5
 
6
6
  /** SDK-native content type for Anthropic human messages */
7
7
  type AnthropicContent = string | Anthropic.Messages.ContentBlockParam[];
@@ -1,4 +1,3 @@
1
- import { Duration } from '@temporalio/common';
2
1
  import { ActivityFunctionWithOptions, QueryDefinition, ChildWorkflowOptions, ActivityInterfaceFor } from '@temporalio/workflow';
3
2
  import { UpdateDefinition } from '@temporalio/common/lib/interfaces';
4
3
  import { z } from 'zod';
@@ -544,6 +543,13 @@ declare class VirtualFileSystem<TCtx = unknown, TMeta = FileEntryMetadata> imple
544
543
  getEntry(path: string): FileEntry<TMeta> | undefined;
545
544
  readFile(path: string): Promise<string>;
546
545
  readFileBuffer(path: string): Promise<Uint8Array>;
546
+ /**
547
+ * Resolve the string content for an entry, preferring inline content
548
+ * carried on the entry itself before consulting the resolver. Used by
549
+ * `readFile`, `appendFile`, and `cp` so all read paths agree on the
550
+ * lookup precedence.
551
+ */
552
+ private readEntryContent;
547
553
  exists(path: string): Promise<boolean>;
548
554
  stat(path: string): Promise<FileStat>;
549
555
  readdir(path: string): Promise<string[]>;
@@ -577,6 +583,25 @@ interface FileEntry<TMeta = FileEntryMetadata> {
577
583
  /** ISO-8601 date string (JSON-safe) */
578
584
  mtime: string;
579
585
  metadata: TMeta;
586
+ /**
587
+ * Optional inline content carried directly on the entry. When present the
588
+ * {@link VirtualFileSystem} returns this string from `readFile` /
589
+ * `readFileBuffer` (and uses it as the source for `cp` / `appendFile`)
590
+ * without consulting the resolver.
591
+ *
592
+ * Use this for files that exist purely in workflow state and have no
593
+ * backing in the consumer's data layer (e.g. skill resources bundled at
594
+ * session creation time). Because the content travels with the entry,
595
+ * any tool handler that constructs a `VirtualFileSystem` from `fileTree`
596
+ * sees the same content — no separate `inlineFiles` plumbing required.
597
+ *
598
+ * Read-only: entries with `inlineContent` reject in-place mutations
599
+ * (`writeFile`, `appendFile`, `rm`, `mv` of the entry, `cp` over the
600
+ * entry as destination). The resolver has no contract for the synthetic
601
+ * `id` these entries carry, so attempting a mutation throws an `EROFS`
602
+ * error instead of silently routing a doomed call through the resolver.
603
+ */
604
+ inlineContent?: string;
580
605
  }
581
606
  /**
582
607
  * Flat list of file entries.
@@ -1145,6 +1170,14 @@ interface SubagentSessionInput {
1145
1170
  sandboxId?: string;
1146
1171
  snapshot?: SandboxSnapshot;
1147
1172
  threadId: string;
1173
+ usage: {
1174
+ totalInputTokens: number;
1175
+ totalOutputTokens: number;
1176
+ totalCachedWriteTokens: number;
1177
+ totalCachedReadTokens: number;
1178
+ totalReasonTokens: number;
1179
+ turns: number;
1180
+ };
1148
1181
  }) => void;
1149
1182
  }
1150
1183
 
@@ -1351,8 +1384,6 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
1351
1384
  * Returns SDK-native content for the initial human message.
1352
1385
  */
1353
1386
  buildContextMessage: () => TContent | Promise<TContent>;
1354
- /** How long to wait for input before cancelling the workflow */
1355
- waitForInputTimeout?: Duration;
1356
1387
  /**
1357
1388
  * Thread initialization strategy (default: `{ mode: "new" }`).
1358
1389
  *
@@ -1412,6 +1443,14 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
1412
1443
  threadId: string;
1413
1444
  sandboxId?: string;
1414
1445
  snapshot?: SandboxSnapshot;
1446
+ usage: {
1447
+ totalInputTokens: number;
1448
+ totalOutputTokens: number;
1449
+ totalCachedWriteTokens: number;
1450
+ totalCachedReadTokens: number;
1451
+ totalReasonTokens: number;
1452
+ turns: number;
1453
+ };
1415
1454
  }) => void;
1416
1455
  virtualFsOps?: VirtualFsOps;
1417
1456
  /**
@@ -1,5 +1,5 @@
1
1
  import Redis from 'ioredis';
2
- import { P as PersistedThreadState, J as JsonValue } from './types-Cn2r3ol3.cjs';
2
+ import { P as PersistedThreadState, J as JsonValue } from './types-DjaQKUJx.cjs';
3
3
 
4
4
  interface ThreadManagerConfig<T> {
5
5
  redis: Redis;
@@ -1,5 +1,5 @@
1
1
  import Redis from 'ioredis';
2
- import { P as PersistedThreadState, J as JsonValue } from './types-DeQH84C_.js';
2
+ import { P as PersistedThreadState, J as JsonValue } from './types-BqTmyH31.js';
3
3
 
4
4
  interface ThreadManagerConfig<T> {
5
5
  redis: Redis;
@@ -1,4 +1,3 @@
1
- import { Duration } from '@temporalio/common';
2
1
  import { ActivityFunctionWithOptions, QueryDefinition, ChildWorkflowOptions, ActivityInterfaceFor } from '@temporalio/workflow';
3
2
  import { UpdateDefinition } from '@temporalio/common/lib/interfaces';
4
3
  import { z } from 'zod';
@@ -544,6 +543,13 @@ declare class VirtualFileSystem<TCtx = unknown, TMeta = FileEntryMetadata> imple
544
543
  getEntry(path: string): FileEntry<TMeta> | undefined;
545
544
  readFile(path: string): Promise<string>;
546
545
  readFileBuffer(path: string): Promise<Uint8Array>;
546
+ /**
547
+ * Resolve the string content for an entry, preferring inline content
548
+ * carried on the entry itself before consulting the resolver. Used by
549
+ * `readFile`, `appendFile`, and `cp` so all read paths agree on the
550
+ * lookup precedence.
551
+ */
552
+ private readEntryContent;
547
553
  exists(path: string): Promise<boolean>;
548
554
  stat(path: string): Promise<FileStat>;
549
555
  readdir(path: string): Promise<string[]>;
@@ -577,6 +583,25 @@ interface FileEntry<TMeta = FileEntryMetadata> {
577
583
  /** ISO-8601 date string (JSON-safe) */
578
584
  mtime: string;
579
585
  metadata: TMeta;
586
+ /**
587
+ * Optional inline content carried directly on the entry. When present the
588
+ * {@link VirtualFileSystem} returns this string from `readFile` /
589
+ * `readFileBuffer` (and uses it as the source for `cp` / `appendFile`)
590
+ * without consulting the resolver.
591
+ *
592
+ * Use this for files that exist purely in workflow state and have no
593
+ * backing in the consumer's data layer (e.g. skill resources bundled at
594
+ * session creation time). Because the content travels with the entry,
595
+ * any tool handler that constructs a `VirtualFileSystem` from `fileTree`
596
+ * sees the same content — no separate `inlineFiles` plumbing required.
597
+ *
598
+ * Read-only: entries with `inlineContent` reject in-place mutations
599
+ * (`writeFile`, `appendFile`, `rm`, `mv` of the entry, `cp` over the
600
+ * entry as destination). The resolver has no contract for the synthetic
601
+ * `id` these entries carry, so attempting a mutation throws an `EROFS`
602
+ * error instead of silently routing a doomed call through the resolver.
603
+ */
604
+ inlineContent?: string;
580
605
  }
581
606
  /**
582
607
  * Flat list of file entries.
@@ -1145,6 +1170,14 @@ interface SubagentSessionInput {
1145
1170
  sandboxId?: string;
1146
1171
  snapshot?: SandboxSnapshot;
1147
1172
  threadId: string;
1173
+ usage: {
1174
+ totalInputTokens: number;
1175
+ totalOutputTokens: number;
1176
+ totalCachedWriteTokens: number;
1177
+ totalCachedReadTokens: number;
1178
+ totalReasonTokens: number;
1179
+ turns: number;
1180
+ };
1148
1181
  }) => void;
1149
1182
  }
1150
1183
 
@@ -1351,8 +1384,6 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
1351
1384
  * Returns SDK-native content for the initial human message.
1352
1385
  */
1353
1386
  buildContextMessage: () => TContent | Promise<TContent>;
1354
- /** How long to wait for input before cancelling the workflow */
1355
- waitForInputTimeout?: Duration;
1356
1387
  /**
1357
1388
  * Thread initialization strategy (default: `{ mode: "new" }`).
1358
1389
  *
@@ -1412,6 +1443,14 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
1412
1443
  threadId: string;
1413
1444
  sandboxId?: string;
1414
1445
  snapshot?: SandboxSnapshot;
1446
+ usage: {
1447
+ totalInputTokens: number;
1448
+ totalOutputTokens: number;
1449
+ totalCachedWriteTokens: number;
1450
+ totalCachedReadTokens: number;
1451
+ totalReasonTokens: number;
1452
+ turns: number;
1453
+ };
1415
1454
  }) => void;
1416
1455
  virtualFsOps?: VirtualFsOps;
1417
1456
  /**
@@ -1,4 +1,4 @@
1
- import { as as ToolMap, a1 as SessionConfig, aD as ZeitlichSession, $ as SandboxShutdown, ak as ThreadInit, _ as SandboxInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aF as ToolRouterOptions, av as ToolRouter, R as RouterContext, J as JsonValue, ax as ToolWithHandler, w as ParsedToolCallUnion, at as ToolNames, aa as SubagentDefinition, ad as SubagentHooks, ae as SubagentSandboxConfig, a9 as SubagentConfig, af as SubagentSandboxShutdown, ag as SubagentSessionInput, ab as SubagentFnResult, a6 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, al as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, az as VirtualFileTree, k as TreeMutation, s as FileEntry, aA as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, aq as ToolHandler, aC as WorkflowTask, d as ActivityToolHandler } from './types-Cn2r3ol3.cjs';
1
+ import { as as ToolMap, a1 as SessionConfig, aD as ZeitlichSession, $ as SandboxShutdown, ak as ThreadInit, _ as SandboxInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aF as ToolRouterOptions, av as ToolRouter, R as RouterContext, J as JsonValue, ax as ToolWithHandler, w as ParsedToolCallUnion, at as ToolNames, aa as SubagentDefinition, ad as SubagentHooks, ae as SubagentSandboxConfig, a9 as SubagentConfig, af as SubagentSandboxShutdown, ag as SubagentSessionInput, ab as SubagentFnResult, a6 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, al as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, az as VirtualFileTree, k as TreeMutation, s as FileEntry, aA as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, aq as ToolHandler, aC as WorkflowTask, d as ActivityToolHandler } from './types-DjaQKUJx.cjs';
2
2
  import { g as SandboxOps } from './types-yx0LzPGn.cjs';
3
3
  import z$1, { z } from 'zod';
4
4
  import { Sinks, proxyActivities } from '@temporalio/workflow';
@@ -1,4 +1,4 @@
1
- import { as as ToolMap, a1 as SessionConfig, aD as ZeitlichSession, $ as SandboxShutdown, ak as ThreadInit, _ as SandboxInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aF as ToolRouterOptions, av as ToolRouter, R as RouterContext, J as JsonValue, ax as ToolWithHandler, w as ParsedToolCallUnion, at as ToolNames, aa as SubagentDefinition, ad as SubagentHooks, ae as SubagentSandboxConfig, a9 as SubagentConfig, af as SubagentSandboxShutdown, ag as SubagentSessionInput, ab as SubagentFnResult, a6 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, al as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, az as VirtualFileTree, k as TreeMutation, s as FileEntry, aA as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, aq as ToolHandler, aC as WorkflowTask, d as ActivityToolHandler } from './types-DeQH84C_.js';
1
+ import { as as ToolMap, a1 as SessionConfig, aD as ZeitlichSession, $ as SandboxShutdown, ak as ThreadInit, _ as SandboxInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aF as ToolRouterOptions, av as ToolRouter, R as RouterContext, J as JsonValue, ax as ToolWithHandler, w as ParsedToolCallUnion, at as ToolNames, aa as SubagentDefinition, ad as SubagentHooks, ae as SubagentSandboxConfig, a9 as SubagentConfig, af as SubagentSandboxShutdown, ag as SubagentSessionInput, ab as SubagentFnResult, a6 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, al as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, az as VirtualFileTree, k as TreeMutation, s as FileEntry, aA as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, aq as ToolHandler, aC as WorkflowTask, d as ActivityToolHandler } from './types-BqTmyH31.js';
2
2
  import { g as SandboxOps } from './types-yx0LzPGn.js';
3
3
  import z$1, { z } from 'zod';
4
4
  import { Sinks, proxyActivities } from '@temporalio/workflow';
package/dist/workflow.cjs CHANGED
@@ -953,7 +953,6 @@ async function createSession({
953
953
  processToolsInParallel = true,
954
954
  hooks = {},
955
955
  appendSystemPrompt = true,
956
- waitForInputTimeout = "48h",
957
956
  threadKey,
958
957
  sandboxOps,
959
958
  thread: threadInit,
@@ -1136,12 +1135,23 @@ async function createSession({
1136
1135
  path,
1137
1136
  size: content.length,
1138
1137
  mtime: (/* @__PURE__ */ new Date()).toISOString(),
1139
- metadata: {}
1138
+ metadata: {},
1139
+ // Carry the content directly on the entry so any handler that
1140
+ // constructs a VirtualFileSystem from `fileTree` can read it
1141
+ // without needing to also wire up `inlineFiles` from state.
1142
+ inlineContent: content
1140
1143
  }))
1141
1144
  ] : result.fileTree;
1142
1145
  stateManager.mergeUpdate({
1143
1146
  fileTree,
1144
1147
  virtualFsCtx: virtualFsConfig.ctx,
1148
+ // `inlineFiles` is still the source of truth at read time:
1149
+ // VirtualFileSystem checks the inlineFiles map first and only
1150
+ // falls through to entry.inlineContent. Embedding the content on
1151
+ // the entry is the migration target so that handlers building a
1152
+ // VirtualFileSystem from `fileTree` alone (without forwarding
1153
+ // `inlineFiles` from state) can read skill resources. Until a
1154
+ // follow-up drops `inlineFiles`, both fields are populated.
1145
1155
  ...skillFiles && { inlineFiles: skillFiles }
1146
1156
  });
1147
1157
  }
@@ -1267,18 +1277,6 @@ async function createSession({
1267
1277
  continue;
1268
1278
  }
1269
1279
  assistantId = void 0;
1270
- if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
1271
- const conditionMet = await workflow.condition(
1272
- () => stateManager.getStatus() === "RUNNING",
1273
- waitForInputTimeout
1274
- );
1275
- if (!conditionMet) {
1276
- stateManager.cancel();
1277
- exitReason = "cancelled";
1278
- await workflow.condition(() => false, "2s");
1279
- break;
1280
- }
1281
- }
1282
1280
  }
1283
1281
  if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
1284
1282
  exitReason = "max_turns";
@@ -1352,7 +1350,8 @@ async function createSession({
1352
1350
  onSessionExit({
1353
1351
  ...sandboxId && { sandboxId },
1354
1352
  ...exitSnapshot && { snapshot: exitSnapshot },
1355
- threadId
1353
+ threadId,
1354
+ usage: stateManager.getTotalUsage()
1356
1355
  });
1357
1356
  }
1358
1357
  return {
@@ -1573,6 +1572,20 @@ function createAgentStateManager({
1573
1572
  }
1574
1573
  };
1575
1574
  }
1575
+ var SandboxNotSupportedError = class extends common.ApplicationFailure {
1576
+ constructor(operation) {
1577
+ super(
1578
+ `Sandbox does not support: ${operation}`,
1579
+ "SandboxNotSupportedError",
1580
+ true
1581
+ );
1582
+ }
1583
+ };
1584
+ var SandboxNotFoundError = class extends common.ApplicationFailure {
1585
+ constructor(sandboxId) {
1586
+ super(`Sandbox not found: ${sandboxId}`, "SandboxNotFoundError", true);
1587
+ }
1588
+ };
1576
1589
 
1577
1590
  // src/lib/subagent/define.ts
1578
1591
  function defineSubagent(definition, overrides) {
@@ -1601,6 +1614,7 @@ function defineSubagentWorkflow(config, fn) {
1601
1614
  let capturedSnapshot;
1602
1615
  let capturedBaseSnapshot;
1603
1616
  let capturedThreadId;
1617
+ let capturedUsage;
1604
1618
  const sessionInput = {
1605
1619
  agentName: config.name,
1606
1620
  sandboxShutdown: effectiveShutdown,
@@ -1617,10 +1631,17 @@ function defineSubagentWorkflow(config, fn) {
1617
1631
  });
1618
1632
  }
1619
1633
  },
1620
- onSessionExit: ({ sandboxId, snapshot, threadId }) => {
1634
+ onSessionExit: ({ sandboxId, snapshot, threadId, usage }) => {
1621
1635
  capturedSandboxId = sandboxId;
1622
1636
  capturedSnapshot = snapshot;
1623
1637
  capturedThreadId = threadId;
1638
+ capturedUsage = {
1639
+ inputTokens: usage.totalInputTokens,
1640
+ outputTokens: usage.totalOutputTokens,
1641
+ cachedWriteTokens: usage.totalCachedWriteTokens,
1642
+ cachedReadTokens: usage.totalCachedReadTokens,
1643
+ reasonTokens: usage.totalReasonTokens
1644
+ };
1624
1645
  }
1625
1646
  };
1626
1647
  const result = await fn(prompt, sessionInput, context ?? {});
@@ -1631,7 +1652,8 @@ function defineSubagentWorkflow(config, fn) {
1631
1652
  ...capturedSnapshot !== void 0 && { snapshot: capturedSnapshot },
1632
1653
  ...capturedBaseSnapshot !== void 0 && {
1633
1654
  baseSnapshot: capturedBaseSnapshot
1634
- }
1655
+ },
1656
+ ...capturedUsage !== void 0 && { usage: capturedUsage }
1635
1657
  };
1636
1658
  };
1637
1659
  Object.defineProperty(workflow$1, "name", { value: config.name });
@@ -1715,20 +1737,6 @@ function proxyRunAgent(scope, options) {
1715
1737
  );
1716
1738
  return acts[name];
1717
1739
  }
1718
- var SandboxNotSupportedError = class extends common.ApplicationFailure {
1719
- constructor(operation) {
1720
- super(
1721
- `Sandbox does not support: ${operation}`,
1722
- "SandboxNotSupportedError",
1723
- true
1724
- );
1725
- }
1726
- };
1727
- var SandboxNotFoundError = class extends common.ApplicationFailure {
1728
- constructor(sandboxId) {
1729
- super(`Sandbox not found: ${sandboxId}`, "SandboxNotFoundError", true);
1730
- }
1731
- };
1732
1740
 
1733
1741
  // src/lib/virtual-fs/mutations.ts
1734
1742
  function applyVirtualTreeMutations(stateManager, mutations) {