Runtime

View as Markdown

Generated from crates/node/index.d.ts.

Import from nemo-relay-node.

Main runtime lifecycle, scope, middleware, subscriber, and exporter APIs.

Interfaces

PropagationContext

Transport-neutral Relay causal context for application-managed transport.

export interface PropagationContext {
version: number
rootUuid?: string
parentUuid: string
traceparent?: string
tracestate?: string
}

RuntimeRegistrationOwner

Discovery metadata describing the owner of a runtime registration.

export interface RuntimeRegistrationOwner {
kind: RuntimeRegistrationOwnerKind
pluginKind?: string
componentOrdinal?: number
}

RuntimeRegistrationIdentity

Structured identity for one global gateable runtime registration.

export interface RuntimeRegistrationIdentity {
kind: RuntimeRegistrationKind
localName: string
effectiveName: string
owner: RuntimeRegistrationOwner
}

AtofExporterConfig

One tagged sink configuration for AtofExporter.

export interface AtofExporterConfig {
/** Sink type: `"file"` (default) or `"stream"`. */
type?: string
/** Output directory. Defaults to the current working directory. */
outputDirectory?: string
/** `"append"` (default) or `"overwrite"`. */
mode?: string
/** Output filename. Defaults to `nemo-relay-events-YYYY-MM-DD-HH.MM.SS.jsonl`. */
filename?: string
/** Stream endpoint URL. Required when `type` is `"stream"`. */
url?: string
/** `"http_post"` (default), `"websocket"`, or `"ndjson"`. */
transport?: string
/** Extra stream headers as string key/value pairs. */
headers?: Json
/** Header names mapped to environment variables that supply their values. */
headerEnv?: Json
/** Per-stream timeout in milliseconds. */
timeoutMillis?: number
/** Field name policy applied before sending stream events. */
fieldNamePolicy?: string
}

OpenTelemetryConfig

Mutable configuration object for OpenTelemetrySubscriber.

export interface OpenTelemetryConfig {
/** `"full"`, `"gen_ai"`, or `"openinference"`. */
type: "full" | "gen_ai" | "openinference"
/** `"http_binary"` (default) or `"grpc"`. */
transport?: string
/** OTLP endpoint, such as `http://localhost:4318/v1/traces`. */
endpoint: string
/** Extra exporter headers/metadata as string key/value pairs. */
headers?: Json
/** Header names mapped to environment variables resolved during subscriber activation. */
headerEnv?: Record<string, string>
/** Extra OpenTelemetry resource attributes as string key/value pairs. */
resourceAttributes?: Json
/** `service.name` resource attribute. Defaults to `"unknown_service"`. */
serviceName?: string
/** Optional `service.namespace` resource attribute. */
serviceNamespace?: string
/** Optional `service.version` resource attribute. */
serviceVersion?: string
/** Instrumentation scope name. Defaults to `"opentelemetry"`. */
instrumentationScope?: string
/** Export timeout in milliseconds. Defaults to `3000`. */
timeoutMillis?: number
/** Completed scope lineage retention in milliseconds as a `bigint`. Defaults to `60000`. */
completedSpanContextTtlMillis?: bigint
/** Mark projection for full and OpenInference exporters. Defaults to `"inherit"`. */
markProjection?: "inherit" | "event" | "tool"
/** Mark names excluded from full and OpenInference projections. */
markExcludeNames?: Array<string>
/** Attribute aliases for full and OpenInference projections. */
attributeMappings?: Json
/** Literal Event metadata prefixes copied to top-level OTLP attributes. */
promoteMetadataPrefixes?: Array<string>
/** Literal root-scope Event metadata prefixes copied to OTLP resource attributes. */
promoteResourceMetadataPrefixes?: Array<string>
}

OpenTelemetryFileSinkConfig

Configuration for a subscriber that writes OTLP to a local file.

Carries no endpoint, transport, headers, or timeout: a file destination has no use for them.

export interface OpenTelemetryFileSinkConfig {
/** `"full"`, `"gen_ai"`, or `"openinference"`. */
type: "full" | "gen_ai" | "openinference"
/** Directory containing the output file. */
outputDirectory: string
/** Output filename. Defaults to a name derived from `format`. */
filename?: string
/** `"json_lines"` (default) or `"proto"`. */
format?: "json_lines" | "proto"
/** `"overwrite"` (default) or `"append"`. */
mode?: "append" | "overwrite"
/** Extra OpenTelemetry resource attributes as string key/value pairs. */
resourceAttributes?: Json
/** `service.name` resource attribute. Defaults to `"unknown_service"`. */
serviceName?: string
/** Optional `service.namespace` resource attribute. */
serviceNamespace?: string
/** Optional `service.version` resource attribute. */
serviceVersion?: string
/** Instrumentation scope name. Defaults to `"opentelemetry"`. */
instrumentationScope?: string
/** Completed scope lineage retention in milliseconds as a `bigint`. Defaults to `60000`. */
completedSpanContextTtlMillis?: bigint
/** Mark projection for full and OpenInference exporters. Defaults to `"inherit"`. */
markProjection?: "inherit" | "event" | "tool"
/** Mark names excluded from full and OpenInference projections. */
markExcludeNames?: Array<string>
/** Attribute aliases for full and OpenInference projections. */
attributeMappings?: Json
/** Literal Event metadata prefixes copied to top-level OTLP attributes. */
promoteMetadataPrefixes?: Array<string>
/** Literal root-scope Event metadata prefixes copied to OTLP resource attributes. */
promoteResourceMetadataPrefixes?: Array<string>
}

OpenTelemetryLogConfig

Configuration object for OpenTelemetryLogSubscriber.

export interface OpenTelemetryLogConfig {
/** OTLP endpoint. Bare HTTP origins append `/v1/logs`. */
endpoint: string
/** `"http_binary"` (default) or `"grpc"`. */
transport?: "http_binary" | "grpc"
/** Extra exporter headers/metadata as string key/value pairs. */
headers?: Record<string, string>
/** Header names mapped to environment variables resolved during subscriber activation. */
headerEnv?: Record<string, string>
/** Extra OpenTelemetry resource attributes as string key/value pairs. */
resourceAttributes?: Record<string, string>
/** `service.name` resource attribute. Defaults to `"unknown_service"`. */
serviceName?: string
/** Optional `service.namespace` resource attribute. */
serviceNamespace?: string
/** Optional `service.version` resource attribute. */
serviceVersion?: string
/** Instrumentation scope name. Defaults to `"opentelemetry"`. */
instrumentationScope?: string
/** Export timeout in milliseconds. Defaults to `3000`. */
timeoutMillis?: number
/** Minimum severity exported. Defaults to `LogSeverity.Info`. */
minimumSeverity?: LogSeverity
/** Maximum queued log records. Defaults to `2048`. */
maxQueueSize?: number
/** Maximum records per export batch. Defaults to `512`. */
maxExportBatchSize?: number
/** Maximum delay before a partial batch is exported. Defaults to `1000`. */
scheduledDelayMillis?: number
/** Completed scope lineage retention in milliseconds as a `bigint`. Defaults to `60000`. */
completedSpanContextTtlMillis?: bigint
}

OpenTelemetryMetricConfig

Configuration object for OpenTelemetryMetricSubscriber.

export interface OpenTelemetryMetricConfig {
/** OTLP endpoint. Bare HTTP origins append `/v1/metrics`. */
endpoint: string
/** `"http_binary"` (default) or `"grpc"`. */
transport?: "http_binary" | "grpc"
/** Extra exporter headers/metadata as string key/value pairs. */
headers?: Record<string, string>
/** Header names mapped to environment variables resolved during subscriber activation. */
headerEnv?: Record<string, string>
/** Extra OpenTelemetry resource attributes as string key/value pairs. */
resourceAttributes?: Record<string, string>
/** `service.name` resource attribute. Defaults to `"unknown_service"`. */
serviceName?: string
/** Optional `service.namespace` resource attribute. */
serviceNamespace?: string
/** Optional `service.version` resource attribute. */
serviceVersion?: string
/** Instrumentation scope name. Defaults to `"opentelemetry"`. */
instrumentationScope?: string
/** Export timeout in milliseconds. Defaults to `3000`. */
timeoutMillis?: number
/** Collection interval in milliseconds. Defaults to `60000`. */
exportIntervalMillis?: number
/** Preferred aggregation temporality. Defaults to cumulative. */
temporality?: MetricTemporality
/** Maximum number of retained instrument descriptors. Defaults to `256`. */
maxInstruments?: number
/** Maximum series cardinality per instrument. Defaults to `2000`. */
cardinalityLimit?: number
}

JsLlmCodecIdentity

Structured codec identity delivered to JavaScript LLM sanitizers.

export interface JsLlmCodecIdentity {
kind: string
id?: string
}

DataSchema

Schema identifier attached to an event’s opaque data payload.

export interface DataSchema {
name: string
version: string
}

MetricMeasurement

One typed recording operation emitted by metric.

export interface MetricMeasurement {
name: string
kind: MetricKind
valueType: MetricValueType
value: number
unit?: string
description?: string
attributes?: Json
boundaries?: Array<number>
}

ToolExecutionResult

Canonical application-visible result of tool execution.

result is application-owned JSON. annotation is optional opaque adjacent metadata that Relay transports without interpretation.

export interface ToolExecutionResult {
result: Json
annotation?: Json
}

ToolExecutionContext

Per-call context delivered to a tool execution intercept.

toolCallId is the provider-issued correlation identifier recorded on the managed tool call, or null when the call did not record one. It lets an intercept that completes execution without invoking the remaining chain associate its result with the originating tool call.

export interface ToolExecutionContext {
toolName: string
args: Json
toolCallId: string | null
}

PendingMarkSpec

A mark Relay materializes under a managed lifecycle.

