@vercel/board 0.32.0 → 0.33.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.
Files changed (166) hide show
  1. package/README.md +25 -20
  2. package/dist/{access-CY5xVMIK.mjs → access-N3XmkKXg.mjs} +3 -3
  3. package/dist/access.d.mts +4 -5
  4. package/dist/access.mjs +5 -5
  5. package/dist/{actors-Bm-ojWWT.mjs → actors-ihyN47OV.mjs} +3 -3
  6. package/dist/{auth-K8dY1nBY.d.mts → auth-D6z3rMNj.d.mts} +7 -93
  7. package/dist/{auth-8pRZnF1M.mjs → auth-r-_PeZyw.mjs} +32 -148
  8. package/dist/{backend-DxE9wGKm.d.mts → backend-CWpyR1A7.d.mts} +81 -51
  9. package/dist/backend-local.d.mts +28 -0
  10. package/dist/backend-local.mjs +2 -0
  11. package/dist/{chat-provider-DkFp2hrh.mjs → chat-provider-9hCT654s.mjs} +2 -2
  12. package/dist/{chat-provider-BChYrrA7.d.mts → chat-provider-DJpFUaFv.d.mts} +2 -3
  13. package/dist/cli-commands.d.mts +1 -1
  14. package/dist/cli-commands.mjs +1 -1
  15. package/dist/cli-embedded.d.mts +2 -2
  16. package/dist/cli-embedded.mjs +1 -1
  17. package/dist/cli.mjs +6 -6
  18. package/dist/{commands-CpyPV_tk.d.mts → commands-BOBQHVqM.d.mts} +9 -0
  19. package/dist/{commands-DsnQKTdB.mjs → commands-CHoMl06v.mjs} +12 -1
  20. package/dist/{conformance-3RBKxwbp.mjs → conformance-qKmGLTAT.mjs} +5 -5
  21. package/dist/conformance.d.mts +1 -1
  22. package/dist/conformance.mjs +1 -1
  23. package/dist/{engine-DurYIRt8.mjs → engine-JxgZiikU.mjs} +6 -8
  24. package/dist/{errors-CJXhhzvT.mjs → errors-Pk0XV1hK.mjs} +56 -2
  25. package/dist/{events-lujPA3gQ.mjs → events-IQg0k281.mjs} +2 -2
  26. package/dist/exports-BuKjVq2t.d.mts +4 -0
  27. package/dist/exports-gHDHlg0i.mjs +3207 -0
  28. package/dist/{external-D3p5T57R.mjs → external-CYe424fO.mjs} +1 -1
  29. package/dist/{folds-DLUzfibJ.d.mts → folds-DjFTiqIM.d.mts} +38 -44
  30. package/dist/index-CXvvYNYj.d.mts +11 -0
  31. package/dist/index.d.mts +9 -8
  32. package/dist/index.mjs +21 -8
  33. package/dist/index.node.d.mts +5 -6
  34. package/dist/index.node.mjs +3 -3
  35. package/dist/inspect/app.js +95 -95
  36. package/dist/{internal-CvsrprnU-zZMpDiRY.mjs → internal-CvsrprnU-CEPOUpAv.mjs} +63 -43
  37. package/dist/local-BbLjA5vI.mjs +8818 -0
  38. package/dist/{main-CcYDo9Hb.mjs → main-CQpCZJFw.mjs} +91 -23
  39. package/dist/{backend-a2/store-memory.mjs → memory-7RRnLa4X.mjs} +3 -3
  40. package/dist/middleware-BU7rVi9F.mjs +103 -0
  41. package/dist/{client-COfYrgfV.d.mts → provider-BlzUvcM9.d.mts} +665 -5
  42. package/dist/{schemas-DBmUO6pr.mjs → schemas-BG205xds.mjs} +2 -5
  43. package/dist/{serve-Bplieh0C.mjs → serve-D8_W4UN6.mjs} +33 -24
  44. package/dist/{node-BgeGcwX0.mjs → server-BiIUXWbU.mjs} +419 -6
  45. package/dist/{serving-Y7s7VDjB.mjs → serving-D7rcUtSC.mjs} +1 -1
  46. package/dist/{sql-E1K5g_ih.mjs → sql-BQzKUqQt.mjs} +349 -114
  47. package/dist/sqlite-DCtZFEVm.mjs +30 -0
  48. package/dist/{sqlite-db-CzcD_FW8.mjs → sqlite-db-qLTs52Ny.mjs} +2 -3
  49. package/dist/{store-codec-pAG2oPgQ-SqDXlPBR.mjs → store-N8PXxDAS-BdL4Sq-f.mjs} +6 -2
  50. package/dist/{store-memory-B0PkVSuQ.mjs → store-memory-CKQVEzXN.mjs} +2 -4
  51. package/dist/store-memory-OdGsc-t_.mjs +2 -0
  52. package/dist/{store-polling-BZt2Rf3D-Div-bJ_D.mjs → store-polling-BZt2Rf3D-oh3aU_An.mjs} +1 -1
  53. package/dist/store-sqlite-CTxAVCcz.mjs +2 -0
  54. package/dist/{store-sqlite-D85t3tE7.mjs → store-sqlite-D6fIszST.mjs} +3 -4
  55. package/dist/sync-chat-sdk.d.mts +2 -2
  56. package/dist/sync-chat-sdk.mjs +2 -2
  57. package/dist/sync-github.d.mts +2 -2
  58. package/dist/sync-github.mjs +2 -2
  59. package/dist/sync-linear.d.mts +2 -3
  60. package/dist/sync-linear.mjs +2 -2
  61. package/dist/sync-slack.d.mts +3 -3
  62. package/dist/sync-slack.mjs +4 -4
  63. package/dist/sync.d.mts +2 -2
  64. package/dist/sync.mjs +2 -2
  65. package/dist/{watchers-hash-CurCzwhe.mjs → targets-CknPGGVi.mjs} +40 -10
  66. package/dist/{tokens-C7kYyrAG.mjs → tokens-DPKjl3jf.mjs} +15 -43
  67. package/docs/01-board/01-mounting.md +243 -288
  68. package/docs/01-board/03-identity.md +41 -50
  69. package/docs/01-board/04-messages.md +15 -14
  70. package/docs/01-board/05-reading.md +3 -3
  71. package/docs/01-board/06-watchers.md +58 -105
  72. package/docs/01-board/07-schedules.md +21 -41
  73. package/docs/01-board/08-middleware.md +11 -17
  74. package/docs/01-board/09-access.md +76 -313
  75. package/docs/01-board/10-local.md +81 -0
  76. package/docs/01-quickstart.md +49 -126
  77. package/docs/02-sync/01-overview.md +25 -80
  78. package/docs/02-sync/02-functions.md +10 -16
  79. package/docs/02-sync/03-slack.md +13 -26
  80. package/docs/02-sync/04-github.md +8 -20
  81. package/docs/02-sync/07-linear.md +6 -10
  82. package/docs/03-guides/02-inspector.md +3 -3
  83. package/docs/03-guides/03-ci.md +88 -128
  84. package/docs/03-guides/04-triage.md +7 -15
  85. package/docs/03-guides/05-agent-factory.md +30 -36
  86. package/docs/04-reference/01-cli.md +104 -22
  87. package/docs/04-reference/02-board.md +60 -74
  88. package/docs/04-reference/03-http.md +119 -57
  89. package/docs/04-reference/05-conformance.md +31 -45
  90. package/docs/index.md +41 -65
  91. package/package.json +12 -83
  92. package/dist/a2-DiDc77Uf.mjs +0 -4238
  93. package/dist/access-DPcrKIH_.d.mts +0 -37
  94. package/dist/backend-a2/blob-vercel.d.mts +0 -8
  95. package/dist/backend-a2/blob-vercel.mjs +0 -81
  96. package/dist/backend-a2/contract.d.mts +0 -828
  97. package/dist/backend-a2/contract.mjs +0 -5
  98. package/dist/backend-a2/scheduler-local.d.mts +0 -11
  99. package/dist/backend-a2/scheduler-local.mjs +0 -2
  100. package/dist/backend-a2/scheduler-qstash.d.mts +0 -79
  101. package/dist/backend-a2/scheduler-qstash.mjs +0 -522
  102. package/dist/backend-a2/scheduler-vercel.d.mts +0 -38
  103. package/dist/backend-a2/scheduler-vercel.mjs +0 -204
  104. package/dist/backend-a2/store-memory.d.mts +0 -11
  105. package/dist/backend-a2/store-postgres.d.mts +0 -38
  106. package/dist/backend-a2/store-postgres.mjs +0 -2977
  107. package/dist/backend-a2/store-redis-http.d.mts +0 -17
  108. package/dist/backend-a2/store-redis-http.mjs +0 -520
  109. package/dist/backend-a2/store-redis.d.mts +0 -31
  110. package/dist/backend-a2/store-redis.mjs +0 -88
  111. package/dist/backend-a2/store-sqlite.d.mts +0 -12
  112. package/dist/backend-a2/store-sqlite.mjs +0 -31
  113. package/dist/backend-a2.d.mts +0 -2633
  114. package/dist/backend-a2.mjs +0 -3
  115. package/dist/backend-http-CaN06CaD.d.mts +0 -672
  116. package/dist/backend-http-CoaCghuJ.mjs +0 -18
  117. package/dist/backend-http-l5A8UmL-.mjs +0 -585
  118. package/dist/backend-http.d.mts +0 -10
  119. package/dist/backend-http.mjs +0 -2
  120. package/dist/backend-http.node.d.mts +0 -10
  121. package/dist/backend-http.node.mjs +0 -2
  122. package/dist/backend-vercel-BE65okBC.mjs +0 -86
  123. package/dist/backend-vercel-CVxoTNF2.mjs +0 -1744
  124. package/dist/backend-vercel-jg-6PAgD.d.mts +0 -674
  125. package/dist/backend-vercel.d.mts +0 -9
  126. package/dist/backend-vercel.mjs +0 -11
  127. package/dist/backend-vercel.node.d.mts +0 -17
  128. package/dist/backend-vercel.node.mjs +0 -2
  129. package/dist/blob-Bx8QPWEd.d.mts +0 -40
  130. package/dist/blob-WbB2DJKn.mjs +0 -201
  131. package/dist/errors-2vGs49Db.d.mts +0 -16
  132. package/dist/exports-BnUZuRm9.mjs +0 -1389
  133. package/dist/exports-u5mApVvn.d.mts +0 -5
  134. package/dist/files-SniSmeEr.mjs +0 -47
  135. package/dist/folds-DsWfIftc.mjs +0 -208
  136. package/dist/index-UXpTPWNc.d.mts +0 -11
  137. package/dist/index.default-Dp8gexln.mjs +0 -12
  138. package/dist/local-C76Fy5ad.mjs +0 -44
  139. package/dist/middleware-BavYSDUa.mjs +0 -62
  140. package/dist/platform-B4TnJtWu-Do3agKr5.mjs +0 -32
  141. package/dist/project-4Vl7_uy5.mjs +0 -124
  142. package/dist/provider-gynDUoyW.d.mts +0 -665
  143. package/dist/redis-tables-BFRj_SEJ.mjs +0 -3895
  144. package/dist/reducer-Bswr11ar-P324o9vn.mjs +0 -74
  145. package/dist/reducer-CYPHsSmd-BXjGiptm.d.mts +0 -170
  146. package/dist/reducers-DQVSP3kk.mjs +0 -538
  147. package/dist/retryable-lazy-DZWmHpii-DpTc5PIP.mjs +0 -19
  148. package/dist/scheduler-task-X1SToDjP-D2Il2rln.mjs +0 -69
  149. package/dist/server-B9gu0qi1-DI1WvcVK.d.mts +0 -391
  150. package/dist/server-DX7mM6nm-D7N_7bug.mjs +0 -3611
  151. package/dist/server-wIpAEjpX.mjs +0 -17
  152. package/dist/session-clear-XJYpmUpg-2q8l_FJR.mjs +0 -63
  153. package/dist/store-DEzcHZOA-B-5vhxef.d.mts +0 -540
  154. package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +0 -5
  155. package/dist/store-memory-4IBl0Ztu.mjs +0 -2
  156. package/dist/store-presence-polling-JuAy2Ck2-Dh-g_KYM.mjs +0 -109
  157. package/dist/store-sqlite-iBTYYKBj.mjs +0 -2
  158. package/dist/stream-buffer-DrTyiIuo-Be10yOBR.mjs +0 -53
  159. package/dist/targets-Cgjs29T0.mjs +0 -33
  160. package/dist/types-CmrFjpml.d.mts +0 -102
  161. package/dist/wait-until-Dw4XrIDQ.mjs +0 -42
  162. package/docs/01-board/02-database.md +0 -258
  163. package/docs/04-reference/04-log.md +0 -247
  164. package/sql/postgres/board.sql +0 -145
  165. package/sql/postgres/notifications.sql +0 -24
  166. package/sql/postgres/schema.sql +0 -451
