@atomoz/workflows-nodes 0.1.15 → 0.1.17

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 (3) hide show
  1. package/dist/index.cjs +2394 -0
  2. package/dist/index.js +2302 -0
  3. package/package.json +8 -6
package/dist/index.cjs ADDED
@@ -0,0 +1,2394 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ AiSupervisorNode: () => AiSupervisorNode,
34
+ AiSupervisorNodeFunction: () => AiSupervisorNodeFunction,
35
+ AiSupervisorNodeSchema: () => AiSupervisorNodeSchema,
36
+ AiToolNode: () => AiToolNode,
37
+ AiToolNodeFunction: () => AiToolNodeFunction,
38
+ AiToolNodeSchema: () => AiToolNodeSchema,
39
+ BodyFieldSchema: () => BodyFieldSchema,
40
+ CustomToolSchema: () => CustomToolSchema,
41
+ HTTP_METHODS: () => HTTP_METHODS,
42
+ HTTP_NODE_TYPES: () => HTTP_NODE_TYPES,
43
+ HeaderSchema: () => HeaderSchema,
44
+ HttpDeleteInputNode: () => HttpDeleteInputNode,
45
+ HttpDeleteInputNodeFunction: () => HttpDeleteInputNodeFunction,
46
+ HttpDeleteInputNodeSchema: () => HttpDeleteInputNodeSchema,
47
+ HttpGetInputNode: () => HttpGetInputNode,
48
+ HttpGetInputNodeFunction: () => HttpGetInputNodeFunction,
49
+ HttpGetInputNodeSchema: () => HttpGetInputNodeSchema,
50
+ HttpPatchInputNode: () => HttpPatchInputNode,
51
+ HttpPatchInputNodeFunction: () => HttpPatchInputNodeFunction,
52
+ HttpPatchInputNodeSchema: () => HttpPatchInputNodeSchema,
53
+ HttpPostInputNode: () => HttpPostInputNode,
54
+ HttpPostInputNodeFunction: () => HttpPostInputNodeFunction,
55
+ HttpPostInputNodeSchema: () => HttpPostInputNodeSchema,
56
+ HttpPutInputNode: () => HttpPutInputNode,
57
+ HttpPutInputNodeFunction: () => HttpPutInputNodeFunction,
58
+ HttpPutInputNodeSchema: () => HttpPutInputNodeSchema,
59
+ IaAgentNode: () => IaAgentNode,
60
+ IaAgentNodeFunction: () => IaAgentNodeFunction,
61
+ IaAgentNodeSchema: () => IaAgentNodeSchema,
62
+ IaMessageNode: () => IaMessageNode,
63
+ IaMessageNodeFunction: () => IaMessageNodeFunction,
64
+ IaMessageNodeSchema: () => IaMessageNodeSchema,
65
+ QueryParamSchema: () => QueryParamSchema,
66
+ RouteSchema: () => RouteSchema,
67
+ WhatsappMessageTriggerNode: () => WhatsappMessageTriggerNode,
68
+ WhatsappSendMessageFunction: () => WhatsappSendMessageFunction,
69
+ WhatsappSendMessageNode: () => WhatsappSendMessageNode,
70
+ WhatsappSendMessageNodeSchema: () => WhatsappSendMessageNodeSchema,
71
+ WhatsappSendTemplateNode: () => WhatsappSendTemplateNode,
72
+ WhatsappSendTemplateNodeSchema: () => WhatsappSendTemplateNodeSchema,
73
+ WhatsappStartChatFunction: () => WhatsappStartChatFunction,
74
+ createMessageTemplate: () => createMessageTemplate,
75
+ extractHttpMethodFromNodeType: () => extractHttpMethodFromNodeType,
76
+ getHttpMethodFromFriendlyId: () => getHttpMethodFromFriendlyId,
77
+ getHttpMethodFromNodeType: () => getHttpMethodFromNodeType,
78
+ getHttpNodeTypeStrings: () => getHttpNodeTypeStrings,
79
+ getHttpNodeTypesArray: () => getHttpNodeTypesArray,
80
+ getHttpNodesTypes: () => getHttpNodesTypes,
81
+ getMessageTemplates: () => getMessageTemplates,
82
+ isAnyHttpInputNode: () => isAnyHttpInputNode,
83
+ isHttpInputFriendlyId: () => isHttpInputFriendlyId,
84
+ isHttpInputNode: () => isHttpInputNode,
85
+ isHttpMethodNode: () => isHttpMethodNode,
86
+ nodeFunctions: () => node_functions_default,
87
+ nodes: () => nodes_default,
88
+ schemas: () => schemas
89
+ });
90
+ module.exports = __toCommonJS(index_exports);
91
+
92
+ // src/nodes/inputs/http/get/data.ts
93
+ var HttpGetInputNode = {
94
+ label: "Http GET Input",
95
+ type: "HttpGetInput",
96
+ category: "input",
97
+ icon: "\u{1F310}",
98
+ description: "Node que representa uma rota GET HTTP e recebe query/path parameters",
99
+ group: "HTTP",
100
+ tags: {
101
+ execution: "sync",
102
+ group: "HTTP"
103
+ },
104
+ fields: [
105
+ {
106
+ id: "route",
107
+ label: "Route",
108
+ type: "route",
109
+ required: true,
110
+ placeholder: "/produtos/{id}"
111
+ },
112
+ {
113
+ id: "queryParams",
114
+ label: "Query Params",
115
+ type: "keyValue",
116
+ required: false,
117
+ handle: {
118
+ type: "output",
119
+ label: "Query Params",
120
+ name: "queryParams",
121
+ fieldType: "keyValue"
122
+ }
123
+ },
124
+ {
125
+ id: "headers",
126
+ label: "Headers",
127
+ type: "keyValue",
128
+ required: false,
129
+ handle: {
130
+ type: "output",
131
+ label: "Headers",
132
+ name: "headers",
133
+ fieldType: "keyValue"
134
+ }
135
+ },
136
+ {
137
+ id: "ip",
138
+ label: "Request IP",
139
+ type: "string",
140
+ required: false,
141
+ typeable: false,
142
+ handle: {
143
+ type: "output",
144
+ label: "IP",
145
+ name: "ip",
146
+ fieldType: "string"
147
+ }
148
+ }
149
+ ]
150
+ };
151
+
152
+ // src/nodes/inputs/http/get/function.ts
153
+ var HttpGetInputNodeFunction = async (params) => {
154
+ const { $field: _$field, $req, $inputs: _$inputs, $vars: _$vars } = params;
155
+ const request = $req || params.request;
156
+ const fieldValues = params.fieldValues || {};
157
+ const { queryParams: configQueryParams, headers: configHeaders } = fieldValues || {};
158
+ const actualData = {
159
+ queryParams: request?.query || {},
160
+ headers: request?.headers || {},
161
+ ip: request?.ip || "127.0.0.1"
162
+ };
163
+ if (configQueryParams) {
164
+ const requiredParams = configQueryParams.filter((p) => p.required);
165
+ const missingParams = requiredParams.filter((p) => !actualData.queryParams[p.key]);
166
+ if (missingParams.length > 0) {
167
+ throw new Error(`Par\xE2metros obrigat\xF3rios ausentes: ${missingParams.map((p) => p.key).join(", ")}`);
168
+ }
169
+ }
170
+ if (configHeaders) {
171
+ const requiredHeaders = configHeaders.filter((h) => h.required);
172
+ const missingHeaders = requiredHeaders.filter((h) => !actualData.headers[h.key.toLowerCase()]);
173
+ if (missingHeaders.length > 0) {
174
+ throw new Error(`Headers obrigat\xF3rios ausentes: ${missingHeaders.map((h) => h.key).join(", ")}`);
175
+ }
176
+ }
177
+ return actualData;
178
+ };
179
+
180
+ // src/nodes/inputs/http/get/schema.ts
181
+ var import_zod2 = require("zod");
182
+
183
+ // src/nodes/inputs/http/schemas.ts
184
+ var import_zod = require("zod");
185
+ var QueryParamSchema = import_zod.z.object({
186
+ key: import_zod.z.string(),
187
+ value: import_zod.z.string().optional(),
188
+ required: import_zod.z.boolean().optional()
189
+ });
190
+ var HeaderSchema = import_zod.z.object({
191
+ key: import_zod.z.string(),
192
+ value: import_zod.z.string().optional(),
193
+ required: import_zod.z.boolean().optional()
194
+ });
195
+ var BodyFieldSchema = import_zod.z.object({
196
+ key: import_zod.z.string(),
197
+ value: import_zod.z.any().optional(),
198
+ required: import_zod.z.boolean().optional()
199
+ });
200
+ var RouteSchema = import_zod.z.string().describe("HTTP route path");
201
+
202
+ // src/nodes/inputs/http/get/schema.ts
203
+ var HttpGetInputNodeSchema = import_zod2.z.object({
204
+ route: RouteSchema,
205
+ queryParams: import_zod2.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
206
+ headers: import_zod2.z.array(HeaderSchema).optional().describe("Headers configuration")
207
+ });
208
+
209
+ // src/nodes/inputs/http/post/data.ts
210
+ var HttpPostInputNode = {
211
+ label: "Http POST Input",
212
+ type: "HttpPostInput",
213
+ category: "input",
214
+ icon: "\u{1F4E4}",
215
+ description: "Node que representa uma rota POST HTTP e recebe dados no body",
216
+ tags: {
217
+ execution: "sync",
218
+ group: "HTTP"
219
+ },
220
+ fields: [
221
+ {
222
+ id: "route",
223
+ label: "Route",
224
+ type: "route",
225
+ required: true,
226
+ placeholder: "/produtos/{id}"
227
+ },
228
+ {
229
+ id: "queryParams",
230
+ label: "Query Params",
231
+ type: "keyValue",
232
+ required: false,
233
+ handle: {
234
+ type: "output",
235
+ label: "Query Params",
236
+ name: "queryParams",
237
+ fieldType: "keyValue"
238
+ }
239
+ },
240
+ {
241
+ id: "headers",
242
+ label: "Headers",
243
+ type: "keyValue",
244
+ required: false,
245
+ handle: {
246
+ type: "output",
247
+ label: "Headers",
248
+ name: "headers",
249
+ fieldType: "keyValue"
250
+ }
251
+ },
252
+ {
253
+ id: "body",
254
+ label: "Body",
255
+ type: "object",
256
+ required: false,
257
+ handle: {
258
+ type: "output",
259
+ label: "Body",
260
+ name: "body",
261
+ fieldType: "object",
262
+ required: false
263
+ }
264
+ },
265
+ {
266
+ id: "ip",
267
+ label: "Request IP",
268
+ type: "string",
269
+ required: false,
270
+ typeable: false,
271
+ handle: {
272
+ type: "output",
273
+ label: "IP",
274
+ name: "ip",
275
+ fieldType: "string"
276
+ }
277
+ }
278
+ ]
279
+ };
280
+
281
+ // src/nodes/inputs/http/post/function.ts
282
+ var HttpPostInputNodeFunction = (params) => {
283
+ const { $field: _$field, $req, $inputs: _$inputs, $vars: _$vars } = params;
284
+ const request = $req || params.request;
285
+ const fieldValues = params.fieldValues || {};
286
+ const { queryParams: configQueryParams, headers: configHeaders, body: configBody } = fieldValues || {};
287
+ if (request.method !== "POST") {
288
+ throw new Error("M\xE9todo HTTP inv\xE1lido");
289
+ }
290
+ const actualData = {
291
+ queryParams: request?.query || {},
292
+ headers: request?.headers || {},
293
+ body: request?.body || {},
294
+ ip: request?.ip || "127.0.0.1"
295
+ };
296
+ if (configQueryParams) {
297
+ const requiredParams = configQueryParams.filter((p) => p.required);
298
+ const missingParams = requiredParams.filter((p) => !actualData.queryParams[p.key]);
299
+ if (missingParams.length > 0) {
300
+ throw new Error(`Par\xE2metros obrigat\xF3rios ausentes: ${missingParams.map((p) => p.key).join(", ")}`);
301
+ }
302
+ }
303
+ if (configHeaders) {
304
+ const requiredHeaders = configHeaders.filter((h) => h.required);
305
+ const missingHeaders = requiredHeaders.filter((h) => !actualData.headers[h.key.toLowerCase()]);
306
+ if (missingHeaders.length > 0) {
307
+ throw new Error(`Headers obrigat\xF3rios ausentes: ${missingHeaders.map((h) => h.key).join(", ")}`);
308
+ }
309
+ }
310
+ if (configBody) {
311
+ const requiredBodyFields = configBody.filter((f) => f.required);
312
+ const missingBodyFields = requiredBodyFields.filter((f) => !actualData.body[f.key]);
313
+ if (missingBodyFields.length > 0) {
314
+ throw new Error(`Campos obrigat\xF3rios do body ausentes: ${missingBodyFields.map((f) => f.key).join(", ")}`);
315
+ }
316
+ }
317
+ return actualData;
318
+ };
319
+
320
+ // src/nodes/inputs/http/post/schema.ts
321
+ var import_zod3 = require("zod");
322
+ var HttpPostInputNodeSchema = import_zod3.z.object({
323
+ route: RouteSchema,
324
+ queryParams: import_zod3.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
325
+ headers: import_zod3.z.array(HeaderSchema).optional().describe("Headers configuration"),
326
+ body: import_zod3.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
327
+ });
328
+
329
+ // src/nodes/inputs/chat/chat.ts
330
+ var ChatInputNodeFunction = (params) => {
331
+ const { $field: _$field, $req, $inputs: _$inputs, $vars: _$vars } = params;
332
+ const request = $req || params.request;
333
+ const fieldValues = params.fieldValues || {};
334
+ const { message: configMessage, chatId: configChatId } = fieldValues || {};
335
+ const actualData = {
336
+ message: request?.message ?? configMessage ?? "",
337
+ chatId: request?.chatId ?? configChatId ?? null
338
+ };
339
+ if (!actualData.message || typeof actualData.message !== "string") {
340
+ throw new Error("Message is required for ChatInputNode");
341
+ }
342
+ return actualData;
343
+ };
344
+ var ChatInputNode = {
345
+ label: "Chat Input",
346
+ type: "ChatInput",
347
+ category: "input",
348
+ icon: "\u{1F4AC}",
349
+ description: "Entrada de mensagem de chat para iniciar conversas com IA",
350
+ tags: {
351
+ execution: "sync",
352
+ group: "IA"
353
+ },
354
+ fields: [
355
+ {
356
+ id: "message",
357
+ label: "Message",
358
+ type: "string",
359
+ required: true,
360
+ typeable: false,
361
+ handle: {
362
+ type: "output",
363
+ label: "Message",
364
+ name: "message",
365
+ fieldType: "string"
366
+ }
367
+ },
368
+ {
369
+ id: "chatId",
370
+ label: "Chat ID",
371
+ type: "string",
372
+ required: true,
373
+ typeable: false,
374
+ handle: {
375
+ type: "output",
376
+ label: "Chat ID",
377
+ name: "chatId",
378
+ fieldType: "string"
379
+ }
380
+ }
381
+ ]
382
+ };
383
+
384
+ // src/nodes/inputs/manual/trigger.ts
385
+ var ManualTriggerNodeFunction = (params) => {
386
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
387
+ const fieldValues = params.fieldValues || {};
388
+ return fieldValues || {};
389
+ };
390
+ var ManualTriggerNode = {
391
+ label: "Manual Trigger",
392
+ type: "ManualTrigger",
393
+ category: "input",
394
+ icon: "\u{1F590}\uFE0F",
395
+ description: "Dispara fluxo manualmente e envia campos din\xE2micos",
396
+ tags: {
397
+ execution: "sync",
398
+ group: "Custom"
399
+ },
400
+ fields: [
401
+ {
402
+ id: "stringExample",
403
+ label: "String Example",
404
+ type: "string",
405
+ handle: { type: "output", label: "String", name: "stringExample", fieldType: "string" },
406
+ placeholder: "Ex.: valor literal"
407
+ },
408
+ {
409
+ id: "numberExample",
410
+ label: "Number Example",
411
+ type: "number",
412
+ handle: { type: "output", label: "Number", name: "numberExample", fieldType: "number" },
413
+ placeholder: "Ex.: 123"
414
+ },
415
+ {
416
+ id: "keyValue1",
417
+ label: "Key/Value 1",
418
+ type: "keyValue",
419
+ handle: { type: "output", label: "Key/Value", name: "keyValue1", fieldType: "keyValue" }
420
+ }
421
+ ]
422
+ };
423
+
424
+ // src/nodes/inputs/cron/trigger.ts
425
+ var CronTriggerNodeFunction = (params) => {
426
+ const { $req } = params;
427
+ const triggerData = $req || {};
428
+ const fieldValues = params.fieldValues || {};
429
+ return {
430
+ triggeredAt: triggerData.triggeredAt || (/* @__PURE__ */ new Date()).toISOString(),
431
+ scheduleId: triggerData.scheduleId || null,
432
+ cronExpression: fieldValues.cronExpression || null,
433
+ timezone: fieldValues.timezone || "America/Sao_Paulo",
434
+ success: true
435
+ };
436
+ };
437
+ var CronTriggerNode = {
438
+ label: "Cron Trigger",
439
+ type: "CronTrigger",
440
+ category: "input",
441
+ icon: "\u23F0",
442
+ description: "Dispara fluxo automaticamente baseado em express\xE3o cron",
443
+ tags: {
444
+ execution: "async",
445
+ group: "Custom"
446
+ },
447
+ fields: [
448
+ {
449
+ id: "cronExpression",
450
+ label: "Express\xE3o Cron",
451
+ type: "string",
452
+ required: true,
453
+ placeholder: "0 9 * * * (todos os dias \xE0s 9h)"
454
+ },
455
+ {
456
+ id: "timezone",
457
+ label: "Timezone",
458
+ type: "select",
459
+ defaultValue: "America/Sao_Paulo",
460
+ options: [
461
+ { label: "S\xE3o Paulo (GMT-3)", value: "America/Sao_Paulo" },
462
+ { label: "UTC", value: "UTC" },
463
+ { label: "New York (GMT-5)", value: "America/New_York" },
464
+ { label: "Los Angeles (GMT-8)", value: "America/Los_Angeles" },
465
+ { label: "London (GMT+0)", value: "Europe/London" }
466
+ ]
467
+ },
468
+ {
469
+ id: "triggeredAt",
470
+ label: "Triggered At",
471
+ type: "string",
472
+ typeable: false,
473
+ handle: {
474
+ type: "output",
475
+ label: "Triggered At",
476
+ name: "triggeredAt",
477
+ fieldType: "string"
478
+ }
479
+ },
480
+ {
481
+ id: "scheduleId",
482
+ label: "Schedule ID",
483
+ type: "string",
484
+ typeable: false,
485
+ handle: {
486
+ type: "output",
487
+ label: "Schedule ID",
488
+ name: "scheduleId",
489
+ fieldType: "string"
490
+ }
491
+ }
492
+ ]
493
+ };
494
+
495
+ // src/nodes/processors/concat.ts
496
+ var import_zod4 = require("zod");
497
+ var ConcatNodeFunction = (params) => {
498
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
499
+ const inputs_resolved = params.inputs || params || {};
500
+ const input1 = inputs_resolved.input1 || "";
501
+ const input2 = inputs_resolved.input2 || "";
502
+ const result = `${input1}${input2}`;
503
+ return {
504
+ output: result,
505
+ function: ConcatNodeFunction,
506
+ type: "ConcatNode"
507
+ };
508
+ };
509
+ var ConcatNodeSchema = import_zod4.z.object({
510
+ input1: import_zod4.z.string(),
511
+ input2: import_zod4.z.string()
512
+ });
513
+ var ConcatNode = {
514
+ label: "Concat Data",
515
+ type: "ConcatNode",
516
+ category: "step",
517
+ icon: "\u{1F504}",
518
+ description: "Node para concatenar dados de entrada",
519
+ toolable: true,
520
+ fields: [
521
+ {
522
+ id: "input1",
523
+ label: "Input 1",
524
+ type: "string",
525
+ required: true,
526
+ typeable: false,
527
+ handle: {
528
+ type: "input",
529
+ label: "Input 1",
530
+ name: "input1",
531
+ fieldType: "string",
532
+ required: true
533
+ }
534
+ },
535
+ {
536
+ id: "input2",
537
+ label: "Input 2",
538
+ type: "string",
539
+ required: true,
540
+ typeable: false,
541
+ handle: {
542
+ type: "input",
543
+ label: "Input 2",
544
+ name: "input2",
545
+ fieldType: "string",
546
+ required: true
547
+ }
548
+ },
549
+ {
550
+ id: "output",
551
+ label: "Output",
552
+ type: "string",
553
+ required: true,
554
+ typeable: false,
555
+ handle: {
556
+ type: "output",
557
+ label: "Output",
558
+ name: "output",
559
+ fieldType: "string",
560
+ required: true
561
+ }
562
+ }
563
+ ]
564
+ };
565
+
566
+ // src/nodes/output-node/index.ts
567
+ var HttpOutputNodeFunction = (params) => {
568
+ const { fieldValues, results } = params;
569
+ let responseData = fieldValues?.data || {};
570
+ if (typeof responseData === "object" && responseData !== null) {
571
+ const processedData = {};
572
+ for (const [key, value] of Object.entries(responseData)) {
573
+ if (typeof value === "string" && value.includes("{{")) {
574
+ processedData[key] = processPlaceholders(value, results);
575
+ } else {
576
+ processedData[key] = value;
577
+ }
578
+ }
579
+ responseData = processedData;
580
+ } else if (typeof responseData === "string") {
581
+ responseData = { value: responseData };
582
+ }
583
+ const status = fieldValues?.status || 200;
584
+ const headers = fieldValues?.headers || {};
585
+ if (status && (status < 100 || status > 599)) {
586
+ throw new Error(`Status HTTP inv\xE1lido: ${status}`);
587
+ }
588
+ return {
589
+ status,
590
+ headers,
591
+ data: responseData,
592
+ isHttpResponse: true
593
+ };
594
+ };
595
+ function processPlaceholders(value, results) {
596
+ return value.replace(/\{\{(.*?)\}\}/g, (match, placeholder) => {
597
+ const parts = placeholder.split("-");
598
+ const friendlyId = parts[0];
599
+ const fieldName = parts[1];
600
+ const keyName = parts.length > 2 ? parts[2] : void 0;
601
+ const sourceResult = results[friendlyId];
602
+ if (sourceResult) {
603
+ if (keyName) {
604
+ return sourceResult[fieldName]?.[keyName] || keyName;
605
+ } else {
606
+ return sourceResult[fieldName] || "";
607
+ }
608
+ }
609
+ return match;
610
+ });
611
+ }
612
+ var OutputNode = {
613
+ label: "Http Output Node",
614
+ type: "HttpOutput",
615
+ category: "output",
616
+ icon: "\u{1F4E4}",
617
+ description: "Node de sa\xEDda do workflow que aceita qualquer entrada e retorna ela diretamente",
618
+ group: "HTTP",
619
+ tags: {
620
+ execution: "sync",
621
+ group: "HTTP"
622
+ },
623
+ fields: [
624
+ {
625
+ id: "status",
626
+ label: "Status Code",
627
+ type: "select",
628
+ required: true,
629
+ defaultValue: 200,
630
+ options: [
631
+ { label: "200 - OK", value: 200 },
632
+ { label: "201 - Created", value: 201 },
633
+ { label: "204 - No Content", value: 204 },
634
+ { label: "400 - Bad Request", value: 400 },
635
+ { label: "401 - Unauthorized", value: 401 },
636
+ { label: "403 - Forbidden", value: 403 },
637
+ { label: "404 - Not Found", value: 404 },
638
+ { label: "422 - Unprocessable Entity", value: 422 },
639
+ { label: "500 - Internal Server Error", value: 500 }
640
+ ],
641
+ handle: {
642
+ type: "output",
643
+ label: "Status",
644
+ name: "status",
645
+ fieldType: "number",
646
+ required: true
647
+ }
648
+ },
649
+ {
650
+ id: "headers",
651
+ label: "Response Headers",
652
+ type: "keyValue",
653
+ required: false,
654
+ defaultValue: {},
655
+ handle: {
656
+ type: "output",
657
+ label: "Headers",
658
+ name: "headers",
659
+ fieldType: "object",
660
+ required: false
661
+ }
662
+ },
663
+ {
664
+ id: "data",
665
+ label: "Response Data",
666
+ type: "json",
667
+ required: true,
668
+ handle: {
669
+ type: "input",
670
+ label: "Data",
671
+ name: "data",
672
+ fieldType: "json",
673
+ required: true
674
+ }
675
+ }
676
+ ]
677
+ };
678
+
679
+ // src/nodes/outputs/chat/output.ts
680
+ var ChatOutputNodeFunction = async (params) => {
681
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
682
+ const inputs_resolved = params.inputs || {};
683
+ const fieldValues = params.fieldValues || {};
684
+ const stream = params.stream;
685
+ const emitter = params.emitter;
686
+ const content = inputs_resolved?.data ?? fieldValues?.data ?? "";
687
+ if (stream && emitter) {
688
+ try {
689
+ emitter.emitDone({ content });
690
+ } catch (_e) {
691
+ try {
692
+ emitter.emitDone({ content });
693
+ } catch (err) {
694
+ console.debug("ChatOutput emitDone error", err);
695
+ }
696
+ }
697
+ }
698
+ return {
699
+ output: content,
700
+ type: "ChatOutput"
701
+ };
702
+ };
703
+ var ChatOutputNode = {
704
+ label: "Chat Output",
705
+ type: "ChatOutput",
706
+ category: "output",
707
+ icon: "\u{1F4E4}",
708
+ description: "Output de chat que envia a resposta para o cliente via WebSocket",
709
+ tags: {
710
+ execution: "async",
711
+ group: "IA"
712
+ },
713
+ fields: [
714
+ {
715
+ id: "data",
716
+ label: "Data",
717
+ type: "string",
718
+ required: true,
719
+ typeable: false,
720
+ handle: {
721
+ type: "input",
722
+ label: "Data",
723
+ name: "data",
724
+ fieldType: "string"
725
+ }
726
+ }
727
+ ]
728
+ };
729
+
730
+ // src/nodes/ia/agent/data.ts
731
+ var import_zod5 = require("zod");
732
+ var IaAgentNodeSchema = import_zod5.z.object({
733
+ name: import_zod5.z.string().describe("Unique name for the agent"),
734
+ systemMessage: import_zod5.z.string().optional().describe("System context for the agent"),
735
+ message: import_zod5.z.string().optional().describe("Input message for the agent"),
736
+ model: import_zod5.z.any().describe("LLM model for the agent"),
737
+ tools: import_zod5.z.any().optional().describe("Tools available to the agent")
738
+ });
739
+ var IaAgentNode = {
740
+ label: "IA Agent",
741
+ type: "IaAgentNode",
742
+ category: "step",
743
+ description: "Creates a configurable AI agent for supervision",
744
+ icon: "\u{1F916}",
745
+ toolable: true,
746
+ group: "IA",
747
+ tags: {
748
+ execution: "async",
749
+ group: "IA"
750
+ },
751
+ fields: [
752
+ {
753
+ id: "name",
754
+ label: "Agent Name",
755
+ type: "string",
756
+ required: true,
757
+ placeholder: "e.g., researcher_agent"
758
+ },
759
+ {
760
+ id: "systemMessage",
761
+ label: "System Message",
762
+ type: "textarea",
763
+ required: true,
764
+ placeholder: "You are a web researcher...",
765
+ handle: {
766
+ type: "input",
767
+ label: "System Message",
768
+ name: "systemMessage",
769
+ fieldType: "string"
770
+ }
771
+ },
772
+ {
773
+ id: "message",
774
+ label: "Message",
775
+ type: "string",
776
+ required: false,
777
+ typeable: false,
778
+ handle: {
779
+ type: "input",
780
+ label: "Message",
781
+ name: "message",
782
+ fieldType: "string"
783
+ }
784
+ },
785
+ {
786
+ id: "model",
787
+ label: "Model",
788
+ type: "model",
789
+ typeable: false,
790
+ required: true,
791
+ handle: {
792
+ type: "input",
793
+ label: "Model",
794
+ name: "model",
795
+ fieldType: "model",
796
+ acceptTypes: ["model"],
797
+ maxConnections: 1
798
+ }
799
+ },
800
+ {
801
+ id: "tools",
802
+ label: "Tools",
803
+ type: "tool",
804
+ required: false,
805
+ typeable: false,
806
+ handle: {
807
+ type: "input",
808
+ label: "Tools",
809
+ name: "tools",
810
+ fieldType: "tool",
811
+ acceptTypes: ["tool"]
812
+ }
813
+ },
814
+ {
815
+ id: "agent",
816
+ label: "Agent",
817
+ type: "agent",
818
+ required: true,
819
+ typeable: false,
820
+ handle: {
821
+ type: "output",
822
+ label: "Agent",
823
+ name: "agent",
824
+ fieldType: "agent"
825
+ }
826
+ },
827
+ {
828
+ id: "response",
829
+ label: "Response",
830
+ type: "string",
831
+ required: true,
832
+ typeable: false,
833
+ handle: {
834
+ type: "output",
835
+ label: "response",
836
+ name: "response",
837
+ fieldType: "string"
838
+ }
839
+ }
840
+ ]
841
+ };
842
+
843
+ // src/nodes/ia/agent/function.ts
844
+ var import_prebuilt = require("@langchain/langgraph/prebuilt");
845
+ var import_messages = require("@langchain/core/messages");
846
+
847
+ // src/utils/llm-factory.ts
848
+ var import_graphql_request = require("graphql-request");
849
+ var import_google_gauth = require("@langchain/google-gauth");
850
+ var import_openai = require("@langchain/openai");
851
+ var GRAPHQL_ENDPOINT = process.env["GRAPHQL_URL"] || "http://localhost:3001/graphql";
852
+ var GET_INTEGRATIONS_QUERY = import_graphql_request.gql`
853
+ query GetIntegrations($where: IntegrationWhereInput) {
854
+ getIntegrations(where: $where) {
855
+ status
856
+ message
857
+ data {
858
+ id
859
+ status
860
+ data
861
+ }
862
+ }
863
+ }
864
+ `;
865
+ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
866
+ if (modelConfig?.invoke || modelConfig?.call) {
867
+ return modelConfig;
868
+ }
869
+ if (!modelConfig?.model || !modelConfig?.integrationId) {
870
+ throw new Error('Model config deve conter "model" e "integrationId"');
871
+ }
872
+ const { model, integrationId } = modelConfig;
873
+ const provider = "gemini";
874
+ switch (provider) {
875
+ case "gemini":
876
+ return new import_google_gauth.ChatGoogle({
877
+ model: "gemini-flash-latest",
878
+ apiKey: "AIzaSyAWS9GhesWxG4uTdJRQbBziMB1diXtXtlI",
879
+ streaming
880
+ });
881
+ case "openai":
882
+ return new import_openai.ChatOpenAI({
883
+ model,
884
+ openAIApiKey: apiKey,
885
+ streaming
886
+ });
887
+ case "openrouter":
888
+ return new import_openai.ChatOpenAI({
889
+ model,
890
+ openAIApiKey: apiKey,
891
+ configuration: {
892
+ baseURL: "https://openrouter.ai/api/v1"
893
+ },
894
+ streaming
895
+ });
896
+ default:
897
+ throw new Error(
898
+ `Provider "${provider}" n\xE3o suportado. Providers dispon\xEDveis: gemini, openai, openrouter`
899
+ );
900
+ }
901
+ }
902
+
903
+ // src/nodes/ia/agent/function.ts
904
+ var IaAgentNodeFunction = async (inputs) => {
905
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
906
+ const { model, tools, systemMessage, name, message } = inputs.fieldValues || {};
907
+ const authToken = inputs.authToken;
908
+ const stream = Boolean(inputs?.stream);
909
+ const emitter = inputs?.emitter;
910
+ if (!name) {
911
+ throw new Error("Agent 'name' is required. Please provide a unique name for the agent in the node properties.");
912
+ }
913
+ if (!model) {
914
+ throw new Error("Model is required for IaAgentNode");
915
+ }
916
+ let toolsArray = [];
917
+ if (Array.isArray(tools)) {
918
+ toolsArray = tools;
919
+ } else if (tools) {
920
+ toolsArray = [tools];
921
+ }
922
+ const finalSystemMessageContent = `${systemMessage || ""}
923
+
924
+ IMPORTANT: You must base your response on the last message in the conversation history.`;
925
+ const finalSystemMessage = new import_messages.SystemMessage(finalSystemMessageContent);
926
+ let llmInstance;
927
+ if (model?.integrationId) {
928
+ if (!authToken) {
929
+ throw new Error("Auth token is required to instantiate LLM from integration");
930
+ }
931
+ llmInstance = await createLLMFromModel(model, authToken, stream);
932
+ } else if (typeof model?.bindTools === "function") {
933
+ llmInstance = model;
934
+ } else {
935
+ throw new Error("Invalid model: must have integrationId or be a valid LLM instance with bindTools method");
936
+ }
937
+ const agent = (0, import_prebuilt.createReactAgent)({
938
+ llm: llmInstance,
939
+ tools: toolsArray,
940
+ messageModifier: finalSystemMessage
941
+ });
942
+ agent.name = name;
943
+ let output = "";
944
+ if (message) {
945
+ try {
946
+ const { HumanMessage: HumanMessage2 } = await import("@langchain/core/messages");
947
+ if (stream && emitter) {
948
+ const streamIterator = await agent.stream({
949
+ messages: [new HumanMessage2(message)]
950
+ });
951
+ let lastMessages = [];
952
+ const sentContents = /* @__PURE__ */ new Set();
953
+ for await (const step of streamIterator) {
954
+ if (step && typeof step === "object") {
955
+ for (const [key, value] of Object.entries(step)) {
956
+ if (value && typeof value === "object" && "messages" in value) {
957
+ const messages = value.messages;
958
+ if (Array.isArray(messages)) {
959
+ lastMessages = messages;
960
+ for (const msg of messages) {
961
+ const content = msg?.content;
962
+ const contentStr = typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => p.type === "text" ? p.text : "").filter(Boolean).join("") : "";
963
+ if (contentStr && !sentContents.has(contentStr)) {
964
+ sentContents.add(contentStr);
965
+ if (emitter?.emitDelta) {
966
+ emitter.emitDelta({
967
+ content: contentStr,
968
+ actor: name,
969
+ isAgent: true,
970
+ isTool: false
971
+ });
972
+ }
973
+ }
974
+ }
975
+ }
976
+ }
977
+ }
978
+ }
979
+ }
980
+ if (lastMessages.length > 0) {
981
+ const lastMessage = lastMessages[lastMessages.length - 1];
982
+ const content = lastMessage?.content;
983
+ if (typeof content === "string") {
984
+ output = content;
985
+ } else if (Array.isArray(content)) {
986
+ output = content.map((part) => {
987
+ if (typeof part === "string") return part;
988
+ if (part?.type === "text") return part.text;
989
+ return "";
990
+ }).filter(Boolean).join("\n");
991
+ }
992
+ }
993
+ } else {
994
+ const result = await agent.invoke({
995
+ messages: [new HumanMessage2(message)]
996
+ });
997
+ if (result?.messages && result.messages.length > 0) {
998
+ const lastMessage = result.messages[result.messages.length - 1];
999
+ const content = lastMessage?.content;
1000
+ if (typeof content === "string") {
1001
+ output = content;
1002
+ } else if (Array.isArray(content)) {
1003
+ output = content.map((part) => {
1004
+ if (typeof part === "string") return part;
1005
+ if (part?.type === "text") return part.text;
1006
+ return "";
1007
+ }).filter(Boolean).join("\n");
1008
+ } else {
1009
+ output = "";
1010
+ }
1011
+ }
1012
+ }
1013
+ } catch (error) {
1014
+ console.error("Error processing message in agent:", error);
1015
+ output = `Error: ${error instanceof Error ? error.message : "Unknown error"}`;
1016
+ }
1017
+ }
1018
+ return {
1019
+ agent,
1020
+ output: output || ""
1021
+ };
1022
+ };
1023
+
1024
+ // src/nodes/ia/supervisor/data.ts
1025
+ var import_zod6 = require("zod");
1026
+ var AiSupervisorNodeSchema = import_zod6.z.object({
1027
+ model: import_zod6.z.any().describe("LLM model for the supervisor"),
1028
+ agents: import_zod6.z.any().optional().describe("Agent(s) to supervise"),
1029
+ message: import_zod6.z.string().describe("Task or message for the supervisor to handle"),
1030
+ systemMessage: import_zod6.z.string().optional().describe("Custom system message for the supervisor")
1031
+ });
1032
+ var AiSupervisorNode = {
1033
+ label: "AI Supervisor",
1034
+ type: "AiSupervisorNode",
1035
+ category: "step",
1036
+ description: "Coordinates multiple agents to perform tasks manually",
1037
+ icon: "\u{1F440}",
1038
+ toolable: false,
1039
+ group: "IA",
1040
+ tags: {
1041
+ execution: "async",
1042
+ group: "IA"
1043
+ },
1044
+ fields: [
1045
+ {
1046
+ id: "message",
1047
+ label: "Message",
1048
+ type: "string",
1049
+ required: true,
1050
+ handle: { type: "input", label: "Message", name: "message", fieldType: "string" }
1051
+ },
1052
+ {
1053
+ id: "systemMessage",
1054
+ label: "System Message",
1055
+ type: "textarea",
1056
+ required: false,
1057
+ placeholder: "You are a supervisor... (use {members} to list agents)",
1058
+ handle: {
1059
+ type: "input",
1060
+ label: "System Message",
1061
+ name: "systemMessage",
1062
+ fieldType: "string"
1063
+ }
1064
+ },
1065
+ {
1066
+ id: "model",
1067
+ label: "Model",
1068
+ type: "model",
1069
+ typeable: false,
1070
+ required: true,
1071
+ handle: {
1072
+ type: "input",
1073
+ label: "Model",
1074
+ name: "model",
1075
+ fieldType: "model",
1076
+ acceptTypes: ["model"],
1077
+ maxConnections: 1
1078
+ }
1079
+ },
1080
+ {
1081
+ id: "agents",
1082
+ label: "Agents",
1083
+ type: "agent",
1084
+ required: true,
1085
+ typeable: false,
1086
+ handle: {
1087
+ type: "input",
1088
+ label: "Agents",
1089
+ name: "agents",
1090
+ fieldType: "agent",
1091
+ acceptTypes: ["agent"]
1092
+ }
1093
+ },
1094
+ {
1095
+ id: "response",
1096
+ label: "Response",
1097
+ type: "string",
1098
+ required: true,
1099
+ typeable: false,
1100
+ handle: {
1101
+ type: "output",
1102
+ label: "response",
1103
+ name: "response",
1104
+ fieldType: "string"
1105
+ }
1106
+ }
1107
+ ]
1108
+ };
1109
+
1110
+ // src/nodes/ia/supervisor/function.ts
1111
+ var import_langgraph_supervisor = require("@langchain/langgraph-supervisor");
1112
+ var import_messages2 = require("@langchain/core/messages");
1113
+ var import_langgraph = require("@langchain/langgraph");
1114
+ var checkpointer = new import_langgraph.MemorySaver();
1115
+ var store = new import_langgraph.InMemoryStore();
1116
+ var extractSupervisorAgents = (agents) => {
1117
+ if (Array.isArray(agents)) {
1118
+ return agents.map((a) => a.agent).filter(Boolean);
1119
+ }
1120
+ if (agents?.agent) {
1121
+ return [agents.agent];
1122
+ }
1123
+ return [agents];
1124
+ };
1125
+ var extractFinalResponse = (messages) => {
1126
+ if (!messages || messages.length === 0) return "No response generated.";
1127
+ const isTransferOrToolMsg = (m) => {
1128
+ const content = m?.content;
1129
+ const name = m?.name;
1130
+ const hasToolCallId = typeof m?.tool_call_id === "string" || typeof m?.additional_kwargs?.tool_call_id === "string";
1131
+ const hasToolCalls = Array.isArray(m?.additional_kwargs?.tool_calls) && m.additional_kwargs.tool_calls.length > 0;
1132
+ const contentStr = typeof content === "string" ? content : "";
1133
+ const nameStr = typeof name === "string" ? name : "";
1134
+ if (hasToolCallId || hasToolCalls) return true;
1135
+ if (/^Successfully transferred/i.test(contentStr)) return true;
1136
+ if (/^Transferring back to supervisor/i.test(contentStr)) return true;
1137
+ if (/^transfer_/i.test(nameStr)) return true;
1138
+ return false;
1139
+ };
1140
+ for (let i = messages.length - 1; i >= 0; i--) {
1141
+ const msg = messages[i];
1142
+ if (isTransferOrToolMsg(msg)) continue;
1143
+ const content = msg?.content;
1144
+ if (typeof content === "string" && content.trim()) return content;
1145
+ if (Array.isArray(content)) {
1146
+ const textContent = content.map((part) => part.type === "text" ? part.text : "").filter(Boolean).join("\n");
1147
+ if (textContent.trim()) return textContent;
1148
+ }
1149
+ }
1150
+ const lastMessage = messages[messages.length - 1];
1151
+ if (!lastMessage?.content) return "No response generated.";
1152
+ if (typeof lastMessage.content === "string") return lastMessage.content;
1153
+ if (Array.isArray(lastMessage.content)) {
1154
+ const textContent = lastMessage.content.map((part) => part.type === "text" ? part.text : "").filter(Boolean).join("\n");
1155
+ return textContent || JSON.stringify(lastMessage.content);
1156
+ }
1157
+ return "No response generated.";
1158
+ };
1159
+ var AiSupervisorNodeFunction = async (params) => {
1160
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
1161
+ const outer = params ?? {};
1162
+ const inner = outer && typeof outer === "object" && outer.fieldValues && typeof outer.fieldValues === "object" ? outer.fieldValues : {};
1163
+ const model = inner.model ?? outer.model;
1164
+ const agents = inner.agents ?? outer.agents;
1165
+ const message = inner.message ?? outer.message;
1166
+ const systemMessage = inner.systemMessage ?? outer.systemMessage;
1167
+ const stream = (typeof outer.stream === "boolean" ? outer.stream : inner.stream) ?? false;
1168
+ const emitter = outer.emitter ?? inner.emitter;
1169
+ const authToken = outer.authToken ?? inner.authToken;
1170
+ if (!model) throw new Error("Model is required for AiSupervisorNode");
1171
+ if (!agents) throw new Error("Agents are required for AiSupervisorNode.");
1172
+ try {
1173
+ const supervisorAgents = extractSupervisorAgents(agents);
1174
+ if (supervisorAgents.length === 0) throw new Error("No valid agents were extracted from the 'agents' input.");
1175
+ if (supervisorAgents.some((agent) => !agent.name)) throw new Error("All agents must have a name.");
1176
+ let llmInstance;
1177
+ if (model?.model && model?.integrationId) {
1178
+ if (!authToken) {
1179
+ throw new Error("Auth token is required to instantiate LLM from integration 3");
1180
+ }
1181
+ llmInstance = await createLLMFromModel(model, authToken, stream);
1182
+ } else {
1183
+ llmInstance = model;
1184
+ }
1185
+ const finalSystemPrompt = systemMessage || "You are a supervisor...";
1186
+ const workflow = (0, import_langgraph_supervisor.createSupervisor)({
1187
+ llm: llmInstance,
1188
+ agents: supervisorAgents,
1189
+ prompt: finalSystemPrompt
1190
+ });
1191
+ const app = workflow.compile({
1192
+ checkpointer,
1193
+ store
1194
+ });
1195
+ if (stream && emitter) {
1196
+ try {
1197
+ const streamIterator = await app.stream(
1198
+ { messages: [new import_messages2.HumanMessage({ content: message })] },
1199
+ { recursionLimit: 150, configurable: { thread_id: "conversation" } }
1200
+ );
1201
+ let finalMessages = [];
1202
+ const previousStepMessages = /* @__PURE__ */ new Map();
1203
+ const sentMessages = /* @__PURE__ */ new Set();
1204
+ let stepCount = 0;
1205
+ for await (const step of streamIterator) {
1206
+ stepCount++;
1207
+ if (step && typeof step === "object") {
1208
+ for (const [agentKey, agentData] of Object.entries(step)) {
1209
+ if (agentData && typeof agentData === "object" && "messages" in agentData) {
1210
+ const currentMessages = agentData.messages;
1211
+ if (Array.isArray(currentMessages) && currentMessages.length > 0) {
1212
+ finalMessages = currentMessages;
1213
+ const previousCount = previousStepMessages.get(agentKey) || 0;
1214
+ const currentCount = currentMessages.length;
1215
+ if (currentCount > previousCount) {
1216
+ const newMessages = currentMessages.slice(previousCount);
1217
+ const structuredMessages = newMessages.map((msg) => {
1218
+ const msgContent = msg?.content || "";
1219
+ const msgName = msg?.name || "";
1220
+ const toolCallId = msg?.tool_call_id;
1221
+ const isTool = !!(toolCallId || msgName.includes("transfer_") || msgContent.includes("Successfully transferred"));
1222
+ const isAgent = !isTool && agentKey !== "supervisor";
1223
+ let name = "";
1224
+ if (isTool) {
1225
+ if (msgName.includes("transfer_")) {
1226
+ name = msgName;
1227
+ } else {
1228
+ name = "transfer_tool";
1229
+ }
1230
+ } else if (isAgent) {
1231
+ name = msgName || agentKey;
1232
+ } else {
1233
+ name = agentKey === "supervisor" ? "supervisor" : agentKey;
1234
+ }
1235
+ return {
1236
+ isTool,
1237
+ isAgent,
1238
+ name,
1239
+ message: msgContent.trim()
1240
+ };
1241
+ }).filter((item) => item.message);
1242
+ if (structuredMessages.length > 0) {
1243
+ structuredMessages.forEach((structuredMsg) => {
1244
+ const messageHash = `${structuredMsg.name}-${structuredMsg.message.slice(0, 100)}`;
1245
+ if (!sentMessages.has(messageHash)) {
1246
+ sentMessages.add(messageHash);
1247
+ if (emitter?.emitDelta) {
1248
+ emitter.emitDelta({
1249
+ content: structuredMsg.message,
1250
+ actor: structuredMsg.name,
1251
+ isAgent: structuredMsg.isAgent,
1252
+ isTool: structuredMsg.isTool
1253
+ });
1254
+ }
1255
+ }
1256
+ });
1257
+ }
1258
+ previousStepMessages.set(agentKey, currentCount);
1259
+ }
1260
+ }
1261
+ }
1262
+ }
1263
+ }
1264
+ }
1265
+ const finalResponse = extractFinalResponse(finalMessages);
1266
+ return {
1267
+ output: finalResponse,
1268
+ function: AiSupervisorNodeFunction,
1269
+ type: "AiSupervisorNode"
1270
+ };
1271
+ } catch (err) {
1272
+ console.error("\u274C Streaming error:", err);
1273
+ throw err;
1274
+ }
1275
+ } else {
1276
+ const result = await app.invoke(
1277
+ { messages: [new import_messages2.HumanMessage({ content: message })] },
1278
+ { recursionLimit: 150, configurable: { thread_id: "conversation" } }
1279
+ );
1280
+ const finalResponse = extractFinalResponse(result?.messages);
1281
+ return {
1282
+ output: finalResponse,
1283
+ function: AiSupervisorNodeFunction,
1284
+ type: "AiSupervisorNode"
1285
+ };
1286
+ }
1287
+ } catch (error) {
1288
+ console.error("\u274C AiSupervisorNode - Error:", error);
1289
+ return {
1290
+ output: `Error: ${error instanceof Error ? error.message : String(error)}`,
1291
+ function: AiSupervisorNodeFunction,
1292
+ type: "AiSupervisorNode"
1293
+ };
1294
+ }
1295
+ };
1296
+
1297
+ // src/nodes/ia/tool/data.ts
1298
+ var import_zod7 = require("zod");
1299
+ var CustomToolSchema = import_zod7.z.object({
1300
+ input: import_zod7.z.string().optional().describe("Input for the tool")
1301
+ });
1302
+ var AiToolNodeSchema = import_zod7.z.object({
1303
+ name: import_zod7.z.string().describe("Name of the tool"),
1304
+ description: import_zod7.z.string().describe("Description of what the tool does"),
1305
+ // z.function() não suporta .describe(), então usamos z.any() para aceitar qualquer função.
1306
+ nodeFunction: import_zod7.z.any().describe("The function to execute"),
1307
+ nodeType: import_zod7.z.string().describe("The type of the node the tool represents"),
1308
+ originalNodeData: import_zod7.z.any().optional().describe("Original data of the node"),
1309
+ workflowService: import_zod7.z.any().optional().describe("Service for workflow operations"),
1310
+ currentResults: import_zod7.z.any().optional().describe("Current results in the workflow")
1311
+ });
1312
+ var AiToolNode = {
1313
+ label: "AI Tool",
1314
+ type: "AiToolNode",
1315
+ category: "step",
1316
+ description: "Wraps another node to be used as a tool by an AI agent",
1317
+ icon: "\u{1F6E0}\uFE0F",
1318
+ group: "IA",
1319
+ tags: {
1320
+ execution: "async",
1321
+ group: "IA"
1322
+ },
1323
+ fields: [
1324
+ {
1325
+ id: "name",
1326
+ label: "Name",
1327
+ type: "string",
1328
+ required: true
1329
+ },
1330
+ {
1331
+ id: "description",
1332
+ label: "Description",
1333
+ type: "string",
1334
+ required: true
1335
+ },
1336
+ {
1337
+ id: "function",
1338
+ label: "Function",
1339
+ type: "any",
1340
+ // Alterado para 'any' para corresponder ao schema z.any()
1341
+ required: true,
1342
+ typeable: false,
1343
+ handle: {
1344
+ type: "input",
1345
+ label: "Input",
1346
+ name: "input",
1347
+ fieldType: "string",
1348
+ required: true
1349
+ }
1350
+ },
1351
+ {
1352
+ id: "tool",
1353
+ label: "Tool",
1354
+ type: "tool",
1355
+ required: true,
1356
+ typeable: false,
1357
+ handle: {
1358
+ type: "output",
1359
+ label: "Tool",
1360
+ name: "tool",
1361
+ fieldType: "tool",
1362
+ required: true,
1363
+ acceptTypes: ["tool"]
1364
+ }
1365
+ }
1366
+ ]
1367
+ };
1368
+
1369
+ // src/nodes/ia/tool/function.ts
1370
+ var import_tools = require("@langchain/core/tools");
1371
+
1372
+ // src/nodes/consts/schemas.ts
1373
+ var schemas = {
1374
+ IaAgentNode: IaAgentNodeSchema,
1375
+ AiSupervisorNode: AiSupervisorNodeSchema,
1376
+ AiToolNode: AiToolNodeSchema,
1377
+ IaMessageNode: IaMessageNodeSchema
1378
+ };
1379
+
1380
+ // src/nodes/ia/tool/function.ts
1381
+ var AiToolNodeFunction = async (params) => {
1382
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
1383
+ const fieldValues = params.fieldValues || params;
1384
+ const { name, description, nodeFunction, nodeType, originalNodeData, workflowService, currentResults } = fieldValues;
1385
+ const schema = schemas[nodeType] || CustomToolSchema;
1386
+ const dynamicTool = (0, import_tools.tool)(
1387
+ async (args) => {
1388
+ if (nodeFunction && typeof nodeFunction === "function") {
1389
+ try {
1390
+ let resolvedInputs = originalNodeData?.inputs || {};
1391
+ if (workflowService && currentResults && originalNodeData?.inputs) {
1392
+ resolvedInputs = await workflowService.resolveInputs(originalNodeData.inputs, currentResults);
1393
+ }
1394
+ const combinedInputs = {
1395
+ ...resolvedInputs,
1396
+ ...args,
1397
+ originalNodeData
1398
+ };
1399
+ const result = await nodeFunction({ fieldValues: combinedInputs });
1400
+ return result?.output || result;
1401
+ } catch (error) {
1402
+ return `Error: ${error instanceof Error ? error.message : String(error)}`;
1403
+ }
1404
+ }
1405
+ return "Tool function not provided";
1406
+ },
1407
+ {
1408
+ name: name || "Dynamic Tool",
1409
+ description: description || "Tool created from workflow",
1410
+ schema
1411
+ }
1412
+ );
1413
+ return {
1414
+ tool: dynamicTool
1415
+ };
1416
+ };
1417
+
1418
+ // src/nodes/ia/message/message.ts
1419
+ var import_zod8 = require("zod");
1420
+ var IaMessageNodeSchema = import_zod8.z.object({
1421
+ model: import_zod8.z.any().describe("LLM model to use"),
1422
+ systemMessage: import_zod8.z.string().optional().describe("System message for context"),
1423
+ message: import_zod8.z.string().describe("User message to send to the LLM")
1424
+ });
1425
+ var IaMessageNodeFunction = async (inputs) => {
1426
+ const { $field: _$field, $req: _$req, $inputs: _$inputs_var, $vars: _$vars } = inputs;
1427
+ const fieldValues = inputs.fieldValues || inputs;
1428
+ const { model, systemMessage, message } = fieldValues;
1429
+ const authToken = inputs.authToken;
1430
+ const stream = Boolean(inputs?.stream);
1431
+ const emitter = inputs?.emitter;
1432
+ if (!model) {
1433
+ throw new Error("Model is required");
1434
+ }
1435
+ if (!message) {
1436
+ throw new Error("Message is required");
1437
+ }
1438
+ let llmInstance;
1439
+ if (model?.model && model?.integrationId) {
1440
+ if (!authToken) {
1441
+ throw new Error("Auth token is required to instantiate LLM from integration");
1442
+ }
1443
+ llmInstance = await createLLMFromModel(model, authToken, stream);
1444
+ } else {
1445
+ llmInstance = model;
1446
+ }
1447
+ const messages = [];
1448
+ if (systemMessage) {
1449
+ messages.push(["system", systemMessage]);
1450
+ }
1451
+ messages.push(["human", message]);
1452
+ try {
1453
+ if (stream && emitter) {
1454
+ let fullContent = "";
1455
+ const streamResponse = await llmInstance.stream(messages);
1456
+ for await (const chunk of streamResponse) {
1457
+ const chunkContent = typeof chunk.content === "string" ? chunk.content : chunk.content?.text || "";
1458
+ if (chunkContent) {
1459
+ fullContent += chunkContent;
1460
+ if (emitter?.emitDelta) {
1461
+ emitter.emitDelta({
1462
+ content: chunkContent,
1463
+ actor: "IaMessageNode",
1464
+ isAgent: false,
1465
+ isTool: false
1466
+ });
1467
+ }
1468
+ }
1469
+ }
1470
+ return {
1471
+ output: fullContent,
1472
+ response: fullContent,
1473
+ fullResponse: { content: fullContent }
1474
+ };
1475
+ }
1476
+ const response = await llmInstance.invoke(messages);
1477
+ return {
1478
+ output: response.content,
1479
+ response: response.content,
1480
+ fullResponse: response
1481
+ };
1482
+ } catch (error) {
1483
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
1484
+ throw new Error(`Error invoking Model: ${errorMessage}`);
1485
+ }
1486
+ };
1487
+ var IaMessageNode = {
1488
+ label: "AI Message",
1489
+ type: "IaMessageNode",
1490
+ category: "step",
1491
+ description: "Send message to AI model and return response",
1492
+ icon: "\u{1F4AC}",
1493
+ group: "IA",
1494
+ tags: {
1495
+ execution: "async",
1496
+ group: "IA"
1497
+ },
1498
+ fields: [
1499
+ {
1500
+ id: "model",
1501
+ label: "Model",
1502
+ type: "model",
1503
+ required: true,
1504
+ typeable: false,
1505
+ handle: {
1506
+ type: "input",
1507
+ label: "Model",
1508
+ name: "model",
1509
+ fieldType: "model",
1510
+ acceptTypes: ["model"],
1511
+ maxConnections: 1,
1512
+ required: true
1513
+ }
1514
+ },
1515
+ {
1516
+ id: "systemMessage",
1517
+ label: "System Message",
1518
+ type: "string",
1519
+ required: false,
1520
+ placeholder: "You are a helpful assistant...",
1521
+ handle: {
1522
+ type: "input",
1523
+ label: "System Message",
1524
+ name: "systemMessage",
1525
+ fieldType: "string"
1526
+ }
1527
+ },
1528
+ {
1529
+ id: "message",
1530
+ label: "Message",
1531
+ type: "string",
1532
+ required: true,
1533
+ placeholder: "Type your message...",
1534
+ handle: {
1535
+ type: "input",
1536
+ label: "Message",
1537
+ name: "message",
1538
+ fieldType: "string"
1539
+ }
1540
+ },
1541
+ {
1542
+ id: "response",
1543
+ label: "Response",
1544
+ type: "string",
1545
+ required: true,
1546
+ typeable: false,
1547
+ handle: {
1548
+ type: "output",
1549
+ label: "response",
1550
+ name: "response",
1551
+ fieldType: "string"
1552
+ }
1553
+ }
1554
+ ]
1555
+ };
1556
+
1557
+ // src/nodes/social/whatsapp/send-template/data.ts
1558
+ var import_zod9 = require("zod");
1559
+ var WhatsappSendTemplateNodeSchema = import_zod9.z.object({
1560
+ phoneNumber: import_zod9.z.string().describe("Phone number to send the message to"),
1561
+ message: import_zod9.z.string().describe("Message to send")
1562
+ });
1563
+ var WhatsappSendTemplateNode = {
1564
+ label: "Whatsapp Send Template",
1565
+ type: "WhatsappSendTemplateNode",
1566
+ category: "step",
1567
+ description: "Send a template message to a WhatsApp number",
1568
+ icon: "\u{1F4F1}",
1569
+ toolable: true,
1570
+ group: "Social",
1571
+ tags: {
1572
+ execution: "async",
1573
+ group: "Social"
1574
+ },
1575
+ fields: [
1576
+ {
1577
+ id: "phoneNumber",
1578
+ label: "Phone Number",
1579
+ type: "string",
1580
+ required: true,
1581
+ placeholder: "e.g., +5511999999999",
1582
+ handle: {
1583
+ type: "input",
1584
+ label: "Phone Number",
1585
+ name: "phoneNumber",
1586
+ fieldType: "string"
1587
+ }
1588
+ },
1589
+ {
1590
+ id: "template",
1591
+ label: "Template",
1592
+ type: "select",
1593
+ required: true,
1594
+ optionsSource: {
1595
+ provider: "whatsapp.messageTemplates"
1596
+ }
1597
+ }
1598
+ ]
1599
+ };
1600
+
1601
+ // src/nodes/social/whatsapp/send-message/data.ts
1602
+ var import_zod10 = require("zod");
1603
+ var WhatsappSendMessageNodeSchema = import_zod10.z.object({
1604
+ phoneNumber: import_zod10.z.string().describe("Phone number to send the message to"),
1605
+ message: import_zod10.z.string().describe("Message content to send")
1606
+ });
1607
+ var WhatsappSendMessageNode = {
1608
+ label: "Whatsapp Send Message",
1609
+ type: "WhatsappSendMessageNode",
1610
+ category: "step",
1611
+ description: "Send an open text message to a WhatsApp number",
1612
+ icon: "\u{1F4AC}",
1613
+ toolable: true,
1614
+ group: "Social",
1615
+ tags: {
1616
+ execution: "async",
1617
+ group: "Social"
1618
+ },
1619
+ fields: [
1620
+ {
1621
+ id: "phoneNumber",
1622
+ label: "Phone Number",
1623
+ type: "string",
1624
+ required: true,
1625
+ placeholder: "e.g., +5511999999999",
1626
+ handle: {
1627
+ type: "input",
1628
+ label: "Phone Number",
1629
+ name: "phoneNumber",
1630
+ fieldType: "string"
1631
+ }
1632
+ },
1633
+ {
1634
+ id: "message",
1635
+ label: "Message",
1636
+ type: "textarea",
1637
+ required: true,
1638
+ placeholder: "Type your message here...",
1639
+ handle: {
1640
+ type: "input",
1641
+ label: "Message",
1642
+ name: "message",
1643
+ fieldType: "string"
1644
+ }
1645
+ }
1646
+ ]
1647
+ };
1648
+
1649
+ // src/nodes/social/whatsapp/message-trigger/data.ts
1650
+ var WhatsappMessageTriggerNode = {
1651
+ label: "Whatsapp Message Trigger",
1652
+ type: "WhatsappMessageTriggerNode",
1653
+ category: "input",
1654
+ description: "Trigger when a message is received from a WhatsApp number",
1655
+ icon: "\u{1F4F1}",
1656
+ toolable: false,
1657
+ group: "Social",
1658
+ tags: {
1659
+ execution: "async",
1660
+ group: "Social"
1661
+ },
1662
+ fields: [
1663
+ {
1664
+ id: "phoneNumber",
1665
+ label: "Phone Number",
1666
+ type: "string",
1667
+ required: true,
1668
+ typeable: false,
1669
+ handle: {
1670
+ type: "output",
1671
+ label: "Phone Number",
1672
+ name: "phoneNumber",
1673
+ fieldType: "string"
1674
+ }
1675
+ },
1676
+ {
1677
+ id: "userName",
1678
+ label: "User Name",
1679
+ type: "string",
1680
+ required: true,
1681
+ typeable: false,
1682
+ handle: {
1683
+ type: "output",
1684
+ label: "User Name",
1685
+ name: "userName",
1686
+ fieldType: "string"
1687
+ }
1688
+ },
1689
+ {
1690
+ id: "message",
1691
+ label: "Message",
1692
+ type: "string",
1693
+ required: true,
1694
+ typeable: false,
1695
+ handle: {
1696
+ type: "output",
1697
+ label: "Message",
1698
+ name: "message",
1699
+ fieldType: "string"
1700
+ }
1701
+ }
1702
+ ]
1703
+ };
1704
+
1705
+ // src/nodes/processors/custom-code.ts
1706
+ var NodeFunction = (params) => {
1707
+ let input = params?.inputValue ?? params?.input;
1708
+ const context = params && params.fieldValues ? params.fieldValues : params || {};
1709
+ let customCode = context?.customCode ?? params?.customCode;
1710
+ if (input === void 0 && Array.isArray(context?.fields)) {
1711
+ const firstInputField = context.fields.find((f) => f?.handle?.type === "input");
1712
+ if (firstInputField && firstInputField.id) {
1713
+ const key = String(firstInputField.id);
1714
+ if (params && Object.prototype.hasOwnProperty.call(params, key)) input = params[key];
1715
+ else if (context && Object.prototype.hasOwnProperty.call(context, key)) input = context[key];
1716
+ else if (firstInputField.value !== void 0) input = firstInputField.value;
1717
+ }
1718
+ }
1719
+ const looksLikeCode = (code) => {
1720
+ if (typeof code !== "string") return false;
1721
+ const c = code.trim();
1722
+ if (c.length < 3) return false;
1723
+ return /(return\s+|=>|function\s*\(|;|\n|\{|\})/.test(c);
1724
+ };
1725
+ if (typeof customCode === "string" && !looksLikeCode(customCode)) {
1726
+ if (input === void 0) input = customCode;
1727
+ customCode = "";
1728
+ }
1729
+ if (!customCode || typeof customCode === "string" && customCode.trim() === "") {
1730
+ return input;
1731
+ }
1732
+ try {
1733
+ const $inputs = params?.results || {};
1734
+ const $vars = context && context.variables || params?.variables || void 0;
1735
+ const __placeholders = params?.__codePlaceholders ?? context?.__codePlaceholders;
1736
+ const customFunction = new Function("input", "context", "request", "params", "$inputs", "$vars", "__placeholders", customCode);
1737
+ const result = customFunction(input, context, params?.request, params, $inputs, $vars, __placeholders);
1738
+ return result;
1739
+ } catch (error) {
1740
+ throw new Error(`Erro ao executar c\xF3digo customizado: ${error instanceof Error ? error.message : "Erro desconhecido"}`);
1741
+ }
1742
+ };
1743
+ var CustomNodeFunction = (params) => {
1744
+ const context = params && params.fieldValues ? params.fieldValues : params || {};
1745
+ const customCode = context?.customCode;
1746
+ if (!customCode || typeof customCode === "string" && customCode.trim() === "") {
1747
+ throw new Error("CustomNode sem c\xF3digo configurado");
1748
+ }
1749
+ const fields = Array.isArray(context?.fields) ? context.fields : [];
1750
+ const $field = {};
1751
+ fields.forEach((field) => {
1752
+ const fieldId = field?.id;
1753
+ if (!fieldId) return;
1754
+ let value;
1755
+ if (params && Object.prototype.hasOwnProperty.call(params, fieldId)) {
1756
+ value = params[fieldId];
1757
+ } else if (field.handle && field.handle.name && params && Object.prototype.hasOwnProperty.call(params, field.handle.name)) {
1758
+ value = params[field.handle.name];
1759
+ } else if (field.value !== void 0) {
1760
+ value = field.value;
1761
+ } else if (field.defaultValue !== void 0) {
1762
+ value = field.defaultValue;
1763
+ }
1764
+ $field[fieldId] = value;
1765
+ });
1766
+ try {
1767
+ const $inputs = params?.results || {};
1768
+ const $vars = context && context.variables || params?.variables || void 0;
1769
+ const customFunction = new Function("$field", "context", "request", "params", "$inputs", "$vars", customCode);
1770
+ const result = customFunction($field, context, params?.request, params, $inputs, $vars);
1771
+ return result;
1772
+ } catch (error) {
1773
+ throw new Error(`Erro ao executar CustomNode: ${error instanceof Error ? error.message : "Erro desconhecido"}`);
1774
+ }
1775
+ };
1776
+ var CustomCodeNode = {
1777
+ label: "Custom Code",
1778
+ type: "CustomCodeNode",
1779
+ category: "step",
1780
+ icon: "\u{1F4BB}",
1781
+ description: "Node para executar c\xF3digo JavaScript customizado",
1782
+ fields: [
1783
+ {
1784
+ id: "customCode",
1785
+ label: "C\xF3digo Customizado",
1786
+ type: "code",
1787
+ required: false,
1788
+ placeholder: '// Seu c\xF3digo JavaScript aqui\n// Use "input" para acessar o valor de entrada\n// Use "context" para acessar os dados do n\xF3\nreturn input;'
1789
+ },
1790
+ {
1791
+ id: "input",
1792
+ label: "Input",
1793
+ type: "any",
1794
+ required: false,
1795
+ handle: {
1796
+ type: "input",
1797
+ label: "Input",
1798
+ name: "input",
1799
+ fieldType: "any",
1800
+ required: false
1801
+ }
1802
+ },
1803
+ {
1804
+ id: "output",
1805
+ label: "Output",
1806
+ type: "any",
1807
+ required: false,
1808
+ handle: {
1809
+ type: "output",
1810
+ label: "Output",
1811
+ name: "output",
1812
+ fieldType: "any",
1813
+ required: false
1814
+ }
1815
+ }
1816
+ ]
1817
+ };
1818
+
1819
+ // src/nodes/consts/nodes.ts
1820
+ var nodes = [
1821
+ ChatInputNode,
1822
+ ManualTriggerNode,
1823
+ CronTriggerNode,
1824
+ HttpGetInputNode,
1825
+ // HttpPostInputNode,
1826
+ // TransformNode,
1827
+ ConcatNode,
1828
+ OutputNode,
1829
+ ChatOutputNode,
1830
+ IaMessageNode,
1831
+ IaAgentNode,
1832
+ AiToolNode,
1833
+ AiSupervisorNode,
1834
+ WhatsappSendTemplateNode,
1835
+ WhatsappSendMessageNode,
1836
+ WhatsappMessageTriggerNode,
1837
+ CustomCodeNode
1838
+ ];
1839
+ var nodes_default = nodes;
1840
+
1841
+ // src/nodes/social/whatsapp/send-template/functions.ts
1842
+ var BUSINESS_ACCOUNT_ID = "1079341674316936";
1843
+ var NUMBER_ID = "700207253183039";
1844
+ var TOKEN = "EAAUuy5eznhEBPQUOoF07SUTSVjgNIX9eZCWSKPYQhzHiXeEp4Qj3g47bZAPcZAgs8P2B5cZBH9YJjzq0HKNXfA14kaK5Cp2DZCmxzV60MgWlsY1yKavb2qXAQcydoHTTLKcWO53w6ZB7JNzZBeIpZBTb9cB0teRzfX3kjrZBc7utyKq2ZCZCCOQ74pZA28gnmQYzp24oZBQpf7BmuNHgndFVlTba5drxgcpERyNl1dUIDhky7NIruggZDZD";
1845
+ var WhatsappStartChatFunction = async (fieldValues) => {
1846
+ const { phoneNumber, template } = fieldValues;
1847
+ const response = await fetch(`https://graph.facebook.com/v23.0/${NUMBER_ID}/messages`, {
1848
+ method: "POST",
1849
+ headers: {
1850
+ "Authorization": `Bearer ${TOKEN}`,
1851
+ "Content-Type": "application/json"
1852
+ },
1853
+ body: JSON.stringify({
1854
+ messaging_product: "whatsapp",
1855
+ to: phoneNumber,
1856
+ type: "template",
1857
+ template: {
1858
+ name: template,
1859
+ language: {
1860
+ code: "pt_BR"
1861
+ }
1862
+ }
1863
+ })
1864
+ });
1865
+ const data = await response.json();
1866
+ if (!response.ok) {
1867
+ throw new Error(`Failed to start chat: ${response.statusText}`);
1868
+ }
1869
+ return data;
1870
+ };
1871
+ var getMessageTemplates = async () => {
1872
+ const response = await fetch(`https://graph.facebook.com/v23.0/${BUSINESS_ACCOUNT_ID}/message_templates`, {
1873
+ method: "GET",
1874
+ headers: {
1875
+ "Authorization": `Bearer ${TOKEN}`
1876
+ }
1877
+ });
1878
+ const data = await response.json();
1879
+ return data;
1880
+ };
1881
+ var createMessageTemplate = async (payload) => {
1882
+ const response = await fetch(`https://graph.facebook.com/v23.0/${BUSINESS_ACCOUNT_ID}/message_templates`, {
1883
+ method: "POST",
1884
+ headers: {
1885
+ "Authorization": `Bearer ${TOKEN}`,
1886
+ "Content-Type": "application/json"
1887
+ },
1888
+ body: JSON.stringify(payload)
1889
+ });
1890
+ const data = await response.json();
1891
+ if (!response.ok) {
1892
+ const errObj = data.error;
1893
+ const msg = errObj?.message || response.statusText;
1894
+ const enriched = new Error(`Failed to create template: ${msg}`);
1895
+ enriched.details = data;
1896
+ enriched.status = response.status;
1897
+ throw enriched;
1898
+ }
1899
+ return data;
1900
+ };
1901
+
1902
+ // src/nodes/social/whatsapp/send-message/functions.ts
1903
+ var NUMBER_ID2 = "700207253183039";
1904
+ var TOKEN2 = "EAAUuy5eznhEBPWw62uE6cs4oZAW6WvpsiF9RBjTGDjg8H74GouBMl1MBifCuA572AVMp53T83pBuSaMJUcWMDIGxvXbxaU6RFTyXOuKkhUPkF3Boc7QbmRuUWSFuyvkjZCyA7ngAg2NXV8nYzzZCleSuFQD487NN2mat7sHPx2pMHuN95IcaevyKLnuz5Om2Bp36JihQweodc517aH2Krv70jqNKKzBjoGVziWNnOhULQZDZD";
1905
+ var WhatsappSendMessageFunction = async (fieldValues) => {
1906
+ const { phoneNumber, message } = fieldValues;
1907
+ const response = await fetch(`https://graph.facebook.com/v23.0/${NUMBER_ID2}/messages`, {
1908
+ method: "POST",
1909
+ headers: {
1910
+ "Authorization": `Bearer ${TOKEN2}`,
1911
+ "Content-Type": "application/json"
1912
+ },
1913
+ body: JSON.stringify({
1914
+ messaging_product: "whatsapp",
1915
+ to: phoneNumber,
1916
+ type: "text",
1917
+ text: {
1918
+ preview_url: false,
1919
+ body: message
1920
+ }
1921
+ })
1922
+ });
1923
+ const data = await response.json();
1924
+ if (!response.ok) {
1925
+ const errObj = data.error;
1926
+ const msg = errObj?.message || response.statusText;
1927
+ const enriched = new Error(`Failed to send message: ${msg}`);
1928
+ enriched.details = data;
1929
+ enriched.status = response.status;
1930
+ throw enriched;
1931
+ }
1932
+ return data;
1933
+ };
1934
+
1935
+ // src/nodes/consts/node-functions.ts
1936
+ var nodeFunctions = {
1937
+ ChatInput: ChatInputNodeFunction,
1938
+ ChatOutput: ChatOutputNodeFunction,
1939
+ HttpGetInput: HttpGetInputNodeFunction,
1940
+ HttpPostInput: HttpPostInputNodeFunction,
1941
+ ManualTrigger: ManualTriggerNodeFunction,
1942
+ CronTrigger: CronTriggerNodeFunction,
1943
+ HttpOutput: HttpOutputNodeFunction,
1944
+ ConcatNode: ConcatNodeFunction,
1945
+ IaMessageNode: IaMessageNodeFunction,
1946
+ IaAgentNode: IaAgentNodeFunction,
1947
+ AiToolNode: AiToolNodeFunction,
1948
+ AiSupervisorNode: AiSupervisorNodeFunction,
1949
+ WhatsappNode: WhatsappStartChatFunction,
1950
+ WhatsappSendMessageNode: WhatsappSendMessageFunction,
1951
+ CustomCodeNode: NodeFunction,
1952
+ CustomNode: CustomNodeFunction
1953
+ };
1954
+ var node_functions_default = nodeFunctions;
1955
+
1956
+ // src/nodes/inputs/http/put/data.ts
1957
+ var HttpPutInputNode = {
1958
+ label: "Http PUT Input",
1959
+ type: "HttpPutInput",
1960
+ category: "input",
1961
+ icon: "\u{1F4DD}",
1962
+ description: "Node que representa uma rota PUT HTTP para atualiza\xE7\xE3o completa de recursos",
1963
+ tags: {
1964
+ execution: "sync",
1965
+ group: "HTTP"
1966
+ },
1967
+ fields: [
1968
+ {
1969
+ id: "route",
1970
+ label: "Route",
1971
+ type: "route",
1972
+ required: true,
1973
+ placeholder: "/produtos/{id}"
1974
+ },
1975
+ {
1976
+ id: "queryParams",
1977
+ label: "Query Params",
1978
+ type: "keyValue",
1979
+ required: false,
1980
+ handle: {
1981
+ type: "output",
1982
+ label: "Query Params",
1983
+ name: "queryParams",
1984
+ fieldType: "keyValue"
1985
+ }
1986
+ },
1987
+ {
1988
+ id: "headers",
1989
+ label: "Headers",
1990
+ type: "keyValue",
1991
+ required: false,
1992
+ handle: {
1993
+ type: "output",
1994
+ label: "Headers",
1995
+ name: "headers",
1996
+ fieldType: "keyValue"
1997
+ }
1998
+ },
1999
+ {
2000
+ id: "body",
2001
+ label: "Body",
2002
+ type: "object",
2003
+ required: false,
2004
+ handle: {
2005
+ type: "output",
2006
+ label: "Body",
2007
+ name: "body",
2008
+ fieldType: "object",
2009
+ required: false
2010
+ }
2011
+ },
2012
+ {
2013
+ id: "ip",
2014
+ label: "Request IP",
2015
+ type: "string",
2016
+ required: false,
2017
+ typeable: false,
2018
+ handle: {
2019
+ type: "output",
2020
+ label: "IP",
2021
+ name: "ip",
2022
+ fieldType: "string"
2023
+ }
2024
+ }
2025
+ ]
2026
+ };
2027
+
2028
+ // src/nodes/inputs/http/put/function.ts
2029
+ var HttpPutInputNodeFunction = (params) => {
2030
+ const { request, fieldValues } = params;
2031
+ const { queryParams: configQueryParams, headers: configHeaders, body: configBody } = fieldValues || {};
2032
+ if (request.method !== "PUT") {
2033
+ throw new Error("M\xE9todo HTTP inv\xE1lido");
2034
+ }
2035
+ const actualData = {
2036
+ queryParams: request?.query || {},
2037
+ headers: request?.headers || {},
2038
+ body: request?.body || {},
2039
+ ip: request?.ip || "127.0.0.1"
2040
+ };
2041
+ if (configQueryParams) {
2042
+ const requiredParams = configQueryParams.filter((p) => p.required);
2043
+ const missingParams = requiredParams.filter((p) => !actualData.queryParams[p.key]);
2044
+ if (missingParams.length > 0) {
2045
+ throw new Error(`Par\xE2metros obrigat\xF3rios ausentes: ${missingParams.map((p) => p.key).join(", ")}`);
2046
+ }
2047
+ }
2048
+ if (configHeaders) {
2049
+ const requiredHeaders = configHeaders.filter((h) => h.required);
2050
+ const missingHeaders = requiredHeaders.filter((h) => !actualData.headers[h.key.toLowerCase()]);
2051
+ if (missingHeaders.length > 0) {
2052
+ throw new Error(`Headers obrigat\xF3rios ausentes: ${missingHeaders.map((h) => h.key).join(", ")}`);
2053
+ }
2054
+ }
2055
+ if (configBody) {
2056
+ const requiredBodyFields = configBody.filter((f) => f.required);
2057
+ const missingBodyFields = requiredBodyFields.filter((f) => !actualData.body[f.key]);
2058
+ if (missingBodyFields.length > 0) {
2059
+ throw new Error(`Campos obrigat\xF3rios do body ausentes: ${missingBodyFields.map((f) => f.key).join(", ")}`);
2060
+ }
2061
+ }
2062
+ return actualData;
2063
+ };
2064
+
2065
+ // src/nodes/inputs/http/put/schema.ts
2066
+ var import_zod11 = require("zod");
2067
+ var HttpPutInputNodeSchema = import_zod11.z.object({
2068
+ route: RouteSchema,
2069
+ queryParams: import_zod11.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2070
+ headers: import_zod11.z.array(HeaderSchema).optional().describe("Headers configuration"),
2071
+ body: import_zod11.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
2072
+ });
2073
+
2074
+ // src/nodes/inputs/http/delete/data.ts
2075
+ var HttpDeleteInputNode = {
2076
+ label: "Http DELETE Input",
2077
+ type: "HttpDeleteInput",
2078
+ category: "input",
2079
+ icon: "\u{1F5D1}\uFE0F",
2080
+ description: "Node que representa uma rota DELETE HTTP para remo\xE7\xE3o de recursos",
2081
+ tags: {
2082
+ execution: "sync",
2083
+ group: "HTTP"
2084
+ },
2085
+ fields: [
2086
+ {
2087
+ id: "route",
2088
+ label: "Route",
2089
+ type: "route",
2090
+ required: true,
2091
+ placeholder: "/produtos/{id}"
2092
+ },
2093
+ {
2094
+ id: "queryParams",
2095
+ label: "Query Params",
2096
+ type: "keyValue",
2097
+ required: false,
2098
+ handle: {
2099
+ type: "output",
2100
+ label: "Query Params",
2101
+ name: "queryParams",
2102
+ fieldType: "keyValue"
2103
+ }
2104
+ },
2105
+ {
2106
+ id: "headers",
2107
+ label: "Headers",
2108
+ type: "keyValue",
2109
+ required: false,
2110
+ handle: {
2111
+ type: "output",
2112
+ label: "Headers",
2113
+ name: "headers",
2114
+ fieldType: "keyValue"
2115
+ }
2116
+ },
2117
+ {
2118
+ id: "ip",
2119
+ label: "Request IP",
2120
+ type: "string",
2121
+ required: false,
2122
+ typeable: false,
2123
+ handle: {
2124
+ type: "output",
2125
+ label: "IP",
2126
+ name: "ip",
2127
+ fieldType: "string"
2128
+ }
2129
+ }
2130
+ ]
2131
+ };
2132
+
2133
+ // src/nodes/inputs/http/delete/function.ts
2134
+ var HttpDeleteInputNodeFunction = async (params) => {
2135
+ const { request, fieldValues } = params;
2136
+ const { queryParams: configQueryParams, headers: configHeaders } = fieldValues || {};
2137
+ if (request.method !== "DELETE") {
2138
+ throw new Error("M\xE9todo HTTP inv\xE1lido");
2139
+ }
2140
+ const actualData = {
2141
+ queryParams: request?.query || {},
2142
+ headers: request?.headers || {},
2143
+ ip: request?.ip || "127.0.0.1"
2144
+ };
2145
+ if (configQueryParams) {
2146
+ const requiredParams = configQueryParams.filter((p) => p.required);
2147
+ const missingParams = requiredParams.filter((p) => !actualData.queryParams[p.key]);
2148
+ if (missingParams.length > 0) {
2149
+ throw new Error(`Par\xE2metros obrigat\xF3rios ausentes: ${missingParams.map((p) => p.key).join(", ")}`);
2150
+ }
2151
+ }
2152
+ if (configHeaders) {
2153
+ const requiredHeaders = configHeaders.filter((h) => h.required);
2154
+ const missingHeaders = requiredHeaders.filter((h) => !actualData.headers[h.key.toLowerCase()]);
2155
+ if (missingHeaders.length > 0) {
2156
+ throw new Error(`Headers obrigat\xF3rios ausentes: ${missingHeaders.map((h) => h.key).join(", ")}`);
2157
+ }
2158
+ }
2159
+ return actualData;
2160
+ };
2161
+
2162
+ // src/nodes/inputs/http/delete/schema.ts
2163
+ var import_zod12 = require("zod");
2164
+ var HttpDeleteInputNodeSchema = import_zod12.z.object({
2165
+ route: RouteSchema,
2166
+ queryParams: import_zod12.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2167
+ headers: import_zod12.z.array(HeaderSchema).optional().describe("Headers configuration")
2168
+ });
2169
+
2170
+ // src/nodes/inputs/http/patch/data.ts
2171
+ var HttpPatchInputNode = {
2172
+ label: "Http PATCH Input",
2173
+ type: "HttpPatchInput",
2174
+ category: "input",
2175
+ icon: "\u{1F527}",
2176
+ description: "Node que representa uma rota PATCH HTTP para atualiza\xE7\xE3o parcial de recursos",
2177
+ tags: {
2178
+ execution: "sync",
2179
+ group: "HTTP"
2180
+ },
2181
+ fields: [
2182
+ {
2183
+ id: "route",
2184
+ label: "Route",
2185
+ type: "route",
2186
+ required: true,
2187
+ placeholder: "/produtos/{id}"
2188
+ },
2189
+ {
2190
+ id: "queryParams",
2191
+ label: "Query Params",
2192
+ type: "keyValue",
2193
+ required: false,
2194
+ handle: {
2195
+ type: "output",
2196
+ label: "Query Params",
2197
+ name: "queryParams",
2198
+ fieldType: "keyValue"
2199
+ }
2200
+ },
2201
+ {
2202
+ id: "headers",
2203
+ label: "Headers",
2204
+ type: "keyValue",
2205
+ required: false,
2206
+ handle: {
2207
+ type: "output",
2208
+ label: "Headers",
2209
+ name: "headers",
2210
+ fieldType: "keyValue"
2211
+ }
2212
+ },
2213
+ {
2214
+ id: "body",
2215
+ label: "Body",
2216
+ type: "object",
2217
+ required: false,
2218
+ handle: {
2219
+ type: "output",
2220
+ label: "Body",
2221
+ name: "body",
2222
+ fieldType: "object",
2223
+ required: false
2224
+ }
2225
+ },
2226
+ {
2227
+ id: "ip",
2228
+ label: "Request IP",
2229
+ type: "string",
2230
+ required: false,
2231
+ typeable: false,
2232
+ handle: {
2233
+ type: "output",
2234
+ label: "IP",
2235
+ name: "ip",
2236
+ fieldType: "string"
2237
+ }
2238
+ }
2239
+ ]
2240
+ };
2241
+
2242
+ // src/nodes/inputs/http/patch/function.ts
2243
+ var HttpPatchInputNodeFunction = (params) => {
2244
+ const { request, fieldValues } = params;
2245
+ const { queryParams: configQueryParams, headers: configHeaders, body: configBody } = fieldValues || {};
2246
+ if (request.method !== "PATCH") {
2247
+ throw new Error("M\xE9todo HTTP inv\xE1lido");
2248
+ }
2249
+ const actualData = {
2250
+ queryParams: request?.query || {},
2251
+ headers: request?.headers || {},
2252
+ body: request?.body || {},
2253
+ ip: request?.ip || "127.0.0.1"
2254
+ };
2255
+ if (configQueryParams) {
2256
+ const requiredParams = configQueryParams.filter((p) => p.required);
2257
+ const missingParams = requiredParams.filter((p) => !actualData.queryParams[p.key]);
2258
+ if (missingParams.length > 0) {
2259
+ throw new Error(`Par\xE2metros obrigat\xF3rios ausentes: ${missingParams.map((p) => p.key).join(", ")}`);
2260
+ }
2261
+ }
2262
+ if (configHeaders) {
2263
+ const requiredHeaders = configHeaders.filter((h) => h.required);
2264
+ const missingHeaders = requiredHeaders.filter((h) => !actualData.headers[h.key.toLowerCase()]);
2265
+ if (missingHeaders.length > 0) {
2266
+ throw new Error(`Headers obrigat\xF3rios ausentes: ${missingHeaders.map((h) => h.key).join(", ")}`);
2267
+ }
2268
+ }
2269
+ if (configBody) {
2270
+ const requiredBodyFields = configBody.filter((f) => f.required);
2271
+ const missingBodyFields = requiredBodyFields.filter((f) => !actualData.body[f.key]);
2272
+ if (missingBodyFields.length > 0) {
2273
+ throw new Error(`Campos obrigat\xF3rios do body ausentes: ${missingBodyFields.map((f) => f.key).join(", ")}`);
2274
+ }
2275
+ }
2276
+ return actualData;
2277
+ };
2278
+
2279
+ // src/nodes/inputs/http/patch/schema.ts
2280
+ var import_zod13 = require("zod");
2281
+ var HttpPatchInputNodeSchema = import_zod13.z.object({
2282
+ route: RouteSchema,
2283
+ queryParams: import_zod13.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2284
+ headers: import_zod13.z.array(HeaderSchema).optional().describe("Headers configuration"),
2285
+ body: import_zod13.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
2286
+ });
2287
+
2288
+ // src/nodes/inputs/http/utils.ts
2289
+ var HTTP_NODE_TYPES = {
2290
+ GET: "HttpGetInput",
2291
+ POST: "HttpPostInput",
2292
+ PUT: "HttpPutInput",
2293
+ DELETE: "HttpDeleteInput",
2294
+ PATCH: "HttpPatchInput"
2295
+ };
2296
+ var HTTP_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH"];
2297
+ var getHttpNodesTypes = () => {
2298
+ return [
2299
+ HttpGetInputNode,
2300
+ HttpPostInputNode,
2301
+ HttpPutInputNode,
2302
+ HttpDeleteInputNode,
2303
+ HttpPatchInputNode
2304
+ ].map((node) => node.type);
2305
+ };
2306
+ var getHttpNodeTypesArray = () => {
2307
+ return Object.values(HTTP_NODE_TYPES);
2308
+ };
2309
+ var isHttpInputNode = (nodeType) => {
2310
+ return getHttpNodeTypesArray().some((httpType) => nodeType.includes(httpType));
2311
+ };
2312
+ var isHttpMethodNode = (nodeType, method) => {
2313
+ return nodeType.includes(HTTP_NODE_TYPES[method]);
2314
+ };
2315
+ var extractHttpMethodFromNodeType = (nodeType) => {
2316
+ for (const [method, nodeTypeValue] of Object.entries(HTTP_NODE_TYPES)) {
2317
+ if (nodeType.includes(nodeTypeValue)) {
2318
+ return method;
2319
+ }
2320
+ }
2321
+ return "GET";
2322
+ };
2323
+ var getHttpMethodFromNodeType = extractHttpMethodFromNodeType;
2324
+ var isAnyHttpInputNode = (nodeType) => {
2325
+ return nodeType.includes("Http") && nodeType.includes("Input");
2326
+ };
2327
+ var getHttpNodeTypeStrings = () => {
2328
+ return Object.values(HTTP_NODE_TYPES);
2329
+ };
2330
+ var isHttpInputFriendlyId = (friendlyId) => {
2331
+ return friendlyId.includes("Http") && friendlyId.includes("Input");
2332
+ };
2333
+ var getHttpMethodFromFriendlyId = (friendlyId) => {
2334
+ return extractHttpMethodFromNodeType(friendlyId);
2335
+ };
2336
+ // Annotate the CommonJS export names for ESM import in node:
2337
+ 0 && (module.exports = {
2338
+ AiSupervisorNode,
2339
+ AiSupervisorNodeFunction,
2340
+ AiSupervisorNodeSchema,
2341
+ AiToolNode,
2342
+ AiToolNodeFunction,
2343
+ AiToolNodeSchema,
2344
+ BodyFieldSchema,
2345
+ CustomToolSchema,
2346
+ HTTP_METHODS,
2347
+ HTTP_NODE_TYPES,
2348
+ HeaderSchema,
2349
+ HttpDeleteInputNode,
2350
+ HttpDeleteInputNodeFunction,
2351
+ HttpDeleteInputNodeSchema,
2352
+ HttpGetInputNode,
2353
+ HttpGetInputNodeFunction,
2354
+ HttpGetInputNodeSchema,
2355
+ HttpPatchInputNode,
2356
+ HttpPatchInputNodeFunction,
2357
+ HttpPatchInputNodeSchema,
2358
+ HttpPostInputNode,
2359
+ HttpPostInputNodeFunction,
2360
+ HttpPostInputNodeSchema,
2361
+ HttpPutInputNode,
2362
+ HttpPutInputNodeFunction,
2363
+ HttpPutInputNodeSchema,
2364
+ IaAgentNode,
2365
+ IaAgentNodeFunction,
2366
+ IaAgentNodeSchema,
2367
+ IaMessageNode,
2368
+ IaMessageNodeFunction,
2369
+ IaMessageNodeSchema,
2370
+ QueryParamSchema,
2371
+ RouteSchema,
2372
+ WhatsappMessageTriggerNode,
2373
+ WhatsappSendMessageFunction,
2374
+ WhatsappSendMessageNode,
2375
+ WhatsappSendMessageNodeSchema,
2376
+ WhatsappSendTemplateNode,
2377
+ WhatsappSendTemplateNodeSchema,
2378
+ WhatsappStartChatFunction,
2379
+ createMessageTemplate,
2380
+ extractHttpMethodFromNodeType,
2381
+ getHttpMethodFromFriendlyId,
2382
+ getHttpMethodFromNodeType,
2383
+ getHttpNodeTypeStrings,
2384
+ getHttpNodeTypesArray,
2385
+ getHttpNodesTypes,
2386
+ getMessageTemplates,
2387
+ isAnyHttpInputNode,
2388
+ isHttpInputFriendlyId,
2389
+ isHttpInputNode,
2390
+ isHttpMethodNode,
2391
+ nodeFunctions,
2392
+ nodes,
2393
+ schemas
2394
+ });