@ellyco/agentic 0.1.2 → 0.2.1
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 +88 -126
- package/dist/graphs/graph.d.ts.map +1 -1
- package/dist/graphs/graph.js +72 -47
- package/dist/graphs/graph.js.map +1 -1
- package/dist/graphs/index.d.ts +0 -1
- package/dist/graphs/index.d.ts.map +1 -1
- package/dist/graphs/index.js +0 -1
- package/dist/graphs/index.js.map +1 -1
- package/dist/graphs/iterator.d.ts +25 -21
- package/dist/graphs/iterator.d.ts.map +1 -1
- package/dist/graphs/iterator.js +30 -25
- package/dist/graphs/iterator.js.map +1 -1
- package/dist/graphs/types.d.ts +2 -3
- package/dist/graphs/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/models/BaseModel.d.ts +3 -1
- package/dist/models/BaseModel.d.ts.map +1 -1
- package/dist/models/BaseModel.js +5 -0
- package/dist/models/BaseModel.js.map +1 -1
- package/dist/models/react-agent.d.ts +12 -0
- package/dist/models/react-agent.d.ts.map +1 -0
- package/dist/models/react-agent.js +48 -0
- package/dist/models/react-agent.js.map +1 -0
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.d.ts.map +1 -1
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/index.js.map +1 -1
- package/dist/nodes/model-node.d.ts +207 -25
- package/dist/nodes/model-node.d.ts.map +1 -1
- package/dist/nodes/model-node.js +124 -24
- package/dist/nodes/model-node.js.map +1 -1
- package/dist/nodes/state-transform.d.ts +108 -0
- package/dist/nodes/state-transform.d.ts.map +1 -0
- package/dist/nodes/state-transform.js +141 -0
- package/dist/nodes/state-transform.js.map +1 -0
- package/dist/tools.d.ts +10 -9
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +3 -2
- package/dist/tools.js.map +1 -1
- package/dist/util/clone-aware.d.ts +2 -0
- package/dist/util/clone-aware.d.ts.map +1 -0
- package/dist/util/clone-aware.js +29 -0
- package/dist/util/clone-aware.js.map +1 -0
- package/dist/util/index.d.ts +4 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +20 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/merge-state.d.ts +50 -0
- package/dist/util/merge-state.d.ts.map +1 -0
- package/dist/util/merge-state.js +88 -0
- package/dist/util/merge-state.js.map +1 -0
- package/dist/util/serializer.d.ts +15 -0
- package/dist/util/serializer.d.ts.map +1 -0
- package/dist/util/serializer.js +73 -0
- package/dist/util/serializer.js.map +1 -0
- package/package.json +5 -1
- package/dist/graphs/merge-state.d.ts +0 -22
- package/dist/graphs/merge-state.d.ts.map +0 -1
- package/dist/graphs/merge-state.js +0 -56
- package/dist/graphs/merge-state.js.map +0 -1
package/dist/nodes/model-node.js
CHANGED
|
@@ -9,71 +9,171 @@ const BaseModel_1 = require("../models/BaseModel");
|
|
|
9
9
|
* @param {any} value - Value to check
|
|
10
10
|
* @returns {boolean} True if value is a messages-returning function
|
|
11
11
|
*/
|
|
12
|
-
function
|
|
12
|
+
function isMessagesConstructed(value) {
|
|
13
|
+
return typeof value === "function";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Type guard to check if a value is a function that constructs output from the model response.
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
* @param {any} value - Value to check
|
|
20
|
+
* @returns {boolean} True if value is an output-constructing function
|
|
21
|
+
*/
|
|
22
|
+
function isOutputConstructed(value) {
|
|
23
|
+
return typeof value === "function";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type guard to check if a value is a function that dynamically generates a system message.
|
|
27
|
+
*
|
|
28
|
+
* @private
|
|
29
|
+
* @param {any} value - Value to check
|
|
30
|
+
* @returns {boolean} True if value is a system message function
|
|
31
|
+
*/
|
|
32
|
+
function isSystemMessageDynamic(value) {
|
|
33
|
+
return typeof value === "function";
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Type guard to check if a value is a function that dynamically generates tool definitions.
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @param {any} value - Value to check
|
|
40
|
+
* @returns {boolean} True if value is a tools function
|
|
41
|
+
*/
|
|
42
|
+
function isToolsDynamic(value) {
|
|
13
43
|
return typeof value === "function";
|
|
14
44
|
}
|
|
15
45
|
/**
|
|
16
46
|
* A node that invokes an AI model and stores the response in the state.
|
|
17
|
-
*
|
|
47
|
+
*
|
|
48
|
+
* ModelNode provides flexible configuration for:
|
|
49
|
+
* - Message sources: read from state or construct dynamically
|
|
50
|
+
* - Output handling: store in state key or transform via function
|
|
51
|
+
* - System messages: static or dynamic based on state/context
|
|
52
|
+
* - Tool definitions: static or dynamic (ignored for StructuredOutputWrapper)
|
|
53
|
+
*
|
|
54
|
+
* Supports both regular BaseModel instances (returns messages) and StructuredOutputWrapper
|
|
55
|
+
* instances (returns structured data matching a Zod schema).
|
|
18
56
|
*
|
|
19
57
|
* @class ModelNode
|
|
20
58
|
* @template T - The state type
|
|
21
|
-
* @
|
|
59
|
+
* @template M - The model type (BaseModel or StructuredOutputWrapper), defaults to BaseModel
|
|
60
|
+
* @implements {NodeLike<T>}
|
|
22
61
|
*
|
|
23
62
|
* @example
|
|
24
63
|
* ```typescript
|
|
25
|
-
* //
|
|
64
|
+
* // Basic usage with messages from state
|
|
26
65
|
* const node = new ModelNode(model, {
|
|
27
|
-
* messages:
|
|
66
|
+
* messages: "conversationMessages",
|
|
28
67
|
* output: "modelResponse"
|
|
29
68
|
* });
|
|
30
69
|
*
|
|
31
|
-
* //
|
|
70
|
+
* // Dynamic message construction
|
|
32
71
|
* const node = new ModelNode(model, {
|
|
33
|
-
* messages:
|
|
72
|
+
* messages: (state, context) => [new UserMessage(state.input)],
|
|
34
73
|
* output: "modelResponse"
|
|
35
74
|
* });
|
|
75
|
+
*
|
|
76
|
+
* // With structured output
|
|
77
|
+
* const structuredModel = model.withStructuredOutput(z.object({
|
|
78
|
+
* name: z.string(),
|
|
79
|
+
* age: z.number()
|
|
80
|
+
* }));
|
|
81
|
+
* const node = new ModelNode(structuredModel, {
|
|
82
|
+
* messages: "userInput",
|
|
83
|
+
* output: "extractedData"
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* // Dynamic output transformation
|
|
87
|
+
* const node = new ModelNode(model, {
|
|
88
|
+
* messages: "messages",
|
|
89
|
+
* output: (response, state, context) => ({
|
|
90
|
+
* modelResponse: response.messages,
|
|
91
|
+
* tokenUsage: response.usage,
|
|
92
|
+
* timestamp: Date.now()
|
|
93
|
+
* })
|
|
94
|
+
* });
|
|
36
95
|
* ```
|
|
37
96
|
*/
|
|
38
97
|
class ModelNode {
|
|
39
98
|
model;
|
|
40
|
-
|
|
99
|
+
config;
|
|
41
100
|
/**
|
|
42
101
|
* Creates a new model node.
|
|
43
102
|
*
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
103
|
+
* @param {M} model - The model to invoke (BaseModel or StructuredOutputWrapper)
|
|
104
|
+
* @param {ModelNodeConfig<T, M>} config - Configuration for messages, output, system message, and tools
|
|
46
105
|
*/
|
|
47
|
-
constructor(model,
|
|
106
|
+
constructor(model, config) {
|
|
48
107
|
this.model = model;
|
|
49
|
-
this.
|
|
108
|
+
this.config = config;
|
|
50
109
|
}
|
|
51
110
|
/**
|
|
52
111
|
* Runs the model with configured messages and stores the response in state.
|
|
53
112
|
*
|
|
113
|
+
* Execution flow:
|
|
114
|
+
* 1. Resolves messages from config (state key or function)
|
|
115
|
+
* 2. Applies system message if configured (static or dynamic)
|
|
116
|
+
* 3. Applies tools if configured and model is not StructuredOutputWrapper (static or dynamic)
|
|
117
|
+
* 4. Invokes the model with resolved messages
|
|
118
|
+
* 5. Transforms response based on output config (state key or function)
|
|
119
|
+
*
|
|
120
|
+
* For StructuredOutputWrapper: the response is the structured data directly.
|
|
121
|
+
* For BaseModel: the response contains messages array and usage information.
|
|
122
|
+
*
|
|
54
123
|
* @param {T} state - The current state
|
|
55
124
|
* @param {ContextLayer} context - The execution context
|
|
56
|
-
* @returns {Promise<Partial<T>>} Partial state containing the model's response
|
|
57
|
-
* @throws {Error} If messages
|
|
125
|
+
* @returns {Promise<Partial<T>>} Partial state update containing the model's response
|
|
126
|
+
* @throws {Error} If messages key is specified but not found in state, or if the value is not an array
|
|
58
127
|
*/
|
|
59
128
|
async run(state, context) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
129
|
+
const { messages, output, systemMessage, tools } = this.config;
|
|
130
|
+
let inMessages = [];
|
|
131
|
+
if (isMessagesConstructed(messages)) {
|
|
132
|
+
inMessages = messages(state, context);
|
|
63
133
|
}
|
|
64
134
|
else {
|
|
65
|
-
const stateMessages = state[
|
|
135
|
+
const stateMessages = state[messages];
|
|
66
136
|
if (!stateMessages || !Array.isArray(stateMessages)) {
|
|
67
|
-
throw new Error(`No Messages array found for key ${
|
|
137
|
+
throw new Error(`No Messages array found for key ${messages}`);
|
|
68
138
|
}
|
|
69
|
-
|
|
139
|
+
inMessages = stateMessages;
|
|
140
|
+
}
|
|
141
|
+
if (systemMessage) {
|
|
142
|
+
let inSystemMessage;
|
|
143
|
+
if (isSystemMessageDynamic(systemMessage)) {
|
|
144
|
+
inSystemMessage = systemMessage(state, context);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
inSystemMessage = systemMessage;
|
|
148
|
+
}
|
|
149
|
+
this.model.withSystemMessage(inSystemMessage);
|
|
150
|
+
}
|
|
151
|
+
if (tools && !(this.model instanceof BaseModel_1.StructuredOutputWrapper)) {
|
|
152
|
+
let inTools;
|
|
153
|
+
if (isToolsDynamic(tools)) {
|
|
154
|
+
inTools = tools(state, context);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
inTools = tools;
|
|
158
|
+
}
|
|
159
|
+
this.model.withTools(inTools);
|
|
70
160
|
}
|
|
71
161
|
if (this.model instanceof BaseModel_1.StructuredOutputWrapper) {
|
|
72
|
-
const
|
|
73
|
-
|
|
162
|
+
const structuredOutput = await this.model.invoke(inMessages);
|
|
163
|
+
if (isOutputConstructed(output)) {
|
|
164
|
+
return output(structuredOutput, state, context);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return { [output]: structuredOutput };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const response = await this.model.invoke(inMessages);
|
|
171
|
+
if (isOutputConstructed(output)) {
|
|
172
|
+
return output(response, state, context);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return { [output]: response.messages };
|
|
74
176
|
}
|
|
75
|
-
const response = await this.model.invoke(messages);
|
|
76
|
-
return { [this.settings.output]: response.messages };
|
|
77
177
|
}
|
|
78
178
|
}
|
|
79
179
|
exports.ModelNode = ModelNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-node.js","sourceRoot":"","sources":["../../src/nodes/model-node.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"model-node.js","sourceRoot":"","sources":["../../src/nodes/model-node.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { NodeLike } from "./types";
|
|
3
|
+
import { ContextLayer } from "../graphs/runtime-context";
|
|
4
|
+
import { Graph } from "../graphs/graph";
|
|
5
|
+
/**
|
|
6
|
+
* A node that transforms state between different schemas, allowing nested nodes/graphs
|
|
7
|
+
* to operate on a different state structure than the parent graph.
|
|
8
|
+
*
|
|
9
|
+
* StateTransformNode wraps a node or graph that expects a different state schema.
|
|
10
|
+
* It handles:
|
|
11
|
+
* - Input transformation: converts parent state to child state schema
|
|
12
|
+
* - Schema validation: ensures transformed state matches the child schema
|
|
13
|
+
* - Output transformation: converts child state back to parent state updates
|
|
14
|
+
* - Interrupt handling: preserves wrapped state during interrupts for resumption
|
|
15
|
+
* - State isolation: child state is stored separately during execution
|
|
16
|
+
*
|
|
17
|
+
* This is useful when you need to:
|
|
18
|
+
* - Reuse nodes/graphs with different state schemas
|
|
19
|
+
* - Isolate state transformations within a workflow
|
|
20
|
+
* - Compose graphs with incompatible state structures
|
|
21
|
+
*
|
|
22
|
+
* @class StateTransformNode
|
|
23
|
+
* @template PS - Parent state type (the graph's state schema)
|
|
24
|
+
* @template N - Zod schema object for the child state
|
|
25
|
+
* @template NS - Child state type (inferred from N)
|
|
26
|
+
* @implements {NodeLike<PS>}
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Parent schema
|
|
31
|
+
* const parentSchema = z.object({
|
|
32
|
+
* userId: z.string(),
|
|
33
|
+
* userName: z.string(),
|
|
34
|
+
* count: z.number()
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Child schema
|
|
38
|
+
* const childSchema = z.object({
|
|
39
|
+
* id: z.string(),
|
|
40
|
+
* name: z.string(),
|
|
41
|
+
* value: z.number()
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Transform parent -> child
|
|
45
|
+
* const inputTransform = (state: ParentState): ChildState => ({
|
|
46
|
+
* id: state.userId,
|
|
47
|
+
* name: state.userName,
|
|
48
|
+
* value: state.count
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Transform child -> parent
|
|
52
|
+
* const outputTransform = (state: ChildState): Partial<ParentState> => ({
|
|
53
|
+
* count: state.value
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Create transform node wrapping a child node
|
|
57
|
+
* const childNode = makeNode<ChildState>((state) => ({
|
|
58
|
+
* value: state.value + 1
|
|
59
|
+
* }));
|
|
60
|
+
*
|
|
61
|
+
* const transformNode = new StateTransformNode(
|
|
62
|
+
* childSchema,
|
|
63
|
+
* inputTransform,
|
|
64
|
+
* childNode,
|
|
65
|
+
* outputTransform
|
|
66
|
+
* );
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare class StateTransformNode<PS extends Record<string, unknown>, N extends z.ZodObject, NS extends Record<string, unknown> = z.infer<N>> implements NodeLike<PS> {
|
|
70
|
+
private readonly schema;
|
|
71
|
+
private readonly input;
|
|
72
|
+
private readonly node;
|
|
73
|
+
private readonly output;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new state transform node.
|
|
76
|
+
*
|
|
77
|
+
* @param {N} schema - Zod schema object that validates the child state structure
|
|
78
|
+
* @param {Function} input - Function that transforms parent state to child state
|
|
79
|
+
* @param {NodeLike<NS> | Graph<N, NS>} node - The node or graph to wrap (operates on child state)
|
|
80
|
+
* @param {Function} output - Function that transforms child state back to parent state updates
|
|
81
|
+
*/
|
|
82
|
+
constructor(schema: N, input: (state: PS, context: ContextLayer) => NS, node: NodeLike<NS> | Graph<N, NS>, output: (state: NS, context: ContextLayer) => Partial<PS>);
|
|
83
|
+
/**
|
|
84
|
+
* Executes the wrapped node/graph with transformed state.
|
|
85
|
+
*
|
|
86
|
+
* Execution flow:
|
|
87
|
+
* 1. If resuming from interrupt: restores child state from parent state's wrapped key
|
|
88
|
+
* 2. If not resuming: transforms parent state to child state using input function
|
|
89
|
+
* 3. Validates transformed state against the child schema
|
|
90
|
+
* 4. Attaches parent state reference to child state (as __parentState)
|
|
91
|
+
* 5. Runs the wrapped node/graph with the child state
|
|
92
|
+
* 6. Merges results back into child state
|
|
93
|
+
* 7. If interrupted: stores child state in parent state under wrapped key and returns
|
|
94
|
+
* 8. If completed: transforms child state back to parent state using output function
|
|
95
|
+
* 9. Cleans up wrapped state key from parent state
|
|
96
|
+
*
|
|
97
|
+
* The wrapped state is stored under a key like `__wrappedState_{contextId}.{nodeName}`
|
|
98
|
+
* to allow resumption after interrupts. This key is automatically cleaned up on completion.
|
|
99
|
+
*
|
|
100
|
+
* @param {PS} state - The parent state
|
|
101
|
+
* @param {ContextLayer} context - The execution context
|
|
102
|
+
* @returns {Promise<Partial<PS>>} Partial parent state update
|
|
103
|
+
* @throws {Error} If input transformation doesn't match the child schema (wraps ZodError)
|
|
104
|
+
* @throws {Error} If the wrapped node/graph throws an error (re-thrown)
|
|
105
|
+
*/
|
|
106
|
+
run(state: PS, context: ContextLayer): Promise<Partial<PS>>;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=state-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-transform.d.ts","sourceRoot":"","sources":["../../src/nodes/state-transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,qBAAa,kBAAkB,CAC3B,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,CAAC,SAAS,CAAC,CAAC,SAAS,EACrB,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CACjD,YAAW,QAAQ,CAAC,EAAE,CAAC;IAUjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAZ3B;;;;;;;OAOG;gBAEkB,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,YAAY,KAAK,EAAE,EAC/C,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EACjC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,EAAE,CAAC;IAG9E;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;CAyBpE"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateTransformNode = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const util_1 = require("../util");
|
|
6
|
+
/**
|
|
7
|
+
* A node that transforms state between different schemas, allowing nested nodes/graphs
|
|
8
|
+
* to operate on a different state structure than the parent graph.
|
|
9
|
+
*
|
|
10
|
+
* StateTransformNode wraps a node or graph that expects a different state schema.
|
|
11
|
+
* It handles:
|
|
12
|
+
* - Input transformation: converts parent state to child state schema
|
|
13
|
+
* - Schema validation: ensures transformed state matches the child schema
|
|
14
|
+
* - Output transformation: converts child state back to parent state updates
|
|
15
|
+
* - Interrupt handling: preserves wrapped state during interrupts for resumption
|
|
16
|
+
* - State isolation: child state is stored separately during execution
|
|
17
|
+
*
|
|
18
|
+
* This is useful when you need to:
|
|
19
|
+
* - Reuse nodes/graphs with different state schemas
|
|
20
|
+
* - Isolate state transformations within a workflow
|
|
21
|
+
* - Compose graphs with incompatible state structures
|
|
22
|
+
*
|
|
23
|
+
* @class StateTransformNode
|
|
24
|
+
* @template PS - Parent state type (the graph's state schema)
|
|
25
|
+
* @template N - Zod schema object for the child state
|
|
26
|
+
* @template NS - Child state type (inferred from N)
|
|
27
|
+
* @implements {NodeLike<PS>}
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // Parent schema
|
|
32
|
+
* const parentSchema = z.object({
|
|
33
|
+
* userId: z.string(),
|
|
34
|
+
* userName: z.string(),
|
|
35
|
+
* count: z.number()
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Child schema
|
|
39
|
+
* const childSchema = z.object({
|
|
40
|
+
* id: z.string(),
|
|
41
|
+
* name: z.string(),
|
|
42
|
+
* value: z.number()
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Transform parent -> child
|
|
46
|
+
* const inputTransform = (state: ParentState): ChildState => ({
|
|
47
|
+
* id: state.userId,
|
|
48
|
+
* name: state.userName,
|
|
49
|
+
* value: state.count
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // Transform child -> parent
|
|
53
|
+
* const outputTransform = (state: ChildState): Partial<ParentState> => ({
|
|
54
|
+
* count: state.value
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Create transform node wrapping a child node
|
|
58
|
+
* const childNode = makeNode<ChildState>((state) => ({
|
|
59
|
+
* value: state.value + 1
|
|
60
|
+
* }));
|
|
61
|
+
*
|
|
62
|
+
* const transformNode = new StateTransformNode(
|
|
63
|
+
* childSchema,
|
|
64
|
+
* inputTransform,
|
|
65
|
+
* childNode,
|
|
66
|
+
* outputTransform
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
class StateTransformNode {
|
|
71
|
+
schema;
|
|
72
|
+
input;
|
|
73
|
+
node;
|
|
74
|
+
output;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new state transform node.
|
|
77
|
+
*
|
|
78
|
+
* @param {N} schema - Zod schema object that validates the child state structure
|
|
79
|
+
* @param {Function} input - Function that transforms parent state to child state
|
|
80
|
+
* @param {NodeLike<NS> | Graph<N, NS>} node - The node or graph to wrap (operates on child state)
|
|
81
|
+
* @param {Function} output - Function that transforms child state back to parent state updates
|
|
82
|
+
*/
|
|
83
|
+
constructor(schema, input, node, output) {
|
|
84
|
+
this.schema = schema;
|
|
85
|
+
this.input = input;
|
|
86
|
+
this.node = node;
|
|
87
|
+
this.output = output;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Executes the wrapped node/graph with transformed state.
|
|
91
|
+
*
|
|
92
|
+
* Execution flow:
|
|
93
|
+
* 1. If resuming from interrupt: restores child state from parent state's wrapped key
|
|
94
|
+
* 2. If not resuming: transforms parent state to child state using input function
|
|
95
|
+
* 3. Validates transformed state against the child schema
|
|
96
|
+
* 4. Attaches parent state reference to child state (as __parentState)
|
|
97
|
+
* 5. Runs the wrapped node/graph with the child state
|
|
98
|
+
* 6. Merges results back into child state
|
|
99
|
+
* 7. If interrupted: stores child state in parent state under wrapped key and returns
|
|
100
|
+
* 8. If completed: transforms child state back to parent state using output function
|
|
101
|
+
* 9. Cleans up wrapped state key from parent state
|
|
102
|
+
*
|
|
103
|
+
* The wrapped state is stored under a key like `__wrappedState_{contextId}.{nodeName}`
|
|
104
|
+
* to allow resumption after interrupts. This key is automatically cleaned up on completion.
|
|
105
|
+
*
|
|
106
|
+
* @param {PS} state - The parent state
|
|
107
|
+
* @param {ContextLayer} context - The execution context
|
|
108
|
+
* @returns {Promise<Partial<PS>>} Partial parent state update
|
|
109
|
+
* @throws {Error} If input transformation doesn't match the child schema (wraps ZodError)
|
|
110
|
+
* @throws {Error} If the wrapped node/graph throws an error (re-thrown)
|
|
111
|
+
*/
|
|
112
|
+
async run(state, context) {
|
|
113
|
+
const wrappedStateKey = `__wrappedState_${context.id}.${context.currentNode}`;
|
|
114
|
+
try {
|
|
115
|
+
let nodeState;
|
|
116
|
+
if (context.runtime.resuming) {
|
|
117
|
+
nodeState = { ...state[wrappedStateKey], __parentState: state };
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const inputTransformed = this.input(state, context);
|
|
121
|
+
nodeState = { ...this.schema.parse(inputTransformed), __parentState: state };
|
|
122
|
+
}
|
|
123
|
+
const result = await this.node.run((0, util_1.cloneAware)(nodeState), context);
|
|
124
|
+
nodeState = { ...nodeState, ...result };
|
|
125
|
+
if (context.runtime.interrupted) {
|
|
126
|
+
const { __parentState, ...rest } = nodeState;
|
|
127
|
+
return { [wrappedStateKey]: rest };
|
|
128
|
+
}
|
|
129
|
+
const outState = this.output(nodeState, context);
|
|
130
|
+
return { ...outState, [wrappedStateKey]: undefined };
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (error instanceof zod_1.z.ZodError) {
|
|
134
|
+
throw new Error(`Transformed input does not match schema: ${error.message}`);
|
|
135
|
+
}
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.StateTransformNode = StateTransformNode;
|
|
141
|
+
//# sourceMappingURL=state-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-transform.js","sourceRoot":"","sources":["../../src/nodes/state-transform.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAIxB,kCAAqC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAa,kBAAkB;IAcN;IACA;IACA;IACA;IAZrB;;;;;;;OAOG;IACH,YACqB,MAAS,EACT,KAA+C,EAC/C,IAAiC,EACjC,MAAyD;QAHzD,WAAM,GAAN,MAAM,CAAG;QACT,UAAK,GAAL,KAAK,CAA0C;QAC/C,SAAI,GAAJ,IAAI,CAA6B;QACjC,WAAM,GAAN,MAAM,CAAmD;IAC1E,CAAC;IAEL;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,GAAG,CAAC,KAAS,EAAE,OAAqB;QACtC,MAAM,eAAe,GAAG,kBAAkB,OAAO,CAAC,EAAE,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QAC9E,IAAI,CAAC;YACD,IAAI,SAAa,CAAC;YAClB,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;gBAC3B,SAAS,GAAG,EAAE,GAAG,KAAK,CAAC,eAAe,CAAO,EAAE,aAAa,EAAE,KAAK,EAAQ,CAAC;YAChF,CAAC;iBAAM,CAAC;gBACJ,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;gBACpD,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,aAAa,EAAE,KAAK,EAAQ,CAAC;YACvF,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAA,iBAAU,EAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;YACnE,SAAS,GAAG,EAAE,GAAG,SAAS,EAAE,GAAG,MAAM,EAAQ,CAAC;YAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBAC9B,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,EAAE,GAAG,SAAS,CAAC;gBAC7C,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,IAAI,EAAiB,CAAC;YACtD,CAAC;YACD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YACjD,OAAO,EAAE,GAAG,QAAQ,EAAE,CAAC,eAAe,CAAC,EAAE,SAAS,EAAiB,CAAC;QACxE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,KAAK,YAAY,OAAC,CAAC,QAAQ,EAAE,CAAC;gBAC9B,MAAM,IAAI,KAAK,CAAC,4CAA4C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;YACjF,CAAC;YACD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AApED,gDAoEC"}
|
package/dist/tools.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ import * as z from "zod";
|
|
|
7
7
|
* @property {string} [description] - Human-readable description of what the tool does
|
|
8
8
|
* @property {z.ZodSchema<T>} schema - Zod schema that validates the tool's input parameters
|
|
9
9
|
*/
|
|
10
|
-
export interface ToolDefinition<T =
|
|
10
|
+
export interface ToolDefinition<T = z.ZodObject> {
|
|
11
11
|
name: string;
|
|
12
12
|
description?: string;
|
|
13
|
-
schema:
|
|
13
|
+
schema: T;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* Creates a tool definition with validation schema.
|
|
@@ -31,24 +31,26 @@ export interface ToolDefinition<T = object> {
|
|
|
31
31
|
* );
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export declare function defineTool<T>(name: string, description: string, schema:
|
|
34
|
+
export declare function defineTool<T extends z.ZodObject>(name: string, description: string, schema: T): ToolDefinition<T>;
|
|
35
35
|
/**
|
|
36
36
|
* Internal interface extending ToolDefinition with the actual implementation function.
|
|
37
37
|
*
|
|
38
38
|
* @template T - The input type for the tool
|
|
39
39
|
* @template K - The output type returned by the tool function
|
|
40
|
+
* @template A - The additional arguments type
|
|
40
41
|
*/
|
|
41
|
-
interface ToolImplementation<T, K
|
|
42
|
-
func: (input: T) => K | Promise<K>;
|
|
42
|
+
export interface ToolImplementation<T extends z.ZodObject, K, A extends Record<string, any>> extends ToolDefinition<T> {
|
|
43
|
+
func: (input: z.infer<T>, additionalArgs?: A) => K | Promise<K>;
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
46
|
* Creates a complete tool implementation by combining a tool definition with its function.
|
|
46
47
|
*
|
|
47
48
|
* @template T - The input parameter type
|
|
48
49
|
* @template K - The return type of the tool function
|
|
50
|
+
* @template A - The additional arguments type
|
|
49
51
|
* @param {ToolDefinition<T>} toolDefinition - The tool definition created with defineTool()
|
|
50
|
-
* @param {(input: T) => K | Promise<K>} func - The function that implements the tool's behavior
|
|
51
|
-
* @returns {ToolImplementation<T, K>} A complete tool with both definition and implementation
|
|
52
|
+
* @param {(input: T, additionalArgs?: Record<string, any>) => K | Promise<K>} func - The function that implements the tool's behavior
|
|
53
|
+
* @returns {ToolImplementation<T, K, A>} A complete tool with both definition and implementation
|
|
52
54
|
*
|
|
53
55
|
* @example
|
|
54
56
|
* ```typescript
|
|
@@ -60,6 +62,5 @@ interface ToolImplementation<T, K> extends ToolDefinition<T> {
|
|
|
60
62
|
* );
|
|
61
63
|
* ```
|
|
62
64
|
*/
|
|
63
|
-
export declare function tool<T, K
|
|
64
|
-
export {};
|
|
65
|
+
export declare function tool<T extends z.ZodObject, K, A extends Record<string, any>>(toolDefinition: ToolDefinition<T>, func: (input: z.infer<T>, additionalArgs?: A) => K | Promise<K>): ToolImplementation<T, K, A>;
|
|
65
66
|
//# sourceMappingURL=tools.d.ts.map
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,CAAC,CAAC;CACb;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,EAC5C,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,CAAC,GACV,cAAc,CAAC,CAAC,CAAC,CAMnB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IAClH,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACnE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxE,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,EACjC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAChE,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAK7B"}
|
package/dist/tools.js
CHANGED
|
@@ -33,9 +33,10 @@ function defineTool(name, description, schema) {
|
|
|
33
33
|
*
|
|
34
34
|
* @template T - The input parameter type
|
|
35
35
|
* @template K - The return type of the tool function
|
|
36
|
+
* @template A - The additional arguments type
|
|
36
37
|
* @param {ToolDefinition<T>} toolDefinition - The tool definition created with defineTool()
|
|
37
|
-
* @param {(input: T) => K | Promise<K>} func - The function that implements the tool's behavior
|
|
38
|
-
* @returns {ToolImplementation<T, K>} A complete tool with both definition and implementation
|
|
38
|
+
* @param {(input: T, additionalArgs?: Record<string, any>) => K | Promise<K>} func - The function that implements the tool's behavior
|
|
39
|
+
* @returns {ToolImplementation<T, K, A>} A complete tool with both definition and implementation
|
|
39
40
|
*
|
|
40
41
|
* @example
|
|
41
42
|
* ```typescript
|
package/dist/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":";;AAmCA,gCAUC;
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":";;AAmCA,gCAUC;AAiCD,oBAQC;AAtED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,UAAU,CACtB,IAAY,EACZ,WAAmB,EACnB,MAAS;IAET,OAAO;QACH,IAAI;QACJ,WAAW;QACX,MAAM;KACT,CAAC;AACN,CAAC;AAaD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,IAAI,CAChB,cAAiC,EACjC,IAA+D;IAE/D,OAAO;QACH,GAAG,cAAc;QACjB,IAAI;KACP,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone-aware.d.ts","sourceRoot":"","sources":["../../src/util/clone-aware.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAyBnF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cloneAware = cloneAware;
|
|
4
|
+
const serializer_1 = require("./serializer");
|
|
5
|
+
// this creates a deep clone of something - an object, array, or primitive - while being aware of the classes that can be serialized/deserialized
|
|
6
|
+
function cloneAware(value) {
|
|
7
|
+
if (typeof value === "object" && value !== null) {
|
|
8
|
+
// The value is a class
|
|
9
|
+
if ('constructor' in value && !["Object", "Array"].includes(value.constructor.name)) {
|
|
10
|
+
return (0, serializer_1.deserialize)((0, serializer_1.serialize)(value));
|
|
11
|
+
}
|
|
12
|
+
// The value is an array
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
const newArr = [];
|
|
15
|
+
for (const item of value) {
|
|
16
|
+
newArr.push(cloneAware(item));
|
|
17
|
+
}
|
|
18
|
+
return newArr;
|
|
19
|
+
}
|
|
20
|
+
// The value is a plain object
|
|
21
|
+
const newObj = {};
|
|
22
|
+
for (const key in value) {
|
|
23
|
+
newObj[key] = cloneAware(value[key]);
|
|
24
|
+
}
|
|
25
|
+
return newObj;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=clone-aware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clone-aware.js","sourceRoot":"","sources":["../../src/util/clone-aware.ts"],"names":[],"mappings":";;AAGA,gCAyBC;AA5BD,6CAAsD;AAEtD,iJAAiJ;AACjJ,SAAgB,UAAU,CAA8C,KAAQ;IAC5E,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC9C,uBAAuB;QACvB,IAAI,aAAa,IAAI,KAAK,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;YAClF,OAAO,IAAA,wBAAW,EAAC,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAM,CAAC;QAC9C,CAAC;QAED,wBAAwB;QACxB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,MAAM,GAAG,EAAE,CAAC;YAClB,KAAK,MAAM,IAAI,IAAI,KAAuB,EAAE,CAAC;gBACzC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,MAAW,CAAC;QACvB,CAAC;QAED,8BAA8B;QAC9B,MAAM,MAAM,GAAG,EAA6B,CAAC;QAC7C,KAAK,MAAM,GAAG,IAAI,KAAgC,EAAE,CAAC;YACjD,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAE,KAAiC,CAAC,GAAG,CAAC,CAAC,CAAC;QACtE,CAAC;QACD,OAAO,MAAW,CAAC;IAEvB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./clone-aware"), exports);
|
|
18
|
+
__exportStar(require("./merge-state"), exports);
|
|
19
|
+
__exportStar(require("./serializer"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,gDAA8B;AAC9B,+CAA6B"}
|