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(
9        phi::Tool::new(
10            "echo",
11            "Echo the input back",
12            phi::Schema::object()
13                .property("text", phi::Schema::string())
14                .required(["text"]),
15            |args| {
16                let text = String::from_utf8_lossy(args);
17                Ok(phi::ToolResult {
18                    content: format!("echo: {text}"),
19                    ..Default::default()
20                })
21            },
22        )
23        .detail_from_args(|args| String::from_utf8_lossy(args).into_owned()),
24    );
25
26    m.register_command(
27        "ask",
28        phi::Command::new("Ask a yes/no question", |_args, ctx| {
29            let reply = ctx.confirm("Confirm?", "Proceed with /tmp/x?");
30            if reply.ok {
31                ctx.notify("info", "Confirmed!");
32            } else {
33                ctx.notify("warning", "Declined.");
34            }
35            ctx.submit("follow-up from ask");
36            Ok(())
37        }),
38    );
39
40    m.run()
41}