import 'package:flutter/foundation.dart'; enum CopilotRole { user, assistant } class CopilotImage { final String base64; final String source; final int page; final String? fileLink; final double? similarityScore; CopilotImage({ required this.base64, required this.source, required this.page, this.fileLink, this.similarityScore, }); factory CopilotImage.fromJson(Map json) => CopilotImage( base64: json['image_base64'] ?? '', source: json['source'] ?? '', page: json['page'] is int ? json['page'] : int.tryParse('${json['page']}') ?? 0, fileLink: json['file_link'], similarityScore: (json['similarity_score'] as num?)?.toDouble(), ); } class CopilotMessage { final String id; final CopilotRole role; String content; String? documentAnswer; String? websiteAnswer; List images; DateTime? timestamp; bool isStreaming; bool isError; String? localAudioPath; String? localImagePath; List ttsAudioClips; CopilotMessage({ required this.id, required this.role, this.content = '', this.documentAnswer, this.websiteAnswer, this.images = const [], this.timestamp, this.isStreaming = false, this.isError = false, this.localAudioPath, this.localImagePath, List? ttsAudioClips, }) : ttsAudioClips = ttsAudioClips ?? []; factory CopilotMessage.fromHistoryJson(Map json) => CopilotMessage( id: UniqueKey().toString(), role: json['role'] == 'ai' ? CopilotRole.assistant : CopilotRole.user, content: json['content'] ?? '', documentAnswer: json['document_answer'], websiteAnswer: json['website_answer'], images: (json['images'] as List? ?? []).map((e) => CopilotImage.fromJson(e)).toList(), timestamp: json['timestamp'] != null ? (DateTime.tryParse(json['timestamp'].toString()) ?? DateTime.now()) : DateTime.now(), ); } class CopilotStreamEvent { final String type; final CopilotStreamContent? content; final String? transcriptionContent; CopilotStreamEvent({required this.type, this.content, this.transcriptionContent}); factory CopilotStreamEvent.fromJson(Map json) => CopilotStreamEvent( type: json['type'] ?? '', content: json['content'] is Map ? CopilotStreamContent.fromJson(json['content']) : null, transcriptionContent: json['content'] is String ? json['content'] : null, ); } class CopilotStreamContent { final String? answer; final String? documentAnswer; final String? websiteAnswer; final int? chunksUsed; final List images; CopilotStreamContent({ this.answer, this.documentAnswer, this.websiteAnswer, this.chunksUsed, this.images = const [], }); factory CopilotStreamContent.fromJson(Map json) => CopilotStreamContent( answer: json['answer'], documentAnswer: json['document_answer'], websiteAnswer: json['website_answer'], chunksUsed: json['chunks_used'], images: (json['images'] as List? ?? []).map((e) => CopilotImage.fromJson(e)).toList(), ); } class CopilotHistoryItem { final String threadId; final String firstHumanMessage; final String updatedAt; CopilotHistoryItem({ required this.threadId, required this.firstHumanMessage, required this.updatedAt, }); factory CopilotHistoryItem.fromJson(Map json) => CopilotHistoryItem( threadId: json['threadId'] ?? '', firstHumanMessage: json['firstHumanMessage'] ?? '', updatedAt: json['updatedAt'] ?? '', ); }