getToolUseIdsFromMessage static method

List<String> getToolUseIdsFromMessage(
  1. RenderableMessage msg
)

Get all tool use IDs from a single message.

Implementation

static List<String> getToolUseIdsFromMessage(RenderableMessage msg) {
  if (msg.type == 'assistant') {
    final content = msg.message?.content;
    if (content != null && content.isNotEmpty) {
      final first = content.first;
      if (first['type'] == 'tool_use' && first['id'] != null) {
        return [first['id'] as String];
      }
    }
  }
  if (msg.type == 'grouped_tool_use' && msg.messages != null) {
    return msg.messages!
        .map((m) {
          final c = m.message?.content;
          if (c != null && c.isNotEmpty && c.first['type'] == 'tool_use') {
            return c.first['id'] as String?;
          }
          return null;
        })
        .whereType<String>()
        .toList();
  }
  return [];
}