UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

133 lines 5.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryXata = void 0; const xata_1 = require("@langchain/community/stores/message/xata"); const client_1 = require("@xata.io/client"); const memory_1 = require("@langchain/classic/memory"); const n8n_workflow_1 = require("n8n-workflow"); const helpers_1 = require("../../../utils/helpers"); const ai_utilities_1 = require("@n8n/ai-utilities"); const descriptions_1 = require("../descriptions"); class MemoryXata { constructor() { this.description = { displayName: 'Xata', name: 'memoryXata', icon: 'file:xata.svg', group: ['transform'], version: [1, 1.1, 1.2, 1.3, 1.4], description: 'Use Xata Memory', defaults: { name: 'Xata', color: '#1321A7', }, codex: { categories: ['AI'], subcategories: { AI: ['Memory'], Memory: ['Other memories'], }, resources: { primaryDocumentation: [ { url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memoryxata/', }, ], }, }, inputs: [], outputs: [n8n_workflow_1.NodeConnectionTypes.AiMemory], outputNames: ['Memory'], credentials: [ { name: 'xataApi', required: true, }, ], properties: [ (0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiAgent]), { displayName: 'Session ID', name: 'sessionId', type: 'string', required: true, default: '', displayOptions: { show: { '@version': [1], }, }, }, { displayName: 'Session ID', name: 'sessionId', type: 'string', default: '={{ $json.sessionId }}', description: 'The key to use to store the memory', displayOptions: { show: { '@version': [1.1], }, }, }, { ...descriptions_1.sessionIdOption, displayOptions: { show: { '@version': [{ _cnd: { gte: 1.2 } }], }, }, }, descriptions_1.sessionKeyProperty, (0, descriptions_1.expressionSessionKeyProperty)(1.4), { ...descriptions_1.contextWindowLengthProperty, displayOptions: { hide: { '@version': [{ _cnd: { lt: 1.3 } }] } }, }, ], }; } async supplyData(itemIndex) { const credentials = await this.getCredentials('xataApi'); const nodeVersion = this.getNode().typeVersion; let sessionId; if (nodeVersion >= 1.2) { sessionId = (0, helpers_1.getSessionId)(this, itemIndex); } else { sessionId = this.getNodeParameter('sessionId', itemIndex); } const xataClient = new client_1.BaseClient({ apiKey: credentials.apiKey, branch: credentials.branch || 'main', databaseURL: credentials.databaseEndpoint, }); const table = credentials.databaseEndpoint.match(/https:\/\/[^.]+\.[^.]+\.xata\.sh\/db\/([^\/:]+)/); if (table === null) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'It was not possible to extract the table from the Database Endpoint.'); } const chatHistory = new xata_1.XataChatMessageHistory({ table: table[1], sessionId, client: xataClient, apiKey: credentials.apiKey, }); const memClass = this.getNode().typeVersion < 1.3 ? memory_1.BufferMemory : memory_1.BufferWindowMemory; const kOptions = this.getNode().typeVersion < 1.3 ? {} : { k: this.getNodeParameter('contextWindowLength', itemIndex) }; const memory = new memClass({ chatHistory, memoryKey: 'chat_history', returnMessages: true, inputKey: 'input', outputKey: 'output', ...kOptions, }); return { response: (0, ai_utilities_1.logWrapper)(memory, this), }; } } exports.MemoryXata = MemoryXata; //# sourceMappingURL=MemoryXata.node.js.map