Skip to main content

AppToolRenderersExt

Trait AppToolRenderersExt 

Source
pub trait AppToolRenderersExt {
    // Required methods
    fn add_tool_renderer(
        &mut self,
        tool: &str,
        render: impl Fn(&ToolCallView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static,
    ) -> &mut Self;
    fn add_entry_renderer(
        &mut self,
        plugin: &str,
        render: impl Fn(&EntryView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static,
    ) -> &mut Self;
    fn add_content_renderer(
        &mut self,
        kind: ContentKind,
        render: impl Fn(&ContentView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static,
    ) -> &mut Self;
    fn add_aside_renderer(
        &mut self,
        kind: &str,
        render: impl Fn(&AsideView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static,
    ) -> &mut Self;
    fn add_call_decorator(
        &mut self,
        name: &str,
        render: impl Fn(&ToolCallView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static,
    ) -> &mut Self;
}
Expand description

Registers transcript looks: how tool calls, notes, content blocks, asides and message text are drawn, and lines under every call or message.

Each look is a component on an entity of its own, named by what it draws: renderer:<tool>, entry:<plugin>, content:<kind>, aside:<kind>, message:<role>, decorator:<name>, message-decorator:<name>. The first look of a name stays (a later one is refused with a warning); Disabled on it, in Plugin::finish, frees it. A look spawned as a child of a TranscriptPane applies in that pane only, before the global one. A change to a look draws the transcript again. Without a look, a call draws as ToolCallView::default_lines, also while its arguments stream (CallState::Streaming). A renderer sees the calls its call started, through any effect in between, as ToolCallView::children:

use rig_harness::prelude::*;
use rig_tui::AppToolRenderersExt;
use rig_tui::ratatui::text::Line;

fn build(app: &mut App) {
    app.add_tool_renderer("consult", |view| {
        let mut lines = view.default_lines();
        for child in view.children {
            let indent = "  ".repeat(child.depth + 2);
            lines.push(Line::from(format!("{indent}↳ {} {:?}", child.name, child.state)));
        }
        lines
    });
}

Required Methods§

Source

fn add_tool_renderer( &mut self, tool: &str, render: impl Fn(&ToolCallView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Draw the calls of tool with render.

Source

fn add_entry_renderer( &mut self, plugin: &str, render: impl Fn(&EntryView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Draw the notes and the entries the plugin plugin wrote, such as a compaction’s summary, with render; without one they draw as EntryView::default_lines.

Source

fn add_content_renderer( &mut self, kind: ContentKind, render: impl Fn(&ContentView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Draw the content blocks of kind (an image, audio, a video or a document) with render; without one they draw as ContentView::default_lines.

Source

fn add_aside_renderer( &mut self, kind: &str, render: impl Fn(&AsideView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Draw the asides of kind with render after the entry they follow, as the transcript item TranscriptItem::Aside. An aside of a kind with no renderer is not drawn; a note (note) is drawn by its plugin’s entry renderer.

Source

fn add_call_decorator( &mut self, name: &str, render: impl Fn(&ToolCallView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Draw render’s lines under every tool call, after the call’s own look, whichever draws it. Decorators add up, in the order of their entities. Its rows under a call are the transcript item TranscriptItem::Decoration, by the call’s id and name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl AppToolRenderersExt for App

Source§

fn add_tool_renderer( &mut self, tool: &str, render: impl Fn(&ToolCallView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Source§

fn add_entry_renderer( &mut self, plugin: &str, render: impl Fn(&EntryView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Source§

fn add_content_renderer( &mut self, kind: ContentKind, render: impl Fn(&ContentView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Source§

fn add_aside_renderer( &mut self, kind: &str, render: impl Fn(&AsideView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Source§

fn add_call_decorator( &mut self, name: &str, render: impl Fn(&ToolCallView<'_>) -> Vec<Line<'static>> + Send + Sync + 'static, ) -> &mut Self

Implementors§