@n8n/n8n-nodes-langchain 1.121.1 → 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.
Files changed (137) hide show
  1. package/dist/nodes/Guardrails/Guardrails.node.js +29 -40
  2. package/dist/nodes/Guardrails/Guardrails.node.js.map +1 -1
  3. package/dist/nodes/Guardrails/actions/execute.js +68 -0
  4. package/dist/nodes/Guardrails/actions/execute.js.map +1 -0
  5. package/dist/nodes/Guardrails/actions/process.js +10 -7
  6. package/dist/nodes/Guardrails/actions/process.js.map +1 -1
  7. package/dist/nodes/Guardrails/description.js +326 -365
  8. package/dist/nodes/Guardrails/description.js.map +1 -1
  9. package/dist/nodes/Guardrails/helpers/configureNodeInputs.js +37 -3
  10. package/dist/nodes/Guardrails/helpers/configureNodeInputs.js.map +1 -1
  11. package/dist/nodes/Guardrails/helpers/model.js.map +1 -1
  12. package/dist/nodes/Guardrails/v1/GuardrailsV1.node.js +59 -0
  13. package/dist/nodes/Guardrails/v1/GuardrailsV1.node.js.map +1 -0
  14. package/dist/nodes/Guardrails/v2/GuardrailsV2.node.js +59 -0
  15. package/dist/nodes/Guardrails/v2/GuardrailsV2.node.js.map +1 -0
  16. package/dist/nodes/ToolExecutor/ToolExecutor.node.js.map +1 -1
  17. package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js +1 -1
  18. package/dist/nodes/agents/Agent/agents/ConversationalAgent/execute.js.map +1 -1
  19. package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js +3 -85
  20. package/dist/nodes/agents/Agent/agents/OpenAiFunctionsAgent/execute.js.map +1 -1
  21. package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js +1 -1
  22. package/dist/nodes/agents/Agent/agents/PlanAndExecuteAgent/execute.js.map +1 -1
  23. package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js +1 -1
  24. package/dist/nodes/agents/Agent/agents/ReActAgent/execute.js.map +1 -1
  25. package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js +2 -2
  26. package/dist/nodes/agents/Agent/agents/SqlAgent/execute.js.map +1 -1
  27. package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js +1 -1
  28. package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js.map +1 -1
  29. package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js +1 -1
  30. package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js.map +1 -1
  31. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/buildExecutionContext.js.map +1 -1
  32. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js +1 -1
  33. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/createAgentSequence.js.map +1 -1
  34. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.js.map +1 -1
  35. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/finalizeResult.js.map +1 -1
  36. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/prepareItemContext.js.map +1 -1
  37. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js +8 -16
  38. package/dist/nodes/agents/Agent/agents/ToolsAgent/V3/helpers/runAgent.js.map +1 -1
  39. package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js +1 -1
  40. package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js.map +1 -1
  41. package/dist/nodes/agents/Agent/agents/utils.js.map +1 -1
  42. package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js +2 -2
  43. package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js.map +1 -1
  44. package/dist/nodes/chains/ChainRetrievalQA/processItem.js +2 -2
  45. package/dist/nodes/chains/ChainRetrievalQA/processItem.js.map +1 -1
  46. package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js +1 -1
  47. package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js.map +1 -1
  48. package/dist/nodes/chains/ChainSummarization/V2/processItem.js +1 -1
  49. package/dist/nodes/chains/ChainSummarization/V2/processItem.js.map +1 -1
  50. package/dist/nodes/chains/ChainSummarization/helpers.js.map +1 -1
  51. package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +1 -1
  52. package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -1
  53. package/dist/nodes/chains/InformationExtractor/processItem.js.map +1 -1
  54. package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js +1 -1
  55. package/dist/nodes/chains/SentimentAnalysis/SentimentAnalysis.node.js.map +1 -1
  56. package/dist/nodes/chains/TextClassifier/TextClassifier.node.js +1 -1
  57. package/dist/nodes/chains/TextClassifier/TextClassifier.node.js.map +1 -1
  58. package/dist/nodes/chains/TextClassifier/processItem.js.map +1 -1
  59. package/dist/nodes/code/Code.node.js +66 -2
  60. package/dist/nodes/code/Code.node.js.map +1 -1
  61. package/dist/nodes/llms/LMOllama/LmOllama.node.js +1 -1
  62. package/dist/nodes/llms/LMOllama/LmOllama.node.js.map +1 -1
  63. package/dist/nodes/mcp/McpClientTool/utils.js +1 -1
  64. package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
  65. package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js +1 -1
  66. package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js.map +1 -1
  67. package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js +1 -1
  68. package/dist/nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.js.map +1 -1
  69. package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js +1 -1
  70. package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js.map +1 -1
  71. package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js +1 -1
  72. package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js.map +1 -1
  73. package/dist/nodes/memory/MemoryXata/MemoryXata.node.js +1 -1
  74. package/dist/nodes/memory/MemoryXata/MemoryXata.node.js.map +1 -1
  75. package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js +2 -2
  76. package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js.map +1 -1
  77. package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js +1 -1
  78. package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js.map +1 -1
  79. package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js +1 -1
  80. package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js.map +1 -1
  81. package/dist/nodes/tools/ToolThink/ToolThink.node.js +1 -1
  82. package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -1
  83. package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js +2 -2
  84. package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js.map +1 -1
  85. package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +5 -21
  86. package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
  87. package/dist/nodes/trigger/ChatTrigger/Chat.node.js +2 -2
  88. package/dist/nodes/trigger/ChatTrigger/Chat.node.js.map +1 -1
  89. package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +1 -1
  90. package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
  91. package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js +65 -17
  92. package/dist/nodes/vector_store/VectorStoreAzureAISearch/VectorStoreAzureAISearch.node.js.map +1 -1
  93. package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -1
  94. package/dist/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.js.map +1 -1
  95. package/dist/nodes/vector_store/VectorStoreQdrant/qdrant.svg +23 -19
  96. package/dist/nodes/vector_store/shared/MemoryManager/MemoryCalculator.js.map +1 -1
  97. package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js +1 -1
  98. package/dist/nodes/vector_store/shared/MemoryManager/MemoryVectorStoreManager.js.map +1 -1
  99. package/dist/nodes/vector_store/shared/MemoryManager/StoreCleanupService.js.map +1 -1
  100. package/dist/nodes/vector_store/shared/MemoryManager/types.js.map +1 -1
  101. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +18 -16
  102. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -1
  103. package/dist/nodes/vendors/GoogleGemini/actions/image/edit.operation.js +6 -1
  104. package/dist/nodes/vendors/GoogleGemini/actions/image/edit.operation.js.map +1 -1
  105. package/dist/nodes/vendors/GoogleGemini/actions/image/generate.operation.js +1 -1
  106. package/dist/nodes/vendors/GoogleGemini/actions/image/generate.operation.js.map +1 -1
  107. package/dist/nodes/vendors/GoogleGemini/methods/listSearch.js +23 -8
  108. package/dist/nodes/vendors/GoogleGemini/methods/listSearch.js.map +1 -1
  109. package/dist/nodes/vendors/OpenAi/helpers/utils.js.map +1 -1
  110. package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js +2 -2
  111. package/dist/nodes/vendors/OpenAi/v1/actions/assistant/message.operation.js.map +1 -1
  112. package/dist/types/nodes.json +7 -6
  113. package/dist/utils/N8nBinaryLoader.js +2 -2
  114. package/dist/utils/N8nBinaryLoader.js.map +1 -1
  115. package/dist/utils/N8nJsonLoader.js +2 -2
  116. package/dist/utils/N8nJsonLoader.js.map +1 -1
  117. package/dist/utils/N8nTool.js +1 -1
  118. package/dist/utils/N8nTool.js.map +1 -1
  119. package/dist/utils/agent-execution/buildSteps.js +12 -8
  120. package/dist/utils/agent-execution/buildSteps.js.map +1 -1
  121. package/dist/utils/agent-execution/createEngineRequests.js +19 -1
  122. package/dist/utils/agent-execution/createEngineRequests.js.map +1 -1
  123. package/dist/utils/agent-execution/index.js +4 -4
  124. package/dist/utils/agent-execution/index.js.map +1 -1
  125. package/dist/utils/agent-execution/memoryManagement.js +15 -14
  126. package/dist/utils/agent-execution/memoryManagement.js.map +1 -1
  127. package/dist/utils/agent-execution/processEventStream.js +1 -47
  128. package/dist/utils/agent-execution/processEventStream.js.map +1 -1
  129. package/dist/utils/agent-execution/types.js.map +1 -1
  130. package/dist/utils/fromAIToolFactory.js +61 -0
  131. package/dist/utils/fromAIToolFactory.js.map +1 -0
  132. package/dist/utils/helpers.js +1 -1
  133. package/dist/utils/helpers.js.map +1 -1
  134. package/dist/utils/logWrapper.js.map +1 -1
  135. package/dist/utils/output_parsers/N8nStructuredOutputParser.js +1 -1
  136. package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -1
  137. package/package.json +31 -30
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/chains/TextClassifier/TextClassifier.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';\nimport { NodeOperationError, NodeConnectionTypes, sleep } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeParameters,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { getBatchingOptionFields } from '@utils/sharedFields';\n\nimport { processItem } from './processItem';\n\nconst SYSTEM_PROMPT_TEMPLATE =\n\t\"Please classify the text provided by the user into one of the following categories: {categories}, and use the provided formatting instructions below. Don't explain, and only output the json.\";\n\nconst configuredOutputs = (parameters: INodeParameters) => {\n\tconst categories = ((parameters.categories as IDataObject)?.categories as IDataObject[]) ?? [];\n\tconst fallback = (parameters.options as IDataObject)?.fallback as string;\n\tconst ret = categories.map((cat) => {\n\t\treturn { type: 'main', displayName: cat.category };\n\t});\n\tif (fallback === 'other') ret.push({ type: 'main', displayName: 'Other' });\n\treturn ret;\n};\n\nexport class TextClassifier implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Text Classifier',\n\t\tname: 'textClassifier',\n\t\ticon: 'fa:tags',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Classify your text into distinct categories',\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.text-classifier/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tdefaults: {\n\t\t\tname: 'Text Classifier',\n\t\t},\n\t\tinputs: [\n\t\t\t{ displayName: '', type: NodeConnectionTypes.Main },\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toutputs: `={{(${configuredOutputs})($parameter)}}`,\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Text to Classify',\n\t\t\t\tname: 'inputText',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tdescription: 'Use an expression to reference data in previous nodes or enter static text',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Categories',\n\t\t\t\tname: 'categories',\n\t\t\t\tplaceholder: 'Add Category',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tdefault: {},\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'categories',\n\t\t\t\t\t\tdisplayName: 'Categories',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Category',\n\t\t\t\t\t\t\t\tname: 'category',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: 'Category to add',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Description',\n\t\t\t\t\t\t\t\tname: 'description',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: \"Describe your category if it's not obvious\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Allow Multiple Classes To Be True',\n\t\t\t\t\t\tname: 'multiClass',\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\t{\n\t\t\t\t\t\tdisplayName: 'When No Clear Match',\n\t\t\t\t\t\tname: 'fallback',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdefault: 'discard',\n\t\t\t\t\t\tdescription: 'What to do with items that don’t match the categories exactly',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Discard Item',\n\t\t\t\t\t\t\t\tvalue: 'discard',\n\t\t\t\t\t\t\t\tdescription: 'Ignore the item and drop it from the output',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"Output on Extra, 'Other' Branch\",\n\t\t\t\t\t\t\t\tvalue: 'other',\n\t\t\t\t\t\t\t\tdescription: \"Create a separate output branch called 'Other'\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'System Prompt Template',\n\t\t\t\t\t\tname: 'systemPromptTemplate',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: SYSTEM_PROMPT_TEMPLATE,\n\t\t\t\t\t\tdescription: 'String to use directly as the system prompt template',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 6,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Auto-Fixing',\n\t\t\t\t\t\tname: 'enableAutoFixing',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to enable auto-fixing (may trigger an additional LLM call if output is broken)',\n\t\t\t\t\t},\n\t\t\t\t\tgetBatchingOptionFields({\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.1 } }],\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst items = this.getInputData();\n\t\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'options.batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tconst llm = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst categories = this.getNodeParameter('categories.categories', 0, []) as Array<{\n\t\t\tcategory: string;\n\t\t\tdescription: string;\n\t\t}>;\n\n\t\tif (categories.length === 0) {\n\t\t\tthrow new NodeOperationError(this.getNode(), 'At least one category must be defined');\n\t\t}\n\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tmultiClass: boolean;\n\t\t\tfallback?: string;\n\t\t\tsystemPromptTemplate?: string;\n\t\t\tenableAutoFixing: boolean;\n\t\t};\n\t\tconst multiClass = options?.multiClass ?? false;\n\t\tconst fallback = options?.fallback ?? 'discard';\n\n\t\tconst schemaEntries = categories.map((cat) => [\n\t\t\tcat.category,\n\t\t\tz\n\t\t\t\t.boolean()\n\t\t\t\t.describe(\n\t\t\t\t\t`Should be true if the input has category \"${cat.category}\" (description: ${cat.description})`,\n\t\t\t\t),\n\t\t]);\n\t\tif (fallback === 'other')\n\t\t\tschemaEntries.push([\n\t\t\t\t'fallback',\n\t\t\t\tz.boolean().describe('Should be true if none of the other categories apply'),\n\t\t\t]);\n\t\tconst schema = z.object(Object.fromEntries(schemaEntries));\n\n\t\tconst structuredParser = StructuredOutputParser.fromZodSchema(schema);\n\n\t\tconst parser = options.enableAutoFixing\n\t\t\t? OutputFixingParser.fromLLM(llm, structuredParser)\n\t\t\t: structuredParser;\n\n\t\tconst multiClassPrompt = multiClass\n\t\t\t? 'Categories are not mutually exclusive, and multiple can be true'\n\t\t\t: 'Categories are mutually exclusive, and only one can be true';\n\n\t\tconst fallbackPrompt = {\n\t\t\tother: 'If no categories apply, select the \"fallback\" option.',\n\t\t\tdiscard: 'If there is not a very fitting category, select none of the categories.',\n\t\t}[fallback];\n\n\t\tconst returnData: INodeExecutionData[][] = Array.from(\n\t\t\t{ length: categories.length + (fallback === 'other' ? 1 : 0) },\n\t\t\t(_) => [],\n\t\t);\n\n\t\tif (this.getNode().typeVersion >= 1.1 && batchSize > 1) {\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\t\t\tconst itemIndex = i + batchItemIndex;\n\t\t\t\t\tconst item = items[itemIndex];\n\n\t\t\t\t\treturn await processItem(\n\t\t\t\t\t\tthis,\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tllm,\n\t\t\t\t\t\tparser,\n\t\t\t\t\t\tcategories,\n\t\t\t\t\t\tmultiClassPrompt,\n\t\t\t\t\t\tfallbackPrompt,\n\t\t\t\t\t);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\n\t\t\t\tbatchResults.forEach((response, batchItemIndex) => {\n\t\t\t\t\tconst index = i + batchItemIndex;\n\t\t\t\t\tif (response.status === 'rejected') {\n\t\t\t\t\t\tconst error = response.reason as Error;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\treturnData[0].push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: index },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst output = response.value;\n\t\t\t\t\t\tconst item = items[index];\n\n\t\t\t\t\t\tcategories.forEach((cat, idx) => {\n\t\t\t\t\t\t\tif (output[cat.category]) returnData[idx].push(item);\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (fallback === 'other' && output.fallback)\n\t\t\t\t\t\t\treturnData[returnData.length - 1].push(item);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t// Add delay between batches if not the last batch\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\tconst item = items[itemIndex];\n\n\t\t\t\ttry {\n\t\t\t\t\tconst output = await processItem(\n\t\t\t\t\t\tthis,\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tllm,\n\t\t\t\t\t\tparser,\n\t\t\t\t\t\tcategories,\n\t\t\t\t\t\tmultiClassPrompt,\n\t\t\t\t\t\tfallbackPrompt,\n\t\t\t\t\t);\n\n\t\t\t\t\tcategories.forEach((cat, idx) => {\n\t\t\t\t\t\tif (output[cat.category]) returnData[idx].push(item);\n\t\t\t\t\t});\n\t\t\t\t\tif (fallback === 'other' && output.fallback) returnData[returnData.length - 1].push(item);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\treturnData[0].push({\n\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn returnData;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAA2D;AAC3D,0BAA+D;AAS/D,iBAAkB;AAElB,0BAAwC;AAExC,yBAA4B;AAE5B,MAAM,yBACL;AAED,MAAM,oBAAoB,CAAC,eAAgC;AAC1D,QAAM,aAAe,WAAW,YAA4B,cAAgC,CAAC;AAC7F,QAAM,WAAY,WAAW,SAAyB;AACtD,QAAM,MAAM,WAAW,IAAI,CAAC,QAAQ;AACnC,WAAO,EAAE,MAAM,QAAQ,aAAa,IAAI,SAAS;AAAA,EAClD,CAAC;AACD,MAAI,aAAa,QAAS,KAAI,KAAK,EAAE,MAAM,QAAQ,aAAa,QAAQ,CAAC;AACzE,SAAO;AACR;AAEO,M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;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACD;AAEA,qBAAW,QAAQ,CAAC,KAAK,QAAQ;AAChC,gBAAI,OAAO,IAAI,QAAQ,EAAG,YAAW,GAAG,EAAE,KAAK,IAAI;AAAA,UACpD,CAAC;AACD,cAAI,aAAa,WAAW,OAAO,SAAU,YAAW,WAAW,SAAS,CAAC,EAAE,KAAK,IAAI;AAAA,QACzF,SAAS,OAAO;AACf,cAAI,KAAK,eAAe,GAAG;AAC1B,uBAAW,CAAC,EAAE,KAAK;AAAA,cAClB,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,cAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,YAC/B,CAAC;AAED;AAAA,UACD;AAEA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/chains/TextClassifier/TextClassifier.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { OutputFixingParser, StructuredOutputParser } from '@langchain/classic/output_parsers';\nimport { NodeOperationError, NodeConnectionTypes, sleep } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeParameters,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { getBatchingOptionFields } from '@utils/sharedFields';\n\nimport { processItem } from './processItem';\n\nconst SYSTEM_PROMPT_TEMPLATE =\n\t\"Please classify the text provided by the user into one of the following categories: {categories}, and use the provided formatting instructions below. Don't explain, and only output the json.\";\n\nconst configuredOutputs = (parameters: INodeParameters) => {\n\tconst categories = ((parameters.categories as IDataObject)?.categories as IDataObject[]) ?? [];\n\tconst fallback = (parameters.options as IDataObject)?.fallback as string;\n\tconst ret = categories.map((cat) => {\n\t\treturn { type: 'main', displayName: cat.category };\n\t});\n\tif (fallback === 'other') ret.push({ type: 'main', displayName: 'Other' });\n\treturn ret;\n};\n\nexport class TextClassifier implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Text Classifier',\n\t\tname: 'textClassifier',\n\t\ticon: 'fa:tags',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Classify your text into distinct categories',\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Chains', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.text-classifier/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tdefaults: {\n\t\t\tname: 'Text Classifier',\n\t\t},\n\t\tinputs: [\n\t\t\t{ displayName: '', type: NodeConnectionTypes.Main },\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toutputs: `={{(${configuredOutputs})($parameter)}}`,\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Text to Classify',\n\t\t\t\tname: 'inputText',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tdescription: 'Use an expression to reference data in previous nodes or enter static text',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\trows: 2,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Categories',\n\t\t\t\tname: 'categories',\n\t\t\t\tplaceholder: 'Add Category',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tdefault: {},\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'categories',\n\t\t\t\t\t\tdisplayName: 'Categories',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Category',\n\t\t\t\t\t\t\t\tname: 'category',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: 'Category to add',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Description',\n\t\t\t\t\t\t\t\tname: 'description',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\tdescription: \"Describe your category if it's not obvious\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Allow Multiple Classes To Be True',\n\t\t\t\t\t\tname: 'multiClass',\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\t{\n\t\t\t\t\t\tdisplayName: 'When No Clear Match',\n\t\t\t\t\t\tname: 'fallback',\n\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\tdefault: 'discard',\n\t\t\t\t\t\tdescription: 'What to do with items that don’t match the categories exactly',\n\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: 'Discard Item',\n\t\t\t\t\t\t\t\tvalue: 'discard',\n\t\t\t\t\t\t\t\tdescription: 'Ignore the item and drop it from the output',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: \"Output on Extra, 'Other' Branch\",\n\t\t\t\t\t\t\t\tvalue: 'other',\n\t\t\t\t\t\t\t\tdescription: \"Create a separate output branch called 'Other'\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'System Prompt Template',\n\t\t\t\t\t\tname: 'systemPromptTemplate',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: SYSTEM_PROMPT_TEMPLATE,\n\t\t\t\t\t\tdescription: 'String to use directly as the system prompt template',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 6,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Auto-Fixing',\n\t\t\t\t\t\tname: 'enableAutoFixing',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to enable auto-fixing (may trigger an additional LLM call if output is broken)',\n\t\t\t\t\t},\n\t\t\t\t\tgetBatchingOptionFields({\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.1 } }],\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst items = this.getInputData();\n\t\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 5) as number;\n\t\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t\t'options.batching.delayBetweenBatches',\n\t\t\t0,\n\t\t\t0,\n\t\t) as number;\n\n\t\tconst llm = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\t0,\n\t\t)) as BaseLanguageModel;\n\n\t\tconst categories = this.getNodeParameter('categories.categories', 0, []) as Array<{\n\t\t\tcategory: string;\n\t\t\tdescription: string;\n\t\t}>;\n\n\t\tif (categories.length === 0) {\n\t\t\tthrow new NodeOperationError(this.getNode(), 'At least one category must be defined');\n\t\t}\n\n\t\tconst options = this.getNodeParameter('options', 0, {}) as {\n\t\t\tmultiClass: boolean;\n\t\t\tfallback?: string;\n\t\t\tsystemPromptTemplate?: string;\n\t\t\tenableAutoFixing: boolean;\n\t\t};\n\t\tconst multiClass = options?.multiClass ?? false;\n\t\tconst fallback = options?.fallback ?? 'discard';\n\n\t\tconst schemaEntries = categories.map((cat) => [\n\t\t\tcat.category,\n\t\t\tz\n\t\t\t\t.boolean()\n\t\t\t\t.describe(\n\t\t\t\t\t`Should be true if the input has category \"${cat.category}\" (description: ${cat.description})`,\n\t\t\t\t),\n\t\t]);\n\t\tif (fallback === 'other')\n\t\t\tschemaEntries.push([\n\t\t\t\t'fallback',\n\t\t\t\tz.boolean().describe('Should be true if none of the other categories apply'),\n\t\t\t]);\n\t\tconst schema = z.object(Object.fromEntries(schemaEntries));\n\n\t\tconst structuredParser = StructuredOutputParser.fromZodSchema(schema);\n\n\t\tconst parser = options.enableAutoFixing\n\t\t\t? OutputFixingParser.fromLLM(llm, structuredParser)\n\t\t\t: structuredParser;\n\n\t\tconst multiClassPrompt = multiClass\n\t\t\t? 'Categories are not mutually exclusive, and multiple can be true'\n\t\t\t: 'Categories are mutually exclusive, and only one can be true';\n\n\t\tconst fallbackPrompt = {\n\t\t\tother: 'If no categories apply, select the \"fallback\" option.',\n\t\t\tdiscard: 'If there is not a very fitting category, select none of the categories.',\n\t\t}[fallback];\n\n\t\tconst returnData: INodeExecutionData[][] = Array.from(\n\t\t\t{ length: categories.length + (fallback === 'other' ? 1 : 0) },\n\t\t\t(_) => [],\n\t\t);\n\n\t\tif (this.getNode().typeVersion >= 1.1 && batchSize > 1) {\n\t\t\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\t\t\tconst batch = items.slice(i, i + batchSize);\n\t\t\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\t\t\tconst itemIndex = i + batchItemIndex;\n\t\t\t\t\tconst item = items[itemIndex];\n\n\t\t\t\t\treturn await processItem(\n\t\t\t\t\t\tthis,\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tllm,\n\t\t\t\t\t\tparser,\n\t\t\t\t\t\tcategories,\n\t\t\t\t\t\tmultiClassPrompt,\n\t\t\t\t\t\tfallbackPrompt,\n\t\t\t\t\t);\n\t\t\t\t});\n\n\t\t\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\n\t\t\t\tbatchResults.forEach((response, batchItemIndex) => {\n\t\t\t\t\tconst index = i + batchItemIndex;\n\t\t\t\t\tif (response.status === 'rejected') {\n\t\t\t\t\t\tconst error = response.reason as Error;\n\t\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\t\treturnData[0].push({\n\t\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\t\tpairedItem: { item: index },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst output = response.value;\n\t\t\t\t\t\tconst item = items[index];\n\n\t\t\t\t\t\tcategories.forEach((cat, idx) => {\n\t\t\t\t\t\t\tif (output[cat.category]) returnData[idx].push(item);\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (fallback === 'other' && output.fallback)\n\t\t\t\t\t\t\treturnData[returnData.length - 1].push(item);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t// Add delay between batches if not the last batch\n\t\t\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\t\t\tawait sleep(delayBetweenBatches);\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\tconst item = items[itemIndex];\n\n\t\t\t\ttry {\n\t\t\t\t\tconst output = await processItem(\n\t\t\t\t\t\tthis,\n\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tllm,\n\t\t\t\t\t\tparser,\n\t\t\t\t\t\tcategories,\n\t\t\t\t\t\tmultiClassPrompt,\n\t\t\t\t\t\tfallbackPrompt,\n\t\t\t\t\t);\n\n\t\t\t\t\tcategories.forEach((cat, idx) => {\n\t\t\t\t\t\tif (output[cat.category]) returnData[idx].push(item);\n\t\t\t\t\t});\n\t\t\t\t\tif (fallback === 'other' && output.fallback) returnData[returnData.length - 1].push(item);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\t\treturnData[0].push({\n\t\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn returnData;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,4BAA2D;AAC3D,0BAA+D;AAS/D,iBAAkB;AAElB,0BAAwC;AAExC,yBAA4B;AAE5B,MAAM,yBACL;AAED,MAAM,oBAAoB,CAAC,eAAgC;AAC1D,QAAM,aAAe,WAAW,YAA4B,cAAgC,CAAC;AAC7F,QAAM,WAAY,WAAW,SAAyB;AACtD,QAAM,MAAM,WAAW,IAAI,CAAC,QAAQ;AACnC,WAAO,EAAE,MAAM,QAAQ,aAAa,IAAI,SAAS;AAAA,EAClD,CAAC;AACD,MAAI,aAAa,QAAS,KAAI,KAAK,EAAE,MAAM,QAAQ,aAAa,QAAQ,CAAC;AACzE,SAAO;AACR;A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,YACpB;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACD;AAEA,qBAAW,QAAQ,CAAC,KAAK,QAAQ;AAChC,gBAAI,OAAO,IAAI,QAAQ,EAAG,YAAW,GAAG,EAAE,KAAK,IAAI;AAAA,UACpD,CAAC;AACD,cAAI,aAAa,WAAW,OAAO,SAAU,YAAW,WAAW,SAAS,CAAC,EAAE,KAAK,IAAI;AAAA,QACzF,SAAS,OAAO;AACf,cAAI,KAAK,eAAe,GAAG;AAC1B,uBAAW,CAAC,EAAE,KAAK;AAAA,cAClB,MAAM,EAAE,OAAO,MAAM,QAAQ;AAAA,cAC7B,YAAY,EAAE,MAAM,UAAU;AAAA,YAC/B,CAAC;AAED;AAAA,UACD;AAEA,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/chains/TextClassifier/processItem.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { ChatPromptTemplate, SystemMessagePromptTemplate } from '@langchain/core/prompts';\nimport type { OutputFixingParser, StructuredOutputParser } from 'langchain/output_parsers';\nimport { NodeOperationError, type IExecuteFunctions, type INodeExecutionData } from 'n8n-workflow';\n\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { SYSTEM_PROMPT_TEMPLATE } from './constants';\n\nexport async function processItem(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\titem: INodeExecutionData,\n\tllm: BaseLanguageModel,\n\tparser: StructuredOutputParser<any> | OutputFixingParser<any>,\n\tcategories: Array<{ category: string; description: string }>,\n\tmultiClassPrompt: string,\n\tfallbackPrompt: string | undefined,\n): Promise<Record<string, unknown>> {\n\tconst input = ctx.getNodeParameter('inputText', itemIndex) as string;\n\n\tif (!input) {\n\t\tthrow new NodeOperationError(\n\t\t\tctx.getNode(),\n\t\t\t`Text to classify for item ${itemIndex} is not defined`,\n\t\t);\n\t}\n\n\titem.pairedItem = { item: itemIndex };\n\n\tconst inputPrompt = new HumanMessage(input);\n\n\tconst systemPromptTemplateOpt = ctx.getNodeParameter(\n\t\t'options.systemPromptTemplate',\n\t\titemIndex,\n\t\tSYSTEM_PROMPT_TEMPLATE,\n\t) as string;\n\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t`${systemPromptTemplateOpt ?? SYSTEM_PROMPT_TEMPLATE}\n\t{format_instructions}\n\t${multiClassPrompt}\n\t${fallbackPrompt}`,\n\t);\n\n\tconst messages = [\n\t\tawait systemPromptTemplate.format({\n\t\t\tcategories: categories.map((cat) => cat.category).join(', '),\n\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t}),\n\t\tinputPrompt,\n\t];\n\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(ctx));\n\n\treturn await chain.invoke(messages);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAA6B;AAC7B,qBAAgE;AAEhE,0BAAoF;AAEpF,qBAAiC;AAEjC,uBAAuC;AAEvC,eAAsB,YACrB,KACA,WACA,MACA,KACA,QACA,YACA,kBACA,gBACmC;AACnC,QAAM,QAAQ,IAAI,iBAAiB,aAAa,SAAS;AAEzD,MAAI,CAAC,OAAO;AACX,UAAM,IAAI;AAAA,MACT,IAAI,QAAQ;AAAA,MACZ,6BAA6B,SAAS;AAAA,IACvC;AAAA,EACD;AAEA,OAAK,aAAa,EAAE,MAAM,UAAU;AAEpC,QAAM,cAAc,IAAI,6BAAa,KAAK;AAE1C,QAAM,0BAA0B,IAAI;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,QAAM,uBAAuB,2CAA4B;AAAA,IACxD,GAAG,2BAA2B,uCAAsB;AAAA;AAAA,GAEnD,gBAAgB;AAAA,GAChB,cAAc;AAAA,EAChB;AAEA,QAAM,WAAW;AAAA,IAChB,MAAM,qBAAqB,OAAO;AAAA,MACjC,YAAY,WAAW,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,KAAK,IAAI;AAAA,MAC3D,qBAAqB,OAAO,sBAAsB;AAAA,IACnD,CAAC;AAAA,IACD;AAAA,EACD;AACA,QAAM,SAAS,kCAAmB,aAAa,QAAQ;AACvD,QAAM,QAAQ,OAAO,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,eAAW,iCAAiB,GAAG,CAAC;AAE5E,SAAO,MAAM,MAAM,OAAO,QAAQ;AACnC;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/chains/TextClassifier/processItem.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { ChatPromptTemplate, SystemMessagePromptTemplate } from '@langchain/core/prompts';\nimport type { OutputFixingParser, StructuredOutputParser } from '@langchain/classic/output_parsers';\nimport { NodeOperationError, type IExecuteFunctions, type INodeExecutionData } from 'n8n-workflow';\n\nimport { getTracingConfig } from '@utils/tracing';\n\nimport { SYSTEM_PROMPT_TEMPLATE } from './constants';\n\nexport async function processItem(\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n\titem: INodeExecutionData,\n\tllm: BaseLanguageModel,\n\tparser: StructuredOutputParser<any> | OutputFixingParser<any>,\n\tcategories: Array<{ category: string; description: string }>,\n\tmultiClassPrompt: string,\n\tfallbackPrompt: string | undefined,\n): Promise<Record<string, unknown>> {\n\tconst input = ctx.getNodeParameter('inputText', itemIndex) as string;\n\n\tif (!input) {\n\t\tthrow new NodeOperationError(\n\t\t\tctx.getNode(),\n\t\t\t`Text to classify for item ${itemIndex} is not defined`,\n\t\t);\n\t}\n\n\titem.pairedItem = { item: itemIndex };\n\n\tconst inputPrompt = new HumanMessage(input);\n\n\tconst systemPromptTemplateOpt = ctx.getNodeParameter(\n\t\t'options.systemPromptTemplate',\n\t\titemIndex,\n\t\tSYSTEM_PROMPT_TEMPLATE,\n\t) as string;\n\tconst systemPromptTemplate = SystemMessagePromptTemplate.fromTemplate(\n\t\t`${systemPromptTemplateOpt ?? SYSTEM_PROMPT_TEMPLATE}\n\t{format_instructions}\n\t${multiClassPrompt}\n\t${fallbackPrompt}`,\n\t);\n\n\tconst messages = [\n\t\tawait systemPromptTemplate.format({\n\t\t\tcategories: categories.map((cat) => cat.category).join(', '),\n\t\t\tformat_instructions: parser.getFormatInstructions(),\n\t\t}),\n\t\tinputPrompt,\n\t];\n\tconst prompt = ChatPromptTemplate.fromMessages(messages);\n\tconst chain = prompt.pipe(llm).pipe(parser).withConfig(getTracingConfig(ctx));\n\n\treturn await chain.invoke(messages);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAA6B;AAC7B,qBAAgE;AAEhE,0BAAoF;AAEpF,qBAAiC;AAEjC,uBAAuC;AAEvC,eAAsB,YACrB,KACA,WACA,MACA,KACA,QACA,YACA,kBACA,gBACmC;AACnC,QAAM,QAAQ,IAAI,iBAAiB,aAAa,SAAS;AAEzD,MAAI,CAAC,OAAO;AACX,UAAM,IAAI;AAAA,MACT,IAAI,QAAQ;AAAA,MACZ,6BAA6B,SAAS;AAAA,IACvC;AAAA,EACD;AAEA,OAAK,aAAa,EAAE,MAAM,UAAU;AAEpC,QAAM,cAAc,IAAI,6BAAa,KAAK;AAE1C,QAAM,0BAA0B,IAAI;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,QAAM,uBAAuB,2CAA4B;AAAA,IACxD,GAAG,2BAA2B,uCAAsB;AAAA;AAAA,GAEnD,gBAAgB;AAAA,GAChB,cAAc;AAAA,EAChB;AAEA,QAAM,WAAW;AAAA,IAChB,MAAM,qBAAqB,OAAO;AAAA,MACjC,YAAY,WAAW,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,KAAK,IAAI;AAAA,MAC3D,qBAAqB,OAAO,sBAAsB;AAAA,IACnD,CAAC;AAAA,IACD;AAAA,EACD;AACA,QAAM,SAAS,kCAAmB,aAAa,QAAQ;AACvD,QAAM,QAAQ,OAAO,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,eAAW,iCAAiB,GAAG,CAAC;AAE5E,SAAO,MAAM,MAAM,OAAO,QAAQ;AACnC;","names":[]}
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var Code_node_exports = {};
20
20
  __export(Code_node_exports, {
21
21
  Code: () => Code,
22
+ transformLegacyLangchainImport: () => transformLegacyLangchainImport,
22
23
  vmResolver: () => vmResolver
23
24
  });
