@eve/board 0.2.1 → 0.4.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 (44) hide show
  1. package/dist/extension/_manifest.json +1 -1
  2. package/dist/extension/extension.d.ts +8 -5
  3. package/dist/extension/extension.mjs +48 -37
  4. package/dist/extension/hooks/claims.d.ts +2 -0
  5. package/dist/extension/hooks/claims.mjs +11 -0
  6. package/dist/extension/instructions.md +2 -2
  7. package/dist/extension/lib/authorize.d.ts +9 -6
  8. package/dist/extension/lib/board-channel.d.ts +7 -18
  9. package/dist/extension/lib/board-channel.mjs +59 -141
  10. package/dist/extension/lib/boards.d.ts +29 -4
  11. package/dist/extension/lib/boards.mjs +310 -45
  12. package/dist/extension/lib/claims.d.ts +38 -0
  13. package/dist/extension/lib/claims.mjs +239 -0
  14. package/dist/extension/lib/client.d.ts +41 -1
  15. package/dist/extension/lib/client.mjs +89 -12
  16. package/dist/extension/lib/inbound.d.ts +1 -1
  17. package/dist/extension/lib/inbound.mjs +1 -1
  18. package/dist/extension/lib/tools.d.ts +206 -9
  19. package/dist/extension/lib/tools.mjs +310 -52
  20. package/dist/extension/lib/watches.d.ts +3 -1
  21. package/dist/extension/lib/watches.mjs +1 -1
  22. package/dist/extension/skills/collaborate/SKILL.md +9 -6
  23. package/dist/extension/tools/block_task.d.ts +1 -1
  24. package/dist/extension/tools/block_task.mjs +2 -1
  25. package/dist/extension/tools/boards.d.ts +6 -0
  26. package/dist/extension/tools/boards.mjs +10 -0
  27. package/dist/extension/tools/claim_task.d.ts +70 -0
  28. package/dist/extension/tools/claim_task.mjs +10 -0
  29. package/dist/extension/tools/complete_task.d.ts +1 -1
  30. package/dist/extension/tools/complete_task.mjs +2 -1
  31. package/dist/extension/tools/create_task.d.ts +5 -0
  32. package/dist/extension/tools/fail_task.d.ts +1 -1
  33. package/dist/extension/tools/fail_task.mjs +2 -1
  34. package/dist/extension/tools/note.d.ts +5 -0
  35. package/dist/extension/tools/post.d.ts +10 -0
  36. package/dist/extension/tools/read.d.ts +40 -0
  37. package/dist/extension/tools/release_task.d.ts +3 -0
  38. package/dist/extension/tools/release_task.mjs +11 -0
  39. package/dist/extension/tools/reply.d.ts +10 -0
  40. package/dist/extension/tools/tasks.d.ts +40 -0
  41. package/dist/extension/tools/tasks.mjs +10 -0
  42. package/dist/tools/index.d.ts +4 -0
  43. package/dist/tools/index.mjs +5 -1
  44. package/package.json +4 -4
