feat: a new-session draft and a sidebar grouped by project

- Starting a session opens NewSessionScreen instead of a title sheet: a
  project chip (GET /api/project, one row per canonical), a model/agent
  chip, attachments and the composer. Nothing is created on the server
  until the first send, which posts the session with its directory, model
  and agent and then sends that message.
- The draft lives in AppState (memory only): leaving it keeps it; the
  sidebar shows a draft row with its first line and a discard button; a
  failed create stays on the draft with its text.
- The session list groups by project (chat folders under 聊天), dates the
  rows (今天/昨天/本周早些时候/更早), pins through
  session.metadata.openchamber.pinned, archives on demand, pages with
  "载入更多", and swipes to pin/archive/delete (flutter_slidable).
- Child sessions are hidden; a parent's row shows its children's activity.
- The chat app bar follows the live session list, so the title the server
  generates from the first message appears at once.
- Attachments and the model picker move to shared widgets, used by the
  chat and the draft.
- 0.3.13 (313).
This commit is contained in:
blumia committed 2026-11-21 14:29:52 +08:00
1 parent 5a371e4faf
commit fff6562cbc
14 files changed
+1775 -366

No files matched your search

+33 -2
View File
@@ -62,6 +62,7 @@ class Client {
String order = 'desc',
String? search,
String? directory,
bool? archived,
}) async {
final query = <String, String>{
'limit': '$limit',
@@ -69,6 +70,7 @@ class Client {
if (cursor != null) 'cursor': cursor,
if (search != null && search.isNotEmpty) 'search': search,
if (directory != null && directory.isNotEmpty) 'directory': directory,
if (archived != null) 'archived': '$archived',
};
final r = await _json('GET', '/api/session', query: query, directory: directory);
final data = (r['data'] as List? ?? [])
@@ -85,22 +87,40 @@ class Client {
return data.keys.toSet();
}
Future<Session> createSession({String? title, String? directory}) async {
Future<Session> createSession(
{String? title,
String? directory,
ModelRef? model,
String? agent}) async {
final r = await _json('POST', '/api/session', body: {
if (title != null && title.isNotEmpty) 'title': title,
if (directory != null && directory.isNotEmpty)
'location': {'directory': directory},
// The first turn runs on the draft's selection; no switch after create.
if (model != null) 'model': model.toJson(),
if (agent != null && agent.isNotEmpty) 'agent': agent,
});
return Session.fromJson(r['data'] as Map<String, dynamic>);
}
Future<void> updateSession(String id, {String? title, bool? archived}) async {
Future<void> updateSession(String id,
{String? title, bool? archived, Map<String, dynamic>? metadata}) async {
await _json('PATCH', '/api/session/${Uri.encodeComponent(id)}', body: {
if (title != null) 'title': title,
if (archived != null) 'archived': archived,
if (metadata != null) 'metadata': metadata,
});
}
/// The projects (checkouts and chat folders) an agent can open a session in.
Future<List<ProjectInfo>> listProjects() async {
final list = await _jsonList('GET', '/api/project');
return [
for (final p in list)
if (p is Map<String, dynamic>) ProjectInfo.fromJson(p),
];
}
Future<void> deleteSession(String id) async {
await _json('DELETE', '/api/session/${Uri.encodeComponent(id)}');
}
@@ -681,6 +701,17 @@ class Client {
// --------------------------------------------------------------- transport
Future<List<dynamic>> _jsonList(String method, String path,
{Map<String, String>? query}) async {
final res = await _request(method, path, query: query);
final text = utf8.decode(await res.collect(), allowMalformed: true);
if (res.statusCode < 200 || res.statusCode >= 300) {
throw ApiError(res.statusCode, text.trim());
}
final decoded = jsonDecode(text);
return decoded is List ? decoded : const [];
}
Future<Map<String, dynamic>> _json(String method, String path,
{Map<String, String>? query,
Map<String, dynamic>? body,