import 'package:flutter/foundation.dart'; /// A pane menu action that lives in the conversation itself (its own state), /// so a chat list choice asks the open conversation to run it. enum ChatPaneCommand { details, files, runCommand, openTerminal, dismissFinished, } /// Hands a chat list choice to the open conversation of one chat. The list /// opens the chat first; its conversation takes the request once it is built /// and runs the same handler its own More menu runs. /// /// It also records which chats have finished command runs, so the list offers /// Dismiss all finished commands where the pane would. class ChatPaneCommands extends ChangeNotifier { final List<(String, ChatPaneCommand)> _pending = []; final Set _finished = {}; /// Asks [sessionId]'s conversation to run [command]. void request(String sessionId, ChatPaneCommand command) { _pending.add((sessionId, command)); notifyListeners(); } /// Takes the oldest request for [sessionId], or null when there is none. ChatPaneCommand? take(String sessionId) { final index = _pending.indexWhere((entry) => entry.$1 == sessionId); if (index < 0) return null; return _pending.removeAt(index).$2; } /// Whether [sessionId]'s conversation holds finished command runs. bool hasFinished(String sessionId) => _finished.contains(sessionId); /// Called by a conversation as its finished runs change. void setFinished(String sessionId, bool finished) { if (finished) { _finished.add(sessionId); } else { _finished.remove(sessionId); } } }