mirror of
https://github.com/openai/codex.git
synced 2026-10-22 17:58:46 +00:00
codex: simplify pending input metadata
This commit is contained in:
@@ -4423,10 +4423,10 @@ impl Session {
|
||||
|
||||
let mut idle_pending_input = self.idle_pending_input.lock().await;
|
||||
for item in items {
|
||||
if let Some(timer_source) = item.generated_timer_source()
|
||||
if let Some(timer_source) = item.timer_source()
|
||||
&& idle_pending_input
|
||||
.iter()
|
||||
.any(|queued| queued.generated_timer_source() == Some(timer_source))
|
||||
.any(|queued| queued.timer_source() == Some(timer_source))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ use super::INITIAL_SUBMIT_ID;
|
||||
use super::Session;
|
||||
use crate::injected_message::InjectedMessage;
|
||||
use crate::injected_message::MessagePayload;
|
||||
use crate::pending_input::GeneratedMessageInput;
|
||||
use crate::pending_input::PendingInputItem;
|
||||
use crate::timers::ClaimedTimer;
|
||||
use crate::timers::CreateTimer;
|
||||
@@ -256,10 +255,7 @@ impl Session {
|
||||
self.emit_timer_updated_notification().await;
|
||||
}
|
||||
let message = timer_injected_message(&context);
|
||||
let input_item = PendingInputItem::GeneratedMessage(GeneratedMessageInput {
|
||||
item: message.prompt_input_item(),
|
||||
injected_event: message.event(),
|
||||
});
|
||||
let input_item = PendingInputItem::injected(message.prompt_input_item(), message.event());
|
||||
match context.delivery {
|
||||
TimerDelivery::SteerCurrentTurn => {
|
||||
if !self.inject_timer_into_active_turn(input_item.clone()).await {
|
||||
@@ -367,10 +363,8 @@ impl Session {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let input_item = PendingInputItem::GeneratedMessage(GeneratedMessageInput {
|
||||
item: message.prompt_input_item(),
|
||||
injected_event: message.event(),
|
||||
});
|
||||
let input_item =
|
||||
PendingInputItem::injected(message.prompt_input_item(), message.event());
|
||||
return Some(PendingMessageClaim::Claimed(Box::new(input_item), delivery));
|
||||
}
|
||||
Some(codex_state::ThreadMessageClaim::Invalid { id, reason }) => {
|
||||
|
||||
@@ -203,13 +203,8 @@ pub(crate) async fn inspect_pending_input(
|
||||
turn_context: &Arc<TurnContext>,
|
||||
pending_input_item: PendingInputItem,
|
||||
) -> PendingInputHookDisposition {
|
||||
let (response_item, injected_event) = match pending_input_item {
|
||||
PendingInputItem::Plain(item) => (ResponseItem::from(item), None),
|
||||
PendingInputItem::GeneratedMessage(generated) => (
|
||||
ResponseItem::from(generated.item),
|
||||
Some(generated.injected_event),
|
||||
),
|
||||
};
|
||||
let (input_item, injected_event) = pending_input_item.into_parts();
|
||||
let response_item = ResponseItem::from(input_item);
|
||||
if let Some(TurnItem::UserMessage(user_message)) = parse_turn_item(&response_item) {
|
||||
let user_prompt_submit_outcome =
|
||||
run_user_prompt_submit_hooks(sess, turn_context, user_message.message()).await;
|
||||
|
||||
@@ -9,40 +9,41 @@ use codex_protocol::models::ResponseInputItem;
|
||||
use codex_protocol::protocol::InjectedMessageEvent;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct GeneratedMessageInput {
|
||||
pub(crate) item: ResponseInputItem,
|
||||
pub(crate) injected_event: InjectedMessageEvent,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) enum PendingInputItem {
|
||||
Plain(ResponseInputItem),
|
||||
GeneratedMessage(GeneratedMessageInput),
|
||||
pub(crate) struct PendingInputItem {
|
||||
item: ResponseInputItem,
|
||||
injected_event: Option<InjectedMessageEvent>,
|
||||
}
|
||||
|
||||
impl PendingInputItem {
|
||||
pub(crate) fn generated_timer_source(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Plain(_) => None,
|
||||
Self::GeneratedMessage(generated) => generated
|
||||
.injected_event
|
||||
.source
|
||||
.starts_with("timer ")
|
||||
.then_some(generated.injected_event.source.as_str()),
|
||||
pub(crate) fn injected(item: ResponseInputItem, event: InjectedMessageEvent) -> Self {
|
||||
Self {
|
||||
item,
|
||||
injected_event: Some(event),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn timer_source(&self) -> Option<&str> {
|
||||
self.injected_event
|
||||
.as_ref()
|
||||
.filter(|event| event.source.starts_with("timer "))
|
||||
.map(|event| event.source.as_str())
|
||||
}
|
||||
|
||||
pub(crate) fn into_parts(self) -> (ResponseInputItem, Option<InjectedMessageEvent>) {
|
||||
(self.item, self.injected_event)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn into_model_input(self) -> ResponseInputItem {
|
||||
match self {
|
||||
Self::Plain(item) => item,
|
||||
Self::GeneratedMessage(generated) => generated.item,
|
||||
}
|
||||
self.item
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResponseInputItem> for PendingInputItem {
|
||||
fn from(item: ResponseInputItem) -> Self {
|
||||
Self::Plain(item)
|
||||
Self {
|
||||
item,
|
||||
injected_event: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user