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.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({
|
|
@@ -1283,6 +1336,9 @@ async function createSession({
|
|
|
1283
1336
|
threadId,
|
|
1284
1337
|
maxTurns
|
|
1285
1338
|
});
|
|
1339
|
+
} else if (stateManager.getStatus() === "WAITING_FOR_INPUT") {
|
|
1340
|
+
exitReason = "waiting_for_input";
|
|
1341
|
+
log.info("session waiting for input", { agentName, threadId });
|
|
1286
1342
|
}
|
|
1287
1343
|
} catch (error) {
|
|
1288
1344
|
exitReason = "failed";
|
|
@@ -1310,19 +1366,19 @@ async function createSession({
|
|
|
1310
1366
|
}
|
|
1311
1367
|
await callSessionEnd(exitReason, stateManager.getTurns());
|
|
1312
1368
|
if (sandboxOwned && sandboxId && sandboxOps) {
|
|
1313
|
-
switch (
|
|
1369
|
+
switch (resolvedShutdown) {
|
|
1314
1370
|
case "destroy":
|
|
1315
1371
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1316
1372
|
break;
|
|
1317
1373
|
case "pause":
|
|
1318
1374
|
case "pause-until-parent-close":
|
|
1319
|
-
await
|
|
1375
|
+
await wideOps().pauseSandbox(sandboxId);
|
|
1320
1376
|
break;
|
|
1321
1377
|
case "keep":
|
|
1322
1378
|
case "keep-until-parent-close":
|
|
1323
1379
|
break;
|
|
1324
1380
|
case "snapshot":
|
|
1325
|
-
exitSnapshot = await
|
|
1381
|
+
exitSnapshot = await wideOps().snapshotSandbox(sandboxId);
|
|
1326
1382
|
await sandboxOps.destroySandbox(sandboxId);
|
|
1327
1383
|
break;
|
|
1328
1384
|
}
|
|
@@ -1737,14 +1793,14 @@ function defineSubagentWorkflow(config, fn) {
|
|
|
1737
1793
|
};
|
|
1738
1794
|
const result = await fn(prompt, sessionInput, context ?? {});
|
|
1739
1795
|
return {
|
|
1740
|
-
...result,
|
|
1741
1796
|
...capturedThreadId !== void 0 && { threadId: capturedThreadId },
|
|
1742
1797
|
...capturedSandboxId !== void 0 && { sandboxId: capturedSandboxId },
|
|
1743
1798
|
...capturedSnapshot !== void 0 && { snapshot: capturedSnapshot },
|
|
1744
1799
|
...capturedBaseSnapshot !== void 0 && {
|
|
1745
1800
|
baseSnapshot: capturedBaseSnapshot
|
|
1746
1801
|
},
|
|
1747
|
-
...capturedUsage !== void 0 && { usage: capturedUsage }
|
|
1802
|
+
...capturedUsage !== void 0 && { usage: capturedUsage },
|
|
1803
|
+
...result
|
|
1748
1804
|
};
|
|
1749
1805
|
};
|
|
1750
1806
|
Object.defineProperty(workflow, "name", { value: config.name });
|
|
@@ -2670,6 +2726,9 @@ function getActivityContext() {
|
|
|
2670
2726
|
}
|
|
2671
2727
|
async function queryParentWorkflowState(client) {
|
|
2672
2728
|
const { workflowExecution } = Context.current().info;
|
|
2729
|
+
if (!workflowExecution) {
|
|
2730
|
+
throw new Error("No workflow execution found");
|
|
2731
|
+
}
|
|
2673
2732
|
const handle = client.getHandle(
|
|
2674
2733
|
workflowExecution.workflowId,
|
|
2675
2734
|
workflowExecution.runId
|
|
@@ -2693,13 +2752,56 @@ function withParentWorkflowState(client, handler) {
|
|
|
2693
2752
|
}
|
|
2694
2753
|
|
|
2695
2754
|
// src/lib/sandbox/manager.ts
|
|
2755
|
+
var CAP_METHOD_TO_CAPABILITY = [
|
|
2756
|
+
{ method: "pause", capability: "pause" },
|
|
2757
|
+
{ method: "resume", capability: "resume" },
|
|
2758
|
+
{ method: "snapshot", capability: "snapshot" },
|
|
2759
|
+
{ method: "deleteSnapshot", capability: "snapshot" },
|
|
2760
|
+
{ method: "restore", capability: "restore" },
|
|
2761
|
+
{ method: "fork", capability: "fork" }
|
|
2762
|
+
];
|
|
2696
2763
|
var SandboxManager = class {
|
|
2697
2764
|
constructor(provider, options) {
|
|
2698
2765
|
this.provider = provider;
|
|
2699
2766
|
this.hooks = options?.hooks ?? {};
|
|
2767
|
+
this.assertCapabilityRuntimeConsistency();
|
|
2700
2768
|
}
|
|
2701
2769
|
provider;
|
|
2702
2770
|
hooks;
|
|
2771
|
+
/**
|
|
2772
|
+
* Verifies that the provider's runtime `supportedCapabilities` set is
|
|
2773
|
+
* consistent with the gated methods physically present on the provider.
|
|
2774
|
+
*
|
|
2775
|
+
* Belt-and-suspenders complement to the type-level
|
|
2776
|
+
* `ReadonlySet<TCaps & SandboxCapability>` constraint: TypeScript can
|
|
2777
|
+
* prevent the runtime set from containing capabilities not declared in
|
|
2778
|
+
* `TCaps`, but it cannot detect a provider that **declares** a cap in
|
|
2779
|
+
* `TCaps` and forgets to include it in the runtime set (or that ships
|
|
2780
|
+
* a method without listing its cap). Both shapes silently break
|
|
2781
|
+
* activity registration, so we trip a loud failure at construction
|
|
2782
|
+
* time instead.
|
|
2783
|
+
*
|
|
2784
|
+
* Adapters that derive both surfaces from a single `as const`
|
|
2785
|
+
* capability array (the recommended pattern) pass this check by
|
|
2786
|
+
* construction.
|
|
2787
|
+
*/
|
|
2788
|
+
assertCapabilityRuntimeConsistency() {
|
|
2789
|
+
const supported = this.provider.supportedCapabilities;
|
|
2790
|
+
for (const { method, capability } of CAP_METHOD_TO_CAPABILITY) {
|
|
2791
|
+
const hasMethod = typeof this.provider[method] === "function";
|
|
2792
|
+
const declaresCap = supported.has(capability);
|
|
2793
|
+
if (hasMethod && !declaresCap) {
|
|
2794
|
+
throw new Error(
|
|
2795
|
+
`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.`
|
|
2796
|
+
);
|
|
2797
|
+
}
|
|
2798
|
+
if (declaresCap && !hasMethod) {
|
|
2799
|
+
throw new Error(
|
|
2800
|
+
`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.`
|
|
2801
|
+
);
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2703
2805
|
async create(options, ctx) {
|
|
2704
2806
|
let providerOptions = options;
|
|
2705
2807
|
if (this.hooks.onPreCreate) {
|
|
@@ -2737,26 +2839,61 @@ var SandboxManager = class {
|
|
|
2737
2839
|
async destroy(id) {
|
|
2738
2840
|
await this.provider.destroy(id);
|
|
2739
2841
|
}
|
|
2842
|
+
/**
|
|
2843
|
+
* Capability-gated lifecycle methods on the underlying provider.
|
|
2844
|
+
*
|
|
2845
|
+
* These manager methods always exist at runtime; calling one whose
|
|
2846
|
+
* capability is absent from the provider's `supportedCapabilities`
|
|
2847
|
+
* throws an error. The activities returned from
|
|
2848
|
+
* {@link SandboxManager.createActivities} are gated at the type level
|
|
2849
|
+
* via `TCaps`, which is where compile-time safety is enforced.
|
|
2850
|
+
*/
|
|
2740
2851
|
async pause(id, ttlSeconds) {
|
|
2741
|
-
|
|
2852
|
+
const fn = this.providerMethod("pause");
|
|
2853
|
+
if (!fn) throw this.unsupported("pause");
|
|
2854
|
+
await fn.call(this.provider, id, ttlSeconds);
|
|
2742
2855
|
}
|
|
2743
2856
|
async resume(id) {
|
|
2744
|
-
|
|
2857
|
+
const fn = this.providerMethod("resume");
|
|
2858
|
+
if (!fn) throw this.unsupported("resume");
|
|
2859
|
+
await fn.call(this.provider, id);
|
|
2745
2860
|
}
|
|
2746
2861
|
async snapshot(id, options) {
|
|
2747
|
-
|
|
2862
|
+
const fn = this.providerMethod("snapshot");
|
|
2863
|
+
if (!fn) throw this.unsupported("snapshot");
|
|
2864
|
+
return fn.call(this.provider, id, options);
|
|
2748
2865
|
}
|
|
2749
2866
|
async restore(snapshot, options) {
|
|
2750
|
-
const
|
|
2867
|
+
const fn = this.providerMethod("restore");
|
|
2868
|
+
if (!fn) throw this.unsupported("restore");
|
|
2869
|
+
const sandbox = await fn.call(this.provider, snapshot, options);
|
|
2751
2870
|
return sandbox.id;
|
|
2752
2871
|
}
|
|
2753
2872
|
async deleteSnapshot(snapshot) {
|
|
2754
|
-
|
|
2873
|
+
const fn = this.providerMethod("deleteSnapshot");
|
|
2874
|
+
if (!fn) throw this.unsupported("deleteSnapshot");
|
|
2875
|
+
await fn.call(this.provider, snapshot);
|
|
2755
2876
|
}
|
|
2756
2877
|
async fork(sandboxId, options) {
|
|
2757
|
-
const
|
|
2878
|
+
const fn = this.providerMethod("fork");
|
|
2879
|
+
if (!fn) throw this.unsupported("fork");
|
|
2880
|
+
const sandbox = await fn.call(this.provider, sandboxId, options);
|
|
2758
2881
|
return sandbox.id;
|
|
2759
2882
|
}
|
|
2883
|
+
providerMethod(name) {
|
|
2884
|
+
const value = this.provider[name];
|
|
2885
|
+
return typeof value === "function" ? value : void 0;
|
|
2886
|
+
}
|
|
2887
|
+
/**
|
|
2888
|
+
* Constructs the structured error thrown when an unsupported lifecycle
|
|
2889
|
+
* method is invoked through the manager. Uses the public
|
|
2890
|
+
* {@link SandboxNotSupportedError} symbol so consumers that catch on
|
|
2891
|
+
* `instanceof SandboxNotSupportedError` (the documented compatibility
|
|
2892
|
+
* path) keep matching after the refactor.
|
|
2893
|
+
*/
|
|
2894
|
+
unsupported(name) {
|
|
2895
|
+
return new SandboxNotSupportedError(name);
|
|
2896
|
+
}
|
|
2760
2897
|
/**
|
|
2761
2898
|
* Returns Temporal activity functions with prefixed names.
|
|
2762
2899
|
*
|
|
@@ -2764,6 +2901,11 @@ var SandboxManager = class {
|
|
|
2764
2901
|
* to pass the workflow/scope name. Use the matching `proxy*SandboxOps()`
|
|
2765
2902
|
* helper from the adapter's `/workflow` entrypoint on the workflow side.
|
|
2766
2903
|
*
|
|
2904
|
+
* Activities are only registered for capabilities the provider declares
|
|
2905
|
+
* via {@link SandboxProvider.supportedCapabilities}: methods omitted
|
|
2906
|
+
* from the cap set are not wrapped, and the returned object's type
|
|
2907
|
+
* omits the corresponding keys.
|
|
2908
|
+
*
|
|
2767
2909
|
* @param scope - Workflow name (appended to the provider id)
|
|
2768
2910
|
*
|
|
2769
2911
|
* @example
|
|
@@ -2774,40 +2916,55 @@ var SandboxManager = class {
|
|
|
2774
2916
|
*
|
|
2775
2917
|
* const dmgr = new SandboxManager(new DaytonaSandboxProvider(config));
|
|
2776
2918
|
* dmgr.createActivities("CodingAgent");
|
|
2777
|
-
* // registers: daytonaCodingAgentCreateSandbox,
|
|
2919
|
+
* // registers: daytonaCodingAgentCreateSandbox, daytonaCodingAgentDestroySandbox
|
|
2920
|
+
* // (snapshot/restore/fork/pause/resume omitted — Daytona doesn't declare them)
|
|
2778
2921
|
* ```
|
|
2779
2922
|
*/
|
|
2780
2923
|
createActivities(scope) {
|
|
2781
2924
|
const prefix = `${this.provider.id}${scope.charAt(0).toUpperCase()}${scope.slice(1)}`;
|
|
2925
|
+
const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
2926
|
+
const supported = this.provider.supportedCapabilities;
|
|
2782
2927
|
const ops = {
|
|
2783
2928
|
createSandbox: async (options, ctx) => {
|
|
2784
2929
|
return this.create(options, ctx);
|
|
2785
2930
|
},
|
|
2786
2931
|
destroySandbox: async (sandboxId) => {
|
|
2787
2932
|
await this.destroy(sandboxId);
|
|
2788
|
-
}
|
|
2789
|
-
|
|
2933
|
+
}
|
|
2934
|
+
};
|
|
2935
|
+
if (supported.has("pause")) {
|
|
2936
|
+
ops.pauseSandbox = async (sandboxId, ttlSeconds) => {
|
|
2790
2937
|
await this.pause(sandboxId, ttlSeconds);
|
|
2791
|
-
}
|
|
2792
|
-
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
if (supported.has("resume")) {
|
|
2941
|
+
ops.resumeSandbox = async (sandboxId) => {
|
|
2793
2942
|
await this.resume(sandboxId);
|
|
2794
|
-
}
|
|
2795
|
-
|
|
2943
|
+
};
|
|
2944
|
+
}
|
|
2945
|
+
if (supported.has("snapshot")) {
|
|
2946
|
+
ops.snapshotSandbox = async (sandboxId, options) => {
|
|
2796
2947
|
return this.snapshot(sandboxId, options);
|
|
2797
|
-
}
|
|
2798
|
-
|
|
2799
|
-
return this.restore(snapshot, options);
|
|
2800
|
-
},
|
|
2801
|
-
deleteSandboxSnapshot: async (snapshot) => {
|
|
2948
|
+
};
|
|
2949
|
+
ops.deleteSandboxSnapshot = async (snapshot) => {
|
|
2802
2950
|
await this.deleteSnapshot(snapshot);
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2951
|
+
};
|
|
2952
|
+
}
|
|
2953
|
+
if (supported.has("restore")) {
|
|
2954
|
+
ops.restoreSandbox = async (snapshot, options) => {
|
|
2955
|
+
return this.restore(snapshot, options);
|
|
2956
|
+
};
|
|
2957
|
+
}
|
|
2958
|
+
if (supported.has("fork")) {
|
|
2959
|
+
ops.forkSandbox = async (sandboxId, options) => {
|
|
2805
2960
|
return this.fork(sandboxId, options);
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
const
|
|
2961
|
+
};
|
|
2962
|
+
}
|
|
2963
|
+
const entries = Object.entries(ops).filter(
|
|
2964
|
+
([, v]) => typeof v === "function"
|
|
2965
|
+
);
|
|
2809
2966
|
return Object.fromEntries(
|
|
2810
|
-
|
|
2967
|
+
entries.map(([k, v]) => [`${prefix}${cap(k)}`, v])
|
|
2811
2968
|
);
|
|
2812
2969
|
}
|
|
2813
2970
|
};
|