mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Expose collaboration_mode_kind in turn.started / turn notifications
This commit is contained in:
@@ -85,6 +85,7 @@ use codex_core::protocol::TurnDiffEvent;
|
||||
use codex_core::review_format::format_review_findings_block;
|
||||
use codex_core::review_prompts;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::plan_tool::UpdatePlanArgs;
|
||||
use codex_protocol::protocol::ReviewOutputEvent;
|
||||
use codex_protocol::request_user_input::RequestUserInputAnswer as CoreRequestUserInputAnswer;
|
||||
@@ -115,6 +116,11 @@ pub(crate) async fn apply_bespoke_event_handling(
|
||||
msg,
|
||||
} = event;
|
||||
match msg {
|
||||
EventMsg::TurnStarted(turn_started_event) => {
|
||||
let mut summaries = turn_summary_store.lock().await;
|
||||
let summary = summaries.entry(conversation_id).or_default();
|
||||
summary.collaboration_mode_kind = Some(turn_started_event.collaboration_mode_kind);
|
||||
}
|
||||
EventMsg::TurnComplete(_ev) => {
|
||||
handle_turn_complete(
|
||||
conversation_id,
|
||||
@@ -1132,6 +1138,7 @@ async fn emit_turn_completed_with_status(
|
||||
event_turn_id: String,
|
||||
status: TurnStatus,
|
||||
error: Option<TurnError>,
|
||||
collaboration_mode_kind: Option<ModeKind>,
|
||||
outgoing: &OutgoingMessageSender,
|
||||
) {
|
||||
let notification = TurnCompletedNotification {
|
||||
@@ -1141,6 +1148,7 @@ async fn emit_turn_completed_with_status(
|
||||
items: vec![],
|
||||
error,
|
||||
status,
|
||||
collaboration_mode_kind,
|
||||
},
|
||||
};
|
||||
outgoing
|
||||
@@ -1248,13 +1256,22 @@ async fn handle_turn_complete(
|
||||
turn_summary_store: &TurnSummaryStore,
|
||||
) {
|
||||
let turn_summary = find_and_remove_turn_summary(conversation_id, turn_summary_store).await;
|
||||
let collaboration_mode_kind = turn_summary.collaboration_mode_kind;
|
||||
|
||||
let (status, error) = match turn_summary.last_error {
|
||||
Some(error) => (TurnStatus::Failed, Some(error)),
|
||||
None => (TurnStatus::Completed, None),
|
||||
};
|
||||
|
||||
emit_turn_completed_with_status(conversation_id, event_turn_id, status, error, outgoing).await;
|
||||
emit_turn_completed_with_status(
|
||||
conversation_id,
|
||||
event_turn_id,
|
||||
status,
|
||||
error,
|
||||
collaboration_mode_kind,
|
||||
outgoing,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
async fn handle_turn_interrupted(
|
||||
@@ -1263,13 +1280,14 @@ async fn handle_turn_interrupted(
|
||||
outgoing: &OutgoingMessageSender,
|
||||
turn_summary_store: &TurnSummaryStore,
|
||||
) {
|
||||
find_and_remove_turn_summary(conversation_id, turn_summary_store).await;
|
||||
let turn_summary = find_and_remove_turn_summary(conversation_id, turn_summary_store).await;
|
||||
|
||||
emit_turn_completed_with_status(
|
||||
conversation_id,
|
||||
event_turn_id,
|
||||
TurnStatus::Interrupted,
|
||||
None,
|
||||
turn_summary.collaboration_mode_kind,
|
||||
outgoing,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -170,6 +170,7 @@ use codex_login::ShutdownHandle;
|
||||
use codex_login::run_login_server;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::config_types::ForcedLoginMethod;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::config_types::Personality;
|
||||
use codex_protocol::items::TurnItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
@@ -213,6 +214,7 @@ pub(crate) type PendingRollbacks = Arc<Mutex<HashMap<ThreadId, RequestId>>>;
|
||||
pub(crate) struct TurnSummary {
|
||||
pub(crate) file_change_started: HashSet<String>,
|
||||
pub(crate) last_error: Option<TurnError>,
|
||||
pub(crate) collaboration_mode_kind: Option<ModeKind>,
|
||||
}
|
||||
|
||||
pub(crate) type TurnSummaryStore = Arc<Mutex<HashMap<ThreadId, TurnSummary>>>;
|
||||
@@ -3641,13 +3643,14 @@ impl CodexMessageProcessor {
|
||||
}
|
||||
|
||||
async fn turn_start(&self, request_id: RequestId, params: TurnStartParams) {
|
||||
let (_, thread) = match self.load_thread(¶ms.thread_id).await {
|
||||
let (thread_id, thread) = match self.load_thread(¶ms.thread_id).await {
|
||||
Ok(v) => v,
|
||||
Err(error) => {
|
||||
self.outgoing.send_error(request_id, error).await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let thread_id_str = params.thread_id.clone();
|
||||
|
||||
// Map v2 input items to core input items.
|
||||
let mapped_items: Vec<CoreInputItem> = params
|
||||
@@ -3655,6 +3658,15 @@ impl CodexMessageProcessor {
|
||||
.into_iter()
|
||||
.map(V2UserInput::into_core)
|
||||
.collect();
|
||||
let collaboration_mode_kind = params.collaboration_mode.as_ref().map(|mode| mode.mode);
|
||||
let config_snapshot = thread.config_snapshot().await;
|
||||
let collaboration_mode_kind =
|
||||
collaboration_mode_kind.or(Some(config_snapshot.collaboration_mode_kind));
|
||||
{
|
||||
let mut summaries = self.turn_summary_store.lock().await;
|
||||
let summary = summaries.entry(thread_id).or_default();
|
||||
summary.collaboration_mode_kind = collaboration_mode_kind;
|
||||
}
|
||||
|
||||
let has_any_overrides = params.cwd.is_some()
|
||||
|| params.approval_policy.is_some()
|
||||
@@ -3696,6 +3708,7 @@ impl CodexMessageProcessor {
|
||||
items: vec![],
|
||||
error: None,
|
||||
status: TurnStatus::InProgress,
|
||||
collaboration_mode_kind,
|
||||
};
|
||||
|
||||
let response = TurnStartResponse { turn: turn.clone() };
|
||||
@@ -3703,7 +3716,7 @@ impl CodexMessageProcessor {
|
||||
|
||||
// Emit v2 turn/started notification.
|
||||
let notif = TurnStartedNotification {
|
||||
thread_id: params.thread_id,
|
||||
thread_id: thread_id_str,
|
||||
turn,
|
||||
};
|
||||
self.outgoing
|
||||
@@ -3740,6 +3753,7 @@ impl CodexMessageProcessor {
|
||||
items,
|
||||
error: None,
|
||||
status: TurnStatus::InProgress,
|
||||
collaboration_mode_kind: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user