@moltenship/calendar 1.0.0-rc.2 → 2.0.0-beta.1

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 (70) hide show
  1. package/README.md +24 -4
  2. package/dist/index.d.mts +2 -2
  3. package/docs/accessibility.md +304 -0
  4. package/docs/agents/changes.md +449 -0
  5. package/docs/agents/coding-agents.md +117 -0
  6. package/docs/agents/connect.md +435 -0
  7. package/docs/agents/deleting.md +296 -0
  8. package/docs/agents/reference.md +512 -0
  9. package/docs/agents/server.md +317 -0
  10. package/docs/agents/webmcp.md +153 -0
  11. package/docs/agents.md +353 -0
  12. package/docs/annotations.md +196 -0
  13. package/docs/api/changes.md +248 -0
  14. package/docs/api/dnd-kit.md +267 -0
  15. package/docs/api/events.md +152 -0
  16. package/docs/api/ics.md +524 -0
  17. package/docs/api/primitives.md +168 -0
  18. package/docs/api/react.md +236 -0
  19. package/docs/api/recurrence.md +586 -0
  20. package/docs/api/solid.md +460 -0
  21. package/docs/api/store.md +92 -0
  22. package/docs/api/temporal.md +172 -0
  23. package/docs/api.md +57 -0
  24. package/docs/availability.md +573 -0
  25. package/docs/comparison.md +279 -0
  26. package/docs/concepts/anatomy.md +73 -0
  27. package/docs/concepts/events.md +164 -0
  28. package/docs/concepts/how-it-works.md +95 -0
  29. package/docs/concepts/recurrence.md +127 -0
  30. package/docs/concepts/state.md +244 -0
  31. package/docs/concepts/time.md +170 -0
  32. package/docs/guides/dnd-kit.md +333 -0
  33. package/docs/guides/google-calendar-sync.md +1246 -0
  34. package/docs/guides/google-calendar.md +367 -0
  35. package/docs/guides/ics.md +486 -0
  36. package/docs/guides/motion.md +414 -0
  37. package/docs/guides/nextjs-app-router.md +630 -0
  38. package/docs/guides/nextjs.md +149 -0
  39. package/docs/guides/performance.md +103 -0
  40. package/docs/guides/recurring-events.md +583 -0
  41. package/docs/guides/tanstack-query.md +485 -0
  42. package/docs/index.md +118 -0
  43. package/docs/installation.md +194 -0
  44. package/docs/interactions.md +408 -0
  45. package/docs/llms.txt +86 -0
  46. package/docs/migrating-to-2.md +322 -0
  47. package/docs/quick-start.md +159 -0
  48. package/docs/stylex.md +265 -0
  49. package/docs/testing.md +581 -0
  50. package/docs/theme-builder.md +81 -0
  51. package/docs/theming.md +169 -0
  52. package/docs/undo-redo.md +339 -0
  53. package/docs/views/agenda.md +221 -0
  54. package/docs/views/custom-views.md +192 -0
  55. package/docs/views/month.md +109 -0
  56. package/docs/views/resource-columns.md +261 -0
  57. package/docs/views/resource-timeline.md +225 -0
  58. package/docs/views/scrolling.md +192 -0
  59. package/docs/views/week-and-day.md +257 -0
  60. package/docs/views/year.md +138 -0
  61. package/docs/views.md +69 -0
  62. package/package.json +41 -14
  63. package/skills/moltenship-time/SKILL.md +75 -0
  64. package/skills/moltenship-time/references/agent-ready.md +272 -0
  65. package/skills/moltenship-time/references/changes.md +188 -0
  66. package/skills/moltenship-time/references/compose.md +168 -0
  67. package/skills/moltenship-time/references/mistakes.md +98 -0
  68. package/skills/moltenship-time/references/solid.md +202 -0
  69. package/skills/moltenship-time/references/state.md +129 -0
  70. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,296 @@
