main
dart 84 lines 2.04 KB
Raw
1 import 'tool_definition.dart';
2
3 enum ToolEventStatus {
4 requested,
5 approved,
6 rejected,
7 running,
8 completed,
9 failed,
10 }
11
12 class ToolEvent {
13 final String eventId;
14 final DateTime timestamp;
15 final ToolEventStatus status;
16 final String toolName;
17 final ToolProviderType providerType;
18 final String? providerRef;
19 final Map<String, dynamic>? arguments;
20 final String? result;
21 final String? error;
22 final int? durationMs;
23
24 const ToolEvent({
25 required this.eventId,
26 required this.timestamp,
27 required this.status,
28 required this.toolName,
29 required this.providerType,
30 this.providerRef,
31 this.arguments,
32 this.result,
33 this.error,
34 this.durationMs,
35 });
36
37 factory ToolEvent.requested({
38 required String eventId,
39 required String toolName,
40 required ToolProviderType providerType,
41 String? providerRef,
42 Map<String, dynamic>? arguments,
43 }) => ToolEvent(
44 eventId: eventId,
45 timestamp: DateTime.now(),
46 status: ToolEventStatus.requested,
47 toolName: toolName,
48 providerType: providerType,
49 providerRef: providerRef,
50 arguments: arguments,
51 );
52
53 Map<String, dynamic> toMap() {
54 return {
55 'eventId': eventId,
56 'timestamp': timestamp.toIso8601String(),
57 'status': status.name,
58 'toolName': toolName,
59 'providerType': providerType.name,
60 'providerRef': providerRef,
61 'arguments': arguments,
62 'result': result,
63 'error': error,
64 'durationMs': durationMs,
65 };
66 }
67
68 factory ToolEvent.fromMap(Map<String, dynamic> map) {
69 return ToolEvent(
70 eventId: map['eventId'],
71 timestamp: DateTime.parse(map['timestamp']),
72 status: ToolEventStatus.values.byName(map['status']),
73 toolName: map['toolName'],
74 providerType: ToolProviderType.values.byName(map['providerType']),
75 providerRef: map['providerRef'],
76 arguments: map['arguments'] != null
77 ? Map<String, dynamic>.from(map['arguments'])
78 : null,
79 result: map['result'],
80 error: map['error'],
81 durationMs: map['durationMs'],
82 );
83 }
84 }