zeitlich 0.2.41 → 0.2.42

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 (119) hide show
  1. package/dist/{activities-qUflxmfS.d.cts → activities-Coafq5zr.d.cts} +2 -2
  2. package/dist/{activities-D_g13S3y.d.ts → activities-CrN-ghLo.d.ts} +2 -2
  3. package/dist/adapters/sandbox/daytona/index.cjs +4 -23
  4. package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
  5. package/dist/adapters/sandbox/daytona/index.d.cts +18 -86
  6. package/dist/adapters/sandbox/daytona/index.d.ts +18 -86
  7. package/dist/adapters/sandbox/daytona/index.js +4 -23
  8. package/dist/adapters/sandbox/daytona/index.js.map +1 -1
  9. package/dist/adapters/sandbox/daytona/workflow.cjs +1 -7
  10. package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
  11. package/dist/adapters/sandbox/daytona/workflow.d.cts +9 -2
  12. package/dist/adapters/sandbox/daytona/workflow.d.ts +9 -2
  13. package/dist/adapters/sandbox/daytona/workflow.js +1 -7
  14. package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
  15. package/dist/adapters/sandbox/e2b/index.cjs +9 -0
  16. package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
  17. package/dist/adapters/sandbox/e2b/index.d.cts +13 -5
  18. package/dist/adapters/sandbox/e2b/index.d.ts +13 -5
  19. package/dist/adapters/sandbox/e2b/index.js +9 -1
  20. package/dist/adapters/sandbox/e2b/index.js.map +1 -1
  21. package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
  22. package/dist/adapters/sandbox/e2b/workflow.d.cts +4 -2
  23. package/dist/adapters/sandbox/e2b/workflow.d.ts +4 -2
  24. package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
  25. package/dist/adapters/sandbox/inmemory/index.cjs +11 -0
  26. package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
  27. package/dist/adapters/sandbox/inmemory/index.d.cts +11 -3
  28. package/dist/adapters/sandbox/inmemory/index.d.ts +11 -3
  29. package/dist/adapters/sandbox/inmemory/index.js +11 -1
  30. package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
  31. package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
  32. package/dist/adapters/sandbox/inmemory/workflow.d.cts +4 -2
  33. package/dist/adapters/sandbox/inmemory/workflow.d.ts +4 -2
  34. package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
  35. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  36. package/dist/adapters/thread/anthropic/index.d.cts +5 -5
  37. package/dist/adapters/thread/anthropic/index.d.ts +5 -5
  38. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  39. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  40. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  41. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  42. package/dist/adapters/thread/google-genai/index.d.cts +5 -5
  43. package/dist/adapters/thread/google-genai/index.d.ts +5 -5
  44. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  45. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
  46. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
  47. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  48. package/dist/adapters/thread/langchain/index.d.cts +5 -5
  49. package/dist/adapters/thread/langchain/index.d.ts +5 -5
  50. package/dist/adapters/thread/langchain/index.js.map +1 -1
  51. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  52. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  53. package/dist/index.cjs +224 -70
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.cts +66 -16
  56. package/dist/index.d.ts +66 -16
  57. package/dist/index.js +224 -70
  58. package/dist/index.js.map +1 -1
  59. package/dist/{proxy-D7mvDEO6.d.cts → proxy-Bf7uI-Hw.d.cts} +1 -1
  60. package/dist/{proxy-BbcgoXg1.d.ts → proxy-COqA95FW.d.ts} +1 -1
  61. package/dist/{thread-manager-CTXPCu9W.d.ts → thread-manager-BhkOyQ1I.d.ts} +2 -2
  62. package/dist/{thread-manager-Dqstsw4i.d.ts → thread-manager-Bi1XlbpJ.d.ts} +2 -2
  63. package/dist/{thread-manager-cLhDhRRc.d.cts → thread-manager-BsLO3Fgc.d.cts} +2 -2
  64. package/dist/{thread-manager-DrWfVjlj.d.cts → thread-manager-wRVVBFgj.d.cts} +2 -2
  65. package/dist/{types-CjF1_Idx.d.ts → types-BkX4HLzi.d.ts} +1 -1
  66. package/dist/{types-CdvcmXb6.d.cts → types-C66-BVBr.d.cts} +1 -1
  67. package/dist/types-CJ7tCdl6.d.cts +266 -0
  68. package/dist/types-CJ7tCdl6.d.ts +266 -0
  69. package/dist/{types-DjaQKUJx.d.cts → types-CdALEF3z.d.cts} +300 -20
  70. package/dist/{types-BqTmyH31.d.ts → types-ChAy_jSP.d.ts} +300 -20
  71. package/dist/types-CjY93AWZ.d.cts +84 -0
  72. package/dist/types-gVa5XCWD.d.ts +84 -0
  73. package/dist/{workflow-N1MNDoul.d.ts → workflow-BwT5EybR.d.ts} +7 -6
  74. package/dist/{workflow-CuqxgS6X.d.cts → workflow-DMmiaw6w.d.cts} +7 -6
  75. package/dist/workflow.cjs +99 -46
  76. package/dist/workflow.cjs.map +1 -1
  77. package/dist/workflow.d.cts +4 -4
  78. package/dist/workflow.d.ts +4 -4
  79. package/dist/workflow.js +99 -46
  80. package/dist/workflow.js.map +1 -1
  81. package/package.json +7 -32
  82. package/src/adapters/sandbox/daytona/index.ts +25 -48
  83. package/src/adapters/sandbox/daytona/proxy.ts +7 -8
  84. package/src/adapters/sandbox/e2b/index.ts +21 -6
  85. package/src/adapters/sandbox/e2b/proxy.ts +3 -2
  86. package/src/adapters/sandbox/inmemory/index.ts +21 -1
  87. package/src/adapters/sandbox/inmemory/proxy.ts +7 -3
  88. package/src/lib/activity.ts +5 -0
  89. package/src/lib/sandbox/capability-types.test.ts +859 -0
  90. package/src/lib/sandbox/index.ts +1 -0
  91. package/src/lib/sandbox/manager.ts +187 -31
  92. package/src/lib/sandbox/types.ts +189 -46
  93. package/src/lib/session/index.ts +1 -0
  94. package/src/lib/session/session.ts +97 -35
  95. package/src/lib/session/types.ts +181 -5
  96. package/src/lib/subagent/handler.ts +66 -43
  97. package/src/lib/subagent/types.ts +484 -16
  98. package/src/workflow.ts +3 -0
  99. package/tsup.config.ts +0 -4
  100. package/dist/adapters/sandbox/bedrock/index.cjs +0 -457
  101. package/dist/adapters/sandbox/bedrock/index.cjs.map +0 -1
  102. package/dist/adapters/sandbox/bedrock/index.d.cts +0 -25
  103. package/dist/adapters/sandbox/bedrock/index.d.ts +0 -25
  104. package/dist/adapters/sandbox/bedrock/index.js +0 -454
  105. package/dist/adapters/sandbox/bedrock/index.js.map +0 -1
  106. package/dist/adapters/sandbox/bedrock/workflow.cjs +0 -36
  107. package/dist/adapters/sandbox/bedrock/workflow.cjs.map +0 -1
  108. package/dist/adapters/sandbox/bedrock/workflow.d.cts +0 -29
  109. package/dist/adapters/sandbox/bedrock/workflow.d.ts +0 -29
  110. package/dist/adapters/sandbox/bedrock/workflow.js +0 -34
  111. package/dist/adapters/sandbox/bedrock/workflow.js.map +0 -1
  112. package/dist/types-DAsQ21Rt.d.ts +0 -74
  113. package/dist/types-lm8tMNJQ.d.cts +0 -74
  114. package/dist/types-yx0LzPGn.d.cts +0 -173
  115. package/dist/types-yx0LzPGn.d.ts +0 -173
  116. package/src/adapters/sandbox/bedrock/filesystem.ts +0 -340
  117. package/src/adapters/sandbox/bedrock/index.ts +0 -274
  118. package/src/adapters/sandbox/bedrock/proxy.ts +0 -59
  119. package/src/adapters/sandbox/bedrock/types.ts +0 -24
