|
| 1 | +import datetime as dt |
| 2 | +from typing import ClassVar, Optional |
| 3 | + |
| 4 | +from cuenca_validations.types import AgentQuery, AgentRequest, PhoneNumber |
| 5 | +from cuenca_validations.typing import DictStrAny |
| 6 | +from pydantic import ConfigDict, Field |
| 7 | + |
| 8 | +from ..http import Session, session as global_session |
| 9 | +from .base import Creatable, Queryable |
| 10 | + |
| 11 | + |
| 12 | +class Agent(Creatable, Queryable): |
| 13 | + _resource: ClassVar = 'agents' |
| 14 | + _query_params: ClassVar = AgentQuery |
| 15 | + |
| 16 | + created_at: dt.datetime |
| 17 | + user_id: str |
| 18 | + platform_id: str |
| 19 | + agent_verification_id: str |
| 20 | + session_id: str |
| 21 | + device_info: DictStrAny = Field(default_factory=dict) |
| 22 | + deactivated_at: Optional[dt.datetime] = None |
| 23 | + |
| 24 | + model_config = ConfigDict( |
| 25 | + json_schema_extra={ |
| 26 | + 'example': { |
| 27 | + 'id': 'AG1G6Bm0oGQOCRjTDaeFSsyA', |
| 28 | + 'created_at': '2026-06-27T01:56:42.613781', |
| 29 | + 'user_id': 'USMP3EPgI4T4CPFyVmXUPi8A', |
| 30 | + 'platform_id': 'PTZbBlk__kQt-wfwzP5nwA9A', |
| 31 | + 'agent_verification_id': 'AV7A1FLC7MSnqKcb7oAkiQxA', |
| 32 | + 'session_id': 'SSH0M5yteyRHas-PmfT9pu9w', |
| 33 | + 'device_info': {'client': 'cursor', 'os': 'macOS'}, |
| 34 | + } |
| 35 | + } |
| 36 | + ) |
| 37 | + |
| 38 | + @classmethod |
| 39 | + def create( |
| 40 | + cls, |
| 41 | + pairing_code: str, |
| 42 | + phone_number: PhoneNumber, |
| 43 | + device_info: Optional[DictStrAny] = None, |
| 44 | + *, |
| 45 | + session: Session = global_session, |
| 46 | + ) -> 'Agent': |
| 47 | + req = AgentRequest( |
| 48 | + pairing_code=pairing_code, |
| 49 | + phone_number=phone_number, |
| 50 | + device_info=device_info or {}, |
| 51 | + ) |
| 52 | + return cls._create(session=session, **req.model_dump()) |
0 commit comments