@eve/board 0.1.0 → 0.2.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 (42) hide show
  1. package/dist/extension/_manifest.json +1 -1
  2. package/dist/extension/extension.d.ts +30 -4
  3. package/dist/extension/extension.mjs +55 -4
  4. package/dist/extension/instructions/boards.d.ts +2 -0
  5. package/dist/extension/instructions/boards.mjs +14 -0
  6. package/dist/extension/lib/authorize.d.ts +27 -0
  7. package/dist/extension/lib/authorize.mjs +7 -0
  8. package/dist/extension/lib/board-channel.d.ts +13 -1
  9. package/dist/extension/lib/board-channel.mjs +84 -34
  10. package/dist/extension/lib/boards.d.ts +28 -0
  11. package/dist/extension/lib/boards.mjs +103 -0
  12. package/dist/extension/lib/channel.d.ts +1 -0
  13. package/dist/extension/lib/client.d.ts +4 -1
  14. package/dist/extension/lib/client.mjs +24 -11
  15. package/dist/extension/lib/inbound.d.ts +9 -7
  16. package/dist/extension/lib/inbound.mjs +43 -15
  17. package/dist/extension/lib/route.d.ts +5 -0
  18. package/dist/extension/lib/route.mjs +23 -0
  19. package/dist/extension/lib/tools.d.ts +45 -1
  20. package/dist/extension/lib/tools.mjs +173 -65
  21. package/dist/extension/lib/watches.d.ts +11 -5
  22. package/dist/extension/lib/watches.mjs +37 -17
  23. package/dist/extension/skills/collaborate/SKILL.md +16 -5
  24. package/dist/extension/tools/actors.d.ts +1 -0
  25. package/dist/extension/tools/block_task.d.ts +1 -1
  26. package/dist/extension/tools/cancel_schedule.d.ts +1 -0
  27. package/dist/extension/tools/channels.d.ts +3 -1
  28. package/dist/extension/tools/complete_task.d.ts +1 -1
  29. package/dist/extension/tools/create_task.d.ts +1 -0
  30. package/dist/extension/tools/fail_task.d.ts +1 -1
  31. package/dist/extension/tools/label.d.ts +1 -0
  32. package/dist/extension/tools/note.d.ts +1 -0
  33. package/dist/extension/tools/post.d.ts +2 -0
  34. package/dist/extension/tools/react.d.ts +2 -0
  35. package/dist/extension/tools/read.d.ts +8 -0
  36. package/dist/extension/tools/reply.d.ts +2 -0
  37. package/dist/extension/tools/schedule.d.ts +1 -0
  38. package/dist/extension/tools/schedules.d.ts +1 -0
  39. package/dist/extension/tools/unwatch.d.ts +1 -0
  40. package/dist/extension/tools/watch.d.ts +7 -0
  41. package/dist/extension/tools/watches.d.ts +13 -0
  42. package/package.json +4 -4
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "kind": "eve-extension",
3
3
  "formatVersion": 3,
4
- "builtWithEve": "1.2.0",
4
+ "builtWithEve": "1.5.0",
5
5
  "contractMajor": 0
6
6
  }
@@ -1,12 +1,14 @@
1
1
  import { z } from "zod";
2
+ import type { BoardAuthorize } from "./lib/authorize.ts";
2
3
  /**
3
- * Makes the agent a participant on a Vercel Board. The agent creates watches with its `watch`
4
- * tool when someone asks; each watch's match wakes it in the board thread, or claims a ready
5
- * 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. 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.
6
7
  */
7
8
  declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
8
9
  name: z.ZodOptional<z.ZodString>;
9
10
  team: z.ZodOptional<z.ZodString>;
11
+ url: z.ZodOptional<z.ZodString>;
10
12
  profile: z.ZodOptional<z.ZodString>;
11
13
  can: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodReadonly<z.ZodArray<z.ZodEnum<{
12
14
  label: "label";
@@ -24,6 +26,30 @@ declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
24
26
  sync: "sync";
25
27
  }>>>]>>]>>;
26
28
  watchChannel: z.ZodOptional<z.ZodString>;
