slotlock 0.6.3 → 0.8.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/CHANGELOG.md +511 -0
- package/CONTRIBUTING.md +12 -5
- package/README.md +50 -1551
- package/SECURITY.md +5 -2
- package/SPEC.md +1 -1
- package/agent-server.d.ts +160 -8
- package/agent-server.js +559 -44
- package/agent-store-backend.d.ts +34 -1
- package/agent-store-backend.js +1399 -38
- package/api-keys.d.ts +69 -3
- package/api-keys.js +217 -28
- package/application-api.d.ts +56 -3
- package/application-api.js +826 -15
- package/approvals.d.ts +88 -0
- package/approvals.js +293 -0
- package/assistant.d.ts +70 -1
- package/assistant.js +478 -50
- package/billing.d.ts +114 -0
- package/billing.js +258 -0
- package/config.d.ts +25 -4
- package/config.js +72 -3
- package/dashboard-assistant-ui.d.ts +21 -0
- package/dashboard-assistant-ui.js +438 -0
- package/dashboard-icon.d.ts +1 -0
- package/dashboard-icon.js +5 -0
- package/dashboard-markdown.d.ts +2 -0
- package/dashboard-markdown.js +157 -0
- package/dashboard-settings-ui.d.ts +1 -0
- package/dashboard-settings-ui.js +78 -0
- package/dashboard.d.ts +227 -7
- package/dashboard.js +2313 -247
- package/ddl.d.ts +51 -12
- package/ddl.js +2566 -54
- package/event-feed.d.ts +30 -4
- package/event-feed.js +171 -19
- package/index.d.ts +15 -4
- package/index.js +8 -2
- package/maintenance.d.ts +10 -0
- package/maintenance.js +16 -2
- package/metrics.d.ts +41 -0
- package/metrics.js +22 -0
- package/openapi.json +14675 -5957
- package/otel.d.ts +86 -0
- package/otel.js +273 -0
- package/overage.d.ts +33 -0
- package/overage.js +115 -0
- package/package.json +1 -1
- package/partner-billing.d.ts +81 -0
- package/partner-billing.js +333 -0
- package/partner-names.d.ts +8 -0
- package/partner-names.js +10 -0
- package/partners.d.ts +147 -0
- package/partners.js +375 -0
- package/plans.d.ts +92 -0
- package/plans.js +115 -0
- package/quotas.d.ts +108 -0
- package/quotas.js +258 -0
- package/rate-limit.d.ts +21 -1
- package/rate-limit.js +82 -15
- package/resource-profile.d.ts +135 -0
- package/resource-profile.js +263 -0
- package/rest-api.d.ts +2 -0
- package/rest-api.js +68 -3
- package/sandbox.d.ts +70 -0
- package/sandbox.js +295 -0
- package/self-host.d.ts +33 -5
- package/self-host.js +950 -22
- package/slotlock.manifest.json +1 -1
- package/store.d.ts +373 -4
- package/store.js +1212 -118
- package/teams.d.ts +25 -0
- package/teams.js +63 -0
- package/timezone.js +13 -1
- package/types.d.ts +95 -1
- package/usage.d.ts +106 -0
- package/usage.js +238 -0
package/README.md
CHANGED
|
@@ -14,16 +14,20 @@ TypeScript library.
|
|
|
14
14
|
- Free/busy says whether it is *certain*: a calendar not yet synced makes time unproven, not free.
|
|
15
15
|
- Tool names, schemas and errors work on Claude, OpenAI and every MCP host.
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Get started
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
```
|
|
19
|
+
The documentation is at [slotlock.pylota.io/docs](https://slotlock.pylota.io/docs/). There are
|
|
20
|
+
three ways to run Slotlock:
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
- **[Slotlock Cloud](docs/hosted/README.md)**: nothing to run. Sign in with GitHub at
|
|
23
|
+
`https://app.slotlock.pylota.io/dashboard`, create a key, and connect an agent to
|
|
24
|
+
`https://slotlock-api.pylota.io/mcp`. Free while it is a preview, best effort, with no service
|
|
25
|
+
level agreement.
|
|
26
|
+
- **[Self-host with Docker](#self-host-with-docker)**, or from npm with
|
|
27
|
+
[Self-hosting](https://slotlock.pylota.io/docs/self-host/).
|
|
28
|
+
- **[As a TypeScript library](#quick-start-the-next-free-slot)** inside your own Node.js service.
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
### Self-host with Docker
|
|
27
31
|
|
|
28
32
|
From a clone of this repository:
|
|
29
33
|
|
|
@@ -37,422 +41,26 @@ docker compose exec slotlock slotlock resource add vehicle-42 --timezone Europe/
|
|
|
37
41
|
| --- | --- |
|
|
38
42
|
| `http://localhost:8080/mcp` | MCP, with `Authorization: Bearer <SLOTLOCK_AUTH_TOKEN>` |
|
|
39
43
|
| `http://localhost:8080/a2a` | A2A 1.0, same token; card at `/.well-known/agent-card.json` |
|
|
40
|
-
| `http://localhost:8080/v1/…` | [REST](
|
|
44
|
+
| `http://localhost:8080/v1/…` | [REST](https://slotlock.pylota.io/docs/api/): the tools, and the [application API](https://slotlock.pylota.io/docs/reference/#application-api) for admin keys; described at `/openapi.json` |
|
|
41
45
|
| `http://localhost:8080/healthz` | Readiness, including the database |
|
|
42
46
|
| `http://localhost:8080/metrics` | Prometheus metrics, with `Authorization: Bearer <SLOTLOCK_METRICS_TOKEN>`; off without it |
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- `SLOTLOCK_AVAILABILITY` sets the default bookable hours. A resource can have its own
|
|
51
|
-
(`slotlock hours set`, or the dashboard); with neither, no slot is offered.
|
|
52
|
-
`SLOTLOCK_CONFIRM_WRITES=all` (as `.env.example` sets it; the server's default is `none`) makes
|
|
53
|
-
every write wait for a person.
|
|
54
|
-
- To serve beyond this machine, put a TLS proxy in front and set `SLOTLOCK_PUBLIC_URL`.
|
|
55
|
-
- The server limits requests per client address (before any key is looked up), per key, per
|
|
56
|
-
tenant and for the whole server, and answers `429 rate_limited` with `Retry-After` and the
|
|
57
|
-
`RateLimit` fields. The application API counts an admin key's calls in its tenant's own
|
|
58
|
-
`app_read` and `app_write` budgets, apart from the agents'; another key's are its own. A recurring create and every event update (a new title
|
|
59
|
-
re-expands a recurring event's series too) takes its write token, then waits for a slot: one at
|
|
60
|
-
a time per tenant (`tenant_series_writes`) and per server (`series_writes`); each server process
|
|
61
|
-
counts its own. A freed slot rests for as long as the server was busy while the write before
|
|
62
|
-
held it (at most a second), so with one slot, writes that each hold it under a second keep the
|
|
63
|
-
server busy at most about half the time. It then goes to the waiting tenant with the fewest
|
|
64
|
-
writes in flight and, among those, the one whose writes have kept the server busy least lately
|
|
65
|
-
(halving every ten seconds), then to the first to ask. So a tenant sending one write at a time
|
|
66
|
-
waits for the write running, its rest, and the other tenants with one write in flight whose
|
|
67
|
-
writes kept the server less busy: many such tenants, new ones included, can each go ahead of it
|
|
68
|
-
once. Tenants keeping more writes waiting never go ahead of it. Four more of a tenant's writes
|
|
69
|
-
may wait and the rest get 429. When the server's 64 places are all taken, a write from a tenant
|
|
70
|
-
with fewer writes in flight than the tenant with the most takes the place of that tenant's last
|
|
71
|
-
write, which gets 503 `server_busy`; otherwise it gets 503 at once. An expansion runs on the
|
|
72
|
-
server's main thread, so any request may also wait for the one running. A write that has waited
|
|
73
|
-
two seconds gets 429 while its tenant's own write is still running, otherwise 503
|
|
74
|
-
`server_busy`. An application API maintenance run waits the same way for slots of its own: one
|
|
75
|
-
per tenant, `maintenance_runs` per server. The health check is not counted. One tenant's
|
|
76
|
-
requests hold at most `tenant_transactions` (2) of the server's 10 database connections at once
|
|
77
|
-
and the rest wait their turn, so a tenant's writes waiting on its own locks leave the others to
|
|
78
|
-
other tenants and key lookups; a server with one tenant can set `tenant_transactions=10`. A
|
|
79
|
-
request whose transaction waits more than 5 seconds for a lock gets 503 `server_busy`.
|
|
80
|
-
With more than one server, `SLOTLOCK_SHARED_LIMITS=on` shares the tenant budgets (`tenant_*`,
|
|
81
|
-
`app_*`) through the database, so N servers allow a tenant its rate once, not N times; each server
|
|
82
|
-
checks its own buckets first, and goes on with them alone if the database cannot be reached.
|
|
83
|
-
`SLOTLOCK_LIMITS` changes the limits; behind a proxy, set `SLOTLOCK_TRUSTED_PROXY_HEADER` to the field it puts the
|
|
84
|
-
client's address in (`CF-Connecting-IP` behind Cloudflare) before the server takes traffic, or
|
|
85
|
-
every client shares the proxy's budget: the server logs a `client_address_field_ignored` warning
|
|
86
|
-
when such a field arrives without the setting. Behind two proxies, such as Cloudflare and then
|
|
87
|
-
kamal-proxy, name the first one's field: the server reads the last address of a list field such
|
|
88
|
-
as `X-Forwarded-For`, which the second proxy writes as Cloudflare's. A client can send that field
|
|
89
|
-
itself, so let nothing reach the server except through the proxy. Where something else can reach
|
|
90
|
-
it (another container on kamal-proxy's network), also set `SLOTLOCK_TRUSTED_PROXY_SECRET` and have
|
|
91
|
-
the proxy set `X-Slotlock-Proxy-Proof` to it on every request (a Cloudflare request header
|
|
92
|
-
transform rule): the field is then believed only beside that exact value, and any other request
|
|
93
|
-
is counted by its connection's address.
|
|
94
|
-
- The server also bounds what one tenant may store, whichever key, agent or application writes
|
|
95
|
-
it: 10,000 holds, and 100,000 each of bookings, calendar events and coverage rows, counted as
|
|
96
|
-
the store's `tenantLimits` count them, besides 10,000 resources. A write past one answers 409
|
|
97
|
-
`hold_limit_reached`, `reservation_limit_reached`, `event_limit_reached` or
|
|
98
|
-
`coverage_limit_reached`; `SLOTLOCK_LIMITS` changes them (`tenant_holds`,
|
|
99
|
-
`tenant_reservations`, `tenant_events`, `tenant_coverage`).
|
|
100
|
-
|
|
101
|
-
```sh
|
|
102
|
-
slotlock hours set '[{"rrule":"FREQ=WEEKLY;BYDAY=SA","startMinutes":600,"durationMinutes":240}]' --resource vehicle-42
|
|
103
|
-
slotlock hours clear --all # back to SLOTLOCK_AVAILABILITY
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
A rule is `rrule`, `startMinutes` and `durationMinutes` here and in `SLOTLOCK_AVAILABILITY`. The
|
|
107
|
-
REST application API spells every field in snake_case, so there it is `rrule`, `start_minutes` and
|
|
108
|
-
`duration_minutes`. `slotlock --help` lists every setting.
|
|
109
|
-
|
|
110
|
-
#### Booking rules
|
|
111
|
-
|
|
112
|
-
A resource can also say what a booking on it must satisfy:
|
|
113
|
-
|
|
114
|
-
```sh
|
|
115
|
-
slotlock rules set '{"minNoticeMinutes":120,"slotStepMinutes":30,"turnaroundMinutes":30,"enforceHours":true}' --resource vehicle-42
|
|
116
|
-
slotlock rules clear --resource vehicle-42
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
| Rule | A booking made now |
|
|
120
|
-
| --- | --- |
|
|
121
|
-
| `minNoticeMinutes` | starts at least this far ahead |
|
|
122
|
-
| `maxAdvanceDays` | starts at most this far ahead |
|
|
123
|
-
| `slotStepMinutes` | starts on a step from local midnight in the resource's time zone |
|
|
124
|
-
| `stepOffsetMinutes` | starts this far past each step (0 to the step less one): with a 30-minute step, 15 starts bookings on :15 and :45 |
|
|
125
|
-
| `bufferBeforeMinutes` | keeps this long free before it: its leading buffer, which the database enforces |
|
|
126
|
-
| `turnaroundMinutes` | keeps this long free after it: its trailing buffer, which the database enforces |
|
|
127
|
-
| `enforceHours` | lies inside the resource's bookable hours |
|
|
128
|
-
| `checkInMinutes` | is claimed (`checkInReservation`) this long after its start, or maintenance releases it |
|
|
129
|
-
| `requireCertain` | lies in time every calendar sync recording coverage for the resource has read within a day |
|
|
130
|
-
|
|
131
|
-
- Holds, reservations, moves and agents' events are checked when they are made, by the database's
|
|
132
|
-
clock; a refusal names the rule (`booking_rule_violated` with `rule` in the store,
|
|
133
|
-
`booking_rule_min_notice`, `_max_advance`, `_slot_step`, `_outside_hours` or `_uncertain` to an
|
|
134
|
-
agent). Under `requireCertain`, a search (the store's and the tools') needs those syncs' coverage
|
|
135
|
-
too, read within a day, of the slot and its turnaround, so it offers no slot they leave unproven.
|
|
136
|
-
- A series is judged on its first occurrence for notice and advance, and on every occurrence for
|
|
137
|
-
step and hours. Imported calendar events are not checked: they happened elsewhere.
|
|
138
|
-
- Searches (`slotlock_find_next_available`, `slotlock_find_available_slots`, `findNextAvailableFor`)
|
|
139
|
-
offer only slots the rules allow, so an offered slot is one the write accepts.
|
|
140
|
-
- Two bookings stay at least the earlier one's trailing buffer plus the later one's leading buffer
|
|
141
|
-
apart: each occupies from its start less its leading buffer to its end plus its trailing one, and
|
|
142
|
-
the exclusion constraint keeps those apart. Free/busy reports that time as busy.
|
|
143
|
-
- The REST application API sets them with `PUT /v1/resources/{resource_id}/booking-rules`, in
|
|
144
|
-
snake_case; the store with `setResourceBookingRules`.
|
|
145
|
-
- Defaults: rules for every resource of the tenant (`PUT /v1/booking-rules`) and for every member
|
|
146
|
-
of a pool (`PUT /v1/pools/{pool}/booking-rules`), read back with `GET /v1/booking-rules`; the
|
|
147
|
-
store's `setBookingRuleDefaults` and `getBookingRuleDefaults`. A resource's rules as they apply
|
|
148
|
-
(`effective_booking_rules`, `effectiveBookingRules`) are the tenant's defaults, overlaid by its
|
|
149
|
-
pool's, overlaid by its own: a rule set at a narrower level wins. `checkInMinutes` is a resource's
|
|
150
|
-
own only. The dashboard's resource page shows which rules a resource inherits, and from where.
|
|
151
|
-
- With no rule set anywhere, nothing changes: every rule is opt-in.
|
|
152
|
-
- A tenant has default rules for at most 1,000 pools (`pool_rules_limit_reached`, 409, for one
|
|
153
|
-
more). Merged rules are read leniently: a pool's `stepOffsetMinutes` under a resource's shorter
|
|
154
|
-
step applies modulo that step, and a field that is invalid on its own is ignored (and logged),
|
|
155
|
-
never read as refusing every booking.
|
|
156
|
-
|
|
157
|
-
### Without Docker
|
|
158
|
-
|
|
159
|
-
With Node.js 22.12+ and PostgreSQL 16 or newer, run each command as `npx slotlock` after
|
|
160
|
-
`npm install slotlock postgres`, or from a clone, built once, as `node dist/cli.js` (a clone does not
|
|
161
|
-
put `slotlock` on your `PATH`). Use two roles, as Compose does, so two URLs: `serve` connects as
|
|
162
|
-
`DATABASE_URL`, a role that owns nothing and cannot bypass row-level security, and `migrate`
|
|
163
|
-
connects as `SLOTLOCK_MIGRATE_DATABASE_URL`, the schema owner, and grants that role what it needs.
|
|
164
|
-
`serve` refuses to start as a superuser or a `BYPASSRLS` role, which row-level security does not
|
|
165
|
-
confine, and warns (`serving_as_schema_owner`) when its role owns the schema.
|
|
166
|
-
|
|
167
|
-
```sh
|
|
168
|
-
npm ci && npm run build
|
|
169
|
-
# Once, as a superuser:
|
|
170
|
-
# CREATE ROLE slotlock_app LOGIN PASSWORD '<app password>' NOSUPERUSER NOBYPASSRLS;
|
|
171
|
-
export SLOTLOCK_MIGRATE_DATABASE_URL='postgresql://<owner>:<owner password>@localhost:5432/slotlock'
|
|
172
|
-
export DATABASE_URL='postgresql://slotlock_app:<app password>@localhost:5432/slotlock'
|
|
173
|
-
export SLOTLOCK_AUTH_TOKEN="$(openssl rand -hex 32)"
|
|
174
|
-
export SLOTLOCK_CONFIRMATION_SECRET="$(openssl rand -hex 32)"
|
|
175
|
-
node dist/cli.js migrate
|
|
176
|
-
node dist/cli.js resource add vehicle-42 --timezone Europe/London
|
|
177
|
-
node dist/cli.js serve
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
The `slotlock …` commands in this README run the same way as `node dist/cli.js …` (with Compose,
|
|
181
|
-
`docker compose exec slotlock slotlock …`).
|
|
48
|
+
The server listens on `127.0.0.1:8080`, as a database role that cannot bypass row-level security.
|
|
49
|
+
`.env.example` makes every resource bookable on weekdays 09:00 to 17:00 and every write wait for a
|
|
50
|
+
person. The [Quickstart](https://slotlock.pylota.io/docs/quickstart/) walks through it with Claude
|
|
51
|
+
Code; [Self-hosting](https://slotlock.pylota.io/docs/self-host/) covers the published image,
|
|
52
|
+
configuration and commands, and [Operations](https://slotlock.pylota.io/docs/operations/#production-checklist)
|
|
53
|
+
the production checklist.
|
|
182
54
|
|
|
183
|
-
###
|
|
184
|
-
|
|
185
|
-
Give each agent its own key instead of sharing the server token:
|
|
55
|
+
### Quick start: the next free slot
|
|
186
56
|
|
|
187
57
|
```sh
|
|
188
|
-
|
|
189
|
-
slotlock key create "Availability bot" --scope read --expires-in-days 90
|
|
190
|
-
slotlock key create "Booking site" --scope read,write,admin
|
|
191
|
-
slotlock key list
|
|
192
|
-
slotlock key rotate <id>
|
|
193
|
-
slotlock key revoke <id>
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
- A key (`slk_…`) is shown once and stored only as a SHA-256. Send it as `Authorization: Bearer`.
|
|
197
|
-
- It acts in the tenant it was created for (`SLOTLOCK_TENANT`), so one server serves many tenants.
|
|
198
|
-
- `read` covers the seven tools that only look; `write` covers create, update and delete; `admin`
|
|
199
|
-
covers the [application API](#application-api), which no agent needs. Default: read and write.
|
|
200
|
-
- `rotate` keeps the key's id, scopes and bookings; `revoke` stops it on its next request.
|
|
201
|
-
- A tenant may hold 100 active keys. The last six characters are a checksum secret scanners can
|
|
202
|
-
verify offline.
|
|
203
|
-
|
|
204
|
-
### Retiring resources and tenants
|
|
205
|
-
|
|
206
|
-
```sh
|
|
207
|
-
slotlock resource archive vehicle-42 # no new bookings, holds or events; history kept
|
|
208
|
-
slotlock resource restore vehicle-42
|
|
209
|
-
slotlock resource delete vehicle-42 # with its history; refused while anything on it is live
|
|
210
|
-
slotlock tenant status
|
|
211
|
-
slotlock tenant suspend --reason "chargeback review"
|
|
212
|
-
slotlock tenant unsuspend
|
|
213
|
-
slotlock tenant erase --confirm "$SLOTLOCK_TENANT"
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
- The resource commands take a reference or an id, and act in `SLOTLOCK_TENANT`.
|
|
217
|
-
- A suspended tenant may read and writes nothing; its keys still authenticate, but it gets no new
|
|
218
|
-
key or secret. Only the schema owner suspends or lifts a suspension, so `suspend` and `unsuspend`
|
|
219
|
-
connect as `SLOTLOCK_MIGRATE_DATABASE_URL`'s role when it is set.
|
|
220
|
-
- `erase` deletes everything the tenant has, its API keys included, at once and for good;
|
|
221
|
-
`--confirm` must repeat the tenant. A suspension outlives it.
|
|
222
|
-
|
|
223
|
-
### Dashboard
|
|
224
|
-
|
|
225
|
-
The server can also serve a dashboard where people sign in with GitHub and manage their own keys and
|
|
226
|
-
resources, so you can give each person API keys without running `slotlock key create` for them:
|
|
227
|
-
|
|
228
|
-
1. On GitHub, open Settings, Developer settings, OAuth apps, New OAuth App, and set the
|
|
229
|
-
"Authorization callback URL" to `<SLOTLOCK_PUBLIC_URL>/dashboard/callback`. Then generate a
|
|
230
|
-
client secret on the app's page.
|
|
231
|
-
2. Set `SLOTLOCK_GITHUB_CLIENT_ID` and `SLOTLOCK_GITHUB_CLIENT_SECRET` from the app,
|
|
232
|
-
`SLOTLOCK_SESSION_SECRET` to 32+ random characters (`openssl rand -hex 32`), and
|
|
233
|
-
`SLOTLOCK_DASHBOARD_USERS` to the GitHub user ids that may sign in (`gh api users/<login> --jq .id`),
|
|
234
|
-
or to `*` for every GitHub account.
|
|
235
|
-
3. Run `slotlock serve` and open `<SLOTLOCK_PUBLIC_URL>/dashboard`. With Compose, set the four in
|
|
236
|
-
`.env` (empty, the default, leaves the dashboard off) and run `docker compose up --detach`.
|
|
237
|
-
|
|
238
|
-
- Its pages: an Overview with the coming week's bookings, events and live holds across every
|
|
239
|
-
resource (each in its resource's time zone) and the latest changes agents made, named by key;
|
|
240
|
-
Resources, each with its own page for bookable hours, booking rules, pool, coming bookings and
|
|
241
|
-
activity; Waitlist, to see who waits and remove an entry; API keys, with the MCP and A2A
|
|
242
|
-
endpoints; Webhooks, to add, delete and re-enable endpoints and see which are failing; and
|
|
243
|
-
Settings.
|
|
244
|
-
Everything on them is read from the tenant's own data. `SLOTLOCK_DASHBOARD_NAME` sets what the
|
|
245
|
-
dashboard calls the deployment (Slotlock by default).
|
|
246
|
-
- Each person gets a tenant of their own, `github:<user id>`: the keys, resources and bookings in it
|
|
247
|
-
are theirs alone. Keys made with `slotlock key create` act in `SLOTLOCK_TENANT` instead.
|
|
248
|
-
- **For organizations instead of people**, set `SLOTLOCK_DASHBOARD_ORGS` to the GitHub organization
|
|
249
|
-
ids the dashboard serves (`gh api orgs/<login> --jq .id`). Each is then one tenant,
|
|
250
|
-
`github-org:<id>`, that its members share: keys, resources and hours. A person signs in to the
|
|
251
|
-
served organizations they are an active owner or member of (a billing manager is neither),
|
|
252
|
-
switching between them when there are several; someone in none of them is refused. Every member
|
|
253
|
-
has the same power: each can create, rotate and revoke the organization's keys, and the key list
|
|
254
|
-
says who created each one. Membership is read at each sign-in, so a person who leaves keeps
|
|
255
|
-
the dashboard until their session ends (12 hours at most), and keys they made work until revoked.
|
|
256
|
-
Removing an id from the list signs its sessions out and stops its keys at once. An organization
|
|
257
|
-
that restricts OAuth apps must approve the dashboard's app (its Settings, Third-party access), or
|
|
258
|
-
GitHub hides the membership. `SLOTLOCK_DASHBOARD_USERS` still says who may sign in at all, and a
|
|
259
|
-
key records the person who created it (`github:<user id>`): erasing that person's own tenant
|
|
260
|
-
leaves it on keys they made in an organization, which go with the organization's erasure. Only the
|
|
261
|
-
first 100 memberships GitHub lists, and the first 20 served organizations by login, are read.
|
|
262
|
-
- Sign-in uses `state` and PKCE, and keeps nothing from GitHub but the user id and login (and, with
|
|
263
|
-
organizations, the served ones the person belongs to): the GitHub token is used once and dropped.
|
|
264
|
-
It asks for no scope, or `read:org` with organizations.
|
|
265
|
-
- A session is a signed, HttpOnly cookie that lasts 12 hours. The allowlist is checked on every
|
|
266
|
-
request, dashboard and API alike: removing an id and restarting the server signs that person out
|
|
267
|
-
and stops every key in their tenant at once.
|
|
268
|
-
- Every form carries a token bound to the session and must come from the server's own origin; the
|
|
269
|
-
pages run no inline script, under a Content-Security-Policy that allows only their own files.
|
|
270
|
-
- Give the dashboard an origin of its own (`https://slotlock.example.com`, not a path beside other
|
|
271
|
-
apps): its cookies are host-wide, so any other app on the same origin could read them.
|
|
272
|
-
- Finished sign-ins (a callback works once), signed-out sessions (a copied cookie stays out) and sent
|
|
273
|
-
forms (a reload does not create or rotate a key twice) are recorded in Postgres, so they hold on
|
|
274
|
-
every server that shares the database, behind any load balancer. Each is a SHA-256 digest, kept
|
|
275
|
-
until its cookie or form expires (12 hours at most); a form record also carries a digest of the
|
|
276
|
-
GitHub user id that sent it. The server role reaches them only through two SECURITY DEFINER
|
|
277
|
-
functions, and `serve` refuses to start the dashboard until `migrate` has granted them.
|
|
278
|
-
- The database's clock decides when a sign-in or session has expired, so servers whose clocks drift
|
|
279
|
-
from it or from each other cannot let a replay or a signed-out session through. Keep clocks in
|
|
280
|
-
sync all the same: a server more than 12 hours ahead of the database cannot sign anyone in.
|
|
281
|
-
- Each form carries a single-use value bound to its session. A person may have 1,000 forms
|
|
282
|
-
recorded at once (12 hours' worth); past that the dashboard answers 429 until the oldest expire.
|
|
283
|
-
Signing out always works.
|
|
284
|
-
- A person may add 100 resources. The database holds the cap, so adds racing on any number of servers
|
|
285
|
-
stop at 100; a resource they already have can still change time zone.
|
|
286
|
-
- Each resource uses the server's bookable hours (`SLOTLOCK_AVAILABILITY`) until its owner sets its
|
|
287
|
-
own on the hours page: two windows a day, overnight or all day, or closed. One form sets them
|
|
288
|
-
for every resource at once.
|
|
289
|
-
|
|
290
|
-
#### Assistant: operate Slotlock by chat
|
|
291
|
-
|
|
292
|
-
With `SLOTLOCK_ASSISTANT_SECRET` set (32+ random characters, `openssl rand -hex 32`), the dashboard
|
|
293
|
-
gains an Assistant page where every member chats with a model their organization connects, instead
|
|
294
|
-
of clicking. Each organization brings its own model:
|
|
295
|
-
|
|
296
|
-
- **Connect it** in Settings, Assistant (owners only; with personal tenants, each person): the
|
|
297
|
-
provider (`Anthropic Messages API`, or `OpenAI-compatible`, which covers OpenAI, OpenRouter,
|
|
298
|
-
vLLM, Ollama and LM Studio), the base URL (`https://api.anthropic.com`, or the one ending in
|
|
299
|
-
`/v1`: `https://api.openai.com/v1`, `http://localhost:11434/v1`; https, or http only on
|
|
300
|
-
`localhost` or `127.0.0.1`), the model name (`your-model`) and the API key, which a local model
|
|
301
|
-
may not need. As with webhooks, a URL whose host is, or resolves to, a loopback, private,
|
|
302
|
-
link-local, shared (CGNAT), unique-local or metadata address (`169.254.169.254`) is refused, when
|
|
303
|
-
it is saved and at each connection (the address the socket connects to is checked, so a name
|
|
304
|
-
rebound to one is refused too), and the page says why. For a self-hosted model on the server's
|
|
305
|
-
own machine or network (Ollama, vLLM), the operator sets `SLOTLOCK_ASSISTANT_PRIVATE_URLS=on`.
|
|
306
|
-
On Cloudflare Workers the literal check applies and names are not resolved: a Worker's fetch
|
|
307
|
-
reaches no private network. Changing the provider or the base URL takes the key again (decided in the
|
|
308
|
-
database write, so racing saves cannot get past it), so the stored key is only ever sent where it
|
|
309
|
-
was entered for, even on an origin that serves several accounts. **Test connection** makes one real request
|
|
310
|
-
and checks the model answers with one correct tool call. The organization's messages, and the bookings and resources the assistant
|
|
311
|
-
reads, are sent to the provider it configures.
|
|
312
|
-
- **The key** is stored sealed with AES-256-GCM under a key derived from `SLOTLOCK_ASSISTANT_SECRET`,
|
|
313
|
-
bound to the organization, in `slotlock.assistant_settings` (forced row-level security, erased
|
|
314
|
-
with the tenant). The dashboard shows only that it is set and its last four characters. Changing
|
|
315
|
-
the secret makes stored keys unreadable: owners enter them again.
|
|
316
|
-
- **Reads run, writes wait.** The server runs the tool loop, up to 8 model calls a message, with a
|
|
317
|
-
fixed list of the agent tools (the reads: resources, free-busy, next free time, slots, pool
|
|
318
|
-
availability, events; the writes: holds, bookings, pool and bundle bookings, changes and
|
|
319
|
-
cancellations). A read runs at once through the same operation boundary as an agent's. A write
|
|
320
|
-
never runs when the model asks: it appears as a proposed change the member approves (or
|
|
321
|
-
dismisses) with a form, and only then runs, once (its idempotency key is the dashboard's), with
|
|
322
|
-
the same booking rules, tenant limits and rate limits as an agent, recorded as
|
|
323
|
-
`dashboard-assistant:github:<user id>` (shown as "Assistant for @login"). The card leads with
|
|
324
|
-
the sentence a confirmation would ask (the resource by name, the times in its zone, and for a
|
|
325
|
-
change or cancellation the event's title, resource and time as it stands) and then shows every
|
|
326
|
-
argument in full; a change too large to show (16 KB of arguments) is not proposed, and a
|
|
327
|
-
conversation has at most 4 waiting. A proposal is only checked: the series-write slot and the
|
|
328
|
-
write's rate token are taken when the approved change runs. A message's reads share a budget of
|
|
329
|
-
16 calls and 400 resource-days. API keys, webhooks, booking rules, pools, erasure and
|
|
330
|
-
coverage are never offered; a tool the model names outside the list is refused.
|
|
331
|
-
- Tool results and booking data are data to the model, never instructions, and the system prompt
|
|
332
|
-
says so; the tool list does not change with what the model says. A member may send 10 messages
|
|
333
|
-
a minute; each model call has 30 seconds and a message 90. Conversations are kept per member in
|
|
334
|
-
`slotlock.assistant_conversations` for 2 hours after the last message, then deleted: by
|
|
335
|
-
`serve`'s maintenance, which sweeps every tenant's expired conversations every quarter hour (a
|
|
336
|
-
tenant only the dashboard serves included), by `slotlock maintain`, and whenever the tenant's
|
|
337
|
-
conversations are read (so on Workers too). They are bounded in UTF-8 bytes; **New conversation** forgets one. On Workers, the
|
|
338
|
-
assistant's agent calls are capped at 24 a request and by `tenant_read` and `tenant_write` of
|
|
339
|
-
`SLOTLOCK_LIMITS` in each isolate. A provider's failure is shown as a plain message, never with
|
|
340
|
-
the key or the provider's answer.
|
|
341
|
-
- It works as plain forms: no script is needed.
|
|
342
|
-
|
|
343
|
-
### Dashboard on Cloudflare Workers
|
|
344
|
-
|
|
345
|
-
The same dashboard can run as a Cloudflare Worker at an origin of its own (`workers/dashboard`),
|
|
346
|
-
while agents keep using the server. It shows the server's MCP and A2A URLs (`SLOTLOCK_SERVICE_URL`),
|
|
347
|
-
and reaches the server's database through Hyperdrive, as the role the server serves as.
|
|
348
|
-
|
|
349
|
-
`workers/dashboard/wrangler.jsonc` is an example: copy it into your own deployment and replace what
|
|
350
|
-
it marks as yours. This repository's Dashboard workflow only checks that the Worker bundles. Deploy
|
|
351
|
-
from your own pipeline with your own Cloudflare token: a token that can deploy Workers can replace
|
|
352
|
-
this one and read its session secret, which signs in as any tenant.
|
|
353
|
-
|
|
354
|
-
1. Create a Hyperdrive configuration for that role, with caching off: the dashboard reads back a
|
|
355
|
-
sign-in or a form it has just recorded, and a cached sign-out check would keep a copied session
|
|
356
|
-
working. Check it before each deploy (`wrangler hyperdrive get <id>`). For a database on a private
|
|
357
|
-
network, connect it through Workers VPC, on the Cloudflare Tunnel that reaches it. Point the VPC
|
|
358
|
-
service at a listener that serves only Slotlock's database, such as a PgBouncer with TLS and only
|
|
359
|
-
that database and role, rather than at the whole Postgres:
|
|
360
|
-
```sh
|
|
361
|
-
cd workers/dashboard && npm ci
|
|
362
|
-
npx wrangler vpc service create slotlock-postgres --type tcp --tunnel-id <tunnel id> \
|
|
363
|
-
--ipv4 <listener host> --tcp-port <listener port> --app-protocol postgresql
|
|
364
|
-
read -rs SLOTLOCK_DB_PASSWORD # not on the command line, so not in your shell history
|
|
365
|
-
npx wrangler hyperdrive create slotlock-dashboard --service-id <vpc service id> \
|
|
366
|
-
--database <database> --user <server role> --password "$SLOTLOCK_DB_PASSWORD" --caching-disabled
|
|
367
|
-
```
|
|
368
|
-
2. In your copy of the configuration, set:
|
|
369
|
-
- the configuration's id;
|
|
370
|
-
- your hostname (`routes`);
|
|
371
|
-
- `SLOTLOCK_PUBLIC_URL`, `SLOTLOCK_SERVICE_URL` and `SLOTLOCK_DASHBOARD_USERS` (`vars`);
|
|
372
|
-
- the three rate limiting bindings, each with a `namespace_id` unique in your account.
|
|
373
|
-
3. Create the GitHub OAuth app as above, with the callback URL
|
|
374
|
-
`<SLOTLOCK_PUBLIC_URL>/dashboard/callback` on the Worker's origin.
|
|
375
|
-
4. Store the secrets on the Worker: `npx wrangler secret put` for `SLOTLOCK_GITHUB_CLIENT_ID`,
|
|
376
|
-
`SLOTLOCK_GITHUB_CLIENT_SECRET` and `SLOTLOCK_SESSION_SECRET`, and `SLOTLOCK_ASSISTANT_SECRET`
|
|
377
|
-
for the assistant.
|
|
378
|
-
5. Deploy: `npm ci --omit=dev` at the repository root (the Worker bundles Slotlock's sources), then
|
|
379
|
-
`npx wrangler deploy --config <your configuration>` in `workers/dashboard`.
|
|
380
|
-
|
|
381
|
-
- Each request opens its own database client, at most five connections, and closes it when the
|
|
382
|
-
response is sent; Hyperdrive keeps the pool.
|
|
383
|
-
- Anyone may start a sign-in, and each callback costs a database write and a request to GitHub
|
|
384
|
-
with the app's client secret. An isolate runs at most eight at once, but Workers run many
|
|
385
|
-
isolates, so three rate limiting bindings bound them all:
|
|
386
|
-
- `SLOTLOCK_CLIENT_RATE_LIMIT` counts every dashboard request per client address (an IPv6
|
|
387
|
-
client's /64, as `slotlock serve` counts it);
|
|
388
|
-
- `SLOTLOCK_SIGN_IN_RATE_LIMIT` counts sign-ins and callbacks per client network (an IPv6
|
|
389
|
-
client's /48, a site's allocation, as `slotlock serve` counts its sign-ins), so a site rotating
|
|
390
|
-
through its /64s cannot use up the ceiling;
|
|
391
|
-
- `SLOTLOCK_SIGN_IN_CEILING_RATE_LIMIT` counts them from every client together, set far above one
|
|
392
|
-
client's limit so a few clients cannot use it up for everyone.
|
|
393
|
-
|
|
394
|
-
Their counts are per Cloudflare location. Without either of the first two the Worker answers 503.
|
|
395
|
-
Without the ceiling, as in a configuration from before it, `SLOTLOCK_SIGN_IN_RATE_LIMIT` counts
|
|
396
|
-
every client together, and the Worker logs a warning: add the ceiling before lowering that
|
|
397
|
-
binding's limit to one client's. The example configuration also removes query strings (a
|
|
398
|
-
callback's OAuth code) from the URLs Workers Logs keep.
|
|
399
|
-
- With organizations, set `SLOTLOCK_DASHBOARD_ORGS` on both the Worker and the server: the server
|
|
400
|
-
takes an organization's keys only while its own list names it, whether or not it serves the
|
|
401
|
-
dashboard.
|
|
402
|
-
- Set `SLOTLOCK_DASHBOARD_USERS` on both the Worker and the server too: the server takes a person's
|
|
403
|
-
keys only while its own list allows them, whether or not it serves the dashboard, so removing a
|
|
404
|
-
person from both lists signs them out and stops their keys. A server without it takes every
|
|
405
|
-
person's keys.
|
|
406
|
-
- A missing or weak secret makes the Worker answer 503 and log which variable, never its value.
|
|
407
|
-
|
|
408
|
-
## Connect an MCP client
|
|
409
|
-
|
|
410
|
-
Point any Streamable HTTP client at `http://localhost:8080/mcp` with the token.
|
|
411
|
-
|
|
412
|
-
**Claude Code:**
|
|
413
|
-
|
|
414
|
-
```sh
|
|
415
|
-
claude mcp add --transport http slotlock http://localhost:8080/mcp \
|
|
416
|
-
--header "Authorization: Bearer $SLOTLOCK_AUTH_TOKEN"
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
**Cursor** (`~/.cursor/mcp.json`):
|
|
420
|
-
|
|
421
|
-
```json
|
|
422
|
-
{
|
|
423
|
-
"mcpServers": {
|
|
424
|
-
"slotlock": {
|
|
425
|
-
"url": "http://localhost:8080/mcp",
|
|
426
|
-
"headers": { "Authorization": "Bearer ${env:SLOTLOCK_AUTH_TOKEN}" }
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
**VS Code** (`.vscode/mcp.json`; it asks for the token once):
|
|
433
|
-
|
|
434
|
-
```json
|
|
435
|
-
{
|
|
436
|
-
"inputs": [
|
|
437
|
-
{ "type": "promptString", "id": "slotlock-token", "description": "Slotlock token", "password": true }
|
|
438
|
-
],
|
|
439
|
-
"servers": {
|
|
440
|
-
"slotlock": {
|
|
441
|
-
"type": "http",
|
|
442
|
-
"url": "http://localhost:8080/mcp",
|
|
443
|
-
"headers": { "Authorization": "Bearer ${input:slotlock-token}" }
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
58
|
+
npm install slotlock postgres
|
|
447
59
|
```
|
|
448
60
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
## Quick start: the next free slot
|
|
454
|
-
|
|
455
|
-
The availability maths needs no database:
|
|
61
|
+
Node.js 22.12+, PostgreSQL 16 or newer with `btree_gist` (created for you if missing), and
|
|
62
|
+
`postgres` ^3.4.5 as a peer dependency. TypeScript declarations are included. The availability
|
|
63
|
+
maths needs no database:
|
|
456
64
|
|
|
457
65
|
<!-- example: examples/availability.ts#next-slot -->
|
|
458
66
|
```ts
|
|
@@ -477,1151 +85,42 @@ export const slot = findNextAvailable({
|
|
|
477
85
|
// slot: 2026-09-14 10:00–12:00 UTC, the first two free hours after the busy one
|
|
478
86
|
```
|
|
479
87
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
## Set up PostgreSQL
|
|
484
|
-
|
|
485
|
-
| Role | Owns | Used for |
|
|
486
|
-
| --- | --- | --- |
|
|
487
|
-
| Deployment | the `slotlock` schema | `applySchema`, `applyTenantRls`, `grantApplicationRole`, once per release |
|
|
488
|
-
| Application | nothing (`NOSUPERUSER NOBYPASSRLS`) | all traffic, confined to one tenant by forced row-level security |
|
|
489
|
-
|
|
490
|
-
Create the application role once (`CREATE ROLE slotlock_app LOGIN PASSWORD '…' NOSUPERUSER
|
|
491
|
-
NOBYPASSRLS;`), then deploy as the owner:
|
|
492
|
-
|
|
493
|
-
<!-- example: examples/deploy.ts#deploy -->
|
|
494
|
-
```ts
|
|
495
|
-
import { createSlotlockStore } from 'slotlock';
|
|
496
|
-
import postgres from 'postgres';
|
|
497
|
-
|
|
498
|
-
export async function deploySlotlock(deployUrl: string, applicationRole: string): Promise<void> {
|
|
499
|
-
const sql = postgres(deployUrl, { max: 1, onnotice: () => {} });
|
|
500
|
-
try {
|
|
501
|
-
const store = createSlotlockStore(sql);
|
|
502
|
-
await store.applySchema();
|
|
503
|
-
await store.applyTenantRls();
|
|
504
|
-
await store.grantApplicationRole(applicationRole);
|
|
505
|
-
} finally {
|
|
506
|
-
await sql.end();
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
- `applySchema` is idempotent and safe to run from several instances at once.
|
|
512
|
-
- `grantApplicationRole` grants schema usage and DML on Slotlock's tables, and refuses
|
|
513
|
-
(`unsafe_application_role`) a role that could get around row-level security. Run it after every
|
|
514
|
-
`applySchema`. [SECURITY.md](./SECURITY.md#security-model) lists what it checks.
|
|
515
|
-
- `applySchema` refuses a `slotlock` schema another role controls (`unsafe_slotlock_schema`).
|
|
516
|
-
- Already have a tenant setting such as `app.tenant_id`? Pass `{ tenantContextSetting:
|
|
517
|
-
'app.tenant_id' }` to `createSlotlockStore`.
|
|
518
|
-
|
|
519
|
-
## Book and read as the application
|
|
520
|
-
|
|
521
|
-
<!-- example: examples/store.ts#connect -->
|
|
522
|
-
```ts
|
|
523
|
-
import { type SlotlockStore, createSlotlockStore } from 'slotlock';
|
|
524
|
-
import postgres from 'postgres';
|
|
525
|
-
|
|
526
|
-
export function openSlotlock(applicationUrl: string) {
|
|
527
|
-
const sql = postgres(applicationUrl, { max: 10 });
|
|
528
|
-
return { sql, store: createSlotlockStore(sql) };
|
|
529
|
-
}
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
<!-- example: examples/store.ts#book -->
|
|
533
|
-
```ts
|
|
534
|
-
export async function bookHandover(store: SlotlockStore, tenantRef: string) {
|
|
535
|
-
return store.withTenant(tenantRef, async (tenant) => {
|
|
536
|
-
const vehicle = await tenant.createResource({
|
|
537
|
-
tenantRef,
|
|
538
|
-
externalRef: 'vehicle-42',
|
|
539
|
-
timezone: 'Europe/London',
|
|
540
|
-
});
|
|
541
|
-
const handover = await tenant.putCalendarEvent({
|
|
542
|
-
tenantRef,
|
|
543
|
-
externalRef: 'handover-BK-42',
|
|
544
|
-
idempotencyKey: 'booking-BK-42-create',
|
|
545
|
-
expectedRevision: 0,
|
|
546
|
-
resourceId: vehicle.id,
|
|
547
|
-
start: new Date('2027-03-29T09:00:00Z'),
|
|
548
|
-
end: new Date('2027-03-29T10:00:00Z'),
|
|
549
|
-
timezone: 'Europe/London',
|
|
550
|
-
summary: 'Vehicle handover',
|
|
551
|
-
organizer: { email: 'fleet@example.com', name: 'Fleet Desk' },
|
|
552
|
-
attendees: [{ email: 'renter@example.com', participationStatus: 'needs_action', rsvp: true }],
|
|
553
|
-
reminders: [{ action: 'display', minutesBeforeStart: 30 }],
|
|
554
|
-
});
|
|
555
|
-
if (!handover.ok) throw new Error(`handover not booked: ${handover.code}`);
|
|
556
|
-
|
|
557
|
-
const freeBusy = await tenant.getFreeBusy({
|
|
558
|
-
tenantRef,
|
|
559
|
-
resourceId: vehicle.id,
|
|
560
|
-
window: { start: new Date('2027-03-29T00:00:00Z'), end: new Date('2027-03-30T00:00:00Z') },
|
|
561
|
-
});
|
|
562
|
-
return { vehicle, handover, freeBusy };
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
```
|
|
566
|
-
|
|
567
|
-
Run every store method inside `withTenant`. A call outside it is not refused: it runs with no tenant
|
|
568
|
-
context, so as the application role forced row-level security shows it no rows.
|
|
569
|
-
|
|
570
|
-
`withTenant` validates the tenant, sets the context transaction-locally on the one connection every
|
|
571
|
-
callback call uses, supports nested savepoints, and restores the previous context. Do not issue a
|
|
572
|
-
standalone `set_config(..., true)` through a pool: its transaction ends before the next call.
|
|
573
|
-
`withTenant(tenantRef, callback, { isolation: 'read committed' })` runs the callback in a READ
|
|
574
|
-
COMMITTED transaction whatever the role's default, and refuses inside a caller's transaction of
|
|
575
|
-
another level. A store sharing one pool among tenants can bound each tenant's share:
|
|
576
|
-
`createSlotlockStore(sql, { maxTenantTransactions, tenantLockTimeoutMs })` runs at most that many
|
|
577
|
-
of a tenant's `withTenant` transactions at once (the rest wait in the process, and leave the line
|
|
578
|
-
when `withTenant`'s `signal` aborts), and refuses one that waits longer than that for a lock with
|
|
579
|
-
`lock_timeout`, safe to retry. `slotlock serve` sets `tenant_transactions` (2) and 5,000.
|
|
580
|
-
|
|
581
|
-
`createResource({ ..., maxTenantResources })` refuses a new resource (`resource_limit_reached`) once
|
|
582
|
-
the tenant has that many (1-100,000); an existing `externalRef` is still updated. Capped creates for
|
|
583
|
-
one tenant take a database lock and count under READ COMMITTED, so racing ones stop at the cap on
|
|
584
|
-
any number of servers; inside a REPEATABLE READ or SERIALIZABLE transaction they refuse
|
|
585
|
-
(`invalid_transaction_isolation`). Uncapped creates take no lock.
|
|
586
|
-
|
|
587
|
-
`setResourceAvailability({ tenantRef, id, rules })` gives a resource its own bookable hours (`null`
|
|
588
|
-
uses the default, `[]` closes it); `setTenantAvailability({ tenantRef, rules })` sets every resource
|
|
589
|
-
of a tenant. `createSlotlockStoreAgentBackend` answers from a resource's own hours and calls
|
|
590
|
-
`availabilityRules` only for resources without them.
|
|
591
|
-
|
|
592
|
-
Waitlists: `joinWaitlist({ tenantRef, resourceId | pool, start, end, holderRef, offerTtlMs })`
|
|
593
|
-
waits for a window that is taken now. When it comes free (a cancel, a released or expired hold, a
|
|
594
|
-
no-show), `offerWaitlist` gives it to the entries in the order they joined: the first whose window
|
|
595
|
-
is free, on its resource or the first free member of its pool, gets a hold for its holder, and the
|
|
596
|
-
feed says so (`waitlist.offered`, with `hold_id`). Confirm the hold to book it; let it go and the next
|
|
597
|
-
is offered. Cancels, releases and moves, whether an agent (MCP, A2A) or the application API makes
|
|
598
|
-
them, offer at once; maintenance offers what lapses on its own (an expired hold, a no-show) and
|
|
599
|
-
expires entries whose window has started (`waitlist.expired`). With `checkInMinutes` in a
|
|
600
|
-
resource's booking rules, maintenance releases a booking made since the rule was set that nobody
|
|
601
|
-
checked in that long after its start, or after it was made for a walk-in (`reservation.no_show`),
|
|
602
|
-
and the waitlist is offered its time. Check-in opens an hour before the start; moving a booking to
|
|
603
|
-
another start clears it. Leaving the waitlist lets an offer not yet confirmed go with it.
|
|
604
|
-
|
|
605
|
-
Calendar tools speak the standards: `emitVAvailability({ rules, timezone, uid })` writes rules as an
|
|
606
|
-
iCalendar VAVAILABILITY (RFC 7953) and `parseVAvailability(text)` reads one back as
|
|
607
|
-
`{ timezone, rules }`; `toJSCalendarEvent(event)` answers a calendar event as a JSCalendar Event
|
|
608
|
-
(RFC 8984). The API serves them at `/v1/resources/{resource_id}/availability/ical` and
|
|
609
|
-
`/v1/tenant/events/{event_id}/jscalendar`.
|
|
610
|
-
|
|
611
|
-
Writing rules:
|
|
612
|
-
|
|
613
|
-
- Create with `expectedRevision: 0`; update with the revision you last read and a new idempotency
|
|
614
|
-
key. Replaying the same command and key returns the original result (`idempotent: true`); reusing
|
|
615
|
-
a key with a different payload returns `idempotency_conflict`.
|
|
616
|
-
- A conflicting opaque occurrence returns `{ ok: false, code: 'overlap' }`. Transparent events
|
|
617
|
-
never block.
|
|
618
|
-
- Cancelling leaves a tombstone, so a delayed create cannot resurrect the event; use a new external
|
|
619
|
-
reference for a genuinely new event.
|
|
620
|
-
- `listCalendarEvents` and `listResources` return at most 1,000 rows and page with keyset cursors.
|
|
621
|
-
|
|
622
|
-
### Holds, external bookings and the feed
|
|
623
|
-
|
|
624
|
-
<!-- example: examples/store.ts#holds -->
|
|
625
|
-
```ts
|
|
626
|
-
export async function holdBookAndFollow(store: SlotlockStore, tenantRef: string, resourceId: string) {
|
|
627
|
-
// Inside withTenant: outside it the application role's row-level security shows no rows.
|
|
628
|
-
const booked = await store.withTenant(tenantRef, async (tenant) => {
|
|
629
|
-
// Hold a window for ten minutes while the customer pays, then turn it into a booking.
|
|
630
|
-
const held = await tenant.acquireHold({
|
|
631
|
-
tenantRef,
|
|
632
|
-
resourceId,
|
|
633
|
-
start: new Date('2027-04-05T09:00:00Z'),
|
|
634
|
-
end: new Date('2027-04-05T10:00:00Z'),
|
|
635
|
-
ttlMs: 10 * 60_000,
|
|
636
|
-
});
|
|
637
|
-
if (!held.ok) throw new Error(`not held: ${held.code}`);
|
|
638
|
-
const confirmed = await tenant.confirmHold(held.hold.id, { tenantRef });
|
|
639
|
-
if (!confirmed.ok) throw new Error(`hold not confirmed: ${confirmed.code}`);
|
|
640
|
-
|
|
641
|
-
// A booking your own system already has, by its reference there: revision 1 creates it.
|
|
642
|
-
const imported = await tenant.createExternalReservation({
|
|
643
|
-
tenantRef,
|
|
644
|
-
externalRef: 'BK-43',
|
|
645
|
-
resourceId,
|
|
646
|
-
start: new Date('2027-04-05T11:00:00Z'),
|
|
647
|
-
end: new Date('2027-04-05T12:00:00Z'),
|
|
648
|
-
bufferAfterMs: 15 * 60_000,
|
|
649
|
-
revision: 1,
|
|
650
|
-
});
|
|
651
|
-
if (!imported.ok) throw new Error(`BK-43 not booked: ${imported.code}`);
|
|
652
|
-
return { booking: confirmed.reservation, imported: imported.reservation };
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
// What changed, oldest first, once committed: so in a withTenant of its own. Poll again with
|
|
656
|
-
// `after: feed.next`.
|
|
657
|
-
const feed = await store.withTenant(tenantRef, (tenant) =>
|
|
658
|
-
tenant.listChanges({ tenantRef, limit: 100 }),
|
|
659
|
-
);
|
|
660
|
-
if (!feed.ok) throw new Error(`feed not read: ${feed.code}`);
|
|
661
|
-
return { ...booked, feed };
|
|
662
|
-
}
|
|
663
|
-
```
|
|
664
|
-
|
|
665
|
-
### Recurring events
|
|
666
|
-
|
|
667
|
-
<!-- example: examples/store.ts#recurring -->
|
|
668
|
-
```ts
|
|
669
|
-
export async function scheduleWeeklyInspection(
|
|
670
|
-
store: SlotlockStore,
|
|
671
|
-
tenantRef: string,
|
|
672
|
-
resourceId: string,
|
|
673
|
-
) {
|
|
674
|
-
return store.withTenant(tenantRef, (tenant) =>
|
|
675
|
-
tenant.putCalendarEvent({
|
|
676
|
-
tenantRef,
|
|
677
|
-
externalRef: 'inspection-vehicle-42',
|
|
678
|
-
idempotencyKey: 'inspection-vehicle-42-create',
|
|
679
|
-
expectedRevision: 0,
|
|
680
|
-
resourceId,
|
|
681
|
-
start: new Date('2027-03-30T07:00:00Z'),
|
|
682
|
-
end: new Date('2027-03-30T08:00:00Z'),
|
|
683
|
-
timezone: 'Europe/London',
|
|
684
|
-
summary: 'Weekly inspection',
|
|
685
|
-
recurrence: { rrule: 'FREQ=WEEKLY;COUNT=8' },
|
|
686
|
-
materializationWindow: {
|
|
687
|
-
start: new Date('2027-03-30T00:00:00Z'),
|
|
688
|
-
end: new Date('2027-05-30T00:00:00Z'),
|
|
689
|
-
},
|
|
690
|
-
}),
|
|
691
|
-
);
|
|
692
|
-
}
|
|
693
|
-
```
|
|
694
|
-
|
|
695
|
-
Occurrences are stored for a window of at most 367 days and 2,000 occurrences; maintenance rolls
|
|
696
|
-
the window forward, never moving its end back. Outside it, before or after, free/busy reports the
|
|
697
|
-
time as unproven.
|
|
698
|
-
|
|
699
|
-
A rule is expanded within a budget of steps, a count of work that reads no clock, so the same input
|
|
700
|
-
is accepted or refused however loaded the machine: 500,000 for a feed (the whole read, from its
|
|
701
|
-
text) or for a stored series as maintenance rolls it, about half a second, and 50,000 for one event
|
|
702
|
-
as it is written, refused within a tenth of a second whatever its rule or time zone (on a laptop; a
|
|
703
|
-
4-vCPU Linux server takes up to twice as long). A step is about a microsecond: a step of ical.js's
|
|
704
|
-
search costs three, a weekday compared one, five days walked one, a year scanned three (and one for
|
|
705
|
-
each eight days it lists), and two weekdays of a year listed one. Each occurrence passed costs one
|
|
706
|
-
more, each conversion of a time in an IANA zone half (one and a half in a zone only the feed
|
|
707
|
-
defines), and each instant Intl is asked for to read a zone's offsets five, the first time an
|
|
708
|
-
expansion reads that day of the zone, whatever the process has read before. A feed's own time zones
|
|
709
|
-
(VTIMEZONE) count against the same budget, each change listed when one is expanded costing four
|
|
710
|
-
tenths: one written the way Outlook writes them, from 1601, costs about 6,000. A feed may carry 100
|
|
711
|
-
time zones and name 100 it does not define, 1,000 observances and 2,000 RDATE values in the zones it
|
|
712
|
-
carries, and 20,000 RDATE and EXDATE values in its events, and an event 8 RRULEs, each further one
|
|
713
|
-
costing a step at every occurrence its expansion passes; a property's name and parameters may take
|
|
714
|
-
8 KB and list 100. A MINUTELY to WEEKLY step, a `DURATION`, or an event's length may be a century at
|
|
715
|
-
most. A calendar that needs more, such as a rule that never occurs
|
|
716
|
-
(`FREQ=DAILY;BYMONTH=2;BYMONTHDAY=30`), is refused: `invalid_event` on a write, `invalid_icalendar`
|
|
717
|
-
from a feed.
|
|
718
|
-
|
|
719
|
-
A feed's rules are expanded from their start, and each series may pass 4,000 occurrences on the way
|
|
720
|
-
(a daily one, about 11 years) whatever the feed's other series take. A feed series with one DAILY or
|
|
721
|
-
WEEKLY rule and no COUNT, RDATE or `RANGE=THISANDFUTURE` override is searched from just before the
|
|
722
|
-
window instead, so a daily standup since 2014 reads like one that began this year. A stored series
|
|
723
|
-
keeps where its last expansion stopped, and the next one resumes there, so a daily series keeps
|
|
724
|
-
rolling for as long as it runs: its budget goes on the window, not on the years before it. A write
|
|
725
|
-
that changes a series searches from its start, and resumes from where it stopped only if that search
|
|
726
|
-
is over the budget. A place serves only the rule, start and time zone it was kept for, read by the
|
|
727
|
-
same version of ical.js, and never lies past an occurrence that could still reach the window (one
|
|
728
|
-
within the event's length and a day of it, or one an exception moves into it). Otherwise the series
|
|
729
|
-
is searched from its start, within the same budget. During maintenance, a stored series that
|
|
730
|
-
outgrows the budget, that an earlier release stored and this one refuses, or whose roll fails for
|
|
731
|
-
any other reason (a row no release could have written, such as a rule ical.js cannot read), is
|
|
732
|
-
counted as `refused` (its ids in `refusedEventIds`), keeps its old coverage and waits an hour behind
|
|
733
|
-
the others. A pass whose roll fails still prunes, then reports the failure.
|
|
734
|
-
`storedCalendarEventProblem(event)` says why this
|
|
735
|
-
release would refuse a stored event (a rule shape it no longer expands, `COUNT` with a yearly day
|
|
736
|
-
some years lack, or an exception that names no occurrence), or `null`; run it over your stored
|
|
737
|
-
events before upgrading.
|
|
738
|
-
|
|
739
|
-
A stored rule is daily or less frequent and follows RFC 5545's grammar: `COUNT=0`, an unknown or
|
|
740
|
-
repeated part, or `COUNT` with `UNTIL` is refused. Shapes ical.js 2.2.1 expands differently from
|
|
741
|
-
RFC 5545 are refused everywhere, a feed included, and `recurrenceRuleProblem(rule)` says why:
|
|
742
|
-
`BYWEEKNO`; a two-digit `BYDAY` ordinal; `BYSETPOS` other than with `FREQ=MONTHLY` and `BYDAY`
|
|
743
|
-
alone; `BYMONTH` with `FREQ=MONTHLY`; a negative `BYMONTHDAY` other than with `FREQ=MONTHLY` and
|
|
744
|
-
no `BYDAY`; `FREQ=YEARLY` with `BYMONTHDAY` but no `BYMONTH`, with a day none of its months has,
|
|
745
|
-
with `COUNT` or `BYDAY` and a day one of its months can lack, with `BYYEARDAY` and `BYMONTH` or
|
|
746
|
-
`BYMONTHDAY`, or with a numbered `BYDAY` and `BYMONTHDAY`; `BYHOUR` with `FREQ=HOURLY`,
|
|
747
|
-
`BYMINUTE` or `BYSECOND` with `FREQ=MINUTELY`, and any of them with `FREQ=MONTHLY` or `YEARLY`;
|
|
748
|
-
and `FREQ=SECONDLY`. A yearly day some years lack (29 February, or a 31st with April) occurs only
|
|
749
|
-
in the years that have it, as RFC 5545 says, so its series may not add an RDATE or a second RRULE.
|
|
750
|
-
A DATE `UNTIL` on a timed series includes its whole day on the series' clock. An event's time zone
|
|
751
|
-
is an IANA name, stored in its canonical spelling (`europe/london` becomes `Europe/London`); a UTC
|
|
752
|
-
offset such as `+05:00` is refused.
|
|
753
|
-
|
|
754
|
-
A recurrence exception names the occurrence it cancels or moves by that occurrence's instant, as
|
|
755
|
-
`expandCalendarEventOccurrences` reports it, and is exported as a UTC `RECURRENCE-ID`; one that
|
|
756
|
-
names no occurrence is refused, so a mistyped instant is an error rather than a cancellation that
|
|
757
|
-
frees nothing. A series' occurrences never overlap each other: one that reaches past the next one's
|
|
758
|
-
start (a day-long occurrence the night the clocks go forward) ends there, and the next ends at the
|
|
759
|
-
later of the two ends, so the series holds the same time as separate reservations.
|
|
760
|
-
|
|
761
|
-
### External calendars
|
|
762
|
-
|
|
763
|
-
Provider adapters (Google, Microsoft, CalDAV) stay in your application, with their credentials.
|
|
764
|
-
Slotlock gives them neutral boundaries:
|
|
765
|
-
|
|
766
|
-
- `normalizeExternalCalendarChange` for webhook changes; `parseICalendarChanges` and `emitICalendar`
|
|
767
|
-
for bounded iCalendar in and out; `emitITipCalendar` for invitations.
|
|
768
|
-
- `parseICalendarFeed` reads a feed series by series: a series it cannot read (a refused rule
|
|
769
|
-
shape, an end the clocks move onto its start, DTEND with DURATION, more than 4,000 occurrences
|
|
770
|
-
from its start, or more work than the feed's budget has left) is named in `refused` by UID, with
|
|
771
|
-
`limit: true` for the last two, and the rest is read. Treat a refused series' time as busy, or the
|
|
772
|
-
feed's coverage as incomplete. `parseICalendarChanges` refuses the whole feed instead.
|
|
773
|
-
- All-day events become whole local days in the calendar's time zone; a feed without one is refused.
|
|
774
|
-
- A TZID Intl knows is read as that IANA zone, whether or not the feed defines it (a VTIMEZONE's
|
|
775
|
-
own rules for such a name are not used); one only the feed defines, such as a Windows name, is
|
|
776
|
-
read from its VTIMEZONE. A floating time is read in the calendar's zone. So an UNTIL, EXDATE,
|
|
777
|
-
RDATE or RECURRENCE-ID written in UTC or another zone names the occurrence it means, a floating
|
|
778
|
-
UNTIL is read on the series' own clock, and a `RANGE=THISANDFUTURE` exception moves every later
|
|
779
|
-
occurrence by its own shift.
|
|
780
|
-
- An event with no length (a DATE-TIME DTSTART without DTEND or DURATION) occupies no time and is
|
|
781
|
-
left out. A PERIOD RDATE ends where its period does. A document whose root is not a VCALENDAR, or
|
|
782
|
-
an event that ends before it starts, is refused as `invalid_icalendar`.
|
|
783
|
-
- A series' DTSTART is its first occurrence, with or without an RRULE; every RRULE is expanded; an
|
|
784
|
-
instant two of them, or an RRULE and an RDATE, name is one occurrence; every EXDATE excludes the
|
|
785
|
-
occurrence it names (RFC 5545 §3.8.5). A DATE EXDATE of a timed series names the occurrence at the
|
|
786
|
-
series' start time that day.
|
|
787
|
-
- An occurrence of a series occupies both readings of it when the clocks change inside it: its
|
|
788
|
-
exact length from its start (RFC 5545 §3.8.5.3) and its written end on the wall clock (the later
|
|
789
|
-
instant of a repeated hour). 00:00-06:00 holds six hours the night the clocks go forward and
|
|
790
|
-
seven the night they go back. A start in a skipped hour moves forward by the gap; one in a
|
|
791
|
-
repeated hour is its first instant. One-off events, overrides and PERIOD RDATEs occupy exactly
|
|
792
|
-
the times they give. A series' occurrences never overlap each other, as for stored series. SPEC.md,
|
|
793
|
-
"Daylight-saving time", lists the cases.
|
|
794
|
-
- An override without DTEND or DURATION lasts its series' length. One whose RECURRENCE-ID names no
|
|
795
|
-
occurrence, or whose occurrence the series also EXDATEs, occupies its own time, as the provider
|
|
796
|
-
shows it. The instances of a CalDAV-expanded series are each read, the first with or without a
|
|
797
|
-
RECURRENCE-ID. An event with both DTEND and DURATION is refused.
|
|
798
|
-
- `parseTrustedICalendarEvents` reads times as `parseICalendarChanges` does, so a series stored from
|
|
799
|
-
it occupies what the feed reports; an all-day series, stored from local midnight to local
|
|
800
|
-
midnight, may also hold the hour after a midnight the clocks go forward on, never less. It drops
|
|
801
|
-
an EXDATE that names no occurrence, and refuses what a stored series cannot hold: a zone only the
|
|
802
|
-
feed defines (a Windows name such as `GMT Standard Time`; map it to an IANA zone first), a DTSTART
|
|
803
|
-
or DTEND the clocks skip (an all-day series' first midnight included), a `DURATION` that counts
|
|
804
|
-
days or weeks outside UTC, an instance whose transparency differs from its series', or a moved
|
|
805
|
-
instance that names no occurrence.
|
|
806
|
-
- `emitICalendar` and `emitITipCalendar` write a VTIMEZONE for the zone their times name (RFC 5545
|
|
807
|
-
§3.6.5), from the IANA rules: every change over the years the event covers, and, where a zone
|
|
808
|
-
changes on the same numbered or last weekday of a month every year, yearly rules that carry a
|
|
809
|
-
series on past them. A zone that does not, such as Casablanca, Gaza, Jerusalem or Santiago, is
|
|
810
|
-
exact over those years only.
|
|
811
|
-
- `recordCalendarCoverage` marks how much of a feed is read. Pass the sources a resource depends on as
|
|
812
|
-
`requiredSources`, and any coverage short of `complete` means the time is not proven free.
|
|
813
|
-
|
|
814
|
-
Read a feed someone else controls with `createICalendarWorkerPool`, which runs the same parsers on
|
|
815
|
-
worker threads. However costly the feed, the thread that serves requests never runs ical.js on it: a
|
|
816
|
-
worker past its deadline (3 seconds by default) or its heap (128 MB) is stopped, and the feed is
|
|
817
|
-
refused with `CalendarExpansionLimitError`. The pool offers `parseICalendarFeed` too. When every
|
|
818
|
-
worker is busy and the queue is full, the pool answers `ICalendarWorkerBusyError` at once. A worker
|
|
819
|
-
starts in about 40 ms and is reused; idle workers do not keep the process alive. The pool runs from
|
|
820
|
-
the built package (the worker is `ical-worker-thread.js`), not from Slotlock's TypeScript sources.
|
|
821
|
-
|
|
822
|
-
<!-- example: examples/feeds.ts#feeds -->
|
|
823
|
-
```ts
|
|
824
|
-
import {
|
|
825
|
-
CalendarExpansionLimitError,
|
|
826
|
-
ICalendarWorkerBusyError,
|
|
827
|
-
createICalendarWorkerPool,
|
|
828
|
-
} from 'slotlock';
|
|
829
|
-
|
|
830
|
-
// One pool for the process. Each feed is read on a worker thread; one that runs past its deadline
|
|
831
|
-
// or its heap is stopped, and the feed refused, while this thread carries on.
|
|
832
|
-
const feeds = createICalendarWorkerPool({ size: 2, deadlineMs: 3_000 });
|
|
833
|
-
|
|
834
|
-
export async function readFeed(text: string, window: { start: Date; end: Date }) {
|
|
835
|
-
try {
|
|
836
|
-
return {
|
|
837
|
-
ok: true as const,
|
|
838
|
-
changes: await feeds.parseICalendarChanges(text, undefined, window),
|
|
839
|
-
};
|
|
840
|
-
} catch (error) {
|
|
841
|
-
// Every worker is busy and the queue is full: read this feed on the next sync.
|
|
842
|
-
if (error instanceof ICalendarWorkerBusyError) return { ok: false as const, retry: true };
|
|
843
|
-
// The feed takes more than Slotlock will spend reading one: tell its owner, do not retry.
|
|
844
|
-
if (error instanceof CalendarExpansionLimitError) return { ok: false as const, retry: false };
|
|
845
|
-
throw error;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
export function closeFeeds() {
|
|
850
|
-
return feeds.close();
|
|
851
|
-
}
|
|
852
|
-
```
|
|
853
|
-
|
|
854
|
-
## Expose Slotlock to agents
|
|
855
|
-
|
|
856
|
-
One HTTP handler serves the tools over MCP and A2A. The tenant comes from your `authenticate`, never
|
|
857
|
-
from a tool argument.
|
|
858
|
-
|
|
859
|
-
<!-- example: examples/agent-server.ts#server -->
|
|
860
|
-
```ts
|
|
861
|
-
import {
|
|
862
|
-
type SlotlockAgentOperation,
|
|
863
|
-
type SlotlockAgentPrincipal,
|
|
864
|
-
type SlotlockStore,
|
|
865
|
-
createSlotlockAgentServer,
|
|
866
|
-
createSlotlockStoreAgentBackend,
|
|
867
|
-
createSlotlockStoreChangeSource,
|
|
868
|
-
} from 'slotlock';
|
|
869
|
-
import { createSlotlockNodeServer } from 'slotlock/node-server';
|
|
870
|
-
import type { Sql } from 'postgres';
|
|
871
|
-
|
|
872
|
-
const ALLOWED_OPERATIONS: ReadonlySet<SlotlockAgentOperation> = new Set([
|
|
873
|
-
'slotlock_list_resources',
|
|
874
|
-
'slotlock_get_free_busy',
|
|
875
|
-
'slotlock_find_next_available',
|
|
876
|
-
'slotlock_create_event',
|
|
877
|
-
'slotlock_get_event',
|
|
878
|
-
'slotlock_list_events',
|
|
879
|
-
'slotlock_update_event',
|
|
880
|
-
]);
|
|
881
|
-
|
|
882
|
-
export interface CalendarServerConfig {
|
|
883
|
-
store: SlotlockStore;
|
|
884
|
-
/** The store's client: live updates read the change feed's head with it. */
|
|
885
|
-
sql: Sql;
|
|
886
|
-
publicBaseUrl: string;
|
|
887
|
-
port: number;
|
|
888
|
-
verifyToken(token: string): Promise<SlotlockAgentPrincipal | null>;
|
|
889
|
-
allowInsecureLocalhost?: boolean;
|
|
890
|
-
confirmationSecret?: string;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
export async function startCalendarServer(config: CalendarServerConfig) {
|
|
894
|
-
const server = createSlotlockAgentServer({
|
|
895
|
-
publicBaseUrl: config.publicBaseUrl,
|
|
896
|
-
allowInsecureLocalhost: config.allowInsecureLocalhost === true,
|
|
897
|
-
...(config.confirmationSecret
|
|
898
|
-
? {
|
|
899
|
-
confirmation: {
|
|
900
|
-
operations: ['slotlock_create_event', 'slotlock_update_event'] as const,
|
|
901
|
-
secrets: [config.confirmationSecret],
|
|
902
|
-
},
|
|
903
|
-
}
|
|
904
|
-
: {}),
|
|
905
|
-
resourceWindowDays: 90,
|
|
906
|
-
// Live updates follow each tenant's change feed: a booking is announced as it commits.
|
|
907
|
-
subscriptions: { changes: createSlotlockStoreChangeSource(config.store, config.sql) },
|
|
908
|
-
backend: createSlotlockStoreAgentBackend(config.store, {
|
|
909
|
-
availabilityRules: async () => [
|
|
910
|
-
{ rrule: 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR', startMinutes: 9 * 60, durationMinutes: 480 },
|
|
911
|
-
],
|
|
912
|
-
}),
|
|
913
|
-
authenticate: async (request) => {
|
|
914
|
-
const token = /^Bearer (.+)$/.exec(request.headers.get('authorization') ?? '')?.[1];
|
|
915
|
-
return token ? config.verifyToken(token) : null;
|
|
916
|
-
},
|
|
917
|
-
authorize: async ({ operation }) => ALLOWED_OPERATIONS.has(operation),
|
|
918
|
-
health: async () => ({ ready: true, checks: ['database'] }),
|
|
919
|
-
});
|
|
920
|
-
|
|
921
|
-
const listener = createSlotlockNodeServer(server, {
|
|
922
|
-
requestOrigin: new URL(config.publicBaseUrl).origin,
|
|
923
|
-
});
|
|
924
|
-
await listener.listen({ host: '127.0.0.1', port: config.port });
|
|
925
|
-
return listener;
|
|
926
|
-
}
|
|
927
|
-
```
|
|
928
|
-
|
|
929
|
-
- `authorize` runs on every call with the current tool name, even when a client used an old alias.
|
|
930
|
-
Prefer an allow-list, so a tool added in a later release stays off until you allow it.
|
|
931
|
-
- `availabilityRules` returns the default bookable hours, for resources without their own. No
|
|
932
|
-
rules means never bookable.
|
|
933
|
-
- `confirmation` makes the listed writes wait for a person ([Confirm before writing](#confirm-before-writing)).
|
|
934
|
-
- `publicBaseUrl` must be HTTPS (`allowInsecureLocalhost` permits `http://localhost` for
|
|
935
|
-
development). Run the Node listener behind a TLS proxy, or mount `server.fetch` in any Fetch
|
|
936
|
-
runtime.
|
|
937
|
-
- The server sends no CORS headers: call it from your backend, not a web page.
|
|
938
|
-
|
|
939
|
-
### Endpoints
|
|
940
|
-
|
|
941
|
-
| Method and path | What |
|
|
942
|
-
| --- | --- |
|
|
943
|
-
| `POST {base}/mcp` | MCP over Streamable HTTP, stateless |
|
|
944
|
-
| `POST {base}/a2a` | A2A 1.0 JSON-RPC |
|
|
945
|
-
| `GET {base}/.well-known/agent-card.json` | A2A agent card, also at the origin root |
|
|
946
|
-
| `GET {base}/manifest.json` | Protocol versions, endpoints and every tool's JSON Schemas |
|
|
947
|
-
| `GET {base}/healthz` | Readiness from your `health` callback |
|
|
948
|
-
| `GET /.well-known/oauth-protected-resource{/path}` | OAuth metadata, when `oauth` is set |
|
|
949
|
-
| `{base}/v1/…`, `GET {base}/openapi.json` | [REST API](#rest-and-openapi) and its OpenAPI 3.1 document, when `rest` is on |
|
|
950
|
-
|
|
951
|
-
### Tools
|
|
952
|
-
|
|
953
|
-
| Tool | Does | Hints |
|
|
954
|
-
| --- | --- | --- |
|
|
955
|
-
| `slotlock_list_resources` | Resources visible to the tenant | read-only |
|
|
956
|
-
| `slotlock_get_free_busy` | Busy intervals plus coverage certainty | read-only |
|
|
957
|
-
| `slotlock_find_next_available` | Earliest *certain* slot across resources | read-only |
|
|
958
|
-
| `slotlock_find_available_slots` | Up to 50 *certain* slots, earliest first, to offer a choice | read-only |
|
|
959
|
-
| `slotlock_hold_slots` | Hold up to 5 candidates for 30-900 seconds while a person chooses | write |
|
|
960
|
-
| `slotlock_release_slots` | Release a hold and the rest of its group | write |
|
|
961
|
-
| `slotlock_book_together` | Book the same time on 2-20 resources, all or none | write |
|
|
962
|
-
| `slotlock_book_pool` | Book any one free member of a pool (a vehicle class, a room type) | write |
|
|
963
|
-
| `slotlock_get_pool_availability` | How many of a pool's members are free across a window | read |
|
|
964
|
-
| `slotlock_list_events` | Events the caller created in a window | read-only |
|
|
965
|
-
| `slotlock_get_event` | One event the caller created | read-only |
|
|
966
|
-
| `slotlock_create_event` | Create an event of up to 3,660 days (idempotent) | write |
|
|
967
|
-
| `slotlock_update_event` | Patch at an expected revision, optionally fenced to `expected_resource_id` | write |
|
|
968
|
-
| `slotlock_delete_event` | Tombstone at an expected revision | write, destructive |
|
|
969
|
-
|
|
970
|
-
A query window is at most 367 days. Each caller sees only the events it created, but everyone's
|
|
971
|
-
events count as busy time.
|
|
972
|
-
|
|
973
|
-
An agent offering a person several times holds them first, so none is taken while the person
|
|
974
|
-
decides: `slotlock_hold_slots` holds each free candidate in one group (and lists the taken ones in
|
|
975
|
-
`refused`), and `slotlock_create_event` with one `hold_id` books that time and releases the rest in
|
|
976
|
-
the same transaction. A hold belongs to the agent that took it: another agent can neither book nor
|
|
977
|
-
release it. One agent may have 20 live holds at once, holding at most 2,160 hours together in
|
|
978
|
-
`slotlock serve` (`SLOTLOCK_LIMITS`: `holder_holds`, `holder_held_hours`; `maxHoldsPerHolder` and
|
|
979
|
-
`maxHeldHoursPerHolder` in `createSlotlockStore`); past either it is refused, `hold_limit_reached` or
|
|
980
|
-
`held_time_limit_reached`. Unbooked holds expire by the database clock.
|
|
981
|
-
Notice was judged when the time was held, so booking the hold does not judge it again.
|
|
982
|
-
|
|
983
|
-
A booking that needs several resources at once (a van and its driver, a room and its projector)
|
|
984
|
-
uses `slotlock_find_available_slots` with `require_free` (every resource, or any n of them, free
|
|
985
|
-
together, each judged by its own hours and rules) and books with `slotlock_book_together`: one event
|
|
986
|
-
per resource in one transaction, all or none. A refusal names the `resource_id` that refused, on
|
|
987
|
-
MCP and A2A in the error beside its `code`, on REST in the problem. Bundles take their resources
|
|
988
|
-
in one order, so two racing over the same ones end with one booked, never a deadlock.
|
|
989
|
-
|
|
990
|
-
Rentals sell a class, not a plate. Put interchangeable resources in a pool
|
|
991
|
-
(`PUT /v1/resources/{id}/pool`, `setResourcePool`); agents see each resource's `pool`, list a pool's
|
|
992
|
-
members with `slotlock_list_resources` and `pool`, and book the class with `slotlock_book_pool`,
|
|
993
|
-
which takes the first member that is free and allows the booking, in one transaction: a class of
|
|
994
|
-
five sells exactly five for a time, however many race (`pool_full` after that). To see how many are
|
|
995
|
-
free, `slotlock_get_pool_availability` splits a window where that number changes (counting each
|
|
996
|
-
member busy over its bookings' occupied time, buffers included, but not the buffers a new booking
|
|
997
|
-
would keep, so a member it counts free may still refuse a booking that abuts another); to see which,
|
|
998
|
-
search the members with `slotlock_find_available_slots` and `require_free: 1`: each slot names the
|
|
999
|
-
members free in `resource_ids`. `GET /v1/pools` lists the pools with their capacity. The older names `calendar.<verb>` and `calendar_<verb>` still work and
|
|
1000
|
-
are no longer advertised.
|
|
1001
|
-
|
|
1002
|
-
### Errors
|
|
1003
|
-
|
|
1004
|
-
A refusal is a result the model can act on:
|
|
1005
|
-
|
|
1006
|
-
- **MCP**: `isError: true` with text `{"error":{"code":"…"}}`.
|
|
1007
|
-
- **A2A**: the reply's data part is `{"error":{"code":"…"}}`.
|
|
1008
|
-
|
|
1009
|
-
| Code | Meaning |
|
|
1010
|
-
| --- | --- |
|
|
1011
|
-
| `invalid_arguments` | Input failed the schema, or a window is inverted or longer than 367 days. A schema failure adds `issues`, up to 20 `{"path":[…],"message":"…"}`, each naming a field by its path in the arguments (`["rules",0,"start_minutes"]`; `[]` is the arguments as a whole): in `error` on MCP and A2A, beside `code` in REST's problem details |
|
|
1012
|
-
| `forbidden` | `authorize` refused the call |
|
|
1013
|
-
| `rate_limited` | `consumeRateLimit` refused the call |
|
|
1014
|
-
| `not_found`, `resource_not_found`, `event_not_found` | Not visible to this caller, or no such id: a resource id is the `id` `slotlock_list_resources` returns, not its `external_ref` |
|
|
1015
|
-
| `overlap` | The time is taken |
|
|
1016
|
-
| `revision_conflict`, `idempotency_conflict`, `event_cancelled` | Re-read, then retry with the current revision or a new key |
|
|
1017
|
-
| `owner_event_quota_exceeded`, `owner_command_quota_exceeded` | Per-caller quota reached (see [Operations](#operations)) |
|
|
1018
|
-
| `confirmation_required` | The write needs a person, and this client cannot ask one |
|
|
1019
|
-
| `confirmation_declined`, `confirmation_cancelled` | The person said no, or dismissed the question |
|
|
1020
|
-
| `invalid_cursor`, `invalid_event`, `invalid_window`, … | The store rejected a bounded input |
|
|
1021
|
-
| `request_aborted`, `server_busy`, `store_inconsistent` | Transient; retry |
|
|
1022
|
-
|
|
1023
|
-
#### Errors from your own backend
|
|
1024
|
-
|
|
1025
|
-
Throw `new SlotlockAgentOperationError('snake_case_code', status)` and the agent receives the code.
|
|
1026
|
-
Any other exception is a server fault, and its message never leaves the server: the agent gets
|
|
1027
|
-
`internal_error`, and `onError(error, { operation })` gets the error, as it does a result outside
|
|
1028
|
-
the operation's output schema, so you can log it. `slotlock serve` logs it as an `agent_error` line
|
|
1029
|
-
on stderr.
|
|
1030
|
-
|
|
1031
|
-
#### Protocol errors
|
|
1032
|
-
|
|
1033
|
-
| Where | Error |
|
|
1034
|
-
| --- | --- |
|
|
1035
|
-
| HTTP | `401` with `WWW-Authenticate`, `403` disallowed origin, `413`/`415` bad body, `429` rate limit (MCP, REST) |
|
|
1036
|
-
| MCP | `-32602` unknown tool, `arguments` that are not an object, or altered confirmation; `-32603` server fault; `-32601` unknown method |
|
|
1037
|
-
| MCP 2026-07-28 | `-32020` header disagrees with body, `-32021` form elicitation not declared, `-32022` unsupported revision, `-31029` rate limit |
|
|
1038
|
-
| A2A | `-32602` malformed message or parameters, `-32029` rate limit (`RATE_LIMITED`, in the 200 envelope like every A2A error), `-32009` unsupported `A2A-Version`, `-32003` push notifications, `-32004` task subscription or extended card, `-32001` task not found (the server keeps no tasks) |
|
|
1039
|
-
|
|
1040
|
-
### Authentication and OAuth discovery
|
|
1041
|
-
|
|
1042
|
-
`authenticate` checks whatever bearer token you issue. To let OAuth-capable MCP hosts find your
|
|
1043
|
-
authorization server, publish RFC 9728 metadata:
|
|
1044
|
-
|
|
1045
|
-
<!-- example: examples/oauth.ts#oauth -->
|
|
1046
|
-
```ts
|
|
1047
|
-
import type { SlotlockAgentServerOAuthOptions } from 'slotlock';
|
|
1048
|
-
|
|
1049
|
-
export const oauth: SlotlockAgentServerOAuthOptions = {
|
|
1050
|
-
authorizationServers: ['https://auth.example.com'],
|
|
1051
|
-
scopesSupported: ['calendar:read', 'calendar:write'],
|
|
1052
|
-
requiredScopes: ['calendar:read'],
|
|
1053
|
-
};
|
|
1054
|
-
```
|
|
1055
|
-
|
|
1056
|
-
A `401` from `/mcp` then points clients at the metadata and asks for `requiredScopes`. Slotlock only
|
|
1057
|
-
publishes it: `authenticate` must still validate each token, including its audience.
|
|
1058
|
-
|
|
1059
|
-
### Confirm before writing
|
|
1060
|
-
|
|
1061
|
-
With `confirmation`, a listed write first asks the person a yes/no question that says exactly what
|
|
1062
|
-
will change, such as `Book vehicle-42 for 2027-03-29 10:00–11:00 (Europe/London): "Vehicle
|
|
1063
|
-
handover".` Only an explicit yes runs the write.
|
|
1064
|
-
|
|
1065
|
-
- A booking that leaves the time free (`transparency: 'transparent'`) says so, and a write names
|
|
1066
|
-
the other fields it sets (`also description, attendees`) without quoting them.
|
|
1067
|
-
- Facts come first: the resource by its own reference, times in its own zone, and an event as it
|
|
1068
|
-
stands now, read through your backend's `describeResource` and `getEvent` when the caller may
|
|
1069
|
-
read them (within 2 seconds in all). Otherwise things are named by id, and each time carries its
|
|
1070
|
-
UTC offset. The agent's own text comes last, quoted.
|
|
1071
|
-
- A repeating booking says how many times it books, the first and the last, and each moved
|
|
1072
|
-
occurrence, from the same expansion the store books with; a change to one says it covers every
|
|
1073
|
-
repeat. Agents may send RFC 5545 rules that repeat daily or less often and can occur.
|
|
1074
|
-
- The pending question is sealed (HMAC-SHA256) to the caller, the tool and the exact arguments, and
|
|
1075
|
-
expires after `ttlSeconds` (600).
|
|
1076
|
-
- Clients that cannot ask (MCP 2025 revisions, A2A) get `confirmation_required`; nothing is written.
|
|
1077
|
-
- The yes comes from the client: Slotlock relies on the MCP client to ask its person, and a key
|
|
1078
|
-
holder's own client can answer for itself. Confirmation keeps an agent from writing unasked; it is
|
|
1079
|
-
not an authorization boundary. Scopes and `authorize` decide who may write.
|
|
1080
|
-
- `secrets` holds 1 to 8 keys of 32+ bytes: list the new one first to rotate. `onEvent` reports each
|
|
1081
|
-
outcome for audit.
|
|
1082
|
-
|
|
1083
|
-
### Calendar resources and live updates
|
|
1084
|
-
|
|
1085
|
-
On MCP 2026-07-28 each resource is also an MCP resource, `slotlock://resources/{id}`, whose read
|
|
1086
|
-
returns busy time and coverage for the next `resourceWindowDays` (30). `subscriptions/listen` streams
|
|
1087
|
-
`notifications/resources/updated` when a resource's free/busy changes.
|
|
1088
|
-
|
|
1089
|
-
- With `subscriptions.changes` (`createSlotlockStoreChangeSource(store, sql)`; `slotlock serve`
|
|
1090
|
-
sets it), changes come from the tenant's change feed: one reader per tenant per process, shared by
|
|
1091
|
-
all its subscriptions, polls the feed by cursor, one indexed query per read, under the tenant's
|
|
1092
|
-
row-level security. It reads again 250 ms after a read that found changes
|
|
1093
|
-
(`SLOTLOCK_FEED_BUSY_MS`, also the least gap between two reads) and backs off to once a second
|
|
1094
|
-
when quiet (`SLOTLOCK_FEED_IDLE_MS`), so a booking is announced within about a second. A change
|
|
1095
|
-
re-reads the subscriptions watching its resource, at most once a second each however many
|
|
1096
|
-
changes arrive, and each announces only what actually changed in its window. A cursor the feed
|
|
1097
|
-
has pruned past announces every watched resource once, then follows from now.
|
|
1098
|
-
- Each subscription is also re-read every `pollIntervalMs` (15 s with a feed, 10 s without one,
|
|
1099
|
-
which is then the only way changes are found), re-checking the caller each time, so a revoked key
|
|
1100
|
-
or what the feed does not carry (bookable hours) is caught.
|
|
1101
|
-
- A subscription ends after `maxDurationMs` (15 minutes), on `shutdown()`, or when access is lost.
|
|
1102
|
-
- At most 4 open per caller and 256 per server (`maxPerPrincipal`, `maxTotal`). `maxPerTenant`
|
|
1103
|
-
caps one tenant's across all its callers (default `maxTotal`; `slotlock serve` sets 16), so a
|
|
1104
|
-
tenant with many keys cannot hold every slot. When the server is full, a tenant holding fewer
|
|
1105
|
-
than the tenant holding most, less one, ends that tenant's oldest stream instead of being
|
|
1106
|
-
refused, so many tenants cannot hold every slot either. `slotlock serve` sets `maxTotal` to
|
|
1107
|
-
`subscriptions` (256) and lets one key hold `key_subscriptions` (4), and always fewer than its
|
|
1108
|
-
tenant may unless that is one, so one key cannot lock its tenant's other keys out.
|
|
1109
|
-
`subscriptions: false` turns them off.
|
|
1110
|
-
|
|
1111
|
-
### Caching and tracing
|
|
1112
|
-
|
|
1113
|
-
2026-07-28 results carry cache hints: discovery and tool lists are public for an hour, free/busy is
|
|
1114
|
-
never cached. W3C `traceparent`, `tracestate` and `baggage` reach your backend as `context.trace`.
|
|
1115
|
-
|
|
1116
|
-
`onEvent` hears about every call that names an operation, so you can count, time and correlate them:
|
|
1117
|
-
|
|
1118
|
-
- `{ type: 'call', protocol, operation, outcome, durationMs, traceId? }` for an MCP `tools/call` or
|
|
1119
|
-
A2A `SendMessage`; `outcome` is `ok`, the refusal's code (`overlap`, `rate_limited`, …), or why
|
|
1120
|
-
it was refused before it ran: `invalid_arguments`, `missing_capability` (a guarded write from a
|
|
1121
|
-
client that cannot confirm), `invalid_message` or `invalid_message_parameters` (A2A).
|
|
1122
|
-
- `{ type: 'rest', operation, status, durationMs, traceId? }` for a REST call, or one refused before
|
|
1123
|
-
it ran: a body that is not JSON (415, 400), too large (413) or not an object (400).
|
|
1124
|
-
- `{ type: 'confirmation', operation, outcome }` for each confirmation, before the call it decides.
|
|
1125
|
-
- A request refused before its operation is read is not reported: a missing credential, the rate
|
|
1126
|
-
limit, an `A2A-Version` other than 1.0, a JSON-RPC envelope that does not parse, a path no route
|
|
1127
|
-
has.
|
|
1128
|
-
- `traceId` is the trace id of a valid `traceparent` from `_meta` or the header. Arguments, callers,
|
|
1129
|
-
the parent span, `tracestate` and `baggage` are never reported, and an `onEvent` or `onError` that
|
|
1130
|
-
throws, or returns a promise that rejects, changes nothing a client sees. Resource reads and
|
|
1131
|
-
subscription polls are not reported.
|
|
1132
|
-
|
|
1133
|
-
`slotlock serve` writes each as a JSON line (`"event":"call"`, `duration_ms`, `trace_id`).
|
|
1134
|
-
|
|
1135
|
-
### REST and OpenAPI
|
|
1136
|
-
|
|
1137
|
-
`rest: true` also serves each tool as plain HTTP, described by an OpenAPI 3.1 document at
|
|
1138
|
-
`/openapi.json`. `slotlock serve` has it on; `SLOTLOCK_REST_API=off` turns it off.
|
|
1139
|
-
|
|
1140
|
-
| Request | Tool |
|
|
1141
|
-
| --- | --- |
|
|
1142
|
-
| `GET /v1/resources` | `slotlock_list_resources` |
|
|
1143
|
-
| `GET /v1/free-busy` | `slotlock_get_free_busy` |
|
|
1144
|
-
| `GET /v1/next-available` | `slotlock_find_next_available` |
|
|
1145
|
-
| `GET /v1/available-slots` | `slotlock_find_available_slots` |
|
|
1146
|
-
| `POST /v1/slot-holds` | `slotlock_hold_slots` |
|
|
1147
|
-
| `DELETE /v1/slot-holds/{hold_id}` | `slotlock_release_slots` |
|
|
1148
|
-
| `POST /v1/bundles` | `slotlock_book_together` |
|
|
1149
|
-
| `POST /v1/pool-bookings` | `slotlock_book_pool` |
|
|
1150
|
-
| `GET /v1/pool-availability` | `slotlock_get_pool_availability` |
|
|
1151
|
-
| `GET /v1/events` | `slotlock_list_events` |
|
|
1152
|
-
| `POST /v1/events` | `slotlock_create_event` |
|
|
1153
|
-
| `GET /v1/events/{event_id}` | `slotlock_get_event` |
|
|
1154
|
-
| `PATCH /v1/events/{event_id}` | `slotlock_update_event` |
|
|
1155
|
-
| `DELETE /v1/events/{event_id}` | `slotlock_delete_event` |
|
|
1156
|
-
|
|
1157
|
-
```sh
|
|
1158
|
-
curl "http://localhost:8080/v1/resources" -H "Authorization: Bearer $SLOTLOCK_API_KEY"
|
|
1159
|
-
```
|
|
1160
|
-
|
|
1161
|
-
- `GET` and `DELETE` take the tool's arguments as query parameters (a list repeats:
|
|
1162
|
-
`resource_ids=a&resource_ids=b`); `POST`, `PUT` and `PATCH` take a JSON body. Ids are in the path;
|
|
1163
|
-
percent-encode one that holds `/`.
|
|
1164
|
-
- Keys, scopes, `authorize` and the rate limit apply as over MCP. The body is the tool's output, or
|
|
1165
|
-
an [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) problem (`application/problem+json`) with
|
|
1166
|
-
the matching HTTP status: `type` (a tag URI, one per code), `title`, `status`, `code`, and
|
|
1167
|
-
`error.code` as well, the body earlier clients read. An `overlap` names the `resource_id`, `start`
|
|
1168
|
-
and `end` it refused. A `Link: <…>; rel="describedby"` header points at these docs.
|
|
1169
|
-
- A write's `idempotency_key` may come as the `Idempotency-Key` header instead
|
|
1170
|
-
([draft 08](https://datatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/)): a
|
|
1171
|
-
quoted Structured Field String (`Idempotency-Key: "booking-BK-42"`) or the bare key, equal to the
|
|
1172
|
-
argument when both are sent. A write that needs one and gets neither answers
|
|
1173
|
-
`400 idempotency_key_required`; the same key with another request, `422 idempotency_conflict`.
|
|
1174
|
-
An event write's key is kept 30 days (or `SLOTLOCK_RETENTION_DAYS`), then removed by maintenance,
|
|
1175
|
-
after which the key is new; a
|
|
1176
|
-
hold's until the hold would have expired, is released or is confirmed.
|
|
1177
|
-
- REST cannot ask a person, so a write listed in `confirmation` answers `428 confirmation_required`.
|
|
1178
|
-
- Free/busy and the next-available search read each resource they name once, however often it is
|
|
1179
|
-
named, and 10,000 busy intervals in all; the next-available search also expands 100,000 bookable
|
|
1180
|
-
windows from its resources' hours in all. Past either they answer `400 calendar_work_limit`: ask
|
|
1181
|
-
for fewer resources or a shorter window.
|
|
1182
|
-
- There are no CORS headers: call it from a server, not a browser.
|
|
1183
|
-
- From Python, Go, Rust, Java or .NET, use the [clients](clients/README.md): one method per
|
|
1184
|
-
operation, the application API included, each tested against the server in CI. For another
|
|
1185
|
-
language, generate one from [`openapi.json`](openapi.json) (or a server's `/openapi.json`, or
|
|
1186
|
-
`slotlock/openapi.json` in the npm package) with any OpenAPI 3.1 generator.
|
|
1187
|
-
|
|
1188
|
-
### Application API
|
|
1189
|
-
|
|
1190
|
-
What the application around the agents does, from any language: the store's resource, hours, hold,
|
|
1191
|
-
reservation, coverage and maintenance calls, as REST beside the tools. It needs a key with the
|
|
1192
|
-
`admin` scope ("Full" in the dashboard); the server's own `SLOTLOCK_AUTH_TOKEN`, the token agents
|
|
1193
|
-
are given, reads and writes but is never admin. It is never an MCP tool or an A2A skill, and never
|
|
1194
|
-
waits for a confirmation.
|
|
1195
|
-
|
|
1196
|
-
| Request | Does |
|
|
1197
|
-
| --- | --- |
|
|
1198
|
-
| `POST /v1/resources` | Create the resource with this `external_ref`, or update its `timezone`; `visibility: "private"` hides it from agents |
|
|
1199
|
-
| `GET /v1/resources/{resource_id}` | One resource, with its own weekly hours, visibility and `archived_at` |
|
|
1200
|
-
| `POST /v1/resources/{resource_id}/archive` | Take it out of use; `…/restore` puts it back |
|
|
1201
|
-
| `DELETE /v1/resources/{resource_id}` | Delete it with its history (`409 resource_in_use` while anything on it is live) |
|
|
1202
|
-
| `GET /v1/resources/{resource_id}/busy?start=…&end=…` | Its occupied time, private resources included |
|
|
1203
|
-
| `PUT /v1/resources/{resource_id}/availability` | `{"rules":[…]}`: its own weekly hours; `"rules":[]` never bookable, `"rules":null` the server's |
|
|
1204
|
-
| `PUT /v1/availability` | `{"rules":[…]}`: every resource's weekly hours at once |
|
|
1205
|
-
| `POST /v1/holds` | Hold a window for `ttl_seconds` (up to 7 days) |
|
|
1206
|
-
| `GET /v1/holds/{hold_id}` | One live hold; `GET /v1/resources/{resource_id}/holds` lists them |
|
|
1207
|
-
| `POST /v1/holds/{hold_id}/confirm` | Turn the hold into a reservation |
|
|
1208
|
-
| `DELETE /v1/holds/{hold_id}` | Release the hold |
|
|
1209
|
-
| `GET /v1/reservations/{reservation_ref}` | The booking at its current revision |
|
|
1210
|
-
| `GET /v1/resources/{resource_id}/reservations?start=…&end=…` | Its bookings in a window |
|
|
1211
|
-
| `PUT /v1/reservations/{reservation_ref}` | Book (`revision: 1`) or move (the current revision plus 1) |
|
|
1212
|
-
| `DELETE /v1/reservations/{reservation_ref}?revision=…` | Cancel, at the current revision plus 1 |
|
|
1213
|
-
| `PUT /v1/resources/{resource_id}/coverage/{source}` | Record that `source`'s events are complete for a window |
|
|
1214
|
-
| `GET /v1/tenant/events?resource_id=…&start=…&end=…` | Every key's events on a resource, with the `id` the next two take |
|
|
1215
|
-
| `GET /v1/tenant/events/{event_id}` | One of them |
|
|
1216
|
-
| `DELETE /v1/tenant/events/{event_id}?expected_revision=…` | Cancel it, whichever key wrote it |
|
|
1217
|
-
| `GET /v1/tenant` | The key's tenant, and whether it is suspended |
|
|
1218
|
-
| `POST /v1/tenant/erase` | Erase the tenant, when the server allows it |
|
|
1219
|
-
| `POST /v1/maintenance` | Run [maintenance](#operations) for the key's tenant |
|
|
1220
|
-
|
|
1221
|
-
```sh
|
|
1222
|
-
curl -X PUT "http://localhost:8080/v1/reservations/BK-42" \
|
|
1223
|
-
-H "Authorization: Bearer $SLOTLOCK_ADMIN_KEY" -H "Content-Type: application/json" \
|
|
1224
|
-
-d '{"resource_id":"<id>","start":"2027-03-29T09:00:00Z","end":"2027-03-31T09:00:00Z",
|
|
1225
|
-
"buffer_after_minutes":60,"revision":1}'
|
|
1226
|
-
```
|
|
1227
|
-
|
|
1228
|
-
- A taken window answers `409 overlap`. `buffer_after_minutes` keeps the time after a reservation
|
|
1229
|
-
busy for holds and other reservations alike.
|
|
1230
|
-
- Every write is safe to retry: the same reservation at its current revision answers
|
|
1231
|
-
`replayed: true`, a confirmed hold confirms again, and a cancelled reference stays cancelled (a
|
|
1232
|
-
late booking for it answers `409`). A late copy of a booking or a move that has since been
|
|
1233
|
-
superseded answers `409 stale_revision`.
|
|
1234
|
-
- A confirmed hold is the booking whose reference is the hold's id, at revision 1: cancel it with
|
|
1235
|
-
`DELETE /v1/reservations/{hold_id}?revision=2`.
|
|
1236
|
-
- `POST /v1/holds` and `DELETE /v1/tenant/events/…` take a retry identity as the `Idempotency-Key`
|
|
1237
|
-
header or as `idempotency_key`. A retried hold answers the hold the first request made; the same
|
|
1238
|
-
key with another request is `422 idempotency_conflict`. Other routes are safe to retry as they
|
|
1239
|
-
are, and refuse the header (`400 idempotency_key_not_supported`).
|
|
1240
|
-
- Lists page by `limit` (up to 100) and `cursor`, the `next_cursor` of the page before, and read a
|
|
1241
|
-
window of at most 367 days.
|
|
1242
|
-
- The time a calendar event occupies is the event's: reservation calls never find, move or cancel
|
|
1243
|
-
it, whatever reference they name. Change the event instead, or cancel it as the tenant with
|
|
1244
|
-
`DELETE /v1/tenant/events/{event_id}`, which needs its revision and an idempotency key, and
|
|
1245
|
-
takes `expected_resource_id` to fence it to the resource you read it on.
|
|
1246
|
-
- Erasing a tenant over the API is off unless the backend is created with `tenantErasure: true`
|
|
1247
|
-
(`slotlock serve` leaves it off: its operator runs `slotlock tenant erase`). It needs
|
|
1248
|
-
`confirm_tenant_ref` to be the tenant's reference (`GET /v1/tenant`), deletes every key the tenant
|
|
1249
|
-
has, the caller's included, and is refused while the tenant is suspended. Suspending a tenant is
|
|
1250
|
-
never an API call: only the schema owner may, and a tenant could not lift its own.
|
|
1251
|
-
- The tenant is the key's. Another tenant's resource or hold is `404`, whatever the database role.
|
|
1252
|
-
- With the library, pass `application` beside `rest: true`:
|
|
1253
|
-
`{ backend: createSlotlockStoreApplicationBackend(store, { maxTenantResources }), authorize }`.
|
|
1254
|
-
A principal with `scopes` needs `admin`; then `authorize` decides.
|
|
1255
|
-
|
|
1256
|
-
### Changes and webhooks
|
|
1257
|
-
|
|
1258
|
-
Every committed change to a tenant's holds, bookings, calendar events and configuration is recorded
|
|
1259
|
-
in the same transaction (by a database trigger, so no write path skips it), and nothing is recorded
|
|
1260
|
-
that did not commit. A change carries ids, times and states, never titles, descriptions, attendees,
|
|
1261
|
-
webhook URLs or secrets.
|
|
1262
|
-
|
|
1263
|
-
- The types: `hold.created`, `.updated`, `.confirmed`, `.released`, `.expired`;
|
|
1264
|
-
`reservation.created`, `.updated`, `.cancelled`, `.checked_in`, `.no_show`; `event.created`,
|
|
1265
|
-
`.updated`, `.cancelled`, `.timezone_shifted`, `.timezone_conflict`; `waitlist.offered`,
|
|
1266
|
-
`.expired`; `coverage.stale`; and configuration: `resource.created`, `resource.updated` (booking
|
|
1267
|
-
and check-in rules, pool, bookable hours, time zone or reference, with `before` and `after` of
|
|
1268
|
-
only the fields that changed), `resource.archived`, `.restored`, `.deleted`; `coverage.recorded`
|
|
1269
|
-
(a source's first read; reading it again is not a change) and `coverage.deleted`. A `coverage.*`
|
|
1270
|
-
change names its source by `source_id` (also its `subject`), never the source itself, which can
|
|
1271
|
-
be an iCalendar URL with a token or an address: `src_` and 32 random hex digits, made when the
|
|
1272
|
-
source is first recorded for the resource and kept until it is deleted, so it cannot be worked
|
|
1273
|
-
out from the source. `slotlock_get_coverage` (`listCoverage`) gives it beside the source, to
|
|
1274
|
-
match a change to its source. A change about a source deleted before 0.6 named it is
|
|
1275
|
-
`src_redacted`;
|
|
1276
|
-
`webhook.created`, `.enabled`, `.disabled`, `.deleted` (the id and `event_types`, never the URL);
|
|
1277
|
-
`key.created`, `.rotated`, `.revoked` (the id, scopes and expiry, never the key, its digest,
|
|
1278
|
-
prefix or name). `SLOTLOCK_CHANGE_TYPES` lists them.
|
|
1279
|
-
- Each change records who made it (`actor`: the API key or agent), the API key's id (`key_id`) when
|
|
1280
|
-
a key made it, and where it came from (`origin`): `mcp`, `a2a`, `rest` (the REST agent routes),
|
|
1281
|
-
`application` (the application API), `dashboard`, `dashboard-assistant`, `maintenance`, or
|
|
1282
|
-
`library`: code calling the store itself, inside `withTenant` with no `origin` or outside it, and
|
|
1283
|
-
any write that names none. Never an address or anything else about a person. A change an earlier
|
|
1284
|
-
release recorded has neither (`null`).
|
|
1285
|
-
- `key_id` is pseudonymous: the key's id, never the key or its name. It stays on the changes the key
|
|
1286
|
-
made after the key is revoked or deleted, for as long as the feed keeps them (the retention below,
|
|
1287
|
-
and longer while an enabled webhook has still to receive them); erasing the tenant removes them.
|
|
1288
|
-
|
|
1289
|
-
- `GET /v1/changes?cursor=…` lists them oldest first as [CloudEvents 1.0](https://cloudevents.io)
|
|
1290
|
-
(`io.pylota.slotlock.hold.created`, `.reservation.cancelled`, `.event.updated`, …), with the
|
|
1291
|
-
extension attributes `slotlockorigin` and `slotlockkeyid` when the change records them. Follow
|
|
1292
|
-
`next_cursor`, which comes back even when nothing is new: it never skips a change, even one whose
|
|
1293
|
-
transaction commits after a later one's. Changes are kept 30 days (`SLOTLOCK_RETENTION_DAYS`,
|
|
1294
|
-
`retentionDays` in `createSlotlockStore`, 1-3,650, for `serve` and `maintain` alike); a cursor
|
|
1295
|
-
that a pruned change came after, whichever server pruned it, answers `410 cursor_expired`. A change keeps who made
|
|
1296
|
-
it (`actor`) and a booking's or waitlist entry's reference: keep references opaque, not emails,
|
|
1297
|
-
when the feed is kept long. A shorter retention never shortens how long a retried write is
|
|
1298
|
-
answered as the first was: that stays at least 30 days.
|
|
1299
|
-
- `POST /v1/webhooks` with an https `url` (and `event_types`, optionally) sends each change from
|
|
1300
|
-
then on as a [Standard Webhooks](https://www.standardwebhooks.com) request: `webhook-id` (the
|
|
1301
|
-
change's id, the same on every retry), `webhook-timestamp` and `webhook-signature`, keyed by the
|
|
1302
|
-
`whsec_` secret the call returns once. `event_types` takes any of the types above. Verify it with any Standard Webhooks library, and use
|
|
1303
|
-
`webhook-id` to drop a repeat: delivery is at least once.
|
|
1304
|
-
- Changes go to each webhook in order, one at a time, until one fails; that one is retried after
|
|
1305
|
-
5 seconds, 5 minutes, 30 minutes, 2, 5, then every 10 hours. After a day of failures, or a `410`,
|
|
1306
|
-
the webhook is disabled and the feed records `webhook.disabled`; `POST /v1/webhooks/{id}/enable`
|
|
1307
|
-
resumes it where it stopped, or answers `409 changes_pruned` when what it missed is older than the
|
|
1308
|
-
feed keeps (add it again and read what it missed from `/v1/changes`). The feed keeps every change
|
|
1309
|
-
an enabled webhook has still to receive, however old. At most 10 webhooks per tenant.
|
|
1310
|
-
- Each request has 15 seconds in all, and a tenant's pass 30 seconds; tenants are delivered 8 at
|
|
1311
|
-
a time, so a slow endpoint holds up only its own tenant.
|
|
1312
|
-
- History reads the same record backwards, with who made each change (`actor`, `key_id`), where
|
|
1313
|
-
from (`origin`) and, for a change of an existing booking, event or resource, what it was before:
|
|
1314
|
-
`GET /v1/resources/{id}/history` (its bookings, events and its own configuration),
|
|
1315
|
-
`GET /v1/reservations/{reference}/history`, `GET /v1/tenant/events/{id}/history`, newest first,
|
|
1316
|
-
paged by `before`. In the library, pass `actor`, `origin` and `keyId` to `withTenant` (`origin`
|
|
1317
|
-
defaults to the enclosing call's, else `library`; `createSlotlockApiKeyAuthenticator` gives the
|
|
1318
|
-
principal its `keyId`), and `actor` and `origin` to the API key store's `create`, `rotate` and
|
|
1319
|
-
`revoke`; read `listHistory`. It is kept as long as the feed and erased with
|
|
1320
|
-
the tenant.
|
|
1321
|
-
- When time zone rules change (a new tzdata), a booking's instant and the wall time it was made for
|
|
1322
|
-
part: Winnipeg's 09:00 is no longer the instant stored. Slotlock keeps both, and maintenance finds
|
|
1323
|
-
future one-off events whose wall time moved: it reports each once (`event.timezone_shifted`, with
|
|
1324
|
-
the instant it has and the one its wall time now means). The library's `followZoneRules` option
|
|
1325
|
-
to `maintainSlotlockTenant` moves them instead, as a new revision, unless that overlaps another
|
|
1326
|
-
booking (`event.timezone_conflict`; it stays, for a person or an agent to decide). `/healthz`
|
|
1327
|
-
reports the `tzdata` the server runs.
|
|
1328
|
-
- Feed health: `GET /v1/resources/{id}/coverage` shows each source (and its `source_id`, as the feed
|
|
1329
|
-
names it), its window, when it was last read,
|
|
1330
|
-
its last error (`POST /v1/resources/{id}/coverage/{source}/failure` records one) and whether it is
|
|
1331
|
-
stale (not read for a day, so the time it covers is unproven, never free). A source that goes stale
|
|
1332
|
-
is put on the feed once, as `coverage.stale`, until it is read again. Retire a sync you have
|
|
1333
|
-
disconnected or replaced with `DELETE /v1/resources/{id}/coverage/{source}` (`deleteCoverage`):
|
|
1334
|
-
nothing waits on it after that, `requireCertain` included.
|
|
1335
|
-
- `slotlock serve` delivers (`SLOTLOCK_WEBHOOKS`): never to an address on a private network, which
|
|
1336
|
-
it checks when it connects, and following no redirect. `private` allows those, for testing.
|
|
1337
|
-
- In the library: `listChanges`, `createWebhookEndpoint` and the rest are store methods, and
|
|
1338
|
-
`startSlotlockWebhookDelivery` with `deliverSlotlockWebhooks` runs delivery in your own process.
|
|
88
|
+
The [TypeScript library](https://slotlock.pylota.io/docs/library/) guide sets up PostgreSQL, then
|
|
89
|
+
books, holds and reads time under row-level security.
|
|
1339
90
|
|
|
1340
91
|
## Connect an agent
|
|
1341
92
|
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
calls Slotlock directly, without an agent, can use the [REST clients](clients/README.md) for
|
|
1345
|
-
Python, Go, Rust, Java and .NET.
|
|
1346
|
-
|
|
1347
|
-
### MCP (any client)
|
|
1348
|
-
|
|
1349
|
-
<!-- example: examples/mcp-client.ts#mcp -->
|
|
1350
|
-
```ts
|
|
1351
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
1352
|
-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
1353
|
-
|
|
1354
|
-
export async function findSlotOverMcp(mcpUrl: string, token: string, resourceId: string) {
|
|
1355
|
-
const client = new Client({ name: 'fleet-assistant', version: '1.0.0' });
|
|
1356
|
-
const transport = new StreamableHTTPClientTransport(new URL(mcpUrl), {
|
|
1357
|
-
requestInit: { headers: { Authorization: `Bearer ${token}` } },
|
|
1358
|
-
});
|
|
1359
|
-
await client.connect(transport);
|
|
1360
|
-
try {
|
|
1361
|
-
const result = await client.callTool({
|
|
1362
|
-
name: 'slotlock_find_next_available',
|
|
1363
|
-
arguments: {
|
|
1364
|
-
resource_ids: [resourceId],
|
|
1365
|
-
start: '2027-03-29T00:00:00Z',
|
|
1366
|
-
end: '2027-04-05T00:00:00Z',
|
|
1367
|
-
duration_minutes: 120,
|
|
1368
|
-
},
|
|
1369
|
-
});
|
|
1370
|
-
if (result.isError) {
|
|
1371
|
-
const [text] = result.content as Array<{ type: 'text'; text: string }>;
|
|
1372
|
-
return { error: JSON.parse(text?.text ?? '{}').error as { code: string } };
|
|
1373
|
-
}
|
|
1374
|
-
return { slot: result.structuredContent };
|
|
1375
|
-
} finally {
|
|
1376
|
-
await client.close();
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
```
|
|
1380
|
-
|
|
1381
|
-
A refusal or conflict is a result (`isError`), not an exception. Slotlock speaks MCP 2026-07-28 to
|
|
1382
|
-
clients that ask for it and 2025-11-25 or 2025-06-18 to the rest.
|
|
1383
|
-
|
|
1384
|
-
### MCP 2026-07-28: confirmation and live updates
|
|
1385
|
-
|
|
1386
|
-
With the TypeScript SDK v2 (`@modelcontextprotocol/client`), a client shows Slotlock's confirmation
|
|
1387
|
-
to the person and hears about changes:
|
|
1388
|
-
|
|
1389
|
-
<!-- example: examples/mcp-live.ts#live -->
|
|
1390
|
-
```ts
|
|
1391
|
-
import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/client';
|
|
1392
|
-
import { slotlockCalendarResourceUri } from 'slotlock';
|
|
1393
|
-
|
|
1394
|
-
export interface LiveCalendarOptions {
|
|
1395
|
-
mcpUrl: string;
|
|
1396
|
-
token: string;
|
|
1397
|
-
resourceId: string;
|
|
1398
|
-
confirm(message: string): Promise<boolean>;
|
|
1399
|
-
onChange(uri: string): void;
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
export async function openLiveCalendar(options: LiveCalendarOptions) {
|
|
1403
|
-
const client = new Client(
|
|
1404
|
-
{ name: 'fleet-assistant', version: '1.0.0' },
|
|
1405
|
-
{ versionNegotiation: { mode: 'auto' }, capabilities: { elicitation: { form: {} } } },
|
|
1406
|
-
);
|
|
1407
|
-
client.setRequestHandler('elicitation/create', async (request) =>
|
|
1408
|
-
(await options.confirm(request.params.message))
|
|
1409
|
-
? { action: 'accept' as const, content: { confirm: true } }
|
|
1410
|
-
: { action: 'decline' as const },
|
|
1411
|
-
);
|
|
1412
|
-
client.setNotificationHandler('notifications/resources/updated', (notification) =>
|
|
1413
|
-
options.onChange(notification.params.uri),
|
|
1414
|
-
);
|
|
1415
|
-
await client.connect(
|
|
1416
|
-
new StreamableHTTPClientTransport(new URL(options.mcpUrl), {
|
|
1417
|
-
requestInit: { headers: { Authorization: `Bearer ${options.token}` } },
|
|
1418
|
-
}),
|
|
1419
|
-
);
|
|
1420
|
-
|
|
1421
|
-
const uri = slotlockCalendarResourceUri(options.resourceId);
|
|
1422
|
-
const subscription = await client.listen({ resourceSubscriptions: [uri] });
|
|
1423
|
-
return {
|
|
1424
|
-
watching: subscription.honoredFilter.resourceSubscriptions ?? [],
|
|
1425
|
-
book: (booking: Record<string, unknown>) =>
|
|
1426
|
-
client.callTool({
|
|
1427
|
-
name: 'slotlock_create_event',
|
|
1428
|
-
arguments: { resource_id: options.resourceId, ...booking },
|
|
1429
|
-
}),
|
|
1430
|
-
read: async () => {
|
|
1431
|
-
const [content] = (await client.readResource({ uri })).contents;
|
|
1432
|
-
return content && 'text' in content ? JSON.parse(content.text) : null;
|
|
1433
|
-
},
|
|
1434
|
-
close: async () => {
|
|
1435
|
-
await subscription.close();
|
|
1436
|
-
await client.close();
|
|
1437
|
-
},
|
|
1438
|
-
};
|
|
1439
|
-
}
|
|
1440
|
-
```
|
|
1441
|
-
|
|
1442
|
-
### Claude Code and the Claude API
|
|
1443
|
-
|
|
1444
|
-
**Claude Code:**
|
|
93
|
+
Point any Streamable HTTP MCP client at `http://localhost:8080/mcp` with the token (on Slotlock
|
|
94
|
+
Cloud, `https://slotlock-api.pylota.io/mcp` with an API key). Claude Code:
|
|
1445
95
|
|
|
1446
96
|
```sh
|
|
1447
|
-
claude mcp add --transport http slotlock
|
|
1448
|
-
--header "Authorization: Bearer $
|
|
1449
|
-
```
|
|
1450
|
-
|
|
1451
|
-
**Claude API** (MCP connector, `anthropic-beta: mcp-client-2025-11-20`; the server must be public
|
|
1452
|
-
over HTTPS):
|
|
1453
|
-
|
|
1454
|
-
```json
|
|
1455
|
-
{
|
|
1456
|
-
"model": "<model id>",
|
|
1457
|
-
"max_tokens": 1024,
|
|
1458
|
-
"mcp_servers": [
|
|
1459
|
-
{
|
|
1460
|
-
"type": "url",
|
|
1461
|
-
"url": "https://calendar.example.com/slotlock/mcp",
|
|
1462
|
-
"name": "slotlock",
|
|
1463
|
-
"authorization_token": "<token your authenticate accepts>"
|
|
1464
|
-
}
|
|
1465
|
-
],
|
|
1466
|
-
"tools": [{ "type": "mcp_toolset", "mcp_server_name": "slotlock" }],
|
|
1467
|
-
"messages": [{ "role": "user", "content": "When is vehicle 42 free for two hours next week?" }]
|
|
1468
|
-
}
|
|
1469
|
-
```
|
|
1470
|
-
|
|
1471
|
-
### A2A 1.0
|
|
1472
|
-
|
|
1473
|
-
<!-- example: examples/a2a-client.ts#a2a -->
|
|
1474
|
-
```ts
|
|
1475
|
-
import { SendMessageRequest } from '@a2a-js/sdk';
|
|
1476
|
-
import { ClientFactory } from '@a2a-js/sdk/client';
|
|
1477
|
-
|
|
1478
|
-
export async function listResourcesOverA2a(baseUrl: string, token: string) {
|
|
1479
|
-
const client = await new ClientFactory().createFromUrl(baseUrl);
|
|
1480
|
-
const reply = await client.sendMessage(
|
|
1481
|
-
SendMessageRequest.fromJSON({
|
|
1482
|
-
message: {
|
|
1483
|
-
messageId: crypto.randomUUID(),
|
|
1484
|
-
role: 'ROLE_USER',
|
|
1485
|
-
parts: [
|
|
1486
|
-
{
|
|
1487
|
-
data: { skill: 'slotlock_list_resources', arguments: { limit: 10 } },
|
|
1488
|
-
mediaType: 'application/json',
|
|
1489
|
-
},
|
|
1490
|
-
],
|
|
1491
|
-
},
|
|
1492
|
-
}),
|
|
1493
|
-
{ serviceParameters: { Authorization: `Bearer ${token}` } },
|
|
1494
|
-
);
|
|
1495
|
-
const part = 'parts' in reply ? reply.parts[0] : undefined;
|
|
1496
|
-
return part?.content?.$case === 'data' ? part.content.value : undefined;
|
|
1497
|
-
}
|
|
1498
|
-
```
|
|
1499
|
-
|
|
1500
|
-
Send one `application/json` data part, `{"skill": "<id>", "arguments": {…}}`, with header
|
|
1501
|
-
`A2A-Version: 1.0`. Each skill in the agent card has an example; replies are synchronous.
|
|
1502
|
-
|
|
1503
|
-
The card declares `streaming`. `SendStreamingMessage` with any skill streams its reply as one
|
|
1504
|
-
message. With `slotlock_watch_resources` (`{"resource_ids": [...]}`, up to 20) it streams a watch:
|
|
1505
|
-
a task in `TASK_STATE_WORKING` naming the resources it can see, then a status update
|
|
1506
|
-
`{"resource_id", "uri"}` each time one's free/busy changes, from the same feed and under the same
|
|
1507
|
-
caps as MCP subscriptions, until `TASK_STATE_COMPLETED` (its duration, shutdown) or
|
|
1508
|
-
`TASK_STATE_FAILED` (access withdrawn). Closing the stream ends it; the task is not kept, so
|
|
1509
|
-
`SubscribeToTask` and `GetTask` do not find it. Push notifications are not offered: a tenant's
|
|
1510
|
-
changes reach a URL as signed webhooks.
|
|
1511
|
-
|
|
1512
|
-
### MCP Apps
|
|
1513
|
-
|
|
1514
|
-
Read-only tools link to `ui://slotlock/calendar`, a self-contained calendar view that hosts
|
|
1515
|
-
supporting MCP Apps (`io.modelcontextprotocol/ui`) render in a sandbox. It makes no network requests
|
|
1516
|
-
and never writes.
|
|
1517
|
-
|
|
1518
|
-
A person can pick a slot in it. After `slotlock_find_available_slots` or a certain
|
|
1519
|
-
`slotlock_find_next_available`, the view shows a strip of days and each day's times by morning,
|
|
1520
|
-
afternoon and evening, or the one next available time. Picking a time and pressing *Book this time*
|
|
1521
|
-
sends one chat message naming the resource id and the slot's start and end. The agent books it with
|
|
1522
|
-
`slotlock_create_event`, through confirmation if `SLOTLOCK_CONFIRM_WRITES` asks for it. The message
|
|
1523
|
-
carries nothing else from the result. If the host refuses the message, the view shows the text to
|
|
1524
|
-
send instead. Write tools are marked `visibility: ["model"]`, so a host never lets a view call them.
|
|
1525
|
-
|
|
1526
|
-
The view takes its look from the host: its light or dark theme and its standard MCP Apps style
|
|
1527
|
-
variables (colours, fonts, sizes). It shows times in the person's locale, clock and time zone, with
|
|
1528
|
-
a 12h/24h switch.
|
|
1529
|
-
|
|
1530
|
-
## Operations
|
|
1531
|
-
|
|
1532
|
-
Every tenant needs maintenance at least daily: it extends recurring events to the rolling horizon
|
|
1533
|
-
and prunes what the retention window no longer needs, which is what returns agent quota.
|
|
1534
|
-
|
|
1535
|
-
- `slotlock serve` maintains `SLOTLOCK_TENANT` and every tenant with data when it starts (whether
|
|
1536
|
-
or not its keys call), then each hourly, one tenant at a time. It logs a `maintenance` line with
|
|
1537
|
-
counts. It finds the tenants through `slotlock.maintenance_tenants(text)`, which lists names
|
|
1538
|
-
only; each pass runs in its own tenant's context, under row-level security.
|
|
1539
|
-
- `slotlock maintain` runs one tenant's maintenance now, for cron or after a bulk import. An admin
|
|
1540
|
-
key can call `POST /v1/maintenance`.
|
|
1541
|
-
- Each pass holds a per-tenant PostgreSQL advisory lock, so servers and cron jobs never repeat each
|
|
1542
|
-
other's work; a pass that finds the lock taken does nothing.
|
|
1543
|
-
|
|
1544
|
-
In a process of your own:
|
|
1545
|
-
|
|
1546
|
-
<!-- example: examples/maintenance.ts#maintenance -->
|
|
1547
|
-
```ts
|
|
1548
|
-
import { type SlotlockStore, maintainSlotlockTenant } from 'slotlock';
|
|
1549
|
-
|
|
1550
|
-
export async function maintainTenant(store: SlotlockStore, tenantRef: string) {
|
|
1551
|
-
// Extends recurring events to the rolling horizon, then prunes past the retention window, each in
|
|
1552
|
-
// at most ten batches. `capped: true` means work was left: run another pass.
|
|
1553
|
-
return maintainSlotlockTenant(store, tenantRef, { batches: 10 });
|
|
1554
|
-
}
|
|
97
|
+
claude mcp add --transport http slotlock http://localhost:8080/mcp \
|
|
98
|
+
--header "Authorization: Bearer $SLOTLOCK_AUTH_TOKEN"
|
|
1555
99
|
```
|
|
1556
100
|
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
- **Capped passes.** A capped pass that extended and pruned nothing met only series it cannot extend
|
|
1561
|
-
(counted in `conflicts` and `refused`). The roll puts each behind every series it has not put
|
|
1562
|
-
back, for an hour, so with `rollPending: true` (it stopped before those) run another pass at once:
|
|
1563
|
-
it meets new ones, and a healthy series is reached however many are stuck. Otherwise another pass
|
|
1564
|
-
would meet the same ones, so wait for the next interval.
|
|
1565
|
-
- **Paging the roll yourself.** `rollCalendarEventHorizon` returns `next`; pass it as `after` to the
|
|
1566
|
-
next batch of the same pass, so later batches go on from the last series examined. Series the
|
|
1567
|
-
roll has never put back come first, then those it has, longest waiting first.
|
|
1568
|
-
- **Quotas.** Each agent principal may retain 1,000 event identities (active plus cancelled) and
|
|
1569
|
-
10,000 idempotency commands, of which 9,000 can be creates or updates, so a cancel always has
|
|
1570
|
-
room. Adjust with `agentOwnerEventQuota` and `agentOwnerCommandQuota` on `createSlotlockStore`.
|
|
1571
|
-
`pruneCalendarEventRetention` is what returns quota.
|
|
1572
|
-
- **Retention.** Commands are exact-replay evidence for the replay window, by default
|
|
1573
|
-
`SLOTLOCK_EVENT_COMMAND_RETENTION_DAYS` (30) days: pruning deletes older commands for every owner,
|
|
1574
|
-
then agent-owned tombstones older than the window with no command left. `internal` tombstones
|
|
1575
|
-
(provider and sync authority) are kept until you erase the tenant. After the window a retried
|
|
1576
|
-
command is evaluated afresh under its expected revision, and a pruned agent identity can be
|
|
1577
|
-
created again. `retentionDays` (1-3650) changes the window; keep it longer than any client retries.
|
|
1578
|
-
- **Erasure.** `slotlock tenant erase --confirm <tenant>`, or the store's `eraseTenant({ tenantRef })`,
|
|
1579
|
-
deletes everything the tenant owns in one transaction, waiting for its transactions in flight:
|
|
1580
|
-
resources, holds, bookings, events with their attendees and reminders, cancellations,
|
|
1581
|
-
idempotency records, coverage, API keys, and a personal tenant's dashboard records. Call it from
|
|
1582
|
-
your own erasure workflow; nothing is deleted table by table. Only the API keys' SHA-256 digests
|
|
1583
|
-
stay, with nothing about the tenant, so an erased key is never accepted again. The dashboard's
|
|
1584
|
-
other records hold no tenant and expire within 12 hours; a form record carries a SHA-256 digest
|
|
1585
|
-
of the GitHub user id that sent it, and an accepted write confirmation a digest of its nonce.
|
|
101
|
+
Cursor, VS Code, the Claude API and the MCP and A2A SDKs are in
|
|
102
|
+
[Connect an agent](https://slotlock.pylota.io/docs/connect/), and every `slotlock_*` tool's input,
|
|
103
|
+
output and errors in the [Tools reference](https://slotlock.pylota.io/docs/tools/).
|
|
1586
104
|
|
|
1587
|
-
|
|
105
|
+
## Documentation
|
|
1588
106
|
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
discovery, MCP, A2A, holds and reservations (in a resource named `slotlock-smoke`, 400 days
|
|
1607
|
-
ahead, cancelled after) and the 401, 409, 413 and 415 refusals.
|
|
1608
|
-
12. Rate-limit every public server. `slotlock serve` does it per client address, key, tenant and
|
|
1609
|
-
server (`SLOTLOCK_LIMITS`); behind a proxy, set `SLOTLOCK_TRUSTED_PROXY_HEADER` and firewall
|
|
1610
|
-
the server so nothing reaches it except through that proxy. Embedding the
|
|
1611
|
-
agent server, give it a `consumeRateLimit`. Watch serve's `refusals` log line for floods.
|
|
1612
|
-
13. On an upgrade, migrate first, then, as a library user, run `grantApplicationRole` again right
|
|
1613
|
-
after `applySchema` and before serving traffic: a release that adds a table (the leading-buffer
|
|
1614
|
-
release adds `booking_rule_defaults`, which every booking reads) fails every booking with a
|
|
1615
|
-
permission error until the serving role is granted it. `slotlock migrate` does both. A migration
|
|
1616
|
-
that rebuilds a constraint holds its table's lock for the whole build (see the CHANGELOG's
|
|
1617
|
-
Upgrading notes).
|
|
1618
|
-
14. Bound how long a transaction may run. A store over your own transaction (a savepoint per call)
|
|
1619
|
-
keeps its locks and its snapshot for as long as yours runs, and a hold you confirm inside it is
|
|
1620
|
-
judged by the statement's clock, not the transaction's. On PostgreSQL 17 and later, give the
|
|
1621
|
-
serving role a `transaction_timeout` above your longest legitimate transaction
|
|
1622
|
-
(`ALTER ROLE slotlock_app SET transaction_timeout = '60s'`): PostgreSQL ends one that runs
|
|
1623
|
-
longer, rolling back what it did, and closes its connection (the pool opens another). On 16, set `idle_in_transaction_session_timeout`
|
|
1624
|
-
and `statement_timeout`, which bound idle gaps and single statements but not the whole.
|
|
107
|
+
| For | Read |
|
|
108
|
+
| --- | --- |
|
|
109
|
+
| Running it | [Quickstart](https://slotlock.pylota.io/docs/quickstart/), [Self-hosting](https://slotlock.pylota.io/docs/self-host/), [Slotlock Cloud](docs/hosted/README.md) |
|
|
110
|
+
| API keys and scopes | [API keys](https://slotlock.pylota.io/docs/keys/) |
|
|
111
|
+
| Bookable hours and booking rules | [Hours and booking rules](https://slotlock.pylota.io/docs/booking-rules/) |
|
|
112
|
+
| The dashboard, organizations and the assistant | [Dashboard](https://slotlock.pylota.io/docs/dashboard/), [on Cloudflare Workers](https://slotlock.pylota.io/docs/dashboard-workers/) |
|
|
113
|
+
| Agents: tools, errors and protocols | [Connect an agent](https://slotlock.pylota.io/docs/connect/), [Tools reference](https://slotlock.pylota.io/docs/tools/), [Protocol reference](https://slotlock.pylota.io/docs/reference/) |
|
|
114
|
+
| REST, the application API, changes and webhooks | [REST API](https://slotlock.pylota.io/docs/api/), [Protocol reference](https://slotlock.pylota.io/docs/reference/#rest-and-openapi) |
|
|
115
|
+
| The library: store, holds, waitlists | [TypeScript library](https://slotlock.pylota.io/docs/library/) |
|
|
116
|
+
| Recurring events | [Recurring events](https://slotlock.pylota.io/docs/recurring-events/) |
|
|
117
|
+
| External calendars and iCalendar | [External calendars](https://slotlock.pylota.io/docs/external-calendars/) |
|
|
118
|
+
| Rate limits and tenant limits | [Limits](https://slotlock.pylota.io/docs/limits/) |
|
|
119
|
+
| Maintenance, retention and the production checklist | [Operations](https://slotlock.pylota.io/docs/operations/) |
|
|
120
|
+
| Scaling and benchmarks | [Scaling](https://slotlock.pylota.io/docs/scaling/), [Benchmarks](https://slotlock.pylota.io/docs/benchmarks/) |
|
|
121
|
+
| Clients for Python, Go, Rust, Java and .NET | [Clients](clients/README.md) |
|
|
122
|
+
| Concepts and the security model | [Concepts](https://slotlock.pylota.io/docs/concepts/), [Security](https://slotlock.pylota.io/docs/security/), [SECURITY.md](SECURITY.md) |
|
|
123
|
+
| The exact rules | [SPEC.md](SPEC.md) |
|
|
1625
124
|
|
|
1626
125
|
## Supported versions
|
|
1627
126
|
|