For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
  • About NVIDIA NeMo Relay
    • Overview
    • Architecture
    • Ecosystem
    • Concepts
    • Release Notes
  • Getting Started
    • Agent Runtime Primer
    • Prerequisites
    • Installation
    • Configuration / Setup
    • Quick Start
  • NVIDIA NeMo Relay CLI
    • About
    • Basic Usage
    • Claude Code
    • Codex
    • Cursor
    • Hermes Agent
  • Supported Integrations
    • About
    • OpenClaw Plugin Guide
    • LangChain Integration Guide
    • LangGraph Integration Guide
    • Deep Agents Integration Guide
  • Instrument Applications
    • About
    • Adding Scopes and Marks
    • Instrument a Tool Call
    • Instrument an LLM Call
    • Add Middleware
    • Code Examples
  • Observability Plugin
    • About
    • Configuration
    • Agent Trajectory Interchange Format (ATIF)
    • Agent Trajectory Observability Format (ATOF)
    • OpenTelemetry
    • OpenInference
  • Adaptive Plugin
    • About
    • Configuration
    • Adaptive Cache Governor (ACG)
    • Adaptive Hints
  • NeMo Guardrails Plugin
    • About
    • Configuration
  • Integrate into Frameworks
    • About
    • Adding Scopes
    • Wrap Tool Calls
    • Wrap LLM Calls
    • Handle Non-Serializable Data
    • Using Codecs
    • Provider Codecs
    • Provider Response Codecs
    • Code Examples
  • Build Plugins
    • About
    • Define a Plugin
    • Validate Plugin Configuration
    • Plugin Configuration Files
    • Register Plugin Behavior
    • Design Plugin Configuration
    • NeMo Guardrails Example Plugin
    • Code Examples
  • Contribute
    • About
    • Development Setup
    • Workflow and Reviews
    • Testing and Documentation
  • Reference
    • APIs
      • Python Library Reference
      • Node.js Library Reference
        • Runtime
        • Typed Helpers
        • Plugin Helpers
        • Adaptive Helpers
        • Observability Helpers
      • Rust Library Reference
    • Performance
  • Resources
    • Support and FAQs
    • Glossary
    • Troubleshooting Guide
    • Community
    • Legal
NVIDIANVIDIA
Developer-friendly docs for your API
Privacy Policy | Your Privacy Choices | Terms of Service | Accessibility | Corporate Policies | Product Security | Contact

Copyright © 2026, NVIDIA Corporation.

