feat(chat): add ToolResult and UiCard models
This commit is contained in:
@@ -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<String, dynamic> json) =>
|
||||||
|
_$ToolResultFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$ToolResultToJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// UI 卡片 Schema(给 UI 渲染)
|
||||||
|
@JsonSerializable()
|
||||||
|
class UiCard {
|
||||||
|
@JsonKey(name: 'type')
|
||||||
|
final String cardType;
|
||||||
|
|
||||||
|
@JsonKey(name: 'version')
|
||||||
|
final String? schemaVersion;
|
||||||
|
|
||||||
|
final Map<String, dynamic> data;
|
||||||
|
final List<CardAction>? actions;
|
||||||
|
|
||||||
|
UiCard({
|
||||||
|
required this.cardType,
|
||||||
|
this.schemaVersion = 'v1',
|
||||||
|
required this.data,
|
||||||
|
this.actions,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory UiCard.fromJson(Map<String, dynamic> json) => _$UiCardFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> 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<String, dynamic> json) =>
|
||||||
|
_$CardActionFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> 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<String, dynamic> json) =>
|
||||||
|
_$CalendarCardDataFromJson(json);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$CalendarCardDataToJson(this);
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'tool_result.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
ToolResult _$ToolResultFromJson(Map<String, dynamic> json) => ToolResult(
|
||||||
|
eventId: json['eventId'] as String?,
|
||||||
|
ok: json['ok'] as bool? ?? true,
|
||||||
|
message: json['message'] as String?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$ToolResultToJson(ToolResult instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'eventId': instance.eventId,
|
||||||
|
'ok': instance.ok,
|
||||||
|
'message': instance.message,
|
||||||
|
};
|
||||||
|
|
||||||
|
UiCard _$UiCardFromJson(Map<String, dynamic> json) => UiCard(
|
||||||
|
cardType: json['type'] as String,
|
||||||
|
schemaVersion: json['version'] as String? ?? 'v1',
|
||||||
|
data: json['data'] as Map<String, dynamic>,
|
||||||
|
actions: (json['actions'] as List<dynamic>?)
|
||||||
|
?.map((e) => CardAction.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$UiCardToJson(UiCard instance) => <String, dynamic>{
|
||||||
|
'type': instance.cardType,
|
||||||
|
'version': instance.schemaVersion,
|
||||||
|
'data': instance.data,
|
||||||
|
'actions': instance.actions,
|
||||||
|
};
|
||||||
|
|
||||||
|
CardAction _$CardActionFromJson(Map<String, dynamic> json) => CardAction(
|
||||||
|
type: json['type'] as String,
|
||||||
|
label: json['label'] as String,
|
||||||
|
target: json['target'] as String?,
|
||||||
|
action: json['action'] as String?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$CardActionToJson(CardAction instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'type': instance.type,
|
||||||
|
'label': instance.label,
|
||||||
|
'target': instance.target,
|
||||||
|
'action': instance.action,
|
||||||
|
};
|
||||||
|
|
||||||
|
CalendarCardData _$CalendarCardDataFromJson(Map<String, dynamic> 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<String, dynamic> _$CalendarCardDataToJson(CalendarCardData instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'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,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user