Skip to content

ThreadChatPane

Base classes

Name Children Inherits
Vertical
textual.containers
An expanding container with vertical layout and no scrollbars.

⋔ Inheritance diagram

graph TD
  3928938449["chat.ThreadChatPane"]
  723859837["containers.Vertical"]
  4188532303["widget.Widget"]
  3946681048["dom.DOMNode"]
  53685856["message_pump.MessagePump"]
  2751680898["builtins.object"]
  723859837 --> 3928938449
  4188532303 --> 723859837
  3946681048 --> 4188532303
  53685856 --> 3946681048
  2751680898 --> 53685856

🛈 DocStrings

Bases: Vertical

Right pane: header, scrollable message timeline, and composer.

Source code in src/acptui/t3/chat.py
class ThreadChatPane(Vertical):
    """Right pane: header, scrollable message timeline, and composer."""

    DEFAULT_CSS = """
    ThreadChatPane {
        width: 1fr;
        height: 1fr;
        background: $background;
    }
    #chat-header {
        height: 3;
        padding: 0 2;
        align: left middle;
        border-bottom: solid $panel;
        background: $surface;
    }
    #chat-title {
        width: 1fr;
        text-style: bold;
    }
    #chat-status {
        width: auto;
        margin-right: 1;
        color: $text-muted;
    }
    #stop-btn {
        height: 1;
        min-width: 8;
        border: none;
        display: none;
    }
    #stop-btn.-visible {
        display: block;
    }
    #chat-scroll {
        height: 1fr;
        padding: 1 2;
    }
    #chat-empty {
        padding: 2 2;
        color: $text-muted;
    }
    #composer-wrap {
        height: auto;
        padding: 0 2 1 2;
        border-top: solid $panel;
        background: $surface;
    }
    #composer-hint {
        color: $text-muted;
        height: 1;
    }
    """

    class SendRequested(Message):
        """User submitted a message for the active thread."""

        def __init__(self, text: str) -> None:
            super().__init__()
            self.text = text

    class StopRequested(Message):
        """User requested stopping the active thread's run."""

    def __init__(self) -> None:
        super().__init__(id="thread-chat-pane")
        self._widgets: dict[str, TurnItemWidget] = {}
        self._active_thread_id: str | None = None

    def compose(self) -> ComposeResult:
        """Build the header, timeline scroll area, and composer."""
        with Horizontal(id="chat-header"):
            yield Static("Select a thread", id="chat-title")
            yield Static("", id="chat-status")
            yield Button("Stop", id="stop-btn", variant="error")
        with VerticalScroll(id="chat-scroll"):
            yield Static(
                "Pick a thread from the sidebar or press Ctrl+N to start a new one.",
                id="chat-empty",
            )
        with Vertical(id="composer-wrap"):
            yield ComposerTextArea(id="composer")
            yield Static(
                "Enter: send · Shift+Enter: newline · Ctrl+B: sidebar · /: filter · Ctrl+N: new",
                id="composer-hint",
            )

    def focus_composer(self) -> None:
        """Focus the chat composer."""
        self.query_one("#composer", ComposerTextArea).focus()

    def set_header(
        self, thread: ThreadShell | None, *, project_title: str = "", running: bool = False
    ) -> None:
        """Update the thread header bar and Stop button visibility."""
        title_w = self.query_one("#chat-title", Static)
        status_w = self.query_one("#chat-status", Static)
        stop_btn = self.query_one("#stop-btn", Button)
        if thread is None:
            title_w.update("Select a thread")
            status_w.update("")
            stop_btn.set_class(False, "-visible")
            return

        meta = [project_title] if project_title else []
        if thread.branch:
            meta.append(thread.branch)
        model = (
            str(thread.model_selection.get("model"))
            if thread.model_selection and thread.model_selection.get("model")
            else ""
        )
        if model:
            meta.append(model)
        meta_str = f"  ({' · '.join(meta)})" if meta else ""
        title_w.update(
            Content.assemble(
                Content(thread.title).stylize("bold"),
                Content(meta_str).stylize("$text-muted"),
            )
        )
        is_running = running or thread.status in {"queued", "preparing", "starting", "running"}
        status_style = (
            "bold $warning"
            if thread.status == "waiting"
            else "bold $accent"
            if is_running
            else "$text-muted"
        )
        status_w.update(
            Content(f"{_status_icon(thread.status)} {thread.status}").stylize(status_style)
        )
        stop_btn.set_class(is_running, "-visible")

    async def reset_timeline(self, timeline: ThreadTimelineState) -> None:
        """Replace the timeline view with `timeline`'s current items."""
        self._active_thread_id = timeline.thread_id
        scroll = self.query_one("#chat-scroll", VerticalScroll)
        await scroll.remove_children()
        self._widgets.clear()
        items = timeline.ordered_items
        if not items:
            await scroll.mount(
                Static("No messages yet. Type below to start this thread.", id="chat-empty")
            )
            return
        widgets: list[TurnItemWidget] = []
        for item in items:
            widget = TurnItemWidget(item)
            self._widgets[item.id] = widget
            widgets.append(widget)
        await scroll.mount(*widgets)
        self.call_after_refresh(scroll.scroll_end, animate=False)

    async def upsert_item(self, item: TurnItem) -> None:
        """Insert or update a single :class:`TurnItem` in the timeline."""
        scroll = self.query_one("#chat-scroll", VerticalScroll)
        existing = self._widgets.get(item.id)
        if existing is not None:
            await existing.sync_item(item)
        else:
            for empty in list(scroll.query("#chat-empty")):
                await empty.remove()
            widget = TurnItemWidget(item)
            self._widgets[item.id] = widget
            await scroll.mount(widget)
        self.call_after_refresh(scroll.scroll_end, animate=False)

    def on_composer_text_area_submitted(self, event: ComposerTextArea.Submitted) -> None:
        """Bubble composer submission."""
        event.stop()
        self.post_message(self.SendRequested(event.text))

    def on_button_pressed(self, event: Button.Pressed) -> None:
        """Handle Stop button click."""
        if event.button.id == "stop-btn":
            event.stop()
            self.post_message(self.StopRequested())

