mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-20 15:34:23 +01:00
feat: Add isWaitingForAgentResponse property to TaskViewModel
- Added a boolean property `isWaitingForAgentResponse` to the `TaskViewModel` class to track whether a task is being created and waiting for a response from the agent. - When a task is being created, we set `isWaitingForAgentResponse` to `true` and notify the listeners. - When the task creation process is completed (successfully or not), `isWaitingForAgentResponse` is set to `false` and listeners are notified. - Updated the `ChatView` class to listen to changes in `TaskViewModel.isWaitingForAgentResponse` to show the loading indicator conditionally.
This commit is contained in:
@@ -20,6 +20,10 @@ class TaskViewModel with ChangeNotifier {
|
|||||||
Task? _selectedTask;
|
Task? _selectedTask;
|
||||||
TestSuite? _selectedTestSuite;
|
TestSuite? _selectedTestSuite;
|
||||||
|
|
||||||
|
bool _isWaitingForAgentResponse = false;
|
||||||
|
|
||||||
|
bool get isWaitingForAgentResponse => _isWaitingForAgentResponse;
|
||||||
|
|
||||||
TaskViewModel(this._taskService, this._prefsService);
|
TaskViewModel(this._taskService, this._prefsService);
|
||||||
|
|
||||||
/// Returns the currently selected task.
|
/// Returns the currently selected task.
|
||||||
@@ -28,6 +32,8 @@ class TaskViewModel with ChangeNotifier {
|
|||||||
|
|
||||||
/// Adds a task and returns its ID.
|
/// Adds a task and returns its ID.
|
||||||
Future<String> createTask(String title) async {
|
Future<String> createTask(String title) async {
|
||||||
|
_isWaitingForAgentResponse = true;
|
||||||
|
notifyListeners();
|
||||||
try {
|
try {
|
||||||
final newTask = TaskRequestBody(input: title);
|
final newTask = TaskRequestBody(input: title);
|
||||||
// Add to data source
|
// Add to data source
|
||||||
@@ -45,6 +51,9 @@ class TaskViewModel with ChangeNotifier {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// TODO: We are bubbling up the full response. Revisit this.
|
// TODO: We are bubbling up the full response. Revisit this.
|
||||||
rethrow;
|
rethrow;
|
||||||
|
} finally {
|
||||||
|
_isWaitingForAgentResponse = false;
|
||||||
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class _ChatViewState extends State<ChatView> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// TODO: Do we want to have a reference to task view model in this class?
|
// TODO: Do we want to have a reference to task view model in this class?
|
||||||
final taskViewModel = Provider.of<TaskViewModel>(context, listen: false);
|
final taskViewModel = Provider.of<TaskViewModel>(context, listen: true);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -105,7 +105,8 @@ class _ChatViewState extends State<ChatView> {
|
|||||||
LoadingIndicator(
|
LoadingIndicator(
|
||||||
isLoading: Provider.of<TaskQueueViewModel>(context, listen: true)
|
isLoading: Provider.of<TaskQueueViewModel>(context, listen: true)
|
||||||
.isBenchmarkRunning ||
|
.isBenchmarkRunning ||
|
||||||
widget.viewModel.isWaitingForAgentResponse),
|
widget.viewModel.isWaitingForAgentResponse ||
|
||||||
|
taskViewModel.isWaitingForAgentResponse),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
// Input area
|
// Input area
|
||||||
Padding(
|
Padding(
|
||||||
|
|||||||
Reference in New Issue
Block a user