okami.mom/albedo

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

nekomimi.petFormat Python sources and remove root HTML diagram59d7370

main
1.5 KiB63 linesraw
1from typing import cast
2
3from albedo_api import Host, PythonApi, Record
4
5
6class SkillResources(Record):
7    """resources.resources and resources["resources"] both work."""
8
9    resources: list[str]
10    truncated: bool
11    diagnostics: list[str]
12
13
14class SkillPage(Record):
15    """page.content and page["content"] both work."""
16
17    path: str
18    encoding: str
19    content: str
20    next_offset: int
21    truncated: bool
22    size: int
23
24
25host: Host
26
27
28class Skills:
29    async def resources(self, name: str) -> SkillResources:
30        """List resource names without reading or executing their contents."""
31        return SkillResources(
32            cast(dict, await host("skills.resources", {"name": name}))
33        )
34
35    async def read(
36        self,
37        name: str,
38        resource: str = "SKILL.md",
39        *,
40        offset: int = 0,
41        limit: int = 16_384,
42    ) -> SkillPage:
43        """Read one bounded page from a cataloged skill resource."""
44        return SkillPage(
45            cast(
46                dict,
47                await host(
48                    "skills.read",
49                    {
50                        "name": name,
51                        "resource": resource,
52                        "offset": offset,
53                        "limit": limit,
54                    },
55                ),
56            )
57        )
58
59
60def setup(api: PythonApi) -> dict[str, object]:
61    global host
62    host = api.host
63    return {"skills": Skills(), "SkillsError": api.HostError}