Skip to main content
Start with the integration question: The client exposes four entry points. During the 0.x series, minor releases may change public APIs and will include migration notes in the changelog.

Core

Import framework-neutral primitives from @inttegro/cogni-client.

PredictionCoordinator

The coordinator admits, deduplicates, bounds, and records predictions.
Methods:
  • cancel(key: string): void cancels active work by stable key.
  • dispose(): void rejects new work and cancels active work.
  • markReused(key: string): boolean attributes reuse to active work.
  • predict(candidate: PredictionCandidate, loader: PredictionLoader): PredictionHandle admits or rejects a candidate.
  • quality(filter?: PredictionQualityFilter): PredictionQualitySnapshot summarizes bounded terminal history.
  • subscribe(listener: PredictionEventListener): () => void observes lifecycle events without replacing the host’s onEvent callback.
PredictionCoordinatorOptions fields:

PredictionScheduler

The scheduler waits for configured delays, idle time, foreground quiet, and allowed environments.
Members:
  • cancel(key: string): void cancels pending or coordinator-owned work.
  • coordinator: PredictionCoordinator returns the underlying coordinator.
  • dispose(): void cancels pending work and disposes an internally created coordinator.
  • environmentAllowed: boolean returns the current environment gate.
  • foregroundActivity: number returns the current foreground count.
  • schedule(candidate, loader, options?): ScheduledPrediction schedules one candidate.
  • setEnvironmentAllowed(allowed: boolean): void updates the environment gate.
  • setForegroundActivity(count: number): void updates the non-negative active foreground count.
  • subscribe(listener: PredictionSchedulerEventListener): () => void observes scheduling and gate changes.
PredictionSchedulerOptions fields: PredictionScheduleOptions fields:

IntentPrefetchController

This controller coalesces hover, focus, touch, and pointer signals into one callback.
Methods:
  • cancel(): void cancels a pending delayed run.
  • dispose(): void cancels pending work and ignores future calls.
  • runNow(value: Value): void cancels pending delay and executes immediately.
  • schedule(value: Value): void replaces any pending value and runs after delayMs.
Options are delayMs with a 120 ms default, required run, optional onError, and optional PredictionRuntime. Navigation metrics measure lead time. Pair them with coordinator outcomes to measure useful reuse.
Methods:
  • clear(key?: string): void
  • recordNavigationCompleted(key: string, at?: number): NavigationMetric | undefined
  • recordNavigationStarted(key: string, at?: number): void
  • recordPrefetchSettled(key: string, at?: number): void
  • recordPrefetchStarted(key: string, at?: number): void
NavigationMetricsOptions fields are maxPending with default 24, now, onComplete, and ttlMs with default 120000.

Main type exports

All current main-entry type exports are listed below.

Browser

Import from @inttegro/cogni-client/browser to apply visibility, connection, and idle signals. Functions:
  • browserAllowsPrediction(environment?): boolean
  • createBrowserPredictionCalibration(options): PredictionCalibrationController
  • createBrowserPredictionSchedulerRuntime(host?): PredictionSchedulerRuntime
  • evaluateBrowserPredictionEnvironment(environment?): BrowserPredictionDecision
  • observeBrowserPredictionEnvironment(listener, environment?): () => void
Type exports:

Adaptive calibration

Import the storage-agnostic model from @inttegro/cogni-client/learning.

AdaptivePredictionCalibrator

Methods:
  • calibrate(input): Promise<AdaptiveCalibrationResult> returns a cloned candidate with its final probability and inspectable calibration metadata.
  • observeChoice(observation): Promise<number> learns a committed destination against a bounded, host-approved candidate set, including candidates that did not run.
  • observe(observation): Promise<boolean> records material reused or missed outcomes and returns whether the model learned from the outcome.
  • clearSubject(subjectKey): Promise<void> removes this namespace’s aggregate evidence for one opaque subject.
AdaptiveCalibratorOptions requires an AdaptiveCalibrationStore. Defaults are namespace default, a 14-day half-life, prior strength 8, minimum evidence 5, confidence scale 12, maximum adjustment 0.2, and at most 32 choice destinations. InMemoryAdaptiveCalibrationStore supports tests and process-local use. Implement AdaptiveCalibrationStore to use another atomic persistence layer. Import browser persistence and identity helpers from @inttegro/cogni-client/learning/browser:
  • createBrowserPredictionCalibration(options) creates the default fail-open learning controller.
  • IndexedDbAdaptiveCalibrationStore stores aggregate weights in IndexedDB.
  • getOrCreateCogniDeviceKey() creates a random browser-profile key in local storage.
  • composeUserDeviceSubjectKey(opaqueUserKey, deviceKey) creates the local subject partition. The user key must already be opaque and must not contain direct identifiers.
Framework-owned browser runtimes create this controller automatically. They require only the opaque authenticated account key; there is no learning feature flag. Missing, cleared, blocked, or replaced browser storage starts a fresh model and never blocks prediction or navigation.

Backend protocol

Import from @inttegro/cogni-client/protocol; the host supplies the route map.

createCogniBackendClient

CogniBackendClientOptions fields: CogniBackendRoutes requires non-empty capabilities, outcomes, and predictions strings. The returned client has:
ExecutePredictionsOptions fields are onEvent, signal, and transport, where transport is json or ndjson and defaults to ndjson. Error exports:
  • CogniBackendError contains the HTTP status and optional parsed problem.
  • CogniProtocolError reports invalid local requests, response media types, messages, and event sequences.
Protocol type exports: BackendCapabilities, PredictionAcceptedEvent, PredictionBatchCompletedEvent, PredictionBatchRequest, PredictionBatchResponse, PredictionBatchSummary, PredictionCandidateRequest, PredictionCost, PredictionEvent, PredictionFailedEvent, PredictionFailureCode, PredictionOutcome, PredictionOutcomeBatch, PredictionOutcomeRecord, PredictionRejectedEvent, PredictionRejectionReason, PredictionResolvedEvent, PredictionWork, Problem, ProtocolVersion, ResolvedResource, and ResourceRequest. These types mirror the backend contract; their field names use snake_case.

Chrome ranking

The optional Chrome ranker may reorder a host allowlist. It cannot invent candidates, assign probabilities, or start work.
Options: Additional type exports are ChromeLanguageModelApi, ChromeLanguageModelCreateOptions, ChromeLanguageModelSession, ChromePromptCandidateRankerEvent, ChromePromptCandidateRankerOptions, and ChromePromptRankerUnavailableReason. The adapter validates every ID against the allowlist and returns null when unavailable, cancelled, or invalid. It ranks at most eight candidates by default.