@atomoz/workflows-nodes 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +331 -86
- package/dist/index.js +332 -87
- package/package.json +8 -5
- package/dist/index.d.cts +0 -430
- package/dist/index.d.ts +0 -430
package/dist/index.cjs
CHANGED
|
@@ -150,7 +150,9 @@ var HttpGetInputNode = {
|
|
|
150
150
|
|
|
151
151
|
// src/nodes/inputs/http/get/function.ts
|
|
152
152
|
var HttpGetInputNodeFunction = async (params) => {
|
|
153
|
-
const {
|
|
153
|
+
const { $field: _$field, $req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
154
|
+
const request = $req || params.request;
|
|
155
|
+
const fieldValues = params.fieldValues || {};
|
|
154
156
|
const { queryParams: configQueryParams, headers: configHeaders } = fieldValues || {};
|
|
155
157
|
const actualData = {
|
|
156
158
|
queryParams: request?.query || {},
|
|
@@ -277,7 +279,9 @@ var HttpPostInputNode = {
|
|
|
277
279
|
|
|
278
280
|
// src/nodes/inputs/http/post/function.ts
|
|
279
281
|
var HttpPostInputNodeFunction = (params) => {
|
|
280
|
-
const {
|
|
282
|
+
const { $field: _$field, $req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
283
|
+
const request = $req || params.request;
|
|
284
|
+
const fieldValues = params.fieldValues || {};
|
|
281
285
|
const { queryParams: configQueryParams, headers: configHeaders, body: configBody } = fieldValues || {};
|
|
282
286
|
if (request.method !== "POST") {
|
|
283
287
|
throw new Error("M\xE9todo HTTP inv\xE1lido");
|
|
@@ -323,7 +327,9 @@ var HttpPostInputNodeSchema = import_zod3.z.object({
|
|
|
323
327
|
|
|
324
328
|
// src/nodes/inputs/chat/chat.ts
|
|
325
329
|
var ChatInputNodeFunction = (params) => {
|
|
326
|
-
const {
|
|
330
|
+
const { $field: _$field, $req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
331
|
+
const request = $req || params.request;
|
|
332
|
+
const fieldValues = params.fieldValues || {};
|
|
327
333
|
const { message: configMessage, chatId: configChatId } = fieldValues || {};
|
|
328
334
|
const actualData = {
|
|
329
335
|
message: request?.message ?? configMessage ?? "",
|
|
@@ -376,7 +382,8 @@ var ChatInputNode = {
|
|
|
376
382
|
|
|
377
383
|
// src/nodes/inputs/manual/trigger.ts
|
|
378
384
|
var ManualTriggerNodeFunction = (params) => {
|
|
379
|
-
const {
|
|
385
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
386
|
+
const fieldValues = params.fieldValues || {};
|
|
380
387
|
return fieldValues || {};
|
|
381
388
|
};
|
|
382
389
|
var ManualTriggerNode = {
|
|
@@ -413,11 +420,143 @@ var ManualTriggerNode = {
|
|
|
413
420
|
]
|
|
414
421
|
};
|
|
415
422
|
|
|
423
|
+
// src/nodes/inputs/cron/trigger.ts
|
|
424
|
+
var CronTriggerNodeFunction = (params) => {
|
|
425
|
+
const { $req } = params;
|
|
426
|
+
const triggerData = $req || {};
|
|
427
|
+
const fieldValues = params.fieldValues || {};
|
|
428
|
+
return {
|
|
429
|
+
triggeredAt: triggerData.triggeredAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
430
|
+
scheduleId: triggerData.scheduleId || null,
|
|
431
|
+
cronExpression: fieldValues.cronExpression || null,
|
|
432
|
+
timezone: fieldValues.timezone || "America/Sao_Paulo",
|
|
433
|
+
success: true
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
var CronTriggerNode = {
|
|
437
|
+
label: "Cron Trigger",
|
|
438
|
+
type: "CronTrigger",
|
|
439
|
+
category: "input",
|
|
440
|
+
icon: "\u23F0",
|
|
441
|
+
description: "Dispara fluxo automaticamente baseado em express\xE3o cron",
|
|
442
|
+
tags: {
|
|
443
|
+
execution: "async",
|
|
444
|
+
group: "Custom"
|
|
445
|
+
},
|
|
446
|
+
fields: [
|
|
447
|
+
{
|
|
448
|
+
id: "cronExpression",
|
|
449
|
+
label: "Express\xE3o Cron",
|
|
450
|
+
type: "string",
|
|
451
|
+
required: true,
|
|
452
|
+
placeholder: "0 9 * * * (todos os dias \xE0s 9h)"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
id: "timezone",
|
|
456
|
+
label: "Timezone",
|
|
457
|
+
type: "select",
|
|
458
|
+
defaultValue: "America/Sao_Paulo",
|
|
459
|
+
options: [
|
|
460
|
+
{ label: "S\xE3o Paulo (GMT-3)", value: "America/Sao_Paulo" },
|
|
461
|
+
{ label: "UTC", value: "UTC" },
|
|
462
|
+
{ label: "New York (GMT-5)", value: "America/New_York" },
|
|
463
|
+
{ label: "Los Angeles (GMT-8)", value: "America/Los_Angeles" },
|
|
464
|
+
{ label: "London (GMT+0)", value: "Europe/London" }
|
|
465
|
+
]
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
id: "triggeredAt",
|
|
469
|
+
label: "Triggered At",
|
|
470
|
+
type: "string",
|
|
471
|
+
typeable: false,
|
|
472
|
+
handle: {
|
|
473
|
+
type: "output",
|
|
474
|
+
label: "Triggered At",
|
|
475
|
+
name: "triggeredAt",
|
|
476
|
+
fieldType: "string"
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
id: "scheduleId",
|
|
481
|
+
label: "Schedule ID",
|
|
482
|
+
type: "string",
|
|
483
|
+
typeable: false,
|
|
484
|
+
handle: {
|
|
485
|
+
type: "output",
|
|
486
|
+
label: "Schedule ID",
|
|
487
|
+
name: "scheduleId",
|
|
488
|
+
fieldType: "string"
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
]
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
// src/nodes/processors/delay/index.ts
|
|
495
|
+
var DelayNode = {
|
|
496
|
+
label: "Delay",
|
|
497
|
+
type: "DelayNode",
|
|
498
|
+
category: "step",
|
|
499
|
+
icon: "\u23F3",
|
|
500
|
+
description: "Pausa o workflow por um tempo determinado",
|
|
501
|
+
tags: {
|
|
502
|
+
execution: "async",
|
|
503
|
+
group: "Control"
|
|
504
|
+
},
|
|
505
|
+
fields: [
|
|
506
|
+
{
|
|
507
|
+
id: "input",
|
|
508
|
+
label: "Trigger",
|
|
509
|
+
type: "any",
|
|
510
|
+
required: false,
|
|
511
|
+
handle: {
|
|
512
|
+
type: "input",
|
|
513
|
+
label: "Start",
|
|
514
|
+
name: "trigger",
|
|
515
|
+
fieldType: "any"
|
|
516
|
+
}
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
id: "duration",
|
|
520
|
+
label: "Dura\xE7\xE3o",
|
|
521
|
+
type: "number",
|
|
522
|
+
required: true,
|
|
523
|
+
defaultValue: 1
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
id: "unit",
|
|
527
|
+
label: "Unidade",
|
|
528
|
+
type: "select",
|
|
529
|
+
defaultValue: "minutes",
|
|
530
|
+
required: true,
|
|
531
|
+
options: [
|
|
532
|
+
{ label: "Segundos", value: "seconds" },
|
|
533
|
+
{ label: "Minutos", value: "minutes" },
|
|
534
|
+
{ label: "Horas", value: "hours" },
|
|
535
|
+
{ label: "Dias", value: "days" }
|
|
536
|
+
]
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
id: "output",
|
|
540
|
+
label: "Continue",
|
|
541
|
+
type: "any",
|
|
542
|
+
required: false,
|
|
543
|
+
handle: {
|
|
544
|
+
type: "output",
|
|
545
|
+
label: "Continue",
|
|
546
|
+
name: "continue",
|
|
547
|
+
fieldType: "any"
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
]
|
|
551
|
+
};
|
|
552
|
+
|
|
416
553
|
// src/nodes/processors/concat.ts
|
|
417
554
|
var import_zod4 = require("zod");
|
|
418
|
-
var ConcatNodeFunction = (
|
|
419
|
-
const
|
|
420
|
-
const
|
|
555
|
+
var ConcatNodeFunction = (params) => {
|
|
556
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
557
|
+
const inputs_resolved = params.inputs || params || {};
|
|
558
|
+
const input1 = inputs_resolved.input1 || "";
|
|
559
|
+
const input2 = inputs_resolved.input2 || "";
|
|
421
560
|
const result = `${input1}${input2}`;
|
|
422
561
|
return {
|
|
423
562
|
output: result,
|
|
@@ -597,8 +736,12 @@ var OutputNode = {
|
|
|
597
736
|
|
|
598
737
|
// src/nodes/outputs/chat/output.ts
|
|
599
738
|
var ChatOutputNodeFunction = async (params) => {
|
|
600
|
-
const {
|
|
601
|
-
const
|
|
739
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
740
|
+
const inputs_resolved = params.inputs || {};
|
|
741
|
+
const fieldValues = params.fieldValues || {};
|
|
742
|
+
const stream = params.stream;
|
|
743
|
+
const emitter = params.emitter;
|
|
744
|
+
const content = inputs_resolved?.data ?? fieldValues?.data ?? "";
|
|
602
745
|
if (stream && emitter) {
|
|
603
746
|
try {
|
|
604
747
|
emitter.emitDone({ content });
|
|
@@ -785,44 +928,12 @@ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
|
|
|
785
928
|
throw new Error('Model config deve conter "model" e "integrationId"');
|
|
786
929
|
}
|
|
787
930
|
const { model, integrationId } = modelConfig;
|
|
788
|
-
const
|
|
789
|
-
headers: {
|
|
790
|
-
Authorization: `Bearer ${authToken}`,
|
|
791
|
-
"x-tenant-id": "65d62c52-0c09-473a-8895-359afbed3f5a"
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
let integrationData;
|
|
795
|
-
try {
|
|
796
|
-
const response = await client.request(
|
|
797
|
-
GET_INTEGRATIONS_QUERY,
|
|
798
|
-
{
|
|
799
|
-
where: {
|
|
800
|
-
id: {
|
|
801
|
-
eq: integrationId
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
);
|
|
806
|
-
if (!response.getIntegrations?.data?.[0]) {
|
|
807
|
-
throw new Error(`Integra\xE7\xE3o ${integrationId} n\xE3o encontrada`);
|
|
808
|
-
}
|
|
809
|
-
integrationData = response.getIntegrations.data[0];
|
|
810
|
-
} catch (error) {
|
|
811
|
-
console.error("Erro ao buscar integra\xE7\xE3o:", error);
|
|
812
|
-
throw new Error(
|
|
813
|
-
`Falha ao buscar integra\xE7\xE3o: ${error instanceof Error ? error.message : "Erro desconhecido"}`
|
|
814
|
-
);
|
|
815
|
-
}
|
|
816
|
-
const apiKey = integrationData.data?.["token"] || integrationData.data?.["token"];
|
|
817
|
-
if (!apiKey) {
|
|
818
|
-
throw new Error(`API Key n\xE3o encontrada na integra\xE7\xE3o ${integrationId}`);
|
|
819
|
-
}
|
|
820
|
-
const provider = integrationData.data?.provider?.toLowerCase() || inferProviderFromModel(model);
|
|
931
|
+
const provider = "gemini";
|
|
821
932
|
switch (provider) {
|
|
822
933
|
case "gemini":
|
|
823
934
|
return new import_google_gauth.ChatGoogle({
|
|
824
935
|
model: "gemini-flash-latest",
|
|
825
|
-
apiKey,
|
|
936
|
+
apiKey: "AIzaSyAWS9GhesWxG4uTdJRQbBziMB1diXtXtlI",
|
|
826
937
|
streaming
|
|
827
938
|
});
|
|
828
939
|
case "openai":
|
|
@@ -846,21 +957,14 @@ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
|
|
|
846
957
|
);
|
|
847
958
|
}
|
|
848
959
|
}
|
|
849
|
-
function inferProviderFromModel(model) {
|
|
850
|
-
const modelLower = model.toLowerCase();
|
|
851
|
-
if (modelLower.includes("gemini") || modelLower.includes("palm")) {
|
|
852
|
-
return "gemini";
|
|
853
|
-
}
|
|
854
|
-
if (modelLower.includes("gpt") || modelLower.includes("o1") || modelLower.includes("o3")) {
|
|
855
|
-
return "openai";
|
|
856
|
-
}
|
|
857
|
-
return "openrouter";
|
|
858
|
-
}
|
|
859
960
|
|
|
860
961
|
// src/nodes/ia/agent/function.ts
|
|
861
962
|
var IaAgentNodeFunction = async (inputs) => {
|
|
862
|
-
const {
|
|
963
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
|
|
964
|
+
const { model, tools, systemMessage, name, message } = inputs.fieldValues || {};
|
|
863
965
|
const authToken = inputs.authToken;
|
|
966
|
+
const stream = Boolean(inputs?.stream);
|
|
967
|
+
const emitter = inputs?.emitter;
|
|
864
968
|
if (!name) {
|
|
865
969
|
throw new Error("Agent 'name' is required. Please provide a unique name for the agent in the node properties.");
|
|
866
970
|
}
|
|
@@ -882,8 +986,7 @@ IMPORTANT: You must base your response on the last message in the conversation h
|
|
|
882
986
|
if (!authToken) {
|
|
883
987
|
throw new Error("Auth token is required to instantiate LLM from integration");
|
|
884
988
|
}
|
|
885
|
-
|
|
886
|
-
llmInstance = await createLLMFromModel(model, authToken, streaming);
|
|
989
|
+
llmInstance = await createLLMFromModel(model, authToken, stream);
|
|
887
990
|
} else if (typeof model?.bindTools === "function") {
|
|
888
991
|
llmInstance = model;
|
|
889
992
|
} else {
|
|
@@ -899,22 +1002,70 @@ IMPORTANT: You must base your response on the last message in the conversation h
|
|
|
899
1002
|
if (message) {
|
|
900
1003
|
try {
|
|
901
1004
|
const { HumanMessage: HumanMessage2 } = await import("@langchain/core/messages");
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1005
|
+
if (stream && emitter) {
|
|
1006
|
+
const streamIterator = await agent.stream({
|
|
1007
|
+
messages: [new HumanMessage2(message)]
|
|
1008
|
+
});
|
|
1009
|
+
let lastMessages = [];
|
|
1010
|
+
const sentContents = /* @__PURE__ */ new Set();
|
|
1011
|
+
for await (const step of streamIterator) {
|
|
1012
|
+
if (step && typeof step === "object") {
|
|
1013
|
+
for (const [key, value] of Object.entries(step)) {
|
|
1014
|
+
if (value && typeof value === "object" && "messages" in value) {
|
|
1015
|
+
const messages = value.messages;
|
|
1016
|
+
if (Array.isArray(messages)) {
|
|
1017
|
+
lastMessages = messages;
|
|
1018
|
+
for (const msg of messages) {
|
|
1019
|
+
const content = msg?.content;
|
|
1020
|
+
const contentStr = typeof content === "string" ? content : Array.isArray(content) ? content.map((p) => p.type === "text" ? p.text : "").filter(Boolean).join("") : "";
|
|
1021
|
+
if (contentStr && !sentContents.has(contentStr)) {
|
|
1022
|
+
sentContents.add(contentStr);
|
|
1023
|
+
if (emitter?.emitDelta) {
|
|
1024
|
+
emitter.emitDelta({
|
|
1025
|
+
content: contentStr,
|
|
1026
|
+
actor: name,
|
|
1027
|
+
isAgent: true,
|
|
1028
|
+
isTool: false
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
if (lastMessages.length > 0) {
|
|
1039
|
+
const lastMessage = lastMessages[lastMessages.length - 1];
|
|
1040
|
+
const content = lastMessage?.content;
|
|
1041
|
+
if (typeof content === "string") {
|
|
1042
|
+
output = content;
|
|
1043
|
+
} else if (Array.isArray(content)) {
|
|
1044
|
+
output = content.map((part) => {
|
|
1045
|
+
if (typeof part === "string") return part;
|
|
1046
|
+
if (part?.type === "text") return part.text;
|
|
1047
|
+
return "";
|
|
1048
|
+
}).filter(Boolean).join("\n");
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
} else {
|
|
1052
|
+
const result = await agent.invoke({
|
|
1053
|
+
messages: [new HumanMessage2(message)]
|
|
1054
|
+
});
|
|
1055
|
+
if (result?.messages && result.messages.length > 0) {
|
|
1056
|
+
const lastMessage = result.messages[result.messages.length - 1];
|
|
1057
|
+
const content = lastMessage?.content;
|
|
1058
|
+
if (typeof content === "string") {
|
|
1059
|
+
output = content;
|
|
1060
|
+
} else if (Array.isArray(content)) {
|
|
1061
|
+
output = content.map((part) => {
|
|
1062
|
+
if (typeof part === "string") return part;
|
|
1063
|
+
if (part?.type === "text") return part.text;
|
|
1064
|
+
return "";
|
|
1065
|
+
}).filter(Boolean).join("\n");
|
|
1066
|
+
} else {
|
|
1067
|
+
output = "";
|
|
1068
|
+
}
|
|
918
1069
|
}
|
|
919
1070
|
}
|
|
920
1071
|
} catch (error) {
|
|
@@ -1063,8 +1214,9 @@ var extractFinalResponse = (messages) => {
|
|
|
1063
1214
|
}
|
|
1064
1215
|
return "No response generated.";
|
|
1065
1216
|
};
|
|
1066
|
-
var AiSupervisorNodeFunction = async (
|
|
1067
|
-
const
|
|
1217
|
+
var AiSupervisorNodeFunction = async (params) => {
|
|
1218
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
1219
|
+
const outer = params ?? {};
|
|
1068
1220
|
const inner = outer && typeof outer === "object" && outer.fieldValues && typeof outer.fieldValues === "object" ? outer.fieldValues : {};
|
|
1069
1221
|
const model = inner.model ?? outer.model;
|
|
1070
1222
|
const agents = inner.agents ?? outer.agents;
|
|
@@ -1284,7 +1436,9 @@ var schemas = {
|
|
|
1284
1436
|
};
|
|
1285
1437
|
|
|
1286
1438
|
// src/nodes/ia/tool/function.ts
|
|
1287
|
-
var AiToolNodeFunction = async (
|
|
1439
|
+
var AiToolNodeFunction = async (params) => {
|
|
1440
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = params;
|
|
1441
|
+
const fieldValues = params.fieldValues || params;
|
|
1288
1442
|
const { name, description, nodeFunction, nodeType, originalNodeData, workflowService, currentResults } = fieldValues;
|
|
1289
1443
|
const schema = schemas[nodeType] || CustomToolSchema;
|
|
1290
1444
|
const dynamicTool = (0, import_tools.tool)(
|
|
@@ -1327,9 +1481,12 @@ var IaMessageNodeSchema = import_zod8.z.object({
|
|
|
1327
1481
|
message: import_zod8.z.string().describe("User message to send to the LLM")
|
|
1328
1482
|
});
|
|
1329
1483
|
var IaMessageNodeFunction = async (inputs) => {
|
|
1484
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs_var, $vars: _$vars } = inputs;
|
|
1330
1485
|
const fieldValues = inputs.fieldValues || inputs;
|
|
1331
1486
|
const { model, systemMessage, message } = fieldValues;
|
|
1332
1487
|
const authToken = inputs.authToken;
|
|
1488
|
+
const stream = Boolean(inputs?.stream);
|
|
1489
|
+
const emitter = inputs?.emitter;
|
|
1333
1490
|
if (!model) {
|
|
1334
1491
|
throw new Error("Model is required");
|
|
1335
1492
|
}
|
|
@@ -1339,10 +1496,9 @@ var IaMessageNodeFunction = async (inputs) => {
|
|
|
1339
1496
|
let llmInstance;
|
|
1340
1497
|
if (model?.model && model?.integrationId) {
|
|
1341
1498
|
if (!authToken) {
|
|
1342
|
-
throw new Error("Auth token is required to instantiate LLM from
|
|
1499
|
+
throw new Error("Auth token is required to instantiate LLM from integration");
|
|
1343
1500
|
}
|
|
1344
|
-
|
|
1345
|
-
llmInstance = await createLLMFromModel(model, authToken, streaming);
|
|
1501
|
+
llmInstance = await createLLMFromModel(model, authToken, stream);
|
|
1346
1502
|
} else {
|
|
1347
1503
|
llmInstance = model;
|
|
1348
1504
|
}
|
|
@@ -1352,6 +1508,29 @@ var IaMessageNodeFunction = async (inputs) => {
|
|
|
1352
1508
|
}
|
|
1353
1509
|
messages.push(["human", message]);
|
|
1354
1510
|
try {
|
|
1511
|
+
if (stream && emitter) {
|
|
1512
|
+
let fullContent = "";
|
|
1513
|
+
const streamResponse = await llmInstance.stream(messages);
|
|
1514
|
+
for await (const chunk of streamResponse) {
|
|
1515
|
+
const chunkContent = typeof chunk.content === "string" ? chunk.content : chunk.content?.text || "";
|
|
1516
|
+
if (chunkContent) {
|
|
1517
|
+
fullContent += chunkContent;
|
|
1518
|
+
if (emitter?.emitDelta) {
|
|
1519
|
+
emitter.emitDelta({
|
|
1520
|
+
content: chunkContent,
|
|
1521
|
+
actor: "IaMessageNode",
|
|
1522
|
+
isAgent: false,
|
|
1523
|
+
isTool: false
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return {
|
|
1529
|
+
output: fullContent,
|
|
1530
|
+
response: fullContent,
|
|
1531
|
+
fullResponse: { content: fullContent }
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1355
1534
|
const response = await llmInstance.invoke(messages);
|
|
1356
1535
|
return {
|
|
1357
1536
|
output: response.content,
|
|
@@ -1583,19 +1762,75 @@ var WhatsappMessageTriggerNode = {
|
|
|
1583
1762
|
|
|
1584
1763
|
// src/nodes/processors/custom-code.ts
|
|
1585
1764
|
var NodeFunction = (params) => {
|
|
1586
|
-
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1589
|
-
|
|
1765
|
+
let input = params?.inputValue ?? params?.input;
|
|
1766
|
+
const context = params && params.fieldValues ? params.fieldValues : params || {};
|
|
1767
|
+
let customCode = context?.customCode ?? params?.customCode;
|
|
1768
|
+
if (input === void 0 && Array.isArray(context?.fields)) {
|
|
1769
|
+
const firstInputField = context.fields.find((f) => f?.handle?.type === "input");
|
|
1770
|
+
if (firstInputField && firstInputField.id) {
|
|
1771
|
+
const key = String(firstInputField.id);
|
|
1772
|
+
if (params && Object.prototype.hasOwnProperty.call(params, key)) input = params[key];
|
|
1773
|
+
else if (context && Object.prototype.hasOwnProperty.call(context, key)) input = context[key];
|
|
1774
|
+
else if (firstInputField.value !== void 0) input = firstInputField.value;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
const looksLikeCode = (code) => {
|
|
1778
|
+
if (typeof code !== "string") return false;
|
|
1779
|
+
const c = code.trim();
|
|
1780
|
+
if (c.length < 3) return false;
|
|
1781
|
+
return /(return\s+|=>|function\s*\(|;|\n|\{|\})/.test(c);
|
|
1782
|
+
};
|
|
1783
|
+
if (typeof customCode === "string" && !looksLikeCode(customCode)) {
|
|
1784
|
+
if (input === void 0) input = customCode;
|
|
1785
|
+
customCode = "";
|
|
1786
|
+
}
|
|
1787
|
+
if (!customCode || typeof customCode === "string" && customCode.trim() === "") {
|
|
1788
|
+
return input;
|
|
1590
1789
|
}
|
|
1591
1790
|
try {
|
|
1592
|
-
const
|
|
1593
|
-
const
|
|
1791
|
+
const $inputs = params?.results || {};
|
|
1792
|
+
const $vars = context && context.variables || params?.variables || void 0;
|
|
1793
|
+
const __placeholders = params?.__codePlaceholders ?? context?.__codePlaceholders;
|
|
1794
|
+
const customFunction = new Function("input", "context", "request", "params", "$inputs", "$vars", "__placeholders", customCode);
|
|
1795
|
+
const result = customFunction(input, context, params?.request, params, $inputs, $vars, __placeholders);
|
|
1594
1796
|
return result;
|
|
1595
1797
|
} catch (error) {
|
|
1596
1798
|
throw new Error(`Erro ao executar c\xF3digo customizado: ${error instanceof Error ? error.message : "Erro desconhecido"}`);
|
|
1597
1799
|
}
|
|
1598
1800
|
};
|
|
1801
|
+
var CustomNodeFunction = (params) => {
|
|
1802
|
+
const context = params && params.fieldValues ? params.fieldValues : params || {};
|
|
1803
|
+
const customCode = context?.customCode;
|
|
1804
|
+
if (!customCode || typeof customCode === "string" && customCode.trim() === "") {
|
|
1805
|
+
throw new Error("CustomNode sem c\xF3digo configurado");
|
|
1806
|
+
}
|
|
1807
|
+
const fields = Array.isArray(context?.fields) ? context.fields : [];
|
|
1808
|
+
const $field = {};
|
|
1809
|
+
fields.forEach((field) => {
|
|
1810
|
+
const fieldId = field?.id;
|
|
1811
|
+
if (!fieldId) return;
|
|
1812
|
+
let value;
|
|
1813
|
+
if (params && Object.prototype.hasOwnProperty.call(params, fieldId)) {
|
|
1814
|
+
value = params[fieldId];
|
|
1815
|
+
} else if (field.handle && field.handle.name && params && Object.prototype.hasOwnProperty.call(params, field.handle.name)) {
|
|
1816
|
+
value = params[field.handle.name];
|
|
1817
|
+
} else if (field.value !== void 0) {
|
|
1818
|
+
value = field.value;
|
|
1819
|
+
} else if (field.defaultValue !== void 0) {
|
|
1820
|
+
value = field.defaultValue;
|
|
1821
|
+
}
|
|
1822
|
+
$field[fieldId] = value;
|
|
1823
|
+
});
|
|
1824
|
+
try {
|
|
1825
|
+
const $inputs = params?.results || {};
|
|
1826
|
+
const $vars = context && context.variables || params?.variables || void 0;
|
|
1827
|
+
const customFunction = new Function("$field", "context", "request", "params", "$inputs", "$vars", customCode);
|
|
1828
|
+
const result = customFunction($field, context, params?.request, params, $inputs, $vars);
|
|
1829
|
+
return result;
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
throw new Error(`Erro ao executar CustomNode: ${error instanceof Error ? error.message : "Erro desconhecido"}`);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1599
1834
|
var CustomCodeNode = {
|
|
1600
1835
|
label: "Custom Code",
|
|
1601
1836
|
type: "CustomCodeNode",
|
|
@@ -1608,7 +1843,13 @@ var CustomCodeNode = {
|
|
|
1608
1843
|
label: "C\xF3digo Customizado",
|
|
1609
1844
|
type: "code",
|
|
1610
1845
|
required: false,
|
|
1611
|
-
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;'
|
|
1846
|
+
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;'
|
|
1847
|
+
},
|
|
1848
|
+
{
|
|
1849
|
+
id: "input",
|
|
1850
|
+
label: "Input",
|
|
1851
|
+
type: "any",
|
|
1852
|
+
required: false,
|
|
1612
1853
|
handle: {
|
|
1613
1854
|
type: "input",
|
|
1614
1855
|
label: "Input",
|
|
@@ -1637,6 +1878,8 @@ var CustomCodeNode = {
|
|
|
1637
1878
|
var nodes = [
|
|
1638
1879
|
ChatInputNode,
|
|
1639
1880
|
ManualTriggerNode,
|
|
1881
|
+
CronTriggerNode,
|
|
1882
|
+
DelayNode,
|
|
1640
1883
|
HttpGetInputNode,
|
|
1641
1884
|
// HttpPostInputNode,
|
|
1642
1885
|
// TransformNode,
|
|
@@ -1755,6 +1998,7 @@ var nodeFunctions = {
|
|
|
1755
1998
|
HttpGetInput: HttpGetInputNodeFunction,
|
|
1756
1999
|
HttpPostInput: HttpPostInputNodeFunction,
|
|
1757
2000
|
ManualTrigger: ManualTriggerNodeFunction,
|
|
2001
|
+
CronTrigger: CronTriggerNodeFunction,
|
|
1758
2002
|
HttpOutput: HttpOutputNodeFunction,
|
|
1759
2003
|
ConcatNode: ConcatNodeFunction,
|
|
1760
2004
|
IaMessageNode: IaMessageNodeFunction,
|
|
@@ -1763,7 +2007,8 @@ var nodeFunctions = {
|
|
|
1763
2007
|
AiSupervisorNode: AiSupervisorNodeFunction,
|
|
1764
2008
|
WhatsappNode: WhatsappStartChatFunction,
|
|
1765
2009
|
WhatsappSendMessageNode: WhatsappSendMessageFunction,
|
|
1766
|
-
CustomCodeNode: NodeFunction
|
|
2010
|
+
CustomCodeNode: NodeFunction,
|
|
2011
|
+
CustomNode: CustomNodeFunction
|
|
1767
2012
|
};
|
|
1768
2013
|
var node_functions_default = nodeFunctions;
|
|
1769
2014
|
|