Share additional tool declarations across response item clones (#54945)

## Why

Cloning `ResponseItem::AdditionalTools` deep-copies its tool declarations for history and request copies.

## What changed

Store `tools` in an `Arc<[serde_json::Value]>` so clones share immutable declarations. Update constructors and existing test fixtures to use the shared representation.

GitOrigin-RevId: eb8831774afb45fe8431a796f34ae9d1243e884a
This commit is contained in:
Charlie Marsh
2026-10-17 23:17:51 +00:00
committed by copyberry
parent 8d9f6466ff
commit 1cc7dc8f2a
11 changed files with 23 additions and 19 deletions
+4 -2
View File
@@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::io;
use std::num::NonZeroUsize;
use std::path::Path;
use std::sync::Arc;
use codex_utils_image::PromptImageMode;
use codex_utils_image::data_url_from_bytes;
@@ -1055,7 +1056,8 @@ pub enum ResponseItem {
id: Option<ResponseItemId>,
role: String,
#[ts(type = "unknown[]")]
tools: Vec<serde_json::Value>,
// Share immutable declarations across history and request copies.
tools: Arc<[serde_json::Value]>,
},
Message {
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -2807,7 +2809,7 @@ mod tests {
let mut additional_tools = ResponseItem::AdditionalTools {
id: None,
role: "developer".to_string(),
tools: Vec::new(),
tools: Arc::from([]),
};
additional_tools.set_id(Some(ResponseItemId::with_suffix("at", "test")));
assert_eq!(