@atomoz/workflows-nodes 0.1.11 → 0.1.12

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.
Files changed (196) hide show
  1. package/package.json +8 -8
  2. package/src/index.d.ts +2 -0
  3. package/src/index.d.ts.map +1 -0
  4. package/src/index.js +1 -0
  5. package/src/nodes/consts/index.d.ts +3 -0
  6. package/src/nodes/consts/index.d.ts.map +1 -0
  7. package/src/nodes/consts/index.js +2 -0
  8. package/src/nodes/consts/node-colors.d.ts +7 -0
  9. package/src/nodes/consts/node-colors.d.ts.map +1 -0
  10. package/src/nodes/consts/node-colors.js +6 -0
  11. package/src/nodes/consts/node-functions.d.ts +19 -0
  12. package/src/nodes/consts/node-functions.d.ts.map +1 -0
  13. package/src/nodes/consts/node-functions.js +27 -0
  14. package/src/nodes/consts/nodes.d.ts +3 -0
  15. package/src/nodes/consts/nodes.d.ts.map +1 -0
  16. package/src/nodes/consts/nodes.js +28 -0
  17. package/src/nodes/consts/schemas.d.ts +30 -0
  18. package/src/nodes/consts/schemas.d.ts.map +1 -0
  19. package/src/nodes/consts/schemas.js +7 -0
  20. package/src/nodes/ia/agent/data.d.ts +11 -0
  21. package/src/nodes/ia/agent/data.d.ts.map +1 -0
  22. package/src/nodes/ia/agent/data.js +111 -0
  23. package/src/nodes/ia/agent/function.d.ts +2 -0
  24. package/src/nodes/ia/agent/function.d.ts.map +1 -0
  25. package/src/nodes/ia/agent/function.js +90 -0
  26. package/src/nodes/ia/agent/index.d.ts +3 -0
  27. package/src/nodes/ia/agent/index.d.ts.map +1 -0
  28. package/src/nodes/ia/agent/index.js +2 -0
  29. package/src/nodes/ia/index.d.ts +5 -0
  30. package/src/nodes/ia/index.d.ts.map +1 -0
  31. package/src/nodes/ia/index.js +4 -0
  32. package/src/nodes/ia/message/index.d.ts +2 -0
  33. package/src/nodes/ia/message/index.d.ts.map +1 -0
  34. package/src/nodes/ia/message/index.js +1 -0
  35. package/src/nodes/ia/message/message.d.ts +10 -0
  36. package/src/nodes/ia/message/message.d.ts.map +1 -0
  37. package/src/nodes/ia/message/message.js +118 -0
  38. package/src/nodes/ia/supervisor/data.d.ts +10 -0
  39. package/src/nodes/ia/supervisor/data.d.ts.map +1 -0
  40. package/src/nodes/ia/supervisor/data.js +84 -0
  41. package/src/nodes/ia/supervisor/function.d.ts +2 -0
  42. package/src/nodes/ia/supervisor/function.d.ts.map +1 -0
  43. package/src/nodes/ia/supervisor/function.js +227 -0
  44. package/src/nodes/ia/supervisor/index.d.ts +3 -0
  45. package/src/nodes/ia/supervisor/index.d.ts.map +1 -0
  46. package/src/nodes/ia/supervisor/index.js +2 -0
  47. package/src/nodes/ia/tool/data.d.ts +16 -0
  48. package/src/nodes/ia/tool/data.d.ts.map +1 -0
  49. package/src/nodes/ia/tool/data.js +70 -0
  50. package/src/nodes/ia/tool/function.d.ts +4 -0
  51. package/src/nodes/ia/tool/function.d.ts.map +1 -0
  52. package/src/nodes/ia/tool/function.js +36 -0
  53. package/src/nodes/ia/tool/index.d.ts +3 -0
  54. package/src/nodes/ia/tool/index.d.ts.map +1 -0
  55. package/src/nodes/ia/tool/index.js +2 -0
  56. package/src/nodes/index.d.ts +9 -0
  57. package/src/nodes/index.d.ts.map +1 -0
  58. package/src/nodes/index.js +8 -0
  59. package/src/nodes/inputs/chat/chat.d.ts +4 -0
  60. package/src/nodes/inputs/chat/chat.d.ts.map +1 -0
  61. package/src/nodes/inputs/chat/chat.js +51 -0
  62. package/src/nodes/inputs/http/delete/data.d.ts +3 -0
  63. package/src/nodes/inputs/http/delete/data.d.ts.map +1 -0
  64. package/src/nodes/inputs/http/delete/data.js +57 -0
  65. package/src/nodes/inputs/http/delete/function.d.ts +2 -0
  66. package/src/nodes/inputs/http/delete/function.d.ts.map +1 -0
  67. package/src/nodes/inputs/http/delete/function.js +28 -0
  68. package/src/nodes/inputs/http/delete/index.d.ts +4 -0
  69. package/src/nodes/inputs/http/delete/index.d.ts.map +1 -0
  70. package/src/nodes/inputs/http/delete/index.js +3 -0
  71. package/src/nodes/inputs/http/delete/schema.d.ts +16 -0
  72. package/src/nodes/inputs/http/delete/schema.d.ts.map +1 -0
  73. package/src/nodes/inputs/http/delete/schema.js +7 -0
  74. package/src/nodes/inputs/http/get/data.d.ts +3 -0
  75. package/src/nodes/inputs/http/get/data.d.ts.map +1 -0
  76. package/src/nodes/inputs/http/get/data.js +58 -0
  77. package/src/nodes/inputs/http/get/function.d.ts +2 -0
  78. package/src/nodes/inputs/http/get/function.d.ts.map +1 -0
  79. package/src/nodes/inputs/http/get/function.js +25 -0
  80. package/src/nodes/inputs/http/get/index.d.ts +4 -0
  81. package/src/nodes/inputs/http/get/index.d.ts.map +1 -0
  82. package/src/nodes/inputs/http/get/index.js +3 -0
  83. package/src/nodes/inputs/http/get/schema.d.ts +16 -0
  84. package/src/nodes/inputs/http/get/schema.d.ts.map +1 -0
  85. package/src/nodes/inputs/http/get/schema.js +7 -0
  86. package/src/nodes/inputs/http/index.d.ts +8 -0
  87. package/src/nodes/inputs/http/index.d.ts.map +1 -0
  88. package/src/nodes/inputs/http/index.js +10 -0
  89. package/src/nodes/inputs/http/patch/data.d.ts +3 -0
  90. package/src/nodes/inputs/http/patch/data.d.ts.map +1 -0
  91. package/src/nodes/inputs/http/patch/data.js +70 -0
  92. package/src/nodes/inputs/http/patch/function.d.ts +2 -0
  93. package/src/nodes/inputs/http/patch/function.d.ts.map +1 -0
  94. package/src/nodes/inputs/http/patch/function.js +36 -0
  95. package/src/nodes/inputs/http/patch/index.d.ts +4 -0
  96. package/src/nodes/inputs/http/patch/index.d.ts.map +1 -0
  97. package/src/nodes/inputs/http/patch/index.js +3 -0
  98. package/src/nodes/inputs/http/patch/schema.d.ts +21 -0
  99. package/src/nodes/inputs/http/patch/schema.d.ts.map +1 -0
  100. package/src/nodes/inputs/http/patch/schema.js +8 -0
  101. package/src/nodes/inputs/http/post/data.d.ts +3 -0
  102. package/src/nodes/inputs/http/post/data.d.ts.map +1 -0
  103. package/src/nodes/inputs/http/post/data.js +70 -0
  104. package/src/nodes/inputs/http/post/function.d.ts +2 -0
  105. package/src/nodes/inputs/http/post/function.d.ts.map +1 -0
  106. package/src/nodes/inputs/http/post/function.js +36 -0
  107. package/src/nodes/inputs/http/post/index.d.ts +4 -0
  108. package/src/nodes/inputs/http/post/index.d.ts.map +1 -0
  109. package/src/nodes/inputs/http/post/index.js +3 -0
  110. package/src/nodes/inputs/http/post/schema.d.ts +21 -0
  111. package/src/nodes/inputs/http/post/schema.d.ts.map +1 -0
  112. package/src/nodes/inputs/http/post/schema.js +8 -0
  113. package/src/nodes/inputs/http/put/data.d.ts +3 -0
  114. package/src/nodes/inputs/http/put/data.d.ts.map +1 -0
  115. package/src/nodes/inputs/http/put/data.js +70 -0
  116. package/src/nodes/inputs/http/put/function.d.ts +2 -0
  117. package/src/nodes/inputs/http/put/function.d.ts.map +1 -0
  118. package/src/nodes/inputs/http/put/function.js +36 -0
  119. package/src/nodes/inputs/http/put/index.d.ts +4 -0
  120. package/src/nodes/inputs/http/put/index.d.ts.map +1 -0
  121. package/src/nodes/inputs/http/put/index.js +3 -0
  122. package/src/nodes/inputs/http/put/schema.d.ts +21 -0
  123. package/src/nodes/inputs/http/put/schema.d.ts.map +1 -0
  124. package/src/nodes/inputs/http/put/schema.js +8 -0
  125. package/src/nodes/inputs/http/schemas.d.ts +18 -0
  126. package/src/nodes/inputs/http/schemas.d.ts.map +1 -0
  127. package/src/nodes/inputs/http/schemas.js +17 -0
  128. package/src/nodes/inputs/http/utils.d.ts +21 -0
  129. package/src/nodes/inputs/http/utils.d.ts.map +1 -0
  130. package/src/nodes/inputs/http/utils.js +63 -0
  131. package/src/nodes/inputs/index.d.ts +5 -0
  132. package/src/nodes/inputs/index.d.ts.map +1 -0
  133. package/src/nodes/inputs/index.js +4 -0
  134. package/src/nodes/inputs/manual/trigger.d.ts +4 -0
  135. package/src/nodes/inputs/manual/trigger.d.ts.map +1 -0
  136. package/src/nodes/inputs/manual/trigger.js +39 -0
  137. package/src/nodes/output-node/index.d.ts +4 -0
  138. package/src/nodes/output-node/index.d.ts.map +1 -0
  139. package/src/nodes/output-node/index.js +123 -0
  140. package/src/nodes/outputs/chat/output.d.ts +4 -0
  141. package/src/nodes/outputs/chat/output.d.ts.map +1 -0
  142. package/src/nodes/outputs/chat/output.js +48 -0
  143. package/src/nodes/outputs/http-output.d.ts +4 -0
  144. package/src/nodes/outputs/http-output.d.ts.map +1 -0
  145. package/src/nodes/outputs/http-output.js +76 -0
  146. package/src/nodes/processors/concat.d.ts +9 -0
  147. package/src/nodes/processors/concat.d.ts.map +1 -0
  148. package/src/nodes/processors/concat.js +68 -0
  149. package/src/nodes/processors/custom-code.d.ts +4 -0
  150. package/src/nodes/processors/custom-code.d.ts.map +1 -0
  151. package/src/nodes/processors/custom-code.js +54 -0
  152. package/src/nodes/processors/index.d.ts +2 -0
  153. package/src/nodes/processors/index.d.ts.map +1 -0
  154. package/src/nodes/processors/index.js +1 -0
  155. package/src/nodes/processors/transform.d.ts +3 -0
  156. package/src/nodes/processors/transform.d.ts.map +1 -0
  157. package/src/nodes/processors/transform.js +48 -0
  158. package/src/nodes/social/index.d.ts +2 -0
  159. package/src/nodes/social/index.d.ts.map +1 -0
  160. package/src/nodes/social/index.js +1 -0
  161. package/src/nodes/social/whatsapp/index.d.ts +4 -0
  162. package/src/nodes/social/whatsapp/index.d.ts.map +1 -0
  163. package/src/nodes/social/whatsapp/index.js +3 -0
  164. package/src/nodes/social/whatsapp/message-trigger/data.d.ts +3 -0
  165. package/src/nodes/social/whatsapp/message-trigger/data.d.ts.map +1 -0
  166. package/src/nodes/social/whatsapp/message-trigger/data.js +55 -0
  167. package/src/nodes/social/whatsapp/message-trigger/index.d.ts +2 -0
  168. package/src/nodes/social/whatsapp/message-trigger/index.d.ts.map +1 -0
  169. package/src/nodes/social/whatsapp/message-trigger/index.js +1 -0
  170. package/src/nodes/social/whatsapp/send-message/data.d.ts +8 -0
  171. package/src/nodes/social/whatsapp/send-message/data.d.ts.map +1 -0
  172. package/src/nodes/social/whatsapp/send-message/data.js +46 -0
  173. package/src/nodes/social/whatsapp/send-message/functions.d.ts +3 -0
  174. package/src/nodes/social/whatsapp/send-message/functions.d.ts.map +1 -0
  175. package/src/nodes/social/whatsapp/send-message/functions.js +32 -0
  176. package/src/nodes/social/whatsapp/send-message/index.d.ts +3 -0
  177. package/src/nodes/social/whatsapp/send-message/index.d.ts.map +1 -0
  178. package/src/nodes/social/whatsapp/send-message/index.js +2 -0
  179. package/src/nodes/social/whatsapp/send-template/data.d.ts +8 -0
  180. package/src/nodes/social/whatsapp/send-template/data.d.ts.map +1 -0
  181. package/src/nodes/social/whatsapp/send-template/data.js +42 -0
  182. package/src/nodes/social/whatsapp/send-template/functions.d.ts +5 -0
  183. package/src/nodes/social/whatsapp/send-template/functions.d.ts.map +1 -0
  184. package/src/nodes/social/whatsapp/send-template/functions.js +60 -0
  185. package/src/nodes/social/whatsapp/send-template/index.d.ts +3 -0
  186. package/src/nodes/social/whatsapp/send-template/index.d.ts.map +1 -0
  187. package/src/nodes/social/whatsapp/send-template/index.js +2 -0
  188. package/src/nodes/types/base-node.d.ts +17 -0
  189. package/src/nodes/types/base-node.d.ts.map +1 -0
  190. package/src/nodes/types/base-node.js +1 -0
  191. package/src/nodes/types/base-node.types.d.ts +144 -0
  192. package/src/nodes/types/base-node.types.d.ts.map +1 -0
  193. package/src/nodes/types/base-node.types.js +1 -0
  194. package/src/utils/llm-factory.d.ts +16 -0
  195. package/src/utils/llm-factory.d.ts.map +1 -0
  196. package/src/utils/llm-factory.js +110 -0
