Files
codex/codex-rs/tool-call-id/src/lib.rs
T
cassirer-openai 8a1a476659 Use a shared ToolCallId for dispatched tool invocations (#62888)
## Why

Dispatched invocations, model-visible Responses calls, and Code Mode's
per-cell runtime calls use IDs with different roles. A dedicated Rust type
makes the dispatch identity explicit in APIs that carry it.

## What changed

Add `codex-tool-call-id` and use its `ToolCallId` across core tool dispatch,
nested Code Mode calls, and rollout tracing. The type wraps a string and
continues to serialize as a string.

GitOrigin-RevId: 119de57a9af840c4de72895adc9acdd0ed15b4fd
2026-11-21 03:14:33 +00:00

54 lines
1.1 KiB
Rust

//! Identity of a tool invocation dispatched by Codex, including nested Code Mode calls.
//! The model-visible Responses ID and the JavaScript runtime's per-cell ID have separate roles.
use serde::Deserialize;
use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct ToolCallId(String);
impl ToolCallId {
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<String> for ToolCallId {
fn from(id: String) -> Self {
Self(id)
}
}
impl From<&str> for ToolCallId {
fn from(id: &str) -> Self {
Self(id.to_owned())
}
}
impl std::borrow::Borrow<str> for ToolCallId {
fn borrow(&self) -> &str {
self.as_str()
}
}
impl std::fmt::Display for ToolCallId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl std::ops::Deref for ToolCallId {
type Target = str;
fn deref(&self) -> &Self::Target {
self.as_str()
}
}
impl From<ToolCallId> for String {
fn from(id: ToolCallId) -> Self {
id.0
}
}