@vercel/board 0.45.1 → 0.47.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 (88) hide show
  1. package/dist/{access-3udXjJAg.mjs → access-C06pIr0M.mjs} +2 -2
  2. package/dist/access.d.mts +2 -2
  3. package/dist/access.mjs +5 -5
  4. package/dist/{actors-DasGZnfb.mjs → actors-Dkyg-oo0.mjs} +3 -3
  5. package/dist/{auth-aiOVE82-.mjs → auth-B9-wXQ-x.mjs} +29 -9
  6. package/dist/{auth-BG_whr9_.d.mts → auth-li3lKwJG.d.mts} +1 -1
  7. package/dist/{backend-D6yTo8Un.d.mts → backend-i_esjwUS.d.mts} +144 -5
  8. package/dist/backend-local.d.mts +1 -1
  9. package/dist/backend-local.mjs +1 -1
  10. package/dist/{chat-provider-V2jnjVLq.d.mts → chat-provider-BWBGZOZY.d.mts} +4 -2
  11. package/dist/{chat-provider-BvNqOQFL.mjs → chat-provider-CD7jskh7.mjs} +7 -4
  12. package/dist/cli-commands.d.mts +1 -1
  13. package/dist/cli-commands.mjs +1 -1
  14. package/dist/cli-embedded.d.mts +2 -2
  15. package/dist/cli-embedded.mjs +3 -2
  16. package/dist/cli.mjs +46 -15
  17. package/dist/{commands-DewS14_P.d.mts → commands-CJsOA-hf.d.mts} +60 -0
  18. package/dist/{commands-CqdnjUkm.mjs → commands-Dk6_cHLS.mjs} +325 -0
  19. package/dist/{conformance-BInS4_6b.mjs → conformance-CDP8y2Zm.mjs} +1063 -6
  20. package/dist/conformance.d.mts +6 -5
  21. package/dist/conformance.mjs +1 -1
  22. package/dist/{engine-XVBt02Bl.mjs → engine-j2VeNuKG.mjs} +51 -50
  23. package/dist/{errors-ZazTZh-s.mjs → errors-QhkdzI-o.mjs} +176 -9
  24. package/dist/{events-D17RndlV.mjs → events-MOcxGpOQ.mjs} +2 -2
  25. package/dist/{exports-DCxecX15.mjs → exports-CEqS-IPP.mjs} +1417 -84
  26. package/dist/exports-CF9rKCXd.d.mts +44 -0
  27. package/dist/{external-DfhN7lKK.mjs → external-BuVTXT1R.mjs} +7 -3
  28. package/dist/{index-Djmr4GzQ.d.mts → index-ttfx1TZ6.d.mts} +2 -2
  29. package/dist/index.d.mts +6 -6
  30. package/dist/index.mjs +5 -5
  31. package/dist/index.node.d.mts +7 -6
  32. package/dist/index.node.mjs +5 -4
  33. package/dist/inspect/app.js +215 -115
  34. package/dist/inspect/engine.js +5 -5
  35. package/dist/inspect-8YAhl_h3.mjs +2 -0
  36. package/dist/{inspect-CHsgnf_5.mjs → inspect-vOSrW_g6.mjs} +322 -50
  37. package/dist/{local-DE9vmanM.mjs → local-0ajWOVhN.mjs} +1673 -98
  38. package/dist/{main-CF1Me3jg.mjs → main-B8Zkd4Pm.mjs} +1282 -58
  39. package/dist/{memory-DyEL0fvN.mjs → memory-CMm-Fk_A.mjs} +2 -2
  40. package/dist/{mentions-DfZGp3B-.mjs → mentions-CnWt9Z5b.mjs} +34 -1
  41. package/dist/{middleware-BHHKHA9q.mjs → middleware-CT6vMNUc.mjs} +2 -2
  42. package/dist/{provider-BC9mPYVh.d.mts → provider-Bc3xI90K.d.mts} +199 -6
  43. package/dist/{routes-CkUetTO2.mjs → routes-ABXf3CKq.mjs} +261 -8
  44. package/dist/{routes-zm4TXKCC.d.mts → routes-CjA6Mp4D.d.mts} +610 -6
  45. package/dist/{schemas-BhZaystC.mjs → schemas-7VFdomFB.mjs} +34 -1
  46. package/dist/serve-BepKXDH3.mjs +285 -0
  47. package/dist/{server-Bmz0zqYM.mjs → server-4rQL3xuH.mjs} +41 -22
  48. package/dist/{serving-BLVRrJ7P.mjs → serving-BNdiReQT.mjs} +1 -1
  49. package/dist/{sql-CyVcjw8x.mjs → sql-IEbO5vXs.mjs} +174 -9
  50. package/dist/{sqlite-Con-8duk.mjs → sqlite-CVG8XKHm.mjs} +2 -2
  51. package/dist/{sqlite-db-BdzxtUOV.mjs → sqlite-db-BJjPQYx4.mjs} +1 -1
  52. package/dist/sync-chat-sdk.d.mts +16 -2
  53. package/dist/sync-chat-sdk.mjs +2 -2
  54. package/dist/sync-github.d.mts +16 -2
  55. package/dist/sync-github.mjs +3 -3
  56. package/dist/sync-linear.d.mts +17 -3
  57. package/dist/sync-linear.mjs +2 -2
  58. package/dist/sync-slack.d.mts +17 -3
  59. package/dist/sync-slack.mjs +107 -15
  60. package/dist/sync.d.mts +2 -2
  61. package/dist/sync.mjs +2 -2
  62. package/dist/{origin-BbwhnKrg.mjs → task-batch-BZXm6kOE.mjs} +83 -8
  63. package/dist/{tokens-BErYXuHZ.mjs → tokens-BCp4EWTQ.mjs} +2 -2
  64. package/docs/01-board/01-mounting.md +8 -5
  65. package/docs/01-board/03-identity.md +43 -23
  66. package/docs/01-board/04-messages.md +3 -2
  67. package/docs/01-board/06-watchers.md +3 -3
  68. package/docs/01-board/07-schedules.md +2 -2
  69. package/docs/01-board/08-middleware.md +7 -0
  70. package/docs/01-board/09-access.md +6 -4
  71. package/docs/01-board/10-local.md +4 -1
  72. package/docs/01-board/11-tasks.md +348 -0
  73. package/docs/02-sync/01-overview.md +4 -5
  74. package/docs/02-sync/02-functions.md +2 -2
  75. package/docs/02-sync/03-slack.md +8 -5
  76. package/docs/02-sync/06-providers.md +8 -0
  77. package/docs/03-guides/02-inspector.md +83 -10
  78. package/docs/03-guides/06-sandboxed-agents.md +7 -5
  79. package/docs/03-guides/07-build-a-ui.md +210 -0
  80. package/docs/03-guides/08-tailnet.md +123 -0
  81. package/docs/04-reference/01-cli.md +272 -23
  82. package/docs/04-reference/02-board.md +287 -7
  83. package/docs/04-reference/03-http.md +208 -13
  84. package/docs/04-reference/05-conformance.md +10 -7
  85. package/package.json +1 -1
  86. package/dist/exports-Gspe1eEq.d.mts +0 -4
  87. package/dist/inspect-C8U3A4jQ.mjs +0 -2
  88. package/dist/serve-CEMvl0EH.mjs +0 -181
