Skip to content

ProviderEditScreen

Base classes

Name Children Inherits
ModalScreen
textual.screen
A screen with bindings that take precedence over the App's key bindings.

⋔ Inheritance diagram

graph TD
  107846721646576["providers.ProviderEditScreen"]
  107846717906624["screen.ModalScreen"]
  107846717858048["screen.Screen"]
  107846685555472["typing.Generic"]
  137699722799616["builtins.object"]
  107846718477920["widget.Widget"]
  107846718489888["dom.DOMNode"]
  107846718374032["message_pump.MessagePump"]
  107846717906624 --> 107846721646576
  107846717858048 --> 107846717906624
  107846685555472 --> 107846717858048
  137699722799616 --> 107846685555472
  107846718477920 --> 107846717858048
  107846718489888 --> 107846718477920
  107846718374032 --> 107846718489888
  137699722799616 --> 107846718374032

🛈 DocStrings

Bases: ModalScreen[bool]

Edit (or disable) one provider.

Source code in src/acptui/ui/screens/providers.py
class ProviderEditScreen(ModalScreen[bool]):
    """Edit (or disable) one provider."""

    DEFAULT_CSS = (
        "ProviderEditScreen {"
        + DIALOG_CSS
        + " TextArea { height: 5; } #buttons { height: auto; } }"
    )
    BINDINGS: ClassVar = [Binding("escape", "close", "Cancel")]

    def __init__(self, connection: AgentConnection, provider: ProviderInfo) -> None:
        super().__init__()
        self.connection = connection
        self.provider = provider

    def compose(self) -> ComposeResult:
        provider = self.provider
        current = provider.current if is_set(provider.current) else None
        with Vertical(id="dialog"):
            yield Static(Content(f"Provider {provider.provider_id}"), id="dialog-title")
            yield Static("API type")
            yield Select(
                [(api, api) for api in provider.supported],
                value=current.api_type if current is not None else Select.NULL,
                id="api-type",
            )
            yield Static("Base URL")
            yield Input(current.base_url if current is not None else "", id="base-url")
            yield Static("Headers (one 'Name: value' per line, replaces all headers)")
            yield TextArea("", id="headers")
            with Horizontal(id="buttons"):
                yield Button("Save", variant="success", id="save", compact=True)
                if not provider.required:
                    yield Button("Disable", variant="error", id="disable", compact=True)
                yield Button("Cancel", id="cancel", compact=True)

    async def on_button_pressed(self, event: Button.Pressed) -> None:
        match event.button.id:
            case "save":
                api = self.query_one("#api-type", Select).value
                url = self.query_one("#base-url", Input).value.strip()
                if api is Select.NULL or not url:
                    self.notify("API type and base URL are required", severity="error")
                    return
                headers = parse_headers(self.query_one("#headers", TextArea).text)
                await self._run(
                    self.connection.set_provider(self.provider.provider_id, str(api), url, headers)
                )
            case "disable":
                await self._run(self.connection.disable_provider(self.provider.provider_id))
            case _:
                self.dismiss(False)

    async def _run(self, call: Awaitable[None]) -> None:
        try:
            await call
        except (RequestError, ConnectionError) as exc:
            self.notify(f"The agent rejected the change: {exc}", severity="error")
            return
        self.dismiss(True)

    def action_close(self) -> None:
        """Cancel."""
        self.dismiss(False)

action_close

action_close() -> None

Cancel.

Source code in src/acptui/ui/screens/providers.py
def action_close(self) -> None:
    """Cancel."""
    self.dismiss(False)

:fa-brands-github: Show source on GitHub