import type { KnowledgeStore } from '../store.js'; import type { KnowledgeSourceRecord } from '../types.js'; import type { KnowledgeObjectProfilePolicy } from '../extensions.js'; import type { KnowledgeSemanticAnswerInput, KnowledgeSemanticAnswerResult, KnowledgeSemanticEnrichmentResult, KnowledgeSemanticGapRepairer, KnowledgeSemanticLlm, KnowledgeSemanticSelfImproveInput, KnowledgeSemanticSelfImproveResult } from './types.js'; export interface KnowledgeSemanticServiceOptions { readonly llm?: KnowledgeSemanticLlm | null | undefined; readonly maxLlmSourcesPerReindex?: number | undefined; readonly gapRepairer?: KnowledgeSemanticGapRepairer | null | undefined; readonly maxReindexRunMs?: number | undefined; readonly backgroundRepairDelayMs?: number | undefined; readonly backgroundRepairLimit?: number | undefined; readonly objectProfiles?: readonly KnowledgeObjectProfilePolicy[] | undefined; /** * Minimum floor (ms) enforced on EVERY background self-improvement schedule. * A background run can never be scheduled sooner than this even when a caller * asks for `delayMs=0`, that bare-zero path is what turned an enrichment * burst into a CPU-bound hot loop. Default 5000. */ readonly backgroundSelfImproveMinDelayMs?: number | undefined; /** * After a background run finds ZERO candidate gaps, further self-scheduled * runs for that scope are suppressed for this window (ms), the work backs off * to the hourly reindex schedule instead of self-perpetuating. Default * 3_600_000 (one hour, matching the reindex cadence). */ readonly backgroundSelfImproveZeroGapBackoffMs?: number | undefined; /** * Backpressure gate the MemoryGovernor drives: when it returns true the * background self-improvement job is paused and new runs are not scheduled * (the foreground path is untouched). Wired from the daemon composition. */ readonly isBackgroundPaused?: (() => boolean) | undefined; /** * MemoryGovernor admission gate: consulted before a background run fires and * before an explicit reindex, at the critical tier the run is refused with * an honest structured reason instead of allocating toward OOM. */ readonly admitExpensiveWork?: ((label: string) => { allowed: boolean; reason?: string | undefined; }) | undefined; /** Test seam: timer scheduling (defaults to scheduleBackground). */ readonly scheduleSeam?: ((callback: () => void, delayMs: number) => void) | undefined; /** Test seam: clock (defaults to Date.now). */ readonly now?: (() => number) | undefined; } export declare class KnowledgeSemanticService { private readonly store; private options; private readonly activeGapRepairs; private readonly activeSelfImprovementRuns; constructor(store: KnowledgeStore, options?: KnowledgeSemanticServiceOptions); /** * The configured semantic LLM, or null when unconfigured. Home Graph issue * triage prompts through this the same way `enrichment.ts`/`answer-llm.ts` do * inside this service; exposing it lets the Home Graph refinement loop share the * one model route without re-plumbing a provider registry. */ get llm(): KnowledgeSemanticLlm | null; setGapRepairer(gapRepairer: KnowledgeSemanticGapRepairer | null | undefined): void; addObjectProfiles(profiles: readonly KnowledgeObjectProfilePolicy[] | null | undefined): void; enrichSource(sourceId: string, input?: { readonly force?: boolean | undefined; readonly knowledgeSpaceId?: string | undefined; }): Promise; enrichSources(sources: readonly KnowledgeSourceRecord[], input?: { readonly force?: boolean; readonly knowledgeSpaceId?: string; readonly limit?: number; }): Promise; reindex(input?: { readonly sourceIds?: readonly string[] | undefined; readonly limit?: number | undefined; readonly maxRunMs?: number | undefined; readonly force?: boolean | undefined; readonly knowledgeSpaceId?: string | undefined; }): Promise<{ readonly scanned: number; readonly enriched: number; readonly skipped: number; readonly failed: number; readonly errors: readonly { readonly sourceId: string; readonly error: string; }[]; readonly selfImprovement: KnowledgeSemanticSelfImproveResult; }>; answer(input: KnowledgeSemanticAnswerInput): Promise; repairAnswerGaps(input: { readonly answer: KnowledgeSemanticAnswerResult; readonly maxRunMs?: number | undefined; readonly limit?: number | undefined; }): Promise; private runAnswerRefinementInBackground; /** The governed background scheduler (floor/coalesce/backoff/pause/admit). */ private readonly backgroundScheduler; /** * THE background self-improvement entry point: every trigger (enrichment * tails, answer refinement, Home Graph ingest, knowledge-service ingest) * routes through the governed scheduler, see background-scheduler.ts for * the five guards. Public so out-of-package producers (home-graph) use it. */ queueBackgroundSelfImprove(input: KnowledgeSemanticSelfImproveInput, delayMs?: number): void; selfImprove(input?: KnowledgeSemanticSelfImproveInput, runOptions?: { readonly stopWhenPaused?: boolean; }): Promise; /** True when a background run should stop at the next safe yield point. */ private backgroundStopRequested; /** Public pause probe so producers (home-graph ask/ingest tails) can defer their own background work. */ isBackgroundWorkPaused(): boolean; /** Public admission probe (MemoryGovernor critical tier) for producers' own expensive tails. */ admitBackgroundWork(label: string): { allowed: boolean; reason?: string | undefined; }; private runSelfImproveUnlocked; /** * Collect every distinct non-stale knowledge-space id across all sources and * nodes in ONE cursor pass over each collection (O(N)), yielding to the * event loop every SELF_IMPROVE_SPACE_PAGE_SIZE records so a huge store * never blocks the loop, and honoring a stop signal at each yield. */ private collectSemanticSpaceIds; private taskIdsForGaps; private waitForActiveAnswerGapRepairs; } //# sourceMappingURL=service.d.ts.map