Skip to main content

Module phi

Module phi 

Source
Expand description

Author-facing SDK for a Phi PXB extension binary — a Rust port of ext/go/phi.

Build an Extension, register tools / slash commands / event handlers, then call Extension::run to speak PXB on stdin/stdout until shutdown:

use phi_ext::{phi, pxb};

fn main() -> Result<(), phi::Error> {
    let mut m = phi::Extension::new("hello", "0.1.0");
    m.register_command("hello", phi::Command::new("Say hi", |_args, ctx| {
        ctx.notify("info", "Hello!");
        Ok(())
    }));
    m.subscribe(pxb::Event::SessionStart, |_ev| {});
    m.run()
}

The run loop is single-threaded. Command handlers receive a Context whose methods (notify, confirm, submit, …) forward to the host over the same pipe — the borrow checker enforces at compile time what the Go SDK’s mutexes enforce at runtime.

Re-exports§

pub use crate::pxb::Error;

Structs§

BeforeAgentStartEvent
BeforeAgentStartResult
Command
A slash command. The handler receives the raw argument string and a Context for host interaction (notify / confirm / submit / …).
ConfirmReply
The user’s choice for a ConfirmRequest.
ConfirmRequest
Modal yes/no dialog shown by the host.
Context
Interaction surface handed to command handlers. All host traffic goes over the same PXB pipe the run loop owns — a handler may block the loop (e.g. confirm reads nested frames).
Extension
The author-facing registration surface for a PXB extension binary.
HostInfo
Host metadata filled by the hello handshake (and refreshed by SessionMeta pushes).
Schema
JSON Schema body for an LLM tool’s parameters (type / properties / required / …).
SessionBeforeSwitchEvent
SessionBeforeSwitchResult
Tool
An LLM-callable tool. schema is a typed JSON Schema for parameters (same role as Go’s Parameters / Codex’s schemars-generated input schema).
ToolCallEvent
ToolCallResult
ToolResult
Outcome of a Tool execution.
ToolResultEvent
ToolResultResult
TurnStoppingEvent
TurnStoppingResult
UserInputEvent
UserInputResult