langmail-mcp 0.1.0 → 0.2.0

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.
Files changed (137) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +89 -169
  3. package/dist/chunk-0fxfqny0.js +12642 -0
  4. package/dist/langmail-mcp.js +7 -0
  5. package/package.json +93 -98
  6. package/THIRD_PARTY_NOTICES.md +0 -388
  7. package/dist/attachments/download.js +0 -69
  8. package/dist/attachments/routes.js +0 -42
  9. package/dist/attachments/tickets.js +0 -45
  10. package/dist/attachments/upload-tickets.js +0 -43
  11. package/dist/attachments/upload.js +0 -136
  12. package/dist/caldav/account-settings.js +0 -92
  13. package/dist/caldav/agenda.js +0 -277
  14. package/dist/caldav/alarm.js +0 -97
  15. package/dist/caldav/client.js +0 -408
  16. package/dist/caldav/ical.js +0 -248
  17. package/dist/caldav/occurrence.js +0 -534
  18. package/dist/caldav/recurrence.js +0 -313
  19. package/dist/caldav/rsvp.js +0 -107
  20. package/dist/caldav/scheduling-handover.js +0 -22
  21. package/dist/caldav/timezone.js +0 -103
  22. package/dist/caldav/types.js +0 -5
  23. package/dist/config.js +0 -219
  24. package/dist/contacts/address-class.js +0 -79
  25. package/dist/contacts/birthdays.js +0 -81
  26. package/dist/contacts/card.js +0 -58
  27. package/dist/contacts/constants.js +0 -46
  28. package/dist/contacts/fold.js +0 -309
  29. package/dist/contacts/index.js +0 -10
  30. package/dist/contacts/merge.js +0 -388
  31. package/dist/contacts/observations.js +0 -115
  32. package/dist/contacts/profile.js +0 -402
  33. package/dist/contacts/scoring.js +0 -146
  34. package/dist/contacts/types.js +0 -7
  35. package/dist/contacts/upsert.js +0 -131
  36. package/dist/drafts/attachments.js +0 -254
  37. package/dist/drafts/idempotency.js +0 -60
  38. package/dist/drafts/send-guard.js +0 -184
  39. package/dist/email-render/email-viewer.html +0 -143
  40. package/dist/email-render/image-proxy.js +0 -389
  41. package/dist/email-render/meta.js +0 -48
  42. package/dist/email-render/sanitize.js +0 -93
  43. package/dist/email-render/viewer-resource.js +0 -104
  44. package/dist/http/bearer.js +0 -30
  45. package/dist/http/guard.js +0 -57
  46. package/dist/http/hosts.js +0 -10
  47. package/dist/http/listener.js +0 -170
  48. package/dist/http/routes.js +0 -72
  49. package/dist/ical/ical-parse.js +0 -357
  50. package/dist/ical/index.js +0 -4
  51. package/dist/ical/timezone.js +0 -22
  52. package/dist/ical/windows-zones.js +0 -155
  53. package/dist/index.js +0 -79
  54. package/dist/jmap/blob.js +0 -49
  55. package/dist/jmap/contacts.js +0 -226
  56. package/dist/jmap/drafts.js +0 -480
  57. package/dist/jmap/email.js +0 -668
  58. package/dist/jmap/index.js +0 -12
  59. package/dist/jmap/keywords.js +0 -22
  60. package/dist/jmap/live.js +0 -21
  61. package/dist/jmap/origin.js +0 -113
  62. package/dist/jmap/patch.js +0 -29
  63. package/dist/jmap/request.js +0 -37
  64. package/dist/jmap/session.js +0 -89
  65. package/dist/jmap/sieve.js +0 -71
  66. package/dist/jmap/submission.js +0 -107
  67. package/dist/jmap/timeout.js +0 -30
  68. package/dist/jmap/types.js +0 -6
  69. package/dist/logger.js +0 -48
  70. package/dist/mcp/handler.js +0 -255
  71. package/dist/mcp/http.js +0 -29
  72. package/dist/mcp/instructions.js +0 -44
  73. package/dist/mcp/links.js +0 -64
  74. package/dist/mcp/tool-logging.js +0 -67
  75. package/dist/observability/errors.js +0 -41
  76. package/dist/rules/apply.js +0 -236
  77. package/dist/rules/rule.js +0 -280
  78. package/dist/rules/store.js +0 -92
  79. package/dist/tools/annotations.js +0 -71
  80. package/dist/tools/archive-emails.js +0 -40
  81. package/dist/tools/calendar-lookup.js +0 -64
  82. package/dist/tools/contact-common.js +0 -146
  83. package/dist/tools/contact-format.js +0 -72
  84. package/dist/tools/contact-write-through.js +0 -37
  85. package/dist/tools/create-calendar-event.js +0 -231
  86. package/dist/tools/create-calendar.js +0 -54
  87. package/dist/tools/create-contact.js +0 -172
  88. package/dist/tools/create-draft.js +0 -369
  89. package/dist/tools/create-mail-rule.js +0 -101
  90. package/dist/tools/delete-calendar-event.js +0 -165
  91. package/dist/tools/delete-contact.js +0 -60
  92. package/dist/tools/delete-draft.js +0 -129
  93. package/dist/tools/delete-mail-rule.js +0 -38
  94. package/dist/tools/download-attachment.js +0 -90
  95. package/dist/tools/download-email.js +0 -112
  96. package/dist/tools/draft-common.js +0 -600
  97. package/dist/tools/email-types.js +0 -58
  98. package/dist/tools/error-detail.js +0 -10
  99. package/dist/tools/file-emails-common.js +0 -75
  100. package/dist/tools/format.js +0 -131
  101. package/dist/tools/forward-message.js +0 -237
  102. package/dist/tools/forward-quote.js +0 -179
  103. package/dist/tools/get-draft.js +0 -61
  104. package/dist/tools/get-email.js +0 -164
  105. package/dist/tools/get-thread.js +0 -67
  106. package/dist/tools/keywords.js +0 -43
  107. package/dist/tools/list-calendar-events.js +0 -180
  108. package/dist/tools/list-calendars.js +0 -44
  109. package/dist/tools/list-drafts.js +0 -134
  110. package/dist/tools/list-mail-rules.js +0 -28
  111. package/dist/tools/list-unsubscribe.js +0 -152
  112. package/dist/tools/list-upcoming-birthdays.js +0 -165
  113. package/dist/tools/mail-rule-common.js +0 -43
  114. package/dist/tools/mail-rule-format.js +0 -79
  115. package/dist/tools/mailbox-lookup.js +0 -13
  116. package/dist/tools/mark-emails.js +0 -78
  117. package/dist/tools/merge-contacts.js +0 -145
  118. package/dist/tools/move-calendar-events.js +0 -340
  119. package/dist/tools/move-emails.js +0 -64
  120. package/dist/tools/one-click-post.js +0 -275
  121. package/dist/tools/preview-email.js +0 -204
  122. package/dist/tools/preview-mail-rule.js +0 -79
  123. package/dist/tools/reply-quote.js +0 -426
  124. package/dist/tools/reply-to-message.js +0 -292
  125. package/dist/tools/respond-to-event.js +0 -110
  126. package/dist/tools/result.js +0 -9
  127. package/dist/tools/search-contacts.js +0 -431
  128. package/dist/tools/search-emails.js +0 -570
  129. package/dist/tools/send-draft.js +0 -308
  130. package/dist/tools/trash-emails.js +0 -36
  131. package/dist/tools/unsubscribe-from-list.js +0 -249
  132. package/dist/tools/update-calendar-event.js +0 -973
  133. package/dist/tools/update-calendar.js +0 -100
  134. package/dist/tools/update-contact.js +0 -382
  135. package/dist/tools/update-draft.js +0 -714
  136. package/dist/tools/update-mail-rule.js +0 -103
  137. package/dist/tools/upload-attachments.js +0 -126
