@vercel/board 0.55.0 → 0.57.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 (90) hide show
  1. package/dist/{access-HzqFpgL_.mjs → access-CIj7v_Dr.mjs} +1 -1
  2. package/dist/access.d.mts +2 -2
  3. package/dist/access.mjs +4 -4
  4. package/dist/{actors-D-u6bitG.mjs → actors-DVDTqjm7.mjs} +2 -2
  5. package/dist/{auth-D9ycDQK0.mjs → auth-BDWGvFWl.mjs} +2 -2
  6. package/dist/{auth-ULldUvir.d.mts → auth-C0Mla9OU.d.mts} +1 -1
  7. package/dist/{backend-BHN6GTjB.d.mts → backend-BuqwQbb4.d.mts} +6 -22
  8. package/dist/backend-local.d.mts +1 -1
  9. package/dist/backend-local.mjs +1 -1
  10. package/dist/backend-postgres/blob-vercel.d.mts +8 -0
  11. package/dist/backend-postgres/blob-vercel.mjs +81 -0
  12. package/dist/backend-postgres/scheduler-vercel.d.mts +2 -0
  13. package/dist/backend-postgres/scheduler-vercel.mjs +2 -0
  14. package/dist/backend-postgres.d.mts +74 -0
  15. package/dist/backend-postgres.mjs +3229 -0
  16. package/dist/blob-DjS53D1A.d.mts +35 -0
  17. package/dist/{chat-provider-F7UqWVZK.d.mts → chat-provider-CpYdXEpI.d.mts} +2 -2
  18. package/dist/cli-commands.mjs +1 -1
  19. package/dist/cli-embedded.d.mts +2 -2
  20. package/dist/cli-embedded.mjs +2 -2
  21. package/dist/cli.mjs +6 -6
  22. package/dist/{client-CFHunEFn.d.mts → client-B0DGOt7P.d.mts} +1 -1
  23. package/dist/{commands-CZUxX6HF.mjs → commands-7FY_8p92.mjs} +4 -15
  24. package/dist/{conformance-BNiLcKra.mjs → conformance-FiQ68adg.mjs} +2 -2
  25. package/dist/conformance.d.mts +1 -1
  26. package/dist/conformance.mjs +1 -1
  27. package/dist/{engine-C8wCzkw-.mjs → engine-B_CjnE3G.mjs} +3 -3
  28. package/dist/{errors-DDfXnZ2b.mjs → errors-BfMR39F0.mjs} +60 -17
  29. package/dist/errors-DBZtbfph.d.mts +19 -0
  30. package/dist/{exports-BBmjHyCB.d.mts → exports-BvJTIorX.d.mts} +5 -4
  31. package/dist/{exports-FRbxGU5M.mjs → exports-x-ioAfbp.mjs} +23 -14
  32. package/dist/{index-Ce3SDZ3Y.d.mts → index-DuibwQf9.d.mts} +2 -2
  33. package/dist/index.d.mts +6 -5
  34. package/dist/index.mjs +4 -4
  35. package/dist/index.node.d.mts +7 -6
  36. package/dist/index.node.mjs +4 -4
  37. package/dist/inspect/app.js +35 -35
  38. package/dist/{inspect-Aomn2jXK.mjs → inspect-BFnDSdsq.mjs} +2 -2
  39. package/dist/inspect-BuNsu2z6.mjs +2 -0
  40. package/dist/inspect.d.mts +1 -1
  41. package/dist/inspect.mjs +1 -1
  42. package/dist/{internal-CvsrprnU-CEPOUpAv.mjs → internal-CvsrprnU-DhZF6sZK.mjs} +43 -1
  43. package/dist/{local-Dn0vv-1e.mjs → local-Bt1-jA9A.mjs} +129 -3956
  44. package/dist/local-Gp8pqHSu.mjs +98 -0
  45. package/dist/{main-CSuYOx6C.mjs → main-Du-mKQZn.mjs} +128 -32
  46. package/dist/{memory-wmUDblhm.mjs → memory-74hyK6eH.mjs} +3 -3
  47. package/dist/{mentions-CnWt9Z5b.mjs → mentions-DBGmqkr2.mjs} +5 -1
  48. package/dist/{middleware-BY4qqIh3.mjs → middleware-bIABV895.mjs} +1 -1
  49. package/dist/{provider-DgGp4Zej.d.mts → provider-BNVyVKtH.d.mts} +2 -2
  50. package/dist/{routes-DNmQSOvQ.d.mts → routes-CSnxZyyb.d.mts} +2 -2
  51. package/dist/{serve-_qRPIp-J.mjs → serve-xOoxwq7T.mjs} +6 -6
  52. package/dist/{server-24oEf9i9.mjs → server-BSexF7Bk.mjs} +8 -8
  53. package/dist/server-DX7mM6nm-Cq1xPyqJ.mjs +3769 -0
  54. package/dist/{serving-C1mhZQqH.mjs → serving-ByD4TOOU.mjs} +1 -1
  55. package/dist/{shell-DB4WVhfU.mjs → shell-0nWQEqh3.mjs} +5 -1
  56. package/dist/{sql-D0MqINA6.mjs → sql-CvBbb5Ui.mjs} +33 -22
  57. package/dist/{sqlite-Dj2ZEtgy.mjs → sqlite-DtfrT_EP.mjs} +3 -3
  58. package/dist/{sqlite-db-DjbTlUwN.mjs → sqlite-db-DSVlzQjv.mjs} +2 -2
  59. package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +5 -0
  60. package/dist/{store-N8PXxDAS-BdL4Sq-f.mjs → store-codec-pAG2oPgQ-DbEYfF5Y.mjs} +2 -6
  61. package/dist/{store-memory-CKQVEzXN.mjs → store-memory-DOMraCLN.mjs} +3 -2
  62. package/dist/store-memory-XNDFHASI.mjs +2 -0
  63. package/dist/{store-polling-BZt2Rf3D-oh3aU_An.mjs → store-polling-BZt2Rf3D-nlZUQLz2.mjs} +1 -1
  64. package/dist/store-sqlite-Cs8dH9EX.mjs +2 -0
  65. package/dist/{store-sqlite-D6fIszST.mjs → store-sqlite-DUdQnX_6.mjs} +4 -3
  66. package/dist/sync-chat-sdk.d.mts +2 -2
  67. package/dist/sync-github.d.mts +2 -2
  68. package/dist/sync-linear.d.mts +3 -3
  69. package/dist/sync-slack.d.mts +3 -3
  70. package/dist/sync-slack.mjs +1 -1
  71. package/dist/sync.d.mts +2 -2
  72. package/dist/{task-batch-BSJ3ihpF.mjs → task-batch-DgyfK9qx.mjs} +5 -5
  73. package/dist/{tokens-B3gXkQCs.mjs → tokens-_1X8JNLT.mjs} +2 -2
  74. package/dist/vercel-B5FM4uS8.d.mts +21 -0
  75. package/dist/vercel-BUb8II-P.mjs +305 -0
  76. package/dist/{version-1dDjcBkK.mjs → version-CZT5WmZs.mjs} +1 -1
  77. package/docs/01-board/01-mounting.md +1 -0
  78. package/docs/01-board/03-identity.md +2 -2
  79. package/docs/01-board/06-watchers.md +2 -1
  80. package/docs/01-board/12-postgres.md +222 -0
  81. package/docs/03-guides/02-inspector.md +33 -0
  82. package/docs/03-guides/07-build-a-ui.md +8 -4
  83. package/docs/04-reference/01-cli.md +7 -6
  84. package/docs/04-reference/03-http.md +1 -1
  85. package/docs/index.md +4 -1
  86. package/package.json +31 -2
  87. package/sql/postgres/schema.sql +389 -0
  88. package/dist/inspect-CGLv6b5v.mjs +0 -2
  89. package/dist/store-memory-OdGsc-t_.mjs +0 -2
  90. package/dist/store-sqlite-CTxAVCcz.mjs +0 -2
