Skip to main content

full/
full.rs

1//! Richer example: a tool, a confirm dialog, and a queued follow-up.
2
3use phi_ext::phi;
4
5fn main() -> Result<(), phi::Error> {
6    let mut m = phi::Extension::new("full", "0.1.0");
7
8    m.register_tool(phi::Tool::new(
9        "echo",
10        "Echo the input back",
11        phi::Schema::object()
12            .property("text", phi::Schema::string())
13            .required(["text"]),
14        |args| {
15            let text = String::from_utf8_lossy(args);
16            Ok(phi::ToolResult {
17                content: format!("echo: {text}"),
18                ..Default::default()
19            })
20        },
21    ));
22
23    m.register_command(
24        "ask",
25        phi::Command::new("Ask a yes/no question", |_args, ctx| {
26            let reply = ctx.confirm("Confirm?", "Proceed with /tmp/x?");
27            if reply.ok {
28                ctx.notify("info", "Confirmed!");
29            } else {
30                ctx.notify("warning", "Declined.");
31            }
32            ctx.submit("follow-up from ask");
33            Ok(())
34        }),
35    );
36
37    m.run()
38}