@qilin-agent/schedule 0.0.0-stage → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.i18n.yaml +76 -0
- package/README.md +170 -2
- package/README.zh.md +171 -0
- package/lib/index.js +2271 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +734 -0
- package/lib/typert.remote-client.d.ts +30 -0
- package/lib/typert.remote-client.js +480 -0
- package/lib/types/client.d.ts +3 -0
- package/lib/types/client.js +2 -0
- package/lib/types/delivery-history.d.ts +24 -0
- package/lib/types/delivery-history.js +66 -0
- package/lib/types/domain.d.ts +309 -0
- package/lib/types/domain.js +1587 -0
- package/lib/types/index.d.ts +134 -0
- package/lib/types/index.js +416 -0
- package/lib/types/runtime.d.ts +42 -0
- package/lib/types/runtime.js +168 -0
- package/lib/types/storage.d.ts +59 -0
- package/lib/types/storage.js +54 -0
- package/lib/types/types.d.ts +422 -0
- package/lib/types/types.js +6 -0
- package/lib/types/update.d.ts +26 -0
- package/lib/types/update.js +164 -0
- package/package.json +84 -3
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict Schedule decoding, replay, time validation, and framing.
|
|
3
|
+
* @module @qilin-agent/schedule
|
|
4
|
+
*/
|
|
5
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
6
|
+
import type { SessionEvent, SessionLogOffset as SessionLogOffsetType } from '@qilin-agent/session';
|
|
7
|
+
import type { AfterScheduleRecord, AtInput, AtScheduleRecord, EveryScheduleRecord, CronInput, CronScheduleRecord, DailyInput, DailyScheduleRecord, WeeklyInput, WeeklyScheduleRecord, LegacyScheduleRecord, RecurringScheduleRecord, OneShotScheduleRecord, ScheduleChange, ScheduleId as ScheduleIdType, ScheduleRecord, ScheduleView } from './types.ts';
|
|
8
|
+
/** Durable Schedule protocol version implemented by this package. */
|
|
9
|
+
export declare const SCHEDULE_CHANGE_VERSION: 1;
|
|
10
|
+
/** Fixed v1 lower bound for a fixed-rate reminder. */
|
|
11
|
+
export declare const MIN_EVERY_INTERVAL_SECONDS = 60;
|
|
12
|
+
/** Fixed v1 upper bound for a stored task title. */
|
|
13
|
+
export declare const MAX_TITLE_LENGTH = 120;
|
|
14
|
+
/**
|
|
15
|
+
* Longest forward or backward walk of the cron date search, in years.
|
|
16
|
+
*
|
|
17
|
+
* The proleptic Gregorian leap-year and weekday alignment repeats every 400
|
|
18
|
+
* years, so a rule that matches any local date has a match within this window;
|
|
19
|
+
* walking further can only reach a rule that never matches. Bounding the walk
|
|
20
|
+
* keeps a valid but unsatisfiable rule's creation and decision cost fixed
|
|
21
|
+
* instead of enumerating candidate dates toward the four-digit-year ceiling.
|
|
22
|
+
*/
|
|
23
|
+
export declare const CRON_SEARCH_HORIZON_YEARS = 400;
|
|
24
|
+
/** Error from malformed or transition-invalid durable Schedule data. */
|
|
25
|
+
export declare class ScheduleLogError extends Error {
|
|
26
|
+
/** Stable machine-readable error code. */
|
|
27
|
+
readonly code: "corrupt_schedule_log";
|
|
28
|
+
/**
|
|
29
|
+
* Construct a durable-log failure.
|
|
30
|
+
* @param message - Package-specific violated invariant.
|
|
31
|
+
*/
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
/** Error from a model-supplied Schedule rule that cannot become a record. */
|
|
35
|
+
export declare class ScheduleInputError extends Error {
|
|
36
|
+
/** Stable public Schedule input code. */
|
|
37
|
+
readonly code: 'invalid_prompt' | 'invalid_selector' | 'invalid_rule' | 'invalid_time_zone' | 'not_future' | 'time_out_of_range' | 'frequency_too_high';
|
|
38
|
+
/**
|
|
39
|
+
* Construct a stable input failure.
|
|
40
|
+
* @param code - Public Schedule error discriminator.
|
|
41
|
+
* @param message - Stable public diagnostic.
|
|
42
|
+
* @param options - Optional contained implementation cause.
|
|
43
|
+
*/
|
|
44
|
+
constructor(code: 'invalid_prompt' | 'invalid_selector' | 'invalid_rule' | 'invalid_time_zone' | 'not_future' | 'time_out_of_range' | 'frequency_too_high', message: string, options?: ErrorOptions);
|
|
45
|
+
}
|
|
46
|
+
/** Pure replay result, retaining active create order and every used id. */
|
|
47
|
+
export interface FoldedSchedules {
|
|
48
|
+
/** Active records in their original create order. */
|
|
49
|
+
readonly active: readonly LegacyScheduleRecord[];
|
|
50
|
+
/** Every id ever created in this session-local suffix. */
|
|
51
|
+
readonly seenIds: readonly ScheduleIdType[];
|
|
52
|
+
}
|
|
53
|
+
/** One latest-only recurring decision derived without enumerating a backlog. */
|
|
54
|
+
export interface RecurringOccurrence {
|
|
55
|
+
/** Latest occurrence due at the decision time. */
|
|
56
|
+
readonly occurrenceAt: string;
|
|
57
|
+
/** First eligible target after the decision, or exhaustion. */
|
|
58
|
+
readonly nextScheduledAt?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Brand a raw session-local id without changing its runtime value.
|
|
62
|
+
* @param value - Raw session-local id.
|
|
63
|
+
* @returns The same string with the Schedule brand.
|
|
64
|
+
*/
|
|
65
|
+
export declare function ScheduleId(value: string): ScheduleIdType;
|
|
66
|
+
/** Stable diagnostic for a title that is missing or empty after trimming. */
|
|
67
|
+
export declare const REQUIRED_TITLE_MESSAGE = "title is required and must be non-empty after trimming.";
|
|
68
|
+
/**
|
|
69
|
+
* Validate the title supplied at creation.
|
|
70
|
+
*
|
|
71
|
+
* Creation requires an explicit title: a missing, blank-after-trim, or over-long
|
|
72
|
+
* value throws instead of deriving a name from the instruction.
|
|
73
|
+
* @param title - Task name supplied at creation.
|
|
74
|
+
* @returns The trimmed title; an invalid title throws ScheduleInputError.
|
|
75
|
+
*/
|
|
76
|
+
export declare function scheduleTitle(title: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Validate one required stored title at the durable boundary.
|
|
79
|
+
*
|
|
80
|
+
* Only records written after titles became required are read: a missing,
|
|
81
|
+
* blank-after-trim, untrimmed, or over-long stored title is invalid, and no name
|
|
82
|
+
* is derived from the instruction.
|
|
83
|
+
* @param value - Untrusted durable title field.
|
|
84
|
+
* @returns The stored title; an invalid title throws ScheduleLogError.
|
|
85
|
+
*/
|
|
86
|
+
export declare function decodeStoredTitle(value: unknown): string;
|
|
87
|
+
/**
|
|
88
|
+
* Validate and canonicalize one raw IANA time-zone selector.
|
|
89
|
+
* @param value - Candidate `UTC` or IANA Area/Location name.
|
|
90
|
+
* @returns The runtime's canonical IANA name.
|
|
91
|
+
*/
|
|
92
|
+
export declare function canonicalizeTimeZone(value: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Parse one strict local clock time accepted by the weekly selector.
|
|
95
|
+
* @param value - Candidate `HH:mm:ss` time with optional one-to-three fractional digits.
|
|
96
|
+
* @returns The parsed plain time; malformed input throws ScheduleInputError.
|
|
97
|
+
*/
|
|
98
|
+
export declare function weeklyTime(value: string): Temporal.PlainTime;
|
|
99
|
+
/**
|
|
100
|
+
* Normalize the explicit ISO weekday set of one weekly rule.
|
|
101
|
+
* @param weekdays - Untrusted candidate weekday values.
|
|
102
|
+
* @returns Frozen unique ascending weekdays from 1 (Monday) through 7 (Sunday).
|
|
103
|
+
*/
|
|
104
|
+
export declare function normalizeWeekdays(weekdays: unknown): number[];
|
|
105
|
+
/**
|
|
106
|
+
* Decode a current Host task record, preserving its committed target and stored zone spelling.
|
|
107
|
+
*
|
|
108
|
+
* Every variant of a stored Host task carries its title, so the historical
|
|
109
|
+
* one-shot variants are re-checked for that member after their shape decodes.
|
|
110
|
+
* @param value - Untrusted durable JSON record.
|
|
111
|
+
* @returns Detached frozen record; malformed fields throw ScheduleLogError.
|
|
112
|
+
*/
|
|
113
|
+
export declare function decodeScheduleRecord(value: unknown): ScheduleRecord;
|
|
114
|
+
/**
|
|
115
|
+
* Decode one strict version-1 `schedule/change` payload.
|
|
116
|
+
* @param value - Untrusted durable JSON value.
|
|
117
|
+
* @returns Detached, frozen Schedule change.
|
|
118
|
+
*/
|
|
119
|
+
export declare function decodeScheduleChange(value: unknown): ScheduleChange;
|
|
120
|
+
/** Timing fields one fixed-rate decision needs from its record. */
|
|
121
|
+
type EveryOccurrenceInput = Pick<EveryScheduleRecord, 'everySeconds' | 'scheduledAt'>;
|
|
122
|
+
/**
|
|
123
|
+
* Resolve one fixed-rate decision without enumerating missed occurrences.
|
|
124
|
+
* @param record - Active record whose target is the earliest unaccepted occurrence.
|
|
125
|
+
* @param acceptedAt - Wall-clock decision time in epoch milliseconds.
|
|
126
|
+
* @returns The latest due occurrence and first strictly future target, if representable.
|
|
127
|
+
*/
|
|
128
|
+
export declare function resolveEveryOccurrence(record: EveryOccurrenceInput, acceptedAt: number): RecurringOccurrence;
|
|
129
|
+
/**
|
|
130
|
+
* Resolve a daily decision near the decision's local date, not across its missed history.
|
|
131
|
+
* @param record - Daily rule with a committed earliest unaccepted UTC target.
|
|
132
|
+
* @param acceptedAt - Explicit wall-clock decision time, at or after the committed target.
|
|
133
|
+
* @returns Latest actual due occurrence and the next future occurrence on a later local date.
|
|
134
|
+
*/
|
|
135
|
+
export declare function resolveDailyOccurrence(record: DailyScheduleRecord, acceptedAt: number): RecurringOccurrence;
|
|
136
|
+
/**
|
|
137
|
+
* Resolve a weekly decision near the decision's local date, not across its missed history.
|
|
138
|
+
* @param record - Weekly rule with a committed earliest unaccepted UTC target.
|
|
139
|
+
* @param acceptedAt - Explicit wall-clock decision time, at or after the committed target.
|
|
140
|
+
* @returns Latest actual due occurrence and the next future occurrence on a selected weekday.
|
|
141
|
+
*/
|
|
142
|
+
export declare function resolveWeeklyOccurrence(record: WeeklyScheduleRecord, acceptedAt: number): RecurringOccurrence;
|
|
143
|
+
/**
|
|
144
|
+
* Resolve a cron decision near the decision's local date, not across its missed history.
|
|
145
|
+
* @param record - Cron rule with a committed earliest unaccepted UTC target.
|
|
146
|
+
* @param acceptedAt - Explicit wall-clock decision time, at or after the committed target.
|
|
147
|
+
* @returns Latest actual due occurrence and the first future occurrence.
|
|
148
|
+
*/
|
|
149
|
+
export declare function resolveCronOccurrence(record: CronScheduleRecord, acceptedAt: number): RecurringOccurrence;
|
|
150
|
+
/**
|
|
151
|
+
* Identify recurring Host records explicitly, excluding both one-shot variants.
|
|
152
|
+
* @param record - Current Host schedule record.
|
|
153
|
+
* @returns Whether the record uses a recurring rule.
|
|
154
|
+
*/
|
|
155
|
+
export declare function isRecurringScheduleRecord(record: ScheduleRecord): record is RecurringScheduleRecord;
|
|
156
|
+
/**
|
|
157
|
+
* Resolve one due recurring Host record with its rule-specific calendar or interval arithmetic.
|
|
158
|
+
* @param record - Due recurring rule.
|
|
159
|
+
* @param acceptedAt - Explicit decision time in epoch milliseconds.
|
|
160
|
+
* @returns Latest due occurrence and optional future target.
|
|
161
|
+
*/
|
|
162
|
+
export declare function resolveRecurringOccurrence(record: RecurringScheduleRecord, acceptedAt: number): RecurringOccurrence;
|
|
163
|
+
/**
|
|
164
|
+
* Apply already-decoded Schedule changes to one complete fold value.
|
|
165
|
+
*
|
|
166
|
+
* The transition authority for full-log replay. One mutable Map/Set pair spans
|
|
167
|
+
* the whole batch; the returned arrays are materialized and frozen once.
|
|
168
|
+
* @param folded - complete active records and used-id history before the changes.
|
|
169
|
+
* @param changes - strictly decoded durable mutations in log order.
|
|
170
|
+
* @returns the complete fold value after every mutation.
|
|
171
|
+
*/
|
|
172
|
+
export declare function applyScheduleChanges(folded: FoldedSchedules, changes: Iterable<ScheduleChange>): FoldedSchedules;
|
|
173
|
+
/**
|
|
174
|
+
* Fold the package-owned stream after the durable fork seed boundary.
|
|
175
|
+
* @param events - Complete ordered session log or candidate-extended log.
|
|
176
|
+
* @param inheritedEventCount - Inherited prefix length excluded from child ownership.
|
|
177
|
+
* @returns Active records and all previously used ids.
|
|
178
|
+
*/
|
|
179
|
+
export declare function foldScheduleEvents(events: readonly SessionEvent[], inheritedEventCount?: SessionLogOffsetType): FoldedSchedules;
|
|
180
|
+
/**
|
|
181
|
+
* Allocate the next readable id without reusing any prior session-local id.
|
|
182
|
+
* @param folded - Fold containing every previously created id.
|
|
183
|
+
* @returns A fresh `schedule-N` identity.
|
|
184
|
+
*/
|
|
185
|
+
export declare function allocateScheduleId(folded: FoldedSchedules): ScheduleIdType;
|
|
186
|
+
/**
|
|
187
|
+
* Validate a model after rule and compute its durable target.
|
|
188
|
+
* @param id - Already allocated task id.
|
|
189
|
+
* @param prompt - Reminder content supplied at creation.
|
|
190
|
+
* @param afterSeconds - Requested positive delay.
|
|
191
|
+
* @param now - Single rule-acceptance wall-clock sample in epoch milliseconds.
|
|
192
|
+
* @param title - Required task name supplied at creation.
|
|
193
|
+
* @returns Frozen durable after record.
|
|
194
|
+
*/
|
|
195
|
+
export declare function createAfterScheduleRecord(id: ScheduleIdType, prompt: string, afterSeconds: number, now: number, title: string): AfterScheduleRecord;
|
|
196
|
+
/**
|
|
197
|
+
* Validate an absolute selector and compute its sole durable UTC target.
|
|
198
|
+
* @param id - Already allocated task id.
|
|
199
|
+
* @param prompt - Reminder content supplied at creation.
|
|
200
|
+
* @param at - Explicit-offset instant or structured local calendar value.
|
|
201
|
+
* @param now - Single rule-acceptance wall-clock sample in epoch milliseconds.
|
|
202
|
+
* @param title - Required task name supplied at creation.
|
|
203
|
+
* @returns Frozen durable absolute one-shot record.
|
|
204
|
+
*/
|
|
205
|
+
export declare function createAtScheduleRecord(id: ScheduleIdType, prompt: string, at: AtInput, now: number, title: string): AtScheduleRecord;
|
|
206
|
+
/**
|
|
207
|
+
* Parse an absolute selector without requiring it to be future.
|
|
208
|
+
* @param at - Explicit-offset instant or strict local calendar input.
|
|
209
|
+
* @returns Resolved epoch milliseconds; malformed input throws ScheduleInputError.
|
|
210
|
+
*/
|
|
211
|
+
export declare function parseAtInput(at: AtInput): number;
|
|
212
|
+
/**
|
|
213
|
+
* Validate a fixed-rate selector and compute the first target of a new interval anchor.
|
|
214
|
+
* @param id - Already allocated task id.
|
|
215
|
+
* @param prompt - Reminder content supplied at creation.
|
|
216
|
+
* @param everySeconds - Requested fixed safe-integer interval.
|
|
217
|
+
* @param now - Single rule-acceptance wall-clock sample in epoch milliseconds.
|
|
218
|
+
* @param title - Required task name supplied at creation.
|
|
219
|
+
* @returns Frozen durable fixed-rate record.
|
|
220
|
+
*/
|
|
221
|
+
export declare function createEveryScheduleRecord(id: ScheduleIdType, prompt: string, everySeconds: number, now: number, title: string): EveryScheduleRecord;
|
|
222
|
+
/**
|
|
223
|
+
* Create a daily wall-clock rule with a strictly future committed UTC target.
|
|
224
|
+
* @param id - Already allocated task identity.
|
|
225
|
+
* @param prompt - Reminder content supplied at creation.
|
|
226
|
+
* @param daily - Strict local time and explicit IANA zone.
|
|
227
|
+
* @param now - Single rule-acceptance wall-clock sample in epoch milliseconds.
|
|
228
|
+
* @param title - Required task name supplied at creation.
|
|
229
|
+
* @returns Frozen daily record; absent future dates throw time_out_of_range.
|
|
230
|
+
*/
|
|
231
|
+
export declare function createDailyScheduleRecord(id: ScheduleIdType, prompt: string, daily: DailyInput, now: number, title: string): DailyScheduleRecord;
|
|
232
|
+
/**
|
|
233
|
+
* Normalize a daily selector without calculating a new committed target.
|
|
234
|
+
* @param daily - Strict local time and explicit IANA zone.
|
|
235
|
+
* @returns Normalized time and canonical zone; malformed input throws ScheduleInputError.
|
|
236
|
+
*/
|
|
237
|
+
export declare function parseDailyInput(daily: DailyInput): {
|
|
238
|
+
readonly time: string;
|
|
239
|
+
readonly timeZone: string;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Create a weekly wall-clock rule with a strictly future committed UTC target.
|
|
243
|
+
* @param id - Already allocated task identity.
|
|
244
|
+
* @param prompt - Reminder content supplied at creation.
|
|
245
|
+
* @param weekly - Strict local time, explicit IANA zone, and explicit ISO weekday set.
|
|
246
|
+
* @param now - Single rule-acceptance wall-clock sample in epoch milliseconds.
|
|
247
|
+
* @param title - Required task name supplied at creation.
|
|
248
|
+
* @returns Frozen weekly record; absent future weekdays throw time_out_of_range.
|
|
249
|
+
*/
|
|
250
|
+
export declare function createWeeklyScheduleRecord(id: ScheduleIdType, prompt: string, weekly: WeeklyInput, now: number, title: string): WeeklyScheduleRecord;
|
|
251
|
+
/**
|
|
252
|
+
* Create a cron wall-clock rule with a strictly future committed UTC target.
|
|
253
|
+
* @param id - Already allocated task identity.
|
|
254
|
+
* @param prompt - Reminder content supplied at creation.
|
|
255
|
+
* @param cron - Strict five-field expression and explicit IANA zone.
|
|
256
|
+
* @param now - Single rule-acceptance wall-clock sample in epoch milliseconds.
|
|
257
|
+
* @param title - Required task name supplied at creation.
|
|
258
|
+
* @returns Frozen cron record; absent future occurrences throw time_out_of_range.
|
|
259
|
+
*/
|
|
260
|
+
export declare function createCronScheduleRecord(id: ScheduleIdType, prompt: string, cron: CronInput, now: number, title: string): CronScheduleRecord;
|
|
261
|
+
/**
|
|
262
|
+
* Normalize a weekly selector without calculating a new committed target.
|
|
263
|
+
* @param weekly - Strict local time, explicit IANA zone, and explicit ISO weekday set.
|
|
264
|
+
* @returns Normalized time, canonical zone, and unique ascending weekdays; malformed input throws ScheduleInputError.
|
|
265
|
+
*/
|
|
266
|
+
export declare function parseWeeklyInput(weekly: WeeklyInput): {
|
|
267
|
+
readonly time: string;
|
|
268
|
+
readonly timeZone: string;
|
|
269
|
+
readonly weekdays: number[];
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Canonicalize one strict five-field cron expression.
|
|
273
|
+
* @param expression - Candidate `minute hour day-of-month month day-of-week` expression.
|
|
274
|
+
* @returns The canonical expression; malformed or unsupported input throws ScheduleInputError.
|
|
275
|
+
*/
|
|
276
|
+
export declare function canonicalizeCronExpression(expression: string): string;
|
|
277
|
+
/**
|
|
278
|
+
* Normalize a cron selector without calculating a new committed target.
|
|
279
|
+
* @param cron - Strict five-field expression and explicit IANA zone.
|
|
280
|
+
* @returns The canonical expression and canonical zone; malformed input throws ScheduleInputError.
|
|
281
|
+
*/
|
|
282
|
+
export declare function parseCronInput(cron: CronInput): {
|
|
283
|
+
readonly expression: string;
|
|
284
|
+
readonly timeZone: string;
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Derive one execution-local management view.
|
|
288
|
+
* @param record - Active durable record.
|
|
289
|
+
* @param now - Wall-clock sample used for its timing state.
|
|
290
|
+
* @returns Complete Host delivery view.
|
|
291
|
+
*/
|
|
292
|
+
export declare function scheduleView(record: ScheduleRecord, now: number): ScheduleView;
|
|
293
|
+
/**
|
|
294
|
+
* Render the fixed model framing for a due reminder.
|
|
295
|
+
* @param record - Due active record.
|
|
296
|
+
* @returns Stable model-visible text with JSON-escaped dynamic fields.
|
|
297
|
+
*/
|
|
298
|
+
export declare function renderReminderFraming(record: OneShotScheduleRecord): string;
|
|
299
|
+
/**
|
|
300
|
+
* Render one recurring reminder batch in the supplied order.
|
|
301
|
+
* @param reminders - Complete admitted batch with one latest occurrence per record.
|
|
302
|
+
* @returns Stable model-visible text whose dynamic payload is canonical JSON.
|
|
303
|
+
*/
|
|
304
|
+
export declare function renderRecurringReminderBatchFraming(reminders: readonly {
|
|
305
|
+
readonly record: RecurringScheduleRecord;
|
|
306
|
+
readonly occurrenceAt: string;
|
|
307
|
+
}[]): string;
|
|
308
|
+
export {};
|
|
309
|
+
//# sourceMappingURL=domain.d.ts.map
|