@vercel/board 0.40.0 → 0.42.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 (91) hide show
  1. package/README.md +1 -1
  2. package/dist/{access-Bl_k_Hpa.mjs → access-BgBiaCyx.mjs} +2 -2
  3. package/dist/access.d.mts +6 -6
  4. package/dist/access.mjs +5 -5
  5. package/dist/{actors-yBRWTpt5.mjs → actors-DkZsnMgA.mjs} +59 -40
  6. package/dist/{auth-DtmZzlHm.d.mts → auth-Bn8J_1F2.d.mts} +12 -30
  7. package/dist/{auth-C8URZHLx.mjs → auth-Ft4AJptx.mjs} +9 -19
  8. package/dist/{backend-BW5NbBsp.d.mts → backend-DMrK55mU.d.mts} +137 -48
  9. package/dist/backend-local.d.mts +1 -1
  10. package/dist/backend-local.mjs +1 -1
  11. package/dist/{chat-provider-1WKsLEnM.mjs → chat-provider-CPZg2MQb.mjs} +2 -2
  12. package/dist/{chat-provider-Bbb9JguG.d.mts → chat-provider-Cgkh9xJw.d.mts} +2 -2
  13. package/dist/cli-commands.d.mts +1 -1
  14. package/dist/cli-commands.mjs +1 -1
  15. package/dist/cli-embedded.d.mts +10 -5
  16. package/dist/cli-embedded.mjs +8 -6
  17. package/dist/cli.mjs +8 -13
  18. package/dist/{commands-BJLocuXj.d.mts → commands-CrEVjASe.d.mts} +8 -30
  19. package/dist/{commands-D6VWegVY.mjs → commands-QRD0U9AQ.mjs} +30 -101
  20. package/dist/{conformance-BWhZ0k8T.mjs → conformance-BORt5nky.mjs} +139 -109
  21. package/dist/conformance.d.mts +9 -8
  22. package/dist/conformance.mjs +1 -1
  23. package/dist/digest-CKC0Rmy1.mjs +4 -0
  24. package/dist/{engine-Djif8XVk.mjs → engine-BVHSH2Kn.mjs} +11 -12
  25. package/dist/{errors-CNRJqUuL.mjs → errors-DUzpDSrJ.mjs} +112 -30
  26. package/dist/{events-C6HwB046.mjs → events-BT8y_81j.mjs} +2 -2
  27. package/dist/{exports-C2OWIbLU.mjs → exports-BfNXPHN_.mjs} +473 -174
  28. package/dist/exports-Bw_OYNRl.d.mts +4 -0
  29. package/dist/{external-CHDxWIVf.mjs → external-DymyhUzl.mjs} +1 -1
  30. package/dist/{index-Cuxbz_E0.d.mts → index-CydxnBND.d.mts} +2 -2
  31. package/dist/index.d.mts +6 -6
  32. package/dist/index.mjs +6 -5
  33. package/dist/index.node.d.mts +6 -6
  34. package/dist/index.node.mjs +3 -3
  35. package/dist/inspect/app.js +41 -41
  36. package/dist/inspect/engine.js +2 -2
  37. package/dist/{inspect-cGcP8ZO9.mjs → inspect-CniRRiJ2.mjs} +6 -6
  38. package/dist/inspect-HlHh7OXa.mjs +2 -0
  39. package/dist/{local-CsleYuyM.mjs → local-CWLPYoiY.mjs} +130 -359
  40. package/dist/{main-D97xuqWZ.mjs → main-aVEEoc60.mjs} +429 -139
  41. package/dist/{memory-BvVoglGv.mjs → memory-DhduVbUu.mjs} +2 -2
  42. package/dist/{mentions-CT2bN5eP.mjs → mentions-DfZGp3B-.mjs} +1 -1
  43. package/dist/{middleware-BF9vnPPS.mjs → middleware-0DUFrav-.mjs} +2 -2
  44. package/dist/{origin-DLCmrwmE.mjs → origin-DAyYeDuW.mjs} +7 -36
  45. package/dist/{page-6BTCZWGY.mjs → page-BD6ygU49.mjs} +2 -2
  46. package/dist/page-BiJVe-7R.mjs +2 -0
  47. package/dist/{provider-YqkF1E2k.d.mts → provider-dY54GFNz.d.mts} +1 -25
  48. package/dist/{routes-CAjd5ARa.d.mts → routes-By9lmvUD.d.mts} +1 -63
  49. package/dist/{schemas-AZkxk06N.mjs → schemas-DAzSsgWk.mjs} +8 -3
  50. package/dist/{serve-Cs-e0Jke.mjs → serve-BnBqi0sw.mjs} +5 -5
  51. package/dist/{server-CIfMdIt3.mjs → server-Bcpkt6TS.mjs} +79 -131
  52. package/dist/{serving-B4l0nLng.mjs → serving-hcxzaCCO.mjs} +1 -1
  53. package/dist/{sql-Bv-RQu8n.mjs → sql-P9g-rLIF.mjs} +3 -3
  54. package/dist/{sqlite-D4mkYihG.mjs → sqlite-B3rCcIof.mjs} +2 -2
  55. package/dist/{sqlite-db-BraLvHtf.mjs → sqlite-db-D0Fyju-4.mjs} +1 -1
  56. package/dist/sync-chat-sdk.d.mts +2 -2
  57. package/dist/sync-chat-sdk.mjs +2 -2
  58. package/dist/sync-github.d.mts +2 -2
  59. package/dist/sync-github.mjs +2 -2
  60. package/dist/sync-linear.d.mts +3 -3
  61. package/dist/sync-linear.mjs +2 -2
  62. package/dist/sync-slack.d.mts +3 -3
  63. package/dist/sync-slack.mjs +4 -4
  64. package/dist/sync.d.mts +2 -2
  65. package/dist/sync.mjs +2 -2
  66. package/dist/{tokens-CrrXAVGz.mjs → tokens-BSMpTPEe.mjs} +4 -4
  67. package/docs/01-board/01-mounting.md +12 -17
  68. package/docs/01-board/03-identity.md +45 -39
  69. package/docs/01-board/04-messages.md +3 -1
  70. package/docs/01-board/05-reading.md +8 -2
  71. package/docs/01-board/06-watchers.md +15 -10
  72. package/docs/01-board/07-schedules.md +6 -2
  73. package/docs/01-board/09-access.md +59 -111
  74. package/docs/02-sync/01-overview.md +5 -2
  75. package/docs/02-sync/03-slack.md +12 -12
  76. package/docs/03-guides/01-coding-agents.md +18 -22
  77. package/docs/03-guides/02-inspector.md +4 -5
  78. package/docs/03-guides/03-ci.md +7 -26
  79. package/docs/03-guides/04-triage.md +2 -2
  80. package/docs/03-guides/05-agent-factory.md +7 -9
  81. package/docs/03-guides/06-sandboxed-agents.md +149 -0
  82. package/docs/04-reference/01-cli.md +59 -90
  83. package/docs/04-reference/02-board.md +53 -37
  84. package/docs/04-reference/03-http.md +32 -53
  85. package/docs/04-reference/05-conformance.md +37 -18
  86. package/docs/index.md +4 -4
  87. package/package.json +1 -1
  88. package/dist/digest-D32GV_mX.mjs +0 -4
  89. package/dist/exports-FyRBIAMs.d.mts +0 -4
  90. package/dist/inspect-CLy6FrOZ.mjs +0 -2
  91. package/dist/page-BnY8FhPn.mjs +0 -2
