zeitlich 0.2.11 → 0.2.13
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 +313 -126
- package/dist/adapters/langchain/index.cjs +270 -0
- package/dist/adapters/langchain/index.cjs.map +1 -0
- package/dist/adapters/langchain/index.d.cts +132 -0
- package/dist/adapters/langchain/index.d.ts +132 -0
- package/dist/adapters/langchain/index.js +265 -0
- package/dist/adapters/langchain/index.js.map +1 -0
- package/dist/index.cjs +89 -209
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -46
- package/dist/index.d.ts +62 -46
- package/dist/index.js +88 -208
- package/dist/index.js.map +1 -1
- package/dist/{workflow-BhjsEQc1.d.cts → model-invoker-y_zlyMqu.d.cts} +45 -482
- package/dist/{workflow-BhjsEQc1.d.ts → model-invoker-y_zlyMqu.d.ts} +45 -482
- package/dist/thread-manager-qc0g5Rvd.d.cts +39 -0
- package/dist/thread-manager-qc0g5Rvd.d.ts +39 -0
- package/dist/workflow.cjs +59 -27
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +459 -6
- package/dist/workflow.d.ts +459 -6
- package/dist/workflow.js +60 -29
- package/dist/workflow.js.map +1 -1
- package/package.json +17 -2
- package/src/adapters/langchain/activities.ts +120 -0
- package/src/adapters/langchain/index.ts +38 -0
- package/src/adapters/langchain/model-invoker.ts +102 -0
- package/src/adapters/langchain/thread-manager.ts +142 -0
- package/src/index.ts +24 -23
- package/src/lib/fs.ts +25 -0
- package/src/lib/model-invoker.ts +15 -75
- package/src/lib/session.ts +52 -21
- package/src/lib/state-manager.ts +23 -5
- package/src/lib/thread-id.ts +25 -0
- package/src/lib/thread-manager.ts +18 -142
- package/src/lib/tool-router.ts +12 -18
- package/src/lib/types.ts +26 -10
- package/src/lib/workflow-helpers.ts +50 -0
- package/src/tools/ask-user-question/handler.ts +25 -1
- package/src/tools/bash/handler.ts +13 -0
- package/src/tools/subagent/handler.ts +16 -5
- package/src/tools/subagent/tool.ts +34 -15
- package/src/workflow.ts +26 -7
- package/tsup.config.ts +1 -0
- package/src/activities.ts +0 -91
- package/src/plugin.ts +0 -28
package/dist/index.d.cts
CHANGED
|
@@ -1,60 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { GlobArgs, FileEditArgs, BashArgs } from './workflow.cjs';
|
|
2
|
+
export { AgentState, AgentStateManager, AskUserQuestionArgs, FileReadArgs, FileWriteArgs, GrepArgs, JsonPrimitive, JsonSerializable, JsonValue, ReadSkillArgs, SessionLifecycleHooks, TaskCreateArgs, TaskGetArgs, TaskListArgs, TaskUpdateArgs, ZeitlichSession, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, editTool, getShortId, globTool, grepTool, parseSkillFile, proxyDefaultThreadOps, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool } from './workflow.cjs';
|
|
3
|
+
import { M as ModelInvoker, R as RunAgentConfig, A as AgentResponse, b as ActivityToolHandler, S as SkillProvider, c as SkillMetadata, d as Skill } from './model-invoker-y_zlyMqu.cjs';
|
|
4
|
+
export { e as AgentConfig, f as AgentFile, g as AgentStatus, h as AppendToolResultFn, B as BaseAgentState, C as ContentPart, H as Hooks, I as InferToolResults, i as MessageContent, a as ModelInvokerConfig, P as ParsedToolCall, j as ParsedToolCallUnion, k as PostHumanMessageAppendHook, l as PostHumanMessageAppendHookContext, m as PostToolUseFailureHook, n as PostToolUseFailureHookContext, o as PostToolUseFailureHookResult, p as PostToolUseHook, q as PostToolUseHookContext, r as PreHumanMessageAppendHook, s as PreHumanMessageAppendHookContext, t as PreToolUseHook, u as PreToolUseHookContext, v as PreToolUseHookResult, w as ProcessToolCallsContext, x as RawToolCall, y as RunAgentActivity, z as SessionConfig, D as SessionEndHook, E as SessionEndHookContext, F as SessionExitReason, G as SessionStartHook, J as SessionStartHookContext, K as SubagentArgs, L as SubagentConfig, N as SubagentHooks, O as SubagentInput, Q as SubagentWorkflow, U as TaskStatus, T as ThreadOps, V as TokenUsage, W as ToolArgs, X as ToolCallResult, Y as ToolCallResultUnion, Z as ToolDefinition, _ as ToolHandler, $ as ToolHandlerContext, a0 as ToolHandlerResponse, a1 as ToolHooks, a2 as ToolMap, a3 as ToolMessageContent, a4 as ToolNames, a5 as ToolResult, a6 as ToolResultConfig, a7 as ToolRouter, a8 as ToolWithHandler, a9 as WorkflowTask, aa as agentQueryName, ab as agentStateChangeUpdateName, ac as createSubagentTool, ad as createToolRouter, ae as defineSubagent, af as defineTool, ag as hasNoOtherToolCalls, ah as isTerminalStatus, ai as withAutoAppend } from './model-invoker-y_zlyMqu.cjs';
|
|
5
|
+
export { B as BaseThreadManager, T as ThreadManagerConfig, c as createThreadManager } from './thread-manager-qc0g5Rvd.cjs';
|
|
5
6
|
import { WorkflowClient } from '@temporalio/client';
|
|
6
|
-
import { BaseChatModel, BaseChatModelCallOptions, BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
7
7
|
import { IFileSystem, BashOptions } from 'just-bash';
|
|
8
8
|
import '@temporalio/workflow';
|
|
9
|
-
import '@
|
|
9
|
+
import '@temporalio/common/lib/interfaces';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@temporalio/common';
|
|
12
|
-
import '
|
|
12
|
+
import 'ioredis';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @experimental The Zeitlich plugin is an experimental feature; APIs may change without notice.
|
|
15
|
+
* Query the parent workflow's state from within an activity.
|
|
16
|
+
* Resolves the workflow handle from the current activity context.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
redis: Redis;
|
|
21
|
-
}
|
|
18
|
+
declare function queryParentWorkflowState<T>(client: WorkflowClient, queryName: string): Promise<T>;
|
|
22
19
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Workflow-specific activities (like runAgent) should be created separately.
|
|
20
|
+
* Wraps a `ModelInvoker` into a `RunAgentActivity` by automatically
|
|
21
|
+
* loading tool definitions from the parent workflow state via query.
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Configuration for invoking the model
|
|
35
|
-
*/
|
|
36
|
-
interface InvokeModelConfig {
|
|
37
|
-
threadId: string;
|
|
38
|
-
agentName: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Core model invocation logic - shared utility for workflow-specific activities
|
|
23
|
+
* This is the generic bridge between any provider-specific model invoker
|
|
24
|
+
* and the session's `runAgent` contract.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { createRunAgentActivity } from 'zeitlich';
|
|
29
|
+
* import { createLangChainModelInvoker } from 'zeitlich/adapters/langchain';
|
|
42
30
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @param options.model - Pre-instantiated LangChain chat model
|
|
47
|
-
* @param options.client - Temporal WorkflowClient for querying workflow state
|
|
48
|
-
* @returns Agent response with message and metadata
|
|
31
|
+
* const invoker = createLangChainModelInvoker({ redis, model });
|
|
32
|
+
* return { runAgent: createRunAgentActivity(client, invoker) };
|
|
33
|
+
* ```
|
|
49
34
|
*/
|
|
50
|
-
declare function
|
|
51
|
-
redis: Redis;
|
|
52
|
-
client: WorkflowClient;
|
|
53
|
-
config: InvokeModelConfig;
|
|
54
|
-
model: BaseChatModel<BaseChatModelCallOptions & {
|
|
55
|
-
tools?: BindToolsInput;
|
|
56
|
-
}>;
|
|
57
|
-
}): Promise<AgentResponse>;
|
|
35
|
+
declare function createRunAgentActivity<M>(client: WorkflowClient, invoker: ModelInvoker<M>): (config: RunAgentConfig) => Promise<AgentResponse<M>>;
|
|
58
36
|
|
|
59
37
|
/**
|
|
60
38
|
* Result of a glob operation
|
|
@@ -93,8 +71,46 @@ type BashExecOut = {
|
|
|
93
71
|
};
|
|
94
72
|
/** BashOptions with `fs` required */
|
|
95
73
|
type BashToolOptions = Required<Pick<BashOptions, "fs">> & Omit<BashOptions, "fs">;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a Bash tool handler that executes shell commands in a sandboxed environment.
|
|
76
|
+
*
|
|
77
|
+
* @param bashOptions - Options including a required `fs` (file system implementation from `just-bash`)
|
|
78
|
+
* @returns Activity tool handler for Bash tool calls
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { createBashHandler } from 'zeitlich';
|
|
83
|
+
*
|
|
84
|
+
* const bashHandlerActivity = createBashHandler({ fs: inMemoryFileSystem });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
96
87
|
declare const createBashHandler: (bashOptions: BashToolOptions) => ActivityToolHandler<BashArgs, BashExecOut | null>;
|
|
97
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Generates a formatted file tree string from an `IFileSystem` instance.
|
|
91
|
+
* Useful for including filesystem context in agent prompts.
|
|
92
|
+
*
|
|
93
|
+
* @param fs - File system implementation (e.g. from `just-bash`)
|
|
94
|
+
* @param opts - Optional configuration for tree generation
|
|
95
|
+
* @param opts.dir - Root directory to start from (defaults to `/`)
|
|
96
|
+
* @param opts.separator - Path separator (`/` or `\\`, defaults to `/`)
|
|
97
|
+
* @param opts.depth - Maximum directory depth (defaults to 10)
|
|
98
|
+
* @param opts.sort - Sort entries alphabetically with directories first (defaults to true)
|
|
99
|
+
* @returns Formatted file tree string
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { toTree } from 'zeitlich';
|
|
104
|
+
*
|
|
105
|
+
* const fileTree = await toTree(inMemoryFileSystem);
|
|
106
|
+
* // Returns:
|
|
107
|
+
* // /
|
|
108
|
+
* // ├─ src/
|
|
109
|
+
* // │ ├─ index.ts
|
|
110
|
+
* // │ └─ utils.ts
|
|
111
|
+
* // └─ package.json
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
98
114
|
declare const toTree: (fs: IFileSystem, opts?: {
|
|
99
115
|
dir?: string;
|
|
100
116
|
separator?: "/" | "\\";
|
|
@@ -129,4 +145,4 @@ declare class FileSystemSkillProvider implements SkillProvider {
|
|
|
129
145
|
private discoverSkillDirs;
|
|
130
146
|
}
|
|
131
147
|
|
|
132
|
-
export { ActivityToolHandler, AgentResponse, BashArgs, FileEditArgs, FileSystemSkillProvider, GlobArgs,
|
|
148
|
+
export { ActivityToolHandler, AgentResponse, BashArgs, FileEditArgs, FileSystemSkillProvider, GlobArgs, ModelInvoker, RunAgentConfig, Skill, SkillMetadata, SkillProvider, createBashHandler, createEditHandler, createGlobHandler, createRunAgentActivity, queryParentWorkflowState, toTree };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,60 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { GlobArgs, FileEditArgs, BashArgs } from './workflow.js';
|
|
2
|
+
export { AgentState, AgentStateManager, AskUserQuestionArgs, FileReadArgs, FileWriteArgs, GrepArgs, JsonPrimitive, JsonSerializable, JsonValue, ReadSkillArgs, SessionLifecycleHooks, TaskCreateArgs, TaskGetArgs, TaskListArgs, TaskUpdateArgs, ZeitlichSession, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, editTool, getShortId, globTool, grepTool, parseSkillFile, proxyDefaultThreadOps, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool } from './workflow.js';
|
|
3
|
+
import { M as ModelInvoker, R as RunAgentConfig, A as AgentResponse, b as ActivityToolHandler, S as SkillProvider, c as SkillMetadata, d as Skill } from './model-invoker-y_zlyMqu.js';
|
|
4
|
+
export { e as AgentConfig, f as AgentFile, g as AgentStatus, h as AppendToolResultFn, B as BaseAgentState, C as ContentPart, H as Hooks, I as InferToolResults, i as MessageContent, a as ModelInvokerConfig, P as ParsedToolCall, j as ParsedToolCallUnion, k as PostHumanMessageAppendHook, l as PostHumanMessageAppendHookContext, m as PostToolUseFailureHook, n as PostToolUseFailureHookContext, o as PostToolUseFailureHookResult, p as PostToolUseHook, q as PostToolUseHookContext, r as PreHumanMessageAppendHook, s as PreHumanMessageAppendHookContext, t as PreToolUseHook, u as PreToolUseHookContext, v as PreToolUseHookResult, w as ProcessToolCallsContext, x as RawToolCall, y as RunAgentActivity, z as SessionConfig, D as SessionEndHook, E as SessionEndHookContext, F as SessionExitReason, G as SessionStartHook, J as SessionStartHookContext, K as SubagentArgs, L as SubagentConfig, N as SubagentHooks, O as SubagentInput, Q as SubagentWorkflow, U as TaskStatus, T as ThreadOps, V as TokenUsage, W as ToolArgs, X as ToolCallResult, Y as ToolCallResultUnion, Z as ToolDefinition, _ as ToolHandler, $ as ToolHandlerContext, a0 as ToolHandlerResponse, a1 as ToolHooks, a2 as ToolMap, a3 as ToolMessageContent, a4 as ToolNames, a5 as ToolResult, a6 as ToolResultConfig, a7 as ToolRouter, a8 as ToolWithHandler, a9 as WorkflowTask, aa as agentQueryName, ab as agentStateChangeUpdateName, ac as createSubagentTool, ad as createToolRouter, ae as defineSubagent, af as defineTool, ag as hasNoOtherToolCalls, ah as isTerminalStatus, ai as withAutoAppend } from './model-invoker-y_zlyMqu.js';
|
|
5
|
+
export { B as BaseThreadManager, T as ThreadManagerConfig, c as createThreadManager } from './thread-manager-qc0g5Rvd.js';
|
|
5
6
|
import { WorkflowClient } from '@temporalio/client';
|
|
6
|
-
import { BaseChatModel, BaseChatModelCallOptions, BindToolsInput } from '@langchain/core/language_models/chat_models';
|
|
7
7
|
import { IFileSystem, BashOptions } from 'just-bash';
|
|
8
8
|
import '@temporalio/workflow';
|
|
9
|
-
import '@
|
|
9
|
+
import '@temporalio/common/lib/interfaces';
|
|
10
10
|
import 'zod';
|
|
11
11
|
import '@temporalio/common';
|
|
12
|
-
import '
|
|
12
|
+
import 'ioredis';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @experimental The Zeitlich plugin is an experimental feature; APIs may change without notice.
|
|
15
|
+
* Query the parent workflow's state from within an activity.
|
|
16
|
+
* Resolves the workflow handle from the current activity context.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
redis: Redis;
|
|
21
|
-
}
|
|
18
|
+
declare function queryParentWorkflowState<T>(client: WorkflowClient, queryName: string): Promise<T>;
|
|
22
19
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Workflow-specific activities (like runAgent) should be created separately.
|
|
20
|
+
* Wraps a `ModelInvoker` into a `RunAgentActivity` by automatically
|
|
21
|
+
* loading tool definitions from the parent workflow state via query.
|
|
26
22
|
*
|
|
27
|
-
*
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* Configuration for invoking the model
|
|
35
|
-
*/
|
|
36
|
-
interface InvokeModelConfig {
|
|
37
|
-
threadId: string;
|
|
38
|
-
agentName: string;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Core model invocation logic - shared utility for workflow-specific activities
|
|
23
|
+
* This is the generic bridge between any provider-specific model invoker
|
|
24
|
+
* and the session's `runAgent` contract.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { createRunAgentActivity } from 'zeitlich';
|
|
29
|
+
* import { createLangChainModelInvoker } from 'zeitlich/adapters/langchain';
|
|
42
30
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @param options.model - Pre-instantiated LangChain chat model
|
|
47
|
-
* @param options.client - Temporal WorkflowClient for querying workflow state
|
|
48
|
-
* @returns Agent response with message and metadata
|
|
31
|
+
* const invoker = createLangChainModelInvoker({ redis, model });
|
|
32
|
+
* return { runAgent: createRunAgentActivity(client, invoker) };
|
|
33
|
+
* ```
|
|
49
34
|
*/
|
|
50
|
-
declare function
|
|
51
|
-
redis: Redis;
|
|
52
|
-
client: WorkflowClient;
|
|
53
|
-
config: InvokeModelConfig;
|
|
54
|
-
model: BaseChatModel<BaseChatModelCallOptions & {
|
|
55
|
-
tools?: BindToolsInput;
|
|
56
|
-
}>;
|
|
57
|
-
}): Promise<AgentResponse>;
|
|
35
|
+
declare function createRunAgentActivity<M>(client: WorkflowClient, invoker: ModelInvoker<M>): (config: RunAgentConfig) => Promise<AgentResponse<M>>;
|
|
58
36
|
|
|
59
37
|
/**
|
|
60
38
|
* Result of a glob operation
|
|
@@ -93,8 +71,46 @@ type BashExecOut = {
|
|
|
93
71
|
};
|
|
94
72
|
/** BashOptions with `fs` required */
|
|
95
73
|
type BashToolOptions = Required<Pick<BashOptions, "fs">> & Omit<BashOptions, "fs">;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a Bash tool handler that executes shell commands in a sandboxed environment.
|
|
76
|
+
*
|
|
77
|
+
* @param bashOptions - Options including a required `fs` (file system implementation from `just-bash`)
|
|
78
|
+
* @returns Activity tool handler for Bash tool calls
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { createBashHandler } from 'zeitlich';
|
|
83
|
+
*
|
|
84
|
+
* const bashHandlerActivity = createBashHandler({ fs: inMemoryFileSystem });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
96
87
|
declare const createBashHandler: (bashOptions: BashToolOptions) => ActivityToolHandler<BashArgs, BashExecOut | null>;
|
|
97
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Generates a formatted file tree string from an `IFileSystem` instance.
|
|
91
|
+
* Useful for including filesystem context in agent prompts.
|
|
92
|
+
*
|
|
93
|
+
* @param fs - File system implementation (e.g. from `just-bash`)
|
|
94
|
+
* @param opts - Optional configuration for tree generation
|
|
95
|
+
* @param opts.dir - Root directory to start from (defaults to `/`)
|
|
96
|
+
* @param opts.separator - Path separator (`/` or `\\`, defaults to `/`)
|
|
97
|
+
* @param opts.depth - Maximum directory depth (defaults to 10)
|
|
98
|
+
* @param opts.sort - Sort entries alphabetically with directories first (defaults to true)
|
|
99
|
+
* @returns Formatted file tree string
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* import { toTree } from 'zeitlich';
|
|
104
|
+
*
|
|
105
|
+
* const fileTree = await toTree(inMemoryFileSystem);
|
|
106
|
+
* // Returns:
|
|
107
|
+
* // /
|
|
108
|
+
* // ├─ src/
|
|
109
|
+
* // │ ├─ index.ts
|
|
110
|
+
* // │ └─ utils.ts
|
|
111
|
+
* // └─ package.json
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
98
114
|
declare const toTree: (fs: IFileSystem, opts?: {
|
|
99
115
|
dir?: string;
|
|
100
116
|
separator?: "/" | "\\";
|
|
@@ -129,4 +145,4 @@ declare class FileSystemSkillProvider implements SkillProvider {
|
|
|
129
145
|
private discoverSkillDirs;
|
|
130
146
|
}
|
|
131
147
|
|
|
132
|
-
export { ActivityToolHandler, AgentResponse, BashArgs, FileEditArgs, FileSystemSkillProvider, GlobArgs,
|
|
148
|
+
export { ActivityToolHandler, AgentResponse, BashArgs, FileEditArgs, FileSystemSkillProvider, GlobArgs, ModelInvoker, RunAgentConfig, Skill, SkillMetadata, SkillProvider, createBashHandler, createEditHandler, createGlobHandler, createRunAgentActivity, queryParentWorkflowState, toTree };
|