@@ -0,0 +1,84 @@
1
+ import { z } from "zod";
2
+ export const AiSupervisorNodeSchema = z.object({
3
+ model: z.any().describe("LLM model for the supervisor"),
4
+ agents: z.any().optional().describe("Agent(s) to supervise"),
5
+ message: z.string().describe("Task or message for the supervisor to handle"),
6
+ systemMessage: z.string().optional().describe("Custom system message for the supervisor"),
7
+ });
8
+ export const AiSupervisorNode = {
9
+ label: "AI Supervisor",
10
+ type: "AiSupervisorNode",
11
+ category: "step",
12
+ description: "Coordinates multiple agents to perform tasks manually",
13
+ icon: "👀",
14
+ toolable: false,
15
+ group: 'IA',
16
+ tags: {
17
+ execution: 'async',
18
+ group: 'IA'
19
+ },
20
+ fields: [
21
+ {
22
+ id: "message",
23
+ label: "Message",
24
+ type: "string",
25
+ required: true,
26
+ handle: { type: 'input', label: 'Message', name: 'message', fieldType: 'string' }
27
+ },
28
+ {
29
+ id: "systemMessage",
30
+ label: "System Message",
31
+ type: "textarea",
32
+ required: false,
33
+ placeholder: "You are a supervisor... (use {members} to list agents)",
34
+ handle: {
35
+ type: "input",
36
+ label: "System Message",
37
+ name: "systemMessage",
38
+ fieldType: "string",
39
+ }
40
+ },
41
+ {
42
+ id: "model",
43
+ label: "Model",
44
+ type: "model",
45
+ typeable: false,
46
+ required: true,
47
+ handle: {
48
+ type: "input",
49
+ label: "Model",
50
+ name: "model",
51
+ fieldType: "model",
52
+ acceptTypes: ["model"],
53
+ maxConnections: 1,
54
+ }
55
+ },
56
+ {
57
+ id: 'agents',
58
+ label: 'Agents',
59
+ type: 'agent',
60
+ required: true,
61
+ typeable: false,
62
+ handle: {
63
+ type: 'input',
64
+ label: 'Agents',
65
+ name: 'agents',
66
+ fieldType: 'agent',
67
+ acceptTypes: ['agent'],
68
+ }
69
+ },
70
+ {
71
+ id: 'response',
72
+ label: 'Response',
73
+ type: 'string',
74
+ required: true,
75
+ typeable: false,
76
+ handle: {
77
+ type: 'output',
78
+ label: 'response',
79
+ name: 'response',
80
+ fieldType: 'string',
81
+ }
82
+ }
83
+ ]
84
+ };
@@ -0,0 +1,2 @@
1
+ export declare const AiSupervisorNodeFunction: (fieldValues: any) => Promise<any>;
2
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../../../../../libs/nodes/src/nodes/ia/supervisor/function.ts"],"names":[],"mappings":"AAwEA,eAAO,MAAM,wBAAwB,GAAU,aAAa,GAAG,KAAG,OAAO,CAAC,GAAG,CAmL5E,CAAA"}
@@ -0,0 +1,227 @@
1
+ "use server";
2
+ import { createSupervisor } from "@langchain/langgraph-supervisor";
3
+ import { HumanMessage } from "@langchain/core/messages";
4
+ import { InMemoryStore, MemorySaver } from "@langchain/langgraph";
5
+ import { createLLMFromModel } from "../../../utils/llm-factory";
6
+ const checkpointer = new MemorySaver();
7
+ const store = new InMemoryStore();
8
+ const extractSupervisorAgents = (agents) => {
9
+ if (Array.isArray(agents)) {
10
+ return agents.map((a) => a.agent).filter(Boolean);
11
+ }
12
+ if (agents?.agent) {
13
+ return [agents.agent];
14
+ }
15
+ return [agents];
16
+ };
17
+ const extractFinalResponse = (messages) => {
18
+ if (!messages || messages.length === 0)
19
+ return 'No response generated.';
20
+ // Heurísticas para ignorar mensagens de ferramenta/transferência
21
+ const isTransferOrToolMsg = (m) => {
22
+ const content = m?.content;
23
+ const name = m?.name;
24
+ const hasToolCallId = typeof m?.tool_call_id === 'string' || typeof m?.additional_kwargs?.tool_call_id === 'string';
25
+ const hasToolCalls = Array.isArray(m?.additional_kwargs?.tool_calls) && m.additional_kwargs.tool_calls.length > 0;
26
+ const contentStr = typeof content === 'string' ? content : '';
27
+ const nameStr = typeof name === 'string' ? name : '';
28
+ if (hasToolCallId || hasToolCalls)
29
+ return true;
30
+ if (/^Successfully transferred/i.test(contentStr))
31
+ return true;
32
+ if (/^Transferring back to supervisor/i.test(contentStr))
33
+ return true;
34
+ if (/^transfer_/i.test(nameStr))
35
+ return true;
36
+ return false;
37
+ };
38
+ // Preferir a última mensagem textual que não seja de ferramenta nem de transferência
39
+ for (let i = messages.length - 1; i >= 0; i--) {
40
+ const msg = messages[i];
41
+ if (isTransferOrToolMsg(msg))
42
+ continue;
43
+ const content = msg?.content;
44
+ if (typeof content === 'string' && content.trim())
45
+ return content;
46
+ if (Array.isArray(content)) {
47
+ const textContent = content
48
+ .map((part) => (part.type === 'text' ? part.text : ''))
49
+ .filter(Boolean)
50
+ .join('\n');
51
+ if (textContent.trim())
52
+ return textContent;
53
+ }
54
+ }
55
+ // Fallback: tenta última mensagem com conteúdo textual
56
+ const lastMessage = messages[messages.length - 1];
57
+ if (!lastMessage?.content)
58
+ return 'No response generated.';
59
+ if (typeof lastMessage.content === 'string')
60
+ return lastMessage.content;
61
+ if (Array.isArray(lastMessage.content)) {
62
+ const textContent = lastMessage.content
63
+ .map((part) => (part.type === 'text' ? part.text : ''))
64
+ .filter(Boolean)
65
+ .join('\n');
66
+ return textContent || JSON.stringify(lastMessage.content);
67
+ }
68
+ return 'No response generated.';
69
+ };
70
+ export const AiSupervisorNodeFunction = async (fieldValues) => {
71
+ // Merge outer-level (transport flags/emitter) with inner-level (node inputs)
72
+ const outer = fieldValues ?? {};
73
+ const inner = (outer && typeof outer === 'object' && outer.fieldValues && typeof outer.fieldValues === 'object') ? outer.fieldValues : {};
74
+ const model = inner.model ?? outer.model;
75
+ const agents = inner.agents ?? outer.agents;
76
+ const message = inner.message ?? outer.message;
77
+ const systemMessage = inner.systemMessage ?? outer.systemMessage;
78
+ const stream = (typeof outer.stream === 'boolean' ? outer.stream : inner.stream) ?? false;
79
+ const emitter = outer.emitter ?? inner.emitter;
80
+ const authToken = outer.authToken ?? inner.authToken;
81
+ if (!model)
82
+ throw new Error("Model is required for AiSupervisorNode");
83
+ if (!agents)
84
+ throw new Error("Agents are required for AiSupervisorNode.");
85
+ try {
86
+ const supervisorAgents = extractSupervisorAgents(agents);
87
+ if (supervisorAgents.length === 0)
88
+ throw new Error("No valid agents were extracted from the 'agents' input.");
89
+ if (supervisorAgents.some(agent => !agent.name))
90
+ throw new Error("All agents must have a name.");
91
+ // Instanciar LLM a partir do model config
92
+ let llmInstance;
93
+ if (model?.model && model?.integrationId) {
94
+ // Model é um objeto com integrationId, criar instância
95
+ if (!authToken) {
96
+ throw new Error("Auth token is required to instantiate LLM from integration 3");
97
+ }
98
+ llmInstance = await createLLMFromModel(model, authToken, stream);
99
+ }
100
+ else {
101
+ // Model já é uma instância de LLM
102
+ llmInstance = model;
103
+ }
104
+ const finalSystemPrompt = systemMessage || "You are a supervisor...";
105
+ const workflow = createSupervisor({
106
+ llm: llmInstance,
107
+ agents: supervisorAgents,
108
+ prompt: finalSystemPrompt,
109
+ });
110
+ const app = workflow.compile({
111
+ checkpointer,
112
+ store,
113
+ });
114
+ if (stream && emitter) {
115
+ try {
116
+ // Use a consistent thread_id to maintain conversation context
117
+ const streamIterator = await app.stream({ messages: [new HumanMessage({ content: message })] }, { recursionLimit: 150, configurable: { thread_id: 'conversation' } });
118
+ let finalMessages = [];
119
+ const previousStepMessages = new Map(); // Track message count per agent
120
+ const sentMessages = new Set(); // Track already sent messages by content hash
121
+ let stepCount = 0;
122
+ for await (const step of streamIterator) {
123
+ stepCount++;
124
+ // Process each agent in this step and show only NEW messages added in THIS step
125
+ if (step && typeof step === 'object') {
126
+ for (const [agentKey, agentData] of Object.entries(step)) {
127
+ if (agentData && typeof agentData === 'object' && 'messages' in agentData) {
128
+ const currentMessages = agentData.messages;
129
+ if (Array.isArray(currentMessages) && currentMessages.length > 0) {
130
+ finalMessages = currentMessages;
131
+ // Get how many messages this agent had in previous steps
132
+ const previousCount = previousStepMessages.get(agentKey) || 0;
133
+ const currentCount = currentMessages.length;
134
+ // Only show messages that are NEW in this step (beyond previous count)
135
+ if (currentCount > previousCount) {
136
+ const newMessages = currentMessages.slice(previousCount);
137
+ // Process each new message and create structured data
138
+ const structuredMessages = newMessages.map((msg) => {
139
+ const msgContent = msg?.content || '';
140
+ const msgName = msg?.name || '';
141
+ const toolCallId = msg?.tool_call_id;
142
+ // Detect if it's a tool message
143
+ const isTool = !!(toolCallId || msgName.includes('transfer_') || msgContent.includes('Successfully transferred'));
144
+ // Detect if it's an agent (not tool AND not supervisor)
145
+ const isAgent = !isTool && agentKey !== 'supervisor';
146
+ // Extract name (agent name or tool name)
147
+ let name = '';
148
+ if (isTool) {
149
+ if (msgName.includes('transfer_')) {
150
+ name = msgName;
151
+ }
152
+ else {
153
+ name = 'transfer_tool';
154
+ }
155
+ }
156
+ else if (isAgent) {
157
+ name = msgName || agentKey;
158
+ }
159
+ else {
160
+ // Always use 'supervisor' for supervisor messages
161
+ name = agentKey === 'supervisor' ? 'supervisor' : agentKey;
162
+ }
163
+ return {
164
+ isTool,
165
+ isAgent,
166
+ name,
167
+ message: msgContent.trim()
168
+ };
169
+ }).filter(item => item.message); // Only include messages with content
170
+ if (structuredMessages.length > 0) {
171
+ structuredMessages.forEach((structuredMsg) => {
172
+ // Create unique hash for deduplication
173
+ const messageHash = `${structuredMsg.name}-${structuredMsg.message.slice(0, 100)}`;
174
+ if (!sentMessages.has(messageHash)) {
175
+ sentMessages.add(messageHash);
176
+ // Send complete message via delta for natural streaming display
177
+ if (emitter?.emitDelta) {
178
+ emitter.emitDelta({
179
+ content: structuredMsg.message,
180
+ actor: structuredMsg.name,
181
+ isAgent: structuredMsg.isAgent,
182
+ isTool: structuredMsg.isTool
183
+ });
184
+ }
185
+ }
186
+ });
187
+ }
188
+ // Update the count for this agent
189
+ previousStepMessages.set(agentKey, currentCount);
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ const finalResponse = extractFinalResponse(finalMessages);
197
+ return {
198
+ output: finalResponse,
199
+ function: AiSupervisorNodeFunction,
200
+ type: "AiSupervisorNode"
201
+ };
202
+ }
203
+ catch (err) {
204
+ console.error('❌ Streaming error:', err);
205
+ throw err;
206
+ }
207
+ }
208
+ else {
209
+ // Use consistent thread_id for non-streaming mode too
210
+ const result = await app.invoke({ messages: [new HumanMessage({ content: message })] }, { recursionLimit: 150, configurable: { thread_id: 'conversation' } });
211
+ const finalResponse = extractFinalResponse(result?.messages);
212
+ return {
213
+ output: finalResponse,
214
+ function: AiSupervisorNodeFunction,
215
+ type: "AiSupervisorNode"
216
+ };
217
+ }
218
+ }
219
+ catch (error) {
220
+ console.error('❌ AiSupervisorNode - Error:', error);
221
+ return {
222
+ output: `Error: ${error instanceof Error ? error.message : String(error)}`,
223
+ function: AiSupervisorNodeFunction,
224
+ type: "AiSupervisorNode"
225
+ };
226
+ }
227
+ };
@@ -0,0 +1,3 @@
1
+ export * from './data';
2
+ export * from './function';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../libs/nodes/src/nodes/ia/supervisor/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './data';
2
+ export * from './function';
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ import { NodeData } from "../../types/base-node";
3
+ export declare const CustomToolSchema: z.ZodObject<{
4
+ input: z.ZodOptional<z.ZodString>;
5
+ }, z.core.$strip>;
6
+ export declare const AiToolNodeSchema: z.ZodObject<{
7
+ name: z.ZodString;
8
+ description: z.ZodString;
9
+ nodeFunction: z.ZodAny;
10
+ nodeType: z.ZodString;
11
+ originalNodeData: z.ZodOptional<z.ZodAny>;
12
+ workflowService: z.ZodOptional<z.ZodAny>;
13
+ currentResults: z.ZodOptional<z.ZodAny>;
14
+ }, z.core.$strip>;
15
+ export declare const AiToolNode: NodeData;
16
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../../../../libs/nodes/src/nodes/ia/tool/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,eAAO,MAAM,gBAAgB;;iBAE3B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;;;iBAS3B,CAAC;AAEH,eAAO,MAAM,UAAU,EAAE,QAsDxB,CAAA"}
@@ -0,0 +1,70 @@
1
+ import { z } from "zod";
2
+ // Schema para o CustomTool como fallback
3
+ export const CustomToolSchema = z.object({
4
+ input: z.string().optional().describe("Input for the tool"),
5
+ });
6
+ export const AiToolNodeSchema = z.object({
7
+ name: z.string().describe("Name of the tool"),
8
+ description: z.string().describe("Description of what the tool does"),
9
+ // z.function() não suporta .describe(), então usamos z.any() para aceitar qualquer função.
10
+ nodeFunction: z.any().describe("The function to execute"),
11
+ nodeType: z.string().describe("The type of the node the tool represents"),
12
+ originalNodeData: z.any().optional().describe("Original data of the node"),
13
+ workflowService: z.any().optional().describe("Service for workflow operations"),
14
+ currentResults: z.any().optional().describe("Current results in the workflow"),
15
+ });
16
+ export const AiToolNode = {
17
+ label: 'AI Tool',
18
+ type: 'AiToolNode',
19
+ category: 'step',
20
+ description: 'Wraps another node to be used as a tool by an AI agent',
21
+ icon: '🛠️',
22
+ group: 'IA',
23
+ tags: {
24
+ execution: 'async',
25
+ group: 'IA'
26
+ },
27
+ fields: [
28
+ {
29
+ id: 'name',
30
+ label: 'Name',
31
+ type: 'string',
32
+ required: true,
33
+ },
34
+ {
35
+ id: 'description',
36
+ label: 'Description',
37
+ type: 'string',
38
+ required: true,
39
+ },
40
+ {
41
+ id: 'function',
42
+ label: 'Function',
43
+ type: 'any', // Alterado para 'any' para corresponder ao schema z.any()
44
+ required: true,
45
+ typeable: false,
46
+ handle: {
47
+ type: 'input',
48
+ label: 'Input',
49
+ name: 'input',
50
+ fieldType: 'string',
51
+ required: true
52
+ }
53
+ },
54
+ {
55
+ id: 'tool',
56
+ label: 'Tool',
57
+ type: 'tool',
58
+ required: true,
59
+ typeable: false,
60
+ handle: {
61
+ type: 'output',
62
+ label: 'Tool',
63
+ name: 'tool',
64
+ fieldType: 'tool',
65
+ required: true,
66
+ acceptTypes: ['tool'],
67
+ }
68
+ }
69
+ ]
70
+ };
@@ -0,0 +1,4 @@
1
+ export declare const AiToolNodeFunction: (fieldValues: any) => Promise<{
2
+ tool: any;
3
+ }>;
4
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../../../../../libs/nodes/src/nodes/ia/tool/function.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,kBAAkB,GAAU,aAAa,GAAG,KAAG,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE,CAwChF,CAAA"}
@@ -0,0 +1,36 @@
1
+ "use server";
2
+ import { tool } from "@langchain/core/tools";
3
+ import { schemas } from "../../consts/schemas";
4
+ import { CustomToolSchema } from "./data";
5
+ export const AiToolNodeFunction = async (fieldValues) => {
6
+ const { name, description, nodeFunction, nodeType, originalNodeData, workflowService, currentResults } = fieldValues;
7
+ const schema = schemas[nodeType] || CustomToolSchema;
8
+ const dynamicTool = tool(async (args) => {
9
+ if (nodeFunction && typeof nodeFunction === 'function') {
10
+ try {
11
+ let resolvedInputs = originalNodeData?.inputs || {};
12
+ if (workflowService && currentResults && originalNodeData?.inputs) {
13
+ resolvedInputs = await workflowService.resolveInputs(originalNodeData.inputs, currentResults);
14
+ }
15
+ const combinedInputs = {
16
+ ...resolvedInputs,
17
+ ...args,
18
+ originalNodeData: originalNodeData
19
+ };
20
+ const result = await nodeFunction({ fieldValues: combinedInputs });
21
+ return result?.output || result;
22
+ }
23
+ catch (error) {
24
+ return `Error: ${error instanceof Error ? error.message : String(error)}`;
25
+ }
26
+ }
27
+ return 'Tool function not provided';
28
+ }, {
29
+ name: name || 'Dynamic Tool',
30
+ description: description || 'Tool created from workflow',
31
+ schema: schema,
32
+ });
33
+ return {
34
+ tool: dynamicTool
35
+ };
36
+ };
@@ -0,0 +1,3 @@
1
+ export * from './data';
2
+ export * from './function';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../libs/nodes/src/nodes/ia/tool/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './data';
2
+ export * from './function';
@@ -0,0 +1,9 @@
1
+ export * from './types/base-node';
2
+ export * from './types/base-node.types';
3
+ export { default as nodes } from './consts/nodes';
4
+ export { default as nodeFunctions } from './consts/node-functions';
5
+ export * from './ia';
6
+ export * from './inputs/http';
7
+ export * from './consts/schemas';
8
+ export * from './social';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../libs/nodes/src/nodes/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACnE,cAAc,MAAM,CAAC;AACrB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from './types/base-node';
2
+ export * from './types/base-node.types';
3
+ export { default as nodes } from './consts/nodes';
4
+ export { default as nodeFunctions } from './consts/node-functions';
5
+ export * from './ia';
6
+ export * from './inputs/http';
7
+ export * from './consts/schemas';
8
+ export * from './social';
@@ -0,0 +1,4 @@
1
+ import { NodeData } from "../../types/base-node";
2
+ export declare const ChatInputNodeFunction: (params: any) => any;
3
+ export declare const ChatInputNode: NodeData;
4
+ //# sourceMappingURL=chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../../../../../libs/nodes/src/nodes/inputs/chat/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,eAAO,MAAM,qBAAqB,GAAI,QAAQ,GAAG,KAAG,GAcnD,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,QAsC3B,CAAC"}
@@ -0,0 +1,51 @@
1
+ export const ChatInputNodeFunction = (params) => {
2
+ const { request, fieldValues } = params;
3
+ const { message: configMessage, chatId: configChatId } = fieldValues || {};
4
+ const actualData = {
5
+ message: request?.message ?? configMessage ?? "",
6
+ chatId: request?.chatId ?? configChatId ?? null,
7
+ };
8
+ if (!actualData.message || typeof actualData.message !== "string") {
9
+ throw new Error("Message is required for ChatInputNode");
10
+ }
11
+ return actualData;
12
+ };
13
+ export const ChatInputNode = {
14
+ label: "Chat Input",
15
+ type: "ChatInput",
16
+ category: "input",
17
+ icon: "💬",
18
+ description: "Entrada de mensagem de chat para iniciar conversas com IA",
19
+ tags: {
20
+ execution: "sync",
21
+ group: "IA",
22
+ },
23
+ fields: [
24
+ {
25
+ id: "message",
26
+ label: "Message",
27
+ type: "string",
28
+ required: true,
29
+ typeable: false,
30
+ handle: {
31
+ type: "output",
32
+ label: "Message",
33
+ name: "message",
34
+ fieldType: "string",
35
+ },
36
+ },
37
+ {
38
+ id: "chatId",
39
+ label: "Chat ID",
40
+ type: "string",
41
+ required: true,
42
+ typeable: false,
43
+ handle: {
44
+ type: "output",
45
+ label: "Chat ID",
46
+ name: "chatId",
47
+ fieldType: "string",
48
+ },
49
+ },
50
+ ],
51
+ };
@@ -0,0 +1,3 @@
1
+ import { NodeData } from "../../../types/base-node";
2
+ export declare const HttpDeleteInputNode: NodeData;
3
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/nodes/src/nodes/inputs/http/delete/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,eAAO,MAAM,mBAAmB,EAAE,QAwDjC,CAAC"}
@@ -0,0 +1,57 @@
1
+ export const HttpDeleteInputNode = {
2
+ label: 'Http DELETE Input',
3
+ type: 'HttpDeleteInput',
4
+ category: 'input',
5
+ icon: '🗑️',
6
+ description: 'Node que representa uma rota DELETE HTTP para remoção de recursos',
7
+ tags: {
8
+ execution: 'sync',
9
+ group: 'HTTP'
10
+ },
11
+ fields: [
12
+ {
13
+ id: 'route',
14
+ label: 'Route',
15
+ type: 'route',
16
+ required: true,
17
+ placeholder: '/produtos/{id}',
18
+ },
19
+ {
20
+ id: 'queryParams',
21
+ label: 'Query Params',
22
+ type: 'keyValue',
23
+ required: false,
24
+ handle: {
25
+ type: 'output',
26
+ label: 'Query Params',
27
+ name: 'queryParams',
28
+ fieldType: 'keyValue',
29
+ }
30
+ },
31
+ {
32
+ id: 'headers',
33
+ label: 'Headers',
34
+ type: 'keyValue',
35
+ required: false,
36
+ handle: {
37
+ type: 'output',
38
+ label: 'Headers',
39
+ name: 'headers',
40
+ fieldType: 'keyValue',
41
+ }
42
+ },
43
+ {
44
+ id: 'ip',
45
+ label: 'Request IP',
46
+ type: 'string',
47
+ required: false,
48
+ typeable: false,
49
+ handle: {
50
+ type: 'output',
51
+ label: 'IP',
52
+ name: 'ip',
53
+ fieldType: 'string',
54
+ }
55
+ }
56
+ ]
57
+ };
@@ -0,0 +1,2 @@
1
+ export declare const HttpDeleteInputNodeFunction: (params: any) => Promise<any>;
2
+ //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../../../../../../libs/nodes/src/nodes/inputs/http/delete/function.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,2BAA2B,GAAU,QAAQ,GAAG,KAAG,OAAO,CAAC,GAAG,CA+B1E,CAAC"}