spacr.qt.widgets.ai_chat_panel
==============================

.. py:module:: spacr.qt.widgets.ai_chat_panel

.. autoapi-nested-parse::

   AIChatPanel — reusable chat widget hosting the spacr AI Console.

   Meant to be embedded next to the pipeline Console (via a QDockWidget on
   the main window) so users never leave the app they're running. Exposes
   `open_error_flow(traceback, active_app)` for AppScreen's "Explain
   error" button.

   Design notes
   ------------
   * One instance is shared across the whole main window; the user's
     chat context persists as they switch between Mask/Measure/etc.
   * Streaming is done in a QThread via `spacr.qt.ai.worker.StreamWorker`.
     The worker reference is stored on `self` — if we let Python drop it,
     Qt may never deliver the finished signal.
   * There is NO "already streaming" guard. If a stream is in flight, the
     Send button turns into Cancel so the user can always recover.





Module Contents
---------------

.. py:class:: AIChatPanel(parent: Optional[PySide6.QtWidgets.QWidget] = None)

   Bases: :py:obj:`PySide6.QtWidgets.QWidget`


   Full chat panel — embed inside a QDockWidget or any container.


   .. py:method:: refresh_provider_combo() -> None

      Rebuild the provider dropdown from the currently configured CLIs.



   .. py:method:: clear_chat() -> None

      Discard chat history and remove every bubble from the scroll area.



   .. py:method:: open_error_flow(traceback_text: str, active_app: str = '') -> None

      Send a traceback to the AI explainer and stream the reply.

      :param traceback_text: raw traceback captured from the pipeline.
      :param active_app: optional app label used in the framing prompt.



