@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,16 +1,17 @@
1
- import { a as forbidden$1, c as toErrorResponse, f as duration, g as fileName, h as IMPORT_BYTES_MAX, i as duplicateId, l as unauthorized, m as DIRECT_UPLOAD_BYTES_MAX, p as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, u as BoardError, v as mediaType } from "./errors-rYDxZEuN.mjs";
1
+ import { a as forbidden$1, c as toErrorResponse, f as duration, g as fileName, h as IMPORT_BYTES_MAX, i as duplicateId, l as unauthorized, m as DIRECT_UPLOAD_BYTES_MAX, p as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, u as BoardError, v as mediaType } from "./errors-CNRJqUuL.mjs";
2
2
  import { _ as actorKind, a as CAN_MAX, c as Handle, d as Labels, g as SeenActorKind, h as RemoteWatcherId, i as Author, l as LabelKey, m as MessageText, n as Attachment, o as ChannelPath, p as MessageId, s as Emoji, t as ActorId, v as platformAvatar, y as storable } from "./schemas-AZkxk06N.mjs";
3
3
  import { a as Link, i as ExternalTarget, n as ExternalEvent, o as Origin } from "./external-CHDxWIVf.mjs";
4
- import { a as runMatch, g as VERSION, h as SYNC, i as canonicalWatchers, l as METHODS, n as syncTarget, o as compileWatcher, r as withEmailMentions, s as hasCriteria } from "./targets-C1mT3M1N.mjs";
5
- import { a as waitUntil, c as isKeyIdOf, n as MIDDLEWARE_ACTOR, s as derivedId, t as DroppedError } from "./middleware-CPqAuRtp.mjs";
6
- import { a as canText, c as compileAccess, i as authorize, o as checkGrantChange, t as FULL_ACCESS, u as parseCan } from "./access-CVkjSfxj.mjs";
7
- import { C as workflowPath, c as checkGrant, f as grantIssuers, h as joined, l as checkPrincipal, m as issuerName, n as DEFAULT_CAN, o as authenticates, r as GITHUB_ISSUER, s as checkCan, t as BOARD_TOKEN_PREFIX, v as removes, w as wroteAs, y as tokenHash } from "./auth-B3bBYOqf.mjs";
4
+ import { a as SCHEMA_DESCRIPTION_MAX, c as canonical, d as parseSchemaId, f as schemaId, i as BUILT_IN_SCHEMAS, l as checkDefinition, n as blocksIn, o as SCHEMA_NAME, s as SCHEMA_VERSION_MAX, u as isBuiltInName } from "./blocks-CVoBC7ur.mjs";
5
+ import { a as compileWatcher, c as METHODS, h as VERSION, i as runMatch, m as SYNC, n as syncTarget, o as hasCriteria, r as canonicalWatchers, t as SYNC_ACTOR } from "./origin-DLCmrwmE.mjs";
6
+ import { a as waitUntil, c as platformProfile, d as userIdOf, h as isKeyIdOf, l as shownName, m as derivedId, n as MIDDLEWARE_ACTOR, o as actorParts, s as importedHandle, t as DroppedError } from "./middleware-BF9vnPPS.mjs";
7
+ import { a as canText, c as compileAccess, i as authorize, o as checkGrantChange, t as FULL_ACCESS, u as parseCan } from "./access-Bl_k_Hpa.mjs";
8
+ import { C as workflowPath, c as checkGrant, f as grantIssuers, h as joined, l as checkPrincipal, m as issuerName, n as DEFAULT_CAN, o as authenticates, r as GITHUB_ISSUER, s as checkCan, t as BOARD_TOKEN_PREFIX, v as removes, w as wroteAs, y as tokenHash } from "./auth-C8URZHLx.mjs";
8
9
  import { n as setOwn, t as own } from "./own-OwgPWdmh.mjs";
9
- import { n as replaceMentions } from "./mentions-CB6ShY4R.mjs";
10
- import { a as resolveMentions, n as actorSeen } from "./actors-kfMejhaw.mjs";
10
+ import { a as viaOf, n as actorSeen } from "./actors-yBRWTpt5.mjs";
11
11
  import { C as sessionClearedError, a as SOCKET_TIMINGS, c as drainSettledHooks, d as nullProtoRecord, f as runtimeConsumerFactory, g as A2Error, h as stateTailReaders, i as RESERVED_PARTICIPANT_IDS, l as failedPreviousAttempt, m as serverInternals, n as POLL_TIMINGS, o as STATE_CACHE, p as runtimeConsumers, r as PRESENCE_TIMINGS, s as STREAM_TIMINGS, t as DRAIN_TIMINGS, u as markSchedulerSendFailure, v as NonRetriableError, x as isSessionCleared, y as asStoreUnavailable } from "./internal-CvsrprnU-CEPOUpAv.mjs";
12
12
  import { i as streamActivities, n as defaultSleep, t as createStreamActivity } from "./store-polling-BZt2Rf3D-oh3aU_An.mjs";
13
- import { a as foldActors, i as concernedMessageId, o as foldMessages, s as iso, t as TABLES_CONSUMER } from "./sql-l3ysn4O5.mjs";
13
+ import { a as foldActors, i as concernedMessageId, o as foldMessages, s as iso, t as TABLES_CONSUMER } from "./sql-Bv-RQu8n.mjs";
14
+ import { a as replaceMentions, i as mentionTerms, n as isEmail, r as mentionTerm, t as extractMentions } from "./mentions-CT2bN5eP.mjs";
14
15
  import { z } from "zod";
15
16
  import { createHash, randomBytes } from "node:crypto";
16
17
  import { mkdir, readFile, writeFile } from "node:fs/promises";
@@ -3843,7 +3844,6 @@ const boardEvents = {
3843
3844
  thread: ThreadKey,
3844
3845
  labels: Labels,
3845
3846
  noSync: z.boolean(),
3846
- mentions: z.array(ActorId),
3847
3847
  by: Author,
3848
3848
  origin: Origin.nullable(),
3849
3849
  from: From,
@@ -3888,7 +3888,6 @@ const boardEvents = {
3888
3888
  id: MessageId,
3889
3889
  thread: ThreadKey,
3890
3890
  text: MessageText,
3891
- mentions: z.array(ActorId),
3892
3891
  by: Author,
3893
3892
  from: From
3894
3893
  }),
@@ -3969,10 +3968,26 @@ const boardEvents = {
3969
3968
  name: z.string().min(1).max(128).refine(storable, "name has a NUL character or a lone surrogate"),
3970
3969
  avatar: z.string().url().nullable(),
3971
3970
  /**
3971
+ * (server) Who an actor with a profile acts through, as the board shows it: its principal's name
3972
+ * (a deployment's project, anyone else's handle), and a deployment's environment.
3973
+ */
3974
+ via: z.object({
3975
+ name: Handle,
3976
+ environment: z.string().min(1).max(128).nullable()
3977
+ }).optional(),
3978
+ /** (server) A platform user's platform (`slack`), as their sync key was registered with: for display. */
3979
+ platform: z.string().min(1).max(64).optional(),
3980
+ /**
3972
3981
  * (server) A principal a host's `authenticate` made, or one of its profiles: someone the board
3973
3982
  * signs in, whatever its ID or kind, so sync never writes as it. Others have none.
3974
3983
  */
3975
- host: z.literal(true).optional()
3984
+ host: z.literal(true).optional(),
3985
+ /**
3986
+ * (server) Whether this write's credential named the actor as shown, rather than taking it from what
3987
+ * the caller sent: under the handle it gave the principal, as itself or after `via`. Unlike `host`,
3988
+ * each `actor.seen` says it anew. Others, and events from before, have none.
3989
+ */
3990
+ verified: z.literal(true).optional()
3976
3991
  })
3977
3992
  };
3978
3993
  const BOARD_SESSION = "board";
