@ellyco/agentic 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.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +560 -0
  3. package/dist/graphs/graph.d.ts +218 -0
  4. package/dist/graphs/graph.d.ts.map +1 -0
  5. package/dist/graphs/graph.js +334 -0
  6. package/dist/graphs/graph.js.map +1 -0
  7. package/dist/graphs/index.d.ts +7 -0
  8. package/dist/graphs/index.d.ts.map +1 -0
  9. package/dist/graphs/index.js +15 -0
  10. package/dist/graphs/index.js.map +1 -0
  11. package/dist/graphs/iterator.d.ts +138 -0
  12. package/dist/graphs/iterator.d.ts.map +1 -0
  13. package/dist/graphs/iterator.js +184 -0
  14. package/dist/graphs/iterator.js.map +1 -0
  15. package/dist/graphs/merge-state.d.ts +22 -0
  16. package/dist/graphs/merge-state.d.ts.map +1 -0
  17. package/dist/graphs/merge-state.js +56 -0
  18. package/dist/graphs/merge-state.js.map +1 -0
  19. package/dist/graphs/node-sequence.d.ts +63 -0
  20. package/dist/graphs/node-sequence.d.ts.map +1 -0
  21. package/dist/graphs/node-sequence.js +84 -0
  22. package/dist/graphs/node-sequence.js.map +1 -0
  23. package/dist/graphs/registry.d.ts +5 -0
  24. package/dist/graphs/registry.d.ts.map +1 -0
  25. package/dist/graphs/registry.js +6 -0
  26. package/dist/graphs/registry.js.map +1 -0
  27. package/dist/graphs/runtime-context.d.ts +189 -0
  28. package/dist/graphs/runtime-context.d.ts.map +1 -0
  29. package/dist/graphs/runtime-context.js +254 -0
  30. package/dist/graphs/runtime-context.js.map +1 -0
  31. package/dist/graphs/state-machine.d.ts +105 -0
  32. package/dist/graphs/state-machine.d.ts.map +1 -0
  33. package/dist/graphs/state-machine.js +130 -0
  34. package/dist/graphs/state-machine.js.map +1 -0
  35. package/dist/graphs/store/base-store.d.ts +90 -0
  36. package/dist/graphs/store/base-store.d.ts.map +1 -0
  37. package/dist/graphs/store/base-store.js +50 -0
  38. package/dist/graphs/store/base-store.js.map +1 -0
  39. package/dist/graphs/store/sqlite-store.d.ts +88 -0
  40. package/dist/graphs/store/sqlite-store.d.ts.map +1 -0
  41. package/dist/graphs/store/sqlite-store.js +109 -0
  42. package/dist/graphs/store/sqlite-store.js.map +1 -0
  43. package/dist/graphs/store/stored-run.d.ts +77 -0
  44. package/dist/graphs/store/stored-run.d.ts.map +1 -0
  45. package/dist/graphs/store/stored-run.js +88 -0
  46. package/dist/graphs/store/stored-run.js.map +1 -0
  47. package/dist/graphs/types.d.ts +15 -0
  48. package/dist/graphs/types.d.ts.map +1 -0
  49. package/dist/graphs/types.js +3 -0
  50. package/dist/graphs/types.js.map +1 -0
  51. package/dist/messages/index.d.ts +6 -0
  52. package/dist/messages/index.d.ts.map +1 -0
  53. package/dist/messages/index.js +19 -0
  54. package/dist/messages/index.js.map +1 -0
  55. package/dist/messages/message.d.ts +143 -0
  56. package/dist/messages/message.d.ts.map +1 -0
  57. package/dist/messages/message.js +172 -0
  58. package/dist/messages/message.js.map +1 -0
  59. package/dist/messages/tool.d.ts +160 -0
  60. package/dist/messages/tool.d.ts.map +1 -0
  61. package/dist/messages/tool.js +173 -0
  62. package/dist/messages/tool.js.map +1 -0
  63. package/dist/models/BaseModel.d.ts +232 -0
  64. package/dist/models/BaseModel.d.ts.map +1 -0
  65. package/dist/models/BaseModel.js +247 -0
  66. package/dist/models/BaseModel.js.map +1 -0
  67. package/dist/models/BedrockModel.d.ts +112 -0
  68. package/dist/models/BedrockModel.d.ts.map +1 -0
  69. package/dist/models/BedrockModel.js +315 -0
  70. package/dist/models/BedrockModel.js.map +1 -0
  71. package/dist/models/TestModel.d.ts +135 -0
  72. package/dist/models/TestModel.d.ts.map +1 -0
  73. package/dist/models/TestModel.js +191 -0
  74. package/dist/models/TestModel.js.map +1 -0
  75. package/dist/nodes/function-node.d.ts +59 -0
  76. package/dist/nodes/function-node.d.ts.map +1 -0
  77. package/dist/nodes/function-node.js +72 -0
  78. package/dist/nodes/function-node.js.map +1 -0
  79. package/dist/nodes/index.d.ts +4 -0
  80. package/dist/nodes/index.d.ts.map +1 -0
  81. package/dist/nodes/index.js +9 -0
  82. package/dist/nodes/index.js.map +1 -0
  83. package/dist/nodes/interrupt-node.d.ts +51 -0
  84. package/dist/nodes/interrupt-node.d.ts.map +1 -0
  85. package/dist/nodes/interrupt-node.js +65 -0
  86. package/dist/nodes/interrupt-node.js.map +1 -0
  87. package/dist/nodes/model-node.d.ts +72 -0
  88. package/dist/nodes/model-node.d.ts.map +1 -0
  89. package/dist/nodes/model-node.js +80 -0
  90. package/dist/nodes/model-node.js.map +1 -0
  91. package/dist/nodes/types.d.ts +5 -0
  92. package/dist/nodes/types.d.ts.map +1 -0
  93. package/dist/nodes/types.js +3 -0
  94. package/dist/nodes/types.js.map +1 -0
  95. package/dist/tools.d.ts +65 -0
  96. package/dist/tools.d.ts.map +1 -0
  97. package/dist/tools.js +56 -0
  98. package/dist/tools.js.map +1 -0
  99. package/dist/types.d.ts +17 -0
  100. package/dist/types.d.ts.map +1 -0
  101. package/dist/types.js +3 -0
  102. package/dist/types.js.map +1 -0
  103. package/package.json +32 -0