export interface PendingMarkSpec {
name: string
category?: string | null
categoryProfile?: Json
data?: Json
dataSchema?: { name: string; version: string } | null
metadata?: Json
severity?: 'trace' | 'debug' | 'info' | 'warn' | 'warning' | 'error' | null
}

EventSanitizeFields

Observability fields returned by mark and scope event sanitizers.

export interface EventSanitizeFields {
data?: Json
categoryProfile?: Json
metadata?: Json
}

ResourceMeasurement

export interface ResourceMeasurement<
T extends number | bigint,
U extends DurationUnit | CapacityUnit | DataUnit | BandwidthUnit | CpuUnit | UtilizationUnit | CountUnit,
> {
value: T;
unit: U;
}

ResourceLimitEventCount

export interface ResourceLimitEventCount {
resource: 'cpu' | 'memory' | 'processes';
event: 'throttled' | 'high' | 'maximum' | 'out_of_memory' | 'terminated';
count: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
}

AcceleratorDeviceMetrics

export interface AcceleratorDeviceMetrics {
vendor: AcceleratorVendor;
deviceIdentifier: string;
deviceIndex: number | null;
memoryUsed: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
computeUtilization: ResourceMeasurement<number, UtilizationUnit> | null;
}

AcceleratorProcessMetrics

export interface AcceleratorProcessMetrics {
vendor: AcceleratorVendor;
deviceIdentifier: string;
deviceIndex: number | null;
processId: number;
memoryUsed: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
computeUtilization: ResourceMeasurement<number, UtilizationUnit> | null;
}

FilesystemCapacityMetrics

export interface FilesystemCapacityMetrics {
path: string;
totalCapacity: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
availableCapacity: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
freeCapacity: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
}

CpuMetrics

export interface CpuMetrics {
userTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
systemTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
totalTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
consumptionRate: ResourceMeasurement<number, CpuUnit> | null;
throttledTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
effectiveLimit: ResourceMeasurement<number, CpuUnit> | null;
somePressureStallTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
fullPressureStallTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
limitEvents: ResourceLimitEventCount[];
}

MemoryMetrics

export interface MemoryMetrics {
systemUsed: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
systemTotal: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
systemAvailable: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
resident: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
private: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
physicalFootprint: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
virtualMemory: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
peakResident: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
limit: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
environmentAccounted: ResourceMeasurement<ResourceNumeric, CapacityUnit> | null;
somePressureStallTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
fullPressureStallTime: ResourceMeasurement<ResourceNumeric, DurationUnit> | null;
outOfMemoryEventCount: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
limitEvents: ResourceLimitEventCount[];
}

ProcessMetrics

export interface ProcessMetrics {
activeCount: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
descendantCount: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
threadCount: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
lifetimeCreationCount: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
openFileDescriptorCount: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
windowsHandleCount: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
limitEvents: ResourceLimitEventCount[];
}

DiskMetrics

export interface DiskMetrics {
readData: ResourceMeasurement<ResourceNumeric, DataUnit> | null;
writeData: ResourceMeasurement<ResourceNumeric, DataUnit> | null;
readThroughput: ResourceMeasurement<number, BandwidthUnit> | null;
writeThroughput: ResourceMeasurement<number, BandwidthUnit> | null;
readOperations: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
writeOperations: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
filesystems: FilesystemCapacityMetrics[];
}

GpuMetrics

export interface GpuMetrics {
deviceMetrics: AcceleratorDeviceMetrics[] | null;
processMetrics: AcceleratorProcessMetrics[] | null;
}

NetworkTrafficMetrics

export interface NetworkTrafficMetrics {
receivedData: ResourceMeasurement<ResourceNumeric, DataUnit> | null;
transmittedData: ResourceMeasurement<ResourceNumeric, DataUnit> | null;
receiveThroughput: ResourceMeasurement<number, BandwidthUnit> | null;
transmitThroughput: ResourceMeasurement<number, BandwidthUnit> | null;
receivedPackets: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
transmittedPackets: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
receiveErrors: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
transmitErrors: ResourceMeasurement<ResourceNumeric, CountUnit> | null;
}

NetworkInterfaceMetrics

export interface NetworkInterfaceMetrics {
name: string;
traffic: NetworkTrafficMetrics;
}

NetworkMetrics

export interface NetworkMetrics {
measurementScope: 'global';
system: NetworkTrafficMetrics;
interfaces: NetworkInterfaceMetrics[];
}

ProcessSamplingMetadata

export interface ProcessSamplingMetadata {
visibleProcesses: ResourceNumeric;
sampledProcesses: ResourceNumeric;
/** Readable process counts keyed by canonical snake_case measurement paths. */
fieldSampledProcesses: Record<string, ResourceNumeric>;
}

ResourceMetricsSnapshot

export interface ResourceMetricsSnapshot {
timestamp: string;
operatingSystem: ResourceOperatingSystem;
measurementScope: ResourceMeasurementScope;
processSampling: ProcessSamplingMetadata | null;
cpu: CpuMetrics | null;
memory: MemoryMetrics | null;
process: ProcessMetrics | null;
disk: DiskMetrics | null;
gpu: GpuMetrics | null;
network: NetworkMetrics | null;
}

LlmSanitizeRequestContext

Request codec context shared by sanitizer and execution callbacks.

export interface LlmSanitizeRequestContext {
codec: LlmCodecIdentity;
/** Resolve the active codec for this callback. Do not retain the result after the callback returns. */
resolveCodec(): import('./typed').LlmCodec | null;
}

LlmSanitizeResponseContext

Response codec context shared by sanitizer and execution callbacks.

export interface LlmSanitizeResponseContext {
codec: LlmCodecIdentity;
/** Resolve the active codec for this callback. Do not retain the result after the callback returns. */
resolveCodec(): import('./typed').LlmResponseCodec | null;
}

LlmExecutionContext

Codec capabilities for one managed LLM execution intercept invocation.

export interface LlmExecutionContext {
/** Request codec identity plus optional decode and encode capability. */
requestCodec: LlmRequestContext;
/** Unary response codec identity plus optional decode capability; `null` for streaming execution. */
responseCodec: LlmResponseContext | null;
}

LlmOptimizationDataSchema

Schema tag attached to an opaque optimization contribution payload.

export interface LlmOptimizationDataSchema {
name: string;
version: string;
}

LlmOptimizationModel

Model identity retained for counterfactual pricing and downstream repricing.

export interface LlmOptimizationModel {
model: string;
provider?: string;
}

LlmOptimizationModelTransition

Baseline and effective model identities for a routing optimization.

export interface LlmOptimizationModelTransition {
baseline?: LlmOptimizationModel;
effective?: LlmOptimizationModel;
}

LlmOptimizationTokens

Explicit token evidence, independent from a pricing catalog.

export interface LlmOptimizationTokens {
/** Token counts must be non-negative JavaScript safe integers. */
prompt_tokens?: number;
/** Token counts must be non-negative JavaScript safe integers. */
completion_tokens?: number;
/** Token counts must be non-negative JavaScript safe integers. */
cache_read_tokens?: number;
/** Token counts must be non-negative JavaScript safe integers. */
cache_write_tokens?: number;
/** Token counts must be non-negative JavaScript safe integers. */
total_tokens?: number;
}

LlmOptimizationTokenImpact

Baseline, effective, and saved token evidence for one optimization.

export interface LlmOptimizationTokenImpact {
baseline?: LlmOptimizationTokens;
effective?: LlmOptimizationTokens;
saved?: LlmOptimizationTokens;
quality?: 'observed' | 'estimated';
estimation_method?: string;
}

LlmOptimizationContribution

One plugin’s optimization evidence.

kind is deliberately an open string so new optimizer categories round-trip without a Relay release. Unknown top-level fields are retained by the wire contract and represented by this interface’s JSON extension surface.

export interface LlmOptimizationContribution {
id?: string;
/** Relay ordering must remain within JavaScript's safe-integer range. */
sequence?: number;
producer: string;
kind: 'input_compression' | 'model_routing' | (string & {});
applied: boolean;
model_transition?: LlmOptimizationModelTransition;
token_impact?: LlmOptimizationTokenImpact;
payload_schema?: LlmOptimizationDataSchema;
payload?: Json;
[key: string]: Json | undefined;
}

LlmRequestInterceptOutcome

Canonical result returned by an LLM request intercept.

export interface LlmRequestInterceptOutcome {
request: Json;
annotated?: Json | null;
pendingMarks?: PendingMarkSpec[];
optimizationContributions?: LlmOptimizationContribution[];
}

Classes

AtifExporter

An Agent Trajectory Interchange Format (ATIF) exporter that collects lifecycle events and exports them as a structured trajectory.

Create an instance with session and agent metadata, then register it as an event subscriber. When ready, call exportJson() to serialize the collected trajectory.

export declare class AtifExporter {
/**
* Create a new ATIF exporter.
*
* `sessionId` identifies the session. `agentName` and `agentVersion` describe the agent.
* Optional `modelName` records the LLM model used.
*/
constructor(sessionId: string, agentName: string, agentVersion: string, modelName?: string | undefined | null)
/**
* Register this exporter as an event subscriber with the given name.
*
* Throws if a subscriber with the same `name` already exists.
*/
register(name: string): void
/**
* Deregister this exporter's event subscriber by name.
*
* Returns `true` if a subscriber with that name was found and removed.
*/
deregister(name: string): boolean
/**
* Export the collected trajectory as a JSON string.
*
* Returns a JSON-serialized `AtifTrajectory`.
*/
exportJson(): string
/** Clear all collected events from the exporter. */
clear(): void
}

AtofExporter

Single-sink Agent Trajectory Observability Format (ATOF) exporter.

