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

43 lines (42 loc) • 2.19 kB
/** * Per-account token and cost totals, read incrementally from the proxy's own * request log. * * `~/.neurolink/logs` runs to hundreds of megabytes, so a polled endpoint * cannot re-read it per request. This keeps a per-file cursor and only ever * reads bytes appended since the last call. * * ## Why this is not built on proxyAnalysis.ts * * That module always re-reads whole files and sweeps the lifecycle, attempts * and debug streams too. Attempts carry one row per retry for the same * requestId, so folding them in would multiply a retried request's tokens by * its retry count. * * ## Correctness rules this file exists to enforce * * - **Only `proxy-<date>.jsonl`.** Never attempts/lifecycle/debug. * - **Dedupe by requestId.** A request can be logged twice: once when the * response headers are known and again when a streamed body finishes and its * token counts arrive (the Codex engine does exactly this). Totals are * derived from a requestId-keyed map, never by adding up raw lines. * - **Only advance the cursor to the last complete newline**, so a line still * being appended is re-read whole next time rather than parsed truncated. * - **A shrinking file means delete-and-recreate**, not truncation — the writer * only appends. Reset the cursor rather than reporting corruption. */ import type { CliAccountUsageTotals } from "../types/index.js"; /** UTC date stamp of the log file the totals cover. */ export declare function currentUsageDate(now?: Date): string; /** * Token and cost totals for one UTC day, keyed by provider-qualified account * key ("anthropic:<label>" / "codex:<label>"). * * Both engines' rows are attributed, each under its own key, so a Codex login * sharing an email with an Anthropic one contributes to its own row and never * to the other's. Keying by bare label used to force a choice between merging * them and dropping Codex outright; it dropped Codex. */ export declare function readAccountUsage(date?: string): Promise<Map<string, CliAccountUsageTotals>>; /** Drop all cached cursors. Exported for tests, which vary HOME per case. */ export declare function resetAccountLedgerCache(): void;