@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,449 @@
|
|
|
1
|
+
# Who made a change
|
|
2
|
+
|
|
3
|
+
Tell an agent's change from a person's, refuse it with a policy, and undo it without touching what the person did.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/agents/changes
|
|
6
|
+
|
|
7
|
+
> Live example: see it at https://time.molten.sh/docs/react/agents/changes
|
|
8
|
+
|
|
9
|
+
An agent's change reaches the same handlers as a person's, with a detail that says who made it.
|
|
10
|
+
You can log it, refuse it, and take it back. This page's samples import the `Calendar`, `Meeting`,
|
|
11
|
+
`meetings` and `weekRules` that the [Quick start](../quick-start.md) puts in `calendar.tsx`, and
|
|
12
|
+
the bridge in `agent.ts` from [Connect an agent](./connect.md).
|
|
13
|
+
|
|
14
|
+
## Two kinds of change
|
|
15
|
+
|
|
16
|
+
The calendar tells an agent apart from a person in two places, one for each kind of change:
|
|
17
|
+
|
|
18
|
+
| What changed | Handler on `Root` | Where it says who | An agent's value |
|
|
19
|
+
| ----------------------------------------------- | ----------------------------------------------- | ----------------- | ---------------- |
|
|
20
|
+
| The calendar's state: view, date, time zone | `onViewChange`, `onAnchorDateChange`, and so on | `detail.source` | `"agent"` |
|
|
21
|
+
| An event: a move, an update, a create, a delete | `onEventChange` and `onEventChangeResult` | `detail.input` | `"agent"` |
|
|
22
|
+
|
|
23
|
+
`detail.source` is one of `"agent"`, `"mouse"`, `"touch"`, `"pen"`, `"keyboard"`, `"virtual"` or
|
|
24
|
+
`"programmatic"`. `"keyboard"` is a person's keys: a toolbar button pressed with Enter, and also
|
|
25
|
+
arrow-key navigation, moving focus between cells and events, and expanding a resource.
|
|
26
|
+
`"virtual"` is a click with no pointer or key behind it, which may come from assistive technology.
|
|
27
|
+
`"programmatic"` is your own code.
|
|
28
|
+
|
|
29
|
+
`detail.input` is one of `"agent"`, `"pointer"`, `"keyboard"` or `"api"`. `"api"` is your own
|
|
30
|
+
`proposeEventChange` call. An agent's `createEvent` and `updateEvent` also bring `detail.fields`:
|
|
31
|
+
the title and the fields it sent, which
|
|
32
|
+
[your handler stores](./connect.md#save-what-the-agent-sent).
|
|
33
|
+
|
|
34
|
+
Anything a step causes is the agent's, not only the calendar's own actions. An agent can press a
|
|
35
|
+
ui-sdk button your app rendered. If its handler calls `proposeEventChange` or an action such as
|
|
36
|
+
`setView`, the handlers above hear `"agent"`, whatever input your code passed, and so do your
|
|
37
|
+
policies. A person's click on the same button reads as before.
|
|
38
|
+
|
|
39
|
+
That covers what the button's handler does before it returns. Work the handler starts and finishes
|
|
40
|
+
later, after an `await`, in a timer or in an effect, reads as your own code: `"api"` for a proposal
|
|
41
|
+
and `"programmatic"` for a state change. ui-sdk tracks the agent for the length of the press and no
|
|
42
|
+
longer. So a button that waits before it changes the calendar, as one that asks "are you sure?"
|
|
43
|
+
first, isn't covered by a policy on `"agent"`. Keep such a button from agents: put it inside an
|
|
44
|
+
element with `data-agent-hidden`, or refuse the press in the bridge's `allow`.
|
|
45
|
+
|
|
46
|
+
This calendar logs both:
|
|
47
|
+
|
|
48
|
+
```tsx title="agent-audit.tsx"
|
|
49
|
+
"use client";
|
|
50
|
+
|
|
51
|
+
import { createEventHistory } from "@moltenship/calendar";
|
|
52
|
+
import { useState } from "react";
|
|
53
|
+
|
|
54
|
+
import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
|
|
55
|
+
|
|
56
|
+
import { weekdaysForAgents } from "./agent-policy";
|
|
57
|
+
import { applyChange, timedOnly, type MeetingChange } from "./agent-save";
|
|
58
|
+
import { UndoAgentChange } from "./agent-undo";
|
|
59
|
+
import { Calendar, meetings as initialMeetings, weekRules, type Meeting } from "./calendar";
|
|
60
|
+
|
|
61
|
+
function describe(change: MeetingChange): string {
|
|
62
|
+
if (change.cause === "delete") return `deleted ${change.eventId}`;
|
|
63
|
+
if (change.cause === "create") return "created a meeting";
|
|
64
|
+
// "update" is an agent's `updateEvent`: a title, times, or both.
|
|
65
|
+
const verb =
|
|
66
|
+
change.cause === "move" ? "moved" : change.cause === "update" ? "updated" : "resized";
|
|
67
|
+
return `${verb} ${change.eventId}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function AuditedCalendar({ onLog }: { readonly onLog: (line: string) => void }) {
|
|
71
|
+
const [meetings, setMeetings] = useState(initialMeetings);
|
|
72
|
+
// The meeting each create became, by change ID, so the history can find it to undo.
|
|
73
|
+
const [createdIds] = useState(() => new Map<string, string>());
|
|
74
|
+
const [history] = useState(() =>
|
|
75
|
+
createEventHistory<Meeting, string, never>({
|
|
76
|
+
// Only what an agent did: undo takes back its changes and leaves the person's alone.
|
|
77
|
+
inputs: ["agent"],
|
|
78
|
+
createdEventId: (change, events) => {
|
|
79
|
+
const id = createdIds.get(change.id);
|
|
80
|
+
return id !== undefined && events.get(id) !== undefined ? id : undefined;
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<Calendar.Root
|
|
87
|
+
label="Team calendar"
|
|
88
|
+
events={meetings}
|
|
89
|
+
// `detail.input` says who proposed the change: "pointer", "keyboard", "api" or "agent".
|
|
90
|
+
onEventChange={(change, detail) => {
|
|
91
|
+
const id =
|
|
92
|
+
change.cause === "create" ? (change.event?.id ?? crypto.randomUUID()) : undefined;
|
|
93
|
+
if (id !== undefined) createdIds.set(change.id, id);
|
|
94
|
+
setMeetings((current) => applyChange(current, change, detail, id));
|
|
95
|
+
onLog(`${detail.input} ${describe(change)}`);
|
|
96
|
+
}}
|
|
97
|
+
// How every proposal ended, a policy's refusal included, with the same detail.
|
|
98
|
+
onEventChangeResult={(result, detail) => {
|
|
99
|
+
history.record(result, detail);
|
|
100
|
+
if (result.status === "rejected") onLog(`${detail.input} was refused: ${result.reason}`);
|
|
101
|
+
}}
|
|
102
|
+
// State changes say where they came from too: "agent", "mouse", "keyboard", "programmatic".
|
|
103
|
+
onAnchorDateChange={(date, detail) => onLog(`${detail.source} went to ${date.toString()}`)}
|
|
104
|
+
onViewChange={(view, detail) => onLog(`${detail.source} switched to the ${view} view`)}
|
|
105
|
+
policies={[timedOnly, weekdaysForAgents]}
|
|
106
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
107
|
+
defaultTimeZone="Europe/Berlin"
|
|
108
|
+
locale="en-US"
|
|
109
|
+
weekRules={weekRules}
|
|
110
|
+
>
|
|
111
|
+
<Calendar.Frame className="flex h-full flex-col">
|
|
112
|
+
<CalendarToolbar calendar={Calendar}>
|
|
113
|
+
<UndoAgentChange
|
|
114
|
+
history={history}
|
|
115
|
+
onRestore={({ id, title }) =>
|
|
116
|
+
setMeetings((current) =>
|
|
117
|
+
current.map((meeting) => (meeting.id === id ? { ...meeting, title } : meeting)),
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
/>
|
|
121
|
+
</CalendarToolbar>
|
|
122
|
+
<Calendar.Viewport className="min-h-0 flex-1">
|
|
123
|
+
<Calendar.ActiveView />
|
|
124
|
+
</Calendar.Viewport>
|
|
125
|
+
</Calendar.Frame>
|
|
126
|
+
</Calendar.Root>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`applyChange` and `timedOnly` come from `agent-save.ts` in
|
|
132
|
+
[Connect an agent](./connect.md#name-the-calendar). The policy and the undo button are
|
|
133
|
+
below.
|
|
134
|
+
|
|
135
|
+
After an agent moves the design review and renames the team lunch, a person clicks Next, and the
|
|
136
|
+
agent switches to the month view, the log reads:
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
agent moved review
|
|
140
|
+
agent updated lunch
|
|
141
|
+
mouse went to 2026-10-15
|
|
142
|
+
agent switched to the month view
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`change.cause` is `"update"` for an agent's `updateEvent`, whether it changed the title, the times
|
|
146
|
+
or both. A person's drag makes a `"move"` or a resize.
|
|
147
|
+
|
|
148
|
+
## Refuse an agent's change
|
|
149
|
+
|
|
150
|
+
A [policy](../interactions.md#policies) sees every proposed change before your handler does, and
|
|
151
|
+
its second argument has the same `detail`. This one lets a person book a Saturday and refuses an
|
|
152
|
+
agent that tries:
|
|
153
|
+
|
|
154
|
+
```ts title="agent-policy.ts"
|
|
155
|
+
import type { CalendarPolicy } from "@moltenship/calendar";
|
|
156
|
+
|
|
157
|
+
import type { Meeting } from "./calendar";
|
|
158
|
+
|
|
159
|
+
// An agent books weekdays only. A person can still drag a meeting onto Saturday: the policy
|
|
160
|
+
// reads who proposed the change.
|
|
161
|
+
export const weekdaysForAgents: CalendarPolicy<Meeting, string, never> = (
|
|
162
|
+
{ proposed },
|
|
163
|
+
{ detail, timeZone },
|
|
164
|
+
) => {
|
|
165
|
+
if (detail?.input !== "agent" || proposed === null || proposed.kind !== "timed") {
|
|
166
|
+
return { type: "accept" };
|
|
167
|
+
}
|
|
168
|
+
const { dayOfWeek } = proposed.start.toZonedDateTimeISO(timeZone);
|
|
169
|
+
return dayOfWeek >= 6
|
|
170
|
+
? { type: "reject", reason: "agents-book-weekdays-only" }
|
|
171
|
+
: { type: "accept" };
|
|
172
|
+
};
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Pass it to `Root` with your other policies, as `policies={[timedOnly, weekdaysForAgents]}` above.
|
|
176
|
+
The agent's step fails with the policy's reason, and your `onEventChange` isn't called:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"ok": false,
|
|
181
|
+
"error": {
|
|
182
|
+
"step": 1,
|
|
183
|
+
"message": "calendar-event-change-rejected: agents-book-weekdays-only"
|
|
184
|
+
},
|
|
185
|
+
"steps": [{ "step": 0, "ref": "c1" }],
|
|
186
|
+
"appeared": [],
|
|
187
|
+
"values": {}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Write the reason for the model that reads it. `agents-book-weekdays-only` tells it what to try
|
|
192
|
+
next; `rejected` doesn't. An agent can't ask beforehand whether a change would pass, so the reason
|
|
193
|
+
is how it learns your rules.
|
|
194
|
+
|
|
195
|
+
A few things to know:
|
|
196
|
+
|
|
197
|
+
- **`detail` is optional in a policy.** It's `undefined` when your own code calls a policy outside
|
|
198
|
+
a proposal, so read it as `detail?.input`.
|
|
199
|
+
- **A policy can read what the agent sent.** `detail?.fields` has the title and fields of a
|
|
200
|
+
`createEvent` or an `updateEvent`, before anything is saved.
|
|
201
|
+
- **Each policy runs once for an agent's change.** A drag or a keyboard move asks your policies
|
|
202
|
+
more often: for each preview, then for the drop. Every one of those calls has the `input` the
|
|
203
|
+
drop will have, `"pointer"` or `"keyboard"`, so a rule on `detail?.input` marks the preview the
|
|
204
|
+
way it will decide the drop.
|
|
205
|
+
- **`onEventChangeResult` hears the refusal.** It gets `{ status: "rejected", reason }` with
|
|
206
|
+
`detail.input` of `"agent"`, once. The example's log adds
|
|
207
|
+
`agent was refused: agents-book-weekdays-only`.
|
|
208
|
+
- **A policy that returns a promise can't fail the step.** The step returns the change with
|
|
209
|
+
`status: "validating"`, and the agent reads the refusal from `getChange`, as for a
|
|
210
|
+
[save that takes a while](#saves-that-take-a-while). Where you can, decide an agent's changes
|
|
211
|
+
with a policy that answers at once.
|
|
212
|
+
|
|
213
|
+
Your handler can refuse too, by throwing. The agent then reads `handler-error` and your error's
|
|
214
|
+
message, as in `calendar-event-change-rejected: handler-error (This slot was just taken)`. Write
|
|
215
|
+
that message for the model as well, and keep anything private out of it.
|
|
216
|
+
|
|
217
|
+
The same policy works for every other input. `detail?.input === "keyboard"` is a keyboard move, and
|
|
218
|
+
`detail?.history` is `"undo"` or `"redo"` for a change the [history](../undo-redo.md) proposes.
|
|
219
|
+
|
|
220
|
+
## Refuse a state change
|
|
221
|
+
|
|
222
|
+
A state handler's detail has `cancel()`. This `Root` keeps an agent out of the month view:
|
|
223
|
+
|
|
224
|
+
```tsx title="agent-week-only.tsx"
|
|
225
|
+
"use client";
|
|
226
|
+
|
|
227
|
+
import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
|
|
228
|
+
|
|
229
|
+
import { Calendar, meetings, weekRules } from "./calendar";
|
|
230
|
+
|
|
231
|
+
export function WeekOnlyForAgents() {
|
|
232
|
+
return (
|
|
233
|
+
<Calendar.Root
|
|
234
|
+
label="Team calendar"
|
|
235
|
+
events={meetings}
|
|
236
|
+
onViewChange={(view, detail) => {
|
|
237
|
+
// A person can still open the month view.
|
|
238
|
+
if (detail.source === "agent" && view === "month") detail.cancel();
|
|
239
|
+
}}
|
|
240
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
241
|
+
defaultTimeZone="Europe/Berlin"
|
|
242
|
+
locale="en-US"
|
|
243
|
+
weekRules={weekRules}
|
|
244
|
+
>
|
|
245
|
+
<Calendar.Frame className="flex h-full flex-col">
|
|
246
|
+
<CalendarToolbar calendar={Calendar} />
|
|
247
|
+
<Calendar.Viewport className="min-h-0 flex-1">
|
|
248
|
+
<Calendar.ActiveView />
|
|
249
|
+
</Calendar.Viewport>
|
|
250
|
+
</Calendar.Frame>
|
|
251
|
+
</Calendar.Root>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
A cancelled change doesn't fail the step. The call returns `ok: true` and the step has no
|
|
257
|
+
`changes`, so the agent sees that nothing happened. To fail the step with a message instead,
|
|
258
|
+
refuse the action in the bridge's [`allow`](./connect.md#decide-what-an-agent-may-do).
|
|
259
|
+
|
|
260
|
+
For a [controlled](../concepts/state.md#controlled) value, not storing the new value does the same
|
|
261
|
+
as `cancel()`.
|
|
262
|
+
|
|
263
|
+
## Undo an agent's changes
|
|
264
|
+
|
|
265
|
+
An [event history](../undo-redo.md) records changes and undoes them through the same pipeline.
|
|
266
|
+
`inputs: ["agent"]` makes one that records an agent's changes only, so its undo never takes back a
|
|
267
|
+
drag. `AuditedCalendar` in `agent-audit.tsx` creates it with
|
|
268
|
+
`createEventHistory<Meeting, string, never>({ inputs: ["agent"], createdEventId })` and records
|
|
269
|
+
into it from `onEventChangeResult` with `history.record(result, detail)`.
|
|
270
|
+
|
|
271
|
+
The button reads the history with `useCalendarHistory`, anywhere inside `Root`:
|
|
272
|
+
|
|
273
|
+
```tsx title="agent-undo.tsx"
|
|
274
|
+
"use client";
|
|
275
|
+
|
|
276
|
+
import { useCalendarHistory, type EventHistory } from "@moltenship/calendar";
|
|
277
|
+
|
|
278
|
+
import { Button } from "@/components/ui/button";
|
|
279
|
+
|
|
280
|
+
import type { Meeting } from "./calendar";
|
|
281
|
+
|
|
282
|
+
// Anywhere inside Root. The history it's given holds an agent's changes only, so this never
|
|
283
|
+
// undoes a drag.
|
|
284
|
+
export function UndoAgentChange({
|
|
285
|
+
history,
|
|
286
|
+
onRestore,
|
|
287
|
+
}: {
|
|
288
|
+
readonly history: EventHistory<Meeting, string, never>;
|
|
289
|
+
/** Hears the meeting as it was before the step that was undone. */
|
|
290
|
+
readonly onRestore: (before: Meeting) => void;
|
|
291
|
+
}) {
|
|
292
|
+
const { canUndo, past, undo } = useCalendarHistory(history);
|
|
293
|
+
|
|
294
|
+
return (
|
|
295
|
+
<Button
|
|
296
|
+
disabled={!canUndo}
|
|
297
|
+
onClick={async () => {
|
|
298
|
+
// The step `undo` takes is the last. Its first change has your record as it was before.
|
|
299
|
+
const before = past.at(-1)?.changes[0]?.event;
|
|
300
|
+
const outcome = await undo();
|
|
301
|
+
// The history puts times and resources back. It doesn't know your fields, so a title
|
|
302
|
+
// the agent changed is yours to restore.
|
|
303
|
+
if (outcome.status === "committed" && before !== undefined && before !== null) {
|
|
304
|
+
onRestore(before);
|
|
305
|
+
}
|
|
306
|
+
}}
|
|
307
|
+
variant="ghost"
|
|
308
|
+
>
|
|
309
|
+
Undo the agent
|
|
310
|
+
</Button>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
The undo is a proposal of its own. When a person clicks the button, your `onEventChange` gets it
|
|
316
|
+
with `detail.input` of `"api"` and `detail.history` of `"undo"`, and the log above adds
|
|
317
|
+
`api moved review`. It isn't the agent's, so a policy that refuses agents doesn't refuse it.
|
|
318
|
+
|
|
319
|
+
It is the agent's when the agent presses the button. Had this one been a ui-sdk button, a `press`
|
|
320
|
+
step on it would propose the undo with `input: "agent"` and `history: "undo"`, and
|
|
321
|
+
`weekdaysForAgents` would have its say. Undoing a create proposes a delete, so on a `Root` without
|
|
322
|
+
`allowAgentDelete` the agent's press would be refused with `agent-delete-not-allowed`.
|
|
323
|
+
|
|
324
|
+
The history records where an event was, not your fields. Undoing an agent's rename proposes the
|
|
325
|
+
event's times again, with no `detail.fields`, and the new title would stay. So the button reads
|
|
326
|
+
the step it's about to undo: `past.at(-1).changes[0].event` is your record as it was before the
|
|
327
|
+
step, and `onRestore` puts its title back once the undo is saved. `AuditedCalendar` passes
|
|
328
|
+
`onRestore` a function that copies the title into its meetings.
|
|
329
|
+
|
|
330
|
+
To undo an agent's `createEvent`, the history has to find the event the create became. That's what
|
|
331
|
+
`createdEventId` in `AuditedCalendar` is for; [Undo and redo](../undo-redo.md#creates-and-deletes)
|
|
332
|
+
explains it.
|
|
333
|
+
|
|
334
|
+
For one history that holds everyone's changes, leave `inputs` out. Each step in `past` from
|
|
335
|
+
`useCalendarHistory` has the `input` that made it, so your UI can still mark the agent's.
|
|
336
|
+
|
|
337
|
+
## Saves that take a while
|
|
338
|
+
|
|
339
|
+
> Live example: see it at https://time.molten.sh/docs/react/agents/changes
|
|
340
|
+
|
|
341
|
+
This page has two calendars, so this one has a label of its own, `Bookings`. An agent names a
|
|
342
|
+
calendar by its label, and a step on a label two calendars share fails: the bridge can't tell which
|
|
343
|
+
one is meant.
|
|
344
|
+
|
|
345
|
+
When `onEventChange` returns a promise, the calendar shows the change as
|
|
346
|
+
[pending](../interactions.md#pending-changes) while it settles. The agent's step doesn't wait for
|
|
347
|
+
it. It returns the change at once, with `status: "saving"`:
|
|
348
|
+
|
|
349
|
+
```json
|
|
350
|
+
{
|
|
351
|
+
"cause": "move",
|
|
352
|
+
"changeId": "change-1",
|
|
353
|
+
"eventId": "review",
|
|
354
|
+
"proposed": {
|
|
355
|
+
"start": "2026-10-09T10:00:00+02:00",
|
|
356
|
+
"end": "2026-10-09T11:00:00+02:00",
|
|
357
|
+
"kind": "timed",
|
|
358
|
+
"resourceIds": []
|
|
359
|
+
},
|
|
360
|
+
"status": "saving"
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
The agent asks how it ended with `getChange`, a step like any other:
|
|
365
|
+
|
|
366
|
+
```json
|
|
367
|
+
{ "ref": "Bookings", "action": "getChange", "args": [{ "changeId": "change-1" }] }
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
| The save | `getChange` returns |
|
|
371
|
+
| ------------------------------ | --------------------------------------------------------------- |
|
|
372
|
+
| Hasn't settled | The change with `status: "saving"` |
|
|
373
|
+
| Resolved | The change with `status: "saved"` |
|
|
374
|
+
| Rejected, or the handler threw | The change with `status: "rejected"`, `reason: "handler-error"` |
|
|
375
|
+
|
|
376
|
+
While a change saves, `describeCalendar` lists it in `pendingChanges`, and `listEvents` shows a
|
|
377
|
+
moved or updated event where it's going, with `"pending": true`. A new event is different: it
|
|
378
|
+
isn't in `listEvents` until your `events` has it, so an agent that created one reads `getChange`
|
|
379
|
+
first and lists the events once it's `saved`. A calendar remembers the last 50 changes agents
|
|
380
|
+
proposed on it, so an ID from earlier in a conversation still answers.
|
|
381
|
+
|
|
382
|
+
Your app hears the same outcome at `onEventChangeResult`, with `detail.input` of `"agent"`:
|
|
383
|
+
|
|
384
|
+
```tsx title="agent-slow-save.tsx"
|
|
385
|
+
"use client";
|
|
386
|
+
|
|
387
|
+
import { useState } from "react";
|
|
388
|
+
|
|
389
|
+
import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
|
|
390
|
+
|
|
391
|
+
import { applyChange, timedOnly, type MeetingChange } from "./agent-save";
|
|
392
|
+
import { Calendar, meetings as initialMeetings, weekRules, type Meeting } from "./calendar";
|
|
393
|
+
|
|
394
|
+
export interface SavedCalendarProps {
|
|
395
|
+
/** Hears an agent's change whose save failed after the agent was told "saving". */
|
|
396
|
+
readonly onAgentSaveFailed: (change: MeetingChange) => void;
|
|
397
|
+
/** Your server call: resolves once the change is stored, or rejects. */
|
|
398
|
+
readonly save: (change: MeetingChange) => Promise<void>;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export function SavedCalendar({ onAgentSaveFailed, save }: SavedCalendarProps) {
|
|
402
|
+
const [meetings, setMeetings] = useState<readonly Meeting[]>(initialMeetings);
|
|
403
|
+
|
|
404
|
+
return (
|
|
405
|
+
<Calendar.Root
|
|
406
|
+
// Its own name: a page with two calendars gives each one a label.
|
|
407
|
+
label="Bookings"
|
|
408
|
+
events={meetings}
|
|
409
|
+
// The calendar shows the change as pending until this promise settles, and the agent's
|
|
410
|
+
// step returns it with `status: "saving"`.
|
|
411
|
+
onEventChange={async (change, detail) => {
|
|
412
|
+
await save(change);
|
|
413
|
+
setMeetings((current) => applyChange(current, change, detail));
|
|
414
|
+
}}
|
|
415
|
+
// How every proposal ended, the agent's included. The agent reads the same from `getChange`.
|
|
416
|
+
onEventChangeResult={(result, detail) => {
|
|
417
|
+
if (detail.input !== "agent" || result.status !== "rejected") return;
|
|
418
|
+
if (result.change !== undefined) onAgentSaveFailed(result.change);
|
|
419
|
+
}}
|
|
420
|
+
policies={[timedOnly]}
|
|
421
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
422
|
+
defaultTimeZone="Europe/Berlin"
|
|
423
|
+
locale="en-US"
|
|
424
|
+
weekRules={weekRules}
|
|
425
|
+
>
|
|
426
|
+
<Calendar.Frame className="flex h-full flex-col">
|
|
427
|
+
<CalendarToolbar calendar={Calendar} />
|
|
428
|
+
<Calendar.Viewport className="min-h-0 flex-1">
|
|
429
|
+
<Calendar.ActiveView />
|
|
430
|
+
</Calendar.Viewport>
|
|
431
|
+
</Calendar.Frame>
|
|
432
|
+
</Calendar.Root>
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
`save` is your own server call. When it fails, the calendar puts the event back as it was, the
|
|
438
|
+
agent's `getChange` reads `rejected`, and `onAgentSaveFailed` is where your app tells the person.
|
|
439
|
+
A failed save leaves nothing in the browser's console that you didn't put there.
|
|
440
|
+
|
|
441
|
+
Two differences from a refusal that fails the step:
|
|
442
|
+
|
|
443
|
+
- **A late `rejected` has the reason and not your message.** `handler-error` is all `getChange`
|
|
444
|
+
says. A handler that throws before it returns a promise fails the step, and that message carries
|
|
445
|
+
your error's text.
|
|
446
|
+
- **Nothing tells the agent.** It reads a late outcome only when it asks. Tell your model to call
|
|
447
|
+
`getChange` before it reports a change that came back as `saving` or `validating`.
|
|
448
|
+
|
|
449
|
+
Next, [deleting with the person's say](./deleting.md).
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Build with a coding agent
|
|
2
|
+
|
|
3
|
+
Give Claude Code, Cursor or another coding agent these docs as Markdown, and a skill that teaches it the library.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/agents/coding-agents
|
|
6
|
+
|
|
7
|
+
The other pages in this section are about an agent that uses the calendar in your app. This one is
|
|
8
|
+
about the agent that writes your app. A coding agent trained before 2.0 doesn't know the 2.0
|
|
9
|
+
API, such as the agent bridge, and guesses at it. Three things give it the real API:
|
|
10
|
+
|
|
11
|
+
| What | Where | Use it when |
|
|
12
|
+
| ------------------- | ---------------------------------------------------------- | --------------------------------------------------------- |
|
|
13
|
+
| A skill | `npx skills add Moltenship/time --skill moltenship-time` | The agent supports [Agent Skills](https://agentskills.io) |
|
|
14
|
+
| Docs in the package | `node_modules/@moltenship/calendar/docs` | The agent can read files in your project |
|
|
15
|
+
| Docs on the site | [`/llms.txt`](https://time.molten.sh/llms.txt) and a `.md` version of every page | The agent can fetch a URL |
|
|
16
|
+
|
|
17
|
+
Each is made from the same source as the pages you're reading.
|
|
18
|
+
|
|
19
|
+
## Install the skill
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx skills add Moltenship/time --skill moltenship-time
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The [`skills` CLI](https://skills.sh) puts the `moltenship-time` skill in the folder your agent
|
|
26
|
+
reads skills from, such as `.claude/skills` for Claude Code. The agent loads it when a task
|
|
27
|
+
involves the calendar. `--skill` names it because the repository also holds skills for its own
|
|
28
|
+
maintenance.
|
|
29
|
+
|
|
30
|
+
The skill is a short guide and seven references the agent opens as it needs them:
|
|
31
|
+
|
|
32
|
+
| Reference | What it covers |
|
|
33
|
+
| ---------------- | ---------------------------------------------------------------------------------------- |
|
|
34
|
+
| `SKILL.md` | How the library is put together, where to look first, and the rules that hold everywhere |
|
|
35
|
+
| `compose.md` | Building a calendar from the registry's views and the parts |
|
|
36
|
+
| `state.md` | Controlled and uncontrolled state, change handlers, the store |
|
|
37
|
+
| `changes.md` | Event changes, saving, policies, undo |
|
|
38
|
+
| `agent-ready.md` | The bridge, permissions, deleting, WebMCP, a model on your server |
|
|
39
|
+
| `testing.md` | `@moltenship/calendar-testing`: the environment, the harness, queries |
|
|
40
|
+
| `mistakes.md` | Mistakes agents make with this library, and the fix for each |
|
|
41
|
+
| `solid.md` | SolidJS: the packages to install, a calendar, and the rules that differ from React |
|
|
42
|
+
|
|
43
|
+
Since 2.0 the npm package ships the same skill, at
|
|
44
|
+
`node_modules/@moltenship/calendar/skills/moltenship-time`. That copy matches the version you
|
|
45
|
+
installed. Without the CLI, copy the folder into your agent's skills folder, or point the agent at
|
|
46
|
+
it.
|
|
47
|
+
|
|
48
|
+
## Docs in the package
|
|
49
|
+
|
|
50
|
+
`@moltenship/calendar` carries these docs as Markdown:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
node_modules/@moltenship/calendar/docs/
|
|
54
|
+
llms.txt the index: every page, with one line on what it covers
|
|
55
|
+
index.md Introduction
|
|
56
|
+
quick-start.md
|
|
57
|
+
agents/connect.md
|
|
58
|
+
api/components.md
|
|
59
|
+
...
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
They're written when the package is built, from the React pages of this site, so they describe the
|
|
63
|
+
version in your `node_modules` and not the newest one. Links between pages are relative paths, and
|
|
64
|
+
they work offline. A link to a page of the Solid docs is a link to this site.
|
|
65
|
+
|
|
66
|
+
A live example can't run in a Markdown file. Where a page has one, the Markdown has a line with the
|
|
67
|
+
page's address, and the example's source stays as a code sample.
|
|
68
|
+
## Docs on the site
|
|
69
|
+
|
|
70
|
+
| Address | What it returns |
|
|
71
|
+
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
|
|
72
|
+
| [`/llms.txt`](https://time.molten.sh/llms.txt) | The index, in the [llms.txt](https://llmstxt.org) format |
|
|
73
|
+
| [`/llms-full.txt`](https://time.molten.sh/llms-full.txt) | Every page in one Markdown document |
|
|
74
|
+
| `/docs/react/agents/connect.md` | One page as Markdown: add `.md` to any page's address |
|
|
75
|
+
| [`/docs/react.md`](https://time.molten.sh/docs/react.md) | The introduction to the React docs |
|
|
76
|
+
| [`/docs/solid.md`](https://time.molten.sh/docs/solid.md) | The introduction to the Solid docs |
|
|
77
|
+
|
|
78
|
+
The index lists the React docs and then the Solid docs. It groups each set's pages as the sidebar
|
|
79
|
+
does and puts the ones an agent can skip under `Optional`. Start an agent there and let it fetch the pages it needs. `/llms-full.txt` is the whole
|
|
80
|
+
site and is large; use it when the agent can't follow links.
|
|
81
|
+
|
|
82
|
+
The site describes the newest version. For an older one, read the docs in the package.
|
|
83
|
+
|
|
84
|
+
## Tell your agent where to look
|
|
85
|
+
|
|
86
|
+
An agent reads your project's instruction file before it starts: `AGENTS.md`, or `CLAUDE.md` for
|
|
87
|
+
Claude Code. A few lines there save it from guessing:
|
|
88
|
+
|
|
89
|
+
```md title="AGENTS.md"
|
|
90
|
+
## Calendar
|
|
91
|
+
|
|
92
|
+
The calendar is Moltenship Time (`@moltenship/calendar`), a headless calendar built on ui-sdk.
|
|
93
|
+
|
|
94
|
+
- Its docs are in `node_modules/@moltenship/calendar/docs`. Read `llms.txt` there first, then the
|
|
95
|
+
pages it lists. They match the installed version; don't rely on what you remember of the API.
|
|
96
|
+
- The views are source files in `src/components/calendar`, added with `shadcn add`. Edit them
|
|
97
|
+
there. Don't look for them in `node_modules`.
|
|
98
|
+
- Dates and times are `Temporal` values, never `Date`.
|
|
99
|
+
- An event change is saved in `onEventChange`. The calendar doesn't store events.
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Change the paths to your project's. The last three lines are the facts agents get wrong most often;
|
|
103
|
+
the skill's `mistakes.md` has the rest.
|
|
104
|
+
|
|
105
|
+
## Make the app agent-ready too
|
|
106
|
+
|
|
107
|
+
A coding agent that knows the library can also build the other half: a calendar that the agent in
|
|
108
|
+
your product can use. Ask for it by name, with the pages that cover it:
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
Make the calendar agent-ready. Follow node_modules/@moltenship/calendar/docs/agents/connect.md:
|
|
112
|
+
create one bridge, name the calendar with `label`, and allow navigation and changes but ask the
|
|
113
|
+
person before a delete.
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Then check what it built the way a person would, and with a test that runs [an agent's steps through the bridge](../testing.md#changes-an-agent-makes).
|