export declare class AtofExporter {
/**
* Create a new Agent Trajectory Observability Format (ATOF) JSONL exporter
* from a config object.
*/
constructor(config?: AtofExporterConfig | undefined | null)
/** Return the JSONL output path, or `null` for a stream sink. */
get path(): string | null
/** Register this exporter globally with the given name. */
register(name: string): void
/** Deregister a subscriber by name. */
deregister(name: string): boolean
/**
* Outside subscriber and middleware callbacks, wait for queued subscriber delivery, then
* flush the file sink or ask the stream sink to drain for up to its timeout. A stream timeout
* is logged and does not by itself return an error.
*/
forceFlush(): void
/**
* Outside subscriber and middleware callbacks, wait for queued subscriber delivery, then
* flush the file sink or ask the stream sink to drain and close up to its timeout. A stream
* timeout is logged and does not by itself return an error.
*/
shutdown(): void
}

OpenTelemetrySubscriber

OpenTelemetry-backed event subscriber.

export declare class OpenTelemetrySubscriber {
/** Create a new OpenTelemetry subscriber from a config object. */
constructor(config: OpenTelemetryConfig)
/** Create a subscriber that writes OTLP to a local file. */
static fileSink(config: OpenTelemetryFileSinkConfig): OpenTelemetrySubscriber
/** Register this subscriber globally with the given name. */
register(name: string): void
/** Deregister a subscriber by name. */
deregister(name: string): boolean
/**
* Force a flush of finished spans through the exporter.
*
* A successful flush updates `runtimeDiagnostics()` with queue drops observed so far.
*/
forceFlush(): void
/** Return bounded runtime diagnostics recorded by this subscriber. */
runtimeDiagnostics(): Array<{ code: string; message: string; count: number }>
/** Shut down the underlying tracer provider. */
shutdown(): void
}

OpenTelemetryLogSubscriber

Subscriber that exports severity-tagged marks through OTLP logs.

export declare class OpenTelemetryLogSubscriber {
/** Create a log subscriber from a config object. */
constructor(config: OpenTelemetryLogConfig)
/** Register this subscriber globally with the given name. */
register(name: string): void
/** Deregister a subscriber by name. */
deregister(name: string): boolean
/**
* Flush queued Relay events and the OTLP log processor.
*
* A successful flush updates `runtimeDiagnostics()` with queue drops observed so far.
*/
forceFlush(): void
/** Return bounded runtime diagnostics recorded by this subscriber. */
runtimeDiagnostics(): Array<{ code: string; message: string; count: number }>
/** Shut down the underlying logger provider. */
shutdown(): void
}

OpenTelemetryMetricSubscriber

Subscriber that records metric marks and exports them through OTLP metrics.

export declare class OpenTelemetryMetricSubscriber {
/** Create a metric subscriber from a config object. */
constructor(config: OpenTelemetryMetricConfig)
/** Register this subscriber globally with the given name. */
register(name: string): void
/** Deregister a subscriber by name. */
deregister(name: string): boolean
/** Collect and export current metric aggregates immediately. */
forceFlush(): void
/** Return bounded runtime diagnostics recorded by this subscriber. */
runtimeDiagnostics(): Array<{ code: string; message: string; count: number }>
/** Shut down the underlying meter provider. */
shutdown(): void
}

AdaptiveRuntime

Owned adaptive runtime that can register adaptive features outside the plugin system.

export declare class AdaptiveRuntime {
/**
* Create an adaptive runtime wrapper from config.
*
* The runtime is constructed lazily when `register()` is awaited.
*/
constructor(config: Json)
/**
* Register all configured adaptive runtime features.
*
* `register()` and `shutdown()` both temporarily take ownership of the
* runtime state, so concurrent calls are mutually exclusive by design.
* Once either operation takes the state, another concurrent registration or
* shutdown attempt fails with "adaptive runtime already shut down". This
* prevents double-registration and shutdown-during-registration races.
*/
register(): Promise<void>
/** Deregister all previously registered adaptive runtime features. */
deregister(): void
/** Shut down the adaptive runtime and consume its Rust runtime state. */
shutdown(): Promise<void>
/** Block until the telemetry drain has processed pending events. */
waitForIdle(): void
/** Return the validation report captured during runtime construction. */
report(): Json
/** Bind the runtime's ACG request rewrite to a scope. */
bindScope(scopeHandle: ScopeHandle): void
/** Build cache request facts for an annotated LLM request. */
buildCacheRequestFacts(options: Json): Json | null
}

PluginHostActivation

Owned dynamic plugin activation.

Keep this object alive while code may invoke callbacks registered by the dynamic plugins. Call close() for deterministic cleanup; garbage collection performs the same cleanup as a defensive fallback.

export declare class PluginHostActivation {
/** Return the validation report produced by activation. */
get report(): Json
/**
* Return whether this activation handle has not begun teardown.
*
* Failed teardown leaves the activation active so `close()` can retry.
*/
get isActive(): boolean
/**
* Clear plugin callbacks before unloading libraries and workers.
*
* This method is idempotent, including when concurrent callers race to
* close the same activation.
*/
close(): Promise<void>
/**
* Supply the structured disposal signature to napi-rs declaration generation.
*
* Module initialization installs `close()` under the actual well-known
* symbol and removes this string-named declaration shim from the prototype.
*/
[Symbol.asyncDispose](): Promise<void>
}

LlmStream

An async iterator over chunks from a streaming LLM response.

Obtained from llmStreamCallExecute(). Call next() repeatedly to consume response chunks. Returns null when the stream is fully consumed.

export declare class LlmStream {
/**
* Retrieve the next chunk from the stream.
*
* Returns the next JSON chunk, or `null` when the stream is exhausted.
* Throws if the underlying stream encountered an error.
*/
next(): Promise<Json | null>
/** Stop the producer and wait for its cleanup to complete. */
close(): Promise<void>
}

ScopeStack

Handle to an isolated scope stack for per-request/per-task isolation.

export declare class ScopeStack {
/** Creates a new isolated scope stack with its own root scope. */
constructor()
}

ScopeHandle

A handle to an execution scope in the agent runtime.

Scopes form a hierarchical stack representing the current execution context (e.g., agent -> function -> tool). Use this handle to reference a specific scope when pushing child scopes, emitting events, or making tool/LLM calls.

export declare class ScopeHandle {
/** The unique identifier for this scope. */
get uuid(): string
/** The human-readable name of this scope. */
get name(): string
/** The type of this scope (Agent, Tool, Llm, etc.). */
get scopeType(): ScopeType
/** Bitfield of scope attributes (e.g., PARALLEL, RELOCATABLE). */
get attributes(): number
/** The UUID of this scope's parent, or `null` if this is the root scope. */
get parentUuid(): string | null
/** Optional user-defined data associated with this scope. */
get data(): any | null
/** Optional metadata associated with this scope. */
get metadata(): any | null
}

ToolHandle

A handle representing an in-progress tool call.

Returned by toolCall() and used to signal completion via toolCallEnd().

export declare class ToolHandle {
/** The unique identifier for this tool call. */
get uuid(): string
/** The name of the tool being called. */
get name(): string
/** Bitfield of tool attributes (e.g., LOCAL). */
get attributes(): number
/** The UUID of the parent scope that initiated this tool call, or `null`. */
get parentUuid(): string | null
}

LlmHandle

A handle representing an in-progress LLM call.

Returned by llmCall() and used to signal completion via llmCallEnd().

export declare class LlmHandle {
/** The unique identifier for this LLM call. */
get uuid(): string
/** The name of the LLM provider being called. */
get name(): string
/** Bitfield of LLM attributes (e.g., STATELESS, STREAMING). */
get attributes(): number
/** The UUID of the parent scope that initiated this LLM call, or `null`. */
get parentUuid(): string | null
}

LlmRequest

An LLM request, encapsulating headers and content.

Construct via new LlmRequest(headers, content).

export declare class LlmRequest {
/** Create a new LLM request from headers and content. */
constructor(headers: any, content: any)
/** The metadata headers as a JSON object. */
get headers(): any
/** The request payload as a JSON value. */
get content(): any
}

OpenAIChatCodec

Built-in codec for the OpenAI Chat Completions API.

Implements both request codec (decode/encode) and response codec (decodeResponse). Construct with new OpenAIChatCodec().

export declare class OpenAIChatCodec {
constructor()
/** Decode an opaque LLM request into structured form. */
decode(request: Json): Json
/** Encode structured changes back into an opaque LLM request. */
encode(annotated: Json, original: Json): Json
/** Decode a raw LLM response into structured form. */
decodeResponse(response: Json): Json
}

OpenAIResponsesCodec

Built-in codec for the OpenAI Responses API.

Implements both request codec (decode/encode) and response codec (decodeResponse). Construct with new OpenAIResponsesCodec().

export declare class OpenAIResponsesCodec {
constructor()
/** Decode an opaque LLM request into structured form. */
decode(request: Json): Json
/** Encode structured changes back into an opaque LLM request. */
encode(annotated: Json, original: Json): Json
/** Decode a raw LLM response into structured form. */
decodeResponse(response: Json): Json
}

GeminiGenerateContentCodec

Built-in codec for the Gemini generateContent API.

Implements both request codec (decode/encode) and response codec (decodeResponse). Construct with new GeminiGenerateContentCodec().

export declare class GeminiGenerateContentCodec {
constructor()
/** Decode an opaque LLM request into structured form. */
decode(request: Json): Json
/** Encode structured changes back into an opaque LLM request. */
encode(annotated: Json, original: Json): Json
/** Decode a raw LLM response into structured form. */
decodeResponse(response: Json): Json
}

AnthropicMessagesCodec

Built-in codec for the Anthropic Messages API.

Implements both request codec (decode/encode) and response codec (decodeResponse). Construct with new AnthropicMessagesCodec().

export declare class AnthropicMessagesCodec {
constructor()
/** Decode an opaque LLM request into structured form. */
decode(request: Json): Json
/** Encode structured changes back into an opaque LLM request. */
encode(annotated: Json, original: Json): Json
/** Decode a raw LLM response into structured form. */
decodeResponse(response: Json): Json
}

