Skip to main content

codetether_agent/session/
prompt_api.rs

1//! Public prompt entry points that delegate into
2//! [`helper::prompt`](super::helper::prompt) and
3//! [`helper::prompt_events`](super::helper::prompt_events).
4
5use std::sync::Arc;
6
7use anyhow::Result;
8
9use super::events::{SessionEvent, SessionResult};
10use super::helper;
11use super::types::{ImageAttachment, Session};
12
13impl Session {
14    /// Execute a prompt and return the final text answer (non-streaming).
15    ///
16    /// This loads the provider registry from Vault on every call, which is
17    /// fine for one-shot CLI use but expensive for the TUI — the TUI uses
18    /// [`Session::prompt_with_events`] with a shared registry instead.
19    ///
20    /// # Errors
21    ///
22    /// Returns an error if no providers are configured, the model cannot
23    /// be resolved, or the agentic loop exhausts its retry budgets.
24    pub async fn prompt(&mut self, message: &str) -> Result<SessionResult> {
25        helper::prompt::run_prompt(self, message).await
26    }
27
28    /// Process a user message with real-time event streaming for UI
29    /// updates.
30    ///
31    /// Accepts a pre-loaded
32    /// [`ProviderRegistry`](crate::provider::ProviderRegistry) to avoid
33    /// re-fetching secrets from Vault on every message.
34    pub async fn prompt_with_events(
35        &mut self,
36        message: &str,
37        event_tx: tokio::sync::mpsc::Sender<SessionEvent>,
38        registry: Arc<crate::provider::ProviderRegistry>,
39    ) -> Result<SessionResult> {
40        helper::prompt_events::run_prompt_with_events(self, message, Vec::new(), event_tx, registry)
41            .await
42    }
43
44    /// Execute a prompt with optional image attachments and stream events.
45    ///
46    /// Images must be base64-encoded data URLs.
47    pub async fn prompt_with_events_and_images(
48        &mut self,
49        message: &str,
50        images: Vec<ImageAttachment>,
51        event_tx: tokio::sync::mpsc::Sender<SessionEvent>,
52        registry: Arc<crate::provider::ProviderRegistry>,
53    ) -> Result<SessionResult> {
54        helper::prompt_events::run_prompt_with_events(self, message, images, event_tx, registry)
55            .await
56    }
57}