import type { LivingMemoryPresetExport, LivingMemoryPresetImportResult, MemoryEntryRecord, MemoryMutationInput, MemoryUpdatePatch, MemoryScope, MemorySourceMessage, PresetSpeakerRecord } from '../../contracts/memory'; import type { MemoryIndexMutationSink } from '../../contracts/vector_index'; import type { AttributedMemoryItem, ExtractionMemoryWriter, ExtractionPayload } from '../../contracts/workflows'; import type { LivingMemoryRepository } from '../persistence/repository'; import { type LivingMemoryLogger } from '../logging/logger'; type MemoryFactRepository = Pick; export declare const MEMORY_DELETE_BATCH_SIZE = 500; export declare class LivingMemoryMutationService implements ExtractionMemoryWriter { private readonly repository; private readonly vectorIndex; private readonly logger; private readonly queue; constructor(repository: MemoryFactRepository, vectorIndex: MemoryIndexMutationSink, logger: LivingMemoryLogger); /** * Dream 前置补齐:活跃记忆上的缺行键以合成标签补注册。必须在预设级 * 队列内重读活跃键——队列外读到的键可能已被同预设清空删除,按陈旧 * 键补行会在清空后的预设上留下孤儿注册行,listDistinctPresetIds 会 * 把它重新列为存量预设。 */ ensurePresetSpeakersCoverage(presetId: string): Promise; appendExtractedMemories(scope: MemoryScope, sourceOriginMessages: MemorySourceMessage[], extracted: AttributedMemoryItem[], sourceLabel: string, windowSpeakers: ExtractionPayload['speakers']): Promise<{ memories: MemoryEntryRecord[]; warnings: string[]; }>; 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>; updateActiveMemory(presetId: string, id: string, patch: Omit): Promise; private persistMemoryUpdate; /** * 铸键不变量:create/update 落库的键(显式传入或 scope 默认推导)不 * 经过提取窗口映射,RPC 面只有键没有昵称,落库前以合成标签补齐缺失 * 行。与记忆写入同在预设级队列操作内、分属两个事务,依据同 * appendExtractedMemories。 */ private registerCallerSpeakerKeys; archiveActiveMemories(presetId: string, ids: string[]): Promise<{ archived: number; }>; splitActiveMemory(presetId: string, sourceMemoryId: string, memories: AttributedMemoryItem[]): Promise<{ memories: MemoryEntryRecord[]; warnings: string[]; }>; mergeActiveMemories(presetId: string, sourceMemoryIds: string[], memory: AttributedMemoryItem): Promise<{ memory: MemoryEntryRecord; warnings: string[]; }>; private syncCommittedMemoriesToIndex; deleteMemory(id: string): Promise; deleteMemories(presetId: string, ids: string[]): Promise<{ deleted: number; }>; deleteExpiredArchivedMemories(presetId: string, now: Date): Promise<{ deleted: number; }>; clearPresetData(presetId: string): Promise; importPreset(targetPresetId: string, data: LivingMemoryPresetExport): Promise; private syncCommittedMutationToIndex; private scheduleIndexReconcile; /** * 按 MEMORY_DELETE_BATCH_SIZE 将 id 切片,逐批执行 applyBatch 并累加其 * 返回的处理条数。批大小、切片与计数的单点:三处批量归档/删除只描述 * 每批做什么,SQL $in 规模与索引同步批次的约束集中在此维护。 */ private runBatchedMutation; private runPresetMutation; private buildIndexUpsert; private factsCommittedError; } export {};