okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
4ad84fd
main
1from __future__import annotations 2 3import builtins 4from typing import cast 5from albedo_api import Host ,PythonApi ,Record 6 7 8class Hook (Record ): 9id :str 10session :str 11name :str 12enabled :bool 13url :str 14signatureHeader :str 15signaturePrefix :str 16revision :int 17 18 19host :Host 20 21 22class Webhooks : 23async def list (self )-> builtins .list [Hook ]: 24"""Hooks targeting this session. Agent management requires human opt-in.""" 25return [ 26Hook (item ) 27for item in cast (builtins .list [dict ],await host ("webhooks.list" , {})) 28 ] 29 30async def delivery (self ,id :str )-> Record : 31"""Read one accepted payload for this session, even without management permission.""" 32return Record (cast (dict ,await host ("webhooks.delivery" , {"id" :id }))) 33 34async def create (self ,name :str ,secret :str | None = None )-> Record : 35"""Create a signed endpoint; returns a generated secret when omitted.""" 36value = cast ( 37dict ,await host ("webhooks.create" , {"name" :name ,"secret" :secret }) 38 ) 39return Record ({"hook" :Hook (value ["hook" ]),"secret" :value ["secret" ]}) 40 41async def rotate ( 42self ,id :str ,* ,revision :int ,secret :str | None = None 43 )-> Record : 44value = cast ( 45dict , 46await host ( 47"webhooks.rotate" , {"id" :id ,"revision" :revision ,"secret" :secret } 48 ), 49 ) 50return Record ({"hook" :Hook (value ["hook" ]),"secret" :value ["secret" ]}) 51 52async def configure ( 53self ,id :str ,* ,revision :int ,header :str ,prefix :str = "sha256=" 54 )-> Hook : 55return Hook ( 56cast ( 57dict , 58await host ( 59"webhooks.configure" , 60 { 61"id" :id , 62"revision" :revision , 63"header" :header , 64"prefix" :prefix , 65 }, 66 ), 67 ) 68 ) 69 70async def enable (self ,id :str ,* ,revision :int )-> Hook : 71return Hook ( 72cast (dict ,await host ("webhooks.enable" , {"id" :id ,"revision" :revision })) 73 ) 74 75async def disable (self ,id :str ,* ,revision :int )-> Hook : 76return Hook ( 77cast (dict ,await host ("webhooks.disable" , {"id" :id ,"revision" :revision })) 78 ) 79 80async def delete (self ,id :str ,* ,revision :int )-> Hook : 81return Hook ( 82cast (dict ,await host ("webhooks.delete" , {"id" :id ,"revision" :revision })) 83 ) 84 85 86def setup (api :PythonApi )-> dict [str ,object ]: 87global host 88host = api .host 89return {"webhooks" :Webhooks (),"WebhookError" :api .HostError }