BidiGenerateContentServerMessage.fromJson constructor

BidiGenerateContentServerMessage.fromJson(
  1. Map<String, dynamic> json
)

Creates a message from JSON.

Dispatches to the appropriate subclass based on the JSON key.

Implementation

factory BidiGenerateContentServerMessage.fromJson(Map<String, dynamic> json) {
  if (json.containsKey('setupComplete')) {
    return BidiGenerateContentSetupComplete.fromJson(
      json['setupComplete'] as Map<String, dynamic>,
    );
  }
  if (json.containsKey('serverContent')) {
    return BidiGenerateContentServerContent.fromJson(
      json['serverContent'] as Map<String, dynamic>,
    );
  }
  if (json.containsKey('toolCall')) {
    return BidiGenerateContentToolCall.fromJson(
      json['toolCall'] as Map<String, dynamic>,
    );
  }
  if (json.containsKey('toolCallCancellation')) {
    return BidiGenerateContentToolCallCancellation.fromJson(
      json['toolCallCancellation'] as Map<String, dynamic>,
    );
  }
  if (json.containsKey('goAway')) {
    return GoAway.fromJson(json['goAway'] as Map<String, dynamic>);
  }
  if (json.containsKey('sessionResumptionUpdate')) {
    return SessionResumptionUpdate.fromJson(
      json['sessionResumptionUpdate'] as Map<String, dynamic>,
    );
  }
  // Return unknown message type instead of throwing to handle
  // future API additions gracefully
  return UnknownServerMessage(json);
}