zeitlich 0.2.1 → 0.2.3
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 +36 -33
- package/dist/index.cjs +445 -385
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -42
- package/dist/index.d.ts +25 -42
- package/dist/index.js +415 -362
- package/dist/index.js.map +1 -1
- package/dist/{workflow-CCoHnc3B.d.cts → workflow-D-2vp4Pq.d.cts} +456 -253
- package/dist/{workflow-CCoHnc3B.d.ts → workflow-D-2vp4Pq.d.ts} +456 -253
- package/dist/workflow.cjs +339 -272
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +4 -3
- package/dist/workflow.d.ts +4 -3
- package/dist/workflow.js +315 -252
- package/dist/workflow.js.map +1 -1
- package/package.json +3 -2
- package/src/activities.ts +1 -14
- package/src/index.ts +17 -11
- package/src/lib/session.ts +69 -86
- package/src/lib/state-manager.ts +9 -2
- package/src/lib/thread-manager.ts +45 -37
- package/src/lib/tool-router.ts +338 -116
- package/src/lib/types.ts +110 -28
- package/src/tools/ask-user-question/handler.ts +6 -6
- package/src/tools/ask-user-question/tool.ts +3 -2
- package/src/tools/bash/bash.test.ts +32 -32
- package/src/tools/bash/handler.ts +9 -9
- package/src/tools/bash/tool.ts +3 -2
- package/src/tools/edit/handler.ts +78 -123
- package/src/tools/edit/tool.ts +3 -2
- package/src/tools/glob/handler.ts +17 -48
- package/src/tools/glob/tool.ts +3 -2
- package/src/tools/grep/tool.ts +3 -2
- package/src/tools/{read → read-file}/tool.ts +3 -2
- package/src/tools/task/handler.ts +19 -9
- package/src/tools/task/tool.ts +3 -10
- package/src/tools/task-create/handler.ts +11 -20
- package/src/tools/task-create/tool.ts +3 -2
- package/src/tools/task-get/handler.ts +9 -14
- package/src/tools/task-get/tool.ts +3 -2
- package/src/tools/task-list/handler.ts +7 -12
- package/src/tools/task-list/tool.ts +3 -2
- package/src/tools/task-update/handler.ts +9 -16
- package/src/tools/task-update/tool.ts +3 -2
- package/src/tools/{write → write-file}/tool.ts +5 -6
- package/src/workflow.ts +25 -19
|
@@ -1,153 +1,95 @@
|
|
|
1
|
+
import { Workflow, proxyActivities } from '@temporalio/workflow';
|
|
2
|
+
import Redis from 'ioredis';
|
|
1
3
|
import { $InferMessageContent, MessageStructure, StoredMessage, MessageContent } from '@langchain/core/messages';
|
|
2
4
|
import z, { z as z$1 } from 'zod';
|
|
3
|
-
import
|
|
4
|
-
import Redis from 'ioredis';
|
|
5
|
+
import * as _temporalio_common from '@temporalio/common';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Content for a tool message response.
|
|
8
9
|
* Can be a simple string or complex content parts (text, images, cache points, etc.)
|
|
9
10
|
*/
|
|
10
11
|
type ToolMessageContent = $InferMessageContent<MessageStructure, "tool">;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
*/
|
|
35
|
-
|
|
12
|
+
interface ThreadManagerConfig<T = StoredMessage> {
|
|
13
|
+
redis: Redis;
|
|
14
|
+
threadId: string;
|
|
15
|
+
/** Thread key, defaults to 'messages' */
|
|
16
|
+
key?: string;
|
|
17
|
+
/** Custom serializer, defaults to JSON.stringify */
|
|
18
|
+
serialize?: (message: T) => string;
|
|
19
|
+
/** Custom deserializer, defaults to JSON.parse */
|
|
20
|
+
deserialize?: (raw: string) => T;
|
|
21
|
+
}
|
|
22
|
+
/** Generic thread manager for any message type */
|
|
23
|
+
interface BaseThreadManager<T> {
|
|
24
|
+
/** Initialize an empty thread */
|
|
25
|
+
initialize(): Promise<void>;
|
|
26
|
+
/** Load all messages from the thread */
|
|
27
|
+
load(): Promise<T[]>;
|
|
28
|
+
/** Append messages to the thread */
|
|
29
|
+
append(messages: T[]): Promise<void>;
|
|
30
|
+
/** Delete the thread */
|
|
31
|
+
delete(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/** Thread manager with StoredMessage convenience helpers */
|
|
34
|
+
interface ThreadManager extends BaseThreadManager<StoredMessage> {
|
|
35
|
+
/** Create a HumanMessage (returns StoredMessage for storage) */
|
|
36
|
+
createHumanMessage(content: string | MessageContent): StoredMessage;
|
|
37
|
+
/** Create an AIMessage with optional additional kwargs */
|
|
38
|
+
createAIMessage(content: string | MessageContent, kwargs?: {
|
|
39
|
+
header?: string;
|
|
40
|
+
options?: string[];
|
|
41
|
+
multiSelect?: boolean;
|
|
42
|
+
}): StoredMessage;
|
|
43
|
+
/** Create a ToolMessage */
|
|
44
|
+
createToolMessage(content: ToolMessageContent, toolCallId: string): StoredMessage;
|
|
45
|
+
/** Create and append a HumanMessage */
|
|
46
|
+
appendHumanMessage(content: string | MessageContent): Promise<void>;
|
|
47
|
+
/** Create and append a ToolMessage */
|
|
48
|
+
appendToolMessage(content: ToolMessageContent, toolCallId: string): Promise<void>;
|
|
49
|
+
/** Create and append an AIMessage */
|
|
50
|
+
appendAIMessage(content: string | MessageContent): Promise<void>;
|
|
51
|
+
}
|
|
36
52
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* the state and helpers needed for those handlers.
|
|
53
|
+
* Creates a thread manager for handling conversation state in Redis.
|
|
54
|
+
* Without generic args, returns a full ThreadManager with StoredMessage helpers.
|
|
55
|
+
* With a custom type T, returns a BaseThreadManager<T>.
|
|
41
56
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
/** Check if agent is running */
|
|
46
|
-
isRunning(): boolean;
|
|
47
|
-
/** Check if agent is in terminal state */
|
|
48
|
-
isTerminal(): boolean;
|
|
49
|
-
/** Get current state version */
|
|
50
|
-
getVersion(): number;
|
|
51
|
-
/** Set status to RUNNING */
|
|
52
|
-
run(): void;
|
|
53
|
-
/** Set status to WAITING_FOR_INPUT */
|
|
54
|
-
waitForInput(): void;
|
|
55
|
-
/** Set status to COMPLETED */
|
|
56
|
-
complete(): void;
|
|
57
|
-
/** Set status to FAILED */
|
|
58
|
-
fail(): void;
|
|
59
|
-
/** Set status to CANCELLED */
|
|
60
|
-
cancel(): void;
|
|
61
|
-
/** Increment state version (call after state changes) */
|
|
62
|
-
incrementVersion(): void;
|
|
63
|
-
/** Increment turns (call after each turn) */
|
|
64
|
-
incrementTurns(): void;
|
|
65
|
-
/** Get current turns */
|
|
66
|
-
getTurns(): number;
|
|
67
|
-
/** Get a custom state value by key */
|
|
68
|
-
get<K extends keyof TCustom>(key: K): TCustom[K];
|
|
69
|
-
/** Set a custom state value by key */
|
|
70
|
-
set<K extends keyof TCustom>(key: K, value: TCustom[K]): void;
|
|
71
|
-
/** Get full state for query handler */
|
|
72
|
-
getCurrentState(): AgentState<TCustom>;
|
|
73
|
-
/** Check if should return from waitForStateChange */
|
|
74
|
-
shouldReturnFromWait(lastKnownVersion: number): boolean;
|
|
75
|
-
/** Get all tasks */
|
|
76
|
-
getTasks(): WorkflowTask[];
|
|
77
|
-
/** Get a task by ID */
|
|
78
|
-
getTask(id: string): WorkflowTask | undefined;
|
|
79
|
-
/** Add or update a task */
|
|
80
|
-
setTask(task: WorkflowTask): void;
|
|
81
|
-
/** Delete a task by ID */
|
|
82
|
-
deleteTask(id: string): boolean;
|
|
83
|
-
/** Set the tools */
|
|
84
|
-
setTools(newTools: ToolDefinition[]): void;
|
|
85
|
-
}
|
|
57
|
+
declare function createThreadManager(config: ThreadManagerConfig): ThreadManager;
|
|
58
|
+
declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThreadManager<T>;
|
|
59
|
+
|
|
86
60
|
/**
|
|
87
|
-
* Creates
|
|
61
|
+
* Creates a Task tool configured with the available subagents.
|
|
88
62
|
*
|
|
89
|
-
* @param
|
|
90
|
-
*
|
|
63
|
+
* @param subagents - Array of subagent configurations (must have at least one)
|
|
64
|
+
* @returns A tool definition with dynamic schema based on available subagents
|
|
91
65
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
*
|
|
66
|
+
* @example
|
|
67
|
+
* const taskTool = createTaskTool([
|
|
68
|
+
* {
|
|
69
|
+
* name: "researcher",
|
|
70
|
+
* description: "Researches topics and gathers information",
|
|
71
|
+
* workflow: "researcherWorkflow",
|
|
72
|
+
* resultSchema: z.object({ findings: z.string() }),
|
|
73
|
+
* },
|
|
74
|
+
* ]);
|
|
99
75
|
*/
|
|
100
|
-
declare
|
|
101
|
-
|
|
102
|
-
readonly waitForStateChange: "waitForStateChange";
|
|
103
|
-
readonly addMessage: "addMessage";
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
declare const taskCreateTool: {
|
|
107
|
-
name: "TaskCreate";
|
|
76
|
+
declare function createTaskTool<T extends SubagentConfig[]>(subagents: T): {
|
|
77
|
+
name: string;
|
|
108
78
|
description: string;
|
|
109
79
|
schema: z.ZodObject<{
|
|
110
|
-
|
|
80
|
+
subagent: z.ZodEnum<Record<string, string>>;
|
|
111
81
|
description: z.ZodString;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}, z.core.$strip>;
|
|
82
|
+
prompt: z.ZodString;
|
|
83
|
+
}>;
|
|
115
84
|
};
|
|
116
|
-
type TaskCreateToolSchemaType = z.infer<typeof taskCreateTool.schema>;
|
|
117
|
-
|
|
118
85
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* @param stateManager - State manager containing tasks state
|
|
122
|
-
* @param idGenerator - Function to generate unique task IDs (e.g., uuid4 from Temporal)
|
|
123
|
-
* @returns A tool handler function
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* const handler = createTaskCreateHandler(stateManager, uuid4);
|
|
86
|
+
* Task tool args type (when subagent names are not known at compile time)
|
|
127
87
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
idGenerator: () => string;
|
|
131
|
-
}): (args: TaskCreateToolSchemaType) => ToolHandlerResponse<WorkflowTask>;
|
|
132
|
-
|
|
133
|
-
declare const bashTool: {
|
|
134
|
-
name: "Bash";
|
|
88
|
+
type TaskArgs = {
|
|
89
|
+
subagent: string;
|
|
135
90
|
description: string;
|
|
136
|
-
|
|
137
|
-
command: z.ZodString;
|
|
138
|
-
}, z.core.$strip>;
|
|
139
|
-
strict: boolean;
|
|
140
|
-
};
|
|
141
|
-
type bashToolSchemaType = z.infer<typeof bashTool.schema>;
|
|
142
|
-
|
|
143
|
-
type BashExecOut = {
|
|
144
|
-
exitCode: number;
|
|
145
|
-
stderr: string;
|
|
146
|
-
stdout: string;
|
|
91
|
+
prompt: string;
|
|
147
92
|
};
|
|
148
|
-
/** BashOptions with `fs` required */
|
|
149
|
-
type BashToolOptions = Required<Pick<BashOptions, "fs">> & Omit<BashOptions, "fs">;
|
|
150
|
-
declare const handleBashTool: (bashOptions: BashToolOptions) => ActivityToolHandler<bashToolSchemaType, BashExecOut | null>;
|
|
151
93
|
|
|
152
94
|
/**
|
|
153
95
|
* A tool definition with a name, description, and Zod schema for arguments.
|
|
@@ -171,17 +113,28 @@ interface ToolWithHandler<TName extends string = string, TSchema extends z$1.Zod
|
|
|
171
113
|
handler: ToolHandler<z$1.infer<TSchema>, TResult, TContext>;
|
|
172
114
|
strict?: boolean;
|
|
173
115
|
max_uses?: number;
|
|
116
|
+
/** Whether this tool is available to the agent (default: true). Disabled tools are excluded from definitions and rejected at parse time. */
|
|
117
|
+
enabled?: boolean;
|
|
118
|
+
/** Per-tool lifecycle hooks (run in addition to global hooks) */
|
|
119
|
+
hooks?: ToolHooks<z$1.infer<TSchema>, TResult>;
|
|
174
120
|
}
|
|
175
121
|
/**
|
|
176
122
|
* A map of tool keys to tool definitions with handlers.
|
|
123
|
+
*
|
|
124
|
+
* Handler uses `any` intentionally — this is a type-system boundary where heterogeneous
|
|
125
|
+
* tool types are stored together. Type safety for individual tools is enforced by
|
|
126
|
+
* `defineTool()` at the definition site and generic inference utilities like
|
|
127
|
+
* `InferToolResults<T>` at the consumption site.
|
|
177
128
|
*/
|
|
178
129
|
type ToolMap = Record<string, {
|
|
179
130
|
name: string;
|
|
180
131
|
description: string;
|
|
181
132
|
schema: z$1.ZodType;
|
|
182
|
-
handler:
|
|
133
|
+
handler: ToolHandler<any, any, any>;
|
|
183
134
|
strict?: boolean;
|
|
184
135
|
max_uses?: number;
|
|
136
|
+
enabled?: boolean;
|
|
137
|
+
hooks?: ToolHooks<any, any>;
|
|
185
138
|
}>;
|
|
186
139
|
/**
|
|
187
140
|
* Extract the tool names from a tool map (uses the tool's name property, not the key).
|
|
@@ -216,29 +169,29 @@ type AppendToolResultFn = (config: ToolResultConfig) => Promise<void>;
|
|
|
216
169
|
/**
|
|
217
170
|
* The response from a tool handler.
|
|
218
171
|
* Contains the content for the tool message and the result to return from processToolCalls.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
172
|
+
*
|
|
173
|
+
* Tools that don't return additional data should use `data: null` (TResult defaults to null).
|
|
174
|
+
* Tools that may fail to produce data should type TResult as `SomeType | null`.
|
|
175
|
+
*/
|
|
176
|
+
interface ToolHandlerResponse<TResult = null> {
|
|
177
|
+
/** Content sent back to the LLM as the tool call response */
|
|
178
|
+
toolResponse: ToolMessageContent;
|
|
179
|
+
/** Data returned to the workflow and hooks for further processing */
|
|
180
|
+
data: TResult;
|
|
181
|
+
/**
|
|
182
|
+
* When true, the tool result has already been appended to the thread
|
|
183
|
+
* by the handler itself (e.g. via `withAutoAppend`), so the router
|
|
184
|
+
* will skip the `appendToolResult` call. This avoids sending large
|
|
185
|
+
* payloads through Temporal's activity payload limit.
|
|
186
|
+
*/
|
|
187
|
+
resultAppended?: boolean;
|
|
225
188
|
}
|
|
226
189
|
/**
|
|
227
190
|
* Context passed to tool handlers for additional data beyond tool args.
|
|
228
191
|
* Use this to pass workflow state like file trees, user context, etc.
|
|
192
|
+
* Generic so callers can type the context shape, e.g. ToolHandlerContext<ControlTestFsParams>.
|
|
229
193
|
*/
|
|
230
|
-
|
|
231
|
-
/** Additional context data - define your own shape */
|
|
232
|
-
[key: string]: unknown;
|
|
233
|
-
}
|
|
234
|
-
interface BuildInToolDefinitions {
|
|
235
|
-
[bashTool.name]: typeof bashTool & {
|
|
236
|
-
handler: ReturnType<typeof handleBashTool>;
|
|
237
|
-
};
|
|
238
|
-
[taskCreateTool.name]: typeof taskCreateTool & {
|
|
239
|
-
handler: ReturnType<typeof createTaskCreateHandler>;
|
|
240
|
-
};
|
|
241
|
-
}
|
|
194
|
+
type ToolHandlerContext<T = Record<string, unknown>> = T;
|
|
242
195
|
/**
|
|
243
196
|
* A handler function for a specific tool.
|
|
244
197
|
* Receives the parsed args and context, returns a response with content and result.
|
|
@@ -254,7 +207,7 @@ type ToolHandler<TArgs, TResult, TContext = ToolHandlerContext> = (args: TArgs,
|
|
|
254
207
|
* ```typescript
|
|
255
208
|
* // Filesystem handler with context
|
|
256
209
|
* const readHandler: ActivityToolHandler<
|
|
257
|
-
*
|
|
210
|
+
* FileReadArgs,
|
|
258
211
|
* ReadResult,
|
|
259
212
|
* { scopedNodes: FileNode[]; provider: FileSystemProvider }
|
|
260
213
|
* > = async (args, context) => {
|
|
@@ -281,14 +234,12 @@ type ToolResult<T extends ToolMap, TName extends ToolNames<T>> = Extract<T[keyof
|
|
|
281
234
|
interface ToolCallResult<TName extends string = string, TResult = unknown> {
|
|
282
235
|
toolCallId: string;
|
|
283
236
|
name: TName;
|
|
284
|
-
|
|
237
|
+
data: TResult;
|
|
285
238
|
}
|
|
286
239
|
/**
|
|
287
240
|
* Options for creating a tool router.
|
|
288
241
|
*/
|
|
289
242
|
interface ToolRouterOptions<T extends ToolMap> {
|
|
290
|
-
/** File tree for the agent */
|
|
291
|
-
fileTree: string;
|
|
292
243
|
/** Map of tools with their handlers */
|
|
293
244
|
tools: T;
|
|
294
245
|
/** Thread ID for appending tool results */
|
|
@@ -301,10 +252,6 @@ interface ToolRouterOptions<T extends ToolMap> {
|
|
|
301
252
|
hooks?: Hooks<T, ToolCallResultUnion<InferToolResults<T>>>;
|
|
302
253
|
/** Subagent configurations */
|
|
303
254
|
subagents?: SubagentConfig[];
|
|
304
|
-
/** Build in tools - accepts raw handlers or proxied activities */
|
|
305
|
-
buildInTools?: {
|
|
306
|
-
[K in keyof BuildInToolDefinitions]?: BuildInToolDefinitions[K]["handler"];
|
|
307
|
-
};
|
|
308
255
|
}
|
|
309
256
|
/**
|
|
310
257
|
* Infer result types from a tool map based on handler return types.
|
|
@@ -405,6 +352,98 @@ interface ToolRouter<T extends ToolMap> {
|
|
|
405
352
|
* ```
|
|
406
353
|
*/
|
|
407
354
|
declare function createToolRouter<T extends ToolMap>(options: ToolRouterOptions<T>): ToolRouter<T>;
|
|
355
|
+
/**
|
|
356
|
+
* Wraps a tool handler to automatically append its result directly to the
|
|
357
|
+
* thread and sets `resultAppended: true` on the response.
|
|
358
|
+
*
|
|
359
|
+
* Use this for tools whose responses may exceed Temporal's activity payload
|
|
360
|
+
* limit. The wrapper appends to the thread inside the activity (where Redis
|
|
361
|
+
* is available), then replaces `toolResponse` with an empty string so the
|
|
362
|
+
* large payload never travels through the Temporal workflow boundary.
|
|
363
|
+
*
|
|
364
|
+
* @param getThread - Factory that returns a thread manager for the given threadId
|
|
365
|
+
* @param handler - The original tool handler
|
|
366
|
+
* @returns A wrapped handler that auto-appends and flags the response
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* import { withAutoAppend } from '@bead-ai/zeitlich/workflow';
|
|
371
|
+
* import { createThreadManager } from '@bead-ai/zeitlich';
|
|
372
|
+
*
|
|
373
|
+
* const handler = withAutoAppend(
|
|
374
|
+
* (threadId) => createThreadManager({ redis, threadId }),
|
|
375
|
+
* async (args, ctx) => ({
|
|
376
|
+
* toolResponse: JSON.stringify(largeResult), // appended directly to Redis
|
|
377
|
+
* data: { summary: "..." }, // small data for workflow
|
|
378
|
+
* }),
|
|
379
|
+
* );
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
declare function withAutoAppend<TArgs, TResult, TContext extends ToolHandlerContext = ToolHandlerContext>(threadHandler: (config: ToolResultConfig) => Promise<void>, handler: ActivityToolHandler<TArgs, TResult, TContext>): ActivityToolHandler<TArgs, TResult, TContext>;
|
|
383
|
+
/**
|
|
384
|
+
* Identity function that creates a generic inference context for a tool definition.
|
|
385
|
+
* TypeScript infers TResult from the handler and flows it to hooks automatically.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* tools: {
|
|
390
|
+
* AskUser: defineTool({
|
|
391
|
+
* ...askUserTool,
|
|
392
|
+
* handler: handleAskUser,
|
|
393
|
+
* hooks: {
|
|
394
|
+
* onPostToolUse: ({ result }) => {
|
|
395
|
+
* // result is correctly typed as the handler's return data type
|
|
396
|
+
* },
|
|
397
|
+
* },
|
|
398
|
+
* }),
|
|
399
|
+
* }
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
declare function defineTool<TName extends string, TSchema extends z$1.ZodType, TResult, TContext = ToolHandlerContext>(tool: ToolWithHandler<TName, TSchema, TResult, TContext>): ToolWithHandler<TName, TSchema, TResult, TContext>;
|
|
403
|
+
/**
|
|
404
|
+
* Identity function that provides full type inference for subagent configurations.
|
|
405
|
+
* Verifies the workflow function's input parameters match the configured context,
|
|
406
|
+
* and properly types the lifecycle hooks with Task tool args and inferred result type.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* // With typed context — workflow must accept { prompt, context }
|
|
411
|
+
* const researcher = defineSubagent({
|
|
412
|
+
* name: "researcher",
|
|
413
|
+
* description: "Researches topics",
|
|
414
|
+
* workflow: researcherWorkflow, // (input: { prompt: string; context: { apiKey: string } }) => Promise<...>
|
|
415
|
+
* context: { apiKey: "..." },
|
|
416
|
+
* resultSchema: z.object({ findings: z.string() }),
|
|
417
|
+
* hooks: {
|
|
418
|
+
* onPostExecution: ({ result }) => {
|
|
419
|
+
* // result is typed as { findings: string }
|
|
420
|
+
* },
|
|
421
|
+
* },
|
|
422
|
+
* });
|
|
423
|
+
*
|
|
424
|
+
* // Without context — workflow only needs { prompt }
|
|
425
|
+
* const writer = defineSubagent({
|
|
426
|
+
* name: "writer",
|
|
427
|
+
* description: "Writes content",
|
|
428
|
+
* workflow: writerWorkflow, // (input: { prompt: string }) => Promise<...>
|
|
429
|
+
* resultSchema: z.object({ content: z.string() }),
|
|
430
|
+
* });
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType, TContext extends Record<string, unknown> = Record<string, unknown>>(config: Omit<SubagentConfig<TResult>, "hooks" | "workflow" | "context"> & {
|
|
434
|
+
workflow: string | ((input: {
|
|
435
|
+
prompt: string;
|
|
436
|
+
context: TContext;
|
|
437
|
+
}) => Promise<any>);
|
|
438
|
+
context: TContext;
|
|
439
|
+
hooks?: SubagentHooks<TaskArgs, z$1.infer<TResult>>;
|
|
440
|
+
}): SubagentConfig<TResult>;
|
|
441
|
+
declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType>(config: Omit<SubagentConfig<TResult>, "hooks" | "workflow"> & {
|
|
442
|
+
workflow: string | ((input: {
|
|
443
|
+
prompt: string;
|
|
444
|
+
}) => Promise<any>);
|
|
445
|
+
hooks?: SubagentHooks<TaskArgs, z$1.infer<TResult>>;
|
|
446
|
+
}): SubagentConfig<TResult>;
|
|
408
447
|
/**
|
|
409
448
|
* Utility to check if there were no tool calls besides a specific one
|
|
410
449
|
*/
|
|
@@ -418,11 +457,12 @@ type AgentStatus = "RUNNING" | "WAITING_FOR_INPUT" | "COMPLETED" | "FAILED" | "C
|
|
|
418
457
|
* Base state that all agents must have
|
|
419
458
|
*/
|
|
420
459
|
interface BaseAgentState {
|
|
421
|
-
tools:
|
|
460
|
+
tools: SerializableToolDefinition[];
|
|
422
461
|
status: AgentStatus;
|
|
423
462
|
version: number;
|
|
424
463
|
turns: number;
|
|
425
464
|
tasks: Map<string, WorkflowTask>;
|
|
465
|
+
systemPrompt: string;
|
|
426
466
|
}
|
|
427
467
|
/**
|
|
428
468
|
* File representation for agent workflows
|
|
@@ -442,8 +482,8 @@ interface AgentFile {
|
|
|
442
482
|
/**
|
|
443
483
|
* Agent response from LLM invocation
|
|
444
484
|
*/
|
|
445
|
-
interface AgentResponse {
|
|
446
|
-
message:
|
|
485
|
+
interface AgentResponse<M = StoredMessage> {
|
|
486
|
+
message: M;
|
|
447
487
|
stopReason: string | null;
|
|
448
488
|
usage?: {
|
|
449
489
|
input_tokens?: number;
|
|
@@ -451,17 +491,33 @@ interface AgentResponse {
|
|
|
451
491
|
total_tokens?: number;
|
|
452
492
|
};
|
|
453
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Thread operations required by a session.
|
|
496
|
+
* Consumers provide these — typically by wrapping Temporal activities.
|
|
497
|
+
* Use `proxyDefaultThreadOps()` for the default StoredMessage implementation.
|
|
498
|
+
*/
|
|
499
|
+
interface ThreadOps<M = StoredMessage> {
|
|
500
|
+
/** Initialize an empty thread */
|
|
501
|
+
initializeThread(threadId: string): Promise<void>;
|
|
502
|
+
/** Append a human message to the thread */
|
|
503
|
+
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
504
|
+
/** Append a tool result to the thread */
|
|
505
|
+
appendToolResult(config: ToolResultConfig): Promise<void>;
|
|
506
|
+
/** Extract raw tool calls from a message */
|
|
507
|
+
parseToolCalls(message: M): Promise<RawToolCall[]>;
|
|
508
|
+
}
|
|
454
509
|
/**
|
|
455
510
|
* Configuration for a Zeitlich agent session
|
|
456
511
|
*/
|
|
457
|
-
interface ZeitlichAgentConfig<T extends ToolMap> {
|
|
458
|
-
buildFileTree?: () => Promise<string>;
|
|
512
|
+
interface ZeitlichAgentConfig<T extends ToolMap, M = StoredMessage> {
|
|
459
513
|
threadId: string;
|
|
460
514
|
agentName: string;
|
|
461
515
|
metadata?: Record<string, unknown>;
|
|
462
516
|
maxTurns?: number;
|
|
463
517
|
/** Workflow-specific runAgent activity (with tools pre-bound) */
|
|
464
|
-
runAgent: RunAgentActivity
|
|
518
|
+
runAgent: RunAgentActivity<M>;
|
|
519
|
+
/** Thread operations (initialize, append messages, parse tool calls) */
|
|
520
|
+
threadOps: ThreadOps<M>;
|
|
465
521
|
/** Tool router for processing tool calls (optional if agent has no tools) */
|
|
466
522
|
tools?: T;
|
|
467
523
|
/** Subagent configurations */
|
|
@@ -470,27 +526,23 @@ interface ZeitlichAgentConfig<T extends ToolMap> {
|
|
|
470
526
|
hooks?: Hooks<T, ToolCallResultUnion<InferToolResults<T>>>;
|
|
471
527
|
/** Whether to process tools in parallel */
|
|
472
528
|
processToolsInParallel?: boolean;
|
|
473
|
-
/**
|
|
474
|
-
* Base system prompt (e.g., Auditron identity).
|
|
475
|
-
* Can be a static string or async function.
|
|
476
|
-
*/
|
|
477
|
-
baseSystemPrompt: string | (() => string | Promise<string>);
|
|
478
|
-
/**
|
|
479
|
-
* Agent-specific instructions prompt.
|
|
480
|
-
* Can be a static string or async function.
|
|
481
|
-
*/
|
|
482
|
-
instructionsPrompt: string | (() => string | Promise<string>);
|
|
483
529
|
/**
|
|
484
530
|
* Build context message content from agent-specific context.
|
|
485
531
|
* Returns MessageContent array for the initial HumanMessage.
|
|
486
532
|
*/
|
|
487
533
|
buildContextMessage: () => MessageContent | Promise<MessageContent>;
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* A JSON-serializable tool definition for state storage.
|
|
537
|
+
* Uses a plain JSON Schema object instead of a live Zod instance,
|
|
538
|
+
* so it survives Temporal serialization without losing constraints (min, max, etc.).
|
|
539
|
+
*/
|
|
540
|
+
interface SerializableToolDefinition {
|
|
541
|
+
name: string;
|
|
542
|
+
description: string;
|
|
543
|
+
schema: Record<string, unknown>;
|
|
544
|
+
strict?: boolean;
|
|
545
|
+
max_uses?: number;
|
|
494
546
|
}
|
|
495
547
|
/**
|
|
496
548
|
* Configuration passed to runAgent activity
|
|
@@ -503,13 +555,15 @@ interface RunAgentConfig {
|
|
|
503
555
|
/**
|
|
504
556
|
* Type signature for workflow-specific runAgent activity
|
|
505
557
|
*/
|
|
506
|
-
type RunAgentActivity = (config: RunAgentConfig) => Promise<AgentResponse
|
|
558
|
+
type RunAgentActivity<M = StoredMessage> = (config: RunAgentConfig) => Promise<AgentResponse<M>>;
|
|
507
559
|
/**
|
|
508
560
|
* Configuration for appending a tool result
|
|
509
561
|
*/
|
|
510
562
|
interface ToolResultConfig {
|
|
511
563
|
threadId: string;
|
|
512
564
|
toolCallId: string;
|
|
565
|
+
/** The name of the tool that produced this result */
|
|
566
|
+
toolName: string;
|
|
513
567
|
/** Content for the tool message (string or complex content parts) */
|
|
514
568
|
content: ToolMessageContent;
|
|
515
569
|
}
|
|
@@ -523,12 +577,43 @@ interface SubagentConfig<TResult extends z$1.ZodType = z$1.ZodType> {
|
|
|
523
577
|
name: string;
|
|
524
578
|
/** Description shown to the parent agent explaining what this subagent does */
|
|
525
579
|
description: string;
|
|
526
|
-
/** Temporal workflow type name (used with executeChild) */
|
|
527
|
-
|
|
580
|
+
/** Temporal workflow function or type name (used with executeChild) */
|
|
581
|
+
workflow: string | Workflow;
|
|
528
582
|
/** Optional task queue - defaults to parent's queue if not specified */
|
|
529
583
|
taskQueue?: string;
|
|
530
584
|
/** Optional Zod schema to validate the child workflow's result. If omitted, result is passed through as-is. */
|
|
531
585
|
resultSchema?: TResult;
|
|
586
|
+
/** Optional static context passed to the subagent on every invocation */
|
|
587
|
+
context?: Record<string, unknown>;
|
|
588
|
+
/** Per-subagent lifecycle hooks */
|
|
589
|
+
hooks?: SubagentHooks;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Per-subagent lifecycle hooks - defined on a SubagentConfig.
|
|
593
|
+
* Runs in addition to global hooks (global pre → subagent pre → execute → subagent post → global post).
|
|
594
|
+
*/
|
|
595
|
+
interface SubagentHooks<TArgs = unknown, TResult = unknown> {
|
|
596
|
+
/** Called before this subagent executes - can skip or modify args */
|
|
597
|
+
onPreExecution?: (ctx: {
|
|
598
|
+
args: TArgs;
|
|
599
|
+
threadId: string;
|
|
600
|
+
turn: number;
|
|
601
|
+
}) => PreToolUseHookResult | Promise<PreToolUseHookResult>;
|
|
602
|
+
/** Called after this subagent executes successfully */
|
|
603
|
+
onPostExecution?: (ctx: {
|
|
604
|
+
args: TArgs;
|
|
605
|
+
result: TResult;
|
|
606
|
+
threadId: string;
|
|
607
|
+
turn: number;
|
|
608
|
+
durationMs: number;
|
|
609
|
+
}) => void | Promise<void>;
|
|
610
|
+
/** Called when this subagent execution fails */
|
|
611
|
+
onExecutionFailure?: (ctx: {
|
|
612
|
+
args: TArgs;
|
|
613
|
+
error: Error;
|
|
614
|
+
threadId: string;
|
|
615
|
+
turn: number;
|
|
616
|
+
}) => PostToolUseFailureHookResult | Promise<PostToolUseFailureHookResult>;
|
|
532
617
|
}
|
|
533
618
|
/**
|
|
534
619
|
* Input passed to child workflows when spawned as subagents
|
|
@@ -536,6 +621,8 @@ interface SubagentConfig<TResult extends z$1.ZodType = z$1.ZodType> {
|
|
|
536
621
|
interface SubagentInput {
|
|
537
622
|
/** The prompt/task from the parent agent */
|
|
538
623
|
prompt: string;
|
|
624
|
+
/** Optional context parameters passed from the parent agent */
|
|
625
|
+
context?: Record<string, unknown>;
|
|
539
626
|
}
|
|
540
627
|
/**
|
|
541
628
|
* Status of a workflow task
|
|
@@ -669,6 +756,33 @@ interface SessionEndHookContext {
|
|
|
669
756
|
* SessionEnd hook - called when session ends
|
|
670
757
|
*/
|
|
671
758
|
type SessionEndHook = (ctx: SessionEndHookContext) => void | Promise<void>;
|
|
759
|
+
/**
|
|
760
|
+
* Per-tool lifecycle hooks - defined directly on a tool definition.
|
|
761
|
+
* Runs in addition to global hooks (global pre → tool pre → execute → tool post → global post).
|
|
762
|
+
*/
|
|
763
|
+
interface ToolHooks<TArgs = unknown, TResult = unknown> {
|
|
764
|
+
/** Called before this tool executes - can skip or modify args */
|
|
765
|
+
onPreToolUse?: (ctx: {
|
|
766
|
+
args: TArgs;
|
|
767
|
+
threadId: string;
|
|
768
|
+
turn: number;
|
|
769
|
+
}) => PreToolUseHookResult | Promise<PreToolUseHookResult>;
|
|
770
|
+
/** Called after this tool executes successfully */
|
|
771
|
+
onPostToolUse?: (ctx: {
|
|
772
|
+
args: TArgs;
|
|
773
|
+
result: TResult;
|
|
774
|
+
threadId: string;
|
|
775
|
+
turn: number;
|
|
776
|
+
durationMs: number;
|
|
777
|
+
}) => void | Promise<void>;
|
|
778
|
+
/** Called when this tool execution fails */
|
|
779
|
+
onPostToolUseFailure?: (ctx: {
|
|
780
|
+
args: TArgs;
|
|
781
|
+
error: Error;
|
|
782
|
+
threadId: string;
|
|
783
|
+
turn: number;
|
|
784
|
+
}) => PostToolUseFailureHookResult | Promise<PostToolUseFailureHookResult>;
|
|
785
|
+
}
|
|
672
786
|
/**
|
|
673
787
|
* Combined hooks interface for session lifecycle
|
|
674
788
|
*/
|
|
@@ -689,10 +803,105 @@ interface Hooks<T extends ToolMap, TResult = unknown> {
|
|
|
689
803
|
*/
|
|
690
804
|
declare function isTerminalStatus(status: AgentStatus): boolean;
|
|
691
805
|
|
|
692
|
-
|
|
806
|
+
/**
|
|
807
|
+
* JSON primitive types that Temporal can serialize
|
|
808
|
+
*/
|
|
809
|
+
type JsonPrimitive = string | number | boolean | null | undefined;
|
|
810
|
+
/**
|
|
811
|
+
* JSON-serializable value (recursive type for Temporal compatibility)
|
|
812
|
+
*/
|
|
813
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
814
|
+
[key: string]: JsonValue;
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Type constraint ensuring T only contains JSON-serializable values.
|
|
818
|
+
* Use this for custom state to ensure Temporal workflow compatibility.
|
|
819
|
+
*
|
|
820
|
+
* Allows: primitives, arrays, plain objects, and JsonValue
|
|
821
|
+
* Rejects: functions, symbols, undefined, class instances with methods
|
|
822
|
+
*/
|
|
823
|
+
type JsonSerializable<T> = {
|
|
824
|
+
[K in keyof T]: T[K] extends JsonValue ? T[K] : T[K] extends JsonPrimitive ? T[K] : T[K] extends (infer U)[] ? U extends JsonValue ? T[K] : JsonSerializable<U>[] : T[K] extends object ? JsonSerializable<T[K]> : never;
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* Full state type combining base state with custom state
|
|
828
|
+
*/
|
|
829
|
+
type AgentState<TCustom extends JsonSerializable<TCustom>> = BaseAgentState & TCustom;
|
|
830
|
+
/**
|
|
831
|
+
* Agent state manager interface
|
|
832
|
+
* Note: Temporal handlers must be set up in the workflow file due to
|
|
833
|
+
* Temporal's workflow isolation requirements. This manager provides
|
|
834
|
+
* the state and helpers needed for those handlers.
|
|
835
|
+
*/
|
|
836
|
+
interface AgentStateManager<TCustom extends JsonSerializable<TCustom>> {
|
|
837
|
+
/** Get current status */
|
|
838
|
+
getStatus(): AgentStatus;
|
|
839
|
+
/** Check if agent is running */
|
|
840
|
+
isRunning(): boolean;
|
|
841
|
+
/** Check if agent is in terminal state */
|
|
842
|
+
isTerminal(): boolean;
|
|
843
|
+
/** Get current state version */
|
|
844
|
+
getVersion(): number;
|
|
845
|
+
/** Set status to RUNNING */
|
|
846
|
+
run(): void;
|
|
847
|
+
/** Set status to WAITING_FOR_INPUT */
|
|
848
|
+
waitForInput(): void;
|
|
849
|
+
/** Set status to COMPLETED */
|
|
850
|
+
complete(): void;
|
|
851
|
+
/** Set status to FAILED */
|
|
852
|
+
fail(): void;
|
|
853
|
+
/** Set status to CANCELLED */
|
|
854
|
+
cancel(): void;
|
|
855
|
+
/** Increment state version (call after state changes) */
|
|
856
|
+
incrementVersion(): void;
|
|
857
|
+
/** Increment turns (call after each turn) */
|
|
858
|
+
incrementTurns(): void;
|
|
859
|
+
/** Get current turns */
|
|
860
|
+
getTurns(): number;
|
|
861
|
+
/** Get a custom state value by key */
|
|
862
|
+
get<K extends keyof TCustom>(key: K): TCustom[K];
|
|
863
|
+
/** Set a custom state value by key */
|
|
864
|
+
set<K extends keyof TCustom>(key: K, value: TCustom[K]): void;
|
|
865
|
+
/** Get full state for query handler */
|
|
866
|
+
getCurrentState(): AgentState<TCustom>;
|
|
867
|
+
/** Check if should return from waitForStateChange */
|
|
868
|
+
shouldReturnFromWait(lastKnownVersion: number): boolean;
|
|
869
|
+
/** Get all tasks */
|
|
870
|
+
getTasks(): WorkflowTask[];
|
|
871
|
+
/** Get a task by ID */
|
|
872
|
+
getTask(id: string): WorkflowTask | undefined;
|
|
873
|
+
/** Add or update a task */
|
|
874
|
+
setTask(task: WorkflowTask): void;
|
|
875
|
+
/** Delete a task by ID */
|
|
876
|
+
deleteTask(id: string): boolean;
|
|
877
|
+
/** Set the tools (converts Zod schemas to JSON Schema for serialization) */
|
|
878
|
+
setTools(newTools: ToolDefinition[]): void;
|
|
879
|
+
}
|
|
880
|
+
declare const getStateQuery: _temporalio_common.QueryDefinition<BaseAgentState, [], string>;
|
|
881
|
+
/**
|
|
882
|
+
* Creates an agent state manager for tracking workflow state.
|
|
883
|
+
*
|
|
884
|
+
* @param initialState - Optional initial values for base and custom state
|
|
885
|
+
* Base state defaults: status="RUNNING", version=0, turns=0, tasks=empty, fileTree=[]
|
|
886
|
+
*
|
|
887
|
+
* Note: Due to Temporal's workflow isolation, handlers must be set up
|
|
888
|
+
* in the workflow file using defineQuery/defineUpdate and setHandler.
|
|
889
|
+
* This manager provides the state and logic needed for those handlers.
|
|
890
|
+
*/
|
|
891
|
+
declare function createAgentStateManager<TCustom extends JsonSerializable<TCustom> = Record<string, never>>(initialState?: Partial<BaseAgentState> & TCustom): AgentStateManager<TCustom>;
|
|
892
|
+
/**
|
|
893
|
+
* Handler names used across agents
|
|
894
|
+
*/
|
|
895
|
+
declare const AGENT_HANDLER_NAMES: {
|
|
896
|
+
readonly getAgentState: "getAgentState";
|
|
897
|
+
readonly waitForStateChange: "waitForStateChange";
|
|
898
|
+
readonly addMessage: "addMessage";
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
interface ZeitlichSession<M = unknown> {
|
|
693
902
|
runSession<T extends JsonSerializable<T>>(args: {
|
|
694
903
|
stateManager: AgentStateManager<T>;
|
|
695
|
-
}): Promise<
|
|
904
|
+
}): Promise<M | null>;
|
|
696
905
|
}
|
|
697
906
|
/**
|
|
698
907
|
* Session-level hooks for lifecycle events
|
|
@@ -703,45 +912,20 @@ interface SessionLifecycleHooks {
|
|
|
703
912
|
/** Called when session ends */
|
|
704
913
|
onSessionEnd?: SessionEndHook;
|
|
705
914
|
}
|
|
706
|
-
declare const createSession: <T extends ToolMap>({ threadId, agentName, maxTurns, metadata, runAgent,
|
|
707
|
-
|
|
915
|
+
declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentName, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, tools, processToolsInParallel, hooks, }: ZeitlichAgentConfig<T, M>) => Promise<ZeitlichSession<M>>;
|
|
708
916
|
/**
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
* @param subagents - Array of subagent configurations (must have at least one)
|
|
712
|
-
* @returns A tool definition with dynamic schema based on available subagents
|
|
917
|
+
* Proxy the default ZeitlichSharedActivities as ThreadOps<StoredMessage>.
|
|
918
|
+
* Call this in workflow code for the standard LangChain/StoredMessage setup.
|
|
713
919
|
*
|
|
714
920
|
* @example
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
* },
|
|
722
|
-
* ]);
|
|
723
|
-
*/
|
|
724
|
-
declare function createTaskTool<T extends SubagentConfig[]>(subagents: T): {
|
|
725
|
-
name: string;
|
|
726
|
-
description: string;
|
|
727
|
-
schema: z.ZodObject<{
|
|
728
|
-
subagent: z.ZodEnum<Record<string, string>>;
|
|
729
|
-
description: z.ZodString;
|
|
730
|
-
prompt: z.ZodString;
|
|
731
|
-
}>;
|
|
732
|
-
};
|
|
733
|
-
/**
|
|
734
|
-
* Infer the schema type for a task tool created with specific subagents
|
|
735
|
-
*/
|
|
736
|
-
type TaskToolSchemaType<T extends SubagentConfig[]> = z.infer<ReturnType<typeof createTaskTool<T>>["schema"]>;
|
|
737
|
-
/**
|
|
738
|
-
* Generic task tool schema type (when subagent names are not known at compile time)
|
|
921
|
+
* ```typescript
|
|
922
|
+
* const session = await createSession({
|
|
923
|
+
* threadOps: proxyDefaultThreadOps(),
|
|
924
|
+
* // ...
|
|
925
|
+
* });
|
|
926
|
+
* ```
|
|
739
927
|
*/
|
|
740
|
-
|
|
741
|
-
subagent: string;
|
|
742
|
-
description: string;
|
|
743
|
-
prompt: string;
|
|
744
|
-
};
|
|
928
|
+
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps<StoredMessage>;
|
|
745
929
|
|
|
746
930
|
/**
|
|
747
931
|
* Result from a task handler execution
|
|
@@ -758,7 +942,6 @@ interface TaskHandlerResult<TResult = unknown> {
|
|
|
758
942
|
* Note: runAgent is workflow-specific and should be created per-workflow
|
|
759
943
|
*/
|
|
760
944
|
interface ZeitlichSharedActivities {
|
|
761
|
-
appendSystemMessage(threadId: string, content: string): Promise<void>;
|
|
762
945
|
/**
|
|
763
946
|
* Append a tool result to the thread.
|
|
764
947
|
* Handles JSON serialization and optional cache points.
|
|
@@ -768,10 +951,6 @@ interface ZeitlichSharedActivities {
|
|
|
768
951
|
* Initialize an empty thread.
|
|
769
952
|
*/
|
|
770
953
|
initializeThread(threadId: string): Promise<void>;
|
|
771
|
-
/**
|
|
772
|
-
* Append a system message to a thread.
|
|
773
|
-
*/
|
|
774
|
-
appendSystemMessage(threadId: string, content: string): Promise<void>;
|
|
775
954
|
/**
|
|
776
955
|
* Append messages to a thread.
|
|
777
956
|
*/
|
|
@@ -809,9 +988,9 @@ declare const askUserQuestionTool: {
|
|
|
809
988
|
multiSelect: z.ZodBoolean;
|
|
810
989
|
}, z.core.$strip>>;
|
|
811
990
|
}, z.core.$strip>;
|
|
812
|
-
strict:
|
|
991
|
+
strict: true;
|
|
813
992
|
};
|
|
814
|
-
type
|
|
993
|
+
type AskUserQuestionArgs = z.infer<typeof askUserQuestionTool.schema>;
|
|
815
994
|
|
|
816
995
|
declare const globTool: {
|
|
817
996
|
name: "Glob";
|
|
@@ -820,9 +999,9 @@ declare const globTool: {
|
|
|
820
999
|
pattern: z$1.ZodString;
|
|
821
1000
|
root: z$1.ZodOptional<z$1.ZodString>;
|
|
822
1001
|
}, z$1.core.$strip>;
|
|
823
|
-
strict:
|
|
1002
|
+
strict: true;
|
|
824
1003
|
};
|
|
825
|
-
type
|
|
1004
|
+
type GlobArgs = z$1.infer<typeof globTool.schema>;
|
|
826
1005
|
|
|
827
1006
|
declare const grepTool: {
|
|
828
1007
|
name: "Grep";
|
|
@@ -835,9 +1014,9 @@ declare const grepTool: {
|
|
|
835
1014
|
excludePatterns: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
|
|
836
1015
|
contextLines: z$1.ZodOptional<z$1.ZodNumber>;
|
|
837
1016
|
}, z$1.core.$strip>;
|
|
838
|
-
strict:
|
|
1017
|
+
strict: true;
|
|
839
1018
|
};
|
|
840
|
-
type
|
|
1019
|
+
type GrepArgs = z$1.infer<typeof grepTool.schema>;
|
|
841
1020
|
|
|
842
1021
|
declare const readTool: {
|
|
843
1022
|
name: "FileRead";
|
|
@@ -847,9 +1026,9 @@ declare const readTool: {
|
|
|
847
1026
|
offset: z$1.ZodOptional<z$1.ZodNumber>;
|
|
848
1027
|
limit: z$1.ZodOptional<z$1.ZodNumber>;
|
|
849
1028
|
}, z$1.core.$strip>;
|
|
850
|
-
strict:
|
|
1029
|
+
strict: true;
|
|
851
1030
|
};
|
|
852
|
-
type
|
|
1031
|
+
type FileReadArgs = z$1.infer<typeof readTool.schema>;
|
|
853
1032
|
|
|
854
1033
|
declare const writeTool: {
|
|
855
1034
|
name: "FileWrite";
|
|
@@ -858,9 +1037,9 @@ declare const writeTool: {
|
|
|
858
1037
|
file_path: z$1.ZodString;
|
|
859
1038
|
content: z$1.ZodString;
|
|
860
1039
|
}, z$1.core.$strip>;
|
|
861
|
-
strict:
|
|
1040
|
+
strict: true;
|
|
862
1041
|
};
|
|
863
|
-
type
|
|
1042
|
+
type FileWriteArgs = z$1.infer<typeof writeTool.schema>;
|
|
864
1043
|
|
|
865
1044
|
declare const editTool: {
|
|
866
1045
|
name: "FileEdit";
|
|
@@ -871,9 +1050,29 @@ declare const editTool: {
|
|
|
871
1050
|
new_string: z$1.ZodString;
|
|
872
1051
|
replace_all: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
873
1052
|
}, z$1.core.$strip>;
|
|
874
|
-
strict:
|
|
1053
|
+
strict: true;
|
|
1054
|
+
};
|
|
1055
|
+
type FileEditArgs = z$1.infer<typeof editTool.schema>;
|
|
1056
|
+
|
|
1057
|
+
declare const taskCreateTool: {
|
|
1058
|
+
name: "TaskCreate";
|
|
1059
|
+
description: string;
|
|
1060
|
+
schema: z.ZodObject<{
|
|
1061
|
+
subject: z.ZodString;
|
|
1062
|
+
description: z.ZodString;
|
|
1063
|
+
activeForm: z.ZodString;
|
|
1064
|
+
metadata: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
1065
|
+
}, z.core.$strip>;
|
|
875
1066
|
};
|
|
876
|
-
type
|
|
1067
|
+
type TaskCreateArgs = z.infer<typeof taskCreateTool.schema>;
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* Creates a TaskCreate handler that adds tasks to the workflow state.
|
|
1071
|
+
*
|
|
1072
|
+
* @param stateManager - State manager containing tasks state
|
|
1073
|
+
* @returns A ToolHandler for TaskCreate tool calls
|
|
1074
|
+
*/
|
|
1075
|
+
declare function createTaskCreateHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>): ToolHandler<TaskCreateArgs, WorkflowTask>;
|
|
877
1076
|
|
|
878
1077
|
declare const taskGetTool: {
|
|
879
1078
|
name: "TaskGet";
|
|
@@ -882,36 +1081,30 @@ declare const taskGetTool: {
|
|
|
882
1081
|
taskId: z.ZodString;
|
|
883
1082
|
}, z.core.$strip>;
|
|
884
1083
|
};
|
|
885
|
-
type
|
|
1084
|
+
type TaskGetArgs = z.infer<typeof taskGetTool.schema>;
|
|
886
1085
|
|
|
887
1086
|
/**
|
|
888
1087
|
* Creates a TaskGet handler that retrieves a task by ID.
|
|
889
1088
|
*
|
|
890
1089
|
* @param stateManager - State manager containing tasks state
|
|
891
|
-
* @returns A tool
|
|
892
|
-
*
|
|
893
|
-
* @example
|
|
894
|
-
* const handler = createTaskGetHandler(stateManager);
|
|
1090
|
+
* @returns A ToolHandler for TaskGet tool calls
|
|
895
1091
|
*/
|
|
896
|
-
declare function createTaskGetHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>):
|
|
1092
|
+
declare function createTaskGetHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>): ToolHandler<TaskGetArgs, WorkflowTask | null>;
|
|
897
1093
|
|
|
898
1094
|
declare const taskListTool: {
|
|
899
1095
|
name: "TaskList";
|
|
900
1096
|
description: string;
|
|
901
1097
|
schema: z.ZodObject<{}, z.core.$strip>;
|
|
902
1098
|
};
|
|
903
|
-
type
|
|
1099
|
+
type TaskListArgs = z.infer<typeof taskListTool.schema>;
|
|
904
1100
|
|
|
905
1101
|
/**
|
|
906
1102
|
* Creates a TaskList handler that returns all tasks.
|
|
907
1103
|
*
|
|
908
1104
|
* @param stateManager - State manager containing tasks state
|
|
909
|
-
* @returns A tool
|
|
910
|
-
*
|
|
911
|
-
* @example
|
|
912
|
-
* const handler = createTaskListHandler(stateManager);
|
|
1105
|
+
* @returns A ToolHandler for TaskList tool calls
|
|
913
1106
|
*/
|
|
914
|
-
declare function createTaskListHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>):
|
|
1107
|
+
declare function createTaskListHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>): ToolHandler<TaskListArgs, WorkflowTask[]>;
|
|
915
1108
|
|
|
916
1109
|
declare const taskUpdateTool: {
|
|
917
1110
|
name: "TaskUpdate";
|
|
@@ -927,17 +1120,27 @@ declare const taskUpdateTool: {
|
|
|
927
1120
|
addBlocks: z.ZodArray<z.ZodString>;
|
|
928
1121
|
}, z.core.$strip>;
|
|
929
1122
|
};
|
|
930
|
-
type
|
|
1123
|
+
type TaskUpdateArgs = z.infer<typeof taskUpdateTool.schema>;
|
|
931
1124
|
|
|
932
1125
|
/**
|
|
933
1126
|
* Creates a TaskUpdate handler that modifies task status and dependencies.
|
|
934
1127
|
*
|
|
935
1128
|
* @param stateManager - State manager containing tasks state
|
|
936
|
-
* @returns A tool
|
|
937
|
-
*
|
|
938
|
-
* @example
|
|
939
|
-
* const handler = createTaskUpdateHandler(stateManager);
|
|
1129
|
+
* @returns A ToolHandler for TaskUpdate tool calls
|
|
940
1130
|
*/
|
|
941
|
-
declare function createTaskUpdateHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>):
|
|
1131
|
+
declare function createTaskUpdateHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>): ToolHandler<TaskUpdateArgs, WorkflowTask | null>;
|
|
1132
|
+
|
|
1133
|
+
declare const createBashToolDescription: ({ fileTree, }: {
|
|
1134
|
+
fileTree: string;
|
|
1135
|
+
}) => string;
|
|
1136
|
+
declare const bashTool: {
|
|
1137
|
+
name: "Bash";
|
|
1138
|
+
description: string;
|
|
1139
|
+
schema: z.ZodObject<{
|
|
1140
|
+
command: z.ZodString;
|
|
1141
|
+
}, z.core.$strip>;
|
|
1142
|
+
strict: true;
|
|
1143
|
+
};
|
|
1144
|
+
type BashArgs = z.infer<typeof bashTool.schema>;
|
|
942
1145
|
|
|
943
|
-
export { type
|
|
1146
|
+
export { type ThreadOps as $, type AgentResponse as A, type BashArgs as B, type RunAgentConfig as C, type SessionEndHookContext as D, type SessionExitReason as E, type FileEditArgs as F, type GlobArgs as G, type SessionLifecycleHooks as H, type InferToolResults as I, type JsonPrimitive as J, type SessionStartHook as K, type SessionStartHookContext as L, type SubagentConfig as M, type SubagentHooks as N, type SubagentInput as O, type ParsedToolCall as P, type TaskCreateArgs as Q, type RawToolCall as R, type SessionEndHook as S, type TaskArgs as T, type TaskGetArgs as U, type TaskHandlerResult as V, type TaskListArgs as W, type TaskStatus as X, type TaskUpdateArgs as Y, type ThreadManager as Z, type ThreadManagerConfig as _, type ActivityToolHandler as a, type ToolArgs as a0, type ToolCallResult as a1, type ToolCallResultUnion as a2, type ToolDefinition as a3, type ToolHandler as a4, type ToolHandlerContext as a5, type ToolHandlerResponse as a6, type ToolHooks as a7, type ToolMap as a8, type ToolMessageContent as a9, globTool as aA, grepTool as aB, hasNoOtherToolCalls as aC, isTerminalStatus as aD, proxyDefaultThreadOps as aE, readTool as aF, taskCreateTool as aG, taskGetTool as aH, taskListTool as aI, taskUpdateTool as aJ, withAutoAppend as aK, writeTool as aL, type ToolNames as aa, type ToolResult as ab, type ToolResultConfig as ac, type ToolRouter as ad, type ToolWithHandler as ae, type WorkflowTask as af, type ZeitlichAgentConfig as ag, type ZeitlichSession as ah, type ZeitlichSharedActivities as ai, askUserQuestionTool as aj, bashTool as ak, createAgentStateManager as al, createBashToolDescription as am, createSession as an, createSharedActivities as ao, createTaskCreateHandler as ap, createTaskGetHandler as aq, createTaskListHandler as ar, createTaskTool as as, createTaskUpdateHandler as at, createThreadManager as au, createToolRouter as av, defineSubagent as aw, defineTool as ax, editTool as ay, getStateQuery as az, type AskUserQuestionArgs as b, AGENT_HANDLER_NAMES as c, type AgentFile as d, type AgentState as e, type AgentStateManager as f, type AgentStatus as g, type AppendToolResultFn as h, type BaseAgentState as i, type BaseThreadManager as j, type FileReadArgs as k, type FileWriteArgs as l, type GrepArgs as m, type JsonSerializable as n, type JsonValue as o, type ParsedToolCallUnion as p, type PostToolUseFailureHook as q, type PostToolUseFailureHookContext as r, type PostToolUseFailureHookResult as s, type PostToolUseHook as t, type PostToolUseHookContext as u, type PreToolUseHook as v, type PreToolUseHookContext as w, type PreToolUseHookResult as x, type ProcessToolCallsContext as y, type RunAgentActivity as z };
|