fix(protocol): align model schema and turn context

This commit is contained in:
James Peter
2025-12-28 07:50:33 +10:00
parent bb6c2ad6e6
commit bc3d7bf894
6 changed files with 54 additions and 58 deletions
-8
View File
@@ -941,14 +941,6 @@ impl Default for StreamConfig {
}
}
#[derive(Deserialize, Debug, Clone, PartialEq, Eq, Default, Hash)]
#[serde(rename_all = "kebab-case")]
pub enum ReasoningSummaryFormat {
#[default]
None,
Experimental,
}
/// Theme configuration for the TUI
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct ThemeConfig {
+1 -12
View File
@@ -1,4 +1,4 @@
use crate::config_types::{ReasoningEffort, ReasoningSummaryFormat};
use crate::config_types::ReasoningEffort;
use crate::tool_apply_patch::ApplyPatchToolType;
/// The `instructions` field in the payload sent to a model should always start
@@ -49,9 +49,6 @@ pub struct ModelFamily {
/// The reasoning effort to use for this model family when none is explicitly chosen.
pub default_reasoning_effort: Option<ReasoningEffort>,
// Define if we need a special handling of reasoning summary
pub reasoning_summary_format: ReasoningSummaryFormat,
/// Whether this model supports parallel tool calls when using the
/// Responses API.
pub supports_parallel_tool_calls: bool,
@@ -84,7 +81,6 @@ macro_rules! model_family {
auto_compact_token_limit: None,
supports_reasoning_summaries: false,
default_reasoning_effort: None,
reasoning_summary_format: ReasoningSummaryFormat::None,
supports_parallel_tool_calls: false,
uses_local_shell_tool: false,
apply_patch_tool_type: None,
@@ -150,7 +146,6 @@ pub fn find_family_for_model(slug: &str) -> Option<ModelFamily> {
model_family!(
slug, slug,
supports_reasoning_summaries: true,
reasoning_summary_format: ReasoningSummaryFormat::Experimental,
base_instructions: GPT_5_CODEX_INSTRUCTIONS.to_string(),
apply_patch_tool_type: Some(ApplyPatchToolType::Freeform),
supports_parallel_tool_calls: true,
@@ -161,7 +156,6 @@ pub fn find_family_for_model(slug: &str) -> Option<ModelFamily> {
model_family!(
slug, slug,
supports_reasoning_summaries: true,
reasoning_summary_format: ReasoningSummaryFormat::Experimental,
base_instructions: GPT_5_2_CODEX_INSTRUCTIONS.to_string(),
apply_patch_tool_type: Some(ApplyPatchToolType::Freeform),
supports_parallel_tool_calls: true,
@@ -178,7 +172,6 @@ pub fn find_family_for_model(slug: &str) -> Option<ModelFamily> {
model_family!(
slug, slug,
supports_reasoning_summaries: true,
reasoning_summary_format: ReasoningSummaryFormat::Experimental,
base_instructions: GPT_5_1_CODEX_MAX_INSTRUCTIONS.to_string(),
apply_patch_tool_type: Some(ApplyPatchToolType::Freeform),
context_window: Some(CONTEXT_WINDOW_272K),
@@ -191,7 +184,6 @@ pub fn find_family_for_model(slug: &str) -> Option<ModelFamily> {
model_family!(
slug, slug,
supports_reasoning_summaries: true,
reasoning_summary_format: ReasoningSummaryFormat::Experimental,
base_instructions: GPT_5_CODEX_INSTRUCTIONS.to_string(),
apply_patch_tool_type: Some(ApplyPatchToolType::Freeform),
context_window: Some(CONTEXT_WINDOW_272K),
@@ -202,7 +194,6 @@ pub fn find_family_for_model(slug: &str) -> Option<ModelFamily> {
model_family!(
slug, slug,
supports_reasoning_summaries: true,
reasoning_summary_format: ReasoningSummaryFormat::Experimental,
base_instructions: GPT_5_2_CODEX_INSTRUCTIONS.to_string(),
apply_patch_tool_type: Some(ApplyPatchToolType::Freeform),
supports_parallel_tool_calls: true,
@@ -213,7 +204,6 @@ pub fn find_family_for_model(slug: &str) -> Option<ModelFamily> {
model_family!(
slug, slug,
supports_reasoning_summaries: true,
reasoning_summary_format: ReasoningSummaryFormat::Experimental,
base_instructions: GPT_5_2_CODEX_INSTRUCTIONS.to_string(),
apply_patch_tool_type: Some(ApplyPatchToolType::Freeform),
supports_parallel_tool_calls: true,
@@ -276,7 +266,6 @@ pub fn derive_default_model_family(model: &str) -> ModelFamily {
auto_compact_token_limit: None,
supports_reasoning_summaries: false,
default_reasoning_effort: None,
reasoning_summary_format: ReasoningSummaryFormat::None,
supports_parallel_tool_calls: false,
uses_local_shell_tool: false,
apply_patch_tool_type: None,
-15
View File
@@ -8,7 +8,6 @@ use code_protocol::openai_models::ApplyPatchToolType as ProtocolApplyPatchToolTy
use code_protocol::openai_models::ModelInfo;
use code_protocol::openai_models::ModelsResponse;
use code_protocol::openai_models::ReasoningEffort as ProtocolReasoningEffort;
use code_protocol::openai_models::ReasoningSummaryFormat as ProtocolReasoningSummaryFormat;
use reqwest::header;
use reqwest::Method;
use reqwest::Url;
@@ -330,9 +329,6 @@ pub fn apply_model_info_overrides(info: &ModelInfo, mut family: ModelFamily) ->
family.supports_reasoning_summaries = info.supports_reasoning_summaries;
family.supports_parallel_tool_calls = info.supports_parallel_tool_calls;
family.default_reasoning_effort = Some(map_reasoning_effort(info.default_reasoning_level));
family.reasoning_summary_format =
map_reasoning_summary_format(info.reasoning_summary_format.clone());
family
}
@@ -356,17 +352,6 @@ fn map_reasoning_effort(effort: ProtocolReasoningEffort) -> crate::config_types:
}
}
fn map_reasoning_summary_format(
format: ProtocolReasoningSummaryFormat,
) -> crate::config_types::ReasoningSummaryFormat {
match format {
ProtocolReasoningSummaryFormat::None => crate::config_types::ReasoningSummaryFormat::None,
ProtocolReasoningSummaryFormat::Experimental => {
crate::config_types::ReasoningSummaryFormat::Experimental
}
}
}
/// Convert the build's version triple into a whole semver string.
fn format_client_version_to_whole() -> String {
format_client_version_from_parts(
@@ -27,7 +27,6 @@ fn remote_model(slug: &str, display: &str, priority: i32) -> ModelInfo {
],
"shell_type": "shell_command",
"visibility": "list",
"minimal_client_version": [0, 1, 0],
"supported_in_api": true,
"priority": priority,
"upgrade": null,
@@ -39,7 +38,6 @@ fn remote_model(slug: &str, display: &str, priority: i32) -> ModelInfo {
"truncation_policy": {"mode": "bytes", "limit": 10_000},
"supports_parallel_tool_calls": false,
"context_window": null,
"reasoning_summary_format": "none",
"experimental_supported_tools": [],
}))
.expect("valid model")
@@ -250,7 +248,6 @@ async fn construct_model_family_applies_remote_overrides() {
"supported_reasoning_levels": [],
"shell_type": "shell_command",
"visibility": "list",
"minimal_client_version": [0, 1, 0],
"supported_in_api": true,
"priority": 0,
"upgrade": null,
@@ -262,7 +259,6 @@ async fn construct_model_family_applies_remote_overrides() {
"truncation_policy": {"mode": "bytes", "limit": 10_000},
"supports_parallel_tool_calls": false,
"context_window": 12345,
"reasoning_summary_format": "experimental",
"experimental_supported_tools": [],
}))
.expect("model info");
@@ -300,9 +296,4 @@ async fn construct_model_family_applies_remote_overrides() {
family.default_reasoning_effort,
Some(code_core::config_types::ReasoningEffort::High)
);
assert_eq!(
family.reasoning_summary_format,
code_core::config_types::ReasoningSummaryFormat::Experimental
);
}
-14
View File
@@ -125,14 +125,6 @@ pub enum ApplyPatchToolType {
Function,
}
#[derive(Deserialize, Debug, Clone, PartialEq, Eq, Default, Hash, TS, JsonSchema, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ReasoningSummaryFormat {
#[default]
None,
Experimental,
}
/// Server-provided truncation policy metadata for a model.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
#[serde(rename_all = "snake_case")]
@@ -163,10 +155,6 @@ impl TruncationPolicyConfig {
}
}
/// Semantic version triple encoded as an array in JSON (e.g. [0, 62, 0]).
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, TS, JsonSchema)]
pub struct ClientVersion(pub i32, pub i32, pub i32);
/// Model metadata returned by the Codex backend `/models` endpoint.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct ModelInfo {
@@ -177,7 +165,6 @@ pub struct ModelInfo {
pub supported_reasoning_levels: Vec<ReasoningEffortPreset>,
pub shell_type: ConfigShellToolType,
pub visibility: ModelVisibility,
pub minimal_client_version: ClientVersion,
pub supported_in_api: bool,
pub priority: i32,
pub upgrade: Option<String>,
@@ -189,7 +176,6 @@ pub struct ModelInfo {
pub truncation_policy: TruncationPolicyConfig,
pub supports_parallel_tool_calls: bool,
pub context_window: Option<i64>,
pub reasoning_summary_format: ReasoningSummaryFormat,
pub experimental_supported_tools: Vec<String>,
}
+53
View File
@@ -615,6 +615,35 @@ pub enum EventMsg {
ExitedReviewMode(ExitedReviewModeEvent),
}
/// Codex errors that we expose to clients.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, TS)]
#[serde(rename_all = "snake_case")]
#[ts(rename_all = "snake_case")]
pub enum CodexErrorInfo {
ContextWindowExceeded,
UsageLimitExceeded,
HttpConnectionFailed {
http_status_code: Option<u16>,
},
/// Failed to connect to the response SSE stream.
ResponseStreamConnectionFailed {
http_status_code: Option<u16>,
},
InternalServerError,
Unauthorized,
BadRequest,
SandboxError,
/// The response SSE stream disconnected in the middle of a turnbefore completion.
ResponseStreamDisconnected {
http_status_code: Option<u16>,
},
/// Reached the retry limit for responses.
ResponseTooManyFailedAttempts {
http_status_code: Option<u16>,
},
Other,
}
#[derive(Debug, Clone, Deserialize, Serialize, TS)]
pub struct ExitedReviewModeEvent {
pub review_output: Option<ReviewOutputEvent>,
@@ -1126,6 +1155,23 @@ pub struct TurnContextItem {
#[serde(skip_serializing_if = "Option::is_none")]
pub effort: Option<ReasoningEffortConfig>,
pub summary: ReasoningSummaryConfig,
#[serde(skip_serializing_if = "Option::is_none")]
pub base_instructions: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub user_instructions: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub developer_instructions: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub final_output_json_schema: Option<Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub truncation_policy: Option<TruncationPolicy>,
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, TS)]
#[serde(tag = "mode", content = "limit", rename_all = "snake_case")]
pub enum TruncationPolicy {
Bytes(usize),
Tokens(usize),
}
#[derive(Serialize, Deserialize, Clone)]
@@ -1314,6 +1360,13 @@ pub struct BackgroundEventEvent {
#[derive(Debug, Clone, Deserialize, Serialize, TS)]
pub struct StreamErrorEvent {
pub message: String,
#[serde(default)]
pub codex_error_info: Option<CodexErrorInfo>,
/// Optional details about the underlying stream failure (often the same
/// human-readable message that is surfaced as the terminal error if retries
/// are exhausted).
#[serde(default)]
pub additional_details: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize, TS)]