zeitlich 0.2.29 → 0.2.31
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-DOViDCTE.d.ts → activities-DRSdt8Y3.d.ts} +2 -2
- package/dist/{activities-1xrWRrGJ.d.cts → activities-qPkJDAiq.d.cts} +2 -2
- package/dist/adapters/sandbox/bedrock/index.cjs.map +1 -1
- package/dist/adapters/sandbox/bedrock/index.d.cts +3 -3
- package/dist/adapters/sandbox/bedrock/index.d.ts +3 -3
- package/dist/adapters/sandbox/bedrock/index.js.map +1 -1
- package/dist/adapters/sandbox/bedrock/workflow.d.cts +2 -2
- package/dist/adapters/sandbox/bedrock/workflow.d.ts +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +1 -1
- package/dist/adapters/sandbox/daytona/index.d.ts +1 -1
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.ts +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/index.d.ts +1 -1
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.ts +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.ts +1 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +1 -1
- package/dist/adapters/thread/anthropic/index.cjs +0 -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 +0 -1
- 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 +0 -1
- 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 +0 -1
- 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 +0 -1
- 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 +0 -1
- 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 +95 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -15
- package/dist/index.d.ts +78 -15
- package/dist/index.js +95 -54
- package/dist/index.js.map +1 -1
- package/dist/{proxy-Bm2UTiO_.d.cts → proxy-BDQ3Rj6R.d.cts} +1 -1
- package/dist/{proxy-78nc985d.d.ts → proxy-BkvkV2oU.d.ts} +1 -1
- package/dist/{thread-manager-CatBkarc.d.cts → thread-manager-BLgvv9Gf.d.cts} +1 -1
- package/dist/{thread-manager-CxbWo7q_.d.ts → thread-manager-Cv82H1wi.d.ts} +1 -1
- package/dist/{thread-manager-BRE5KkHB.d.cts → thread-manager-DowU4ntB.d.cts} +1 -1
- package/dist/{thread-manager-07BaYu_z.d.ts → thread-manager-HsAYkyAV.d.ts} +1 -1
- package/dist/{types-ChAMwU3q.d.ts → types-AujBIMMn.d.cts} +5 -8
- package/dist/{types-ChAMwU3q.d.cts → types-AujBIMMn.d.ts} +5 -8
- package/dist/{types-BkVoEyiH.d.ts → types-BmS-Huc0.d.ts} +145 -139
- package/dist/{types-seDYom4M.d.cts → types-CjeGWQm1.d.cts} +145 -139
- package/dist/{types-DAv_SLN8.d.ts → types-D6UKZZtj.d.ts} +1 -1
- package/dist/{types-BdCdR41N.d.ts → types-DBk-C8zM.d.ts} +1 -1
- package/dist/{types-ZHs2v9Ap.d.cts → types-DUvEZSDe.d.cts} +1 -1
- package/dist/{types-Dpz2gXLk.d.cts → types-e_38QaKo.d.cts} +1 -1
- package/dist/{workflow-B4T3la0p.d.cts → workflow-CNshfqSO.d.cts} +2 -2
- package/dist/{workflow-DCmaXLZ_.d.ts → workflow-CTcrPZAV.d.ts} +2 -2
- package/dist/workflow.cjs +43 -43
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +3 -3
- package/dist/workflow.d.ts +3 -3
- package/dist/workflow.js +43 -43
- package/dist/workflow.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/thread/anthropic/thread-manager.ts +6 -6
- package/src/adapters/thread/google-genai/thread-manager.ts +6 -6
- package/src/adapters/thread/langchain/thread-manager.ts +6 -6
- package/src/index.ts +1 -0
- package/src/lib/lifecycle.ts +8 -3
- package/src/lib/sandbox/index.ts +2 -4
- package/src/lib/sandbox/manager.ts +128 -13
- package/src/lib/sandbox/sandbox.test.ts +136 -16
- package/src/lib/sandbox/types.ts +6 -5
- package/src/lib/session/session.integration.test.ts +7 -40
- package/src/lib/session/session.ts +78 -50
- package/src/lib/session/types.ts +22 -13
- package/src/lib/state/types.ts +9 -6
- package/src/lib/subagent/handler.ts +18 -12
- package/src/lib/subagent/register.ts +11 -12
- package/src/lib/types.ts +4 -0
- package/src/lib/virtual-fs/filesystem.ts +15 -0
- package/src/lib/virtual-fs/types.ts +10 -14
- package/src/lib/virtual-fs/virtual-fs.test.ts +64 -0
- package/src/lib/virtual-fs/with-virtual-fs.ts +4 -3
- package/src/tools/bash/bash.test.ts +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-
|
|
2
|
-
export { A as AskUserQuestionArgs, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as TaskCreateArgs, g as TaskGetArgs, h as TaskListArgs, i as TaskUpdateArgs, j as ToolExecutedEvent, k as TurnCompletedEvent, W as WorkflowConfig, l as WorkflowInput, m as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, n as applyVirtualTreeMutations, o as askUserQuestionTool, p as bashTool, q as composeHooks, r as createAgentStateManager, s as createAskUserQuestionHandler, t as createBashToolDescription, u as createObservabilityHooks, v as createReadSkillHandler, w as createReadSkillTool, x as createSession, y as createTaskCreateHandler, z as createTaskGetHandler, C as createTaskListHandler, D as createTaskUpdateHandler, E as createToolRouter, H as defineSubagent, I as defineSubagentWorkflow, J as defineTool, K as defineWorkflow, L as editTool, M as filesWithMimeType, N as formatVirtualFileTree, P as getShortId, Q as globTool, U as grepTool, V as hasDirectory, X as hasFileWithMimeType, Y as hasNoOtherToolCalls, _ as parseSkillFile, $ as proxyVirtualFsOps, a0 as readFileTool, a1 as taskCreateTool, a2 as taskGetTool, a3 as taskListTool, a4 as taskUpdateTool, a5 as writeFileTool } from './workflow-
|
|
3
|
-
import { R as RouterContext, d as ToolResultConfig, c as ActivityToolHandler, J as JsonValue, b as ToolHandlerResponse, B as BaseAgentState, e as RunAgentConfig, f as SkillProvider, g as SkillMetadata, h as Skill, F as FileEntryMetadata, i as FileResolver, V as VirtualFsContext, j as TreeMutation, k as PrefixedVirtualFsOps } from './types-
|
|
4
|
-
export { l as AgentConfig, m as AgentFile, A as AgentResponse, n as AgentState, o as AgentStateManager, p as AgentStatus, q as AppendToolResultFn, r as FileEntry, H as Hooks, I as InferToolResults, s as JsonPrimitive, t as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, u as ParsedToolCall, v as ParsedToolCallUnion, w as PostHumanMessageAppendHook, x as PostHumanMessageAppendHookContext, y as PostToolUseFailureHook, z as PostToolUseFailureHookContext, C as PostToolUseFailureHookResult, D as PostToolUseHook, E as PostToolUseHookContext, G as PreHumanMessageAppendHook, K as PreHumanMessageAppendHookContext, L as PreToolUseHook, N as PreToolUseHookContext, O as PreToolUseHookResult, P as PrefixedThreadOps, Q as ProcessToolCallsContext, U as RawToolCall, W as RunAgentActivity, X as SandboxInit, Y as SandboxShutdown, S as ScopedPrefix, Z as SerializableToolDefinition, _ as SessionConfig, $ as SessionEndHook, a0 as SessionEndHookContext, a1 as SessionExitReason, a2 as SessionResult, a3 as SessionStartHook, a4 as SessionStartHookContext, a5 as SubagentConfig, a6 as SubagentDefinition, a7 as SubagentFnResult, a8 as SubagentHandlerResponse, a9 as SubagentHooks, aa as SubagentSandboxConfig, ab as SubagentSandboxShutdown, ac as SubagentSessionInput, ad as SubagentWorkflow, ae as SubagentWorkflowInput, af as TaskStatus, ag as ThreadInit, T as ThreadOps, ah as TokenUsage, ai as ToolArgs, aj as ToolCallResult, ak as ToolCallResultUnion, al as ToolDefinition, am as ToolHandler, an as ToolHooks, ao as ToolMap, ap as ToolNames, aq as ToolResult, ar as ToolRouter, as as ToolRouterHooks, at as ToolWithHandler, au as VirtualFileSystem, av as VirtualFileTree, aw as VirtualFsOps, ax as VirtualFsState, ay as WorkflowTask, az as ZeitlichSession, aA as isTerminalStatus } from './types-
|
|
5
|
-
import { S as Sandbox, a as SandboxFileSystem, d as SandboxCreateOptions, b as SandboxProvider, f as SandboxSnapshot, P as PrefixedSandboxOps, F as FileStat, D as DirentEntry, E as ExecResult } from './types-
|
|
6
|
-
export { h as ExecOptions, c as SandboxCapabilities, e as SandboxCreateResult, i as SandboxNotFoundError, j as SandboxNotSupportedError, g as SandboxOps } from './types-
|
|
1
|
+
import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-CNshfqSO.cjs';
|
|
2
|
+
export { A as AskUserQuestionArgs, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as TaskCreateArgs, g as TaskGetArgs, h as TaskListArgs, i as TaskUpdateArgs, j as ToolExecutedEvent, k as TurnCompletedEvent, W as WorkflowConfig, l as WorkflowInput, m as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, n as applyVirtualTreeMutations, o as askUserQuestionTool, p as bashTool, q as composeHooks, r as createAgentStateManager, s as createAskUserQuestionHandler, t as createBashToolDescription, u as createObservabilityHooks, v as createReadSkillHandler, w as createReadSkillTool, x as createSession, y as createTaskCreateHandler, z as createTaskGetHandler, C as createTaskListHandler, D as createTaskUpdateHandler, E as createToolRouter, H as defineSubagent, I as defineSubagentWorkflow, J as defineTool, K as defineWorkflow, L as editTool, M as filesWithMimeType, N as formatVirtualFileTree, P as getShortId, Q as globTool, U as grepTool, V as hasDirectory, X as hasFileWithMimeType, Y as hasNoOtherToolCalls, _ as parseSkillFile, $ as proxyVirtualFsOps, a0 as readFileTool, a1 as taskCreateTool, a2 as taskGetTool, a3 as taskListTool, a4 as taskUpdateTool, a5 as writeFileTool } from './workflow-CNshfqSO.cjs';
|
|
3
|
+
import { R as RouterContext, d as ToolResultConfig, c as ActivityToolHandler, J as JsonValue, b as ToolHandlerResponse, B as BaseAgentState, e as RunAgentConfig, f as SkillProvider, g as SkillMetadata, h as Skill, F as FileEntryMetadata, i as FileResolver, V as VirtualFsContext, j as TreeMutation, k as PrefixedVirtualFsOps } from './types-CjeGWQm1.cjs';
|
|
4
|
+
export { l as AgentConfig, m as AgentFile, A as AgentResponse, n as AgentState, o as AgentStateManager, p as AgentStatus, q as AppendToolResultFn, r as FileEntry, H as Hooks, I as InferToolResults, s as JsonPrimitive, t as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, u as ParsedToolCall, v as ParsedToolCallUnion, w as PostHumanMessageAppendHook, x as PostHumanMessageAppendHookContext, y as PostToolUseFailureHook, z as PostToolUseFailureHookContext, C as PostToolUseFailureHookResult, D as PostToolUseHook, E as PostToolUseHookContext, G as PreHumanMessageAppendHook, K as PreHumanMessageAppendHookContext, L as PreToolUseHook, N as PreToolUseHookContext, O as PreToolUseHookResult, P as PrefixedThreadOps, Q as ProcessToolCallsContext, U as RawToolCall, W as RunAgentActivity, X as SandboxInit, Y as SandboxShutdown, S as ScopedPrefix, Z as SerializableToolDefinition, _ as SessionConfig, $ as SessionEndHook, a0 as SessionEndHookContext, a1 as SessionExitReason, a2 as SessionResult, a3 as SessionStartHook, a4 as SessionStartHookContext, a5 as SubagentConfig, a6 as SubagentDefinition, a7 as SubagentFnResult, a8 as SubagentHandlerResponse, a9 as SubagentHooks, aa as SubagentSandboxConfig, ab as SubagentSandboxShutdown, ac as SubagentSessionInput, ad as SubagentWorkflow, ae as SubagentWorkflowInput, af as TaskStatus, ag as ThreadInit, T as ThreadOps, ah as TokenUsage, ai as ToolArgs, aj as ToolCallResult, ak as ToolCallResultUnion, al as ToolDefinition, am as ToolHandler, an as ToolHooks, ao as ToolMap, ap as ToolNames, aq as ToolResult, ar as ToolRouter, as as ToolRouterHooks, at as ToolWithHandler, au as VirtualFileSystem, av as VirtualFileTree, aw as VirtualFsOps, ax as VirtualFsState, ay as WorkflowTask, az as ZeitlichSession, aA as isTerminalStatus } from './types-CjeGWQm1.cjs';
|
|
5
|
+
import { S as Sandbox, a as SandboxFileSystem, d as SandboxCreateOptions, b as SandboxProvider, f as SandboxSnapshot, P as PrefixedSandboxOps, F as FileStat, D as DirentEntry, E as ExecResult } from './types-AujBIMMn.cjs';
|
|
6
|
+
export { h as ExecOptions, c as SandboxCapabilities, e as SandboxCreateResult, i as SandboxNotFoundError, j as SandboxNotSupportedError, g as SandboxOps } from './types-AujBIMMn.cjs';
|
|
7
7
|
import { WorkflowClient } from '@temporalio/client';
|
|
8
|
-
import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-
|
|
9
|
-
export { P as ProviderThreadManager } from './types-
|
|
8
|
+
import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-e_38QaKo.cjs';
|
|
9
|
+
export { P as ProviderThreadManager } from './types-e_38QaKo.cjs';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@temporalio/workflow';
|
|
12
12
|
import '@temporalio/common';
|
|
@@ -191,12 +191,53 @@ declare class FileSystemSkillProvider implements SkillProvider {
|
|
|
191
191
|
*/
|
|
192
192
|
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Result returned by {@link SandboxManagerHooks.onPreCreate}.
|
|
196
|
+
*
|
|
197
|
+
* - Set `skip: true` to prevent sandbox creation entirely.
|
|
198
|
+
* - Set `modifiedOptions` to override/extend the creation options that will
|
|
199
|
+
* be forwarded to the provider. Fields in `modifiedOptions` are merged on
|
|
200
|
+
* top of the original options (`initialFiles` and `env` are shallow-merged;
|
|
201
|
+
* everything else is overwritten).
|
|
202
|
+
*/
|
|
203
|
+
interface PreCreateHookResult<TOptions extends SandboxCreateOptions = SandboxCreateOptions> {
|
|
204
|
+
skip?: boolean;
|
|
205
|
+
modifiedOptions?: Partial<TOptions>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Lifecycle hooks for {@link SandboxManager}.
|
|
209
|
+
*
|
|
210
|
+
* Hooks run inside the existing `createSandbox` activity — no additional
|
|
211
|
+
* activity registration required.
|
|
212
|
+
*/
|
|
213
|
+
interface SandboxManagerHooks<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TCtx = unknown> {
|
|
214
|
+
/**
|
|
215
|
+
* Called before sandbox creation.
|
|
216
|
+
*
|
|
217
|
+
* Receives the provider options and an opaque `ctx` value set from the
|
|
218
|
+
* workflow's {@link SandboxInit}. Use `ctx` to derive additional creation
|
|
219
|
+
* options (e.g. initial files from workflow arguments).
|
|
220
|
+
*
|
|
221
|
+
* Return `{ skip: true }` to prevent creation, or `{ modifiedOptions }`
|
|
222
|
+
* to alter the options before they reach the provider.
|
|
223
|
+
*/
|
|
224
|
+
onPreCreate?: (options: TOptions, ctx: TCtx) => Promise<PreCreateHookResult<TOptions> | undefined>;
|
|
225
|
+
/**
|
|
226
|
+
* Called after a sandbox has been successfully created.
|
|
227
|
+
*/
|
|
228
|
+
onPostCreate?: (sandboxId: string) => Promise<void>;
|
|
229
|
+
}
|
|
194
230
|
/**
|
|
195
231
|
* Stateless facade over a {@link SandboxProvider}.
|
|
196
232
|
*
|
|
197
233
|
* Delegates all lifecycle operations to the provider, which is responsible
|
|
198
234
|
* for its own instance management strategy (e.g. in-memory map, remote API).
|
|
199
235
|
*
|
|
236
|
+
* Optional {@link SandboxManagerHooks} can be passed at construction time.
|
|
237
|
+
* The `onPreCreate` hook runs inside the `createSandbox` activity, receiving
|
|
238
|
+
* the provider options and an opaque `ctx` value from the workflow's
|
|
239
|
+
* {@link SandboxInit}. It can modify options or skip creation entirely.
|
|
240
|
+
*
|
|
200
241
|
* @example
|
|
201
242
|
* ```typescript
|
|
202
243
|
* const manager = new SandboxManager(new InMemorySandboxProvider());
|
|
@@ -206,16 +247,38 @@ declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThr
|
|
|
206
247
|
* };
|
|
207
248
|
* // registers: inMemoryCodingAgentCreateSandbox, …
|
|
208
249
|
* ```
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const manager = new SandboxManager(
|
|
254
|
+
* new DaytonaSandboxProvider(config),
|
|
255
|
+
* {
|
|
256
|
+
* hooks: {
|
|
257
|
+
* onPreCreate: async (options, ctx) => {
|
|
258
|
+
* const { projectId, filePaths } = ctx as { projectId: string; filePaths: string[] };
|
|
259
|
+
* const files: Record<string, string> = {};
|
|
260
|
+
* for (const p of filePaths) files[p] = await db.readFile(projectId, p);
|
|
261
|
+
* return { modifiedOptions: { initialFiles: files } };
|
|
262
|
+
* },
|
|
263
|
+
* onPostCreate: async (sandboxId) => {
|
|
264
|
+
* console.log("Sandbox created:", sandboxId);
|
|
265
|
+
* },
|
|
266
|
+
* },
|
|
267
|
+
* },
|
|
268
|
+
* );
|
|
269
|
+
* ```
|
|
209
270
|
*/
|
|
210
|
-
declare class SandboxManager<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TSandbox extends Sandbox = Sandbox, TId extends string = string> {
|
|
271
|
+
declare class SandboxManager<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TSandbox extends Sandbox = Sandbox, TId extends string = string, TCtx = unknown> {
|
|
211
272
|
private provider;
|
|
273
|
+
private hooks;
|
|
212
274
|
constructor(provider: SandboxProvider<TOptions, TSandbox> & {
|
|
213
275
|
readonly id: TId;
|
|
276
|
+
}, options?: {
|
|
277
|
+
hooks?: SandboxManagerHooks<TOptions, TCtx>;
|
|
214
278
|
});
|
|
215
|
-
create(options?: TOptions): Promise<{
|
|
279
|
+
create(options?: TOptions, ctx?: TCtx): Promise<{
|
|
216
280
|
sandboxId: string;
|
|
217
|
-
|
|
218
|
-
}>;
|
|
281
|
+
} | null>;
|
|
219
282
|
getSandbox(id: string): Promise<TSandbox>;
|
|
220
283
|
destroy(id: string): Promise<void>;
|
|
221
284
|
pause(id: string, ttlSeconds?: number): Promise<void>;
|
|
@@ -242,7 +305,7 @@ declare class SandboxManager<TOptions extends SandboxCreateOptions = SandboxCrea
|
|
|
242
305
|
* // registers: daytonaCodingAgentCreateSandbox, …
|
|
243
306
|
* ```
|
|
244
307
|
*/
|
|
245
|
-
createActivities<S extends string>(scope: S): PrefixedSandboxOps<`${TId}${Capitalize<S>}`, TOptions>;
|
|
308
|
+
createActivities<S extends string>(scope: S): PrefixedSandboxOps<`${TId}${Capitalize<S>}`, TOptions, TCtx>;
|
|
246
309
|
}
|
|
247
310
|
|
|
248
311
|
/**
|
|
@@ -293,7 +356,7 @@ declare class NodeFsSandboxFileSystem implements SandboxFileSystem {
|
|
|
293
356
|
* the parent workflow for the current file tree and resolver context.
|
|
294
357
|
*
|
|
295
358
|
* On each invocation the wrapper:
|
|
296
|
-
* 1. Queries the workflow's `AgentState` for `fileTree`, `
|
|
359
|
+
* 1. Queries the workflow's `AgentState` for `fileTree`, `ctx`, and `workspaceBase`
|
|
297
360
|
* 2. Creates an ephemeral {@link VirtualFileSystem} from tree + resolver
|
|
298
361
|
* 3. Runs the inner handler
|
|
299
362
|
* 4. Returns the handler's result together with any {@link TreeMutation}s
|
|
@@ -433,4 +496,4 @@ declare const toTree: (fs: SandboxFileSystem, opts?: {
|
|
|
433
496
|
sort?: boolean;
|
|
434
497
|
}) => Promise<string>;
|
|
435
498
|
|
|
436
|
-
export { ActivityToolHandler, type AgentStateContext, BaseAgentState, BaseThreadManager, BashArgs, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, GlobArgs, JsonValue, NodeFsSandboxFileSystem, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, bashHandler, createRunAgentActivity, createThreadManager, createVirtualFsActivities, editHandler, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };
|
|
499
|
+
export { ActivityToolHandler, type AgentStateContext, BaseAgentState, BaseThreadManager, BashArgs, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, GlobArgs, JsonValue, NodeFsSandboxFileSystem, type PreCreateHookResult, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, type SandboxManagerHooks, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, bashHandler, createRunAgentActivity, createThreadManager, createVirtualFsActivities, editHandler, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-
|
|
2
|
-
export { A as AskUserQuestionArgs, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as TaskCreateArgs, g as TaskGetArgs, h as TaskListArgs, i as TaskUpdateArgs, j as ToolExecutedEvent, k as TurnCompletedEvent, W as WorkflowConfig, l as WorkflowInput, m as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, n as applyVirtualTreeMutations, o as askUserQuestionTool, p as bashTool, q as composeHooks, r as createAgentStateManager, s as createAskUserQuestionHandler, t as createBashToolDescription, u as createObservabilityHooks, v as createReadSkillHandler, w as createReadSkillTool, x as createSession, y as createTaskCreateHandler, z as createTaskGetHandler, C as createTaskListHandler, D as createTaskUpdateHandler, E as createToolRouter, H as defineSubagent, I as defineSubagentWorkflow, J as defineTool, K as defineWorkflow, L as editTool, M as filesWithMimeType, N as formatVirtualFileTree, P as getShortId, Q as globTool, U as grepTool, V as hasDirectory, X as hasFileWithMimeType, Y as hasNoOtherToolCalls, _ as parseSkillFile, $ as proxyVirtualFsOps, a0 as readFileTool, a1 as taskCreateTool, a2 as taskGetTool, a3 as taskListTool, a4 as taskUpdateTool, a5 as writeFileTool } from './workflow-
|
|
3
|
-
import { R as RouterContext, d as ToolResultConfig, c as ActivityToolHandler, J as JsonValue, b as ToolHandlerResponse, B as BaseAgentState, e as RunAgentConfig, f as SkillProvider, g as SkillMetadata, h as Skill, F as FileEntryMetadata, i as FileResolver, V as VirtualFsContext, j as TreeMutation, k as PrefixedVirtualFsOps } from './types-
|
|
4
|
-
export { l as AgentConfig, m as AgentFile, A as AgentResponse, n as AgentState, o as AgentStateManager, p as AgentStatus, q as AppendToolResultFn, r as FileEntry, H as Hooks, I as InferToolResults, s as JsonPrimitive, t as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, u as ParsedToolCall, v as ParsedToolCallUnion, w as PostHumanMessageAppendHook, x as PostHumanMessageAppendHookContext, y as PostToolUseFailureHook, z as PostToolUseFailureHookContext, C as PostToolUseFailureHookResult, D as PostToolUseHook, E as PostToolUseHookContext, G as PreHumanMessageAppendHook, K as PreHumanMessageAppendHookContext, L as PreToolUseHook, N as PreToolUseHookContext, O as PreToolUseHookResult, P as PrefixedThreadOps, Q as ProcessToolCallsContext, U as RawToolCall, W as RunAgentActivity, X as SandboxInit, Y as SandboxShutdown, S as ScopedPrefix, Z as SerializableToolDefinition, _ as SessionConfig, $ as SessionEndHook, a0 as SessionEndHookContext, a1 as SessionExitReason, a2 as SessionResult, a3 as SessionStartHook, a4 as SessionStartHookContext, a5 as SubagentConfig, a6 as SubagentDefinition, a7 as SubagentFnResult, a8 as SubagentHandlerResponse, a9 as SubagentHooks, aa as SubagentSandboxConfig, ab as SubagentSandboxShutdown, ac as SubagentSessionInput, ad as SubagentWorkflow, ae as SubagentWorkflowInput, af as TaskStatus, ag as ThreadInit, T as ThreadOps, ah as TokenUsage, ai as ToolArgs, aj as ToolCallResult, ak as ToolCallResultUnion, al as ToolDefinition, am as ToolHandler, an as ToolHooks, ao as ToolMap, ap as ToolNames, aq as ToolResult, ar as ToolRouter, as as ToolRouterHooks, at as ToolWithHandler, au as VirtualFileSystem, av as VirtualFileTree, aw as VirtualFsOps, ax as VirtualFsState, ay as WorkflowTask, az as ZeitlichSession, aA as isTerminalStatus } from './types-
|
|
5
|
-
import { S as Sandbox, a as SandboxFileSystem, d as SandboxCreateOptions, b as SandboxProvider, f as SandboxSnapshot, P as PrefixedSandboxOps, F as FileStat, D as DirentEntry, E as ExecResult } from './types-
|
|
6
|
-
export { h as ExecOptions, c as SandboxCapabilities, e as SandboxCreateResult, i as SandboxNotFoundError, j as SandboxNotSupportedError, g as SandboxOps } from './types-
|
|
1
|
+
import { B as BashArgs, F as FileEditArgs, G as GlobArgs, a as FileReadArgs, b as FileWriteArgs } from './workflow-CTcrPZAV.js';
|
|
2
|
+
export { A as AskUserQuestionArgs, c as FileTreeAccessor, d as GrepArgs, O as ObservabilityHooks, R as ReadSkillArgs, S as SessionEndedEvent, e as SessionStartedEvent, f as SubagentArgs, T as TaskCreateArgs, g as TaskGetArgs, h as TaskListArgs, i as TaskUpdateArgs, j as ToolExecutedEvent, k as TurnCompletedEvent, W as WorkflowConfig, l as WorkflowInput, m as WorkflowSessionInput, Z as ZeitlichObservabilitySinks, n as applyVirtualTreeMutations, o as askUserQuestionTool, p as bashTool, q as composeHooks, r as createAgentStateManager, s as createAskUserQuestionHandler, t as createBashToolDescription, u as createObservabilityHooks, v as createReadSkillHandler, w as createReadSkillTool, x as createSession, y as createTaskCreateHandler, z as createTaskGetHandler, C as createTaskListHandler, D as createTaskUpdateHandler, E as createToolRouter, H as defineSubagent, I as defineSubagentWorkflow, J as defineTool, K as defineWorkflow, L as editTool, M as filesWithMimeType, N as formatVirtualFileTree, P as getShortId, Q as globTool, U as grepTool, V as hasDirectory, X as hasFileWithMimeType, Y as hasNoOtherToolCalls, _ as parseSkillFile, $ as proxyVirtualFsOps, a0 as readFileTool, a1 as taskCreateTool, a2 as taskGetTool, a3 as taskListTool, a4 as taskUpdateTool, a5 as writeFileTool } from './workflow-CTcrPZAV.js';
|
|
3
|
+
import { R as RouterContext, d as ToolResultConfig, c as ActivityToolHandler, J as JsonValue, b as ToolHandlerResponse, B as BaseAgentState, e as RunAgentConfig, f as SkillProvider, g as SkillMetadata, h as Skill, F as FileEntryMetadata, i as FileResolver, V as VirtualFsContext, j as TreeMutation, k as PrefixedVirtualFsOps } from './types-BmS-Huc0.js';
|
|
4
|
+
export { l as AgentConfig, m as AgentFile, A as AgentResponse, n as AgentState, o as AgentStateManager, p as AgentStatus, q as AppendToolResultFn, r as FileEntry, H as Hooks, I as InferToolResults, s as JsonPrimitive, t as JsonSerializable, a as ModelInvoker, M as ModelInvokerConfig, u as ParsedToolCall, v as ParsedToolCallUnion, w as PostHumanMessageAppendHook, x as PostHumanMessageAppendHookContext, y as PostToolUseFailureHook, z as PostToolUseFailureHookContext, C as PostToolUseFailureHookResult, D as PostToolUseHook, E as PostToolUseHookContext, G as PreHumanMessageAppendHook, K as PreHumanMessageAppendHookContext, L as PreToolUseHook, N as PreToolUseHookContext, O as PreToolUseHookResult, P as PrefixedThreadOps, Q as ProcessToolCallsContext, U as RawToolCall, W as RunAgentActivity, X as SandboxInit, Y as SandboxShutdown, S as ScopedPrefix, Z as SerializableToolDefinition, _ as SessionConfig, $ as SessionEndHook, a0 as SessionEndHookContext, a1 as SessionExitReason, a2 as SessionResult, a3 as SessionStartHook, a4 as SessionStartHookContext, a5 as SubagentConfig, a6 as SubagentDefinition, a7 as SubagentFnResult, a8 as SubagentHandlerResponse, a9 as SubagentHooks, aa as SubagentSandboxConfig, ab as SubagentSandboxShutdown, ac as SubagentSessionInput, ad as SubagentWorkflow, ae as SubagentWorkflowInput, af as TaskStatus, ag as ThreadInit, T as ThreadOps, ah as TokenUsage, ai as ToolArgs, aj as ToolCallResult, ak as ToolCallResultUnion, al as ToolDefinition, am as ToolHandler, an as ToolHooks, ao as ToolMap, ap as ToolNames, aq as ToolResult, ar as ToolRouter, as as ToolRouterHooks, at as ToolWithHandler, au as VirtualFileSystem, av as VirtualFileTree, aw as VirtualFsOps, ax as VirtualFsState, ay as WorkflowTask, az as ZeitlichSession, aA as isTerminalStatus } from './types-BmS-Huc0.js';
|
|
5
|
+
import { S as Sandbox, a as SandboxFileSystem, d as SandboxCreateOptions, b as SandboxProvider, f as SandboxSnapshot, P as PrefixedSandboxOps, F as FileStat, D as DirentEntry, E as ExecResult } from './types-AujBIMMn.js';
|
|
6
|
+
export { h as ExecOptions, c as SandboxCapabilities, e as SandboxCreateResult, i as SandboxNotFoundError, j as SandboxNotSupportedError, g as SandboxOps } from './types-AujBIMMn.js';
|
|
7
7
|
import { WorkflowClient } from '@temporalio/client';
|
|
8
|
-
import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-
|
|
9
|
-
export { P as ProviderThreadManager } from './types-
|
|
8
|
+
import { a as ThreadManagerConfig, B as BaseThreadManager } from './types-D6UKZZtj.js';
|
|
9
|
+
export { P as ProviderThreadManager } from './types-D6UKZZtj.js';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@temporalio/workflow';
|
|
12
12
|
import '@temporalio/common';
|
|
@@ -191,12 +191,53 @@ declare class FileSystemSkillProvider implements SkillProvider {
|
|
|
191
191
|
*/
|
|
192
192
|
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
193
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Result returned by {@link SandboxManagerHooks.onPreCreate}.
|
|
196
|
+
*
|
|
197
|
+
* - Set `skip: true` to prevent sandbox creation entirely.
|
|
198
|
+
* - Set `modifiedOptions` to override/extend the creation options that will
|
|
199
|
+
* be forwarded to the provider. Fields in `modifiedOptions` are merged on
|
|
200
|
+
* top of the original options (`initialFiles` and `env` are shallow-merged;
|
|
201
|
+
* everything else is overwritten).
|
|
202
|
+
*/
|
|
203
|
+
interface PreCreateHookResult<TOptions extends SandboxCreateOptions = SandboxCreateOptions> {
|
|
204
|
+
skip?: boolean;
|
|
205
|
+
modifiedOptions?: Partial<TOptions>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Lifecycle hooks for {@link SandboxManager}.
|
|
209
|
+
*
|
|
210
|
+
* Hooks run inside the existing `createSandbox` activity — no additional
|
|
211
|
+
* activity registration required.
|
|
212
|
+
*/
|
|
213
|
+
interface SandboxManagerHooks<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TCtx = unknown> {
|
|
214
|
+
/**
|
|
215
|
+
* Called before sandbox creation.
|
|
216
|
+
*
|
|
217
|
+
* Receives the provider options and an opaque `ctx` value set from the
|
|
218
|
+
* workflow's {@link SandboxInit}. Use `ctx` to derive additional creation
|
|
219
|
+
* options (e.g. initial files from workflow arguments).
|
|
220
|
+
*
|
|
221
|
+
* Return `{ skip: true }` to prevent creation, or `{ modifiedOptions }`
|
|
222
|
+
* to alter the options before they reach the provider.
|
|
223
|
+
*/
|
|
224
|
+
onPreCreate?: (options: TOptions, ctx: TCtx) => Promise<PreCreateHookResult<TOptions> | undefined>;
|
|
225
|
+
/**
|
|
226
|
+
* Called after a sandbox has been successfully created.
|
|
227
|
+
*/
|
|
228
|
+
onPostCreate?: (sandboxId: string) => Promise<void>;
|
|
229
|
+
}
|
|
194
230
|
/**
|
|
195
231
|
* Stateless facade over a {@link SandboxProvider}.
|
|
196
232
|
*
|
|
197
233
|
* Delegates all lifecycle operations to the provider, which is responsible
|
|
198
234
|
* for its own instance management strategy (e.g. in-memory map, remote API).
|
|
199
235
|
*
|
|
236
|
+
* Optional {@link SandboxManagerHooks} can be passed at construction time.
|
|
237
|
+
* The `onPreCreate` hook runs inside the `createSandbox` activity, receiving
|
|
238
|
+
* the provider options and an opaque `ctx` value from the workflow's
|
|
239
|
+
* {@link SandboxInit}. It can modify options or skip creation entirely.
|
|
240
|
+
*
|
|
200
241
|
* @example
|
|
201
242
|
* ```typescript
|
|
202
243
|
* const manager = new SandboxManager(new InMemorySandboxProvider());
|
|
@@ -206,16 +247,38 @@ declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThr
|
|
|
206
247
|
* };
|
|
207
248
|
* // registers: inMemoryCodingAgentCreateSandbox, …
|
|
208
249
|
* ```
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const manager = new SandboxManager(
|
|
254
|
+
* new DaytonaSandboxProvider(config),
|
|
255
|
+
* {
|
|
256
|
+
* hooks: {
|
|
257
|
+
* onPreCreate: async (options, ctx) => {
|
|
258
|
+
* const { projectId, filePaths } = ctx as { projectId: string; filePaths: string[] };
|
|
259
|
+
* const files: Record<string, string> = {};
|
|
260
|
+
* for (const p of filePaths) files[p] = await db.readFile(projectId, p);
|
|
261
|
+
* return { modifiedOptions: { initialFiles: files } };
|
|
262
|
+
* },
|
|
263
|
+
* onPostCreate: async (sandboxId) => {
|
|
264
|
+
* console.log("Sandbox created:", sandboxId);
|
|
265
|
+
* },
|
|
266
|
+
* },
|
|
267
|
+
* },
|
|
268
|
+
* );
|
|
269
|
+
* ```
|
|
209
270
|
*/
|
|
210
|
-
declare class SandboxManager<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TSandbox extends Sandbox = Sandbox, TId extends string = string> {
|
|
271
|
+
declare class SandboxManager<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TSandbox extends Sandbox = Sandbox, TId extends string = string, TCtx = unknown> {
|
|
211
272
|
private provider;
|
|
273
|
+
private hooks;
|
|
212
274
|
constructor(provider: SandboxProvider<TOptions, TSandbox> & {
|
|
213
275
|
readonly id: TId;
|
|
276
|
+
}, options?: {
|
|
277
|
+
hooks?: SandboxManagerHooks<TOptions, TCtx>;
|
|
214
278
|
});
|
|
215
|
-
create(options?: TOptions): Promise<{
|
|
279
|
+
create(options?: TOptions, ctx?: TCtx): Promise<{
|
|
216
280
|
sandboxId: string;
|
|
217
|
-
|
|
218
|
-
}>;
|
|
281
|
+
} | null>;
|
|
219
282
|
getSandbox(id: string): Promise<TSandbox>;
|
|
220
283
|
destroy(id: string): Promise<void>;
|
|
221
284
|
pause(id: string, ttlSeconds?: number): Promise<void>;
|
|
@@ -242,7 +305,7 @@ declare class SandboxManager<TOptions extends SandboxCreateOptions = SandboxCrea
|
|
|
242
305
|
* // registers: daytonaCodingAgentCreateSandbox, …
|
|
243
306
|
* ```
|
|
244
307
|
*/
|
|
245
|
-
createActivities<S extends string>(scope: S): PrefixedSandboxOps<`${TId}${Capitalize<S>}`, TOptions>;
|
|
308
|
+
createActivities<S extends string>(scope: S): PrefixedSandboxOps<`${TId}${Capitalize<S>}`, TOptions, TCtx>;
|
|
246
309
|
}
|
|
247
310
|
|
|
248
311
|
/**
|
|
@@ -293,7 +356,7 @@ declare class NodeFsSandboxFileSystem implements SandboxFileSystem {
|
|
|
293
356
|
* the parent workflow for the current file tree and resolver context.
|
|
294
357
|
*
|
|
295
358
|
* On each invocation the wrapper:
|
|
296
|
-
* 1. Queries the workflow's `AgentState` for `fileTree`, `
|
|
359
|
+
* 1. Queries the workflow's `AgentState` for `fileTree`, `ctx`, and `workspaceBase`
|
|
297
360
|
* 2. Creates an ephemeral {@link VirtualFileSystem} from tree + resolver
|
|
298
361
|
* 3. Runs the inner handler
|
|
299
362
|
* 4. Returns the handler's result together with any {@link TreeMutation}s
|
|
@@ -433,4 +496,4 @@ declare const toTree: (fs: SandboxFileSystem, opts?: {
|
|
|
433
496
|
sort?: boolean;
|
|
434
497
|
}) => Promise<string>;
|
|
435
498
|
|
|
436
|
-
export { ActivityToolHandler, type AgentStateContext, BaseAgentState, BaseThreadManager, BashArgs, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, GlobArgs, JsonValue, NodeFsSandboxFileSystem, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, bashHandler, createRunAgentActivity, createThreadManager, createVirtualFsActivities, editHandler, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };
|
|
499
|
+
export { ActivityToolHandler, type AgentStateContext, BaseAgentState, BaseThreadManager, BashArgs, ExecResult, FileEditArgs, FileEntryMetadata, FileReadArgs, FileResolver, FileSystemSkillProvider, FileWriteArgs, GlobArgs, JsonValue, NodeFsSandboxFileSystem, type PreCreateHookResult, PrefixedSandboxOps, PrefixedVirtualFsOps, RouterContext, RunAgentConfig, Sandbox, type SandboxContext, SandboxCreateOptions, DirentEntry as SandboxDirentEntry, FileStat as SandboxFileStat, SandboxFileSystem, SandboxManager, type SandboxManagerHooks, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, TreeMutation, VirtualFsContext, bashHandler, createRunAgentActivity, createThreadManager, createVirtualFsActivities, editHandler, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, withVirtualFs, writeFileHandler };
|
package/dist/index.js
CHANGED
|
@@ -399,7 +399,7 @@ function resolveSandboxConfig(config) {
|
|
|
399
399
|
if (config === "own") return { source: "own" };
|
|
400
400
|
return { source: "own", shutdown: config.shutdown };
|
|
401
401
|
}
|
|
402
|
-
function createSubagentHandler(subagents
|
|
402
|
+
function createSubagentHandler(subagents) {
|
|
403
403
|
const { taskQueue: parentTaskQueue } = workflowInfo();
|
|
404
404
|
const childResults = /* @__PURE__ */ new Map();
|
|
405
405
|
const pendingDestroys = /* @__PURE__ */ new Map();
|
|
@@ -427,15 +427,16 @@ function createSubagentHandler(subagents, options) {
|
|
|
427
427
|
const continuationThreadId = args.threadId && allowsContinuation ? args.threadId : void 0;
|
|
428
428
|
let thread;
|
|
429
429
|
if (continuationThreadId) {
|
|
430
|
-
thread = {
|
|
430
|
+
thread = {
|
|
431
|
+
mode: threadMode,
|
|
432
|
+
threadId: continuationThreadId
|
|
433
|
+
};
|
|
431
434
|
}
|
|
432
435
|
let sandbox;
|
|
433
436
|
if (sandboxCfg.source === "inherit" && parentSandboxId) {
|
|
434
|
-
const stateUpdate = options?.getSandboxStateForInheritance?.();
|
|
435
437
|
sandbox = {
|
|
436
438
|
mode: "inherit",
|
|
437
|
-
sandboxId: parentSandboxId
|
|
438
|
-
...stateUpdate && { stateUpdate }
|
|
439
|
+
sandboxId: parentSandboxId
|
|
439
440
|
};
|
|
440
441
|
} else if (sandboxCfg.source === "own") {
|
|
441
442
|
const prevSbId = continuationThreadId ? threadSandboxes.get(continuationThreadId) : void 0;
|
|
@@ -555,7 +556,7 @@ function createSubagentHandler(subagents, options) {
|
|
|
555
556
|
}
|
|
556
557
|
|
|
557
558
|
// src/lib/subagent/register.ts
|
|
558
|
-
function buildSubagentRegistration(subagents
|
|
559
|
+
function buildSubagentRegistration(subagents) {
|
|
559
560
|
if (subagents.length === 0) return null;
|
|
560
561
|
const getEnabled = () => subagents.filter(
|
|
561
562
|
(s) => typeof s.enabled === "function" ? s.enabled() : s.enabled ?? true
|
|
@@ -565,9 +566,7 @@ function buildSubagentRegistration(subagents, options) {
|
|
|
565
566
|
if (s.hooks) subagentHooksMap.set(s.agentName, s.hooks);
|
|
566
567
|
}
|
|
567
568
|
const resolveSubagentName = (args) => args.subagent;
|
|
568
|
-
const { handler, destroySubagentSandboxes } = createSubagentHandler(subagents
|
|
569
|
-
getSandboxStateForInheritance: options?.getSandboxStateForInheritance
|
|
570
|
-
});
|
|
569
|
+
const { handler, destroySubagentSandboxes } = createSubagentHandler(subagents);
|
|
571
570
|
const registration = {
|
|
572
571
|
name: SUBAGENT_TOOL_NAME,
|
|
573
572
|
enabled: () => getEnabled().length > 0,
|
|
@@ -707,7 +706,8 @@ async function createSession({
|
|
|
707
706
|
thread: threadInit,
|
|
708
707
|
sandbox: sandboxInit,
|
|
709
708
|
sandboxShutdown = "destroy",
|
|
710
|
-
virtualFs: virtualFsConfig
|
|
709
|
+
virtualFs: virtualFsConfig,
|
|
710
|
+
virtualFsOps
|
|
711
711
|
}) {
|
|
712
712
|
const threadMode = threadInit?.mode ?? "new";
|
|
713
713
|
let threadId;
|
|
@@ -733,11 +733,8 @@ async function createSession({
|
|
|
733
733
|
} = threadOps;
|
|
734
734
|
const plugins = [];
|
|
735
735
|
let destroySubagentSandboxes;
|
|
736
|
-
let sandboxStateGetter;
|
|
737
736
|
if (subagents) {
|
|
738
|
-
const result = buildSubagentRegistration(subagents
|
|
739
|
-
getSandboxStateForInheritance: () => sandboxStateGetter?.()
|
|
740
|
-
});
|
|
737
|
+
const result = buildSubagentRegistration(subagents);
|
|
741
738
|
if (result) {
|
|
742
739
|
plugins.push(result.registration);
|
|
743
740
|
destroySubagentSandboxes = result.destroySubagentSandboxes;
|
|
@@ -793,23 +790,9 @@ async function createSession({
|
|
|
793
790
|
const sandboxMode = sandboxInit?.mode;
|
|
794
791
|
let sandboxId;
|
|
795
792
|
let sandboxOwned = false;
|
|
796
|
-
sandboxStateGetter = () => {
|
|
797
|
-
const fileTree = stateManager.get("fileTree");
|
|
798
|
-
const resolverContext = stateManager.get("resolverContext");
|
|
799
|
-
const workspaceBase = stateManager.get("workspaceBase");
|
|
800
|
-
if (!fileTree && !resolverContext && !workspaceBase) return void 0;
|
|
801
|
-
return {
|
|
802
|
-
...fileTree !== void 0 && { fileTree },
|
|
803
|
-
...resolverContext !== void 0 && { resolverContext },
|
|
804
|
-
...workspaceBase !== void 0 && { workspaceBase }
|
|
805
|
-
};
|
|
806
|
-
};
|
|
807
793
|
if (sandboxMode === "inherit") {
|
|
808
794
|
const inheritInit = sandboxInit;
|
|
809
795
|
sandboxId = inheritInit.sandboxId;
|
|
810
|
-
if (inheritInit.stateUpdate) {
|
|
811
|
-
stateManager.mergeUpdate(inheritInit.stateUpdate);
|
|
812
|
-
}
|
|
813
796
|
if (!sandboxOps) {
|
|
814
797
|
throw ApplicationFailure.create({
|
|
815
798
|
message: "sandboxId provided but no sandboxOps \u2014 cannot manage sandbox lifecycle",
|
|
@@ -838,24 +821,36 @@ async function createSession({
|
|
|
838
821
|
sandboxOwned = true;
|
|
839
822
|
} else if (sandboxOps) {
|
|
840
823
|
const skillFiles = skills ? collectSkillFiles(skills) : void 0;
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
);
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
stateManager.mergeUpdate(result.stateUpdate);
|
|
824
|
+
const ctx = sandboxInit?.ctx;
|
|
825
|
+
const createOptions = skillFiles ? { initialFiles: skillFiles } : void 0;
|
|
826
|
+
const result = await sandboxOps.createSandbox(createOptions, ctx);
|
|
827
|
+
if (result) {
|
|
828
|
+
sandboxId = result.sandboxId;
|
|
829
|
+
sandboxOwned = true;
|
|
848
830
|
}
|
|
849
831
|
}
|
|
850
832
|
if (virtualFsConfig) {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
833
|
+
if (!virtualFsOps) {
|
|
834
|
+
throw ApplicationFailure.create({
|
|
835
|
+
message: "No virtualFsOps provided \u2014 cannot resolve file tree",
|
|
836
|
+
nonRetryable: true
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
const result = await virtualFsOps.resolveFileTree(virtualFsConfig.ctx);
|
|
840
|
+
const skillFiles = skills ? collectSkillFiles(skills) : void 0;
|
|
841
|
+
const fileTree = skillFiles ? [
|
|
842
|
+
...result.fileTree,
|
|
843
|
+
...Object.entries(skillFiles).map(([path, content]) => ({
|
|
844
|
+
id: `skill:${path}`,
|
|
845
|
+
path,
|
|
846
|
+
size: content.length,
|
|
847
|
+
mtime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
848
|
+
metadata: {}
|
|
849
|
+
}))
|
|
850
|
+
] : result.fileTree;
|
|
854
851
|
stateManager.mergeUpdate({
|
|
855
|
-
fileTree
|
|
856
|
-
|
|
857
|
-
workspaceBase: virtualFsConfig.workspaceBase ?? "/",
|
|
858
|
-
...result.stateUpdate
|
|
852
|
+
fileTree,
|
|
853
|
+
...skillFiles && { inlineFiles: skillFiles }
|
|
859
854
|
});
|
|
860
855
|
}
|
|
861
856
|
if (hooks.onSessionStart) {
|
|
@@ -889,7 +884,12 @@ async function createSession({
|
|
|
889
884
|
await initializeThread(threadId, threadKey);
|
|
890
885
|
}
|
|
891
886
|
}
|
|
892
|
-
await appendHumanMessage(
|
|
887
|
+
await appendHumanMessage(
|
|
888
|
+
threadId,
|
|
889
|
+
uuid4(),
|
|
890
|
+
await buildContextMessage(),
|
|
891
|
+
threadKey
|
|
892
|
+
);
|
|
893
893
|
let exitReason = "completed";
|
|
894
894
|
try {
|
|
895
895
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
@@ -2186,12 +2186,41 @@ function withParentWorkflowState(client, handler) {
|
|
|
2186
2186
|
|
|
2187
2187
|
// src/lib/sandbox/manager.ts
|
|
2188
2188
|
var SandboxManager = class {
|
|
2189
|
-
constructor(provider) {
|
|
2189
|
+
constructor(provider, options) {
|
|
2190
2190
|
this.provider = provider;
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2191
|
+
this.hooks = options?.hooks ?? {};
|
|
2192
|
+
}
|
|
2193
|
+
hooks;
|
|
2194
|
+
async create(options, ctx) {
|
|
2195
|
+
let providerOptions = options;
|
|
2196
|
+
if (this.hooks.onPreCreate) {
|
|
2197
|
+
const hookResult = await this.hooks.onPreCreate(
|
|
2198
|
+
options ?? {},
|
|
2199
|
+
ctx ?? {}
|
|
2200
|
+
);
|
|
2201
|
+
if (hookResult?.skip) return null;
|
|
2202
|
+
if (hookResult?.modifiedOptions) {
|
|
2203
|
+
const orig = options ?? {};
|
|
2204
|
+
const mod = hookResult.modifiedOptions;
|
|
2205
|
+
providerOptions = {
|
|
2206
|
+
...mod,
|
|
2207
|
+
...orig,
|
|
2208
|
+
initialFiles: {
|
|
2209
|
+
...mod.initialFiles,
|
|
2210
|
+
...orig.initialFiles
|
|
2211
|
+
},
|
|
2212
|
+
env: {
|
|
2213
|
+
...mod.env,
|
|
2214
|
+
...orig.env
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
const { sandbox } = await this.provider.create(providerOptions);
|
|
2220
|
+
if (this.hooks.onPostCreate) {
|
|
2221
|
+
await this.hooks.onPostCreate(sandbox.id);
|
|
2222
|
+
}
|
|
2223
|
+
return { sandboxId: sandbox.id };
|
|
2195
2224
|
}
|
|
2196
2225
|
async getSandbox(id) {
|
|
2197
2226
|
return this.provider.get(id);
|
|
@@ -2236,8 +2265,8 @@ var SandboxManager = class {
|
|
|
2236
2265
|
createActivities(scope) {
|
|
2237
2266
|
const prefix = `${this.provider.id}${scope.charAt(0).toUpperCase()}${scope.slice(1)}`;
|
|
2238
2267
|
const ops = {
|
|
2239
|
-
createSandbox: async (options) => {
|
|
2240
|
-
return this.create(options);
|
|
2268
|
+
createSandbox: async (options, ctx) => {
|
|
2269
|
+
return this.create(options, ctx);
|
|
2241
2270
|
},
|
|
2242
2271
|
destroySandbox: async (sandboxId) => {
|
|
2243
2272
|
await this.destroy(sandboxId);
|
|
@@ -2348,7 +2377,7 @@ function inferDirectories(entries, workspaceBase) {
|
|
|
2348
2377
|
return dirs;
|
|
2349
2378
|
}
|
|
2350
2379
|
var VirtualFileSystem = class {
|
|
2351
|
-
constructor(tree, resolver, ctx, workspaceBase = "/") {
|
|
2380
|
+
constructor(tree, resolver, ctx, workspaceBase = "/", inlineFiles) {
|
|
2352
2381
|
this.resolver = resolver;
|
|
2353
2382
|
this.ctx = ctx;
|
|
2354
2383
|
this.workspaceBase = normalisePath(workspaceBase);
|
|
@@ -2356,11 +2385,18 @@ var VirtualFileSystem = class {
|
|
|
2356
2385
|
tree.map((e) => [normalisePath(e.path, this.workspaceBase), e])
|
|
2357
2386
|
);
|
|
2358
2387
|
this.directories = inferDirectories(tree, this.workspaceBase);
|
|
2388
|
+
this.inlineFiles = new Map(
|
|
2389
|
+
inlineFiles ? Object.entries(inlineFiles).map(([p, c]) => [
|
|
2390
|
+
normalisePath(p, this.workspaceBase),
|
|
2391
|
+
c
|
|
2392
|
+
]) : []
|
|
2393
|
+
);
|
|
2359
2394
|
}
|
|
2360
2395
|
workspaceBase;
|
|
2361
2396
|
entries;
|
|
2362
2397
|
directories;
|
|
2363
2398
|
mutations = [];
|
|
2399
|
+
inlineFiles;
|
|
2364
2400
|
/** Return all mutations accumulated during this invocation. */
|
|
2365
2401
|
getMutations() {
|
|
2366
2402
|
return this.mutations;
|
|
@@ -2374,12 +2410,16 @@ var VirtualFileSystem = class {
|
|
|
2374
2410
|
// --------------------------------------------------------------------------
|
|
2375
2411
|
async readFile(path) {
|
|
2376
2412
|
const norm = normalisePath(path, this.workspaceBase);
|
|
2413
|
+
const inline = this.inlineFiles.get(norm);
|
|
2414
|
+
if (inline !== void 0) return inline;
|
|
2377
2415
|
const entry = this.entries.get(norm);
|
|
2378
2416
|
if (!entry) throw new Error(`ENOENT: no such file: ${path}`);
|
|
2379
2417
|
return this.resolver.readFile(entry.id, this.ctx, entry.metadata);
|
|
2380
2418
|
}
|
|
2381
2419
|
async readFileBuffer(path) {
|
|
2382
2420
|
const norm = normalisePath(path, this.workspaceBase);
|
|
2421
|
+
const inline = this.inlineFiles.get(norm);
|
|
2422
|
+
if (inline !== void 0) return new TextEncoder().encode(inline);
|
|
2383
2423
|
const entry = this.entries.get(norm);
|
|
2384
2424
|
if (!entry) throw new Error(`ENOENT: no such file: ${path}`);
|
|
2385
2425
|
return this.resolver.readFileBuffer(entry.id, this.ctx, entry.metadata);
|
|
@@ -2610,7 +2650,7 @@ var VirtualFileSystem = class {
|
|
|
2610
2650
|
function withVirtualFs(client, resolver, handler) {
|
|
2611
2651
|
return async (args, context) => {
|
|
2612
2652
|
const state = await queryParentWorkflowState(client);
|
|
2613
|
-
const { fileTree,
|
|
2653
|
+
const { fileTree, ctx, workspaceBase, inlineFiles } = state;
|
|
2614
2654
|
if (!fileTree) {
|
|
2615
2655
|
return {
|
|
2616
2656
|
toolResponse: `Error: No fileTree in agent state. The ${context.toolName} tool requires a virtual filesystem.`,
|
|
@@ -2620,8 +2660,9 @@ function withVirtualFs(client, resolver, handler) {
|
|
|
2620
2660
|
const virtualFs = new VirtualFileSystem(
|
|
2621
2661
|
fileTree,
|
|
2622
2662
|
resolver,
|
|
2623
|
-
|
|
2624
|
-
workspaceBase ?? "/"
|
|
2663
|
+
ctx,
|
|
2664
|
+
workspaceBase ?? "/",
|
|
2665
|
+
inlineFiles
|
|
2625
2666
|
);
|
|
2626
2667
|
const response = await handler(args, { ...context, virtualFs });
|
|
2627
2668
|
const mutations = virtualFs.getMutations();
|