Chat: draw agent follow-ups and automatic continues apart from the operator
The server now names a user turn's origin (followup, auto_continue, auto_switch, scheduled) on chat messages, user frames and queued prompts, from the prompt's operation id while it holds the prompt and from its own text prefixes in history read later. Origin is a new field, so older clients keep treating these as ordinary user turns. The app draws an agent follow-up, auto-continue and account-switch prompt as a quiet outlined card on the agent's side with an icon, label and the schedule facts from the preamble; the operator's own scheduled message keeps its bubble with a small Scheduled mark. Find searches the drawn text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_find.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_prompt_origin.dart';
|
||||
|
||||
Map<String, dynamic> _user(
|
||||
String text, [
|
||||
Map<String, dynamic> extra = const {},
|
||||
]) => {
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': text},
|
||||
],
|
||||
...extra,
|
||||
};
|
||||
|
||||
const _followup =
|
||||
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with schedule_followup] '
|
||||
'Check the deploy.';
|
||||
|
||||
void main() {
|
||||
test('the server origin names who sent a user turn', () {
|
||||
expect(
|
||||
chatPromptOrigin(_user('x', {'origin': 'followup'})),
|
||||
ChatPromptOrigin.followup,
|
||||
);
|
||||
expect(
|
||||
chatPromptOrigin(_user('continue', {'origin': 'auto_continue'})),
|
||||
ChatPromptOrigin.autoContinue,
|
||||
);
|
||||
expect(
|
||||
chatPromptOrigin(_user('x', {'origin': 'auto_switch'})),
|
||||
ChatPromptOrigin.autoSwitch,
|
||||
);
|
||||
expect(
|
||||
chatPromptOrigin(_user('x', {'origin': 'scheduled'})),
|
||||
ChatPromptOrigin.scheduled,
|
||||
);
|
||||
expect(chatPromptOrigin(_user('hello')), ChatPromptOrigin.operator);
|
||||
});
|
||||
|
||||
test('an older server is read from operation ids and its own text', () {
|
||||
expect(
|
||||
chatPromptOrigin(_user('x', {'operation_id': 'followup-ab12'})),
|
||||
ChatPromptOrigin.followup,
|
||||
);
|
||||
expect(
|
||||
chatPromptOrigin(_user('again', {'operation_id': 'auto-continue-m1'})),
|
||||
ChatPromptOrigin.autoContinue,
|
||||
);
|
||||
expect(
|
||||
chatPromptOrigin(_user('x', {'operation_id': 'auto-switch-m1'})),
|
||||
ChatPromptOrigin.autoSwitch,
|
||||
);
|
||||
expect(chatPromptOrigin(_user(_followup)), ChatPromptOrigin.followup);
|
||||
expect(
|
||||
chatPromptOrigin(
|
||||
_user('[Sent automatically by Pipelines] Usage ran out'),
|
||||
),
|
||||
ChatPromptOrigin.autoSwitch,
|
||||
);
|
||||
expect(
|
||||
chatPromptOrigin(_user('later', {'send_at': 1764756000000})),
|
||||
ChatPromptOrigin.scheduled,
|
||||
);
|
||||
expect(
|
||||
chatPromptOrigin(_user('see [Follow-up you scheduled at noon]')),
|
||||
ChatPromptOrigin.operator,
|
||||
);
|
||||
});
|
||||
|
||||
test('a follow-up preamble becomes the header facts', () {
|
||||
final plain = chatAutomatedPrompt(ChatPromptOrigin.followup, _followup);
|
||||
expect(plain.body, 'Check the deploy.');
|
||||
expect(plain.scheduledAt, DateTime.utc(2026, 12, 3, 10).toLocal());
|
||||
expect(plain.condition, isNull);
|
||||
|
||||
final run = chatAutomatedPrompt(
|
||||
ChatPromptOrigin.followup,
|
||||
'[Follow-up you scheduled at 2026-12-03T10:00:00Z with schedule_followup, '
|
||||
'for when run 42 needs the operator or finishes; delivered at '
|
||||
'2026-12-04T10:00:00Z at the latest] Review it.\n\n'
|
||||
'[Pipelines: run 42 is now succeeded; read it with pipelines inspect 42.]',
|
||||
);
|
||||
expect(run.condition, 'run 42 needs the operator or finishes');
|
||||
expect(run.body, startsWith('Review it.\n\n[Pipelines: run 42'));
|
||||
|
||||
final unknown = chatAutomatedPrompt(ChatPromptOrigin.followup, 'raw');
|
||||
expect(unknown.body, 'raw');
|
||||
expect(
|
||||
chatAutomatedPrompt(
|
||||
ChatPromptOrigin.autoSwitch,
|
||||
'[Sent automatically by Pipelines] Usage ran out.',
|
||||
).body,
|
||||
'Usage ran out.',
|
||||
);
|
||||
});
|
||||
|
||||
test('find searches the text a follow-up draws', () {
|
||||
final units = chatFindUnits(
|
||||
[
|
||||
{'kind': 'user', 'key': 'u1', 'message': _user(_followup)},
|
||||
{'kind': 'user', 'key': 'u2', 'message': _user('mine')},
|
||||
],
|
||||
['u1', 'u2'],
|
||||
);
|
||||
expect(units.map((unit) => unit.text), ['Check the deploy.', 'mine']);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user