27
- configurers: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ authorize: z.ZodOptional<z.ZodCustom<BoardAuthorize, BoardAuthorize>>;
30
+ route: z.ZodOptional<z.ZodString>;
31
+ boards: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
32
+ name: z.ZodOptional<z.ZodString>;
33
+ team: z.ZodOptional<z.ZodString>;
34
+ url: z.ZodOptional<z.ZodString>;
35
+ profile: z.ZodOptional<z.ZodString>;
36
+ can: z.ZodOptional<z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodReadonly<z.ZodArray<z.ZodEnum<{
37
+ label: "label";
38
+ manage: "manage";
39
+ post: "post";
40
+ react: "react";
41
+ read: "read";
42
+ sync: "sync";
43
+ }>>>]>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodReadonly<z.ZodArray<z.ZodEnum<{
44
+ label: "label";
45
+ manage: "manage";
46
+ post: "post";
47
+ react: "react";
48
+ read: "read";
49
+ sync: "sync";
50
+ }>>>]>>]>>;
51
+ watchChannel: z.ZodOptional<z.ZodString>;
52
+ authorize: z.ZodOptional<z.ZodCustom<BoardAuthorize, BoardAuthorize>>;
53
+ }, z.core.$strip>>>;
28
54
  }, z.core.$strip>>;
29
55
  export default _default;
@@ -5,15 +5,66 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { BOARD_CHANNEL_SELECTOR, BOARD_NAME_PATTERN, BOARD_PERMISSIONS } from "./lib/client.mjs";
8
+ import { isValidBoardRouteBase } from "./lib/route.mjs";
8
9
  import { defineExtension } from "eve/extension";
9
10
  import { z } from "zod";
11
+ const fn = () => z.custom((value) => typeof value === "function", "expected a function");
10
12
  const grant = z.union([z.literal("all"), z.array(z.enum(BOARD_PERMISSIONS)).readonly()]);
13
+ const profile = z.string().regex(BOARD_NAME_PATTERN, "a letter, then up to 31 letters, numbers, or hyphens");
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
+ const watchChannel = z.string().max(200).regex(BOARD_CHANNEL_SELECTOR, "lowercase segments joined by /").refine((channel) => !channel.endsWith("/"), "one channel, not a subtree");
16
+ const authorize = fn();
17
+ const boardUrl = z.string().url().refine((value) => /^https?:\/\//u.test(value), "an http:// or https:// board URL");
18
+ const boardEntry = z.object({
19
+ name: z.string().min(1).max(64).optional(),
20
+ team: z.string().min(1).optional(),
21
+ url: boardUrl.optional(),
22
+ profile: profile.optional(),
23
+ can: can.optional(),
24
+ watchChannel: watchChannel.optional(),
25
+ authorize: authorize.optional()
26
+ });
11
27
  var extension_default = defineExtension({ config: z.object({
12
28
  name: z.string().min(1).max(64).optional(),
13
29
  team: z.string().min(1).optional(),
14
- profile: z.string().regex(BOARD_NAME_PATTERN, "a letter, then up to 31 letters, numbers, or hyphens").optional(),
15
- 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)]).optional(),
16
- watchChannel: z.string().max(200).regex(BOARD_CHANNEL_SELECTOR, "lowercase segments joined by /").refine((channel) => !channel.endsWith("/"), "one channel, not a subtree").optional(),
17
- configurers: z.array(z.string().min(1)).optional()
30
+ url: boardUrl.optional(),
31
+ profile: profile.optional(),
32
+ can: can.optional(),
33
+ watchChannel: watchChannel.optional(),
34
+ authorize: authorize.optional(),
35
+ route: z.string().min(1).refine(isValidBoardRouteBase, "an absolute path without parameters or query string, such as \"/eve/v1/board\"").optional(),
36
+ boards: z.record(z.string().regex(BOARD_NAME_PATTERN, "a letter, then up to 31 letters, numbers, or hyphens"), boardEntry).optional()
37
+ }).superRefine((value, ctx) => {
38
+ if (value.boards === void 0) return;
39
+ const entries = Object.entries(value.boards);
40
+ if (entries.length === 0) ctx.addIssue({
41
+ code: "custom",
42
+ message: "boards must configure at least one board.",
43
+ path: ["boards"]
44
+ });
45
+ if (value.name !== void 0 || value.team !== void 0 || value.url !== void 0 || value.can !== void 0) ctx.addIssue({
46
+ code: "custom",
47
+ message: "Cannot combine `boards` with top-level `name`, `team`, `url`, or `can`; set those fields on each entry in `boards`.",
48
+ path: ["boards"]
49
+ });
50
+ const seenTargets = new Map();
51
+ for (const [key, entry] of entries) {
52
+ let target;
53
+ if (entry.url !== void 0) {
54
+ const parsed = new URL(entry.url.trim());
55
+ target = JSON.stringify(["url", `${parsed.origin}${parsed.pathname.replace(/\/+$/u, "")}`]);
56
+ } else target = JSON.stringify([
57
+ "vercel",
58
+ entry.team ?? null,
59
+ entry.name ?? null
60
+ ]);
61
+ const previous = seenTargets.get(target);
62
+ if (previous !== void 0) ctx.addIssue({
63
+ code: "custom",
64
+ message: `boards "${previous}" and "${key}" target the same board; give each entry a distinct \`name\`, \`team\`, or \`url\`.`,
65
+ path: ["boards", key]
66
+ });
67
+ else seenTargets.set(target, key);
68
+ }
18
69
  }) });
