From f41a982b03720a9449f38c901e699f0fedc8267a Mon Sep 17 00:00:00 2001 From: jif-oai Date: Mon, 12 Jan 2026 09:11:58 +0000 Subject: [PATCH] fix merge --- codex-rs/core/src/codex.rs | 18 ------- codex-rs/core/src/context_manager/history.rs | 2 +- .../core/src/tools/handlers/view_image.rs | 47 ++++++++----------- 3 files changed, 21 insertions(+), 46 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 3998dcc950..64a88dc2e8 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -1540,24 +1540,6 @@ impl Session { } } - /// Returns the input if there was no task running to inject into - pub async fn inject_response_items( - &self, - input: Vec, - ) -> Result<(), Vec> { - let mut active = self.active_turn.lock().await; - match active.as_mut() { - Some(at) => { - let mut ts = at.turn_state.lock().await; - for item in input { - ts.push_pending_input(item); - } - Ok(()) - } - None => Err(input), - } - } - pub async fn get_pending_input(&self) -> Vec { let mut active = self.active_turn.lock().await; match active.as_mut() { diff --git a/codex-rs/core/src/context_manager/history.rs b/codex-rs/core/src/context_manager/history.rs index 42697597b4..64ec587d30 100644 --- a/codex-rs/core/src/context_manager/history.rs +++ b/codex-rs/core/src/context_manager/history.rs @@ -169,7 +169,7 @@ impl ContextManager { } } ResponseItem::FunctionCallOutput { output, .. } => { - if output.content_items.as_ref().map_or(false, |items| { + if output.content_items.as_ref().is_some_and(|items| { items.iter().any(|item| { matches!(item, FunctionCallOutputContentItem::InputImage { .. }) }) diff --git a/codex-rs/core/src/tools/handlers/view_image.rs b/codex-rs/core/src/tools/handlers/view_image.rs index 179cf64765..61954b9d2c 100644 --- a/codex-rs/core/src/tools/handlers/view_image.rs +++ b/codex-rs/core/src/tools/handlers/view_image.rs @@ -12,9 +12,6 @@ use crate::tools::handlers::parse_arguments; use crate::tools::registry::ToolHandler; use crate::tools::registry::ToolKind; use codex_protocol::models::ContentItem; -use codex_protocol::models::ResponseInputItem; -use codex_protocol::models::local_image_content_items_with_label_number; -use codex_protocol::models::ContentItem; use codex_protocol::models::FunctionCallOutputContentItem; use codex_protocol::models::ResponseInputItem; use codex_protocol::user_input::UserInput; @@ -69,24 +66,6 @@ impl ToolHandler for ViewImageHandler { } let event_path = abs_path.clone(); - /// here - // let content: Vec = - // local_image_content_items_with_label_number(&abs_path, None); - // let input = ResponseInputItem::Message { - // role: "user".to_string(), - // content, - // }; - // - // session - // .inject_response_items(vec![input]) - // .await - // .map_err(|_| { - // FunctionCallError::RespondToModel( - // "unable to attach image (no active task)".to_string(), - // ) - // })?; - - session .send_event( turn.as_ref(), @@ -102,17 +81,31 @@ impl ToolHandler for ViewImageHandler { }] .into(); let image_url = match response_input { - ResponseInputItem::Message { content, .. } => match content.into_iter().next() { - Some(ContentItem::InputImage { image_url }) => image_url, - Some(ContentItem::InputText { text }) => { - return Err(FunctionCallError::RespondToModel(text)); + ResponseInputItem::Message { content, .. } => { + let mut image_url = None; + let mut text_fallback = None; + for item in content { + match item { + ContentItem::InputImage { image_url: url } => { + image_url = Some(url); + break; + } + ContentItem::InputText { text } => { + text_fallback.get_or_insert(text); + } + _ => {} + } } - _ => { + if let Some(url) = image_url { + url + } else if let Some(text) = text_fallback { + return Err(FunctionCallError::RespondToModel(text)); + } else { return Err(FunctionCallError::RespondToModel( "unexpected image input payload".to_string(), )); } - }, + } _ => { return Err(FunctionCallError::RespondToModel( "unexpected image input payload".to_string(),