zeitlich 0.2.26 → 0.2.28

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 (97) hide show
  1. package/dist/{activities-BEJRyDVU.d.cts → activities-3xj_fEJK.d.ts} +7 -4
  2. package/dist/{activities-LVQdLF6I.d.ts → activities-BzYq6jf7.d.cts} +7 -4
  3. package/dist/adapters/sandbox/e2b/index.cjs +230 -0
  4. package/dist/adapters/sandbox/e2b/index.cjs.map +1 -0
  5. package/dist/adapters/sandbox/e2b/index.d.cts +77 -0
  6. package/dist/adapters/sandbox/e2b/index.d.ts +77 -0
  7. package/dist/adapters/sandbox/e2b/index.js +227 -0
  8. package/dist/adapters/sandbox/e2b/index.js.map +1 -0
  9. package/dist/adapters/sandbox/e2b/workflow.cjs +33 -0
  10. package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -0
  11. package/dist/adapters/sandbox/e2b/workflow.d.cts +27 -0
  12. package/dist/adapters/sandbox/e2b/workflow.d.ts +27 -0
  13. package/dist/adapters/sandbox/e2b/workflow.js +31 -0
  14. package/dist/adapters/sandbox/e2b/workflow.js.map +1 -0
  15. package/dist/adapters/sandbox/virtual/index.d.cts +4 -4
  16. package/dist/adapters/sandbox/virtual/index.d.ts +4 -4
  17. package/dist/adapters/sandbox/virtual/workflow.d.cts +2 -2
  18. package/dist/adapters/sandbox/virtual/workflow.d.ts +2 -2
  19. package/dist/adapters/thread/anthropic/index.cjs +13 -6
  20. package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
  21. package/dist/adapters/thread/anthropic/index.d.cts +10 -7
  22. package/dist/adapters/thread/anthropic/index.d.ts +10 -7
  23. package/dist/adapters/thread/anthropic/index.js +13 -6
  24. package/dist/adapters/thread/anthropic/index.js.map +1 -1
  25. package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
  26. package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
  27. package/dist/adapters/thread/google-genai/index.cjs +11 -6
  28. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  29. package/dist/adapters/thread/google-genai/index.d.cts +9 -6
  30. package/dist/adapters/thread/google-genai/index.d.ts +9 -6
  31. package/dist/adapters/thread/google-genai/index.js +11 -6
  32. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  33. package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
  34. package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
  35. package/dist/adapters/thread/langchain/index.cjs +44 -5
  36. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  37. package/dist/adapters/thread/langchain/index.d.cts +25 -9
  38. package/dist/adapters/thread/langchain/index.d.ts +25 -9
  39. package/dist/adapters/thread/langchain/index.js +44 -6
  40. package/dist/adapters/thread/langchain/index.js.map +1 -1
  41. package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
  42. package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
  43. package/dist/index.cjs +27 -16
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.cts +8 -8
  46. package/dist/index.d.ts +8 -8
  47. package/dist/index.js +27 -16
  48. package/dist/index.js.map +1 -1
  49. package/dist/{proxy-BK1ydQt0.d.ts → proxy-7e7v8ccg.d.ts} +1 -1
  50. package/dist/{proxy-BMAsMHdp.d.cts → proxy-CsB8r0RR.d.cts} +1 -1
  51. package/dist/{queries-DwnE2bu3.d.cts → queries-DVnukByF.d.cts} +1 -1
  52. package/dist/{queries-BCgJ9Sr5.d.ts → queries-kjlvsUfz.d.ts} +1 -1
  53. package/dist/{thread-manager-DOnQzImf.d.cts → thread-manager-B5qA4v7V.d.ts} +5 -3
  54. package/dist/{thread-manager-b4DML-qu.d.cts → thread-manager-D8C5QvLi.d.ts} +4 -2
  55. package/dist/{thread-manager-CH9krS3h.d.ts → thread-manager-DFJ3sKKU.d.cts} +4 -2
  56. package/dist/{thread-manager-Czhpxbt6.d.ts → thread-manager-DdVFl1IY.d.cts} +5 -3
  57. package/dist/{types-BDRDbm3h.d.cts → types-BZ75HpYd.d.ts} +14 -2
  58. package/dist/{types-mCVxKIZb.d.cts → types-BclYm5Ic.d.cts} +0 -4
  59. package/dist/{types-mCVxKIZb.d.ts → types-BclYm5Ic.d.ts} +0 -4
  60. package/dist/{types-DRnz-OZp.d.cts → types-BgsAwN3L.d.cts} +1 -1
  61. package/dist/{types-CvJyXDYt.d.ts → types-BtqbM1bO.d.ts} +1 -1
  62. package/dist/{types-DSOefLpY.d.cts → types-BuCEZ4dF.d.cts} +1 -1
  63. package/dist/{types-WNSeZbWa.d.ts → types-HbjqzyJH.d.cts} +14 -2
  64. package/dist/{types-DFUNSYbj.d.ts → types-yU5AINiP.d.ts} +1 -1
  65. package/dist/workflow.cjs +27 -16
  66. package/dist/workflow.cjs.map +1 -1
  67. package/dist/workflow.d.cts +7 -7
  68. package/dist/workflow.d.ts +7 -7
  69. package/dist/workflow.js +27 -16
  70. package/dist/workflow.js.map +1 -1
  71. package/package.json +21 -1
  72. package/src/adapters/sandbox/e2b/proxy.ts +56 -0
  73. package/src/adapters/thread/anthropic/activities.ts +3 -0
  74. package/src/adapters/thread/anthropic/model-invoker.ts +7 -2
  75. package/src/adapters/thread/anthropic/thread-manager.test.ts +137 -0
  76. package/src/adapters/thread/anthropic/thread-manager.ts +13 -2
  77. package/src/adapters/thread/google-genai/activities.ts +3 -1
  78. package/src/adapters/thread/google-genai/model-invoker.ts +7 -3
  79. package/src/adapters/thread/google-genai/thread-manager.test.ts +159 -0
  80. package/src/adapters/thread/google-genai/thread-manager.ts +13 -2
  81. package/src/adapters/thread/langchain/activities.ts +3 -1
  82. package/src/adapters/thread/langchain/hooks.test.ts +195 -0
  83. package/src/adapters/thread/langchain/hooks.ts +54 -0
  84. package/src/adapters/thread/langchain/index.ts +3 -0
  85. package/src/adapters/thread/langchain/model-invoker.ts +7 -4
  86. package/src/adapters/thread/langchain/thread-manager.test.ts +144 -0
  87. package/src/adapters/thread/langchain/thread-manager.ts +12 -1
  88. package/src/lib/.env +1 -0
  89. package/src/lib/session/session.ts +16 -5
  90. package/src/lib/subagent/handler.ts +5 -2
  91. package/src/lib/subagent/register.ts +7 -2
  92. package/src/lib/thread/index.ts +1 -0
  93. package/src/lib/thread/types.ts +13 -0
  94. package/src/lib/tool-router/router.ts +2 -5
  95. package/src/lib/tool-router/types.ts +0 -4
  96. package/src/tools/bash/.env +1 -0
  97. package/tsup.config.ts +3 -0