19
70
  export { extension_default as default };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("eve/instructions").DynamicSentinel<import("eve/instructions").DynamicInstructionsResult, import("eve/instructions").DynamicContext>;
2
+ export default _default;
@@ -0,0 +1,14 @@
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 extension_default from "../extension.mjs";
8
+ import { formatConfiguredBoards } from "../lib/boards.mjs";
9
+ import { defineDynamic, defineInstructions } from "eve/instructions";
10
+ var boards_default = defineDynamic(() => {
11
+ const content = formatConfiguredBoards(extension_default.config);
12
+ return content === null ? null : defineInstructions({ content });
13
+ });
14
+ export { boards_default as default };
@@ -0,0 +1,27 @@
1
+ import type { SessionAuthContext } from "eve/context";
2
+ /** Operation passed to {@link BoardAuthorize}. */
3
+ export type BoardAuthorizeAction = "watch" | "watches" | "unwatch";
4
+ /** Context passed to `authorize` before creating, listing, or removing board watches. */
5
+ export interface BoardAuthorizeRequest {
6
+ /** Which operation is being requested. */
7
+ readonly action: BoardAuthorizeAction;
8
+ /** The session's current caller, or `null` when the session has none. */
9
+ readonly auth: SessionAuthContext | null;
10
+ /** The configured board key (or `"default"` for a shorthand mount). */
11
+ readonly board: string;
12
+ /** The board's configured name, when set. */
13
+ readonly boardName?: string;
14
+ /** The board's configured team, when set. */
15
+ readonly team?: string;
16
+ /** For `"watch"`, the channel selector being watched. */
17
+ readonly channel?: string;
18
+ /** For `"watch"` with `claim`, the task queue channel selector being claimed from. */
19
+ readonly claimChannel?: string;
20
+ /** For `"unwatch"`, the watch ID being removed. */
21
+ readonly watchId?: string;
22
+ }
23
+ /**
24
+ * Decides whether the current caller may create, list, or remove watches on a board.
25
+ * Return `true` to allow the operation; any other value denies it.
26
+ */
27
+ export type BoardAuthorize = (request: BoardAuthorizeRequest) => boolean | Promise<boolean>;
@@ -0,0 +1,7 @@
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
+ export {};
@@ -1,9 +1,12 @@
1
1
  import { type Channel, type ChannelContinuationOps, type ChannelFrom, type TurnPolicy, type UploadPolicyInput } from "eve/channels";
2
2
  import { type SessionView } from "eve/events";
3
3
  import { type PromptQueueState } from "eve/internal/channels";
4
+ import { type ResolvedBoardConfig } from "./boards.ts";
4
5
  import { type BoardClaim, type BoardClient, type BoardMessage, type BoardPostOptions, type BoardSettings } from "./client.ts";
5
6
  /** JSON-serializable state for one board thread's session. */
6
7
  export interface BoardChannelState extends PromptQueueState {
8
+ /** The configured board key for this session, or omitted on a shorthand mount. */
9
+ readonly board?: string | null;
7
10
  readonly channel: string | null;
8
11
  /** The thread's root message ID, which replies name. */
9
12
  readonly threadId: string | null;
@@ -27,11 +30,13 @@ export interface BoardEventContext extends BoardChannelContext, ChannelContinuat
27
30
  }
