|
| 1 | +from __future__ import annotations |
| 2 | +from datetime import datetime |
| 3 | +from enum import Enum |
| 4 | +from typing import Literal, Optional |
| 5 | + |
| 6 | +from pydantic import BaseModel |
| 7 | + |
| 8 | + |
| 9 | +class ApprovalActor(BaseModel): |
| 10 | + id: str |
| 11 | + type: str = Literal["user", "agent", "tool"] |
| 12 | + on_behalf_of: ApprovalActor | None = None |
| 13 | + |
| 14 | + |
| 15 | +class ApprovalEffect(str, Enum): |
| 16 | + allow = "allow" |
| 17 | + deny = "deny" |
| 18 | + challenge = "challenge" |
| 19 | + |
| 20 | + |
| 21 | +ApprovalAction = str |
| 22 | +ApprovalResource = str |
| 23 | + |
| 24 | + |
| 25 | +class ApprovalGrant(BaseModel): |
| 26 | + """Effect the actions on the resources to the grantee by the grantor until the expiration.""" |
| 27 | + |
| 28 | + effect: Literal[ApprovalEffect.allow, ApprovalEffect.deny] |
| 29 | + """Whether to grant an allow or deny.""" |
| 30 | + actions: list[ApprovalAction] |
| 31 | + """The actions to which the grant will effect.""" |
| 32 | + resources: list[ApprovalResource] |
| 33 | + """The resources that this grant affects.""" |
| 34 | + grantee: ApprovalActor |
| 35 | + """Who the grant applies to.""" |
| 36 | + grantor: ApprovalActor |
| 37 | + """The permission holder that granted toe access (e.g. user, or delegated by a parent agent).""" |
| 38 | + expiration_time: Optional[datetime] = None # Optional expiration time |
| 39 | + """The time after which the grant ceases to be valid.""" |
| 40 | + |
| 41 | + comment: Optional[str] = None |
| 42 | + """Comment from the grantor (typically the end user) from the point of granting. This is used when communicating a grant update to a model, for example a deny, to explain the reason.""" |
0 commit comments