@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
@@ -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 };
@@ -0,0 +1,285 @@
1
+ import { f as BoardError, p as createBoardClient, t as HttpError } from "./errors-QhkdzI-o.mjs";
2
+ import { i as LOGINS, r as LOGIN } from "./auth-B9-wXQ-x.mjs";
3
+ import { p as localTokenFile, t as board } from "./server-4rQL3xuH.mjs";
4
+ import { t as oidcTokens } from "./tokens-BCp4EWTQ.mjs";
5
+ import { t as local } from "./local-0ajWOVhN.mjs";
6
+ import { mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
7
+ import { userInfo } from "node:os";
8
+ import { dirname, join, resolve } from "node:path";
9
+ import { SignJWT, createLocalJWKSet, exportJWK, generateKeyPair } from "jose";
10
+ import { createServer } from "node:http";
11
+ //#region src/cli/tailscale.ts
12
+ /**
13
+ * The login Tailscale says a request is from, as its `Tailscale-User-Login` header gives it, in
14
+ * lowercase: `ada@example.com`. Null when it names none, as for a tagged device or a request
15
+ * through Funnel, or one a principal's ID can't hold (a `+`, or what Tailscale had to encode).
16
+ */
17
+ function tailscaleLogin(header) {
18
+ const login = typeof header === "string" ? header.trim().toLowerCase() : "";
19
+ return LOGIN.test(login) ? login : null;
20
+ }
21
+ /**
22
+ * `tokens`, and where `at` says Tailscale serves the board, the people Tailscale says are calling:
23
+ * a request there with no token is `tailscale:user:<login>`, a person, with the handle before the
24
+ * login's `@`. `tailscale serve` drops any `Tailscale-User-Login` its caller sent and sets its own,
25
+ * so the header is Tailscale's word wherever only its proxy and this machine reach the board; it's
26
+ * read nowhere else, since any other sender writes its own.
27
+ *
28
+ * A browser sends a page's requests from its user's place on the tailnet, whatever site the page is
29
+ * from, so a request a browser marks as another site's is no one's: only the board's own origin
30
+ * acts as its visitor.
31
+ */
32
+ function tailscale(tokens, at) {
33
+ const authenticate = (request) => {
34
+ if (request.credential !== null || !at(request.audience)) return tokens(request);
35
+ const login = tailscaleLogin(request.headers.get("tailscale-user-login"));
36
+ if (login === null) return null;
37
+ const site = request.headers.get("sec-fetch-site");
38
+ const origin = request.headers.get("origin");
39
+ if (site !== null && site !== "same-origin" && site !== "none" || origin !== null && origin !== new URL(request.audience).origin) throw new HttpError(403, "forbidden", "a page on another site can't act as you on this board");
40
+ return {
41
+ id: `tailscale:user:${login}`,
42
+ kind: "person",
43
+ handle: login.slice(0, login.indexOf("@"))
44
+ };
45
+ };
46
+ return Object.assign(authenticate, { [LOGINS]: true });
47
+ }
48
+ /** Where the board is mounted on its server: every other path is the inspector's, when it's served. */
49
+ const MOUNT = "/api/board";
50
+ const mounted = (path) => path === MOUNT || path.startsWith(`${MOUNT}/`);
51
+ const ISSUER = "board:local";
52
+ const BODY_MAX = 8388608;
53
+ /** Your OS username as a handle: lowercase letters, digits, `.`, `_`, `-`. */
54
+ function localHandle(name = safeUsername()) {
55
+ return name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, "").slice(0, 64).replace(/[^a-z0-9]+$/, "") || "me";
56
+ }
57
+ function safeUsername() {
58
+ try {
59
+ return userInfo().username;
60
+ } catch {
61
+ return process.env.USER || process.env.USERNAME || "me";
62
+ }
63
+ }
64
+ /** What an earlier `vb serve` left under `dir` (`board.db`, `attachments/`), moved to where `local()` keeps the board. */
65
+ async function carryOver(dir) {
66
+ const there = (path) => stat(join(dir, path)).then(() => true, () => false);
67
+ if (!await there("board.db") || await there("local.db")) return;
68
+ for (const suffix of [
69
+ "",
70
+ "-wal",
71
+ "-shm"
72
+ ]) if (await there(`board.db${suffix}`)) await rename(join(dir, `board.db${suffix}`), join(dir, `local.db${suffix}`));
73
+ if (await there("attachments") && !await there("local")) await rename(join(dir, "attachments"), join(dir, "local"));
74
+ }
75
+ /**
76
+ * A board on this machine, for agents and people sharing one computer: `local()` under `dir`, its
77
+ * log in SQLite, attachments next to it, a scheduler in this process, no sync, on 127.0.0.1 only.
78
+ * Its keys live in memory for this run; it signs one token, for you, into a file only you can read
79
+ * (`localTokenFile`), which `vb` on this machine picks up. `hosts` adds names a proxy in front of
80
+ * it serves it on: a request for one reaches the board at that host's URL, which a token must be
81
+ * minted for there, and your token is for its own. Its server answers the board under `/api/board`,
82
+ * and what `page` is given everywhere else. `tailscale` names the hosts `tailscale serve` is the
83
+ * proxy for: they're allowed like `hosts`, and a request for one with no token is the person
84
+ * Tailscale says sent it (`tailscale()`).
85
+ */
86
+ async function serveLocal(options) {
87
+ const dir = resolve(options.dir);
88
+ await mkdir(dir, {
89
+ recursive: true,
90
+ mode: 448
91
+ });
92
+ quietSqliteWarning();
93
+ await carryOver(dir);
94
+ const backend = local({ dir });
95
+ const { publicKey, privateKey } = await generateKeyPair("ES256");
96
+ const jwks = createLocalJWKSet({ keys: [{
97
+ ...await exportJWK(publicKey),
98
+ kid: "local",
99
+ alg: "ES256"
100
+ }] });
101
+ const tailnet = new Set((options.tailscale ?? []).map((host) => host.toLowerCase()));
102
+ const hosts = /* @__PURE__ */ new Set([...(options.hosts ?? []).map((host) => host.toLowerCase()), ...tailnet]);
103
+ let origin = "";
104
+ let handler = null;
105
+ let page = null;
106
+ const server = createServer((request, response) => {
107
+ if (!handler) return void response.writeHead(503).end();
108
+ if (page && !mounted((request.url ?? "/").split("?")[0])) try {
109
+ return page(request, response);
110
+ } catch {
111
+ if (!response.headersSent) response.writeHead(500);
112
+ response.end();
113
+ return;
114
+ }
115
+ forward(handler, originOf(request, origin, hosts), request, response);
116
+ });
117
+ let port;
118
+ try {
119
+ port = await listen(server, options.port ?? 4100);
120
+ } catch (error) {
121
+ if (error.code === "EADDRINUSE") throw new BoardError("port_taken", `Port ${options.port ?? 4100} is taken. Is a board already running there?`, 0);
122
+ throw error;
123
+ }
124
+ origin = `http://127.0.0.1:${port}`;
125
+ const url = `${origin}${MOUNT}`;
126
+ const tokens = oidcTokens({ local: {
127
+ issuer: ISSUER,
128
+ jwks
129
+ } });
130
+ const team = board({
131
+ backend,
132
+ authenticate: tailnet.size > 0 ? tailscale(tokens, (audience) => servedAt(tailnet, audience)) : tokens,
133
+ basePath: MOUNT
134
+ });
135
+ try {
136
+ await team.channels();
137
+ } catch (error) {
138
+ server.close();
139
+ throw error;
140
+ }
141
+ handler = team.fetch;
142
+ const handle = options.handle ?? localHandle();
143
+ const token = await new SignJWT({}).setProtectedHeader({
144
+ alg: "ES256",
145
+ kid: "local"
146
+ }).setIssuer(ISSUER).setAudience(url).setSubject(handle).setIssuedAt().setExpirationTime("30d").sign(privateKey);
147
+ const file = localTokenFile(url);
148
+ await mkdir(dirname(file), {
149
+ recursive: true,
150
+ mode: 448
151
+ });
152
+ await writeFile(file, JSON.stringify({
153
+ url,
154
+ token,
155
+ handle
156
+ }), { mode: 384 });
157
+ const visitors = /* @__PURE__ */ new Map();
158
+ return {
159
+ url,
160
+ port,
161
+ page(handler) {
162
+ page = handler;
163
+ },
164
+ visitor(request) {
165
+ const at = originOf(request, origin, hosts);
166
+ if (at === origin) return void 0;
167
+ if (!servedAt(tailnet, at)) return tailnet.size > 0 ? null : void 0;
168
+ const login = tailscaleLogin(request.headers["tailscale-user-login"]);
169
+ if (login === null) return null;
170
+ const key = `${at} ${login}`;
171
+ const known = visitors.get(key);
172
+ if (known) return known;
173
+ const client = createBoardClient({
174
+ url: `${at}${MOUNT}`,
175
+ fetch: ((input, init) => {
176
+ const sent = new Request(input, init);
177
+ sent.headers.set("tailscale-user-login", login);
178
+ return team.fetch(sent);
179
+ })
180
+ });
181
+ visitors.set(key, client);
182
+ return client;
183
+ },
184
+ principal: `local:user:${handle}`,
185
+ handle,
186
+ token,
187
+ dir,
188
+ async close() {
189
+ await rm(file, { force: true });
190
+ server.closeAllConnections();
191
+ await new Promise((done) => server.close(() => done()));
192
+ await backend.close();
193
+ }
194
+ };
195
+ }
196
+ /** Node flags `node:sqlite` as experimental on stderr, which would be the CLI's only stderr line. */
197
+ function quietSqliteWarning() {
198
+ const emit = process.emitWarning;
199
+ process.emitWarning = ((warning, ...rest) => {
200
+ const text = typeof warning === "string" ? warning : warning.message;
201
+ if (/SQLite is an experimental feature/.test(text)) return;
202
+ return emit.call(process, warning, ...rest);
203
+ });
204
+ }
205
+ function listen(server, port) {
206
+ return new Promise((done, fail) => {
207
+ server.once("error", fail);
208
+ server.listen(port, "127.0.0.1", () => {
209
+ server.off("error", fail);
210
+ done(server.address().port);
211
+ });
212
+ });
213
+ }
214
+ /**
215
+ * Where a request reached this server: at a host you allowed, over `https` when the proxy in front
216
+ * says so (`X-Forwarded-Proto`), and at the server's `own` address for any other. A request's
217
+ * sender chooses its `Host`, so one you didn't allow never names the board.
218
+ */
219
+ function originOf(request, own, hosts) {
220
+ const host = String(request.headers.host ?? "").toLowerCase();
221
+ if (!hosts.has(host)) return own;
222
+ return `${String(request.headers["x-forwarded-proto"] ?? "").split(",")[0].trim().toLowerCase() === "https" ? "https" : "http"}://${host}`;
223
+ }
224
+ /**
225
+ * Whether `url` is at one of `hosts`, however each was written: a URL leaves its scheme's own port
226
+ * out of its host (`box:443` over https is `box`), so each is compared as that URL would write it.
227
+ */
228
+ function servedAt(hosts, url) {
229
+ const { protocol, host } = new URL(url);
230
+ for (const named of hosts) try {
231
+ if (new URL(`${protocol}//${named}`).host === host) return true;
232
+ } catch {}
233
+ return false;
234
+ }
235
+ async function forward(handler, origin, req, res) {
236
+ const controller = new AbortController();
237
+ res.on("close", () => controller.abort());
238
+ try {
239
+ let body;
240
+ if (req.method !== "GET" && req.method !== "HEAD") {
241
+ const chunks = [];
242
+ let size = 0;
243
+ for await (const chunk of req) {
244
+ size += chunk.length;
245
+ if (size > BODY_MAX) {
246
+ res.writeHead(413, { "content-type": "application/json" });
247
+ res.end(JSON.stringify({ error: {
248
+ code: "too_large",
249
+ message: "request too large"
250
+ } }));
251
+ return;
252
+ }
253
+ chunks.push(chunk);
254
+ }
255
+ body = new Uint8Array(Buffer.concat(chunks));
256
+ }
257
+ const headers = new Headers();
258
+ for (const [key, value] of Object.entries(req.headers)) if (typeof value === "string") headers.set(key, value);
259
+ else if (Array.isArray(value)) for (const item of value) headers.append(key, item);
260
+ const response = await handler(new Request(`${origin}${req.url ?? "/"}`, {
261
+ method: req.method ?? "GET",
262
+ headers,
263
+ ...body && body.length > 0 ? { body } : {},
264
+ signal: controller.signal
265
+ }));
266
+ const out = {};
267
+ response.headers.forEach((value, key) => {
268
+ if (key === "set-cookie") return;
269
+ out[key] = value;
270
+ });
271
+ res.writeHead(response.status, out);
272
+ if (response.body) try {
273
+ for await (const chunk of response.body) res.write(chunk);
274
+ } catch {}
275
+ res.end();
276
+ } catch (error) {
277
+ if (!res.headersSent) res.writeHead(500, { "content-type": "application/json" });
278
+ res.end(JSON.stringify({ error: {
279
+ code: "internal",
280
+ message: error.message
281
+ } }));
282
+ }
283
+ }
284
+ //#endregion
285
+ export { serveLocal };
@@ -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-QhkdzI-o.mjs";
2
+ import "./schemas-7VFdomFB.mjs";
3
+ import { Y as routes } from "./routes-ABXf3CKq.mjs";
4
+ import { g as keyId, p as DERIVED_ID } from "./middleware-CT6vMNUc.mjs";
5
+ import { l as METHODS, o as compileWatcher } from "./task-batch-BZXm6kOE.mjs";
6
+ import { c as PROTOCOL_ROUTES, d as deployedOnVercel, l as withoutToken, o as createVercel, r as createBoard, u as tailWatchers } from "./exports-CEqS-IPP.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";
@@ -177,13 +177,13 @@ const apiLogin = async (handed) => handed ?? await getVercelToken().catch(() =>
177
177
  /**
178
178
  * A person's token: their Vercel CLI login mints a development token for the
179
179
  * project the board's host is a deployment of, exchanged so its audience is the
180
- * board's URL. Cached on disk for its 12-hour life.
180
+ * board's URL. Cached on disk for its 12-hour life. For a board whose discovery
181
+ * names a project: one that names none has no token for a login to mint.
181
182
  */
182
183
  async function personToken(audience, discovery) {
183
184
  const login = await handedToken();
184
185
  const cached = await readCache(audience, login);
185
186
  if (cached) return cached;
186
- if (!discovery.project_id) throw new BoardError("no_project", `The board at ${audience} doesn't know its Vercel project, so there's no Vercel login token to mint for it.`, 0, { hint: "Pass a token it accepts in BOARD_TOKEN." });
187
187
  const authToken = await apiLogin(login);
188
188
  const project = await boardProject(audience, discovery, authToken);
189
189
  let development;
@@ -266,7 +266,9 @@ function boardUrl() {
266
266
  * How a client reaches the board at `url` from Node: through Deployment Protection, with a token
267
267
  * from `token`, `BOARD_TOKEN`, a local board's token file (`vb serve`), GitHub Actions, the Vercel
268
268
  * runtime, or your Vercel CLI login, in that order. Who you are is the token's to say: the board
269
- * names you from what it verifies.
269
+ * names you from what it verifies. A board with no Vercel project has no token for your login to
270
+ * mint, so a request goes to it with none: what verifies its callers may know you another way, as
271
+ * a board behind `tailscale serve` does.
270
272
  */
271
273
  function connect(url, options = {}) {
272
274
  url = url.replace(/\/+$/, "");
@@ -325,6 +327,10 @@ function connect(url, options = {}) {
325
327
  expiresAt: expiry(token)
326
328
  };
327
329
  }
330
+ if (!discovered.project_id) return {
331
+ token: null,
332
+ expiresAt: Date.now() + 3e5
333
+ };
328
334
  person ??= personToken(url, discovered).finally(() => {
329
335
  person = null;
330
336
  });
@@ -341,13 +347,21 @@ function connect(url, options = {}) {
341
347
  const method = (init.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
342
348
  const path = (href.startsWith(url) ? href.slice(url.length) : new URL(href).pathname).split("?")[0] || "/";
343
349
  const headers = new Headers(init.headers ?? (input instanceof Request ? input.headers : void 0));
344
- if (!(method === "GET" && path === "/")) {
345
- if (!headers.has("authorization")) headers.set("authorization", `Bearer ${await token()}`);
350
+ let bare = false;
351
+ if (!(method === "GET" && path === "/") && !headers.has("authorization")) {
352
+ const credential = await token();
353
+ if (credential !== null) headers.set("authorization", `Bearer ${credential}`);
354
+ else bare = true;
346
355
  }
347
- return doFetch(input, {
356
+ const response = await doFetch(input, {
348
357
  ...init,
349
358
  headers
350
359
  });
360
+ if (bare && response.status === 401) {
361
+ await response.body?.cancel().catch(() => {});
362
+ throw new BoardError("no_project", `The board at ${url} has no Vercel project to mint you a token for, and doesn't know who you are without one.`, 0, { hint: "Pass a token it accepts in BOARD_TOKEN." });
363
+ }
364
+ return response;
351
365
  });
352
366
  return {
353
367
  fetch: send,
@@ -808,7 +822,7 @@ function createHttp(url, options, environment) {
808
822
  start();
809
823
  if ("identity" in caller) throw new HttpError(404, "not_found", `this board uses ${remote}, and answers nothing itself`);
810
824
  const client = clientOf(caller);
811
- if ((method === "post" || method === "posted") && "self" in caller && typeof input.id === "string" && DERIVED_ID.test(input.id)) input = {
825
+ 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
826
  ...input,
813
827
  id: await ownKey(input.id).catch(rethrow)
814
828
  };
@@ -848,6 +862,7 @@ function createHttp(url, options, environment) {
848
862
  ...methods,
849
863
  routes: [],
850
864
  keeps: false,
865
+ settlesMentions: true,
851
866
  async sandbox({ profile, can, token }) {
852
867
  const credential = environment ? await environment.sandbox(remote, token) : token === void 0 ? withoutToken(remote) : { authorization: `Bearer ${token}` };
853
868
  return {
@@ -901,13 +916,17 @@ function http(url, options = {}) {
901
916
  //#region src/backend-vercel/index.ts
902
917
  /** On Vercel, or with its OIDC token pulled (`vercel env pull`): a deployment acts as its project. */
903
918
  const deployed = () => process.env.VERCEL === "1" || !!process.env.VERCEL_OIDC_TOKEN;
919
+ /** Off a deployment, a credential Vercel's API takes, set for board: what a sandbox or CI passes. */
920
+ const boardToken = () => deployed() ? null : process.env.BOARD_TOKEN || null;
904
921
  /**
905
- * A token Vercel's API takes: `VERCEL_TOKEN`, this deployment's OIDC token, or your Vercel login,
906
- * the one the CLI that runs board's hands it (`vercel board`'s) or your `vercel login`.
922
+ * A token Vercel's API takes: this deployment's OIDC token, or else `BOARD_TOKEN`, or your Vercel
923
+ * login, the one the CLI that runs board's hands it (`vercel board`'s, or `VERCEL_AUTH_TOKEN`) or
924
+ * your `vercel login`.
907
925
  */
908
926
  async function token() {
909
- if (process.env.VERCEL_TOKEN) return process.env.VERCEL_TOKEN;
910
927
  if (deployed()) return getVercelOidcToken();
928
+ const set = boardToken();
929
+ if (set) return set;
911
930
  return vercelLogin().catch(() => {
912
931
  throw new HttpError(401, "not_logged_in", "You're not logged in to Vercel.", {
913
932
  hint: "Run vercel login.",
@@ -917,8 +936,8 @@ async function token() {
917
936
  }
918
937
  /** Where `token` comes from, in words: what `vb whoami` says. */
919
938
  function credentialSource() {
920
- if (process.env.VERCEL_TOKEN) return "VERCEL_TOKEN";
921
939
  if (deployed()) return "Vercel OIDC";
940
+ if (boardToken()) return "BOARD_TOKEN";
922
941
  return loginHanded() ? "the Vercel CLI" : "vercel login";
923
942
  }
924
943
  /** The team a CLI that runs board's resolves itself (`vercel board`'s), while one does. */
@@ -942,7 +961,7 @@ async function team() {
942
961
  throw new HttpError(502, "no_team", error instanceof Error ? error.message : String(error), { origin: "handle" });
943
962
  }
944
963
  if (process.env.VERCEL_ORG_ID) return process.env.VERCEL_ORG_ID;
945
- if (!process.env.VERCEL_TOKEN && deployed()) try {
964
+ if (deployed()) try {
946
965
  const owner = decodeJwt(await getVercelOidcToken()).owner_id;
947
966
  if (typeof owner === "string") return owner;
948
967
  } catch {}
@@ -957,7 +976,7 @@ async function team() {
957
976
  const environment = {
958
977
  fetch: () => async (input, init = {}) => {
959
978
  const credential = await token();
960
- if (!process.env.VERCEL_TOKEN && !deployed()) return asYou(input, init, credential);
979
+ if (!deployed() && !boardToken()) return asYou(input, init, credential);
961
980
  const headers = new Headers(init.headers);
962
981
  headers.set("authorization", `Bearer ${credential}`);
963
982
  return globalThis.fetch(input, {
@@ -989,10 +1008,10 @@ function vercel(options = {}) {
989
1008
  function board(options = {}) {
990
1009
  return createBoard(options, {
991
1010
  backend: (fetch) => process.env.BOARD_URL?.trim() ? http() : vercel(fetch ? { fetch } : {}),
992
- sync: () => import("./engine-XVBt02Bl.mjs"),
993
- serving: () => import("./serving-BLVRrJ7P.mjs"),
1011
+ sync: () => import("./engine-j2VeNuKG.mjs"),
1012
+ serving: () => import("./serving-BNdiReQT.mjs"),
994
1013
  sandbox: (url, token) => sandboxHeaders(url, url, token)
995
1014
  });
996
1015
  }
997
1016
  //#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 };
1017
+ 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-BCp4EWTQ.mjs";
2
2
  export { discoveryIdentity, oidcTokens, ownProjectId, ownTeamId };