feat(core): add metadata field to ResponseItem (#28355)

## Description

This PR adds an optional `metadata` field to `ResponseItem` for
Responses API calls. Only mechanical plumbing, no actual values
populated and sent yet. Turns out just adding a new field to
`ResponseItem` has quite a large blast radius already.

This change is backwards compatible because `metadata` is optional and
omitted when absent, so existing response items and rollout history
without it still deserialize and requests that do not set it keep the
same wire shape. For provider compatibility, we strip out `metadata`
before non-OpenAI Responses requests so Azure and AWS Bedrock never see
this field.

My followup PR here will actually make use of it to start storing and
passing along `turn_id`: https://github.com/openai/codex/pull/28360

## What changed

- Added `ResponseItemMetadata` with optional `turn_id`, plus optional
`metadata` on Responses API item variants and inter-agent communication.
- Preserved item metadata through response-item rewrites such as
truncation, missing tool-output synthesis, compaction history
rebuilding, visible-history conversion, rollout/resume, and generated
app-server schemas/types.
- Strip item metadata from non-OpenAI Responses requests while
preserving it for OpenAI-shaped requests.
- Updated the mechanical fixture/test construction churn required by the
new optional field.
This commit is contained in:
Owen Lin
2026-06-15 15:05:28 -07:00
committed by GitHub
Unverified
parent bef99f861b
commit 040dafa32d
85 changed files with 1637 additions and 92 deletions
+16 -12
View File
@@ -338,23 +338,25 @@ impl ContextManager {
fn process_item(&self, item: &ResponseItem, policy: TruncationPolicy) -> ResponseItem {
let policy_with_serialization_budget = policy * 1.2;
match item {
ResponseItem::FunctionCallOutput { call_id, output } => {
ResponseItem::FunctionCallOutput {
call_id: call_id.clone(),
output: truncate_function_output_payload(
output,
policy_with_serialization_budget,
),
}
}
ResponseItem::FunctionCallOutput {
call_id,
output,
metadata,
} => ResponseItem::FunctionCallOutput {
call_id: call_id.clone(),
output: truncate_function_output_payload(output, policy_with_serialization_budget),
metadata: metadata.clone(),
},
ResponseItem::CustomToolCallOutput {
call_id,
name,
output,
metadata,
} => ResponseItem::CustomToolCallOutput {
call_id: call_id.clone(),
name: name.clone(),
output: truncate_function_output_payload(output, policy_with_serialization_budget),
metadata: metadata.clone(),
},
ResponseItem::Message { .. }
| ResponseItem::AgentMessage { .. }
@@ -367,7 +369,7 @@ impl ContextManager {
| ResponseItem::ImageGenerationCall { .. }
| ResponseItem::CustomToolCall { .. }
| ResponseItem::Compaction { .. }
| ResponseItem::CompactionTrigger
| ResponseItem::CompactionTrigger { .. }
| ResponseItem::ContextCompaction { .. }
| ResponseItem::Other => item.clone(),
}
@@ -459,7 +461,7 @@ fn is_api_message(message: &ResponseItem) -> bool {
| ResponseItem::ImageGenerationCall { .. }
| ResponseItem::Compaction { .. }
| ResponseItem::ContextCompaction { .. } => true,
ResponseItem::CompactionTrigger => false,
ResponseItem::CompactionTrigger { .. } => false,
ResponseItem::Other => false,
}
}
@@ -511,9 +513,11 @@ fn estimate_response_item_model_visible_bytes(item: &ResponseItem) -> i64 {
}
| ResponseItem::Compaction {
encrypted_content: content,
..
}
| ResponseItem::ContextCompaction {
encrypted_content: Some(content),
..
} => i64::try_from(estimate_reasoning_length(content.len())).unwrap_or(i64::MAX),
item => {
let raw = serde_json::to_string(item)
@@ -689,7 +693,7 @@ fn is_model_generated_item(item: &ResponseItem) -> bool {
| ResponseItem::LocalShellCall { .. }
| ResponseItem::Compaction { .. }
| ResponseItem::ContextCompaction { .. } => true,
ResponseItem::CompactionTrigger => false,
ResponseItem::CompactionTrigger { .. } => false,
ResponseItem::FunctionCallOutput { .. }
| ResponseItem::ToolSearchOutput { .. }
| ResponseItem::CustomToolCallOutput { .. }
@@ -14,6 +14,7 @@ use codex_protocol::models::LocalShellExecAction;
use codex_protocol::models::LocalShellStatus;
use codex_protocol::models::ReasoningItemContent;
use codex_protocol::models::ReasoningItemReasoningSummary;
use codex_protocol::models::ResponseItemMetadata;
use codex_protocol::openai_models::InputModality;
use codex_protocol::openai_models::default_input_modalities;
use codex_protocol::protocol::AskForApproval;
@@ -41,6 +42,7 @@ fn assistant_msg(text: &str) -> ResponseItem {
text: text.to_string(),
}],
phase: None,
metadata: None,
}
}
@@ -59,6 +61,7 @@ fn inter_agent_assistant_msg(text: &str) -> ResponseItem {
text: serde_json::to_string(&communication).unwrap(),
}],
phase: None,
metadata: None,
}
}
@@ -78,6 +81,7 @@ fn user_msg(text: &str) -> ResponseItem {
text: text.to_string(),
}],
phase: None,
metadata: None,
}
}
@@ -89,6 +93,7 @@ fn user_input_text_msg(text: &str) -> ResponseItem {
text: text.to_string(),
}],
phase: None,
metadata: None,
}
}
@@ -100,6 +105,7 @@ fn developer_msg(text: &str) -> ResponseItem {
text: text.to_string(),
}],
phase: None,
metadata: None,
}
}
@@ -114,6 +120,7 @@ fn developer_msg_with_fragments(texts: &[&str]) -> ResponseItem {
})
.collect(),
phase: None,
metadata: None,
}
}
@@ -145,6 +152,7 @@ fn custom_tool_call_output(call_id: &str, output: &str) -> ResponseItem {
call_id: call_id.to_string(),
name: None,
output: FunctionCallOutputPayload::from_text(output.to_string()),
metadata: None,
}
}
@@ -158,6 +166,7 @@ fn reasoning_msg(text: &str) -> ResponseItem {
text: text.to_string(),
}]),
encrypted_content: None,
metadata: None,
}
}
@@ -169,6 +178,7 @@ fn reasoning_with_encrypted_content(len: usize) -> ResponseItem {
}],
content: None,
encrypted_content: Some("a".repeat(len)),
metadata: None,
}
}
@@ -192,6 +202,7 @@ fn filters_non_api_messages() {
text: "ignored".to_string(),
}],
phase: None,
metadata: None,
};
let reasoning = reasoning_msg("thinking...");
h.record_items([&system, &reasoning, &ResponseItem::Other], policy);
@@ -214,6 +225,7 @@ fn filters_non_api_messages() {
text: "thinking...".to_string(),
}]),
encrypted_content: None,
metadata: None,
},
ResponseItem::Message {
id: None,
@@ -222,6 +234,7 @@ fn filters_non_api_messages() {
text: "hi".to_string()
}],
phase: None,
metadata: None,
},
ResponseItem::Message {
id: None,
@@ -230,6 +243,7 @@ fn filters_non_api_messages() {
text: "hello".to_string()
}],
phase: None,
metadata: None,
}
]
);
@@ -379,6 +393,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
},
],
phase: None,
metadata: None,
},
ResponseItem::FunctionCall {
id: None,
@@ -386,6 +401,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-1".to_string(),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-1".to_string(),
@@ -398,6 +414,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
detail: Some(DEFAULT_IMAGE_DETAIL),
},
]),
metadata: None,
},
ResponseItem::CustomToolCall {
id: None,
@@ -405,6 +422,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
call_id: "tool-1".to_string(),
name: "js_repl".to_string(),
input: "view_image".to_string(),
metadata: None,
},
ResponseItem::CustomToolCallOutput {
call_id: "tool-1".to_string(),
@@ -418,6 +436,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
detail: Some(DEFAULT_IMAGE_DETAIL),
},
]),
metadata: None,
},
];
let history = create_history_with_items(items);
@@ -441,6 +460,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
},
],
phase: None,
metadata: None,
},
ResponseItem::FunctionCall {
id: None,
@@ -448,6 +468,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-1".to_string(),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-1".to_string(),
@@ -460,6 +481,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
.to_string(),
},
]),
metadata: None,
},
ResponseItem::CustomToolCall {
id: None,
@@ -467,6 +489,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
call_id: "tool-1".to_string(),
name: "js_repl".to_string(),
input: "view_image".to_string(),
metadata: None,
},
ResponseItem::CustomToolCallOutput {
call_id: "tool-1".to_string(),
@@ -480,6 +503,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
.to_string(),
},
]),
metadata: None,
},
];
assert_eq!(stripped, expected);
@@ -499,6 +523,7 @@ fn for_prompt_strips_images_when_model_does_not_support_images() {
},
],
phase: None,
metadata: None,
}]);
let preserved = with_images.for_prompt(&modalities);
assert_eq!(preserved.len(), 1);
@@ -518,6 +543,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
status: "generating".to_string(),
revised_prompt: Some("lobster".to_string()),
result: "Zm9v".to_string(),
metadata: None,
},
ResponseItem::Message {
id: None,
@@ -526,6 +552,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
text: "hi".to_string(),
}],
phase: None,
metadata: None,
},
]);
@@ -537,6 +564,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
status: "generating".to_string(),
revised_prompt: Some("lobster".to_string()),
result: "Zm9v".to_string(),
metadata: None,
},
ResponseItem::Message {
id: None,
@@ -545,6 +573,7 @@ fn for_prompt_preserves_image_generation_calls_when_images_are_supported() {
text: "hi".to_string(),
}],
phase: None,
metadata: None,
}
]
);
@@ -560,12 +589,14 @@ fn for_prompt_clears_image_generation_result_when_images_are_unsupported() {
text: "generate a lobster".to_string(),
}],
phase: None,
metadata: None,
},
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
status: "completed".to_string(),
revised_prompt: Some("lobster".to_string()),
result: "Zm9v".to_string(),
metadata: None,
},
]);
@@ -579,12 +610,14 @@ fn for_prompt_clears_image_generation_result_when_images_are_unsupported() {
text: "generate a lobster".to_string(),
}],
phase: None,
metadata: None,
},
ResponseItem::ImageGenerationCall {
id: "ig_123".to_string(),
status: "completed".to_string(),
revised_prompt: Some("lobster".to_string()),
result: String::new(),
metadata: None,
},
]
);
@@ -621,10 +654,12 @@ fn remove_first_item_removes_matching_output_for_function_call() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-1".to_string(),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
},
];
let mut h = create_history_with_items(items);
@@ -638,6 +673,7 @@ fn remove_first_item_removes_matching_call_for_output() {
ResponseItem::FunctionCallOutput {
call_id: "call-2".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
},
ResponseItem::FunctionCall {
id: None,
@@ -645,6 +681,7 @@ fn remove_first_item_removes_matching_call_for_output() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-2".to_string(),
metadata: None,
},
];
let mut h = create_history_with_items(items);
@@ -667,6 +704,7 @@ fn replace_last_turn_images_replaces_tool_output_images() {
]),
success: Some(true),
},
metadata: None,
},
];
let mut history = create_history_with_items(items);
@@ -687,6 +725,7 @@ fn replace_last_turn_images_replaces_tool_output_images() {
]),
success: Some(true),
},
metadata: None,
},
]
);
@@ -702,6 +741,7 @@ fn replace_last_turn_images_does_not_touch_user_images() {
detail: Some(DEFAULT_IMAGE_DETAIL),
}],
phase: None,
metadata: None,
}];
let mut history = create_history_with_items(items.clone());
@@ -723,10 +763,12 @@ fn remove_first_item_handles_local_shell_pair() {
env: None,
user: None,
}),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-3".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
},
];
let mut h = create_history_with_items(items);
@@ -948,11 +990,13 @@ fn remove_first_item_handles_custom_tool_pair() {
call_id: "tool-1".to_string(),
name: "my_tool".to_string(),
input: "{}".to_string(),
metadata: None,
},
ResponseItem::CustomToolCallOutput {
call_id: "tool-1".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
},
];
let mut h = create_history_with_items(items);
@@ -974,10 +1018,12 @@ fn normalization_retains_local_shell_outputs() {
env: None,
user: None,
}),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "shell-1".to_string(),
output: FunctionCallOutputPayload::from_text("Total output lines: 1\n\nok".to_string()),
metadata: None,
},
];
@@ -1001,6 +1047,9 @@ fn record_items_truncates_function_call_output_content() {
body: FunctionCallOutputBody::Text(long_output.clone()),
success: Some(true),
},
metadata: Some(ResponseItemMetadata {
turn_id: Some("turn-1".to_string()),
}),
};
history.record_items([&item], policy);
@@ -1021,6 +1070,7 @@ fn record_items_truncates_function_call_output_content() {
}
other => panic!("unexpected history item: {other:?}"),
}
assert_eq!(history.items[0].turn_id(), Some("turn-1"));
}
#[test]
@@ -1033,6 +1083,7 @@ fn record_items_truncates_custom_tool_call_output_content() {
call_id: "tool-200".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text(long_output.clone()),
metadata: None,
};
history.record_items([&item], policy);
@@ -1066,6 +1117,7 @@ fn record_items_respects_custom_token_limit() {
body: FunctionCallOutputBody::Text(long_output),
success: Some(true),
},
metadata: None,
};
history.record_items([&item], policy);
@@ -1185,6 +1237,7 @@ fn normalize_adds_missing_output_for_function_call() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-x".to_string(),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1199,10 +1252,12 @@ fn normalize_adds_missing_output_for_function_call() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-x".to_string(),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-x".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
]
);
@@ -1217,6 +1272,7 @@ fn normalize_adds_missing_output_for_custom_tool_call() {
call_id: "tool-x".to_string(),
name: "custom".to_string(),
input: "{}".to_string(),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1231,11 +1287,13 @@ fn normalize_adds_missing_output_for_custom_tool_call() {
call_id: "tool-x".to_string(),
name: "custom".to_string(),
input: "{}".to_string(),
metadata: None,
},
ResponseItem::CustomToolCallOutput {
call_id: "tool-x".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
]
);
@@ -1255,6 +1313,7 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id() {
env: None,
user: None,
}),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1274,10 +1333,12 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id() {
env: None,
user: None,
}),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "shell-1".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
]
);
@@ -1289,6 +1350,7 @@ fn normalize_removes_orphan_function_call_output() {
let items = vec![ResponseItem::FunctionCallOutput {
call_id: "orphan-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1304,6 +1366,7 @@ fn normalize_removes_orphan_custom_tool_call_output() {
call_id: "orphan-2".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1323,11 +1386,13 @@ fn normalize_mixed_inserts_and_removals() {
namespace: None,
arguments: "{}".to_string(),
call_id: "c1".to_string(),
metadata: None,
},
// Orphan output that should be removed
ResponseItem::FunctionCallOutput {
call_id: "c2".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
},
// Will get an inserted custom tool output
ResponseItem::CustomToolCall {
@@ -1336,6 +1401,7 @@ fn normalize_mixed_inserts_and_removals() {
call_id: "t1".to_string(),
name: "tool".to_string(),
input: "{}".to_string(),
metadata: None,
},
// Local shell call also gets an inserted function call output
ResponseItem::LocalShellCall {
@@ -1349,6 +1415,7 @@ fn normalize_mixed_inserts_and_removals() {
env: None,
user: None,
}),
metadata: None,
},
];
let mut h = create_history_with_items(items);
@@ -1364,10 +1431,12 @@ fn normalize_mixed_inserts_and_removals() {
namespace: None,
arguments: "{}".to_string(),
call_id: "c1".to_string(),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "c1".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
ResponseItem::CustomToolCall {
id: None,
@@ -1375,11 +1444,13 @@ fn normalize_mixed_inserts_and_removals() {
call_id: "t1".to_string(),
name: "tool".to_string(),
input: "{}".to_string(),
metadata: None,
},
ResponseItem::CustomToolCallOutput {
call_id: "t1".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
ResponseItem::LocalShellCall {
id: None,
@@ -1392,10 +1463,12 @@ fn normalize_mixed_inserts_and_removals() {
env: None,
user: None,
}),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "s1".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
]
);
@@ -1409,6 +1482,7 @@ fn normalize_adds_missing_output_for_function_call_inserts_output() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-x".to_string(),
metadata: None,
}];
let mut h = create_history_with_items(items);
h.normalize_history(&default_input_modalities());
@@ -1421,10 +1495,12 @@ fn normalize_adds_missing_output_for_function_call_inserts_output() {
namespace: None,
arguments: "{}".to_string(),
call_id: "call-x".to_string(),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "call-x".to_string(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
]
);
@@ -1438,6 +1514,7 @@ fn normalize_adds_missing_output_for_tool_search_call() {
status: Some("completed".to_string()),
execution: "client".to_string(),
arguments: "{}".into(),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1452,12 +1529,14 @@ fn normalize_adds_missing_output_for_tool_search_call() {
status: Some("completed".to_string()),
execution: "client".to_string(),
arguments: "{}".into(),
metadata: None,
},
ResponseItem::ToolSearchOutput {
call_id: Some("search-call-x".to_string()),
status: "completed".to_string(),
execution: "client".to_string(),
tools: Vec::new(),
metadata: None,
},
]
);
@@ -1473,6 +1552,7 @@ fn normalize_adds_missing_output_for_custom_tool_call_panics_in_debug() {
call_id: "tool-x".to_string(),
name: "custom".to_string(),
input: "{}".to_string(),
metadata: None,
}];
let mut h = create_history_with_items(items);
h.normalize_history(&default_input_modalities());
@@ -1493,6 +1573,7 @@ fn normalize_adds_missing_output_for_local_shell_call_with_id_panics_in_debug()
env: None,
user: None,
}),
metadata: None,
}];
let mut h = create_history_with_items(items);
h.normalize_history(&default_input_modalities());
@@ -1505,6 +1586,7 @@ fn normalize_removes_orphan_function_call_output_panics_in_debug() {
let items = vec![ResponseItem::FunctionCallOutput {
call_id: "orphan-1".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
}];
let mut h = create_history_with_items(items);
h.normalize_history(&default_input_modalities());
@@ -1518,6 +1600,7 @@ fn normalize_removes_orphan_custom_tool_call_output_panics_in_debug() {
call_id: "orphan-2".to_string(),
name: None,
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
}];
let mut h = create_history_with_items(items);
h.normalize_history(&default_input_modalities());
@@ -1531,6 +1614,7 @@ fn normalize_removes_orphan_client_tool_search_output() {
status: "completed".to_string(),
execution: "client".to_string(),
tools: Vec::new(),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1548,6 +1632,7 @@ fn normalize_removes_orphan_client_tool_search_output_panics_in_debug() {
status: "completed".to_string(),
execution: "client".to_string(),
tools: Vec::new(),
metadata: None,
}];
let mut h = create_history_with_items(items);
h.normalize_history(&default_input_modalities());
@@ -1560,6 +1645,7 @@ fn normalize_keeps_server_tool_search_output_without_matching_call() {
status: "completed".to_string(),
execution: "server".to_string(),
tools: Vec::new(),
metadata: None,
}];
let mut h = create_history_with_items(items);
@@ -1572,6 +1658,7 @@ fn normalize_keeps_server_tool_search_output_without_matching_call() {
status: "completed".to_string(),
execution: "server".to_string(),
tools: Vec::new(),
metadata: None,
}]
);
}
@@ -1587,10 +1674,12 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
namespace: None,
arguments: "{}".to_string(),
call_id: "c1".to_string(),
metadata: None,
},
ResponseItem::FunctionCallOutput {
call_id: "c2".to_string(),
output: FunctionCallOutputPayload::from_text("ok".to_string()),
metadata: None,
},
ResponseItem::CustomToolCall {
id: None,
@@ -1598,6 +1687,7 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
call_id: "t1".to_string(),
name: "tool".to_string(),
input: "{}".to_string(),
metadata: None,
},
ResponseItem::LocalShellCall {
id: None,
@@ -1610,6 +1700,7 @@ fn normalize_mixed_inserts_and_removals_panics_in_debug() {
env: None,
user: None,
}),
metadata: None,
},
];
let mut h = create_history_with_items(items);
@@ -1633,6 +1724,7 @@ fn image_data_url_payload_does_not_dominate_message_estimate() {
},
],
phase: None,
metadata: None,
};
let text_only_item = ResponseItem::Message {
id: None,
@@ -1641,6 +1733,7 @@ fn image_data_url_payload_does_not_dominate_message_estimate() {
text: "Here is the screenshot".to_string(),
}],
phase: None,
metadata: None,
};
let raw_len = serde_json::to_string(&image_item).unwrap().len() as i64;
@@ -1668,6 +1761,7 @@ fn image_data_url_payload_does_not_dominate_function_call_output_estimate() {
detail: Some(DEFAULT_IMAGE_DETAIL),
},
]),
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1694,6 +1788,7 @@ fn image_data_url_payload_does_not_dominate_custom_tool_call_output_estimate() {
detail: Some(DEFAULT_IMAGE_DETAIL),
},
]),
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1714,6 +1809,7 @@ fn non_base64_image_urls_are_unchanged() {
detail: Some(DEFAULT_IMAGE_DETAIL),
}],
phase: None,
metadata: None,
};
let function_output_item = ResponseItem::FunctionCallOutput {
call_id: "call-1".to_string(),
@@ -1723,6 +1819,7 @@ fn non_base64_image_urls_are_unchanged() {
detail: Some(DEFAULT_IMAGE_DETAIL),
},
]),
metadata: None,
};
assert_eq!(
@@ -1745,6 +1842,7 @@ fn encrypted_function_output_uses_plaintext_byte_estimate() {
encrypted_content: encrypted_content.clone(),
},
]),
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1765,6 +1863,7 @@ fn data_url_without_base64_marker_is_unchanged() {
detail: Some(DEFAULT_IMAGE_DETAIL),
}],
phase: None,
metadata: None,
};
assert_eq!(
@@ -1785,6 +1884,7 @@ fn non_image_base64_data_url_is_unchanged() {
detail: Some(DEFAULT_IMAGE_DETAIL),
},
]),
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1805,6 +1905,7 @@ fn mixed_case_data_url_markers_are_adjusted() {
detail: Some(DEFAULT_IMAGE_DETAIL),
}],
phase: None,
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1837,6 +1938,7 @@ fn multiple_inline_images_apply_multiple_fixed_costs() {
},
],
phase: None,
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1870,6 +1972,7 @@ fn original_detail_images_scale_with_dimensions() {
detail: Some(ImageDetail::Original),
},
]),
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1900,6 +2003,7 @@ fn original_detail_images_are_capped_at_max_patch_count() {
detail: Some(ImageDetail::Original),
},
]),
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1933,6 +2037,7 @@ fn original_detail_webp_images_scale_with_dimensions() {
detail: Some(ImageDetail::Original),
},
]),
metadata: None,
};
let raw_len = serde_json::to_string(&item).unwrap().len() as i64;
@@ -1951,6 +2056,7 @@ fn text_only_items_unchanged() {
text: "Hello world, this is a response.".to_string(),
}],
phase: None,
metadata: None,
};
let estimated = estimate_response_item_model_visible_bytes(&item);
@@ -49,6 +49,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
ResponseItem::FunctionCallOutput {
call_id: call_id.clone(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
));
}
@@ -64,6 +65,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
status: "completed".to_string(),
execution: "client".to_string(),
tools: Vec::new(),
metadata: None,
},
));
}
@@ -79,6 +81,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
call_id: call_id.clone(),
name: None,
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
));
}
@@ -95,6 +98,7 @@ pub(crate) fn ensure_call_outputs_present(items: &mut Vec<ResponseItem>) {
ResponseItem::FunctionCallOutput {
call_id: call_id.clone(),
output: FunctionCallOutputPayload::from_text("aborted".to_string()),
metadata: None,
},
));
}
@@ -203,6 +203,7 @@ fn build_text_message(role: &str, text_sections: Vec<String>) -> Option<Response
role: role.to_string(),
content,
phase: None,
metadata: None,
})
}