refactor(ai): use typed choice.usage in openai-chat parser (#57596)

This commit is contained in:
Aiden Cline
2026-10-20 22:50:37 -05:00
committed by GitHub
Unverified
parent 4b50f5cc6c
commit 8c60f940bc
+1 -2
View File
@@ -1028,10 +1028,9 @@ const step = (state: ParserState, event: OpenAIChatEvent) =>
const choice = event.choices?.[0]
// Moonshot (and a few other OpenAI-compatible providers) attach usage to
// `choice.usage` instead of the top-level `usage` field.
const choiceUsage = (choice as unknown as { usage?: OpenAIChatEvent["usage"] })?.usage
const usage =
mapUsage(event.usage, state.providerMetadataKey) ??
(choiceUsage ? mapUsage(choiceUsage, state.providerMetadataKey) : undefined) ??
mapUsage(choice?.usage, state.providerMetadataKey) ??
state.usage
const rawFinishReason = choice?.finish_reason
const finishReason = rawFinishReason