add deferred image content reads

This commit is contained in:
Roy Han
2026-05-05 14:19:58 -07:00
committed by rhan-oai
parent 989bdbf217
commit b7be806121
16 changed files with 451 additions and 58 deletions
@@ -584,6 +584,13 @@ client_request_definitions! {
serialization: None,
response: v2::ThreadTurnsItemsListResponse,
},
#[experimental("thread/item/content/read")]
ThreadItemContentRead => "thread/item/content/read" {
params: v2::ThreadItemContentReadParams,
// Explicitly concurrent: this primarily reads append-only rollout storage.
serialization: None,
response: v2::ThreadItemContentReadResponse,
},
/// Append raw Responses API items to the thread history without starting a user turn.
ThreadInjectItems => "thread/inject_items" {
params: v2::ThreadInjectItemsParams,
@@ -1839,6 +1846,7 @@ mod tests {
cursor: None,
limit: None,
sort_direction: None,
large_content: None,
},
};
assert_eq!(thread_turns_list.serialization_scope(), None);
+66 -25
View File
@@ -3961,6 +3961,11 @@ pub struct ThreadResumeParams {
#[experimental("thread/resume.excludeTurns")]
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub exclude_turns: bool,
/// Controls whether large item payloads are embedded in returned turns or
/// replaced with deferred-content metadata.
#[experimental("thread/resume.largeContent")]
#[ts(optional = nullable)]
pub large_content: Option<LargeContentMode>,
/// If true, persist additional EventMsg variants to the rollout file.
/// However, `thread/read`, `thread/resume`, and `thread/fork` still only
/// return the limited form of thread history for scalability reasons.
@@ -4658,6 +4663,10 @@ pub struct ThreadTurnsListParams {
/// Optional turn pagination direction; defaults to descending.
#[ts(optional = nullable)]
pub sort_direction: Option<SortDirection>,
/// Controls whether large item payloads are embedded in returned turns or
/// replaced with deferred-content metadata.
#[ts(optional = nullable)]
pub large_content: Option<LargeContentMode>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
@@ -4675,6 +4684,15 @@ pub struct ThreadTurnsListResponse {
pub backwards_cursor: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema, TS, Default)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub enum LargeContentMode {
#[default]
Inline,
Deferred,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
@@ -4690,6 +4708,10 @@ pub struct ThreadTurnsItemsListParams {
/// Optional item pagination direction; defaults to ascending.
#[ts(optional = nullable)]
pub sort_direction: Option<SortDirection>,
/// Controls whether large item payloads are embedded in returned items or
/// replaced with deferred-content metadata.
#[ts(optional = nullable)]
pub large_content: Option<LargeContentMode>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
@@ -4707,6 +4729,25 @@ pub struct ThreadTurnsItemsListResponse {
pub backwards_cursor: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadItemContentReadParams {
pub thread_id: String,
pub turn_id: String,
pub item_id: String,
pub content_id: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadItemContentReadResponse {
pub mime_type: String,
pub data_base64: String,
pub byte_length: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
@@ -9041,6 +9082,31 @@ mod tests {
assert_eq!(decoded, response);
}
#[test]
fn image_generation_defaults_missing_content_for_legacy_payloads() {
let item: ThreadItem = serde_json::from_value(json!({
"type": "imageGeneration",
"id": "ig_123",
"status": "completed",
"revisedPrompt": null,
"result": "Zm9v",
"savedPath": null
}))
.expect("legacy image generation item should deserialize");
assert_eq!(
item,
ThreadItem::ImageGeneration {
id: "ig_123".to_string(),
status: "completed".to_string(),
revised_prompt: None,
content: ImageGenerationContent::default(),
result: "Zm9v".to_string(),
saved_path: None,
}
);
}
#[test]
fn fs_read_file_params_round_trip() {
let params = FsReadFileParams {
@@ -11970,29 +12036,4 @@ mod tests {
"unexpected error: {err}"
);
}
#[test]
fn image_generation_defaults_missing_content_for_legacy_payloads() {
let item: ThreadItem = serde_json::from_value(json!({
"type": "imageGeneration",
"id": "ig_123",
"status": "completed",
"revisedPrompt": null,
"result": "Zm9v",
"savedPath": null
}))
.expect("legacy image generation item should deserialize");
assert_eq!(
item,
ThreadItem::ImageGeneration {
id: "ig_123".to_string(),
status: "completed".to_string(),
revised_prompt: None,
content: ImageGenerationContent::default(),
result: "Zm9v".to_string(),
saved_path: None,
}
);
}
}