Skip to main content

horus_cli/frontend/
mod.rs

1//! Horus terminal frontend.
2
3use horus::Result;
4use horus::protocol::FrontendBlock;
5use horus_gateway::client::{GatewayEvents, GatewaySender};
6use horus_gateway::wire::{ReadyPayload, SessionReadyPayload};
7
8mod catalog;
9mod cloudflare_setup;
10mod dashboard;
11mod gateway;
12mod gateway_actions;
13mod headless;
14mod reinitialize;
15mod setup;
16mod terminal;
17mod theme;
18mod tui;
19
20pub use headless::run as run_headless;
21pub use tui::terminal_text;
22
23pub use cloudflare_setup::{CloudflareInit, run as run_cloudflare_setup};
24pub use dashboard::{run as run_gateway_dashboard, run_provider as run_gateway_provider};
25pub use reinitialize::confirm as confirm_gateway_reinitialize;
26
27fn block_text(block: &FrontendBlock) -> String {
28    let mut text = block.text.clone();
29    for file in &block.files {
30        if !text.is_empty() {
31            text.push('\n');
32        }
33        text.push_str(&format!(
34            "[file] {} · {} · {} bytes",
35            file.name, file.media_type, file.size
36        ));
37    }
38    text
39}
40
41pub async fn run(
42    sender: GatewaySender,
43    events: GatewayEvents,
44    gateway: &mut ReadyPayload,
45    session: &mut SessionReadyPayload,
46    local_gateway: bool,
47    gateway_endpoint: String,
48) -> Result<(FrontendExit, GatewaySender, GatewayEvents)> {
49    let workspace = session.workspace.path.clone();
50    let catalog = catalog::UiCatalog::build(&session.contributions, &gateway.models, &workspace)?;
51    tui::runtime::run(
52        sender,
53        events,
54        gateway,
55        session,
56        catalog,
57        local_gateway,
58        gateway_endpoint,
59    )
60    .await
61}
62
63/// Why a frontend returned control to its launcher.
64pub enum FrontendExit {
65    Exit,
66    Discard,
67    New,
68    Resume(String),
69    Reload,
70    Reconnect,
71}