@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.
@@ -5,7 +5,7 @@ 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
10
  const BOARD_TASK_STATES = [
11
11
  "waiting",
@@ -28,10 +28,34 @@ const BOARD_TEXT_LIMIT = 1e4;
28
28
  const BOARD_TAIL_LIMIT = 1e3;
29
29
  const BOARD_UPLOAD_LIMIT = 4194304;
30
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;
31
33
  const BOARD_CHANNEL_SELECTOR = /^[a-z0-9][a-z0-9_-]*(?:\/[a-z0-9][a-z0-9_-]*)*\/?$/u;
32
34
  const BOARD_TASK_NOTE_LIMIT = 1e3;
33
35
  const BOARD_HOLD_KIND_PATTERN = /^[a-z0-9][a-z0-9_.-]{0,63}$/u;
34
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
+ }
35
59
  function boardPostId(key) {
36
60
  return `eve-${createHash("sha256").update(key).digest("hex").slice(0, 32)}`;
37
61
  }
@@ -46,20 +70,45 @@ function boardErrorCode(error) {
46
70
  const code = error.code;
47
71
  return typeof code === "string" ? code : void 0;
48
72
  }
73
+ const MAX_CACHED_HANDLES = 256;
49
74
  const handles = new Map();
50
75
  const principals = new Map();
51
- 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 }) {
52
92
  return JSON.stringify([
53
- name ?? null,
93
+ id ?? null,
94
+ id !== void 0 ? null : name ?? null,
95
+ id !== void 0 ? null : ensure ?? null,
54
96
  team ?? null,
55
97
  url?.trim().replace(/\/+$/u, "") || process.env.BOARD_URL?.trim().replace(/\/+$/u, "") || null,
56
- 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
57
101
  ]);
58
102
  }
59
103
  function createBoardHandle(board$1) {
60
- const { name, team, url } = board$1;
61
- 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
+ } : {
62
110
  ...name !== void 0 && { name },
111
+ ...name !== void 0 && ensure !== void 0 && { ensure },
63
112
  ...team !== void 0 && { team }
64
113
  };
65
114
  if (url === void 0) return board(options);
