feat: add scheduled tasks behind a 全部功能 button

- the sidebar footer gains 全部功能 left of 设置; its page lists the
  features the server offers, planned tasks for now
- 计划任务 follows the web client: a project (or the chats scope) picked
  at the top, then its tasks with schedule, last result, next run, model
  and error; the switch pauses, the menu runs now, edits or deletes
- the editor covers name, prompt, daily/weekly/once/cron schedules
  (Chinese date and time pickers), several times a day, weekdays, cron
  examples, enabled, and either the session defaults or a fixed model
  and agent
- the same /api/projects/:id/scheduled-tasks endpoints the web uses; a
  server without them says so instead of failing silently
- the app now pins zh_CN localizations, so the built-in pickers and
  menus are Chinese too
- bump to 0.5.1
This commit is contained in:
blumia committed 2026-11-26 00:36:27 +08:00
1 parent 2f5ce61692
commit da4bfb6826
13 files changed
+1612 -3

No files matched your search

+42
View File
@@ -8,6 +8,7 @@ import 'dart:typed_data';
import '../version.dart';
import 'models.dart';
import 'scheduled_tasks.dart';
import 'shells.dart';
import 'terminal.dart';
import 'transport.dart';
@@ -400,6 +401,47 @@ class Client {
});
}
// ------------------------------------------------------ scheduled tasks
/// The project id the scheduled-tasks API uses for sessions outside any
/// project: the web client's chats scope.
static const scheduledChatsScope = 'openchamber:chats';
static String _scheduledTasksPath(String projectId) =>
'/api/projects/${Uri.encodeComponent(projectId)}/scheduled-tasks';
static List<ScheduledTask> _scheduledTasks(Map<String, dynamic> r) => [
for (final task in r['tasks'] as List? ?? const [])
if (task is Map<String, dynamic>) ScheduledTask.fromJson(task),
];
Future<List<ScheduledTask>> scheduledTasks(String projectId) async =>
_scheduledTasks(await _json('GET', _scheduledTasksPath(projectId)));
/// Creates or replaces [task]; the server answers with the project's tasks.
Future<List<ScheduledTask>> saveScheduledTask(
String projectId, ScheduledTask task) async {
final r = await _json('PUT', _scheduledTasksPath(projectId),
body: {'task': task.toJson()});
return _scheduledTasks(r);
}
Future<List<ScheduledTask>> deleteScheduledTask(
String projectId, String taskId) async {
final r = await _json('DELETE',
'${_scheduledTasksPath(projectId)}/${Uri.encodeComponent(taskId)}');
return _scheduledTasks(r);
}
/// Starts a run now; the run's task (with its new state) comes back.
Future<ScheduledTask?> runScheduledTask(
String projectId, String taskId) async {
final r = await _json('POST',
'${_scheduledTasksPath(projectId)}/${Uri.encodeComponent(taskId)}/run');
final task = r['task'];
return task is Map<String, dynamic> ? ScheduledTask.fromJson(task) : null;
}
/// Moves a waiting prompt between `steer` and `queue`.
Future<void> updateInbox(String sessionId, String inboxId, String delivery,
{String? directory}) async {