@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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "kind": "eve-extension",
3
3
  "formatVersion": 3,
4
- "builtWithEve": "1.7.0",
4
+ "builtWithEve": "1.9.0",
5
5
  "contractMajor": 0
6
6
  }
@@ -1,11 +1,13 @@
1
1
  import { z } from "zod";
2
- import type { BoardAuthorize } from "./lib/authorize.ts";
2
+ import type { BoardAuthorize, BoardClaimAuthorize } from "./lib/authorize.ts";
3
3
  /**
4
- * Makes the agent a participant on one or more Vercel Boards. The agent creates watches with its
5
- * `watch` tool when someone asks; each watch's match wakes it in the board thread, or claims a
6
- * ready task first, and board tools let it read, post, schedule, and settle tasks.
4
+ * Makes the agent a participant on one or more Vercel Boards. By default, every accessible board on
5
+ * the team is discoverable and `General` is used when no board is specified; configure `boards` to
6
+ * override per-board settings, use `"*"` for fallback defaults, or set `"*": false` to disable
7
+ * discovery and allow only explicitly listed boards.
7
8
  */
8
9
  declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
10
+ id: z.ZodOptional<z.ZodString>;
9
11
  name: z.ZodOptional<z.ZodString>;
10
12
  team: z.ZodOptional<z.ZodString>;
11
13
  url: z.ZodOptional<z.ZodString>;
@@ -27,9 +29,11 @@ declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
27
29
  }>>>]>>]>>;
28
30
  watchChannel: z.ZodOptional<z.ZodString>;
29
31
  authorize: z.ZodOptional<z.ZodCustom<BoardAuthorize, BoardAuthorize>>;
32
+ authorizeClaim: z.ZodOptional<z.ZodCustom<BoardClaimAuthorize, BoardClaimAuthorize>>;
30
33
  configurers: z.ZodOptional<z.ZodUnknown>;
31
34
  route: z.ZodOptional<z.ZodString>;
32
- boards: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
35
+ boards: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
36
+ id: z.ZodOptional<z.ZodString>;
33
37
  name: z.ZodOptional<z.ZodString>;
34
38
  team: z.ZodOptional<z.ZodString>;
35
39
  url: z.ZodOptional<z.ZodString>;
@@ -51,7 +55,8 @@ declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
51
55
  }>>>]>>]>>;
52
56
  watchChannel: z.ZodOptional<z.ZodString>;
53
57
  authorize: z.ZodOptional<z.ZodCustom<BoardAuthorize, BoardAuthorize>>;
58
+ authorizeClaim: z.ZodOptional<z.ZodCustom<BoardClaimAuthorize, BoardClaimAuthorize>>;
54
59
  configurers: z.ZodOptional<z.ZodUnknown>;
55
- }, z.core.$strip>>>;
60
+ }, z.core.$strip>]>>>;
56
61
  }, z.core.$strip>>;
57
62
  export default _default;
@@ -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 { BOARD_CHANNEL_SELECTOR, BOARD_NAME_PATTERN, BOARD_PERMISSIONS } from "./lib/client.mjs";
7
+ import { BOARD_CHANNEL_SELECTOR, BOARD_ID_PATTERN, BOARD_NAME_PATTERN, BOARD_PERMISSIONS, isVercelBoardName, normalizeBoardName } from "./lib/client.mjs";
8
8
  import { isValidBoardRouteBase } from "./lib/route.mjs";
9
9
  import { defineExtension } from "eve/extension";
10
10
  import { z } from "zod";
