getFilePathsFromReadMessage static method

List<String> getFilePathsFromReadMessage(
  1. RenderableMessage msg
)

Extract file paths from read tool inputs in a message.

Implementation

static List<String> getFilePathsFromReadMessage(RenderableMessage msg) {
  final paths = <String>[];
  if (msg.type == 'assistant') {
    final content = msg.message?.content;
    if (content != null && content.isNotEmpty) {
      final first = content.first;
      if (first['type'] == 'tool_use') {
        final filePath = (first['input'] as Map?)?['file_path'] as String?;
        if (filePath != null) paths.add(filePath);
      }
    }
  } else if (msg.type == 'grouped_tool_use' && msg.messages != null) {
    for (final m in msg.messages!) {
      final content = m.message?.content;
      if (content != null && content.isNotEmpty) {
        final first = content.first;
        if (first['type'] == 'tool_use') {
          final filePath = (first['input'] as Map?)?['file_path'] as String?;
          if (filePath != null) paths.add(filePath);
        }
      }
    }
  }
  return paths;
}