@vercel/board 0.45.1 → 0.46.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 (75) hide show
  1. package/dist/{access-3udXjJAg.mjs → access-Crbvd2Dm.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-BBphaJ_G.mjs} +3 -3
  5. package/dist/{auth-aiOVE82-.mjs → auth-C-pFnJBA.mjs} +2 -2
  6. package/dist/{auth-BG_whr9_.d.mts → auth-CkNXnQno.d.mts} +1 -1
  7. package/dist/{backend-D6yTo8Un.d.mts → backend-D3p8gjba.d.mts} +126 -4
  8. package/dist/backend-local.d.mts +1 -1
  9. package/dist/backend-local.mjs +1 -1
  10. package/dist/{chat-provider-BvNqOQFL.mjs → chat-provider-1zpY6Qo_.mjs} +2 -2
  11. package/dist/{chat-provider-V2jnjVLq.d.mts → chat-provider-Bn33acHd.d.mts} +2 -2
  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 +6 -6
  17. package/dist/{commands-DewS14_P.d.mts → commands-CSZPQ38I.d.mts} +54 -0
  18. package/dist/{commands-CqdnjUkm.mjs → commands-D0lyo8O8.mjs} +319 -0
  19. package/dist/{conformance-BInS4_6b.mjs → conformance-Blzd4CXG.mjs} +972 -6
  20. package/dist/conformance.d.mts +6 -5
  21. package/dist/conformance.mjs +1 -1
  22. package/dist/{engine-XVBt02Bl.mjs → engine-C_SlBihU.mjs} +15 -7
  23. package/dist/{errors-ZazTZh-s.mjs → errors-DZ1tbwSM.mjs} +151 -3
  24. package/dist/{events-D17RndlV.mjs → events-mGuhF4i5.mjs} +2 -2
  25. package/dist/{exports-DCxecX15.mjs → exports-DQauuHrc.mjs} +1226 -42
  26. package/dist/exports-DUX_Yzo7.d.mts +44 -0
  27. package/dist/{external-DfhN7lKK.mjs → external-BVr1Sq0y.mjs} +1 -1
  28. package/dist/{index-Djmr4GzQ.d.mts → index-BHXg4Xdo.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-CHsgnf_5.mjs → inspect-2OIjv2lW.mjs} +242 -20
  36. package/dist/inspect-F-b4GPXX.mjs +2 -0
  37. package/dist/{local-DE9vmanM.mjs → local-11FMUJrU.mjs} +1593 -60
  38. package/dist/{main-CF1Me3jg.mjs → main-BYmbTDgo.mjs} +1167 -24
  39. package/dist/{memory-DyEL0fvN.mjs → memory-CZBdVNn8.mjs} +2 -2
  40. package/dist/{middleware-BHHKHA9q.mjs → middleware-BKsTcMAv.mjs} +2 -2
  41. package/dist/{provider-BC9mPYVh.d.mts → provider-D3bfHRHA.d.mts} +119 -3
  42. package/dist/{routes-CkUetTO2.mjs → routes-B2HHHD_C.mjs} +246 -6
  43. package/dist/{routes-zm4TXKCC.d.mts → routes-NEc6w3QC.d.mts} +540 -6
  44. package/dist/{schemas-BhZaystC.mjs → schemas-7VFdomFB.mjs} +34 -1
  45. package/dist/{serve-CEMvl0EH.mjs → serve-DS2T2iWI.mjs} +4 -4
  46. package/dist/{server-Bmz0zqYM.mjs → server-Ch3tuK2k.mjs} +10 -10
  47. package/dist/{serving-BLVRrJ7P.mjs → serving-9riPNrHk.mjs} +1 -1
  48. package/dist/{sql-CyVcjw8x.mjs → sql-Bml29DpM.mjs} +174 -9
  49. package/dist/{sqlite-Con-8duk.mjs → sqlite-4C5u7-ag.mjs} +2 -2
  50. package/dist/{sqlite-db-BdzxtUOV.mjs → sqlite-db-eVb9v3zc.mjs} +1 -1
  51. package/dist/sync-chat-sdk.d.mts +2 -2
  52. package/dist/sync-chat-sdk.mjs +2 -2
  53. package/dist/sync-github.d.mts +2 -2
  54. package/dist/sync-github.mjs +2 -2
  55. package/dist/sync-linear.d.mts +3 -3
  56. package/dist/sync-linear.mjs +2 -2
  57. package/dist/sync-slack.d.mts +3 -3
  58. package/dist/sync-slack.mjs +4 -4
  59. package/dist/sync.d.mts +2 -2
  60. package/dist/sync.mjs +2 -2
  61. package/dist/{origin-BbwhnKrg.mjs → task-batch-BJcLiYe1.mjs} +83 -8
  62. package/dist/{tokens-BErYXuHZ.mjs → tokens-DPKF_cb5.mjs} +2 -2
  63. package/docs/01-board/01-mounting.md +1 -1
  64. package/docs/01-board/08-middleware.md +7 -0
  65. package/docs/01-board/11-tasks.md +348 -0
  66. package/docs/03-guides/02-inspector.md +66 -9
  67. package/docs/03-guides/06-sandboxed-agents.md +5 -3
  68. package/docs/03-guides/07-build-a-ui.md +210 -0
  69. package/docs/04-reference/01-cli.md +216 -8
  70. package/docs/04-reference/02-board.md +277 -2
  71. package/docs/04-reference/03-http.md +184 -10
  72. package/docs/04-reference/05-conformance.md +10 -7
  73. package/package.json +1 -1
  74. package/dist/exports-Gspe1eEq.d.mts +0 -4
  75. package/dist/inspect-C8U3A4jQ.mjs +0 -2