28
31
  /**
29
32
  * Target accepted by `to(board, target)` for proactive sessions: an existing thread by any
30
- * message ID in it, or a new thread in a channel.
33
+ * message ID in it, or a new thread in a channel. Pass `board` when multiple boards are configured.
31
34
  */
32
35
  export type BoardReceiveTarget = {
36
+ readonly board?: string;
33
37
  readonly thread: string;
34
38
  } | {
39
+ readonly board?: string;
35
40
  readonly channel: string;
36
41
  readonly text: string;
37
42
  readonly labels?: Readonly<Record<string, string>>;
@@ -44,6 +49,8 @@ export interface BoardChannelConfig {
44
49
  }
45
50
  /** What the board channel reports about a session to tools, hooks, and instrumentation. */
46
51
  export interface BoardChannelMetadata extends Record<string, unknown> {
52
+ /** The configured board key for this session, or `null` for a shorthand mount. */
53
+ readonly board: string | null;
47
54
  /** The board channel the session's thread is in. */
48
55
  readonly boardChannel: string | null;
49
56
  /** The task the session holds, with when its claim ends, or `null`. */
@@ -61,7 +68,12 @@ export interface BoardChannel extends Channel<BoardChannelState, BoardReceiveTar
61
68
  }
62
69
  export declare function createBoardChannel(settings: () => BoardSettings, options?: BoardChannelConfig): BoardChannel;
63
70
  export declare function drainMatches(options: {
71
+ readonly board: ResolvedBoardConfig;
72
+ readonly from: ChannelFrom<BoardChannelState>;
73
+ readonly wait?: number;
74
+ } | {
64
75
  readonly settings: BoardSettings;
76
+ readonly board?: string;
65
77
  readonly from: ChannelFrom<BoardChannelState>;
66
78
  readonly wait?: number;
67
79
  }): Promise<number>;
@@ -4,9 +4,11 @@ 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
8
  import { BOARD_TEXT_LIMIT, boardAllows, boardErrorCode, boardPostId } from "./client.mjs";
8
9
  import { boardMessageContent, boardSessionAddress, boardThreadId, defaultBoardAuth, fetchBoardAttachment, formatBoardContext, formatTaskContext, formatTaskFollowUpContext, formatWatchContext } from "./inbound.mjs";
9
- import { BOARD_WAKE_ROUTE, BoardWatchConfigError, boardClients, checkQueueScope, coversChannel, findWatchRecord } from "./watches.mjs";
10
+ import { LEGACY_BOARD_WAKE_ROUTE, normalizeBoardRouteBase } from "./route.mjs";
11
+ import { BoardWatchConfigError, boardClients, checkQueueScope, coversChannel, findWatchRecord } from "./watches.mjs";
10
12
  import { POST, SessionStrandedError, defineChannel } from "eve/channels";
11
13
  import { call } from "eve/events";
12
14
  import { createLogger, postedIn, renderTextInteraction, surfaceEvents } from "eve/internal/channels";
@@ -35,16 +37,17 @@ const CLAIM_EVENTS = new Set([
35
37
  "task.unblocked"
36
38
  ]);
37
39
  function createBoardChannel(settings, options = {}) {
38
- const deployment = () => boardClients(settings()).deployment;
39
- const keepClaim = (state) => keepBoardClaim(deployment(), state);
40
- let draining;
41
- const coalesced = (drain) => {
42
- if (draining !== void 0) {
43
- draining.again = true;
40
+ const deploymentFor = (state) => boardClients(resolveSessionBoard(settings(), state.board)).deployment;
41
+ const keepClaim = (state) => keepBoardClaim(deploymentFor(state), state);
42
+ const draining = new Map();
43
+ const coalesced = (key, drain) => {
44
+ const existing = draining.get(key);
45
+ if (existing !== void 0) {
46
+ existing.again = true;
44
47
  return;
45
48
  }
46
49
  const current = { again: false };
47
- draining = current;
50
+ draining.set(key, current);
48
51
  return (async () => {
49
52
  let dispatched = 0;
50
53
  try {
@@ -53,7 +56,7 @@ function createBoardChannel(settings, options = {}) {
53
56
  dispatched += await drain();
54
57
  } while (current.again);
55
58
  } finally {
56
- draining = void 0;
59
+ if (draining.get(key) === current) draining.delete(key);
57
60
  }
58
61
  return dispatched;
59
62
  })();
@@ -67,6 +70,42 @@ function createBoardChannel(settings, options = {}) {
67
70
  await bestEffort("typing", () => channel.board.typing());
68
71
  }
69
72
  });
73
+ const routeBase = normalizeBoardRouteBase(settings().route);
74
+ const wakeTarget = (board, from, waitUntil) => {
75
+ const wake = coalesced(board.key, () => drainMatches({
76
+ board,
77
+ from
78
+ }));
79
+ if (wake !== void 0) waitUntil(wake.catch((error) => logError("board wake-up failed", error, { board: board.key })));
80
+ return Response.json({ ok: true }, { status: 202 });
81
+ };
82
+ const handleShorthandWake = async (_request, { from, waitUntil }) => {
83
+ const resolved = resolveBoards(settings());
84
+ if (!resolved.shorthand) return Response.json({
85
+ error: "Board key is required.",
86
+ ok: false
87
+ }, { status: 404 });
88
+ return wakeTarget(resolved.byKey.values().next().value, from, waitUntil);
89
+ };
90
+ const handleNamedWake = async (_request, { from, params, waitUntil }) => {
91
+ const resolved = resolveBoards(settings());
92
+ if (resolved.shorthand) return Response.json({
93
+ error: "Unknown board.",
94
+ ok: false
95
+ }, { status: 404 });
96
+ const boardKey = params.board;
97
+ const target = boardKey === void 0 ? void 0 : lookupBoard(resolved, boardKey);
98
+ if (target === void 0) return Response.json({
99
+ error: "Unknown board.",
100
+ ok: false
101
+ }, { status: 404 });
102
+ return wakeTarget(target, from, waitUntil);
103
+ };
104
+ const routes = [
105
+ POST(`${routeBase}/wake`, handleShorthandWake),
106
+ POST(`${routeBase}/:board/wake`, handleNamedWake),
107
+ ...routeBase === "/eve/v1/board" ? [POST(LEGACY_BOARD_WAKE_ROUTE, handleShorthandWake)] : []
108
+ ];
70
109
  return defineChannel({
71
110
  turnPolicy: options.turnPolicy,
72
111
  state: {
@@ -75,13 +114,15 @@ function createBoardChannel(settings, options = {}) {
75
114
  threadId: null
76
115
  },
77
116
  context(state) {
117
+ const target = resolveSessionBoard(settings(), state.board);
78
118
  return {
79
- board: threadHandle(boardClients(settings()).model, state),
119
+ board: threadHandle(boardClients(target).model, state),
80
120
  state
81
121
  };
82
122
  },
83
123
  metadata(state) {
84
124
  return {
125
+ board: state.board ?? null,
85
126
  boardChannel: state.channel,
86
127
  boardTask: state.task == null ? null : {
87
128
  id: state.task.taskId,
@@ -95,16 +136,10 @@ function createBoardChannel(settings, options = {}) {
95
136
  if (payload.state?.task !== void 0) ctx.state.task = payload.state.task;
96
137
  if (payload.state?.noSync !== void 0) ctx.state.noSync = payload.state.noSync;
97
138
  },
98
- routes: [POST(BOARD_WAKE_ROUTE, async (_request, { from, waitUntil }) => {
99
- const wake = coalesced(() => drainMatches({
100
- from,
101
- settings: settings()
102
- }));
103
- if (wake !== void 0) waitUntil(wake.catch((error) => logError("board wake-up failed", error)));
104
- return Response.json({ ok: true }, { status: 202 });
105
- })],
139
+ routes,
106
140
  async receive({ message, target, ...send }, { from }) {
107
- const board = boardClients(settings()).model;
141
+ const resolved = selectBoard(resolveBoards(settings()), target.board, void 0);
142
+ const board = boardClients(resolved).model;
108
143
  let root;
109
144
  if ("thread" in target) root = (await board.thread(target.thread)).message;
110
145
  else {
@@ -115,9 +150,11 @@ function createBoardChannel(settings, options = {}) {
115
150
  text: target.text
116
151
  });
117
152
  }
118
- return await sendRecovering(from(boardSessionAddress(board.profile, root)), message, {
153
+ const boardKey = resolved.shorthand ? void 0 : resolved.key;
154
+ return await sendRecovering(from(boardSessionAddress(board.profile, root, boardKey)), message, {
119
155
  ...send,
120
156
  state: {
157
+ ...boardKey !== void 0 && { board: boardKey },
121
158
  channel: root.channel,
122
159
  noSync: false,
123
160
  threadId: root.id
@@ -127,7 +164,11 @@ function createBoardChannel(settings, options = {}) {
127
164
  fetchFile(url) {
128
165
  const policy = options.uploadPolicy;
129
166
  if (policy === "disabled") return Promise.resolve(null);
130
- return fetchBoardAttachment(url, boardClients(settings()).model, policy?.maxBytes ?? DEFAULT_MAX_UPLOAD_BYTES);
167
+ return fetchBoardAttachment(url, (boardKey) => {
168
+ const set = resolveBoards(settings());
169
+ const target = boardKey === void 0 ? set.byKey.size === 1 ? set.byKey.values().next().value : void 0 : lookupBoard(set, boardKey);
170
+ return target === void 0 ? void 0 : boardClients(target).model;
171
+ }, policy?.maxBytes ?? DEFAULT_MAX_UPLOAD_BYTES);
131
172
  },
132
173
  uploadPolicy: options.uploadPolicy,
133
174
  events: {
@@ -143,12 +184,12 @@ function createBoardChannel(settings, options = {}) {
143
184
  await bestEffort("typing", () => ctx.channel.board.typing(status));
144
185
  },
145
186
  async "call.started"(event, ctx) {
146
- if (event.data.taskId === void 0) renewDuringCall(deployment, ctx.channel.state, event.data.callId);
147
- else await renewBeforeTask(deployment(), ctx.channel.state);
187
+ if (event.data.taskId === void 0) renewDuringCall(() => deploymentFor(ctx.channel.state), ctx.channel.state, event.data.callId);
188
+ else await renewBeforeTask(deploymentFor(ctx.channel.state), ctx.channel.state);
148
189
  },
149
190
  async "call.settled"(event, ctx) {
150
191
  endRenewal(ctx.channel.state, event.data.callId);
151
- await settleAfterCall(deployment(), ctx.channel, ctx.view, event.data);
192
+ await settleAfterCall(deploymentFor(ctx.channel.state), ctx.channel, ctx.view, event.data);
152
193
  },
153
194
  async "turn.settled"(event, ctx) {
154
195
  endRenewal(ctx.channel.state);
@@ -158,16 +199,18 @@ function createBoardChannel(settings, options = {}) {
158
199
  });
159
200
  }
160
201
  async function drainMatches(options) {
161
- const { settings } = options;
162
- const { deployment, model, watchChannel } = boardClients(settings);
202
+ const target = "settings" in options ? selectBoard(resolveBoards(options.settings), options.board, void 0) : options.board;
203
+ const { deployment, model, watchChannel } = boardClients(target);
163
204
  const self = await deployment.me();
164
205
  const records = new Map();
165
206
  const wake = {
166
- can: settings.can,
207
+ boardKey: target.shorthand ? void 0 : target.key,
208
+ can: target.can,
167
209
  deployment,
168
210
  from: options.from,
211
+ key: target.key,
169
212
  model,
170
- name: settings.name,
213
+ name: target.name,
171
214
  recordOf(id) {
172
215
  let record = records.get(id);
173
216
  if (record === void 0) {
@@ -182,6 +225,7 @@ async function drainMatches(options) {
182
225
  return record;
183
226
  },
184
227
  self,
228
+ shorthand: target.shorthand,
185
229
  watchChannel
186
230
  };
187
231
  const wait = options.wait ?? 0;
@@ -224,17 +268,21 @@ async function handleMatch(wake, match) {
224
268
  }
225
269
  }
226
270
  async function dispatch(wake, match, record) {
227
- const { can, deployment, self } = wake;
271
+ const { boardKey, can, deployment, self } = wake;
228
272
  const posted = match.event.message;
229
273
  if (posted !== void 0 && coversChannel(wake.watchChannel, posted.channel)) return false;
230
- const start = (message, context, idempotencyKey, task) => sendRecovering(wake.from(boardSessionAddress(record.id, message)), boardMessageContent(message), {
274
+ const idempotencyPrefix = boardKey === void 0 ? "board" : `board:${boardKey}`;
275
+ const start = (message, context, idempotencyKey, task) => sendRecovering(wake.from(boardSessionAddress(record.id, message, boardKey)), boardMessageContent(message, boardKey), {
231
276
  auth: defaultBoardAuth(message, {
277
+ key: wake.key,
232
278
  name: wake.name,
279
+ shorthand: wake.shorthand,
233
280
  watch: record.id
234
281
  }),
235
- context: [formatWatchContext(record), context],
282
+ context: [formatWatchContext(record, boardKey), context],
236
283
  idempotencyKey,
237
284
  state: {
285
+ ...boardKey !== void 0 && { board: boardKey },
238
286
  channel: message.channel,
239
287
  noSync: message.noSync,
240
288
  threadId: boardThreadId(message),
@@ -247,13 +295,14 @@ async function dispatch(wake, match, record) {
247
295
  if (posted.by.actor === self.actor && posted.schedule === void 0) return false;
248
296
  if (!boardAllows(can, posted.channel, "read")) {
249
297
  log.warn("board watch matched a channel outside the agent's read scope; skipped it", {
298
+ ...boardKey !== void 0 && { board: boardKey },
250
299
  channel: posted.channel,
251
300
  watch: record.id
252
301
  });
253
302
  return false;
254
303
  }
255
304
  if (record.action.type !== "claim") {
256
- await start(posted, formatBoardContext(posted), `board:${match.id}`);
305
+ await start(posted, formatBoardContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`);
257
306
  return true;
258
307
  }
259
308
  if (posted.re === null) return false;
@@ -261,7 +310,7 @@ async function dispatch(wake, match, record) {
261
310
  const held = root.task?.claim;
262
311
  if (held?.actor !== self.actor || Date.parse(held.until) <= Date.now()) return false;
263
312
  if (root.labels[CLAIM_WATCH_LABEL] !== record.id) return false;
264
- await start(posted, formatTaskFollowUpContext(posted), `board:${match.id}`);
313
+ await start(posted, formatTaskFollowUpContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`);
265
314
  return true;
266
315
  }
267
316
  if (record.action.type !== "claim" || !CLAIM_EVENTS.has(match.event.type)) return false;
@@ -274,6 +323,7 @@ async function dispatch(wake, match, record) {
274
323
  if (!boardAllows(can, task.channel, "read") || !boardAllows(can, task.channel, "label")) {
275
324
  await deployment.held(claim).release();
276
325
  log.warn("board watch claimed a task outside the agent's read scope; released it", {
326
+ ...boardKey !== void 0 && { board: boardKey },
277
327
  task: task.id,
278
328
  watch: record.id
279
329
  });
@@ -281,7 +331,7 @@ async function dispatch(wake, match, record) {
281
331
  }
282
332
  try {
283
333
  await deployment.label(task.id, { set: { [CLAIM_WATCH_LABEL]: record.id } });
284
- await start(task, formatTaskContext(claimed), `board:task:${task.id}:${claim.epoch}`, claim);
334
+ await start(task, formatTaskContext(claimed, boardKey), `${idempotencyPrefix}:task:${task.id}:${claim.epoch}`, claim);
285
335
  } catch (error) {
286
336
  await deployment.held(claim).release().catch((releaseError) => logError("board task release failed", releaseError, { task: task.id }));
287
337
  throw error;
@@ -0,0 +1,28 @@
1
+ import type { BoardAuthorize } from "./authorize.ts";
2
+ import type { BoardCan, BoardSettings } from "./client.ts";
3
+ export declare const DEFAULT_BOARD_KEY = "default";
4
+ export declare const DEFAULT_WATCH_CHANNEL = "eve-config/watches";
5
+ export interface ResolvedBoardConfig {
6
+ readonly key: string;
7
+ readonly shorthand: boolean;
8
+ readonly name?: string;
9
+ readonly team?: string;
10
+ readonly url?: string;
11
+ readonly profile?: string;
12
+ readonly can?: BoardCan;
13
+ readonly watchChannel: string;
14
+ readonly authorize?: BoardAuthorize;
15
+ readonly routeBase: string;
16
+ readonly registrationRouteBase: string;
17
+ }
18
+ export interface ResolvedBoardSet {
19
+ readonly shorthand: boolean;
20
+ readonly routeBase: string;
21
+ readonly byKey: ReadonlyMap<string, ResolvedBoardConfig>;
22
+ readonly keys: readonly string[];
23
+ }
24
+ 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;
28
+ export declare function formatConfiguredBoards(settings: BoardSettings): string | null;
@@ -0,0 +1,103 @@
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 { normalizeBoardRouteBase } from "./route.mjs";
8
+ const DEFAULT_BOARD_KEY = "default";
9
+ const DEFAULT_WATCH_CHANNEL = "eve-config/watches";
10
+ function resolveBoards(settings) {
11
+ 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
+ }
33
+ const byKey = new Map();
34
+ const keys = [];
35
+ for (const [key, entry] of Object.entries(settings.boards)) {
36
+ byKey.set(key, {
37
+ authorize: entry.authorize ?? settings.authorize,
38
+ can: entry.can,
39
+ key,
40
+ name: entry.name,
41
+ profile: entry.profile ?? settings.profile,
42
+ registrationRouteBase: `${routeBase}/${key}`,
43
+ routeBase,
44
+ shorthand: false,
45
+ team: entry.team,
46
+ url: entry.url,
47
+ watchChannel: entry.watchChannel ?? settings.watchChannel ?? "eve-config/watches"
48
+ });
49
+ keys.push(key);
50
+ }
51
+ if (keys.length === 0) throw new Error("Board extension `boards` must configure at least one board.");
52
+ return {
53
+ byKey,
54
+ keys,
55
+ routeBase,
56
+ shorthand: false
57
+ };
58
+ }
59
+ function lookupBoard(set, key) {
60
+ return set.byKey.get(key);
61
+ }
62
+ function selectBoard(set, requestedKey, sessionKey) {
63
+ if (requestedKey !== void 0) {
64
+ const found = lookupBoard(set, requestedKey);
65
+ if (found !== void 0) return found;
66
+ throw new Error(`Unknown board "${requestedKey}". Configured boards: ${set.keys.join(", ")}.`);
67
+ }
68
+ if (sessionKey != null && sessionKey.length > 0) {
69
+ const found = lookupBoard(set, sessionKey);
70
+ if (found !== void 0) return found;
71
+ throw new Error(`Board "${sessionKey}" from this session is no longer configured. Configured boards: ${set.keys.join(", ")}.`);
72
+ }
73
+ if (set.byKey.size === 1) return set.byKey.values().next().value;
74
+ throw new Error(`Pass \`board\` to choose which board to use. Configured boards: ${set.keys.join(", ")}.`);
75
+ }
76
+ function resolveSessionBoard(settings, sessionKey) {
77
+ const set = resolveBoards(settings);
78
+ 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(", ")}.`);
82
+ }
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(", ")}).`);
85
+ }
86
+ function formatConfiguredBoards(settings) {
87
+ const set = resolveBoards(settings);
88
+ if (set.shorthand) return null;
89
+ const lines = [...set.byKey.values()].map((entry) => {
90
+ const label = entry.name ?? "team default board";
91
+ const team = entry.team === void 0 ? "" : ` (team \`${entry.team}\`)`;
92
+ return `- \`${entry.key}\`: ${label}${team}`;
93
+ });
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.`;
95
+ return [
96
+ "## Configured boards",
97
+ "",
98
+ ...lines,
99
+ "",
100
+ `In a session a board started, replies stay on that board and board tools default to that board. ${requirement}`
101
+ ].join("\n");
102
+ }
103
+ export { DEFAULT_BOARD_KEY, DEFAULT_WATCH_CHANNEL, formatConfiguredBoards, lookupBoard, resolveBoards, resolveSessionBoard, selectBoard };
@@ -8,4 +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
12
  export type { BoardChannel, BoardChannelConfig, BoardChannelMetadata, BoardChannelState, BoardReceiveTarget, } from "./board-channel.ts";