@vercel/board 0.39.0 → 0.41.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 (100) hide show
  1. package/README.md +6 -4
  2. package/dist/{access-CVkjSfxj.mjs → access-C5HaO42b.mjs} +2 -2
  3. package/dist/access.d.mts +6 -6
  4. package/dist/access.mjs +5 -5
  5. package/dist/actors-nrOf7Y7z.mjs +160 -0
  6. package/dist/{auth-BXLCkeB0.d.mts → auth-Bn8J_1F2.d.mts} +14 -29
  7. package/dist/{auth-B3bBYOqf.mjs → auth-DAlYi6TN.mjs} +9 -19
  8. package/dist/{backend-HcCCGPG4.d.mts → backend-CYsTLxtP.d.mts} +139 -43
  9. package/dist/backend-local.d.mts +1 -1
  10. package/dist/backend-local.mjs +1 -1
  11. package/dist/blocks-CVoBC7ur.mjs +402 -0
  12. package/dist/blocks-DGvh2alZ.d.mts +33 -0
  13. package/dist/{chat-provider-1WKsLEnM.mjs → chat-provider-CPZg2MQb.mjs} +2 -2
  14. package/dist/{chat-provider-DyNy5xdC.d.mts → chat-provider-Cgkh9xJw.d.mts} +2 -2
  15. package/dist/cli-commands.d.mts +1 -1
  16. package/dist/cli-commands.mjs +1 -1
  17. package/dist/cli-embedded.d.mts +3 -3
  18. package/dist/cli-embedded.mjs +4 -4
  19. package/dist/cli.mjs +8 -13
  20. package/dist/{commands-B5d-lmNN.d.mts → commands-CrEVjASe.d.mts} +14 -26
  21. package/dist/{commands-BLS7erNu.mjs → commands-QRD0U9AQ.mjs} +114 -105
  22. package/dist/{conformance-D59Py2m2.mjs → conformance-ClxEEZ9C.mjs} +378 -101
  23. package/dist/conformance.d.mts +11 -9
  24. package/dist/conformance.mjs +1 -1
  25. package/dist/data-values-C-Cq80hz.mjs +176 -0
  26. package/dist/digest-Dna1CGa_.mjs +4 -0
  27. package/dist/{engine-eUgO5jTM.mjs → engine-8BcNeckB.mjs} +197 -84
  28. package/dist/{errors-rYDxZEuN.mjs → errors-DcQf5WeM.mjs} +123 -42
  29. package/dist/{events-C6HwB046.mjs → events-BT8y_81j.mjs} +2 -2
  30. package/dist/{exports-M5o4PTfO.mjs → exports-B6udRV_E.mjs} +961 -383
  31. package/dist/exports-C8zsIL1A.d.mts +4 -0
  32. package/dist/{external-CHDxWIVf.mjs → external-DymyhUzl.mjs} +1 -1
  33. package/dist/{index-rNqqgkyu.d.mts → index-fcpEFCTR.d.mts} +2 -2
  34. package/dist/index.d.mts +7 -6
  35. package/dist/index.mjs +8 -6
  36. package/dist/index.node.d.mts +7 -6
  37. package/dist/index.node.mjs +5 -4
  38. package/dist/inspect/app.js +110 -109
  39. package/dist/inspect/engine.js +5 -5
  40. package/dist/inspect-BsF3mYMY.mjs +2 -0
  41. package/dist/{inspect-BkXxR2uB.mjs → inspect-DPRoC_Gg.mjs} +6 -6
  42. package/dist/{local-DvkOWf4U.mjs → local-B9y4p6N7.mjs} +463 -512
  43. package/dist/{main-DtV_Po9i.mjs → main-S0A-c_kP.mjs} +549 -178
  44. package/dist/{memory-DkoqhxIH.mjs → memory-DhduVbUu.mjs} +2 -2
  45. package/dist/{mentions-CB6ShY4R.mjs → mentions-DfZGp3B-.mjs} +18 -4
  46. package/dist/{middleware-CPqAuRtp.mjs → middleware-DHdrxmoc.mjs} +71 -3
  47. package/dist/{targets-C1mT3M1N.mjs → origin-B3m2lnZC.mjs} +43 -64
  48. package/dist/{page-64IwoGRu.mjs → page-2jjHZmIW.mjs} +2 -2
  49. package/dist/page-CAUe4GmQ.mjs +2 -0
  50. package/dist/{provider-D5yVFisj.d.mts → provider-dY54GFNz.d.mts} +20 -34
  51. package/dist/{routes-BffuaoTX.d.mts → routes-By9lmvUD.d.mts} +91 -77
  52. package/dist/{schemas-AZkxk06N.mjs → schemas-DAzSsgWk.mjs} +8 -3
  53. package/dist/schemas.d.mts +37 -0
  54. package/dist/schemas.mjs +3 -0
  55. package/dist/{serve-CX1rqDF_.mjs → serve-B15I2Ibf.mjs} +5 -5
  56. package/dist/{server-DkYkyarg.mjs → server-DgpRZ4Nu.mjs} +74 -127
  57. package/dist/{serving-DJMcG0dT.mjs → serving-CALKWs9K.mjs} +1 -1
  58. package/dist/{sql-l3ysn4O5.mjs → sql-P9g-rLIF.mjs} +75 -12
  59. package/dist/{sqlite-CAwNHbQD.mjs → sqlite-B3rCcIof.mjs} +2 -2
  60. package/dist/{sqlite-db-cm5yhrD-.mjs → sqlite-db-D0Fyju-4.mjs} +1 -1
  61. package/dist/sync-chat-sdk.d.mts +2 -2
  62. package/dist/sync-chat-sdk.mjs +2 -2
  63. package/dist/sync-github.d.mts +2 -2
  64. package/dist/sync-github.mjs +2 -2
  65. package/dist/sync-linear.d.mts +3 -3
  66. package/dist/sync-linear.mjs +2 -2
  67. package/dist/sync-slack.d.mts +14 -8
  68. package/dist/sync-slack.mjs +46 -19
  69. package/dist/sync.d.mts +2 -2
  70. package/dist/sync.mjs +2 -2
  71. package/dist/{tokens-DA9ipsZ-.mjs → tokens-D7_ZIWpX.mjs} +4 -4
  72. package/docs/01-board/01-mounting.md +13 -16
  73. package/docs/01-board/03-identity.md +112 -74
  74. package/docs/01-board/04-messages.md +61 -2
  75. package/docs/01-board/05-reading.md +11 -5
  76. package/docs/01-board/06-watchers.md +17 -13
  77. package/docs/01-board/07-schedules.md +8 -6
  78. package/docs/01-board/08-middleware.md +1 -1
  79. package/docs/01-board/09-access.md +80 -132
  80. package/docs/02-sync/01-overview.md +75 -4
  81. package/docs/02-sync/02-functions.md +11 -6
  82. package/docs/02-sync/03-slack.md +43 -19
  83. package/docs/02-sync/06-providers.md +9 -4
  84. package/docs/03-guides/01-coding-agents.md +18 -22
  85. package/docs/03-guides/02-inspector.md +4 -5
  86. package/docs/03-guides/03-ci.md +7 -26
  87. package/docs/03-guides/04-triage.md +2 -2
  88. package/docs/03-guides/05-agent-factory.md +7 -9
  89. package/docs/03-guides/06-sandboxed-agents.md +149 -0
  90. package/docs/04-reference/01-cli.md +161 -104
  91. package/docs/04-reference/02-board.md +89 -37
  92. package/docs/04-reference/03-http.md +176 -71
  93. package/docs/04-reference/05-conformance.md +47 -21
  94. package/docs/index.md +5 -5
  95. package/package.json +5 -1
  96. package/dist/actors-kfMejhaw.mjs +0 -156
  97. package/dist/digest-krhjNAt4.mjs +0 -4
  98. package/dist/exports-vLQ2Y2Nd.d.mts +0 -4
  99. package/dist/inspect-lnv1sLXM.mjs +0 -2
  100. package/dist/page-BUj8_UZv.mjs +0 -2
