mirror of
https://github.com/openai/codex.git
synced 2026-04-28 02:11:08 +03:00
turn type enums
This commit is contained in:
@@ -31,6 +31,7 @@ use crate::client_common::Prompt;
|
||||
use crate::client_common::ResponseEvent;
|
||||
use crate::client_common::ResponseStream;
|
||||
use crate::client_common::ResponsesApiRequest;
|
||||
use crate::client_common::TurnType;
|
||||
use crate::client_common::create_reasoning_param_for_request;
|
||||
use crate::client_common::create_text_param_for_request;
|
||||
use crate::config::Config;
|
||||
@@ -244,12 +245,7 @@ impl ModelClient {
|
||||
let max_attempts = self.provider.request_max_retries();
|
||||
for attempt in 0..=max_attempts {
|
||||
match self
|
||||
.attempt_stream_responses(
|
||||
attempt,
|
||||
&payload_json,
|
||||
&auth_manager,
|
||||
prompt.is_review_turn,
|
||||
)
|
||||
.attempt_stream_responses(attempt, &payload_json, &auth_manager, prompt.turn_type)
|
||||
.await
|
||||
{
|
||||
Ok(stream) => {
|
||||
@@ -277,7 +273,7 @@ impl ModelClient {
|
||||
attempt: u64,
|
||||
payload_json: &Value,
|
||||
auth_manager: &Option<Arc<AuthManager>>,
|
||||
is_review_turn: bool,
|
||||
turn_type: TurnType,
|
||||
) -> std::result::Result<ResponseStream, StreamAttemptError> {
|
||||
// Always fetch the latest auth in case a prior attempt refreshed the token.
|
||||
let auth = auth_manager.as_ref().and_then(|m| m.auth());
|
||||
@@ -301,7 +297,10 @@ impl ModelClient {
|
||||
.header("session_id", self.conversation_id.to_string())
|
||||
.header(
|
||||
"action_kind",
|
||||
if is_review_turn { "review" } else { "turn" },
|
||||
match turn_type {
|
||||
TurnType::Review => "review",
|
||||
TurnType::Regular => "turn",
|
||||
},
|
||||
)
|
||||
.header(reqwest::header::ACCEPT, "text/event-stream")
|
||||
.json(payload_json);
|
||||
|
||||
@@ -23,6 +23,13 @@ use tokio::sync::mpsc;
|
||||
/// Review thread system prompt. Edit `core/src/review_prompt.md` to customize.
|
||||
pub const REVIEW_PROMPT: &str = include_str!("../review_prompt.md");
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum TurnType {
|
||||
#[default]
|
||||
Regular,
|
||||
Review,
|
||||
}
|
||||
|
||||
/// API request payload for a single model turn
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct Prompt {
|
||||
@@ -42,8 +49,8 @@ pub struct Prompt {
|
||||
/// Optional the output schema for the model's response.
|
||||
pub output_schema: Option<Value>,
|
||||
|
||||
/// Marks whether this prompt is part of a review turn.
|
||||
pub is_review_turn: bool,
|
||||
/// The type of turn being executed
|
||||
pub turn_type: TurnType,
|
||||
}
|
||||
|
||||
impl Prompt {
|
||||
|
||||
@@ -42,6 +42,7 @@ use crate::apply_patch::convert_apply_patch_to_protocol;
|
||||
use crate::client::ModelClient;
|
||||
use crate::client_common::Prompt;
|
||||
use crate::client_common::ResponseEvent;
|
||||
use crate::client_common::TurnType;
|
||||
use crate::config::Config;
|
||||
use crate::config_types::ShellEnvironmentPolicy;
|
||||
use crate::conversation_history::ConversationHistory;
|
||||
@@ -1933,6 +1934,14 @@ async fn run_turn(
|
||||
sub_id: String,
|
||||
input: Vec<ResponseItem>,
|
||||
) -> CodexResult<TurnRunResult> {
|
||||
/// Resolve the effective `TurnType` to use for a given turn context.
|
||||
fn resolve_turn_type(turn_context: &TurnContext) -> TurnType {
|
||||
if turn_context.is_review_mode {
|
||||
TurnType::Review
|
||||
} else {
|
||||
TurnType::Regular
|
||||
}
|
||||
}
|
||||
let mcp_tools = sess.services.mcp_connection_manager.list_all_tools();
|
||||
let router = Arc::new(ToolRouter::from_config(
|
||||
&turn_context.tools_config,
|
||||
@@ -1950,7 +1959,7 @@ async fn run_turn(
|
||||
parallel_tool_calls,
|
||||
base_instructions_override: turn_context.base_instructions.clone(),
|
||||
output_schema: turn_context.final_output_json_schema.clone(),
|
||||
is_review_turn: turn_context.is_review_mode,
|
||||
turn_type: resolve_turn_type(&turn_context),
|
||||
};
|
||||
|
||||
let mut retries = 0;
|
||||
|
||||
Reference in New Issue
Block a user