Files
pipelines/app/lib/features/schedules/domain/schedule_json.dart
T
alan f2c33d2a1e feat(app): schedule a recorded run with its options
The run detail now offers the web's "Schedule this run" action when the
run names a positive pipeline and pinned version. It opens the existing
create editor seeded from the run and sends nothing until Save.

The seed preserves every field the browser's scheduleDraft({ run })
copies: title (following the title_source rule), all input keys with
prompt kept editable, pinned version, workspace, notify mode, write
paths, tool access, model, stage models and output format. build() emits
the same conditional payload as serializeSchedule.

One request key is minted per editor opening so a refused save retries
without duplicating the schedule. Advanced options are seed-only for
now: the editor has no controls for them yet.
2026-10-22 17:28:28 +01:00

44 lines
1.5 KiB
Dart

import '../../../core/api_gateway.dart';
/// Deep copy of a decoded JSON value.
///
/// Saved schedules travel back to the server unchanged, so unknown fields (and
/// unknown nested values) must survive every round trip without sharing state
/// with the reply map that produced them.
dynamic cloneJsonValue(dynamic value) {
if (value is Map) {
return <String, dynamic>{
for (final entry in value.entries)
'${entry.key}': cloneJsonValue(entry.value),
};
}
if (value is List) {
return [for (final item in value) cloneJsonValue(item)];
}
return value;
}
JsonMap cloneJsonMap(JsonMap value) =>
Map<String, dynamic>.from(cloneJsonValue(value) as Map);
/// Whole number from a decoded JSON field, as the browser's `Number(value)`
/// followed by an integer check: integral numbers and integral numeric strings
/// are accepted; null, fractions, non-finite values and non-numeric text are
/// not.
int? jsonInteger(dynamic value) {
if (value is int) return value;
if (value is num) {
if (!value.isFinite || value != value.truncateToDouble()) return null;
return value.toInt();
}
if (value is String) {
final number = num.tryParse(value.trim());
if (number == null || !number.isFinite) return null;
return number == number.truncateToDouble() ? number.toInt() : null;
}
return null;
}
/// String field from a decoded JSON value; anything else is the empty string.
String jsonText(dynamic value) => value is String ? value : '';