/** * Per-session OpenViking runtime: initialization, profile/recall injection, * capture, threshold commits, and the offline pending queue. * @module openviking-memory/runtime */ import { createUserMessage, type ContextFormed } from '@deepseek-ai/dsh-llm'; import type { OpenVikingClient } from './ov-client.ts'; import type { OpenVikingConfig } from './config.ts'; export interface SessionLike { id: string; header?: { cwd?: string; }; } export interface AgentLike { session: SessionLike; status: string; } interface RuntimeState { dshSessionId: string; ovSessionId: string; cwd: string; config: OpenVikingConfig; ready: boolean; /** Whether the OpenViking session has been created/confirmed on the server. * The session is only materialized lazily on the first real write * (addMessage / commit with content), never during read-only init, so * capture-disabled sessions do not accumulate empty session records. */ sessionReady: boolean; initializing: Promise | null; initializationRetryable: boolean; profileBlock: string; profileDelivered: boolean; toolNames: Map; writes: Promise; hasPendingWrites: boolean; pendingCreatedAt: number; disposing: Promise | null; } export type Logger = { debug?(message: string, ...args: unknown[]): void; info?(message: string, ...args: unknown[]): void; warn?(message: string, ...args: unknown[]): void; error?(message: string, ...args: unknown[]): void; }; export declare class OpenVikingRuntime { readonly client: OpenVikingClient; readonly logger: Logger; readonly states: Map; constructor(client: OpenVikingClient, config: OpenVikingConfig, logger?: Logger); config: OpenVikingConfig; /** * Apply a live settings change. Updates the shared config and re-derives * per-session states so the next access re-initializes with the new values; * already-queued writes still drain with their old config copy. */ reconfigure(config: OpenVikingConfig): void; stateFor(session: SessionLike): RuntimeState; initialize(agent: { session: SessionLike; }): Promise; ensureState(state: RuntimeState): Promise; initializeState(state: RuntimeState): Promise; profileMessage(agent: { session: SessionLike; }): Promise | null>; recallMessage(agent: { session: SessionLike; }, messages: ReadonlyArray): Promise | null>; /** * Build the pre-step context additions (profile + recall) concurrently under * one hard deadline. Profile construction is independent of the final message * batch, so the caller may hand in an already-started profile promise to * overlap its HTTP round-trips with the downstream pre-step waterfall; recall * needs the batch and starts here. A slow or unreachable OpenViking server * must never stall a model step: whichever side misses the deadline is * dropped for that step (null), while its underlying work keeps running and * is picked up by the next pre-step. */ preStepContext(agent: { session: SessionLike; }, messages: ReadonlyArray, options?: { profile?: Promise | null>; deadlineMs?: number; }): Promise<{ profile: ReturnType | null; recall: ReturnType | null; }>; capture(session: SessionLike, event: Record): void; maybeCommit(session: SessionLike, event: Record): void; dispose(session: SessionLike): Promise; disposeAll(): Promise; enqueueWrite(state: RuntimeState, operation: () => Promise): void; enqueuePending(state: RuntimeState, type: 'addMessage' | 'commitSession', payload: Record): Promise<{ ok: boolean; error?: string; }>; enqueueFinalCommit(state: RuntimeState, payload: Record): Promise; enqueuePendingMessage(state: RuntimeState, payload: Record): Promise; removePendingCommits(state: RuntimeState): Promise; refreshPendingState(state: RuntimeState): Promise; flush(session: SessionLike): Promise; log(stage: string, data: unknown): void; } /** * Declare this plugin's message source. * * DSH 0.1.7 deleted the shared catch-all `plugin` source kind in favour of a * merge-extensible map each producer extends with its own: a user message may * carry any producer's kind, and consumers fall through unknown kinds. The * `form` discriminator rides along unchanged — `instructions` marks the * session-start profile block, `recall` the per-step recall block — so DSH's * own context accounting still sees what each message is. */ declare module '@deepseek-ai/dsh-llm' { interface MessageSourceMap { 'openviking-memory': { kind: 'openviking-memory'; } & ContextFormed; } } export {}; //# sourceMappingURL=runtime.d.ts.map