@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.
- package/dist/extension/_manifest.json +1 -1
- package/dist/extension/extension.d.ts +11 -6
- package/dist/extension/extension.mjs +51 -37
- package/dist/extension/instructions.md +1 -1
- package/dist/extension/lib/authorize.d.ts +31 -10
- package/dist/extension/lib/board-channel.d.ts +5 -4
- package/dist/extension/lib/board-channel.mjs +57 -40
- package/dist/extension/lib/boards.d.ts +32 -5
- package/dist/extension/lib/boards.mjs +308 -45
- package/dist/extension/lib/channel.d.ts +1 -1
- package/dist/extension/lib/claims.d.ts +1 -1
- package/dist/extension/lib/claims.mjs +18 -10
- package/dist/extension/lib/client.d.ts +22 -1
- package/dist/extension/lib/client.mjs +63 -11
- package/dist/extension/lib/inbound.d.ts +2 -1
- package/dist/extension/lib/inbound.mjs +3 -1
- package/dist/extension/lib/tools.d.ts +7 -1
- package/dist/extension/lib/tools.mjs +145 -77
- package/dist/extension/lib/watches.d.ts +7 -3
- package/dist/extension/lib/watches.mjs +79 -28
- package/dist/extension/skills/collaborate/SKILL.md +4 -4
- package/dist/extension/tools/boards.d.ts +6 -0
- package/dist/extension/tools/boards.mjs +10 -0
- package/dist/extension/tools/watch.d.ts +2 -1
- package/dist/extension/tools/watches.d.ts +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.mjs +2 -1
- package/package.json +3 -3
|
@@ -4,10 +4,10 @@ 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 {
|
|
7
|
+
import { listAccessibleBoards, matchesBoard, resolveBoards, selectBoardAsync } from "./boards.mjs";
|
|
8
8
|
import { CLAIM_LEASE_SECONDS, CLAIM_WATCH_LABEL, clearSessionClaim, readSessionClaim, settleClaim, stopClaimRenewal, writeSessionClaim } from "./claims.mjs";
|
|
9
|
-
import { BOARD_HOLD_KIND_PATTERN, BOARD_NAME_PATTERN, BOARD_TASK_NOTE_LIMIT, BOARD_TASK_STATES, BOARD_TEXT_LIMIT, boardAllows, boardPostId } from "./client.mjs";
|
|
10
|
-
import { boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, listWatches, removeWatch, tailOf, watchIdOf } from "./watches.mjs";
|
|
9
|
+
import { BOARD_HOLD_KIND_PATTERN, BOARD_NAME_PATTERN, BOARD_TASK_NOTE_LIMIT, BOARD_TASK_STATES, BOARD_TEXT_LIMIT, boardAllows, boardErrorCode, boardPostId } from "./client.mjs";
|
|
10
|
+
import { boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, listWatches, removeWatch, tailOf, updateWatch, watchIdOf } from "./watches.mjs";
|
|
11
11
|
import { authorOf } from "./inbound.mjs";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { createLogger } from "eve/internal/channels";
|
|
@@ -16,7 +16,7 @@ import { always } from "eve/tools/approval";
|
|
|
16
16
|
const defaultSettings = () => ({});
|
|
17
17
|
const SHARED = "Board channels are shared with the team, and a channel may sync to Slack, GitHub, or Linear, so everything posted there can reach people outside the board.";
|
|
18
18
|
const messageId = z.string().min(1).describe("Any message ID in the thread, as the board gave it.");
|
|
19
|
-
const boardOption = z.string().min(1).optional().describe("Which
|
|
19
|
+
const boardOption = z.string().min(1).optional().describe("Which board to use, by configured key, board name, or board ID (`brd_…`). Defaults to this session's board inside a board session, or to the team's default board (`General`) outside one when discovery is enabled; required outside a board session when multiple static boards are configured with discovery disabled.");
|
|
20
20
|
function postId(ctx) {
|
|
21
21
|
return boardPostId(`${ctx.session.id}:${ctx.callId}`);
|
|
22
22
|
}
|
|
@@ -33,27 +33,27 @@ function sessionBoard(ctx) {
|
|
|
33
33
|
function currentThread(ctx) {
|
|
34
34
|
return boardMetadata(ctx).boardThread || void 0;
|
|
35
35
|
}
|
|
36
|
-
function targetBoard(settings, board, ctx) {
|
|
37
|
-
return
|
|
36
|
+
async function targetBoard(settings, board, ctx, options) {
|
|
37
|
+
return await selectBoardAsync(settings(), board, sessionBoard(ctx), options);
|
|
38
38
|
}
|
|
39
|
-
function clientFor(settings, board, ctx) {
|
|
40
|
-
const resolved = targetBoard(settings, board, ctx);
|
|
39
|
+
async function clientFor(settings, board, ctx) {
|
|
40
|
+
const resolved = await targetBoard(settings, board, ctx);
|
|
41
41
|
return {
|
|
42
42
|
board: resolved,
|
|
43
43
|
client: boardClients(resolved).model
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
function threadOrCurrent(id, ctx,
|
|
46
|
+
function threadOrCurrent(id, ctx, target) {
|
|
47
47
|
if (id !== void 0) return id;
|
|
48
48
|
const sessionKey = sessionBoard(ctx);
|
|
49
|
-
if (sessionKey !== void 0 && sessionKey
|
|
49
|
+
if (sessionKey !== void 0 && !matchesBoard(target, sessionKey)) throw new Error(`Pass the thread's \`id\`: this session's thread is on board "${sessionKey}", not "${target.key}".`);
|
|
50
50
|
const thread = currentThread(ctx);
|
|
51
51
|
if (thread === void 0) throw new Error("Pass the thread's `id`: this session didn't start from a board thread.");
|
|
52
52
|
return thread;
|
|
53
53
|
}
|
|
54
|
-
function replyTarget(settings, boardKey, id, ctx) {
|
|
54
|
+
async function replyTarget(settings, boardKey, id, ctx) {
|
|
55
55
|
if (id !== void 0) {
|
|
56
|
-
const { board, client } = clientFor(settings, boardKey, ctx);
|
|
56
|
+
const { board, client } = await clientFor(settings, boardKey, ctx);
|
|
57
57
|
return {
|
|
58
58
|
board,
|
|
59
59
|
client,
|
|
@@ -62,9 +62,14 @@ function replyTarget(settings, boardKey, id, ctx) {
|
|
|
62
62
|
}
|
|
63
63
|
const meta = boardMetadata(ctx);
|
|
64
64
|
if (meta.boardThread) {
|
|
65
|
-
const { board, client } = clientFor(settings, boardKey, ctx);
|
|
65
|
+
const { board, client } = await clientFor(settings, boardKey, ctx);
|
|
66
66
|
const sessionKey = meta.board || void 0;
|
|
67
|
-
if (sessionKey !== void 0
|
|
67
|
+
if (sessionKey !== void 0) {
|
|
68
|
+
if (!matchesBoard(board, sessionKey)) throw new Error(`Pass the thread's \`id\`: this session's thread is on board "${sessionKey}", not "${board.key}".`);
|
|
69
|
+
} else if (boardKey !== void 0 && !board.shorthand) {
|
|
70
|
+
const own = await selectBoardAsync(settings(), void 0, void 0).catch(() => void 0);
|
|
71
|
+
if (own === void 0 || !matchesBoard(board, own.key)) throw new Error(`Pass the thread's \`id\`: this session's thread isn't on board "${board.key}".`);
|
|
72
|
+
}
|
|
68
73
|
return {
|
|
69
74
|
board,
|
|
70
75
|
client,
|
|
@@ -73,8 +78,8 @@ function replyTarget(settings, boardKey, id, ctx) {
|
|
|
73
78
|
}
|
|
74
79
|
const held = activeSessionClaim();
|
|
75
80
|
if (held !== null) {
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
const resolved = await selectBoardAsync(settings(), boardKey, held.board);
|
|
82
|
+
if (boardKey !== void 0 && !matchesBoard(resolved, held.board)) throw new Error(`Pass the thread's \`id\`: this session holds task #${held.claim.taskId} on board "${held.board}", not "${resolved.key}".`);
|
|
78
83
|
return {
|
|
79
84
|
board: resolved,
|
|
80
85
|
client: boardClients(resolved).model,
|
|
@@ -105,9 +110,9 @@ async function settleSessionTask(settings, settled, details) {
|
|
|
105
110
|
stopClaimRenewal(held.claim.token);
|
|
106
111
|
let resolved;
|
|
107
112
|
try {
|
|
108
|
-
resolved =
|
|
113
|
+
resolved = await selectBoardAsync(settings(), void 0, held.board);
|
|
109
114
|
} catch (error) {
|
|
110
|
-
clearSessionClaim();
|
|
115
|
+
if (boardErrorCode(error) === void 0) clearSessionClaim();
|
|
111
116
|
throw error;
|
|
112
117
|
}
|
|
113
118
|
const client = boardClients(resolved).deployment;
|
|
@@ -198,13 +203,23 @@ function summarize(message) {
|
|
|
198
203
|
function requireContent(text, attach) {
|
|
199
204
|
if ((text === void 0 || text.trim() === "") && (attach === void 0 || attach.length === 0)) throw new Error("Pass text, files to attach, or both.");
|
|
200
205
|
}
|
|
206
|
+
function defineBoardBoardsTool(settings) {
|
|
207
|
+
return defineTool({
|
|
208
|
+
deferred: true,
|
|
209
|
+
description: "List the boards this agent can access, with each board's key or ID (`board`), display name, whether it is the team's default board, and visibility.",
|
|
210
|
+
inputSchema: z.object({}),
|
|
211
|
+
async execute() {
|
|
212
|
+
return await listAccessibleBoards(settings());
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
201
216
|
function defineBoardChannelsTool(settings) {
|
|
202
217
|
return defineTool({
|
|
203
218
|
deferred: true,
|
|
204
219
|
description: "List the board's channels you can read.",
|
|
205
220
|
inputSchema: z.object({ board: boardOption }),
|
|
206
221
|
async execute({ board }, ctx) {
|
|
207
|
-
return { channels: await clientFor(settings, board, ctx).client.channels() };
|
|
222
|
+
return { channels: await (await clientFor(settings, board, ctx)).client.channels() };
|
|
208
223
|
}
|
|
209
224
|
});
|
|
210
225
|
}
|
|
@@ -224,7 +239,7 @@ function defineBoardReadTool(settings) {
|
|
|
224
239
|
limit: z.number().int().min(1).max(100).optional()
|
|
225
240
|
}),
|
|
226
241
|
async execute({ board: boardKey, id, link, after, ...query }, ctx) {
|
|
227
|
-
const board = clientFor(settings, boardKey, ctx).client;
|
|
242
|
+
const board = (await clientFor(settings, boardKey, ctx)).client;
|
|
228
243
|
if (id !== void 0) return summarizeThread(await board.thread(id, { after }));
|
|
229
244
|
if (link !== void 0) return summarizeThread(await board.linked(link));
|
|
230
245
|
if (query.channel === void 0) throw new Error("Pass `id`, `link`, or `channel`.");
|
|
@@ -259,7 +274,7 @@ function defineBoardPostTool(settings) {
|
|
|
259
274
|
}),
|
|
260
275
|
async execute({ board: boardKey, channel, text, attach, ...post }, ctx) {
|
|
261
276
|
requireContent(text, attach);
|
|
262
|
-
const board = clientFor(settings, boardKey, ctx).client;
|
|
277
|
+
const board = (await clientFor(settings, boardKey, ctx)).client;
|
|
263
278
|
const attachments = await uploadFiles(board, attach, ctx.getSandbox);
|
|
264
279
|
return written(await board.post(channel, {
|
|
265
280
|
...post,
|
|
@@ -283,7 +298,7 @@ function defineBoardReplyTool(settings) {
|
|
|
283
298
|
}),
|
|
284
299
|
async execute({ board: boardKey, id, text, attach, ...post }, ctx) {
|
|
285
300
|
requireContent(text, attach);
|
|
286
|
-
const { client: board, targetId } = replyTarget(settings, boardKey, id, ctx);
|
|
301
|
+
const { client: board, targetId } = await replyTarget(settings, boardKey, id, ctx);
|
|
287
302
|
const attachments = await uploadFiles(board, attach, ctx.getSandbox);
|
|
288
303
|
return written(await board.reply(targetId, {
|
|
289
304
|
...post,
|
|
@@ -304,7 +319,7 @@ function defineBoardNoteTool(settings) {
|
|
|
304
319
|
text: z.string().min(1).max(BOARD_TEXT_LIMIT)
|
|
305
320
|
}),
|
|
306
321
|
async execute({ board: boardKey, id, text }, ctx) {
|
|
307
|
-
const { client: board, targetId } = replyTarget(settings, boardKey, id, ctx);
|
|
322
|
+
const { client: board, targetId } = await replyTarget(settings, boardKey, id, ctx);
|
|
308
323
|
return written(await board.reply(targetId, {
|
|
309
324
|
id: postId(ctx),
|
|
310
325
|
noSync: true,
|
|
@@ -323,7 +338,7 @@ function defineBoardReactTool(settings) {
|
|
|
323
338
|
remove: z.boolean().optional()
|
|
324
339
|
}),
|
|
325
340
|
async execute({ board: boardKey, id, emoji, remove }, ctx) {
|
|
326
|
-
await clientFor(settings, boardKey, ctx).client.react(id, emoji, { remove });
|
|
341
|
+
await (await clientFor(settings, boardKey, ctx)).client.react(id, emoji, { remove });
|
|
327
342
|
return { ok: true };
|
|
328
343
|
}
|
|
329
344
|
});
|
|
@@ -340,7 +355,7 @@ function defineBoardLabelTool(settings) {
|
|
|
340
355
|
if: z.record(z.string(), z.string().nullable()).optional().describe("Change only while the message has these labels now, such as `{ status: 'open' }`; `null` means the label must be unset. Use it when others may change the same labels.")
|
|
341
356
|
}),
|
|
342
357
|
async execute({ board: boardKey, id, set, unset, if: conditions }, ctx) {
|
|
343
|
-
await clientFor(settings, boardKey, ctx).client.label(id, {
|
|
358
|
+
await (await clientFor(settings, boardKey, ctx)).client.label(id, {
|
|
344
359
|
if: conditions,
|
|
345
360
|
set,
|
|
346
361
|
unset
|
|
@@ -365,8 +380,18 @@ function defineBoardScheduleTool(settings) {
|
|
|
365
380
|
sync: z.boolean().optional().describe("Also post it to the thread's synced platforms, such as Slack.")
|
|
366
381
|
}),
|
|
367
382
|
async execute({ board: boardKey, id, sync, ...timing }, ctx) {
|
|
368
|
-
const
|
|
369
|
-
const
|
|
383
|
+
const resolved = await targetBoard(settings, boardKey, ctx, { needsMetadata: true });
|
|
384
|
+
const re = threadOrCurrent(id, ctx, resolved);
|
|
385
|
+
const board = boardClients(resolved).model;
|
|
386
|
+
let claimChannel;
|
|
387
|
+
if (id === void 0) claimChannel = boardMetadata(ctx).boardChannel ?? void 0;
|
|
388
|
+
else if (resolved.authorizeClaim !== void 0) claimChannel = (await board.thread(id, { limit: 1 })).message.channel;
|
|
389
|
+
const denial = await authorizationDenial(resolved, ctx, {
|
|
390
|
+
...claimChannel !== void 0 && { details: { claimChannel } },
|
|
391
|
+
kind: "schedule"
|
|
392
|
+
});
|
|
393
|
+
if (denial !== void 0) throw new Error(denial);
|
|
394
|
+
const schedule = await board.schedule({ re }, {
|
|
370
395
|
...timing,
|
|
371
396
|
noSync: sync !== true
|
|
372
397
|
});
|
|
@@ -387,7 +412,7 @@ function defineBoardCancelScheduleTool(settings) {
|
|
|
387
412
|
id: z.string().min(1).describe("The schedule's ID.")
|
|
388
413
|
}),
|
|
389
414
|
async execute({ board: boardKey, id }, ctx) {
|
|
390
|
-
return await clientFor(settings, boardKey, ctx).client.cancelSchedule(id);
|
|
415
|
+
return await (await clientFor(settings, boardKey, ctx)).client.cancelSchedule(id);
|
|
391
416
|
}
|
|
392
417
|
});
|
|
393
418
|
}
|
|
@@ -401,9 +426,9 @@ function defineBoardSchedulesTool(settings) {
|
|
|
401
426
|
channel: z.string().min(1).optional()
|
|
402
427
|
}),
|
|
403
428
|
async execute({ board: boardKey, id, channel }, ctx) {
|
|
404
|
-
const { board: resolved, client: board } = clientFor(settings, boardKey, ctx);
|
|
429
|
+
const { board: resolved, client: board } = await clientFor(settings, boardKey, ctx);
|
|
405
430
|
const sessionKey = sessionBoard(ctx);
|
|
406
|
-
const sameBoard = sessionKey === void 0
|
|
431
|
+
const sameBoard = sessionKey === void 0 ? boardKey === void 0 : matchesBoard(resolved, sessionKey);
|
|
407
432
|
const re = id ?? (channel === void 0 && sameBoard ? currentThread(ctx) : void 0);
|
|
408
433
|
return { schedules: await board.schedules(re !== void 0 ? { re } : channel !== void 0 ? { channel } : { by: (await board.me()).actor }) };
|
|
409
434
|
}
|
|
@@ -420,7 +445,7 @@ function defineBoardActorsTool(settings) {
|
|
|
420
445
|
}),
|
|
421
446
|
async execute({ board: boardKey, search, limit }, ctx) {
|
|
422
447
|
const needle = search?.toLowerCase();
|
|
423
|
-
const actors = (await clientFor(settings, boardKey, ctx).client.actors()).filter((actor) => needle === void 0 || actor.handle.toLowerCase().includes(needle) || actor.name.toLowerCase().includes(needle));
|
|
448
|
+
const actors = (await (await clientFor(settings, boardKey, ctx)).client.actors()).filter((actor) => needle === void 0 || actor.handle.toLowerCase().includes(needle) || actor.name.toLowerCase().includes(needle));
|
|
424
449
|
return {
|
|
425
450
|
actors: actors.slice(0, limit ?? 50),
|
|
426
451
|
total: actors.length
|
|
@@ -441,7 +466,7 @@ function defineBoardCreateTaskTool(settings) {
|
|
|
441
466
|
noSync: z.boolean().optional()
|
|
442
467
|
}),
|
|
443
468
|
async execute({ board: boardKey, channel, ...task }, ctx) {
|
|
444
|
-
return summarize(await clientFor(settings, boardKey, ctx).client.createTask(channel, {
|
|
469
|
+
return summarize(await (await clientFor(settings, boardKey, ctx)).client.createTask(channel, {
|
|
445
470
|
...task,
|
|
446
471
|
id: postId(ctx)
|
|
447
472
|
}));
|
|
@@ -494,46 +519,80 @@ function defineBoardReleaseTaskTool(settings = defaultSettings) {
|
|
|
494
519
|
});
|
|
495
520
|
}
|
|
496
521
|
const log = createLogger("board.tools");
|
|
497
|
-
|
|
522
|
+
const TRUSTED_CLAIM_ACTOR_KINDS = new Set([
|
|
523
|
+
"person",
|
|
524
|
+
"agent",
|
|
525
|
+
"deployment"
|
|
526
|
+
]);
|
|
527
|
+
async function authorizationDenial(board, ctx, policy) {
|
|
498
528
|
const caller = ctx.session.auth?.current ?? null;
|
|
499
|
-
const
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
|
|
529
|
+
const denied = policy.kind === "watch" ? "You are not authorized to manage board watches on this agent." : policy.kind === "schedule" ? "You are not authorized to schedule board check-ins on this agent." : "You are not authorized to claim board tasks on this agent.";
|
|
530
|
+
const baseRequest = {
|
|
531
|
+
auth: caller,
|
|
532
|
+
board: board.key,
|
|
533
|
+
...board.name !== void 0 && { boardName: board.name },
|
|
534
|
+
...board.team !== void 0 && { team: board.team }
|
|
535
|
+
};
|
|
536
|
+
if (policy.kind === "watch" && board.authorize !== void 0) try {
|
|
503
537
|
return await board.authorize({
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
...board.name !== void 0 && { boardName: board.name },
|
|
508
|
-
...board.team !== void 0 && { team: board.team },
|
|
509
|
-
...details.channel !== void 0 && { channel: details.channel },
|
|
510
|
-
...details.claimChannel !== void 0 && { claimChannel: details.claimChannel },
|
|
511
|
-
...details.watchId !== void 0 && { watchId: details.watchId },
|
|
512
|
-
...details.taskId !== void 0 && { taskId: details.taskId }
|
|
538
|
+
...baseRequest,
|
|
539
|
+
action: policy.action,
|
|
540
|
+
...policy.details
|
|
513
541
|
}) === true ? void 0 : denied;
|
|
514
542
|
} catch (error) {
|
|
515
543
|
log.error("board authorization callback failed", {
|
|
516
|
-
action,
|
|
544
|
+
action: policy.action,
|
|
517
545
|
board: board.key,
|
|
518
546
|
error,
|
|
519
547
|
errorId: crypto.randomUUID()
|
|
520
548
|
});
|
|
521
549
|
return denied;
|
|
522
550
|
}
|
|
523
|
-
if (
|
|
551
|
+
if (policy.kind !== "watch" && board.authorizeClaim !== void 0) {
|
|
552
|
+
const action = policy.kind === "schedule" ? "schedule" : "claim_task";
|
|
553
|
+
try {
|
|
554
|
+
return await board.authorizeClaim({
|
|
555
|
+
...baseRequest,
|
|
556
|
+
action,
|
|
557
|
+
...policy.details
|
|
558
|
+
}) === true ? void 0 : denied;
|
|
559
|
+
} catch (error) {
|
|
560
|
+
log.error("board claim authorization callback failed", {
|
|
561
|
+
action,
|
|
562
|
+
board: board.key,
|
|
563
|
+
error,
|
|
564
|
+
errorId: crypto.randomUUID()
|
|
565
|
+
});
|
|
566
|
+
return denied;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (caller === null || caller.principalType === "anonymous") {
|
|
570
|
+
if (policy.kind === "watch") return "Only a signed-in person may change this agent's board watches. Ask from a channel where you're signed in.";
|
|
571
|
+
return `Only a signed-in caller, an agent schedule, or an internal board watch may ${policy.kind === "schedule" ? "schedule board check-ins" : "claim board tasks"} with this agent. Ask from a channel where you're signed in.`;
|
|
572
|
+
}
|
|
524
573
|
if (caller.authenticator === "board-watcher") {
|
|
525
|
-
if (
|
|
574
|
+
if (policy.kind === "watch") {
|
|
575
|
+
if (caller.attributes.actor_kind !== "person") return "Only a person on the team may change this agent's board watches, not a synced platform user or another agent.";
|
|
576
|
+
} else {
|
|
577
|
+
const actorKind = caller.attributes.actor_kind;
|
|
578
|
+
const selfSchedule = caller.attributes.self_schedule === "true";
|
|
579
|
+
if (!(typeof actorKind === "string" && TRUSTED_CLAIM_ACTOR_KINDS.has(actorKind)) && !selfSchedule) return `Only a team member, agent, deployment, or this agent's own scheduled check-in may ${policy.kind === "schedule" ? "schedule board check-ins" : "claim board tasks"} from a board watch, not a synced external user, CI workflow, or unrecognized board actor. Configure \`authorizeClaim\` to allow other board actors.`;
|
|
580
|
+
}
|
|
526
581
|
const callerBoard = typeof caller.attributes.board_key === "string" ? caller.attributes.board_key : void 0;
|
|
527
|
-
if (callerBoard !== void 0 && callerBoard
|
|
582
|
+
if (callerBoard !== void 0 && !matchesBoard(board, callerBoard) || callerBoard === void 0 && !board.shorthand) {
|
|
583
|
+
if (policy.kind === "watch") return "Board callers may only manage watches on their own board. Configure `authorize` to allow cross-board watch management.";
|
|
584
|
+
return `Board callers may only ${policy.kind === "schedule" ? "schedule check-ins" : "claim tasks"} on their own board. Configure \`authorizeClaim\` to allow it across boards.`;
|
|
585
|
+
}
|
|
528
586
|
}
|
|
529
587
|
}
|
|
530
|
-
async function
|
|
531
|
-
const
|
|
588
|
+
async function authorizingWatch(settings, board, action, ctx, details) {
|
|
589
|
+
const resolved = await targetBoard(settings, board, ctx, { needsMetadata: true });
|
|
590
|
+
const denial = await authorizationDenial(resolved, ctx, {
|
|
591
|
+
action,
|
|
592
|
+
details,
|
|
593
|
+
kind: "watch"
|
|
594
|
+
});
|
|
532
595
|
if (denial !== void 0) throw new Error(denial);
|
|
533
|
-
}
|
|
534
|
-
async function authorizingWatch(settings, board, action, ctx, details = {}) {
|
|
535
|
-
const resolved = targetBoard(settings, board, ctx);
|
|
536
|
-
await assertWatchAuthorized(resolved, action, ctx, details);
|
|
537
596
|
return {
|
|
538
597
|
config: resolved,
|
|
539
598
|
...boardClients(resolved)
|
|
@@ -548,9 +607,10 @@ function defineBoardWatchTool(settings) {
|
|
|
548
607
|
return defineTool({
|
|
549
608
|
approval: always(),
|
|
550
609
|
deferred: true,
|
|
551
|
-
description: "
|
|
610
|
+
description: "Create or update a board watch: from now on, every message in the channel that matches the filters wakes you in its board thread with these instructions, across conversations, cold starts, and redeploys. Pass `id` to replace an existing watch's full definition in place (preserving its ID and thread sessions) instead of creating a new one and unwatching the old one: inspect existing settings with `watches({ details: true })` first and include any `label`, `by`, `text`, or `claim` fields you want to keep. Confirm conversational vs. task-claim (`claim`) mode, filters, and `claim.from` owners when unclear before calling; the caller approves the exact watch before it is applied. Keep it as narrow as the request. Returns the watch's ID.",
|
|
552
611
|
inputSchema: z.object({
|
|
553
612
|
board: boardOption,
|
|
613
|
+
id: z.string().regex(BOARD_NAME_PATTERN).optional().describe("An existing watch's ID (such as `w-7k3p2q`) to replace its full definition in place (include any `label`, `by`, `text`, or `claim` fields to keep); omit to create a new watch."),
|
|
554
614
|
channel: z.string().min(1).max(200).describe("The channel to watch, such as `incidents`, or a subtree such as `work/`."),
|
|
555
615
|
label: z.array(z.string().min(1).max(200)).max(10).optional().describe("Labels a message must have: `key`, or `key=value`."),
|
|
556
616
|
by: z.string().min(1).max(200).optional().describe("Only messages by this handle, such as `@ada`."),
|
|
@@ -558,10 +618,11 @@ function defineBoardWatchTool(settings) {
|
|
|
558
618
|
instructions: z.string().min(1).max(BOARD_TEXT_LIMIT - 1e3).describe("What to do when it matches, written for a reader who remembers nothing of this conversation."),
|
|
559
619
|
claim: queue.optional()
|
|
560
620
|
}),
|
|
561
|
-
async execute({ board: boardKey, instructions, claim, ...filter }, ctx) {
|
|
621
|
+
async execute({ board: boardKey, id, instructions, claim, ...filter }, ctx) {
|
|
562
622
|
const { config, deployment, watchChannel } = await authorizingWatch(settings, boardKey, "watch", ctx, {
|
|
563
623
|
channel: filter.channel,
|
|
564
|
-
...claim !== void 0 && { claimChannel: claim.channel }
|
|
624
|
+
...claim !== void 0 && { claimChannel: claim.channel },
|
|
625
|
+
...id !== void 0 && { watchId: id }
|
|
565
626
|
});
|
|
566
627
|
const action = claim === void 0 ? { type: "converse" } : {
|
|
567
628
|
queue: claim,
|
|
@@ -573,16 +634,17 @@ function defineBoardWatchTool(settings) {
|
|
|
573
634
|
channel: filter.channel,
|
|
574
635
|
watchChannel
|
|
575
636
|
});
|
|
576
|
-
const
|
|
637
|
+
const input = {
|
|
577
638
|
action,
|
|
578
639
|
boardKey: config.key,
|
|
579
640
|
client: deployment,
|
|
580
|
-
id: watchIdOf(ctx.session.id, ctx.callId),
|
|
641
|
+
id: id ?? watchIdOf(ctx.session.id, ctx.callId),
|
|
581
642
|
instructions,
|
|
582
643
|
routeBase: config.registrationRouteBase,
|
|
583
644
|
tail: tailOf(filter),
|
|
584
645
|
watchChannel
|
|
585
|
-
}
|
|
646
|
+
};
|
|
647
|
+
const watch = await (id !== void 0 ? updateWatch(input) : createWatch(input));
|
|
586
648
|
return config.shorthand ? {
|
|
587
649
|
action: watch.action,
|
|
588
650
|
id: watch.id,
|
|
@@ -599,30 +661,32 @@ function defineBoardWatchTool(settings) {
|
|
|
599
661
|
function defineBoardWatchesTool(settings) {
|
|
600
662
|
return defineTool({
|
|
601
663
|
deferred: true,
|
|
602
|
-
description: "List your board watches: each one's ID and what it matches, and with `details`, what it does. Defaults to this session's board inside a board session; outside one,
|
|
664
|
+
description: "List your board watches: each one's ID and what it matches, and with `details`, what it does. Defaults to this session's board inside a board session; outside one, defaults to the team's default board (`General`) when discovery is enabled, or lists every authorized static board grouped by board when multiple static boards are configured with discovery disabled.",
|
|
603
665
|
inputSchema: z.object({
|
|
604
666
|
board: boardOption,
|
|
605
667
|
details: z.boolean().optional().describe("Also read each watch's instructions and action.")
|
|
606
668
|
}),
|
|
607
669
|
async execute({ board: boardKey, details }, ctx) {
|
|
608
|
-
const
|
|
670
|
+
const currentSettings = settings();
|
|
671
|
+
const set = resolveBoards(currentSettings);
|
|
609
672
|
const sessionKey = sessionBoard(ctx);
|
|
610
|
-
if (boardKey !== void 0 || sessionKey !== void 0 || set.byKey.size === 1) {
|
|
611
|
-
const
|
|
612
|
-
await assertWatchAuthorized(resolved, "watches", ctx);
|
|
613
|
-
const { deployment, watchChannel } = boardClients(resolved);
|
|
673
|
+
if (set.fallback !== void 0 || boardKey !== void 0 || sessionKey !== void 0 || set.byKey.size === 1) {
|
|
674
|
+
const { config, deployment, watchChannel } = await authorizingWatch(() => currentSettings, boardKey, "watches", ctx);
|
|
614
675
|
const watches = await listWatches({
|
|
615
676
|
client: deployment,
|
|
616
677
|
details: details === true,
|
|
617
678
|
watchChannel
|
|
618
679
|
});
|
|
619
|
-
return
|
|
620
|
-
board:
|
|
680
|
+
return config.shorthand ? { watches } : {
|
|
681
|
+
board: config.key,
|
|
621
682
|
watches
|
|
622
683
|
};
|
|
623
684
|
}
|
|
624
685
|
const checked = await Promise.all([...set.byKey.values()].map(async (entry) => ({
|
|
625
|
-
denial: await
|
|
686
|
+
denial: await authorizationDenial(entry, ctx, {
|
|
687
|
+
action: "watches",
|
|
688
|
+
kind: "watch"
|
|
689
|
+
}),
|
|
626
690
|
entry
|
|
627
691
|
})));
|
|
628
692
|
const permitted = checked.filter((result) => result.denial === void 0).map((result) => result.entry);
|
|
@@ -687,7 +751,7 @@ function defineBoardTasksTool(settings) {
|
|
|
687
751
|
limit: z.number().int().min(1).max(100).optional()
|
|
688
752
|
}),
|
|
689
753
|
async execute({ board: boardKey, ...query }, ctx) {
|
|
690
|
-
const page = await clientFor(settings, boardKey, ctx).client.tasks({
|
|
754
|
+
const page = await (await clientFor(settings, boardKey, ctx)).client.tasks({
|
|
691
755
|
...query,
|
|
692
756
|
limit: query.limit ?? 50
|
|
693
757
|
});
|
|
@@ -728,17 +792,21 @@ function defineBoardClaimTaskTool(settings) {
|
|
|
728
792
|
if (claimingSessions.has(ctx.session.id)) throw new Error("This session is already claiming a board task: claim one task at a time.");
|
|
729
793
|
claimingSessions.add(ctx.session.id);
|
|
730
794
|
try {
|
|
731
|
-
const resolved = targetBoard(settings, boardKey, ctx);
|
|
795
|
+
const resolved = await targetBoard(settings, boardKey, ctx, { needsMetadata: true });
|
|
732
796
|
const { deployment, model, watchChannel } = boardClients(resolved);
|
|
733
797
|
let claimChannel = channel;
|
|
734
798
|
if (id !== void 0) {
|
|
735
799
|
const { message } = await model.thread(id, { limit: 1 });
|
|
736
800
|
claimChannel = message.channel;
|
|
737
801
|
}
|
|
738
|
-
await
|
|
739
|
-
|
|
740
|
-
|
|
802
|
+
const denial = await authorizationDenial(resolved, ctx, {
|
|
803
|
+
details: {
|
|
804
|
+
...claimChannel !== void 0 && { claimChannel },
|
|
805
|
+
...id !== void 0 && { taskId: id }
|
|
806
|
+
},
|
|
807
|
+
kind: "claim"
|
|
741
808
|
});
|
|
809
|
+
if (denial !== void 0) throw new Error(denial);
|
|
742
810
|
if (channel !== void 0) checkQueueScope({
|
|
743
811
|
channel,
|
|
744
812
|
from,
|
|
@@ -806,4 +874,4 @@ function defineBoardClaimTaskTool(settings) {
|
|
|
806
874
|
}
|
|
807
875
|
});
|
|
808
876
|
}
|
|
809
|
-
export { defineBoardActorsTool, defineBoardBlockTaskTool, defineBoardCancelScheduleTool, defineBoardChannelsTool, defineBoardClaimTaskTool, defineBoardCompleteTaskTool, defineBoardCreateTaskTool, defineBoardFailTaskTool, defineBoardLabelTool, defineBoardNoteTool, defineBoardPostTool, defineBoardReactTool, defineBoardReadTool, defineBoardReleaseTaskTool, defineBoardReplyTool, defineBoardScheduleTool, defineBoardSchedulesTool, defineBoardTasksTool, defineBoardUnwatchTool, defineBoardWatchTool, defineBoardWatchesTool, holdsSessionTask, holdsTask };
|
|
877
|
+
export { defineBoardActorsTool, defineBoardBlockTaskTool, defineBoardBoardsTool, defineBoardCancelScheduleTool, defineBoardChannelsTool, defineBoardClaimTaskTool, defineBoardCompleteTaskTool, defineBoardCreateTaskTool, defineBoardFailTaskTool, defineBoardLabelTool, defineBoardNoteTool, defineBoardPostTool, defineBoardReactTool, defineBoardReadTool, defineBoardReleaseTaskTool, defineBoardReplyTool, defineBoardScheduleTool, defineBoardSchedulesTool, defineBoardTasksTool, defineBoardUnwatchTool, defineBoardWatchTool, defineBoardWatchesTool, holdsSessionTask, holdsTask };
|
|
@@ -41,7 +41,9 @@ export interface BoardWatchFilter {
|
|
|
41
41
|
export declare function tailOf({ channel, label, by, text }: BoardWatchFilter): string;
|
|
42
42
|
export declare function coversChannel(pattern: string, channel: string): boolean;
|
|
43
43
|
export declare function assertWatchId(id: string): void;
|
|
44
|
-
export type BoardClientConfig = Pick<BoardSettings, "can" | "name" | "profile" | "team" | "url" | "watchChannel"
|
|
44
|
+
export type BoardClientConfig = Pick<BoardSettings, "can" | "id" | "name" | "profile" | "team" | "url" | "watchChannel"> & {
|
|
45
|
+
readonly ensure?: boolean;
|
|
46
|
+
};
|
|
45
47
|
export declare function boardClients(settings: BoardClientConfig): {
|
|
46
48
|
deployment: BoardClient;
|
|
47
49
|
model: BoardClient;
|
|
@@ -68,7 +70,7 @@ export declare function findWatchRecord(input: {
|
|
|
68
70
|
}): Promise<BoardWatchRecord>;
|
|
69
71
|
export declare function registrationWhere(discovery: Pick<BoardDiscovery, "wake_by_path">, routeBase?: string): Omit<BoardRegistrationInput, "watch">;
|
|
70
72
|
export declare function heldRegistration(client: BoardClient): Promise<BoardRegistration | undefined>;
|
|
71
|
-
export
|
|
73
|
+
export interface BoardWatchWriteInput {
|
|
72
74
|
readonly boardKey?: string;
|
|
73
75
|
readonly client: BoardClient;
|
|
74
76
|
readonly watchChannel: string;
|
|
@@ -77,7 +79,9 @@ export declare function createWatch(input: {
|
|
|
77
79
|
readonly instructions: string;
|
|
78
80
|
readonly action: BoardWatchAction;
|
|
79
81
|
readonly routeBase?: string;
|
|
80
|
-
}
|
|
82
|
+
}
|
|
83
|
+
export declare function createWatch(input: BoardWatchWriteInput): Promise<BoardWatch>;
|
|
84
|
+
export declare function updateWatch(input: BoardWatchWriteInput): Promise<BoardWatch>;
|
|
81
85
|
export declare function listWatches(input: {
|
|
82
86
|
readonly client: BoardClient;
|
|
83
87
|
readonly watchChannel: string;
|
|
@@ -213,37 +213,42 @@ function registrationDestinationChanged(held, desired) {
|
|
|
213
213
|
if (held === void 0) return false;
|
|
214
214
|
return (held.path ?? null) !== (desired.path ?? null) || (held.branch ?? null) !== (desired.branch ?? null) || (held.url ?? null) !== (desired.url ?? null);
|
|
215
215
|
}
|
|
216
|
-
async function
|
|
216
|
+
async function writeRegistration(input) {
|
|
217
217
|
const { client } = input;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
});
|
|
218
|
+
const held = "held" in input ? input.held : await heldRegistration(client);
|
|
219
|
+
const watch = { ...held?.watch };
|
|
220
|
+
const watchChanged = input.change(watch);
|
|
221
|
+
const desired = isVercelDeployment() ? registrationWhere(await client.discovery(), input.routeBase) : void 0;
|
|
222
|
+
const destinationChanged = desired !== void 0 && registrationDestinationChanged(held, desired);
|
|
223
|
+
if (!watchChanged && !destinationChanged) return held;
|
|
224
|
+
const where = desired ?? (held !== void 0 ? {
|
|
225
|
+
branch: held.branch ?? null,
|
|
226
|
+
path: held.path ?? null,
|
|
227
|
+
url: held.url ?? null
|
|
228
|
+
} : registrationWhere(await client.discovery(), input.routeBase));
|
|
229
|
+
try {
|
|
230
|
+
return await client.register({
|
|
231
|
+
...where,
|
|
232
|
+
...held?.sync !== void 0 && { sync: held.sync },
|
|
233
|
+
watch
|
|
234
|
+
});
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (boardErrorCode(error) !== "watchers_need_project") throw error;
|
|
237
|
+
throw new Error("Vercel's board takes watches only from a deployment. To try watches locally, run `npx @vercel/board serve` and set BOARD_URL to the URL it prints.", { cause: error });
|
|
238
|
+
}
|
|
241
239
|
}
|
|
242
|
-
async function
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
async function updateRegistration(input) {
|
|
241
|
+
return await withRegistrationLock(input.client, input.watchChannel, input.boardKey ?? "default", () => writeRegistration(input));
|
|
242
|
+
}
|
|
243
|
+
function watchContent(id, action, instructions, tail) {
|
|
244
|
+
const text = watchRecordText(id, action, instructions);
|
|
245
245
|
if (text.length > 1e4) throw new Error(`These watch instructions are too long to store: shorten them by ${text.length - BOARD_TEXT_LIMIT} characters.`);
|
|
246
246
|
if (tail.length > 1e3) throw new Error(`This watch's filters are too long for the board: shorten them by ${tail.length - BOARD_TAIL_LIMIT} characters.`);
|
|
247
|
+
return text;
|
|
248
|
+
}
|
|
249
|
+
async function createWatch(input) {
|
|
250
|
+
const { action, client, id, tail } = input;
|
|
251
|
+
const text = watchContent(id, action, input.instructions, tail);
|
|
247
252
|
const held = await heldRegistration(client);
|
|
248
253
|
if (held?.watch[id] === void 0 && Object.keys(held?.watch ?? {}).length >= 64) throw tooManyWatches();
|
|
249
254
|
const record = await client.post(input.watchChannel, {
|
|
@@ -276,6 +281,52 @@ async function createWatch(input) {
|
|
|
276
281
|
tail
|
|
277
282
|
};
|
|
278
283
|
}
|
|
284
|
+
async function updateWatch(input) {
|
|
285
|
+
const { action, client, id, tail } = input;
|
|
286
|
+
assertWatchId(id);
|
|
287
|
+
const text = watchContent(id, action, input.instructions, tail);
|
|
288
|
+
return await withRegistrationLock(client, input.watchChannel, input.boardKey ?? "default", async () => {
|
|
289
|
+
const [held, self] = await Promise.all([heldRegistration(client), client.me()]);
|
|
290
|
+
if (held?.watch[id] === void 0) throw new Error(`Board watch ${id} doesn't exist on this board. Omit \`id\` to create a new watch, or call \`watches\` to list existing ones.`);
|
|
291
|
+
let existing;
|
|
292
|
+
try {
|
|
293
|
+
existing = await findWatchRecord({
|
|
294
|
+
client,
|
|
295
|
+
id,
|
|
296
|
+
self,
|
|
297
|
+
watchChannel: input.watchChannel
|
|
298
|
+
});
|
|
299
|
+
} catch (error) {
|
|
300
|
+
if (error instanceof BoardWatchConfigError) throw new Error(`Board watch ${id} has no editable instructions (${error.message}). Remove it with \`unwatch\` and omit \`id\` to create a new watch.`, { cause: error });
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
if (existing.retired) throw new Error(`Board watch ${id} is retired and can't be updated. Remove it with \`unwatch\` and omit \`id\` to create a new watch.`);
|
|
304
|
+
const previousText = existing.message.text;
|
|
305
|
+
const textChanged = previousText !== text;
|
|
306
|
+
if (textChanged) await client.edit(existing.message.id, text);
|
|
307
|
+
try {
|
|
308
|
+
await writeRegistration({
|
|
309
|
+
client,
|
|
310
|
+
held,
|
|
311
|
+
routeBase: input.routeBase,
|
|
312
|
+
change(watch) {
|
|
313
|
+
if (watch[id]?.tail === tail) return false;
|
|
314
|
+
watch[id] = { tail };
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
} catch (error) {
|
|
319
|
+
if (textChanged) await client.edit(existing.message.id, previousText).catch(() => void 0);
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
action,
|
|
324
|
+
id,
|
|
325
|
+
instructions: input.instructions,
|
|
326
|
+
tail
|
|
327
|
+
};
|
|
328
|
+
});
|
|
329
|
+
}
|
|
279
330
|
function tooManyWatches() {
|
|
280
331
|
return new Error(`This agent already has 64 board watches, the most one deployment can register. Remove one first.`);
|
|
281
332
|
}
|
|
@@ -341,4 +392,4 @@ async function removeWatch(input) {
|
|
|
341
392
|
removed
|
|
342
393
|
};
|
|
343
394
|
}
|
|
344
|
-
export { BOARD_WAKE_ROUTE, BoardWatchConfigError, DEFAULT_BOARD_ROUTE_BASE, DEFAULT_WATCH_CHANNEL, LEGACY_BOARD_WAKE_ROUTE, MAX_WATCHES, assertWatchId, boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, findWatchRecord, heldRegistration, listWatches, registrationWhere, removeWatch, tailOf, watchIdOf, watchRecordText };
|
|
395
|
+
export { BOARD_WAKE_ROUTE, BoardWatchConfigError, DEFAULT_BOARD_ROUTE_BASE, DEFAULT_WATCH_CHANNEL, LEGACY_BOARD_WAKE_ROUTE, MAX_WATCHES, assertWatchId, boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, findWatchRecord, heldRegistration, listWatches, registrationWhere, removeWatch, tailOf, updateWatch, watchIdOf, watchRecordText };
|