@@ -0,0 +1,227 @@
1
+ import { FileType, Sandbox } from '@e2b/code-interpreter';
2
+ import { ApplicationFailure } from '@temporalio/common';
3
+ import { posix } from 'path';
4
+
5
+ // src/adapters/sandbox/e2b/index.ts
6
+ var SandboxNotSupportedError = class extends ApplicationFailure {
7
+ constructor(operation) {
8
+ super(
9
+ `Sandbox does not support: ${operation}`,
10
+ "SandboxNotSupportedError",
11
+ true
12
+ );
13
+ }
14
+ };
15
+ var SandboxNotFoundError = class extends ApplicationFailure {
16
+ constructor(sandboxId) {
17
+ super(`Sandbox not found: ${sandboxId}`, "SandboxNotFoundError", true);
18
+ }
19
+ };
20
+ function toArrayBuffer(u8) {
21
+ return u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
22
+ }
23
+ var E2bSandboxFileSystem = class {
24
+ constructor(sandbox, workspaceBase = "/home/user") {
25
+ this.sandbox = sandbox;
26
+ this.workspaceBase = posix.resolve("/", workspaceBase);
27
+ }
28
+ workspaceBase;
29
+ normalisePath(path) {
30
+ return posix.resolve(this.workspaceBase, path);
31
+ }
32
+ async readFile(path) {
33
+ return this.sandbox.files.read(this.normalisePath(path));
34
+ }
35
+ async readFileBuffer(path) {
36
+ return this.sandbox.files.read(this.normalisePath(path), {
37
+ format: "bytes"
38
+ });
39
+ }
40
+ async writeFile(path, content) {
41
+ const norm = this.normalisePath(path);
42
+ if (typeof content === "string") {
43
+ await this.sandbox.files.write(norm, content);
44
+ } else {
45
+ await this.sandbox.files.write(norm, toArrayBuffer(content));
46
+ }
47
+ }
48
+ async appendFile(path, content) {
49
+ const norm = this.normalisePath(path);
50
+ let existing = "";
51
+ try {
52
+ existing = await this.sandbox.files.read(norm);
53
+ } catch {
54
+ }
55
+ const addition = typeof content === "string" ? content : new TextDecoder().decode(content);
56
+ await this.sandbox.files.write(norm, existing + addition);
57
+ }
58
+ async exists(path) {
59
+ return this.sandbox.files.exists(this.normalisePath(path));
60
+ }
61
+ async stat(path) {
62
+ const norm = this.normalisePath(path);
63
+ const info = await this.sandbox.files.getInfo(norm);
64
+ const isSymlink = !!info.symlinkTarget;
65
+ return {
66
+ isFile: isSymlink ? false : info.type === FileType.FILE,
67
+ isDirectory: isSymlink ? false : info.type === FileType.DIR,
68
+ isSymbolicLink: isSymlink,
69
+ size: info.size,
70
+ mtime: info.modifiedTime ?? /* @__PURE__ */ new Date(0)
71
+ };
72
+ }
73
+ async mkdir(path, _options) {
74
+ await this.sandbox.files.makeDir(this.normalisePath(path));
75
+ }
76
+ async readdir(path) {
77
+ const entries = await this.sandbox.files.list(this.normalisePath(path));
78
+ return entries.map((e) => posix.basename(e.path));
79
+ }
80
+ async readdirWithFileTypes(path) {
81
+ const entries = await this.sandbox.files.list(this.normalisePath(path));
82
+ return entries.map((e) => {
83
+ const isSymlink = !!e.symlinkTarget;
84
+ return {
85
+ name: posix.basename(e.path),
86
+ isFile: isSymlink ? false : e.type === FileType.FILE,
87
+ isDirectory: isSymlink ? false : e.type === FileType.DIR,
88
+ isSymbolicLink: isSymlink
89
+ };
90
+ });
91
+ }
92
+ async rm(path, options) {
93
+ const norm = this.normalisePath(path);
94
+ try {
95
+ await this.sandbox.files.remove(norm);
96
+ } catch (err) {
97
+ if (!options?.force) throw err;
98
+ }
99
+ }
100
+ async cp(src, dest, _options) {
101
+ const normSrc = this.normalisePath(src);
102
+ const normDest = this.normalisePath(dest);
103
+ await this.sandbox.commands.run(`cp -r "${normSrc}" "${normDest}"`);
104
+ }
105
+ async mv(src, dest) {
106
+ const normSrc = this.normalisePath(src);
107
+ const normDest = this.normalisePath(dest);
108
+ await this.sandbox.files.rename(normSrc, normDest);
109
+ }
110
+ async readlink(path) {
111
+ const norm = this.normalisePath(path);
112
+ const info = await this.sandbox.files.getInfo(norm);
113
+ if (!info.symlinkTarget) {
114
+ throw new Error(`EINVAL: invalid argument, readlink '${path}'`);
115
+ }
116
+ return info.symlinkTarget;
117
+ }
118
+ resolvePath(base, path) {
119
+ return posix.resolve(this.normalisePath(base), path);
120
+ }
121
+ };
122
+
123
+ // src/adapters/sandbox/e2b/index.ts
124
+ var E2bSandboxImpl = class {
125
+ constructor(id, sdkSandbox, workspaceBase = "/home/user") {
126
+ this.id = id;
127
+ this.sdkSandbox = sdkSandbox;
128
+ this.fs = new E2bSandboxFileSystem(sdkSandbox, workspaceBase);
129
+ }
130
+ capabilities = {
131
+ filesystem: true,
132
+ execution: true,
133
+ persistence: true
134
+ };
135
+ fs;
136
+ async exec(command, options) {
137
+ const result = await this.sdkSandbox.commands.run(command, {
138
+ cwd: options?.cwd,
139
+ envs: options?.env,
140
+ timeoutMs: options?.timeout
141
+ });
142
+ return {
143
+ exitCode: result.exitCode,
144
+ stdout: result.stdout,
145
+ stderr: result.stderr
146
+ };
147
+ }
148
+ async destroy() {
149
+ await this.sdkSandbox.kill();
150
+ }
151
+ };
152
+ var E2bSandboxProvider = class {
153
+ id = "e2b";
154
+ capabilities = {
155
+ filesystem: true,
156
+ execution: true,
157
+ persistence: true
158
+ };
159
+ defaultTemplate;
160
+ defaultWorkspaceBase;
161
+ defaultTimeoutMs;
162
+ constructor(config) {
163
+ this.defaultTemplate = config?.template;
164
+ this.defaultWorkspaceBase = config?.workspaceBase ?? "/home/user";
165
+ this.defaultTimeoutMs = config?.timeoutMs;
166
+ }
167
+ async create(options) {
168
+ const template = options?.template ?? this.defaultTemplate;
169
+ const workspaceBase = this.defaultWorkspaceBase;
170
+ const createOpts = {
171
+ envs: options?.env,
172
+ timeoutMs: options?.timeoutMs ?? this.defaultTimeoutMs
173
+ };
174
+ const sdkSandbox = template ? await Sandbox.create(template, createOpts) : await Sandbox.create(createOpts);
175
+ const sandbox = new E2bSandboxImpl(
176
+ sdkSandbox.sandboxId,
177
+ sdkSandbox,
178
+ workspaceBase
179
+ );
180
+ if (options?.initialFiles) {
181
+ await Promise.all(
182
+ Object.entries(options.initialFiles).map(
183
+ ([path, content]) => sandbox.fs.writeFile(path, content)
184
+ )
185
+ );
186
+ }
187
+ return { sandbox };
188
+ }
189
+ async get(sandboxId) {
190
+ try {
191
+ const sdkSandbox = await Sandbox.connect(sandboxId);
192
+ return new E2bSandboxImpl(sandboxId, sdkSandbox, this.defaultWorkspaceBase);
193
+ } catch {
194
+ throw new SandboxNotFoundError(sandboxId);
195
+ }
196
+ }
197
+ async destroy(sandboxId) {
198
+ try {
199
+ const sdkSandbox = await Sandbox.connect(sandboxId);
200
+ await sdkSandbox.kill();
201
+ } catch {
202
+ }
203
+ }
204
+ async pause(sandboxId, _ttlSeconds) {
205
+ const sdkSandbox = await Sandbox.connect(sandboxId);
206
+ await sdkSandbox.pause();
207
+ }
208
+ async snapshot(_sandboxId) {
209
+ throw new SandboxNotSupportedError("snapshot");
210
+ }
211
+ async restore(_snapshot) {
212
+ throw new SandboxNotSupportedError("restore");
213
+ }
214
+ async fork(sandboxId) {
215
+ const { snapshotId } = await Sandbox.createSnapshot(sandboxId);
216
+ const sdkSandbox = await Sandbox.create(snapshotId);
217
+ return new E2bSandboxImpl(
218
+ sdkSandbox.sandboxId,
219
+ sdkSandbox,
220
+ this.defaultWorkspaceBase
221
+ );
222
+ }
223
+ };
224
+
225
+ export { E2bSandboxFileSystem, E2bSandboxProvider };
226
+ //# sourceMappingURL=index.js.map
227
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/lib/sandbox/types.ts","../../../../src/adapters/sandbox/e2b/filesystem.ts","../../../../src/adapters/sandbox/e2b/index.ts"],"names":["E2bSdkSandbox"],"mappings":";;;;;AAkLO,IAAM,wBAAA,GAAN,cAAuC,kBAAA,CAAmB;AA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A,CAAc,eAAe,SAAS,CAAA;AACnE,IAAA,MAAM,UAAA,GAAa,MAAMA,OAAA,CAAc,MAAA,CAAO,UAAU,CAAA;AACxD,IAAA,OAAO,IAAI,cAAA;AAAA,MACT,UAAA,CAAW,SAAA;AAAA,MACX,UAAA;AAAA,MACA,IAAA,CAAK;AAAA,KACP;AAAA,EACF;AACF","file":"index.js","sourcesContent":["// ============================================================================\n// Sandbox Filesystem\n// ============================================================================\n\nexport interface DirentEntry {\n name: string;\n isFile: boolean;\n isDirectory: boolean;\n isSymbolicLink: boolean;\n}\n\nexport interface FileStat {\n isFile: boolean;\n isDirectory: boolean;\n isSymbolicLink: boolean;\n size: number;\n mtime: Date;\n}\n\n/**\n * Provider-agnostic filesystem interface.\n *\n * Implementations that don't support a method should throw\n * {@link SandboxNotSupportedError}.\n */\nexport interface SandboxFileSystem {\n /** Base directory used when resolving relative paths. */\n readonly workspaceBase: string;\n readFile(path: string): Promise<string>;\n readFileBuffer(path: string): Promise<Uint8Array>;\n writeFile(path: string, content: string | Uint8Array): Promise<void>;\n appendFile(path: string, content: string | Uint8Array): Promise<void>;\n exists(path: string): Promise<boolean>;\n stat(path: string): Promise<FileStat>;\n mkdir(path: string, options?: { recursive?: boolean }): Promise<void>;\n readdir(path: string): Promise<string[]>;\n readdirWithFileTypes(path: string): Promise<DirentEntry[]>;\n rm(\n path: string,\n options?: { recursive?: boolean; force?: boolean }\n ): Promise<void>;\n cp(\n src: string,\n dest: string,\n options?: { recursive?: boolean }\n ): Promise<void>;\n mv(src: string, dest: string): Promise<void>;\n readlink(path: string): Promise<string>;\n resolvePath(base: string, path: string): string;\n}\n\n// ============================================================================\n// Execution\n// ============================================================================\n\nexport interface ExecOptions {\n timeout?: number;\n cwd?: string;\n env?: Record<string, string>;\n}\n\nexport interface ExecResult {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\n// ============================================================================\n// Capabilities\n// ============================================================================\n\nexport interface SandboxCapabilities {\n /** Sandbox supports filesystem operations */\n filesystem: boolean;\n /** Sandbox supports shell/command execution */\n execution: boolean;\n /** Sandbox state can be persisted and restored */\n persistence: boolean;\n}\n\n// ============================================================================\n// Sandbox\n// ============================================================================\n\nexport interface Sandbox {\n readonly id: string;\n readonly capabilities: SandboxCapabilities;\n readonly fs: SandboxFileSystem;\n\n exec(command: string, options?: ExecOptions): Promise<ExecResult>;\n destroy(): Promise<void>;\n}\n\n// ============================================================================\n// Snapshots\n// ============================================================================\n\nexport interface SandboxSnapshot {\n sandboxId: string;\n providerId: string;\n /** Provider-specific serialised state */\n data: unknown;\n createdAt: string;\n}\n\n// ============================================================================\n// Provider\n// ============================================================================\n\nexport interface SandboxCreateOptions {\n /** Preferred sandbox ID (provider may ignore) */\n id?: string;\n /** Seed the filesystem with these files */\n initialFiles?: Record<string, string | Uint8Array>;\n /** Environment variables available inside the sandbox */\n env?: Record<string, string>;\n}\n\nexport interface SandboxCreateResult {\n sandbox: Sandbox;\n /** Optional state to merge into the workflow's `AgentState` via the session. */\n stateUpdate?: Record<string, unknown>;\n}\n\nexport interface SandboxProvider<\n TOptions extends SandboxCreateOptions = SandboxCreateOptions,\n TSandbox extends Sandbox = Sandbox,\n> {\n readonly id: string;\n readonly capabilities: SandboxCapabilities;\n\n create(options?: TOptions): Promise<SandboxCreateResult>;\n get(sandboxId: string): Promise<TSandbox>;\n destroy(sandboxId: string): Promise<void>;\n pause(sandboxId: string, ttlSeconds?: number): Promise<void>;\n snapshot(sandboxId: string): Promise<SandboxSnapshot>;\n restore(snapshot: SandboxSnapshot): Promise<Sandbox>;\n fork(sandboxId: string): Promise<Sandbox>;\n}\n\n// ============================================================================\n// SandboxOps — workflow-side activity interface (like ThreadOps)\n// ============================================================================\n\nexport interface SandboxOps<\n TOptions extends SandboxCreateOptions = SandboxCreateOptions,\n> {\n createSandbox(\n options?: TOptions\n ): Promise<{ sandboxId: string; stateUpdate?: Record<string, unknown> }>;\n destroySandbox(sandboxId: string): Promise<void>;\n pauseSandbox(sandboxId: string): Promise<void>;\n snapshotSandbox(sandboxId: string): Promise<SandboxSnapshot>;\n forkSandbox(sandboxId: string): Promise<string>;\n}\n\n/**\n * Maps generic {@link SandboxOps} method names to adapter-prefixed names.\n *\n * @example\n * ```typescript\n * type InMemOps = PrefixedSandboxOps<\"inMemory\">;\n * // → { inMemoryCreateSandbox, inMemoryDestroySandbox, inMemorySnapshotSandbox }\n * ```\n */\nexport type PrefixedSandboxOps<\n TPrefix extends string,\n TOptions extends SandboxCreateOptions = SandboxCreateOptions,\n> = {\n [K in keyof SandboxOps<TOptions> as `${TPrefix}${Capitalize<K & string>}`]: SandboxOps<TOptions>[K];\n};\n\n// ============================================================================\n// Errors\n// ============================================================================\n\nimport { ApplicationFailure } from \"@temporalio/common\";\n\nexport class SandboxNotSupportedError extends ApplicationFailure {\n constructor(operation: string) {\n super(\n `Sandbox does not support: ${operation}`,\n \"SandboxNotSupportedError\",\n true\n );\n }\n}\n\nexport class SandboxNotFoundError extends ApplicationFailure {\n constructor(sandboxId: string) {\n super(`Sandbox not found: ${sandboxId}`, \"SandboxNotFoundError\", true);\n }\n}\n","import { FileType, type Sandbox as E2bSdkSandbox } from \"@e2b/code-interpreter\";\nimport type {\n SandboxFileSystem,\n DirentEntry,\n FileStat,\n} from \"../../../lib/sandbox/types\";\nimport { posix } from \"node:path\";\n\nfunction toArrayBuffer(u8: Uint8Array): ArrayBuffer {\n return u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength) as ArrayBuffer;\n}\n\n/**\n * {@link SandboxFileSystem} backed by an E2B SDK sandbox.\n *\n * Maps zeitlich's filesystem interface to E2B's `sandbox.files` and\n * `sandbox.commands` APIs. Operations that have no direct E2B equivalent\n * (e.g. `appendFile`, `cp`) are composed from primitives.\n */\nexport class E2bSandboxFileSystem implements SandboxFileSystem {\n readonly workspaceBase: string;\n\n constructor(\n private sandbox: E2bSdkSandbox,\n workspaceBase = \"/home/user\"\n ) {\n this.workspaceBase = posix.resolve(\"/\", workspaceBase);\n }\n\n private normalisePath(path: string): string {\n return posix.resolve(this.workspaceBase, path);\n }\n\n async readFile(path: string): Promise<string> {\n return this.sandbox.files.read(this.normalisePath(path));\n }\n\n async readFileBuffer(path: string): Promise<Uint8Array> {\n return this.sandbox.files.read(this.normalisePath(path), {\n format: \"bytes\",\n });\n }\n\n async writeFile(path: string, content: string | Uint8Array): Promise<void> {\n const norm = this.normalisePath(path);\n if (typeof content === \"string\") {\n await this.sandbox.files.write(norm, content);\n } else {\n await this.sandbox.files.write(norm, toArrayBuffer(content));\n }\n }\n\n async appendFile(path: string, content: string | Uint8Array): Promise<void> {\n const norm = this.normalisePath(path);\n let existing = \"\";\n try {\n existing = await this.sandbox.files.read(norm);\n } catch {\n // file doesn't exist yet — write from scratch\n }\n const addition =\n typeof content === \"string\"\n ? content\n : new TextDecoder().decode(content);\n await this.sandbox.files.write(norm, existing + addition);\n }\n\n async exists(path: string): Promise<boolean> {\n return this.sandbox.files.exists(this.normalisePath(path));\n }\n\n async stat(path: string): Promise<FileStat> {\n const norm = this.normalisePath(path);\n const info = await this.sandbox.files.getInfo(norm);\n const isSymlink = !!info.symlinkTarget;\n return {\n isFile: isSymlink ? false : info.type === FileType.FILE,\n isDirectory: isSymlink ? false : info.type === FileType.DIR,\n isSymbolicLink: isSymlink,\n size: info.size,\n mtime: info.modifiedTime ?? new Date(0),\n };\n }\n\n async mkdir(path: string, _options?: { recursive?: boolean }): Promise<void> {\n await this.sandbox.files.makeDir(this.normalisePath(path));\n }\n\n async readdir(path: string): Promise<string[]> {\n const entries = await this.sandbox.files.list(this.normalisePath(path));\n return entries.map((e) => posix.basename(e.path));\n }\n\n async readdirWithFileTypes(path: string): Promise<DirentEntry[]> {\n const entries = await this.sandbox.files.list(this.normalisePath(path));\n return entries.map((e) => {\n const isSymlink = !!e.symlinkTarget;\n return {\n name: posix.basename(e.path),\n isFile: isSymlink ? false : e.type === FileType.FILE,\n isDirectory: isSymlink ? false : e.type === FileType.DIR,\n isSymbolicLink: isSymlink,\n };\n });\n }\n\n async rm(\n path: string,\n options?: { recursive?: boolean; force?: boolean }\n ): Promise<void> {\n const norm = this.normalisePath(path);\n try {\n await this.sandbox.files.remove(norm);\n } catch (err) {\n if (!options?.force) throw err;\n }\n }\n\n async cp(\n src: string,\n dest: string,\n _options?: { recursive?: boolean }\n ): Promise<void> {\n const normSrc = this.normalisePath(src);\n const normDest = this.normalisePath(dest);\n await this.sandbox.commands.run(`cp -r \"${normSrc}\" \"${normDest}\"`);\n }\n\n async mv(src: string, dest: string): Promise<void> {\n const normSrc = this.normalisePath(src);\n const normDest = this.normalisePath(dest);\n await this.sandbox.files.rename(normSrc, normDest);\n }\n\n async readlink(path: string): Promise<string> {\n const norm = this.normalisePath(path);\n const info = await this.sandbox.files.getInfo(norm);\n if (!info.symlinkTarget) {\n throw new Error(`EINVAL: invalid argument, readlink '${path}'`);\n }\n return info.symlinkTarget;\n }\n\n resolvePath(base: string, path: string): string {\n return posix.resolve(this.normalisePath(base), path);\n }\n}\n","import { Sandbox as E2bSdkSandbox } from \"@e2b/code-interpreter\";\nimport type {\n Sandbox,\n SandboxCapabilities,\n SandboxCreateResult,\n SandboxProvider,\n SandboxSnapshot,\n ExecOptions,\n ExecResult,\n} from \"../../../lib/sandbox/types\";\nimport {\n SandboxNotFoundError,\n SandboxNotSupportedError,\n} from \"../../../lib/sandbox/types\";\nimport { E2bSandboxFileSystem } from \"./filesystem\";\nimport type {\n E2bSandbox,\n E2bSandboxConfig,\n E2bSandboxCreateOptions,\n} from \"./types\";\n\n// ============================================================================\n// E2bSandbox\n// ============================================================================\n\nclass E2bSandboxImpl implements Sandbox {\n readonly capabilities: SandboxCapabilities = {\n filesystem: true,\n execution: true,\n persistence: true,\n };\n\n readonly fs: E2bSandboxFileSystem;\n\n constructor(\n readonly id: string,\n private sdkSandbox: E2bSdkSandbox,\n workspaceBase = \"/home/user\"\n ) {\n this.fs = new E2bSandboxFileSystem(sdkSandbox, workspaceBase);\n }\n\n async exec(command: string, options?: ExecOptions): Promise<ExecResult> {\n const result = await this.sdkSandbox.commands.run(command, {\n cwd: options?.cwd,\n envs: options?.env,\n timeoutMs: options?.timeout,\n });\n return {\n exitCode: result.exitCode,\n stdout: result.stdout,\n stderr: result.stderr,\n };\n }\n\n async destroy(): Promise<void> {\n await this.sdkSandbox.kill();\n }\n}\n\n// ============================================================================\n// E2bSandboxProvider\n// ============================================================================\n\nexport class E2bSandboxProvider\n implements SandboxProvider<E2bSandboxCreateOptions, E2bSandbox>\n{\n readonly id = \"e2b\";\n readonly capabilities: SandboxCapabilities = {\n filesystem: true,\n execution: true,\n persistence: true,\n };\n\n private readonly defaultTemplate?: string;\n private readonly defaultWorkspaceBase: string;\n private readonly defaultTimeoutMs?: number;\n\n constructor(config?: E2bSandboxConfig) {\n this.defaultTemplate = config?.template;\n this.defaultWorkspaceBase = config?.workspaceBase ?? \"/home/user\";\n this.defaultTimeoutMs = config?.timeoutMs;\n }\n\n async create(\n options?: E2bSandboxCreateOptions\n ): Promise<SandboxCreateResult> {\n const template = options?.template ?? this.defaultTemplate;\n const workspaceBase = this.defaultWorkspaceBase;\n const createOpts = {\n envs: options?.env,\n timeoutMs: options?.timeoutMs ?? this.defaultTimeoutMs,\n };\n\n const sdkSandbox = template\n ? await E2bSdkSandbox.create(template, createOpts)\n : await E2bSdkSandbox.create(createOpts);\n\n const sandbox = new E2bSandboxImpl(\n sdkSandbox.sandboxId,\n sdkSandbox,\n workspaceBase\n );\n\n if (options?.initialFiles) {\n await Promise.all(\n Object.entries(options.initialFiles).map(([path, content]) =>\n sandbox.fs.writeFile(path, content)\n )\n );\n }\n\n return { sandbox };\n }\n\n async get(sandboxId: string): Promise<E2bSandbox> {\n try {\n const sdkSandbox = await E2bSdkSandbox.connect(sandboxId);\n return new E2bSandboxImpl(sandboxId, sdkSandbox, this.defaultWorkspaceBase);\n } catch {\n throw new SandboxNotFoundError(sandboxId);\n }\n }\n\n async destroy(sandboxId: string): Promise<void> {\n try {\n const sdkSandbox = await E2bSdkSandbox.connect(sandboxId);\n await sdkSandbox.kill();\n } catch {\n // Already gone or not found\n }\n }\n\n async pause(sandboxId: string, _ttlSeconds?: number): Promise<void> {\n const sdkSandbox = await E2bSdkSandbox.connect(sandboxId);\n await sdkSandbox.pause();\n }\n\n async snapshot(_sandboxId: string): Promise<SandboxSnapshot> {\n throw new SandboxNotSupportedError(\"snapshot\");\n }\n\n async restore(_snapshot: SandboxSnapshot): Promise<Sandbox> {\n throw new SandboxNotSupportedError(\"restore\");\n }\n\n async fork(sandboxId: string): Promise<Sandbox> {\n const { snapshotId } = await E2bSdkSandbox.createSnapshot(sandboxId);\n const sdkSandbox = await E2bSdkSandbox.create(snapshotId);\n return new E2bSandboxImpl(\n sdkSandbox.sandboxId,\n sdkSandbox,\n this.defaultWorkspaceBase\n );\n }\n}\n\n// Re-exports\nexport { E2bSandboxFileSystem } from \"./filesystem\";\nexport type {\n E2bSandbox,\n E2bSandboxConfig,\n E2bSandboxCreateOptions,\n} from \"./types\";\n"]}
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var workflow = require('@temporalio/workflow');
4
+
5
+ // src/adapters/sandbox/e2b/proxy.ts
6
+ var ADAPTER_PREFIX = "e2b";
7
+ function proxyE2bSandboxOps(scope, options) {
8
+ const resolvedScope = scope ?? workflow.workflowInfo().workflowType;
9
+ const acts = workflow.proxyActivities(
10
+ options ?? {
11
+ startToCloseTimeout: "120s",
12
+ retry: {
13
+ maximumAttempts: 3,
14
+ initialInterval: "5s",
15
+ maximumInterval: "60s",
16
+ backoffCoefficient: 3
17
+ }
18
+ }
19
+ );
20
+ const prefix = `${ADAPTER_PREFIX}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;
21
+ const p = (key) => `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;
22
+ return {
23
+ createSandbox: acts[p("createSandbox")],
24
+ destroySandbox: acts[p("destroySandbox")],
25
+ pauseSandbox: acts[p("pauseSandbox")],
26
+ snapshotSandbox: acts[p("snapshotSandbox")],
27
+ forkSandbox: acts[p("forkSandbox")]
28
+ };
29
+ }
30
+
31
+ exports.proxyE2bSandboxOps = proxyE2bSandboxOps;
32
+ //# sourceMappingURL=workflow.cjs.map
33
+ //# sourceMappingURL=workflow.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/adapters/sandbox/e2b/proxy.ts"],"names":["workflowInfo","proxyActivities"],"mappings":";;;;;AAuBA,IAAM,cAAA,GAAiB,KAAA;AAEhB,SAAS,kBAAA,CACd,OACA,OAAA,EACY;AACZ,EAAA,MAAM,aAAA,GAAgB,KAAA,IAASA,qBAAA,EAAa,CAAE,YAAA;AAG9C,EAAA,MAAM,IAAA,GAAOC,wBAAA;AAAA,IACX,OAAA,IAAW;AAAA,MACT,mBAAA,EAAqB,MAAA;AAAA,MACrB,KAAA,EAAO;AAAA,QACL,eAAA,EAAiB,CAAA;AAAA,QACjB,eAAA,EAAiB,IAAA;AAAA,QACjB,eAAA,EAAiB,KAAA;AAAA,QACjB,kBAAA,EAAoB;AAAA;AACtB;AACF,GACF;AAEA,EAAA,MAAM,MAAA,GAAS,CAAA,EAAG,cAAc,CAAA,EAAG,cAAc,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,aAAA,CAAc,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AACjG,EAAA,MAAM,IAAI,CAAC,GAAA,KACT,CAAA,EAAG,MAAM,GAAG,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA,CAAE,aAAa,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,aAAA,EAAe,IAAA,CAAK,CAAA,CAAE,eAAe,CAAC,CAAA;AAAA,IACtC,cAAA,EAAgB,IAAA,CAAK,CAAA,CAAE,gBAAgB,CAAC,CAAA;AAAA,IACxC,YAAA,EAAc,IAAA,CAAK,CAAA,CAAE,cAAc,CAAC,CAAA;AAAA,IACpC,eAAA,EAAiB,IAAA,CAAK,CAAA,CAAE,iBAAiB,CAAC,CAAA;AAAA,IAC1C,WAAA,EAAa,IAAA,CAAK,CAAA,CAAE,aAAa,CAAC;AAAA,GACpC;AACF","file":"workflow.cjs","sourcesContent":["/**\n * Workflow-safe proxy for E2B sandbox operations.\n *\n * Uses longer timeouts than in-memory providers since E2B\n * sandboxes are remote and creation involves provisioning.\n *\n * Import this from `zeitlich/adapters/sandbox/e2b/workflow`\n * in your Temporal workflow files.\n *\n * By default the scope is derived from `workflowInfo().workflowType`,\n * so activities are automatically namespaced per workflow.\n *\n * @example\n * ```typescript\n * import { proxyE2bSandboxOps } from 'zeitlich/adapters/sandbox/e2b/workflow';\n *\n * const sandbox = proxyE2bSandboxOps();\n * ```\n */\nimport { proxyActivities, workflowInfo } from \"@temporalio/workflow\";\nimport type { SandboxOps } from \"../../../lib/sandbox/types\";\nimport type { E2bSandboxCreateOptions } from \"./types\";\n\nconst ADAPTER_PREFIX = \"e2b\";\n\nexport function proxyE2bSandboxOps(\n scope?: string,\n options?: Parameters<typeof proxyActivities>[0]\n): SandboxOps {\n const resolvedScope = scope ?? workflowInfo().workflowType;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const acts = proxyActivities<Record<string, (...args: any[]) => any>>(\n options ?? {\n startToCloseTimeout: \"120s\",\n retry: {\n maximumAttempts: 3,\n initialInterval: \"5s\",\n maximumInterval: \"60s\",\n backoffCoefficient: 3,\n },\n }\n );\n\n const prefix = `${ADAPTER_PREFIX}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;\n const p = (key: string): string =>\n `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;\n\n return {\n createSandbox: acts[p(\"createSandbox\")],\n destroySandbox: acts[p(\"destroySandbox\")],\n pauseSandbox: acts[p(\"pauseSandbox\")],\n snapshotSandbox: acts[p(\"snapshotSandbox\")],\n forkSandbox: acts[p(\"forkSandbox\")],\n } as SandboxOps<E2bSandboxCreateOptions>;\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { proxyActivities } from '@temporalio/workflow';
2
+ import { g as SandboxOps } from '../../../types-ChAMwU3q.cjs';
3
+ import '@temporalio/common';
4
+
5
+ /**
6
+ * Workflow-safe proxy for E2B sandbox operations.
7
+ *
8
+ * Uses longer timeouts than in-memory providers since E2B
9
+ * sandboxes are remote and creation involves provisioning.
10
+ *
11
+ * Import this from `zeitlich/adapters/sandbox/e2b/workflow`
12
+ * in your Temporal workflow files.
13
+ *
14
+ * By default the scope is derived from `workflowInfo().workflowType`,
15
+ * so activities are automatically namespaced per workflow.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { proxyE2bSandboxOps } from 'zeitlich/adapters/sandbox/e2b/workflow';
20
+ *
21
+ * const sandbox = proxyE2bSandboxOps();
22
+ * ```
23
+ */
24
+
25
+ declare function proxyE2bSandboxOps(scope?: string, options?: Parameters<typeof proxyActivities>[0]): SandboxOps;
26
+
27
+ export { proxyE2bSandboxOps };
@@ -0,0 +1,27 @@
1
+ import { proxyActivities } from '@temporalio/workflow';
2
+ import { g as SandboxOps } from '../../../types-ChAMwU3q.js';
3
+ import '@temporalio/common';
4
+
5
+ /**
6
+ * Workflow-safe proxy for E2B sandbox operations.
7
+ *
8
+ * Uses longer timeouts than in-memory providers since E2B
9
+ * sandboxes are remote and creation involves provisioning.
10
+ *
11
+ * Import this from `zeitlich/adapters/sandbox/e2b/workflow`
12
+ * in your Temporal workflow files.
13
+ *
14
+ * By default the scope is derived from `workflowInfo().workflowType`,
15
+ * so activities are automatically namespaced per workflow.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { proxyE2bSandboxOps } from 'zeitlich/adapters/sandbox/e2b/workflow';
20
+ *
21
+ * const sandbox = proxyE2bSandboxOps();
22
+ * ```
23
+ */
24
+
25
+ declare function proxyE2bSandboxOps(scope?: string, options?: Parameters<typeof proxyActivities>[0]): SandboxOps;
26
+
27
+ export { proxyE2bSandboxOps };
@@ -0,0 +1,31 @@
1
+ import { workflowInfo, proxyActivities } from '@temporalio/workflow';
2
+
3
+ // src/adapters/sandbox/e2b/proxy.ts
4
+ var ADAPTER_PREFIX = "e2b";
5
+ function proxyE2bSandboxOps(scope, options) {
6
+ const resolvedScope = scope ?? workflowInfo().workflowType;
7
+ const acts = proxyActivities(
8
+ options ?? {
9
+ startToCloseTimeout: "120s",
10
+ retry: {
11
+ maximumAttempts: 3,
12
+ initialInterval: "5s",
13
+ maximumInterval: "60s",
14
+ backoffCoefficient: 3
15
+ }
16
+ }
17
+ );
18
+ const prefix = `${ADAPTER_PREFIX}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;
19
+ const p = (key) => `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;
20
+ return {
21
+ createSandbox: acts[p("createSandbox")],
22
+ destroySandbox: acts[p("destroySandbox")],
23
+ pauseSandbox: acts[p("pauseSandbox")],
24
+ snapshotSandbox: acts[p("snapshotSandbox")],
25
+ forkSandbox: acts[p("forkSandbox")]
26
+ };
27
+ }
28
+
29
+ export { proxyE2bSandboxOps };
30
+ //# sourceMappingURL=workflow.js.map
31
+ //# sourceMappingURL=workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/adapters/sandbox/e2b/proxy.ts"],"names":[],"mappings":";;;AAuBA,IAAM,cAAA,GAAiB,KAAA;AAEhB,SAAS,kBAAA,CACd,OACA,OAAA,EACY;AACZ,EAAA,MAAM,aAAA,GAAgB,KAAA,IAAS,YAAA,EAAa,CAAE,YAAA;AAG9C,EAAA,MAAM,IAAA,GAAO,eAAA;AAAA,IACX,OAAA,IAAW;AAAA,MACT,mBAAA,EAAqB,MAAA;AAAA,MACrB,KAAA,EAAO;AAAA,QACL,eAAA,EAAiB,CAAA;AAAA,QACjB,eAAA,EAAiB,IAAA;AAAA,QACjB,eAAA,EAAiB,KAAA;AAAA,QACjB,kBAAA,EAAoB;AAAA;AACtB;AACF,GACF;AAEA,EAAA,MAAM,MAAA,GAAS,CAAA,EAAG,cAAc,CAAA,EAAG,cAAc,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAa,CAAA,EAAG,aAAA,CAAc,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AACjG,EAAA,MAAM,IAAI,CAAC,GAAA,KACT,CAAA,EAAG,MAAM,GAAG,GAAA,CAAI,MAAA,CAAO,CAAC,CAAA,CAAE,aAAa,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AAExD,EAAA,OAAO;AAAA,IACL,aAAA,EAAe,IAAA,CAAK,CAAA,CAAE,eAAe,CAAC,CAAA;AAAA,IACtC,cAAA,EAAgB,IAAA,CAAK,CAAA,CAAE,gBAAgB,CAAC,CAAA;AAAA,IACxC,YAAA,EAAc,IAAA,CAAK,CAAA,CAAE,cAAc,CAAC,CAAA;AAAA,IACpC,eAAA,EAAiB,IAAA,CAAK,CAAA,CAAE,iBAAiB,CAAC,CAAA;AAAA,IAC1C,WAAA,EAAa,IAAA,CAAK,CAAA,CAAE,aAAa,CAAC;AAAA,GACpC;AACF","file":"workflow.js","sourcesContent":["/**\n * Workflow-safe proxy for E2B sandbox operations.\n *\n * Uses longer timeouts than in-memory providers since E2B\n * sandboxes are remote and creation involves provisioning.\n *\n * Import this from `zeitlich/adapters/sandbox/e2b/workflow`\n * in your Temporal workflow files.\n *\n * By default the scope is derived from `workflowInfo().workflowType`,\n * so activities are automatically namespaced per workflow.\n *\n * @example\n * ```typescript\n * import { proxyE2bSandboxOps } from 'zeitlich/adapters/sandbox/e2b/workflow';\n *\n * const sandbox = proxyE2bSandboxOps();\n * ```\n */\nimport { proxyActivities, workflowInfo } from \"@temporalio/workflow\";\nimport type { SandboxOps } from \"../../../lib/sandbox/types\";\nimport type { E2bSandboxCreateOptions } from \"./types\";\n\nconst ADAPTER_PREFIX = \"e2b\";\n\nexport function proxyE2bSandboxOps(\n scope?: string,\n options?: Parameters<typeof proxyActivities>[0]\n): SandboxOps {\n const resolvedScope = scope ?? workflowInfo().workflowType;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const acts = proxyActivities<Record<string, (...args: any[]) => any>>(\n options ?? {\n startToCloseTimeout: \"120s\",\n retry: {\n maximumAttempts: 3,\n initialInterval: \"5s\",\n maximumInterval: \"60s\",\n backoffCoefficient: 3,\n },\n }\n );\n\n const prefix = `${ADAPTER_PREFIX}${resolvedScope.charAt(0).toUpperCase()}${resolvedScope.slice(1)}`;\n const p = (key: string): string =>\n `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`;\n\n return {\n createSandbox: acts[p(\"createSandbox\")],\n destroySandbox: acts[p(\"destroySandbox\")],\n pauseSandbox: acts[p(\"pauseSandbox\")],\n snapshotSandbox: acts[p(\"snapshotSandbox\")],\n forkSandbox: acts[p(\"forkSandbox\")],\n } as SandboxOps<E2bSandboxCreateOptions>;\n}\n"]}
@@ -1,9 +1,9 @@
1
- import { a as FileEntryMetadata, V as VirtualSandboxCreateOptions, b as FileResolver, c as VirtualSandboxContext, T as TreeMutation, F as FileEntry, d as VirtualSandbox } from '../../../types-DRnz-OZp.cjs';
2
- export { e as VirtualFileTree, f as VirtualSandboxFileSystem, g as VirtualSandboxState } from '../../../types-DRnz-OZp.cjs';
1
+ import { a as FileEntryMetadata, V as VirtualSandboxCreateOptions, b as FileResolver, c as VirtualSandboxContext, T as TreeMutation, F as FileEntry, d as VirtualSandbox } from '../../../types-BgsAwN3L.cjs';
2
+ export { e as VirtualFileTree, f as VirtualSandboxFileSystem, g as VirtualSandboxState } from '../../../types-BgsAwN3L.cjs';
3
3
  import { b as SandboxProvider, c as SandboxCapabilities, e as SandboxCreateResult } from '../../../types-ChAMwU3q.cjs';