24
25
  module.exports = __toCommonJS(Code_node_exports);
@@ -54,9 +55,70 @@ const prompt = PromptTemplate.fromTemplate(query);
54
55
  const llm = await this.getInputConnectionData('ai_languageModel', 0);
55
56
  let chain = prompt.pipe(llm);
56
57
  const output = await chain.invoke();
57
- return [ {json: { output } } ];`;
58
+ return [ {json: { output } } ];
59
+
60
+ // NOTE: Old langchain imports (e.g., 'langchain/chains') are automatically
61
+ // converted to '@langchain/classic' imports for backwards compatibility.`;
58
62
  const defaultCodeSupplyData = `const { WikipediaQueryRun } = require( '@langchain/community/tools/wikipedia_query_run');
59
63
  return new WikipediaQueryRun();`;
64
+ function transformLegacyLangchainImport(moduleName) {
65
+ const classicModules = [
66
+ "agents",
67
+ "callbacks",
68
+ "chains",
69
+ "chat_models/universal",
70
+ "document",
71
+ "document_loaders",
72
+ "document_transformers",
73
+ "embeddings/cache_backed",
74
+ "embeddings/fake",
75
+ "evaluation",
76
+ "experimental",
77
+ "hub",
78
+ "indexes",
79
+ "load",
80
+ "memory",
81
+ "output_parsers",
82
+ "retrievers",
83
+ "schema",
84
+ "smith",
85
+ "sql_db",
86
+ "storage",
87
+ "stores",
88
+ "text_splitter",
89
+ "tools",
90
+ "util",
91
+ "vectorstores"
92
+ ];
93
+ if (moduleName.startsWith("langchain/")) {
94
+ const subpath = moduleName.substring("langchain/".length);
95
+ for (const classicModule of classicModules) {
96
+ if (subpath === classicModule || subpath.startsWith(classicModule + "/")) {
97
+ return `@langchain/classic/${subpath}`;
98
+ }
99
+ }
100
+ }
101
+ return moduleName;
102
+ }
103
+ function transformLegacyLangchainCode(code) {
104
+ let transformedCode = code.replace(
105
+ /require\s*\(\s*['"]langchain\/([\w/_]+)['"]\s*\)/g,
106
+ (match, subpath) => {
107
+ const oldPath = `langchain/${subpath}`;
108
+ const newPath = transformLegacyLangchainImport(oldPath);
109
+ return newPath === oldPath ? match : `require('${newPath}')`;
110
+ }
111
+ );
112
+ transformedCode = transformedCode.replace(
113
+ /from\s+['"]langchain\/([\w/_]+)['"]/g,
114
+ (match, subpath) => {
115
+ const oldPath = `langchain/${subpath}`;
116
+ const newPath = transformLegacyLangchainImport(oldPath);
117
+ return newPath === oldPath ? match : `from '${newPath}'`;
118
+ }
119
+ );
120
+ return transformedCode;
121
+ }
60
122
  const langchainModules = ["langchain", "@langchain/*"];
61
123
  const vmResolver = (0, import_vm2.makeResolverFromLegacyOptions)({
62
124
  external: {
@@ -77,6 +139,7 @@ function getSandbox(code, options) {
77
139
  const itemIndex = options?.itemIndex ?? 0;
78
140
  const node = this.getNode();
79
141
  const workflowMode = this.getMode();
142
+ const transformedCode = transformLegacyLangchainCode(code);
80
143
  const context = import_Sandbox.getSandboxContext.call(this, itemIndex);
81
144
  context.addInputData = this.addInputData.bind(this);
82
145
  context.addOutputData = this.addOutputData.bind(this);
@@ -91,7 +154,7 @@ function getSandbox(code, options) {
91
154
  if (options?.addItems) {
92
155
  context.items = context.$input.all();
93
156
  }
94
- const sandbox = new import_JavaScriptSandbox.JavaScriptSandbox(context, code, this.helpers, {
157
+ const sandbox = new import_JavaScriptSandbox.JavaScriptSandbox(context, transformedCode, this.helpers, {
95
158
  resolver: vmResolver
96
159
  });
97
160
  sandbox.on(
@@ -344,6 +407,7 @@ class Code {
344
407
  // Annotate the CommonJS export names for ESM import in node:
345
408
  0 && (module.exports = {
346
409
  Code,
410
+ transformLegacyLangchainImport,
347
411
  vmResolver
348
412
  });
349
413
  //# sourceMappingURL=Code.node.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../nodes/code/Code.node.ts"],"sourcesContent":["import type { Tool } from '@langchain/core/tools';\nimport { makeResolverFromLegacyOptions } from '@n8n/vm2';\nimport { JavaScriptSandbox } from 'n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox';\nimport { getSandboxContext } from 'n8n-nodes-base/dist/nodes/Code/Sandbox';\nimport { standardizeOutput } from 'n8n-nodes-base/dist/nodes/Code/utils';\nimport { NodeOperationError, NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tINodeOutputConfiguration,\n\tSupplyData,\n\tISupplyDataFunctions,\n} from 'n8n-workflow';\n\n// TODO: Add support for execute function. Got already started but got commented out\n\nimport { logWrapper } from '@utils/logWrapper';\n\nconst { NODE_FUNCTION_ALLOW_BUILTIN: builtIn, NODE_FUNCTION_ALLOW_EXTERNAL: external } =\n\tprocess.env;\n\n// TODO: Replace\nconst connectorTypes = {\n\t[NodeConnectionTypes.AiChain]: 'Chain',\n\t[NodeConnectionTypes.AiDocument]: 'Document',\n\t[NodeConnectionTypes.AiEmbedding]: 'Embedding',\n\t[NodeConnectionTypes.AiLanguageModel]: 'Language Model',\n\t[NodeConnectionTypes.AiMemory]: 'Memory',\n\t[NodeConnectionTypes.AiOutputParser]: 'Output Parser',\n\t[NodeConnectionTypes.AiTextSplitter]: 'Text Splitter',\n\t[NodeConnectionTypes.AiTool]: 'Tool',\n\t[NodeConnectionTypes.AiVectorStore]: 'Vector Store',\n\t[NodeConnectionTypes.Main]: 'Main',\n};\n\nconst defaultCodeExecute = `const { PromptTemplate } = require('@langchain/core/prompts');\n\nconst query = 'Tell me a joke';\nconst prompt = PromptTemplate.fromTemplate(query);\n\n// If you are allowing more than one language model input connection (-1 or\n// anything greater than 1), getInputConnectionData returns an array, so you\n// will have to change the code below it to deal with that. For example, use\n// llm[0] in the chain definition\n\nconst llm = await this.getInputConnectionData('ai_languageModel', 0);\nlet chain = prompt.pipe(llm);\nconst output = await chain.invoke();\nreturn [ {json: { output } } ];`;\n\nconst defaultCodeSupplyData = `const { WikipediaQueryRun } = require( '@langchain/community/tools/wikipedia_query_run');\nreturn new WikipediaQueryRun();`;\n\nconst langchainModules = ['langchain', '@langchain/*'];\nexport const vmResolver = makeResolverFromLegacyOptions({\n\texternal: {\n\t\tmodules: external ? [...langchainModules, ...external.split(',')] : [...langchainModules],\n\t\ttransitive: false,\n\t},\n\tresolve(moduleName, parentDirname) {\n\t\tif (moduleName.match(/^langchain\\//) ?? moduleName.match(/^@langchain\\//)) {\n\t\t\treturn require.resolve(`@n8n/n8n-nodes-langchain/node_modules/${moduleName}.cjs`, {\n\t\t\t\tpaths: [parentDirname],\n\t\t\t});\n\t\t}\n\t\treturn;\n\t},\n\tbuiltin: builtIn?.split(',') ?? [],\n});\n\nfunction getSandbox(\n\tthis: IExecuteFunctions | ISupplyDataFunctions,\n\tcode: string,\n\toptions?: { addItems?: boolean; itemIndex?: number },\n) {\n\tconst itemIndex = options?.itemIndex ?? 0;\n\tconst node = this.getNode();\n\tconst workflowMode = this.getMode();\n\n\tconst context = getSandboxContext.call(this, itemIndex);\n\tcontext.addInputData = this.addInputData.bind(this);\n\tcontext.addOutputData = this.addOutputData.bind(this);\n\tcontext.getInputConnectionData = this.getInputConnectionData.bind(this);\n\tcontext.getInputData = this.getInputData.bind(this);\n\tcontext.getNode = this.getNode.bind(this);\n\tcontext.getExecutionCancelSignal = this.getExecutionCancelSignal.bind(this);\n\tcontext.getNodeOutputs = this.getNodeOutputs.bind(this);\n\tcontext.executeWorkflow = this.executeWorkflow.bind(this);\n\tcontext.getWorkflowDataProxy = this.getWorkflowDataProxy.bind(this);\n\tcontext.logger = this.logger;\n\n\tif (options?.addItems) {\n\t\tcontext.items = context.$input.all();\n\t}\n\n\tconst sandbox = new JavaScriptSandbox(context, code, this.helpers, {\n\t\tresolver: vmResolver,\n\t});\n\n\tsandbox.on(\n\t\t'output',\n\t\tworkflowMode === 'manual'\n\t\t\t? this.sendMessageToUI.bind(this)\n\t\t\t: (...args: unknown[]) =>\n\t\t\t\t\tconsole.log(`[Workflow \"${this.getWorkflow().id}\"][Node \"${node.name}\"]`, ...args),\n\t);\n\treturn sandbox;\n}\n\nexport class Code implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'LangChain Code',\n\t\tname: 'code',\n\t\ticon: 'fa:code',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'LangChain Code Node',\n\t\tdefaults: {\n\t\t\tname: 'LangChain Code',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Miscellaneous'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.code/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ ((values) => { const connectorTypes = ${JSON.stringify(\n\t\t\tconnectorTypes,\n\t\t)}; return values.map(value => { return { type: value.type, required: value.required, maxConnections: value.maxConnections === -1 ? undefined : value.maxConnections, displayName: connectorTypes[value.type] !== 'Main' ? connectorTypes[value.type] : undefined } } ) })($parameter.inputs.input) }}`,\n\t\toutputs: `={{ ((values) => { const connectorTypes = ${JSON.stringify(\n\t\t\tconnectorTypes,\n\t\t)}; return values.map(value => { return { type: value.type, displayName: connectorTypes[value.type] !== 'Main' ? connectorTypes[value.type] : undefined } } ) })($parameter.outputs.output) }}`,\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Code',\n\t\t\t\tname: 'code',\n\t\t\t\tplaceholder: 'Add Code',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'execute',\n\t\t\t\t\t\tdisplayName: 'Execute',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'JavaScript - Execute',\n\t\t\t\t\t\t\t\tname: 'code',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\teditor: 'jsEditor',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdefault: defaultCodeExecute,\n\t\t\t\t\t\t\t\thint: 'This code will only run and return data if a \"Main\" input & output got created.',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'supplyData',\n\t\t\t\t\t\tdisplayName: 'Supply Data',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'JavaScript - Supply Data',\n\t\t\t\t\t\t\t\tname: 'code',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\teditor: 'jsEditor',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdefault: defaultCodeSupplyData,\n\t\t\t\t\t\t\t\thint: 'This code will only run and return data if an output got created which is not \"Main\".',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\n\t\t\t// TODO: Add links to docs which provide additional information regarding functionality\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'You can import LangChain and use all available functionality. Debug by using <code>console.log()</code> statements and viewing their output in the browser console.',\n\t\t\t\tname: 'notice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Inputs',\n\t\t\t\tname: 'inputs',\n\t\t\t\tplaceholder: 'Add Input',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\tdescription: 'The input to add',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'input',\n\t\t\t\t\t\tdisplayName: 'Input',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\toptions: Object.keys(connectorTypes).map((key) => ({\n\t\t\t\t\t\t\t\t\tname: connectorTypes[key as keyof typeof connectorTypes],\n\t\t\t\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription: 'The type of the input',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Max Connections',\n\t\t\t\t\t\t\t\tname: 'maxConnections',\n\t\t\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'How many nodes of this type are allowed to be connected. Set it to -1 for unlimited.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Required',\n\t\t\t\t\t\t\t\tname: 'required',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription: 'Whether the input needs a connection',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Outputs',\n\t\t\t\tname: 'outputs',\n\t\t\t\tplaceholder: 'Add Output',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\tdescription: 'The output to add',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'output',\n\t\t\t\t\t\tdisplayName: 'Output',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\toptions: Object.keys(connectorTypes).map((key) => ({\n\t\t\t\t\t\t\t\t\tname: connectorTypes[key as keyof typeof connectorTypes],\n\t\t\t\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription: 'The type of the input',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst itemIndex = 0;\n\n\t\tconst code = this.getNodeParameter('code', itemIndex) as { execute?: { code: string } };\n\n\t\tif (!code.execute?.code) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t`No code for \"Execute\" set on node \"${this.getNode().name}`,\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst sandbox = getSandbox.call(this, code.execute.code, { addItems: true, itemIndex });\n\n\t\tconst outputs = this.getNodeOutputs();\n\t\tconst mainOutputs: INodeOutputConfiguration[] = outputs.filter(\n\t\t\t(output) => output.type === NodeConnectionTypes.Main,\n\t\t);\n\n\t\tconst options = { multiOutput: mainOutputs.length !== 1 };\n\n\t\tlet items: INodeExecutionData[] | INodeExecutionData[][];\n\t\ttry {\n\t\t\titems = await sandbox.runCodeAllItems(options);\n\t\t} catch (error) {\n\t\t\tif (!this.continueOnFail()) throw error;\n\t\t\titems = [{ json: { error: (error as Error).message } }];\n\t\t\tif (options.multiOutput) {\n\t\t\t\titems = [items];\n\t\t\t}\n\t\t}\n\n\t\tif (mainOutputs.length === 0) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'The node does not have a \"Main\" output set. Please add one.',\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t},\n\t\t\t);\n\t\t} else if (!options.multiOutput) {\n\t\t\tfor (const item of items as INodeExecutionData[]) {\n\t\t\t\tstandardizeOutput(item.json);\n\t\t\t}\n\t\t\treturn [items as INodeExecutionData[]];\n\t\t} else {\n\t\t\titems.forEach((data) => {\n\t\t\t\tfor (const item of data as INodeExecutionData[]) {\n\t\t\t\t\tstandardizeOutput(item.json);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn items as INodeExecutionData[][];\n\t\t}\n\t}\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst code = this.getNodeParameter('code', itemIndex) as { supplyData?: { code: string } };\n\n\t\tif (!code.supplyData?.code) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t`No code for \"Supply Data\" set on node \"${this.getNode().name}`,\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst sandbox = getSandbox.call(this, code.supplyData.code, { itemIndex });\n\t\tconst response = await sandbox.runCode<Tool>();\n\n\t\treturn {\n\t\t\tresponse: logWrapper(response, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA8C;AAC9C,+BAAkC;AAClC,qBAAkC;AAClC,mBAAkC;AAClC,0BAAwD;AAaxD,wBAA2B;AAE3B,MAAM,EAAE,6BAA6B,SAAS,8BAA8B,SAAS,IACpF,QAAQ;AAGT,MAAM,iBAAiB;AAAA,EACtB,CAAC,wCAAoB,OAAO,GAAG;AAAA,EAC/B,CAAC,wCAAoB,UAAU,GAAG;AAAA,EAClC,CAAC,wCAAoB,WAAW,GAAG;AAAA,EACnC,CAAC,wCAAoB,eAAe,GAAG;AAAA,EACvC,CAAC,wCAAoB,QAAQ,GAAG;AAAA,EAChC,CAAC,wCAAoB,cAAc,GAAG;AAAA,EACtC,CAAC,wCAAoB,cAAc,GAAG;AAAA,EACtC,CAAC,wCAAoB,MAAM,GAAG;AAAA,EAC9B,CAAC,wCAAoB,aAAa,GAAG;AAAA,EACrC,CAAC,wCAAoB,IAAI,GAAG;AAC7B;AAEA,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAe3B,MAAM,wBAAwB;AAAA;AAG9B,MAAM,mBAAmB,CAAC,aAAa,cAAc;AAC9C,MAAM,iBAAa,0CAA8B;AAAA,EACvD,UAAU;AAAA,IACT,S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G,OAAM;AAClC,cAAQ,CAAC,EAAE,MAAM,EAAE,OAAQ,MAAgB,QAAQ,EAAE,CAAC;AACtD,UAAI,QAAQ,aAAa;AACxB,gBAAQ,CAAC,KAAK;AAAA,MACf;AAAA,IACD;AAEA,QAAI,YAAY,WAAW,GAAG;AAC7B,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,QACA;AAAA,UACC;AAAA,QACD;AAAA,MACD;AAAA,IACD,WAAW,CAAC,QAAQ,aAAa;AAChC,iBAAW,QAAQ,OAA+B;AACjD,4CAAkB,KAAK,IAAI;AAAA,MAC5B;AACA,aAAO,CAAC,KAA6B;AAAA,IACtC,OAAO;AACN,YAAM,QAAQ,CAAC,SAAS;AACvB,mBAAW,QAAQ,MAA8B;AAChD,8CAAkB,KAAK,IAAI;AAAA,QAC5B;AAAA,MACD,CAAC;AACD,aAAO;AAAA,IACR;AAAA,EACD;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,OAAO,KAAK,iBAAiB,QAAQ,SAAS;AAEpD,QAAI,CAAC,KAAK,YAAY,MAAM;AAC3B,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb,0CAA0C,KAAK,QAAQ,EAAE,IAAI;AAAA,QAC7D;AAAA,UACC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,UAAU,WAAW,KAAK,MAAM,KAAK,WAAW,MAAM,EAAE,UAAU,CAAC;AACzE,UAAM,WAAW,MAAM,QAAQ,QAAc;AAE7C,WAAO;AAAA,MACN,cAAU,8BAAW,UAAU,IAAI;AAAA,IACpC;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../nodes/code/Code.node.ts"],"sourcesContent":["import type { Tool } from '@langchain/core/tools';\nimport { makeResolverFromLegacyOptions } from '@n8n/vm2';\nimport { JavaScriptSandbox } from 'n8n-nodes-base/dist/nodes/Code/JavaScriptSandbox';\nimport { getSandboxContext } from 'n8n-nodes-base/dist/nodes/Code/Sandbox';\nimport { standardizeOutput } from 'n8n-nodes-base/dist/nodes/Code/utils';\nimport { NodeOperationError, NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n\tINodeOutputConfiguration,\n\tSupplyData,\n\tISupplyDataFunctions,\n} from 'n8n-workflow';\n\n// TODO: Add support for execute function. Got already started but got commented out\n\nimport { logWrapper } from '@utils/logWrapper';\n\nconst { NODE_FUNCTION_ALLOW_BUILTIN: builtIn, NODE_FUNCTION_ALLOW_EXTERNAL: external } =\n\tprocess.env;\n\n// TODO: Replace\nconst connectorTypes = {\n\t[NodeConnectionTypes.AiChain]: 'Chain',\n\t[NodeConnectionTypes.AiDocument]: 'Document',\n\t[NodeConnectionTypes.AiEmbedding]: 'Embedding',\n\t[NodeConnectionTypes.AiLanguageModel]: 'Language Model',\n\t[NodeConnectionTypes.AiMemory]: 'Memory',\n\t[NodeConnectionTypes.AiOutputParser]: 'Output Parser',\n\t[NodeConnectionTypes.AiTextSplitter]: 'Text Splitter',\n\t[NodeConnectionTypes.AiTool]: 'Tool',\n\t[NodeConnectionTypes.AiVectorStore]: 'Vector Store',\n\t[NodeConnectionTypes.Main]: 'Main',\n};\n\nconst defaultCodeExecute = `const { PromptTemplate } = require('@langchain/core/prompts');\n\nconst query = 'Tell me a joke';\nconst prompt = PromptTemplate.fromTemplate(query);\n\n// If you are allowing more than one language model input connection (-1 or\n// anything greater than 1), getInputConnectionData returns an array, so you\n// will have to change the code below it to deal with that. For example, use\n// llm[0] in the chain definition\n\nconst llm = await this.getInputConnectionData('ai_languageModel', 0);\nlet chain = prompt.pipe(llm);\nconst output = await chain.invoke();\nreturn [ {json: { output } } ];\n\n// NOTE: Old langchain imports (e.g., 'langchain/chains') are automatically\n// converted to '@langchain/classic' imports for backwards compatibility.`;\n\nconst defaultCodeSupplyData = `const { WikipediaQueryRun } = require( '@langchain/community/tools/wikipedia_query_run');\nreturn new WikipediaQueryRun();`;\n\n/**\n * Transforms old langchain import paths to @langchain/classic for backwards compatibility.\n * Only transforms paths that actually moved to the classic package.\n *\n * @param moduleName - The original module name from the import statement\n * @returns The transformed module name, or the original if no transformation is needed\n */\nexport function transformLegacyLangchainImport(moduleName: string): string {\n\t// List of langchain submodules that moved to @langchain/classic\n\t// Based on https://www.npmjs.com/package/@langchain/classic exports\n\tconst classicModules = [\n\t\t'agents',\n\t\t'callbacks',\n\t\t'chains',\n\t\t'chat_models/universal',\n\t\t'document',\n\t\t'document_loaders',\n\t\t'document_transformers',\n\t\t'embeddings/cache_backed',\n\t\t'embeddings/fake',\n\t\t'evaluation',\n\t\t'experimental',\n\t\t'hub',\n\t\t'indexes',\n\t\t'load',\n\t\t'memory',\n\t\t'output_parsers',\n\t\t'retrievers',\n\t\t'schema',\n\t\t'smith',\n\t\t'sql_db',\n\t\t'storage',\n\t\t'stores',\n\t\t'text_splitter',\n\t\t'tools',\n\t\t'util',\n\t\t'vectorstores',\n\t];\n\n\t// Check if this is a langchain/ import (old style)\n\tif (moduleName.startsWith('langchain/')) {\n\t\tconst subpath = moduleName.substring('langchain/'.length);\n\n\t\t// Check if this subpath or any parent path is in the classic modules list\n\t\tfor (const classicModule of classicModules) {\n\t\t\tif (subpath === classicModule || subpath.startsWith(classicModule + '/')) {\n\t\t\t\t// Transform to @langchain/classic\n\t\t\t\treturn `@langchain/classic/${subpath}`;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn moduleName;\n}\n\n/**\n * Transforms user code to replace old langchain require/import statements\n * with @langchain/classic equivalents.\n *\n * @param code - The user's code string\n * @returns The transformed code with updated import paths\n */\nfunction transformLegacyLangchainCode(code: string): string {\n\t// Transform require statements: require('langchain/...')\n\tlet transformedCode = code.replace(\n\t\t/require\\s*\\(\\s*['\"]langchain\\/([\\w/_]+)['\"]\\s*\\)/g,\n\t\t(match, subpath) => {\n\t\t\tconst oldPath = `langchain/${subpath}`;\n\t\t\tconst newPath = transformLegacyLangchainImport(oldPath);\n\t\t\treturn newPath === oldPath ? match : `require('${newPath}')`;\n\t\t},\n\t);\n\n\t// Transform import statements: from 'langchain/...'\n\ttransformedCode = transformedCode.replace(\n\t\t/from\\s+['\"]langchain\\/([\\w/_]+)['\"]/g,\n\t\t(match, subpath) => {\n\t\t\tconst oldPath = `langchain/${subpath}`;\n\t\t\tconst newPath = transformLegacyLangchainImport(oldPath);\n\t\t\treturn newPath === oldPath ? match : `from '${newPath}'`;\n\t\t},\n\t);\n\n\treturn transformedCode;\n}\n\nconst langchainModules = ['langchain', '@langchain/*'];\nexport const vmResolver = makeResolverFromLegacyOptions({\n\texternal: {\n\t\tmodules: external ? [...langchainModules, ...external.split(',')] : [...langchainModules],\n\t\ttransitive: false,\n\t},\n\tresolve(moduleName, parentDirname) {\n\t\tif (moduleName.match(/^langchain\\//) ?? moduleName.match(/^@langchain\\//)) {\n\t\t\treturn require.resolve(`@n8n/n8n-nodes-langchain/node_modules/${moduleName}.cjs`, {\n\t\t\t\tpaths: [parentDirname],\n\t\t\t});\n\t\t}\n\t\treturn;\n\t},\n\tbuiltin: builtIn?.split(',') ?? [],\n});\n\nfunction getSandbox(\n\tthis: IExecuteFunctions | ISupplyDataFunctions,\n\tcode: string,\n\toptions?: { addItems?: boolean; itemIndex?: number },\n) {\n\tconst itemIndex = options?.itemIndex ?? 0;\n\tconst node = this.getNode();\n\tconst workflowMode = this.getMode();\n\n\t// Transform legacy langchain imports to @langchain/classic\n\tconst transformedCode = transformLegacyLangchainCode(code);\n\n\tconst context = getSandboxContext.call(this, itemIndex);\n\tcontext.addInputData = this.addInputData.bind(this);\n\tcontext.addOutputData = this.addOutputData.bind(this);\n\tcontext.getInputConnectionData = this.getInputConnectionData.bind(this);\n\tcontext.getInputData = this.getInputData.bind(this);\n\tcontext.getNode = this.getNode.bind(this);\n\tcontext.getExecutionCancelSignal = this.getExecutionCancelSignal.bind(this);\n\tcontext.getNodeOutputs = this.getNodeOutputs.bind(this);\n\tcontext.executeWorkflow = this.executeWorkflow.bind(this);\n\tcontext.getWorkflowDataProxy = this.getWorkflowDataProxy.bind(this);\n\tcontext.logger = this.logger;\n\n\tif (options?.addItems) {\n\t\tcontext.items = context.$input.all();\n\t}\n\n\tconst sandbox = new JavaScriptSandbox(context, transformedCode, this.helpers, {\n\t\tresolver: vmResolver,\n\t});\n\n\tsandbox.on(\n\t\t'output',\n\t\tworkflowMode === 'manual'\n\t\t\t? this.sendMessageToUI.bind(this)\n\t\t\t: (...args: unknown[]) =>\n\t\t\t\t\tconsole.log(`[Workflow \"${this.getWorkflow().id}\"][Node \"${node.name}\"]`, ...args),\n\t);\n\treturn sandbox;\n}\n\nexport class Code implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'LangChain Code',\n\t\tname: 'code',\n\t\ticon: 'fa:code',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'LangChain Code Node',\n\t\tdefaults: {\n\t\t\tname: 'LangChain Code',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Miscellaneous'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.code/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\tinputs: `={{ ((values) => { const connectorTypes = ${JSON.stringify(\n\t\t\tconnectorTypes,\n\t\t)}; return values.map(value => { return { type: value.type, required: value.required, maxConnections: value.maxConnections === -1 ? undefined : value.maxConnections, displayName: connectorTypes[value.type] !== 'Main' ? connectorTypes[value.type] : undefined } } ) })($parameter.inputs.input) }}`,\n\t\toutputs: `={{ ((values) => { const connectorTypes = ${JSON.stringify(\n\t\t\tconnectorTypes,\n\t\t)}; return values.map(value => { return { type: value.type, displayName: connectorTypes[value.type] !== 'Main' ? connectorTypes[value.type] : undefined } } ) })($parameter.outputs.output) }}`,\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Code',\n\t\t\t\tname: 'code',\n\t\t\t\tplaceholder: 'Add Code',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'execute',\n\t\t\t\t\t\tdisplayName: 'Execute',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'JavaScript - Execute',\n\t\t\t\t\t\t\t\tname: 'code',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\teditor: 'jsEditor',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdefault: defaultCodeExecute,\n\t\t\t\t\t\t\t\thint: 'This code will only run and return data if a \"Main\" input & output got created.',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'supplyData',\n\t\t\t\t\t\tdisplayName: 'Supply Data',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'JavaScript - Supply Data',\n\t\t\t\t\t\t\t\tname: 'code',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\t\t\teditor: 'jsEditor',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tdefault: defaultCodeSupplyData,\n\t\t\t\t\t\t\t\thint: 'This code will only run and return data if an output got created which is not \"Main\".',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\n\t\t\t// TODO: Add links to docs which provide additional information regarding functionality\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'You can import LangChain and use all available functionality. Debug by using <code>console.log()</code> statements and viewing their output in the browser console.',\n\t\t\t\tname: 'notice',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Inputs',\n\t\t\t\tname: 'inputs',\n\t\t\t\tplaceholder: 'Add Input',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\tdescription: 'The input to add',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'input',\n\t\t\t\t\t\tdisplayName: 'Input',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\toptions: Object.keys(connectorTypes).map((key) => ({\n\t\t\t\t\t\t\t\t\tname: connectorTypes[key as keyof typeof connectorTypes],\n\t\t\t\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription: 'The type of the input',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Max Connections',\n\t\t\t\t\t\t\t\tname: 'maxConnections',\n\t\t\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t'How many nodes of this type are allowed to be connected. Set it to -1 for unlimited.',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Required',\n\t\t\t\t\t\t\t\tname: 'required',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription: 'Whether the input needs a connection',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Outputs',\n\t\t\t\tname: 'outputs',\n\t\t\t\tplaceholder: 'Add Output',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t\tsortable: true,\n\t\t\t\t},\n\t\t\t\tdescription: 'The output to add',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'output',\n\t\t\t\t\t\tdisplayName: 'Output',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\toptions: Object.keys(connectorTypes).map((key) => ({\n\t\t\t\t\t\t\t\t\tname: connectorTypes[key as keyof typeof connectorTypes],\n\t\t\t\t\t\t\t\t\tvalue: key,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdescription: 'The type of the input',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst itemIndex = 0;\n\n\t\tconst code = this.getNodeParameter('code', itemIndex) as { execute?: { code: string } };\n\n\t\tif (!code.execute?.code) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t`No code for \"Execute\" set on node \"${this.getNode().name}`,\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst sandbox = getSandbox.call(this, code.execute.code, { addItems: true, itemIndex });\n\n\t\tconst outputs = this.getNodeOutputs();\n\t\tconst mainOutputs: INodeOutputConfiguration[] = outputs.filter(\n\t\t\t(output) => output.type === NodeConnectionTypes.Main,\n\t\t);\n\n\t\tconst options = { multiOutput: mainOutputs.length !== 1 };\n\n\t\tlet items: INodeExecutionData[] | INodeExecutionData[][];\n\t\ttry {\n\t\t\titems = await sandbox.runCodeAllItems(options);\n\t\t} catch (error) {\n\t\t\tif (!this.continueOnFail()) throw error;\n\t\t\titems = [{ json: { error: (error as Error).message } }];\n\t\t\tif (options.multiOutput) {\n\t\t\t\titems = [items];\n\t\t\t}\n\t\t}\n\n\t\tif (mainOutputs.length === 0) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'The node does not have a \"Main\" output set. Please add one.',\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t},\n\t\t\t);\n\t\t} else if (!options.multiOutput) {\n\t\t\tfor (const item of items as INodeExecutionData[]) {\n\t\t\t\tstandardizeOutput(item.json);\n\t\t\t}\n\t\t\treturn [items as INodeExecutionData[]];\n\t\t} else {\n\t\t\titems.forEach((data) => {\n\t\t\t\tfor (const item of data as INodeExecutionData[]) {\n\t\t\t\t\tstandardizeOutput(item.json);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn items as INodeExecutionData[][];\n\t\t}\n\t}\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst code = this.getNodeParameter('code', itemIndex) as { supplyData?: { code: string } };\n\n\t\tif (!code.supplyData?.code) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t`No code for \"Supply Data\" set on node \"${this.getNode().name}`,\n\t\t\t\t{\n\t\t\t\t\titemIndex,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tconst sandbox = getSandbox.call(this, code.supplyData.code, { itemIndex });\n\t\tconst response = await sandbox.runCode<Tool>();\n\n\t\treturn {\n\t\t\tresponse: logWrapper(response, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA8C;AAC9C,+BAAkC;AAClC,qBAAkC;AAClC,mBAAkC;AAClC,0BAAwD;AAaxD,wBAA2B;AAE3B,MAAM,EAAE,6BAA6B,SAAS,8BAA8B,SAAS,IACpF,QAAQ;AAGT,MAAM,iBAAiB;AAAA,EACtB,CAAC,wCAAoB,OAAO,GAAG;AAAA,EAC/B,CAAC,wCAAoB,UAAU,GAAG;AAAA,EAClC,CAAC,wCAAoB,WAAW,GAAG;AAAA,EACnC,CAAC,wCAAoB,eAAe,GAAG;AAAA,EACvC,CAAC,wCAAoB,QAAQ,GAAG;AAAA,EAChC,CAAC,wCAAoB,cAAc,GAAG;AAAA,EACtC,CAAC,wCAAoB,cAAc,GAAG;AAAA,EACtC,CAAC,wCAAoB,MAAM,GAAG;AAAA,EAC9B,CAAC,wCAAoB,aAAa,GAAG;AAAA,EACrC,CAAC,wCAAoB,IAAI,GAAG;AAC7B;AAEA,MAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkB3B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OAAQ,MAAgB,QAAQ,EAAE,CAAC;AACtD,UAAI,QAAQ,aAAa;AACxB,gBAAQ,CAAC,KAAK;AAAA,MACf;AAAA,IACD;AAEA,QAAI,YAAY,WAAW,GAAG;AAC7B,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb;AAAA,QACA;AAAA,UACC;AAAA,QACD;AAAA,MACD;AAAA,IACD,WAAW,CAAC,QAAQ,aAAa;AAChC,iBAAW,QAAQ,OAA+B;AACjD,4CAAkB,KAAK,IAAI;AAAA,MAC5B;AACA,aAAO,CAAC,KAA6B;AAAA,IACtC,OAAO;AACN,YAAM,QAAQ,CAAC,SAAS;AACvB,mBAAW,QAAQ,MAA8B;AAChD,8CAAkB,KAAK,IAAI;AAAA,QAC5B;AAAA,MACD,CAAC;AACD,aAAO;AAAA,IACR;AAAA,EACD;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,OAAO,KAAK,iBAAiB,QAAQ,SAAS;AAEpD,QAAI,CAAC,KAAK,YAAY,MAAM;AAC3B,YAAM,IAAI;AAAA,QACT,KAAK,QAAQ;AAAA,QACb,0CAA0C,KAAK,QAAQ,EAAE,IAAI;AAAA,QAC7D;AAAA,UACC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,UAAU,WAAW,KAAK,MAAM,KAAK,WAAW,MAAM,EAAE,UAAU,CAAC;AACzE,UAAM,WAAW,MAAM,QAAQ,QAAc;AAE7C,WAAO;AAAA,MACN,cAAU,8BAAW,UAAU,IAAI;AAAA,IACpC;AAAA,EACD;AACD;","names":[]}
@@ -21,7 +21,7 @@ __export(LmOllama_node_exports, {
21
21
  LmOllama: () => LmOllama
22
22
  });
23
23
  module.exports = __toCommonJS(LmOllama_node_exports);
24
- var import_ollama = require("@langchain/community/llms/ollama");
24
+ var import_ollama = require("@langchain/ollama");
25
25
  var import_n8n_workflow = require("n8n-workflow");
26
26
  var import_sharedFields = require("../../../utils/sharedFields");
27
27
  var import_description = require("./description");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/llms/LMOllama/LmOllama.node.ts"],"sourcesContent":["import { Ollama } from '@langchain/community/llms/ollama';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { ollamaDescription, ollamaModel, ollamaOptions } from './description';\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\n\nexport class LmOllama implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Ollama Model',\n\n\t\tname: 'lmOllama',\n\t\ticon: 'file:ollama.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Language Model Ollama',\n\t\tdefaults: {\n\t\t\tname: 'Ollama Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Text Completion Models'],\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.lmollama/',\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.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\t...ollamaDescription,\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),\n\t\t\tollamaModel,\n\t\t\tollamaOptions,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('ollamaApi');\n\n\t\tconst modelName = this.getNodeParameter('model', itemIndex) as string;\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as object;\n\t\tconst headers = credentials.apiKey\n\t\t\t? {\n\t\t\t\t\tAuthorization: `Bearer ${credentials.apiKey as string}`,\n\t\t\t\t}\n\t\t\t: undefined;\n\n\t\tconst model = new Ollama({\n\t\t\tbaseUrl: credentials.baseUrl as string,\n\t\t\tmodel: modelName,\n\t\t\t...options,\n\t\t\tcallbacks: [new N8nLlmTracing(this)],\n\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t\theaders,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AACvB,0BAMO;AAEP,0BAA6C;AAE7C,yBAA8D;AAC9D,wCAA+C;AAC/C,2BAA8B;AAEvB,MAAM,SAA8B;AAAA,EAApC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MAEb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,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,mBAAmB,YAAY;AAAA,UACpC,mBAAmB,CAAC,wBAAwB;AAAA,QAC7C;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ,CAAC;AAAA,MAET,SAAS,CAAC,wCAAoB,eAAe;AAAA,MAC7C,aAAa,CAAC,OAAO;AAAA,MACrB,GAAG;AAAA,MACH,YAAY;AAAA,YACX,kDAA6B,CAAC,wCAAoB,SAAS,wCAAoB,OAAO,CAAC;AAAA,QACvF;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,cAAc,MAAM,KAAK,eAAe,WAAW;AAEzD,UAAM,YAAY,KAAK,iBAAiB,SAAS,SAAS;AAC1D,UAAM,UAAU,KAAK,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAC9D,UAAM,UAAU,YAAY,SACzB;AAAA,MACA,eAAe,UAAU,YAAY,MAAgB;AAAA,IACtD,IACC;AAEH,UAAM,QAAQ,IAAI,qBAAO;AAAA,MACxB,SAAS,YAAY;AAAA,MACrB,OAAO;AAAA,MACP,GAAG;AAAA,MACH,WAAW,CAAC,IAAI,mCAAc,IAAI,CAAC;AAAA,MACnC,qBAAiB,kEAA+B,IAAI;AAAA,MACpD;AAAA,IACD,CAAC;AAED,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/llms/LMOllama/LmOllama.node.ts"],"sourcesContent":["import { Ollama } from '@langchain/ollama';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { ollamaDescription, ollamaModel, ollamaOptions } from './description';\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\n\nexport class LmOllama implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Ollama Model',\n\n\t\tname: 'lmOllama',\n\t\ticon: 'file:ollama.svg',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Language Model Ollama',\n\t\tdefaults: {\n\t\t\tname: 'Ollama Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Text Completion Models'],\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.lmollama/',\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.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\t...ollamaDescription,\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),\n\t\t\tollamaModel,\n\t\t\tollamaOptions,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('ollamaApi');\n\n\t\tconst modelName = this.getNodeParameter('model', itemIndex) as string;\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as object;\n\t\tconst headers = credentials.apiKey\n\t\t\t? {\n\t\t\t\t\tAuthorization: `Bearer ${credentials.apiKey as string}`,\n\t\t\t\t}\n\t\t\t: undefined;\n\n\t\tconst model = new Ollama({\n\t\t\tbaseUrl: credentials.baseUrl as string,\n\t\t\tmodel: modelName,\n\t\t\t...options,\n\t\t\tcallbacks: [new N8nLlmTracing(this)],\n\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t\theaders,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAuB;AACvB,0BAMO;AAEP,0BAA6C;AAE7C,yBAA8D;AAC9D,wCAA+C;AAC/C,2BAA8B;AAEvB,MAAM,SAA8B;AAAA,EAApC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MAEb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,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,mBAAmB,YAAY;AAAA,UACpC,mBAAmB,CAAC,wBAAwB;AAAA,QAC7C;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ,CAAC;AAAA,MAET,SAAS,CAAC,wCAAoB,eAAe;AAAA,MAC7C,aAAa,CAAC,OAAO;AAAA,MACrB,GAAG;AAAA,MACH,YAAY;AAAA,YACX,kDAA6B,CAAC,wCAAoB,SAAS,wCAAoB,OAAO,CAAC;AAAA,QACvF;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,cAAc,MAAM,KAAK,eAAe,WAAW;AAEzD,UAAM,YAAY,KAAK,iBAAiB,SAAS,SAAS;AAC1D,UAAM,UAAU,KAAK,iBAAiB,WAAW,WAAW,CAAC,CAAC;AAC9D,UAAM,UAAU,YAAY,SACzB;AAAA,MACA,eAAe,UAAU,YAAY,MAAgB;AAAA,IACtD,IACC;AAEH,UAAM,QAAQ,IAAI,qBAAO;AAAA,MACxB,SAAS,YAAY;AAAA,MACrB,OAAO;AAAA,MACP,GAAG;AAAA,MACH,WAAW,CAAC,IAAI,mCAAc,IAAI,CAAC;AAAA,MACnC,qBAAiB,kEAA+B,IAAI;AAAA,MACpD;AAAA,IACD,CAAC;AAED,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
@@ -27,7 +27,7 @@ __export(utils_exports, {
27
27
  module.exports = __toCommonJS(utils_exports);
28
28
  var import_tools = require("@langchain/core/tools");
29
29
  var import_types = require("@modelcontextprotocol/sdk/types.js");
30
- var import_agents = require("langchain/agents");
30
+ var import_agents = require("@langchain/classic/agents");
31
31
  var import_zod = require("zod");
32
32
  var import_schemaParsing = require("../../../utils/schemaParsing");
33
33
  function getSelectedTools({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/mcp/McpClientTool/utils.ts"],"sourcesContent":["import { DynamicStructuredTool, type DynamicStructuredToolInput } from '@langchain/core/tools';\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { CompatibilityCallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { Toolkit } from 'langchain/agents';\nimport { type IDataObject } from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { convertJsonSchemaToZod } from '@utils/schemaParsing';\n\nimport type { McpToolIncludeMode } from './types';\nimport type { McpTool } from '../shared/types';\n\nexport function getSelectedTools({\n\tmode,\n\tincludeTools,\n\texcludeTools,\n\ttools,\n}: {\n\tmode: McpToolIncludeMode;\n\tincludeTools?: string[];\n\texcludeTools?: string[];\n\ttools: McpTool[];\n}) {\n\tswitch (mode) {\n\t\tcase 'selected': {\n\t\t\tif (!includeTools?.length) return tools;\n\t\t\tconst include = new Set(includeTools);\n\t\t\treturn tools.filter((tool) => include.has(tool.name));\n\t\t}\n\t\tcase 'except': {\n\t\t\tconst except = new Set(excludeTools ?? []);\n\t\t\treturn tools.filter((tool) => !except.has(tool.name));\n\t\t}\n\t\tcase 'all':\n\t\tdefault:\n\t\t\treturn tools;\n\t}\n}\n\nexport const getErrorDescriptionFromToolCall = (result: unknown): string | undefined => {\n\tif (result && typeof result === 'object') {\n\t\tif ('content' in result && Array.isArray(result.content)) {\n\t\t\tconst errorMessage = (result.content as Array<{ type: 'text'; text: string }>).find(\n\t\t\t\t(content) => content && typeof content === 'object' && typeof content.text === 'string',\n\t\t\t)?.text;\n\t\t\treturn errorMessage;\n\t\t} else if ('toolResult' in result && typeof result.toolResult === 'string') {\n\t\t\treturn result.toolResult;\n\t\t}\n\t\tif ('message' in result && typeof result.message === 'string') {\n\t\t\treturn result.message;\n\t\t}\n\t}\n\n\treturn undefined;\n};\n\nexport const createCallTool =\n\t(name: string, client: Client, timeout: number, onError: (error: string) => void) =>\n\tasync (args: IDataObject) => {\n\t\tlet result: Awaited<ReturnType<Client['callTool']>>;\n\n\t\tfunction handleError(error: unknown) {\n\t\t\tconst errorDescription =\n\t\t\t\tgetErrorDescriptionFromToolCall(error) ?? `Failed to execute tool \"${name}\"`;\n\t\t\tonError(errorDescription);\n\t\t\treturn errorDescription;\n\t\t}\n\n\t\ttry {\n\t\t\tresult = await client.callTool({ name, arguments: args }, CompatibilityCallToolResultSchema, {\n\t\t\t\ttimeout,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn handleError(error);\n\t\t}\n\n\t\tif (result.isError) {\n\t\t\treturn handleError(result);\n\t\t}\n\n\t\tif (result.toolResult !== undefined) {\n\t\t\treturn result.toolResult;\n\t\t}\n\n\t\tif (result.content !== undefined) {\n\t\t\treturn result.content;\n\t\t}\n\n\t\treturn result;\n\t};\n\nexport function mcpToolToDynamicTool(\n\ttool: McpTool,\n\tonCallTool: DynamicStructuredToolInput['func'],\n): DynamicStructuredTool {\n\tconst rawSchema = convertJsonSchemaToZod(tool.inputSchema);\n\n\t// Ensure we always have an object schema for structured tools\n\tconst objectSchema =\n\t\trawSchema instanceof z.ZodObject ? rawSchema : z.object({ value: rawSchema });\n\n\treturn new DynamicStructuredTool({\n\t\tname: tool.name,\n\t\tdescription: tool.description ?? '',\n\t\tschema: objectSchema,\n\t\tfunc: onCallTool,\n\t\tmetadata: { isFromToolkit: true },\n\t});\n}\n\nexport class McpToolkit extends Toolkit {\n\tconstructor(public tools: DynamicStructuredTool[]) {\n\t\tsuper();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuE;AAEvE,mBA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AAW,KAAK,GAAG,gDAAmC;AAAA,MAC5F;AAAA,IACD,CAAC;AAAA,EACF,SAAS,OAAO;AACf,WAAO,YAAY,KAAK;AAAA,EACzB;AAEA,MAAI,OAAO,SAAS;AACnB,WAAO,YAAY,MAAM;AAAA,EAC1B;AAEA,MAAI,OAAO,eAAe,QAAW;AACpC,WAAO,OAAO;AAAA,EACf;AAEA,MAAI,OAAO,YAAY,QAAW;AACjC,WAAO,OAAO;AAAA,EACf;AAEA,SAAO;AACR;AAEM,SAAS,qBACf,MACA,YACwB;AACxB,QAAM,gBAAY,6CAAuB,KAAK,WAAW;AAGzD,QAAM,eACL,qBAAqB,aAAE,YAAY,YAAY,aAAE,OAAO,EAAE,OAAO,UAAU,CAAC;AAE7E,SAAO,IAAI,mCAAsB;AAAA,IAChC,MAAM,KAAK;AAAA,IACX,aAAa,KAAK,eAAe;AAAA,IACjC,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,UAAU,EAAE,eAAe,KAAK;AAAA,EACjC,CAAC;AACF;AAEO,MAAM,mBAAmB,sBAAQ;AAAA,EACvC,YAAmB,OAAgC;AAClD,UAAM;AADY;AAAA,EAEnB;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/mcp/McpClientTool/utils.ts"],"sourcesContent":["import { DynamicStructuredTool, type DynamicStructuredToolInput } from '@langchain/core/tools';\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { CompatibilityCallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { Toolkit } from '@langchain/classic/agents';\nimport { type IDataObject } from 'n8n-workflow';\nimport { z } from 'zod';\n\nimport { convertJsonSchemaToZod } from '@utils/schemaParsing';\n\nimport type { McpToolIncludeMode } from './types';\nimport type { McpTool } from '../shared/types';\n\nexport function getSelectedTools({\n\tmode,\n\tincludeTools,\n\texcludeTools,\n\ttools,\n}: {\n\tmode: McpToolIncludeMode;\n\tincludeTools?: string[];\n\texcludeTools?: string[];\n\ttools: McpTool[];\n}) {\n\tswitch (mode) {\n\t\tcase 'selected': {\n\t\t\tif (!includeTools?.length) return tools;\n\t\t\tconst include = new Set(includeTools);\n\t\t\treturn tools.filter((tool) => include.has(tool.name));\n\t\t}\n\t\tcase 'except': {\n\t\t\tconst except = new Set(excludeTools ?? []);\n\t\t\treturn tools.filter((tool) => !except.has(tool.name));\n\t\t}\n\t\tcase 'all':\n\t\tdefault:\n\t\t\treturn tools;\n\t}\n}\n\nexport const getErrorDescriptionFromToolCall = (result: unknown): string | undefined => {\n\tif (result && typeof result === 'object') {\n\t\tif ('content' in result && Array.isArray(result.content)) {\n\t\t\tconst errorMessage = (result.content as Array<{ type: 'text'; text: string }>).find(\n\t\t\t\t(content) => content && typeof content === 'object' && typeof content.text === 'string',\n\t\t\t)?.text;\n\t\t\treturn errorMessage;\n\t\t} else if ('toolResult' in result && typeof result.toolResult === 'string') {\n\t\t\treturn result.toolResult;\n\t\t}\n\t\tif ('message' in result && typeof result.message === 'string') {\n\t\t\treturn result.message;\n\t\t}\n\t}\n\n\treturn undefined;\n};\n\nexport const createCallTool =\n\t(name: string, client: Client, timeout: number, onError: (error: string) => void) =>\n\tasync (args: IDataObject) => {\n\t\tlet result: Awaited<ReturnType<Client['callTool']>>;\n\n\t\tfunction handleError(error: unknown) {\n\t\t\tconst errorDescription =\n\t\t\t\tgetErrorDescriptionFromToolCall(error) ?? `Failed to execute tool \"${name}\"`;\n\t\t\tonError(errorDescription);\n\t\t\treturn errorDescription;\n\t\t}\n\n\t\ttry {\n\t\t\tresult = await client.callTool({ name, arguments: args }, CompatibilityCallToolResultSchema, {\n\t\t\t\ttimeout,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\treturn handleError(error);\n\t\t}\n\n\t\tif (result.isError) {\n\t\t\treturn handleError(result);\n\t\t}\n\n\t\tif (result.toolResult !== undefined) {\n\t\t\treturn result.toolResult;\n\t\t}\n\n\t\tif (result.content !== undefined) {\n\t\t\treturn result.content;\n\t\t}\n\n\t\treturn result;\n\t};\n\nexport function mcpToolToDynamicTool(\n\ttool: McpTool,\n\tonCallTool: DynamicStructuredToolInput['func'],\n): DynamicStructuredTool {\n\tconst rawSchema = convertJsonSchemaToZod(tool.inputSchema);\n\n\t// Ensure we always have an object schema for structured tools\n\tconst objectSchema =\n\t\trawSchema instanceof z.ZodObject ? rawSchema : z.object({ value: rawSchema });\n\n\treturn new DynamicStructuredTool({\n\t\tname: tool.name,\n\t\tdescription: tool.description ?? '',\n\t\tschema: objectSchema,\n\t\tfunc: onCallTool,\n\t\tmetadata: { isFromToolkit: true },\n\t});\n}\n\nexport class McpToolkit extends Toolkit {\n\tconstructor(public tools: DynamicStructuredTool[]) {\n\t\tsuper();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuE;AAEvE,mBAAkD;AAClD,oBAAwB;AAExB,iBAAkB;AAElB,2BAAuC;AAKhC,SAAS,iBAAiB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAKG;AACF,UAAQ,MAAM;AAAA,IACb,KAAK,YAAY;AAChB,UAAI,CAAC,cAAc,OAAQ,QAAO;AAClC,YAAM,UAAU,IAAI,IAAI,YAAY;AACpC,aAAO,MAAM,OAAO,CAAC,SAAS,QAAQ,IAAI,KAAK,IAAI,CAAC;AAAA,IACrD;AAAA,IACA,KAAK,UAAU;AACd,YAAM,SAAS,IAAI,IAAI,gBAAgB,CAAC,CAAC;AACzC,aAAO,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,IAAI,KAAK,IAAI,CAAC;AAAA,IACrD;AAAA,IACA,KAAK;AAAA,IACL;AACC,aAAO;AAAA,EACT;AACD;AAEO,MAAM,kCAAkC,CAAC,WAAwC;AACvF,MAAI,UAAU,OAAO,WAAW,UAAU;AACzC,QAAI,aAAa,UAAU,MAAM,QAAQ,OAAO,OAAO,GAAG;AACzD,YAAM,eAAgB,OAAO,QAAkD;A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AAClD,UAAM;AADY;AAAA,EAEnB;AACD;","names":[]}
@@ -21,7 +21,7 @@ __export(MemoryBufferWindow_node_exports, {
21
21
  MemoryBufferWindow: () => MemoryBufferWindow
22
22
  });
23
23
  module.exports = __toCommonJS(MemoryBufferWindow_node_exports);
24
- var import_memory = require("langchain/memory");
24
+ var import_memory = require("@langchain/classic/memory");
25
25
  var import_n8n_workflow = require("n8n-workflow");
26
26
  var import_helpers = require("../../../utils/helpers");
27
27
  var import_logWrapper = require("../../../utils/logWrapper");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts"],"sourcesContent":["import type { BufferWindowMemoryInput } from 'langchain/memory';\nimport { BufferWindowMemory } from 'langchain/memory';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\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\nclass MemoryChatBufferSingleton {\n\tprivate static instance: MemoryChatBufferSingleton;\n\n\tprivate memoryBuffer: Map<\n\t\tstring,\n\t\t{ buffer: BufferWindowMemory; created: Date; last_accessed: Date }\n\t>;\n\n\tprivate constructor() {\n\t\tthis.memoryBuffer = new Map();\n\t}\n\n\tstatic getInstance(): MemoryChatBufferSingleton {\n\t\tif (!MemoryChatBufferSingleton.instance) {\n\t\t\tMemoryChatBufferSingleton.instance = new MemoryChatBufferSingleton();\n\t\t}\n\t\treturn MemoryChatBufferSingleton.instance;\n\t}\n\n\tasync getMemory(\n\t\tsessionKey: string,\n\t\tmemoryParams: BufferWindowMemoryInput,\n\t): Promise<BufferWindowMemory> {\n\t\tawait this.cleanupStaleBuffers();\n\n\t\tlet memoryInstance = this.memoryBuffer.get(sessionKey);\n\t\tif (memoryInstance) {\n\t\t\tmemoryInstance.last_accessed = new Date();\n\t\t} else {\n\t\t\tconst newMemory = new BufferWindowMemory(memoryParams);\n\n\t\t\tmemoryInstance = {\n\t\t\t\tbuffer: newMemory,\n\t\t\t\tcreated: new Date(),\n\t\t\t\tlast_accessed: new Date(),\n\t\t\t};\n\t\t\tthis.memoryBuffer.set(sessionKey, memoryInstance);\n\t\t}\n\t\treturn memoryInstance.buffer;\n\t}\n\n\tprivate async cleanupStaleBuffers(): Promise<void> {\n\t\tconst oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);\n\n\t\tfor (const [key, memoryInstance] of this.memoryBuffer.entries()) {\n\t\t\tif (memoryInstance.last_accessed < oneHourAgo) {\n\t\t\t\tawait this.memoryBuffer.get(key)?.buffer.clear();\n\t\t\t\tthis.memoryBuffer.delete(key);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class MemoryBufferWindow implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Simple Memory',\n\t\tname: 'memoryBufferWindow',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Stores in n8n memory, so no credentials required',\n\t\tdefaults: {\n\t\t\tname: 'Simple Memory',\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: ['For beginners'],\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.memorybufferwindow/',\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\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Key',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'chat_history',\n\t\t\t\tdescription: 'The key to use to store the memory in the workflow data',\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: 'sessionKey',\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\texpressionSessionKeyProperty(1.3),\n\t\t\tsessionKeyProperty,\n\t\t\tcontextWindowLengthProperty,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst contextWindowLength = this.getNodeParameter('contextWindowLength', itemIndex) as number;\n\t\tconst workflowId = this.getWorkflow().id;\n\t\tconst memoryInstance = MemoryChatBufferSingleton.getInstance();\n\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('sessionKey', itemIndex) as string;\n\t\t}\n\n\t\tconst memory = await memoryInstance.getMemory(`${workflowId}__${sessionId}`, {\n\t\t\tk: contextWindowLength,\n\t\t\tinputKey: 'input',\n\t\t\tmemoryKey: 'chat_history',\n\t\t\toutputKey: 'output',\n\t\t\treturnMessages: true,\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;AACA,oBAAmC;AACnC,0BAMO;AAEP,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEP,MAAM,0BAA0B;AAAA,EAQvB,cAAc;AACrB,SAAK,eAAe,oBAAI,IAAI;AAAA,EAC7B;AAAA,EAEA,OAAO,cAAyC;AAC/C,QAAI,CAAC,0BAA0B,UAAU;AACxC,gCAA0B,WAAW,IAAI,0BAA0B;AAAA,IACpE;AACA,WAAO,0BAA0B;AAAA,EAClC;AAAA,EAEA,MAAM,UACL,YACA,cAC8B;AAC9B,UAAM,KAAK,oBAAoB;AAE/B,QAAI,iBAAiB,KAAK,aAAa,IAAI,UAAU;AACrD,QAAI,gBAAgB;AACnB,qBAAe,gBAAgB,oBAAI,KAAK;AAAA,IACzC,OAAO;AACN,YAAM,YAAY,IAAI,iCAAmB,YAAY;AAErD,uBAAiB;AAAA,QAChB,QAAQ;AAAA,QACR,SAAS,oBAAI,KAAK;AAAA,QAClB,eAAe,oBAAI,KAAK;AAAA,MACzB;AACA,WAAK,aAAa,IAAI,YAAY,cAAc;AAAA,IACjD;AACA,WAAO,eAAe;AAAA,EACvB;AAAA,EAEA,MAAc,sBAAqC;AAClD,UAAM,aAAa,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,GAAI;AAEvD,eAAW,CAAC,KAAK,cAAc,KAAK,KAAK,aAAa,QAAQ,GAAG;AAChE,UAAI,eAAe,gBAAgB,YAAY;AAC9C,cAAM,KAAK,aAAa,IAAI,GAAG,GAAG,OAAO,MAAM;AAC/C,aAAK,aAAa,OAAO,G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;AAAA,UACD;AAAA,QACD;AAAA,YACA,kDAA6B,GAAG;AAAA,QAChC;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,sBAAsB,KAAK,iBAAiB,uBAAuB,SAAS;AAClF,UAAM,aAAa,KAAK,YAAY,EAAE;AACtC,UAAM,iBAAiB,0BAA0B,YAAY;AAE7D,UAAM,cAAc,KAAK,QAAQ,EAAE;AAEnC,QAAI;AAEJ,QAAI,eAAe,KAAK;AACvB,sBAAY,6BAAa,MAAM,SAAS;AAAA,IACzC,OAAO;AACN,kBAAY,KAAK,iBAAiB,cAAc,SAAS;AAAA,IAC1D;AAEA,UAAM,SAAS,MAAM,eAAe,UAAU,GAAG,UAAU,KAAK,SAAS,IAAI;AAAA,MAC5E,GAAG;AAAA,MACH,UAAU;AAAA,MACV,WAAW;AAAA,MACX,WAAW;AAAA,MACX,gBAAgB;AAAA,IACjB,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts"],"sourcesContent":["import type { BufferWindowMemoryInput } from '@langchain/classic/memory';\nimport { BufferWindowMemory } from '@langchain/classic/memory';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\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\nclass MemoryChatBufferSingleton {\n\tprivate static instance: MemoryChatBufferSingleton;\n\n\tprivate memoryBuffer: Map<\n\t\tstring,\n\t\t{ buffer: BufferWindowMemory; created: Date; last_accessed: Date }\n\t>;\n\n\tprivate constructor() {\n\t\tthis.memoryBuffer = new Map();\n\t}\n\n\tstatic getInstance(): MemoryChatBufferSingleton {\n\t\tif (!MemoryChatBufferSingleton.instance) {\n\t\t\tMemoryChatBufferSingleton.instance = new MemoryChatBufferSingleton();\n\t\t}\n\t\treturn MemoryChatBufferSingleton.instance;\n\t}\n\n\tasync getMemory(\n\t\tsessionKey: string,\n\t\tmemoryParams: BufferWindowMemoryInput,\n\t): Promise<BufferWindowMemory> {\n\t\tawait this.cleanupStaleBuffers();\n\n\t\tlet memoryInstance = this.memoryBuffer.get(sessionKey);\n\t\tif (memoryInstance) {\n\t\t\tmemoryInstance.last_accessed = new Date();\n\t\t} else {\n\t\t\tconst newMemory = new BufferWindowMemory(memoryParams);\n\n\t\t\tmemoryInstance = {\n\t\t\t\tbuffer: newMemory,\n\t\t\t\tcreated: new Date(),\n\t\t\t\tlast_accessed: new Date(),\n\t\t\t};\n\t\t\tthis.memoryBuffer.set(sessionKey, memoryInstance);\n\t\t}\n\t\treturn memoryInstance.buffer;\n\t}\n\n\tprivate async cleanupStaleBuffers(): Promise<void> {\n\t\tconst oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);\n\n\t\tfor (const [key, memoryInstance] of this.memoryBuffer.entries()) {\n\t\t\tif (memoryInstance.last_accessed < oneHourAgo) {\n\t\t\t\tawait this.memoryBuffer.get(key)?.buffer.clear();\n\t\t\t\tthis.memoryBuffer.delete(key);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class MemoryBufferWindow implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Simple Memory',\n\t\tname: 'memoryBufferWindow',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Stores in n8n memory, so no credentials required',\n\t\tdefaults: {\n\t\t\tname: 'Simple Memory',\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: ['For beginners'],\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.memorybufferwindow/',\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\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Key',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'chat_history',\n\t\t\t\tdescription: 'The key to use to store the memory in the workflow data',\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: 'sessionKey',\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\texpressionSessionKeyProperty(1.3),\n\t\t\tsessionKeyProperty,\n\t\t\tcontextWindowLengthProperty,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst contextWindowLength = this.getNodeParameter('contextWindowLength', itemIndex) as number;\n\t\tconst workflowId = this.getWorkflow().id;\n\t\tconst memoryInstance = MemoryChatBufferSingleton.getInstance();\n\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('sessionKey', itemIndex) as string;\n\t\t}\n\n\t\tconst memory = await memoryInstance.getMemory(`${workflowId}__${sessionId}`, {\n\t\t\tk: contextWindowLength,\n\t\t\tinputKey: 'input',\n\t\t\tmemoryKey: 'chat_history',\n\t\t\toutputKey: 'output',\n\t\t\treturnMessages: true,\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;AACA,oBAAmC;AACnC,0BAMO;AAEP,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEP,MAAM,0BAA0B;AAAA,EAQvB,cAAc;AACrB,SAAK,eAAe,oBAAI,IAAI;AAAA,EAC7B;AAAA,EAEA,OAAO,cAAyC;AAC/C,QAAI,CAAC,0BAA0B,UAAU;AACxC,gCAA0B,WAAW,IAAI,0BAA0B;AAAA,IACpE;AACA,WAAO,0BAA0B;AAAA,EAClC;AAAA,EAEA,MAAM,UACL,YACA,cAC8B;AAC9B,UAAM,KAAK,oBAAoB;AAE/B,QAAI,iBAAiB,KAAK,aAAa,IAAI,UAAU;AACrD,QAAI,gBAAgB;AACnB,qBAAe,gBAAgB,oBAAI,KAAK;AAAA,IACzC,OAAO;AACN,YAAM,YAAY,IAAI,iCAAmB,YAAY;AAErD,uBAAiB;AAAA,QAChB,QAAQ;AAAA,QACR,SAAS,oBAAI,KAAK;AAAA,QAClB,eAAe,oBAAI,KAA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YACf;AAAA,UACD;AAAA,QACD;AAAA,QACA;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,UACT,aAAa;AAAA,UACb,gBAAgB;AAAA,YACf,MAAM;AAAA,cACL,YAAY,CAAC,GAAG;AAAA,YACjB;AAAA,UACD;AAAA,QACD;AAAA,QACA;AAAA,UACC,GAAG;AAAA,UACH,gBAAgB;AAAA,YACf,MAAM;AAAA,cACL,YAAY,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC;AAAA,YACpC;AAAA,UACD;AAAA,QACD;AAAA,YACA,kDAA6B,GAAG;AAAA,QAChC;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,UAAM,sBAAsB,KAAK,iBAAiB,uBAAuB,SAAS;AAClF,UAAM,aAAa,KAAK,YAAY,EAAE;AACtC,UAAM,iBAAiB,0BAA0B,YAAY;AAE7D,UAAM,cAAc,KAAK,QAAQ,EAAE;AAEnC,QAAI;AAEJ,QAAI,eAAe,KAAK;AACvB,sBAAY,6BAAa,MAAM,SAAS;AAAA,IACzC,OAAO;AACN,kBAAY,KAAK,iBAAiB,cAAc,SAAS;AAAA,IAC1D;AAEA,UAAM,SAAS,MAAM,eAAe,UAAU,GAAG,UAAU,KAAK,SAAS,IAAI;AAAA,MAC5E,GAAG;AAAA,MACH,UAAU;AAAA,MACV,WAAW;AAAA,MACX,WAAW;AAAA,MACX,gBAAgB;AAAA,IACjB,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":[]}
@@ -22,7 +22,7 @@ __export(MemoryMongoDbChat_node_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(MemoryMongoDbChat_node_exports);
24
24
  var import_mongodb = require("@langchain/mongodb");
25
- var import_memory = require("langchain/memory");
25
+ var import_memory = require("@langchain/classic/memory");
26
26
  var import_mongodb2 = require("mongodb");
27
27
  var import_n8n_workflow = require("n8n-workflow");
28
28
  var import_helpers = require("../../../utils/helpers");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.ts"],"sourcesContent":["import { MongoDBChatMessageHistory } from '@langchain/mongodb';\nimport { BufferWindowMemory } from 'langchain/memory';\nimport { MongoClient } from 'mongodb';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes, NodeOperationError } 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\texpressionSessionKeyProperty,\n\tcontextWindowLengthProperty,\n} from '../descriptions';\n\nexport class MemoryMongoDbChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MongoDB Chat Memory',\n\t\tname: 'memoryMongoDbChat',\n\t\ticon: 'file:mongodb.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1],\n\t\tdescription: 'Stores the chat history in MongoDB collection.',\n\t\tdefaults: {\n\t\t\tname: 'MongoDB Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'mongoDb',\n\t\t\t\trequired: true,\n\t\t\t},\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.memorymongochat/',\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.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\tsessionIdOption,\n\t\t\texpressionSessionKeyProperty(1),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Collection Name',\n\t\t\t\tname: 'collectionName',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'n8n_chat_histories',\n\t\t\t\tdescription:\n\t\t\t\t\t'The collection name to store the chat history in. If collection does not exist, it will be created.',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Database Name',\n\t\t\t\tname: 'databaseName',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tdescription:\n\t\t\t\t\t'The database name to store the chat history in. If not provided, the database from credentials will be used.',\n\t\t\t},\n\t\t\tcontextWindowLengthProperty,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<{\n\t\t\tconfigurationType: string;\n\t\t\tconnectionString: string;\n\t\t\tdatabase: string;\n\t\t\thost: string;\n\t\t\tuser: string;\n\t\t\tport: number;\n\t\t\tpassword: string;\n\t\t\ttls: boolean;\n\t\t}>('mongoDb');\n\t\tconst collectionName = this.getNodeParameter(\n\t\t\t'collectionName',\n\t\t\titemIndex,\n\t\t\t'n8n_chat_histories',\n\t\t) as string;\n\t\tconst databaseName = this.getNodeParameter('databaseName', itemIndex, '') as string;\n\t\tconst sessionId = getSessionId(this, itemIndex);\n\n\t\tlet connectionString: string;\n\t\tlet dbName: string;\n\n\t\tif (credentials.configurationType === 'connectionString') {\n\t\t\tconnectionString = credentials.connectionString;\n\t\t\tdbName = databaseName || credentials.database;\n\t\t} else {\n\t\t\t// Build connection string from individual fields\n\t\t\tconst host = credentials.host;\n\t\t\tconst port = credentials.port;\n\t\t\tconst user = credentials.user ? encodeURIComponent(credentials.user) : '';\n\t\t\tconst password = credentials.password ? encodeURIComponent(credentials.password) : '';\n\t\t\tconst authString = user && password ? `${user}:${password}@` : '';\n\t\t\tconst tls = credentials.tls;\n\n\t\t\tconnectionString = `mongodb://${authString}${host}:${port}/?appname=n8n`;\n\t\t\tif (tls) {\n\t\t\t\tconnectionString += '&ssl=true';\n\t\t\t}\n\n\t\t\tdbName = databaseName || credentials.database;\n\t\t}\n\n\t\tif (!dbName) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Database name must be provided either in credentials or in node parameters',\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tconst client = new MongoClient(connectionString);\n\t\t\tawait client.connect();\n\n\t\t\tconst db = client.db(dbName);\n\t\t\tconst collection = db.collection(collectionName);\n\n\t\t\tconst mongoDBChatHistory = new MongoDBChatMessageHistory({\n\t\t\t\tcollection,\n\t\t\t\tsessionId,\n\t\t\t});\n\n\t\t\tconst memory = new BufferWindowMemory({\n\t\t\t\tmemoryKey: 'chat_history',\n\t\t\t\tchatHistory: mongoDBChatHistory,\n\t\t\t\treturnMessages: true,\n\t\t\t\tinputKey: 'input',\n\t\t\t\toutputKey: 'output',\n\t\t\t\tk: this.getNodeParameter('contextWindowLength', itemIndex, 5) as number,\n\t\t\t});\n\n\t\t\tasync function closeFunction() {\n\t\t\t\tawait client.close();\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcloseFunction,\n\t\t\t\tresponse: logWrapper(memory, this),\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(this.getNode(), `MongoDB connection error: ${error.message}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0C;AAC1C,oBAAmC;AACnC,IAAAA,kBAA4B;AAO5B,0BAAwD;AAExD,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAE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AG,6BAA6B,MAAM,OAAO,EAAE;AAAA,IAC1F;AAAA,EACD;AACD;","names":["import_mongodb"]}
1
+ {"version":3,"sources":["../../../../nodes/memory/MemoryMongoDbChat/MemoryMongoDbChat.node.ts"],"sourcesContent":["import { MongoDBChatMessageHistory } from '@langchain/mongodb';\nimport { BufferWindowMemory } from '@langchain/classic/memory';\nimport { MongoClient } from 'mongodb';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes, NodeOperationError } 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\texpressionSessionKeyProperty,\n\tcontextWindowLengthProperty,\n} from '../descriptions';\n\nexport class MemoryMongoDbChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MongoDB Chat Memory',\n\t\tname: 'memoryMongoDbChat',\n\t\ticon: 'file:mongodb.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1],\n\t\tdescription: 'Stores the chat history in MongoDB collection.',\n\t\tdefaults: {\n\t\t\tname: 'MongoDB Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'mongoDb',\n\t\t\t\trequired: true,\n\t\t\t},\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.memorymongochat/',\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.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\tsessionIdOption,\n\t\t\texpressionSessionKeyProperty(1),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Collection Name',\n\t\t\t\tname: 'collectionName',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'n8n_chat_histories',\n\t\t\t\tdescription:\n\t\t\t\t\t'The collection name to store the chat history in. If collection does not exist, it will be created.',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Database Name',\n\t\t\t\tname: 'databaseName',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tdescription:\n\t\t\t\t\t'The database name to store the chat history in. If not provided, the database from credentials will be used.',\n\t\t\t},\n\t\t\tcontextWindowLengthProperty,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<{\n\t\t\tconfigurationType: string;\n\t\t\tconnectionString: string;\n\t\t\tdatabase: string;\n\t\t\thost: string;\n\t\t\tuser: string;\n\t\t\tport: number;\n\t\t\tpassword: string;\n\t\t\ttls: boolean;\n\t\t}>('mongoDb');\n\t\tconst collectionName = this.getNodeParameter(\n\t\t\t'collectionName',\n\t\t\titemIndex,\n\t\t\t'n8n_chat_histories',\n\t\t) as string;\n\t\tconst databaseName = this.getNodeParameter('databaseName', itemIndex, '') as string;\n\t\tconst sessionId = getSessionId(this, itemIndex);\n\n\t\tlet connectionString: string;\n\t\tlet dbName: string;\n\n\t\tif (credentials.configurationType === 'connectionString') {\n\t\t\tconnectionString = credentials.connectionString;\n\t\t\tdbName = databaseName || credentials.database;\n\t\t} else {\n\t\t\t// Build connection string from individual fields\n\t\t\tconst host = credentials.host;\n\t\t\tconst port = credentials.port;\n\t\t\tconst user = credentials.user ? encodeURIComponent(credentials.user) : '';\n\t\t\tconst password = credentials.password ? encodeURIComponent(credentials.password) : '';\n\t\t\tconst authString = user && password ? `${user}:${password}@` : '';\n\t\t\tconst tls = credentials.tls;\n\n\t\t\tconnectionString = `mongodb://${authString}${host}:${port}/?appname=n8n`;\n\t\t\tif (tls) {\n\t\t\t\tconnectionString += '&ssl=true';\n\t\t\t}\n\n\t\t\tdbName = databaseName || credentials.database;\n\t\t}\n\n\t\tif (!dbName) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Database name must be provided either in credentials or in node parameters',\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tconst client = new MongoClient(connectionString);\n\t\t\tawait client.connect();\n\n\t\t\tconst db = client.db(dbName);\n\t\t\tconst collection = db.collection(collectionName);\n\n\t\t\tconst mongoDBChatHistory = new MongoDBChatMessageHistory({\n\t\t\t\tcollection,\n\t\t\t\tsessionId,\n\t\t\t});\n\n\t\t\tconst memory = new BufferWindowMemory({\n\t\t\t\tmemoryKey: 'chat_history',\n\t\t\t\tchatHistory: mongoDBChatHistory,\n\t\t\t\treturnMessages: true,\n\t\t\t\tinputKey: 'input',\n\t\t\t\toutputKey: 'output',\n\t\t\t\tk: this.getNodeParameter('contextWindowLength', itemIndex, 5) as number,\n\t\t\t});\n\n\t\t\tasync function closeFunction() {\n\t\t\t\tawait client.close();\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcloseFunction,\n\t\t\t\tresponse: logWrapper(memory, this),\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(this.getNode(), `MongoDB connection error: ${error.message}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0C;AAC1C,oBAAmC;AACnC,IAAAA,kBAA4B;AAO5B,0BAAwD;AAExD,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,kBAAuC;AAA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AO,EAAE;AAAA,IAC1F;AAAA,EACD;AACD;","names":["import_mongodb"]}
@@ -22,7 +22,7 @@ __export(MemoryPostgresChat_node_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(MemoryPostgresChat_node_exports);
24
24
  var import_postgres = require("@langchain/community/stores/message/postgres");
25
- var import_memory = require("langchain/memory");
25
+ var import_memory = require("@langchain/classic/memory");
26
26
  var import_transport = require("n8n-nodes-base/dist/nodes/Postgres/transport/index");
27
27
  var import_credentialTest = require("n8n-nodes-base/dist/nodes/Postgres/v2/methods/credentialTest");
28
28
  var import_n8n_workflow = require("n8n-workflow");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts"],"sourcesContent":["import { PostgresChatMessageHistory } from '@langchain/community/stores/message/postgres';\nimport { BufferMemory, BufferWindowMemory } from 'langchain/memory';\nimport { configurePostgres } from 'n8n-nodes-base/dist/nodes/Postgres/transport/index';\nimport type { PostgresNodeCredentials } from 'n8n-nodes-base/dist/nodes/Postgres/v2/helpers/interfaces';\nimport { postgresConnectionTest } from 'n8n-nodes-base/dist/nodes/Postgres/v2/methods/credentialTest';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type pg from 'pg';\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 MemoryPostgresChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Postgres Chat Memory',\n\t\tname: 'memoryPostgresChat',\n\t\ticon: 'file:postgres.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Stores the chat history in Postgres table.',\n\t\tdefaults: {\n\t\t\tname: 'Postgres Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'postgres',\n\t\t\t\trequired: true,\n\t\t\t\ttestedBy: 'postgresConnectionTest',\n\t\t\t},\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.memorypostgreschat/',\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\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\tsessionIdOption,\n\t\t\texpressionSessionKeyProperty(1.2),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Table Name',\n\t\t\t\tname: 'tableName',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'n8n_chat_histories',\n\t\t\t\tdescription:\n\t\t\t\t\t'The table name to store the chat history in. If table does not exist, it will be created.',\n\t\t\t},\n\t\t\t{\n\t\t\t\t...contextWindowLengthProperty,\n\t\t\t\tdisplayOptions: { hide: { '@version': [{ _cnd: { lt: 1.1 } }] } },\n\t\t\t},\n\t\t],\n\t};\n\n\tmethods = {\n\t\tcredentialTest: {\n\t\t\tpostgresConnectionTest,\n\t\t},\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<PostgresNodeCredentials>('postgres');\n\t\tconst tableName = this.getNodeParameter('tableName', itemIndex, 'n8n_chat_histories') as string;\n\t\tconst sessionId = getSessionId(this, itemIndex);\n\n\t\tconst pgConf = await configurePostgres.call(this, credentials);\n\t\tconst pool = pgConf.db.$pool as unknown as pg.Pool;\n\n\t\tconst pgChatHistory = new PostgresChatMessageHistory({\n\t\t\tpool,\n\t\t\tsessionId,\n\t\t\ttableName,\n\t\t});\n\n\t\tconst memClass = this.getNode().typeVersion < 1.1 ? BufferMemory : BufferWindowMemory;\n\t\tconst kOptions =\n\t\t\tthis.getNode().typeVersion < 1.1\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\tmemoryKey: 'chat_history',\n\t\t\tchatHistory: pgChatHistory,\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,sBAA2C;AAC3C,oBAAiD;AACjD,uBAAkC;AAElC,4BAAuC;AAOvC,0BAAoC;AAGpC,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,mBAAwC;AAAA,EAA9C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,GAAG;AAAA,MAC1B,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,UACV,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,QAAQ;AAA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AAA,MAC3B,WAAW;AAAA,MACX,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts"],"sourcesContent":["import { PostgresChatMessageHistory } from '@langchain/community/stores/message/postgres';\nimport { BufferMemory, BufferWindowMemory } from '@langchain/classic/memory';\nimport { configurePostgres } from 'n8n-nodes-base/dist/nodes/Postgres/transport/index';\nimport type { PostgresNodeCredentials } from 'n8n-nodes-base/dist/nodes/Postgres/v2/helpers/interfaces';\nimport { postgresConnectionTest } from 'n8n-nodes-base/dist/nodes/Postgres/v2/methods/credentialTest';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type pg from 'pg';\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 MemoryPostgresChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Postgres Chat Memory',\n\t\tname: 'memoryPostgresChat',\n\t\ticon: 'file:postgres.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Stores the chat history in Postgres table.',\n\t\tdefaults: {\n\t\t\tname: 'Postgres Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'postgres',\n\t\t\t\trequired: true,\n\t\t\t\ttestedBy: 'postgresConnectionTest',\n\t\t\t},\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.memorypostgreschat/',\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\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\tsessionIdOption,\n\t\t\texpressionSessionKeyProperty(1.2),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Table Name',\n\t\t\t\tname: 'tableName',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'n8n_chat_histories',\n\t\t\t\tdescription:\n\t\t\t\t\t'The table name to store the chat history in. If table does not exist, it will be created.',\n\t\t\t},\n\t\t\t{\n\t\t\t\t...contextWindowLengthProperty,\n\t\t\t\tdisplayOptions: { hide: { '@version': [{ _cnd: { lt: 1.1 } }] } },\n\t\t\t},\n\t\t],\n\t};\n\n\tmethods = {\n\t\tcredentialTest: {\n\t\t\tpostgresConnectionTest,\n\t\t},\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<PostgresNodeCredentials>('postgres');\n\t\tconst tableName = this.getNodeParameter('tableName', itemIndex, 'n8n_chat_histories') as string;\n\t\tconst sessionId = getSessionId(this, itemIndex);\n\n\t\tconst pgConf = await configurePostgres.call(this, credentials);\n\t\tconst pool = pgConf.db.$pool as unknown as pg.Pool;\n\n\t\tconst pgChatHistory = new PostgresChatMessageHistory({\n\t\t\tpool,\n\t\t\tsessionId,\n\t\t\ttableName,\n\t\t});\n\n\t\tconst memClass = this.getNode().typeVersion < 1.1 ? BufferMemory : BufferWindowMemory;\n\t\tconst kOptions =\n\t\t\tthis.getNode().typeVersion < 1.1\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\tmemoryKey: 'chat_history',\n\t\t\tchatHistory: pgChatHistory,\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,sBAA2C;AAC3C,oBAAiD;AACjD,uBAAkC;AAElC,4BAAuC;AAOvC,0BAAoC;AAGpC,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,mBAAwC;AAAA,EAA9C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,GAAG;AAAA,MAC1B,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,UACV,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,QAAQ;AAAA,UACb,QAAQ,CAAC,gBAAgB;AAAA,QAC1B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ,CAAC;AAAA,MA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AAAA,EACD;AACD;","names":[]}
@@ -22,7 +22,7 @@ __export(MemoryRedisChat_node_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(MemoryRedisChat_node_exports);
24
24
  var import_redis = require("@langchain/redis");
25
- var import_memory = require("langchain/memory");
25
+ var import_memory = require("@langchain/classic/memory");
26
26
  var import_n8n_workflow = require("n8n-workflow");
27
27
  var import_redis2 = require("redis");
28
28
  var import_helpers = require("../../../utils/helpers");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts"],"sourcesContent":["import type { RedisChatMessageHistoryInput } from '@langchain/redis';\nimport { RedisChatMessageHistory } from '@langchain/redis';\nimport { BufferMemory, BufferWindowMemory } from 'langchain/memory';\nimport {\n\tNodeOperationError,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\tNodeConnectionTypes,\n} from 'n8n-workflow';\nimport type { RedisClientOptions } from 'redis';\nimport { createClient } from 'redis';\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 MemoryRedisChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Redis Chat Memory',\n\t\tname: 'memoryRedisChat',\n\t\ticon: 'file:redis.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5],\n\t\tdescription: 'Stores the chat history in Redis.',\n\t\tdefaults: {\n\t\t\tname: 'Redis Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'redis',\n\t\t\t\trequired: true,\n\t\t\t},\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.memoryredischat/',\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\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Key',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'chat_history',\n\t\t\t\tdescription: 'The key to use to store the memory in the workflow data',\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: 'sessionKey',\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\texpressionSessionKeyProperty(1.4),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Time To Live',\n\t\t\t\tname: 'sessionTTL',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 0,\n\t\t\t\tdescription:\n\t\t\t\t\t'For how long the session should be stored in seconds. If set to 0 it will not expire.',\n\t\t\t},\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('redis');\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tconst sessionTTL = this.getNodeParameter('sessionTTL', itemIndex, 0) as number;\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('sessionKey', itemIndex) as string;\n\t\t}\n\n\t\tconst redisOptions: RedisClientOptions = {\n\t\t\tsocket: {\n\t\t\t\thost: credentials.host as string,\n\t\t\t\tport: credentials.port as number,\n\t\t\t\ttls: credentials.ssl === true,\n\t\t\t},\n\t\t\tdatabase: credentials.database as number,\n\t\t};\n\n\t\tif (credentials.user && nodeVersion >= 1.5) {\n\t\t\tredisOptions.username = credentials.user as string;\n\t\t}\n\t\tif (credentials.password) {\n\t\t\tredisOptions.password = credentials.password as string;\n\t\t}\n\n\t\tconst client = createClient({\n\t\t\t...redisOptions,\n\t\t});\n\n\t\tclient.on('error', async (error: Error) => {\n\t\t\tawait client.quit();\n\t\t\tthrow new NodeOperationError(this.getNode(), 'Redis Error: ' + error.message);\n\t\t});\n\n\t\tconst redisChatConfig: RedisChatMessageHistoryInput = {\n\t\t\tclient,\n\t\t\tsessionId,\n\t\t};\n\n\t\tif (sessionTTL > 0) {\n\t\t\tredisChatConfig.sessionTTL = sessionTTL;\n\t\t}\n\t\tconst redisChatHistory = new RedisChatMessageHistory(redisChatConfig);\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\tmemoryKey: 'chat_history',\n\t\t\tchatHistory: redisChatHistory,\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\tasync function closeFunction() {\n\t\t\tvoid client.disconnect();\n\t\t}\n\n\t\treturn {\n\t\t\tcloseFunction,\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAwC;AACxC,oBAAiD;AACjD,0BAOO;AAEP,IAAAA,gBAA6B;AAE7B,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,gBAAqC;AAAA,EAA3C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,MACpC,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,QAAQ;AAAA,UACb,QAAQ,CAAC,gBAAgB;AAAA,QAC1B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ,CAAC;AAAA,MAET,SAAS,CAAC,wCAAoB,QAAQ;AAAA,MACtC,aAAa,CAAC,QAAQ;AAA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A,UAAM,eAAmC;AAAA,MACxC,QAAQ;AAAA,QACP,MAAM,YAAY;AAAA,QAClB,MAAM,YAAY;AAAA,QAClB,KAAK,YAAY,QAAQ;AAAA,MAC1B;AAAA,MACA,UAAU,YAAY;AAAA,IACvB;AAEA,QAAI,YAAY,QAAQ,eAAe,KAAK;AAC3C,mBAAa,WAAW,YAAY;AAAA,IACrC;AACA,QAAI,YAAY,UAAU;AACzB,mBAAa,WAAW,YAAY;AAAA,IACrC;AAEA,UAAM,aAAS,4BAAa;AAAA,MAC3B,GAAG;AAAA,IACJ,CAAC;AAED,WAAO,GAAG,SAAS,OAAO,UAAiB;AAC1C,YAAM,OAAO,KAAK;AAClB,YAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,kBAAkB,MAAM,OAAO;AAAA,IAC7E,CAAC;AAED,UAAM,kBAAgD;AAAA,MACrD;AAAA,MACA;AAAA,IACD;AAEA,QAAI,aAAa,GAAG;AACnB,sBAAgB,aAAa;AAAA,IAC9B;AACA,UAAM,mBAAmB,IAAI,qCAAwB,eAAe;AAEpE,UAAM,WAAW,KAAK,QAAQ,EAAE,cAAc,MAAM,6BAAe;AACnE,UAAM,WACL,KAAK,QAAQ,EAAE,cAAc,MAC1B,CAAC,IACD,EAAE,GAAG,KAAK,iBAAiB,uBAAuB,SAAS,EAAE;AAEjE,UAAM,SAAS,IAAI,SAAS;AAAA,MAC3B,WAAW;AAAA,MACX,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,mBAAe,gBAAgB;AAC9B,WAAK,OAAO,WAAW;AAAA,IACxB;AAEA,WAAO;AAAA,MACN;AAAA,MACA,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":["import_redis"]}
1
+ {"version":3,"sources":["../../../../nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts"],"sourcesContent":["import type { RedisChatMessageHistoryInput } from '@langchain/redis';\nimport { RedisChatMessageHistory } from '@langchain/redis';\nimport { BufferMemory, BufferWindowMemory } from '@langchain/classic/memory';\nimport {\n\tNodeOperationError,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\tNodeConnectionTypes,\n} from 'n8n-workflow';\nimport type { RedisClientOptions } from 'redis';\nimport { createClient } from 'redis';\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 MemoryRedisChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Redis Chat Memory',\n\t\tname: 'memoryRedisChat',\n\t\ticon: 'file:redis.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5],\n\t\tdescription: 'Stores the chat history in Redis.',\n\t\tdefaults: {\n\t\t\tname: 'Redis Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'redis',\n\t\t\t\trequired: true,\n\t\t\t},\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.memoryredischat/',\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\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Key',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'chat_history',\n\t\t\t\tdescription: 'The key to use to store the memory in the workflow data',\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: 'sessionKey',\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\texpressionSessionKeyProperty(1.4),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Time To Live',\n\t\t\t\tname: 'sessionTTL',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 0,\n\t\t\t\tdescription:\n\t\t\t\t\t'For how long the session should be stored in seconds. If set to 0 it will not expire.',\n\t\t\t},\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('redis');\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tconst sessionTTL = this.getNodeParameter('sessionTTL', itemIndex, 0) as number;\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('sessionKey', itemIndex) as string;\n\t\t}\n\n\t\tconst redisOptions: RedisClientOptions = {\n\t\t\tsocket: {\n\t\t\t\thost: credentials.host as string,\n\t\t\t\tport: credentials.port as number,\n\t\t\t\ttls: credentials.ssl === true,\n\t\t\t},\n\t\t\tdatabase: credentials.database as number,\n\t\t};\n\n\t\tif (credentials.user && nodeVersion >= 1.5) {\n\t\t\tredisOptions.username = credentials.user as string;\n\t\t}\n\t\tif (credentials.password) {\n\t\t\tredisOptions.password = credentials.password as string;\n\t\t}\n\n\t\tconst client = createClient({\n\t\t\t...redisOptions,\n\t\t});\n\n\t\tclient.on('error', async (error: Error) => {\n\t\t\tawait client.quit();\n\t\t\tthrow new NodeOperationError(this.getNode(), 'Redis Error: ' + error.message);\n\t\t});\n\n\t\tconst redisChatConfig: RedisChatMessageHistoryInput = {\n\t\t\tclient,\n\t\t\tsessionId,\n\t\t};\n\n\t\tif (sessionTTL > 0) {\n\t\t\tredisChatConfig.sessionTTL = sessionTTL;\n\t\t}\n\t\tconst redisChatHistory = new RedisChatMessageHistory(redisChatConfig);\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\tmemoryKey: 'chat_history',\n\t\t\tchatHistory: redisChatHistory,\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\tasync function closeFunction() {\n\t\t\tvoid client.disconnect();\n\t\t}\n\n\t\treturn {\n\t\t\tcloseFunction,\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;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AAO,UAAiB;AAC1C,YAAM,OAAO,KAAK;AAClB,YAAM,IAAI,uCAAmB,KAAK,QAAQ,GAAG,kBAAkB,MAAM,OAAO;AAAA,IAC7E,CAAC;AAED,UAAM,kBAAgD;AAAA,MACrD;AAAA,MACA;AAAA,IACD;AAEA,QAAI,aAAa,GAAG;AACnB,sBAAgB,aAAa;AAAA,IAC9B;AACA,UAAM,mBAAmB,IAAI,qCAAwB,eAAe;AAEpE,UAAM,WAAW,KAAK,QAAQ,EAAE,cAAc,MAAM,6BAAe;AACnE,UAAM,WACL,KAAK,QAAQ,EAAE,cAAc,MAC1B,CAAC,IACD,EAAE,GAAG,KAAK,iBAAiB,uBAAuB,SAAS,EAAE;AAEjE,UAAM,SAAS,IAAI,SAAS;AAAA,MAC3B,WAAW;AAAA,MACX,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,mBAAe,gBAAgB;AAC9B,WAAK,OAAO,WAAW;AAAA,IACxB;AAEA,WAAO;AAAA,MACN;AAAA,MACA,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":["import_redis"]}
@@ -23,7 +23,7 @@ __export(MemoryXata_node_exports, {
23
23
  module.exports = __toCommonJS(MemoryXata_node_exports);
24
24
  var import_xata = require("@langchain/community/stores/message/xata");
25
25
  var import_client = require("@xata.io/client");
26
- var import_memory = require("langchain/memory");
26
+ var import_memory = require("@langchain/classic/memory");
27
27
  var import_n8n_workflow = require("n8n-workflow");
28
28
  var import_helpers = require("../../../utils/helpers");
29
29
  var import_logWrapper = require("../../../utils/logWrapper");