Skip to main content

LlamaExtension

Struct LlamaExtension 

Source
pub struct LlamaExtension;
Expand description

pi’s built-in llama.cpp extension.

Trait Implementations§

Source§

impl Debug for LlamaExtension

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LlamaExtension

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Extension for LlamaExtension

Source§

fn source(&self) -> SourceInfo

Where the extension comes from, as get_commands reports it.
Source§

fn commands(&self) -> Vec<Command>

The commands it handles.
Source§

fn run_command<'a>( &'a self, command: &'a str, _args: &'a str, ctx: &'a Context, ) -> BoxFuture<'a, ()>

Runs command with its argument text.
Source§

fn grants(&self) -> Grants

What the extension may reach. The session applies its event handlers’ results only within these.
Source§

fn warn(&self, _message: &str)

Reports message, a warning from the host about the extension, such as a handler result the session dropped for lack of a grant, with the extension’s own output. Built-in extensions, which have every grant, report nothing.
Source§

fn load(&self, _tools: &Tools)

Registers the tools it offers from the start, before the session’s active tools are chosen.
Source§

fn complete(&self, _command: &str, _prefix: &str) -> ArgumentCompletions

Completions for the argument of command. While they are ArgumentCompletions::Pending, the UI’s refresh_completions follows once they are ready.
Source§

fn shortcuts(&self) -> Vec<Shortcut>

The keys it binds.
Source§

fn run_shortcut<'a>( &'a self, _key: &'a str, _ctx: &'a Context, ) -> BoxFuture<'a, Result<(), String>>

Runs the handler of shortcut key and returns the handler’s error.
Source§

fn settle(&self) -> BoxFuture<'_, u64>

Resolves once the extension code that is running has finished and delivered its results. pi runs extension code to completion before it reads the next input. Returns a count that grows with every call into the extension’s code.
Source§

fn session_start<'a>(&'a self, _ctx: &'a Context) -> BoxFuture<'a, ()>

The session started or was bound to a mode.
Source§

fn session_shutdown<'a>(&'a self, _ctx: &'a Context) -> BoxFuture<'a, ()>

The session ends or is being replaced.
Source§

fn end_session<'a>(&'a self, _session_id: &'a str) -> BoxFuture<'a, ()>

Session session_id ended or another replaced it, after its session_shutdown, but not on reload. pi disposes the session’s resources then, with pi-ai’s cleanupSessionResources.
Source§

fn before_agent_start<'a>( &'a self, _ctx: &'a Context, _sections: &'a mut IndexMap<String, String>, ) -> BoxFuture<'a, ()>

A prompt is about to run. sections are extra system prompt sections by tag name, which the extension may change.
Source§

fn handles(&self, _kind: &str) -> bool

Whether it handles pi events of type kind through Extension::handle.
Source§

fn handle<'a>( &'a self, _ctx: &'a Context, _event: &'a Value, ) -> BoxFuture<'a, Option<Value>>

Runs its handlers for pi event event, a JSON object with a type, and returns their combined result as pi’s runner combines one extension’s handlers. The session combines results across extensions.
Source§

fn prepare_loadout(&self, _loadout: &Loadout) -> LoadoutChanges

pi’s prepareLoadout hook of a tool it registered: how the next request presents the declared tools. Runs before every request.
Source§

fn refresh_loadout<'a>(&'a self, _loadout: &'a Loadout) -> BoxFuture<'a, ()>

Runs before a request’s Extension::prepare_loadout for loadout, for hooks that run elsewhere and answer later, so that prepare_loadout can give what they made of it.
Source§

fn renderers(&self) -> Renderers

What it draws in the transcript.
Source§

fn component<'a>( &'a self, _request: &'a Value, ) -> BoxFuture<'a, Option<RemoteComponent>>

Builds the component for a transcript item it draws. request is {"kind": "toolCall" | "toolResult", "name", "toolCallId", "args", "result", "options", "context"}, {"kind": "message", "key", "message", "options"} or {"kind": "entry", "key", "entry", "options"}. None keeps the built-in rendering, which shows nothing for an entry.
Source§

fn transform_markdown<'a>( &'a self, _request: &'a Value, ) -> BoxFuture<'a, Result<Option<String>, String>>

The Markdown its transformer makes of request, {"markdown", "context"} with pi’s MarkdownTransformContext. Ok(None) keeps the Markdown, as when the transformer fails or returns no string.
Source§

fn render_code<'a>( &'a self, _request: &'a Value, ) -> BoxFuture<'a, Result<Option<Vec<String>>, String>>

The lines its code renderer draws for request, {"code", "lang", "width"} with lang possibly null, as text with escape sequences. Ok(None) leaves the code to yapi, and an error is the renderer’s.
Source§

fn tool_call<'a>( &'a self, _ctx: &'a Context, _tool: &'a str, _input: &'a Value, ) -> BoxFuture<'a, Option<String>>

A tool is about to run. Some(reason) blocks it.
Source§

fn run_bash<'a>( &'a self, _handle: &'a Value, _command: &'a str, _cwd: &'a Path, _output: UnboundedSender<Vec<u8>>, _cancel: CancellationToken, ) -> BoxFuture<'a, Result<Option<i32>, String>>

Runs command in cwd through the operations its user_bash handler returned as handle, sending output to output, until the command ends or cancel fires, and returns the exit code.
Source§

fn refresh_models<'a>( &'a self, _registry: &'a ModelRegistry, _options: &'a RefreshOptions, ) -> BoxFuture<'a, Vec<(String, ModelList)>>

Refreshes the model lists of the providers it registered with refreshModels that options selects, as pi does: first offline with the registry’s runtime key or stored credential (ModelRegistry::read_credential), then, when options allow the network and a credential resolves, online with it. Then those with the legacy oauth.modifyModels project their models for the stored credential, and pi-ai Providers check their API key and filter their models for it. Returns each step’s update, or why it failed, by provider in order.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more