@vercel/board 0.39.0 → 0.40.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 (85) hide show
  1. package/README.md +5 -3
  2. package/dist/{access-CVkjSfxj.mjs → access-Bl_k_Hpa.mjs} +1 -1
  3. package/dist/access.d.mts +2 -2
  4. package/dist/access.mjs +4 -4
  5. package/dist/{actors-kfMejhaw.mjs → actors-yBRWTpt5.mjs} +38 -53
  6. package/dist/{auth-B3bBYOqf.mjs → auth-C8URZHLx.mjs} +2 -2
  7. package/dist/{auth-BXLCkeB0.d.mts → auth-DtmZzlHm.d.mts} +5 -2
  8. package/dist/{backend-HcCCGPG4.d.mts → backend-BW5NbBsp.d.mts} +36 -10
  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-DyNy5xdC.d.mts → chat-provider-Bbb9JguG.d.mts} +2 -2
  14. package/dist/cli-commands.d.mts +1 -1
  15. package/dist/cli-commands.mjs +1 -1
  16. package/dist/cli-embedded.d.mts +2 -2
  17. package/dist/cli-embedded.mjs +3 -3
  18. package/dist/cli.mjs +5 -5
  19. package/dist/{commands-B5d-lmNN.d.mts → commands-BJLocuXj.d.mts} +10 -0
  20. package/dist/{commands-BLS7erNu.mjs → commands-D6VWegVY.mjs} +88 -8
  21. package/dist/{conformance-D59Py2m2.mjs → conformance-BWhZ0k8T.mjs} +252 -5
  22. package/dist/conformance.d.mts +4 -3
  23. package/dist/conformance.mjs +1 -1
  24. package/dist/data-values-C-Cq80hz.mjs +176 -0
  25. package/dist/digest-D32GV_mX.mjs +4 -0
  26. package/dist/{engine-eUgO5jTM.mjs → engine-Djif8XVk.mjs} +191 -77
  27. package/dist/{errors-rYDxZEuN.mjs → errors-CNRJqUuL.mjs} +16 -14
  28. package/dist/{exports-M5o4PTfO.mjs → exports-C2OWIbLU.mjs} +621 -245
  29. package/dist/exports-FyRBIAMs.d.mts +4 -0
  30. package/dist/{index-rNqqgkyu.d.mts → index-Cuxbz_E0.d.mts} +2 -2
  31. package/dist/index.d.mts +7 -6
  32. package/dist/index.mjs +6 -5
  33. package/dist/index.node.d.mts +7 -6
  34. package/dist/index.node.mjs +5 -4
  35. package/dist/inspect/app.js +110 -109
  36. package/dist/inspect/engine.js +5 -5
  37. package/dist/inspect-CLy6FrOZ.mjs +2 -0
  38. package/dist/{inspect-BkXxR2uB.mjs → inspect-cGcP8ZO9.mjs} +4 -4
  39. package/dist/{local-DvkOWf4U.mjs → local-CsleYuyM.mjs} +373 -177
  40. package/dist/{main-DtV_Po9i.mjs → main-D97xuqWZ.mjs} +177 -59
  41. package/dist/{memory-DkoqhxIH.mjs → memory-BvVoglGv.mjs} +2 -2
  42. package/dist/{mentions-CB6ShY4R.mjs → mentions-CT2bN5eP.mjs} +17 -3
  43. package/dist/{middleware-CPqAuRtp.mjs → middleware-BF9vnPPS.mjs} +70 -2
  44. package/dist/{targets-C1mT3M1N.mjs → origin-DLCmrwmE.mjs} +47 -39
  45. package/dist/{page-64IwoGRu.mjs → page-6BTCZWGY.mjs} +2 -2
  46. package/dist/page-BnY8FhPn.mjs +2 -0
  47. package/dist/{provider-D5yVFisj.d.mts → provider-YqkF1E2k.d.mts} +23 -13
  48. package/dist/{routes-BffuaoTX.d.mts → routes-CAjd5ARa.d.mts} +101 -25
  49. package/dist/schemas.d.mts +37 -0
  50. package/dist/schemas.mjs +3 -0
  51. package/dist/{serve-CX1rqDF_.mjs → serve-Cs-e0Jke.mjs} +4 -4
  52. package/dist/{server-DkYkyarg.mjs → server-CIfMdIt3.mjs} +6 -6
  53. package/dist/{serving-DJMcG0dT.mjs → serving-B4l0nLng.mjs} +1 -1
  54. package/dist/{sql-l3ysn4O5.mjs → sql-Bv-RQu8n.mjs} +73 -10
  55. package/dist/{sqlite-CAwNHbQD.mjs → sqlite-D4mkYihG.mjs} +2 -2
  56. package/dist/{sqlite-db-cm5yhrD-.mjs → sqlite-db-BraLvHtf.mjs} +1 -1
  57. package/dist/sync-chat-sdk.d.mts +2 -2
  58. package/dist/sync-github.d.mts +2 -2
  59. package/dist/sync-linear.d.mts +3 -3
  60. package/dist/sync-slack.d.mts +14 -8
  61. package/dist/sync-slack.mjs +42 -15
  62. package/dist/sync.d.mts +2 -2
  63. package/dist/{tokens-DA9ipsZ-.mjs → tokens-CrrXAVGz.mjs} +2 -2
  64. package/docs/01-board/01-mounting.md +5 -3
  65. package/docs/01-board/03-identity.md +70 -38
  66. package/docs/01-board/04-messages.md +58 -1
  67. package/docs/01-board/05-reading.md +3 -3
  68. package/docs/01-board/06-watchers.md +2 -3
  69. package/docs/01-board/07-schedules.md +2 -4
  70. package/docs/01-board/08-middleware.md +1 -1
  71. package/docs/01-board/09-access.md +24 -21
  72. package/docs/02-sync/01-overview.md +70 -2
  73. package/docs/02-sync/02-functions.md +11 -6
  74. package/docs/02-sync/03-slack.md +40 -16
  75. package/docs/02-sync/06-providers.md +9 -4
  76. package/docs/04-reference/01-cli.md +110 -18
  77. package/docs/04-reference/02-board.md +63 -10
  78. package/docs/04-reference/03-http.md +154 -28
  79. package/docs/04-reference/05-conformance.md +13 -6
  80. package/docs/index.md +1 -1
  81. package/package.json +5 -1
  82. package/dist/digest-krhjNAt4.mjs +0 -4
  83. package/dist/exports-vLQ2Y2Nd.d.mts +0 -4
  84. package/dist/inspect-lnv1sLXM.mjs +0 -2
  85. package/dist/page-BUj8_UZv.mjs +0 -2