OCIGenAIChatCodec

Built-in codec for the OCI Generative AI chat API.

Implements both request codec (decode/encode) and response codec (decodeResponse). Construct with new OCIGenAIChatCodec().

export declare class OCIGenAIChatCodec {
constructor()
/** Decode an opaque LLM request into structured form. */
decode(request: Json): Json
/** Encode structured changes back into an opaque LLM request. */
encode(annotated: Json, original: Json): Json
/** Decode a raw LLM response into structured form. */
decodeResponse(response: Json): Json
}

Enums

RuntimeRegistrationKind

A global runtime registration surface that a conditional middleware guardrail can select.

export const enum RuntimeRegistrationKind {
Subscriber = 'subscriber',
EventMetadataInjector = 'event_metadata_injector',
MarkSanitizeGuardrail = 'mark_sanitize_guardrail',
ScopeSanitizeStartGuardrail = 'scope_sanitize_start_guardrail',
ScopeSanitizeEndGuardrail = 'scope_sanitize_end_guardrail',
ToolSanitizeRequestGuardrail = 'tool_sanitize_request_guardrail',
ToolSanitizeResponseGuardrail = 'tool_sanitize_response_guardrail',
ToolConditionalExecutionGuardrail = 'tool_conditional_execution_guardrail',
ToolRequestIntercept = 'tool_request_intercept',
ToolExecutionIntercept = 'tool_execution_intercept',
LlmSanitizeRequestGuardrail = 'llm_sanitize_request_guardrail',
LlmSanitizeResponseGuardrail = 'llm_sanitize_response_guardrail',
LlmConditionalExecutionGuardrail = 'llm_conditional_execution_guardrail',
LlmRequestIntercept = 'llm_request_intercept',
LlmExecutionIntercept = 'llm_execution_intercept',
LlmStreamExecutionIntercept = 'llm_stream_execution_intercept'
}

RuntimeRegistrationOwnerKind

The owner category reported for a global runtime registration.

export const enum RuntimeRegistrationOwnerKind {
Core = 'core',
GlobalApi = 'global_api',
Plugin = 'plugin'
}

DurationUnit

Units for duration measurements.

export const enum DurationUnit {
/** Microseconds. */
Microseconds = 'microseconds',
/** Milliseconds. */
Milliseconds = 'milliseconds',
/** Seconds. */
Seconds = 'seconds',
/** Minutes. */
Minutes = 'minutes'
}

CapacityUnit

Units for capacity measurements.

export const enum CapacityUnit {
/** Bytes. */
Bytes = 'bytes',
/** Kilobytes. */
Kilobytes = 'kilobytes',
/** Megabytes. */
Megabytes = 'megabytes',
/** Gigabytes. */
Gigabytes = 'gigabytes',
/** Terabytes. */
Terabytes = 'terabytes',
/** Kibibytes. */
Kibibytes = 'kibibytes',
/** Mebibytes. */
Mebibytes = 'mebibytes',
/** Gibibytes. */
Gibibytes = 'gibibytes',
/** Tebibytes. */
Tebibytes = 'tebibytes'
}

DataUnit

Units for data measurements.

export const enum DataUnit {
/** Bytes. */
Bytes = 'bytes',
/** Kilobytes. */
Kilobytes = 'kilobytes',
/** Megabytes. */
Megabytes = 'megabytes',
/** Gigabytes. */
Gigabytes = 'gigabytes',
/** Terabytes. */
Terabytes = 'terabytes',
/** Kibibytes. */
Kibibytes = 'kibibytes',
/** Mebibytes. */
Mebibytes = 'mebibytes',
/** Gibibytes. */
Gibibytes = 'gibibytes',
/** Tebibytes. */
Tebibytes = 'tebibytes'
}

BandwidthUnit

Units for bandwidth measurements.

export const enum BandwidthUnit {
/** Bytes per second. */
BytesPerSecond = 'bytes_per_second',
/** Kibibytes per second. */
KibibytesPerSecond = 'kibibytes_per_second',
/** Mebibytes per second. */
MebibytesPerSecond = 'mebibytes_per_second',
/** Gibibytes per second. */
GibibytesPerSecond = 'gibibytes_per_second',
/** Bits per second. */
BitsPerSecond = 'bits_per_second',
/** Megabits per second. */
MegabitsPerSecond = 'megabits_per_second',
/** Gigabits per second. */
GigabitsPerSecond = 'gigabits_per_second'
}

CpuUnit

Units for CPU measurements.

export const enum CpuUnit {
/** Logical processors. */
LogicalProcessors = 'logical_processors',
/** Millicores. */
Millicores = 'millicores'
}

UtilizationUnit

Units for utilization measurements.

export const enum UtilizationUnit {
/** Percentage. */
Percentage = 'percentage',
/** Fraction. */
Fraction = 'fraction'
}

CountUnit

Units for count measurements.

export const enum CountUnit {
/** Processes. */
Processes = 'processes',
/** Threads. */
Threads = 'threads',
/** File descriptors. */
FileDescriptors = 'file_descriptors',
/** Handles. */
Handles = 'handles',
/** Events. */
Events = 'events',
/** Operations. */
Operations = 'operations',
/** Packets. */
Packets = 'packets',
/** Errors. */
Errors = 'errors'
}

ScopeType

The type of an execution scope in the agent runtime hierarchy.

export const enum ScopeType {
/** An autonomous agent scope. */
Agent = 0,
/** A generic function invocation scope. */
Function = 1,
/** A tool execution scope. */
Tool = 2,
/** A large language model call scope. */
Llm = 3,
/** A retriever (vector search / RAG) scope. */
Retriever = 4,
/** An embedding model scope. */
Embedder = 5,
/** A reranker model scope. */
Reranker = 6,
/** A guardrail evaluation scope. */
Guardrail = 7,
/** An evaluator / scoring scope. */
Evaluator = 8,
/** A user-defined custom scope type. */
Custom = 9,
/** An unknown or unclassified scope type. */
Unknown = 10
}

LogSeverity

Severity attached to a mark projected as an OpenTelemetry log.

export const enum LogSeverity {
Trace = 0,
Debug = 1,
Info = 2,
Warn = 3,
Error = 4
}

MetricKind

OpenTelemetry instrument kind recorded by a metric measurement.

export const enum MetricKind {
Counter = 0,
UpDownCounter = 1,
Gauge = 2,
Histogram = 3
}

MetricValueType

Explicit numeric representation used by a metric measurement.

export const enum MetricValueType {
U64 = 0,
I64 = 1,
F64 = 2
}

MetricTemporality

Preferred aggregation temporality for OTLP metric export.

export const enum MetricTemporality {
Cumulative = 0,
Delta = 1,
LowMemory = 2
}

Functions

log

Emit a structured operational log record through Relay’s configured sinks.

export declare function log(level: string, message: string, target?: string | undefined | null, fields?: Json | undefined | null): void

trace

export declare function trace(message: string, target?: string | undefined | null, fields?: Json | undefined | null): void

debug

export declare function debug(message: string, target?: string | undefined | null, fields?: Json | undefined | null): void

info

export declare function info(message: string, target?: string | undefined | null, fields?: Json | undefined | null): void

warn

export declare function warn(message: string, target?: string | undefined | null, fields?: Json | undefined | null): void

collectResourceMetrics

Acquire a fresh resource metrics snapshot without requiring polling. Collection runs outside the JavaScript event loop.

export declare function collectResourceMetrics(): Promise<ResourceMetricsSnapshot>

error

export declare function error(message: string, target?: string | undefined | null, fields?: Json | undefined | null): void

pushStreamChunk

Push a chunk into the stream identified by streamId. Called from JavaScript during async generator iteration.

export declare function pushStreamChunk(streamId: number, chunk: Json): boolean

endStream

Signal that a stream is complete. Drops the sender so the Rust receiver sees the channel as closed.

export declare function endStream(streamId: number): void

createScopeStack

Creates a new isolated scope stack.

export declare function createScopeStack(): ScopeStack

capturePropagationContext

Capture the current Relay causal parent for application-managed transport.

export declare function capturePropagationContext(): PropagationContext

captureRootlessPropagationContext

Capture the current Relay causal parent without a propagation root.

export declare function captureRootlessPropagationContext(): PropagationContext

capturePropagationContextWithRoot

Capture the current parent with an optional stable application session root.

export declare function capturePropagationContextWithRoot(rootUuid?: string | undefined | null): PropagationContext

captureTraceparent

Capture the current Relay context as a W3C traceparent value.

export declare function captureTraceparent(): string

propagationContextToJson

Serialize a Relay causal context to the JSON wire format.

export declare function propagationContextToJson(context: PropagationContext): string

propagationContextToTraceparent

Convert a Relay propagation context to a W3C traceparent value.

export declare function propagationContextToTraceparent(context: PropagationContext): string

propagationContextFromJson

Deserialize and validate a Relay causal context from the JSON wire format.

export declare function propagationContextFromJson(value: string): PropagationContext

createScopeStackFromPropagation

Create an isolated scope stack seeded from a received propagation context.

export declare function createScopeStackFromPropagation(context: PropagationContext): ScopeStack

withScopeStack

Run a callback with an isolated scope stack installed.

The caller’s stack is restored immediately after callback invocation. When the callback returns a Promise, the requested stack remains active for that Promise until it settles and is then expired for inherited detached work. Use this helper instead of setThreadScopeStack to isolate concurrent async branches.

export declare function withScopeStack(stack: ScopeStack, callback: (...args: any[]) => any): unknown

currentScopeStack

Returns the current execution context’s scope stack handle.

export declare function currentScopeStack(): ScopeStack

setThreadScopeStack

Binds a scope stack to the current thread or async resource.

