UNPKG

@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

39 lines (38 loc) • 2.13 kB
/** * Token usage as data. A wire's `usage` block in its rules file names where * each count lives; `readWireUsage` reads them and `splitIncludedPart` * applies the one formula every wire shares: a count reported INSIDE another * (cache reads inside the prompt, reasoning inside the completion) is split * out and clamped to its total. */ import type { ProviderUsageCountDialect, ProviderWireUsage, ProviderWireUsageCounts } from "../../types/index.js"; /** The value at a dotted path, or undefined. */ export declare function valueAtPath(source: unknown, path: string): unknown; /** A wire's usage field map; throws when its rules file has none. */ export declare function getWireUsage(id: string): ProviderWireUsage; /** Each count the wire reported, exactly as reported (undefined when absent). */ export declare function readWireUsage(wire: ProviderWireUsage, usage: unknown): ProviderWireUsageCounts; /** * Split `part` out of a `total` that already contains it: `rest` is the * remainder (never below 0) and `part` is clamped to the total, since some * gateways report a part larger than its total. */ export declare function splitIncludedCount(total: number, part: number): { rest: number; part: number; }; /** {@link splitIncludedCount}, passing both through when either is missing. */ export declare function splitIncludedPart(total: number | undefined, part: number | undefined): { rest: number | undefined; part: number | undefined; }; /** Output billed at the output rate: reasoning is added when the wire reports it apart. */ export declare function outputWithReasoning(wire: ProviderWireUsage, output: number, reasoning: number | undefined): number; /** A named count dialect from a rules file; throws when it is missing. */ export declare function getUsageDialect(id: string, name: string): ProviderUsageCountDialect; /** Prompt, completion and total counts read through a dialect (see ProviderUsageCountDialect). */ export declare function readUsageCounts(dialect: ProviderUsageCountDialect, source: unknown): { promptTokens: number; completionTokens: number; total: number; };