@@ -6,6 +6,12 @@ const CHANNEL_PATTERN_MAX = 2049;
6
6
  const MESSAGE_TEXT_MAX = 1e4;
7
7
  /** The longest `x-board-can` header the board reads; a schedule keeps its creator's. */
8
8
  const CAN_MAX = 4e3;
9
+ /** The label namespace the board writes itself: `board.task`, a task's state. No caller's write sets or unsets a key under it. */
10
+ const RESERVED_LABEL_PREFIX = "board.";
11
+ /** The label a task's root wears, with its state as the value. */
12
+ const TASK_LABEL = "board.task";
13
+ /** The longest result or reason a task keeps: a line or two, with the detail in its thread. */
14
+ const TASK_NOTE_MAX = 1e3;
9
15
  const segment = "[a-z0-9][a-z0-9_-]*";
10
16
  /** `errors-www`, `www/production`: lowercase segments joined by `/`. */
11
17
  const ChannelPath = z.string().max(CHANNEL_PATH_MAX).regex(new RegExp(`^${segment}(?:/${segment})*$`), "invalid channel path");
@@ -77,7 +83,34 @@ const Attachment = z.object({
77
83
  type: z.string().min(1).max(255),
78
84
  size: z.number().int().nonnegative()
79
85
  });
86
+ /** What a task is doing: its root's `board.task` label. */
87
+ const TaskState = z.enum([
88
+ "waiting",
89
+ "ready",
90
+ "claimed",
91
+ "blocked",
92
+ "completed",
93
+ "failed",
94
+ "canceled"
95
+ ]);
96
+ /** The states a task can still leave by being worked: `GET /tasks` lists these by default. */
97
+ const OPEN_TASK_STATES = [
98
+ "waiting",
99
+ "ready",
100
+ "claimed",
101
+ "blocked"
102
+ ];
103
+ /** A task's result or reason: a line or two. */
104
+ const TaskNote = z.string().max(TASK_NOTE_MAX).refine((text) => text.trim().length > 0, "it is empty").refine(storable, "it has a NUL character or a lone surrogate");
105
+ /** A task's result or reason as a request sends it: its length is the backend's to judge. */
106
+ const SentTaskNote = z.string().refine((text) => text.trim().length > 0, "it is empty").refine(storable, "it has a NUL character or a lone surrogate");
107
+ /** A hold's kind as a request sends it: its length is the backend's to judge. */
108
+ const SentTaskHoldKind = z.string().regex(/^[a-z0-9][a-z0-9_.-]*$/, "a kind is lowercase letters, numbers, and _.-");
109
+ /** Why a task is held, as whoever held it names it: `needs_input`, `awaiting_approval`. `edited` is the board's own. */
110
+ /** The kind of the hold the board places itself, when someone who doesn't own a task edits its root: no request holds a task as it. */
111
+ const EDITED_HOLD = "edited";
112
+ const TaskHoldKind = z.string().regex(/^[a-z0-9][a-z0-9_.-]{0,63}$/, "a kind is up to 64 lowercase letters, numbers, and _.-");
80
113
  /** A registered watcher's ID: a profile name, since its writes are by that profile. */
