Skip to navigation

Generated from crates/node/dist/typed.d.ts.

Import from nemo-relay-node/typed.

Typed wrappers for the execute APIs, converting values with a Codec<T>.

Interfaces

ToolExecutionResult

Result returned to the application after tool execution.

export interface ToolExecutionResult<TResult> {
result: TResult;
annotation?: JsonValue;
}

Codec

Converts between a typed value T and JSON.

export interface Codec<T, TJson extends JsonCompatible<TJson> = JsonValue> {
/** Converts a typed value to JSON. */
toJson: (value: T) => TJson;
/** Rebuilds a typed value from JSON. */
fromJson: (data: JsonValue) => T;
}

TypedToolExecuteOptions

Options for typedToolExecute.

export interface TypedToolExecuteOptions<TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue> {
handle?: ScopeHandle | null;
attributes?: number | null;
data?: TData;
metadata?: TMetadata;
toolCallId?: string | null;
/** Host-supplied context for execution intercepts: at most 16 KiB and 64 object/array levels (root is level 1); never event metadata. */
executionContext?: ApplicationExecutionContext | null;
executionOptions?: ExecutionOptions | null;
}

TypedLlmExecuteOptions

Options for typedLlmExecute.

export interface TypedLlmExecuteOptions<TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue> {
handle?: ScopeHandle | null;
attributes?: number | null;
data?: TData;
metadata?: TMetadata;
modelName?: string | null;
codec?: LlmCodec<TAnnotated, TEncoded> | null;
responseCodec?: LlmResponseCodec<TDecodedResponse> | null;
executionOptions?: ExecutionOptions | null;
executionContext?: LlmApplicationExecutionContext | null;
}

TypedLlmStreamExecuteOptions

Options for typedLlmStreamExecute.

export interface TypedLlmStreamExecuteOptions<TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue> {
handle?: ScopeHandle | null;
attributes?: number | null;
data?: TData;
metadata?: TMetadata;
modelName?: string | null;
codec?: LlmCodec<TAnnotated, TEncoded> | null;
responseCodec?: LlmResponseCodec<TDecodedResponse> | null;
executionOptions?: ExecutionOptions | null;
executionContext?: LlmApplicationExecutionContext | null;
}

Classes

JsonPassthrough

Codec that returns values unchanged.

export declare class JsonPassthrough implements Codec<JsonValue> {
toJson(value: JsonValue): JsonValue;
fromJson(data: JsonValue): JsonValue;
}

Functions

typedToolExecute

Executes a tool call with typed arguments and result.

args is encoded with argsCodec before the tool lifecycle runs, and the JSON result is decoded with resultCodec afterwards. The annotation is returned as the pipeline produced it.

Parameters

  • name: Tool name.
  • args: Typed tool arguments.
  • func: The tool. It may return the result directly or in a promise.
  • argsCodec: Converts the arguments to and from JSON.
  • resultCodec: Converts the result to and from JSON.
  • options: Scope handle, attributes, data, metadata, tool call id, and host execution context.

Returns

The decoded result and its annotation.

Remarks

A codec error or an execution error rejects the returned promise.

export declare function typedToolExecute<TArgs, TResult, TArgsJson extends JsonCompatible<TArgsJson> = JsonValue, TResultJson extends JsonCompatible<TResultJson> = JsonValue, TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue>(name: string, args: TArgs, func: (args: TArgs, signal: AbortSignal) => ToolExecutionResult<TResult> | Promise<ToolExecutionResult<TResult>>, argsCodec: Codec<TArgs, TArgsJson>, resultCodec: Codec<TResult, TResultJson>, options?: TypedToolExecuteOptions<TData, TMetadata>): Promise<ToolExecutionResult<TResult>>;

typedLlmExecute

Executes an LLM call with a typed response.

The LLM lifecycle runs on request, and the JSON response is decoded with responseCodec before it is returned.

Parameters

  • name: Provider name.
  • request: Request with headers and content.
  • func: The LLM call. It may return the response directly or in a promise.
  • responseCodec: Converts the response to and from JSON.
  • options: Scope handle, attributes, data, metadata, model name, and codecs.

Returns

The decoded response.

Remarks

options.responseCodec decodes the response copied into events. It does not change the returned response.

export declare function typedLlmExecute<TRequest extends LlmRequestCompatible<TRequest>, TResponse, TResponseJson extends JsonCompatible<TResponseJson> = JsonValue, TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue>(name: string, request: TRequest, func: (request: LlmRequestShape, signal: AbortSignal) => TResponse | Promise<TResponse>, responseCodec: Codec<TResponse, TResponseJson>, options?: TypedLlmExecuteOptions<TData, TMetadata, TAnnotated, TEncoded, TDecodedResponse>): Promise<TResponse>;

typedLlmStreamExecute

Executes a streaming LLM call with typed chunks and response.

Each chunk from func is encoded with chunkCodec before middleware sees it and decoded again before collector receives it. The value from finalizer is encoded with responseCodec.

Parameters

  • name: Provider name.
  • request: Request with headers and content.
  • func: The streaming LLM call. It receives the request and an AbortSignal and returns an async iterable of chunks.
  • collector: Receives one decoded chunk at a time. It may return a promise.
  • finalizer: Returns the final response once the stream ends. It may return a promise.
  • chunkCodec: Converts chunks to and from JSON.
  • responseCodec: Converts the final response to and from JSON.
  • options: Scope handle, attributes, data, metadata, model name, and codecs.

Returns

The LlmStream to read chunks from.

Remarks

An error in collector fails the stream. An error in finalizer is thrown by stream.close(). A reader that stops early must await stream.close(), which aborts the signal and waits for cleanup.

export declare function typedLlmStreamExecute<TRequest extends LlmRequestCompatible<TRequest>, TChunk, TResponse, TChunkJson extends JsonCompatible<TChunkJson> = JsonValue, TResponseJson extends JsonCompatible<TResponseJson> = JsonValue, TData extends JsonCompatible<TData> = JsonValue, TMetadata extends JsonCompatible<TMetadata> = JsonValue, TAnnotated extends JsonCompatible<TAnnotated> = JsonValue, TEncoded extends LlmRequestCompatible<TEncoded> = LlmRequestShape, TDecodedResponse extends JsonCompatible<TDecodedResponse> = JsonValue>(name: string, request: TRequest, func: (request: LlmRequestShape, signal: AbortSignal) => AsyncIterable<TChunk> | Promise<AsyncIterable<TChunk>>, collector: (chunk: TChunk) => void | Promise<void>, finalizer: () => TResponse | Promise<TResponse>, chunkCodec: Codec<TChunk, TChunkJson>, responseCodec: Codec<TResponse, TResponseJson>, options?: TypedLlmStreamExecuteOptions<TData, TMetadata, TAnnotated, TEncoded, TDecodedResponse>): Promise<LlmStream>;

Re-exports

  • ApplicationExecutionContext
  • Json
  • JsonArray
  • JsonCompatible
  • JsonObject
  • JsonPrimitive
  • JsonValue
  • LlmCodec
  • LlmRequestCompatible
  • LlmRequestShape
  • LlmResponseCodec