The package requires Node.js 20 or newer.
Server factories
createCogniResourceServer
Use the reference registry and executor.
createCogniServer
Use custom execution that emits a valid event sequence.
CogniServerHandlers requires:
Both factories return:
Context.
Resource registry
PredictionResourceRegistry
The registry maps stable names to host validation and resolution. Authorization remains host-owned.
definition(name: string): PredictionResourceDefinition<Context> | undefinedhas(name: string): booleanregister<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
CogniResourceFailure
prediction.failed event. retryable defaults to
false.
Executor
createPredictionExecutor
The executor applies confidence gates, concurrency, cancellation, and deadlines.
The returned executor exposes:
PredictionExecutorInput contains batch, context, request, and signal.
Errors
CogniServerError
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.