/** * @license * Copyright 2026 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { Usage } from "@workglow/ai"; /** * Collects Anthropic's token accounting off a raw Messages event stream. * * Anthropic splits usage across two frames: `message_start` carries the prompt * side (`input_tokens`, `cache_read_input_tokens`, `cache_creation_input_tokens`) * while `message_delta` carries the running completion side. Both report * **cumulative** figures, so each field is last-reported-wins rather than summed * — the collector never adds counts of its own, it only keeps the newest number * the SDK stated. * * `message_delta.usage` nulls the prompt-side fields on older API versions; a * `null` is "not restated here", so it leaves the earlier value intact rather * than erasing it. A field no frame ever reported stays `undefined`. */ export interface IAnthropicUsageCollector { /** Feed one raw SDK stream event. Non-usage events are ignored. */ readonly observe: (event: unknown) => void; /** The collected usage, or `undefined` when the stream reported none. */ readonly result: () => Usage | undefined; } /** * Map one Anthropic usage payload into {@link Usage}. * * Anthropic already reports the three prompt buckets disjointly — `input_tokens` * excludes both cache reads and cache writes — so nothing is subtracted here. * Used directly for non-streaming calls (a checkpoint warm-up) and per frame by * {@link createAnthropicUsageCollector} for streams. */ export declare function mapAnthropicUsage(raw: unknown): Usage | undefined; export declare function createAnthropicUsageCollector(): IAnthropicUsageCollector;