@@ -1,277 +0,0 @@
1
- // The entries list_calendar_events shows. A stored calendar object holds a
2
- // series as one master VEVENT (DTSTART, RRULE, EXDATE) plus one override VEVENT
3
- // per changed occurrence (RFC 5545 §3.8.4.4), and Stalwart answers a time-range
4
- // query with every object that touches the window — so read raw, "what is on
5
- // my calendar on Tuesday" comes back as the series' first date and overrides
6
- // from other weeks. This module turns the stored components into what the
7
- // question asks for: inside a window, one entry per occurrence that overlaps it,
8
- // at its actual time; without one, every stored component once.
9
- //
10
- // Either way an override is completed from its master. An override only has to
11
- // carry what changed — an attendee's reply to one occurrence is stored as an
12
- // override with no SUMMARY of its own — and listing it bare reads as an
13
- // untitled event at no time.
14
- //
15
- // Pure in/out over parsed events, like recurrence.ts.
16
- import { parseWallClockInZone } from "../ical/index.js";
17
- import { durationSeconds } from "./alarm.js";
18
- import { seriesOccurrences } from "./recurrence.js";
19
- import { isValidTimeZone, toWallClockIso } from "./timezone.js";
20
- const DAY_MS = 86_400_000;
21
- // How many occurrences one series may generate for a window. Bounds the work a
22
- // `FREQ=MINUTELY` series over a long window costs; the tool shows fewer still.
23
- const MAX_GENERATED = 1000;
24
- // rrule walks every occurrence from DTSTART to the window one by one (the
25
- // `between` iterator only sees those inside it), so a seconds- or minutes-long
26
- // rule that started long ago would block the event loop. Such a series is
27
- // listed as stored instead.
28
- const SUB_DAILY_RE = /(?:^|;)FREQ=(?:SECONDLY|MINUTELY)(?:;|$)/iu;
29
- // The UTC offset written on an ISO 8601 date-time (`Z`, `+02:00`), in ms.
30
- const OFFSET_RE = /([+-])(\d{2}):(\d{2})$/u;
31
- const offsetMs = (iso) => {
32
- const match = OFFSET_RE.exec(iso);
33
- if (!match) {
34
- return 0;
35
- }
36
- const [, sign, hours, minutes] = match;
37
- return ((sign === "-" ? -1 : 1) * (Number(hours) * 60 + Number(minutes)) * 60_000);
38
- };
39
- // The window between two ISO 8601 date-times with offsets.
40
- export const agendaWindow = (start, end) => ({
41
- end: new Date(end),
42
- endOffsetMs: offsetMs(end),
43
- start: new Date(start),
44
- startOffsetMs: offsetMs(start),
45
- });
46
- const timeForm = (ev) => {
47
- if (ev.allDay) {
48
- return { kind: "allDay" };
49
- }
50
- if (ev.startTzid && isValidTimeZone(ev.startTzid)) {
51
- return { kind: "zoned", timeZone: ev.startTzid };
52
- }
53
- return ev.start.endsWith("Z") ? { kind: "utc" } : { kind: "floating" };
54
- };
55
- // An instant written back in the event's own form, as `ParsedEvent.start` holds
56
- // it. All-day values are UTC midnights (see dateOnlyToInstant).
57
- const display = (at, form) => {
58
- switch (form.kind) {
59
- case "allDay":
60
- return at.toISOString().slice(0, 10);
61
- case "zoned":
62
- return toWallClockIso(at, form.timeZone);
63
- case "floating":
64
- return at.toISOString().slice(0, 19);
65
- default:
66
- return `${at.toISOString().slice(0, 19)}Z`;
67
- }
68
- };
69
- const FLOATING_DATE_TIME_RE = /T\d{2}:\d{2}:\d{2}$/u;
70
- // The instant a stored value names, or NaN when it has none (an empty DTEND).
71
- // Inverse of display.
72
- const instantOf = (value, form) => {
73
- if (value === "") {
74
- return Number.NaN;
75
- }
76
- if (!FLOATING_DATE_TIME_RE.test(value)) {
77
- return Date.parse(value);
78
- }
79
- return form.kind === "zoned"
80
- ? parseWallClockInZone(value, form.timeZone).getTime()
81
- : Date.parse(`${value}Z`);
82
- };
83
- // An event's length, for occurrences generated from it: from DTEND, else from
84
- // DURATION. Neither means a zero-length timed event or a one-day all-day one
85
- // (RFC 5545 §3.6.1).
86
- const durationMs = (ev, form) => {
87
- const length = instantOf(ev.end, form) - instantOf(ev.start, form);
88
- if (!Number.isNaN(length)) {
89
- return length;
90
- }
91
- const seconds = ev.duration ? durationSeconds(ev.duration) : undefined;
92
- if (seconds !== undefined && seconds >= 0) {
93
- return seconds * 1000;
94
- }
95
- return form.kind === "allDay" ? DAY_MS : 0;
96
- };
97
- // An override with the master's values filled in where it carries none. An
98
- // override's attendee list is its own per-occurrence state (each reply to this
99
- // day), so it is only borrowed when the override has no attendees at all.
100
- const completeOverride = (override, master) => {
101
- if (!master) {
102
- return override;
103
- }
104
- // The master's times and their form never carry over to an override that has
105
- // its own DTSTART, nor do the series' exclusions to a single occurrence. Nor
106
- // does its TRANSP: an override is a whole VEVENT, so one without TRANSP is
107
- // busy whatever the master says. Its CLASS and STATUS do carry over, like its
108
- // title: a reply override that names neither must not turn one occurrence of
109
- // a private series public, nor bring back one of a cancelled series.
110
- const { allDay, end: _end, excludedDates: _excluded, showAs: _showAs, start: _start, startTzid, ...series } = master;
111
- const merged = {
112
- ...series,
113
- ...override,
114
- attendees: override.attendees.length > 0 ? override.attendees : master.attendees,
115
- title: override.title || master.title,
116
- };
117
- if (override.start !== "" || override.recurrenceId === undefined) {
118
- return merged;
119
- }
120
- // No DTSTART of its own: the occurrence sits at its original start, with the
121
- // series' length.
122
- const form = timeForm(master);
123
- const start = new Date(override.recurrenceId);
124
- const end = new Date(start.getTime() + durationMs(master, form));
125
- return {
126
- ...merged,
127
- ...(allDay ? { allDay } : {}),
128
- ...(startTzid ? { startTzid } : {}),
129
- end: master.end === "" ? "" : display(end, form),
130
- start: display(start, form),
131
- };
132
- };
133
- const overrideEntry = (override, master) => {
134
- const event = completeOverride(override, master);
135
- const form = timeForm(event);
136
- const startMs = instantOf(event.start, form);
137
- const originalMs = event.recurrenceId
138
- ? Date.parse(event.recurrenceId)
139
- : startMs;
140
- const entry = {
141
- event,
142
- startMs,
143
- ...((master ?? override).allDay ? { seriesAllDay: true } : {}),
144
- };
145
- if (!Number.isNaN(startMs) && originalMs !== startMs) {
146
- // In the occurrence's own form, so the zone `when:` names reads right for it
147
- // too — except on an all-day series, whose original slot is a date.
148
- entry.movedFrom = display(new Date(originalMs), entry.seriesAllDay ? { kind: "allDay" } : form);
149
- }
150
- return entry;
151
- };
152
- const plainEntry = (event) => ({
153
- event,
154
- startMs: instantOf(event.start, timeForm(event)),
155
- });
156
- const addComponent = (series, ev) => {
157
- if (ev.recurrenceId !== undefined) {
158
- series.overrides.push(ev);
159
- }
160
- else if (!series.master) {
161
- series.master = ev;
162
- }
163
- else if (ev.recurrence && !series.master.recurrence) {
164
- series.others.push(series.master);
165
- series.master = ev;
166
- }
167
- else {
168
- series.others.push(ev);
169
- }
170
- };
171
- const groupSeries = (events) => {
172
- const byUid = new Map();
173
- for (const ev of events) {
174
- const series = byUid.get(ev.uid) ?? { others: [], overrides: [] };
175
- addComponent(series, ev);
176
- byUid.set(ev.uid, series);
177
- }
178
- return [...byUid.values()];
179
- };
180
- // Every stored component once: masters and one-off events as they are,
181
- // overrides completed from their master. The listing without a window.
182
- export const storedEntries = (events) => groupSeries(events).flatMap(({ master, others, overrides }) => [
183
- ...(master ? [plainEntry(master)] : []),
184
- ...others.map(plainEntry),
185
- ...overrides.map((o) => overrideEntry(o, master)),
186
- ]);
187
- // The entry's end as epoch ms: its DTEND, or its start plus the RFC 5545
188
- // default length when it has none.
189
- export const entryEndMs = (entry) => {
190
- const form = timeForm(entry.event);
191
- const endMs = instantOf(entry.event.end, form);
192
- return Number.isNaN(endMs)
193
- ? entry.startMs + durationMs(entry.event, form)
194
- : endMs;
195
- };
196
- // [start, end) overlaps the window. A zero-length event counts when it starts
197
- // inside it. All-day entries are compared on the caller's day (AgendaWindow).
198
- const overlaps = (entry, window) => {
199
- if (entry.unexpanded || Number.isNaN(entry.startMs)) {
200
- return true;
201
- }
202
- const form = timeForm(entry.event);
203
- const allDay = form.kind === "allDay";
204
- const from = window.start.getTime() + (allDay ? window.startOffsetMs : 0);
205
- const to = window.end.getTime() + (allDay ? window.endOffsetMs : 0);
206
- const end = entryEndMs(entry);
207
- return (entry.startMs < to &&
208
- (end > from || (end === entry.startMs && entry.startMs >= from)));
209
- };
210
- // The occurrences of a master's rule that start in the expanded range, minus
211
- // excluded dates and the ones an override replaces. Generated a duration early
212
- // (an occurrence that started before the window may still run into it) and
213
- // with a day's slack each way for all-day dates; `overlaps` makes the call.
214
- const generatedEntries = (master, rule, overridden, window) => {
215
- const form = timeForm(master);
216
- const length = durationMs(master, form);
217
- const from = new Date(window.start.getTime() - length - DAY_MS);
218
- const to = new Date(window.end.getTime() + DAY_MS);
219
- // The parser already resolved TZID values to UTC; a floating one is read in
220
- // the series' own zone, like its DTSTART.
221
- const excluded = new Set((master.excludedDates ?? []).map((value) => instantOf(value, form)));
222
- const masterStart = form.kind === "floating" ? `${master.start}Z` : master.start;
223
- const timeZone = form.kind === "zoned" ? form.timeZone : undefined;
224
- return seriesOccurrences(masterStart, rule, from, to, MAX_GENERATED, timeZone)
225
- .filter((at) => !(excluded.has(at.getTime()) || overridden.has(at.getTime())))
226
- .map((at) => {
227
- const { excludedDates: _excluded, ...series } = master;
228
- return {
229
- event: {
230
- ...series,
231
- end: master.end === ""
232
- ? ""
233
- : display(new Date(at.getTime() + length), form),
234
- recurrenceId: at.toISOString(),
235
- start: display(at, form),
236
- },
237
- startMs: at.getTime(),
238
- ...(master.allDay ? { seriesAllDay: true } : {}),
239
- };
240
- });
241
- };
242
- const seriesInWindow = ({ master, others, overrides }, window) => {
243
- const replaced = [
244
- ...others.map(plainEntry),
245
- ...overrides.map((o) => overrideEntry(o, master)),
246
- ];
247
- const rule = master?.recurrence;
248
- if (!(master && rule)) {
249
- return [...(master ? [plainEntry(master)] : []), ...replaced];
250
- }
251
- // A component in `others` replaces an occurrence we can't name, so expanding
252
- // the rule would list that occurrence a second time at its old time. A zone
253
- // that is neither IANA nor a Windows name (the parser maps those to IANA)
254
- // can't be expanded honestly either: its occurrences would get
255
- // recurrenceIds that update/delete_calendar_event refuse (seriesTimeZone). A
256
- // sub-daily rule is too costly to walk (SUB_DAILY_RE).
257
- if (others.length > 0 ||
258
- SUB_DAILY_RE.test(rule) ||
259
- (master.startTzid && !isValidTimeZone(master.startTzid))) {
260
- return [{ ...plainEntry(master), unexpanded: true }, ...replaced];
261
- }
262
- const overridden = new Set(overrides.map((o) => Date.parse(o.recurrenceId ?? "")));
263
- let generated;
264
- try {
265
- generated = generatedEntries(master, rule, overridden, window);
266
- }
267
- catch {
268
- // A rule rrule can't read: list the series as stored rather than drop it.
269
- generated = [{ ...plainEntry(master), unexpanded: true }];
270
- }
271
- return [...generated, ...replaced];
272
- };
273
- // The entries that overlap the window: one per occurrence for a series, each at
274
- // its actual time; one-off events as they are.
275
- export const windowEntries = (events, window) => groupSeries(events)
276
- .flatMap((series) => seriesInWindow(series, window))
277
- .filter((entry) => overlaps(entry, window));
@@ -1,97 +0,0 @@
1
- // Reminders (VALARM) as the calendar tools speak about them: a number of
2
- // minutes before the start. Writing goes through buildInvite (InviteAlarm);
3
- // this module renders them for tool output.
4
- import { icalDateToIso } from "../ical/index.js";
5
- const MINUTES_PER_HOUR = 60;
6
- const MINUTES_PER_DAY = 1440;
7
- const MINUTES_PER_WEEK = 10_080;
8
- // The upper bound on `reminderMinutesBefore`: four weeks.
9
- export const MAX_REMINDER_MINUTES = 4 * MINUTES_PER_WEEK;
10
- const plural = (n, unit) => `${n} ${unit}${n === 1 ? "" : "s"}`;
11
- // 30 → "30 minutes", 60 → "1 hour", 1440 → "1 day"; the largest whole unit.
12
- const formatMinutes = (minutes) => {
13
- if (minutes > 0 && minutes % MINUTES_PER_WEEK === 0) {
14
- return plural(minutes / MINUTES_PER_WEEK, "week");
15
- }
16
- if (minutes > 0 && minutes % MINUTES_PER_DAY === 0) {
17
- return plural(minutes / MINUTES_PER_DAY, "day");
18
- }
19
- if (minutes > 0 && minutes % MINUTES_PER_HOUR === 0) {
20
- return plural(minutes / MINUTES_PER_HOUR, "hour");
21
- }
22
- return plural(minutes, "minute");
23
- };
24
- // A reminder `minutes` before the start, as tool output reads it back: "30
25
- // minutes before", or on an all-day event the clock time it fires ("09:00 the
26
- // day before"), matching list_calendar_events.
27
- export const describeReminder = (minutes, allDay) => allDay ? allDayFiring(minutes) : `${formatMinutes(minutes)} before`;
28
- // A relative TRIGGER (RFC 5545 §3.3.6 duration, e.g. `-PT30M`, `-P1D`,
29
- // `-P1W`, `PT0S`), as a signed number of seconds; undefined when it is not a
30
- // duration.
31
- const DURATION_RE = /^([+-])?P(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$/iu;
32
- const SECONDS_PER_MINUTE = 60;
33
- export const durationSeconds = (value) => {
34
- const m = DURATION_RE.exec(value);
35
- if (!m) {
36
- return;
37
- }
38
- const [, sign, w = "0", d = "0", h = "0", mi = "0", s = "0"] = m;
39
- const minutes = Number(w) * MINUTES_PER_WEEK +
40
- Number(d) * MINUTES_PER_DAY +
41
- Number(h) * MINUTES_PER_HOUR +
42
- Number(mi);
43
- const seconds = minutes * SECONDS_PER_MINUTE + Number(s);
44
- return sign === "-" ? -seconds : seconds;
45
- };
46
- // An offset in words, keeping seconds when it isn't a whole minute (a foreign
47
- // `-PT90S` is "1 minute 30 seconds", not a rounded "2 minutes"; `-PT29S` is
48
- // "29 seconds", not "at start"; `-PT1H1M30S` is "61 minutes 30 seconds").
49
- const formatSeconds = (seconds) => {
50
- const minutes = Math.floor(seconds / SECONDS_PER_MINUTE);
51
- const rest = seconds % SECONDS_PER_MINUTE;
52
- if (rest === 0) {
53
- return formatMinutes(minutes);
54
- }
55
- if (minutes === 0) {
56
- return plural(seconds, "second");
57
- }
58
- return `${plural(minutes, "minute")} ${plural(rest, "second")}`;
59
- };
60
- const RELATED_END_RE = /(?:^|;)RELATED=END(?:;|$)/iu;
61
- const pad2 = (n) => String(n).padStart(2, "0");
62
- // A reminder `minutes` before an all-day event's 00:00 start, as the clock
63
- // time it actually fires: "09:00 the day before", "00:00 on the day",
64
- // "18:00 2 days before". "1 day before start" would hide that it is midnight.
65
- const allDayFiring = (minutes) => {
66
- const daysBack = Math.ceil(minutes / MINUTES_PER_DAY);
67
- const clock = daysBack * MINUTES_PER_DAY - minutes;
68
- const time = `${pad2(Math.floor(clock / MINUTES_PER_HOUR))}:${pad2(clock % MINUTES_PER_HOUR)}`;
69
- if (daysBack === 0) {
70
- return `${time} on the day`;
71
- }
72
- return `${time} ${daysBack === 1 ? "the day" : `${daysBack} days`} before`;
73
- };
74
- // One stored alarm in words: "30 minutes before start", "at start",
75
- // "1 hour after end", "at 2026-10-02T09:00:00Z" (absolute trigger). On an
76
- // all-day event a reminder before the start is shown as the clock time it
77
- // fires ("09:00 the day before").
78
- export const describeAlarm = (alarm, allDay = false) => {
79
- const trigger = alarm.trigger ?? "";
80
- const seconds = durationSeconds(trigger);
81
- if (seconds === undefined) {
82
- return trigger ? `at ${icalDateToIso(trigger)}` : "unknown trigger";
83
- }
84
- const anchor = RELATED_END_RE.test(alarm.triggerParams ?? "")
85
- ? "end"
86
- : "start";
87
- if (allDay &&
88
- anchor === "start" &&
89
- seconds <= 0 &&
90
- seconds % SECONDS_PER_MINUTE === 0) {
91
- return allDayFiring(-seconds / SECONDS_PER_MINUTE);
92
- }
93
- if (seconds === 0) {
94
- return `at ${anchor}`;
95
- }
96
- return `${formatSeconds(Math.abs(seconds))} ${seconds < 0 ? "before" : "after"} ${anchor}`;
97
- };