4
4
  import { WorkflowClient } from '@temporalio/client';
5
- import { J as JsonValue, A as ActivityToolHandler, R as RouterContext } from '../../../types-mCVxKIZb.cjs';
6
- export { F as FileTreeAccessor, f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from '../../../queries-DwnE2bu3.cjs';
5
+ import { J as JsonValue, A as ActivityToolHandler, R as RouterContext } from '../../../types-BclYm5Ic.cjs';
6
+ export { F as FileTreeAccessor, f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from '../../../queries-DVnukByF.cjs';
7
7
  import '@temporalio/common';
8
8
  import '@temporalio/workflow';
9
9
  import '@temporalio/common/lib/interfaces';
@@ -1,9 +1,9 @@
1
- import { a as FileEntryMetadata, V as VirtualSandboxCreateOptions, b as FileResolver, c as VirtualSandboxContext, T as TreeMutation, F as FileEntry, d as VirtualSandbox } from '../../../types-DFUNSYbj.js';
2
- export { e as VirtualFileTree, f as VirtualSandboxFileSystem, g as VirtualSandboxState } from '../../../types-DFUNSYbj.js';
1
+ import { a as FileEntryMetadata, V as VirtualSandboxCreateOptions, b as FileResolver, c as VirtualSandboxContext, T as TreeMutation, F as FileEntry, d as VirtualSandbox } from '../../../types-yU5AINiP.js';
2
+ export { e as VirtualFileTree, f as VirtualSandboxFileSystem, g as VirtualSandboxState } from '../../../types-yU5AINiP.js';
3
3
  import { b as SandboxProvider, c as SandboxCapabilities, e as SandboxCreateResult } from '../../../types-ChAMwU3q.js';
4
4
  import { WorkflowClient } from '@temporalio/client';
5
- import { J as JsonValue, A as ActivityToolHandler, R as RouterContext } from '../../../types-mCVxKIZb.js';
6
- export { F as FileTreeAccessor, f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from '../../../queries-BCgJ9Sr5.js';
5
+ import { J as JsonValue, A as ActivityToolHandler, R as RouterContext } from '../../../types-BclYm5Ic.js';
6
+ export { F as FileTreeAccessor, f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from '../../../queries-kjlvsUfz.js';
7
7
  import '@temporalio/common';
8
8
  import '@temporalio/workflow';
9
9
  import '@temporalio/common/lib/interfaces';
@@ -1,8 +1,8 @@
1
1
  import { proxyActivities } from '@temporalio/workflow';
2
2
  import { g as SandboxOps } from '../../../types-ChAMwU3q.cjs';
3
- import { V as VirtualSandboxCreateOptions } from '../../../types-DRnz-OZp.cjs';
3
+ import { V as VirtualSandboxCreateOptions } from '../../../types-BgsAwN3L.cjs';
4
4
  import '@temporalio/common';
5
- import '../../../types-mCVxKIZb.cjs';
5
+ import '../../../types-BclYm5Ic.cjs';
6
6
  import '@temporalio/common/lib/interfaces';
7
7
  import 'zod';
8
8
 
@@ -1,8 +1,8 @@
1
1
  import { proxyActivities } from '@temporalio/workflow';
2
2
  import { g as SandboxOps } from '../../../types-ChAMwU3q.js';
3
- import { V as VirtualSandboxCreateOptions } from '../../../types-DFUNSYbj.js';
3
+ import { V as VirtualSandboxCreateOptions } from '../../../types-yU5AINiP.js';
4
4
  import '@temporalio/common';
5
- import '../../../types-mCVxKIZb.js';
5
+ import '../../../types-BclYm5Ic.js';
6
6
  import '@temporalio/common/lib/interfaces';
7
7
  import 'zod';
8
8
 
@@ -161,17 +161,20 @@ function createAnthropicThreadManager(config) {
161
161
  },
162
162
  async prepareForInvocation() {
163
163
  const stored = await base.load();
164
+ const { onPrepareMessage, onPreparedMessage } = config.hooks ?? {};
165
+ const mapped = onPrepareMessage ? stored.map((msg, i) => onPrepareMessage(msg, i, stored)) : stored;
164
166
  let system;
165
167
  const conversationMessages = [];
166
- for (const item of stored) {
168
+ for (const item of mapped) {
167
169
  if (item.isSystem) {
168
170
  system = typeof item.message.content === "string" ? item.message.content : void 0;
169
171
  } else {
170
172
  conversationMessages.push(item.message);
171
173
  }
172
174
  }
175
+ const messages = mergeConsecutiveMessages(conversationMessages);
173
176
  return {
174
- messages: mergeConsecutiveMessages(conversationMessages),
177
+ messages: onPreparedMessage ? messages.map((msg, i) => onPreparedMessage(msg, i, messages)) : messages,
175
178
  ...system ? { system } : {}
176
179
  };
177
180
  }
@@ -236,11 +239,12 @@ function createAnthropicModelInvoker({
236
239
  redis,
237
240
  client,
238
241
  model,
239
- maxTokens = 16384
242
+ maxTokens = 16384,
243
+ hooks
240
244
  }) {
241
245
  return async function invokeAnthropicModel2(config) {
242
246
  const { threadId, threadKey, state } = config;
243
- const thread = createAnthropicThreadManager({ redis, threadId, key: threadKey });
247
+ const thread = createAnthropicThreadManager({ redis, threadId, key: threadKey, hooks });
244
248
  const { messages, system } = await thread.prepareForInvocation();
245
249
  const anthropicTools = toAnthropicTools(state.tools);
246
250
  const tools = anthropicTools.length > 0 ? anthropicTools : void 0;
@@ -276,13 +280,15 @@ async function invokeAnthropicModel({
276
280
  client,
277
281
  model,
278
282
  maxTokens,
283
+ hooks,
279
284
  config
280
285
  }) {
281
286
  const invoker = createAnthropicModelInvoker({
282
287
  redis,
283
288
  client,
284
289
  model,
285
- maxTokens
290
+ maxTokens,
291
+ hooks
286
292
  });
287
293
  return invoker(config);
288
294
  }
@@ -331,7 +337,8 @@ function createAnthropicAdapter(config) {
331
337
  client,
332
338
  model,
333
339
  ...maxTokens !== void 0 ? { maxTokens } : {},
334
- ...config.maxTokens !== void 0 && maxTokens === void 0 ? { maxTokens: config.maxTokens } : {}
340
+ ...config.maxTokens !== void 0 && maxTokens === void 0 ? { maxTokens: config.maxTokens } : {},
341
+ hooks: config.hooks
335
342
  };
336
343
  return createAnthropicModelInvoker(invokerConfig);
337
344
  };