LogoLogo
On this page
  • Interfaces
  • AtofExporterConfig
  • OpenTelemetryConfig
  • OpenInferenceConfig
  • Classes
  • AtifExporter
  • AtofExporter
  • OpenTelemetrySubscriber
  • OpenInferenceSubscriber
  • LlmStream
  • ScopeStack
  • ScopeHandle
  • ToolHandle
  • LlmHandle
  • LlmRequest
  • OpenAIChatCodec
  • OpenAIResponsesCodec
  • AnthropicMessagesCodec
  • Enums
  • ScopeType
  • Functions
  • pushStreamChunk
  • endStream
  • createScopeStack
  • currentScopeStack
  • setThreadScopeStack
  • scopeStackActive
  • getLastCallbackError
  • clearLastCallbackError
  • getHandle
  • pushScope
  • popScope
  • withScope
  • event
  • toolCall
  • toolCallEnd
  • toolCallExecute
  • toolCallExecuteAsync
  • llmCall
  • llmCallEnd
  • llmCallExecute
  • llmCallExecuteAsync
  • llmStreamCallExecute
  • registerToolSanitizeRequestGuardrail
  • deregisterToolSanitizeRequestGuardrail
  • registerToolSanitizeResponseGuardrail
  • deregisterToolSanitizeResponseGuardrail
  • registerToolConditionalExecutionGuardrail
  • deregisterToolConditionalExecutionGuardrail
  • registerToolRequestIntercept
  • deregisterToolRequestIntercept
  • registerToolExecutionIntercept
  • deregisterToolExecutionIntercept
  • registerLlmSanitizeRequestGuardrail
  • deregisterLlmSanitizeRequestGuardrail
  • registerLlmSanitizeResponseGuardrail
  • deregisterLlmSanitizeResponseGuardrail
  • registerLlmConditionalExecutionGuardrail
  • deregisterLlmConditionalExecutionGuardrail
  • registerLlmRequestIntercept
  • deregisterLlmRequestIntercept
  • registerLlmExecutionIntercept
  • deregisterLlmExecutionIntercept
  • registerLlmStreamExecutionIntercept
  • deregisterLlmStreamExecutionIntercept
  • registerSubscriber
  • deregisterSubscriber
  • flushSubscribers
  • scopeRegisterToolSanitizeRequestGuardrail
  • scopeDeregisterToolSanitizeRequestGuardrail
  • scopeRegisterToolSanitizeResponseGuardrail
  • scopeDeregisterToolSanitizeResponseGuardrail
  • scopeRegisterToolConditionalExecutionGuardrail
  • scopeDeregisterToolConditionalExecutionGuardrail
  • scopeRegisterToolRequestIntercept
  • scopeDeregisterToolRequestIntercept
  • scopeRegisterToolExecutionIntercept
  • scopeDeregisterToolExecutionIntercept
  • scopeRegisterLlmSanitizeRequestGuardrail
  • scopeDeregisterLlmSanitizeRequestGuardrail
  • scopeRegisterLlmSanitizeResponseGuardrail
  • scopeDeregisterLlmSanitizeResponseGuardrail
  • scopeRegisterLlmConditionalExecutionGuardrail
  • scopeDeregisterLlmConditionalExecutionGuardrail
  • scopeRegisterLlmRequestIntercept
  • scopeDeregisterLlmRequestIntercept
  • scopeRegisterLlmExecutionIntercept
  • scopeDeregisterLlmExecutionIntercept
  • scopeRegisterLlmStreamExecutionIntercept
  • scopeDeregisterLlmStreamExecutionIntercept
  • scopeRegisterSubscriber
  • scopeDeregisterSubscriber
  • toolRequestIntercepts
  • toolConditionalExecution
  • llmRequestIntercepts
  • llmConditionalExecution
  • validatePluginConfig
  • registerPlugin
  • deregisterPlugin
  • initializePlugins
  • clearPluginConfiguration
  • activePluginReport
  • listPluginKinds
ReferenceAPIsNode.js Library Reference

Runtime

||View as Markdown|
Previous

Node.js Library Reference

Next

Typed Helpers

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

Import from nemo-relay-node.

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

Interfaces

AtofExporterConfig

Mutable configuration object for AtofExporter.

1export interface AtofExporterConfig {
2 /** Output directory. Defaults to the current working directory. */
3 outputDirectory?: string
4 /** `"append"` (default) or `"overwrite"`. */
5 mode?: string
6 /** Output filename. Defaults to `nemo-relay-events-YYYY-MM-DD-HH.MM.SS.jsonl`. */
7 filename?: string
8}

OpenTelemetryConfig

Mutable configuration object for OpenTelemetrySubscriber.

1export interface OpenTelemetryConfig {
2 /** `"http_binary"` (default) or `"grpc"`. */
3 transport?: string
4 /** OTLP endpoint, such as `http://localhost:4318/v1/traces`. */
5 endpoint?: string
6 /** Extra exporter headers/metadata as string key/value pairs. */
7 headers?: Json
8 /** Extra OpenTelemetry resource attributes as string key/value pairs. */
9 resourceAttributes?: Json
10 /** `service.name` resource attribute. Defaults to `"nemo-relay"`. */
11 serviceName?: string
12 /** Optional `service.namespace` resource attribute. */
13 serviceNamespace?: string
14 /** Optional `service.version` resource attribute. */
15 serviceVersion?: string
16 /** Instrumentation scope name. Defaults to `"nemo-relay-otel"`. */
17 instrumentationScope?: string
18 /** Export timeout in milliseconds. Defaults to `3000`. */
19 timeoutMillis?: number
20}

OpenInferenceConfig

Mutable configuration object for OpenInferenceSubscriber.