@@ -0,0 +1,59 @@
1
+ import { type NodeLike } from "./types";
2
+ import { ContextLayer } from "../graphs";
3
+ /**
4
+ * A simple node that executes a function and returns partial state updates.
5
+ * Useful for stateless transformations or computations within a graph.
6
+ *
7
+ * @class FunctionNode
8
+ * @template T - The state type
9
+ * @implements {NodeLike<T, Partial<T>>}
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const doubleNode = new FunctionNode((state) => ({
14
+ * count: state.count * 2
15
+ * }));
16
+ *
17
+ * // Or using the helper function
18
+ * const node = makeNode((state, context) => ({
19
+ * result: state.input + " processed"
20
+ * }));
21
+ * ```
22
+ */
23
+ export declare class FunctionNode<T extends Record<string, unknown>> implements NodeLike<T, Partial<T>> {
24
+ private readonly func;
25
+ /**
26
+ * Creates a new function node.
27
+ *
28
+ * @param {(state: T, context: ContextLayer) => Partial<T> | Promise<Partial<T>>} func
29
+ * The function to execute. Can return state changes synchronously or asynchronously.
30
+ * The function receives the current state and context layer.
31
+ */
32
+ constructor(func: (state: T, context: ContextLayer) => Partial<T> | Promise<Partial<T>>);
33
+ /**
34
+ * Executes the function and returns the state updates.
35
+ *
36
+ * @param {T} state - The current state
37
+ * @param {ContextLayer} context - The execution context
38
+ * @returns {Promise<Partial<T>>} Partial state updates from the function
39
+ */
40
+ run(state: T, context: ContextLayer): Promise<Partial<T>>;
41
+ }
42
+ /**
43
+ * Helper function to create a FunctionNode with type inference.
44
+ *
45
+ * @template T - The state type
46
+ * @param {(state: T, context: ContextLayer) => Partial<T> | Promise<Partial<T>>} func
47
+ * The function to execute
48
+ * @returns {NodeLike<T, Partial<T>>} A node that can be used in a graph
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const node = makeNode((state, context) => {
53
+ * console.log("Executing node with state:", state);
54
+ * return { processed: true };
55
+ * });
56
+ * ```
57
+ */
58
+ export declare function makeNode<T extends Record<string, unknown>>(func: (state: T, context: ContextLayer) => Partial<T> | Promise<Partial<T>>): NodeLike<T, Partial<T>>;
59
+ //# sourceMappingURL=function-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-node.d.ts","sourceRoot":"","sources":["../../src/nodes/function-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IASvF,OAAO,CAAC,QAAQ,CAAC,IAAI;IARzB;;;;;;OAMG;gBAEkB,IAAI,EAAE,CACnB,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,YAAY,KACpB,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAGzC;;;;;;OAMG;IACG,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAQlE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtD,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAC5E,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAEzB"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionNode = void 0;
4
+ exports.makeNode = makeNode;
5
+ /**
6
+ * A simple node that executes a function and returns partial state updates.
7
+ * Useful for stateless transformations or computations within a graph.
8
+ *
9
+ * @class FunctionNode
10
+ * @template T - The state type
11
+ * @implements {NodeLike<T, Partial<T>>}
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const doubleNode = new FunctionNode((state) => ({
16
+ * count: state.count * 2
17
+ * }));
18
+ *
19
+ * // Or using the helper function
20
+ * const node = makeNode((state, context) => ({
21
+ * result: state.input + " processed"
22
+ * }));
23
+ * ```
24
+ */
25
+ class FunctionNode {
26
+ func;
27
+ /**
28
+ * Creates a new function node.
29
+ *
30
+ * @param {(state: T, context: ContextLayer) => Partial<T> | Promise<Partial<T>>} func
31
+ * The function to execute. Can return state changes synchronously or asynchronously.
32
+ * The function receives the current state and context layer.
33
+ */
34
+ constructor(func) {
35
+ this.func = func;
36
+ }
37
+ /**
38
+ * Executes the function and returns the state updates.
39
+ *
40
+ * @param {T} state - The current state
41
+ * @param {ContextLayer} context - The execution context
42
+ * @returns {Promise<Partial<T>>} Partial state updates from the function
43
+ */
44
+ async run(state, context) {
45
+ const response = this.func(state, context);
46
+ if (response instanceof Promise) {
47
+ return await response;
48
+ }
49
+ return response;
50
+ }
51
+ }
52
+ exports.FunctionNode = FunctionNode;
53
+ /**
54
+ * Helper function to create a FunctionNode with type inference.
55
+ *
56
+ * @template T - The state type
57
+ * @param {(state: T, context: ContextLayer) => Partial<T> | Promise<Partial<T>>} func
58
+ * The function to execute
59
+ * @returns {NodeLike<T, Partial<T>>} A node that can be used in a graph
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const node = makeNode((state, context) => {
64
+ * console.log("Executing node with state:", state);
65
+ * return { processed: true };
66
+ * });
67
+ * ```
68
+ */
69
+ function makeNode(func) {
70
+ return new FunctionNode(func);
71
+ }
72
+ //# sourceMappingURL=function-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-node.js","sourceRoot":"","sources":["../../src/nodes/function-node.ts"],"names":[],"mappings":";;;AAuEA,4BAIC;AAxED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,YAAY;IASA;IARrB;;;;;;OAMG;IACH,YACqB,IAGoB;QAHpB,SAAI,GAAJ,IAAI,CAGgB;IACrC,CAAC;IAEL;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,CAAC,KAAQ,EAAE,OAAqB;QACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,QAAQ,YAAY,OAAO,EAAE,CAAC;YAC9B,OAAO,MAAM,QAAQ,CAAC;QAC1B,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AA9BD,oCA8BC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,QAAQ,CACpB,IAA2E;IAE3E,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { FunctionNode, makeNode } from "./function-node";
2
+ export { InterruptNode } from "./interrupt-node";
3
+ export { type NodeLike } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InterruptNode = exports.makeNode = exports.FunctionNode = void 0;
4
+ var function_node_1 = require("./function-node");
5
+ Object.defineProperty(exports, "FunctionNode", { enumerable: true, get: function () { return function_node_1.FunctionNode; } });
6
+ Object.defineProperty(exports, "makeNode", { enumerable: true, get: function () { return function_node_1.makeNode; } });
7
+ var interrupt_node_1 = require("./interrupt-node");
8
+ Object.defineProperty(exports, "InterruptNode", { enumerable: true, get: function () { return interrupt_node_1.InterruptNode; } });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/nodes/index.ts"],"names":[],"mappings":";;;AAAA,iDAAyD;AAAhD,6GAAA,YAAY,OAAA;AAAE,yGAAA,QAAQ,OAAA;AAC/B,mDAAiD;AAAxC,+GAAA,aAAa,OAAA"}
@@ -0,0 +1,51 @@
1
+ import { NodeLike } from "./types";
2
+ import { ContextLayer } from "../graphs";
3
+ /**
4
+ * A node that interrupts graph execution and returns control to the caller.
5
+ * Useful for handling user input, human-in-the-loop workflows, or pausing execution.
6
+ *
7
+ * When resumed, the graph will continue from after this node if the resumeFrom
8
+ * cursor indicates this node was the interruption point.
9
+ *
10
+ * @class InterruptNode
11
+ * @template T - The state type
12
+ * @implements {NodeLike<T, Partial<T>>}
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Interrupt for user confirmation
17
+ * const confirmNode = new InterruptNode("Please confirm the action");
18
+ *
19
+ * // Graph execution
20
+ * const result = await graph.invoke(state);
21
+ * if (result.exitReason === "interrupt") {
22
+ * console.log("Paused:", result.exitMessage);
23
+ * // Get user input...
24
+ * // Resume with: await graph.invoke(result.state, { resumeFrom: result.cursor });
25
+ * }
26
+ * ```
27
+ */
28
+ export declare class InterruptNode<T extends Record<string, unknown>> implements NodeLike<T> {
29
+ private readonly message?;
30
+ /**
31
+ * Creates an interrupt node.
32
+ *
33
+ * @param {string} [message] - Optional message to send when interrupting
34
+ */
35
+ constructor(message?: string | undefined);
36
+ /**
37
+ * Executes the interrupt.
38
+ * If resuming from a previous interrupt, marks the execution as resumed.
39
+ * Otherwise, marks the runtime as interrupted with an optional message.
40
+ *
41
+ * @param {T} state - The current state (unchanged by this node)
42
+ * @param {ContextLayer} context - The execution context
43
+ * @returns {Promise<Partial<T>>} Empty partial state (this node doesn't modify state)
44
+ *
45
+ * @remarks
46
+ * This node returns an empty object as it doesn't modify state.
47
+ * The actual interruption is signaled through the RuntimeContext.
48
+ */
49
+ run(state: T, context: ContextLayer): Promise<Partial<T>>;
50
+ }
51
+ //# sourceMappingURL=interrupt-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interrupt-node.d.ts","sourceRoot":"","sources":["../../src/nodes/interrupt-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IAMpE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IALrC;;;;OAIG;gBAC0B,OAAO,CAAC,EAAE,MAAM,YAAA;IAE7C;;;;;;;;;;;;OAYG;IACG,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAUlE"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InterruptNode = void 0;
4
+ /**
5
+ * A node that interrupts graph execution and returns control to the caller.
6
+ * Useful for handling user input, human-in-the-loop workflows, or pausing execution.
7
+ *
8
+ * When resumed, the graph will continue from after this node if the resumeFrom
9
+ * cursor indicates this node was the interruption point.
10
+ *
11
+ * @class InterruptNode
12
+ * @template T - The state type
13
+ * @implements {NodeLike<T, Partial<T>>}
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Interrupt for user confirmation
18
+ * const confirmNode = new InterruptNode("Please confirm the action");
19
+ *
20
+ * // Graph execution
21
+ * const result = await graph.invoke(state);
22
+ * if (result.exitReason === "interrupt") {
23
+ * console.log("Paused:", result.exitMessage);
24
+ * // Get user input...
25
+ * // Resume with: await graph.invoke(result.state, { resumeFrom: result.cursor });
26
+ * }
27
+ * ```
28
+ */
29
+ class InterruptNode {
30
+ message;
31
+ /**
32
+ * Creates an interrupt node.
33
+ *
34
+ * @param {string} [message] - Optional message to send when interrupting
35
+ */
36
+ constructor(message) {
37
+ this.message = message;
38
+ }
39
+ /**
40
+ * Executes the interrupt.
41
+ * If resuming from a previous interrupt, marks the execution as resumed.
42
+ * Otherwise, marks the runtime as interrupted with an optional message.
43
+ *
44
+ * @param {T} state - The current state (unchanged by this node)
45
+ * @param {ContextLayer} context - The execution context
46
+ * @returns {Promise<Partial<T>>} Empty partial state (this node doesn't modify state)
47
+ *
48
+ * @remarks
49
+ * This node returns an empty object as it doesn't modify state.
50
+ * The actual interruption is signaled through the RuntimeContext.
51
+ */
52
+ async run(state, context) {
53
+ // InterruptNode assumes that if a resumeFrom is provided, it's because this node originally called it.
54
+ // In that case, we don't need to interrupt the state machine at this spot again.
55
+ if (context.runtime.resuming) {
56
+ context.runtime.markResumed();
57
+ }
58
+ else {
59
+ context.runtime.markInterrupted(this.message);
60
+ }
61
+ return {};
62
+ }
63
+ }
64
+ exports.InterruptNode = InterruptNode;
65
+ //# sourceMappingURL=interrupt-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interrupt-node.js","sourceRoot":"","sources":["../../src/nodes/interrupt-node.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,aAAa;IAMO;IAL7B;;;;OAIG;IACH,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAI,CAAC;IAElD;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,GAAG,CAAC,KAAQ,EAAE,OAAqB;QACrC,uGAAuG;QACvG,iFAAiF;QACjF,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC3B,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAClC,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AA/BD,sCA+BC"}
@@ -0,0 +1,72 @@
1
+ import { ModelMessages } from "../messages";
2
+ import { BaseModel, StructuredOutputWrapper } from "../models/BaseModel";
3
+ import { NodeLike } from "./types";
4
+ import { ContextLayer } from "../graphs/runtime-context";
5
+ import { TypedKeys } from "../types";
6
+ /**
7
+ * Helper type to extract keys from an object that have ModelMessages[] values.
8
+ */
9
+ type MessagesKeys<T> = TypedKeys<T, ModelMessages[]>;
10
+ /**
11
+ * Configuration for messages provided through a function.
12
+ */
13
+ interface ConstructedMessages<T extends Record<string, unknown>> {
14
+ messages: (state: T, context: ContextLayer) => ModelMessages[];
15
+ }
16
+ /**
17
+ * Configuration for messages provided through a state path.
18
+ */
19
+ interface MessagesPath<T> {
20
+ messages: MessagesKeys<T>;
21
+ }
22
+ /**
23
+ * Settings for a ModelNode specifying where to get messages and where to store output.
24
+ */
25
+ type ModelNodeSettings<T extends Record<string, unknown>> = {
26
+ output: keyof T;
27
+ } & (ConstructedMessages<T> | MessagesPath<T>);
28
+ /**
29
+ * A node that invokes an AI model and stores the response in the state.
30
+ * Can be configured to either construct messages dynamically or read from state.
31
+ *
32
+ * @class ModelNode
33
+ * @template T - The state type
34
+ * @implements {NodeLike<T, Partial<T>>}
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // With messages from a function
39
+ * const node = new ModelNode(model, {
40
+ * messages: (state, context) => [new UserMessage(state.input)],
41
+ * output: "modelResponse"
42
+ * });
43
+ *
44
+ * // With messages from state
45
+ * const node = new ModelNode(model, {
46
+ * messages: "conversationMessages",
47
+ * output: "modelResponse"
48
+ * });
49
+ * ```
50
+ */
51
+ export declare class ModelNode<T extends Record<string, unknown>> implements NodeLike<T> {
52
+ private readonly model;
53
+ private readonly settings;
54
+ /**
55
+ * Creates a new model node.
56
+ *
57
+ * @param {BaseModel | StructuredOutputWrapper<any>} model - The model to invoke
58
+ * @param {ModelNodeSettings<T>} settings - Configuration for message source and output location
59
+ */
60
+ constructor(model: BaseModel | StructuredOutputWrapper<any>, settings: ModelNodeSettings<T>);
61
+ /**
62
+ * Runs the model with configured messages and stores the response in state.
63
+ *
64
+ * @param {T} state - The current state
65
+ * @param {ContextLayer} context - The execution context
66
+ * @returns {Promise<Partial<T>>} Partial state containing the model's response
67
+ * @throws {Error} If messages path is specified but not found in state
68
+ */
69
+ run(state: T, context: ContextLayer): Promise<Partial<T>>;
70
+ }
71
+ export {};
72
+ //# sourceMappingURL=model-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-node.d.ts","sourceRoot":"","sources":["../../src/nodes/model-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAcrC;;GAEG;AACH,KAAK,YAAY,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC;AAErD;;GAEG;AACH,UAAU,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,KAAK,aAAa,EAAE,CAAC;CAClE;AAED;;GAEG;AACH,UAAU,YAAY,CAAC,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACpD;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACjB,CAAC,mBAAmB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,YAAW,QAAQ,CAAC,CAAC,CAAC;IAQxE,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAR7B;;;;;OAKG;gBAEkB,KAAK,EAAE,SAAS,GAAG,uBAAuB,CAAC,GAAG,CAAC,EAC/C,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAGnD;;;;;;;OAOG;IACG,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAkBlE"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModelNode = void 0;
4
+ const BaseModel_1 = require("../models/BaseModel");
5
+ /**
6
+ * Type guard to check if a value is a function that returns messages.
7
+ *
8
+ * @private
9
+ * @param {any} value - Value to check
10
+ * @returns {boolean} True if value is a messages-returning function
11
+ */
12
+ function isMessagesFunction(value) {
13
+ return typeof value === "function";
14
+ }
15
+ /**
16
+ * A node that invokes an AI model and stores the response in the state.
17
+ * Can be configured to either construct messages dynamically or read from state.
18
+ *
19
+ * @class ModelNode
20
+ * @template T - The state type
21
+ * @implements {NodeLike<T, Partial<T>>}
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // With messages from a function
26
+ * const node = new ModelNode(model, {
27
+ * messages: (state, context) => [new UserMessage(state.input)],
28
+ * output: "modelResponse"
29
+ * });
30
+ *
31
+ * // With messages from state
32
+ * const node = new ModelNode(model, {
33
+ * messages: "conversationMessages",
34
+ * output: "modelResponse"
35
+ * });
36
+ * ```
37
+ */
38
+ class ModelNode {
39
+ model;
40
+ settings;
41
+ /**
42
+ * Creates a new model node.
43
+ *
44
+ * @param {BaseModel | StructuredOutputWrapper<any>} model - The model to invoke
45
+ * @param {ModelNodeSettings<T>} settings - Configuration for message source and output location
46
+ */
47
+ constructor(model, settings) {
48
+ this.model = model;
49
+ this.settings = settings;
50
+ }
51
+ /**
52
+ * Runs the model with configured messages and stores the response in state.
53
+ *
54
+ * @param {T} state - The current state
55
+ * @param {ContextLayer} context - The execution context
56
+ * @returns {Promise<Partial<T>>} Partial state containing the model's response
57
+ * @throws {Error} If messages path is specified but not found in state
58
+ */
59
+ async run(state, context) {
60
+ let messages = [];
61
+ if (isMessagesFunction(this.settings.messages)) {
62
+ messages = this.settings.messages(state, context);
63
+ }
64
+ else {
65
+ const stateMessages = state[this.settings.messages];
66
+ if (!stateMessages || !Array.isArray(stateMessages)) {
67
+ throw new Error(`No Messages array found for key ${this.settings.messages}`);
68
+ }
69
+ messages = stateMessages;
70
+ }
71
+ if (this.model instanceof BaseModel_1.StructuredOutputWrapper) {
72
+ const output = await this.model.invoke(messages);
73
+ return { [this.settings.output]: output };
74
+ }
75
+ const response = await this.model.invoke(messages);
76
+ return { [this.settings.output]: response.messages };
77
+ }
78
+ }
79
+ exports.ModelNode = ModelNode;
80
+ //# sourceMappingURL=model-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-node.js","sourceRoot":"","sources":["../../src/nodes/model-node.ts"],"names":[],"mappings":";;;AACA,mDAAyE;AAMzE;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAoC,KAAU;IACrE,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACvC,CAAC;AA4BD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,SAAS;IAQG;IACA;IARrB;;;;;OAKG;IACH,YACqB,KAA+C,EAC/C,QAA8B;QAD9B,UAAK,GAAL,KAAK,CAA0C;QAC/C,aAAQ,GAAR,QAAQ,CAAsB;IAC/C,CAAC;IAEL;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,KAAQ,EAAE,OAAqB;QACrC,IAAI,QAAQ,GAAoB,EAAE,CAAC;QACnC,IAAI,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7C,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;aAAM,CAAC;YACJ,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAmB,CAAC,CAAC;YAC/D,IAAI,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;gBAClD,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,CAAC,QAAQ,CAAC,QAAkB,EAAE,CAAC,CAAC;YAC3F,CAAC;YACD,QAAQ,GAAG,aAAgC,CAAC;QAChD,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,YAAY,mCAAuB,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACjD,OAAO,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAgB,CAAC;QAC5D,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACnD,OAAO,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,QAAQ,EAAgB,CAAC;IACvE,CAAC;CACJ;AAtCD,8BAsCC"}
@@ -0,0 +1,5 @@
1
+ import { ContextLayer } from "../graphs/runtime-context";
2
+ export interface NodeLike<I extends Record<string, unknown>, O extends Record<string, unknown> = Partial<I>> {
3
+ run(state: I, context: ContextLayer): Promise<O>;
4
+ }
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/nodes/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,WAAW,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IACvG,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACpD"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/nodes/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,65 @@
1
+ import * as z from "zod";
2
+ /**
3
+ * Defines the structure for a tool that can be used by AI models.
4
+ *
5
+ * @template T - The input type for the tool, validated against the schema
6
+ * @property {string} name - Unique identifier for the tool
7
+ * @property {string} [description] - Human-readable description of what the tool does
8
+ * @property {z.ZodSchema<T>} schema - Zod schema that validates the tool's input parameters
9
+ */
10
+ export interface ToolDefinition<T = object> {
11
+ name: string;
12
+ description?: string;
13
+ schema: z.ZodSchema<T>;
14
+ }
15
+ /**
16
+ * Creates a tool definition with validation schema.
17
+ * Used to declare what tools are available to AI models.
18
+ *
19
+ * @template T - The input parameter type
20
+ * @param {string} name - Unique identifier for the tool
21
+ * @param {string} description - Description of the tool's purpose and behavior
22
+ * @param {z.ZodSchema<T>} schema - Zod schema for validating input parameters
23
+ * @returns {ToolDefinition<T>} A tool definition object
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const searchTool = defineTool(
28
+ * "search",
29
+ * "Search the web for information",
30
+ * z.object({ query: z.string() })
31
+ * );
32
+ * ```
33
+ */
34
+ export declare function defineTool<T>(name: string, description: string, schema: z.ZodSchema<T>): ToolDefinition<T>;
35
+ /**
36
+ * Internal interface extending ToolDefinition with the actual implementation function.
37
+ *
38
+ * @template T - The input type for the tool
39
+ * @template K - The output type returned by the tool function
40
+ */
41
+ interface ToolImplementation<T, K> extends ToolDefinition<T> {
42
+ func: (input: T) => K | Promise<K>;
43
+ }
44
+ /**
45
+ * Creates a complete tool implementation by combining a tool definition with its function.
46
+ *
47
+ * @template T - The input parameter type
48
+ * @template K - The return type of the tool function
49
+ * @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
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const searchTool = tool(
56
+ * defineTool("search", "Search the web", z.object({ query: z.string() })),
57
+ * async (input) => {
58
+ * return await fetch(`https://api.search.com?q=${input.query}`);
59
+ * }
60
+ * );
61
+ * ```
62
+ */
63
+ export declare function tool<T, K>(toolDefinition: ToolDefinition<T>, func: (input: T) => K | Promise<K>): ToolImplementation<T, K>;
64
+ export {};
65
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +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,MAAM;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAMnB;AAED;;;;;GAKG;AACH,UAAU,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IACxD,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EACrB,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC,EACjC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACnC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAK1B"}
package/dist/tools.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineTool = defineTool;
4
+ exports.tool = tool;
5
+ /**
6
+ * Creates a tool definition with validation schema.
7
+ * Used to declare what tools are available to AI models.
8
+ *
9
+ * @template T - The input parameter type
10
+ * @param {string} name - Unique identifier for the tool
11
+ * @param {string} description - Description of the tool's purpose and behavior
12
+ * @param {z.ZodSchema<T>} schema - Zod schema for validating input parameters
13
+ * @returns {ToolDefinition<T>} A tool definition object
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const searchTool = defineTool(
18
+ * "search",
19
+ * "Search the web for information",
20
+ * z.object({ query: z.string() })
21
+ * );
22
+ * ```
23
+ */
24
+ function defineTool(name, description, schema) {
25
+ return {
26
+ name,
27
+ description,
28
+ schema,
29
+ };
30
+ }
31
+ /**
32
+ * Creates a complete tool implementation by combining a tool definition with its function.
33
+ *
34
+ * @template T - The input parameter type
35
+ * @template K - The return type of the tool function
36
+ * @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
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const searchTool = tool(
43
+ * defineTool("search", "Search the web", z.object({ query: z.string() })),
44
+ * async (input) => {
45
+ * return await fetch(`https://api.search.com?q=${input.query}`);
46
+ * }
47
+ * );
48
+ * ```
49
+ */
50
+ function tool(toolDefinition, func) {
51
+ return {
52
+ ...toolDefinition,
53
+ func,
54
+ };
55
+ }
56
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":";;AAmCA,gCAUC;AA+BD,oBAQC;AApED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,UAAU,CACtB,IAAY,EACZ,WAAmB,EACnB,MAAsB;IAEtB,OAAO;QACH,IAAI;QACJ,WAAW;QACX,MAAM;KACT,CAAC;AACN,CAAC;AAYD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,IAAI,CAChB,cAAiC,EACjC,IAAkC;IAElC,OAAO;QACH,GAAG,cAAc;QACjB,IAAI;KACP,CAAC;AACN,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Utility type that extracts keys from an object where the value matches a specific type.
3
+ *
4
+ * @template O - The object type to extract keys from
5
+ * @template T - The type to match against object values
6
+ * @returns A union of keys from O where the value type extends T
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * type Obj = { a: string; b: number; c: string };
11
+ * type StringKeys = TypedKeys<Obj, string>; // 'a' | 'c'
12
+ * ```
13
+ */
14
+ export type TypedKeys<O, T> = {
15
+ [K in keyof O]: O[K] extends T ? K : never;
16
+ }[keyof O];
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK;CAC7C,CAAC,MAAM,CAAC,CAAC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}