Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions codex-rs/app-server-protocol/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ pub struct SendUserTurnParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub effort: Option<ReasoningEffort>,
pub summary: ReasoningSummary,
#[serde(skip_serializing_if = "Option::is_none")]
pub final_output_json_schema: Option<serde_json::Value>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, TS)]
Expand Down Expand Up @@ -929,4 +931,66 @@ mod tests {
assert_eq!(payload.request_with_id(RequestId::Integer(7)), request);
Ok(())
}

#[test]
fn serialize_send_user_turn_includes_schema_when_present() -> Result<()> {
let conversation_id = ConversationId::from_string("67e55044-10b1-426f-9247-bb680e5fe0c8")?;
let schema = json!({"type": "object"});
let request = ClientRequest::SendUserTurn {
request_id: RequestId::Integer(9),
params: SendUserTurnParams {
conversation_id,
items: vec![InputItem::Text {
text: "hello".to_string(),
}],
cwd: PathBuf::from("/tmp"),
approval_policy: AskForApproval::Never,
sandbox_policy: SandboxPolicy::DangerFullAccess,
model: "gpt-5-codex".to_string(),
effort: Some(ReasoningEffort::Medium),
summary: ReasoningSummary::Auto,
final_output_json_schema: Some(schema.clone()),
},
};

let value = serde_json::to_value(&request)?;
let params = value
.get("params")
.and_then(|params| params.as_object())
.expect("params should be an object");
assert_eq!(params.get("finalOutputJsonSchema"), Some(&schema));
Ok(())
}

#[test]
fn serialize_send_user_turn_omits_schema_when_absent() -> Result<()> {
let conversation_id = ConversationId::from_string("67e55044-10b1-426f-9247-bb680e5fe0c8")?;
let request = ClientRequest::SendUserTurn {
request_id: RequestId::Integer(10),
params: SendUserTurnParams {
conversation_id,
items: vec![InputItem::Text {
text: "hello".to_string(),
}],
cwd: PathBuf::from("/tmp"),
approval_policy: AskForApproval::Never,
sandbox_policy: SandboxPolicy::DangerFullAccess,
model: "gpt-5-codex".to_string(),
effort: Some(ReasoningEffort::Medium),
summary: ReasoningSummary::Auto,
final_output_json_schema: None,
},
};

let value = serde_json::to_value(&request)?;
let params = value
.get("params")
.and_then(|params| params.as_object())
.expect("params should be an object");
assert!(
!params.contains_key("finalOutputJsonSchema"),
"finalOutputJsonSchema should be omitted when not provided",
);
Ok(())
}
}
3 changes: 2 additions & 1 deletion codex-rs/app-server/src/codex_message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ impl CodexMessageProcessor {
model,
effort,
summary,
final_output_json_schema,
} = params;

let Ok(conversation) = self
Expand Down Expand Up @@ -1049,7 +1050,7 @@ impl CodexMessageProcessor {
model,
effort,
summary,
final_output_json_schema: None,
final_output_json_schema,
})
.await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ async fn test_send_user_turn_changes_approval_policy_behavior() {
model: "mock-model".to_string(),
effort: Some(ReasoningEffort::Medium),
summary: ReasoningSummary::Auto,
final_output_json_schema: None,
})
.await
.expect("send sendUserTurn");
Expand Down Expand Up @@ -483,6 +484,7 @@ async fn test_send_user_turn_updates_sandbox_and_cwd_between_turns() {
model: model.clone(),
effort: Some(ReasoningEffort::Medium),
summary: ReasoningSummary::Auto,
final_output_json_schema: None,
})
.await
.expect("send first sendUserTurn");
Expand Down Expand Up @@ -513,6 +515,7 @@ async fn test_send_user_turn_updates_sandbox_and_cwd_between_turns() {
model: model.clone(),
effort: Some(ReasoningEffort::Medium),
summary: ReasoningSummary::Auto,
final_output_json_schema: None,
})
.await
.expect("send second sendUserTurn");
Expand Down