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.
cancel(key: string): voidcancels active work by stable key.dispose(): voidrejects new work and cancels active work.markReused(key: string): booleanattributes reuse to active work.predict(candidate: PredictionCandidate, loader: PredictionLoader): PredictionHandleadmits or rejects a candidate.quality(filter?: PredictionQualityFilter): PredictionQualitySnapshotsummarizes bounded terminal history.subscribe(listener: PredictionEventListener): () => voidobserves lifecycle events without replacing the host’sonEventcallback.
PredictionCoordinatorOptions fields:
PredictionScheduler
The scheduler waits for configured delays, idle time, foreground quiet, and allowed environments.
cancel(key: string): voidcancels pending or coordinator-owned work.coordinator: PredictionCoordinatorreturns the underlying coordinator.dispose(): voidcancels pending work and disposes an internally created coordinator.environmentAllowed: booleanreturns the current environment gate.foregroundActivity: numberreturns the current foreground count.schedule(candidate, loader, options?): ScheduledPredictionschedules one candidate.setEnvironmentAllowed(allowed: boolean): voidupdates the environment gate.setForegroundActivity(count: number): voidupdates the non-negative active foreground count.subscribe(listener: PredictionSchedulerEventListener): () => voidobserves scheduling and gate changes.
PredictionSchedulerOptions fields:
PredictionScheduleOptions fields:
IntentPrefetchController
This controller coalesces hover, focus, touch, and pointer signals into one callback.
cancel(): voidcancels a pending delayed run.dispose(): voidcancels pending work and ignores future calls.runNow(value: Value): voidcancels pending delay and executes immediately.schedule(value: Value): voidreplaces any pending value and runs afterdelayMs.
delayMs with a 120 ms default, required run, optional onError, and optional
PredictionRuntime.
NavigationMetrics
Navigation metrics measure lead time. Pair them with coordinator outcomes to measure useful reuse.
clear(key?: string): voidrecordNavigationCompleted(key: string, at?: number): NavigationMetric | undefinedrecordNavigationStarted(key: string, at?: number): voidrecordPrefetchSettled(key: string, at?: number): voidrecordPrefetchStarted(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?): booleancreateBrowserPredictionCalibration(options): PredictionCalibrationControllercreateBrowserPredictionSchedulerRuntime(host?): PredictionSchedulerRuntimeevaluateBrowserPredictionEnvironment(environment?): BrowserPredictionDecisionobserveBrowserPredictionEnvironment(listener, environment?): () => void
Adaptive calibration
Import the storage-agnostic model from@inttegro/cogni-client/learning.
AdaptivePredictionCalibrator
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 materialreusedormissedoutcomes 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.IndexedDbAdaptiveCalibrationStorestores 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.
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:
CogniBackendErrorcontains the HTTPstatusand optional parsedproblem.CogniProtocolErrorreports invalid local requests, response media types, messages, and event sequences.
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.
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.