parseAttachment function

Attachment? parseAttachment(
  1. Map<String, dynamic> json
)

Normalize an attachment map into the typed attachment.

Implementation

Attachment? parseAttachment(Map<String, dynamic> json) {
  final type = json['type'] as String?;
  return switch (type) {
    'file' => FileAttachment(
      filename: json['filename'] as String,
      content: json['content'] as String? ?? '',
      truncated: json['truncated'] as bool? ?? false,
      displayPath: json['displayPath'] as String? ?? json['filename'] as String,
    ),
    'compact_file_reference' => CompactFileReferenceAttachment(
      filename: json['filename'] as String,
      displayPath: json['displayPath'] as String? ?? json['filename'] as String,
    ),
    'pdf_reference' => PDFReferenceAttachment(
      filename: json['filename'] as String,
      pageCount: json['pageCount'] as int? ?? 0,
      fileSize: json['fileSize'] as int? ?? 0,
      displayPath: json['displayPath'] as String? ?? json['filename'] as String,
    ),
    'directory' => DirectoryAttachment(
      path: json['path'] as String,
      content: json['content'] as String? ?? '',
      displayPath: json['displayPath'] as String? ?? json['path'] as String,
    ),
    'queued_command' => QueuedCommandAttachment(
      prompt: json['prompt'],
      sourceUuid: json['source_uuid'] as String?,
      commandMode: json['commandMode'] as String?,
    ),
    'output_style' => OutputStyleAttachment(style: json['style'] as String),
    'date_change' => DateChangeAttachment(newDate: json['newDate'] as String),
    _ => null,
  };
}