1export interface OpenInferenceConfig {
2 /** `"http_binary"` (default) or `"grpc"`. */
3 transport?: string
4 /** OTLP endpoint, such as `http://localhost:4318/v1/traces`. */
5 endpoint?: string
6 /** Extra exporter headers/metadata as string key/value pairs. */
7 headers?: Json
8 /** Extra OpenInference resource attributes as string key/value pairs. */
9 resourceAttributes?: Json
10 /** `service.name` resource attribute. Defaults to `"nemo-relay"`. */
11 serviceName?: string
12 /** Optional `service.namespace` resource attribute. */
13 serviceNamespace?: string
14 /** Optional `service.version` resource attribute. */
15 serviceVersion?: string
16 /** Instrumentation scope name. Defaults to `"nemo-relay-openinference"`. */
17 instrumentationScope?: string
18 /** Export timeout in milliseconds. Defaults to `3000`. */
19 timeoutMillis?: number
20}

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.

1export declare class AtifExporter {
2 /**
3 * Create a new ATIF exporter.
4 *
5 * `sessionId` identifies the session. `agentName` and `agentVersion` describe the agent.
6 * Optional `modelName` records the LLM model used.
7 */
8 constructor(sessionId: string, agentName: string, agentVersion: string, modelName?: string | undefined | null)
9 /**
10 * Register this exporter as an event subscriber with the given name.
11 *
12 * Throws if a subscriber with the same `name` already exists.
13 */
14 register(name: string): void
15 /**
16 * Deregister this exporter's event subscriber by name.
17 *
18 * Returns `true` if a subscriber with that name was found and removed.
19 */
20 deregister(name: string): boolean
21 /**
22 * Export the collected trajectory as a JSON string.
23 *
24 * Returns a JSON-serialized `AtifTrajectory`.
25 */
26 exportJson(): string
27 /** Clear all collected events from the exporter. */
28 clear(): void
29}

AtofExporter

Filesystem-backed Agent Trajectory Observability Format (ATOF) JSONL event exporter.

1export declare class AtofExporter {
2 /**
3 * Create a new Agent Trajectory Observability Format (ATOF) JSONL exporter
4 * from a config object.
5 */
6 constructor(config?: AtofExporterConfig | undefined | null)
7 /** Return the JSONL output path. */
8 get path(): string
9 /** Register this exporter globally with the given name. */
10 register(name: string): void
11 /** Deregister a subscriber by name. */
12 deregister(name: string): boolean
13 /** Flush the output file. */
14 forceFlush(): void
15 /** Shut down the exporter by flushing output. */
16 shutdown(): void
17}

OpenTelemetrySubscriber

OpenTelemetry-backed event subscriber.

1export declare class OpenTelemetrySubscriber {
2 /** Create a new OpenTelemetry subscriber from a config object. */
3 constructor(config?: OpenTelemetryConfig | undefined | null)
4 /** Register this subscriber globally with the given name. */
5 register(name: string): void
6 /** Deregister a subscriber by name. */
7 deregister(name: string): boolean
8 /** Force a flush of finished spans through the exporter. */
9 forceFlush(): void
10 /** Shut down the underlying tracer provider. */
11 shutdown(): void
12}

OpenInferenceSubscriber

OpenInference-backed event subscriber.

1export declare class OpenInferenceSubscriber {
2 /** Create a new OpenInference subscriber from a config object. */
3 constructor(config?: OpenInferenceConfig | undefined | null)
4 /** Register this subscriber globally with the given name. */
5 register(name: string): void
6 /** Deregister a subscriber by name. */
7 deregister(name: string): boolean
8 /** Force a flush of finished spans through the exporter. */
9 forceFlush(): void
10 /** Shut down the underlying tracer provider. */
11 shutdown(): void
12}

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.

1export declare class LlmStream {
2 /**
3 * Retrieve the next chunk from the stream.
4 *
5 * Returns the next JSON chunk, or `null` when the stream is exhausted.
6 * Throws if the underlying stream encountered an error.
7 */
8 next(): Promise<Json | null>
9}

ScopeStack

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

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

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.