@@ -1,5 +1,5 @@
1
1
  import { proxyActivities, ActivityInterfaceFor } from '@temporalio/workflow';
2
- import { T as ThreadOps } from './types-DjaQKUJx.cjs';
2
+ import { T as ThreadOps } from './types-CdALEF3z.cjs';
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-BqTmyH31.js';
2
+ import { T as ThreadOps } from './types-ChAy_jSP.js';
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-BqTmyH31.js';
2
+ import { J as JsonValue } from './types-ChAy_jSP.js';
3
3
  import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CjF1_Idx.js';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-BkX4HLzi.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-BqTmyH31.js';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CjF1_Idx.js';
3
+ import { J as JsonValue } from './types-ChAy_jSP.js';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-BkX4HLzi.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
2
  import Anthropic from '@anthropic-ai/sdk';
3
- import { J as JsonValue } from './types-DjaQKUJx.cjs';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CdvcmXb6.cjs';
3
+ import { J as JsonValue } from './types-CdALEF3z.cjs';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-C66-BVBr.cjs';
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-DjaQKUJx.cjs';
2
+ import { J as JsonValue } from './types-CdALEF3z.cjs';
3
3
  import { MessageContent, StoredMessage, BaseMessage } from '@langchain/core/messages';
4
- import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-CdvcmXb6.cjs';
4
+ import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-C66-BVBr.cjs';
5
5
 
6
6
  /** SDK-native content type for LangChain human messages */
7
7
  type LangChainContent = string | MessageContent;
