mirror of
https://github.com/openai/codex.git
synced 2026-10-21 17:48:44 +00:00
Preserve raw response usage metadata (#41980)
## What changed - Include the complete upstream `response.usage` object in `ResponseUsageMetadata.metadata` while retaining the existing `amount` field. - Expose the metadata through `rawResponse/completed` notifications and update the generated JSON and TypeScript schemas. ## Testing - Cover SSE, WebSocket, turn, and compaction completion paths. GitOrigin-RevId: 6d79b1b4c92ac11abf43ec98f380b4868288a701
This commit is contained in:
@@ -478,8 +478,15 @@ pub fn process_responses_event(
|
||||
}
|
||||
"response.completed" => {
|
||||
if let Some(resp_val) = event.response {
|
||||
let metadata = resp_val
|
||||
.get("usage")
|
||||
.filter(|usage| !usage.is_null())
|
||||
.cloned();
|
||||
match serde_json::from_value::<ResponseCompleted>(resp_val) {
|
||||
Ok(resp) => {
|
||||
Ok(mut resp) => {
|
||||
if let Some(metadata) = metadata {
|
||||
resp.usage_metadata.get_or_insert_default().metadata = Some(metadata);
|
||||
}
|
||||
return Ok(Some(ResponseEvent::Completed {
|
||||
response_id: resp.id,
|
||||
token_usage: resp.usage.map(Into::into),
|
||||
|
||||
Reference in New Issue
Block a user