@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
37 lines (36 loc) • 1.92 kB
TypeScript
/**
* Reads token usage out of OpenCode's local SQLite store.
*
* Store: `~/.local/share/opencode/opencode.db` (NOT `~/.config/opencode`,
* which holds only configuration). Usage lives on the `message` table, whose
* `data` column is a JSON blob carrying `role`, `modelID`, `providerID`,
* `cost` and a `tokens` object.
*
* Two things the real data settled, both of which would corrupt totals
* silently if assumed instead of checked.
*
* **Cache is DISJOINT from input here.** Measured across all 4,674
* usage-bearing messages on a reference machine, `total` equals
* `input + output + cache.read + cache.write` — never `input + output` alone
* unless cache happened to be zero. This is the opposite of Codex, where
* `cached_input_tokens` is a SUBSET of `input_tokens` and has to be subtracted
* back out. Three readers now, three conventions; none of them is safe to
* infer from the others.
*
* **OpenCode's own `cost` field is not usable.** It was 0 in all 4,674
* messages, while the provider mix spanned `github-copilot` (a subscription),
* `openai` (metered) and `neurolink` (this proxy). A single cost figure for
* that mixture would be wrong whichever way it was computed, so tokens are
* reported and cost is declared `unavailable` rather than invented or
* quietly zeroed.
*
* Worth knowing for anyone summing sources: traffic OpenCode sent through the
* NeuroLink proxy appears under `providerID: "neurolink"` here AND in the
* proxy's own ledger. The two are independent measurements of the same
* requests, not additive. On the reference machine that was 41 messages and
* ~772k tokens against 458M total, so it is small — but it is not zero, and a
* dashboard adding local usage to proxy usage double-counts exactly that
* slice.
*/
import type { LocalUsageReader } from "../types/index.js";
export declare function createOpenCodeReader(): Promise<LocalUsageReader>;