@@ -1,8 +1,8 @@
1
- import { y as actorKind } from "./schemas-BhZaystC.mjs";
2
- import { c as externalMessageKey, l as isThreadTarget } from "./external-DfhN7lKK.mjs";
1
+ import { k as actorKind, w as TASK_LABEL } from "./schemas-7VFdomFB.mjs";
2
+ import { c as externalMessageKey, l as isThreadTarget } from "./external-BuVTXT1R.mjs";
3
3
  import { t as canonicalEmoji } from "./emoji-CTLpvH-A.mjs";
4
+ import { i as mentionTerms } from "./mentions-CnWt9Z5b.mjs";
4
5
  import { n as setOwn, t as own } from "./own-OwgPWdmh.mjs";
5
- import { i as mentionTerms } from "./mentions-DfZGp3B-.mjs";
6
6
  //#region src/contract/folds.ts
7
7
  const iso = (date) => typeof date === "string" ? date : date.toISOString();
8
8
  function foldMessages(state, event) {
@@ -109,9 +109,133 @@ function foldMessage(state, event) {
109
109
  delete message.undelivered[event.payload.target];
110
110
  return message;
111
111
  }
112
+ case "task.created": {
113
+ const message = state.byId[event.payload.id];
114
+ if (!message || message.deleted || message.re !== null || message.task) return void 0;
115
+ const { needs, by } = event.payload;
116
+ message.task = {
117
+ state: needs.length > 0 ? "waiting" : "ready",
118
+ owner: by.principal,
119
+ by: by.actor,
120
+ for: event.payload.for,
121
+ needs: [...needs],
122
+ epoch: 0,
123
+ claim: null,
124
+ blocked: null,
125
+ result: null,
126
+ reason: null
127
+ };
128
+ return labeled(message);
129
+ }
130
+ case "task.assigned":
131
+ case "task.needs_changed":
132
+ case "task.ready":
133
+ case "task.claimed":
134
+ case "task.renewed":
135
+ case "task.released":
136
+ case "task.expired":
137
+ case "task.completed":
138
+ case "task.failed":
139
+ case "task.blocked":
140
+ case "task.unblocked":
141
+ case "task.canceled":
142
+ case "task.reopened": {
143
+ const message = state.byId[event.payload.id];
144
+ if (!message?.task || !foldTask(message.task, event)) return void 0;
145
+ return labeled(message);
146
+ }
112
147
  default: return;
113
148
  }
114
149
  }
