@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
38 lines (37 loc) • 2.8 kB
TypeScript
import type { Span } from "@opentelemetry/api";
import type { GenerationRecord, ObservationAttributes, ObservationLevel, ObservationType, RawUsageObject, TraceContent } from "../types/index.js";
/**
* @description Stamps Langfuse observation attributes on a span, plus a `gen_ai.observation.type` marker so the exporter pipeline recognizes it whatever its tracer scope. Input and output are credential-masked and capped at `SPAN_ATTRIBUTE_MAX_CHARS` before serialization.
* @param span {Span} - Span to describe.
* @param type {ObservationType} - Observation type Langfuse renders the span as.
* @param attrs {ObservationAttributes} - Input, output, model, parameters, usage, cost, level and metadata to record.
* @returns {void} Nothing.
*/
export declare function observe(span: Span, type: ObservationType, attrs: ObservationAttributes): void;
/**
* @description Sets the trace-level input, output and metadata on a span, credential-masked and capped like `observe`. Each metadata entry is written as its own `langfuse.trace.metadata.<key>` attribute, redacted like input and output.
* @param span {Span} - Span whose trace is described.
* @param io {TraceContent} - Trace input, output and metadata.
* @returns {void} Nothing.
*/
export declare function observeTrace(span: Span, io: TraceContent): void;
/**
* @description Maps any provider's token usage onto Langfuse usage-detail keys.
* @param usage {RawUsageObject | undefined | null} - Token usage in any naming convention NeuroLink normalizes.
* @returns {Record<string, number>} `input`, `output` and `total`, plus `cache_read_input_tokens`, `cache_creation_input_tokens` and `reasoning` when reported.
*/
export declare function usageDetails(usage: RawUsageObject | undefined | null): Record<string, number>;
/**
* @description Picks the Langfuse level for a model call that finished without throwing.
* @param finishReason {string | undefined} - Provider finish reason, in any casing.
* @param aborted {boolean | undefined} - Whether the caller aborted or closed the call early.
* @returns {ObservationLevel | undefined} `"WARNING"` for truncated, filtered, aborted or empty output, otherwise `undefined`.
*/
export declare function observationLevel(finishReason?: string, aborted?: boolean): ObservationLevel | undefined;
/**
* @description Records a model request on its span as a Langfuse generation: model, defined parameters, input, output, usage, cost and level. Safe to call once with the request and again with the response; unset fields leave earlier values in place.
* @param span {Span} - Span of one model request.
* @param call {GenerationRecord} - What was sent and what came back.
* @returns {void} Nothing.
*/
export declare function observeGeneration(span: Span, call: GenerationRecord): void;