@eve/board 0.0.0 → 0.1.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 (66) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +101 -0
  3. package/README.md +36 -2
  4. package/dist/extension/_manifest.json +6 -0
  5. package/dist/extension/channels/board.d.ts +2 -0
  6. package/dist/extension/channels/board.mjs +9 -0
  7. package/dist/extension/extension.d.ts +29 -0
  8. package/dist/extension/extension.mjs +19 -0
  9. package/dist/extension/instructions.md +9 -0
  10. package/dist/extension/lib/board-channel.d.ts +91 -0
  11. package/dist/extension/lib/board-channel.mjs +478 -0
  12. package/dist/extension/lib/channel.d.ts +11 -0
  13. package/dist/extension/lib/channel.mjs +12 -0
  14. package/dist/extension/lib/client.d.ts +253 -0
  15. package/dist/extension/lib/client.mjs +350 -0
  16. package/dist/extension/lib/inbound.d.ts +19 -0
  17. package/dist/extension/lib/inbound.mjs +93 -0
  18. package/dist/extension/lib/tools.d.ts +504 -0
  19. package/dist/extension/lib/tools.mjs +457 -0
  20. package/dist/extension/lib/watches.d.ts +89 -0
  21. package/dist/extension/lib/watches.mjs +310 -0
  22. package/dist/extension/skills/collaborate/SKILL.md +54 -0
  23. package/dist/extension/tools/actors.d.ts +9 -0
  24. package/dist/extension/tools/actors.mjs +10 -0
  25. package/dist/extension/tools/block_task.d.ts +3 -0
  26. package/dist/extension/tools/block_task.mjs +10 -0
  27. package/dist/extension/tools/cancel_schedule.d.ts +7 -0
  28. package/dist/extension/tools/cancel_schedule.mjs +10 -0
  29. package/dist/extension/tools/channels.d.ts +5 -0
  30. package/dist/extension/tools/channels.mjs +10 -0
  31. package/dist/extension/tools/complete_task.d.ts +3 -0
  32. package/dist/extension/tools/complete_task.mjs +10 -0
  33. package/dist/extension/tools/create_task.d.ts +27 -0
  34. package/dist/extension/tools/create_task.mjs +10 -0
  35. package/dist/extension/tools/fail_task.d.ts +3 -0
  36. package/dist/extension/tools/fail_task.mjs +10 -0
  37. package/dist/extension/tools/label.d.ts +10 -0
  38. package/dist/extension/tools/label.mjs +10 -0
  39. package/dist/extension/tools/no_reply.d.ts +1 -0
  40. package/dist/extension/tools/no_reply.mjs +7 -0
  41. package/dist/extension/tools/note.d.ts +25 -0
  42. package/dist/extension/tools/note.mjs +10 -0
  43. package/dist/extension/tools/post.d.ts +55 -0
  44. package/dist/extension/tools/post.mjs +10 -0
  45. package/dist/extension/tools/react.d.ts +17 -0
  46. package/dist/extension/tools/react.mjs +10 -0
  47. package/dist/extension/tools/read.d.ts +187 -0
  48. package/dist/extension/tools/read.mjs +10 -0
  49. package/dist/extension/tools/reply.d.ts +55 -0
  50. package/dist/extension/tools/reply.mjs +10 -0
  51. package/dist/extension/tools/schedule.d.ts +16 -0
  52. package/dist/extension/tools/schedule.mjs +10 -0
  53. package/dist/extension/tools/schedules.d.ts +8 -0
  54. package/dist/extension/tools/schedules.mjs +10 -0
  55. package/dist/extension/tools/unwatch.d.ts +8 -0
  56. package/dist/extension/tools/unwatch.mjs +10 -0
  57. package/dist/extension/tools/watch.d.ts +18 -0
  58. package/dist/extension/tools/watch.mjs +10 -0
  59. package/dist/extension/tools/watches.d.ts +7 -0
  60. package/dist/extension/tools/watches.mjs +10 -0
  61. package/dist/index.d.ts +4 -0
  62. package/dist/index.mjs +7 -0
  63. package/dist/tools/index.d.ts +21 -0
  64. package/dist/tools/index.mjs +26 -0
  65. package/package.json +65 -14
  66. package/index.js +0 -1
