zeitlich 0.2.9 → 0.2.12
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 +313 -126
- package/dist/adapters/langchain/index.cjs +270 -0
- package/dist/adapters/langchain/index.cjs.map +1 -0
- package/dist/adapters/langchain/index.d.cts +132 -0
- package/dist/adapters/langchain/index.d.ts +132 -0
- package/dist/adapters/langchain/index.js +265 -0
- package/dist/adapters/langchain/index.js.map +1 -0
- package/dist/index.cjs +406 -301
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -45
- package/dist/index.d.ts +88 -45
- package/dist/index.js +375 -274
- package/dist/index.js.map +1 -1
- package/dist/{workflow-C2ShwjC7.d.cts → model-invoker-C5-N-5TC.d.cts} +92 -435
- package/dist/{workflow-C2ShwjC7.d.ts → model-invoker-C5-N-5TC.d.ts} +92 -435
- package/dist/thread-manager-qc0g5Rvd.d.cts +39 -0
- package/dist/thread-manager-qc0g5Rvd.d.ts +39 -0
- package/dist/workflow.cjs +294 -126
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +459 -5
- package/dist/workflow.d.ts +459 -5
- package/dist/workflow.js +266 -103
- package/dist/workflow.js.map +1 -1
- package/package.json +30 -15
- package/src/adapters/langchain/activities.ts +120 -0
- package/src/adapters/langchain/index.ts +38 -0
- package/src/adapters/langchain/model-invoker.ts +102 -0
- package/src/adapters/langchain/thread-manager.ts +142 -0
- package/src/index.ts +26 -22
- package/src/lib/fs.ts +25 -0
- package/src/lib/model-invoker.ts +14 -74
- package/src/lib/session.ts +60 -23
- package/src/lib/skills/fs-provider.ts +84 -0
- package/src/lib/skills/index.ts +3 -0
- package/src/lib/skills/parse.ts +117 -0
- package/src/lib/skills/types.ts +41 -0
- package/src/lib/state-manager.ts +65 -31
- package/src/lib/thread-id.ts +25 -0
- package/src/lib/thread-manager.ts +63 -128
- package/src/lib/tool-router.ts +33 -23
- package/src/lib/types.ts +48 -15
- package/src/lib/workflow-helpers.ts +50 -0
- package/src/tools/ask-user-question/handler.ts +25 -1
- package/src/tools/bash/handler.ts +13 -0
- package/src/tools/read-skill/handler.ts +31 -0
- package/src/tools/read-skill/tool.ts +47 -0
- package/src/tools/subagent/handler.ts +37 -9
- package/src/tools/subagent/tool.ts +38 -34
- package/src/tools/task-create/tool.ts +1 -1
- package/src/workflow.ts +39 -11
- package/tsup.config.ts +1 -0
- package/src/activities.ts +0 -91
- package/src/plugin.ts +0 -28
|
@@ -1,64 +1,47 @@
|
|
|
1
|
-
import { Workflow, proxyActivities } from '@temporalio/workflow';
|
|
2
|
-
import Redis from 'ioredis';
|
|
3
|
-
import { $InferMessageContent, MessageStructure, StoredMessage, MessageContent } from '@langchain/core/messages';
|
|
4
1
|
import z, { z as z$1 } from 'zod';
|
|
5
2
|
import { Duration } from '@temporalio/common';
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* Skill metadata — the lightweight subset loaded at startup for all skills.
|
|
6
|
+
* Follows the agentskills.io specification frontmatter fields.
|
|
10
7
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
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>;
|
|
8
|
+
interface SkillMetadata {
|
|
9
|
+
/** Lowercase alphanumeric + hyphens, max 64 chars, must match directory name */
|
|
10
|
+
name: string;
|
|
11
|
+
/** What the skill does and when to use it (max 1024 chars) */
|
|
12
|
+
description: string;
|
|
13
|
+
/** License name or reference to a bundled license file */
|
|
14
|
+
license?: string;
|
|
15
|
+
/** Environment requirements (intended product, system packages, network access) */
|
|
16
|
+
compatibility?: string;
|
|
17
|
+
/** Arbitrary key-value pairs for additional metadata */
|
|
18
|
+
metadata?: Record<string, string>;
|
|
19
|
+
/** Space-delimited list of pre-approved tools the skill may use */
|
|
20
|
+
allowedTools?: string[];
|
|
32
21
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 SystemMessage */
|
|
48
|
-
appendSystemMessage(content: string): Promise<void>;
|
|
49
|
-
/** Create and append a ToolMessage */
|
|
50
|
-
appendToolMessage(content: ToolMessageContent, toolCallId: string): Promise<void>;
|
|
51
|
-
/** Create and append an AIMessage */
|
|
52
|
-
appendAIMessage(content: string | MessageContent): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* A fully-loaded skill including the SKILL.md instruction body.
|
|
24
|
+
* Progressive disclosure: metadata is always available, instructions
|
|
25
|
+
* are loaded on-demand via the ReadSkill tool.
|
|
26
|
+
*/
|
|
27
|
+
interface Skill extends SkillMetadata {
|
|
28
|
+
/** The markdown body of SKILL.md (everything after the frontmatter) */
|
|
29
|
+
instructions: string;
|
|
53
30
|
}
|
|
54
31
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
32
|
+
* Abstraction for discovering and loading skills.
|
|
33
|
+
*
|
|
34
|
+
* Implement this interface to provide skills from any source
|
|
35
|
+
* (filesystem, database, API, in-memory, etc.).
|
|
58
36
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
37
|
+
interface SkillProvider {
|
|
38
|
+
/** Return lightweight metadata for all available skills */
|
|
39
|
+
listSkills(): Promise<SkillMetadata[]>;
|
|
40
|
+
/** Load a single skill with full instructions by name */
|
|
41
|
+
getSkill(name: string): Promise<Skill>;
|
|
42
|
+
}
|
|
61
43
|
|
|
44
|
+
declare const SUBAGENT_TOOL_NAME: "Subagent";
|
|
62
45
|
/**
|
|
63
46
|
* Creates a Subagent tool configured with the available subagents.
|
|
64
47
|
*
|
|
@@ -76,13 +59,9 @@ declare function createThreadManager<T>(config: ThreadManagerConfig<T>): BaseThr
|
|
|
76
59
|
* ]);
|
|
77
60
|
*/
|
|
78
61
|
declare function createSubagentTool<T extends SubagentConfig[]>(subagents: T): {
|
|
79
|
-
name:
|
|
80
|
-
description: string;
|
|
81
|
-
schema: z.ZodObject<
|
|
82
|
-
subagent: z.ZodEnum<Record<string, string>>;
|
|
83
|
-
description: z.ZodString;
|
|
84
|
-
prompt: z.ZodString;
|
|
85
|
-
}>;
|
|
62
|
+
readonly name: typeof SUBAGENT_TOOL_NAME;
|
|
63
|
+
readonly description: string;
|
|
64
|
+
readonly schema: z.ZodObject<z.ZodRawShape>;
|
|
86
65
|
};
|
|
87
66
|
/**
|
|
88
67
|
* Subagent tool args type (when subagent names are not known at compile time)
|
|
@@ -91,6 +70,7 @@ type SubagentArgs = {
|
|
|
91
70
|
subagent: string;
|
|
92
71
|
description: string;
|
|
93
72
|
prompt: string;
|
|
73
|
+
threadId?: string;
|
|
94
74
|
};
|
|
95
75
|
|
|
96
76
|
/**
|
|
@@ -116,7 +96,7 @@ interface ToolWithHandler<TName extends string = string, TSchema extends z$1.Zod
|
|
|
116
96
|
strict?: boolean;
|
|
117
97
|
max_uses?: number;
|
|
118
98
|
/** Whether this tool is available to the agent (default: true). Disabled tools are excluded from definitions and rejected at parse time. */
|
|
119
|
-
enabled?:
|
|
99
|
+
enabled?: boolean;
|
|
120
100
|
/** Per-tool lifecycle hooks (run in addition to global hooks) */
|
|
121
101
|
hooks?: ToolHooks<z$1.infer<TSchema>, TResult>;
|
|
122
102
|
}
|
|
@@ -135,7 +115,7 @@ type ToolMap = Record<string, {
|
|
|
135
115
|
handler: ToolHandler<any, any, any>;
|
|
136
116
|
strict?: boolean;
|
|
137
117
|
max_uses?: number;
|
|
138
|
-
enabled?:
|
|
118
|
+
enabled?: boolean;
|
|
139
119
|
hooks?: ToolHooks<any, any>;
|
|
140
120
|
}>;
|
|
141
121
|
/**
|
|
@@ -189,6 +169,8 @@ interface ToolHandlerResponse<TResult = null> {
|
|
|
189
169
|
resultAppended?: boolean;
|
|
190
170
|
/** Token usage from the tool execution (e.g. child agent invocations) */
|
|
191
171
|
usage?: TokenUsage;
|
|
172
|
+
/** Thread ID used by the handler (surfaced to the LLM for subagent thread continuation) */
|
|
173
|
+
threadId?: string;
|
|
192
174
|
}
|
|
193
175
|
/**
|
|
194
176
|
* Context passed to tool handlers for additional data beyond tool args.
|
|
@@ -257,6 +239,8 @@ interface ToolRouterOptions<T extends ToolMap> {
|
|
|
257
239
|
hooks?: Hooks<T, ToolCallResultUnion<InferToolResults<T>>>;
|
|
258
240
|
/** Subagent configurations */
|
|
259
241
|
subagents?: SubagentConfig[];
|
|
242
|
+
/** Skills available to the agent (auto-adds ReadSkill tool when non-empty) */
|
|
243
|
+
skills?: Skill[];
|
|
260
244
|
}
|
|
261
245
|
/**
|
|
262
246
|
* Infer result types from a tool map based on handler return types.
|
|
@@ -439,14 +423,14 @@ declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType, TCont
|
|
|
439
423
|
workflow: string | ((input: {
|
|
440
424
|
prompt: string;
|
|
441
425
|
context: TContext;
|
|
442
|
-
}) => Promise<
|
|
426
|
+
}) => Promise<ToolHandlerResponse<TResult | null>>);
|
|
443
427
|
context: TContext;
|
|
444
428
|
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
445
429
|
}): SubagentConfig<TResult>;
|
|
446
430
|
declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType>(config: Omit<SubagentConfig<TResult>, "hooks" | "workflow"> & {
|
|
447
431
|
workflow: string | ((input: {
|
|
448
432
|
prompt: string;
|
|
449
|
-
}) => Promise<
|
|
433
|
+
}) => Promise<ToolHandlerResponse<TResult | null>>);
|
|
450
434
|
hooks?: SubagentHooks<SubagentArgs, z$1.infer<TResult>>;
|
|
451
435
|
}): SubagentConfig<TResult>;
|
|
452
436
|
/**
|
|
@@ -454,6 +438,15 @@ declare function defineSubagent<TResult extends z$1.ZodType = z$1.ZodType>(confi
|
|
|
454
438
|
*/
|
|
455
439
|
declare function hasNoOtherToolCalls<T extends ToolMap>(toolCalls: ParsedToolCallUnion<T>[], excludeName: ToolNames<T>): boolean;
|
|
456
440
|
|
|
441
|
+
/** A single content part within a structured message (text, image, etc.) */
|
|
442
|
+
type ContentPart = {
|
|
443
|
+
type: string;
|
|
444
|
+
[key: string]: unknown;
|
|
445
|
+
};
|
|
446
|
+
/** Message content — plain string or an array of structured content parts */
|
|
447
|
+
type MessageContent = string | ContentPart[];
|
|
448
|
+
/** Content returned by a tool handler */
|
|
449
|
+
type ToolMessageContent = string;
|
|
457
450
|
/**
|
|
458
451
|
* Agent execution status
|
|
459
452
|
*/
|
|
@@ -467,11 +460,11 @@ interface BaseAgentState {
|
|
|
467
460
|
version: number;
|
|
468
461
|
turns: number;
|
|
469
462
|
tasks: Map<string, WorkflowTask>;
|
|
470
|
-
systemPrompt
|
|
463
|
+
systemPrompt?: string;
|
|
471
464
|
totalInputTokens: number;
|
|
472
465
|
totalOutputTokens: number;
|
|
473
466
|
cachedWriteTokens: number;
|
|
474
|
-
|
|
467
|
+
cachedReadTokens: number;
|
|
475
468
|
}
|
|
476
469
|
/**
|
|
477
470
|
* File representation for agent workflows
|
|
@@ -498,7 +491,7 @@ interface TokenUsage {
|
|
|
498
491
|
/**
|
|
499
492
|
* Agent response from LLM invocation
|
|
500
493
|
*/
|
|
501
|
-
interface AgentResponse<M =
|
|
494
|
+
interface AgentResponse<M = unknown> {
|
|
502
495
|
message: M;
|
|
503
496
|
rawToolCalls: RawToolCall[];
|
|
504
497
|
usage?: TokenUsage;
|
|
@@ -506,7 +499,6 @@ interface AgentResponse<M = StoredMessage> {
|
|
|
506
499
|
/**
|
|
507
500
|
* Thread operations required by a session.
|
|
508
501
|
* Consumers provide these — typically by wrapping Temporal activities.
|
|
509
|
-
* Use `proxyDefaultThreadOps()` for the default StoredMessage implementation.
|
|
510
502
|
*/
|
|
511
503
|
interface ThreadOps {
|
|
512
504
|
/** Initialize an empty thread */
|
|
@@ -526,15 +518,13 @@ interface AgentConfig {
|
|
|
526
518
|
agentName: string;
|
|
527
519
|
/** Description, used for sub agents */
|
|
528
520
|
description?: string;
|
|
529
|
-
/** The system prompt to append to the thread */
|
|
530
|
-
systemPrompt?: string;
|
|
531
521
|
}
|
|
532
522
|
/**
|
|
533
523
|
* Configuration for a Zeitlich agent session
|
|
534
524
|
*/
|
|
535
|
-
interface SessionConfig<T extends ToolMap, M =
|
|
536
|
-
/** The thread ID to use for the session */
|
|
537
|
-
threadId
|
|
525
|
+
interface SessionConfig<T extends ToolMap, M = unknown> {
|
|
526
|
+
/** The thread ID to use for the session (defaults to a short generated ID) */
|
|
527
|
+
threadId?: string;
|
|
538
528
|
/** Metadata for the session */
|
|
539
529
|
metadata?: Record<string, unknown>;
|
|
540
530
|
/** Whether to append the system prompt as message to the thread */
|
|
@@ -549,6 +539,8 @@ interface SessionConfig<T extends ToolMap, M = StoredMessage> {
|
|
|
549
539
|
tools?: T;
|
|
550
540
|
/** Subagent configurations */
|
|
551
541
|
subagents?: SubagentConfig[];
|
|
542
|
+
/** Skills available to this agent (metadata + instructions, loaded activity-side) */
|
|
543
|
+
skills?: Skill[];
|
|
552
544
|
/** Session lifecycle hooks */
|
|
553
545
|
hooks?: Hooks<T, ToolCallResultUnion<InferToolResults<T>>>;
|
|
554
546
|
/** Whether to process tools in parallel */
|
|
@@ -558,6 +550,8 @@ interface SessionConfig<T extends ToolMap, M = StoredMessage> {
|
|
|
558
550
|
* Returns MessageContent array for the initial HumanMessage.
|
|
559
551
|
*/
|
|
560
552
|
buildContextMessage: () => MessageContent | Promise<MessageContent>;
|
|
553
|
+
/** When true, skip thread initialization and system prompt — append only the new human message to the existing thread. */
|
|
554
|
+
continueThread?: boolean;
|
|
561
555
|
/** How long to wait for input before cancelling the workflow */
|
|
562
556
|
waitForInputTimeout?: Duration;
|
|
563
557
|
}
|
|
@@ -585,7 +579,7 @@ interface RunAgentConfig extends AgentConfig {
|
|
|
585
579
|
/**
|
|
586
580
|
* Type signature for workflow-specific runAgent activity
|
|
587
581
|
*/
|
|
588
|
-
type RunAgentActivity<M =
|
|
582
|
+
type RunAgentActivity<M = unknown> = (config: RunAgentConfig) => Promise<AgentResponse<M>>;
|
|
589
583
|
/**
|
|
590
584
|
* Configuration for appending a tool result
|
|
591
585
|
*/
|
|
@@ -597,6 +591,7 @@ interface ToolResultConfig {
|
|
|
597
591
|
/** Content for the tool message (string or complex content parts) */
|
|
598
592
|
content: ToolMessageContent;
|
|
599
593
|
}
|
|
594
|
+
type SubagentWorkflow<TResult extends z$1.ZodType = z$1.ZodType> = (input: SubagentInput) => Promise<ToolHandlerResponse<TResult | null>>;
|
|
600
595
|
/**
|
|
601
596
|
* Configuration for a subagent that can be spawned by the parent workflow.
|
|
602
597
|
*
|
|
@@ -608,15 +603,17 @@ interface SubagentConfig<TResult extends z$1.ZodType = z$1.ZodType> {
|
|
|
608
603
|
/** Description shown to the parent agent explaining what this subagent does */
|
|
609
604
|
description: string;
|
|
610
605
|
/** Whether this subagent is available (default: true). Disabled subagents are excluded from the Subagent tool. */
|
|
611
|
-
enabled?:
|
|
606
|
+
enabled?: boolean;
|
|
612
607
|
/** Temporal workflow function or type name (used with executeChild) */
|
|
613
|
-
workflow: string |
|
|
608
|
+
workflow: string | SubagentWorkflow<TResult>;
|
|
614
609
|
/** Optional task queue - defaults to parent's queue if not specified */
|
|
615
610
|
taskQueue?: string;
|
|
616
611
|
/** Optional Zod schema to validate the child workflow's result. If omitted, result is passed through as-is. */
|
|
617
612
|
resultSchema?: TResult;
|
|
618
613
|
/** Optional static context passed to the subagent on every invocation */
|
|
619
614
|
context?: Record<string, unknown>;
|
|
615
|
+
/** Allow the parent agent to pass a threadId for this subagent to continue (default: false) */
|
|
616
|
+
allowThreadContinuation?: boolean;
|
|
620
617
|
/** Per-subagent lifecycle hooks */
|
|
621
618
|
hooks?: SubagentHooks;
|
|
622
619
|
}
|
|
@@ -655,6 +652,8 @@ interface SubagentInput {
|
|
|
655
652
|
prompt: string;
|
|
656
653
|
/** Optional context parameters passed from the parent agent */
|
|
657
654
|
context?: Record<string, unknown>;
|
|
655
|
+
/** When set, the subagent should continue this thread instead of starting a new one */
|
|
656
|
+
threadId?: string;
|
|
658
657
|
}
|
|
659
658
|
/**
|
|
660
659
|
* Status of a workflow task
|
|
@@ -860,376 +859,34 @@ interface Hooks<T extends ToolMap, TResult = unknown> {
|
|
|
860
859
|
/** Called when session ends */
|
|
861
860
|
onSessionEnd?: SessionEndHook;
|
|
862
861
|
}
|
|
862
|
+
/** Derives the query name for an agent's state (usable in both workflow and activity code) */
|
|
863
|
+
declare const agentQueryName: (agentName: string) => `get${string}State`;
|
|
864
|
+
/** Derives the update name for waiting on an agent's state change */
|
|
865
|
+
declare const agentStateChangeUpdateName: (agentName: string) => `waitFor${string}StateChange`;
|
|
863
866
|
/**
|
|
864
867
|
* Helper to check if status is terminal
|
|
865
868
|
*/
|
|
866
869
|
declare function isTerminalStatus(status: AgentStatus): boolean;
|
|
867
870
|
|
|
868
871
|
/**
|
|
869
|
-
*
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* JSON-serializable value (recursive type for Temporal compatibility)
|
|
874
|
-
*/
|
|
875
|
-
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
876
|
-
[key: string]: JsonValue;
|
|
877
|
-
};
|
|
878
|
-
/**
|
|
879
|
-
* Type constraint ensuring T only contains JSON-serializable values.
|
|
880
|
-
* Use this for custom state to ensure Temporal workflow compatibility.
|
|
881
|
-
*
|
|
882
|
-
* Allows: primitives, arrays, plain objects, and JsonValue
|
|
883
|
-
* Rejects: functions, symbols, undefined, class instances with methods
|
|
884
|
-
*/
|
|
885
|
-
type JsonSerializable<T> = {
|
|
886
|
-
[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;
|
|
887
|
-
};
|
|
888
|
-
/**
|
|
889
|
-
* Full state type combining base state with custom state
|
|
890
|
-
*/
|
|
891
|
-
type AgentState<TCustom extends JsonSerializable<TCustom>> = BaseAgentState & TCustom;
|
|
892
|
-
/**
|
|
893
|
-
* Agent state manager interface
|
|
894
|
-
* Note: Temporal handlers must be set up in the workflow file due to
|
|
895
|
-
* Temporal's workflow isolation requirements. This manager provides
|
|
896
|
-
* the state and helpers needed for those handlers.
|
|
897
|
-
*/
|
|
898
|
-
interface AgentStateManager<TCustom extends JsonSerializable<TCustom>> {
|
|
899
|
-
/** Get current status */
|
|
900
|
-
getStatus(): AgentStatus;
|
|
901
|
-
/** Check if agent is running */
|
|
902
|
-
isRunning(): boolean;
|
|
903
|
-
/** Check if agent is in terminal state */
|
|
904
|
-
isTerminal(): boolean;
|
|
905
|
-
/** Get current state version */
|
|
906
|
-
getVersion(): number;
|
|
907
|
-
/** Set status to RUNNING */
|
|
908
|
-
run(): void;
|
|
909
|
-
/** Set status to WAITING_FOR_INPUT */
|
|
910
|
-
waitForInput(): void;
|
|
911
|
-
/** Set status to COMPLETED */
|
|
912
|
-
complete(): void;
|
|
913
|
-
/** Set status to FAILED */
|
|
914
|
-
fail(): void;
|
|
915
|
-
/** Set status to CANCELLED */
|
|
916
|
-
cancel(): void;
|
|
917
|
-
/** Increment state version (call after state changes) */
|
|
918
|
-
incrementVersion(): void;
|
|
919
|
-
/** Increment turns (call after each turn) */
|
|
920
|
-
incrementTurns(): void;
|
|
921
|
-
/** Get current turns */
|
|
922
|
-
getTurns(): number;
|
|
923
|
-
/** Get a custom state value by key */
|
|
924
|
-
get<K extends keyof TCustom>(key: K): TCustom[K];
|
|
925
|
-
/** Set a custom state value by key */
|
|
926
|
-
set<K extends keyof TCustom>(key: K, value: TCustom[K]): void;
|
|
927
|
-
/** Get full state for query handler */
|
|
928
|
-
getCurrentState(): AgentState<TCustom>;
|
|
929
|
-
/** Check if should return from waitForStateChange */
|
|
930
|
-
shouldReturnFromWait(lastKnownVersion: number): boolean;
|
|
931
|
-
/** Get all tasks */
|
|
932
|
-
getTasks(): WorkflowTask[];
|
|
933
|
-
/** Get a task by ID */
|
|
934
|
-
getTask(id: string): WorkflowTask | undefined;
|
|
935
|
-
/** Add or update a task */
|
|
936
|
-
setTask(task: WorkflowTask): void;
|
|
937
|
-
/** Delete a task by ID */
|
|
938
|
-
deleteTask(id: string): boolean;
|
|
939
|
-
/** Set the tools (converts Zod schemas to JSON Schema for serialization) */
|
|
940
|
-
setTools(newTools: ToolDefinition[]): void;
|
|
941
|
-
/** Update the usage */
|
|
942
|
-
updateUsage(usage: {
|
|
943
|
-
inputTokens?: number;
|
|
944
|
-
outputTokens?: number;
|
|
945
|
-
cachedWriteTokens?: number;
|
|
946
|
-
cachedReadTokens?: number;
|
|
947
|
-
reasonTokens?: number;
|
|
948
|
-
}): void;
|
|
949
|
-
/** Get the total usage */
|
|
950
|
-
getTotalUsage(): {
|
|
951
|
-
totalInputTokens: number;
|
|
952
|
-
totalOutputTokens: number;
|
|
953
|
-
totalCachedWriteTokens: number;
|
|
954
|
-
totalCachedReadTokens: number;
|
|
955
|
-
totalReasonTokens: number;
|
|
956
|
-
turns: number;
|
|
957
|
-
};
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Creates an agent state manager for tracking workflow state.
|
|
961
|
-
*
|
|
962
|
-
* @param initialState - Optional initial values for base and custom state
|
|
963
|
-
* Base state defaults: status="RUNNING", version=0, turns=0, tasks=empty, fileTree=[]
|
|
964
|
-
*
|
|
965
|
-
* Note: Due to Temporal's workflow isolation, handlers must be set up
|
|
966
|
-
* in the workflow file using defineQuery/defineUpdate and setHandler.
|
|
967
|
-
* This manager provides the state and logic needed for those handlers.
|
|
968
|
-
*/
|
|
969
|
-
declare function createAgentStateManager<TCustom extends JsonSerializable<TCustom> = Record<string, never>>({ initialState, agentConfig, }: {
|
|
970
|
-
initialState?: Partial<BaseAgentState> & TCustom;
|
|
971
|
-
agentConfig: AgentConfig;
|
|
972
|
-
}): AgentStateManager<TCustom>;
|
|
973
|
-
/**
|
|
974
|
-
* Handler names used across agents
|
|
872
|
+
* Configuration passed to a ModelInvoker.
|
|
873
|
+
* Includes the full agent state so adapters can read tools, system prompt,
|
|
874
|
+
* token usage, or any custom state fields for model configuration.
|
|
975
875
|
*/
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
interface ZeitlichSession<M = unknown> {
|
|
983
|
-
runSession<T extends JsonSerializable<T>>(args: {
|
|
984
|
-
stateManager: AgentStateManager<T>;
|
|
985
|
-
}): Promise<{
|
|
986
|
-
finalMessage: M | null;
|
|
987
|
-
exitReason: SessionExitReason;
|
|
988
|
-
usage: ReturnType<AgentStateManager<T>["getTotalUsage"]>;
|
|
989
|
-
}>;
|
|
990
|
-
}
|
|
991
|
-
/**
|
|
992
|
-
* Session-level hooks for lifecycle events
|
|
993
|
-
*/
|
|
994
|
-
interface SessionLifecycleHooks {
|
|
995
|
-
/** Called when session starts */
|
|
996
|
-
onSessionStart?: SessionStartHook;
|
|
997
|
-
/** Called when session ends */
|
|
998
|
-
onSessionEnd?: SessionEndHook;
|
|
999
|
-
}
|
|
1000
|
-
declare const createSession: <T extends ToolMap, M = unknown>({ threadId, agentName, description, maxTurns, metadata, runAgent, threadOps, buildContextMessage, subagents, tools, processToolsInParallel, hooks, appendSystemPrompt, systemPrompt, waitForInputTimeout, }: SessionConfig<T, M> & AgentConfig) => Promise<ZeitlichSession<M>>;
|
|
1001
|
-
/**
|
|
1002
|
-
* Proxy the default ZeitlichSharedActivities as ThreadOps<StoredMessage>.
|
|
1003
|
-
* Call this in workflow code for the standard LangChain/StoredMessage setup.
|
|
1004
|
-
*
|
|
1005
|
-
* @example
|
|
1006
|
-
* ```typescript
|
|
1007
|
-
* const session = await createSession({
|
|
1008
|
-
* threadOps: proxyDefaultThreadOps(),
|
|
1009
|
-
* // ...
|
|
1010
|
-
* });
|
|
1011
|
-
* ```
|
|
1012
|
-
*/
|
|
1013
|
-
declare function proxyDefaultThreadOps(options?: Parameters<typeof proxyActivities>[0]): ThreadOps;
|
|
1014
|
-
|
|
1015
|
-
/**
|
|
1016
|
-
* Shared Zeitlich activities - thread management and message handling
|
|
1017
|
-
* Note: runAgent is workflow-specific and should be created per-workflow
|
|
1018
|
-
*/
|
|
1019
|
-
interface ZeitlichSharedActivities {
|
|
1020
|
-
/**
|
|
1021
|
-
* Append a tool result to the thread.
|
|
1022
|
-
* Handles JSON serialization and optional cache points.
|
|
1023
|
-
*/
|
|
1024
|
-
appendToolResult(config: ToolResultConfig): Promise<void>;
|
|
1025
|
-
/**
|
|
1026
|
-
* Initialize an empty thread.
|
|
1027
|
-
*/
|
|
1028
|
-
initializeThread(threadId: string): Promise<void>;
|
|
1029
|
-
/**
|
|
1030
|
-
* Append messages to a thread.
|
|
1031
|
-
*/
|
|
1032
|
-
appendThreadMessages(threadId: string, messages: StoredMessage[]): Promise<void>;
|
|
1033
|
-
/**
|
|
1034
|
-
* Append a human message to a thread.
|
|
1035
|
-
*/
|
|
1036
|
-
appendHumanMessage(threadId: string, content: string | MessageContent): Promise<void>;
|
|
1037
|
-
/**
|
|
1038
|
-
* Append a system message to a thread.
|
|
1039
|
-
*/
|
|
1040
|
-
appendSystemMessage(threadId: string, content: string): Promise<void>;
|
|
876
|
+
interface ModelInvokerConfig {
|
|
877
|
+
threadId: string;
|
|
878
|
+
agentName: string;
|
|
879
|
+
state: BaseAgentState;
|
|
880
|
+
metadata?: Record<string, unknown>;
|
|
1041
881
|
}
|
|
1042
882
|
/**
|
|
1043
|
-
*
|
|
1044
|
-
*
|
|
1045
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
* @experimental The Zeitlich integration is an experimental feature; APIs may change without notice.
|
|
1048
|
-
*/
|
|
1049
|
-
declare function createSharedActivities(redis: Redis): ZeitlichSharedActivities;
|
|
1050
|
-
|
|
1051
|
-
declare const globTool: {
|
|
1052
|
-
name: "Glob";
|
|
1053
|
-
description: string;
|
|
1054
|
-
schema: z$1.ZodObject<{
|
|
1055
|
-
pattern: z$1.ZodString;
|
|
1056
|
-
root: z$1.ZodOptional<z$1.ZodString>;
|
|
1057
|
-
}, z$1.core.$strip>;
|
|
1058
|
-
strict: true;
|
|
1059
|
-
};
|
|
1060
|
-
type GlobArgs = z$1.infer<typeof globTool.schema>;
|
|
1061
|
-
|
|
1062
|
-
declare const grepTool: {
|
|
1063
|
-
name: "Grep";
|
|
1064
|
-
description: string;
|
|
1065
|
-
schema: z$1.ZodObject<{
|
|
1066
|
-
pattern: z$1.ZodString;
|
|
1067
|
-
ignoreCase: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
1068
|
-
maxMatches: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1069
|
-
includePatterns: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
|
|
1070
|
-
excludePatterns: z$1.ZodOptional<z$1.ZodArray<z$1.ZodString>>;
|
|
1071
|
-
contextLines: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1072
|
-
}, z$1.core.$strip>;
|
|
1073
|
-
strict: true;
|
|
1074
|
-
};
|
|
1075
|
-
type GrepArgs = z$1.infer<typeof grepTool.schema>;
|
|
1076
|
-
|
|
1077
|
-
declare const readFileTool: {
|
|
1078
|
-
name: "FileRead";
|
|
1079
|
-
description: string;
|
|
1080
|
-
schema: z$1.ZodObject<{
|
|
1081
|
-
path: z$1.ZodString;
|
|
1082
|
-
offset: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1083
|
-
limit: z$1.ZodOptional<z$1.ZodNumber>;
|
|
1084
|
-
}, z$1.core.$strip>;
|
|
1085
|
-
strict: true;
|
|
1086
|
-
};
|
|
1087
|
-
type FileReadArgs = z$1.infer<typeof readFileTool.schema>;
|
|
1088
|
-
|
|
1089
|
-
declare const writeFileTool: {
|
|
1090
|
-
name: "FileWrite";
|
|
1091
|
-
description: string;
|
|
1092
|
-
schema: z$1.ZodObject<{
|
|
1093
|
-
file_path: z$1.ZodString;
|
|
1094
|
-
content: z$1.ZodString;
|
|
1095
|
-
}, z$1.core.$strip>;
|
|
1096
|
-
strict: true;
|
|
1097
|
-
};
|
|
1098
|
-
type FileWriteArgs = z$1.infer<typeof writeFileTool.schema>;
|
|
1099
|
-
|
|
1100
|
-
declare const editTool: {
|
|
1101
|
-
name: "FileEdit";
|
|
1102
|
-
description: string;
|
|
1103
|
-
schema: z$1.ZodObject<{
|
|
1104
|
-
file_path: z$1.ZodString;
|
|
1105
|
-
old_string: z$1.ZodString;
|
|
1106
|
-
new_string: z$1.ZodString;
|
|
1107
|
-
replace_all: z$1.ZodOptional<z$1.ZodBoolean>;
|
|
1108
|
-
}, z$1.core.$strip>;
|
|
1109
|
-
strict: true;
|
|
1110
|
-
};
|
|
1111
|
-
type FileEditArgs = z$1.infer<typeof editTool.schema>;
|
|
1112
|
-
|
|
1113
|
-
declare const taskCreateTool: {
|
|
1114
|
-
name: "TaskCreate";
|
|
1115
|
-
description: string;
|
|
1116
|
-
schema: z.ZodObject<{
|
|
1117
|
-
subject: z.ZodString;
|
|
1118
|
-
description: z.ZodString;
|
|
1119
|
-
activeForm: z.ZodString;
|
|
1120
|
-
metadata: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
1121
|
-
}, z.core.$strip>;
|
|
1122
|
-
};
|
|
1123
|
-
type TaskCreateArgs = z.infer<typeof taskCreateTool.schema>;
|
|
1124
|
-
|
|
1125
|
-
/**
|
|
1126
|
-
* Creates a TaskCreate handler that adds tasks to the workflow state.
|
|
883
|
+
* Generic model invocation contract.
|
|
884
|
+
* Implementations load the thread, call the LLM, append the response,
|
|
885
|
+
* and return a normalised AgentResponse.
|
|
1127
886
|
*
|
|
1128
|
-
*
|
|
1129
|
-
*
|
|
887
|
+
* Framework adapters (e.g. `zeitlich/langchain`) provide concrete
|
|
888
|
+
* implementations of this type.
|
|
1130
889
|
*/
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
declare const taskGetTool: {
|
|
1134
|
-
name: "TaskGet";
|
|
1135
|
-
description: string;
|
|
1136
|
-
schema: z.ZodObject<{
|
|
1137
|
-
taskId: z.ZodString;
|
|
1138
|
-
}, z.core.$strip>;
|
|
1139
|
-
};
|
|
1140
|
-
type TaskGetArgs = z.infer<typeof taskGetTool.schema>;
|
|
1141
|
-
|
|
1142
|
-
/**
|
|
1143
|
-
* Creates a TaskGet handler that retrieves a task by ID.
|
|
1144
|
-
*
|
|
1145
|
-
* @param stateManager - State manager containing tasks state
|
|
1146
|
-
* @returns A ToolHandler for TaskGet tool calls
|
|
1147
|
-
*/
|
|
1148
|
-
declare function createTaskGetHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>): ToolHandler<TaskGetArgs, WorkflowTask | null>;
|
|
1149
|
-
|
|
1150
|
-
declare const taskListTool: {
|
|
1151
|
-
name: "TaskList";
|
|
1152
|
-
description: string;
|
|
1153
|
-
schema: z.ZodObject<{}, z.core.$strip>;
|
|
1154
|
-
};
|
|
1155
|
-
type TaskListArgs = z.infer<typeof taskListTool.schema>;
|
|
1156
|
-
|
|
1157
|
-
/**
|
|
1158
|
-
* Creates a TaskList handler that returns all tasks.
|
|
1159
|
-
*
|
|
1160
|
-
* @param stateManager - State manager containing tasks state
|
|
1161
|
-
* @returns A ToolHandler for TaskList tool calls
|
|
1162
|
-
*/
|
|
1163
|
-
declare function createTaskListHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>): ToolHandler<TaskListArgs, WorkflowTask[]>;
|
|
1164
|
-
|
|
1165
|
-
declare const taskUpdateTool: {
|
|
1166
|
-
name: "TaskUpdate";
|
|
1167
|
-
description: string;
|
|
1168
|
-
schema: z.ZodObject<{
|
|
1169
|
-
taskId: z.ZodString;
|
|
1170
|
-
status: z.ZodEnum<{
|
|
1171
|
-
pending: "pending";
|
|
1172
|
-
in_progress: "in_progress";
|
|
1173
|
-
completed: "completed";
|
|
1174
|
-
}>;
|
|
1175
|
-
addBlockedBy: z.ZodArray<z.ZodString>;
|
|
1176
|
-
addBlocks: z.ZodArray<z.ZodString>;
|
|
1177
|
-
}, z.core.$strip>;
|
|
1178
|
-
};
|
|
1179
|
-
type TaskUpdateArgs = z.infer<typeof taskUpdateTool.schema>;
|
|
1180
|
-
|
|
1181
|
-
/**
|
|
1182
|
-
* Creates a TaskUpdate handler that modifies task status and dependencies.
|
|
1183
|
-
*
|
|
1184
|
-
* @param stateManager - State manager containing tasks state
|
|
1185
|
-
* @returns A ToolHandler for TaskUpdate tool calls
|
|
1186
|
-
*/
|
|
1187
|
-
declare function createTaskUpdateHandler<TCustom extends JsonSerializable<TCustom>>(stateManager: AgentStateManager<TCustom>): ToolHandler<TaskUpdateArgs, WorkflowTask | null>;
|
|
1188
|
-
|
|
1189
|
-
declare const createBashToolDescription: ({ fileTree, }: {
|
|
1190
|
-
fileTree: string;
|
|
1191
|
-
}) => string;
|
|
1192
|
-
declare const bashTool: {
|
|
1193
|
-
name: "Bash";
|
|
1194
|
-
description: string;
|
|
1195
|
-
schema: z.ZodObject<{
|
|
1196
|
-
command: z.ZodString;
|
|
1197
|
-
}, z.core.$strip>;
|
|
1198
|
-
strict: true;
|
|
1199
|
-
};
|
|
1200
|
-
type BashArgs = z.infer<typeof bashTool.schema>;
|
|
1201
|
-
|
|
1202
|
-
declare const askUserQuestionTool: {
|
|
1203
|
-
name: "AskUserQuestion";
|
|
1204
|
-
description: string;
|
|
1205
|
-
schema: z.ZodObject<{
|
|
1206
|
-
questions: z.ZodArray<z.ZodObject<{
|
|
1207
|
-
question: z.ZodString;
|
|
1208
|
-
header: z.ZodString;
|
|
1209
|
-
options: z.ZodArray<z.ZodObject<{
|
|
1210
|
-
label: z.ZodString;
|
|
1211
|
-
description: z.ZodString;
|
|
1212
|
-
}, z.core.$strip>>;
|
|
1213
|
-
multiSelect: z.ZodBoolean;
|
|
1214
|
-
}, z.core.$strip>>;
|
|
1215
|
-
}, z.core.$strip>;
|
|
1216
|
-
strict: true;
|
|
1217
|
-
};
|
|
1218
|
-
type AskUserQuestionArgs = z.infer<typeof askUserQuestionTool.schema>;
|
|
1219
|
-
|
|
1220
|
-
/**
|
|
1221
|
-
* Creates handler for user interaction tool - creates AI messages for display.
|
|
1222
|
-
*/
|
|
1223
|
-
declare const createAskUserQuestionHandler: () => ActivityToolHandler<AskUserQuestionArgs, {
|
|
1224
|
-
questions: {
|
|
1225
|
-
question: string;
|
|
1226
|
-
header: string;
|
|
1227
|
-
options: {
|
|
1228
|
-
label: string;
|
|
1229
|
-
description: string;
|
|
1230
|
-
}[];
|
|
1231
|
-
multiSelect: boolean;
|
|
1232
|
-
}[];
|
|
1233
|
-
}>;
|
|
890
|
+
type ModelInvoker<M = unknown> = (config: ModelInvokerConfig) => Promise<AgentResponse<M>>;
|
|
1234
891
|
|
|
1235
|
-
export { type
|
|
892
|
+
export { type ToolHandlerContext as $, type AgentResponse as A, type BaseAgentState as B, type ContentPart as C, type SessionEndHook as D, type SessionEndHookContext as E, type SessionExitReason as F, type SessionStartHook as G, type Hooks as H, type InferToolResults as I, type SessionStartHookContext as J, type SubagentArgs as K, type SubagentConfig as L, type ModelInvoker as M, type SubagentHooks as N, type SubagentInput as O, type ParsedToolCall as P, type SubagentWorkflow as Q, type RunAgentConfig as R, type SkillProvider as S, type ThreadOps as T, type TaskStatus as U, type TokenUsage as V, type ToolArgs as W, type ToolCallResult as X, type ToolCallResultUnion as Y, type ToolDefinition as Z, type ToolHandler as _, type ModelInvokerConfig as a, type ToolHandlerResponse as a0, type ToolHooks as a1, type ToolMap as a2, type ToolMessageContent as a3, type ToolNames as a4, type ToolResult as a5, type ToolResultConfig as a6, type ToolRouter as a7, type ToolWithHandler as a8, type WorkflowTask as a9, agentQueryName as aa, agentStateChangeUpdateName as ab, createSubagentTool as ac, createToolRouter as ad, defineSubagent as ae, defineTool as af, hasNoOtherToolCalls as ag, isTerminalStatus as ah, withAutoAppend as ai, type ActivityToolHandler as b, type SkillMetadata as c, type Skill as d, type AgentConfig as e, type AgentFile as f, type AgentStatus as g, type AppendToolResultFn as h, type MessageContent as i, type ParsedToolCallUnion as j, type PostHumanMessageAppendHook as k, type PostHumanMessageAppendHookContext as l, type PostToolUseFailureHook as m, type PostToolUseFailureHookContext as n, type PostToolUseFailureHookResult as o, type PostToolUseHook as p, type PostToolUseHookContext as q, type PreHumanMessageAppendHook as r, type PreHumanMessageAppendHookContext as s, type PreToolUseHook as t, type PreToolUseHookContext as u, type PreToolUseHookResult as v, type ProcessToolCallsContext as w, type RawToolCall as x, type RunAgentActivity as y, type SessionConfig as z };
|