Skip to main content
Choose the registry-backed reference server or supply custom execution behind the wire handlers: The package requires Node.js 20 or newer.

Server factories

createCogniResourceServer

Use the reference registry and executor.
Options are:

createCogniServer

Use custom execution that emits a valid event sequence.
CogniServerHandlers requires: Both factories return:
The host chooses routes, authenticates requests, and constructs Context.

Resource registry

PredictionResourceRegistry

The registry maps stable names to host validation and resolution. Authorization remains host-owned.
Methods:
  • definition(name: string): PredictionResourceDefinition<Context> | undefined
  • has(name: string): boolean
  • register<Parameters>(name, definition): this
PredictionResourceDefinition has optional validate(parameters) and required resolve(input). validate receives a read-only JSON object. resolve receives: The resolver returns PredictionResourceResult with required payload and optional bytes, etag, expiresAt, and materialWork.

CogniResourceRejection

Throw from parameter validation to produce a candidate rejection reason without acceptance.

CogniResourceFailure

Throw from a resolver to produce a classified prediction.failed event. retryable defaults to false.

Executor

createPredictionExecutor

The executor applies confidence gates, concurrency, cancellation, and deadlines.
Options: The returned executor exposes:
PredictionExecutorInput contains batch, context, request, and signal.

Errors

CogniServerError

This becomes application/problem+json. Validation failures use HTTP 400; uncaught failures become a generic HTTP 500 without internal details.

Input types

Additional server type exports are CogniResourceServerOptions, CogniServer, CogniServerHandlers, PredictionExecutor, PredictionExecutorInput, PredictionExecutorOptions, PredictionResourceDefinition, PredictionResourceInput, and PredictionResourceResult.

Protocol types

The package re-exports these version 1 types: BackendCapabilities, PredictionAcceptedEvent, PredictionBatchCompletedEvent, PredictionBatchRequest, PredictionBatchResponse, PredictionBatchSummary, PredictionCandidateRequest, PredictionCost, PredictionEvent, PredictionFailedEvent, PredictionFailureCode, PredictionOutcome, PredictionOutcomeBatch, PredictionOutcomeRecord, PredictionRejectedEvent, PredictionRejectionReason, PredictionResolvedEvent, PredictionWork, Problem, ProtocolVersion, ResolvedResource, and ResourceRequest. Their wire fields and lifecycle rules are documented in the backend contract.