Skip to content

Commit c6f688c

Browse files
committed
changes
1 parent aa0b4e2 commit c6f688c

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

codex-rs/app-server-protocol/src/protocol/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,9 @@ server_notification_definitions! {
508508
McpToolCallProgress => "item/mcpToolCall/progress" (v2::McpToolCallProgressNotification),
509509
AccountUpdated => "account/updated" (v2::AccountUpdatedNotification),
510510
AccountRateLimitsUpdated => "account/rateLimits/updated" (v2::AccountRateLimitsUpdatedNotification),
511-
ReasoningDelta => "item/reasoning/delta" (v2::ReasoningDeltaNotification),
511+
ReasoningSummaryTextDelta => "item/reasoning/summaryTextDelta" (v2::ReasoningSummaryTextDeltaNotification),
512512
ReasoningSummaryPartAdded => "item/reasoning/summaryPartAdded" (v2::ReasoningSummaryPartAddedNotification),
513+
ReasoningTextDelta => "item/reasoning/textDelta" (v2::ReasoningTextDeltaNotification),
513514

514515
#[serde(rename = "account/login/completed")]
515516
#[ts(rename = "account/login/completed")]

codex-rs/app-server-protocol/src/protocol/v2.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,9 @@ pub enum ThreadItem {
485485
},
486486
Reasoning {
487487
id: String,
488-
text: String,
488+
summary: Vec<String>,
489+
#[serde(default)]
490+
content: Vec<String>,
489491
},
490492
CommandExecution {
491493
id: String,
@@ -544,17 +546,11 @@ impl From<CoreTurnItem> for ThreadItem {
544546
.collect::<String>();
545547
ThreadItem::AgentMessage { id: agent.id, text }
546548
}
547-
CoreTurnItem::Reasoning(reasoning) => {
548-
let text = if !reasoning.summary_text.is_empty() {
549-
reasoning.summary_text.join("\n")
550-
} else {
551-
reasoning.raw_content.join("\n")
552-
};
553-
ThreadItem::Reasoning {
554-
id: reasoning.id,
555-
text,
556-
}
557-
}
549+
CoreTurnItem::Reasoning(reasoning) => ThreadItem::Reasoning {
550+
id: reasoning.id,
551+
summary: reasoning.summary_text,
552+
content: reasoning.raw_content,
553+
},
558554
CoreTurnItem::WebSearch(search) => ThreadItem::WebSearch {
559555
id: search.id,
560556
query: search.query,
@@ -691,16 +687,27 @@ pub struct AgentMessageDeltaNotification {
691687
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
692688
#[serde(rename_all = "camelCase")]
693689
#[ts(export_to = "v2/")]
694-
pub struct ReasoningDeltaNotification {
690+
pub struct ReasoningSummaryTextDeltaNotification {
695691
pub item_id: String,
696692
pub delta: String,
693+
pub summary_index: i64,
697694
}
698695

699696
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
700697
#[serde(rename_all = "camelCase")]
701698
#[ts(export_to = "v2/")]
702699
pub struct ReasoningSummaryPartAddedNotification {
703700
pub item_id: String,
701+
pub summary_index: i64,
702+
}
703+
704+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
705+
#[serde(rename_all = "camelCase")]
706+
#[ts(export_to = "v2/")]
707+
pub struct ReasoningTextDeltaNotification {
708+
pub item_id: String,
709+
pub delta: String,
710+
pub content_index: i64,
704711
}
705712

706713
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
@@ -851,7 +858,8 @@ mod tests {
851858
ThreadItem::from(reasoning_item),
852859
ThreadItem::Reasoning {
853860
id: "reasoning-1".to_string(),
854-
text: "line one\nline two".to_string(),
861+
summary: vec!["line one".to_string(), "line two".to_string()],
862+
content: vec![],
855863
}
856864
);
857865

codex-rs/core/src/client.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ struct SseEvent {
553553
response: Option<Value>,
554554
item: Option<Value>,
555555
delta: Option<String>,
556+
summary_index: Option<i64>,
557+
content_index: Option<i64>,
556558
}
557559

558560
#[derive(Debug, Deserialize)]
@@ -812,16 +814,22 @@ async fn process_sse<S>(
812814
}
813815
}
814816
"response.reasoning_summary_text.delta" => {
815-
if let Some(delta) = event.delta {
816-
let event = ResponseEvent::ReasoningSummaryDelta(delta);
817+
if let (Some(delta), Some(summary_index)) = (event.delta, event.summary_index) {
818+
let event = ResponseEvent::ReasoningSummaryDelta {
819+
delta,
820+
summary_index,
821+
};
817822
if tx_event.send(Ok(event)).await.is_err() {
818823
return;
819824
}
820825
}
821826
}
822827
"response.reasoning_text.delta" => {
823-
if let Some(delta) = event.delta {
824-
let event = ResponseEvent::ReasoningContentDelta(delta);
828+
if let (Some(delta), Some(content_index)) = (event.delta, event.content_index) {
829+
let event = ResponseEvent::ReasoningContentDelta {
830+
delta,
831+
content_index,
832+
};
825833
if tx_event.send(Ok(event)).await.is_err() {
826834
return;
827835
}
@@ -898,12 +906,14 @@ async fn process_sse<S>(
898906
}
899907
}
900908
"response.reasoning_summary_part.added" => {
901-
// Boundary between reasoning summary sections (e.g., titles).
902-
let event = ResponseEvent::ReasoningSummaryPartAdded;
903-
if tx_event.send(Ok(event)).await.is_err() {
904-
return;
909+
if let Some(summary_index) = event.summary_index {
910+
// Boundary between reasoning summary sections (e.g., titles).
911+
let event = ResponseEvent::ReasoningSummaryPartAdded { summary_index };
912+
if tx_event.send(Ok(event)).await.is_err() {
913+
return;
914+
}
905915
}
906-
}
916+
}
907917
"response.reasoning_summary_text.done" => {}
908918
_ => {}
909919
}

0 commit comments

Comments
 (0)