zeitlich 0.2.13 → 0.2.14
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 +49 -38
- package/dist/adapters/sandbox/daytona/index.cjs +205 -0
- package/dist/adapters/sandbox/daytona/index.cjs.map +1 -0
- package/dist/adapters/sandbox/daytona/index.d.cts +86 -0
- package/dist/adapters/sandbox/daytona/index.d.ts +86 -0
- package/dist/adapters/sandbox/daytona/index.js +202 -0
- package/dist/adapters/sandbox/daytona/index.js.map +1 -0
- package/dist/adapters/sandbox/inmemory/index.cjs +174 -0
- package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -0
- package/dist/adapters/sandbox/inmemory/index.d.cts +28 -0
- package/dist/adapters/sandbox/inmemory/index.d.ts +28 -0
- package/dist/adapters/sandbox/inmemory/index.js +172 -0
- package/dist/adapters/sandbox/inmemory/index.js.map +1 -0
- package/dist/adapters/sandbox/virtual/index.cjs +405 -0
- package/dist/adapters/sandbox/virtual/index.cjs.map +1 -0
- package/dist/adapters/sandbox/virtual/index.d.cts +85 -0
- package/dist/adapters/sandbox/virtual/index.d.ts +85 -0
- package/dist/adapters/sandbox/virtual/index.js +400 -0
- package/dist/adapters/sandbox/virtual/index.js.map +1 -0
- package/dist/adapters/thread/google-genai/index.cjs +284 -0
- package/dist/adapters/thread/google-genai/index.cjs.map +1 -0
- package/dist/adapters/thread/google-genai/index.d.cts +145 -0
- package/dist/adapters/thread/google-genai/index.d.ts +145 -0
- package/dist/adapters/thread/google-genai/index.js +278 -0
- package/dist/adapters/thread/google-genai/index.js.map +1 -0
- package/dist/adapters/{langchain → thread/langchain}/index.cjs +7 -9
- package/dist/adapters/thread/langchain/index.cjs.map +1 -0
- package/dist/adapters/{langchain → thread/langchain}/index.d.cts +17 -21
- package/dist/adapters/{langchain → thread/langchain}/index.d.ts +17 -21
- package/dist/adapters/{langchain → thread/langchain}/index.js +7 -9
- package/dist/adapters/thread/langchain/index.js.map +1 -0
- package/dist/index.cjs +816 -545
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +235 -74
- package/dist/index.d.ts +235 -74
- package/dist/index.js +804 -540
- package/dist/index.js.map +1 -1
- package/dist/types-B4C9txdq.d.ts +389 -0
- package/dist/{thread-manager-qc0g5Rvd.d.cts → types-B9ljZewB.d.cts} +1 -6
- package/dist/{thread-manager-qc0g5Rvd.d.ts → types-B9ljZewB.d.ts} +1 -6
- package/dist/types-BMXzv7TN.d.cts +476 -0
- package/dist/types-BMXzv7TN.d.ts +476 -0
- package/dist/types-BVP87m_W.d.cts +121 -0
- package/dist/types-CDubRtad.d.cts +115 -0
- package/dist/types-CDubRtad.d.ts +115 -0
- package/dist/types-CwwgQ_9H.d.ts +121 -0
- package/dist/types-GpMU4b0w.d.cts +389 -0
- package/dist/workflow.cjs +444 -318
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +271 -222
- package/dist/workflow.d.ts +271 -222
- package/dist/workflow.js +440 -316
- package/dist/workflow.js.map +1 -1
- package/package.json +59 -6
- package/src/adapters/sandbox/daytona/filesystem.ts +136 -0
- package/src/adapters/sandbox/daytona/index.ts +149 -0
- package/src/adapters/sandbox/daytona/types.ts +34 -0
- package/src/adapters/sandbox/inmemory/index.ts +213 -0
- package/src/adapters/sandbox/virtual/filesystem.ts +345 -0
- package/src/adapters/sandbox/virtual/index.ts +88 -0
- package/src/adapters/sandbox/virtual/mutations.ts +38 -0
- package/src/adapters/sandbox/virtual/provider.ts +101 -0
- package/src/adapters/sandbox/virtual/tree.ts +82 -0
- package/src/adapters/sandbox/virtual/types.ts +127 -0
- package/src/adapters/sandbox/virtual/virtual-sandbox.test.ts +523 -0
- package/src/adapters/sandbox/virtual/with-virtual-sandbox.ts +91 -0
- package/src/adapters/thread/google-genai/activities.ts +121 -0
- package/src/adapters/thread/google-genai/index.ts +41 -0
- package/src/adapters/thread/google-genai/model-invoker.ts +154 -0
- package/src/adapters/thread/google-genai/thread-manager.ts +169 -0
- package/src/adapters/{langchain → thread/langchain}/activities.ts +11 -15
- package/src/adapters/{langchain → thread/langchain}/index.ts +1 -1
- package/src/adapters/{langchain → thread/langchain}/model-invoker.ts +15 -18
- package/src/adapters/{langchain → thread/langchain}/thread-manager.ts +1 -1
- package/src/index.ts +32 -24
- package/src/lib/activity.ts +87 -0
- package/src/lib/hooks/index.ts +11 -0
- package/src/lib/hooks/types.ts +98 -0
- package/src/lib/model/helpers.ts +6 -0
- package/src/lib/model/index.ts +13 -0
- package/src/lib/{model-invoker.ts → model/types.ts} +18 -1
- package/src/lib/sandbox/index.ts +19 -0
- package/src/lib/sandbox/manager.ts +76 -0
- package/src/lib/sandbox/sandbox.test.ts +158 -0
- package/src/lib/{fs.ts → sandbox/tree.ts} +6 -6
- package/src/lib/sandbox/types.ts +164 -0
- package/src/lib/session/index.ts +11 -0
- package/src/lib/{session.ts → session/session.ts} +76 -48
- package/src/lib/session/types.ts +93 -0
- package/src/lib/skills/fs-provider.ts +16 -15
- package/src/lib/skills/handler.ts +31 -0
- package/src/lib/skills/index.ts +5 -1
- package/src/lib/skills/register.ts +20 -0
- package/src/lib/skills/tool.ts +47 -0
- package/src/lib/state/index.ts +9 -0
- package/src/lib/{state-manager.ts → state/manager.ts} +10 -147
- package/src/lib/state/types.ts +134 -0
- package/src/lib/subagent/define.ts +71 -0
- package/src/lib/subagent/handler.ts +99 -0
- package/src/lib/subagent/index.ts +13 -0
- package/src/lib/subagent/register.ts +53 -0
- package/src/lib/subagent/tool.ts +80 -0
- package/src/lib/subagent/types.ts +92 -0
- package/src/lib/thread/index.ts +7 -0
- package/src/lib/{thread-manager.ts → thread/manager.ts} +1 -33
- package/src/lib/thread/types.ts +33 -0
- package/src/lib/tool-router/auto-append.ts +55 -0
- package/src/lib/tool-router/index.ts +41 -0
- package/src/lib/tool-router/router.ts +462 -0
- package/src/lib/tool-router/types.ts +478 -0
- package/src/lib/tool-router/with-sandbox.ts +70 -0
- package/src/lib/types.ts +5 -382
- package/src/tools/bash/bash.test.ts +53 -55
- package/src/tools/bash/handler.ts +23 -51
- package/src/tools/edit/handler.ts +67 -81
- package/src/tools/glob/handler.ts +60 -17
- package/src/tools/read-file/handler.ts +67 -0
- package/src/tools/read-skill/handler.ts +1 -31
- package/src/tools/read-skill/tool.ts +5 -47
- package/src/tools/subagent/handler.ts +1 -100
- package/src/tools/subagent/tool.ts +5 -93
- package/src/tools/task-create/handler.ts +1 -1
- package/src/tools/task-get/handler.ts +1 -1
- package/src/tools/task-list/handler.ts +1 -1
- package/src/tools/task-update/handler.ts +1 -1
- package/src/tools/write-file/handler.ts +47 -0
- package/src/workflow.ts +88 -47
- package/tsup.config.ts +8 -1
- package/dist/adapters/langchain/index.cjs.map +0 -1
- package/dist/adapters/langchain/index.js.map +0 -1
- package/dist/model-invoker-y_zlyMqu.d.cts +0 -892
- package/dist/model-invoker-y_zlyMqu.d.ts +0 -892
- package/src/lib/tool-router.ts +0 -977
- package/src/lib/workflow-helpers.ts +0 -50
- /package/src/lib/{thread-id.ts → thread/id.ts} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,96 +1,283 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
|
|
1
|
+
import { BashArgs, FileEditArgs, GlobArgs, FileReadArgs, FileWriteArgs } from './workflow.js';
|
|
2
|
+
export { AskUserQuestionArgs, GrepArgs, ReadSkillArgs, SubagentArgs, TaskCreateArgs, TaskGetArgs, TaskListArgs, TaskUpdateArgs, applyVirtualTreeMutations, askUserQuestionTool, bashTool, createAgentStateManager, createAskUserQuestionHandler, createBashToolDescription, createReadSkillHandler, createReadSkillTool, createSession, createTaskCreateHandler, createTaskGetHandler, createTaskListHandler, createTaskUpdateHandler, createToolRouter, defineSubagent, defineTool, editTool, formatVirtualFileTree, getShortId, globTool, grepTool, hasNoOtherToolCalls, parseSkillFile, proxyDefaultThreadOps, proxySandboxOps, readFileTool, taskCreateTool, taskGetTool, taskListTool, taskUpdateTool, writeFileTool } from './workflow.js';
|
|
3
|
+
import { S as SkillProvider, b as SkillMetadata, c as Skill } from './types-B4C9txdq.js';
|
|
4
|
+
export { A as AgentResponse, d as AgentState, e as AgentStateManager, H as Hooks, J as JsonPrimitive, f as JsonSerializable, g as JsonValue, M as ModelInvoker, a as ModelInvokerConfig, P as PostHumanMessageAppendHook, h as PostHumanMessageAppendHookContext, i as PreHumanMessageAppendHook, j as PreHumanMessageAppendHookContext, R as RunAgentActivity, k as SessionConfig, l as SessionEndHook, m as SessionEndHookContext, n as SessionStartHook, o as SessionStartHookContext, p as SubagentConfig, q as SubagentHandlerResponse, r as SubagentHooks, s as SubagentInput, t as SubagentWorkflow, T as ThreadOps, Z as ZeitlichSession } from './types-B4C9txdq.js';
|
|
5
|
+
import { T as ThreadManagerConfig, B as BaseThreadManager } from './types-B9ljZewB.js';
|
|
6
|
+
import { R as RouterContext, j as ToolResultConfig, A as ActivityToolHandler, c as ToolHandlerResponse, B as BaseAgentState, g as RunAgentConfig } from './types-BMXzv7TN.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, p as ParsedToolCallUnion, 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, x as SerializableToolDefinition, S as SessionExitReason, y as TaskStatus, f as TokenUsage, z as ToolArgs, D as ToolCallResult, k as ToolCallResultUnion, i as ToolDefinition, E as ToolHandler, F as ToolHooks, a as ToolMap, T as ToolMessageContent, G as ToolNames, H as ToolResult, J as ToolRouter, b as ToolRouterHooks, K as ToolWithHandler, W as WorkflowTask, L as isTerminalStatus } from './types-BMXzv7TN.js';
|
|
8
|
+
import { S as Sandbox, a as SandboxFileSystem, d as SandboxCreateOptions, b as SandboxProvider, f as SandboxSnapshot, g as SandboxOps, E as ExecResult } from './types-CDubRtad.js';
|
|
9
|
+
export { h as ExecOptions, c as SandboxCapabilities, e as SandboxCreateResult, D as SandboxDirentEntry, F as SandboxFileStat, i as SandboxNotFoundError, j as SandboxNotSupportedError } from './types-CDubRtad.js';
|
|
6
10
|
import { WorkflowClient } from '@temporalio/client';
|
|
7
|
-
|
|
11
|
+
export { c as FileEntry, F as FileEntryMetadata, a as FileResolver, T as TreeMutation, e as VirtualFileTree, g as VirtualSandboxState } from './types-CwwgQ_9H.js';
|
|
8
12
|
import '@temporalio/workflow';
|
|
9
|
-
import '@temporalio/common/lib/interfaces';
|
|
10
13
|
import 'zod';
|
|
11
14
|
import '@temporalio/common';
|
|
15
|
+
import '@temporalio/common/lib/interfaces';
|
|
12
16
|
import 'ioredis';
|
|
13
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Creates a generic thread manager for handling conversation state in Redis.
|
|
20
|
+
* Framework-agnostic — works with any serializable message type.
|
|
21
|
+
*/
|
|
22
|
+
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wraps a tool handler to automatically append its result directly to the
|
|
26
|
+
* thread and sets `resultAppended: true` on the response.
|
|
27
|
+
*
|
|
28
|
+
* Use this for tools whose responses may exceed Temporal's activity payload
|
|
29
|
+
* limit. The wrapper appends to the thread inside the activity (where Redis
|
|
30
|
+
* is available), then replaces `toolResponse` with an empty string so the
|
|
31
|
+
* large payload never travels through the Temporal workflow boundary.
|
|
32
|
+
*
|
|
33
|
+
* @param getThread - Factory that returns a thread manager for the given threadId
|
|
34
|
+
* @param handler - The original tool handler
|
|
35
|
+
* @returns A wrapped handler that auto-appends and flags the response
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { withAutoAppend } from '@bead-ai/zeitlich/workflow';
|
|
40
|
+
* import { createThreadManager } from '@bead-ai/zeitlich';
|
|
41
|
+
*
|
|
42
|
+
* const handler = withAutoAppend(
|
|
43
|
+
* (threadId) => createThreadManager({ redis, threadId }),
|
|
44
|
+
* async (args, ctx) => ({
|
|
45
|
+
* toolResponse: JSON.stringify(largeResult), // appended directly to Redis
|
|
46
|
+
* data: { summary: "..." }, // small data for workflow
|
|
47
|
+
* }),
|
|
48
|
+
* );
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare function withAutoAppend<TArgs, TResult, TContext extends RouterContext = RouterContext>(threadHandler: (config: ToolResultConfig) => Promise<void>, handler: ActivityToolHandler<TArgs, TResult, TContext>): ActivityToolHandler<TArgs, TResult, TContext>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Extended router context with a resolved {@link Sandbox} instance.
|
|
55
|
+
*
|
|
56
|
+
* Handlers typed with this context are guaranteed to have a live sandbox
|
|
57
|
+
* and a non-optional `sandboxId`. Use with {@link withSandbox} to
|
|
58
|
+
* automatically resolve the sandbox from the manager.
|
|
59
|
+
*/
|
|
60
|
+
interface SandboxContext extends RouterContext {
|
|
61
|
+
sandbox: Sandbox;
|
|
62
|
+
sandboxId: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Wraps a tool handler that requires a {@link Sandbox}, automatically
|
|
66
|
+
* resolving it from the manager via the `sandboxId` on the router context.
|
|
67
|
+
*
|
|
68
|
+
* If no `sandboxId` is present the wrapper short-circuits with an error
|
|
69
|
+
* response and `data: null`, so the inner handler never runs without a
|
|
70
|
+
* valid sandbox.
|
|
71
|
+
*
|
|
72
|
+
* The sandbox type parameter `TSandbox` is inferred from the manager's
|
|
73
|
+
* `getSandbox` return type, allowing handlers to receive provider-specific
|
|
74
|
+
* sandbox subtypes (e.g. `DaytonaSandbox`) without manual casting.
|
|
75
|
+
*
|
|
76
|
+
* @param manager - Any object with a `getSandbox` method (e.g. {@link SandboxManager})
|
|
77
|
+
* @param handler - The inner handler that expects a sandbox context
|
|
78
|
+
* @returns A standard `ActivityToolHandler` that can be registered on the router
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* import { withSandbox, type SandboxContext } from 'zeitlich';
|
|
83
|
+
*
|
|
84
|
+
* // Generic sandbox — works with any provider:
|
|
85
|
+
* const bashHandler: ActivityToolHandler<BashArgs, ExecResult, SandboxContext> =
|
|
86
|
+
* async (args, { sandbox }) => {
|
|
87
|
+
* const result = await sandbox.exec(args.command);
|
|
88
|
+
* return { toolResponse: result.stdout, data: result };
|
|
89
|
+
* };
|
|
90
|
+
* const handler = withSandbox(manager, bashHandler);
|
|
91
|
+
*
|
|
92
|
+
* // Provider-specific sandbox — use SandboxManager<DaytonaSandbox>:
|
|
93
|
+
* const daytonaManager = new SandboxManager<DaytonaSandbox>(provider);
|
|
94
|
+
* const handler2 = withSandbox(daytonaManager, async (args, { sandbox }) => {
|
|
95
|
+
* // sandbox is typed as DaytonaSandbox here
|
|
96
|
+
* await sandbox.fs.uploadFiles([...]);
|
|
97
|
+
* return { toolResponse: 'ok', data: null };
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
declare function withSandbox<TArgs, TResult, TSandbox extends Sandbox = Sandbox>(manager: {
|
|
102
|
+
getSandbox(id: string): Promise<TSandbox>;
|
|
103
|
+
}, handler: (args: TArgs, context: RouterContext & {
|
|
104
|
+
sandbox: TSandbox;
|
|
105
|
+
sandboxId: string;
|
|
106
|
+
}) => Promise<ToolHandlerResponse<TResult>>): ActivityToolHandler<TArgs, TResult | null>;
|
|
107
|
+
|
|
14
108
|
/**
|
|
15
109
|
* Query the parent workflow's state from within an activity.
|
|
16
110
|
* Resolves the workflow handle from the current activity context.
|
|
17
111
|
*/
|
|
18
|
-
declare function queryParentWorkflowState<T>(client: WorkflowClient
|
|
112
|
+
declare function queryParentWorkflowState<T>(client: WorkflowClient): Promise<T>;
|
|
19
113
|
/**
|
|
20
|
-
* Wraps a
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* This is the generic bridge between any provider-specific model invoker
|
|
24
|
-
* and the session's `runAgent` contract.
|
|
114
|
+
* Wraps a handler into a `RunAgentActivity` by auto-fetching the parent
|
|
115
|
+
* workflow's agent state before each invocation.
|
|
25
116
|
*
|
|
26
117
|
* @example
|
|
27
118
|
* ```typescript
|
|
28
119
|
* import { createRunAgentActivity } from 'zeitlich';
|
|
29
|
-
* import { createLangChainModelInvoker } from 'zeitlich/adapters/langchain';
|
|
120
|
+
* import { createLangChainModelInvoker } from 'zeitlich/adapters/thread/langchain';
|
|
30
121
|
*
|
|
31
122
|
* const invoker = createLangChainModelInvoker({ redis, model });
|
|
32
123
|
* return { runAgent: createRunAgentActivity(client, invoker) };
|
|
33
124
|
* ```
|
|
34
125
|
*/
|
|
35
|
-
declare function createRunAgentActivity<
|
|
126
|
+
declare function createRunAgentActivity<R, S extends BaseAgentState = BaseAgentState>(client: WorkflowClient, handler: (config: RunAgentConfig & {
|
|
127
|
+
state: S;
|
|
128
|
+
}) => Promise<R>): (config: RunAgentConfig) => Promise<R>;
|
|
129
|
+
/**
|
|
130
|
+
* Context injected into tool handlers created via {@link withParentWorkflowState}.
|
|
131
|
+
*/
|
|
132
|
+
interface AgentStateContext<S extends BaseAgentState = BaseAgentState> extends RouterContext {
|
|
133
|
+
state: S;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Wraps a tool handler into an `ActivityToolHandler` by auto-fetching the
|
|
137
|
+
* parent workflow's agent state before each invocation.
|
|
138
|
+
*
|
|
139
|
+
* @typeParam S - Custom agent state type (defaults to `BaseAgentState`)
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* import { withParentWorkflowState, type AgentStateContext } from 'zeitlich';
|
|
144
|
+
*
|
|
145
|
+
* // With custom state:
|
|
146
|
+
* interface MyState extends BaseAgentState { customField: string }
|
|
147
|
+
* const myHandler = withParentWorkflowState<MyArgs, MyResult, MyState>(
|
|
148
|
+
* client,
|
|
149
|
+
* async (args, ctx) => {
|
|
150
|
+
* console.log(ctx.state.customField);
|
|
151
|
+
* return { toolResponse: 'done', data: null };
|
|
152
|
+
* },
|
|
153
|
+
* );
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
declare function withParentWorkflowState<TArgs, TResult, S extends BaseAgentState = BaseAgentState>(client: WorkflowClient, handler: (args: TArgs, context: AgentStateContext<S>) => Promise<ToolHandlerResponse<TResult>>): ActivityToolHandler<TArgs, TResult>;
|
|
36
157
|
|
|
37
158
|
/**
|
|
38
|
-
*
|
|
159
|
+
* Loads skills from a directory following the agentskills.io layout:
|
|
160
|
+
*
|
|
161
|
+
* ```
|
|
162
|
+
* skills/
|
|
163
|
+
* ├── code-review/
|
|
164
|
+
* │ └── SKILL.md
|
|
165
|
+
* ├── pdf-processing/
|
|
166
|
+
* │ └── SKILL.md
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* Uses the sandbox filesystem abstraction — works with any backend
|
|
170
|
+
* (in-memory, host FS, Wasmer, Daytona, etc.).
|
|
39
171
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
172
|
+
declare class FileSystemSkillProvider implements SkillProvider {
|
|
173
|
+
private readonly fs;
|
|
174
|
+
private readonly baseDir;
|
|
175
|
+
constructor(fs: SandboxFileSystem, baseDir: string);
|
|
176
|
+
listSkills(): Promise<SkillMetadata[]>;
|
|
177
|
+
getSkill(name: string): Promise<Skill>;
|
|
178
|
+
/**
|
|
179
|
+
* Convenience method to load all skills with full instructions.
|
|
180
|
+
* Returns `Skill[]` ready to pass into a workflow.
|
|
181
|
+
*/
|
|
182
|
+
loadAll(): Promise<Skill[]>;
|
|
183
|
+
private discoverSkillDirs;
|
|
42
184
|
}
|
|
185
|
+
|
|
43
186
|
/**
|
|
44
|
-
*
|
|
187
|
+
* Stateless facade over a {@link SandboxProvider}.
|
|
45
188
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
189
|
+
* Delegates all lifecycle operations to the provider, which is responsible
|
|
190
|
+
* for its own instance management strategy (e.g. in-memory map, remote API).
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* const manager = new SandboxManager(new InMemorySandboxProvider());
|
|
195
|
+
* const activities = {
|
|
196
|
+
* ...manager.createActivities(),
|
|
197
|
+
* bashHandler: withSandbox(manager, bashHandler),
|
|
198
|
+
* };
|
|
199
|
+
* ```
|
|
48
200
|
*/
|
|
49
|
-
declare
|
|
201
|
+
declare class SandboxManager<TOptions extends SandboxCreateOptions = SandboxCreateOptions, TSandbox extends Sandbox = Sandbox> {
|
|
202
|
+
private provider;
|
|
203
|
+
constructor(provider: SandboxProvider<TOptions, TSandbox>);
|
|
204
|
+
create(options?: TOptions): Promise<{
|
|
205
|
+
sandboxId: string;
|
|
206
|
+
stateUpdate?: Record<string, unknown>;
|
|
207
|
+
}>;
|
|
208
|
+
getSandbox(id: string): Promise<TSandbox>;
|
|
209
|
+
destroy(id: string): Promise<void>;
|
|
210
|
+
snapshot(id: string): Promise<SandboxSnapshot>;
|
|
211
|
+
restore(snapshot: SandboxSnapshot): Promise<string>;
|
|
212
|
+
/**
|
|
213
|
+
* Returns Temporal activity functions matching {@link SandboxOps}.
|
|
214
|
+
* Spread these into your worker's activity map.
|
|
215
|
+
*/
|
|
216
|
+
createActivities(): SandboxOps<TOptions>;
|
|
217
|
+
}
|
|
50
218
|
|
|
51
219
|
/**
|
|
52
|
-
*
|
|
220
|
+
* Bash tool handler — executes shell commands inside a {@link Sandbox}.
|
|
221
|
+
*
|
|
222
|
+
* Wrap with {@link withSandbox} at activity registration time to inject the
|
|
223
|
+
* sandbox automatically.
|
|
53
224
|
*/
|
|
225
|
+
declare const bashHandler: ActivityToolHandler<BashArgs, ExecResult | null, SandboxContext>;
|
|
226
|
+
|
|
54
227
|
interface EditResult {
|
|
55
228
|
path: string;
|
|
56
229
|
success: boolean;
|
|
57
230
|
replacements: number;
|
|
58
231
|
}
|
|
59
232
|
/**
|
|
60
|
-
*
|
|
233
|
+
* Edit tool handler — performs string replacements in sandbox files.
|
|
61
234
|
*
|
|
62
|
-
* @
|
|
63
|
-
*
|
|
235
|
+
* Wrap with {@link withSandbox} at activity registration time to inject the
|
|
236
|
+
* sandbox automatically.
|
|
64
237
|
*/
|
|
65
|
-
declare
|
|
238
|
+
declare const editHandler: ActivityToolHandler<FileEditArgs, EditResult, SandboxContext>;
|
|
66
239
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
stdout: string;
|
|
71
|
-
};
|
|
72
|
-
/** BashOptions with `fs` required */
|
|
73
|
-
type BashToolOptions = Required<Pick<BashOptions, "fs">> & Omit<BashOptions, "fs">;
|
|
240
|
+
interface GlobResult {
|
|
241
|
+
files: string[];
|
|
242
|
+
}
|
|
74
243
|
/**
|
|
75
|
-
*
|
|
244
|
+
* Glob tool handler — searches files within a {@link Sandbox} filesystem.
|
|
76
245
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
246
|
+
* Wrap with {@link withSandbox} at activity registration time to inject the
|
|
247
|
+
* sandbox automatically.
|
|
248
|
+
*/
|
|
249
|
+
declare const globHandler: ActivityToolHandler<GlobArgs, GlobResult, SandboxContext>;
|
|
250
|
+
|
|
251
|
+
interface ReadFileResult {
|
|
252
|
+
path: string;
|
|
253
|
+
content: string;
|
|
254
|
+
totalLines?: number;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Read-file tool handler — reads files from a {@link Sandbox} filesystem.
|
|
79
258
|
*
|
|
80
|
-
* @
|
|
81
|
-
*
|
|
82
|
-
|
|
259
|
+
* Wrap with {@link withSandbox} at activity registration time to inject the
|
|
260
|
+
* sandbox automatically.
|
|
261
|
+
*/
|
|
262
|
+
declare const readFileHandler: ActivityToolHandler<FileReadArgs, ReadFileResult | null, SandboxContext>;
|
|
263
|
+
|
|
264
|
+
interface WriteFileResult {
|
|
265
|
+
path: string;
|
|
266
|
+
success: boolean;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Write-file tool handler — writes files to a {@link Sandbox} filesystem.
|
|
83
270
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
271
|
+
* Wrap with {@link withSandbox} at activity registration time to inject the
|
|
272
|
+
* sandbox automatically.
|
|
86
273
|
*/
|
|
87
|
-
declare const
|
|
274
|
+
declare const writeFileHandler: ActivityToolHandler<FileWriteArgs, WriteFileResult, SandboxContext>;
|
|
88
275
|
|
|
89
276
|
/**
|
|
90
|
-
* Generates a formatted file tree string from
|
|
277
|
+
* Generates a formatted file tree string from a {@link SandboxFileSystem}.
|
|
91
278
|
* Useful for including filesystem context in agent prompts.
|
|
92
279
|
*
|
|
93
|
-
* @param fs -
|
|
280
|
+
* @param fs - Sandbox filesystem implementation
|
|
94
281
|
* @param opts - Optional configuration for tree generation
|
|
95
282
|
* @param opts.dir - Root directory to start from (defaults to `/`)
|
|
96
283
|
* @param opts.separator - Path separator (`/` or `\\`, defaults to `/`)
|
|
@@ -102,7 +289,7 @@ declare const createBashHandler: (bashOptions: BashToolOptions) => ActivityToolH
|
|
|
102
289
|
* ```typescript
|
|
103
290
|
* import { toTree } from 'zeitlich';
|
|
104
291
|
*
|
|
105
|
-
* const fileTree = await toTree(
|
|
292
|
+
* const fileTree = await toTree(sandbox.fs);
|
|
106
293
|
* // Returns:
|
|
107
294
|
* // /
|
|
108
295
|
* // ├─ src/
|
|
@@ -111,7 +298,7 @@ declare const createBashHandler: (bashOptions: BashToolOptions) => ActivityToolH
|
|
|
111
298
|
* // └─ package.json
|
|
112
299
|
* ```
|
|
113
300
|
*/
|
|
114
|
-
declare const toTree: (fs:
|
|
301
|
+
declare const toTree: (fs: SandboxFileSystem, opts?: {
|
|
115
302
|
dir?: string;
|
|
116
303
|
separator?: "/" | "\\";
|
|
117
304
|
depth?: number;
|
|
@@ -119,30 +306,4 @@ declare const toTree: (fs: IFileSystem, opts?: {
|
|
|
119
306
|
sort?: boolean;
|
|
120
307
|
}) => Promise<string>;
|
|
121
308
|
|
|
122
|
-
|
|
123
|
-
* Loads skills from a filesystem directory following the agentskills.io layout:
|
|
124
|
-
*
|
|
125
|
-
* ```
|
|
126
|
-
* skills/
|
|
127
|
-
* ├── code-review/
|
|
128
|
-
* │ └── SKILL.md
|
|
129
|
-
* ├── pdf-processing/
|
|
130
|
-
* │ └── SKILL.md
|
|
131
|
-
* ```
|
|
132
|
-
*
|
|
133
|
-
* Activity-side only — cannot be used in Temporal workflow code.
|
|
134
|
-
*/
|
|
135
|
-
declare class FileSystemSkillProvider implements SkillProvider {
|
|
136
|
-
private readonly baseDir;
|
|
137
|
-
constructor(baseDir: string);
|
|
138
|
-
listSkills(): Promise<SkillMetadata[]>;
|
|
139
|
-
getSkill(name: string): Promise<Skill>;
|
|
140
|
-
/**
|
|
141
|
-
* Convenience method to load all skills with full instructions.
|
|
142
|
-
* Returns `Skill[]` ready to pass into a workflow.
|
|
143
|
-
*/
|
|
144
|
-
loadAll(): Promise<Skill[]>;
|
|
145
|
-
private discoverSkillDirs;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export { ActivityToolHandler, AgentResponse, BashArgs, FileEditArgs, FileSystemSkillProvider, GlobArgs, ModelInvoker, RunAgentConfig, Skill, SkillMetadata, SkillProvider, createBashHandler, createEditHandler, createGlobHandler, createRunAgentActivity, queryParentWorkflowState, toTree };
|
|
309
|
+
export { ActivityToolHandler, type AgentStateContext, BaseAgentState, BaseThreadManager, BashArgs, ExecResult, FileEditArgs, FileReadArgs, FileSystemSkillProvider, FileWriteArgs, GlobArgs, RouterContext, RunAgentConfig, Sandbox, type SandboxContext, SandboxCreateOptions, SandboxFileSystem, SandboxManager, SandboxOps, SandboxProvider, SandboxSnapshot, Skill, SkillMetadata, SkillProvider, ThreadManagerConfig, ToolHandlerResponse, ToolResultConfig, bashHandler, createRunAgentActivity, createThreadManager, editHandler, globHandler, queryParentWorkflowState, readFileHandler, toTree, withAutoAppend, withParentWorkflowState, withSandbox, writeFileHandler };
|