wip(app): chat /stop and /help commands (retained from the cancelled lane)
This commit is contained in:
@@ -26,6 +26,9 @@ const String chatAttachLabel = 'Attach file';
|
||||
/// The unknown-command report's two actions, verbatim from the web client.
|
||||
const String chatCommandSendAsMessageLabel = 'Send as message';
|
||||
const String chatCommandCancelLabel = 'Cancel';
|
||||
const String chatCommandNoticeLabel = 'Command';
|
||||
const String chatCommandFailedLabel = 'Command failed';
|
||||
const String chatCommandDismissLabel = 'Dismiss command notice';
|
||||
|
||||
/// Shown while the reply says this prompt waits behind the running turn.
|
||||
const String chatQueuedNotice =
|
||||
@@ -41,7 +44,7 @@ const String chatQueuedNotice =
|
||||
/// above the field: rows are filtered by name prefix, Up/Down move the
|
||||
/// highlight, Enter or a tap completes the highlighted command, Escape closes
|
||||
/// the palette. A slash draft is never handed to the prompt path: a completed
|
||||
/// command is not run yet (command actions are a later slice), and text naming
|
||||
/// recorded commands run locally or through the existing Stop path; text naming
|
||||
/// no recorded command becomes the web client's local no-send report with its
|
||||
/// explicit "Send as message" offer. Picked files are memory-only chips:
|
||||
/// their names are shown with the host's own remove action and the bounded
|
||||
@@ -93,6 +96,7 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
/// command carries [_commandOffer] back for an explicit "Send as message".
|
||||
String? _commandNotice;
|
||||
String? _commandOffer;
|
||||
bool _commandFailed = false;
|
||||
|
||||
ChatAttachmentPicker get _picker => widget.picker ?? hostChatAttachmentPicker;
|
||||
|
||||
@@ -212,25 +216,39 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
/// Routes the current slash draft to the command surface. Command actions
|
||||
/// are not implemented in this slice, so a recorded command reports that it
|
||||
/// is unavailable and keeps its draft; an unknown word takes the web client's
|
||||
/// report and consumes the draft into the offer. Neither posts a prompt.
|
||||
/// Routes a slash draft locally or through the existing Stop controller path.
|
||||
void _runSlashDraft() {
|
||||
final draft = widget.composer.draft;
|
||||
final word = chatCommandWord(draft);
|
||||
if (word == null) return;
|
||||
final command = chatCommandNamed(draft);
|
||||
if (command != null) {
|
||||
setState(() {
|
||||
_commandOffer = null;
|
||||
_commandNotice = chatCommandUnavailableReport('/${command.name}');
|
||||
});
|
||||
_focus.requestFocus();
|
||||
final argument = chatCommandArgument(draft);
|
||||
if (!command.takesArgument && argument.isNotEmpty) {
|
||||
_consumeCommandDraft();
|
||||
_showCommandNotice(
|
||||
'${command.usage} does not take an argument.',
|
||||
failed: true,
|
||||
);
|
||||
} else if (command.name == chatCommandStop) {
|
||||
_consumeCommandDraft();
|
||||
if (widget.running) {
|
||||
unawaited(widget.composer.stop());
|
||||
} else {
|
||||
_showCommandNotice('No turn is running in this chat.', failed: true);
|
||||
}
|
||||
} else if (command.name == chatCommandHelp) {
|
||||
_consumeCommandDraft();
|
||||
_showCommandNotice(chatCommandHelpText());
|
||||
} else {
|
||||
_consumeCommandDraft();
|
||||
_showCommandNotice(chatCommandUnavailableReport('/${command.name}'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
final offer = draft.trim();
|
||||
setState(() {
|
||||
_commandFailed = true;
|
||||
_commandOffer = offer;
|
||||
_commandNotice = chatUnknownCommandReport(word);
|
||||
});
|
||||
@@ -239,11 +257,26 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
_focus.requestFocus();
|
||||
}
|
||||
|
||||
void _consumeCommandDraft() {
|
||||
_text.clear();
|
||||
unawaited(widget.composer.setDraft(''));
|
||||
_focus.requestFocus();
|
||||
}
|
||||
|
||||
void _showCommandNotice(String text, {bool failed = false}) {
|
||||
setState(() {
|
||||
_commandFailed = failed;
|
||||
_commandOffer = null;
|
||||
_commandNotice = text;
|
||||
});
|
||||
}
|
||||
|
||||
/// Closes whatever local command report is showing. Callers wrap this in
|
||||
/// [setState]; it owns no rebuild of its own.
|
||||
void _dismissCommandReport() {
|
||||
_commandNotice = null;
|
||||
_commandOffer = null;
|
||||
_commandFailed = false;
|
||||
}
|
||||
|
||||
/// The offer's one explicit route to the agent: take the reported draft back
|
||||
@@ -661,12 +694,48 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
key: const Key('chat-composer-command-notice'),
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
_commandFailed
|
||||
? chatCommandFailedLabel
|
||||
: chatCommandNoticeLabel,
|
||||
style: TextStyle(
|
||||
color: _commandFailed
|
||||
? (cupertino
|
||||
? CupertinoColors.systemRed.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.error)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (cupertino)
|
||||
Semantics(
|
||||
button: true,
|
||||
label: chatCommandDismissLabel,
|
||||
child: CupertinoButton(
|
||||
key: const Key('chat-command-dismiss'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () => setState(_dismissCommandReport),
|
||||
child: const Text('Dismiss'),
|
||||
),
|
||||
)
|
||||
else
|
||||
IconButton(
|
||||
key: const Key('chat-command-dismiss'),
|
||||
tooltip: chatCommandDismissLabel,
|
||||
onPressed: () => setState(_dismissCommandReport),
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
],
|
||||
),
|
||||
_notice(
|
||||
context,
|
||||
cupertino,
|
||||
key: const Key('chat-composer-command-text'),
|
||||
text: _commandNotice!,
|
||||
failed: true,
|
||||
failed: _commandFailed,
|
||||
),
|
||||
if (offer != null)
|
||||
Padding(
|
||||
|
||||
@@ -106,6 +106,18 @@ ChatCommand? chatCommandNamed(String draft) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/// The trimmed text after the command word, or empty when there is no argument.
|
||||
String chatCommandArgument(String draft) {
|
||||
final word = chatCommandWord(draft);
|
||||
if (word == null) return '';
|
||||
return draft.trimLeft().substring(word.length).trim();
|
||||
}
|
||||
|
||||
/// `/help`'s local listing, in the same order and wording as the palette.
|
||||
String chatCommandHelpText() => chatCommands
|
||||
.map((command) => '${command.usage} — ${command.summary}')
|
||||
.join('\n');
|
||||
|
||||
/// The local no-send report for a slash draft naming no recorded command,
|
||||
/// verbatim from the web client's unknown-command notice. The report offers the
|
||||
/// draft back, so only an explicit "Send as message" reaches the agent.
|
||||
|
||||
Reference in New Issue
Block a user