Skip to content

chat

Class info

Classes

Name Children Inherits
ApprovalDecisionMade
acptui.t3.chat
User clicked an approval button on an inline request card.
    ComposerTextArea
    acptui.t3.chat
    Multiline chat input: ``Enter`` sends, ``Shift+Enter`` / ``Ctrl+J`` adds a newline.
      ThreadChatPane
      acptui.t3.chat
      Right pane: header, scrollable message timeline, and composer.
        TurnItemWidget
        acptui.t3.chat
        Renders one :class:`TurnItem` and updates in place while streaming.

          🛈 DocStrings

          Right-hand chat pane: thread header, streaming timeline, inline approvals, composer.

          ApprovalDecisionMade

          Bases: Message

          User clicked an approval button on an inline request card.

          Source code in src/acptui/t3/chat.py
          class ApprovalDecisionMade(Message):
              """User clicked an approval button on an inline request card."""
          
              def __init__(self, thread_id: str, request_id: str, decision: ApprovalDecision) -> None:
                  super().__init__()
                  self.thread_id = thread_id
                  self.request_id = request_id
                  self.decision: ApprovalDecision = decision
          

          ComposerTextArea

          Bases: TextArea

          Multiline chat input: Enter sends, Shift+Enter / Ctrl+J adds a newline.

          Source code in src/acptui/t3/chat.py
          class ComposerTextArea(TextArea):
              """Multiline chat input: ``Enter`` sends, ``Shift+Enter`` / ``Ctrl+J`` adds a newline."""
          
              DEFAULT_CSS = """
              ComposerTextArea {
                  height: auto;
                  min-height: 3;
                  max-height: 8;
                  border: tall $panel-lighten-2;
                  background: $surface;
              }
              ComposerTextArea:focus {
                  border: tall $primary;
              }
              """
          
              class Submitted(Message):
                  """User pressed Enter to send the message."""
          
                  def __init__(self, text: str) -> None:
                      super().__init__()
                      self.text = text
          
              async def _on_key(self, event: Key) -> None:
                  if event.key == "enter":
                      event.prevent_default()
                      event.stop()
                      text = self.text.strip()
                      if text:
                          self.clear()
                          self.post_message(self.Submitted(text))
                      return
                  if event.key in {"shift+enter", "ctrl+j"}:
                      event.prevent_default()
                      event.stop()
                      self.insert("\n")
                      return
                  await super()._on_key(event)
          

          Submitted

          Bases: Message

          User pressed Enter to send the message.

          Source code in src/acptui/t3/chat.py
          class Submitted(Message):
              """User pressed Enter to send the message."""
          
              def __init__(self, text: str) -> None:
                  super().__init__()
                  self.text = text
          

          ThreadChatPane

          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)
          

          TurnItemWidget

          Bases: Vertical

          Renders one :class:TurnItem and updates in place while streaming.

          Source code in src/acptui/t3/chat.py
          class TurnItemWidget(Vertical):
              """Renders one :class:`TurnItem` and updates in place while streaming."""
          
              DEFAULT_CSS = """
              TurnItemWidget {
                  height: auto;
                  margin: 0 0 1 0;
                  padding: 0 1;
              }
              TurnItemWidget.-user {
                  border-left: thick $primary;
                  background: $panel;
                  padding: 0 1 0 2;
              }
              TurnItemWidget.-assistant {
                  border-left: thick $accent-darken-1;
                  padding: 0 1 0 2;
              }
              TurnItemWidget.-approval {
                  border: round $warning;
                  background: $panel;
                  padding: 1 2;
              }
              TurnItemWidget.-error {
                  border-left: thick $error;
                  background: $panel;
                  padding: 0 1 0 2;
              }
              TurnItemWidget .item-label {
                  color: $text-muted;
                  text-style: bold;
                  margin-bottom: 0;
              }
              TurnItemWidget .approval-prompt {
                  color: $warning;
                  text-style: bold;
                  margin: 1 0;
              }
              TurnItemWidget .approval-reason {
                  color: $text-muted;
                  margin-bottom: 1;
              }
              TurnItemWidget .approval-buttons {
                  height: auto;
                  margin-top: 1;
              }
              TurnItemWidget .approval-buttons Button {
                  margin-right: 1;
                  height: 1;
                  border: none;
                  min-width: 10;
              }
              TurnItemWidget Collapsible {
                  padding: 0;
                  border: none;
                  background: $surface;
              }
              TurnItemWidget .tool-body {
                  color: $text-muted;
                  padding: 0 1;
              }
              """
          
              def __init__(self, item: TurnItem) -> None:
                  super().__init__()
                  self.item = item
                  self._last_text: str = ""
                  self._apply_classes()
          
              def _apply_classes(self) -> None:
                  kind = self.item.type
                  self.set_class(kind == "user_message", "-user")
                  self.set_class(kind in {"assistant_message", "proposed_plan"}, "-assistant")
                  self.set_class(kind in {"approval_request", "user_input_request"}, "-approval")
                  self.set_class(kind == "error", "-error")
          
              def compose(self) -> ComposeResult:
                  """Build widgets according to `item.type`."""
                  item = self.item
                  kind = item.type
          
                  if kind == "user_message":
                      yield Static("You", classes="item-label")
                      self._last_text = item.text or ""
                      yield AgentMarkdown(self._last_text, classes="item-md")
                      return
          
                  if kind in {"assistant_message", "proposed_plan"}:
                      suffix = " · streaming…" if item.streaming else ""
                      label = "Plan" if kind == "proposed_plan" else "Assistant"
                      yield Static(f"{label}{suffix}", classes="item-label")
                      self._last_text = item.text or ""
                      yield AgentMarkdown(self._last_text, classes="item-md")
                      return
          
                  if kind == "reasoning":
                      title = "Thinking…" if item.streaming else "Reasoning"
                      self._last_text = item.text or ""
                      with Collapsible(title=title, collapsed=not bool(item.streaming)):
                          yield AgentMarkdown(self._last_text, classes="item-md")
                      return
          
                  if kind in {"approval_request", "user_input_request"}:
                      yield from self._compose_approval(item)
                      return
          
                  if kind in {"error", "system_notice"}:
                      label = "Error" if kind == "error" else "Notice"
                      yield Static(f"{_status_icon(item.status)} {label}", classes="item-label")
                      yield Static(_item_body(item) or (item.title or ""), classes="tool-body")
                      return
          
                  # Tool / command / file change / search / checkpoint / subagent
                  heading = f"{_status_icon(item.status)} {item.title or kind.replace('_', ' ')}"
                  body = _item_body(item)
                  with Collapsible(title=heading, collapsed=True):
                      yield Static(body or "(no output)", classes="tool-body")
          
              def _compose_approval(self, item: TurnItem) -> ComposeResult:
                  status_label = (
                      "Approval required" if item.status == "waiting" else f"Approval ({item.status})"
                  )
                  kind_tag = f" · {item.request_kind}" if item.request_kind else ""
                  yield Static(f"◆ {status_label}{kind_tag}", classes="item-label")
                  if item.prompt or item.title:
                      yield Static(item.prompt or item.title or "", classes="approval-prompt")
                  if item.reason:
                      yield Static(item.reason, classes="approval-reason")
                  if item.status == "waiting" and item.request_id:
                      options = item.options or []
                      with Horizontal(classes="approval-buttons"):
                          if options:
                              for opt in options:
                                  variant = (
                                      "success"
                                      if opt.decision in {"accept", "acceptForSession", "acceptAlways"}
                                      else "error"
                                  )
                                  yield Button(
                                      opt.label,
                                      variant=variant,
                                      name=opt.decision,
                                      classes="approval-btn",
                                  )
                          else:
                              yield Button("Allow", variant="success", name="accept", classes="approval-btn")
                              yield Button(
                                  "Session",
                                  variant="primary",
                                  name="acceptForSession",
                                  classes="approval-btn",
                              )
                              yield Button("Decline", variant="error", name="decline", classes="approval-btn")
          
              async def sync_item(self, item: TurnItem) -> None:
                  """Update this widget in place from a newer :class:`TurnItem`."""
                  prev_status = self.item.status
                  self.item = item
                  self._apply_classes()
          
                  if item.type in {"user_message", "assistant_message", "proposed_plan"}:
                      md_list = list(self.query(AgentMarkdown))
                      label_list = list(self.query(".item-label"))
                      if label_list and item.type in {"assistant_message", "proposed_plan"}:
                          base = "Plan" if item.type == "proposed_plan" else "Assistant"
                          suffix = " · streaming…" if item.streaming else ""
                          cast("Static", label_list[0]).update(f"{base}{suffix}")
                      new_text = item.text or ""
                      if md_list and new_text != self._last_text:
                          self._last_text = new_text
                          await md_list[0].update(new_text)
                      return
          
                  if item.type == "reasoning":
                      md_list = list(self.query(AgentMarkdown))
                      new_text = item.text or ""
                      if md_list and new_text != self._last_text:
                          self._last_text = new_text
                          await md_list[0].update(new_text)
                      return
          
                  if prev_status != item.status or item.type in {"approval_request", "user_input_request"}:
                      await self.recompose()
          
              def on_button_pressed(self, event: Button.Pressed) -> None:
                  """Forward inline approval button presses."""
                  if not event.button.has_class("approval-btn"):
                      return
                  if not self.item.request_id or not event.button.name:
                      return
                  event.stop()
                  decision = cast("ApprovalDecision", event.button.name)
                  self.post_message(ApprovalDecisionMade(self.item.thread_id, self.item.request_id, decision))
          

          compose

          compose() -> ComposeResult
          

          Build widgets according to item.type.

          Source code in src/acptui/t3/chat.py
          def compose(self) -> ComposeResult:
              """Build widgets according to `item.type`."""
              item = self.item
              kind = item.type
          
              if kind == "user_message":
                  yield Static("You", classes="item-label")
                  self._last_text = item.text or ""
                  yield AgentMarkdown(self._last_text, classes="item-md")
                  return
          
              if kind in {"assistant_message", "proposed_plan"}:
                  suffix = " · streaming…" if item.streaming else ""
                  label = "Plan" if kind == "proposed_plan" else "Assistant"
                  yield Static(f"{label}{suffix}", classes="item-label")
                  self._last_text = item.text or ""
                  yield AgentMarkdown(self._last_text, classes="item-md")
                  return
          
              if kind == "reasoning":
                  title = "Thinking…" if item.streaming else "Reasoning"
                  self._last_text = item.text or ""
                  with Collapsible(title=title, collapsed=not bool(item.streaming)):
                      yield AgentMarkdown(self._last_text, classes="item-md")
                  return
          
              if kind in {"approval_request", "user_input_request"}:
                  yield from self._compose_approval(item)
                  return
          
              if kind in {"error", "system_notice"}:
                  label = "Error" if kind == "error" else "Notice"
                  yield Static(f"{_status_icon(item.status)} {label}", classes="item-label")
                  yield Static(_item_body(item) or (item.title or ""), classes="tool-body")
                  return
          
              # Tool / command / file change / search / checkpoint / subagent
              heading = f"{_status_icon(item.status)} {item.title or kind.replace('_', ' ')}"
              body = _item_body(item)
              with Collapsible(title=heading, collapsed=True):
                  yield Static(body or "(no output)", classes="tool-body")
          

          on_button_pressed

          on_button_pressed(event: Pressed) -> None
          

          Forward inline approval button presses.

          Source code in src/acptui/t3/chat.py
          def on_button_pressed(self, event: Button.Pressed) -> None:
              """Forward inline approval button presses."""
              if not event.button.has_class("approval-btn"):
                  return
              if not self.item.request_id or not event.button.name:
                  return
              event.stop()
              decision = cast("ApprovalDecision", event.button.name)
              self.post_message(ApprovalDecisionMade(self.item.thread_id, self.item.request_id, decision))
          

          sync_item async

          sync_item(item: TurnItem) -> None
          

          Update this widget in place from a newer :class:TurnItem.

          Source code in src/acptui/t3/chat.py
          async def sync_item(self, item: TurnItem) -> None:
              """Update this widget in place from a newer :class:`TurnItem`."""
              prev_status = self.item.status
              self.item = item
              self._apply_classes()
          
              if item.type in {"user_message", "assistant_message", "proposed_plan"}:
                  md_list = list(self.query(AgentMarkdown))
                  label_list = list(self.query(".item-label"))
                  if label_list and item.type in {"assistant_message", "proposed_plan"}:
                      base = "Plan" if item.type == "proposed_plan" else "Assistant"
                      suffix = " · streaming…" if item.streaming else ""
                      cast("Static", label_list[0]).update(f"{base}{suffix}")
                  new_text = item.text or ""
                  if md_list and new_text != self._last_text:
                      self._last_text = new_text
                      await md_list[0].update(new_text)
                  return
          
              if item.type == "reasoning":
                  md_list = list(self.query(AgentMarkdown))
                  new_text = item.text or ""
                  if md_list and new_text != self._last_text:
                      self._last_text = new_text
                      await md_list[0].update(new_text)
                  return
          
              if prev_status != item.status or item.type in {"approval_request", "user_input_request"}:
                  await self.recompose()