mirror of
https://github.com/openai/codex.git
synced 2026-04-28 16:45:54 +00:00
change collaboration mode to struct (#9793)
Shouldn't cause behavioral change
This commit is contained in:
@@ -163,31 +163,24 @@ pub enum ModeKind {
|
||||
|
||||
/// Collaboration mode for a Codex session.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize, JsonSchema, TS)]
|
||||
#[serde(tag = "mode", rename_all = "lowercase")]
|
||||
pub enum CollaborationMode {
|
||||
Plan(Settings),
|
||||
PairProgramming(Settings),
|
||||
Execute(Settings),
|
||||
Custom(Settings),
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub struct CollaborationMode {
|
||||
pub mode: ModeKind,
|
||||
pub settings: Settings,
|
||||
}
|
||||
|
||||
impl CollaborationMode {
|
||||
/// Returns a reference to the settings, regardless of variant.
|
||||
fn settings(&self) -> &Settings {
|
||||
match self {
|
||||
CollaborationMode::Plan(settings)
|
||||
| CollaborationMode::PairProgramming(settings)
|
||||
| CollaborationMode::Execute(settings)
|
||||
| CollaborationMode::Custom(settings) => settings,
|
||||
}
|
||||
/// Returns a reference to the settings.
|
||||
fn settings_ref(&self) -> &Settings {
|
||||
&self.settings
|
||||
}
|
||||
|
||||
pub fn model(&self) -> &str {
|
||||
self.settings().model.as_str()
|
||||
self.settings_ref().model.as_str()
|
||||
}
|
||||
|
||||
pub fn reasoning_effort(&self) -> Option<ReasoningEffort> {
|
||||
self.settings().reasoning_effort
|
||||
self.settings_ref().reasoning_effort
|
||||
}
|
||||
|
||||
/// Updates the collaboration mode with new model and/or effort values.
|
||||
@@ -196,14 +189,14 @@ impl CollaborationMode {
|
||||
/// - `effort`: `Some(Some(e))` to set effort to `e`, `Some(None)` to clear effort, `None` to keep current effort
|
||||
/// - `developer_instructions`: `Some(s)` to update developer instructions, `None` to keep current
|
||||
///
|
||||
/// Returns a new `CollaborationMode` with updated values, preserving the variant.
|
||||
/// Returns a new `CollaborationMode` with updated values, preserving the mode.
|
||||
pub fn with_updates(
|
||||
&self,
|
||||
model: Option<String>,
|
||||
effort: Option<Option<ReasoningEffort>>,
|
||||
developer_instructions: Option<String>,
|
||||
) -> Self {
|
||||
let settings = self.settings();
|
||||
let settings = self.settings_ref();
|
||||
let updated_settings = Settings {
|
||||
model: model.unwrap_or_else(|| settings.model.clone()),
|
||||
reasoning_effort: effort.unwrap_or(settings.reasoning_effort),
|
||||
@@ -211,13 +204,9 @@ impl CollaborationMode {
|
||||
.or_else(|| settings.developer_instructions.clone()),
|
||||
};
|
||||
|
||||
match self {
|
||||
CollaborationMode::Plan(_) => CollaborationMode::Plan(updated_settings),
|
||||
CollaborationMode::PairProgramming(_) => {
|
||||
CollaborationMode::PairProgramming(updated_settings)
|
||||
}
|
||||
CollaborationMode::Execute(_) => CollaborationMode::Execute(updated_settings),
|
||||
CollaborationMode::Custom(_) => CollaborationMode::Custom(updated_settings),
|
||||
CollaborationMode {
|
||||
mode: self.mode,
|
||||
settings: updated_settings,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,13 +263,8 @@ impl DeveloperInstructions {
|
||||
|
||||
/// Returns developer instructions from a collaboration mode if they exist and are non-empty.
|
||||
pub fn from_collaboration_mode(collaboration_mode: &CollaborationMode) -> Option<Self> {
|
||||
let settings = match collaboration_mode {
|
||||
CollaborationMode::Plan(settings)
|
||||
| CollaborationMode::PairProgramming(settings)
|
||||
| CollaborationMode::Execute(settings)
|
||||
| CollaborationMode::Custom(settings) => settings,
|
||||
};
|
||||
settings
|
||||
collaboration_mode
|
||||
.settings
|
||||
.developer_instructions
|
||||
.as_ref()
|
||||
.filter(|instructions| !instructions.is_empty())
|
||||
|
||||
Reference in New Issue
Block a user