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.
Files changed (135) hide show
  1. package/README.md +49 -38
  2. package/dist/adapters/sandbox/daytona/index.cjs +205 -0
  3. package/dist/adapters/sandbox/daytona/index.cjs.map +1 -0
  4. package/dist/adapters/sandbox/daytona/index.d.cts +86 -0
  5. package/dist/adapters/sandbox/daytona/index.d.ts +86 -0
  6. package/dist/adapters/sandbox/daytona/index.js +202 -0
  7. package/dist/adapters/sandbox/daytona/index.js.map +1 -0
  8. package/dist/adapters/sandbox/inmemory/index.cjs +174 -0
  9. package/dist/adapters/sandbox/inmemory/index.cjs.map +1 -0
  10. package/dist/adapters/sandbox/inmemory/index.d.cts +28 -0
  11. package/dist/adapters/sandbox/inmemory/index.d.ts +28 -0
  12. package/dist/adapters/sandbox/inmemory/index.js +172 -0
  13. package/dist/adapters/sandbox/inmemory/index.js.map +1 -0
  14. package/dist/adapters/sandbox/virtual/index.cjs +405 -0
  15. package/dist/adapters/sandbox/virtual/index.cjs.map +1 -0
  16. package/dist/adapters/sandbox/virtual/index.d.cts +85 -0
  17. package/dist/adapters/sandbox/virtual/index.d.ts +85 -0
  18. package/dist/adapters/sandbox/virtual/index.js +400 -0
  19. package/dist/adapters/sandbox/virtual/index.js.map +1 -0
  20. package/dist/adapters/thread/google-genai/index.cjs +284 -0
  21. package/dist/adapters/thread/google-genai/index.cjs.map +1 -0
  22. package/dist/adapters/thread/google-genai/index.d.cts +145 -0
  23. package/dist/adapters/thread/google-genai/index.d.ts +145 -0
  24. package/dist/adapters/thread/google-genai/index.js +278 -0
  25. package/dist/adapters/thread/google-genai/index.js.map +1 -0
  26. package/dist/adapters/{langchain → thread/langchain}/index.cjs +7 -9
  27. package/dist/adapters/thread/langchain/index.cjs.map +1 -0
  28. package/dist/adapters/{langchain → thread/langchain}/index.d.cts +17 -21
  29. package/dist/adapters/{langchain → thread/langchain}/index.d.ts +17 -21
  30. package/dist/adapters/{langchain → thread/langchain}/index.js +7 -9
  31. package/dist/adapters/thread/langchain/index.js.map +1 -0
  32. package/dist/index.cjs +816 -545
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +235 -74
  35. package/dist/index.d.ts +235 -74
  36. package/dist/index.js +804 -540
  37. package/dist/index.js.map +1 -1
  38. package/dist/types-B4C9txdq.d.ts +389 -0
  39. package/dist/{thread-manager-qc0g5Rvd.d.cts → types-B9ljZewB.d.cts} +1 -6
  40. package/dist/{thread-manager-qc0g5Rvd.d.ts → types-B9ljZewB.d.ts} +1 -6
  41. package/dist/types-BMXzv7TN.d.cts +476 -0
  42. package/dist/types-BMXzv7TN.d.ts +476 -0
  43. package/dist/types-BVP87m_W.d.cts +121 -0
  44. package/dist/types-CDubRtad.d.cts +115 -0
  45. package/dist/types-CDubRtad.d.ts +115 -0
  46. package/dist/types-CwwgQ_9H.d.ts +121 -0
  47. package/dist/types-GpMU4b0w.d.cts +389 -0
  48. package/dist/workflow.cjs +444 -318
  49. package/dist/workflow.cjs.map +1 -1
  50. package/dist/workflow.d.cts +271 -222
  51. package/dist/workflow.d.ts +271 -222
  52. package/dist/workflow.js +440 -316
  53. package/dist/workflow.js.map +1 -1
  54. package/package.json +59 -6
  55. package/src/adapters/sandbox/daytona/filesystem.ts +136 -0
  56. package/src/adapters/sandbox/daytona/index.ts +149 -0
  57. package/src/adapters/sandbox/daytona/types.ts +34 -0
  58. package/src/adapters/sandbox/inmemory/index.ts +213 -0
  59. package/src/adapters/sandbox/virtual/filesystem.ts +345 -0
  60. package/src/adapters/sandbox/virtual/index.ts +88 -0
  61. package/src/adapters/sandbox/virtual/mutations.ts +38 -0
  62. package/src/adapters/sandbox/virtual/provider.ts +101 -0
  63. package/src/adapters/sandbox/virtual/tree.ts +82 -0
  64. package/src/adapters/sandbox/virtual/types.ts +127 -0
  65. package/src/adapters/sandbox/virtual/virtual-sandbox.test.ts +523 -0
  66. package/src/adapters/sandbox/virtual/with-virtual-sandbox.ts +91 -0
  67. package/src/adapters/thread/google-genai/activities.ts +121 -0
  68. package/src/adapters/thread/google-genai/index.ts +41 -0
  69. package/src/adapters/thread/google-genai/model-invoker.ts +154 -0
  70. package/src/adapters/thread/google-genai/thread-manager.ts +169 -0
  71. package/src/adapters/{langchain → thread/langchain}/activities.ts +11 -15
  72. package/src/adapters/{langchain → thread/langchain}/index.ts +1 -1
  73. package/src/adapters/{langchain → thread/langchain}/model-invoker.ts +15 -18
  74. package/src/adapters/{langchain → thread/langchain}/thread-manager.ts +1 -1
  75. package/src/index.ts +32 -24
  76. package/src/lib/activity.ts +87 -0
  77. package/src/lib/hooks/index.ts +11 -0
  78. package/src/lib/hooks/types.ts +98 -0
  79. package/src/lib/model/helpers.ts +6 -0
  80. package/src/lib/model/index.ts +13 -0
  81. package/src/lib/{model-invoker.ts → model/types.ts} +18 -1
  82. package/src/lib/sandbox/index.ts +19 -0
  83. package/src/lib/sandbox/manager.ts +76 -0
  84. package/src/lib/sandbox/sandbox.test.ts +158 -0
  85. package/src/lib/{fs.ts → sandbox/tree.ts} +6 -6
  86. package/src/lib/sandbox/types.ts +164 -0
  87. package/src/lib/session/index.ts +11 -0
  88. package/src/lib/{session.ts → session/session.ts} +76 -48
  89. package/src/lib/session/types.ts +93 -0
  90. package/src/lib/skills/fs-provider.ts +16 -15
  91. package/src/lib/skills/handler.ts +31 -0
  92. package/src/lib/skills/index.ts +5 -1
  93. package/src/lib/skills/register.ts +20 -0
  94. package/src/lib/skills/tool.ts +47 -0
  95. package/src/lib/state/index.ts +9 -0
  96. package/src/lib/{state-manager.ts → state/manager.ts} +10 -147
  97. package/src/lib/state/types.ts +134 -0
  98. package/src/lib/subagent/define.ts +71 -0
  99. package/src/lib/subagent/handler.ts +99 -0
  100. package/src/lib/subagent/index.ts +13 -0
  101. package/src/lib/subagent/register.ts +53 -0
  102. package/src/lib/subagent/tool.ts +80 -0
  103. package/src/lib/subagent/types.ts +92 -0
  104. package/src/lib/thread/index.ts +7 -0
  105. package/src/lib/{thread-manager.ts → thread/manager.ts} +1 -33
  106. package/src/lib/thread/types.ts +33 -0
  107. package/src/lib/tool-router/auto-append.ts +55 -0
  108. package/src/lib/tool-router/index.ts +41 -0
  109. package/src/lib/tool-router/router.ts +462 -0
  110. package/src/lib/tool-router/types.ts +478 -0
  111. package/src/lib/tool-router/with-sandbox.ts +70 -0
  112. package/src/lib/types.ts +5 -382
  113. package/src/tools/bash/bash.test.ts +53 -55
  114. package/src/tools/bash/handler.ts +23 -51
  115. package/src/tools/edit/handler.ts +67 -81
  116. package/src/tools/glob/handler.ts +60 -17
  117. package/src/tools/read-file/handler.ts +67 -0
  118. package/src/tools/read-skill/handler.ts +1 -31
  119. package/src/tools/read-skill/tool.ts +5 -47
  120. package/src/tools/subagent/handler.ts +1 -100
  121. package/src/tools/subagent/tool.ts +5 -93
  122. package/src/tools/task-create/handler.ts +1 -1
  123. package/src/tools/task-get/handler.ts +1 -1
  124. package/src/tools/task-list/handler.ts +1 -1
  125. package/src/tools/task-update/handler.ts +1 -1
  126. package/src/tools/write-file/handler.ts +47 -0
  127. package/src/workflow.ts +88 -47
  128. package/tsup.config.ts +8 -1
  129. package/dist/adapters/langchain/index.cjs.map +0 -1
  130. package/dist/adapters/langchain/index.js.map +0 -1
  131. package/dist/model-invoker-y_zlyMqu.d.cts +0 -892
  132. package/dist/model-invoker-y_zlyMqu.d.ts +0 -892
  133. package/src/lib/tool-router.ts +0 -977
  134. package/src/lib/workflow-helpers.ts +0 -50
  135. /package/src/lib/{thread-id.ts → thread/id.ts} +0 -0
