@n8n/n8n-nodes-langchain 1.112.2 → 1.113.1

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 (30) hide show
  1. package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js +7 -1
  2. package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js.map +1 -1
  3. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js +13 -18
  4. package/dist/nodes/mcp/McpClientTool/McpClientTool.node.js.map +1 -1
  5. package/dist/nodes/mcp/McpClientTool/descriptions.js +49 -0
  6. package/dist/nodes/mcp/McpClientTool/descriptions.js.map +1 -0
  7. package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js +24 -1
  8. package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js.map +1 -1
  9. package/dist/nodes/tools/ToolCode/ToolCode.node.js +122 -102
  10. package/dist/nodes/tools/ToolCode/ToolCode.node.js.map +1 -1
  11. package/dist/nodes/tools/ToolSearXng/ToolSearXng.node.js +29 -10
  12. package/dist/nodes/tools/ToolSearXng/ToolSearXng.node.js.map +1 -1
  13. package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js +22 -3
  14. package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js.map +1 -1
  15. package/dist/nodes/tools/ToolThink/ToolThink.node.js +32 -11
  16. package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -1
  17. package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js +42 -21
  18. package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js.map +1 -1
  19. package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js +24 -3
  20. package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js.map +1 -1
  21. package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js +18 -0
  22. package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js.map +1 -1
  23. package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js +30 -13
  24. package/dist/nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.js.map +1 -1
  25. package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +27 -19
  26. package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
  27. package/dist/nodes/trigger/ChatTrigger/constants.js +2 -2
  28. package/dist/nodes/trigger/ChatTrigger/constants.js.map +1 -1
  29. package/dist/types/nodes.json +2 -2
  30. package/package.json +8 -8
@@ -25,6 +25,21 @@ var import_n8n_workflow = require("n8n-workflow");
25
25
  var import_methods = require("./methods");
26
26
  var import_WorkflowToolService = require("./utils/WorkflowToolService");
27
27
  var import_versionDescription = require("./versionDescription");
