parse static method

FunctionCallResponse? parse(
  1. String text, {
  2. ModelType? modelType,
})

Parse function call based on model type Uses explicit ModelType routing - no fallback chains

Implementation

static FunctionCallResponse? parse(String text, {ModelType? modelType}) {
  if (text.trim().isEmpty) return null;

  try {
    final content = _cleanModelResponse(text);

    // Explicit routing by model type using Dart 3 switch expression
    return switch (modelType) {
      ModelType.functionGemma => _parseFunctionGemmaCall(content),
      // All other models use JSON-based formats
      _ => _parseToolCodeBlock(content) ??
           _parseMarkdownBlock(content) ??
           _parseDirectJson(content),
    };
  } catch (e) {
    debugPrint('FunctionCallParser: Error parsing function call: $e');
    return null;
  }
}