generateAnnotationsExpression function

String generateAnnotationsExpression(
  1. Map<String, dynamic> tool
)

Generates the ToolAnnotations expression for a tool, or empty string if none.

Implementation

String generateAnnotationsExpression(Map<String, dynamic> tool) {
  final annotations = tool['annotations'] as Map<String, dynamic>?;
  if (annotations == null || annotations.isEmpty) return '';

  final parts = <String>[];
  if (annotations.containsKey('title')) {
    parts.add("title: '${escapeDartString(annotations['title'] as String)}'");
  }
  if (annotations.containsKey('readOnlyHint')) {
    parts.add('readOnlyHint: ${annotations['readOnlyHint']}');
  }
  if (annotations.containsKey('destructiveHint')) {
    parts.add('destructiveHint: ${annotations['destructiveHint']}');
  }
  if (annotations.containsKey('idempotentHint')) {
    parts.add('idempotentHint: ${annotations['idempotentHint']}');
  }
  if (annotations.containsKey('openWorldHint')) {
    parts.add('openWorldHint: ${annotations['openWorldHint']}');
  }

  if (parts.isEmpty) return '';
  return '\n        annotations: ToolAnnotations(${parts.join(', ')}),';
}