Result of a command execution.
| 28 | |
| 29 | @dataclass |
| 30 | class CommandResult: |
| 31 | """Result of a command execution.""" |
| 32 | |
| 33 | success: bool |
| 34 | command_name: str |
| 35 | result_type: str = "text" # "text" | "prompt" | "skip" |
| 36 | text: str = "" |
| 37 | prompt_content: list[dict[str, Any]] = field(default_factory=list) |
| 38 | should_query: bool = False |
| 39 | display: str = "system" # "skip" | "system" | "user" |
| 40 | meta_messages: list[str] = field(default_factory=list) |
| 41 | error: Optional[str] = None |
| 42 | |
| 43 | @classmethod |
| 44 | def success_text(cls, command_name: str, text: str) -> "CommandResult": |
| 45 | """Create a successful text result.""" |
| 46 | return cls( |
| 47 | success=True, |
| 48 | command_name=command_name, |
| 49 | result_type="text", |
| 50 | text=text, |
| 51 | display="system", |
| 52 | ) |
| 53 | |
| 54 | @classmethod |
| 55 | def success_prompt( |
| 56 | cls, |
| 57 | command_name: str, |
| 58 | prompt_content: list[dict[str, Any]], |
| 59 | should_query: bool = True, |
| 60 | ) -> "CommandResult": |
| 61 | """Create a successful prompt result.""" |
| 62 | return cls( |
| 63 | success=True, |
| 64 | command_name=command_name, |
| 65 | result_type="prompt", |
| 66 | prompt_content=prompt_content, |
| 67 | should_query=should_query, |
| 68 | display="user", |
| 69 | ) |
| 70 | |
| 71 | @classmethod |
| 72 | def error(cls, command_name: str, error: str) -> "CommandResult": |
| 73 | """Create an error result.""" |
| 74 | return cls( |
| 75 | success=False, |
| 76 | command_name=command_name, |
| 77 | result_type="text", |
| 78 | text=f"Error: {error}", |
| 79 | error=error, |
| 80 | display="system", |
| 81 | ) |
| 82 | |
| 83 | @classmethod |
| 84 | def skip(cls, command_name: str) -> "CommandResult": |
| 85 | """Create a skip result.""" |
| 86 | return cls( |
| 87 | success=True, |
no outgoing calls
no test coverage detected