|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from types import SimpleNamespace |
| 4 | +from typing import Any, Dict, List, Optional |
| 5 | + |
| 6 | + |
| 7 | +def dump_model(value: Any) -> Any: |
| 8 | + if hasattr(value, "model_dump"): |
| 9 | + return value.model_dump(exclude_none=True) |
| 10 | + if isinstance(value, dict): |
| 11 | + return {k: dump_model(v) for k, v in value.items()} |
| 12 | + if isinstance(value, list): |
| 13 | + return [dump_model(v) for v in value] |
| 14 | + return value |
| 15 | + |
| 16 | + |
| 17 | +class DummyAgents: |
| 18 | + def __init__(self) -> None: |
| 19 | + self.start_calls: List[Any] = [] |
| 20 | + self.stop_calls: List[Any] = [] |
| 21 | + self.speak_calls: List[Any] = [] |
| 22 | + self.interrupt_calls: List[Any] = [] |
| 23 | + self.update_calls: List[Any] = [] |
| 24 | + self.history_calls: List[Any] = [] |
| 25 | + self.turn_calls: List[Any] = [] |
| 26 | + self.get_calls: List[Any] = [] |
| 27 | + |
| 28 | + self.start_result: Any = SimpleNamespace(agent_id="agent-1") |
| 29 | + self.start_error: Optional[Exception] = None |
| 30 | + self.stop_error: Optional[Exception] = None |
| 31 | + |
| 32 | + def start(self, app_id, **kwargs): |
| 33 | + self.start_calls.append((app_id, kwargs)) |
| 34 | + if self.start_error is not None: |
| 35 | + raise self.start_error |
| 36 | + return self.start_result |
| 37 | + |
| 38 | + def stop(self, app_id, agent_id, request_options=None): |
| 39 | + self.stop_calls.append((app_id, agent_id, request_options)) |
| 40 | + if self.stop_error is not None: |
| 41 | + raise self.stop_error |
| 42 | + return None |
| 43 | + |
| 44 | + def speak(self, app_id, agent_id, request_options=None, **kwargs): |
| 45 | + self.speak_calls.append((app_id, agent_id, request_options, kwargs)) |
| 46 | + return None |
| 47 | + |
| 48 | + def interrupt(self, app_id, agent_id, request_options=None): |
| 49 | + self.interrupt_calls.append((app_id, agent_id, request_options)) |
| 50 | + return None |
| 51 | + |
| 52 | + def update(self, app_id, agent_id, properties=None, request_options=None): |
| 53 | + self.update_calls.append((app_id, agent_id, properties, request_options)) |
| 54 | + return None |
| 55 | + |
| 56 | + def get_history(self, app_id, agent_id, request_options=None): |
| 57 | + self.history_calls.append((app_id, agent_id, request_options)) |
| 58 | + return {"contents": []} |
| 59 | + |
| 60 | + def get_turns(self, app_id, agent_id, request_options=None): |
| 61 | + self.turn_calls.append((app_id, agent_id, request_options)) |
| 62 | + return {"turns": [{"agent_id": agent_id}]} |
| 63 | + |
| 64 | + def get(self, app_id, agent_id, request_options=None): |
| 65 | + self.get_calls.append((app_id, agent_id, request_options)) |
| 66 | + return {"agent_id": agent_id} |
| 67 | + |
| 68 | + |
| 69 | +class DummyAsyncAgents(DummyAgents): |
| 70 | + async def start(self, app_id, **kwargs): |
| 71 | + return super().start(app_id, **kwargs) |
| 72 | + |
| 73 | + async def stop(self, app_id, agent_id, request_options=None): |
| 74 | + return super().stop(app_id, agent_id, request_options) |
| 75 | + |
| 76 | + async def speak(self, app_id, agent_id, request_options=None, **kwargs): |
| 77 | + return super().speak(app_id, agent_id, request_options, **kwargs) |
| 78 | + |
| 79 | + async def interrupt(self, app_id, agent_id, request_options=None): |
| 80 | + return super().interrupt(app_id, agent_id, request_options) |
| 81 | + |
| 82 | + async def update(self, app_id, agent_id, properties=None, request_options=None): |
| 83 | + return super().update(app_id, agent_id, properties, request_options) |
| 84 | + |
| 85 | + async def get_history(self, app_id, agent_id, request_options=None): |
| 86 | + return super().get_history(app_id, agent_id, request_options) |
| 87 | + |
| 88 | + async def get_turns(self, app_id, agent_id, request_options=None): |
| 89 | + return super().get_turns(app_id, agent_id, request_options) |
| 90 | + |
| 91 | + async def get(self, app_id, agent_id, request_options=None): |
| 92 | + return super().get(app_id, agent_id, request_options) |
| 93 | + |
| 94 | + |
| 95 | +class DummyClient: |
| 96 | + def __init__( |
| 97 | + self, |
| 98 | + *, |
| 99 | + auth_mode: str = "basic", |
| 100 | + app_id: str = "app-id", |
| 101 | + app_certificate: Optional[str] = "app-cert", |
| 102 | + ) -> None: |
| 103 | + self.app_id = app_id |
| 104 | + self.app_certificate = app_certificate |
| 105 | + self.auth_mode = auth_mode |
| 106 | + self.agents = DummyAgents() |
| 107 | + |
| 108 | + |
| 109 | +class DummyAsyncClient(DummyClient): |
| 110 | + def __init__(self, **kwargs: Any) -> None: |
| 111 | + super().__init__(**kwargs) |
| 112 | + self.agents = DummyAsyncAgents() |
0 commit comments