1export declare class ScopeHandle {
2 /** The unique identifier for this scope. */
3 get uuid(): string
4 /** The human-readable name of this scope. */
5 get name(): string
6 /** The type of this scope (Agent, Tool, Llm, etc.). */
7 get scopeType(): ScopeType
8 /** Bitfield of scope attributes (e.g., PARALLEL, RELOCATABLE). */
9 get attributes(): number
10 /** The UUID of this scope's parent, or `null` if this is the root scope. */
11 get parentUuid(): string | null
12 /** Optional user-defined data associated with this scope. */
13 get data(): any | null
14 /** Optional metadata associated with this scope. */
15 get metadata(): any | null
16}

ToolHandle

A handle representing an in-progress tool call.

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

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

LlmHandle

A handle representing an in-progress LLM call.

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

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

LlmRequest

An LLM request, encapsulating headers and content.

Construct via new LlmRequest(headers, content).

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

OpenAIChatCodec

Built-in codec for the OpenAI Chat Completions API.

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

1export declare class OpenAIChatCodec {
2 constructor()
3 /** Decode an opaque LLM request into structured form. */
4 decode(request: Json): Json
5 /** Encode structured changes back into an opaque LLM request. */
6 encode(annotated: Json, original: Json): Json
7 /** Decode a raw LLM response into structured form. */
8 decodeResponse(response: Json): Json
9}

OpenAIResponsesCodec

Built-in codec for the OpenAI Responses API.

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

1export declare class OpenAIResponsesCodec {
2 constructor()
3 /** Decode an opaque LLM request into structured form. */
4 decode(request: Json): Json
5 /** Encode structured changes back into an opaque LLM request. */
6 encode(annotated: Json, original: Json): Json
7 /** Decode a raw LLM response into structured form. */
8 decodeResponse(response: Json): Json
9}

AnthropicMessagesCodec

Built-in codec for the Anthropic Messages API.

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

1export declare class AnthropicMessagesCodec {
2 constructor()
3 /** Decode an opaque LLM request into structured form. */
4 decode(request: Json): Json
5 /** Encode structured changes back into an opaque LLM request. */
6 encode(annotated: Json, original: Json): Json
7 /** Decode a raw LLM response into structured form. */
8 decodeResponse(response: Json): Json
9}

Enums

ScopeType

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

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

Functions

pushStreamChunk

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

1export 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.

1export declare function endStream(streamId: number): void

createScopeStack

Creates a new isolated scope stack.

1export declare function createScopeStack(): ScopeStack

currentScopeStack

Returns the current execution context’s scope stack handle.

1export declare function currentScopeStack(): ScopeStack

setThreadScopeStack

Binds a scope stack to the current thread.

1export 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.

1export 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/intercept/finalizer callback paths whose core callback signatures cannot return Result.

1export declare function getLastCallbackError(): string | null

clearLastCallbackError

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

1export 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.

1export 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.

1export 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. Throws if the handle does not match the current top scope.