@@ -1,8 +1,8 @@
1
- import { d as createBoardClient, t as HttpError, u as BoardError } from "./errors-rYDxZEuN.mjs";
2
- import "./schemas-AZkxk06N.mjs";
3
- import { X as routes, l as METHODS, o as compileWatcher } from "./targets-C1mT3M1N.mjs";
4
- import { l as keyId, o as DERIVED_ID } from "./middleware-CPqAuRtp.mjs";
5
- import { a as tailWatchers, o as deployedOnVercel, r as createVercel, t as createBoard } from "./exports-M5o4PTfO.mjs";
1
+ import { d as createBoardClient, p as formatProfileHeader, t as HttpError, u as BoardError } from "./errors-DcQf5WeM.mjs";
2
+ import "./schemas-DAzSsgWk.mjs";
3
+ import { Y as routes, a as compileWatcher, c as METHODS } from "./origin-B3m2lnZC.mjs";
4
+ import { g as keyId, p as DERIVED_ID } from "./middleware-DHdrxmoc.mjs";
5
+ import { a as PROTOCOL_ROUTES, c as deployedOnVercel, o as withoutToken, r as createVercel, s as tailWatchers, t as createBoard } from "./exports-B6udRV_E.mjs";
6
6
  import { execFile } from "node:child_process";
7
7
  import { createHash } from "node:crypto";
8
8
  import { mkdir, readFile, readdir, stat, unlink, writeFile } from "node:fs/promises";
@@ -74,49 +74,11 @@ function localToken(url) {
74
74
  if (!LOOPBACK.has(new URL(url).hostname)) return null;
75
75
  const saved = JSON.parse(readFileSync(localTokenFile(url), "utf8"));
76
76
  if (saved.url !== url.replace(/\/+$/, "") || typeof saved.token !== "string") return null;
77
- return {
78
- token: saved.token,
79
- handle: saved.handle ?? null
80
- };
77
+ return { token: saved.token };
81
78
  } catch {
82
79
  return null;
83
80
  }
84
81
  }
