Stop background tasks separately from chat turns
Keep Esc and /stop scoped to the foreground turn while exposing an explicit stop-tasks operation for supported chat backends. Add the protocol, server routing, app command, and coverage for task stopping and unsupported harnesses.
This commit is contained in:
@@ -249,6 +249,7 @@ void main() {
|
||||
'/close — Finish this session for every client, keeping its history\n'
|
||||
'/rename <title> — Rename this session\n'
|
||||
'/stop — Stop the turn that is running\n'
|
||||
'/stop_tasks — Stop all background tasks in this chat\n'
|
||||
'/help — List every command\n'
|
||||
'!<command> — Run a shell command in this chat’s folder; '
|
||||
'the agent does not see it unless you send it',
|
||||
@@ -294,6 +295,34 @@ void main() {
|
||||
variant: _desktop,
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'/stop_tasks stops background tasks without interrupting the turn',
|
||||
(tester) async {
|
||||
gateway.stopTasks = () async => {
|
||||
'chat_stop_tasks': {
|
||||
'stopped': 2,
|
||||
'message': 'Stopped background tasks.',
|
||||
},
|
||||
};
|
||||
await pumpComposer(tester);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
'/stop_tasks',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(gateway.stopTasksBodies, [
|
||||
<String, dynamic>{'session_id': 's'},
|
||||
]);
|
||||
expect(gateway.interruptBodies, isEmpty);
|
||||
expect(gateway.promptBodies, isEmpty);
|
||||
expect(find.text('Stopped background tasks.'), findsOneWidget);
|
||||
},
|
||||
variant: _desktop,
|
||||
);
|
||||
|
||||
testWidgets('/stop interrupts the current session through the composer', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -16,6 +16,7 @@ class ComposerBarGateway implements ApiGateway {
|
||||
JsonMap page = chatPage(const []);
|
||||
Future<JsonMap> Function(String text, String operationId)? prompt;
|
||||
Future<JsonMap> Function()? interrupt;
|
||||
Future<JsonMap> Function()? stopTasks;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
@@ -32,6 +33,8 @@ class ComposerBarGateway implements ApiGateway {
|
||||
: prompt!('${body['text'] ?? ''}', '${body['operation_id'] ?? ''}');
|
||||
case 'chat_interrupt':
|
||||
return interrupt == null ? <String, dynamic>{} : interrupt!();
|
||||
case 'chat_stop_tasks':
|
||||
return stopTasks == null ? <String, dynamic>{} : stopTasks!();
|
||||
}
|
||||
return <String, dynamic>{};
|
||||
}
|
||||
@@ -49,6 +52,11 @@ class ComposerBarGateway implements ApiGateway {
|
||||
.map((call) => call.fields['chat_query'] as JsonMap)
|
||||
.toList();
|
||||
|
||||
List<JsonMap> get stopTasksBodies => calls
|
||||
.where((call) => call.type == 'chat_stop_tasks')
|
||||
.map((call) => call.fields['chat_query'] as JsonMap)
|
||||
.toList();
|
||||
|
||||
void emitEvent(JsonMap body) =>
|
||||
_frames.add({'type': 'chat_event', 'chat_event': body});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ void main() {
|
||||
'close',
|
||||
'rename',
|
||||
'stop',
|
||||
'stop_tasks',
|
||||
'help',
|
||||
]);
|
||||
expect(chatCommands.map((command) => command.usage), [
|
||||
@@ -15,6 +16,7 @@ void main() {
|
||||
'/close',
|
||||
'/rename <title>',
|
||||
'/stop',
|
||||
'/stop_tasks',
|
||||
'/help',
|
||||
]);
|
||||
expect(chatCommands.map((command) => command.summary), [
|
||||
@@ -22,6 +24,7 @@ void main() {
|
||||
'Finish this session for every client, keeping its history',
|
||||
'Rename this session',
|
||||
'Stop the turn that is running',
|
||||
'Stop all background tasks in this chat',
|
||||
'List every command',
|
||||
]);
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user