import type { LlmConfig } from './llm/types.js'; export { decodeRdfStringLiteral } from './rdf-literal.js'; export interface MemoryToolContext { query: (sparql: string, opts?: { contextGraphId?: string; graphSuffix?: '_shared_memory'; includeSharedMemory?: boolean; view?: 'working-memory' | 'shared-working-memory' | 'verifiable-memory'; agentAddress?: string; assertionName?: string; subGraphName?: string; }) => Promise; /** * ENSURE a per-agent Working Memory assertion graph exists and is * writable. Idempotent: "already exists" is resolved quietly, any other * error surfaces. The implementation owns whatever storage upgrades that * takes — the daemon, for example, migrates a legacy root-scoped * `agent-context/chat-turns` draft here before creating (#2149). The * manager only describes the assertion it wants; it never orchestrates * publisher storage concerns. */ createAssertion: (contextGraphId: string, name: string, opts?: { subGraphName?: string; agentAddress?: string; }) => Promise<{ assertionUri: string | null; alreadyExists: boolean; }>; /** Append quads into an existing Working Memory assertion graph. */ writeAssertion: (contextGraphId: string, name: string, quads: any[], opts?: { subGraphName?: string; agentAddress?: string; }) => Promise<{ written: number; }>; createContextGraph: (opts: { id: string; name: string; description?: string; private?: boolean; }) => Promise; listContextGraphs: () => Promise; } /** Options passed to ChatMemoryManager at construction time. */ export interface ChatMemoryManagerOptions { /** * The attached agent's address. Used as the `agentAddress` field on * `view: 'working-memory'` queries so the query engine can route reads * to the correct per-agent assertion graph. Defaults to `undefined` * during tests / scripts; the daemon passes the node peer ID at runtime. */ agentAddress?: string; /** * Target context graph for chat-turn persistence. Defaults to * `'agent-context'`. Tests and scripts can override. */ contextGraphId?: string; /** * Assertion name for chat-turn persistence. Defaults to `'chat-turns'`. */ assertionName?: string; } export interface MemoryStats { contextGraphId: string; initialized: boolean; messageCount: number; knowledgeTriples: number; totalTriples: number; sessionCount: number; entityCount: number; } export interface MemoryEntity { uri: string; type: string; label: string; properties: Array<{ predicate: string; object: string; }>; sourceSession?: string; } export interface PublishFromSwmResult { kaId?: bigint; ual?: string; status: string; tripleCount: number; } export interface SessionPublicationStatus { sessionId: string; sharedMemoryTripleCount: number; dataTripleCount: number; scope: 'shared_memory_only' | 'published' | 'published_with_pending' | 'empty'; rootEntityCount: number; } export interface SessionPublishResult extends PublishFromSwmResult { sessionId: string; rootEntityCount: number; publication: SessionPublicationStatus; } export interface SessionGraphDeltaWatermark { baseTurnId: string | null; previousTurnId: string | null; appliedTurnId: string | null; latestTurnId: string | null; turnIndex: number; turnCount: number; } export interface SessionGraphDeltaResult { mode: 'delta' | 'full_refresh_required'; reason?: 'session_empty' | 'turn_not_found' | 'missing_watermark' | 'watermark_mismatch'; sessionId: string; turnId: string; watermark: SessionGraphDeltaWatermark; triples: Array<{ subject: string; predicate: string; object: string; }>; } export type ChatTurnPersistenceState = 'stored' | 'failed' | 'pending'; declare const IMPORT_SOURCES: readonly ["claude", "chatgpt", "gemini", "other"]; export type ImportSource = (typeof IMPORT_SOURCES)[number]; export interface ImportResultQuad { subject: string; predicate: string; object: string; } export interface ImportResult { batchId: string | null; source: ImportSource; memoryCount: number; tripleCount: number; entityCount: number; quads: ImportResultQuad[]; quadsTruncated?: boolean; warnings?: string[]; } /** * Chat-turn persistence target. * * V10 architectural note: writes go through Working Memory assertion routes * (`agent.assertion.create` + `agent.assertion.write`), not SWM via * `agent.share`. The `'chat-turns'` assertion inside the `'agent-context'` * context graph is the single canonical home for all chat-turn persistence * in the adapter; reads use `view: 'working-memory'` to hit the matching * per-agent WM assertion graph. * * Triple shapes (`schema:Message` / `schema:Conversation` / `dkg:ChatTurn` + * custom predicates) are preserved from the pre-v1 adapter for raw * persistence. `21_TRI_MODAL_MEMORY.md §3` defines a different target model * (markdown Knowledge Assets with YAML frontmatter and structural + semantic * extraction). v1 of the openclaw-dkg-primary-memory work intentionally * defers that migration; follow-up work tracks it. */ export declare const AGENT_CONTEXT_GRAPH = "agent-context"; export declare const CHAT_TURNS_ASSERTION = "chat-turns"; interface ChatAttachmentRef { id?: string; fileName: string; contextGraphId: string; assertionName?: string; assertionUri: string; fileHash: string; detectedContentType?: string; extractionStatus?: 'completed' | 'skipped' | 'failed'; tripleCount?: number; rootEntity?: string; } interface ChatToolCall { name: string; args: Record; result: unknown; } export declare class ChatMemoryManager { private tools; private llmConfig; private initialized; private knownSessions; private readonly llmClient; private readonly agentContextGraph; private readonly chatTurnsAssertion; private readonly assertionEnsured; readonly agentAddress: string | undefined; constructor(tools: MemoryToolContext, llmConfig: LlmConfig, options?: ChatMemoryManagerOptions); get contextGraphId(): string; /** * The chat-turns assertion this manager writes to. Exposed so a caller * wiring a storage-upgrade policy can assert it covers the assertion the * manager ACTUALLY uses, rather than comparing its own configuration to * itself (#2149). */ get assertionName(): string; updateConfig(llmConfig: LlmConfig): void; /** * Build the read options block used for every WM query issued by this * manager. Reads must match the layer writes land in — mixing SWM-writes * with WM-reads produces silent empty results. */ private wmReadOpts; private wmMutationOpts; /** * The ONE route every chat-turn mutation takes. Target graph, assertion * name, and the resolved-agent mutation options are owned here, so a new * write path cannot silently land in a different graph or skip the * agentAddress that reads resolve under (#277, #2149). */ private writeChatTurns; /** * Lazy creation of the chat-turn context graph + assertion. Runs on the * first `storeChatExchange` / `ensureInitialized` call and is idempotent * thereafter. */ ensureInitialized(): Promise; storeChatExchange(sessionId: string, userMessage: string, assistantReply: string, toolCalls?: ChatToolCall[], opts?: { turnId?: string; persistenceState?: ChatTurnPersistenceState; failureReason?: string | null; attachmentRefs?: ChatAttachmentRef[]; }): Promise; hasChatTurn(sessionId: string, turnId: string): Promise; getChatTurnPersistenceState(sessionId: string, turnId: string): Promise; recordChatTurnPersistenceTransition(sessionId: string, turnId: string, persistenceState: ChatTurnPersistenceState, opts?: { failureReason?: string | null; assistantReply?: string; toolCalls?: ChatToolCall[]; attachmentRefs?: ChatAttachmentRef[]; }): Promise; private extractAndWriteMentions; private callMentionExtraction; extractKnowledge(sessionId: string, userMessage: string, assistantReply: string): Promise; recall(sparql: string): Promise; semanticRecall(question: string): Promise<{ sparql: string; result: any; }>; getStats(): Promise; getEntities(limit?: number): Promise; getSession(sessionId: string, opts?: { limit?: number; order?: 'asc' | 'desc'; }): Promise<{ session: string; messages: Array<{ uri: string; author: string; text: string; ts: string; turnId?: string; persistStatus?: 'pending' | 'in_progress' | 'stored' | 'failed' | 'skipped'; failureReason?: string | null; attachmentRefs?: ChatAttachmentRef[]; toolCalls?: ChatToolCall[]; }>; } | null>; getRecentChats(limit?: number): Promise; }>>; getSessionGraphDelta(sessionId: string, turnId: string, opts?: { baseTurnId?: string | null; }): Promise; getSessionPublicationStatus(sessionId: string): Promise; getSessionRootEntities(sessionId: string): Promise; publishSession(sessionId: string, opts?: { rootEntities?: string[]; clearSharedMemoryAfter?: boolean; }): Promise; publishFromSwm(selection?: 'all' | { rootEntities: string[]; }, opts?: { clearSharedMemoryAfter?: boolean; }): Promise; private parseNTriples; } //# sourceMappingURL=chat-memory.d.ts.map