mobius-cli 0.9.10

The terminal client for a möbius gateway
Documentation
use super::*;

pub(super) fn rendered(block: FrontendBlock) -> RenderedBlock {
    RenderedBlock {
        capability: "test".into(),
        block,
    }
}

pub(super) fn recorded(
    event: EventMsg,
    blocks: Vec<RenderedBlock>,
    preview: Option<RenderedPreview>,
) -> RecordedEvent {
    RecordedEvent {
        sequence: 1,
        recorded_at_ms: 0,
        event: Event {
            submission_id: None,
            msg: event,
        },
        stream_metrics: Vec::new(),
        blocks,
        preview,
    }
}

pub(super) fn preview_record(
    id: &str,
    page_id: &str,
    update: FrontendPreviewUpdate,
    messages: &[&str],
    next: Option<Op>,
) -> RecordedEvent {
    recorded(
        EventMsg::ContextCompacted,
        Vec::new(),
        Some(RenderedPreview {
            id: id.into(),
            title: "agent".into(),
            subtitle: "complete · kimi/high · Full context".into(),
            page_id: page_id.into(),
            update,
            events: messages
                .iter()
                .map(|message| RenderedEvent {
                    recorded_at_ms: 0,
                    event: EventMsg::UserMessage(mobius::protocol::UserMessageEvent {
                        message: (*message).into(),
                        attachments: Vec::new(),
                        message_target: None,
                    }),
                    blocks: Vec::new(),
                })
                .collect(),
            next,
        }),
    )
}

pub(super) fn snapshot(state: &TuiState) -> &SnapshotPreview {
    let Some(PreviewState {
        content: PreviewContent::Snapshot(snapshot),
        ..
    }) = state.preview.as_ref()
    else {
        panic!("snapshot preview");
    };
    snapshot
}

pub(super) fn preview_messages(snapshot: &SnapshotPreview) -> Vec<&str> {
    snapshot
        .transcript
        .iter()
        .map(|entry| entry.text.as_str())
        .collect()
}

pub(super) fn preview_continuation(arguments: &str) -> Op {
    Op::CapabilityCommand {
        capability: "subagents".into(),
        command: "subagents".into(),
        arguments: arguments.into(),
        input: None,
        target: None,
    }
}

pub(super) fn catalog(workspace: &std::path::Path) -> UiCatalog {
    let steering = FrontendContribution {
        capability: "steering".into(),
        active_input: Some(FrontendActiveInput {
            operation: "steer".into(),
        }),
        ..FrontendContribution::default()
    };
    UiCatalog::build(
        &[steering],
        &[ModelChoice {
            route: "kimi".into(),
            group: "kimi".into(),
            model: "kimi-k3".into(),
            reasoning_effort: Some("high".into()),
            context_window: Some(1_048_576),
            supports_image_input: true,
        }],
        workspace,
    )
    .expect("UI catalog")
}

pub(super) fn default_catalog() -> UiCatalog {
    catalog(std::path::Path::new("/missing-mobius-test-workspace"))
}

pub(super) fn state() -> TuiState {
    TuiState::new(
        &default_catalog(),
        "/work/mobius".into(),
        ModelInfo {
            model: "kimi-k3".into(),
            reasoning_effort: Some("high".into()),
        },
        "kimi".into(),
        "MÖBIUS AGENT\nmodel: kimi-k3 · high".into(),
    )
}

pub(super) fn rendered_text(lines: &[ratatui::text::Line<'_>]) -> String {
    lines
        .iter()
        .map(|line| {
            line.spans
                .iter()
                .map(|span| span.content.as_ref())
                .collect::<String>()
        })
        .collect::<Vec<_>>()
        .join("\n")
}