mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-17 14:04:27 +01:00
Merge commit 'e5d30a9f6d0854e20049309333c2f637cd03025c' as 'frontend'
This commit is contained in:
61
frontend/lib/models/task.dart
Normal file
61
frontend/lib/models/task.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
/// Represents a task or topic the user wants to discuss with the agent.
|
||||
class Task {
|
||||
final String id;
|
||||
final Map<String, dynamic>? additionalInput;
|
||||
final List<String>? artifacts;
|
||||
|
||||
String _title;
|
||||
|
||||
Task({
|
||||
required this.id,
|
||||
this.additionalInput,
|
||||
this.artifacts,
|
||||
required String title,
|
||||
}) : assert(title.isNotEmpty, 'Title cannot be empty'),
|
||||
_title = title;
|
||||
|
||||
String get title => _title;
|
||||
|
||||
set title(String newTitle) {
|
||||
if (newTitle.isNotEmpty) {
|
||||
_title = newTitle;
|
||||
} else {
|
||||
throw ArgumentError('Title cannot be empty.');
|
||||
}
|
||||
}
|
||||
|
||||
// Convert a Map (usually from JSON) to a Task object
|
||||
factory Task.fromMap(Map<String, dynamic> map) {
|
||||
Map<String, dynamic>? additionalInput;
|
||||
List<String>? artifacts;
|
||||
|
||||
if (map['additional_input'] != null) {
|
||||
additionalInput = Map<String, dynamic>.from(map['additional_input']);
|
||||
}
|
||||
|
||||
if (map['artifacts'] != null) {
|
||||
artifacts = List<String>.from(map['artifacts'].map((e) => e.toString()));
|
||||
}
|
||||
|
||||
return Task(
|
||||
id: map['task_id'],
|
||||
additionalInput: additionalInput,
|
||||
artifacts: artifacts,
|
||||
title: map['input'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Task &&
|
||||
runtimeType == other.runtimeType &&
|
||||
id == other.id &&
|
||||
title == other.title;
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode ^ title.hashCode;
|
||||
|
||||
@override
|
||||
String toString() => 'Task(id: $id, title: $title)';
|
||||
}
|
||||
Reference in New Issue
Block a user