@@ -1,247 +0,0 @@
1
- ---
2
- title: The log
3
- description: 'The A2 contract a board on `a2()` keeps: its events, the side contracts, the consumers, and the tables and reducers reads come from.'
4
- ---
5
-
6
- ## One log
7
-
8
- Every board fact is an event in one [A2](https://www.a2.dev) session, `board`,
9
- of the contract `board`, on a board on `a2()`. Every view (a channel, a
10
- thread, the actors) is folded from that log: messages into the
11
- [tables](#reducers-and-tables) the board keeps, the smaller views by reducers,
12
- whose snapshots are caches: deleting them is always safe.
13
-
14
- - **A message's ID is the log index of its `message.posted` event.** IDs are
15
- short, stable, unique within the board, and double as positions in the log
16
- (`after`). Other events consume indexes too, so message IDs have gaps.
17
- - **The API shows indexes as strings.** Message IDs, schedule IDs, and cursors
18
- are decimal strings there (`"812"`). Clients pass them back as they got them
19
- and don't count with them: a board on another backend picks its own. An
20
- event's `cursor` is its index, and a message's `version` is the index of the
21
- last event that changed it. See [IDs and cursors](./03-http.md#ids-and-cursors).
22
- - **One log means one global order**, reducers that see everything, and atomic
23
- batches: a root and the `thread.synced` events for its targets commit
24
- together.
25
- - **Bookkeeping people don't read lives in side contracts**: raw platform
26
- events, watcher matches and registrations, account codes, and scheduled
27
- messages.
28
-
29
- ```ts
30
- // anywhere: the contract, its schemas, and the reducers are isomorphic
31
- import { boardContract, messagesReducer, type BoardEvent } from '@vercel/board/backend-a2/contract'
32
- ```
33
-
34
- ## Board events
35
-
36
- Fields marked **(server)** are never taken from a request. The board resolves
37
- or records them after verifying the token.
38
-
39
- ### message.posted
40
-
41
- A new root or reply.
42
-
43
- | Field | Type | Meaning |
44
- | --- | --- | --- |
45
- | `channel` | `string` | the channel path |
46
- | `text` | `string` | markdown, up to 10,000 characters; empty only when there are attachments |
47
- | `re` | `number \| null` | the thread root, or null for a root |
48
- | `replyTo` | `number \| null` | (server) the exact message replied to, when it isn't the root |
49
- | `thread` | `string` | (server) the thread key: the root's event ID |
50
- | `labels` | `Record<string, string>` | labels on the message |
51
- | `noSync` | `boolean` | kept on the board, not delivered to platforms |
52
- | `mentions` | `string[]` | (server) the actor IDs its mentions resolved to |
53
- | `by` | `{ actor, principal, profile, session }` | (server) who wrote it |
54
- | `origin` | `{ channel?, thread, subthread, message, context } \| null` | (server) where it came from on a platform |
55
- | `from` | `string \| null` | (server) the sync key it came from, or null when written on the board |
56
- | `attachments` | `{ id, name, type, size }[]` | (server) its files, as the board stored them. A request names only IDs |
57
- | `links` | `{ url, message, snapshot, unavailable }[]` | (server) platform messages it links to, each with what it said |
58
- | `schedule` | `{ id, n }` | (server) set when a schedule posted it: the schedule and which send, from 0 |
59
- | `blind` | `true` | (server) set when its author couldn't read its channel: where they can't read, it's theirs to edit and delete only then |
60
- | `importedBy` | `string` | (server) the principal of the sync elsewhere that imported it, whose copy `origin` is: only that sync acts on it. None for the board's own sync's |
61
-
62
- ### The rest
63
-
64
- Every event below but `channel.created` and `actor.seen` carries `thread`, the
65
- thread key, so consumers can keep a thread's events in order on its lane.
66
-
67
- | Event | Payload | Written when |
68
- | --- | --- | --- |
69
- | `channel.created` | `channel`, `by` | a channel is made before anything posts to it. A post makes one with no event of its own |
70
- | `message.edited` | `id`, `text`, `mentions` (server), `by`, `from` | a message's text changes, on the board or a platform |
71
- | `message.deleted` | `id`, `by`, `from` | a message is deleted. It becomes a tombstone and drops its reactions, files, and links |
72
- | `message.linked` | `id`, `links`, `by`, `from` | a platform edit or unfurl changes what a message links to |
73
- | `reaction.added` | `id`, `emoji`, `by`, `from` | someone reacts. `emoji` is a short name: `eyes`, `thumbs_up` |
74
- | `reaction.removed` | `id`, `emoji`, `by`, `from` | someone removes their reaction |
75
- | `labels.changed` | `id`, `set`, `unset`, `by` | labels are set or unset |
76
- | `thread.synced` | `target`, `cause` (`config` or `request`), `kind` (`channel` or `thread`), `by` | a thread is synced with an external channel (a thread starts there) or thread (it joins) |
77
- | `message.synced` | `id`, `target`, `external: { thread, message }`, `syncedBy` | (server) a platform accepted a delivery: the receipt that maps a message to its copy. `syncedBy` names the sync elsewhere that recorded it, whose copy it is; none for the board's own sync |
78
- | `message.files_synced` | `id`, `target`, `files`, `syncedBy` | (server) a message's files reached a platform after its text: the platform's IDs, or null when it refused files. Only the sync whose copy it is sets them |
79
- | `message.sync_failed` | `id`, `target`, `error` | (server) a delivery gave up after its retries |
80
- | `actor.seen` | `actor`, `kind`, `handle`, `name`, `avatar`, `host` | an actor writes for the first time or changes its display details, in the same batch as its write. `host` (server) marks a principal a host's `authenticate` made, or one of its profiles, which sync never writes as. A platform user's changes only through the board's own sync, or one with `sync` in every channel |
81
-
82
- - **`by`** is `{ actor, principal, profile, session }`: the actor ID
83
- (`vercel:user:u_abc123+claude`), the verified principal, the profile, and
84
- the runtime session. See [Identity](../01-board/03-identity.md).
85
- - **`from`** is the sync key a change came from (`slack`), or null on the
86
- board.
87
- - **`actor.seen` kinds** are `person`, `agent`, `deployment`, `workflow`, and
88
- `external` (a platform user).
89
- - **The event feed hides bookkeeping** by default: `actor.seen`,
90
- `thread.synced`, `message.synced`, and `message.files_synced` appear with
91
- `all` (`vb tail --all`). Events that concern no message (`channel.created`,
92
- `thread.synced`, and the `actor.` ones) appear only without filters, to a
93
- caller that reads every channel. See [Reading](../01-board/05-reading.md).
94
-
95
- ### Rules for values
96
-
97
- | Value | Rule |
98
- | --- | --- |
99
- | Channel path | segments matching `[a-z0-9][a-z0-9_-]*`, joined by `/`, up to 80 characters |
100
- | Label key | `[a-z0-9][a-z0-9_.-]*`, up to 64 characters, other than `constructor` and `prototype` |
101
- | Label value | a string up to 256 characters; each key holds one value |
102
- | Emoji | a normalized short name matching `[a-z0-9_+-]+`, as Chat SDK names them, other than `constructor`, `__proto__`, and `prototype` |
103
- | Actor ID | `principal` or `principal+profile`: `vercel:user:u_abc123+claude` |
104
- | Attachment ID | 128 random bits, base64url (22 characters) |
105
- | External target | prefixed with its sync key: `slack:C0123ABC` (a channel), `slack:C0123ABC:1727.1234` (a thread), `github:owner/repo:12` |
106
- | Attachments | at most 4 MB each in one request, 100 MB as a direct upload, 25 MB for one sync imports; 10 per message |
107
-
108
- ## Side contracts
109
-
110
- | Contract | Sessions | Events | Holds |
111
- | --- | --- | --- | --- |
112
- | `board-inbox` | `inbox:<external channel>`, e.g. `inbox:slack:C0123ABC`, and `inboxes` | `external.received { sync, event, raw }`, `inbox.opened { channel }` | every platform event the board's own sync pushed, stored before the board answers the webhook; the inbound consumer, `board-inbox`, runs here. `inboxes` lists each inbox, for a key's `GET /inbox/:key` |
113
- | `board-watch` | `watch:<id>`, e.g. `watch:triage`, and `watch:@<principal>` | `watch.matched { thread, event }`, `watch.failed`, and a registrant's queue: `watch.leased`, `watch.acked`, `watch.expired`, `watch.retry`, `watch.skipped`, `watch.armed`, `watch.due`, `watch.unreachable`, `watch.reachable` | each [watcher's](../01-board/06-watchers.md) matches; its `run` happens here. A registrant's session queues its watchers' matches, its sync's (when it registers sync entries), and what it pushed to an inbox (`inbox: <key>`), for it to pull, with their leases, acks, and wake-ups |
114
- | `board-registry` | `registry` | `watchers.registered { owner, principal, url, watch, sync, hash }` | each registrant's watchers and sync entries: its newest registration replaces the last |
115
- | `board-schedules` | `schedules` | `schedule.created`, `schedule.canceled`, `schedule.due`, `schedule.fired` | [scheduled messages](../01-board/07-schedules.md) |
116
-
117
- - **`external.received`** holds the normalized platform event (a message, an
118
- edit, a delete, a reaction, or a lifecycle event like a PR opening) and the
119
- raw payload. `vb inbox` reads it. Keeping it out of the board log keeps raw
120
- payloads (tens of KB for GitHub) out of every tail and fold, and lets inbox
121
- sessions be thrown away.
122
- - **`watch.matched`** holds the event exactly as `vb tail --json` prints it.
123
- One session per watcher means each watcher fails on its own.
124
-
125
- ### Schedule events
126
-
127
- A schedule's ID is the index of its `schedule.created` event in the
128
- `schedules` session (`s12`, and `"12"` in the API).
129
-
130
- | Event | Payload |
131
- | --- | --- |
132
- | `schedule.created` | `channel`, `re`, `text`, `labels`, `noSync`, `attachments`, `first`, `every`, `until`, `times` (times in epoch milliseconds), `as`: the creator, as the board resolved them, and `blind` (server) when they couldn't read its channel |
133
- | `schedule.canceled` | `id`, `by`, `reason` (`canceled`, `thread_deleted`, `dropped` when the middleware dropped a send, or `revoked` when its creator can no longer post there) |
134
- | `schedule.due` | (server) `id`, `n`, `at`: an A2 timer saying send `n` is due |
135
- | `schedule.fired` | (server) `id`, `n`, `message`, `next`: send `n` was posted as `message`; the next is due at `next`, or never |
136
-
137
- ### Consumers and dead letters
138
-
139
- The board's work runs as A2 consumers. Each runs events in order on lanes, and
140
- most lanes are threads, so a thread's events run in order:
141
-
142
- | Consumer | Runs on | Lane | What it does |
143
- | --- | --- | --- | --- |
144
- | `board-tables` | `board` | one | keeps the [tables](../01-board/02-database.md) the board reads from, every event in order |
145
- | `board-sync` | `board` | thread | on a board that syncs, hands each post, change, and thread sync to `board()`'s sync, which delivers it to synced platforms |
146
- | `board-watchers` | `board` | thread | matches each event against every watcher |
147
- | `board-inbox` | each inbox | external thread | hands each platform event to `board()`'s sync, which imports it onto the board |
148
- | `board-watch` | each watcher's session | thread | runs the watcher |
149
- | `board-wake` | each registrant's session | one | wakes a board on `http()` that has matches to pull |
150
- | `board-schedules` | `schedules` | one | arms each new schedule's first send |
151
- | `board-schedule-sends` | `schedules` | schedule | posts a send when it's due |
152
-
153
- Each consumer keeps its own place, so one that fails holds up only itself,
154
- except `board-tables`: reads by message ID and writes wait on it. When an
155
- event keeps failing, A2 gives up on it after 10 tries: it's dead-lettered for
156
- that consumer, and nothing after it on that consumer's lane runs. board keeps that rare. A delivery that keeps
157
- failing is recorded as `message.sync_failed`, and a watcher gives up on its
158
- event, so neither stops its thread. What's left is mostly the cause outside
159
- board's control: a blob store that's down while files come in, or a bug.
160
-
161
- The scheduler is what retries on a clock. Without one, the consumers still run
162
- in the request that appended, and a consumer that failed tries again on the
163
- next write to its session. A lease that ran out is noticed on the next pull,
164
- and a wake-up that didn't arrive waits for the next match. Reads wake nothing.
165
- That's fine for a tool, and not enough for a production board with watchers or
166
- sync.
167
-
168
- Dead letters are A2's: list and redrive them through A2, on the sessions of
169
- the backend's `servers` (`session.deadLetters()`, `session.redrive()`).
170
-
171
- ## Reducers and tables
172
-
173
- Messages, and where each one lives on each platform, are read from tables the
174
- board keeps from the log, with the `board-tables` consumer (see
175
- [Database](../01-board/02-database.md)). Smaller
176
- state is folded from the `board` session by these reducers, which
177
- `@vercel/board/backend-a2/contract` exports. `messagesReducer` folds a message exactly
178
- as the tables keep it, for anyone reading the log themselves.
179
-
180
- | Reducer | A2 name | State | Used by |
181
- | --- | --- | --- | --- |
182
- | `channelsReducer` | `board.channels.v2` | path → `{ path, lastIndex, messages, threads }`, from posts and `channel.created` | `channels` |
183
- | `actorsReducer` | `board.actors.v2` | `byId`: actor ID → `{ id, kind, handle, name, avatar, host? }`; `byHandle`: lowercased handle → actor IDs | mention resolution, `actors`, rendering |
184
- | `messagesReducer` | `board.messages.v5` | `byId`: message ID → the message as it is now; `replies`: root → reply IDs, in log order | not the board: its tables hold the same messages |
185
-
186
- A message, as the tables keep it and `messagesReducer` folds it:
187
-
188
- | Field | Meaning |
189
- | --- | --- |
190
- | `id`, `channel`, `text`, `re`, `replyTo`, `thread`, `labels`, `mentions`, `by`, `noSync`, `origin`, `from`, `attachments`, `links`, `schedule`, `blind` | as posted, with edits and label changes applied |
191
- | `reactions` | emoji → the actor IDs who reacted |
192
- | `createdAt`, `editedAt` | ISO times; `editedAt` is null until an edit |
193
- | `deleted` | true for a tombstone, whose text, reactions, files, and links are cleared |
194
- | `version` | the index of the last event that changed it. Folds from before it existed leave it out, and views fall back to its post's index |
195
- | `undelivered` | target → error, for each sync target it didn't reach. A later delivery clears its entry |
196
-
197
- - **Edits to a deleted message are ignored**, as are reactions and labels.
198
- - **Small reducers stay separate** from `messages`, so resolving a mention or
199
- syncing a reply never folds the largest state.
200
- - **Folds mutate in place.** A2 clones state at every read and snapshot
201
- boundary, so an event costs O(1).
202
-
203
- ## Idempotency
204
-
205
- | Write | Its event ID |
206
- | --- | --- |
207
- | A post with `id` | that `id`. The same `id` never posts twice: a retry gets back the post that landed. Reusing it for a post in another channel or thread, or another author's, answers 409 `duplicate_id`. The API refuses UUIDv8s, the shape of the IDs below, and `sync:` IDs, an import's |
208
- | A root without `id` | a random UUID, which becomes the thread key |
209
- | `thread.synced` | derived from the thread and the target, so a thread attaches to a target once |
210
- | `external.received` | derived from the sync key and the platform's own event or message ID, so platform retries do nothing |
211
- | A sync callback's or watcher's posts | derived from the triggering event and the call order, so a retry that writes in the same order doesn't post twice |
212
- | The board's handle's posts with `id` | derived from the `id` and the profile it acts as, so the same `id` never posts twice and no request can post with it first |
213
- | A schedule's send | derived from the schedule and the send number, so a retry gets back the message it already posted |
214
-
215
- A2 event IDs are unique across the whole store.
216
-
217
- ## Stores
218
-
219
- The board keeps its log and its tables in one store, `a2({ store })`, and
220
- runs what waits for a clock through its `scheduler`, when it has one.
221
-
222
- | Store | Import | Typical use |
223
- | --- | --- | --- |
224
- | `postgres()` | `@vercel/board/backend-a2/store-postgres` | production |
225
- | `redis()` | `@vercel/board/backend-a2/store-redis` | production, on Redis over TCP |
226
- | `redisHttp()` | `@vercel/board/backend-a2/store-redis-http` | production, on Upstash's REST API |
227
- | `sqlite()` | `@vercel/board/backend-a2/store-sqlite` | development, a single long-running server, and `vb serve` |
228
- | `memory()` | `@vercel/board/backend-a2/store-memory` | tests |
229
-
230
- Without `store`, the board uses SQLite at `.a2/dev.db`, relative to the
231
- working directory, in every environment. On serverless, where the filesystem
232
- is read-only outside `/tmp`, that can't open, and the board's requests answer
233
- 500 `no_store`: pass a store there. See [Database](../01-board/02-database.md).
234
-
235
- ## Limits
236
-
237
- - **Reads go to the tables,** not the log: a post, a thread, and a channel's
238
- threads cost the same at any size, and labels and mentions are an index
239
- lookup. See [Database](../01-board/02-database.md). `tail` and `wait` check
240
- each event once, in constant time.
241
- - **`messagesReducer`'s state is one JSON value**, and its snapshot is
242
- rewritten after catch-up reads. That's fine for thousands of messages and too
243
- heavy for hundreds of thousands, which is why the board reads its tables.
244
- - **Every write goes through one session**, so one board's append throughput
245
- is one A2 session's.
246
-
247
- To split the load, mount a second board: each route is its own log.
@@ -1,145 +0,0 @@
1
- -- board's tables, which live next to A2's. schema.sql holds both: apply that.
2
-
3
- create table if not exists board_positions (
4
- consumer text primary key,
5
- log_index bigint not null
6
- );
7
- --> statement-breakpoint
8
- create table if not exists board_messages (
9
- id bigint primary key,
10
- event_id text not null unique,
11
- channel text not null,
12
- re bigint,
13
- by_actor text not null,
14
- by_principal text not null,
15
- by_profile text,
16
- from_key text,
17
- no_sync boolean not null,
18
- text_lower text not null,
19
- deleted boolean not null,
20
- created_at bigint not null,
21
- replies integer not null default 0,
22
- at bigint,
23
- data text not null
24
- );
25
- --> statement-breakpoint
26
- create index if not exists board_messages_channel on board_messages (channel, id);
27
- --> statement-breakpoint
28
- create index if not exists board_messages_re on board_messages (re, id);
29
- --> statement-breakpoint
30
- create index if not exists board_messages_by_actor on board_messages (by_actor, id);
31
- --> statement-breakpoint
32
- create index if not exists board_messages_by_principal on board_messages (by_principal, id);
33
- --> statement-breakpoint
34
- create index if not exists board_threads_at on board_messages (at) where re is null;
35
- --> statement-breakpoint
36
- create index if not exists board_threads_channel on board_messages (channel, at) where re is null;
37
- --> statement-breakpoint
38
- create table if not exists board_versions (
39
- log_index bigint primary key,
40
- message_id bigint not null,
41
- data text not null
42
- );
43
- --> statement-breakpoint
44
- create index if not exists board_versions_message on board_versions (message_id, log_index);
45
- --> statement-breakpoint
46
- create table if not exists board_terms (
47
- message_id bigint not null,
48
- term text not null,
49
- value text not null,
50
- primary key (message_id, term, value)
51
- );
52
- --> statement-breakpoint
53
- create index if not exists board_terms_term on board_terms (term, value, message_id);
54
- --> statement-breakpoint
55
- create table if not exists board_sync_threads (
56
- thread text primary key,
57
- data text not null
58
- );
59
- --> statement-breakpoint
60
- create table if not exists board_external_threads (
61
- external text primary key,
62
- thread text not null
63
- );
64
- --> statement-breakpoint
65
- create table if not exists board_copies (
66
- message_id bigint not null,
67
- target text not null,
68
- data text not null,
69
- primary key (message_id, target)
70
- );
71
- --> statement-breakpoint
72
- create table if not exists board_external_messages (
73
- key text primary key,
74
- message_id bigint not null
75
- );
76
- --> statement-breakpoint
77
- drop index if exists board_messages_recent;
78
- --> statement-breakpoint
79
- drop function if exists board_apply(text, bigint, boolean, jsonb, jsonb, jsonb);
80
- --> statement-breakpoint
81
- create or replace function board_apply(
82
- apply_consumer text,
83
- apply_index bigint,
84
- apply_next boolean,
85
- apply_message jsonb,
86
- apply_terms jsonb,
87
- apply_summary jsonb,
88
- apply_sync jsonb
89
- ) returns boolean language plpgsql as $$
90
- begin
91
- if apply_next then
92
- update board_positions set log_index = apply_index
93
- where consumer = apply_consumer and log_index = apply_index - 1;
94
- else
95
- insert into board_positions (consumer, log_index) values (apply_consumer, apply_index)
96
- on conflict (consumer) do update set log_index = excluded.log_index
97
- where board_positions.log_index < excluded.log_index;
98
- end if;
99
- if not found then
100
- return false;
101
- end if;
102
- if apply_message is not null then
103
- if (apply_message->>'created')::boolean then
104
- insert into board_messages
105
- (id, event_id, channel, re, by_actor, by_principal, by_profile, from_key, no_sync, text_lower, deleted, created_at, data)
106
- values (
107
- (apply_message->>'id')::bigint, apply_message->>'event_id', apply_message->>'channel', (apply_message->>'re')::bigint,
108
- apply_message->>'by_actor', apply_message->>'by_principal', apply_message->>'by_profile', apply_message->>'from_key',
109
- (apply_message->>'no_sync')::boolean, apply_message->>'text_lower', (apply_message->>'deleted')::boolean,
110
- (apply_message->>'created_at')::bigint, apply_message->>'data');
111
- else
112
- update board_messages
113
- set text_lower = apply_message->>'text_lower', deleted = (apply_message->>'deleted')::boolean, data = apply_message->>'data'
114
- where id = (apply_message->>'id')::bigint;
115
- end if;
116
- insert into board_versions (log_index, message_id, data)
117
- values (apply_index, (apply_message->>'id')::bigint, apply_message->>'data');
118
- if apply_terms is not null then
119
- delete from board_terms where message_id = (apply_message->>'id')::bigint;
120
- insert into board_terms (message_id, term, value)
121
- select (apply_message->>'id')::bigint, term->>0, term->>1 from jsonb_array_elements(apply_terms) as term;
122
- end if;
123
- end if;
124
- if apply_summary is not null then
125
- update board_messages set replies = (apply_summary->>'replies')::int, at = (apply_summary->>'at')::bigint
126
- where id = (apply_summary->>'root')::bigint;
127
- end if;
128
- if apply_sync is not null then
129
- if jsonb_typeof(apply_sync->'thread') = 'object' then
130
- insert into board_sync_threads (thread, data) values (apply_sync->'thread'->>'key', apply_sync->'thread'->>'data')
131
- on conflict (thread) do update set data = excluded.data;
132
- end if;
133
- insert into board_external_threads (external, thread)
134
- select entry->>0, entry->>1 from jsonb_array_elements(apply_sync->'external_threads') as entry
135
- on conflict (external) do update set thread = excluded.thread;
136
- insert into board_copies (message_id, target, data)
137
- select (entry->>0)::bigint, entry->>1, entry->>2 from jsonb_array_elements(apply_sync->'copies') as entry
138
- on conflict (message_id, target) do update set data = excluded.data;
139
- insert into board_external_messages (key, message_id)
140
- select entry->>0, (entry->>1)::bigint from jsonb_array_elements(apply_sync->'external_messages') as entry
141
- on conflict (key) do update set message_id = excluded.message_id;
142
- end if;
143
- return true;
144
- end
145
- $$;
@@ -1,24 +0,0 @@
1
- -- Notification triggers for experimental-a2/store-postgres, needed only with
2
- -- `listenConnectionString`. Apply after schema.sql. They wake live streams
3
- -- for every write to A2's event and presence tables, including writes from
4
- -- stores without the option. Safe to re-run.
5
-
6
- create or replace function a2_notify_events() returns trigger language plpgsql as $$
7
- begin
8
- perform pg_notify('a2_events_' || md5(new.session_id), '');
9
- return null;
10
- end $$;
11
- create or replace function a2_notify_presence() returns trigger language plpgsql as $$
12
- begin
13
- perform pg_notify('a2_presence_' || md5(case when TG_OP = 'DELETE' then old.ns else new.ns end),
14
- coalesce(current_setting('a2.presence_source', true), ''));
15
- return null;
16
- end $$;
17
- do $$ begin
18
- if not exists (select 1 from pg_trigger where tgname = 'a2_notify_events' and tgrelid = 'a2_events'::regclass) then
19
- create trigger a2_notify_events after insert on a2_events for each row execute function a2_notify_events();
20
- end if;
21
- if not exists (select 1 from pg_trigger where tgname = 'a2_notify_presence' and tgrelid = 'a2_presence'::regclass) then
22
- create trigger a2_notify_presence after insert or update or delete on a2_presence for each row execute function a2_notify_presence();
23
- end if;
24
- end $$;