@atomoz/workflows-nodes 0.1.20 → 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 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
@@ -1007,6 +997,47 @@ var IaAgentNode = {
1007
997
  name: "response",
1008
998
  fieldType: "string"
1009
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
+ ]
1010
1041
  }
1011
1042
  ]
1012
1043
  };
@@ -1046,7 +1077,7 @@ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
1046
1077
  case "gemini":
1047
1078
  return new import_google_gauth.ChatGoogle({
1048
1079
  model: "gemini-flash-latest",
1049
- apiKey: "AIzaSyAWS9GhesWxG4uTdJRQbBziMB1diXtXtlI",
1080
+ apiKey: "AIzaSyD9WiFuXp2fhVAokIMPp9YPKMlh7_Bvddc",
1050
1081
  streaming
1051
1082
  });
1052
1083
  case "openai":
@@ -1071,22 +1102,165 @@ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
1071
1102
  }
1072
1103
  }
1073
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
+
1074
1219
  // src/nodes/ia/agent/function.ts
1075
1220
  var IaAgentNodeFunction = async (inputs) => {
1076
1221
  const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
1077
1222
  const fieldValues = inputs.fieldValues || {};
1078
- const { model, tools, systemMessage, name, message } = fieldValues;
1223
+ const { model, tools, systemMessage, name, message, beforeGuardrails, afterGuardrails, guardrailMode } = fieldValues;
1079
1224
  const authToken = inputs.authToken;
1080
1225
  const stream = Boolean(inputs?.stream);
1081
1226
  const emitter = inputs?.emitter;
1082
1227
  const sessionMemory = fieldValues.sessionMemory || inputs.sessionMemory;
1083
- const checkpointer = sessionMemory?.checkpointer;
1228
+ const checkpointer = sessionMemory && typeof sessionMemory.put === "function" ? sessionMemory : sessionMemory?.checkpointer;
1084
1229
  const sessionId = inputs.sessionId || inputs.$req?.sessionId || `session-${Date.now()}`;
1085
1230
  if (!name) {
1086
1231
  throw new Error("Agent 'name' is required. Please provide a unique name for the agent in the node properties.");
1087
1232
  }
1088
- if (!model) {
1089
- throw new Error("Model is required for IaAgentNode");
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
+ }
1090
1264
  }
1091
1265
  let toolsArray = [];
1092
1266
  if (Array.isArray(tools)) {
@@ -1094,9 +1268,15 @@ var IaAgentNodeFunction = async (inputs) => {
1094
1268
  } else if (tools) {
1095
1269
  toolsArray = [tools];
1096
1270
  }
1097
- const finalSystemMessageContent = `${systemMessage || ""}
1271
+ let finalSystemMessageContent = `${systemMessage || ""}
1098
1272
 
1099
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
+ }
1100
1280
  const finalSystemMessage = new import_messages.SystemMessage(finalSystemMessageContent);
1101
1281
  let llmInstance;
