deweygui 1.0.0

An agentic-first GUI framework with pluggable rendering backends and complete ontology for AI agent discoverability
//! Agent Demo — demonstrates the agent protocol integration.
//!
//! Run with: `cargo run --example agent_demo`
//! Then pipe JSON Lines commands to stdin:
//!
//! ```json
//! {"id":1,"request":"QueryOntology"}
//! {"id":2,"request":{"GetWidgetState":{"agent_id":"counter_label"}}}
//! {"id":3,"request":{"PerformAction":{"agent_id":"increment_btn","action":"click","params":{}}}}
//! ```

use dewey::prelude::*;

struct App {
    count: i32,
}

#[derive(Debug)]
enum Msg {
    Increment,
}

impl Model for App {
    type Msg = Msg;

    fn update(&mut self, msg: Msg) -> Command<Msg> {
        match msg {
            Msg::Increment => self.count += 1,
        }
        Command::None
    }

    fn view(&self, frame: &mut Frame<'_>) {
        let area = frame.area;

        let chunks = Layout::new(
            Direction::Vertical,
            [Constraint::Length(40.0), Constraint::Length(40.0)],
        )
        .split(area);

        Label::new(format!("Count: {}", self.count))
            .agent_id("counter_label")
            .render(chunks[0], frame);

        Button::new("Increment")
            .agent_id("increment_btn")
            .render(chunks[1], frame);
    }

    fn handle_event(&self, event: Event) -> Option<Msg> {
        if let Event::Key(KeyEvent {
            code: KeyCode::Char('+'),
            ..
        }) = event
        {
            Some(Msg::Increment)
        } else {
            None
        }
    }

    fn title(&self) -> &str {
        "Dewey — Agent Demo"
    }
}

fn main() -> std::result::Result<(), eframe::Error> {
    env_logger::init();
    log::info!("Starting Dewey Agent Demo");
    log::info!("Pipe JSON Lines to stdin for agent control");

    Program::new(App { count: 0 })
        .with_options(ProgramOptions {
            width: 400.0,
            height: 200.0,
            ..Default::default()
        })
        .run()
}