@moltenship/calendar 1.0.0-rc.2 → 2.0.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.
- package/README.md +27 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/docs/accessibility.md +305 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +116 -0
- package/docs/agents/connect.md +444 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +511 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +355 -0
- package/docs/annotations.md +198 -0
- package/docs/api/changes.md +264 -0
- package/docs/api/components.md +245 -0
- package/docs/api/dnd-kit.md +265 -0
- package/docs/api/events.md +153 -0
- package/docs/api/primitives.md +218 -0
- package/docs/api/store.md +92 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +576 -0
- package/docs/comparison.md +278 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +163 -0
- package/docs/concepts/how-it-works.md +112 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +168 -0
- package/docs/customization.md +271 -0
- package/docs/frameworks.md +116 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/ics/feed.md +484 -0
- package/docs/ics/import.md +183 -0
- package/docs/ics/reference.md +482 -0
- package/docs/ics.md +142 -0
- package/docs/index.md +149 -0
- package/docs/installation.md +209 -0
- package/docs/interactions.md +441 -0
- package/docs/llms.txt +99 -0
- package/docs/migrating-to-2.md +497 -0
- package/docs/quick-start.md +163 -0
- package/docs/recurrence/calendar.md +598 -0
- package/docs/recurrence/model.md +128 -0
- package/docs/recurrence/reference.md +547 -0
- package/docs/recurrence.md +122 -0
- package/docs/stylex.md +290 -0
- package/docs/temporal/daylight-saving-time.md +172 -0
- package/docs/temporal/month-grid.md +119 -0
- package/docs/temporal/reference.md +167 -0
- package/docs/temporal.md +105 -0
- package/docs/testing.md +600 -0
- package/docs/theme-builder.md +82 -0
- package/docs/theming.md +275 -0
- package/docs/undo-redo.md +347 -0
- package/docs/views/agenda.md +222 -0
- package/docs/views/custom-views.md +195 -0
- package/docs/views/month.md +110 -0
- package/docs/views/resource-columns.md +265 -0
- package/docs/views/resource-timeline.md +226 -0
- package/docs/views/scrolling.md +193 -0
- package/docs/views/week-and-day.md +258 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +42 -14
- package/skills/moltenship-time/SKILL.md +77 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +175 -0
- package/skills/moltenship-time/references/mistakes.md +100 -0
- package/skills/moltenship-time/references/solid.md +213 -0
- package/skills/moltenship-time/references/state.md +129 -0
- 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/react/agents/deleting
|
|
6
|
+
|
|
7
|
+
> Live example: see it at https://time.molten.sh/docs/react/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).
|