SendRequested

Bases: Message

User submitted a message for the active thread.

Source code in src/acptui/t3/chat.py
class SendRequested(Message):
    """User submitted a message for the active thread."""

    def __init__(self, text: str) -> None:
        super().__init__()
        self.text = text

StopRequested

Bases: Message

User requested stopping the active thread's run.

Source code in src/acptui/t3/chat.py
class StopRequested(Message):
    """User requested stopping the active thread's run."""

compose

compose() -> ComposeResult

Build the header, timeline scroll area, and composer.

Source code in src/acptui/t3/chat.py
def compose(self) -> ComposeResult:
    """Build the header, timeline scroll area, and composer."""
    with Horizontal(id="chat-header"):
        yield Static("Select a thread", id="chat-title")
        yield Static("", id="chat-status")
        yield Button("Stop", id="stop-btn", variant="error")
    with VerticalScroll(id="chat-scroll"):
        yield Static(
            "Pick a thread from the sidebar or press Ctrl+N to start a new one.",
            id="chat-empty",
        )
    with Vertical(id="composer-wrap"):
        yield ComposerTextArea(id="composer")
        yield Static(
            "Enter: send · Shift+Enter: newline · Ctrl+B: sidebar · /: filter · Ctrl+N: new",
            id="composer-hint",
        )

focus_composer

focus_composer() -> None

Focus the chat composer.

Source code in src/acptui/t3/chat.py
def focus_composer(self) -> None:
    """Focus the chat composer."""
    self.query_one("#composer", ComposerTextArea).focus()

on_button_pressed

