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:
1 parent
ea3b1f0f5e
commit
1aa84a53e5
13 files changed
+655
-49
No files matched your search
+163
-2
@@ -26,6 +26,10 @@ const _eventTypes = [
|
||||
'session.execution.succeeded',
|
||||
'session.execution.failed',
|
||||
'session.execution.interrupted',
|
||||
'session.inbox.enqueued',
|
||||
'session.inbox.delivered',
|
||||
'session.inbox.cancelled',
|
||||
'session.inbox.delivery.changed',
|
||||
'session.step.started',
|
||||
'session.step.ended',
|
||||
'session.step.failed',
|
||||
@@ -689,7 +693,10 @@ class AppState extends ChangeNotifier {
|
||||
if (client == null) return;
|
||||
_startStream();
|
||||
await refreshSessions();
|
||||
if (chat != null) await chat!.reloadTail();
|
||||
if (chat != null) {
|
||||
await chat!.reloadTail();
|
||||
await chat!.reloadInbox();
|
||||
}
|
||||
for (final terminal in terminals.values) {
|
||||
await terminal.reconnectIfNeeded();
|
||||
}
|
||||
@@ -920,6 +927,10 @@ class ChatState extends ChangeNotifier {
|
||||
/// The agent's pending questions (native forms), oldest first.
|
||||
List<FormInfo> forms = [];
|
||||
|
||||
/// Prompts waiting in the server's inbox (queued, or steering the running
|
||||
/// turn), oldest first. They enter the transcript only when delivered.
|
||||
List<InboxItem> inbox = [];
|
||||
|
||||
/// `/` palette contents, loaded once per open chat.
|
||||
List<SlashItem> slashItems = [];
|
||||
bool slashLoading = false;
|
||||
@@ -951,6 +962,7 @@ class ChatState extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
await reloadTail();
|
||||
await reloadForms();
|
||||
await reloadInbox();
|
||||
} catch (e) {
|
||||
loading = false;
|
||||
error = e.toString();
|
||||
@@ -1039,6 +1051,54 @@ class ChatState extends ChangeNotifier {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// Fetches the prompts waiting in the inbox, which may have been queued by
|
||||
/// another client while this one was closed.
|
||||
Future<void> reloadInbox() async {
|
||||
final cl = app.client;
|
||||
if (cl == null) return;
|
||||
try {
|
||||
inbox = await cl.inbox(id, directory: dir);
|
||||
notifyListeners();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/// Takes a waiting prompt out of the inbox and puts its text back into the
|
||||
/// composer, as dsh-Go's 撤回 does.
|
||||
Future<bool> withdrawInbox(String inboxId) async {
|
||||
final cl = app.client;
|
||||
if (cl == null) return false;
|
||||
final item = inbox.where((i) => i.id == inboxId).firstOrNull;
|
||||
try {
|
||||
await cl.cancelInbox(id, inboxId, directory: dir);
|
||||
inbox.removeWhere((i) => i.id == inboxId);
|
||||
if (item != null) draft = item.text;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
error = e.toString();
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Switches a waiting prompt between steering the running turn and waiting
|
||||
/// for it to end.
|
||||
Future<void> changeInboxDelivery(String inboxId, String delivery) async {
|
||||
final cl = app.client;
|
||||
if (cl == null) return;
|
||||
try {
|
||||
await cl.updateInbox(id, inboxId, delivery, directory: dir);
|
||||
inbox = [
|
||||
for (final i in inbox)
|
||||
i.id == inboxId ? i.withDelivery(delivery) : i,
|
||||
];
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
error = e.toString();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> replyForm(FormInfo form, Map<String, Object?> answer) async {
|
||||
final cl = app.client;
|
||||
if (cl == null) return;
|
||||
@@ -1129,7 +1189,13 @@ class ChatState extends ChangeNotifier {
|
||||
byId = {for (final m in msgs) m.id: m};
|
||||
}
|
||||
|
||||
Future<String?> send({String? text, List<Map<String, String>>? files}) async {
|
||||
/// Sends [text]. [delivery] is 'steer' (join the running turn at its next
|
||||
/// step) or 'queue' (wait for it to end); with none, an idle session starts
|
||||
/// a turn. Queue and steer prompts show as pending bubbles until the server
|
||||
/// delivers them, so no user message is written here.
|
||||
Future<String?> send({String? text,
|
||||
List<Map<String, String>>? files,
|
||||
String? delivery}) async {
|
||||
final t = (text ?? draft).trim();
|
||||
if (t.isEmpty && (files == null || files.isEmpty)) return null;
|
||||
if (t.startsWith('/')) {
|
||||
@@ -1179,6 +1245,10 @@ class ChatState extends ChangeNotifier {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// A skill can be queued like any prompt.
|
||||
if (delivery != null) {
|
||||
return _sendToInbox(t, files, delivery, skillIds: [item.id]);
|
||||
}
|
||||
final id = _newMsgId();
|
||||
msgs.add(Message(
|
||||
id: id,
|
||||
@@ -1208,6 +1278,9 @@ class ChatState extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (delivery != null) {
|
||||
return _sendToInbox(t, files, delivery);
|
||||
}
|
||||
final id = _newMsgId();
|
||||
draft = '';
|
||||
error = null;
|
||||
@@ -1239,6 +1312,61 @@ class ChatState extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// A prompt for the server's inbox: it shows as a pending bubble at the end
|
||||
/// of the chat until the server delivers it into the transcript.
|
||||
Future<String?> _sendToInbox(String text,
|
||||
List<Map<String, String>>? files, String delivery,
|
||||
{List<String>? skillIds}) async {
|
||||
final id = _newMsgId();
|
||||
final item = InboxItem(
|
||||
id: id,
|
||||
text: text,
|
||||
delivery: delivery,
|
||||
created: DateTime.now().millisecondsSinceEpoch,
|
||||
files: files
|
||||
?.map((f) => FileAttachment(f['name'] ?? '附件', ''))
|
||||
.toList() ??
|
||||
const [],
|
||||
);
|
||||
draft = '';
|
||||
error = null;
|
||||
inbox = [...inbox, item]..sort((a, b) => a.created.compareTo(b.created));
|
||||
notifyListeners();
|
||||
try {
|
||||
final serverId = await app.client!.prompt(this.id,
|
||||
text: text,
|
||||
messageId: id,
|
||||
directory: dir,
|
||||
files: files,
|
||||
delivery: delivery,
|
||||
skillIds: skillIds);
|
||||
// The server names the inbox item; keep the bubble keyed to it so the
|
||||
// cancel and delivery events find it.
|
||||
if (serverId != null && serverId != id) {
|
||||
inbox = [
|
||||
for (final i in inbox)
|
||||
i.id == id
|
||||
? InboxItem(
|
||||
id: serverId,
|
||||
text: i.text,
|
||||
delivery: i.delivery,
|
||||
created: i.created,
|
||||
files: i.files)
|
||||
: i,
|
||||
];
|
||||
}
|
||||
error = null;
|
||||
notifyListeners();
|
||||
return serverId ?? id;
|
||||
} catch (e) {
|
||||
inbox.removeWhere((i) => i.id == id);
|
||||
draft = text;
|
||||
error = e.toString();
|
||||
notifyListeners();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static String _newMsgId() =>
|
||||
'msg_${DateTime.now().microsecondsSinceEpoch.toRadixString(36)}';
|
||||
|
||||
@@ -1481,6 +1609,39 @@ class ChatState extends ChangeNotifier {
|
||||
final agent = data['agent'];
|
||||
if (agent is String && agent.isNotEmpty) selectedAgent = agent;
|
||||
break;
|
||||
case 'session.inbox.enqueued':
|
||||
final iid = data['inboxID'] as String?;
|
||||
final raw = data['item'];
|
||||
if (iid != null && raw is Map<String, dynamic> && raw['type'] == 'user') {
|
||||
final parsed = InboxItem.fromEvent(iid, raw, created);
|
||||
inbox = [
|
||||
for (final i in inbox)
|
||||
if (i.id != iid) i,
|
||||
parsed,
|
||||
]..sort((a, b) => a.created.compareTo(b.created));
|
||||
} else {
|
||||
reloadInbox();
|
||||
}
|
||||
break;
|
||||
case 'session.inbox.delivered':
|
||||
final iid = data['inboxID'] as String?;
|
||||
if (iid != null) inbox.removeWhere((i) => i.id == iid);
|
||||
// The message enters the transcript now: take the server's copy.
|
||||
reloadTail();
|
||||
break;
|
||||
case 'session.inbox.cancelled':
|
||||
final iid = data['inboxID'] as String?;
|
||||
if (iid != null) inbox.removeWhere((i) => i.id == iid);
|
||||
break;
|
||||
case 'session.inbox.delivery.changed':
|
||||
final iid = data['inboxID'] as String?;
|
||||
final d = data['delivery'] as String?;
|
||||
if (iid != null && d != null) {
|
||||
inbox = [
|
||||
for (final i in inbox) i.id == iid ? i.withDelivery(d) : i,
|
||||
];
|
||||
}
|
||||
break;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user