@n8n/n8n-nodes-langchain 1.98.1 → 1.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +0 -2
  2. package/dist/known/nodes.json +4 -0
  3. package/dist/methods/defined.json +3 -0
  4. package/dist/methods/referenced.json +3 -0
  5. package/dist/nodes/ModelSelector/ModelSelector.node.js +175 -0
  6. package/dist/nodes/ModelSelector/ModelSelector.node.js.map +1 -0
  7. package/dist/nodes/ModelSelector/helpers.js +85 -0
  8. package/dist/nodes/ModelSelector/helpers.js.map +1 -0
  9. package/dist/nodes/agents/Agent/V1/AgentV1.node.js +2 -1
  10. package/dist/nodes/agents/Agent/V1/AgentV1.node.js.map +1 -1
  11. package/dist/nodes/agents/Agent/V2/AgentV2.node.js +2 -1
  12. package/dist/nodes/agents/Agent/V2/AgentV2.node.js.map +1 -1
  13. package/dist/nodes/agents/Agent/agents/utils.js.map +1 -1
  14. package/dist/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.js +4 -3
  15. package/dist/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.js.map +1 -1
  16. package/dist/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.js +1 -1
  17. package/dist/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.js.map +1 -1
  18. package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js +1 -1
  19. package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js.map +1 -1
  20. package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js +1 -1
  21. package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js.map +1 -1
  22. package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js +1 -1
  23. package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js.map +1 -1
  24. package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js +1 -1
  25. package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js.map +1 -1
  26. package/dist/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.js +1 -1
  27. package/dist/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.js.map +1 -1
  28. package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js +1 -1
  29. package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js.map +1 -1
  30. package/dist/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.js +1 -1
  31. package/dist/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.js.map +1 -1
  32. package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js +1 -1
  33. package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js.map +1 -1
  34. package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js +1 -1
  35. package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js.map +1 -1
  36. package/dist/nodes/llms/N8nLlmTracing.js +37 -13
  37. package/dist/nodes/llms/N8nLlmTracing.js.map +1 -1
  38. package/dist/nodes/llms/N8nNonEstimatingTracing.js +167 -0
  39. package/dist/nodes/llms/N8nNonEstimatingTracing.js.map +1 -0
  40. package/dist/nodes/mcp/McpTrigger/McpServer.js +18 -0
  41. package/dist/nodes/mcp/McpTrigger/McpServer.js.map +1 -1
  42. package/dist/nodes/mcp/McpTrigger/McpTrigger.node.js +20 -6
  43. package/dist/nodes/mcp/McpTrigger/McpTrigger.node.js.map +1 -1
  44. package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.js +2 -5
  45. package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.js.map +1 -1
  46. package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TokenTextSplitter.js +59 -0
  47. package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TokenTextSplitter.js.map +1 -0
  48. package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.js +20 -8
  49. package/dist/nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.js.map +1 -1
  50. package/dist/types/nodes.json +6 -5
  51. package/dist/types/types.js +15 -0
  52. package/dist/types/types.js.map +1 -1
  53. package/dist/utils/N8nTool.js.map +1 -1
  54. package/dist/utils/output_parsers/N8nStructuredOutputParser.js +7 -0
  55. package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -1
  56. package/dist/utils/tokenizer/cl100k_base.json +1 -0
  57. package/dist/utils/tokenizer/o200k_base.json +1 -0
  58. package/dist/utils/tokenizer/tiktoken.js +64 -0
  59. package/dist/utils/tokenizer/tiktoken.js.map +1 -0
  60. package/package.json +26 -24
@@ -139,6 +139,16 @@ class McpTrigger extends import_n8n_workflow.Node {
139
139
  nodeType: "mcp",
140
140
  ndvHideMethod: true,
141
141
  ndvHideUrl: true
142
+ },
143
+ {
144
+ name: "default",
145
+ httpMethod: "DELETE",
146
+ responseMode: "onReceived",
147
+ isFullPath: true,
148
+ path: '={{$parameter["path"]}}',
149
+ nodeType: "mcp",
150
+ ndvHideMethod: true,
151
+ ndvHideUrl: true
142
152
  }
143
153
  ]
144
154
  };