1export declare function popScope(handle: ScopeHandle, output?: Json | undefined | null, timestamp?: number | 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.

1export 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.

1export declare function event(name: string, handle?: ScopeHandle | undefined | null, data?: Json | 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.

1export 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.

1export declare function toolCallEnd(handle: ToolHandle, result: Json, 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.

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

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.

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

1export declare function toolCallExecuteAsync(name: string, args: Json, func: (...args: any[]) => any, handle?: ScopeHandle | undefined | null, attributes?: number | undefined | null, data?: Json | undefined | null, metadata?: Json | undefined | null): Promise<unknown>

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.

1export 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.

1export 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.

1export 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 | undefined | null, codecEncode?: (arg: Json) => any | undefined | null, responseCodecDecode?: (arg: Json) => any | undefined | null): 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.

1export 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 | undefined | null, codecEncode?: (arg: Json) => any | undefined | null, responseCodecDecode?: (arg: Json) => any | undefined | null): 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 and must return a JSON value representing the aggregated response.

1export declare function llmStreamCallExecute(name: string, request: Json, func: (arg: Json) => 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 | undefined | null, codecEncode?: (arg: Json) => any | undefined | null, responseCodecDecode?: (arg: Json) => any | undefined | null): Promise<LlmStream>

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.

1export declare function registerToolSanitizeRequestGuardrail(name: string, priority: number, guardrail: (arg0: string, arg1: Json) => any): void

deregisterToolSanitizeRequestGuardrail

Deregister a tool request sanitization guardrail by name.

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

1export 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.

1export declare function registerToolSanitizeResponseGuardrail(name: string, priority: number, guardrail: (arg0: string, arg1: Json) => any): void

deregisterToolSanitizeResponseGuardrail

Deregister a tool response sanitization guardrail by name.

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

1export 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.

1export declare function registerToolConditionalExecutionGuardrail(name: string, priority: number, guardrail: (arg0: string, arg1: Json) => any): void

deregisterToolConditionalExecutionGuardrail

Deregister a tool conditional execution guardrail by name.

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

1export 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.

1export declare function registerToolRequestIntercept(name: string, priority: number, breakChain: boolean, callable: (arg0: string, arg1: Json) => any): void

deregisterToolRequestIntercept

Deregister a tool request intercept by name.

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

1export declare function deregisterToolRequestIntercept(name: string): boolean

registerToolExecutionIntercept

Register a tool execution intercept following the middleware chain pattern.

The callable receives the args and a next function. Call next(args) to invoke the next intercept or original implementation; skip calling next to short-circuit the chain.

1export declare function registerToolExecutionIntercept(name: string, priority: number, callable: (...args: any[]) => any): void

deregisterToolExecutionIntercept

Deregister a tool execution intercept by name.

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

1export declare function deregisterToolExecutionIntercept(name: string): boolean

registerLlmSanitizeRequestGuardrail

Register a guardrail that sanitizes LLM request data before execution.

The guardrail callback receives the LLM request as JSON and must return the sanitized request. Higher priority values run first. Throws if a guardrail with the same name already exists.

1export declare function registerLlmSanitizeRequestGuardrail(name: string, priority: number, guardrail: (arg: Json) => any): void

deregisterLlmSanitizeRequestGuardrail

Deregister an LLM request sanitization guardrail by name.

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

1export declare function deregisterLlmSanitizeRequestGuardrail(name: string): boolean

registerLlmSanitizeResponseGuardrail

Register a guardrail that sanitizes LLM response data after execution.

The guardrail callback receives the LLM response as a JSON value and must return the sanitized response as JSON. Higher priority values run first. Throws if a guardrail with the same name already exists.

1export declare function registerLlmSanitizeResponseGuardrail(name: string, priority: number, guardrail: (arg: Json) => any): void

deregisterLlmSanitizeResponseGuardrail

Deregister an LLM response sanitization guardrail by name.

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

1export 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.

1export declare function registerLlmConditionalExecutionGuardrail(name: string, priority: number, guardrail: (arg: Json) => any): void

deregisterLlmConditionalExecutionGuardrail

Deregister an LLM conditional execution guardrail by name.

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

1export 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.

1export declare function registerLlmRequestIntercept(name: string, priority: number, breakChain: boolean, callable: (arg: Json) => any): void

deregisterLlmRequestIntercept

Deregister an LLM request intercept by name.

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

1export declare function deregisterLlmRequestIntercept(name: string): boolean

registerLlmExecutionIntercept

Register an LLM execution intercept following the middleware chain pattern.

The callable receives the request and a next function. Call next(request) to invoke the next intercept or original implementation; skip calling next to short-circuit the chain.

1export declare function registerLlmExecutionIntercept(name: string, priority: number, callable: (...args: any[]) => any): void

deregisterLlmExecutionIntercept

Deregister an LLM execution intercept by name.

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

1export declare function deregisterLlmExecutionIntercept(name: string): boolean

registerLlmStreamExecutionIntercept

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

The callable receives the request and a next function. Call next(request) to invoke the next intercept or original streaming implementation; in Node the returned promise resolves to an array of downstream JSON chunks. Skip calling next to short-circuit the chain.

1export declare function registerLlmStreamExecutionIntercept(name: string, priority: number, callable: (...args: any[]) => any): void

deregisterLlmStreamExecutionIntercept

Deregister an LLM stream execution intercept by name.

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

1export 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. Events are delivered asynchronously and non-blocking. Throws if a subscriber with the same name already exists.

1export declare function registerSubscriber(name: string, callback: (arg: Json) => any): 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.

1export declare function deregisterSubscriber(name: string): boolean

flushSubscribers

Wait for native subscriber callbacks queued before this call to finish.

JavaScript subscribers are queued through Node’s ThreadsafeFunction; callers that need JS callback side effects should await an event-loop tick after this returns.

1export declare function flushSubscribers(): void

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.

1export declare function scopeRegisterToolSanitizeRequestGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (arg0: string, arg1: Json) => any): 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.

