Something went wrong. Try again.
Codex App without electron
Something went wrong. Try again.
5.7 kB · 154 lines
Rust
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155use codex_app_server_protocol::UserInput;use gpui::Context;
use super::ChatController;
impl ChatController { pub(crate) fn discard_pending_queue(&mut self, cx: &mut Context<Self>) { self.chat.update(cx, |chat, cx| { if let Some(message) = chat .pending_user_message() .filter(|message| message.queued && !chat.user_message_is_sending()) { let id = message.client_id.clone(); chat.finish_queued_user_message(&id); chat.remove_notice(&format!("send-error-{id}")); cx.notify(); } }); }
pub(crate) fn retry_pending_queue(&mut self, cx: &mut Context<Self>) { let pending = self .chat .read(cx) .pending_user_message() .filter(|message| message.queued && !self.chat.read(cx).user_message_is_sending()) .map(|message| (message.client_id.clone(), message.content.clone())); if let Some((id, input)) = pending { self.discard_pending_queue(cx); self.queue(id, input, cx); } }
pub(crate) fn refresh_queue(&mut self, cx: &mut Context<Self>) { if self.closed || self .chat .read(cx) .thread .as_ref() .is_none_or(|thread| thread.ephemeral) { return; } self.queue_refresh_revision += 1; let revision = self.queue_refresh_revision; let thread_id = self.chat.read(cx).id.clone(); let bridge = self.source.read(cx).client.connection(); let generation = bridge.request_generation(); cx.spawn(async move |this, cx| { let result = bridge.list_queued_messages(thread_id.clone()).await; let _ = this.update(cx, |controller, cx| { if bridge.generation() != generation || controller.queue_refresh_revision != revision { return; } let Some(chat) = controller.chat_for_response(&thread_id, cx) else { return; }; match result { Ok(entries) => chat.update(cx, |chat, cx| { chat.set_queued_submissions(entries); if chat .notices .iter() .any(|notice| notice.id == "queue-load-error") { chat.remove_notice("queue-load-error"); } cx.notify(); }), Err(error) => controller.append_notice( &thread_id, "queue-load-error".into(), error.to_string(), cx, ), } }); }) .detach(); }
pub(crate) fn update_queued_message( &mut self, id: String, input: Vec<UserInput>, cx: &mut Context<Self>, ) { if self.closed { return; } // Invalidate reads started before this mutation; refresh again on completion. self.queue_refresh_revision += 1; let thread_id = self.chat.read(cx).id.clone(); let bridge = self.source.read(cx).client.connection(); let generation = bridge.request_generation(); cx.spawn(async move |this, cx| { let result = bridge .update_queued_message(thread_id.clone(), id, input) .await; let _ = this.update(cx, |controller, cx| { if bridge.generation() != generation { return; } let Some(chat) = controller.chat_for_response(&thread_id, cx) else { return; }; match result { Ok(response) => chat.update(cx, |chat, cx| { chat.accept_queued_message(response.queued_submission); cx.notify(); }), Err(error) => controller.apply_bridge_error(error.to_string(), cx), } controller.refresh_queue(cx); }); }) .detach(); }
pub(crate) fn delete_queued_message(&mut self, id: String, cx: &mut Context<Self>) { if self.closed { return; } self.queue_refresh_revision += 1; let thread_id = self.chat.read(cx).id.clone(); let bridge = self.source.read(cx).client.connection(); let generation = bridge.request_generation(); cx.spawn(async move |this, cx| { let result = bridge .delete_queued_message(thread_id.clone(), id.clone()) .await; let _ = this.update(cx, |controller, cx| { if bridge.generation() != generation { return; } let Some(chat) = controller.chat_for_response(&thread_id, cx) else { return; }; match result { Ok(_) => chat.update(cx, |chat, cx| { chat.queued_submissions.retain(|entry| entry.id != id); cx.notify(); }), Err(error) => controller.apply_bridge_error(error.to_string(), cx), } controller.refresh_queue(cx); }); }) .detach(); }}