import { Context } from 'koishi'; import type { AgenticMemorySnapshotItem, LivingMemoryPresetExport, LivingMemoryPresetImportSummary, MemoryEntryRecord, MemoryJobKind, MemoryJobRecord, MemoryMutationInput, MemoryScope, MemorySnapshotRecord, MemorySourceMessage, MemoryUpdatePatch, PresetSpeakerInput, PresetSpeakerRecord, UserProfileInput, UserProfileRecord } from '../../contracts/memory'; import type { LegacyMemoryEmbeddingRecord, MemoryIndexSourceRecord } from '../../contracts/vector_index'; import type { AttributedMemoryItem, DreamMemoryEntryRecord, JobRepository, RecallRepository, SnapshotRepository, UserProfileMemoryRepository, UserProfileRepository } from '../../contracts/workflows'; import { type PresetPersonaWriteInput } from './preset_personas'; export declare class LivingMemoryRepository implements RecallRepository, SnapshotRepository, JobRepository, UserProfileMemoryRepository, UserProfileRepository { private readonly ctx; private readonly entries; private readonly jobs; private readonly snapshots; private readonly userProfiles; private readonly presetPersonas; private readonly transactions; constructor(ctx: Context); getPresetPersona(presetId: string): Promise; listPresetPersonas(): Promise; upsertPresetPersona(input: PresetPersonaWriteInput): Promise; deletePresetPersona(presetId: string): Promise; defineTables(): void; /** * 全部事务的唯一入口。单连接数据库无法并发开启事务,因此所有事务共用一条 * 串行链;这是驱动限制的变通,不是一致性机制本身——一致性来自事务边界, * 上层的预设级串行队列不得因此被移除。 */ private runTransaction; migrateMemorySourceOriginsArray(): Promise; migrateWebuiSourceConversationKeys(): Promise; migrateActiveMemorySpeakers(): Promise; removeLegacyReferenceSnapshots(): Promise; hasMigratedLegacyEmbeddings(): Promise; completeLegacyEmbeddingMigration(): Promise; listEntriesByPreset(presetId: string): Promise; listArchivedEntriesBefore(presetId: string, updatedBefore: Date): Promise[]>; listDreamEntriesByPreset(presetId: string): Promise; listActiveMemorySpeakerKeys(presetId: string): Promise; listActiveMemorySpeakerLinks(presetId: string, speakerKeys: string[]): Promise[]>; listEntryIndexSourcePage(afterId: string | null, limit: number): Promise; listEntryIndexSourcePageByPreset(presetId: string, afterId: string | null, limit: number): Promise; listLegacyEmbeddingPage(afterId: string | null, limit: number): Promise; countEntriesByPreset(presetId: string): Promise; countEntries(): Promise; listEntryPresetIds(): Promise; countActiveEntries(presetId: string): Promise; getEntryById(id: string): Promise; getEntriesByPresetAndIds(presetId: string, ids: string[]): Promise; getSearchEntriesByPresetAndIds(presetId: string, ids: string[]): Promise[]>; appendMemories(scope: MemoryScope, sourceOriginMessages: MemorySourceMessage[], extracted: AttributedMemoryItem[], sourceLabel?: string | null): Promise; createMemory(scope: MemoryScope, input: MemoryMutationInput, speakerKeys?: string[]): Promise; updateMemory(id: string, patch: MemoryUpdatePatch): Promise<{ record: { id: string; presetId: string; sourceConversationId: string | null; sourceLabel: string | null; sourceOrigins: import("../..").MemorySourceOrigin[]; createdAt: Date; updatedAt: Date; speakerKeys: string[]; type: "context" | "fact" | "identity" | "other" | "plan" | "preference"; status: "active" | "archived"; content: string; keywords: string[]; summary: string | null; sentiment: string | null; importance: number | null; }; contentChanged: boolean; } | null>; archiveActiveEntries(presetId: string, ids: string[]): Promise<{ id: string; presetId: string; speakerKeys: string[]; type: import("../..").MemoryEntryType; content: string; keywords: string[]; summary: string | null; sentiment: string | null; importance: number | null; sourceConversationId: string | null; sourceLabel: string | null; sourceOrigins: import("../..").MemorySourceOrigin[]; createdAt: Date; status: 'archived'; updatedAt: Date; }[]>; splitMemory(presetId: string, sourceMemoryId: string, memories: AttributedMemoryItem[]): Promise<{ memories: MemoryEntryRecord[]; archivedSource: { id: string; presetId: string; speakerKeys: string[]; type: import("../..").MemoryEntryType; content: string; keywords: string[]; summary: string | null; sentiment: string | null; importance: number | null; sourceConversationId: string | null; sourceLabel: string | null; sourceOrigins: import("../..").MemorySourceOrigin[]; createdAt: Date; status: 'archived'; updatedAt: Date; }; }>; mergeMemories(presetId: string, sourceMemoryIds: string[], memory: AttributedMemoryItem): Promise<{ memory: MemoryEntryRecord; archivedSources: { id: string; presetId: string; speakerKeys: string[]; type: import("../..").MemoryEntryType; content: string; keywords: string[]; summary: string | null; sentiment: string | null; importance: number | null; sourceConversationId: string | null; sourceLabel: string | null; sourceOrigins: import("../..").MemorySourceOrigin[]; createdAt: Date; status: 'archived'; updatedAt: Date; }[]; }>; deleteMemory(id: string): Promise; deleteEntries(presetId: string, ids: string[]): Promise; getLatestSnapshotByScope(scope: Pick): Promise; listSnapshotsByPreset(presetId: string): Promise; upsertSnapshot(scope: MemoryScope, query: string, items: AgenticMemorySnapshotItem[]): Promise; deleteSnapshot(snapshotId: string): Promise; deleteSnapshotsByConversation(conversationId: string): Promise; deleteSnapshotsByPreset(presetId: string): Promise; createJob(scope: MemoryScope, kind: MemoryJobKind, input: string): Promise; createFailedJob(scope: MemoryScope, kind: MemoryJobKind, input: string, error: unknown, startedAt: Date): Promise; updateJob(id: string, patch: Partial): Promise; listJobsByPreset(presetId: string): Promise; markStaleRunningJobsAsFailed(options?: { presetId?: string; kind?: MemoryJobKind; }, reason?: string): Promise; removeExpiredJobs(deadline: Date): Promise; listPresetSpeakers(presetId: string): Promise; upsertPresetSpeaker(input: PresetSpeakerInput): Promise; registerMissingPresetSpeakers(presetId: string, speakers: Array<{ speakerKey: string; speakerLabel: string; }>): Promise; reconcilePresetSpeaker(input: PresetSpeakerInput): Promise; listUserProfilesByPreset(presetId: string): Promise; listUserProfilesBySpeakerKeys(presetId: string, speakerKeys: string[]): Promise; replaceUserProfile(presetId: string, profile: UserProfileInput): Promise; updateUserProfileContent(profileId: string, content: string): Promise; markUserProfileReviewed(profileId: string, sourceMemoryIds: string[]): Promise; deleteUserProfile(profileId: string): Promise; clearAllByPreset(presetId: string): Promise; exportPresetData(presetId: string): Promise; importPresetData(targetPresetId: string, data: LivingMemoryPresetExport): Promise; private buildPresetImportRows; listDistinctPresetIds(): Promise; }