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.js
CHANGED
|
@@ -7,6 +7,16 @@ import { Context } from '@temporalio/activity';
|
|
|
7
7
|
import { promises } from 'fs';
|
|
8
8
|
|
|
9
9
|
// src/lib/session/session.ts
|
|
10
|
+
|
|
11
|
+
// src/lib/session/types.ts
|
|
12
|
+
function resolveSessionLifecycle(init, shutdown) {
|
|
13
|
+
const resolvedInit = init ?? { mode: "new" };
|
|
14
|
+
const resolvedShutdown = shutdown ?? "destroy";
|
|
15
|
+
return {
|
|
16
|
+
mode: resolvedInit.mode,
|
|
17
|
+
shutdown: resolvedShutdown
|
|
18
|
+
};
|
|
19
|
+
}
|
|
10
20
|
function createToolRouter(options) {
|
|
11
21
|
const { appendToolResult } = options;
|
|
12
22
|
const toolMap = /* @__PURE__ */ new Map();
|
|
@@ -435,6 +445,37 @@ function createSubagentTool(subagents) {
|
|
|
435
445
|
schema
|
|
436
446
|
};
|
|
437
447
|
}
|
|
448
|
+
|
|
449
|
+
// src/lib/subagent/types.ts
|
|
450
|
+
function isSurvivalShutdown(s) {
|
|
451
|
+
return s === "pause" || s === "pause-until-parent-close" || s === "keep" || s === "keep-until-parent-close";
|
|
452
|
+
}
|
|
453
|
+
function resolveSubagentLifecycle(cfg, isLazyCreator) {
|
|
454
|
+
if (cfg.source !== "own") {
|
|
455
|
+
return {
|
|
456
|
+
shutdownOverride: cfg.shutdown,
|
|
457
|
+
mustSurvive: false
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
if (cfg.continuation === "snapshot") {
|
|
461
|
+
return {
|
|
462
|
+
shutdownOverride: "snapshot",
|
|
463
|
+
mustSurvive: false
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
const isLazy = cfg.init === "once";
|
|
467
|
+
const mustSurvive = isLazyCreator || cfg.continuation === "continue" || isLazy && cfg.continuation === "fork";
|
|
468
|
+
if (!mustSurvive) {
|
|
469
|
+
return { shutdownOverride: cfg.shutdown, mustSurvive: false };
|
|
470
|
+
}
|
|
471
|
+
if (isSurvivalShutdown(cfg.shutdown)) {
|
|
472
|
+
return { shutdownOverride: cfg.shutdown, mustSurvive };
|
|
473
|
+
}
|
|
474
|
+
return {
|
|
475
|
+
shutdownOverride: isLazyCreator ? "pause-until-parent-close" : "pause",
|
|
476
|
+
mustSurvive
|
|
477
|
+
};
|
|
478
|
+
}
|
|
438
479
|
var childSandboxReadySignal = defineSignal("childSandboxReady");
|
|
439
480
|
|
|
440
481
|
// src/lib/subagent/handler.ts
|
|
@@ -460,10 +501,18 @@ function resolveSandboxConfig(config) {
|
|
|
460
501
|
}
|
|
461
502
|
function createSubagentHandler(subagents) {
|
|
462
503
|
const { taskQueue: parentTaskQueue } = workflowInfo();
|
|
463
|
-
const
|
|
504
|
+
const agentDestroyOps = /* @__PURE__ */ new Map();
|
|
505
|
+
const agentDeleteSnapshotOps = /* @__PURE__ */ new Map();
|
|
464
506
|
for (const cfg of subagents) {
|
|
465
|
-
|
|
466
|
-
|
|
507
|
+
const cfgSandbox = cfg.sandbox;
|
|
508
|
+
if (!cfgSandbox || cfgSandbox === "none") continue;
|
|
509
|
+
if (cfgSandbox.continuation === "snapshot") {
|
|
510
|
+
const proxy = cfgSandbox.proxy(cfg.agentName);
|
|
511
|
+
agentDestroyOps.set(cfg.agentName, proxy);
|
|
512
|
+
agentDeleteSnapshotOps.set(cfg.agentName, proxy);
|
|
513
|
+
} else {
|
|
514
|
+
const proxy = cfgSandbox.proxy(cfg.agentName);
|
|
515
|
+
agentDestroyOps.set(cfg.agentName, proxy);
|
|
467
516
|
}
|
|
468
517
|
}
|
|
469
518
|
const pendingDestroys = /* @__PURE__ */ new Map();
|
|
@@ -502,7 +551,7 @@ function createSubagentHandler(subagents) {
|
|
|
502
551
|
const childWorkflowId = `${args.subagent}-${getShortId()}`;
|
|
503
552
|
const { sandboxId: parentSandboxId } = context;
|
|
504
553
|
const sandboxCfg = resolveSandboxConfig(config.sandbox);
|
|
505
|
-
if (sandboxCfg.source !== "none" && !
|
|
554
|
+
if (sandboxCfg.source !== "none" && !agentDestroyOps.has(config.agentName)) {
|
|
506
555
|
throw ApplicationFailure.create({
|
|
507
556
|
message: `Subagent "${config.agentName}" uses a sandbox but no \`sandbox.proxy\` is configured on its SubagentConfig`,
|
|
508
557
|
nonRetryable: true
|
|
@@ -570,7 +619,6 @@ function createSubagentHandler(subagents) {
|
|
|
570
619
|
if (baseSnap) {
|
|
571
620
|
sandbox = { mode: "from-snapshot", snapshot: baseSnap };
|
|
572
621
|
}
|
|
573
|
-
sandboxShutdownOverride = "snapshot";
|
|
574
622
|
} else if (sandboxCfg.source === "own") {
|
|
575
623
|
const isLazy = sandboxCfg.init === "once";
|
|
576
624
|
let baseSandboxId;
|
|
@@ -606,12 +654,10 @@ function createSubagentHandler(subagents) {
|
|
|
606
654
|
sandboxId: baseSandboxId
|
|
607
655
|
};
|
|
608
656
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
sandboxShutdownOverride = isLazyCreator ? "pause-until-parent-close" : "pause";
|
|
614
|
-
}
|
|
657
|
+
}
|
|
658
|
+
{
|
|
659
|
+
const lifecycle = resolveSubagentLifecycle(sandboxCfg, isLazyCreator);
|
|
660
|
+
sandboxShutdownOverride = lifecycle.shutdownOverride;
|
|
615
661
|
}
|
|
616
662
|
const workflowInput = {
|
|
617
663
|
...thread && { thread },
|
|
@@ -756,7 +802,7 @@ function createSubagentHandler(subagents) {
|
|
|
756
802
|
pendingDestroys.clear();
|
|
757
803
|
await Promise.all(
|
|
758
804
|
entries.map(async ({ agentName, sandboxId }) => {
|
|
759
|
-
const ops =
|
|
805
|
+
const ops = agentDestroyOps.get(agentName);
|
|
760
806
|
if (!ops) {
|
|
761
807
|
log.warn(
|
|
762
808
|
"Skipping sandbox destroy \u2014 no sandbox.proxy registered for agent",
|
|
@@ -786,7 +832,7 @@ function createSubagentHandler(subagents) {
|
|
|
786
832
|
persistentBaseSnapshot.clear();
|
|
787
833
|
await Promise.all(
|
|
788
834
|
tagged.map(async ({ agentName, snapshot }) => {
|
|
789
|
-
const ops =
|
|
835
|
+
const ops = agentDeleteSnapshotOps.get(agentName);
|
|
790
836
|
if (!ops) {
|
|
791
837
|
log.warn(
|
|
792
838
|
"Skipping snapshot delete \u2014 no sandbox.proxy registered for agent",
|
|
@@ -938,29 +984,31 @@ function collectSkillFiles(skills) {
|
|
|
938
984
|
}
|
|
939
985
|
return files;
|
|
940
986
|
}
|
|
941
|
-
async function createSession({
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
987
|
+
async function createSession(config) {
|
|
988
|
+
const {
|
|
989
|
+
agentName,
|
|
990
|
+
maxTurns = 50,
|
|
991
|
+
metadata = {},
|
|
992
|
+
runAgent,
|
|
993
|
+
threadOps,
|
|
994
|
+
buildContextMessage,
|
|
995
|
+
subagents,
|
|
996
|
+
skills,
|
|
997
|
+
tools = {},
|
|
998
|
+
processToolsInParallel = true,
|
|
999
|
+
hooks = {},
|
|
1000
|
+
appendSystemPrompt = true,
|
|
1001
|
+
threadKey,
|
|
1002
|
+
sandboxOps,
|
|
1003
|
+
thread: threadInit,
|
|
1004
|
+
sandbox: sandboxInit,
|
|
1005
|
+
sandboxShutdown,
|
|
1006
|
+
onSandboxReady,
|
|
1007
|
+
onSessionExit,
|
|
1008
|
+
virtualFs: virtualFsConfig,
|
|
1009
|
+
virtualFsOps
|
|
1010
|
+
} = config;
|
|
1011
|
+
const wideOps = () => sandboxOps;
|
|
964
1012
|
const threadMode = threadInit?.mode ?? "new";
|
|
965
1013
|
let threadId;
|
|
966
1014
|
let sourceThreadId;
|
|
@@ -1044,7 +1092,12 @@ async function createSession({
|
|
|
1044
1092
|
stateManager.run();
|
|
1045
1093
|
}
|
|
1046
1094
|
);
|
|
1047
|
-
const
|
|
1095
|
+
const lifecycle = resolveSessionLifecycle(
|
|
1096
|
+
sandboxInit,
|
|
1097
|
+
sandboxShutdown
|
|
1098
|
+
);
|
|
1099
|
+
const sandboxMode = lifecycle.mode;
|
|
1100
|
+
const resolvedShutdown = lifecycle.shutdown;
|
|
1048
1101
|
let sandboxId;
|
|
1049
1102
|
let sandboxOwned = false;
|
|
1050
1103
|
let baseSnapshot;
|
|
@@ -1067,8 +1120,8 @@ async function createSession({
|
|
|
1067
1120
|
});
|
|
1068
1121
|
}
|
|
1069
1122
|
sandboxId = sandboxInit.sandboxId;
|
|
1070
|
-
if (
|
|
1071
|
-
await
|
|
1123
|
+
if (resolvedShutdown === "pause-until-parent-close") {
|
|
1124
|
+
await wideOps().resumeSandbox(sandboxId);
|
|
1072
1125
|
}
|
|
1073
1126
|
sandboxOwned = true;
|
|
1074
1127
|
} else if (sandboxMode === "fork") {
|
|
@@ -1079,7 +1132,7 @@ async function createSession({
|
|
|
1079
1132
|
});
|
|
1080
1133
|
}
|
|
1081
1134
|
const forkInit = sandboxInit;
|
|
1082
|
-
sandboxId = await
|
|
1135
|
+
sandboxId = await wideOps().forkSandbox(
|
|
1083
1136
|
forkInit.sandboxId,
|
|
1084
1137
|
forkInit.options
|
|
1085
1138
|
);
|
|
@@ -1092,7 +1145,7 @@ async function createSession({
|
|
|
1092
1145
|
});
|
|
1093
1146
|
}
|
|
1094
1147
|
const restoreInit = sandboxInit;
|
|
1095
|
-
sandboxId = await
|
|
1148
|
+
sandboxId = await wideOps().restoreSandbox(
|
|
1096
1149
|
restoreInit.snapshot,
|
|
1097
1150
|
restoreInit.options
|
|
1098
1151
|
);
|
|
@@ -1108,8 +1161,8 @@ async function createSession({
|
|
|
1108
1161
|
freshlyCreated = true;
|
|
1109
1162
|
}
|
|
1110
1163
|
}
|
|
1111
|
-
if (sandboxId && sandboxOwned && freshlyCreated &&
|
|
1112
|
-
baseSnapshot = await
|
|
1164
|
+
if (sandboxId && sandboxOwned && freshlyCreated && resolvedShutdown === "snapshot" && sandboxOps) {
|
|
1165
|
+
baseSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1113
1166
|
}
|
|
1114
1167
|
if (sandboxId && sandboxOwned && onSandboxReady) {
|
|
1115
1168
|
onSandboxReady({
|
|
@@ -1310,19 +1363,19 @@ async function createSession({
|
|
|
1310
1363
|
}
|
|
1311
1364
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
1312
1365
|
if (sandboxOwned && sandboxId && sandboxOps) {
|
|
1313
|
-
switch (
|
|
1366
|
+
switch (resolvedShutdown) {
|
|
1314
1367
|
case "destroy":
|
|
1315
1368
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1316
1369
|
break;
|
|
1317
1370
|
case "pause":
|
|
1318
1371
|
case "pause-until-parent-close":
|
|
1319
|
-
await
|
|
1372
|
+
await wideOps().pauseSandbox(sandboxId);
|
|
1320
1373
|
break;
|
|
1321
1374
|
case "keep":
|
|
1322
1375
|
case "keep-until-parent-close":
|
|
1323
1376
|
break;
|
|
1324
1377
|
case "snapshot":
|
|
1325
|
-
exitSnapshot = await
|
|
1378
|
+
exitSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1326
1379
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1327
1380
|
break;
|
|
1328
1381
|
}
|
|
@@ -2670,6 +2723,9 @@ function getActivityContext() {
|
|
|
2670
2723
|
}
|
|
2671
2724
|
async function queryParentWorkflowState(client) {
|
|
2672
2725
|
const { workflowExecution } = Context.current().info;
|
|
2726
|
+
if (!workflowExecution) {
|
|
2727
|
+
throw new Error("No workflow execution found");
|
|
2728
|
+
}
|
|
2673
2729
|
const handle = client.getHandle(
|
|
2674
2730
|
workflowExecution.workflowId,
|
|
2675
2731
|
workflowExecution.runId
|
|
@@ -2693,13 +2749,56 @@ function withParentWorkflowState(client, handler) {
|
|
|
2693
2749
|
}
|
|
2694
2750
|
|
|
2695
2751
|
// src/lib/sandbox/manager.ts
|
|
2752
|
+
var CAP_METHOD_TO_CAPABILITY = [
|
|
2753
|
+
{ method: "pause", capability: "pause" },
|
|
2754
|
+
{ method: "resume", capability: "resume" },
|
|
2755
|
+
{ method: "snapshot", capability: "snapshot" },
|
|
2756
|
+
{ method: "deleteSnapshot", capability: "snapshot" },
|
|
2757
|
+
{ method: "restore", capability: "restore" },
|
|
2758
|
+
{ method: "fork", capability: "fork" }
|
|
2759
|
+
];
|
|
2696
2760
|
var SandboxManager = class {
|
|
2697
2761
|
constructor(provider, options) {
|
|
2698
2762
|
this.provider = provider;
|
|
2699
2763
|
this.hooks = options?.hooks ?? {};
|
|
2764
|
+
this.assertCapabilityRuntimeConsistency();
|
|
2700
2765
|
}
|
|
2701
2766
|
provider;
|
|
2702
2767
|
hooks;
|
|
2768
|
+
/**
|
|
2769
|
+
* Verifies that the provider's runtime `supportedCapabilities` set is
|
|
2770
|
+
* consistent with the gated methods physically present on the provider.
|
|
2771
|
+
*
|
|
2772
|
+
* Belt-and-suspenders complement to the type-level
|
|
2773
|
+
* `ReadonlySet<TCaps & SandboxCapability>` constraint: TypeScript can
|
|
2774
|
+
* prevent the runtime set from containing capabilities not declared in
|
|
2775
|
+
* `TCaps`, but it cannot detect a provider that **declares** a cap in
|
|
2776
|
+
* `TCaps` and forgets to include it in the runtime set (or that ships
|
|
2777
|
+
* a method without listing its cap). Both shapes silently break
|
|
2778
|
+
* activity registration, so we trip a loud failure at construction
|
|
2779
|
+
* time instead.
|
|
2780
|
+
*
|
|
2781
|
+
* Adapters that derive both surfaces from a single `as const`
|
|
2782
|
+
* capability array (the recommended pattern) pass this check by
|
|
2783
|
+
* construction.
|
|
2784
|
+
*/
|
|
2785
|
+
assertCapabilityRuntimeConsistency() {
|
|
2786
|
+
const supported = this.provider.supportedCapabilities;
|
|
2787
|
+
for (const { method, capability } of CAP_METHOD_TO_CAPABILITY) {
|
|
2788
|
+
const hasMethod = typeof this.provider[method] === "function";
|
|
2789
|
+
const declaresCap = supported.has(capability);
|
|
2790
|
+
if (hasMethod && !declaresCap) {
|
|
2791
|
+
throw new Error(
|
|
2792
|
+
`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.`
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
if (declaresCap && !hasMethod) {
|
|
2796
|
+
throw new Error(
|
|
2797
|
+
`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.`
|
|
2798
|
+
);
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2703
2802
|
async create(options, ctx) {
|
|
2704
2803
|
let providerOptions = options;
|
|
2705
2804
|
if (this.hooks.onPreCreate) {
|
|
@@ -2737,26 +2836,61 @@ var SandboxManager = class {
|
|
|
2737
2836
|
async destroy(id) {
|
|
2738
2837
|
await this.provider.destroy(id);
|
|
2739
2838
|
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Capability-gated lifecycle methods on the underlying provider.
|
|
2841
|
+
*
|
|
2842
|
+
* These manager methods always exist at runtime; calling one whose
|
|
2843
|
+
* capability is absent from the provider's `supportedCapabilities`
|
|
2844
|
+
* throws an error. The activities returned from
|
|
2845
|
+
* {@link SandboxManager.createActivities} are gated at the type level
|
|
2846
|
+
* via `TCaps`, which is where compile-time safety is enforced.
|
|
2847
|
+
*/
|
|
2740
2848
|
async pause(id, ttlSeconds) {
|
|
2741
|
-
|
|
2849
|
+
const fn = this.providerMethod("pause");
|
|
2850
|
+
if (!fn) throw this.unsupported("pause");
|
|
2851
|
+
await fn.call(this.provider, id, ttlSeconds);
|
|
2742
2852
|
}
|
|
2743
2853
|
async resume(id) {
|
|
2744
|
-
|
|
2854
|
+
const fn = this.providerMethod("resume");
|
|
2855
|
+
if (!fn) throw this.unsupported("resume");
|
|
2856
|
+
await fn.call(this.provider, id);
|
|
2745
2857
|
}
|
|
2746
2858
|
async snapshot(id, options) {
|
|
2747
|
-
|
|
2859
|
+
const fn = this.providerMethod("snapshot");
|
|
2860
|
+
if (!fn) throw this.unsupported("snapshot");
|
|
2861
|
+
return fn.call(this.provider, id, options);
|
|
2748
2862
|
}
|
|
2749
2863
|
async restore(snapshot, options) {
|
|
2750
|
-
const
|
|
2864
|
+
const fn = this.providerMethod("restore");
|
|
2865
|
+
if (!fn) throw this.unsupported("restore");
|
|
2866
|
+
const sandbox = await fn.call(this.provider, snapshot, options);
|
|
2751
2867
|
return sandbox.id;
|
|
2752
2868
|
}
|
|
2753
2869
|
async deleteSnapshot(snapshot) {
|
|
2754
|
-
|
|
2870
|
+
const fn = this.providerMethod("deleteSnapshot");
|
|
2871
|
+
if (!fn) throw this.unsupported("deleteSnapshot");
|
|
2872
|
+
await fn.call(this.provider, snapshot);
|
|
2755
2873
|
}
|
|
2756
2874
|
async fork(sandboxId, options) {
|
|
2757
|
-
const
|
|
2875
|
+
const fn = this.providerMethod("fork");
|
|
2876
|
+
if (!fn) throw this.unsupported("fork");
|
|
2877
|
+
const sandbox = await fn.call(this.provider, sandboxId, options);
|
|
2758
2878
|
return sandbox.id;
|
|
2759
2879
|
}
|
|
2880
|
+
providerMethod(name) {
|
|
2881
|
+
const value = this.provider[name];
|
|
2882
|
+
return typeof value === "function" ? value : void 0;
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Constructs the structured error thrown when an unsupported lifecycle
|
|
2886
|
+
* method is invoked through the manager. Uses the public
|
|
2887
|
+
* {@link SandboxNotSupportedError} symbol so consumers that catch on
|
|
2888
|
+
* `instanceof SandboxNotSupportedError` (the documented compatibility
|
|
2889
|
+
* path) keep matching after the refactor.
|
|
2890
|
+
*/
|
|
2891
|
+
unsupported(name) {
|
|
2892
|
+
return new SandboxNotSupportedError(name);
|
|
2893
|
+
}
|
|
2760
2894
|
/**
|
|
2761
2895
|
* Returns Temporal activity functions with prefixed names.
|
|
2762
2896
|
*
|
|
@@ -2764,6 +2898,11 @@ var SandboxManager = class {
|
|
|
2764
2898
|
* to pass the workflow/scope name. Use the matching `proxy*SandboxOps()`
|
|
2765
2899
|
* helper from the adapter's `/workflow` entrypoint on the workflow side.
|
|
2766
2900
|
*
|
|
2901
|
+
* Activities are only registered for capabilities the provider declares
|
|
2902
|
+
* via {@link SandboxProvider.supportedCapabilities}: methods omitted
|
|
2903
|
+
* from the cap set are not wrapped, and the returned object's type
|
|
2904
|
+
* omits the corresponding keys.
|
|
2905
|
+
*
|
|
2767
2906
|
* @param scope - Workflow name (appended to the provider id)
|
|
2768
2907
|
*
|
|
2769
2908
|
* @example
|
|
@@ -2774,40 +2913,55 @@ var SandboxManager = class {
|
|
|
2774
2913
|
*
|
|
2775
2914
|
* const dmgr = new SandboxManager(new DaytonaSandboxProvider(config));
|
|
2776
2915
|
* dmgr.createActivities("CodingAgent");
|
|
2777
|
-
* // registers: daytonaCodingAgentCreateSandbox,
|
|
2916
|
+
* // registers: daytonaCodingAgentCreateSandbox, daytonaCodingAgentDestroySandbox
|
|
2917
|
+
* // (snapshot/restore/fork/pause/resume omitted — Daytona doesn't declare them)
|
|
2778
2918
|
* ```
|
|
2779
2919
|
*/
|
|
2780
2920
|
createActivities(scope) {
|
|
2781
2921
|
const prefix = `${this.provider.id}${scope.charAt(0).toUpperCase()}${scope.slice(1)}`;
|
|
2922
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
2923
|
+
const supported = this.provider.supportedCapabilities;
|
|
2782
2924
|
const ops = {
|
|
2783
2925
|
createSandbox: async (options, ctx) => {
|
|
2784
2926
|
return this.create(options, ctx);
|
|
2785
2927
|
},
|
|
2786
2928
|
destroySandbox: async (sandboxId) => {
|
|
2787
2929
|
await this.destroy(sandboxId);
|
|
2788
|
-
}
|
|
2789
|
-
|
|
2930
|
+
}
|
|
2931
|
+
};
|
|
2932
|
+
if (supported.has("pause")) {
|
|
2933
|
+
ops.pauseSandbox = async (sandboxId, ttlSeconds) => {
|
|
2790
2934
|
await this.pause(sandboxId, ttlSeconds);
|
|
2791
|
-
}
|
|
2792
|
-
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2937
|
+
if (supported.has("resume")) {
|
|
2938
|
+
ops.resumeSandbox = async (sandboxId) => {
|
|
2793
2939
|
await this.resume(sandboxId);
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2940
|
+
};
|
|
2941
|
+
}
|
|
2942
|
+
if (supported.has("snapshot")) {
|
|
2943
|
+
ops.snapshotSandbox = async (sandboxId, options) => {
|
|
2796
2944
|
return this.snapshot(sandboxId, options);
|
|
2797
|
-
}
|
|
2798
|
-
|
|
2799
|
-
return this.restore(snapshot, options);
|
|
2800
|
-
},
|
|
2801
|
-
deleteSandboxSnapshot: async (snapshot) => {
|
|
2945
|
+
};
|
|
2946
|
+
ops.deleteSandboxSnapshot = async (snapshot) => {
|
|
2802
2947
|
await this.deleteSnapshot(snapshot);
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
if (supported.has("restore")) {
|
|
2951
|
+
ops.restoreSandbox = async (snapshot, options) => {
|
|
2952
|
+
return this.restore(snapshot, options);
|
|
2953
|
+
};
|
|
2954
|
+
}
|
|
2955
|
+
if (supported.has("fork")) {
|
|
2956
|
+
ops.forkSandbox = async (sandboxId, options) => {
|
|
2805
2957
|
return this.fork(sandboxId, options);
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
const
|
|
2958
|
+
};
|
|
2959
|
+
}
|
|
2960
|
+
const entries = Object.entries(ops).filter(
|
|
2961
|
+
([, v]) => typeof v === "function"
|
|
2962
|
+
);
|
|
2809
2963
|
return Object.fromEntries(
|
|
2810
|
-
|
|
2964
|
+
entries.map(([k, v]) => [`${prefix}${cap(k)}`, v])
|
|
2811
2965
|
);
|
|
2812
2966
|
}
|
|
2813
2967
|
};
|