Skip to content

DemoSession

🛈 DocStrings

A session of the demo agent.

Source code in src/acptui/demo.py
@dataclass
class DemoSession:
    """A session of the demo agent."""

    session_id: str
    cwd: str
    title: str | None = None
    updated_at: str = field(default_factory=lambda: datetime.now(UTC).isoformat())
    history: list[SessionUpdate] = field(default_factory=list)
    mode: str = "ask"
    model: str = "demo-fast"
    thinking: bool = True
    turn: asyncio.Task[None] | None = None
    archived: bool = False
    parent_id: str | None = None
    additional_directories: list[str] = field(default_factory=list)
    mcp_servers: list[dict[str, object]] = field(default_factory=list)
    system_prompt: str | None = None
    cursors: dict[str, int] = field(default_factory=dict)
    """Fork points: cursor ID -> length of the history before it."""
    cancelled_tools: set[str] = field(default_factory=set)

    def apply_initial(self, option: InitialSessionConfigOption) -> None:
        """Apply an initial config option value; unknown ones are ignored (as the spec says)."""
        match option:
            case InitialConfigOptionId(config_id="mode", value=value) if value in {"ask", "auto"}:
                self.mode = value
            case InitialConfigOptionId(config_id="model", value=value) if value in MODELS:
                self.model = value
            case InitialConfigOptionBoolean(config_id="thinking", value=value):
                self.thinking = value
            case _:
                pass

    def describe_setup(self) -> str:
        """What the client sent on session setup, as Markdown."""
        servers = ", ".join(str(s.get("name")) for s in self.mcp_servers) or "none"
        return "\n".join([
            "## Session setup",
            "",
            f"- cwd: `{self.cwd}`",
            f"- additional directories: {', '.join(self.additional_directories) or 'none'}",
            f"- MCP servers: {servers}",
            f"- system prompt: {self.system_prompt or 'none'}",
            f"- mode: {self.mode}, model: {self.model}, thinking: {self.thinking}",
        ])

    def config_options(self) -> list[SessionConfigOption]:
        """The session's config options and their values."""
        return [
            SelectSessionConfigOption(
                config_id="mode",
                name="Mode",
                category="mode",
                current_value=self.mode,
                options=[
                    SessionConfigSelectOption(
                        value="ask", name="Ask", description="Ask before editing files"
                    ),
                    SessionConfigSelectOption(
                        value="auto", name="Auto", description="Edit without asking"
                    ),
                ],
            ),
            SelectSessionConfigOption(
                config_id="model",
                name="Model",
                category="model",
                current_value=self.model,
                options=[
                    SessionConfigSelectGroup(
                        group_id="fast",
                        name="Fast",
                        options=[SessionConfigSelectOption(value="demo-fast", name="Demo Fast")],
                    ),
                    SessionConfigSelectGroup(
                        group_id="smart",
                        name="Smart",
                        options=[SessionConfigSelectOption(value="demo-smart", name="Demo Smart")],
                    ),
                ],
            ),
            BooleanSessionConfigOption(
                config_id="thinking",
                name="Thinking",
                category="thought_level",
                current_value=self.thinking,
            ),
        ]

cursors class-attribute instance-attribute

cursors: dict[str, int] = field(default_factory=dict)

Fork points: cursor ID -> length of the history before it.

apply_initial

apply_initial(option: InitialSessionConfigOption) -> None

Apply an initial config option value; unknown ones are ignored (as the spec says).

Source code in src/acptui/demo.py
def apply_initial(self, option: InitialSessionConfigOption) -> None:
    """Apply an initial config option value; unknown ones are ignored (as the spec says)."""
    match option:
        case InitialConfigOptionId(config_id="mode", value=value) if value in {"ask", "auto"}:
            self.mode = value
        case InitialConfigOptionId(config_id="model", value=value) if value in MODELS:
            self.model = value
        case InitialConfigOptionBoolean(config_id="thinking", value=value):
            self.thinking = value
        case _:
            pass

config_options

config_options() -> list[SessionConfigOption]

The session's config options and their values.

Source code in src/acptui/demo.py
def config_options(self) -> list[SessionConfigOption]:
    """The session's config options and their values."""
    return [
        SelectSessionConfigOption(
            config_id="mode",
            name="Mode",
            category="mode",
            current_value=self.mode,
            options=[
                SessionConfigSelectOption(
                    value="ask", name="Ask", description="Ask before editing files"
                ),
                SessionConfigSelectOption(
                    value="auto", name="Auto", description="Edit without asking"
                ),
            ],
        ),
        SelectSessionConfigOption(
            config_id="model",
            name="Model",
            category="model",
            current_value=self.model,
            options=[
                SessionConfigSelectGroup(
                    group_id="fast",
                    name="Fast",
                    options=[SessionConfigSelectOption(value="demo-fast", name="Demo Fast")],
                ),
                SessionConfigSelectGroup(
                    group_id="smart",
                    name="Smart",
                    options=[SessionConfigSelectOption(value="demo-smart", name="Demo Smart")],
                ),
            ],
        ),
        BooleanSessionConfigOption(
            config_id="thinking",
            name="Thinking",
            category="thought_level",
            current_value=self.thinking,
        ),
    ]

describe_setup

describe_setup() -> str

What the client sent on session setup, as Markdown.

Source code in src/acptui/demo.py
def describe_setup(self) -> str:
    """What the client sent on session setup, as Markdown."""
    servers = ", ".join(str(s.get("name")) for s in self.mcp_servers) or "none"
    return "\n".join([
        "## Session setup",
        "",
        f"- cwd: `{self.cwd}`",
        f"- additional directories: {', '.join(self.additional_directories) or 'none'}",
        f"- MCP servers: {servers}",
        f"- system prompt: {self.system_prompt or 'none'}",
        f"- mode: {self.mode}, model: {self.model}, thinking: {self.thinking}",
    ])

:fa-brands-github: Show source on GitHub