@@ -1,9 +1,9 @@
1
- import { _ as fileSize, h as IMPORT_BYTES_MAX, p as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, y as typeOf } from "./errors-rYDxZEuN.mjs";
1
+ import { _ as fileSize, h as IMPORT_BYTES_MAX, p as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, y as typeOf } from "./errors-CNRJqUuL.mjs";
2
2
  import { b as toStorable, f as MESSAGE_TEXT_MAX, o as ChannelPath } from "./schemas-AZkxk06N.mjs";
3
3
  import { l as isThreadTarget, s as channelOf } from "./external-CHDxWIVf.mjs";
4
4
  import { t as canonicalEmoji } from "./emoji-CTLpvH-A.mjs";
5
- import { a as waitUntil, i as afterRetry, s as derivedId, t as DroppedError } from "./middleware-CPqAuRtp.mjs";
6
- import { n as replaceMentions } from "./mentions-CB6ShY4R.mjs";
5
+ import { a as waitUntil, c as platformProfile, f as viaText, i as afterRetry, l as shownName, m as derivedId, o as actorParts, t as DroppedError } from "./middleware-BF9vnPPS.mjs";
6
+ import { a as replaceMentions, n as isEmail, t as extractMentions } from "./mentions-CT2bN5eP.mjs";
7
7
  import { a as immutable, d as routesFor, l as UnreadableError, n as SyncOverrides, o as ReceivedEvent, s as ResolvedTarget, u as channelMissing } from "./events-C6HwB046.mjs";
8
8
  import { t as displayText } from "./bots-CGkO76qH.mjs";
9
9
  //#region src/sync/engine.ts