1102
1282
  if (model?.integrationId) {
@@ -1125,11 +1305,10 @@ IMPORTANT: You must base your response on the last message in the conversation h
1125
1305
  let output = "";
1126
1306
  if (message) {
1127
1307
  try {
1128
- const { HumanMessage: HumanMessage2 } = await import("@langchain/core/messages");
1129
1308
  const invokeConfig = checkpointer ? { configurable: { thread_id: sessionId } } : {};
1130
1309
  if (stream && emitter) {
1131
1310
  const streamIterator = await agent.stream(
1132
- { messages: [new HumanMessage2(message)] },
1311
+ { messages: [new import_messages.HumanMessage(message)] },
1133
1312
  invokeConfig
1134
1313
  );
1135
1314
  let lastMessages = [];
@@ -1176,7 +1355,7 @@ IMPORTANT: You must base your response on the last message in the conversation h
1176
1355
  }
1177
1356
  } else {
1178
1357
  const result = await agent.invoke(
1179
- { messages: [new HumanMessage2(message)] },
1358
+ { messages: [new import_messages.HumanMessage(message)] },
1180
1359
  invokeConfig
1181
1360
  );
1182
1361
  if (result?.messages && result.messages.length > 0) {
@@ -1195,6 +1374,26 @@ IMPORTANT: You must base your response on the last message in the conversation h
1195
1374
  }
1196
1375
  }
1197
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
+ }
1198
1397
  } catch (error) {
1199
1398
  console.error("Error processing message in agent:", error);
1200
1399
  output = `Error: ${error instanceof Error ? error.message : "Unknown error"}`;
@@ -1598,7 +1797,7 @@ var PostgresMemoryNode = {
1598
1797
  label: "Connection String",
1599
1798
  type: "string",
1600
1799
  required: true,
1601
- defaultValue: "postgresql://postgres:postgres@localhost:5432/workflows",
1800
+ defaultValue: "postgresql://yugabyte:yugabyte@localhost:5433/workflows",
1602
1801
  placeholder: "postgresql://user:pass@host:5432/database"
1603
1802
  },
1604
1803
  {
@@ -2150,6 +2349,375 @@ var CustomCodeNode = {
2150
2349
  ]
2151
2350
  };
2152
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
+
2153
2721
  // src/nodes/consts/nodes.ts
2154
2722
  var nodes = [
2155
2723
  ChatInputNode,
@@ -2172,7 +2740,11 @@ var nodes = [
2172
2740
  WhatsappSendTemplateNode,
2173
2741
  WhatsappSendMessageNode,
2174
2742
  WhatsappMessageTriggerNode,
2175
- CustomCodeNode
2743
+ CustomCodeNode,
2744
+ PromptGuardrailNode,
2745
+ RuleGuardrailNode,
2746
+ FunctionGuardrailNode,
2747
+ ModelGuardrailNode
2176
2748
  ];
2177
2749
  var nodes_default = nodes;
2178
2750
 
@@ -2290,7 +2862,11 @@ var nodeFunctions = {
2290
2862
  CustomCodeNode: NodeFunction,
2291
2863
  CustomNode: CustomNodeFunction,
2292
2864
  PostgresMemoryNode: PostgresMemoryNodeFunction,
2293
- RedisMemoryNode: RedisMemoryNodeFunction
2865
+ RedisMemoryNode: RedisMemoryNodeFunction,
2866
+ PromptGuardrailNode: PromptGuardrailNodeFunction,
2867
+ RuleGuardrailNode: RuleGuardrailNodeFunction,
2868
+ FunctionGuardrailNode: FunctionGuardrailNodeFunction,
2869
+ ModelGuardrailNode: ModelGuardrailNodeFunction
2294
2870
  };
2295
2871
  var node_functions_default = nodeFunctions;
2296
2872
 
@@ -2404,12 +2980,12 @@ var HttpPutInputNodeFunction = (params) => {
2404
2980
  };
2405
2981
 
2406
2982
  // src/nodes/inputs/http/put/schema.ts
2407
- var import_zod13 = require("zod");
2408
- var HttpPutInputNodeSchema = import_zod13.z.object({
2983
+ var import_zod17 = require("zod");
2984
+ var HttpPutInputNodeSchema = import_zod17.z.object({
2409
2985
  route: RouteSchema,
2410
- queryParams: import_zod13.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2411
- headers: import_zod13.z.array(HeaderSchema).optional().describe("Headers configuration"),
2412
- body: import_zod13.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
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")
2413
2989
  });
2414
2990
 
2415
2991
  // src/nodes/inputs/http/delete/data.ts
@@ -2501,11 +3077,11 @@ var HttpDeleteInputNodeFunction = async (params) => {
2501
3077
  };
2502
3078
 
2503
3079
  // src/nodes/inputs/http/delete/schema.ts
2504
- var import_zod14 = require("zod");
2505
- var HttpDeleteInputNodeSchema = import_zod14.z.object({
3080
+ var import_zod18 = require("zod");
3081
+ var HttpDeleteInputNodeSchema = import_zod18.z.object({
2506
3082
  route: RouteSchema,
2507
- queryParams: import_zod14.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2508
- headers: import_zod14.z.array(HeaderSchema).optional().describe("Headers configuration")
3083
+ queryParams: import_zod18.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
3084
+ headers: import_zod18.z.array(HeaderSchema).optional().describe("Headers configuration")
2509
3085
  });
2510
3086
 
2511
3087
  // src/nodes/inputs/http/patch/data.ts
@@ -2618,12 +3194,12 @@ var HttpPatchInputNodeFunction = (params) => {
2618
3194
  };
2619
3195
 
2620
3196
  // src/nodes/inputs/http/patch/schema.ts
2621
- var import_zod15 = require("zod");
2622
- var HttpPatchInputNodeSchema = import_zod15.z.object({
3197
+ var import_zod19 = require("zod");
3198
+ var HttpPatchInputNodeSchema = import_zod19.z.object({
2623
3199
  route: RouteSchema,
2624
- queryParams: import_zod15.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2625
- headers: import_zod15.z.array(HeaderSchema).optional().describe("Headers configuration"),
2626
- body: import_zod15.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
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")
2627
3203
  });
2628
3204
 
2629
3205
  // src/nodes/inputs/http/utils.ts