zeitlich 0.2.25 → 0.2.26

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.
Files changed (111) hide show
  1. package/dist/activities-BEJRyDVU.d.cts +137 -0
  2. package/dist/activities-LVQdLF6I.d.ts +137 -0
  3. package/dist/adapters/sandbox/virtual/index.cjs.map +1 -1
  4. package/dist/adapters/sandbox/virtual/index.d.cts +8 -7
  5. package/dist/adapters/sandbox/virtual/index.d.ts +8 -7
  6. package/dist/adapters/sandbox/virtual/index.js.map +1 -1
  7. package/dist/adapters/sandbox/virtual/workflow.d.cts +3 -2
  8. package/dist/adapters/sandbox/virtual/workflow.d.ts +3 -2
  9. package/dist/adapters/thread/anthropic/index.cjs +356 -0
  10. package/dist/adapters/thread/anthropic/index.cjs.map +1 -0
  11. package/dist/adapters/thread/anthropic/index.d.cts +148 -0
  12. package/dist/adapters/thread/anthropic/index.d.ts +148 -0
  13. package/dist/adapters/thread/anthropic/index.js +351 -0
  14. package/dist/adapters/thread/anthropic/index.js.map +1 -0
  15. package/dist/adapters/thread/anthropic/workflow.cjs +38 -0
  16. package/dist/adapters/thread/anthropic/workflow.cjs.map +1 -0
  17. package/dist/adapters/thread/anthropic/workflow.d.cts +37 -0
  18. package/dist/adapters/thread/anthropic/workflow.d.ts +37 -0
  19. package/dist/adapters/thread/anthropic/workflow.js +36 -0
  20. package/dist/adapters/thread/anthropic/workflow.js.map +1 -0
  21. package/dist/adapters/thread/google-genai/index.cjs +95 -97
  22. package/dist/adapters/thread/google-genai/index.cjs.map +1 -1
  23. package/dist/adapters/thread/google-genai/index.d.cts +9 -111
  24. package/dist/adapters/thread/google-genai/index.d.ts +9 -111
  25. package/dist/adapters/thread/google-genai/index.js +96 -97
  26. package/dist/adapters/thread/google-genai/index.js.map +1 -1
  27. package/dist/adapters/thread/google-genai/workflow.cjs +9 -4
  28. package/dist/adapters/thread/google-genai/workflow.cjs.map +1 -1
  29. package/dist/adapters/thread/google-genai/workflow.d.cts +10 -5
  30. package/dist/adapters/thread/google-genai/workflow.d.ts +10 -5
  31. package/dist/adapters/thread/google-genai/workflow.js +9 -4
  32. package/dist/adapters/thread/google-genai/workflow.js.map +1 -1
  33. package/dist/adapters/thread/langchain/index.cjs +43 -60
  34. package/dist/adapters/thread/langchain/index.cjs.map +1 -1
  35. package/dist/adapters/thread/langchain/index.d.cts +24 -38
  36. package/dist/adapters/thread/langchain/index.d.ts +24 -38
  37. package/dist/adapters/thread/langchain/index.js +43 -60
  38. package/dist/adapters/thread/langchain/index.js.map +1 -1
  39. package/dist/adapters/thread/langchain/workflow.cjs +9 -4
  40. package/dist/adapters/thread/langchain/workflow.cjs.map +1 -1
  41. package/dist/adapters/thread/langchain/workflow.d.cts +10 -5
  42. package/dist/adapters/thread/langchain/workflow.d.ts +10 -5
  43. package/dist/adapters/thread/langchain/workflow.js +9 -4
  44. package/dist/adapters/thread/langchain/workflow.js.map +1 -1
  45. package/dist/index.cjs +27 -10
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.d.cts +13 -12
  48. package/dist/index.d.ts +13 -12
  49. package/dist/index.js +28 -11
  50. package/dist/index.js.map +1 -1
  51. package/dist/proxy-BK1ydQt0.d.ts +24 -0
  52. package/dist/proxy-BMAsMHdp.d.cts +24 -0
  53. package/dist/{queries-DwBe2CAA.d.ts → queries-BCgJ9Sr5.d.ts} +1 -1
  54. package/dist/{queries-BYGBImeC.d.cts → queries-DwnE2bu3.d.cts} +1 -1
  55. package/dist/thread-manager-CH9krS3h.d.ts +37 -0
  56. package/dist/thread-manager-Czhpxbt6.d.ts +29 -0
  57. package/dist/thread-manager-DOnQzImf.d.cts +29 -0
  58. package/dist/thread-manager-b4DML-qu.d.cts +37 -0
  59. package/dist/{types-35POpVfa.d.ts → types-BDRDbm3h.d.cts} +22 -1
  60. package/dist/{types-hmferhc2.d.ts → types-CvJyXDYt.d.ts} +44 -123
  61. package/dist/{types-LVKmCNds.d.ts → types-DFUNSYbj.d.ts} +1 -1
  62. package/dist/{types-Bf8KV0Ci.d.cts → types-DRnz-OZp.d.cts} +1 -1
  63. package/dist/{types-7PeMi1bD.d.cts → types-DSOefLpY.d.cts} +44 -123
  64. package/dist/{types-35POpVfa.d.cts → types-WNSeZbWa.d.ts} +22 -1
  65. package/dist/{types-D_igp10o.d.cts → types-mCVxKIZb.d.cts} +233 -137
  66. package/dist/{types-D_igp10o.d.ts → types-mCVxKIZb.d.ts} +233 -137
  67. package/dist/workflow.cjs +25 -9
  68. package/dist/workflow.cjs.map +1 -1
  69. package/dist/workflow.d.cts +11 -11
  70. package/dist/workflow.d.ts +11 -11
  71. package/dist/workflow.js +26 -10
  72. package/dist/workflow.js.map +1 -1
  73. package/package.json +26 -1
  74. package/src/adapters/sandbox/virtual/with-virtual-sandbox.ts +8 -3
  75. package/src/adapters/thread/anthropic/activities.ts +223 -0
  76. package/src/adapters/thread/anthropic/index.ts +44 -0
  77. package/src/adapters/thread/anthropic/model-invoker.ts +124 -0
  78. package/src/adapters/thread/anthropic/proxy.ts +33 -0
  79. package/src/adapters/thread/anthropic/thread-manager.ts +191 -0
  80. package/src/adapters/thread/google-genai/activities.ts +107 -32
  81. package/src/adapters/thread/google-genai/index.ts +3 -1
  82. package/src/adapters/thread/google-genai/model-invoker.ts +7 -40
  83. package/src/adapters/thread/google-genai/proxy.ts +6 -34
  84. package/src/adapters/thread/google-genai/thread-manager.ts +84 -104
  85. package/src/adapters/thread/langchain/activities.ts +53 -20
  86. package/src/adapters/thread/langchain/index.ts +3 -1
  87. package/src/adapters/thread/langchain/model-invoker.ts +7 -9
  88. package/src/adapters/thread/langchain/proxy.ts +6 -34
  89. package/src/adapters/thread/langchain/thread-manager.ts +44 -98
  90. package/src/index.ts +5 -1
  91. package/src/lib/activity.ts +4 -3
  92. package/src/lib/hooks/types.ts +12 -12
  93. package/src/lib/model/types.ts +2 -0
  94. package/src/lib/session/session-edge-cases.integration.test.ts +24 -6
  95. package/src/lib/session/session.ts +18 -14
  96. package/src/lib/session/types.ts +31 -14
  97. package/src/lib/subagent/handler.ts +15 -8
  98. package/src/lib/subagent/types.ts +3 -2
  99. package/src/lib/thread/index.ts +2 -0
  100. package/src/lib/thread/manager.ts +4 -7
  101. package/src/lib/thread/proxy.ts +57 -0
  102. package/src/lib/thread/types.ts +31 -0
  103. package/src/lib/tool-router/auto-append-sandbox.integration.test.ts +54 -0
  104. package/src/lib/tool-router/auto-append.ts +5 -2
  105. package/src/lib/tool-router/router-edge-cases.integration.test.ts +9 -5
  106. package/src/lib/tool-router/router.ts +13 -7
  107. package/src/lib/tool-router/types.ts +20 -13
  108. package/src/lib/tool-router/with-sandbox.ts +4 -3
  109. package/src/lib/types.ts +7 -14
  110. package/src/workflow.ts +0 -4
  111. package/tsup.config.ts +5 -0
