@atomoz/workflows-nodes 0.1.19 → 0.1.20

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
@@ -980,6 +980,21 @@ var IaAgentNode = {
980
980
  fieldType: "agent"
981
981
  }
982
982
  },
983
+ {
984
+ id: "sessionMemory",
985
+ label: "Session Memory",
986
+ type: "memory",
987
+ required: false,
988
+ typeable: false,
989
+ handle: {
990
+ type: "input",
991
+ label: "Session Memory",
992
+ name: "sessionMemory",
993
+ fieldType: "memory",
994
+ acceptTypes: ["memory"],
995
+ maxConnections: 1
996
+ }
997
+ },
983
998
  {
984
999
  id: "response",
985
1000
  label: "Response",
@@ -1059,10 +1074,14 @@ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
1059
1074
  // src/nodes/ia/agent/function.ts
1060
1075
  var IaAgentNodeFunction = async (inputs) => {
1061
1076
  const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
1062
- const { model, tools, systemMessage, name, message } = inputs.fieldValues || {};
1077
+ const fieldValues = inputs.fieldValues || {};
1078
+ const { model, tools, systemMessage, name, message } = fieldValues;
1063
1079
  const authToken = inputs.authToken;
1064
1080
  const stream = Boolean(inputs?.stream);
1065
1081
  const emitter = inputs?.emitter;
1082
+ const sessionMemory = fieldValues.sessionMemory || inputs.sessionMemory;
1083
+ const checkpointer = sessionMemory?.checkpointer;
1084
+ const sessionId = inputs.sessionId || inputs.$req?.sessionId || `session-${Date.now()}`;
1066
1085
  if (!name) {
1067
1086
  throw new Error("Agent 'name' is required. Please provide a unique name for the agent in the node properties.");
1068
1087
  }
@@ -1093,17 +1112,26 @@ IMPORTANT: You must base your response on the last message in the conversation h
1093
1112
  const agent = (0, import_prebuilt.createReactAgent)({
1094
1113
  llm: llmInstance,
1095
1114
  tools: toolsArray,
1096
- messageModifier: finalSystemMessage
1115
+ messageModifier: finalSystemMessage,
1116
+ // Pass checkpointer directly for distributed memory
1117
+ ...checkpointer ? { checkpointer } : {}
1097
1118
  });
1098
1119
  agent.name = name;
1120
+ if (checkpointer) {
1121
+ console.log(`\u{1F9E0} IaAgentNode "${name}": Using distributed memory (sessionId: ${sessionId})`);
1122
+ } else {
1123
+ console.log(`\u26A0\uFE0F IaAgentNode "${name}": No sessionMemory connected - stateless mode`);
1124
+ }
1099
1125
  let output = "";
1100
1126
  if (message) {
1101
1127
  try {
1102
1128
  const { HumanMessage: HumanMessage2 } = await import("@langchain/core/messages");
1129
+ const invokeConfig = checkpointer ? { configurable: { thread_id: sessionId } } : {};
1103
1130
  if (stream && emitter) {
1104
- const streamIterator = await agent.stream({
1105
- messages: [new HumanMessage2(message)]
1106
- });
1131
+ const streamIterator = await agent.stream(
1132
+ { messages: [new HumanMessage2(message)] },
1133
+ invokeConfig
1134
+ );
1107
1135
  let lastMessages = [];
1108
1136
  const sentContents = /* @__PURE__ */ new Set();
1109
1137
  for await (const step of streamIterator) {
@@ -1147,9 +1175,10 @@ IMPORTANT: You must base your response on the last message in the conversation h
1147
1175
  }
1148
1176
  }
1149
1177
  } else {
1150
- const result = await agent.invoke({
1151
- messages: [new HumanMessage2(message)]
1152
- });
1178
+ const result = await agent.invoke(
1179
+ { messages: [new HumanMessage2(message)] },
1180
+ invokeConfig
1181
+ );
1153
1182
  if (result?.messages && result.messages.length > 0) {
1154
1183
  const lastMessage = result.messages[result.messages.length - 1];
1155
1184
  const content = lastMessage?.content;
@@ -1247,6 +1276,21 @@ var AiSupervisorNode = {
1247
1276
  acceptTypes: ["agent"]
1248
1277
  }
1249
1278
  },
1279
+ {
1280
+ id: "sessionMemory",
1281
+ label: "Session Memory",
1282
+ type: "memory",
1283
+ required: false,
1284
+ typeable: false,
1285
+ handle: {
1286
+ type: "input",
1287
+ label: "Session Memory",
1288
+ name: "sessionMemory",
1289
+ fieldType: "memory",
1290
+ acceptTypes: ["memory"],
1291
+ maxConnections: 1
1292
+ }
1293
+ },
1250
1294
  {
1251
1295
  id: "response",
1252
1296
  label: "Response",
@@ -1267,7 +1311,6 @@ var AiSupervisorNode = {
1267
1311
  var import_langgraph_supervisor = require("@langchain/langgraph-supervisor");
1268
1312
  var import_messages2 = require("@langchain/core/messages");
1269
1313
  var import_langgraph = require("@langchain/langgraph");
1270
- var checkpointer = new import_langgraph.MemorySaver();
1271
1314
  var store = new import_langgraph.InMemoryStore();
1272
1315
  var extractSupervisorAgents = (agents) => {
1273
1316
  if (Array.isArray(agents)) {
@@ -1323,6 +1366,9 @@ var AiSupervisorNodeFunction = async (params) => {
1323
1366
  const stream = (typeof outer.stream === "boolean" ? outer.stream : inner.stream) ?? false;
1324
1367
  const emitter = outer.emitter ?? inner.emitter;
1325
1368
  const authToken = outer.authToken ?? inner.authToken;
1369
+ const sessionMemory = inner.sessionMemory ?? outer.sessionMemory;
1370
+ const checkpointer = sessionMemory?.checkpointer;
1371
+ const sessionId = outer.sessionId || outer.$req?.sessionId || `supervisor-${Date.now()}`;
1326
1372
  if (!model) throw new Error("Model is required for AiSupervisorNode");
1327
1373
  if (!agents) throw new Error("Agents are required for AiSupervisorNode.");
1328
1374
  try {
@@ -1332,12 +1378,17 @@ var AiSupervisorNodeFunction = async (params) => {
1332
1378
  let llmInstance;
1333
1379
  if (model?.model && model?.integrationId) {
1334
1380
  if (!authToken) {
1335
- throw new Error("Auth token is required to instantiate LLM from integration 3");
1381
+ throw new Error("Auth token is required to instantiate LLM from integration");
1336
1382
  }
1337
1383
  llmInstance = await createLLMFromModel(model, authToken, stream);
1338
1384
  } else {
1339
1385
  llmInstance = model;
1340
1386
  }
1387
+ if (checkpointer) {
1388
+ console.log(`\u{1F9E0} AiSupervisorNode: Using distributed memory (sessionId: ${sessionId})`);
1389
+ } else {
1390
+ console.log(`\u26A0\uFE0F AiSupervisorNode: No sessionMemory connected - stateless mode`);
1391
+ }
1341
1392
  const finalSystemPrompt = systemMessage || "You are a supervisor...";
1342
1393
  const workflow = (0, import_langgraph_supervisor.createSupervisor)({
1343
1394
  llm: llmInstance,
@@ -1345,14 +1396,14 @@ var AiSupervisorNodeFunction = async (params) => {
1345
1396
  prompt: finalSystemPrompt
1346
1397
  });
1347
1398
  const app = workflow.compile({
1348
- checkpointer,
1399
+ ...checkpointer ? { checkpointer } : {},
1349
1400
  store
1350
1401
  });
1351
1402
  if (stream && emitter) {
1352
1403
  try {
1353
1404
  const streamIterator = await app.stream(
1354
1405
  { messages: [new import_messages2.HumanMessage({ content: message })] },
1355
- { recursionLimit: 150, configurable: { thread_id: "conversation" } }
1406
+ { recursionLimit: 150, configurable: { thread_id: sessionId } }
1356
1407
  );
1357
1408
  let finalMessages = [];
1358
1409
  const previousStepMessages = /* @__PURE__ */ new Map();
@@ -1431,7 +1482,7 @@ var AiSupervisorNodeFunction = async (params) => {
1431
1482
  } else {
1432
1483
  const result = await app.invoke(
1433
1484
  { messages: [new import_messages2.HumanMessage({ content: message })] },
1434
- { recursionLimit: 150, configurable: { thread_id: "conversation" } }
1485
+ { recursionLimit: 150, configurable: { thread_id: sessionId } }
1435
1486
  );
1436
1487
  const finalResponse = extractFinalResponse(result?.messages);
1437
1488
  return {
@@ -1525,12 +1576,139 @@ var AiToolNode = {
1525
1576
  // src/nodes/ia/tool/function.ts
1526
1577
  var import_tools = require("@langchain/core/tools");
1527
1578
 
1579
+ // src/nodes/memory/postgres/data.ts
1580
+ var import_zod8 = require("zod");
1581
+ var PostgresMemoryNodeSchema = import_zod8.z.object({
1582
+ connectionString: import_zod8.z.string().describe("PostgreSQL connection string")
1583
+ });
1584
+ var PostgresMemoryNode = {
1585
+ label: "Postgres Memory",
1586
+ type: "PostgresMemoryNode",
1587
+ category: "memory",
1588
+ description: "Persistent conversation memory using PostgreSQL (distributed across pods)",
1589
+ icon: "\u{1F418}",
1590
+ group: "Memory",
1591
+ tags: {
1592
+ execution: "sync",
1593
+ group: "Memory"
1594
+ },
1595
+ fields: [
1596
+ {
1597
+ id: "connectionString",
1598
+ label: "Connection String",
1599
+ type: "string",
1600
+ required: true,
1601
+ defaultValue: "postgresql://postgres:postgres@localhost:5432/workflows",
1602
+ placeholder: "postgresql://user:pass@host:5432/database"
1603
+ },
1604
+ {
1605
+ id: "checkpointer",
1606
+ label: "Checkpointer",
1607
+ type: "memory",
1608
+ required: true,
1609
+ typeable: false,
1610
+ handle: {
1611
+ type: "output",
1612
+ label: "Memory",
1613
+ name: "checkpointer",
1614
+ fieldType: "memory"
1615
+ }
1616
+ }
1617
+ ]
1618
+ };
1619
+
1620
+ // src/nodes/memory/postgres/function.ts
1621
+ var import_langgraph_checkpoint_postgres = require("@langchain/langgraph-checkpoint-postgres");
1622
+ var PostgresMemoryNodeFunction = async (inputs) => {
1623
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
1624
+ const fieldValues = inputs.fieldValues || {};
1625
+ const connectionString = fieldValues.connectionString || inputs.connectionString || "postgresql://postgres:postgres@localhost:5432/workflows";
1626
+ try {
1627
+ const checkpointer = import_langgraph_checkpoint_postgres.PostgresSaver.fromConnString(connectionString);
1628
+ await checkpointer.setup();
1629
+ console.log("\u2705 PostgresMemory: Checkpointer initialized");
1630
+ return {
1631
+ checkpointer,
1632
+ type: "PostgresMemoryNode",
1633
+ connectionString: connectionString.replace(/:[^:@]+@/, ":***@")
1634
+ // Hide password in output
1635
+ };
1636
+ } catch (error) {
1637
+ console.error("\u274C PostgresMemory: Failed to initialize checkpointer:", error);
1638
+ throw new Error(`PostgresMemory initialization failed: ${error instanceof Error ? error.message : String(error)}`);
1639
+ }
1640
+ };
1641
+
1642
+ // src/nodes/memory/redis/data.ts
1643
+ var import_zod9 = require("zod");
1644
+ var RedisMemoryNodeSchema = import_zod9.z.object({
1645
+ redisUrl: import_zod9.z.string().describe("Redis connection URL")
1646
+ });
1647
+ var RedisMemoryNode = {
1648
+ label: "Redis Memory",
1649
+ type: "RedisMemoryNode",
1650
+ category: "memory",
1651
+ description: "Fast, persistent conversation memory using Redis (distributed across pods)",
1652
+ icon: "\u{1F534}",
1653
+ group: "Memory",
1654
+ tags: {
1655
+ execution: "sync",
1656
+ group: "Memory"
1657
+ },
1658
+ fields: [
1659
+ {
1660
+ id: "redisUrl",
1661
+ label: "Redis URL",
1662
+ type: "string",
1663
+ required: true,
1664
+ defaultValue: "redis://localhost:6379",
1665
+ placeholder: "redis://localhost:6379"
1666
+ },
1667
+ {
1668
+ id: "checkpointer",
1669
+ label: "Checkpointer",
1670
+ type: "memory",
1671
+ required: true,
1672
+ typeable: false,
1673
+ handle: {
1674
+ type: "output",
1675
+ label: "Memory",
1676
+ name: "checkpointer",
1677
+ fieldType: "memory"
1678
+ }
1679
+ }
1680
+ ]
1681
+ };
1682
+
1683
+ // src/nodes/memory/redis/function.ts
1684
+ var import_langgraph_checkpoint_redis = require("@langchain/langgraph-checkpoint-redis");
1685
+ var RedisMemoryNodeFunction = async (inputs) => {
1686
+ const { $field: _$field, $req: _$req, $inputs: _$inputs, $vars: _$vars } = inputs;
1687
+ const fieldValues = inputs.fieldValues || {};
1688
+ const redisUrl = fieldValues.redisUrl || inputs.redisUrl || "redis://localhost:6379";
1689
+ try {
1690
+ const checkpointer = await import_langgraph_checkpoint_redis.RedisSaver.fromUrl(redisUrl);
1691
+ console.log("\u2705 RedisMemory: Checkpointer initialized");
1692
+ return {
1693
+ checkpointer,
1694
+ type: "RedisMemoryNode",
1695
+ redisUrl: redisUrl.replace(/:[^:@]+@/, ":***@")
1696
+ // Hide password in output
1697
+ };
1698
+ } catch (error) {
1699
+ console.error("\u274C RedisMemory: Failed to initialize checkpointer:", error);
1700
+ throw new Error(`RedisMemory initialization failed: ${error instanceof Error ? error.message : String(error)}`);
1701
+ }
1702
+ };
1703
+
1528
1704
  // src/nodes/consts/schemas.ts
1529
1705
  var schemas = {
1530
1706
  IaAgentNode: IaAgentNodeSchema,
1531
1707
  AiSupervisorNode: AiSupervisorNodeSchema,
1532
1708
  AiToolNode: AiToolNodeSchema,
1533
- IaMessageNode: IaMessageNodeSchema
1709
+ IaMessageNode: IaMessageNodeSchema,
1710
+ PostgresMemoryNode: PostgresMemoryNodeSchema,
1711
+ RedisMemoryNode: RedisMemoryNodeSchema
1534
1712
  };
1535
1713
 
1536
1714
  // src/nodes/ia/tool/function.ts
@@ -1572,11 +1750,11 @@ var AiToolNodeFunction = async (params) => {
1572
1750
  };
1573
1751
 
1574
1752
  // src/nodes/ia/message/message.ts
1575
- var import_zod8 = require("zod");
1576
- var IaMessageNodeSchema = import_zod8.z.object({
1577
- model: import_zod8.z.any().describe("LLM model to use"),
1578
- systemMessage: import_zod8.z.string().optional().describe("System message for context"),
1579
- message: import_zod8.z.string().describe("User message to send to the LLM")
1753
+ var import_zod10 = require("zod");
1754
+ var IaMessageNodeSchema = import_zod10.z.object({
1755
+ model: import_zod10.z.any().describe("LLM model to use"),
1756
+ systemMessage: import_zod10.z.string().optional().describe("System message for context"),
1757
+ message: import_zod10.z.string().describe("User message to send to the LLM")
1580
1758
  });
1581
1759
  var IaMessageNodeFunction = async (inputs) => {
1582
1760
  const { $field: _$field, $req: _$req, $inputs: _$inputs_var, $vars: _$vars } = inputs;
@@ -1711,10 +1889,10 @@ var IaMessageNode = {
1711
1889
  };
1712
1890
 
1713
1891
  // src/nodes/social/whatsapp/send-template/data.ts
1714
- var import_zod9 = require("zod");
1715
- var WhatsappSendTemplateNodeSchema = import_zod9.z.object({
1716
- phoneNumber: import_zod9.z.string().describe("Phone number to send the message to"),
1717
- message: import_zod9.z.string().describe("Message to send")
1892
+ var import_zod11 = require("zod");
1893
+ var WhatsappSendTemplateNodeSchema = import_zod11.z.object({
1894
+ phoneNumber: import_zod11.z.string().describe("Phone number to send the message to"),
1895
+ message: import_zod11.z.string().describe("Message to send")
1718
1896
  });
1719
1897
  var WhatsappSendTemplateNode = {
1720
1898
  label: "Whatsapp Send Template",
@@ -1755,10 +1933,10 @@ var WhatsappSendTemplateNode = {
1755
1933
  };
1756
1934
 
1757
1935
  // src/nodes/social/whatsapp/send-message/data.ts
1758
- var import_zod10 = require("zod");
1759
- var WhatsappSendMessageNodeSchema = import_zod10.z.object({
1760
- phoneNumber: import_zod10.z.string().describe("Phone number to send the message to"),
1761
- message: import_zod10.z.string().describe("Message content to send")
1936
+ var import_zod12 = require("zod");
1937
+ var WhatsappSendMessageNodeSchema = import_zod12.z.object({
1938
+ phoneNumber: import_zod12.z.string().describe("Phone number to send the message to"),
1939
+ message: import_zod12.z.string().describe("Message content to send")
1762
1940
  });
1763
1941
  var WhatsappSendMessageNode = {
1764
1942
  label: "Whatsapp Send Message",
@@ -1989,6 +2167,8 @@ var nodes = [
1989
2167
  IaAgentNode,
1990
2168
  AiToolNode,
1991
2169
  AiSupervisorNode,
2170
+ PostgresMemoryNode,
2171
+ RedisMemoryNode,
1992
2172
  WhatsappSendTemplateNode,
1993
2173
  WhatsappSendMessageNode,
1994
2174
  WhatsappMessageTriggerNode,
@@ -2108,7 +2288,9 @@ var nodeFunctions = {
2108
2288
  WhatsappNode: WhatsappStartChatFunction,
2109
2289
  WhatsappSendMessageNode: WhatsappSendMessageFunction,
2110
2290
  CustomCodeNode: NodeFunction,
2111
- CustomNode: CustomNodeFunction
2291
+ CustomNode: CustomNodeFunction,
2292
+ PostgresMemoryNode: PostgresMemoryNodeFunction,
2293
+ RedisMemoryNode: RedisMemoryNodeFunction
2112
2294
  };
2113
2295
  var node_functions_default = nodeFunctions;
2114
2296
 
@@ -2222,12 +2404,12 @@ var HttpPutInputNodeFunction = (params) => {
2222
2404
  };
2223
2405
 
2224
2406
  // src/nodes/inputs/http/put/schema.ts
2225
- var import_zod11 = require("zod");
2226
- var HttpPutInputNodeSchema = import_zod11.z.object({
2407
+ var import_zod13 = require("zod");
2408
+ var HttpPutInputNodeSchema = import_zod13.z.object({
2227
2409
  route: RouteSchema,
2228
- queryParams: import_zod11.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2229
- headers: import_zod11.z.array(HeaderSchema).optional().describe("Headers configuration"),
2230
- body: import_zod11.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
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")
2231
2413
  });
2232
2414
 
2233
2415
  // src/nodes/inputs/http/delete/data.ts
@@ -2319,11 +2501,11 @@ var HttpDeleteInputNodeFunction = async (params) => {
2319
2501
  };
2320
2502
 
2321
2503
  // src/nodes/inputs/http/delete/schema.ts
2322
- var import_zod12 = require("zod");
2323
- var HttpDeleteInputNodeSchema = import_zod12.z.object({
2504
+ var import_zod14 = require("zod");
2505
+ var HttpDeleteInputNodeSchema = import_zod14.z.object({
2324
2506
  route: RouteSchema,
2325
- queryParams: import_zod12.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2326
- headers: import_zod12.z.array(HeaderSchema).optional().describe("Headers configuration")
2507
+ queryParams: import_zod14.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2508
+ headers: import_zod14.z.array(HeaderSchema).optional().describe("Headers configuration")
2327
2509
  });
2328
2510
 
2329
2511
  // src/nodes/inputs/http/patch/data.ts
@@ -2436,12 +2618,12 @@ var HttpPatchInputNodeFunction = (params) => {
2436
2618
  };
2437
2619
 
2438
2620
  // src/nodes/inputs/http/patch/schema.ts
2439
- var import_zod13 = require("zod");
2440
- var HttpPatchInputNodeSchema = import_zod13.z.object({
2621
+ var import_zod15 = require("zod");
2622
+ var HttpPatchInputNodeSchema = import_zod15.z.object({
2441
2623
  route: RouteSchema,
2442
- queryParams: import_zod13.z.array(QueryParamSchema).optional().describe("Query parameters configuration"),
2443
- headers: import_zod13.z.array(HeaderSchema).optional().describe("Headers configuration"),
2444
- body: import_zod13.z.array(BodyFieldSchema).optional().describe("Body fields configuration")
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")
2445
2627
  });
2446
2628
 
2447
2629
  // src/nodes/inputs/http/utils.ts