projectionCopyChatMessageMetadataWithGuard function

Map<String, Object?> projectionCopyChatMessageMetadataWithGuard(
  1. Map<String, Object?> metadata,
  2. ChatInputBudget budget,
  3. ChatStructuredUpdateGuard guard
)

Implementation

Map<String, Object?> projectionCopyChatMessageMetadataWithGuard(
  Map<String, Object?> metadata,
  acp.ChatInputBudget budget,
  acp.ChatStructuredUpdateGuard guard,
) {
  final snapshot = projectionSnapshotChatMessageMetadata(metadata, budget);
  final stableMetadata = snapshot.metadata;
  if (stableMetadata == null) {
    throw const FormatException('Invalid session event metadata.');
  }
  if (snapshot.limit case final limit?) throw limit;
  if (_isRecognizedTypedConfigUpdateMetadata(stableMetadata)) {
    final typed = _copyTypedConfigUpdateMetadata(
      stableMetadata,
      budget,
      structuredGuard: guard,
    );
    if (typed == null) {
      throw const FormatException('Invalid typed session event metadata.');
    }
    return typed;
  }
  return guard.copyMetadata(stableMetadata, field: 'event metadata');
}