@atomoz/workflows-nodes 0.1.6 → 0.1.8

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
@@ -61,8 +61,6 @@ __export(index_exports, {
61
61
  IaMessageNode: () => IaMessageNode,
62
62
  IaMessageNodeFunction: () => IaMessageNodeFunction,
63
63
  IaMessageNodeSchema: () => IaMessageNodeSchema,
64
- IaModelNode: () => IaModelNode,
65
- IaModelNodeFunction: () => IaModelNodeFunction,
66
64
  QueryParamSchema: () => QueryParamSchema,
67
65
  RouteSchema: () => RouteSchema,
68
66
  WhatsappMessageTriggerNode: () => WhatsappMessageTriggerNode,
@@ -172,7 +170,6 @@ var HttpGetInputNodeFunction = async (params) => {
172
170
  throw new Error(`Headers obrigat\xF3rios ausentes: ${missingHeaders.map((h) => h.key).join(", ")}`);
173
171
  }
174
172
  }
175
- console.log(actualData);
176
173
  return actualData;
177
174
  };
178
175
 
@@ -418,11 +415,9 @@ var ManualTriggerNode = {
418
415
  // src/nodes/processors/concat.ts
419
416
  var import_zod4 = require("zod");
420
417
  var ConcatNodeFunction = (inputs) => {
421
- console.log("\u{1F517} ConcatNode - Input:", { input1: inputs.input1 || "", input2: inputs.input2 || "" });
422
418
  const input1 = inputs.input1 || "";
423
419
  const input2 = inputs.input2 || "";
424
420
  const result = `${input1}${input2}`;
425
- console.log("\u{1F517} ConcatNode - Output:", result);
426
421
  return {
427
422
  output: result,
428
423
  function: ConcatNodeFunction,
@@ -744,13 +739,13 @@ var IaAgentNode = {
744
739
  },
745
740
  {
746
741
  id: "output",
747
- label: "Output",
742
+ label: "Response",
748
743
  type: "string",
749
744
  required: true,
750
745
  typeable: false,
751
746
  handle: {
752
747
  type: "output",
753
- label: "Output",
748
+ label: "response",
754
749
  name: "output",
755
750
  fieldType: "string"
756
751
  }
@@ -761,8 +756,109 @@ var IaAgentNode = {
761
756
  // src/nodes/ia/agent/function.ts
762
757
  var import_prebuilt = require("@langchain/langgraph/prebuilt");
763
758
  var import_messages = require("@langchain/core/messages");
759
+
760
+ // src/utils/llm-factory.ts
761
+ var import_graphql_request = require("graphql-request");
762
+ var import_google_gauth = require("@langchain/google-gauth");
763
+ var import_openai = require("@langchain/openai");
764
+ var GRAPHQL_ENDPOINT = process.env["GRAPHQL_URL"] || "http://localhost:3001/graphql";
765
+ var GET_INTEGRATIONS_QUERY = import_graphql_request.gql`
766
+ query GetIntegrations($where: IntegrationWhereInput) {
767
+ getIntegrations(where: $where) {
768
+ status
769
+ message
770
+ data {
771
+ id
772
+ status
773
+ data
774
+ }
775
+ }
776
+ }
777
+ `;
778
+ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
779
+ if (modelConfig?.invoke || modelConfig?.call) {
780
+ return modelConfig;
781
+ }
782
+ if (!modelConfig?.model || !modelConfig?.integrationId) {
783
+ throw new Error('Model config deve conter "model" e "integrationId"');
784
+ }
785
+ const { model, integrationId } = modelConfig;
786
+ const client = new import_graphql_request.GraphQLClient(GRAPHQL_ENDPOINT, {
787
+ headers: {
788
+ Authorization: `Bearer ${authToken}`,
789
+ "x-tenant-id": "65d62c52-0c09-473a-8895-359afbed3f5a"
790
+ }
791
+ });
792
+ let integrationData;
793
+ try {
794
+ const response = await client.request(
795
+ GET_INTEGRATIONS_QUERY,
796
+ {
797
+ where: {
798
+ id: {
799
+ eq: integrationId
800
+ }
801
+ }
802
+ }
803
+ );
804
+ if (!response.getIntegrations?.data?.[0]) {
805
+ throw new Error(`Integra\xE7\xE3o ${integrationId} n\xE3o encontrada`);
806
+ }
807
+ integrationData = response.getIntegrations.data[0];
808
+ } catch (error) {
809
+ console.error("Erro ao buscar integra\xE7\xE3o:", error);
810
+ throw new Error(
811
+ `Falha ao buscar integra\xE7\xE3o: ${error instanceof Error ? error.message : "Erro desconhecido"}`
812
+ );
813
+ }
814
+ const apiKey = integrationData.data?.["token"] || integrationData.data?.["token"];
815
+ if (!apiKey) {
816
+ throw new Error(`API Key n\xE3o encontrada na integra\xE7\xE3o ${integrationId}`);
817
+ }
818
+ const provider = integrationData.data?.provider?.toLowerCase() || inferProviderFromModel(model);
819
+ switch (provider) {
820
+ case "gemini":
821
+ return new import_google_gauth.ChatGoogle({
822
+ model: "gemini-flash-latest",
823
+ apiKey,
824
+ streaming
825
+ });
826
+ case "openai":
827
+ return new import_openai.ChatOpenAI({
828
+ model,
829
+ openAIApiKey: apiKey,
830
+ streaming
831
+ });
832
+ case "openrouter":
833
+ return new import_openai.ChatOpenAI({
834
+ model,
835
+ openAIApiKey: apiKey,
836
+ configuration: {
837
+ baseURL: "https://openrouter.ai/api/v1"
838
+ },
839
+ streaming
840
+ });
841
+ default:
842
+ throw new Error(
843
+ `Provider "${provider}" n\xE3o suportado. Providers dispon\xEDveis: gemini, openai, openrouter`
844
+ );
845
+ }
846
+ }
847
+ function inferProviderFromModel(model) {
848
+ const modelLower = model.toLowerCase();
849
+ if (modelLower.includes("gemini") || modelLower.includes("palm")) {
850
+ return "gemini";
851
+ }
852
+ if (modelLower.includes("gpt") || modelLower.includes("o1") || modelLower.includes("o3")) {
853
+ return "openai";
854
+ }
855
+ return "openrouter";
856
+ }
857
+
858
+ // src/nodes/ia/agent/function.ts
764
859
  var IaAgentNodeFunction = async (inputs) => {
765
- const { model, tools, systemMessage, name, message } = inputs.fieldValues || inputs;
860
+ const { model, tools, systemMessage, name, message } = inputs.fieldValues;
861
+ const authToken = inputs.authToken;
766
862
  if (!name) {
767
863
  throw new Error("Agent 'name' is required. Please provide a unique name for the agent in the node properties.");
768
864
  }
@@ -779,8 +875,20 @@ var IaAgentNodeFunction = async (inputs) => {
779
875
 
780
876
  IMPORTANT: You must base your response on the last message in the conversation history.`;
781
877
  const finalSystemMessage = new import_messages.SystemMessage(finalSystemMessageContent);
878
+ let llmInstance;
879
+ if (model?.integrationId) {
880
+ if (!authToken) {
881
+ throw new Error("Auth token is required to instantiate LLM from integration");
882
+ }
883
+ const streaming = Boolean(inputs?.stream);
884
+ llmInstance = await createLLMFromModel(model, authToken, streaming);
885
+ } else if (typeof model?.bindTools === "function") {
886
+ llmInstance = model;
887
+ } else {
888
+ throw new Error("Invalid model: must have integrationId or be a valid LLM instance with bindTools method");
889
+ }
782
890
  const agent = (0, import_prebuilt.createReactAgent)({
783
- llm: model,
891
+ llm: llmInstance,
784
892
  tools: toolsArray,
785
893
  messageModifier: finalSystemMessage
786
894
  });
@@ -956,15 +1064,25 @@ var AiSupervisorNodeFunction = async (fieldValues) => {
956
1064
  const systemMessage = inner.systemMessage ?? outer.systemMessage;
957
1065
  const stream = (typeof outer.stream === "boolean" ? outer.stream : inner.stream) ?? false;
958
1066
  const emitter = outer.emitter ?? inner.emitter;
1067
+ const authToken = outer.authToken ?? inner.authToken;
959
1068
  if (!model) throw new Error("Model is required for AiSupervisorNode");
960
1069
  if (!agents) throw new Error("Agents are required for AiSupervisorNode.");
961
1070
  try {
962
1071
  const supervisorAgents = extractSupervisorAgents(agents);
963
1072
  if (supervisorAgents.length === 0) throw new Error("No valid agents were extracted from the 'agents' input.");
964
1073
  if (supervisorAgents.some((agent) => !agent.name)) throw new Error("All agents must have a name.");
1074
+ let llmInstance;
1075
+ if (model?.model && model?.integrationId) {
1076
+ if (!authToken) {
1077
+ throw new Error("Auth token is required to instantiate LLM from integration 3");
1078
+ }
1079
+ llmInstance = await createLLMFromModel(model, authToken, stream);
1080
+ } else {
1081
+ llmInstance = model;
1082
+ }
965
1083
  const finalSystemPrompt = systemMessage || "You are a supervisor...";
966
1084
  const workflow = (0, import_langgraph_supervisor.createSupervisor)({
967
- llm: model,
1085
+ llm: llmInstance,
968
1086
  agents: supervisorAgents,
969
1087
  prompt: finalSystemPrompt
970
1088
  });
@@ -974,7 +1092,6 @@ var AiSupervisorNodeFunction = async (fieldValues) => {
974
1092
  });
975
1093
  if (stream && emitter) {
976
1094
  try {
977
- console.log("\u{1F504} Starting streaming mode...");
978
1095
  const streamIterator = await app.stream(
979
1096
  { messages: [new import_messages2.HumanMessage({ content: message })] },
980
1097
  { recursionLimit: 150, configurable: { thread_id: "conversation" } }
@@ -1192,76 +1309,6 @@ var AiToolNodeFunction = async (fieldValues) => {
1192
1309
  };
1193
1310
  };
1194
1311
 
1195
- // src/nodes/ia/model/data.ts
1196
- var IaModelNode = {
1197
- label: "AI Model",
1198
- type: "IaModelNode",
1199
- category: "step",
1200
- description: "AI Model",
1201
- icon: "\u{1F916}",
1202
- tags: {
1203
- execution: "async",
1204
- group: "IA"
1205
- },
1206
- fields: [
1207
- {
1208
- id: "model",
1209
- label: "Model",
1210
- type: "select",
1211
- required: true,
1212
- defaultValue: "gemini-2.5-pro",
1213
- options: [
1214
- { label: "Gemini 2.5 Pro", value: "gemini-2.5-pro" },
1215
- { label: "Gemini 2.5 Flash", value: "gemini-2.5-flash" },
1216
- { label: "Gemini 2.5 Flash Lite", value: "gemini-2.5-flash-lite" },
1217
- { label: "Gemini 2.0 Flash", value: "gemini-2.0-flash" },
1218
- { label: "Gemini 2.0 Flash Lite", value: "gemini-2.0-flash-lite" }
1219
- ]
1220
- },
1221
- {
1222
- id: "apiKey",
1223
- label: "API Key",
1224
- type: "string",
1225
- required: true
1226
- },
1227
- {
1228
- id: "model",
1229
- label: "Model",
1230
- type: "model",
1231
- required: true,
1232
- typeable: false,
1233
- handle: {
1234
- type: "output",
1235
- label: "Model",
1236
- name: "model",
1237
- fieldType: "model",
1238
- required: true
1239
- }
1240
- }
1241
- ]
1242
- };
1243
-
1244
- // src/nodes/ia/model/function.ts
1245
- var import_google_gauth = require("@langchain/google-gauth");
1246
- var IaModelNodeFunction = async (inputs) => {
1247
- const fieldValues = inputs.fieldValues || inputs;
1248
- const { model, apiKey } = fieldValues;
1249
- const stream = Boolean(inputs?.stream || fieldValues?.stream);
1250
- if (!model || !apiKey) {
1251
- console.error("\u274C Model e apiKey s\xE3o obrigat\xF3rios para IaModelNode");
1252
- console.error("\u274C Received:", { model, apiKey });
1253
- throw new Error("Model e apiKey s\xE3o obrigat\xF3rios");
1254
- }
1255
- const llm = new import_google_gauth.ChatGoogle({
1256
- model,
1257
- apiKey,
1258
- streaming: stream
1259
- });
1260
- return {
1261
- model: llm
1262
- };
1263
- };
1264
-
1265
1312
  // src/nodes/ia/message/message.ts
1266
1313
  var import_zod8 = require("zod");
1267
1314
  var IaMessageNodeSchema = import_zod8.z.object({
@@ -1269,21 +1316,33 @@ var IaMessageNodeSchema = import_zod8.z.object({
1269
1316
  systemMessage: import_zod8.z.string().optional().describe("System message for context"),
1270
1317
  message: import_zod8.z.string().describe("User message to send to the LLM")
1271
1318
  });
1272
- var IaMessageNodeFunction = async (fieldValues) => {
1319
+ var IaMessageNodeFunction = async (inputs) => {
1320
+ const fieldValues = inputs.fieldValues || inputs;
1273
1321
  const { model, systemMessage, message } = fieldValues;
1322
+ const authToken = inputs.authToken;
1274
1323
  if (!model) {
1275
1324
  throw new Error("Model is required");
1276
1325
  }
1277
1326
  if (!message) {
1278
1327
  throw new Error("Message is required");
1279
1328
  }
1329
+ let llmInstance;
1330
+ if (model?.model && model?.integrationId) {
1331
+ if (!authToken) {
1332
+ throw new Error("Auth token is required to instantiate LLM from integration2 ");
1333
+ }
1334
+ const streaming = Boolean(inputs?.stream);
1335
+ llmInstance = await createLLMFromModel(model, authToken, streaming);
1336
+ } else {
1337
+ llmInstance = model;
1338
+ }
1280
1339
  const messages = [];
1281
1340
  if (systemMessage) {
1282
1341
  messages.push(["system", systemMessage]);
1283
1342
  }
1284
1343
  messages.push(["human", message]);
1285
1344
  try {
1286
- const response = await model.invoke(messages);
1345
+ const response = await llmInstance.invoke(messages);
1287
1346
  return {
1288
1347
  output: response.content,
1289
1348
  response: response.content,
@@ -1519,7 +1578,6 @@ var nodes = [
1519
1578
  ConcatNode,
1520
1579
  OutputNode,
1521
1580
  ChatOutputNode,
1522
- IaModelNode,
1523
1581
  IaMessageNode,
1524
1582
  IaAgentNode,
1525
1583
  AiToolNode,
@@ -1536,10 +1594,6 @@ var NUMBER_ID = "700207253183039";
1536
1594
  var TOKEN = "EAAUuy5eznhEBPQUOoF07SUTSVjgNIX9eZCWSKPYQhzHiXeEp4Qj3g47bZAPcZAgs8P2B5cZBH9YJjzq0HKNXfA14kaK5Cp2DZCmxzV60MgWlsY1yKavb2qXAQcydoHTTLKcWO53w6ZB7JNzZBeIpZBTb9cB0teRzfX3kjrZBc7utyKq2ZCZCCOQ74pZA28gnmQYzp24oZBQpf7BmuNHgndFVlTba5drxgcpERyNl1dUIDhky7NIruggZDZD";
1537
1595
  var WhatsappStartChatFunction = async (fieldValues) => {
1538
1596
  const { phoneNumber, template } = fieldValues;
1539
- console.log({
1540
- phoneNumber,
1541
- template
1542
- });
1543
1597
  const response = await fetch(`https://graph.facebook.com/v23.0/${NUMBER_ID}/messages`, {
1544
1598
  method: "POST",
1545
1599
  headers: {
@@ -1600,10 +1654,6 @@ var NUMBER_ID2 = "700207253183039";
1600
1654
  var TOKEN2 = "EAAUuy5eznhEBPWw62uE6cs4oZAW6WvpsiF9RBjTGDjg8H74GouBMl1MBifCuA572AVMp53T83pBuSaMJUcWMDIGxvXbxaU6RFTyXOuKkhUPkF3Boc7QbmRuUWSFuyvkjZCyA7ngAg2NXV8nYzzZCleSuFQD487NN2mat7sHPx2pMHuN95IcaevyKLnuz5Om2Bp36JihQweodc517aH2Krv70jqNKKzBjoGVziWNnOhULQZDZD";
1601
1655
  var WhatsappSendMessageFunction = async (fieldValues) => {
1602
1656
  const { phoneNumber, message } = fieldValues;
1603
- console.log({
1604
- phoneNumber,
1605
- message
1606
- });
1607
1657
  const response = await fetch(`https://graph.facebook.com/v23.0/${NUMBER_ID2}/messages`, {
1608
1658
  method: "POST",
1609
1659
  headers: {
@@ -1641,7 +1691,6 @@ var nodeFunctions = {
1641
1691
  ManualTrigger: ManualTriggerNodeFunction,
1642
1692
  HttpOutput: HttpOutputNodeFunction,
1643
1693
  ConcatNode: ConcatNodeFunction,
1644
- IaModelNode: IaModelNodeFunction,
1645
1694
  IaMessageNode: IaMessageNodeFunction,
1646
1695
  IaAgentNode: IaAgentNodeFunction,
1647
1696
  AiToolNode: AiToolNodeFunction,
@@ -2065,8 +2114,6 @@ var getHttpMethodFromFriendlyId = (friendlyId) => {
2065
2114
  IaMessageNode,
2066
2115
  IaMessageNodeFunction,
2067
2116
  IaMessageNodeSchema,
2068
- IaModelNode,
2069
- IaModelNodeFunction,
2070
2117
  QueryParamSchema,
2071
2118
  RouteSchema,
2072
2119
  WhatsappMessageTriggerNode,
package/dist/index.d.cts CHANGED
@@ -170,8 +170,7 @@ declare const nodeFunctions: {
170
170
  ManualTrigger: (params: any) => any;
171
171
  HttpOutput: (params: any) => any;
172
172
  ConcatNode: (inputs: any) => any;
173
- IaModelNode: (inputs: any) => Promise<any>;
174
- IaMessageNode: (fieldValues: any) => Promise<any>;
173
+ IaMessageNode: (inputs: any) => Promise<any>;
175
174
  IaAgentNode: (inputs: any) => Promise<any>;
176
175
  AiToolNode: (fieldValues: any) => Promise<{
177
176
  tool: any;
@@ -220,16 +219,12 @@ declare const AiToolNodeFunction: (fieldValues: any) => Promise<{
220
219
  tool: any;
221
220
  }>;
222
221
 
223
- declare const IaModelNode: NodeData;
224
-
225
- declare const IaModelNodeFunction: (inputs: any) => Promise<any>;
226
-
227
222
  declare const IaMessageNodeSchema: z.ZodObject<{
228
223
  model: z.ZodAny;
229
224
  systemMessage: z.ZodOptional<z.ZodString>;
230
225
  message: z.ZodString;
231
226
  }, z.core.$strip>;
232
- declare const IaMessageNodeFunction: (fieldValues: any) => Promise<any>;
227
+ declare const IaMessageNodeFunction: (inputs: any) => Promise<any>;
233
228
  declare const IaMessageNode: NodeData;
234
229
 
235
230
  declare const HttpGetInputNode: NodeData;
@@ -430,4 +425,4 @@ declare const WhatsappSendMessageFunction: (fieldValues: any) => Promise<any>;
430
425
 
431
426
  declare const WhatsappMessageTriggerNode: NodeData;
432
427
 
433
- export { AiSupervisorNode, AiSupervisorNodeFunction, AiSupervisorNodeSchema, AiToolNode, AiToolNodeFunction, AiToolNodeSchema, type BaseNodeType, BodyFieldSchema, CustomToolSchema, type ExecutionStep, HTTP_METHODS, HTTP_NODE_TYPES, HeaderSchema, HttpDeleteInputNode, HttpDeleteInputNodeFunction, HttpDeleteInputNodeSchema, type HttpDeleteInputNodeType, HttpGetInputNode, HttpGetInputNodeFunction, HttpGetInputNodeSchema, type HttpGetInputNodeType, type HttpMethod, type HttpNodeType, type HttpOutput, HttpPatchInputNode, HttpPatchInputNodeFunction, HttpPatchInputNodeSchema, type HttpPatchInputNodeType, HttpPostInputNode, HttpPostInputNodeFunction, HttpPostInputNodeSchema, type HttpPostInputNodeType, HttpPutInputNode, HttpPutInputNodeFunction, HttpPutInputNodeSchema, type HttpPutInputNodeType, IaAgentNode, IaAgentNodeFunction, IaAgentNodeSchema, IaMessageNode, IaMessageNodeFunction, IaMessageNodeSchema, IaModelNode, IaModelNodeFunction, type NodeData, type NodeDefinition, type NodeExecution, type NodeExecutionConfig, type NodeExecutionContext, type NodeField, type NodeHandle, type NodeInput, type NodeInputValue, type NodeLogicFunction, type NodeOutput, type NodeOutputValue, type NodeStyle, type NodeTags, type NodeTransformation, type NodeValidation, QueryParamSchema, RouteSchema, WhatsappMessageTriggerNode, WhatsappSendMessageFunction, WhatsappSendMessageNode, WhatsappSendMessageNodeSchema, WhatsappSendTemplateNode, WhatsappSendTemplateNodeSchema, WhatsappStartChatFunction, createMessageTemplate, extractHttpMethodFromNodeType, getHttpMethodFromFriendlyId, getHttpMethodFromNodeType, getHttpNodeTypeStrings, getHttpNodeTypesArray, getHttpNodesTypes, getMessageTemplates, isAnyHttpInputNode, isHttpInputFriendlyId, isHttpInputNode, isHttpMethodNode, nodeFunctions, nodes, schemas };
428
+ export { AiSupervisorNode, AiSupervisorNodeFunction, AiSupervisorNodeSchema, AiToolNode, AiToolNodeFunction, AiToolNodeSchema, type BaseNodeType, BodyFieldSchema, CustomToolSchema, type ExecutionStep, HTTP_METHODS, HTTP_NODE_TYPES, HeaderSchema, HttpDeleteInputNode, HttpDeleteInputNodeFunction, HttpDeleteInputNodeSchema, type HttpDeleteInputNodeType, HttpGetInputNode, HttpGetInputNodeFunction, HttpGetInputNodeSchema, type HttpGetInputNodeType, type HttpMethod, type HttpNodeType, type HttpOutput, HttpPatchInputNode, HttpPatchInputNodeFunction, HttpPatchInputNodeSchema, type HttpPatchInputNodeType, HttpPostInputNode, HttpPostInputNodeFunction, HttpPostInputNodeSchema, type HttpPostInputNodeType, HttpPutInputNode, HttpPutInputNodeFunction, HttpPutInputNodeSchema, type HttpPutInputNodeType, IaAgentNode, IaAgentNodeFunction, IaAgentNodeSchema, IaMessageNode, IaMessageNodeFunction, IaMessageNodeSchema, type NodeData, type NodeDefinition, type NodeExecution, type NodeExecutionConfig, type NodeExecutionContext, type NodeField, type NodeHandle, type NodeInput, type NodeInputValue, type NodeLogicFunction, type NodeOutput, type NodeOutputValue, type NodeStyle, type NodeTags, type NodeTransformation, type NodeValidation, QueryParamSchema, RouteSchema, WhatsappMessageTriggerNode, WhatsappSendMessageFunction, WhatsappSendMessageNode, WhatsappSendMessageNodeSchema, WhatsappSendTemplateNode, WhatsappSendTemplateNodeSchema, WhatsappStartChatFunction, createMessageTemplate, extractHttpMethodFromNodeType, getHttpMethodFromFriendlyId, getHttpMethodFromNodeType, getHttpNodeTypeStrings, getHttpNodeTypesArray, getHttpNodesTypes, getMessageTemplates, isAnyHttpInputNode, isHttpInputFriendlyId, isHttpInputNode, isHttpMethodNode, nodeFunctions, nodes, schemas };
package/dist/index.d.ts CHANGED
@@ -170,8 +170,7 @@ declare const nodeFunctions: {
170
170
  ManualTrigger: (params: any) => any;
171
171
  HttpOutput: (params: any) => any;
172
172
  ConcatNode: (inputs: any) => any;
173
- IaModelNode: (inputs: any) => Promise<any>;
174
- IaMessageNode: (fieldValues: any) => Promise<any>;
173
+ IaMessageNode: (inputs: any) => Promise<any>;
175
174
  IaAgentNode: (inputs: any) => Promise<any>;
176
175
  AiToolNode: (fieldValues: any) => Promise<{
177
176
  tool: any;
@@ -220,16 +219,12 @@ declare const AiToolNodeFunction: (fieldValues: any) => Promise<{
220
219
  tool: any;
221
220
  }>;
222
221
 
223
- declare const IaModelNode: NodeData;
224
-
225
- declare const IaModelNodeFunction: (inputs: any) => Promise<any>;
226
-
227
222
  declare const IaMessageNodeSchema: z.ZodObject<{
228
223
  model: z.ZodAny;
229
224
  systemMessage: z.ZodOptional<z.ZodString>;
230
225
  message: z.ZodString;
231
226
  }, z.core.$strip>;
232
- declare const IaMessageNodeFunction: (fieldValues: any) => Promise<any>;
227
+ declare const IaMessageNodeFunction: (inputs: any) => Promise<any>;
233
228
  declare const IaMessageNode: NodeData;
234
229
 
235
230
  declare const HttpGetInputNode: NodeData;
@@ -430,4 +425,4 @@ declare const WhatsappSendMessageFunction: (fieldValues: any) => Promise<any>;
430
425
 
431
426
  declare const WhatsappMessageTriggerNode: NodeData;
432
427
 
433
- export { AiSupervisorNode, AiSupervisorNodeFunction, AiSupervisorNodeSchema, AiToolNode, AiToolNodeFunction, AiToolNodeSchema, type BaseNodeType, BodyFieldSchema, CustomToolSchema, type ExecutionStep, HTTP_METHODS, HTTP_NODE_TYPES, HeaderSchema, HttpDeleteInputNode, HttpDeleteInputNodeFunction, HttpDeleteInputNodeSchema, type HttpDeleteInputNodeType, HttpGetInputNode, HttpGetInputNodeFunction, HttpGetInputNodeSchema, type HttpGetInputNodeType, type HttpMethod, type HttpNodeType, type HttpOutput, HttpPatchInputNode, HttpPatchInputNodeFunction, HttpPatchInputNodeSchema, type HttpPatchInputNodeType, HttpPostInputNode, HttpPostInputNodeFunction, HttpPostInputNodeSchema, type HttpPostInputNodeType, HttpPutInputNode, HttpPutInputNodeFunction, HttpPutInputNodeSchema, type HttpPutInputNodeType, IaAgentNode, IaAgentNodeFunction, IaAgentNodeSchema, IaMessageNode, IaMessageNodeFunction, IaMessageNodeSchema, IaModelNode, IaModelNodeFunction, type NodeData, type NodeDefinition, type NodeExecution, type NodeExecutionConfig, type NodeExecutionContext, type NodeField, type NodeHandle, type NodeInput, type NodeInputValue, type NodeLogicFunction, type NodeOutput, type NodeOutputValue, type NodeStyle, type NodeTags, type NodeTransformation, type NodeValidation, QueryParamSchema, RouteSchema, WhatsappMessageTriggerNode, WhatsappSendMessageFunction, WhatsappSendMessageNode, WhatsappSendMessageNodeSchema, WhatsappSendTemplateNode, WhatsappSendTemplateNodeSchema, WhatsappStartChatFunction, createMessageTemplate, extractHttpMethodFromNodeType, getHttpMethodFromFriendlyId, getHttpMethodFromNodeType, getHttpNodeTypeStrings, getHttpNodeTypesArray, getHttpNodesTypes, getMessageTemplates, isAnyHttpInputNode, isHttpInputFriendlyId, isHttpInputNode, isHttpMethodNode, nodeFunctions, nodes, schemas };
428
+ export { AiSupervisorNode, AiSupervisorNodeFunction, AiSupervisorNodeSchema, AiToolNode, AiToolNodeFunction, AiToolNodeSchema, type BaseNodeType, BodyFieldSchema, CustomToolSchema, type ExecutionStep, HTTP_METHODS, HTTP_NODE_TYPES, HeaderSchema, HttpDeleteInputNode, HttpDeleteInputNodeFunction, HttpDeleteInputNodeSchema, type HttpDeleteInputNodeType, HttpGetInputNode, HttpGetInputNodeFunction, HttpGetInputNodeSchema, type HttpGetInputNodeType, type HttpMethod, type HttpNodeType, type HttpOutput, HttpPatchInputNode, HttpPatchInputNodeFunction, HttpPatchInputNodeSchema, type HttpPatchInputNodeType, HttpPostInputNode, HttpPostInputNodeFunction, HttpPostInputNodeSchema, type HttpPostInputNodeType, HttpPutInputNode, HttpPutInputNodeFunction, HttpPutInputNodeSchema, type HttpPutInputNodeType, IaAgentNode, IaAgentNodeFunction, IaAgentNodeSchema, IaMessageNode, IaMessageNodeFunction, IaMessageNodeSchema, type NodeData, type NodeDefinition, type NodeExecution, type NodeExecutionConfig, type NodeExecutionContext, type NodeField, type NodeHandle, type NodeInput, type NodeInputValue, type NodeLogicFunction, type NodeOutput, type NodeOutputValue, type NodeStyle, type NodeTags, type NodeTransformation, type NodeValidation, QueryParamSchema, RouteSchema, WhatsappMessageTriggerNode, WhatsappSendMessageFunction, WhatsappSendMessageNode, WhatsappSendMessageNodeSchema, WhatsappSendTemplateNode, WhatsappSendTemplateNodeSchema, WhatsappStartChatFunction, createMessageTemplate, extractHttpMethodFromNodeType, getHttpMethodFromFriendlyId, getHttpMethodFromNodeType, getHttpNodeTypeStrings, getHttpNodeTypesArray, getHttpNodesTypes, getMessageTemplates, isAnyHttpInputNode, isHttpInputFriendlyId, isHttpInputNode, isHttpMethodNode, nodeFunctions, nodes, schemas };
package/dist/index.js CHANGED
@@ -80,7 +80,6 @@ var HttpGetInputNodeFunction = async (params) => {
80
80
  throw new Error(`Headers obrigat\xF3rios ausentes: ${missingHeaders.map((h) => h.key).join(", ")}`);
81
81
  }
82
82
  }
83
- console.log(actualData);
84
83
  return actualData;
85
84
  };
86
85
 
@@ -326,11 +325,9 @@ var ManualTriggerNode = {
326
325
  // src/nodes/processors/concat.ts
327
326
  import { z as z4 } from "zod";
328
327
  var ConcatNodeFunction = (inputs) => {
329
- console.log("\u{1F517} ConcatNode - Input:", { input1: inputs.input1 || "", input2: inputs.input2 || "" });
330
328
  const input1 = inputs.input1 || "";
331
329
  const input2 = inputs.input2 || "";
332
330
  const result = `${input1}${input2}`;
333
- console.log("\u{1F517} ConcatNode - Output:", result);
334
331
  return {
335
332
  output: result,
336
333
  function: ConcatNodeFunction,
@@ -652,13 +649,13 @@ var IaAgentNode = {
652
649
  },
653
650
  {
654
651
  id: "output",
655
- label: "Output",
652
+ label: "Response",
656
653
  type: "string",
657
654
  required: true,
658
655
  typeable: false,
659
656
  handle: {
660
657
  type: "output",
661
- label: "Output",
658
+ label: "response",
662
659
  name: "output",
663
660
  fieldType: "string"
664
661
  }
@@ -669,8 +666,109 @@ var IaAgentNode = {
669
666
  // src/nodes/ia/agent/function.ts
670
667
  import { createReactAgent } from "@langchain/langgraph/prebuilt";
671
668
  import { SystemMessage } from "@langchain/core/messages";
669
+
670
+ // src/utils/llm-factory.ts
671
+ import { GraphQLClient, gql } from "graphql-request";
672
+ import { ChatGoogle } from "@langchain/google-gauth";
673
+ import { ChatOpenAI } from "@langchain/openai";
674
+ var GRAPHQL_ENDPOINT = process.env["GRAPHQL_URL"] || "http://localhost:3001/graphql";
675
+ var GET_INTEGRATIONS_QUERY = gql`
676
+ query GetIntegrations($where: IntegrationWhereInput) {
677
+ getIntegrations(where: $where) {
678
+ status
679
+ message
680
+ data {
681
+ id
682
+ status
683
+ data
684
+ }
685
+ }
686
+ }
687
+ `;
688
+ async function createLLMFromModel(modelConfig, authToken, streaming = false) {
689
+ if (modelConfig?.invoke || modelConfig?.call) {
690
+ return modelConfig;
691
+ }
692
+ if (!modelConfig?.model || !modelConfig?.integrationId) {
693
+ throw new Error('Model config deve conter "model" e "integrationId"');
694
+ }
695
+ const { model, integrationId } = modelConfig;
696
+ const client = new GraphQLClient(GRAPHQL_ENDPOINT, {
697
+ headers: {
698
+ Authorization: `Bearer ${authToken}`,
699
+ "x-tenant-id": "65d62c52-0c09-473a-8895-359afbed3f5a"
700
+ }
701
+ });
702
+ let integrationData;
703
+ try {
704
+ const response = await client.request(
705
+ GET_INTEGRATIONS_QUERY,
706
+ {
707
+ where: {
708
+ id: {
709
+ eq: integrationId
710
+ }
711
+ }
712
+ }
713
+ );
714
+ if (!response.getIntegrations?.data?.[0]) {
715
+ throw new Error(`Integra\xE7\xE3o ${integrationId} n\xE3o encontrada`);
716
+ }
717
+ integrationData = response.getIntegrations.data[0];
718
+ } catch (error) {
719
+ console.error("Erro ao buscar integra\xE7\xE3o:", error);
720
+ throw new Error(
721
+ `Falha ao buscar integra\xE7\xE3o: ${error instanceof Error ? error.message : "Erro desconhecido"}`
722
+ );
723
+ }
724
+ const apiKey = integrationData.data?.["token"] || integrationData.data?.["token"];
725
+ if (!apiKey) {
726
+ throw new Error(`API Key n\xE3o encontrada na integra\xE7\xE3o ${integrationId}`);
727
+ }
728
+ const provider = integrationData.data?.provider?.toLowerCase() || inferProviderFromModel(model);
729
+ switch (provider) {
730
+ case "gemini":
731
+ return new ChatGoogle({
732
+ model: "gemini-flash-latest",
733
+ apiKey,
734
+ streaming
735
+ });
736
+ case "openai":
737
+ return new ChatOpenAI({
738
+ model,
739
+ openAIApiKey: apiKey,
740
+ streaming
741
+ });
742
+ case "openrouter":
743
+ return new ChatOpenAI({
744
+ model,
745
+ openAIApiKey: apiKey,
746
+ configuration: {
747
+ baseURL: "https://openrouter.ai/api/v1"
748
+ },
749
+ streaming
750
+ });
751
+ default:
752
+ throw new Error(
753
+ `Provider "${provider}" n\xE3o suportado. Providers dispon\xEDveis: gemini, openai, openrouter`
754
+ );
755
+ }
756
+ }
757
+ function inferProviderFromModel(model) {
758
+ const modelLower = model.toLowerCase();
759
+ if (modelLower.includes("gemini") || modelLower.includes("palm")) {
760
+ return "gemini";
761
+ }
762
+ if (modelLower.includes("gpt") || modelLower.includes("o1") || modelLower.includes("o3")) {
763
+ return "openai";
764
+ }
765
+ return "openrouter";
766
+ }
767
+
768
+ // src/nodes/ia/agent/function.ts
672
769
  var IaAgentNodeFunction = async (inputs) => {
673
- const { model, tools, systemMessage, name, message } = inputs.fieldValues || inputs;
770
+ const { model, tools, systemMessage, name, message } = inputs.fieldValues;
771
+ const authToken = inputs.authToken;
674
772
  if (!name) {
675
773
  throw new Error("Agent 'name' is required. Please provide a unique name for the agent in the node properties.");
676
774
  }
@@ -687,8 +785,20 @@ var IaAgentNodeFunction = async (inputs) => {
687
785
 
688
786
  IMPORTANT: You must base your response on the last message in the conversation history.`;
689
787
  const finalSystemMessage = new SystemMessage(finalSystemMessageContent);
788
+ let llmInstance;
789
+ if (model?.integrationId) {
790
+ if (!authToken) {
791
+ throw new Error("Auth token is required to instantiate LLM from integration");
792
+ }
793
+ const streaming = Boolean(inputs?.stream);
794
+ llmInstance = await createLLMFromModel(model, authToken, streaming);
795
+ } else if (typeof model?.bindTools === "function") {
796
+ llmInstance = model;
797
+ } else {
798
+ throw new Error("Invalid model: must have integrationId or be a valid LLM instance with bindTools method");
799
+ }
690
800
  const agent = createReactAgent({
691
- llm: model,
801
+ llm: llmInstance,
692
802
  tools: toolsArray,
693
803
  messageModifier: finalSystemMessage
694
804
  });
@@ -864,15 +974,25 @@ var AiSupervisorNodeFunction = async (fieldValues) => {
864
974
  const systemMessage = inner.systemMessage ?? outer.systemMessage;
865
975
  const stream = (typeof outer.stream === "boolean" ? outer.stream : inner.stream) ?? false;
866
976
  const emitter = outer.emitter ?? inner.emitter;
977
+ const authToken = outer.authToken ?? inner.authToken;
867
978
  if (!model) throw new Error("Model is required for AiSupervisorNode");
868
979
  if (!agents) throw new Error("Agents are required for AiSupervisorNode.");
869
980
  try {
870
981
  const supervisorAgents = extractSupervisorAgents(agents);
871
982
  if (supervisorAgents.length === 0) throw new Error("No valid agents were extracted from the 'agents' input.");
872
983
  if (supervisorAgents.some((agent) => !agent.name)) throw new Error("All agents must have a name.");
984
+ let llmInstance;
985
+ if (model?.model && model?.integrationId) {
986
+ if (!authToken) {
987
+ throw new Error("Auth token is required to instantiate LLM from integration 3");
988
+ }
989
+ llmInstance = await createLLMFromModel(model, authToken, stream);
990
+ } else {
991
+ llmInstance = model;
992
+ }
873
993
  const finalSystemPrompt = systemMessage || "You are a supervisor...";
874
994
  const workflow = createSupervisor({
875
- llm: model,
995
+ llm: llmInstance,
876
996
  agents: supervisorAgents,
877
997
  prompt: finalSystemPrompt
878
998
  });
@@ -882,7 +1002,6 @@ var AiSupervisorNodeFunction = async (fieldValues) => {
882
1002
  });
883
1003
  if (stream && emitter) {
884
1004
  try {
885
- console.log("\u{1F504} Starting streaming mode...");
886
1005
  const streamIterator = await app.stream(
887
1006
  { messages: [new HumanMessage({ content: message })] },
888
1007
  { recursionLimit: 150, configurable: { thread_id: "conversation" } }
@@ -1100,76 +1219,6 @@ var AiToolNodeFunction = async (fieldValues) => {
1100
1219
  };
1101
1220
  };
1102
1221
 
1103
- // src/nodes/ia/model/data.ts
1104
- var IaModelNode = {
1105
- label: "AI Model",
1106
- type: "IaModelNode",
1107
- category: "step",
1108
- description: "AI Model",
1109
- icon: "\u{1F916}",
1110
- tags: {
1111
- execution: "async",
1112
- group: "IA"
1113
- },
1114
- fields: [
1115
- {
1116
- id: "model",
1117
- label: "Model",
1118
- type: "select",
1119
- required: true,
1120
- defaultValue: "gemini-2.5-pro",
1121
- options: [
1122
- { label: "Gemini 2.5 Pro", value: "gemini-2.5-pro" },
1123
- { label: "Gemini 2.5 Flash", value: "gemini-2.5-flash" },
1124
- { label: "Gemini 2.5 Flash Lite", value: "gemini-2.5-flash-lite" },
1125
- { label: "Gemini 2.0 Flash", value: "gemini-2.0-flash" },
1126
- { label: "Gemini 2.0 Flash Lite", value: "gemini-2.0-flash-lite" }
1127
- ]
1128
- },
1129
- {
1130
- id: "apiKey",
1131
- label: "API Key",
1132
- type: "string",
1133
- required: true
1134
- },
1135
- {
1136
- id: "model",
1137
- label: "Model",
1138
- type: "model",
1139
- required: true,
1140
- typeable: false,
1141
- handle: {
1142
- type: "output",
1143
- label: "Model",
1144
- name: "model",
1145
- fieldType: "model",
1146
- required: true
1147
- }
1148
- }
1149
- ]
1150
- };
1151
-
1152
- // src/nodes/ia/model/function.ts
1153
- import { ChatGoogle } from "@langchain/google-gauth";
1154
- var IaModelNodeFunction = async (inputs) => {
1155
- const fieldValues = inputs.fieldValues || inputs;
1156
- const { model, apiKey } = fieldValues;
1157
- const stream = Boolean(inputs?.stream || fieldValues?.stream);
1158
- if (!model || !apiKey) {
1159
- console.error("\u274C Model e apiKey s\xE3o obrigat\xF3rios para IaModelNode");
1160
- console.error("\u274C Received:", { model, apiKey });
1161
- throw new Error("Model e apiKey s\xE3o obrigat\xF3rios");
1162
- }
1163
- const llm = new ChatGoogle({
1164
- model,
1165
- apiKey,
1166
- streaming: stream
1167
- });
1168
- return {
1169
- model: llm
1170
- };
1171
- };
1172
-
1173
1222
  // src/nodes/ia/message/message.ts
1174
1223
  import { z as z8 } from "zod";
1175
1224
  var IaMessageNodeSchema = z8.object({
@@ -1177,21 +1226,33 @@ var IaMessageNodeSchema = z8.object({
1177
1226
  systemMessage: z8.string().optional().describe("System message for context"),
1178
1227
  message: z8.string().describe("User message to send to the LLM")
1179
1228
  });
1180
- var IaMessageNodeFunction = async (fieldValues) => {
1229
+ var IaMessageNodeFunction = async (inputs) => {
1230
+ const fieldValues = inputs.fieldValues || inputs;
1181
1231
  const { model, systemMessage, message } = fieldValues;
1232
+ const authToken = inputs.authToken;
1182
1233
  if (!model) {
1183
1234
  throw new Error("Model is required");
1184
1235
  }
1185
1236
  if (!message) {
1186
1237
  throw new Error("Message is required");
1187
1238
  }
1239
+ let llmInstance;
1240
+ if (model?.model && model?.integrationId) {
1241
+ if (!authToken) {
1242
+ throw new Error("Auth token is required to instantiate LLM from integration2 ");
1243
+ }
1244
+ const streaming = Boolean(inputs?.stream);
1245
+ llmInstance = await createLLMFromModel(model, authToken, streaming);
1246
+ } else {
1247
+ llmInstance = model;
1248
+ }
1188
1249
  const messages = [];
1189
1250
  if (systemMessage) {
1190
1251
  messages.push(["system", systemMessage]);
1191
1252
  }
1192
1253
  messages.push(["human", message]);
1193
1254
  try {
1194
- const response = await model.invoke(messages);
1255
+ const response = await llmInstance.invoke(messages);
1195
1256
  return {
1196
1257
  output: response.content,
1197
1258
  response: response.content,
@@ -1427,7 +1488,6 @@ var nodes = [
1427
1488
  ConcatNode,
1428
1489
  OutputNode,
1429
1490
  ChatOutputNode,
1430
- IaModelNode,
1431
1491
  IaMessageNode,
1432
1492
  IaAgentNode,
1433
1493
  AiToolNode,
@@ -1444,10 +1504,6 @@ var NUMBER_ID = "700207253183039";
1444
1504
  var TOKEN = "EAAUuy5eznhEBPQUOoF07SUTSVjgNIX9eZCWSKPYQhzHiXeEp4Qj3g47bZAPcZAgs8P2B5cZBH9YJjzq0HKNXfA14kaK5Cp2DZCmxzV60MgWlsY1yKavb2qXAQcydoHTTLKcWO53w6ZB7JNzZBeIpZBTb9cB0teRzfX3kjrZBc7utyKq2ZCZCCOQ74pZA28gnmQYzp24oZBQpf7BmuNHgndFVlTba5drxgcpERyNl1dUIDhky7NIruggZDZD";
1445
1505
  var WhatsappStartChatFunction = async (fieldValues) => {
1446
1506
  const { phoneNumber, template } = fieldValues;
1447
- console.log({
1448
- phoneNumber,
1449
- template
1450
- });
1451
1507
  const response = await fetch(`https://graph.facebook.com/v23.0/${NUMBER_ID}/messages`, {
1452
1508
  method: "POST",
1453
1509
  headers: {
@@ -1508,10 +1564,6 @@ var NUMBER_ID2 = "700207253183039";
1508
1564
  var TOKEN2 = "EAAUuy5eznhEBPWw62uE6cs4oZAW6WvpsiF9RBjTGDjg8H74GouBMl1MBifCuA572AVMp53T83pBuSaMJUcWMDIGxvXbxaU6RFTyXOuKkhUPkF3Boc7QbmRuUWSFuyvkjZCyA7ngAg2NXV8nYzzZCleSuFQD487NN2mat7sHPx2pMHuN95IcaevyKLnuz5Om2Bp36JihQweodc517aH2Krv70jqNKKzBjoGVziWNnOhULQZDZD";
1509
1565
  var WhatsappSendMessageFunction = async (fieldValues) => {
1510
1566
  const { phoneNumber, message } = fieldValues;
1511
- console.log({
1512
- phoneNumber,
1513
- message
1514
- });
1515
1567
  const response = await fetch(`https://graph.facebook.com/v23.0/${NUMBER_ID2}/messages`, {
1516
1568
  method: "POST",
1517
1569
  headers: {
@@ -1549,7 +1601,6 @@ var nodeFunctions = {
1549
1601
  ManualTrigger: ManualTriggerNodeFunction,
1550
1602
  HttpOutput: HttpOutputNodeFunction,
1551
1603
  ConcatNode: ConcatNodeFunction,
1552
- IaModelNode: IaModelNodeFunction,
1553
1604
  IaMessageNode: IaMessageNodeFunction,
1554
1605
  IaAgentNode: IaAgentNodeFunction,
1555
1606
  AiToolNode: AiToolNodeFunction,
@@ -1972,8 +2023,6 @@ export {
1972
2023
  IaMessageNode,
1973
2024
  IaMessageNodeFunction,
1974
2025
  IaMessageNodeSchema,
1975
- IaModelNode,
1976
- IaModelNodeFunction,
1977
2026
  QueryParamSchema,
1978
2027
  RouteSchema,
1979
2028
  WhatsappMessageTriggerNode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomoz/workflows-nodes",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Atomoz Workflows - Node Library",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -41,6 +41,8 @@
41
41
  "@langchain/google-gauth": "^0.2.16",
42
42
  "@langchain/langgraph": "^0.4.3",
43
43
  "@langchain/langgraph-supervisor": "^0.0.17",
44
+ "@langchain/openai": "^0.6.3",
45
+ "graphql-request": "^7.2.0",
44
46
  "tslib": "^2.3.0",
45
47
  "zod": "^4.0.14"
46
48
  },