897b444d27
* feat: Add context management middleware for improved error handling and context editing * feat: Implement LLMToolSelectorMiddleware for enhanced tool selection and tracking * feat(tests): update test functions to include mock timestamp parameter * refactor: simplify tool selection state storage and update comments in middleware * feat: Enhance tool selection handling and suppress structured output for improved event streaming * refactor: simplify patching in test_create_tool_selector functions * feat: add model parameter to create_tool_selector_middleware for enhanced flexibility * feat: enhance tool selection suppression with JSON buffering for improved accuracy
41 lines
1016 B
Python
41 lines
1016 B
Python
"""Tool selection panel widget for LLMToolSelectorMiddleware display.
|
|
|
|
Renders a Rich Panel showing which tools were selected for the current
|
|
query. Dim border to indicate it's informational, not interactive.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from rich.panel import Panel
|
|
from rich.text import Text
|
|
from textual.widgets import Static
|
|
|
|
|
|
class ToolSelectionWidget(Static):
|
|
"""Static panel showing selected tools.
|
|
|
|
Usage::
|
|
|
|
w = ToolSelectionWidget(["ls", "read_file", "execute"])
|
|
await container.mount(w)
|
|
"""
|
|
|
|
DEFAULT_CSS = """
|
|
ToolSelectionWidget {
|
|
height: auto;
|
|
margin: 0 0 1 0;
|
|
}
|
|
"""
|
|
|
|
def __init__(self, tools: list[str]) -> None:
|
|
super().__init__("")
|
|
tools_str = ", ".join(tools)
|
|
self.update(
|
|
Panel(
|
|
Text(tools_str, style="cyan"),
|
|
title=f"Adaptive Selected Tools ({len(tools)})",
|
|
border_style="#2d7d46",
|
|
padding=(0, 1),
|
|
)
|
|
)
|