| 1 | # Base's API for its native app, v1 |
| 2 | |
| 3 | What Base's Mac and iPhone app may rely on. Everything here is pinned by |
| 4 | tests in `internal/webtest` (`native_test.go`, `api_test.go`, |
| 5 | `api_team_test.go`, `ask_native_contract_test.go`, |
| 6 | `ask_oficina_native_test.go`). The Ask routes are the same ones the web's |
| 7 | `ask.js` uses, so a change that breaks this document breaks the web too. |
| 8 | |
| 9 | ## Signing in |
| 10 | |
| 11 | - **`POST /native/oficina-id`** is connect's native exchange |
| 12 | (`connect.NativeExchange`; Home spec 2026-11-14-oficina-id-native.md §7). |
| 13 | The kit sends `{assertion, verifier}` as JSON, with no `Origin`, no |
| 14 | `Sec-Fetch-Site` and no cookie. |
| 15 | - `200 {"state":"ok","name":"__Host-rastrillo_session","value":…,"expires_at":<unix>}`: |
| 16 | the session, seven days from now, absolute. |
| 17 | - `403 {"state":"unknown"}`: no member here is linked to this Oficina ID. |
| 18 | Base admits only people who have signed in to Base on the web with |
| 19 | Oficina ID once (slice 1). |
| 20 | - `400 invalid`, `401 failed` (get a fresh assertion), `503 unavailable`, |
| 21 | as connect documents. Base never answers `409 choose`. |
| 22 | - **The session** is the cookie `name=value`. Every other request sends it |
| 23 | with `Origin: <Base's origin>`; a POST without that `Origin` is refused |
| 24 | (403, Base's CSRF check). |
| 25 | - **`POST /signout`** ends the session it carries, and nothing else: |
| 26 | `204` to a JSON request (`Content-Type` or `Accept` of |
| 27 | `application/json`), `303 /signed-out` to a form. |
| 28 | - **Refusals.** Anything under `/api/`, and any request whose `Accept` |
| 29 | names `application/json` or `text/event-stream`, hears |
| 30 | `401 {"code":"unauthenticated"}` (no-store, never a redirect) when it has |
| 31 | no session, or a session that names nobody who is a member now: unlinked, |
| 32 | removed, or a native session more than seven days old. Mint a new session |
| 33 | and try once more. |
| 34 | |
| 35 | ## Reads |
| 36 | |
| 37 | ### `GET /api/v1/me` |
| 38 | |
| 39 | ```json |
| 40 | { |
| 41 | "member": {"id": "…", "name": "Ana Ruiz", "email": "ana@acme.test", "initials": "AR", "owner": false}, |
| 42 | "base": {"name": "Acme", "slug": "acme", "origin": "https://base.acme.example", "timezone": "Europe/Dublin"}, |
| 43 | "appearance": "system", |
| 44 | "equipo_origin": "https://equipo.acme.example" |
| 45 | } |
| 46 | ``` |
| 47 | |
| 48 | - `member.name` is the member's name, or their address's local part, |
| 49 | capitalised. `member.id` is Base's member id, never the address. |
| 50 | - `base.timezone` is an IANA name. |
| 51 | - `appearance` is `system`, `light` or `dark`. Change it with the web's |
| 52 | `POST /settings/appearance`, form field `theme` (`system`, `light` or |
| 53 | `dark`), which answers `303 /settings`. |
| 54 | - `equipo_origin` is `null` when Ask Base is off. The app asks Oficina ID |
| 55 | for an assertion addressed to it (Ask set-up, below). |
| 56 | |
| 57 | ### `GET /api/v1/home` |
| 58 | |
| 59 | ```json |
| 60 | { |
| 61 | "greeting": "Good morning, Ana.", |
| 62 | "lede": "One step until Acme's Base is ready.", |
| 63 | "steps": [{"label": "Signed in", "done": true}, {"label": "Invite your team", "done": false}, {"label": "Install your first app", "done": true}], |
| 64 | "apps": [ |
| 65 | {"id": "calls", "kind": "oficina", "name": "Calls", "url": "https://calls.oficina.works/", "icon_url": "/static/oficina/calls.<hash>.svg", "bundle_id": "works.oficina.calls", "scheme": "oficina-calls"}, |
| 66 | {"id": "docs", "kind": "oficina", "name": "Docs", "url": "https://docs.oficina.works/", "icon_url": "/static/oficina/docs.<hash>.svg", "bundle_id": "works.oficina.docs"}, |
| 67 | {"id": "scratchpad", "kind": "installed", "name": "Scratchpad", "url": "https://acme-scratchpad.example/", "tint": "rose", "icon_svg": "<svg …>"}, |
| 68 | {"id": "store", "kind": "own", "name": "Store", "url": "https://base.acme.example/store", "tint": "teal", "icon_svg": "<svg …>"} |
| 69 | ] |
| 70 | } |
| 71 | ``` |
| 72 | |
| 73 | - `apps` are in Home's order: the team's Oficina apps, the installed apps, |
| 74 | then Base's own pages (`store`, `people`, `settings`). |
| 75 | - An Oficina app has `icon_url`, a path on Base's origin (content-hashed, |
| 76 | immutable), its `bundle_id` (`works.oficina.<id>`), and a `scheme` only |
| 77 | where its native app opens by one today (Calls, Equipo). The others open |
| 78 | on the web until their apps take the kit's `…://open`. |
| 79 | - An installed app or own page has `tint` (a catalogue tint name: `amber`, |
| 80 | `teal`, `violet`, `rose`, `mist`, …) and `icon_svg`, line art drawn in |
| 81 | `currentColor`. Own pages' `url`s are Base's web pages. |
| 82 | - Optional keys are absent, never `null` or `""`. |
| 83 | |
| 84 | ## Store and People |
| 85 | |
| 86 | What the Store and People pages show, from the same builders, behind the |
| 87 | same member gate: any member's session, the native one or the web's |
| 88 | cookie. Every answer is JSON and `no-store`. A refusal is |
| 89 | `{"code": "…"}`. Without a session, or for someone who is no longer a |
| 90 | member, every route answers `401 {"code":"unauthenticated"}`, as above. |
| 91 | An app that hears `404` from a read is talking to an older Base, and opens |
| 92 | the web page instead. |
| 93 | |
| 94 | ### `GET /api/v1/store` |
| 95 | |
| 96 | ```json |
| 97 | { |
| 98 | "owner": true, |
| 99 | "rows": [ |
| 100 | {"id": "welcome", "name": "Welcome", "summary": "…", "tint": "amber", "icon_svg": "<svg …>", "state": "installed", "error": ""}, |
| 101 | {"id": "scratchpad", "name": "Scratchpad", "summary": "…", "tint": "rose", "icon_svg": "<svg …>", "state": "installing", "error": ""}, |
| 102 | {"id": "contra", "name": "Contra", "summary": "…", "tint": "teal", "icon_svg": "<svg …>", "state": "failed", "error": "The app did not start answering"} |
| 103 | ] |
| 104 | } |
| 105 | ``` |
| 106 | |
| 107 | - `rows` is the whole catalogue, in its order. `state` is `""` (not |
| 108 | installed), `installing`, `installed` or `failed`. `error` is a failed |
| 109 | install's reason, and may be `""` (show "The install didn't finish."). |
| 110 | - `owner` is whether this member may install and uninstall. Every member |
| 111 | sees the same rows. |
| 112 | - `icon_svg` is line art drawn in `currentColor` on `tint`, as in |
| 113 | `/api/v1/home`. |
| 114 | - `503 {"code":"unavailable"}`: Base couldn't read its installs. |
| 115 | |
| 116 | ### `GET /api/v1/people` |
| 117 | |
| 118 | ```json |
| 119 | { |
| 120 | "owner": true, |
| 121 | "people": [ |
| 122 | {"id": "…", "initial": "O", "name": "", "email": "owner@acme.test", "role": "owner"}, |
| 123 | {"id": "…", "initial": "A", "name": "Ana Ruiz", "email": "ana@acme.test", "role": "member"}, |
| 124 | {"id": "…", "initial": "B", "name": "", "email": "bob@acme.test", "role": "invited"} |
| 125 | ] |
| 126 | } |
| 127 | ``` |
| 128 | |
| 129 | - `people` is everyone here, in the order they were invited, as the page |
| 130 | lists them. |
| 131 | - `role` is `owner`, `member`, or `invited` (hasn't signed in yet). |
| 132 | - `name` is `""` for someone who has given none: show `email` then. |
| 133 | `initial` is the first letter of the name, or else of the address. |
| 134 | - `owner` is whether this member may invite. |
| 135 | - `503 {"code":"unavailable"}`: Base couldn't read its members. |
| 136 | - Nothing removes a member: `DELETE /api/v1/people/{id}` isn't a route. |
| 137 | |
| 138 | ### The writes |
| 139 | |
| 140 | The owner's alone. They are POSTs, inside Base's CSRF check, which the |
| 141 | kit's `Origin` passes. Install and uninstall take no body (one is |
| 142 | ignored); an invite takes JSON. |
| 143 | |
| 144 | | Route | Answers | |
| 145 | |---|---| |
| 146 | | `POST /api/v1/store/{app}/install` | `202 {"store": …}` with the app installing: poll `GET /api/v1/store` every 2 s while any row is. An app already installing answers `202`, and one already installed `200`, and neither starts anything. A failed row may be installed again (the page's "Try again"). If the install couldn't be started, the store is read again: a row that now shows installing (another request started it) answers `202` as it stands; anything else is `503 unavailable`, and nothing was started. A row that still reads failed then shows an earlier failure, not this attempt. | |
| 147 | | `POST /api/v1/store/{app}/uninstall` | `200 {"store": …}`, also when it was uninstalled already. `409 {"code":"busy"}` while it is still installing ("This app is still installing. Try again in a moment."). `503 unavailable`. | |
| 148 | | `POST /api/v1/people` | Body `{"email": "…"}`, trimmed and lowercased. `200 {"person": …}`, a person as in `GET /api/v1/people`: invited now, or already here (nothing is sent then). `422 {"code":"bad_email"}`: not one plain address. `502 {"code":"mail_failed"}`: they are invited but the email wasn't delivered; invite them again to send it. `415 {"code":"json_only"}` for a body that isn't `application/json`, `413 {"code":"too_large"}` over 4 KiB, `400 {"code":"bad_request"}` for JSON that doesn't parse. `503 unavailable`. | |
| 149 | |
| 150 | Every write also answers `403 {"code":"owner_only"}` to a member who isn't |
| 151 | the owner, before anything else, and the Store's `404 |
| 152 | {"code":"unknown_app"}` for an app the catalogue doesn't have. A POST with |
| 153 | no `Origin` (or another site's) is `403` in plain text, from the CSRF |
| 154 | check. |
| 155 | |
| 156 | ## Ask Base |
| 157 | |
| 158 | No Ask route answers `401` while Base's session is good: Equipo refusing |
| 159 | Ask's key is `409 {"state":"reconnect"}` (or `state` `reconnect` in a read). |
| 160 | A `401` is only ever Base's own `{"code":"unauthenticated"}`. |
| 161 | |
| 162 | The web's own routes. Writes are **form-encoded** |
| 163 | (`application/x-www-form-urlencoded`), not JSON, and must send |
| 164 | `Accept: application/json` to get JSON back (without it they redirect, as |
| 165 | for a form). Every answer is `no-store`. |
| 166 | |
| 167 | ### What the app can draw |
| 168 | |
| 169 | `GET /ask/state` and `GET /ask/events` may say what this build of the app |
| 170 | draws: a comma-separated list, as the header `Base-Client-Capabilities` |
| 171 | or as the query parameter `client_caps` (the kit's `NativeHTTP` sets no |
| 172 | header of its own, so the app sends the parameter). Base keeps the newest |
| 173 | list per app session, from these two reads only, and tells the Assistant |
| 174 | a feature is drawn only while every app the member used in the last 30 |
| 175 | days last said so. An app session Base has not yet heard say it (a live |
| 176 | session that hasn't read `/ask/state` since, or whose read Base couldn't |
| 177 | record) counts as drawing nothing. An app that says nothing keeps what it |
| 178 | gets today: its reads carry each message's lookups folded into its |
| 179 | `text`, with the answer's own links and markup escaped. |
| 180 | |
| 181 | | value | what the app draws | |
| 182 | |---|---| |
| 183 | | `lookup_answers` | A message's `lookups` (below) | |
| 184 | |
| 185 | ### The states |
| 186 | |
| 187 | `state` is one of: |
| 188 | |
| 189 | | state | meaning | |
| 190 | |---|---| |
| 191 | | `connect` | Ask isn't connected for this person (or a code ran out). | |
| 192 | | `pending` | A sign-in code waits for approval in Equipo (web code flow). | |
| 193 | | `ready` | Connected; the conversation shows. | |
| 194 | | `norunner`, `oldrunner` | Connected, but the person has no runner that can answer (none, or too old). The conversation shows, with a note. | |
| 195 | | `reconnect` | Equipo refused the key, or it expired. | |
| 196 | | `unavailable` | Equipo didn't answer. | |
| 197 | | `not_linked` | (Only from `POST /api/v1/ask/oficina`.) Equipo has no member linked to this Oficina ID. | |
| 198 | |
| 199 | ### `GET /ask/state` |
| 200 | |
| 201 | ```json |
| 202 | {"state": "ready", "messages": [Message…], "jobs": [Job…], "cards": [Card…], "turn": Turn|null, |
| 203 | "status": "Thinking…", "cursor": 42, "renew_after": "2026-11-28T10:00:00Z", "equipo_origin": "https://equipo.acme.example", |
| 204 | "disconnected": false, "can_attach": true} |
| 205 | ``` |
| 206 | |
| 207 | - `messages`, `jobs` and `cards` are never `null`. Outside `ready`, |
| 208 | `norunner` and `oldrunner` they are empty and `cursor` is `0`. |
| 209 | - `turn` is the newest turn the person sees running (never a quiet |
| 210 | `team_update` one), or `null`. `status` is the line under the |
| 211 | conversation while it runs: `"Thinking…"`, `"Ask Base can't answer right |
| 212 | now. It will as soon as it can."` (turn `waiting`), or `""`. With no |
| 213 | turn running, it says why the turn of the person's newest message |
| 214 | failed for its files (Turn `reason` `attachment_unavailable`, |
| 215 | `runner_storage_full` or `runner_too_old`), as a live `turn` event with |
| 216 | that reason should too. |
| 217 | - `cursor` is where `/ask/events` starts. |
| 218 | - `renew_after` (RFC 3339, UTC) is set when Ask was connected with Oficina |
| 219 | ID: from then on, the app sets Ask up again with a fresh assertion |
| 220 | (below), silently. `""` for a key from the web's code flow, or none. |
| 221 | - `equipo_origin` is the Equipo instance Ask relays to: the audience of the |
| 222 | assertion for Ask set-up. |
| 223 | - `disconnected` is `true` once the member has disconnected Ask, on any |
| 224 | device or the web, until a connection they make themselves is stored. |
| 225 | While it is, no client sets Ask up by itself; the app offers Connect |
| 226 | instead. `state` is then `connect`, as after any Disconnect, or `pending` |
| 227 | while a code from the web's Connect waits for approval (still `true`). |
| 228 | - `can_attach` is `true` only in `ready`, when Equipo says the person's |
| 229 | runner can take files. Offer attaching only then; an older Equipo never |
| 230 | says so. |
| 231 | |
| 232 | **Message** `{"id", "role": "person"|"assistant", "text", "turn_id", "created_at", "attachments"?, "lookups"?}`. |
| 233 | An assistant's `text` may carry the little Markdown `ask.js` draws (lists, |
| 234 | links to http(s) only, bold and italics). `attachments` is there only on a |
| 235 | person's message with files, in the order they were attached; its `text` |
| 236 | may then be `""`. Until the app draws files, show their names as a line |
| 237 | under the text, so a bubble is never empty. |
| 238 | |
| 239 | `lookups` is there only on an assistant's message that looked |
| 240 | something up, and only for an app that says it draws them (above), at |
| 241 | most 2, in the order they were made. |
| 242 | |
| 243 | **Lookup** `{"answer", "sources": [{"url", "title"}]}`. Draw each after |
| 244 | the message's own words: the answer in the little Markdown above but with |
| 245 | **no links at all** (a Markdown link shows as its words, a bare URL as |
| 246 | text), then a quiet "Sources" line with each source's `title` as a link |
| 247 | (an `https` address, opening in the browser) and its host after it, without |
| 248 | `www.`. An empty `title` shows the host. The answer is at most 1,200 |
| 249 | characters, a title at most 120, and there are at most 5 sources. |
| 250 | |
| 251 | **Attachment** `{"id", "kind": "image"|"file", "name", "media_type", "size", "width", "height"}`. |
| 252 | `size` is in bytes; `width` and `height` are an image's upright size, `0` |
| 253 | for a file. Treat any other `kind` as `file`. Read it from Base, never from |
| 254 | Equipo: `GET /ask/attachments/{id}`, and an image's thumbnail (at most |
| 255 | 1024 px) at `/ask/attachments/{id}/preview` (see Files). |
| 256 | |
| 257 | **Turn** `{"id", "kind", "state": "queued"|"running"|"waiting"|"replied"|"failed"|"cancelled", "reason"}`. |
| 258 | |
| 259 | **Card** `{"id", "revision", "kind", "state", "question", "options": [{"value","label"}], "links": [{"label","url","rel"?}], "result", "job"?, "detail"?, "started_at"?, "carry_on"?, "turn_id"?}`. |
| 260 | - `kind` is `question`, `confirm`, `outcome`, `connect` or `job`; a card is |
| 261 | `open` while it waits for an answer. Every link is absolute http(s). |
| 262 | - `rel` is `equipo` (a job's page in Equipo) or `oficina_connect` (Base's |
| 263 | own `/ask/oficina/connect`, a browser flow). |
| 264 | - A job card has no options; its `state` is `working`, `asking`, `ready`, |
| 265 | `done`, `paused` or `stopped`; `result` is its short status, `detail` one sentence |
| 266 | more and `started_at` when it began. A `paused` job carries on by itself |
| 267 | (draw it with the clock mark); its `result` and `detail` are Equipo's, |
| 268 | already in the team's time zone ("Paused until 21:00"): show them as |
| 269 | given. `carry_on: true` (on a `paused` or `stopped` job card only, else |
| 270 | absent) offers "Carry on now" (`POST /ask/cards/{id}/carry_on`). On a |
| 271 | `paused` job it has the line "Uses your other plan, at no extra cost." |
| 272 | under it; on a `stopped` one (a job held while building was turned off |
| 273 | for the person, now on again) it has no line. |
| 274 | - `job` names the job card a card belongs to; `turn_id`, on a connect card |
| 275 | from the stream, the turn that raised it. |
| 276 | |
| 277 | **Job** is a job Card plus `"cards": [Card…]`, the cards that belong to it, |
| 278 | open and ended. |
| 279 | |
| 280 | ### `GET /ask/events?after=<cursor>` |
| 281 | |
| 282 | Server-Sent Events, `text/event-stream`. On a reconnect, `Last-Event-ID` |
| 283 | wins over `after`. The stream opens with `retry: 3000`, then: |
| 284 | |
| 285 | ``` |
| 286 | id: 43 |
| 287 | event: message |
| 288 | data: {"type":"message","data":Message} |
| 289 | ``` |
| 290 | |
| 291 | | event | data | |
| 292 | |---|---| |
| 293 | | `message` | Message | |
| 294 | | `turn` | Turn | |
| 295 | | `card` | Card (a job card included: `kind` `job`) | |
| 296 | | `delta` | `{"turn_id","offset","text"}`: a few of the reply's words; `offset` counts UTF-8 bytes | |
| 297 | | `activity` | `{"turn_id","label"}`: what the Assistant is doing | |
| 298 | | `glance` | `{"turn_id","text"}`: one line before the first words. **No `id` line**: it doesn't move the cursor. | |
| 299 | | `state` | `{"state"}`: the stream can't start (not `ready`); it ends after this one event. | |
| 300 | |
| 301 | - `: ping` comments keep it alive. A stream lasts at most ten minutes; |
| 302 | reconnect with the last id. |
| 303 | - Equipo not answering is `502`, and a bad `after` `400` (plain text): |
| 304 | reload `/ask/state` and start again from its cursor. |
| 305 | |
| 306 | ### `POST /ask/messages` |
| 307 | |
| 308 | Form: `text` (at most 16 KiB after trimming; valid UTF-8, no NUL), up to |
| 309 | five `attachments` (upload ids, in order; see Files) and `key`, a fresh |
| 310 | idempotency key per message (at most 128 bytes, not starting `reply:`, |
| 311 | `card:` or `handoff:`). Text may be empty when there are attachments. A |
| 312 | resend after a network error reuses the key: Equipo keeps one message per |
| 313 | key, with its files. |
| 314 | |
| 315 | - `200 {"message": Message, "turn": Turn}`. |
| 316 | - `422 {"state":"ready"}`: empty, too long, not text, or more than five |
| 317 | attachments or one that isn't an upload id. Nothing was sent. |
| 318 | - With attachments only: |
| 319 | - `409 {"state":"ready","files":"unavailable"}`: the person's runner |
| 320 | can't take files right now. Ask stays ready; nothing was stored. Drop |
| 321 | the files (stop offering them: `can_attach` is now `false`) and the |
| 322 | words can go alone. |
| 323 | - `422 {"state":"ready","files":"stale"}`: an upload is gone (dropped |
| 324 | after 24 hours unsent, removed, or already sent). Attach it again. |
| 325 | |
| 326 | ### `POST /ask/turns/{id}/cancel` |
| 327 | |
| 328 | Form: `key`. `200 {"state":"ready"}`; `409 {"state":"ready"}` when the turn |
| 329 | has already ended. |
| 330 | |
| 331 | ### `POST /ask/cards/{id}/answer` |
| 332 | |
| 333 | Form: `choice` (an option's `value`), `revision` (the card's, as seen) and |
| 334 | `key`. |
| 335 | |
| 336 | - `200 {"card": Card, "message": Message|null, "turn": Turn|null}`. An |
| 337 | outcome card's answer starts no turn: both are `null`. |
| 338 | - `409 {"state":"ready"}`: the card moved on (answered, or a newer |
| 339 | revision). Reload `/ask/state` to redraw it. |
| 340 | |
| 341 | ### `POST /ask/cards/{id}/carry_on` |
| 342 | |
| 343 | A paused or held job's "Carry on now". Form: `revision` (the job card's, as seen) |
| 344 | and `key`, a fresh idempotency key kept until an answer settles the |
| 345 | outcome (a resend after a network error or a `502` reuses it). |
| 346 | |
| 347 | - `200 {"card": Card}`: the job card as it is now (working again). |
| 348 | `{"card": null}` (a card Base does not draw): reload `/ask/state`. |
| 349 | - `409 {"state":"ready"}`: the job moved on (a newer revision), is no longer |
| 350 | paused, no longer offers it, or is not one of the person's jobs at all |
| 351 | (Equipo's `card_stale`, `not_paused`, `carry_on_unavailable`, `404`). |
| 352 | Reload `/ask/state` to redraw it; never resend. |
| 353 | - A failure to try again (`502`, no answer) belongs next to the button, |
| 354 | inside the job view, not only on the status line. |
| 355 | - Without scripts, the form answers `303 /ask`. |
| 356 | |
| 357 | ### Every write's other answers |
| 358 | |
| 359 | | status | body | meaning | |
| 360 | |---|---|---| |
| 361 | | `409` | `{"state":"connect"\|"pending"\|"reconnect"\|"unavailable"}` | Not connected: nothing was sent. | |
| 362 | | `409` | `{"state":"reconnect"}` | Equipo refused the key as it was used. Set Ask up again (with Oficina ID, below). | |
| 363 | | `409` | `{"state":"norunner"\|"oldrunner"}` | No runner can answer; nothing was sent. | |
| 364 | | `502` | `{"state":"unavailable"}` | Equipo didn't answer. Try again with the same key. | |
| 365 | | `400` | plain text | The form couldn't be read. | |
| 366 | |
| 367 | ### Files |
| 368 | |
| 369 | An upload belongs to the person until it is sent, or for 24 hours; at |
| 370 | most 20 wait unsent. Base keeps no copy: it relays to Equipo with the |
| 371 | person's key. Equipo's limits: 10 MiB a file, at most 12,000 px a side and |
| 372 | 40 megapixels an image, and nine types (PNG, JPEG, WebP, GIF, PDF, plain |
| 373 | text, Markdown, CSV, JSON), sniffed from the bytes. HEIC is refused. |
| 374 | |
| 375 | #### `POST /ask/attachments` |
| 376 | |
| 377 | The file's bytes as the body (with `Content-Length`), its type in |
| 378 | `Content-Type`, its name in `Content-Disposition` (`filename`, or |
| 379 | `filename*` beyond ASCII). Not a form, and no key: a retry is a second |
| 380 | upload. |
| 381 | |
| 382 | - `201 Attachment`. |
| 383 | - `413 {"code":"attachment_too_large"}`: over 10 MiB, refused before the |
| 384 | body is read when the length says so. |
| 385 | - Equipo's refusals, with its status: `415 {"code":"attachment_type"}`, |
| 386 | `415 {"code":"attachment_heic"}`, `413 {"code":"attachment_pixels"}`, |
| 387 | `409 {"code":"attachment_limit"}` (20 wait unsent: send or remove some). |
| 388 | - `503 {"code":"busy"}` with `Retry-After` (seconds): every upload slot is |
| 389 | busy. Try again after it, by itself. |
| 390 | - `409 {"state"}` and `502 {"state":"unavailable"}` as for every write. |
| 391 | |
| 392 | #### `DELETE /ask/attachments/{id}` |
| 393 | |
| 394 | Removes an unsent upload, freeing its place among the 20. `204`, also when |
| 395 | it was gone already. `409 {"state":"ready","code":"attachment_sent"}` once |
| 396 | it is on a message. `404` for anything that isn't an upload id. |
| 397 | |
| 398 | #### `POST /ask/attachments/discard` |
| 399 | |
| 400 | The web page's beacon as it goes away: form, up to five `id`. Base deletes |
| 401 | each as best it can and always answers `204`. |
| 402 | |
| 403 | #### `GET /ask/attachments/{id}`, `GET /ask/attachments/{id}/preview` |
| 404 | |
| 405 | The file, streamed (`HEAD` too). `/preview` is an image's thumbnail, and |
| 406 | `404` for any other file. PNG, JPEG, WebP and GIF are `inline`; everything |
| 407 | else is an `attachment` download (text with `charset=utf-8`), and a type |
| 408 | outside the nine is `application/octet-stream`. Every answer has |
| 409 | `X-Content-Type-Options: nosniff` and a sandboxing CSP. A preview may be |
| 410 | cached by this client for an hour (`private, max-age=3600`); the file |
| 411 | itself is `no-store`. |
| 412 | |
| 413 | - `404` (empty) for a file that isn't the person's, or without a live Ask |
| 414 | connection; never a redirect. |
| 415 | - `502` (empty) when Equipo fails or is slow. |
| 416 | |
| 417 | ### `POST /ask/disconnect` |
| 418 | |
| 419 | Ends the person's Ask connection, revoking the key in Equipo, whichever |
| 420 | way it was made, and marks Ask disconnected by the member (`disconnected` |
| 421 | in `/ask/state`), for every device and the web. It answers `303 /settings`. |
| 422 | A Disconnect that fails changes nothing, the mark included. |
| 423 | |
| 424 | Only a connection the member makes clears the mark, in the same |
| 425 | transaction that stores it: |
| 426 | - the web's code flow once the code is approved and the key stored (pressing |
| 427 | Connect or Reconnect alone leaves it set; a code that expires, is refused |
| 428 | or is abandoned leaves it set); |
| 429 | - `POST /api/v1/ask/oficina` without `"auto": true`, once its key is stored. |
| 430 | |
| 431 | Any set-up that fails leaves it set. An automatic set-up never clears it, |
| 432 | and the save itself refuses while it is set. |
| 433 | |
| 434 | ## Ask set-up with Oficina ID |
| 435 | |
| 436 | ### `POST /api/v1/ask/oficina` |
| 437 | |
| 438 | JSON `{"assertion", "verifier", "auto"?}`: an assertion the kit fetched |
| 439 | from Oficina ID addressed to `equipo_origin`, and its verifier. `auto` is |
| 440 | `true` for a set-up the app starts by itself (after sign-in, or to renew |
| 441 | after `renew_after`); leave it out, or send `false`, when the person asked |
| 442 | to connect. `auto` must be exactly `true` or `false`: `null`, any other |
| 443 | type, a repeated key or another spelling (`"AUTO"`) is `400 invalid`, as is |
| 444 | any unknown or repeated name. Only a native session may |
| 445 | call it (with `Origin`, as every POST). Base completes Equipo's own native |
| 446 | sign-in for the person (Equipo's `POST /native/oficina-id`, then |
| 447 | `POST /api/v1/auth/devices/native`), keeps the key it gets sealed where the |
| 448 | web's code flow keeps one, and registers the Assistant's host with it. |
| 449 | Two posts for the same person run one at a time, and a set-up yields to |
| 450 | anything else that changes the person's connection meanwhile. |
| 451 | |
| 452 | | status | body | meaning | |
| 453 | |---|---|---| |
| 454 | | `200` | `{"state":"ready","renew_after":"<RFC 3339>"}` | Ask is ready. The key ends with Equipo's session, seven days after it was made; `renew_after` is five days after. After it, post a fresh assertion: that replaces the key and revokes the old one in Equipo. | |
| 455 | | `409` | `{"state":"disconnected"}` | `auto` was `true`, and the member has disconnected Ask (also while a web code waits for approval). Nothing is stored; if the member disconnected while this set-up was at Equipo, the device Equipo made was revoked. Show Connect; post again without `auto` only when the person asks. | |
| 456 | | `409` | `{"state":"not_linked"}` | Equipo has no member linked to this Oficina ID. Show Ask's "not set up for you yet" state, with the web's code flow; don't retry in a loop. | |
| 457 | | `409` | `{"state":"superseded"}` | Ask's connection changed while Equipo answered (Disconnect, or a connection from the web): nothing was saved, and the device Equipo made was revoked. Reload `/ask/state`; don't retry at once. | |
| 458 | | `422` | `{"state":"failed"}` | Equipo didn't accept the assertion (expired, wrong audience or verifier, already used). Get a fresh one and try once more. | |
| 459 | | `400` | `{"state":"invalid"}` | Not JSON, an unknown, repeated or missing name, `auto` not exactly `true` or `false`, or Equipo couldn't read it. | |
| 460 | | `403` | `{"state":"forbidden"}` | Not a native session: the web keeps its code flow. | |
| 461 | | `502` | `{"state":"unavailable"}` | Equipo didn't answer, or refused the device. Try again later. | |
| 462 | | `503` | `{"state":"unavailable"}` | Base couldn't read or store the connection. | |
| 463 | |
| 464 | Every failure stores nothing and leaves an existing connection as it was. |
| 465 | The route answers `404` when Ask Base is off. It never answers `401` for |
| 466 | Equipo's sake: a `401` is always Base's own session. |
| 467 | |