1export 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.

1export declare function scopeRegisterToolSanitizeResponseGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (arg0: string, arg1: Json) => any): 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.

1export 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.

1export declare function scopeRegisterToolConditionalExecutionGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (arg0: string, arg1: Json) => any): 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.

1export 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.

1export declare function scopeRegisterToolRequestIntercept(scopeUuid: string, name: string, priority: number, breakChain: boolean, callable: (arg0: string, arg1: Json) => any): 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.

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

scopeRegisterToolExecutionIntercept

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

The callable receives the args and a next function. Call next(args) to invoke the next intercept or original implementation; skip calling next to short-circuit the chain.

1export declare function scopeRegisterToolExecutionIntercept(scopeUuid: string, name: string, priority: number, callable: (...args: any[]) => any): void

scopeDeregisterToolExecutionIntercept

Deregister a scope-local tool execution intercept by name.

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

1export 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 the LLM request as JSON and must return the sanitized request. Higher priority values run first. Throws if a guardrail with the same name already exists on the specified scope.

1export declare function scopeRegisterLlmSanitizeRequestGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (arg: Json) => any): 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.

1export 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 the LLM response as a JSON value and must return the sanitized response as JSON. Higher priority values run first. Throws if a guardrail with the same name already exists on the specified scope.

1export declare function scopeRegisterLlmSanitizeResponseGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (arg: Json) => any): 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.

1export 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.

1export declare function scopeRegisterLlmConditionalExecutionGuardrail(scopeUuid: string, name: string, priority: number, guardrail: (arg: Json) => any): 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.

1export 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.

1export declare function scopeRegisterLlmRequestIntercept(scopeUuid: string, name: string, priority: number, breakChain: boolean, callable: (arg: Json) => any): 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.

1export 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 and a next function. Call next(request) to invoke the next intercept or original implementation; skip calling next to short-circuit the chain.

1export declare function scopeRegisterLlmExecutionIntercept(scopeUuid: string, name: string, priority: number, callable: (...args: any[]) => any): 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.

1export 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 and a next function. Call next(request) to invoke the next intercept or original streaming implementation; in Node the returned promise resolves to an array of downstream JSON chunks. Skip calling next to short-circuit the chain.

1export declare function scopeRegisterLlmStreamExecutionIntercept(scopeUuid: string, name: string, priority: number, callable: (...args: any[]) => any): 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.

1export 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. Events are delivered asynchronously and non-blocking. Throws if a subscriber with the same name already exists on the specified scope.

1export declare function scopeRegisterSubscriber(scopeUuid: string, name: string, callback: (arg: Json) => any): 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.

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

toolRequestIntercepts

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

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

toolConditionalExecution

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

1export 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.

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

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.

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

validatePluginConfig

Validate a plugin config document and return a structured diagnostics report.

1export declare function validatePluginConfig(config: Json): Json

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.

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

deregisterPlugin

Deregister a plugin by kind.

1export declare function deregisterPlugin(pluginKind: string): boolean

initializePlugins

Initialize the active global plugin components.

1export declare function initializePlugins(config: Json): Promise<Json>

clearPluginConfiguration

Clear the active global plugin configuration.

1export declare function clearPluginConfiguration(): void

activePluginReport

Return the last successfully configured plugin report.

1export declare function activePluginReport(): Json | null

listPluginKinds

List registered plugin kinds.

1export declare function listPluginKinds(): Array<string>