@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
57 lines (56 loc) • 3.13 kB
TypeScript
import type { MetricConnectionType } from "../types/index.js";
/**
* @description Counts one AI request with its duration, tokens and, when known, cost, labelled by provider and model.
* @param provider {string} - Provider that served the request.
* @param model {string} - Model that served the request.
* @param tokens {number} - Total tokens used.
* @param durationMs {number} - Request duration in milliseconds.
* @param cost {number | undefined} - Cost in USD; omitted or non-positive values add nothing to the cost counter.
* @returns {void} Nothing.
*/
export declare function recordAIRequest(provider: string, model: string, tokens: number, durationMs: number, cost?: number): void;
/**
* @description Counts one AI provider error, labelled by provider, error name and a bounded `message`: the HTTP status the error carries (`HTTP 429`), or `unspecified`, never the message text.
* @param provider {string} - Provider that failed.
* @param error {Error} - The failure.
* @returns {void} Nothing.
*/
export declare function recordAIError(provider: string, error: Error): void;
/**
* @description Counts one MCP tool call, labelled by tool, outcome and a duration bucket (`fast`, `medium`, `slow`, `very_slow`).
* @param toolName {string} - Name of the tool.
* @param durationMs {number} - Call duration in milliseconds.
* @param success {boolean} - `false` for a thrown error and for a resolved MCP error result.
* @returns {void} Nothing.
*/
export declare function recordMCPToolCall(toolName: string, durationMs: number, success: boolean): void;
/**
* @description Counts one opened connection, labelled by its type.
* @param type {MetricConnectionType} - `websocket`, `sse` or `http`.
* @returns {void} Nothing.
*/
export declare function recordConnection(type: MetricConnectionType): void;
/**
* @description Records one server response time, labelled by endpoint, method and a status bucket (`excellent`, `good`, `acceptable`, `poor`).
* @param endpoint {string} - Route that answered.
* @param method {string} - HTTP method.
* @param durationMs {number} - Response time in milliseconds.
* @returns {void} Nothing.
*/
export declare function recordResponseTime(endpoint: string, method: string, durationMs: number): void;
/**
* @description Adds to a counter named `custom_<name>`, created on first use.
* @param name {string} - Metric name without the `custom_` prefix.
* @param value {number} - Amount to add.
* @param labels {Record<string, string> | undefined} - Series labels.
* @returns {void} Nothing.
*/
export declare function recordCustomMetric(name: string, value: number, labels?: Record<string, string>): void;
/**
* @description Records into a histogram named `custom_<name>_histogram`, created on first use.
* @param name {string} - Metric name without the `custom_` prefix and `_histogram` suffix.
* @param value {number} - Value to record.
* @param labels {Record<string, string> | undefined} - Series labels.
* @returns {void} Nothing.
*/
export declare function recordCustomHistogram(name: string, value: number, labels?: Record<string, string>): void;