on_button_pressed(event: Pressed) -> None

Handle Stop button click.

Source code in src/acptui/t3/chat.py
def on_button_pressed(self, event: Button.Pressed) -> None:
    """Handle Stop button click."""
    if event.button.id == "stop-btn":
        event.stop()
        self.post_message(self.StopRequested())

on_composer_text_area_submitted

on_composer_text_area_submitted(event: Submitted) -> None

Bubble composer submission.

Source code in src/acptui/t3/chat.py
def on_composer_text_area_submitted(self, event: ComposerTextArea.Submitted) -> None:
    """Bubble composer submission."""
    event.stop()
    self.post_message(self.SendRequested(event.text))

reset_timeline async

reset_timeline(timeline: ThreadTimelineState) -> None

Replace the timeline view with timeline's current items.

Source code in src/acptui/t3/chat.py
async def reset_timeline(self, timeline: ThreadTimelineState) -> None:
    """Replace the timeline view with `timeline`'s current items."""
    self._active_thread_id = timeline.thread_id
    scroll = self.query_one("#chat-scroll", VerticalScroll)
    await scroll.remove_children()
    self._widgets.clear()
    items = timeline.ordered_items
    if not items:
        await scroll.mount(
            Static("No messages yet. Type below to start this thread.", id="chat-empty")
        )
        return
    widgets: list[TurnItemWidget] = []
    for item in items:
        widget = TurnItemWidget(item)
        self._widgets[item.id] = widget
        widgets.append(widget)
    await scroll.mount(*widgets)
    self.call_after_refresh(scroll.scroll_end, animate=False)

set_header

set_header(thread: ThreadShell | None, *, project_title: str = '', running: bool = False) -> None

Update the thread header bar and Stop button visibility.

Source code in src/acptui/t3/chat.py
def set_header(
    self, thread: ThreadShell | None, *, project_title: str = "", running: bool = False
) -> None:
    """Update the thread header bar and Stop button visibility."""
    title_w = self.query_one("#chat-title", Static)
    status_w = self.query_one("#chat-status", Static)
    stop_btn = self.query_one("#stop-btn", Button)
    if thread is None:
        title_w.update("Select a thread")
        status_w.update("")
        stop_btn.set_class(False, "-visible")
        return

    meta = [project_title] if project_title else []
    if thread.branch:
        meta.append(thread.branch)
    model = (
        str(thread.model_selection.get("model"))
        if thread.model_selection and thread.model_selection.get("model")
        else ""
    )
    if model:
        meta.append(model)
    meta_str = f"  ({' · '.join(meta)})" if meta else ""
    title_w.update(
        Content.assemble(
            Content(thread.title).stylize("bold"),
            Content(meta_str).stylize("$text-muted"),
        )
    )
    is_running = running or thread.status in {"queued", "preparing", "starting", "running"}
    status_style = (
        "bold $warning"
        if thread.status == "waiting"
        else "bold $accent"
        if is_running
        else "$text-muted"
    )
    status_w.update(
        Content(f"{_status_icon(thread.status)} {thread.status}").stylize(status_style)
    )
    stop_btn.set_class(is_running, "-visible")

upsert_item async

upsert_item(item: TurnItem) -> None

Insert or update a single :class:TurnItem in the timeline.

Source code in src/acptui/t3/chat.py
async def upsert_item(self, item: TurnItem) -> None:
    """Insert or update a single :class:`TurnItem` in the timeline."""
    scroll = self.query_one("#chat-scroll", VerticalScroll)
    existing = self._widgets.get(item.id)
    if existing is not None:
        await existing.sync_item(item)
    else:
        for empty in list(scroll.query("#chat-empty")):
            await empty.remove()
        widget = TurnItemWidget(item)
        self._widgets[item.id] = widget
        await scroll.mount(widget)
    self.call_after_refresh(scroll.scroll_end, animate=False)

:fa-brands-github: Show source on GitHub