@n8n/n8n-nodes-langchain 1.121.0 → 1.122.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/nodes/Guardrails/Guardrails.node.js +29 -40
- package/dist/nodes/Guardrails/Guardrails.node.js.map +1 -1
- package/dist/nodes/Guardrails/actions/execute.js +68 -0
- package/dist/nodes/Guardrails/actions/execute.js.map +1 -0
- package/dist/nodes/Guardrails/actions/process.js +10 -7
- package/dist/nodes/Guardrails/actions/process.js.map +1 -1
- package/dist/nodes/Guardrails/description.js +326 -365
- package/dist/nodes/Guardrails/description.js.map +1 -1
- package/dist/nodes/Guardrails/helpers/configureNodeInputs.js +37 -3
- package/dist/nodes/Guardrails/helpers/configureNodeInputs.js.map +1 -1
- package/dist/nodes/Guardrails/helpers/model.js.map +1 -1
- package/dist/nodes/Guardrails/v1/GuardrailsV1.node.js +59 -0
- package/dist/nodes/Guardrails/v1/GuardrailsV1.node.js.map +1 -0
- package/dist/nodes/Guardrails/v2/GuardrailsV2.node.js +59 -0
- package/dist/nodes/Guardrails/v2/GuardrailsV2.node.js.map +1 -0
- package/dist/nodes/ToolExecutor/ToolExecutor.node.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js +3 -85
- package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js +2 -2
- package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildExecutionContext.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/finalizeResult.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/prepareItemContext.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js +8 -16
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/utils.js.map +1 -1
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js +2 -2
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js.map +1 -1
- package/dist/nodes/chains/ChainRetrievalQA/processItem.js +2 -2
- package/dist/nodes/chains/ChainRetrievalQA/processItem.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js +1 -1
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/processItem.js +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/processItem.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/helpers.js.map +1 -1
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +1 -1
- package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -1
- package/dist/nodes/chains/InformationExtractor/processItem.js.map +1 -1
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js +1 -1
- package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js.map +1 -1
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js +1 -1
- package/dist/nodes/chains/TextClassifier/TextClassifier.node.js.map +1 -1
- package/dist/nodes/chains/TextClassifier/processItem.js.map +1 -1
- package/dist/nodes/code/Code.node.js +66 -2
- package/dist/nodes/code/Code.node.js.map +1 -1
- package/dist/nodes/llms/LMOllama/LmOllama.node.js +1 -1
- package/dist/nodes/llms/LMOllama/LmOllama.node.js.map +1 -1
- package/dist/nodes/mcp/McpClientTool/utils.js +1 -1
- package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js +1 -1
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js.map +1 -1
- package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js +1 -1
- package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js +1 -1
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js +1 -1
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js +1 -1
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js +2 -2
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js +1 -1
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js +1 -1
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js.map +1 -1
- package/dist/nodes/tools/ToolThink/ToolThink.node.js +1 -1
- package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -1
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js +2 -2
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +5 -21
- package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/Chat.node.js +2 -2
- package/dist/nodes/trigger/ChatTrigger/Chat.node.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js +65 -17
- package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreQdrant/qdrant.svg +23 -19
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryCalculator.js.map +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js.map +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/StoreCleanupService.js.map +1 -1
- package/dist/nodes/vector_store/shared/MemoryManager/types.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +18 -16
- package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/edit.operation.js +6 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/edit.operation.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/generate.operation.js +1 -1
- package/dist/nodes/vendors/GoogleGemini/actions/image/generate.operation.js.map +1 -1
- package/dist/nodes/vendors/GoogleGemini/methods/listSearch.js +23 -8
- package/dist/nodes/vendors/GoogleGemini/methods/listSearch.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/helpers/utils.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js +2 -2
- package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js.map +1 -1
- package/dist/types/nodes.json +7 -6
- package/dist/utils/N8nBinaryLoader.js +2 -2
- package/dist/utils/N8nBinaryLoader.js.map +1 -1
- package/dist/utils/N8nJsonLoader.js +2 -2
- package/dist/utils/N8nJsonLoader.js.map +1 -1
- package/dist/utils/N8nTool.js +1 -1
- package/dist/utils/N8nTool.js.map +1 -1
- package/dist/utils/agent-execution/buildSteps.js +12 -8
- package/dist/utils/agent-execution/buildSteps.js.map +1 -1
- package/dist/utils/agent-execution/createEngineRequests.js +19 -1
- package/dist/utils/agent-execution/createEngineRequests.js.map +1 -1
- package/dist/utils/agent-execution/index.js +4 -4
- package/dist/utils/agent-execution/index.js.map +1 -1
- package/dist/utils/agent-execution/memoryManagement.js +15 -14
- package/dist/utils/agent-execution/memoryManagement.js.map +1 -1
- package/dist/utils/agent-execution/processEventStream.js +1 -47
- package/dist/utils/agent-execution/processEventStream.js.map +1 -1
- package/dist/utils/agent-execution/types.js.map +1 -1
- package/dist/utils/fromAIToolFactory.js +61 -0
- package/dist/utils/fromAIToolFactory.js.map +1 -0
- package/dist/utils/helpers.js +1 -1
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/logWrapper.js.map +1 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js +1 -1
- package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -1
- package/package.json +31 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryXata/MemoryXata.node.ts"],"sourcesContent":["import { XataChatMessageHistory } from '@langchain/community/stores/message/xata';\nimport { BaseClient } from '@xata.io/client';\nimport { BufferMemory, BufferWindowMemory } from 'langchain/memory';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport {\n\tsessionIdOption,\n\tsessionKeyProperty,\n\tcontextWindowLengthProperty,\n\texpressionSessionKeyProperty,\n} from '../descriptions';\n\nexport class MemoryXata implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Xata',\n\t\tname: 'memoryXata',\n\t\ticon: 'file:xata.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4],\n\t\tdescription: 'Use Xata Memory',\n\t\tdefaults: {\n\t\t\tname: 'Xata',\n\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-non-core-color-present\n\t\t\tcolor: '#1321A7',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['Other memories'],\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.memoryxata/',\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.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'xataApi',\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: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\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: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '={{ $json.sessionId }}',\n\t\t\t\tdescription: 'The key to use to store the memory',\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\t...sessionIdOption,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tsessionKeyProperty,\n\t\t\texpressionSessionKeyProperty(1.4),\n\t\t\t{\n\t\t\t\t...contextWindowLengthProperty,\n\t\t\t\tdisplayOptions: { hide: { '@version': [{ _cnd: { lt: 1.3 } }] } },\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('xataApi');\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tlet sessionId;\n\n\t\tif (nodeVersion >= 1.2) {\n\t\t\tsessionId = getSessionId(this, itemIndex);\n\t\t} else {\n\t\t\tsessionId = this.getNodeParameter('sessionId', itemIndex) as string;\n\t\t}\n\n\t\tconst xataClient = new BaseClient({\n\t\t\tapiKey: credentials.apiKey as string,\n\t\t\tbranch: (credentials.branch as string) || 'main',\n\t\t\tdatabaseURL: credentials.databaseEndpoint as string,\n\t\t});\n\n\t\tconst table = (credentials.databaseEndpoint as string).match(\n\t\t\t/https:\\/\\/[^.]+\\.[^.]+\\.xata\\.sh\\/db\\/([^\\/:]+)/,\n\t\t);\n\n\t\tif (table === null) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'It was not possible to extract the table from the Database Endpoint.',\n\t\t\t);\n\t\t}\n\n\t\tconst chatHistory = new XataChatMessageHistory({\n\t\t\ttable: table[1],\n\t\t\tsessionId,\n\t\t\tclient: xataClient,\n\t\t\tapiKey: credentials.apiKey as string,\n\t\t});\n\n\t\tconst memClass = this.getNode().typeVersion < 1.3 ? BufferMemory : BufferWindowMemory;\n\t\tconst kOptions =\n\t\t\tthis.getNode().typeVersion < 1.3\n\t\t\t\t? {}\n\t\t\t\t: { k: this.getNodeParameter('contextWindowLength', itemIndex) };\n\n\t\tconst memory = new memClass({\n\t\t\tchatHistory,\n\t\t\tmemoryKey: 'chat_history',\n\t\t\treturnMessages: true,\n\t\t\tinputKey: 'input',\n\t\t\toutputKey: 'output',\n\t\t\t...kOptions,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuC;AACvC,oBAA2B;AAC3B,oBAAiD;AACjD,0BAAwD;AAQxD,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM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ACX,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryXata/MemoryXata.node.ts"],"sourcesContent":["import { XataChatMessageHistory } from '@langchain/community/stores/message/xata';\nimport { BaseClient } from '@xata.io/client';\nimport { BufferMemory, BufferWindowMemory } from '@langchain/classic/memory';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport {\n\tsessionIdOption,\n\tsessionKeyProperty,\n\tcontextWindowLengthProperty,\n\texpressionSessionKeyProperty,\n} from '../descriptions';\n\nexport class MemoryXata implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Xata',\n\t\tname: 'memoryXata',\n\t\ticon: 'file:xata.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4],\n\t\tdescription: 'Use Xata Memory',\n\t\tdefaults: {\n\t\t\tname: 'Xata',\n\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-non-core-color-present\n\t\t\tcolor: '#1321A7',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['Other memories'],\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.memoryxata/',\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.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'xataApi',\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: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\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: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '={{ $json.sessionId }}',\n\t\t\t\tdescription: 'The key to use to store the memory',\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\t...sessionIdOption,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tsessionKeyProperty,\n\t\t\texpressionSessionKeyProperty(1.4),\n\t\t\t{\n\t\t\t\t...contextWindowLengthProperty,\n\t\t\t\tdisplayOptions: { hide: { '@version': [{ _cnd: { lt: 1.3 } }] } },\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('xataApi');\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tlet sessionId;\n\n\t\tif (nodeVersion >= 1.2) {\n\t\t\tsessionId = getSessionId(this, itemIndex);\n\t\t} else {\n\t\t\tsessionId = this.getNodeParameter('sessionId', itemIndex) as string;\n\t\t}\n\n\t\tconst xataClient = new BaseClient({\n\t\t\tapiKey: credentials.apiKey as string,\n\t\t\tbranch: (credentials.branch as string) || 'main',\n\t\t\tdatabaseURL: credentials.databaseEndpoint as string,\n\t\t});\n\n\t\tconst table = (credentials.databaseEndpoint as string).match(\n\t\t\t/https:\\/\\/[^.]+\\.[^.]+\\.xata\\.sh\\/db\\/([^\\/:]+)/,\n\t\t);\n\n\t\tif (table === null) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'It was not possible to extract the table from the Database Endpoint.',\n\t\t\t);\n\t\t}\n\n\t\tconst chatHistory = new XataChatMessageHistory({\n\t\t\ttable: table[1],\n\t\t\tsessionId,\n\t\t\tclient: xataClient,\n\t\t\tapiKey: credentials.apiKey as string,\n\t\t});\n\n\t\tconst memClass = this.getNode().typeVersion < 1.3 ? BufferMemory : BufferWindowMemory;\n\t\tconst kOptions =\n\t\t\tthis.getNode().typeVersion < 1.3\n\t\t\t\t? {}\n\t\t\t\t: { k: this.getNodeParameter('contextWindowLength', itemIndex) };\n\n\t\tconst memory = new memClass({\n\t\t\tchatHistory,\n\t\t\tmemoryKey: 'chat_history',\n\t\t\treturnMessages: true,\n\t\t\tinputKey: 'input',\n\t\t\toutputKey: 'output',\n\t\t\t...kOptions,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuC;AACvC,oBAA2B;AAC3B,oBAAiD;AACjD,0BAAwD;AAQxD,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,WAAgC;AAAA,EAAtC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAA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/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js
CHANGED
|
@@ -21,8 +21,8 @@ __export(RetrieverContextualCompression_node_exports, {
|
|
|
21
21
|
RetrieverContextualCompression: () => RetrieverContextualCompression
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(RetrieverContextualCompression_node_exports);
|
|
24
|
-
var import_contextual_compression = require("langchain/retrievers/contextual_compression");
|
|
25
|
-
var import_chain_extract = require("langchain/retrievers/document_compressors/chain_extract");
|
|
24
|
+
var import_contextual_compression = require("@langchain/classic/retrievers/contextual_compression");
|
|
25
|
+
var import_chain_extract = require("@langchain/classic/retrievers/document_compressors/chain_extract");
|
|
26
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
27
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
28
28
|
class RetrieverContextualCompression {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { BaseRetriever } from '@langchain/core/retrievers';\nimport { ContextualCompressionRetriever } from 'langchain/retrievers/contextual_compression';\nimport { LLMChainExtractor } from 'langchain/retrievers/document_compressors/chain_extract';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverContextualCompression implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Contextual Compression Retriever',\n\t\tname: 'retrieverContextualCompression',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Enhances document similarity search by contextual compression.',\n\t\tdefaults: {\n\t\t\tname: 'Contextual Compression Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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.retrievercontextualcompression/',\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\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: [\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},\n\t\t],\n\t\tproperties: [],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supplying data for Contextual Compression Retriever');\n\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\titemIndex,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst baseRetriever = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiRetriever,\n\t\t\titemIndex,\n\t\t)) as BaseRetriever;\n\n\t\tconst baseCompressor = LLMChainExtractor.fromLLM(model);\n\n\t\tconst retriever = new ContextualCompressionRetriever({\n\t\t\tbaseCompressor,\n\t\t\tbaseRetriever,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(retriever, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;A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;AAAA,MACN,cAAU,8BAAW,WAAW,IAAI;AAAA,IACrC;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { BaseRetriever } from '@langchain/core/retrievers';\nimport { ContextualCompressionRetriever } from '@langchain/classic/retrievers/contextual_compression';\nimport { LLMChainExtractor } from '@langchain/classic/retrievers/document_compressors/chain_extract';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverContextualCompression implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Contextual Compression Retriever',\n\t\tname: 'retrieverContextualCompression',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Enhances document similarity search by contextual compression.',\n\t\tdefaults: {\n\t\t\tname: 'Contextual Compression Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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.retrievercontextualcompression/',\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\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: [\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},\n\t\t],\n\t\tproperties: [],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supplying data for Contextual Compression Retriever');\n\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\titemIndex,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst baseRetriever = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiRetriever,\n\t\t\titemIndex,\n\t\t)) as BaseRetriever;\n\n\t\tconst baseCompressor = LLMChainExtractor.fromLLM(model);\n\n\t\tconst retriever = new ContextualCompressionRetriever({\n\t\t\tbaseCompressor,\n\t\t\tbaseRetriever,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(retriever, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oCAA+C;AAC/C,2BAAkC;AAClC,0BAMO;AAEP,wBAA2B;AAEpB,MAAM,+BAAoD;AAAA,EAA1D;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,YAAY;AAAA,QAClB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ;AAAA,QACP;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,QACA;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,SAAS;AAAA,QACR;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,QAC3B;AAAA,MACD;AAAA,MACA,YAAY,CAAC;AAAA,IACd;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,SAAK,OAAO,MAAM,qDAAqD;AAEvE,UAAM,QAAS,MAAM,KAAK;AAAA,MACzB,wCAAoB;AAAA,MACpB;AAAA,IACD;AAEA,UAAM,gBAAiB,MAAM,KAAK;AAAA,MACjC,wCAAoB;AAAA,MACpB;AAAA,IACD;AAEA,UAAM,iBAAiB,uCAAkB,QAAQ,KAAK;AAEtD,UAAM,YAAY,IAAI,6DAA+B;AAAA,MACpD;AAAA,MACA;AAAA,IACD,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,WAAW,IAAI;AAAA,IACrC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -21,7 +21,7 @@ __export(RetrieverMultiQuery_node_exports, {
|
|
|
21
21
|
RetrieverMultiQuery: () => RetrieverMultiQuery
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(RetrieverMultiQuery_node_exports);
|
|
24
|
-
var import_multi_query = require("langchain/retrievers/multi_query");
|
|
24
|
+
var import_multi_query = require("@langchain/classic/retrievers/multi_query");
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
26
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
27
|
class RetrieverMultiQuery {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { BaseRetriever } from '@langchain/core/retrievers';\nimport { MultiQueryRetriever } from 'langchain/retrievers/multi_query';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverMultiQuery implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MultiQuery Retriever',\n\t\tname: 'retrieverMultiQuery',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription:\n\t\t\t'Automates prompt tuning, generates diverse queries and expands document pool for enhanced retrieval.',\n\t\tdefaults: {\n\t\t\tname: 'MultiQuery Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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.retrievermultiquery/',\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\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: [\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},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Query Count',\n\t\t\t\t\t\tname: 'queryCount',\n\t\t\t\t\t\tdefault: 3,\n\t\t\t\t\t\ttypeOptions: { minValue: 1 },\n\t\t\t\t\t\tdescription: 'Number of different versions of the given question to generate',\n\t\t\t\t\t\ttype: 'number',\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\tthis.logger.debug('Supplying data for MultiQuery Retriever');\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as { queryCount?: number };\n\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\titemIndex,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst baseRetriever = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiRetriever,\n\t\t\titemIndex,\n\t\t)) as BaseRetriever;\n\n\t\t// TODO: Add support for parserKey\n\n\t\tconst retriever = MultiQueryRetriever.fromLLM({\n\t\t\tllm: model,\n\t\t\tretriever: baseRetriever,\n\t\t\t...options,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(retriever, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAoC;AACpC,0BAMO;AAEP,wBAA2B;AAEpB,MAAM,oBAAyC;AAAA,EAA/C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,M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;AAAA,MACpB;AAAA,IACD;AAEA,UAAM,gBAAiB,MAAM,KAAK;AAAA,MACjC,wCAAoB;AAAA,MACpB;AAAA,IACD;AAIA,UAAM,YAAY,uCAAoB,QAAQ;AAAA,MAC7C,KAAK;AAAA,MACL,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,WAAW,IAAI;AAAA,IACrC;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { BaseRetriever } from '@langchain/core/retrievers';\nimport { MultiQueryRetriever } from '@langchain/classic/retrievers/multi_query';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverMultiQuery implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MultiQuery Retriever',\n\t\tname: 'retrieverMultiQuery',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription:\n\t\t\t'Automates prompt tuning, generates diverse queries and expands document pool for enhanced retrieval.',\n\t\tdefaults: {\n\t\t\tname: 'MultiQuery Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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.retrievermultiquery/',\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\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: [\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},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Query Count',\n\t\t\t\t\t\tname: 'queryCount',\n\t\t\t\t\t\tdefault: 3,\n\t\t\t\t\t\ttypeOptions: { minValue: 1 },\n\t\t\t\t\t\tdescription: 'Number of different versions of the given question to generate',\n\t\t\t\t\t\ttype: 'number',\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\tthis.logger.debug('Supplying data for MultiQuery Retriever');\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as { queryCount?: number };\n\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\titemIndex,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst baseRetriever = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiRetriever,\n\t\t\titemIndex,\n\t\t)) as BaseRetriever;\n\n\t\t// TODO: Add support for parserKey\n\n\t\tconst retriever = MultiQueryRetriever.fromLLM({\n\t\t\tllm: model,\n\t\t\tretriever: baseRetriever,\n\t\t\t...options,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(retriever, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,yBAAoC;AACpC,0BAMO;AAEP,wBAA2B;AAEpB,MAAM,oBAAyC;AAAA,EAA/C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aACC;AAAA,MACD,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,YAAY;AAAA,QAClB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ;AAAA,QACP;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,QACA;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,SAAS;AAAA,QACR;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,QAC3B;AAAA,MACD;AAAA,MACA,YAAY;AAAA,QACX;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,aAAa;AAAA,UACb,aAAa;AAAA,UACb,MAAM;AAAA,UACN,SAAS,CAAC;AAAA,UACV,SAAS;AAAA,YACR;AAAA,cACC,aAAa;AAAA,cACb,MAAM;AAAA,cACN,SAAS;AAAA,cACT,aAAa,EAAE,UAAU,EAAE;AAAA,cAC3B,aAAa;AAAA,cACb,MAAM;AAAA,YACP;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,SAAK,OAAO,MAAM,yCAAyC;AAE3D,UAAM,UAAU,KAAK,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAE9D,UAAM,QAAS,MAAM,KAAK;AAAA,MACzB,wCAAoB;AAAA,MACpB;AAAA,IACD;AAEA,UAAM,gBAAiB,MAAM,KAAK;AAAA,MACjC,wCAAoB;AAAA,MACpB;AAAA,IACD;AAIA,UAAM,YAAY,uCAAoB,QAAQ;AAAA,MAC7C,KAAK;AAAA,MACL,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,WAAW,IAAI;AAAA,IACrC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -22,7 +22,7 @@ __export(RetrieverVectorStore_node_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(RetrieverVectorStore_node_exports);
|
|
24
24
|
var import_vectorstores = require("@langchain/core/vectorstores");
|
|
25
|
-
var import_contextual_compression = require("langchain/retrievers/contextual_compression");
|
|
25
|
+
var import_contextual_compression = require("@langchain/classic/retrievers/contextual_compression");
|
|
26
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
27
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
28
28
|
class RetrieverVectorStore {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts"],"sourcesContent":["import type { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';\nimport { VectorStore } from '@langchain/core/vectorstores';\nimport { ContextualCompressionRetriever } from 'langchain/retrievers/contextual_compression';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Retriever',\n\t\tname: 'retrieverVectorStore',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Use a Vector Store as Retriever',\n\t\tdefaults: {\n\t\t\tname: 'Vector Store Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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.retrievervectorstore/',\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\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\n\t\toutputs: [NodeConnectionTypes.AiRetriever],\n\t\toutputNames: ['Retriever'],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supplying data for Vector Store Retriever');\n\n\t\tconst topK = this.getNodeParameter('topK', itemIndex, 4) as number;\n\t\tconst vectorStore = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiVectorStore,\n\t\t\titemIndex,\n\t\t)) as\n\t\t\t| VectorStore\n\t\t\t| {\n\t\t\t\t\treranker: BaseDocumentCompressor;\n\t\t\t\t\tvectorStore: VectorStore;\n\t\t\t };\n\n\t\tlet retriever = null;\n\n\t\tif (vectorStore instanceof VectorStore) {\n\t\t\tretriever = vectorStore.asRetriever(topK);\n\t\t} else {\n\t\t\tretriever = new ContextualCompressionRetriever({\n\t\t\t\tbaseCompressor: vectorStore.reranker,\n\t\t\t\tbaseRetriever: vectorStore.vectorStore.asRetriever(topK),\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tresponse: logWrapper(retriever, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAA4B;AAC5B,oCAA+C;AAC/C,0BAMO;AAEP,wBAA2B;AAEpB,MAAM,qBAA0C;AAAA,EAAhD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,YAAY;AAAA,QAClB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ;AAAA,QACP;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MAEA,SAAS,CAAC,wCAAoB,WAAW;AAAA,MACzC,aAAa,CAAC,WAAW;AAAA,MACzB,YAAY;AAAA,QACX;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,QACd;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,SAAK,OAAO,MAAM,2CAA2C;AAE7D,UAAM,OAAO,KAAK,iBAAiB,QAAQ,WAAW,CAAC;AACvD,UAAM,cAAe,MAAM,KAAK;AAAA,MAC/B,wCAAoB;AAAA,MACpB;AAAA,IACD;AAOA,QAAI,YAAY;AAEhB,QAAI,uBAAuB,iCAAa;AACvC,kBAAY,YAAY,YAAY,IAAI;AAAA,IACzC,OAAO;AACN,kBAAY,IAAI,6DAA+B;AAAA,QAC9C,gBAAgB,YAAY;AAAA,QAC5B,eAAe,YAAY,YAAY,YAAY,IAAI;AAAA,MACxD,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,MACN,cAAU,8BAAW,WAAW,IAAI;AAAA,IACrC;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.ts"],"sourcesContent":["import type { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';\nimport { VectorStore } from '@langchain/core/vectorstores';\nimport { ContextualCompressionRetriever } from '@langchain/classic/retrievers/contextual_compression';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\n\nexport class RetrieverVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Retriever',\n\t\tname: 'retrieverVectorStore',\n\t\ticon: 'fa:box-open',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Use a Vector Store as Retriever',\n\t\tdefaults: {\n\t\t\tname: 'Vector Store Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Retrievers'],\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.retrievervectorstore/',\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\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\n\t\toutputs: [NodeConnectionTypes.AiRetriever],\n\t\toutputNames: ['Retriever'],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supplying data for Vector Store Retriever');\n\n\t\tconst topK = this.getNodeParameter('topK', itemIndex, 4) as number;\n\t\tconst vectorStore = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiVectorStore,\n\t\t\titemIndex,\n\t\t)) as\n\t\t\t| VectorStore\n\t\t\t| {\n\t\t\t\t\treranker: BaseDocumentCompressor;\n\t\t\t\t\tvectorStore: VectorStore;\n\t\t\t };\n\n\t\tlet retriever = null;\n\n\t\tif (vectorStore instanceof VectorStore) {\n\t\t\tretriever = vectorStore.asRetriever(topK);\n\t\t} else {\n\t\t\tretriever = new ContextualCompressionRetriever({\n\t\t\t\tbaseCompressor: vectorStore.reranker,\n\t\t\t\tbaseRetriever: vectorStore.vectorStore.asRetriever(topK),\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tresponse: logWrapper(retriever, this),\n\t\t};\n\t}\n}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,QAC9C,gBAAgB,YAAY;AAAA,QAC5B,eAAe,YAAY,YAAY,YAAY,IAAI;AAAA,MACxD,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,MACN,cAAU,8BAAW,WAAW,IAAI;AAAA,IACrC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -21,7 +21,7 @@ __export(ToolThink_node_exports, {
|
|
|
21
21
|
ToolThink: () => ToolThink
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ToolThink_node_exports);
|
|
24
|
-
var import_tools = require("langchain/tools");
|
|
24
|
+
var import_tools = require("@langchain/classic/tools");
|
|
25
25
|
var import_n8n_workflow = require("n8n-workflow");
|
|
26
26
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
27
27
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolThink/ToolThink.node.ts"],"sourcesContent":["import { DynamicTool } from 'langchain/tools';\nimport {\n\ttype IExecuteFunctions,\n\tNodeConnectionTypes,\n\tnodeNameToToolName,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\ttype INodeExecutionData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): Promise<DynamicTool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\n\tconst name = typeVersion === 1 ? 'thinking_tool' : nodeNameToToolName(node);\n\tconst description = ctx.getNodeParameter('description', itemIndex) as string;\n\n\treturn new DynamicTool({\n\t\tname,\n\t\tdescription,\n\t\tfunc: async (subject: string) => {\n\t\t\treturn subject;\n\t\t},\n\t});\n}\n\n// A thinking tool, see https://www.anthropic.com/engineering/claude-think-tool\n\nconst defaultToolDescription =\n\t'Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.';\n\nexport class ToolThink implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Think Tool',\n\t\tname: 'toolThink',\n\t\ticon: 'fa:brain',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Invite the AI agent to do some thinking',\n\t\tdefaults: {\n\t\t\tname: 'Think',\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.toolthink/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Think Tool Description',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: defaultToolDescription,\n\t\t\t\tplaceholder: '[Describe your thinking tool here, explaining how it will help the AI think]',\n\t\t\t\tdescription: \"The thinking tool's description\",\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst tool = await getTool(this, itemIndex);\n\n\t\treturn {\n\t\t\tresponse: logWrapper(tool, this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst input = this.getInputData();\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let i = 0; i < input.length; i++) {\n\t\t\tconst inputItem = input[i];\n\t\t\tconst tool = await getTool(this, i);\n\t\t\tconst result = await tool.invoke(inputItem.json);\n\t\t\tresponse.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: result,\n\t\t\t\t},\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: i,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn [response];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4B;AAC5B,0BASO;AAEP,wBAA2B;AAC3B,0BAA6C;AAE7C,eAAe,QACd,KACA,WACuB;AACvB,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AAExB,QAAM,OAAO,gBAAgB,IAAI,sBAAkB,wCAAmB,IAAI;AAC1E,QAAM,cAAc,IAAI,iBAAiB,eAAe,SAAS;AAEjE,SAAO,IAAI,yBAAY;AAAA,IACtB;AAAA,IACA;AAAA,IACA,MAAM,OAAO,YAAoB;AAChC,aAAO;AAAA,IACR;AAAA,EACD,CAAC;AACF;AAIA,MAAM,yBACL;AAEM,MAAM,UAA+B;AAAA,EAArC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,GAAG;AAAA,MAChB,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,OAAO;AAAA,UACZ,OAAO,CAAC,aAAa;AAAA,QACtB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,QAAQ,CAAC;AAAA,MACT,SAAS,CAAC,wCAAoB,MAAM;AAAA,MACpC,aAAa,CAAC,MAAM;AAAA,MACpB,YAAY;AAAA,YACX,kDAA6B,CAAC,wCAAoB,OAAO,CAAC;AAAA,QAC1D;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,UACb,aAAa;AAAA,UACb,aAAa;AAAA,YACZ,MAAM;AAAA,UACP;AAAA,UACA,UAAU;AAAA,QACX;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,OAAO,MAAM,QAAQ,MAAM,SAAS;AAE1C,WAAO;AAAA,MACN,cAAU,8BAAW,MAAM,IAAI;AAAA,IAChC;AAAA,EACD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,QAAQ,KAAK,aAAa;AAChC,UAAM,WAAiC,CAAC;AACxC,aAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACtC,YAAM,YAAY,MAAM,CAAC;AACzB,YAAM,OAAO,MAAM,QAAQ,MAAM,CAAC;AAClC,YAAM,SAAS,MAAM,KAAK,OAAO,UAAU,IAAI;AAC/C,eAAS,KAAK;AAAA,QACb,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,QAAQ;AAAA,EACjB;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolThink/ToolThink.node.ts"],"sourcesContent":["import { DynamicTool } from '@langchain/classic/tools';\nimport {\n\ttype IExecuteFunctions,\n\tNodeConnectionTypes,\n\tnodeNameToToolName,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\ttype INodeExecutionData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): Promise<DynamicTool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\n\tconst name = typeVersion === 1 ? 'thinking_tool' : nodeNameToToolName(node);\n\tconst description = ctx.getNodeParameter('description', itemIndex) as string;\n\n\treturn new DynamicTool({\n\t\tname,\n\t\tdescription,\n\t\tfunc: async (subject: string) => {\n\t\t\treturn subject;\n\t\t},\n\t});\n}\n\n// A thinking tool, see https://www.anthropic.com/engineering/claude-think-tool\n\nconst defaultToolDescription =\n\t'Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.';\n\nexport class ToolThink implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Think Tool',\n\t\tname: 'toolThink',\n\t\ticon: 'fa:brain',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Invite the AI agent to do some thinking',\n\t\tdefaults: {\n\t\t\tname: 'Think',\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.toolthink/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: [],\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Think Tool Description',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: defaultToolDescription,\n\t\t\t\tplaceholder: '[Describe your thinking tool here, explaining how it will help the AI think]',\n\t\t\t\tdescription: \"The thinking tool's description\",\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst tool = await getTool(this, itemIndex);\n\n\t\treturn {\n\t\t\tresponse: logWrapper(tool, this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst input = this.getInputData();\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let i = 0; i < input.length; i++) {\n\t\t\tconst inputItem = input[i];\n\t\t\tconst tool = await getTool(this, i);\n\t\t\tconst result = await tool.invoke(inputItem.json);\n\t\t\tresponse.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: result,\n\t\t\t\t},\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: i,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn [response];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4B;AAC5B,0BASO;AAEP,wBAA2B;AAC3B,0BAA6C;AAE7C,eAAe,QACd,KACA,WACuB;AACvB,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AAExB,QAAM,OAAO,gBAAgB,IAAI,sBAAkB,wCAAmB,IAAI;AAC1E,QAAM,cAAc,IAAI,iBAAiB,eAAe,SAAS;AAEjE,SAAO,IAAI,yBAAY;AAAA,IACtB;AAAA,IACA;AAAA,IACA,MAAM,OAAO,YAAoB;AAChC,aAAO;AAAA,IACR;AAAA,EACD,CAAC;AACF;AAIA,MAAM,yBACL;AAEM,MAAM,UAA+B;AAAA,EAArC;AACN,uBAAoC;AAAA,M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,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,QAAQ;AAAA,EACjB;AACD;","names":[]}
|
|
@@ -21,8 +21,8 @@ __export(ToolVectorStore_node_exports, {
|
|
|
21
21
|
ToolVectorStore: () => ToolVectorStore
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(ToolVectorStore_node_exports);
|
|
24
|
-
var import_chains = require("langchain/chains");
|
|
25
|
-
var import_tools = require("langchain/tools");
|
|
24
|
+
var import_chains = require("@langchain/classic/chains");
|
|
25
|
+
var import_tools = require("@langchain/classic/tools");
|
|
26
26
|
var import_n8n_workflow = require("n8n-workflow");
|
|
27
27
|
var import_logWrapper = require("../../../utils/logWrapper");
|
|
28
28
|
var import_sharedFields = require("../../../utils/sharedFields");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/tools/ToolVectorStore/ToolVectorStore.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { VectorDBQAChain } from 'langchain/chains';\nimport { VectorStoreQATool } from 'langchain/tools';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes, nodeNameToToolName } from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): Promise<VectorStoreQATool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\tconst name =\n\t\ttypeVersion <= 1\n\t\t\t? (ctx.getNodeParameter('name', itemIndex) as string)\n\t\t\t: nodeNameToToolName(node);\n\tconst toolDescription = ctx.getNodeParameter('description', itemIndex) as string;\n\tconst topK = ctx.getNodeParameter('topK', itemIndex, 4) as number;\n\tconst description = VectorStoreQATool.getDescription(name, toolDescription);\n\tconst vectorStore = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiVectorStore,\n\t\titemIndex,\n\t)) as VectorStore;\n\tconst llm = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\titemIndex,\n\t)) as BaseLanguageModel;\n\n\tconst vectorStoreTool = new VectorStoreQATool(name, description, {\n\t\tllm,\n\t\tvectorStore,\n\t});\n\n\tvectorStoreTool.chain = VectorDBQAChain.fromLLM(llm, vectorStore, {\n\t\tk: topK,\n\t});\n\n\treturn vectorStoreTool;\n}\n\nexport class ToolVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Question Answer Tool',\n\t\tname: 'toolVectorStore',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Answer questions with a vector store',\n\t\tdefaults: {\n\t\t\tname: 'Answer questions with a vector store',\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.toolvectorstore/',\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\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\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],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Data Name',\n\t\t\t\tname: 'name',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. users_info',\n\t\t\t\tvalidateType: 'string-alphanumeric',\n\t\t\t\tdescription:\n\t\t\t\t\t'Name of the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\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: 'Description of Data',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: \"[Describe your data here, e.g. a user's name, email, etc.]\",\n\t\t\t\tdescription:\n\t\t\t\t\t'Describe the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst vectorStoreTool = await getTool(this, itemIndex);\n\n\t\treturn {\n\t\t\tresponse: logWrapper(vectorStoreTool, this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst inputData = this.getInputData();\n\t\tconst result: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {\n\t\t\tconst tool = await getTool(this, itemIndex);\n\t\t\tconst outputData = await tool.invoke(inputData[itemIndex].json);\n\t\t\tresult.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: outputData,\n\t\t\t\t},\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: itemIndex,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn [result];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAgC;AAChC,mBAAkC;AASlC,0BAAwD;AAExD,wBAA2B;AAC3B,0BAA6C;AAE7C,eAAe,QACd,KACA,WAC6B;AAC7B,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,OACL,eAAe,IACX,IAAI,iBAAiB,QAAQ,SAAS,QACvC,wCAAmB,IAAI;AAC3B,QAAM,kBAAkB,IAAI,iBAAiB,eAAe,SAAS;AACrE,QAAM,OAAO,IAAI,iBAAiB,QAAQ,WAAW,CAAC;AACtD,QAAM,cAAc,+BAAkB,eAAe,MAAM,eAAe;AAC1E,QAAM,cAAe,MAAM,IAAI;AAAA,IAC9B,wCAAoB;AAAA,IACpB;AAAA,EACD;AACA,QAAM,MAAO,MAAM,IAAI;AAAA,IACtB,wCAAoB;AAAA,IACpB;AAAA,EACD;AAEA,QAAM,kBAAkB,IAAI,+BAAkB,MAAM,aAAa;AAAA,IAChE;AAAA,IACA;AAAA,EACD,CAAC;AAED,kBAAgB,QAAQ,8BAAgB,QAAQ,KAAK,aAAa;AAAA,IACjE,GAAG;AAAA,EACJ,CAAC;AAED,SAAO;AACR;AAEO,MAAM,gBAAqC;AAAA,EAA3C;AACN,uBAAoC;AAA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,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,QACd;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,kBAAkB,MAAM,QAAQ,MAAM,SAAS;AAErD,WAAO;AAAA,MACN,cAAU,8BAAW,iBAAiB,IAAI;AAAA,IAC3C;AAAA,EACD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,YAAY,KAAK,aAAa;AACpC,UAAM,SAA+B,CAAC;AACtC,aAAS,YAAY,GAAG,YAAY,UAAU,QAAQ,aAAa;AAClE,YAAM,OAAO,MAAM,QAAQ,MAAM,SAAS;AAC1C,YAAM,aAAa,MAAM,KAAK,OAAO,UAAU,SAAS,EAAE,IAAI;AAC9D,aAAO,KAAK;AAAA,QACX,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,MAAM;AAAA,EACf;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/tools/ToolVectorStore/ToolVectorStore.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { VectorDBQAChain } from '@langchain/classic/chains';\nimport { VectorStoreQATool } from '@langchain/classic/tools';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes, nodeNameToToolName } from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\titemIndex: number,\n): Promise<VectorStoreQATool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\tconst name =\n\t\ttypeVersion <= 1\n\t\t\t? (ctx.getNodeParameter('name', itemIndex) as string)\n\t\t\t: nodeNameToToolName(node);\n\tconst toolDescription = ctx.getNodeParameter('description', itemIndex) as string;\n\tconst topK = ctx.getNodeParameter('topK', itemIndex, 4) as number;\n\tconst description = VectorStoreQATool.getDescription(name, toolDescription);\n\tconst vectorStore = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiVectorStore,\n\t\titemIndex,\n\t)) as VectorStore;\n\tconst llm = (await ctx.getInputConnectionData(\n\t\tNodeConnectionTypes.AiLanguageModel,\n\t\titemIndex,\n\t)) as BaseLanguageModel;\n\n\tconst vectorStoreTool = new VectorStoreQATool(name, description, {\n\t\tllm,\n\t\tvectorStore,\n\t});\n\n\tvectorStoreTool.chain = VectorDBQAChain.fromLLM(llm, vectorStore, {\n\t\tk: topK,\n\t});\n\n\treturn vectorStoreTool;\n}\n\nexport class ToolVectorStore implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Vector Store Question Answer Tool',\n\t\tname: 'toolVectorStore',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Answer questions with a vector store',\n\t\tdefaults: {\n\t\t\tname: 'Answer questions with a vector store',\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.toolvectorstore/',\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\t{\n\t\t\t\tdisplayName: 'Vector Store',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiVectorStore,\n\t\t\t\trequired: true,\n\t\t\t},\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],\n\n\t\toutputs: [NodeConnectionTypes.AiTool],\n\t\toutputNames: ['Tool'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Data Name',\n\t\t\t\tname: 'name',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'e.g. users_info',\n\t\t\t\tvalidateType: 'string-alphanumeric',\n\t\t\t\tdescription:\n\t\t\t\t\t'Name of the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\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: 'Description of Data',\n\t\t\t\tname: 'description',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: \"[Describe your data here, e.g. a user's name, email, etc.]\",\n\t\t\t\tdescription:\n\t\t\t\t\t'Describe the data in vector store. This will be used to fill this tool description: Useful for when you need to answer questions about [name]. Whenever you need information about [data description], you should ALWAYS use this. Input should be a fully formed question.',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 3,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Limit',\n\t\t\t\tname: 'topK',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 4,\n\t\t\t\tdescription: 'The maximum number of results to return',\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst vectorStoreTool = await getTool(this, itemIndex);\n\n\t\treturn {\n\t\t\tresponse: logWrapper(vectorStoreTool, this),\n\t\t};\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst inputData = this.getInputData();\n\t\tconst result: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < inputData.length; itemIndex++) {\n\t\t\tconst tool = await getTool(this, itemIndex);\n\t\t\tconst outputData = await tool.invoke(inputData[itemIndex].json);\n\t\t\tresult.push({\n\t\t\t\tjson: {\n\t\t\t\t\tresponse: outputData,\n\t\t\t\t},\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: itemIndex,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\treturn [result];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAgC;AAChC,mBAAkC;AASlC,0BAAwD;AAExD,wBAA2B;AAC3B,0BAA6C;AAE7C,eAAe,QACd,KACA,WAC6B;AAC7B,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,OACL,eAAe,IACX,IAAI,iBAAiB,QAAQ,SAAS,QACvC,wCAAmB,IAAI;AAC3B,QAAM,kBAAkB,IAAI,iBAAiB,eAAe,SAAS;AACrE,QAAM,OAAO,IAAI,iBAAiB,QAAQ,WAAW,CAAC;AACtD,QAAM,cAAc,+BAAkB,eAAe,MAAM,eAAe;AAC1E,QAAM,cAAe,MAAM,IAAI;AAAA,IAC9B,wCAAoB;AAAA,IACpB;AAAA,EACD;AACA,QAAM,MAAO,MAAM,IAAI;AAAA,IACtB,wCAAoB;AAAA,IACpB;AAAA,EACD;AAEA,QAAM,kBAAkB,IAAI,+BAAkB,MAAM,aAAa;AAAA,IAChE;AAAA,IACA;AAAA,EACD,CAAC;AAED,kBAAgB,QAAQ,8BAAgB,QAAQ,KAAK,aAAa;AA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,UACb,aACC;AAAA,UACD,aAAa;AAAA,YACZ,MAAM;AAAA,UACP;AAAA,QACD;AAAA,QACA;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,QACd;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,kBAAkB,MAAM,QAAQ,MAAM,SAAS;AAErD,WAAO;AAAA,MACN,cAAU,8BAAW,iBAAiB,IAAI;AAAA,IAC3C;AAAA,EACD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,YAAY,KAAK,aAAa;AACpC,UAAM,SAA+B,CAAC;AACtC,aAAS,YAAY,GAAG,YAAY,UAAU,QAAQ,aAAa;AAClE,YAAM,OAAO,MAAM,QAAQ,MAAM,SAAS;AAC1C,YAAM,aAAa,MAAM,KAAK,OAAO,UAAU,SAAS,EAAE,IAAI;AAC9D,aAAO,KAAK;AAAA,QACX,MAAM;AAAA,UACL,UAAU;AAAA,QACX;AAAA,QACA,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD,CAAC;AAAA,IACF;AAEA,WAAO,CAAC,MAAM;AAAA,EACf;AACD;","names":[]}
|
|
@@ -37,7 +37,7 @@ var import_isObject = __toESM(require("lodash/isObject"));
|
|
|
37
37
|
var manual = __toESM(require("n8n-nodes-base/dist/nodes/Set/v2/manual.mode"));
|
|
38
38
|
var import_GenericFunctions = require("n8n-nodes-base/dist/utils/workflowInputsResourceMapping/GenericFunctions");
|
|
39
39
|
var import_n8n_workflow = require("n8n-workflow");
|
|
40
|
-
var
|
|
40
|
+
var import_fromAIToolFactory = require("../../../../../utils/fromAIToolFactory");
|
|
41
41
|
function isNodeExecutionData(data) {
|
|
42
42
|
return (0, import_isArray.default)(data) && Boolean(data.length) && (0, import_isObject.default)(data[0]) && "json" in data[0];
|
|
43
43
|
}
|
|
@@ -146,7 +146,7 @@ class WorkflowToolService {
|
|
|
146
146
|
}
|
|
147
147
|
return `There was an error: ${lastError?.message ?? "Unknown error"}`;
|
|
148
148
|
};
|
|
149
|
-
return this.useSchema ?
|
|
149
|
+
return this.useSchema ? this.createStructuredTool(name, description, toolHandler) : new import_tools.DynamicTool({ name, description, func: toolHandler });
|
|
150
150
|
}
|
|
151
151
|
handleToolResponse(response) {
|
|
152
152
|
if (typeof response === "number") {
|
|
@@ -288,30 +288,14 @@ class WorkflowToolService {
|
|
|
288
288
|
/**
|
|
289
289
|
* Create structured tool by parsing the sub-workflow input schema
|
|
290
290
|
*/
|
|
291
|
-
|
|
292
|
-
const collectedArguments =
|
|
291
|
+
createStructuredTool(name, description, func) {
|
|
292
|
+
const collectedArguments = (0, import_fromAIToolFactory.extractFromAIParameters)(this.baseContext.getNode().parameters);
|
|
293
293
|
if (collectedArguments.length === 0) {
|
|
294
294
|
return new import_tools.DynamicTool({ name, description, func });
|
|
295
295
|
}
|
|
296
|
-
const schema =
|
|
296
|
+
const schema = (0, import_fromAIToolFactory.createZodSchemaFromArgs)(collectedArguments);
|
|
297
297
|
return new import_tools.DynamicStructuredTool({ schema, name, description, func });
|
|
298
298
|
}
|
|
299
|
-
async extractFromAIParameters() {
|
|
300
|
-
const collectedArguments = [];
|
|
301
|
-
(0, import_n8n_workflow.traverseNodeParameters)(this.baseContext.getNode().parameters, collectedArguments);
|
|
302
|
-
const uniqueArgsMap = /* @__PURE__ */ new Map();
|
|
303
|
-
for (const arg of collectedArguments) {
|
|
304
|
-
uniqueArgsMap.set(arg.key, arg);
|
|
305
|
-
}
|
|
306
|
-
return Array.from(uniqueArgsMap.values());
|
|
307
|
-
}
|
|
308
|
-
createZodSchema(args) {
|
|
309
|
-
const schemaObj = args.reduce((acc, placeholder) => {
|
|
310
|
-
acc[placeholder.key] = (0, import_n8n_workflow.generateZodSchema)(placeholder);
|
|
311
|
-
return acc;
|
|
312
|
-
}, {});
|
|
313
|
-
return import_zod.z.object(schemaObj).required();
|
|
314
|
-
}
|
|
315
299
|
}
|
|
316
300
|
// Annotate the CommonJS export names for ESM import in node:
|
|
317
301
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.ts"],"sourcesContent":["import type { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';\nimport { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';\nimport isArray from 'lodash/isArray';\nimport isObject from 'lodash/isObject';\nimport type { SetField, SetNodeOptions } from 'n8n-nodes-base/dist/nodes/Set/v2/helpers/interfaces';\nimport * as manual from 'n8n-nodes-base/dist/nodes/Set/v2/manual.mode';\nimport { getCurrentWorkflowInputData } from 'n8n-nodes-base/dist/utils/workflowInputsResourceMapping/GenericFunctions';\nimport type {\n\tExecuteWorkflowData,\n\tExecutionError,\n\tFromAIArgument,\n\tIDataObject,\n\tIExecuteFunctions,\n\tIExecuteWorkflowInfo,\n\tINodeExecutionData,\n\tINodeParameterResourceLocator,\n\tISupplyDataFunctions,\n\tITaskMetadata,\n\tIWorkflowBase,\n\tIWorkflowDataProxyData,\n\tResourceMapperValue,\n} from 'n8n-workflow';\nimport {\n\tgenerateZodSchema,\n\tjsonParse,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n\tparseErrorMetadata,\n\tsleepWithAbort,\n\ttraverseNodeParameters,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nfunction isNodeExecutionData(data: unknown): data is INodeExecutionData[] {\n\treturn isArray(data) && Boolean(data.length) && isObject(data[0]) && 'json' in data[0];\n}\n\n/**\n\tMain class for creating the Workflow tool\n\tProcesses the node parameters and creates AI Agent tool capable of executing n8n workflows\n*/\nexport class WorkflowToolService {\n\t// Determines if we should use input schema when creating the tool\n\tprivate useSchema: boolean;\n\n\t// Sub-workflow id, pulled from referenced sub-workflow\n\tprivate subWorkflowId: string | undefined;\n\n\t// Sub-workflow execution id, will be set after the sub-workflow is executed\n\tprivate subExecutionId: string | undefined;\n\n\tprivate returnAllItems: boolean = false;\n\n\tconstructor(\n\t\tprivate baseContext: ISupplyDataFunctions | IExecuteFunctions,\n\t\toptions?: { returnAllItems: boolean },\n\t) {\n\t\tconst subWorkflowInputs = this.baseContext.getNode().parameters\n\t\t\t.workflowInputs as ResourceMapperValue;\n\t\tthis.useSchema = (subWorkflowInputs?.schema ?? []).length > 0;\n\t\tthis.returnAllItems = options?.returnAllItems ?? false;\n\t}\n\n\t// Creates the tool based on the provided parameters\n\tasync createTool({\n\t\tctx,\n\t\tname,\n\t\tdescription,\n\t\titemIndex,\n\t\tmanualLogging = true,\n\t}: {\n\t\tctx: ISupplyDataFunctions | IExecuteFunctions;\n\t\tname: string;\n\t\tdescription: string;\n\t\titemIndex: number;\n\t\tmanualLogging?: boolean;\n\t}): Promise<DynamicTool | DynamicStructuredTool> {\n\t\t// Handler for the tool execution, will be called when the tool is executed\n\t\t// This function will execute the sub-workflow and return the response\n\t\t// We get the runIndex from the context to handle multiple executions\n\t\t// of the same tool when the tool is used in a loop or in a parallel execution.\n\t\tconst node = ctx.getNode();\n\n\t\tlet runIndex: number = 'getNextRunIndex' in ctx ? ctx.getNextRunIndex() : 0;\n\t\tconst toolHandler = async (\n\t\t\tquery: string | IDataObject,\n\t\t\trunManager?: CallbackManagerForToolRun,\n\t\t): Promise<IDataObject | IDataObject[] | string> => {\n\t\t\tlet maxTries = 1;\n\t\t\tif (node.retryOnFail === true) {\n\t\t\t\tmaxTries = Math.min(5, Math.max(2, node.maxTries ?? 3));\n\t\t\t}\n\n\t\t\tlet waitBetweenTries = 0;\n\t\t\tif (node.retryOnFail === true) {\n\t\t\t\twaitBetweenTries = Math.min(5000, Math.max(0, node.waitBetweenTries ?? 1000));\n\t\t\t}\n\n\t\t\tlet lastError: ExecutionError | undefined;\n\n\t\t\tfor (let tryIndex = 0; tryIndex < maxTries; tryIndex++) {\n\t\t\t\tconst localRunIndex = runIndex++;\n\n\t\t\t\tlet context = this.baseContext;\n\t\t\t\t// We need to clone the context here to handle runIndex correctly\n\t\t\t\t// Otherwise the runIndex will be shared between different executions\n\t\t\t\t// Causing incorrect data to be passed to the sub-workflow and via $fromAI\n\t\t\t\tif ('cloneWith' in this.baseContext) {\n\t\t\t\t\tcontext = this.baseContext.cloneWith({\n\t\t\t\t\t\trunIndex: localRunIndex,\n\t\t\t\t\t\tinputData: [[{ json: { query } }]],\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Get abort signal from context for cancellation support\n\t\t\t\tconst abortSignal = context.getExecutionCancelSignal?.();\n\n\t\t\t\t// Check if execution was cancelled before retry\n\t\t\t\tif (abortSignal?.aborted) {\n\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t}\n\n\t\t\t\tif (tryIndex !== 0) {\n\t\t\t\t\t// Reset error from previous attempt\n\t\t\t\t\tlastError = undefined;\n\t\t\t\t\tif (waitBetweenTries !== 0) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait sleepWithAbort(waitBetweenTries, abortSignal);\n\t\t\t\t\t\t} catch (abortError) {\n\t\t\t\t\t\t\treturn 'There was an error: \"Execution was cancelled\"';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await this.runFunction(context, query, itemIndex, runManager);\n\n\t\t\t\t\tconst processedResponse = this.handleToolResponse(response);\n\n\t\t\t\t\tlet responseData: INodeExecutionData[];\n\t\t\t\t\tif (isNodeExecutionData(response)) {\n\t\t\t\t\t\tresponseData = response;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst reParsedData = jsonParse<IDataObject>(processedResponse, {\n\t\t\t\t\t\t\tfallbackValue: { response: processedResponse },\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tresponseData = [{ json: reParsedData }];\n\t\t\t\t\t}\n\n\t\t\t\t\t// Once the sub-workflow is executed, add the output data to the context\n\t\t\t\t\t// This will be used to link the sub-workflow execution in the parent workflow\n\t\t\t\t\tlet metadata: ITaskMetadata | undefined;\n\t\t\t\t\tif (this.subExecutionId && this.subWorkflowId) {\n\t\t\t\t\t\tmetadata = {\n\t\t\t\t\t\t\tsubExecution: {\n\t\t\t\t\t\t\t\texecutionId: this.subExecutionId,\n\t\t\t\t\t\t\t\tworkflowId: this.subWorkflowId,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\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? await this.createStructuredTool(name, description, toolHandler)\n\t\t\t: new DynamicTool({ name, description, func: toolHandler });\n\t}\n\n\tprivate handleToolResponse(response: unknown): string {\n\t\tif (typeof response === 'number') {\n\t\t\treturn response.toString();\n\t\t}\n\n\t\tif (isNodeExecutionData(response)) {\n\t\t\treturn JSON.stringify(\n\t\t\t\tresponse.map((item) => item.json),\n\t\t\t\tnull,\n\t\t\t\t2,\n\t\t\t);\n\t\t}\n\n\t\tif (isObject(response)) {\n\t\t\treturn JSON.stringify(response, null, 2);\n\t\t}\n\n\t\tif (typeof response !== 'string') {\n\t\t\tthrow new NodeOperationError(this.baseContext.getNode(), 'Wrong output type returned', {\n\t\t\t\tdescription: `The response property should be a string, but it is an ${typeof response}`,\n\t\t\t});\n\t\t}\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Executes specified sub-workflow with provided inputs\n\t */\n\tprivate async executeSubWorkflow(\n\t\tcontext: ISupplyDataFunctions | IExecuteFunctions,\n\t\tworkflowInfo: IExecuteWorkflowInfo,\n\t\titems: INodeExecutionData[],\n\t\tworkflowProxy: IWorkflowDataProxyData,\n\t\trunManager?: CallbackManagerForToolRun,\n\t): Promise<{ response: 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 async createStructuredTool(\n\t\tname: string,\n\t\tdescription: string,\n\t\tfunc: (\n\t\t\tquery: string | IDataObject,\n\t\t\trunManager?: CallbackManagerForToolRun,\n\t\t) => Promise<string | IDataObject | IDataObject[]>,\n\t): Promise<DynamicStructuredTool | DynamicTool> {\n\t\tconst collectedArguments = await this.extractFromAIParameters();\n\n\t\t// If there are no `fromAI` arguments, fallback to creating a simple tool\n\t\tif (collectedArguments.length === 0) {\n\t\t\treturn new DynamicTool({ name, description, func });\n\t\t}\n\n\t\t// Otherwise, prepare Zod schema and create a structured tool\n\t\tconst schema = this.createZodSchema(collectedArguments);\n\t\treturn new DynamicStructuredTool({ schema, name, description, func });\n\t}\n\n\tprivate async extractFromAIParameters(): Promise<FromAIArgument[]> {\n\t\tconst collectedArguments: FromAIArgument[] = [];\n\t\ttraverseNodeParameters(this.baseContext.getNode().parameters, collectedArguments);\n\n\t\tconst uniqueArgsMap = new Map<string, FromAIArgument>();\n\t\tfor (const arg of collectedArguments) {\n\t\t\tuniqueArgsMap.set(arg.key, arg);\n\t\t}\n\n\t\treturn Array.from(uniqueArgsMap.values());\n\t}\n\n\tprivate createZodSchema(args: FromAIArgument[]): z.ZodObject<any> {\n\t\tconst schemaObj = args.reduce((acc: Record<string, z.ZodTypeAny>, placeholder) => {\n\t\t\tacc[placeholder.key] = generateZodSchema(placeholder);\n\t\t\treturn acc;\n\t\t}, {});\n\n\t\treturn z.object(schemaObj).required();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAmD;AACnD,qBAAoB;AACpB,sBAAqB;AAErB,aAAwB;AACxB,8BAA4C;AAgB5C,0BAQO;AACP,iBAAkB;AAElB,SAAS,oBAAoB,MAA6C;AACzE,aAAO,eAAAA,SAAQ,IAAI,KAAK,QAAQ,KAAK,MAAM,SAAK,gBAAAC,SAAS,KAAK,CAAC,CAAC,KAAK,UAAU,KAAK,CAAC;AACtF;AAMO,MAAM,oBAAoB;AAAA,EAYhC,YACS,aACR,SACC;AAFO;AAHT,SAAQ,iBAA0B;AAMjC,UAAM,oBAAoB,KAAK,YAAY,QAAQ,EAAE,WACnD;AACF,SAAK,aAAa,mBAAmB,UAAU,CAAC,GAAG,SAAS;AAC5D,SAAK,iBAAiB,SAAS,kBAAkB;AAAA,EAClD;AAAA;AAAA,EAGA,MAAM,WAAW;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,EACjB,GAMiD;AAKhD,UAAM,OAAO,IAAI,QAAQ;AAEzB,QAAI,WAAmB,qBAAqB,MAAM,IAAI,gBAAgB,IAAI;AAC1E,UAAM,cAAc,OACnB,OACA,eACmD;AACnD,UAAI,WAAW;AACf,UAAI,KAAK,gBAAgB,MAAM;AAC9B,mBAAW,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,YAAY,CAAC,CAAC;AAAA,MACvD;AAEA,UAAI,mBAAmB;AACvB,UAAI,KAAK,gBAAgB,MAAM;AAC9B,2BAAmB,KAAK,IAAI,KAAM,KAAK,IAAI,GAAG,KAAK,oBAAoB,GAAI,CAAC;AAAA,MAC7E;AAEA,UAAI;AAEJ,eAAS,WAAW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AA;AAAA;AAAA;AAAA,EAKA,MAAc,qBACb,MACA,aACA,MAI+C;AAC/C,UAAM,qBAAqB,MAAM,KAAK,wBAAwB;AAG9D,QAAI,mBAAmB,WAAW,GAAG;AACpC,aAAO,IAAI,yBAAY,EAAE,MAAM,aAAa,KAAK,CAAC;AAAA,IACnD;AAGA,UAAM,SAAS,KAAK,gBAAgB,kBAAkB;AACtD,WAAO,IAAI,mCAAsB,EAAE,QAAQ,MAAM,aAAa,KAAK,CAAC;AAAA,EACrE;AAAA,EAEA,MAAc,0BAAqD;AAClE,UAAM,qBAAuC,CAAC;AAC9C,oDAAuB,KAAK,YAAY,QAAQ,EAAE,YAAY,kBAAkB;AAEhF,UAAM,gBAAgB,oBAAI,IAA4B;AACtD,eAAW,OAAO,oBAAoB;AACrC,oBAAc,IAAI,IAAI,KAAK,GAAG;AAAA,IAC/B;AAEA,WAAO,MAAM,KAAK,cAAc,OAAO,CAAC;AAAA,EACzC;AAAA,EAEQ,gBAAgB,MAA0C;AACjE,UAAM,YAAY,KAAK,OAAO,CAAC,KAAmC,gBAAgB;AACjF,UAAI,YAAY,GAAG,QAAI,uCAAkB,WAAW;AACpD,aAAO;AAAA,IACR,GAAG,CAAC,CAAC;AAEL,WAAO,aAAE,OAAO,SAAS,EAAE,SAAS;AAAA,EACrC;AACD;","names":["isArray","isObject"]}
|
|
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,aAAO,eAAAA,SAAQ,IAAI,KAAK,QAAQ,KAAK,MAAM,SAAK,gBAAAC,SAAS,KAAK,CAAC,CAAC,KAAK,UAAU,KAAK,CAAC;AACtF;AAMO,MAAM,oBAAoB;AAAA,EAYhC,YACS,aACR,SACC;AAFO;AAHT,SAAQ,iBAA0B;AAMjC,UAAM,oBAAoB,KAAK,YAAY,QAAQ,EAAE,WACnD;AACF,SAAK,aAAa,mBAAmB,UAAU,CAAC,GAAG,SAAS;AAC5D,SAAK,iBAAiB,SAAS,kBAAkB;AAAA,EAClD;AAAA;AAAA,EAGA,MAAM,WAAW;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,EACjB,GAMiD;AAKhD,UAAM,OAAO,IAAI,QAAQ;AAEzB,QAAI,WAAmB,qBAAqB,MAAM,IAAI,gBAAgB,IAAI;AAC1E,UAAM,cAAc,OACnB,OACA,eACmD;AACnD,UAAI,WAAW;AACf,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AAW;AACnB,YAAM,wBAAwB,oDAA4B,KAAK,OAAO;AACtE,iBAAW,sBAAsB,SAAS,EAAE;AAAA,IAC7C;AAEA,UAAM,UAAU,MAAM,OAAO,QAAQ;AAAA,MACpC;AAAA,MACA,EAAE,MAAM,SAAS;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAQ,QAAQ;AAAA,IACjB;AAEA,WAAO,CAAC,OAAO;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKQ,qBACP,MACA,aACA,MAIsC;AACtC,UAAM,yBAAqB,kDAAwB,KAAK,YAAY,QAAQ,EAAE,UAAU;AAGxF,QAAI,mBAAmB,WAAW,GAAG;AACpC,aAAO,IAAI,yBAAY,EAAE,MAAM,aAAa,KAAK,CAAC;AAAA,IACnD;AAGA,UAAM,aAAS,kDAAwB,kBAAkB;AACzD,WAAO,IAAI,mCAAsB,EAAE,QAAQ,MAAM,aAAa,KAAK,CAAC;AAAA,EACrE;AACD;","names":["isArray","isObject"]}
|
|
@@ -140,7 +140,7 @@ class Chat {
|
|
|
140
140
|
resources: {
|
|
141
141
|
primaryDocumentation: [
|
|
142
142
|
{
|
|
143
|
-
url: "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.
|
|
143
|
+
url: "https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.respondtochat/"
|
|
144
144
|
}
|
|
145
145
|
]
|
|
146
146
|
}
|
|
@@ -262,7 +262,7 @@ class Chat {
|
|
|
262
262
|
if (options.memoryConnection) {
|
|
263
263
|
const memory = await this.getInputConnectionData(import_n8n_workflow.NodeConnectionTypes.AiMemory, 0);
|
|
264
264
|
if (memory) {
|
|
265
|
-
await memory.chatHistory.
|
|
265
|
+
await memory.chatHistory.addAIMessage(message);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
const waitTill = (0, import_util.configureWaitTillDate)(this);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/trigger/ChatTrigger/Chat.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseChatMemory } from 'langchain/memory';\nimport {\n\tCHAT_TRIGGER_NODE_TYPE,\n\tCHAT_WAIT_USER_REPLY,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n} from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeTypeDescription,\n\tINodeType,\n\tINodeProperties,\n\tNodeTypeAndVersion,\n\tINode,\n} from 'n8n-workflow';\n\nimport { configureInputs, configureWaitTillDate } from './util';\n\nconst limitWaitTimeProperties: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Limit Type',\n\t\tname: 'limitType',\n\t\ttype: 'options',\n\t\tdefault: 'afterTimeInterval',\n\t\tdescription:\n\t\t\t'Sets the condition for the execution to resume. Can be a specified date or after some time.',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'After Time Interval',\n\t\t\t\tdescription: 'Waits for a certain amount of time',\n\t\t\t\tvalue: 'afterTimeInterval',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'At Specified Time',\n\t\t\t\tdescription: 'Waits until the set date and time to continue',\n\t\t\t\tvalue: 'atSpecifiedTime',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tdisplayName: 'Amount',\n\t\tname: 'resumeAmount',\n\t\ttype: 'number',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\ttypeOptions: {\n\t\t\tminValue: 0,\n\t\t\tnumberPrecision: 2,\n\t\t},\n\t\tdefault: 1,\n\t\tdescription: 'The time to wait',\n\t},\n\t{\n\t\tdisplayName: 'Unit',\n\t\tname: 'resumeUnit',\n\t\ttype: 'options',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'Minutes',\n\t\t\t\tvalue: 'minutes',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Hours',\n\t\t\t\tvalue: 'hours',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Days',\n\t\t\t\tvalue: 'days',\n\t\t\t},\n\t\t],\n\t\tdefault: 'hours',\n\t\tdescription: 'Unit of the interval value',\n\t},\n\t{\n\t\tdisplayName: 'Max Date and Time',\n\t\tname: 'maxDateAndTime',\n\t\ttype: 'dateTime',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['atSpecifiedTime'],\n\t\t\t},\n\t\t},\n\t\tdefault: '',\n\t\tdescription: 'Continue execution after the specified date and time',\n\t},\n];\n\nconst limitWaitTimeOption: INodeProperties = {\n\tdisplayName: 'Limit Wait Time',\n\tname: 'limitWaitTime',\n\ttype: 'fixedCollection',\n\tdescription:\n\t\t'Whether to limit the time this node should wait for a user response before execution resumes',\n\tdefault: { values: { limitType: 'afterTimeInterval', resumeAmount: 45, resumeUnit: 'minutes' } },\n\toptions: [\n\t\t{\n\t\t\tdisplayName: 'Values',\n\t\t\tname: 'values',\n\t\t\tvalues: limitWaitTimeProperties,\n\t\t},\n\t],\n\tdisplayOptions: {\n\t\tshow: {\n\t\t\t[`/${CHAT_WAIT_USER_REPLY}`]: [true],\n\t\t},\n\t},\n};\n\nexport class Chat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tusableAsTool: true,\n\t\tdisplayName: 'Respond to Chat',\n\t\tname: 'chat',\n\t\ticon: 'fa:comments',\n\t\ticonColor: 'black',\n\t\tgroup: ['input'],\n\t\tversion: 1,\n\t\tdescription: 'Send a message to a chat',\n\t\tdefaults: {\n\t\t\tname: 'Respond to Chat',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['Core Nodes', 'HITL'],\n\t\t\tsubcategories: {\n\t\t\t\tHITL: ['Human in the Loop'],\n\t\t\t},\n\t\t\talias: ['human', 'wait', 'hitl'],\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/core-nodes/n8n-nodes-langchain.chat/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ (${configureInputs})($parameter) }}`,\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t\"Verify you're using a chat trigger with the 'Response Mode' option set to 'Using Response Nodes'\",\n\t\t\t\tname: 'generalNotice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Message',\n\t\t\t\tname: 'message',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 6,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Wait for User Reply',\n\t\t\t\tname: CHAT_WAIT_USER_REPLY,\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: true,\n\t\t\t\tnoDataExpression: true,\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\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@tool': [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Add Memory Input Connection',\n\t\t\t\t\t\tname: 'memoryConnection',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tlimitWaitTimeOption,\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\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [limitWaitTimeOption],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@tool': [true],\n\t\t\t\t\t\t[`/${CHAT_WAIT_USER_REPLY}`]: [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n\n\tasync onMessage(\n\t\tcontext: IExecuteFunctions,\n\t\tdata: INodeExecutionData,\n\t): Promise<INodeExecutionData[][]> {\n\t\tconst options = context.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tconst waitForReply = context.getNodeParameter(CHAT_WAIT_USER_REPLY, 0, true) as boolean;\n\n\t\tif (!waitForReply) {\n\t\t\tconst inputData = context.getInputData();\n\t\t\treturn [inputData];\n\t\t}\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await context.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tconst message = data.json?.chatInput;\n\n\t\t\tif (memory && message) {\n\t\t\t\tawait memory.chatHistory.addUserMessage(message as string);\n\t\t\t}\n\t\t}\n\n\t\treturn [[data]];\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst connectedNodes = this.getParentNodes(this.getNode().name, {\n\t\t\tincludeNodeParameters: true,\n\t\t});\n\n\t\tlet chatTrigger: INode | NodeTypeAndVersion | undefined | null = connectedNodes.find(\n\t\t\t(node) => node.type === CHAT_TRIGGER_NODE_TYPE && !node.disabled,\n\t\t);\n\n\t\tif (!chatTrigger) {\n\t\t\ttry {\n\t\t\t\t// try to get chat trigger from workflow if node working as a tool\n\t\t\t\tchatTrigger = this.getChatTrigger();\n\t\t\t} catch (error) {}\n\t\t}\n\n\t\tif (!chatTrigger) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Workflow must be started from a chat trigger node',\n\t\t\t);\n\t\t}\n\n\t\tconst parameters = chatTrigger.parameters as {\n\t\t\tmode?: 'hostedChat' | 'webhook';\n\t\t\toptions: { responseMode: 'lastNode' | 'responseNodes' | 'streaming' | 'responseNode' };\n\t\t};\n\n\t\tif (parameters.mode === 'webhook') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Embeded chat\" is not supported, change the \"Mode\" in the chat trigger node to the \"Hosted Chat\"',\n\t\t\t);\n\t\t}\n\n\t\tif (parameters.options.responseMode !== 'responseNodes') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Response Mode\" in the chat trigger node must be set to \"Respond Nodes\"',\n\t\t\t);\n\t\t}\n\n\t\tconst message = (this.getNodeParameter('message', 0) as string) ?? '';\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tif (memory) {\n\t\t\t\tawait memory.chatHistory.addAIChatMessage(message);\n\t\t\t}\n\t\t}\n\n\t\tconst waitTill = configureWaitTillDate(this);\n\n\t\tawait this.putExecutionToWait(waitTill);\n\t\treturn [[{ json: {}, sendMessage: message }]];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAKO;AAWP,kBAAuD;AAEvD,MAAM,0BAA6C;AAAA,EAClD;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aACC;AAAA,IACD,SAAS;AAAA,MACR;AAAA,QACC,MAAM;AAA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aAAa;AACjB,UAAI;AAEH,sBAAc,KAAK,eAAe;AAAA,MACnC,SAAS,OAAO;AAAA,MAAC;AAAA,IAClB;AAEA,QAAI,CAAC,aAAa;AACjB,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AAEA,UAAM,aAAa,YAAY;AAK/B,QAAI,WAAW,SAAS,WAAW;AAClC,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AAEA,QAAI,WAAW,QAAQ,iBAAiB,iBAAiB;AACxD,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AAEA,UAAM,UAAW,KAAK,iBAAiB,WAAW,CAAC,KAAgB;AACnE,UAAM,UAAU,KAAK,iBAAiB,WAAW,GAAG,CAAC,CAAC;AAItD,QAAI,QAAQ,kBAAkB;AAC7B,YAAM,SAAU,MAAM,KAAK,uBAAuB,wCAAoB,UAAU,CAAC;AAIjF,UAAI,QAAQ;AACX,cAAM,OAAO,YAAY,iBAAiB,OAAO;AAAA,MAClD;AAAA,IACD;AAEA,UAAM,eAAW,mCAAsB,IAAI;AAE3C,UAAM,KAAK,mBAAmB,QAAQ;AACtC,WAAO,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,aAAa,QAAQ,CAAC,CAAC;AAAA,EAC7C;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/trigger/ChatTrigger/Chat.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseChatMemory } from '@langchain/classic/memory';\nimport {\n\tCHAT_TRIGGER_NODE_TYPE,\n\tCHAT_WAIT_USER_REPLY,\n\tNodeConnectionTypes,\n\tNodeOperationError,\n} from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeTypeDescription,\n\tINodeType,\n\tINodeProperties,\n\tNodeTypeAndVersion,\n\tINode,\n} from 'n8n-workflow';\n\nimport { configureInputs, configureWaitTillDate } from './util';\n\nconst limitWaitTimeProperties: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Limit Type',\n\t\tname: 'limitType',\n\t\ttype: 'options',\n\t\tdefault: 'afterTimeInterval',\n\t\tdescription:\n\t\t\t'Sets the condition for the execution to resume. Can be a specified date or after some time.',\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'After Time Interval',\n\t\t\t\tdescription: 'Waits for a certain amount of time',\n\t\t\t\tvalue: 'afterTimeInterval',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'At Specified Time',\n\t\t\t\tdescription: 'Waits until the set date and time to continue',\n\t\t\t\tvalue: 'atSpecifiedTime',\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tdisplayName: 'Amount',\n\t\tname: 'resumeAmount',\n\t\ttype: 'number',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\ttypeOptions: {\n\t\t\tminValue: 0,\n\t\t\tnumberPrecision: 2,\n\t\t},\n\t\tdefault: 1,\n\t\tdescription: 'The time to wait',\n\t},\n\t{\n\t\tdisplayName: 'Unit',\n\t\tname: 'resumeUnit',\n\t\ttype: 'options',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['afterTimeInterval'],\n\t\t\t},\n\t\t},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tname: 'Minutes',\n\t\t\t\tvalue: 'minutes',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Hours',\n\t\t\t\tvalue: 'hours',\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'Days',\n\t\t\t\tvalue: 'days',\n\t\t\t},\n\t\t],\n\t\tdefault: 'hours',\n\t\tdescription: 'Unit of the interval value',\n\t},\n\t{\n\t\tdisplayName: 'Max Date and Time',\n\t\tname: 'maxDateAndTime',\n\t\ttype: 'dateTime',\n\t\tdisplayOptions: {\n\t\t\tshow: {\n\t\t\t\tlimitType: ['atSpecifiedTime'],\n\t\t\t},\n\t\t},\n\t\tdefault: '',\n\t\tdescription: 'Continue execution after the specified date and time',\n\t},\n];\n\nconst limitWaitTimeOption: INodeProperties = {\n\tdisplayName: 'Limit Wait Time',\n\tname: 'limitWaitTime',\n\ttype: 'fixedCollection',\n\tdescription:\n\t\t'Whether to limit the time this node should wait for a user response before execution resumes',\n\tdefault: { values: { limitType: 'afterTimeInterval', resumeAmount: 45, resumeUnit: 'minutes' } },\n\toptions: [\n\t\t{\n\t\t\tdisplayName: 'Values',\n\t\t\tname: 'values',\n\t\t\tvalues: limitWaitTimeProperties,\n\t\t},\n\t],\n\tdisplayOptions: {\n\t\tshow: {\n\t\t\t[`/${CHAT_WAIT_USER_REPLY}`]: [true],\n\t\t},\n\t},\n};\n\nexport class Chat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tusableAsTool: true,\n\t\tdisplayName: 'Respond to Chat',\n\t\tname: 'chat',\n\t\ticon: 'fa:comments',\n\t\ticonColor: 'black',\n\t\tgroup: ['input'],\n\t\tversion: 1,\n\t\tdescription: 'Send a message to a chat',\n\t\tdefaults: {\n\t\t\tname: 'Respond to Chat',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['Core Nodes', 'HITL'],\n\t\t\tsubcategories: {\n\t\t\t\tHITL: ['Human in the Loop'],\n\t\t\t},\n\t\t\talias: ['human', 'wait', 'hitl'],\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/core-nodes/n8n-nodes-langchain.respondtochat/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ (${configureInputs})($parameter) }}`,\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t\"Verify you're using a chat trigger with the 'Response Mode' option set to 'Using Response Nodes'\",\n\t\t\t\tname: 'generalNotice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Message',\n\t\t\t\tname: 'message',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\trequired: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 6,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Wait for User Reply',\n\t\t\t\tname: CHAT_WAIT_USER_REPLY,\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: true,\n\t\t\t\tnoDataExpression: true,\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\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\thide: {\n\t\t\t\t\t\t'@tool': [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Add Memory Input Connection',\n\t\t\t\t\t\tname: 'memoryConnection',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tlimitWaitTimeOption,\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\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [limitWaitTimeOption],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@tool': [true],\n\t\t\t\t\t\t[`/${CHAT_WAIT_USER_REPLY}`]: [true],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n\n\tasync onMessage(\n\t\tcontext: IExecuteFunctions,\n\t\tdata: INodeExecutionData,\n\t): Promise<INodeExecutionData[][]> {\n\t\tconst options = context.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tconst waitForReply = context.getNodeParameter(CHAT_WAIT_USER_REPLY, 0, true) as boolean;\n\n\t\tif (!waitForReply) {\n\t\t\tconst inputData = context.getInputData();\n\t\t\treturn [inputData];\n\t\t}\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await context.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tconst message = data.json?.chatInput;\n\n\t\t\tif (memory && message) {\n\t\t\t\tawait memory.chatHistory.addUserMessage(message as string);\n\t\t\t}\n\t\t}\n\n\t\treturn [[data]];\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst connectedNodes = this.getParentNodes(this.getNode().name, {\n\t\t\tincludeNodeParameters: true,\n\t\t});\n\n\t\tlet chatTrigger: INode | NodeTypeAndVersion | undefined | null = connectedNodes.find(\n\t\t\t(node) => node.type === CHAT_TRIGGER_NODE_TYPE && !node.disabled,\n\t\t);\n\n\t\tif (!chatTrigger) {\n\t\t\ttry {\n\t\t\t\t// try to get chat trigger from workflow if node working as a tool\n\t\t\t\tchatTrigger = this.getChatTrigger();\n\t\t\t} catch (error) {}\n\t\t}\n\n\t\tif (!chatTrigger) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Workflow must be started from a chat trigger node',\n\t\t\t);\n\t\t}\n\n\t\tconst parameters = chatTrigger.parameters as {\n\t\t\tmode?: 'hostedChat' | 'webhook';\n\t\t\toptions: { responseMode: 'lastNode' | 'responseNodes' | 'streaming' | 'responseNode' };\n\t\t};\n\n\t\tif (parameters.mode === 'webhook') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Embeded chat\" is not supported, change the \"Mode\" in the chat trigger node to the \"Hosted Chat\"',\n\t\t\t);\n\t\t}\n\n\t\tif (parameters.options.responseMode !== 'responseNodes') {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'\"Response Mode\" in the chat trigger node must be set to \"Respond Nodes\"',\n\t\t\t);\n\t\t}\n\n\t\tconst message = (this.getNodeParameter('message', 0) as string) ?? '';\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tmemoryConnection?: boolean;\n\t\t};\n\n\t\tif (options.memoryConnection) {\n\t\t\tconst memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t\t| BaseChatMemory\n\t\t\t\t| undefined;\n\n\t\t\tif (memory) {\n\t\t\t\tawait memory.chatHistory.addAIMessage(message);\n\t\t\t}\n\t\t}\n\n\t\tconst waitTill = configureWaitTillDate(this);\n\n\t\tawait this.putExecutionToWait(waitTill);\n\t\treturn [[{ json: {}, sendMessage: message }]];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAKO;AAWP,kBAAuD;AAEvD,MAAM,0BAA6C;AAAA,EAClD;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,SAAS;AAAA,IACT,aACC;AAAA,IACD,SAAS;AAAA,MACR;AAAA,QACC,MAAM;AAAA,QACN,aAAa;AAAA,QACb,OAAO;AAAA,MACR;AAAA,MACA;AAAA,QACC,MAAM;AAAA,QACN,aAAa;AAAA,QACb,OAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAAA,EACA;AAAA,IACC,aAAa;AAAA,IACb,MAAM;AAAA,IACN,MAAM;AAAA,IACN,gBAAgB;AAAA,MACf,MAAM;AAAA,QACL,WAAW,CAAC,mBAAmB;AAAA,MAChC;AAAA,IACD;AAAA,IACA,aAAa;AAAA,MACZ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,IACD;AAEA,QAAI,WAAW,QAAQ,iBAAiB,iBAAiB;AACxD,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,MACD;AAAA,IACD;AAEA,UAAM,UAAW,KAAK,iBAAiB,WAAW,CAAC,KAAgB;AACnE,UAAM,UAAU,KAAK,iBAAiB,WAAW,GAAG,CAAC,CAAC;AAItD,QAAI,QAAQ,kBAAkB;AAC7B,YAAM,SAAU,MAAM,KAAK,uBAAuB,wCAAoB,UAAU,CAAC;AAIjF,UAAI,QAAQ;AACX,cAAM,OAAO,YAAY,aAAa,OAAO;AAAA,MAC9C;AAAA,IACD;AAEA,UAAM,eAAW,mCAAsB,IAAI;AAE3C,UAAM,KAAK,mBAAmB,QAAQ;AACtC,WAAO,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,aAAa,QAAQ,CAAC,CAAC;AAAA,EAC7C;AACD;","names":[]}
|
|
@@ -72,7 +72,7 @@ const streamingResponseMode = {
|
|
|
72
72
|
const respondNodesResponseMode = {
|
|
73
73
|
name: "Using Response Nodes",
|
|
74
74
|
value: "responseNodes",
|
|
75
|
-
description: "Send responses to the chat by using 'Respond to Chat'
|
|
75
|
+
description: "Send responses to the chat by using 'Respond to Chat' node"
|
|
76
76
|
};
|
|
77
77
|
const commonOptionsFields = [
|
|
78
78
|
// CORS parameters are only valid for when chat is used in hosted or webhook mode
|