This mutates the current execution resource. Use withScopeStack when concurrent asynchronous branches need isolated stack replacements.

export declare function setThreadScopeStack(stack: ScopeStack): void

scopeStackActive

Returns whether the current execution context has an explicitly-initialized scope stack.

Returns true if setThreadScopeStack has been called on the current thread, or the caller is inside a task-local scope. Returns false when only the auto-created default is present.

export declare function scopeStackActive(): boolean

getLastCallbackError

Returns the most recent callback error that could not be surfaced through a direct exception.

This is primarily used for sanitize callback paths that omit observability payloads and cannot surface their errors directly.

export declare function getLastCallbackError(): string | null

clearLastCallbackError

Clears the most recent callback error recorded by the Node binding.

export declare function clearLastCallbackError(): void

getHandle

Get the handle for the current top-of-stack execution scope.

Returns the ScopeHandle for the innermost active scope on the current task’s scope stack. Throws if the scope stack is empty.

export declare function getHandle(): ScopeHandle

pushScope

Push a new execution scope onto the scope stack.

Creates a child scope with the given name and scopeType. If handle is provided, the new scope is parented to that scope; otherwise it is parented to the current top scope. Optional attributes is a bitfield of scope attribute flags. Optional data is a JSON application payload stored on the scope handle. Optional metadata is a JSON metadata payload recorded on the scope start event. Optional input is a semantic JSON payload exported on the scope start event. Optional timestamp is a Unix timestamp in microseconds recorded as the handle start time and start event timestamp. It must be a safe integer number; omit it to use the current runtime time. Returns the handle for the newly created scope.

export declare function pushScope(name: string, scopeType: ScopeType, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, input?: Json | undefined | null, timestamp?: number | undefined | null): ScopeHandle

popScope

Pop an execution scope from the scope stack.

Removes the scope identified by handle from the stack and emits an end event. Optional output is a semantic JSON payload exported on the scope end event. Optional timestamp is a Unix timestamp in microseconds recorded on the end event. It must be a safe integer number; omit it to use the runtime default end timestamp. Optional metadata is a JSON metadata payload recorded on the scope end event. Throws if the handle does not match the current top scope.

export declare function popScope(handle: ScopeHandle, output?: Json | undefined | null, timestamp?: number | undefined | null, metadata?: Json | undefined | null): void

withScope

Push a scope, run a callback, then pop the scope automatically.

Creates a child scope with the given name and scopeType, invokes the callback with the new scope handle, and guarantees that the scope is popped when the callback completes (whether it returns normally, throws, or returns a rejected Promise). Supports both synchronous and async (Promise-returning) callbacks.

Optional handle sets the parent scope; attributes is a bitfield of scope attribute flags; data is stored on the scope handle; metadata is recorded on the start event; and input is exported as the semantic start-event payload.

Returns a Promise that resolves with the callback’s return value.

export declare function withScope(name: string, scopeType: ScopeType, callback: (...args: any[]) => any, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, input?: Json | undefined | null): Promise<unknown>

event

Emit a custom mark event on the current scope.

Emits a named event with optional data and metadata payloads. If handle is provided, the event is associated with that scope; otherwise it uses the current top scope. Optional timestamp is a Unix timestamp in microseconds recorded on the mark event. It must be a safe integer number; omit it to use the current runtime time. Optional dataSchema identifies the shape of data; severity supplies the typed severity used by OpenTelemetry log exporters.

export declare function event(name: string, handle?: ScopeHandle | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, timestamp?: number | undefined | null, dataSchema?: DataSchema | undefined | null, severity?: LogSeverity | undefined | null): void

metric

Emit an atomic, validated group of OpenTelemetry metric recording operations.

name is the metric mark name. Every measurement is validated before any event is published. Optional handle, metadata, and microsecond timestamp have the same behavior as the corresponding event parameters.

export declare function metric(name: string, measurements: Array<MetricMeasurement>, handle?: ScopeHandle | undefined | null, metadata?: Json | undefined | null, timestamp?: number | undefined | null): void

toolCall

Begin a manual tool call lifecycle span.

Registers a tool invocation with the given name and args. Sanitize-request guardrails are applied to the emitted start-event payload; request and execution intercepts run only through toolCallExecute. Returns a ToolHandle that must be passed to toolCallEnd() when the tool finishes. Optional handle specifies the parent scope; attributes is a bitfield; data is stored on the handle; metadata is recorded on the start event; and toolCallId is recorded in the tool event category profile. Optional timestamp is a Unix timestamp in microseconds recorded as the handle start time and start event timestamp. It must be a safe integer number; omit it to use the current runtime time.

export declare function toolCall(name: string, args: Json, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, toolCallId?: string | undefined | null, timestamp?: number | undefined | null): ToolHandle

toolCallEnd

End a manual tool call lifecycle span.

Signals that the tool call identified by handle has completed with the given result. Sanitize-response guardrails are applied to the emitted end-event payload; response intercepts run only through toolCallExecute. Optional data is used when the sanitized result is JSON null, and optional metadata is recorded on the end event. Optional timestamp is a Unix timestamp in microseconds recorded on the end event. It must be a safe integer number; omit it to use the runtime default end timestamp.

export declare function toolCallEnd(handle: ToolHandle, result: ToolExecutionResult, data?: Json | undefined | null, metadata?: Json | undefined | null, timestamp?: number | undefined | null): void

toolCallExecute

Execute a tool call end-to-end with full lifecycle management.

Runs conditional-execution guardrails (on raw args) -> request intercepts -> sanitize-request guardrails for the emitted Start event payload -> execution intercepts -> func -> sanitize-response guardrails for the emitted End event payload. On rejection, only a standalone Mark event is emitted (no Start/End pair) and GuardrailRejected is returned. Returns the final execution result; sanitize guardrails do not rewrite the caller-visible value. An optional trailing toolCallId is recorded in both lifecycle events.

export declare function toolCallExecute(name: string, args: Json, func: (arg: Json) => ToolExecutionResult, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, toolCallId?: string | undefined | null): Promise<ToolExecutionResult>

toolCallExecuteAsync

Execute a tool call end-to-end, supporting both sync and async (Promise-returning) callbacks.

Same lifecycle as toolCallExecute (guardrails -> intercepts -> func -> response processing), but transparently handles JS callbacks that return Promises. Uses napi_is_promise to detect Promise return values and resolves them before continuing the pipeline. An optional trailing toolCallId is recorded in both lifecycle events.

Accepts a raw JsFunction instead of ThreadsafeFunction so it can create a promise-aware wrapper with access to Env.

export declare function toolCallExecuteAsync(name: string, args: Json, func: (arg: Json, signal: AbortSignal) => ToolExecutionResult | Promise<ToolExecutionResult>, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, toolCallId?: string | undefined | null): Promise<ToolExecutionResult>

llmCall

Begin a manual LLM call lifecycle span.

Registers an LLM invocation with the given provider name and request payload. The request should be a JSON object with headers and content fields matching the LlmRequest schema. Returns an LlmHandle that must be passed to llmCallEnd() when the response is received. Sanitize-request guardrails are applied to the emitted start-event payload; request and execution intercepts run only through llmCallExecute. Optional handle specifies the parent scope; attributes is a bitfield; data is stored on the handle; metadata is recorded on the start event; and modelName is recorded in the LLM event category profile. Optional timestamp is a Unix timestamp in microseconds recorded as the handle start time and start event timestamp. It must be a safe integer number; omit it to use the current runtime time.

export declare function llmCall(name: string, request: Json, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, modelName?: string | undefined | null, timestamp?: number | undefined | null): LlmHandle

llmCallEnd

End a manual LLM call lifecycle span.

Signals that the LLM call identified by handle has completed with the given response. Sanitize-response guardrails are applied to the emitted end-event payload; response intercepts run only through llmCallExecute. Optional data is used when the sanitized response is JSON null, and optional metadata is recorded on the end event. Optional timestamp is a Unix timestamp in microseconds recorded on the end event. It must be a safe integer number; omit it to use the runtime default end timestamp.

export declare function llmCallEnd(handle: LlmHandle, response: Json, data?: Json | undefined | null, metadata?: Json | undefined | null, timestamp?: number | undefined | null): void

llmCallExecute

Execute an LLM call end-to-end with full lifecycle management.

Runs conditional-execution guardrails (on raw request) -> request intercepts -> sanitize-request guardrails for the emitted Start event payload -> execution intercepts -> func -> sanitize-response guardrails for the emitted End event payload. On rejection, only a standalone Mark event is emitted (no Start/End pair) and GuardrailRejected is returned. The request should be a JSON object with headers and content fields matching the LlmRequest schema. Returns the final execution response; sanitize guardrails do not rewrite the caller-visible value.

export declare function llmCallExecute(name: string, request: Json, func: (arg: Json) => any, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, modelName?: string | undefined | null, codecDecode?: (arg: Json) => any, codecEncode?: (arg: Json) => any, responseCodecDecode?: (arg: Json) => any): Promise<unknown>

llmCallExecuteAsync

Execute an LLM call end-to-end, supporting both sync and async (Promise-returning) callbacks.

Same lifecycle as llmCallExecute (guardrails -> intercepts -> func -> response processing), but transparently handles JS callbacks that return Promises.

export declare function llmCallExecuteAsync(name: string, request: Json, func: (...args: any[]) => any, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, modelName?: string | undefined | null, codecDecode?: (arg: Json) => any, codecEncode?: (arg: Json) => any, responseCodecDecode?: (arg: Json) => any): Promise<unknown>

llmStreamCallExecute

Execute a streaming LLM call end-to-end with full lifecycle management.