81
114
  const RemoteWatcherId = z.string().regex(/^[A-Za-z][A-Za-z0-9-]{0,31}$/, "ids start with a letter and use up to 32 letters, numbers, and hyphens");
82
115
  //#endregion
83
- export { toStorable as C, storable as S, SeenActorKind as _, CAN_MAX as a, authorView as b, Emoji as c, LabelValue as d, Labels as f, RemoteWatcherId as g, MessageText as h, Author as i, Handle as l, MessageId as m, Attachment as n, CHANNEL_PATTERN_MAX as o, MESSAGE_TEXT_MAX as p, AttachmentId as r, ChannelPath as s, ActorId as t, LabelKey as u, SentText as v, platformAvatar as x, actorKind as y };
116
+ export { authorView as A, SentText as C, TaskNote as D, TaskHoldKind as E, storable as M, toStorable as N, TaskState as O, SentTaskNote as S, TASK_NOTE_MAX as T, OPEN_TASK_STATES as _, CAN_MAX as a, SeenActorKind as b, EDITED_HOLD as c, LabelKey as d, LabelValue as f, MessageText as g, MessageId as h, Author as i, platformAvatar as j, actorKind as k, Emoji as l, MESSAGE_TEXT_MAX as m, Attachment as n, CHANNEL_PATTERN_MAX as o, Labels as p, AttachmentId as r, ChannelPath as s, ActorId as t, Handle as u, RESERVED_LABEL_PREFIX as v, TASK_LABEL as w, SentTaskHoldKind as x, RemoteWatcherId as y };
@@ -1,7 +1,7 @@
1
- import { d as BoardError } from "./errors-ZazTZh-s.mjs";
2
- import { d as localTokenFile, t as board } from "./server-Bmz0zqYM.mjs";
3
- import { t as oidcTokens } from "./tokens-BErYXuHZ.mjs";
4
- import { t as local } from "./local-DE9vmanM.mjs";
1
+ import { f as BoardError } from "./errors-DZ1tbwSM.mjs";
2
+ import { p as localTokenFile, t as board } from "./server-Ch3tuK2k.mjs";
3
+ import { t as oidcTokens } from "./tokens-DPKF_cb5.mjs";
4
+ import { t as local } from "./local-11FMUJrU.mjs";
5
5
  import { mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
6
6
  import { userInfo } from "node:os";
7
7
  import { dirname, join, resolve } from "node:path";
@@ -1,9 +1,9 @@
1
- import { d as BoardError, f as createBoardClient, h as formatProfileHeader, t as HttpError } from "./errors-ZazTZh-s.mjs";
2
- import "./schemas-BhZaystC.mjs";
3
- import { F as routes } from "./routes-CkUetTO2.mjs";
4
- import { g as keyId, p as DERIVED_ID } from "./middleware-BHHKHA9q.mjs";
5
- import { a as compileWatcher, c as METHODS } from "./origin-BbwhnKrg.mjs";
6
- import { c as tailWatchers, i as createVercel, l as deployedOnVercel, o as PROTOCOL_ROUTES, s as withoutToken, t as createBoard } from "./exports-DCxecX15.mjs";
1
+ import { _ as formatProfileHeader, f as BoardError, p as createBoardClient, t as HttpError } from "./errors-DZ1tbwSM.mjs";
2
+ import "./schemas-7VFdomFB.mjs";
3
+ import { Y as routes } from "./routes-B2HHHD_C.mjs";
4
+ import { g as keyId, p as DERIVED_ID } from "./middleware-BKsTcMAv.mjs";
5
+ import { l as METHODS, o as compileWatcher } from "./task-batch-BJcLiYe1.mjs";
6
+ import { c as PROTOCOL_ROUTES, d as deployedOnVercel, l as withoutToken, o as createVercel, r as createBoard, u as tailWatchers } from "./exports-DQauuHrc.mjs";
7
7
  import { execFile } from "node:child_process";
8
8
  import { createHash } from "node:crypto";
9
9
  import { mkdir, readFile, readdir, stat, unlink, writeFile } from "node:fs/promises";
@@ -808,7 +808,7 @@ function createHttp(url, options, environment) {
808
808
  start();
809
809
  if ("identity" in caller) throw new HttpError(404, "not_found", `this board uses ${remote}, and answers nothing itself`);
810
810
  const client = clientOf(caller);
811
- if ((method === "post" || method === "posted") && "self" in caller && typeof input.id === "string" && DERIVED_ID.test(input.id)) input = {
811
+ if ((method === "post" || method === "posted" || method === "createTask" || method === "createTasks" || method === "createdTasks") && "self" in caller && typeof input.id === "string" && DERIVED_ID.test(input.id)) input = {
812
812
  ...input,
813
813
  id: await ownKey(input.id).catch(rethrow)
814
814
  };
@@ -989,10 +989,10 @@ function vercel(options = {}) {
989
989
  function board(options = {}) {
990
990
  return createBoard(options, {
991
991
  backend: (fetch) => process.env.BOARD_URL?.trim() ? http() : vercel(fetch ? { fetch } : {}),
992
- sync: () => import("./engine-XVBt02Bl.mjs"),
993
- serving: () => import("./serving-BLVRrJ7P.mjs"),
992
+ sync: () => import("./engine-C_SlBihU.mjs"),
993
+ serving: () => import("./serving-9riPNrHk.mjs"),
994
994
  sandbox: (url, token) => sandboxHeaders(url, url, token)
995
995
  });
996
996
  }
997
997
  //#endregion
998
- export { vercel as a, connect as c, localTokenFile as d, projectDir as f, handTeam as i, handFetch as l, credentialSource as n, http as o, vercelProjectFile as p, credentialed as r, boardUrl as s, board as t, handLogin as u };
998
+ export { vercel as a, configDir as c, handFetch as d, handLogin as f, vercelProjectFile as h, handTeam as i, connect as l, projectDir as m, credentialSource as n, http as o, localTokenFile as p, credentialed as r, boardUrl as s, board as t, environmentProfile as u };
@@ -1,2 +1,2 @@
1
- import { i as ownTeamId, n as discoveryIdentity, r as ownProjectId, t as oidcTokens } from "./tokens-BErYXuHZ.mjs";
1
+ import { i as ownTeamId, n as discoveryIdentity, r as ownProjectId, t as oidcTokens } from "./tokens-DPKF_cb5.mjs";
2
2
  export { discoveryIdentity, oidcTokens, ownProjectId, ownTeamId };
@@ -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-BVr1Sq0y.mjs";
3
3
  import { t as canonicalEmoji } from "./emoji-CTLpvH-A.mjs";
4
- import { n as setOwn, t as own } from "./own-OwgPWdmh.mjs";
5
4
  import { i as mentionTerms } from "./mentions-DfZGp3B-.mjs";
5
+ import { n as setOwn, t as own } from "./own-OwgPWdmh.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)}`,
863
+ values: p.values
864
+ };
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)}`,
737
878
  values: p.values
738
879
  };
739
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-Bml29DpM.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-eVb9v3zc.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-Bml29DpM.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-D3bfHRHA.mjs";
2
+ import { r as ChatTransport, t as ChatInput } from "./chat-provider-Bn33acHd.mjs";
3
3
  import { z } from "zod";
4
4
  import { ReactionEvent } from "chat";
5
5
  //#region src/sync/chat-sdk.d.ts
@@ -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-mGuhF4i5.mjs";
2
+ import { t as ChatSyncProvider } from "./chat-provider-1zpY6Qo_.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-D3bfHRHA.mjs";
2
+ import { n as ChatSyncProvider } from "./chat-provider-Bn33acHd.mjs";
3
3
  import { z } from "zod";
4
4
  import { Adapter } from "chat";
5
5
  //#region src/sync/github.d.ts
@@ -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-mGuhF4i5.mjs";
2
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-1zpY6Qo_.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";
@@ -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-NEc6w3QC.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-D3bfHRHA.mjs";
3
+ import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-Bn33acHd.mjs";
4
4
  import { z } from "zod";
5
5
  import { Adapter } from "chat";
6
6
  //#region src/sync/linear.d.ts
@@ -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-mGuhF4i5.mjs";
2
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-1zpY6Qo_.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-NEc6w3QC.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-D3bfHRHA.mjs";
3
+ import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-Bn33acHd.mjs";
4
4
  import { z } from "zod";
5
5
  import { Adapter } from "chat";
6
6
  //#region src/sync/slack-deployments.d.ts
@@ -1,7 +1,7 @@
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-BVr1Sq0y.mjs";
3
+ import { d as opensBlock, i as eventSchema, l as UnreadableError, p as channels, r as envelope } from "./events-mGuhF4i5.mjs";
4
+ import { n as markdownOf, t as ChatSyncProvider } from "./chat-provider-1zpY6Qo_.mjs";
5
5
  import { r as formatVercelDeployments } from "./bots-CLKKMgYf.mjs";
6
6
  import { z } from "zod";
7
7
  import { stringifyMarkdown } from "chat";
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-NEc6w3QC.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-D3bfHRHA.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-BVr1Sq0y.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-mGuhF4i5.mjs";
3
3
  export { EventBase, ExternalEvent, ReceivedEvent, ResolvedTarget, SyncOverrides, SyncProvider, UnreadableError, channels, envelope, eventSchema, into, mirror, render };
@@ -1,13 +1,13 @@
1
- import { _ as ATTACHMENT_BYTES_MAX, r as badRequest, t as HttpError } from "./errors-ZazTZh-s.mjs";
2
- import "./schemas-BhZaystC.mjs";
3
- import { l as isThreadTarget } from "./external-DfhN7lKK.mjs";
4
- import { F as routes, s as Filters } from "./routes-CkUetTO2.mjs";
5
- import { i as afterRetry } from "./middleware-BHHKHA9q.mjs";
6
- import { o as options } from "./commands-CqdnjUkm.mjs";
1
+ import { r as badRequest, t as HttpError, y as ATTACHMENT_BYTES_MAX } from "./errors-DZ1tbwSM.mjs";
2
+ import "./schemas-7VFdomFB.mjs";
3
+ import { l as isThreadTarget } from "./external-BVr1Sq0y.mjs";
4
+ import { Y as routes, _ as Filters } from "./routes-B2HHHD_C.mjs";
5
+ import { i as afterRetry } from "./middleware-BKsTcMAv.mjs";
6
+ import { o as options } from "./commands-D0lyo8O8.mjs";
7
7
  import { z } from "zod";
8
8
  //#endregion
9
9
  //#region src/version.ts
10
- const VERSION = "0.45.1";
10
+ const VERSION = "0.46.0";
11
11
  //#endregion
12
12
  //#region src/server/backend.ts
13
13
  /** The subscription sync's outbound runs on, in `BoardBinding.subscriptions`. No watcher's ID starts with `@`. */
@@ -40,6 +40,22 @@ const METHODS = [
40
40
  "schedule",
41
41
  "schedules",
42
42
  "cancelSchedule",
43
+ "tasks",
44
+ "createTask",
45
+ "createTasks",
46
+ "createdTasks",
47
+ "claimReadyTask",
48
+ "claimTask",
49
+ "renewTask",
50
+ "releaseTask",
51
+ "completeTask",
52
+ "failTask",
53
+ "blockTask",
54
+ "unblockTask",
55
+ "reopenTask",
56
+ "assignTask",
57
+ "setTaskNeeds",
58
+ "cancelTask",
43
59
  "grants",
44
60
  "createGrant",
45
61
  "updateGrant",
@@ -72,6 +88,7 @@ const METHODS = [
72
88
  "synced",
73
89
  "linked"
74
90
  ];
91
+ METHODS.filter((name) => name === "tasks" || name.includes("Task"));
75
92
  const escape = (literal) => literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
76
93
  function compile(method, path, target, own) {
77
94
  const parts = path.split("/").filter(Boolean);
@@ -425,4 +442,62 @@ const syncTarget = (target) => typeof target === "string" ? {
425
442
  */
426
443
  const SYNC_ACTOR = "board:sync";
427
444
  //#endregion
428
- export { compileWatcher as a, METHODS as c, queryObject as d, readCapped as f, VERSION as h, runMatch as i, createRouter as l, SYNC as m, syncTarget as n, hasCriteria as o, readJson as p, canonicalWatchers as r, withMentions as s, SYNC_ACTOR as t, openapi as u };
445
+ //#region src/contract/task-batch.ts
446
+ /**
447
+ * For each task of a batch, the batch's tasks it waits for, by their place in it, and an order to
448
+ * make them in: every task after the ones it waits for, and as the batch has them otherwise. A
449
+ * `problem` instead when two tasks have one `key`, a task waits for a `key` no task has or for
450
+ * itself, or tasks wait for each other: such a batch can't be made.
451
+ */
452
+ function batchPlan(tasks) {
453
+ const named = /* @__PURE__ */ new Map();
454
+ for (const [at, task] of tasks.entries()) {
455
+ if (task.key === void 0) continue;
456
+ if (named.has(task.key)) return { problem: `two tasks of the batch have the key ${JSON.stringify(task.key)}` };
457
+ named.set(task.key, at);
458
+ }
459
+ const inside = [];
460
+ for (const [at, task] of tasks.entries()) {
461
+ const waits = /* @__PURE__ */ new Set();
462
+ for (const need of task.needs ?? []) {
463
+ if (typeof need === "string") continue;
464
+ const found = named.get(need.key);
465
+ if (found === void 0) return { problem: `no task of the batch has the key ${JSON.stringify(need.key)}` };
466
+ if (found === at) return { problem: `the task with the key ${JSON.stringify(need.key)} waits for itself` };
467
+ waits.add(found);
468
+ }
469
+ inside.push([...waits]);
470
+ }
471
+ const order = [];
472
+ const state = new Uint8Array(tasks.length);
473
+ for (let start = 0; start < tasks.length; start++) {
474
+ if (state[start] !== 0) continue;
475
+ const path = [{
476
+ at: start,
477
+ next: 0
478
+ }];
479
+ state[start] = 1;
480
+ while (path.length > 0) {
481
+ const top = path.at(-1);
482
+ const need = inside[top.at][top.next++];
483
+ if (need === void 0) {
484
+ state[top.at] = 2;
485
+ order.push(top.at);
486
+ path.pop();
487
+ } else if (state[need] === 1) return { problem: `the tasks with the keys ${path.slice(path.findIndex((step) => step.at === need)).map((step) => JSON.stringify(tasks[step.at].key)).join(", ")} wait for each other` };
488
+ else if (state[need] === 0) {
489
+ state[need] = 1;
490
+ path.push({
491
+ at: need,
492
+ next: 0
493
+ });
494
+ }
495
+ }
496
+ }
497
+ return {
498
+ inside,
499
+ order
500
+ };
501
+ }
502
+ //#endregion
503
+ export { runMatch as a, withMentions as c, openapi as d, queryObject as f, VERSION as g, SYNC as h, canonicalWatchers as i, METHODS as l, readJson as m, SYNC_ACTOR as n, compileWatcher as o, readCapped as p, syncTarget as r, hasCriteria as s, batchPlan as t, createRouter as u };
@@ -1,5 +1,5 @@
1
- import { u as unauthorized } from "./errors-ZazTZh-s.mjs";
2
- import { g as privateHost, h as markVerified, i as VERCEL_ISSUER, p as issuerName, r as TOKENS, v as trustedIssuers } from "./auth-aiOVE82-.mjs";
1
+ import { d as unauthorized } from "./errors-DZ1tbwSM.mjs";
2
+ import { g as privateHost, h as markVerified, i as VERCEL_ISSUER, p as issuerName, r as TOKENS, v as trustedIssuers } from "./auth-C-pFnJBA.mjs";
3
3
  import { createRemoteJWKSet, decodeJwt, jwtVerify } from "jose";
4
4
  //#region src/server/identity.ts
5
5
  let fromDisk;
@@ -52,7 +52,7 @@ on any backend, and the backend stores. SSE, [the handle](#the-handle),
52
52
  `board()` with no backend keeps nothing here:
53
53
 
54
54
  - **Vercel's API keeps the board:** messages, threads, reactions, labels, a
55
- channel's changes, schedules, and files, up to 100 MB each as a
55
+ channel's changes, schedules, tasks, and files, up to 100 MB each as a
56
56
  [direct upload](../04-reference/03-http.md#direct-uploads).
57
57
  - **Its watchers run here.** Vercel's API matches each event against their
58
58
  tails and wakes this route when one matches: see
@@ -60,6 +60,13 @@ it's made, as the caller's post.
60
60
  fails with `duplicate_id`. A write it dropped has nothing on the board, so a
61
61
  retry goes through it again: keep side effects like `respond` idempotent, or
62
62
  cheap to repeat.
63
+ - **A batch of tasks goes through a root at a time.** `tasks.createMany` hands
64
+ it each task's root as a post, in order, before any is written: one it drops
65
+ makes none of them. A retry of a batch that landed skips it, as a post's
66
+ does: the board looks for the batch by its `id` first, and tells the same
67
+ request by what was sent, before the middleware. Vercel's board has no such
68
+ read, so a retry goes through again there: see
69
+ [`tasks`](../04-reference/02-board.md#tasks).
63
70
 
64
71
  ## What it gets
65
72