Skip to content

Commit 168d495

Browse files
committed
feat(ai): allow provider-specific numeric fields on UsageTotals.costDetails
The JSDoc promised "loosely typed" costDetails to accommodate provider divergence (BYOK upstream costs, cache discounts, per-tier rates) but the declared shape only allowed two OpenRouter-specific keys, so any other adapter would have been forced to `as any`-cast to report its own breakdown. Add a numeric index signature so additional keys are type-legal without a cast, matching the documented intent. Picked up in CodeRabbit review of TanStack#469.
1 parent 08840ac commit 168d495

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

packages/typescript/ai/src/types.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,6 @@ export interface RunStartedEvent extends AGUIRunStartedEvent {
803803
model?: string
804804
}
805805

806-
/**
807-
* Emitted when a run completes successfully.
808-
*
809-
* @ag-ui/core provides: `threadId`, `runId`, `result?`
810-
* TanStack AI adds: `model?`, `finishReason?`, `usage?`
811-
*/
812806
/**
813807
* Per-run token and cost totals, shared between `RunFinishedEvent.usage`
814808
* and the middleware `UsageInfo` so the two can never drift.
@@ -829,14 +823,23 @@ export interface UsageTotals {
829823
* Provider-reported cost breakdown. Loosely typed because providers
830824
* disagree on what to expose (BYOK upstream costs, cache discounts,
831825
* per-tier rates, ...) and locking the shape down would force every
832-
* new adapter to either lie or back-fill.
826+
* new adapter to either lie or back-fill. The named fields are
827+
* whatever OpenRouter currently reports; other adapters may report
828+
* numeric fields under their own keys via the index signature.
833829
*/
834830
costDetails?: {
835831
upstreamInferenceCost?: number | null
836832
cacheDiscount?: number | null
833+
[key: string]: number | null | undefined
837834
}
838835
}
839836

837+
/**
838+
* Emitted when a run completes successfully.
839+
*
840+
* @ag-ui/core provides: `threadId`, `runId`, `result?`
841+
* TanStack AI adds: `model?`, `finishReason?`, `usage?`
842+
*/
840843
export interface RunFinishedEvent extends AGUIRunFinishedEvent {
841844
/** Model identifier for multi-model support */
842845
model?: string

0 commit comments

Comments
 (0)