zeitlich 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bead AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,494 @@
1
+ # Zeitlich
2
+
3
+ > **⚠️ Experimental Beta**: This library is under active development. APIs and interfaces may change between versions. Use in production at your own risk.
4
+
5
+ **Durable AI Agents for Temporal**
6
+
7
+ Zeitlich is an opinionated framework for building reliable, stateful AI agents using [Temporal](https://temporal.io). It provides the building blocks for creating agents that can survive crashes, handle long-running tasks, and coordinate with other agents—all with full type safety.
8
+
9
+ ## Why Zeitlich?
10
+
11
+ Building production AI agents is hard. Agents need to:
12
+
13
+ - **Survive failures** — What happens when your agent crashes mid-task?
14
+ - **Handle long-running work** — Some tasks take hours or days
15
+ - **Coordinate** — Multiple agents often need to work together
16
+ - **Maintain state** — Conversation history, tool results, workflow state
17
+
18
+ Temporal solves these problems for workflows. Zeitlich brings these guarantees to AI agents.
19
+
20
+ ## Features
21
+
22
+ - **Durable execution** — Agent state survives process restarts and failures
23
+ - **Thread management** — Redis-backed conversation storage with automatic persistence
24
+ - **Type-safe tools** — Define tools with Zod schemas, get full TypeScript inference
25
+ - **Lifecycle hooks** — Pre/post tool execution, session start/end
26
+ - **Subagent support** — Spawn child agents as Temporal child workflows
27
+ - **Filesystem utilities** — In-memory or custom providers for file operations
28
+ - **Model flexibility** — Use any LLM provider via LangChain
29
+
30
+ ## LLM Integration
31
+
32
+ Zeitlich uses [LangChain](https://js.langchain.com/) as the abstraction layer for LLM execution. This gives you:
33
+
34
+ - **Provider flexibility** — Use Anthropic, OpenAI, Google, Azure, AWS Bedrock, or any LangChain-supported provider
35
+ - **Consistent interface** — Same tool calling and message format regardless of provider
36
+ - **Easy model swapping** — Change models without rewriting agent logic
37
+ - **Soon** — Support native provider SDKs directly
38
+
39
+ ```typescript
40
+ import { ChatAnthropic } from "@langchain/anthropic";
41
+ import { ChatOpenAI } from "@langchain/openai";
42
+ import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
43
+
44
+ // Use any LangChain chat model
45
+ const anthropic = new ChatAnthropic({ model: "claude-sonnet-4-20250514" });
46
+ const openai = new ChatOpenAI({ model: "gpt-4o" });
47
+ const google = new ChatGoogleGenerativeAI({ model: "gemini-1.5-pro" });
48
+
49
+ // Pass to invokeModel in your activity
50
+ return {
51
+ runAgent: (config, invocationConfig) =>
52
+ invokeModel(redis, { ...config, tools }, anthropic, invocationConfig),
53
+ };
54
+ ```
55
+
56
+ Install the LangChain package for your chosen provider:
57
+
58
+ ```bash
59
+ npm install @langchain/anthropic # Anthropic
60
+ npm install @langchain/openai # OpenAI
61
+ npm install @langchain/google-genai # Google
62
+ ```
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ npm install zeitlich ioredis
68
+ ```
69
+
70
+ **Peer dependencies:**
71
+
72
+ - `ioredis` >= 5.0.0
73
+
74
+ **Required infrastructure:**
75
+
76
+ - Temporal server (local dev: `temporal server start-dev`)
77
+ - Redis instance
78
+
79
+ ## Import Paths
80
+
81
+ Zeitlich provides two entry points to work with Temporal's workflow sandboxing:
82
+
83
+ ```typescript
84
+ // In workflow files - no external dependencies (Redis, LangChain, etc.)
85
+ import { createSession, createToolRegistry, ... } from 'zeitlich/workflow';
86
+
87
+ // In activity files and worker setup - full functionality
88
+ import { ZeitlichPlugin, invokeModel, createGlobHandler, ... } from 'zeitlich';
89
+ ```
90
+
91
+ **Why?** Temporal workflows run in an isolated V8 sandbox that cannot import modules with Node.js APIs or external dependencies. The `/workflow` entry point contains only pure TypeScript code safe for workflow use.
92
+
93
+ ## Examples
94
+
95
+ Runnable examples (worker, client, workflows) are in a separate repo: [zeitlich-examples](https://github.com/bead-ai/zeitlich-examples).
96
+
97
+ ## Quick Start
98
+
99
+ ### 1. Define Your Tools
100
+
101
+ ```typescript
102
+ import { z } from "zod";
103
+ import type { ToolDefinition } from "zeitlich/workflow";
104
+
105
+ export const searchTool: ToolDefinition<"Search", typeof searchSchema> = {
106
+ name: "Search",
107
+ description: "Search for information",
108
+ schema: z.object({
109
+ query: z.string().describe("The search query"),
110
+ }),
111
+ };
112
+
113
+ export const tools = { Search: searchTool };
114
+ ```
115
+
116
+ ### 2. Create Activities
117
+
118
+ ```typescript
119
+ import type Redis from "ioredis";
120
+ import { ChatAnthropic } from "@langchain/anthropic";
121
+ import { invokeModel } from "zeitlich";
122
+ import { tools } from "./tools";
123
+
124
+ export const createActivities = (redis: Redis) => {
125
+ const model = new ChatAnthropic({
126
+ model: "claude-sonnet-4-20250514",
127
+ maxTokens: 4096,
128
+ });
129
+
130
+ return {
131
+ runAgent: (config, invocationConfig) =>
132
+ invokeModel(
133
+ redis,
134
+ { ...config, tools: Object.values(tools) },
135
+ model,
136
+ invocationConfig
137
+ ),
138
+
139
+ handleSearchResult: async ({ args }) => {
140
+ // Your tool implementation
141
+ const results = await performSearch(args.query);
142
+ return { result: { results } };
143
+ },
144
+ };
145
+ };
146
+ ```
147
+
148
+ ### 3. Create the Workflow
149
+
150
+ ```typescript
151
+ import { proxyActivities, workflowInfo } from "@temporalio/workflow";
152
+ import {
153
+ createAgentStateManager,
154
+ createSession,
155
+ createPromptManager,
156
+ createToolRegistry,
157
+ createToolRouter,
158
+ } from "zeitlich/workflow";
159
+ import type { ZeitlichSharedActivities } from "zeitlich/workflow";
160
+ import { tools } from "./tools";
161
+
162
+ const { runAgent, handleSearchResult } = proxyActivities<MyActivities>({
163
+ startToCloseTimeout: "30m",
164
+ });
165
+
166
+ const { appendToolResult } = proxyActivities<ZeitlichSharedActivities>({
167
+ startToCloseTimeout: "30m",
168
+ });
169
+
170
+ export async function myAgentWorkflow({ prompt }: { prompt: string }) {
171
+ const { runId } = workflowInfo();
172
+
173
+ const stateManager = createAgentStateManager({
174
+ initialState: { prompt },
175
+ });
176
+
177
+ const toolRegistry = createToolRegistry(tools);
178
+
179
+ const toolRouter = createToolRouter(
180
+ { registry: toolRegistry, threadId: runId, appendToolResult },
181
+ { Search: handleSearchResult }
182
+ );
183
+
184
+ const promptManager = createPromptManager({
185
+ baseSystemPrompt: "You are a helpful assistant.",
186
+ buildContextMessage: () => [{ type: "text", text: prompt }],
187
+ });
188
+
189
+ const session = await createSession(
190
+ { threadId: runId, agentName: "my-agent", maxTurns: 20 },
191
+ { runAgent, promptManager, toolRouter, toolRegistry }
192
+ );
193
+
194
+ await session.runSession(prompt, stateManager);
195
+ return stateManager.getCurrentState();
196
+ }
197
+ ```
198
+
199
+ ### 4. Set Up the Worker
200
+
201
+ ```typescript
202
+ import { Worker, NativeConnection } from "@temporalio/worker";
203
+ import { ZeitlichPlugin } from "zeitlich";
204
+ import Redis from "ioredis";
205
+ import { createActivities } from "./activities";
206
+
207
+ async function run() {
208
+ const connection = await NativeConnection.connect({
209
+ address: "localhost:7233",
210
+ });
211
+ const redis = new Redis({ host: "localhost", port: 6379 });
212
+
213
+ const worker = await Worker.create({
214
+ plugins: [new ZeitlichPlugin({ redis })],
215
+ connection,
216
+ taskQueue: "my-agent",
217
+ workflowsPath: require.resolve("./workflows"),
218
+ activities: createActivities(redis),
219
+ });
220
+
221
+ await worker.run();
222
+ }
223
+ ```
224
+
225
+ ## Core Concepts
226
+
227
+ ### Agent State Manager
228
+
229
+ Manages workflow state with automatic versioning and status tracking:
230
+
231
+ ```typescript
232
+ import { createAgentStateManager } from "zeitlich/workflow";
233
+
234
+ const stateManager = createAgentStateManager({
235
+ initialState: { customField: "value" },
236
+ });
237
+
238
+ // State operations
239
+ stateManager.set("customField", "new value");
240
+ stateManager.complete(); // Mark as COMPLETED
241
+ stateManager.waitForInput(); // Mark as WAITING_FOR_INPUT
242
+ stateManager.isRunning(); // Check if RUNNING
243
+ stateManager.isTerminal(); // Check if COMPLETED/FAILED/CANCELLED
244
+ ```
245
+
246
+ ### Tool Registry
247
+
248
+ Type-safe tool management with Zod validation:
249
+
250
+ ```typescript
251
+ import { createToolRegistry } from "zeitlich/workflow";
252
+
253
+ const registry = createToolRegistry({
254
+ Search: searchTool,
255
+ Calculate: calculateTool,
256
+ });
257
+
258
+ // Parse and validate tool calls from LLM
259
+ const parsed = registry.parseToolCall(rawToolCall);
260
+ // parsed.name is "Search" | "Calculate"
261
+ // parsed.args is fully typed based on the tool's schema
262
+ ```
263
+
264
+ ### Tool Router
265
+
266
+ Routes tool calls to handlers with lifecycle hooks:
267
+
268
+ ```typescript
269
+ import { createToolRouter } from "zeitlich/workflow";
270
+
271
+ const router = createToolRouter(
272
+ {
273
+ registry: toolRegistry,
274
+ threadId,
275
+ appendToolResult,
276
+ hooks: {
277
+ onPreToolUse: ({ toolCall }) => {
278
+ console.log(`Executing ${toolCall.name}`);
279
+ return {}; // Can return { skip: true } or { modifiedArgs: {...} }
280
+ },
281
+ onPostToolUse: ({ toolCall, result, durationMs }) => {
282
+ console.log(`${toolCall.name} completed in ${durationMs}ms`);
283
+ },
284
+ onPostToolUseFailure: ({ toolCall, error }) => {
285
+ return { fallbackContent: "Tool failed, please try again" };
286
+ },
287
+ },
288
+ },
289
+ {
290
+ Search: handleSearchResult,
291
+ Calculate: handleCalculateResult,
292
+ }
293
+ );
294
+ ```
295
+
296
+ ### Subagents
297
+
298
+ Spawn child agents as Temporal child workflows:
299
+
300
+ ```typescript
301
+ import { withSubagentSupport } from "zeitlich/workflow";
302
+ import { z } from "zod";
303
+
304
+ const { tools, taskHandler } = withSubagentSupport(baseTools, {
305
+ subagents: [
306
+ {
307
+ name: "researcher",
308
+ description: "Researches topics and returns findings",
309
+ workflowType: "researcherWorkflow",
310
+ resultSchema: z.object({
311
+ findings: z.string(),
312
+ sources: z.array(z.string()),
313
+ }),
314
+ },
315
+ ],
316
+ });
317
+
318
+ // Include taskHandler in your tool router
319
+ const router = createToolRouter(
320
+ { registry, threadId, appendToolResult },
321
+ { ...handlers, Task: taskHandler }
322
+ );
323
+ ```
324
+
325
+ ### Filesystem Utilities
326
+
327
+ Built-in support for file operations with pluggable providers:
328
+
329
+ ```typescript
330
+ // In workflow - use the pure utilities and tool definitions
331
+ import {
332
+ buildFileTreePrompt,
333
+ globTool,
334
+ grepTool,
335
+ readTool,
336
+ } from "zeitlich/workflow";
337
+
338
+ // In activities - use the providers and handlers
339
+ import {
340
+ InMemoryFileSystemProvider,
341
+ createGlobHandler,
342
+ createGrepHandler,
343
+ createReadHandler,
344
+ } from "zeitlich";
345
+
346
+ // Create an in-memory filesystem
347
+ const provider = InMemoryFileSystemProvider.fromTextFiles(
348
+ fileTree,
349
+ fileContents
350
+ );
351
+
352
+ // Create tool handlers
353
+ const handlers = {
354
+ Glob: createGlobHandler({ provider, scopedNodes: fileTree }),
355
+ Grep: createGrepHandler({ provider, scopedNodes: fileTree }),
356
+ FileRead: createReadHandler({ provider, scopedNodes: fileTree }),
357
+ };
358
+
359
+ // Generate context for the agent
360
+ const fileTreeContext = buildFileTreePrompt(fileTree, {
361
+ headerText: "Available Files",
362
+ });
363
+ ```
364
+
365
+ ### Built-in Tools
366
+
367
+ Zeitlich provides ready-to-use tool definitions and handlers for common agent operations. More tools will be added in future releases.
368
+
369
+ | Tool | Description |
370
+ | ----------------- | ------------------------------------------------------------------------- |
371
+ | `FileRead` | Read file contents with optional pagination (supports text, images, PDFs) |
372
+ | `FileWrite` | Create or overwrite files with new content |
373
+ | `FileEdit` | Edit specific sections of a file by find/replace |
374
+ | `Glob` | Search for files matching a glob pattern |
375
+ | `Grep` | Search file contents with regex patterns |
376
+ | `AskUserQuestion` | Ask the user questions during execution with structured options |
377
+ | `Task` | Launch subagents as child workflows (see [Subagents](#subagents)) |
378
+
379
+ ```typescript
380
+ // Import tool definitions in workflows
381
+ import {
382
+ readTool,
383
+ writeTool,
384
+ editTool,
385
+ globTool,
386
+ grepTool,
387
+ askUserQuestionTool,
388
+ } from "zeitlich/workflow";
389
+
390
+ // Import handlers in activities
391
+ import {
392
+ createReadHandler,
393
+ createWriteHandler,
394
+ createEditHandler,
395
+ createGlobHandler,
396
+ createGrepHandler,
397
+ } from "zeitlich";
398
+ ```
399
+
400
+ ## API Reference
401
+
402
+ ### Workflow Entry Point (`zeitlich/workflow`)
403
+
404
+ Safe for use in Temporal workflow files:
405
+
406
+ | Export | Description |
407
+ | ------------------------- | ---------------------------------------------------------------------------------- |
408
+ | `createSession` | Creates an agent session for running the agentic loop |
409
+ | `createAgentStateManager` | Creates a state manager for workflow state |
410
+ | `createPromptManager` | Creates a prompt manager for system/context prompts |
411
+ | `createToolRegistry` | Creates a type-safe tool registry |
412
+ | `createToolRouter` | Creates a tool router with handlers and hooks |
413
+ | `withSubagentSupport` | Adds Task tool for spawning subagents |
414
+ | `buildFileTreePrompt` | Generates file tree context for prompts |
415
+ | Tool definitions | `askUserQuestionTool`, `globTool`, `grepTool`, `readTool`, `writeTool`, `editTool` |
416
+ | Types | All TypeScript types and interfaces |
417
+
418
+ ### Activity Entry Point (`zeitlich`)
419
+
420
+ For use in activities, worker setup, and Node.js code:
421
+
422
+ | Export | Description |
423
+ | ----------------------------- | -------------------------------------------------------------------------------------------------------- |
424
+ | `ZeitlichPlugin` | Temporal worker plugin that registers shared activities |
425
+ | `createSharedActivities` | Creates thread management activities |
426
+ | `invokeModel` | Core LLM invocation utility (requires Redis + LangChain) |
427
+ | `InMemoryFileSystemProvider` | In-memory filesystem implementation |
428
+ | `CompositeFileSystemProvider` | Combines multiple filesystem providers |
429
+ | `BaseFileSystemProvider` | Base class for custom providers |
430
+ | Tool handlers | `createGlobHandler`, `createGrepHandler`, `createReadHandler`, `createWriteHandler`, `createEditHandler` |
431
+
432
+ ### Types
433
+
434
+ | Export | Description |
435
+ | ---------------- | ---------------------------------------------------------------------------- |
436
+ | `AgentStatus` | `"RUNNING" \| "WAITING_FOR_INPUT" \| "COMPLETED" \| "FAILED" \| "CANCELLED"` |
437
+ | `ToolDefinition` | Tool definition with name, description, and Zod schema |
438
+ | `SubagentConfig` | Configuration for subagent workflows |
439
+ | `SessionHooks` | Lifecycle hooks interface |
440
+
441
+ ## Architecture
442
+
443
+ ```
444
+ ┌─────────────────────────────────────────────────────────────────┐
445
+ │ Temporal Worker │
446
+ │ ┌──────────────────────────────────────────────────────────┐ │
447
+ │ │ ZeitlichPlugin │ │
448
+ │ │ • Registers shared activities (thread management) │ │
449
+ │ └──────────────────────────────────────────────────────────┘ │
450
+ │ │ │
451
+ │ ┌──────────────────────────────────────────────────────────┐ │
452
+ │ │ Workflow │ │
453
+ │ │ ┌────────────────┐ ┌─────────────┐ ┌──────────────┐ │ │
454
+ │ │ │ State Manager │ │ Session │ │ Tool Router │ │ │
455
+ │ │ │ • Status │ │ • Run loop │ │ • Dispatch │ │ │
456
+ │ │ │ • Turns │ │ • Max turns │ │ • Hooks │ │ │
457
+ │ │ │ • Custom state │ │ • Lifecycle │ │ • Handlers │ │ │
458
+ │ │ └────────────────┘ └─────────────┘ └──────────────┘ │ │
459
+ │ │ │ │ │
460
+ │ │ ┌────────────────┐ ┌─────────────┐ ┌──────────────┐ │ │
461
+ │ │ │ Prompt Manager │ │Tool Registry│ │ Subagents │ │ │
462
+ │ │ │ • System prompt│ │ • Parsing │ │ • Child WFs │ │ │
463
+ │ │ │ • Context │ │ • Validation│ │ • Results │ │ │
464
+ │ │ └────────────────┘ └─────────────┘ └──────────────┘ │ │
465
+ │ └──────────────────────────────────────────────────────────┘ │
466
+ │ │ │
467
+ │ ┌──────────────────────────────────────────────────────────┐ │
468
+ │ │ Activities │ │
469
+ │ │ • runAgent (LLM invocation) │ │
470
+ │ │ • Tool handlers │ │
471
+ │ └──────────────────────────────────────────────────────────┘ │
472
+ └─────────────────────────────────────────────────────────────────┘
473
+
474
+
475
+ ┌─────────────────┐
476
+ │ Redis │
477
+ │ • Thread state │
478
+ │ • Messages │
479
+ └─────────────────┘
480
+ ```
481
+
482
+ ## Requirements
483
+
484
+ - Node.js >= 18
485
+ - Temporal server
486
+ - Redis
487
+
488
+ ## Contributing
489
+
490
+ Contributions are welcome! Please open an issue or submit a PR.
491
+
492
+ ## License
493
+
494
+ MIT © [Bead Technologies Inc.](https://usebead.ai)
@@ -0,0 +1,152 @@
1
+ import { T as ToolDefinition, I as InvocationConfig, A as AgentResponse, a as ActivityToolHandler, b as AskUserQuestionToolSchemaType, F as FileSystemProvider, c as FileNode, G as GlobToolSchemaType, d as GrepToolSchemaType, e as GrepMatch, R as ReadToolSchemaType, f as FileContent, W as WriteToolSchemaType, E as EditToolSchemaType } from './workflow-DeVGEXSc.mjs';
2
+ export { g as AGENT_HANDLER_NAMES, h as AgentFile, i as AgentState, j as AgentStateManager, k as AgentStateManagerConfig, l as AgentStatus, m as AppendToolResultFn, B as BackendConfig, n as BaseAgentState, o as BaseFileSystemProvider, C as CompositeFileSystemProvider, p as FileResolver, q as FileSystemToolsConfig, r as FileTreeRenderOptions, s as GenericTaskToolSchemaType, t as GrepOptions, u as InMemoryFileSystemProvider, J as JsonPrimitive, v as JsonSerializable, w as JsonValue, P as ParsedToolCall, x as ParsedToolCallUnion, y as PostToolUseFailureHook, z as PostToolUseFailureHookContext, D as PostToolUseFailureHookResult, H as PostToolUseHook, K as PostToolUseHookContext, L as PreToolUseHook, M as PreToolUseHookContext, N as PreToolUseHookResult, O as ProcessToolCallsContext, Q as PromptManager, S as PromptManagerConfig, U as RawToolCall, V as RunAgentActivity, X as RunAgentConfig, Y as SessionEndHook, Z as SessionEndHookContext, _ as SessionExitReason, $ as SessionHooks, a0 as SessionLifecycleHooks, a1 as SessionStartHook, a2 as SessionStartHookContext, a3 as SubagentConfig, a4 as SubagentInput, a5 as SubagentSupportConfig, a6 as SubagentSupportResult, a7 as TaskHandlerResult, a8 as TaskToolSchemaType, a9 as ToolCallResult, aa as ToolCallResultUnion, ab as ToolHandler, ac as ToolHandlerMap, ad as ToolHandlerResponse, ae as ToolMap, af as ToolMessageContent, ag as ToolNames, ah as ToolRegistry, ai as ToolResultConfig, aj as ToolRouter, ak as ToolRouterHooks, al as ToolRouterOptions, am as ZeitlichAgentConfig, an as ZeitlichSession, ao as ZeitlichSharedActivities, ap as askUserQuestionTool, aq as buildFileTreePrompt, ar as createAgentStateManager, as as createPromptManager, at as createSession, au as createSharedActivities, av as createTaskHandler, aw as createTaskTool, ax as createToolRegistry, ay as createToolRouter, az as editTool, aA as fileContentToMessageContent, aB as findNodeByPath, aC as flattenFileTree, aD as globTool, aE as grepTool, aF as hasNoOtherToolCalls, aG as hasTaskTool, aH as isPathInScope, aI as isTerminalStatus, aJ as readTool, aK as withSubagentSupport, aL as writeTool } from './workflow-DeVGEXSc.mjs';
3
+ import { SimplePlugin } from '@temporalio/plugin';
4
+ import Redis from 'ioredis';
5
+ import { BaseChatModel, BaseChatModelCallOptions, BindToolsInput } from '@langchain/core/language_models/chat_models';
6
+ import { StoredMessage, ContentBlock } from '@langchain/core/messages';
7
+ import 'zod';
8
+
9
+ /**
10
+ * Options for the Zeitlich plugin
11
+ *
12
+ * @experimental The Zeitlich plugin is an experimental feature; APIs may change without notice.
13
+ */
14
+ interface ZeitlichPluginOptions {
15
+ redis: Redis;
16
+ }
17
+ /**
18
+ * A Temporal plugin that integrates Zeitlich for use in workflows.
19
+ * This plugin creates shared activities for thread management.
20
+ * Workflow-specific activities (like runAgent) should be created separately.
21
+ *
22
+ * @experimental The Zeitlich plugin is an experimental feature; APIs may change without notice.
23
+ */
24
+ declare class ZeitlichPlugin extends SimplePlugin {
25
+ constructor(options: ZeitlichPluginOptions);
26
+ }
27
+
28
+ /**
29
+ * Configuration for invoking the model
30
+ */
31
+ interface InvokeModelConfig {
32
+ threadId: string;
33
+ agentName: string;
34
+ tools: ToolDefinition[];
35
+ }
36
+ /**
37
+ * Core model invocation logic - shared utility for workflow-specific activities
38
+ *
39
+ * @param redis - Redis client for thread management
40
+ * @param config - Model invocation configuration
41
+ * @param model - Pre-instantiated LangChain chat model
42
+ * @param invocationConfig - Per-invocation configuration (system prompt, etc.)
43
+ * @returns Agent response with message and metadata
44
+ */
45
+ declare function invokeModel(redis: Redis, { threadId, agentName, tools }: InvokeModelConfig, model: BaseChatModel<BaseChatModelCallOptions & {
46
+ tools?: BindToolsInput;
47
+ }>, { systemPrompt }: InvocationConfig): Promise<AgentResponse>;
48
+
49
+ /**
50
+ * Handle user interaction tool result - creates AI messages for display.
51
+ */
52
+ declare const handleAskUserQuestionToolResult: ActivityToolHandler<AskUserQuestionToolSchemaType, {
53
+ chatMessages: StoredMessage[];
54
+ }>;
55
+
56
+ interface GlobHandlerConfig {
57
+ provider: FileSystemProvider;
58
+ scopedNodes: FileNode[];
59
+ }
60
+ /**
61
+ * Create a glob handler that searches within the scoped file tree.
62
+ */
63
+ declare function createGlobHandler(config: GlobHandlerConfig): (args: GlobToolSchemaType) => Promise<{
64
+ content: string;
65
+ result: {
66
+ files: FileNode[];
67
+ };
68
+ }>;
69
+
70
+ interface GrepHandlerConfig {
71
+ provider: FileSystemProvider;
72
+ scopedNodes: FileNode[];
73
+ }
74
+ /**
75
+ * Create a grep handler that searches within the scoped file tree.
76
+ */
77
+ declare function createGrepHandler(config: GrepHandlerConfig): (args: GrepToolSchemaType) => Promise<{
78
+ content: string;
79
+ result: {
80
+ matches: GrepMatch[];
81
+ };
82
+ }>;
83
+
84
+ interface ReadHandlerConfig {
85
+ provider: FileSystemProvider;
86
+ scopedNodes: FileNode[];
87
+ }
88
+ /**
89
+ * Create a read handler that reads files within the scoped file tree.
90
+ */
91
+ declare function createReadHandler(config: ReadHandlerConfig): (args: ReadToolSchemaType) => Promise<{
92
+ content: ContentBlock[];
93
+ result: {
94
+ path: string;
95
+ content: FileContent;
96
+ };
97
+ }>;
98
+
99
+ interface WriteHandlerConfig {
100
+ provider: FileSystemProvider;
101
+ scopedNodes: FileNode[];
102
+ /**
103
+ * Set of file paths that have been read in this session.
104
+ * Required for enforcing read-before-write policy.
105
+ */
106
+ readFiles: Set<string>;
107
+ /**
108
+ * If true, skip the read-before-write check (not recommended)
109
+ */
110
+ skipReadCheck?: boolean;
111
+ }
112
+ interface WriteResult {
113
+ path: string;
114
+ success: boolean;
115
+ created: boolean;
116
+ bytesWritten: number;
117
+ }
118
+ /**
119
+ * Create a write handler that writes files within the scoped file tree.
120
+ */
121
+ declare function createWriteHandler(config: WriteHandlerConfig): (args: WriteToolSchemaType) => Promise<{
122
+ content: string;
123
+ result: WriteResult;
124
+ }>;
125
+
126
+ interface EditHandlerConfig {
127
+ provider: FileSystemProvider;
128
+ scopedNodes: FileNode[];
129
+ /**
130
+ * Set of file paths that have been read in this session.
131
+ * Required for enforcing read-before-write policy.
132
+ */
133
+ readFiles: Set<string>;
134
+ /**
135
+ * If true, skip the read-before-write check (not recommended)
136
+ */
137
+ skipReadCheck?: boolean;
138
+ }
139
+ interface EditResult {
140
+ path: string;
141
+ success: boolean;
142
+ replacements: number;
143
+ }
144
+ /**
145
+ * Create an edit handler that edits files within the scoped file tree.
146
+ */
147
+ declare function createEditHandler(config: EditHandlerConfig): (args: EditToolSchemaType) => Promise<{
148
+ content: string;
149
+ result: EditResult;
150
+ }>;
151
+
152
+ export { ActivityToolHandler, AgentResponse, AskUserQuestionToolSchemaType, type EditHandlerConfig, type EditResult, EditToolSchemaType, FileContent, FileNode, FileSystemProvider, type GlobHandlerConfig, GlobToolSchemaType, type GrepHandlerConfig, GrepMatch, GrepToolSchemaType, InvocationConfig, type InvokeModelConfig, type ReadHandlerConfig, ReadToolSchemaType, ToolDefinition, type WriteHandlerConfig, type WriteResult, WriteToolSchemaType, ZeitlichPlugin, type ZeitlichPluginOptions, createEditHandler, createGlobHandler, createGrepHandler, createReadHandler, createWriteHandler, handleAskUserQuestionToolResult, invokeModel };