85
- /** fx, Claude Code, Codex, and Grok sessions select their own profile, like Just Chat's CLI. */
86
- function detectAgent(env = process.env) {
87
- const found = [];
88
- if (env.AI_AGENT?.trim().toLowerCase() === "fx") found.push({
89
- profile: "fx",
90
- session: env.FX_SESSION_ID || null
91
- });
92
- if (env.CLAUDECODE === "1" || env.CLAUDE_CODE_SESSION_ID) found.push({
93
- profile: "claude",
94
- session: env.CLAUDE_CODE_SESSION_ID || null
95
- });
96
- if (env.CODEX_THREAD_ID || env.CODEX_SESSION_ID) found.push({
97
- profile: "codex",
98
- session: env.CODEX_THREAD_ID || env.CODEX_SESSION_ID || null
99
- });
100
- if (env.GROK_SESSION_ID) found.push({
101
- profile: "grok",
102
- session: env.GROK_SESSION_ID
103
- });
104
- if (env.CURSOR_AGENT === "1") found.push({
105
- profile: "cursor",
106
- session: null
107
- });
108
- if (env.PI_CODING_AGENT === "true" || env.AI_AGENT === "pi") found.push({
109
- profile: "pi",
110
- session: env.PI_SESSION_ID || null
111
- });
112
- const named = env.AI_AGENT?.trim().toLowerCase();
113
- if (named && /^[a-z][a-z0-9-]{0,31}$/.test(named) && !found.some((agent) => agent.profile === named)) found.push({
114
- profile: named,
115
- session: null
116
- });
117
- if (found.length > 1) throw new BoardError("ambiguous_agent", `Several coding agents' environments are set (${found.map((a) => a.profile).join(", ")}), so it can't tell which one is writing.`, 0, { hint: "Pick one with a profile, or none to write as yourself." });
118
- return found[0] ?? null;
119
- }
120
82
  const expiry = (token) => {
121
83
  try {
122
84
  const { exp } = decodeJwt(token);
@@ -197,7 +159,7 @@ const loginHanded = () => handed$1 !== null || !!process.env.VERCEL_AUTH_TOKEN;
197
159
  */
198
160
  const vercelLogin = () => handed$1 ? handed$1() : process.env.VERCEL_AUTH_TOKEN ? Promise.resolve(process.env.VERCEL_AUTH_TOKEN) : getVercelToken();
199
161
  /**
200
- * A handed login's token, which its board tokens are cached by: null for `vercel login`'s own. One
162
+ * A handed login's token, which its tokens for boards are cached by: null for `vercel login`'s own. One
201
163
  * that fails fails the request: `vercel login`'s, cached or in the `vercel` on PATH, can be someone
202
164
  * else's.
203
165
  */
@@ -219,17 +181,6 @@ const apiLogin = async (handed) => handed ?? await getVercelToken().catch(() =>
219
181
  async function personToken(audience, discovery) {
220
182
  const login = await handedToken();
221
183
  const cached = await readCache(audience, login);
222
- if (cached && cached.name === void 0) {
223
- const authToken = await apiLogin(login);
224
- const user = authToken ? await vercelUser(authToken) : null;
225
- const filled = {
226
- ...cached,
227
- name: user?.name ?? null,
228
- avatar: user?.avatar ?? null
229
- };
230
- await writeCache(audience, login, filled).catch(() => {});
231
- return filled;
232
- }
233
184
  if (cached) return cached;
234
185
  if (!discovery.project_id) throw new BoardError("no_project", `The board at ${audience} doesn't know its Vercel project, so there's no Vercel login token to mint for it.`, 0, { hint: "Pass a token it accepts in BOARD_TOKEN." });
235
186
  const authToken = await apiLogin(login);
@@ -249,13 +200,9 @@ async function personToken(audience, discovery) {
249
200
  token: development,
250
201
  audience
251
202
  });
252
- const user = authToken ? await vercelUser(authToken) : null;
253
203
  const fresh = {
254
204
  token,
255
- expiresAt: expiry(token),
256
- handle: user?.handle ?? null,
257
- name: user?.name ?? null,
258
- avatar: user?.avatar ?? null
205
+ expiresAt: expiry(token)
259
206
  };
260
207
  await writeCache(audience, login, fresh).catch(() => {});
261
208
  return fresh;
@@ -301,21 +248,6 @@ async function tokenFromVercelCli(project) {
301
248
  throw new BoardError("not_logged_in", "You're not logged in to Vercel.", 0, { hint: "Run vercel login." });
302
249
  }
303
250
  }
304
- /** Your Vercel username, display name, and avatar (Vercel serves avatars publicly). */
305
- async function vercelUser(authToken) {
306
- try {
307
- const response = await asYou("https://api.vercel.com/v2/user", {}, authToken);
308
- if (!response.ok) return null;
309
- const { user } = await response.json();
310
- return {
311
- handle: user?.username?.toLowerCase() ?? null,
312
- name: user?.name?.trim() || null,
313
- avatar: user?.avatar && /^[0-9a-f]+$/i.test(user.avatar) ? `https://vercel.com/api/www/avatar/${user.avatar}?s=128` : null
314
- };
315
- } catch {
316
- return null;
317
- }
318
- }
319
251
  async function githubActionsToken(audience) {
320
252
  const url = new URL(process.env.ACTIONS_ID_TOKEN_REQUEST_URL);
321
253
  url.searchParams.set("audience", audience);
@@ -332,8 +264,8 @@ function boardUrl() {
332
264
  /**
333
265
  * How a client reaches the board at `url` from Node: through Deployment Protection, with a token
334
266
  * from `token`, `BOARD_TOKEN`, a local board's token file (`vb serve`), GitHub Actions, the Vercel
335
- * runtime, or your Vercel CLI login, in that order. `handle` is yours, in place of `BOARD_HANDLE`
336
- * or your Vercel username.
267
+ * runtime, or your Vercel CLI login, in that order. Who you are is the token's to say: the board
268
+ * names you from what it verifies.
337
269
  */
338
270
  function connect(url, options = {}) {
339
271
  url = url.replace(/\/+$/, "");
@@ -372,10 +304,7 @@ function connect(url, options = {}) {
372
304
  source = "vb serve";
373
305
  return {
374
306
  token: local.token,
375
- expiresAt: expiry(local.token),
376
- handle: local.handle,
377
- name: null,
378
- avatar: null
307
+ expiresAt: expiry(local.token)
379
308
  };
380
309
  }
381
310
  const discovered = await discover();
@@ -413,12 +342,6 @@ function connect(url, options = {}) {
413
342
  const headers = new Headers(init.headers ?? (input instanceof Request ? input.headers : void 0));
414
343
  if (!(method === "GET" && path === "/")) {
415
344
  if (!headers.has("authorization")) headers.set("authorization", `Bearer ${await token()}`);
416
- const handle = options.handle ?? (process.env.BOARD_HANDLE || (options.token === void 0 ? cached?.handle : null));
417
- if (handle && !headers.has("x-board-handle")) headers.set("x-board-handle", handle);
418
- if (!headers.has("x-board-profile") && options.token === void 0) {
419
- if (cached?.name && !headers.has("x-board-name")) headers.set("x-board-name", encodeURIComponent(cached.name));
420
- if (cached?.avatar && !headers.has("x-board-avatar")) headers.set("x-board-avatar", cached.avatar);
421
- }
422
345
  }
423
346
  return doFetch(input, {
424
347
  ...init,
@@ -430,18 +353,18 @@ function connect(url, options = {}) {
430
353
  source: () => source
431
354
  };
432
355
  }
433
- /** The profile the environment picks: `BOARD_AS`, or the coding agent it runs in, with its session. */
356
+ /**
357
+ * The profile the environment names: `BOARD_PROFILE`, with `BOARD_AVATAR`. Nothing else picks one, a coding
358
+ * agent included: without it, you write as yourself.
359
+ */
434
360
  function environmentProfile() {
435
- const detected = detectAgent();
436
- const name = process.env.BOARD_AS || detected?.profile;
361
+ if (process.env.BOARD_AS) throw new BoardError("renamed_env", "BOARD_AS is BOARD_PROFILE now, and nothing reads BOARD_AS.", 0, { hint: "Set BOARD_PROFILE to the same name, and unset BOARD_AS." });
362
+ const name = process.env.BOARD_PROFILE;
437
363
  const avatar = process.env.BOARD_AVATAR;
438
- return {
439
- profile: name ? avatar ? {
440
- name,
441
- avatar
442
- } : name : null,
443
- session: detected?.session ?? null
444
- };
364
+ return name ? avatar ? {
365
+ name,
366
+ avatar
367
+ } : name : null;
445
368
  }
446
369
  const WHERE = "Project → Settings → Deployment Protection → Protection Bypass for Automation";
447
370
  var Wall = class extends Error {
@@ -481,6 +404,29 @@ const ownHost = (host) => [
481
404
  process.env.VERCEL_BRANCH_URL,
482
405
  process.env.VERCEL_PROJECT_PRODUCTION_URL
483
406
  ].some((own) => !!own && own.toLowerCase() === host.toLowerCase());
407
+ /**
408
+ * What a sandbox's requests to the board at `url` carry, from this deployment: `token`, or this
409
+ * deployment's own Vercel OIDC token, for `audience` (the board's URL; null for Vercel's API, which
410
+ * takes it as it is), and on a board behind Deployment Protection what a hosted client sends to get
411
+ * through it: this deployment's bypass secret on its own hosts, or else its OIDC token for Trusted
412
+ * Sources. Never a person's login or `VERCEL_TOKEN`: what a policy holds, its sandbox can use.
413
+ */
414
+ async function sandboxHeaders(url, audience, token) {
415
+ const oidc = async () => {
416
+ try {
417
+ return await getVercelOidcToken(audience === null ? void 0 : { audience });
418
+ } catch (cause) {
419
+ throw Object.assign(new BoardError("no_token", `There's no Vercel OIDC token here to hand a sandbox for ${url}.`, 0, { hint: "Run it in a Vercel deployment with OIDC, or pass the credential: sandboxPolicy({ token })." }), { cause });
420
+ }
421
+ };
422
+ const credential = token ?? await oidc();
423
+ const headers = { authorization: `Bearer ${credential}` };
424
+ if (audience === null) return headers;
425
+ const bypass = process.env.VERCEL_AUTOMATION_BYPASS_SECRET;
426
+ if (bypass && (process.env.VERCEL !== "1" || ownHost(new URL(url).host))) headers["x-vercel-protection-bypass"] = bypass;
427
+ else if (process.env.VERCEL === "1") headers["x-vercel-trusted-oidc-idp-token"] = credential;
428
+ return headers;
429
+ }
484
430
  /** Explicit bypass wins; otherwise hosted calls use OIDC and local people use their saved bypass. */
485
431
  function guarded(url, doFetch, suppliedToken) {
486
432
  const host = new URL(url).host;
@@ -507,16 +453,13 @@ function guarded(url, doFetch, suppliedToken) {
507
453
  envRejected = true;
508
454
  }
509
455
  if (process.env.VERCEL === "1") {
510
- let edgeless = false;
511
456
  if (!headers.has("x-vercel-trusted-oidc-idp-token")) {
512
457
  const token = headers.get("authorization")?.match(/^Bearer (.+)$/i)?.[1] ?? (typeof suppliedToken === "function" ? await suppliedToken() : suppliedToken) ?? (process.env.BOARD_TOKEN || await hostedToken(url));
513
- const edge = token.startsWith("board_") ? await hostedToken(url).catch(() => null) : token;
514
- if (edge === null) edgeless = true;
515
- else headers.set("x-vercel-trusted-oidc-idp-token", edge);
458
+ headers.set("x-vercel-trusted-oidc-idp-token", token);
516
459
  }
517
460
  return through(doFetch, input, init, null).catch((error) => {
518
461
  if (!(error instanceof Wall)) throw error;
519
- throw edgeless ? new BoardError("protected", `${url} is behind Vercel Deployment Protection, and this deployment has no Vercel OIDC token to get through it.`, error.status, { hint: "Enable OIDC on its project, and add it to the board project's Deployment Protection Trusted Sources." }) : new BoardError("protected", `${url} is behind Vercel Deployment Protection, and it rejected this deployment's Vercel OIDC token.`, error.status, { hint: "Add this project and environment to the board project's Deployment Protection Trusted Sources." });
462
+ throw new BoardError("protected", `${url} is behind Vercel Deployment Protection, and it rejected this deployment's Vercel OIDC token.`, error.status, { hint: "Add this project and environment to the board project's Deployment Protection Trusted Sources." });
520
463
  });
521
464
  }
522
465
  const used = await (secret ??= readBypass(host));
@@ -756,23 +699,21 @@ function createHttp(url, options, environment) {
756
699
  return binding;
757
700
  };
758
701
  /**
759
- * The SDK against the remote, as this deployment with `profile`. `quiet` names no session: this
760
- * deployment's own code. Otherwise a profile chosen in code keeps the environment's session, and
761
- * yourself (`null`) has none. Who the token's holder is, `fetch` says.
702
+ * The SDK against the remote, as this deployment with `profile`, or the environment's for
703
+ * `undefined`. Who the token's holder is, `fetch` says.
762
704
  */
763
- const sdk = (profile, quiet) => createBoardClient({
705
+ const sdk = (profile) => createBoardClient({
764
706
  url: remote,
765
707
  fetch: doFetch,
766
- profile: profile !== void 0 ? profile : () => environment?.profile().profile ?? null,
767
- session: quiet || profile === null ? null : () => environment?.profile().session ?? null
708
+ profile: profile !== void 0 ? profile : () => environment?.profile() ?? null
768
709
  });
769
- const own = sdk(null, true);
710
+ const own = sdk(null);
770
711
  const profiles = /* @__PURE__ */ new Map();
771
712
  /** This deployment as `profile`: a watcher's ID, or the middleware. */
772
713
  function asProfile(profile) {
773
714
  if (!PROFILE.test(profile)) throw new HttpError(400, "invalid_request", `as: ${profile}: profiles start with a letter and use up to 32 letters, numbers, and hyphens`);
774
715
  let client = profiles.get(profile);
775
- if (!client) profiles.set(profile, client = sdk(profile, true));
716
+ if (!client) profiles.set(profile, client = sdk(profile));
776
717
  return client;
777
718
  }
778
719
  const holders = /* @__PURE__ */ new Map();
@@ -780,7 +721,7 @@ function createHttp(url, options, environment) {
780
721
  function holder(profile) {
781
722
  const key = JSON.stringify(profile ?? (profile === null ? null : "\0"));
782
723
  let client = holders.get(key);
783
- if (!client) holders.set(key, client = sdk(profile, false));
724
+ if (!client) holders.set(key, client = sdk(profile));
784
725
  return client;
785
726
  }
786
727
  /**
@@ -906,6 +847,18 @@ function createHttp(url, options, environment) {
906
847
  ...methods,
907
848
  routes: [],
908
849
  keeps: false,
850
+ async sandbox({ profile, can, token }) {
851
+ const credential = environment ? await environment.sandbox(remote, token) : token === void 0 ? withoutToken(remote) : { authorization: `Bearer ${token}` };
852
+ return {
853
+ url: remote,
854
+ headers: {
855
+ ...credential,
856
+ "x-board-profile": formatProfileHeader(profile),
857
+ "x-board-can": can
858
+ },
859
+ routes: PROTOCOL_ROUTES
860
+ };
861
+ },
909
862
  bind(next) {
910
863
  if (binding) throw new Error("http: this backend already serves a board: create one http() per board()");
911
864
  for (const [id, spec] of Object.entries(next.subscriptions)) {
@@ -932,7 +885,8 @@ function createHttp(url, options, environment) {
932
885
  const environment$1 = {
933
886
  url: boardUrl,
934
887
  fetch: (url) => connect(url).fetch,
935
- profile: environmentProfile
888
+ profile: environmentProfile,
889
+ sandbox: (url, token) => sandboxHeaders(url, url, token)
936
890
  };
937
891
  /**
938
892
  * The board at `url`, which keeps the log: this board uses it as this deployment. Without a
@@ -947,17 +901,10 @@ function http(url, options = {}) {
947
901
  /** On Vercel, or with its OIDC token pulled (`vercel env pull`): a deployment acts as its project. */
948
902
  const deployed = () => process.env.VERCEL === "1" || !!process.env.VERCEL_OIDC_TOKEN;
949
903
  /**
950
- * A token you set for the board: it goes as `Authorization: Bearer <token>`, as it is, whatever its
951
- * format (that's Vercel's API's), ahead of every other, as it does to a board at a URL.
952
- */
953
- const boardToken = () => process.env.BOARD_TOKEN || null;
954
- /**
955
- * A token Vercel's API takes: `BOARD_TOKEN`, `VERCEL_TOKEN`, this deployment's OIDC token, or your
956
- * Vercel login, the one the CLI that runs board's hands it (`vercel board`'s) or your `vercel login`.
904
+ * A token Vercel's API takes: `VERCEL_TOKEN`, this deployment's OIDC token, or your Vercel login,
905
+ * the one the CLI that runs board's hands it (`vercel board`'s) or your `vercel login`.
957
906
  */
958
907
  async function token() {
959
- const given = boardToken();
960
- if (given) return given;
961
908
  if (process.env.VERCEL_TOKEN) return process.env.VERCEL_TOKEN;
962
909
  if (deployed()) return getVercelOidcToken();
963
910
  return vercelLogin().catch(() => {
@@ -969,7 +916,6 @@ async function token() {
969
916
  }
970
917
  /** Where `token` comes from, in words: what `vb whoami` says. */
971
918
  function credentialSource() {
972
- if (boardToken()) return "BOARD_TOKEN";
973
919
  if (process.env.VERCEL_TOKEN) return "VERCEL_TOKEN";
974
920
  if (deployed()) return "Vercel OIDC";
975
921
  return loginHanded() ? "the Vercel CLI" : "vercel login";
@@ -1010,7 +956,7 @@ async function team() {
1010
956
  const environment = {
1011
957
  fetch: () => async (input, init = {}) => {
1012
958
  const credential = await token();
1013
- if (!boardToken() && !process.env.VERCEL_TOKEN && !deployed()) return asYou(input, init, credential);
959
+ if (!process.env.VERCEL_TOKEN && !deployed()) return asYou(input, init, credential);
1014
960
  const headers = new Headers(init.headers);
1015
961
  headers.set("authorization", `Bearer ${credential}`);
1016
962
  return globalThis.fetch(input, {
@@ -1020,7 +966,7 @@ const environment = {
1020
966
  },
1021
967
  team,
1022
968
  profile: environmentProfile,
1023
- boardToken: () => boardToken() !== null
969
+ sandbox: (url, token) => sandboxHeaders(url, null, token)
1024
970
  };
1025
971
  /** The fetch `vercel()` sends by default, with the credentials it finds: for the CLI to add a header of its own to. */
1026
972
  const credentialed = () => environment.fetch();
@@ -1042,8 +988,9 @@ function vercel(options = {}) {
1042
988
  function board(options = {}) {
1043
989
  return createBoard(options, {
1044
990
  backend: (fetch) => process.env.BOARD_URL?.trim() ? http() : vercel(fetch ? { fetch } : {}),
1045
- sync: () => import("./engine-eUgO5jTM.mjs"),
1046
- serving: () => import("./serving-DJMcG0dT.mjs")
991
+ sync: () => import("./engine-8BcNeckB.mjs"),
992
+ serving: () => import("./serving-CALKWs9K.mjs"),
993
+ sandbox: (url, token) => sandboxHeaders(url, url, token)
1047
994
  });
1048
995
  }
1049
996
  //#endregion
@@ -1,2 +1,2 @@
1
- import { i as ownTeamId, n as discoveryIdentity, r as ownProjectId, t as oidcTokens } from "./tokens-DA9ipsZ-.mjs";
1
+ import { i as ownTeamId, n as discoveryIdentity, r as ownProjectId, t as oidcTokens } from "./tokens-D7_ZIWpX.mjs";
2
2
  export { discoveryIdentity, oidcTokens, ownProjectId, ownTeamId };
@@ -1,7 +1,8 @@
1
- import { _ as actorKind } from "./schemas-AZkxk06N.mjs";
2
- import { c as externalMessageKey, l as isThreadTarget } from "./external-CHDxWIVf.mjs";
1
+ import { _ as actorKind } from "./schemas-DAzSsgWk.mjs";
2
+ import { c as externalMessageKey, l as isThreadTarget } from "./external-DymyhUzl.mjs";
3
3
  import { t as canonicalEmoji } from "./emoji-CTLpvH-A.mjs";
4
4
  import { n as setOwn, t as own } from "./own-OwgPWdmh.mjs";
5
+ import { i as mentionTerms } from "./mentions-DfZGp3B-.mjs";
5
6
  //#region src/contract/folds.ts
6
7
  const iso = (date) => typeof date === "string" ? date : date.toISOString();
7
8
  function foldMessages(state, event) {
@@ -24,7 +25,6 @@ function foldMessage(state, event) {
24
25
  thread: payload.thread,
25
26
  labels: { ...payload.labels },
26
27
  reactions: {},
27
- mentions: payload.mentions,
28
28
  by: payload.by,
29
29
  noSync: payload.noSync,
30
30
  origin: payload.origin,
@@ -46,8 +46,9 @@ function foldMessage(state, event) {
46
46
  const message = state.byId[event.payload.id];
47
47
  if (!message || message.deleted) return void 0;
48
48
  message.text = event.payload.text;
49
- message.mentions = event.payload.mentions;
50
49
  message.editedAt = iso(event.createdAt);
50
+ if (message.from === null && event.payload.from !== null) message.platformText = true;
51
+ else delete message.platformText;
51
52
  return message;
52
53
  }
53
54
  case "message.deleted": {
@@ -57,7 +58,6 @@ function foldMessage(state, event) {
57
58
  message.text = "";
58
59
  message.reactions = {};
59
60
  message.labels = {};
60
- message.mentions = [];
61
61
  message.attachments = [];
62
62
  message.links = [];
63
63
  return message;
@@ -115,7 +115,7 @@ function foldMessage(state, event) {
115
115
  /** Who's who: `actor.seen`. */
116
116
  function foldActors(state, event) {
117
117
  if (event.type !== "actor.seen") return state;
118
- const { actor, kind, handle, name, avatar, host } = event.payload;
118
+ const { actor, kind, handle, name, avatar, via, platform, host, verified } = event.payload;
119
119
  const previous = own(state.byId, actor);
120
120
  if (previous) {
121
121
  const key = previous.handle.toLowerCase();
@@ -129,7 +129,10 @@ function foldActors(state, event) {
129
129
  handle,
130
130
  name,
131
131
  avatar,
132
- ...host || previous?.host ? { host: true } : {}
132
+ ...via ? { via: { ...via } } : {},
133
+ ...platform ? { platform } : {},
134
+ ...host || previous?.host ? { host: true } : {},
135
+ ...verified ? { verified: true } : {}
133
136
  });
134
137
  const key = handle.toLowerCase();
135
138
  const ids = own(state.byHandle, key) ?? setOwn(state.byHandle, key, []);
@@ -214,7 +217,7 @@ function concernedMessageId(event) {
214
217
  }
215
218
  const termsOf = (message) => JSON.stringify([
216
219
  message.labels,
217
- message.mentions,
220
+ mentionTerms(message.text),
218
221
  message.attachments.map((file) => file.id)
219
222
  ]);
220
223
  /**
@@ -384,9 +387,12 @@ function ddl() {
384
387
  key text primary key,
385
388
  message_id integer not null
386
389
  )`,
387
- "drop index if exists board_messages_recent"
390
+ "drop index if exists board_messages_recent",
391
+ "create table if not exists board_meta (\n key text primary key,\n value text not null\n)"
388
392
  ];
389
393
  }
394
+ /** `board_meta`'s key for the mention index taken from each message's text. */
395
+ const MENTION_TERMS = "mention_terms";
390
396
  /**
391
397
  * The board refuses NUL in text and a lone surrogate, and a log from before
392
398
  * that may hold them. Nothing a reader filters on needs either, so keys and
@@ -394,7 +400,10 @@ function ddl() {
394
400
  * that find them do the same.
395
401
  */
396
402
  const clean = (value) => value.replaceAll("\0", "").toWellFormed();
397
- /** A mention's term. Label keys start with a letter or digit, so it's never a label's. */
403
+ /**
404
+ * A mention's term, each one as the text has it (`mentionTerms`). Label keys start with a letter or
405
+ * digit, so it's never a label's.
406
+ */
398
407
  const MENTION = "@";
399
408
  /** An attachment's term, the same way. */
400
409
  const ATTACHMENT = "^";
@@ -432,7 +441,14 @@ function clauses(filter, p) {
432
441
  const either = [...actors.length ? [`m.by_actor in (${p.list(actors)})`] : [], ...principals.length ? [`m.by_principal in (${p.list(principals)})`] : []];
433
442
  out.push(either.length ? `(${either.join(" or ")})` : "1 = 0");
434
443
  }
435
- if (filter.mentions) out.push(filter.mentions.length ? `exists (select 1 from board_terms t where t.message_id = m.id and t.term = '${MENTION}' and t.value in (${p.list(filter.mentions)}))` : "1 = 0");
444
+ if (filter.mentions) {
445
+ const { terms, prefixes } = filter.mentions;
446
+ const either = [...terms.length ? [`t.value in (${p.list(terms)})`] : [], ...prefixes.map((prefix) => {
447
+ const at = `cast(${p.add(prefix)} as text)`;
448
+ return `substr(t.value, 1, length(${at})) = ${at}`;
449
+ })];
450
+ out.push(either.length ? `exists (select 1 from board_terms t where t.message_id = m.id and t.term = '${MENTION}' and (${either.join(" or ")}))` : "1 = 0");
451
+ }
436
452
  if (filter.from !== void 0) out.push(`coalesce(m.from_key, 'board') = ${p.add(filter.from)}`);
437
453
  if (filter.text !== void 0) out.push(`m.text_lower like ${p.add(`%${likeEscape(filter.text)}%`)} escape '\\'`);
438
454
  for (const label of filter.labels ?? []) {
@@ -444,6 +460,51 @@ function clauses(filter, p) {
444
460
  const parse = (row) => row === void 0 || row.data === null || row.data === void 0 ? null : JSON.parse(String(row.data));
445
461
  /** The tables on a SQL database. */
446
462
  function sqlTables(db) {
463
+ /**
464
+ * Tables from before mentions were text index a message's mentions as the actor IDs its write
465
+ * resolved them to. Once per database, each message whose text has an `@` gets the terms its
466
+ * text has instead, unless a writer changed its text in between, which reindexed it already.
467
+ * A read that filters on mentions waits for it.
468
+ */
469
+ async function reindexMentions() {
470
+ if ((await db.all({
471
+ text: "select 1 from board_meta where key = $1",
472
+ values: [MENTION_TERMS]
473
+ })).length > 0) return;
474
+ const rows = await db.all({
475
+ text: "select id, data from board_messages where text_lower like '%@%'",
476
+ values: []
477
+ });
478
+ const writes = [];
479
+ for (const row of rows) {
480
+ const message = parse(row);
481
+ const unchanged = "json_extract((select data from board_messages where id = $1), '$.text') = $2";
482
+ writes.push({
483
+ text: `delete from board_terms where message_id = $1 and term = '${MENTION}' and ${unchanged}`,
484
+ values: [message.id, message.text]
485
+ });
486
+ for (const term of mentionTerms(message.text)) writes.push({
487
+ text: `insert or ignore into board_terms (message_id, term, value) select $1, '${MENTION}', $3 where ${unchanged}`,
488
+ values: [
489
+ message.id,
490
+ message.text,
491
+ clean(term)
492
+ ]
493
+ });
494
+ }
495
+ await db.commit({
496
+ text: "insert into board_meta (key, value) values ($1, 'text') on conflict (key) do nothing returning 1 as claimed",
497
+ values: [MENTION_TERMS]
498
+ }, writes);
499
+ }
500
+ let reindexed = null;
501
+ const mentionsReady = () => {
502
+ reindexed ??= reindexMentions().catch((error) => {
503
+ reindexed = null;
504
+ throw error;
505
+ });
506
+ return reindexed;
507
+ };
447
508
  const positionSql = {
448
509
  text: "select log_index from board_positions where consumer = $1",
449
510
  values: [TABLES_CONSUMER]
@@ -555,7 +616,7 @@ function sqlTables(db) {
555
616
  },
556
617
  terms: m && change.message.terms ? [
557
618
  ...Object.entries(m.labels).map(([key, value]) => [key, clean(value)]),
558
- ...[...new Set(m.mentions)].map((actor) => [MENTION, clean(actor)]),
619
+ ...mentionTerms(m.text).map((term) => [MENTION, clean(term)]),
559
620
  ...[...new Set(m.attachments.map((file) => file.id))].map((id) => [ATTACHMENT, clean(id)])
560
621
  ] : null,
561
622
  summary: change.summary ?? null,
@@ -715,6 +776,7 @@ where v.message_id in (${p.list([...new Set(ids)])})
715
776
  })).map((found) => parse(found));
716
777
  },
717
778
  async messages(filter, page) {
779
+ if (filter.mentions) await mentionsReady();
718
780
  const p = new Params();
719
781
  const where = clauses(filter, p);
720
782
  if (page.before !== void 0) where.push(`m.id < ${p.add(page.before)}`);
@@ -732,6 +794,7 @@ where v.message_id in (${p.list([...new Set(ids)])})
732
794
  };
733
795
  },
734
796
  async threads(filter, page) {
797
+ if (filter.mentions) await mentionsReady();
735
798
  const [positions, rows] = await db.read([positionSql, threadsQuery(filter, page)]);
736
799
  const threads = rows.map((found) => ({
737
800
  root: parse(found),
@@ -1,6 +1,6 @@
1
- import { r as sqlTables } from "./sql-l3ysn4O5.mjs";
1
+ import { r as sqlTables } from "./sql-P9g-rLIF.mjs";
2
2
  import { t as sqlite$1 } from "./store-sqlite-D6fIszST.mjs";
3
- import { t as sqliteDb } from "./sqlite-db-cm5yhrD-.mjs";
3
+ import { t as sqliteDb } from "./sqlite-db-D0Fyju-4.mjs";
4
4
  //#region src/store/sqlite.ts
5
5
  /**
6
6
  * A local board in one SQLite file, its log and board's tables side by side. It
@@ -1,4 +1,4 @@
1
- import { n as ddl } from "./sql-l3ysn4O5.mjs";
1
+ import { n as ddl } from "./sql-P9g-rLIF.mjs";
2
2
  import { mkdirSync } from "node:fs";
3
3
  import { dirname, resolve } from "node:path";
4
4
  //#region src/store/sqlite-db.ts
@@ -1,5 +1,5 @@
1
- import { b as channels, g as SyncFn, p as SyncProvider } from "./provider-D5yVFisj.mjs";
2
- import { r as ChatTransport, t as ChatInput } from "./chat-provider-DyNy5xdC.mjs";
1
+ import { _ as SyncFn, m as SyncProvider, x as channels } from "./provider-dY54GFNz.mjs";
2
+ import { r as ChatTransport, t as ChatInput } from "./chat-provider-Cgkh9xJw.mjs";
3
3
  import { z } from "zod";
4
4
  import { ReactionEvent } from "chat";
5
5
  //#region src/sync/chat-sdk.d.ts
@@ -1,5 +1,5 @@
1
- import { f as channels, i as eventSchema, r as envelope } from "./events-C6HwB046.mjs";
2
- import { t as ChatSyncProvider } from "./chat-provider-1WKsLEnM.mjs";
1
+ import { f as channels, i as eventSchema, r as envelope } from "./events-BT8y_81j.mjs";
2
+ import { t as ChatSyncProvider } from "./chat-provider-CPZg2MQb.mjs";
3
3
  import { createHash } from "node:crypto";
4
4
  //#region src/sync/chat-sdk.ts
5
5
  const schemaOf = (platform) => eventSchema(platform, "message");
@@ -1,5 +1,5 @@
1
- import { f as SyncContext, g as SyncFn, y as SyncUnit } from "./provider-D5yVFisj.mjs";
2
- import { n as ChatSyncProvider } from "./chat-provider-DyNy5xdC.mjs";
1
+ import { _ as SyncFn, b as SyncUnit, p as SyncContext } from "./provider-dY54GFNz.mjs";
2
+ import { n as ChatSyncProvider } from "./chat-provider-Cgkh9xJw.mjs";
3
3
  import { z } from "zod";
4
4
  import { Adapter } from "chat";
5
5
  //#region src/sync/github.d.ts
@@ -1,5 +1,5 @@
1
- import { g as withRoutes, i as eventSchema, p as into, r as envelope } from "./events-C6HwB046.mjs";
2
- import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-1WKsLEnM.mjs";
1
+ import { g as withRoutes, i as eventSchema, p as into, r as envelope } from "./events-BT8y_81j.mjs";
2
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-CPZg2MQb.mjs";
3
3
  import { n as tagOf } from "./tags-BpFo6q0_.mjs";
4
4
  import { z } from "zod";
5
5
  import { connectGitHubAdapter } from "@vercel/connect/chat";
@@ -1,6 +1,6 @@
1
- import { st as SourceRead } from "./routes-BffuaoTX.mjs";
2
- import { c as ReceivedEvent, d as ResolvedTarget, f as SyncContext, g as SyncFn, o as ProviderPost, r as ProviderDelivery, y as SyncUnit } from "./provider-D5yVFisj.mjs";
3
- import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-DyNy5xdC.mjs";
1
+ import { dt as SourceRead } from "./routes-By9lmvUD.mjs";
2
+ import { _ as SyncFn, b as SyncUnit, f as ResolvedTarget, l as ReceivedEvent, o as ProviderPost, p as SyncContext, r as ProviderDelivery } from "./provider-dY54GFNz.mjs";
3
+ import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-Cgkh9xJw.mjs";
4
4
  import { z } from "zod";
5
5
  import { Adapter } from "chat";
6
6
  //#region src/sync/linear.d.ts
@@ -1,5 +1,5 @@
1
- import { f as channels, i as eventSchema, l as UnreadableError, r as envelope } from "./events-C6HwB046.mjs";
2
- import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-1WKsLEnM.mjs";
1
+ import { f as channels, i as eventSchema, l as UnreadableError, r as envelope } from "./events-BT8y_81j.mjs";
2
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-CPZg2MQb.mjs";
3
3
  import { n as tagOf, t as slug } from "./tags-BpFo6q0_.mjs";
4
4
  import "zod";
5
5
  import { connectLinearAdapter } from "@vercel/connect/chat";