mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-27 19:04:25 +01:00
This commit updates the ChatService and TaskService classes to use the api.get method instead of the previous api.getList. This change allows us to handle structured API responses more effectively, particularly those containing pagination information and detailed task and step data. - Update ChatService methods to use api.get - Update TaskService methods to use api.get - Handle structured TaskResponse in TaskService.listAllTasks
63 lines
1.9 KiB
Dart
63 lines
1.9 KiB
Dart
import 'package:auto_gpt_flutter_client/models/task_request_body.dart';
|
|
import 'package:auto_gpt_flutter_client/models/task_response.dart';
|
|
import 'package:auto_gpt_flutter_client/utils/rest_api_utility.dart';
|
|
|
|
/// Service class for performing task-related operations.
|
|
class TaskService {
|
|
final RestApiUtility api;
|
|
|
|
TaskService(this.api);
|
|
|
|
/// Creates a new task.
|
|
///
|
|
/// [taskRequestBody] is a Map representing the request body for creating a task.
|
|
Future<Map<String, dynamic>> createTask(
|
|
TaskRequestBody taskRequestBody) async {
|
|
try {
|
|
return await api.post('agent/tasks', taskRequestBody.toJson());
|
|
} catch (e) {
|
|
throw Exception('Failed to create a new task: $e');
|
|
}
|
|
}
|
|
|
|
/// Lists all tasks.
|
|
///
|
|
/// [currentPage] and [pageSize] are optional pagination parameters.
|
|
///
|
|
Future<TaskResponse> listAllTasks(
|
|
{int currentPage = 1, int pageSize = 10}) async {
|
|
try {
|
|
final response = await api
|
|
.get('agent/tasks?current_page=$currentPage&page_size=$pageSize');
|
|
return TaskResponse.fromJson(response);
|
|
} catch (e) {
|
|
throw Exception('Failed to list all tasks: $e');
|
|
}
|
|
}
|
|
|
|
/// Gets details about a specific task.
|
|
///
|
|
/// [taskId] is the ID of the task.
|
|
Future<Map<String, dynamic>> getTaskDetails(String taskId) async {
|
|
try {
|
|
return await api.get('agent/tasks/$taskId');
|
|
} catch (e) {
|
|
throw Exception('Failed to get task details: $e');
|
|
}
|
|
}
|
|
|
|
/// Lists all artifacts for a specific task.
|
|
///
|
|
/// [taskId] is the ID of the task.
|
|
/// [currentPage] and [pageSize] are optional pagination parameters.
|
|
Future<Map<String, dynamic>> listTaskArtifacts(String taskId,
|
|
{int currentPage = 1, int pageSize = 10}) async {
|
|
try {
|
|
return await api.get(
|
|
'agent/tasks/$taskId/artifacts?current_page=$currentPage&page_size=$pageSize');
|
|
} catch (e) {
|
|
throw Exception('Failed to list task artifacts: $e');
|
|
}
|
|
}
|
|
}
|