@@ -1,6 +1,6 @@
1
- import { u as BoardError } from "./errors-CNRJqUuL.mjs";
1
+ import { u as BoardError } from "./errors-DUzpDSrJ.mjs";
2
2
  import { c as canonical, t as block } from "./blocks-CVoBC7ur.mjs";
3
- import { c as compileAccess } from "./access-Bl_k_Hpa.mjs";
3
+ import { a as canText, c as compileAccess } from "./access-BgBiaCyx.mjs";
4
4
  //#region src/conformance/index.ts
5
5
  var Mismatch = class extends Error {};
6
6
  const show = (value) => JSON.stringify(value) ?? String(value);
@@ -30,6 +30,26 @@ async function refused(attempt, status, what) {
30
30
  throw new Mismatch(`${what}: expected ${status}, and it succeeded`);
31
31
  }
32
32
  const NO_CAN = "this run can't call the board with an x-board-can header";
33
+ const NO_HEADERS = "this run can't call the board with headers of its own";
34
+ /** The avatar the checks of who writes give their profile. */
35
+ const AVATAR = "https://example.com/conformance.png";
36
+ /** A post by `poster`, which sends `header`, read back as the run sees it: it lands, and is deleted when the run ends. */
37
+ async function postedWith(ctx, poster, header) {
38
+ const posted = await poster.post(ctx.channel, {
39
+ text: `conformance: with ${header}`,
40
+ labels: ctx.labels,
41
+ noSync: true
42
+ }).catch((error) => {
43
+ throw new Mismatch(`a post with ${header}, which released clients still send: expected it to land, got ${error instanceof BoardError ? `${error.status} ${error.code}` : String(error)}`);
44
+ });
45
+ ctx.posted.push(posted.id);
46
+ return (await ctx.board.thread(posted.id)).message;
47
+ }
48
+ /** That a view's `by` names who wrote it as the protocol has it: an actor, a principal, and a profile, and no session. */
49
+ function noSession(by, what) {
50
+ check(typeof by === "object" && by !== null, `${what} should have a by, got ${show(by)}`);
51
+ check(!("session" in by), `${what} should carry no session, got ${show(by)}`);
52
+ }
33
53
  /**
34
54
  * That `attempt`, by a caller narrowed with `x-board-can`, is refused as one: 403 `forbidden`.
35
55
  * Vercel's API's refusal of a person's watchers goes on as it is, for the run to skip.
@@ -65,7 +85,6 @@ function isRef(value, what) {
65
85
  const OPTIONAL = /* @__PURE__ */ new Set([
66
86
  "schedules",
67
87
  "grants",
68
- "tokens",
69
88
  "schemas",
70
89
  "attachments"
71
90
  ]);
@@ -113,13 +132,12 @@ function unnamed(error) {
113
132
  }
114
133
  const messageOf = (error) => error instanceof Error ? error.message : String(error);
115
134
  /**
116
- * Runs `check` with what it makes grants and tokens with, and revokes them all afterwards, the
135
+ * Runs `check` with what it makes grants with, and revokes them all afterwards, the
117
136
  * newest grant first, so one that closes a pattern goes while the one keeping this run in is there.
118
137
  * A revoke that fails fails the check: what it made would stay on the board.
119
138
  */
