Generated from cargo doc --no-deps -p nemo-relay -p nemo-relay-adaptive -p nemo-relay-ffi.
C function pointer typedefs and wrapper functions for FFI callbacks.
This module defines the callback signatures used by the C API for tool and LLM guardrails, intercepts, execution functions, and event subscribers. Each pub type alias corresponds to a C function pointer that appears in the generated nemo_relay.h header.
The wrap_* functions convert C callbacks (with opaque user_data pointers) into Rust closures that the core runtime can invoke. Registry-stored callbacks return Arc-backed closures, while one-shot or mutable callback shapes remain boxed. Each wrapper captures the user data and its optional free function in an Arc<UserData> so the closure is Send + Sync and the free function is called exactly once when all references are dropped.
Functions
- wrap_codec_fn: Wrap a pair of C codec callbacks into an
Arc<dyn LlmCodec>.
- wrap_collector_fn: Wrap a C collector callback into a
Box<dyn FnMut(Json) -> Result<()> + Send> for use by the core runtime. Each intercepted chunk Json is serialized to a JSON string and passed to the callback.
- wrap_event_subscriber: Wrap a C event subscriber callback into a Rust closure.
- wrap_finalizer_fn: Wrap a C finalizer callback into a
Box<dyn FnOnce() -> Json + Send> for use by the core runtime. The callback is invoked exactly once when the stream is exhausted. The returned C string is parsed as JSON and then freed.
- wrap_json_fn: Wrap a generic C JSON callback into a Rust closure.
- wrap_llm_conditional_fn: Wrap a C LLM conditional callback into a Rust closure.
- wrap_llm_exec_fn: Wrap a C LLM execution callback into an async Rust closure. The C callback receives an
LlmRequest serialized as a JSON string.
- wrap_llm_exec_intercept_fn: Wrap a C LLM execution intercept callback into an
Arc<dyn Fn(LlmRequest, LlmExecutionNextFn) -> ...>.
- wrap_llm_request_intercept_fn: Wrap a C LLM request intercept callback (annotated-aware) into a Rust
LlmRequestInterceptFn closure. The callback receives the intercept name, the opaque FfiLLMRequest, and the annotated JSON (or null). It writes the transformed request and annotated JSON to output pointers.
- wrap_llm_response_fn: Wrap a C JSON callback into a
Fn(Json) -> Json closure for LLM response sanitization. The callback receives the response as a JSON string and returns the (possibly modified) JSON string.
- wrap_llm_sanitize_request_fn: Wrap a C LLM request sanitize callback into a Rust closure.
- wrap_llm_stream_exec_fn: Wrap a C LLM execution callback into an async Rust closure that returns a stream. The C callback returns the full response as a single JSON string, which is emitted as a single-item stream of Json values.
- wrap_llm_stream_exec_intercept_fn: Wrap a C LLM stream execution intercept callback. Since the C callback returns a single string (not a real stream), this wraps it as a single-item stream, same as
wrap_llm_stream_exec_fn.
- wrap_tool_conditional_fn: Wrap a C tool conditional callback into a Rust closure for use by the core runtime.
- wrap_tool_exec_fn: Wrap a C tool execution callback into an async Rust closure.
- wrap_tool_exec_intercept_fn: Wrap a C tool execution intercept callback into an
Arc<dyn Fn(Json, ToolExecutionNextFn) -> ...>.
- wrap_tool_request_intercept_fn: Wrap a C tool request intercept callback into a Rust closure for use by the core runtime.
- wrap_tool_sanitize_fn: Wrap a C tool sanitize callback into a Rust closure for use by the core runtime.
Type Aliases
- NemoRelayCodecDecodeCb: Callback for Codec decode: translates an opaque
FfiLLMRequest into an AnnotatedLLMRequest JSON string. Returns a heap-allocated C string on success, or null on error (after setting the last error message).
- NemoRelayCodecDecodeFn: Nullable version of
NemoRelayCodecDecodeCb for use as an optional parameter in FFI execute functions. Pass null to indicate no codec.
- NemoRelayCodecEncodeCb: Callback for Codec encode: merges structured changes back into opaque request content. Receives the annotated request as a JSON C string and the original
FfiLLMRequest. Returns a heap-allocated JSON C string representing the new LlmRequest content on success, or null on error.
- NemoRelayCodecEncodeFn: Nullable version of
NemoRelayCodecEncodeCb for use as an optional parameter in FFI execute functions. Pass null to indicate no codec.
- NemoRelayCollectorCb: Callback for collecting intercepted stream chunks. Invoked with each chunk (after stream execution intercepts have been applied) as a null-terminated C string. The string is only valid for the duration of the call.
- NemoRelayEventSubscriberCb: Callback for event subscribers. Invoked on each lifecycle event emitted by the runtime. The
FfiEvent pointer is only valid for the duration of the call.
- NemoRelayFinalizerCb: Callback for finalizing a collected stream. Invoked once when the stream is exhausted. Must return a JSON C string representing the aggregated response. The returned string must be allocated with
malloc or equivalent; the runtime will free it.
- NemoRelayFreeFn: Optional destructor for user data passed to callbacks. Called when the runtime no longer needs the associated callback.
- NemoRelayJsonCb: Generic JSON-to-JSON callback, used for LLM response sanitization and intercepts. The returned string must be allocated with
malloc or equivalent.
- NemoRelayLlmConditionalCb: Callback for LLM conditional execution guardrails. Returns NULL to allow execution, or an error message string to reject.
- NemoRelayLlmExecCb: Callback for LLM execution (default callable). Receives a native JSON C string, returns the response as a JSON C string.
- NemoRelayLlmExecInterceptCb: Callback for LLM execution intercepts with middleware chain support. Receives native JSON C string plus a
next callback and its context.
- NemoRelayLlmExecNextFn: Runtime-provided “next” callback for LLM execution middleware chain. Takes a native JSON C string, returns a response JSON C string.
- NemoRelayLlmRequestCb: Callback for LLM request sanitization. Receives an
FfiLLMRequest and returns a new (possibly modified) FfiLLMRequest. Return null to use defaults.
- NemoRelayLlmRequestInterceptCb: C callback type for LLM request intercepts with unified annotated-aware signature. Receives the intercept name, the opaque
FfiLLMRequest, and optionally the annotated request as a JSON C string (null if no Codec resolved). Writes transformed outputs to out_request and out_annotated_json. Returns NemoRelayStatus.
- NemoRelayPluginRegisterCb: Callback for plugin registration. Receives plugin config JSON and a plugin context pointer that is only valid for the duration of the call.
- NemoRelayPluginValidateCb: Callback for plugin validation. Receives plugin config JSON and returns a JSON array of diagnostics.
- NemoRelayToolConditionalCb: Callback for tool conditional execution guardrails. Receives tool name and arguments as JSON. Returns NULL to allow execution, or an error message string to reject.
- NemoRelayToolExecCb: Callback for tool execution (default callable). Receives arguments as JSON, returns result as JSON. The returned string must be allocated with
malloc or equivalent.
- NemoRelayToolExecInterceptCb: Callback for tool execution intercepts. Receives arguments as JSON plus a
next callback and its context. Call next_fn(args, next_ctx) to invoke the next layer in the middleware chain, or return directly to short-circuit.
- NemoRelayToolExecNextFn: Runtime-provided “next” callback for tool execution middleware chain. Call this from an intercept to invoke the next layer (or original function).
next_ctx is an opaque pointer managed by the runtime.
- NemoRelayToolSanitizeCb: Callback for tool request/response sanitization guardrails and intercepts. Receives tool name and arguments as JSON, returns sanitized arguments as JSON. The returned string must be allocated with
malloc or equivalent.