zeitlich 0.2.40 → 0.2.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/{activities-CvUrG3YG.d.cts → activities-Coafq5zr.d.cts} +2 -2
- package/dist/{activities-CULxRzJ1.d.ts → activities-CrN-ghLo.d.ts} +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs +4 -23
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +18 -86
- package/dist/adapters/sandbox/daytona/index.d.ts +18 -86
- package/dist/adapters/sandbox/daytona/index.js +4 -23
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.cjs +1 -7
- package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.d.ts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.js +1 -7
- package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs +21 -3
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +48 -7
- package/dist/adapters/sandbox/e2b/index.d.ts +48 -7
- package/dist/adapters/sandbox/e2b/index.js +22 -5
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs +11 -0
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +11 -3
- package/dist/adapters/sandbox/inmemory/index.d.ts +11 -3
- package/dist/adapters/sandbox/inmemory/index.js +11 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +6 -6
- package/dist/adapters/thread/anthropic/index.d.ts +6 -6
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +6 -6
- package/dist/adapters/thread/anthropic/workflow.d.ts +6 -6
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +6 -6
- package/dist/adapters/thread/google-genai/index.d.ts +6 -6
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +6 -6
- package/dist/adapters/thread/google-genai/workflow.d.ts +6 -6
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +6 -6
- package/dist/adapters/thread/langchain/index.d.ts +6 -6
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +6 -6
- package/dist/adapters/thread/langchain/workflow.d.ts +6 -6
- package/dist/index.cjs +316 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -17
- package/dist/index.d.ts +93 -17
- package/dist/index.js +317 -120
- package/dist/index.js.map +1 -1
- package/dist/{proxy-5EbwzaY4.d.cts → proxy-Bf7uI-Hw.d.cts} +1 -1
- package/dist/{proxy-wZufFfBh.d.ts → proxy-COqA95FW.d.ts} +1 -1
- package/dist/{thread-manager-BqBAIsED.d.ts → thread-manager-BhkOyQ1I.d.ts} +2 -2
- package/dist/{thread-manager-BNiIt5r8.d.ts → thread-manager-Bi1XlbpJ.d.ts} +2 -2
- package/dist/{thread-manager-DF8WuCRs.d.cts → thread-manager-BsLO3Fgc.d.cts} +2 -2
- package/dist/{thread-manager-BoN5DOvG.d.cts → thread-manager-wRVVBFgj.d.cts} +2 -2
- package/dist/{types-C7OoY7h8.d.ts → types-BkX4HLzi.d.ts} +1 -1
- package/dist/{types-CuISs0Ub.d.cts → types-C66-BVBr.d.cts} +1 -1
- package/dist/types-CJ7tCdl6.d.cts +266 -0
- package/dist/types-CJ7tCdl6.d.ts +266 -0
- package/dist/{types-DeQH84C_.d.ts → types-CdALEF3z.d.cts} +342 -23
- package/dist/{types-Cn2r3ol3.d.cts → types-ChAy_jSP.d.ts} +342 -23
- package/dist/types-CjY93AWZ.d.cts +84 -0
- package/dist/types-gVa5XCWD.d.ts +84 -0
- package/dist/{workflow-DhplIN65.d.cts → workflow-BwT5EybR.d.ts} +7 -6
- package/dist/{workflow-C2MZZj5K.d.ts → workflow-DMmiaw6w.d.cts} +7 -6
- package/dist/workflow.cjs +138 -77
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +4 -4
- package/dist/workflow.d.ts +4 -4
- package/dist/workflow.js +139 -78
- package/dist/workflow.js.map +1 -1
- package/package.json +17 -33
- package/src/adapters/sandbox/daytona/index.ts +25 -48
- package/src/adapters/sandbox/daytona/proxy.ts +7 -8
- package/src/adapters/sandbox/e2b/README.md +81 -0
- package/src/adapters/sandbox/e2b/index.ts +53 -11
- package/src/adapters/sandbox/e2b/keep-alive.test.ts +115 -0
- package/src/adapters/sandbox/e2b/proxy.ts +3 -2
- package/src/adapters/sandbox/e2b/types.ts +34 -2
- package/src/adapters/sandbox/inmemory/index.ts +21 -1
- package/src/adapters/sandbox/inmemory/proxy.ts +7 -3
- package/src/index.ts +1 -1
- package/src/lib/activity.ts +5 -0
- package/src/lib/sandbox/capability-types.test.ts +859 -0
- package/src/lib/sandbox/index.ts +1 -0
- package/src/lib/sandbox/manager.ts +187 -31
- package/src/lib/sandbox/types.ts +189 -46
- package/src/lib/session/index.ts +1 -0
- package/src/lib/session/session.integration.test.ts +58 -0
- package/src/lib/session/session.ts +109 -50
- package/src/lib/session/types.ts +189 -8
- package/src/lib/subagent/handler.ts +66 -43
- package/src/lib/subagent/subagent.integration.test.ts +2 -0
- package/src/lib/subagent/types.ts +492 -16
- package/src/lib/subagent/workflow.ts +11 -1
- package/src/lib/tool-router/auto-append-sandbox.integration.test.ts +158 -0
- package/src/lib/tool-router/index.ts +1 -1
- package/src/lib/tool-router/with-sandbox.ts +45 -2
- package/src/lib/virtual-fs/filesystem.ts +41 -16
- package/src/lib/virtual-fs/types.ts +19 -0
- package/src/lib/virtual-fs/virtual-fs.test.ts +204 -1
- package/src/tools/read-file/handler.test.ts +83 -0
- package/src/workflow.ts +3 -0
- package/tsup.config.ts +0 -4
- package/dist/adapters/sandbox/bedrock/index.cjs +0 -457
- package/dist/adapters/sandbox/bedrock/index.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/index.d.cts +0 -25
- package/dist/adapters/sandbox/bedrock/index.d.ts +0 -25
- package/dist/adapters/sandbox/bedrock/index.js +0 -454
- package/dist/adapters/sandbox/bedrock/index.js.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.cjs +0 -36
- package/dist/adapters/sandbox/bedrock/workflow.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.d.cts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.d.ts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.js +0 -34
- package/dist/adapters/sandbox/bedrock/workflow.js.map +0 -1
- package/dist/types-DAsQ21Rt.d.ts +0 -74
- package/dist/types-lm8tMNJQ.d.cts +0 -74
- package/dist/types-yx0LzPGn.d.cts +0 -173
- package/dist/types-yx0LzPGn.d.ts +0 -173
- package/src/adapters/sandbox/bedrock/filesystem.ts +0 -340
- package/src/adapters/sandbox/bedrock/index.ts +0 -274
- package/src/adapters/sandbox/bedrock/proxy.ts +0 -59
- package/src/adapters/sandbox/bedrock/types.ts +0 -24
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as SandboxOps } from './types-yx0LzPGn.cjs';
|
|
1
|
+
import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aF as ZeitlichSession, $ as SandboxShutdown, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aH as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, an as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, aB as VirtualFileTree, k as TreeMutation, s as FileEntry, aC as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, as as ToolHandler, aE as WorkflowTask, d as ActivityToolHandler } from './types-ChAy_jSP.js';
|
|
3
2
|
import z$1, { z } from 'zod';
|
|
3
|
+
import './types-CJ7tCdl6.js';
|
|
4
|
+
import { Duration } from '@temporalio/common';
|
|
4
5
|
import { Sinks, proxyActivities } from '@temporalio/workflow';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -34,10 +35,10 @@ import { Sinks, proxyActivities } from '@temporalio/workflow';
|
|
|
34
35
|
* const { finalMessage, exitReason } = await session.runSession({ stateManager });
|
|
35
36
|
* ```
|
|
36
37
|
*/
|
|
37
|
-
declare function createSession<T extends ToolMap, M = unknown, TContent = string>(config: SessionConfig<T, M, TContent> & {
|
|
38
|
-
sandboxOps:
|
|
38
|
+
declare function createSession<T extends ToolMap, M = unknown, TContent = string, TInit extends SandboxInit | undefined = undefined, TShutdown extends SubagentSandboxShutdown | undefined = undefined>(config: SessionConfig<T, M, TContent, TInit, TShutdown> & {
|
|
39
|
+
sandboxOps: NonNullable<SessionConfig<T, M, TContent, TInit, TShutdown>["sandboxOps"]>;
|
|
39
40
|
}): Promise<ZeitlichSession<M, true>>;
|
|
40
|
-
declare function createSession<T extends ToolMap, M = unknown, TContent = string>(config: SessionConfig<T, M, TContent>): Promise<ZeitlichSession<M, false>>;
|
|
41
|
+
declare function createSession<T extends ToolMap, M = unknown, TContent = string, TInit extends SandboxInit | undefined = undefined, TShutdown extends SubagentSandboxShutdown | undefined = undefined>(config: SessionConfig<T, M, TContent, TInit, TShutdown>): Promise<ZeitlichSession<M, false>>;
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* Session config fields derived from a main workflow input, ready to spread
|
|
@@ -270,7 +271,7 @@ type SubagentArgs = {
|
|
|
270
271
|
* still catching hangs; agents that legitimately need longer should set an
|
|
271
272
|
* explicit `workflowOptions.workflowRunTimeout`.
|
|
272
273
|
*/
|
|
273
|
-
declare const DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT
|
|
274
|
+
declare const DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT: Duration;
|
|
274
275
|
|
|
275
276
|
/**
|
|
276
277
|
* Creates a `SubagentConfig` from a `SubagentDefinition` (returned by `defineSubagentWorkflow`).
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as SandboxOps } from './types-yx0LzPGn.js';
|
|
1
|
+
import { au as ToolMap, _ as SandboxInit, ah as SubagentSandboxShutdown, a1 as SessionConfig, aF as ZeitlichSession, $ as SandboxShutdown, am as ThreadInit, u as JsonSerializable, B as BaseAgentState, p as AgentStateManager, aH as ToolRouterOptions, ax as ToolRouter, R as RouterContext, J as JsonValue, az as ToolWithHandler, w as ParsedToolCallUnion, av as ToolNames, ac as SubagentDefinition, af as SubagentHooks, ag as SubagentSandboxConfig, aa as SubagentConfig, ai as SubagentSessionInput, ad as SubagentFnResult, a7 as SessionStartHook, a2 as SessionEndHook, E as PostToolUseHook, z as PostToolUseFailureHook, a4 as SessionExitReason, an as TokenUsage, f as RunAgentConfig, A as AgentResponse, F as FileEntryMetadata, aB as VirtualFileTree, k as TreeMutation, s as FileEntry, aC as VirtualFsOps, h as SkillMetadata, i as Skill, c as ToolHandlerResponse, as as ToolHandler, aE as WorkflowTask, d as ActivityToolHandler } from './types-CdALEF3z.cjs';
|
|
3
2
|
import z$1, { z } from 'zod';
|
|
3
|
+
import './types-CJ7tCdl6.cjs';
|
|
4
|
+
import { Duration } from '@temporalio/common';
|
|
4
5
|
import { Sinks, proxyActivities } from '@temporalio/workflow';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -34,10 +35,10 @@ import { Sinks, proxyActivities } from '@temporalio/workflow';
|
|
|
34
35
|
* const { finalMessage, exitReason } = await session.runSession({ stateManager });
|
|
35
36
|
* ```
|
|
36
37
|
*/
|
|
37
|
-
declare function createSession<T extends ToolMap, M = unknown, TContent = string>(config: SessionConfig<T, M, TContent> & {
|
|
38
|
-
sandboxOps:
|
|
38
|
+
declare function createSession<T extends ToolMap, M = unknown, TContent = string, TInit extends SandboxInit | undefined = undefined, TShutdown extends SubagentSandboxShutdown | undefined = undefined>(config: SessionConfig<T, M, TContent, TInit, TShutdown> & {
|
|
39
|
+
sandboxOps: NonNullable<SessionConfig<T, M, TContent, TInit, TShutdown>["sandboxOps"]>;
|
|
39
40
|
}): Promise<ZeitlichSession<M, true>>;
|
|
40
|
-
declare function createSession<T extends ToolMap, M = unknown, TContent = string>(config: SessionConfig<T, M, TContent>): Promise<ZeitlichSession<M, false>>;
|
|
41
|
+
declare function createSession<T extends ToolMap, M = unknown, TContent = string, TInit extends SandboxInit | undefined = undefined, TShutdown extends SubagentSandboxShutdown | undefined = undefined>(config: SessionConfig<T, M, TContent, TInit, TShutdown>): Promise<ZeitlichSession<M, false>>;
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* Session config fields derived from a main workflow input, ready to spread
|
|
@@ -270,7 +271,7 @@ type SubagentArgs = {
|
|
|
270
271
|
* still catching hangs; agents that legitimately need longer should set an
|
|
271
272
|
* explicit `workflowOptions.workflowRunTimeout`.
|
|
272
273
|
*/
|
|
273
|
-
declare const DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT
|
|
274
|
+
declare const DEFAULT_SUBAGENT_WORKFLOW_RUN_TIMEOUT: Duration;
|
|
274
275
|
|
|
275
276
|
/**
|
|
276
277
|
* Creates a `SubagentConfig` from a `SubagentDefinition` (returned by `defineSubagentWorkflow`).
|
package/dist/workflow.cjs
CHANGED
|
@@ -9,6 +9,16 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
9
9
|
var z14__default = /*#__PURE__*/_interopDefault(z14);
|
|
10
10
|
|
|
11
11
|
// src/lib/session/session.ts
|
|
12
|
+
|
|
13
|
+
// src/lib/session/types.ts
|
|
14
|
+
function resolveSessionLifecycle(init, shutdown) {
|
|
15
|
+
const resolvedInit = init ?? { mode: "new" };
|
|
16
|
+
const resolvedShutdown = shutdown ?? "destroy";
|
|
17
|
+
return {
|
|
18
|
+
mode: resolvedInit.mode,
|
|
19
|
+
shutdown: resolvedShutdown
|
|
20
|
+
};
|
|
21
|
+
}
|
|
12
22
|
function createToolRouter(options) {
|
|
13
23
|
const { appendToolResult } = options;
|
|
14
24
|
const toolMap = /* @__PURE__ */ new Map();
|
|
@@ -437,6 +447,37 @@ function createSubagentTool(subagents) {
|
|
|
437
447
|
schema
|
|
438
448
|
};
|
|
439
449
|
}
|
|
450
|
+
|
|
451
|
+
// src/lib/subagent/types.ts
|
|
452
|
+
function isSurvivalShutdown(s) {
|
|
453
|
+
return s === "pause" || s === "pause-until-parent-close" || s === "keep" || s === "keep-until-parent-close";
|
|
454
|
+
}
|
|
455
|
+
function resolveSubagentLifecycle(cfg, isLazyCreator) {
|
|
456
|
+
if (cfg.source !== "own") {
|
|
457
|
+
return {
|
|
458
|
+
shutdownOverride: cfg.shutdown,
|
|
459
|
+
mustSurvive: false
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
if (cfg.continuation === "snapshot") {
|
|
463
|
+
return {
|
|
464
|
+
shutdownOverride: "snapshot",
|
|
465
|
+
mustSurvive: false
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
const isLazy = cfg.init === "once";
|
|
469
|
+
const mustSurvive = isLazyCreator || cfg.continuation === "continue" || isLazy && cfg.continuation === "fork";
|
|
470
|
+
if (!mustSurvive) {
|
|
471
|
+
return { shutdownOverride: cfg.shutdown, mustSurvive: false };
|
|
472
|
+
}
|
|
473
|
+
if (isSurvivalShutdown(cfg.shutdown)) {
|
|
474
|
+
return { shutdownOverride: cfg.shutdown, mustSurvive };
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
shutdownOverride: isLazyCreator ? "pause-until-parent-close" : "pause",
|
|
478
|
+
mustSurvive
|
|
479
|
+
};
|
|
480
|
+
}
|
|
440
481
|
var childSandboxReadySignal = workflow.defineSignal("childSandboxReady");
|
|
441
482
|
|
|
442
483
|
// src/lib/subagent/handler.ts
|
|
@@ -462,10 +503,18 @@ function resolveSandboxConfig(config) {
|
|
|
462
503
|
}
|
|
463
504
|
function createSubagentHandler(subagents) {
|
|
464
505
|
const { taskQueue: parentTaskQueue } = workflow.workflowInfo();
|
|
465
|
-
const
|
|
506
|
+
const agentDestroyOps = /* @__PURE__ */ new Map();
|
|
507
|
+
const agentDeleteSnapshotOps = /* @__PURE__ */ new Map();
|
|
466
508
|
for (const cfg of subagents) {
|
|
467
|
-
|
|
468
|
-
|
|
509
|
+
const cfgSandbox = cfg.sandbox;
|
|
510
|
+
if (!cfgSandbox || cfgSandbox === "none") continue;
|
|
511
|
+
if (cfgSandbox.continuation === "snapshot") {
|
|
512
|
+
const proxy = cfgSandbox.proxy(cfg.agentName);
|
|
513
|
+
agentDestroyOps.set(cfg.agentName, proxy);
|
|
514
|
+
agentDeleteSnapshotOps.set(cfg.agentName, proxy);
|
|
515
|
+
} else {
|
|
516
|
+
const proxy = cfgSandbox.proxy(cfg.agentName);
|
|
517
|
+
agentDestroyOps.set(cfg.agentName, proxy);
|
|
469
518
|
}
|
|
470
519
|
}
|
|
471
520
|
const pendingDestroys = /* @__PURE__ */ new Map();
|
|
@@ -504,7 +553,7 @@ function createSubagentHandler(subagents) {
|
|
|
504
553
|
const childWorkflowId = `${args.subagent}-${getShortId()}`;
|
|
505
554
|
const { sandboxId: parentSandboxId } = context;
|
|
506
555
|
const sandboxCfg = resolveSandboxConfig(config.sandbox);
|
|
507
|
-
if (sandboxCfg.source !== "none" && !
|
|
556
|
+
if (sandboxCfg.source !== "none" && !agentDestroyOps.has(config.agentName)) {
|
|
508
557
|
throw workflow.ApplicationFailure.create({
|
|
509
558
|
message: `Subagent "${config.agentName}" uses a sandbox but no \`sandbox.proxy\` is configured on its SubagentConfig`,
|
|
510
559
|
nonRetryable: true
|
|
@@ -572,7 +621,6 @@ function createSubagentHandler(subagents) {
|
|
|
572
621
|
if (baseSnap) {
|
|
573
622
|
sandbox = { mode: "from-snapshot", snapshot: baseSnap };
|
|
574
623
|
}
|
|
575
|
-
sandboxShutdownOverride = "snapshot";
|
|
576
624
|
} else if (sandboxCfg.source === "own") {
|
|
577
625
|
const isLazy = sandboxCfg.init === "once";
|
|
578
626
|
let baseSandboxId;
|
|
@@ -608,12 +656,10 @@ function createSubagentHandler(subagents) {
|
|
|
608
656
|
sandboxId: baseSandboxId
|
|
609
657
|
};
|
|
610
658
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
sandboxShutdownOverride = isLazyCreator ? "pause-until-parent-close" : "pause";
|
|
616
|
-
}
|
|
659
|
+
}
|
|
660
|
+
{
|
|
661
|
+
const lifecycle = resolveSubagentLifecycle(sandboxCfg, isLazyCreator);
|
|
662
|
+
sandboxShutdownOverride = lifecycle.shutdownOverride;
|
|
617
663
|
}
|
|
618
664
|
const workflowInput = {
|
|
619
665
|
...thread && { thread },
|
|
@@ -758,7 +804,7 @@ function createSubagentHandler(subagents) {
|
|
|
758
804
|
pendingDestroys.clear();
|
|
759
805
|
await Promise.all(
|
|
760
806
|
entries.map(async ({ agentName, sandboxId }) => {
|
|
761
|
-
const ops =
|
|
807
|
+
const ops = agentDestroyOps.get(agentName);
|
|
762
808
|
if (!ops) {
|
|
763
809
|
workflow.log.warn(
|
|
764
810
|
"Skipping sandbox destroy \u2014 no sandbox.proxy registered for agent",
|
|
@@ -788,7 +834,7 @@ function createSubagentHandler(subagents) {
|
|
|
788
834
|
persistentBaseSnapshot.clear();
|
|
789
835
|
await Promise.all(
|
|
790
836
|
tagged.map(async ({ agentName, snapshot }) => {
|
|
791
|
-
const ops =
|
|
837
|
+
const ops = agentDeleteSnapshotOps.get(agentName);
|
|
792
838
|
if (!ops) {
|
|
793
839
|
workflow.log.warn(
|
|
794
840
|
"Skipping snapshot delete \u2014 no sandbox.proxy registered for agent",
|
|
@@ -940,30 +986,31 @@ function collectSkillFiles(skills) {
|
|
|
940
986
|
}
|
|
941
987
|
return files;
|
|
942
988
|
}
|
|
943
|
-
async function createSession({
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
}
|
|
989
|
+
async function createSession(config) {
|
|
990
|
+
const {
|
|
991
|
+
agentName,
|
|
992
|
+
maxTurns = 50,
|
|
993
|
+
metadata = {},
|
|
994
|
+
runAgent,
|
|
995
|
+
threadOps,
|
|
996
|
+
buildContextMessage,
|
|
997
|
+
subagents,
|
|
998
|
+
skills,
|
|
999
|
+
tools = {},
|
|
1000
|
+
processToolsInParallel = true,
|
|
1001
|
+
hooks = {},
|
|
1002
|
+
appendSystemPrompt = true,
|
|
1003
|
+
threadKey,
|
|
1004
|
+
sandboxOps,
|
|
1005
|
+
thread: threadInit,
|
|
1006
|
+
sandbox: sandboxInit,
|
|
1007
|
+
sandboxShutdown,
|
|
1008
|
+
onSandboxReady,
|
|
1009
|
+
onSessionExit,
|
|
1010
|
+
virtualFs: virtualFsConfig,
|
|
1011
|
+
virtualFsOps
|
|
1012
|
+
} = config;
|
|
1013
|
+
const wideOps = () => sandboxOps;
|
|
967
1014
|
const threadMode = threadInit?.mode ?? "new";
|
|
968
1015
|
let threadId;
|
|
969
1016
|
let sourceThreadId;
|
|
@@ -1047,7 +1094,12 @@ async function createSession({
|
|
|
1047
1094
|
stateManager.run();
|
|
1048
1095
|
}
|
|
1049
1096
|
);
|
|
1050
|
-
const
|
|
1097
|
+
const lifecycle = resolveSessionLifecycle(
|
|
1098
|
+
sandboxInit,
|
|
1099
|
+
sandboxShutdown
|
|
1100
|
+
);
|
|
1101
|
+
const sandboxMode = lifecycle.mode;
|
|
1102
|
+
const resolvedShutdown = lifecycle.shutdown;
|
|
1051
1103
|
let sandboxId;
|
|
1052
1104
|
let sandboxOwned = false;
|
|
1053
1105
|
let baseSnapshot;
|
|
@@ -1070,8 +1122,8 @@ async function createSession({
|
|
|
1070
1122
|
});
|
|
1071
1123
|
}
|
|
1072
1124
|
sandboxId = sandboxInit.sandboxId;
|
|
1073
|
-
if (
|
|
1074
|
-
await
|
|
1125
|
+
if (resolvedShutdown === "pause-until-parent-close") {
|
|
1126
|
+
await wideOps().resumeSandbox(sandboxId);
|
|
1075
1127
|
}
|
|
1076
1128
|
sandboxOwned = true;
|
|
1077
1129
|
} else if (sandboxMode === "fork") {
|
|
@@ -1082,7 +1134,7 @@ async function createSession({
|
|
|
1082
1134
|
});
|
|
1083
1135
|
}
|
|
1084
1136
|
const forkInit = sandboxInit;
|
|
1085
|
-
sandboxId = await
|
|
1137
|
+
sandboxId = await wideOps().forkSandbox(
|
|
1086
1138
|
forkInit.sandboxId,
|
|
1087
1139
|
forkInit.options
|
|
1088
1140
|
);
|
|
@@ -1095,7 +1147,7 @@ async function createSession({
|
|
|
1095
1147
|
});
|
|
1096
1148
|
}
|
|
1097
1149
|
const restoreInit = sandboxInit;
|
|
1098
|
-
sandboxId = await
|
|
1150
|
+
sandboxId = await wideOps().restoreSandbox(
|
|
1099
1151
|
restoreInit.snapshot,
|
|
1100
1152
|
restoreInit.options
|
|
1101
1153
|
);
|
|
@@ -1111,8 +1163,8 @@ async function createSession({
|
|
|
1111
1163
|
freshlyCreated = true;
|
|
1112
1164
|
}
|
|
1113
1165
|
}
|
|
1114
|
-
if (sandboxId && sandboxOwned && freshlyCreated &&
|
|
1115
|
-
baseSnapshot = await
|
|
1166
|
+
if (sandboxId && sandboxOwned && freshlyCreated && resolvedShutdown === "snapshot" && sandboxOps) {
|
|
1167
|
+
baseSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1116
1168
|
}
|
|
1117
1169
|
if (sandboxId && sandboxOwned && onSandboxReady) {
|
|
1118
1170
|
onSandboxReady({
|
|
@@ -1136,12 +1188,23 @@ async function createSession({
|
|
|
1136
1188
|
path,
|
|
1137
1189
|
size: content.length,
|
|
1138
1190
|
mtime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1139
|
-
metadata: {}
|
|
1191
|
+
metadata: {},
|
|
1192
|
+
// Carry the content directly on the entry so any handler that
|
|
1193
|
+
// constructs a VirtualFileSystem from `fileTree` can read it
|
|
1194
|
+
// without needing to also wire up `inlineFiles` from state.
|
|
1195
|
+
inlineContent: content
|
|
1140
1196
|
}))
|
|
1141
1197
|
] : result.fileTree;
|
|
1142
1198
|
stateManager.mergeUpdate({
|
|
1143
1199
|
fileTree,
|
|
1144
1200
|
virtualFsCtx: virtualFsConfig.ctx,
|
|
1201
|
+
// `inlineFiles` is still the source of truth at read time:
|
|
1202
|
+
// VirtualFileSystem checks the inlineFiles map first and only
|
|
1203
|
+
// falls through to entry.inlineContent. Embedding the content on
|
|
1204
|
+
// the entry is the migration target so that handlers building a
|
|
1205
|
+
// VirtualFileSystem from `fileTree` alone (without forwarding
|
|
1206
|
+
// `inlineFiles` from state) can read skill resources. Until a
|
|
1207
|
+
// follow-up drops `inlineFiles`, both fields are populated.
|
|
1145
1208
|
...skillFiles && { inlineFiles: skillFiles }
|
|
1146
1209
|
});
|
|
1147
1210
|
}
|
|
@@ -1267,18 +1330,6 @@ async function createSession({
|
|
|
1267
1330
|
continue;
|
|
1268
1331
|
}
|
|
1269
1332
|
assistantId = void 0;
|
|
1270
|
-
if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
1271
|
-
const conditionMet = await workflow.condition(
|
|
1272
|
-
() => stateManager.getStatus() === "RUNNING",
|
|
1273
|
-
waitForInputTimeout
|
|
1274
|
-
);
|
|
1275
|
-
if (!conditionMet) {
|
|
1276
|
-
stateManager.cancel();
|
|
1277
|
-
exitReason = "cancelled";
|
|
1278
|
-
await workflow.condition(() => false, "2s");
|
|
1279
|
-
break;
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
1333
|
}
|
|
1283
1334
|
if (stateManager.getTurns() >= maxTurns && stateManager.isRunning()) {
|
|
1284
1335
|
exitReason = "max_turns";
|
|
@@ -1314,19 +1365,19 @@ async function createSession({
|
|
|
1314
1365
|
}
|
|
1315
1366
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
1316
1367
|
if (sandboxOwned && sandboxId && sandboxOps) {
|
|
1317
|
-
switch (
|
|
1368
|
+
switch (resolvedShutdown) {
|
|
1318
1369
|
case "destroy":
|
|
1319
1370
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1320
1371
|
break;
|
|
1321
1372
|
case "pause":
|
|
1322
1373
|
case "pause-until-parent-close":
|
|
1323
|
-
await
|
|
1374
|
+
await wideOps().pauseSandbox(sandboxId);
|
|
1324
1375
|
break;
|
|
1325
1376
|
case "keep":
|
|
1326
1377
|
case "keep-until-parent-close":
|
|
1327
1378
|
break;
|
|
1328
1379
|
case "snapshot":
|
|
1329
|
-
exitSnapshot = await
|
|
1380
|
+
exitSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1330
1381
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1331
1382
|
break;
|
|
1332
1383
|
}
|
|
@@ -1352,7 +1403,8 @@ async function createSession({
|
|
|
1352
1403
|
onSessionExit({
|
|
1353
1404
|
...sandboxId && { sandboxId },
|
|
1354
1405
|
...exitSnapshot && { snapshot: exitSnapshot },
|
|
1355
|
-
threadId
|
|
1406
|
+
threadId,
|
|
1407
|
+
usage: stateManager.getTotalUsage()
|
|
1356
1408
|
});
|
|
1357
1409
|
}
|
|
1358
1410
|
return {
|
|
@@ -1573,6 +1625,20 @@ function createAgentStateManager({
|
|
|
1573
1625
|
}
|
|
1574
1626
|
};
|
|
1575
1627
|
}
|
|
1628
|
+
var SandboxNotSupportedError = class extends common.ApplicationFailure {
|
|
1629
|
+
constructor(operation) {
|
|
1630
|
+
super(
|
|
1631
|
+
`Sandbox does not support: ${operation}`,
|
|
1632
|
+
"SandboxNotSupportedError",
|
|
1633
|
+
true
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
var SandboxNotFoundError = class extends common.ApplicationFailure {
|
|
1638
|
+
constructor(sandboxId) {
|
|
1639
|
+
super(`Sandbox not found: ${sandboxId}`, "SandboxNotFoundError", true);
|
|
1640
|
+
}
|
|
1641
|
+
};
|
|
1576
1642
|
|
|
1577
1643
|
// src/lib/subagent/define.ts
|
|
1578
1644
|
function defineSubagent(definition, overrides) {
|
|
@@ -1601,6 +1667,7 @@ function defineSubagentWorkflow(config, fn) {
|
|
|
1601
1667
|
let capturedSnapshot;
|
|
1602
1668
|
let capturedBaseSnapshot;
|
|
1603
1669
|
let capturedThreadId;
|
|
1670
|
+
let capturedUsage;
|
|
1604
1671
|
const sessionInput = {
|
|
1605
1672
|
agentName: config.name,
|
|
1606
1673
|
sandboxShutdown: effectiveShutdown,
|
|
@@ -1617,10 +1684,17 @@ function defineSubagentWorkflow(config, fn) {
|
|
|
1617
1684
|
});
|
|
1618
1685
|
}
|
|
1619
1686
|
},
|
|
1620
|
-
onSessionExit: ({ sandboxId, snapshot, threadId }) => {
|
|
1687
|
+
onSessionExit: ({ sandboxId, snapshot, threadId, usage }) => {
|
|
1621
1688
|
capturedSandboxId = sandboxId;
|
|
1622
1689
|
capturedSnapshot = snapshot;
|
|
1623
1690
|
capturedThreadId = threadId;
|
|
1691
|
+
capturedUsage = {
|
|
1692
|
+
inputTokens: usage.totalInputTokens,
|
|
1693
|
+
outputTokens: usage.totalOutputTokens,
|
|
1694
|
+
cachedWriteTokens: usage.totalCachedWriteTokens,
|
|
1695
|
+
cachedReadTokens: usage.totalCachedReadTokens,
|
|
1696
|
+
reasonTokens: usage.totalReasonTokens
|
|
1697
|
+
};
|
|
1624
1698
|
}
|
|
1625
1699
|
};
|
|
1626
1700
|
const result = await fn(prompt, sessionInput, context ?? {});
|
|
@@ -1631,7 +1705,8 @@ function defineSubagentWorkflow(config, fn) {
|
|
|
1631
1705
|
...capturedSnapshot !== void 0 && { snapshot: capturedSnapshot },
|
|
1632
1706
|
...capturedBaseSnapshot !== void 0 && {
|
|
1633
1707
|
baseSnapshot: capturedBaseSnapshot
|
|
1634
|
-
}
|
|
1708
|
+
},
|
|
1709
|
+
...capturedUsage !== void 0 && { usage: capturedUsage }
|
|
1635
1710
|
};
|
|
1636
1711
|
};
|
|
1637
1712
|
Object.defineProperty(workflow$1, "name", { value: config.name });
|
|
@@ -1715,20 +1790,6 @@ function proxyRunAgent(scope, options) {
|
|
|
1715
1790
|
);
|
|
1716
1791
|
return acts[name];
|
|
1717
1792
|
}
|
|
1718
|
-
var SandboxNotSupportedError = class extends common.ApplicationFailure {
|
|
1719
|
-
constructor(operation) {
|
|
1720
|
-
super(
|
|
1721
|
-
`Sandbox does not support: ${operation}`,
|
|
1722
|
-
"SandboxNotSupportedError",
|
|
1723
|
-
true
|
|
1724
|
-
);
|
|
1725
|
-
}
|
|
1726
|
-
};
|
|
1727
|
-
var SandboxNotFoundError = class extends common.ApplicationFailure {
|
|
1728
|
-
constructor(sandboxId) {
|
|
1729
|
-
super(`Sandbox not found: ${sandboxId}`, "SandboxNotFoundError", true);
|
|
1730
|
-
}
|
|
1731
|
-
};
|
|
1732
1793
|
|
|
1733
1794
|
// src/lib/virtual-fs/mutations.ts
|
|
1734
1795
|
function applyVirtualTreeMutations(stateManager, mutations) {
|