@@ -4156,7 +4171,11 @@ const ScheduleIdentity = z.object({
4156
4171
  kind: SeenActorKind,
4157
4172
  handle: Handle,
4158
4173
  name: z.string().min(1).max(128),
4159
- avatar: z.string().nullable()
4174
+ avatar: z.string().nullable(),
4175
+ via: z.object({
4176
+ name: Handle,
4177
+ environment: z.string().min(1).max(128).nullable()
4178
+ }).optional()
4160
4179
  })
4161
4180
  });
4162
4181
  /**
@@ -4332,6 +4351,23 @@ const accessContract = contract({
4332
4351
  }
4333
4352
  });
4334
4353
  const ACCESS_SESSION = "access";
4354
+ /**
4355
+ * The board's schema registry, outside the board log: one session, `schemas`. A version is
4356
+ * registered once and never changes, so its event is all there is of it.
4357
+ */
4358
+ const schemasContract = contract({
4359
+ name: "board-schemas",
4360
+ events: {
4361
+ /** A schema version, for good: `name@version` is its ID, and `schema` the JSON Schema the board checked. */
4362
+ "schema.created": z.object({
4363
+ name: z.string().regex(SCHEMA_NAME),
4364
+ version: z.number().int().min(1).max(SCHEMA_VERSION_MAX),
4365
+ description: z.string().min(1).max(SCHEMA_DESCRIPTION_MAX).nullable(),
4366
+ schema: z.record(z.string(), z.unknown()),
4367
+ by: ActorId
4368
+ }) }
4369
+ });
4370
+ const SCHEMAS_SESSION = "schemas";
4335
4371
  reducer({
4336
4372
  contract: boardContract,
4337
4373
  name: "board.messages.v5",
@@ -4387,16 +4423,34 @@ const HIDDEN = /* @__PURE__ */ new Set([
4387
4423
  "message.synced",
4388
4424
  "message.files_synced"
4389
4425
  ]);
4426
+ /** Whether the board checked who an actor is, as people see them, at their last write (`actor.seen`'s `verified`). */
4427
+ const verifiedRecord = (actor) => actor.verified === true;
4390
4428
  function actorView(actors, id) {
4391
4429
  const author = own(actors.byId, id);
4392
4430
  if (!author) return null;
4431
+ const via = viaOfRecord(author);
4393
4432
  return {
4394
4433
  kind: author.kind,
4395
4434
  handle: author.handle,
4396
4435
  name: author.name,
4397
- avatar: author.avatar
4436
+ avatar: author.avatar,
4437
+ ...via ? { via } : {},
4438
+ ...author.platform ? { platform: author.platform } : {},
4439
+ ...verifiedRecord(author) ? { verified: true } : {}
4398
4440
  };
4399
4441
  }
4442
+ /**
4443
+ * Who an actor with a profile acts through, as its record says. An agent recorded before records
4444
+ * said, whose handle is `<person>/<profile>`, acts through the person its handle names.
4445
+ */
4446
+ function viaOfRecord(actor) {
4447
+ if (actor.via) return { ...actor.via };
4448
+ const slash = actor.handle.indexOf("/");
4449
+ return actorParts(actor.id).profile !== null && slash > 0 ? {
4450
+ name: actor.handle.slice(0, slash),
4451
+ environment: null
4452
+ } : void 0;
4453
+ }
4400
4454
  /** The board's own code, which reads every channel: it needs no messages to say so. */
4401
4455
  const OWN_CODE = {
4402
4456
  access: FULL_ACCESS,
@@ -4462,8 +4516,8 @@ const scheduleRef = (index) => `s${index}`;
4462
4516
  /** The log index a ref names on this board, or null for a string that names nothing here. */
4463
4517
  const indexOf$1 = (value) => /^(0|[1-9]\d{0,15})$/.test(value) ? Number(value) : null;
4464
4518
  /** A message as `reader` sees it. Every view names its reader, so none shows a link's snapshot by default. */
4465
- function view(message, actors, reader) {
4466
- const { blind, version, revision, schedule, ...shown } = message;
4519
+ function view$1(message, actors, reader) {
4520
+ const { blind, version, revision, schedule, platformText, mentions: _mentions, ...shown } = message;
4467
4521
  return {
4468
4522
  ...shown,
4469
4523
  ...blind ? { blind } : {},
@@ -4479,14 +4533,14 @@ function view(message, actors, reader) {
4479
4533
  links: readableLinks(message.links, reader),
4480
4534
  labels: { ...message.labels },
4481
4535
  reactions: Object.fromEntries(Object.entries(message.reactions).map(([emoji, ids]) => [emoji, [...ids]])),
4482
- author: actorView(actors, message.by.actor)
4536
+ author: actorView(actors, message.by.actor),
4537
+ blocks: message.from === null && !platformText ? blocksIn(message.text) : []
4483
4538
  };
4484
4539
  }
4485
4540
  const actorSet = (value, actors) => own(actors.byId, value) ? /* @__PURE__ */ new Set([value]) : new Set(own(actors.byHandle, value.toLowerCase()) ?? []);
4486
4541
  /**
4487
- * Who a `--by` or `--mentions` value covers. A person (`julian`) is everyone they
4488
- * are: their own actor, and their agents (`julian/claude`). An agent or a platform
4489
- * actor is just itself.
4542
+ * Who a `--by` value covers. A person (`julian`) is everyone they are: their own
4543
+ * actor, and their agents (`julian/claude`). An agent or a platform actor is just itself.
4490
4544
  */
4491
4545
  function whoIs(value, actors) {
4492
4546
  const ids = actorSet(value, actors);
@@ -4495,6 +4549,37 @@ function whoIs(value, actors) {
4495
4549
  principals: new Set([...ids].filter((id) => own(actors.byId, id)?.kind === "person"))
4496
4550
  };
4497
4551
  }
4552
+ /**
4553
+ * What a `--mentions` value matches in a message's text (`mentionTerms`): `me` is the caller's handle
4554
+ * and ID. Anyone else is the value as written, and what's under it: a person's agents
4555
+ * (`@julian/claude`), a project's imports (`@support/malte`), and their IDs. A reader of every
4556
+ * channel also gets each actor the value names, by ID or by handle, through their other name: their
4557
+ * handle and ID. Anyone else doesn't, since that would say who goes by what where it can't read.
4558
+ */
4559
+ function mentionFilter(value, context) {
4560
+ if (value === "me") return {
4561
+ terms: context.me === null ? [] : [mentionTerm(context.me.handle), context.me.id],
4562
+ prefixes: []
4563
+ };
4564
+ const under = (name) => name.includes(":") ? `${name}+` : `${mentionTerm(name)}/`;
4565
+ const terms = /* @__PURE__ */ new Set([mentionTerm(value)]);
4566
+ const prefixes = /* @__PURE__ */ new Set([under(value)]);
4567
+ if (!context.access.readsAll) return {
4568
+ terms: [...terms],
4569
+ prefixes: [...prefixes]
4570
+ };
4571
+ for (const id of actorSet(value, context.actors)) {
4572
+ const actor = own(context.actors.byId, id);
4573
+ terms.add(id).add(mentionTerm(actor.handle));
4574
+ prefixes.add(under(actor.handle)).add(under(id));
4575
+ }
4576
+ return {
4577
+ terms: [...terms],
4578
+ prefixes: [...prefixes]
4579
+ };
4580
+ }
4581
+ /** Whether `text` mentions what a `--mentions` filter matches. */
4582
+ const mentionsIn = (text, filter) => mentionTerms(text).some((term) => filter.terms.includes(term) || filter.prefixes.some((prefix) => term.startsWith(prefix)));
4498
4583
  /** Whether `author` is one of `who`: its actor, or an agent of one of its people. */
4499
4584
  const covers = (who, actor, principal) => who.actors.has(actor) || principal !== void 0 && who.principals.has(principal);
4500
4585
  const hasLabel = (labels, [key, values]) => Object.hasOwn(labels, key) && (values === null || values.includes(labels[key]));
@@ -4513,7 +4598,7 @@ function compileFilter(filters, context) {
4513
4598
  const subtree = channel?.endsWith("/") ? channel.slice(0, -1) : null;
4514
4599
  const by = filters.by === void 0 ? null : whoIs(filters.by, context.actors);
4515
4600
  const re = filters.re === void 0 ? void 0 : indexOf$1(filters.re) ?? -1;
4516
- const mentions = filters.mentions === void 0 ? null : filters.mentions === "me" ? new Set(context.me === null ? [] : [context.me]) : whoIs(filters.mentions, context.actors).actors;
4601
+ const mentions = filters.mentions === void 0 ? null : mentionFilter(filters.mentions, context);
4517
4602
  return (message) => {
4518
4603
  if (!message || !access.readable(message.channel)) return false;
4519
4604
  if (channel !== void 0) {
@@ -4523,7 +4608,7 @@ function compileFilter(filters, context) {
4523
4608
  }
4524
4609
  if (re !== void 0 && message.id !== re && message.re !== re) return false;
4525
4610
  if (by !== null && !covers(by, message.by.actor, message.by.principal)) return false;
4526
- if (mentions !== null && !message.mentions.some((id) => mentions.has(id))) return false;
4611
+ if (mentions !== null && !mentionsIn(message.text, mentions)) return false;
4527
4612
  if (filters.from !== void 0 && (message.from ?? "board") !== filters.from) return false;
4528
4613
  if (text !== void 0 && !message.text.toLowerCase().includes(text)) return false;
4529
4614
  if (labels.length > 0) {
@@ -4547,7 +4632,7 @@ function readableFilter(filter, known, access) {
4547
4632
  channels: [...known].filter((path) => within(path) && access.readable(path))
4548
4633
  };
4549
4634
  }
4550
- /** The filters as the tables take them: handles resolved to who they cover, `me` to the caller. */
4635
+ /** The filters as the tables take them: handles resolved to who they cover, mentions to the terms they match. */
4551
4636
  function toMessageFilter(filters, context) {
4552
4637
  const out = {};
4553
4638
  const channel = filters.channel;
@@ -4566,7 +4651,7 @@ function toMessageFilter(filters, context) {
4566
4651
  principals: [...who.principals]
4567
4652
  };
4568
4653
  }
4569
- if (filters.mentions !== void 0) out.mentions = filters.mentions === "me" ? context.me === null ? [] : [context.me] : [...whoIs(filters.mentions, context.actors).actors];
4654
+ if (filters.mentions !== void 0) out.mentions = mentionFilter(filters.mentions, context);
4570
4655
  if (filters.from !== void 0) out.from = filters.from;
4571
4656
  if (filters.text !== void 0) out.text = filters.text.toLowerCase();
4572
4657
  if (filters.label?.length) out.labels = filters.label.map(([key, values]) => ({
@@ -4630,7 +4715,7 @@ function eventView(event, after, actors, reader) {
4630
4715
  type: event.type,
4631
4716
  createdAt: iso(event.createdAt),
4632
4717
  payload: payloadView(event.payload, links ? readableLinks(links, reader) : void 0),
4633
- ...after ? { message: view(after, actors, reader) } : {},
4718
+ ...after ? { message: view$1(after, actors, reader) } : {},
4634
4719
  ...actor ? { actor: {
4635
4720
  id: actor.id,
4636
4721
  ...actorView(actors, actor.id)
@@ -4639,7 +4724,7 @@ function eventView(event, after, actors, reader) {
4639
4724
  }
4640
4725
  /** An event's payload as clients see it: the message IDs in it are refs. */
4641
4726
  function payloadView(payload, links) {
4642
- const shown = { ...payload };
4727
+ const { mentions: _mentions, ...shown } = payload;
4643
4728
  for (const key of [
4644
4729
  "id",
4645
4730
  "re",
@@ -4840,22 +4925,34 @@ function deploymentIdentity(actor, handle) {
4840
4925
  }
4841
4926
  /**
4842
4927
  * The `actor.seen` a write carries, or null: who its author is, as the board's record of them
4843
- * says, unless the board knows that already. A platform user's record is board-wide, so a write
4844
- * whose identity doesn't keep it (`records: false`) leaves it as it is. A host's principal and its
4845
- * profiles are recorded as the host's, which sync never writes as.
4928
+ * says, unless the board knows that already. A host's principal and its profiles are recorded as
4929
+ * the host's, which sync never writes as.
4846
4930
  */
4847
4931
  function seenFor(identity, actors) {
4848
- if (identity.records === false) return null;
4849
- return actorSeen(identity.actor, actors, identity.principal.facts?.issuer === "host");
4850
- }
4851
- /** The actors a write can mention: the ones the board knows, plus the ones an email named. */
4852
- const knownWith = (actors, found) => found.length === 0 ? actors : {
4853
- ...actors,
4854
- byId: {
4855
- ...actors.byId,
4856
- ...Object.fromEntries(found.map((a) => [a.id, a]))
4857
- }
4858
- };
4932
+ const { verified: _verified, ...actor } = identity.actor;
4933
+ return actorSeen(verifiedAs(identity) ? {
4934
+ ...actor,
4935
+ verified: true
4936
+ } : actor, actors, identity.principal.facts?.issuer === "host");
4937
+ }
4938
+ /**
4939
+ * Whether the board checked who a write is by, as it shows them: a principal a credential named
4940
+ * (an OIDC token it trusts, a board token, or a host's verifier; never the board's own code), under
4941
+ * the handle that credential gave it. An agent shows that principal after `via`, and its profile
4942
+ * name is the principal's to choose; a person, deployment, or workflow writing as itself shows the
4943
+ * handle as its name, which a display name its client sends replaces. An import says for itself.
4944
+ */
4945
+ function verifiedAs({ principal, author, actor }) {
4946
+ if (principal.kind === "external") return actor.verified === true;
4947
+ if (principal.id.startsWith("board:")) return false;
4948
+ if (author.profile !== null) return actor.via !== void 0 && actor.via.name === viaOf(principal).name;
4949
+ return actor.name === principal.handle && actor.handle === principal.handle;
4950
+ }
4951
+ /**
4952
+ * Whether `identity` wrote `message`, to change it as its author: its principal did, as itself or
4953
+ * any of its agents, and a platform user a sync speaks for only as that same user.
4954
+ */
4955
+ const authored = (message, identity) => message.by.principal === identity.principal.id && (platformProfile(identity.author.profile) === null || message.by.actor === identity.author.actor);
4859
4956
  const messageNotFound = (id) => () => notFound(`message not found: #${id}`, "message_not_found");
4860
4957
  /**
4861
4958
  * A message the board looked up and the caller may act on with `permission`,
@@ -4989,7 +5086,7 @@ async function landedFor(ctx, identity, landed) {
4989
5086
  if (!sameAuthor(landed.by, identity.author)) return null;
4990
5087
  const { access } = identity.principal;
4991
5088
  const { state: actors } = await ctx.session.state(actorsReducer);
4992
- if (access.readable(landed.channel)) return view(landed, actors, await readerFor(ctx, access, landed));
5089
+ if (access.readable(landed.channel)) return view$1(landed, actors, await readerFor(ctx, access, landed));
4993
5090
  if (!landed.blind) return null;
4994
5091
  const [event] = await ctx.session.history({
4995
5092
  gte: landed.id,
@@ -5000,15 +5097,14 @@ async function landedFor(ctx, identity, landed) {
5000
5097
  replies: {}
5001
5098
  }, event).byId[landed.id];
5002
5099
  return {
5003
- ...view(posted, actors, await readerFor(ctx, access, posted)),
5004
- text: blindText(posted.text, identity.actor.id),
5005
- mentions: []
5100
+ ...view$1(posted, actors, await readerFor(ctx, access, posted)),
5101
+ text: blindText(posted.text, identity.actor.id)
5006
5102
  };
5007
5103
  }
5008
5104
  /**
5009
5105
  * A message's text for its writer where it can't read: each exact mention but of itself shows as
5010
- * `@…`. The board may have turned an email it wrote into an actor ID, and who that is, `/actors`
5011
- * doesn't show it either.
5106
+ * `@…`. The board turned an email it wrote into an actor ID before mentions were text, and a sync's
5107
+ * import names its own profiles: who those are, `/actors` doesn't show it either.
5012
5108
  */
5013
5109
  const blindText = (text, own) => replaceMentions(text, (token) => token.kind === "actor" && token.actor !== own ? "@…" : null);
5014
5110
  const sameAuthor = (a, b) => a.actor === b.actor && a.principal === b.principal && a.profile === b.profile && a.session === b.session;
@@ -5026,9 +5122,6 @@ async function commitPost(ctx, input, placed) {
5026
5122
  });
5027
5123
  }
5028
5124
  const seen = seenFor(identity, actors);
5029
- const { text, found } = await withEmailMentions(input.text);
5030
- const named = found.map((actor) => actorSeen(actor, actors)).filter((event) => event !== null);
5031
- const { mentions, unknown } = resolveMentions(text, knownWith(actors, found), seen ? identity.actor : void 0, input.lenientMentions ?? false, identity.principal.access.readsAll);
5032
5125
  const synced = await Promise.all(targets.map(async ({ target, kind, cause }) => ({
5033
5126
  type: "thread.synced",
5034
5127
  id: await derivedId("board", thread, "sync", target),
@@ -5042,19 +5135,17 @@ async function commitPost(ctx, input, placed) {
5042
5135
  })));
5043
5136
  const events = [
5044
5137
  ...seen ? [seen] : [],
5045
- ...named,
5046
5138
  {
5047
5139
  type: "message.posted",
5048
5140
  ...id ? { id } : {},
5049
5141
  payload: {
5050
5142
  channel,
5051
- text,
5143
+ text: input.text,
5052
5144
  re,
5053
5145
  replyTo,
5054
5146
  thread,
5055
5147
  labels: input.labels ?? {},
5056
5148
  noSync: input.noSync ?? false,
5057
- mentions,
5058
5149
  by: identity.author,
5059
5150
  origin: input.origin ?? null,
5060
5151
  from: input.from ?? null,
@@ -5089,25 +5180,22 @@ async function commitPost(ctx, input, placed) {
5089
5180
  ...actors,
5090
5181
  byId: {
5091
5182
  ...actors.byId,
5092
- [identity.actor.id]: identity.actor
5183
+ [identity.actor.id]: {
5184
+ ...identity.actor,
5185
+ ...seen.payload.host ? { host: true } : {},
5186
+ ...seen.payload.verified ? { verified: true } : {}
5187
+ }
5093
5188
  }
5094
5189
  } : actors;
5095
- return shownTo(view(message, known, await readerFor(ctx, identity.principal.access, message)), identity.principal.access, sent, unknown);
5190
+ return shownTo(view$1(message, known, await readerFor(ctx, identity.principal.access, message)), identity.principal.access, sent);
5096
5191
  }
5097
5192
  /**
5098
5193
  * A post's view for its writer. One that can't read the channel gets back the
5099
- * text it sent, no mentions, and no `unknownMentions`: the board resolved its
5100
- * handles and emails to actor IDs, which `/actors` doesn't show it, and which
5101
- * handles matched no one would say which ones exist. The board keeps the
5102
- * mentions, so they still notify.
5194
+ * text it sent: what the board made of it (the middleware's changes) is for its readers.
5103
5195
  */
5104
- const shownTo = (shown, access, sent, unknown = []) => !access.readable(shown.channel) ? {
5105
- ...shown,
5106
- text: sent,
5107
- mentions: []
5108
- } : unknown.length ? {
5196
+ const shownTo = (shown, access, sent) => !access.readable(shown.channel) ? {
5109
5197
  ...shown,
5110
- unknownMentions: unknown
5198
+ text: sent
5111
5199
  } : shown;
5112
5200
  /** The writer, as the reader of the view its write returns. Only a link to a board message needs a lookup. */
5113
5201
  const readerFor = (ctx, access, message) => ctx.reads.reader(access, [message]);
@@ -5190,7 +5278,7 @@ function spent(authorized, permission) {
5190
5278
  }
5191
5279
  async function writeEdit(ctx, input) {
5192
5280
  const message = spent(input.authorized, "post");
5193
- if (input.asAuthor !== false && message.by.principal !== input.identity.principal.id) throw forbidden$1("only the author can edit a message");
5281
+ if (input.asAuthor !== false && !authored(message, input.identity)) throw forbidden$1("only the author can edit a message");
5194
5282
  if (message.deleted) {
5195
5283
  if (input.revision !== void 0 && input.revision !== (message.revision ?? message.id)) throw new HttpError(409, "revision_conflict", `#${message.id} was deleted since revision ${input.revision}`);
5196
5284
  throw badRequest("message was deleted", "message_deleted");
@@ -5200,26 +5288,17 @@ async function writeEdit(ctx, input) {
5200
5288
  async function commitEdit(ctx, input, message) {
5201
5289
  const { state: actors } = await ctx.session.state(actorsReducer);
5202
5290
  const seen = seenFor(input.identity, actors);
5203
- const { text, found } = await withEmailMentions(input.text);
5204
- const named = found.map((actor) => actorSeen(actor, actors)).filter((event) => event !== null);
5205
- const { mentions, unknown } = resolveMentions(text, knownWith(actors, found), seen ? input.identity.actor : void 0, input.from != null, input.identity.principal.access.readsAll);
5206
- const events = [
5207
- ...seen ? [seen] : [],
5208
- ...named,
5209
- {
5210
- type: "message.edited",
5211
- payload: {
5212
- id: message.id,
5213
- thread: message.thread,
5214
- text,
5215
- mentions,
5216
- by: input.identity.author,
5217
- from: input.from ?? null
5218
- }
5291
+ const events = [...seen ? [seen] : [], {
5292
+ type: "message.edited",
5293
+ payload: {
5294
+ id: message.id,
5295
+ thread: message.thread,
5296
+ text: input.text,
5297
+ by: input.identity.author,
5298
+ from: input.from ?? null
5219
5299
  }
5220
- ];
5300
+ }];
5221
5301
  await untilApplied(ctx, input.revision === void 0 ? await ctx.session.append(...events) : await appendWhile(ctx, revisionIs(ctx, message.id, input.revision), events));
5222
- return unknown.length && input.identity.principal.access.readable(message.channel) ? { unknownMentions: unknown } : {};
5223
5302
  }
5224
5303
  /** A message's links, replaced: a platform edit or unfurl changed what it links to. */
5225
5304
  async function writeLinks(ctx, input) {
@@ -5238,7 +5317,7 @@ async function writeLinks(ctx, input) {
5238
5317
  }
5239
5318
  async function writeDelete(ctx, input) {
5240
5319
  const message = spent(input.authorized, "post");
5241
- if (input.asAuthor !== false && message.by.principal !== input.identity.principal.id) throw forbidden$1("only the author can delete a message");
5320
+ if (input.asAuthor !== false && !authored(message, input.identity)) throw forbidden$1("only the author can delete a message");
5242
5321
  if (message.deleted) {
5243
5322
  if (input.revision !== void 0 && input.revision !== (message.revision ?? message.id)) throw new HttpError(409, "revision_conflict", `#${message.id} was deleted since revision ${input.revision}`);
5244
5323
  return;
@@ -5380,9 +5459,9 @@ const TOKEN_DEPTH_MAX = 8;
5380
5459
  /**
5381
5460
  * The grants a board starts with, as a team's board in Vercel's API does: g1, every person may do
5382
5461
  * everything (no team roles cap it here), g2, every project on the board's team, in every
5383
- * environment, reads, posts, reacts, and labels everywhere, and g3, every app on the team, the
5384
- * same. A local board has no apps, so g3 names no one here, but the defaults are the same
5385
- * everywhere. Revoke or change them like any other.
5462
+ * environment, reads, posts, reacts, labels, and syncs everywhere, and g3, every app on the team,
5463
+ * reads, posts, reacts, and labels. A local board has no apps, so g3 names no one here, but the
5464
+ * defaults are the same everywhere. Revoke or change them like any other.
5386
5465
  */
5387
5466
  const STARTING_GRANTS = {
5388
5467
  1: {
@@ -5408,7 +5487,8 @@ const STARTING_GRANTS = {
5408
5487
  "read",
5409
5488
  "post",
5410
5489
  "react",
5411
- "label"
5490
+ "label",
5491
+ "sync"
5412
5492
  ] },
5413
5493
  by: null,
5414
5494
  at: null
@@ -5526,7 +5606,7 @@ function foldAccess(state, event) {
5526
5606
  }
5527
5607
  const accessReducer = reducer({
5528
5608
  contract: accessContract,
5529
- name: "board.access.v2",
5609
+ name: "board.access.v3",
5530
5610
  initialState: startingAccess()
5531
5611
  }).fold(foldAccess);
5532
5612
  const grantId = (id) => `g${id}`;
@@ -6056,6 +6136,108 @@ function createTrust(options) {
6056
6136
  };
6057
6137
  }
6058
6138
  //#endregion
6139
+ //#region src/server/schemas.ts
6140
+ /** The schemas session's fold: a version is its first event, and nothing changes it after. */
6141
+ function foldSchemas(state, event) {
6142
+ const { name, version, description, schema, by } = event.payload;
6143
+ state.byId[schemaId(name, version)] ??= {
6144
+ name,
6145
+ version,
6146
+ description,
6147
+ schema,
6148
+ by,
6149
+ at: new Date(event.createdAt).getTime()
6150
+ };
6151
+ return state;
6152
+ }
6153
+ const schemasReducer = reducer({
6154
+ contract: schemasContract,
6155
+ name: "board.schemas.v1",
6156
+ initialState: { byId: {} }
6157
+ }).fold(foldSchemas);
6158
+ const builtIns = BUILT_IN_SCHEMAS.map((schema) => ({
6159
+ id: schemaId(schema.name, schema.version),
6160
+ ...schema,
6161
+ builtIn: true,
6162
+ by: null,
6163
+ at: null
6164
+ }));
6165
+ const view = (row) => ({
6166
+ id: schemaId(row.name, row.version),
6167
+ name: row.name,
6168
+ version: row.version,
6169
+ description: row.description,
6170
+ schema: row.schema,
6171
+ builtIn: false,
6172
+ by: row.by,
6173
+ at: new Date(row.at).toISOString()
6174
+ });
6175
+ /**
6176
+ * The board's schema registry, in session `schemas` of its log: what a local board answers for
6177
+ * them. Anyone the board let in reads it, and registering takes `manage` at `*`, since a schema is
6178
+ * the whole board's.
6179
+ */
6180
+ function createSchemas(options) {
6181
+ const session = createServer({
6182
+ contract: schemasContract,
6183
+ store: options.store
6184
+ }).session(SCHEMAS_SESSION);
6185
+ const read = async () => (await session.state(schemasReducer)).state;
6186
+ /** The registry as it is now, and the index a conditional write holds it at. */
6187
+ const latest = () => session.state(schemasReducer, { through: "latest" });
6188
+ return {
6189
+ async schemas() {
6190
+ const own = Object.values((await read()).byId).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : a.version - b.version);
6191
+ return { schemas: [...builtIns, ...own.map(view)] };
6192
+ },
6193
+ async schema({ id }) {
6194
+ if (!parseSchemaId(id)) throw badRequest(`${id} doesn't name a schema: one is name@version, like sandbox@1`, "invalid_schema_id");
6195
+ const builtIn = builtIns.find((schema) => schema.id === id);
6196
+ if (builtIn) return { schema: builtIn };
6197
+ const row = (await read()).byId[id];
6198
+ if (!row) throw notFound(`schema not found: ${id}`, "schema_not_found");
6199
+ return { schema: view(row) };
6200
+ },
6201
+ async createSchema({ principal, actor }, body) {
6202
+ if (!principal.access.at("manage", "*")) throw forbidden$1("this token can't register schemas: it needs manage at *");
6203
+ const id = schemaId(body.name, body.version);
6204
+ if (isBuiltInName(body.name)) throw new HttpError(409, "reserved_schema", `${body.name} is a built-in schema: register yours under another name`);
6205
+ const problem = checkDefinition(body.schema);
6206
+ if (problem !== null) throw badRequest(problem, "invalid_schema");
6207
+ const description = body.description ?? null;
6208
+ return whileHeadMoves(async () => {
6209
+ const { state, index } = await latest();
6210
+ const existing = state.byId[id];
6211
+ if (existing) {
6212
+ const differs = canonical(existing.schema) !== canonical(body.schema) ? "definition" : existing.description !== description ? "description" : null;
6213
+ if (differs !== null) throw new HttpError(409, "schema_immutable", `${id} is registered with another ${differs}, and a version never changes: register a new version`);
6214
+ return {
6215
+ schema: view(existing),
6216
+ created: false
6217
+ };
6218
+ }
6219
+ if (Object.keys(state.byId).length >= 500) throw badRequest(`a board registers at most 500 schema versions`, "too_many_schemas");
6220
+ await session.append.ifLastIndex(index, {
6221
+ type: "schema.created",
6222
+ payload: {
6223
+ name: body.name,
6224
+ version: body.version,
6225
+ description,
6226
+ schema: body.schema,
6227
+ by: actor.id
6228
+ }
6229
+ });
6230
+ const made = (await read()).byId[id];
6231
+ if (!made) throw new Error("a schema was registered but its log has no record of it");
6232
+ return {
6233
+ schema: view(made),
6234
+ created: true
6235
+ };
6236
+ });
6237
+ }
6238
+ };
6239
+ }
6240
+ //#endregion
6059
6241
  //#region src/server/blob.ts
6060
6242
  /** Files in memory, for tests: forgets everything when the process ends. */
6061
6243
  function memoryBlob() {
@@ -6556,6 +6738,11 @@ const createdBy = (schedule, identity) => wroteAs(identity, {
6556
6738
  }) && identity.principal.access.can("post", schedule.channel) && (schedule.blind || identity.principal.access.readable(schedule.channel));
6557
6739
  const scheduleView = (schedule, actors) => {
6558
6740
  const author = actors.byId[schedule.as.actor.id] ?? schedule.as.actor;
6741
+ const via = viaOfRecord({
6742
+ id: schedule.as.actor.id,
6743
+ handle: author.handle,
6744
+ via: "via" in author ? author.via : void 0
6745
+ });
6559
6746
  return {
6560
6747
  id: scheduleRef(schedule.id),
6561
6748
  channel: schedule.channel,
@@ -6578,7 +6765,8 @@ const scheduleView = (schedule, actors) => {
6578
6765
  kind: author.kind,
6579
6766
  handle: author.handle,
6580
6767
  name: author.name,
6581
- avatar: author.avatar
6768
+ avatar: author.avatar,
6769
+ ...via ? { via } : {}
6582
6770
  },
6583
6771
  createdAt: schedule.createdAt
6584
6772
  };
@@ -6834,9 +7022,6 @@ function createSchedules(options) {
6834
7022
  const until = expires !== null && (asked === null || asked > expires) ? expires : asked;
6835
7023
  if (until !== null && until < first) throw badRequest("the schedule stops before its first send");
6836
7024
  if (first > now + 316224e5 || until !== null && until > now + 316224e5) throw badRequest("a schedule reaches at most a year out: its first send and its stop");
6837
- const { state: known } = await writes.session.state(actorsReducer);
6838
- const withoutEmails = replaceMentions(body.text, (t) => t.kind === "actor" && t.actor.includes("@") ? t.actor : null);
6839
- const { unknown } = resolveMentions(withoutEmails, known, identity.actor, false, identity.principal.access.readsAll);
6840
7025
  let channel = body.channel;
6841
7026
  let re = null;
6842
7027
  if (body.re !== void 0) {
@@ -6870,11 +7055,7 @@ function createSchedules(options) {
6870
7055
  const created = state.byId[row.index];
6871
7056
  if (created.next !== null) await arm("first", created.id, created.sent, created.next);
6872
7057
  const { state: actors } = await writes.session.state(actorsReducer);
6873
- const schedule = scheduleView(created, actors);
6874
- return unknown.length && identity.principal.access.readable(channel) ? {
6875
- schedule,
6876
- unknownMentions: unknown
6877
- } : { schedule };
7058
+ return { schedule: scheduleView(created, actors) };
6878
7059
  },
6879
7060
  /**
6880
7061
  * Its creator may cancel it while they can post there, and so may `manage`
@@ -7022,7 +7203,7 @@ function createWatchers(options) {
7022
7203
  const by = event.payload.by?.actor;
7023
7204
  const message = after ?? before;
7024
7205
  const thread = event.payload.thread;
7025
- let view$1;
7206
+ let view;
7026
7207
  /** Each session's matches, appended together: one append per watcher in config, one per registrant. */
7027
7208
  const appends = /* @__PURE__ */ new Map();
7028
7209
  const add = (session, matched) => (appends.get(session) ?? appends.set(session, []).get(session)).push(matched);
@@ -7053,7 +7234,7 @@ function createWatchers(options) {
7053
7234
  });
7054
7235
  if (!(watcher.criteria ? match(before) || match(after) : id !== null)) continue;
7055
7236
  const key = registration ? `@${registration.owner}/${watcher.id}` : watcher.id;
7056
- const shown = registration ? eventView(event, after, actors, await reads.reader(access, after ? [after] : [])) : view$1 ??= eventView(event, after, actors, OWN_CODE);
7237
+ const shown = registration ? eventView(event, after, actors, await reads.reader(access, after ? [after] : [])) : view ??= eventView(event, after, actors, OWN_CODE);
7057
7238
  add(registration ? registrantSession(registration.owner) : watchSession(watcher.id), {
7058
7239
  type: "watch.matched",
7059
7240
  id: await idempotentId("board-watch", key, event.id),
@@ -7073,7 +7254,7 @@ function createWatchers(options) {
7073
7254
  const reader = await reads.reader(now, [about, ...before ? [before] : []]);
7074
7255
  const shown = {
7075
7256
  ...eventView(event, about, actors, reader),
7076
- ...event.type === "labels.changed" && before ? { before: view(before, actors, reader) } : {}
7257
+ ...event.type === "labels.changed" && before ? { before: view$1(before, actors, reader) } : {}
7077
7258
  };
7078
7259
  add(registrantSession(registration.owner), {
7079
7260
  type: "watch.matched",
@@ -7381,8 +7562,6 @@ function failure(found, error) {
7381
7562
  }
7382
7563
  //#endregion
7383
7564
  //#region src/server/a2.ts
7384
- /** Sync's own lookups and receipts, from board() in this deployment. */
7385
- const SYNC_ACTOR = "board:sync";
7386
7565
  /** The board's own code, through its handle: `team.post(…)`. With `as(profile)`, `board:client:<profile>`. */
7387
7566
  const CLIENT_ACTOR = "board:client";
7388
7567
  /** A cursor or message ref in a request, as this board's log index: decimals, from 0. */
@@ -7445,6 +7624,11 @@ function selfIdentity(caller) {
7445
7624
  if (!ID.test(self)) throw badRequest(`as: profiles use lowercase letters, numbers, - and _, got: ${self}`);
7446
7625
  return deploymentIdentity(`${CLIENT_ACTOR}:${self}`, self);
7447
7626
  }
7627
+ /** An actor's name as people see it, with who it acts through: `Malte via www (preview)`. */
7628
+ const shownOf = (actor) => actor ? shownName({
7629
+ name: actor.name,
7630
+ via: viaOfRecord(actor)
7631
+ }) : void 0;
7448
7632
  /** A schedule as its creator sees it where it can't read: its text as a blind writer's message's is. */
7449
7633
  const blindSchedule = (schedule, access, own) => access.readable(schedule.channel) ? schedule : {
7450
7634
  ...schedule,
@@ -7452,32 +7636,40 @@ const blindSchedule = (schedule, access, own) => access.readable(schedule.channe
7452
7636
  };
7453
7637
  /**
7454
7638
  * A platform user, writing through sync: full access, and each write still proved against the
7455
- * channel it lands in. Their avatar is an https URL or none. `records`: the write keeps the
7456
- * board's record of who they are, which only a sync that may sync everywhere does.
7639
+ * channel it lands in. Their avatar is an https URL or none. This board's own sync checked the
7640
+ * platform said so, so its platform users are themselves (`slack:user:U0456`); a sync elsewhere's
7641
+ * are its word, a profile of its principal (`vercel:project:prj_1:production+slack:user:U0456`),
7642
+ * whose record only its own imports change.
7457
7643
  */
7458
- function externalIdentity(author, records) {
7644
+ function externalIdentity(author, through, platform) {
7645
+ const id = through === null ? author.id : `${through.id}+${author.id}`;
7646
+ const host = through?.facts?.issuer === "host" ? { facts: through.facts } : {};
7647
+ const principal = {
7648
+ id: through?.id ?? author.id,
7649
+ kind: "external",
7650
+ handle: author.handle,
7651
+ access: FULL_ACCESS,
7652
+ expiresAt: null,
7653
+ ...host
7654
+ };
7459
7655
  return {
7460
- principal: {
7461
- id: author.id,
7462
- kind: "external",
7463
- handle: author.handle,
7464
- access: FULL_ACCESS,
7465
- expiresAt: null
7466
- },
7656
+ principal,
7467
7657
  author: {
7468
- actor: author.id,
7469
- principal: author.id,
7470
- profile: null,
7658
+ actor: id,
7659
+ principal: principal.id,
7660
+ profile: through === null ? null : author.id,
7471
7661
  session: null
7472
7662
  },
7473
7663
  actor: {
7474
- id: author.id,
7664
+ id,
7475
7665
  kind: "external",
7476
- handle: author.handle,
7666
+ handle: through === null ? author.handle : importedHandle(viaOf(through).name, author.handle, userIdOf(author.id)),
7477
7667
  name: author.name,
7478
- avatar: platformAvatar(author.avatar)
7479
- },
7480
- ...records ? {} : { records: false }
7668
+ avatar: platformAvatar(author.avatar),
7669
+ ...through === null ? {} : { via: viaOf(through) },
7670
+ platform,
7671
+ ...through !== null && !through.id.startsWith("board:") ? { verified: true } : {}
7672
+ }
7481
7673
  };
7482
7674
  }
7483
7675
  /** The board events sync delivers: what a platform shows, and a thread's new targets. */
@@ -7559,7 +7751,7 @@ function build(options, binding) {
7559
7751
  const { before, after } = foldEvent(messages, actors, event);
7560
7752
  const shown = {
7561
7753
  ...eventView(event, event.type === "thread.synced" ? (await reads.ensure(event.index - 1, ctx.signal), await store.tables.byEventId(event.payload.thread)) ?? void 0 : after, actors, OWN_CODE),
7562
- ...event.type === "labels.changed" && before ? { before: view(before, actors, OWN_CODE) } : {}
7754
+ ...event.type === "labels.changed" && before ? { before: view$1(before, actors, OWN_CODE) } : {}
7563
7755
  };
7564
7756
  await delivering.run(ctx, () => binding.run(SYNC, shown, {
7565
7757
  trigger: ctx.event.id,
@@ -7612,6 +7804,7 @@ function build(options, binding) {
7612
7804
  explain: (principal, channel) => binding.explain(principal, channel),
7613
7805
  team: async () => (await binding.project()).teamId
7614
7806
  });
7807
+ const schemaRegistry = createSchemas({ store: log });
7615
7808
  const inboxes = inboxServer.session(INBOXES_SESSION);
7616
7809
  /** The inboxes this instance knows have an `inbox.opened`, so most pushes write nothing more. */
7617
7810
  const opened = /* @__PURE__ */ new Set();
@@ -7647,7 +7840,7 @@ function build(options, binding) {
7647
7840
  through: index
7648
7841
  };
7649
7842
  }
7650
- /** Who wrote, was mentioned, or reacted in the channels `access` reads, a page at a time. */
7843
+ /** Who wrote, was mentioned by actor ID (`@[actor-id]`), or reacted in the channels `access` reads, a page at a time. */
7651
7844
  async function actorsIn(access) {
7652
7845
  const ids = /* @__PURE__ */ new Set();
7653
7846
  const { filter } = await readable({}, access);
@@ -7658,7 +7851,7 @@ function build(options, binding) {
7658
7851
  });
7659
7852
  for (const message of messages) {
7660
7853
  ids.add(message.by.actor);
7661
- for (const id of message.mentions) ids.add(id);
7854
+ for (const token of extractMentions(message.text)) if (token.kind === "actor" && !isEmail(token.actor)) ids.add(token.actor);
7662
7855
  for (const reactors of Object.values(message.reactions)) for (const id of reactors) ids.add(id);
7663
7856
  }
7664
7857
  if (messages.length < 500) return ids;
@@ -7703,7 +7896,7 @@ function build(options, binding) {
7703
7896
  if (fromRequest(caller) && body.id?.startsWith("sync:")) throw badRequest("id: sync:… IDs are what sync imports, under the principal that imports them");
7704
7897
  const attachments = await attachmentsFor(principal, body.attachments);
7705
7898
  const { schedule } = caller.origin;
7706
- const { unknownMentions, ...message } = await writePost(writes, {
7899
+ return { message: await writePost(writes, {
7707
7900
  attachments,
7708
7901
  identity,
7709
7902
  proofs,
@@ -7715,15 +7908,8 @@ function build(options, binding) {
7715
7908
  id: body.id,
7716
7909
  sync: body.sync,
7717
7910
  after: afterAt(body.after),
7718
- ...schedule && !fromRequest(caller) ? {
7719
- schedule,
7720
- lenientMentions: true
7721
- } : {}
7722
- });
7723
- return {
7724
- message,
7725
- ...unknownMentions ? { unknownMentions } : {}
7726
- };
7911
+ ...schedule && !fromRequest(caller) ? { schedule } : {}
7912
+ }) };
7727
7913
  }
7728
7914
  /**
7729
7915
  * The sync entry an import says it came through, when it names one: one its caller syncs, or a
@@ -7755,6 +7941,7 @@ function build(options, binding) {
7755
7941
  name: actor.name,
7756
7942
  avatar: actor.avatar,
7757
7943
  profile: author.profile,
7944
+ ...actor.via ? { via: { ...actor.via } } : {},
7758
7945
  session: author.session,
7759
7946
  expiresAt: principal.expiresAt?.toISOString() ?? null,
7760
7947
  can: principal.access.summary()
@@ -7784,7 +7971,15 @@ function build(options, binding) {
7784
7971
  seen = (id) => ids.has(id);
7785
7972
  }
7786
7973
  return {
7787
- actors: Object.values(state.byId).filter((a) => seen === null || seen(a.id)).sort((a, b) => a.handle.localeCompare(b.handle)).map(({ host: _host, ...a }) => a),
7974
+ actors: Object.values(state.byId).filter((a) => seen === null || seen(a.id)).sort((a, b) => a.handle.localeCompare(b.handle)).map((found) => {
7975
+ const { host: _host, via: _via, ...a } = found;
7976
+ const via = viaOfRecord(found);
7977
+ return {
7978
+ ...a,
7979
+ ...via ? { via } : {},
7980
+ ...verifiedRecord(found) ? { verified: true } : {}
7981
+ };
7982
+ }),
7788
7983
  cursor: ref(index)
7789
7984
  };
7790
7985
  },
@@ -7792,8 +7987,12 @@ function build(options, binding) {
7792
7987
  const { principal, actor } = await identityOf(caller);
7793
7988
  const { state: actors } = await session.state(actorsReducer);
7794
7989
  const { filter, through } = await readable(toMessageFilter(query, {
7795
- me: actor.id,
7796
- actors
7990
+ me: {
7991
+ id: actor.id,
7992
+ handle: actor.handle
7993
+ },
7994
+ actors,
7995
+ access: principal.access
7797
7996
  }), principal.access);
7798
7997
  const { messages, position } = await reads.messages(filter, {
7799
7998
  ...query.before !== void 0 ? { before: cursorAt(query.before) } : {},
@@ -7802,7 +8001,7 @@ function build(options, binding) {
7802
8001
  });
7803
8002
  const reader = await reads.reader(principal.access, messages);
7804
8003
  return {
7805
- messages: messages.map((m) => view(m, actors, reader)),
8004
+ messages: messages.map((m) => view$1(m, actors, reader)),
7806
8005
  cursor: ref(Math.min(position, through))
7807
8006
  };
7808
8007
  },
@@ -7810,8 +8009,12 @@ function build(options, binding) {
7810
8009
  const { principal, actor } = await identityOf(caller);
7811
8010
  const { state: actors } = await session.state(actorsReducer);
7812
8011
  const { filter, through } = await readable(toMessageFilter(query, {
7813
- me: actor.id,
7814
- actors
8012
+ me: {
8013
+ id: actor.id,
8014
+ handle: actor.handle
8015
+ },
8016
+ actors,
8017
+ access: principal.access
7815
8018
  }), principal.access);
7816
8019
  const { threads, position } = await reads.threads(filter, {
7817
8020
  ...query.after !== void 0 ? { after: cursorAt(query.after) } : {},
@@ -7820,9 +8023,9 @@ function build(options, binding) {
7820
8023
  const reader = await reads.reader(principal.access, threads.flatMap((t) => t.last ? [t.root, t.last] : [t.root]));
7821
8024
  return {
7822
8025
  threads: threads.map((t) => ({
7823
- message: view(t.root, actors, reader),
8026
+ message: view$1(t.root, actors, reader),
7824
8027
  replies: t.replies,
7825
- last: t.last && view(t.last, actors, reader)
8028
+ last: t.last && view$1(t.last, actors, reader)
7826
8029
  })),
7827
8030
  cursor: ref(Math.min(position, through))
7828
8031
  };
@@ -7836,8 +8039,8 @@ function build(options, binding) {
7836
8039
  const [root, ...replies] = messages;
7837
8040
  const reader = await reads.reader(principal.access, messages);
7838
8041
  return {
7839
- message: view(root, actors, reader),
7840
- replies: replies.map((reply) => view(reply, actors, reader)),
8042
+ message: view$1(root, actors, reader),
8043
+ replies: replies.map((reply) => view$1(reply, actors, reader)),
7841
8044
  cursor: ref(cursor),
7842
8045
  schedules: await schedules.forThread(root.id)
7843
8046
  };
@@ -7855,16 +8058,13 @@ function build(options, binding) {
7855
8058
  async edit(caller, { id, text, revision }) {
7856
8059
  const identity = await identityOf(caller);
7857
8060
  const authorized = await authorizeOwn(writes, identity, messageAt(id), "edit");
7858
- const { unknownMentions } = await writeEdit(writes, {
8061
+ await writeEdit(writes, {
7859
8062
  identity,
7860
8063
  authorized,
7861
8064
  text,
7862
8065
  revision
7863
8066
  });
7864
- return {
7865
- ok: true,
7866
- ...unknownMentions ? { unknownMentions } : {}
7867
- };
8067
+ return { ok: true };
7868
8068
  },
7869
8069
  async delete(caller, { id, revision }) {
7870
8070
  const identity = await identityOf(caller);
@@ -7941,6 +8141,9 @@ function build(options, binding) {
7941
8141
  tokens: async (caller) => access.tokens(await identityOf(caller)),
7942
8142
  createToken: async (caller, body) => access.createToken(await identityOf(caller), body),
7943
8143
  revokeToken: async (caller, input) => access.revokeToken(await identityOf(caller), input),
8144
+ schemas: async () => schemaRegistry.schemas(),
8145
+ schema: async (_caller, input) => schemaRegistry.schema(input),
8146
+ createSchema: async (caller, body) => schemaRegistry.createSchema(await identityOf(caller), body),
7944
8147
  async upload(caller, { data, name, type }) {
7945
8148
  const { principal } = await identityOf(caller);
7946
8149
  if (!principal.access.anywhere("post") && !principal.access.anywhere("sync")) throw forbidden$1("this token can't post anywhere, so it can't upload");
@@ -8050,7 +8253,10 @@ function build(options, binding) {
8050
8253
  after,
8051
8254
  filters: query,
8052
8255
  all: query.all ?? false,
8053
- me: actor.id,
8256
+ me: {
8257
+ id: actor.id,
8258
+ handle: actor.handle
8259
+ },
8054
8260
  actors,
8055
8261
  access: principal.access
8056
8262
  }, (query.wait ?? 0) * 1e3, signal);
@@ -8132,15 +8338,11 @@ function build(options, binding) {
8132
8338
  },
8133
8339
  async syncImport(caller, body, signal) {
8134
8340
  const { principal } = await needSync(caller, "import", true);
8135
- await speaksFor(caller, principal.id, body.author, body.op === "seen" ? null : body.from);
8136
- const author = externalIdentity(body.author, recordsActors(caller, principal));
8137
- if (body.op === "seen") {
8138
- const { state: actors } = await session.state(actorsReducer);
8139
- const seen = author.records === false ? null : actorSeen(author.actor, actors);
8140
- if (seen) await session.append(seen);
8141
- return { message: null };
8142
- }
8341
+ const platform = await speaksFor(caller, principal.id, body.author, body.from);
8342
+ const author = externalIdentity(body.author, ownSync(caller) ? null : principal, platform);
8143
8343
  const may = (channel) => principal.access.can("sync", channel);
8344
+ const keys = ownSync(caller) ? [] : (await entriesOf(caller, principal.id)).map(({ key }) => key);
8345
+ const asNamed = (text) => keys.length === 0 ? text : replaceMentions(text, (token) => token.kind === "actor" && keys.some((key) => token.actor.startsWith(`${key}:`)) ? `@[${principal.id}+${token.actor}]` : null);
8144
8346
  if (body.op === "post") {
8145
8347
  if (body.channel === void 0 === (body.re === void 0)) throw badRequest("an import needs `channel`; a reply needs `re`");
8146
8348
  let re;
@@ -8166,7 +8368,7 @@ function build(options, binding) {
8166
8368
  proofs,
8167
8369
  channel: body.channel,
8168
8370
  re,
8169
- text,
8371
+ text: asNamed(text),
8170
8372
  labels,
8171
8373
  noSync: body.noSync,
8172
8374
  id,
@@ -8174,7 +8376,6 @@ function build(options, binding) {
8174
8376
  from: body.from,
8175
8377
  ...body.origin && !ownSync(caller) ? { importedBy: principal.id } : {},
8176
8378
  after: afterAt(body.after),
8177
- lenientMentions: true,
8178
8379
  attachments,
8179
8380
  links: await linksOf(principal, body.links)
8180
8381
  })).id;
@@ -8200,7 +8401,7 @@ function build(options, binding) {
8200
8401
  await writeEdit(writes, {
8201
8402
  identity: author,
8202
8403
  authorized: proof,
8203
- text,
8404
+ text: asNamed(text),
8204
8405
  from: body.from,
8205
8406
  asAuthor,
8206
8407
  revision: body.revision
@@ -8214,7 +8415,7 @@ function build(options, binding) {
8214
8415
  re: found.re === null ? null : ref(found.re),
8215
8416
  text: body.text
8216
8417
  };
8217
- if (!found.deleted && !(asAuthor && found.by.principal !== body.author.id)) await checkSource(caller, principal.id, body.source);
8418
+ if (!found.deleted && !(asAuthor && found.by.actor !== author.author.actor)) await checkSource(caller, principal.id, body.source);
8218
8419
  return { message: await commit(write) };
8219
8420
  }
8220
8421
  if (body.op === "delete") await writeDelete(writes, {
@@ -8495,15 +8696,18 @@ function build(options, binding) {
8495
8696
  return [...found.values()];
8496
8697
  }
8497
8698
  /**
8498
- * Whether a caller may write as `author`: a platform user, never anyone this board
8499
- * signs in, on a platform it syncs: the one of entry `from`, when it names one.
8699
+ * Whether a caller may write as `author`, and the platform of the sync key they're a user of: a
8700
+ * platform user, never anyone this board signs in, named under a key it syncs (`slack-eu:…`):
8701
+ * entry `from`, when it names one.
8500
8702
  */
8501
8703
  async function speaksFor(caller, principal, author, from) {
8502
8704
  if (authenticates(author.id) || await signedIn(author.id)) throw forbidden$1(`${author.id} is someone this board signs in, not a platform user: sync can't write as them`);
8503
8705
  const entries = await entriesOf(caller, principal);
8504
- const platforms = (from === null ? entries : entries.filter((entry) => entry.key === from)).map((entry) => entry.platform);
8505
- if (from !== null && platforms.length === 0) throw forbidden$1(`this token doesn't sync ${from} here: its board registers its sync entries`);
8506
- if (!platforms.some((platform) => author.id.startsWith(`${platform}:`))) throw forbidden$1(`${author.id} isn't a user of ${platforms.length ? platforms.join(" or ") : "a platform this token syncs"}`);
8706
+ const keys = from === null ? entries : entries.filter((entry) => entry.key === from);
8707
+ if (from !== null && keys.length === 0) throw forbidden$1(`this token doesn't sync ${from} here: its board registers its sync entries`);
8708
+ const entry = keys.find(({ key }) => author.id.startsWith(`${key}:`));
8709
+ if (!entry) throw forbidden$1(`${author.id} isn't a user of ${keys.length ? keys.map(({ key }) => key).join(" or ") : "a sync key this token has"}: their ID starts with its key`);
8710
+ return entry.platform;
8507
8711
  }
8508
8712
  /**
8509
8713
  * Whether `id` is someone this board signs in that `authenticates` can't tell by its shape: a
@@ -8531,14 +8735,6 @@ function build(options, binding) {
8531
8735
  if (principal.scope !== void 0) throw forbidden$1("this token is narrowed with x-board-can: registering and running watchers is its project's job");
8532
8736
  }
8533
8737
  /**
8534
- * Whether a sync's writes keep the board's record of the platform users they're by (name and
8535
- * avatar), which every channel shows: this board's own sync's, and those of one that may sync in every
8536
- * channel. Anyone else's still carry their author, and leave the record as it is.
8537
- */
8538
- function recordsActors(caller, principal) {
8539
- return ownSync(caller) || principal.access.everywhere("sync");
8540
- }
8541
- /**
8542
8738
  * The caller, when it may sync somewhere: what every sync route needs. `records`: what it does
8543
8739
  * keeps sync's records (imports, receipts, its inbox, links), which only an integration does,
8544
8740
  * never a caller narrowed with `x-board-can`.
@@ -8620,7 +8816,7 @@ function build(options, binding) {
8620
8816
  message: null
8621
8817
  };
8622
8818
  const snapshot = {
8623
- author: actors.byId[found.by.actor]?.name ?? found.by.actor,
8819
+ author: shownOf(actors.byId[found.by.actor]) ?? found.by.actor,
8624
8820
  text: found.text,
8625
8821
  createdAt: found.createdAt,
8626
8822
  files: found.attachments.map((file) => ({
@@ -8829,10 +9025,10 @@ function local(options = {}) {
8829
9025
  opening ??= (async () => {
8830
9026
  const file = localFile(bound.name);
8831
9027
  let store;
8832
- if (options.memory) store = (await import("./memory-DkoqhxIH.mjs")).memory();
9028
+ if (options.memory) store = (await import("./memory-BvVoglGv.mjs")).memory();
8833
9029
  else {
8834
9030
  const { mkdir } = await import("node:fs/promises");
8835
- const { sqlite } = await import("./sqlite-CAwNHbQD.mjs");
9031
+ const { sqlite } = await import("./sqlite-D4mkYihG.mjs");
8836
9032
  const path = join(dir, `${file}.db`);
8837
9033
  try {
8838
9034
  await mkdir(dir, {