@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,435 @@
1
+ # Connect an agent
2
+
3
+ Create the agent bridge, name your calendar, and decide which actions an agent may run.
4
+
5
+ Source: https://time.molten.sh/docs/agents/connect
6
+
7
+ > Live example: see it at https://time.molten.sh/docs/agents/connect
8
+
9
+ A calendar is reachable by agents once your app creates ui-sdk's agent bridge. The bridge lists the
10
+ calendar, runs an agent's steps on it, and asks your `allow` before each one. This page sets that
11
+ up. Its samples import the `Calendar`, `Meeting`, `meetings` and `weekRules` that the
12
+ [Quick start](../quick-start.md) puts in `calendar.tsx`.
13
+
14
+ ## Create the bridge
15
+
16
+ The bridge comes from `@ui-sdk/react/agent`. `@ui-sdk/react` is one of the calendar's peer
17
+ dependencies, so [Installation](../installation.md) already added it. Create one bridge for the
18
+ whole app, in a module of its own:
19
+
20
+ ```ts title="agent.ts"
21
+ "use client";
22
+
23
+ import { createAgent } from "@ui-sdk/react/agent";
24
+
25
+ // Once, in the browser. It finds the calendars already on the page and hears new ones.
26
+ export const agent = createAgent();
27
+ ```
28
+
29
+ The bridge finds the calendars already on the page and hears new ones as they mount. It covers
30
+ every ui-sdk component in your app, not only calendars. On the server it lists nothing, so the
31
+ module is safe to import from a component that renders there.
32
+
33
+ Creating the bridge connects nothing to a model. It gives your code four methods:
34
+
35
+ | Method | What it does |
36
+ | --------------------------- | ------------------------------------------------------------------------------------- |
37
+ | `agent.snapshot()` | Lists every component on the page |
38
+ | `agent.query({ within })` | Finds components, or the events one calendar shows. Resolves with the list |
39
+ | `agent.act({ steps })` | Runs steps in order. Resolves with what each one did |
40
+ | `agent.subscribe(listener)` | Calls `listener` when a component's state changes. Returns the function that stops it |
41
+
42
+ You hand those to an agent in one of two ways: [WebMCP](./webmcp.md) for the agent built
43
+ into a browser, or [your own server](./server.md) for a model you run.
44
+
45
+ ## Name the calendar
46
+
47
+ An agent names a component by its label. Give `Root` a `label`, and make changes saveable with
48
+ `onEventChange`:
49
+
50
+ ```tsx title="agent-calendar.tsx"
51
+ "use client";
52
+
53
+ import { useState } from "react";
54
+
55
+ import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
56
+
57
+ import { applyChange, timedOnly } from "./agent-save";
58
+ import { Calendar, meetings as initialMeetings, weekRules } from "./calendar";
59
+
60
+ export function AgentReadyCalendar() {
61
+ const [meetings, setMeetings] = useState(initialMeetings);
62
+
63
+ return (
64
+ <Calendar.Root
65
+ // The name an agent finds the calendar by. Without it, the title names the calendar, and
66
+ // the title changes with every navigation.
67
+ label="Team calendar"
68
+ events={meetings}
69
+ // An agent's change arrives here like a drag does, and `detail.fields` has what the agent
70
+ // sent beside the times, such as a title. Without a handler the calendar is read-only,
71
+ // for agents too.
72
+ onEventChange={(change, detail) =>
73
+ setMeetings((current) => applyChange(current, change, detail))
74
+ }
75
+ policies={[timedOnly]}
76
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
77
+ defaultTimeZone="Europe/Berlin"
78
+ locale="en-US"
79
+ weekRules={weekRules}
80
+ >
81
+ <Calendar.Frame className="flex h-full flex-col">
82
+ <CalendarToolbar calendar={Calendar} />
83
+ <Calendar.Viewport className="min-h-0 flex-1">
84
+ <Calendar.ActiveView />
85
+ </Calendar.Viewport>
86
+ </Calendar.Frame>
87
+ </Calendar.Root>
88
+ );
89
+ }
90
+ ```
91
+
92
+ Without `label`, the calendar is named by its title, such as "Oct 5 – 11, 2026", and the title
93
+ changes each time the agent navigates. With two calendars on a page, give each its own `label`.
94
+
95
+ The bridge finds a calendar by its `Calendar.Frame`. A `Root` that renders its views without a
96
+ frame works for a person and isn't listed for an agent.
97
+
98
+ `applyChange`, `titleFrom` and `timedOnly` are this example's own. `applyChange` is what saving
99
+ means here, and `timedOnly` is a [policy](../interactions.md#policies) that refuses an all-day
100
+ meeting:
101
+
102
+ ```ts title="agent-save.ts"
103
+ import type {
104
+ CalendarEventChange,
105
+ CalendarPolicy,
106
+ CalendarProposalDetail,
107
+ } from "@moltenship/calendar";
108
+
109
+ import type { Meeting } from "./calendar";
110
+
111
+ export type MeetingChange = CalendarEventChange<Meeting, string, never>;
112
+
113
+ /**
114
+ * The title an agent sent with `createEvent` or `updateEvent`. The calendar passes `fields` on
115
+ * as it got them, so check each one as you would a form's input.
116
+ */
117
+ export function titleFrom(detail: CalendarProposalDetail | undefined): string | undefined {
118
+ const title = detail?.fields?.title;
119
+ return typeof title === "string" && title.trim() !== "" ? title.trim() : undefined;
120
+ }
121
+
122
+ // What saving a change means in this example: a new array of meetings.
123
+ export function applyChange(
124
+ meetings: readonly Meeting[],
125
+ change: MeetingChange,
126
+ detail?: CalendarProposalDetail,
127
+ id = crypto.randomUUID(),
128
+ ): readonly Meeting[] {
129
+ if (change.cause === "delete") {
130
+ return meetings.filter((meeting) => meeting.id !== change.eventId);
131
+ }
132
+ if (change.proposed.kind !== "timed") return meetings;
133
+
134
+ const { start, end } = change.proposed;
135
+ const title = titleFrom(detail);
136
+ if (change.cause === "create") {
137
+ // A create has times and no event: the app makes the meeting. An agent's `createEvent` can
138
+ // name it; a slot a person drags out can't. An undone delete brings the deleted meeting.
139
+ const meeting = change.event ?? { id, title: title ?? "New meeting", color: "blue" as const };
140
+ return [...meetings, { ...meeting, start, end }];
141
+ }
142
+ // A move, a resize, or an agent's `updateEvent`, which can bring a title with or without times.
143
+ return meetings.map((meeting) =>
144
+ meeting.id === change.eventId
145
+ ? { ...meeting, title: title ?? meeting.title, start, end }
146
+ : meeting,
147
+ );
148
+ }
149
+
150
+ // Meetings always have a time, so an all-day proposal is refused with a reason, not dropped.
151
+ export const timedOnly: CalendarPolicy<Meeting, string, never> = ({ proposed }) =>
152
+ proposed === null || proposed.kind === "timed"
153
+ ? { type: "accept" }
154
+ : { type: "reject", reason: "meetings-need-a-time" };
155
+ ```
156
+
157
+ Without `onEventChange` the calendar is read-only for agents as well. An agent can still read it
158
+ and navigate. The actions that change an event leave its `actions`, and `describeCalendar` reports
159
+ `readOnly: true`.
160
+
161
+ ## Save what the agent sent
162
+
163
+ The calendar knows when an event is and which resources it's on. Everything else about an event is
164
+ your record's, so the calendar can't write it. An agent sends those values, and your handler
165
+ stores them.
166
+
167
+ An agent's `createEvent` and `updateEvent` take two inputs for that: `title`, and `fields`, an
168
+ object of whatever your events have.
169
+
170
+ ```json
171
+ {
172
+ "ref": "Team calendar",
173
+ "action": "createEvent",
174
+ "args": [
175
+ {
176
+ "start": "2026-10-06T14:00",
177
+ "end": "2026-10-06T15:00",
178
+ "title": "Customer call",
179
+ "fields": { "color": "green" }
180
+ }
181
+ ]
182
+ }
183
+ ```
184
+
185
+ Your `onEventChange` gets them as `detail.fields`, with the title folded in:
186
+
187
+ ```ts
188
+ // change.cause === "create", change.event === null, detail.input === "agent"
189
+ detail.fields; // { color: "green", title: "Customer call" }
190
+ ```
191
+
192
+ What each change brings:
193
+
194
+ | Step | `change.cause` | `change.proposed` | `detail.fields` |
195
+ | ------------- | ---------------------------- | -------------------------------------- | ---------------------------------- |
196
+ | `createEvent` | `"create"` | The new event's times and resources | `title` and `fields`, when sent |
197
+ | `updateEvent` | `"update"` | The event's times, new or as they were | `title` and `fields`, when sent |
198
+ | `moveEvent` | `"move"` | The new times | Absent: the action takes no fields |
199
+ | `resizeEvent` | `"resize-start"` or `"-end"` | The new times | Absent |
200
+ | `deleteEvent` | `"delete"` | `null` | Absent |
201
+
202
+ Three rules for the handler, which `applyChange` above follows:
203
+
204
+ - **Check every field.** The calendar passes `fields` on as the agent sent them. It checks that
205
+ `fields` is an object and `title` a string, and nothing inside: a value can be any type, nested
206
+ to any depth. `titleFrom` takes a title only when it's a non-empty string; treat each field of
207
+ yours the same way, as you would a form's input.
208
+ - **An update can bring fields alone.** `updateEvent` with only a `title` proposes the event's
209
+ current times, so keep storing `change.proposed` and read the title beside it.
210
+ - **A person's change has no fields.** A drag, a resize and an undo arrive without
211
+ `detail.fields`, so fall back to what the event had.
212
+
213
+ A policy gets the same detail as its second argument's `detail`, so a rule can read a field before
214
+ anything is saved: refuse an agent's create without a title, or a title that's too long. The agent
215
+ reads the policy's reason in the failed step.
216
+
217
+ What the handler doesn't store is dropped without a word to the agent. If your app takes only some
218
+ fields from an agent, say which in the model's prompt, or refuse the others in a policy.
219
+
220
+ ## Try it from the console
221
+
222
+ Before any model is involved, call the bridge yourself. Put it on `window` in development:
223
+
224
+ ```ts title="main.tsx"
225
+ import { agent } from "./agent";
226
+
227
+ if (process.env.NODE_ENV !== "production") Object.assign(window, { agent });
228
+ ```
229
+
230
+ Then, in the browser's console:
231
+
232
+ ```js
233
+ agent.snapshot();
234
+ // [{ ref: "c1", component: "calendar", label: "Team calendar", view: "week", … }]
235
+
236
+ const calendar = { ref: "Team calendar" };
237
+
238
+ await agent.act({ steps: [{ ...calendar, action: "describeCalendar" }] });
239
+ // { ok: true, steps: [{ step: 0, ref: "c1", result: { today: "2026-10-06", views: […], … } }], … }
240
+
241
+ await agent.act({ steps: [{ ...calendar, action: "listEvents" }] });
242
+ // { ok: true, steps: [{ step: 0, ref: "c1", result: [{ id: "review", title: "Design review", … }] }], … }
243
+
244
+ await agent.act({
245
+ steps: [
246
+ {
247
+ ...calendar,
248
+ action: "moveEvent",
249
+ args: [{ eventId: "review", start: "2026-10-09T10:00" }],
250
+ },
251
+ ],
252
+ });
253
+ // { ok: true, steps: [{ step: 0, ref: "c1", result: { changeId: "change-1", status: "saved", … } }], … }
254
+ ```
255
+
256
+ An action takes one object, never a list of values. `args: ["review", "2026-10-09T10:00"]` fails,
257
+ and the message says what the action takes:
258
+
259
+ ```text
260
+ calendar-agent-invalid-arguments: moveEvent takes { eventId: ID, start: ISO date or date-time, end?: same, resourceIds?: ID[] }; it takes one object, not 2 arguments
261
+ ```
262
+
263
+ `ref` takes the calendar's label, its ref from the snapshot, or its kind, `"calendar"`. A name that
264
+ fits two components fails the step and lists both, so use the ref then.
265
+
266
+ In the object `snapshot()` returns, `anchorDate` is a `Temporal.PlainDate`. It becomes the string
267
+ `"2026-10-08"` when the snapshot is sent as JSON, which is how a model gets it.
268
+
269
+ ## Decide what an agent may do
270
+
271
+ Without `allow`, a bridge runs every step. Pass `allow` to `createAgent` to decide step by step.
272
+ This bridge reads a setting the person controls:
273
+
274
+ ```ts title="agent.ts"
275
+ "use client";
276
+
277
+ import { createAgent } from "@ui-sdk/react/agent";
278
+
279
+ /** What the person lets the agent do, from a switch in your settings. */
280
+ export type AgentAccess = "read" | "navigate" | "edit";
281
+
282
+ // Reading the calendar's facts, its events and how a change ended. These are steps too, so a
283
+ // list of what's allowed has to name them, or the agent never learns an event's ID.
284
+ const reading: ReadonlySet<string> = new Set(["describeCalendar", "listEvents", "getChange"]);
285
+ const navigation: ReadonlySet<string> = new Set([
286
+ "navigateNext",
287
+ "navigatePrevious",
288
+ "navigateToday",
289
+ "goToDate",
290
+ "setView",
291
+ "selectEvent",
292
+ ]);
293
+ const editing: ReadonlySet<string> = new Set([
294
+ "createEvent",
295
+ "updateEvent",
296
+ "moveEvent",
297
+ "resizeEvent",
298
+ ]);
299
+
300
+ let access: AgentAccess = "navigate";
301
+
302
+ export function setAgentAccess(next: AgentAccess): void {
303
+ access = next;
304
+ }
305
+
306
+ export const agent = createAgent({
307
+ // Asked before every step, with the component the step resolved to. The bridge's own
308
+ // `snapshot` and `query` aren't steps: they always answer.
309
+ allow: ({ action, component }) => {
310
+ if (component !== "calendar") return false;
311
+ if (reading.has(action)) return true;
312
+ if (navigation.has(action)) return access !== "read";
313
+ // Never `deleteEvent` or `setTimeZone`, whatever the switch says.
314
+ return access === "edit" && editing.has(action);
315
+ },
316
+ });
317
+ ```
318
+
319
+ `allow` gets the step after the bridge found its component:
320
+
321
+ | Field | Contents |
322
+ | ----------- | ----------------------------------------------------------------------------- |
323
+ | `component` | The component's kind: `"calendar"` for a calendar |
324
+ | `label` | The component's label, such as `"Team calendar"` |
325
+ | `ref` | The component's ref, such as `"c1"` |
326
+ | `action` | The action, such as `"moveEvent"` |
327
+ | `args` | The input as the agent sent it, such as `[{ eventId: "review", start: "…" }]` |
328
+ | `confirm` | The text of a `data-agent-confirm` mark on the component, if it has one |
329
+
330
+ Return `true` to run the step and `false` to refuse it. A refused step fails with a message the
331
+ agent reads, and the steps after it don't run:
332
+
333
+ ```json
334
+ {
335
+ "ok": false,
336
+ "error": { "step": 1, "message": "The app refused moveEvent on c1." },
337
+ "steps": [{ "step": 0, "ref": "c1" }],
338
+ "appeared": [],
339
+ "values": {}
340
+ }
341
+ ```
342
+
343
+ Start from a list of what's allowed, as the example does, so an action added in a later version
344
+ stays refused until you choose it. `allow` can also return a promise, which is how you
345
+ [ask the person first](./deleting.md).
346
+
347
+ Put the reading actions on that list. `describeCalendar`, `listEvents` and `getChange` are steps
348
+ like any other, and `allow` is asked for them. An agent that may move events and may not list them
349
+ has no event IDs to move. `allow` sees `args` before the calendar checks them, so read them as
350
+ unknown input.
351
+
352
+ A step isn't always one of the calendar's actions. An agent can also press a ui-sdk button of
353
+ yours, as a step with the action `press`, and what its handler does to the calendar counts as the
354
+ agent's: your policies and `onEventChange` hear `input: "agent"`. The example's `allow` refuses
355
+ every component but the calendar, so no button is pressed there. If yours lets presses through,
356
+ decide them as carefully as the calendar's own actions, a
357
+ [delete button](./deleting.md#a-delete-button-of-yours) most of all.
358
+
359
+ `allow` covers steps. The bridge's own `snapshot` and `query` aren't steps: they answer whatever
360
+ `allow` says, with the calendar's entry and the events in view. To keep a calendar from agents
361
+ entirely, put `data-agent-hidden` on an element around it:
362
+
363
+ ```tsx title="agent-hidden.tsx"
364
+ "use client";
365
+
366
+ import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
367
+
368
+ import { Calendar, meetings, weekRules } from "./calendar";
369
+
370
+ export function PrivateCalendar() {
371
+ return (
372
+ // Everything inside is left out of what an agent sees and can act on.
373
+ <section data-agent-hidden>
374
+ <Calendar.Root
375
+ label="Private calendar"
376
+ events={meetings}
377
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
378
+ defaultTimeZone="Europe/Berlin"
379
+ locale="en-US"
380
+ weekRules={weekRules}
381
+ >
382
+ <Calendar.Frame className="flex h-full flex-col">
383
+ <CalendarToolbar calendar={Calendar} />
384
+ <Calendar.Viewport className="min-h-0 flex-1">
385
+ <Calendar.ActiveView />
386
+ </Calendar.Viewport>
387
+ </Calendar.Frame>
388
+ </Calendar.Root>
389
+ </section>
390
+ );
391
+ }
392
+ ```
393
+
394
+ That calendar is left out of `snapshot` and `query`, and a step that names it fails with
395
+ `"Private calendar" isn't available to agents here. Ask the person.`
396
+
397
+ `allow` is the first of three checks an agent's change passes. The second is your
398
+ [policies](./changes.md#refuse-an-agents-change), which see the change itself: the event,
399
+ where it would land, and who proposed it. The third is your `onEventChange`, which can refuse to
400
+ save.
401
+
402
+ ## If the agent sees nothing
403
+
404
+ When `agent.snapshot()` returns `[]` while a calendar is on the page, a step fails with a message
405
+ that starts `No component "Team calendar" on the page.` The usual cause is that the bridge and the
406
+ calendar run on two copies of `@ui-sdk/core`. Each copy keeps its own list of components, so the
407
+ bridge's copy never hears of the calendar.
408
+
409
+ Check these first:
410
+
411
+ - **A frame.** The calendar renders `Calendar.Frame` inside `Root`. Without one it isn't listed.
412
+ - **One version.** `@ui-sdk/core` and `@ui-sdk/react` are installed once, at the same version.
413
+ `pnpm why @ui-sdk/core` or `npm ls @ui-sdk/core` shows more than one when they aren't.
414
+ - **One import path for the bridge.** Import `createAgent` from `@ui-sdk/react/agent`, the adapter
415
+ your calendar uses. A Solid app imports it from `@ui-sdk/solid/agent`.
416
+ - **The dev server's pre-bundle.** Vite pre-bundles dependencies in development. When one package
417
+ that imports `@ui-sdk/core` is kept out of the pre-bundle and another isn't, the page loads the
418
+ core twice. Solid's Vite plugin does that for `@ui-sdk/solid`. Keep the core out as well:
419
+
420
+ ```ts title="vite.config.ts"
421
+ import { defineConfig } from "vite";
422
+
423
+ export default defineConfig({
424
+ optimizeDeps: {
425
+ // One copy of the core, unbundled, for the calendar and the bridge alike.
426
+ exclude: ["@ui-sdk/core"],
427
+ },
428
+ });
429
+ ```
430
+
431
+ With two copies the calendar's own parts can stop following its state too, so a toolbar that no
432
+ longer updates is the same problem. Check a new setup in the browser: mount a calendar, call
433
+ `agent.snapshot()`, and expect one entry with `component: "calendar"`.
434
+
435
+ Next, see [who made a change](./changes.md).