@@ -1,130 +1,6 @@
1
+ import { ActivityFunctionWithOptions, QueryDefinition } from '@temporalio/workflow';
2
+ import { UpdateDefinition } from '@temporalio/common/lib/interfaces';
1
3
  import { z } from 'zod';
2
- import { ActivityFunctionWithOptions } from '@temporalio/workflow';
3
-
4
- /** A single content part within a structured message (text, image, etc.) */
5
- type ContentPart = {
6
- type: string;
7
- [key: string]: unknown;
8
- };
9
- /** Message content — plain string or an array of structured content parts */
10
- type MessageContent = string | ContentPart[];
11
- /** Content returned by a tool handler */
12
- type ToolMessageContent = MessageContent;
13
- /**
14
- * Agent execution status
15
- */
16
- type AgentStatus = "RUNNING" | "WAITING_FOR_INPUT" | "COMPLETED" | "FAILED" | "CANCELLED";
17
- /**
18
- * Base state that all agents must have
19
- */
20
- interface BaseAgentState {
21
- tools: SerializableToolDefinition[];
22
- status: AgentStatus;
23
- version: number;
24
- turns: number;
25
- tasks: Map<string, WorkflowTask>;
26
- systemPrompt?: string;
27
- totalInputTokens: number;
28
- totalOutputTokens: number;
29
- cachedWriteTokens: number;
30
- cachedReadTokens: number;
31
- }
32
- /**
33
- * File representation for agent workflows
34
- */
35
- interface AgentFile {
36
- /** Database/S3 file ID */
37
- id: string;
38
- /** Virtual path for agent (e.g., "evidence/invoice.pdf") */
39
- path: string;
40
- /** Original filename */
41
- filename: string;
42
- /** Generic description for prompt */
43
- description?: string;
44
- /** MIME type of the file */
45
- mimeType?: string;
46
- }
47
- interface TokenUsage {
48
- inputTokens?: number;
49
- outputTokens?: number;
50
- cachedWriteTokens?: number;
51
- cachedReadTokens?: number;
52
- reasonTokens?: number;
53
- }
54
- /**
55
- * Configuration for a Zeitlich agent
56
- */
57
- interface AgentConfig {
58
- /** The name of the agent, should be unique within the workflows, ideally Pascal Case */
59
- agentName: string;
60
- /** Description, used for sub agents */
61
- description?: string;
62
- }
63
- /**
64
- * A JSON-serializable tool definition for state storage.
65
- * Uses a plain JSON Schema object instead of a live Zod instance,
66
- * so it survives Temporal serialization without losing constraints (min, max, etc.).
67
- */
68
- interface SerializableToolDefinition {
69
- name: string;
70
- description: string;
71
- schema: Record<string, unknown>;
72
- strict?: boolean;
73
- max_uses?: number;
74
- }
75
- /**
76
- * Configuration passed to runAgent activity
77
- */
78
- interface RunAgentConfig extends AgentConfig {
79
- /** The thread ID to use for the session */
80
- threadId: string;
81
- /** Metadata for the session */
82
- metadata?: Record<string, unknown>;
83
- }
84
- /**
85
- * Configuration for appending a tool result
86
- */
87
- interface ToolResultConfig {
88
- threadId: string;
89
- toolCallId: string;
90
- /** The name of the tool that produced this result */
91
- toolName: string;
92
- /** Content for the tool message (string or complex content parts) */
93
- content: ToolMessageContent;
94
- }
95
- /**
96
- * Status of a workflow task
97
- */
98
- type TaskStatus = "pending" | "in_progress" | "completed";
99
- /**
100
- * A task managed within a workflow for tracking work items
101
- */
102
- interface WorkflowTask {
103
- /** Unique task identifier */
104
- id: string;
105
- /** Brief, actionable title in imperative form */
106
- subject: string;
107
- /** Detailed description of what needs to be done */
108
- description: string;
109
- /** Present continuous form shown in spinner when in_progress */
110
- activeForm: string;
111
- /** Current status of the task */
112
- status: TaskStatus;
113
- /** Arbitrary key-value pairs for tracking */
114
- metadata: Record<string, string>;
115
- /** IDs of tasks that must complete before this one can start */
116
- blockedBy: string[];
117
- /** IDs of tasks that are waiting for this one to complete */
118
- blocks: string[];
119
- }
120
- /**
121
- * Exit reasons for session termination
122
- */
123
- type SessionExitReason = "completed" | "max_turns" | "waiting_for_input" | "failed" | "cancelled";
124
- /**
125
- * Helper to check if status is terminal
126
- */
127
- declare function isTerminalStatus(status: AgentStatus): boolean;
128
4
 
