feat: group the server's chats and use OpenChamber's project icons

Sessions under the server's managed chats root (chats/<date>/session-…) were
grouped per directory, so each one appeared as its own session-xxxxx band.
GET /api/fs/home now supplies the chats root plus its canonical and legacy
aliases; every chat folder becomes the single 聊天 group. The new-session
picker can target 聊天 too: the first send creates a fresh chat directory
before creating the session, and a new session started from an existing chat
gets a new one instead of sharing its folder.

Projects merge their OpenChamber settings row (label, icon key, colour,
iconBackground and uploaded/auto icon image) with /api/project. Group
headers, the picker and the draft chip draw the chosen icon in its colour,
and custom images are fetched through the client transport (SVG included)
with a themed fallback to the glyph. The chat group uses a chat bubble rather
than a folder.

0.4.8 (408).
This commit is contained in:
blumia committed 2026-11-23 17:42:49 +08:00
1 parent 91bf5e5b81
commit 79221e57d7
14 files changed
+599 -32

No files matched your search

+29
View File
@@ -153,6 +153,35 @@ class Client {
];
}
/// The server's home and chats root. Sessions filed under a chats root are
/// the "聊天" group, not a project; the root can be relocated away from the
/// home config directory, so it must come from the server.
Future<FsHomeInfo> fsHome() async {
final r = await _json('GET', '/api/fs/home');
return FsHomeInfo.fromJson(r);
}
/// The project's chosen/auto icon image. [projectId] is the OpenChamber
/// settings id; SVG icons are recoloured by the server for [theme] and
/// [iconColor].
Future<Uint8List?> projectIconBytes(String projectId,
{String? theme, String? iconColor}) async {
try {
final res = await _request(
'GET', '/api/projects/${Uri.encodeComponent(projectId)}/icon',
query: {
if (theme != null && theme.isNotEmpty) 'theme': theme,
if (iconColor != null && iconColor.isNotEmpty)
'iconColor': iconColor,
});
if (res.statusCode != 200) return null;
final bytes = await res.collect();
return bytes.isEmpty ? null : Uint8List.fromList(bytes);
} catch (_) {
return null;
}
}
Future<void> deleteSession(String id) async {
await _json('DELETE', '/api/session/${Uri.encodeComponent(id)}');
}
+84
View File
@@ -143,6 +143,32 @@ class Session {
);
}
/// The server's home and managed chats roots (`GET /api/fs/home`).
class FsHomeInfo {
final String home;
final String chatsRoot;
final String? canonicalChatsRoot;
final String? canonicalLegacyChatsRoot;
const FsHomeInfo({
required this.home,
required this.chatsRoot,
this.canonicalChatsRoot,
this.canonicalLegacyChatsRoot,
});
factory FsHomeInfo.fromJson(Map<String, dynamic> j) {
String? nonEmpty(Object? value) =>
value is String && value.trim().isNotEmpty ? value.trim() : null;
return FsHomeInfo(
home: nonEmpty(j['home']) ?? '',
chatsRoot: nonEmpty(j['chatsRoot']) ?? '',
canonicalChatsRoot: nonEmpty(j['canonicalChatsRoot']),
canonicalLegacyChatsRoot: nonEmpty(j['canonicalLegacyChatsRoot']),
);
}
}
/// A project the server knows: a checkout (or chat folder) an agent can work
/// in. [canonical] is the directory a session there carries.
class ProjectInfo {
@@ -151,11 +177,26 @@ class ProjectInfo {
final String name;
final String vcs;
/// The OpenChamber settings row this project was decorated from. The icon
/// endpoint keys on this id, not the opencode project id.
final String metaId;
final String icon;
final String color;
final String iconBackground;
final String iconImageMime;
final int iconImageUpdatedAt;
const ProjectInfo({
required this.id,
required this.canonical,
this.name = '',
this.vcs = '',
this.metaId = '',
this.icon = '',
this.color = '',
this.iconBackground = '',
this.iconImageMime = '',
this.iconImageUpdatedAt = 0,
});
factory ProjectInfo.fromJson(Map<String, dynamic> j) => ProjectInfo(
@@ -165,6 +206,36 @@ class ProjectInfo {
vcs: j['vcs'] as String? ?? '',
);
bool get hasIconImage => metaId.isNotEmpty && iconImageUpdatedAt > 0;
/// Decorates the opencode project with its OpenChamber settings row: the
/// operator's label, icon key, colour and uploaded/auto icon image.
ProjectInfo withMeta(Map<String, dynamic>? meta) {
if (meta == null) return this;
String text(Object? value) => value is String ? value.trim() : '';
final label = text(meta['label']);
final image = meta['iconImage'];
var mime = '';
var updatedAt = 0;
if (image is Map) {
mime = text(image['mime']);
final updated = image['updatedAt'];
if (updated is num) updatedAt = updated.toInt();
}
return ProjectInfo(
id: id,
canonical: canonical,
name: label.isNotEmpty ? label : name,
vcs: vcs,
metaId: text(meta['id']),
icon: text(meta['icon']),
color: text(meta['color']),
iconBackground: text(meta['iconBackground']),
iconImageMime: mime,
iconImageUpdatedAt: updatedAt,
);
}
String get label {
if (name.trim().isNotEmpty) return name.trim();
return pathLeaf(canonical);
@@ -184,6 +255,19 @@ String pathLeaf(String path) {
String slashPath(String path) =>
path.replaceAll('\\', '/').replaceAll(RegExp(r'/+$'), '');
/// Whether [directory] is [root] or inside it. Separators are unified and a
/// Windows drive path compares case-insensitively, as [samePath] does.
bool isUnderDirectory(String directory, String root) {
final d = slashPath(directory);
final r = slashPath(root);
if (d.isEmpty || r.isEmpty) return false;
final windows = RegExp(r'^[A-Za-z]:').hasMatch(d) ||
RegExp(r'^[A-Za-z]:').hasMatch(r);
final dd = windows ? d.toLowerCase() : d;
final rr = windows ? r.toLowerCase() : r;
return dd == rr || dd.startsWith('$rr/');
}
/// Whether two directory paths name the same place. Separators are unified;
/// a drive-letter path compares case-insensitively, as Windows does.
bool samePath(String a, String b) {