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.
- package/dist/{activities-qUflxmfS.d.cts → activities-Coafq5zr.d.cts} +2 -2
- package/dist/{activities-D_g13S3y.d.ts → activities-CrN-ghLo.d.ts} +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs +4 -23
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +18 -86
- package/dist/adapters/sandbox/daytona/index.d.ts +18 -86
- package/dist/adapters/sandbox/daytona/index.js +4 -23
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.cjs +1 -7
- package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.d.ts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.js +1 -7
- package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs +9 -0
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +13 -5
- package/dist/adapters/sandbox/e2b/index.d.ts +13 -5
- package/dist/adapters/sandbox/e2b/index.js +9 -1
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs +11 -0
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +11 -3
- package/dist/adapters/sandbox/inmemory/index.d.ts +11 -3
- package/dist/adapters/sandbox/inmemory/index.js +11 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +5 -5
- package/dist/adapters/thread/anthropic/index.d.ts +5 -5
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +5 -5
- package/dist/adapters/thread/google-genai/index.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
- package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +5 -5
- package/dist/adapters/thread/langchain/index.d.ts +5 -5
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
- package/dist/index.cjs +224 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -16
- package/dist/index.d.ts +66 -16
- package/dist/index.js +224 -70
- package/dist/index.js.map +1 -1
- package/dist/{proxy-D7mvDEO6.d.cts → proxy-Bf7uI-Hw.d.cts} +1 -1
- package/dist/{proxy-BbcgoXg1.d.ts → proxy-COqA95FW.d.ts} +1 -1
- package/dist/{thread-manager-CTXPCu9W.d.ts → thread-manager-BhkOyQ1I.d.ts} +2 -2
- package/dist/{thread-manager-Dqstsw4i.d.ts → thread-manager-Bi1XlbpJ.d.ts} +2 -2
- package/dist/{thread-manager-cLhDhRRc.d.cts → thread-manager-BsLO3Fgc.d.cts} +2 -2
- package/dist/{thread-manager-DrWfVjlj.d.cts → thread-manager-wRVVBFgj.d.cts} +2 -2
- package/dist/{types-CjF1_Idx.d.ts → types-BkX4HLzi.d.ts} +1 -1
- package/dist/{types-CdvcmXb6.d.cts → types-C66-BVBr.d.cts} +1 -1
- package/dist/types-CJ7tCdl6.d.cts +266 -0
- package/dist/types-CJ7tCdl6.d.ts +266 -0
- package/dist/{types-DjaQKUJx.d.cts → types-CdALEF3z.d.cts} +300 -20
- package/dist/{types-BqTmyH31.d.ts → types-ChAy_jSP.d.ts} +300 -20
- package/dist/types-CjY93AWZ.d.cts +84 -0
- package/dist/types-gVa5XCWD.d.ts +84 -0
- package/dist/{workflow-N1MNDoul.d.ts → workflow-BwT5EybR.d.ts} +7 -6
- package/dist/{workflow-CuqxgS6X.d.cts → workflow-DMmiaw6w.d.cts} +7 -6
- package/dist/workflow.cjs +99 -46
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +4 -4
- package/dist/workflow.d.ts +4 -4
- package/dist/workflow.js +99 -46
- package/dist/workflow.js.map +1 -1
- package/package.json +7 -32
- package/src/adapters/sandbox/daytona/index.ts +25 -48
- package/src/adapters/sandbox/daytona/proxy.ts +7 -8
- package/src/adapters/sandbox/e2b/index.ts +21 -6
- package/src/adapters/sandbox/e2b/proxy.ts +3 -2
- package/src/adapters/sandbox/inmemory/index.ts +21 -1
- package/src/adapters/sandbox/inmemory/proxy.ts +7 -3
- package/src/lib/activity.ts +5 -0
- package/src/lib/sandbox/capability-types.test.ts +859 -0
- package/src/lib/sandbox/index.ts +1 -0
- package/src/lib/sandbox/manager.ts +187 -31
- package/src/lib/sandbox/types.ts +189 -46
- package/src/lib/session/index.ts +1 -0
- package/src/lib/session/session.ts +97 -35
- package/src/lib/session/types.ts +181 -5
- package/src/lib/subagent/handler.ts +66 -43
- package/src/lib/subagent/types.ts +484 -16
- package/src/workflow.ts +3 -0
- package/tsup.config.ts +0 -4
- package/dist/adapters/sandbox/bedrock/index.cjs +0 -457
- package/dist/adapters/sandbox/bedrock/index.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/index.d.cts +0 -25
- package/dist/adapters/sandbox/bedrock/index.d.ts +0 -25
- package/dist/adapters/sandbox/bedrock/index.js +0 -454
- package/dist/adapters/sandbox/bedrock/index.js.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.cjs +0 -36
- package/dist/adapters/sandbox/bedrock/workflow.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.d.cts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.d.ts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.js +0 -34
- package/dist/adapters/sandbox/bedrock/workflow.js.map +0 -1
- package/dist/types-DAsQ21Rt.d.ts +0 -74
- package/dist/types-lm8tMNJQ.d.cts +0 -74
- package/dist/types-yx0LzPGn.d.cts +0 -173
- package/dist/types-yx0LzPGn.d.ts +0 -173
- package/src/adapters/sandbox/bedrock/filesystem.ts +0 -340
- package/src/adapters/sandbox/bedrock/index.ts +0 -274
- package/src/adapters/sandbox/bedrock/proxy.ts +0 -59
- package/src/adapters/sandbox/bedrock/types.ts +0 -24
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Redis from 'ioredis';
|
|
2
|
-
import { J as JsonValue } from './types-
|
|
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-
|
|
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-
|
|
4
|
-
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-
|
|
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-
|
|
4
|
-
import { T as ThreadManagerHooks, P as ProviderThreadManager } from './types-
|
|
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-
|
|
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-
|
|
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;
|
|
@@ -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 };
|