129
5
  /**
130
6
  * A tool definition with a name, description, and Zod schema for arguments.
@@ -141,11 +17,11 @@ interface ToolDefinition<TName extends string = string, TSchema extends z.ZodTyp
141
17
  * A tool definition with an integrated handler function.
142
18
  * This is the primary type for defining tools in the router.
143
19
  */
144
- interface ToolWithHandler<TName extends string = string, TSchema extends z.ZodType = z.ZodType, TResult = unknown, TContext extends RouterContext = RouterContext> {
20
+ interface ToolWithHandler<TName extends string = string, TSchema extends z.ZodType = z.ZodType, TResult = unknown, TContext extends RouterContext = RouterContext, TToolResponse = JsonValue> {
145
21
  name: TName;
146
22
  description: string;
147
23
  schema: TSchema;
148
- handler: ToolHandler<z.infer<TSchema>, TResult, TContext>;
24
+ handler: ToolHandler<z.infer<TSchema>, TResult, TContext, TToolResponse>;
149
25
  strict?: boolean;
150
26
  max_uses?: number;
151
27
  /** Whether this tool is available to the agent (default: true). Disabled tools are excluded from definitions and rejected at parse time. */
@@ -165,7 +41,7 @@ type ToolMap = Record<string, {
165
41
  name: string;
166
42
  description: string | (() => string);
167
43
  schema: z.ZodType | (() => z.ZodType);
168
- handler: ToolHandler<any, any, any>;
44
+ handler: ToolHandler<any, any, any, any>;
169
45
  strict?: boolean;
170
46
  max_uses?: number;
171
47
  enabled?: boolean | (() => boolean);
@@ -208,9 +84,9 @@ type AppendToolResultFn = ActivityFunctionWithOptions<(id: string, config: ToolR
208
84
  * Tools that don't return additional data should use `data: null` (TResult defaults to null).
209
85
  * Tools that may fail to produce data should type TResult as `SomeType | null`.
210
86
  */
211
- interface ToolHandlerResponse<TResult = null> {
87
+ interface ToolHandlerResponse<TResult = null, TToolResponse = JsonValue> {
212
88
  /** Content sent back to the LLM as the tool call response */
213
- toolResponse: ToolMessageContent;
89
+ toolResponse: TToolResponse;
214
90
  /** Data returned to the workflow and hooks for further processing */
215
91
  data: TResult;
216
92
  /**
@@ -235,6 +111,8 @@ interface ToolHandlerResponse<TResult = null> {
235
111
  */
236
112
  interface RouterContext {
237
113
  threadId: string;
114
+ /** Redis key suffix for thread storage. Defaults to 'messages'. */
115
+ threadKey?: string;
238
116
  toolCallId: string;
239
117
  toolName: string;
240
118
  sandboxId?: string;
@@ -246,7 +124,7 @@ interface RouterContext {
246
124
  * Receives the parsed args and a context that always includes {@link RouterContext}
247
125
  * fields, plus any additional properties when TContext extends RouterContext.
248
126
  */
249
- type ToolHandler<TArgs, TResult, TContext extends RouterContext = RouterContext> = (args: TArgs, context: TContext) => ToolHandlerResponse<TResult> | Promise<ToolHandlerResponse<TResult>>;
127
+ type ToolHandler<TArgs, TResult, TContext extends RouterContext = RouterContext, TToolResponse = JsonValue> = (args: TArgs, context: TContext) => ToolHandlerResponse<TResult, TToolResponse> | Promise<ToolHandlerResponse<TResult, TToolResponse>>;
250
128
  /**
251
129
  * Activity-compatible tool handler that always returns a Promise.
252
130
  * Use this for tool handlers registered as Temporal activities.
@@ -263,7 +141,7 @@ type ToolHandler<TArgs, TResult, TContext extends RouterContext = RouterContext>
263
141
  * };
264
142
  * ```
265
143
  */
266
- type ActivityToolHandler<TArgs, TResult, TContext extends RouterContext = RouterContext> = (args: TArgs, context: TContext) => Promise<ToolHandlerResponse<TResult>>;
144
+ type ActivityToolHandler<TArgs, TResult, TContext extends RouterContext = RouterContext, TToolResponse = JsonValue> = (args: TArgs, context: TContext) => Promise<ToolHandlerResponse<TResult, TToolResponse>>;
267
145
  /**
268
146
  * Extract the args type for a specific tool name from a tool map.
269
147
  */
@@ -275,7 +153,7 @@ type ToolArgs<T extends ToolMap, TName extends ToolNames<T>> = z.infer<Extract<T
275
153
  */
276
154
  type ToolResult<T extends ToolMap, TName extends ToolNames<T>> = Extract<T[keyof T], {
277
155
  name: TName;
278
- }>["handler"] extends ToolHandler<unknown, infer R, RouterContext> ? Awaited<R> : never;
156
+ }>["handler"] extends ToolHandler<unknown, infer R, RouterContext, any> ? Awaited<R> : never;
279
157
  /**
280
158
  * The result of processing a tool call.
281
159
  */
@@ -291,7 +169,7 @@ interface ToolCallResult<TName extends string = string, TResult = unknown> {
291
169
  * Infer result types from a tool map based on handler return types.
292
170
  */
293
171
  type InferToolResults<T extends ToolMap> = {
294
- [K in keyof T as T[K]["name"]]: T[K]["handler"] extends ToolHandler<any, infer R, any> ? Awaited<R> : never;
172
+ [K in keyof T as T[K]["name"]]: T[K]["handler"] extends ToolHandler<any, infer R, any, any> ? Awaited<R> : never;
295
173
  };
296
174
  /**
297
175
  * Union of all possible tool call results based on handler return types.
@@ -324,7 +202,7 @@ interface PreToolUseHookResult {
324
202
  */
325
203
  interface PostToolUseFailureHookResult {
326
204
  /** Provide a fallback result instead of throwing */
327
- fallbackContent?: ToolMessageContent;
205
+ fallbackContent?: JsonValue;
328
206
  /** Whether to suppress the error (still logs, but continues) */
329
207
  suppress?: boolean;
330
208
  }
@@ -427,6 +305,8 @@ interface ToolRouterOptions<T extends ToolMap> {
427
305
  tools: T;
428
306
  /** Thread ID for appending tool results */
429
307
  threadId: string;
308
+ /** Redis key suffix for thread storage. Defaults to 'messages'. */
309
+ threadKey?: string;
430
310
  /** Function to append tool results to the thread (called automatically after each handler).
431
311
  * Accepts a Temporal activity proxy with {@link ActivityFunctionWithOptions}. */
432
312
  appendToolResult: AppendToolResultFn;
@@ -486,4 +366,220 @@ interface ToolRouter<T extends ToolMap> {
486
366
  getResultsByName<TName extends ToolNames<T>>(results: ToolCallResultUnion<InferToolResults<T>>[], name: TName): ToolCallResult<TName, ToolResult<T, TName>>[];
487
367
  }
488
368
 
489
- export { type ActivityToolHandler as A, type BaseAgentState as B, type ContentPart as C, type ToolCallResult as D, type ToolHandler as E, type ToolHooks as F, type ToolNames as G, type ToolResult as H, type InferToolResults as I, type ToolRouter as J, type ToolWithHandler as K, isTerminalStatus as L, type MessageContent as M, type ToolRouterOptions as N, type PreToolUseHookResult as P, type RouterContext as R, type SessionExitReason as S, type ToolMessageContent as T, type WorkflowTask as W, type ToolMap as a, type ToolRouterHooks as b, type ToolHandlerResponse as c, type PostToolUseFailureHookResult as d, type RawToolCall as e, type TokenUsage as f, type RunAgentConfig as g, type AgentStatus as h, type ToolDefinition as i, type ToolResultConfig as j, type ToolCallResultUnion as k, type AgentConfig as l, type AgentFile as m, type AppendToolResultFn as n, type ParsedToolCall as o, type ParsedToolCallUnion as p, type PostToolUseFailureHook as q, type PostToolUseFailureHookContext as r, type PostToolUseHook as s, type PostToolUseHookContext as t, type PreToolUseHook as u, type PreToolUseHookContext as v, type ProcessToolCallsContext as w, type SerializableToolDefinition as x, type TaskStatus as y, type ToolArgs as z };
369
+ /**
370
+ * JSON primitive types that Temporal can serialize
371
+ */
372
+ type JsonPrimitive = string | number | boolean | null | undefined;
373
+ /**
374
+ * JSON-serializable value (recursive type for Temporal compatibility)
375
+ */
376
+ type JsonValue = JsonPrimitive | JsonValue[] | {
377
+ [key: string]: JsonValue;
378
+ };
379
+ /**
380
+ * Type constraint ensuring T only contains JSON-serializable values.
381
+ * Use this for custom state to ensure Temporal workflow compatibility.
382
+ *
383
+ * Allows: primitives, arrays, plain objects, and JsonValue
384
+ * Rejects: functions, symbols, undefined, class instances with methods
385
+ */
386
+ type JsonSerializable<T> = {
387
+ [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;
388
+ };
389
+ /**
390
+ * Full state type combining base state with custom state
391
+ */
392
+ type AgentState<TCustom extends JsonSerializable<TCustom>> = BaseAgentState & TCustom;
393
+ /**
394
+ * Agent state manager interface
395
+ * Note: Temporal handlers must be set up in the workflow file due to
396
+ * Temporal's workflow isolation requirements. This manager provides
397
+ * the state and helpers needed for those handlers.
398
+ */
399
+ interface AgentStateManager<TCustom extends JsonSerializable<TCustom>> {
400
+ /** Typed query definition registered for this agent's state */
401
+ readonly stateQuery: QueryDefinition<AgentState<TCustom>>;
402
+ /** Typed update definition registered for waiting on this agent's state change */
403
+ readonly stateChangeUpdate: UpdateDefinition<AgentState<TCustom>, [number]>;
404
+ /** Get current status */
405
+ getStatus(): AgentStatus;
406
+ /** Check if agent is running */
407
+ isRunning(): boolean;
408
+ /** Check if agent is in terminal state */
409
+ isTerminal(): boolean;
410
+ /** Get current state version */
411
+ getVersion(): number;
412
+ /** Set status to RUNNING */
413
+ run(): void;
414
+ /** Set status to WAITING_FOR_INPUT */
415
+ waitForInput(): void;
416
+ /** Set status to COMPLETED */
417
+ complete(): void;
418
+ /** Set status to FAILED */
419
+ fail(): void;
420
+ /** Set status to CANCELLED */
421
+ cancel(): void;
422
+ /** Increment state version (call after state changes) */
423
+ incrementVersion(): void;
424
+ /** Increment turns (call after each turn) */
425
+ incrementTurns(): void;
426
+ /** Get current turns */
427
+ getTurns(): number;
428
+ /** Get the system prompt */
429
+ getSystemPrompt(): string | undefined;
430
+ /** Set the system prompt */
431
+ setSystemPrompt(newSystemPrompt: string): void;
432
+ /** Get a custom state value by key */
433
+ get<K extends keyof TCustom>(key: K): TCustom[K];
434
+ /** Set a custom state value by key */
435
+ set<K extends keyof TCustom>(key: K, value: TCustom[K]): void;
436
+ /** Bulk-merge a partial update into custom state (e.g. from sandbox stateUpdate) */
437
+ mergeUpdate(update: Partial<TCustom>): void;
438
+ /** Get full state for query handler */
439
+ getCurrentState(): AgentState<TCustom>;
440
+ /** Check if should return from waitForStateChange */
441
+ shouldReturnFromWait(lastKnownVersion: number): boolean;
442
+ /** Get all tasks */
443
+ getTasks(): WorkflowTask[];
444
+ /** Get a task by ID */
445
+ getTask(id: string): WorkflowTask | undefined;
446
+ /** Add or update a task */
447
+ setTask(task: WorkflowTask): void;
448
+ /** Delete a task by ID */
449
+ deleteTask(id: string): boolean;
450
+ /** Set the tools (converts Zod schemas to JSON Schema for serialization) */
451
+ setTools(newTools: ToolDefinition[]): void;
452
+ /** Update the usage */
453
+ updateUsage(usage: TokenUsage): void;
454
+ /** Get the total usage */
455
+ getTotalUsage(): {
456
+ totalInputTokens: number;
457
+ totalOutputTokens: number;
458
+ totalCachedWriteTokens: number;
459
+ totalCachedReadTokens: number;
460
+ totalReasonTokens: number;
461
+ turns: number;
462
+ };
463
+ }
464
+
465
+ /**
466
+ * Agent execution status
467
+ */
468
+ type AgentStatus = "RUNNING" | "WAITING_FOR_INPUT" | "COMPLETED" | "FAILED" | "CANCELLED";
469
+ /**
470
+ * Base state that all agents must have
471
+ */
472
+ interface BaseAgentState {
473
+ tools: SerializableToolDefinition[];
474
+ status: AgentStatus;
475
+ version: number;
476
+ turns: number;
477
+ tasks: Map<string, WorkflowTask>;
478
+ systemPrompt?: string;
479
+ totalInputTokens: number;
480
+ totalOutputTokens: number;
481
+ cachedWriteTokens: number;
482
+ cachedReadTokens: number;
483
+ }
484
+ /**
485
+ * File representation for agent workflows
486
+ */
487
+ interface AgentFile {
488
+ /** Database/S3 file ID */
489
+ id: string;
490
+ /** Virtual path for agent (e.g., "evidence/invoice.pdf") */
491
+ path: string;
492
+ /** Original filename */
493
+ filename: string;
494
+ /** Generic description for prompt */
495
+ description?: string;
496
+ /** MIME type of the file */
497
+ mimeType?: string;
498
+ }
499
+ interface TokenUsage {
500
+ inputTokens?: number;
501
+ outputTokens?: number;
502
+ cachedWriteTokens?: number;
503
+ cachedReadTokens?: number;
504
+ reasonTokens?: number;
505
+ }
506
+ /**
507
+ * Configuration for a Zeitlich agent
508
+ */
509
+ interface AgentConfig {
510
+ /** The name of the agent, should be unique within the workflows, ideally Pascal Case */
511
+ agentName: string;
512
+ /** Description, used for sub agents */
513
+ description?: string;
514
+ }
515
+ /**
516
+ * A JSON-serializable tool definition for state storage.
517
+ * Uses a plain JSON Schema object instead of a live Zod instance,
518
+ * so it survives Temporal serialization without losing constraints (min, max, etc.).
519
+ */
520
+ interface SerializableToolDefinition {
521
+ name: string;
522
+ description: string;
523
+ schema: Record<string, unknown>;
524
+ strict?: boolean;
525
+ max_uses?: number;
526
+ }
527
+ /**
528
+ * Configuration passed to runAgent activity
529
+ */
530
+ interface RunAgentConfig extends AgentConfig {
531
+ /** The thread ID to use for the session */
532
+ threadId: string;
533
+ /** Redis key suffix for thread storage. Defaults to 'messages'. */
534
+ threadKey?: string;
535
+ /** Metadata for the session */
536
+ metadata?: Record<string, unknown>;
537
+ }
538
+ /**
539
+ * Configuration for appending a tool result
540
+ */
541
+ interface ToolResultConfig {
542
+ threadId: string;
543
+ /** Redis key suffix for thread storage. Defaults to 'messages'. */
544
+ threadKey?: string;
545
+ toolCallId: string;
546
+ /** The name of the tool that produced this result */
547
+ toolName: string;
548
+ /** Content for the tool result — string, object, or array. The adapter converts to its SDK-native format. */
549
+ content: JsonValue;
550
+ }
551
+ /**
552
+ * Status of a workflow task
553
+ */
554
+ type TaskStatus = "pending" | "in_progress" | "completed";
555
+ /**
556
+ * A task managed within a workflow for tracking work items
557
+ */
558
+ interface WorkflowTask {
559
+ /** Unique task identifier */
560
+ id: string;
561
+ /** Brief, actionable title in imperative form */
562
+ subject: string;
563
+ /** Detailed description of what needs to be done */
564
+ description: string;
565
+ /** Present continuous form shown in spinner when in_progress */
566
+ activeForm: string;
567
+ /** Current status of the task */
568
+ status: TaskStatus;
569
+ /** Arbitrary key-value pairs for tracking */
570
+ metadata: Record<string, string>;
571
+ /** IDs of tasks that must complete before this one can start */
572
+ blockedBy: string[];
573
+ /** IDs of tasks that are waiting for this one to complete */
574
+ blocks: string[];
575
+ }
576
+ /**
577
+ * Exit reasons for session termination
578
+ */
579
+ type SessionExitReason = "completed" | "max_turns" | "waiting_for_input" | "failed" | "cancelled";
580
+ /**
581
+ * Helper to check if status is terminal
582
+ */
583
+ declare function isTerminalStatus(status: AgentStatus): boolean;
584
+
585
+ export { type ActivityToolHandler as A, type BaseAgentState as B, type TaskStatus as C, type ToolArgs as D, type ToolCallResult as E, type ToolDefinition as F, type ToolHandler as G, type ToolHooks as H, type InferToolResults as I, type JsonValue as J, type ToolNames as K, type ToolResult as L, type ToolRouter as M, type ToolWithHandler as N, isTerminalStatus as O, type PreToolUseHookResult as P, type ToolRouterOptions as Q, type RouterContext as R, type SessionExitReason as S, type ToolHandlerResponse as T, type WorkflowTask as W, type ToolMap as a, type ToolRouterHooks as b, type PostToolUseFailureHookResult as c, type RawToolCall as d, type TokenUsage as e, type RunAgentConfig as f, type ToolResultConfig as g, type ToolCallResultUnion as h, type JsonSerializable as i, type AgentStateManager as j, type AgentConfig as k, type AgentFile as l, type AgentState as m, type AgentStatus as n, type AppendToolResultFn as o, type JsonPrimitive as p, type ParsedToolCall as q, type ParsedToolCallUnion as r, type PostToolUseFailureHook as s, type PostToolUseFailureHookContext as t, type PostToolUseHook as u, type PostToolUseHookContext as v, type PreToolUseHook as w, type PreToolUseHookContext as x, type ProcessToolCallsContext as y, type SerializableToolDefinition as z };