@@ -42,6 +42,8 @@ const linkKey = (link) => JSON.stringify([
42
42
  const sameLinks = (a, b) => a.length === b.length && a.every((link, i) => linkKey(link) === linkKey(b[i]));
43
43
  /** Tries per file before it's noted instead: a retry repeats the whole message, so keep it short. */
44
44
  const FILE_ATTEMPTS = 3;
45
+ /** How long a platform's answer to who has an email holds, for `@[ada@vercel.com]`: a busy thread asks once. */
46
+ const EMAIL_TTL_MS = 3e5;
45
47
  /** How long a webhook waits for the board's tables before it lets an event into the inbox anyway: platforms resend after about 3 seconds. */
46
48
  const GATE_WAIT_MS = 2e3;
47
49
  /**
@@ -77,6 +79,25 @@ const describe = (error) => {
77
79
  /** A board error that says what wasn't there. */
78
80
  const missing = (error) => error instanceof HttpError && error.status === 404;
79
81
  /**
82
+ * A platform user's ID as the board names them: under the sync key they came through, not the
83
+ * platform their provider names (`slack-eu:user:U0456` for `slack:user:U0456` through key
84
+ * `slack-eu`). The key is the connection, so a user is that connection's.
85
+ */
86
+ function keyedId(key, platform, id) {
87
+ if (id.startsWith(`${key}:`)) return id;
88
+ return `${key}:${id.startsWith(`${platform}:`) ? id.slice(platform.length + 1) : id}`;
89
+ }
90
+ /** A platform event with its author named under `key`. */
91
+ function keyedEvent(key, platform, event) {
92
+ return "author" in event ? {
93
+ ...event,
94
+ author: {
95
+ ...event.author,
96
+ id: keyedId(key, platform, event.author.id)
97
+ }
98
+ } : event;
99
+ }
100
+ /**
80
101
  * Two-way sync between a board and its platforms, run by board(): webhooks come in through its
81
102
  * adapters and land in the backend's inbox, and what the board's subscription delivers goes out
82
103
  * to them. It reads and writes only through the backend's protocol methods, as `caller`.
@@ -103,8 +124,10 @@ function createSyncEngine(entries) {
103
124
  return platform;
104
125
  };
105
126
  const keyOf = (target) => target.slice(0, target.indexOf(":"));
106
- /** A target of this sync's own: another sync on the board (its own, or one elsewhere) delivers the rest. */
107
- const ours = (target) => entries[keyOf(target)] !== void 0;
127
+ /** Whether this board syncs entry `key` here: another deployment may hold it, and take its webhooks and deliveries. */
128
+ const here = (key) => host().syncedHere(key);
129
+ /** A target of this sync's own, here: another sync on the board (its own, one elsewhere, or another deployment's) delivers the rest. */
130
+ const ours = async (target) => entries[keyOf(target)] !== void 0 && await here(keyOf(target));
108
131
  const native = (external) => external.slice(external.indexOf(":") + 1);
109
132
  /** A thread's sync, or null when the board has no such thread. */
110
133
  async function syncOf(thread) {
@@ -134,16 +157,33 @@ function createSyncEngine(entries) {
134
157
  return (await call("syncCopies", { message: [...new Set(ids)] })).copies;
135
158
  }
136
159
  const find = (query, signal) => call("syncFind", query, signal);
160
+ /** Who this sync is on its board, asked once: the board's own sync on a local board, or this deployment on one elsewhere. */
161
+ let principal = null;
162
+ function principalNow() {
163
+ if (principal) return principal;
164
+ const asked = call("me", {}).then((me) => me.principal);
165
+ principal = asked;
166
+ asked.catch(() => {
167
+ if (principal === asked) principal = null;
168
+ });
169
+ return asked;
170
+ }
137
171
  /** The actors sync renders with, as the board has them now. */
138
172
  async function actorsNow() {
139
- const { actors } = await call("actors", {});
140
- const state = { byId: {} };
173
+ const [{ actors }, me] = await Promise.all([call("actors", {}), principalNow().catch(() => null)]);
174
+ const state = {
175
+ byId: {},
176
+ principal: me
177
+ };
141
178
  for (const actor of actors) state.byId[actor.id] = {
142
179
  id: actor.id,
143
180
  kind: actor.kind,
144
181
  handle: actor.handle,
145
182
  name: actor.name,
146
- avatar: actor.avatar
183
+ avatar: actor.avatar,
184
+ ...actor.via ? { via: { ...actor.via } } : {},
185
+ ...actor.platform ? { platform: actor.platform } : {},
186
+ ...actor.verified ? { verified: true } : {}
147
187
  };
148
188
  return state;
149
189
  }
@@ -184,19 +224,29 @@ function createSyncEngine(entries) {
184
224
  return null;
185
225
  }
186
226
  }
187
- /** A synced platform's user with this email, for `@[ada@vercel.com]`. */
188
- async function findByEmail(email) {
189
- for (const platform of Object.values(entries)) {
190
- const author = await platform.findByEmail(email).catch(() => null);
191
- if (author) return {
192
- id: author.id,
193
- kind: "external",
194
- handle: author.handle,
195
- name: author.name,
196
- avatar: author.avatar
197
- };
198
- }
199
- return null;
227
+ const emails = /* @__PURE__ */ new Map();
228
+ /**
229
+ * How entry `key`'s platform mentions whoever has this email there, as it posts: `<@U0456>` for
230
+ * `@[ada@vercel.com]`, or null when it finds no one. Each answer holds a few minutes.
231
+ */
232
+ function emailMention(key, email) {
233
+ const at = `${key}\u001f${email.toLowerCase()}`;
234
+ const cached = emails.get(at);
235
+ if (cached && Date.now() - cached.at < EMAIL_TTL_MS) return cached.mention;
236
+ if (emails.size >= 1e3) emails.clear();
237
+ const platform = platformOf(key);
238
+ const mention = platform.findByEmail(email).then((user) => user ? platform.mention({
239
+ id: user.id,
240
+ kind: "external",
241
+ handle: user.handle,
242
+ name: user.name,
243
+ avatar: user.avatar
244
+ }) : null, () => null);
245
+ emails.set(at, {
246
+ at: Date.now(),
247
+ mention
248
+ });
249
+ return mention;
200
250
  }
201
251
  /** Validates a requested target and resolves names (`slack:#prs`) to IDs. */
202
252
  async function normalizeTarget(target) {
@@ -257,6 +307,7 @@ function createSyncEngine(entries) {
257
307
  async function handleWebhook(key, request) {
258
308
  const platform = entries[key];
259
309
  if (!platform) throw notFound(`no sync entry named ${key}`);
310
+ if (!await here(key)) return new Response(null, { status: 200 });
260
311
  let response;
261
312
  try {
262
313
  response = await platform.receive(key, request, (received) => intake(key, received));
@@ -275,14 +326,17 @@ function createSyncEngine(entries) {
275
326
  async function pull(keys = Object.keys(entries)) {
276
327
  let ran = 0;
277
328
  const until = Date.now() + PULL_MS;
278
- for (const key of keys) while (Date.now() < until) {
279
- const { items } = await call("inboxNext", {
280
- key,
281
- limit: 10
282
- });
283
- if (items.length === 0) break;
284
- await Promise.all(items.map((item) => runItem(key, item)));
285
- ran += items.length;
329
+ for (const key of keys) {
330
+ if (!await here(key)) continue;
331
+ while (Date.now() < until) {
332
+ const { items } = await call("inboxNext", {
333
+ key,
334
+ limit: 10
335
+ });
336
+ if (items.length === 0) break;
337
+ await Promise.all(items.map((item) => runItem(key, item)));
338
+ ran += items.length;
339
+ }
286
340
  }
287
341
  return ran;
288
342
  }
@@ -332,7 +386,7 @@ function createSyncEngine(entries) {
332
386
  message: copy.id,
333
387
  unavailable: null,
334
388
  snapshot: {
335
- author: copy.author?.name ?? copy.by.actor,
389
+ author: copy.author ? shownName(copy.author) : copy.by.actor,
336
390
  text: copy.text,
337
391
  createdAt: copy.createdAt,
338
392
  files: copy.attachments.map((file) => ({
@@ -437,9 +491,13 @@ function createSyncEngine(entries) {
437
491
  };
438
492
  }
439
493
  /** One platform event from the inbox, through its entry's sync function. `id` is its ID there, which its writes derive theirs from. */
440
- async function inbound(key, item, meta) {
441
- const { event, raw } = item;
494
+ async function inbound(key, received, meta) {
442
495
  const platform = platformOf(key);
496
+ const item = {
497
+ ...received,
498
+ event: keyedEvent(key, platform.platform, received.event)
499
+ };
500
+ const { event, raw } = item;
443
501
  const linked = (await find({ thread: event.thread })).thread ?? void 0;
444
502
  if (event.kind === "message") {
445
503
  const copied = (await find({
@@ -452,7 +510,7 @@ function createSyncEngine(entries) {
452
510
  }
453
511
  }
454
512
  const author = "author" in event ? event.author : {
455
- id: `${platform.platform}:system`,
513
+ id: `${key}:system`,
456
514
  handle: platform.platform,
457
515
  name: platform.platform,
458
516
  avatar: null,
@@ -679,7 +737,10 @@ function createSyncEngine(entries) {
679
737
  raw: fetched.raw ?? null
680
738
  });
681
739
  const root = await post({
682
- author: fetched.author,
740
+ author: {
741
+ ...fetched.author,
742
+ id: keyedId(key, platform.platform, fetched.author.id)
743
+ },
683
744
  channel,
684
745
  text: clampText(draft.text),
685
746
  labels: labels(draft.labels),
@@ -709,7 +770,7 @@ function createSyncEngine(entries) {
709
770
  message: null
710
771
  };
711
772
  const author = "author" in event ? event.author : {
712
- id: `${platform.platform}:system`,
773
+ id: `${key}:system`,
713
774
  handle: platform.platform,
714
775
  name: platform.platform,
715
776
  avatar: null,
@@ -748,7 +809,8 @@ function createSyncEngine(entries) {
748
809
  } else {
749
810
  if (platform.singleReaction) {
750
811
  const emoji = canonicalEmoji(event.emoji);
751
- for (const [held, actors] of Object.entries((await messageOf(id))?.reactions ?? {})) if (actors.includes(author.id) && !(event.added && held === emoji)) await call("syncImport", {
812
+ const as = /* @__PURE__ */ new Set([author.id, `${await principalNow()}+${author.id}`]);
813
+ for (const [held, actors] of Object.entries((await messageOf(id))?.reactions ?? {})) if (actors.some((actor) => as.has(actor)) && !(event.added && held === emoji)) await call("syncImport", {
752
814
  op: "react",
753
815
  author,
754
816
  from: key,
@@ -851,29 +913,78 @@ function createSyncEngine(entries) {
851
913
  }
852
914
  }
853
915
  /**
854
- * A message's text for a platform: each mention it resolved reads natively where the
855
- * actor is the platform's own, and as their plain name anywhere else. A handle it
856
- * didn't resolve goes out as written.
916
+ * A message's text for a platform, through entry `key`, its mentions resolved as it posts and only
917
+ * against that entry's own users. An `@handle` reads natively when one of them has it, or of
918
+ * several, the one who wrote in the thread: `@support/malte` names one of support's users, and
919
+ * `@malte` is short for whichever of this sync's users that is, under its principal's name. An `@[actor-id]` reads natively when it's one of them,
920
+ * and as the actor's name otherwise; an `@[email]`, as whoever the platform finds with it, or as
921
+ * the email. The rest go as written.
857
922
  */
858
- function textFor(platform, message, actors, text = message.text) {
859
- const mentioned = message.mentions.map((id) => actors.byId[id]).filter((actor) => actor !== void 0);
860
- return replaceMentions(text, (token, written) => {
861
- const actor = token.kind === "actor" ? mentioned.find((candidate) => candidate.id === token.actor) : mentioned.find((candidate) => candidate.handle.toLowerCase() === token.handle);
862
- if (actor) return nativeMention(platform, actor.id, actors) ?? actor.name;
863
- return null;
923
+ async function textFor(key, message, actors, text) {
924
+ const tokens = extractMentions(text);
925
+ if (tokens.length === 0) return text;
926
+ const found = /* @__PURE__ */ new Map();
927
+ for (const token of tokens) if (token.kind === "actor" && !actors.byId[token.actor] && isEmail(token.actor)) found.set(token.actor, await emailMention(key, token.actor));
928
+ const users = /* @__PURE__ */ new Map();
929
+ for (const token of tokens) {
930
+ if (token.kind !== "handle") continue;
931
+ const theirs = Object.values(actors.byId).filter((actor) => {
932
+ const handle = actor.handle.toLowerCase();
933
+ return handle === token.handle || !token.handle.includes("/") && handle.slice(handle.indexOf("/") + 1) === token.handle;
934
+ });
935
+ users.set(token.handle, theirs.flatMap((actor) => {
936
+ const mention = nativeMention(key, actor.id, actors);
937
+ return mention === null ? [] : [{
938
+ id: actor.id,
939
+ mention
940
+ }];
941
+ }));
942
+ }
943
+ const writers = [...users.values()].some((theirs) => new Set(theirs.map((user) => user.mention)).size > 1) ? new Set((await threadOf(message.re ?? message.id)).map((written) => written.by.actor)) : null;
944
+ const one = (theirs) => {
945
+ const mentions = new Set(theirs.map((user) => user.mention));
946
+ return mentions.size === 1 ? [...mentions][0] : null;
947
+ };
948
+ return replaceMentions(text, (token) => {
949
+ if (token.kind === "handle") {
950
+ const theirs = users.get(token.handle) ?? [];
951
+ return one(theirs) ?? (writers ? one(theirs.filter((user) => writers.has(user.id))) : null);
952
+ }
953
+ if (found.has(token.actor)) return found.get(token.actor) ?? token.actor;
954
+ const actor = actors.byId[token.actor];
955
+ return actor ? nativeMention(key, actor.id, actors) ?? actor.name : null;
864
956
  });
865
957
  }
866
- /** How `platform` mentions an actor: natively when it's the platform's own account, or null. */
867
- function nativeMention(platform, actor, actors) {
958
+ /**
959
+ * Whose ID an actor is on entry `key`'s platform, when it's one of that entry's users: this sync's
960
+ * own profile of them (`<principal>+<key>:…`), or one named under the key alone, as the board's
961
+ * own sync names its users and as Vercel's board named imports before profiles. Null for anyone
962
+ * else: a platform user another sync speaks for is that sync's word.
963
+ */
964
+ function userOf(key, actor, actors) {
965
+ const { principal, profile } = actorParts(actor);
966
+ const id = profile === null ? actor : platformProfile(profile) !== null && principal === actors.principal ? profile : null;
967
+ return id?.startsWith(`${key}:`) ? id.slice(key.length + 1) : null;
968
+ }
969
+ /** How entry `key`'s platform mentions an actor: natively when it's one of that entry's users, found on the platform by their ID there, or null. */
970
+ function nativeMention(key, actor, actors) {
868
971
  const account = actors.byId[actor];
869
- return account ? platform.mention(account) : null;
972
+ const user = account ? userOf(key, actor, actors) : null;
973
+ if (user === null) return null;
974
+ const platform = platformOf(key);
975
+ return platform.mention({
976
+ ...account,
977
+ id: `${platform.platform}:${user}`
978
+ });
870
979
  }
871
980
  /** A board message as markdown for a platform, which converts it to its own format: by `renderer`, or the provider's own. */
872
- function render(key, target, message, actors, renderer) {
981
+ async function render(key, target, message, actors, renderer) {
873
982
  const actor = actors.byId[message.by.actor];
874
- let name = actor?.name ?? message.by.actor;
875
- if (message.by.profile && actor?.handle.includes("/")) name = `${actor.name} via ${actor.handle.split("/")[0]}`;
876
- if (message.from) name = `${name} (${entries[message.from]?.platform ?? message.by.actor.slice(0, message.by.actor.indexOf(":"))})`;
983
+ const own = actor?.name ?? message.by.actor;
984
+ const after = `${actor?.via ? ` ${viaText(actor.via)}` : ""}${message.from ? ` (${actor?.platform ?? entries[message.from]?.platform ?? message.from})` : ""}`;
985
+ const environment = actor?.kind === "deployment" && !actor.via ? /(?:@[^@/]+| \([^()]+\))$/.exec(own)?.[0] ?? "" : "";
986
+ const name = `${own}${after}`;
987
+ const attribution = `${environment}${after}`;
877
988
  const platform = platformOf(key);
878
989
  const body = (renderer ?? ((input) => platform.render(input)))(immutable({
879
990
  message: {
@@ -881,21 +992,22 @@ function createSyncEngine(entries) {
881
992
  text: displayText(message.text, message.by.actor)
882
993
  },
883
994
  author: actor ? { ...actor } : null,
884
- mentionOf: (id) => nativeMention(platform, id, actors),
995
+ mentionOf: (id) => nativeMention(key, id, actors),
885
996
  label: name,
886
997
  target
887
998
  }));
888
999
  if (typeof body !== "string") throw badRequest("a provider renderer must return markdown");
889
- const markdown = textFor(platform, message, actors, body);
890
- return message.by.profile && !message.from ? {
1000
+ const markdown = await textFor(key, message, actors, body);
1001
+ return actor?.verified ? {
891
1002
  markdown,
892
1003
  as: {
893
1004
  name,
894
- avatar: senderAvatar(message, actor, actors)
1005
+ avatar: senderAvatar(message, actor, actors),
1006
+ attribution
895
1007
  }
896
1008
  } : { markdown };
897
1009
  }
898
- /** An agent's own picture, or for the board's built-in one, its person's Vercel avatar: `claude via julian` shows Julian. */
1010
+ /** An author's own picture, or for an agent with the board's built-in one, its person's Vercel avatar: `claude via julian` shows Julian. */
899
1011
  function senderAvatar(message, actor, actors) {
900
1012
  const builtIn = (avatar) => !avatar || /\/avatars\/[a-z0-9-]+$/.test(avatar);
901
1013
  const own = actor?.avatar ?? null;
@@ -912,9 +1024,9 @@ function createSyncEngine(entries) {
912
1024
  * `render`, with a line per file where the files won't follow: on a platform
913
1025
  * that takes no uploads, or one that refused them (`noted`).
914
1026
  */
915
- const renderFor = (target, message, actors, noted = false, renderer) => {
1027
+ const renderFor = async (target, message, actors, noted = false, renderer) => {
916
1028
  const key = keyOf(target);
917
- const { markdown, as } = render(key, target, message, actors, renderer);
1029
+ const { markdown, as } = await render(key, target, message, actors, renderer);
918
1030
  return {
919
1031
  markdown: message.attachments.length > 0 && (noted || !platformOf(key).uploadsFiles) ? `${markdown}\n${attachmentNotes(message)}` : markdown,
920
1032
  ...as ? { as } : {}
@@ -924,7 +1036,7 @@ function createSyncEngine(entries) {
924
1036
  const replyCopy = message.replyTo === null ? void 0 : (await copiesOf([message.replyTo]))[message.replyTo]?.[target];
925
1037
  const place = replyCopy !== void 0 && replyCopy.thread !== externalThread ? replyCopy.thread : externalThread;
926
1038
  const platform = platformOf(keyOf(target));
927
- let body = renderFor(target, message, actors, false, renderer);
1039
+ let body = await renderFor(target, message, actors, false, renderer);
928
1040
  let files;
929
1041
  let sentId;
930
1042
  if (!body.markdown.trim() && message.attachments.length && platform.uploadsFiles) try {
@@ -933,7 +1045,7 @@ function createSyncEngine(entries) {
933
1045
  files = sent.files;
934
1046
  } catch (error) {
935
1047
  if (!platform.refusesFiles(error) && !keepsNoFiles(error)) throw error;
936
- body = renderFor(target, message, actors, true, renderer);
1048
+ body = await renderFor(target, message, actors, true, renderer);
937
1049
  sentId = (await platform.post(native(place), "thread", body)).message;
938
1050
  files = null;
939
1051
  }
@@ -993,7 +1105,7 @@ function createSyncEngine(entries) {
993
1105
  });
994
1106
  console.warn(`[board] ${target} won't take #${message.id}'s files (${describe(error)}); noting them in its text`);
995
1107
  ids = null;
996
- await platform.edit(native(copy.thread), copy.message, renderFor(target, message, actors, true, renderer)).catch((edit) => console.warn(`[board] couldn't note #${message.id}'s files on ${target}:`, describe(edit)));
1108
+ await renderFor(target, message, actors, true, renderer).then((body) => platform.edit(native(copy.thread), copy.message, body)).catch((edit) => console.warn(`[board] couldn't note #${message.id}'s files on ${target}:`, describe(edit)));
997
1109
  }
998
1110
  await call("syncReceipt", {
999
1111
  kind: "files",
@@ -1072,7 +1184,8 @@ function createSyncEngine(entries) {
1072
1184
  }
1073
1185
  /** A new root, offered to each platform that can start threads: its sync function may `start` one there. */
1074
1186
  async function deliverRoot(event, attempt) {
1075
- const starters = Object.keys(entries).filter((key) => entries[key].canStartThreads);
1187
+ const starters = [];
1188
+ for (const key of Object.keys(entries)) if (entries[key].canStartThreads && await here(key)) starters.push(key);
1076
1189
  if (event.payload.noSync || starters.length === 0) return;
1077
1190
  const root = await messageOf(event.message.id);
1078
1191
  if (!root || root.deleted) return;
@@ -1086,11 +1199,12 @@ function createSyncEngine(entries) {
1086
1199
  }
1087
1200
  async function deliverThread(event, attempt) {
1088
1201
  const { thread, target } = event.payload;
1089
- if (!ours(target)) return;
1202
+ if (!await ours(target)) return;
1090
1203
  if ((event.payload.kind ?? (isThreadTarget(target) ? "thread" : "channel")) === "thread") return;
1091
1204
  const synced = await syncOf(thread);
1092
- const [root, ...replies] = synced ? await threadOf(synced.root) : [];
1093
- if (!synced || !root || root.id !== synced.root || root.deleted) return;
1205
+ if (!synced?.targets.includes(target)) return;
1206
+ const [root, ...replies] = await threadOf(synced.root);
1207
+ if (!root || root.id !== synced.root || root.deleted) return;
1094
1208
  const failures = [];
1095
1209
  try {
1096
1210
  await offer(keyOf(target), event, root, target, (renderer) => backfill(synced, root, replies, target, failures, renderer));
@@ -1117,7 +1231,7 @@ function createSyncEngine(entries) {
1117
1231
  let externalThread = synced.external[target];
1118
1232
  if (!externalThread) try {
1119
1233
  const platform = platformOf(keyOf(target));
1120
- const body = renderFor(target, root, actors, false, renderer);
1234
+ const body = await renderFor(target, root, actors, false, renderer);
1121
1235
  const mediaOnly = !body.markdown.trim() && root.attachments.length > 0 && platform.uploadsFiles;
1122
1236
  if (!body.markdown.trim() && !mediaOnly) throw badRequest("a renderer must return text unless the message has media");
1123
1237
  let uploaded;
@@ -1135,7 +1249,7 @@ function createSyncEngine(entries) {
1135
1249
  } catch (error) {
1136
1250
  if (!platform.refusesFiles(error) && !keepsNoFiles(error)) throw error;
1137
1251
  uploaded = null;
1138
- return platform.post(native(target), "channel", renderFor(target, root, actors, true, renderer));
1252
+ return platform.post(native(target), "channel", await renderFor(target, root, actors, true, renderer));
1139
1253
  }
1140
1254
  };
1141
1255
  const sent = await post();
@@ -1188,7 +1302,7 @@ function createSyncEngine(entries) {
1188
1302
  const failures = [];
1189
1303
  for (const target of synced.targets) {
1190
1304
  const externalThread = synced.external[target];
1191
- if (!ours(target) || !externalThread) continue;
1305
+ if (!await ours(target) || !externalThread) continue;
1192
1306
  if (cameFrom(message, target)) continue;
1193
1307
  try {
1194
1308
  await offer(keyOf(target), event, message, target, async (renderer) => {
@@ -1209,12 +1323,12 @@ function createSyncEngine(entries) {
1209
1323
  if (!message || event.type === "message.edited" && message.deleted) return;
1210
1324
  const actors = await actorsNow();
1211
1325
  for (const [target, copy] of Object.entries(copies)) {
1212
- if (!ours(target) || event.payload.from !== null && keyOf(target) === event.payload.from) continue;
1326
+ if (!await ours(target) || event.payload.from !== null && keyOf(target) === event.payload.from) continue;
1213
1327
  try {
1214
1328
  await offer(keyOf(target), event, message, target, async (renderer) => {
1215
1329
  const platform = platformOf(keyOf(target));
1216
1330
  const thread = native(copy.thread);
1217
- if (event.type === "message.edited") await platform.edit(thread, copy.message, renderFor(target, message, actors, copy.files === null, renderer));
1331
+ if (event.type === "message.edited") await platform.edit(thread, copy.message, await renderFor(target, message, actors, copy.files === null, renderer));
1218
1332
  else if (event.type === "message.deleted") {
1219
1333
  await platform.delete(thread, copy.message);
1220
1334
  if (copy.files?.length) await platform.deleteFiles(copy.files);
@@ -1247,11 +1361,11 @@ function createSyncEngine(entries) {
1247
1361
  labels: event.before?.labels ?? {}
1248
1362
  };
1249
1363
  for (const [target, copy] of Object.entries(copies)) {
1250
- if (!ours(target)) continue;
1364
+ if (!await ours(target)) continue;
1251
1365
  try {
1252
1366
  await offer(keyOf(target), event, message, target, async (renderer) => {
1253
- const body = renderFor(target, message, actors, copy.files === null, renderer);
1254
- if (body.markdown === renderFor(target, previous, actors, copy.files === null, renderer).markdown) return;
1367
+ const body = await renderFor(target, message, actors, copy.files === null, renderer);
1368
+ if (body.markdown === (await renderFor(target, previous, actors, copy.files === null, renderer)).markdown) return;
1255
1369
  await platformOf(keyOf(target)).edit(native(copy.thread), copy.message, body);
1256
1370
  });
1257
1371
  } catch (error) {
@@ -1283,7 +1397,8 @@ function createSyncEngine(entries) {
1283
1397
  async function typing(messages, status) {
1284
1398
  const synced = messages[0] ? await syncOf(messages[0].thread) : null;
1285
1399
  if (!synced) return [];
1286
- const externals = [...new Set(Object.values(synced.external))].filter(ours);
1400
+ const externals = [];
1401
+ for (const external of new Set(Object.values(synced.external))) if (await ours(external)) externals.push(external);
1287
1402
  return (await Promise.all(externals.map(async (external) => {
1288
1403
  const key = keyOf(external);
1289
1404
  try {
@@ -1358,7 +1473,6 @@ function createSyncEngine(entries) {
1358
1473
  receive: inbound,
1359
1474
  pull,
1360
1475
  normalizeTarget,
1361
- findByEmail,
1362
1476
  handleWebhook,
1363
1477
  inboxChannel,
1364
1478
  typing,
@@ -1372,4 +1486,4 @@ function lifecycleText(event) {
1372
1486
  return event.body ? `${head}\n\n${event.body}` : head;
1373
1487
  }
1374
1488
  //#endregion
1375
- export { createSyncEngine };
1489
+ export { createSyncEngine, keyedId };
@@ -191,10 +191,6 @@ function creatorOf(me, path) {
191
191
  };
192
192
  throw new BoardError("no_own_principal", `A private channel lets its creator in, as a person or a project's deployment, and ${me.principal} is neither, so ${path} wasn't made.`, 400, { hint: "Make it as a person or a deployment, or make it and its grants yourself." });
193
193
  }
194
- const written = (value, unknownMentions) => unknownMentions?.length ? {
195
- ...value,
196
- unknownMentions
197
- } : value;
198
194
  function createBoardClient(options) {
199
195
  const base = options.url.replace(/\/+$/, "");
200
196
  const doFetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
@@ -329,20 +325,17 @@ function createBoardClient(options) {
329
325
  posted: async (id) => (await call("GET", `/posts/${path(id)}`)).message,
330
326
  /** Threads with a matching message, one summary each (root, reply count, latest reply), by latest activity. `limit` counts threads. */
331
327
  threads: (query = {}) => call("GET", `/threads${queryString(query)}`),
332
- /** `unknownMentions` lists the handles that matched nobody: they posted as plain text. */
333
328
  async post(channel, input) {
334
- const { message, unknownMentions } = await call("POST", "/messages", { body: {
329
+ return (await call("POST", "/messages", { body: {
335
330
  channel,
336
331
  ...messageBody(input)
337
- } });
338
- return written(message, unknownMentions);
332
+ } })).message;
339
333
  },
340
334
  async reply(id, input) {
341
- const { message, unknownMentions } = await call("POST", "/messages", { body: {
335
+ return (await call("POST", "/messages", { body: {
342
336
  re: id,
343
337
  ...messageBody(input)
344
- } });
345
- return written(message, unknownMentions);
338
+ } })).message;
346
339
  },
347
340
  /**
348
341
  * Posts later, as you: a new thread when `target` is a channel, a reply when it's
@@ -350,11 +343,10 @@ function createBoardClient(options) {
350
343
  * `schedule: { id, n }`. Needs a board with a scheduler.
351
344
  */
352
345
  async schedule(target, input) {
353
- const { schedule, unknownMentions } = await call("POST", "/schedules", { body: {
346
+ return (await call("POST", "/schedules", { body: {
354
347
  ...typeof target === "string" ? { channel: target } : { re: target.re },
355
348
  ...scheduleBody(input)
356
- } });
357
- return written(schedule, unknownMentions);
349
+ } })).schedule;
358
350
  },
359
351
  /** Pending schedules (`all` for done and canceled too), oldest first. `re` is any message in a thread. */
360
352
  schedules: async (query = {}) => (await call("GET", `/schedules${queryString(query)}`)).schedules,
@@ -405,6 +397,16 @@ function createBoardClient(options) {
405
397
  tokens: async () => (await call("GET", "/tokens")).tokens,
406
398
  /** It and every token minted with it stop. `revoked` is false when it was already revoked. */
407
399
  revokeToken: (id) => call("POST", `/tokens/${path(id)}/revoke`, { body: {} }),
400
+ /** Every schema: the built-ins, then the board's own, by name and version. */
401
+ schemas: async () => (await call("GET", "/schemas")).schemas,
402
+ /** One schema version, by its ID: `sandbox@1`. */
403
+ schema: async (id) => (await call("GET", `/schemas/${path(id)}`)).schema,
404
+ /**
405
+ * Registers a schema version, for good: `schema` is a JSON Schema for an object, in structural
406
+ * keywords only. Needs manage at `*`. `created` is false for one that's there with the same
407
+ * definition; another definition is refused, since a version never changes.
408
+ */
409
+ createSchema: (input) => call("POST", "/schemas", { body: input }),
408
410
  /**
409
411
  * Stores a file on the board, for a post or reply's `attachments`. Up to 4 MB goes in one
410
412
  * request; bigger, up to 100 MB, goes straight to the board's blob store on a URL the board