@@ -0,0 +1,239 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ import { selectBoardAsync } from "./boards.mjs";
8
+ import { boardErrorCode } from "./client.mjs";
9
+ import { boardClients } from "./watches.mjs";
10
+ import { createLogger } from "eve/internal/channels";
11
+ import { defineState } from "eve/context";
12
+ const log = createLogger("board.claims");
13
+ const CLAIM_LEASE_SECONDS = 3600;
14
+ const CLAIM_WATCH_LABEL = "eve-claim-watch";
15
+ const RENEW_EVERY_MS = 3e4;
16
+ const RECENT_RENEWAL_MS = 6e4;
17
+ const SETTLE_ATTEMPTS = 3;
18
+ const SETTLE_BACKOFF_MS = 500;
19
+ const SETTLEMENTS = new Set([
20
+ "completed",
21
+ "failed",
22
+ "blocked"
23
+ ]);
24
+ const SETTLE_TOOL = /^(?:.+__)?(?:complete|fail|block)_task$/u;
25
+ const sessionClaimState = defineState("board.claim", () => null);
26
+ function readSessionClaim() {
27
+ return sessionClaimState.get();
28
+ }
29
+ function writeSessionClaim(claim) {
30
+ sessionClaimState.update(() => claim);
31
+ }
32
+ function clearSessionClaim() {
33
+ const existing = sessionClaimState.get();
34
+ if (existing !== null) stopClaimRenewal(existing.claim.token);
35
+ sessionClaimState.update(() => null);
36
+ }
37
+ function settlementOf(output, taskId, capability) {
38
+ if (capability.kind !== "tool" || !SETTLE_TOOL.test(capability.name)) return void 0;
39
+ if (typeof output !== "object" || output === null) return void 0;
40
+ const settlement = output;
41
+ if (settlement.task !== taskId || !SETTLEMENTS.has(settlement.settled ?? "")) return void 0;
42
+ return settlement;
43
+ }
44
+ function temporaryBoardFailure(error) {
45
+ const status = error?.status;
46
+ return typeof status !== "number" || status === 429 || status >= 500;
47
+ }
48
+ function claimDue(claim, now = Date.now()) {
49
+ return Date.parse(claim.until) - now < CLAIM_LEASE_SECONDS * 1e3 / 3;
50
+ }
51
+ function renewedRecently(claim, now = Date.now()) {
52
+ return Date.parse(claim.until) - now > CLAIM_LEASE_SECONDS * 1e3 - RECENT_RENEWAL_MS;
53
+ }
54
+ async function renewClaim(client, claim) {
55
+ try {
56
+ return {
57
+ ...claim,
58
+ until: await client.held(claim).renew(CLAIM_LEASE_SECONDS)
59
+ };
60
+ } catch (error) {
61
+ if (boardErrorCode(error) === "claim_lost") {
62
+ log.warn("board task claim was lost; the agent no longer holds the task", { task: claim.taskId });
63
+ return null;
64
+ }
65
+ logError("board task renewal failed", error, { task: claim.taskId });
66
+ return claim;
67
+ }
68
+ }
69
+ const renewals = new Map();
70
+ function renewClaimDuringCall(client, claim, callId) {
71
+ if (claim == null) return;
72
+ const running = renewals.get(claim.token);
73
+ if (running !== void 0) {
74
+ running.calls.add(callId);
75
+ return;
76
+ }
77
+ const renewal = {
78
+ calls: new Set([callId]),
79
+ claim,
80
+ renewing: false
81
+ };
82
+ renewal.timer = setInterval(async () => {
83
+ if (renewal.renewing || renewal.claim === null || !claimDue(renewal.claim)) return;
84
+ renewal.renewing = true;
85
+ try {
86
+ let resolved;
87
+ try {
88
+ resolved = await client();
89
+ } catch (error) {
90
+ if (boardErrorCode(error) !== void 0) return;
91
+ log.warn("board task claim's board is no longer configured; dropping renewal", {
92
+ error,
93
+ task: renewal.claim.taskId
94
+ });
95
+ renewal.claim = null;
96
+ return;
97
+ }
98
+ renewal.claim = await renewClaim(resolved, renewal.claim);
99
+ } finally {
100
+ renewal.renewing = false;
101
+ }
102
+ if (renewal.claim === null) clearInterval(renewal.timer);
103
+ }, RENEW_EVERY_MS);
104
+ renewal.timer.unref?.();
105
+ renewals.set(claim.token, renewal);
106
+ }
107
+ function stopClaimRenewal(token) {
108
+ clearInterval(renewals.get(token)?.timer);
109
+ renewals.delete(token);
110
+ }
111
+ function endClaimRenewal(slot, callId) {
112
+ const token = slot.get()?.token;
113
+ const renewal = token === void 0 ? void 0 : renewals.get(token);
114
+ if (token === void 0 || renewal === void 0) return;
115
+ if (callId !== void 0) renewal.calls.delete(callId);
116
+ slot.set(renewal.claim);
117
+ if (callId === void 0 || renewal.calls.size === 0 || renewal.claim === null) stopClaimRenewal(token);
118
+ }
119
+ async function keepClaimInSlot(client, slot) {
120
+ const claim = slot.get();
121
+ if (claim != null && claimDue(claim)) await renewSlot(client, slot);
122
+ }
123
+ async function renewClaimBeforeTask(client, slot) {
124
+ const claim = slot.get();
125
+ if (claim != null && !renewedRecently(claim)) await renewSlot(client, slot);
126
+ }
127
+ async function renewSlot(client, slot) {
128
+ const claim = slot.get();
129
+ if (claim == null) return;
130
+ const renewed = await renewClaim(client, claim);
131
+ slot.set(renewed);
132
+ if (renewed === null) stopClaimRenewal(claim.token);
133
+ }
134
+ async function settleClaim(client, claim, settlement) {
135
+ const held = client.held(claim);
136
+ const verb = settlement.settled === "released" ? `release task #${claim.taskId}` : `mark task #${claim.taskId} ${settlement.settled}`;
137
+ for (let attempt = 1;; attempt += 1) try {
138
+ if (settlement.settled === "completed") await held.complete(settlement.result);
139
+ else if (settlement.settled === "failed") await held.fail(settlement.reason ?? "Failed.");
140
+ else if (settlement.settled === "released") await held.release();
141
+ else await held.block(settlement.reason ?? "Needs a person.", { kind: settlement.kind });
142
+ return {};
143
+ } catch (error) {
144
+ if (boardErrorCode(error) === "claim_lost") return {
145
+ claimLost: true,
146
+ problem: `eve couldn't ${verb}: its claim ended before the agent settled it.`
147
+ };
148
+ const id = logError("board task settlement failed", error, {
149
+ attempt,
150
+ task: claim.taskId
151
+ });
152
+ if (temporaryBoardFailure(error) && attempt < SETTLE_ATTEMPTS) {
153
+ await new Promise((resolve) => setTimeout(resolve, attempt * SETTLE_BACKOFF_MS));
154
+ continue;
155
+ }
156
+ return {
157
+ errorId: id,
158
+ problem: `eve couldn't ${verb} on the board (error id ${id}). Its claim runs out within the hour, and the task goes back to the queue.`
159
+ };
160
+ }
161
+ }
162
+ function sessionSlot() {
163
+ return {
164
+ get: () => sessionClaimState.get()?.claim ?? null,
165
+ set: (claim) => {
166
+ sessionClaimState.update((current) => current === null || claim === null ? null : {
167
+ ...current,
168
+ claim
169
+ });
170
+ }
171
+ };
172
+ }
173
+ function createBoardClaimsHook(settings) {
174
+ const resolveClient = async (boardKey) => {
175
+ try {
176
+ return boardClients(await selectBoardAsync(settings(), void 0, boardKey)).deployment;
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
+ }
185
+ log.warn("board task claim's board is no longer configured; clearing the session claim", {
186
+ board: boardKey,
187
+ error
188
+ });
189
+ clearSessionClaim();
190
+ return null;
191
+ }
192
+ };
193
+ return { events: {
194
+ async "turn.started"() {
195
+ const held = readSessionClaim();
196
+ if (held === null) return;
197
+ const client = await resolveClient(held.board);
198
+ if (client !== null) await keepClaimInSlot(client, sessionSlot());
199
+ },
200
+ async "call.requested"() {
201
+ const held = readSessionClaim();
202
+ if (held === null) return;
203
+ const client = await resolveClient(held.board);
204
+ if (client !== null) await keepClaimInSlot(client, sessionSlot());
205
+ },
206
+ async "call.started"(event) {
207
+ const held = readSessionClaim();
208
+ if (held === null) return;
209
+ const boardKey = held.board;
210
+ if (event.data.taskId === void 0) {
211
+ if (await resolveClient(boardKey) === null) return;
212
+ renewClaimDuringCall(async () => boardClients(await selectBoardAsync(settings(), void 0, boardKey)).deployment, held.claim, event.data.callId);
213
+ } else {
214
+ const client = await resolveClient(boardKey);
215
+ if (client !== null) await renewClaimBeforeTask(client, sessionSlot());
216
+ }
217
+ },
218
+ async "call.settled"(event) {
219
+ endClaimRenewal(sessionSlot(), event.data.callId);
220
+ const held = readSessionClaim();
221
+ if (held === null) return;
222
+ const client = await resolveClient(held.board);
223
+ if (client !== null) await keepClaimInSlot(client, sessionSlot());
224
+ },
225
+ "turn.settled"() {
226
+ endClaimRenewal(sessionSlot());
227
+ }
228
+ } };
229
+ }
230
+ function logError(message, error, fields = {}) {
231
+ const errorId = crypto.randomUUID();
232
+ log.error(message, {
233
+ ...fields,
234
+ error,
235
+ errorId
236
+ });
237
+ return errorId;
238
+ }
239
+ export { CLAIM_LEASE_SECONDS, CLAIM_WATCH_LABEL, clearSessionClaim, createBoardClaimsHook, endClaimRenewal, keepClaimInSlot, readSessionClaim, renewClaimBeforeTask, renewClaimDuringCall, settleClaim, settlementOf, stopClaimRenewal, writeSessionClaim };
@@ -18,6 +18,8 @@ export interface BoardAttachment {
18
18
  export interface BoardTaskState {
19
19
  readonly state: string;
20
20
  readonly owner: string;
21
+ readonly for: string | null;
22
+ readonly needs: readonly string[];
21
23
  readonly claim: {
22
24
  readonly actor: string;
23
25
  readonly until: string;
@@ -133,6 +135,22 @@ export interface BoardReadyTaskQuery {
133
135
  readonly from?: readonly string[];
134
136
  readonly lease?: number;
135
137
  }
138
+ export declare const BOARD_TASK_STATES: readonly ["waiting", "ready", "claimed", "blocked", "completed", "failed", "canceled"];
139
+ export type BoardTaskStateName = (typeof BOARD_TASK_STATES)[number];
140
+ export interface BoardTasksQuery {
141
+ readonly channel?: string;
142
+ readonly state?: "open" | "all" | BoardTaskStateName;
143
+ readonly label?: readonly string[];
144
+ readonly owner?: string;
145
+ readonly for?: string;
146
+ readonly needs?: string;
147
+ readonly after?: string;
148
+ readonly limit?: number;
149
+ }
150
+ export interface BoardTasksPage {
151
+ readonly tasks: readonly BoardThreadSummary[];
152
+ readonly cursor: string;
153
+ }
136
154
  export interface BoardNewTask {
137
155
  readonly text: string;
138
156
  readonly labels?: Readonly<Record<string, string>>;
@@ -174,6 +192,16 @@ export interface BoardDiscovery {
174
192
  readonly url: string;
175
193
  readonly wake_by_path?: boolean;
176
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
+ }
177
205
  export type BoardCan = "all" | readonly BoardPermission[] | Readonly<Record<string, "all" | readonly BoardPermission[]>>;
178
206
  export declare const BOARD_PERMISSIONS: readonly ["read", "post", "react", "label", "sync", "manage"];
179
207
  export type BoardPermission = (typeof BOARD_PERMISSIONS)[number];
@@ -212,6 +240,7 @@ export interface BoardClient {
212
240
  typing(id: string, status?: string): Promise<void>;
213
241
  thread(id: string, range?: {
214
242
  readonly after?: string;
243
+ readonly limit?: number;
215
244
  }): Promise<BoardThread>;
216
245
  posted(id: string): Promise<BoardMessage>;
217
246
  linked(url: string): Promise<BoardThread>;
@@ -233,6 +262,7 @@ export interface BoardClient {
233
262
  cancelSchedule(id: string): Promise<{
234
263
  readonly canceled: boolean;
235
264
  }>;
265
+ tasks(query?: BoardTasksQuery): Promise<BoardTasksPage>;
236
266
  claimReady(query: BoardReadyTaskQuery): Promise<BoardClaimedTask | null>;
237
267
  claim(taskId: string, lease?: number): Promise<BoardClaimedTask>;
238
268
  held(claim: BoardClaim): BoardHeldTask;
@@ -244,14 +274,24 @@ export declare const BOARD_TEXT_LIMIT = 10000;
244
274
  export declare const BOARD_TAIL_LIMIT = 1000;
245
275
  export declare const BOARD_UPLOAD_LIMIT: number;
246
276
  export declare const BOARD_NAME_PATTERN: RegExp;
277
+ export declare const BOARD_ID_PATTERN: RegExp;
247
278
  export declare const BOARD_CHANNEL_SELECTOR: RegExp;
248
279
  export declare const BOARD_TASK_NOTE_LIMIT = 1000;
249
280
  export declare const BOARD_HOLD_KIND_PATTERN: RegExp;
250
281
  export declare const DEFAULT_BOARD_PROFILE = "eve";
282
+ export declare function normalizeBoardName(name: string): string;
283
+ export declare function isVercelBoardName(name: string): boolean;
284
+ export declare function listTeamBoards(options?: {
285
+ readonly team?: string;
286
+ }): Promise<ListedBoardsResult>;
251
287
  export declare function boardPostId(key: string): string;
252
288
  export declare function boardAllows(can: BoardCan | undefined, channel: string, permission: string): boolean;
253
289
  export declare function boardErrorCode(error: unknown): string | undefined;
254
- type BoardRef = Pick<BoardSettings, "name" | "team" | "url" | "profile">;
290
+ export declare function getCached<T>(cache: Map<string, T>, key: string): T | undefined;
291
+ export declare function setCached<T>(cache: Map<string, T>, key: string, value: T, max?: number): void;
292
+ type BoardRef = Pick<BoardSettings, "id" | "name" | "team" | "url" | "profile"> & {
293
+ readonly ensure?: boolean;
294
+ };
255
295
  export declare function createBoardClient(board: BoardRef, can?: BoardCan): BoardClient;
256
296
  export declare function withHints<T extends object>(target: T): T;
257
297
  export {};
@@ -5,8 +5,17 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { createHash } from "node:crypto";
8
- import { board } from "@vercel/board";
8
+ import { board, listBoards } from "@vercel/board";
9
9
  import { compileAccess } from "@vercel/board/access";
10
+ const BOARD_TASK_STATES = [
11
+ "waiting",
12
+ "ready",
13
+ "claimed",
14
+ "blocked",
15
+ "completed",
16
+ "failed",
17
+ "canceled"
18
+ ];
10
19
  const BOARD_PERMISSIONS = [
11
20
  "read",
12
21
  "post",
@@ -19,10 +28,34 @@ const BOARD_TEXT_LIMIT = 1e4;
19
28
  const BOARD_TAIL_LIMIT = 1e3;
20
29
  const BOARD_UPLOAD_LIMIT = 4194304;
21
30
  const BOARD_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9-]{0,31}$/u;
31
+ const BOARD_ID_PATTERN = /^brd_[^\s/]+$/u;
32
+ const VERCEL_BOARD_NAME_PATTERN = /^[^/]{1,64}$/u;
22
33
  const BOARD_CHANNEL_SELECTOR = /^[a-z0-9][a-z0-9_-]*(?:\/[a-z0-9][a-z0-9_-]*)*\/?$/u;
23
34
  const BOARD_TASK_NOTE_LIMIT = 1e3;
24
35
  const BOARD_HOLD_KIND_PATTERN = /^[a-z0-9][a-z0-9_.-]{0,63}$/u;
25
36
  const DEFAULT_BOARD_PROFILE = "eve";
37
+ function normalizeBoardName(name) {
38
+ return name.trim().normalize("NFC");
39
+ }
40
+ function isVercelBoardName(name) {
41
+ return VERCEL_BOARD_NAME_PATTERN.test(normalizeBoardName(name));
42
+ }
43
+ async function listTeamBoards(options) {
44
+ try {
45
+ const listed = await listBoards(options?.team === void 0 ? {} : { team: options.team });
46
+ return {
47
+ boards: listed.boards.map((entry) => ({
48
+ id: entry.id,
49
+ name: entry.name,
50
+ ...entry.teamId !== void 0 && { teamId: entry.teamId },
51
+ ...entry.visibility !== void 0 && { visibility: entry.visibility }
52
+ })),
53
+ defaultBoardId: listed.defaultBoardId
54
+ };
55
+ } catch (error) {
56
+ throw hinted(error);
57
+ }
58
+ }
26
59
  function boardPostId(key) {
27
60
  return `eve-${createHash("sha256").update(key).digest("hex").slice(0, 32)}`;
28
61
  }
@@ -37,20 +70,45 @@ function boardErrorCode(error) {
37
70
  const code = error.code;
38
71
  return typeof code === "string" ? code : void 0;
39
72
  }
73
+ const MAX_CACHED_HANDLES = 256;
40
74
  const handles = new Map();
41
75
  const principals = new Map();
42
- function handleKey({ name, team, url }) {
76
+ function getCached(cache, key) {
77
+ const value = cache.get(key);
78
+ if (value === void 0) return void 0;
79
+ cache.delete(key);
80
+ cache.set(key, value);
81
+ return value;
82
+ }
83
+ function setCached(cache, key, value, max = MAX_CACHED_HANDLES) {
84
+ cache.delete(key);
85
+ cache.set(key, value);
86
+ if (cache.size > max) {
87
+ const oldest = cache.keys().next().value;
88
+ if (oldest !== void 0) cache.delete(oldest);
89
+ }
90
+ }
91
+ function handleKey({ ensure, id, name, team, url }) {
43
92
  return JSON.stringify([
44
- name ?? null,
93
+ id ?? null,
94
+ id !== void 0 ? null : name ?? null,
95
+ id !== void 0 ? null : ensure ?? null,
45
96
  team ?? null,
46
97
  url?.trim().replace(/\/+$/u, "") || process.env.BOARD_URL?.trim().replace(/\/+$/u, "") || null,
47
- process.env.BOARD_TOKEN ?? null
98
+ process.env.BOARD_TOKEN ?? null,
99
+ process.env.VERCEL_ORG_ID ?? null,
100
+ process.env.VERCEL_AUTH_TOKEN ?? null
48
101
  ]);
49
102
  }
50
103
  function createBoardHandle(board$1) {
51
- const { name, team, url } = board$1;
52
- const options = {
104
+ const { ensure, id, name, team, url } = board$1;
105
+ if (id !== void 0 && url === void 0 && Boolean(process.env.BOARD_URL?.trim())) throw new Error(`Cannot target board "${id}" by ID while BOARD_URL is set; unset BOARD_URL to reach Vercel Board by ID.`);
106
+ const options = id !== void 0 ? {
107
+ id,
108
+ ...team !== void 0 && { team }
109
+ } : {
53
110
  ...name !== void 0 && { name },
111
+ ...name !== void 0 && ensure !== void 0 && { ensure },
54
112
  ...team !== void 0 && { team }
55
113
  };
56
114
  if (url === void 0) return board(options);
@@ -67,10 +125,10 @@ function createBoardClient(board, can) {
67
125
  const profile = (board.profile ?? "eve").toLowerCase();
68
126
  if (!BOARD_NAME_PATTERN.test(profile)) throw new Error(`Board profile "${board.profile}" is invalid: use a letter, then up to 31 letters, numbers, or hyphens.`);
69
127
  const key = handleKey(board);
70
- let base = handles.get(key);
128
+ let base = getCached(handles, key);
71
129
  if (base === void 0) {
72
130
  base = createBoardHandle(board);
73
- handles.set(key, base);
131
+ setCached(handles, key, base);
74
132
  }
75
133
  const handle = withHints(base.as(profile, can === void 0 ? void 0 : { can }));
76
134
  const meKey = `${key}\n${profile}`;
@@ -107,7 +165,7 @@ function createBoardClient(board, can) {
107
165
  profile,
108
166
  discovery: async () => await handle.discovery(),
109
167
  me: () => {
110
- let me = principals.get(meKey);
168
+ let me = getCached(principals, meKey);
111
169
  if (me === void 0) {
112
170
  me = handle.me().then(({ actor, principal }) => ({
113
171
  actor,
@@ -116,7 +174,7 @@ function createBoardClient(board, can) {
116
174
  principals.delete(meKey);
117
175
  throw error;
118
176
  });
119
- principals.set(meKey, me);
177
+ setCached(principals, meKey, me);
120
178
  }
121
179
  return me;
122
180
  },
@@ -168,7 +226,10 @@ function createBoardClient(board, can) {
168
226
  async typing(id, status) {
169
227
  await handle.typing(id, status === void 0 ? void 0 : status.slice(0, 50));
170
228
  },
171
- thread: async (id, range = {}) => threadOf(await handle.thread(id, range.after === void 0 ? {} : { after: range.after })),
229
+ thread: async (id, range = {}) => threadOf(await handle.thread(id, {
230
+ ...range.after !== void 0 && { after: range.after },
231
+ ...range.limit !== void 0 && { limit: range.limit }
232
+ })),
172
233
  posted: async (id) => messageOf(await handle.posted(id)),
173
234
  linked: async (url) => threadOf(await handle.linked(url)),
174
235
  async threads(query = {}) {
@@ -203,6 +264,20 @@ function createBoardClient(board, can) {
203
264
  const { canceled } = await handle.cancelSchedule(id);
204
265
  return { canceled };
205
266
  },
267
+ async tasks(query = {}) {
268
+ const page = await handle.tasks.list({
269
+ ...query,
270
+ ...query.label !== void 0 && { label: [...query.label] }
271
+ });
272
+ return {
273
+ cursor: page.cursor,
274
+ tasks: page.tasks.map((summary) => ({
275
+ last: summary.last === null ? null : messageOf(summary.last),
276
+ message: messageOf(summary.message),
277
+ replies: summary.replies
278
+ }))
279
+ };
280
+ },
206
281
  async claimReady(query) {
207
282
  const claim = await handle.tasks.claim({
208
283
  channel: query.channel,
@@ -303,6 +378,8 @@ function messageOf(view) {
303
378
  actor: task.claim.actor,
304
379
  until: task.claim.until
305
380
  },
381
+ for: task.for,
382
+ needs: [...task.needs],
306
383
  owner: task.owner,
307
384
  reason: task.reason,
308
385
  result: task.result,
@@ -361,4 +438,4 @@ function scheduleOf(schedule) {
361
438
  text: schedule.text
362
439
  };
363
440
  }
364
- export { BOARD_CHANNEL_SELECTOR, BOARD_HOLD_KIND_PATTERN, BOARD_NAME_PATTERN, BOARD_PERMISSIONS, BOARD_TAIL_LIMIT, BOARD_TASK_NOTE_LIMIT, BOARD_TEXT_LIMIT, BOARD_UPLOAD_LIMIT, DEFAULT_BOARD_PROFILE, boardAllows, boardErrorCode, boardPostId, createBoardClient, withHints };
441
+ export { BOARD_CHANNEL_SELECTOR, BOARD_HOLD_KIND_PATTERN, BOARD_ID_PATTERN, BOARD_NAME_PATTERN, BOARD_PERMISSIONS, BOARD_TAIL_LIMIT, BOARD_TASK_NOTE_LIMIT, BOARD_TASK_STATES, BOARD_TEXT_LIMIT, BOARD_UPLOAD_LIMIT, DEFAULT_BOARD_PROFILE, boardAllows, boardErrorCode, boardPostId, createBoardClient, getCached, isVercelBoardName, listTeamBoards, normalizeBoardName, setCached, withHints };
@@ -18,4 +18,4 @@ export declare function formatBoardContext(message: BoardMessage, boardKey?: str
18
18
  export declare function formatTaskContext(claim: BoardClaimedTask, boardKey?: string): string;
19
19
  export declare function formatTaskFollowUpContext(message: BoardMessage, boardKey?: string): string;
20
20
  export declare function boardMessageContent(message: BoardMessage, boardKey?: string): MessageContent;
21
- export declare function fetchBoardAttachment(url: string, client: BoardClient | ((boardKey: string | undefined) => BoardClient | undefined), maxBytes: number): Promise<FetchFileResult | null>;
21
+ export declare function fetchBoardAttachment(url: string, client: BoardClient | ((boardKey: string | undefined) => BoardClient | undefined | Promise<BoardClient | undefined>), maxBytes: number): Promise<FetchFileResult | null>;
@@ -94,7 +94,7 @@ async function fetchBoardAttachment(url, client, maxBytes) {
94
94
  return null;
95
95
  }
96
96
  if (attachmentId.length === 0 || attachmentId.includes("/")) return null;
97
- const resolved = typeof client === "function" ? client(boardKey) : client;
97
+ const resolved = typeof client === "function" ? await client(boardKey) : client;
98
98
  if (resolved === void 0) return null;
99
99
  const response = await resolved.download(attachmentId);
100
100
  return {