Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tether/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Provider-neutral Agent integration and the owner-bound Client composition."""

from tether.client import Client
from tether.client._composition.client import BoundClient
from tether.sessions.service import SessionService
from tether.types import MODEL_PORT_VERSION as MODEL_PORT_VERSION
from tether.types.execution import Actor
Expand All @@ -10,4 +11,4 @@ class Tether(SessionService):
"""Explicit asynchronous composition; public commands are developed in slice 4."""

def client(self, actor: Actor) -> Client:
return Client(self, actor)
return BoundClient(self, actor)
17 changes: 13 additions & 4 deletions src/tether/client/_composition/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ async def turn_result(self, session_id: str, turn_id: str) -> TurnResult | None:


class Client(ClientTurnOperations, OperationClient, ClientReads):
def __init__(self, service: SessionService, actor: Actor) -> None:
super().__init__(service.access, actor, service.archives)
self._service = service
self._metadata = MetadataCommands(service.access)
_metadata: MetadataCommands

def __init__(self) -> None:
raise TypeError("Obtain a Client through ClientHost.client(actor)")

async def confirm(
self,
Expand Down Expand Up @@ -212,3 +212,12 @@ async def resume(self, session_id: str) -> TurnHandle:

async def restore(self, session_id: str) -> SessionSummary:
return await self._service.archives.restore(self._actor, session_id)


class BoundClient(Client):
"""Internal implementation constructed with an owner-bound service."""

def __init__(self, service: SessionService, actor: Actor) -> None:
ClientReads.__init__(self, service.access, actor, service.archives)
self._service = service
self._metadata = MetadataCommands(service.access)
21 changes: 15 additions & 6 deletions src/tether/client/_composition/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ class ClientPorts:
class ClientHost:
"""Owns a composed client service and only the resources it opens."""

def __init__(self, service: SessionService) -> None:
self._service = service
self._closed = False
_service: SessionService
_closed: bool

def __init__(self) -> None:
raise TypeError("Use ClientHost.open() or ClientHost.from_ports()")

@classmethod
def _from_service(cls, service: SessionService) -> Self:
host = cls.__new__(cls)
host._service = service
host._closed = False
return host

@classmethod
async def open(cls, settings: ClientSettings) -> Self:
Expand Down Expand Up @@ -154,7 +163,7 @@ async def _open(cls, settings: ClientSettings, ports: ClientPorts) -> Self:
_storage_drain=root.wait_closed if root is not None else None,
)
await service.__aenter__()
return cls(service)
return cls._from_service(service)
except BaseException:
if service is not None:
await service.aclose()
Expand All @@ -170,9 +179,9 @@ async def _open(cls, settings: ClientSettings, ports: ClientPorts) -> Self:
def client(self, actor: Actor) -> ClientProtocol:
if self._closed:
raise RuntimeError("tether_not_active")
from .client import Client
from .client import BoundClient

return Client(self._service, actor)
return BoundClient(self._service, actor)

@property
def store(self) -> SessionStore:
Expand Down
Loading
Loading