import type { AgentMessage } from './agent-runner.js'; import type { OrgBus } from './bus.js'; import type { CumulativeMeter } from './cumulative-meter.js'; import { type Mailbox } from './mailbox.js'; import type { PolicyEngine, TokenUsage } from './policy.js'; /** ADR-O001 D1 — token-metering helpers. * * `cache_read_input_tokens` and `cache_creation_input_tokens` are siblings * of `input_tokens` in the Anthropic API, not subsets of it, and both are * billable. Everything below therefore sums all four. */ export declare function totalTokens(u: TokenUsage): number; export declare function addTo(target: TokenUsage, add: TokenUsage): void; /** One model turn's own usage, off an 'assistant' (or per-turn 'result') * message. */ export declare function turnBreakdown(m: AgentMessage): TokenUsage; /** #597: an assistant message's usage not yet metered for its API response. * A response split across several messages repeats its input/cache usage, * and its earlier messages can carry placeholder output, so each field * counts only its increase over the largest value already seen for that * response id. A message without an id is counted as-is. */ export declare function newResponseUsage(seen: Map, m: AgentMessage): TokenUsage; /** What a 'result' message says this mailbox message consumed. * * When the runner reports `cumulative_tokens` (the Claude SDK's whole-pipeline * `modelUsage`, which unlike `usage` includes Task subagents and sidechains), * that value is CUMULATIVE per session — the same lifecycle as * `total_cost_usd` — so it is converted to a delta by the meter (see * cumulative-meter.ts). Without `cumulative_tokens` the per-turn fields are * used as before. */ export declare function resultBreakdown(m: AgentMessage, tokenTotals: CumulativeMeter | undefined, sid: string): TokenUsage; /** ADR-O001 D1: the four quantities travel separately so every downstream * consumer (forwarder → dashboard state.json, reporting, `org costs`) can * record real values instead of the 0s they used to persist. `tokens` stays * the single billable total. */ export declare function emitUsage(bus: OrgBus, from: string, t: TokenUsage, costUsd: number | undefined, subtype: string | undefined): void; /** The 'result' message's side of a mailbox message's token accounting. * * Per the SDK's own type docs, a 'result' message's usage is that message's * own (effectively last-turn) usage in streaming-input mode, NOT a * cumulative total across every turn of the mailbox message — and that last * turn was already counted via its own 'assistant' message (`turns`), * specifically so overBudget could trip mid-message. Adding the result's own * usage again unconditionally would double-count it. (A modelUsage-derived * delta is per-session-cumulative, so the same subtraction is exactly right * there too: it removes what the assistant turns of THIS message already * contributed and leaves the subagent/auxiliary volume the main loop never * reported.) Only the shortfall (never negative) is added to the meter, so a * turn whose usage never reached the 'assistant' branch (e.g. a runner/test * double that doesn't emit per-turn usage) still gets counted once. * * Returns what the whole mailbox message added to the meter — the per-turn * accounting plus the top-up — which is what the 'usage' event reports, so a * consumer summing events lands on the same number as policy.usage. */ export declare function settleResultTokens(policy: PolicyEngine, result: TokenUsage, turns: TokenUsage): TokenUsage; /** AgentRunArgs.usdBudget for a session: the role's USD cap minus what it has * spent, 0 once its mailbox was closed for budget, undefined with no cap. */ export declare function sessionUsdBudget(policy: PolicyEngine, mailbox: Mailbox): { left: number; } | undefined; /** #550: AgentRunArgs.tokenBudget for a session — what the role may still * spend on the budgeted basis. 0 once its mailbox was closed for budget * (its own cap, budget_usd, or the org-wide ceiling, which closes every * mailbox without touching the role's own meter). */ export declare function sessionTokenBudget(policy: PolicyEngine, mailbox: Mailbox): { left: number; max?: number; } | undefined; //# sourceMappingURL=session-usage.d.ts.map