Skip to main content

codetether_agent/tui/app/autochat/
notify.rs

1//! Send autochat UI completion and error events.
2
3use tokio::sync::mpsc;
4
5use super::events::AutochatUiEvent;
6
7/// Notify the UI that provider loading failed.
8pub fn send_registry_error(ui_tx: &mpsc::UnboundedSender<AutochatUiEvent>, err: anyhow::Error) {
9    let _ = ui_tx.send(AutochatUiEvent::SystemMessage(format!(
10        "Failed to load providers for /autochat: {err}"
11    )));
12    let _ = ui_tx.send(completed(
13        "Autochat aborted: provider registry unavailable.".to_string(),
14    ));
15}
16
17/// Notify the UI that no provider is configured.
18pub fn send_no_provider_error(ui_tx: &mpsc::UnboundedSender<AutochatUiEvent>) {
19    let _ = ui_tx.send(completed(
20        "Autochat aborted: no providers configured.".to_string(),
21    ));
22}
23
24/// Notify the UI about a successful completion with pre-built summary text.
25pub fn send_success_text(
26    ui_tx: &mpsc::UnboundedSender<AutochatUiEvent>,
27    resolved_model: String,
28    summary: String,
29) {
30    let _ = ui_tx.send(AutochatUiEvent::SystemMessage(format!(
31        "Autochat relay complete (final persona on {resolved_model})"
32    )));
33    let _ = ui_tx.send(completed(summary));
34}
35
36/// Notify the UI that completion failed.
37pub fn send_completion_error(ui_tx: &mpsc::UnboundedSender<AutochatUiEvent>, err: anyhow::Error) {
38    let _ = ui_tx.send(completed(format!("❌ Autochat execution failed: {err}")));
39}
40
41fn completed(summary: String) -> AutochatUiEvent {
42    AutochatUiEvent::Completed {
43        summary,
44        okr_id: None,
45        okr_run_id: None,
46        relay_id: None,
47    }
48}