Like llmCallExecute, conditional-execution guardrails run first on the raw request. Sanitize-request guardrails only affect the emitted Start event payload, and sanitize-response guardrails only affect the aggregated End event payload. Returns an LlmStream whose next() method yields response chunks incrementally. The func callback receives the intercepted request as JSON and its response is streamed back. Stream-level intercepts are applied to each chunk. The request should be a JSON object with headers and content fields matching the LlmRequest schema.

The optional collector callback is invoked with each intercepted chunk as JSON, allowing the caller to accumulate chunks for aggregation. The optional finalizer callback is invoked once when the stream is exhausted or closed early and must return a JSON value representing the aggregated response. Consumers that stop reading early must await stream.close() to wait for producer cleanup and surface cleanup errors.

export declare function llmStreamCallExecute(name: string, request: Json, func: (...args: any[]) => any, collector?: (arg: Json) => any | undefined | null, finalizer?: () => any | undefined | null, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null, modelName?: string | undefined | null, codecDecode?: (arg: Json) => any, codecEncode?: (arg: Json) => any, responseCodecDecode?: (arg: Json) => any): Promise<LlmStream>

registerEventMetadataInjector

Register a global event metadata injector.

The callback receives an immutable event snapshot and may return additions directly or in a Promise. Relay validates and merges accepted additions before event sanitizers run.

export declare function registerEventMetadataInjector(name: string, priority: number, injector: (event: Json) => EventMetadata | Promise<EventMetadata>): void

deregisterEventMetadataInjector

Deregister a global event metadata injector by name.

export declare function deregisterEventMetadataInjector(name: string): boolean

registerConditionalMiddlewareGuardrail

Register a global eligibility gate for runtime registrations matching kind and name.

export declare function registerConditionalMiddlewareGuardrail(name: string, kinds: Array<RuntimeRegistrationKind>, registrationName: string, guardrail: (kinds: RuntimeRegistrationKind[], registrationName: string) => string | null): void

deregisterConditionalMiddlewareGuardrail

Deregister a global runtime-registration eligibility gate by name.

export declare function deregisterConditionalMiddlewareGuardrail(name: string): boolean

listRuntimeRegistrations

List global gateable runtime registrations.

export declare function listRuntimeRegistrations(kinds?: Array<RuntimeRegistrationKind> | undefined | null): Array<RuntimeRegistrationIdentity>

registerMarkSanitizeGuardrail

Register an event sanitize guardrail.

The callback may return fields directly or in a Promise. Scope and mark calls queue the event and return synchronously; publication resumes after the Promise settles. Callback, serialization, conversion, or invalid-result failures clear the emitted event fields and record the error for getLastCallbackError(). Await flushSubscribers() before inspecting either the delivered event or that error.

export declare function registerMarkSanitizeGuardrail(name: string, priority: number, guardrail: (event: Json, fields: EventSanitizeFields) => EventSanitizeFields | Promise<EventSanitizeFields>): void

deregisterMarkSanitizeGuardrail

export declare function deregisterMarkSanitizeGuardrail(name: string): boolean

registerScopeSanitizeStartGuardrail

Register an event sanitize guardrail.

The callback may return fields directly or in a Promise. Scope and mark calls queue the event and return synchronously; publication resumes after the Promise settles. Callback, serialization, conversion, or invalid-result failures clear the emitted event fields and record the error for getLastCallbackError(). Await flushSubscribers() before inspecting either the delivered event or that error.

export declare function registerScopeSanitizeStartGuardrail(name: string, priority: number, guardrail: (event: Json, fields: EventSanitizeFields) => EventSanitizeFields | Promise<EventSanitizeFields>): void

deregisterScopeSanitizeStartGuardrail

export declare function deregisterScopeSanitizeStartGuardrail(name: string): boolean

registerScopeSanitizeEndGuardrail

Register an event sanitize guardrail.

The callback may return fields directly or in a Promise. Scope and mark calls queue the event and return synchronously; publication resumes after the Promise settles. Callback, serialization, conversion, or invalid-result failures clear the emitted event fields and record the error for getLastCallbackError(). Await flushSubscribers() before inspecting either the delivered event or that error.

export declare function registerScopeSanitizeEndGuardrail(name: string, priority: number, guardrail: (event: Json, fields: EventSanitizeFields) => EventSanitizeFields | Promise<EventSanitizeFields>): void

deregisterScopeSanitizeEndGuardrail

export declare function deregisterScopeSanitizeEndGuardrail(name: string): boolean

registerToolSanitizeRequestGuardrail

Register a guardrail that sanitizes tool request arguments before execution.

The guardrail callback receives (toolName, args) and must return sanitized args. Higher priority values run first. Throws if a guardrail with the same name already exists. If the callback throws, Relay omits the emitted payload and records the error for getLastCallbackError().

export declare function registerToolSanitizeRequestGuardrail(name: string, priority: number, guardrail: (toolName: string, value: Json) => Json | Promise<Json>): void

deregisterToolSanitizeRequestGuardrail

Deregister a tool request sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed.

export declare function deregisterToolSanitizeRequestGuardrail(name: string): boolean

registerToolSanitizeResponseGuardrail

Register a guardrail that sanitizes tool response data after execution.

The guardrail callback receives (toolName, result) and must return sanitized result. Higher priority values run first. Throws if a guardrail with the same name already exists. If the callback throws, Relay omits the emitted payload and records the error for getLastCallbackError().

export declare function registerToolSanitizeResponseGuardrail(name: string, priority: number, guardrail: (toolName: string, value: Json) => Json | Promise<Json>): void

deregisterToolSanitizeResponseGuardrail

Deregister a tool response sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed.

export declare function deregisterToolSanitizeResponseGuardrail(name: string): boolean

registerToolConditionalExecutionGuardrail

Register a guardrail that conditionally gates tool execution.

The guardrail callback receives (toolName, args) and must return null to allow execution or a rejection reason string to block it. Higher priority values run first. If the callback throws, the managed call rejects and the protected callback does not run.

export declare function registerToolConditionalExecutionGuardrail(name: string, priority: number, guardrail: (toolName: string, args: Json) => string | null | Promise<string | null>): void

deregisterToolConditionalExecutionGuardrail

Deregister a tool conditional execution guardrail by name.

Returns true if a guardrail with that name was found and removed.

export declare function deregisterToolConditionalExecutionGuardrail(name: string): boolean

registerToolRequestIntercept

Register an intercept that transforms tool request arguments.

The callable receives (toolName, args) and returns transformed args. If breakChain is true, no lower-priority intercepts run after this one. Higher priority values run first. If the callback throws, the managed call rejects and later middleware does not run.

export declare function registerToolRequestIntercept(name: string, priority: number, breakChain: boolean, callable: (toolName: string, args: Json) => Json | Promise<Json>): void

deregisterToolRequestIntercept

Deregister a tool request intercept by name.

Returns true if an intercept with that name was found and removed.

export declare function deregisterToolRequestIntercept(name: string): boolean

registerToolExecutionIntercept

Register a tool execution intercept following the middleware chain pattern.

The callable receives ToolExecutionContext and next. The context exposes toolName, args, and toolCallId; toolCallId is null when the managed call has no provider-issued correlation identifier. Call next(context.args) to continue the chain, or return an outcome directly to short-circuit execution.

export declare function registerToolExecutionIntercept(name: string, priority: number, callable: (context: ToolExecutionContext, next: (args: Json) => ToolExecutionResult | Promise<ToolExecutionResult>) => { result: Json; annotation?: Json; pendingMarks?: Array<PendingMarkSpec> } | Promise<{ result: Json; annotation?: Json; pendingMarks?: Array<PendingMarkSpec> }>): void

deregisterToolExecutionIntercept

Deregister a tool execution intercept by name.

Removes an intercept registered through either registration shape. Returns true if an intercept with that name was found and removed.

export declare function deregisterToolExecutionIntercept(name: string): boolean

registerLlmSanitizeRequestGuardrail

Register a guardrail that sanitizes LLM request data before execution.

The guardrail callback receives (request, context) and must return the sanitized request, or null to omit the observability payload. Lower priority values run first. Throws if a guardrail with the same name already exists. If the callback throws, Relay omits the payload and annotation, continues publication, and records the error for getLastCallbackError().

export declare function registerLlmSanitizeRequestGuardrail(name: string, priority: number, guardrail: (request: Json, context: LlmSanitizeRequestContext) => Json | null | Promise<Json | null>): void

deregisterLlmSanitizeRequestGuardrail

Deregister an LLM request sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed.

export declare function deregisterLlmSanitizeRequestGuardrail(name: string): boolean

registerLlmSanitizeResponseGuardrail

Register a guardrail that sanitizes LLM response data after execution.

The guardrail callback receives (response, context) and must return the sanitized response, or null to omit the observability payload. Lower priority values run first. Throws if a guardrail with the same name already exists. If the callback throws, Relay omits the payload and annotation, continues publication, and records the error for getLastCallbackError().

export declare function registerLlmSanitizeResponseGuardrail(name: string, priority: number, guardrail: (response: Json, context: LlmSanitizeResponseContext) => Json | null | Promise<Json | null>): void

deregisterLlmSanitizeResponseGuardrail

Deregister an LLM response sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed.

export declare function deregisterLlmSanitizeResponseGuardrail(name: string): boolean

registerLlmConditionalExecutionGuardrail

Register a guardrail that conditionally gates LLM execution.

The guardrail callback receives the LLM request as JSON and must return null to allow execution or a rejection reason string to block it. Higher priority values run first. If the callback throws, the managed call rejects and the protected callback does not run.

export declare function registerLlmConditionalExecutionGuardrail(name: string, priority: number, guardrail: (request: Json) => string | null | Promise<string | null>): void

deregisterLlmConditionalExecutionGuardrail

Deregister an LLM conditional execution guardrail by name.

Returns true if a guardrail with that name was found and removed.

export declare function deregisterLlmConditionalExecutionGuardrail(name: string): boolean

registerLlmRequestIntercept

