diff --git a/apps/lib/features/chat/data/models/tool_result.dart b/apps/lib/features/chat/data/models/tool_result.dart new file mode 100644 index 0000000..a2298e7 --- /dev/null +++ b/apps/lib/features/chat/data/models/tool_result.dart @@ -0,0 +1,94 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'tool_result.g.dart'; + +/// 工具执行结果(给 AI 的原始数据) +@JsonSerializable() +class ToolResult { + final String? eventId; + final bool ok; + final String? message; + + ToolResult({this.eventId, this.ok = true, this.message}); + + factory ToolResult.fromJson(Map json) => + _$ToolResultFromJson(json); + + Map toJson() => _$ToolResultToJson(this); +} + +/// UI 卡片 Schema(给 UI 渲染) +@JsonSerializable() +class UiCard { + @JsonKey(name: 'type') + final String cardType; + + @JsonKey(name: 'version') + final String? schemaVersion; + + final Map data; + final List? actions; + + UiCard({ + required this.cardType, + this.schemaVersion = 'v1', + required this.data, + this.actions, + }); + + factory UiCard.fromJson(Map json) => _$UiCardFromJson(json); + + Map toJson() => _$UiCardToJson(this); +} + +/// 卡片操作按钮 +@JsonSerializable() +class CardAction { + final String type; + final String label; + final String? target; + final String? action; + + CardAction({ + required this.type, + required this.label, + this.target, + this.action, + }); + + factory CardAction.fromJson(Map json) => + _$CardActionFromJson(json); + + Map toJson() => _$CardActionToJson(this); +} + +/// 日历卡片数据 +@JsonSerializable() +class CalendarCardData { + final String id; + final String title; + final String? description; + final String startAt; + final String? endAt; + final String? timezone; + final String? location; + final String? color; + final String? sourceType; + + CalendarCardData({ + required this.id, + required this.title, + this.description, + required this.startAt, + this.endAt, + this.timezone, + this.location, + this.color, + this.sourceType, + }); + + factory CalendarCardData.fromJson(Map json) => + _$CalendarCardDataFromJson(json); + + Map toJson() => _$CalendarCardDataToJson(this); +} diff --git a/apps/lib/features/chat/data/models/tool_result.g.dart b/apps/lib/features/chat/data/models/tool_result.g.dart new file mode 100644 index 0000000..c5f4e03 --- /dev/null +++ b/apps/lib/features/chat/data/models/tool_result.g.dart @@ -0,0 +1,77 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'tool_result.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ToolResult _$ToolResultFromJson(Map json) => ToolResult( + eventId: json['eventId'] as String?, + ok: json['ok'] as bool? ?? true, + message: json['message'] as String?, +); + +Map _$ToolResultToJson(ToolResult instance) => + { + 'eventId': instance.eventId, + 'ok': instance.ok, + 'message': instance.message, + }; + +UiCard _$UiCardFromJson(Map json) => UiCard( + cardType: json['type'] as String, + schemaVersion: json['version'] as String? ?? 'v1', + data: json['data'] as Map, + actions: (json['actions'] as List?) + ?.map((e) => CardAction.fromJson(e as Map)) + .toList(), +); + +Map _$UiCardToJson(UiCard instance) => { + 'type': instance.cardType, + 'version': instance.schemaVersion, + 'data': instance.data, + 'actions': instance.actions, +}; + +CardAction _$CardActionFromJson(Map json) => CardAction( + type: json['type'] as String, + label: json['label'] as String, + target: json['target'] as String?, + action: json['action'] as String?, +); + +Map _$CardActionToJson(CardAction instance) => + { + 'type': instance.type, + 'label': instance.label, + 'target': instance.target, + 'action': instance.action, + }; + +CalendarCardData _$CalendarCardDataFromJson(Map json) => + CalendarCardData( + id: json['id'] as String, + title: json['title'] as String, + description: json['description'] as String?, + startAt: json['startAt'] as String, + endAt: json['endAt'] as String?, + timezone: json['timezone'] as String?, + location: json['location'] as String?, + color: json['color'] as String?, + sourceType: json['sourceType'] as String?, + ); + +Map _$CalendarCardDataToJson(CalendarCardData instance) => + { + 'id': instance.id, + 'title': instance.title, + 'description': instance.description, + 'startAt': instance.startAt, + 'endAt': instance.endAt, + 'timezone': instance.timezone, + 'location': instance.location, + 'color': instance.color, + 'sourceType': instance.sourceType, + };