GPUI Box GitHub

Components / agent

PromptBuilder builder

A template with host-owned slots.

A builder is RenderOnce. Construct and mount it in one expression.

use gpui_kit::agent::PromptBuilder;

Reviewed in prompt-builder.

Construct
new(ident: impl Into<Ident>, label: impl Into<SharedString>) -> Self
Options

Chain onto the value.

body(body: impl Into<SharedString>) -> Self
slots(slots: impl IntoIterator<Item = PromptSlot>) -> Self
state(state: PromptBuilderState) -> Self
on_slot(handler: impl Fn(&PromptSlot, &mut Window, &mut App) + 'static) -> Self
Reports

The variants of the event it emits. It never applies the change itself.

  • SlotActivated
Example · prompt-builder
fn prompt_builder(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(520.0))
        .child(caption(
            &theme,
            "host-owned slots; activating one reports identity, never fills the prompt",
        ))
        .child(
            PromptBuilder::new("scene.prompt.loading", "Review template")
                .state(PromptBuilderState::Loading),
        )
        .child(
            PromptBuilder::new("scene.prompt.ready", "Review template")
                .body("Review {path} for {concern} and return a verdict.")
                .slots([
                    PromptSlot::new("path", "path").value("src/lib.rs"),
                    PromptSlot::new("concern", "concern"),
                ])
                .on_slot(|_, _, _| {}),
        )
        .child(
            PromptBuilder::new("scene.prompt.empty", "Review template")
                .state(PromptBuilderState::Empty),
        )
        .child(
            PromptBuilder::new("scene.prompt.unavailable", "Review template").state(
                PromptBuilderState::Unavailable("The template host refused the request.".into()),
            ),
        )
        .child(
            PromptBuilder::new("scene.prompt.error", "Review template").state(
                PromptBuilderState::Error("The template request failed.".into()),
            ),
        )
        .into_any_element()
}

Source: crates/gpui-kit/src/agent/prompt.rs