attachedRowFromMessage function

AttachedMessage? attachedRowFromMessage(
  1. Message message
)

Renders one conversation Message as an attached-view row, or null for content the view skips (tool results, empty rows).

Implementation

AttachedMessage? attachedRowFromMessage(Message message) {
  switch (message) {
    case UserMessage():
      final text = _textOf(message.content);
      if (text == null) return null; // tool results arrive as user rows
      return AttachedMessage(role: AttachedMessageRole.user, text: text);
    case AssistantMessage():
      final text = _textOf(message.content);
      if (text != null && text.isNotEmpty) {
        return AttachedMessage(role: AttachedMessageRole.assistant, text: text);
      }
      final toolName = _toolNameOf(message.content);
      if (toolName != null) {
        return AttachedMessage(
          role: AttachedMessageRole.tool,
          text: '',
          toolName: toolName,
        );
      }
      return null;
    default:
      return null;
  }
}