98 lines
2.3 KiB
Dart
98 lines
2.3 KiB
Dart
enum MessageRole { user, assistant, system }
|
|
|
|
enum MessageType { text, toolUse, toolResult, approval, thinking, standingOrderDraft, interrupted }
|
|
|
|
enum ToolStatus { executing, completed, error, blocked, awaitingApproval }
|
|
|
|
class ChatMessage {
|
|
final String id;
|
|
final MessageRole role;
|
|
final String content;
|
|
final DateTime timestamp;
|
|
final MessageType? type;
|
|
final ToolExecution? toolExecution;
|
|
final ApprovalRequest? approvalRequest;
|
|
final bool isStreaming;
|
|
final Map<String, dynamic>? metadata;
|
|
|
|
const ChatMessage({
|
|
required this.id,
|
|
required this.role,
|
|
required this.content,
|
|
required this.timestamp,
|
|
this.type,
|
|
this.toolExecution,
|
|
this.approvalRequest,
|
|
this.isStreaming = false,
|
|
this.metadata,
|
|
});
|
|
|
|
ChatMessage copyWith({
|
|
String? id,
|
|
MessageRole? role,
|
|
String? content,
|
|
DateTime? timestamp,
|
|
MessageType? type,
|
|
ToolExecution? toolExecution,
|
|
ApprovalRequest? approvalRequest,
|
|
bool? isStreaming,
|
|
Map<String, dynamic>? metadata,
|
|
}) {
|
|
return ChatMessage(
|
|
id: id ?? this.id,
|
|
role: role ?? this.role,
|
|
content: content ?? this.content,
|
|
timestamp: timestamp ?? this.timestamp,
|
|
type: type ?? this.type,
|
|
toolExecution: toolExecution ?? this.toolExecution,
|
|
approvalRequest: approvalRequest ?? this.approvalRequest,
|
|
isStreaming: isStreaming ?? this.isStreaming,
|
|
metadata: metadata ?? this.metadata,
|
|
);
|
|
}
|
|
}
|
|
|
|
class ToolExecution {
|
|
final String toolName;
|
|
final String input;
|
|
final String? output;
|
|
final int riskLevel;
|
|
final ToolStatus status;
|
|
|
|
const ToolExecution({
|
|
required this.toolName,
|
|
required this.input,
|
|
this.output,
|
|
required this.riskLevel,
|
|
required this.status,
|
|
});
|
|
|
|
ToolExecution copyWith({String? output, ToolStatus? status}) {
|
|
return ToolExecution(
|
|
toolName: toolName,
|
|
input: input,
|
|
output: output ?? this.output,
|
|
riskLevel: riskLevel,
|
|
status: status ?? this.status,
|
|
);
|
|
}
|
|
}
|
|
|
|
class ApprovalRequest {
|
|
final String taskId;
|
|
final String command;
|
|
final int riskLevel;
|
|
final String? targetServer;
|
|
final DateTime expiresAt;
|
|
final String? status;
|
|
|
|
const ApprovalRequest({
|
|
required this.taskId,
|
|
required this.command,
|
|
required this.riskLevel,
|
|
this.targetServer,
|
|
required this.expiresAt,
|
|
this.status,
|
|
});
|
|
}
|