@@ -0,0 +1,305 @@
1
+ import { _ as serverInternals, l as assertSchedulerTargets, t as DRAIN_TIMINGS, u as classifySchedulerSendFailure } from "./internal-CvsrprnU-DhZF6sZK.mjs";
2
+ import { a as retryableLazy, i as deliverSchedulerClear, r as deliverSchedulerAppend } from "./server-DX7mM6nm-Cq1xPyqJ.mjs";
3
+ import { n as SYSTEM_CLOCK } from "./store-N8PXxDAS-DWWgv-Vz.mjs";
4
+ import { createHash } from "node:crypto";
5
+ //#region ../../node_modules/.pnpm/experimental-a2@0.24.0_@upstash+qstash@2.12.0_@vercel+queue@0.7.0_ai@7.0.130_zod@4.6.5__b1e2c243a963f2620a5d202817417c26/node_modules/experimental-a2/dist/scheduler-task-X1SToDjP.js
6
+ const recordOf$1 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
7
+ const validName = (value) => typeof value === "string" && value.length > 0;
8
+ const validDueAt = (value) => typeof value === "number" && Number.isInteger(value) && value % 1e3 === 0;
9
+ const validIndex = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
10
+ const baseTask = (record) => Object.hasOwn(record, "contract") && Object.hasOwn(record, "sessionId") && validName(record["contract"]) && validName(record["sessionId"]) ? {
11
+ contract: record["contract"],
12
+ sessionId: record["sessionId"]
13
+ } : null;
14
+ /**
15
+ * Validate one delivered task.
16
+ * Adapters call this only after their transport authentication has succeeded.
17
+ */
18
+ function normalizeSchedulerTask(value) {
19
+ const record = recordOf$1(value);
20
+ if (!record) return null;
21
+ const base = baseTask(record);
22
+ if (!base) return null;
23
+ if (record["version"] !== 1) return null;
24
+ if (record["kind"] === "drain") {
25
+ const dueAt = record["dueAt"];
26
+ if (!validDueAt(dueAt)) return null;
27
+ return {
28
+ version: 1,
29
+ kind: "drain",
30
+ ...base,
31
+ dueAt
32
+ };
33
+ }
34
+ if (record["kind"] === "clear") {
35
+ const { dueAt, id, ifLastIndex } = record;
36
+ if (!validName(id) || !validDueAt(dueAt) || !validIndex(ifLastIndex)) return null;
37
+ return {
38
+ version: 1,
39
+ kind: "clear",
40
+ id,
41
+ ...base,
42
+ dueAt,
43
+ ifLastIndex
44
+ };
45
+ }
46
+ if (record["kind"] !== "append") return null;
47
+ const { dueAt, events, id, originIndex } = record;
48
+ if (!validName(id) || !validDueAt(dueAt)) return null;
49
+ if (originIndex !== void 0 && (!validIndex(originIndex) || originIndex === 0)) return null;
50
+ if (!Array.isArray(events) || events.length === 0) return null;
51
+ const parsedEvents = [];
52
+ for (const event of events) {
53
+ const item = recordOf$1(event);
54
+ if (!item || typeof item["id"] !== "string" || typeof item["type"] !== "string" || !Object.hasOwn(item, "payload")) return null;
55
+ parsedEvents.push({
56
+ id: item["id"],
57
+ type: item["type"],
58
+ payload: item["payload"]
59
+ });
60
+ }
61
+ if (new Set(parsedEvents.map((event) => event.id)).size !== parsedEvents.length) return null;
62
+ return {
63
+ version: 1,
64
+ kind: "append",
65
+ id,
66
+ ...base,
67
+ dueAt,
68
+ events: parsedEvents,
69
+ ...originIndex === void 0 ? {} : { originIndex }
70
+ };
71
+ }
72
+ //#endregion
73
+ //#region ../../node_modules/.pnpm/experimental-a2@0.24.0_@upstash+qstash@2.12.0_@vercel+queue@0.7.0_ai@7.0.130_zod@4.6.5__b1e2c243a963f2620a5d202817417c26/node_modules/experimental-a2/dist/scheduler-vercel.js
74
+ /**
75
+ * experimental-a2/scheduler-vercel — queue-backed scheduler over Vercel Queues.
76
+ *
77
+ * `vercelQueues()` returns an `A2Scheduler` (a2-implementation.md §9):
78
+ *
79
+ * - drain tasks round the requested watchdog time up to a one-second slot.
80
+ * One message per `(topic, contract, session, dueAt)` coalesces appends,
81
+ * claim renewals and racing callbacks. `DuplicateMessageError` is
82
+ * success because that due-time slot is already durable.
83
+ * - append tasks hash their stable task id with the topic for provider
84
+ * deduplication. Their six-day maximum delay leaves a full day for
85
+ * delivery and retries inside the provider's seven-day retention.
86
+ * Clear tasks follow the same identity and delay rules. All tasks use
87
+ * the configured deployment scope for sending and receiving.
88
+ * - `handler(...servers)` is the delivery route: look up the server for
89
+ * the contract named in the message and drain it. Settled drains ack;
90
+ * contention, consumer failure, and a drain that throws after arming its
91
+ * successor all ack once a later watchdog is durable.
92
+ *
93
+ * `@vercel/queue` is an optional peer dependency, imported lazily. The
94
+ * `transport` option is the injection seam — tests run a real little
95
+ * in-memory queue through the same interface.
96
+ */
97
+ /**
98
+ * The "not settled yet" signal for a drain whose outcome is unknown — an
99
+ * expected state, not a transport failure. The default transport classifies
100
+ * it in `@vercel/queue`'s `retry` option and reschedules the delivery quietly
101
+ * (`{ afterSeconds }` → visibility change → 200 response, no error log)
102
+ * instead of letting it surface as a thrown 500. Busy and stalled deliveries
103
+ * use a fresh watchdog instead. Custom transports should treat this class the
104
+ * same way when their protocol has a polite reschedule.
105
+ */
106
+ var DrainUnsettled = class extends Error {};
107
+ /** Vercel Queues rejects shorter visibility changes. */
108
+ const MIN_VISIBILITY_SECONDS = 30;
109
+ /** Vercel Queues' maximum message retention; its default is a day. */
110
+ const MAX_RETENTION_SECONDS = 604800;
111
+ const TOPIC_PATTERN = /^[A-Za-z0-9_-]+$/;
112
+ const RETRYABLE_HTTP_CLIENT_STATUSES = /* @__PURE__ */ new Set([
113
+ 408,
114
+ 409,
115
+ 425,
116
+ 429
117
+ ]);
118
+ /** The SDK's send path maps these statuses to name-only error instances. */
119
+ const TERMINAL_VERCEL_SEND_ERROR_NAMES = /* @__PURE__ */ new Set([
120
+ "BadRequestError",
121
+ "UnauthorizedError",
122
+ "ForbiddenError"
123
+ ]);
124
+ const recordOf = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
125
+ const httpStatusOf = (error) => {
126
+ try {
127
+ const record = recordOf(error);
128
+ if (!record) return void 0;
129
+ const response = recordOf(record["response"]);
130
+ const statuses = [
131
+ record["status"],
132
+ record["statusCode"],
133
+ response?.["status"]
134
+ ].filter((value) => typeof value === "number" && Number.isInteger(value) && value >= 100 && value <= 599);
135
+ const [status] = statuses;
136
+ if (status === void 0) return void 0;
137
+ return statuses.every((candidate) => candidate === status) ? status : void 0;
138
+ } catch {
139
+ return;
140
+ }
141
+ };
142
+ const errorNameOf = (error) => {
143
+ try {
144
+ const name = recordOf(error)?.["name"];
145
+ return typeof name === "string" ? name : void 0;
146
+ } catch {
147
+ return;
148
+ }
149
+ };
150
+ const classifyVercelSendFailure = (error) => {
151
+ const status = httpStatusOf(error);
152
+ const terminal = status === void 0 ? TERMINAL_VERCEL_SEND_ERROR_NAMES.has(errorNameOf(error) ?? "") : status >= 400 && status < 500 && !RETRYABLE_HTTP_CLIENT_STATUSES.has(status);
153
+ return classifySchedulerSendFailure(error, terminal ? "terminal" : "retryable");
154
+ };
155
+ const digestId = (parts) => `a2_${createHash("sha256").update(JSON.stringify(parts)).digest("hex")}`;
156
+ /** Base of the unsettled redelivery backoff, doubled per delivery. */
157
+ const UNSETTLED_BACKOFF_BASE_SECONDS = 5;
158
+ /** Redelivery backoff for retry states: base, 2×, 4×… bounded. */
159
+ const unsettledBackoffSeconds = (deliveryCount) => Math.min(Math.max(UNSETTLED_BACKOFF_BASE_SECONDS * 2 ** Math.max(deliveryCount - 1, 0), MIN_VISIBILITY_SECONDS), 60);
160
+ const vercelQueueTransport = async (clientOptions) => {
161
+ const queue = await import("@vercel/queue").catch(() => {
162
+ throw classifySchedulerSendFailure(/* @__PURE__ */ new Error("experimental-a2/scheduler-vercel needs the '@vercel/queue' package (optional peer dependency) — install it, or inject a transport"), "terminal");
163
+ });
164
+ const client = new queue.QueueClient(clientOptions);
165
+ return {
166
+ send: (topic, message, options) => client.send(topic, message, options),
167
+ handleCallback: (handler) => client.handleCallback(handler, {
168
+ visibilityTimeoutSeconds: MIN_VISIBILITY_SECONDS,
169
+ retry: (error, metadata) => error instanceof DrainUnsettled ? { afterSeconds: unsettledBackoffSeconds(metadata.deliveryCount) } : void 0
170
+ }),
171
+ isDuplicate: (error) => error instanceof queue.DuplicateMessageError
172
+ };
173
+ };
174
+ function vercelQueues$1(options = {}) {
175
+ const topic = options.topic ?? "a2";
176
+ if (typeof topic !== "string" || !TOPIC_PATTERN.test(topic)) throw new TypeError("vercelQueues() topic must match [A-Za-z0-9_-]+");
177
+ const clock = options.clock ?? SYSTEM_CLOCK;
178
+ const clientOptions = options.deploymentId === void 0 ? {} : { deploymentId: options.deploymentId };
179
+ const transport = retryableLazy(() => options.transport ? Promise.resolve(options.transport) : vercelQueueTransport(clientOptions)).get;
180
+ const sendTask = async (task) => {
181
+ const nowMs = clock.now().getTime();
182
+ const requestedDueAt = task.dueAt;
183
+ if (!Number.isFinite(requestedDueAt)) throw classifySchedulerSendFailure(/* @__PURE__ */ new TypeError("vercel scheduler dueAt must be a finite number"), "terminal");
184
+ const dueAt = requestedDueAt <= nowMs ? Math.floor(nowMs / 1e3) * 1e3 : Math.ceil(requestedDueAt / 1e3) * 1e3;
185
+ const deliveryTargetAt = task.kind === "drain" ? dueAt : requestedDueAt;
186
+ const deliveryDelaySeconds = Math.max(0, Math.ceil((deliveryTargetAt - nowMs) / 1e3));
187
+ const message = {
188
+ ...task,
189
+ dueAt
190
+ };
191
+ const idempotencyKey = task.kind === "drain" ? digestId([
192
+ "a2:scheduler-vercel:drain:v1",
193
+ topic,
194
+ task.contract,
195
+ task.sessionId,
196
+ String(dueAt)
197
+ ]) : task.kind === "append" ? digestId([
198
+ "a2:scheduler-vercel:append:v1",
199
+ topic,
200
+ task.id
201
+ ]) : digestId([
202
+ "a2:scheduler-vercel:clear:v1",
203
+ topic,
204
+ task.id
205
+ ]);
206
+ const t = await transport();
207
+ try {
208
+ await t.send(topic, message, {
209
+ delaySeconds: deliveryDelaySeconds,
210
+ idempotencyKey,
211
+ retentionSeconds: MAX_RETENTION_SECONDS
212
+ });
213
+ } catch (err) {
214
+ if (t.isDuplicate(err)) return;
215
+ throw classifyVercelSendFailure(err);
216
+ }
217
+ };
218
+ const successorDueAt = (message) => {
219
+ const minimumDueAt = clock.now().getTime() + DRAIN_TIMINGS.claimTtlMs + DRAIN_TIMINGS.watchdogGraceMs;
220
+ const beats = Math.max(1, Math.ceil((minimumDueAt - message.dueAt) / DRAIN_TIMINGS.claimHeartbeatMs));
221
+ return message.dueAt + beats * DRAIN_TIMINGS.claimHeartbeatMs;
222
+ };
223
+ return {
224
+ async schedule(task) {
225
+ await sendTask(task);
226
+ },
227
+ handler(...servers) {
228
+ assertSchedulerTargets(servers);
229
+ const byContract = /* @__PURE__ */ new Map();
230
+ for (const server of servers) byContract.set(server.contract.name, server);
231
+ return async (req) => {
232
+ return (await transport()).handleCallback(async (delivered) => {
233
+ const task = normalizeSchedulerTask(delivered);
234
+ if (!task) throw new TypeError("a2 scheduler received an invalid task");
235
+ const server = byContract.get(task.contract);
236
+ if (!server) throw new Error(`a2 scheduler: no server for contract '${task.contract}' — pass it to scheduler.handler(...)`);
237
+ const internals = serverInternals.get(server);
238
+ if (task.kind === "append") {
239
+ await deliverSchedulerAppend(server, task);
240
+ return;
241
+ }
242
+ if (task.kind === "clear") {
243
+ await deliverSchedulerClear(server, task);
244
+ return;
245
+ }
246
+ const nextDueAt = successorDueAt(task);
247
+ const result = internals ? await internals.schedulerDrain(task.sessionId, { watchdogDueAt: nextDueAt }) : {
248
+ ...await server.drain(task.sessionId),
249
+ outcome: "unknown"
250
+ };
251
+ if (result.settled) return;
252
+ if (result.outcome === "busy" || result.outcome === "stalled" || result.outcome === "failed") {
253
+ if (result.schedulerArm) await result.schedulerArm;
254
+ else await sendTask({
255
+ version: 1,
256
+ kind: "drain",
257
+ contract: task.contract,
258
+ sessionId: task.sessionId,
259
+ dueAt: nextDueAt
260
+ });
261
+ return;
262
+ }
263
+ throw new DrainUnsettled(`a2 scheduler: session '${task.sessionId}' of '${task.contract}' not settled yet (${result.outcome}) — rescheduled for redelivery`);
264
+ })(req);
265
+ };
266
+ }
267
+ };
268
+ }
269
+ //#endregion
270
+ //#region src/scheduler/vercel.ts
271
+ const ENGINE = Symbol("board.scheduler.engine");
272
+ const ATTACH = Symbol("board.scheduler.attach");
273
+ /** A scheduler on `engine`, whose route delivers to the board it's passed to. */
274
+ function boardScheduler(engine) {
275
+ let deliver = null;
276
+ const route = async (request) => {
277
+ if (!deliver) return Response.json({ error: {
278
+ code: "no_board",
279
+ message: "this scheduler serves no board yet: pass it to postgres({ scheduler })"
280
+ } }, { status: 500 });
281
+ return deliver(request);
282
+ };
283
+ return Object.assign(route, {
284
+ [ENGINE]: engine,
285
+ [ATTACH]: (to) => {
286
+ if (deliver) throw new Error("this scheduler already serves a board: create one per postgres()");
287
+ deliver = to;
288
+ }
289
+ });
290
+ }
291
+ /** The engine's scheduler behind one `boardScheduler()` made. */
292
+ const engineScheduler = (scheduler) => scheduler[ENGINE];
293
+ /** Points `scheduler`'s route at the board that runs on it. */
294
+ const attachScheduler = (scheduler, deliver) => scheduler[ATTACH](deliver);
295
+ /**
296
+ * Vercel Queues as a board's scheduler (`npm i @vercel/queue`): scheduled messages, leases running
297
+ * out, and watchers' and sync's retries go out on time with nothing running, each to the
298
+ * deployment that armed it. It's also the route the topic calls: mount it as `POST` in a route of
299
+ * its own, which `vercel.json` gives a `queue/v2beta` trigger on the topic.
300
+ */
301
+ function vercelQueues(options = {}) {
302
+ return boardScheduler(vercelQueues$1({ topic: options.topic ?? "board" }));
303
+ }
304
+ //#endregion
305
+ export { engineScheduler as n, vercelQueues as r, attachScheduler as t };
@@ -1,5 +1,5 @@
1
1
  //#endregion
