@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,14 +1,15 @@
1
- import { f as Board } from "./backend-D6yTo8Un.mjs";
1
+ import { f as Board } from "./backend-i_esjwUS.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
5
- * `vb` and agents use it: every board answers all of it. A board may keep no schedules or files,
6
- * and says so with a 501, which the kit reports as not kept here. It writes to one channel
7
- * (`conformance` by default), keeps every post on the board, and deletes what it posted. The one
5
+ * `vb` and agents use it: every board answers all of it. A board may keep no schedules, tasks, or
6
+ * files, and says so with a 501, which the kit reports as not kept here. It writes to one channel
7
+ * (`conformance` by default), and for the tasks checks that need two, to `tasks` under it, keeps
8
+ * every post on the board, and deletes what it posted. The one
8
9
  * schema it registers, `conformance@1`, stays: a schema version is never removed.
9
10
  */
10
11
  /** What a check is about, for the report's headings. */
11
- export type CheckGroup = 'core' | 'schedules' | 'grants' | 'schemas' | 'attachments' | 'watchers' | 'sync';
12
+ export type CheckGroup = 'core' | 'paging' | 'schedules' | 'tasks' | 'grants' | 'schemas' | 'attachments' | 'watchers' | 'sync';
12
13
  export type CheckResult = {
13
14
  group: CheckGroup;
14
15
  name: string;
@@ -1,2 +1,2 @@
1
- import { t as conformance } from "./conformance-BInS4_6b.mjs";
1
+ import { t as conformance } from "./conformance-CDP8y2Zm.mjs";
2
2
  export { conformance };
@@ -1,10 +1,10 @@
1
- import { C as typeOf, _ as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, x as fileSize, y as IMPORT_BYTES_MAX } from "./errors-ZazTZh-s.mjs";
2
- import { C as toStorable, p as MESSAGE_TEXT_MAX, s as ChannelPath } from "./schemas-BhZaystC.mjs";
3
- import { l as isThreadTarget, s as channelOf } from "./external-DfhN7lKK.mjs";
1
+ import { C as fileSize, T as typeOf, c as notFound, r as badRequest, t as HttpError, x as IMPORT_BYTES_MAX, y as ATTACHMENT_BYTES_MAX } from "./errors-QhkdzI-o.mjs";
2
+ import { N as toStorable, m as MESSAGE_TEXT_MAX, s as ChannelPath } from "./schemas-7VFdomFB.mjs";
3
+ import { l as isThreadTarget, s as channelOf } from "./external-BuVTXT1R.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-BHHKHA9q.mjs";
6
- import { a as replaceMentions, n as isEmail, t as extractMentions } from "./mentions-DfZGp3B-.mjs";
7
- import { a as immutable, d as opensBlock, f as routesFor, l as UnreadableError, n as SyncOverrides, o as ReceivedEvent, s as ResolvedTarget, u as channelMissing } from "./events-D17RndlV.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-CT6vMNUc.mjs";
6
+ import { a as replaceMentions, n as isEmail, t as extractMentions } from "./mentions-CnWt9Z5b.mjs";
7
+ import { a as immutable, d as opensBlock, f as routesFor, l as UnreadableError, n as SyncOverrides, o as ReceivedEvent, s as ResolvedTarget, u as channelMissing } from "./events-MOcxGpOQ.mjs";
8
8
  import { i as vercelDeployments, n as displayText } from "./bots-CLKKMgYf.mjs";
9
9
  //#region src/sync/engine.ts
10
10
  /** `files`: a message with files may have no text. */
@@ -87,15 +87,30 @@ function keyedId(key, platform, id) {
87
87
  if (id.startsWith(`${key}:`)) return id;
88
88
  return `${key}:${id.startsWith(`${platform}:`) ? id.slice(platform.length + 1) : id}`;
89
89
  }
90
- /** A platform event with its author named under `key`. */
90
+ /**
91
+ * A platform event with its author named under `key`, and every user its text mentions there too:
92
+ * the ones `mentioned` describes, and any it has no room for, since a mention by the platform's
93
+ * name would be of another sync's user.
94
+ */
91
95
  function keyedEvent(key, platform, event) {
92
- return "author" in event ? {
96
+ if (!("author" in event)) return event;
97
+ const author = {
98
+ ...event.author,
99
+ id: keyedId(key, platform, event.author.id)
100
+ };
101
+ if (event.kind !== "message" && event.kind !== "edited" || key === platform) return {
93
102
  ...event,
94
- author: {
95
- ...event.author,
96
- id: keyedId(key, platform, event.author.id)
97
- }
98
- } : event;
103
+ author
104
+ };
105
+ return {
106
+ ...event,
107
+ author,
108
+ ...event.mentioned ? { mentioned: event.mentioned.map((user) => ({
109
+ ...user,
110
+ id: keyedId(key, platform, user.id)
111
+ })) } : {},
112
+ text: replaceMentions(event.text, (token) => token.kind === "actor" && token.actor.startsWith(`${platform}:`) ? `@[${keyedId(key, platform, token.actor)}]` : null)
113
+ };
99
114
  }
100
115
  /**
101
116
  * Two-way sync between a board and its platforms, run by board(): webhooks come in through its
@@ -698,6 +713,7 @@ function createSyncEngine(entries) {
698
713
  }, synced?.channel ?? channel);
699
714
  const base = {
700
715
  ...links.length ? { links } : {},
716
+ ...event.mentioned?.length ? { mentioned: event.mentioned } : {},
701
717
  author: event.author,
702
718
  text: clampText(withNotes(overrides.text ?? event.text, notes), attachments.length > 0),
703
719
  ...attachments.length ? { attachments } : {},
@@ -794,13 +810,15 @@ function createSyncEngine(entries) {
794
810
  else if (event.kind === "edited") {
795
811
  const stored = await messageOf(id);
796
812
  const text = clampText(withNotes(overrides.text ?? event.text, stored ? notesIn(stored.text) : []), (stored?.attachments.length ?? 0) > 0);
813
+ const mentioned = event.mentioned?.length ? { mentioned: event.mentioned } : {};
797
814
  if (stored && !event.linksOnly && stored.text !== text) await screened(await call("syncImport", {
798
815
  op: "edit",
799
816
  author,
800
817
  from: key,
801
818
  origin,
802
819
  text,
803
- source: from
820
+ source: from,
821
+ ...mentioned
804
822
  }));
805
823
  const links = stored ? await resolveLinks(platform, event.links ?? [], origin, stored.channel, stored.links) : [];
806
824
  if (stored && !sameLinks(links, stored.links)) await call("syncImport", {
@@ -917,49 +935,32 @@ function createSyncEngine(entries) {
917
935
  }
918
936
  }
919
937
  /**
920
- * A message's text for a platform, through entry `key`, its mentions resolved as it posts and only
921
- * against that entry's own users. An `@handle` reads natively when one of them has it, or of
922
- * several, the one who wrote in the thread: `@support/malte` names one of support's users, and
923
- * `@malte` is short for whichever of this sync's users that is, under its principal's name. An `@[actor-id]` reads natively when it's one of them,
924
- * and as the actor's name otherwise; an `@[email]`, as whoever the platform finds with it, or as
925
- * the email. The rest go as written.
938
+ * A message's text for a platform, through entry `key`. A mention is `@[actor-id]`, settled when
939
+ * the message was written: it reads natively when the actor is one of this entry's own users
940
+ * (`@[slack:user:U0456]` also naming this sync's own profile of them), and as the actor's name
941
+ * otherwise. An `@[email]` is whoever the platform finds with it, or the email. Everything else
942
+ * is text and goes as written, an `@handle` included: no sync reads one as a mention.
926
943
  */
927
- async function textFor(key, message, actors, text) {
928
- const tokens = extractMentions(text);
929
- if (tokens.length === 0) return text;
944
+ async function textFor(key, actors, text) {
945
+ const exact = extractMentions(text).flatMap((token) => token.kind === "actor" ? [token.actor] : []);
946
+ if (exact.length === 0) return text;
930
947
  const found = /* @__PURE__ */ new Map();
931
- for (const token of tokens) if (token.kind === "actor" && !actors.byId[token.actor] && isEmail(token.actor)) found.set(token.actor, await emailMention(key, token.actor));
932
- const users = /* @__PURE__ */ new Map();
933
- for (const token of tokens) {
934
- if (token.kind !== "handle") continue;
935
- const theirs = Object.values(actors.byId).filter((actor) => {
936
- const handle = actor.handle.toLowerCase();
937
- return handle === token.handle || !token.handle.includes("/") && handle.slice(handle.indexOf("/") + 1) === token.handle;
938
- });
939
- users.set(token.handle, theirs.flatMap((actor) => {
940
- const mention = nativeMention(key, actor.id, actors);
941
- return mention === null ? [] : [{
942
- id: actor.id,
943
- mention
944
- }];
945
- }));
946
- }
947
- const writers = [...users.values()].some((theirs) => new Set(theirs.map((user) => user.mention)).size > 1) ? new Set((await threadOf(message.re ?? message.id)).map((written) => written.by.actor)) : null;
948
- const one = (theirs) => {
949
- const mentions = new Set(theirs.map((user) => user.mention));
950
- return mentions.size === 1 ? [...mentions][0] : null;
951
- };
948
+ for (const named of exact) if (!actors.byId[named] && isEmail(named)) found.set(named, await emailMention(key, named));
952
949
  return replaceMentions(text, (token) => {
953
- if (token.kind === "handle") {
954
- const theirs = users.get(token.handle) ?? [];
955
- return one(theirs) ?? (writers ? one(theirs.filter((user) => writers.has(user.id))) : null);
956
- }
950
+ if (token.kind === "handle") return null;
957
951
  if (found.has(token.actor)) return found.get(token.actor) ?? token.actor;
958
- const actor = actors.byId[token.actor];
952
+ const actor = actorNamed(token.actor, actors);
959
953
  return actor ? nativeMention(key, actor.id, actors) ?? actor.name : null;
960
954
  });
961
955
  }
962
956
  /**
957
+ * The actor an `@[actor-id]` names: that actor, or, when the board has none by that ID, this
958
+ * sync's own profile of it (`@[slack:user:U0456]` for `<principal>+slack:user:U0456`).
959
+ */
960
+ function actorNamed(id, actors) {
961
+ return actors.byId[id] ?? (actors.principal ? actors.byId[`${actors.principal}+${id}`] : void 0) ?? null;
962
+ }
963
+ /**
963
964
  * Whose ID an actor is on entry `key`'s platform, when it's one of that entry's users: this sync's
964
965
  * own profile of them (`<principal>+<key>:…`), or one named under the key alone, as the board's
965
966
  * own sync names its users and as Vercel's board named imports before profiles. Null for anyone
@@ -1002,7 +1003,7 @@ function createSyncEngine(entries) {
1002
1003
  }));
1003
1004
  if (typeof body !== "string") throw badRequest("a provider renderer must return markdown");
1004
1005
  const labeled = `**${name}**: `;
1005
- const markdown = await textFor(key, message, actors, body.startsWith(labeled) && opensBlock(body.slice(labeled.length)) ? `**${name}**:\n\n${body.slice(labeled.length)}` : body);
1006
+ const markdown = await textFor(key, actors, body.startsWith(labeled) && opensBlock(body.slice(labeled.length)) ? `**${name}**:\n\n${body.slice(labeled.length)}` : body);
1006
1007
  const deployments = message.by.actor === "github:user:35613825" ? vercelDeployments(message.text) : null;
1007
1008
  return {
1008
1009
  markdown,
@@ -1,4 +1,4 @@
1
- import { p as MESSAGE_TEXT_MAX } from "./schemas-BhZaystC.mjs";
1
+ import { m as MESSAGE_TEXT_MAX } from "./schemas-7VFdomFB.mjs";
2
2
  import { r as normalizeEmoji } from "./emoji-CTLpvH-A.mjs";
3
3
  import { ZodError } from "zod";
4
4
  //#region src/contract/files.ts
@@ -257,6 +257,10 @@ function eventsState(onState) {
257
257
  failed: () => tell("retrying")
258
258
  };
259
259
  }
260
+ /** How long one request for a ready task is held, in seconds, as one for the next event is. */
261
+ const CLAIM_WAIT_S = 25;
262
+ /** How soon a claim that waits asks again, when the board answered without holding the request. */
263
+ const CLAIM_AGAIN_MS = 1e3;
260
264
  const UNITS = {
261
265
  ms: 1,
262
266
  s: 1e3,
@@ -345,6 +349,112 @@ function createBoardClient(options) {
345
349
  async function poll(query = {}, signal) {
346
350
  return call("GET", `/events${queryString(query)}`, signal ? { signal } : {});
347
351
  }
352
+ /** One write to task `id`, which answers its root. */
353
+ const taskWrite = async (id, verb, body = {}) => (await call("POST", `/tasks/${path(id)}/${verb}`, { body })).task;
354
+ /** What a claim on task `id` does, with the `epoch` and `token` the claim answered. */
355
+ const held = (id, proof) => {
356
+ const { epoch, token } = proof;
357
+ return {
358
+ async renew(lease) {
359
+ const { task, until } = await call("POST", `/tasks/${path(id)}/renew`, { body: {
360
+ epoch,
361
+ token,
362
+ ...lease !== void 0 ? { lease } : {}
363
+ } });
364
+ return claimed(task, {
365
+ epoch,
366
+ token,
367
+ until
368
+ });
369
+ },
370
+ release: () => taskWrite(id, "release", {
371
+ epoch,
372
+ token
373
+ }),
374
+ complete: (result) => taskWrite(id, "complete", {
375
+ epoch,
376
+ token,
377
+ ...result !== void 0 ? { result } : {}
378
+ }),
379
+ fail: (reason) => taskWrite(id, "fail", {
380
+ epoch,
381
+ token,
382
+ reason
383
+ }),
384
+ block: (reason, opts = {}) => taskWrite(id, "block", {
385
+ epoch,
386
+ token,
387
+ reason,
388
+ ...opts
389
+ })
390
+ };
391
+ };
392
+ /** A claim as a handle answers it: the task, the claim, and what the claim does. */
393
+ const claimed = (task, claim) => ({
394
+ task,
395
+ ...claim,
396
+ ...held(task.id, claim)
397
+ });
398
+ async function createTask(target, input = {}) {
399
+ const where = typeof target === "string" ? { channel: target } : { re: target.re };
400
+ const made = typeof input === "string" ? { text: input } : "attachments" in input && input.attachments?.length ? {
401
+ ...input,
402
+ attachments: input.attachments.map((file) => typeof file === "string" ? file : file.id)
403
+ } : input;
404
+ const { task, claim, mentions } = await call("POST", "/tasks", { body: {
405
+ ...where,
406
+ ...made
407
+ } });
408
+ return {
409
+ task,
410
+ ...claim ? { claim: claimed(task, claim) } : {},
411
+ ...mentions ? { mentions } : {}
412
+ };
413
+ }
414
+ /**
415
+ * Starts a thread in `channel` for each of `tasks`, as tasks, in one write: all of them or none,
416
+ * and none shows before all have landed. It answers their roots in the order given. A task waits
417
+ * for the ones made with it by their `key`. With `id`, a retry answers the tasks the first call
418
+ * made. A board makes 100 at most, and throws a 400 `batch_too_large` for more, or for more than it
419
+ * holds in one write: `createTasksInChunks` makes a longer plan, in several.
420
+ */
421
+ async function createTasks(channel, tasks, opts = {}) {
422
+ return (await call("POST", "/tasks/batch", { body: {
423
+ channel,
424
+ tasks: tasks.map((task) => task.attachments?.length ? {
425
+ ...task,
426
+ attachments: task.attachments.map((file) => typeof file === "string" ? file : file.id)
427
+ } : task),
428
+ ...opts.id !== void 0 ? { id: opts.id } : {}
429
+ } })).tasks;
430
+ }
431
+ async function claimTask(target, opts = {}) {
432
+ const signal = opts.signal ? { signal: opts.signal } : {};
433
+ if (typeof target === "string") {
434
+ const { task, claim } = await call("POST", `/tasks/${path(target)}/claim`, {
435
+ body: opts.lease !== void 0 ? { lease: opts.lease } : {},
436
+ ...signal
437
+ });
438
+ return claimed(task, claim);
439
+ }
440
+ const { wait, ...ready } = target;
441
+ const deadline = Date.now() + (wait ?? 0) * 1e3;
442
+ for (;;) {
443
+ const asked = Date.now();
444
+ const hold = Math.max(0, Math.min(CLAIM_WAIT_S, (deadline - asked) / 1e3));
445
+ const answer = await call("POST", "/tasks/claim", {
446
+ body: {
447
+ ...ready,
448
+ ...hold > 0 ? { wait: hold } : {}
449
+ },
450
+ ...signal
451
+ });
452
+ if (answer.task) return claimed(answer.task, answer.claim);
453
+ if (Date.now() >= deadline || opts.signal?.aborted) return null;
454
+ const pause = Math.min(CLAIM_AGAIN_MS - (Date.now() - asked), deadline - Date.now());
455
+ if (pause > 0) await new Promise((resolve) => setTimeout(resolve, pause));
456
+ }
457
+ }
348
458
  return {
349
459
  url: base,
350
460
  /**
@@ -429,19 +539,33 @@ function createBoardClient(options) {
429
539
  thread: (id) => call("GET", `/messages/${path(id)}`),
430
540
  /** Your own post with the client ID you gave it, as posting it answered: 404 `post_not_found` when there's none. */
431
541
  posted: async (id) => (await call("GET", `/posts/${path(id)}`)).message,
432
- /** Threads with a matching message, one summary each (root, reply count, latest reply), by latest activity. `limit` counts threads. */
542
+ /** Threads with a matching message, one summary each (root, reply count, latest reply), by latest activity. `limit` counts threads; `before` takes a page's `older`. */
433
543
  threads: (query = {}) => call("GET", `/threads${queryString(query)}`),
544
+ /**
545
+ * Starts a thread. An `@handle` in the text that names exactly one actor you can see is stored as
546
+ * `@[actor-id]`, a mention of them; one that names none or several stays as typed, a mention of
547
+ * no one. `mentions` on what comes back says what became of each, when the text typed any.
548
+ */
434
549
  async post(channel, input) {
435
- return (await call("POST", "/messages", { body: {
550
+ const { message, mentions } = await call("POST", "/messages", { body: {
436
551
  channel,
437
552
  ...messageBody(input)
438
- } })).message;
553
+ } });
554
+ return mentions ? {
555
+ ...message,
556
+ mentions
557
+ } : message;
439
558
  },
559
+ /** Replies in a thread. Its `@handle`s are settled as `post`'s are: of several who share one, it's the one who wrote in the thread. */
440
560
  async reply(id, input) {
441
- return (await call("POST", "/messages", { body: {
561
+ const { message, mentions } = await call("POST", "/messages", { body: {
442
562
  re: id,
443
563
  ...messageBody(input)
444
- } })).message;
564
+ } });
565
+ return mentions ? {
566
+ ...message,
567
+ mentions
568
+ } : message;
445
569
  },
446
570
  /**
447
571
  * Posts later, as you: a new thread when `target` is a channel, a reply when it's
@@ -449,16 +573,57 @@ function createBoardClient(options) {
449
573
  * `schedule: { id, n }`. Needs a board with a scheduler.
450
574
  */
451
575
  async schedule(target, input) {
452
- return (await call("POST", "/schedules", { body: {
576
+ const { schedule, mentions } = await call("POST", "/schedules", { body: {
453
577
  ...typeof target === "string" ? { channel: target } : { re: target.re },
454
578
  ...scheduleBody(input)
455
- } })).schedule;
579
+ } });
580
+ return mentions ? {
581
+ ...schedule,
582
+ mentions
583
+ } : schedule;
456
584
  },
457
585
  /** Pending schedules (`all` for done and canceled too), oldest first. `re` is any message in a thread. */
458
586
  schedules: async (query = {}) => (await call("GET", `/schedules${queryString(query)}`)).schedules,
459
587
  /** Stops a schedule: yours, or any with manage in its channel. `canceled` is false when it was already done or canceled. */
460
588
  cancelSchedule: (id) => call("POST", `/schedules/${path(id)}/cancel`, { body: {} }),
461
589
  /**
590
+ * Tasks: threads someone's agents are to do, with a state the board keeps. A task's ID is its
591
+ * root's, and its root's `task` says its state, whose it is, what it waits for, and who holds
592
+ * it. A board that keeps no tasks fails each of these with 501 `no_tasks`.
593
+ */
594
+ tasks: {
595
+ /**
596
+ * Tasks, oldest first, each as its thread's summary: open ones (`waiting`, `ready`, `claimed`,
597
+ * `blocked`) unless `state` says `all` or names one. `owner` and `for` take a handle or an ID,
598
+ * `needs` a task's ID, for the tasks that wait for it. `cursor`, as `after`, reads the next page.
599
+ */
600
+ list: (query = {}) => call("GET", `/tasks${queryString(query)}`),
601
+ create: createTask,
602
+ createMany: createTasks,
603
+ claim: claimTask,
604
+ /** What a claim you hold does, from the `epoch` and `token` it answered: for a process that kept them, as `vb` does between commands. */
605
+ held,
606
+ /** Holds a task no one has claimed for a person: yours, or any with manage in its channel. A claimed one's hold is its claim's (`claim.block`). */
607
+ block: (id, reason, opts = {}) => taskWrite(id, "block", {
608
+ reason,
609
+ ...opts
610
+ }),
611
+ /** Lifts a hold: the task is ready again, or waiting while a task it needs hasn't completed. */
612
+ unblock: (id) => taskWrite(id, "unblock"),
613
+ /** Makes a failed task ready again, in place: what waits for it still does. */
614
+ reopen: (id) => taskWrite(id, "reopen"),
615
+ /** Assigns a task to one of its owner's actors (`<owner>+<profile>`), the only one that claims it then, or with null to anyone who may. */
616
+ assign: (id, actor) => taskWrite(id, "assign", { for: actor }),
617
+ /**
618
+ * Replaces what a task waits for, by their IDs: it waits for those now, and is ready once they've all completed, or
619
+ * at once with none. For its owner, while no one holds it and it isn't finished. One that would make it wait for
620
+ * itself, through however many tasks, throws a 400 `invalid_needs`.
621
+ */
622
+ needs: (id, needs) => taskWrite(id, "needs", { needs }),
623
+ /** Cancels a task that hasn't completed, ending any claim. What waits for it keeps waiting. */
624
+ cancel: (id, reason) => taskWrite(id, "cancel", { reason })
625
+ },
626
+ /**
462
627
  * A new grant: `principals` may do what `can` says, a map from channel pattern to permissions
463
628
  * (`[]` for none). The same principals again are another grant. At each channel, the most
464
629
  * specific pattern among the grants that name a caller decides, then the closest principal,
@@ -717,6 +882,8 @@ const forbidden = (message) => new HttpError(403, "forbidden", message);
717
882
  const notFound = (message, code = "not_found") => new HttpError(404, code, message);
718
883
  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." });
719
884
  const duplicateId = () => new HttpError(409, "duplicate_id", "that id was already used for a different write");
885
+ /** More tasks than a board makes in one batch: `most` is how many it does. Nothing was made, and its sender splits it. */
886
+ const batchTooLarge = (tasks, most) => new HttpError(400, "batch_too_large", `a batch makes ${most} tasks at most, and this one has ${tasks}: send it in parts`);
720
887
  const json = (body, status = 200, headers) => new Response(JSON.stringify(body), {
721
888
  status,
722
889
  headers: {
@@ -774,4 +941,4 @@ function toErrorResponse(error) {
774
941
  } }, 500);
775
942
  }
776
943
  //#endregion
777
- export { typeOf as C, mediaType as S, ATTACHMENT_BYTES_MAX as _, forbidden as a, fileName as b, textTooLong as c, BoardError as d, createBoardClient as f, parseProfileHeader as g, formatProfileHeader as h, duplicateId as i, toErrorResponse as l, eventsState as m, RejectedError as n, json as o, duration as p, badRequest as r, notFound as s, HttpError as t, unauthorized as u, DIRECT_UPLOAD_BYTES_MAX as v, fileSize as x, IMPORT_BYTES_MAX as y };
944
+ export { fileSize as C, fileName as S, typeOf as T, formatProfileHeader as _, duplicateId as a, DIRECT_UPLOAD_BYTES_MAX as b, notFound as c, unauthorized as d, BoardError as f, InvalidProfileHeader as g, eventsState as h, batchTooLarge as i, textTooLong as l, duration as m, RejectedError as n, forbidden as o, createBoardClient as p, badRequest as r, json as s, HttpError as t, toErrorResponse as u, parseProfileHeader as v, mediaType as w, IMPORT_BYTES_MAX as x, ATTACHMENT_BYTES_MAX as y };
@@ -1,5 +1,5 @@
1
- import { f as Labels, u as LabelKey } from "./schemas-BhZaystC.mjs";
2
- import { n as ExternalEvent, r as ExternalLocation } from "./external-DfhN7lKK.mjs";
1
+ import { d as LabelKey, p as Labels } from "./schemas-7VFdomFB.mjs";
2
+ import { n as ExternalEvent, r as ExternalLocation } from "./external-BuVTXT1R.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/sync/fn.ts
5
5
  const ROUTES = Symbol.for("board.syncRoutes");