@@ -0,0 +1,253 @@
1
+ import type extension from "../extension.ts";
2
+ export interface BoardAuthor {
3
+ readonly actor: string;
4
+ readonly principal: string;
5
+ readonly profile: string | null;
6
+ }
7
+ export interface BoardActor {
8
+ readonly kind: string;
9
+ readonly handle: string;
10
+ readonly name: string;
11
+ }
12
+ export interface BoardAttachment {
13
+ readonly id: string;
14
+ readonly name: string;
15
+ readonly type: string;
16
+ readonly size: number;
17
+ }
18
+ export interface BoardTaskState {
19
+ readonly state: string;
20
+ readonly owner: string;
21
+ readonly claim: {
22
+ readonly actor: string;
23
+ readonly until: string;
24
+ } | null;
25
+ readonly blocked: {
26
+ readonly kind: string | null;
27
+ readonly reason: string;
28
+ } | null;
29
+ readonly result: string | null;
30
+ readonly reason: string | null;
31
+ }
32
+ export interface BoardMessage {
33
+ readonly id: string;
34
+ readonly channel: string;
35
+ readonly text: string;
36
+ readonly re: string | null;
37
+ readonly thread: string;
38
+ readonly labels: Readonly<Record<string, string>>;
39
+ readonly by: BoardAuthor;
40
+ readonly author: BoardActor | null;
41
+ readonly attachments: readonly BoardAttachment[];
42
+ readonly createdAt: string;
43
+ readonly deleted: boolean;
44
+ readonly noSync: boolean;
45
+ readonly schedule?: {
46
+ readonly id: string;
47
+ readonly n: number;
48
+ };
49
+ readonly task?: BoardTaskState;
50
+ }
51
+ export interface BoardWrittenMessage extends BoardMessage {
52
+ readonly unknownMentions?: readonly string[];
53
+ }
54
+ export interface BoardThread {
55
+ readonly message: BoardMessage;
56
+ readonly replies: readonly BoardMessage[];
57
+ }
58
+ export interface BoardThreadSummary {
59
+ readonly message: BoardMessage;
60
+ readonly replies: number;
61
+ readonly last: BoardMessage | null;
62
+ }
63
+ export interface BoardChannelSummary {
64
+ readonly path: string;
65
+ }
66
+ export interface BoardThreadsQuery {
67
+ readonly channel?: string;
68
+ readonly label?: readonly string[];
69
+ readonly after?: string;
70
+ readonly before?: string;
71
+ readonly limit?: number;
72
+ }
73
+ export interface BoardThreadsPage {
74
+ readonly threads: readonly BoardThreadSummary[];
75
+ readonly cursor: string;
76
+ readonly older: string | null;
77
+ }
78
+ export interface BoardActorSummary {
79
+ readonly id: string;
80
+ readonly handle: string;
81
+ readonly name: string;
82
+ readonly kind: string;
83
+ }
84
+ export interface BoardPostOptions {
85
+ readonly text: string;
86
+ readonly labels?: Readonly<Record<string, string>>;
87
+ readonly noSync?: boolean;
88
+ readonly id?: string;
89
+ readonly attachments?: readonly string[];
90
+ readonly after?: string;
91
+ }
92
+ export interface BoardScheduleOptions {
93
+ readonly text: string;
94
+ readonly noSync?: boolean;
95
+ readonly in?: string;
96
+ readonly at?: string;
97
+ readonly every?: string;
98
+ readonly times?: number;
99
+ readonly until?: string;
100
+ }
101
+ export interface BoardSchedule {
102
+ readonly id: string;
103
+ readonly channel: string;
104
+ readonly re: string | null;
105
+ readonly text: string;
106
+ readonly next: string | null;
107
+ readonly state: string;
108
+ }
109
+ export interface BoardClaim {
110
+ readonly taskId: string;
111
+ readonly epoch: number;
112
+ readonly token: string;
113
+ readonly until: string;
114
+ }
115
+ export interface BoardClaimedTask extends BoardClaim {
116
+ readonly task: BoardMessage;
117
+ }
118
+ export interface BoardHeldTask {
119
+ renew(lease?: number): Promise<string>;
120
+ release(): Promise<void>;
121
+ complete(result?: string): Promise<void>;
122
+ fail(reason: string): Promise<void>;
123
+ block(reason: string, options?: {
124
+ readonly kind?: string;
125
+ }): Promise<void>;
126
+ }
127
+ export interface BoardReadyTaskQuery {
128
+ readonly channel: string;
129
+ readonly label?: Readonly<Record<string, string>>;
130
+ readonly from?: readonly string[];
131
+ readonly lease?: number;
132
+ }
133
+ export interface BoardNewTask {
134
+ readonly text: string;
135
+ readonly labels?: Readonly<Record<string, string>>;
136
+ readonly needs?: readonly string[];
137
+ readonly noSync?: boolean;
138
+ readonly id?: string;
139
+ }
140
+ export interface BoardEvent {
141
+ readonly cursor: string;
142
+ readonly type: string;
143
+ readonly createdAt: string;
144
+ readonly message?: BoardMessage;
145
+ }
146
+ export interface BoardMatch {
147
+ readonly id: string;
148
+ readonly watcher: string;
149
+ readonly lease: string;
150
+ readonly attempt: number;
151
+ readonly event: BoardEvent;
152
+ }
153
+ export interface BoardSyncEntry {
154
+ readonly key: string;
155
+ readonly platform: string;
156
+ }
157
+ export interface BoardRegistrationInput {
158
+ readonly url?: string | null;
159
+ readonly path?: string | null;
160
+ readonly branch?: string | null;
161
+ readonly watch: Readonly<Record<string, {
162
+ readonly tail: string;
163
+ }>>;
164
+ readonly sync?: readonly BoardSyncEntry[];
165
+ }
166
+ export interface BoardRegistration extends BoardRegistrationInput {
167
+ readonly owner: string;
168
+ readonly hash: string;
169
+ }
170
+ export interface BoardDiscovery {
171
+ readonly url: string;
172
+ readonly wake_by_path?: boolean;
173
+ }
174
+ export type BoardCan = "all" | readonly BoardPermission[] | Readonly<Record<string, "all" | readonly BoardPermission[]>>;
175
+ export declare const BOARD_PERMISSIONS: readonly ["read", "post", "react", "label", "sync", "manage"];
176
+ export type BoardPermission = (typeof BOARD_PERMISSIONS)[number];
177
+ export interface BoardClient {
178
+ readonly profile: string;
179
+ discovery(): Promise<BoardDiscovery>;
180
+ me(): Promise<{
181
+ readonly principal: string;
182
+ readonly actor: string;
183
+ }>;
184
+ watchers(): Promise<readonly BoardRegistration[]>;
185
+ register(input: BoardRegistrationInput): Promise<BoardRegistration>;
186
+ matches(options?: {
187
+ readonly limit?: number;
188
+ readonly wait?: number;
189
+ }): Promise<readonly BoardMatch[]>;
190
+ ack(match: BoardMatch, outcome?: {
191
+ readonly error?: string;
192
+ readonly skip?: boolean;
193
+ }): Promise<void>;
194
+ post(channel: string, options: BoardPostOptions): Promise<BoardWrittenMessage>;
195
+ reply(id: string, options: BoardPostOptions): Promise<BoardWrittenMessage>;
196
+ upload(file: {
197
+ readonly data: Uint8Array;
198
+ readonly name: string;
199
+ readonly type?: string;
200
+ }): Promise<BoardAttachment>;
201
+ react(id: string, emoji: string, options?: {
202
+ readonly remove?: boolean;
203
+ }): Promise<void>;
204
+ label(id: string, change: {
205
+ readonly set?: Record<string, string>;
206
+ readonly unset?: readonly string[];
207
+ readonly if?: Readonly<Record<string, string | null>>;
208
+ }): Promise<void>;
209
+ typing(id: string, status?: string): Promise<void>;
210
+ thread(id: string, range?: {
211
+ readonly after?: string;
212
+ }): Promise<BoardThread>;
213
+ linked(url: string): Promise<BoardThread>;
214
+ threads(query?: BoardThreadsQuery): Promise<readonly BoardThreadSummary[]>;
215
+ threadsPage(query?: BoardThreadsQuery): Promise<BoardThreadsPage>;
216
+ schedules(query?: {
217
+ readonly re?: string;
218
+ readonly channel?: string;
219
+ readonly by?: string;
220
+ }): Promise<readonly BoardSchedule[]>;
221
+ actors(): Promise<readonly BoardActorSummary[]>;
222
+ channels(): Promise<readonly BoardChannelSummary[]>;
223
+ download(attachmentId: string): Promise<Response>;
224
+ schedule(target: {
225
+ readonly re: string;
226
+ } | {
227
+ readonly channel: string;
228
+ }, options: BoardScheduleOptions): Promise<BoardSchedule>;
229
+ cancelSchedule(id: string): Promise<{
230
+ readonly canceled: boolean;
231
+ }>;
232
+ claimReady(query: BoardReadyTaskQuery): Promise<BoardClaimedTask | null>;
233
+ claim(taskId: string, lease?: number): Promise<BoardClaimedTask>;
234
+ held(claim: BoardClaim): BoardHeldTask;
235
+ createTask(channel: string, task: BoardNewTask): Promise<BoardMessage>;
236
+ }
237
+ /** Which board the agent reads and writes, and as whom. */
238
+ export type BoardSettings = Readonly<typeof extension.config>;
239
+ export declare const BOARD_TEXT_LIMIT = 10000;
240
+ export declare const BOARD_TAIL_LIMIT = 1000;
241
+ export declare const BOARD_UPLOAD_LIMIT: number;
242
+ export declare const BOARD_NAME_PATTERN: RegExp;
243
+ export declare const BOARD_CHANNEL_SELECTOR: RegExp;
244
+ export declare const BOARD_TASK_NOTE_LIMIT = 1000;
245
+ export declare const BOARD_HOLD_KIND_PATTERN: RegExp;
246
+ export declare const DEFAULT_BOARD_PROFILE = "eve";
247
+ export declare function boardPostId(key: string): string;
248
+ export declare function boardAllows(can: BoardCan | undefined, channel: string, permission: string): boolean;
249
+ export declare function boardErrorCode(error: unknown): string | undefined;
250
+ type BoardRef = Pick<BoardSettings, "name" | "team" | "profile">;
251
+ export declare function createBoardClient(board: BoardRef, can?: BoardCan): BoardClient;
252
+ export declare function withHints<T extends object>(target: T): T;
253
+ export {};
@@ -0,0 +1,350 @@
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 { createHash } from "node:crypto";
8
+ import { board } from "@vercel/board";
9
+ import { compileAccess } from "@vercel/board/access";
10
+ const BOARD_PERMISSIONS = [
11
+ "read",
12
+ "post",
13
+ "react",
14
+ "label",
15
+ "sync",
16
+ "manage"
17
+ ];
18
+ const BOARD_TEXT_LIMIT = 1e4;
19
+ const BOARD_TAIL_LIMIT = 1e3;
20
+ const BOARD_UPLOAD_LIMIT = 4194304;
21
+ const BOARD_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9-]{0,31}$/u;
22
+ const BOARD_CHANNEL_SELECTOR = /^[a-z0-9][a-z0-9_-]*(?:\/[a-z0-9][a-z0-9_-]*)*\/?$/u;
23
+ const BOARD_TASK_NOTE_LIMIT = 1e3;
24
+ const BOARD_HOLD_KIND_PATTERN = /^[a-z0-9][a-z0-9_.-]{0,63}$/u;
25
+ const DEFAULT_BOARD_PROFILE = "eve";
26
+ function boardPostId(key) {
27
+ return `eve-${createHash("sha256").update(key).digest("hex").slice(0, 32)}`;
28
+ }
29
+ function boardAllows(can, channel, permission) {
30
+ if (can === void 0 || can === "all") return true;
31
+ const access = compileAccess(can);
32
+ const name = permission;
33
+ return channel.endsWith("/") ? access.at(name, channel) : access.can(name, channel);
34
+ }
35
+ function boardErrorCode(error) {
36
+ if (typeof error !== "object" || error === null) return void 0;
37
+ const code = error.code;
38
+ return typeof code === "string" ? code : void 0;
39
+ }
40
+ const handles = new Map();
41
+ const principals = new Map();
42
+ function handleKey({ name, team }) {
43
+ return JSON.stringify([
44
+ name ?? null,
45
+ team ?? null,
46
+ process.env.BOARD_URL?.trim() || null,
47
+ process.env.BOARD_TOKEN ?? null
48
+ ]);
49
+ }
50
+ function createBoardClient(board$1, can) {
51
+ const profile = (board$1.profile ?? "eve").toLowerCase();
52
+ if (!BOARD_NAME_PATTERN.test(profile)) throw new Error(`Board profile "${board$1.profile}" is invalid: use a letter, then up to 31 letters, numbers, or hyphens.`);
53
+ const key = handleKey(board$1);
54
+ let base = handles.get(key);
55
+ if (base === void 0) {
56
+ const { name, team } = board$1;
57
+ base = board({
58
+ ...name !== void 0 && { name },
59
+ ...team !== void 0 && { team }
60
+ });
61
+ handles.set(key, base);
62
+ }
63
+ const handle = withHints(base.as(profile, can === void 0 ? void 0 : { can }));
64
+ const meKey = `${key}\n${profile}`;
65
+ const held = (claim) => {
66
+ const task = handle.tasks.held(claim.taskId, {
67
+ epoch: claim.epoch,
68
+ token: claim.token
69
+ });
70
+ return {
71
+ renew: async (lease) => (await task.renew(lease)).until,
72
+ release: async () => void await task.release(),
73
+ complete: async (result) => void await task.complete(result),
74
+ fail: async (reason) => void await task.fail(reason),
75
+ block: async (reason, options) => void await task.block(reason, options?.kind === void 0 ? void 0 : { kind: options.kind })
76
+ };
77
+ };
78
+ async function threadsPage(query = {}) {
79
+ const page = await handle.threads({
80
+ ...query,
81
+ ...query.label !== void 0 && { label: [...query.label] }
82
+ });
83
+ return {
84
+ cursor: page.cursor,
85
+ older: page.older ?? null,
86
+ threads: page.threads.map((summary) => ({
87
+ last: summary.last === null ? null : messageOf(summary.last),
88
+ message: messageOf(summary.message),
89
+ replies: summary.replies
90
+ }))
91
+ };
92
+ }
93
+ return {
94
+ profile,
95
+ discovery: async () => await handle.discovery(),
96
+ me: () => {
97
+ let me = principals.get(meKey);
98
+ if (me === void 0) {
99
+ me = handle.me().then(({ actor, principal }) => ({
100
+ actor,
101
+ principal
102
+ }), (error) => {
103
+ principals.delete(meKey);
104
+ throw error;
105
+ });
106
+ principals.set(meKey, me);
107
+ }
108
+ return me;
109
+ },
110
+ watchers: async () => (await handle.watchers()).map(registrationOf),
111
+ async register(input) {
112
+ const watch = Object.fromEntries(Object.entries(input.watch).map(([name, { tail }]) => [name, { tail }]));
113
+ const where = input.path ? {
114
+ branch: input.branch ?? null,
115
+ path: input.path
116
+ } : { url: input.url ?? null };
117
+ const sync = input.sync?.map(({ key, platform }) => ({
118
+ key,
119
+ platform
120
+ }));
121
+ return registrationOf(await handle.register({
122
+ ...where,
123
+ watch,
124
+ ...sync !== void 0 && { sync }
125
+ }));
126
+ },
127
+ matches: async (options = {}) => (await handle.matches({
128
+ ...options.limit !== void 0 && { limit: options.limit },
129
+ ...options.wait !== void 0 && { wait: options.wait }
130
+ })).map(matchOf),
131
+ async ack(match, outcome = {}) {
132
+ await handle.ack(match.id, {
133
+ lease: match.lease,
134
+ ...outcome.error !== void 0 && { error: outcome.error.slice(0, 500) },
135
+ ...outcome.skip === true && { skip: true }
136
+ });
137
+ },
138
+ post: async (channel, post) => writtenOf(await handle.post(channel, postOf(post))),
139
+ reply: async (id, post) => writtenOf(await handle.reply(id, postOf(post))),
140
+ upload: async (file) => await handle.upload({
141
+ data: file.data,
142
+ name: file.name,
143
+ ...file.type !== void 0 && { type: file.type }
144
+ }),
145
+ async react(id, emoji, reaction = {}) {
146
+ await handle.react(id, emoji, reaction.remove === true ? { remove: true } : {});
147
+ },
148
+ async label(id, change) {
149
+ await handle.label(id, {
150
+ ...change.set !== void 0 && { set: change.set },
151
+ ...change.unset !== void 0 && { unset: [...change.unset] },
152
+ ...change.if !== void 0 && { if: { ...change.if } }
153
+ });
154
+ },
155
+ async typing(id, status) {
156
+ await handle.typing(id, status === void 0 ? void 0 : status.slice(0, 50));
157
+ },
158
+ thread: async (id, range = {}) => threadOf(await handle.thread(id, range.after === void 0 ? {} : { after: range.after })),
159
+ linked: async (url) => threadOf(await handle.linked(url)),
160
+ async threads(query = {}) {
161
+ return (await threadsPage(query)).threads;
162
+ },
163
+ threadsPage,
164
+ async schedules(query = {}) {
165
+ return (await handle.schedules({ ...query })).map(scheduleOf);
166
+ },
167
+ async actors() {
168
+ return (await handle.actors()).map((actor) => ({
169
+ handle: actor.handle,
170
+ id: actor.id,
171
+ kind: actor.kind,
172
+ name: actor.name
173
+ }));
174
+ },
175
+ channels: async () => (await handle.channels()).channels.map((channel) => ({ path: channel.path })),
176
+ download: async (attachmentId) => await handle.download(attachmentId),
177
+ async schedule(target, options) {
178
+ return scheduleOf(await handle.schedule("re" in target ? { re: target.re } : target.channel, {
179
+ text: options.text,
180
+ ...options.noSync !== void 0 && { noSync: options.noSync },
181
+ ...options.in !== void 0 && { in: options.in },
182
+ ...options.at !== void 0 && { at: options.at },
183
+ ...options.every !== void 0 && { every: options.every },
184
+ ...options.times !== void 0 && { times: options.times },
185
+ ...options.until !== void 0 && { until: options.until }
186
+ }));
187
+ },
188
+ async cancelSchedule(id) {
189
+ const { canceled } = await handle.cancelSchedule(id);
190
+ return { canceled };
191
+ },
192
+ async claimReady(query) {
193
+ const claim = await handle.tasks.claim({
194
+ channel: query.channel,
195
+ ...query.label !== void 0 && { label: { ...query.label } },
196
+ ...query.from !== void 0 && query.from.length > 0 && { from: [...query.from] },
197
+ ...query.lease !== void 0 && { lease: query.lease }
198
+ });
199
+ return claim === null ? null : claimedOf(claim);
200
+ },
201
+ claim: async (taskId, lease) => claimedOf(await handle.tasks.claim(taskId, lease === void 0 ? {} : { lease })),
202
+ held,
203
+ async createTask(channel, task) {
204
+ return messageOf((await handle.tasks.create(channel, {
205
+ text: task.text,
206
+ ...task.labels !== void 0 && { labels: { ...task.labels } },
207
+ ...task.needs !== void 0 && { needs: [...task.needs] },
208
+ ...task.noSync !== void 0 && { noSync: task.noSync },
209
+ ...task.id !== void 0 && { id: task.id }
210
+ })).task);
211
+ }
212
+ };
213
+ }
214
+ function claimedOf(claim) {
215
+ const { epoch, token, until } = claim;
216
+ return {
217
+ epoch,
218
+ task: messageOf(claim.task),
219
+ taskId: claim.task.id,
220
+ token,
221
+ until
222
+ };
223
+ }
224
+ function postOf(post) {
225
+ return {
226
+ text: post.text,
227
+ ...post.labels !== void 0 && { labels: { ...post.labels } },
228
+ ...post.noSync !== void 0 && { noSync: post.noSync },
229
+ ...post.id !== void 0 && { id: post.id },
230
+ ...post.attachments !== void 0 && { attachments: [...post.attachments] },
231
+ ...post.after !== void 0 && { after: post.after }
232
+ };
233
+ }
234
+ function withHints(target) {
235
+ return new Proxy(target, { get(object, key) {
236
+ const value = Reflect.get(object, key);
237
+ if (typeof value === "function") return (...args) => {
238
+ const result = Reflect.apply(value, object, args);
239
+ if (result instanceof Promise) return result.catch((error) => Promise.reject(hinted(error)));
240
+ return typeof result === "object" && result !== null ? withHints(result) : result;
241
+ };
242
+ return typeof value === "object" && value !== null ? withHints(value) : value;
243
+ } });
244
+ }
245
+ function hinted(error) {
246
+ if (!(error instanceof Error)) return error;
247
+ const hint = error.hint;
248
+ if (typeof hint === "string" && hint.length > 0 && !error.message.includes(hint)) error.message = `${error.message} ${hint}`;
249
+ return error;
250
+ }
251
+ function messageOf(view) {
252
+ const { author, by, schedule, task } = view;
253
+ return {
254
+ attachments: view.attachments.map(({ id, name, size, type }) => ({
255
+ id,
256
+ name,
257
+ size,
258
+ type
259
+ })),
260
+ author: author === null ? null : {
261
+ handle: author.handle,
262
+ kind: author.kind,
263
+ name: author.name
264
+ },
265
+ by: {
266
+ actor: by.actor,
267
+ principal: by.principal,
268
+ profile: by.profile
269
+ },
270
+ channel: view.channel,
271
+ createdAt: view.createdAt,
272
+ deleted: view.deleted,
273
+ id: view.id,
274
+ labels: { ...view.labels },
275
+ noSync: view.noSync === true,
276
+ re: view.re,
277
+ text: view.text,
278
+ thread: view.thread,
279
+ ...schedule !== void 0 && { schedule: {
280
+ id: schedule.id,
281
+ n: schedule.n
282
+ } },
283
+ ...task !== void 0 && { task: {
284
+ blocked: task.blocked === null ? null : {
285
+ kind: task.blocked.kind,
286
+ reason: task.blocked.reason
287
+ },
288
+ claim: task.claim === null ? null : {
289
+ actor: task.claim.actor,
290
+ until: task.claim.until
291
+ },
292
+ owner: task.owner,
293
+ reason: task.reason,
294
+ result: task.result,
295
+ state: task.state
296
+ } }
297
+ };
298
+ }
299
+ function writtenOf(written) {
300
+ const unknown = (written.mentions ?? []).filter((mention) => mention.actor === null).map((mention) => mention.written.replace(/^@/u, ""));
301
+ return unknown.length === 0 ? messageOf(written) : {
302
+ ...messageOf(written),
303
+ unknownMentions: unknown
304
+ };
305
+ }
306
+ function threadOf(view) {
307
+ return {
308
+ message: messageOf(view.message),
309
+ replies: view.replies.map(messageOf)
310
+ };
311
+ }
312
+ function matchOf(match) {
313
+ return {
314
+ attempt: match.attempt,
315
+ event: {
316
+ createdAt: match.event.createdAt,
317
+ cursor: match.event.cursor,
318
+ type: match.event.type,
319
+ ...match.event.message !== void 0 && { message: messageOf(match.event.message) }
320
+ },
321
+ id: match.id,
322
+ lease: match.lease,
323
+ watcher: match.watcher
324
+ };
325
+ }
326
+ function registrationOf(registration) {
327
+ return {
328
+ hash: registration.hash,
329
+ owner: registration.owner,
330
+ sync: (registration.sync ?? []).map(({ key, platform }) => ({
331
+ key,
332
+ platform
333
+ })),
334
+ url: registration.url,
335
+ ...registration.path !== void 0 && { path: registration.path },
336
+ ...registration.branch !== void 0 && { branch: registration.branch },
337
+ watch: registration.watch
338
+ };
339
+ }
340
+ function scheduleOf(schedule) {
341
+ return {
342
+ channel: schedule.channel,
343
+ id: schedule.id,
344
+ next: schedule.next,
345
+ re: schedule.re,
346
+ state: schedule.state,
347
+ text: schedule.text
348
+ };
349
+ }
350
+ export { BOARD_CHANNEL_SELECTOR, BOARD_HOLD_KIND_PATTERN, BOARD_NAME_PATTERN, BOARD_PERMISSIONS, BOARD_TAIL_LIMIT, BOARD_TASK_NOTE_LIMIT, BOARD_TEXT_LIMIT, BOARD_UPLOAD_LIMIT, DEFAULT_BOARD_PROFILE, boardAllows, boardErrorCode, boardPostId, createBoardClient, withHints };
@@ -0,0 +1,19 @@
1
+ import type { FetchFileResult, MessageContent } from "eve/channels";
2
+ import type { SessionAuthContext } from "eve/context";
3
+ import type { BoardClaimedTask, BoardClient, BoardMessage } from "./client.ts";
4
+ export declare function boardThreadId(message: Pick<BoardMessage, "id" | "re">): string;
5
+ export declare function boardSessionAddress(watch: string, message: Pick<BoardMessage, "thread">): string;
6
+ export declare function defaultBoardAuth(message: BoardMessage, board: {
7
+ readonly name?: string;
8
+ readonly watch?: string;
9
+ }): SessionAuthContext;
10
+ export declare function authorOf(message: BoardMessage): string;
11
+ export declare function formatWatchContext(watch: {
12
+ readonly id: string;
13
+ readonly instructions: string;
14
+ }): string;
15
+ export declare function formatBoardContext(message: BoardMessage): string;
16
+ export declare function formatTaskContext(claim: BoardClaimedTask): string;
17
+ export declare function formatTaskFollowUpContext(message: BoardMessage): string;
18
+ export declare function boardMessageContent(message: BoardMessage): MessageContent;
19
+ export declare function fetchBoardAttachment(url: string, client: BoardClient, maxBytes: number): Promise<FetchFileResult | null>;