/** * Minimal OpenViking HTTP client used by the runtime and model tools. * Every method normalizes the OpenViking envelope into `{ ok, result, status, * error, traceId }` and never throws on transport failure. * @module openviking-memory/client */ import type { OpenVikingConfig } from './config.ts'; export interface ApiResponse { ok: boolean; result: T | null; status: number; error?: { code?: string; message?: string; details?: Record; }; traceId: string | undefined; } export interface FindOptions { targetUri?: string; limit?: number; scoreThreshold?: number; actorPeerId?: string; } export interface FindEntry { uri: string; contextType: 'memory' | 'skill' | 'resource'; score: number; abstract: string; overview: string | null; } export interface FetchOptions { timeoutMs?: number; actorPeerId?: string; } /** Options shared by filesystem content tools (tree/grep/glob). */ export interface FsToolOptions { /** Starting OpenViking URI; the tools supply the default root. */ uri?: string; /** Maximum number of nodes/matches to return. */ nodeLimit?: number; /** Maximum depth to traverse. */ levelLimit?: number; /** Case-insensitive matching (grep only). */ caseInsensitive?: boolean; /** Per-session actor peer override. */ actorPeerId?: string; } /** Result of `GET /api/v1/fs/tree` (agent output). */ export interface TreeEntry { uri: string; rel_path: string; isDir: boolean; size?: number; modTime?: string; abstract?: string; } /** Result of `POST /api/v1/search/grep`. */ export interface GrepResult { matches?: Array<{ uri?: string; line?: number; content?: string; }>; count?: number; match_count?: number; files_scanned?: number; } /** One match from `POST /api/v1/search/glob`. */ export interface GlobEntry { uri: string; [key: string]: unknown; } /** A watch task as returned by `GET /api/v1/watches`. */ export interface WatchTask { task_id: string; path: string; to_uri?: string; parent_uri?: string; reason?: string; instruction?: string; watch_interval?: number; is_active?: boolean; last_execution_time?: string; next_execution_time?: string; [key: string]: unknown; } /** One installed agent skill as returned by `GET /api/v1/skills`. */ export interface SkillEntry { type?: string; name: string; uri?: string; root_uri?: string; skill_md_uri?: string; description?: string; tags?: string[]; allowed_tools?: string[]; score?: number; [key: string]: unknown; } /** Detail returned by `GET /api/v1/skills/{name}` with `include_content=true`. */ export interface SkillDetail { name?: string; description?: string; uri?: string; root_uri?: string; skill_md_uri?: string; content?: string; abstract?: string; overview?: string; tags?: string[]; allowed_tools?: string[]; [key: string]: unknown; } /** Skill scope selector for the skills API (`target_uri`). */ export interface SkillScopeOptions { /** OpenViking `target_uri` disambiguator: `viking://agent/skills` or a user skills root. */ targetUri?: string; /** Per-session actor peer override. */ actorPeerId?: string; /** Request timeout override. */ timeoutMs?: number; } /** * Failure envelope for a skill mutation (create/update/delete). The client * never throws; every failed mutation returns this shape so callers can tell a * request that never completed (where the server may already have committed * the write) apart from an explicit server rejection. */ export interface SkillMutationFailure { ok: false; /** HTTP status; `0` means no response arrived (client abort / network failure). */ status: number; /** Human-readable error message from the server or the transport. */ errorMessage: string; /** * True when the request was aborted by the client timeout or otherwise * failed on the wire without an HTTP response. In that case the server may * already have committed the write, so the caller must treat the outcome as * unknown and advise verification rather than reporting a definitive failure. */ timedOut: boolean; } /** Successful skill create/update (`POST /api/v1/skills`). */ export interface SkillUpsertOk { ok: true; rootUri: string; uri: string; name: string; taskId?: string; } /** Successful skill delete (`DELETE /api/v1/skills/{name}`). */ export interface SkillDeleteOk { ok: true; name: string; rootUri?: string; deletedCount?: number; } /** Result of `POST /api/v1/skills` (create/update). */ export type SkillUpsertResult = SkillUpsertOk | SkillMutationFailure; /** Result of `DELETE /api/v1/skills/{name}`. */ export type SkillDeleteResult = SkillDeleteOk | SkillMutationFailure; /** Client construction options. */ export interface OpenVikingClientOptions { /** * Resolve the current Bearer API key from the DSH credential store. Called * once per request (the credential seam contract: re-resolve per operation, * never cache across operations), so a changed credential reaches the next * request without any plugin restart. Omit to send requests without a key. */ resolveApiKey?: () => Promise; } export declare class OpenVikingClient { connected: boolean; config: OpenVikingConfig; private readonly resolveApiKey?; constructor(config: OpenVikingConfig, options?: OpenVikingClientOptions); /** * Swap the live configuration in place. The client is constructed once at * plugin apply with the composition entry (usually defaults); the DSH * settings service attaches afterwards, so settings changes must be pushed * into the client or every request would keep using the old endpoint/key. */ reconfigure(config: OpenVikingConfig): void; headers(options?: FetchOptions & { apiKey?: string; }): Record; /** Only include an actor peer option when one is actually provided. */ private peer; fetchJSON(path: string, init?: RequestInit, options?: FetchOptions): Promise>>; health(): Promise; healthResult(): Promise>>; ensureSession(sessionId: string, actorPeerId?: string): Promise; ensureSessionResult(sessionId: string, actorPeerId?: string): Promise>>; getSession(sessionId: string, actorPeerId?: string): Promise | null>; getSessionArchive(sessionId: string, archiveId: string, actorPeerId?: string): Promise | null>; addMessage(sessionId: string, payload: Record, actorPeerId?: string): Promise>>; commitSession(sessionId: string, actorPeerId?: string, options?: { timeoutMs?: number; }): Promise>>; find(query: string, options?: FindOptions): Promise; read(uri: string, level: 'abstract' | 'overview' | 'full', actorPeerId?: string): Promise; list(uri: string, actorPeerId?: string): Promise>>; stat(uri: string, actorPeerId?: string): Promise | null>; forget(uri: string, recursive?: boolean, actorPeerId?: string): Promise; addResource(path: string, reason?: string, actorPeerId?: string): Promise | null>; /** Recursively list a directory tree (agent output). */ tree(uri: string, options?: FsToolOptions): Promise; /** Write, append, or create text content at an OpenViking file URI. */ writeContent(uri: string, content: string, options?: { mode?: 'replace' | 'append' | 'create'; wait?: boolean; timeoutMs?: number; actorPeerId?: string; }): Promise>>; /** Replace an exact string in an existing file (read → replace → write). */ editContent(uri: string, oldString: string, newString: string, options?: { replaceAll?: boolean; wait?: boolean; timeoutMs?: number; actorPeerId?: string; }): Promise<{ ok: boolean; message: string; }>; /** Content search with a regex pattern. */ grep(pattern: string, options?: FsToolOptions): Promise; /** Find files matching a glob pattern. */ glob(pattern: string, options?: FsToolOptions): Promise; /** * List installed agent skills for the current user plus shared agent skills. * @param options - `nodeLimit` caps the returned count; `actorPeerId` selects the requesting peer. * @returns `ok: false` on transport/server failure so callers can report an * incomplete observation; otherwise the merged skill entries. */ listSkills(options?: { nodeLimit?: number; actorPeerId?: string; }): Promise<{ ok: boolean; skills: SkillEntry[]; }>; /** * Read one installed skill's metadata and (optionally) full SKILL.md content. * @param skillName - kebab-case skill name. * @param options - `targetUri` disambiguates duplicate user/agent names; `includeContent` fetches the body. * @returns the skill detail, or `null` on failure / not found. */ getSkill(skillName: string, options?: SkillScopeOptions & { includeContent?: boolean; }): Promise; /** * Create or update one skill from its full SKILL.md body. The server treats * the skill name (frontmatter `name`, also the directory key) as the * upsert identity: posting an existing name replaces its SKILL.md. * @param content - the complete SKILL.md text, including frontmatter. * @param options - `targetUri` selects the root (the account-shared agent * skills root when targeting shared skills; omitted means the current * user's private skills root); `actorPeerId` selects the requesting peer. * @returns `ok: true` with the upload result (root URI and task id), or a * `SkillMutationFailure` carrying the status and a `timedOut` flag so * callers can tell a never-completed request from an explicit rejection. */ upsertSkill(content: string, options?: SkillScopeOptions): Promise; /** * Delete one skill by name. * @param skillName - kebab-case skill name. * @param options - `targetUri` disambiguates the root (the user's private * skills root when omitted); `actorPeerId` selects the requesting peer. * @returns `ok: true` with the deletion result, or a `SkillMutationFailure` * when the skill does not exist, the request failed, or the request never * completed (`timedOut`). */ deleteSkill(skillName: string, options?: SkillScopeOptions): Promise; /** List watch tasks (re-ingestion schedules). */ listWatches(actorPeerId?: string): Promise; /** Cancel the watch task targeting a URI. */ cancelWatch(uri: string, actorPeerId?: string): Promise; } //# sourceMappingURL=ov-client.d.ts.map