@n8n/n8n-nodes-langchain 2.0.0 → 2.1.0
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/credentials/McpOAuth2Api.credentials.js +1 -2
- package/dist/credentials/McpOAuth2Api.credentials.js.map +1 -1
- package/dist/nodes/agents/Agent/Agent.node.js +4 -2
- package/dist/nodes/agents/Agent/Agent.node.js.map +1 -1
- package/dist/nodes/agents/Agent/AgentTool.node.js +4 -2
- package/dist/nodes/agents/Agent/AgentTool.node.js.map +1 -1
- package/dist/nodes/agents/Agent/V1/AgentV1.node.js +1 -1
- package/dist/nodes/agents/Agent/V1/AgentV1.node.js.map +1 -1
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js +1 -1
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js.map +1 -1
- package/dist/nodes/agents/Agent/V3/AgentToolV3.node.js +99 -0
- package/dist/nodes/agents/Agent/V3/AgentToolV3.node.js.map +1 -0
- package/dist/nodes/agents/Agent/V3/AgentV3.node.js +9 -2
- package/dist/nodes/agents/Agent/V3/AgentV3.node.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/SqlAgent/description.js +1 -1
- package/dist/nodes/agents/Agent/agents/SqlAgent/description.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/execute.js +1 -3
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.js +4 -0
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js +1 -1
- package/dist/nodes/chains/ChainLLM/ChainLlm.node.js.map +1 -1
- package/dist/nodes/chains/ChainLLM/methods/config.js +10 -2
- package/dist/nodes/chains/ChainLLM/methods/config.js.map +1 -1
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js +11 -3
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js.map +1 -1
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js +9 -3
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +3 -0
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +66 -15
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/templates.js +1 -2
- package/dist/nodes/trigger/ChatTrigger/templates.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/file/index.js +2 -2
- package/dist/nodes/vendors/GoogleGemini/actions/file/index.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/createStore.operation.js +64 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/createStore.operation.js.map +1 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/deleteStore.operation.js +72 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/deleteStore.operation.js.map +1 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/index.js +94 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/index.js.map +1 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/listStores.operation.js +75 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/listStores.operation.js.map +1 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/uploadToStore.operation.js +129 -0
- package/dist/nodes/vendors/GoogleGemini/actions/fileSearch/uploadToStore.operation.js.map +1 -0
- package/dist/nodes/vendors/GoogleGemini/actions/node.type.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/router.js +4 -0
- package/dist/nodes/vendors/GoogleGemini/actions/router.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/text/message.operation.js +184 -11
- package/dist/nodes/vendors/GoogleGemini/actions/text/message.operation.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/versionDescription.js +10 -3
- package/dist/nodes/vendors/GoogleGemini/actions/versionDescription.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/helpers/interfaces.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/helpers/utils.js +131 -26
- package/dist/nodes/vendors/GoogleGemini/helpers/utils.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js +1 -1
- package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js.map +1 -1
- package/dist/types/credentials.json +1 -1
- package/dist/types/nodes.json +9 -8
- package/dist/utils/agent-execution/buildSteps.js +67 -8
- package/dist/utils/agent-execution/buildSteps.js.map +1 -1
- package/dist/utils/agent-execution/createEngineRequests.js +27 -5
- package/dist/utils/agent-execution/createEngineRequests.js.map +1 -1
- package/dist/utils/agent-execution/types.js +24 -0
- package/dist/utils/agent-execution/types.js.map +1 -1
- package/dist/utils/descriptions.js +21 -1
- package/dist/utils/descriptions.js.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/chains/ChainLLM/ChainLlm.node.ts"],"sourcesContent":["import type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { NodeApiError, NodeConnectionTypes, NodeOperationError, sleep } from 'n8n-workflow';\n\nimport { getOptionalOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\n// Import from centralized module\nimport { formatResponse, getInputs, nodeProperties } from './methods';\nimport { processItem } from './methods/processItem';\nimport {\n\tgetCustomErrorMessage as getCustomOpenAiErrorMessage,\n\tisOpenAiError,\n} from '../../vendors/OpenAi/helpers/error-handling';\n\n/**\n * Basic LLM Chain Node Implementation\n * Allows connecting to language models with optional structured output parsing\n */\nexport class ChainLlm implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Basic LLM Chain',\n\t\tname: 'chainLlm',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7],\n\t\tdescription: 'A simple chain to prompt a large language model',\n\t\tdefaults: {\n\t\t\tname: 'Basic LLM Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainllm/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ ((parameter) => { ${getInputs.toString()}; return getInputs(parameter) })($parameter) }}`,\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: nodeProperties,\n\t};\n\n\t/**\n\t * Main execution method for the node\n\t */\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Basic LLM Chain');\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\t\tconst outputParser = await getOptionalOutputParser(this);\n\t\t// If the node version is 1.6(and LLM is using `response_format: json_object`) or higher or an output parser is configured,\n\t\t// we unwrap the response and return the object directly as JSON\n\t\tconst shouldUnwrapObjects = this.getNode().typeVersion >= 1.6 || !!outputParser;\n\n\t\tconst batchSize = this.getNodeParameter('batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tif (this.getNode().typeVersion >= 1.7 && batchSize > 1) {\n\t\t\t// Process items in batches\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\t\t\treturn await processItem(this, i + batchItemIndex);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\n\t\t\t\tbatchResults.forEach((promiseResult, batchItemIndex) => {\n\t\t\t\t\tconst itemIndex = i + batchItemIndex;\n\t\t\t\t\tif (promiseResult.status === 'rejected') {\n\t\t\t\t\t\tconst error = promiseResult.reason as Error;\n\t\t\t\t\t\t// Handle OpenAI specific rate limit errors\n\t\t\t\t\t\tif (error instanceof NodeApiError && isOpenAiError(error.cause)) {\n\t\t\t\t\t\t\tconst openAiErrorCode: string | undefined = (error.cause as any).error?.code;\n\t\t\t\t\t\t\tif (openAiErrorCode) {\n\t\t\t\t\t\t\t\tconst customMessage = getCustomOpenAiErrorMessage(openAiErrorCode);\n\t\t\t\t\t\t\t\tif (customMessage) {\n\t\t\t\t\t\t\t\t\terror.message = customMessage;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst responses = promiseResult.value;\n\t\t\t\t\tresponses.forEach((response: unknown) => {\n\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\tjson: formatResponse(response, shouldUnwrapObjects),\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Process each input item\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst responses = await processItem(this, itemIndex);\n\n\t\t\t\t\t// Process each response and add to return data\n\t\t\t\t\tresponses.forEach((response) => {\n\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\tjson: formatResponse(response, shouldUnwrapObjects),\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Handle OpenAI specific rate limit errors\n\t\t\t\t\tif (error instanceof NodeApiError && isOpenAiError(error.cause)) {\n\t\t\t\t\t\tconst openAiErrorCode: string | undefined = (error.cause as any).error?.code;\n\t\t\t\t\t\tif (openAiErrorCode) {\n\t\t\t\t\t\t\tconst customMessage = getCustomOpenAiErrorMessage(openAiErrorCode);\n\t\t\t\t\t\t\tif (customMessage) {\n\t\t\t\t\t\t\t\terror.message = customMessage;\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\t// Continue on failure if configured\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\treturnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,0BAA6E;AAE7E,6BAAwC;AAGxC,qBAA0D;AAC1D,yBAA4B;AAC5B,4BAGO;AAMA,MAAM,SAA8B;AAAA,EAApC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainLLM/ChainLlm.node.ts"],"sourcesContent":["import type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { NodeApiError, NodeConnectionTypes, NodeOperationError, sleep } from 'n8n-workflow';\n\nimport { getOptionalOutputParser } from '@utils/output_parsers/N8nOutputParser';\n\n// Import from centralized module\nimport { formatResponse, getInputs, nodeProperties } from './methods';\nimport { processItem } from './methods/processItem';\nimport {\n\tgetCustomErrorMessage as getCustomOpenAiErrorMessage,\n\tisOpenAiError,\n} from '../../vendors/OpenAi/helpers/error-handling';\n\n/**\n * Basic LLM Chain Node Implementation\n * Allows connecting to language models with optional structured output parsing\n */\nexport class ChainLlm implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Basic LLM Chain',\n\t\tname: 'chainLlm',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8],\n\t\tdescription: 'A simple chain to prompt a large language model',\n\t\tdefaults: {\n\t\t\tname: 'Basic LLM Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainllm/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ ((parameter) => { ${getInputs.toString()}; return getInputs(parameter) })($parameter) }}`,\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: nodeProperties,\n\t};\n\n\t/**\n\t * Main execution method for the node\n\t */\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Basic LLM Chain');\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\t\tconst outputParser = await getOptionalOutputParser(this);\n\t\t// If the node version is 1.6(and LLM is using `response_format: json_object`) or higher or an output parser is configured,\n\t\t// we unwrap the response and return the object directly as JSON\n\t\tconst shouldUnwrapObjects = this.getNode().typeVersion >= 1.6 || !!outputParser;\n\n\t\tconst batchSize = this.getNodeParameter('batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tif (this.getNode().typeVersion >= 1.7 && batchSize > 1) {\n\t\t\t// Process items in batches\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\t\t\treturn await processItem(this, i + batchItemIndex);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\n\t\t\t\tbatchResults.forEach((promiseResult, batchItemIndex) => {\n\t\t\t\t\tconst itemIndex = i + batchItemIndex;\n\t\t\t\t\tif (promiseResult.status === 'rejected') {\n\t\t\t\t\t\tconst error = promiseResult.reason as Error;\n\t\t\t\t\t\t// Handle OpenAI specific rate limit errors\n\t\t\t\t\t\tif (error instanceof NodeApiError && isOpenAiError(error.cause)) {\n\t\t\t\t\t\t\tconst openAiErrorCode: string | undefined = (error.cause as any).error?.code;\n\t\t\t\t\t\t\tif (openAiErrorCode) {\n\t\t\t\t\t\t\t\tconst customMessage = getCustomOpenAiErrorMessage(openAiErrorCode);\n\t\t\t\t\t\t\t\tif (customMessage) {\n\t\t\t\t\t\t\t\t\terror.message = customMessage;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst responses = promiseResult.value;\n\t\t\t\t\tresponses.forEach((response: unknown) => {\n\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\tjson: formatResponse(response, shouldUnwrapObjects),\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Process each input item\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst responses = await processItem(this, itemIndex);\n\n\t\t\t\t\t// Process each response and add to return data\n\t\t\t\t\tresponses.forEach((response) => {\n\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\tjson: formatResponse(response, shouldUnwrapObjects),\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Handle OpenAI specific rate limit errors\n\t\t\t\t\tif (error instanceof NodeApiError && isOpenAiError(error.cause)) {\n\t\t\t\t\t\tconst openAiErrorCode: string | undefined = (error.cause as any).error?.code;\n\t\t\t\t\t\tif (openAiErrorCode) {\n\t\t\t\t\t\t\tconst customMessage = getCustomOpenAiErrorMessage(openAiErrorCode);\n\t\t\t\t\t\t\tif (customMessage) {\n\t\t\t\t\t\t\t\terror.message = customMessage;\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\t// Continue on failure if configured\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\treturnData.push({ json: { error: error.message }, pairedItem: { item: itemIndex } });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,0BAA6E;AAE7E,6BAAwC;AAGxC,qBAA0D;AAC1D,yBAA4B;AAC5B,4BAGO;AAMA,MAAM,SAA8B;AAAA,EAApC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,MACnD,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,MACR;AAAA,MACA,OAAO;AAAA,QACN,OAAO,CAAC,WAAW;AAAA,QACnB,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,UAAU,YAAY;AAAA,QAC5B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,QAAQ,yBAAyB,yBAAU,SAAS,CAAC;AAAA,MACrD,SAAS,CAAC,wCAAoB,IAAI;AAAA,MAClC,aAAa,CAAC;AAAA,MACd,YAAY;AAAA,IACb;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAkE;AACvE,SAAK,OAAO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Y,cAAc;AAChC,oBAAU,QAAQ,CAAC,aAAsB;AACxC,uBAAW,KAAK;AAAA,cACf,UAAM,+BAAe,UAAU,mBAAmB;AAAA,YACnD,CAAC;AAAA,UACF,CAAC;AAAA,QACF,CAAC;AAED,YAAI,IAAI,YAAY,MAAM,UAAU,sBAAsB,GAAG;AAC5D,oBAAM,2BAAM,mBAAmB;AAAA,QAChC;AAAA,MACD;AAAA,IACD,OAAO;AAEN,eAAS,YAAY,GAAG,YAAY,MAAM,QAAQ,aAAa;AAC9D,YAAI;AACH,gBAAM,YAAY,UAAM,gCAAY,MAAM,SAAS;AAGnD,oBAAU,QAAQ,CAAC,aAAa;AAC/B,uBAAW,KAAK;AAAA,cACf,UAAM,+BAAe,UAAU,mBAAmB;AAAA,YACnD,CAAC;AAAA,UACF,CAAC;AAAA,QACF,SAAS,OAAO;AAEf,cAAI,iBAAiB,wCAAgB,qCAAc,MAAM,KAAK,GAAG;AAChE,kBAAM,kBAAuC,MAAM,MAAc,OAAO;AACxE,gBAAI,iBAAiB;AACpB,oBAAM,oBAAgB,sBAAAA,uBAA4B,eAAe;AACjE,kBAAI,eAAe;AAClB,sBAAM,UAAU;AAAA,cACjB;AAAA,YACD;AAAA,UACD;AAGA,cAAI,KAAK,eAAe,GAAG;AAC1B,uBAAW,KAAK,EAAE,MAAM,EAAE,OAAO,MAAM,QAAQ,GAAG,YAAY,EAAE,MAAM,UAAU,EAAE,CAAC;AACnF;AAAA,UACD;AAEA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":["getCustomOpenAiErrorMessage"]}
|
|
@@ -95,10 +95,18 @@ const nodeProperties = [
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
|
-
...import_descriptions.
|
|
98
|
+
...import_descriptions.promptTypeOptionsDeprecated,
|
|
99
99
|
displayOptions: {
|
|
100
100
|
hide: {
|
|
101
|
-
"@version": [
|
|
101
|
+
"@version": [{ _cnd: { lte: 1.3 } }, { _cnd: { gte: 1.8 } }]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
...import_descriptions.promptTypeOptions,
|
|
107
|
+
displayOptions: {
|
|
108
|
+
show: {
|
|
109
|
+
"@version": [{ _cnd: { gte: 1.8 } }]
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/config.ts"],"sourcesContent":["import {\n\tAIMessagePromptTemplate,\n\tHumanMessagePromptTemplate,\n\tSystemMessagePromptTemplate,\n} from '@langchain/core/prompts';\nimport type { IDataObject, INodeInputConfiguration, INodeProperties } from 'n8n-workflow';\nimport { NodeConnectionTypes } from 'n8n-workflow';\n\nimport {\n\tpromptTypeOptions,\n\ttextFromGuardrailsNode,\n\ttextFromPreviousNode,\n} from '@utils/descriptions';\nimport { getBatchingOptionFields, getTemplateNoticeField } from '@utils/sharedFields';\n\n/**\n * Dynamic input configuration generation based on node parameters\n */\nexport function getInputs(parameters: IDataObject) {\n\tconst inputs: INodeInputConfiguration[] = [\n\t\t{ displayName: '', type: 'main' },\n\t\t{\n\t\t\tdisplayName: 'Model',\n\t\t\tmaxConnections: 1,\n\t\t\ttype: 'ai_languageModel',\n\t\t\trequired: true,\n\t\t},\n\t];\n\n\tconst needsFallback = parameters?.needsFallback;\n\n\tif (needsFallback === true) {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Fallback Model',\n\t\t\tmaxConnections: 1,\n\t\t\ttype: 'ai_languageModel',\n\t\t\trequired: true,\n\t\t});\n\t}\n\n\t// If `hasOutputParser` is undefined it must be version 1.3 or earlier so we\n\t// always add the output parser input\n\tconst hasOutputParser = parameters?.hasOutputParser;\n\tif (hasOutputParser === undefined || hasOutputParser === true) {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Output Parser',\n\t\t\ttype: 'ai_outputParser',\n\t\t\tmaxConnections: 1,\n\t\t\trequired: false,\n\t\t});\n\t}\n\n\treturn inputs;\n}\n\n/**\n * Node properties configuration\n */\nexport const nodeProperties: INodeProperties[] = [\n\tgetTemplateNoticeField(1978),\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.input }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.chat_input }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1.1, 1.2],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.chatInput }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\t...promptTypeOptions,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [1, 1.1, 1.2, 1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\t...textFromGuardrailsNode,\n\t\tdisplayOptions: { show: { promptType: ['guardrails'], '@version': [{ _cnd: { gte: 1.5 } }] } },\n\t},\n\t{\n\t\t...textFromPreviousNode,\n\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.5 } }] } },\n\t},\n\t{\n\t\tdisplayName: 'Prompt (User Message)',\n\t\tname: 'text',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '',\n\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\ttypeOptions: {\n\t\t\trows: 2,\n\t\t},\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tpromptType: ['define'],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Require Specific Output Format',\n\t\tname: 'hasOutputParser',\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t\tnoDataExpression: true,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [1, 1.1, 1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Enable Fallback Model',\n\t\tname: 'needsFallback',\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t\tnoDataExpression: true,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [1, 1.1, 1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Chat Messages (if Using a Chat Model)',\n\t\tname: 'messages',\n\t\ttype: 'fixedCollection',\n\t\ttypeOptions: {\n\t\t\tmultipleValues: true,\n\t\t},\n\t\tdefault: {},\n\t\tplaceholder: 'Add prompt',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'messageValues',\n\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\tvalues: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Type Name or ID',\n\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'AI',\n\t\t\t\t\t\t\t\tvalue: AIMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'System',\n\t\t\t\t\t\t\t\tvalue: SystemMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'User',\n\t\t\t\t\t\t\t\tvalue: HumanMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: SystemMessagePromptTemplate.lc_name(),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Message Type',\n\t\t\t\t\t\tname: 'messageType',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\ttype: [HumanMessagePromptTemplate.lc_name()],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Text',\n\t\t\t\t\t\t\t\tvalue: 'text',\n\t\t\t\t\t\t\t\tdescription: 'Simple text message',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Image (Binary)',\n\t\t\t\t\t\t\t\tvalue: 'imageBinary',\n\t\t\t\t\t\t\t\tdescription: 'Process the binary input from the previous node',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Image (URL)',\n\t\t\t\t\t\t\t\tvalue: 'imageUrl',\n\t\t\t\t\t\t\t\tdescription: 'Process the image from the specified URL',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'text',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image Data Field Name',\n\t\t\t\t\t\tname: 'binaryImageDataKey',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'data',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"The name of the field in the chain's input that contains the binary image file to be processed\",\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image URL',\n\t\t\t\t\t\tname: 'imageUrl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdescription: 'URL to the image to be processed',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tmessageType: ['imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image Details',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Control how the model processes the image and generates its textual understanding',\n\t\t\t\t\t\tname: 'imageDetail',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\ttype: [HumanMessagePromptTemplate.lc_name()],\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary', 'imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Auto',\n\t\t\t\t\t\t\t\tvalue: 'auto',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'Model will use the auto setting which will look at the image input size and decide if it should use the low or high setting',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Low',\n\t\t\t\t\t\t\t\tvalue: 'low',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'The model will receive a low-res 512px x 512px version of the image, and represent the image with a budget of 65 tokens. This allows the API to return faster responses and consume fewer input tokens for use cases that do not require high detail.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'High',\n\t\t\t\t\t\t\t\tvalue: 'high',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'Allows the model to see the low res image and then creates detailed crops of input images as 512px squares based on the input image size. Each of the detailed crops uses twice the token budget (65 tokens) for a total of 129 tokens.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'auto',\n\t\t\t\t\t},\n\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\tname: 'message',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary', 'imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t},\n\tgetBatchingOptionFields({\n\t\tshow: {\n\t\t\t'@version': [{ _cnd: { gte: 1.7 } }],\n\t\t},\n\t}),\n\t{\n\t\tdisplayName: `Connect an <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${NodeConnectionTypes.AiOutputParser}'>output parser</a> on the canvas to specify the output format you require`,\n\t\tname: 'notice',\n\t\ttype: 'notice',\n\t\tdefault: '',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\thasOutputParser: [true],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName:\n\t\t\t'Connect an additional language model on the canvas to use it as a fallback if the main model fails',\n\t\tname: 'fallbackNotice',\n\t\ttype: 'notice',\n\t\tdefault: '',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tneedsFallback: [true],\n\t\t\t},\n\t\t},\n\t},\n];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAIO;AAEP,0BAAoC;AAEpC,0BAIO;AACP,0BAAgE;AAKzD,SAAS,UAAU,YAAyB;AAClD,QAAM,SAAoC;AAAA,IACzC,EAAE,aAAa,IAAI,MAAM,OAA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M;AAAA,QACL,eAAe,CAAC,IAAI;AAAA,MACrB;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../nodes/chains/ChainLLM/methods/config.ts"],"sourcesContent":["import {\n\tAIMessagePromptTemplate,\n\tHumanMessagePromptTemplate,\n\tSystemMessagePromptTemplate,\n} from '@langchain/core/prompts';\nimport type { IDataObject, INodeInputConfiguration, INodeProperties } from 'n8n-workflow';\nimport { NodeConnectionTypes } from 'n8n-workflow';\n\nimport {\n\tpromptTypeOptions,\n\tpromptTypeOptionsDeprecated,\n\ttextFromGuardrailsNode,\n\ttextFromPreviousNode,\n} from '@utils/descriptions';\nimport { getBatchingOptionFields, getTemplateNoticeField } from '@utils/sharedFields';\n\n/**\n * Dynamic input configuration generation based on node parameters\n */\nexport function getInputs(parameters: IDataObject) {\n\tconst inputs: INodeInputConfiguration[] = [\n\t\t{ displayName: '', type: 'main' },\n\t\t{\n\t\t\tdisplayName: 'Model',\n\t\t\tmaxConnections: 1,\n\t\t\ttype: 'ai_languageModel',\n\t\t\trequired: true,\n\t\t},\n\t];\n\n\tconst needsFallback = parameters?.needsFallback;\n\n\tif (needsFallback === true) {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Fallback Model',\n\t\t\tmaxConnections: 1,\n\t\t\ttype: 'ai_languageModel',\n\t\t\trequired: true,\n\t\t});\n\t}\n\n\t// If `hasOutputParser` is undefined it must be version 1.3 or earlier so we\n\t// always add the output parser input\n\tconst hasOutputParser = parameters?.hasOutputParser;\n\tif (hasOutputParser === undefined || hasOutputParser === true) {\n\t\tinputs.push({\n\t\t\tdisplayName: 'Output Parser',\n\t\t\ttype: 'ai_outputParser',\n\t\t\tmaxConnections: 1,\n\t\t\trequired: false,\n\t\t});\n\t}\n\n\treturn inputs;\n}\n\n/**\n * Node properties configuration\n */\nexport const nodeProperties: INodeProperties[] = [\n\tgetTemplateNoticeField(1978),\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.input }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.chat_input }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1.1, 1.2],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Prompt',\n\t\tname: 'prompt',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '={{ $json.chatInput }}',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\t...promptTypeOptionsDeprecated,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [{ _cnd: { lte: 1.3 } }, { _cnd: { gte: 1.8 } }],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\t...promptTypeOptions,\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\t'@version': [{ _cnd: { gte: 1.8 } }],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\t...textFromGuardrailsNode,\n\t\tdisplayOptions: { show: { promptType: ['guardrails'], '@version': [{ _cnd: { gte: 1.5 } }] } },\n\t},\n\t{\n\t\t...textFromPreviousNode,\n\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.5 } }] } },\n\t},\n\t{\n\t\tdisplayName: 'Prompt (User Message)',\n\t\tname: 'text',\n\t\ttype: 'string',\n\t\trequired: true,\n\t\tdefault: '',\n\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\ttypeOptions: {\n\t\t\trows: 2,\n\t\t},\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tpromptType: ['define'],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Require Specific Output Format',\n\t\tname: 'hasOutputParser',\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t\tnoDataExpression: true,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [1, 1.1, 1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Enable Fallback Model',\n\t\tname: 'needsFallback',\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t\tnoDataExpression: true,\n\t\tdisplayOptions: {\n\t\t\thide: {\n\t\t\t\t'@version': [1, 1.1, 1.3],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName: 'Chat Messages (if Using a Chat Model)',\n\t\tname: 'messages',\n\t\ttype: 'fixedCollection',\n\t\ttypeOptions: {\n\t\t\tmultipleValues: true,\n\t\t},\n\t\tdefault: {},\n\t\tplaceholder: 'Add prompt',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'messageValues',\n\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\tvalues: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Type Name or ID',\n\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'AI',\n\t\t\t\t\t\t\t\tvalue: AIMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'System',\n\t\t\t\t\t\t\t\tvalue: SystemMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'User',\n\t\t\t\t\t\t\t\tvalue: HumanMessagePromptTemplate.lc_name(),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: SystemMessagePromptTemplate.lc_name(),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Message Type',\n\t\t\t\t\t\tname: 'messageType',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\ttype: [HumanMessagePromptTemplate.lc_name()],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Text',\n\t\t\t\t\t\t\t\tvalue: 'text',\n\t\t\t\t\t\t\t\tdescription: 'Simple text message',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Image (Binary)',\n\t\t\t\t\t\t\t\tvalue: 'imageBinary',\n\t\t\t\t\t\t\t\tdescription: 'Process the binary input from the previous node',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Image (URL)',\n\t\t\t\t\t\t\t\tvalue: 'imageUrl',\n\t\t\t\t\t\t\t\tdescription: 'Process the image from the specified URL',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'text',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image Data Field Name',\n\t\t\t\t\t\tname: 'binaryImageDataKey',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'data',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\"The name of the field in the chain's input that contains the binary image file to be processed\",\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image URL',\n\t\t\t\t\t\tname: 'imageUrl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdescription: 'URL to the image to be processed',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tmessageType: ['imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Image Details',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Control how the model processes the image and generates its textual understanding',\n\t\t\t\t\t\tname: 'imageDetail',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\ttype: [HumanMessagePromptTemplate.lc_name()],\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary', 'imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Auto',\n\t\t\t\t\t\t\t\tvalue: 'auto',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'Model will use the auto setting which will look at the image input size and decide if it should use the low or high setting',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Low',\n\t\t\t\t\t\t\t\tvalue: 'low',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'The model will receive a low-res 512px x 512px version of the image, and represent the image with a budget of 65 tokens. This allows the API to return faster responses and consume fewer input tokens for use cases that do not require high detail.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'High',\n\t\t\t\t\t\t\t\tvalue: 'high',\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'Allows the model to see the low res image and then creates detailed crops of input images as 512px squares based on the input image size. Each of the detailed crops uses twice the token budget (65 tokens) for a total of 129 tokens.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'auto',\n\t\t\t\t\t},\n\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\tname: 'message',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tmessageType: ['imageBinary', 'imageUrl'],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t},\n\tgetBatchingOptionFields({\n\t\tshow: {\n\t\t\t'@version': [{ _cnd: { gte: 1.7 } }],\n\t\t},\n\t}),\n\t{\n\t\tdisplayName: `Connect an <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='${NodeConnectionTypes.AiOutputParser}'>output parser</a> on the canvas to specify the output format you require`,\n\t\tname: 'notice',\n\t\ttype: 'notice',\n\t\tdefault: '',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\thasOutputParser: [true],\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tdisplayName:\n\t\t\t'Connect an additional language model on the canvas to use it as a fallback if the main model fails',\n\t\tname: 'fallbackNotice',\n\t\ttype: 'notice',\n\t\tdefault: '',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tneedsFallback: [true],\n\t\t\t},\n\t\t},\n\t},\n];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAIO;AAEP,0BAAoC;AAEpC,0BAKO;AACP,0BAAgE;AAKzD,SAAS,UAAU,YAAyB;AAClD,QAAM,SAAoC;AAAA,IACzC,EAAE,aAAa,IAAI,MAAM,OAAO;AAAA,IAChC;AAAA,MACC,aAAa;AAAA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MACf,MAAM;AAAA,QACL,iBAAiB,CAAC,IAAI;AAAA,MACvB;AAAA,IACD;AAAA,EACD;AAAA,EACA;AAAA,IACC,aACC;AAAA,IACD,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,gBAAgB;AAAA,MACf,MAAM;AAAA,QACL,eAAe,CAAC,IAAI;AAAA,MACrB;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -34,7 +34,7 @@ class ChainRetrievalQa {
|
|
|
34
34
|
icon: "fa:link",
|
|
35
35
|
iconColor: "black",
|
|
36
36
|
group: ["transform"],
|
|
37
|
-
version: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6],
|
|
37
|
+
version: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7],
|
|
38
38
|
description: "Answer questions about retrieved documents",
|
|
39
39
|
defaults: {
|
|
40
40
|
name: "Question and Answer Chain",
|
|
@@ -110,10 +110,18 @@ class ChainRetrievalQa {
|
|
|
110
110
|
}
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
|
-
...import_descriptions.
|
|
113
|
+
...import_descriptions.promptTypeOptionsDeprecated,
|
|
114
114
|
displayOptions: {
|
|
115
115
|
hide: {
|
|
116
|
-
"@version": [{ _cnd: { lte: 1.2 } }]
|
|
116
|
+
"@version": [{ _cnd: { lte: 1.2 } }, { _cnd: { gte: 1.7 } }]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
...import_descriptions.promptTypeOptions,
|
|
122
|
+
displayOptions: {
|
|
123
|
+
show: {
|
|
124
|
+
"@version": [{ _cnd: { gte: 1.7 } }]
|
|
117
125
|
}
|
|
118
126
|
}
|
|
119
127
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts"],"sourcesContent":["import { NodeConnectionTypes, parseErrorMetadata, sleep } from 'n8n-workflow';\nimport {\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nimport {\n\tpromptTypeOptions,\n\ttextFromGuardrailsNode,\n\ttextFromPreviousNode,\n} from '@utils/descriptions';\nimport { getBatchingOptionFields, getTemplateNoticeField } from '@utils/sharedFields';\n\nimport { INPUT_TEMPLATE_KEY, LEGACY_INPUT_TEMPLATE_KEY, systemPromptOption } from './constants';\nimport { processItem } from './processItem';\n\nexport class ChainRetrievalQa implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Question and Answer Chain',\n\t\tname: 'chainRetrievalQa',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6],\n\t\tdescription: 'Answer questions about retrieved documents',\n\t\tdefaults: {\n\t\t\tname: 'Question and Answer Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainretrievalqa/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [\n\t\t\tNodeConnectionTypes.Main,\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Retriever',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiRetriever,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: [\n\t\t\tgetTemplateNoticeField(1960),\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chat_input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chatInput }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.2],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...promptTypeOptions,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...textFromGuardrailsNode,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: { promptType: ['guardrails'], '@version': [{ _cnd: { gte: 1.4 } }] },\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...textFromPreviousNode,\n\t\t\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.4 } }] } },\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Prompt (User Message)',\n\t\t\t\tname: 'text',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tpromptType: ['define'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${LEGACY_INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetBatchingOptionFields({\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.6 } }],\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Retrieval QA Chain');\n\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\t\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'options.batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tif (this.getNode().typeVersion >= 1.6 && batchSize >= 1) {\n\t\t\t// Run in batches\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\t\t\treturn await processItem(this, i + batchItemIndex);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\n\t\t\t\tbatchResults.forEach((response, index) => {\n\t\t\t\t\tif (response.status === 'rejected') {\n\t\t\t\t\t\tconst error = response.reason;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: index },\n\t\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst output = response.value;\n\t\t\t\t\tconst answer = output.answer as string;\n\t\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t// Add delay between batches if not the last batch\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Run for each item\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await processItem(this, itemIndex);\n\t\t\t\t\tconst answer = response.answer as string;\n\t\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA+D;AAQ/D,0BAIO;AACP,0BAAgE;AAEhE,uBAAkF;AAClF,yBAA4B;AAErB,MAAM,iBAAsC;AAAA,EAA5C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,MACzC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,cAAI,KAAK,QAAQ,EAAE,eAAe,KAAK;AACtC,uBAAW,KAAK,EAAE,MAAM,EAAE,UAAU,OAAO,EAAE,CAAC;AAAA,UAC/C,OAAO;AAEN,uBAAW,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,EAAE,EAAE,CAAC;AAAA,UACzD;AAAA,QACD,CAAC;AAGD,YAAI,IAAI,YAAY,MAAM,UAAU,sBAAsB,GAAG;AAC5D,oBAAM,2BAAM,mBAAmB;AAAA,QAChC;AAAA,MACD;AAAA,IACD,OAAO;AAEN,eAAS,YAAY,GAAG,YAAY,MAAM,QAAQ,aAAa;AAC9D,YAAI;AACH,gBAAM,WAAW,UAAM,gCAAY,MAAM,SAAS;AAClD,gBAAM,SAAS,SAAS;AACxB,cAAI,KAAK,QAAQ,EAAE,eAAe,KAAK;AACtC,uBAAW,KAAK,EAAE,MAAM,EAAE,UAAU,OAAO,EAAE,CAAC;AAAA,UAC/C,OAAO;AAEN,uBAAW,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,EAAE,EAAE,CAAC;AAAA,UACzD;AAAA,QACD,SAAS,OAAO;AACf,cAAI,KAAK,eAAe,GAAG;AAC1B,kBAAM,eAAW,wCAAmB,KAAK;AACzC,uBAAW,KAAK;AAAA,cACf,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,cAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,cAC9B;AAAA,YACD,CAAC;AACD;AAAA,UACD;AAEA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AACA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.ts"],"sourcesContent":["import { NodeConnectionTypes, parseErrorMetadata, sleep } from 'n8n-workflow';\nimport {\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nimport {\n\tpromptTypeOptions,\n\tpromptTypeOptionsDeprecated,\n\ttextFromGuardrailsNode,\n\ttextFromPreviousNode,\n} from '@utils/descriptions';\nimport { getBatchingOptionFields, getTemplateNoticeField } from '@utils/sharedFields';\n\nimport { INPUT_TEMPLATE_KEY, LEGACY_INPUT_TEMPLATE_KEY, systemPromptOption } from './constants';\nimport { processItem } from './processItem';\n\nexport class ChainRetrievalQa implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Question and Answer Chain',\n\t\tname: 'chainRetrievalQa',\n\t\ticon: 'fa:link',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7],\n\t\tdescription: 'Answer questions about retrieved documents',\n\t\tdefaults: {\n\t\t\tname: 'Question and Answer Chain',\n\t\t\tcolor: '#909298',\n\t\t},\n\t\tcodex: {\n\t\t\talias: ['LangChain'],\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.chainretrievalqa/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [\n\t\t\tNodeConnectionTypes.Main,\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Retriever',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiRetriever,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tcredentials: [],\n\t\tproperties: [\n\t\t\tgetTemplateNoticeField(1960),\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chat_input }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Query',\n\t\t\t\tname: 'query',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '={{ $json.chatInput }}',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.2],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...promptTypeOptionsDeprecated,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }, { _cnd: { gte: 1.7 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...promptTypeOptions,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.7 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...textFromGuardrailsNode,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: { promptType: ['guardrails'], '@version': [{ _cnd: { gte: 1.4 } }] },\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...textFromPreviousNode,\n\t\t\t\tdisplayOptions: { show: { promptType: ['auto'], '@version': [{ _cnd: { gte: 1.4 } }] } },\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Prompt (User Message)',\n\t\t\t\tname: 'text',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. Hello, how can you help me?',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tpromptType: ['define'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${LEGACY_INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { lt: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t...systemPromptOption,\n\t\t\t\t\t\tdescription: `Template string used for the system prompt. This should include the variable \\`{context}\\` for the provided context. For text completion models, you should also include the variable \\`{${INPUT_TEMPLATE_KEY}}\\` for the user’s query.`,\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.5 } }],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\tgetBatchingOptionFields({\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.6 } }],\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Retrieval QA Chain');\n\n\t\tconst items = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\t\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'options.batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tif (this.getNode().typeVersion >= 1.6 && batchSize >= 1) {\n\t\t\t// Run in batches\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\t\t\treturn await processItem(this, i + batchItemIndex);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\n\t\t\t\tbatchResults.forEach((response, index) => {\n\t\t\t\t\tif (response.status === 'rejected') {\n\t\t\t\t\t\tconst error = response.reason;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: index },\n\t\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst output = response.value;\n\t\t\t\t\tconst answer = output.answer as string;\n\t\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t// Add delay between batches if not the last batch\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Run for each item\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await processItem(this, itemIndex);\n\t\t\t\t\tconst answer = response.answer as string;\n\t\t\t\t\tif (this.getNode().typeVersion >= 1.5) {\n\t\t\t\t\t\treturnData.push({ json: { response: answer } });\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Legacy format for versions 1.4 and below is { text: string }\n\t\t\t\t\t\treturnData.push({ json: { response: { text: answer } } });\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\tconst metadata = parseErrorMetadata(error);\n\t\t\t\t\t\treturnData.push({\n\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA+D;AAQ/D,0BAKO;AACP,0BAAgE;AAEhE,uBAAkF;AAClF,yBAA4B;AAErB,MAAM,iBAAsC;AAAA,EAA5C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA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,cAC9B;AAAA,YACD,CAAC;AACD;AAAA,UACD;AAEA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AACA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
@@ -22,9 +22,9 @@ __export(ToolSerpApi_node_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ToolSerpApi_node_exports);
|
|
24
24
|
var import_serpapi = require("@langchain/community/tools/serpapi");
|
|
25
|
-
var import_n8n_workflow = require("n8n-workflow");
|
|
26
25
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
26
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
27
|
+
var import_n8n_workflow = require("n8n-workflow");
|
|
28
28
|
async function getTool(ctx, itemIndex) {
|
|
29
29
|
const credentials = await ctx.getCredentials("serpApi");
|
|
30
30
|
const options = ctx.getNodeParameter("options", itemIndex);
|
|
@@ -138,8 +138,14 @@ class ToolSerpApi {
|
|
|
138
138
|
const returnData = [];
|
|
139
139
|
for (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {
|
|
140
140
|
const tool = await getTool(this, itemIndex);
|
|
141
|
-
const
|
|
142
|
-
|
|
141
|
+
const item = inputData[itemIndex].json;
|
|
142
|
+
if (typeof item.input !== "string" || !item.input) {
|
|
143
|
+
throw new import_n8n_workflow.NodeOperationError(
|
|
144
|
+
this.getNode(),
|
|
145
|
+
`Missing search query input at itemIndex ${itemIndex}`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
const result = await tool.invoke(item);
|
|
143
149
|
returnData.push({
|
|
144
150
|
json: {
|
|
145
151
|
response: result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolSerpApi/ToolSerpApi.node.ts"],"sourcesContent":["import { SerpAPI } from '@langchain/community/tools/serpapi';\nimport {\n\ttype IExecuteFunctions,\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\ttype INodeExecutionData,\n} from 'n8n-workflow';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolSerpApi/ToolSerpApi.node.ts"],"sourcesContent":["import { SerpAPI } from '@langchain/community/tools/serpapi';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\nimport {\n\ttype IExecuteFunctions,\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\ttype INodeExecutionData,\n\tNodeOperationError,\n} from 'n8n-workflow';\n\nasync function getTool(ctx: ISupplyDataFunctions | IExecuteFunctions, itemIndex: number) {\n\tconst credentials = await ctx.getCredentials('serpApi');\n\n\tconst options = ctx.getNodeParameter('options', itemIndex) as object;\n\n\treturn new SerpAPI(credentials.apiKey as string, options);\n}\n\nexport class ToolSerpApi implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'SerpApi (Google Search)',\n\t\tname: 'toolSerpApi',\n\t\ticon: 'file:serpApi.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Search in Google using SerpAPI',\n\t\tdefaults: {\n\t\t\tname: 'SerpAPI',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Tools'],\n\t\t\t\tTools: ['Other Tools'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolserpapi/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'serpApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Country',\n\t\t\t\t\t\tname: 'gl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'us',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the country to use for search. Head to <a href=\"https://serpapi.com/google-countries\">Google countries page</a> for a full list of supported countries.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Device',\n\t\t\t\t\t\tname: 'device',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Desktop',\n\t\t\t\t\t\t\t\tvalue: 'desktop',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Mobile',\n\t\t\t\t\t\t\t\tvalue: 'mobile',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Tablet',\n\t\t\t\t\t\t\t\tvalue: 'tablet',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t\tdefault: 'desktop',\n\t\t\t\t\t\tdescription: 'Device to use to get the results',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Explicit Array',\n\t\t\t\t\t\tname: 'no_cache',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to force SerpApi to fetch the Google results even if a cached version is already present. Cache expires after 1h. Cached searches are free, and are not counted towards your searches per month.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Google Domain',\n\t\t\t\t\t\tname: 'google_domain',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'google.com',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the domain to use for search. Head to <a href=\"https://serpapi.com/google-domains\">Google domains page</a> for a full list of supported domains.',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Language',\n\t\t\t\t\t\tname: 'hl',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: 'en',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Defines the language to use. It\\'s a two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for French). Head to <a href=\"https://serpapi.com/google-languages\">Google languages page</a> for a full list of supported languages.',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\treturn {\n\t\t\tresponse: logWrapper(await getTool(this, itemIndex), this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst inputData = this.getInputData();\n\t\tconst returnData: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {\n\t\t\tconst tool = await getTool(this, itemIndex);\n\t\t\tconst item = inputData[itemIndex].json;\n\n\t\t\tif (typeof item.input !== 'string' || !item.input) {\n\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\tthis.getNode(),\n\t\t\t\t\t`Missing search query input at itemIndex ${itemIndex}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst result = (await tool.invoke(item)) as string;\n\n\t\t\treturnData.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: result,\n\t\t\t\t},\n\t\t\t\tpairedItem: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O,IAAI;AAEtC,iBAAW,KAAK;AAAA,QACf,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY,EAAE,MAAM,UAAU;AAAA,MAC/B,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":[]}
|
|
@@ -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\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\tjsonParse,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\tparseErrorMetadata,\n\tsleepWithAbort,\n} from 'n8n-workflow';\n\nimport {\n\tcreateZodSchemaFromArgs,\n\textractFromAIParameters,\n} from '../../../../../utils/fromAIToolFactory';\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\t// If manualLogging is enabled we've been called by the AgentExecutor\n\t\t\t\t\t// and have to return a stringified response.\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\n\t\t\t\t\t\treturn processedResponse;\n\t\t\t\t\t}\n\n\t\t\t\t\t// If manualLogging is false we've been called by the engine and need\n\t\t\t\t\t// the structured response.\n\t\t\t\t\treturn responseData;\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? 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: 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<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 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): DynamicStructuredTool | DynamicTool {\n\t\tconst collectedArguments = extractFromAIParameters(this.baseContext.getNode().parameters);\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 = createZodSchemaFromArgs(collectedArguments);\n\t\treturn new DynamicStructuredTool({ schema, name, description, func });\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmD;AACnD,qBAAoB;AACpB,sBAAqB;AAErB,aAAwB;AACxB,8BAA4C;AAe5C,0BAMO;AAEP,+BAGO;AAEP,SAAS,oBAAoB,MAA6C;AACzE,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
|
|
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\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\tjsonParse,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\tparseErrorMetadata,\n\tsleepWithAbort,\n} from 'n8n-workflow';\n\nimport {\n\tcreateZodSchemaFromArgs,\n\textractFromAIParameters,\n} from '../../../../../utils/fromAIToolFactory';\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\t// If manualLogging is enabled we've been called by the AgentExecutor\n\t\t\t\t\t// and have to return a stringified response.\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\n\t\t\t\t\t\treturn processedResponse;\n\t\t\t\t\t}\n\t\t\t\t\t// If manualLogging is false we've been called by the engine and need\n\t\t\t\t\t// the structured response.\n\n\t\t\t\t\tif (metadata && 'setMetadata' in context) {\n\t\t\t\t\t\tvoid context.setMetadata(metadata);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn responseData;\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? 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: 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<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 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): DynamicStructuredTool | DynamicTool {\n\t\tconst collectedArguments = extractFromAIParameters(this.baseContext.getNode().parameters);\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 = createZodSchemaFromArgs(collectedArguments);\n\t\treturn new DynamicStructuredTool({ schema, name, description, func });\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmD;AACnD,qBAAoB;AACpB,sBAAqB;AAErB,aAAwB;AACxB,8BAA4C;AAe5C,0BAMO;AAEP,+BAGO;AAEP,SAAS,oBAAoB,MAA6C;AACzE,aAAO,eAAAA,SAAQ,IAAI,KAAK,QAAQ,KAAK,MAAM,SAAK,gBAAAC,SAAS,KAAK,CAAC,CAAC,KAAK,UAAU,KAAK,CAAC;AACtF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8n_workflow.Node {
|
|
|
284
284
|
{
|
|
285
285
|
name: "default",
|
|
286
286
|
httpMethod: "POST",
|
|
287
|
-
responseMode: '={{$parameter.options?.["responseMode"]
|
|
287
|
+
responseMode: '={{$parameter.options?.["responseMode"] ?? ($parameter.availableInChat ? "streaming" : "lastNode") }}',
|
|
288
288
|
path: CHAT_TRIGGER_PATH_IDENTIFIER,
|
|
289
289
|
ndvHideMethod: true,
|
|
290
290
|
ndvHideUrl: "={{ !$parameter.public }}"
|
|
@@ -328,7 +328,7 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
328
328
|
}
|
|
329
329
|
},
|
|
330
330
|
{
|
|
331
|
-
displayName: "Chat will be live at the URL above once
|
|
331
|
+
displayName: "Chat will be live at the URL above once this workflow is published. Live executions will show up in the \u2018executions\u2019 tab",
|
|
332
332
|
name: "hostedChatNotice",
|
|
333
333
|
type: "notice",
|
|
334
334
|
displayOptions: {
|
|
@@ -340,7 +340,7 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
340
340
|
default: ""
|
|
341
341
|
},
|
|
342
342
|
{
|
|
343
|
-
displayName: 'Follow the instructions <a href="https://www.npmjs.com/package/@n8n/chat" target="_blank">here</a> to embed chat in a webpage (or just call the webhook URL at the top of this section). Chat will be live once you
|
|
343
|
+
displayName: 'Follow the instructions <a href="https://www.npmjs.com/package/@n8n/chat" target="_blank">here</a> to embed chat in a webpage (or just call the webhook URL at the top of this section). Chat will be live once you publish this workflow',
|
|
344
344
|
name: "embeddedChatNotice",
|
|
345
345
|
type: "notice",
|
|
346
346
|
displayOptions: {
|
|
@@ -403,12 +403,31 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
403
403
|
type: "boolean",
|
|
404
404
|
default: false,
|
|
405
405
|
noDataExpression: true,
|
|
406
|
-
description: "Whether to make the agent available in n8n Chat"
|
|
406
|
+
description: "Whether to make the agent available in n8n Chat"
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
displayName: "Your Chat Trigger node is out of date. To update, delete this node and insert a new Chat Trigger node.",
|
|
410
|
+
name: "availableInChatNotice",
|
|
411
|
+
type: "notice",
|
|
407
412
|
displayOptions: {
|
|
408
413
|
show: {
|
|
409
|
-
|
|
414
|
+
availableInChat: [true],
|
|
415
|
+
"@version": [{ _cnd: { lt: 1.2 } }]
|
|
410
416
|
}
|
|
411
|
-
}
|
|
417
|
+
},
|
|
418
|
+
default: ""
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
displayName: 'Your n8n users will be able to use this agent in <a href="/home/chat/" target="_blank">Chat</a> once this workflow is published. Make sure to share this workflow with at least Project Chat User access to all users who should use it. Currently, only streaming response mode is supported.',
|
|
422
|
+
name: "availableInChatNotice",
|
|
423
|
+
type: "notice",
|
|
424
|
+
displayOptions: {
|
|
425
|
+
show: {
|
|
426
|
+
availableInChat: [true],
|
|
427
|
+
"@version": [{ _cnd: { gte: 1.2 } }]
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
default: ""
|
|
412
431
|
},
|
|
413
432
|
{
|
|
414
433
|
displayName: "Agent Name",
|
|
@@ -416,10 +435,11 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
416
435
|
type: "string",
|
|
417
436
|
default: "",
|
|
418
437
|
noDataExpression: true,
|
|
419
|
-
description: "The name of the agent on n8n Chat",
|
|
438
|
+
description: "The name of the agent on n8n Chat. Name of the workflow is used if left empty.",
|
|
420
439
|
displayOptions: {
|
|
421
440
|
show: {
|
|
422
|
-
availableInChat: [true]
|
|
441
|
+
availableInChat: [true],
|
|
442
|
+
"@version": [{ _cnd: { gte: 1.2 } }]
|
|
423
443
|
}
|
|
424
444
|
}
|
|
425
445
|
},
|
|
@@ -435,7 +455,8 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
435
455
|
description: "The description of the agent on n8n Chat",
|
|
436
456
|
displayOptions: {
|
|
437
457
|
show: {
|
|
438
|
-
availableInChat: [true]
|
|
458
|
+
availableInChat: [true],
|
|
459
|
+
"@version": [{ _cnd: { gte: 1.2 } }]
|
|
439
460
|
}
|
|
440
461
|
}
|
|
441
462
|
},
|
|
@@ -501,7 +522,17 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
501
522
|
type: "options",
|
|
502
523
|
options: [lastNodeResponseMode, respondToWebhookResponseMode, streamingResponseMode],
|
|
503
524
|
default: "lastNode",
|
|
504
|
-
description: "When and how to respond to the webhook"
|
|
525
|
+
description: "When and how to respond to the webhook",
|
|
526
|
+
displayOptions: { show: { "/availableInChat": [false] } }
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
displayName: "Response Mode",
|
|
530
|
+
name: "responseMode",
|
|
531
|
+
type: "options",
|
|
532
|
+
options: [streamingResponseMode],
|
|
533
|
+
default: "streaming",
|
|
534
|
+
description: "When and how to respond to the webhook",
|
|
535
|
+
displayOptions: { show: { "/availableInChat": [true] } }
|
|
505
536
|
}
|
|
506
537
|
]
|
|
507
538
|
},
|
|
@@ -524,9 +555,19 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
524
555
|
displayName: "Response Mode",
|
|
525
556
|
name: "responseMode",
|
|
526
557
|
type: "options",
|
|
527
|
-
options: [lastNodeResponseMode, respondNodesResponseMode],
|
|
558
|
+
options: [lastNodeResponseMode, respondNodesResponseMode, streamingResponseMode],
|
|
528
559
|
default: "lastNode",
|
|
529
|
-
description: "When and how to respond to the chat"
|
|
560
|
+
description: "When and how to respond to the chat",
|
|
561
|
+
displayOptions: { show: { "/availableInChat": [false] } }
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
displayName: "Response Mode",
|
|
565
|
+
name: "responseMode",
|
|
566
|
+
type: "options",
|
|
567
|
+
options: [streamingResponseMode],
|
|
568
|
+
default: "streaming",
|
|
569
|
+
description: "When and how to respond to the webhook",
|
|
570
|
+
displayOptions: { show: { "/availableInChat": [true] } }
|
|
530
571
|
}
|
|
531
572
|
]
|
|
532
573
|
},
|
|
@@ -545,6 +586,15 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
545
586
|
default: {},
|
|
546
587
|
options: [
|
|
547
588
|
...commonOptionsFields,
|
|
589
|
+
{
|
|
590
|
+
displayName: "Response Mode",
|
|
591
|
+
name: "responseMode",
|
|
592
|
+
type: "options",
|
|
593
|
+
options: [streamingResponseMode],
|
|
594
|
+
default: "streaming",
|
|
595
|
+
description: "When and how to respond to the webhook",
|
|
596
|
+
displayOptions: { show: { "/availableInChat": [true] } }
|
|
597
|
+
},
|
|
548
598
|
{
|
|
549
599
|
displayName: "Response Mode",
|
|
550
600
|
name: "responseMode",
|
|
@@ -552,7 +602,7 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
552
602
|
options: [lastNodeResponseMode, streamingResponseMode, respondToWebhookResponseMode],
|
|
553
603
|
default: "lastNode",
|
|
554
604
|
description: "When and how to respond to the chat",
|
|
555
|
-
displayOptions: { show: { "/mode": ["webhook"] } }
|
|
605
|
+
displayOptions: { show: { "/mode": ["webhook"], "/availableInChat": [false] } }
|
|
556
606
|
},
|
|
557
607
|
{
|
|
558
608
|
displayName: "Response Mode",
|
|
@@ -561,7 +611,7 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
561
611
|
options: [lastNodeResponseMode, streamingResponseMode, respondNodesResponseMode],
|
|
562
612
|
default: "lastNode",
|
|
563
613
|
description: "When and how to respond to the webhook",
|
|
564
|
-
displayOptions: { show: { "/mode": ["hostedChat"] } }
|
|
614
|
+
displayOptions: { show: { "/mode": ["hostedChat"], "/availableInChat": [false] } }
|
|
565
615
|
}
|
|
566
616
|
]
|
|
567
617
|
}
|
|
@@ -631,6 +681,7 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
631
681
|
noWebhookResponse: true
|
|
632
682
|
};
|
|
633
683
|
}
|
|
684
|
+
const availableInChat = ctx.getNodeParameter("availableInChat", false);
|
|
634
685
|
const options = ctx.getNodeParameter("options", {});
|
|
635
686
|
(0, import_n8n_workflow.validateNodeParameters)(
|
|
636
687
|
options,
|
|
@@ -650,7 +701,7 @@ class ChatTrigger extends import_n8n_workflow.Node {
|
|
|
650
701
|
);
|
|
651
702
|
const loadPreviousSession = options.loadPreviousSession;
|
|
652
703
|
(0, import_types.assertValidLoadPreviousSessionOption)(loadPreviousSession, ctx.getNode());
|
|
653
|
-
const enableStreaming = options.responseMode === "streaming";
|
|
704
|
+
const enableStreaming = availableInChat ? !options.responseMode || options.responseMode === "streaming" : options.responseMode === "streaming";
|
|
654
705
|
const req = ctx.getRequestObject();
|
|
655
706
|
const webhookName = ctx.getWebhookName();
|
|
656
707
|
const mode = ctx.getMode() === "manual" ? "test" : "production";
|