150
+ /** `message`, a task's root, wearing its task's state as `board.task`. A tombstone wears no labels, this one included. */
151
+ function labeled(message) {
152
+ if (!message.deleted) setOwn(message.labels, TASK_LABEL, message.task.state);
153
+ return message;
154
+ }
155
+ /** Whether a claim's write is by the claim that holds the task: the same epoch, while it's claimed. */
156
+ const holds = (task, epoch) => task.state === "claimed" && task.epoch === epoch;
157
+ /**
158
+ * Applies a task's event to it, and says whether it changed anything. Each event lands only from
159
+ * the states it can leave, so one written against a task that has since moved on changes nothing:
160
+ * the writes check first, and this is what holds if one didn't.
161
+ */
162
+ function foldTask(task, event) {
163
+ switch (event.type) {
164
+ case "task.assigned":
165
+ if (task.for === event.payload.for) return false;
166
+ task.for = event.payload.for;
167
+ return true;
168
+ case "task.needs_changed":
169
+ if (task.state !== "waiting" && task.state !== "ready" && task.state !== "blocked") return false;
170
+ task.needs = [...event.payload.needs];
171
+ if (task.state !== "blocked") task.state = task.needs.length > 0 ? "waiting" : "ready";
172
+ return true;
173
+ case "task.ready":
174
+ if (task.state !== "waiting") return false;
175
+ task.state = "ready";
176
+ return true;
177
+ case "task.claimed": {
178
+ const { epoch, until, token, by } = event.payload;
179
+ if (task.state !== "ready" || epoch !== task.epoch + 1) return false;
180
+ task.state = "claimed";
181
+ task.epoch = epoch;
182
+ task.claim = {
183
+ actor: by.actor,
184
+ until,
185
+ token
186
+ };
187
+ return true;
188
+ }
189
+ case "task.renewed":
190
+ if (!holds(task, event.payload.epoch)) return false;
191
+ task.claim.until = event.payload.until;
192
+ return true;
193
+ case "task.released":
194
+ case "task.expired":
195
+ if (!holds(task, event.payload.epoch)) return false;
196
+ task.state = "ready";
197
+ task.claim = null;
198
+ return true;
199
+ case "task.completed":
200
+ if (!holds(task, event.payload.epoch)) return false;
201
+ task.state = "completed";
202
+ task.claim = null;
203
+ task.result = event.payload.result;
204
+ return true;
205
+ case "task.failed":
206
+ if (!holds(task, event.payload.epoch)) return false;
207
+ task.state = "failed";
208
+ task.claim = null;
209
+ task.reason = event.payload.reason;
210
+ return true;
211
+ case "task.blocked":
212
+ if (task.state !== "waiting" && task.state !== "ready" && task.state !== "claimed") return false;
213
+ task.state = "blocked";
214
+ task.claim = null;
215
+ task.blocked = {
216
+ kind: event.payload.kind,
217
+ reason: event.payload.reason
218
+ };
219
+ return true;
220
+ case "task.unblocked":
221
+ if (task.state !== "blocked") return false;
222
+ task.state = task.needs.length > 0 ? "waiting" : "ready";
223
+ task.blocked = null;
224
+ return true;
225
+ case "task.canceled":
226
+ if (task.state === "completed" || task.state === "canceled") return false;
227
+ task.state = "canceled";
228
+ task.claim = null;
229
+ task.blocked = null;
230
+ task.reason = event.payload.reason;
231
+ return true;
232
+ case "task.reopened":
233
+ if (task.state !== "failed") return false;
234
+ task.state = "ready";
235
+ task.reason = null;
236
+ return true;
237
+ }
238
+ }
115
239
  /** Who's who: `actor.seen`. */
