@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,10 +1,10 @@
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";
2
- import { b as toStorable, f as MESSAGE_TEXT_MAX, o as ChannelPath } from "./schemas-AZkxk06N.mjs";
3
- import { l as isThreadTarget, s as channelOf } from "./external-CHDxWIVf.mjs";
1
+ import { _ as IMPORT_BYTES_MAX, h as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, x as typeOf, y as fileSize } from "./errors-DcQf5WeM.mjs";
2
+ import { f as MESSAGE_TEXT_MAX, o as ChannelPath, x as toStorable } from "./schemas-DAzSsgWk.mjs";
3
+ import { l as isThreadTarget, s as channelOf } from "./external-DymyhUzl.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";
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";
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-DHdrxmoc.mjs";
6
+ import { a as replaceMentions, n as isEmail, t as extractMentions } from "./mentions-DfZGp3B-.mjs";
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-BT8y_81j.mjs";
8
8
  import { t as displayText } from "./bots-CGkO76qH.mjs";
9
9
  //#region src/sync/engine.ts
10
10
  /** `files`: a message with files may have no text. */
@@ -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,29 +992,29 @@ 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),
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. */
899
- function senderAvatar(message, actor, actors) {
1010
+ /** An author's own picture, or for one with none or the board's built-in one, its person's Vercel avatar: `claude via julian` shows Julian. */
1011
+ function senderAvatar(message, actor) {
900
1012
  const builtIn = (avatar) => !avatar || /\/avatars\/[a-z0-9-]+$/.test(avatar);
901
1013
  const own = actor?.avatar ?? null;
902
1014
  if (!builtIn(own)) return own;
903
- const person = actors.byId[message.by.principal]?.avatar;
904
- if (!builtIn(person)) return person;
905
1015
  const username = actor?.handle.split("/")[0] ?? "";
906
- if (!message.by.principal.startsWith("vercel:user:") || !username || /^user-/.test(username)) return own;
1016
+ const id = message.by.principal.slice(12);
1017
+ if (!message.by.principal.startsWith("vercel:user:") || !username || /^user-/.test(username) || username.toLowerCase() === id.toLowerCase()) return own;
907
1018
  return `https://vercel.com/api/www/avatar?u=${encodeURIComponent(username)}&s=64&format=png`;
908
1019
  }
909
1020
  /** What a platform shows for files it didn't get: one line each, so a reader knows they're on the board. */
@@ -912,9 +1023,9 @@ function createSyncEngine(entries) {
912
1023
  * `render`, with a line per file where the files won't follow: on a platform
913
1024
  * that takes no uploads, or one that refused them (`noted`).
914
1025
  */
915
- const renderFor = (target, message, actors, noted = false, renderer) => {
1026
+ const renderFor = async (target, message, actors, noted = false, renderer) => {
916
1027
  const key = keyOf(target);
917
- const { markdown, as } = render(key, target, message, actors, renderer);
1028
+ const { markdown, as } = await render(key, target, message, actors, renderer);
918
1029
  return {
919
1030
  markdown: message.attachments.length > 0 && (noted || !platformOf(key).uploadsFiles) ? `${markdown}\n${attachmentNotes(message)}` : markdown,
920
1031
  ...as ? { as } : {}
@@ -924,7 +1035,7 @@ function createSyncEngine(entries) {
924
1035
  const replyCopy = message.replyTo === null ? void 0 : (await copiesOf([message.replyTo]))[message.replyTo]?.[target];
925
1036
  const place = replyCopy !== void 0 && replyCopy.thread !== externalThread ? replyCopy.thread : externalThread;
926
1037
  const platform = platformOf(keyOf(target));
927
- let body = renderFor(target, message, actors, false, renderer);
1038
+ let body = await renderFor(target, message, actors, false, renderer);
928
1039
  let files;
929
1040
  let sentId;
930
1041
  if (!body.markdown.trim() && message.attachments.length && platform.uploadsFiles) try {
@@ -933,7 +1044,7 @@ function createSyncEngine(entries) {
933
1044
  files = sent.files;
934
1045
  } catch (error) {
935
1046
  if (!platform.refusesFiles(error) && !keepsNoFiles(error)) throw error;
936
- body = renderFor(target, message, actors, true, renderer);
1047
+ body = await renderFor(target, message, actors, true, renderer);
937
1048
  sentId = (await platform.post(native(place), "thread", body)).message;
938
1049
  files = null;
939
1050
  }
@@ -993,7 +1104,7 @@ function createSyncEngine(entries) {
993
1104
  });
994
1105
  console.warn(`[board] ${target} won't take #${message.id}'s files (${describe(error)}); noting them in its text`);
995
1106
  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)));
1107
+ 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
1108
  }
998
1109
  await call("syncReceipt", {
999
1110
  kind: "files",
@@ -1072,7 +1183,8 @@ function createSyncEngine(entries) {
1072
1183
  }
1073
1184
  /** A new root, offered to each platform that can start threads: its sync function may `start` one there. */
1074
1185
  async function deliverRoot(event, attempt) {
1075
- const starters = Object.keys(entries).filter((key) => entries[key].canStartThreads);
1186
+ const starters = [];
1187
+ for (const key of Object.keys(entries)) if (entries[key].canStartThreads && await here(key)) starters.push(key);
1076
1188
  if (event.payload.noSync || starters.length === 0) return;
1077
1189
  const root = await messageOf(event.message.id);
1078
1190
  if (!root || root.deleted) return;
@@ -1086,11 +1198,12 @@ function createSyncEngine(entries) {
1086
1198
  }
1087
1199
  async function deliverThread(event, attempt) {
1088
1200
  const { thread, target } = event.payload;
1089
- if (!ours(target)) return;
1201
+ if (!await ours(target)) return;
1090
1202
  if ((event.payload.kind ?? (isThreadTarget(target) ? "thread" : "channel")) === "thread") return;
1091
1203
  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;
1204
+ if (!synced?.targets.includes(target)) return;
1205
+ const [root, ...replies] = await threadOf(synced.root);
1206
+ if (!root || root.id !== synced.root || root.deleted) return;
1094
1207
  const failures = [];
1095
1208
  try {
1096
1209
  await offer(keyOf(target), event, root, target, (renderer) => backfill(synced, root, replies, target, failures, renderer));
@@ -1117,7 +1230,7 @@ function createSyncEngine(entries) {
1117
1230
  let externalThread = synced.external[target];
1118
1231
  if (!externalThread) try {
1119
1232
  const platform = platformOf(keyOf(target));
1120
- const body = renderFor(target, root, actors, false, renderer);
1233
+ const body = await renderFor(target, root, actors, false, renderer);
1121
1234
  const mediaOnly = !body.markdown.trim() && root.attachments.length > 0 && platform.uploadsFiles;
1122
1235
  if (!body.markdown.trim() && !mediaOnly) throw badRequest("a renderer must return text unless the message has media");
1123
1236
  let uploaded;
@@ -1135,7 +1248,7 @@ function createSyncEngine(entries) {
1135
1248
  } catch (error) {
1136
1249
  if (!platform.refusesFiles(error) && !keepsNoFiles(error)) throw error;
1137
1250
  uploaded = null;
1138
- return platform.post(native(target), "channel", renderFor(target, root, actors, true, renderer));
1251
+ return platform.post(native(target), "channel", await renderFor(target, root, actors, true, renderer));
1139
1252
  }
1140
1253
  };
1141
1254
  const sent = await post();
@@ -1188,7 +1301,7 @@ function createSyncEngine(entries) {
1188
1301
  const failures = [];
1189
1302
  for (const target of synced.targets) {
1190
1303
  const externalThread = synced.external[target];
1191
- if (!ours(target) || !externalThread) continue;
1304
+ if (!await ours(target) || !externalThread) continue;
1192
1305
  if (cameFrom(message, target)) continue;
1193
1306
  try {
1194
1307
  await offer(keyOf(target), event, message, target, async (renderer) => {
@@ -1209,12 +1322,12 @@ function createSyncEngine(entries) {
1209
1322
  if (!message || event.type === "message.edited" && message.deleted) return;
1210
1323
  const actors = await actorsNow();
1211
1324
  for (const [target, copy] of Object.entries(copies)) {
1212
- if (!ours(target) || event.payload.from !== null && keyOf(target) === event.payload.from) continue;
1325
+ if (!await ours(target) || event.payload.from !== null && keyOf(target) === event.payload.from) continue;
1213
1326
  try {
1214
1327
  await offer(keyOf(target), event, message, target, async (renderer) => {
1215
1328
  const platform = platformOf(keyOf(target));
1216
1329
  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));
1330
+ if (event.type === "message.edited") await platform.edit(thread, copy.message, await renderFor(target, message, actors, copy.files === null, renderer));
1218
1331
  else if (event.type === "message.deleted") {
1219
1332
  await platform.delete(thread, copy.message);
1220
1333
  if (copy.files?.length) await platform.deleteFiles(copy.files);
@@ -1247,11 +1360,11 @@ function createSyncEngine(entries) {
1247
1360
  labels: event.before?.labels ?? {}
1248
1361
  };
1249
1362
  for (const [target, copy] of Object.entries(copies)) {
1250
- if (!ours(target)) continue;
1363
+ if (!await ours(target)) continue;
1251
1364
  try {
1252
1365
  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;
1366
+ const body = await renderFor(target, message, actors, copy.files === null, renderer);
1367
+ if (body.markdown === (await renderFor(target, previous, actors, copy.files === null, renderer)).markdown) return;
1255
1368
  await platformOf(keyOf(target)).edit(native(copy.thread), copy.message, body);
1256
1369
  });
1257
1370
  } catch (error) {
@@ -1283,7 +1396,8 @@ function createSyncEngine(entries) {
1283
1396
  async function typing(messages, status) {
1284
1397
  const synced = messages[0] ? await syncOf(messages[0].thread) : null;
1285
1398
  if (!synced) return [];
1286
- const externals = [...new Set(Object.values(synced.external))].filter(ours);
1399
+ const externals = [];
1400
+ for (const external of new Set(Object.values(synced.external))) if (await ours(external)) externals.push(external);
1287
1401
  return (await Promise.all(externals.map(async (external) => {
1288
1402
  const key = keyOf(external);
1289
1403
  try {
@@ -1358,7 +1472,6 @@ function createSyncEngine(entries) {
1358
1472
  receive: inbound,
1359
1473
  pull,
1360
1474
  normalizeTarget,
1361
- findByEmail,
1362
1475
  handleWebhook,
1363
1476
  inboxChannel,
1364
1477
  typing,
@@ -1372,4 +1485,4 @@ function lifecycleText(event) {
1372
1485
  return event.body ? `${head}\n\n${event.body}` : head;
1373
1486
  }
1374
1487
  //#endregion
1375
- export { createSyncEngine };
1488
+ export { createSyncEngine, keyedId };