@@ -76,10 +125,10 @@ function createBoardClient(board, can) {
76
125
  const profile = (board.profile ?? "eve").toLowerCase();
77
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.`);
78
127
  const key = handleKey(board);
79
- let base = handles.get(key);
128
+ let base = getCached(handles, key);
80
129
  if (base === void 0) {
81
130
  base = createBoardHandle(board);
82
- handles.set(key, base);
131
+ setCached(handles, key, base);
83
132
  }
84
133
  const handle = withHints(base.as(profile, can === void 0 ? void 0 : { can }));
85
134
  const meKey = `${key}\n${profile}`;
@@ -116,7 +165,7 @@ function createBoardClient(board, can) {
116
165
  profile,
117
166
  discovery: async () => await handle.discovery(),
118
167
  me: () => {
119
- let me = principals.get(meKey);
168
+ let me = getCached(principals, meKey);
120
169
  if (me === void 0) {
121
170
  me = handle.me().then(({ actor, principal }) => ({
122
171
  actor,
@@ -125,7 +174,7 @@ function createBoardClient(board, can) {
125
174
  principals.delete(meKey);
126
175
  throw error;
127
176
  });
128
- principals.set(meKey, me);
177
+ setCached(principals, meKey, me);
129
178
  }
130
179
  return me;
131
180
  },
@@ -159,6 +208,9 @@ function createBoardClient(board, can) {
159
208
  },
160
209
  post: async (channel, post) => writtenOf(await handle.post(channel, postOf(post))),
161
210
  reply: async (id, post) => writtenOf(await handle.reply(id, postOf(post))),
211
+ async edit(id, text) {
212
+ await handle.edit(id, text);
213
+ },
162
214
  upload: async (file) => await handle.upload({
163
215
  data: file.data,
164
216
  name: file.name,
@@ -389,4 +441,4 @@ function scheduleOf(schedule) {
389
441
  text: schedule.text
390
442
  };
391
443
  }
392
- export { BOARD_CHANNEL_SELECTOR, BOARD_HOLD_KIND_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, withHints };
444
+ 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 };
@@ -6,6 +6,7 @@ export declare function boardSessionAddress(watch: string, message: Pick<BoardMe
6
6
  export declare function defaultBoardAuth(message: BoardMessage, board: {
7
7
  readonly key?: string;
8
8
  readonly name?: string;
9
+ readonly selfSchedule?: boolean;
9
10
  readonly shorthand?: boolean;
10
11
  readonly watch?: string;
11
12
  }): SessionAuthContext;
@@ -18,4 +19,4 @@ export declare function formatBoardContext(message: BoardMessage, boardKey?: str
18
19
  export declare function formatTaskContext(claim: BoardClaimedTask, boardKey?: string): string;
19
20
  export declare function formatTaskFollowUpContext(message: BoardMessage, boardKey?: string): string;
20
21
  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>;
22
+ export declare function fetchBoardAttachment(url: string, client: BoardClient | ((boardKey: string | undefined) => BoardClient | undefined | Promise<BoardClient | undefined>), maxBytes: number): Promise<FetchFileResult | null>;
@@ -25,6 +25,8 @@ function defaultBoardAuth(message, board) {
25
25
  message_id: message.id,
26
26
  principal: message.by.principal,
27
27
  ...message.by.profile !== null && { profile: message.by.profile },
28
+ ...message.schedule !== void 0 && { schedule_id: message.schedule.id },
29
+ ...board.selfSchedule === true && { self_schedule: "true" },
28
30
  thread_id: boardThreadId(message),
29
31
  ...board.watch !== void 0 && { watch: board.watch }
30
32
  },
@@ -94,7 +96,7 @@ async function fetchBoardAttachment(url, client, maxBytes) {
94
96
  return null;
95
97
  }
96
98
  if (attachmentId.length === 0 || attachmentId.includes("/")) return null;
97
- const resolved = typeof client === "function" ? client(boardKey) : client;
99
+ const resolved = typeof client === "function" ? await client(boardKey) : client;
98
100
  if (resolved === void 0) return null;
99
101
  const response = await resolved.download(attachmentId);
100
102
  return {
@@ -4,6 +4,11 @@ import { type BoardWatchAction } from "./watches.ts";
4
4
  type Settings = () => BoardSettings;
5
5
  export declare function holdsTask(ctx: Pick<ToolContext, "channel">): boolean;
6
6
  export declare function holdsSessionTask(): boolean;
7
+ /** Lists the boards the agent can access. */
8
+ export declare function defineBoardBoardsTool(settings: Settings): import("eve/tools").ToolDefinition<Record<string, never>, {
9
+ readonly boards: readonly import("./boards.ts").AccessibleBoardSummary[];
10
+ readonly defaultBoardId: string | null;
11
+ }>;
7
12
  /** Lists the board's channels. */
8
13
  export declare function defineBoardChannelsTool(settings: Settings): import("eve/tools").ToolDefinition<{
9
14
  board?: string | undefined;
@@ -580,9 +585,10 @@ export declare function defineBoardReleaseTaskTool(settings?: Settings): import(
580
585
  task: string;
581
586
  }>;
582
587
  };
583
- /** Creates a watch: the board wakes the agent with these instructions when a message matches. */
588
+ /** Creates a watch, or updates an existing watch in place when `id` is provided. */
584
589
  export declare function defineBoardWatchTool(settings: Settings): import("eve/tools").ToolDefinition<{
585
590
  board?: string | undefined;
591
+ id?: string | undefined;
586
592
  channel: string;
587
593
  label?: string[] | undefined;
588
594
  by?: string | undefined;