UNPKG

n8n-nodes-recallio

Version:

RecallioAI Memory node for n8n

325 lines 12.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Recallio = void 0; const n8n_workflow_1 = require("n8n-workflow"); const RecallioClient_1 = require("../../lib/RecallioClient"); class Recallio { constructor() { this.description = { displayName: 'Recallio', name: 'recallio', icon: 'file:recallio-icon.svg', group: ['transform'], codex: { categories: ['Memory'], subcategories: { Memory: ['Other memories'], } }, version: 1, description: 'Interact with RecallioAI memory API', defaults: { name: 'Recallio', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'recallioApi', required: true, }, ], properties: [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, options: [ { name: 'Clear', value: 'clear', action: 'Clear memories from recallio', }, { name: 'Export', value: 'export', action: 'Export memories from recallio', }, { name: 'Retrieve', value: 'retrieve', action: 'Retrieve memory from recallio', }, { name: 'Retrieve Summary', value: 'retrieveSummary', action: 'Get memory summary from recallio', }, { name: 'Store', value: 'store', action: 'Store memory to recallio', } ], default: 'store', }, { displayName: 'Context', name: 'context', type: 'string', typeOptions: { rows: 4 }, default: '', displayOptions: { show: { operation: ['store'], }, }, }, { displayName: 'User ID', name: 'userId', type: 'string', default: '', required: true, }, { displayName: 'Tags', name: 'tags', type: 'string', default: '', placeholder: 'tag1,tag2', displayOptions: { show: { operation: ['store', 'retrieveSummary', 'retrieve'], }, }, }, { displayName: 'TTL Days', name: 'ttlDays', type: 'number', default: 30, displayOptions: { show: { operation: ['store'], }, }, }, { displayName: 'Query', name: 'query', type: 'string', default: '', displayOptions: { show: { operation: ['retrieve'], }, }, }, { displayName: 'Export Type', name: 'exportType', type: 'options', options: [ { name: 'Facts', value: 'facts', }, { name: 'Memory', value: 'memory', }, { name: 'Graph', value: 'graph', }, ], default: 'facts', displayOptions: { show: { operation: ['export'], }, }, }, { displayName: 'Export Format', name: 'exportFormat', type: 'options', options: [ { name: 'JSON', value: 'json', }, { name: 'CSV', value: 'csv', }, ], default: 'json', displayOptions: { show: { operation: ['export'], }, }, }, { displayName: 'Start Date', name: 'startDate', type: 'dateTime', default: '', displayOptions: { show: { operation: ['export'], }, }, }, { displayName: 'End Date', name: 'endDate', type: 'dateTime', default: '', displayOptions: { show: { operation: ['export'], }, }, }, { displayName: 'Delete Scope', name: 'deleteScope', type: 'options', options: [ { name: 'User', value: 'user', }, { name: 'Project', value: 'project', }, ], default: 'user', displayOptions: { show: { operation: ['clear'], }, }, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const credentials = (await this.getCredentials('recallioApi')); const client = new RecallioClient_1.RecallioClient({ apiKey: credentials.apiKey }, this.helpers.httpRequest); const operation = this.getNodeParameter('operation', 0); for (let i = 0; i < items.length; i++) { try { if (operation === 'store') { const context = this.getNodeParameter('context', i); const userId = this.getNodeParameter('userId', i); const tagsStr = this.getNodeParameter('tags', i, ''); const ttlDays = this.getNodeParameter('ttlDays', i); const tags = tagsStr ? tagsStr.split(',').map(t => t.trim()).filter(Boolean) : undefined; const expiresAt = new Date(Date.now() + ttlDays * 24 * 60 * 60 * 1000).toISOString(); await client.writeMemory({ userId, projectId: 'default', content: context, tags, consentFlag: true, expiresAt: expiresAt, }); returnData.push({ json: { success: true } }); } else if (operation === 'retrieve') { const userId = this.getNodeParameter('userId', i); const query = this.getNodeParameter('query', i); const memories = await client.recallMemory({ userId, projectId: 'default', query, scope: 'user', }, { limit: 3 }); for (const mem of memories) { returnData.push({ json: mem }); } } else if (operation === 'retrieveSummary') { const userId = this.getNodeParameter('userId', i); const tagsStr = this.getNodeParameter('tags', i, ''); const tags = tagsStr ? tagsStr.split(',').map(t => t.trim()).filter(Boolean) : undefined; const summary = await client.recallSummary({ userId, projectId: 'default', tags, scope: 'user', }); returnData.push({ json: summary }); } else if (operation === 'export') { const userId = this.getNodeParameter('userId', i); const exportType = this.getNodeParameter('exportType', i); const exportFormat = this.getNodeParameter('exportFormat', i); const startDate = this.getNodeParameter('startDate', i, ''); const endDate = this.getNodeParameter('endDate', i, ''); const exportParams = { type: exportType, format: exportFormat, userId, projectId: 'default', ...(startDate && { startDate }), ...(endDate && { endDate }), }; const exportData = await client.exportMemory(exportParams); returnData.push({ json: { exportData } }); } else if (operation === 'clear') { const userId = this.getNodeParameter('userId', i); const deleteScope = this.getNodeParameter('deleteScope', i); await client.deleteMemory({ scope: deleteScope, userId, projectId: 'default', }); returnData.push({ json: { success: true, message: `Deleted memories for scope: ${deleteScope}` } }); } else { throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`); } } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message } }); continue; } throw error; } } return [returnData]; } async supplyData(itemIndex) { const credentials = (await this.getCredentials('recallioApi')); const client = new RecallioClient_1.RecallioClient({ apiKey: credentials.apiKey }, this.helpers.httpRequest); const userId = this.getNodeParameter('userId', itemIndex); try { const summary = await client.recallSummary({ userId, projectId: 'default', scope: 'user', }); return { response: summary.content || 'No memories available', }; } catch (error) { return { response: 'Error retrieving memories', }; } } } exports.Recallio = Recallio; //# sourceMappingURL=Recallio.node.js.map