@@ -165,13 +175,17 @@ class McpTrigger extends import_n8n_workflow.Node {
165
175
  await mcpServerManager.createServerWithSSETransport(serverName, postUrl, resp);
166
176
  return { noWebhookResponse: true };
167
177
  } else if (webhookName === "default") {
168
- const sessionId = mcpServerManager.getSessionId(req);
169
- if (sessionId && mcpServerManager.getTransport(sessionId)) {
170
- const connectedTools = await (0, import_helpers.getConnectedTools)(context, true);
171
- const wasToolCall = await mcpServerManager.handlePostMessage(req, resp, connectedTools);
172
- if (wasToolCall) return { noWebhookResponse: true, workflowData: [[{ json: {} }]] };
178
+ if (req.method === "DELETE") {
179
+ await mcpServerManager.handleDeleteRequest(req, resp);
173
180
  } else {
174
- await mcpServerManager.createServerWithStreamableHTTPTransport(serverName, resp, req);
181
+ const sessionId = mcpServerManager.getSessionId(req);
182
+ if (sessionId && mcpServerManager.getTransport(sessionId)) {
183
+ const connectedTools = await (0, import_helpers.getConnectedTools)(context, true);
184
+ const wasToolCall = await mcpServerManager.handlePostMessage(req, resp, connectedTools);
185
+ if (wasToolCall) return { noWebhookResponse: true, workflowData: [[{ json: {} }]] };
186
+ } else {
187
+ await mcpServerManager.createServerWithStreamableHTTPTransport(serverName, resp, req);
188
+ }
175
189
  }
176
190
  return { noWebhookResponse: true };
177
191
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/mcp/McpTrigger/McpTrigger.node.ts"],"sourcesContent":["import { WebhookAuthorizationError } from 'n8n-nodes-base/dist/nodes/Webhook/error';\nimport { validateWebhookAuthentication } from 'n8n-nodes-base/dist/nodes/Webhook/utils';\nimport type { INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';\nimport { NodeConnectionTypes, Node } from 'n8n-workflow';\n\nimport { getConnectedTools, nodeNameToToolName } from '@utils/helpers';\n\nimport type { CompressionResponse } from './FlushingTransport';\nimport { McpServerManager } from './McpServer';\n\nconst MCP_SSE_SETUP_PATH = 'sse';\nconst MCP_SSE_MESSAGES_PATH = 'messages';\n\nexport class McpTrigger extends Node {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MCP Server Trigger',\n\t\tname: 'mcpTrigger',\n\t\ticon: {\n\t\t\tlight: 'file:../mcp.svg',\n\t\t\tdark: 'file:../mcp.dark.svg',\n\t\t},\n\t\tgroup: ['trigger'],\n\t\tversion: [1, 1.1, 2],\n\t\tdescription: 'Expose n8n tools as an MCP Server endpoint',\n\t\tactivationMessage:\n\t\t\t'You can now connect your MCP Clients to the URL, using SSE or Streamable HTTP transports.',\n\t\tdefaults: {\n\t\t\tname: 'MCP Server Trigger',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI', 'Core Nodes'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Root Nodes', 'Model Context Protocol'],\n\t\t\t\t'Core Nodes': ['Other Trigger Nodes'],\n\t\t\t},\n\t\t\talias: ['Model Context Protocol', 'MCP Server'],\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.mcptrigger/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\ttriggerPanel: {\n\t\t\theader: 'Listen for MCP events',\n\t\t\texecutionsHelp: {\n\t\t\t\tinactive:\n\t\t\t\t\t\"This trigger has two modes: test and production.<br /><br /><b>Use test mode while you build your workflow</b>. Click the 'execute step' button, then make an MCP request to the test URL. The executions will show up in the editor.<br /><br /><b>Use production mode to run your workflow automatically</b>. <a data-key='activate'>Activate</a> the workflow, then make requests to the production URL. These executions will show up in the <a data-key='executions'>executions list</a>, but not the editor.\",\n\t\t\t\tactive:\n\t\t\t\t\t\"This trigger has two modes: test and production.<br /><br /><b>Use test mode while you build your workflow</b>. Click the 'execute step' button, then make an MCP request to the test URL. The executions will show up in the editor.<br /><br /><b>Use production mode to run your workflow automatically</b>. Since your workflow is activated, you can make requests to the production URL. These executions will show up in the <a data-key='executions'>executions list</a>, but not the editor.\",\n\t\t\t},\n\t\t\tactivationHint:\n\t\t\t\t'Once you’ve finished building your workflow, run it without having to click this button by using the production URL.',\n\t\t},\n\t\tinputs: [\n\t\t\t{\n\t\t\t\ttype: NodeConnectionTypes.AiTool,\n\t\t\t\tdisplayName: 'Tools',\n\t\t\t},\n\t\t],\n\t\toutputs: [],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed\n\t\t\t\tname: 'httpBearerAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['bearerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'httpHeaderAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['headerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{ name: 'None', value: 'none' },\n\t\t\t\t\t{ name: 'Bearer Auth', value: 'bearerAuth' },\n\t\t\t\t\t{ name: 'Header Auth', value: 'headerAuth' },\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Path',\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'webhook',\n\t\t\t\trequired: true,\n\t\t\t\tdescription: 'The base path for this MCP server',\n\t\t\t},\n\t\t],\n\t\twebhooks: [\n\t\t\t{\n\t\t\t\tname: 'setup',\n\t\t\t\thttpMethod: 'GET',\n\t\t\t\tresponseMode: 'onReceived',\n\t\t\t\tisFullPath: true,\n\t\t\t\tpath: `={{$parameter[\"path\"]}}{{parseFloat($nodeVersion)<2 ? '/${MCP_SSE_SETUP_PATH}' : ''}}`,\n\t\t\t\tnodeType: 'mcp',\n\t\t\t\tndvHideMethod: true,\n\t\t\t\tndvHideUrl: false,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'default',\n\t\t\t\thttpMethod: 'POST',\n\t\t\t\tresponseMode: 'onReceived',\n\t\t\t\tisFullPath: true,\n\t\t\t\tpath: `={{$parameter[\"path\"]}}{{parseFloat($nodeVersion)<2 ? '/${MCP_SSE_MESSAGES_PATH}' : ''}}`,\n\t\t\t\tnodeType: 'mcp',\n\t\t\t\tndvHideMethod: true,\n\t\t\t\tndvHideUrl: true,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync webhook(context: IWebhookFunctions): Promise<IWebhookResponseData> {\n\t\tconst webhookName = context.getWebhookName();\n\t\tconst req = context.getRequestObject();\n\t\tconst resp = context.getResponseObject() as unknown as CompressionResponse;\n\n\t\ttry {\n\t\t\tawait validateWebhookAuthentication(context, 'authentication');\n\t\t} catch (error) {\n\t\t\tif (error instanceof WebhookAuthorizationError) {\n\t\t\t\tresp.writeHead(error.responseCode);\n\t\t\t\tresp.end(error.message);\n\t\t\t\treturn { noWebhookResponse: true };\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tconst node = context.getNode();\n\t\t// Get a url/tool friendly name for the server, based on the node name\n\t\tconst serverName = node.typeVersion > 1 ? nodeNameToToolName(node) : 'n8n-mcp-server';\n\n\t\tconst mcpServerManager: McpServerManager = McpServerManager.instance(context.logger);\n\n\t\tif (webhookName === 'setup') {\n\t\t\t// Sets up the transport and opens the long-lived connection. This resp\n\t\t\t// will stay streaming, and is the channel that sends the events\n\n\t\t\t// Prior to version 2.0, we use different paths for the setup and messages.\n\t\t\tconst postUrl =\n\t\t\t\tnode.typeVersion < 2\n\t\t\t\t\t? req.path.replace(new RegExp(`/${MCP_SSE_SETUP_PATH}$`), `/${MCP_SSE_MESSAGES_PATH}`)\n\t\t\t\t\t: req.path;\n\t\t\tawait mcpServerManager.createServerWithSSETransport(serverName, postUrl, resp);\n\n\t\t\treturn { noWebhookResponse: true };\n\t\t} else if (webhookName === 'default') {\n\t\t\t// Here we handle POST requests. These can be either\n\t\t\t// 1) Client calls in an established session using the SSE transport, or\n\t\t\t// 2) Client calls in an established session using the StreamableHTTPServerTransport\n\t\t\t// 3) Session setup requests using the StreamableHTTPServerTransport\n\n\t\t\t// Check if there is a session and a transport is already established\n\t\t\tconst sessionId = mcpServerManager.getSessionId(req);\n\t\t\tif (sessionId && mcpServerManager.getTransport(sessionId)) {\n\t\t\t\tconst connectedTools = await getConnectedTools(context, true);\n\t\t\t\tconst wasToolCall = await mcpServerManager.handlePostMessage(req, resp, connectedTools);\n\t\t\t\tif (wasToolCall) return { noWebhookResponse: true, workflowData: [[{ json: {} }]] };\n\t\t\t} else {\n\t\t\t\t// If no session is established, this is a setup request\n\t\t\t\t// for the StreamableHTTPServerTransport, so we create a new transport\n\t\t\t\tawait mcpServerManager.createServerWithStreamableHTTPTransport(serverName, resp, req);\n\t\t\t}\n\t\t\treturn { noWebhookResponse: true };\n\t\t}\n\n\t\treturn { workflowData: [[{ json: {} }]] };\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0C;AAC1C,mBAA8C;AAE9C,0BAA0C;AAE1C,qBAAsD;AAGtD,uBAAiC;AAEjC,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAEvB,MAAM,mBAAmB,yBAAK;AAAA,EAA9B;AAAA;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,MACP;AAAA,MACA,OAAO,CAAC,SAAS;AAAA,MACjB,SAAS,CAAC,GAAG,KAAK,CAAC;AAAA,MACnB,aAAa;AAAA,MACb,mBACC;AAAA,MACD,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,MAAM,YAAY;AAAA,QAC/B,eAAe;AAAA,UACd,IAAI,CAAC,cAAc,wBAAwB;AAAA,UAC3C,cAAc,CAAC,qBAAqB;AAAA,QACrC;AAAA,QACA,OAAO,CAAC,0BAA0B,YAAY;AAAA,QAC9C,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,cAAc;AAAA,QACb,QAAQ;AAAA,QACR,gBAAgB;AAAA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AAG;AAAA,MACrF;AACA,aAAO,EAAE,mBAAmB,KAAK;AAAA,IAClC;AAEA,WAAO,EAAE,cAAc,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE;AAAA,EACzC;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/mcp/McpTrigger/McpTrigger.node.ts"],"sourcesContent":["import { WebhookAuthorizationError } from 'n8n-nodes-base/dist/nodes/Webhook/error';\nimport { validateWebhookAuthentication } from 'n8n-nodes-base/dist/nodes/Webhook/utils';\nimport type { INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';\nimport { NodeConnectionTypes, Node } from 'n8n-workflow';\n\nimport { getConnectedTools, nodeNameToToolName } from '@utils/helpers';\n\nimport type { CompressionResponse } from './FlushingTransport';\nimport { McpServerManager } from './McpServer';\n\nconst MCP_SSE_SETUP_PATH = 'sse';\nconst MCP_SSE_MESSAGES_PATH = 'messages';\n\nexport class McpTrigger extends Node {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'MCP Server Trigger',\n\t\tname: 'mcpTrigger',\n\t\ticon: {\n\t\t\tlight: 'file:../mcp.svg',\n\t\t\tdark: 'file:../mcp.dark.svg',\n\t\t},\n\t\tgroup: ['trigger'],\n\t\tversion: [1, 1.1, 2],\n\t\tdescription: 'Expose n8n tools as an MCP Server endpoint',\n\t\tactivationMessage:\n\t\t\t'You can now connect your MCP Clients to the URL, using SSE or Streamable HTTP transports.',\n\t\tdefaults: {\n\t\t\tname: 'MCP Server Trigger',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI', 'Core Nodes'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Root Nodes', 'Model Context Protocol'],\n\t\t\t\t'Core Nodes': ['Other Trigger Nodes'],\n\t\t\t},\n\t\t\talias: ['Model Context Protocol', 'MCP Server'],\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.mcptrigger/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\ttriggerPanel: {\n\t\t\theader: 'Listen for MCP events',\n\t\t\texecutionsHelp: {\n\t\t\t\tinactive:\n\t\t\t\t\t\"This trigger has two modes: test and production.<br /><br /><b>Use test mode while you build your workflow</b>. Click the 'execute step' button, then make an MCP request to the test URL. The executions will show up in the editor.<br /><br /><b>Use production mode to run your workflow automatically</b>. <a data-key='activate'>Activate</a> the workflow, then make requests to the production URL. These executions will show up in the <a data-key='executions'>executions list</a>, but not the editor.\",\n\t\t\t\tactive:\n\t\t\t\t\t\"This trigger has two modes: test and production.<br /><br /><b>Use test mode while you build your workflow</b>. Click the 'execute step' button, then make an MCP request to the test URL. The executions will show up in the editor.<br /><br /><b>Use production mode to run your workflow automatically</b>. Since your workflow is activated, you can make requests to the production URL. These executions will show up in the <a data-key='executions'>executions list</a>, but not the editor.\",\n\t\t\t},\n\t\t\tactivationHint:\n\t\t\t\t'Once you’ve finished building your workflow, run it without having to click this button by using the production URL.',\n\t\t},\n\t\tinputs: [\n\t\t\t{\n\t\t\t\ttype: NodeConnectionTypes.AiTool,\n\t\t\t\tdisplayName: 'Tools',\n\t\t\t},\n\t\t],\n\t\toutputs: [],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-credentials-name-unsuffixed\n\t\t\t\tname: 'httpBearerAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['bearerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'httpHeaderAuth',\n\t\t\t\trequired: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tauthentication: ['headerAuth'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Authentication',\n\t\t\t\tname: 'authentication',\n\t\t\t\ttype: 'options',\n\t\t\t\toptions: [\n\t\t\t\t\t{ name: 'None', value: 'none' },\n\t\t\t\t\t{ name: 'Bearer Auth', value: 'bearerAuth' },\n\t\t\t\t\t{ name: 'Header Auth', value: 'headerAuth' },\n\t\t\t\t],\n\t\t\t\tdefault: 'none',\n\t\t\t\tdescription: 'The way to authenticate',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Path',\n\t\t\t\tname: 'path',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '',\n\t\t\t\tplaceholder: 'webhook',\n\t\t\t\trequired: true,\n\t\t\t\tdescription: 'The base path for this MCP server',\n\t\t\t},\n\t\t],\n\t\twebhooks: [\n\t\t\t{\n\t\t\t\tname: 'setup',\n\t\t\t\thttpMethod: 'GET',\n\t\t\t\tresponseMode: 'onReceived',\n\t\t\t\tisFullPath: true,\n\t\t\t\tpath: `={{$parameter[\"path\"]}}{{parseFloat($nodeVersion)<2 ? '/${MCP_SSE_SETUP_PATH}' : ''}}`,\n\t\t\t\tnodeType: 'mcp',\n\t\t\t\tndvHideMethod: true,\n\t\t\t\tndvHideUrl: false,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'default',\n\t\t\t\thttpMethod: 'POST',\n\t\t\t\tresponseMode: 'onReceived',\n\t\t\t\tisFullPath: true,\n\t\t\t\tpath: `={{$parameter[\"path\"]}}{{parseFloat($nodeVersion)<2 ? '/${MCP_SSE_MESSAGES_PATH}' : ''}}`,\n\t\t\t\tnodeType: 'mcp',\n\t\t\t\tndvHideMethod: true,\n\t\t\t\tndvHideUrl: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'default',\n\t\t\t\thttpMethod: 'DELETE',\n\t\t\t\tresponseMode: 'onReceived',\n\t\t\t\tisFullPath: true,\n\t\t\t\tpath: '={{$parameter[\"path\"]}}',\n\t\t\t\tnodeType: 'mcp',\n\t\t\t\tndvHideMethod: true,\n\t\t\t\tndvHideUrl: true,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync webhook(context: IWebhookFunctions): Promise<IWebhookResponseData> {\n\t\tconst webhookName = context.getWebhookName();\n\t\tconst req = context.getRequestObject();\n\t\tconst resp = context.getResponseObject() as unknown as CompressionResponse;\n\n\t\ttry {\n\t\t\tawait validateWebhookAuthentication(context, 'authentication');\n\t\t} catch (error) {\n\t\t\tif (error instanceof WebhookAuthorizationError) {\n\t\t\t\tresp.writeHead(error.responseCode);\n\t\t\t\tresp.end(error.message);\n\t\t\t\treturn { noWebhookResponse: true };\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tconst node = context.getNode();\n\t\t// Get a url/tool friendly name for the server, based on the node name\n\t\tconst serverName = node.typeVersion > 1 ? nodeNameToToolName(node) : 'n8n-mcp-server';\n\n\t\tconst mcpServerManager: McpServerManager = McpServerManager.instance(context.logger);\n\n\t\tif (webhookName === 'setup') {\n\t\t\t// Sets up the transport and opens the long-lived connection. This resp\n\t\t\t// will stay streaming, and is the channel that sends the events\n\n\t\t\t// Prior to version 2.0, we use different paths for the setup and messages.\n\t\t\tconst postUrl =\n\t\t\t\tnode.typeVersion < 2\n\t\t\t\t\t? req.path.replace(new RegExp(`/${MCP_SSE_SETUP_PATH}$`), `/${MCP_SSE_MESSAGES_PATH}`)\n\t\t\t\t\t: req.path;\n\t\t\tawait mcpServerManager.createServerWithSSETransport(serverName, postUrl, resp);\n\n\t\t\treturn { noWebhookResponse: true };\n\t\t} else if (webhookName === 'default') {\n\t\t\t// Here we handle POST and DELETE requests.\n\t\t\t// POST can be either:\n\t\t\t// 1) Client calls in an established session using the SSE transport, or\n\t\t\t// 2) Client calls in an established session using the StreamableHTTPServerTransport\n\t\t\t// 3) Session setup requests using the StreamableHTTPServerTransport\n\t\t\t// DELETE is used to terminate the session using the StreamableHTTPServerTransport\n\n\t\t\tif (req.method === 'DELETE') {\n\t\t\t\tawait mcpServerManager.handleDeleteRequest(req, resp);\n\t\t\t} else {\n\t\t\t\t// Check if there is a session and a transport is already established\n\t\t\t\tconst sessionId = mcpServerManager.getSessionId(req);\n\n\t\t\t\tif (sessionId && mcpServerManager.getTransport(sessionId)) {\n\t\t\t\t\tconst connectedTools = await getConnectedTools(context, true);\n\t\t\t\t\tconst wasToolCall = await mcpServerManager.handlePostMessage(req, resp, connectedTools);\n\t\t\t\t\tif (wasToolCall) return { noWebhookResponse: true, workflowData: [[{ json: {} }]] };\n\t\t\t\t} else {\n\t\t\t\t\t// If no session is established, this is a setup request\n\t\t\t\t\t// for the StreamableHTTPServerTransport, so we create a new transport\n\t\t\t\t\tawait mcpServerManager.createServerWithStreamableHTTPTransport(serverName, resp, req);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { noWebhookResponse: true };\n\t\t}\n\n\t\treturn { workflowData: [[{ json: {} }]] };\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0C;AAC1C,mBAA8C;AAE9C,0BAA0C;AAE1C,qBAAsD;AAGtD,uBAAiC;AAEjC,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAEvB,MAAM,mBAAmB,yBAAK;AAAA,EAA9B;AAAA;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,QACL,OAAO;AAAA,QACP,MAAM;AAAA,MACP;AAAA,MACA,OAAO,CAAC,SAAS;AAAA,MACjB,SAAS,CAAC,GAAG,KAAK,CAAC;AAAA,MACnB,aAAa;AAAA,MACb,mBACC;AAAA,MACD,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,MAAM,YAAY;AAAA,QAC/B,eAAe;AAAA,UACd,IAAI,CAAC,cAAc,wBAAwB;AAAA,UAC3C,cAAc,CAAC,qBAAqB;AAAA,QACrC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gB,WAAW;AAQrC,UAAI,IAAI,WAAW,UAAU;AAC5B,cAAM,iBAAiB,oBAAoB,KAAK,IAAI;AAAA,MACrD,OAAO;AAEN,cAAM,YAAY,iBAAiB,aAAa,GAAG;AAEnD,YAAI,aAAa,iBAAiB,aAAa,SAAS,GAAG;AAC1D,gBAAM,iBAAiB,UAAM,kCAAkB,SAAS,IAAI;AAC5D,gBAAM,cAAc,MAAM,iBAAiB,kBAAkB,KAAK,MAAM,cAAc;AACtF,cAAI,YAAa,QAAO,EAAE,mBAAmB,MAAM,cAAc,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE;AAAA,QACnF,OAAO;AAGN,gBAAM,iBAAiB,wCAAwC,YAAY,MAAM,GAAG;AAAA,QACrF;AAAA,MACD;AAEA,aAAO,EAAE,mBAAmB,KAAK;AAAA,IAClC;AAEA,WAAO,EAAE,cAAc,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE;AAAA,EACzC;AACD;","names":[]}
@@ -21,10 +21,10 @@ __export(TextSplitterTokenSplitter_node_exports, {
21
21
  TextSplitterTokenSplitter: () => TextSplitterTokenSplitter
22
22
  });
23
23
  module.exports = __toCommonJS(TextSplitterTokenSplitter_node_exports);
24
- var import_textsplitters = require("@langchain/textsplitters");
25
24
  var import_n8n_workflow = require("n8n-workflow");
26
25
  var import_logWrapper = require("../../../utils/logWrapper");
27
26
  var import_sharedFields = require("../../../utils/sharedFields");
27
+ var import_TokenTextSplitter = require("./TokenTextSplitter");
28
28
  class TextSplitterTokenSplitter {
29
29
  constructor() {
30
30
  this.description = {
@@ -77,16 +77,13 @@ class TextSplitterTokenSplitter {
77
77
  this.logger.debug("Supply Data for Text Splitter");
78
78
  const chunkSize = this.getNodeParameter("chunkSize", itemIndex);
79
79
  const chunkOverlap = this.getNodeParameter("chunkOverlap", itemIndex);
80
- const splitter = new import_textsplitters.TokenTextSplitter({
80
+ const splitter = new import_TokenTextSplitter.TokenTextSplitter({
81
81
  chunkSize,
82
82
  chunkOverlap,
83
83
  allowedSpecial: "all",
84
84
  disallowedSpecial: "all",
85
85
  encodingName: "cl100k_base",
86
86
  keepSeparator: false
87
- // allowedSpecial: 'all',
88
- // disallowedSpecial: 'all',
89
- // encodingName: 'cl100k_base',
90
87
  });
91
88
  return {
92
89
  response: (0, import_logWrapper.logWrapper)(splitter, this)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport { TokenTextSplitter } from '@langchain/textsplitters';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nexport class TextSplitterTokenSplitter implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Token Splitter',\n\t\tname: 'textSplitterTokenSplitter',\n\t\ticon: 'fa:grip-lines-vertical',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Split text into chunks by tokens',\n\t\tdefaults: {\n\t\t\tname: 'Token Splitter',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Text Splitters'],\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.textsplittertokensplitter/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiTextSplitter],\n\t\toutputNames: ['Text Splitter'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiDocument]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Chunk Size',\n\t\t\t\tname: 'chunkSize',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 1000,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Chunk Overlap',\n\t\t\t\tname: 'chunkOverlap',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 0,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supply Data for Text Splitter');\n\n\t\tconst chunkSize = this.getNodeParameter('chunkSize', itemIndex) as number;\n\t\tconst chunkOverlap = this.getNodeParameter('chunkOverlap', itemIndex) as number;\n\n\t\tconst splitter = new TokenTextSplitter({\n\t\t\tchunkSize,\n\t\t\tchunkOverlap,\n\t\t\tallowedSpecial: 'all',\n\t\t\tdisallowedSpecial: 'all',\n\t\t\tencodingName: 'cl100k_base',\n\t\t\tkeepSeparator: false,\n\t\t\t// allowedSpecial: 'all',\n\t\t\t// disallowedSpecial: 'all',\n\t\t\t// encodingName: 'cl100k_base',\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(splitter, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAAkC;AAClC,0BAMO;AAEP,wBAA2B;AAC3B,0BAA6C;AAEtC,MAAM,0BAA+C;AAAA,EAArD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,gBAAgB;AAAA,QACtB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA;AAAA,MAEA,QAAQ,CAAC;AAAA;AAAA,MAET,SAAS,CAAC,wCAAoB,cAAc;AAAA,MAC5C,aAAa,CAAC,eAAe;AAAA,MAC7B,YAAY;AAAA,YACX,kDAA6B,CAAC,wCAAoB,UAAU,CAAC;AAAA,QAC7D;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,QACV;AAAA,QACA;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,SAAK,OAAO,MAAM,+BAA+B;AAEjD,UAAM,YAAY,KAAK,iBAAiB,aAAa,SAAS;AAC9D,UAAM,eAAe,KAAK,iBAAiB,gBAAgB,SAAS;AAEpE,UAAM,WAAW,IAAI,uCAAkB;AAAA,MACtC;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,MAChB,mBAAmB;AAAA,MACnB,cAAc;AAAA,MACd,eAAe;AAAA;AAAA;AAAA;AAAA,IAIhB,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,UAAU,IAAI;AAAA,IACpC;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { TokenTextSplitter } from './TokenTextSplitter';\n\nexport class TextSplitterTokenSplitter implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Token Splitter',\n\t\tname: 'textSplitterTokenSplitter',\n\t\ticon: 'fa:grip-lines-vertical',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Split text into chunks by tokens',\n\t\tdefaults: {\n\t\t\tname: 'Token Splitter',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Text Splitters'],\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.textsplittertokensplitter/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [NodeConnectionTypes.AiTextSplitter],\n\t\toutputNames: ['Text Splitter'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiDocument]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Chunk Size',\n\t\t\t\tname: 'chunkSize',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 1000,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Chunk Overlap',\n\t\t\t\tname: 'chunkOverlap',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 0,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tthis.logger.debug('Supply Data for Text Splitter');\n\n\t\tconst chunkSize = this.getNodeParameter('chunkSize', itemIndex) as number;\n\t\tconst chunkOverlap = this.getNodeParameter('chunkOverlap', itemIndex) as number;\n\n\t\tconst splitter = new TokenTextSplitter({\n\t\t\tchunkSize,\n\t\t\tchunkOverlap,\n\t\t\tallowedSpecial: 'all',\n\t\t\tdisallowedSpecial: 'all',\n\t\t\tencodingName: 'cl100k_base',\n\t\t\tkeepSeparator: false,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(splitter, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAMO;AAEP,wBAA2B;AAC3B,0BAA6C;AAE7C,+BAAkC;AAE3B,MAAM,0BAA+C;AAAA,EAArD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,gBAAgB;AAAA,QACtB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA;AAAA,MAEA,QAAQ,CAAC;AAAA;AAAA,MAET,SAAS,CAAC,wCAAoB,cAAc;AAAA,MAC5C,aAAa,CAAC,eAAe;AAAA,MAC7B,YAAY;AAAA,YACX,kDAA6B,CAAC,wCAAoB,UAAU,CAAC;AAAA,QAC7D;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,QACV;AAAA,QACA;AAAA,UACC,aAAa;AAAA,UACb,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAAA;AAAA,EAEA,MAAM,WAAuC,WAAwC;AACpF,SAAK,OAAO,MAAM,+BAA+B;AAEjD,UAAM,YAAY,KAAK,iBAAiB,aAAa,SAAS;AAC9D,UAAM,eAAe,KAAK,iBAAiB,gBAAgB,SAAS;AAEpE,UAAM,WAAW,IAAI,2CAAkB;AAAA,MACtC;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,MAChB,mBAAmB;AAAA,MACnB,cAAc;AAAA,MACd,eAAe;AAAA,IAChB,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,UAAU,IAAI;AAAA,IACpC;AAAA,EACD;AACD;","names":[]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var TokenTextSplitter_exports = {};
20
+ __export(TokenTextSplitter_exports, {
21
+ TokenTextSplitter: () => TokenTextSplitter
22
+ });
23
+ module.exports = __toCommonJS(TokenTextSplitter_exports);
24
+ var import_textsplitters = require("@langchain/textsplitters");
25
+ var import_tiktoken = require("../../../utils/tokenizer/tiktoken");
26
+ class TokenTextSplitter extends import_textsplitters.TextSplitter {
27
+ static lc_name() {
28
+ return "TokenTextSplitter";
29
+ }
30
+ constructor(fields) {
31
+ super(fields);
32
+ this.encodingName = fields?.encodingName ?? "cl100k_base";
33
+ this.allowedSpecial = fields?.allowedSpecial ?? [];
34
+ this.disallowedSpecial = fields?.disallowedSpecial ?? "all";
35
+ }
36
+ async splitText(text) {
37
+ if (!this.tokenizer) {
38
+ this.tokenizer = await (0, import_tiktoken.getEncoding)(this.encodingName);
39
+ }
40
+ const splits = [];
41
+ const input_ids = this.tokenizer.encode(text, this.allowedSpecial, this.disallowedSpecial);
42
+ let start_idx = 0;
43
+ while (start_idx < input_ids.length) {
44
+ if (start_idx > 0) {
45
+ start_idx -= this.chunkOverlap;
46
+ }
47
+ const end_idx = Math.min(start_idx + this.chunkSize, input_ids.length);
48
+ const chunk_ids = input_ids.slice(start_idx, end_idx);
49
+ splits.push(this.tokenizer.decode(chunk_ids));
50
+ start_idx = end_idx;
51
+ }
52
+ return splits;
53
+ }
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ TokenTextSplitter
58
+ });
59
+ //# sourceMappingURL=TokenTextSplitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../nodes/text_splitters/TextSplitterTokenSplitter/TokenTextSplitter.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { TokenTextSplitterParams } from '@langchain/textsplitters';\nimport { TextSplitter } from '@langchain/textsplitters';\nimport type * as tiktoken from 'js-tiktoken';\n\nimport { getEncoding } from '@utils/tokenizer/tiktoken';\n\n/**\n * Implementation of splitter which looks at tokens.\n * This is override of the LangChain TokenTextSplitter\n * to use the n8n tokenizer utility which uses local JSON encodings\n */\nexport class TokenTextSplitter extends TextSplitter implements TokenTextSplitterParams {\n\tstatic lc_name() {\n\t\treturn 'TokenTextSplitter';\n\t}\n\n\tencodingName: tiktoken.TiktokenEncoding;\n\n\tallowedSpecial: 'all' | string[];\n\n\tdisallowedSpecial: 'all' | string[];\n\n\tprivate tokenizer: tiktoken.Tiktoken | undefined;\n\n\tconstructor(fields?: Partial<TokenTextSplitterParams>) {\n\t\tsuper(fields);\n\n\t\tthis.encodingName = fields?.encodingName ?? 'cl100k_base';\n\t\tthis.allowedSpecial = fields?.allowedSpecial ?? [];\n\t\tthis.disallowedSpecial = fields?.disallowedSpecial ?? 'all';\n\t}\n\n\tasync splitText(text: string): Promise<string[]> {\n\t\tif (!this.tokenizer) {\n\t\t\tthis.tokenizer = await getEncoding(this.encodingName);\n\t\t}\n\n\t\tconst splits: string[] = [];\n\n\t\tconst input_ids = this.tokenizer.encode(text, this.allowedSpecial, this.disallowedSpecial);\n\n\t\tlet start_idx = 0;\n\n\t\twhile (start_idx < input_ids.length) {\n\t\t\tif (start_idx > 0) {\n\t\t\t\tstart_idx -= this.chunkOverlap;\n\t\t\t}\n\t\t\tconst end_idx = Math.min(start_idx + this.chunkSize, input_ids.length);\n\t\t\tconst chunk_ids = input_ids.slice(start_idx, end_idx);\n\t\t\tsplits.push(this.tokenizer.decode(chunk_ids));\n\t\t\tstart_idx = end_idx;\n\t\t}\n\n\t\treturn splits;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,2BAA6B;AAG7B,sBAA4B;AAOrB,MAAM,0BAA0B,kCAAgD;AAAA,EACtF,OAAO,UAAU;AAChB,WAAO;AAAA,EACR;AAAA,EAUA,YAAY,QAA2C;AACtD,UAAM,MAAM;AAEZ,SAAK,eAAe,QAAQ,gBAAgB;AAC5C,SAAK,iBAAiB,QAAQ,kBAAkB,CAAC;AACjD,SAAK,oBAAoB,QAAQ,qBAAqB;AAAA,EACvD;AAAA,EAEA,MAAM,UAAU,MAAiC;AAChD,QAAI,CAAC,KAAK,WAAW;AACpB,WAAK,YAAY,UAAM,6BAAY,KAAK,YAAY;AAAA,IACrD;AAEA,UAAM,SAAmB,CAAC;AAE1B,UAAM,YAAY,KAAK,UAAU,OAAO,MAAM,KAAK,gBAAgB,KAAK,iBAAiB;AAEzF,QAAI,YAAY;AAEhB,WAAO,YAAY,UAAU,QAAQ;AACpC,UAAI,YAAY,GAAG;AAClB,qBAAa,KAAK;AAAA,MACnB;AACA,YAAM,UAAU,KAAK,IAAI,YAAY,KAAK,WAAW,UAAU,MAAM;AACrE,YAAM,YAAY,UAAU,MAAM,WAAW,OAAO;AACpD,aAAO,KAAK,KAAK,UAAU,OAAO,SAAS,CAAC;AAC5C,kBAAY;AAAA,IACb;AAEA,WAAO;AAAA,EACR;AACD;","names":[]}
@@ -18,7 +18,9 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var VectorStoreMongoDBAtlas_node_exports = {};
20
20
  __export(VectorStoreMongoDBAtlas_node_exports, {
21
- VectorStoreMongoDBAtlas: () => VectorStoreMongoDBAtlas
21
+ VectorStoreMongoDBAtlas: () => VectorStoreMongoDBAtlas,
22
+ getMongoClient: () => getMongoClient,
23
+ mongoConfig: () => mongoConfig
22
24
  });
23
25
  module.exports = __toCommonJS(VectorStoreMongoDBAtlas_node_exports);
24
26
  var import_mongodb = require("@langchain/mongodb");
@@ -116,16 +118,24 @@ const insertFields = [
116
118
  ]
117
119
  }
118
120
  ];
119
- let mongoClient = null;
121
+ const mongoConfig = {
122
+ client: null,
123
+ connectionString: ""
124
+ };
120
125
  async function getMongoClient(context) {
121
- if (!mongoClient) {
122
- const credentials = await context.getCredentials("mongoDb");
123
- mongoClient = new import_mongodb2.MongoClient(credentials.connectionString, {
126
+ const credentials = await context.getCredentials("mongoDb");
127
+ const connectionString = credentials.connectionString;
128
+ if (!mongoConfig.client || mongoConfig.connectionString !== connectionString) {
129
+ if (mongoConfig.client) {
130
+ await mongoConfig.client.close();
131
+ }
132
+ mongoConfig.connectionString = connectionString;
133
+ mongoConfig.client = new import_mongodb2.MongoClient(connectionString, {
124
134
  appName: "devrel.integration.n8n_vector_integ"
125
135
  });
126
- await mongoClient.connect();
136
+ await mongoConfig.client.connect();
127
137
  }
128
- return mongoClient;
138
+ return mongoConfig.client;
129
139
  }
130
140
  async function mongoClientAndDatabase(context) {
131
141
  const client = await getMongoClient(context);
@@ -266,6 +276,8 @@ class VectorStoreMongoDBAtlas extends (0, import_createVectorStoreNode.createVec
266
276
  }
267
277
  // Annotate the CommonJS export names for ESM import in node:
268
278
  0 && (module.exports = {
269
- VectorStoreMongoDBAtlas
279
+ VectorStoreMongoDBAtlas,
280
+ getMongoClient,
281
+ mongoConfig
270
282
  });
271
283
  //# sourceMappingURL=VectorStoreMongoDBAtlas.node.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.ts"],"sourcesContent":["import { MongoDBAtlasVectorSearch } from '@langchain/mongodb';\nimport { MongoClient } from 'mongodb';\nimport { type ILoadOptionsFunctions, NodeOperationError, type INodeProperties } from 'n8n-workflow';\n\nimport { metadataFilterField } from '@utils/sharedFields';\n\nimport { createVectorStoreNode } from '../shared/createVectorStoreNode/createVectorStoreNode';\n\nconst mongoCollectionRLC: INodeProperties = {\n\tdisplayName: 'MongoDB Collection',\n\tname: 'mongoCollection',\n\ttype: 'resourceLocator',\n\tdefault: { mode: 'list', value: '' },\n\trequired: true,\n\tmodes: [\n\t\t{\n\t\t\tdisplayName: 'From List',\n\t\t\tname: 'list',\n\t\t\ttype: 'list',\n\t\t\ttypeOptions: {\n\t\t\t\tsearchListMethod: 'mongoCollectionSearch', // Method to fetch collections\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tdisplayName: 'Name',\n\t\t\tname: 'name',\n\t\t\ttype: 'string',\n\t\t\tplaceholder: 'e.g. my_collection',\n\t\t},\n\t],\n};\n\nconst vectorIndexName: INodeProperties = {\n\tdisplayName: 'Vector Index Name',\n\tname: 'vectorIndexName',\n\ttype: 'string',\n\tdefault: '',\n\tdescription: 'The name of the vector index',\n\trequired: true,\n};\n\nconst embeddingField: INodeProperties = {\n\tdisplayName: 'Embedding',\n\tname: 'embedding',\n\ttype: 'string',\n\tdefault: 'embedding',\n\tdescription: 'The field with the embedding array',\n\trequired: true,\n};\n\nconst metadataField: INodeProperties = {\n\tdisplayName: 'Metadata Field',\n\tname: 'metadata_field',\n\ttype: 'string',\n\tdefault: 'text',\n\tdescription: 'The text field of the raw data',\n\trequired: true,\n};\n\nconst sharedFields: INodeProperties[] = [\n\tmongoCollectionRLC,\n\tembeddingField,\n\tmetadataField,\n\tvectorIndexName,\n];\n\nconst mongoNamespaceField: INodeProperties = {\n\tdisplayName: 'Namespace',\n\tname: 'namespace',\n\ttype: 'string',\n\tdescription: 'Logical partition for documents. Uses metadata.namespace field for filtering.',\n\tdefault: '',\n};\n\nconst retrieveFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [mongoNamespaceField, metadataFilterField],\n\t},\n];\n\nconst insertFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Clear Namespace',\n\t\t\t\tname: 'clearNamespace',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription: 'Whether to clear documents in the namespace before inserting new data',\n\t\t\t},\n\t\t\tmongoNamespaceField,\n\t\t],\n\t},\n];\n\nlet mongoClient: MongoClient | null = null;\n\nasync function getMongoClient(context: any) {\n\tif (!mongoClient) {\n\t\tconst credentials = await context.getCredentials('mongoDb');\n\t\tmongoClient = new MongoClient(credentials.connectionString as string, {\n\t\t\tappName: 'devrel.integration.n8n_vector_integ',\n\t\t});\n\t\tawait mongoClient.connect();\n\t}\n\treturn mongoClient;\n}\n\nasync function mongoClientAndDatabase(context: any) {\n\tconst client = await getMongoClient(context);\n\tconst credentials = await context.getCredentials('mongoDb');\n\tconst db = client.db(credentials.database as string);\n\treturn { client, db };\n}\n\nasync function mongoCollectionSearch(this: ILoadOptionsFunctions) {\n\tconst { db } = await mongoClientAndDatabase(this);\n\ttry {\n\t\tconst collections = await db.listCollections().toArray();\n\t\tconst results = collections.map((collection) => ({\n\t\t\tname: collection.name,\n\t\t\tvalue: collection.name,\n\t\t}));\n\n\t\treturn { results };\n\t} catch (error) {\n\t\tthrow new NodeOperationError(this.getNode(), `Error: ${error.message}`);\n\t}\n}\nexport class VectorStoreMongoDBAtlas extends createVectorStoreNode({\n\tmeta: {\n\t\tdisplayName: 'MongoDB Atlas Vector Store',\n\t\tname: 'vectorStoreMongoDBAtlas',\n\t\tdescription: 'Work with your data in MongoDB Atlas Vector Store',\n\t\ticon: { light: 'file:mongodb.svg', dark: 'file:mongodb.dark.svg' },\n\t\tdocsUrl:\n\t\t\t'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoremongodbatlas/',\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\toperationModes: ['load', 'insert', 'retrieve', 'update', 'retrieve-as-tool'],\n\t},\n\tmethods: { listSearch: { mongoCollectionSearch } },\n\tretrieveFields,\n\tloadFields: retrieveFields,\n\tinsertFields,\n\tsharedFields,\n\tasync getVectorStoreClient(context, _filter, embeddings, itemIndex) {\n\t\ttry {\n\t\t\tconst { db } = await mongoClientAndDatabase(context);\n\t\t\ttry {\n\t\t\t\tconst collectionName = context.getNodeParameter('mongoCollection', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst mongoVectorIndexName = context.getNodeParameter('vectorIndexName', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst embeddingFieldName = context.getNodeParameter('embedding', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst metadataFieldName = context.getNodeParameter('metadata_field', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst collection = db.collection(collectionName);\n\n\t\t\t\t// test index exists\n\t\t\t\tconst indexes = await collection.listSearchIndexes().toArray();\n\n\t\t\t\tconst indexExists = indexes.some((index) => index.name === mongoVectorIndexName);\n\n\t\t\t\tif (!indexExists) {\n\t\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\t\tcontext.getNode(),\n\t\t\t\t\t\t`Index ${mongoVectorIndexName} not found`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\tdescription: 'Please check that the index exists in your collection',\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn new MongoDBAtlasVectorSearch(embeddings, {\n\t\t\t\t\tcollection,\n\t\t\t\t\tindexName: mongoVectorIndexName, // Default index name\n\t\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\t// Don't close the client here to maintain connection pooling\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n\tasync populateVectorStore(context, embeddings, documents, itemIndex) {\n\t\ttry {\n\t\t\tconst { db } = await mongoClientAndDatabase(context);\n\t\t\ttry {\n\t\t\t\tconst mongoCollectionName = context.getNodeParameter('mongoCollection', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\t\t\t\tconst embeddingFieldName = context.getNodeParameter('embedding', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst metadataFieldName = context.getNodeParameter('metadata_field', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst mongoDBAtlasVectorIndex = context.getNodeParameter('vectorIndexName', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\t// Check if collection exists\n\t\t\t\tconst collections = await db.listCollections({ name: mongoCollectionName }).toArray();\n\t\t\t\tif (collections.length === 0) {\n\t\t\t\t\tawait db.createCollection(mongoCollectionName);\n\t\t\t\t}\n\t\t\t\tconst collection = db.collection(mongoCollectionName);\n\t\t\t\tawait MongoDBAtlasVectorSearch.fromDocuments(documents, embeddings, {\n\t\t\t\t\tcollection,\n\t\t\t\t\tindexName: mongoDBAtlasVectorIndex, // Default index name\n\t\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\t// Don't close the client here to maintain connection pooling\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n}) {}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAyC;AACzC,IAAAA,kBAA4B;AAC5B,0BAAqF;AAErF,0BAAoC;AAEp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O;AACf,YAAM,IAAI,uCAAmB,QAAQ,QAAQ,GAAG,UAAU,MAAM,OAAO,IAAI;AAAA,QAC1E;AAAA,QACA,aAAa;AAAA,MACd,CAAC;AAAA,IACF;AAAA,EACD;AACD,CAAC,EAAE;AAAC;","names":["import_mongodb"]}
1
+ {"version":3,"sources":["../../../../nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.ts"],"sourcesContent":["import { MongoDBAtlasVectorSearch } from '@langchain/mongodb';\nimport { MongoClient } from 'mongodb';\nimport { type ILoadOptionsFunctions, NodeOperationError, type INodeProperties } from 'n8n-workflow';\n\nimport { metadataFilterField } from '@utils/sharedFields';\n\nimport { createVectorStoreNode } from '../shared/createVectorStoreNode/createVectorStoreNode';\n\nconst mongoCollectionRLC: INodeProperties = {\n\tdisplayName: 'MongoDB Collection',\n\tname: 'mongoCollection',\n\ttype: 'resourceLocator',\n\tdefault: { mode: 'list', value: '' },\n\trequired: true,\n\tmodes: [\n\t\t{\n\t\t\tdisplayName: 'From List',\n\t\t\tname: 'list',\n\t\t\ttype: 'list',\n\t\t\ttypeOptions: {\n\t\t\t\tsearchListMethod: 'mongoCollectionSearch', // Method to fetch collections\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tdisplayName: 'Name',\n\t\t\tname: 'name',\n\t\t\ttype: 'string',\n\t\t\tplaceholder: 'e.g. my_collection',\n\t\t},\n\t],\n};\n\nconst vectorIndexName: INodeProperties = {\n\tdisplayName: 'Vector Index Name',\n\tname: 'vectorIndexName',\n\ttype: 'string',\n\tdefault: '',\n\tdescription: 'The name of the vector index',\n\trequired: true,\n};\n\nconst embeddingField: INodeProperties = {\n\tdisplayName: 'Embedding',\n\tname: 'embedding',\n\ttype: 'string',\n\tdefault: 'embedding',\n\tdescription: 'The field with the embedding array',\n\trequired: true,\n};\n\nconst metadataField: INodeProperties = {\n\tdisplayName: 'Metadata Field',\n\tname: 'metadata_field',\n\ttype: 'string',\n\tdefault: 'text',\n\tdescription: 'The text field of the raw data',\n\trequired: true,\n};\n\nconst sharedFields: INodeProperties[] = [\n\tmongoCollectionRLC,\n\tembeddingField,\n\tmetadataField,\n\tvectorIndexName,\n];\n\nconst mongoNamespaceField: INodeProperties = {\n\tdisplayName: 'Namespace',\n\tname: 'namespace',\n\ttype: 'string',\n\tdescription: 'Logical partition for documents. Uses metadata.namespace field for filtering.',\n\tdefault: '',\n};\n\nconst retrieveFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [mongoNamespaceField, metadataFilterField],\n\t},\n];\n\nconst insertFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Clear Namespace',\n\t\t\t\tname: 'clearNamespace',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription: 'Whether to clear documents in the namespace before inserting new data',\n\t\t\t},\n\t\t\tmongoNamespaceField,\n\t\t],\n\t},\n];\n\nexport const mongoConfig = {\n\tclient: null as MongoClient | null,\n\tconnectionString: '',\n};\n\nexport async function getMongoClient(context: any) {\n\tconst credentials = await context.getCredentials('mongoDb');\n\tconst connectionString = credentials.connectionString as string;\n\tif (!mongoConfig.client || mongoConfig.connectionString !== connectionString) {\n\t\tif (mongoConfig.client) {\n\t\t\tawait mongoConfig.client.close();\n\t\t}\n\n\t\tmongoConfig.connectionString = connectionString;\n\t\tmongoConfig.client = new MongoClient(connectionString, {\n\t\t\tappName: 'devrel.integration.n8n_vector_integ',\n\t\t});\n\t\tawait mongoConfig.client.connect();\n\t}\n\treturn mongoConfig.client;\n}\n\nasync function mongoClientAndDatabase(context: any) {\n\tconst client = await getMongoClient(context);\n\tconst credentials = await context.getCredentials('mongoDb');\n\tconst db = client.db(credentials.database as string);\n\treturn { client, db };\n}\n\nasync function mongoCollectionSearch(this: ILoadOptionsFunctions) {\n\tconst { db } = await mongoClientAndDatabase(this);\n\ttry {\n\t\tconst collections = await db.listCollections().toArray();\n\t\tconst results = collections.map((collection) => ({\n\t\t\tname: collection.name,\n\t\t\tvalue: collection.name,\n\t\t}));\n\n\t\treturn { results };\n\t} catch (error) {\n\t\tthrow new NodeOperationError(this.getNode(), `Error: ${error.message}`);\n\t}\n}\nexport class VectorStoreMongoDBAtlas extends createVectorStoreNode({\n\tmeta: {\n\t\tdisplayName: 'MongoDB Atlas Vector Store',\n\t\tname: 'vectorStoreMongoDBAtlas',\n\t\tdescription: 'Work with your data in MongoDB Atlas Vector Store',\n\t\ticon: { light: 'file:mongodb.svg', dark: 'file:mongodb.dark.svg' },\n\t\tdocsUrl:\n\t\t\t'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoremongodbatlas/',\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\toperationModes: ['load', 'insert', 'retrieve', 'update', 'retrieve-as-tool'],\n\t},\n\tmethods: { listSearch: { mongoCollectionSearch } },\n\tretrieveFields,\n\tloadFields: retrieveFields,\n\tinsertFields,\n\tsharedFields,\n\tasync getVectorStoreClient(context, _filter, embeddings, itemIndex) {\n\t\ttry {\n\t\t\tconst { db } = await mongoClientAndDatabase(context);\n\t\t\ttry {\n\t\t\t\tconst collectionName = context.getNodeParameter('mongoCollection', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst mongoVectorIndexName = context.getNodeParameter('vectorIndexName', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst embeddingFieldName = context.getNodeParameter('embedding', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst metadataFieldName = context.getNodeParameter('metadata_field', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst collection = db.collection(collectionName);\n\n\t\t\t\t// test index exists\n\t\t\t\tconst indexes = await collection.listSearchIndexes().toArray();\n\n\t\t\t\tconst indexExists = indexes.some((index) => index.name === mongoVectorIndexName);\n\n\t\t\t\tif (!indexExists) {\n\t\t\t\t\tthrow new NodeOperationError(\n\t\t\t\t\t\tcontext.getNode(),\n\t\t\t\t\t\t`Index ${mongoVectorIndexName} not found`,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\titemIndex,\n\t\t\t\t\t\t\tdescription: 'Please check that the index exists in your collection',\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn new MongoDBAtlasVectorSearch(embeddings, {\n\t\t\t\t\tcollection,\n\t\t\t\t\tindexName: mongoVectorIndexName, // Default index name\n\t\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\t// Don't close the client here to maintain connection pooling\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n\tasync populateVectorStore(context, embeddings, documents, itemIndex) {\n\t\ttry {\n\t\t\tconst { db } = await mongoClientAndDatabase(context);\n\t\t\ttry {\n\t\t\t\tconst mongoCollectionName = context.getNodeParameter('mongoCollection', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\t\t\t\tconst embeddingFieldName = context.getNodeParameter('embedding', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst metadataFieldName = context.getNodeParameter('metadata_field', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\tconst mongoDBAtlasVectorIndex = context.getNodeParameter('vectorIndexName', itemIndex, '', {\n\t\t\t\t\textractValue: true,\n\t\t\t\t}) as string;\n\n\t\t\t\t// Check if collection exists\n\t\t\t\tconst collections = await db.listCollections({ name: mongoCollectionName }).toArray();\n\t\t\t\tif (collections.length === 0) {\n\t\t\t\t\tawait db.createCollection(mongoCollectionName);\n\t\t\t\t}\n\t\t\t\tconst collection = db.collection(mongoCollectionName);\n\t\t\t\tawait MongoDBAtlasVectorSearch.fromDocuments(documents, embeddings, {\n\t\t\t\t\tcollection,\n\t\t\t\t\tindexName: mongoDBAtlasVectorIndex, // Default index name\n\t\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t\t});\n\t\t\t} finally {\n\t\t\t\t// Don't close the client here to maintain connection pooling\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n}) {}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAyC;AACzC,IAAAA,kBAA4B;AAC5B,0BAAqF;AAErF,0BAAoC;AAEpC,mCAAsC;AAEtC,MAAM,qBAAsC;AAA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