n8n
Version:
n8n Workflow Automation Tool
77 lines (76 loc) • 3.68 kB
TypeScript
import type { AgentDbMessage, BuiltMemory, BuiltObservationStore, MemoryDescriptor, NewObservation, Observation, ObservationCursor, ObservationLockHandle, ScopeKind, Thread } from '@n8n/agents';
import { AgentMessageRepository } from '../repositories/agent-message.repository';
import { AgentObservationCursorRepository } from '../repositories/agent-observation-cursor.repository';
import { AgentObservationLockRepository } from '../repositories/agent-observation-lock.repository';
import { AgentObservationRepository } from '../repositories/agent-observation.repository';
import { AgentResourceRepository } from '../repositories/agent-resource.repository';
import { AgentThreadRepository } from '../repositories/agent-thread.repository';
export declare class N8nMemory implements BuiltMemory, BuiltObservationStore {
private readonly threadRepository;
private readonly messageRepository;
private readonly resourceRepository;
private readonly observationRepository;
private readonly observationCursorRepository;
private readonly observationLockRepository;
constructor(threadRepository: AgentThreadRepository, messageRepository: AgentMessageRepository, resourceRepository: AgentResourceRepository, observationRepository: AgentObservationRepository, observationCursorRepository: AgentObservationCursorRepository, observationLockRepository: AgentObservationLockRepository);
getThread(threadId: string): Promise<Thread | null>;
saveThread(thread: Omit<Thread, 'createdAt' | 'updatedAt'>): Promise<Thread>;
private ensureResource;
deleteThread(threadId: string): Promise<void>;
deleteThreadsByPrefix(threadIdPrefix: string): Promise<void>;
getMessages(threadId: string, opts?: {
limit?: number;
before?: Date;
resourceId?: string;
}): Promise<AgentDbMessage[]>;
saveMessages(args: {
threadId: string;
resourceId: string;
messages: AgentDbMessage[];
}): Promise<void>;
deleteMessages(messageIds: string[]): Promise<void>;
deleteMessagesByThread(threadId: string, resourceId?: string): Promise<void>;
getWorkingMemory(params: {
threadId: string;
resourceId: string;
scope: 'resource' | 'thread';
}): Promise<string | null>;
saveWorkingMemory(params: {
threadId: string;
resourceId: string;
scope: 'resource' | 'thread';
}, content: string): Promise<void>;
appendObservations(rows: NewObservation[]): Promise<Observation[]>;
getObservations(opts: {
scopeKind: ScopeKind;
scopeId: string;
since?: {
sinceCreatedAt: Date;
sinceObservationId: string;
};
kindIs?: string;
limit?: number;
schemaVersionAtMost?: number;
}): Promise<Observation[]>;
getMessagesForScope(scopeKind: ScopeKind, scopeId: string, opts?: {
since?: {
sinceCreatedAt: Date;
sinceMessageId: string;
};
}): Promise<AgentDbMessage[]>;
deleteObservations(ids: string[]): Promise<void>;
getCursor(scopeKind: ScopeKind, scopeId: string): Promise<ObservationCursor | null>;
setCursor(cursor: ObservationCursor): Promise<void>;
acquireObservationLock(scopeKind: ScopeKind, scopeId: string, opts: {
ttlMs: number;
holderId: string;
}): Promise<ObservationLockHandle | null>;
releaseObservationLock(handle: ObservationLockHandle): Promise<void>;
describe(): MemoryDescriptor;
private toObservation;
private toThread;
private extractWorkingMemory;
private mergeWorkingMemory;
private upsertResourceMetadata;
private upsertThreadMetadata;
}