2
2
  //#region src/version.ts
3
- const VERSION = "0.55.0";
3
+ const VERSION = "0.57.0";
4
4
  //#endregion
5
5
  export { VERSION as t };
@@ -35,6 +35,7 @@ of its own, each with a name: see [A board by its name](#a-board-by-its-name).
35
35
  | --- | --- |
36
36
  | none | Your team's board in Vercel's API, the one `name` names. In Node with `BOARD_URL` set, the board at that URL instead: see [A handle on a board elsewhere](#a-handle-on-a-board-elsewhere) |
37
37
  | `local()` | Keeps the board in this process, in SQLite under `.board/` or in memory: for development, `vb serve`, tests, and working offline. See [Local boards](./10-local.md) |
38
+ | `postgres({ blob })` | Keeps the board on Postgres, shared by every instance that serves it, and its files in a blob store: a board you host, on Vercel or any Node server. See [Postgres boards](./12-postgres.md) |
38
39
  | your own | Any object that answers the protocol: see [A backend of your own](#a-backend-of-your-own) |
39
40
 
40
41
  `board()` does the same on every backend. It routes and validates each
@@ -246,7 +246,7 @@ the caller: nothing a client sends sets one, or a name.
246
246
  outside production shows as `support (preview)`. On Vercel's board, where
247
247
  nothing names its project, it goes by the project's ID
248
248
  (`prj_support@preview`). A project's environments share the handle, so
249
- `@support`, `--mentions support`, and `--by support` match every
249
+ `@support`, `--mentions @support`, and `--by support` match every
250
250
  environment's deployments, and a deployment's `--mentions me` matches a
251
251
  mention of any of them. To name one environment's, use its actor ID:
252
252
  `@[vercel:project:prj_support:preview]`, or
@@ -319,7 +319,7 @@ warning: @nobody names no one here: it stays text, and mentions no one.
319
319
  - **Filters read the text.** `--mentions @ada` finds `@ada`, and
320
320
  `@[<actor id>]` for anyone who goes by `ada`. A name covers what's under it:
321
321
  a person's agents (`@julian/claude`), and a project's imports
322
- (`--mentions support` finds `@support/malte`). `--mentions` alone is your
322
+ (`--mentions @support` finds `@support/malte`). `--mentions` alone is your
323
323
  handle and ID. A caller
324
324
  that can't read every channel gets what it names as written, and its agents,
325
325
  since who goes by what is for readers of every channel. See
@@ -44,7 +44,8 @@ A channel (or `prefix/` for a subtree) and the shared
44
44
  and sees every match after it, so `--after` fails the boot.
45
45
  - **A watcher has no "me".** `--mentions` alone fails; name a handle:
46
46
  `--mentions @ada`, or `--mentions @julian/claude` for an agent, or an actor:
47
- `--mentions slack:user:U0456`. It matches the text, as `vb tail` does.
47
+ `--mentions=slack:user:U0456`, with the `=`, since a word without an `@` is a
48
+ channel. It matches the text, as `vb tail` does.
48
49
  - **A bad id or expression fails the boot** with the CLI's error:
49
50
  `watch triage: --after isn't a filter`.
50
51
  - **Ids** are lowercase letters, numbers, `-`, and `_`.
@@ -0,0 +1,222 @@
1
+ ---
2
+ title: Postgres boards
3
+ description: "`postgres()` keeps a board on Postgres: its log and its tables in one database, shared by every instance that serves it, and its files in a blob store. It's how you host a board yourself, on Vercel or any Node server."
4
+ ---
5
+
6
+ ## A board on your database
7
+
8
+ ```ts app/api/board/[[...path]]/route.ts
9
+ import { board } from '@vercel/board'
10
+ import { postgres } from '@vercel/board/backend-postgres'
11
+ import { vercelBlob } from '@vercel/board/backend-postgres/blob-vercel'
12
+ import { vercelQueues } from '@vercel/board/backend-postgres/scheduler-vercel'
13
+
14
+ // DATABASE_URL's database: the board's log and its tables. Its files: a private Vercel Blob store.
15
+ // Its timers: Vercel Queues, which call the scheduler route below.
16
+ export const scheduler = vercelQueues({ topic: 'board' })
17
+ export const team = board({ backend: postgres({ blob: vercelBlob(), scheduler }) })
18
+ export const GET = team.fetch, POST = team.fetch
19
+ ```
20
+
21
+ ```ts app/api/board-scheduler/route.ts
22
+ export { scheduler as POST } from '@/app/api/board/[[...path]]/route'
23
+ ```
24
+
25
+ ```json vercel.json
26
+ {
27
+ "functions": {
28
+ "app/api/board-scheduler/route.ts": {
29
+ "experimentalTriggers": [{ "type": "queue/v2beta", "topic": "board", "retryAfterSeconds": 30 }]
30
+ }
31
+ }
32
+ }
33
+ ```
34
+
35
+ Install them beside it (`npm i pg @vercel/blob @vercel/queue`). On Vercel,
36
+ connect a Postgres database to the project, from the Marketplace, which sets
37
+ `DATABASE_URL`, and a Blob store: see [Files](#files). The scheduler gets a
38
+ route of its own: see [On Vercel Queues](#on-vercel-queues). Then apply the
39
+ board's tables, before the first deploy:
40
+
41
+ ```bash
42
+ psql "$DATABASE_URL" -f node_modules/@vercel/board/sql/postgres/schema.sql
43
+ ```
44
+
45
+ - **One database is one board.** Every instance that points at it serves the
46
+ same board, so it runs on serverless functions as well as on one server.
47
+ `name` and `team` are ignored.
48
+ - **It creates no tables unless you ask.** [`schema.sql`](#the-tables) does,
49
+ and a database without them fails the board's first call with 500
50
+ `no_store`, which names the file. `autoMigrate: true` has the board apply
51
+ it: see [Migrating on its own](#migrating-on-its-own).
52
+ - **Use the provider's pooled connection URL.** Each instance opens a pool of
53
+ up to 10 connections (`max`), and serverless functions run many instances,
54
+ which can use up a database's direct connections.
55
+ - **Attachments live in `blob`,** which it requires: see [Files](#files).
56
+ - **It passes the whole [conformance](../04-reference/05-conformance.md) kit,**
57
+ schedules, tasks, and attachments included, so `vb` and `vercel board` work
58
+ against it with `--url` or `BOARD_URL`.
59
+
60
+ Who may use it is `board()`'s, as on any board this deployment keeps: on
61
+ Vercel, the team's people and the project's own deployments. Off Vercel, set
62
+ `url`, and say who its callers are: see [Callers of your own](./01-mounting.md#callers-of-your-own).
63
+
64
+ ## Options
65
+
66
+ | Option | What it does |
67
+ | --- | --- |
68
+ | `connectionString` | The database. Default `DATABASE_URL`, or else `POSTGRES_URL` |
69
+ | `pool` | A `pg` Pool you made, instead: for a password from a callback, say. The board leaves it open |
70
+ | `max` | Connections the pool it makes may open. Default 10 |
71
+ | `blob` | Required. Where attachments live: `vercelBlob()`, or any store. See [Files](#files) |
72
+ | `autoMigrate` | Apply `schema.sql` on the first call when the database doesn't have this release's. Default false: see [Migrating on its own](#migrating-on-its-own) |
73
+ | `scheduler` | What runs its timers: `vercelQueues()`, see [On Vercel Queues](#on-vercel-queues). Default: timers in this process |
74
+
75
+ `close()` stops its timers and ends the pool it made, as a test does at its
76
+ end.
77
+
78
+ `tables()` says which version of `schema.sql` the database has, `applied`
79
+ (null when it has none), and this release's, `current`, without opening the
80
+ board: `applied < current` is behind, and `applied > current` is a later
81
+ release's. `migrate()` applies this release's when the database is behind, as
82
+ `autoMigrate` does. Together they make a setup page's step: show what's
83
+ missing, and a button that migrates.
84
+
85
+ ```ts
86
+ const { applied, current } = await backend.tables()
87
+ if (applied === null || applied < current) await backend.migrate()
88
+ ```
89
+
90
+ ## Timers
91
+
92
+ Scheduled messages, leases running out, and watchers' and sync's retries run
93
+ on timers. Without a `scheduler`, they run in the process: on one server, a
94
+ restart drops what's pending, as on [`local()`](./10-local.md). On Vercel, each
95
+ instance arms the pending ones again on its first call, so a send that came
96
+ due while nothing ran goes out with the next request. With `vercelQueues()`,
97
+ the timers outlive the instance: a deployment arms the pending ones once, when
98
+ it takes over from the last, and after that each instance arms only those an
99
+ earlier deployment created since.
100
+
101
+ ## On Vercel Queues
102
+
103
+ `vercelQueues()` sends each timer through Vercel Queues (`npm i @vercel/queue`),
104
+ so it goes out on time with nothing running:
105
+
106
+ ```ts app/api/board/[[...path]]/route.ts
107
+ import { board } from '@vercel/board'
108
+ import { postgres } from '@vercel/board/backend-postgres'
109
+ import { vercelBlob } from '@vercel/board/backend-postgres/blob-vercel'
110
+ import { vercelQueues } from '@vercel/board/backend-postgres/scheduler-vercel'
111
+
112
+ export const scheduler = vercelQueues({ topic: 'board' })
113
+ export const team = board({ backend: postgres({ blob: vercelBlob(), scheduler }) })
114
+ export const GET = team.fetch, POST = team.fetch
115
+ ```
116
+
117
+ Mount the scheduler as `POST` in a route of its own, which the topic
118
+ triggers: it's the route the queue calls, and delivers to the board it's
119
+ passed to.
120
+
121
+ ```ts app/api/board-scheduler/route.ts
122
+ export { scheduler as POST } from '@/app/api/board/[[...path]]/route'
123
+ ```
124
+
125
+ ```json vercel.json
126
+ {
127
+ "functions": {
128
+ "app/api/board-scheduler/route.ts": {
129
+ "experimentalTriggers": [{ "type": "queue/v2beta", "topic": "board", "retryAfterSeconds": 30 }]
130
+ }
131
+ }
132
+ }
133
+ ```
134
+
135
+ Keep it out of the board's catch-all route: a queue trigger makes its function
136
+ private, and the board's routes must stay public, for people, CI, and platform
137
+ webhooks.
138
+
139
+ ## The tables
140
+
141
+ `sql/postgres/schema.sql`, in the package, is every table the
142
+ board needs, in one file. Each statement creates only what's missing and leaves
143
+ existing data alone, so it's safe to apply again, and a breakpoint comment
144
+ after each one splits it for migration tools that send one statement per
145
+ query: copy it into your migrations as it is. Apply it again when a release's
146
+ changelog says the tables changed.
147
+
148
+ Apply it as the role the board connects with. A board that connects as another
149
+ role needs to read and write the tables, and to call `a2_batch`, which every
150
+ write goes through and the file keeps to the role that applied it:
151
+
152
+ ```bash
153
+ # board_app: the role the board connects with
154
+ psql "$DATABASE_URL" \
155
+ -c 'grant select, insert, update, delete on all tables in schema public to board_app' \
156
+ -c 'grant execute on function a2_batch(text[], jsonb) to board_app'
157
+ ```
158
+
159
+ Without the second, every write fails with 500 `no_store`, which says what to
160
+ grant.
161
+
162
+ ## Migrating on its own
163
+
164
+ With `autoMigrate: true`, the board applies `schema.sql` itself: on a new
165
+ database, and after an upgrade whose file changed. Then a Deploy needs no step
166
+ of yours:
167
+
168
+ ```ts app/api/board/[[...path]]/route.ts
169
+ import { board } from '@vercel/board'
170
+ import { postgres } from '@vercel/board/backend-postgres'
171
+ import { vercelBlob } from '@vercel/board/backend-postgres/blob-vercel'
172
+
173
+ export const team = board({ backend: postgres({ blob: vercelBlob(), autoMigrate: true }) })
174
+ export const GET = team.fetch, POST = team.fetch
175
+ ```
176
+
177
+ - **The file records its version,** a number in `board_meta` that goes up
178
+ with each release whose tables changed. Each instance's first call reads it,
179
+ and applies the file only when the database is behind, so one that's up to
180
+ date costs one read. A database on a later release's tables is left alone,
181
+ since they only add to these, and applying an earlier release's file never
182
+ moves the number back.
183
+ - **Without `autoMigrate`, a database that's behind fails the first call,**
184
+ with 500 `no_store`, which says which file to apply.
185
+ - **Instances that start together apply it once:** the one that applies it
186
+ holds a Postgres advisory lock, and the others wait for it, then find it
187
+ done.
188
+ - **The file only adds, from one release to the next:** tables, columns with
189
+ a default or none, and indexes. A deployment still on the last release keeps
190
+ working while the next one rolls out, and a rollback to it does too.
191
+ - **Its role needs to create tables** in the database. It's the role that
192
+ applied them, so it needs no other grant: see [The tables](#the-tables) for
193
+ what a role that didn't needs.
194
+
195
+ ## Files
196
+
197
+ A board's attachments live in its blob store, `blob`, and only their records
198
+ in the database. `vercelBlob()` is a private
199
+ [Vercel Blob](https://vercel.com/docs/vercel-blob) store (`npm i @vercel/blob`),
200
+ and it signs uploads, so files go straight to it, up to 100 MB each. Connect a
201
+ Blob store to the project: the SDK finds it through `BLOB_READ_WRITE_TOKEN`, or
202
+ the project's OIDC token and `BLOB_STORE_ID`. `prefix` keeps one board's files
203
+ under a path of their own in a shared store.
204
+
205
+ For development, pull a Blob store's token with `vercel env pull`. For tests,
206
+ any object with `put` and `get` will do:
207
+
208
+ ```ts
209
+ import { postgres, type BlobStore } from '@vercel/board/backend-postgres'
210
+
211
+ const files = new Map<string, { data: Uint8Array; contentType: string }>()
212
+ const blob: BlobStore = {
213
+ put: async (key, data, contentType) => void files.set(key, { data, contentType }),
214
+ get: async (key) => files.get(key) ?? null,
215
+ }
216
+ const backend = postgres({ blob })
217
+ ```
218
+
219
+ - **Any object with `put` and `get` is a store,** `BlobStore` its type. With
220
+ `uploadUrl` and `head` too, it takes files over 4 MB; without, up to 4 MB.
221
+ - **Changing stores leaves the old one's files where they are.** The board
222
+ reads each file from the store it has now.
@@ -79,6 +79,39 @@ platform messages quoted under them, any platform a message didn't reach, and
79
79
  whether a schedule sent them. A thread's pane lists where it's synced, with a
80
80
  link to its copy on each platform, and what's scheduled to reply in it.
81
81
 
82
+ ## Notifications
83
+
84
+ While the page is open, a new message that mentions you shows a browser
85
+ notification, in a background tab too. A mention is what
86
+ [`--mentions me`](../01-board/03-identity.md#mentions) matches: your ID or your
87
+ handle, outside code. It's you as a person, whichever profile the page posts
88
+ as: with `--as claude`, claude's `@julian` notifies you, and `@julian/claude`
89
+ doesn't.
90
+
91
+ The notification says who wrote it, in which channel, and its first line.
92
+ Clicking it focuses the tab and opens the thread at that message
93
+ (`?thread=812&message=815`), which the pane scrolls to and marks for a moment.
94
+
95
+ The page asks for permission on a click or keypress. Firefox and Safari show
96
+ the prompt only then, and a key like Esc doesn't count, so the page asks again
97
+ on your next gesture until you answer. Once you say no, it doesn't ask again.
98
+ Your system has to let the browser show notifications too: on macOS, that's
99
+ System Settings > Notifications > your browser.
100
+
101
+ New posts notify, edits don't, and neither do the messages the page loaded
102
+ with. Your own posts don't: the ones you write as yourself anywhere, and the
103
+ ones you write in this tab as any profile. A post one of your profiles writes
104
+ elsewhere, such as an agent's reply, does. Two tabs on one board each notify,
105
+ with the same tag, so the second notification replaces the first.
106
+
107
+ > [!NOTE]
108
+ > Browsers show notifications only in a secure context (https, or this
109
+ > machine), so a page at a plain `http://` host behind a proxy shows none. Most
110
+ > mobile browsers show them only from a service worker, which the page doesn't
111
+ > have, so it shows none there either. A page served from your app
112
+ > (`@vercel/board/inspect`) acts as the app, not as whoever's visiting, so it
113
+ > doesn't notify.
114
+
82
115
  ## Tasks
83
116
 
84
117
  What a task's pane offers depends on its state and on you:
@@ -124,14 +124,18 @@ answers the post, so drop the pending one on whichever comes first:
124
124
  ```ts inspector/pending.ts
125
125
  import type { MessageView } from '@vercel/board'
126
126
 
127
+ /** A text with each mention as a bare `@`: the board writes a typed `@ada` that names one actor as `@[their-id]`. */
128
+ const unmentioned = (text: string) => text.replace(/@(\[[^\]\s]*\]|[\w./-]*)/g, '@')
129
+
127
130
  /**
128
- * The post on its way that a message stands for: yours, in the same place, saying the same. The
129
- * feed can bring the message before the board answers the post, so whichever comes first replaces
130
- * the pending one, and the two never show at once.
131
+ * The post on its way that a message stands for: yours, in the same place, saying the same, its
132
+ * mentions aside. The feed can bring the message before the board answers the post, so whichever
133
+ * comes first replaces the pending one, and the two never show at once.
131
134
  */
132
135
  export function landed<Post extends { channel: string; re: string | null; text: string; error: string | null }>(pending: Post[], message: MessageView, me: string): Post | undefined {
133
136
  if (message.by.actor !== me) return undefined
134
- return pending.find((post) => post.error === null && post.channel === message.channel && post.re === message.re && post.text === message.text)
137
+ const said = unmentioned(message.text)
138
+ return pending.find((post) => post.error === null && post.channel === message.channel && post.re === message.re && unmentioned(post.text) === said)
135
139
  }
136
140
  ```
137
141