File size: 2,226 Bytes
3382f47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/// `Artifact` class represents an artifact either created by or submitted to the agent.
///
/// Each artifact object contains an ID, a flag indicating if it was created by the agent,
/// a file name, and a relative path of the artifact in the agent's workspace.
class Artifact {
  // ID of the artifact.
  final String artifactId;

  // Whether the artifact has been created by the agent.
  final bool agentCreated;

  // Filename of the artifact.
  final String fileName;

  // Relative path of the artifact in the agent's workspace.
  final String? relativePath;

  /// Creates an `Artifact` instance.
  ///
  /// - `artifactId`: ID of the artifact. This is a required field.
  /// - `agentCreated`: Indicates whether the artifact was created by the agent. This is a required field.
  /// - `fileName`: The file name of the artifact. This is a required field.
  /// - `relativePath`: The relative path of the artifact in the agent's workspace. This field can be null.
  Artifact({
    required this.artifactId,
    required this.agentCreated,
    required this.fileName,
    this.relativePath,
  });

  /// Creates an `Artifact` instance from a map.
  ///
  /// This constructor is used for deserializing a JSON object into an `Artifact` instance.
  /// It expects all the required fields to be present; otherwise, an error will be thrown.
  ///
  /// - `map`: The map from which the `Artifact` instance will be created.
  factory Artifact.fromJson(Map<String, dynamic> map) {
    if (map['artifact_id'] == null ||
        map['agent_created'] == null ||
        map['file_name'] == null) {
      throw const FormatException(
          'Invalid JSON: Missing one of the required fields.');
    }

    return Artifact(
      artifactId: map['artifact_id'],
      agentCreated: map['agent_created'],
      fileName: map['file_name'],
      relativePath: map['relative_path'],
    );
  }

  /// Converts the `Artifact` instance into a JSON object.
  ///
  /// This can be useful for encoding the `Artifact` object into a JSON string.
  Map<String, dynamic> toJson() => {
        'artifact_id': artifactId,
        'agent_created': agentCreated,
        'file_name': fileName,
        'relative_path': relativePath,
      };
}