GPUI Box GitHub

Components / agent

ThinkingBlock builder

A collapsed block of model reasoning.

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

use gpui_kit::agent::ThinkingBlock;

Reviewed in thinking.

Construct
new(ident: impl Into<Ident>, reasoning: Reasoning) -> Self
Options

Chain onto the value.

expanded(expanded: bool) -> Self
presentation(presentation: AgentDisclosurePresentation) -> Self
thinking(thinking: bool) -> Self
elapsed(elapsed: impl Into<SharedString>) -> Self
on_toggle(handler: impl Fn(bool, &mut Window, &mut App) + 'static) -> Self
Example · thinking
fn thinking(_window: &mut Window, cx: &mut App) -> AnyElement {
    let theme = cx.theme().clone();
    stack(&theme)
        .w(px(640.0))
        .child(
            ThinkingBlock::new(
                "scene.thinking.collapsed",
                Reasoning::present("The brief asks for two files, so read both before answering."),
            )
            .elapsed("2.1 s"),
        )
        // Reasoning that has finished and reasoning still arriving are the
        // same words in the same place, so the difference has to be shown.
        .child(
            ThinkingBlock::new(
                "scene.thinking.working",
                Reasoning::present("Reading the second file before answering."),
            )
            .thinking(true),
        )
        .child(
            ThinkingBlock::new(
                "scene.thinking.open",
                Reasoning::present(
                    "The brief asks for two files.\nRead both before answering.\nThen summarise.",
                ),
            )
            .expanded(true)
            .elapsed("8.4 s")
            .on_toggle(|_, _, _| {}),
        )
        .child(
            ThinkingBlock::new(
                "scene.thinking.flow",
                Reasoning::present("The same evidence stays indented.\nIt has no body plane."),
            )
            .expanded(true)
            .presentation(AgentDisclosurePresentation::Flow)
            .on_toggle(|_, _, _| {}),
        )
        // Withheld and absent are two different facts, and neither is the
        // collapsed block above.
        .child(ThinkingBlock::new(
            "scene.thinking.withheld",
            Reasoning::withheld("This connection does not hand over reasoning."),
        ))
        .child(ThinkingBlock::new(
            "scene.thinking.absent",
            Reasoning::Absent,
        ))
        .into_any_element()
}

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