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:
1 parent
5a371e4faf
commit
fff6562cbc
14 files changed
+1775
-366
No files matched your search
@@ -52,34 +52,126 @@ class Location {
|
||||
|
||||
class Session {
|
||||
final String id;
|
||||
final String? parentID;
|
||||
final String projectID;
|
||||
final String title;
|
||||
final String agent;
|
||||
final ModelRef? model;
|
||||
final Location? location;
|
||||
final Map<String, dynamic> metadata;
|
||||
final int created;
|
||||
final int updated;
|
||||
final int viewed;
|
||||
final int archived;
|
||||
|
||||
Session({
|
||||
required this.id,
|
||||
required this.title,
|
||||
this.parentID,
|
||||
this.projectID = '',
|
||||
this.agent = '',
|
||||
this.model,
|
||||
this.location,
|
||||
this.metadata = const {},
|
||||
this.created = 0,
|
||||
this.updated = 0,
|
||||
this.viewed = 0,
|
||||
this.archived = 0,
|
||||
});
|
||||
|
||||
factory Session.fromJson(Map<String, dynamic> j) {
|
||||
final t = j['time'] as Map<String, dynamic>? ?? {};
|
||||
return Session(
|
||||
id: j['id'] as String,
|
||||
parentID: j['parentID'] as String?,
|
||||
projectID: j['projectID'] as String? ?? '',
|
||||
title: j['title'] as String? ?? '',
|
||||
agent: j['agent'] as String? ?? '',
|
||||
model: j['model'] == null ? null : ModelRef.fromJson(j['model'] as Map<String, dynamic>),
|
||||
location: j['location'] == null ? null : Location.fromJson(j['location'] as Map<String, dynamic>),
|
||||
metadata: j['metadata'] is Map<String, dynamic>
|
||||
? Map<String, dynamic>.from(j['metadata'] as Map<String, dynamic>)
|
||||
: const {},
|
||||
created: (t['created'] as num?)?.toInt() ?? 0,
|
||||
updated: (t['updated'] as num?)?.toInt() ?? 0,
|
||||
viewed: (t['viewed'] as num?)?.toInt() ?? 0,
|
||||
archived: (t['archived'] as num?)?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
String get directory => location?.directory ?? '';
|
||||
|
||||
bool get isChild => parentID != null && parentID!.isNotEmpty;
|
||||
bool get isArchived => archived > 0;
|
||||
|
||||
/// Pins live in the session's metadata (`openchamber.pinned`), so every
|
||||
/// client of the server sees them.
|
||||
bool get isPinned {
|
||||
final openchamber = metadata['openchamber'];
|
||||
return openchamber is Map && openchamber['pinned'] is Map;
|
||||
}
|
||||
|
||||
int get pinnedAt {
|
||||
final openchamber = metadata['openchamber'];
|
||||
if (openchamber is! Map) return 0;
|
||||
final pinned = openchamber['pinned'];
|
||||
return pinned is Map && pinned['at'] is num ? (pinned['at'] as num).toInt() : 0;
|
||||
}
|
||||
|
||||
Session copyWith({
|
||||
String? title,
|
||||
ModelRef? model,
|
||||
String? agent,
|
||||
Map<String, dynamic>? metadata,
|
||||
int? viewed,
|
||||
int? archived,
|
||||
int? updated,
|
||||
}) =>
|
||||
Session(
|
||||
id: id,
|
||||
parentID: parentID,
|
||||
projectID: projectID,
|
||||
title: title ?? this.title,
|
||||
agent: agent ?? this.agent,
|
||||
model: model ?? this.model,
|
||||
location: location,
|
||||
metadata: metadata ?? this.metadata,
|
||||
created: created,
|
||||
updated: updated ?? this.updated,
|
||||
viewed: viewed ?? this.viewed,
|
||||
archived: archived ?? this.archived,
|
||||
);
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
final String id;
|
||||
final String canonical;
|
||||
final String name;
|
||||
final String vcs;
|
||||
|
||||
const ProjectInfo({
|
||||
required this.id,
|
||||
required this.canonical,
|
||||
this.name = '',
|
||||
this.vcs = '',
|
||||
});
|
||||
|
||||
factory ProjectInfo.fromJson(Map<String, dynamic> j) => ProjectInfo(
|
||||
id: j['id'] as String? ?? '',
|
||||
canonical: j['canonical'] as String? ?? '',
|
||||
name: j['name'] as String? ?? '',
|
||||
vcs: j['vcs'] as String? ?? '',
|
||||
);
|
||||
|
||||
String get label {
|
||||
if (name.trim().isNotEmpty) return name.trim();
|
||||
final trimmed =
|
||||
canonical.replaceAll(RegExp(r'/+$'), '');
|
||||
final index = trimmed.lastIndexOf('/');
|
||||
return index >= 0 ? trimmed.substring(index + 1) : trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
class ContentPart {
|
||||
|
||||
Reference in new issue
Block a user