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
package/dist/workflow.d.cts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, g as RunAgentConfig, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, F as ToolHooks, T as ToolMessageContent, H as ToolResult, j as ToolResultConfig, b as ToolRouterHooks, L as isTerminalStatus } from './types-YbL7JpEA.cjs';
|
|
1
|
+
import { o as SessionConfig, Z as ZeitlichSession, n as SandboxShutdown, F as ThreadInit, m as SandboxInit, g as JsonSerializable, f as AgentStateManager, v as SubagentDefinition, y as SubagentHooks, z as SubagentSandboxConfig, u as SubagentConfig, B as SubagentSandboxShutdown, C as SubagentSessionInput, w as SubagentFnResult, c as SkillMetadata, d as Skill } from './types-DQW8l7pY.cjs';
|
|
2
|
+
export { A as AgentResponse, e as AgentState, H as Hooks, J as JsonPrimitive, h as JsonValue, M as ModelInvoker, a as ModelInvokerConfig, i as PostHumanMessageAppendHook, j as PostHumanMessageAppendHookContext, k as PreHumanMessageAppendHook, l as PreHumanMessageAppendHookContext, P as PrefixedThreadOps, R as RunAgentActivity, S as ScopedPrefix, p as SessionEndHook, q as SessionEndHookContext, r as SessionResult, s as SessionStartHook, t as SessionStartHookContext, b as SkillProvider, x as SubagentHandlerResponse, D as SubagentWorkflow, E as SubagentWorkflowInput, T as ThreadOps } from './types-DQW8l7pY.cjs';
|
|
3
|
+
import { g as SandboxOps } from './types-ChAMwU3q.cjs';
|
|
4
|
+
export { h as ExecOptions, E as ExecResult, P as PrefixedSandboxOps, S as Sandbox, c as SandboxCapabilities, d as SandboxCreateOptions, e as SandboxCreateResult, D as SandboxDirentEntry, F as SandboxFileStat, a as SandboxFileSystem, i as SandboxNotFoundError, j as SandboxNotSupportedError, b as SandboxProvider, f as SandboxSnapshot } from './types-ChAMwU3q.cjs';
|
|
5
|
+
import { a as ToolMap, B as BaseAgentState, N as ToolRouterOptions, J as ToolRouter, R as RouterContext, K as ToolWithHandler, p as ParsedToolCallUnion, G as ToolNames, c as ToolHandlerResponse, E as ToolHandler, W as WorkflowTask, A as ActivityToolHandler } from './types-Bll19FZJ.cjs';
|
|
6
|
+
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, g as RunAgentConfig, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, F as ToolHooks, T as ToolMessageContent, H as ToolResult, j as ToolResultConfig, b as ToolRouterHooks, L as isTerminalStatus } from './types-Bll19FZJ.cjs';
|
|
8
7
|
import z$1, { z } from 'zod';
|
|
9
|
-
import {
|
|
10
|
-
export {
|
|
8
|
+
import { a as FileEntryMetadata, e as VirtualFileTree, T as TreeMutation, F as FileEntry } from './types-BuXdFhaZ.cjs';
|
|
9
|
+
export { b as FileResolver, g as VirtualSandboxState } from './types-BuXdFhaZ.cjs';
|
|
10
|
+
export { f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from './queries-DModcWRy.cjs';
|
|
11
11
|
import '@temporalio/common';
|
|
12
|
+
import '@temporalio/workflow';
|
|
12
13
|
import '@temporalio/common/lib/interfaces';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Creates an agent session that manages the agent loop: LLM invocation,
|
|
16
17
|
* tool routing, subagent coordination, and lifecycle hooks.
|
|
17
18
|
*
|
|
19
|
+
* When `sandboxOps` is provided the returned session result is guaranteed to
|
|
20
|
+
* include `sandboxId: string`. Without it, `sandboxId` is `undefined`.
|
|
21
|
+
*
|
|
18
22
|
* @param config - Session and agent configuration (merged `SessionConfig` and `AgentConfig`)
|
|
19
23
|
* @returns A session object with `runSession()` to start the agent loop
|
|
20
24
|
*
|
|
21
25
|
* @example
|
|
22
26
|
* ```typescript
|
|
23
27
|
* import { createSession, createAgentStateManager, defineTool, bashTool } from 'zeitlich/workflow';
|
|
24
|
-
*
|
|
25
|
-
* const stateManager = createAgentStateManager({
|
|
26
|
-
* initialState: { systemPrompt: "You are a helpful assistant." },
|
|
27
|
-
* agentName: "my-agent",
|
|
28
|
-
* });
|
|
28
|
+
* import { proxyGoogleGenAIThreadOps } from 'zeitlich/adapters/thread/google-genai/workflow';
|
|
29
29
|
*
|
|
30
30
|
* const session = await createSession({
|
|
31
31
|
* agentName: "my-agent",
|
|
32
32
|
* maxTurns: 20,
|
|
33
|
-
*
|
|
33
|
+
* thread: { mode: "new" },
|
|
34
|
+
* threadOps: proxyGoogleGenAIThreadOps(),
|
|
34
35
|
* runAgent: runAgentActivity,
|
|
35
36
|
* buildContextMessage: () => [{ type: "text", text: prompt }],
|
|
36
37
|
* subagents: [researcherSubagent],
|
|
@@ -42,57 +43,43 @@ import '@temporalio/common/lib/interfaces';
|
|
|
42
43
|
* const { finalMessage, exitReason } = await session.runSession({ stateManager });
|
|
43
44
|
* ```
|
|
44
45
|
*/
|
|
45
|
-
declare
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* adapter-provided activities registered on the worker.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const session = await createSession({
|
|
54
|
-
* threadOps: proxyDefaultThreadOps(),
|
|
55
|
-
* // ...
|
|
56
|
-
* });
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ActivityInterfaceFor<ThreadOps>;
|
|
60
|
-
/**
|
|
61
|
-
* Proxy sandbox lifecycle operations as Temporal activities.
|
|
62
|
-
* Call this in workflow code when the agent needs a sandbox.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const session = await createSession({
|
|
67
|
-
* sandbox: proxySandboxOps(),
|
|
68
|
-
* // ...
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
declare function proxySandboxOps(options?: Parameters<typeof proxyActivities>[0]): SandboxOps;
|
|
46
|
+
declare function createSession<T extends ToolMap, M = unknown>(config: SessionConfig<T, M> & {
|
|
47
|
+
sandboxOps: SandboxOps;
|
|
48
|
+
}): Promise<ZeitlichSession<M, true>>;
|
|
49
|
+
declare function createSession<T extends ToolMap, M = unknown>(config: SessionConfig<T, M>): Promise<ZeitlichSession<M, false>>;
|
|
73
50
|
|
|
74
51
|
/**
|
|
75
52
|
* Session config fields derived from a main workflow input, ready to spread
|
|
76
53
|
* into `createSession`.
|
|
77
54
|
*/
|
|
78
55
|
interface WorkflowSessionInput {
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
|
|
56
|
+
/** Agent name — spread directly into `createSession` */
|
|
57
|
+
agentName: string;
|
|
58
|
+
/** Thread initialization strategy */
|
|
59
|
+
thread?: ThreadInit;
|
|
60
|
+
/** Sandbox initialization strategy */
|
|
61
|
+
sandbox?: SandboxInit;
|
|
62
|
+
/** Sandbox shutdown policy (default: "destroy") */
|
|
63
|
+
sandboxShutdown?: SandboxShutdown;
|
|
85
64
|
}
|
|
86
65
|
/** Raw workflow input fields that map into `WorkflowSessionInput`. */
|
|
87
66
|
interface WorkflowInput {
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
|
|
67
|
+
/** Thread initialization strategy (default: `{ mode: "new" }`) */
|
|
68
|
+
thread?: ThreadInit;
|
|
69
|
+
/** Sandbox initialization strategy */
|
|
70
|
+
sandbox?: SandboxInit;
|
|
92
71
|
}
|
|
93
72
|
interface WorkflowConfig {
|
|
94
73
|
/** Workflow name — used as the Temporal workflow function name */
|
|
95
74
|
name: string;
|
|
75
|
+
/**
|
|
76
|
+
* Sandbox shutdown policy applied when the main agent session exits.
|
|
77
|
+
*
|
|
78
|
+
* - `"destroy"` (default) — destroy the sandbox on exit.
|
|
79
|
+
* - `"pause"` — pause the sandbox so it can be resumed later.
|
|
80
|
+
* - `"keep"` — leave the sandbox running (no-op on exit).
|
|
81
|
+
*/
|
|
82
|
+
sandboxShutdown?: SandboxShutdown;
|
|
96
83
|
}
|
|
97
84
|
/**
|
|
98
85
|
* Wraps a main workflow function, translating workflow input fields into
|
|
@@ -101,8 +88,8 @@ interface WorkflowConfig {
|
|
|
101
88
|
* The wrapper:
|
|
102
89
|
* - Accepts a `config` with at least a `name` (used for Temporal workflow naming)
|
|
103
90
|
* - Accepts a handler `fn` receiving `(input, sessionInput)`
|
|
104
|
-
* - Derives
|
|
105
|
-
* -
|
|
91
|
+
* - Derives thread / sandbox init from `workflowInput`
|
|
92
|
+
* - Applies the configured `sandboxShutdown` policy
|
|
106
93
|
*/
|
|
107
94
|
declare function defineWorkflow<TInput, TResult>(config: WorkflowConfig, fn: (input: TInput, sessionInput: WorkflowSessionInput) => Promise<TResult>): (input: TInput, workflowInput?: WorkflowInput) => Promise<TResult>;
|
|
108
95
|
|
|
@@ -228,8 +215,8 @@ type SubagentArgs = {
|
|
|
228
215
|
*
|
|
229
216
|
* // With parent-specific overrides
|
|
230
217
|
* export const researcher = defineSubagent(researcherWorkflow, {
|
|
231
|
-
*
|
|
232
|
-
* sandbox: "own",
|
|
218
|
+
* thread: "fork",
|
|
219
|
+
* sandbox: { source: "own", shutdown: "pause" },
|
|
233
220
|
* hooks: {
|
|
234
221
|
* onPostExecution: ({ result }) => console.log(result),
|
|
235
222
|
* },
|
|
@@ -242,12 +229,12 @@ type SubagentArgs = {
|
|
|
242
229
|
* ```
|
|
243
230
|
*/
|
|
244
231
|
declare function defineSubagent<TResult extends z.ZodType = z.ZodType, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: SubagentDefinition<TResult, TContext>, overrides?: {
|
|
245
|
-
context?: TContext;
|
|
232
|
+
context?: TContext | (() => TContext);
|
|
246
233
|
hooks?: SubagentHooks<SubagentArgs, z.infer<TResult>>;
|
|
247
234
|
enabled?: boolean | (() => boolean);
|
|
248
235
|
taskQueue?: string;
|
|
249
|
-
|
|
250
|
-
sandbox?:
|
|
236
|
+
thread?: "new" | "fork" | "continue";
|
|
237
|
+
sandbox?: SubagentSandboxConfig;
|
|
251
238
|
}): SubagentConfig<TResult>;
|
|
252
239
|
|
|
253
240
|
/**
|
|
@@ -296,15 +283,17 @@ declare function defineSubagent<TResult extends z.ZodType = z.ZodType, TContext
|
|
|
296
283
|
* });
|
|
297
284
|
* ```
|
|
298
285
|
*/
|
|
299
|
-
declare function defineSubagentWorkflow<TContext extends Record<string, unknown> = Record<string, unknown>>(config: {
|
|
286
|
+
declare function defineSubagentWorkflow<TSandboxShutdown extends SubagentSandboxShutdown = "destroy", TContext extends Record<string, unknown> = Record<string, unknown>>(config: {
|
|
300
287
|
name: string;
|
|
301
288
|
description: string;
|
|
302
|
-
|
|
303
|
-
|
|
289
|
+
sandboxShutdown?: TSandboxShutdown;
|
|
290
|
+
}, fn: (prompt: string, sessionInput: SubagentSessionInput, context: TContext) => Promise<SubagentFnResult<null, TSandboxShutdown>>): SubagentDefinition<z.ZodNull, TContext>;
|
|
291
|
+
declare function defineSubagentWorkflow<TResult extends z.ZodType, TSandboxShutdown extends SubagentSandboxShutdown = "destroy", TContext extends Record<string, unknown> = Record<string, unknown>>(config: {
|
|
304
292
|
name: string;
|
|
305
293
|
description: string;
|
|
306
294
|
resultSchema: TResult;
|
|
307
|
-
|
|
295
|
+
sandboxShutdown?: TSandboxShutdown;
|
|
296
|
+
}, fn: (prompt: string, sessionInput: SubagentSessionInput, context: TContext) => Promise<SubagentFnResult<z.infer<TResult> | null, TSandboxShutdown>>): SubagentDefinition<TResult, TContext>;
|
|
308
297
|
|
|
309
298
|
/**
|
|
310
299
|
* Apply a list of {@link TreeMutation}s to the `fileTree` stored in a state
|
|
@@ -584,4 +573,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
|
|
|
584
573
|
}[];
|
|
585
574
|
}>;
|
|
586
575
|
|
|
587
|
-
export { ActivityToolHandler, AgentStateManager, type AskUserQuestionArgs, BaseAgentState, type BashArgs, type FileEditArgs, FileEntry, FileEntryMetadata, type FileReadArgs, type FileWriteArgs, type GlobArgs, type GrepArgs, JsonSerializable, ParsedToolCallUnion, type ReadSkillArgs, RouterContext, SandboxOps, SessionConfig, Skill, SkillMetadata, type SubagentArgs, SubagentConfig, SubagentDefinition,
|
|
576
|
+
export { ActivityToolHandler, AgentStateManager, type AskUserQuestionArgs, BaseAgentState, type BashArgs, type FileEditArgs, FileEntry, FileEntryMetadata, type FileReadArgs, type FileWriteArgs, type GlobArgs, type GrepArgs, JsonSerializable, ParsedToolCallUnion, type ReadSkillArgs, RouterContext, SandboxInit, SandboxOps, SandboxShutdown, SessionConfig, Skill, SkillMetadata, type SubagentArgs, SubagentConfig, SubagentDefinition, SubagentFnResult, SubagentHooks, SubagentSandboxConfig, SubagentSandboxShutdown, SubagentSessionInput, type TaskCreateArgs, type TaskGetArgs, type TaskListArgs, type TaskUpdateArgs, ThreadInit, ToolHandler, ToolHandlerResponse, ToolMap, ToolNames, ToolRouter, ToolWithHandler, TreeMutation, VirtualFileTree, type WorkflowConfig, type WorkflowInput, type WorkflowSessionInput, WorkflowTask, ZeitlichSession, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, formatVirtualFileTree, getShortId, globTool, grepTool, hasNoOtherToolCalls, parseSkillFile, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool };
|
package/dist/workflow.d.ts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, g as RunAgentConfig, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, F as ToolHooks, T as ToolMessageContent, H as ToolResult, j as ToolResultConfig, b as ToolRouterHooks, L as isTerminalStatus } from './types-YbL7JpEA.js';
|
|
1
|
+
import { o as SessionConfig, Z as ZeitlichSession, n as SandboxShutdown, F as ThreadInit, m as SandboxInit, g as JsonSerializable, f as AgentStateManager, v as SubagentDefinition, y as SubagentHooks, z as SubagentSandboxConfig, u as SubagentConfig, B as SubagentSandboxShutdown, C as SubagentSessionInput, w as SubagentFnResult, c as SkillMetadata, d as Skill } from './types-B50pBPEV.js';
|
|
2
|
+
export { A as AgentResponse, e as AgentState, H as Hooks, J as JsonPrimitive, h as JsonValue, M as ModelInvoker, a as ModelInvokerConfig, i as PostHumanMessageAppendHook, j as PostHumanMessageAppendHookContext, k as PreHumanMessageAppendHook, l as PreHumanMessageAppendHookContext, P as PrefixedThreadOps, R as RunAgentActivity, S as ScopedPrefix, p as SessionEndHook, q as SessionEndHookContext, r as SessionResult, s as SessionStartHook, t as SessionStartHookContext, b as SkillProvider, x as SubagentHandlerResponse, D as SubagentWorkflow, E as SubagentWorkflowInput, T as ThreadOps } from './types-B50pBPEV.js';
|
|
3
|
+
import { g as SandboxOps } from './types-ChAMwU3q.js';
|
|
4
|
+
export { h as ExecOptions, E as ExecResult, P as PrefixedSandboxOps, S as Sandbox, c as SandboxCapabilities, d as SandboxCreateOptions, e as SandboxCreateResult, D as SandboxDirentEntry, F as SandboxFileStat, a as SandboxFileSystem, i as SandboxNotFoundError, j as SandboxNotSupportedError, b as SandboxProvider, f as SandboxSnapshot } from './types-ChAMwU3q.js';
|
|
5
|
+
import { a as ToolMap, B as BaseAgentState, N as ToolRouterOptions, J as ToolRouter, R as RouterContext, K as ToolWithHandler, p as ParsedToolCallUnion, G as ToolNames, c as ToolHandlerResponse, E as ToolHandler, W as WorkflowTask, A as ActivityToolHandler } from './types-Bll19FZJ.js';
|
|
6
|
+
export { l as AgentConfig, m as AgentFile, h as AgentStatus, n as AppendToolResultFn, C as ContentPart, I as InferToolResults, M as MessageContent, o as ParsedToolCall, q as PostToolUseFailureHook, r as PostToolUseFailureHookContext, d as PostToolUseFailureHookResult, s as PostToolUseHook, t as PostToolUseHookContext, u as PreToolUseHook, v as PreToolUseHookContext, P as PreToolUseHookResult, w as ProcessToolCallsContext, e as RawToolCall, g as RunAgentConfig, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, F as ToolHooks, T as ToolMessageContent, H as ToolResult, j as ToolResultConfig, b as ToolRouterHooks, L as isTerminalStatus } from './types-Bll19FZJ.js';
|
|
8
7
|
import z$1, { z } from 'zod';
|
|
9
|
-
import {
|
|
10
|
-
export {
|
|
8
|
+
import { a as FileEntryMetadata, e as VirtualFileTree, T as TreeMutation, F as FileEntry } from './types-GZ76HZSj.js';
|
|
9
|
+
export { b as FileResolver, g as VirtualSandboxState } from './types-GZ76HZSj.js';
|
|
10
|
+
export { f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from './queries-byD0jr1Y.js';
|
|
11
11
|
import '@temporalio/common';
|
|
12
|
+
import '@temporalio/workflow';
|
|
12
13
|
import '@temporalio/common/lib/interfaces';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Creates an agent session that manages the agent loop: LLM invocation,
|
|
16
17
|
* tool routing, subagent coordination, and lifecycle hooks.
|
|
17
18
|
*
|
|
19
|
+
* When `sandboxOps` is provided the returned session result is guaranteed to
|
|
20
|
+
* include `sandboxId: string`. Without it, `sandboxId` is `undefined`.
|
|
21
|
+
*
|
|
18
22
|
* @param config - Session and agent configuration (merged `SessionConfig` and `AgentConfig`)
|
|
19
23
|
* @returns A session object with `runSession()` to start the agent loop
|
|
20
24
|
*
|
|
21
25
|
* @example
|
|
22
26
|
* ```typescript
|
|
23
27
|
* import { createSession, createAgentStateManager, defineTool, bashTool } from 'zeitlich/workflow';
|
|
24
|
-
*
|
|
25
|
-
* const stateManager = createAgentStateManager({
|
|
26
|
-
* initialState: { systemPrompt: "You are a helpful assistant." },
|
|
27
|
-
* agentName: "my-agent",
|
|
28
|
-
* });
|
|
28
|
+
* import { proxyGoogleGenAIThreadOps } from 'zeitlich/adapters/thread/google-genai/workflow';
|
|
29
29
|
*
|
|
30
30
|
* const session = await createSession({
|
|
31
31
|
* agentName: "my-agent",
|
|
32
32
|
* maxTurns: 20,
|
|
33
|
-
*
|
|
33
|
+
* thread: { mode: "new" },
|
|
34
|
+
* threadOps: proxyGoogleGenAIThreadOps(),
|
|
34
35
|
* runAgent: runAgentActivity,
|
|
35
36
|
* buildContextMessage: () => [{ type: "text", text: prompt }],
|
|
36
37
|
* subagents: [researcherSubagent],
|
|
@@ -42,57 +43,43 @@ import '@temporalio/common/lib/interfaces';
|
|
|
42
43
|
* const { finalMessage, exitReason } = await session.runSession({ stateManager });
|
|
43
44
|
* ```
|
|
44
45
|
*/
|
|
45
|
-
declare
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* adapter-provided activities registered on the worker.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const session = await createSession({
|
|
54
|
-
* threadOps: proxyDefaultThreadOps(),
|
|
55
|
-
* // ...
|
|
56
|
-
* });
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ActivityInterfaceFor<ThreadOps>;
|
|
60
|
-
/**
|
|
61
|
-
* Proxy sandbox lifecycle operations as Temporal activities.
|
|
62
|
-
* Call this in workflow code when the agent needs a sandbox.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const session = await createSession({
|
|
67
|
-
* sandbox: proxySandboxOps(),
|
|
68
|
-
* // ...
|
|
69
|
-
* });
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
declare function proxySandboxOps(options?: Parameters<typeof proxyActivities>[0]): SandboxOps;
|
|
46
|
+
declare function createSession<T extends ToolMap, M = unknown>(config: SessionConfig<T, M> & {
|
|
47
|
+
sandboxOps: SandboxOps;
|
|
48
|
+
}): Promise<ZeitlichSession<M, true>>;
|
|
49
|
+
declare function createSession<T extends ToolMap, M = unknown>(config: SessionConfig<T, M>): Promise<ZeitlichSession<M, false>>;
|
|
73
50
|
|
|
74
51
|
/**
|
|
75
52
|
* Session config fields derived from a main workflow input, ready to spread
|
|
76
53
|
* into `createSession`.
|
|
77
54
|
*/
|
|
78
55
|
interface WorkflowSessionInput {
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
|
|
56
|
+
/** Agent name — spread directly into `createSession` */
|
|
57
|
+
agentName: string;
|
|
58
|
+
/** Thread initialization strategy */
|
|
59
|
+
thread?: ThreadInit;
|
|
60
|
+
/** Sandbox initialization strategy */
|
|
61
|
+
sandbox?: SandboxInit;
|
|
62
|
+
/** Sandbox shutdown policy (default: "destroy") */
|
|
63
|
+
sandboxShutdown?: SandboxShutdown;
|
|
85
64
|
}
|
|
86
65
|
/** Raw workflow input fields that map into `WorkflowSessionInput`. */
|
|
87
66
|
interface WorkflowInput {
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
|
|
67
|
+
/** Thread initialization strategy (default: `{ mode: "new" }`) */
|
|
68
|
+
thread?: ThreadInit;
|
|
69
|
+
/** Sandbox initialization strategy */
|
|
70
|
+
sandbox?: SandboxInit;
|
|
92
71
|
}
|
|
93
72
|
interface WorkflowConfig {
|
|
94
73
|
/** Workflow name — used as the Temporal workflow function name */
|
|
95
74
|
name: string;
|
|
75
|
+
/**
|
|
76
|
+
* Sandbox shutdown policy applied when the main agent session exits.
|
|
77
|
+
*
|
|
78
|
+
* - `"destroy"` (default) — destroy the sandbox on exit.
|
|
79
|
+
* - `"pause"` — pause the sandbox so it can be resumed later.
|
|
80
|
+
* - `"keep"` — leave the sandbox running (no-op on exit).
|
|
81
|
+
*/
|
|
82
|
+
sandboxShutdown?: SandboxShutdown;
|
|
96
83
|
}
|
|
97
84
|
/**
|
|
98
85
|
* Wraps a main workflow function, translating workflow input fields into
|
|
@@ -101,8 +88,8 @@ interface WorkflowConfig {
|
|
|
101
88
|
* The wrapper:
|
|
102
89
|
* - Accepts a `config` with at least a `name` (used for Temporal workflow naming)
|
|
103
90
|
* - Accepts a handler `fn` receiving `(input, sessionInput)`
|
|
104
|
-
* - Derives
|
|
105
|
-
* -
|
|
91
|
+
* - Derives thread / sandbox init from `workflowInput`
|
|
92
|
+
* - Applies the configured `sandboxShutdown` policy
|
|
106
93
|
*/
|
|
107
94
|
declare function defineWorkflow<TInput, TResult>(config: WorkflowConfig, fn: (input: TInput, sessionInput: WorkflowSessionInput) => Promise<TResult>): (input: TInput, workflowInput?: WorkflowInput) => Promise<TResult>;
|
|
108
95
|
|
|
@@ -228,8 +215,8 @@ type SubagentArgs = {
|
|
|
228
215
|
*
|
|
229
216
|
* // With parent-specific overrides
|
|
230
217
|
* export const researcher = defineSubagent(researcherWorkflow, {
|
|
231
|
-
*
|
|
232
|
-
* sandbox: "own",
|
|
218
|
+
* thread: "fork",
|
|
219
|
+
* sandbox: { source: "own", shutdown: "pause" },
|
|
233
220
|
* hooks: {
|
|
234
221
|
* onPostExecution: ({ result }) => console.log(result),
|
|
235
222
|
* },
|
|
@@ -242,12 +229,12 @@ type SubagentArgs = {
|
|
|
242
229
|
* ```
|
|
243
230
|
*/
|
|
244
231
|
declare function defineSubagent<TResult extends z.ZodType = z.ZodType, TContext extends Record<string, unknown> = Record<string, unknown>>(definition: SubagentDefinition<TResult, TContext>, overrides?: {
|
|
245
|
-
context?: TContext;
|
|
232
|
+
context?: TContext | (() => TContext);
|
|
246
233
|
hooks?: SubagentHooks<SubagentArgs, z.infer<TResult>>;
|
|
247
234
|
enabled?: boolean | (() => boolean);
|
|
248
235
|
taskQueue?: string;
|
|
249
|
-
|
|
250
|
-
sandbox?:
|
|
236
|
+
thread?: "new" | "fork" | "continue";
|
|
237
|
+
sandbox?: SubagentSandboxConfig;
|
|
251
238
|
}): SubagentConfig<TResult>;
|
|
252
239
|
|
|
253
240
|
/**
|
|
@@ -296,15 +283,17 @@ declare function defineSubagent<TResult extends z.ZodType = z.ZodType, TContext
|
|
|
296
283
|
* });
|
|
297
284
|
* ```
|
|
298
285
|
*/
|
|
299
|
-
declare function defineSubagentWorkflow<TContext extends Record<string, unknown> = Record<string, unknown>>(config: {
|
|
286
|
+
declare function defineSubagentWorkflow<TSandboxShutdown extends SubagentSandboxShutdown = "destroy", TContext extends Record<string, unknown> = Record<string, unknown>>(config: {
|
|
300
287
|
name: string;
|
|
301
288
|
description: string;
|
|
302
|
-
|
|
303
|
-
|
|
289
|
+
sandboxShutdown?: TSandboxShutdown;
|
|
290
|
+
}, fn: (prompt: string, sessionInput: SubagentSessionInput, context: TContext) => Promise<SubagentFnResult<null, TSandboxShutdown>>): SubagentDefinition<z.ZodNull, TContext>;
|
|
291
|
+
declare function defineSubagentWorkflow<TResult extends z.ZodType, TSandboxShutdown extends SubagentSandboxShutdown = "destroy", TContext extends Record<string, unknown> = Record<string, unknown>>(config: {
|
|
304
292
|
name: string;
|
|
305
293
|
description: string;
|
|
306
294
|
resultSchema: TResult;
|
|
307
|
-
|
|
295
|
+
sandboxShutdown?: TSandboxShutdown;
|
|
296
|
+
}, fn: (prompt: string, sessionInput: SubagentSessionInput, context: TContext) => Promise<SubagentFnResult<z.infer<TResult> | null, TSandboxShutdown>>): SubagentDefinition<TResult, TContext>;
|
|
308
297
|
|
|
309
298
|
/**
|
|
310
299
|
* Apply a list of {@link TreeMutation}s to the `fileTree` stored in a state
|
|
@@ -584,4 +573,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
|
|
|
584
573
|
}[];
|
|
585
574
|
}>;
|
|
586
575
|
|
|
587
|
-
export { ActivityToolHandler, AgentStateManager, type AskUserQuestionArgs, BaseAgentState, type BashArgs, type FileEditArgs, FileEntry, FileEntryMetadata, type FileReadArgs, type FileWriteArgs, type GlobArgs, type GrepArgs, JsonSerializable, ParsedToolCallUnion, type ReadSkillArgs, RouterContext, SandboxOps, SessionConfig, Skill, SkillMetadata, type SubagentArgs, SubagentConfig, SubagentDefinition,
|
|
576
|
+
export { ActivityToolHandler, AgentStateManager, type AskUserQuestionArgs, BaseAgentState, type BashArgs, type FileEditArgs, FileEntry, FileEntryMetadata, type FileReadArgs, type FileWriteArgs, type GlobArgs, type GrepArgs, JsonSerializable, ParsedToolCallUnion, type ReadSkillArgs, RouterContext, SandboxInit, SandboxOps, SandboxShutdown, SessionConfig, Skill, SkillMetadata, type SubagentArgs, SubagentConfig, SubagentDefinition, SubagentFnResult, SubagentHooks, SubagentSandboxConfig, SubagentSandboxShutdown, SubagentSessionInput, type TaskCreateArgs, type TaskGetArgs, type TaskListArgs, type TaskUpdateArgs, ThreadInit, ToolHandler, ToolHandlerResponse, ToolMap, ToolNames, ToolRouter, ToolWithHandler, TreeMutation, VirtualFileTree, type WorkflowConfig, type WorkflowInput, type WorkflowSessionInput, WorkflowTask, ZeitlichSession, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, formatVirtualFileTree, getShortId, globTool, grepTool, hasNoOtherToolCalls, parseSkillFile, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool };
|