n8n-nodes-graphiti
Version:
Graphiti temporal knowledge graph memory for n8n AI agents
145 lines • 6.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GraphitiMemory = void 0;
const uuid_1 = require("uuid");
const GraphitiChatMemory_1 = require("./GraphitiChatMemory");
class GraphitiMemory {
constructor() {
this.description = {
displayName: 'Graphiti Memory',
name: 'graphitiMemory',
icon: 'file:graphiti-memory.svg',
group: ['transform'],
version: 1,
description: 'Graphiti temporal knowledge graph memory for AI agents',
defaults: {
name: 'Graphiti Memory',
},
codex: {
categories: ['AI'],
subcategories: {
AI: ['Memory'],
},
resources: {
primaryDocumentation: [
{
url: 'https://github.com/GoGoButters/Graphiti_n8n_node',
},
],
},
},
inputs: [],
outputs: ['ai_memory'],
outputNames: ['Memory'],
credentials: [
{
name: 'graphitiApi',
required: true,
},
],
properties: [
{
displayName: 'Session ID Type',
name: 'sessionIdType',
type: 'options',
options: [
{
name: 'Take From Previous Node Automatically',
value: 'fromInput',
description: 'Use sessionId from the input data',
},
{
name: 'Define Below',
value: 'customKey',
description: 'Use a custom session key expression',
},
],
default: 'fromInput',
description: 'How to determine the session ID for the user',
},
{
displayName: 'Session Key',
name: 'sessionKey',
type: 'string',
default: '={{ $json.sessionId }}',
description: 'The key to use to store session ID. Can be an expression. If empty or not found, a random ID will be generated.',
displayOptions: {
show: {
sessionIdType: ['customKey'],
},
},
},
{
displayName: 'Context Window Length',
name: 'contextWindowLength',
type: 'number',
default: 5,
description: 'Number of recent messages to keep in short-term memory',
typeOptions: {
minValue: 1,
maxValue: 50,
},
},
{
displayName: 'Search Limit',
name: 'searchLimit',
type: 'number',
default: 10,
description: 'Maximum number of facts to retrieve from long-term memory',
typeOptions: {
minValue: 1,
maxValue: 100,
},
},
],
};
}
async supplyData(itemIndex) {
var _a, _b, _c, _d;
// Get credentials
const credentials = await this.getCredentials('graphitiApi');
const apiUrl = credentials.apiUrl;
const apiKey = credentials.apiKey;
// Get parameters
const sessionIdType = this.getNodeParameter('sessionIdType', itemIndex, 'fromInput');
const contextWindowLength = this.getNodeParameter('contextWindowLength', itemIndex, 5);
const searchLimit = this.getNodeParameter('searchLimit', itemIndex, 10);
// Determine session ID based on type
let sessionId;
// Debug: Log available data
console.log('[Graphiti Node] ===== SESSION ID EXTRACTION =====');
console.log('[Graphiti Node] sessionIdType:', sessionIdType);
if (sessionIdType === 'customKey') {
const sessionKey = this.getNodeParameter('sessionKey', itemIndex, '');
console.log('[Graphiti Node] customKey sessionKey:', sessionKey);
sessionId = sessionKey || (0, uuid_1.v4)();
}
else {
// Try multiple sources for session ID
const inputData = this.getInputData(itemIndex);
console.log('[Graphiti Node] inputData:', JSON.stringify(inputData, null, 2));
// Try to get from various possible locations
const fromJsonSessionId = (_b = (_a = inputData[0]) === null || _a === void 0 ? void 0 : _a.json) === null || _b === void 0 ? void 0 : _b.sessionId;
const fromJsonChatSessionId = (_d = (_c = inputData[0]) === null || _c === void 0 ? void 0 : _c.json) === null || _d === void 0 ? void 0 : _d.chatSessionId;
console.log('[Graphiti Node] fromJsonSessionId:', fromJsonSessionId);
console.log('[Graphiti Node] fromJsonChatSessionId:', fromJsonChatSessionId);
sessionId = fromJsonSessionId || fromJsonChatSessionId || (0, uuid_1.v4)();
}
console.log('[Graphiti Node] FINAL sessionId (userId):', sessionId);
console.log('[Graphiti Node] ===============================');
// Initialize memory instance
const memory = new GraphitiChatMemory_1.GraphitiChatMemory({
apiUrl,
apiKey,
userId: sessionId,
contextWindowLength,
searchLimit,
memoryKey: 'chat_history',
});
return {
response: memory,
};
}
}
exports.GraphitiMemory = GraphitiMemory;
//# sourceMappingURL=GraphitiMemory.node.js.map