| 1 | # The Slides drive API |
| 2 | |
| 3 | This is the surface a program uses to build a deck, look at what it |
| 4 | made, and put it on a projector. A person's browser never touches it β |
| 5 | the screens are a separate thing, and neither one accepts the other's |
| 6 | credential. |
| 7 | |
| 8 | They do write the same document, though. Since slice 2 there is a |
| 9 | browser editor at `/d/{sqid}/edit`, and an op you post here and a |
| 10 | keystroke somebody types there land in one Yjs document as one ordered |
| 11 | log. Your `seq` moves when they type; theirs moves when you post. If you |
| 12 | want to know how a person's tab keeps up, "The live-sync wire" below |
| 13 | describes what the editor speaks. |
| 14 | |
| 15 | Everything below assumes the instance is at `https://slides.example`. |
| 16 | Replace it with your own. |
| 17 | |
| 18 | ## Getting a token |
| 19 | |
| 20 | A token belongs to an **agent**, and an agent belongs to a person β its |
| 21 | operator. Sign in, open **Agents** from the account menu, give the |
| 22 | agent a name, and press Create. The token is shown once, on the page |
| 23 | Create answers with, and never again: only its fingerprint is stored, |
| 24 | so there is nothing to show you a second time, and it is in no URL to |
| 25 | go back to. Copy it before you leave that page; lose it and you revoke |
| 26 | the agent and make another. |
| 27 | |
| 28 | A name is 2 to 32 characters of lowercase letters, digits and hyphens |
| 29 | β `claude`, `codex`, `release-bot`. It has to be different from every |
| 30 | other agent you have that is still live. |
| 31 | |
| 32 | The token looks like `sl_` followed by forty letters and digits. Send |
| 33 | it on every request: |
| 34 | |
| 35 | ``` |
| 36 | Authorization: Bearer sl_... |
| 37 | ``` |
| 38 | |
| 39 | Two rules worth knowing before you build anything on this: |
| 40 | |
| 41 | - **The API never reads a session cookie**, and the screens never read |
| 42 | a bearer. A request to `/api/v1/...` with a perfectly good session |
| 43 | and no token is a 401. |
| 44 | - **An agent sees exactly what its operator sees.** It can read and |
| 45 | write every deck that person can, and nothing else. It is not an |
| 46 | administrator and it cannot mint another token. |
| 47 | |
| 48 | Every change an agent makes is recorded against the agent, not the |
| 49 | person: the actor is `agent:<id>`, and the deck list shows it as |
| 50 | π€ `claude~you@example.com`. Revoking the agent stops the token |
| 51 | immediately; the history it already wrote keeps its name. |
| 52 | |
| 53 | A token also stops working when its **operator** does. If the person |
| 54 | who minted it is taken off `SLIDES_ALLOWED_ADDRESSES`, every request |
| 55 | this token makes is a `401` from then on β the same 401 a revoked token |
| 56 | gets, and for the same reason: an agent sees exactly what its operator |
| 57 | sees, and an operator who is no longer admitted here sees nothing. This |
| 58 | is checked on every request rather than at minting, so an offboarding |
| 59 | takes effect without anybody hunting down tokens. |
| 60 | |
| 61 | ## Shapes |
| 62 | |
| 63 | Requests with a body send JSON and say so: |
| 64 | `Content-Type: application/json`. Anything else is a 415. A body over |
| 65 | 1 MiB is a 413. The one exception is adding a picture, whose body is |
| 66 | the image itself (see `POST /api/v1/decks/{sqid}/assets`). |
| 67 | |
| 68 | Every answer with a body is JSON. Every error is: |
| 69 | |
| 70 | ```json |
| 71 | {"error": "invalid", "message": "op 1: no slide \"abc\"", "op": 1} |
| 72 | ``` |
| 73 | |
| 74 | `error` is a fixed English identifier β branch on it. `message` and |
| 75 | `op` are only on some of them. |
| 76 | |
| 77 | | Status | `error` | What happened | |
| 78 | |--------|--------------------------|---------------| |
| 79 | | 401 | `unauthorized` | No token, an unknown token, a revoked one, or one whose operator is no longer admitted on this instance. All four answer identically. | |
| 80 | | 403 | `forbidden` | Team mode only: making a deck when the roster says the operator is not on the team. | |
| 81 | | 404 | `not_found` | No such deck, slide or path β including a deck the operator cannot see. A deck that is not yours does not exist. | |
| 82 | | 405 | `method_not_allowed` | Right path, wrong verb. | |
| 83 | | 409 | `conflict` | Somebody else wrote to the deck while this batch was landing, twice. Re-read the deck and decide what your batch now means. | |
| 84 | | 413 | `too_large` | The body is over 1 MiB (a picture: over 20 MiB). | |
| 85 | | 415 | `unsupported_media_type` | The body is not `application/json`. | |
| 86 | | 422 | `invalid` | The request was read and refused. `message` says why; `op` is the index of the operation at fault, when the failure was about one. A body carrying anything after its JSON value is refused here too, rather than half-read. | |
| 87 | | 429 | `busy` | You already have four exports running. Wait for one to finish; nothing was started. | |
| 88 | | 500 | `internal` | Our fault. The server log has a matching line. | |
| 89 | | 503 | `unavailable` | Team mode only: the operator's team standing cannot be read right now (Home's roster is out of reach). Retry after `Retry-After` seconds. A deck list is never answered short in its place: it is all of it, or this. | |
| 90 | |
| 91 | On a **team instance** (one whose people come from Home's team roster), |
| 92 | an agent reaches exactly what its operator's roster standing reaches, asked |
| 93 | on every request: a team member's own decks, the team's decks and their |
| 94 | grants; somebody off the team only their grants. Taking the operator off |
| 95 | the team takes the agent's reach with it within a minute, without revoking |
| 96 | the token. |
| 97 | |
| 98 | --- |
| 99 | |
| 100 | ## Endpoints |
| 101 | |
| 102 | ### `GET /api/v1/decks` β every deck you can open |
| 103 | |
| 104 | ```sh |
| 105 | curl -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 106 | https://slides.example/api/v1/decks |
| 107 | ``` |
| 108 | |
| 109 | ```json |
| 110 | {"decks": [ |
| 111 | {"sqid": "k7m2xq9dwb", "title": "Q3 review", "slides": 12, |
| 112 | "rung": "private", "updated_at": "2026-09-07T09:41:02Z", "seq": 34} |
| 113 | ]} |
| 114 | ``` |
| 115 | |
| 116 | Most recently edited first. `sqid` is the deck's public name and what |
| 117 | every other endpoint takes. `rung` is who can open it: `private`, |
| 118 | `granted` or `team`. `seq` is the deck's version β it moves on every |
| 119 | write and on nothing else. |
| 120 | |
| 121 | ### `POST /api/v1/decks` β make one |
| 122 | |
| 123 | ```sh |
| 124 | curl -X POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 125 | -H "Content-Type: application/json" \ |
| 126 | -d '{"title": "Q3 review", "theme": "ink"}' \ |
| 127 | https://slides.example/api/v1/decks |
| 128 | ``` |
| 129 | |
| 130 | ```json |
| 131 | {"sqid": "k7m2xq9dwb"} |
| 132 | ``` |
| 133 | |
| 134 | 201. `title` is required; `theme` is one of `paper`, `ink`, `sunset`, |
| 135 | `forest`, `slate`, `candy`, and defaults to `paper`. The deck is owned |
| 136 | by your operator and starts on the `private` rung, exactly as one made |
| 137 | from the screen does β and like one made from the screen, it opens |
| 138 | with a title slide already on it. |
| 139 | |
| 140 | ### `GET /api/v1/decks/{sqid}` β the whole document |
| 141 | |
| 142 | ```sh |
| 143 | curl -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 144 | https://slides.example/api/v1/decks/k7m2xq9dwb |
| 145 | ``` |
| 146 | |
| 147 | ```json |
| 148 | {"sqid": "k7m2xq9dwb", "seq": 34, |
| 149 | "meta": {"title": "Q3 review", "theme": "ink", "accent": null, |
| 150 | "fonts": null, "aspect": "16:9"}, |
| 151 | "slides": [{"id": "hq3ktna7vc2m", "layout": "flow", "template": "title", |
| 152 | "background": {"kind": "theme", "value": ""}, |
| 153 | "phone": "inherit", "transition": "none", |
| 154 | "notes": [], "blocks": [...]}], |
| 155 | "assets": {}} |
| 156 | ``` |
| 157 | |
| 158 | The answer carries `ETag: "34"` β the seq, quoted. Send it back and an |
| 159 | unchanged deck is a 304 with no body, which costs the server nothing: |
| 160 | |
| 161 | ```sh |
| 162 | curl -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 163 | -H 'If-None-Match: "34"' \ |
| 164 | https://slides.example/api/v1/decks/k7m2xq9dwb |
| 165 | ``` |
| 166 | |
| 167 | A deck with scenes also carries `"scenes"`, keyed by scene id (see |
| 168 | Scenes, below). A deck without any has no `scenes` key at all. |
| 169 | |
| 170 | Poll this rather than re-fetching. It is how you tell whether anybody β |
| 171 | a person in the editor, another agent β has moved the deck since you |
| 172 | last looked. |
| 173 | |
| 174 | ### `POST /api/v1/decks/{sqid}/ops` β change it |
| 175 | |
| 176 | Everything that changes a deck goes through here, as a batch applied in |
| 177 | order inside one transaction. |
| 178 | |
| 179 | ```sh |
| 180 | curl -X POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 181 | -H "Content-Type: application/json" \ |
| 182 | -d '{"ops": [ |
| 183 | {"op": "add_slide", "layout": "flow", "template": "section"}, |
| 184 | {"op": "set_meta", "title": "Q3 review, final"} |
| 185 | ]}' \ |
| 186 | https://slides.example/api/v1/decks/k7m2xq9dwb/ops |
| 187 | ``` |
| 188 | |
| 189 | ```json |
| 190 | {"seq": 35, "ids": {"0": "hq3ktna7vc2m"}} |
| 191 | ``` |
| 192 | |
| 193 | **You do not have to invent ids.** `add_slide`, `add_block` and |
| 194 | `duplicate_slide` each need one, and if you leave it out the server |
| 195 | mints it and hands it back keyed by the operation's index β `"0"` is |
| 196 | the first operation you sent. Supply your own and it is used as given. |
| 197 | For `duplicate_slide` the returned id is the new slide's; the copied |
| 198 | blocks get ids too, and you read them back off the deck. |
| 199 | |
| 200 | **A refused batch changes nothing.** Not the good operations in front |
| 201 | of the bad one, not the seq β the whole batch is checked before the |
| 202 | first byte is written: |
| 203 | |
| 204 | ```json |
| 205 | {"error": "invalid", "op": 1, "message": "op 1: no slide \"nosuchslide\""} |
| 206 | ``` |
| 207 | |
| 208 | If two writers land at once you may get a `409 conflict`. The batch |
| 209 | applied nothing. Re-read the deck and send it again if it still makes |
| 210 | sense. |
| 211 | |
| 212 | ### `GET /api/v1/decks/{sqid}/slides/{id}.html` β look at a slide |
| 213 | |
| 214 | ```sh |
| 215 | curl -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 216 | 'https://slides.example/api/v1/decks/k7m2xq9dwb/slides/hq3ktna7vc2m.html?vp=phone' |
| 217 | ``` |
| 218 | |
| 219 | One `<section>` of HTML β the same markup the viewer renders β and |
| 220 | nothing around it. `vp=phone` renders the phone layout; leave it off |
| 221 | for the desktop one. This is how you check what you built without a |
| 222 | browser. |
| 223 | |
| 224 | ### `GET /api/v1/decks/{sqid}/slides/{id}.svg` β look at it as a picture |
| 225 | |
| 226 | ```sh |
| 227 | curl -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 228 | 'https://slides.example/api/v1/decks/k7m2xq9dwb/slides/hq3ktna7vc2m.svg' \ |
| 229 | -o slide.svg |
| 230 | ``` |
| 231 | |
| 232 | The slide as one 1920 by 1080 SVG: the same paint list the PDF is made |
| 233 | of, so what you see here is what the export will put on a page. Text is |
| 234 | `<text>` with a `<tspan>` per run at its measured position, pictures are |
| 235 | embedded as data URIs where they can be, and nothing in the file |
| 236 | fetches anything. |
| 237 | |
| 238 | `?w=` is a rendering hint and is in the `ETag`; it changes nothing about |
| 239 | the bytes today. The `ETag` is `(seq, slide, w)`, so send |
| 240 | `If-None-Match` and you will get a `304` until somebody edits the deck. |
| 241 | |
| 242 | It is not a substitute for reading the document: a picture is for |
| 243 | looking at what you made, and `GET /api/v1/decks/{sqid}` is for knowing |
| 244 | what is in it. |
| 245 | |
| 246 | ### `POST /api/v1/decks/{sqid}/assets` β add a picture |
| 247 | |
| 248 | The body is the image: a PNG, JPEG or WebP, at most 20 MiB, no more |
| 249 | than 30000 pixels either way and 50 megapixels in all. The type is read |
| 250 | from the bytes, not from `Content-Type`, so send whatever header your |
| 251 | client likes. The server reads the image's header for its type and |
| 252 | size, and does not decode the whole picture: a file whose header is |
| 253 | fine but whose pixels are broken is taken, and shows as a broken |
| 254 | picture. `?alt=` gives the picture its description, which a screen |
| 255 | reader says in place of it; leave it out only for a picture that is |
| 256 | decoration. The same bearer and the same decks as |
| 257 | `POST /api/v1/decks/{sqid}/ops`. |
| 258 | |
| 259 | ```sh |
| 260 | curl -X POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 261 | --data-binary @roadmap.png \ |
| 262 | "https://slides.example/api/v1/decks/k7m2xq9dwb/assets?alt=Three%20phases%2C%20each%20with%20a%20date" |
| 263 | ``` |
| 264 | |
| 265 | ```json |
| 266 | {"id": "b3k9xw2mq7tz", "ref": "9f2c1e...ab", "width": 1600, "height": 900} |
| 267 | ``` |
| 268 | |
| 269 | The server keeps the bytes under their SHA-256 (`ref`), as it does a |
| 270 | picture uploaded in the editor, and applies `register_asset` to the |
| 271 | deck as you, so anybody with the deck open sees it at once. `id` is the |
| 272 | asset's id in the deck: an image block names it as `props.asset`. |
| 273 | |
| 274 | The answer is `201` for a new picture. Send the same bytes to the same |
| 275 | deck again and the answer is `200` with the asset already there, its |
| 276 | `id` and `ref` unchanged; nothing is added. |
| 277 | |
| 278 | Then put it on a slide. Here `$S` is a slide made with the |
| 279 | `image-full` template, whose `media` region takes a picture; on a |
| 280 | canvas slide give a `box` instead, as under `add_block` below. |
| 281 | |
| 282 | ```sh |
| 283 | curl -X POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 284 | -H "Content-Type: application/json" \ |
| 285 | -d '{"ops":[{"op":"add_block","slide":"'"$S"'","type":"image", |
| 286 | "region":"media","props":{"asset":"b3k9xw2mq7tz"}}]}' \ |
| 287 | https://slides.example/api/v1/decks/k7m2xq9dwb/ops |
| 288 | ``` |
| 289 | |
| 290 | Refusals are `{"error": "β¦"}`, most with a `"message"` for you to |
| 291 | read; branch on `error`, since `message` is not always there: |
| 292 | `not_found` (no such deck, or not yours; 404, no message), `too_large` |
| 293 | (413), `not_an_image` (422: anything else, including SVG, bytes that |
| 294 | only start like a picture, and a header claiming too many pixels), and |
| 295 | `no_store` (503: this instance has nowhere to keep pictures). |
| 296 | |
| 297 | ### `POST /api/v1/decks/{sqid}/export` β make a PDF |
| 298 | |
| 299 | ```sh |
| 300 | curl -X POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 301 | -H "Content-Type: application/json" -d '{"notes": true}' \ |
| 302 | https://slides.example/api/v1/decks/k7m2xq9dwb/export |
| 303 | ``` |
| 304 | |
| 305 | ```json |
| 306 | {"job": "9Qb1t0RmS3aXk7Zt2Fv8Lw", |
| 307 | "status_url": "/api/v1/decks/k7m2xq9dwb/export/9Qb1t0RmS3aXk7Zt2Fv8Lw", |
| 308 | "pdf_url": "/api/v1/decks/k7m2xq9dwb/export/9Qb1t0RmS3aXk7Zt2Fv8Lw.pdf"} |
| 309 | ``` |
| 310 | |
| 311 | `202`, because nothing is ready yet: an export is a job, and what comes |
| 312 | back is where to watch it and where the file will be. The body is |
| 313 | optional; `{"notes": true}` adds the speaker notes as pages of their own |
| 314 | after each slide. |
| 315 | |
| 316 | A deck over 200 slides is a `422` before anything starts. Four exports |
| 317 | running at once for one operator is a `429` β wait for one to finish. |
| 318 | |
| 319 | ### `GET /api/v1/decks/{sqid}/export/{job}` β how is it going |
| 320 | |
| 321 | ```json |
| 322 | {"state": "running", "progress": "slide 3 of 8"} |
| 323 | ``` |
| 324 | |
| 325 | ```json |
| 326 | {"state": "done", "progress": "slide 8 of 8", "warnings": [ |
| 327 | {"kind": "asset", "slide": "hq3ktna7vc2m", |
| 328 | "detail": "image \"a1b2c3d4e5f6\" is an SVG with a stylesheet, which cannot be nested into a page; left out of the PDF"}]} |
| 329 | ``` |
| 330 | |
| 331 | `state` is `running`, `done` or `failed`, and it is the word to branch |
| 332 | on. A `failed` job carries a `message` written for a person. A `done` |
| 333 | one carries `warnings`: everything worth saying about the file β a block |
| 334 | that ran past its box, a picture that could not go in, a character no |
| 335 | embedded face can draw β each naming the slide it is about. An empty |
| 336 | list means the PDF is the deck. |
| 337 | |
| 338 | Poll it, a second or two apart. `"expired": true` on a `done` job means |
| 339 | the file is no longer there; make another. This endpoint answers `done` |
| 340 | for as long as the file does β the whole hour β so it and the `.pdf` |
| 341 | below never disagree about whether an export still exists. |
| 342 | |
| 343 | ### `GET /api/v1/decks/{sqid}/export/{job}.pdf` β take the file |
| 344 | |
| 345 | ```sh |
| 346 | curl -L -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 347 | https://slides.example/api/v1/decks/k7m2xq9dwb/export/9Qb1t0RmS3aXk7Zt2Fv8Lw.pdf \ |
| 348 | -o deck.pdf |
| 349 | ``` |
| 350 | |
| 351 | The bytes, as `application/pdf` β or a `302` to a presigned URL when the |
| 352 | instance has an object store, which is why the `-L` is there. |
| 353 | |
| 354 | **The file lives for an hour.** With no bucket bound it is held in the |
| 355 | instance's memory, which is also why it is capped: an export bigger than |
| 356 | the instance will hold fails with a message saying so. |
| 357 | |
| 358 | An export belongs to the operator, not to the agent that started it β so |
| 359 | a person can watch it from the screen and any of that person's agents can |
| 360 | fetch it. Another operator's job is a `404`, exactly as another |
| 361 | operator's deck is. |
| 362 | |
| 363 | ### `POST /api/v1/decks/{sqid}/present` β start a talk |
| 364 | |
| 365 | ```sh |
| 366 | curl -X POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 367 | https://slides.example/api/v1/decks/k7m2xq9dwb/present |
| 368 | ``` |
| 369 | |
| 370 | ```json |
| 371 | {"session": "p4wq7nzk2h", "code": "K7MQ2X", |
| 372 | "present_url": "https://slides.example/p/p4wq7nzk2h", |
| 373 | "notes_url": "https://slides.example/p/p4wq7nzk2h/notes?t=...", |
| 374 | "remote_url": "https://slides.example/r/K7MQ2X?t=..."} |
| 375 | ``` |
| 376 | |
| 377 | Call it again on the same deck and you get the same session back, so a |
| 378 | projector already showing `present_url` keeps showing the same talk. |
| 379 | What you do get fresh each time is the remote token, which means the |
| 380 | previous `notes_url` and `remote_url` stop working. This endpoint is the |
| 381 | only way into a talk that mints a token on every call. Pressing Present |
| 382 | in a browser, or reopening the presenter window, mints nothing; a phone |
| 383 | is paired only when the presenter asks for it (`POST /p/{session}/pair`). |
| 384 | |
| 385 | Treat the three URLs differently. `present_url` is safe to put on a |
| 386 | screen in front of a room β it only watches. `notes_url` and |
| 387 | `remote_url` carry the token that *drives* the deck, so they are |
| 388 | secrets: send them to the presenter, not to the audience. |
| 389 | |
| 390 | `present_url` is a *projector* address, though, and not an audience |
| 391 | one. It lives as long as the talk and no revocation reaches it, so |
| 392 | sending it to a room is sending something you cannot take back. For an |
| 393 | audience, mint a share link and let them follow: `/s/{token}?follow=1` |
| 394 | shows the presenter's own slide behind a capability that can be |
| 395 | revoked, and everything that page then reads β its slide fragments, its |
| 396 | stream at `/s/{token}/stream`, its pictures β resolves the token again |
| 397 | on every request. Revoke the link mid-talk and it stops, immediately. |
| 398 | |
| 399 | A command against a session is logged with one of two actors, whichever |
| 400 | let it in: |
| 401 | |
| 402 | - `remote:{session}`, for a command that carried the remote token. The |
| 403 | token is transferable by design β that is the feature β so the server |
| 404 | cannot say who is holding it, and Β§6.2's "every write names its real |
| 405 | actor" is kept by naming the capability and logging the issuer beside |
| 406 | it. |
| 407 | - The presenter's own actor (`person:{id}`), for a command sent with no |
| 408 | token from the presenter's signed-in browser: the presenter window, |
| 409 | the slide window it opens, or a talk rejoined by pressing Present. |
| 410 | The session cookie names a person, so the log does too. That cookie |
| 411 | is checked as on every signed-in page, so an address taken off the |
| 412 | allowlist drives nothing. |
| 413 | |
| 414 | This JSON is the only place the pairing block exists for a session an |
| 415 | agent started. When a person presses Present in a browser, they pair a |
| 416 | phone themselves, from the presenter window's menu (`POST /p/{session}/pair`), |
| 417 | and that page shows them the code and a QR to scan; that is theirs, and |
| 418 | it replaces the phone's earlier token. For your session the credentials |
| 419 | are the ones you were given, so `notes_url` renders the talk and the |
| 420 | controls, and no code and no QR. Pass on what you were given: the |
| 421 | `code` for somebody to type into `/r/`, or `remote_url` outright. It is |
| 422 | not recoverable afterwards, and calling this endpoint again mints a |
| 423 | fresh token, which retires the URLs you are holding. |
| 424 | |
| 425 | The talk is the deck minus its parked slides. Parked slides (`talk: |
| 426 | "parked"`) are in the document and in everything you read here, but they |
| 427 | are never shown to a share link, a follower or the presenting screens; |
| 428 | slides marked `full` show only in the full version of the talk. |
| 429 | |
| 430 | --- |
| 431 | |
| 432 | ## The operations |
| 433 | |
| 434 | Every operation is an object with an `op` key. Ids are twelve lowercase |
| 435 | base32 characters and are minted by the server when you omit them. The |
| 436 | vocabularies: |
| 437 | |
| 438 | - **layout**: `flow`, `canvas` |
| 439 | - **template** (flow slides): `title`, `title-body`, `two-column`, |
| 440 | `section`, `image-full`, `quote`, `blank` |
| 441 | - **region** (blocks on a flow slide): `heading`, `body`, `aside`, `media` |
| 442 | - **block type**: `heading`, `text`, `list`, `quote`, `image`, |
| 443 | `columns`, `code`, `shape`, `table`, `divider`, `spacer`, `scene`, |
| 444 | `clip`, `qr` |
| 445 | - **background kind**: `theme`, `color`, `image` |
| 446 | - **transition**: `none`, `fade` β **slide phone**: `inherit`, `reflow` |
| 447 | - **size**: `s`, `m`, `l` |
| 448 | - **items** (lists): `together`, `each` β **talk**: `full`, `parked` β |
| 449 | **arrive**: `appear`, `fade`, `rise` |
| 450 | - **play** (clips): `press`, `loop`, `once` |
| 451 | |
| 452 | `after` says where something goes: absent appends, `null` puts it |
| 453 | first, an id puts it after that one. A `box` is `{x, y, w, h}` as |
| 454 | fractions of the 16:9 stage. Text arrives as Markdown and is converted |
| 455 | server-side. A block's `step` and `items`, a slide's `talk` and the |
| 456 | deck's `arrive` appear in the deck's JSON only when they are set. |
| 457 | |
| 458 | A `qr` block is a follow-along code. Its `props.url` must have the |
| 459 | shape of a follow address, `https://<host>/s/<token>?follow=1`, and |
| 460 | anything else is refused. The shape is all the API checks. A code is |
| 461 | drawn only when the address is this instance's own and its token is a |
| 462 | live share link of the same deck; otherwise readers see nothing and the |
| 463 | editor shows an empty frame. Revoking the link turns the code off. |
| 464 | People who open the deck through a share link see a code for their own |
| 465 | link, never the one stored. The API can't mint a share link: the deck's |
| 466 | owner makes one from the editor (`POST /d/{sqid}/qr-link`), and the |
| 467 | share page lists it as Audience. The `url` holds that link's token, so |
| 468 | anyone who can read the deck through the API can read the token. |
| 469 | |
| 470 | Each example below is one batch, so you can paste any of them straight |
| 471 | into the `ops` body above. `$D` is the deck sqid, `$S` a slide id, |
| 472 | `$B` a block id and `$C` a scene id. |
| 473 | |
| 474 | ### Deck |
| 475 | |
| 476 | **`set_meta`** β the deck's title, theme, accent and font pair, and |
| 477 | `arrive`: how a block waiting for its press comes in (`appear` when |
| 478 | unset). Send `null` for `accent`, `fonts` or `arrive` to clear one. |
| 479 | |
| 480 | The document also carries `meta.fontFiles`: the fonts uploaded to the |
| 481 | deck, as a list of `{family, css, faces}`. `css` is the name the deck |
| 482 | styles it by, and each face gives its file's `ref`, `format` (`ttf`, |
| 483 | `otf`, `woff` or `woff2`), `weight` as `[min, max]`, and `italic` and |
| 484 | `pictures` flags. It is left out of the document when the deck has none. |
| 485 | A `set_meta` can set `fontFiles` or clear it with `null`, but the API |
| 486 | can't upload font bytes, and the server serves a font only through a deck |
| 487 | that recorded it from its owner's library (`GET /d/{sqid}/fonts/{ref}`, |
| 488 | and the same under `/s/{token}` and `/p/{session}`; a ref the deck |
| 489 | doesn't list is a 404). A `ref` you write by hand loads nothing until |
| 490 | then. A list that doesn't check out (more than 32 |
| 491 | families or 16 faces to a family, a `css` that doesn't start with a |
| 492 | letter or digit or holds anything but letters, digits, spaces, `.`, `_` |
| 493 | and `-`, a `css` used twice in any case, a `css` that is a catalog |
| 494 | family's or a CSS generic family's name, a bad `ref`, `format` or |
| 495 | `weight`) is refused like any other bad op. |
| 496 | |
| 497 | ```sh |
| 498 | curl -X POST -H "Authorization: Bearer $SLIDES_TOKEN" -H "Content-Type: application/json" \ |
| 499 | -d '{"ops":[{"op":"set_meta","title":"Q3 review","theme":"ink","accent":"#c0392b", |
| 500 | "fonts":{"heading":"Inter","body":"Inter"}}]}' \ |
| 501 | https://slides.example/api/v1/decks/$D/ops |
| 502 | ``` |
| 503 | |
| 504 | ### Slides |
| 505 | |
| 506 | **`add_slide`** β a new slide. `id` optional (minted and returned). |
| 507 | |
| 508 | ```sh |
| 509 | -d '{"ops":[{"op":"add_slide","layout":"flow","template":"title-body","after":null}]}' |
| 510 | ``` |
| 511 | |
| 512 | **`remove_slide`** β delete one, and everything on it. |
| 513 | |
| 514 | ```sh |
| 515 | -d '{"ops":[{"op":"remove_slide","id":"'"$S"'"}]}' |
| 516 | ``` |
| 517 | |
| 518 | **`move_slide`** β reorder. `"after": null` moves it to the front. The |
| 519 | view's `slides` come back in the new order; under the hood the slide |
| 520 | keeps its identity and gets an `order` written on it, exactly as |
| 521 | `move_block` does, so somebody typing on that slide at the same moment |
| 522 | loses nothing (spec Β§2.1, Β§2.2). |
| 523 | |
| 524 | ```sh |
| 525 | -d '{"ops":[{"op":"move_slide","id":"'"$S"'","after":null}]}' |
| 526 | ``` |
| 527 | |
| 528 | **`duplicate_slide`** β copy a slide and everything on it. `new_id` and |
| 529 | `new_block_ids` are both optional; leave them out and the server mints |
| 530 | as many block ids as the slide has. |
| 531 | |
| 532 | ```sh |
| 533 | -d '{"ops":[{"op":"duplicate_slide","id":"'"$S"'"}]}' |
| 534 | ``` |
| 535 | |
| 536 | **`set_slide`** β a slide's own settings. `talk` is `full` when only the |
| 537 | full version of the talk shows the slide, and `parked` when the talk |
| 538 | leaves it out; `null` puts it back in the talk. |
| 539 | |
| 540 | ```sh |
| 541 | -d '{"ops":[{"op":"set_slide","id":"'"$S"'","layout":"flow","template":"quote", |
| 542 | "background":{"kind":"color","value":"#101418"}, |
| 543 | "phone":"reflow","transition":"fade","talk":"full"}]}' |
| 544 | ``` |
| 545 | |
| 546 | **`set_notes`** β the speaker notes, as Markdown. |
| 547 | |
| 548 | ```sh |
| 549 | -d '{"ops":[{"op":"set_notes","id":"'"$S"'","markdown":"Pause here. Ask about hiring."}]}' |
| 550 | ``` |
| 551 | |
| 552 | ### Blocks |
| 553 | |
| 554 | **`add_block`** β put something on a slide. `id` optional. On a flow |
| 555 | slide give a `region`; on a canvas slide give a `box` and optionally |
| 556 | `z`. |
| 557 | |
| 558 | ```sh |
| 559 | -d '{"ops":[{"op":"add_block","slide":"'"$S"'","type":"heading", |
| 560 | "region":"heading","props":{"level":1},"markdown":"Revenue"}]}' |
| 561 | ``` |
| 562 | |
| 563 | ```sh |
| 564 | -d '{"ops":[{"op":"add_block","slide":"'"$S"'","type":"image", |
| 565 | "box":{"x":0.1,"y":0.2,"w":0.5,"h":0.4},"z":2, |
| 566 | "props":{"asset":"a1"}}]}' |
| 567 | ``` |
| 568 | |
| 569 | **`remove_block`** β take one off. |
| 570 | |
| 571 | ```sh |
| 572 | -d '{"ops":[{"op":"remove_block","slide":"'"$S"'","id":"'"$B"'"}]}' |
| 573 | ``` |
| 574 | |
| 575 | **`move_block`** β reorder within its slide. The view's `blocks` come |
| 576 | back in the new order; under the hood the block keeps its identity and |
| 577 | gets an `order` written on it, so somebody typing into it at the same |
| 578 | moment loses nothing (spec Β§2.2). |
| 579 | |
| 580 | ```sh |
| 581 | -d '{"ops":[{"op":"move_block","slide":"'"$S"'","id":"'"$B"'","after":null}]}' |
| 582 | ``` |
| 583 | |
| 584 | A `columns` block's `props.children` names blocks on the same slide, |
| 585 | each at most once and each in at most one `children` list on the slide, |
| 586 | and never a block the columns block already sits under (spec Β§2.4). An |
| 587 | op that would share a child or close a cycle is refused with a message |
| 588 | saying which id. |
| 589 | |
| 590 | **`set_block`** β its props, region, box, z, step or items. `step` is |
| 591 | the press the block arrives on, a number above 0: blocks with the same |
| 592 | step arrive together, and 1.5 comes between 1 and 2. A block with no |
| 593 | step is there when the slide is. `items`, on a list only, is `each` to |
| 594 | give every item its own press. `null` for `region`, `box`, `step` or |
| 595 | `items` clears that one. |
| 596 | |
| 597 | ```sh |
| 598 | -d '{"ops":[{"op":"set_block","slide":"'"$S"'","id":"'"$B"'", |
| 599 | "props":{"level":2},"region":"body","box":null,"z":1,"step":2}]}' |
| 600 | ``` |
| 601 | |
| 602 | A `scene` block shows one of the deck's scenes: `props` is `{scene, |
| 603 | from, to}`, a scene id and two of its state ids, `from` not after `to`. |
| 604 | It arrives with the slide showing `from`, and each press then moves it |
| 605 | one state towards `to`, the way an `each` list gives each item a press. |
| 606 | Its `step` says which press starts that (no step: the first). A block |
| 607 | naming a scene or state that is later removed stays as it is and takes |
| 608 | no presses; an op that points one at a scene or state the deck does not |
| 609 | have is refused. |
| 610 | |
| 611 | A `clip` block plays a video asset: `props` is `{asset, play}`, `play` |
| 612 | being `press` (one press plays it, the first when it has no step), |
| 613 | `loop` or `once` (from when it arrives, taking no press of its own). |
| 614 | |
| 615 | ```sh |
| 616 | -d '{"ops":[{"op":"add_block","slide":"'"$S"'","type":"scene", |
| 617 | "props":{"scene":"'"$C"'","from":"field","to":"city"}}]}' |
| 618 | ``` |
| 619 | |
| 620 | **`set_text`** β replace the words in a text-bearing block (`heading`, |
| 621 | `text`, `list`, `quote`, `code`, `shape`). |
| 622 | |
| 623 | ```sh |
| 624 | -d '{"ops":[{"op":"set_text","slide":"'"$S"'","id":"'"$B"'", |
| 625 | "markdown":"- Up 14%\n- Two new regions"}]}' |
| 626 | ``` |
| 627 | |
| 628 | **`set_phone`** β a block's phone layer: additions to the desktop |
| 629 | layout, never a replacement for it. |
| 630 | |
| 631 | ```sh |
| 632 | -d '{"ops":[{"op":"set_phone","slide":"'"$S"'","id":"'"$B"'", |
| 633 | "phone":{"hidden":false,"order":0,"size":"l"}}]}' |
| 634 | ``` |
| 635 | |
| 636 | ### Assets |
| 637 | |
| 638 | **`register_asset`** β name an image the deck can use. An agent does |
| 639 | not need it: `POST /api/v1/decks/{sqid}/assets` uploads the picture and |
| 640 | applies this for you. The editor's upload applies it itself (see |
| 641 | "Getting the bytes there" below). `ref` is the object store's address for those bytes β a hex |
| 642 | SHA-256, because the store is content-addressed. |
| 643 | |
| 644 | ```sh |
| 645 | -d '{"ops":[{"op":"register_asset","id":"a1", |
| 646 | "ref":"9f2c1e...ab","name":"roadmap.png","width":1600,"height":900, |
| 647 | "alt":"Three phases, each with a date"}]}' |
| 648 | ``` |
| 649 | |
| 650 | A clip's video is an asset too, registered with two more fields: |
| 651 | `poster`, the `ref` of the picture of its first frame (registered as an |
| 652 | asset of its own, a PNG or WebP of at most 4 MiB), and `duration`, its |
| 653 | length in whole milliseconds. Both are omitted for a picture, and |
| 654 | `duration` is omitted when the length is unknown (0, or a file that |
| 655 | does not say); the deck's JSON shows each only when it is set. A `clip` |
| 656 | block names the video's id; every surface that doesn't play it |
| 657 | (scripts off, a thumbnail, the PDF, the presenter's Next, the remote) |
| 658 | draws its poster, described as an image is: the block's `alt`, nothing |
| 659 | when it is `decorative`, else the video's `alt`. |
| 660 | |
| 661 | ```sh |
| 662 | -d '{"ops":[{"op":"register_asset","id":"p1","ref":"5e1a...c0","name":"demo.webp", |
| 663 | "width":1280,"height":720,"alt":""}, |
| 664 | {"op":"register_asset","id":"v1","ref":"77b0...9d","name":"demo.webm", |
| 665 | "width":1280,"height":720,"alt":"Opening a deck","poster":"5e1a...c0", |
| 666 | "duration":4250}]}' |
| 667 | ``` |
| 668 | |
| 669 | **`remove_asset`** β drop the registration. The bytes stay in the store, |
| 670 | which is content-addressed and shared. A scene's still is drawn through |
| 671 | the asset its `ref` is registered under, so removing that asset leaves |
| 672 | the state with no picture; the editor never offers one as unused. |
| 673 | |
| 674 | ```sh |
| 675 | -d '{"ops":[{"op":"remove_asset","id":"a1"}]}' |
| 676 | ``` |
| 677 | |
| 678 | ### Scenes |
| 679 | |
| 680 | A scene is code that draws a set of named states; slides show it |
| 681 | through `scene` blocks. [scenes.md](scenes.md) says what a scene's code |
| 682 | must do, starting from a worked example, |
| 683 | [scenes/example.html](scenes/example.html), and |
| 684 | [how to build a deck with one](scenes.md#building-a-deck-with-a-scene): |
| 685 | the bundle, the batch, the version, then a still per state. In the |
| 686 | deck's JSON each scene is: |
| 687 | |
| 688 | ```json |
| 689 | "scenes": {"k7m2xqrdwbcd": {"name": "The world", "author": "agent:7", |
| 690 | "code": "<64 hex digits>", |
| 691 | "states": [{"id": "field", "name": "Field", "description": "An empty field"}], |
| 692 | "words": {"title": "Vienna"}, "data": {"pieces": []}, |
| 693 | "stills": {"field": {"ref": "<64 hex digits>", "made": "<64 hex digits>"}}}} |
| 694 | ``` |
| 695 | |
| 696 | A scene's id is twelve lowercase base32 characters, like a slide's. |
| 697 | `code` is the ref of the scene's stored bundle. `states` are in order, |
| 698 | one at least, each `id` used once; `description` is what a screen |
| 699 | reader says for that state. `words` are the scene's labels and `data` |
| 700 | its model, any JSON value up to 960 KiB written compactly. A batch that |
| 701 | adds or changes a scene must also make an update of 1 MiB at most, what |
| 702 | one live-sync update may carry, so that an editor can always save the |
| 703 | scene again; the batch is refused with a `422` otherwise. Number-heavy |
| 704 | data encodes larger than its JSON: each number takes up to nine bytes |
| 705 | in the update, so a list of 150,000 numbers like `0.1` (600 KB of JSON) |
| 706 | is about 1.35 MB and refused, and about 116,000 of them is the most that |
| 707 | fits. `__proto__` may not |
| 708 | be a state id, a word's key or a key anywhere in `data` (a browser's |
| 709 | Yjs decoder would lose it); as text it is fine. `stills` holds |
| 710 | a picture per state, and `made` is the scene's version when it was |
| 711 | drawn. |
| 712 | |
| 713 | A scene's **version** is not stored. It is the SHA-256, in lowercase |
| 714 | hex, of the UTF-8 JSON text of `{"code": β¦, "data": β¦, "words": β¦}` |
| 715 | written with no white space, every object's keys sorted by code point |
| 716 | at every level, and numbers and strings as `JSON.stringify` writes them |
| 717 | (absent data is `null`, absent words `{}`). It changes when the code, |
| 718 | the data or the words do, and never otherwise. |
| 719 | |
| 720 | `author` is whoever last changed the code β you, for an agent's op. The |
| 721 | server sets it; an `author` in an op is ignored. |
| 722 | |
| 723 | **`add_scene`** β `id` optional; `name`, `code` and `states` required; |
| 724 | `words` and `data` optional. |
| 725 | |
| 726 | ```sh |
| 727 | -d '{"ops":[{"op":"add_scene","name":"The world","code":"9f2c1e...ab", |
| 728 | "states":[{"id":"field","name":"Field","description":"An empty field"}, |
| 729 | {"id":"city","name":"City","description":"A city"}], |
| 730 | "words":{"title":"Vienna"},"data":{"pieces":[]}}]}' |
| 731 | ``` |
| 732 | |
| 733 | **`set_scene`** β change any of `name`, `code`, `states`, `words`, |
| 734 | `data` and `stills`. `words` and `stills` change key by key, `null` |
| 735 | removing one; `data` is replaced whole. Removing a state leaves the |
| 736 | blocks that name it as they are. |
| 737 | |
| 738 | ```sh |
| 739 | -d '{"ops":[{"op":"set_scene","id":"'"$C"'","words":{"title":"Wien","old":null}, |
| 740 | "stills":{"field":{"ref":"9f2c1e...ab","made":"<version>"}}}]}' |
| 741 | ``` |
| 742 | |
| 743 | **`remove_scene`** β take it out of the deck. Blocks showing it stay. |
| 744 | |
| 745 | ```sh |
| 746 | -d '{"ops":[{"op":"remove_scene","id":"'"$C"'"}]}' |
| 747 | ``` |
| 748 | |
| 749 | ### Stills and code from an agent |
| 750 | |
| 751 | These three take the file as the request body, not JSON, and the same |
| 752 | bearer as the rest. Each registers the file for the deck and applies the |
| 753 | matching op as you, so editors with the deck open see it at once. Without |
| 754 | an object store, each answers `503 no_store`. |
| 755 | |
| 756 | **`POST /api/v1/decks/{sqid}/scene-bundles`** β a scene's first bundle, |
| 757 | before the scene exists. The body is one HTML document, 2 MiB at most, |
| 758 | opening with `<!doctype html>` or `<html>`. Answers `{"ref": "β¦"}`, which |
| 759 | an `add_scene` then names as its `code`. |
| 760 | |
| 761 | **`PUT /api/v1/decks/{sqid}/scenes/{id}/code`** β new code for a scene. |
| 762 | Same body and same checks, then `set_scene` with the ref (the server sets |
| 763 | `author`). Answers `{"ref": "β¦", "version": "β¦"}`, the scene's version |
| 764 | now. Stills made before it are out of date. |
| 765 | |
| 766 | **`PUT /api/v1/decks/{sqid}/scenes/{id}/stills/{state}?made=<version>`** β |
| 767 | a state's still. The body is a PNG or a WebP, 4 MiB at most, that decodes |
| 768 | and is no more than 30000 pixels either way and 50 megapixels in all. |
| 769 | `made` must be the scene's current version, which you work out as |
| 770 | above, or the answer is `409 stale` and nothing changes. On success the picture is registered as |
| 771 | an asset of the deck and set on the scene with `set_scene`, and the answer |
| 772 | is `{"ref": "β¦", "made": "β¦"}`. |
| 773 | |
| 774 | ```sh |
| 775 | curl -X PUT -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 776 | --data-binary @city.png \ |
| 777 | "https://slides.example/api/v1/decks/k7m2xq9dwb/scenes/$C/stills/city?made=$VERSION" |
| 778 | ``` |
| 779 | |
| 780 | Refusals are `{"error": "β¦", "message": "β¦"}`: `not_found` (no such |
| 781 | deck, scene or state, or not yours; 404), `stale` (409), `too_large` |
| 782 | (413), `not_an_image` and `not_html` (422). |
| 783 | |
| 784 | The editor tells a scene's stills are out of date the same way: a state |
| 785 | with no still is missing, and so is one whose `ref` no asset of the deck |
| 786 | is registered under any more; one whose `made` is not the scene's version |
| 787 | is stale. |
| 788 | |
| 789 | --- |
| 790 | |
| 791 | ## Getting the bytes there |
| 792 | |
| 793 | This section is the editor's upload: three endpoints on the |
| 794 | *signed-in* surface, which take a session cookie rather than a bearer |
| 795 | token. **An agent adds a picture with |
| 796 | `POST /api/v1/decks/{sqid}/assets`** (above) and needs none of this. |
| 797 | |
| 798 | A ref named in a `register_asset` op is held by the document, but no |
| 799 | surface serves bytes until the server has read and checked them itself: |
| 800 | serving requires a verification row, written only by the registration |
| 801 | endpoint below or by the agent's upload. Naming an address is not a |
| 802 | way to publish one. |
| 803 | |
| 804 | Limits, on all three: 20 MiB per image, and PNG, JPEG, WebP or SVG. |
| 805 | |
| 806 | A scene's code goes up the same way: sign it as `text/html` (2 MiB at |
| 807 | most), and registration answers `{"kind": "scene", "ref": "β¦"}` for the |
| 808 | scene's `code`. [scenes.md](scenes.md) says what a bundle must be. |
| 809 | |
| 810 | ### `POST /d/{sqid}/uploads` β where do these bytes go |
| 811 | |
| 812 | ```json |
| 813 | {"name": "roadmap.png", "size": 184320, "type": "image/png", "hash": "9f2c1e...ab"} |
| 814 | ``` |
| 815 | |
| 816 | `hash` is the file's SHA-256, computed by the client. Nothing is |
| 817 | addressed by it. It is recorded, and on the development path β where |
| 818 | this app receives the PUT and hashes the bytes anyway β a disagreement |
| 819 | is reported as `hash_mismatch`; on a real bucket it is not consulted at |
| 820 | all. The address the bytes go to is the app's own, always. |
| 821 | |
| 822 | The answer is where to PUT and what header to send: |
| 823 | |
| 824 | ```json |
| 825 | {"ref": "4d0a77...e1", |
| 826 | "url": "https://bucket.example/4d0a77...e1?X-Amz-Signature=...", |
| 827 | "headers": {"Content-Type": "image/png"}} |
| 828 | ``` |
| 829 | |
| 830 | **That `ref` is a staging address, not the address the picture will be |
| 831 | served from.** It is minted here, once, for this deck and this |
| 832 | principal, and it is the only address this app will ever sign a PUT |
| 833 | for. Two things follow, and both are the point: |
| 834 | |
| 835 | - A caller cannot ask for a PUT to an address something is already |
| 836 | served from, in this deck or any other. A presigned PUT is |
| 837 | unconditional, so an address a browser can name is an address a |
| 838 | browser can overwrite β which is how, before this, replacement bytes |
| 839 | could change a registered picture with no document update anywhere. |
| 840 | - Registration will only look at bytes staged this way. Knowing a ref |
| 841 | is not a way to get it registered; see the next endpoint. |
| 842 | |
| 843 | Sign twice for the same file and you get two staging addresses. Ask for |
| 844 | one and never use it and nothing happens: a staged upload nobody |
| 845 | registered within two hours stops being registrable. |
| 846 | |
| 847 | With no object store bound it answers `503` and |
| 848 | `{"error": "no_store", "message": "β¦"}` instead. That is the honest |
| 849 | answer, not a fallback β there is nowhere for the bytes to go. |
| 850 | |
| 851 | In development the bound store is a directory (`blobs.Dir`), which has |
| 852 | nothing to presign, so `url` comes back as a same-origin |
| 853 | `/d/{sqid}/uploads/{ref}` and this app receives the PUT itself. That |
| 854 | path resolves the same receipt before it reads a byte, so it is not a |
| 855 | way round the staging rule either. On a real bucket it answers `404`: |
| 856 | 20 MiB does not go through an app process that has one small instance's |
| 857 | memory. |
| 858 | |
| 859 | ### `POST /d/{sqid}/assets` β what actually landed |
| 860 | |
| 861 | ```json |
| 862 | {"ref": "4d0a77...e1", "name": "roadmap.png", "width": 1600, "height": 900, |
| 863 | "alt": "Three phases, each with a date", "decorative": false} |
| 864 | ``` |
| 865 | |
| 866 | `ref` here is the **staging address** the sign endpoint answered with, |
| 867 | and nothing else is accepted. This endpoint resolves it to the upload |
| 868 | receipt this app wrote when it signed the PUT: same deck, same |
| 869 | principal, not already registered, not older than two hours. Anything |
| 870 | else β a ref from another deck, a ref you happen to know, a receipt |
| 871 | somebody else staged, a receipt already spent β is `404` |
| 872 | `not_found`, the same answer an address holding nothing gets. |
| 873 | |
| 874 | That matters more than it looks. A ref is a content address, so knowing |
| 875 | one is knowing the SHA-256 of somebody's file, and this endpoint writes |
| 876 | the verification row that `GET /d/{sqid}/assets/{ref}` requires. If a |
| 877 | ref alone were enough, knowing one would be permission to read it. |
| 878 | |
| 879 | The server then reads the staged object, sniffs the bytes (a file that |
| 880 | *says* PNG and is not one is refused here, which is the only place the |
| 881 | bytes are ever looked at), sanitises an SVG β scripts, event handlers |
| 882 | and foreign HTML stripped; anything still pointing outside the document |
| 883 | refused β and **puts what it read back as a final object addressed by |
| 884 | its own SHA-256**. That final address is what the deck refers to, and |
| 885 | no browser has ever been handed a PUT for it. Alternative text is |
| 886 | required unless `decorative` is true (Β§2.4). |
| 887 | |
| 888 | It answers `200` with the record to register: |
| 889 | |
| 890 | ```json |
| 891 | {"id": "a1b2c3d4e5f6", "ref": "9f2c1e...ab", "name": "roadmap.png", |
| 892 | "width": 1600, "height": 900, "alt": "Three phases, each with a date"} |
| 893 | ``` |
| 894 | |
| 895 | **The `ref` that comes back is never the one that went in.** The one |
| 896 | that went in was a staging address; this one is the hash of the bytes |
| 897 | the server read, which for a sanitised SVG is not even the hash of what |
| 898 | was uploaded. Register what came back. |
| 899 | |
| 900 | It does not write the document. The client applies `register_asset` |
| 901 | with this record itself, so an upload reaches the deck through the same |
| 902 | op path, the same update log and the same undo step as every other |
| 903 | change. |
| 904 | |
| 905 | Refusals are `{"error": "...", "message": "..."}` β `no_store`, |
| 906 | `too_large`, `not_an_image`, `unsafe_svg`, `alt_required`, `invalid`, |
| 907 | `not_found`. (`unsupported_type` and `already_verified` are the sign |
| 908 | endpoint's own and `hash_mismatch` is the development PUT's; |
| 909 | `unsupported_type` is a *declared* type outside the four, where here |
| 910 | the bytes are what is judged and a file of the wrong kind is |
| 911 | `not_an_image`.) The `error` word is fixed |
| 912 | English for a program to branch on; the `message` is for a person and |
| 913 | follows `Accept-Language`. |
| 914 | |
| 915 | Registering also records that the ref was verified for this deck, and |
| 916 | `GET /d/{sqid}/assets/{ref}` requires that record as well as the deck's |
| 917 | own `assets` map: a `register_asset` op naming a ref that never went |
| 918 | through this endpoint is accepted by the document and the picture is |
| 919 | never served. |
| 920 | |
| 921 | ### Clips: a video and its poster |
| 922 | |
| 923 | A clip's video goes up the same way, signed as `video/mp4` or |
| 924 | `video/webm`, up to 50 MiB. Registration reads the bytes and takes an |
| 925 | MP4 (an `ftyp` box first, not a still picture's brand) or a WebM (an |
| 926 | EBML header whose DocType is `webm`), and nothing else: `not_a_video`. |
| 927 | It also wants the video's poster, a PNG or WebP picture already |
| 928 | registered for this deck, named by its `ref`, and the video's length: |
| 929 | |
| 930 | ```json |
| 931 | {"ref": "<staging address>", "name": "demo.webm", "width": 1280, "height": 720, |
| 932 | "alt": "Opening a deck", "poster": "5e1a...c0", "duration": 4250} |
| 933 | ``` |
| 934 | |
| 935 | A poster that is missing, unknown to this deck, or not a PNG or WebP is |
| 936 | `poster_required`; one over 4 MiB is `poster_too_large`. The record that comes back has `poster` and |
| 937 | `duration`; register it with `register_asset` beside the poster's own |
| 938 | record. A clip's refusals are a code and a developer's sentence |
| 939 | (`too_large`, `not_a_video`, `poster_required`, `poster_too_large`, `not_found`, |
| 940 | `hash_mismatch`, `internal`); the editor words them itself. |
| 941 | |
| 942 | The editor draws the poster from the video's first frame in your |
| 943 | browser. While a video is staged, `GET /d/{sqid}/uploads/{ref}` gives |
| 944 | its bytes back to whoever staged it, and only to them, until it is |
| 945 | registered; the page loads media from this origin alone, so this is how |
| 946 | the browser reads the file it picked. |
| 947 | |
| 948 | ### `GET /d/{sqid}/assets/{ref}` β the bytes back |
| 949 | |
| 950 | A `302` to a presigned GET (one hour), or the file itself where the |
| 951 | store cannot presign. Two more routes serve the same bytes to the |
| 952 | surfaces that have no session: `/s/{token}/assets/{ref}` for a share |
| 953 | link and `/p/{session}/assets/{ref}` while presenting. The renderer |
| 954 | writes whichever base belongs to the page it is drawing. |
| 955 | |
| 956 | A clip's video comes back with its own type and in ranges |
| 957 | (`Accept-Ranges: bytes`, `206` for a `Range`), so a browser can seek. |
| 958 | |
| 959 | Every one of them checks the ref against **that deck's** `assets` map |
| 960 | before serving a byte. A ref is a content address, so knowing one is |
| 961 | knowing the SHA-256 of somebody's file; without that check any |
| 962 | capability for any deck would fetch any object in the bucket. |
| 963 | |
| 964 | ### For the operator: CORS on the bucket |
| 965 | |
| 966 | The presigned PUT is made by the browser, cross-origin, straight to the |
| 967 | object store. That only works if the bucket allows it, and nothing in |
| 968 | this app can arrange it for you. Configure the store's CORS policy to |
| 969 | allow `PUT` from this instance's origin, with the `Content-Type` header, |
| 970 | and expose `ETag`. Without it uploads fail in the browser with no useful |
| 971 | error β the request never reaches this app, so there is nothing here to |
| 972 | log. |
| 973 | |
| 974 | Development needs none of this: `blobs.Dir` has no presigning, so the |
| 975 | PUT is same-origin. |
| 976 | |
| 977 | --- |
| 978 | |
| 979 | ## The live-sync wire |
| 980 | |
| 981 | Four more routes on the signed-in surface, which is what the browser |
| 982 | editor is built on. You do not need them β `/api/v1/decks/{sqid}/ops` |
| 983 | is the supported way for a program to write, and polling the deck with |
| 984 | `If-None-Match` is the supported way to watch. They are documented |
| 985 | because they are how the same deck is edited by a person while your |
| 986 | agent is holding it, and because the framing is easy to get subtly |
| 987 | wrong if you ever do speak it. They take a session cookie, not a bearer, |
| 988 | and the two POSTs among them sit behind the same origin check every |
| 989 | other screen does β see "A note on CSRF" at the foot of this file. |
| 990 | |
| 991 | The document underneath is a Yjs document. `POST /ops` is a batch of |
| 992 | operations the server turns into one Yjs update; these routes carry |
| 993 | Yjs updates directly. Both end up as rows in the same log, in one |
| 994 | order, each stamped with the actor that wrote it. |
| 995 | |
| 996 | ### `GET /d/{sqid}/updates?since=N` β the bytes after seq N |
| 997 | |
| 998 | `application/octet-stream`. Every update after seq `N`, in seq order, |
| 999 | each one framed as a **4-byte big-endian length followed by that many |
| 1000 | bytes**. There is no other structure β no header, no trailer, no count. |
| 1001 | |
| 1002 | `Slides-Seq` on the response is the highest seq in the body, or `N` |
| 1003 | itself when the body is empty. Take your cursor from that header and |
| 1004 | never from a separate query: it is derived from the bytes you were |
| 1005 | actually handed, so a cursor read from it can never be ahead of what |
| 1006 | you received. |
| 1007 | |
| 1008 | At `since=0` the answer may begin from a periodic snapshot rather than |
| 1009 | from the first update ever written, in which case `Slides-Snapshot: |
| 1010 | <seq>` says which seq that first frame brings you to. A snapshot is |
| 1011 | derived data β it is a shortcut, never the truth β so a deck opens |
| 1012 | identically with it and without it. |
| 1013 | |
| 1014 | A `since` that is missing, negative or not a number is a `400`. |
| 1015 | |
| 1016 | ### `POST /d/{sqid}/updates` β one update |
| 1017 | |
| 1018 | The body is one Yjs v1 update, 1 MiB at most. The answer is `204` with |
| 1019 | `Slides-Seq` for the row it wrote. Then it is broadcast, so every other |
| 1020 | open tab learns about it. |
| 1021 | |
| 1022 | An update that leaves a scene it added or changed in a shape the ops |
| 1023 | would refuse β an id that is not twelve lowercase base32 characters, |
| 1024 | `__proto__` as a state id, word key or data key, or more than 960 KiB |
| 1025 | of data β is refused with a `422`. |
| 1026 | |
| 1027 | When the update adds a scene or changes a scene's code, the server |
| 1028 | writes a second row straight after yours setting the scene's `author` |
| 1029 | to you, and puts back any `author` your update changed on its own. |
| 1030 | `Slides-Seq` names your row; the broadcast names the last. |
| 1031 | |
| 1032 | A `422` here means the core read your bytes and refused them, which is |
| 1033 | an ordinary answer rather than a server fault: these arrive from |
| 1034 | browsers. A `413` is the size cap. A `409` means two writers landed at |
| 1035 | once, twice β reread and decide what your update now means. |
| 1036 | |
| 1037 | ### `GET /d/{sqid}/stream` β server-sent events |
| 1038 | |
| 1039 | ``` |
| 1040 | event: update |
| 1041 | data: 41 |
| 1042 | |
| 1043 | event: presence |
| 1044 | data: [{"client":"β¦","name":"Ana","colour":"#6b4","slide":"β¦","block":"β¦"}] |
| 1045 | |
| 1046 | : ping |
| 1047 | ``` |
| 1048 | |
| 1049 | One of each on connect, a `: ping` every 15 seconds, and the connection |
| 1050 | closes after five minutes for you to reopen. |
| 1051 | |
| 1052 | **`update` carries a seq and no bytes.** It is advisory β "there is |
| 1053 | something at least this new" β and the bytes come from `GET /updates`. |
| 1054 | `presence` carries the whole set every time, never a delta, so a |
| 1055 | subscriber that falls behind is dropped and reconnects rather than |
| 1056 | having events silently skipped. |
| 1057 | |
| 1058 | ### `POST /d/{sqid}/presence` β where you are |
| 1059 | |
| 1060 | ```json |
| 1061 | {"client": "9f3cβ¦", "slide": "hq3ktna7vc2m", "block": "blkheading22"} |
| 1062 | ``` |
| 1063 | |
| 1064 | `client` identifies the tab, not the person, and is required. Post it |
| 1065 | every 20 seconds and whenever the person moves; two missed heartbeats |
| 1066 | and the server drops you from the set. |
| 1067 | |
| 1068 | The name and the colour are **stamped by the server** from your user |
| 1069 | row. Sending your own does nothing β otherwise presence would be a |
| 1070 | place to write somebody else's name onto somebody else's screen. |
| 1071 | Presence is never document state: it lives in memory, reaches no log, |
| 1072 | is in no snapshot, and is gone when the process restarts. |
| 1073 | |
| 1074 | ### One note if you write Yjs updates by hand |
| 1075 | |
| 1076 | Text is an `XmlFragment` of `<paragraph>` elements whose formatting |
| 1077 | attributes are the marks, and the marks are named after the attributes: |
| 1078 | `b`, `i`, `c`, `h`, `href`. **`href` is stored as the one-key map |
| 1079 | `{"href": "https://β¦"}`, not as a plain string** (spec Β§1 ruling 12). |
| 1080 | That shape is y-prosemirror's, and it is not cosmetic: a plain string |
| 1081 | throws inside its reader, and it deletes the text node when a read |
| 1082 | throws β so the wrong shape loses the words, not just the link. |
| 1083 | |
| 1084 | Readers on both sides are tolerant where writers are exact. `b`, `i`, |
| 1085 | `c` and `h` are written `true` and read as set on any truthy value; an |
| 1086 | `href` is read as either the map or a plain string. The deck's JSON |
| 1087 | view β what `GET /api/v1/decks/{sqid}` hands you β flattens all of that |
| 1088 | into runs with a plain `href` string, so none of this reaches you |
| 1089 | unless you are writing updates yourself. |
| 1090 | |
| 1091 | The gate on `POST /d/{sqid}/updates` checks the text you leave behind, |
| 1092 | not the view of it (spec Β§2.6): a formatting attribute outside those |
| 1093 | five, an element other than `<paragraph>` at the top of a text, or an |
| 1094 | element or fragment inside a paragraph is a `422`, and nothing is |
| 1095 | stored. The view would have read all of those; the editor would have |
| 1096 | deleted the text on binding, which is why the check is on the |
| 1097 | document. |
| 1098 | |
| 1099 | Block order is a key, not the array. A slide's `blocks` array is the |
| 1100 | set of its blocks; `order` on each block map (a number, array index |
| 1101 | when absent) is the reading order, and the view sorts by it (spec |
| 1102 | Β§2.2). Reorder by writing `order`, never by deleting and re-inserting a |
| 1103 | block map β the second loses whatever another peer typed into it in the |
| 1104 | meantime. |
| 1105 | |
| 1106 | --- |
| 1107 | |
| 1108 | ## A worked example |
| 1109 | |
| 1110 | Build a two-slide deck from nothing: |
| 1111 | |
| 1112 | ```sh |
| 1113 | export SLIDES_TOKEN=sl_... |
| 1114 | export API=https://slides.example/api/v1 |
| 1115 | |
| 1116 | D=$(curl -sX POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 1117 | -H "Content-Type: application/json" \ |
| 1118 | -d '{"title":"Q3 review","theme":"ink"}' $API/decks | jq -r .sqid) |
| 1119 | |
| 1120 | S=$(curl -sX POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 1121 | -H "Content-Type: application/json" \ |
| 1122 | -d '{"ops":[{"op":"add_slide","layout":"flow","template":"title-body"}]}' \ |
| 1123 | $API/decks/$D/ops | jq -r '.ids["0"]') |
| 1124 | |
| 1125 | curl -sX POST -H "Authorization: Bearer $SLIDES_TOKEN" \ |
| 1126 | -H "Content-Type: application/json" \ |
| 1127 | -d '{"ops":[ |
| 1128 | {"op":"add_block","slide":"'"$S"'","type":"heading","region":"heading", |
| 1129 | "props":{"level":1},"markdown":"Revenue"}, |
| 1130 | {"op":"add_block","slide":"'"$S"'","type":"list","region":"body", |
| 1131 | "markdown":"- Up 14%\n- Two new regions"}, |
| 1132 | {"op":"set_notes","id":"'"$S"'","markdown":"Pause on the second bullet."} |
| 1133 | ]}' $API/decks/$D/ops |
| 1134 | |
| 1135 | # Look at what you made. |
| 1136 | curl -s -H "Authorization: Bearer $SLIDES_TOKEN" "$API/decks/$D/slides/$S.html" |
| 1137 | ``` |
| 1138 | |
| 1139 | --- |
| 1140 | |
| 1141 | ## A note on CSRF |
| 1142 | |
| 1143 | The screens are protected by an origin check on every state-changing |
| 1144 | request (`Sec-Fetch-Site`, `Origin`, `Referer`). A program has none of |
| 1145 | those to send, and the check refuses a request that carries none of the |
| 1146 | three β so `/api/v1` is mounted outside it and gated by the bearer |
| 1147 | alone. |
| 1148 | |
| 1149 | That is not a hole. A browser never attaches an `Authorization` header |
| 1150 | by itself, so a page on some other origin cannot make a request this |
| 1151 | API will authenticate, whatever it does with forms or credentials. |
| 1152 | Cross-site request forgery is an attack on ambient credentials β a |
| 1153 | cookie the browser sends for you β and there is no ambient credential |
| 1154 | here. |
| 1155 | |