@@ -14,75 +14,89 @@ const profile = z.string().regex(BOARD_NAME_PATTERN, "a letter, then up to 31 le
14
14
  const can = z.union([grant, z.record(z.string().refine((pattern) => pattern === "*" || BOARD_CHANNEL_SELECTOR.test(pattern), "a channel, a subtree such as `work/`, or `*`"), grant)]);
15
15
  const watchChannel = z.string().max(200).regex(BOARD_CHANNEL_SELECTOR, "lowercase segments joined by /").refine((channel) => !channel.endsWith("/"), "one channel, not a subtree");
16
16
  const authorize = fn();
17
+ const authorizeClaim = fn();
17
18
  const removedConfigurers = z.unknown().optional();
18
19
  const CONFIGURERS_REMOVED = "`configurers` was removed; use `authorize` to decide who may manage board watches. See https://eve.dev/docs/channels/board.";
19
20
  const boardUrl = z.string().url().refine((value) => /^https?:\/\//u.test(value), "an http:// or https:// board URL");
21
+ const boardId = z.string().regex(BOARD_ID_PATTERN, "a board ID starting with \"brd_\"");
22
+ const boardName = z.string().refine(isVercelBoardName, "1 to 64 characters without /");
20
23
  const boardEntry = z.object({
21
- name: z.string().min(1).max(64).optional(),
24
+ id: boardId.optional(),
25
+ name: boardName.optional(),
22
26
  team: z.string().min(1).optional(),
23
27
  url: boardUrl.optional(),
24
28
  profile: profile.optional(),
25
29
  can: can.optional(),
26
30
  watchChannel: watchChannel.optional(),
27
31
  authorize: authorize.optional(),
32
+ authorizeClaim: authorizeClaim.optional(),
28
33
  configurers: removedConfigurers
29
34
  });
30
35
  var extension_default = defineExtension({ config: z.object({
31
- name: z.string().min(1).max(64).optional(),
36
+ id: boardId.optional(),
37
+ name: boardName.optional(),
32
38
  team: z.string().min(1).optional(),
33
39
  url: boardUrl.optional(),
34
40
  profile: profile.optional(),
35
41
  can: can.optional(),
36
42
  watchChannel: watchChannel.optional(),
37
43
  authorize: authorize.optional(),
44
+ authorizeClaim: authorizeClaim.optional(),
38
45
  configurers: removedConfigurers,
39
46
  route: z.string().min(1).refine(isValidBoardRouteBase, "an absolute path without parameters or query string, such as \"/eve/v1/board\"").optional(),
40
- boards: z.record(z.string().regex(BOARD_NAME_PATTERN, "a letter, then up to 31 letters, numbers, or hyphens"), boardEntry).optional()
47
+ boards: z.record(z.string().refine((key) => key === "*" || BOARD_NAME_PATTERN.test(key), "\"*\" or a letter, then up to 31 letters, numbers, or hyphens"), z.union([z.boolean(), boardEntry])).optional()
41
48
  }).superRefine((value, ctx) => {
42
- if (value.configurers !== void 0) ctx.addIssue({
49
+ const fail = (path, message) => ctx.addIssue({
43
50
  code: "custom",
44
- message: CONFIGURERS_REMOVED,
45
- path: ["configurers"]
51
+ message,
52
+ path
46
53
  });
47
- for (const [key, entry] of Object.entries(value.boards ?? {})) if (entry.configurers !== void 0) ctx.addIssue({
48
- code: "custom",
49
- message: CONFIGURERS_REMOVED,
50
- path: [
54
+ const checkIdConflicts = (entry, path, prefix) => {
55
+ if (entry.id === void 0) return;
56
+ if (entry.name !== void 0) fail([...path, "id"], `${prefix}combine \`id\` and \`name\`; pass one of them.`);
57
+ if (entry.url !== void 0) fail([...path, "id"], `${prefix}combine \`id\` and \`url\`; pass one of them.`);
58
+ };
59
+ if (value.configurers !== void 0) fail(["configurers"], CONFIGURERS_REMOVED);
60
+ checkIdConflicts(value, [], "Cannot ");
61
+ if (value.boards === void 0) return;
62
+ if (value.id !== void 0 || value.name !== void 0 || value.url !== void 0) fail(["boards"], "Cannot combine `boards` with top-level `id`, `name`, or `url`; set those fields on each entry in `boards`.");
63
+ const seenTargets = new Map();
64
+ let namedCount = 0;
65
+ let discoveryDisabled = false;
66
+ for (const [key, entry] of Object.entries(value.boards)) {
67
+ if (typeof entry === "boolean") {
68
+ if (key === "*") discoveryDisabled = !entry;
69
+ else fail(["boards", key], `Only \`boards["*"]\` may be a boolean; configure board "${key}" with an object.`);
70
+ continue;
71
+ }
72
+ if (entry.configurers !== void 0) fail([
51
73
  "boards",
52
74
  key,
53
75
  "configurers"
54
- ]
55
- });
56
- if (value.boards === void 0) return;
57
- const entries = Object.entries(value.boards);
58
- if (entries.length === 0) ctx.addIssue({
59
- code: "custom",
60
- message: "boards must configure at least one board.",
61
- path: ["boards"]
62
- });
63
- if (value.name !== void 0 || value.team !== void 0 || value.url !== void 0 || value.can !== void 0) ctx.addIssue({
64
- code: "custom",
65
- message: "Cannot combine `boards` with top-level `name`, `team`, `url`, or `can`; set those fields on each entry in `boards`.",
66
- path: ["boards"]
67
- });
68
- const seenTargets = new Map();
69
- for (const [key, entry] of entries) {
76
+ ], CONFIGURERS_REMOVED);
77
+ if (key === "*") {
78
+ if (entry.id !== void 0 || entry.name !== void 0 || entry.url !== void 0) fail(["boards", "*"], "`boards[\"*\"]` configures the fallback for discovered boards and cannot set `id`, `name`, or `url`.");
79
+ continue;
80
+ }
81
+ namedCount += 1;
82
+ checkIdConflicts(entry, ["boards", key], `Board "${key}" cannot `);
70
83
  let target;
71
84
  if (entry.url !== void 0) {
72
85
  const parsed = new URL(entry.url.trim());
73
86
  target = JSON.stringify(["url", `${parsed.origin}${parsed.pathname.replace(/\/+$/u, "")}`]);
74
- } else target = JSON.stringify([
75
- "vercel",
76
- entry.team ?? null,
77
- entry.name ?? null
78
- ]);
87
+ } else if (entry.id !== void 0) target = JSON.stringify(["vercel-id", entry.id]);
88
+ else {
89
+ const effectiveName = normalizeBoardName(entry.name ?? key).toLowerCase();
90
+ target = JSON.stringify([
91
+ "vercel",
92
+ entry.team ?? value.team ?? null,
93
+ effectiveName
94
+ ]);
95
+ }
79
96
  const previous = seenTargets.get(target);
80
- if (previous !== void 0) ctx.addIssue({
81
- code: "custom",
82
- message: `boards "${previous}" and "${key}" target the same board; give each entry a distinct \`name\`, \`team\`, or \`url\`.`,
83
- path: ["boards", key]
84
- });
97
+ if (previous !== void 0) fail(["boards", key], `boards "${previous}" and "${key}" target the same board; give each entry a distinct \`id\`, \`name\`, \`team\`, or \`url\`.`);
85
98
  else seenTargets.set(target, key);
86
99
  }
100
+ if (discoveryDisabled && namedCount === 0) fail(["boards"], "boards with `\"*\": false` must configure at least one board.");
87
101
  }) });
88
102
  export { extension_default as default };
@@ -4,6 +4,6 @@ Your board tools `read`, `reply`, `post`, `react`, and `no_reply` are always ava
4
4
 
5
5
  - `watch`, `watches`, and `unwatch`, when someone asks you to watch the board and act on what's posted.
6
6
  - `schedule`, `schedules`, and `cancel_schedule`, to come back to a thread later.
7
- - `note` (a board-only reply), `label`, `channels`, `actors` (handles to mention), `tasks` (a queue's tasks and their state), `claim_task` (claim a ready task by ID or from a queue), and `create_task`.
7
+ - `note` (a board-only reply), `label`, `boards` (list boards you can access), `channels`, `actors` (handles to mention), `tasks` (a queue's tasks and their state), `claim_task` (claim a ready task by ID or from a queue), and `create_task`.
8
8
 
9
9
  While you hold a claimed task, `complete_task`, `block_task`, and `fail_task` are available (plus `release_task` for tasks claimed with `claim_task`): settle or release the task before you stop. Load the `collaborate` skill before you work on a shared board.
@@ -1,30 +1,51 @@
1
1
  import type { SessionAuthContext } from "eve/context";
2
2
  /** Operation passed to {@link BoardAuthorize}. */
3
- export type BoardAuthorizeAction = "watch" | "watches" | "unwatch" | "claim_task";
4
- /** Context passed to `authorize` before creating, listing, or removing board watches, or claiming a task with `claim_task`. */
3
+ export type BoardAuthorizeAction = "watch" | "watches" | "unwatch";
4
+ /** Context passed to `authorize` before creating, updating, listing, or removing board watches. */
5
5
  export interface BoardAuthorizeRequest {
6
6
  /** Which operation is being requested. */
7
7
  readonly action: BoardAuthorizeAction;
8
8
  /** The session's current caller, or `null` when the session has none. */
9
9
  readonly auth: SessionAuthContext | null;
10
- /** The configured board key (or `"default"` for a shorthand mount). */
10
+ /** The board identifier: a configured board key, a discovered board ID (`brd_…`), or `"default"` for a pinned single-board mount. */
11
11
  readonly board: string;
12
- /** The board's configured name, when set. */
12
+ /** The board's display or configured name, when known. */
13
13
  readonly boardName?: string;
14
14
  /** The board's configured team, when set. */
15
15
  readonly team?: string;
16
16
  /** For `"watch"`, the channel selector being watched. */
17
17
  readonly channel?: string;
18
- /** For `"watch"` with `claim`, or `"claim_task"`, the task's channel or queue channel selector. */
18
+ /** For `"watch"` with `claim`, the queue channel selector. */
19
19
  readonly claimChannel?: string;
20
- /** For `"unwatch"`, the watch ID being removed. */
20
+ /** For `"unwatch"`, or for `"watch"` when updating an existing watch in place, the watch ID. */
21
21
  readonly watchId?: string;
22
- /** For `"claim_task"` by ID, the ID of the task being claimed. */
23
- readonly taskId?: string;
24
22
  }
25
23
  /**
26
- * Decides whether the current caller may create, list, or remove watches on a board, or claim
27
- * a task with `claim_task`.
24
+ * Decides whether the current caller may create, update, list, or remove watches on a board.
28
25
  * Return `true` to allow the operation; any other value denies it.
29
26
  */
30
27
  export type BoardAuthorize = (request: BoardAuthorizeRequest) => boolean | Promise<boolean>;
28
+ /** Operation passed to {@link BoardClaimAuthorize}. */
29
+ export type BoardClaimAuthorizeAction = "claim_task" | "schedule";
30
+ /** Context passed to `authorizeClaim` before claiming a board task with `claim_task` or scheduling a board check-in with `schedule`. */
31
+ export interface BoardClaimAuthorizeRequest {
32
+ /** Which operation is being requested. */
33
+ readonly action: BoardClaimAuthorizeAction;
34
+ /** The session's current caller, or `null` when the session has none. */
35
+ readonly auth: SessionAuthContext | null;
36
+ /** The board identifier: a configured board key, a discovered board ID (`brd_…`), or `"default"` for a pinned single-board mount. */
37
+ readonly board: string;
38
+ /** The board's display or configured name, when known. */
39
+ readonly boardName?: string;
40
+ /** The board's configured team, when set. */
41
+ readonly team?: string;
42
+ /** The task's or thread's channel, or the queue channel selector. */
43
+ readonly claimChannel?: string;
44
+ /** For `claim_task` by ID, the ID of the task being claimed. */
45
+ readonly taskId?: string;
46
+ }
47
+ /**
48
+ * Decides whether the current caller may claim a board task with `claim_task` or schedule a board
49
+ * check-in with `schedule`. Return `true` to allow the operation; any other value denies it.
50
+ */
51
+ export type BoardClaimAuthorize = (request: BoardClaimAuthorizeRequest) => boolean | Promise<boolean>;
@@ -7,7 +7,7 @@ import { settleClaim, settlementOf, type BoardSettlement } from "./claims.ts";
7
7
  export { settleClaim, settlementOf, type BoardSettlement };
8
8
  /** JSON-serializable state for one board thread's session. */
9
9
  export interface BoardChannelState extends PromptQueueState {
10
- /** The configured board key for this session, or omitted on a shorthand mount. */
10
+ /** The board key or discovered board ID (`brd_…`) for this session, or omitted on a pinned single-board mount. */
11
11
  readonly board?: string | null;
12
12
  readonly channel: string | null;
13
13
  /** The thread's root message ID, which replies name. */
@@ -32,7 +32,8 @@ export interface BoardEventContext extends BoardChannelContext, ChannelContinuat
32
32
  }
33
33
  /**
34
34
  * Target accepted by `to(board, target)` for proactive sessions: an existing thread by any
35
- * message ID in it, or a new thread in a channel. Pass `board` when multiple boards are configured.
35
+ * message ID in it, or a new thread in a channel. Pass `board` by key, name, or ID (`brd_…`) to
36
+ * target a board other than the default.
36
37
  */
37
38
  export type BoardReceiveTarget = {
38
39
  readonly board?: string;
@@ -51,7 +52,7 @@ export interface BoardChannelConfig {
51
52
  }
52
53
  /** What the board channel reports about a session to tools, hooks, and instrumentation. */
53
54
  export interface BoardChannelMetadata extends Record<string, unknown> {
54
- /** The configured board key for this session, or `null` for a shorthand mount. */
55
+ /** The board key or discovered board ID (`brd_…`) for this session, or `null` for a pinned single-board mount. */
55
56
  readonly board: string | null;
56
57
  /** The board channel the session's thread is in. */
57
58
  readonly boardChannel: string | null;
@@ -79,7 +80,7 @@ export declare function drainMatches(options: {
79
80
  readonly from: ChannelFrom<BoardChannelState>;
80
81
  readonly wait?: number;
81
82
  }): Promise<number>;
82
- export declare function renewDuringCall(client: () => BoardClient, state: BoardChannelState, callId: string): void;
83
+ export declare function renewDuringCall(client: () => BoardClient | Promise<BoardClient>, state: BoardChannelState, callId: string): void;
83
84
  export declare function endRenewal(state: BoardChannelState, callId?: string): void;
84
85
  export declare function keepBoardClaim(client: BoardClient, state: BoardChannelState): Promise<void>;
85
86
  export declare function renewBeforeTask(client: BoardClient, state: BoardChannelState): 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 { lookupBoard, resolveBoards, resolveSessionBoard, selectBoard } from "./boards.mjs";
7
+ import { matchesBoard, resolveBoards, resolveWakeBoard, selectBoardAsync } from "./boards.mjs";
8
8
  import { BOARD_TEXT_LIMIT, boardAllows, boardErrorCode, boardPostId } from "./client.mjs";
9
9
  import { boardMessageContent, boardSessionAddress, boardThreadId, defaultBoardAuth, fetchBoardAttachment, formatBoardContext, formatTaskContext, formatTaskFollowUpContext, formatWatchContext } from "./inbound.mjs";
10
10
  import { LEGACY_BOARD_WAKE_ROUTE, normalizeBoardRouteBase } from "./route.mjs";
@@ -27,8 +27,10 @@ const CLAIM_EVENTS = new Set([
27
27
  "task.unblocked"
28
28
  ]);
29
29
  function createBoardChannel(settings, options = {}) {
30
- const deploymentFor = (state) => boardClients(resolveSessionBoard(settings(), state.board)).deployment;
31
- const keepClaim = (state) => keepBoardClaim(deploymentFor(state), state);
30
+ const deploymentFor = async (state) => boardClients(await selectBoardAsync(settings(), void 0, state.board)).deployment;
31
+ const keepClaim = async (state) => {
32
+ if (state.task != null) await keepBoardClaim(await deploymentFor(state), state);
33
+ };
32
34
  const draining = new Map();
33
35
  const coalesced = (key, drain) => {
34
36
  const existing = draining.get(key);
@@ -69,31 +71,28 @@ function createBoardChannel(settings, options = {}) {
69
71
  if (wake !== void 0) waitUntil(wake.catch((error) => logError("board wake-up failed", error, { board: board.key })));
70
72
  return Response.json({ ok: true }, { status: 202 });
71
73
  };
72
- const handleShorthandWake = async (_request, { from, waitUntil }) => {
73
- const resolved = resolveBoards(settings());
74
- if (!resolved.shorthand) return Response.json({
75
- error: "Board key is required.",
76
- ok: false
77
- }, { status: 404 });
78
- return wakeTarget(resolved.byKey.values().next().value, from, waitUntil);
79
- };
80
- const handleNamedWake = async (_request, { from, params, waitUntil }) => {
81
- const resolved = resolveBoards(settings());
82
- if (resolved.shorthand) return Response.json({
83
- error: "Unknown board.",
84
- ok: false
85
- }, { status: 404 });
86
- const boardKey = params.board;
87
- const target = boardKey === void 0 ? void 0 : lookupBoard(resolved, boardKey);
88
- if (target === void 0) return Response.json({
74
+ const wakeHandler = (named) => async (_request, { from, params, waitUntil }) => {
75
+ const boardKey = named ? params?.board : void 0;
76
+ if (named && boardKey === void 0) return Response.json({
89
77
  error: "Unknown board.",
90
78
  ok: false
91
79
  }, { status: 404 });
80
+ const target = await resolveWakeBoard(settings(), boardKey).catch((error) => {
81
+ logError("board wake-up failed", error, { board: boardKey ?? null });
82
+ });
83
+ if (target === void 0) {
84
+ const error = !named && resolveBoards(settings()).fallback === void 0 ? "Board key is required." : "Unknown board.";
85
+ return Response.json({
86
+ error,
87
+ ok: false
88
+ }, { status: 404 });
89
+ }
92
90
  return wakeTarget(target, from, waitUntil);
93
91
  };
92
+ const handleShorthandWake = wakeHandler(false);
94
93
  const routes = [
95
94
  POST(`${routeBase}/wake`, handleShorthandWake),
96
- POST(`${routeBase}/:board/wake`, handleNamedWake),
95
+ POST(`${routeBase}/:board/wake`, wakeHandler(true)),
97
96
  ...routeBase === "/eve/v1/board" ? [POST(LEGACY_BOARD_WAKE_ROUTE, handleShorthandWake)] : []
98
97
  ];
99
98
  return defineChannel({
@@ -104,9 +103,8 @@ function createBoardChannel(settings, options = {}) {
104
103
  threadId: null
105
104
  },
106
105
  context(state) {
107
- const target = resolveSessionBoard(settings(), state.board);
108
106
  return {
109
- board: threadHandle(boardClients(target).model, state),
107
+ board: threadHandle(async () => boardClients(await selectBoardAsync(settings(), void 0, state.board)).model, state),
110
108
  state
111
109
  };
112
110
  },
@@ -128,7 +126,7 @@ function createBoardChannel(settings, options = {}) {
128
126
  },
129
127
  routes,
130
128
  async receive({ message, target, ...send }, { from }) {
131
- const resolved = selectBoard(resolveBoards(settings()), target.board, void 0);
129
+ const resolved = await selectBoardAsync(settings(), target.board, void 0);
132
130
  const board = boardClients(resolved).model;
133
131
  let root;
134
132
  if ("thread" in target) root = (await board.thread(target.thread)).message;
@@ -151,13 +149,26 @@ function createBoardChannel(settings, options = {}) {
151
149
  }
152
150
  });
153
151
  },
154
- fetchFile(url) {
152
+ fetchFile(url, context) {
155
153
  const policy = options.uploadPolicy;
156
154
  if (policy === "disabled") return Promise.resolve(null);
157
- return fetchBoardAttachment(url, (boardKey) => {
158
- const set = resolveBoards(settings());
159
- const target = boardKey === void 0 ? set.byKey.size === 1 ? set.byKey.values().next().value : void 0 : lookupBoard(set, boardKey);
160
- return target === void 0 ? void 0 : boardClients(target).model;
155
+ const sessionBoard = typeof context?.state.board === "string" && context.state.board.length > 0 ? context.state.board : void 0;
156
+ return fetchBoardAttachment(url, async (boardKey) => {
157
+ const current = settings();
158
+ const set = resolveBoards(current);
159
+ if (boardKey !== void 0 && set.shorthand) return void 0;
160
+ let target;
161
+ try {
162
+ target = await selectBoardAsync(current, boardKey, sessionBoard, { verify: true });
163
+ } catch {
164
+ return;
165
+ }
166
+ if (context !== void 0) {
167
+ if (sessionBoard !== void 0) {
168
+ if (!matchesBoard(target, sessionBoard)) return void 0;
169
+ } else if (boardKey !== void 0 && !target.shorthand) return;
170
+ }
171
+ return boardClients(target).model;
161
172
  }, policy?.maxBytes ?? DEFAULT_MAX_UPLOAD_BYTES);
162
173
  },
163
174
  uploadPolicy: options.uploadPolicy,
@@ -175,11 +186,12 @@ function createBoardChannel(settings, options = {}) {
175
186
  },
176
187
  async "call.started"(event, ctx) {
177
188
  if (event.data.taskId === void 0) renewDuringCall(() => deploymentFor(ctx.channel.state), ctx.channel.state, event.data.callId);
178
- else await renewBeforeTask(deploymentFor(ctx.channel.state), ctx.channel.state);
189
+ else if (ctx.channel.state.task != null) await renewBeforeTask(await deploymentFor(ctx.channel.state), ctx.channel.state);
179
190
  },
180
191
  async "call.settled"(event, ctx) {
181
192
  endRenewal(ctx.channel.state, event.data.callId);
182
- await settleAfterCall(deploymentFor(ctx.channel.state), ctx.channel, ctx.view, event.data);
193
+ if (ctx.channel.state.task == null) return;
194
+ await settleAfterCall(await deploymentFor(ctx.channel.state), ctx.channel, ctx.view, event.data);
183
195
  },
184
196
  async "turn.settled"(event, ctx) {
185
197
  endRenewal(ctx.channel.state);
@@ -189,7 +201,7 @@ function createBoardChannel(settings, options = {}) {
189
201
  });
190
202
  }
191
203
  async function drainMatches(options) {
192
- const target = "settings" in options ? selectBoard(resolveBoards(options.settings), options.board, void 0) : options.board;
204
+ const target = "settings" in options ? await selectBoardAsync(options.settings, options.board, void 0) : options.board;
193
205
  const { deployment, model, watchChannel } = boardClients(target);
194
206
  const self = await deployment.me();
195
207
  const records = new Map();
@@ -262,10 +274,11 @@ async function dispatch(wake, match, record) {
262
274
  const posted = match.event.message;
263
275
  if (posted !== void 0 && coversChannel(wake.watchChannel, posted.channel)) return false;
264
276
  const idempotencyPrefix = boardKey === void 0 ? "board" : `board:${boardKey}`;
265
- const start = (message, context, idempotencyKey, task) => sendRecovering(wake.from(boardSessionAddress(record.id, message, boardKey)), boardMessageContent(message, boardKey), {
277
+ const start = (message, context, idempotencyKey, options) => sendRecovering(wake.from(boardSessionAddress(record.id, message, boardKey)), boardMessageContent(message, boardKey), {
266
278
  auth: defaultBoardAuth(message, {
267
279
  key: wake.key,
268
280
  name: wake.name,
281
+ selfSchedule: options?.selfSchedule ?? false,
269
282
  shorthand: wake.shorthand,
270
283
  watch: record.id
271
284
  }),
@@ -277,12 +290,13 @@ async function dispatch(wake, match, record) {
277
290
  noSync: message.noSync,
278
291
  threadId: boardThreadId(message),
279
292
  watch: record.id,
280
- ...task !== void 0 && { task }
293
+ ...options?.task !== void 0 && { task: options.task }
281
294
  }
282
295
  });
283
296
  if (match.event.type === "message.posted") {
284
297
  if (posted === void 0 || posted.deleted) return false;
285
- if (posted.by.actor === self.actor && posted.schedule === void 0) return false;
298
+ const selfSchedule = posted.by.actor === self.actor && posted.schedule !== void 0;
299
+ if (posted.by.actor === self.actor && !selfSchedule) return false;
286
300
  if (!boardAllows(can, posted.channel, "read")) {
287
301
  log.warn("board watch matched a channel outside the agent's read scope; skipped it", {
288
302
  ...boardKey !== void 0 && { board: boardKey },
@@ -292,7 +306,7 @@ async function dispatch(wake, match, record) {
292
306
  return false;
293
307
  }
294
308
  if (record.action.type !== "claim") {
295
- await start(posted, formatBoardContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`);
309
+ await start(posted, formatBoardContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`, { selfSchedule });
296
310
  return true;
297
311
  }
298
312
  if (posted.re === null) return false;
@@ -300,7 +314,7 @@ async function dispatch(wake, match, record) {
300
314
  const held = root.task?.claim;
301
315
  if (held?.actor !== self.actor || Date.parse(held.until) <= Date.now()) return false;
302
316
  if (root.labels["eve-claim-watch"] !== record.id) return false;
303
- await start(posted, formatTaskFollowUpContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`);
317
+ await start(posted, formatTaskFollowUpContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`, { selfSchedule });
304
318
  return true;
305
319
  }
306
320
  if (record.action.type !== "claim" || !CLAIM_EVENTS.has(match.event.type)) return false;
@@ -321,7 +335,10 @@ async function dispatch(wake, match, record) {
321
335
  }
322
336
  try {
323
337
  await deployment.label(task.id, { set: { [CLAIM_WATCH_LABEL]: record.id } });
324
- await start(task, formatTaskContext(claimed, boardKey), `${idempotencyPrefix}:task:${task.id}:${claim.epoch}`, claim);
338
+ await start(task, formatTaskContext(claimed, boardKey), `${idempotencyPrefix}:task:${task.id}:${claim.epoch}`, {
339
+ selfSchedule: false,
340
+ task: claim
341
+ });
325
342
  } catch (error) {
326
343
  await deployment.held(claim).release().catch((releaseError) => logError("board task release failed", releaseError, { task: task.id }));
327
344
  throw error;
@@ -378,11 +395,11 @@ async function settleAfterCall(client, channel, view, call$1) {
378
395
  function threadHandle(client, state) {
379
396
  const threadId = state.threadId ?? "";
380
397
  return {
381
- reply: (post) => client.reply(threadId, typeof post === "string" ? {
398
+ reply: async (post) => await (await client()).reply(threadId, typeof post === "string" ? {
382
399
  noSync: state.noSync === true,
383
400
  text: post
384
401
  } : post),
385
- typing: (status) => client.typing(threadId, status)
402
+ typing: async (status) => await (await client()).typing(threadId, status)
386
403
  };
387
404
  }
388
405
  async function showPrompt(channel, request) {
@@ -1,28 +1,55 @@
1
- import type { BoardAuthorize } from "./authorize.ts";
2
- import type { BoardCan, BoardSettings } from "./client.ts";
1
+ import type { BoardAuthorize, BoardClaimAuthorize } from "./authorize.ts";
2
+ import { type BoardCan, type BoardSettings } from "./client.ts";
3
3
  export declare const DEFAULT_BOARD_KEY = "default";
4
4
  export declare const DEFAULT_WATCH_CHANNEL = "eve-config/watches";
5
5
  export interface ResolvedBoardConfig {
6
6
  readonly key: string;
7
7
  readonly shorthand: boolean;
8
+ readonly id?: string;
8
9
  readonly name?: string;
10
+ readonly ensure?: boolean;
9
11
  readonly team?: string;
10
12
  readonly url?: string;
11
13
  readonly profile?: string;
12
14
  readonly can?: BoardCan;
13
15
  readonly watchChannel: string;
14
16
  readonly authorize?: BoardAuthorize;
17
+ readonly authorizeClaim?: BoardClaimAuthorize;
15
18
  readonly routeBase: string;
16
19
  readonly registrationRouteBase: string;
17
20
  }
21
+ export interface ResolvedBoardFallback {
22
+ readonly team?: string;
23
+ readonly profile?: string;
24
+ readonly can?: BoardCan;
25
+ readonly watchChannel: string;
26
+ readonly authorize?: BoardAuthorize;
27
+ readonly authorizeClaim?: BoardClaimAuthorize;
28
+ }
18
29
  export interface ResolvedBoardSet {
19
30
  readonly shorthand: boolean;
20
31
  readonly routeBase: string;
21
32
  readonly byKey: ReadonlyMap<string, ResolvedBoardConfig>;
22
33
  readonly keys: readonly string[];
34
+ readonly fallback?: ResolvedBoardFallback;
35
+ }
36
+ export interface AccessibleBoardSummary {
37
+ readonly board: string;
38
+ readonly id?: string;
39
+ readonly name?: string;
40
+ readonly default?: boolean;
41
+ readonly visibility?: "team" | "private";
42
+ readonly team?: string;
23
43
  }
44
+ export declare function matchesBoard(board: ResolvedBoardConfig, ref: string): boolean;
24
45
  export declare function resolveBoards(settings: BoardSettings): ResolvedBoardSet;
25
- export declare function lookupBoard(set: ResolvedBoardSet, key: string): ResolvedBoardConfig | undefined;
26
- export declare function selectBoard(set: ResolvedBoardSet, requestedKey: string | undefined, sessionKey?: string | null): ResolvedBoardConfig;
27
- export declare function resolveSessionBoard(settings: BoardSettings, sessionKey?: string | null): ResolvedBoardConfig;
46
+ export declare function selectBoardAsync(settings: BoardSettings, requestedKey: string | undefined, sessionKey?: string | null, options?: {
47
+ readonly needsMetadata?: boolean;
48
+ readonly verify?: boolean;
49
+ }): Promise<ResolvedBoardConfig>;
50
+ export declare function resolveWakeBoard(settings: BoardSettings, boardParam?: string): Promise<ResolvedBoardConfig | undefined>;
51
+ export declare function listAccessibleBoards(settings: BoardSettings): Promise<{
52
+ readonly boards: readonly AccessibleBoardSummary[];
53
+ readonly defaultBoardId: string | null;
54
+ }>;
28
55
  export declare function formatConfiguredBoards(settings: BoardSettings): string | null;