@eve/board 0.3.0 → 0.5.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.
@@ -4,100 +4,363 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
+ import { BOARD_ID_PATTERN, getCached, isVercelBoardName, listTeamBoards, normalizeBoardName, setCached } from "./client.mjs";
7
8
  import { normalizeBoardRouteBase } from "./route.mjs";
8
9
  const DEFAULT_BOARD_KEY = "default";
9
10
  const DEFAULT_WATCH_CHANNEL = "eve-config/watches";
11
+ const DISCOVERY_TTL_MS = 6e4;
12
+ const WAKE_MISS_WINDOW_MS = 6e4;
13
+ const MAX_WAKE_MISS_REFRESHES = 5;
14
+ const MAX_DIRECTORY_TEAMS = 32;
15
+ const directoryCache = new Map();
16
+ function hasBoardUrlEnv() {
17
+ return Boolean(process.env.BOARD_URL?.trim());
18
+ }
19
+ function normalizedNameKey(name) {
20
+ return normalizeBoardName(name).toLowerCase();
21
+ }
22
+ function directoryKey(team) {
23
+ return JSON.stringify([
24
+ team ?? null,
25
+ process.env.BOARD_TOKEN ?? null,
26
+ process.env.VERCEL_ORG_ID ?? null,
27
+ process.env.VERCEL_AUTH_TOKEN ?? null
28
+ ]);
29
+ }
30
+ function directoryEntry(team) {
31
+ const key = directoryKey(team);
32
+ const existing = getCached(directoryCache, key);
33
+ if (existing !== void 0) return existing;
34
+ const created = {
35
+ fetchedAt: 0,
36
+ wakeRefreshes: []
37
+ };
38
+ setCached(directoryCache, key, created, MAX_DIRECTORY_TEAMS);
39
+ return created;
40
+ }
41
+ async function getDirectory(team, options = {}) {
42
+ const entry = directoryEntry(team);
43
+ const now = Date.now();
44
+ if (options.fresh !== true && entry.listed !== void 0 && now - entry.fetchedAt < DISCOVERY_TTL_MS) return {
45
+ listed: entry.listed,
46
+ refreshed: false
47
+ };
48
+ if (entry.inFlight === void 0) {
49
+ if (options.throttle === true) {
50
+ entry.wakeRefreshes = entry.wakeRefreshes.filter((timestamp) => now - timestamp < WAKE_MISS_WINDOW_MS);
51
+ if (entry.wakeRefreshes.length >= MAX_WAKE_MISS_REFRESHES) return {
52
+ listed: entry.listed,
53
+ refreshed: false
54
+ };
55
+ entry.wakeRefreshes.push(now);
56
+ }
57
+ const request = listTeamBoards(team === void 0 ? void 0 : { team }).then((listed) => {
58
+ entry.listed = listed;
59
+ entry.fetchedAt = Date.now();
60
+ if (entry.inFlight === request) entry.inFlight = void 0;
61
+ return listed;
62
+ }, (error) => {
63
+ if (entry.inFlight === request) entry.inFlight = void 0;
64
+ throw error;
65
+ });
66
+ entry.inFlight = request;
67
+ }
68
+ return {
69
+ listed: await entry.inFlight,
70
+ refreshed: true
71
+ };
72
+ }
73
+ function defaultListedBoard(directory) {
74
+ return directory.defaultBoardId == null ? void 0 : directory.boards.find((board) => board.id === directory.defaultBoardId);
75
+ }
76
+ function findListedBoard(directory, query) {
77
+ if (BOARD_ID_PATTERN.test(query)) return directory.boards.find((board) => board.id === query);
78
+ if (!isVercelBoardName(query)) return void 0;
79
+ const normalized = normalizedNameKey(query);
80
+ const byName = directory.boards.find((board) => normalizedNameKey(board.name) === normalized);
81
+ if (byName !== void 0) return byName;
82
+ return normalized === "general" ? defaultListedBoard(directory) : void 0;
83
+ }
84
+ async function entryListedBoard(entry, fallback, directory, throttle = false) {
85
+ if (entry.url !== void 0) return void 0;
86
+ let own = directory;
87
+ if (own === void 0 || (entry.team ?? null) !== (fallback.team ?? null)) {
88
+ ({listed: own} = await getDirectory(entry.team, { throttle }));
89
+ if (own === void 0) throw Object.assign(new Error(`Couldn't verify the settings for board "${entry.key}". Try again shortly.`), { code: "board_unverified" });
90
+ }
91
+ return findListedBoard(own, entry.id ?? entry.name ?? "");
92
+ }
93
+ async function matchStaticOverride(set, fallback, listed, directory, throttle = false) {
94
+ const entries = [...set.byKey.values()];
95
+ const byId = entries.find((entry) => entry.id === listed.id);
96
+ if (byId !== void 0) return byId;
97
+ const listedName = normalizedNameKey(listed.name);
98
+ const isDefault = listed.id === directory.defaultBoardId;
99
+ for (const entry of entries) {
100
+ if (entry.id !== void 0 || entry.name === void 0) continue;
101
+ const name = normalizedNameKey(entry.name);
102
+ if (name !== listedName && !(isDefault && name === "general")) continue;
103
+ if ((await entryListedBoard(entry, fallback, directory, throttle))?.id === listed.id) return entry;
104
+ }
105
+ }
106
+ function fallbackBoardConfig(set, fallback, id, name) {
107
+ return {
108
+ ...fallback,
109
+ id,
110
+ key: id,
111
+ ...name !== void 0 && { name },
112
+ registrationRouteBase: `${set.routeBase}/${id}`,
113
+ routeBase: set.routeBase,
114
+ shorthand: false
115
+ };
116
+ }
117
+ async function dynamicBoardConfig(set, fallback, listed, directory, throttle = false) {
118
+ const override = await matchStaticOverride(set, fallback, listed, directory, throttle);
119
+ if (override !== void 0) return {
120
+ ...override,
121
+ id: listed.id,
122
+ name: listed.name
123
+ };
124
+ return fallbackBoardConfig(set, fallback, listed.id, listed.name);
125
+ }
126
+ function lookupStaticOrId(set, ref) {
127
+ const direct = set.byKey.get(ref);
128
+ if (direct !== void 0) return direct;
129
+ if (!BOARD_ID_PATTERN.test(ref)) return void 0;
130
+ return [...set.byKey.values()].find((entry) => entry.id === ref);
131
+ }
132
+ async function resolveFromDirectory(set, fallback, pick, throttle = false) {
133
+ let { listed, refreshed } = await getDirectory(fallback.team, { throttle });
134
+ let found = listed === void 0 ? void 0 : pick(listed);
135
+ if (found === void 0 && !refreshed) {
136
+ ({listed} = await getDirectory(fallback.team, {
137
+ fresh: true,
138
+ throttle
139
+ }));
140
+ found = listed === void 0 ? void 0 : pick(listed);
141
+ }
142
+ if (found === void 0 || listed === void 0) return void 0;
143
+ return await dynamicBoardConfig(set, fallback, found, listed, throttle);
144
+ }
145
+ async function enrichMetadata(fallback, board, needsMetadata) {
146
+ if (needsMetadata !== true) return board;
147
+ const match = await entryListedBoard(board, fallback).catch(() => void 0);
148
+ return match === void 0 ? board : {
149
+ ...board,
150
+ id: match.id,
151
+ name: match.name
152
+ };
153
+ }
154
+ function staticBoardSummary(entry, extra) {
155
+ return {
156
+ board: entry.key,
157
+ ...extra?.default !== void 0 && { default: extra.default },
158
+ ...entry.id !== void 0 && { id: entry.id },
159
+ ...entry.name !== void 0 && { name: entry.name },
160
+ ...entry.team !== void 0 && { team: entry.team }
161
+ };
162
+ }
163
+ function singleBoardSet(routeBase, entry) {
164
+ const resolved = {
165
+ ...entry,
166
+ key: DEFAULT_BOARD_KEY,
167
+ registrationRouteBase: routeBase,
168
+ routeBase,
169
+ shorthand: true
170
+ };
171
+ return {
172
+ byKey: new Map([[DEFAULT_BOARD_KEY, resolved]]),
173
+ keys: [DEFAULT_BOARD_KEY],
174
+ routeBase,
175
+ shorthand: true
176
+ };
177
+ }
178
+ function matchesBoard(board, ref) {
179
+ return board.key === ref || board.id === ref;
180
+ }
10
181
  function resolveBoards(settings) {
11
182
  const routeBase = normalizeBoardRouteBase(settings.route);
12
- if (settings.boards === void 0) {
13
- const entry = {
14
- authorize: settings.authorize,
15
- can: settings.can,
16
- key: DEFAULT_BOARD_KEY,
17
- name: settings.name,
18
- profile: settings.profile,
19
- registrationRouteBase: routeBase,
20
- routeBase,
21
- shorthand: true,
22
- team: settings.team,
23
- url: settings.url,
24
- watchChannel: settings.watchChannel ?? "eve-config/watches"
25
- };
26
- return {
27
- byKey: new Map([[DEFAULT_BOARD_KEY, entry]]),
28
- keys: [DEFAULT_BOARD_KEY],
29
- routeBase,
30
- shorthand: true
31
- };
32
- }
183
+ const pinnedByEnv = hasBoardUrlEnv();
184
+ if (settings.boards === void 0 && (settings.id !== void 0 || settings.name !== void 0 || settings.url !== void 0 || pinnedByEnv)) return singleBoardSet(routeBase, {
185
+ authorize: settings.authorize,
186
+ authorizeClaim: settings.authorizeClaim,
187
+ can: settings.can,
188
+ ...settings.id !== void 0 && { id: settings.id },
189
+ ...settings.name !== void 0 && { name: settings.name },
190
+ profile: settings.profile,
191
+ team: settings.team,
192
+ url: settings.url,
193
+ watchChannel: settings.watchChannel ?? "eve-config/watches"
194
+ });
195
+ const rawBoards = settings.boards ?? {};
196
+ const wildcard = rawBoards["*"];
197
+ const wildcardObj = typeof wildcard === "object" && wildcard !== null ? wildcard : void 0;
198
+ const discover = !pinnedByEnv && wildcard !== false;
33
199
  const byKey = new Map();
34
200
  const keys = [];
35
- for (const [key, entry] of Object.entries(settings.boards)) {
201
+ for (const [key, entry] of Object.entries(rawBoards)) {
202
+ if (key === "*" || typeof entry !== "object" || entry === null) continue;
203
+ const keyDerivedName = entry.name === void 0 && entry.id === void 0 && entry.url === void 0;
204
+ const effectiveName = keyDerivedName ? key : entry.name;
36
205
  byKey.set(key, {
37
206
  authorize: entry.authorize ?? settings.authorize,
38
- can: entry.can,
207
+ authorizeClaim: entry.authorizeClaim ?? settings.authorizeClaim,
208
+ can: entry.can ?? settings.can,
209
+ ...keyDerivedName && { ensure: false },
210
+ ...entry.id !== void 0 && { id: entry.id },
39
211
  key,
40
- name: entry.name,
212
+ ...effectiveName !== void 0 && { name: effectiveName },
41
213
  profile: entry.profile ?? settings.profile,
42
214
  registrationRouteBase: `${routeBase}/${key}`,
43
215
  routeBase,
44
216
  shorthand: false,
45
- team: entry.team,
217
+ team: entry.team ?? settings.team,
46
218
  url: entry.url,
47
219
  watchChannel: entry.watchChannel ?? settings.watchChannel ?? "eve-config/watches"
48
220
  });
49
221
  keys.push(key);
50
222
  }
51
- if (keys.length === 0) throw new Error("Board extension `boards` must configure at least one board.");
223
+ const defaults = {
224
+ authorize: wildcardObj?.authorize ?? settings.authorize,
225
+ authorizeClaim: wildcardObj?.authorizeClaim ?? settings.authorizeClaim,
226
+ can: wildcardObj?.can ?? settings.can,
227
+ profile: wildcardObj?.profile ?? settings.profile,
228
+ team: wildcardObj?.team ?? settings.team,
229
+ watchChannel: wildcardObj?.watchChannel ?? settings.watchChannel ?? "eve-config/watches"
230
+ };
231
+ if (!discover && keys.length === 0) {
232
+ if (pinnedByEnv && wildcard !== false) return singleBoardSet(routeBase, defaults);
233
+ throw new Error("Board extension `boards` with `\"*\": false` must configure at least one board.");
234
+ }
235
+ const fallback = discover ? defaults : void 0;
52
236
  return {
53
237
  byKey,
238
+ ...fallback !== void 0 && { fallback },
54
239
  keys,
55
240
  routeBase,
56
241
  shorthand: false
57
242
  };
58
243
  }
59
- function lookupBoard(set, key) {
60
- return set.byKey.get(key);
61
- }
62
- function selectBoard(set, requestedKey, sessionKey) {
244
+ function selectStaticBoard(set, requestedKey, sessionKey) {
63
245
  if (requestedKey !== void 0) {
64
- const found = lookupBoard(set, requestedKey);
246
+ const found = lookupStaticOrId(set, requestedKey);
65
247
  if (found !== void 0) return found;
66
248
  throw new Error(`Unknown board "${requestedKey}". Configured boards: ${set.keys.join(", ")}.`);
67
249
  }
68
250
  if (sessionKey != null && sessionKey.length > 0) {
69
- const found = lookupBoard(set, sessionKey);
251
+ const found = lookupStaticOrId(set, sessionKey);
70
252
  if (found !== void 0) return found;
71
253
  throw new Error(`Board "${sessionKey}" from this session is no longer configured. Configured boards: ${set.keys.join(", ")}.`);
72
254
  }
73
255
  if (set.byKey.size === 1) return set.byKey.values().next().value;
74
256
  throw new Error(`Pass \`board\` to choose which board to use. Configured boards: ${set.keys.join(", ")}.`);
75
257
  }
76
- function resolveSessionBoard(settings, sessionKey) {
258
+ async function selectBoardAsync(settings, requestedKey, sessionKey, options = {}) {
77
259
  const set = resolveBoards(settings);
260
+ const fallback = set.fallback;
261
+ if (fallback === void 0) return selectStaticBoard(set, requestedKey, sessionKey);
262
+ if (requestedKey !== void 0) {
263
+ const staticHit = lookupStaticOrId(set, requestedKey);
264
+ if (staticHit !== void 0) return await enrichMetadata(fallback, staticHit, options.needsMetadata);
265
+ const resolved = BOARD_ID_PATTERN.test(requestedKey) || isVercelBoardName(requestedKey) ? await resolveFromDirectory(set, fallback, (directory) => findListedBoard(directory, requestedKey)) : void 0;
266
+ if (resolved !== void 0) return resolved;
267
+ throw new Error(`Unknown or inaccessible board "${requestedKey}". Call \`boards\` to list boards you can access.`);
268
+ }
78
269
  if (sessionKey != null && sessionKey.length > 0) {
79
- const found = lookupBoard(set, sessionKey);
80
- if (found !== void 0) return found;
81
- throw new Error(`Board "${sessionKey}" from this session is no longer configured. Configured boards: ${set.keys.join(", ")}.`);
270
+ const staticHit = lookupStaticOrId(set, sessionKey);
271
+ if (staticHit !== void 0) return await enrichMetadata(fallback, staticHit, options.needsMetadata);
272
+ if (BOARD_ID_PATTERN.test(sessionKey)) {
273
+ if (options.needsMetadata !== true && options.verify !== true && ![...set.byKey.values()].some((entry) => entry.id === void 0 && entry.url === void 0)) return fallbackBoardConfig(set, fallback, sessionKey);
274
+ const resolved = await resolveFromDirectory(set, fallback, (directory) => directory.boards.find((board) => board.id === sessionKey));
275
+ if (resolved !== void 0) return resolved;
276
+ throw new Error(`Board "${sessionKey}" from this session is no longer accessible.`);
277
+ }
278
+ throw new Error(`Board "${sessionKey}" from this session is no longer configured.`);
82
279
  }
83
- if (set.byKey.size === 1) return set.byKey.values().next().value;
84
- throw new Error(`This board session has no board key, and multiple boards are configured (${set.keys.join(", ")}).`);
280
+ const defaultBoard = await resolveFromDirectory(set, fallback, defaultListedBoard);
281
+ if (defaultBoard !== void 0) return defaultBoard;
282
+ throw new Error("This deployment has no access to the team's default board. Pass `board` (call `boards` to list available boards) or grant access to the default board.");
283
+ }
284
+ async function resolveWakeBoard(settings, boardParam) {
285
+ const set = resolveBoards(settings);
286
+ const fallback = set.fallback;
287
+ if (boardParam === void 0) {
288
+ if (set.shorthand) return set.byKey.values().next().value;
289
+ if (fallback === void 0) return void 0;
290
+ return await resolveFromDirectory(set, fallback, defaultListedBoard, true);
291
+ }
292
+ if (set.shorthand) return void 0;
293
+ const staticHit = set.byKey.get(boardParam);
294
+ if (staticHit !== void 0) return staticHit;
295
+ if (fallback === void 0 || !BOARD_ID_PATTERN.test(boardParam)) return void 0;
296
+ return await resolveFromDirectory(set, fallback, (directory) => directory.boards.find((board) => board.id === boardParam), true);
297
+ }
298
+ async function listAccessibleBoards(settings) {
299
+ const set = resolveBoards(settings);
300
+ if (set.shorthand) {
301
+ const entry = set.byKey.values().next().value;
302
+ return {
303
+ boards: [staticBoardSummary(entry, { default: true })],
304
+ defaultBoardId: entry.id ?? null
305
+ };
306
+ }
307
+ const fallback = set.fallback;
308
+ if (fallback === void 0) return {
309
+ boards: [...set.byKey.values()].map((entry) => staticBoardSummary(entry)),
310
+ defaultBoardId: null
311
+ };
312
+ const { listed } = await getDirectory(fallback.team, { fresh: true });
313
+ const directory = listed;
314
+ const matchedStaticKeys = new Set();
315
+ const boards = await Promise.all(directory.boards.map(async (entry) => {
316
+ const override = await matchStaticOverride(set, fallback, entry, directory);
317
+ if (override !== void 0) matchedStaticKeys.add(override.key);
318
+ const team = override?.team ?? fallback.team;
319
+ return {
320
+ board: override?.key ?? entry.id,
321
+ default: entry.id === directory.defaultBoardId,
322
+ id: entry.id,
323
+ name: entry.name,
324
+ ...team !== void 0 && { team },
325
+ ...entry.visibility !== void 0 && { visibility: entry.visibility }
326
+ };
327
+ }));
328
+ for (const entry of set.byKey.values()) if (!matchedStaticKeys.has(entry.key)) boards.push(staticBoardSummary(entry));
329
+ return {
330
+ boards,
331
+ defaultBoardId: directory.defaultBoardId
332
+ };
85
333
  }
86
334
  function formatConfiguredBoards(settings) {
87
335
  const set = resolveBoards(settings);
88
336
  if (set.shorthand) return null;
89
- const lines = [...set.byKey.values()].map((entry) => {
90
- const label = entry.name ?? "team default board";
337
+ const staticLines = [...set.byKey.values()].map((entry) => {
338
+ const label = entry.name ?? entry.id ?? "team default board";
91
339
  const team = entry.team === void 0 ? "" : ` (team \`${entry.team}\`)`;
92
340
  return `- \`${entry.key}\`: ${label}${team}`;
93
341
  });
94
- const requirement = set.keys.length > 1 ? "Outside a board session, pass `board` with one of the keys above to choose which board to use (except `watches`, which lists every board when `board` is omitted)." : `Pass \`board: "${set.keys[0]}"\` or leave \`board\` out to use it.`;
342
+ if (set.fallback === void 0) {
343
+ const requirement = set.keys.length > 1 ? "Outside a board session, pass `board` with one of the keys above to choose which board to use (except `watches`, which lists every board when `board` is omitted)." : `Pass \`board: "${set.keys[0]}"\` or leave \`board\` out to use it.`;
344
+ return [
345
+ "## Configured boards",
346
+ "",
347
+ ...staticLines,
348
+ "",
349
+ `In a session a board started, replies stay on that board and board tools default to that board. ${requirement}`
350
+ ].join("\n");
351
+ }
95
352
  return [
96
- "## Configured boards",
353
+ "## Boards",
97
354
  "",
98
- ...lines,
355
+ `You can use any accessible board on ${set.fallback.team === void 0 ? "your team" : `team \`${set.fallback.team}\``}. Call \`boards\` to discover available boards.`,
356
+ ...staticLines.length > 0 ? [
357
+ "",
358
+ "Configured boards:",
359
+ "",
360
+ ...staticLines
361
+ ] : [],
99
362
  "",
100
- `In a session a board started, replies stay on that board and board tools default to that board. ${requirement}`
363
+ "In a session a board started, replies stay on that board and board tools default to that board. Outside a board session, omitting `board` uses the team's default board (`General`); pass `board` with a board's name, ID (`brd_…`), or configured key to target another board."
101
364
  ].join("\n");
102
365
  }
103
- export { DEFAULT_BOARD_KEY, DEFAULT_WATCH_CHANNEL, formatConfiguredBoards, lookupBoard, resolveBoards, resolveSessionBoard, selectBoard };
366
+ export { DEFAULT_BOARD_KEY, DEFAULT_WATCH_CHANNEL, formatConfiguredBoards, listAccessibleBoards, matchesBoard, resolveBoards, resolveWakeBoard, selectBoardAsync };
@@ -8,5 +8,5 @@ import { type BoardChannel, type BoardChannelConfig } from "./board-channel.ts";
8
8
  * thread the board syncs. Watches are created with the `watch` tool, never by the channel.
9
9
  */
10
10
  export declare function boardChannel(config?: BoardChannelConfig): BoardChannel;
11
- export type { BoardAuthorize, BoardAuthorizeAction, BoardAuthorizeRequest } from "./authorize.ts";
11
+ export type { BoardAuthorize, BoardAuthorizeAction, BoardAuthorizeRequest, BoardClaimAuthorize, BoardClaimAuthorizeAction, BoardClaimAuthorizeRequest, } from "./authorize.ts";
12
12
  export type { BoardChannel, BoardChannelConfig, BoardChannelMetadata, BoardChannelState, BoardReceiveTarget, } from "./board-channel.ts";
@@ -25,7 +25,7 @@ export declare function settlementOf(output: unknown, taskId: string, capability
25
25
  readonly kind: string;
26
26
  readonly name: string;
27
27
  }): BoardSettlement | undefined;
28
- export declare function renewClaimDuringCall(client: () => BoardClient, claim: BoardClaim | null, callId: string): void;
28
+ export declare function renewClaimDuringCall(client: () => BoardClient | Promise<BoardClient>, claim: BoardClaim | null, callId: string): void;
29
29
  export declare function stopClaimRenewal(token: string): void;
30
30
  export declare function endClaimRenewal(slot: ClaimSlot, callId?: string): void;
31
31
  export declare function keepClaimInSlot(client: BoardClient, slot: ClaimSlot): Promise<void>;
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { resolveSessionBoard } from "./boards.mjs";
7
+ import { selectBoardAsync } from "./boards.mjs";
8
8
  import { boardErrorCode } from "./client.mjs";
9
9
  import { boardClients } from "./watches.mjs";
10
10
  import { createLogger } from "eve/internal/channels";
@@ -85,8 +85,9 @@ function renewClaimDuringCall(client, claim, callId) {
85
85
  try {
86
86
  let resolved;
87
87
  try {
88
- resolved = client();
88
+ resolved = await client();
89
89
  } catch (error) {
90
+ if (boardErrorCode(error) !== void 0) return;
90
91
  log.warn("board task claim's board is no longer configured; dropping renewal", {
91
92
  error,
92
93
  task: renewal.claim.taskId
@@ -170,10 +171,17 @@ function sessionSlot() {
170
171
  };
171
172
  }
172
173
  function createBoardClaimsHook(settings) {
173
- const resolveClient = (boardKey) => {
174
+ const resolveClient = async (boardKey) => {
174
175
  try {
175
- return boardClients(resolveSessionBoard(settings(), boardKey)).deployment;
176
+ return boardClients(await selectBoardAsync(settings(), void 0, boardKey)).deployment;
176
177
  } catch (error) {
178
+ if (boardErrorCode(error) !== void 0) {
179
+ log.warn("couldn't resolve the held task's board; keeping the claim", {
180
+ board: boardKey,
181
+ error
182
+ });
183
+ return null;
184
+ }
177
185
  log.warn("board task claim's board is no longer configured; clearing the session claim", {
178
186
  board: boardKey,
179
187
  error
@@ -186,13 +194,13 @@ function createBoardClaimsHook(settings) {
186
194
  async "turn.started"() {
187
195
  const held = readSessionClaim();
188
196
  if (held === null) return;
189
- const client = resolveClient(held.board);
197
+ const client = await resolveClient(held.board);
190
198
  if (client !== null) await keepClaimInSlot(client, sessionSlot());
191
199
  },
192
200
  async "call.requested"() {
193
201
  const held = readSessionClaim();
194
202
  if (held === null) return;
195
- const client = resolveClient(held.board);
203
+ const client = await resolveClient(held.board);
196
204
  if (client !== null) await keepClaimInSlot(client, sessionSlot());
197
205
  },
198
206
  async "call.started"(event) {
@@ -200,10 +208,10 @@ function createBoardClaimsHook(settings) {
200
208
  if (held === null) return;
201
209
  const boardKey = held.board;
202
210
  if (event.data.taskId === void 0) {
203
- if (resolveClient(boardKey) === null) return;
204
- renewClaimDuringCall(() => boardClients(resolveSessionBoard(settings(), boardKey)).deployment, held.claim, event.data.callId);
211
+ if (await resolveClient(boardKey) === null) return;
212
+ renewClaimDuringCall(async () => boardClients(await selectBoardAsync(settings(), void 0, boardKey)).deployment, held.claim, event.data.callId);
205
213
  } else {
206
- const client = resolveClient(boardKey);
214
+ const client = await resolveClient(boardKey);
207
215
  if (client !== null) await renewClaimBeforeTask(client, sessionSlot());
208
216
  }
209
217
  },
@@ -211,7 +219,7 @@ function createBoardClaimsHook(settings) {
211
219
  endClaimRenewal(sessionSlot(), event.data.callId);
212
220
  const held = readSessionClaim();
213
221
  if (held === null) return;
214
- const client = resolveClient(held.board);
222
+ const client = await resolveClient(held.board);
215
223
  if (client !== null) await keepClaimInSlot(client, sessionSlot());
216
224
  },
217
225
  "turn.settled"() {
@@ -192,6 +192,16 @@ export interface BoardDiscovery {
192
192
  readonly url: string;
193
193
  readonly wake_by_path?: boolean;
194
194
  }
195
+ export interface ListedBoard {
196
+ readonly id: string;
197
+ readonly name: string;
198
+ readonly teamId?: string;
199
+ readonly visibility?: "team" | "private";
200
+ }
201
+ export interface ListedBoardsResult {
202
+ readonly boards: readonly ListedBoard[];
203
+ readonly defaultBoardId: string | null;
204
+ }
195
205
  export type BoardCan = "all" | readonly BoardPermission[] | Readonly<Record<string, "all" | readonly BoardPermission[]>>;
196
206
  export declare const BOARD_PERMISSIONS: readonly ["read", "post", "react", "label", "sync", "manage"];
197
207
  export type BoardPermission = (typeof BOARD_PERMISSIONS)[number];
@@ -214,6 +224,7 @@ export interface BoardClient {
214
224
  }): Promise<void>;
215
225
  post(channel: string, options: BoardPostOptions): Promise<BoardWrittenMessage>;
216
226
  reply(id: string, options: BoardPostOptions): Promise<BoardWrittenMessage>;
227
+ edit(id: string, text: string): Promise<void>;
217
228
  upload(file: {
218
229
  readonly data: Uint8Array;
219
230
  readonly name: string;
@@ -264,14 +275,24 @@ export declare const BOARD_TEXT_LIMIT = 10000;
264
275
  export declare const BOARD_TAIL_LIMIT = 1000;
265
276
  export declare const BOARD_UPLOAD_LIMIT: number;
266
277
  export declare const BOARD_NAME_PATTERN: RegExp;
278
+ export declare const BOARD_ID_PATTERN: RegExp;
267
279
  export declare const BOARD_CHANNEL_SELECTOR: RegExp;
268
280
  export declare const BOARD_TASK_NOTE_LIMIT = 1000;
269
281
  export declare const BOARD_HOLD_KIND_PATTERN: RegExp;
270
282
  export declare const DEFAULT_BOARD_PROFILE = "eve";
283
+ export declare function normalizeBoardName(name: string): string;
284
+ export declare function isVercelBoardName(name: string): boolean;
285
+ export declare function listTeamBoards(options?: {
286
+ readonly team?: string;
287
+ }): Promise<ListedBoardsResult>;
271
288
  export declare function boardPostId(key: string): string;
272
289
  export declare function boardAllows(can: BoardCan | undefined, channel: string, permission: string): boolean;
273
290
  export declare function boardErrorCode(error: unknown): string | undefined;
274
- type BoardRef = Pick<BoardSettings, "name" | "team" | "url" | "profile">;
291
+ export declare function getCached<T>(cache: Map<string, T>, key: string): T | undefined;
292
+ export declare function setCached<T>(cache: Map<string, T>, key: string, value: T, max?: number): void;
293
+ type BoardRef = Pick<BoardSettings, "id" | "name" | "team" | "url" | "profile"> & {
294
+ readonly ensure?: boolean;
295
+ };
275
296
  export declare function createBoardClient(board: BoardRef, can?: BoardCan): BoardClient;
276
297
  export declare function withHints<T extends object>(target: T): T;
277
298
  export {};