03f4134190
- Introduced UserMessage widget for displaying user input with a styled prompt. - Updated onboarding steps to include UI backend selection (Rich CLI or Textual TUI). - Modified EvoScientistConfig to store selected UI backend. - Enhanced configuration handling to support UI backend environment variable. - Updated README with new UI backend options and commands. - Added tests for new UI backend functionality and UserMessage widget. - Removed obsolete test files and ensured existing tests are updated accordingly.
62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
"""TUI backend abstractions for streaming output."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any, Callable, Protocol
|
|
|
|
from ..stream.display import _run_streaming
|
|
|
|
|
|
class StreamingTUIBackend(Protocol):
|
|
"""Protocol for TUI backends that can render agent streaming output."""
|
|
|
|
name: str
|
|
|
|
def run_streaming(
|
|
self,
|
|
*,
|
|
agent: Any,
|
|
message: str,
|
|
thread_id: str,
|
|
show_thinking: bool,
|
|
interactive: bool,
|
|
on_thinking: Callable[[str], None] | None = None,
|
|
on_todo: Callable[[list[dict]], None] | None = None,
|
|
on_file_write: Callable[[str], None] | None = None,
|
|
metadata: dict | None = None,
|
|
) -> str:
|
|
"""Run streaming and return final response text."""
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class RichStreamingBackend:
|
|
"""Default Rich backend wrapper around the existing streaming renderer."""
|
|
|
|
name: str = "rich"
|
|
|
|
def run_streaming(
|
|
self,
|
|
*,
|
|
agent: Any,
|
|
message: str,
|
|
thread_id: str,
|
|
show_thinking: bool,
|
|
interactive: bool,
|
|
on_thinking: Callable[[str], None] | None = None,
|
|
on_todo: Callable[[list[dict]], None] | None = None,
|
|
on_file_write: Callable[[str], None] | None = None,
|
|
metadata: dict | None = None,
|
|
) -> str:
|
|
return _run_streaming(
|
|
agent=agent,
|
|
message=message,
|
|
thread_id=thread_id,
|
|
show_thinking=show_thinking,
|
|
interactive=interactive,
|
|
on_thinking=on_thinking,
|
|
on_todo=on_todo,
|
|
on_file_write=on_file_write,
|
|
metadata=metadata,
|
|
)
|