@@ -1,5 +1,5 @@
1
1
  import Redis from 'ioredis';
2
- import { P as PersistedThreadState, J as JsonValue } from './types-BqTmyH31.js';
2
+ import { P as PersistedThreadState, J as JsonValue } from './types-ChAy_jSP.js';
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-DjaQKUJx.cjs';
2
+ import { P as PersistedThreadState, J as JsonValue } from './types-CdALEF3z.cjs';
3
3
 
4
4
  interface ThreadManagerConfig<T> {
5
5
  redis: Redis;
@@ -0,0 +1,266 @@
1
+ import { ApplicationFailure } from '@temporalio/common';
2
+
3
+ interface DirentEntry {
4
+ name: string;
5
+ isFile: boolean;
6
+ isDirectory: boolean;
7
+ isSymbolicLink: boolean;
8
+ }
9
+ interface FileStat {
10
+ isFile: boolean;
11
+ isDirectory: boolean;
12
+ isSymbolicLink: boolean;
13
+ size: number;
14
+ mtime: Date;
15
+ }
16
+ interface SandboxNetworkConfig {
17
+ allowOut?: string[];
18
+ denyOut?: string[];
19
+ allowPublicTraffic?: boolean;
20
+ }
21
+ interface SandboxLifecycleConfig {
22
+ onTimeout: "kill" | "pause";
23
+ autoResume?: boolean;
24
+ }
25
+ /**
26
+ * Provider-agnostic filesystem interface.
27
+ *
28
+ * Implementations that don't support a method should throw
29
+ * {@link SandboxNotSupportedError}.
30
+ */
31
+ interface SandboxFileSystem {
32
+ /** Base directory used when resolving relative paths. */
33
+ readonly workspaceBase: string;
34
+ readFile(path: string): Promise<string>;
35
+ readFileBuffer(path: string): Promise<Uint8Array>;
36
+ writeFile(path: string, content: string | Uint8Array): Promise<void>;
37
+ appendFile(path: string, content: string | Uint8Array): Promise<void>;
38
+ exists(path: string): Promise<boolean>;
39
+ stat(path: string): Promise<FileStat>;
40
+ mkdir(path: string, options?: {
41
+ recursive?: boolean;
42
+ }): Promise<void>;
43
+ readdir(path: string): Promise<string[]>;
44
+ readdirWithFileTypes(path: string): Promise<DirentEntry[]>;
45
+ rm(path: string, options?: {
46
+ recursive?: boolean;
47
+ force?: boolean;
48
+ }): Promise<void>;
49
+ cp(src: string, dest: string, options?: {
50
+ recursive?: boolean;
51
+ }): Promise<void>;
52
+ mv(src: string, dest: string): Promise<void>;
53
+ readlink(path: string): Promise<string>;
54
+ resolvePath(base: string, path: string): string;
55
+ }
56
+ interface ExecOptions {
57
+ timeout?: number;
58
+ cwd?: string;
59
+ env?: Record<string, string>;
60
+ }
61
+ interface ExecResult {
62
+ exitCode: number;
63
+ stdout: string;
64
+ stderr: string;
65
+ }
66
+ /**
67
+ * Runtime capability flags carried by a {@link Sandbox} instance.
68
+ *
69
+ * These are an orthogonal mechanism to the type-level
70
+ * {@link SandboxCapability} union: this flag bag is for runtime
71
+ * introspection ("does the sandbox support a filesystem?") whereas
72
+ * {@link SandboxCapability} narrows the type-level provider/ops contract.
73
+ */
74
+ interface SandboxCapabilities {
75
+ /** Sandbox supports filesystem operations */
76
+ filesystem: boolean;
77
+ /** Sandbox supports shell/command execution */
78
+ execution: boolean;
79
+ /** Sandbox state can be persisted and restored */
80
+ persistence: boolean;
81
+ }
82
+ /**
83
+ * Type-level capability vocabulary for {@link SandboxProvider} and
84
+ * {@link SandboxOps}. Adapters declare the subset they actually support; the
85
+ * conditional types on each contract gate the corresponding methods so
86
+ * unsupported calls become a compile-time error rather than a runtime
87
+ * {@link SandboxNotSupportedError}.
88
+ *
89
+ * `pause` and `resume` are split because some adapters might support one
90
+ * direction without the other. The `snapshot` cap covers both `snapshot()`
91
+ * and `deleteSnapshot()` since they always travel together in practice.
92
+ */
93
+ type SandboxCapability = "pause" | "resume" | "snapshot" | "restore" | "fork";
94
+ interface Sandbox {
95
+ readonly id: string;
96
+ readonly capabilities: SandboxCapabilities;
97
+ readonly fs: SandboxFileSystem;
98
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
99
+ destroy(): Promise<void>;
100
+ }
101
+ interface SandboxSnapshot {
102
+ sandboxId: string;
103
+ providerId: string;
104
+ /** Provider-specific serialised state */
105
+ data: unknown;
106
+ createdAt: string;
107
+ }
108
+ interface SandboxCreateOptions {
109
+ /** Preferred sandbox ID (provider may ignore) */
110
+ id?: string;
111
+ /** Seed the filesystem with these files */
112
+ initialFiles?: Record<string, string | Uint8Array>;
113
+ /** Environment variables available inside the sandbox */
114
+ env?: Record<string, string>;
115
+ /** Key-value metadata surfaced via provider list/query APIs */
116
+ metadata?: Record<string, string>;
117
+ /** Sandbox idle timeout in milliseconds */
118
+ timeoutMs?: number;
119
+ /** Enable or disable outbound internet access */
120
+ allowInternetAccess?: boolean;
121
+ /** Outbound network allow/deny rules */
122
+ network?: SandboxNetworkConfig;
123
+ /** Sandbox timeout behaviour */
124
+ lifecycle?: SandboxLifecycleConfig;
125
+ }
126
+ interface SandboxCreateResult {
127
+ sandbox: Sandbox;
128
+ }
129
+ /**
130
+ * Internal helper: drop keys whose value is `never` from an object type.
131
+ *
132
+ * Used by the capability-gated contracts below so that an absent capability
133
+ * removes the corresponding key entirely, instead of leaving a required
134
+ * field with type `never` (which would make implementations impossible).
135
+ */
136
+ type OmitNever<T> = {
137
+ [K in keyof T as [T[K]] extends [never] ? never : K]: T[K];
138
+ };
139
+ /**
140
+ * Capability-gated provider lifecycle methods.
141
+ *
142
+ * Each field becomes `never` when its capability is absent from `TCaps`;
143
+ * the wrapping `OmitNever` removes those keys entirely, so the method
144
+ * isn't part of the type surface for adapters that don't support it.
145
+ */
146
+ type SandboxProviderCapMethods<TOptions extends SandboxCreateOptions, TSandbox extends Sandbox, TCaps extends SandboxCapability> = OmitNever<{
147
+ pause: "pause" extends TCaps ? (sandboxId: string, ttlSeconds?: number) => Promise<void> : never;
148
+ resume: "resume" extends TCaps ? (sandboxId: string) => Promise<void> : never;
149
+ snapshot: "snapshot" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<SandboxSnapshot> : never;
150
+ deleteSnapshot: "snapshot" extends TCaps ? (snapshot: SandboxSnapshot) => Promise<void> : never;
151
+ restore: "restore" extends TCaps ? (snapshot: SandboxSnapshot, options?: TOptions) => Promise<TSandbox> : never;
152
+ fork: "fork" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<TSandbox> : never;
153
+ }>;
154
+ /**
155
+ * Always-present provider lifecycle methods. These do not depend on the
156
+ * capability set and are required by every adapter.
157
+ */
158
+ interface SandboxProviderBase<TOptions extends SandboxCreateOptions, TSandbox extends Sandbox, TCaps extends SandboxCapability> {
159
+ readonly id: string;
160
+ readonly capabilities: SandboxCapabilities;
161
+ /**
162
+ * Runtime-introspectable list of supported capabilities.
163
+ *
164
+ * Constrained to `ReadonlySet<TCaps & SandboxCapability>` so the runtime
165
+ * set cannot include capabilities not declared at the type level — a
166
+ * provider typed as `SandboxProvider<…, never>` cannot ship a runtime
167
+ * set that contains `"pause"`, etc.
168
+ *
169
+ * The other direction (type declares a cap, runtime set omits it)
170
+ * cannot be enforced by TypeScript alone; adapters should derive both
171
+ * `TCaps` and the runtime set from the same `as const` array (see
172
+ * `SandboxManager`'s constructor-time consistency check) so the two
173
+ * surfaces cannot drift.
174
+ */
175
+ readonly supportedCapabilities: ReadonlySet<TCaps & SandboxCapability>;
176
+ create(options?: TOptions): Promise<SandboxCreateResult>;
177
+ get(sandboxId: string): Promise<TSandbox>;
178
+ destroy(sandboxId: string): Promise<void>;
179
+ }
180
+ /**
181
+ * Provider-side sandbox lifecycle contract.
182
+ *
183
+ * Generic over an optional capability set (`TCaps`). Each capability gates
184
+ * a specific method: when the cap is absent the corresponding key is
185
+ * **removed** from the type entirely, so calling it produces a TypeScript
186
+ * error at the call site instead of a runtime
187
+ * {@link SandboxNotSupportedError}.
188
+ *
189
+ * The default `TCaps = SandboxCapability` resolves to the full union, so
190
+ * existing usages that only pass `TOptions` / `TSandbox` continue to see
191
+ * the full method surface (backwards compatible).
192
+ *
193
+ * Adapters that don't support a method should narrow `TCaps` accordingly:
194
+ *
195
+ * - In-memory / E2B: `SandboxCapability` (default — all caps present).
196
+ * - Bedrock Code Interpreter / Daytona: `never` (only base ops).
197
+ * - Bedrock AgentCore Runtime: `"pause" | "resume"`.
198
+ */
199
+ type SandboxProvider<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TSandbox extends Sandbox = Sandbox, TCaps extends SandboxCapability = SandboxCapability> = SandboxProviderBase<TOptions, TSandbox, TCaps> & SandboxProviderCapMethods<TOptions, TSandbox, TCaps>;
200
+ /**
201
+ * Capability-gated workflow-side methods. Mirrors the provider's gating:
202
+ * keys whose capability is absent from `TCaps` are removed from the type.
203
+ */
204
+ type SandboxOpsCapMethods<TOptions extends SandboxCreateOptions, TCaps extends SandboxCapability> = OmitNever<{
205
+ pauseSandbox: "pause" extends TCaps ? (sandboxId: string) => Promise<void> : never;
206
+ resumeSandbox: "resume" extends TCaps ? (sandboxId: string) => Promise<void> : never;
207
+ snapshotSandbox: "snapshot" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<SandboxSnapshot> : never;
208
+ deleteSandboxSnapshot: "snapshot" extends TCaps ? (snapshot: SandboxSnapshot) => Promise<void> : never;
209
+ restoreSandbox: "restore" extends TCaps ? (snapshot: SandboxSnapshot, options?: TOptions) => Promise<string> : never;
210
+ forkSandbox: "fork" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<string> : never;
211
+ }>;
212
+ /**
213
+ * Always-present workflow-side lifecycle methods.
214
+ */
215
+ interface SandboxOpsBase<TOptions extends SandboxCreateOptions, TCtx> {
216
+ createSandbox(options?: TOptions, ctx?: TCtx): Promise<{
217
+ sandboxId: string;
218
+ } | null>;
219
+ destroySandbox(sandboxId: string): Promise<void>;
220
+ }
221
+ /**
222
+ * Workflow-side counterpart to {@link SandboxProvider}. Exposed as a set of
223
+ * Temporal activities and consumed by `createSession`'s `sandboxOps` field
224
+ * and by `defineSubagent`'s `sandbox.proxy`.
225
+ *
226
+ * Generic over a capability set (`TCaps`) — same semantics as the provider:
227
+ * keys whose capability is absent are removed from the type, so calling
228
+ * them is a TypeScript error rather than a runtime throw. The default
229
+ * `TCaps = SandboxCapability` keeps the full method surface for existing
230
+ * consumers.
231
+ */
232
+ type SandboxOps<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TCtx = unknown, TCaps extends SandboxCapability = SandboxCapability> = SandboxOpsBase<TOptions, TCtx> & SandboxOpsCapMethods<TOptions, TCaps>;
233
+ /**
234
+ * Maps generic {@link SandboxOps} method names to adapter-prefixed names.
235
+ *
236
+ * Inherits the capability gating from {@link SandboxOps}: when `TCaps` omits
237
+ * a capability the prefixed key carries the `never` type so call sites are
238
+ * type-protected.
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * type InMemOps = PrefixedSandboxOps<"inMemory">;
243
+ * // → { inMemoryCreateSandbox, inMemoryDestroySandbox, inMemorySnapshotSandbox, … }
244
+ * ```
245
+ */
246
+ type PrefixedSandboxOps<TPrefix extends string, TOptions extends SandboxCreateOptions = SandboxCreateOptions, TCtx = unknown, TCaps extends SandboxCapability = SandboxCapability> = {
247
+ [K in keyof SandboxOps<TOptions, TCtx, TCaps> as `${TPrefix}${Capitalize<K & string>}`]: SandboxOps<TOptions, TCtx, TCaps>[K];
248
+ };
249
+
250
+ /**
251
+ * Thrown by adapters that still surface an unsupported method at runtime.
252
+ *
253
+ * After the capability-generic refactor most adapters drop their
254
+ * unsupported methods entirely so the type system rejects them at call
255
+ * sites. This symbol is still exported so consumers running against older
256
+ * adapter versions can keep their backwards-compatible error-handling
257
+ * paths until they finish migrating.
258
+ */
259
+ declare class SandboxNotSupportedError extends ApplicationFailure {
260
+ constructor(operation: string);
261
+ }
262
+ declare class SandboxNotFoundError extends ApplicationFailure {
263
+ constructor(sandboxId: string);
264
+ }
265
+
266
+ export { type DirentEntry as D, type ExecResult as E, type FileStat as F, type PrefixedSandboxOps as P, type SandboxOps as S, type SandboxCreateOptions as a, type Sandbox as b, type SandboxFileSystem as c, type SandboxProvider as d, type SandboxCapabilities as e, type SandboxCreateResult as f, type SandboxSnapshot as g, type SandboxCapability as h, type ExecOptions as i, SandboxNotFoundError as j, SandboxNotSupportedError as k };
@@ -0,0 +1,266 @@
1
+ import { ApplicationFailure } from '@temporalio/common';
2
+
3
+ interface DirentEntry {
4
+ name: string;
5
+ isFile: boolean;
6
+ isDirectory: boolean;
7
+ isSymbolicLink: boolean;
8
+ }
9
+ interface FileStat {
10
+ isFile: boolean;
11
+ isDirectory: boolean;
12
+ isSymbolicLink: boolean;
13
+ size: number;
14
+ mtime: Date;
15
+ }
16
+ interface SandboxNetworkConfig {
17
+ allowOut?: string[];
18
+ denyOut?: string[];
19
+ allowPublicTraffic?: boolean;
20
+ }
21
+ interface SandboxLifecycleConfig {
22
+ onTimeout: "kill" | "pause";
23
+ autoResume?: boolean;
24
+ }
25
+ /**
26
+ * Provider-agnostic filesystem interface.
27
+ *
28
+ * Implementations that don't support a method should throw
29
+ * {@link SandboxNotSupportedError}.
30
+ */
31
+ interface SandboxFileSystem {
32
+ /** Base directory used when resolving relative paths. */
33
+ readonly workspaceBase: string;
34
+ readFile(path: string): Promise<string>;
35
+ readFileBuffer(path: string): Promise<Uint8Array>;
36
+ writeFile(path: string, content: string | Uint8Array): Promise<void>;
37
+ appendFile(path: string, content: string | Uint8Array): Promise<void>;
38
+ exists(path: string): Promise<boolean>;
39
+ stat(path: string): Promise<FileStat>;
40
+ mkdir(path: string, options?: {
41
+ recursive?: boolean;
42
+ }): Promise<void>;
43
+ readdir(path: string): Promise<string[]>;
44
+ readdirWithFileTypes(path: string): Promise<DirentEntry[]>;
45
+ rm(path: string, options?: {
46
+ recursive?: boolean;
47
+ force?: boolean;
48
+ }): Promise<void>;
49
+ cp(src: string, dest: string, options?: {
50
+ recursive?: boolean;
51
+ }): Promise<void>;
52
+ mv(src: string, dest: string): Promise<void>;
53
+ readlink(path: string): Promise<string>;
54
+ resolvePath(base: string, path: string): string;
55
+ }
56
+ interface ExecOptions {
57
+ timeout?: number;
58
+ cwd?: string;
59
+ env?: Record<string, string>;
60
+ }
61
+ interface ExecResult {
62
+ exitCode: number;
63
+ stdout: string;
64
+ stderr: string;
65
+ }
66
+ /**
67
+ * Runtime capability flags carried by a {@link Sandbox} instance.
68
+ *
69
+ * These are an orthogonal mechanism to the type-level
70
+ * {@link SandboxCapability} union: this flag bag is for runtime
71
+ * introspection ("does the sandbox support a filesystem?") whereas
72
+ * {@link SandboxCapability} narrows the type-level provider/ops contract.
73
+ */
74
+ interface SandboxCapabilities {
75
+ /** Sandbox supports filesystem operations */
76
+ filesystem: boolean;
77
+ /** Sandbox supports shell/command execution */
78
+ execution: boolean;
79
+ /** Sandbox state can be persisted and restored */
80
+ persistence: boolean;
81
+ }
82
+ /**
83
+ * Type-level capability vocabulary for {@link SandboxProvider} and
84
+ * {@link SandboxOps}. Adapters declare the subset they actually support; the
85
+ * conditional types on each contract gate the corresponding methods so
86
+ * unsupported calls become a compile-time error rather than a runtime
87
+ * {@link SandboxNotSupportedError}.
88
+ *
89
+ * `pause` and `resume` are split because some adapters might support one
90
+ * direction without the other. The `snapshot` cap covers both `snapshot()`
91
+ * and `deleteSnapshot()` since they always travel together in practice.
92
+ */
93
+ type SandboxCapability = "pause" | "resume" | "snapshot" | "restore" | "fork";
94
+ interface Sandbox {
95
+ readonly id: string;
96
+ readonly capabilities: SandboxCapabilities;
97
+ readonly fs: SandboxFileSystem;
98
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
99
+ destroy(): Promise<void>;
100
+ }
101
+ interface SandboxSnapshot {
102
+ sandboxId: string;
103
+ providerId: string;
104
+ /** Provider-specific serialised state */
105
+ data: unknown;
106
+ createdAt: string;
107
+ }
108
+ interface SandboxCreateOptions {
109
+ /** Preferred sandbox ID (provider may ignore) */
110
+ id?: string;
111
+ /** Seed the filesystem with these files */
112
+ initialFiles?: Record<string, string | Uint8Array>;
113
+ /** Environment variables available inside the sandbox */
114
+ env?: Record<string, string>;
115
+ /** Key-value metadata surfaced via provider list/query APIs */
116
+ metadata?: Record<string, string>;
117
+ /** Sandbox idle timeout in milliseconds */
118
+ timeoutMs?: number;
119
+ /** Enable or disable outbound internet access */
120
+ allowInternetAccess?: boolean;
121
+ /** Outbound network allow/deny rules */
122
+ network?: SandboxNetworkConfig;
123
+ /** Sandbox timeout behaviour */
124
+ lifecycle?: SandboxLifecycleConfig;
125
+ }
126
+ interface SandboxCreateResult {
127
+ sandbox: Sandbox;
128
+ }
129
+ /**
130
+ * Internal helper: drop keys whose value is `never` from an object type.
131
+ *
132
+ * Used by the capability-gated contracts below so that an absent capability
133
+ * removes the corresponding key entirely, instead of leaving a required
134
+ * field with type `never` (which would make implementations impossible).
135
+ */
136
+ type OmitNever<T> = {
137
+ [K in keyof T as [T[K]] extends [never] ? never : K]: T[K];
138
+ };
139
+ /**
140
+ * Capability-gated provider lifecycle methods.
141
+ *
142
+ * Each field becomes `never` when its capability is absent from `TCaps`;
143
+ * the wrapping `OmitNever` removes those keys entirely, so the method
144
+ * isn't part of the type surface for adapters that don't support it.
145
+ */
146
+ type SandboxProviderCapMethods<TOptions extends SandboxCreateOptions, TSandbox extends Sandbox, TCaps extends SandboxCapability> = OmitNever<{
147
+ pause: "pause" extends TCaps ? (sandboxId: string, ttlSeconds?: number) => Promise<void> : never;
148
+ resume: "resume" extends TCaps ? (sandboxId: string) => Promise<void> : never;
149
+ snapshot: "snapshot" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<SandboxSnapshot> : never;
150
+ deleteSnapshot: "snapshot" extends TCaps ? (snapshot: SandboxSnapshot) => Promise<void> : never;
151
+ restore: "restore" extends TCaps ? (snapshot: SandboxSnapshot, options?: TOptions) => Promise<TSandbox> : never;
152
+ fork: "fork" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<TSandbox> : never;
153
+ }>;
154
+ /**
155
+ * Always-present provider lifecycle methods. These do not depend on the
156
+ * capability set and are required by every adapter.
157
+ */
158
+ interface SandboxProviderBase<TOptions extends SandboxCreateOptions, TSandbox extends Sandbox, TCaps extends SandboxCapability> {
159
+ readonly id: string;
160
+ readonly capabilities: SandboxCapabilities;
161
+ /**
162
+ * Runtime-introspectable list of supported capabilities.
163
+ *
164
+ * Constrained to `ReadonlySet<TCaps & SandboxCapability>` so the runtime
165
+ * set cannot include capabilities not declared at the type level — a
166
+ * provider typed as `SandboxProvider<…, never>` cannot ship a runtime
167
+ * set that contains `"pause"`, etc.
168
+ *
169
+ * The other direction (type declares a cap, runtime set omits it)
170
+ * cannot be enforced by TypeScript alone; adapters should derive both
171
+ * `TCaps` and the runtime set from the same `as const` array (see
172
+ * `SandboxManager`'s constructor-time consistency check) so the two
173
+ * surfaces cannot drift.
174
+ */
175
+ readonly supportedCapabilities: ReadonlySet<TCaps & SandboxCapability>;
176
+ create(options?: TOptions): Promise<SandboxCreateResult>;
177
+ get(sandboxId: string): Promise<TSandbox>;
178
+ destroy(sandboxId: string): Promise<void>;
179
+ }
180
+ /**
181
+ * Provider-side sandbox lifecycle contract.
182
+ *
183
+ * Generic over an optional capability set (`TCaps`). Each capability gates
184
+ * a specific method: when the cap is absent the corresponding key is
185
+ * **removed** from the type entirely, so calling it produces a TypeScript
186
+ * error at the call site instead of a runtime
187
+ * {@link SandboxNotSupportedError}.
188
+ *
189
+ * The default `TCaps = SandboxCapability` resolves to the full union, so
190
+ * existing usages that only pass `TOptions` / `TSandbox` continue to see
191
+ * the full method surface (backwards compatible).
192
+ *
193
+ * Adapters that don't support a method should narrow `TCaps` accordingly:
194
+ *
195
+ * - In-memory / E2B: `SandboxCapability` (default — all caps present).
196
+ * - Bedrock Code Interpreter / Daytona: `never` (only base ops).
197
+ * - Bedrock AgentCore Runtime: `"pause" | "resume"`.
198
+ */
199
+ type SandboxProvider<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TSandbox extends Sandbox = Sandbox, TCaps extends SandboxCapability = SandboxCapability> = SandboxProviderBase<TOptions, TSandbox, TCaps> & SandboxProviderCapMethods<TOptions, TSandbox, TCaps>;
200
+ /**
201
+ * Capability-gated workflow-side methods. Mirrors the provider's gating:
202
+ * keys whose capability is absent from `TCaps` are removed from the type.
203
+ */
204
+ type SandboxOpsCapMethods<TOptions extends SandboxCreateOptions, TCaps extends SandboxCapability> = OmitNever<{
205
+ pauseSandbox: "pause" extends TCaps ? (sandboxId: string) => Promise<void> : never;
206
+ resumeSandbox: "resume" extends TCaps ? (sandboxId: string) => Promise<void> : never;
207
+ snapshotSandbox: "snapshot" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<SandboxSnapshot> : never;
208
+ deleteSandboxSnapshot: "snapshot" extends TCaps ? (snapshot: SandboxSnapshot) => Promise<void> : never;
209
+ restoreSandbox: "restore" extends TCaps ? (snapshot: SandboxSnapshot, options?: TOptions) => Promise<string> : never;
210
+ forkSandbox: "fork" extends TCaps ? (sandboxId: string, options?: TOptions) => Promise<string> : never;
211
+ }>;
212
+ /**
213
+ * Always-present workflow-side lifecycle methods.
214
+ */
215
+ interface SandboxOpsBase<TOptions extends SandboxCreateOptions, TCtx> {
216
+ createSandbox(options?: TOptions, ctx?: TCtx): Promise<{
217
+ sandboxId: string;
218
+ } | null>;
219
+ destroySandbox(sandboxId: string): Promise<void>;
220
+ }
221
+ /**
222
+ * Workflow-side counterpart to {@link SandboxProvider}. Exposed as a set of
223
+ * Temporal activities and consumed by `createSession`'s `sandboxOps` field
224
+ * and by `defineSubagent`'s `sandbox.proxy`.
225
+ *
226
+ * Generic over a capability set (`TCaps`) — same semantics as the provider:
227
+ * keys whose capability is absent are removed from the type, so calling
228
+ * them is a TypeScript error rather than a runtime throw. The default
229
+ * `TCaps = SandboxCapability` keeps the full method surface for existing
230
+ * consumers.
231
+ */
232
+ type SandboxOps<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TCtx = unknown, TCaps extends SandboxCapability = SandboxCapability> = SandboxOpsBase<TOptions, TCtx> & SandboxOpsCapMethods<TOptions, TCaps>;
233
+ /**
234
+ * Maps generic {@link SandboxOps} method names to adapter-prefixed names.
235
+ *
236
+ * Inherits the capability gating from {@link SandboxOps}: when `TCaps` omits
237
+ * a capability the prefixed key carries the `never` type so call sites are
238
+ * type-protected.
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * type InMemOps = PrefixedSandboxOps<"inMemory">;
243
+ * // → { inMemoryCreateSandbox, inMemoryDestroySandbox, inMemorySnapshotSandbox, … }
244
+ * ```
245
+ */
246
+ type PrefixedSandboxOps<TPrefix extends string, TOptions extends SandboxCreateOptions = SandboxCreateOptions, TCtx = unknown, TCaps extends SandboxCapability = SandboxCapability> = {
247
+ [K in keyof SandboxOps<TOptions, TCtx, TCaps> as `${TPrefix}${Capitalize<K & string>}`]: SandboxOps<TOptions, TCtx, TCaps>[K];
248
+ };
249
+
250
+ /**
251
+ * Thrown by adapters that still surface an unsupported method at runtime.
252
+ *
253
+ * After the capability-generic refactor most adapters drop their
254
+ * unsupported methods entirely so the type system rejects them at call
255
+ * sites. This symbol is still exported so consumers running against older
256
+ * adapter versions can keep their backwards-compatible error-handling
257
+ * paths until they finish migrating.
258
+ */
259
+ declare class SandboxNotSupportedError extends ApplicationFailure {
260
+ constructor(operation: string);
261
+ }
262
+ declare class SandboxNotFoundError extends ApplicationFailure {
263
+ constructor(sandboxId: string);
264
+ }
265
+
266
+ export { type DirentEntry as D, type ExecResult as E, type FileStat as F, type PrefixedSandboxOps as P, type SandboxOps as S, type SandboxCreateOptions as a, type Sandbox as b, type SandboxFileSystem as c, type SandboxProvider as d, type SandboxCapabilities as e, type SandboxCreateResult as f, type SandboxSnapshot as g, type SandboxCapability as h, type ExecOptions as i, SandboxNotFoundError as j, SandboxNotSupportedError as k };