Register an intercept that transforms LLM request data.

The callable receives the LlmRequest (as JSON) and returns a transformed request. If breakChain is true, no lower-priority intercepts run after this one. Higher priority values run first. If the callback throws, the managed call rejects and later middleware does not run.

export declare function registerLlmRequestIntercept(name: string, priority: number, breakChain: boolean, callable: (args: { name: string; request: Json; annotated: Json | null }) => LlmRequestInterceptOutcome | Promise<LlmRequestInterceptOutcome>): void

deregisterLlmRequestIntercept

Deregister an LLM request intercept by name.

Returns true if an intercept with that name was found and removed.

export declare function deregisterLlmRequestIntercept(name: string): boolean

registerLlmExecutionIntercept

Register an LLM execution intercept following the middleware chain pattern.

The callable receives the request, codec context, and a next function. Call next(request) to invoke the next intercept or original implementation; skip calling next to short-circuit the chain. next may be called repeatedly or concurrently while callable is pending; each call receives an isolated scope-stack branch, and unfinished or later calls reject after callable settles.

export declare function registerLlmExecutionIntercept(name: string, priority: number, callable: (request: Json, context: LlmExecutionContext, next: (request: Json) => Json | Promise<Json>) => Json | Promise<Json>): void

deregisterLlmExecutionIntercept

Deregister an LLM execution intercept by name.

Returns true if an intercept with that name was found and removed.

export declare function deregisterLlmExecutionIntercept(name: string): boolean

registerLlmStreamExecutionIntercept

Register a streaming LLM execution intercept following the middleware chain pattern.

The callable receives the request, request-codec context, and a next function. The response codec is null because streaming execution has no complete-response codec. Call next(request) to invoke the next intercept or original streaming implementation; in Node the returned promise resolves to a lazy AsyncIterable. Return it directly or wrap it next to short-circuit the chain. next may be called repeatedly or concurrently while callable is pending; each call receives an isolated scope-stack branch, and unfinished or later calls reject after the returned interceptor stream settles. A downstream stream returned successfully by next keeps its normal lifetime.

export declare function registerLlmStreamExecutionIntercept(name: string, priority: number, callable: (request: Json, context: LlmExecutionContext, next: (request: Json) => Promise<AsyncIterable<Json>>) => AsyncIterable<Json> | Promise<AsyncIterable<Json>>): void

deregisterLlmStreamExecutionIntercept

Deregister an LLM stream execution intercept by name.

Returns true if an intercept with that name was found and removed.

export declare function deregisterLlmStreamExecutionIntercept(name: string): boolean

registerSubscriber

Register a named event subscriber that receives all lifecycle events.

The callback receives each event as the canonical JSON event object and may return a Promise. Events are delivered asynchronously and non-blocking. Callback failures are isolated, reported to stderr and getLastCallbackError(), and do not reject flushSubscribers(). Throws if a subscriber with the same name already exists.

export declare function registerSubscriber(name: string, callback: (event: Json) => void | Promise<void>): void

deregisterSubscriber

Deregister an event subscriber by name.

Future emissions stop seeing the subscriber. Already queued event snapshots may still run. Returns true if a subscriber with that name was found and removed.

export declare function deregisterSubscriber(name: string): boolean

flushSubscribers

Return a Promise that resolves when native and JavaScript subscriber callbacks and managed terminal publications registered before this call finish.

Call this function outside subscribers, event sanitizers, conditional guardrails, and request or execution intercepts. A queued tool or LLM observability sanitizer may call it, but the Promise resolves without waiting for its own publication.

Awaiting this Promise does not block the Node event loop while Promise-returning event sanitizers settle or queued JavaScript subscriber callbacks run. Native events emitted by a JavaScript subscriber are separate publications and may require another flush.

The Promise rejects if the blocking task fails or the core subscriber flush returns an error. Callers should handle errors when awaiting it.

export declare function flushSubscribers(): Promise<void>

scopeRegisterEventMetadataInjector

Register an event metadata injector owned by an active scope.

export declare function scopeRegisterEventMetadataInjector(scopeUuid: string, name: string, priority: number, injector: (event: Json) => EventMetadata | Promise<EventMetadata>): void

scopeDeregisterEventMetadataInjector

Deregister a scope-local event metadata injector by name.

export declare function scopeDeregisterEventMetadataInjector(scopeUuid: string, name: string): boolean

scopeRegisterMarkSanitizeGuardrail

Register a scope-local event sanitize guardrail.

The callback may return fields directly or in a Promise. Scope and mark calls queue the event and return synchronously; publication resumes after the Promise settles. Callback, serialization, conversion, or invalid-result failures clear the emitted event fields and record the error for getLastCallbackError(). Await flushSubscribers() before inspecting either the delivered event or that error.

export declare function scopeRegisterMarkSanitizeGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (event: Json, fields: EventSanitizeFields) => EventSanitizeFields | Promise<EventSanitizeFields>): void

scopeDeregisterMarkSanitizeGuardrail

export declare function scopeDeregisterMarkSanitizeGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterScopeSanitizeStartGuardrail

Register a scope-local event sanitize guardrail.

The callback may return fields directly or in a Promise. Scope and mark calls queue the event and return synchronously; publication resumes after the Promise settles. Callback, serialization, conversion, or invalid-result failures clear the emitted event fields and record the error for getLastCallbackError(). Await flushSubscribers() before inspecting either the delivered event or that error.

export declare function scopeRegisterScopeSanitizeStartGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (event: Json, fields: EventSanitizeFields) => EventSanitizeFields | Promise<EventSanitizeFields>): void

scopeDeregisterScopeSanitizeStartGuardrail

export declare function scopeDeregisterScopeSanitizeStartGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterScopeSanitizeEndGuardrail

Register a scope-local event sanitize guardrail.

The callback may return fields directly or in a Promise. Scope and mark calls queue the event and return synchronously; publication resumes after the Promise settles. Callback, serialization, conversion, or invalid-result failures clear the emitted event fields and record the error for getLastCallbackError(). Await flushSubscribers() before inspecting either the delivered event or that error.

export declare function scopeRegisterScopeSanitizeEndGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (event: Json, fields: EventSanitizeFields) => EventSanitizeFields | Promise<EventSanitizeFields>): void

scopeDeregisterScopeSanitizeEndGuardrail

export declare function scopeDeregisterScopeSanitizeEndGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterToolSanitizeRequestGuardrail

Register a scope-local guardrail that sanitizes tool request arguments before execution.

The guardrail callback receives (toolName, args) and must return sanitized args. Higher priority values run first. Throws if a guardrail with the same name already exists on the specified scope. If the callback throws, Relay omits the emitted payload and records the error for getLastCallbackError().

export declare function scopeRegisterToolSanitizeRequestGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (toolName: string, value: Json) => Json | Promise<Json>): void

scopeDeregisterToolSanitizeRequestGuardrail

Deregister a scope-local tool request sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed from the specified scope.

export declare function scopeDeregisterToolSanitizeRequestGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterToolSanitizeResponseGuardrail

Register a scope-local guardrail that sanitizes tool response data after execution.

The guardrail callback receives (toolName, result) and must return sanitized result. Higher priority values run first. Throws if a guardrail with the same name already exists on the specified scope. If the callback throws, Relay omits the emitted payload and records the error for getLastCallbackError().

export declare function scopeRegisterToolSanitizeResponseGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (toolName: string, value: Json) => Json | Promise<Json>): void

scopeDeregisterToolSanitizeResponseGuardrail

Deregister a scope-local tool response sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed from the specified scope.

export declare function scopeDeregisterToolSanitizeResponseGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterToolConditionalExecutionGuardrail

Register a scope-local guardrail that conditionally gates tool execution.

The guardrail callback receives (toolName, args) and must return null to allow execution or a rejection reason string to block it. Higher priority values run first. If the callback throws, the managed call rejects and the protected callback does not run.

export declare function scopeRegisterToolConditionalExecutionGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (toolName: string, args: Json) => string | null | Promise<string | null>): void

scopeDeregisterToolConditionalExecutionGuardrail

Deregister a scope-local tool conditional execution guardrail by name.

Returns true if a guardrail with that name was found and removed from the specified scope.

export declare function scopeDeregisterToolConditionalExecutionGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterToolRequestIntercept

Register a scope-local intercept that transforms tool request arguments.

The callable receives (toolName, args) and returns transformed args. If breakChain is true, no lower-priority intercepts run after this one. Higher priority values run first. If the callback throws, the managed call rejects and later middleware does not run.

export declare function scopeRegisterToolRequestIntercept(scopeUuid: string, name: string, priority: number, breakChain: boolean, callable: (toolName: string, args: Json) => Json | Promise<Json>): void

scopeDeregisterToolRequestIntercept

Deregister a scope-local tool request intercept by name.

Returns true if an intercept with that name was found and removed from the specified scope.

export declare function scopeDeregisterToolRequestIntercept(scopeUuid: string, name: string): boolean

scopeRegisterToolExecutionIntercept

Register a scope-local tool execution intercept following the middleware chain pattern.

The callable receives ToolExecutionContext and next. The context exposes toolName, args, and toolCallId; toolCallId is null when the managed call has no provider-issued correlation identifier. Call next(context.args) to continue the chain, or return an outcome directly to short-circuit execution.

export declare function scopeRegisterToolExecutionIntercept(scopeUuid: string, name: string, priority: number, callable: (context: ToolExecutionContext, next: (args: Json) => ToolExecutionResult | Promise<ToolExecutionResult>) => { result: Json; annotation?: Json; pendingMarks?: Array<PendingMarkSpec> } | Promise<{ result: Json; annotation?: Json; pendingMarks?: Array<PendingMarkSpec> }>): void

scopeDeregisterToolExecutionIntercept

Deregister a scope-local tool execution intercept by name.

