@atomoz/workflows-nodes 0.1.19 → 0.1.21
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 +816 -58
- package/dist/index.d.cts +445 -0
- package/dist/index.d.ts +445 -0
- package/dist/index.js +821 -53
- package/package.json +6 -3
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,14 +14,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
18
|
|
|
29
19
|
// index.ts
|
|
@@ -980,6 +970,21 @@ var IaAgentNode = {
|
|
|
980
970
|
fieldType: "agent"
|
|
981
971
|
}
|
|
982
972
|
},
|
|
973
|
+
{
|
|
974
|
+
id: "sessionMemory",
|
|
975
|
+
label: "Session Memory",
|
|
976
|
+
type: "memory",
|
|
977
|
+
required: false,
|
|
978
|
+
typeable: false,
|
|
979
|
+
handle: {
|
|
980
|
+
type: "input",
|
|
981
|
+
label: "Session Memory",
|
|
982
|
+
name: "sessionMemory",
|
|
983
|
+
fieldType: "memory",
|
|
984
|
+
acceptTypes: ["memory"],
|
|
985
|
+
maxConnections: 1
|
|
986
|
+
}
|
|
987
|
+
},
|
|
983
988
|
{
|
|
984
989
|
id: "response",
|
|
985
990
|
label: "Response",
|
|
@@ -992,6 +997,47 @@ var IaAgentNode = {
|
|
|
992
997
|
name: "response",
|
|
993
998
|
fieldType: "string"
|
|
994
999
|
}
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
id: "beforeGuardrails",
|
|
1003
|
+
label: "Before Guardrails",
|
|
1004
|
+
type: "guardrail",
|
|
1005
|
+
required: false,
|
|
1006
|
+
typeable: false,
|
|
1007
|
+
handle: {
|
|
1008
|
+
type: "input",
|
|
1009
|
+
label: "Before Guardrails",
|
|
1010
|
+
name: "beforeGuardrails",
|
|
1011
|
+
fieldType: "guardrail",
|
|
1012
|
+
acceptTypes: ["guardrail"],
|
|
1013
|
+
maxConnections: 10
|
|
1014
|
+
}
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
id: "afterGuardrails",
|
|
1018
|
+
label: "After Guardrails",
|
|
1019
|
+
type: "guardrail",
|
|
1020
|
+
required: false,
|
|
1021
|
+
typeable: false,
|
|
1022
|
+
handle: {
|
|
1023
|
+
type: "input",
|
|
1024
|
+
label: "After Guardrails",
|
|
1025
|
+
name: "afterGuardrails",
|
|
1026
|
+
fieldType: "guardrail",
|
|
1027
|
+
acceptTypes: ["guardrail"],
|
|
1028
|
+
maxConnections: 10
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
{
|
|
1032
|
+
id: "guardrailMode",
|
|
1033
|
+
label: "Guardrail Mode",
|
|
1034
|
+
type: "select",
|
|
1035
|
+
required: true,
|
|
1036
|
+
defaultValue: "fail-first",
|
|
1037
|
+
options: [
|
|
1038
|
+
{ label: "Fail on First Violation", value: "fail-first" },
|
|
1039
|
+
{ label: "Run All and Combine", value: "run-all" }
|
|
1040
|
+
]
|
|
995
1041
|
}
|
|
996
1042
|
]
|
|
997
1043
|
};
|
|
@@ -1031,7 +1077,7 @@ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
|
|
|
1031
1077
|
case "gemini":
|
|
1032
1078
|
return new import_google_gauth.ChatGoogle({
|
|
1033
1079
|
model: "gemini-flash-latest",
|
|
1034
|
-
apiKey: "
|
|
1080
|
+
apiKey: "AIzaSyD9WiFuXp2fhVAokIMPp9YPKMlh7_Bvddc",
|
|
1035
1081
|
streaming
|
|
1036
1082
|
});
|
|
1037
1083
|
case "openai":
|
|
@@ -1056,18 +1102,165 @@ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
|
|
|
1056
1102
|
}
|
|
1057
1103
|
}
|
|
1058
1104
|
|
|
1105
|
+
// src/utils/guardrail-executor.ts
|
|
1106
|
+
async function executeGuardrails(guardrails, content, mode = "fail-first") {
|
|
1107
|
+
const list = Array.isArray(guardrails) ? guardrails : [guardrails];
|
|
1108
|
+
const result = {
|
|
1109
|
+
passed: true,
|
|
1110
|
+
blocked: false,
|
|
1111
|
+
modifiedContent: content,
|
|
1112
|
+
violations: []
|
|
1113
|
+
};
|
|
1114
|
+
for (const guard of list) {
|
|
1115
|
+
if (!guard) continue;
|
|
1116
|
+
let guardPassed = true;
|
|
1117
|
+
let violationMessage = "";
|
|
1118
|
+
if (guard.type === "rule") {
|
|
1119
|
+
const { ruleType, config, action } = guard;
|
|
1120
|
+
if (ruleType === "keywords" && config) {
|
|
1121
|
+
const keywords = config.split(",").map((k) => k.trim().toLowerCase());
|
|
1122
|
+
const lowerContent = content.toLowerCase();
|
|
1123
|
+
const found = keywords.filter((k) => lowerContent.includes(k));
|
|
1124
|
+
if (found.length > 0) {
|
|
1125
|
+
guardPassed = false;
|
|
1126
|
+
violationMessage = `Conte\xFAdo cont\xE9m palavras proibidas: ${found.join(", ")}`;
|
|
1127
|
+
}
|
|
1128
|
+
} else if (ruleType === "regex" && config) {
|
|
1129
|
+
try {
|
|
1130
|
+
const regex = new RegExp(config, "i");
|
|
1131
|
+
if (regex.test(content)) {
|
|
1132
|
+
guardPassed = false;
|
|
1133
|
+
violationMessage = `Conte\xFAdo viola regra de padr\xE3o (regex): ${config}`;
|
|
1134
|
+
}
|
|
1135
|
+
} catch (e) {
|
|
1136
|
+
console.error("Invalid regex in guardrail:", config);
|
|
1137
|
+
}
|
|
1138
|
+
} else if (ruleType === "maxValue" && config) {
|
|
1139
|
+
const val = parseFloat(content.replace(/[^\d.-]/g, ""));
|
|
1140
|
+
const max = parseFloat(config);
|
|
1141
|
+
if (!isNaN(val) && val > max) {
|
|
1142
|
+
guardPassed = false;
|
|
1143
|
+
violationMessage = `Valor ${val} excede o m\xE1ximo permitido de ${max}.`;
|
|
1144
|
+
}
|
|
1145
|
+
} else if (ruleType === "minValue" && config) {
|
|
1146
|
+
const val = parseFloat(content.replace(/[^\d.-]/g, ""));
|
|
1147
|
+
const min = parseFloat(config);
|
|
1148
|
+
if (!isNaN(val) && val < min) {
|
|
1149
|
+
guardPassed = false;
|
|
1150
|
+
violationMessage = `Valor ${val} \xE9 menor que o m\xEDnimo permitido de ${min}.`;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
} else if (guard.type === "function") {
|
|
1154
|
+
const { nodeFunction, name } = guard;
|
|
1155
|
+
if (typeof nodeFunction === "function") {
|
|
1156
|
+
try {
|
|
1157
|
+
const result2 = await nodeFunction({
|
|
1158
|
+
input: content,
|
|
1159
|
+
fieldValues: { input: content },
|
|
1160
|
+
originalNodeData: guard.originalNodeData
|
|
1161
|
+
});
|
|
1162
|
+
if (result2 === false || typeof result2 === "object" && result2?.passed === false) {
|
|
1163
|
+
guardPassed = false;
|
|
1164
|
+
violationMessage = typeof result2?.message === "string" ? result2.message : `Fun\xE7\xE3o guardrail "${name}" reprovou o conte\xFAdo.`;
|
|
1165
|
+
} else if (typeof result2 === "object" && result2?.modifiedContent) {
|
|
1166
|
+
result2.modifiedContent = result2.modifiedContent;
|
|
1167
|
+
}
|
|
1168
|
+
} catch (error) {
|
|
1169
|
+
console.error(`Error executing function guardrail "${name}":`, error);
|
|
1170
|
+
guardPassed = false;
|
|
1171
|
+
violationMessage = `Erro na fun\xE7\xE3o guardrail: ${error instanceof Error ? error.message : String(error)}`;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
} else if (guard.type === "model") {
|
|
1175
|
+
const { model, evaluationPrompt, name } = guard;
|
|
1176
|
+
if (model && typeof model.invoke === "function") {
|
|
1177
|
+
try {
|
|
1178
|
+
const prompt = evaluationPrompt.replace("{{content}}", content);
|
|
1179
|
+
const response = await model.invoke(prompt);
|
|
1180
|
+
const resultText = typeof response.content === "string" ? response.content : String(response.content);
|
|
1181
|
+
if (resultText.toUpperCase().includes("UNSAFE")) {
|
|
1182
|
+
guardPassed = false;
|
|
1183
|
+
violationMessage = `Modelo de avalia\xE7\xE3o "${name}" detectou viola\xE7\xE3o de seguran\xE7a/pol\xEDtica.`;
|
|
1184
|
+
}
|
|
1185
|
+
} catch (error) {
|
|
1186
|
+
console.error(`Error executing model guardrail "${name}":`, error);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
if (!guardPassed) {
|
|
1191
|
+
result.passed = false;
|
|
1192
|
+
result.violations.push({
|
|
1193
|
+
name: guard.name,
|
|
1194
|
+
message: violationMessage,
|
|
1195
|
+
action: guard.action || "block"
|
|
1196
|
+
});
|
|
1197
|
+
if (guard.action === "block") {
|
|
1198
|
+
result.blocked = true;
|
|
1199
|
+
result.message = violationMessage;
|
|
1200
|
+
if (mode === "fail-first") break;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
return result;
|
|
1205
|
+
}
|
|
1206
|
+
function applyPromptGuardrails(systemMessage, guardrails) {
|
|
1207
|
+
const list = Array.isArray(guardrails) ? guardrails : [guardrails];
|
|
1208
|
+
let finalSystemMessage = systemMessage;
|
|
1209
|
+
for (const guard of list) {
|
|
1210
|
+
if (guard?.type === "prompt" && guard.prompt) {
|
|
1211
|
+
finalSystemMessage += `
|
|
1212
|
+
|
|
1213
|
+
GUARDRAIL [${guard.name}]: ${guard.prompt}`;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
return finalSystemMessage;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1059
1219
|
// src/nodes/ia/agent/function.ts
|
|
1060
1220
|
var IaAgentNodeFunction = async (inputs) => {
|
|
1061
1221
|
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
|
|
1062
|
-
const
|
|
1222
|
+
const fieldValues = inputs.fieldValues || {};
|
|
1223
|
+
const { model, tools, systemMessage, name, message, beforeGuardrails, afterGuardrails, guardrailMode } = fieldValues;
|
|
1063
1224
|
const authToken = inputs.authToken;
|
|
1064
1225
|
const stream = Boolean(inputs?.stream);
|
|
1065
1226
|
const emitter = inputs?.emitter;
|
|
1227
|
+
const sessionMemory = fieldValues.sessionMemory || inputs.sessionMemory;
|
|
1228
|
+
const checkpointer = sessionMemory && typeof sessionMemory.put === "function" ? sessionMemory : sessionMemory?.checkpointer;
|
|
1229
|
+
const sessionId = inputs.sessionId || inputs.$req?.sessionId || `session-${Date.now()}`;
|
|
1066
1230
|
if (!name) {
|
|
1067
1231
|
throw new Error("Agent 'name' is required. Please provide a unique name for the agent in the node properties.");
|
|
1068
1232
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1233
|
+
const prepareGuardrails = async (list) => {
|
|
1234
|
+
const guardrailsList = Array.isArray(list) ? list : [list];
|
|
1235
|
+
return await Promise.all(guardrailsList.map(async (g) => {
|
|
1236
|
+
if (g?.type === "model" && g.model && !g.model.invoke) {
|
|
1237
|
+
if (!authToken) throw new Error("Auth token required for model guardrail");
|
|
1238
|
+
const modelInstance = await createLLMFromModel(g.model, authToken, false);
|
|
1239
|
+
return { ...g, model: modelInstance };
|
|
1240
|
+
}
|
|
1241
|
+
return g;
|
|
1242
|
+
}));
|
|
1243
|
+
};
|
|
1244
|
+
if (message && beforeGuardrails) {
|
|
1245
|
+
const preparedBefore = await prepareGuardrails(beforeGuardrails);
|
|
1246
|
+
const beforeResults = await executeGuardrails(preparedBefore, message, guardrailMode);
|
|
1247
|
+
if (beforeResults.blocked) {
|
|
1248
|
+
console.log(`\u{1F6E1}\uFE0F IaAgentNode "${name}": Blocked by before-agent guardrail:`, beforeResults.message);
|
|
1249
|
+
if (stream && emitter?.emitDelta) {
|
|
1250
|
+
emitter.emitDelta({
|
|
1251
|
+
content: beforeResults.message || "Requisi\xE7\xE3o bloqueada por pol\xEDtica de seguran\xE7a.",
|
|
1252
|
+
actor: name,
|
|
1253
|
+
isAgent: true,
|
|
1254
|
+
isError: true
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
return {
|
|
1258
|
+
agent: null,
|
|
1259
|
+
output: beforeResults.message || "Requisi\xE7\xE3o bloqueada por pol\xEDtica de seguran\xE7a.",
|
|
1260
|
+
blocked: true,
|
|
1261
|
+
violations: beforeResults.violations
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1071
1264
|
}
|
|
1072
1265
|
let toolsArray = [];
|
|
1073
1266
|
if (Array.isArray(tools)) {
|
|
@@ -1075,9 +1268,15 @@ var IaAgentNodeFunction = async (inputs) => {
|
|
|
1075
1268
|
} else if (tools) {
|
|
1076
1269
|
toolsArray = [tools];
|
|
1077
1270
|
}
|
|
1078
|
-
|
|
1271
|
+
let finalSystemMessageContent = `${systemMessage || ""}
|
|
1079
1272
|
|
|
1080
1273
|
IMPORTANT: You must base your response on the last message in the conversation history.`;
|
|
1274
|
+
if (beforeGuardrails) {
|
|
1275
|
+
finalSystemMessageContent = applyPromptGuardrails(finalSystemMessageContent, beforeGuardrails);
|
|
1276
|
+
}
|
|
1277
|
+
if (afterGuardrails) {
|
|
1278
|
+
finalSystemMessageContent = applyPromptGuardrails(finalSystemMessageContent, afterGuardrails);
|
|
1279
|
+
}
|
|
1081
1280
|
const finalSystemMessage = new import_messages.SystemMessage(finalSystemMessageContent);
|
|
1082
1281
|
let llmInstance;
|
|
1083
1282
|
if (model?.integrationId) {
|
|
@@ -1093,17 +1292,25 @@ IMPORTANT: You must base your response on the last message in the conversation h
|
|
|
1093
1292
|
const agent = (0, import_prebuilt.createReactAgent)({
|
|
1094
1293
|
llm: llmInstance,
|
|
1095
1294
|
tools: toolsArray,
|
|
1096
|
-
messageModifier: finalSystemMessage
|
|
1295
|
+
messageModifier: finalSystemMessage,
|
|
1296
|
+
// Pass checkpointer directly for distributed memory
|
|
1297
|
+
...checkpointer ? { checkpointer } : {}
|
|
1097
1298
|
});
|
|
1098
1299
|
agent.name = name;
|
|
1300
|
+
if (checkpointer) {
|
|
1301
|
+
console.log(`\u{1F9E0} IaAgentNode "${name}": Using distributed memory (sessionId: ${sessionId})`);
|
|
1302
|
+
} else {
|
|
1303
|
+
console.log(`\u26A0\uFE0F IaAgentNode "${name}": No sessionMemory connected - stateless mode`);
|
|
1304
|
+
}
|
|
1099
1305
|
let output = "";
|
|
1100
1306
|
if (message) {
|
|
1101
1307
|
try {
|
|
1102
|
-
const {
|
|
1308
|
+
const invokeConfig = checkpointer ? { configurable: { thread_id: sessionId } } : {};
|
|
1103
1309
|
if (stream && emitter) {
|
|
1104
|
-
const streamIterator = await agent.stream(
|
|
1105
|
-
messages: [new
|
|
1106
|
-
|
|
1310
|
+
const streamIterator = await agent.stream(
|
|
1311
|
+
{ messages: [new import_messages.HumanMessage(message)] },
|
|
1312
|
+
invokeConfig
|
|
1313
|
+
);
|
|
1107
1314
|
let lastMessages = [];
|
|
1108
1315
|
const sentContents = /* @__PURE__ */ new Set();
|
|
1109
1316
|
for await (const step of streamIterator) {
|
|
@@ -1147,9 +1354,10 @@ IMPORTANT: You must base your response on the last message in the conversation h
|
|
|
1147
1354
|
}
|
|
1148
1355
|
}
|
|
1149
1356
|
} else {
|
|
1150
|
-
const result = await agent.invoke(
|
|
1151
|
-
messages: [new
|
|
1152
|
-
|
|
1357
|
+
const result = await agent.invoke(
|
|
1358
|
+
{ messages: [new import_messages.HumanMessage(message)] },
|
|
1359
|
+
invokeConfig
|
|
1360
|
+
);
|
|
1153
1361
|
if (result?.messages && result.messages.length > 0) {
|
|
1154
1362
|
const lastMessage = result.messages[result.messages.length - 1];
|
|
1155
1363
|
const content = lastMessage?.content;
|
|
@@ -1166,6 +1374,26 @@ IMPORTANT: You must base your response on the last message in the conversation h
|
|
|
1166
1374
|
}
|
|
1167
1375
|
}
|
|
1168
1376
|
}
|
|
1377
|
+
if (output && afterGuardrails) {
|
|
1378
|
+
const preparedAfter = await prepareGuardrails(afterGuardrails);
|
|
1379
|
+
const afterResults = await executeGuardrails(preparedAfter, output, guardrailMode);
|
|
1380
|
+
if (afterResults.blocked) {
|
|
1381
|
+
console.log(`\u{1F6E1}\uFE0F IaAgentNode "${name}": Response blocked by after-agent guardrail:`, afterResults.message);
|
|
1382
|
+
if (stream && emitter?.emitDelta) {
|
|
1383
|
+
emitter.emitDelta({
|
|
1384
|
+
content: `
|
|
1385
|
+
|
|
1386
|
+
\u26A0\uFE0F RESPOSTA BLOQUEADA: ${afterResults.message}`,
|
|
1387
|
+
actor: name,
|
|
1388
|
+
isAgent: true,
|
|
1389
|
+
isError: true
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
output = afterResults.message || "Resposta bloqueada por pol\xEDtica de seguran\xE7a.";
|
|
1393
|
+
} else if (afterResults.modifiedContent) {
|
|
1394
|
+
output = afterResults.modifiedContent;
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1169
1397
|
} catch (error) {
|
|
1170
1398
|
console.error("Error processing message in agent:", error);
|
|
1171
1399
|
output = `Error: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
@@ -1247,6 +1475,21 @@ var AiSupervisorNode = {
|
|
|
1247
1475
|
acceptTypes: ["agent"]
|
|
1248
1476
|
}
|
|
1249
1477
|
},
|
|
1478
|
+
{
|
|
1479
|
+
id: "sessionMemory",
|
|
1480
|
+
label: "Session Memory",
|
|
1481
|
+
type: "memory",
|
|
1482
|
+
required: false,
|
|
1483
|
+
typeable: false,
|
|
1484
|
+
handle: {
|
|
1485
|
+
type: "input",
|
|
1486
|
+
label: "Session Memory",
|
|
1487
|
+
name: "sessionMemory",
|
|
1488
|
+
fieldType: "memory",
|
|
1489
|
+
acceptTypes: ["memory"],
|
|
1490
|
+
maxConnections: 1
|
|
1491
|
+
}
|
|
1492
|
+
},
|
|
1250
1493
|
{
|
|
1251
1494
|
id: "response",
|
|
1252
1495
|
label: "Response",
|
|
@@ -1267,7 +1510,6 @@ var AiSupervisorNode = {
|
|
|
1267
1510
|
var import_langgraph_supervisor = require("@langchain/langgraph-supervisor");
|
|
1268
1511
|
var import_messages2 = require("@langchain/core/messages");
|
|
1269
1512
|
var import_langgraph = require("@langchain/langgraph");
|
|
1270
|
-
var checkpointer = new import_langgraph.MemorySaver();
|
|
1271
1513
|
var store = new import_langgraph.InMemoryStore();
|
|
1272
1514
|
var extractSupervisorAgents = (agents) => {
|
|
1273
1515
|
if (Array.isArray(agents)) {
|
|
@@ -1323,6 +1565,9 @@ var AiSupervisorNodeFunction = async (params) => {
|
|
|
1323
1565
|
const stream = (typeof outer.stream === "boolean" ? outer.stream : inner.stream) ?? false;
|
|
1324
1566
|
const emitter = outer.emitter ?? inner.emitter;
|
|
1325
1567
|
const authToken = outer.authToken ?? inner.authToken;
|
|
1568
|
+
const sessionMemory = inner.sessionMemory ?? outer.sessionMemory;
|
|
1569
|
+
const checkpointer = sessionMemory?.checkpointer;
|
|
1570
|
+
const sessionId = outer.sessionId || outer.$req?.sessionId || `supervisor-${Date.now()}`;
|
|
1326
1571
|
if (!model) throw new Error("Model is required for AiSupervisorNode");
|
|
1327
1572
|
if (!agents) throw new Error("Agents are required for AiSupervisorNode.");
|
|
1328
1573
|
try {
|
|
@@ -1332,12 +1577,17 @@ var AiSupervisorNodeFunction = async (params) => {
|
|
|
1332
1577
|
let llmInstance;
|
|
1333
1578
|
if (model?.model && model?.integrationId) {
|
|
1334
1579
|
if (!authToken) {
|
|
1335
|
-
throw new Error("Auth token is required to instantiate LLM from integration
|
|
1580
|
+
throw new Error("Auth token is required to instantiate LLM from integration");
|
|
1336
1581
|
}
|
|
1337
1582
|
llmInstance = await createLLMFromModel(model, authToken, stream);
|
|
1338
1583
|
} else {
|
|
1339
1584
|
llmInstance = model;
|
|
1340
1585
|
}
|
|
1586
|
+
if (checkpointer) {
|
|
1587
|
+
console.log(`\u{1F9E0} AiSupervisorNode: Using distributed memory (sessionId: ${sessionId})`);
|
|
1588
|
+
} else {
|
|
1589
|
+
console.log(`\u26A0\uFE0F AiSupervisorNode: No sessionMemory connected - stateless mode`);
|
|
1590
|
+
}
|
|
1341
1591
|
const finalSystemPrompt = systemMessage || "You are a supervisor...";
|
|
1342
1592
|
const workflow = (0, import_langgraph_supervisor.createSupervisor)({
|
|
1343
1593
|
llm: llmInstance,
|
|
@@ -1345,14 +1595,14 @@ var AiSupervisorNodeFunction = async (params) => {
|
|
|
1345
1595
|
prompt: finalSystemPrompt
|
|
1346
1596
|
});
|
|
1347
1597
|
const app = workflow.compile({
|
|
1348
|
-
checkpointer,
|
|
1598
|
+
...checkpointer ? { checkpointer } : {},
|
|
1349
1599
|
store
|
|
1350
1600
|
});
|
|
1351
1601
|
if (stream && emitter) {
|
|
1352
1602
|
try {
|
|
1353
1603
|
const streamIterator = await app.stream(
|
|
1354
1604
|
{ messages: [new import_messages2.HumanMessage({ content: message })] },
|
|
1355
|
-
{ recursionLimit: 150, configurable: { thread_id:
|
|
1605
|
+
{ recursionLimit: 150, configurable: { thread_id: sessionId } }
|
|
1356
1606
|
);
|
|
1357
1607
|
let finalMessages = [];
|
|
1358
1608
|
const previousStepMessages = /* @__PURE__ */ new Map();
|
|
@@ -1431,7 +1681,7 @@ var AiSupervisorNodeFunction = async (params) => {
|
|
|
1431
1681
|
} else {
|
|
1432
1682
|
const result = await app.invoke(
|
|
1433
1683
|
{ messages: [new import_messages2.HumanMessage({ content: message })] },
|
|
1434
|
-
{ recursionLimit: 150, configurable: { thread_id:
|
|
1684
|
+
{ recursionLimit: 150, configurable: { thread_id: sessionId } }
|
|
1435
1685
|
);
|
|
1436
1686
|
const finalResponse = extractFinalResponse(result?.messages);
|
|
1437
1687
|
return {
|
|
@@ -1525,12 +1775,139 @@ var AiToolNode = {
|
|
|
1525
1775
|
// src/nodes/ia/tool/function.ts
|
|
1526
1776
|
var import_tools = require("@langchain/core/tools");
|
|
1527
1777
|
|
|
1778
|
+
// src/nodes/memory/postgres/data.ts
|
|
1779
|
+
var import_zod8 = require("zod");
|
|
1780
|
+
var PostgresMemoryNodeSchema = import_zod8.z.object({
|
|
1781
|
+
connectionString: import_zod8.z.string().describe("PostgreSQL connection string")
|
|
1782
|
+
});
|
|
1783
|
+
var PostgresMemoryNode = {
|
|
1784
|
+
label: "Postgres Memory",
|
|
1785
|
+
type: "PostgresMemoryNode",
|
|
1786
|
+
category: "memory",
|
|
1787
|
+
description: "Persistent conversation memory using PostgreSQL (distributed across pods)",
|
|
1788
|
+
icon: "\u{1F418}",
|
|
1789
|
+
group: "Memory",
|
|
1790
|
+
tags: {
|
|
1791
|
+
execution: "sync",
|
|
1792
|
+
group: "Memory"
|
|
1793
|
+
},
|
|
1794
|
+
fields: [
|
|
1795
|
+
{
|
|
1796
|
+
id: "connectionString",
|
|
1797
|
+
label: "Connection String",
|
|
1798
|
+
type: "string",
|
|
1799
|
+
required: true,
|
|
1800
|
+
defaultValue: "postgresql://yugabyte:yugabyte@localhost:5433/workflows",
|
|
1801
|
+
placeholder: "postgresql://user:pass@host:5432/database"
|
|
1802
|
+
},
|
|
1803
|
+
{
|
|
1804
|
+
id: "checkpointer",
|
|
1805
|
+
label: "Checkpointer",
|
|
1806
|
+
type: "memory",
|
|
1807
|
+
required: true,
|
|
1808
|
+
typeable: false,
|
|
1809
|
+
handle: {
|
|
1810
|
+
type: "output",
|
|
1811
|
+
label: "Memory",
|
|
1812
|
+
name: "checkpointer",
|
|
1813
|
+
fieldType: "memory"
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
]
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
// src/nodes/memory/postgres/function.ts
|
|
1820
|
+
var import_langgraph_checkpoint_postgres = require("@langchain/langgraph-checkpoint-postgres");
|
|
1821
|
+
var PostgresMemoryNodeFunction = async (inputs) => {
|
|
1822
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
|
|
1823
|
+
const fieldValues = inputs.fieldValues || {};
|
|
1824
|
+
const connectionString = fieldValues.connectionString || inputs.connectionString || "postgresql://postgres:postgres@localhost:5432/workflows";
|
|
1825
|
+
try {
|
|
1826
|
+
const checkpointer = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(connectionString);
|
|
1827
|
+
await checkpointer.setup();
|
|
1828
|
+
console.log("\u2705 PostgresMemory: Checkpointer initialized");
|
|
1829
|
+
return {
|
|
1830
|
+
checkpointer,
|
|
1831
|
+
type: "PostgresMemoryNode",
|
|
1832
|
+
connectionString: connectionString.replace(/:[^:@]+@/, ":***@")
|
|
1833
|
+
// Hide password in output
|
|
1834
|
+
};
|
|
1835
|
+
} catch (error) {
|
|
1836
|
+
console.error("\u274C PostgresMemory: Failed to initialize checkpointer:", error);
|
|
1837
|
+
throw new Error(`PostgresMemory initialization failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
// src/nodes/memory/redis/data.ts
|
|
1842
|
+
var import_zod9 = require("zod");
|
|
1843
|
+
var RedisMemoryNodeSchema = import_zod9.z.object({
|
|
1844
|
+
redisUrl: import_zod9.z.string().describe("Redis connection URL")
|
|
1845
|
+
});
|
|
1846
|
+
var RedisMemoryNode = {
|
|
1847
|
+
label: "Redis Memory",
|
|
1848
|
+
type: "RedisMemoryNode",
|
|
1849
|
+
category: "memory",
|
|
1850
|
+
description: "Fast, persistent conversation memory using Redis (distributed across pods)",
|
|
1851
|
+
icon: "\u{1F534}",
|
|
1852
|
+
group: "Memory",
|
|
1853
|
+
tags: {
|
|
1854
|
+
execution: "sync",
|
|
1855
|
+
group: "Memory"
|
|
1856
|
+
},
|
|
1857
|
+
fields: [
|
|
1858
|
+
{
|
|
1859
|
+
id: "redisUrl",
|
|
1860
|
+
label: "Redis URL",
|
|
1861
|
+
type: "string",
|
|
1862
|
+
required: true,
|
|
1863
|
+
defaultValue: "redis://localhost:6379",
|
|
1864
|
+
placeholder: "redis://localhost:6379"
|
|
1865
|
+
},
|
|
1866
|
+
{
|
|
1867
|
+
id: "checkpointer",
|
|
1868
|
+
label: "Checkpointer",
|
|
1869
|
+
type: "memory",
|
|
1870
|
+
required: true,
|
|
1871
|
+
typeable: false,
|
|
1872
|
+
handle: {
|
|
1873
|
+
type: "output",
|
|
1874
|
+
label: "Memory",
|
|
1875
|
+
name: "checkpointer",
|
|
1876
|
+
fieldType: "memory"
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
]
|
|
1880
|
+
};
|
|
1881
|
+
|
|
1882
|
+
// src/nodes/memory/redis/function.ts
|
|
1883
|
+
var import_langgraph_checkpoint_redis = require("@langchain/langgraph-checkpoint-redis");
|
|
1884
|
+
var RedisMemoryNodeFunction = async (inputs) => {
|
|
1885
|
+
const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
|
|
1886
|
+
const fieldValues = inputs.fieldValues || {};
|
|
1887
|
+
const redisUrl = fieldValues.redisUrl || inputs.redisUrl || "redis://localhost:6379";
|
|
1888
|
+
try {
|
|
1889
|
+
const checkpointer = await import_langgraph_checkpoint_redis.RedisSaver.fromUrl(redisUrl);
|
|
1890
|
+
console.log("\u2705 RedisMemory: Checkpointer initialized");
|
|
1891
|
+
return {
|
|
1892
|
+
checkpointer,
|
|
1893
|
+
type: "RedisMemoryNode",
|
|
1894
|
+
redisUrl: redisUrl.replace(/:[^:@]+@/, ":***@")
|
|
1895
|
+
// Hide password in output
|
|
1896
|
+
};
|
|
1897
|
+
} catch (error) {
|
|
1898
|
+
console.error("\u274C RedisMemory: Failed to initialize checkpointer:", error);
|
|
1899
|
+
throw new Error(`RedisMemory initialization failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
|
|
1528
1903
|
// src/nodes/consts/schemas.ts
|
|
1529
1904
|
var schemas = {
|
|
1530
1905
|
IaAgentNode: IaAgentNodeSchema,
|
|
1531
1906
|
AiSupervisorNode: AiSupervisorNodeSchema,
|
|
1532
1907
|
AiToolNode: AiToolNodeSchema,
|
|
1533
|
-
IaMessageNode: IaMessageNodeSchema
|
|
1908
|
+
IaMessageNode: IaMessageNodeSchema,
|
|
1909
|
+
PostgresMemoryNode: PostgresMemoryNodeSchema,
|
|
1910
|
+
RedisMemoryNode: RedisMemoryNodeSchema
|
|
1534
1911
|
};
|
|
1535
1912
|
|
|
1536
1913
|
// src/nodes/ia/tool/function.ts
|
|
@@ -1572,11 +1949,11 @@ var AiToolNodeFunction = async (params) => {
|
|
|
1572
1949
|
};
|
|
1573
1950
|
|
|
1574
1951
|
// src/nodes/ia/message/message.ts
|
|
1575
|
-
var
|
|
1576
|
-
var IaMessageNodeSchema =
|
|
1577
|
-
model:
|
|
1578
|
-
systemMessage:
|
|
1579
|
-
message:
|
|
1952
|
+
var import_zod10 = require("zod");
|
|
1953
|
+
var IaMessageNodeSchema = import_zod10.z.object({
|
|
1954
|
+
model: import_zod10.z.any().describe("LLM model to use"),
|
|
1955
|
+
systemMessage: import_zod10.z.string().optional().describe("System message for context"),
|
|
1956
|
+
message: import_zod10.z.string().describe("User message to send to the LLM")
|
|
1580
1957
|
});
|
|
1581
1958
|
var IaMessageNodeFunction = async (inputs) => {
|
|
1582
1959
|
const { $field: _$field, $req: _$req, $inputs: _$inputs_var, $vars: _$vars } = inputs;
|
|
@@ -1711,10 +2088,10 @@ var IaMessageNode = {
|
|
|
1711
2088
|
};
|
|
1712
2089
|
|
|
1713
2090
|
// src/nodes/social/whatsapp/send-template/data.ts
|
|
1714
|
-
var
|
|
1715
|
-
var WhatsappSendTemplateNodeSchema =
|
|
1716
|
-
phoneNumber:
|
|
1717
|
-
message:
|
|
2091
|
+
var import_zod11 = require("zod");
|
|
2092
|
+
var WhatsappSendTemplateNodeSchema = import_zod11.z.object({
|
|
2093
|
+
phoneNumber: import_zod11.z.string().describe("Phone number to send the message to"),
|
|
2094
|
+
message: import_zod11.z.string().describe("Message to send")
|
|
1718
2095
|
});
|
|
1719
2096
|
var WhatsappSendTemplateNode = {
|
|
1720
2097
|
label: "Whatsapp Send Template",
|
|
@@ -1755,10 +2132,10 @@ var WhatsappSendTemplateNode = {
|
|
|
1755
2132
|
};
|
|
1756
2133
|
|
|
1757
2134
|
// src/nodes/social/whatsapp/send-message/data.ts
|
|
1758
|
-
var
|
|
1759
|
-
var WhatsappSendMessageNodeSchema =
|
|
1760
|
-
phoneNumber:
|
|
1761
|
-
message:
|
|
2135
|
+
var import_zod12 = require("zod");
|
|
2136
|
+
var WhatsappSendMessageNodeSchema = import_zod12.z.object({
|
|
2137
|
+
phoneNumber: import_zod12.z.string().describe("Phone number to send the message to"),
|
|
2138
|
+
message: import_zod12.z.string().describe("Message content to send")
|
|
1762
2139
|
});
|
|
1763
2140
|
var WhatsappSendMessageNode = {
|
|
1764
2141
|
label: "Whatsapp Send Message",
|
|
@@ -1972,6 +2349,375 @@ var CustomCodeNode = {
|
|
|
1972
2349
|
]
|
|
1973
2350
|
};
|
|
1974
2351
|
|
|
2352
|
+
// src/nodes/guardrails/prompt/data.ts
|
|
2353
|
+
var import_zod13 = require("zod");
|
|
2354
|
+
var PromptGuardrailNodeSchema = import_zod13.z.object({
|
|
2355
|
+
name: import_zod13.z.string().describe("Nome do guardrail"),
|
|
2356
|
+
prompt: import_zod13.z.string().describe("Instru\xE7\xE3o do guardrail")
|
|
2357
|
+
});
|
|
2358
|
+
var PromptGuardrailNode = {
|
|
2359
|
+
label: "Prompt Guardrail",
|
|
2360
|
+
type: "PromptGuardrailNode",
|
|
2361
|
+
category: "step",
|
|
2362
|
+
description: "Injeta instru\xE7\xF5es de seguran\xE7a ou comportamento no sistema do agente",
|
|
2363
|
+
icon: "\u{1F6E1}\uFE0F",
|
|
2364
|
+
group: "Guardrails",
|
|
2365
|
+
tags: {
|
|
2366
|
+
execution: "sync",
|
|
2367
|
+
group: "Guardrails"
|
|
2368
|
+
},
|
|
2369
|
+
fields: [
|
|
2370
|
+
{
|
|
2371
|
+
id: "name",
|
|
2372
|
+
label: "Nome",
|
|
2373
|
+
type: "string",
|
|
2374
|
+
required: true,
|
|
2375
|
+
placeholder: "Ex: Enforce Portuguese"
|
|
2376
|
+
},
|
|
2377
|
+
{
|
|
2378
|
+
id: "prompt",
|
|
2379
|
+
label: "Instru\xE7\xE3o",
|
|
2380
|
+
type: "textarea",
|
|
2381
|
+
required: true,
|
|
2382
|
+
placeholder: "Ex: Sempre responda em portugu\xEAs brasileiro"
|
|
2383
|
+
},
|
|
2384
|
+
{
|
|
2385
|
+
id: "guardrail",
|
|
2386
|
+
label: "Guardrail",
|
|
2387
|
+
type: "guardrail",
|
|
2388
|
+
required: true,
|
|
2389
|
+
typeable: false,
|
|
2390
|
+
handle: {
|
|
2391
|
+
type: "output",
|
|
2392
|
+
label: "Guardrail",
|
|
2393
|
+
name: "guardrail",
|
|
2394
|
+
fieldType: "guardrail"
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
]
|
|
2398
|
+
};
|
|
2399
|
+
|
|
2400
|
+
// src/nodes/guardrails/prompt/function.ts
|
|
2401
|
+
var PromptGuardrailNodeFunction = async (inputs) => {
|
|
2402
|
+
const { fieldValues = {} } = inputs;
|
|
2403
|
+
const { name, prompt } = fieldValues;
|
|
2404
|
+
return {
|
|
2405
|
+
type: "prompt",
|
|
2406
|
+
name: name || "Prompt Guardrail",
|
|
2407
|
+
prompt: prompt || ""
|
|
2408
|
+
};
|
|
2409
|
+
};
|
|
2410
|
+
|
|
2411
|
+
// src/nodes/guardrails/rule/data.ts
|
|
2412
|
+
var import_zod14 = require("zod");
|
|
2413
|
+
var RuleGuardrailNodeSchema = import_zod14.z.object({
|
|
2414
|
+
name: import_zod14.z.string().describe("Nome do guardrail"),
|
|
2415
|
+
phase: import_zod14.z.enum(["before", "after"]).describe("Fase de execu\xE7\xE3o"),
|
|
2416
|
+
ruleType: import_zod14.z.enum(["maxValue", "minValue", "regex", "keywords", "pii"]).describe("Tipo de regra"),
|
|
2417
|
+
config: import_zod14.z.any().describe("Configura\xE7\xE3o da regra"),
|
|
2418
|
+
action: import_zod14.z.enum(["block", "warn", "modify"]).describe("A\xE7\xE3o em caso de viola\xE7\xE3o")
|
|
2419
|
+
});
|
|
2420
|
+
var RuleGuardrailNode = {
|
|
2421
|
+
label: "Rule Guardrail",
|
|
2422
|
+
type: "RuleGuardrailNode",
|
|
2423
|
+
category: "step",
|
|
2424
|
+
description: "Valida\xE7\xF5es determin\xEDsticas baseadas em regras (limites, palavras-chave, regex)",
|
|
2425
|
+
icon: "\u2696\uFE0F",
|
|
2426
|
+
group: "Guardrails",
|
|
2427
|
+
tags: {
|
|
2428
|
+
execution: "sync",
|
|
2429
|
+
group: "Guardrails"
|
|
2430
|
+
},
|
|
2431
|
+
fields: [
|
|
2432
|
+
{
|
|
2433
|
+
id: "name",
|
|
2434
|
+
label: "Nome",
|
|
2435
|
+
type: "string",
|
|
2436
|
+
required: true,
|
|
2437
|
+
placeholder: "Ex: Limit Discount"
|
|
2438
|
+
},
|
|
2439
|
+
{
|
|
2440
|
+
id: "phase",
|
|
2441
|
+
label: "Fase",
|
|
2442
|
+
type: "select",
|
|
2443
|
+
required: true,
|
|
2444
|
+
defaultValue: "after",
|
|
2445
|
+
options: [
|
|
2446
|
+
{ label: "Antes do Agente (Input)", value: "before" },
|
|
2447
|
+
{ label: "Depois do Agente (Output)", value: "after" }
|
|
2448
|
+
]
|
|
2449
|
+
},
|
|
2450
|
+
{
|
|
2451
|
+
id: "ruleType",
|
|
2452
|
+
label: "Tipo de Regra",
|
|
2453
|
+
type: "select",
|
|
2454
|
+
required: true,
|
|
2455
|
+
options: [
|
|
2456
|
+
{ label: "Valor M\xE1ximo", value: "maxValue" },
|
|
2457
|
+
{ label: "Valor M\xEDnimo", value: "minValue" },
|
|
2458
|
+
{ label: "Express\xE3o Regular (Regex)", value: "regex" },
|
|
2459
|
+
{ label: "Palavras-chave (Keywords)", value: "keywords" },
|
|
2460
|
+
{ label: "Dados Sens\xEDveis (PII)", value: "pii" }
|
|
2461
|
+
]
|
|
2462
|
+
},
|
|
2463
|
+
{
|
|
2464
|
+
id: "config",
|
|
2465
|
+
label: "Configura\xE7\xE3o",
|
|
2466
|
+
type: "string",
|
|
2467
|
+
required: true,
|
|
2468
|
+
placeholder: "Ex: 15 (para valor) ou ofensivo,hack (para keywords)"
|
|
2469
|
+
},
|
|
2470
|
+
{
|
|
2471
|
+
id: "action",
|
|
2472
|
+
label: "A\xE7\xE3o em Viola\xE7\xE3o",
|
|
2473
|
+
type: "select",
|
|
2474
|
+
required: true,
|
|
2475
|
+
defaultValue: "block",
|
|
2476
|
+
options: [
|
|
2477
|
+
{ label: "Bloquear Resposta", value: "block" },
|
|
2478
|
+
{ label: "Avisar (Warning)", value: "warn" },
|
|
2479
|
+
{ label: "Modificar/Ocultar", value: "modify" }
|
|
2480
|
+
]
|
|
2481
|
+
},
|
|
2482
|
+
{
|
|
2483
|
+
id: "guardrail",
|
|
2484
|
+
label: "Guardrail",
|
|
2485
|
+
type: "guardrail",
|
|
2486
|
+
required: true,
|
|
2487
|
+
typeable: false,
|
|
2488
|
+
handle: {
|
|
2489
|
+
type: "output",
|
|
2490
|
+
label: "Guardrail",
|
|
2491
|
+
name: "guardrail",
|
|
2492
|
+
fieldType: "guardrail"
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
]
|
|
2496
|
+
};
|
|
2497
|
+
|
|
2498
|
+
// src/nodes/guardrails/rule/function.ts
|
|
2499
|
+
var RuleGuardrailNodeFunction = async (inputs) => {
|
|
2500
|
+
const { fieldValues = {} } = inputs;
|
|
2501
|
+
const { name, phase, ruleType, config, action } = fieldValues;
|
|
2502
|
+
return {
|
|
2503
|
+
type: "rule",
|
|
2504
|
+
name: name || "Rule Guardrail",
|
|
2505
|
+
phase: phase || "after",
|
|
2506
|
+
ruleType: ruleType || "keywords",
|
|
2507
|
+
config: config || "",
|
|
2508
|
+
action: action || "block"
|
|
2509
|
+
};
|
|
2510
|
+
};
|
|
2511
|
+
|
|
2512
|
+
// src/nodes/guardrails/function/data.ts
|
|
2513
|
+
var import_zod15 = require("zod");
|
|
2514
|
+
var FunctionGuardrailNodeSchema = import_zod15.z.object({
|
|
2515
|
+
name: import_zod15.z.string().describe("Nome do guardrail"),
|
|
2516
|
+
phase: import_zod15.z.enum(["before", "after"]).describe("Fase de execu\xE7\xE3o"),
|
|
2517
|
+
description: import_zod15.z.string().optional().describe("Descri\xE7\xE3o do que a fun\xE7\xE3o valida"),
|
|
2518
|
+
action: import_zod15.z.enum(["block", "warn", "modify", "escalate"]).describe("A\xE7\xE3o em caso de viola\xE7\xE3o")
|
|
2519
|
+
});
|
|
2520
|
+
var FunctionGuardrailNode = {
|
|
2521
|
+
label: "Function Guardrail",
|
|
2522
|
+
type: "FunctionGuardrailNode",
|
|
2523
|
+
category: "step",
|
|
2524
|
+
description: "Executa uma fun\xE7\xE3o customizada (Custom Code ou HTTP) para validar entrada/sa\xEDda",
|
|
2525
|
+
icon: "\u{1F9E9}",
|
|
2526
|
+
group: "Guardrails",
|
|
2527
|
+
tags: {
|
|
2528
|
+
execution: "async",
|
|
2529
|
+
group: "Guardrails"
|
|
2530
|
+
},
|
|
2531
|
+
fields: [
|
|
2532
|
+
{
|
|
2533
|
+
id: "name",
|
|
2534
|
+
label: "Nome",
|
|
2535
|
+
type: "string",
|
|
2536
|
+
required: true,
|
|
2537
|
+
placeholder: "Ex: Validar Desconto API"
|
|
2538
|
+
},
|
|
2539
|
+
{
|
|
2540
|
+
id: "phase",
|
|
2541
|
+
label: "Fase",
|
|
2542
|
+
type: "select",
|
|
2543
|
+
required: true,
|
|
2544
|
+
defaultValue: "after",
|
|
2545
|
+
options: [
|
|
2546
|
+
{ label: "Antes do Agente (Input)", value: "before" },
|
|
2547
|
+
{ label: "Depois do Agente (Output)", value: "after" }
|
|
2548
|
+
]
|
|
2549
|
+
},
|
|
2550
|
+
{
|
|
2551
|
+
id: "description",
|
|
2552
|
+
label: "Descri\xE7\xE3o",
|
|
2553
|
+
type: "textarea",
|
|
2554
|
+
required: false,
|
|
2555
|
+
placeholder: "Descreva o que este guardrail valida..."
|
|
2556
|
+
},
|
|
2557
|
+
{
|
|
2558
|
+
id: "function",
|
|
2559
|
+
label: "Fun\xE7\xE3o",
|
|
2560
|
+
type: "function",
|
|
2561
|
+
required: true,
|
|
2562
|
+
typeable: false,
|
|
2563
|
+
handle: {
|
|
2564
|
+
type: "input",
|
|
2565
|
+
label: "Fun\xE7\xE3o",
|
|
2566
|
+
name: "function",
|
|
2567
|
+
fieldType: "function",
|
|
2568
|
+
acceptTypes: ["code", "http", "any"],
|
|
2569
|
+
maxConnections: 1
|
|
2570
|
+
}
|
|
2571
|
+
},
|
|
2572
|
+
{
|
|
2573
|
+
id: "action",
|
|
2574
|
+
label: "A\xE7\xE3o em Viola\xE7\xE3o",
|
|
2575
|
+
type: "select",
|
|
2576
|
+
required: true,
|
|
2577
|
+
defaultValue: "block",
|
|
2578
|
+
options: [
|
|
2579
|
+
{ label: "Bloquear", value: "block" },
|
|
2580
|
+
{ label: "Avisar (Warning)", value: "warn" },
|
|
2581
|
+
{ label: "Modificar", value: "modify" },
|
|
2582
|
+
{ label: "Escalar (Human-in-the-loop)", value: "escalate" }
|
|
2583
|
+
]
|
|
2584
|
+
},
|
|
2585
|
+
{
|
|
2586
|
+
id: "guardrail",
|
|
2587
|
+
label: "Guardrail",
|
|
2588
|
+
type: "guardrail",
|
|
2589
|
+
required: true,
|
|
2590
|
+
typeable: false,
|
|
2591
|
+
handle: {
|
|
2592
|
+
type: "output",
|
|
2593
|
+
label: "Guardrail",
|
|
2594
|
+
name: "guardrail",
|
|
2595
|
+
fieldType: "guardrail"
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
]
|
|
2599
|
+
};
|
|
2600
|
+
|
|
2601
|
+
// src/nodes/guardrails/function/function.ts
|
|
2602
|
+
var FunctionGuardrailNodeFunction = async (inputs) => {
|
|
2603
|
+
const { fieldValues = {} } = inputs;
|
|
2604
|
+
const {
|
|
2605
|
+
name,
|
|
2606
|
+
phase,
|
|
2607
|
+
description,
|
|
2608
|
+
action,
|
|
2609
|
+
nodeFunction,
|
|
2610
|
+
nodeType,
|
|
2611
|
+
originalNodeData
|
|
2612
|
+
} = fieldValues;
|
|
2613
|
+
return {
|
|
2614
|
+
type: "function",
|
|
2615
|
+
name: name || "Function Guardrail",
|
|
2616
|
+
phase: phase || "after",
|
|
2617
|
+
description: description || "",
|
|
2618
|
+
action: action || "block",
|
|
2619
|
+
// Injected by executeWorkflow.ts
|
|
2620
|
+
nodeFunction,
|
|
2621
|
+
nodeType,
|
|
2622
|
+
originalNodeData
|
|
2623
|
+
};
|
|
2624
|
+
};
|
|
2625
|
+
|
|
2626
|
+
// src/nodes/guardrails/model/data.ts
|
|
2627
|
+
var import_zod16 = require("zod");
|
|
2628
|
+
var ModelGuardrailNodeSchema = import_zod16.z.object({
|
|
2629
|
+
name: import_zod16.z.string().describe("Nome do guardrail"),
|
|
2630
|
+
evaluationPrompt: import_zod16.z.string().describe("Prompt de avalia\xE7\xE3o"),
|
|
2631
|
+
model: import_zod16.z.any().describe("Modelo LLM para avalia\xE7\xE3o"),
|
|
2632
|
+
action: import_zod16.z.enum(["block", "warn", "escalate"]).describe("A\xE7\xE3o em caso de viola\xE7\xE3o")
|
|
2633
|
+
});
|
|
2634
|
+
var ModelGuardrailNode = {
|
|
2635
|
+
label: "Model Guardrail",
|
|
2636
|
+
type: "ModelGuardrailNode",
|
|
2637
|
+
category: "step",
|
|
2638
|
+
description: "Usa um modelo de IA secund\xE1rio para avaliar a seguran\xE7a ou qualidade do conte\xFAdo",
|
|
2639
|
+
icon: "\u{1F9E0}\u{1F6E1}\uFE0F",
|
|
2640
|
+
group: "Guardrails",
|
|
2641
|
+
tags: {
|
|
2642
|
+
execution: "async",
|
|
2643
|
+
group: "Guardrails"
|
|
2644
|
+
},
|
|
2645
|
+
fields: [
|
|
2646
|
+
{
|
|
2647
|
+
id: "name",
|
|
2648
|
+
label: "Nome",
|
|
2649
|
+
type: "string",
|
|
2650
|
+
required: true,
|
|
2651
|
+
placeholder: "Ex: Safety Check"
|
|
2652
|
+
},
|
|
2653
|
+
{
|
|
2654
|
+
id: "evaluationPrompt",
|
|
2655
|
+
label: "Prompt de Avalia\xE7\xE3o",
|
|
2656
|
+
type: "textarea",
|
|
2657
|
+
required: true,
|
|
2658
|
+
placeholder: "Ex: Avalie se a resposta abaixo cont\xE9m discurso de \xF3dio ou ofensas. Responda apenas SAFE ou UNSAFE.",
|
|
2659
|
+
defaultValue: "Analise se o conte\xFAdo a seguir \xE9 apropriado, seguro e segue as pol\xEDticas de \xE9tica. Responda 'SAFE' se estiver tudo bem ou 'UNSAFE' caso contr\xE1rio.\n\nCONTE\xDADO:\n{{content}}"
|
|
2660
|
+
},
|
|
2661
|
+
{
|
|
2662
|
+
id: "model",
|
|
2663
|
+
label: "Modelo de Avalia\xE7\xE3o",
|
|
2664
|
+
type: "model",
|
|
2665
|
+
required: true,
|
|
2666
|
+
handle: {
|
|
2667
|
+
type: "input",
|
|
2668
|
+
label: "Modelo",
|
|
2669
|
+
name: "model",
|
|
2670
|
+
fieldType: "model",
|
|
2671
|
+
acceptTypes: ["model"],
|
|
2672
|
+
maxConnections: 1
|
|
2673
|
+
}
|
|
2674
|
+
},
|
|
2675
|
+
{
|
|
2676
|
+
id: "action",
|
|
2677
|
+
label: "A\xE7\xE3o em Viola\xE7\xE3o (UNSAFE)",
|
|
2678
|
+
type: "select",
|
|
2679
|
+
required: true,
|
|
2680
|
+
defaultValue: "block",
|
|
2681
|
+
options: [
|
|
2682
|
+
{ label: "Bloquear Resposta", value: "block" },
|
|
2683
|
+
{ label: "Avisar (Warning)", value: "warn" },
|
|
2684
|
+
{ label: "Escalar (Human-in-the-loop)", value: "escalate" }
|
|
2685
|
+
]
|
|
2686
|
+
},
|
|
2687
|
+
{
|
|
2688
|
+
id: "guardrail",
|
|
2689
|
+
label: "Guardrail",
|
|
2690
|
+
type: "guardrail",
|
|
2691
|
+
required: true,
|
|
2692
|
+
typeable: false,
|
|
2693
|
+
handle: {
|
|
2694
|
+
type: "output",
|
|
2695
|
+
label: "Guardrail",
|
|
2696
|
+
name: "guardrail",
|
|
2697
|
+
fieldType: "guardrail"
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
]
|
|
2701
|
+
};
|
|
2702
|
+
|
|
2703
|
+
// src/nodes/guardrails/model/function.ts
|
|
2704
|
+
var ModelGuardrailNodeFunction = async (inputs) => {
|
|
2705
|
+
const { fieldValues = {} } = inputs;
|
|
2706
|
+
const {
|
|
2707
|
+
name,
|
|
2708
|
+
evaluationPrompt,
|
|
2709
|
+
model,
|
|
2710
|
+
action
|
|
2711
|
+
} = fieldValues;
|
|
2712
|
+
return {
|
|
2713
|
+
type: "model",
|
|
2714
|
+
name: name || "Model Guardrail",
|
|
2715
|
+
evaluationPrompt: evaluationPrompt || "Avalie se este conte\xFAdo \xE9 seguro. Responda apenas SAFE ou UNSAFE.",
|
|
2716
|
+
model,
|
|
2717
|
+
action: action || "block"
|
|
2718
|
+
};
|
|
2719
|
+
};
|
|
2720
|
+
|
|
1975
2721
|
// src/nodes/consts/nodes.ts
|
|
1976
2722
|
var nodes = [
|
|
1977
2723
|
ChatInputNode,
|
|
@@ -1989,10 +2735,16 @@ var nodes = [
|
|
|
1989
2735
|
IaAgentNode,
|
|
1990
2736
|
AiToolNode,
|
|
1991
2737
|
AiSupervisorNode,
|
|
2738
|
+
PostgresMemoryNode,
|
|
2739
|
+
RedisMemoryNode,
|
|
1992
2740
|
WhatsappSendTemplateNode,
|
|
1993
2741
|
WhatsappSendMessageNode,
|
|
1994
2742
|
WhatsappMessageTriggerNode,
|
|
1995
|
-
CustomCodeNode
|
|
2743
|
+
CustomCodeNode,
|
|
2744
|
+
PromptGuardrailNode,
|
|
2745
|
+
RuleGuardrailNode,
|
|
2746
|
+
FunctionGuardrailNode,
|
|
2747
|
+
ModelGuardrailNode
|
|
1996
2748
|
];
|
|
1997
2749
|
var nodes_default = nodes;
|
|
1998
2750
|
|
|
@@ -2108,7 +2860,13 @@ var nodeFunctions = {
|
|
|
2108
2860
|
WhatsappNode: WhatsappStartChatFunction,
|
|
2109
2861
|
WhatsappSendMessageNode: WhatsappSendMessageFunction,
|
|
2110
2862
|
CustomCodeNode: NodeFunction,
|
|
2111
|
-
CustomNode: CustomNodeFunction
|
|
2863
|
+
CustomNode: CustomNodeFunction,
|
|
2864
|
+
PostgresMemoryNode: PostgresMemoryNodeFunction,
|
|
2865
|
+
RedisMemoryNode: RedisMemoryNodeFunction,
|
|
2866
|
+
PromptGuardrailNode: PromptGuardrailNodeFunction,
|
|
2867
|
+
RuleGuardrailNode: RuleGuardrailNodeFunction,
|
|
2868
|
+
FunctionGuardrailNode: FunctionGuardrailNodeFunction,
|
|
2869
|
+
ModelGuardrailNode: ModelGuardrailNodeFunction
|
|
2112
2870
|
};
|
|
2113
2871
|
var node_functions_default = nodeFunctions;
|
|
2114
2872
|
|
|
@@ -2222,12 +2980,12 @@ var HttpPutInputNodeFunction = (params) => {
|
|
|
2222
2980
|
};
|
|
2223
2981
|
|
|
2224
2982
|
// src/nodes/inputs/http/put/schema.ts
|
|
2225
|
-
var
|
|
2226
|
-
var HttpPutInputNodeSchema =
|
|
2983
|
+
var import_zod17 = require("zod");
|
|
2984
|
+
var HttpPutInputNodeSchema = import_zod17.z.object({
|
|
2227
2985
|
route: RouteSchema,
|
|
2228
|
-
queryParams:
|
|
2229
|
-
headers:
|
|
2230
|
-
body:
|
|
2986
|
+
queryParams: import_zod17.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
|
|
2987
|
+
headers: import_zod17.z.array(HeaderSchema).optional().describe("Headers configuration"),
|
|
2988
|
+
body: import_zod17.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
|
|
2231
2989
|
});
|
|
2232
2990
|
|
|
2233
2991
|
// src/nodes/inputs/http/delete/data.ts
|
|
@@ -2319,11 +3077,11 @@ var HttpDeleteInputNodeFunction = async (params) => {
|
|
|
2319
3077
|
};
|
|
2320
3078
|
|
|
2321
3079
|
// src/nodes/inputs/http/delete/schema.ts
|
|
2322
|
-
var
|
|
2323
|
-
var HttpDeleteInputNodeSchema =
|
|
3080
|
+
var import_zod18 = require("zod");
|
|
3081
|
+
var HttpDeleteInputNodeSchema = import_zod18.z.object({
|
|
2324
3082
|
route: RouteSchema,
|
|
2325
|
-
queryParams:
|
|
2326
|
-
headers:
|
|
3083
|
+
queryParams: import_zod18.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
|
|
3084
|
+
headers: import_zod18.z.array(HeaderSchema).optional().describe("Headers configuration")
|
|
2327
3085
|
});
|
|
2328
3086
|
|
|
2329
3087
|
// src/nodes/inputs/http/patch/data.ts
|
|
@@ -2436,12 +3194,12 @@ var HttpPatchInputNodeFunction = (params) => {
|
|
|
2436
3194
|
};
|
|
2437
3195
|
|
|
2438
3196
|
// src/nodes/inputs/http/patch/schema.ts
|
|
2439
|
-
var
|
|
2440
|
-
var HttpPatchInputNodeSchema =
|
|
3197
|
+
var import_zod19 = require("zod");
|
|
3198
|
+
var HttpPatchInputNodeSchema = import_zod19.z.object({
|
|
2441
3199
|
route: RouteSchema,
|
|
2442
|
-
queryParams:
|
|
2443
|
-
headers:
|
|
2444
|
-
body:
|
|
3200
|
+
queryParams: import_zod19.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
|
|
3201
|
+
headers: import_zod19.z.array(HeaderSchema).optional().describe("Headers configuration"),
|
|
3202
|
+
body: import_zod19.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
|
|
2445
3203
|
});
|
|
2446
3204
|
|
|
2447
3205
|
// src/nodes/inputs/http/utils.ts
|