Dismiss finished shell command cards with Undo
Finished command cards get a Dismiss button and the chat's More menu a Dismiss all finished commands entry. Dismissal applies to every client of the chat; a SnackBar (Material) or transient notice (Cupertino) offers Undo for 5 s. Running commands cannot be dismissed until they end.
This commit is contained in:
@@ -18,6 +18,13 @@ class ShellGateway implements ApiGateway {
|
||||
List<JsonMap> runs = const [];
|
||||
String? refusal;
|
||||
|
||||
/// Tombstone ids the `chat_shell_runs` readback reports.
|
||||
List<String> dismissed = const [];
|
||||
|
||||
/// The refusal of `chat_shell_dismiss` / `chat_shell_restore`, when set.
|
||||
String? dismissRefusal;
|
||||
String? restoreRefusal;
|
||||
|
||||
/// The reply to a `chat_shell_run_output` that resumes from an offset.
|
||||
JsonMap? resumeReply;
|
||||
int _serial = 0;
|
||||
@@ -42,7 +49,19 @@ class ShellGateway implements ApiGateway {
|
||||
case 'chat_messages':
|
||||
return chatPage(const []);
|
||||
case 'chat_shell_runs':
|
||||
return {'chat_shell_runs': runs};
|
||||
return {'chat_shell_runs': runs, 'chat_shell_dismissed': dismissed};
|
||||
case 'chat_shell_dismiss':
|
||||
if (dismissRefusal != null) throw StateError(dismissRefusal!);
|
||||
return {'chat_shell_dismissed': body['run_ids']};
|
||||
case 'chat_shell_restore':
|
||||
if (restoreRefusal != null) throw StateError(restoreRefusal!);
|
||||
final ids = (body['run_ids'] as List).toSet();
|
||||
return {
|
||||
'chat_shell_runs': [
|
||||
for (final run in runs)
|
||||
if (ids.contains(run['id'])) run,
|
||||
],
|
||||
};
|
||||
case 'chat_shell_run':
|
||||
if (refusal != null) throw StateError(refusal!);
|
||||
return {
|
||||
@@ -82,6 +101,15 @@ class ShellGateway implements ApiGateway {
|
||||
},
|
||||
});
|
||||
|
||||
void emitDismissed(String id) => _frames.add({
|
||||
'type': 'chat_shell_run_event',
|
||||
'chat_shell_run_event': {
|
||||
'session_id': 's',
|
||||
'run_id': id,
|
||||
'dismissed': true,
|
||||
},
|
||||
});
|
||||
|
||||
void close() => _frames.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user