Removes an intercept registered through either registration shape. Returns true if an intercept with that name was found and removed from the specified scope.

export declare function scopeDeregisterToolExecutionIntercept(scopeUuid: string, name: string): boolean

scopeRegisterLlmSanitizeRequestGuardrail

Register a scope-local guardrail that sanitizes LLM request data before execution.

The guardrail callback receives (request, context) and must return the sanitized request, or null to omit the observability payload. Lower priority values run first. Throws if a guardrail with the same name already exists on the specified scope. If the callback throws, Relay omits the payload and annotation, continues publication, and records the error for getLastCallbackError().

export declare function scopeRegisterLlmSanitizeRequestGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (request: Json, context: LlmSanitizeRequestContext) => Json | null | Promise<Json | null>): void

scopeDeregisterLlmSanitizeRequestGuardrail

Deregister a scope-local LLM request sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed from the specified scope.

export declare function scopeDeregisterLlmSanitizeRequestGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterLlmSanitizeResponseGuardrail

Register a scope-local guardrail that sanitizes LLM response data after execution.

The guardrail callback receives (response, context) and must return the sanitized response, or null to omit the observability payload. Lower priority values run first. Throws if a guardrail with the same name already exists on the specified scope. If the callback throws, Relay omits the payload and annotation, continues publication, and records the error for getLastCallbackError().

export declare function scopeRegisterLlmSanitizeResponseGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (response: Json, context: LlmSanitizeResponseContext) => Json | null | Promise<Json | null>): void

scopeDeregisterLlmSanitizeResponseGuardrail

Deregister a scope-local LLM response sanitization guardrail by name.

Returns true if a guardrail with that name was found and removed from the specified scope.

export declare function scopeDeregisterLlmSanitizeResponseGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterLlmConditionalExecutionGuardrail

Register a scope-local guardrail that conditionally gates LLM execution.

The guardrail callback receives the LLM request as JSON and must return null to allow execution or a rejection reason string to block it. Higher priority values run first. If the callback throws, the managed call rejects and the protected callback does not run.

export declare function scopeRegisterLlmConditionalExecutionGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (request: Json) => string | null | Promise<string | null>): void

scopeDeregisterLlmConditionalExecutionGuardrail

Deregister a scope-local LLM conditional execution guardrail by name.

Returns true if a guardrail with that name was found and removed from the specified scope.

export declare function scopeDeregisterLlmConditionalExecutionGuardrail(scopeUuid: string, name: string): boolean

scopeRegisterLlmRequestIntercept

Register a scope-local intercept that transforms LLM request data.

The callable receives the LlmRequest (as JSON) and returns a transformed request. If breakChain is true, no lower-priority intercepts run after this one. Higher priority values run first. If the callback throws, the managed call rejects and later middleware does not run.

export declare function scopeRegisterLlmRequestIntercept(scopeUuid: string, name: string, priority: number, breakChain: boolean, callable: (args: { name: string; request: Json; annotated: Json | null }) => LlmRequestInterceptOutcome | Promise<LlmRequestInterceptOutcome>): void

scopeDeregisterLlmRequestIntercept

Deregister a scope-local LLM request intercept by name.

Returns true if an intercept with that name was found and removed from the specified scope.

export declare function scopeDeregisterLlmRequestIntercept(scopeUuid: string, name: string): boolean

scopeRegisterLlmExecutionIntercept

Register a scope-local LLM execution intercept following the middleware chain pattern.

The callable receives the request, codec context, and a next function. Call next(request) to invoke the next intercept or original implementation; skip calling next to short-circuit the chain. next may be called repeatedly or concurrently while callable is pending; each call receives an isolated scope-stack branch, and unfinished or later calls reject after callable settles.

export declare function scopeRegisterLlmExecutionIntercept(scopeUuid: string, name: string, priority: number, callable: (request: Json, context: LlmExecutionContext, next: (request: Json) => Json | Promise<Json>) => Json | Promise<Json>): void

scopeDeregisterLlmExecutionIntercept

Deregister a scope-local LLM execution intercept by name.

Returns true if an intercept with that name was found and removed from the specified scope.

export declare function scopeDeregisterLlmExecutionIntercept(scopeUuid: string, name: string): boolean

scopeRegisterLlmStreamExecutionIntercept

Register a scope-local streaming LLM execution intercept following the middleware chain pattern.

The callable receives the request, request-codec context, and a next function. The response codec is null because streaming execution has no complete-response codec. Call next(request) to invoke the next intercept or original streaming implementation; in Node the returned promise resolves to a lazy AsyncIterable. Return it directly or wrap it next to short-circuit the chain. next may be called repeatedly or concurrently while callable is pending; each call receives an isolated scope-stack branch, and unfinished or later calls reject after the returned interceptor stream settles. A downstream stream returned successfully by next keeps its normal lifetime.

export declare function scopeRegisterLlmStreamExecutionIntercept(scopeUuid: string, name: string, priority: number, callable: (request: Json, context: LlmExecutionContext, next: (request: Json) => Promise<AsyncIterable<Json>>) => AsyncIterable<Json> | Promise<AsyncIterable<Json>>): void

scopeDeregisterLlmStreamExecutionIntercept

Deregister a scope-local LLM stream execution intercept by name.

Returns true if an intercept with that name was found and removed from the specified scope.

export declare function scopeDeregisterLlmStreamExecutionIntercept(scopeUuid: string, name: string): boolean

scopeRegisterSubscriber

Register a scope-local named event subscriber that receives lifecycle events for the specified scope.

The callback receives each event as the canonical JSON event object and may return a Promise. Events are delivered asynchronously and non-blocking. Callback failures are isolated, reported to stderr and getLastCallbackError(), and do not reject flushSubscribers(). Throws if a subscriber with the same name already exists on the specified scope.

export declare function scopeRegisterSubscriber(scopeUuid: string, name: string, callback: (event: Json) => void | Promise<void>): void

scopeDeregisterSubscriber

Deregister a scope-local event subscriber by name.

Returns true if a subscriber with that name was found and removed from the specified scope.

export declare function scopeDeregisterSubscriber(scopeUuid: string, name: string): boolean

toolRequestIntercepts

Run the registered tool request intercept chain on the given arguments. Returns the transformed arguments.

export declare function toolRequestIntercepts(name: string, args: Json): Promise<unknown>

toolConditionalExecution

Run the registered tool conditional execution guardrail chain. Throws if any guardrail rejects.

export declare function toolConditionalExecution(name: string, args: Json): Promise<void>

llmRequestIntercepts

Run the registered LLM request intercept chain on the given request. The request should be a JSON object with headers and content fields matching the LlmRequest schema. Returns the transformed request as JSON.

export declare function llmRequestIntercepts(name: string, request: Json): Promise<LlmRequestInterceptOutcome>

llmConditionalExecution

Run the registered LLM conditional execution guardrail chain. Throws if any guardrail rejects. The request should be a JSON object with headers and content fields matching the LlmRequest schema.

export declare function llmConditionalExecution(request: Json): Promise<void>

validateAdaptiveConfig

Validate an adaptive config document without constructing a runtime.

export declare function validateAdaptiveConfig(config: Json): Json

buildCacheTelemetryEvent

Build one adaptive cache telemetry event from normalized usage.

export declare function buildCacheTelemetryEvent(options: Json): Json | null

setLatencySensitivity

Set manual latency sensitivity on the current scope.

export declare function setLatencySensitivity(value: number): void

registerPlugin

Register a plugin backed by JavaScript callbacks.

validate receives (pluginConfig) and should return a diagnostics array. register receives (pluginConfig, context) and should use the context methods to attach subscribers or intercepts. Both callbacks must be synchronous.

export declare function registerPlugin(pluginKind: string, validate: (...args: any[]) => any | undefined | null, register: (...args: any[]) => any): void

deregisterPlugin

Deregister a plugin by kind.

export declare function deregisterPlugin(pluginKind: string): boolean

initialize

Initialize the core-owned static and dynamic plugin host from layered files.

export declare function initialize(config: Json, additionalPluginsToml?: string | undefined | null): Promise<PluginHostActivation>

validate

Validate dynamic plugins without loading any plugin code.

export declare function validate(config: Json, additionalPluginsToml?: string | undefined | null): Json

validateExact

Validate only the supplied static plugin configuration.

export declare function validateExact(config: Json): Json

listPluginKinds

List registered plugin kinds.

export declare function listPluginKinds(): Array<string>

Type Aliases

ResourceOperatingSystem

export type ResourceOperatingSystem = 'linux' | 'macos' | 'windows' | 'unsupported';

ResourceMeasurementScope

export type ResourceMeasurementScope = 'global' | 'application_process' | 'process_tree';

ResourceNumeric

Measurement values use bigint for exact integers above JavaScript’s safe-integer range.

export type ResourceNumeric = number | bigint;

AcceleratorVendor

export type AcceleratorVendor = 'nvidia' | 'amd' | 'intel' | 'apple' | 'other';

LlmCodecIdentity

Codec identity available while a managed LLM event is sanitized.

export type LlmCodecIdentity =
| { kind: 'none' }
| {
kind: 'builtin';

LlmRequestContext

Request codec context exposed to an LLM execution intercept.

export type LlmRequestContext = LlmSanitizeRequestContext;

LlmResponseContext

Response codec context exposed to an LLM execution intercept.

export type LlmResponseContext = LlmSanitizeResponseContext;

EventMetadataScalar

Scalar value accepted in event metadata additions.

export type EventMetadataScalar = string | number | boolean;

EventMetadataValue

Flat value accepted in event metadata additions. After JSON conversion, numeric arrays must contain only integer values or only floating-point values.

export type EventMetadataValue = EventMetadataScalar | string[] | number[] | boolean[];

EventMetadata

Metadata additions returned by an event metadata injector.

export type EventMetadata = Record<string, EventMetadataValue>;