mirror of
https://github.com/openai/codex.git
synced 2026-05-29 15:30:22 +00:00
## Why Extension tools that need conversation context should be able to read it from the live tool invocation instead of reaching into thread persistence themselves. ## What changed - Add a `ConversationHistory` snapshot to extension `ToolCall`s and populate it from the current raw in-memory response history. - Expose all history items at this boundary so each extension can filter and bound the subset it needs before consuming or forwarding it. - Cover the adapter and registry dispatch paths and update existing extension tests that construct `ToolCall` literals. ## Test plan - `cargo test -p codex-tools` - `cargo test -p codex-extension-api` - `cargo test -p codex-goal-extension` - `cargo test -p codex-memories-extension` - `cargo test -p codex-core passes_turn_fields_to_extension_call` - `cargo test -p codex-core extension_tool_executors_are_model_visible_and_dispatchable`
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use crate::FunctionCallError;
|
|
use crate::ToolName;
|
|
use crate::ToolPayload;
|
|
use codex_protocol::models::ResponseItem;
|
|
use codex_utils_output_truncation::TruncationPolicy;
|
|
use std::sync::Arc;
|
|
|
|
/// Raw response history snapshot available when an extension tool is invoked.
|
|
#[derive(Clone, Debug, Default)]
|
|
pub struct ConversationHistory {
|
|
items: Arc<[ResponseItem]>,
|
|
}
|
|
|
|
impl ConversationHistory {
|
|
pub fn new(items: Vec<ResponseItem>) -> Self {
|
|
Self {
|
|
items: items.into(),
|
|
}
|
|
}
|
|
|
|
pub fn items(&self) -> &[ResponseItem] {
|
|
&self.items
|
|
}
|
|
}
|
|
|
|
// TODO: this is temporary and will disappear in the next PR (as we make codex-extension-api generic on Invocation.
|
|
#[derive(Clone, Debug)]
|
|
pub struct ToolCall {
|
|
pub turn_id: String,
|
|
pub call_id: String,
|
|
pub tool_name: ToolName,
|
|
pub truncation_policy: TruncationPolicy,
|
|
pub conversation_history: ConversationHistory,
|
|
pub payload: ToolPayload,
|
|
}
|
|
|
|
impl ToolCall {
|
|
pub fn function_arguments(&self) -> Result<&str, FunctionCallError> {
|
|
match &self.payload {
|
|
ToolPayload::Function { arguments } => Ok(arguments),
|
|
_ => Err(FunctionCallError::Fatal(format!(
|
|
"tool {} invoked with incompatible payload",
|
|
self.tool_name
|
|
))),
|
|
}
|
|
}
|
|
}
|