Skip to content

JavaScript/TypeScript Core API

@nnrp/core contains runtime-neutral types and helpers shared by the JavaScript role and transport packages.

Constants

NameTypeValue
NNRP_PROTOCOL_NAME"NNRP"Protocol name.
NNRP_PROTOCOL_VERSION"1.0.0"Protocol version.
NNRP_STANDARD_INPUT_PROFILESreadonly tupletensor, token, structured_event, tool_delta.

createCapabilityManifest

Creates a build-mode-specific capability manifest.

ParameterTypeRequiredDescription
optionsNnrpCapabilityManifestOptionsYesBuild mode, transports, and capability claims.
Returns
NnrpCapabilityManifest
ts
import { createCapabilityManifest } from "@nnrp/core";

const manifest = createCapabilityManifest({
  buildMode: "backend-native",
  transports: ["tcp", "quic"],
  capabilities: ["client.session"],
});

createBackendNativeManifest

Creates the default backend native capability manifest.

ParameterTypeRequiredDescription
capabilitiesreadonly NnrpCapability[]NoExtra capability claims.
Returns
NnrpCapabilityManifest

createBrowserWasmManifest

Creates the default browser WASM capability manifest.

ParameterTypeRequiredDescription
capabilitiesreadonly NnrpCapability[]NoExtra capability claims.
Returns
NnrpCapabilityManifest

selectTransport

Selects the highest-scored eligible transport candidate under a policy.

ParameterTypeRequiredDescription
candidatesreadonly NnrpTransportCandidate[]YesCandidate transports.
policyNnrpTransportPolicyNoauto, one of the prefer-* policies, or one of the force-* policies.
Returns
NnrpTransportSelection

createTransportCandidates

Builds transport candidates from local and peer manifests.

ParameterTypeRequiredDescription
optionsNnrpTransportCandidateOptionsYesLocal manifest, peer manifest, and optional scores.
Returns
readonly NnrpTransportCandidate[]

createTransportSelectionSummary

Creates a compact selection summary for diagnostics, conformance, and benchmarks.

ParameterTypeRequiredDescription
selectionNnrpTransportSelectionYesFull selection object.
Returns
NnrpTransportSelectionSummary

parseApplicationEndpoint

Parses and validates the public application endpoint. The function accepts only nnrp:// and nnrps:// and returns a URL, preserving the authority, path, query, and security intent.

ParameterTypeRequiredDescription
endpointstring | URLYesPublic NNRP application endpoint.
ReturnsThrows
URLNnrpProtocolError for empty, malformed, or provider-local endpoints.

resolveProviderEndpoint

Resolves the carrier-local endpoint after provider selection. TCP and QUIC derive host:port from the application authority and use port 4433 when it is omitted. IPC and WebSocket require an explicit matching provider endpoint.

ParameterTypeRequiredDescription
endpointstring | URLYesPublic nnrp:// or nnrps:// endpoint.
transportNnrpTransportKindYesSelected carrier.
providerEndpointstring | URLNoExplicit carrier-local endpoint.
ReturnsThrows
stringNnrpTransportError when the selected carrier cannot resolve the supplied locator.

normalizeSubmitRequest

Validates and normalizes submit payloads.

ParameterTypeRequiredDescription
requestNnrpSubmitRequestYesSubmit request.
optionsNormalizeSubmitRequestOptionsNoPayload copy and strict profile options.
ReturnsThrows
NnrpNormalizedSubmitRequestNnrpProtocolError for invalid frame, payload, cache, schema, or profile fields.

normalizeOperationRef

Normalizes an operation id.

ParameterTypeRequiredDescription
operationbigint | numberYesOperation id.
ReturnsThrows
bigintNnrpProtocolError for negative or unsafe ids.

validateEventPollOptions

Validates event polling options.

ParameterTypeRequiredDescription
optionsNnrpEventPollOptionsNoTimeout options.
ReturnsThrows
voidNnrpProtocolError for invalid timeout values.

Data Types

Capability and Transport

TypeDescription
NnrpBuildMode"backend-native" | "browser-wasm".
NnrpTransportKind"tcp" | "quic" | "ipc" | "websocket".
NnrpTransportPolicy"auto", "prefer-quic", "prefer-tcp", "prefer-ipc", "prefer-websocket", and the four corresponding force-* values.
NnrpCapabilityCapability claim such as client.session, server.session, native.loader, wasm.loader, cache, schema, or recovery.
NnrpCapabilityManifestProtocol name/version, build mode, transports, and capabilities.
NnrpTransportCandidateCandidate transport, availability, score, rejection reason, and diagnostic.
NnrpTransportSelectionSummarySelected transport plus rejected candidates.

Submit, Result, and Events

TypeDescription
NnrpInputProfileOne of the standard profiles: tensor, token, structured_event, or tool_delta.
NnrpSubmitMode"inline" | "object-reference".
NnrpSubmitRequestFrame id, payload/tensors, input profile, submit mode, cache key, descriptor, and metadata.
NnrpResultFrame id, optional payload, optional diagnostic, and metadata.
NnrpRuntimeEventResult, flow update, result hint, drop, close, or diagnostic event.
NnrpEventPollOptionsOptional timeoutMillis.

Errors

ClassDescription
NnrpErrorBase error with structured diagnostic.
NnrpCapabilityErrorCapability, manifest, or unsupported runtime error.
NnrpTransportErrorTransport error.
NnrpTimeoutErrorTimeout error.
NnrpProtocolErrorRequest shape or protocol validation error.

NNRP Documentation