@graph-compose/client 1.0.0 → 1.0.3

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 (49) hide show
  1. package/README.md +949 -476
  2. package/dist/core/adk-helpers.d.ts +94 -0
  3. package/dist/core/adk-helpers.d.ts.map +1 -0
  4. package/dist/core/adk-helpers.js +134 -0
  5. package/dist/core/adk-helpers.js.map +1 -0
  6. package/dist/core/adk-node-builder.d.ts +128 -0
  7. package/dist/core/adk-node-builder.d.ts.map +1 -0
  8. package/dist/core/adk-node-builder.js +175 -0
  9. package/dist/core/adk-node-builder.js.map +1 -0
  10. package/dist/core/adk-workflow-builder.d.ts +74 -0
  11. package/dist/core/adk-workflow-builder.d.ts.map +1 -0
  12. package/dist/core/adk-workflow-builder.js +138 -0
  13. package/dist/core/adk-workflow-builder.js.map +1 -0
  14. package/dist/core/base-builder.d.ts +80 -0
  15. package/dist/core/base-builder.d.ts.map +1 -0
  16. package/dist/core/base-builder.js +63 -0
  17. package/dist/core/base-builder.js.map +1 -0
  18. package/dist/core/builder.d.ts +35 -67
  19. package/dist/core/builder.d.ts.map +1 -1
  20. package/dist/core/builder.js +45 -144
  21. package/dist/core/builder.js.map +1 -1
  22. package/dist/core/node-builder.d.ts +15 -59
  23. package/dist/core/node-builder.d.ts.map +1 -1
  24. package/dist/core/node-builder.js +36 -106
  25. package/dist/core/node-builder.js.map +1 -1
  26. package/dist/index.d.ts +5 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +7 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/types.d.ts +50 -4
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/types.js.map +1 -1
  33. package/dist/validation/adk-validation.d.ts +10 -0
  34. package/dist/validation/adk-validation.d.ts.map +1 -0
  35. package/dist/validation/adk-validation.js +362 -0
  36. package/dist/validation/adk-validation.js.map +1 -0
  37. package/dist/validation/index.d.ts +34 -9
  38. package/dist/validation/index.d.ts.map +1 -1
  39. package/dist/validation/index.js +40 -131
  40. package/dist/validation/index.js.map +1 -1
  41. package/package.json +4 -2
  42. package/dist/core/tool-builder.d.ts +0 -130
  43. package/dist/core/tool-builder.d.ts.map +0 -1
  44. package/dist/core/tool-builder.js +0 -343
  45. package/dist/core/tool-builder.js.map +0 -1
  46. package/dist/node-builder.d.ts +0 -64
  47. package/dist/node-builder.d.ts.map +0 -1
  48. package/dist/node-builder.js +0 -261
  49. package/dist/node-builder.js.map +0 -1
