okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

nekomimi.petfix: guard closed child mail and remove inherited shim generationsff92766

main
1.6 KiB51 linesraw
1"""mail.submit: one letter from this session to another. The daemon derives
2the sender, resolves the name, stores the letter, and delivers it."""
3
4from __future__ import annotations
5
6from typing import cast
7
8from albedo_api import Host, PythonApi, Record
9
10
11class Receipt(Record):
12    """receipt.id, .to (session id), .name, and .status: "delivered",
13    "queued" behind a running turn, or "pending" until that session runs.
14    "delivered" may still be waiting for kernel preparation."""
15
16    id: str
17    to: str
18    name: str
19    status: str
20
21
22host: Host
23
24
25class Mail:
26    async def submit(self, to: object, body: str) -> Receipt:
27        """Send `body` to "parent", a child or sibling by name, an agent
28        handle, or any session id."""
29        target = getattr(to, "id", to)
30        if not isinstance(target, str) or not target.strip():
31            raise TypeError(
32                'mail.submit(to, body): to is "parent", a name, a session id, or an agent handle'
33            )
34        if not isinstance(body, str):
35            raise TypeError(
36                f"mail.submit(to, body): body must be str, got {type(body).__name__}"
37            )
38        return Receipt(
39            cast(dict, await host("mail.submit", {"to": target.strip(), "body": body}))
40        )
41
42    def read(self, *_: object, **__: object) -> None:
43        raise AttributeError(
44            "there is no mail.read: letters to you arrive in your conversation as <mail> blocks"
45        )
46
47
48def setup(api: PythonApi) -> dict[str, object]:
49    global host
50    host = api.host
51    return {"mail": Mail(), "MailError": api.HostError}