mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-11-17 09:31:45 +00:00
The run detail tab, route, query hook, and query key say usage. Every read of input_tokens, output_tokens, total_tokens, reasoning_tokens, cache_read_tokens, cache_write_tokens, and total_usd_micros moves to usage.tokens and usage.cost, with lib/usage.ts replacing lib/billing.ts: totalTokens sums the five buckets, and costSourceTag names a cost that the provider reported or that was summed from differently sourced parts. The Usage tab and the stage popover show that tag next to such a cost. Test fixtures build a Usage through makeUsage; the failing set of the web tests is unchanged from main (the same 13 environment failures). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
30 lines
864 B
TypeScript
30 lines
864 B
TypeScript
import type { Cost, Principal, TokenCounts, Usage } from "@qltysh/fabro-api-client";
|
|
|
|
export const TEST_PRINCIPAL: Principal = {
|
|
kind: "user",
|
|
identity: { issuer: "fabro:test", subject: "test-user" },
|
|
login: "test",
|
|
auth_method: "dev_token",
|
|
};
|
|
|
|
export function makeTokenCounts(overrides: Partial<TokenCounts> = {}): TokenCounts {
|
|
return {
|
|
input: 0,
|
|
output: 0,
|
|
reasoning: 0,
|
|
cache_read: 0,
|
|
cache_write: 0,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
/** A usage with the given token buckets and, when `cost` is given, a catalog cost. */
|
|
export function makeUsage(
|
|
tokens: Partial<TokenCounts> = {},
|
|
cost?: number | Cost,
|
|
): Usage {
|
|
const usage: Usage = { tokens: makeTokenCounts(tokens) };
|
|
if (typeof cost === "number") usage.cost = { usd_micros: cost, source: "catalog" };
|
|
else if (cost) usage.cost = cost;
|
|
return usage;
|
|
}
|