zeitlich 0.2.40 → 0.2.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/{activities-CvUrG3YG.d.cts → activities-Coafq5zr.d.cts} +2 -2
- package/dist/{activities-CULxRzJ1.d.ts → activities-CrN-ghLo.d.ts} +2 -2
- package/dist/adapters/sandbox/daytona/index.cjs +4 -23
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +18 -86
- package/dist/adapters/sandbox/daytona/index.d.ts +18 -86
- package/dist/adapters/sandbox/daytona/index.js +4 -23
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.cjs +1 -7
- package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.d.cts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.d.ts +9 -2
- package/dist/adapters/sandbox/daytona/workflow.js +1 -7
- package/dist/adapters/sandbox/daytona/workflow.js.map +1 -1
- package/dist/adapters/sandbox/e2b/index.cjs +21 -3
- package/dist/adapters/sandbox/e2b/index.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/index.d.cts +48 -7
- package/dist/adapters/sandbox/e2b/index.d.ts +48 -7
- package/dist/adapters/sandbox/e2b/index.js +22 -5
- package/dist/adapters/sandbox/e2b/index.js.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/e2b/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/e2b/workflow.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.cjs +11 -0
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +11 -3
- package/dist/adapters/sandbox/inmemory/index.d.ts +11 -3
- package/dist/adapters/sandbox/inmemory/index.js +11 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +4 -2
- package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -1
- package/dist/adapters/thread/anthropic/index.cjs.map +1 -1
- package/dist/adapters/thread/anthropic/index.d.cts +6 -6
- package/dist/adapters/thread/anthropic/index.d.ts +6 -6
- package/dist/adapters/thread/anthropic/index.js.map +1 -1
- package/dist/adapters/thread/anthropic/workflow.d.cts +6 -6
- package/dist/adapters/thread/anthropic/workflow.d.ts +6 -6
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +6 -6
- package/dist/adapters/thread/google-genai/index.d.ts +6 -6
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.d.cts +6 -6
- package/dist/adapters/thread/google-genai/workflow.d.ts +6 -6
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +6 -6
- package/dist/adapters/thread/langchain/index.d.ts +6 -6
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.d.cts +6 -6
- package/dist/adapters/thread/langchain/workflow.d.ts +6 -6
- package/dist/index.cjs +316 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -17
- package/dist/index.d.ts +93 -17
- package/dist/index.js +317 -120
- package/dist/index.js.map +1 -1
- package/dist/{proxy-5EbwzaY4.d.cts → proxy-Bf7uI-Hw.d.cts} +1 -1
- package/dist/{proxy-wZufFfBh.d.ts → proxy-COqA95FW.d.ts} +1 -1
- package/dist/{thread-manager-BqBAIsED.d.ts → thread-manager-BhkOyQ1I.d.ts} +2 -2
- package/dist/{thread-manager-BNiIt5r8.d.ts → thread-manager-Bi1XlbpJ.d.ts} +2 -2
- package/dist/{thread-manager-DF8WuCRs.d.cts → thread-manager-BsLO3Fgc.d.cts} +2 -2
- package/dist/{thread-manager-BoN5DOvG.d.cts → thread-manager-wRVVBFgj.d.cts} +2 -2
- package/dist/{types-C7OoY7h8.d.ts → types-BkX4HLzi.d.ts} +1 -1
- package/dist/{types-CuISs0Ub.d.cts → types-C66-BVBr.d.cts} +1 -1
- package/dist/types-CJ7tCdl6.d.cts +266 -0
- package/dist/types-CJ7tCdl6.d.ts +266 -0
- package/dist/{types-DeQH84C_.d.ts → types-CdALEF3z.d.cts} +342 -23
- package/dist/{types-Cn2r3ol3.d.cts → types-ChAy_jSP.d.ts} +342 -23
- package/dist/types-CjY93AWZ.d.cts +84 -0
- package/dist/types-gVa5XCWD.d.ts +84 -0
- package/dist/{workflow-DhplIN65.d.cts → workflow-BwT5EybR.d.ts} +7 -6
- package/dist/{workflow-C2MZZj5K.d.ts → workflow-DMmiaw6w.d.cts} +7 -6
- package/dist/workflow.cjs +138 -77
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +4 -4
- package/dist/workflow.d.ts +4 -4
- package/dist/workflow.js +139 -78
- package/dist/workflow.js.map +1 -1
- package/package.json +17 -33
- package/src/adapters/sandbox/daytona/index.ts +25 -48
- package/src/adapters/sandbox/daytona/proxy.ts +7 -8
- package/src/adapters/sandbox/e2b/README.md +81 -0
- package/src/adapters/sandbox/e2b/index.ts +53 -11
- package/src/adapters/sandbox/e2b/keep-alive.test.ts +115 -0
- package/src/adapters/sandbox/e2b/proxy.ts +3 -2
- package/src/adapters/sandbox/e2b/types.ts +34 -2
- package/src/adapters/sandbox/inmemory/index.ts +21 -1
- package/src/adapters/sandbox/inmemory/proxy.ts +7 -3
- package/src/index.ts +1 -1
- package/src/lib/activity.ts +5 -0
- package/src/lib/sandbox/capability-types.test.ts +859 -0
- package/src/lib/sandbox/index.ts +1 -0
- package/src/lib/sandbox/manager.ts +187 -31
- package/src/lib/sandbox/types.ts +189 -46
- package/src/lib/session/index.ts +1 -0
- package/src/lib/session/session.integration.test.ts +58 -0
- package/src/lib/session/session.ts +109 -50
- package/src/lib/session/types.ts +189 -8
- package/src/lib/subagent/handler.ts +66 -43
- package/src/lib/subagent/subagent.integration.test.ts +2 -0
- package/src/lib/subagent/types.ts +492 -16
- package/src/lib/subagent/workflow.ts +11 -1
- package/src/lib/tool-router/auto-append-sandbox.integration.test.ts +158 -0
- package/src/lib/tool-router/index.ts +1 -1
- package/src/lib/tool-router/with-sandbox.ts +45 -2
- package/src/lib/virtual-fs/filesystem.ts +41 -16
- package/src/lib/virtual-fs/types.ts +19 -0
- package/src/lib/virtual-fs/virtual-fs.test.ts +204 -1
- package/src/tools/read-file/handler.test.ts +83 -0
- package/src/workflow.ts +3 -0
- package/tsup.config.ts +0 -4
- package/dist/adapters/sandbox/bedrock/index.cjs +0 -457
- package/dist/adapters/sandbox/bedrock/index.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/index.d.cts +0 -25
- package/dist/adapters/sandbox/bedrock/index.d.ts +0 -25
- package/dist/adapters/sandbox/bedrock/index.js +0 -454
- package/dist/adapters/sandbox/bedrock/index.js.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.cjs +0 -36
- package/dist/adapters/sandbox/bedrock/workflow.cjs.map +0 -1
- package/dist/adapters/sandbox/bedrock/workflow.d.cts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.d.ts +0 -29
- package/dist/adapters/sandbox/bedrock/workflow.js +0 -34
- package/dist/adapters/sandbox/bedrock/workflow.js.map +0 -1
- package/dist/types-DAsQ21Rt.d.ts +0 -74
- package/dist/types-lm8tMNJQ.d.cts +0 -74
- package/dist/types-yx0LzPGn.d.cts +0 -173
- package/dist/types-yx0LzPGn.d.ts +0 -173
- package/src/adapters/sandbox/bedrock/filesystem.ts +0 -340
- package/src/adapters/sandbox/bedrock/index.ts +0 -274
- package/src/adapters/sandbox/bedrock/proxy.ts +0 -59
- package/src/adapters/sandbox/bedrock/types.ts +0 -24
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Duration } from '@temporalio/common';
|
|
2
1
|
import { ActivityFunctionWithOptions, QueryDefinition, ChildWorkflowOptions, ActivityInterfaceFor } from '@temporalio/workflow';
|
|
3
2
|
import { UpdateDefinition } from '@temporalio/common/lib/interfaces';
|
|
4
3
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
4
|
+
import { g as SandboxSnapshot, c as SandboxFileSystem, F as FileStat, D as DirentEntry, a as SandboxCreateOptions, S as SandboxOps, h as SandboxCapability } from './types-CJ7tCdl6.cjs';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* A tool definition with a name, description, and Zod schema for arguments.
|
|
@@ -544,6 +543,13 @@ declare class VirtualFileSystem<TCtx = unknown, TMeta = FileEntryMetadata> imple
|
|
|
544
543
|
getEntry(path: string): FileEntry<TMeta> | undefined;
|
|
545
544
|
readFile(path: string): Promise<string>;
|
|
546
545
|
readFileBuffer(path: string): Promise<Uint8Array>;
|
|
546
|
+
/**
|
|
547
|
+
* Resolve the string content for an entry, preferring inline content
|
|
548
|
+
* carried on the entry itself before consulting the resolver. Used by
|
|
549
|
+
* `readFile`, `appendFile`, and `cp` so all read paths agree on the
|
|
550
|
+
* lookup precedence.
|
|
551
|
+
*/
|
|
552
|
+
private readEntryContent;
|
|
547
553
|
exists(path: string): Promise<boolean>;
|
|
548
554
|
stat(path: string): Promise<FileStat>;
|
|
549
555
|
readdir(path: string): Promise<string[]>;
|
|
@@ -577,6 +583,25 @@ interface FileEntry<TMeta = FileEntryMetadata> {
|
|
|
577
583
|
/** ISO-8601 date string (JSON-safe) */
|
|
578
584
|
mtime: string;
|
|
579
585
|
metadata: TMeta;
|
|
586
|
+
/**
|
|
587
|
+
* Optional inline content carried directly on the entry. When present the
|
|
588
|
+
* {@link VirtualFileSystem} returns this string from `readFile` /
|
|
589
|
+
* `readFileBuffer` (and uses it as the source for `cp` / `appendFile`)
|
|
590
|
+
* without consulting the resolver.
|
|
591
|
+
*
|
|
592
|
+
* Use this for files that exist purely in workflow state and have no
|
|
593
|
+
* backing in the consumer's data layer (e.g. skill resources bundled at
|
|
594
|
+
* session creation time). Because the content travels with the entry,
|
|
595
|
+
* any tool handler that constructs a `VirtualFileSystem` from `fileTree`
|
|
596
|
+
* sees the same content — no separate `inlineFiles` plumbing required.
|
|
597
|
+
*
|
|
598
|
+
* Read-only: entries with `inlineContent` reject in-place mutations
|
|
599
|
+
* (`writeFile`, `appendFile`, `rm`, `mv` of the entry, `cp` over the
|
|
600
|
+
* entry as destination). The resolver has no contract for the synthetic
|
|
601
|
+
* `id` these entries carry, so attempting a mutation throws an `EROFS`
|
|
602
|
+
* error instead of silently routing a doomed call through the resolver.
|
|
603
|
+
*/
|
|
604
|
+
inlineContent?: string;
|
|
580
605
|
}
|
|
581
606
|
/**
|
|
582
607
|
* Flat list of file entries.
|
|
@@ -971,6 +996,212 @@ type SubagentDefinition<TResult extends z.ZodType = z.ZodType, TContext extends
|
|
|
971
996
|
};
|
|
972
997
|
/** Context value or factory — resolved at invocation time when a function is provided */
|
|
973
998
|
type SubagentContext = Record<string, unknown> | (() => Record<string, unknown>);
|
|
999
|
+
/** Shutdown classes that the runtime treats equivalently for cap purposes. */
|
|
1000
|
+
type _ShutdownPauseLike = "pause" | "pause-until-parent-close";
|
|
1001
|
+
type _ShutdownKeepLike = "keep" | "keep-until-parent-close";
|
|
1002
|
+
/**
|
|
1003
|
+
* Caps the child session's sandbox-init dispatch invokes for a given
|
|
1004
|
+
* `(mode, shutdown)`. Mirror of `src/lib/session/session.ts:230-314`.
|
|
1005
|
+
*/
|
|
1006
|
+
type _ChildModeCaps<Mode, Shutdown> = (Mode extends "fork" ? "fork" : never) | (Mode extends "from-snapshot" ? "restore" : never) | (Mode extends "continue" ? Shutdown extends "pause-until-parent-close" ? "resume" : never : never);
|
|
1007
|
+
/**
|
|
1008
|
+
* Caps the child session's exit dispatch invokes for a given `shutdown`.
|
|
1009
|
+
* Only fires when `sandboxOwned` is true (mode != "inherit"). Mirror of
|
|
1010
|
+
* `src/lib/session/session.ts:598-615`.
|
|
1011
|
+
*/
|
|
1012
|
+
type _ChildShutdownCaps<Mode, Shutdown> = Mode extends "inherit" ? never : (Shutdown extends _ShutdownPauseLike ? "pause" : never) | (Shutdown extends "snapshot" ? "snapshot" : never);
|
|
1013
|
+
/**
|
|
1014
|
+
* Caps captured on entry for `mode: "new"` + `shutdown: "snapshot"`
|
|
1015
|
+
* (the seeding-base-snapshot path). Mirror of
|
|
1016
|
+
* `src/lib/session/session.ts:316-317`.
|
|
1017
|
+
*/
|
|
1018
|
+
type _ChildSeedCaps<Mode, Shutdown> = Mode extends "new" ? Shutdown extends "snapshot" ? "snapshot" : never : never;
|
|
1019
|
+
/**
|
|
1020
|
+
* Total caps a single child-session invocation calls for the specific
|
|
1021
|
+
* `(mode, shutdown)` pair the parent passes. The proxy field's required
|
|
1022
|
+
* cap union is the union of this across every `(mode, shutdown)` the
|
|
1023
|
+
* runtime might inject for the given config.
|
|
1024
|
+
*/
|
|
1025
|
+
type _ChildSessionCaps<Mode, Shutdown> = _ChildModeCaps<Mode, Shutdown> | _ChildShutdownCaps<Mode, Shutdown> | _ChildSeedCaps<Mode, Shutdown>;
|
|
1026
|
+
/**
|
|
1027
|
+
* Resolves the user's `shutdown` value through the auto-injection rules
|
|
1028
|
+
* for `(source: "own", continuation: "continue")`. Mirror of
|
|
1029
|
+
* `src/lib/subagent/handler.ts:373-389`:
|
|
1030
|
+
*
|
|
1031
|
+
* - `pause` / `pause-until-parent-close` / `keep` / `keep-until-parent-close`
|
|
1032
|
+
* → propagate (`alreadySurvives = true`).
|
|
1033
|
+
* - everything else (undefined, "destroy", "snapshot") → injected
|
|
1034
|
+
* `"pause"` (subsequent calls) or `"pause-until-parent-close"`
|
|
1035
|
+
* (creator first call). Type-level: union both.
|
|
1036
|
+
*/
|
|
1037
|
+
type _ContinueShutdown<S> = S extends _ShutdownPauseLike | _ShutdownKeepLike ? S : "pause" | "pause-until-parent-close";
|
|
1038
|
+
/**
|
|
1039
|
+
* Resolves the user's `shutdown` value through the auto-injection rules
|
|
1040
|
+
* for `(source: "own", continuation: "fork", init: "once")`. Same shape
|
|
1041
|
+
* as `_ContinueShutdown` because both are `mustSurvive` paths.
|
|
1042
|
+
*/
|
|
1043
|
+
type _ForkOnceShutdown<S> = _ContinueShutdown<S>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Modes the child session may be invoked under for `(source: "own",
|
|
1046
|
+
* continuation: "continue")`. First call has no `baseSandboxId` (mode
|
|
1047
|
+
* "new"); subsequent calls reuse it (mode "continue"). The type takes
|
|
1048
|
+
* the union — the matrix can't tell first vs. subsequent statically.
|
|
1049
|
+
*/
|
|
1050
|
+
type _OwnContinueModes = "new" | "continue";
|
|
1051
|
+
/**
|
|
1052
|
+
* Modes the child session may be invoked under for `(source: "own",
|
|
1053
|
+
* continuation: "fork")`. Same first-vs-subsequent shape as continue.
|
|
1054
|
+
*/
|
|
1055
|
+
type _OwnForkModes = "new" | "fork";
|
|
1056
|
+
/**
|
|
1057
|
+
* Modes the child session may be invoked under for `(source: "own",
|
|
1058
|
+
* continuation: "snapshot")`. First call (no base snapshot yet) uses
|
|
1059
|
+
* "new"; subsequent calls (or `init: "once"` after the first creator
|
|
1060
|
+
* publishes a base) use "from-snapshot".
|
|
1061
|
+
*/
|
|
1062
|
+
type _OwnSnapshotModes = "new" | "from-snapshot";
|
|
1063
|
+
/**
|
|
1064
|
+
* Caps required on a subagent's `proxy` for the parent's own gated
|
|
1065
|
+
* calls. The parent only ever calls `destroySandbox` (base) and
|
|
1066
|
+
* `deleteSandboxSnapshot` (`continuation: "snapshot"` cleanup).
|
|
1067
|
+
*/
|
|
1068
|
+
type _ParentLocalCaps<C> = C extends {
|
|
1069
|
+
continuation: "snapshot";
|
|
1070
|
+
} ? "snapshot" : never;
|
|
1071
|
+
/**
|
|
1072
|
+
* **SSOT type.** The full cap union a subagent's `proxy` must expose,
|
|
1073
|
+
* derived from `(source, continuation, init, shutdown)`.
|
|
1074
|
+
*
|
|
1075
|
+
* The shape mirrors the rows of the runtime decision table in
|
|
1076
|
+
* `resolveSubagentLifecycle` (`src/lib/subagent/handler.ts`): each
|
|
1077
|
+
* branch here corresponds to exactly one runtime branch, and adding a
|
|
1078
|
+
* new runtime branch requires adding a matching branch here. The
|
|
1079
|
+
* `(adapter × continuation × shutdown × init × source)` matrix in
|
|
1080
|
+
* `src/lib/sandbox/capability-types.test.ts` enforces agreement.
|
|
1081
|
+
*/
|
|
1082
|
+
type SubagentRequiredCaps<C> = C extends "none" ? never : C extends {
|
|
1083
|
+
source: "inherit";
|
|
1084
|
+
continuation: "continue";
|
|
1085
|
+
} ? never : C extends {
|
|
1086
|
+
source: "inherit";
|
|
1087
|
+
continuation: "fork";
|
|
1088
|
+
} ? "fork" | _ChildSessionCaps<"fork", C extends {
|
|
1089
|
+
shutdown: infer S;
|
|
1090
|
+
} ? S : "destroy"> | _ParentLocalCaps<C> : C extends {
|
|
1091
|
+
source: "own";
|
|
1092
|
+
continuation: "snapshot";
|
|
1093
|
+
} ? _ChildSessionCaps<_OwnSnapshotModes, "snapshot"> | _ParentLocalCaps<C> : C extends {
|
|
1094
|
+
source: "own";
|
|
1095
|
+
continuation: "continue";
|
|
1096
|
+
} ? _ChildSessionCaps<_OwnContinueModes, _ContinueShutdown<C extends {
|
|
1097
|
+
shutdown: infer S;
|
|
1098
|
+
} ? S : undefined>> | _ParentLocalCaps<C> : C extends {
|
|
1099
|
+
source: "own";
|
|
1100
|
+
continuation: "fork";
|
|
1101
|
+
init?: infer I;
|
|
1102
|
+
} ? "fork" | _ChildSessionCaps<_OwnForkModes, I extends "once" ? _ForkOnceShutdown<C extends {
|
|
1103
|
+
shutdown: infer S;
|
|
1104
|
+
} ? S : undefined> : C extends {
|
|
1105
|
+
shutdown: infer S;
|
|
1106
|
+
} ? S extends undefined ? "destroy" : S : "destroy"> | _ParentLocalCaps<C> : never;
|
|
1107
|
+
/**
|
|
1108
|
+
* Backwards-compatible alias retained for external callers that imported
|
|
1109
|
+
* the old name. Resolves through the SSOT against a synthetic
|
|
1110
|
+
* `{ source: "own", continuation: C }` config.
|
|
1111
|
+
*
|
|
1112
|
+
* @deprecated Use `SubagentRequiredCaps<C>` against the full subagent
|
|
1113
|
+
* sandbox config — `continuation` alone misses `shutdown` and `init`,
|
|
1114
|
+
* which is why the previous mapping under-rejected `fork`+`pause` and
|
|
1115
|
+
* `continue`+auto-injected pause.
|
|
1116
|
+
*/
|
|
1117
|
+
type SubagentContinuationCaps<C extends SubagentContinuation> = C extends "snapshot" ? "snapshot" | "restore" : C extends "fork" ? "fork" : never;
|
|
1118
|
+
/** Continuation values supported when `source` is `"inherit"`. */
|
|
1119
|
+
type InheritContinuation = "continue" | "fork";
|
|
1120
|
+
/** Continuation values supported when `source` is `"own"`. */
|
|
1121
|
+
type OwnContinuation = "continue" | "fork" | "snapshot";
|
|
1122
|
+
/** Union of every continuation value across both sources. */
|
|
1123
|
+
type SubagentContinuation = InheritContinuation | OwnContinuation;
|
|
1124
|
+
/**
|
|
1125
|
+
* Caps required on a subagent's `proxy` when `source: "inherit"`,
|
|
1126
|
+
* threaded through the SSOT.
|
|
1127
|
+
*
|
|
1128
|
+
* The `inherit` source has no `init` field, and the `shutdown` field
|
|
1129
|
+
* is the user's literal (or `"destroy"` if omitted). We don't have a
|
|
1130
|
+
* way to detect "omitted" in the field type itself, so this row
|
|
1131
|
+
* resolves the user's `S | undefined` directly — `undefined` is treated
|
|
1132
|
+
* as `"destroy"` to match the runtime default in
|
|
1133
|
+
* `src/lib/subagent/handler.ts:469`.
|
|
1134
|
+
*/
|
|
1135
|
+
type _InheritCaps<C extends InheritContinuation, S> = SubagentRequiredCaps<{
|
|
1136
|
+
source: "inherit";
|
|
1137
|
+
continuation: C;
|
|
1138
|
+
shutdown: S extends undefined ? "destroy" : S;
|
|
1139
|
+
}>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Variants for `source: "inherit"`. Continuation × shutdown-presence ×
|
|
1142
|
+
* shutdown-literal all distribute, with omitted vs. specified
|
|
1143
|
+
* `shutdown` encoded as separate variants — for the same reason
|
|
1144
|
+
* `OwnVariant` does (forbid TS from matching a permissive cell when
|
|
1145
|
+
* the user omits the field).
|
|
1146
|
+
*/
|
|
1147
|
+
type InheritVariant<TOptions extends SandboxCreateOptions> = InheritContinuation extends infer C ? C extends InheritContinuation ? ({
|
|
1148
|
+
_s: undefined;
|
|
1149
|
+
shutdown?: never;
|
|
1150
|
+
} | (SubagentSandboxShutdown extends infer SL ? SL extends SubagentSandboxShutdown ? {
|
|
1151
|
+
_s: SL;
|
|
1152
|
+
shutdown: SL;
|
|
1153
|
+
} : never : never)) extends infer S ? S extends {
|
|
1154
|
+
_s: SubagentSandboxShutdown | undefined;
|
|
1155
|
+
shutdown?: SubagentSandboxShutdown;
|
|
1156
|
+
} ? Omit<S, "_s"> & {
|
|
1157
|
+
source: "inherit";
|
|
1158
|
+
continuation: C;
|
|
1159
|
+
proxy: (scope: string) => SandboxOps<TOptions, unknown, _InheritCaps<C, S["_s"]> & SandboxCapability>;
|
|
1160
|
+
} : never : never : never : never;
|
|
1161
|
+
type _OwnCaps<C extends OwnContinuation, I extends "per-call" | "once" | undefined, S> = SubagentRequiredCaps<{
|
|
1162
|
+
source: "own";
|
|
1163
|
+
continuation: C;
|
|
1164
|
+
init: I extends undefined ? "per-call" : I;
|
|
1165
|
+
shutdown: S;
|
|
1166
|
+
}>;
|
|
1167
|
+
/**
|
|
1168
|
+
* Variants for `source: "own"`. Continuation × init-presence × shutdown-
|
|
1169
|
+
* presence × shutdown-literal all distribute, so each cell gets its
|
|
1170
|
+
* own variant with a precisely-typed `proxy`.
|
|
1171
|
+
*
|
|
1172
|
+
* Critical: omitted vs. specified `init` / `shutdown` are encoded as
|
|
1173
|
+
* *separate* variants. The omitted variant uses `init?: never` /
|
|
1174
|
+
* `shutdown?: never` so the field is forbidden when the user doesn't
|
|
1175
|
+
* write one — without this, TS would infer `field?: undefined` and
|
|
1176
|
+
* happily match an unrelated permissive variant whose caps don't
|
|
1177
|
+
* cover the auto-injection.
|
|
1178
|
+
*/
|
|
1179
|
+
type OwnVariant<TOptions extends SandboxCreateOptions> = OwnContinuation extends infer C ? C extends OwnContinuation ? ({
|
|
1180
|
+
_i: undefined;
|
|
1181
|
+
init?: never;
|
|
1182
|
+
} | {
|
|
1183
|
+
_i: "per-call";
|
|
1184
|
+
init: "per-call";
|
|
1185
|
+
} | {
|
|
1186
|
+
_i: "once";
|
|
1187
|
+
init: "once";
|
|
1188
|
+
}) extends infer I ? I extends {
|
|
1189
|
+
_i: "per-call" | "once" | undefined;
|
|
1190
|
+
init?: "per-call" | "once";
|
|
1191
|
+
} ? ({
|
|
1192
|
+
_s: undefined;
|
|
1193
|
+
shutdown?: never;
|
|
1194
|
+
} | (SubagentSandboxShutdown extends infer SL ? SL extends SubagentSandboxShutdown ? {
|
|
1195
|
+
_s: SL;
|
|
1196
|
+
shutdown: SL;
|
|
1197
|
+
} : never : never)) extends infer S ? S extends {
|
|
1198
|
+
_s: SubagentSandboxShutdown | undefined;
|
|
1199
|
+
shutdown?: SubagentSandboxShutdown;
|
|
1200
|
+
} ? Omit<I, "_i"> & Omit<S, "_s"> & {
|
|
1201
|
+
source: "own";
|
|
1202
|
+
continuation: C;
|
|
1203
|
+
proxy: (scope: string) => SandboxOps<TOptions, unknown, _OwnCaps<C, I["_i"], S["_s"]> & SandboxCapability>;
|
|
1204
|
+
} : never : never : never : never : never : never;
|
|
974
1205
|
/**
|
|
975
1206
|
* Sandbox configuration for a subagent.
|
|
976
1207
|
*
|
|
@@ -988,19 +1219,20 @@ type SubagentContext = Record<string, unknown> | (() => Record<string, unknown>)
|
|
|
988
1219
|
* `scope = agentName`, so the returned proxy resolves to the same activity
|
|
989
1220
|
* prefix the child session uses. The parent uses it to destroy lingering
|
|
990
1221
|
* sandboxes and delete stored snapshots at shutdown.
|
|
1222
|
+
*
|
|
1223
|
+
* The `proxy` field's required `TCaps` is derived from
|
|
1224
|
+
* {@link SubagentRequiredCaps} — the SSOT that mirrors
|
|
1225
|
+
* `resolveSubagentLifecycle` in the handler. It folds in `shutdown` and
|
|
1226
|
+
* `init` (including the handler's auto-injected `"pause"` /
|
|
1227
|
+
* `"pause-until-parent-close"` overrides), so any `(adapter, source,
|
|
1228
|
+
* continuation, init, shutdown)` cell that can't execute at runtime
|
|
1229
|
+
* fails to typecheck at the `defineSubagent` site.
|
|
1230
|
+
*
|
|
1231
|
+
* `TOptions` defaults to {@link SandboxCreateOptions} so the wide,
|
|
1232
|
+
* un-parameterised `SubagentSandboxConfig` keeps working for callers
|
|
1233
|
+
* that don't need adapter-specific options.
|
|
991
1234
|
*/
|
|
992
|
-
type SubagentSandboxConfig = "none" |
|
|
993
|
-
source: "inherit";
|
|
994
|
-
continuation: "continue" | "fork";
|
|
995
|
-
shutdown?: SubagentSandboxShutdown;
|
|
996
|
-
proxy: (scope: string) => SandboxOps;
|
|
997
|
-
} | {
|
|
998
|
-
source: "own";
|
|
999
|
-
init?: "per-call" | "once";
|
|
1000
|
-
continuation: "continue" | "fork" | "snapshot";
|
|
1001
|
-
shutdown?: SubagentSandboxShutdown;
|
|
1002
|
-
proxy: (scope: string) => SandboxOps;
|
|
1003
|
-
};
|
|
1235
|
+
type SubagentSandboxConfig<TOptions extends SandboxCreateOptions = SandboxCreateOptions> = "none" | InheritVariant<TOptions> | OwnVariant<TOptions>;
|
|
1004
1236
|
/**
|
|
1005
1237
|
* Configuration for a subagent that can be spawned by the parent workflow.
|
|
1006
1238
|
*
|
|
@@ -1145,6 +1377,14 @@ interface SubagentSessionInput {
|
|
|
1145
1377
|
sandboxId?: string;
|
|
1146
1378
|
snapshot?: SandboxSnapshot;
|
|
1147
1379
|
threadId: string;
|
|
1380
|
+
usage: {
|
|
1381
|
+
totalInputTokens: number;
|
|
1382
|
+
totalOutputTokens: number;
|
|
1383
|
+
totalCachedWriteTokens: number;
|
|
1384
|
+
totalCachedReadTokens: number;
|
|
1385
|
+
totalReasonTokens: number;
|
|
1386
|
+
turns: number;
|
|
1387
|
+
};
|
|
1148
1388
|
}) => void;
|
|
1149
1389
|
}
|
|
1150
1390
|
|
|
@@ -1316,14 +1556,74 @@ type ScopedPrefix<TScope extends string, TAdapter extends string> = TScope exten
|
|
|
1316
1556
|
type PrefixedThreadOps<TPrefix extends string, TContent = string> = {
|
|
1317
1557
|
[K in keyof ThreadOps<TContent> as `${TPrefix}${Capitalize<K & string>}`]: ThreadOps<TContent>[K];
|
|
1318
1558
|
};
|
|
1559
|
+
/**
|
|
1560
|
+
* Caps the session's sandbox-init dispatch may invoke for a given
|
|
1561
|
+
* `(mode, shutdown)`. Mirror of `src/lib/session/session.ts:241-313`.
|
|
1562
|
+
*
|
|
1563
|
+
* The conditional branches are written non-distributively (each cap
|
|
1564
|
+
* checked against the input `M` / `S` rather than over a union) so
|
|
1565
|
+
* that the *omitted* case (defaults: M = "new", S = "destroy") flows
|
|
1566
|
+
* through to `never`, not to "I don't know, assume everything."
|
|
1567
|
+
*/
|
|
1568
|
+
type _SessionInitCaps<M, S> = (M extends "fork" ? "fork" : never) | (M extends "from-snapshot" ? "restore" : never) | (M extends "continue" ? S extends "pause-until-parent-close" ? "resume" : never : never);
|
|
1569
|
+
/**
|
|
1570
|
+
* Caps the session's exit dispatch may invoke. `"inherit"` mode keeps
|
|
1571
|
+
* `sandboxOwned = false` so exit-shutdown caps NEVER fire — mirror of
|
|
1572
|
+
* `src/lib/session/session.ts:598-615`.
|
|
1573
|
+
*/
|
|
1574
|
+
type _SessionExitCaps<M, S> = M extends "inherit" ? never : (S extends "snapshot" ? "snapshot" : never) | (S extends "pause" | "pause-until-parent-close" ? "pause" : never);
|
|
1575
|
+
/**
|
|
1576
|
+
* Cap captured on entry for `mode: "new"` + `shutdown: "snapshot"` (the
|
|
1577
|
+
* seeding-base-snapshot path). Mirror of
|
|
1578
|
+
* `src/lib/session/session.ts:316-317`.
|
|
1579
|
+
*/
|
|
1580
|
+
type _SessionSeedCaps<M, S> = M extends "new" ? S extends "snapshot" ? "snapshot" : never : never;
|
|
1581
|
+
/**
|
|
1582
|
+
* Resolves an omitted `sandbox` field to the runtime default
|
|
1583
|
+
* `{ mode: "new" }`, and an omitted `sandboxShutdown` field to the
|
|
1584
|
+
* runtime default `"destroy"`. The two `_Resolve…` helpers are the
|
|
1585
|
+
* sole bridge between "user didn't set the field" and the SSOT below
|
|
1586
|
+
* — keeping the defaults out of the conditional table itself.
|
|
1587
|
+
*/
|
|
1588
|
+
type _ResolveInit<TInit> = [TInit] extends [undefined] ? {
|
|
1589
|
+
mode: "new";
|
|
1590
|
+
} : Exclude<TInit, undefined> extends infer Defined ? undefined extends TInit ? Defined | {
|
|
1591
|
+
mode: "new";
|
|
1592
|
+
} : Defined : never;
|
|
1593
|
+
type _ResolveShutdown<TShutdown> = [TShutdown] extends [undefined] ? "destroy" : Exclude<TShutdown, undefined> extends infer Defined ? undefined extends TShutdown ? Defined | "destroy" : Defined : never;
|
|
1594
|
+
/**
|
|
1595
|
+
* Sandbox capabilities a session actually invokes on its
|
|
1596
|
+
* `sandboxOps`, derived from the literal types of the surrounding
|
|
1597
|
+
* `sandbox` and `sandboxShutdown` fields.
|
|
1598
|
+
*
|
|
1599
|
+
* `TInit` / `TShutdown` default to `undefined` so an un-parameterised
|
|
1600
|
+
* `SessionRequiredCaps` resolves to the caps the runtime *defaults*
|
|
1601
|
+
* (`{ mode: "new" }` + `"destroy"`) actually require — i.e.
|
|
1602
|
+
* `never`. This lets a narrow adapter (e.g. `proxyDaytonaSandboxOps`)
|
|
1603
|
+
* satisfy `sandboxOps?: SandboxOps<…, SessionRequiredCaps<…>>` when
|
|
1604
|
+
* the caller doesn't pin literals, matching what's runtime-safe.
|
|
1605
|
+
*
|
|
1606
|
+
* Pin literals via `as const` or by ascribing `SessionConfig<…, TInit,
|
|
1607
|
+
* TShutdown>` to tighten the requirement on a per-call basis.
|
|
1608
|
+
*/
|
|
1609
|
+
type SessionRequiredCaps<TInit extends SandboxInit | undefined = undefined, TShutdown extends SubagentSandboxShutdown | undefined = undefined> = _ResolveInit<TInit> extends infer M ? _ResolveShutdown<TShutdown> extends infer S ? M extends {
|
|
1610
|
+
mode: infer Mode;
|
|
1611
|
+
} ? S extends SubagentSandboxShutdown ? _SessionInitCaps<Mode, S> | _SessionExitCaps<Mode, S> | _SessionSeedCaps<Mode, S> : never : never : never : never;
|
|
1319
1612
|
/**
|
|
1320
1613
|
* Configuration for a Zeitlich agent session.
|
|
1321
1614
|
*
|
|
1322
1615
|
* @typeParam T - Tool map
|
|
1323
1616
|
* @typeParam M - SDK-native message type returned by the model invoker
|
|
1324
1617
|
* @typeParam TContent - SDK-native content type for human messages (defaults to `string`)
|
|
1325
|
-
|
|
1326
|
-
|
|
1618
|
+
* @typeParam TInit - Literal type of `sandbox` (a {@link SandboxInit}
|
|
1619
|
+
* variant or `undefined`). Defaults to the wide union; pin it via
|
|
1620
|
+
* `as const` on the call site to narrow the cap requirement on
|
|
1621
|
+
* `sandboxOps`.
|
|
1622
|
+
* @typeParam TShutdown - Literal type of `sandboxShutdown`. Defaults
|
|
1623
|
+
* to the wide union; pin it via `as const` on the call site to
|
|
1624
|
+
* narrow the cap requirement on `sandboxOps`.
|
|
1625
|
+
*/
|
|
1626
|
+
interface SessionConfig<T extends ToolMap, M = unknown, TContent = string, TInit extends SandboxInit | undefined = SandboxInit | undefined, TShutdown extends SubagentSandboxShutdown | undefined = SubagentSandboxShutdown | undefined> {
|
|
1327
1627
|
/** The name of the agent, should be unique within the workflows */
|
|
1328
1628
|
agentName: string;
|
|
1329
1629
|
/** Metadata for the session */
|
|
@@ -1351,8 +1651,6 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
|
|
|
1351
1651
|
* Returns SDK-native content for the initial human message.
|
|
1352
1652
|
*/
|
|
1353
1653
|
buildContextMessage: () => TContent | Promise<TContent>;
|
|
1354
|
-
/** How long to wait for input before cancelling the workflow */
|
|
1355
|
-
waitForInputTimeout?: Duration;
|
|
1356
1654
|
/**
|
|
1357
1655
|
* Thread initialization strategy (default: `{ mode: "new" }`).
|
|
1358
1656
|
*
|
|
@@ -1370,8 +1668,21 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
|
|
|
1370
1668
|
* same adapter instance.
|
|
1371
1669
|
*/
|
|
1372
1670
|
threadKey?: string;
|
|
1373
|
-
/**
|
|
1374
|
-
|
|
1671
|
+
/**
|
|
1672
|
+
* Sandbox lifecycle operations (optional — omit for agents that don't
|
|
1673
|
+
* need a sandbox).
|
|
1674
|
+
*
|
|
1675
|
+
* The `TCaps` argument is derived from {@link SessionRequiredCaps}
|
|
1676
|
+
* over the literal types of the surrounding `sandbox` and
|
|
1677
|
+
* `sandboxShutdown` fields. With the default wide
|
|
1678
|
+
* `TInit` / `TShutdown`, this resolves to the full
|
|
1679
|
+
* {@link SandboxCapability} union (current behaviour). When the
|
|
1680
|
+
* caller pins those literals via `as const`, the cap requirement
|
|
1681
|
+
* tightens so a narrow adapter (e.g. Daytona's
|
|
1682
|
+
* `SandboxOps<…, never>`) can satisfy combinations that don't need
|
|
1683
|
+
* a gated method.
|
|
1684
|
+
*/
|
|
1685
|
+
sandboxOps?: SandboxOps<SandboxCreateOptions, unknown, SessionRequiredCaps<TInit, TShutdown> & SandboxCapability>;
|
|
1375
1686
|
/**
|
|
1376
1687
|
* Sandbox initialization strategy.
|
|
1377
1688
|
*
|
|
@@ -1382,14 +1693,14 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
|
|
|
1382
1693
|
*
|
|
1383
1694
|
* When omitted and `sandboxOps` is provided, defaults to `{ mode: "new" }`.
|
|
1384
1695
|
*/
|
|
1385
|
-
sandbox?:
|
|
1696
|
+
sandbox?: TInit;
|
|
1386
1697
|
/**
|
|
1387
1698
|
* What to do with the sandbox when this session exits.
|
|
1388
1699
|
*
|
|
1389
1700
|
* Defaults to `"destroy"` when omitted.
|
|
1390
1701
|
* Has no effect when the sandbox is inherited (`sandbox.mode === "inherit"`).
|
|
1391
1702
|
*/
|
|
1392
|
-
sandboxShutdown?:
|
|
1703
|
+
sandboxShutdown?: TShutdown;
|
|
1393
1704
|
/**
|
|
1394
1705
|
* Called as soon as the sandbox is created (or resumed/forked), before the
|
|
1395
1706
|
* agent loop starts. Useful for signalling sandbox readiness to a parent.
|
|
@@ -1412,6 +1723,14 @@ interface SessionConfig<T extends ToolMap, M = unknown, TContent = string> {
|
|
|
1412
1723
|
threadId: string;
|
|
1413
1724
|
sandboxId?: string;
|
|
1414
1725
|
snapshot?: SandboxSnapshot;
|
|
1726
|
+
usage: {
|
|
1727
|
+
totalInputTokens: number;
|
|
1728
|
+
totalOutputTokens: number;
|
|
1729
|
+
totalCachedWriteTokens: number;
|
|
1730
|
+
totalCachedReadTokens: number;
|
|
1731
|
+
totalReasonTokens: number;
|
|
1732
|
+
turns: number;
|
|
1733
|
+
};
|
|
1415
1734
|
}) => void;
|
|
1416
1735
|
virtualFsOps?: VirtualFsOps;
|
|
1417
1736
|
/**
|
|
@@ -1455,4 +1774,4 @@ interface ZeitlichSession<M = unknown, HasSandbox extends boolean = boolean> {
|
|
|
1455
1774
|
}): Promise<SessionResult<M, T, HasSandbox>>;
|
|
1456
1775
|
}
|
|
1457
1776
|
|
|
1458
|
-
export { type SandboxShutdown as $, type AgentResponse as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvokerConfig as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type ModelInvoker as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type
|
|
1777
|
+
export { type SandboxShutdown as $, type AgentResponse as A, type BaseAgentState as B, type PostToolUseFailureHookContext as C, type PostToolUseFailureHookResult as D, type PostToolUseHook as E, type FileEntryMetadata as F, type PostToolUseHookContext as G, type Hooks as H, type InferToolResults as I, type JsonValue as J, type PreHumanMessageAppendHook as K, type PreHumanMessageAppendHookContext as L, type ModelInvokerConfig as M, type PreToolUseHook as N, type PreToolUseHookContext as O, type PersistedThreadState as P, type PreToolUseHookResult as Q, type RouterContext as R, type ScopedPrefix as S, type ThreadOps as T, type ProcessToolCallsContext as U, type VirtualFsContext as V, type ProcessToolCallsResult as W, type RawToolCall as X, type RewindSignal as Y, type RunAgentActivity as Z, type SandboxInit as _, type ModelInvoker as a, type SerializableToolDefinition as a0, type SessionConfig as a1, type SessionEndHook as a2, type SessionEndHookContext as a3, type SessionExitReason as a4, type SessionRequiredCaps as a5, type SessionResult as a6, type SessionStartHook as a7, type SessionStartHookContext as a8, type SubagentChildWorkflowOptions as a9, VirtualFileSystem as aA, type VirtualFileTree as aB, type VirtualFsOps as aC, type VirtualFsState as aD, type WorkflowTask as aE, type ZeitlichSession as aF, isTerminalStatus as aG, type ToolRouterOptions as aH, type SubagentConfig as aa, type SubagentContinuationCaps as ab, type SubagentDefinition as ac, type SubagentFnResult as ad, type SubagentHandlerResponse as ae, type SubagentHooks as af, type SubagentSandboxConfig as ag, type SubagentSandboxShutdown as ah, type SubagentSessionInput as ai, type SubagentWorkflow as aj, type SubagentWorkflowInput as ak, type TaskStatus as al, type ThreadInit as am, type TokenUsage as an, type ToolArgs as ao, type ToolCallResult as ap, type ToolCallResultUnion as aq, type ToolDefinition as ar, type ToolHandler as as, type ToolHooks as at, type ToolMap as au, type ToolNames as av, type ToolResult as aw, type ToolRouter as ax, type ToolRouterHooks as ay, type ToolWithHandler as az, type PrefixedThreadOps as b, type ToolHandlerResponse as c, type ActivityToolHandler as d, type ToolResultConfig as e, type RunAgentConfig as f, type SkillProvider as g, type SkillMetadata as h, type Skill as i, type FileResolver as j, type TreeMutation as k, type PrefixedVirtualFsOps as l, type AgentConfig as m, type AgentFile as n, type AgentState as o, type AgentStateManager as p, type AgentStatus as q, type AppendToolResultFn as r, type FileEntry as s, type JsonPrimitive as t, type JsonSerializable as u, type ParsedToolCall as v, type ParsedToolCallUnion as w, type PostHumanMessageAppendHook as x, type PostHumanMessageAppendHookContext as y, type PostToolUseFailureHook as z };
|