zeitlich 0.2.20 → 0.2.22
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 +70 -55
- package/dist/adapters/sandbox/daytona/index.cjs +3 -0
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -1
- package/dist/adapters/sandbox/daytona/index.d.cts +2 -1
- package/dist/adapters/sandbox/daytona/index.d.ts +2 -1
- package/dist/adapters/sandbox/daytona/index.js +3 -0
- package/dist/adapters/sandbox/daytona/index.js.map +1 -1
- package/dist/adapters/sandbox/daytona/workflow.cjs +32 -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 +30 -0
- package/dist/adapters/sandbox/daytona/workflow.js.map +1 -0
- package/dist/adapters/sandbox/inmemory/index.cjs +4 -1
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -1
- package/dist/adapters/sandbox/inmemory/index.d.cts +3 -2
- package/dist/adapters/sandbox/inmemory/index.d.ts +3 -2
- package/dist/adapters/sandbox/inmemory/index.js +4 -1
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -1
- package/dist/adapters/sandbox/inmemory/workflow.cjs +32 -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 +30 -0
- package/dist/adapters/sandbox/inmemory/workflow.js.map +1 -0
- package/dist/adapters/sandbox/virtual/index.cjs +3 -0
- package/dist/adapters/sandbox/virtual/index.cjs.map +1 -1
- package/dist/adapters/sandbox/virtual/index.d.cts +7 -5
- package/dist/adapters/sandbox/virtual/index.d.ts +7 -5
- package/dist/adapters/sandbox/virtual/index.js +3 -0
- package/dist/adapters/sandbox/virtual/index.js.map +1 -1
- package/dist/adapters/sandbox/virtual/workflow.cjs +32 -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 +30 -0
- package/dist/adapters/sandbox/virtual/workflow.js.map +1 -0
- package/dist/adapters/thread/google-genai/index.cjs +79 -24
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
- package/dist/adapters/thread/google-genai/index.d.cts +39 -27
- package/dist/adapters/thread/google-genai/index.d.ts +39 -27
- package/dist/adapters/thread/google-genai/index.js +79 -24
- 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 +84 -71
- package/dist/adapters/thread/langchain/index.cjs.map +1 -1
- package/dist/adapters/thread/langchain/index.d.cts +35 -24
- package/dist/adapters/thread/langchain/index.d.ts +35 -24
- package/dist/adapters/thread/langchain/index.js +84 -71
- 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 +90 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -17
- package/dist/index.d.ts +38 -17
- package/dist/index.js +92 -43
- package/dist/index.js.map +1 -1
- package/dist/queries-Bw6WEPMw.d.cts +44 -0
- package/dist/queries-C27raDaB.d.ts +44 -0
- package/dist/{queries-KHj5Otv7.d.ts → types-BJ8itUAl.d.cts} +3 -44
- package/dist/{types-By80IE1x.d.ts → types-C5bkx6kQ.d.ts} +37 -9
- package/dist/{types-DZ7BkA3-.d.cts → types-ClsHhtwL.d.cts} +37 -9
- package/dist/{queries-nIdzTCDS.d.cts → types-ENYCKFBk.d.ts} +3 -44
- package/dist/{types-BMRzfELQ.d.cts → types-HBosetv3.d.cts} +15 -1
- package/dist/{types-BMRzfELQ.d.ts → types-HBosetv3.d.ts} +15 -1
- package/dist/{types-Ct2igz9y.d.cts → types-YbL7JpEA.d.cts} +1 -1
- package/dist/{types-Ct2igz9y.d.ts → types-YbL7JpEA.d.ts} +1 -1
- package/dist/workflow.cjs +11 -38
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +15 -43
- package/dist/workflow.d.ts +15 -43
- package/dist/workflow.js +13 -38
- package/dist/workflow.js.map +1 -1
- package/package.json +53 -1
- package/src/adapters/sandbox/daytona/index.ts +4 -0
- package/src/adapters/sandbox/daytona/proxy.ts +55 -0
- package/src/adapters/sandbox/e2b/filesystem.ts +147 -0
- package/src/adapters/sandbox/e2b/index.ts +159 -0
- package/src/adapters/sandbox/e2b/types.ts +23 -0
- package/src/adapters/sandbox/inmemory/index.ts +5 -1
- package/src/adapters/sandbox/inmemory/proxy.ts +53 -0
- package/src/adapters/sandbox/virtual/provider.ts +5 -1
- package/src/adapters/sandbox/virtual/proxy.ts +52 -0
- package/src/adapters/thread/google-genai/activities.ts +62 -26
- package/src/adapters/thread/google-genai/index.ts +1 -0
- package/src/adapters/thread/google-genai/model-invoker.ts +6 -11
- package/src/adapters/thread/google-genai/proxy.ts +61 -0
- package/src/adapters/thread/google-genai/thread-manager.ts +44 -29
- package/src/adapters/thread/langchain/activities.ts +53 -18
- package/src/adapters/thread/langchain/index.ts +1 -0
- package/src/adapters/thread/langchain/proxy.ts +61 -0
- package/src/adapters/thread/langchain/thread-manager.ts +46 -22
- package/src/lib/sandbox/manager.ts +40 -6
- package/src/lib/sandbox/sandbox.test.ts +12 -11
- package/src/lib/sandbox/types.ts +18 -0
- package/src/lib/session/index.ts +3 -5
- package/src/lib/session/session-edge-cases.integration.test.ts +45 -34
- package/src/lib/session/session.integration.test.ts +40 -48
- package/src/lib/session/session.ts +9 -70
- package/src/lib/session/types.ts +39 -3
- package/src/lib/subagent/define.ts +1 -1
- package/src/lib/subagent/handler.ts +9 -2
- package/src/lib/subagent/index.ts +1 -0
- package/src/lib/subagent/subagent.integration.test.ts +62 -0
- package/src/lib/subagent/types.ts +7 -2
- package/src/lib/tool-router/auto-append-sandbox.integration.test.ts +20 -21
- package/src/lib/tool-router/auto-append.ts +3 -2
- package/src/lib/tool-router/router-edge-cases.integration.test.ts +63 -24
- package/src/lib/tool-router/router.integration.test.ts +59 -24
- package/src/lib/tool-router/router.ts +4 -3
- package/src/lib/tool-router/types.ts +1 -1
- package/src/lib/workflow.test.ts +19 -10
- package/src/lib/workflow.ts +4 -1
- package/src/tools/bash/bash.test.ts +16 -7
- package/src/workflow.ts +6 -14
- package/tsup.config.ts +6 -0
package/dist/workflow.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { h as ExecOptions, E as ExecResult, 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-BMRzfELQ.cjs';
|
|
6
|
-
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-Ct2igz9y.cjs';
|
|
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-Ct2igz9y.cjs';
|
|
1
|
+
import { m as SessionConfig, Z as ZeitlichSession, g as JsonSerializable, f as AgentStateManager, s as SubagentDefinition, u as SubagentHooks, r as SubagentConfig, v as SubagentSessionInput, t as SubagentHandlerResponse, c as SkillMetadata, d as Skill } from './types-ClsHhtwL.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, n as SessionEndHook, o as SessionEndHookContext, p as SessionStartHook, q as SessionStartHookContext, b as SkillProvider, w as SubagentWorkflow, x as SubagentWorkflowInput, T as ThreadOps } from './types-ClsHhtwL.cjs';
|
|
3
|
+
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-YbL7JpEA.cjs';
|
|
4
|
+
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';
|
|
8
5
|
import z$1, { z } from 'zod';
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
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, g as SandboxOps, b as SandboxProvider, f as SandboxSnapshot } from './types-HBosetv3.cjs';
|
|
7
|
+
import { a as FileEntryMetadata, e as VirtualFileTree, T as TreeMutation, F as FileEntry } from './types-BJ8itUAl.cjs';
|
|
8
|
+
export { b as FileResolver, g as VirtualSandboxState } from './types-BJ8itUAl.cjs';
|
|
9
|
+
export { f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from './queries-Bw6WEPMw.cjs';
|
|
11
10
|
import '@temporalio/common';
|
|
11
|
+
import '@temporalio/workflow';
|
|
12
12
|
import '@temporalio/common/lib/interfaces';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -21,16 +21,13 @@ import '@temporalio/common/lib/interfaces';
|
|
|
21
21
|
* @example
|
|
22
22
|
* ```typescript
|
|
23
23
|
* 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
|
-
* });
|
|
24
|
+
* import { proxyGoogleGenAIThreadOps } from 'zeitlich/adapters/thread/google-genai/workflow';
|
|
29
25
|
*
|
|
30
26
|
* const session = await createSession({
|
|
31
27
|
* agentName: "my-agent",
|
|
32
28
|
* maxTurns: 20,
|
|
33
29
|
* threadId: runId,
|
|
30
|
+
* threadOps: proxyGoogleGenAIThreadOps(), // auto-scoped to current workflow
|
|
34
31
|
* runAgent: runAgentActivity,
|
|
35
32
|
* buildContextMessage: () => [{ type: "text", text: prompt }],
|
|
36
33
|
* subagents: [researcherSubagent],
|
|
@@ -43,39 +40,14 @@ import '@temporalio/common/lib/interfaces';
|
|
|
43
40
|
* ```
|
|
44
41
|
*/
|
|
45
42
|
declare const createSession: <T extends ToolMap, M = unknown>({ threadId: providedThreadId, agentName, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, skills, tools, processToolsInParallel, hooks, appendSystemPrompt, continueThread, waitForInputTimeout, sandbox: sandboxOps, sandboxId: inheritedSandboxId, }: SessionConfig<T, M>) => Promise<ZeitlichSession<M>>;
|
|
46
|
-
/**
|
|
47
|
-
* Proxy the adapter's thread operations as Temporal activities.
|
|
48
|
-
* Call this in workflow code to delegate thread operations to the
|
|
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;
|
|
73
43
|
|
|
74
44
|
/**
|
|
75
45
|
* Session config fields derived from a main workflow input, ready to spread
|
|
76
46
|
* into `createSession`.
|
|
77
47
|
*/
|
|
78
48
|
interface WorkflowSessionInput {
|
|
49
|
+
/** Agent name — spread directly into `createSession` */
|
|
50
|
+
agentName: string;
|
|
79
51
|
/** Thread ID to continue (set from `input.previousThreadId`) */
|
|
80
52
|
threadId?: string;
|
|
81
53
|
/** Whether to continue an existing thread (true when `previousThreadId` is present) */
|
|
@@ -242,7 +214,7 @@ type SubagentArgs = {
|
|
|
242
214
|
* ```
|
|
243
215
|
*/
|
|
244
216
|
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;
|
|
217
|
+
context?: TContext | (() => TContext);
|
|
246
218
|
hooks?: SubagentHooks<SubagentArgs, z.infer<TResult>>;
|
|
247
219
|
enabled?: boolean | (() => boolean);
|
|
248
220
|
taskQueue?: string;
|
|
@@ -584,4 +556,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
|
|
|
584
556
|
}[];
|
|
585
557
|
}>;
|
|
586
558
|
|
|
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,
|
|
559
|
+
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, SessionConfig, Skill, SkillMetadata, type SubagentArgs, SubagentConfig, SubagentDefinition, SubagentHandlerResponse, SubagentHooks, SubagentSessionInput, type TaskCreateArgs, type TaskGetArgs, type TaskListArgs, type TaskUpdateArgs, 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,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { h as ExecOptions, E as ExecResult, 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-BMRzfELQ.js';
|
|
6
|
-
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-Ct2igz9y.js';
|
|
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-Ct2igz9y.js';
|
|
1
|
+
import { m as SessionConfig, Z as ZeitlichSession, g as JsonSerializable, f as AgentStateManager, s as SubagentDefinition, u as SubagentHooks, r as SubagentConfig, v as SubagentSessionInput, t as SubagentHandlerResponse, c as SkillMetadata, d as Skill } from './types-C5bkx6kQ.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, n as SessionEndHook, o as SessionEndHookContext, p as SessionStartHook, q as SessionStartHookContext, b as SkillProvider, w as SubagentWorkflow, x as SubagentWorkflowInput, T as ThreadOps } from './types-C5bkx6kQ.js';
|
|
3
|
+
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-YbL7JpEA.js';
|
|
4
|
+
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';
|
|
8
5
|
import z$1, { z } from 'zod';
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
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, g as SandboxOps, b as SandboxProvider, f as SandboxSnapshot } from './types-HBosetv3.js';
|
|
7
|
+
import { a as FileEntryMetadata, e as VirtualFileTree, T as TreeMutation, F as FileEntry } from './types-ENYCKFBk.js';
|
|
8
|
+
export { b as FileResolver, g as VirtualSandboxState } from './types-ENYCKFBk.js';
|
|
9
|
+
export { f as filesWithMimeType, h as hasDirectory, a as hasFileWithMimeType } from './queries-C27raDaB.js';
|
|
11
10
|
import '@temporalio/common';
|
|
11
|
+
import '@temporalio/workflow';
|
|
12
12
|
import '@temporalio/common/lib/interfaces';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -21,16 +21,13 @@ import '@temporalio/common/lib/interfaces';
|
|
|
21
21
|
* @example
|
|
22
22
|
* ```typescript
|
|
23
23
|
* 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
|
-
* });
|
|
24
|
+
* import { proxyGoogleGenAIThreadOps } from 'zeitlich/adapters/thread/google-genai/workflow';
|
|
29
25
|
*
|
|
30
26
|
* const session = await createSession({
|
|
31
27
|
* agentName: "my-agent",
|
|
32
28
|
* maxTurns: 20,
|
|
33
29
|
* threadId: runId,
|
|
30
|
+
* threadOps: proxyGoogleGenAIThreadOps(), // auto-scoped to current workflow
|
|
34
31
|
* runAgent: runAgentActivity,
|
|
35
32
|
* buildContextMessage: () => [{ type: "text", text: prompt }],
|
|
36
33
|
* subagents: [researcherSubagent],
|
|
@@ -43,39 +40,14 @@ import '@temporalio/common/lib/interfaces';
|
|
|
43
40
|
* ```
|
|
44
41
|
*/
|
|
45
42
|
declare const createSession: <T extends ToolMap, M = unknown>({ threadId: providedThreadId, agentName, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, skills, tools, processToolsInParallel, hooks, appendSystemPrompt, continueThread, waitForInputTimeout, sandbox: sandboxOps, sandboxId: inheritedSandboxId, }: SessionConfig<T, M>) => Promise<ZeitlichSession<M>>;
|
|
46
|
-
/**
|
|
47
|
-
* Proxy the adapter's thread operations as Temporal activities.
|
|
48
|
-
* Call this in workflow code to delegate thread operations to the
|
|
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;
|
|
73
43
|
|
|
74
44
|
/**
|
|
75
45
|
* Session config fields derived from a main workflow input, ready to spread
|
|
76
46
|
* into `createSession`.
|
|
77
47
|
*/
|
|
78
48
|
interface WorkflowSessionInput {
|
|
49
|
+
/** Agent name — spread directly into `createSession` */
|
|
50
|
+
agentName: string;
|
|
79
51
|
/** Thread ID to continue (set from `input.previousThreadId`) */
|
|
80
52
|
threadId?: string;
|
|
81
53
|
/** Whether to continue an existing thread (true when `previousThreadId` is present) */
|
|
@@ -242,7 +214,7 @@ type SubagentArgs = {
|
|
|
242
214
|
* ```
|
|
243
215
|
*/
|
|
244
216
|
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;
|
|
217
|
+
context?: TContext | (() => TContext);
|
|
246
218
|
hooks?: SubagentHooks<SubagentArgs, z.infer<TResult>>;
|
|
247
219
|
enabled?: boolean | (() => boolean);
|
|
248
220
|
taskQueue?: string;
|
|
@@ -584,4 +556,4 @@ declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQue
|
|
|
584
556
|
}[];
|
|
585
557
|
}>;
|
|
586
558
|
|
|
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,
|
|
559
|
+
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, SessionConfig, Skill, SkillMetadata, type SubagentArgs, SubagentConfig, SubagentDefinition, SubagentHandlerResponse, SubagentHooks, SubagentSessionInput, type TaskCreateArgs, type TaskGetArgs, type TaskListArgs, type TaskUpdateArgs, 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.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { uuid4, setHandler, defineUpdate, ApplicationFailure, condition,
|
|
1
|
+
import { uuid4, setHandler, defineUpdate, ApplicationFailure, condition, defineQuery, workflowInfo, executeChild } from '@temporalio/workflow';
|
|
2
2
|
import z14, { z } from 'zod';
|
|
3
3
|
import { ApplicationFailure as ApplicationFailure$1 } from '@temporalio/common';
|
|
4
4
|
|
|
@@ -106,7 +106,7 @@ function createToolRouter(options) {
|
|
|
106
106
|
const tool = toolMap.get(toolCall.name);
|
|
107
107
|
const preResult = await runPreHooks(toolCall, tool, turn);
|
|
108
108
|
if (preResult.skip) {
|
|
109
|
-
await appendToolResult({
|
|
109
|
+
await appendToolResult(uuid4(), {
|
|
110
110
|
threadId: options.threadId,
|
|
111
111
|
toolCallId: toolCall.id,
|
|
112
112
|
toolName: toolCall.name,
|
|
@@ -162,7 +162,7 @@ function createToolRouter(options) {
|
|
|
162
162
|
{
|
|
163
163
|
summary: `Append ${toolCall.name} result`
|
|
164
164
|
},
|
|
165
|
-
[config]
|
|
165
|
+
[uuid4(), config]
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
168
|
const toolResult = {
|
|
@@ -259,6 +259,7 @@ function createToolRouter(options) {
|
|
|
259
259
|
summary: `Append ${toolCall.name} result`
|
|
260
260
|
},
|
|
261
261
|
[
|
|
262
|
+
uuid4(),
|
|
262
263
|
{
|
|
263
264
|
threadId: options.threadId,
|
|
264
265
|
toolCallId: toolCall.id,
|
|
@@ -368,9 +369,10 @@ function createSubagentHandler(subagents) {
|
|
|
368
369
|
},
|
|
369
370
|
...inheritSandbox && { sandboxId: parentSandboxId }
|
|
370
371
|
};
|
|
372
|
+
const resolvedContext = config.context === void 0 ? void 0 : typeof config.context === "function" ? config.context() : config.context;
|
|
371
373
|
const childOpts = {
|
|
372
374
|
workflowId: childWorkflowId,
|
|
373
|
-
args:
|
|
375
|
+
args: resolvedContext === void 0 ? [args.prompt, workflowInput] : [args.prompt, workflowInput, resolvedContext],
|
|
374
376
|
taskQueue: config.taskQueue ?? parentTaskQueue
|
|
375
377
|
};
|
|
376
378
|
const {
|
|
@@ -494,8 +496,6 @@ function buildSkillRegistration(skills) {
|
|
|
494
496
|
handler: createReadSkillHandler(skills)
|
|
495
497
|
};
|
|
496
498
|
}
|
|
497
|
-
|
|
498
|
-
// src/lib/session/session.ts
|
|
499
499
|
var createSession = async ({
|
|
500
500
|
threadId: providedThreadId,
|
|
501
501
|
agentName,
|
|
@@ -523,7 +523,7 @@ var createSession = async ({
|
|
|
523
523
|
initializeThread,
|
|
524
524
|
appendSystemMessage,
|
|
525
525
|
forkThread
|
|
526
|
-
} = threadOps
|
|
526
|
+
} = threadOps;
|
|
527
527
|
const plugins = [];
|
|
528
528
|
if (subagents) {
|
|
529
529
|
const reg = buildSubagentRegistration(subagents);
|
|
@@ -565,7 +565,7 @@ var createSession = async ({
|
|
|
565
565
|
threadId
|
|
566
566
|
});
|
|
567
567
|
}
|
|
568
|
-
await appendHumanMessage(threadId, message);
|
|
568
|
+
await appendHumanMessage(threadId, uuid4(), message);
|
|
569
569
|
if (hooks.onPostHumanMessageAppend) {
|
|
570
570
|
await hooks.onPostHumanMessageAppend({
|
|
571
571
|
message,
|
|
@@ -602,12 +602,12 @@ var createSession = async ({
|
|
|
602
602
|
nonRetryable: true
|
|
603
603
|
});
|
|
604
604
|
}
|
|
605
|
-
await appendSystemMessage(threadId, systemPrompt);
|
|
605
|
+
await appendSystemMessage(threadId, uuid4(), systemPrompt);
|
|
606
606
|
} else {
|
|
607
607
|
await initializeThread(threadId);
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
|
-
await appendHumanMessage(threadId, await buildContextMessage());
|
|
610
|
+
await appendHumanMessage(threadId, uuid4(), await buildContextMessage());
|
|
611
611
|
let exitReason = "completed";
|
|
612
612
|
try {
|
|
613
613
|
while (stateManager.isRunning() && !stateManager.isTerminal() && stateManager.getTurns() < maxTurns) {
|
|
@@ -637,7 +637,7 @@ var createSession = async ({
|
|
|
637
637
|
try {
|
|
638
638
|
parsedToolCalls.push(toolRouter.parseToolCall(tc));
|
|
639
639
|
} catch (error) {
|
|
640
|
-
await appendToolResult({
|
|
640
|
+
await appendToolResult(uuid4(), {
|
|
641
641
|
threadId,
|
|
642
642
|
toolCallId: tc.id ?? "",
|
|
643
643
|
toolName: tc.name,
|
|
@@ -693,37 +693,12 @@ var createSession = async ({
|
|
|
693
693
|
}
|
|
694
694
|
};
|
|
695
695
|
};
|
|
696
|
-
function proxyDefaultThreadOps(options) {
|
|
697
|
-
return proxyActivities(
|
|
698
|
-
options ?? {
|
|
699
|
-
startToCloseTimeout: "10s",
|
|
700
|
-
retry: {
|
|
701
|
-
maximumAttempts: 6,
|
|
702
|
-
initialInterval: "5s",
|
|
703
|
-
maximumInterval: "15m",
|
|
704
|
-
backoffCoefficient: 4
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
|
-
function proxySandboxOps(options) {
|
|
710
|
-
return proxyActivities(
|
|
711
|
-
options ?? {
|
|
712
|
-
startToCloseTimeout: "30s",
|
|
713
|
-
retry: {
|
|
714
|
-
maximumAttempts: 3,
|
|
715
|
-
initialInterval: "2s",
|
|
716
|
-
maximumInterval: "30s",
|
|
717
|
-
backoffCoefficient: 2
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
);
|
|
721
|
-
}
|
|
722
696
|
|
|
723
697
|
// src/lib/workflow.ts
|
|
724
698
|
function defineWorkflow(config, fn) {
|
|
725
699
|
const workflow = async (input, workflowInput = {}) => {
|
|
726
700
|
const sessionInput = {
|
|
701
|
+
agentName: config.name,
|
|
727
702
|
...workflowInput.previousThreadId && {
|
|
728
703
|
threadId: workflowInput.previousThreadId,
|
|
729
704
|
continueThread: true
|
|
@@ -1484,6 +1459,6 @@ var createAskUserQuestionHandler = () => async (args) => {
|
|
|
1484
1459
|
};
|
|
1485
1460
|
};
|
|
1486
1461
|
|
|
1487
|
-
export { SandboxNotFoundError, SandboxNotSupportedError, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, filesWithMimeType, formatVirtualFileTree, getShortId, globTool, grepTool, hasDirectory, hasFileWithMimeType, hasNoOtherToolCalls, isTerminalStatus, parseSkillFile,
|
|
1462
|
+
export { SandboxNotFoundError, SandboxNotSupportedError, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineSubagentWorkflow, defineTool, defineWorkflow, editTool, filesWithMimeType, formatVirtualFileTree, getShortId, globTool, grepTool, hasDirectory, hasFileWithMimeType, hasNoOtherToolCalls, isTerminalStatus, parseSkillFile, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool };
|
|
1488
1463
|
//# sourceMappingURL=workflow.js.map
|
|
1489
1464
|
//# sourceMappingURL=workflow.js.map
|