Merge branch 'worktree-agent-a785be85dc8fbff78'
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/// A chat's default name, shown until the operator or the harness names it.
|
||||
library;
|
||||
|
||||
/// The web's names for the chat harnesses; an unknown one shows as sent.
|
||||
String chatBackendLabel(String backend) => switch (backend) {
|
||||
'codex' => 'Codex',
|
||||
'claude' => 'Claude',
|
||||
'pi' => 'Pi',
|
||||
'opencode' => 'OpenCode',
|
||||
_ => backend,
|
||||
};
|
||||
|
||||
/// The default chat name: the directory's last folder and the harness, as in
|
||||
/// "Pipelines Codex".
|
||||
String defaultChatName(String directory, String harnessLabel) {
|
||||
final parts = directory
|
||||
.split('/')
|
||||
.where((part) => part.isNotEmpty && part != '~')
|
||||
.toList();
|
||||
final leaf = parts.isEmpty ? 'Home' : parts.last;
|
||||
final folder = leaf.isEmpty
|
||||
? 'Home'
|
||||
: '${leaf[0].toUpperCase()}${leaf.substring(1)}';
|
||||
return '$folder $harnessLabel';
|
||||
}
|
||||
|
||||
/// OpenCode's placeholder for a session it has not named yet
|
||||
/// ("New session - 2026-12-02T09:00:00.000Z").
|
||||
final RegExp _harnessPlaceholder = RegExp(
|
||||
r'^(New|Child) session - \d{4}-\d{2}-\d{2}T',
|
||||
);
|
||||
|
||||
/// The title a harness gave a chat, or null while it has none of its own
|
||||
/// (blank, or only its placeholder).
|
||||
String? chatHarnessTitle(String title) {
|
||||
final trimmed = title.trim();
|
||||
if (trimmed.isEmpty || _harnessPlaceholder.hasMatch(trimmed)) return null;
|
||||
return title;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/// "Send later…": the quick times the composer offers for scheduling the
|
||||
/// operator's own message (the server holds it until `send_at`).
|
||||
library;
|
||||
|
||||
import 'chat_account_usage.dart';
|
||||
import 'chat_usage_limit.dart';
|
||||
|
||||
enum ChatSendLaterKind { halfHour, hour, tomorrowMorning, usageReset }
|
||||
|
||||
typedef ChatSendLaterChoice = ({ChatSendLaterKind kind, DateTime at});
|
||||
|
||||
/// When the account's quota is back: the exhausted limit's reset if one is
|
||||
/// reported, else the next reported window reset; a minute later, as
|
||||
/// auto-continue does. Null when no reset time is known.
|
||||
DateTime? chatSendLaterUsageReset(ChatAccountUsage? usage, DateTime now) {
|
||||
final limit = chatUsageLimit(usage, now);
|
||||
if (limit != null) return limit.sendAt;
|
||||
if (usage == null || usage.unsupported) return null;
|
||||
int? next;
|
||||
for (final window in usage.windows) {
|
||||
final at = window.resetsAt;
|
||||
if (at <= now.millisecondsSinceEpoch) continue;
|
||||
if (next == null || at < next) next = at;
|
||||
}
|
||||
if (next == null) return null;
|
||||
return DateTime.fromMillisecondsSinceEpoch(next).add(chatScheduleMargin);
|
||||
}
|
||||
|
||||
/// In 30 minutes, in 1 hour, tomorrow at 9:00 and, when known, at the usage
|
||||
/// reset.
|
||||
List<ChatSendLaterChoice> chatSendLaterChoices(
|
||||
DateTime now, {
|
||||
DateTime? usageReset,
|
||||
}) {
|
||||
final local = now.toLocal();
|
||||
return [
|
||||
(
|
||||
kind: ChatSendLaterKind.halfHour,
|
||||
at: local.add(const Duration(minutes: 30)),
|
||||
),
|
||||
(kind: ChatSendLaterKind.hour, at: local.add(const Duration(hours: 1))),
|
||||
(
|
||||
kind: ChatSendLaterKind.tomorrowMorning,
|
||||
at: DateTime(local.year, local.month, local.day + 1, 9),
|
||||
),
|
||||
if (usageReset != null && usageReset.isAfter(now))
|
||||
(kind: ChatSendLaterKind.usageReset, at: usageReset.toLocal()),
|
||||
];
|
||||
}
|
||||
|
||||
/// A picked time of day: today when it is still ahead, else tomorrow.
|
||||
DateTime chatSendLaterAt(DateTime now, int hour, int minute) {
|
||||
final local = now.toLocal();
|
||||
final today = DateTime(local.year, local.month, local.day, hour, minute);
|
||||
return today.isAfter(local)
|
||||
? today
|
||||
: DateTime(local.year, local.month, local.day + 1, hour, minute);
|
||||
}
|
||||
@@ -1,9 +1,22 @@
|
||||
import '../../../core/api_gateway.dart';
|
||||
import 'chat_default_name.dart';
|
||||
|
||||
/// Pure session-list operations. Unknown server fields remain on each row.
|
||||
///
|
||||
/// A chat's title is the operator's name for it or else the harness's own;
|
||||
/// until the harness names an unnamed chat it shows the default name
|
||||
/// ("Pipelines Codex") from its directory and harness.
|
||||
String chatSessionTitle(JsonMap session) {
|
||||
final title = '${session['title'] ?? ''}';
|
||||
if (title.trim().isNotEmpty) return title;
|
||||
final title = chatHarnessTitle('${session['title'] ?? ''}');
|
||||
if (title != null) return title;
|
||||
final directory = '${session['directory'] ?? ''}'.trim();
|
||||
if (directory.isNotEmpty) {
|
||||
final backend = '${session['backend'] ?? ''}'.trim();
|
||||
return defaultChatName(
|
||||
directory,
|
||||
chatBackendLabel(backend.isEmpty ? 'opencode' : backend),
|
||||
);
|
||||
}
|
||||
final id = '${session['id'] ?? ''}';
|
||||
return id.isEmpty ? 'Untitled chat' : id.substring(0, id.length.clamp(0, 18));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user