Something went wrong. Try again.
small gleam coding and (not yet) persistent agent daemon with a detachable cli
Something went wrong. Try again.
1.7 kB · 45 lines
Python
12345678910111213141516171819202122232425262728293031323334353637383940414243444546from __future__ import annotations
from albedo_api import Host, PythonApi, Recordfrom typing import cast
class WorkItem(Record): """One ledger item: item.id and item["id"] both work.""" id: int title: str notes: str status: str parent: int | None session: str | None run: str | None revision: int
host: Host
class Work: async def list(self, after: int = 0, limit: int = 50) -> list[WorkItem]: return [WorkItem(item) for item in cast(list[dict], await host("work.list", {"after": after, "limit": limit}))]
async def get(self, id: int) -> WorkItem: return WorkItem(cast(dict, await host("work.get", {"id": id})))
async def create(self, title: str, notes: str = "", parent: int | None = None) -> WorkItem: return WorkItem(cast(dict, await host("work.create", {"title": title, "notes": notes, "parent": parent})))
async def update(self, id: int, *, revision: int, **changes: object) -> WorkItem: allowed = {"title", "notes", "status", "session", "run"} if changes.keys() - allowed: raise ValueError("unknown work fields: " + repr(changes.keys() - allowed)) return WorkItem(cast(dict, await host("work.update", {"id": id, "revision": revision, **changes})))
async def delete(self, id: int, *, revision: int) -> WorkItem: """Remove an item at the revision you last read; one with sub-items stays.""" return WorkItem(cast(dict, await host("work.delete", {"id": id, "revision": revision})))
def setup(api: PythonApi) -> dict[str, object]: global host host = api.host return {"work": Work(), "WorkError": api.HostError}