@moltenship/calendar 1.0.0-rc.1 → 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,512 @@
1
+ # Agent reference
2
+
3
+ Every action an agent can call on a calendar, with its arguments, results and errors, and every field of the calendar's snapshot entry.
4
+
5
+ Source: https://time.molten.sh/docs/agents/reference
6
+
7
+ This page lists what a calendar gives ui-sdk's agent bridge. The guides start at
8
+ [Agents](../agents.md).
9
+
10
+ ## Root props
11
+
12
+ Three props on `Root` are for agents:
13
+
14
+ | Prop | Type | Default | Effect |
15
+ | ----------------------- | --------------------------------------- | ------- | ------------------------------------------------------------------------------------------------- |
16
+ | `label` | `string` | none | The calendar's name for agents: `label` in its snapshot entry. Without it, the title is the name |
17
+ | `allowAgentDelete` | `boolean` | `false` | Gives the calendar its `deleteEvent` action. Without it, any delete an agent causes is refused |
18
+ | `formatAgentEventLabel` | `(event: CalendarAgentEvent) => string` | none | Writes each event's `label` in the snapshot's `items`, in place of the [default](#snapshot-entry) |
19
+
20
+ An agent's change also needs `onEventChange`, as every change does. A calendar is listed for agents
21
+ only when it renders `Calendar.Frame`.
22
+
23
+ ## The bridge
24
+
25
+ The bridge is ui-sdk's, from `@ui-sdk/react/agent` in a React app and `@ui-sdk/solid/agent` in a
26
+ Solid one:
27
+
28
+ ```ts title="agent.ts"
29
+ "use client";
30
+
31
+ import { createAgent } from "@ui-sdk/react/agent";
32
+
33
+ export const agent = createAgent({
34
+ // Optional. Asked before every step; `false` refuses it.
35
+ allow: ({ component, action }) => component === "calendar" && action !== "setTimeZone",
36
+ // Optional. How long a step waits for a promise from `allow`, in milliseconds. 5 minutes by default.
37
+ timeout: 60_000,
38
+ });
39
+ ```
40
+
41
+ | Member | What it does |
42
+ | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
43
+ | `agent.snapshot()` | Returns an entry for every component on the page |
44
+ | `agent.query({ text?, within?, kind? })` | Resolves with the entries that match. `within` with a calendar's label returns it with the events in view |
45
+ | `agent.act({ steps }, { signal? })` | Runs steps in order and resolves with the [result](#results). Stops at the first that fails |
46
+ | `agent.subscribe(listener)` | Calls `listener` for each settled state change, an agent's or a person's. Returns the unsubscribe function |
47
+ | `agentTools` | The definitions of `snapshot`, `act` and `query` for a model: `{ name, description, inputSchema }` |
48
+ | `registerTools(agent, { allow })` | Registers the three tools with [WebMCP](./webmcp.md). Returns the unregister function |
49
+
50
+ `agentTools` and `registerTools` are exports of the same entry as `createAgent`. On a server, import
51
+ `agentTools` from `@ui-sdk/core/agent`.
52
+
53
+ `subscribe` reports changes to the calendar's state: `view`, `anchorDate`, `timeZone`,
54
+ `selection`, `focus` and `expandedResourceIds`. It doesn't report events changing, since your app
55
+ holds them. Use `onEventChangeResult` for those.
56
+
57
+ The three tools are the bridge's own and the same for every component. `act`'s definition says a
58
+ step has a `ref`, an `action` and `args`. It can't say what a calendar's actions take: that's in
59
+ [`describeCalendar().actions`](#describecalendar), and in the message of a call that got it wrong.
60
+
61
+ ## Snapshot entry
62
+
63
+ | Field | Type | Contents |
64
+ | --------------------- | ------------------------------------ | ----------------------------------------------------------------------------------- |
65
+ | `ref` | `string` | The bridge's handle, such as `"c1"`. Stays with the calendar while it's on the page |
66
+ | `component` | `"calendar"` | The component's kind |
67
+ | `label` | `string` | `Root`'s `label`, or the calendar's title |
68
+ | `actions` | `string[]` | The [actions](#actions) this calendar offers now, in alphabetical order |
69
+ | `view` | `string` | The active view's name |
70
+ | `anchorDate` | `string`, as `"2026-10-08"` | The date the visible range is built around |
71
+ | `timeZone` | `string` | The IANA time zone times are shown in |
72
+ | `selection` | your selection type, or `null` | What's selected |
73
+ | `focus` | your focus type, or `null` | What has keyboard focus inside the calendar |
74
+ | `expandedResourceIds` | array of resource IDs | The expanded resource groups |
75
+ | `items` | `{ value: string; label: string }[]` | The events in the visible range. Absent when there are none |
76
+ | `text` | `string[]` | The calendar's title, such as `"Oct 5 – 11, 2026"` |
77
+ | `offPage` | `true` | Only on a calendar that left the page, which the bridge remembers for a while |
78
+
79
+ Which actions a calendar offers:
80
+
81
+ | `Root` has | `actions` |
82
+ | -------------------------------------- | -------------------------------------------------------------------------------- |
83
+ | No `onEventChange` | The ten that read, navigate and select |
84
+ | `onEventChange` | Those, and `createEvent`, `updateEvent`, `moveEvent` and `resizeEvent`: fourteen |
85
+ | `onEventChange` and `allowAgentDelete` | All fifteen, with `deleteEvent` |
86
+
87
+ A calendar lists all fifteen for one microtask after it mounts, and the ones it doesn't offer
88
+ leave after that. A step for an action that isn't offered fails with the bridge's
89
+ `calendar c1 takes no deleteEvent now. It takes: …`.
90
+
91
+ In `items`, `value` is the event's ID turned into a string. `label` is the event's title, a middle
92
+ dot, and when it happens, in ISO 8601 and not in `Root`'s `locale`:
93
+
94
+ | Event | Label |
95
+ | ---------------- | --------------------------------------------------------------------------- |
96
+ | Timed | `Design review · 2026-10-08T15:00 to 2026-10-08T16:00 (Europe/Berlin)` |
97
+ | All-day, one day | `Offsite · 2026-10-06 (all day)` |
98
+ | All-day, several | `Conference · 2026-10-06 to 2026-10-08 (all day)`. The last day is included |
99
+ | Floating | `Lunch · 2026-10-08T12:00 to 2026-10-08T13:00 (local time)` |
100
+
101
+ A timed event's times are wall-clock times in the calendar's time zone, which the label names. An
102
+ event without a title has only the time. All-day events come first, then the rest by start.
103
+
104
+ An all-day label ends on the event's last day, and `listEvents` gives the same event an exclusive
105
+ `end`: the conference above has `"end": "2026-10-09"` there.
106
+
107
+ `formatAgentEventLabel` replaces the label. It gets the event as [`listEvents`](#listevents)
108
+ describes it:
109
+
110
+ ```tsx
111
+ <Calendar.Root
112
+ label="Team calendar"
113
+ formatAgentEventLabel={(event) => `${event.title} (${event.start} to ${event.end})`}
114
+ /* …the rest of your props */
115
+ />
116
+ ```
117
+
118
+ Keep ISO dates in it. A model reads `2026-10-08T15:00` back exactly, and a localized date it has to
119
+ guess at.
120
+
121
+ `selection` and `focus` are your own values, sent as JSON. Keep them serializable if agents should
122
+ read them.
123
+
124
+ In the object `agent.snapshot()` returns in the page, `anchorDate` is a `Temporal.PlainDate`. It
125
+ becomes the string above once the snapshot is serialized, which every tool call does.
126
+
127
+ ## Actions
128
+
129
+ A step names the calendar by `ref`: its ref, its label, or `"calendar"`. An action takes nothing, or
130
+ exactly one JSON object as `args[0]`. An action that takes nothing accepts `{}` too. A second
131
+ argument, a value that isn't an object, a key the action doesn't have, a `null` and a missing
132
+ required key each fail the step with [`calendar-agent-invalid-arguments`](#errors).
133
+
134
+ ### Reading
135
+
136
+ | Action | Input | Returns |
137
+ | ------------------ | ------------------------------ | ----------------------------------------------- |
138
+ | `describeCalendar` | nothing | The calendar's [description](#describecalendar) |
139
+ | `listEvents` | nothing, or `{ start?, end? }` | A list of [events](#listevents) |
140
+ | `getChange` | `{ changeId }` | A [change](#a-change) by its ID, as it is now |
141
+
142
+ These change nothing and call no handler of yours. They're steps, so the bridge's `allow` is asked
143
+ for each.
144
+
145
+ #### describeCalendar
146
+
147
+ | Field | Type | Contents |
148
+ | ----------------- | ---------------------------------------------- | -------------------------------------------------------------------------------------- |
149
+ | `actions` | `Record<string, string>` | Each action the calendar offers now, with its input as the tables on this page give it |
150
+ | `conventions` | `string` | How dates, times, ranges and IDs are written, in a sentence for the model |
151
+ | `today` | `string`, as `"2026-10-06"` | Today in the calendar's time zone |
152
+ | `now` | `string`, as `"2026-10-06T11:42:07.512+02:00"` | The current time, with the calendar's time zone's offset |
153
+ | `timeZone` | `string` | The IANA time zone times are shown in |
154
+ | `locale` | `string` | `Root`'s `locale` |
155
+ | `view` | `string` | The active view |
156
+ | `views` | `string[]` | The names `setView` takes |
157
+ | `anchorDate` | `string` | The date the visible range is built around |
158
+ | `visibleRange` | `{ start, end }` or `null` | The dates in view. `end` is exclusive |
159
+ | `resources` | `{ id, parentId, title }[]` | Your resources, for `resourceIds`. Empty without any |
160
+ | `selectedEventId` | an event ID, or `null` | The selected event, when the selection is the default kind |
161
+ | `pendingChanges` | [changes](#a-change) | The changes being checked or saved now, a person's included |
162
+ | `readOnly` | `boolean` | `true` when `Root` has no `onEventChange` |
163
+ | `canDelete` | `boolean` | Whether the calendar offers `deleteEvent` |
164
+
165
+ `today` and `now` follow `Root`'s `now` or `clock` prop when you pass one.
166
+
167
+ #### listEvents
168
+
169
+ Without input, the events of the visible range. With `start`, `end` or both, the events of those
170
+ dates, in view or not; the one left out is the visible range's. Both are ISO dates, and `end` is
171
+ exclusive. A `start` that isn't before the `end` fails with `calendar-agent-invalid-range`.
172
+
173
+ | Field | Type | Contents |
174
+ | ------------- | -------------------------------------- | ------------------------------------------------------------- |
175
+ | `id` | `string` or `number` | The event's ID as your adapter gives it. What `eventId` takes |
176
+ | `title` | `string` | The adapter's title |
177
+ | `kind` | `"timed"`, `"all-day"` or `"floating"` | How `start` and `end` are written |
178
+ | `start` | `string` | See below |
179
+ | `end` | `string` | Exclusive |
180
+ | `resourceIds` | array of resource IDs | The resources the event is on |
181
+ | `pending` | `true` | Only while a change to the event is being checked or saved |
182
+ | `readOnly` | `true` | Only on an event that can't be changed |
183
+
184
+ | `kind` | `start` and `end` |
185
+ | ---------- | --------------------------------------------------------------------------------- |
186
+ | `timed` | A date-time with the calendar's time zone's offset: `"2026-10-08T15:00:00+02:00"` |
187
+ | `all-day` | A date: `"2026-10-06"`. One day on October 6 ends on `"2026-10-07"` |
188
+ | `floating` | A date-time without an offset: `"2026-10-08T12:00:00"` |
189
+
190
+ The list has all-day events first and then the rest by start. It shows events as the calendar
191
+ does, with pending changes applied. It has the adapter's fields and none of your record's others:
192
+ what else an event holds is your app's to tell a model.
193
+
194
+ ### Navigation and state
195
+
196
+ | Action | Input | Effect | Handler on `Root` |
197
+ | ------------------ | ---------------------------------- | -------------------------------------------------- | -------------------- |
198
+ | `navigateNext` | nothing | Moves one range forward, by the active view's step | `onAnchorDateChange` |
199
+ | `navigatePrevious` | nothing | Moves one range back | `onAnchorDateChange` |
200
+ | `navigateToday` | nothing | Shows the range that holds today | `onAnchorDateChange` |
201
+ | `goToDate` | `{ date: "2026-10-09" }` | Shows the range that holds the date | `onAnchorDateChange` |
202
+ | `setView` | `{ view }`: one of `views` | Switches the view | `onViewChange` |
203
+ | `setTimeZone` | `{ timeZone: "America/New_York" }` | Shows times in that zone | `onTimeZoneChange` |
204
+ | `selectEvent` | `{ eventId }`: an ID, or `null` | Selects the event, or clears the selection | `onSelectionChange` |
205
+
206
+ Each handler gets `detail.source` of `"agent"` and `detail.reason` of `"imperative"`, with no
207
+ `detail.event`. `detail.cancel()` keeps the value, and the step still succeeds, with no `changes`.
208
+ That's for the actions in this table: when the agent presses one of the calendar's triggers
209
+ instead, the handler gets the trigger's own reason, such as `"next-press"`.
210
+
211
+ `goToDate` also takes a date-time and uses its date. `setTimeZone` changes how times are shown and
212
+ moves no event.
213
+
214
+ `selectEvent` sets the selection to `{ kind: "event", eventId }`, the calendar's default selection
215
+ for an event. It writes that shape on a calendar with a
216
+ [selection type of its own](../api/react.md#createcalendar) as well. If yours differs, map it in
217
+ `onSelectionChange` with `selection` controlled, or refuse `selectEvent` in `allow`.
218
+
219
+ ### Events
220
+
221
+ | Action | Input | Proposes |
222
+ | ------------- | ---------------------------------------------------------- | ------------------------------------------------------------------ |
223
+ | `createEvent` | `{ start, end, title?, resourceIds?, fields? }` | `cause: "create"`, with `eventId: null` and `event: null` |
224
+ | `updateEvent` | `{ eventId, title?, start?, end?, resourceIds?, fields? }` | `cause: "update"`. Needs one key beside `eventId` |
225
+ | `moveEvent` | `{ eventId, start, end?, resourceIds? }` | `cause: "move"`. Without `end` the event keeps its length |
226
+ | `resizeEvent` | `{ eventId, start }` or `{ eventId, end }` | `cause: "resize-start"` or `"resize-end"`. The other edge stays |
227
+ | `deleteEvent` | `{ eventId }` | `cause: "delete"`. Offered only when `Root` has `allowAgentDelete` |
228
+
229
+ Each is a proposal with `detail.input` of `"agent"`: policies see it, and so do `onEventChange` and
230
+ `onEventChangeResult`. Each returns [a change](#a-change).
231
+
232
+ `eventId` is an `id` from `listEvents`, or an item's `value`. A number ID matches as a number or
233
+ as its string. Any event you passed to `events` can be named, in view or not.
234
+
235
+ `title` and `fields` are for your record. `createEvent` and `updateEvent` take them, and the other
236
+ three don't. They reach your policies and your `onEventChange` as `detail.fields`: the `fields`
237
+ object, with `title` in it as `fields.title`. The calendar checks that `title` is a string and
238
+ `fields` an object, and that the title isn't given both ways. It checks nothing inside `fields`.
239
+ [Save what the agent sent](./connect.md#save-what-the-agent-sent) has the handler.
240
+
241
+ `updateEvent` with `start` and no `end` keeps the event's length, as `moveEvent` does. With `end`
242
+ alone the start stays. With neither, the event keeps its times, and the change still has them as
243
+ `proposed`.
244
+
245
+ How `start` and `end` are read depends on the event:
246
+
247
+ | Event | `start` and `end` | Examples |
248
+ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
249
+ | Timed | A date-time. Without an offset it's wall-clock time in the calendar's time zone; with `Z`, an offset or a bracketed zone it's that exact moment | `"2026-10-09T10:00"`, `"2026-10-09T08:00Z"`, `"2026-10-09T10:00+02:00[Europe/Berlin]"` |
250
+ | All-day | A date. The end is exclusive: one day on October 9 ends on October 10 | `"2026-10-09"` |
251
+ | Floating | A date-time without an offset | `"2026-10-09T10:00"` |
252
+
253
+ What `listEvents` returns for an event's `start` and `end` is valid input for them.
254
+
255
+ Dates are in the ISO calendar. A date or a time annotated with another calendar, such as
256
+ `"2026-10-09[u-ca=hebrew]"`, fails with `calendar-agent-unsupported-calendar`: the calendar doesn't
257
+ convert it.
258
+
259
+ `createEvent` makes an all-day event when both `start` and `end` are dates, and a timed one
260
+ otherwise.
261
+
262
+ `resourceIds` is a list of resource IDs from `describeCalendar`'s `resources`. On a calendar that
263
+ has resources, an ID that isn't one of them fails with `calendar-agent-unknown-resource`, which
264
+ lists the ones there are. A calendar without resources doesn't check them.
265
+
266
+ A wall-clock time that a daylight saving change skips or repeats is resolved with `Root`'s
267
+ `disambiguation`, `"compatible"` by default.
268
+
269
+ ### Recurring events
270
+
271
+ With [recurring events](../guides/recurring-events.md), each occurrence is an event of its own in `listEvents`,
272
+ with the ID your expansion gives it, such as `standup::2026-10-20T09:00:00Z`. An agent names an
273
+ occurrence by that ID.
274
+
275
+ Which occurrences a change covers is your app's choice, so it travels as a field. An agent sends it
276
+ with `updateEvent`, the one action for an existing event that takes `fields`:
277
+
278
+ ```json
279
+ {
280
+ "ref": "Team calendar",
281
+ "action": "updateEvent",
282
+ "args": [
283
+ {
284
+ "eventId": "standup::2026-10-20T09:00:00Z",
285
+ "start": "2026-10-20T10:00",
286
+ "fields": { "scope": "all" }
287
+ }
288
+ ]
289
+ }
290
+ ```
291
+
292
+ Your handler reads `detail.fields?.scope` and applies the change to that occurrence or to the
293
+ series, as it does for a person's choice in a dialog. `moveEvent`, `resizeEvent` and `deleteEvent`
294
+ take no `fields`, so they act on the occurrence named, with your handler's default scope. After a
295
+ change to a series, occurrence IDs can differ, and the agent calls `listEvents` again.
296
+
297
+ ## Results
298
+
299
+ `act` resolves with:
300
+
301
+ | Field | Contents |
302
+ | ---------- | --------------------------------------------------------------------- |
303
+ | `ok` | `true` when every step ran |
304
+ | `error` | `{ step, message }` for the step that failed. `step` counts from zero |
305
+ | `steps` | The steps that ran: `{ step, ref, changes?, result? }` |
306
+ | `appeared` | Components that came onto the page during the call |
307
+ | `values` | The values of form fields on the page. A calendar adds nothing here |
308
+
309
+ What a calendar's step reports:
310
+
311
+ | Step | Reports |
312
+ | ------------------------------------------- | -------------------------------------------------------------------------------------------- |
313
+ | Navigation or state, applied | `changes: [{ component: "calendar", label, key, value }]`, with `key` such as `"anchorDate"` |
314
+ | Navigation or state, cancelled or unchanged | Neither `changes` nor `result` |
315
+ | `describeCalendar`, `listEvents` | `result`: the description, or the list |
316
+ | An event action, and `getChange` | `result`: [a change](#a-change) |
317
+
318
+ A failed step stops the call. Steps before it stay applied.
319
+
320
+ ### A change
321
+
322
+ What `createEvent`, `updateEvent`, `moveEvent`, `resizeEvent`, `deleteEvent` and `getChange`
323
+ return:
324
+
325
+ | Field | Type | Contents |
326
+ | ---------- | -------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
327
+ | `changeId` | `string` | Names the change on this calendar, for `getChange` |
328
+ | `cause` | `"create"`, `"update"`, `"move"`, `"resize-start"`, `"resize-end"` or `"delete"` | What was proposed |
329
+ | `eventId` | an event ID, or `null` | The event. `null` for a create: your app makes the event and its ID |
330
+ | `proposed` | `{ start, end, kind, resourceIds }`, or `null` | Where the event lands, written as `listEvents` writes it. `null` for a delete |
331
+ | `status` | `"saved"`, `"saving"`, `"validating"` or `"rejected"` | Where the change is |
332
+ | `reason` | `string` | Only with `"rejected"`: one of the [rejection reasons](#rejection-reasons) |
333
+
334
+ | `status` | When |
335
+ | ------------ | ---------------------------------------------------------------------------------------- |
336
+ | `saved` | Your `onEventChange` returned, or the promise it returned resolved |
337
+ | `saving` | Your `onEventChange` returned a promise that hasn't settled |
338
+ | `validating` | A policy returned a promise that hasn't settled. Your `onEventChange` hasn't been called |
339
+ | `rejected` | A policy or your handler refused the change after the step had returned it |
340
+
341
+ A refusal that comes at once never returns as a change: it [fails the step](#errors). So a step's
342
+ own `result` is `saved`, `saving` or `validating`, and `rejected` is something `getChange` reports.
343
+
344
+ `saved` means your handler took the change. It doesn't say your `events` prop has the event in its
345
+ new place yet. `listEvents` reads your `events` with the changes still pending on top, so what it
346
+ shows after the step depends on your handler:
347
+
348
+ | Your `onEventChange` | `listEvents` after the step |
349
+ | ------------------------------------------ | -------------------------------------------------------------------------- |
350
+ | Updates `events` before it returns | The event in its new place |
351
+ | Returns a promise | The new place, with `pending: true` while it saves and from `events` after |
352
+ | Returns nothing and updates `events` later | The old place, until `events` changes |
353
+
354
+ The third is a handler that starts a save and doesn't return its promise. The calendar takes a
355
+ change for saved the moment such a handler returns, a person's drag included, so return the
356
+ promise.
357
+
358
+ A new event is listed once your `events` has it. While a `createEvent` is `saving`, `listEvents`
359
+ doesn't have the event yet.
360
+
361
+ A calendar keeps the last 50 changes agents proposed on it, for as long as it's mounted, and
362
+ `getChange` reads those however they ended. It also reads any change that's still being checked
363
+ or saved, a person's included, by the ID `describeCalendar`'s `pendingChanges` gives it. Once a
364
+ person's change has ended, the calendar no longer has it. `getChange` with an ID it doesn't have
365
+ fails with `calendar-agent-unknown-change` and lists the agents' last ten.
366
+
367
+ ## Errors
368
+
369
+ A failed step's `message` starts with a code.
370
+
371
+ | Code | When | The message also says |
372
+ | ------------------------------------- | ----------------------------------------------------------------- | --------------------------------------------------------- |
373
+ | `calendar-agent-invalid-arguments` | The input isn't one object with the action's keys | What the action takes, and what was wrong |
374
+ | `calendar-agent-invalid-date` | A date isn't an ISO date | The key, an example, and what was sent |
375
+ | `calendar-agent-invalid-time` | A time isn't an ISO date-time | An example in the calendar's time zone, and what was sent |
376
+ | `calendar-agent-invalid-time-zone` | `setTimeZone` got something that isn't an IANA time zone | An example, and what was sent |
377
+ | `calendar-agent-unsupported-calendar` | A date or a time is in a calendar other than ISO 8601 | The calendar it names, and what was sent |
378
+ | `calendar-agent-invalid-resources` | `resourceIds` isn't a list of strings or numbers | What was sent |
379
+ | `calendar-agent-unknown-resource` | `resourceIds` has an ID that none of the calendar's resources has | The first 20 resource IDs |
380
+ | `calendar-agent-invalid-range` | `listEvents` got a `start` that isn't before its `end` | What was sent |
381
+ | `calendar-agent-unknown-event` | No event has that ID | The first 20 event IDs |
382
+ | `calendar-agent-unknown-change` | `getChange` got an ID the calendar doesn't have | The last ten change IDs |
383
+ | `calendar-unknown-view` | `setView` got a name that isn't registered | The registered view names |
384
+ | `calendar-event-change-rejected` | A policy, the calendar or your handler refused the change at once | The [reason](#rejection-reasons) |
385
+
386
+ What `calendar-agent-invalid-arguments` says after the code:
387
+
388
+ ```text
389
+ moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; it takes one object, not 2 arguments
390
+ moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; it has no "fields"
391
+ moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; start is missing
392
+ goToDate takes { date: ISO date }; got "2026-09-01"
393
+ updateEvent changes something: { eventId: ID, title?: string, start?: ISO date or date-time, end?: same, resourceIds?: ID[], fields?: object }
394
+ resizeEvent takes one of start and end: { eventId: ID, start?: ISO date or date-time, end?: same }, one of start and end
395
+ give the title as title or as fields.title, not both
396
+ ```
397
+
398
+ The bridge has messages of its own:
399
+
400
+ | Message | When |
401
+ | -------------------------------------------------------------------- | ---------------------------------------------------------- |
402
+ | `The app refused moveEvent on c1.` | `allow` returned `false` |
403
+ | `deleteEvent on c1 was cancelled.` | The `signal` passed to `act` aborted while the step waited |
404
+ | `No component "Team calendar" on the page. Its labels: …` | Nothing has that ref, label or kind |
405
+ | `calendar c1 takes no deleteEvent now. It takes: createEvent, …` | The calendar doesn't offer the action, or has no such one |
406
+ | `"Private calendar" isn't available to agents here. Ask the person.` | The calendar is inside `data-agent-hidden` |
407
+
408
+ ### Rejection reasons
409
+
410
+ What follows `calendar-event-change-rejected: ` in a failed step, and what a rejected change has as
411
+ `reason`:
412
+
413
+ | Reason | Meaning |
414
+ | -------------------------- | ------------------------------------------------------------------- |
415
+ | a policy's reason | A policy rejected the change, such as `agents-book-weekdays-only` |
416
+ | `read-only` | The event is read-only |
417
+ | `unknown-event` | No event has the change's ID |
418
+ | `agent-delete-not-allowed` | An agent caused a delete on a `Root` without `allowAgentDelete` |
419
+ | `invalid-placement` | The range is empty or reversed, such as an `end` before the `start` |
420
+ | `handler-error` | Your `onEventChange` threw, or the promise it returned rejected |
421
+ | `policy-error` | A policy threw |
422
+ | `superseded` | A newer change to the same event replaced this one |
423
+
424
+ A failed step adds the thrown error's message in parentheses:
425
+ `calendar-event-change-rejected: handler-error (This slot was just taken)`. A rejected change's
426
+ `reason` is the reason alone.
427
+
428
+ The calendar's own actions look the event up before they propose, so a step that names a missing
429
+ event fails with `calendar-agent-unknown-event`, which lists the IDs there are. `unknown-event` is
430
+ what your `onEventChangeResult` gets for a proposal made another way, such as a button of yours
431
+ that proposes a change to an event that's gone.
432
+
433
+ ## Who made a change
434
+
435
+ | Where | Field | Values |
436
+ | ------------------------------------------------------- | --------------- | ------------------------------------------------------------------------------------- |
437
+ | State handlers, such as `onViewChange(view, detail)` | `detail.source` | `"agent"`, `"mouse"`, `"touch"`, `"pen"`, `"keyboard"`, `"virtual"`, `"programmatic"` |
438
+ | `onEventChange(change, detail)` | `detail.input` | `"agent"`, `"pointer"`, `"keyboard"`, `"api"` |
439
+ | `onEventChangeResult(result, detail)` | `detail.input` | The same |
440
+ | A policy's second argument, `{ detail }` | `detail?.input` | The same |
441
+ | A history step, from `useCalendarHistory(history).past` | `input` | The same |
442
+
443
+ The same `detail` has `fields` for an agent's `createEvent` or `updateEvent` that sent a `title`
444
+ or `fields`, and no `fields` key otherwise.
445
+
446
+ An undo or redo also has `detail.history`, `"undo"` or `"redo"`, and its `input` is `"api"` unless
447
+ you pass another to `undo({ input })`.
448
+
449
+ Anything a step causes is the agent's, not only the calendar's own actions. When an agent presses
450
+ a ui-sdk button of yours and its handler calls `proposeEventChange`, an action such as `setView`,
451
+ or a history's `undo`, your policies and handlers hear `"agent"`, whatever input your code passed.
452
+ That holds for what the handler does before it returns: a call it makes after an `await`, in a
453
+ timer or in an effect reads as your own code, as
454
+ [Who made a change](./changes.md#two-kinds-of-change) explains.
455
+ A delete an agent causes that way is refused on a `Root` without `allowAgentDelete`, as
456
+ [Deleting](./deleting.md#a-delete-button-of-yours) describes.
457
+
458
+ A person's keys report `"keyboard"` in a state handler: arrow-key navigation, moving focus between
459
+ cells and events, and expanding or collapsing a resource. `"programmatic"` is left for calls your
460
+ own code makes.
461
+
462
+ Each of an agent's proposals reaches `onEventChangeResult` once, however it ends: `committed`, or
463
+ `rejected` with the reason, a policy's refusal included.
464
+
465
+ ## What isn't there yet
466
+
467
+ - **Tool definitions for the actions.** The bridge's `act` can't describe an action's input. A
468
+ model learns it from `describeCalendar().actions` or from a failed call's message.
469
+ - **A dry run.** An agent can't ask whether a change would be accepted. It proposes the change and
470
+ reads the refusal.
471
+ - **A selection of your own shape from `selectEvent`.** It writes `{ kind: "event", eventId }`
472
+ whatever selection type the calendar has, and `selectedEventId` reads only that kind.
473
+ - **A settled list of actions at mount.** A calendar lists every action for one microtask after it
474
+ mounts, before the ones it doesn't offer leave.
475
+ - **Your record's other fields in `listEvents`.** It has the adapter's ID, title, times and
476
+ resources.
477
+ - **The new event's ID from `createEvent`.** The change has `eventId: null`, and the agent finds
478
+ the event with `listEvents`.
479
+ - **Event changes in `subscribe`.** It reports state. `onEventChangeResult` reports events.
480
+
481
+ ## Types
482
+
483
+ The actions' TypeScript types are in [`@moltenship/calendar-primitives`](../api/primitives.md), for
484
+ code that wraps the bridge or builds on the calendar's ui-sdk primitive. Apps don't have that
485
+ package as a direct dependency, so install it to import from it:
486
+
487
+ ```bash
488
+ pnpm add @moltenship/calendar-primitives
489
+ ```
490
+
491
+ ```ts title="agent-actions.ts"
492
+ import {
493
+ calendarAgentActions,
494
+ type CalendarAgentApi,
495
+ type CalendarAgentChange,
496
+ type CalendarAgentDescription,
497
+ type CalendarAgentEvent,
498
+ } from "@moltenship/calendar-primitives";
499
+
500
+ // The fifteen action names. A snapshot lists the ones a calendar offers, in alphabetical order.
501
+ export const actionNames: readonly (keyof CalendarAgentApi)[] = calendarAgentActions;
502
+
503
+ /** What `describeCalendar`, `listEvents` and an event action return, for code that reads them. */
504
+ export interface CalendarReads {
505
+ readonly description: CalendarAgentDescription;
506
+ readonly events: readonly CalendarAgentEvent[];
507
+ readonly change: CalendarAgentChange;
508
+ }
509
+ ```
510
+
511
+ Apps don't need them: an agent calls the actions by name through the bridge, and TypeScript
512
+ infers the `CalendarAgentEvent` that a `formatAgentEventLabel` written inline takes.