In-memory message data for virtualization. This dataclass holds all information needed to recreate a message widget. It is designed to be lightweight so that thousands of messages can be stored without meaningful memory overhead.
| 93 | |
| 94 | @dataclass |
| 95 | class MessageData: |
| 96 | """In-memory message data for virtualization. |
| 97 | |
| 98 | This dataclass holds all information needed to recreate a message widget. |
| 99 | It is designed to be lightweight so that thousands of messages can be |
| 100 | stored without meaningful memory overhead. |
| 101 | """ |
| 102 | |
| 103 | type: MessageType |
| 104 | """The kind of message (user, assistant, tool, etc.).""" |
| 105 | |
| 106 | content: str |
| 107 | """Primary text content of the message. |
| 108 | |
| 109 | For most message types this is the display text. For TOOL messages it is |
| 110 | typically empty because the tool's identity comes from `tool_name` / |
| 111 | `tool_args` instead. |
| 112 | """ |
| 113 | |
| 114 | id: str = field(default_factory=lambda: f"msg-{uuid.uuid4().hex}") |
| 115 | """Unique identifier used to match the dataclass to its DOM widget. |
| 116 | |
| 117 | Uses the full 128-bit `uuid4` hex (not a truncated prefix) so IDs stay |
| 118 | unique across large histories and long sessions; a widget-ID collision |
| 119 | raises `DuplicateIds` when the widget is mounted. |
| 120 | """ |
| 121 | |
| 122 | timestamp: float = field(default_factory=time) |
| 123 | """Unix epoch timestamp of when the message was created.""" |
| 124 | |
| 125 | # TOOL message fields - only populated for TOOL messages |
| 126 | tool_name: str | None = None |
| 127 | """Name of the tool that was called.""" |
| 128 | |
| 129 | tool_args: dict[str, Any] | None = None |
| 130 | """Arguments passed to the tool call.""" |
| 131 | |
| 132 | tool_status: ToolStatus | None = None |
| 133 | """Current execution status of the tool call.""" |
| 134 | |
| 135 | tool_output: str | None = None |
| 136 | """Output returned by the tool after execution.""" |
| 137 | |
| 138 | tool_expanded: bool = False |
| 139 | """Whether the tool output section is expanded in the UI.""" |
| 140 | |
| 141 | tool_reject_reason: str | None = None |
| 142 | """User-supplied reason attached to a HITL reject decision (if any).""" |
| 143 | |
| 144 | # --- |
| 145 | |
| 146 | diff_file_path: str | None = None |
| 147 | """File path associated with the diff (DIFF messages only).""" |
| 148 | |
| 149 | # SKILL message fields - only populated for SKILL messages |
| 150 | skill_name: str | None = None |
| 151 | """Name of the skill that was invoked.""" |
| 152 |
no outgoing calls