zeitlich 0.2.41 → 0.2.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{activities-qUflxmfS.d.cts → activities-Coafq5zr.d.cts} +2 -2
- package/dist/{activities-D_g13S3y.d.ts → activities-CrN-ghLo.d.ts} +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs +4 -23
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +18 -86
- package/dist/adapters/sandbox/daytona/index.d.ts +18 -86
- package/dist/adapters/sandbox/daytona/index.js +4 -23
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.cjs +1 -7
- package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.d.ts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.js +1 -7
- package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs +9 -0
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +13 -5
- package/dist/adapters/sandbox/e2b/index.d.ts +13 -5
- package/dist/adapters/sandbox/e2b/index.js +9 -1
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs +11 -0
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +11 -3
- package/dist/adapters/sandbox/inmemory/index.d.ts +11 -3
- package/dist/adapters/sandbox/inmemory/index.js +11 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +5 -5
- package/dist/adapters/thread/anthropic/index.d.ts +5 -5
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +5 -5
- package/dist/adapters/thread/anthropic/workflow.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +5 -5
- package/dist/adapters/thread/google-genai/index.d.ts +5 -5
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +5 -5
- package/dist/adapters/thread/google-genai/workflow.d.ts +5 -5
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +5 -5
- package/dist/adapters/thread/langchain/index.d.ts +5 -5
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +5 -5
- package/dist/adapters/thread/langchain/workflow.d.ts +5 -5
- package/dist/index.cjs +224 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -16
- package/dist/index.d.ts +66 -16
- package/dist/index.js +224 -70
- package/dist/index.js.map +1 -1
- package/dist/{proxy-D7mvDEO6.d.cts → proxy-Bf7uI-Hw.d.cts} +1 -1
- package/dist/{proxy-BbcgoXg1.d.ts → proxy-COqA95FW.d.ts} +1 -1
- package/dist/{thread-manager-CTXPCu9W.d.ts → thread-manager-BhkOyQ1I.d.ts} +2 -2
- package/dist/{thread-manager-Dqstsw4i.d.ts → thread-manager-Bi1XlbpJ.d.ts} +2 -2
- package/dist/{thread-manager-cLhDhRRc.d.cts → thread-manager-BsLO3Fgc.d.cts} +2 -2
- package/dist/{thread-manager-DrWfVjlj.d.cts → thread-manager-wRVVBFgj.d.cts} +2 -2
- package/dist/{types-CjF1_Idx.d.ts → types-BkX4HLzi.d.ts} +1 -1
- package/dist/{types-CdvcmXb6.d.cts → types-C66-BVBr.d.cts} +1 -1
- package/dist/types-CJ7tCdl6.d.cts +266 -0
- package/dist/types-CJ7tCdl6.d.ts +266 -0
- package/dist/{types-DjaQKUJx.d.cts → types-CdALEF3z.d.cts} +300 -20
- package/dist/{types-BqTmyH31.d.ts → types-ChAy_jSP.d.ts} +300 -20
- package/dist/types-CjY93AWZ.d.cts +84 -0
- package/dist/types-gVa5XCWD.d.ts +84 -0
- package/dist/{workflow-N1MNDoul.d.ts → workflow-BwT5EybR.d.ts} +7 -6
- package/dist/{workflow-CuqxgS6X.d.cts → workflow-DMmiaw6w.d.cts} +7 -6
- package/dist/workflow.cjs +99 -46
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +4 -4
- package/dist/workflow.d.ts +4 -4
- package/dist/workflow.js +99 -46
- package/dist/workflow.js.map +1 -1
- package/package.json +7 -32
- package/src/adapters/sandbox/daytona/index.ts +25 -48
- package/src/adapters/sandbox/daytona/proxy.ts +7 -8
- package/src/adapters/sandbox/e2b/index.ts +21 -6
- package/src/adapters/sandbox/e2b/proxy.ts +3 -2
- package/src/adapters/sandbox/inmemory/index.ts +21 -1
- package/src/adapters/sandbox/inmemory/proxy.ts +7 -3
- package/src/lib/activity.ts +5 -0
- package/src/lib/sandbox/capability-types.test.ts +859 -0
- package/src/lib/sandbox/index.ts +1 -0
- package/src/lib/sandbox/manager.ts +187 -31
- package/src/lib/sandbox/types.ts +189 -46
- package/src/lib/session/index.ts +1 -0
- package/src/lib/session/session.ts +97 -35
- package/src/lib/session/types.ts +181 -5
- package/src/lib/subagent/handler.ts +66 -43
- package/src/lib/subagent/types.ts +484 -16
- package/src/workflow.ts +3 -0
- package/tsup.config.ts +0 -4
- package/dist/adapters/sandbox/bedrock/index.cjs +0 -457
- package/dist/adapters/sandbox/bedrock/index.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/index.d.cts +0 -25
- package/dist/adapters/sandbox/bedrock/index.d.ts +0 -25
- package/dist/adapters/sandbox/bedrock/index.js +0 -454
- package/dist/adapters/sandbox/bedrock/index.js.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.cjs +0 -36
- package/dist/adapters/sandbox/bedrock/workflow.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.d.cts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.d.ts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.js +0 -34
- package/dist/adapters/sandbox/bedrock/workflow.js.map +0 -1
- package/dist/types-DAsQ21Rt.d.ts +0 -74
- package/dist/types-lm8tMNJQ.d.cts +0 -74
- package/dist/types-yx0LzPGn.d.cts +0 -173
- package/dist/types-yx0LzPGn.d.ts +0 -173
- package/src/adapters/sandbox/bedrock/filesystem.ts +0 -340
- package/src/adapters/sandbox/bedrock/index.ts +0 -274
- package/src/adapters/sandbox/bedrock/proxy.ts +0 -59
- package/src/adapters/sandbox/bedrock/types.ts +0 -24
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({
|
|
@@ -1316,19 +1369,19 @@ async function createSession({
|
|
|
1316
1369
|
}
|
|
1317
1370
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
1318
1371
|
if (sandboxOwned && sandboxId && sandboxOps) {
|
|
1319
|
-
switch (
|
|
1372
|
+
switch (resolvedShutdown) {
|
|
1320
1373
|
case "destroy":
|
|
1321
1374
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1322
1375
|
break;
|
|
1323
1376
|
case "pause":
|
|
1324
1377
|
case "pause-until-parent-close":
|
|
1325
|
-
await
|
|
1378
|
+
await wideOps().pauseSandbox(sandboxId);
|
|
1326
1379
|
break;
|
|
1327
1380
|
case "keep":
|
|
1328
1381
|
case "keep-until-parent-close":
|
|
1329
1382
|
break;
|
|
1330
1383
|
case "snapshot":
|
|
1331
|
-
exitSnapshot = await
|
|
1384
|
+
exitSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1332
1385
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1333
1386
|
break;
|
|
1334
1387
|
}
|
|
@@ -2676,6 +2729,9 @@ function getActivityContext() {
|
|
|
2676
2729
|
}
|
|
2677
2730
|
async function queryParentWorkflowState(client) {
|
|
2678
2731
|
const { workflowExecution } = activity.Context.current().info;
|
|
2732
|
+
if (!workflowExecution) {
|
|
2733
|
+
throw new Error("No workflow execution found");
|
|
2734
|
+
}
|
|
2679
2735
|
const handle = client.getHandle(
|
|
2680
2736
|
workflowExecution.workflowId,
|
|
2681
2737
|
workflowExecution.runId
|
|
@@ -2699,13 +2755,56 @@ function withParentWorkflowState(client, handler) {
|
|
|
2699
2755
|
}
|
|
2700
2756
|
|
|
2701
2757
|
// src/lib/sandbox/manager.ts
|
|
2758
|
+
var CAP_METHOD_TO_CAPABILITY = [
|
|
2759
|
+
{ method: "pause", capability: "pause" },
|
|
2760
|
+
{ method: "resume", capability: "resume" },
|
|
2761
|
+
{ method: "snapshot", capability: "snapshot" },
|
|
2762
|
+
{ method: "deleteSnapshot", capability: "snapshot" },
|
|
2763
|
+
{ method: "restore", capability: "restore" },
|
|
2764
|
+
{ method: "fork", capability: "fork" }
|
|
2765
|
+
];
|
|
2702
2766
|
var SandboxManager = class {
|
|
2703
2767
|
constructor(provider, options) {
|
|
2704
2768
|
this.provider = provider;
|
|
2705
2769
|
this.hooks = options?.hooks ?? {};
|
|
2770
|
+
this.assertCapabilityRuntimeConsistency();
|
|
2706
2771
|
}
|
|
2707
2772
|
provider;
|
|
2708
2773
|
hooks;
|
|
2774
|
+
/**
|
|
2775
|
+
* Verifies that the provider's runtime `supportedCapabilities` set is
|
|
2776
|
+
* consistent with the gated methods physically present on the provider.
|
|
2777
|
+
*
|
|
2778
|
+
* Belt-and-suspenders complement to the type-level
|
|
2779
|
+
* `ReadonlySet<TCaps & SandboxCapability>` constraint: TypeScript can
|
|
2780
|
+
* prevent the runtime set from containing capabilities not declared in
|
|
2781
|
+
* `TCaps`, but it cannot detect a provider that **declares** a cap in
|
|
2782
|
+
* `TCaps` and forgets to include it in the runtime set (or that ships
|
|
2783
|
+
* a method without listing its cap). Both shapes silently break
|
|
2784
|
+
* activity registration, so we trip a loud failure at construction
|
|
2785
|
+
* time instead.
|
|
2786
|
+
*
|
|
2787
|
+
* Adapters that derive both surfaces from a single `as const`
|
|
2788
|
+
* capability array (the recommended pattern) pass this check by
|
|
2789
|
+
* construction.
|
|
2790
|
+
*/
|
|
2791
|
+
assertCapabilityRuntimeConsistency() {
|
|
2792
|
+
const supported = this.provider.supportedCapabilities;
|
|
2793
|
+
for (const { method, capability } of CAP_METHOD_TO_CAPABILITY) {
|
|
2794
|
+
const hasMethod = typeof this.provider[method] === "function";
|
|
2795
|
+
const declaresCap = supported.has(capability);
|
|
2796
|
+
if (hasMethod && !declaresCap) {
|
|
2797
|
+
throw new Error(
|
|
2798
|
+
`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.`
|
|
2799
|
+
);
|
|
2800
|
+
}
|
|
2801
|
+
if (declaresCap && !hasMethod) {
|
|
2802
|
+
throw new Error(
|
|
2803
|
+
`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.`
|
|
2804
|
+
);
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2709
2808
|
async create(options, ctx) {
|
|
2710
2809
|
let providerOptions = options;
|
|
2711
2810
|
if (this.hooks.onPreCreate) {
|
|
@@ -2743,26 +2842,61 @@ var SandboxManager = class {
|
|
|
2743
2842
|
async destroy(id) {
|
|
2744
2843
|
await this.provider.destroy(id);
|
|
2745
2844
|
}
|
|
2845
|
+
/**
|
|
2846
|
+
* Capability-gated lifecycle methods on the underlying provider.
|
|
2847
|
+
*
|
|
2848
|
+
* These manager methods always exist at runtime; calling one whose
|
|
2849
|
+
* capability is absent from the provider's `supportedCapabilities`
|
|
2850
|
+
* throws an error. The activities returned from
|
|
2851
|
+
* {@link SandboxManager.createActivities} are gated at the type level
|
|
2852
|
+
* via `TCaps`, which is where compile-time safety is enforced.
|
|
2853
|
+
*/
|
|
2746
2854
|
async pause(id, ttlSeconds) {
|
|
2747
|
-
|
|
2855
|
+
const fn = this.providerMethod("pause");
|
|
2856
|
+
if (!fn) throw this.unsupported("pause");
|
|
2857
|
+
await fn.call(this.provider, id, ttlSeconds);
|
|
2748
2858
|
}
|
|
2749
2859
|
async resume(id) {
|
|
2750
|
-
|
|
2860
|
+
const fn = this.providerMethod("resume");
|
|
2861
|
+
if (!fn) throw this.unsupported("resume");
|
|
2862
|
+
await fn.call(this.provider, id);
|
|
2751
2863
|
}
|
|
2752
2864
|
async snapshot(id, options) {
|
|
2753
|
-
|
|
2865
|
+
const fn = this.providerMethod("snapshot");
|
|
2866
|
+
if (!fn) throw this.unsupported("snapshot");
|
|
2867
|
+
return fn.call(this.provider, id, options);
|
|
2754
2868
|
}
|
|
2755
2869
|
async restore(snapshot, options) {
|
|
2756
|
-
const
|
|
2870
|
+
const fn = this.providerMethod("restore");
|
|
2871
|
+
if (!fn) throw this.unsupported("restore");
|
|
2872
|
+
const sandbox = await fn.call(this.provider, snapshot, options);
|
|
2757
2873
|
return sandbox.id;
|
|
2758
2874
|
}
|
|
2759
2875
|
async deleteSnapshot(snapshot) {
|
|
2760
|
-
|
|
2876
|
+
const fn = this.providerMethod("deleteSnapshot");
|
|
2877
|
+
if (!fn) throw this.unsupported("deleteSnapshot");
|
|
2878
|
+
await fn.call(this.provider, snapshot);
|
|
2761
2879
|
}
|
|
2762
2880
|
async fork(sandboxId, options) {
|
|
2763
|
-
const
|
|
2881
|
+
const fn = this.providerMethod("fork");
|
|
2882
|
+
if (!fn) throw this.unsupported("fork");
|
|
2883
|
+
const sandbox = await fn.call(this.provider, sandboxId, options);
|
|
2764
2884
|
return sandbox.id;
|
|
2765
2885
|
}
|
|
2886
|
+
providerMethod(name) {
|
|
2887
|
+
const value = this.provider[name];
|
|
2888
|
+
return typeof value === "function" ? value : void 0;
|
|
2889
|
+
}
|
|
2890
|
+
/**
|
|
2891
|
+
* Constructs the structured error thrown when an unsupported lifecycle
|
|
2892
|
+
* method is invoked through the manager. Uses the public
|
|
2893
|
+
* {@link SandboxNotSupportedError} symbol so consumers that catch on
|
|
2894
|
+
* `instanceof SandboxNotSupportedError` (the documented compatibility
|
|
2895
|
+
* path) keep matching after the refactor.
|
|
2896
|
+
*/
|
|
2897
|
+
unsupported(name) {
|
|
2898
|
+
return new SandboxNotSupportedError(name);
|
|
2899
|
+
}
|
|
2766
2900
|
/**
|
|
2767
2901
|
* Returns Temporal activity functions with prefixed names.
|
|
2768
2902
|
*
|
|
@@ -2770,6 +2904,11 @@ var SandboxManager = class {
|
|
|
2770
2904
|
* to pass the workflow/scope name. Use the matching `proxy*SandboxOps()`
|
|
2771
2905
|
* helper from the adapter's `/workflow` entrypoint on the workflow side.
|
|
2772
2906
|
*
|
|
2907
|
+
* Activities are only registered for capabilities the provider declares
|
|
2908
|
+
* via {@link SandboxProvider.supportedCapabilities}: methods omitted
|
|
2909
|
+
* from the cap set are not wrapped, and the returned object's type
|
|
2910
|
+
* omits the corresponding keys.
|
|
2911
|
+
*
|
|
2773
2912
|
* @param scope - Workflow name (appended to the provider id)
|
|
2774
2913
|
*
|
|
2775
2914
|
* @example
|
|
@@ -2780,40 +2919,55 @@ var SandboxManager = class {
|
|
|
2780
2919
|
*
|
|
2781
2920
|
* const dmgr = new SandboxManager(new DaytonaSandboxProvider(config));
|
|
2782
2921
|
* dmgr.createActivities("CodingAgent");
|
|
2783
|
-
* // registers: daytonaCodingAgentCreateSandbox,
|
|
2922
|
+
* // registers: daytonaCodingAgentCreateSandbox, daytonaCodingAgentDestroySandbox
|
|
2923
|
+
* // (snapshot/restore/fork/pause/resume omitted — Daytona doesn't declare them)
|
|
2784
2924
|
* ```
|
|
2785
2925
|
*/
|
|
2786
2926
|
createActivities(scope) {
|
|
2787
2927
|
const prefix = `${this.provider.id}${scope.charAt(0).toUpperCase()}${scope.slice(1)}`;
|
|
2928
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
2929
|
+
const supported = this.provider.supportedCapabilities;
|
|
2788
2930
|
const ops = {
|
|
2789
2931
|
createSandbox: async (options, ctx) => {
|
|
2790
2932
|
return this.create(options, ctx);
|
|
2791
2933
|
},
|
|
2792
2934
|
destroySandbox: async (sandboxId) => {
|
|
2793
2935
|
await this.destroy(sandboxId);
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
if (supported.has("pause")) {
|
|
2939
|
+
ops.pauseSandbox = async (sandboxId, ttlSeconds) => {
|
|
2796
2940
|
await this.pause(sandboxId, ttlSeconds);
|
|
2797
|
-
}
|
|
2798
|
-
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
if (supported.has("resume")) {
|
|
2944
|
+
ops.resumeSandbox = async (sandboxId) => {
|
|
2799
2945
|
await this.resume(sandboxId);
|
|
2800
|
-
}
|
|
2801
|
-
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
if (supported.has("snapshot")) {
|
|
2949
|
+
ops.snapshotSandbox = async (sandboxId, options) => {
|
|
2802
2950
|
return this.snapshot(sandboxId, options);
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2805
|
-
return this.restore(snapshot, options);
|
|
2806
|
-
},
|
|
2807
|
-
deleteSandboxSnapshot: async (snapshot) => {
|
|
2951
|
+
};
|
|
2952
|
+
ops.deleteSandboxSnapshot = async (snapshot) => {
|
|
2808
2953
|
await this.deleteSnapshot(snapshot);
|
|
2809
|
-
}
|
|
2810
|
-
|
|
2954
|
+
};
|
|
2955
|
+
}
|
|
2956
|
+
if (supported.has("restore")) {
|
|
2957
|
+
ops.restoreSandbox = async (snapshot, options) => {
|
|
2958
|
+
return this.restore(snapshot, options);
|
|
2959
|
+
};
|
|
2960
|
+
}
|
|
2961
|
+
if (supported.has("fork")) {
|
|
2962
|
+
ops.forkSandbox = async (sandboxId, options) => {
|
|
2811
2963
|
return this.fork(sandboxId, options);
|
|
2812
|
-
}
|
|
2813
|
-
}
|
|
2814
|
-
const
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2966
|
+
const entries = Object.entries(ops).filter(
|
|
2967
|
+
([, v]) => typeof v === "function"
|
|
2968
|
+
);
|
|
2815
2969
|
return Object.fromEntries(
|
|
2816
|
-
|
|
2970
|
+
entries.map(([k, v]) => [`${prefix}${cap(k)}`, v])
|
|
2817
2971
|
);
|
|
2818
2972
|
}
|
|
2819
2973
|
};
|