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

+82 -60
View File
@@ -5,18 +5,23 @@ import 'package:flutter/material.dart';
import '../api/models.dart';
import '../state.dart';
import 'servers_screen.dart';
import 'chat_screen.dart';
/// The connected screen: the live session list.
class SessionsScreen extends StatefulWidget {
/// The session list: a drawer on a phone, a persistent column on a wide
/// layout. Selecting a session opens it in the chat beside it (the shell owns
/// that), so this only reports the choice through [onOpened].
class SessionListPane extends StatefulWidget {
final AppState app;
const SessionsScreen({super.key, required this.app});
/// Called after a session was opened, so the drawer can close itself.
final VoidCallback? onOpened;
const SessionListPane({super.key, required this.app, this.onOpened});
@override
State<SessionsScreen> createState() => _SessionsScreenState();
State<SessionListPane> createState() => _SessionListPaneState();
}
class _SessionsScreenState extends State<SessionsScreen> {
class _SessionListPaneState extends State<SessionListPane> {
bool _searchOpen = false;
Timer? _timer;
late final TextEditingController _searchCtrl;
@@ -51,40 +56,48 @@ class _SessionsScreenState extends State<SessionsScreen> {
return ListenableBuilder(
listenable: app,
builder: (context, _) {
return Scaffold(
appBar: AppBar(
title: const Text('会话'),
leading: IconButton(
icon: const Icon(Icons.dns_outlined),
tooltip: '服务器',
onPressed: _instancesSheet,
),
actions: [
IconButton(
icon: Icon(_searchOpen ? Icons.close : Icons.search),
tooltip: '搜索',
onPressed: () {
setState(() {
_searchOpen = !_searchOpen;
if (!_searchOpen) {
_searchCtrl.clear();
app.refreshSessions();
}
});
},
),
IconButton(
icon: const Icon(Icons.add),
tooltip: '新建会话',
onPressed: _newSessionSheet,
),
],
),
body: Column(
final scheme = Theme.of(context).colorScheme;
return SafeArea(
child: Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(4, 6, 4, 0),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.dns_outlined),
tooltip: '服务器',
onPressed: _instancesSheet,
),
const Expanded(
child: Text('会话',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w600)),
),
IconButton(
icon: Icon(_searchOpen ? Icons.close : Icons.search),
tooltip: '搜索',
onPressed: () {
setState(() {
_searchOpen = !_searchOpen;
if (!_searchOpen) {
_searchCtrl.clear();
app.refreshSessions();
}
});
},
),
IconButton(
icon: const Icon(Icons.add),
tooltip: '新建会话',
onPressed: _newSessionSheet,
),
],
),
),
if (_searchOpen)
Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 4),
padding: const EdgeInsets.fromLTRB(12, 2, 12, 4),
child: TextField(
controller: _searchCtrl,
autofocus: true,
@@ -99,14 +112,17 @@ class _SessionsScreenState extends State<SessionsScreen> {
),
if (app.error != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
Expanded(
child: Text(app.error!,
style: TextStyle(color: Theme.of(context).colorScheme.error, fontSize: 13)),
style: TextStyle(
color: scheme.error, fontSize: 13)),
),
TextButton(onPressed: app.refreshSessions, child: const Text('重试')),
TextButton(
onPressed: app.refreshSessions,
child: const Text('重试')),
],
),
),
@@ -130,7 +146,8 @@ class _SessionsScreenState extends State<SessionsScreen> {
children: [
const Text('暂无会话'),
const SizedBox(height: 8),
FilledButton(onPressed: _newSessionSheet, child: const Text('新建会话')),
FilledButton(
onPressed: _newSessionSheet, child: const Text('新建会话')),
],
),
);
@@ -142,7 +159,9 @@ class _SessionsScreenState extends State<SessionsScreen> {
itemBuilder: (context, i) {
final s = app.sessions[i];
final running = app.active.contains(s.id);
final selected = widget.app.chat?.session.id == s.id;
return ListTile(
selected: selected,
title: Text(s.title.isEmpty ? '(无标题会话)' : s.title,
maxLines: 1, overflow: TextOverflow.ellipsis),
subtitle: Text(_subtitle(s),
@@ -153,7 +172,9 @@ class _SessionsScreenState extends State<SessionsScreen> {
if (running)
Padding(
padding: const EdgeInsets.only(right: 8),
child: Icon(Icons.circle, size: 10, color: Theme.of(context).colorScheme.primary),
child: Icon(Icons.circle,
size: 10,
color: Theme.of(context).colorScheme.primary),
),
PopupMenuButton<String>(
onSelected: (v) => _sessionAction(s, v),
@@ -167,10 +188,7 @@ class _SessionsScreenState extends State<SessionsScreen> {
),
onTap: () {
app.openChat(s);
Navigator.push(
context,
MaterialPageRoute(builder: (_) => ChatScreen(app: app, session: s)),
);
widget.onOpened?.call();
},
);
},
@@ -212,7 +230,9 @@ class _SessionsScreenState extends State<SessionsScreen> {
title: const Text('重命名'),
content: TextField(controller: ctrl, autofocus: true),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消')),
FilledButton(
onPressed: () {
Navigator.pop(context);
@@ -232,7 +252,9 @@ class _SessionsScreenState extends State<SessionsScreen> {
title: const Text('删除会话?'),
content: Text('“${s.title}”及其子会话将被删除,且无法恢复。'),
actions: [
TextButton(onPressed: () => Navigator.pop(context), child: const Text('取消')),
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消')),
FilledButton(
onPressed: () {
Navigator.pop(context);
@@ -257,12 +279,14 @@ class _SessionsScreenState extends State<SessionsScreen> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text('新建会话', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const Text('新建会话',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
TextField(
controller: ctrl,
autofocus: true,
decoration: const InputDecoration(hintText: '标题(可选)', border: OutlineInputBorder()),
decoration: const InputDecoration(
hintText: '标题(可选)', border: OutlineInputBorder()),
),
const SizedBox(height: 12),
FilledButton(
@@ -274,12 +298,7 @@ class _SessionsScreenState extends State<SessionsScreen> {
widget.app.sessions.insert(0, s);
widget.app.touch();
widget.app.openChat(s);
if (mounted) {
Navigator.push(
context,
MaterialPageRoute(builder: (_) => ChatScreen(app: widget.app, session: s)),
);
}
widget.onOpened?.call();
}
},
child: const Text('创建'),
@@ -300,14 +319,18 @@ class _SessionsScreenState extends State<SessionsScreen> {
children: [
const Padding(
padding: EdgeInsets.all(12),
child: Text('服务器', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
child: Text('服务器',
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
),
for (final c in app.connections) ...[
ListTile(
title: Text(c.label),
subtitle: Text(c.proxy.isEmpty ? c.url : '${c.url}\n经由 ${c.proxy}'),
trailing: app.conn?.id == c.id
? Text('已连接', style: TextStyle(color: Theme.of(context).colorScheme.primary))
? Text('已连接',
style: TextStyle(
color: Theme.of(context).colorScheme.primary))
: null,
onTap: () {
Navigator.pop(context);
@@ -321,8 +344,7 @@ class _SessionsScreenState extends State<SessionsScreen> {
onTap: () {
Navigator.pop(context);
Navigator.of(context).push(MaterialPageRoute(
builder: (_) =>
ServersScreen(app: app, startEditing: true),
builder: (_) => ServersScreen(app: app, startEditing: true),
));
},
),