feat: queue a message for the running turn, and fold the composer when the IME closes

- A send while a turn runs joins it (delivery "steer") on a short press; a
  long press offers steer or queue. Queue/steer prompts wait in the server's
  inbox and show as a pending bubble at the end of the transcript, with
  改为排队/转为转向 and 撤回 (which puts the text back into the composer).
  The inbox is read on open and resume and kept current by the
  session.inbox.* events; delivery reloads the tail.
- The send key is stop only while running with an empty draft; with text it
  sends (as dsh-Go does), leaving the long press for the delivery choice.
- The composer also folds to one line when the phone's back gesture closes
  the keyboard while the field keeps focus: the page passes the keyboard
  height (a Scaffold strips the bottom inset from its body) and the composer
  treats a fall below half the peak as a dismissal.
- The Build/Plan chip now opens a bottom sheet with icons, hints and a check,
  instead of a popup menu.
- Tests: composer_box_test (focus opens, IME dismissal folds, typing reopens)
  and inbox_item_test (list items, enqueued events, delivery changes).
- 0.3.16 (316).
This commit is contained in:
blumia committed 2026-11-21 18:32:57 +08:00
1 parent ea3b1f0f5e
commit 1aa84a53e5
13 files changed
+655 -49

No files matched your search

+34 -2
View File
@@ -181,22 +181,54 @@ class Client {
body: {'decision': decision, if (message.isNotEmpty) 'message': message});
}
Future<void> prompt(String sessionId,
/// Sends a prompt. [delivery] is 'steer' or 'queue' on a running turn; with
/// none the server starts a turn when idle. Returns the inbox item id.
Future<String?> prompt(String sessionId,
{String text = '',
String? messageId,
String? directory,
String? delivery,
List<Map<String, String>>? files,
List<String>? skillIds}) async {
await _json('POST', '/api/session/${Uri.encodeComponent(sessionId)}/prompt', directory: directory,
final r = await _json('POST', '/api/session/${Uri.encodeComponent(sessionId)}/prompt', directory: directory,
body: {
if (text.isNotEmpty) 'text': text,
if (messageId != null) 'id': messageId,
if (delivery != null) 'delivery': delivery,
if (files != null && files.isNotEmpty) 'files': files,
if (skillIds != null && skillIds.isNotEmpty)
'skills': [
for (final id in skillIds) {'id': id},
],
});
final data = r['data'];
return data is Map ? data['id'] as String? : null;
}
/// Prompts waiting in the session's inbox (queued or about to steer).
Future<List<InboxItem>> inbox(String sessionId, {String? directory}) async {
final r = await _json('GET', '/api/session/${Uri.encodeComponent(sessionId)}/inbox',
directory: directory);
return [
for (final e in (r['data'] as List? ?? []))
if (e is Map<String, dynamic> && e['type'] == 'user')
InboxItem.fromJson(e),
];
}
/// Takes a waiting prompt out of the inbox.
Future<void> cancelInbox(String sessionId, String inboxId, {String? directory}) async {
await _json('DELETE',
'/api/session/${Uri.encodeComponent(sessionId)}/inbox/${Uri.encodeComponent(inboxId)}',
directory: directory);
}
/// Moves a waiting prompt between `steer` and `queue`.
Future<void> updateInbox(String sessionId, String inboxId, String delivery,
{String? directory}) async {
await _json('PATCH',
'/api/session/${Uri.encodeComponent(sessionId)}/inbox/${Uri.encodeComponent(inboxId)}',
directory: directory, body: {'delivery': delivery});
}
/// Runs a registered slash command (`/initialize`, `/review`, …). The
+62
View File
@@ -403,6 +403,68 @@ class FileAttachment {
);
}
/// A prompt the server holds in the session's inbox until it is delivered:
/// `queue` waits for the running turn to end, `steer` joins it at its next
/// step. The message only enters the transcript when it is delivered.
class InboxItem {
final String id;
final String text;
/// 'steer' | 'queue'.
final String delivery;
final int created;
final List<FileAttachment> files;
const InboxItem({
required this.id,
required this.text,
required this.delivery,
this.created = 0,
this.files = const [],
});
/// Non-user inbox entries (compaction, moves, synthetic context) are the
/// server's own; only what the person typed is shown.
factory InboxItem.fromJson(Map<String, dynamic> j) {
final time = j['time'] as Map<String, dynamic>? ?? {};
final payload = j['payload'] as Map<String, dynamic>? ?? {};
return InboxItem(
id: j['id'] as String,
text: payload['text'] as String? ?? '',
delivery: j['delivery'] as String? ?? 'queue',
created: (time['created'] as num?)?.toInt() ?? 0,
files: (payload['files'] as List?)
?.map((e) => FileAttachment.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
);
}
/// An `enqueued` event carries the payload under `item` and the id beside
/// it, rather than in the item.
factory InboxItem.fromEvent(String id, Map<String, dynamic> j, int created) {
final payload = j['payload'] as Map<String, dynamic>? ?? {};
return InboxItem(
id: id,
text: payload['text'] as String? ?? '',
delivery: j['delivery'] as String? ?? 'queue',
created: created,
files: (payload['files'] as List?)
?.map((e) => FileAttachment.fromJson(e as Map<String, dynamic>))
.toList() ??
const [],
);
}
InboxItem withDelivery(String value) => InboxItem(
id: id,
text: text,
delivery: value,
created: created,
files: files,
);
}
/// One row of a native form's choice control.
class FormOption {
final String value;