MCPcopy Create free account
hub / github.com/langchain-ai/deepagents / UserMessage

Class UserMessage

libs/code/deepagents_code/widgets/messages.py:208–316  ·  view source on GitHub ↗

Widget displaying a user message.

Source from the content-addressed store, hash-verified

206
207
208class UserMessage(Static):
209 """Widget displaying a user message."""
210
211 DEFAULT_CSS = """
212 UserMessage {
213 height: auto;
214 padding: 0 1;
215 margin: 0 0 1 0;
216 background: transparent;
217 border-left: wide $primary;
218 pointer: text;
219 }
220
221 UserMessage.-cancelled {
222 opacity: 0.6;
223 }
224 """
225 """`-cancelled` dims a prompt whose turn was interrupted by the user."""
226
227 def __init__(self, content: str, **kwargs: Any) -> None:
228 """Initialize a user message.
229
230 Args:
231 content: The message content
232 **kwargs: Additional arguments passed to parent
233 """
234 super().__init__(**kwargs)
235 self._content = content
236
237 def set_cancelled(self) -> None:
238 """Dim the message to mark its turn as interrupted by the user."""
239 self.add_class("-cancelled")
240
241 def get_selection(self, selection: Selection) -> tuple[str, str] | None:
242 """Exclude the prompt prefix glyph from copied text.
243
244 Args:
245 selection: The active selection geometry.
246
247 Returns:
248 The `(text, ending)` selection with the prefix removed, or `None`.
249 """
250 return _strip_prompt_prefix(super().get_selection(selection), selection)
251
252 def text_select_all(self) -> None:
253 """Select the message body without the prompt prefix glyph."""
254 _select_prompt_body(self)
255
256 def on_mount(self) -> None:
257 """Add CSS classes for mode-specific border and ASCII border type."""
258 mode_match = detect_mode_prefix(self._content)
259 if mode_match:
260 _prefix, mode = mode_match
261 self.add_class(f"-mode-{mode.replace('_', '-')}")
262 if is_ascii_mode():
263 self.add_class("-ascii")
264
265 def render(self) -> Content:

Callers 15

_handle_shell_commandMethod · 0.90
_mount_outputMethod · 0.90
_open_url_commandMethod · 0.90
_handle_trace_commandMethod · 0.90
_handle_goal_commandMethod · 0.90
_handle_commandMethod · 0.90
_mount_errorMethod · 0.90

Calls

no outgoing calls