zeitlich 0.2.21 → 0.2.23
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 +303 -105
- package/dist/adapters/sandbox/daytona/index.cjs +7 -1
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +3 -1
- package/dist/adapters/sandbox/daytona/index.d.ts +3 -1
- package/dist/adapters/sandbox/daytona/index.js +7 -1
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.cjs +33 -0
- package/dist/adapters/sandbox/daytona/workflow.cjs.map +1 -0
- package/dist/adapters/sandbox/daytona/workflow.d.cts +27 -0
- package/dist/adapters/sandbox/daytona/workflow.d.ts +27 -0
- package/dist/adapters/sandbox/daytona/workflow.js +31 -0
- package/dist/adapters/sandbox/daytona/workflow.js.map +1 -0
- package/dist/adapters/sandbox/inmemory/index.cjs +18 -1
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +4 -2
- package/dist/adapters/sandbox/inmemory/index.d.ts +4 -2
- package/dist/adapters/sandbox/inmemory/index.js +18 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs +33 -0
- package/dist/adapters/sandbox/inmemory/workflow.cjs.map +1 -0
- package/dist/adapters/sandbox/inmemory/workflow.d.cts +25 -0
- package/dist/adapters/sandbox/inmemory/workflow.d.ts +25 -0
- package/dist/adapters/sandbox/inmemory/workflow.js +31 -0
- package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -0
- package/dist/adapters/sandbox/virtual/index.cjs +36 -9
- package/dist/adapters/sandbox/virtual/index.cjs.map +1 -1
- package/dist/adapters/sandbox/virtual/index.d.cts +8 -5
- package/dist/adapters/sandbox/virtual/index.d.ts +8 -5
- package/dist/adapters/sandbox/virtual/index.js +36 -9
- package/dist/adapters/sandbox/virtual/index.js.map +1 -1
- package/dist/adapters/sandbox/virtual/workflow.cjs +33 -0
- package/dist/adapters/sandbox/virtual/workflow.cjs.map +1 -0
- package/dist/adapters/sandbox/virtual/workflow.d.cts +27 -0
- package/dist/adapters/sandbox/virtual/workflow.d.ts +27 -0
- package/dist/adapters/sandbox/virtual/workflow.js +31 -0
- package/dist/adapters/sandbox/virtual/workflow.js.map +1 -0
- package/dist/adapters/thread/google-genai/index.cjs +9 -1
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +31 -19
- package/dist/adapters/thread/google-genai/index.d.ts +31 -19
- package/dist/adapters/thread/google-genai/index.js +9 -1
- package/dist/adapters/thread/google-genai/index.js.map +1 -1
- package/dist/adapters/thread/google-genai/workflow.cjs +33 -0
- package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -0
- package/dist/adapters/thread/google-genai/workflow.d.cts +32 -0
- package/dist/adapters/thread/google-genai/workflow.d.ts +32 -0
- package/dist/adapters/thread/google-genai/workflow.js +31 -0
- package/dist/adapters/thread/google-genai/workflow.js.map +1 -0
- package/dist/adapters/thread/langchain/index.cjs +9 -1
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +27 -16
- package/dist/adapters/thread/langchain/index.d.ts +27 -16
- package/dist/adapters/thread/langchain/index.js +9 -1
- package/dist/adapters/thread/langchain/index.js.map +1 -1
- package/dist/adapters/thread/langchain/workflow.cjs +33 -0
- package/dist/adapters/thread/langchain/workflow.cjs.map +1 -0
- package/dist/adapters/thread/langchain/workflow.d.cts +32 -0
- package/dist/adapters/thread/langchain/workflow.d.ts +32 -0
- package/dist/adapters/thread/langchain/workflow.js +31 -0
- package/dist/adapters/thread/langchain/workflow.js.map +1 -0
- package/dist/index.cjs +282 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -16
- package/dist/index.d.ts +38 -16
- package/dist/index.js +281 -87
- package/dist/index.js.map +1 -1
- package/dist/queries-DModcWRy.d.cts +44 -0
- package/dist/queries-byD0jr1Y.d.ts +44 -0
- package/dist/{types-BkAYmc96.d.ts → types-B50pBPEV.d.ts} +190 -38
- package/dist/{types-YbL7JpEA.d.cts → types-Bll19FZJ.d.cts} +7 -0
- package/dist/{types-YbL7JpEA.d.ts → types-Bll19FZJ.d.ts} +7 -0
- package/dist/{queries-6Avfh74U.d.ts → types-BuXdFhaZ.d.cts} +7 -48
- package/dist/{types-BMRzfELQ.d.cts → types-ChAMwU3q.d.cts} +17 -1
- package/dist/{types-BMRzfELQ.d.ts → types-ChAMwU3q.d.ts} +17 -1
- package/dist/{types-CES_30qx.d.cts → types-DQW8l7pY.d.cts} +190 -38
- package/dist/{queries-CHa2iv_I.d.cts → types-GZ76HZSj.d.ts} +7 -48
- package/dist/workflow.cjs +244 -86
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +54 -65
- package/dist/workflow.d.ts +54 -65
- package/dist/workflow.js +243 -83
- package/dist/workflow.js.map +1 -1
- package/package.json +54 -2
- package/src/adapters/sandbox/daytona/filesystem.ts +1 -1
- package/src/adapters/sandbox/daytona/index.ts +8 -0
- package/src/adapters/sandbox/daytona/proxy.ts +56 -0
- package/src/adapters/sandbox/e2b/filesystem.ts +147 -0
- package/src/adapters/sandbox/e2b/index.ts +164 -0
- package/src/adapters/sandbox/e2b/types.ts +23 -0
- package/src/adapters/sandbox/inmemory/index.ts +27 -3
- package/src/adapters/sandbox/inmemory/proxy.ts +53 -0
- package/src/adapters/sandbox/virtual/filesystem.ts +41 -17
- package/src/adapters/sandbox/virtual/provider.ts +9 -1
- package/src/adapters/sandbox/virtual/proxy.ts +53 -0
- package/src/adapters/sandbox/virtual/types.ts +9 -4
- package/src/adapters/thread/google-genai/activities.ts +51 -17
- package/src/adapters/thread/google-genai/index.ts +1 -0
- package/src/adapters/thread/google-genai/proxy.ts +61 -0
- package/src/adapters/thread/langchain/activities.ts +47 -14
- package/src/adapters/thread/langchain/index.ts +1 -0
- package/src/adapters/thread/langchain/proxy.ts +61 -0
- package/src/lib/lifecycle.ts +57 -0
- package/src/lib/sandbox/manager.ts +52 -6
- package/src/lib/sandbox/sandbox.test.ts +12 -11
- package/src/lib/sandbox/types.ts +31 -4
- package/src/lib/session/index.ts +4 -5
- package/src/lib/session/session-edge-cases.integration.test.ts +491 -66
- package/src/lib/session/session.integration.test.ts +92 -80
- package/src/lib/session/session.ts +108 -96
- package/src/lib/session/types.ts +87 -17
- package/src/lib/subagent/define.ts +6 -5
- package/src/lib/subagent/handler.ts +148 -16
- package/src/lib/subagent/index.ts +4 -0
- package/src/lib/subagent/register.ts +10 -3
- package/src/lib/subagent/signals.ts +8 -0
- package/src/lib/subagent/subagent.integration.test.ts +893 -128
- package/src/lib/subagent/tool.ts +2 -2
- package/src/lib/subagent/types.ts +84 -21
- package/src/lib/subagent/workflow.ts +83 -12
- package/src/lib/tool-router/router-edge-cases.integration.test.ts +4 -1
- package/src/lib/tool-router/router.integration.test.ts +141 -5
- package/src/lib/tool-router/router.ts +13 -3
- package/src/lib/tool-router/types.ts +7 -0
- package/src/lib/workflow.test.ts +104 -27
- package/src/lib/workflow.ts +37 -19
- package/src/tools/bash/bash.test.ts +16 -7
- package/src/workflow.ts +11 -14
- package/tsup.config.ts +6 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Duration } from '@temporalio/common';
|
|
2
|
-
import { a as ToolMap, b as ToolRouterHooks, M as MessageContent, S as SessionExitReason, c as ToolHandlerResponse, P as PreToolUseHookResult, d as PostToolUseFailureHookResult, e as RawToolCall, f as TokenUsage, B as BaseAgentState, g as RunAgentConfig, h as AgentStatus, W as WorkflowTask, i as ToolDefinition, j as ToolResultConfig, k as ToolCallResultUnion, I as InferToolResults } from './types-
|
|
2
|
+
import { a as ToolMap, b as ToolRouterHooks, M as MessageContent, S as SessionExitReason, c as ToolHandlerResponse, P as PreToolUseHookResult, d as PostToolUseFailureHookResult, e as RawToolCall, f as TokenUsage, B as BaseAgentState, g as RunAgentConfig, h as AgentStatus, W as WorkflowTask, i as ToolDefinition, j as ToolResultConfig, k as ToolCallResultUnion, I as InferToolResults } from './types-Bll19FZJ.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { g as SandboxOps } from './types-
|
|
4
|
+
import { g as SandboxOps } from './types-ChAMwU3q.cjs';
|
|
5
5
|
import { QueryDefinition, ActivityInterfaceFor } from '@temporalio/workflow';
|
|
6
6
|
import { UpdateDefinition } from '@temporalio/common/lib/interfaces';
|
|
7
7
|
|
|
@@ -69,19 +69,80 @@ interface Hooks<T extends ToolMap, TResult = unknown> extends ToolRouterHooks<T,
|
|
|
69
69
|
onSessionEnd?: SessionEndHook;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Thread initialization strategy.
|
|
74
|
+
*
|
|
75
|
+
* - `"new"` — start a fresh thread (optionally specify its ID).
|
|
76
|
+
* - `"continue"` — append directly to an existing thread in-place.
|
|
77
|
+
* - `"fork"` — copy all messages from an existing thread into a new one and
|
|
78
|
+
* continue there.
|
|
79
|
+
*/
|
|
80
|
+
type ThreadInit = {
|
|
81
|
+
mode: "new";
|
|
82
|
+
threadId?: string;
|
|
83
|
+
} | {
|
|
84
|
+
mode: "continue";
|
|
85
|
+
threadId: string;
|
|
86
|
+
} | {
|
|
87
|
+
mode: "fork";
|
|
88
|
+
threadId: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Sandbox initialization strategy.
|
|
92
|
+
*
|
|
93
|
+
* - `"new"` — create a fresh sandbox.
|
|
94
|
+
* - `"continue"` — resume a previously-paused sandbox (this session takes
|
|
95
|
+
* ownership and the shutdown policy applies on exit).
|
|
96
|
+
* - `"fork"` — fork from an existing (or paused) sandbox; a new sandbox is
|
|
97
|
+
* created and owned by this session.
|
|
98
|
+
* - `"inherit"` — use a sandbox owned by someone else (e.g. a parent agent).
|
|
99
|
+
* The session will **not** manage its lifecycle on exit.
|
|
100
|
+
*/
|
|
101
|
+
type SandboxInit = {
|
|
102
|
+
mode: "new";
|
|
103
|
+
} | {
|
|
104
|
+
mode: "continue";
|
|
105
|
+
sandboxId: string;
|
|
106
|
+
} | {
|
|
107
|
+
mode: "fork";
|
|
108
|
+
sandboxId: string;
|
|
109
|
+
} | {
|
|
110
|
+
mode: "inherit";
|
|
111
|
+
sandboxId: string;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* What to do with the sandbox when the session exits.
|
|
115
|
+
*
|
|
116
|
+
* - `"destroy"` — tear down the sandbox entirely.
|
|
117
|
+
* - `"pause"` — pause the sandbox so it can be resumed later.
|
|
118
|
+
* - `"keep"` — leave the sandbox running (no-op on exit).
|
|
119
|
+
*/
|
|
120
|
+
type SandboxShutdown = "destroy" | "pause" | "keep";
|
|
121
|
+
/**
|
|
122
|
+
* Extended shutdown options available to subagent workflows.
|
|
123
|
+
*
|
|
124
|
+
* Includes all base {@link SandboxShutdown} values plus:
|
|
125
|
+
* - `"pause-until-parent-close"` — pause the sandbox on exit, then wait for
|
|
126
|
+
* the parent workflow to signal when to destroy it.
|
|
127
|
+
*/
|
|
128
|
+
type SubagentSandboxShutdown = SandboxShutdown | "pause-until-parent-close";
|
|
129
|
+
|
|
72
130
|
/** ToolHandlerResponse with threadId required (subagents must always surface their thread) */
|
|
73
131
|
type SubagentHandlerResponse<TResult = null> = ToolHandlerResponse<TResult> & {
|
|
74
132
|
threadId: string;
|
|
133
|
+
sandboxId?: string;
|
|
75
134
|
};
|
|
76
135
|
/**
|
|
77
136
|
* Raw workflow input fields passed from parent to child workflow.
|
|
78
137
|
* `defineSubagentWorkflow` maps this into `SubagentSessionInput`.
|
|
79
138
|
*/
|
|
80
139
|
interface SubagentWorkflowInput {
|
|
81
|
-
/** Thread
|
|
82
|
-
|
|
83
|
-
/** Sandbox
|
|
84
|
-
|
|
140
|
+
/** Thread initialization strategy forwarded from the parent */
|
|
141
|
+
thread?: ThreadInit;
|
|
142
|
+
/** Sandbox initialization strategy forwarded from the parent */
|
|
143
|
+
sandbox?: SandboxInit;
|
|
144
|
+
/** Sandbox shutdown override from the parent (takes precedence over workflow default) */
|
|
145
|
+
sandboxShutdown?: SubagentSandboxShutdown;
|
|
85
146
|
}
|
|
86
147
|
type SubagentWorkflow<TResult extends z.ZodType = z.ZodType> = (prompt: string, workflowInput: SubagentWorkflowInput, context?: Record<string, unknown>) => Promise<SubagentHandlerResponse<z.infer<TResult> | null>>;
|
|
87
148
|
/**
|
|
@@ -93,6 +154,23 @@ type SubagentDefinition<TResult extends z.ZodType = z.ZodType, TContext extends
|
|
|
93
154
|
readonly description: string;
|
|
94
155
|
readonly resultSchema?: TResult;
|
|
95
156
|
};
|
|
157
|
+
/** Context value or factory — resolved at invocation time when a function is provided */
|
|
158
|
+
type SubagentContext = Record<string, unknown> | (() => Record<string, unknown>);
|
|
159
|
+
/**
|
|
160
|
+
* Sandbox configuration for a subagent.
|
|
161
|
+
*
|
|
162
|
+
* String shorthands:
|
|
163
|
+
* - `"none"` — no sandbox (default).
|
|
164
|
+
* - `"inherit"` — reuse the parent's sandbox (shared filesystem/exec).
|
|
165
|
+
* - `"own"` — the child creates and owns its own sandbox (shutdown defaults to `"destroy"`).
|
|
166
|
+
*
|
|
167
|
+
* Object form (only for `source: "own"`):
|
|
168
|
+
* - `{ source: "own", shutdown?: SubagentSandboxShutdown }` — own sandbox with explicit shutdown policy.
|
|
169
|
+
*/
|
|
170
|
+
type SubagentSandboxConfig = "none" | "inherit" | "own" | {
|
|
171
|
+
source: "own";
|
|
172
|
+
shutdown?: SubagentSandboxShutdown;
|
|
173
|
+
};
|
|
96
174
|
/**
|
|
97
175
|
* Configuration for a subagent that can be spawned by the parent workflow.
|
|
98
176
|
*
|
|
@@ -106,23 +184,34 @@ interface SubagentConfig<TResult extends z.ZodType = z.ZodType> {
|
|
|
106
184
|
/** Whether this subagent is available (default: true). Disabled subagents are excluded from the Subagent tool. */
|
|
107
185
|
enabled?: boolean | (() => boolean);
|
|
108
186
|
/** Temporal workflow function or type name (used with executeChild) */
|
|
109
|
-
workflow:
|
|
187
|
+
workflow: SubagentWorkflow<TResult>;
|
|
110
188
|
/** Optional task queue - defaults to parent's queue if not specified */
|
|
111
189
|
taskQueue?: string;
|
|
112
190
|
/** Optional Zod schema to validate the child workflow's result. If omitted, result is passed through as-is. */
|
|
113
191
|
resultSchema?: TResult;
|
|
114
|
-
/** Optional
|
|
115
|
-
context?:
|
|
116
|
-
/** Allow the parent agent to pass a threadId for this subagent to continue (default: false) */
|
|
117
|
-
allowThreadContinuation?: boolean;
|
|
192
|
+
/** Optional context passed to the subagent — a static object or a function evaluated at invocation time */
|
|
193
|
+
context?: SubagentContext;
|
|
118
194
|
/** Per-subagent lifecycle hooks */
|
|
119
195
|
hooks?: SubagentHooks;
|
|
196
|
+
/**
|
|
197
|
+
* Thread mode for this subagent.
|
|
198
|
+
*
|
|
199
|
+
* - `"new"` (default) — always start a fresh thread.
|
|
200
|
+
* - `"fork"` — the parent can pass a `threadId`; messages are copied into
|
|
201
|
+
* a new thread and the subagent continues there.
|
|
202
|
+
* - `"continue"` — the parent can pass a `threadId`; the subagent appends
|
|
203
|
+
* directly to the existing thread in-place.
|
|
204
|
+
*/
|
|
205
|
+
thread?: "new" | "fork" | "continue";
|
|
120
206
|
/**
|
|
121
207
|
* Sandbox strategy for this subagent.
|
|
122
|
-
*
|
|
123
|
-
*
|
|
208
|
+
*
|
|
209
|
+
* String shorthands: `"none"` (default) | `"inherit"` | `"own"`.
|
|
210
|
+
* Object form: `{ source: "own", shutdown?: SubagentSandboxShutdown }`.
|
|
211
|
+
*
|
|
212
|
+
* @see {@link SubagentSandboxConfig}
|
|
124
213
|
*/
|
|
125
|
-
sandbox?:
|
|
214
|
+
sandbox?: SubagentSandboxConfig;
|
|
126
215
|
}
|
|
127
216
|
/**
|
|
128
217
|
* Per-subagent lifecycle hooks - defined on a SubagentConfig.
|
|
@@ -142,6 +231,8 @@ interface SubagentHooks<TArgs = unknown, TResult = unknown> {
|
|
|
142
231
|
threadId: string;
|
|
143
232
|
turn: number;
|
|
144
233
|
durationMs: number;
|
|
234
|
+
/** Unvalidated metadata from the child workflow (e.g. infrastructure state) */
|
|
235
|
+
metadata?: Record<string, unknown>;
|
|
145
236
|
}) => void | Promise<void>;
|
|
146
237
|
/** Called when this subagent execution fails */
|
|
147
238
|
onExecutionFailure?: (ctx: {
|
|
@@ -151,18 +242,31 @@ interface SubagentHooks<TArgs = unknown, TResult = unknown> {
|
|
|
151
242
|
turn: number;
|
|
152
243
|
}) => PostToolUseFailureHookResult | Promise<PostToolUseFailureHookResult>;
|
|
153
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Extended response from the subagent `fn` — includes optional cleanup callbacks
|
|
247
|
+
* stripped before signaling the parent.
|
|
248
|
+
*
|
|
249
|
+
* When `TSandboxShutdown` is `"pause-until-parent-close"`, both `destroySandbox`
|
|
250
|
+
* and `sandboxId` become required so the parent can coordinate cleanup.
|
|
251
|
+
*/
|
|
252
|
+
type SubagentFnResult<TResult = null, TSandboxShutdown extends SubagentSandboxShutdown = SubagentSandboxShutdown> = SubagentHandlerResponse<TResult> & (TSandboxShutdown extends "pause-until-parent-close" ? {
|
|
253
|
+
destroySandbox: () => Promise<void>;
|
|
254
|
+
sandboxId: string;
|
|
255
|
+
} : {
|
|
256
|
+
destroySandbox?: () => Promise<void>;
|
|
257
|
+
});
|
|
154
258
|
/**
|
|
155
259
|
* Session config fields passed from parent to child workflow.
|
|
156
260
|
*/
|
|
157
261
|
interface SubagentSessionInput {
|
|
158
262
|
/** Agent name — spread directly into `createSession` */
|
|
159
263
|
agentName: string;
|
|
160
|
-
/** Thread
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
/** Sandbox
|
|
165
|
-
|
|
264
|
+
/** Thread initialization strategy */
|
|
265
|
+
thread?: ThreadInit;
|
|
266
|
+
/** Sandbox initialization strategy */
|
|
267
|
+
sandbox?: SandboxInit;
|
|
268
|
+
/** Sandbox shutdown policy (default: "destroy") */
|
|
269
|
+
sandboxShutdown?: SubagentSandboxShutdown;
|
|
166
270
|
}
|
|
167
271
|
|
|
168
272
|
/**
|
|
@@ -350,14 +454,38 @@ interface ThreadOps {
|
|
|
350
454
|
/** Copy all messages from sourceThreadId into a new thread at targetThreadId */
|
|
351
455
|
forkThread(sourceThreadId: string, targetThreadId: string): Promise<void>;
|
|
352
456
|
}
|
|
457
|
+
/**
|
|
458
|
+
* Composes an adapter prefix + workflow scope for activity naming.
|
|
459
|
+
*
|
|
460
|
+
* The adapter prefix stays first (camelCase); the workflow scope is
|
|
461
|
+
* capitalised and appended. When `TScope` is empty the adapter prefix
|
|
462
|
+
* is used as-is.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* ScopedPrefix<"codingAgent", "googleGenAI"> // "googleGenAICodingAgent"
|
|
467
|
+
* ScopedPrefix<"", "googleGenAI"> // "googleGenAI"
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
type ScopedPrefix<TScope extends string, TAdapter extends string> = TScope extends "" ? TAdapter : `${TAdapter}${Capitalize<TScope>}`;
|
|
471
|
+
/**
|
|
472
|
+
* Maps generic {@link ThreadOps} method names to adapter-prefixed names.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```typescript
|
|
476
|
+
* type GoogleOps = PrefixedThreadOps<"googleGenAI">;
|
|
477
|
+
* // → { googleGenAIInitializeThread, googleGenAIAppendHumanMessage, … }
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
type PrefixedThreadOps<TPrefix extends string> = {
|
|
481
|
+
[K in keyof ThreadOps as `${TPrefix}${Capitalize<K & string>}`]: ThreadOps[K];
|
|
482
|
+
};
|
|
353
483
|
/**
|
|
354
484
|
* Configuration for a Zeitlich agent session
|
|
355
485
|
*/
|
|
356
486
|
interface SessionConfig<T extends ToolMap, M = unknown> {
|
|
357
487
|
/** The name of the agent, should be unique within the workflows */
|
|
358
488
|
agentName: string;
|
|
359
|
-
/** The thread ID to use for the session (defaults to a short generated ID) */
|
|
360
|
-
threadId?: string;
|
|
361
489
|
/** Metadata for the session */
|
|
362
490
|
metadata?: Record<string, unknown>;
|
|
363
491
|
/** Whether to append the system prompt as message to the thread */
|
|
@@ -367,7 +495,7 @@ interface SessionConfig<T extends ToolMap, M = unknown> {
|
|
|
367
495
|
/** Workflow-specific runAgent activity (with tools pre-bound) */
|
|
368
496
|
runAgent: RunAgentActivity<M>;
|
|
369
497
|
/** Thread operations (initialize, append messages, parse tool calls) */
|
|
370
|
-
threadOps
|
|
498
|
+
threadOps: ActivityInterfaceFor<ThreadOps>;
|
|
371
499
|
/** Tool router for processing tool calls (optional if agent has no tools) */
|
|
372
500
|
tools?: T;
|
|
373
501
|
/** Subagent configurations */
|
|
@@ -383,28 +511,52 @@ interface SessionConfig<T extends ToolMap, M = unknown> {
|
|
|
383
511
|
* Returns MessageContent array for the initial HumanMessage.
|
|
384
512
|
*/
|
|
385
513
|
buildContextMessage: () => MessageContent | Promise<MessageContent>;
|
|
386
|
-
/** When true, skip thread initialization and system prompt — append only the new human message to the existing thread. */
|
|
387
|
-
continueThread?: boolean;
|
|
388
514
|
/** How long to wait for input before cancelling the workflow */
|
|
389
515
|
waitForInputTimeout?: Duration;
|
|
516
|
+
/**
|
|
517
|
+
* Thread initialization strategy (default: `{ mode: "new" }`).
|
|
518
|
+
*
|
|
519
|
+
* - `{ mode: "new" }` — start a fresh thread.
|
|
520
|
+
* - `{ mode: "new", threadId: "..." }` — start a fresh thread with a specific ID.
|
|
521
|
+
* - `{ mode: "continue", threadId: "..." }` — append to an existing thread in-place.
|
|
522
|
+
* - `{ mode: "fork", threadId: "..." }` — fork an existing thread and continue in the copy.
|
|
523
|
+
*/
|
|
524
|
+
thread?: ThreadInit;
|
|
390
525
|
/** Sandbox lifecycle operations (optional — omit for agents that don't need a sandbox) */
|
|
391
|
-
|
|
526
|
+
sandboxOps?: SandboxOps;
|
|
392
527
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
*
|
|
528
|
+
* Sandbox initialization strategy.
|
|
529
|
+
*
|
|
530
|
+
* - `{ mode: "new" }` — create a fresh sandbox.
|
|
531
|
+
* - `{ mode: "continue", sandboxId: "..." }` — resume a paused sandbox (session owns it).
|
|
532
|
+
* - `{ mode: "fork", sandboxId: "..." }` — fork from an existing sandbox.
|
|
533
|
+
* - `{ mode: "inherit", sandboxId: "..." }` — use a parent's sandbox without ownership.
|
|
534
|
+
*
|
|
535
|
+
* When omitted and `sandboxOps` is provided, defaults to `{ mode: "new" }`.
|
|
396
536
|
*/
|
|
397
|
-
|
|
537
|
+
sandbox?: SandboxInit;
|
|
538
|
+
/**
|
|
539
|
+
* What to do with the sandbox when this session exits.
|
|
540
|
+
*
|
|
541
|
+
* Defaults to `"destroy"` when omitted.
|
|
542
|
+
* Has no effect when the sandbox is inherited (`sandbox.mode === "inherit"`).
|
|
543
|
+
*/
|
|
544
|
+
sandboxShutdown?: SubagentSandboxShutdown;
|
|
398
545
|
}
|
|
399
|
-
|
|
546
|
+
type SessionResult<M, TState extends JsonSerializable<TState>, HasSandbox extends boolean = boolean> = {
|
|
547
|
+
threadId: string;
|
|
548
|
+
finalMessage: M | null;
|
|
549
|
+
exitReason: SessionExitReason;
|
|
550
|
+
usage: ReturnType<AgentStateManager<TState>["getTotalUsage"]>;
|
|
551
|
+
} & (HasSandbox extends true ? {
|
|
552
|
+
sandboxId: string;
|
|
553
|
+
} : {
|
|
554
|
+
sandboxId?: undefined;
|
|
555
|
+
});
|
|
556
|
+
interface ZeitlichSession<M = unknown, HasSandbox extends boolean = boolean> {
|
|
400
557
|
runSession<T extends JsonSerializable<T>>(args: {
|
|
401
558
|
stateManager: AgentStateManager<T>;
|
|
402
|
-
}): Promise<
|
|
403
|
-
threadId: string;
|
|
404
|
-
finalMessage: M | null;
|
|
405
|
-
exitReason: SessionExitReason;
|
|
406
|
-
usage: ReturnType<AgentStateManager<T>["getTotalUsage"]>;
|
|
407
|
-
}>;
|
|
559
|
+
}): Promise<SessionResult<M, T, HasSandbox>>;
|
|
408
560
|
}
|
|
409
561
|
|
|
410
|
-
export type { AgentResponse as A, Hooks as H, JsonPrimitive as J, ModelInvoker as M,
|
|
562
|
+
export type { AgentResponse as A, SubagentSandboxShutdown as B, SubagentSessionInput as C, SubagentWorkflow as D, SubagentWorkflowInput as E, ThreadInit as F, Hooks as H, JsonPrimitive as J, ModelInvoker as M, PrefixedThreadOps as P, RunAgentActivity as R, ScopedPrefix as S, ThreadOps as T, ZeitlichSession as Z, ModelInvokerConfig as a, SkillProvider as b, SkillMetadata as c, Skill as d, AgentState as e, AgentStateManager as f, JsonSerializable as g, JsonValue as h, PostHumanMessageAppendHook as i, PostHumanMessageAppendHookContext as j, PreHumanMessageAppendHook as k, PreHumanMessageAppendHookContext as l, SandboxInit as m, SandboxShutdown as n, SessionConfig as o, SessionEndHook as p, SessionEndHookContext as q, SessionResult as r, SessionStartHook as s, SessionStartHookContext as t, SubagentConfig as u, SubagentDefinition as v, SubagentFnResult as w, SubagentHandlerResponse as x, SubagentHooks as y, SubagentSandboxConfig as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as SandboxFileSystem, F as FileStat, D as DirentEntry, S as Sandbox, d as SandboxCreateOptions } from './types-
|
|
2
|
-
import { R as RouterContext } from './types-
|
|
1
|
+
import { a as SandboxFileSystem, F as FileStat, D as DirentEntry, S as Sandbox, d as SandboxCreateOptions } from './types-ChAMwU3q.js';
|
|
2
|
+
import { R as RouterContext } from './types-Bll19FZJ.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Ephemeral {@link SandboxFileSystem} backed by a {@link FileResolver}.
|
|
@@ -82,11 +82,11 @@ type TreeMutation<TMeta = FileEntryMetadata> = {
|
|
|
82
82
|
*/
|
|
83
83
|
interface FileResolver<TCtx = unknown, TMeta = FileEntryMetadata> {
|
|
84
84
|
resolveEntries(ctx: TCtx): Promise<FileEntry<TMeta>[]>;
|
|
85
|
-
readFile(id: string, ctx: TCtx): Promise<string>;
|
|
86
|
-
readFileBuffer(id: string, ctx: TCtx): Promise<Uint8Array>;
|
|
87
|
-
writeFile(id: string, content: string | Uint8Array, ctx: TCtx): Promise<void>;
|
|
85
|
+
readFile(id: string, ctx: TCtx, metadata: TMeta): Promise<string>;
|
|
86
|
+
readFileBuffer(id: string, ctx: TCtx, metadata: TMeta): Promise<Uint8Array>;
|
|
87
|
+
writeFile(id: string, content: string | Uint8Array, ctx: TCtx, metadata: TMeta): Promise<void>;
|
|
88
88
|
createFile(path: string, content: string | Uint8Array, ctx: TCtx): Promise<FileEntry<TMeta>>;
|
|
89
|
-
deleteFile(id: string, ctx: TCtx): Promise<void>;
|
|
89
|
+
deleteFile(id: string, ctx: TCtx, metadata: TMeta): Promise<void>;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* Options for {@link VirtualSandboxProvider.create}.
|
|
@@ -122,45 +122,4 @@ interface VirtualSandboxContext<TCtx = unknown, TMeta = FileEntryMetadata> exten
|
|
|
122
122
|
sandbox: VirtualSandbox<TCtx, TMeta>;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
* Structural constraint: accepts any `AgentStateManager<T>` whose custom
|
|
127
|
-
* state includes `fileTree: FileEntry<TMeta>[]`.
|
|
128
|
-
*/
|
|
129
|
-
interface FileTreeAccessor<TMeta> {
|
|
130
|
-
get(key: "fileTree"): FileEntry<TMeta>[];
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Check whether any file in the tree has a `metadata.mimeType` that matches
|
|
134
|
-
* the given pattern.
|
|
135
|
-
*
|
|
136
|
-
* Patterns:
|
|
137
|
-
* - Exact: `"application/pdf"`
|
|
138
|
-
* - Wildcard type: `"image/*"`
|
|
139
|
-
*
|
|
140
|
-
* Useful for conditionally enabling tools:
|
|
141
|
-
*
|
|
142
|
-
* ```ts
|
|
143
|
-
* { enabled: hasFileWithMimeType(stateManager, "image/*") }
|
|
144
|
-
* { enabled: hasFileWithMimeType(stateManager, ["image/*", "application/pdf"]) }
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
declare function hasFileWithMimeType<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string | string[]): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Return all entries whose `metadata.mimeType` matches the given pattern.
|
|
150
|
-
*/
|
|
151
|
-
declare function filesWithMimeType<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string): FileEntry<TMeta>[];
|
|
152
|
-
/**
|
|
153
|
-
* Check whether the tree contains a directory whose name matches the given
|
|
154
|
-
* pattern. Directories are inferred from file paths.
|
|
155
|
-
*
|
|
156
|
-
* Patterns:
|
|
157
|
-
* - Exact: `"src"`
|
|
158
|
-
* - Glob with `*` wildcard: `"test*"`, `"*.generated"`
|
|
159
|
-
*
|
|
160
|
-
* ```ts
|
|
161
|
-
* { enabled: hasDirectory(stateManager, "test*") }
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
declare function hasDirectory<TMeta>(stateManager: FileTreeAccessor<TMeta>, pattern: string): boolean;
|
|
165
|
-
|
|
166
|
-
export { type FileEntryMetadata as F, type TreeMutation as T, type VirtualSandboxCreateOptions as V, type FileResolver as a, type VirtualSandboxContext as b, type FileEntry as c, type VirtualSandbox as d, type FileTreeAccessor as e, type VirtualFileTree as f, VirtualSandboxFileSystem as g, type VirtualSandboxState as h, filesWithMimeType as i, hasDirectory as j, hasFileWithMimeType as k };
|
|
125
|
+
export { type FileEntry as F, type TreeMutation as T, type VirtualSandboxCreateOptions as V, type FileEntryMetadata as a, type FileResolver as b, type VirtualSandboxContext as c, type VirtualSandbox as d, type VirtualFileTree as e, VirtualSandboxFileSystem as f, type VirtualSandboxState as g };
|