@@ -1,343 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToolBuilder = void 0;
4
- const validation_1 = require("../validation");
5
- const builder_1 = require("./builder");
6
- /**
7
- * Fluent API for configuring individual tools within a GraphCompose workflow.
8
- * Tools can be of type 'http' or 'graph'.
9
- * Chain configuration methods (e.g., `.get()`, `.description()`, `.graph()`).
10
- * Call `.end()` to finalize the tool definition and add it to the graph.
11
- */
12
- class ToolBuilder {
13
- /**
14
- * Creates an instance of ToolBuilder.
15
- * @param parentGraph The parent GraphCompose instance.
16
- * @param id The unique identifier for the tool.
17
- */
18
- constructor(parentGraph, id) {
19
- this.parentGraph = parentGraph;
20
- this.id = id; // Store the ID
21
- this.tool = {
22
- id,
23
- type: "http",
24
- http: {
25
- method: "GET",
26
- url: "",
27
- },
28
- };
29
- }
30
- /**
31
- * Validates a JSONata expression within the context of the current tool.
32
- * @param expression The JSONata expression string to validate.
33
- * @param context A descriptive string indicating where the expression is used.
34
- * @throws {Error} If the expression is invalid.
35
- */
36
- validateJsonataExpression(expression, context) {
37
- try {
38
- const result = (0, validation_1.validateExpression)(expression, this.tool.id);
39
- if (!result.isValid) {
40
- throw result.errors[0];
41
- }
42
- }
43
- catch (e) {
44
- console.error(`Error validating expression for tool ${this.tool.id}:`, e);
45
- throw e;
46
- }
47
- }
48
- /**
49
- * Sets the tool type to 'http' (if not already set) and configures it for a GET request.
50
- * @param url The URL endpoint for the GET request.
51
- * @returns The ToolBuilder instance for chaining.
52
- */
53
- get(url) {
54
- if (this.tool.type !== "http") {
55
- // Explicitly create a new HTTP tool structure
56
- this.tool = {
57
- id: this.tool.id,
58
- description: this.tool.description,
59
- type: "http",
60
- http: { method: "GET", url },
61
- };
62
- }
63
- else {
64
- // Ensure http property exists before assigning
65
- if (!this.tool.http)
66
- this.tool.http = { method: "GET", url };
67
- this.tool.http.method = "GET";
68
- this.tool.http.url = url;
69
- }
70
- return this;
71
- }
72
- /**
73
- * Sets the tool type to 'http' (if not already set) and configures it for a POST request.
74
- * @param url The URL endpoint for the POST request.
75
- * @returns The ToolBuilder instance for chaining.
76
- */
77
- post(url) {
78
- if (this.tool.type !== "http") {
79
- this.tool = {
80
- id: this.tool.id,
81
- description: this.tool.description,
82
- type: "http",
83
- http: { method: "POST", url },
84
- };
85
- }
86
- else {
87
- if (!this.tool.http)
88
- this.tool.http = { method: "POST", url };
89
- this.tool.http.method = "POST";
90
- this.tool.http.url = url;
91
- }
92
- return this;
93
- }
94
- /**
95
- * Sets the tool type to 'http' (if not already set) and configures it for a PUT request.
96
- * @param url The URL endpoint for the PUT request.
97
- * @returns The ToolBuilder instance for chaining.
98
- */
99
- put(url) {
100
- if (this.tool.type !== "http") {
101
- this.tool = {
102
- id: this.tool.id,
103
- description: this.tool.description,
104
- type: "http",
105
- http: { method: "PUT", url },
106
- };
107
- }
108
- else {
109
- if (!this.tool.http)
110
- this.tool.http = { method: "PUT", url };
111
- this.tool.http.method = "PUT";
112
- this.tool.http.url = url;
113
- }
114
- return this;
115
- }
116
- /**
117
- * Sets the tool type to 'http' (if not already set) and configures it for a DELETE request.
118
- * @param url The URL endpoint for the DELETE request.
119
- * @returns The ToolBuilder instance for chaining.
120
- */
121
- delete(url) {
122
- if (this.tool.type !== "http") {
123
- this.tool = {
124
- id: this.tool.id,
125
- description: this.tool.description,
126
- type: "http",
127
- http: { method: "DELETE", url },
128
- };
129
- }
130
- else {
131
- if (!this.tool.http)
132
- this.tool.http = { method: "DELETE", url };
133
- this.tool.http.method = "DELETE";
134
- this.tool.http.url = url;
135
- }
136
- return this;
137
- }
138
- /**
139
- * Sets the tool type to 'http' (if not already set) and configures it for a PATCH request.
140
- * @param url The URL endpoint for the PATCH request.
141
- * @returns The ToolBuilder instance for chaining.
142
- */
143
- patch(url) {
144
- if (this.tool.type !== "http") {
145
- this.tool = {
146
- id: this.tool.id,
147
- description: this.tool.description,
148
- type: "http",
149
- http: { method: "PATCH", url },
150
- };
151
- }
152
- else {
153
- if (!this.tool.http)
154
- this.tool.http = { method: "PATCH", url };
155
- this.tool.http.method = "PATCH";
156
- this.tool.http.url = url;
157
- }
158
- return this;
159
- }
160
- // --- Configuration methods for HTTP Tools ---
161
- /**
162
- * Sets the description for the tool.
163
- * @param description A brief description of what the tool does.
164
- * @returns The ToolBuilder instance for chaining.
165
- */
166
- description(description) {
167
- this.tool.description = description;
168
- return this;
169
- }
170
- /**
171
- * Sets the HTTP headers for the HTTP tool's request.
172
- * Only applicable if the tool type is 'http'.
173
- * @param headers A record of header names to string values or JsonataParam objects.
174
- * @returns The ToolBuilder instance for chaining.
175
- * @throws {Error} If the tool type is not 'http'.
176
- * @throws {Error} If any JSONata expression within headers is invalid.
177
- */
178
- withHeaders(headers) {
179
- if (this.tool.type !== "http") {
180
- throw new Error("Cannot set headers on a non-HTTP tool.");
181
- }
182
- // Ensure http property exists
183
- if (!this.tool.http)
184
- this.tool.http = { method: "GET", url: "" }; // Should have URL by now ideally
185
- Object.entries(headers).forEach(([key, value]) => {
186
- if (typeof value === "object" && "jsonataExpression" in value) {
187
- this.validateJsonataExpression(value.jsonataExpression, `header '${key}'`);
188
- }
189
- });
190
- this.tool.http.headers = headers;
191
- return this;
192
- }
193
- /**
194
- * Sets the body for the HTTP tool's request.
195
- * Only applicable if the tool type is 'http'.
196
- * @param body The request body as an object or string.
197
- * @returns The ToolBuilder instance for chaining.
198
- * @throws {Error} If the tool type is not 'http'.
199
- */
200
- withBody(body) {
201
- if (this.tool.type !== "http") {
202
- throw new Error("Cannot set body on a non-HTTP tool.");
203
- }
204
- if (!this.tool.http)
205
- this.tool.http = { method: "GET", url: "" };
206
- this.tool.http.body = body;
207
- return this;
208
- }
209
- /**
210
- * Configures the retry policy for the HTTP tool's request.
211
- * Only applicable if the tool type is 'http'.
212
- * @param config Partial configuration for the RetryPolicy.
213
- * @returns The ToolBuilder instance for chaining.
214
- * @throws {Error} If the tool type is not 'http'.
215
- */
216
- withRetries(config) {
217
- if (this.tool.type !== "http") {
218
- throw new Error("Cannot set retry policy on a non-HTTP tool.");
219
- }
220
- if (!this.tool.http)
221
- this.tool.http = { method: "GET", url: "" };
222
- // Ensure activityConfig exists
223
- if (!this.tool.activityConfig) {
224
- this.tool.activityConfig = {};
225
- }
226
- this.tool.activityConfig.retryPolicy = {
227
- ...this.tool.activityConfig.retryPolicy,
228
- ...config,
229
- };
230
- return this;
231
- }
232
- /**
233
- * Sets the start-to-close timeout for the HTTP tool's activity execution.
234
- * @param duration The timeout duration (e.g., '30s', 5000).
235
- * @returns The ToolBuilder instance for chaining.
236
- * @throws {Error} If the tool type is not 'http'.
237
- */
238
- withStartToCloseTimeout(duration) {
239
- if (this.tool.type !== "http") {
240
- throw new Error("Cannot set startToCloseTimeout on a non-HTTP tool.");
241
- }
242
- if (!this.tool.http)
243
- this.tool.http = { method: "GET", url: "" };
244
- if (!this.tool.activityConfig) {
245
- this.tool.activityConfig = {};
246
- }
247
- this.tool.activityConfig.startToCloseTimeout = duration;
248
- return this;
249
- }
250
- /**
251
- * Sets the schedule-to-close timeout for the HTTP tool's activity execution.
252
- * @param duration The timeout duration (e.g., '30s', 5000).
253
- * @returns The ToolBuilder instance for chaining.
254
- * @throws {Error} If the tool type is not 'http'.
255
- */
256
- withScheduleToCloseTimeout(duration) {
257
- if (this.tool.type !== "http") {
258
- throw new Error("Cannot set scheduleToCloseTimeout on a non-HTTP tool.");
259
- }
260
- if (!this.tool.http)
261
- this.tool.http = { method: "GET", url: "" };
262
- if (!this.tool.activityConfig) {
263
- this.tool.activityConfig = {};
264
- }
265
- this.tool.activityConfig.scheduleToCloseTimeout = duration;
266
- return this;
267
- }
268
- // --- Configuration method for Graph Tools ---
269
- /**
270
- * Configures the tool as a 'graph' type using a nested builder.
271
- * @param builderCallback A function that receives a new GraphCompose instance to define the sub-graph.
272
- * @returns The ToolBuilder instance for chaining.
273
- */
274
- graph(builderCallback) {
275
- const subGraphBuilder = new builder_1.GraphCompose({ token: "subgraph-internal" });
276
- builderCallback(subGraphBuilder);
277
- const subGraphDefinition = subGraphBuilder.getWorkflow();
278
- // --- START VALIDATION ---
279
- const invalidNodes = subGraphDefinition.nodes.filter((node) => node.type !== "http");
280
- if (invalidNodes.length > 0) {
281
- const invalidIds = invalidNodes.map((n) => n.id);
282
- throw new Error(`Graph tool '${this.tool.id}' can only contain HTTP nodes. Found invalid node types for IDs: ${invalidIds.join(", ")}`);
283
- }
284
- // --- END VALIDATION ---
285
- if (subGraphDefinition.tools && subGraphDefinition.tools.length > 0) {
286
- console.warn(`Tool '${this.tool.id}': Graph tools currently do not support nested tools. Inner tools will be ignored.`);
287
- }
288
- this.tool = {
289
- id: this.tool.id,
290
- type: "graph",
291
- description: this.tool.description,
292
- graph: {
293
- nodes: subGraphDefinition.nodes,
294
- },
295
- }; // Assert final assignment conforms to ToolNode
296
- delete this.tool.http;
297
- return this;
298
- }
299
- // --- Finalization ---
300
- /**
301
- * Finalizes the configuration of this tool and returns control to the parent GraphCompose builder.
302
- * Adds the configured tool to the main graph's tool list.
303
- * This method MUST be called to complete the tool definition.
304
- *
305
- * @returns The parent GraphCompose instance, allowing for further chaining on the main graph.
306
- */
307
- end() {
308
- // Basic validation before adding
309
- if (this.tool.type === "http" && !this.tool.http?.url) {
310
- throw new Error(`HTTP tool '${this.tool.id}' must have a URL defined.`);
311
- }
312
- if (this.tool.type === "graph" && (!this.tool.graph || this.tool.graph.nodes.length === 0)) {
313
- throw new Error(`Graph tool '${this.tool.id}' must have at least one node defined in its graph.`);
314
- }
315
- this.parentGraph._addToolDefinition(this.build());
316
- return this.parentGraph;
317
- }
318
- /**
319
- * Builds and returns the configured tool node definition.
320
- * Primarily used internally by the end() method.
321
- * @returns The configured ToolNode object.
322
- */
323
- build() {
324
- // Remove empty activityConfig if no activity settings were provided for HTTP tools
325
- if (this.tool.type === "http" &&
326
- this.tool.activityConfig &&
327
- Object.keys(this.tool.activityConfig).length === 0) {
328
- delete this.tool.activityConfig;
329
- }
330
- return this.tool;
331
- }
332
- /**
333
- * @internal
334
- * Retrieves the ID of the tool being built.
335
- * Used for generating informative error messages.
336
- * @returns The ID of the tool.
337
- */
338
- getId() {
339
- return this.id;
340
- }
341
- }
342
- exports.ToolBuilder = ToolBuilder;
343
- //# sourceMappingURL=tool-builder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-builder.js","sourceRoot":"","sources":["../../src/core/tool-builder.ts"],"names":[],"mappings":";;;AAMA,8CAAmD;AACnD,uCAAyC;AAEzC;;;;;GAKG;AACH,MAAa,WAAW;IAKtB;;;;OAIG;IACH,YACmB,WAAyB,EAC1C,EAAU;QADO,gBAAW,GAAX,WAAW,CAAc;QAG1C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,eAAe;QAC7B,IAAI,CAAC,IAAI,GAAG;YACV,EAAE;YACF,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE;gBACJ,MAAM,EAAE,KAAK;gBACb,GAAG,EAAE,EAAE;aACR;SACF,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACK,yBAAyB,CAAC,UAAkB,EAAE,OAAe;QACnE,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAA,+BAAkB,EAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC5D,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,E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AC,IAAI,KAAK,MAAM;YACzB,IAAI,CAAC,IAAI,CAAC,cAAc;YACxB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,KAAK,CAAC,EAClD,CAAC;YACD,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;QAClC,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC;CACF;AAlWD,kCAkWC"}
@@ -1,64 +0,0 @@
1
- import { AgentNode, ErrorBoundaryNode, FlowControl, HttpNode, JsonataParam, Node, NodeConditions, RetryPolicy } from "@graph-compose/core";
2
- import { z } from "zod";
3
- import { GraphCompose } from "./core/builder";
4
- export declare class NodeBuilder {
5
- private readonly graph;
6
- protected node: HttpNode | ErrorBoundaryNode | AgentNode;
7
- private isHttpNode;
8
- private isAgentNode;
9
- constructor(graph: GraphCompose, id: string, type?: "http" | "error_boundary" | "agent", protectedNodes?: string[]);
10
- private validateJsonataExpression;
11
- get(url: string): NodeBuilder;
12
- post(url: string): NodeBuilder;
13
- put(url: string): NodeBuilder;
14
- delete(url: string): NodeBuilder;
15
- patch(url: string): NodeBuilder;
16
- withCondition(behavior: NodeConditions): NodeBuilder;
17
- withFlowControl(flowControls: FlowControl[]): NodeBuilder;
18
- addFlowControl(flowControl: FlowControl): NodeBuilder;
19
- withHeaders(headers: Record<string, string | JsonataParam>): NodeBuilder;
20
- withBody(body: Record<string, any> | string): NodeBuilder;
21
- withRetries(config: Partial<RetryPolicy>): NodeBuilder;
22
- withTimeout(duration: string | number): NodeBuilder;
23
- withDependencies(nodeIds: string[]): NodeBuilder;
24
- withValidation(config: {
25
- input?: z.ZodType<any> | Record<string, any>;
26
- output?: z.ZodType<any> | Record<string, any>;
27
- }): NodeBuilder;
28
- private isZodType;
29
- /**
30
- * Set the maximum number of iterations for an agent node.
31
- * An agent runs until it returns a completion schema response.
32
- * You are responsible for ensuring the agent returns a `complete` response before this limit.
33
- * If the agent reaches the max iterations without completing, it will fail.
34
- *
35
- * @default 5
36
- * @param maxIterations Must be greater than 0
37
- * @throws {Error} If called on a non-agent node
38
- * @throws {ValidationError} If maxIterations is less than 1
39
- */
40
- withMaxIterations(maxIterations: number): NodeBuilder;
41
- /**
42
- * Set the tools available to the agent.
43
- * Tools must be defined in the global tools section of the workflow.
44
- * Each tool name must be unique within the workflow and have no dashes or spaces.
45
- *
46
- * @param tools Array of tool names that the agent can use
47
- * @throws {Error} If called on a non-agent node
48
- * @throws {ValidationError} If any tool is not found in global tools
49
- */
50
- withTools(tools: string[]): NodeBuilder;
51
- /**
52
- * Add a single tool to the agent's available tools.
53
- * The tool must be defined in the global tools section of the workflow.
54
- * The tool name must be unique within the workflow and have no dashes or spaces.
55
- *
56
- * @param tool Name of the tool to add
57
- * @throws {Error} If called on a non-agent node
58
- * @throws {ValidationError} If the tool is not found in global tools
59
- */
60
- addTool(tool: string): NodeBuilder;
61
- end(): GraphCompose;
62
- build(): Node;
63
- }
64
- //# sourceMappingURL=node-builder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-builder.d.ts","sourceRoot":"","sources":["../src/node-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBAAa,WAAW;IAMpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IALxB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,iBAAiB,GAAG,SAAS,CAAC;IACzD,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,WAAW,CAAU;gBAGV,K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;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW;IASrD;;;;;;;;OAQG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW;IASvC;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAYlC,GAAG,IAAI,YAAY;IAKnB,KAAK,IAAI,IAAI;CAGd"}
@@ -1,261 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NodeBuilder = void 0;
7
- const jsonata_1 = __importDefault(require("jsonata"));
8
- const zod_1 = require("zod");
9
- const zod_to_json_schema_1 = require("zod-to-json-schema");
10
- class NodeBuilder {
11
- constructor(graph, id, type = "http", protectedNodes) {
12
- this.graph = graph;
13
- this.isHttpNode = type === "http";
14
- this.isAgentNode = type === "agent";
15
- if (type === "error_boundary") {
16
- this.node = {
17
- id,
18
- type: "error_boundary",
19
- protectedNodes: protectedNodes || [],
20
- http: {
21
- method: "POST",
22
- url: "",
23
- },
24
- };
25
- }
26
- else if (type === "agent") {
27
- this.node = {
28
- id,
29
- type: "agent",
30
- dependencies: [],
31
- tools: [],
32
- http: {
33
- method: "POST",
34
- url: "",
35
- config: {
36
- max_iterations: undefined,
37
- },
38
- },
39
- };
40
- }
41
- else {
42
- this.node = {
43
- id,
44
- type: "http",
45
- dependencies: [],
46
- http: {
47
- method: "GET",
48
- url: "",
49
- },
50
- };
51
- }
52
- }
53
- validateJsonataExpression(expression, context) {
54
- try {
55
- console.log("validating", expression);
56
- // Try to parse the JSONata expression
57
- (0, jsonata_1.default)(expression);
58
- }
59
- catch (e) {
60
- console.log("error", e);
61
- throw new Error(`Invalid JSONata expression in ${context}: ${e instanceof Error ? e.message : "Unknown error"}`);
62
- }
63
- }
64
- // Update HTTP methods to validate URLs
65
- get(url) {
66
- this.node.http.method = "GET";
67
- this.node.http.url = url;
68
- return this;
69
- }
70
- post(url) {
71
- this.node.http.method = "POST";
72
- this.node.http.url = url;
73
- return this;
74
- }
75
- put(url) {
76
- this.node.http.method = "PUT";
77
- this.node.http.url = url;
78
- return this;
79
- }
80
- delete(url) {
81
- this.node.http.method = "DELETE";
82
- this.node.http.url = url;
83
- return this;
84
- }
85
- patch(url) {
86
- this.node.http.method = "PATCH";
87
- this.node.http.url = url;
88
- return this;
89
- }
90
- // Conditional branching methods - only available for HTTP nodes
91
- withCondition(behavior) {
92
- if (!this.isHttpNode) {
93
- throw new Error("Conditional branching is only available for HTTP nodes");
94
- }
95
- const httpNode = this.node;
96
- httpNode.conditions = behavior;
97
- return this;
98
- }
99
- withFlowControl(flowControls) {
100
- if (!this.isHttpNode) {
101
- throw new Error("Conditional branching is only available for HTTP nodes");
102
- }
103
- const httpNode = this.node;
104
- if (!httpNode.conditions) {
105
- httpNode.conditions = { flowControl: [] };
106
- }
107
- httpNode.conditions.flowControl = flowControls;
108
- return this;
109
- }
110
- addFlowControl(flowControl) {
111
- if (!this.isHttpNode) {
112
- throw new Error("Conditional branching is only available for HTTP nodes");
113
- }
114
- const httpNode = this.node;
115
- if (!httpNode.conditions) {
116
- httpNode.conditions = { flowControl: [] };
117
- }
118
- if (!httpNode.conditions.flowControl) {
119
- httpNode.conditions.flowControl = [];
120
- }
121
- httpNode.conditions.flowControl.push(flowControl);
122
- return this;
123
- }
124
- // Configuration methods
125
- withHeaders(headers) {
126
- // Validate any JSONata expressions in headers
127
- Object.entries(headers).forEach(([key, value]) => {
128
- if (typeof value === "object" && "jsonataExpression" in value) {
129
- this.validateJsonataExpression(value.jsonataExpression, `header '${key}'`);
130
- }
131
- });
132
- this.node.http.headers = headers;
133
- return this;
134
- }
135
- withBody(body) {
136
- // Note: Template expression validation happens during final workflow validation
137
- // This allows us to collect all validation errors at once and maintain a single source of truth
138
- if (typeof body === "string") {
139
- this.node.http.body = body;
140
- }
141
- else {
142
- this.node.http.body = body;
143
- }
144
- return this;
145
- }
146
- withRetries(config) {
147
- this.node.http.retryPolicy = {
148
- ...this.node.http.retryPolicy,
149
- ...config,
150
- };
151
- return this;
152
- }
153
- withTimeout(duration) {
154
- this.node.http.startToCloseTimeout = duration;
155
- return this;
156
- }
157
- withDependencies(nodeIds) {
158
- if (this.isHttpNode) {
159
- this.node.dependencies = nodeIds;
160
- }
161
- else if (this.isAgentNode) {
162
- this.node.dependencies = nodeIds;
163
- }
164
- else {
165
- throw new Error("Dependencies can only be set on HTTP or agent nodes");
166
- }
167
- return this;
168
- }
169
- withValidation(config) {
170
- if (!this.isHttpNode) {
171
- throw new Error("Validation can only be set on HTTP nodes");
172
- }
173
- if (config.input || config.output) {
174
- this.node.validation = {};
175
- if (config.input) {
176
- const inputSchema = this.isZodType(config.input)
177
- ? (0, zod_to_json_schema_1.zodToJsonSchema)(config.input)
178
- : config.input;
179
- this.node.validation.input =
180
- inputSchema.definitions?.[Object.keys(inputSchema.definitions || {})[0]] || inputSchema;
181
- }
182
- if (config.output) {
183
- const outputSchema = this.isZodType(config.output)
184
- ? (0, zod_to_json_schema_1.zodToJsonSchema)(config.output)
185
- : config.output;
186
- this.node.validation.output =
187
- outputSchema.definitions?.[Object.keys(outputSchema.definitions || {})[0]] ||
188
- outputSchema;
189
- }
190
- }
191
- return this;
192
- }
193
- isZodType(value) {
194
- return value instanceof zod_1.z.ZodType;
195
- }
196
- /**
197
- * Set the maximum number of iterations for an agent node.
198
- * An agent runs until it returns a completion schema response.
199
- * You are responsible for ensuring the agent returns a `complete` response before this limit.
200
- * If the agent reaches the max iterations without completing, it will fail.
201
- *
202
- * @default 5
203
- * @param maxIterations Must be greater than 0
204
- * @throws {Error} If called on a non-agent node
205
- * @throws {ValidationError} If maxIterations is less than 1
206
- */
207
- withMaxIterations(maxIterations) {
208
- if (!this.isAgentNode) {
209
- throw new Error("Max iterations can only be set for agent nodes");
210
- }
211
- const agentNode = this.node;
212
- agentNode.http.config.max_iterations = maxIterations;
213
- return this;
214
- }
215
- /**
216
- * Set the tools available to the agent.
217
- * Tools must be defined in the global tools section of the workflow.
218
- * Each tool name must be unique within the workflow and have no dashes or spaces.
219
- *
220
- * @param tools Array of tool names that the agent can use
221
- * @throws {Error} If called on a non-agent node
222
- * @throws {ValidationError} If any tool is not found in global tools
223
- */
224
- withTools(tools) {
225
- if (!this.isAgentNode) {
226
- throw new Error("Tools can only be set for agent nodes");
227
- }
228
- const agentNode = this.node;
229
- agentNode.tools = tools;
230
- return this;
231
- }
232
- /**
233
- * Add a single tool to the agent's available tools.
234
- * The tool must be defined in the global tools section of the workflow.
235
- * The tool name must be unique within the workflow and have no dashes or spaces.
236
- *
237
- * @param tool Name of the tool to add
238
- * @throws {Error} If called on a non-agent node
239
- * @throws {ValidationError} If the tool is not found in global tools
240
- */
241
- addTool(tool) {
242
- if (!this.isAgentNode) {
243
- throw new Error("Tools can only be added to agent nodes");
244
- }
245
- const agentNode = this.node;
246
- if (!agentNode.tools.includes(tool)) {
247
- agentNode.tools.push(tool);
248
- }
249
- return this;
250
- }
251
- // Terminal operation
252
- end() {
253
- return this.graph;
254
- }
255
- // Internal method to get the built node
256
- build() {
257
- return this.node;
258
- }
259
- }
260
- exports.NodeBuilder = NodeBuilder;
261
- //# sourceMappingURL=node-builder.js.map