n8n
Version:
n8n Workflow Automation Tool
63 lines (62 loc) • 3.75 kB
TypeScript
import type { InstanceAiEnsureThreadResponse, InstanceAiRichMessagesResponse, InstanceAiThreadInfo, InstanceAiThreadListResponse, InstanceAiThreadMessagesResponse, InstanceAiThreadOrigin, InstanceAiThreadSource } from '@n8n/api-types';
import { Logger } from '@n8n/backend-common';
import { GlobalConfig } from '@n8n/config';
import { type AgentTreeSnapshot } from '@n8n/instance-ai';
import { DbSnapshotStorage } from './storage/db-snapshot-storage';
import { DurableLogMetrics } from './event-bus/durable-log-metrics';
import { InstanceAiCheckpointRepository } from './repositories/instance-ai-checkpoint.repository';
import { InstanceAiEventLogRepository } from './repositories/instance-ai-event-log.repository';
import { InstanceAiPendingConfirmationRepository } from './repositories/instance-ai-pending-confirmation.repository';
import { TypeORMAgentMemory } from './storage/typeorm-agent-memory';
export interface InstanceAiThreadLaunchMetadata {
source: InstanceAiThreadSource;
origin: InstanceAiThreadOrigin;
sourceContext?: Record<string, unknown>;
}
export declare class InstanceAiMemoryService {
private readonly logger;
private readonly agentMemory;
private readonly dbSnapshotStorage;
private readonly checkpointRepository;
private readonly pendingConfirmationRepository;
private readonly eventLogRepository;
private readonly durableLogMetrics;
private readonly instanceAiConfig;
constructor(logger: Logger, globalConfig: GlobalConfig, agentMemory: TypeORMAgentMemory, dbSnapshotStorage: DbSnapshotStorage, checkpointRepository: InstanceAiCheckpointRepository, pendingConfirmationRepository: InstanceAiPendingConfirmationRepository, eventLogRepository: InstanceAiEventLogRepository, durableLogMetrics: DurableLogMetrics);
listThreads(userId: string, page?: number, perPage?: number): Promise<InstanceAiThreadListResponse>;
ensureThread(userId: string, threadId: string, projectId: string, launchMetadata: InstanceAiThreadLaunchMetadata): Promise<InstanceAiEnsureThreadResponse>;
restoreThreadMessages(userId: string, threadId: string, messages: Array<Record<string, unknown>>): Promise<{
restored: number;
}>;
getThreadProjectId(threadId: string): Promise<string | undefined>;
getThreadMessages(_userId: string, threadId: string, options?: {
limit?: number;
page?: number;
}): Promise<InstanceAiThreadMessagesResponse>;
getRichMessages(_userId: string, threadId: string, options?: {
limit?: number;
page?: number;
excludeRunIds?: string[];
excludeMessageGroupIds?: string[];
}): Promise<Omit<InstanceAiRichMessagesResponse, 'nextEventId'>>;
private foldSnapshotsFromLog;
private flagExpiredConfirmations;
private loadActiveCheckpoints;
getLatestRunSnapshot(threadId: string, options?: {
messageGroupId?: string;
runId?: string;
}): Promise<AgentTreeSnapshot | undefined>;
validateThreadOwnership(userId: string, threadId: string): Promise<boolean>;
checkThreadOwnership(userId: string, threadId: string): Promise<'owned' | 'not_found' | 'other_user'>;
deleteThread(threadId: string): Promise<void>;
deleteThreadsForUser(userId: string): Promise<number>;
renameThread(threadId: string, title: string): Promise<InstanceAiThreadInfo>;
updateThread(threadId: string, updates: {
title?: string;
metadata?: Record<string, unknown>;
}): Promise<InstanceAiThreadInfo>;
getThreadMetadata(userId: string, threadId: string): Promise<Record<string, unknown> | undefined>;
cleanupExpiredThreads(onThreadDeleted?: (threadId: string) => Promise<void>): Promise<number>;
private toThreadInfo;
private toThreadMessage;
}