getToolUseInfo function

ToolUseInfo? getToolUseInfo(
  1. NormalizedMessage msg
)

Extract tool use info from a normalized message.

Implementation

ToolUseInfo? getToolUseInfo(NormalizedMessage msg) {
  if (msg.type != 'assistant') return null;

  final content = msg.message['content'];
  if (content is! List || content.isEmpty) return null;

  final firstBlock = content[0];
  if (firstBlock is! Map<String, dynamic>) return null;
  if (firstBlock['type'] != 'tool_use') return null;

  return ToolUseInfo(
    messageId: msg.message['id'] as String? ?? '',
    toolUseId: firstBlock['id'] as String? ?? '',
    toolName: firstBlock['name'] as String? ?? '',
  );
}