-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathfrontend.py
More file actions
45 lines (31 loc) · 1.28 KB
/
frontend.py
File metadata and controls
45 lines (31 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Frontend port — the Phase boundary (★ multi-interface).
Discord (Phase 1), Slack (Phase 2), Web (Phase 3) and the dev CLI all implement
this. The harness never imports a frontend; frontends drive the harness. Adding
Slack later is "implement this Protocol" with zero core changes.
"""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Protocol, runtime_checkable
from ..identity import Identity
@dataclass
class InboundMessage:
"""Normalised user input from any frontend."""
identity: Identity
text: str
attachments: list[bytes] = field(default_factory=list)
attachment_names: list[str] = field(default_factory=list)
@dataclass
class OutboundMessage:
"""Normalised agent output a frontend renders natively."""
text: str
file_bytes: bytes | None = None # e.g. CSV when result > 50 rows
file_name: str | None = None
@runtime_checkable
class FrontendPort(Protocol):
"""Translate between a chat platform and the harness."""
async def receive(self) -> InboundMessage:
"""Block until the next user message arrives."""
...
async def send(self, identity: Identity, message: OutboundMessage) -> None:
"""Deliver agent output back to the originating conversation."""
...