120
139
  async function withGrants(ctx, check) {
121
140
  const made = [];
122
- const tokens = [];
123
141
  const grants = {
124
142
  async make(input, by) {
125
143
  try {
@@ -142,24 +160,9 @@ async function withGrants(ctx, check) {
142
160
  }
143
161
  throw new Mismatch(`${what}: expected 403, and it made the grant`);
144
162
  },
145
- async mint(can) {
146
- if (!ctx.withToken) throw new Skip("this run can't call the board with a token's secret");
147
- try {
148
- const { token, secret } = await ctx.board.createToken({
149
- name: `conformance-${ctx.labels.conformance}-grants`,
150
- can,
151
- expires: "1h"
152
- });
153
- tokens.push(token.id);
154
- return ctx.withToken(secret);
155
- } catch (error) {
156
- if (error instanceof BoardError && [
157
- 403,
158
- 404,
159
- 501
160
- ].includes(error.status)) throw new Skip(`this board mints no tokens to check with: ${error.message}`);
161
- throw error;
162
- }
163
+ narrow(can) {
164
+ if (!ctx.withCan) throw new Skip(NO_CAN);
165
+ return ctx.withCan(canText(compileAccess(can)));
163
166
  },
164
167
  async keep(pattern) {
165
168
  const [source, kind, id, environment] = ctx.me.principal.split(":");
@@ -194,9 +197,6 @@ async function withGrants(ctx, check) {
194
197
  for (const id of made.reverse()) await ctx.board.revokeGrant(id).catch((error) => {
195
198
  left.push(`${id} (${messageOf(error)})`);
196
199
  });
197
- for (const id of tokens) await ctx.board.revokeToken(id).catch((error) => {
198
- left.push(`token ${id} (${messageOf(error)})`);
199
- });
200
200
  if (left.length > 0) throw new Mismatch(`${failure ? `${messageOf(failure)}; and it ` : ""}couldn't revoke what it made: ${left.join(", ")}`);
201
201
  if (failure) throw failure;
202
202
  return result;
@@ -692,6 +692,105 @@ const CHECKS = [
692
692
  }), 403, "a post by a caller narrowed to read");
693
693
  }
694
694
  },
695
+ {
696
+ group: "core",
697
+ name: "takes a profile and its avatar as one x-board-profile header, and shows both on what it writes",
698
+ run: async (ctx) => {
699
+ if (!ctx.withHeaders) return NO_HEADERS;
700
+ const name = `conformance-${ctx.labels.conformance}`;
701
+ const posted = await ctx.withHeaders({ "x-board-profile": `${name}; avatar="${AVATAR}"` }).post(ctx.channel, {
702
+ text: "conformance: as a profile, with its avatar",
703
+ labels: ctx.labels,
704
+ noSync: true
705
+ });
706
+ ctx.posted.push(posted.id);
707
+ const { message } = await ctx.board.thread(posted.id);
708
+ same(message.by.principal, ctx.me.principal, "the profile's principal, this run's");
709
+ same(message.by.profile?.toLowerCase(), name, "the profile its header names");
710
+ same(message.author?.kind, "agent", "the profile's kind");
711
+ same(message.author?.name, name, "the profile's name");
712
+ same(message.author?.avatar, AVATAR, "the profile's avatar, from its header's parameter");
713
+ }
714
+ },
715
+ {
716
+ group: "core",
717
+ name: "lets a profile change only its own messages, and its principal all of them",
718
+ run: async (ctx) => {
719
+ if (!ctx.withHeaders) return NO_HEADERS;
720
+ if (ctx.me.actor !== ctx.me.principal) return "this run writes as a profile, so it can't change messages as its principal";
721
+ const as = (name) => ctx.withHeaders({ "x-board-profile": `conformance-${name}-${ctx.labels.conformance}` });
722
+ const by = async (poster, text) => {
723
+ const message = await poster.post(ctx.channel, {
724
+ text,
725
+ labels: ctx.labels,
726
+ noSync: true
727
+ });
728
+ ctx.posted.push(message.id);
729
+ return message;
730
+ };
731
+ const profile = as("own");
732
+ const own = await by(profile, "conformance: a profile's own");
733
+ const other = await by(as("other"), "conformance: another profile's");
734
+ const principal = await by(ctx.board, "conformance: its principal's");
735
+ await profile.edit(own.id, "conformance: a profile's own, edited by it");
736
+ same((await ctx.board.thread(own.id)).message.text, "conformance: a profile's own, edited by it", "a profile's own message, once it edits it");
737
+ for (const [message, whose] of [[other, "another profile's"], [principal, "its principal's"]]) {
738
+ await refused(profile.edit(message.id, "conformance: not its own"), 403, `an edit, by a profile, of ${whose} message`);
739
+ await refused(profile.delete(message.id), 403, `a delete, by a profile, of ${whose} message`);
740
+ }
741
+ await ctx.board.edit(other.id, "conformance: another profile's, edited by its principal");
742
+ const edited = (await ctx.board.thread(other.id)).message;
743
+ same(edited.text, "conformance: another profile's, edited by its principal", "a profile's message, once its principal edits it");
744
+ same(edited.by.actor, other.by.actor, "who a profile's message is by, once its principal edits it");
745
+ for (const message of [own, other]) {
746
+ await ctx.board.delete(message.id);
747
+ check((await ctx.board.thread(message.id)).message.deleted, "a profile's message, once its principal deletes it, should be deleted");
748
+ }
749
+ await profile.delete((await by(profile, "conformance: a profile's own, to delete")).id);
750
+ }
751
+ },
752
+ {
753
+ group: "core",
754
+ name: "ignores x-board-avatar, which x-board-profile's avatar parameter replaced",
755
+ run: async (ctx) => {
756
+ if (!ctx.withHeaders) return NO_HEADERS;
757
+ const name = `conformance-bare-${ctx.labels.conformance}`;
758
+ const message = await postedWith(ctx, ctx.withHeaders({
759
+ "x-board-profile": name,
760
+ "x-board-avatar": AVATAR
761
+ }), "x-board-avatar");
762
+ same(message.by.profile?.toLowerCase(), name, "the profile its header names");
763
+ same(message.author?.avatar ?? null, null, "the avatar of a profile whose header names none, whatever x-board-avatar says");
764
+ }
765
+ },
766
+ {
767
+ group: "core",
768
+ name: "ignores x-board-session: who writes is the principal and its profile",
769
+ run: async (ctx) => {
770
+ if (!ctx.withHeaders) return NO_HEADERS;
771
+ const message = await postedWith(ctx, ctx.withHeaders({ "x-board-session": `conformance-${ctx.labels.conformance}` }), "x-board-session");
772
+ same(message.by.actor, ctx.me.actor, "who a post with x-board-session is by: this run, as itself");
773
+ noSession(message.by, "a post with x-board-session");
774
+ }
775
+ },
776
+ {
777
+ group: "core",
778
+ name: "shows no session on a message, its event, or you",
779
+ run: async (ctx) => {
780
+ const { root } = needRoot(ctx);
781
+ noSession((await ctx.board.thread(root.id)).message.by, "a message");
782
+ const { events } = await ctx.board.poll({
783
+ channel: ctx.channel,
784
+ after: ctx.start,
785
+ label: ctx.labels,
786
+ wait: 0
787
+ });
788
+ const posted = events.find((event) => event.type === "message.posted");
789
+ check(posted !== void 0, `events after the run's start should hold its post, got ${show(events.map((event) => event.type))}`);
790
+ noSession(posted.payload.by, "a message.posted event's payload");
791
+ check(!("session" in ctx.me), `you should carry no session, got ${show(ctx.me)}`);
792
+ }
793
+ },
695
794
  {
696
795
  group: "schedules",
697
796
  name: "schedules a reply, lists it, and cancels it",
@@ -940,10 +1039,10 @@ const CHECKS = [
940
1039
  {
941
1040
  group: "grants",
942
1041
  name: "takes manage at each pattern a grant names to change it, and at * to list them",
943
- run: (ctx) => withGrants(ctx, async ({ make, deny, mint }) => {
1042
+ run: (ctx) => withGrants(ctx, async ({ make, deny, narrow }) => {
944
1043
  const subtree = subtreeOf(ctx);
945
1044
  const inner = `${subtree}inner/`;
946
- const poster = await mint({ "*": ["read", "post"] });
1045
+ const poster = narrow({ "*": ["read", "post"] });
947
1046
  const probe = await make(grantFor(ctx));
948
1047
  await deny(poster, grantFor(ctx), "a grant made without manage");
949
1048
  await refused(poster.updateGrant(probe.id, { can: { [`${subtree}ci/`]: ["read"] } }), 403, "an update without manage");
@@ -951,7 +1050,7 @@ const CHECKS = [
951
1050
  await refused(poster.grants(), 403, "listing grants without manage at *");
952
1051
  await refused(poster.explain(`${subtree}thread`, { project: ctx.principals.project }), 403, "explaining a principal's access without manage at *");
953
1052
  alike((await poster.explain(`${subtree}thread`)).grants, [], "which grants decide, for a caller that may not list them");
954
- const manager = await mint({
1053
+ const manager = narrow({
955
1054
  "*": [
956
1055
  "read",
957
1056
  "post",
@@ -976,19 +1075,19 @@ const CHECKS = [
976
1075
  },
977
1076
  {
978
1077
  group: "grants",
979
- name: "lets no token grant past its own can, even where everyone's grant closes it",
980
- run: (ctx) => withGrants(ctx, async ({ make, deny, mint, keep }) => {
1078
+ name: "lets no caller narrowed with x-board-can grant past its can, even where everyone's grant closes it",
1079
+ run: (ctx) => withGrants(ctx, async ({ make, deny, narrow, keep }) => {
981
1080
  const subtree = subtreeOf(ctx);
982
1081
  const secret = `${subtree}secret/`;
983
1082
  const run = granteeOf(ctx);
984
- const narrowed = await mint({
1083
+ const narrowed = narrow({
985
1084
  "*": "all",
986
1085
  [secret]: []
987
1086
  });
988
1087
  await deny(narrowed, {
989
1088
  principals: [run],
990
1089
  can: { [subtree]: ["read"] }
991
- }, `a grant on ${subtree} from a token kept out of ${secret}`);
1090
+ }, `a grant on ${subtree} from a caller narrowed out of ${secret}`);
992
1091
  await keep(secret);
993
1092
  await make({
994
1093
  principals: [{ kind: "everyone" }],
@@ -997,7 +1096,7 @@ const CHECKS = [
997
1096
  await deny(narrowed, {
998
1097
  principals: [run],
999
1098
  can: { [subtree]: ["read"] }
1000
- }, `a grant on ${subtree} from a token kept out of ${secret}, once everyone is too`);
1099
+ }, `a grant on ${subtree} from a caller narrowed out of ${secret}, once everyone is too`);
1001
1100
  await make({
1002
1101
  principals: [run],
1003
1102
  can: { [`${subtree}ci/`]: ["post"] }
@@ -1006,11 +1105,11 @@ const CHECKS = [
1006
1105
  },
1007
1106
  {
1008
1107
  group: "grants",
1009
- name: "lets no token let anyone in where everyone gets more than the token has",
1010
- run: (ctx) => withGrants(ctx, async ({ make, deny, mint, keep }) => {
1108
+ name: "lets no caller narrowed with x-board-can let anyone in where everyone gets more than it has",
1109
+ run: (ctx) => withGrants(ctx, async ({ make, deny, narrow, keep }) => {
1011
1110
  const subtree = subtreeOf(ctx);
1012
1111
  const open = `${subtree}open/`;
1013
- const narrowed = await mint({
1112
+ const narrowed = narrow({
1014
1113
  "*": "all",
1015
1114
  [open]: []
1016
1115
  });
@@ -1022,7 +1121,7 @@ const CHECKS = [
1022
1121
  await deny(narrowed, {
1023
1122
  principals: [granteeOf(ctx)],
1024
1123
  can: { [`${subtree}ci/`]: ["post"] }
1025
- }, `a grant from a token kept out of ${open}, which everyone reads`);
1124
+ }, `a grant from a caller narrowed out of ${open}, which everyone reads`);
1026
1125
  })
1027
1126
  },
1028
1127
  {
@@ -1035,69 +1134,6 @@ const CHECKS = [
1035
1134
  name: "lets a project on another team in, in its environments",
1036
1135
  run: async () => "grants across teams aren't specified yet: what a project on another team needs, and what all-projects means for one, comes later"
1037
1136
  },
1038
- {
1039
- group: "tokens",
1040
- name: "mints a token, shows its secret only then, lists it, and revokes it",
1041
- run: async (ctx) => {
1042
- const name = `conformance-${ctx.labels.conformance}`;
1043
- const { token, secret } = await ctx.board.createToken({
1044
- name,
1045
- can: { [ctx.channel]: ["read"] },
1046
- expires: "1h"
1047
- });
1048
- try {
1049
- isRef(token.id, "a token's id");
1050
- check(typeof secret === "string" && secret.length >= 32, `a token's secret should be a string of at least 32 characters, got ${typeof secret}`);
1051
- same(token.name, name, "the token's name");
1052
- same(show(token.can), show({ [ctx.channel]: ["read"] }), "the token's can");
1053
- const left = Date.parse(token.expiresAt) - Date.now();
1054
- check(left > 33e5 && left <= 3605e3, `a token minted for 1h should expire in an hour, got ${token.expiresAt}`);
1055
- const listed = await ctx.board.tokens();
1056
- check(listed.some((found) => found.id === token.id), `tokens should list ${token.id}`);
1057
- check(!JSON.stringify(listed).includes(secret), "tokens shouldn't show a token's secret");
1058
- } catch (error) {
1059
- await ctx.board.revokeToken(token.id).catch(() => {});
1060
- throw error;
1061
- }
1062
- same((await ctx.board.revokeToken(token.id)).revoked, true, "revoking it");
1063
- same((await ctx.board.revokeToken(token.id)).revoked, false, "revoking it again");
1064
- check(!(await ctx.board.tokens()).some((found) => found.id === token.id), "tokens shouldn't list it once it's revoked");
1065
- }
1066
- },
1067
- {
1068
- group: "tokens",
1069
- name: "lets a token do what its can says, as whoever minted it, and nothing once it's revoked",
1070
- run: async (ctx) => {
1071
- if (!ctx.withToken) return "this run can't call the board with a token's secret";
1072
- const { root } = needRoot(ctx);
1073
- const { token, secret } = await ctx.board.createToken({
1074
- name: `conformance-${ctx.labels.conformance}-reads`,
1075
- can: { [ctx.channel]: ["read"] },
1076
- expires: "1h"
1077
- });
1078
- const holder = ctx.withToken(secret);
1079
- try {
1080
- const me = await holder.me();
1081
- same(me.principal, ctx.me.principal, "a token's principal, its minter's");
1082
- const want = { [ctx.channel]: ["read"] };
1083
- check(show(me.can) === show(want), `what a token that may only read says it may do: expected ${show(want)}, got ${show(me.can)}`);
1084
- same((await holder.thread(root.id)).message.id, root.id, "a thread read with a token that may read it");
1085
- await refused(holder.post(ctx.channel, {
1086
- text: "conformance: a token that may only read",
1087
- labels: ctx.labels,
1088
- noSync: true
1089
- }).then((message) => {
1090
- ctx.posted.push(message.id);
1091
- return message;
1092
- }), 403, "a post with a token that may only read");
1093
- } catch (error) {
1094
- await ctx.board.revokeToken(token.id).catch(() => {});
1095
- throw error;
1096
- }
1097
- same((await ctx.board.revokeToken(token.id)).revoked, true, "revoking it");
1098
- await refused(holder.me(), 401, "a request with a revoked token");
1099
- }
1100
- },
1101
1137
  {
1102
1138
  group: "schemas",
1103
1139
  name: "lists the built-in schemas first, and reads a schema by its ID",
@@ -1737,8 +1773,8 @@ async function conformance(board, options = {}) {
1737
1773
  })).cursor,
1738
1774
  me,
1739
1775
  posted: [],
1740
- ...options.withToken ? { withToken: options.withToken } : {},
1741
- ...options.withCan ? { withCan: options.withCan } : {},
1776
+ ...options.withCan ? { withCan: options.withCan } : options.withHeaders ? { withCan: (can) => options.withHeaders({ "x-board-can": can }) } : {},
1777
+ ...options.withHeaders ? { withHeaders: options.withHeaders } : {},
1742
1778
  principals: {
1743
1779
  project: options.principals?.project ?? `prj_conformance${label}`,
1744
1780
  repository: options.principals?.repository ?? `acme/conformance-${label}`,
@@ -1779,12 +1815,6 @@ async function conformance(board, options = {}) {
1779
1815
  status: "skipped",
1780
1816
  detail: "this board takes no GitHub or OIDC principals in a grant"
1781
1817
  });
1782
- else if (group === "tokens" && error instanceof BoardError && error.code === "unsupported_principal") checks.push({
1783
- group,
1784
- name,
1785
- status: "skipped",
1786
- detail: "this board mints tokens only for a deployment: run as one to check them"
1787
- });
1788
1818
  else checks.push({
1789
1819
  group,
1790
1820
  name,
@@ -1,4 +1,4 @@
1
- import { d as Board } from "./backend-BW5NbBsp.mjs";
1
+ import { f as Board } from "./backend-DMrK55mU.mjs";
2
2
  //#region src/conformance/index.d.ts
3
3
  /**
4
4
  * Checks that a board speaks the protocol, through a handle on it (`conformance(board())`), as
@@ -8,7 +8,7 @@ import { d as Board } from "./backend-BW5NbBsp.mjs";
8
8
  * schema it registers, `conformance@1`, stays: a schema version is never removed.
9
9
  */
10
10
  /** What a check is about, for the report's headings. */
11
- export type CheckGroup = 'core' | 'schedules' | 'grants' | 'tokens' | 'schemas' | 'attachments' | 'watchers' | 'sync';
11
+ export type CheckGroup = 'core' | 'schedules' | 'grants' | 'schemas' | 'attachments' | 'watchers' | 'sync';
12
12
  export type CheckResult = {
13
13
  group: CheckGroup;
14
14
  name: string;
@@ -25,18 +25,19 @@ export type ConformanceReport = {
25
25
  export type ConformanceOptions = {
26
26
  /** Where it posts. Default `conformance`. */
27
27
  channel?: string;
28
- /**
29
- * The same board, with a board token's secret as the credential (as `BOARD_TOKEN` sends it):
30
- * the tokens check calls it so to see that a token does only what its `can` says. Without it,
31
- * that check is skipped.
32
- */
33
- withToken?: (secret: string) => Board;
34
28
  /**
35
29
  * The same board, with this run's credential and an `x-board-can` header that narrows it to
36
30
  * `can` (`conformance=read`), as a proxy holding the credential sends it: the checks of a
37
31
  * narrowed caller call it so. Without it, they're skipped.
38
32
  */
39
33
  withCan?: (can: string) => Board;
34
+ /**
35
+ * The same board, with this run's credential and `headers` on every request, as a client or a proxy
36
+ * holding the credential sends them: the checks of who writes call it so, with an
37
+ * `x-board-profile` that carries an avatar and the headers that one replaced. Without it, they're
38
+ * skipped, and it stands in for `withCan` when that's left out.
39
+ */
40
+ withHeaders?: (headers: Record<string, string>) => Board;
40
41
  /**
41
42
  * Whom the grants checks name. A board that verifies tokens itself (`vb serve`) takes the made-up
42
43
  * IDs they use without it; one that looks names up, as Vercel's API does, needs real ones on its
@@ -1,2 +1,2 @@
1
- import { t as conformance } from "./conformance-BWhZ0k8T.mjs";
1
+ import { t as conformance } from "./conformance-BORt5nky.mjs";
2
2
  export { conformance };
@@ -0,0 +1,4 @@
1
+ //#region src/inspect/digest.ts
2
+ const PAGE_SHA256 = "f50caced754723432e972aafa252cdb3cb49676ceedc21c762987ed418dac0f6";
3
+ //#endregion
4
+ export { PAGE_SHA256 as t };
@@ -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-CNRJqUuL.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-DUzpDSrJ.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, c as platformProfile, f as viaText, i as afterRetry, l as shownName, m as derivedId, o as actorParts, t as DroppedError } from "./middleware-BF9vnPPS.mjs";
6
- import { a as replaceMentions, n as isEmail, t as extractMentions } from "./mentions-CT2bN5eP.mjs";
7
- 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-0DUFrav-.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. */
@@ -1002,20 +1002,19 @@ function createSyncEngine(entries) {
1002
1002
  markdown,
1003
1003
  as: {
1004
1004
  name,
1005
- avatar: senderAvatar(message, actor, actors),
1005
+ avatar: senderAvatar(message, actor),
1006
1006
  attribution
1007
1007
  }
1008
1008
  } : { markdown };
1009
1009
  }
1010
- /** An author's own picture, or for an agent with the board's built-in one, its person's Vercel avatar: `claude via julian` shows Julian. */
1011
- 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) {
1012
1012
  const builtIn = (avatar) => !avatar || /\/avatars\/[a-z0-9-]+$/.test(avatar);
1013
1013
  const own = actor?.avatar ?? null;
1014
1014
  if (!builtIn(own)) return own;
1015
- const person = actors.byId[message.by.principal]?.avatar;
1016
- if (!builtIn(person)) return person;
1017
1015
  const username = actor?.handle.split("/")[0] ?? "";
1018
- 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;
1019
1018
  return `https://vercel.com/api/www/avatar?u=${encodeURIComponent(username)}&s=64&format=png`;
1020
1019
  }
1021
1020
  /** What a platform shows for files it didn't get: one line each, so a reader knows they're on the board. */
@@ -1,3 +1,4 @@
1
+ import { f as MESSAGE_TEXT_MAX } from "./schemas-DAzSsgWk.mjs";
1
2
  import { r as normalizeEmoji } from "./emoji-CTLpvH-A.mjs";
2
3
  import { ZodError } from "zod";
3
4
  //#region src/contract/files.ts
@@ -93,6 +94,113 @@ async function* parseSse(body, signal) {
93
94
  }
94
95
  }
95
96
  //#endregion
97
+ //#region src/contract/profile-header.ts
98
+ /** Why a header isn't one: the board's 400 says it. */
99
+ var InvalidProfileHeader = class extends Error {};
100
+ const TOKEN_START = /[A-Za-z*]/;
101
+ const TCHAR = /[!#$%&'*+\-.^_`|~0-9A-Za-z:/]/;
102
+ const KEY_START = /[a-z*]/;
103
+ const KEY_CHAR = /[a-z0-9_\-.*]/;
104
+ /** RFC 8941's other bare items: an integer, a decimal, a boolean, or a byte sequence. */
105
+ const OTHER_ITEM = /^(?:-?\d{1,15}|-?\d{1,12}\.\d{1,3}|\?[01]|:[A-Za-z0-9+/=]*:)$/;
106
+ /** An sf-string: printable ASCII in quotes, with `"` and `\` escaped. */
107
+ function sfString(value) {
108
+ if (!/^[\x20-\x7e]*$/.test(value)) throw new InvalidProfileHeader("an avatar URL is printable ASCII: percent-encode the rest");
109
+ return `"${value.replace(/[\\"]/g, (char) => `\\${char}`)}"`;
110
+ }
111
+ /**
112
+ * The header's value for a profile: `fixer`, or `fixer;avatar="https://example.com/fixer.png"`,
113
+ * serialized as RFC 8941 says. An avatar outside printable ASCII goes as its URL percent-encodes it.
114
+ */
115
+ function formatProfileHeader(profile) {
116
+ if (!profile.avatar) return profile.name;
117
+ const avatar = /^[\x20-\x7e]*$/.test(profile.avatar) ? profile.avatar : URL.parse(profile.avatar)?.href ?? profile.avatar;
118
+ return `${profile.name};avatar=${sfString(avatar)}`;
119
+ }
120
+ /**
121
+ * Reads the header as RFC 8941 parses an Item. Its bare item is the profile's name, a token or a
122
+ * string; `avatar` is a string. A parameter it doesn't know is ignored, as structured fields' are,
123
+ * and the last of a repeated one wins. Anything else throws `InvalidProfileHeader`.
124
+ */
125
+ function parseProfileHeader(value) {
126
+ let at = 0;
127
+ const fail = (why) => {
128
+ throw new InvalidProfileHeader(`x-board-profile is a structured header, like fixer;avatar="https://example.com/fixer.png": ${why}`);
129
+ };
130
+ const spaces = () => {
131
+ while (value[at] === " ") at++;
132
+ };
133
+ const string = () => {
134
+ at++;
135
+ let out = "";
136
+ while (at < value.length) {
137
+ const char = value[at++];
138
+ if (char === "\\") {
139
+ const next = value[at++];
140
+ if (next !== "\"" && next !== "\\") fail("a string escapes only \" and \\");
141
+ out += next;
142
+ } else if (char === "\"") return out;
143
+ else if (char < " " || char > "~") fail("a string is printable ASCII");
144
+ else out += char;
145
+ }
146
+ return fail("a string is missing its closing \"");
147
+ };
148
+ const token = () => {
149
+ const start = at;
150
+ while (at < value.length && TCHAR.test(value[at])) at++;
151
+ return value.slice(start, at);
152
+ };
153
+ /** A bare item: a string, a token, or another of RFC 8941's (a number, a boolean, bytes), which the header names nothing with. */
154
+ const bare = () => {
155
+ const char = value[at];
156
+ if (char === "\"") return {
157
+ kind: "string",
158
+ value: string()
159
+ };
160
+ if (char !== void 0 && TOKEN_START.test(char)) return {
161
+ kind: "token",
162
+ value: token()
163
+ };
164
+ const start = at;
165
+ while (at < value.length && value[at] !== ";" && value[at] !== " ") at++;
166
+ const item = value.slice(start, at);
167
+ if (!OTHER_ITEM.test(item)) fail(item === "" ? "a parameter has no value after its =" : `${item} isn't a value`);
168
+ return {
169
+ kind: "other",
170
+ value: item
171
+ };
172
+ };
173
+ spaces();
174
+ const name = bare();
175
+ if (name.kind === "other") fail(name.value === "" ? "it names no profile" : `${name.value} isn't a profile's name`);
176
+ let avatar = null;
177
+ while (value[at] === ";") {
178
+ at++;
179
+ spaces();
180
+ if (!KEY_START.test(value[at] ?? "")) fail("a parameter starts with a lowercase letter");
181
+ const start = at;
182
+ while (at < value.length && KEY_CHAR.test(value[at])) at++;
183
+ const key = value.slice(start, at);
184
+ let param = {
185
+ kind: "boolean",
186
+ value: "?1"
187
+ };
188
+ if (value[at] === "=") {
189
+ at++;
190
+ param = bare();
191
+ }
192
+ if (key !== "avatar") continue;
193
+ if (param.kind !== "string") fail("avatar is a string, in quotes");
194
+ avatar = param.value;
195
+ }
196
+ spaces();
197
+ if (at < value.length) fail(`${JSON.stringify(value.slice(at, at + 20))} follows the profile`);
198
+ return {
199
+ name: name.value,
200
+ avatar
201
+ };
202
+ }
203
+ //#endregion
96
204
  //#region src/client/client.ts
97
205
  /**
98
206
  * What went wrong: `message` says what and why, `code` is what to branch on, `hint`, when there's
@@ -200,22 +308,7 @@ function createBoardClient(options) {
200
308
  if (!auth) return out;
201
309
  if (options.token !== void 0) out.authorization = `Bearer ${await resolve(options.token)}`;
202
310
  const profile = as !== void 0 ? as : options.profile === void 0 ? null : await resolve(options.profile);
203
- if (profile !== null) {
204
- const { name, avatar } = typeof profile === "string" ? {
205
- name: profile,
206
- avatar: void 0
207
- } : profile;
208
- out["x-board-profile"] = name;
209
- if (avatar) out["x-board-avatar"] = avatar;
210
- } else {
211
- const person = options.person === void 0 ? null : await resolve(options.person);
212
- if (person?.name) out["x-board-name"] = encodeURIComponent(person.name);
213
- if (person?.avatar) out["x-board-avatar"] = person.avatar;
214
- }
215
- const session = as !== void 0 ? null : options.session === void 0 ? null : await resolve(options.session);
216
- if (session) out["x-board-session"] = session;
217
- const handle = options.handle === void 0 ? null : await resolve(options.handle);
218
- if (handle) out["x-board-handle"] = handle;
311
+ if (profile !== null) out["x-board-profile"] = formatProfileHeader(typeof profile === "string" ? { name: profile } : profile);
219
312
  return out;
220
313
  }
221
314
  async function raw(method, path, init = {}) {
@@ -384,19 +477,6 @@ function createBoardClient(options) {
384
477
  grants: async () => (await call("GET", "/grants")).grants,
385
478
  /** `revoked` is false when it was already gone. Its principals' next requests are refused. */
386
479
  revokeGrant: (id) => call("POST", `/grants/${path(id)}/revoke`, { body: {} }),
387
- /**
388
- * A token that acts as you, narrowed to `can`, writing as `profile` and `session` when they're
389
- * given: for a widget, a sandbox, a script. `secret` shows only here. It lives 30 days, or
390
- * `expires`, at most 90.
391
- */
392
- createToken: (input) => call("POST", "/tokens", { body: input.can === void 0 ? input : {
393
- ...input,
394
- can: wireCan(input.can)
395
- } }),
396
- /** Your live tokens, or everyone's with manage in every channel. Never their secrets. */
397
- tokens: async () => (await call("GET", "/tokens")).tokens,
398
- /** It and every token minted with it stop. `revoked` is false when it was already revoked. */
399
- revokeToken: (id) => call("POST", `/tokens/${path(id)}/revoke`, { body: {} }),
400
480
  /** Every schema: the built-ins, then the board's own, by name and version. */
401
481
  schemas: async () => (await call("GET", "/schemas")).schemas,
402
482
  /** One schema version, by its ID: `sandbox@1`. */
@@ -618,6 +698,7 @@ const badRequest = (message, code = "invalid_request") => new HttpError(400, cod
618
698
  const unauthorized = (message) => new HttpError(401, "unauthorized", message);
619
699
  const forbidden = (message) => new HttpError(403, "forbidden", message);
620
700
  const notFound = (message, code = "not_found") => new HttpError(404, code, message);
701
+ const textTooLong = () => new HttpError(400, "text_too_long", `A message's text is at most ${MESSAGE_TEXT_MAX.toLocaleString("en-US")} characters.`, { hint: "Put the long part in a file and attach it to a message, with a short summary as the text." });
621
702
  const duplicateId = () => new HttpError(409, "duplicate_id", "that id was already used for a different write");
622
703
  const json = (body, status = 200, headers) => new Response(JSON.stringify(body), {
623
704
  status,
@@ -652,6 +733,7 @@ function toErrorResponse(error) {
652
733
  }
653
734
  if (error instanceof ZodError) {
654
735
  const issue = error.issues[0] && reported(error.issues[0]);
736
+ if (issue?.code === "too_big" && issue.origin === "string" && issue.maximum === 1e4 && issue.path.length === 1 && issue.path[0] === "text") return toErrorResponse(textTooLong());
655
737
  const path = issue?.path.length ? `${issue.path.join(".")}: ` : "";
656
738
  return json({ error: {
657
739
  code: "invalid_request",
@@ -675,4 +757,4 @@ function toErrorResponse(error) {
675
757
  } }, 500);
676
758
  }
677
759
  //#endregion
678
- export { fileSize as _, forbidden as a, toErrorResponse as c, createBoardClient as d, duration as f, fileName as g, IMPORT_BYTES_MAX as h, duplicateId as i, unauthorized as l, DIRECT_UPLOAD_BYTES_MAX as m, RejectedError as n, json as o, ATTACHMENT_BYTES_MAX as p, badRequest as r, notFound as s, HttpError as t, BoardError as u, mediaType as v, typeOf as y };
760
+ export { IMPORT_BYTES_MAX as _, forbidden as a, mediaType as b, toErrorResponse as c, createBoardClient as d, duration as f, DIRECT_UPLOAD_BYTES_MAX as g, ATTACHMENT_BYTES_MAX as h, duplicateId as i, unauthorized as l, parseProfileHeader as m, RejectedError as n, json as o, formatProfileHeader as p, badRequest as r, notFound as s, HttpError as t, BoardError as u, fileName as v, typeOf as x, fileSize as y };
@@ -1,5 +1,5 @@
1
- import { d as Labels, l as LabelKey } from "./schemas-AZkxk06N.mjs";
2
- import { n as ExternalEvent, r as ExternalLocation } from "./external-CHDxWIVf.mjs";
1
+ import { d as Labels, l as LabelKey } from "./schemas-DAzSsgWk.mjs";
2
+ import { n as ExternalEvent, r as ExternalLocation } from "./external-DymyhUzl.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/sync/fn.ts
5
5
  const ROUTES = Symbol.for("board.syncRoutes");