zeitlich 0.2.41 → 0.2.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{activities-qUflxmfS.d.cts → activities-Coafq5zr.d.cts} +2 -2
- package/dist/{activities-D_g13S3y.d.ts → activities-CrN-ghLo.d.ts} +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs +4 -23
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +18 -86
- package/dist/adapters/sandbox/daytona/index.d.ts +18 -86
- package/dist/adapters/sandbox/daytona/index.js +4 -23
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.cjs +1 -7
- package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.d.ts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.js +1 -7
- package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs +9 -0
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +13 -5
- package/dist/adapters/sandbox/e2b/index.d.ts +13 -5
- package/dist/adapters/sandbox/e2b/index.js +9 -1
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs +11 -0
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +11 -3
- package/dist/adapters/sandbox/inmemory/index.d.ts +11 -3
- package/dist/adapters/sandbox/inmemory/index.js +11 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +5 -5
- package/dist/adapters/thread/anthropic/index.d.ts +5 -5
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +5 -5
- package/dist/adapters/thread/google-genai/index.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
- package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +5 -5
- package/dist/adapters/thread/langchain/index.d.ts +5 -5
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
- package/dist/index.cjs +229 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -16
- package/dist/index.d.ts +66 -16
- package/dist/index.js +229 -72
- package/dist/index.js.map +1 -1
- package/dist/{proxy-D7mvDEO6.d.cts → proxy-Bf7uI-Hw.d.cts} +1 -1
- package/dist/{proxy-BbcgoXg1.d.ts → proxy-COqA95FW.d.ts} +1 -1
- package/dist/{thread-manager-CTXPCu9W.d.ts → thread-manager-BhkOyQ1I.d.ts} +2 -2
- package/dist/{thread-manager-Dqstsw4i.d.ts → thread-manager-Bi1XlbpJ.d.ts} +2 -2
- package/dist/{thread-manager-cLhDhRRc.d.cts → thread-manager-BsLO3Fgc.d.cts} +2 -2
- package/dist/{thread-manager-DrWfVjlj.d.cts → thread-manager-wRVVBFgj.d.cts} +2 -2
- package/dist/{types-CjF1_Idx.d.ts → types-BkX4HLzi.d.ts} +1 -1
- package/dist/{types-CdvcmXb6.d.cts → types-C66-BVBr.d.cts} +1 -1
- package/dist/types-CJ7tCdl6.d.cts +266 -0
- package/dist/types-CJ7tCdl6.d.ts +266 -0
- package/dist/{types-DjaQKUJx.d.cts → types-CdALEF3z.d.cts} +300 -20
- package/dist/{types-BqTmyH31.d.ts → types-ChAy_jSP.d.ts} +300 -20
- package/dist/types-CjY93AWZ.d.cts +84 -0
- package/dist/types-gVa5XCWD.d.ts +84 -0
- package/dist/{workflow-N1MNDoul.d.ts → workflow-BwT5EybR.d.ts} +7 -6
- package/dist/{workflow-CuqxgS6X.d.cts → workflow-DMmiaw6w.d.cts} +7 -6
- package/dist/workflow.cjs +104 -48
- 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 +104 -48
- package/dist/workflow.js.map +1 -1
- package/package.json +7 -32
- package/src/adapters/sandbox/daytona/index.ts +25 -48
- package/src/adapters/sandbox/daytona/proxy.ts +7 -8
- package/src/adapters/sandbox/e2b/index.ts +21 -6
- package/src/adapters/sandbox/e2b/proxy.ts +3 -2
- package/src/adapters/sandbox/inmemory/index.ts +21 -1
- package/src/adapters/sandbox/inmemory/proxy.ts +7 -3
- package/src/lib/activity.ts +5 -0
- package/src/lib/sandbox/capability-types.test.ts +859 -0
- package/src/lib/sandbox/index.ts +1 -0
- package/src/lib/sandbox/manager.ts +187 -31
- package/src/lib/sandbox/types.ts +189 -46
- package/src/lib/session/index.ts +1 -0
- package/src/lib/session/session-edge-cases.integration.test.ts +16 -10
- package/src/lib/session/session.ts +105 -35
- package/src/lib/session/types.ts +181 -5
- package/src/lib/subagent/handler.ts +66 -43
- package/src/lib/subagent/types.ts +484 -16
- package/src/lib/subagent/workflow.ts +2 -2
- 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
package/dist/index.cjs
CHANGED
|
@@ -13,6 +13,16 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
13
13
|
var z14__default = /*#__PURE__*/_interopDefault(z14);
|
|
14
14
|
|
|
15
15
|
// src/lib/session/session.ts
|
|
16
|
+
|
|
17
|
+
// src/lib/session/types.ts
|
|
18
|
+
function resolveSessionLifecycle(init, shutdown) {
|
|
19
|
+
const resolvedInit = init ?? { mode: "new" };
|
|
20
|
+
const resolvedShutdown = shutdown ?? "destroy";
|
|
21
|
+
return {
|
|
22
|
+
mode: resolvedInit.mode,
|
|
23
|
+
shutdown: resolvedShutdown
|
|
24
|
+
};
|
|
25
|
+
}
|
|
16
26
|
function createToolRouter(options) {
|
|
17
27
|
const { appendToolResult } = options;
|
|
18
28
|
const toolMap = /* @__PURE__ */ new Map();
|
|
@@ -441,6 +451,37 @@ function createSubagentTool(subagents) {
|
|
|
441
451
|
schema
|
|
442
452
|
};
|
|
443
453
|
}
|
|
454
|
+
|
|
455
|
+
// src/lib/subagent/types.ts
|
|
456
|
+
function isSurvivalShutdown(s) {
|
|
457
|
+
return s === "pause" || s === "pause-until-parent-close" || s === "keep" || s === "keep-until-parent-close";
|
|
458
|
+
}
|
|
459
|
+
function resolveSubagentLifecycle(cfg, isLazyCreator) {
|
|
460
|
+
if (cfg.source !== "own") {
|
|
461
|
+
return {
|
|
462
|
+
shutdownOverride: cfg.shutdown,
|
|
463
|
+
mustSurvive: false
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
if (cfg.continuation === "snapshot") {
|
|
467
|
+
return {
|
|
468
|
+
shutdownOverride: "snapshot",
|
|
469
|
+
mustSurvive: false
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
const isLazy = cfg.init === "once";
|
|
473
|
+
const mustSurvive = isLazyCreator || cfg.continuation === "continue" || isLazy && cfg.continuation === "fork";
|
|
474
|
+
if (!mustSurvive) {
|
|
475
|
+
return { shutdownOverride: cfg.shutdown, mustSurvive: false };
|
|
476
|
+
}
|
|
477
|
+
if (isSurvivalShutdown(cfg.shutdown)) {
|
|
478
|
+
return { shutdownOverride: cfg.shutdown, mustSurvive };
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
shutdownOverride: isLazyCreator ? "pause-until-parent-close" : "pause",
|
|
482
|
+
mustSurvive
|
|
483
|
+
};
|
|
484
|
+
}
|
|
444
485
|
var childSandboxReadySignal = workflow.defineSignal("childSandboxReady");
|
|
445
486
|
|
|
446
487
|
// src/lib/subagent/handler.ts
|
|
@@ -466,10 +507,18 @@ function resolveSandboxConfig(config) {
|
|
|
466
507
|
}
|
|
467
508
|
function createSubagentHandler(subagents) {
|
|
468
509
|
const { taskQueue: parentTaskQueue } = workflow.workflowInfo();
|
|
469
|
-
const
|
|
510
|
+
const agentDestroyOps = /* @__PURE__ */ new Map();
|
|
511
|
+
const agentDeleteSnapshotOps = /* @__PURE__ */ new Map();
|
|
470
512
|
for (const cfg of subagents) {
|
|
471
|
-
|
|
472
|
-
|
|
513
|
+
const cfgSandbox = cfg.sandbox;
|
|
514
|
+
if (!cfgSandbox || cfgSandbox === "none") continue;
|
|
515
|
+
if (cfgSandbox.continuation === "snapshot") {
|
|
516
|
+
const proxy = cfgSandbox.proxy(cfg.agentName);
|
|
517
|
+
agentDestroyOps.set(cfg.agentName, proxy);
|
|
518
|
+
agentDeleteSnapshotOps.set(cfg.agentName, proxy);
|
|
519
|
+
} else {
|
|
520
|
+
const proxy = cfgSandbox.proxy(cfg.agentName);
|
|
521
|
+
agentDestroyOps.set(cfg.agentName, proxy);
|
|
473
522
|
}
|
|
474
523
|
}
|
|
475
524
|
const pendingDestroys = /* @__PURE__ */ new Map();
|
|
@@ -508,7 +557,7 @@ function createSubagentHandler(subagents) {
|
|
|
508
557
|
const childWorkflowId = `${args.subagent}-${getShortId()}`;
|
|
509
558
|
const { sandboxId: parentSandboxId } = context;
|
|
510
559
|
const sandboxCfg = resolveSandboxConfig(config.sandbox);
|
|
511
|
-
if (sandboxCfg.source !== "none" && !
|
|
560
|
+
if (sandboxCfg.source !== "none" && !agentDestroyOps.has(config.agentName)) {
|
|
512
561
|
throw workflow.ApplicationFailure.create({
|
|
513
562
|
message: `Subagent "${config.agentName}" uses a sandbox but no \`sandbox.proxy\` is configured on its SubagentConfig`,
|
|
514
563
|
nonRetryable: true
|
|
@@ -576,7 +625,6 @@ function createSubagentHandler(subagents) {
|
|
|
576
625
|
if (baseSnap) {
|
|
577
626
|
sandbox = { mode: "from-snapshot", snapshot: baseSnap };
|
|
578
627
|
}
|
|
579
|
-
sandboxShutdownOverride = "snapshot";
|
|
580
628
|
} else if (sandboxCfg.source === "own") {
|
|
581
629
|
const isLazy = sandboxCfg.init === "once";
|
|
582
630
|
let baseSandboxId;
|
|
@@ -612,12 +660,10 @@ function createSubagentHandler(subagents) {
|
|
|
612
660
|
sandboxId: baseSandboxId
|
|
613
661
|
};
|
|
614
662
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
sandboxShutdownOverride = isLazyCreator ? "pause-until-parent-close" : "pause";
|
|
620
|
-
}
|
|
663
|
+
}
|
|
664
|
+
{
|
|
665
|
+
const lifecycle = resolveSubagentLifecycle(sandboxCfg, isLazyCreator);
|
|
666
|
+
sandboxShutdownOverride = lifecycle.shutdownOverride;
|
|
621
667
|
}
|
|
622
668
|
const workflowInput = {
|
|
623
669
|
...thread && { thread },
|
|
@@ -762,7 +808,7 @@ function createSubagentHandler(subagents) {
|
|
|
762
808
|
pendingDestroys.clear();
|
|
763
809
|
await Promise.all(
|
|
764
810
|
entries.map(async ({ agentName, sandboxId }) => {
|
|
765
|
-
const ops =
|
|
811
|
+
const ops = agentDestroyOps.get(agentName);
|
|
766
812
|
if (!ops) {
|
|
767
813
|
workflow.log.warn(
|
|
768
814
|
"Skipping sandbox destroy \u2014 no sandbox.proxy registered for agent",
|
|
@@ -792,7 +838,7 @@ function createSubagentHandler(subagents) {
|
|
|
792
838
|
persistentBaseSnapshot.clear();
|
|
793
839
|
await Promise.all(
|
|
794
840
|
tagged.map(async ({ agentName, snapshot }) => {
|
|
795
|
-
const ops =
|
|
841
|
+
const ops = agentDeleteSnapshotOps.get(agentName);
|
|
796
842
|
if (!ops) {
|
|
797
843
|
workflow.log.warn(
|
|
798
844
|
"Skipping snapshot delete \u2014 no sandbox.proxy registered for agent",
|
|
@@ -944,29 +990,31 @@ function collectSkillFiles(skills) {
|
|
|
944
990
|
}
|
|
945
991
|
return files;
|
|
946
992
|
}
|
|
947
|
-
async function createSession({
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
993
|
+
async function createSession(config) {
|
|
994
|
+
const {
|
|
995
|
+
agentName,
|
|
996
|
+
maxTurns = 50,
|
|
997
|
+
metadata = {},
|
|
998
|
+
runAgent,
|
|
999
|
+
threadOps,
|
|
1000
|
+
buildContextMessage,
|
|
1001
|
+
subagents,
|
|
1002
|
+
skills,
|
|
1003
|
+
tools = {},
|
|
1004
|
+
processToolsInParallel = true,
|
|
1005
|
+
hooks = {},
|
|
1006
|
+
appendSystemPrompt = true,
|
|
1007
|
+
threadKey,
|
|
1008
|
+
sandboxOps,
|
|
1009
|
+
thread: threadInit,
|
|
1010
|
+
sandbox: sandboxInit,
|
|
1011
|
+
sandboxShutdown,
|
|
1012
|
+
onSandboxReady,
|
|
1013
|
+
onSessionExit,
|
|
1014
|
+
virtualFs: virtualFsConfig,
|
|
1015
|
+
virtualFsOps
|
|
1016
|
+
} = config;
|
|
1017
|
+
const wideOps = () => sandboxOps;
|
|
970
1018
|
const threadMode = threadInit?.mode ?? "new";
|
|
971
1019
|
let threadId;
|
|
972
1020
|
let sourceThreadId;
|
|
@@ -1050,7 +1098,12 @@ async function createSession({
|
|
|
1050
1098
|
stateManager.run();
|
|
1051
1099
|
}
|
|
1052
1100
|
);
|
|
1053
|
-
const
|
|
1101
|
+
const lifecycle = resolveSessionLifecycle(
|
|
1102
|
+
sandboxInit,
|
|
1103
|
+
sandboxShutdown
|
|
1104
|
+
);
|
|
1105
|
+
const sandboxMode = lifecycle.mode;
|
|
1106
|
+
const resolvedShutdown = lifecycle.shutdown;
|
|
1054
1107
|
let sandboxId;
|
|
1055
1108
|
let sandboxOwned = false;
|
|
1056
1109
|
let baseSnapshot;
|
|
@@ -1073,8 +1126,8 @@ async function createSession({
|
|
|
1073
1126
|
});
|
|
1074
1127
|
}
|
|
1075
1128
|
sandboxId = sandboxInit.sandboxId;
|
|
1076
|
-
if (
|
|
1077
|
-
await
|
|
1129
|
+
if (resolvedShutdown === "pause-until-parent-close") {
|
|
1130
|
+
await wideOps().resumeSandbox(sandboxId);
|
|
1078
1131
|
}
|
|
1079
1132
|
sandboxOwned = true;
|
|
1080
1133
|
} else if (sandboxMode === "fork") {
|
|
@@ -1085,7 +1138,7 @@ async function createSession({
|
|
|
1085
1138
|
});
|
|
1086
1139
|
}
|
|
1087
1140
|
const forkInit = sandboxInit;
|
|
1088
|
-
sandboxId = await
|
|
1141
|
+
sandboxId = await wideOps().forkSandbox(
|
|
1089
1142
|
forkInit.sandboxId,
|
|
1090
1143
|
forkInit.options
|
|
1091
1144
|
);
|
|
@@ -1098,7 +1151,7 @@ async function createSession({
|
|
|
1098
1151
|
});
|
|
1099
1152
|
}
|
|
1100
1153
|
const restoreInit = sandboxInit;
|
|
1101
|
-
sandboxId = await
|
|
1154
|
+
sandboxId = await wideOps().restoreSandbox(
|
|
1102
1155
|
restoreInit.snapshot,
|
|
1103
1156
|
restoreInit.options
|
|
1104
1157
|
);
|
|
@@ -1114,8 +1167,8 @@ async function createSession({
|
|
|
1114
1167
|
freshlyCreated = true;
|
|
1115
1168
|
}
|
|
1116
1169
|
}
|
|
1117
|
-
if (sandboxId && sandboxOwned && freshlyCreated &&
|
|
1118
|
-
baseSnapshot = await
|
|
1170
|
+
if (sandboxId && sandboxOwned && freshlyCreated && resolvedShutdown === "snapshot" && sandboxOps) {
|
|
1171
|
+
baseSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1119
1172
|
}
|
|
1120
1173
|
if (sandboxId && sandboxOwned && onSandboxReady) {
|
|
1121
1174
|
onSandboxReady({
|
|
@@ -1289,6 +1342,9 @@ async function createSession({
|
|
|
1289
1342
|
threadId,
|
|
1290
1343
|
maxTurns
|
|
1291
1344
|
});
|
|
1345
|
+
} else if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
1346
|
+
exitReason = "waiting_for_input";
|
|
1347
|
+
workflow.log.info("session waiting for input", { agentName, threadId });
|
|
1292
1348
|
}
|
|
1293
1349
|
} catch (error) {
|
|
1294
1350
|
exitReason = "failed";
|
|
@@ -1316,19 +1372,19 @@ async function createSession({
|
|
|
1316
1372
|
}
|
|
1317
1373
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
1318
1374
|
if (sandboxOwned && sandboxId && sandboxOps) {
|
|
1319
|
-
switch (
|
|
1375
|
+
switch (resolvedShutdown) {
|
|
1320
1376
|
case "destroy":
|
|
1321
1377
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1322
1378
|
break;
|
|
1323
1379
|
case "pause":
|
|
1324
1380
|
case "pause-until-parent-close":
|
|
1325
|
-
await
|
|
1381
|
+
await wideOps().pauseSandbox(sandboxId);
|
|
1326
1382
|
break;
|
|
1327
1383
|
case "keep":
|
|
1328
1384
|
case "keep-until-parent-close":
|
|
1329
1385
|
break;
|
|
1330
1386
|
case "snapshot":
|
|
1331
|
-
exitSnapshot = await
|
|
1387
|
+
exitSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1332
1388
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1333
1389
|
break;
|
|
1334
1390
|
}
|
|
@@ -1743,14 +1799,14 @@ function defineSubagentWorkflow(config, fn) {
|
|
|
1743
1799
|
};
|
|
1744
1800
|
const result = await fn(prompt, sessionInput, context ?? {});
|
|
1745
1801
|
return {
|
|
1746
|
-
...result,
|
|
1747
1802
|
...capturedThreadId !== void 0 && { threadId: capturedThreadId },
|
|
1748
1803
|
...capturedSandboxId !== void 0 && { sandboxId: capturedSandboxId },
|
|
1749
1804
|
...capturedSnapshot !== void 0 && { snapshot: capturedSnapshot },
|
|
1750
1805
|
...capturedBaseSnapshot !== void 0 && {
|
|
1751
1806
|
baseSnapshot: capturedBaseSnapshot
|
|
1752
1807
|
},
|
|
1753
|
-
...capturedUsage !== void 0 && { usage: capturedUsage }
|
|
1808
|
+
...capturedUsage !== void 0 && { usage: capturedUsage },
|
|
1809
|
+
...result
|
|
1754
1810
|
};
|
|
1755
1811
|
};
|
|
1756
1812
|
Object.defineProperty(workflow$1, "name", { value: config.name });
|
|
@@ -2676,6 +2732,9 @@ function getActivityContext() {
|
|
|
2676
2732
|
}
|
|
2677
2733
|
async function queryParentWorkflowState(client) {
|
|
2678
2734
|
const { workflowExecution } = activity.Context.current().info;
|
|
2735
|
+
if (!workflowExecution) {
|
|
2736
|
+
throw new Error("No workflow execution found");
|
|
2737
|
+
}
|
|
2679
2738
|
const handle = client.getHandle(
|
|
2680
2739
|
workflowExecution.workflowId,
|
|
2681
2740
|
workflowExecution.runId
|
|
@@ -2699,13 +2758,56 @@ function withParentWorkflowState(client, handler) {
|
|
|
2699
2758
|
}
|
|
2700
2759
|
|
|
2701
2760
|
// src/lib/sandbox/manager.ts
|
|
2761
|
+
var CAP_METHOD_TO_CAPABILITY = [
|
|
2762
|
+
{ method: "pause", capability: "pause" },
|
|
2763
|
+
{ method: "resume", capability: "resume" },
|
|
2764
|
+
{ method: "snapshot", capability: "snapshot" },
|
|
2765
|
+
{ method: "deleteSnapshot", capability: "snapshot" },
|
|
2766
|
+
{ method: "restore", capability: "restore" },
|
|
2767
|
+
{ method: "fork", capability: "fork" }
|
|
2768
|
+
];
|
|
2702
2769
|
var SandboxManager = class {
|
|
2703
2770
|
constructor(provider, options) {
|
|
2704
2771
|
this.provider = provider;
|
|
2705
2772
|
this.hooks = options?.hooks ?? {};
|
|
2773
|
+
this.assertCapabilityRuntimeConsistency();
|
|
2706
2774
|
}
|
|
2707
2775
|
provider;
|
|
2708
2776
|
hooks;
|
|
2777
|
+
/**
|
|
2778
|
+
* Verifies that the provider's runtime `supportedCapabilities` set is
|
|
2779
|
+
* consistent with the gated methods physically present on the provider.
|
|
2780
|
+
*
|
|
2781
|
+
* Belt-and-suspenders complement to the type-level
|
|
2782
|
+
* `ReadonlySet<TCaps & SandboxCapability>` constraint: TypeScript can
|
|
2783
|
+
* prevent the runtime set from containing capabilities not declared in
|
|
2784
|
+
* `TCaps`, but it cannot detect a provider that **declares** a cap in
|
|
2785
|
+
* `TCaps` and forgets to include it in the runtime set (or that ships
|
|
2786
|
+
* a method without listing its cap). Both shapes silently break
|
|
2787
|
+
* activity registration, so we trip a loud failure at construction
|
|
2788
|
+
* time instead.
|
|
2789
|
+
*
|
|
2790
|
+
* Adapters that derive both surfaces from a single `as const`
|
|
2791
|
+
* capability array (the recommended pattern) pass this check by
|
|
2792
|
+
* construction.
|
|
2793
|
+
*/
|
|
2794
|
+
assertCapabilityRuntimeConsistency() {
|
|
2795
|
+
const supported = this.provider.supportedCapabilities;
|
|
2796
|
+
for (const { method, capability } of CAP_METHOD_TO_CAPABILITY) {
|
|
2797
|
+
const hasMethod = typeof this.provider[method] === "function";
|
|
2798
|
+
const declaresCap = supported.has(capability);
|
|
2799
|
+
if (hasMethod && !declaresCap) {
|
|
2800
|
+
throw new Error(
|
|
2801
|
+
`Sandbox provider "${this.provider.id}" implements ${method}() but does not list "${capability}" in supportedCapabilities. Add the capability to the provider's runtime set so activities for it can be registered.`
|
|
2802
|
+
);
|
|
2803
|
+
}
|
|
2804
|
+
if (declaresCap && !hasMethod) {
|
|
2805
|
+
throw new Error(
|
|
2806
|
+
`Sandbox provider "${this.provider.id}" lists "${capability}" in supportedCapabilities but does not implement ${method}(). Either add the method to the provider or remove the capability from supportedCapabilities.`
|
|
2807
|
+
);
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2709
2811
|
async create(options, ctx) {
|
|
2710
2812
|
let providerOptions = options;
|
|
2711
2813
|
if (this.hooks.onPreCreate) {
|
|
@@ -2743,26 +2845,61 @@ var SandboxManager = class {
|
|
|
2743
2845
|
async destroy(id) {
|
|
2744
2846
|
await this.provider.destroy(id);
|
|
2745
2847
|
}
|
|
2848
|
+
/**
|
|
2849
|
+
* Capability-gated lifecycle methods on the underlying provider.
|
|
2850
|
+
*
|
|
2851
|
+
* These manager methods always exist at runtime; calling one whose
|
|
2852
|
+
* capability is absent from the provider's `supportedCapabilities`
|
|
2853
|
+
* throws an error. The activities returned from
|
|
2854
|
+
* {@link SandboxManager.createActivities} are gated at the type level
|
|
2855
|
+
* via `TCaps`, which is where compile-time safety is enforced.
|
|
2856
|
+
*/
|
|
2746
2857
|
async pause(id, ttlSeconds) {
|
|
2747
|
-
|
|
2858
|
+
const fn = this.providerMethod("pause");
|
|
2859
|
+
if (!fn) throw this.unsupported("pause");
|
|
2860
|
+
await fn.call(this.provider, id, ttlSeconds);
|
|
2748
2861
|
}
|
|
2749
2862
|
async resume(id) {
|
|
2750
|
-
|
|
2863
|
+
const fn = this.providerMethod("resume");
|
|
2864
|
+
if (!fn) throw this.unsupported("resume");
|
|
2865
|
+
await fn.call(this.provider, id);
|
|
2751
2866
|
}
|
|
2752
2867
|
async snapshot(id, options) {
|
|
2753
|
-
|
|
2868
|
+
const fn = this.providerMethod("snapshot");
|
|
2869
|
+
if (!fn) throw this.unsupported("snapshot");
|
|
2870
|
+
return fn.call(this.provider, id, options);
|
|
2754
2871
|
}
|
|
2755
2872
|
async restore(snapshot, options) {
|
|
2756
|
-
const
|
|
2873
|
+
const fn = this.providerMethod("restore");
|
|
2874
|
+
if (!fn) throw this.unsupported("restore");
|
|
2875
|
+
const sandbox = await fn.call(this.provider, snapshot, options);
|
|
2757
2876
|
return sandbox.id;
|
|
2758
2877
|
}
|
|
2759
2878
|
async deleteSnapshot(snapshot) {
|
|
2760
|
-
|
|
2879
|
+
const fn = this.providerMethod("deleteSnapshot");
|
|
2880
|
+
if (!fn) throw this.unsupported("deleteSnapshot");
|
|
2881
|
+
await fn.call(this.provider, snapshot);
|
|
2761
2882
|
}
|
|
2762
2883
|
async fork(sandboxId, options) {
|
|
2763
|
-
const
|
|
2884
|
+
const fn = this.providerMethod("fork");
|
|
2885
|
+
if (!fn) throw this.unsupported("fork");
|
|
2886
|
+
const sandbox = await fn.call(this.provider, sandboxId, options);
|
|
2764
2887
|
return sandbox.id;
|
|
2765
2888
|
}
|
|
2889
|
+
providerMethod(name) {
|
|
2890
|
+
const value = this.provider[name];
|
|
2891
|
+
return typeof value === "function" ? value : void 0;
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* Constructs the structured error thrown when an unsupported lifecycle
|
|
2895
|
+
* method is invoked through the manager. Uses the public
|
|
2896
|
+
* {@link SandboxNotSupportedError} symbol so consumers that catch on
|
|
2897
|
+
* `instanceof SandboxNotSupportedError` (the documented compatibility
|
|
2898
|
+
* path) keep matching after the refactor.
|
|
2899
|
+
*/
|
|
2900
|
+
unsupported(name) {
|
|
2901
|
+
return new SandboxNotSupportedError(name);
|
|
2902
|
+
}
|
|
2766
2903
|
/**
|
|
2767
2904
|
* Returns Temporal activity functions with prefixed names.
|
|
2768
2905
|
*
|
|
@@ -2770,6 +2907,11 @@ var SandboxManager = class {
|
|
|
2770
2907
|
* to pass the workflow/scope name. Use the matching `proxy*SandboxOps()`
|
|
2771
2908
|
* helper from the adapter's `/workflow` entrypoint on the workflow side.
|
|
2772
2909
|
*
|
|
2910
|
+
* Activities are only registered for capabilities the provider declares
|
|
2911
|
+
* via {@link SandboxProvider.supportedCapabilities}: methods omitted
|
|
2912
|
+
* from the cap set are not wrapped, and the returned object's type
|
|
2913
|
+
* omits the corresponding keys.
|
|
2914
|
+
*
|
|
2773
2915
|
* @param scope - Workflow name (appended to the provider id)
|
|
2774
2916
|
*
|
|
2775
2917
|
* @example
|
|
@@ -2780,40 +2922,55 @@ var SandboxManager = class {
|
|
|
2780
2922
|
*
|
|
2781
2923
|
* const dmgr = new SandboxManager(new DaytonaSandboxProvider(config));
|
|
2782
2924
|
* dmgr.createActivities("CodingAgent");
|
|
2783
|
-
* // registers: daytonaCodingAgentCreateSandbox,
|
|
2925
|
+
* // registers: daytonaCodingAgentCreateSandbox, daytonaCodingAgentDestroySandbox
|
|
2926
|
+
* // (snapshot/restore/fork/pause/resume omitted — Daytona doesn't declare them)
|
|
2784
2927
|
* ```
|
|
2785
2928
|
*/
|
|
2786
2929
|
createActivities(scope) {
|
|
2787
2930
|
const prefix = `${this.provider.id}${scope.charAt(0).toUpperCase()}${scope.slice(1)}`;
|
|
2931
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
2932
|
+
const supported = this.provider.supportedCapabilities;
|
|
2788
2933
|
const ops = {
|
|
2789
2934
|
createSandbox: async (options, ctx) => {
|
|
2790
2935
|
return this.create(options, ctx);
|
|
2791
2936
|
},
|
|
2792
2937
|
destroySandbox: async (sandboxId) => {
|
|
2793
2938
|
await this.destroy(sandboxId);
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
if (supported.has("pause")) {
|
|
2942
|
+
ops.pauseSandbox = async (sandboxId, ttlSeconds) => {
|
|
2796
2943
|
await this.pause(sandboxId, ttlSeconds);
|
|
2797
|
-
}
|
|
2798
|
-
|
|
2944
|
+
};
|
|
2945
|
+
}
|
|
2946
|
+
if (supported.has("resume")) {
|
|
2947
|
+
ops.resumeSandbox = async (sandboxId) => {
|
|
2799
2948
|
await this.resume(sandboxId);
|
|
2800
|
-
}
|
|
2801
|
-
|
|
2949
|
+
};
|
|
2950
|
+
}
|
|
2951
|
+
if (supported.has("snapshot")) {
|
|
2952
|
+
ops.snapshotSandbox = async (sandboxId, options) => {
|
|
2802
2953
|
return this.snapshot(sandboxId, options);
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2805
|
-
return this.restore(snapshot, options);
|
|
2806
|
-
},
|
|
2807
|
-
deleteSandboxSnapshot: async (snapshot) => {
|
|
2954
|
+
};
|
|
2955
|
+
ops.deleteSandboxSnapshot = async (snapshot) => {
|
|
2808
2956
|
await this.deleteSnapshot(snapshot);
|
|
2809
|
-
}
|
|
2810
|
-
|
|
2957
|
+
};
|
|
2958
|
+
}
|
|
2959
|
+
if (supported.has("restore")) {
|
|
2960
|
+
ops.restoreSandbox = async (snapshot, options) => {
|
|
2961
|
+
return this.restore(snapshot, options);
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
if (supported.has("fork")) {
|
|
2965
|
+
ops.forkSandbox = async (sandboxId, options) => {
|
|
2811
2966
|
return this.fork(sandboxId, options);
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
const
|
|
2967
|
+
};
|
|
2968
|
+
}
|
|
2969
|
+
const entries = Object.entries(ops).filter(
|
|
2970
|
+
([, v]) => typeof v === "function"
|
|
2971
|
+
);
|
|
2815
2972
|
return Object.fromEntries(
|
|
2816
|
-
|
|
2973
|
+
entries.map(([k, v]) => [`${prefix}${cap(k)}`, v])
|
|
2817
2974
|
);
|
|
2818
2975
|
}
|
|
2819
2976
|
};
|