@@ -0,0 +1,389 @@
1
+ import { Duration } from '@temporalio/common';
2
+ import { a as ToolMap, b as ToolRouterHooks, M as MessageContent, S as SessionExitReason, c as ToolHandlerResponse, P as PreToolUseHookResult, d as PostToolUseFailureHookResult, e as RawToolCall, f as TokenUsage, B as BaseAgentState, g as RunAgentConfig, h as AgentStatus, W as WorkflowTask, i as ToolDefinition, j as ToolResultConfig, k as ToolCallResultUnion, I as InferToolResults } from './types-BMXzv7TN.cjs';
3
+ import { z } from 'zod';
4
+ import { g as SandboxOps } from './types-CDubRtad.cjs';
5
+ import { QueryDefinition } from '@temporalio/workflow';
6
+ import { UpdateDefinition } from '@temporalio/common/lib/interfaces';
7
+
8
+ /**
9
+ * Context for SessionStart hook - called when session begins
10
+ */
11
+ interface SessionStartHookContext {
12
+ threadId: string;
13
+ agentName: string;
14
+ metadata: Record<string, unknown>;
15
+ }
16
+ /**
17
+ * SessionStart hook - called when session begins
18
+ */
19
+ type SessionStartHook = (ctx: SessionStartHookContext) => void | Promise<void>;
20
+ /**
21
+ * Context for SessionEnd hook - called when session ends
22
+ */
23
+ interface SessionEndHookContext {
24
+ threadId: string;
25
+ agentName: string;
26
+ exitReason: SessionExitReason;
27
+ turns: number;
28
+ metadata: Record<string, unknown>;
29
+ }
30
+ /**
31
+ * SessionEnd hook - called when session ends
32
+ */
33
+ type SessionEndHook = (ctx: SessionEndHookContext) => void | Promise<void>;
34
+ /**
35
+ * Context for PreHumanMessageAppend hook - called before each human message is appended to the thread
36
+ */
37
+ interface PreHumanMessageAppendHookContext {
38
+ message: MessageContent;
39
+ threadId: string;
40
+ }
41
+ /**
42
+ * PreHumanMessageAppend hook - called before each human message is appended to the thread
43
+ */
44
+ type PreHumanMessageAppendHook = (ctx: PreHumanMessageAppendHookContext) => void | Promise<void>;
45
+ /**
46
+ * Context for PostHumanMessageAppend hook - called after each human message is appended to the thread
47
+ */
48
+ interface PostHumanMessageAppendHookContext {
49
+ message: MessageContent;
50
+ threadId: string;
51
+ }
52
+ /**
53
+ * PostHumanMessageAppend hook - called after each human message is appended to the thread
54
+ */
55
+ type PostHumanMessageAppendHook = (ctx: PostHumanMessageAppendHookContext) => void | Promise<void>;
56
+ /**
57
+ * Full hooks interface for a session — combines tool execution hooks
58
+ * (consumed by the router) with session/message lifecycle hooks
59
+ * (consumed directly by the session).
60
+ */
61
+ interface Hooks<T extends ToolMap, TResult = unknown> extends ToolRouterHooks<T, TResult> {
62
+ /** Called before each human message is appended to the thread */
63
+ onPreHumanMessageAppend?: PreHumanMessageAppendHook;
64
+ /** Called after each human message is appended to the thread */
65
+ onPostHumanMessageAppend?: PostHumanMessageAppendHook;
66
+ /** Called when session starts */
67
+ onSessionStart?: SessionStartHook;
68
+ /** Called when session ends */
69
+ onSessionEnd?: SessionEndHook;
70
+ }
71
+
72
+ /** ToolHandlerResponse with threadId required (subagents must always surface their thread) */
73
+ type SubagentHandlerResponse<TResult = null> = ToolHandlerResponse<TResult> & {
74
+ threadId: string;
75
+ };
76
+ type SubagentWorkflow<TResult extends z.ZodType = z.ZodType> = (input: SubagentInput) => Promise<SubagentHandlerResponse<z.infer<TResult> | null>>;
77
+ /**
78
+ * Configuration for a subagent that can be spawned by the parent workflow.
79
+ *
80
+ * @template TResult - Zod schema type for validating the child workflow's result
81
+ */
82
+ interface SubagentConfig<TResult extends z.ZodType = z.ZodType> {
83
+ /** Identifier used in Task tool's subagent parameter */
84
+ agentName: string;
85
+ /** Description shown to the parent agent explaining what this subagent does */
86
+ description: string;
87
+ /** Whether this subagent is available (default: true). Disabled subagents are excluded from the Subagent tool. */
88
+ enabled?: boolean;
89
+ /** Temporal workflow function or type name (used with executeChild) */
90
+ workflow: string | SubagentWorkflow<TResult>;
91
+ /** Optional task queue - defaults to parent's queue if not specified */
92
+ taskQueue?: string;
93
+ /** Optional Zod schema to validate the child workflow's result. If omitted, result is passed through as-is. */
94
+ resultSchema?: TResult;
95
+ /** Optional static context passed to the subagent on every invocation */
96
+ context?: Record<string, unknown>;
97
+ /** Allow the parent agent to pass a threadId for this subagent to continue (default: false) */
98
+ allowThreadContinuation?: boolean;
99
+ /** Per-subagent lifecycle hooks */
100
+ hooks?: SubagentHooks;
101
+ /**
102
+ * Sandbox strategy for this subagent.
103
+ * - `'inherit'` (default): reuse the parent's sandbox (shared filesystem/exec).
104
+ * - `'own'`: the child creates and owns its own sandbox.
105
+ */
106
+ sandbox?: "inherit" | "own";
107
+ }
108
+ /**
109
+ * Per-subagent lifecycle hooks - defined on a SubagentConfig.
110
+ * Runs in addition to global hooks (global pre → subagent pre → execute → subagent post → global post).
111
+ */
112
+ interface SubagentHooks<TArgs = unknown, TResult = unknown> {
113
+ /** Called before this subagent executes - can skip or modify args */
114
+ onPreExecution?: (ctx: {
115
+ args: TArgs;
116
+ threadId: string;
117
+ turn: number;
118
+ }) => PreToolUseHookResult | Promise<PreToolUseHookResult>;
119
+ /** Called after this subagent executes successfully */
120
+ onPostExecution?: (ctx: {
121
+ args: TArgs;
122
+ result: TResult;
123
+ threadId: string;
124
+ turn: number;
125
+ durationMs: number;
126
+ }) => void | Promise<void>;
127
+ /** Called when this subagent execution fails */
128
+ onExecutionFailure?: (ctx: {
129
+ args: TArgs;
130
+ error: Error;
131
+ threadId: string;
132
+ turn: number;
133
+ }) => PostToolUseFailureHookResult | Promise<PostToolUseFailureHookResult>;
134
+ }
135
+ /**
136
+ * Input passed to child workflows when spawned as subagents
137
+ */
138
+ interface SubagentInput {
139
+ /** The prompt/task from the parent agent */
140
+ prompt: string;
141
+ /** Optional context parameters passed from the parent agent */
142
+ context?: Record<string, unknown>;
143
+ /** When set, the subagent should continue this thread instead of starting a new one */
144
+ previousThreadId?: string;
145
+ /** Sandbox ID inherited from the parent agent (when SubagentConfig.sandbox is 'inherit') */
146
+ sandboxId?: string;
147
+ }
148
+
149
+ /**
150
+ * Skill metadata — the lightweight subset loaded at startup for all skills.
151
+ * Follows the agentskills.io specification frontmatter fields.
152
+ */
153
+ interface SkillMetadata {
154
+ /** Lowercase alphanumeric + hyphens, max 64 chars, must match directory name */
155
+ name: string;
156
+ /** What the skill does and when to use it (max 1024 chars) */
157
+ description: string;
158
+ /** License name or reference to a bundled license file */
159
+ license?: string;
160
+ /** Environment requirements (intended product, system packages, network access) */
161
+ compatibility?: string;
162
+ /** Arbitrary key-value pairs for additional metadata */
163
+ metadata?: Record<string, string>;
164
+ /** Space-delimited list of pre-approved tools the skill may use */
165
+ allowedTools?: string[];
166
+ }
167
+ /**
168
+ * A fully-loaded skill including the SKILL.md instruction body.
169
+ * Progressive disclosure: metadata is always available, instructions
170
+ * are loaded on-demand via the ReadSkill tool.
171
+ */
172
+ interface Skill extends SkillMetadata {
173
+ /** The markdown body of SKILL.md (everything after the frontmatter) */
174
+ instructions: string;
175
+ }
176
+ /**
177
+ * Abstraction for discovering and loading skills.
178
+ *
179
+ * Implement this interface to provide skills from any source
180
+ * (filesystem, database, API, in-memory, etc.).
181
+ */
182
+ interface SkillProvider {
183
+ /** Return lightweight metadata for all available skills */
184
+ listSkills(): Promise<SkillMetadata[]>;
185
+ /** Load a single skill with full instructions by name */
186
+ getSkill(name: string): Promise<Skill>;
187
+ }
188
+
189
+ /**
190
+ * Agent response from LLM invocation
191
+ */
192
+ interface AgentResponse<M = unknown> {
193
+ message: M;
194
+ rawToolCalls: RawToolCall[];
195
+ usage?: TokenUsage;
196
+ }
197
+ /**
198
+ * Type signature for workflow-specific runAgent activity
199
+ */
200
+ type RunAgentActivity<M = unknown> = (config: RunAgentConfig) => Promise<AgentResponse<M>>;
201
+ /**
202
+ * Configuration passed to a ModelInvoker.
203
+ * Includes the full agent state so adapters can read tools, system prompt,
204
+ * token usage, or any custom state fields for model configuration.
205
+ */
206
+ interface ModelInvokerConfig {
207
+ threadId: string;
208
+ agentName: string;
209
+ state: BaseAgentState;
210
+ metadata?: Record<string, unknown>;
211
+ }
212
+ /**
213
+ * Generic model invocation contract.
214
+ * Implementations load the thread, call the LLM, append the response,
215
+ * and return a normalised AgentResponse.
216
+ *
217
+ * Framework adapters (e.g. `zeitlich/langchain`) provide concrete
218
+ * implementations of this type.
219
+ */
220
+ type ModelInvoker<M = unknown> = (config: ModelInvokerConfig) => Promise<AgentResponse<M>>;
221
+
222
+ /**
223
+ * JSON primitive types that Temporal can serialize
224
+ */
225
+ type JsonPrimitive = string | number | boolean | null | undefined;
226
+ /**
227
+ * JSON-serializable value (recursive type for Temporal compatibility)
228
+ */
229
+ type JsonValue = JsonPrimitive | JsonValue[] | {
230
+ [key: string]: JsonValue;
231
+ };
232
+ /**
233
+ * Type constraint ensuring T only contains JSON-serializable values.
234
+ * Use this for custom state to ensure Temporal workflow compatibility.
235
+ *
236
+ * Allows: primitives, arrays, plain objects, and JsonValue
237
+ * Rejects: functions, symbols, undefined, class instances with methods
238
+ */
239
+ type JsonSerializable<T> = {
240
+ [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;
241
+ };
242
+ /**
243
+ * Full state type combining base state with custom state
244
+ */
245
+ type AgentState<TCustom extends JsonSerializable<TCustom>> = BaseAgentState & TCustom;
246
+ /**
247
+ * Agent state manager interface
248
+ * Note: Temporal handlers must be set up in the workflow file due to
249
+ * Temporal's workflow isolation requirements. This manager provides
250
+ * the state and helpers needed for those handlers.
251
+ */
252
+ interface AgentStateManager<TCustom extends JsonSerializable<TCustom>> {
253
+ /** Typed query definition registered for this agent's state */
254
+ readonly stateQuery: QueryDefinition<AgentState<TCustom>>;
255
+ /** Typed update definition registered for waiting on this agent's state change */
256
+ readonly stateChangeUpdate: UpdateDefinition<AgentState<TCustom>, [number]>;
257
+ /** Get current status */
258
+ getStatus(): AgentStatus;
259
+ /** Check if agent is running */
260
+ isRunning(): boolean;
261
+ /** Check if agent is in terminal state */
262
+ isTerminal(): boolean;
263
+ /** Get current state version */
264
+ getVersion(): number;
265
+ /** Set status to RUNNING */
266
+ run(): void;
267
+ /** Set status to WAITING_FOR_INPUT */
268
+ waitForInput(): void;
269
+ /** Set status to COMPLETED */
270
+ complete(): void;
271
+ /** Set status to FAILED */
272
+ fail(): void;
273
+ /** Set status to CANCELLED */
274
+ cancel(): void;
275
+ /** Increment state version (call after state changes) */
276
+ incrementVersion(): void;
277
+ /** Increment turns (call after each turn) */
278
+ incrementTurns(): void;
279
+ /** Get current turns */
280
+ getTurns(): number;
281
+ /** Get the system prompt */
282
+ getSystemPrompt(): string | undefined;
283
+ /** Set the system prompt */
284
+ setSystemPrompt(newSystemPrompt: string): void;
285
+ /** Get a custom state value by key */
286
+ get<K extends keyof TCustom>(key: K): TCustom[K];
287
+ /** Set a custom state value by key */
288
+ set<K extends keyof TCustom>(key: K, value: TCustom[K]): void;
289
+ /** Bulk-merge a partial update into custom state (e.g. from sandbox stateUpdate) */
290
+ mergeUpdate(update: Partial<TCustom>): void;
291
+ /** Get full state for query handler */
292
+ getCurrentState(): AgentState<TCustom>;
293
+ /** Check if should return from waitForStateChange */
294
+ shouldReturnFromWait(lastKnownVersion: number): boolean;
295
+ /** Get all tasks */
296
+ getTasks(): WorkflowTask[];
297
+ /** Get a task by ID */
298
+ getTask(id: string): WorkflowTask | undefined;
299
+ /** Add or update a task */
300
+ setTask(task: WorkflowTask): void;
301
+ /** Delete a task by ID */
302
+ deleteTask(id: string): boolean;
303
+ /** Set the tools (converts Zod schemas to JSON Schema for serialization) */
304
+ setTools(newTools: ToolDefinition[]): void;
305
+ /** Update the usage */
306
+ updateUsage(usage: TokenUsage): void;
307
+ /** Get the total usage */
308
+ getTotalUsage(): {
309
+ totalInputTokens: number;
310
+ totalOutputTokens: number;
311
+ totalCachedWriteTokens: number;
312
+ totalCachedReadTokens: number;
313
+ totalReasonTokens: number;
314
+ turns: number;
315
+ };
316
+ }
317
+
318
+ /**
319
+ * Thread operations required by a session.
320
+ * Consumers provide these — typically by wrapping Temporal activities.
321
+ */
322
+ interface ThreadOps {
323
+ /** Initialize an empty thread */
324
+ initializeThread(threadId: string): Promise<void>;
325
+ /** Append a human message to the thread */
326
+ appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
327
+ /** Append a tool result to the thread */
328
+ appendToolResult(config: ToolResultConfig): Promise<void>;
329
+ /** Append a system message to the thread */
330
+ appendSystemMessage(threadId: string, content: string): Promise<void>;
331
+ }
332
+ /**
333
+ * Configuration for a Zeitlich agent session
334
+ */
335
+ interface SessionConfig<T extends ToolMap, M = unknown> {
336
+ /** The name of the agent, should be unique within the workflows */
337
+ agentName: string;
338
+ /** The thread ID to use for the session (defaults to a short generated ID) */
339
+ threadId?: string;
340
+ /** Metadata for the session */
341
+ metadata?: Record<string, unknown>;
342
+ /** Whether to append the system prompt as message to the thread */
343
+ appendSystemPrompt?: boolean;
344
+ /** How many turns to run the session for */
345
+ maxTurns?: number;
346
+ /** Workflow-specific runAgent activity (with tools pre-bound) */
347
+ runAgent: RunAgentActivity<M>;
348
+ /** Thread operations (initialize, append messages, parse tool calls) */
349
+ threadOps?: ThreadOps;
350
+ /** Tool router for processing tool calls (optional if agent has no tools) */
351
+ tools?: T;
352
+ /** Subagent configurations */
353
+ subagents?: SubagentConfig[];
354
+ /** Skills available to this agent (metadata + instructions, loaded activity-side) */
355
+ skills?: Skill[];
356
+ /** Session lifecycle hooks */
357
+ hooks?: Hooks<T, ToolCallResultUnion<InferToolResults<T>>>;
358
+ /** Whether to process tools in parallel */
359
+ processToolsInParallel?: boolean;
360
+ /**
361
+ * Build context message content from agent-specific context.
362
+ * Returns MessageContent array for the initial HumanMessage.
363
+ */
364
+ buildContextMessage: () => MessageContent | Promise<MessageContent>;
365
+ /** When true, skip thread initialization and system prompt — append only the new human message to the existing thread. */
366
+ continueThread?: boolean;
367
+ /** How long to wait for input before cancelling the workflow */
368
+ waitForInputTimeout?: Duration;
369
+ /** Sandbox lifecycle operations (optional — omit for agents that don't need a sandbox) */
370
+ sandbox?: SandboxOps;
371
+ /**
372
+ * Pre-existing sandbox ID to reuse (e.g. inherited from a parent agent).
373
+ * When set, the session skips `createSandbox` and will not destroy the
374
+ * sandbox on exit (the owner is responsible for cleanup).
375
+ */
376
+ sandboxId?: string;
377
+ }
378
+ interface ZeitlichSession<M = unknown> {
379
+ runSession<T extends JsonSerializable<T>>(args: {
380
+ stateManager: AgentStateManager<T>;
381
+ }): Promise<{
382
+ threadId: string;
383
+ finalMessage: M | null;
384
+ exitReason: SessionExitReason;
385
+ usage: ReturnType<AgentStateManager<T>["getTotalUsage"]>;
386
+ }>;
387
+ }
388
+
389
+ export type { AgentResponse as A, Hooks as H, JsonPrimitive as J, ModelInvoker as M, PostHumanMessageAppendHook as P, RunAgentActivity as R, SkillProvider as S, ThreadOps as T, ZeitlichSession as Z, ModelInvokerConfig as a, SkillMetadata as b, Skill as c, AgentState as d, AgentStateManager as e, JsonSerializable as f, JsonValue as g, PostHumanMessageAppendHookContext as h, PreHumanMessageAppendHook as i, PreHumanMessageAppendHookContext as j, SessionConfig as k, SessionEndHook as l, SessionEndHookContext as m, SessionStartHook as n, SessionStartHookContext as o, SubagentConfig as p, SubagentHandlerResponse as q, SubagentHooks as r, SubagentInput as s, SubagentWorkflow as t };