/** * EngramRestClient — typed REST client for the engram HTTP API. * * All methods return null on error and update the availability tracker. * No method ever throws to its caller — engram failures must not block agent operation. */ import { AvailabilityTracker } from './availability.js'; import type { PluginConfig } from './config.js'; export interface Observation { id: number; title: string; type: string; scope?: string; narrative?: string; facts?: string[]; tags?: string[]; similarity?: number; project?: string; } export interface ContextInjectResponse { observations: Observation[]; sessionId?: number; rule_router?: RuleRouterPayload; } export interface ContextSearchResponse { observations: Observation[]; /** * Observations flagged always_inject=true in the server config. * These are behavioral rules that must be rendered in every context injection * regardless of query relevance. */ always_inject?: Observation[]; rule_router?: RuleRouterPayload; } export interface RuleRouterPacket { rule_version_id?: number; legacy_behavioral_rule_id?: number; bucket?: string; scope?: string; audience?: string; content?: string; summary?: string; evidence_handles?: string[]; state?: string; budget_class?: string; priority?: number; suppression_reason?: string; } export interface RuleRouterPayload { enabled?: boolean; mode?: string; kernel_count?: number; contextual_count?: number; suppressed_count?: number; budget_outcome?: string; kernel?: RuleRouterPacket[]; contextual?: RuleRouterPacket[]; suppressed?: RuleRouterPacket[]; fallback_reason?: string; } export interface SessionInitResponse { sessionDbId: number; promptNumber: number; skipped?: boolean; } export interface HealthResponse { status: string; version?: string; } export interface SelfCheckResponse { components: Record; } export interface BulkObservationInput { title: string; content: string; type: string; project: string; scope?: string; tags?: string[]; } /** @deprecated Use BulkObservationInput instead. */ export type BulkImportRequest = BulkObservationInput; export interface BulkImportResponse { imported: number; skipped_duplicates: number; errors?: string[]; } export interface BulkDeleteResponse { deleted: number; } /** A single observation returned by the decisions search endpoint. */ export interface DecisionSearchObservation { title?: string; narrative?: string; concepts?: string[]; rejected?: string[]; } /** Response from POST /api/decisions/search. */ export interface DecisionSearchResponse { observations: DecisionSearchObservation[]; } export interface Issue { id: number; title: string; body: string; status: string; priority: string; source_project: string; target_project: string; source_agent: string; labels: string[]; comment_count?: number; created_at: string; updated_at: string; } export interface IssueComment { id: number; issue_id: number; author_project: string; author_agent: string; body: string; created_at: string; } export interface IssueListResponse { issues: Issue[]; total: number; } export interface IssueDetailResponse { issue: Issue; comments: IssueComment[]; comment_count: number; } export interface CreateIssueRequest { title: string; body?: string; priority?: string; source_project?: string; target_project: string; source_agent?: string; created_by_session?: string; labels?: string[]; } export interface CreateIssueResponse { id: number; message: string; } export interface UpdateIssueRequest { status?: string; comment?: string; source_project?: string; source_agent?: string; } export declare class EngramRestClient { private readonly baseUrl; private readonly token; private readonly defaultTimeoutMs; readonly availability: AvailabilityTracker; constructor(config: PluginConfig); /** * Fetch session context for injection (static session-level context). * POST /api/context/inject */ getContextInject(agentId: string, cwd?: string): Promise; /** * Per-turn context search. * POST /api/context/search */ searchContext(body: { project: string; query: string; cwd?: string; agent_id?: string; /** Source identifier passed through to the server for analytics/routing. */ source?: string; /** Search preset: decisions, changes, how_it_works. */ preset?: string; }): Promise; /** * Search for relevant decisions. * POST /api/decisions/search */ searchDecisions(body: { query: string; project: string; limit?: number; }): Promise; /** * Track a search miss for self-tuning analytics. * POST /api/analytics/search-misses (fire-and-forget) */ trackSearchMiss(body: { project: string; query: string; }): Promise; /** * Ingest a tool event for self-learning. * POST /api/events/ingest (fire-and-forget — returns void) */ ingestEvent(body: { session_id: string; project: string; tool_name: string; tool_input: string; tool_result: string; /** Source identifier passed through to the server for analytics/routing. */ source?: string; }): Promise; /** * Submit a transcript for session backfill/extraction. * POST /api/backfill/session (fire-and-forget — returns void) */ backfillSession(body: { session_id: string; project: string; content: string; }): Promise; /** * Initialize a new engram session for this agent interaction. * POST /api/sessions/init */ initSession(body: { claudeSessionId: string; project: string; prompt?: string; }): Promise; /** * Mark observation IDs as injected into this session. * POST /api/sessions/{id}/mark-injected (fire-and-forget) */ markInjected(sessionDbId: number, ids: number[]): Promise; /** * Health check. * GET /api/health */ health(): Promise; /** * Component-level health check. * GET /api/selfcheck */ selfCheck(): Promise; /** * Bulk-import observations. * POST /api/observations/bulk-import * * Server expects: { project, session_id?, observations: [{ type, title, narrative, scope, concepts }] } * Client uses: { content → narrative, tags → concepts } * * Passing sessionId reuses the caller's existing session instead of creating a new * synthetic one per call, preventing phantom session proliferation. */ bulkImport(observations: BulkObservationInput[], sessionId?: string): Promise; /** * Bulk-delete (archive) observations by ID. * POST /api/observations/bulk-status { action: "archive", ids, reason } * * The server has no dedicated bulk-delete endpoint. Archiving is the closest * equivalent — it removes observations from search results and context injection. */ /** * Suppress an observation (reversible soft-hide from search results). * POST /api/observations/bulk-status { action: "suppress", ids: [id] } */ suppressObservation(id: number): Promise; bulkDelete(ids: string[]): Promise; /** * Rate an observation as useful or not useful. * MCP uses feedback(action="rate", id, rating="useful"|"not_useful"). */ rateObservation(id: number, rating: 'useful' | 'not_useful'): Promise; /** * Record session outcome for closed-loop learning. * POST /api/sessions/{sessionId}/outcome { outcome, reason } * sessionId is the Claude session ID string (not numeric DB ID). */ setSessionOutcome(sessionId: string, outcome: string, reason?: string): Promise; /** * Get file-context observations for a specific file. * GET /api/context/by-file?path={file}&project={project}&limit={limit} */ getFileContext(file: string, project: string, limit?: number, timeoutMs?: number): Promise; /** * Get timeline of observations. * POST /api/context/search with timeline params. */ getTimeline(project: string, mode: 'recent' | 'anchor' | 'query', params?: { query?: string; anchor_id?: number; limit?: number; }): Promise; /** * Store an encrypted credential in the vault. * POST /api/vault/credentials { name, value, scope, project } */ storeCredential(name: string, value: string, scope: string, project?: string): Promise; /** * Retrieve and decrypt a credential from the vault. * GET /api/vault/credentials/{name} */ getCredential(name: string): Promise<{ name: string; value: string; } | null>; listIssues(params: { project?: string; source_project?: string; status?: string; limit?: number; offset?: number; }): Promise; getIssue(id: number): Promise; createIssue(body: CreateIssueRequest): Promise; updateIssue(id: number, body: UpdateIssueRequest): Promise<{ message: string; } | null>; /** Returns true if the server is currently considered reachable. */ isAvailable(): boolean; private get; private post; private request; } //# sourceMappingURL=client.d.ts.map