86 lines
2.0 KiB
Dart
86 lines
2.0 KiB
Dart
class ToolUse {
|
|
final String tool;
|
|
final dynamic input;
|
|
final String? output;
|
|
|
|
ToolUse({
|
|
required this.tool,
|
|
this.input,
|
|
this.output,
|
|
});
|
|
|
|
factory ToolUse.fromJson(Map<String, dynamic> json) {
|
|
return ToolUse(
|
|
tool: json['tool'] ?? 'unknown',
|
|
input: json['input'],
|
|
output: json['output'],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'tool': tool,
|
|
'input': input,
|
|
'output': output,
|
|
};
|
|
}
|
|
|
|
class Message {
|
|
final String id;
|
|
final String role;
|
|
final String content;
|
|
final List<ToolUse>? toolUses;
|
|
final bool isStreaming;
|
|
final bool isThinking;
|
|
final DateTime createdAt;
|
|
|
|
Message({
|
|
String? id,
|
|
required this.role,
|
|
required this.content,
|
|
this.toolUses,
|
|
this.isStreaming = false,
|
|
this.isThinking = false,
|
|
DateTime? createdAt,
|
|
}) : id = id ?? DateTime.now().millisecondsSinceEpoch.toString(),
|
|
createdAt = createdAt ?? DateTime.now();
|
|
|
|
Message copyWith({
|
|
String? id,
|
|
String? role,
|
|
String? content,
|
|
List<ToolUse>? toolUses,
|
|
bool? isStreaming,
|
|
bool? isThinking,
|
|
DateTime? createdAt,
|
|
}) {
|
|
return Message(
|
|
id: id ?? this.id,
|
|
role: role ?? this.role,
|
|
content: content ?? this.content,
|
|
toolUses: toolUses ?? this.toolUses,
|
|
isStreaming: isStreaming ?? this.isStreaming,
|
|
isThinking: isThinking ?? this.isThinking,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
);
|
|
}
|
|
|
|
factory Message.fromJson(Map<String, dynamic> json) {
|
|
return Message(
|
|
id: json['id'],
|
|
role: json['role'],
|
|
content: json['content'],
|
|
toolUses: json['tool_uses'] != null
|
|
? (json['tool_uses'] as List)
|
|
.map((e) => ToolUse.fromJson(e))
|
|
.toList()
|
|
: null,
|
|
createdAt: json['created_at'] != null
|
|
? DateTime.parse(json['created_at'])
|
|
: DateTime.now(),
|
|
);
|
|
}
|
|
|
|
bool get isUser => role == 'user';
|
|
bool get isAssistant => role == 'assistant';
|
|
}
|