28
+ async function getTool(ctx, enableLogging, itemIndex) {
29
+ const node = ctx.getNode();
30
+ const { typeVersion } = node;
31
+ const returnAllItems = typeVersion > 2;
32
+ const workflowToolService = new import_WorkflowToolService.WorkflowToolService(ctx, { returnAllItems });
33
+ const name = typeVersion <= 2.1 ? ctx.getNodeParameter("name", 0) : (0, import_n8n_workflow.nodeNameToToolName)(node);
34
+ const description = ctx.getNodeParameter("description", 0);
35
+ return await workflowToolService.createTool({
36
+ ctx,
37
+ name,
38
+ description,
39
+ itemIndex,
40
+ manualLogging: enableLogging
41
+ });
42
+ }
28
43
  class ToolWorkflowV2 {
29
44
  constructor(baseDescription) {
30
45
  this.methods = {
@@ -36,19 +51,21 @@ class ToolWorkflowV2 {
36
51
  };
37
52
  }
38
53
  async supplyData(itemIndex) {
39
- const node = this.getNode();
40
- const { typeVersion } = node;
41
- const returnAllItems = typeVersion > 2;
42
- const workflowToolService = new import_WorkflowToolService.WorkflowToolService(this, { returnAllItems });
43
- const name = typeVersion <= 2.1 ? this.getNodeParameter("name", itemIndex) : (0, import_n8n_workflow.nodeNameToToolName)(node);
44
- const description = this.getNodeParameter("description", itemIndex);
45
- const tool = await workflowToolService.createTool({
46
- ctx: this,
47
- name,
48
- description,
49
- itemIndex
50
- });
51
- return { response: tool };
54
+ return { response: await getTool(this, true, itemIndex) };
55
+ }
56
+ async execute() {
57
+ const items = this.getInputData();
58
+ const response = [];
59
+ for (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {
60
+ const item = items[itemIndex];
61
+ const tool = await getTool(this, false, itemIndex);
62
+ if (item === void 0) {
63
+ continue;
64
+ }
65
+ const result = await tool.invoke(item.json);
66
+ response.push(result);
67
+ }
68
+ return [response];
52
69
  }
53
70
  }
54
71
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.ts"],"sourcesContent":["import type {\n\tINodeTypeBaseDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\n\nimport { nodeNameToToolName } from 'n8n-workflow';\n\nimport { localResourceMapping } from './methods';\nimport { WorkflowToolService } from './utils/WorkflowToolService';\nimport { versionDescription } from './versionDescription';\n\nexport class ToolWorkflowV2 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\t...versionDescription,\n\t\t};\n\t}\n\n\tmethods = {\n\t\tlocalResourceMapping,\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst node = this.getNode();\n\t\tconst { typeVersion } = node;\n\t\tconst returnAllItems = typeVersion > 2;\n\n\t\tconst workflowToolService = new WorkflowToolService(this, { returnAllItems });\n\t\tconst name =\n\t\t\ttypeVersion <= 2.1\n\t\t\t\t? (this.getNodeParameter('name', itemIndex) as string)\n\t\t\t\t: nodeNameToToolName(node);\n\t\tconst description = this.getNodeParameter('description', itemIndex) as string;\n\n\t\tconst tool = await workflowToolService.createTool({\n\t\t\tctx: this,\n\t\t\tname,\n\t\t\tdescription,\n\t\t\titemIndex,\n\t\t});\n\n\t\treturn { response: tool };\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,0BAAmC;AAEnC,qBAAqC;AACrC,iCAAoC;AACpC,gCAAmC;AAE5B,MAAM,eAAoC;AAAA,EAGhD,YAAY,iBAA2C;AAOvD,mBAAU;AAAA,MACT;AAAA,IACD;AARC,SAAK,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,GAAG;AAAA,IACJ;AAAA,EACD;AAAA,EAMA,MAAM,WAAuC,WAAwC;AACpF,UAAM,OAAO,KAAK,QAAQ;AAC1B,UAAM,EAAE,YAAY,IAAI;AACxB,UAAM,iBAAiB,cAAc;AAErC,UAAM,sBAAsB,IAAI,+CAAoB,MAAM,EAAE,eAAe,CAAC;AAC5E,UAAM,OACL,eAAe,MACX,KAAK,iBAAiB,QAAQ,SAAS,QACxC,wCAAmB,IAAI;AAC3B,UAAM,cAAc,KAAK,iBAAiB,eAAe,SAAS;AAElE,UAAM,OAAO,MAAM,oBAAoB,WAAW;AAAA,MACjD,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACD,CAAC;AAED,WAAO,EAAE,UAAU,KAAK;AAAA,EACzB;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.ts"],"sourcesContent":["import type { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';\n\nimport type {\n\tINodeTypeBaseDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n\tINodeType,\n\tINodeTypeDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n} from 'n8n-workflow';\nimport { nodeNameToToolName } from 'n8n-workflow';\n\nimport { localResourceMapping } from './methods';\nimport { WorkflowToolService } from './utils/WorkflowToolService';\nimport { versionDescription } from './versionDescription';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\tenableLogging: boolean,\n\titemIndex: number,\n): Promise<DynamicTool | DynamicStructuredTool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\tconst returnAllItems = typeVersion > 2;\n\n\tconst workflowToolService = new WorkflowToolService(ctx, { returnAllItems });\n\tconst name =\n\t\ttypeVersion <= 2.1 ? (ctx.getNodeParameter('name', 0) as string) : nodeNameToToolName(node);\n\tconst description = ctx.getNodeParameter('description', 0) as string;\n\n\treturn await workflowToolService.createTool({\n\t\tctx,\n\t\tname,\n\t\tdescription,\n\t\titemIndex,\n\t\tmanualLogging: enableLogging,\n\t});\n}\n\nexport class ToolWorkflowV2 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\t...versionDescription,\n\t\t};\n\t}\n\n\tmethods = {\n\t\tlocalResourceMapping,\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\treturn { response: await getTool(this, true, itemIndex) };\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst items = this.getInputData();\n\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tconst tool = await getTool(this, false, itemIndex);\n\n\t\t\tif (item === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = await tool.invoke(item.json);\n\t\t\tresponse.push(result);\n\t\t}\n\n\t\treturn [response];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,0BAAmC;AAEnC,qBAAqC;AACrC,iCAAoC;AACpC,gCAAmC;AAEnC,eAAe,QACd,KACA,eACA,WAC+C;AAC/C,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,iBAAiB,cAAc;AAErC,QAAM,sBAAsB,IAAI,+CAAoB,KAAK,EAAE,eAAe,CAAC;AAC3E,QAAM,OACL,eAAe,MAAO,IAAI,iBAAiB,QAAQ,CAAC,QAAe,wCAAmB,IAAI;AAC3F,QAAM,cAAc,IAAI,iBAAiB,eAAe,CAAC;AAEzD,SAAO,MAAM,oBAAoB,WAAW;AAAA,IAC3C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,EAChB,CAAC;AACF;AAEO,MAAM,eAAoC;AAAA,EAGhD,YAAY,iBAA2C;AAOvD,mBAAU;AAAA,MACT;AAAA,IACD;AARC,SAAK,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,GAAG;AAAA,IACJ;AAAA,EACD;AAAA,EAMA,MAAM,WAAuC,WAAwC;AACpF,WAAO,EAAE,UAAU,MAAM,QAAQ,MAAM,MAAM,SAAS,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,QAAQ,KAAK,aAAa;AAEhC,UAAM,WAAiC,CAAC;AACxC,aAAS,YAAY,GAAG,YAAY,KAAK,aAAa,EAAE,QAAQ,aAAa;AAC5E,YAAM,OAAO,MAAM,SAAS;AAC5B,YAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,SAAS;AAEjD,UAAI,SAAS,QAAW;AACvB;AAAA,MACD;AACA,YAAM,SAAS,MAAM,KAAK,OAAO,KAAK,IAAI;AAC1C,eAAS,KAAK,MAAM;AAAA,IACrB;AAEA,WAAO,CAAC,QAAQ;AAAA,EACjB;AACD;","names":[]}
@@ -54,10 +54,11 @@ class WorkflowToolService {
54
54
  ctx,
55
55
  name,
56
56
  description,
57
- itemIndex
57
+ itemIndex,
58
+ manualLogging = true
58
59
  }) {
59
60
  const node = ctx.getNode();
60
- let runIndex = ctx.getNextRunIndex();
61
+ let runIndex = "getNextRunIndex" in ctx ? ctx.getNextRunIndex() : 0;
61
62
  const toolHandler = async (query, runManager) => {
62
63
  let maxTries = 1;
63
64
  if (node.retryOnFail === true) {
@@ -70,10 +71,13 @@ class WorkflowToolService {
70
71
  let lastError;
71
72
  for (let tryIndex = 0; tryIndex < maxTries; tryIndex++) {
72
73
  const localRunIndex = runIndex++;
73
- const context = this.baseContext.cloneWith({
74
- runIndex: localRunIndex,
75
- inputData: [[{ json: { query } }]]
76
- });
74
+ let context = this.baseContext;
75
+ if ("cloneWith" in this.baseContext) {
76
+ context = this.baseContext.cloneWith({
77
+ runIndex: localRunIndex,
78
+ inputData: [[{ json: { query } }]]
79
+ });
80
+ }
77
81
  const abortSignal = context.getExecutionCancelSignal?.();
78
82
  if (abortSignal?.aborted) {
79
83
  return 'There was an error: "Execution was cancelled"';
@@ -109,12 +113,14 @@ class WorkflowToolService {
109
113
  }
110
114
  };
111
115
  }
112
- void context.addOutputData(
113
- import_n8n_workflow.NodeConnectionTypes.AiTool,
114
- localRunIndex,
115
- [responseData],
116
- metadata
117
- );
116
+ if (manualLogging) {
117
+ void context.addOutputData(
118
+ import_n8n_workflow.NodeConnectionTypes.AiTool,
119
+ localRunIndex,
120
+ [responseData],
121
+ metadata
122
+ );
123
+ }
118
124
  return processedResponse;
119
125
  } catch (error) {
120
126
  if (abortSignal?.aborted) {
@@ -123,13 +129,15 @@ class WorkflowToolService {
123
129
  const executionError = error;
124
130
  lastError = executionError;
125
131
  const errorResponse = `There was an error: "${executionError.message}"`;
126
- const metadata = (0, import_n8n_workflow.parseErrorMetadata)(error);
127
- void context.addOutputData(
128
- import_n8n_workflow.NodeConnectionTypes.AiTool,
129
- localRunIndex,
130
- executionError,
131
- metadata
132
- );
132
+ if (manualLogging) {
133
+ const metadata = (0, import_n8n_workflow.parseErrorMetadata)(error);
134
+ void context.addOutputData(
135
+ import_n8n_workflow.NodeConnectionTypes.AiTool,
136
+ localRunIndex,
137
+ executionError,
138
+ metadata
139
+ );
140
+ }
133
141
  if (tryIndex === maxTries - 1) {
134
142
  return errorResponse;
135
143
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.ts"],"sourcesContent":["import type { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';\nimport { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';\nimport isArray from 'lodash/isArray';\nimport isObject from 'lodash/isObject';\nimport type { SetField, SetNodeOptions } from 'n8n-nodes-base/dist/nodes/Set/v2/helpers/interfaces';\nimport * as manual from 'n8n-nodes-base/dist/nodes/Set/v2/manual.mode';\nimport { getCurrentWorkflowInputData } from 'n8n-nodes-base/dist/utils/workflowInputsResourceMapping/GenericFunctions';\nimport type {\n\tExecuteWorkflowData,\n\tExecutionError,\n\tFromAIArgument,\n\tIDataObject,\n\tIExecuteWorkflowInfo,\n\tINodeExecutionData,\n\tINodeParameterResourceLocator,\n\tISupplyDataFunctions,\n\tITaskMetadata,\n\tIWorkflowBase,\n\tIWorkflowDataProxyData,\n\tResourceMapperValue,\n} from 'n8n-workflow';\nimport {\n\tgenerateZodSchema,\n\tjsonParse,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\tparseErrorMetadata,\n\tsleepWithAbort,\n\ttraverseNodeParameters,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nfunction isNodeExecutionData(data: unknown): data is INodeExecutionData[] {\n\treturn isArray(data) && Boolean(data.length) && isObject(data[0]) && 'json' in data[0];\n}\n\n/**\n\tMain class for creating the Workflow tool\n\tProcesses the node parameters and creates AI Agent tool capable of executing n8n workflows\n*/\nexport class WorkflowToolService {\n\t// Determines if we should use input schema when creating the tool\n\tprivate useSchema: boolean;\n\n\t// Sub-workflow id, pulled from referenced sub-workflow\n\tprivate subWorkflowId: string | undefined;\n\n\t// Sub-workflow execution id, will be set after the sub-workflow is executed\n\tprivate subExecutionId: string | undefined;\n\n\tprivate returnAllItems: boolean = false;\n\n\tconstructor(\n\t\tprivate baseContext: ISupplyDataFunctions,\n\t\toptions?: { returnAllItems: boolean },\n\t) {\n\t\tconst subWorkflowInputs = this.baseContext.getNode().parameters\n\t\t\t.workflowInputs as ResourceMapperValue;\n\t\tthis.useSchema = (subWorkflowInputs?.schema ?? []).length > 0;\n\t\tthis.returnAllItems = options?.returnAllItems ?? false;\n\t}\n\n\t// Creates the tool based on the provided parameters\n\tasync createTool({\n\t\tctx,\n\t\tname,\n\t\tdescription,\n\t\titemIndex,\n\t}: {\n\t\tctx: ISupplyDataFunctions;\n\t\tname: string;\n\t\tdescription: string;\n\t\titemIndex: number;\n\t}): Promise<DynamicTool | DynamicStructuredTool> {\n\t\t// Handler for the tool execution, will be called when the tool is executed\n\t\t// This function will execute the sub-workflow and return the response\n\t\t// We get the runIndex from the context to handle multiple executions\n\t\t// of the same tool when the tool is used in a loop or in a parallel execution.\n\t\tconst node = ctx.getNode();\n\n\t\tlet runIndex: number = ctx.getNextRunIndex();\n\t\tconst toolHandler = async (\n\t\t\tquery: string | IDataObject,\n\t\t\trunManager?: CallbackManagerForToolRun,\n\t\t): Promise<IDataObject | IDataObject[] | string> => {\n\t\t\tlet maxTries = 1;\n\t\t\tif (node.retryOnFail === true) {\n\t\t\t\tmaxTries = Math.min(5, Math.max(2, node.maxTries ?? 3));\n\t\t\t}\n\n\t\t\tlet waitBetweenTries = 0;\n\t\t\tif (node.retryOnFail === true) {\n\t\t\t\twaitBetweenTries = Math.min(5000, Math.max(0, node.waitBetweenTries ?? 1000));\n\t\t\t}\n\n\t\t\tlet lastError: ExecutionError | undefined;\n\n\t\t\tfor (let tryIndex = 0; tryIndex < maxTries; tryIndex++) {\n\t\t\t\tconst localRunIndex = runIndex++;\n\t\t\t\t// We need to clone the context here to handle runIndex correctly\n\t\t\t\t// Otherwise the runIndex will be shared between different executions\n\t\t\t\t// Causing incorrect data to be passed to the sub-workflow and via $fromAI\n\t\t\t\tconst context = this.baseContext.cloneWith({\n\t\t\t\t\trunIndex: localRunIndex,\n\t\t\t\t\tinputData: [[{ json: { query } }]],\n\t\t\t\t});\n\n\t\t\t\t// Get abort signal from context for cancellation support\n\t\t\t\tconst abortSignal = context.getExecutionCancelSignal?.();\n\n\t\t\t\t// Check if execution was cancelled before retry\n\t\t\t\tif (abortSignal?.aborted) {\n\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t}\n\n\t\t\t\tif (tryIndex !== 0) {\n\t\t\t\t\t// Reset error from previous attempt\n\t\t\t\t\tlastError = undefined;\n\t\t\t\t\tif (waitBetweenTries !== 0) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait sleepWithAbort(waitBetweenTries, abortSignal);\n\t\t\t\t\t\t} catch (abortError) {\n\t\t\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await this.runFunction(context, query, itemIndex, runManager);\n\n\t\t\t\t\tconst processedResponse = this.handleToolResponse(response);\n\n\t\t\t\t\tlet responseData: INodeExecutionData[];\n\t\t\t\t\tif (isNodeExecutionData(response)) {\n\t\t\t\t\t\tresponseData = response;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst reParsedData = jsonParse<IDataObject>(processedResponse, {\n\t\t\t\t\t\t\tfallbackValue: { response: processedResponse },\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tresponseData = [{ json: reParsedData }];\n\t\t\t\t\t}\n\n\t\t\t\t\t// Once the sub-workflow is executed, add the output data to the context\n\t\t\t\t\t// This will be used to link the sub-workflow execution in the parent workflow\n\t\t\t\t\tlet metadata: ITaskMetadata | undefined;\n\t\t\t\t\tif (this.subExecutionId && this.subWorkflowId) {\n\t\t\t\t\t\tmetadata = {\n\t\t\t\t\t\t\tsubExecution: {\n\t\t\t\t\t\t\t\texecutionId: this.subExecutionId,\n\t\t\t\t\t\t\t\tworkflowId: this.subWorkflowId,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tvoid context.addOutputData(\n\t\t\t\t\t\tNodeConnectionTypes.AiTool,\n\t\t\t\t\t\tlocalRunIndex,\n\t\t\t\t\t\t[responseData],\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t);\n\n\t\t\t\t\treturn processedResponse;\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Check if error is due to cancellation\n\t\t\t\t\tif (abortSignal?.aborted) {\n\t\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t\t}\n\n\t\t\t\t\tconst executionError = error as ExecutionError;\n\t\t\t\t\tlastError = executionError;\n\t\t\t\t\tconst errorResponse = `There was an error: \"${executionError.message}\"`;\n\n\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\tvoid context.addOutputData(\n\t\t\t\t\t\tNodeConnectionTypes.AiTool,\n\t\t\t\t\t\tlocalRunIndex,\n\t\t\t\t\t\texecutionError,\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (tryIndex === maxTries - 1) {\n\t\t\t\t\t\treturn errorResponse;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn `There was an error: ${lastError?.message ?? 'Unknown error'}`;\n\t\t};\n\n\t\t// Create structured tool if input schema is provided\n\t\treturn this.useSchema\n\t\t\t? await this.createStructuredTool(name, description, toolHandler)\n\t\t\t: new DynamicTool({ name, description, func: toolHandler });\n\t}\n\n\tprivate handleToolResponse(response: unknown): string {\n\t\tif (typeof response === 'number') {\n\t\t\treturn response.toString();\n\t\t}\n\n\t\tif (isNodeExecutionData(response)) {\n\t\t\treturn JSON.stringify(\n\t\t\t\tresponse.map((item) => item.json),\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t);\n\t\t}\n\n\t\tif (isObject(response)) {\n\t\t\treturn JSON.stringify(response, null, 2);\n\t\t}\n\n\t\tif (typeof response !== 'string') {\n\t\t\tthrow new NodeOperationError(this.baseContext.getNode(), 'Wrong output type returned', {\n\t\t\t\tdescription: `The response property should be a string, but it is an ${typeof response}`,\n\t\t\t});\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Executes specified sub-workflow with provided inputs\n\t */\n\tprivate async executeSubWorkflow(\n\t\tcontext: ISupplyDataFunctions,\n\t\tworkflowInfo: IExecuteWorkflowInfo,\n\t\titems: INodeExecutionData[],\n\t\tworkflowProxy: IWorkflowDataProxyData,\n\t\trunManager?: CallbackManagerForToolRun,\n\t): Promise<{ response: string | IDataObject | INodeExecutionData[]; subExecutionId: string }> {\n\t\tlet receivedData: ExecuteWorkflowData;\n\t\ttry {\n\t\t\treceivedData = await context.executeWorkflow(workflowInfo, items, runManager?.getChild(), {\n\t\t\t\tparentExecution: {\n\t\t\t\t\texecutionId: workflowProxy.$execution.id,\n\t\t\t\t\tworkflowId: workflowProxy.$workflow.id,\n\t\t\t\t},\n\t\t\t});\n\t\t\t// Set sub-workflow execution id so it can be used in other places\n\t\t\tthis.subExecutionId = receivedData.executionId;\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), error as Error);\n\t\t}\n\n\t\tlet response: IDataObject | INodeExecutionData[] | undefined;\n\t\tif (this.returnAllItems) {\n\t\t\tresponse = receivedData?.data?.[0]?.length ? receivedData.data[0] : undefined;\n\t\t} else {\n\t\t\tresponse = receivedData?.data?.[0]?.[0]?.json;\n\t\t}\n\t\tif (response === undefined) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tcontext.getNode(),\n\t\t\t\t'There was an error: \"The workflow did not return a response\"',\n\t\t\t);\n\t\t}\n\n\t\treturn { response, subExecutionId: receivedData.executionId };\n\t}\n\n\t/**\n\t * Gets the sub-workflow info based on the source and executes it.\n\t * This function will be called as part of the tool execution (from the toolHandler)\n\t */\n\tprivate async runFunction(\n\t\tcontext: ISupplyDataFunctions,\n\t\tquery: string | IDataObject,\n\t\titemIndex: number,\n\t\trunManager?: CallbackManagerForToolRun,\n\t): Promise<string | IDataObject | INodeExecutionData[]> {\n\t\tconst source = context.getNodeParameter('source', itemIndex) as string;\n\t\tconst workflowProxy = context.getWorkflowDataProxy(0);\n\n\t\tconst { workflowInfo } = await this.getSubWorkflowInfo(\n\t\t\tcontext,\n\t\t\tsource,\n\t\t\titemIndex,\n\t\t\tworkflowProxy,\n\t\t);\n\t\tconst rawData = this.prepareRawData(context, query, itemIndex);\n\t\tconst items = await this.prepareWorkflowItems(context, query, itemIndex, rawData);\n\n\t\tthis.subWorkflowId = workflowInfo.id;\n\n\t\tconst { response } = await this.executeSubWorkflow(\n\t\t\tcontext,\n\t\t\tworkflowInfo,\n\t\t\titems,\n\t\t\tworkflowProxy,\n\t\t\trunManager,\n\t\t);\n\t\treturn response;\n\t}\n\n\t/**\n\t * Gets the sub-workflow info based on the source (database or parameter)\n\t */\n\tprivate async getSubWorkflowInfo(\n\t\tcontext: ISupplyDataFunctions,\n\t\tsource: string,\n\t\titemIndex: number,\n\t\tworkflowProxy: IWorkflowDataProxyData,\n\t): Promise<{\n\t\tworkflowInfo: IExecuteWorkflowInfo;\n\t\tsubWorkflowId: string;\n\t}> {\n\t\tconst workflowInfo: IExecuteWorkflowInfo = {};\n\t\tlet subWorkflowId: string;\n\n\t\tif (source === 'database') {\n\t\t\tconst { value } = context.getNodeParameter(\n\t\t\t\t'workflowId',\n\t\t\t\titemIndex,\n\t\t\t\t{},\n\t\t\t) as INodeParameterResourceLocator;\n\t\t\tworkflowInfo.id = value as string;\n\t\t\tsubWorkflowId = workflowInfo.id;\n\t\t} else if (source === 'parameter') {\n\t\t\tconst workflowJson = context.getNodeParameter('workflowJson', itemIndex) as string;\n\t\t\ttry {\n\t\t\t\tworkflowInfo.code = JSON.parse(workflowJson) as IWorkflowBase;\n\t\t\t\t// subworkflow is same as parent workflow\n\t\t\t\tsubWorkflowId = workflowProxy.$workflow.id;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\tcontext.getNode(),\n\t\t\t\t\t`The provided workflow is not valid JSON: \"${(error as Error).message}\"`,\n\t\t\t\t\t{ itemIndex },\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn { workflowInfo, subWorkflowId: subWorkflowId! };\n\t}\n\n\tprivate prepareRawData(\n\t\tcontext: ISupplyDataFunctions,\n\t\tquery: string | IDataObject,\n\t\titemIndex: number,\n\t): IDataObject {\n\t\tconst rawData: IDataObject = { query };\n\t\tconst workflowFieldsJson = context.getNodeParameter('fields.values', itemIndex, [], {\n\t\t\trawExpressions: true,\n\t\t}) as SetField[];\n\n\t\t// Copied from Set Node v2\n\t\tfor (const entry of workflowFieldsJson) {\n\t\t\tif (entry.type === 'objectValue' && (entry.objectValue as string).startsWith('=')) {\n\t\t\t\trawData[entry.name] = (entry.objectValue as string).replace(/^=+/, '');\n\t\t\t}\n\t\t}\n\n\t\treturn rawData;\n\t}\n\n\t/**\n\t * Prepares the sub-workflow items for execution\n\t */\n\tprivate async prepareWorkflowItems(\n\t\tcontext: ISupplyDataFunctions,\n\t\tquery: string | IDataObject,\n\t\titemIndex: number,\n\t\trawData: IDataObject,\n\t): Promise<INodeExecutionData[]> {\n\t\tconst options: SetNodeOptions = { include: 'all' };\n\t\tlet jsonData = typeof query === 'object' ? query : { query };\n\n\t\tif (this.useSchema) {\n\t\t\tconst currentWorkflowInputs = getCurrentWorkflowInputData.call(context);\n\t\t\tjsonData = currentWorkflowInputs[itemIndex].json;\n\t\t}\n\n\t\tconst newItem = await manual.execute.call(\n\t\t\tcontext,\n\t\t\t{ json: jsonData },\n\t\t\titemIndex,\n\t\t\toptions,\n\t\t\trawData,\n\t\t\tcontext.getNode(),\n\t\t);\n\n\t\treturn [newItem] as INodeExecutionData[];\n\t}\n\n\t/**\n\t * Create structured tool by parsing the sub-workflow input schema\n\t */\n\tprivate async createStructuredTool(\n\t\tname: string,\n\t\tdescription: string,\n\t\tfunc: (\n\t\t\tquery: string | IDataObject,\n\t\t\trunManager?: CallbackManagerForToolRun,\n\t\t) => Promise<string | IDataObject | IDataObject[]>,\n\t): Promise<DynamicStructuredTool | DynamicTool> {\n\t\tconst collectedArguments = await this.extractFromAIParameters();\n\n\t\t// If there are no `fromAI` arguments, fallback to creating a simple tool\n\t\tif (collectedArguments.length === 0) {\n\t\t\treturn new DynamicTool({ name, description, func });\n\t\t}\n\n\t\t// Otherwise, prepare Zod schema and create a structured tool\n\t\tconst schema = this.createZodSchema(collectedArguments);\n\t\treturn new DynamicStructuredTool({ schema, name, description, func });\n\t}\n\n\tprivate async extractFromAIParameters(): Promise<FromAIArgument[]> {\n\t\tconst collectedArguments: FromAIArgument[] = [];\n\t\ttraverseNodeParameters(this.baseContext.getNode().parameters, collectedArguments);\n\n\t\tconst uniqueArgsMap = new Map<string, FromAIArgument>();\n\t\tfor (const arg of collectedArguments) {\n\t\t\tuniqueArgsMap.set(arg.key, arg);\n\t\t}\n\n\t\treturn Array.from(uniqueArgsMap.values());\n\t}\n\n\tprivate createZodSchema(args: FromAIArgument[]): z.ZodObject<any> {\n\t\tconst schemaObj = args.reduce((acc: Record<string, z.ZodTypeAny>, placeholder) => {\n\t\t\tacc[placeholder.key] = generateZodSchema(placeholder);\n\t\t\treturn acc;\n\t\t}, {});\n\n\t\treturn z.object(schemaObj).required();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmD;AACnD,qBAAoB;AACpB,sBAAqB;AAErB,aAAwB;AACxB,8BAA4C;AAe5C,0BAQO;AACP,iBAAkB;AAElB,SAAS,oBAAoB,MAA6C;AACzE,aAAO,eAAAA,SAAQ,IAAI,KAAK,QAAQ,KAAK,MAAM,SAAK,gBAAAC,SAAS,KAAK,CAAC,CAAC,KAAK,UAAU,KAAK,CAAC;AACtF;AAMO,MAAM,oBAAoB;AAAA,EAYhC,YACS,aACR,SACC;AAFO;AAHT,SAAQ,iBAA0B;AAMjC,UAAM,oBAAoB,KAAK,YAAY,QAAQ,EAAE,WACnD;AACF,SAAK,aAAa,mBAAmB,UAAU,CAAC,GAA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AA,EACrC;AACD;","names":["isArray","isObject"]}
1
+ {"version":3,"sources":["../../../../../../nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.ts"],"sourcesContent":["import type { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';\nimport { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';\nimport isArray from 'lodash/isArray';\nimport isObject from 'lodash/isObject';\nimport type { SetField, SetNodeOptions } from 'n8n-nodes-base/dist/nodes/Set/v2/helpers/interfaces';\nimport * as manual from 'n8n-nodes-base/dist/nodes/Set/v2/manual.mode';\nimport { getCurrentWorkflowInputData } from 'n8n-nodes-base/dist/utils/workflowInputsResourceMapping/GenericFunctions';\nimport type {\n\tExecuteWorkflowData,\n\tExecutionError,\n\tFromAIArgument,\n\tIDataObject,\n\tIExecuteFunctions,\n\tIExecuteWorkflowInfo,\n\tINodeExecutionData,\n\tINodeParameterResourceLocator,\n\tISupplyDataFunctions,\n\tITaskMetadata,\n\tIWorkflowBase,\n\tIWorkflowDataProxyData,\n\tResourceMapperValue,\n} from 'n8n-workflow';\nimport {\n\tgenerateZodSchema,\n\tjsonParse,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\tparseErrorMetadata,\n\tsleepWithAbort,\n\ttraverseNodeParameters,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nfunction isNodeExecutionData(data: unknown): data is INodeExecutionData[] {\n\treturn isArray(data) && Boolean(data.length) && isObject(data[0]) && 'json' in data[0];\n}\n\n/**\n\tMain class for creating the Workflow tool\n\tProcesses the node parameters and creates AI Agent tool capable of executing n8n workflows\n*/\nexport class WorkflowToolService {\n\t// Determines if we should use input schema when creating the tool\n\tprivate useSchema: boolean;\n\n\t// Sub-workflow id, pulled from referenced sub-workflow\n\tprivate subWorkflowId: string | undefined;\n\n\t// Sub-workflow execution id, will be set after the sub-workflow is executed\n\tprivate subExecutionId: string | undefined;\n\n\tprivate returnAllItems: boolean = false;\n\n\tconstructor(\n\t\tprivate baseContext: ISupplyDataFunctions | IExecuteFunctions,\n\t\toptions?: { returnAllItems: boolean },\n\t) {\n\t\tconst subWorkflowInputs = this.baseContext.getNode().parameters\n\t\t\t.workflowInputs as ResourceMapperValue;\n\t\tthis.useSchema = (subWorkflowInputs?.schema ?? []).length > 0;\n\t\tthis.returnAllItems = options?.returnAllItems ?? false;\n\t}\n\n\t// Creates the tool based on the provided parameters\n\tasync createTool({\n\t\tctx,\n\t\tname,\n\t\tdescription,\n\t\titemIndex,\n\t\tmanualLogging = true,\n\t}: {\n\t\tctx: ISupplyDataFunctions | IExecuteFunctions;\n\t\tname: string;\n\t\tdescription: string;\n\t\titemIndex: number;\n\t\tmanualLogging?: boolean;\n\t}): Promise<DynamicTool | DynamicStructuredTool> {\n\t\t// Handler for the tool execution, will be called when the tool is executed\n\t\t// This function will execute the sub-workflow and return the response\n\t\t// We get the runIndex from the context to handle multiple executions\n\t\t// of the same tool when the tool is used in a loop or in a parallel execution.\n\t\tconst node = ctx.getNode();\n\n\t\tlet runIndex: number = 'getNextRunIndex' in ctx ? ctx.getNextRunIndex() : 0;\n\t\tconst toolHandler = async (\n\t\t\tquery: string | IDataObject,\n\t\t\trunManager?: CallbackManagerForToolRun,\n\t\t): Promise<IDataObject | IDataObject[] | string> => {\n\t\t\tlet maxTries = 1;\n\t\t\tif (node.retryOnFail === true) {\n\t\t\t\tmaxTries = Math.min(5, Math.max(2, node.maxTries ?? 3));\n\t\t\t}\n\n\t\t\tlet waitBetweenTries = 0;\n\t\t\tif (node.retryOnFail === true) {\n\t\t\t\twaitBetweenTries = Math.min(5000, Math.max(0, node.waitBetweenTries ?? 1000));\n\t\t\t}\n\n\t\t\tlet lastError: ExecutionError | undefined;\n\n\t\t\tfor (let tryIndex = 0; tryIndex < maxTries; tryIndex++) {\n\t\t\t\tconst localRunIndex = runIndex++;\n\n\t\t\t\tlet context = this.baseContext;\n\t\t\t\t// We need to clone the context here to handle runIndex correctly\n\t\t\t\t// Otherwise the runIndex will be shared between different executions\n\t\t\t\t// Causing incorrect data to be passed to the sub-workflow and via $fromAI\n\t\t\t\tif ('cloneWith' in this.baseContext) {\n\t\t\t\t\tcontext = this.baseContext.cloneWith({\n\t\t\t\t\t\trunIndex: localRunIndex,\n\t\t\t\t\t\tinputData: [[{ json: { query } }]],\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Get abort signal from context for cancellation support\n\t\t\t\tconst abortSignal = context.getExecutionCancelSignal?.();\n\n\t\t\t\t// Check if execution was cancelled before retry\n\t\t\t\tif (abortSignal?.aborted) {\n\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t}\n\n\t\t\t\tif (tryIndex !== 0) {\n\t\t\t\t\t// Reset error from previous attempt\n\t\t\t\t\tlastError = undefined;\n\t\t\t\t\tif (waitBetweenTries !== 0) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait sleepWithAbort(waitBetweenTries, abortSignal);\n\t\t\t\t\t\t} catch (abortError) {\n\t\t\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await this.runFunction(context, query, itemIndex, runManager);\n\n\t\t\t\t\tconst processedResponse = this.handleToolResponse(response);\n\n\t\t\t\t\tlet responseData: INodeExecutionData[];\n\t\t\t\t\tif (isNodeExecutionData(response)) {\n\t\t\t\t\t\tresponseData = response;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst reParsedData = jsonParse<IDataObject>(processedResponse, {\n\t\t\t\t\t\t\tfallbackValue: { response: processedResponse },\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tresponseData = [{ json: reParsedData }];\n\t\t\t\t\t}\n\n\t\t\t\t\t// Once the sub-workflow is executed, add the output data to the context\n\t\t\t\t\t// This will be used to link the sub-workflow execution in the parent workflow\n\t\t\t\t\tlet metadata: ITaskMetadata | undefined;\n\t\t\t\t\tif (this.subExecutionId && this.subWorkflowId) {\n\t\t\t\t\t\tmetadata = {\n\t\t\t\t\t\t\tsubExecution: {\n\t\t\t\t\t\t\t\texecutionId: this.subExecutionId,\n\t\t\t\t\t\t\t\tworkflowId: this.subWorkflowId,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tif (manualLogging) {\n\t\t\t\t\t\tvoid context.addOutputData(\n\t\t\t\t\t\t\tNodeConnectionTypes.AiTool,\n\t\t\t\t\t\t\tlocalRunIndex,\n\t\t\t\t\t\t\t[responseData],\n\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn processedResponse;\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Check if error is due to cancellation\n\t\t\t\t\tif (abortSignal?.aborted) {\n\t\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t\t}\n\n\t\t\t\t\tconst executionError = error as ExecutionError;\n\t\t\t\t\tlastError = executionError;\n\t\t\t\t\tconst errorResponse = `There was an error: \"${executionError.message}\"`;\n\n\t\t\t\t\tif (manualLogging) {\n\t\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\t\tvoid context.addOutputData(\n\t\t\t\t\t\t\tNodeConnectionTypes.AiTool,\n\t\t\t\t\t\t\tlocalRunIndex,\n\t\t\t\t\t\t\texecutionError,\n\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (tryIndex === maxTries - 1) {\n\t\t\t\t\t\treturn errorResponse;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn `There was an error: ${lastError?.message ?? 'Unknown error'}`;\n\t\t};\n\n\t\t// Create structured tool if input schema is provided\n\t\treturn this.useSchema\n\t\t\t? await this.createStructuredTool(name, description, toolHandler)\n\t\t\t: new DynamicTool({ name, description, func: toolHandler });\n\t}\n\n\tprivate handleToolResponse(response: unknown): string {\n\t\tif (typeof response === 'number') {\n\t\t\treturn response.toString();\n\t\t}\n\n\t\tif (isNodeExecutionData(response)) {\n\t\t\treturn JSON.stringify(\n\t\t\t\tresponse.map((item) => item.json),\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t);\n\t\t}\n\n\t\tif (isObject(response)) {\n\t\t\treturn JSON.stringify(response, null, 2);\n\t\t}\n\n\t\tif (typeof response !== 'string') {\n\t\t\tthrow new NodeOperationError(this.baseContext.getNode(), 'Wrong output type returned', {\n\t\t\t\tdescription: `The response property should be a string, but it is an ${typeof response}`,\n\t\t\t});\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Executes specified sub-workflow with provided inputs\n\t */\n\tprivate async executeSubWorkflow(\n\t\tcontext: ISupplyDataFunctions | IExecuteFunctions,\n\t\tworkflowInfo: IExecuteWorkflowInfo,\n\t\titems: INodeExecutionData[],\n\t\tworkflowProxy: IWorkflowDataProxyData,\n\t\trunManager?: CallbackManagerForToolRun,\n\t): Promise<{ response: string | IDataObject | INodeExecutionData[]; subExecutionId: string }> {\n\t\tlet receivedData: ExecuteWorkflowData;\n\t\ttry {\n\t\t\treceivedData = await context.executeWorkflow(workflowInfo, items, runManager?.getChild(), {\n\t\t\t\tparentExecution: {\n\t\t\t\t\texecutionId: workflowProxy.$execution.id,\n\t\t\t\t\tworkflowId: workflowProxy.$workflow.id,\n\t\t\t\t},\n\t\t\t});\n\t\t\t// Set sub-workflow execution id so it can be used in other places\n\t\t\tthis.subExecutionId = receivedData.executionId;\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), error as Error);\n\t\t}\n\n\t\tlet response: IDataObject | INodeExecutionData[] | undefined;\n\t\tif (this.returnAllItems) {\n\t\t\tresponse = receivedData?.data?.[0]?.length ? receivedData.data[0] : undefined;\n\t\t} else {\n\t\t\tresponse = receivedData?.data?.[0]?.[0]?.json;\n\t\t}\n\t\tif (response === undefined) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tcontext.getNode(),\n\t\t\t\t'There was an error: \"The workflow did not return a response\"',\n\t\t\t);\n\t\t}\n\n\t\treturn { response, subExecutionId: receivedData.executionId };\n\t}\n\n\t/**\n\t * Gets the sub-workflow info based on the source and executes it.\n\t * This function will be called as part of the tool execution (from the toolHandler)\n\t */\n\tprivate async runFunction(\n\t\tcontext: ISupplyDataFunctions | IExecuteFunctions,\n\t\tquery: string | IDataObject,\n\t\titemIndex: number,\n\t\trunManager?: CallbackManagerForToolRun,\n\t): Promise<string | IDataObject | INodeExecutionData[]> {\n\t\tconst source = context.getNodeParameter('source', itemIndex) as string;\n\t\tconst workflowProxy = context.getWorkflowDataProxy(0);\n\n\t\tconst { workflowInfo } = await this.getSubWorkflowInfo(\n\t\t\tcontext,\n\t\t\tsource,\n\t\t\titemIndex,\n\t\t\tworkflowProxy,\n\t\t);\n\t\tconst rawData = this.prepareRawData(context, query, itemIndex);\n\t\tconst items = await this.prepareWorkflowItems(context, query, itemIndex, rawData);\n\n\t\tthis.subWorkflowId = workflowInfo.id;\n\n\t\tconst { response } = await this.executeSubWorkflow(\n\t\t\tcontext,\n\t\t\tworkflowInfo,\n\t\t\titems,\n\t\t\tworkflowProxy,\n\t\t\trunManager,\n\t\t);\n\t\treturn response;\n\t}\n\n\t/**\n\t * Gets the sub-workflow info based on the source (database or parameter)\n\t */\n\tprivate async getSubWorkflowInfo(\n\t\tcontext: ISupplyDataFunctions | IExecuteFunctions,\n\t\tsource: string,\n\t\titemIndex: number,\n\t\tworkflowProxy: IWorkflowDataProxyData,\n\t): Promise<{\n\t\tworkflowInfo: IExecuteWorkflowInfo;\n\t\tsubWorkflowId: string;\n\t}> {\n\t\tconst workflowInfo: IExecuteWorkflowInfo = {};\n\t\tlet subWorkflowId: string;\n\n\t\tif (source === 'database') {\n\t\t\tconst { value } = context.getNodeParameter(\n\t\t\t\t'workflowId',\n\t\t\t\titemIndex,\n\t\t\t\t{},\n\t\t\t) as INodeParameterResourceLocator;\n\t\t\tworkflowInfo.id = value as string;\n\t\t\tsubWorkflowId = workflowInfo.id;\n\t\t} else if (source === 'parameter') {\n\t\t\tconst workflowJson = context.getNodeParameter('workflowJson', itemIndex) as string;\n\t\t\ttry {\n\t\t\t\tworkflowInfo.code = JSON.parse(workflowJson) as IWorkflowBase;\n\t\t\t\t// subworkflow is same as parent workflow\n\t\t\t\tsubWorkflowId = workflowProxy.$workflow.id;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\tcontext.getNode(),\n\t\t\t\t\t`The provided workflow is not valid JSON: \"${(error as Error).message}\"`,\n\t\t\t\t\t{ itemIndex },\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn { workflowInfo, subWorkflowId: subWorkflowId! };\n\t}\n\n\tprivate prepareRawData(\n\t\tcontext: ISupplyDataFunctions | IExecuteFunctions,\n\t\tquery: string | IDataObject,\n\t\titemIndex: number,\n\t): IDataObject {\n\t\tconst rawData: IDataObject = { query };\n\t\tconst workflowFieldsJson = context.getNodeParameter('fields.values', itemIndex, [], {\n\t\t\trawExpressions: true,\n\t\t}) as SetField[];\n\n\t\t// Copied from Set Node v2\n\t\tfor (const entry of workflowFieldsJson) {\n\t\t\tif (entry.type === 'objectValue' && (entry.objectValue as string).startsWith('=')) {\n\t\t\t\trawData[entry.name] = (entry.objectValue as string).replace(/^=+/, '');\n\t\t\t}\n\t\t}\n\n\t\treturn rawData;\n\t}\n\n\t/**\n\t * Prepares the sub-workflow items for execution\n\t */\n\tprivate async prepareWorkflowItems(\n\t\tcontext: ISupplyDataFunctions | IExecuteFunctions,\n\t\tquery: string | IDataObject,\n\t\titemIndex: number,\n\t\trawData: IDataObject,\n\t): Promise<INodeExecutionData[]> {\n\t\tconst options: SetNodeOptions = { include: 'all' };\n\t\tlet jsonData = typeof query === 'object' ? query : { query };\n\n\t\tif (this.useSchema) {\n\t\t\tconst currentWorkflowInputs = getCurrentWorkflowInputData.call(context);\n\t\t\tjsonData = currentWorkflowInputs[itemIndex].json;\n\t\t}\n\n\t\tconst newItem = await manual.execute.call(\n\t\t\tcontext,\n\t\t\t{ json: jsonData },\n\t\t\titemIndex,\n\t\t\toptions,\n\t\t\trawData,\n\t\t\tcontext.getNode(),\n\t\t);\n\n\t\treturn [newItem] as INodeExecutionData[];\n\t}\n\n\t/**\n\t * Create structured tool by parsing the sub-workflow input schema\n\t */\n\tprivate async createStructuredTool(\n\t\tname: string,\n\t\tdescription: string,\n\t\tfunc: (\n\t\t\tquery: string | IDataObject,\n\t\t\trunManager?: CallbackManagerForToolRun,\n\t\t) => Promise<string | IDataObject | IDataObject[]>,\n\t): Promise<DynamicStructuredTool | DynamicTool> {\n\t\tconst collectedArguments = await this.extractFromAIParameters();\n\n\t\t// If there are no `fromAI` arguments, fallback to creating a simple tool\n\t\tif (collectedArguments.length === 0) {\n\t\t\treturn new DynamicTool({ name, description, func });\n\t\t}\n\n\t\t// Otherwise, prepare Zod schema and create a structured tool\n\t\tconst schema = this.createZodSchema(collectedArguments);\n\t\treturn new DynamicStructuredTool({ schema, name, description, func });\n\t}\n\n\tprivate async extractFromAIParameters(): Promise<FromAIArgument[]> {\n\t\tconst collectedArguments: FromAIArgument[] = [];\n\t\ttraverseNodeParameters(this.baseContext.getNode().parameters, collectedArguments);\n\n\t\tconst uniqueArgsMap = new Map<string, FromAIArgument>();\n\t\tfor (const arg of collectedArguments) {\n\t\t\tuniqueArgsMap.set(arg.key, arg);\n\t\t}\n\n\t\treturn Array.from(uniqueArgsMap.values());\n\t}\n\n\tprivate createZodSchema(args: FromAIArgument[]): z.ZodObject<any> {\n\t\tconst schemaObj = args.reduce((acc: Record<string, z.ZodTypeAny>, placeholder) => {\n\t\t\tacc[placeholder.key] = generateZodSchema(placeholder);\n\t\t\treturn acc;\n\t\t}, {});\n\n\t\treturn z.object(schemaObj).required();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmD;A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BAAkB;AACtD,WAAO,IAAI,mCAAsB,EAAE,QAAQ,MAAM,aAAa,KAAK,CAAC;AAAA,EACrE;AAAA,EAEA,MAAc,0BAAqD;AAClE,UAAM,qBAAuC,CAAC;AAC9C,oDAAuB,KAAK,YAAY,QAAQ,EAAE,YAAY,kBAAkB;AAEhF,UAAM,gBAAgB,oBAAI,IAA4B;AACtD,eAAW,OAAO,oBAAoB;AACrC,oBAAc,IAAI,IAAI,KAAK,GAAG;AAAA,IAC/B;AAEA,WAAO,MAAM,KAAK,cAAc,OAAO,CAAC;AAAA,EACzC;AAAA,EAEQ,gBAAgB,MAA0C;AACjE,UAAM,YAAY,KAAK,OAAO,CAAC,KAAmC,gBAAgB;AACjF,UAAI,YAAY,GAAG,QAAI,uCAAkB,WAAW;AACpD,aAAO;AAAA,IACR,GAAG,CAAC,CAAC;AAEL,WAAO,aAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EACrC;AACD;","names":["isArray","isObject"]}
@@ -35,7 +35,7 @@ const cssVariables = `
35
35
  --chat--color-light-shade-100: #c2c5cc;
36
36
  --chat--color-medium: #d2d4d9;
37
37
  --chat--color-dark: #101330;
38
- --chat--color-disabled: #777980;
38
+ --chat--color-disabled: #d2d4d9;
39
39
  --chat--color-typing: #404040;
40
40
 
41
41
  /* Base Layout */
@@ -127,7 +127,7 @@ const cssVariables = `
127
127
 
128
128
  /* Send and File Buttons */
129
129
  --chat--input--send--button--background: var(--chat--color-white);
130
- --chat--input--send--button--color: var(--chat--color-light);
130
+ --chat--input--send--button--color: var(--chat--color-secondary);
131
131
  --chat--input--send--button--background-hover: var(--chat--color-primary-shade-50);
132
132
  --chat--input--send--button--color-hover: var(--chat--color-secondary-shade-50);
133
133
  --chat--input--file--button--background: var(--chat--color-white);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/trigger/ChatTrigger/constants.ts"],"sourcesContent":["// CSS Variables are defined in `@n8n/chat/src/css/_tokens.scss`\nexport const cssVariables = `\n:root {\n /* Colors */\n --chat--color-primary: #e74266;\n --chat--color-primary-shade-50: #db4061;\n --chat--color-primary-shade-100: #cf3c5c;\n --chat--color-secondary: #20b69e;\n --chat--color-secondary-shade-50: #1ca08a;\n --chat--color-white: #ffffff;\n --chat--color-light: #f2f4f8;\n --chat--color-light-shade-50: #e6e9f1;\n --chat--color-light-shade-100: #c2c5cc;\n --chat--color-medium: #d2d4d9;\n --chat--color-dark: #101330;\n --chat--color-disabled: #777980;\n --chat--color-typing: #404040;\n\n /* Base Layout */\n --chat--spacing: 1rem;\n --chat--border-radius: 0.25rem;\n --chat--transition-duration: 0.15s;\n --chat--font-family: (\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n Oxygen-Sans,\n Ubuntu,\n Cantarell,\n 'Helvetica Neue',\n sans-serif\n );\n\n /* Window Dimensions */\n --chat--window--width: 400px;\n --chat--window--height: 600px;\n --chat--window--bottom: var(--chat--spacing);\n --chat--window--right: var(--chat--spacing);\n --chat--window--z-index: 9999;\n --chat--window--border: 1px solid var(--chat--color-light-shade-50);\n --chat--window--border-radius: var(--chat--border-radius);\n --chat--window--margin-bottom: var(--chat--spacing);\n\n /* Header Styles */\n --chat--header-height: auto;\n --chat--header--padding: var(--chat--spacing);\n --chat--header--background: var(--chat--color-dark);\n --chat--header--color: var(--chat--color-light);\n --chat--header--border-top: none;\n --chat--header--border-bottom: none;\n --chat--header--border-left: none;\n --chat--header--border-right: none;\n --chat--heading--font-size: 2em;\n --chat--subtitle--font-size: inherit;\n --chat--subtitle--line-height: 1.8;\n\n /* Message Styles */\n --chat--message--font-size: 1rem;\n --chat--message--padding: var(--chat--spacing);\n --chat--message--border-radius: var(--chat--border-radius);\n --chat--message-line-height: 1.5;\n --chat--message--margin-bottom: calc(var(--chat--spacing) * 1);\n --chat--message--bot--background: var(--chat--color-white);\n --chat--message--bot--color: var(--chat--color-dark);\n --chat--message--bot--border: none;\n --chat--message--user--background: var(--chat--color-secondary);\n --chat--message--user--color: var(--chat--color-white);\n --chat--message--user--border: none;\n --chat--message--pre--background: rgba(0, 0, 0, 0.05);\n --chat--messages-list--padding: var(--chat--spacing);\n\n /* Toggle Button */\n --chat--toggle--size: 64px;\n --chat--toggle--width: var(--chat--toggle--size);\n --chat--toggle--height: var(--chat--toggle--size);\n --chat--toggle--border-radius: 50%;\n --chat--toggle--background: var(--chat--color-primary);\n --chat--toggle--hover--background: var(--chat--color-primary-shade-50);\n --chat--toggle--active--background: var(--chat--color-primary-shade-100);\n --chat--toggle--color: var(--chat--color-white);\n\n /* Input Area */\n --chat--textarea--height: 50px;\n --chat--textarea--max-height: 30rem;\n --chat--input--font-size: inherit;\n --chat--input--border: 0;\n --chat--input--border-radius: 0;\n --chat--input--padding: 0.8rem;\n --chat--input--background: var(--chat--color-white);\n --chat--input--text-color: initial;\n --chat--input--line-height: 1.5;\n --chat--input--placeholder--font-size: var(--chat--input--font-size);\n --chat--input--border-active: 0;\n --chat--input--left--panel--width: 2rem;\n\n /* Button Styles */\n --chat--button--color: var(--chat--color-light);\n --chat--button--background: var(--chat--color-primary);\n --chat--button--padding: calc(var(--chat--spacing) * 1 / 2) var(--chat--spacing);\n --chat--button--border-radius: var(--chat--border-radius);\n --chat--button--hover--color: var(--chat--color-light);\n --chat--button--hover--background: var(--chat--color-primary-shade-50);\n --chat--close--button--color-hover: var(--chat--color-primary);\n\n /* Send and File Buttons */\n --chat--input--send--button--background: var(--chat--color-white);\n --chat--input--send--button--color: var(--chat--color-light);\n --chat--input--send--button--background-hover: var(--chat--color-primary-shade-50);\n --chat--input--send--button--color-hover: var(--chat--color-secondary-shade-50);\n --chat--input--file--button--background: var(--chat--color-white);\n --chat--input--file--button--color: var(--chat--color-secondary);\n --chat--input--file--button--background-hover: var(--chat--input--file--button--background);\n --chat--input--file--button--color-hover: var(--chat--color-secondary-shade-50);\n --chat--files-spacing: 0.25rem;\n\n /* Body and Footer */\n --chat--body--background: var(--chat--color-light);\n --chat--footer--background: var(--chat--color-light);\n --chat--footer--color: var(--chat--color-dark);\n}\n`;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/trigger/ChatTrigger/constants.ts"],"sourcesContent":["// CSS Variables are defined in `@n8n/chat/src/css/_tokens.scss`\nexport const cssVariables = `\n:root {\n /* Colors */\n --chat--color-primary: #e74266;\n --chat--color-primary-shade-50: #db4061;\n --chat--color-primary-shade-100: #cf3c5c;\n --chat--color-secondary: #20b69e;\n --chat--color-secondary-shade-50: #1ca08a;\n --chat--color-white: #ffffff;\n --chat--color-light: #f2f4f8;\n --chat--color-light-shade-50: #e6e9f1;\n --chat--color-light-shade-100: #c2c5cc;\n --chat--color-medium: #d2d4d9;\n --chat--color-dark: #101330;\n --chat--color-disabled: #d2d4d9;\n --chat--color-typing: #404040;\n\n /* Base Layout */\n --chat--spacing: 1rem;\n --chat--border-radius: 0.25rem;\n --chat--transition-duration: 0.15s;\n --chat--font-family: (\n -apple-system,\n BlinkMacSystemFont,\n 'Segoe UI',\n Roboto,\n Oxygen-Sans,\n Ubuntu,\n Cantarell,\n 'Helvetica Neue',\n sans-serif\n );\n\n /* Window Dimensions */\n --chat--window--width: 400px;\n --chat--window--height: 600px;\n --chat--window--bottom: var(--chat--spacing);\n --chat--window--right: var(--chat--spacing);\n --chat--window--z-index: 9999;\n --chat--window--border: 1px solid var(--chat--color-light-shade-50);\n --chat--window--border-radius: var(--chat--border-radius);\n --chat--window--margin-bottom: var(--chat--spacing);\n\n /* Header Styles */\n --chat--header-height: auto;\n --chat--header--padding: var(--chat--spacing);\n --chat--header--background: var(--chat--color-dark);\n --chat--header--color: var(--chat--color-light);\n --chat--header--border-top: none;\n --chat--header--border-bottom: none;\n --chat--header--border-left: none;\n --chat--header--border-right: none;\n --chat--heading--font-size: 2em;\n --chat--subtitle--font-size: inherit;\n --chat--subtitle--line-height: 1.8;\n\n /* Message Styles */\n --chat--message--font-size: 1rem;\n --chat--message--padding: var(--chat--spacing);\n --chat--message--border-radius: var(--chat--border-radius);\n --chat--message-line-height: 1.5;\n --chat--message--margin-bottom: calc(var(--chat--spacing) * 1);\n --chat--message--bot--background: var(--chat--color-white);\n --chat--message--bot--color: var(--chat--color-dark);\n --chat--message--bot--border: none;\n --chat--message--user--background: var(--chat--color-secondary);\n --chat--message--user--color: var(--chat--color-white);\n --chat--message--user--border: none;\n --chat--message--pre--background: rgba(0, 0, 0, 0.05);\n --chat--messages-list--padding: var(--chat--spacing);\n\n /* Toggle Button */\n --chat--toggle--size: 64px;\n --chat--toggle--width: var(--chat--toggle--size);\n --chat--toggle--height: var(--chat--toggle--size);\n --chat--toggle--border-radius: 50%;\n --chat--toggle--background: var(--chat--color-primary);\n --chat--toggle--hover--background: var(--chat--color-primary-shade-50);\n --chat--toggle--active--background: var(--chat--color-primary-shade-100);\n --chat--toggle--color: var(--chat--color-white);\n\n /* Input Area */\n --chat--textarea--height: 50px;\n --chat--textarea--max-height: 30rem;\n --chat--input--font-size: inherit;\n --chat--input--border: 0;\n --chat--input--border-radius: 0;\n --chat--input--padding: 0.8rem;\n --chat--input--background: var(--chat--color-white);\n --chat--input--text-color: initial;\n --chat--input--line-height: 1.5;\n --chat--input--placeholder--font-size: var(--chat--input--font-size);\n --chat--input--border-active: 0;\n --chat--input--left--panel--width: 2rem;\n\n /* Button Styles */\n --chat--button--color: var(--chat--color-light);\n --chat--button--background: var(--chat--color-primary);\n --chat--button--padding: calc(var(--chat--spacing) * 1 / 2) var(--chat--spacing);\n --chat--button--border-radius: var(--chat--border-radius);\n --chat--button--hover--color: var(--chat--color-light);\n --chat--button--hover--background: var(--chat--color-primary-shade-50);\n --chat--close--button--color-hover: var(--chat--color-primary);\n\n /* Send and File Buttons */\n --chat--input--send--button--background: var(--chat--color-white);\n --chat--input--send--button--color: var(--chat--color-secondary);\n --chat--input--send--button--background-hover: var(--chat--color-primary-shade-50);\n --chat--input--send--button--color-hover: var(--chat--color-secondary-shade-50);\n --chat--input--file--button--background: var(--chat--color-white);\n --chat--input--file--button--color: var(--chat--color-secondary);\n --chat--input--file--button--background-hover: var(--chat--input--file--button--background);\n --chat--input--file--button--color-hover: var(--chat--color-secondary-shade-50);\n --chat--files-spacing: 0.25rem;\n\n /* Body and Footer */\n --chat--body--background: var(--chat--color-light);\n --chat--footer--background: var(--chat--color-light);\n --chat--footer--color: var(--chat--color-dark);\n}\n`;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}