1
+ # Deleting
2
+
3
+ Let an agent delete an event only after the person on the page says yes.
4
+
5
+ Source: https://time.molten.sh/docs/agents/deleting
6
+
7
+ > Live example: see it at https://time.molten.sh/docs/agents/deleting
8
+
9
+ A deleted event is gone from the calendar, so an agent can't delete until you turn it on. Two
10
+ switches are involved, and a careful app sets both:
11
+
12
+ 1. `allowAgentDelete` on `Root`. Without it the calendar has no `deleteEvent` action, for every
13
+ agent and whatever the bridge allows, and it refuses a delete an agent causes any other way,
14
+ with [one exception](#a-delete-button-of-yours): a button of yours that waits before it deletes.
15
+ 2. The bridge's `allow`, which holds the step until the person answers.
16
+
17
+ This page's samples import the `Calendar`, `meetings` and `weekRules` that the
18
+ [Quick start](../quick-start.md) puts in `calendar.tsx`, and `applyChange` and `timedOnly` from
19
+ `agent-save.ts` in [Connect an agent](./connect.md#name-the-calendar).
20
+
21
+ ## Off by default
22
+
23
+ A calendar without `allowAgentDelete` doesn't offer the action. `deleteEvent` isn't in its
24
+ `actions`, `describeCalendar` reports `canDelete: false`, and a step that asks for it fails with
25
+ the bridge's message for an action a component doesn't have:
26
+
27
+ ```json
28
+ {
29
+ "ok": false,
30
+ "error": {
31
+ "step": 0,
32
+ "message": "calendar c1 takes no deleteEvent now. It takes: createEvent, describeCalendar, getChange, goToDate, listEvents, moveEvent, navigateNext, navigatePrevious, navigateToday, resizeEvent, selectEvent, setTimeZone, setView, updateEvent."
33
+ },
34
+ "steps": [],
35
+ "appeared": [],
36
+ "values": {}
37
+ }
38
+ ```
39
+
40
+ So a model that reads the calendar first never proposes a delete it can't make. A read-only
41
+ calendar, one without `onEventChange`, has no `deleteEvent` either, whatever `allowAgentDelete`
42
+ says.
43
+
44
+ > **A new calendar lists every action for a moment**
45
+ >
46
+ > The actions a calendar doesn't offer leave its `actions` one microtask after it mounts. A snapshot
47
+ > taken in the same task as the mount still lists `deleteEvent` and, on a read-only calendar, the
48
+ > actions that change events. No agent reads a page that fast, but a test that mounts a calendar and
49
+ > reads `actions` at once does: await a microtask first. A `deleteEvent` called in that moment
50
+ > deletes nothing: it fails with `calendar-event-change-rejected: agent-delete-not-allowed`.
51
+
52
+ ## Ask the person
53
+
54
+ `allow` can return a promise. The bridge holds the step until it settles, so `allow` is where the
55
+ question goes. This bridge puts the request in a small store and resolves when the person answers:
56
+
57
+ ```ts title="agent-confirm.ts"
58
+ "use client";
59
+
60
+ import { createAgent } from "@ui-sdk/react/agent";
61
+
62
+ /** A delete the agent asked for, waiting for the person's answer. */
63
+ export interface DeleteRequest {
64
+ readonly answer: (allowed: boolean) => void;
65
+ readonly eventId: string;
66
+ }
67
+
68
+ let request: DeleteRequest | null = null;
69
+ const listeners = new Set<() => void>();
70
+
71
+ function setRequest(next: DeleteRequest | null): void {
72
+ request = next;
73
+ for (const listener of listeners) listener();
74
+ }
75
+
76
+ /** The request on screen, for `useSyncExternalStore`. */
77
+ export const deleteRequest = {
78
+ getSnapshot: () => request,
79
+ subscribe: (listener: () => void) => {
80
+ listeners.add(listener);
81
+ return () => void listeners.delete(listener);
82
+ },
83
+ };
84
+
85
+ /** The event a step names. `allow` runs before the calendar checks the step's arguments. */
86
+ function eventIdOf(args: readonly unknown[]): string {
87
+ const input = args[0];
88
+ if (typeof input !== "object" || input === null || !("eventId" in input)) return "";
89
+ return typeof input.eventId === "string" || typeof input.eventId === "number"
90
+ ? String(input.eventId)
91
+ : "";
92
+ }
93
+
94
+ export const agent = createAgent({
95
+ allow: ({ action, args, component }, { signal }) => {
96
+ if (component !== "calendar") return false;
97
+ if (action !== "deleteEvent") return true;
98
+ // The bridge holds this step, and every call after it, until the promise settles.
99
+ return new Promise<boolean>((resolve) => {
100
+ const answer = (allowed: boolean) => {
101
+ setRequest(null);
102
+ resolve(allowed);
103
+ };
104
+ // Nobody answered in time, or the turn was stopped: take the question down.
105
+ signal.addEventListener("abort", () => answer(false), { once: true });
106
+ setRequest({ answer, eventId: eventIdOf(args) });
107
+ });
108
+ },
109
+ // How long a step waits for the answer. Five minutes when left out.
110
+ timeout: 60_000,
111
+ });
112
+ ```
113
+
114
+ The calendar turns deleting on and draws the question from that store:
115
+
116
+ ```tsx title="agent-confirm-calendar.tsx"
117
+ "use client";
118
+
119
+ import { useEffect, useState, useSyncExternalStore } from "react";
120
+
121
+ import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
122
+ import { Button } from "@/components/ui/button";
123
+
124
+ import { deleteRequest } from "./agent-confirm";
125
+ import { applyChange, timedOnly } from "./agent-save";
126
+ import { Calendar, meetings as initialMeetings, weekRules } from "./calendar";
127
+
128
+ export function ConfirmingCalendar() {
129
+ const [meetings, setMeetings] = useState(initialMeetings);
130
+ const pending = useSyncExternalStore(
131
+ deleteRequest.subscribe,
132
+ deleteRequest.getSnapshot,
133
+ () => null,
134
+ );
135
+ const meeting = meetings.find(({ id }) => id === pending?.eventId);
136
+ // The calendar left the page with a question open: the answer is no.
137
+ useEffect(() => () => deleteRequest.getSnapshot()?.answer(false), []);
138
+
139
+ return (
140
+ <div className="flex h-full flex-col">
141
+ {pending === null ? null : (
142
+ <div
143
+ aria-label="The agent asks to delete a meeting"
144
+ className="flex flex-wrap items-center justify-between gap-2 border-b px-4 py-2 text-sm"
145
+ role="alertdialog"
146
+ >
147
+ <p>
148
+ The agent wants to delete{" "}
149
+ <strong>{meeting === undefined ? `"${pending.eventId}"` : meeting.title}</strong>.
150
+ </p>
151
+ <div className="flex gap-2">
152
+ <Button autoFocus onClick={() => pending.answer(false)} variant="outline">
153
+ Keep it
154
+ </Button>
155
+ <Button onClick={() => pending.answer(true)} variant="destructive">
156
+ Delete
157
+ </Button>
158
+ </div>
159
+ </div>
160
+ )}
161
+ <Calendar.Root
162
+ label="Team calendar"
163
+ // Without this the calendar has no `deleteEvent` action, whatever `allow` answers.
164
+ allowAgentDelete
165
+ events={meetings}
166
+ onEventChange={(change, detail) =>
167
+ setMeetings((current) => applyChange(current, change, detail))
168
+ }
169
+ policies={[timedOnly]}
170
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
171
+ defaultTimeZone="Europe/Berlin"
172
+ locale="en-US"
173
+ weekRules={weekRules}
174
+ >
175
+ <Calendar.Frame className="flex min-h-0 flex-1 flex-col">
176
+ <CalendarToolbar calendar={Calendar} />
177
+ <Calendar.Viewport className="min-h-0 flex-1">
178
+ <Calendar.ActiveView />
179
+ </Calendar.Viewport>
180
+ </Calendar.Frame>
181
+ </Calendar.Root>
182
+ </div>
183
+ );
184
+ }
185
+ ```
186
+
187
+ What happens for each answer:
188
+
189
+ | The person | The step | Your `onEventChange` |
190
+ | ---------------------- | --------------------------------------------------------------------- | ----------------------------------------------------- |
191
+ | Chooses "Delete" | Succeeds. Its `result` is the change, with `proposed: null` | Gets `{ cause: "delete", eventId }`, `input: "agent"` |
192
+ | Chooses "Keep it" | Fails with `The app refused deleteEvent on c1.` | Isn't called |
193
+ | Doesn't answer in time | Fails once `timeout` passes, and `signal` aborts so the question goes | Isn't called |
194
+
195
+ A few things to get right:
196
+
197
+ - **Say what will be deleted.** `args[0]` is the step's input as the agent sent it, which should
198
+ be `{ eventId }`. `allow` runs before the calendar checks it, so `eventIdOf` reads it as unknown
199
+ input. Look the event up and show its title, as the example does, since the person can't judge
200
+ an ID.
201
+ - **Take the question down on `signal`.** It aborts when the wait times out and when the turn is
202
+ stopped. A question left on screen would answer a step that's already over.
203
+ - **Later calls wait.** While `allow` is pending, `act` and `query` calls on the same bridge queue
204
+ behind it. `snapshot` still answers.
205
+ - **The calendar is asked first.** On a `Root` without `allowAgentDelete` a `deleteEvent` step
206
+ fails before the bridge calls `allow`, so the person is never asked about a delete that can't
207
+ run.
208
+ - **Your policies still run.** After the person says yes, the delete is a proposal like any other.
209
+ A policy can refuse it, and the agent's step fails with the policy's reason.
210
+ - **`timeout` is yours to choose.** A step waits five minutes for `allow` when you don't set it.
211
+
212
+ ## A delete button of yours
213
+
214
+ An agent can press a ui-sdk button your app rendered, with a `press` step. When that button's
215
+ handler proposes a delete, the delete is the agent's. Your policies and `onEventChange` get it
216
+ with `detail.input` of `"agent"`, whatever input the handler passed:
217
+
218
+ ```tsx title="remove-meeting.tsx"
219
+ "use client";
220
+
221
+ import { Button } from "@ui-sdk/react/button";
222
+
223
+ import { Calendar, type Meeting } from "./calendar";
224
+
225
+ // A button of your own, anywhere inside Root. It's a ui-sdk button, so an agent can press it.
226
+ export function RemoveMeeting({ meeting }: { readonly meeting: Meeting }) {
227
+ const { proposeEventChange } = Calendar.useCalendarActions();
228
+
229
+ return (
230
+ <Button
231
+ // A person's click proposes the delete as your code: `input: "api"`. An agent's press
232
+ // proposes the same delete as the agent: `input: "agent"`.
233
+ onClick={() => void proposeEventChange({ cause: "delete", eventId: meeting.id })}
234
+ >
235
+ Remove {meeting.title}
236
+ </Button>
237
+ );
238
+ }
239
+ ```
240
+
241
+ - **Without `allowAgentDelete`, the calendar refuses it.** The press succeeds as a step and
242
+ deletes nothing. The proposal ends `rejected` with the reason `agent-delete-not-allowed`, your
243
+ `onEventChange` isn't called, and `onEventChangeResult` hears the refusal with `input: "agent"`.
244
+ A person's click on the same button deletes as it did.
245
+ - **With `allowAgentDelete`, the press is what your `allow` has to hold.** The step is `press` on
246
+ a `button`, not `deleteEvent` on a calendar. The `allow` above refuses every component but the
247
+ calendar, so it refuses this press. An `allow` that lets presses through would let this one
248
+ delete without the question: ask the person for it as well, or put the button inside an element
249
+ with `data-agent-hidden`, which keeps it from agents as
250
+ [Connect an agent](./connect.md#decide-what-an-agent-may-do) does for a whole calendar.
251
+
252
+ The same holds for every change a pressed button proposes: a policy that refuses agents refuses
253
+ it. [Who made a change](./changes.md#two-kinds-of-change) has the rule.
254
+
255
+ All of this is about a handler that proposes the delete before it returns. A button that waits
256
+ first, for a confirmation dialog of its own or a request, proposes later, and by then the calendar
257
+ can't tell the agent started it: the delete reads as `"api"` and goes through without
258
+ `allowAgentDelete`. Keep a button like that from agents with `data-agent-hidden`, or refuse its
259
+ press in `allow`.
260
+
261
+ ## Stopping a turn
262
+
263
+ When the person stops the agent while a question is open, pass an `AbortSignal` to `act`. The
264
+ waiting step fails with `deleteEvent on c1 was cancelled.`, `allow`'s `signal` aborts so the
265
+ question comes down, and the steps after it don't run:
266
+
267
+ ```ts title="agent-stop.ts"
268
+ "use client";
269
+
270
+ import { agent } from "./agent-confirm";
271
+
272
+ let turn = new AbortController();
273
+
274
+ /** A delete the person can stop while its question is open. */
275
+ export function deleteEvent(eventId: string) {
276
+ return agent.act(
277
+ { steps: [{ ref: "Team calendar", action: "deleteEvent", args: [{ eventId }] }] },
278
+ { signal: turn.signal },
279
+ );
280
+ }
281
+
282
+ /** For your Stop button: ends the step that waits, and takes its question down. */
283
+ export function stop(): void {
284
+ turn.abort();
285
+ turn = new AbortController();
286
+ }
287
+ ```
288
+
289
+ ## Undo instead of asking
290
+
291
+ Asking first isn't the only shape. For a calendar where a wrong delete is cheap to reverse, let the
292
+ delete run and offer an undo: an [event history](./changes.md#undo-an-agents-changes) with
293
+ `inputs: ["agent"]` brings the deleted event back as it was. Keep the question for deletes your app
294
+ can't take back, such as one that emails the guests.
295
+
296
+ Next, hand the tools to a browser's agent with [WebMCP](./webmcp.md).