116
240
  function foldActors(state, event) {
117
241
  if (event.type !== "actor.seen") return state;
@@ -728,15 +852,38 @@ function sqlTables(db) {
728
852
  const matching = clauses(rest, p);
729
853
  if (matching.length > 0) where.push(`r.id in (select coalesce(m.re, m.id) from board_messages m where ${matching.join(" and ")})`);
730
854
  if (page.after !== void 0) where.push(`r.at > ${p.add(page.after)}`);
855
+ if (page.before !== void 0) where.push(`(r.at < ${p.add(page.before.at)} or (r.at = ${p.add(page.before.at)} and r.id < ${p.add(page.before.id)}))`);
731
856
  const order = page.after !== void 0 ? "asc" : "desc";
857
+ const limit = page.after !== void 0 ? page.limit : page.limit + 1;
732
858
  return {
733
- text: `select r.data as data, r.replies as replies, l.data as last
859
+ text: `select r.data as data, r.replies as replies, r.at as at, l.data as last
734
860
  from board_messages r left join board_messages l on l.id = r.at and r.at <> r.id
735
861
  where ${where.join(" and ")}
736
- order by r.at ${order} limit ${p.add(page.limit)}`,
862
+ order by r.at ${order}, r.id ${order} limit ${p.add(limit)}`,
737
863
  values: p.values
738
864
  };
739
865
  }
866
+ /** Roots that match, each with its summary, by ID: a root's own row holds its reply count and its latest reply. */
867
+ function rootsQuery(filter, page) {
868
+ const p = new Params();
869
+ const where = ["m.re is null", ...clauses(filter, p)];
870
+ if (page.before !== void 0) where.push(`m.id < ${p.add(page.before)}`);
871
+ if (page.after !== void 0) where.push(`m.id > ${p.add(page.after)}`);
872
+ const order = page.after !== void 0 ? "asc" : "desc";
873
+ return {
874
+ text: `select m.data as data, m.replies as replies, l.data as last
875
+ from board_messages m left join board_messages l on l.id = m.at and m.at <> m.id
876
+ where ${where.join(" and ")}
877
+ order by m.id ${order} limit ${p.add(page.limit)}`,
878
+ values: p.values
879
+ };
880
+ }
881
+ /** A thread summary from a row of a root joined with its latest reply. */
882
+ const summary = (found) => ({
883
+ root: parse(found),
884
+ replies: Number(found.replies),
885
+ last: found.last === null || found.last === void 0 ? null : JSON.parse(String(found.last))
886
+ });
740
887
  return {
741
888
  async position() {
742
889
  return position(await db.all(positionSql));
@@ -796,11 +943,29 @@ where v.message_id in (${p.list([...new Set(ids)])})
796
943
  async threads(filter, page) {
797
944
  if (filter.mentions) await mentionsReady();
798
945
  const [positions, rows] = await db.read([positionSql, threadsQuery(filter, page)]);
799
- const threads = rows.map((found) => ({
800
- root: parse(found),
801
- replies: Number(found.replies),
802
- last: found.last === null || found.last === void 0 ? null : JSON.parse(String(found.last))
946
+ const listed = rows.map((found) => ({
947
+ ...summary(found),
948
+ at: Number(found.at)
803
949
  }));
950
+ if (page.after !== void 0) return {
951
+ threads: listed.map(({ at: _, ...thread }) => thread),
952
+ position: position(positions)
953
+ };
954
+ const shown = listed.slice(0, page.limit);
955
+ const oldest = shown.at(-1);
956
+ const older = listed.length > page.limit && oldest ? {
957
+ at: oldest.at,
958
+ id: oldest.root.id
959
+ } : null;
960
+ return {
961
+ threads: shown.reverse().map(({ at: _, ...thread }) => thread),
962
+ position: position(positions),
963
+ older
964
+ };
965
+ },
966
+ async roots(filter, page) {
967
+ const [positions, rows] = await db.read([positionSql, rootsQuery(filter, page)]);
968
+ const threads = rows.map(summary);
804
969
  return {
805
970
  threads: page.after !== void 0 ? threads : threads.reverse(),
806
971
  position: position(positions)
@@ -1,6 +1,6 @@
1
- import { r as sqlTables } from "./sql-CyVcjw8x.mjs";
1
+ import { r as sqlTables } from "./sql-IEbO5vXs.mjs";
2
2
  import { t as sqlite$1 } from "./store-sqlite-D6fIszST.mjs";
3
- import { t as sqliteDb } from "./sqlite-db-BdzxtUOV.mjs";
3
+ import { t as sqliteDb } from "./sqlite-db-BJjPQYx4.mjs";
4
4
  //#region src/store/sqlite.ts
5
5
  /**
6
6
  * A local board in one SQLite file, its log and board's tables side by side. It
@@ -1,4 +1,4 @@
1
- import { n as ddl } from "./sql-CyVcjw8x.mjs";
1
+ import { n as ddl } from "./sql-IEbO5vXs.mjs";
2
2
  import { mkdirSync } from "node:fs";
3
3
  import { dirname, resolve } from "node:path";
4
4
  //#region src/store/sqlite-db.ts
@@ -1,5 +1,5 @@
1
- import { _ as SyncFn, m as SyncProvider, x as channels } from "./provider-BC9mPYVh.mjs";
2
- import { r as ChatTransport, t as ChatInput } from "./chat-provider-V2jnjVLq.mjs";
1
+ import { _ as SyncFn, m as SyncProvider, x as channels } from "./provider-Bc3xI90K.mjs";
2
+ import { r as ChatTransport, t as ChatInput } from "./chat-provider-BWBGZOZY.mjs";
3
3
  import { z } from "zod";
4
4
  import { ReactionEvent } from "chat";
5
5
  //#region src/sync/chat-sdk.d.ts
@@ -46,6 +46,13 @@ declare const schemaOf: <P extends string>(platform: P) => z.ZodDiscriminatedUni
46
46
  }, z.core.$strip>>;
47
47
  }, z.core.$strip>>;
48
48
  }, z.core.$strip>>>;
49
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
50
+ id: z.ZodString;
51
+ handle: z.ZodString;
52
+ name: z.ZodString;
53
+ avatar: z.ZodNullable<z.ZodString>;
54
+ isBot: z.ZodBoolean;
55
+ }, z.core.$strip>>>;
49
56
  id: z.ZodString;
50
57
  key: z.ZodString;
51
58
  raw: z.ZodUnknown;
@@ -80,6 +87,13 @@ declare const schemaOf: <P extends string>(platform: P) => z.ZodDiscriminatedUni
80
87
  }, z.core.$strip>>;
81
88
  }, z.core.$strip>>>;
82
89
  linksOnly: z.ZodOptional<z.ZodBoolean>;
90
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
91
+ id: z.ZodString;
92
+ handle: z.ZodString;
93
+ name: z.ZodString;
94
+ avatar: z.ZodNullable<z.ZodString>;
95
+ isBot: z.ZodBoolean;
96
+ }, z.core.$strip>>>;
83
97
  id: z.ZodString;
84
98
  key: z.ZodString;
85
99
  raw: z.ZodUnknown;
@@ -1,5 +1,5 @@
1
- import { i as eventSchema, p as channels, r as envelope } from "./events-D17RndlV.mjs";
2
- import { t as ChatSyncProvider } from "./chat-provider-BvNqOQFL.mjs";
1
+ import { i as eventSchema, p as channels, r as envelope } from "./events-MOcxGpOQ.mjs";
2
+ import { t as ChatSyncProvider } from "./chat-provider-CD7jskh7.mjs";
3
3
  import { createHash } from "node:crypto";
4
4
  //#region src/sync/chat-sdk.ts
5
5
  const schemaOf = (platform) => eventSchema(platform, "message");
@@ -1,5 +1,5 @@
1
- import { _ as SyncFn, b as SyncUnit, p as SyncContext } from "./provider-BC9mPYVh.mjs";
2
- import { n as ChatSyncProvider } from "./chat-provider-V2jnjVLq.mjs";
1
+ import { _ as SyncFn, b as SyncUnit, p as SyncContext } from "./provider-Bc3xI90K.mjs";
2
+ import { n as ChatSyncProvider } from "./chat-provider-BWBGZOZY.mjs";
3
3
  import { z } from "zod";
4
4
  import { Adapter } from "chat";
5
5
  //#region src/sync/github.d.ts
@@ -77,6 +77,13 @@ export declare const GitHubEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
77
77
  }, z.core.$strip>>;
78
78
  }, z.core.$strip>>;
79
79
  }, z.core.$strip>>>;
80
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
81
+ id: z.ZodString;
82
+ handle: z.ZodString;
83
+ name: z.ZodString;
84
+ avatar: z.ZodNullable<z.ZodString>;
85
+ isBot: z.ZodBoolean;
86
+ }, z.core.$strip>>>;
80
87
  id: z.ZodString;
81
88
  key: z.ZodString;
82
89
  platform: z.ZodLiteral<"github">;
@@ -149,6 +156,13 @@ export declare const GitHubEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
149
156
  }, z.core.$strip>>;
150
157
  }, z.core.$strip>>>;
151
158
  linksOnly: z.ZodOptional<z.ZodBoolean>;
159
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
160
+ id: z.ZodString;
161
+ handle: z.ZodString;
162
+ name: z.ZodString;
163
+ avatar: z.ZodNullable<z.ZodString>;
164
+ isBot: z.ZodBoolean;
165
+ }, z.core.$strip>>>;
152
166
  id: z.ZodString;
153
167
  key: z.ZodString;
154
168
  platform: z.ZodLiteral<"github">;
@@ -1,5 +1,5 @@
1
- import { _ as withRoutes, i as eventSchema, m as into, r as envelope } from "./events-D17RndlV.mjs";
2
- import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-BvNqOQFL.mjs";
1
+ import { _ as withRoutes, i as eventSchema, m as into, r as envelope } from "./events-MOcxGpOQ.mjs";
2
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-CD7jskh7.mjs";
3
3
  import { n as tagOf } from "./tags-BpFo6q0_.mjs";
4
4
  import { z } from "zod";
5
5
  import { connectGitHubAdapter } from "@vercel/connect/chat";
@@ -409,7 +409,7 @@ var GitHubProvider = class extends ChatSyncProvider {
409
409
  platform: "github",
410
410
  adapter: options.adapter,
411
411
  canStartThreads: false,
412
- mention: (actor) => actor.id.startsWith("github:user:") ? `@${actor.handle}` : null,
412
+ mention: (actor) => actor.id.startsWith("github:user:") ? `@${actor.name}` : null,
413
413
  resolveChannel: (key) => Promise.resolve(key),
414
414
  groupThread: (thread) => thread.replace(/:rc:[^:]+$/, ""),
415
415
  channelOf,
@@ -1,6 +1,6 @@
1
- import { ft as SourceRead } from "./routes-zm4TXKCC.mjs";
2
- import { _ as SyncFn, b as SyncUnit, f as ResolvedTarget, l as ReceivedEvent, o as ProviderPost, p as SyncContext, r as ProviderDelivery } from "./provider-BC9mPYVh.mjs";
3
- import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-V2jnjVLq.mjs";
1
+ import { Ot as SourceRead } from "./routes-CjA6Mp4D.mjs";
2
+ import { _ as SyncFn, b as SyncUnit, f as ResolvedTarget, l as ReceivedEvent, o as ProviderPost, p as SyncContext, r as ProviderDelivery } from "./provider-Bc3xI90K.mjs";
3
+ import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-BWBGZOZY.mjs";
4
4
  import { z } from "zod";
5
5
  import { Adapter } from "chat";
6
6
  //#region src/sync/linear.d.ts
@@ -47,6 +47,13 @@ export declare const LinearEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
47
47
  }, z.core.$strip>>;
48
48
  }, z.core.$strip>>;
49
49
  }, z.core.$strip>>>;
50
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
51
+ id: z.ZodString;
52
+ handle: z.ZodString;
53
+ name: z.ZodString;
54
+ avatar: z.ZodNullable<z.ZodString>;
55
+ isBot: z.ZodBoolean;
56
+ }, z.core.$strip>>>;
50
57
  id: z.ZodString;
51
58
  key: z.ZodString;
52
59
  raw: z.ZodUnknown;
@@ -81,6 +88,13 @@ export declare const LinearEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
81
88
  }, z.core.$strip>>;
82
89
  }, z.core.$strip>>>;
83
90
  linksOnly: z.ZodOptional<z.ZodBoolean>;
91
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
92
+ id: z.ZodString;
93
+ handle: z.ZodString;
94
+ name: z.ZodString;
95
+ avatar: z.ZodNullable<z.ZodString>;
96
+ isBot: z.ZodBoolean;
97
+ }, z.core.$strip>>>;
84
98
  id: z.ZodString;
85
99
  key: z.ZodString;
86
100
  raw: z.ZodUnknown;
@@ -1,5 +1,5 @@
1
- import { i as eventSchema, l as UnreadableError, p as channels, r as envelope } from "./events-D17RndlV.mjs";
2
- import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-BvNqOQFL.mjs";
1
+ import { i as eventSchema, l as UnreadableError, p as channels, r as envelope } from "./events-MOcxGpOQ.mjs";
2
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-CD7jskh7.mjs";
3
3
  import { n as tagOf, t as slug } from "./tags-BpFo6q0_.mjs";
4
4
  import "zod";
5
5
  import { connectLinearAdapter } from "@vercel/connect/chat";
@@ -1,6 +1,6 @@
1
- import { dn as ExternalLink } from "./routes-zm4TXKCC.mjs";
2
- import { _ as SyncFn, f as ResolvedTarget, o as ProviderPost, p as SyncContext, r as ProviderDelivery, s as ProviderSender, x as channels } from "./provider-BC9mPYVh.mjs";
3
- import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-V2jnjVLq.mjs";
1
+ import { Nn as ExternalLink } from "./routes-CjA6Mp4D.mjs";
2
+ import { _ as SyncFn, f as ResolvedTarget, o as ProviderPost, p as SyncContext, r as ProviderDelivery, s as ProviderSender, x as channels } from "./provider-Bc3xI90K.mjs";
3
+ import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-BWBGZOZY.mjs";
4
4
  import { z } from "zod";
5
5
  import { Adapter } from "chat";
6
6
  //#region src/sync/slack-deployments.d.ts
@@ -260,6 +260,13 @@ export declare const SlackEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
260
260
  }, z.core.$strip>>;
261
261
  }, z.core.$strip>>;
262
262
  }, z.core.$strip>>>;
263
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
264
+ id: z.ZodString;
265
+ handle: z.ZodString;
266
+ name: z.ZodString;
267
+ avatar: z.ZodNullable<z.ZodString>;
268
+ isBot: z.ZodBoolean;
269
+ }, z.core.$strip>>>;
263
270
  id: z.ZodString;
264
271
  key: z.ZodString;
265
272
  raw: z.ZodUnknown;
@@ -294,6 +301,13 @@ export declare const SlackEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
294
301
  }, z.core.$strip>>;
295
302
  }, z.core.$strip>>>;
296
303
  linksOnly: z.ZodOptional<z.ZodBoolean>;
304
+ mentioned: z.ZodOptional<z.ZodArray<z.ZodObject<{
305
+ id: z.ZodString;
306
+ handle: z.ZodString;
307
+ name: z.ZodString;
308
+ avatar: z.ZodNullable<z.ZodString>;
309
+ isBot: z.ZodBoolean;
310
+ }, z.core.$strip>>>;
297
311
  id: z.ZodString;
298
312
  key: z.ZodString;
299
313
  raw: z.ZodUnknown;
@@ -1,7 +1,8 @@
1
- import { p as MESSAGE_TEXT_MAX } from "./schemas-BhZaystC.mjs";
2
- import "./external-DfhN7lKK.mjs";
3
- import { d as opensBlock, i as eventSchema, l as UnreadableError, p as channels, r as envelope } from "./events-D17RndlV.mjs";
4
- import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-BvNqOQFL.mjs";
1
+ import { m as MESSAGE_TEXT_MAX } from "./schemas-7VFdomFB.mjs";
2
+ import "./external-BuVTXT1R.mjs";
3
+ import { t as extractMentions } from "./mentions-CnWt9Z5b.mjs";
4
+ import { d as opensBlock, i as eventSchema, l as UnreadableError, p as channels, r as envelope } from "./events-MOcxGpOQ.mjs";
5
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-CD7jskh7.mjs";
5
6
  import { r as formatVercelDeployments } from "./bots-CLKKMgYf.mjs";
6
7
  import { z } from "zod";
7
8
  import { stringifyMarkdown } from "chat";
@@ -114,6 +115,86 @@ function deploymentsLayout(markdown, deployments, as = {}) {
114
115
  }
115
116
  //#endregion
116
117
  //#region src/sync/slack.ts
118
+ /**
119
+ * How a user a Slack message mentions stands in what the adapter reads of it: their ID between two
120
+ * characters from Unicode's private use area, which nothing along the way escapes or rewrites.
121
+ */
122
+ const MENTIONED = /@\uF8F0([A-Z0-9_]+)\uF8F1/g;
123
+ const mentionedAs = (user) => `\uF8F0${user}\uF8F1`;
124
+ /** What the adapter read of a Slack message, each user it mentions as board writes a mention: `@[slack:user:U0456]`. */
125
+ const mentionsById = (text) => text.replace(MENTIONED, "@[slack:user:$1]");
126
+ /** Each `@` the adapter reads as a mention: one that opens a word, and isn't Slack's own `<@U0456>` or inside a word, as an email's is. */
127
+ const BARE_MENTION = /(?<![<A-Za-z0-9_])@(?=[A-Za-z0-9_])/g;
128
+ /** A character `text` doesn't have, from Unicode's private use area, or null if it has them all. */
129
+ function unusedIn(text) {
130
+ for (let code = 57344; code <= 63743; code++) if (!text.includes(String.fromCharCode(code))) return String.fromCharCode(code);
131
+ return null;
132
+ }
133
+ /**
134
+ * A message as the adapter converts it, each bare `@` standing as a character its text doesn't have,
135
+ * and `back`, which puts them in what the adapter made of it. Only a string, or a message's
136
+ * `markdown` or `raw`, is text: anything else goes as it is.
137
+ */
138
+ function withoutBareMentions(message) {
139
+ const asIs = {
140
+ given: message,
141
+ back: (text) => text
142
+ };
143
+ const fields = message;
144
+ const field = typeof message === "string" ? null : ["markdown", "raw"].find((name) => typeof fields?.[name] === "string");
145
+ const text = typeof message === "string" ? message : field ? fields[field] : null;
146
+ const stand = text?.includes("@") ? unusedIn(text) : null;
147
+ if (text === null || stand === null) return asIs;
148
+ const hidden = text.replace(BARE_MENTION, stand);
149
+ return {
150
+ given: field ? {
151
+ ...fields,
152
+ [field]: hidden
153
+ } : hidden,
154
+ back: (made) => made.replaceAll(stand, "@")
155
+ };
156
+ }
157
+ const literal = /* @__PURE__ */ new WeakSet();
158
+ /**
159
+ * Turns off the adapter's own reading of mentions, once. Board resolves a message's mentions against
160
+ * its own users before a provider posts it (the engine's `textFor`), each one it finds as Slack's
161
+ * `<@U0456>`, and what it leaves is text: a handle no one here has, a package's name. The adapter
162
+ * would look a bare `@name` up by display name, and write whatever is left as `<@name>`, which Slack
163
+ * shows as is. So its lookup answers the message it was given, and its converter never sees a bare
164
+ * `@`: it converts the text without them, and they go back in what it made.
165
+ *
166
+ * Coming in, the adapter writes each user a message mentions by display name, and their ID is gone
167
+ * from what it read. Here it writes the ID, in a form `mentionsById` reads back, so a mention on
168
+ * Slack is a mention of that user on the board.
169
+ */
170
+ function literalMentions(adapter) {
171
+ if (literal.has(adapter)) return;
172
+ literal.add(adapter);
173
+ if (adapter.resolveMessageMentions) adapter.resolveMessageMentions = async (message) => message;
174
+ const names = adapter.lookupMentionNames;
175
+ if (names) adapter.lookupMentionNames = async (users, channels) => ({
176
+ channels: (await names.call(adapter, /* @__PURE__ */ new Set(), channels)).channels,
177
+ users: new Map([...users].map((user) => [user, mentionedAs(user)]))
178
+ });
179
+ const converter = adapter.formatConverter;
180
+ if (!converter) return;
181
+ const { toSlackPayload, toResponseUrlText } = converter;
182
+ if (toSlackPayload) converter.toSlackPayload = (message) => {
183
+ const { given, back } = withoutBareMentions(message);
184
+ const payload = toSlackPayload.call(converter, given);
185
+ return "markdown_text" in payload ? {
186
+ ...payload,
187
+ markdown_text: back(payload.markdown_text)
188
+ } : {
189
+ ...payload,
190
+ text: back(payload.text)
191
+ };
192
+ };
193
+ if (toResponseUrlText) converter.toResponseUrlText = (message) => {
194
+ const { given, back } = withoutBareMentions(message);
195
+ return back(toResponseUrlText.call(converter, given));
196
+ };
197
+ }
117
198
  /** The most characters Slack shows of a message's username. */
118
199
  const USERNAME_MAX = 80;
119
200
  /**
@@ -133,7 +214,7 @@ function slackUsername({ name, attribution = "" }) {
133
214
  }
134
215
  /**
135
216
  * Text as the adapter gives it to Slack, so the text around a table reads as it does in any
136
- * message (a bare `@name` a mention, an emoji by its Slack name): markdown as the adapter posts
217
+ * message (an emoji by its Slack name): markdown as the adapter posts
137
218
  * it, and its older mrkdwn, which a message's notification text is.
138
219
  */
139
220
  const textOf = (adapter) => ({
@@ -568,12 +649,27 @@ var SlackProvider = class extends ChatSyncProvider {
568
649
  return channel.id;
569
650
  },
570
651
  markdown(message) {
571
- const text = markdownOf(message);
652
+ const text = mentionsById(markdownOf(message));
572
653
  if (text.trim()) return text;
573
654
  const raw = message.raw;
574
655
  const shared = Array.isArray(raw?.attachments) ? raw.attachments.filter((att) => att.is_share) : [];
575
656
  return shared.length ? forwardText(slackLinks("", "", shared, mrkdwn)) : text;
576
657
  },
658
+ async mentioned(text) {
659
+ const users = [...new Set(extractMentions(text).flatMap((token) => token.kind === "actor" && token.actor.startsWith("slack:user:") ? [token.actor.slice(11)] : []))];
660
+ return Promise.all(users.slice(0, 50).map(async (user) => {
661
+ const adapter = options.adapter;
662
+ const [known, avatar] = await Promise.all([adapter.lookupUser ? adapter.lookupUser(user).catch(() => null) : null, avatarOf(user)]);
663
+ const handle = known?.displayName || user;
664
+ return {
665
+ id: `slack:user:${user}`,
666
+ handle,
667
+ name: known?.realName || handle,
668
+ avatar,
669
+ isBot: known?.isBot === true
670
+ };
671
+ }));
672
+ },
577
673
  links(key, message) {
578
674
  const raw = message.raw;
579
675
  return slackLinks(key, typeof raw?.text === "string" ? raw.text : message.text, Array.isArray(raw?.attachments) ? raw.attachments : [], mrkdwn);
@@ -795,6 +891,7 @@ var SlackProvider = class extends ChatSyncProvider {
795
891
  }
796
892
  }, sync);
797
893
  this.web = client;
894
+ literalMentions(options.adapter);
798
895
  }
799
896
  /**
800
897
  * A message goes out under its author's name (`Julián Benegas`, `clever-lemur via vboard-factory`,
@@ -834,11 +931,9 @@ var SlackProvider = class extends ChatSyncProvider {
834
931
  if (!web?.files?.uploadV2 || !web.files.info || !toMrkdwn || !await this.hasScope(web, "files:read")) return null;
835
932
  const threadId = this.toChat(target);
836
933
  const { channel } = adapter.decodeThreadId(threadId);
837
- const message = { markdown };
838
- const resolved = await adapter.resolveMessageMentions?.(message, threadId) ?? message;
839
934
  const ids = ((await web.files.uploadV2({
840
935
  channel_id: channel,
841
- initial_comment: toMrkdwn.call(adapter.formatConverter, resolved),
936
+ initial_comment: toMrkdwn.call(adapter.formatConverter, { markdown }),
842
937
  file_uploads: files.map((file) => ({
843
938
  file: Buffer.from(file.data),
844
939
  filename: slackFileName(file.filename, file.mimeType)
@@ -905,8 +1000,7 @@ var SlackProvider = class extends ChatSyncProvider {
905
1000
  } : null;
906
1001
  const threadId = this.toChat(target);
907
1002
  const { channel, threadTs } = adapter.decodeThreadId(threadId);
908
- const message = { markdown: named ? withoutLabel(markdown, named.name) : markdown };
909
- const layout = deploymentsLayout((await adapter.resolveMessageMentions?.(message, threadId) ?? message).markdown, deployments, textOf(adapter));
1003
+ const layout = deploymentsLayout({ markdown: named ? withoutLabel(markdown, named.name) : markdown }.markdown, deployments, textOf(adapter));
910
1004
  if (!layout) return null;
911
1005
  const sent = await web.chat.postMessage({
912
1006
  channel,
@@ -936,7 +1030,7 @@ var SlackProvider = class extends ChatSyncProvider {
936
1030
  const web = await this.web().catch(() => void 0);
937
1031
  if (!web?.chat?.update) return false;
938
1032
  const threadId = this.toChat(thread);
939
- const layout = deploymentsLayout((await adapter.resolveMessageMentions?.({ markdown }, threadId) ?? { markdown }).markdown, deployments, textOf(adapter));
1033
+ const layout = deploymentsLayout(markdown, deployments, textOf(adapter));
940
1034
  if (!layout) return false;
941
1035
  try {
942
1036
  await web.chat.update({
@@ -957,13 +1051,11 @@ var SlackProvider = class extends ChatSyncProvider {
957
1051
  if (!web?.chat || !adapter.formatConverter?.toSlackPayload || username === null || !await this.canCustomize(web)) return null;
958
1052
  const threadId = this.toChat(target);
959
1053
  const { channel, threadTs } = adapter.decodeThreadId(threadId);
960
- const message = { markdown: withoutLabel(markdown, as.name) };
961
- const resolved = await adapter.resolveMessageMentions?.(message, threadId) ?? message;
962
1054
  const icon = slackIcon(as.avatar);
963
1055
  const sent = await web.chat.postMessage({
964
1056
  channel,
965
1057
  ...threadTs ? { thread_ts: threadTs } : {},
966
- ...adapter.formatConverter.toSlackPayload(resolved),
1058
+ ...adapter.formatConverter.toSlackPayload({ markdown: withoutLabel(markdown, as.name) }),
967
1059
  unfurl_links: false,
968
1060
  unfurl_media: false,
969
1061
  username,
package/dist/sync.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { cn as ExternalAuthor, ln as ExternalEvent, un as ExternalFile } from "./routes-zm4TXKCC.mjs";
2
- import { A as SyncRoot, C as mirror, D as RootOverride, E as ProviderEvent, M as eventSchema, N as VercelDeployment, O as SyncOverrides, S as into, T as EventBase, _ as SyncFn, a as ProviderOptions, b as SyncUnit, c as Receive, d as Renderer, f as ResolvedTarget, g as Sync, h as UnreadableError, i as ProviderFile, j as envelope, k as SyncResult, l as ReceivedEvent, m as SyncProvider, n as FileDelivery, o as ProviderPost, p as SyncContext, r as ProviderDelivery, u as RenderInput, v as SyncIn, w as render, x as channels, y as SyncOut } from "./provider-BC9mPYVh.mjs";
1
+ import { An as ExternalAuthor, Mn as ExternalFile, jn as ExternalEvent } from "./routes-CjA6Mp4D.mjs";
2
+ import { A as SyncRoot, C as mirror, D as RootOverride, E as ProviderEvent, M as eventSchema, N as VercelDeployment, O as SyncOverrides, S as into, T as EventBase, _ as SyncFn, a as ProviderOptions, b as SyncUnit, c as Receive, d as Renderer, f as ResolvedTarget, g as Sync, h as UnreadableError, i as ProviderFile, j as envelope, k as SyncResult, l as ReceivedEvent, m as SyncProvider, n as FileDelivery, o as ProviderPost, p as SyncContext, r as ProviderDelivery, u as RenderInput, v as SyncIn, w as render, x as channels, y as SyncOut } from "./provider-Bc3xI90K.mjs";
3
3
  export { EventBase, type ExternalAuthor, ExternalEvent, type ExternalFile, type FileDelivery, type ProviderDelivery, type ProviderEvent, type ProviderFile, type ProviderOptions, type ProviderPost, type Receive, ReceivedEvent, type RenderInput, type Renderer, ResolvedTarget, type RootOverride, type Sync, type SyncContext, type SyncFn, type SyncIn, type SyncOut, SyncOverrides, SyncProvider, type SyncResult, type SyncRoot, type SyncUnit, UnreadableError, type VercelDeployment, channels, envelope, eventSchema, into, mirror, render };
package/dist/sync.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as ExternalEvent } from "./external-DfhN7lKK.mjs";
2
- import { c as SyncProvider, g as render, h as mirror, i as eventSchema, l as UnreadableError, m as into, n as SyncOverrides, o as ReceivedEvent, p as channels, r as envelope, s as ResolvedTarget, t as EventBase } from "./events-D17RndlV.mjs";
1
+ import { n as ExternalEvent } from "./external-BuVTXT1R.mjs";
2
+ import { c as SyncProvider, g as render, h as mirror, i as eventSchema, l as UnreadableError, m as into, n as SyncOverrides, o as ReceivedEvent, p as channels, r as envelope, s as ResolvedTarget, t as EventBase } from "./events-MOcxGpOQ.mjs";
3
3
  export { EventBase, ExternalEvent, ReceivedEvent, ResolvedTarget, SyncOverrides, SyncProvider, UnreadableError, channels, envelope, eventSchema, into, mirror, render };