feat: a transport seam, image previews, native forms, a phone drawer

- lib/api/transport.dart: TransportRequest/TransportResponse/Transport, with
  DirectTransport holding the old behaviour (HTTP CONNECT, SOCKS5/socks5h,
  self-signed and pinned certificates). Client goes through it, so a relay
  tunnel only adds an implementation.
- User rows decode the server's inline attachment data and open the shared
  image preview on tap; the local path stays the fallback.
- The agent's native forms: models from @opencode/client, the form list,
  replies and cancels, form.* events, and a dock above the composer with
  when-rules and required-field validation (a switch must be on).
- HomeScreen: the session list is the phone's left drawer and a persistent
  column from 840 px, the chat beside it; the newest session opens on start.
- 0.3.10 (310).
This commit is contained in:
blumia committed 2026-11-21 01:16:10 +08:00
1 parent 9b53338908
commit 60d02083d3
11 files changed
+1272 -320

No files matched your search

+69 -1
View File
@@ -41,6 +41,9 @@ const _eventTypes = [
'session.compaction.delta',
'session.compaction.ended',
'session.compaction.failed',
'form.created',
'form.replied',
'form.cancelled',
'permission.asked',
'permission.replied',
];
@@ -328,7 +331,11 @@ class AppState extends ChangeNotifier {
final type = ev['type'] as String? ?? '';
final data = ev['data'] as Map<String, dynamic>? ?? {};
if (chat != null) {
final sid = data['sessionID'] as String?;
final form = data['form'];
final sid = data['sessionID'] as String? ??
(form is Map<String, dynamic>
? form['sessionID'] as String?
: null);
if (sid != null && sid == chat!.session.id) {
chat!.handleEvent(type, data, ev['created'] as int? ?? 0);
}
@@ -468,6 +475,8 @@ class AppState extends ChangeNotifier {
Future<void> openChat(Session s) async {
chat = ChatState(this, s);
// The shell shows the new session at once; its messages follow.
notifyListeners();
await chat!.load();
notifyListeners();
}
@@ -529,6 +538,9 @@ class ChatState extends ChangeNotifier {
ModelRef? selectedModel;
String selectedAgent;
/// The agent's pending questions (native forms), oldest first.
List<FormInfo> forms = [];
/// `/` palette contents, loaded once per open chat.
List<SlashItem> slashItems = [];
bool slashLoading = false;
@@ -559,6 +571,7 @@ class ChatState extends ChangeNotifier {
error = null;
notifyListeners();
await reloadTail();
await reloadForms();
} catch (e) {
loading = false;
error = e.toString();
@@ -664,6 +677,44 @@ class ChatState extends ChangeNotifier {
);
}
/// Fetches the pending forms, which may have been asked while the stream
/// was down (the events alone would miss them).
Future<void> reloadForms() async {
final cl = app.client;
if (cl == null) return;
try {
forms = await cl.forms(id, directory: dir);
notifyListeners();
} catch (_) {}
}
Future<void> replyForm(FormInfo form, Map<String, Object?> answer) async {
final cl = app.client;
if (cl == null) return;
try {
await cl.replyForm(id, form.id, answer, directory: dir);
forms.removeWhere((f) => f.id == form.id);
error = null;
notifyListeners();
} catch (e) {
error = e.toString();
notifyListeners();
}
}
Future<void> cancelForm(FormInfo form) async {
final cl = app.client;
if (cl == null) return;
try {
await cl.cancelForm(id, form.id, directory: dir);
forms.removeWhere((f) => f.id == form.id);
notifyListeners();
} catch (e) {
error = e.toString();
notifyListeners();
}
}
/// Refreshes the newest page without dropping the older pages that were
/// already loaded; the server's copy wins for messages it returns.
Future<void> reloadTail() async {
@@ -1003,6 +1054,23 @@ class ChatState extends ChangeNotifier {
case 'session.tool.progress':
if (mid != null) _applyTool(mid, type, data);
break;
case 'form.created':
final raw = data['form'];
if (raw is Map<String, dynamic>) {
final form = FormInfo.fromJson(raw);
forms.removeWhere((f) => f.id == form.id);
forms.add(form);
notifyListeners();
}
break;
case 'form.replied':
case 'form.cancelled':
final id = data['id'] as String?;
if (id != null) {
forms.removeWhere((f) => f.id == id);
notifyListeners();
}
break;
case 'session.compaction.started':
final cid = data['inputID'] as String?;
if (cid != null && byId[cid] == null) {