@vercel/board 0.18.1 → 0.19.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/{a2-CW8jHGD_.mjs → a2-C1obi0Qb.mjs} +2 -1
- package/dist/{backend-B-SJ7p6p.d.mts → backend-B5GCP1oK.d.mts} +1 -1
- package/dist/backend-a2.d.mts +4 -2
- package/dist/backend-a2.mjs +1 -1
- package/dist/{backend-http-CDDS7MLI.mjs → backend-http-BMVDbtD_.mjs} +19 -4
- package/dist/{backend-http-7cNb8nJI.d.mts → backend-http-Ca6b0FPA.d.mts} +4 -2
- package/dist/{backend-http-BjH8jMDi.mjs → backend-http-DMpQ750P.mjs} +1 -1
- package/dist/backend-http.d.mts +1 -1
- package/dist/backend-http.mjs +1 -1
- package/dist/backend-http.node.d.mts +1 -1
- package/dist/backend-http.node.mjs +1 -1
- package/dist/{chat-provider-DNJQyajS.d.mts → chat-provider-B5uCc0an.d.mts} +1 -1
- package/dist/cli.mjs +5 -5
- package/dist/{conformance-CT5EeHeC.mjs → conformance-D0Z4dXC_.mjs} +46 -5
- package/dist/conformance.d.mts +1 -1
- package/dist/conformance.mjs +1 -1
- package/dist/exports-B3AFzT_f.d.mts +4 -0
- package/dist/{exports-CwsfgCul.mjs → exports-CUGshfRF.mjs} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/{index.default-jkA7eFFe.mjs → index.default-Cm6GsLdj.mjs} +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.node.d.mts +3 -3
- package/dist/index.node.mjs +1 -1
- package/dist/inspect/app.js +2 -2
- package/dist/{provider-B0b9Qxw4.d.mts → provider-B1Z3Ok86.d.mts} +16 -1
- package/dist/{serve-Dpb7zMJ0.mjs → serve-DB9ijyQ7.mjs} +3 -3
- package/dist/{server-Bj1_ugXd.mjs → server-BujqWBP5.mjs} +2 -2
- package/dist/sync-github.d.mts +2 -2
- package/dist/sync-kapso.d.mts +2 -2
- package/dist/sync-linear.d.mts +2 -2
- package/dist/sync-slack.d.mts +2 -2
- package/dist/sync.chat.d.mts +1 -1
- package/dist/sync.d.mts +1 -1
- package/dist/{watchers-hash-qlnbKQQ0.mjs → watchers-hash-B2TevhFZ.mjs} +20 -2
- package/docs/01-board/06-watchers.md +7 -0
- package/docs/04-reference/01-cli.md +2 -1
- package/docs/04-reference/03-http.md +4 -2
- package/package.json +1 -1
- package/dist/exports-ZsgjzEnM.d.mts +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as DIRECT_UPLOAD_BYTES_MAX, r as IMPORT_BYTES_MAX, t as ATTACHMENT_BYTES_MAX } from "./files-SniSmeEr.mjs";
|
|
2
2
|
import { _ as RemoteWatcherId, b as actorKind, i as Attachment, x as platformAvatar } from "./schemas-Be08nyfW.mjs";
|
|
3
3
|
import "./external-BV_cUncs.mjs";
|
|
4
|
-
import { f as VERSION, n as compileWatcher, o as METHODS, p as SYNC, r as hasCriteria, t as canonicalWatchers } from "./watchers-hash-
|
|
4
|
+
import { f as VERSION, n as compileWatcher, o as METHODS, p as SYNC, r as hasCriteria, t as canonicalWatchers } from "./watchers-hash-B2TevhFZ.mjs";
|
|
5
5
|
import { r as duration, t as BoardError } from "./client-BA-J7usH.mjs";
|
|
6
6
|
import { n as derivedId, r as isKeyIdOf } from "./ids-C6AYo1bu.mjs";
|
|
7
7
|
import { a as forbidden, c as toErrorResponse, i as duplicateId, r as badRequest, s as notFound, t as HttpError } from "./errors-DX3hpwWt.mjs";
|
|
@@ -3081,6 +3081,7 @@ function build(options, binding) {
|
|
|
3081
3081
|
return { watchers: principal.access.everywhere("manage") ? all : all.filter((found) => found.owner === principal.id) };
|
|
3082
3082
|
},
|
|
3083
3083
|
async register(caller, body) {
|
|
3084
|
+
if (body.path) throw new HttpError(501, "no_wake_by_path", "this board wakes a url, not a path: register `url` instead");
|
|
3084
3085
|
const { principal } = await identityOf(caller);
|
|
3085
3086
|
ownWatchers(principal);
|
|
3086
3087
|
if (!principal.access.anywhere("read")) throw forbidden("this token can't read anywhere, so a watcher it registers would see nothing");
|
|
@@ -2,7 +2,7 @@ import { t as Access } from "./access-CV96SYgr.mjs";
|
|
|
2
2
|
import { m as RuleFunction, n as AccessRule, r as Authenticate, s as Granted, t as AccessFunction, u as Known } from "./auth-CU56Q2Xh.mjs";
|
|
3
3
|
import { i as Attachment, o as Author, p as Labels } from "./schemas-CWxs3ECJ.mjs";
|
|
4
4
|
import { t as Actor, u as ExternalEvent } from "./folds-CRYY14kc.mjs";
|
|
5
|
-
import { $ as Discovery, Et as PostBody, F as BoardClient, Ft as ScheduleBody, Gt as SourceReadQuery, Kt as SyncAccountBody, Mt as RegistrationView, Qt as SyncCopiesView, Rt as ScheduleView, St as MessagesQuery, Tt as PersonView, Wt as SourceRead, X as BoardEventView, Xt as SyncCodeView, Yt as SyncCodeBody, Z as ChannelView, Zt as SyncCopiesQuery, _n as UploadStartBody, _t as MatchView, bt as MessageView, cn as SyncUnlinkBody, ct as InboxEntry, dn as ThreadView, dt as InboxPushBody, en as SyncFindQuery, et as EditBody, fn as ThreadsPage, ft as InboxQuery, gt as LinkedQuery, hn as TypingBody, ht as LinkedAccount, in as SyncReceiptBody, jt as RegisterBody, kt as ReactBody, ln as SyncedView, lt as InboxItem, nn as SyncImportBody, nt as EventsQuery, on as SyncRootsQuery, ot as IdentityView, p as SyncProvider, pn as ThreadsQuery, pt as LabelBody, q as AckBody, sn as SyncThreadView, st as InboxAckBody, tn as SyncFindView, tt as EventsPage, ut as InboxNextQuery, vn as UploadTicket, vt as MatchesQuery, xt as MessagesPage, yt as Me, z as ProfileOption, zt as SchedulesQuery } from "./provider-
|
|
5
|
+
import { $ as Discovery, Et as PostBody, F as BoardClient, Ft as ScheduleBody, Gt as SourceReadQuery, Kt as SyncAccountBody, Mt as RegistrationView, Qt as SyncCopiesView, Rt as ScheduleView, St as MessagesQuery, Tt as PersonView, Wt as SourceRead, X as BoardEventView, Xt as SyncCodeView, Yt as SyncCodeBody, Z as ChannelView, Zt as SyncCopiesQuery, _n as UploadStartBody, _t as MatchView, bt as MessageView, cn as SyncUnlinkBody, ct as InboxEntry, dn as ThreadView, dt as InboxPushBody, en as SyncFindQuery, et as EditBody, fn as ThreadsPage, ft as InboxQuery, gt as LinkedQuery, hn as TypingBody, ht as LinkedAccount, in as SyncReceiptBody, jt as RegisterBody, kt as ReactBody, ln as SyncedView, lt as InboxItem, nn as SyncImportBody, nt as EventsQuery, on as SyncRootsQuery, ot as IdentityView, p as SyncProvider, pn as ThreadsQuery, pt as LabelBody, q as AckBody, sn as SyncThreadView, st as InboxAckBody, tn as SyncFindView, tt as EventsPage, ut as InboxNextQuery, vn as UploadTicket, vt as MatchesQuery, xt as MessagesPage, yt as Me, z as ProfileOption, zt as SchedulesQuery } from "./provider-B1Z3Ok86.mjs";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
//#region src/api/protocol.d.ts
|
|
8
8
|
type Input<S extends z.ZodType> = NonNullable<z.output<S>>;
|
package/dist/backend-a2.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import { i as Attachment } from "./schemas-CWxs3ECJ.mjs";
|
|
|
2
2
|
import { t as Actor } from "./folds-CRYY14kc.mjs";
|
|
3
3
|
import { l as Reducer, r as ContractEvent } from "./reducer-CYPHsSmd-BQIfozGi.mjs";
|
|
4
4
|
import { a as SessionAppend, c as SessionConsumeOptions, d as SessionSchedule, f as StateOptions, l as SessionConsumeResult, n as A2Server, o as SessionClearOptions, p as SessionCleared, r as Consumer, s as SessionClearResult, t as A2Scheduler, u as SessionDeadLetters } from "./server-qgez0Xny-D5mLfqFQ.mjs";
|
|
5
|
-
import { $ as Discovery, Mt as RegistrationView, Qt as SyncCopiesView, Rt as ScheduleView, Tt as PersonView, Wt as SourceRead, Xt as SyncCodeView, Z as ChannelView, _t as MatchView, bt as MessageView, ct as InboxEntry, dn as ThreadView, fn as ThreadsPage, ht as LinkedAccount, ln as SyncedView, lt as InboxItem, ot as IdentityView, sn as SyncThreadView, tn as SyncFindView, tt as EventsPage, vn as UploadTicket, xt as MessagesPage, yt as Me } from "./provider-
|
|
6
|
-
import { i as Caller, n as BackendRoute, r as BoardBinding } from "./backend-
|
|
5
|
+
import { $ as Discovery, Mt as RegistrationView, Qt as SyncCopiesView, Rt as ScheduleView, Tt as PersonView, Wt as SourceRead, Xt as SyncCodeView, Z as ChannelView, _t as MatchView, bt as MessageView, ct as InboxEntry, dn as ThreadView, fn as ThreadsPage, ht as LinkedAccount, ln as SyncedView, lt as InboxItem, ot as IdentityView, sn as SyncThreadView, tn as SyncFindView, tt as EventsPage, vn as UploadTicket, xt as MessagesPage, yt as Me } from "./provider-B1Z3Ok86.mjs";
|
|
6
|
+
import { i as Caller, n as BackendRoute, r as BoardBinding } from "./backend-B5GCP1oK.mjs";
|
|
7
7
|
import { n as fsBlob, r as memoryBlob, t as BlobStore } from "./blob-C0J3wbGv.mjs";
|
|
8
8
|
import { t as BoardStore } from "./types-8yq2VnKI.mjs";
|
|
9
9
|
import { z } from "zod";
|
|
@@ -221,6 +221,8 @@ export declare function a2(options?: A2Options): {
|
|
|
221
221
|
}>;
|
|
222
222
|
register: (caller: Caller, input: {
|
|
223
223
|
url?: string | null | undefined;
|
|
224
|
+
path?: string | null | undefined;
|
|
225
|
+
branch?: string | null | undefined;
|
|
224
226
|
watch: Record<string, {
|
|
225
227
|
tail: string;
|
|
226
228
|
when: "enters" | "matches";
|
package/dist/backend-a2.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as fsBlob, r as memoryBlob, t as a2 } from "./a2-
|
|
1
|
+
import { n as fsBlob, r as memoryBlob, t as a2 } from "./a2-C1obi0Qb.mjs";
|
|
2
2
|
export { a2, fsBlob, memoryBlob };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./files-SniSmeEr.mjs";
|
|
2
2
|
import "./schemas-Be08nyfW.mjs";
|
|
3
|
-
import { K as routes, k as RegisterBody, n as compileWatcher, o as METHODS, t as canonicalWatchers } from "./watchers-hash-
|
|
3
|
+
import { K as routes, k as RegisterBody, n as compileWatcher, o as METHODS, t as canonicalWatchers } from "./watchers-hash-B2TevhFZ.mjs";
|
|
4
4
|
import { n as createBoardClient, t as BoardError } from "./client-BA-J7usH.mjs";
|
|
5
5
|
import { a as sha256, i as keyId, n as derivedId, t as DERIVED_ID } from "./ids-C6AYo1bu.mjs";
|
|
6
6
|
import { a as forbidden, o as json, t as HttpError } from "./errors-DX3hpwWt.mjs";
|
|
@@ -350,17 +350,32 @@ function createHttp(url, options, environment) {
|
|
|
350
350
|
};
|
|
351
351
|
/** Only an https URL can be woken; anything else pulls on its own. */
|
|
352
352
|
const wakeable = (here) => here?.startsWith("https://") ? here : null;
|
|
353
|
+
/**
|
|
354
|
+
* Where the remote wakes this board: on a board that wakes by path, the path on this project,
|
|
355
|
+
* which gets through its Deployment Protection, from production or from a preview of a branch,
|
|
356
|
+
* which it names; anywhere else (off Vercel, development, a custom environment), its URL.
|
|
357
|
+
*/
|
|
358
|
+
async function wakeAt(here) {
|
|
359
|
+
const env = typeof process !== "undefined" && process.env.VERCEL === "1" ? process.env : null;
|
|
360
|
+
const environment = env?.VERCEL_TARGET_ENV || env?.VERCEL_ENV;
|
|
361
|
+
const branch = environment === "preview" ? env?.VERCEL_GIT_COMMIT_REF || null : null;
|
|
362
|
+
if (!here || environment !== "production" && !branch || !(await discovery()).wake_by_path) return { url: here };
|
|
363
|
+
return {
|
|
364
|
+
path: new URL(here).pathname,
|
|
365
|
+
...branch ? { branch } : {}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
353
368
|
let last = null;
|
|
354
369
|
let registering = null;
|
|
355
370
|
/** Registers this board's watchers with the remote, as itself, replacing its last registration. */
|
|
356
371
|
async function register(here) {
|
|
357
372
|
const current = await watchersHash();
|
|
358
373
|
if (last && last.url === here && last.result.hash === current && Date.now() - last.at < REGISTER_EVERY_MS) return last.result;
|
|
359
|
-
registering ??= own.register({
|
|
360
|
-
|
|
374
|
+
registering ??= wakeAt(here).then((where) => own.register({
|
|
375
|
+
...where,
|
|
361
376
|
watch: specs,
|
|
362
377
|
...sync.length > 0 ? { sync } : {}
|
|
363
|
-
}).then((result) => {
|
|
378
|
+
})).then((result) => {
|
|
364
379
|
last = {
|
|
365
380
|
url: here,
|
|
366
381
|
at: Date.now(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as Attachment } from "./schemas-CWxs3ECJ.mjs";
|
|
2
2
|
import { t as Actor } from "./folds-CRYY14kc.mjs";
|
|
3
|
-
import { $ as Discovery, Mt as RegistrationView, Qt as SyncCopiesView, Rt as ScheduleView, Tt as PersonView, Wt as SourceRead, Xt as SyncCodeView, Z as ChannelView, _t as MatchView, bt as MessageView, ct as InboxEntry, dn as ThreadView, fn as ThreadsPage, ht as LinkedAccount, ln as SyncedView, lt as InboxItem, ot as IdentityView, sn as SyncThreadView, tn as SyncFindView, tt as EventsPage, vn as UploadTicket, xt as MessagesPage, yt as Me, z as ProfileOption } from "./provider-
|
|
4
|
-
import { i as Caller, n as BackendRoute, r as BoardBinding } from "./backend-
|
|
3
|
+
import { $ as Discovery, Mt as RegistrationView, Qt as SyncCopiesView, Rt as ScheduleView, Tt as PersonView, Wt as SourceRead, Xt as SyncCodeView, Z as ChannelView, _t as MatchView, bt as MessageView, ct as InboxEntry, dn as ThreadView, fn as ThreadsPage, ht as LinkedAccount, ln as SyncedView, lt as InboxItem, ot as IdentityView, sn as SyncThreadView, tn as SyncFindView, tt as EventsPage, vn as UploadTicket, xt as MessagesPage, yt as Me, z as ProfileOption } from "./provider-B1Z3Ok86.mjs";
|
|
4
|
+
import { i as Caller, n as BackendRoute, r as BoardBinding } from "./backend-B5GCP1oK.mjs";
|
|
5
5
|
//#region src/server/backend-http.d.ts
|
|
6
6
|
type HttpOptions = {
|
|
7
7
|
/**
|
|
@@ -195,6 +195,8 @@ declare function createHttp(url: string | undefined, options: HttpOptions, envir
|
|
|
195
195
|
}>;
|
|
196
196
|
register: (caller: Caller, input: {
|
|
197
197
|
url?: string | null | undefined;
|
|
198
|
+
path?: string | null | undefined;
|
|
199
|
+
branch?: string | null | undefined;
|
|
198
200
|
watch: Record<string, {
|
|
199
201
|
tail: string;
|
|
200
202
|
when: "enters" | "matches";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as BoardError } from "./client-BA-J7usH.mjs";
|
|
2
|
-
import { t as createHttp } from "./backend-http-
|
|
2
|
+
import { t as createHttp } from "./backend-http-BMVDbtD_.mjs";
|
|
3
3
|
import { execFile } from "node:child_process";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
package/dist/backend-http.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as HttpOptions, t as HttpBackend } from "./backend-http-
|
|
1
|
+
import { n as HttpOptions, t as HttpBackend } from "./backend-http-Ca6b0FPA.mjs";
|
|
2
2
|
//#region src/backend-http/index.default.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The board at `url`, which keeps the log. Outside Node there's no environment to find it or a
|
package/dist/backend-http.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as http } from "./index.default-
|
|
1
|
+
import { t as http } from "./index.default-Cm6GsLdj.mjs";
|
|
2
2
|
export { http };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as HttpOptions, t as HttpBackend } from "./backend-http-
|
|
1
|
+
import { n as HttpOptions, t as HttpBackend } from "./backend-http-Ca6b0FPA.mjs";
|
|
2
2
|
//#region src/backend-http/index.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The board at `url`, which keeps the log: this board uses it as this deployment. Without a
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as http } from "./backend-http-
|
|
1
|
+
import { t as http } from "./backend-http-DMpQ750P.mjs";
|
|
2
2
|
export { http };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { d as ExternalFile, f as ExternalLink, l as ExternalAuthor, t as Actor } from "./folds-CRYY14kc.mjs";
|
|
2
|
-
import { M as SyncRoot, O as ProviderEvent, Wt as SourceRead, a as ProviderOptions, c as ReceivedEvent, d as ResolvedTarget, i as ProviderFile, n as FileDelivery, o as ProviderPost, p as SyncProvider, r as ProviderDelivery, s as Receive, t as FetchedLink, y as SyncFn } from "./provider-
|
|
2
|
+
import { M as SyncRoot, O as ProviderEvent, Wt as SourceRead, a as ProviderOptions, c as ReceivedEvent, d as ResolvedTarget, i as ProviderFile, n as FileDelivery, o as ProviderPost, p as SyncProvider, r as ProviderDelivery, s as Receive, t as FetchedLink, y as SyncFn } from "./provider-B1Z3Ok86.mjs";
|
|
3
3
|
import { Adapter, Author, FileUpload, Message, ReactionEvent } from "chat";
|
|
4
4
|
//#region src/sync/types.d.ts
|
|
5
5
|
declare function externalAuthor(platform: string, author: Author): ExternalAuthor;
|
package/dist/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { i as fileSize, n as DIRECT_UPLOAD_BYTES_MAX, t as ATTACHMENT_BYTES_MAX } from "./files-SniSmeEr.mjs";
|
|
3
3
|
import { a as AttachmentId } from "./schemas-Be08nyfW.mjs";
|
|
4
|
-
import { a as withMentions, f as VERSION, i as FILTER_FLAGS } from "./watchers-hash-
|
|
4
|
+
import { a as withMentions, f as VERSION, i as FILTER_FLAGS } from "./watchers-hash-B2TevhFZ.mjs";
|
|
5
5
|
import { n as displayEmoji, r as normalizeEmoji } from "./emoji-CTLpvH-A.mjs";
|
|
6
6
|
import { t as BoardError } from "./client-BA-J7usH.mjs";
|
|
7
|
-
import { a as detectAgent, c as projectUrl, i as connect, n as boardUrl, r as configDir, s as projectDir, t as http } from "./backend-http-
|
|
8
|
-
import { t as board } from "./server-
|
|
9
|
-
import { t as conformance } from "./conformance-
|
|
7
|
+
import { a as detectAgent, c as projectUrl, i as connect, n as boardUrl, r as configDir, s as projectDir, t as http } from "./backend-http-DMpQ750P.mjs";
|
|
8
|
+
import { t as board } from "./server-BujqWBP5.mjs";
|
|
9
|
+
import { t as conformance } from "./conformance-D0Z4dXC_.mjs";
|
|
10
10
|
import { t as displayText } from "./bots-CGkO76qH.mjs";
|
|
11
11
|
import { execFileSync, spawn } from "node:child_process";
|
|
12
12
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
@@ -2196,7 +2196,7 @@ async function run(command, args) {
|
|
|
2196
2196
|
if (args.length > 0) throw new UsageError("usage: board serve [--port N] [--dir <dir>] [--no-inspect] [--no-open]");
|
|
2197
2197
|
const port = portFlag();
|
|
2198
2198
|
const root = projectDir();
|
|
2199
|
-
const { localHandle, serveLocal } = await import("./serve-
|
|
2199
|
+
const { localHandle, serveLocal } = await import("./serve-DB9ijyQ7.mjs");
|
|
2200
2200
|
const handle = flags.handle ?? process.env.BOARD_HANDLE;
|
|
2201
2201
|
const local = await serveLocal({
|
|
2202
2202
|
dir: flags.dir ?? join(root, ".board"),
|
|
@@ -17,6 +17,14 @@ async function rejects(attempt, status, code, what) {
|
|
|
17
17
|
}
|
|
18
18
|
throw new Mismatch(`${what}: expected ${status} ${code}, and it succeeded`);
|
|
19
19
|
}
|
|
20
|
+
/** Where a registration is woken, to put back after a check replaces it: its path (and branch) on a board that wakes by path, or its url. */
|
|
21
|
+
function wokenAt(registered) {
|
|
22
|
+
if (!registered?.path) return { url: registered?.url ?? null };
|
|
23
|
+
return {
|
|
24
|
+
path: registered.path,
|
|
25
|
+
...registered.branch ? { branch: registered.branch } : {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
20
28
|
/** An ID or cursor as the protocol shapes them: a string of 1 to 128 characters. */
|
|
21
29
|
function isRef(value, what) {
|
|
22
30
|
check(typeof value === "string" && value.length >= 1 && value.length <= 128, `${what} should be a string of 1 to 128 characters, got ${show(value)}`);
|
|
@@ -274,7 +282,7 @@ const CHECKS = [
|
|
|
274
282
|
run: async (ctx) => {
|
|
275
283
|
const registered = (await ctx.board.watchers()).find((r) => r.owner === ctx.me.principal);
|
|
276
284
|
if (registered && (Object.keys(registered.watch).length > 0 || (registered.sync?.length ?? 0) > 0)) return "this token has watchers or a sync registered here, and checking would replace them";
|
|
277
|
-
const
|
|
285
|
+
const where = wokenAt(registered);
|
|
278
286
|
await ctx.board.register({
|
|
279
287
|
url: null,
|
|
280
288
|
watch: { conformance: { tail: `${ctx.channel} --label conformance=${ctx.labels.conformance}` } }
|
|
@@ -290,7 +298,40 @@ const CHECKS = [
|
|
|
290
298
|
await rejects(ctx.board.ack(match.id, { lease: match.lease }), 404, "no_match", "acking a match twice");
|
|
291
299
|
} finally {
|
|
292
300
|
await ctx.board.register({
|
|
293
|
-
|
|
301
|
+
...where,
|
|
302
|
+
watch: {}
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
group: "watchers",
|
|
309
|
+
name: "wakes by path only where its discovery says so, and only a Vercel project",
|
|
310
|
+
run: async (ctx) => {
|
|
311
|
+
const registered = (await ctx.board.watchers()).find((r) => r.owner === ctx.me.principal);
|
|
312
|
+
if (registered && (Object.keys(registered.watch).length > 0 || (registered.sync?.length ?? 0) > 0)) return "this token has watchers or a sync registered here, and checking would replace them";
|
|
313
|
+
const byPath = (await ctx.board.discovery()).wake_by_path;
|
|
314
|
+
const environment = /^vercel:project:[^:]+:(.+)$/.exec(ctx.me.principal)?.[1] ?? null;
|
|
315
|
+
if (byPath && environment !== null && environment !== "production" && environment !== "preview") return `a path wakes production or a preview, and this token is ${environment}'s`;
|
|
316
|
+
const where = wokenAt(registered);
|
|
317
|
+
const branch = environment === "preview" ? { branch: "conformance" } : {};
|
|
318
|
+
const attempt = () => ctx.board.register({
|
|
319
|
+
path: "/conformance",
|
|
320
|
+
...branch,
|
|
321
|
+
watch: {}
|
|
322
|
+
});
|
|
323
|
+
try {
|
|
324
|
+
if (!byPath) await rejects(attempt(), 501, "no_wake_by_path", "a path, on a board that wakes only urls");
|
|
325
|
+
else if (environment === null) await rejects(attempt(), 403, "not_a_project", "a path, from a token that isn't a Vercel project's");
|
|
326
|
+
else {
|
|
327
|
+
const view = await attempt();
|
|
328
|
+
same(view.path, "/conformance", "the registration's path");
|
|
329
|
+
same(view.url, null, "the registration's url");
|
|
330
|
+
same(view.branch ?? null, environment === "preview" ? "conformance" : null, "the registration's branch");
|
|
331
|
+
}
|
|
332
|
+
} finally {
|
|
333
|
+
await ctx.board.register({
|
|
334
|
+
...where,
|
|
294
335
|
watch: {}
|
|
295
336
|
});
|
|
296
337
|
}
|
|
@@ -315,7 +356,7 @@ const CHECKS = [
|
|
|
315
356
|
};
|
|
316
357
|
const registered = (await ctx.board.watchers()).find((registration) => registration.owner === ctx.me.principal);
|
|
317
358
|
if (registered && (Object.keys(registered.watch).length > 0 || (registered.sync?.length ?? 0) > 0)) return "this token has watchers or a sync registered here, which registering would replace";
|
|
318
|
-
const
|
|
359
|
+
const where = wokenAt(registered);
|
|
319
360
|
try {
|
|
320
361
|
await ctx.board.register({
|
|
321
362
|
url: null,
|
|
@@ -350,7 +391,7 @@ const CHECKS = [
|
|
|
350
391
|
});
|
|
351
392
|
} catch (error) {
|
|
352
393
|
await ctx.board.register({
|
|
353
|
-
|
|
394
|
+
...where,
|
|
354
395
|
watch: {}
|
|
355
396
|
}).catch(() => {});
|
|
356
397
|
if (error instanceof BoardError && error.status === 403) return `this token can't sync in ${ctx.channel}`;
|
|
@@ -431,7 +472,7 @@ const CHECKS = [
|
|
|
431
472
|
}
|
|
432
473
|
}).catch(() => {});
|
|
433
474
|
await ctx.board.register({
|
|
434
|
-
|
|
475
|
+
...where,
|
|
435
476
|
watch: {}
|
|
436
477
|
}).catch(() => {});
|
|
437
478
|
}
|
package/dist/conformance.d.mts
CHANGED
package/dist/conformance.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as conformance } from "./conformance-
|
|
1
|
+
import { t as conformance } from "./conformance-D0Z4dXC_.mjs";
|
|
2
2
|
export { conformance };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as ATTACHMENT_BYTES_MAX } from "./files-SniSmeEr.mjs";
|
|
2
2
|
import "./schemas-Be08nyfW.mjs";
|
|
3
|
-
import { A as ScheduleBody, B as SyncReceiptBody, C as LinkedQuery, D as ReactBody, E as PostBody, F as SyncBody, G as UploadStartBody, H as SyncUnlinkBody, I as SyncCodeBody, L as SyncCopiesQuery, M as SignInQuery, N as SourceReadQuery, O as Ref, P as SyncAccountBody, R as SyncFindQuery, S as LabelBody, T as MessagesQuery, U as ThreadsQuery, V as SyncRootsQuery, W as TypingBody, _ as IdentityUnlinkBody, b as InboxPushBody, c as openapi, d as readJson, f as VERSION, g as EventsQuery, h as EditBody, j as SchedulesQuery, k as RegisterBody, l as queryObject, m as AckBody, o as METHODS, p as SYNC, s as createRouter, u as readCapped, v as InboxAckBody, w as MatchesQuery, x as InboxQuery, y as InboxNextQuery, z as SyncImportBody } from "./watchers-hash-
|
|
3
|
+
import { A as ScheduleBody, B as SyncReceiptBody, C as LinkedQuery, D as ReactBody, E as PostBody, F as SyncBody, G as UploadStartBody, H as SyncUnlinkBody, I as SyncCodeBody, L as SyncCopiesQuery, M as SignInQuery, N as SourceReadQuery, O as Ref, P as SyncAccountBody, R as SyncFindQuery, S as LabelBody, T as MessagesQuery, U as ThreadsQuery, V as SyncRootsQuery, W as TypingBody, _ as IdentityUnlinkBody, b as InboxPushBody, c as openapi, d as readJson, f as VERSION, g as EventsQuery, h as EditBody, j as SchedulesQuery, k as RegisterBody, l as queryObject, m as AckBody, o as METHODS, p as SYNC, s as createRouter, u as readCapped, v as InboxAckBody, w as MatchesQuery, x as InboxQuery, y as InboxNextQuery, z as SyncImportBody } from "./watchers-hash-B2TevhFZ.mjs";
|
|
4
4
|
import { n as createBoardClient, t as BoardError } from "./client-BA-J7usH.mjs";
|
|
5
5
|
import { n as derivedId } from "./ids-C6AYo1bu.mjs";
|
|
6
6
|
import { a as forbidden, c as toErrorResponse, l as unauthorized, n as RejectedError, o as json, r as badRequest, s as notFound, t as HttpError } from "./errors-DX3hpwWt.mjs";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as CallerRequest, o as Claims } from "./auth-CU56Q2Xh.mjs";
|
|
2
2
|
import { i as Attachment } from "./schemas-CWxs3ECJ.mjs";
|
|
3
|
-
import { $ as Discovery, $t as SyncFindInput, At as Ref, B as ReplyOptions, Bt as SchedulesQueryInput, Ct as MessagesQueryInput, Dt as PostInput, Et as PostBody, Ft as ScheduleBody, G as Written, Gt as SourceReadQuery, H as ScheduleTiming, Ht as SignInQuery, I as BoardError, It as ScheduleBodyOutput, J as ActorView, Jt as SyncBody, K as duration, Kt as SyncAccountBody, L as Filters, Lt as ScheduleInput, Mt as RegistrationView, Nt as ResolvedSyncTarget, Ot as REGISTERED_WATCHERS_MAX, Pt as RouteName, Q as DeleteBody, Qt as SyncCopiesView, R as PostOptions, Rt as ScheduleView, St as MessagesQuery, Tt as PersonView, U as UploadInput, Ut as SourceMessage, V as ScheduleOptions, Vt as SchedulesQueryOutput, W as WaitOptions, Wt as SourceRead, X as BoardEventView, Xt as SyncCodeView, Y as ApiError, Yt as SyncCodeBody, Z as ChannelView, Zt as SyncCopiesQuery, _n as UploadStartBody, _t as MatchView, an as SyncReceiptInput, at as IdentityUnlinkBody, bt as MessageView, cn as SyncUnlinkBody, ct as InboxEntry, dn as ThreadView, dt as InboxPushBody, en as SyncFindQuery, et as EditBody, fn as ThreadsPage, ft as InboxQuery, gn as TypingResult, gt as LinkedQuery, hn as TypingBody, ht as LinkedAccount, in as SyncReceiptBody, it as FiltersInput, jt as RegisterBody, kt as ReactBody, ln as SyncedView, lt as InboxItem, mn as ThreadsQueryInput, mt as LinkView, nn as SyncImportBody, nt as EventsQuery, on as SyncRootsQuery, ot as IdentityView, pn as ThreadsQuery, pt as LabelBody, q as AckBody, qt as SyncAccountInput, rn as SyncImportInput, rt as EventsQueryInput, sn as SyncThreadView, st as InboxAckBody, tn as SyncFindView, tt as EventsPage, un as ThreadSummaryView, ut as InboxNextQuery, vn as UploadTicket, vt as MatchesQuery, wt as ParsedFilters, xt as MessagesPage, yn as routes, yt as Me, z as ProfileOption, zt as SchedulesQuery } from "./provider-
|
|
4
|
-
import { C as Protocol, S as Method, _ as MiddlewareContext, a as Identity, b as WriteSource, c as SelfCaller, d as Board, f as BoardOptions, g as Middleware, h as DroppedError, i as Caller, l as Subscription, m as WatcherContext, n as BackendRoute, o as InboxDelivery, p as Watcher, r as BoardBinding, s as ProtocolMethods, t as Backend, u as VerifiedCaller, v as Write, x as HttpError, y as WritePatch } from "./backend-
|
|
5
|
-
import "./exports-
|
|
3
|
+
import { $ as Discovery, $t as SyncFindInput, At as Ref, B as ReplyOptions, Bt as SchedulesQueryInput, Ct as MessagesQueryInput, Dt as PostInput, Et as PostBody, Ft as ScheduleBody, G as Written, Gt as SourceReadQuery, H as ScheduleTiming, Ht as SignInQuery, I as BoardError, It as ScheduleBodyOutput, J as ActorView, Jt as SyncBody, K as duration, Kt as SyncAccountBody, L as Filters, Lt as ScheduleInput, Mt as RegistrationView, Nt as ResolvedSyncTarget, Ot as REGISTERED_WATCHERS_MAX, Pt as RouteName, Q as DeleteBody, Qt as SyncCopiesView, R as PostOptions, Rt as ScheduleView, St as MessagesQuery, Tt as PersonView, U as UploadInput, Ut as SourceMessage, V as ScheduleOptions, Vt as SchedulesQueryOutput, W as WaitOptions, Wt as SourceRead, X as BoardEventView, Xt as SyncCodeView, Y as ApiError, Yt as SyncCodeBody, Z as ChannelView, Zt as SyncCopiesQuery, _n as UploadStartBody, _t as MatchView, an as SyncReceiptInput, at as IdentityUnlinkBody, bt as MessageView, cn as SyncUnlinkBody, ct as InboxEntry, dn as ThreadView, dt as InboxPushBody, en as SyncFindQuery, et as EditBody, fn as ThreadsPage, ft as InboxQuery, gn as TypingResult, gt as LinkedQuery, hn as TypingBody, ht as LinkedAccount, in as SyncReceiptBody, it as FiltersInput, jt as RegisterBody, kt as ReactBody, ln as SyncedView, lt as InboxItem, mn as ThreadsQueryInput, mt as LinkView, nn as SyncImportBody, nt as EventsQuery, on as SyncRootsQuery, ot as IdentityView, pn as ThreadsQuery, pt as LabelBody, q as AckBody, qt as SyncAccountInput, rn as SyncImportInput, rt as EventsQueryInput, sn as SyncThreadView, st as InboxAckBody, tn as SyncFindView, tt as EventsPage, un as ThreadSummaryView, ut as InboxNextQuery, vn as UploadTicket, vt as MatchesQuery, wt as ParsedFilters, xt as MessagesPage, yn as routes, yt as Me, z as ProfileOption, zt as SchedulesQuery } from "./provider-B1Z3Ok86.mjs";
|
|
4
|
+
import { C as Protocol, S as Method, _ as MiddlewareContext, a as Identity, b as WriteSource, c as SelfCaller, d as Board, f as BoardOptions, g as Middleware, h as DroppedError, i as Caller, l as Subscription, m as WatcherContext, n as BackendRoute, o as InboxDelivery, p as Watcher, r as BoardBinding, s as ProtocolMethods, t as Backend, u as VerifiedCaller, v as Write, x as HttpError, y as WritePatch } from "./backend-B5GCP1oK.mjs";
|
|
5
|
+
import "./exports-B3AFzT_f.mjs";
|
|
6
6
|
//#region src/server/index.default.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* The handle on a board. Outside Node there's no environment to find one in, so pass its
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createHttp } from "./backend-http-
|
|
1
|
+
import { t as createHttp } from "./backend-http-BMVDbtD_.mjs";
|
|
2
2
|
//#region src/backend-http/index.default.ts
|
|
3
3
|
/**
|
|
4
4
|
* The board at `url`, which keeps the log. Outside Node there's no environment to find it or a
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as duration, t as BoardError } from "./client-BA-J7usH.mjs";
|
|
2
2
|
import { t as HttpError } from "./errors-DX3hpwWt.mjs";
|
|
3
|
-
import { t as http } from "./index.default-
|
|
4
|
-
import { t as createBoard } from "./exports-
|
|
3
|
+
import { t as http } from "./index.default-Cm6GsLdj.mjs";
|
|
4
|
+
import { t as createBoard } from "./exports-CUGshfRF.mjs";
|
|
5
5
|
import { t as DroppedError } from "./middleware-CqaCwucP.mjs";
|
|
6
6
|
//#region src/server/index.default.ts
|
|
7
7
|
/**
|
package/dist/index.node.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { a as CallerRequest, o as Claims } from "./auth-CU56Q2Xh.mjs";
|
|
2
2
|
import { i as Attachment } from "./schemas-CWxs3ECJ.mjs";
|
|
3
|
-
import { $ as Discovery, $t as SyncFindInput, At as Ref, B as ReplyOptions, Bt as SchedulesQueryInput, Ct as MessagesQueryInput, Dt as PostInput, Et as PostBody, Ft as ScheduleBody, G as Written, Gt as SourceReadQuery, H as ScheduleTiming, Ht as SignInQuery, I as BoardError, It as ScheduleBodyOutput, J as ActorView, Jt as SyncBody, K as duration, Kt as SyncAccountBody, L as Filters, Lt as ScheduleInput, Mt as RegistrationView, Nt as ResolvedSyncTarget, Ot as REGISTERED_WATCHERS_MAX, Pt as RouteName, Q as DeleteBody, Qt as SyncCopiesView, R as PostOptions, Rt as ScheduleView, St as MessagesQuery, Tt as PersonView, U as UploadInput, Ut as SourceMessage, V as ScheduleOptions, Vt as SchedulesQueryOutput, W as WaitOptions, Wt as SourceRead, X as BoardEventView, Xt as SyncCodeView, Y as ApiError, Yt as SyncCodeBody, Z as ChannelView, Zt as SyncCopiesQuery, _n as UploadStartBody, _t as MatchView, an as SyncReceiptInput, at as IdentityUnlinkBody, bt as MessageView, cn as SyncUnlinkBody, ct as InboxEntry, dn as ThreadView, dt as InboxPushBody, en as SyncFindQuery, et as EditBody, fn as ThreadsPage, ft as InboxQuery, gn as TypingResult, gt as LinkedQuery, hn as TypingBody, ht as LinkedAccount, in as SyncReceiptBody, it as FiltersInput, jt as RegisterBody, kt as ReactBody, ln as SyncedView, lt as InboxItem, mn as ThreadsQueryInput, mt as LinkView, nn as SyncImportBody, nt as EventsQuery, on as SyncRootsQuery, ot as IdentityView, pn as ThreadsQuery, pt as LabelBody, q as AckBody, qt as SyncAccountInput, rn as SyncImportInput, rt as EventsQueryInput, sn as SyncThreadView, st as InboxAckBody, tn as SyncFindView, tt as EventsPage, un as ThreadSummaryView, ut as InboxNextQuery, vn as UploadTicket, vt as MatchesQuery, wt as ParsedFilters, xt as MessagesPage, yn as routes, yt as Me, z as ProfileOption, zt as SchedulesQuery } from "./provider-
|
|
4
|
-
import { C as Protocol, S as Method, _ as MiddlewareContext, a as Identity, b as WriteSource, c as SelfCaller, d as Board, f as BoardOptions, g as Middleware, h as DroppedError, i as Caller, l as Subscription, m as WatcherContext, n as BackendRoute, o as InboxDelivery, p as Watcher, r as BoardBinding, s as ProtocolMethods, t as Backend, u as VerifiedCaller, v as Write, x as HttpError, y as WritePatch } from "./backend-
|
|
5
|
-
import "./exports-
|
|
3
|
+
import { $ as Discovery, $t as SyncFindInput, At as Ref, B as ReplyOptions, Bt as SchedulesQueryInput, Ct as MessagesQueryInput, Dt as PostInput, Et as PostBody, Ft as ScheduleBody, G as Written, Gt as SourceReadQuery, H as ScheduleTiming, Ht as SignInQuery, I as BoardError, It as ScheduleBodyOutput, J as ActorView, Jt as SyncBody, K as duration, Kt as SyncAccountBody, L as Filters, Lt as ScheduleInput, Mt as RegistrationView, Nt as ResolvedSyncTarget, Ot as REGISTERED_WATCHERS_MAX, Pt as RouteName, Q as DeleteBody, Qt as SyncCopiesView, R as PostOptions, Rt as ScheduleView, St as MessagesQuery, Tt as PersonView, U as UploadInput, Ut as SourceMessage, V as ScheduleOptions, Vt as SchedulesQueryOutput, W as WaitOptions, Wt as SourceRead, X as BoardEventView, Xt as SyncCodeView, Y as ApiError, Yt as SyncCodeBody, Z as ChannelView, Zt as SyncCopiesQuery, _n as UploadStartBody, _t as MatchView, an as SyncReceiptInput, at as IdentityUnlinkBody, bt as MessageView, cn as SyncUnlinkBody, ct as InboxEntry, dn as ThreadView, dt as InboxPushBody, en as SyncFindQuery, et as EditBody, fn as ThreadsPage, ft as InboxQuery, gn as TypingResult, gt as LinkedQuery, hn as TypingBody, ht as LinkedAccount, in as SyncReceiptBody, it as FiltersInput, jt as RegisterBody, kt as ReactBody, ln as SyncedView, lt as InboxItem, mn as ThreadsQueryInput, mt as LinkView, nn as SyncImportBody, nt as EventsQuery, on as SyncRootsQuery, ot as IdentityView, pn as ThreadsQuery, pt as LabelBody, q as AckBody, qt as SyncAccountInput, rn as SyncImportInput, rt as EventsQueryInput, sn as SyncThreadView, st as InboxAckBody, tn as SyncFindView, tt as EventsPage, un as ThreadSummaryView, ut as InboxNextQuery, vn as UploadTicket, vt as MatchesQuery, wt as ParsedFilters, xt as MessagesPage, yn as routes, yt as Me, z as ProfileOption, zt as SchedulesQuery } from "./provider-B1Z3Ok86.mjs";
|
|
4
|
+
import { C as Protocol, S as Method, _ as MiddlewareContext, a as Identity, b as WriteSource, c as SelfCaller, d as Board, f as BoardOptions, g as Middleware, h as DroppedError, i as Caller, l as Subscription, m as WatcherContext, n as BackendRoute, o as InboxDelivery, p as Watcher, r as BoardBinding, s as ProtocolMethods, t as Backend, u as VerifiedCaller, v as Write, x as HttpError, y as WritePatch } from "./backend-B5GCP1oK.mjs";
|
|
5
|
+
import "./exports-B3AFzT_f.mjs";
|
|
6
6
|
//#region src/server/index.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* The handle on a board. With a `backend`, the board lives there: `a2()` keeps it in this
|
package/dist/index.node.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as duration, t as BoardError } from "./client-BA-J7usH.mjs";
|
|
2
2
|
import { t as HttpError } from "./errors-DX3hpwWt.mjs";
|
|
3
3
|
import { t as DroppedError } from "./middleware-CqaCwucP.mjs";
|
|
4
|
-
import { t as board } from "./server-
|
|
4
|
+
import { t as board } from "./server-BujqWBP5.mjs";
|
|
5
5
|
export { BoardError, DroppedError, HttpError, board, duration };
|
package/dist/inspect/app.js
CHANGED
|
@@ -340,8 +340,8 @@ function Do(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...U(n)})}//
|
|
|
340
340
|
function Oo(e,t){let n=/* @__PURE__ */ ko(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(jt(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(jt(r))}},e(t.value,t)),t);return n}// @__NO_SIDE_EFFECTS__
|
|
341
341
|
function ko(e,t){let n=new or({check:`custom`,...U(t)});return n._zod.check=e,n}function Ao(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&Ge(e,t,n[t]);return e}function jo(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??Sa,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:/* @__PURE__ */ new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function Mo(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function No(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,No(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Ao(o.schema,c),t.io===`input`&&Uo(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Po(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Fo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=/* @__PURE__ */ new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${Po(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+Po(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
342
342
|
|
|
343
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function Io(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;Io(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const Lo=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),Ro=[`oneOf`,`anyOf`];function zo(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Bo(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!Lo.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??zo(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Ge(n,r,e.length===1?e[0]:Bo(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=zo(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Vo(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of Lo)if(t in e)return;let n=t.filter(e=>Ro.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Bo(t);else{let e=n[0],i=Ro.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Bo([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,Ao(e,r))}function Ho(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Ao(i,s),Ao(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())Io(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Vo(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Ao(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Ge(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Go(t,`input`,e.processors),output:Go(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Uo(e,t){let n=t??{seen:/* @__PURE__ */ new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Uo(r.element,n);if(r.type===`set`)return Uo(r.valueType,n);if(r.type===`lazy`)return Uo(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return Uo(r.innerType,n);if(r.type===`intersection`)return Uo(r.left,n)||Uo(r.right,n);if(r.type===`record`||r.type===`map`)return Uo(r.keyType,n)||Uo(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:Uo(r.in,n)||Uo(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Uo(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Uo(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Uo(e,n))return!0;return!!(r.rest&&Uo(r.rest,n))}return!1}const Wo=(e,t={})=>n=>{let r=jo({...n,processors:t});return No(e,r),Fo(r,e),Ho(r,e)},Go=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=jo({...i??{},target:a,io:t,processors:n});return No(e,o),Fo(o,e),Ho(o,e)},Ko=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},qo=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Jo=(e,t)=>{Ko(e,`minimum`,t),qo(e,`maximum`,t)},Yo=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Xo=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},Zo=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Qo=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},$o=(e,t)=>Ko(e,`minimum`,t.minimum),es=(e,t)=>qo(e,`maximum`,t.maximum),ts=e=>(t,n)=>{Qo(t,n.format);let[r,i]=e[n.format];Ko(t,`minimum`,r),qo(t,`maximum`,i)},ns={greater_than:(e,t)=>Ko(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>qo(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Yo(e,t.value),number_format:ts(ut),bigint_format:ts(dt),min_length:$o,max_length:es,length_equals:(e,t)=>Jo(e,t.length),min_size:$o,max_size:es,size_equals:(e,t)=>Jo(e,t.size),string_format:(e,t)=>{Qo(e,t.format),t.pattern&&Xo(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Zo(e,t.mime)};function rs(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)ns[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Ko(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Ko(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&qo(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&qo(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Yo(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Zo(t,i.mime);for(let e of i.patterns??[])Xo(t,e);return t}const is={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},as=/* @__PURE__ */ new Map([[ci,Wn],[ui,Gn]]),os=e=>as.get(e)??e,ss=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=rs(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=is[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(os);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},cs=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=rs(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):Mo(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},ls=(e,t,n,r)=>{n.type=`boolean`},us=(e,t,n,r)=>{Mo(e,t,n,r,`BigInt cannot be represented in JSON Schema`)},ds=(e,t,n,r)=>{Mo(e,t,n,r,`Symbols cannot be represented in JSON Schema`)},fs=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},ps=(e,t,n,r)=>{Mo(e,t,n,r,`Undefined cannot be represented in JSON Schema`)},ms=(e,t,n,r)=>{Mo(e,t,n,r,`Void cannot be represented in JSON Schema`)},hs=(e,t,n,r)=>{n.not={}},gs=(e,t,n,r)=>{},_s=(e,t,n,r)=>{},vs=(e,t,n,r)=>{Mo(e,t,n,r,`Date cannot be represented in JSON Schema`)},ys=(e,t,n,r)=>{let i=e._zod.def,a=Le(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},bs=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(Mo(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Mo(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},xs=(e,t,n,r)=>{Mo(e,t,n,r,`NaN cannot be represented in JSON Schema`)},Ss=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},Cs=(e,t,n,r)=>{let i=n;i.type=`string`,i.format=`binary`,i.contentEncoding=`binary`;let{minimum:a,maximum:o,mime:s}=rs(e);a!==void 0&&(i.minLength=a),o!==void 0&&(i.maxLength=o),s&&(s.length===0?i.not={}:s.length===1?i.contentMediaType=s[0]:i.anyOf=s.map(e=>({contentMediaType:e})))},ws=(e,t,n,r)=>{n.type=`boolean`},Ts=(e,t,n,r)=>{Mo(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Es=(e,t,n,r)=>{Mo(e,t,n,r,`Function types cannot be represented in JSON Schema`)},Ds=(e,t,n,r)=>{Mo(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Os=(e,t,n,r)=>{Mo(e,t,n,r,`Map cannot be represented in JSON Schema`)},ks=(e,t,n,r)=>{Mo(e,t,n,r,`Set cannot be represented in JSON Schema`)},As=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=rs(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=No(a.element,t,{...r,path:[...r.path,`items`]})};function js(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?js(t.out):t.type===`catch`?js(t.innerType):e._zod.optin}const Ms=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Mo(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Ge(i.properties,e,No(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?js(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=No(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Ns=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>No(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ps=(e,t,n,r)=>{let i=e._zod.def,a=No(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=No(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},Fs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>No(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?No(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null,u=a.items.length;for(;u>0;){let e=a.items[u-1];if(!(t.io===`input`?js(e)!==void 0:e._zod.optout===`optional`))break;u--}let d=a.items.length,f=!a.rest;t.target===`draft-2020-12`?(i.prefixItems=c,f?i.items=!1:l&&(i.items=l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):(i.items=c,f?i.additionalItems=!1:l&&(i.additionalItems=l),u>0&&(i.minItems=u),f&&(i.maxItems=d));let{minimum:p,maximum:m}=rs(e);typeof p==`number`&&(i.minItems=p),typeof m==`number`&&(i.maxItems=m)};function Is(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=Is(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>Is(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?nr:tr).source),p):p}const Ls=/* @__PURE__ */ new WeakMap;function Rs(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of Ls.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=Is(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const zs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=rs(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=No(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Ge(i.patternProperties,os(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=No(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Ls.get(t);n||(n=[],Ls.set(t,n),t.deferred.push(()=>Rs(t))),n.push(e)}i.additionalProperties=No(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&js(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},Bs=(e,t,n,r)=>{let i=e._zod.def,a=No(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Vs=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Hs=Symbol();function Us(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Mo(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),Hs):JSON.parse(o)}const Ws=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=Us(i.defaultValue,e,t,n,r);o!==Hs&&(n.default=o)},Gs=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=Us(i.defaultValue,e,t,n,r);o!==Hs&&(n._prefault=o)},Ks=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Mo(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},qs=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;No(o,t,r);let s=t.seen.get(e);s.ref=o},Js=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Ys=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Xs=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Zs={string:ss,number:cs,boolean:ls,bigint:us,symbol:ds,null:fs,undefined:ps,void:ms,never:hs,any:gs,unknown:_s,date:vs,enum:ys,literal:bs,nan:xs,template_literal:Ss,file:Cs,success:ws,custom:Ts,function:Es,transform:Ds,map:Os,set:ks,array:As,object:Ms,union:Ns,intersection:Ps,tuple:Fs,record:zs,nullable:Bs,nonoptional:Vs,default:Ws,prefault:Gs,catch:Ks,pipe:qs,readonly:Js,promise:Ys,optional:Xs,lazy:(e,t,n,r)=>{let i=e._zod.innerType;No(i,t,r);let a=t.seen.get(e);a.ref=i}};function Qs(e,t){if(`_idmap`in e){let n=e,r=jo({...t,processors:Zs}),i={};for(let e of n._idmap.entries()){let[t,n]=e;No(n,r)}let a={};r.external={registry:n,uri:t?.uri,defs:i};for(let e of n._idmap.entries()){let[t,n]=e;Fo(r,n),Ge(a,t,Ho(r,n))}return Object.keys(i).length>0&&(a.__shared={[r.target===`draft-2020-12`?`$defs`:`definitions`]:i}),{schemas:a}}let n=jo({...t,processors:Zs});return No(e,n),Fo(n,e),Ho(n,e)}const $s=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function ec(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const tc=(e,t)=>{an.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);$s.has(n)||($s.add(n),ec(n,`format`,e=>t=>cn(e,t)),ec(n,`flatten`,e=>t=>sn(e,t)),ec(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ze,2)}),ec(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ze,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},nc=/*@__PURE__*/ G(`ZodError`,tc),rc=/*@__PURE__*/ G(`ZodError`,tc,void 0,{Parent:Error}),ic=/* @__PURE__ */ un(rc),ac=/* @__PURE__ */ dn(rc),oc=/* @__PURE__ */ fn(rc),sc=/* @__PURE__ */ mn(rc),cc=/* @__PURE__ */ bn(rc),lc=/* @__PURE__ */ xn(rc),uc=/* @__PURE__ */ Sn(rc),dc=/* @__PURE__ */ Cn(rc),fc=/* @__PURE__ */ wn(rc),pc=/* @__PURE__ */ Tn(rc),mc=/* @__PURE__ */ En(rc),hc=/* @__PURE__ */ Dn(rc);function gc(){Xt.localeError||Zt(va())}function _c(){Xt.memoizer||Zt({memoizer:ha()})}const vc=/*@__PURE__*/ G(`ZodType`,(e,t)=>(gc(),Er.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(Qe(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ct(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Rl(e,t))},superRefine(e,t){return this.check(zl(e,t))},overwrite(e){return this.check(/* @__PURE__ */ yo(e))},optional(){return yl(this)},exactOptional(){return xl(this)},nullable(){return Cl(this)},nullish(){return yl(Cl(this))},nonoptional(e){return kl(this,e)},array(){return nl(this)},or(e){return al([this,e])},and(e){return ll(this,e)},transform(e){return Nl(this,_l(e))},default(e){return Tl(this,e)},prefault(e){return Dl(this,e)},catch(e){return jl(this,e)},pipe(e){return Nl(this,e)},readonly(){return Fl(this)},describe(e){let t=this.clone();return Sa.add(t,{description:e}),t},meta(...e){if(e.length===0)return Sa.get(this);let t=this.clone();return Sa.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Pt(this,`~standard`,{...kr(this),jsonSchema:{input:Go(this,`input`),output:Go(this,`output`)}})},set"~standard"(e){Nt(this,`~standard`,e)},parse:function e(t,n){return ic(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await ac(this,t,n,{callee:e})},safeParse(e,t){return oc(this,e,t)},async safeParseAsync(e,t){return sc(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Nt(this,`spa`,e)},validate(e,t){return _n(this,e,t)},validateAsync(e,t){return yn(this,e,t)},encode:function e(t,n){return cc(this,t,n,{callee:e})},decode:function e(t,n){return lc(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await uc(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await dc(this,t,n,{callee:e})},safeEncode(e,t){return fc(this,e,t)},safeDecode(e,t){return pc(this,e,t)},async safeEncodeAsync(e,t){return mc(this,e,t)},async safeDecodeAsync(e,t){return hc(this,e,t)},toJSONSchema(e){return Wo(this,{})(e)},get description(){return Sa.get(this)?.description},get _def(){return this._zod.def}}),yc=/*@__PURE__*/ G(`_ZodString`,(e,t)=>{Ar.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ss(e,t,n,r)},/*@__PURE__*/ Ft({format:e=>rs(e).format??null,minLength:e=>rs(e).minimum??null,maxLength:e=>rs(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ po(...e))},includes(...e){return this.check(/* @__PURE__ */ go(...e))},startsWith(...e){return this.check(/* @__PURE__ */ _o(...e))},endsWith(...e){return this.check(/* @__PURE__ */ vo(...e))},min(...e){return this.check(/* @__PURE__ */ uo(...e))},max(...e){return this.check(/* @__PURE__ */ lo(...e))},length(...e){return this.check(/* @__PURE__ */ fo(...e))},nonempty(...e){return this.check(/* @__PURE__ */ uo(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ mo(e))},uppercase(e){return this.check(/* @__PURE__ */ ho(e))},trim(){return this.check(/* @__PURE__ */ xo())},normalize(...e){return this.check(/* @__PURE__ */ bo(...e))},toLowerCase(){return this.check(/* @__PURE__ */ So())},toUpperCase(){return this.check(/* @__PURE__ */ Co())},slugify(){return this.check(/* @__PURE__ */ wo())}})),bc=/*@__PURE__*/ G(`ZodString`,(e,t)=>{Ar.init(e,t),yc.init(e,t)},{email(e){return this.check(/* @__PURE__ */ Ta(Ec,e))},url(e){return this.check(/* @__PURE__ */ ja(kc,e))},jwt(e){return this.check(/* @__PURE__ */ Ka(Wc,e))},emoji(e){return this.check(/* @__PURE__ */ Ma(Ac,e))},guid(e){return this.check(/* @__PURE__ */ Ea(Dc,e))},uuid(e){return this.check(/* @__PURE__ */ Da(Oc,e))},uuidv4(e){return this.check(/* @__PURE__ */ Oa(Oc,e))},uuidv6(e){return this.check(/* @__PURE__ */ ka(Oc,e))},uuidv7(e){return this.check(/* @__PURE__ */ Aa(Oc,e))},nanoid(e){return this.check(/* @__PURE__ */ Na(jc,e))},cuid(e){return this.check(/* @__PURE__ */ Pa(Mc,e))},cuid2(e){return this.check(/* @__PURE__ */ Fa(Nc,e))},ulid(e){return this.check(/* @__PURE__ */ Ia(Pc,e))},base64(e){return this.check(/* @__PURE__ */ Ua(Vc,e))},base64url(e){return this.check(/* @__PURE__ */ Wa(Hc,e))},xid(e){return this.check(/* @__PURE__ */ La(Fc,e))},ksuid(e){return this.check(/* @__PURE__ */ Ra(Ic,e))},ipv4(e){return this.check(/* @__PURE__ */ za(Lc,e))},ipv6(e){return this.check(/* @__PURE__ */ Ba(Rc,e))},cidrv4(e){return this.check(/* @__PURE__ */ Va(zc,e))},cidrv6(e){return this.check(/* @__PURE__ */ Ha(Bc,e))},e164(e){return this.check(/* @__PURE__ */ Ga(Uc,e))},datetime(e){return this.check(/* @__PURE__ */ qa(Sc,e))},date(e){return this.check(/* @__PURE__ */ Ja(Cc,e))},time(e){return this.check(/* @__PURE__ */ Ya(wc,e))},duration(e){return this.check(/* @__PURE__ */ Xa(Tc,e))}});function K(e){return/* @__PURE__ */ wa(bc,e)}const xc=/*@__PURE__*/ G(`ZodStringFormat`,(e,t)=>{jr.init(e,t),yc.init(e,t)}),Sc=/*@__PURE__*/ G(`ZodISODateTime`,(e,t)=>{Xr.init(e,t),xc.init(e,t)}),Cc=/*@__PURE__*/ G(`ZodISODate`,(e,t)=>{Zr.init(e,t),xc.init(e,t)}),wc=/*@__PURE__*/ G(`ZodISOTime`,(e,t)=>{Qr.init(e,t),xc.init(e,t)}),Tc=/*@__PURE__*/ G(`ZodISODuration`,(e,t)=>{$r.init(e,t),xc.init(e,t)}),Ec=/*@__PURE__*/ G(`ZodEmail`,(e,t)=>{Pr.init(e,t),xc.init(e,t)}),Dc=/*@__PURE__*/ G(`ZodGUID`,(e,t)=>{Mr.init(e,t),xc.init(e,t)}),Oc=/*@__PURE__*/ G(`ZodUUID`,(e,t)=>{Nr.init(e,t),xc.init(e,t)}),kc=/*@__PURE__*/ G(`ZodURL`,(e,t)=>{Hr.init(e,t),xc.init(e,t)}),Ac=/*@__PURE__*/ G(`ZodEmoji`,(e,t)=>{Ur.init(e,t),xc.init(e,t)}),jc=/*@__PURE__*/ G(`ZodNanoID`,(e,t)=>{Wr.init(e,t),xc.init(e,t)}),Mc=/*@__PURE__*/ G(`ZodCUID`,(e,t)=>{Gr.init(e,t),xc.init(e,t)}),Nc=/*@__PURE__*/ G(`ZodCUID2`,(e,t)=>{Kr.init(e,t),xc.init(e,t)}),Pc=/*@__PURE__*/ G(`ZodULID`,(e,t)=>{qr.init(e,t),xc.init(e,t)}),Fc=/*@__PURE__*/ G(`ZodXID`,(e,t)=>{Jr.init(e,t),xc.init(e,t)}),Ic=/*@__PURE__*/ G(`ZodKSUID`,(e,t)=>{Yr.init(e,t),xc.init(e,t)}),Lc=/*@__PURE__*/ G(`ZodIPv4`,(e,t)=>{ei.init(e,t),xc.init(e,t)}),Rc=/*@__PURE__*/ G(`ZodIPv6`,(e,t)=>{ri.init(e,t),xc.init(e,t)}),zc=/*@__PURE__*/ G(`ZodCIDRv4`,(e,t)=>{ii.init(e,t),xc.init(e,t)}),Bc=/*@__PURE__*/ G(`ZodCIDRv6`,(e,t)=>{oi.init(e,t),xc.init(e,t)}),Vc=/*@__PURE__*/ G(`ZodBase64`,(e,t)=>{li.init(e,t),xc.init(e,t)}),Hc=/*@__PURE__*/ G(`ZodBase64URL`,(e,t)=>{fi.init(e,t),xc.init(e,t)}),Uc=/*@__PURE__*/ G(`ZodE164`,(e,t)=>{pi.init(e,t),xc.init(e,t)}),Wc=/*@__PURE__*/ G(`ZodJWT`,(e,t)=>{hi.init(e,t),xc.init(e,t)}),Gc=/*@__PURE__*/ G(`ZodNumber`,(e,t)=>{gi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cs(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ Ft({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=rs(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=rs(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=rs(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>rs(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ oo(e,t))},gte(e,t){return this.check(/* @__PURE__ */ so(e,t))},min(e,t){return this.check(/* @__PURE__ */ so(e,t))},lt(e,t){return this.check(/* @__PURE__ */ io(e,t))},lte(e,t){return this.check(/* @__PURE__ */ ao(e,t))},max(e,t){return this.check(/* @__PURE__ */ ao(e,t))},int(e){return this.check(Jc(e))},safe(e){return this.check(Jc(e))},positive(e){return this.check(/* @__PURE__ */ oo(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ so(0,e))},negative(e){return this.check(/* @__PURE__ */ io(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ ao(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ co(e,t))},step(e,t){return this.check(/* @__PURE__ */ co(e,t))},finite(){return this}}));function Kc(e){return/* @__PURE__ */ Za(Gc,e)}const qc=/*@__PURE__*/ G(`ZodNumberFormat`,(e,t)=>{_i.init(e,t),Gc.init(e,t)});function Jc(e){return/* @__PURE__ */ $a(qc,e)}const Yc=/*@__PURE__*/ G(`ZodBoolean`,(e,t)=>{vi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ls(e,t,n,r)});function Xc(e){return/* @__PURE__ */ eo(Yc,e)}const Zc=/*@__PURE__*/ G(`ZodUnknown`,(e,t)=>{yi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Qc(){return/* @__PURE__ */ no(Zc)}const $c=/*@__PURE__*/ G(`ZodNever`,(e,t)=>{bi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r)});function el(e){return/* @__PURE__ */ ro($c,e)}const tl=/*@__PURE__*/ G(`ZodArray`,(e,t)=>{_c(),Si.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>As(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ uo(e,t))},nonempty(e){return this.check(/* @__PURE__ */ uo(1,e))},max(e,t){return this.check(/* @__PURE__ */ lo(e,t))},length(e,t){return this.check(/* @__PURE__ */ fo(e,t))},unwrap(){return this.element}});function nl(e,t){return/* @__PURE__ */ To(tl,e,t)}const rl=/*@__PURE__*/ G(`ZodObject`,(e,t)=>{_c(),Oi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ms(e,t,n,r),Ht(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return pl(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(Qe(this._zod.def,{catchall:e}))},passthrough(){return this.clone(Qe(this._zod.def,{catchall:Qc()}))},loose(){return this.clone(Qe(this._zod.def,{catchall:Qc()}))},strict(){return this.clone(Qe(this._zod.def,{catchall:el()}))},strip(){return this.clone(Qe(this._zod.def,{catchall:void 0}))},extend(e){return ht(this,e)},safeExtend(e){return _t(this,e)},merge(e){return vt(this,e)},pick(e){return ft(this,e)},omit(e){return mt(this,e)},partial(...e){return yt(vl,this,e[0])},exactPartial(...e){return yt(bl,this,e[0],`exactPartial`)},required(...e){return bt(Ol,this,e[0])}});function q(e,t){let n={type:`object`,shape:e??{},...U(t)};return new rl(n)}const il=/*@__PURE__*/ G(`ZodUnion`,(e,t)=>{Ai.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ns(e,t,n,r),e.options=t.options});function al(e,t){return new il({type:`union`,options:e,...U(t)})}const ol=/*@__PURE__*/ G(`ZodDiscriminatedUnion`,(e,t)=>{il.init(e,t),Mi.init(e,t)});function sl(e,t,n){return new ol({type:`union`,options:t,discriminator:e,...U(n)})}const cl=/*@__PURE__*/ G(`ZodIntersection`,(e,t)=>{Ni.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ps(e,t,n,r)});function ll(e,t){return new cl({type:`intersection`,left:e,right:t})}const ul=/*@__PURE__*/ G(`ZodRecord`,(e,t)=>{_c(),Ii.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zs(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function dl(e,t,n){return!t||!t._zod?new ul({type:`record`,keyType:K(),valueType:e,...U(t)}):new ul({type:`record`,keyType:e,valueType:t,...U(n)})}const fl=/*@__PURE__*/ G(`ZodEnum`,(e,t)=>{Li.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ys(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new fl({...t,checks:[],...U(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new fl({...t,checks:[],...U(r),entries:i})}});function pl(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new fl({type:`enum`,entries:n,...U(t)})}const ml=/*@__PURE__*/ G(`ZodLiteral`,(e,t)=>{Ri.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bs(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function hl(e,t){return new ml({type:`literal`,values:Array.isArray(e)?e:[e],...U(t)})}const gl=/*@__PURE__*/ G(`ZodTransform`,(e,t)=>{_c(),zi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ds(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Yt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(jt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(jt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function _l(e){return new gl({type:`transform`,transform:e})}const vl=/*@__PURE__*/ G(`ZodOptional`,(e,t)=>{Vi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yl(e){return new vl({type:`optional`,innerType:e})}const bl=/*@__PURE__*/ G(`ZodExactOptional`,(e,t)=>{Hi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function xl(e){return new bl({type:`optional`,innerType:e})}const Sl=/*@__PURE__*/ G(`ZodNullable`,(e,t)=>{Ui.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Cl(e){return new Sl({type:`nullable`,innerType:e})}const wl=/*@__PURE__*/ G(`ZodDefault`,(e,t)=>{Wi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ws(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Tl(e,t){return new wl({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const El=/*@__PURE__*/ G(`ZodPrefault`,(e,t)=>{Ki.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Dl(e,t){return new El({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const Ol=/*@__PURE__*/ G(`ZodNonOptional`,(e,t)=>{qi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function kl(e,t){return new Ol({type:`nonoptional`,innerType:e,...U(t)})}const Al=/*@__PURE__*/ G(`ZodCatch`,(e,t)=>{Xi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ks(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function jl(e,t){return new Al({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Ut(t)})}const Ml=/*@__PURE__*/ G(`ZodPipe`,(e,t)=>{Zi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qs(e,t,n,r),e.in=t.in,e.out=t.out});function Nl(e,t){return new Ml({type:`pipe`,in:e,out:t})}const Pl=/*@__PURE__*/ G(`ZodReadonly`,(e,t)=>{$i.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Js(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Fl(e){return new Pl({type:`readonly`,innerType:e})}const Il=/*@__PURE__*/ G(`ZodCustom`,(e,t)=>{ta.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ts(e,t,n,r)});function Ll(e,t){return/* @__PURE__ */ Eo(Il,e??(()=>!0),t)}function Rl(e,t={}){return/* @__PURE__ */ Do(Il,e,t)}function zl(e,t){return/* @__PURE__ */ Oo(e,t)}function Bl(e){return/* @__PURE__ */ Qa(Gc,e)}function Vl(e){return/* @__PURE__ */ to(Yc,e)}const Hl=1e4,Ul=`[a-z0-9][a-z0-9_-]*`,Wl=K().max(80).regex(RegExp(`^${Ul}(?:/${Ul})*$`),`invalid channel path`),Gl=e=>!e.includes(`\0`)&&e.isWellFormed(),Kl=e=>e.replaceAll(`\0`,``).toWellFormed(),ql=K().max(Hl).refine(e=>e.trim().length>0,`message text is empty`).refine(Gl,`message text has a NUL character or a lone surrogate`),Jl=Kc().int().positive(),Yl=/* @__PURE__ */ new Set([...Object.getOwnPropertyNames(Object.prototype),`prototype`]),Xl=e=>!Yl.has(e),Zl=K().max(64).regex(/^[a-z0-9][a-z0-9_.-]*$/,`invalid label key`).refine(Xl,`label key is a reserved name`),Ql=dl(Zl,K().max(256).refine(Gl,`label value has a NUL character or a lone surrogate`)),$l=K().max(64).regex(/^[a-z0-9_+-]+$/,`invalid emoji name`).refine(Xl,`emoji name is a reserved name`),eu=K().min(1).max(256);al([pl([`person`,`agent`,`deployment`,`workflow`,`external`]),hl(`profile`)]);const tu=e=>e===`profile`?`agent`:e;K().min(1).max(128).refine(Gl,`handle has a NUL character or a lone surrogate`);function nu(e){if(e===null)return null;try{return new URL(e).protocol===`https:`?e:null}catch{return null}}q({actor:eu,principal:K().min(1),profile:K().nullable(),session:K().nullable()});const ru=K().regex(/^[A-Za-z0-9_-]{22}$/,`invalid attachment id`);q({id:ru,name:K().min(1).max(255),type:K().min(1).max(255),size:Kc().int().nonnegative()}),K().regex(/^[A-Za-z][A-Za-z0-9-]{0,31}$/,`ids start with a letter and use up to 32 letters, numbers, and hyphens`);const iu=K().min(3).max(300),au=q({channel:iu.optional(),thread:iu,subthread:iu.nullable(),message:K().min(1).max(300),context:K().max(300).nullable()}),ou=q({author:K().min(1).max(256),text:K().max(Hl),createdAt:K().max(64).nullable(),files:nl(q({name:K().min(1).max(1e3),url:K().max(4e3).nullable()})).max(20)}),su=q({url:K().min(1).max(4e3),message:Jl.nullable(),snapshot:ou.nullable(),unavailable:K().max(300).nullable()}),cu=q({id:K().min(1),handle:K().min(1),name:K().min(1),avatar:K().nullable(),isBot:Xc()}),lu=q({type:pl([`image`,`file`,`video`,`audio`]),name:K().max(1e3).optional(),mimeType:K().max(255).optional(),size:Kc().int().nonnegative().optional(),url:K().max(4e3).optional(),fetchMetadata:dl(K(),K().max(4e3)).optional()}),uu=q({url:K().min(1).max(4e3),thread:iu,message:K().min(1).max(300),snapshot:ou.nullable()}),du=q({channel:iu,thread:iu,subthread:iu.nullable()}),fu=sl(`kind`,[q({kind:hl(`message`),...du.shape,message:K(),isRoot:Xc(),text:K(),context:K().nullable(),author:cu,files:nl(lu).max(20).optional(),links:nl(uu).max(10).optional()}),q({kind:hl(`edited`),...du.shape,message:K(),text:K(),author:cu,links:nl(uu).max(10).optional(),linksOnly:Xc().optional()}),q({kind:hl(`deleted`),...du.shape,message:K()}),q({kind:hl(`reaction`),...du.shape,message:K(),emoji:K(),added:Xc(),author:cu}),q({kind:hl(`lifecycle`),...du.omit({subthread:!0}).shape,type:K(),title:K(),url:K().nullable(),labels:dl(K(),K()),unset:nl(K()),owns:nl(K()).optional(),reply:K().nullable(),createRoot:Xc(),retitled:Xc().optional(),author:cu})]),pu=e=>e.slice(e.indexOf(`:`)+1).includes(`:`),mu=e=>{let t=e.indexOf(`:`),n=e.slice(t+1).indexOf(`:`);return n===-1?e:e.slice(0,t+1+n)},hu=(e,t)=>`${e}|${t}`,gu=K().min(1).max(128),_u=gu,vu=al([K(),nl(K())]).transform(e=>Array.isArray(e)?e:[e]),yu=K().regex(/^[a-z0-9][a-z0-9_.-]*(=.*)?$/,`label filters look like key, key=value, or key=a|b`).transform(e=>{let t=e.indexOf(`=`);return t===-1?[e,null]:[e.slice(0,t),e.slice(t+1).split(`|`)]}),bu=q({target:iu,kind:pl([`channel`,`thread`])}),xu=q({channel:K().optional(),re:_u.optional(),by:K().optional(),mentions:K().optional(),label:vu.pipe(nl(yu)).optional(),from:K().min(1).max(64).optional(),text:K().min(1).max(200).optional()}),Su=xu.extend({after:gu.optional(),before:_u.optional(),limit:Bl().int().min(1).max(500).optional()}),Cu=xu.extend({after:gu.optional(),limit:Bl().int().min(1).max(500).optional()}),wu=xu.extend({after:gu.optional(),wait:Bl().min(0).max(300).optional(),all:Vl().optional()}),Tu=q({channel:Wl.optional(),re:gu.optional(),text:K().max(Hl).default(``),labels:Ql.optional(),noSync:Xc().optional(),sync:nl(al([K().min(3).max(300),bu])).max(10).optional(),id:K().min(1).max(200).refine(Gl,`id has a NUL character or a lone surrogate`).optional(),attachments:nl(ru).max(10).optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a post needs `channel`; a reply needs `re`"}).refine(e=>!(e.noSync&&e.sync?.length),{message:"`noSync` and `sync` contradict each other"}),Eu=K().regex(/^\d+(\.\d+)?(s|m|h|d)$/,`durations look like 30s, 30m, 12h, or 1d`),Du=K().datetime({offset:!0}),Ou=q({channel:Wl.optional(),re:gu.optional(),text:K().max(Hl).default(``),labels:Ql.optional(),noSync:Xc().optional(),attachments:nl(ru).max(10).optional(),in:Eu.optional(),at:Du.optional(),every:Eu.optional(),until:Du.optional(),for:Eu.optional(),times:Kc().int().positive().optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a schedule needs `channel` for a new thread, or `re` for a reply"}).refine(e=>e.in!==void 0||e.at!==void 0||e.every!==void 0,{message:"say when: `in`, `at`, or `every`"}).refine(e=>e.in===void 0||e.at===void 0,{message:"`in` and `at` contradict each other"}).refine(e=>[e.until,e.for,e.times].filter(e=>e!==void 0).length<=1,{message:"pick one stop: `until`, `for`, or `times`"}).refine(e=>e.every!==void 0||e.until===void 0&&e.for===void 0&&e.times===void 0,{message:"`until`, `for`, and `times` stop a repeat: add `every`"}),ku=q({re:_u.optional(),channel:K().optional(),by:K().optional(),all:Vl().optional()}),Au=q({target:K().min(3).max(300)}),ju=q({channel:K().optional(),limit:Bl().int().min(1).max(500).optional()}),Mu=q({url:K().url().max(500).refine(e=>/^https:\/\//.test(e),`wake-ups go over https`).transform(e=>e.replace(/\/+$/,``)).nullable().optional(),watch:dl(K().max(100),q({tail:K().max(1e3),when:pl([`matches`,`enters`]).default(`matches`)})).refine(e=>Object.keys(e).length<=32,`a board registers at most 32 watchers`),sync:nl(q({key:K().min(1).max(64),platform:K().min(1).max(64),signIn:Xc().default(!1)})).max(32).optional()}),Nu=q({limit:Bl().int().min(1).max(50).optional(),wait:Bl().min(0).max(25).optional()}),Pu=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional(),skip:Xc().optional()}),Fu=q({target:K().min(1).max(4e3),limit:Bl().int().min(1).max(200).optional()}),Iu=q({url:K().url().max(4e3)}),Lu=q({actor:K().min(1).max(256)}),Ru=K().min(1).max(64),zu=q({thread:iu,message:K().min(1).max(300).optional()}),Bu=su.extend({message:gu.nullable()}),Vu=cu.extend({avatar:K().nullable().transform(nu)}),Hu={author:Vu,from:Ru.nullable()},Uu=q({key:Ru,channel:iu,thread:iu}),Wu={origin:zu.optional(),message:gu.optional()},Gu=sl(`op`,[q({op:hl(`post`),...Hu,origin:au.nullable().default(null),source:Uu.optional(),channel:Wl.optional(),re:gu.optional(),text:K().max(Hl).default(``),labels:Ql.optional(),noSync:Xc().optional(),attachments:nl(ru).max(10).optional(),links:nl(Bu).max(10).optional(),id:K().min(1).max(200).refine(Gl,`id has a NUL character or a lone surrogate`).optional()}),q({op:hl(`edit`),...Hu,...Wu,text:ql,source:Uu.optional()}),q({op:hl(`delete`),...Hu,...Wu}),q({op:hl(`react`),...Hu,...Wu,emoji:$l,remove:Xc().optional()}),q({op:hl(`labels`),...Hu,...Wu,set:Ql.optional(),unset:nl(Zl).optional()}),q({op:hl(`links`),...Hu,...Wu,links:nl(Bu).max(10)}),q({op:hl(`seen`),author:Vu})]),Ku=nl(K().min(1).max(300)).max(10).nullable(),qu=sl(`kind`,[q({kind:hl(`message`),message:gu,target:iu,external:q({thread:iu,message:K().min(1).max(300),asUser:hl(!0).optional()}),files:Ku.optional()}),q({kind:hl(`files`),message:gu,target:iu,files:Ku}),q({kind:hl(`failed`),message:gu,target:iu,error:K().min(1).max(500)}),q({kind:hl(`thread`),message:gu,target:iu,targetKind:pl([`channel`,`thread`]),cause:pl([`config`,`request`])})]),Ju=q({code:K().min(1).max(64).optional(),post:K().min(1).max(200).optional(),thread:iu.optional(),message:K().min(1).max(300).optional(),account:eu.optional(),person:eu.optional()}),Yu=q({message:vu.pipe(nl(gu).min(1).max(100))}),Xu=q({by:eu,since:Bl().int().nonnegative()}),Zu=q({events:nl(q({id:K().min(1).max(300),event:fu,raw:Qc()})).min(1).max(50)}),Qu=q({limit:Bl().int().min(1).max(50).optional()}),$u=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional()}),ed=q({sync:Ru}),td=q({sync:Ru,account:Vu,code:K().min(1).max(64),message:K().max(1024).optional(),method:pl([`code`,`consent`]).optional()}),nd=q({sync:Ru,code:K().min(1).max(64)}),rd=q({account:eu}),id=q({name:K().max(1024).nullable().optional(),type:K().max(1024).nullable().optional(),size:Kc().int().positive().max(Ae,`direct uploads are at most ${Ae/1024/1024} MB`)}),ad=q({text:ql}),od=q({}).optional(),sd=q({status:K().trim().min(1).max(100).optional()}).optional(),cd=q({emoji:$l,remove:Xc().optional()}),ld=q({set:Ql.optional(),unset:nl(Zl).optional()}).refine(e=>e.set!==void 0||e.unset!==void 0,{message:"nothing to change: pass `set` or `unset`"}),ud={discovery:{method:`GET`,path:`/`},me:{method:`GET`,path:`/me`},channels:{method:`GET`,path:`/channels`},actors:{method:`GET`,path:`/actors`},messages:{method:`GET`,path:`/messages`,query:Su},message:{method:`GET`,path:`/messages/:id`},threads:{method:`GET`,path:`/threads`,query:Cu},post:{method:`POST`,path:`/messages`,body:Tu},edit:{method:`POST`,path:`/messages/:id/edit`,body:ad},delete:{method:`POST`,path:`/messages/:id/delete`,body:od},react:{method:`POST`,path:`/messages/:id/reactions`,body:cd},label:{method:`POST`,path:`/messages/:id/labels`,body:ld},sync:{method:`POST`,path:`/messages/:id/sync`,body:Au},synced:{method:`GET`,path:`/messages/:id/sync`},linked:{method:`GET`,path:`/links`,query:Iu},typing:{method:`POST`,path:`/messages/:id/typing`,body:sd},schedule:{method:`POST`,path:`/schedules`,body:Ou},schedules:{method:`GET`,path:`/schedules`,query:ku},cancelSchedule:{method:`POST`,path:`/schedules/:id/cancel`},posted:{method:`GET`,path:`/posts/:id`},inbox:{method:`GET`,path:`/inbox/:key`,query:ju},inboxPush:{method:`POST`,path:`/inbox/:key`,body:Zu},inboxNext:{method:`GET`,path:`/inbox/:key/next`,query:Qu},inboxAck:{method:`POST`,path:`/inbox/:key/:id/ack`,body:$u},syncImport:{method:`POST`,path:`/sync/imports`,body:Gu},syncReceipt:{method:`POST`,path:`/sync/receipts`,body:qu},syncThread:{method:`GET`,path:`/sync/threads/:thread`},syncFind:{method:`GET`,path:`/sync/find`,query:Ju},syncCopies:{method:`GET`,path:`/sync/copies`,query:Yu},syncRoots:{method:`GET`,path:`/sync/roots`,query:Xu},syncCode:{method:`POST`,path:`/sync/codes`,body:ed},syncAccount:{method:`POST`,path:`/sync/accounts`,body:td},syncUnlink:{method:`POST`,path:`/sync/accounts/unlink`,body:rd},readSource:{method:`GET`,path:`/sources/:key/read`,query:Fu},webhook:{method:`POST`,path:`/webhooks/:key`},events:{method:`GET`,path:`/events`,query:wu},avatar:{method:`GET`,path:`/avatars/:name`},upload:{method:`POST`,path:`/attachments`},attachment:{method:`GET`,path:`/attachments/:id`},uploadStart:{method:`POST`,path:`/attachments/uploads`,body:id},uploadFinish:{method:`POST`,path:`/attachments/uploads/:id`},openapi:{method:`GET`,path:`/openapi.json`},identity:{method:`GET`,path:`/identity`},signIn:{method:`GET`,path:`/identity/sign-in`,query:nd},signedIn:{method:`GET`,path:`/identity/signed-in`,query:nd},identityUnlink:{method:`POST`,path:`/identity/unlink`,body:Lu},watchers:{method:`GET`,path:`/watchers`},register:{method:`POST`,path:`/watchers`,body:Mu},matches:{method:`GET`,path:`/watchers/matches`,query:Nu},ack:{method:`POST`,path:`/watchers/matches/:id/ack`,body:Pu},wake:{method:`POST`,path:`/wake`}};async function*dd(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=()=>void n.cancel().catch(()=>{});t?.addEventListener(`abort`,a,{once:!0});try{for(;;){let{value:e,done:t}=await n.read();if(t)return;i+=r.decode(e,{stream:!0});let a;for(;(a=i.search(/\r?\n\r?\n/))!==-1;){let e=i.slice(0,a);i=i.slice(a).replace(/^\r?\n\r?\n/,``);let t={},n=[];for(let r of e.split(/\r?\n/)){if(r===``||r.startsWith(`:`))continue;let e=r.indexOf(`:`),i=e===-1?r:r.slice(0,e),a=e===-1?``:r.slice(e+1).replace(/^ /,``);i===`data`?n.push(a):i===`id`?t.id=a:i===`event`&&(t.event=a)}n.length>0&&(t.data=n.join(`
|
|
344
|
-
`)),(t.id!==void 0||t.data!==void 0)&&(yield t)}}}finally{t?.removeEventListener(`abort`,a),n.releaseLock()}}var fd=class extends Error{code;status;constructor(e,t,n){super(t),this.name=`BoardError`,this.code=e,this.status=n}};const pd=async e=>typeof e==`function`?await e():e,md=e=>{let{at:t,until:n,...r}=hd(e);return{...r,...t===void 0?{}:{at:t instanceof Date?t.toISOString():t},...n===void 0?{}:{until:n instanceof Date?n.toISOString():n}}},hd=e=>{if(typeof e==`string`)return{text:e};let{attachments:t,...n}=e;return t?.length?{...n,attachments:t.map(e=>typeof e==`string`?e:e.id)}:n},gd={ms:1,s:1e3,m:6e4,h:36e5,d:864e5};function _d(e){if(typeof e==`number`)return e;let t=e.trim().match(/^(\d+(?:\.\d+)?)(ms|s|m|h|d)?$/);if(!t)throw new fd(`invalid_duration`,`invalid duration: ${e}`,0);return Number(t[1])*gd[t[2]??`ms`]}const vd=e=>encodeURIComponent(e);function yd(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null){if(n===`label`){let e=Array.isArray(r)?r:typeof r==`object`?Object.entries(r).map(([e,t])=>`${e}=${String(t)}`):[r];for(let n of e)t.append(`label`,String(n))}else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}const bd=(e,t)=>t?.length?{...e,unknownMentions:t}:e;function xd(e){let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>globalThis.fetch(e,t)),r=e.storeFetch??((e,t)=>globalThis.fetch(e,t));async function i(t,n){let r={...e.headers?await pd(e.headers):{}};if(!t)return r;e.token!==void 0&&(r.authorization=`Bearer ${await pd(e.token)}`);let i=n===void 0?e.profile===void 0?null:await pd(e.profile):n;if(i!==null){let{name:e,avatar:t}=typeof i==`string`?{name:i,avatar:void 0}:i;r[`x-board-profile`]=e,t&&(r[`x-board-avatar`]=t)}else{let t=e.person===void 0?null:await pd(e.person);t?.name&&(r[`x-board-name`]=encodeURIComponent(t.name)),t?.avatar&&(r[`x-board-avatar`]=t.avatar)}let a=n===void 0?e.session===void 0?null:await pd(e.session):null;a&&(r[`x-board-session`]=a);let o=e.handle===void 0?null:await pd(e.handle);return o&&(r[`x-board-handle`]=o),r}async function a(e,r,a={}){let o=await n(`${t}${r}`,{method:e,headers:{...await i(a.auth??!0),...a.body===void 0?{}:{"content-type":`application/json`},...a.headers},...a.body===void 0?{}:{body:JSON.stringify(a.body)},...a.signal?{signal:a.signal}:{}});if(!o.ok)throw await Sd(o);return o}async function o(e,t,n){return await(await a(e,t,n)).json()}let s=(e={})=>e;async function c(e={},t){return o(`GET`,`/events${yd(e)}`,t?{signal:t}:{})}return{url:t,request:async(e,r={})=>n(`${t}${e}`,{method:r.method??`GET`,headers:{...r.headers,...await i(!0,r.as)},...r.body?{body:r.body}:{},...r.signal?{signal:r.signal}:{}}),discovery:()=>o(`GET`,`/`,{auth:!1}),me:()=>o(`GET`,`/me`),channels:async()=>(await o(`GET`,`/channels`)).channels,actors:async()=>(await o(`GET`,`/actors`)).actors,identity:()=>o(`GET`,`/identity`),unlinkAccount:e=>o(`POST`,`/identity/unlink`,{body:{actor:e}}),messages:(e={})=>o(`GET`,`/messages${yd(e)}`),thread:e=>o(`GET`,`/messages/${vd(e)}`),posted:async e=>(await o(`GET`,`/posts/${vd(e)}`)).message,threads:(e={})=>o(`GET`,`/threads${yd(e)}`),async post(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{channel:e,...hd(t)}});return bd(n,r)},async reply(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{re:e,...hd(t)}});return bd(n,r)},async schedule(e,t){let{schedule:n,unknownMentions:r}=await o(`POST`,`/schedules`,{body:{...typeof e==`string`?{channel:e}:{re:e.re},...md(t)}});return bd(n,r)},schedules:async(e={})=>(await o(`GET`,`/schedules${yd(e)}`)).schedules,cancelSchedule:e=>o(`POST`,`/schedules/${vd(e)}/cancel`,{body:{}}),async upload(e){let a=e.type||(e.data instanceof Blob?e.data.type:``)||Ne(e.name),s=e.data instanceof Blob?e.data.size:e.data.byteLength;if(s>4194304){if(s>104857600)throw new fd(`too_large`,`attachments are at most ${Ae/1024/1024} MB`,413);let t=await o(`POST`,`/attachments/uploads`,{body:{name:e.name,type:a,size:s}}).catch(e=>{throw e instanceof fd&&e.status===404&&e.code===`not_found`?new fd(`too_large`,`this board takes files of at most ${Oe/1024/1024} MB`,413):e}),n=await r(t.url,{method:`PUT`,headers:t.headers,body:e.data});if(!n.ok)throw new fd(`upload_failed`,`the blob store refused the file: ${n.status} ${(await n.text().catch(()=>``)).slice(0,300)||n.statusText}`,n.status);return(await o(`POST`,`/attachments/uploads/${encodeURIComponent(t.id)}`,{body:{}})).attachment}let c=await n(`${t}/attachments`,{method:`POST`,headers:{...await i(!0),"content-type":a,"x-board-filename":encodeURIComponent(e.name)},body:e.data});if(!c.ok)throw await Sd(c);return(await c.json()).attachment},download:(e,t={})=>a(`GET`,`/attachments/${encodeURIComponent(e)}`,t.signal?{signal:t.signal}:{}),edit:(e,t)=>o(`POST`,`/messages/${vd(e)}/edit`,{body:{text:t}}),delete:e=>o(`POST`,`/messages/${vd(e)}/delete`,{body:{}}),react:(e,t,n={})=>o(`POST`,`/messages/${vd(e)}/reactions`,{body:{emoji:Ee(t),...n}}),label:(e,t)=>o(`POST`,`/messages/${vd(e)}/labels`,{body:t}),typing:async(e,t)=>(await o(`POST`,`/messages/${vd(e)}/typing`,{body:t?{status:t}:{}})).targets,sync:((e,t)=>t===void 0?o(`GET`,`/messages/${vd(e)}/sync`):o(`POST`,`/messages/${vd(e)}/sync`,{body:{target:t}})),linked:e=>o(`GET`,`/links${yd({url:e})}`),inbox:async(e,t={})=>(await o(`GET`,`/inbox/${e}${yd(t)}`)).events,register:e=>o(`POST`,`/watchers`,{body:e}),watchers:async()=>(await o(`GET`,`/watchers`)).watchers,matches:async(e={})=>{let{signal:t,...n}=e;return(await o(`GET`,`/watchers/matches${yd(n)}`,t?{signal:t}:{})).matches},ack:(e,t)=>o(`POST`,`/watchers/matches/${encodeURIComponent(e)}/ack`,{body:t}),readSource:(e,t,n={})=>o(`GET`,`/sources/${e}/read${yd({target:t,...n})}`),poll:c,syncImport:e=>o(`POST`,`/sync/imports`,{body:e}),syncReceipt:e=>o(`POST`,`/sync/receipts`,{body:e}),syncThread:e=>o(`GET`,`/sync/threads/${vd(e)}`),syncFind:(e,t={})=>o(`GET`,`/sync/find${yd(e)}`,t.signal?{signal:t.signal}:{}),syncCopies:async e=>(await o(`GET`,`/sync/copies?${e.map(e=>`message=${encodeURIComponent(e)}`).join(`&`)}`)).copies,syncRoots:async(e,t)=>(await o(`GET`,`/sync/roots${yd({by:e,since:t instanceof Date?t.getTime():t})}`)).roots,inboxPush:(e,t)=>o(`POST`,`/inbox/${vd(e)}`,{body:{events:t}}),inboxNext:async(e,t={})=>(await o(`GET`,`/inbox/${vd(e)}/next${yd(t)}`)).items,inboxAck:(e,t,n)=>o(`POST`,`/inbox/${vd(e)}/${vd(t)}/ack`,{body:n}),syncCode:e=>o(`POST`,`/sync/codes`,{body:{sync:e}}),syncAccount:e=>o(`POST`,`/sync/accounts`,{body:e}),syncUnlink:e=>o(`POST`,`/sync/accounts/unlink`,{body:{account:e}}),async*events(e={},t={}){let n=e.after,r=0;for(;!t.signal?.aborted;){let i;try{i=await a(`GET`,`/events${yd({...s(e),after:n})}`,{headers:{accept:`text/event-stream`},...t.signal?{signal:t.signal}:{}})}catch(e){if(t.signal?.aborted)return;if(e instanceof fd&&e.status>=400&&e.status<500)throw e;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)));continue}r=0;try{for await(let e of dd(i.body,t.signal))e.id!==void 0&&(n=e.id),e.event===`board`&&e.data&&(yield JSON.parse(e.data))}catch{if(t.signal?.aborted)return;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)))}}},async wait(e={},t={}){let n=Date.now()+_d(t.timeout??`30m`),r=e.after??(await c({...e,after:void 0,wait:0},t.signal)).cursor;for(;Date.now()<n&&!t.signal?.aborted;){let i=Math.max(0,Math.min(25,Math.ceil((n-Date.now())/1e3))),a=await c({...e,after:r,wait:i},t.signal);if(a.events.length>0)return a.events[0];r=a.cursor}return null}}}async function Sd(e){try{let t=await e.json();if(t.error?.message)return new fd(t.error.code??`error`,t.error.message,e.status)}catch{}return new fd(`http_error`,`${e.status} ${e.statusText}`,e.status)}const Cd=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);async function wd(e){return Cd(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))))}async function Td(...e){let t=new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(e)))).slice(0,16);t[6]=t[6]&15|128,t[8]=t[8]&63|128;let n=Cd(t);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20,32)}`}const Ed=/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,Dd=async(e,t)=>`key:${e}:${(await wd(`board-key\u001f${t}`)).slice(0,32)}`;var Od=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}},kd=class extends Od{response;constructor(e){super(e.status,`rejected`,`rejected with ${e.status}`),this.response=e}};const Ad=(e,t=`invalid_request`)=>new Od(400,t,e),jd=e=>new Od(401,`unauthorized`,e),Md=e=>new Od(403,`forbidden`,e),Nd=(e,t=`not_found`)=>new Od(404,t,e),Pd=()=>new Od(409,`duplicate_id`,`that id was already used for a different write`),Fd=(e,t=200,n)=>new Response(JSON.stringify(e),{status:t,headers:{"content-type":`application/json`,...n}});function Id(e){if(e instanceof kd)return e.response;if(e instanceof Od)return Fd({error:{code:e.code,message:e.message}},e.status);if(e instanceof nc){let t=e.issues[0],n=t?.path.length?`${t.path.join(`.`)}: `:``;return Fd({error:{code:`invalid_request`,message:`${n}${t?.message??`invalid request`}`}},400)}let t=e?.code;return t===`INVALID_PAYLOAD`?Fd({error:{code:`invalid_request`,message:e.message}},400):t===`PARTIAL_DUPLICATE_BATCH`||t===`DUPLICATE_EVENT_ID`?Id(Pd()):t===`STORE_UNAVAILABLE`||t===`STORE_NOT_CONFIGURED`?Fd({error:{code:`unavailable`,message:e.message}},503):(console.error(`[board]`,e),Fd({error:{code:`internal`,message:`internal error`}},500))}const Ld=`0.18.1`,Rd=[`avatar`,`openapi`,`webhook`,`signIn`,`signedIn`,`identityUnlink`,`sync`],zd=/* @__PURE__ */ `discovery.me.channels.actors.identity.messages.threads.message.post.posted.edit.delete.react.label.schedule.schedules.cancelSchedule.upload.attachment.uploadStart.uploadFinish.watchers.register.matches.ack.events.syncImport.syncReceipt.syncThread.syncFind.syncCopies.syncRoots.inboxPush.inboxNext.inboxAck.inbox.syncCode.syncAccount.syncUnlink.typing.readSource.synced.linked`.split(`.`),Bd=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function Vd(e,t,n,r){let i=t.split(`/`).filter(Boolean),a=i.map(e=>e.startsWith(`:`)?`/([^/]+)`:`/${Bd(e)}`).join(``);return{method:e,pattern:RegExp(`${a}$`),names:i.filter(e=>e.startsWith(`:`)).map(e=>e.slice(1)),target:n,segments:i.length,literals:i.filter(e=>!e.startsWith(`:`)).length,own:r}}function Hd(e,t){let n=[...Rd.map(e=>Vd(ud[e].method,ud[e].path,{kind:`board`,name:e},!1)),...zd.filter(e=>e!==`discovery`).map(e=>Vd(ud[e].method,ud[e].path,{kind:`protocol`,name:e},!1)),...e.map(e=>Vd(e.method,e.path,{kind:`backend`,route:e},!0))].sort((e,t)=>t.segments-e.segments||t.literals-e.literals||Number(t.own)-Number(e.own)),r=(e,t,n)=>{let r={};try{e.names.forEach((e,t)=>r[e]=decodeURIComponent(n[t]))}catch{return null}let i=e.names[0];return{target:e.target,base:t,param:i===void 0?null:r[i],params:r}},i=e=>({target:{kind:`protocol`,name:`discovery`},base:e,param:null,params:{},root:!0});return function(e,a){let o=a.length>1?a.replace(/\/+$/,``):a;if(t!==void 0){let a=t.replace(/\/+$/,``);if(o!==a&&!o.startsWith(`${a}/`))return null;let s=o.slice(a.length)||`/`;if(s===`/`)return e===`GET`?i(a):null;for(let t of n){let n=t.method===e?s.match(RegExp(`^${t.pattern.source}`)):null;if(n)return r(t,a,n.slice(1))}return null}for(let t of n){if(t.method!==e)continue;let n=o.match(t.pattern);if(n)return r(t,o.slice(0,n.index),n.slice(1))}return e===`GET`?i(o===`/`?``:o):null}}function Ud(e){let t={};for(let n of new Set(e.searchParams.keys())){let r=e.searchParams.getAll(n);t[n]=r.length>1?r:r[0]}return t}async function Wd(e){let t=await e.text();if(t.trim()!==``)try{return JSON.parse(t)}catch{throw Ad(`request body is not valid JSON`)}}const Gd=()=>new Od(413,`too_large`,`attachments are at most ${Oe/1024/1024} MB`);async function Kd(e,t){if(Number(e.headers.get(`content-length`)??0)>t)throw Gd();let n=[],r=0;for await(let i of e.body??[]){if(r+=i.byteLength,r>t)throw Gd();n.push(i)}let i=new Uint8Array(r),a=0;for(let e of n)i.set(e,a),a+=e.byteLength;return i}function qd(){let e={};for(let[t,n]of Object.entries(ud)){let r=n.path.replace(/:(\w+)/g,`{$1}`),i={operationId:t};`query`in n&&(i[`x-query-schema`]=Qs(n.query,{io:`input`})),`body`in n&&(i.requestBody={content:{"application/json":{schema:Qs(n.body,{io:`input`})}}}),(e[r]??={})[n.method.toLowerCase()]=i}return{openapi:`3.1.0`,info:{title:`board`,version:Ld},paths:e}}const Jd={re:{type:`string`},by:{type:`string`},mentions:{type:`string`},label:{type:`string`,multiple:!0},from:{type:`string`},text:{type:`string`}};function Yd(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];r===`--mentions`?e[n+1]?.startsWith(`@`)?t.push(`--mentions=${e[++n]}`):t.push(`--mentions=me`):t.push(r)}return t}function Xd(e){let t=[],n=null,r=null;for(let i=0;i<e.length;i++){let a=e[i];r?a===r?r=null:a===`\\`&&r===`"`&&i+1<e.length?n+=e[++i]:n+=a:/\s/.test(a)?(n!==null&&t.push(n),n=null):a===`"`||a===`'`?(r=a,n??=``):n=a===`\\`&&i+1<e.length?(n??``)+e[++i]:(n??``)+a}if(r)throw Error(`unterminated ${r}`);return n!==null&&t.push(n),t}const Zd={...Jd,all:{type:`boolean`}};function Qd(e){let t={},n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i===`--`){n.push(...e.slice(r+1));break}if(!i.startsWith(`-`)||i===`-`){n.push(i);continue}let a=i.indexOf(`=`),o=i.startsWith(`--`)?i.slice(2,a===-1?void 0:a):null,s=o!==null&&Object.hasOwn(Zd,o)?Zd[o]:null;if(!s)throw Error(`${o===null?i.slice(0,2):`--${o}`} isn't a filter`);if(s.type===`boolean`){if(a!==-1)throw Error(`--${o} takes no value`);t[o]=!0;continue}let c;if(a!==-1)c=i.slice(a+1);else{let t=e[r+1];if(t===void 0||t.length>1&&t.startsWith(`-`))throw Error(`--${o} needs a value`);c=t,r++}t[o]=`multiple`in s?[...t[o]??[],c]:c}return{values:t,positionals:n}}function $d(e){let{values:t,positionals:n}=Qd(Yd(Xd(e)));if(n.length>1)throw Error(`expected one channel, got: ${n.join(` `)}`);let r=n[0],i=xu.safeParse({...r?{channel:r}:{},...t.re?{re:t.re.replace(/^#/,``)}:{},...t.by?{by:t.by.replace(/^@/,``)}:{},...t.mentions?{mentions:t.mentions.replace(/^@/,``)}:{},...t.label?.length?{label:t.label}:{},...t.from?{from:t.from}:{},...t.text?{text:t.text}:{}});if(!i.success){let e=i.error.issues[0];throw Error(`${e?.path.length?`--${String(e.path[0])}: `:``}${e?.message??`invalid filters`}`)}return{filters:i.data,all:t.all===!0}}const ef=e=>e.channel!==void 0||e.re!==void 0||e.by!==void 0||e.mentions!==void 0||e.from!==void 0||e.text!==void 0||(e.label?.length??0)>0;function tf(e,t){let n,r;try{({filters:n,all:r}=$d(t.tail))}catch(t){throw Error(`watch ${e}: ${t.message}`)}if(n.mentions===`me`)throw Error(`watch ${e}: a watcher has no "me": use --mentions @handle`);let i=ef(n);if(t.when===`enters`&&!i)throw Error(`watch ${e}: \`when: enters\` needs a filter to enter`);return{filters:n,criteria:i,enters:t.when===`enters`,all:r}}const nf=(e,t)=>e<t?-1:+(e>t);function rf(e,t=[]){let n=Object.keys(e).sort(nf).map(t=>[t,e[t].tail,e[t].when]);return t.length>0&&n.push([`sync`,[...t].sort((e,t)=>nf(e.key,t.key)).map(e=>[e.key,e.platform,e.signIn])]),JSON.stringify(n)}const af=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,of=/* @__PURE__ */ new Set([`identity`,`edit`,`delete`,`schedule`,`cancelSchedule`,`upload`,`uploadStart`,`uploadFinish`,`watchers`,`register`,`matches`,`ack`,`syncImport`,`syncReceipt`,`syncThread`,`syncFind`,`syncCopies`,`syncRoots`,`inboxPush`,`inboxNext`,`inboxAck`,`inbox`,`syncCode`,`syncAccount`,`syncUnlink`]);function sf(e){let t=e.replace(/[^A-Za-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``);return/^[A-Za-z]/.test(t)||(t=`u-${t}`),t.slice(0,32).replace(/-+$/,``)}function cf(e,t){let n=new Set([...t,`middleware`,`client`].map(e=>e.toLowerCase())),r=sf(e),i=r;for(let e=2;n.has(i.toLowerCase());e++)i=`${r.slice(0,31-String(e).length)}-${e}`;return i}function lf(e){let{access:t}=e.principal;if(t.everywhere(`manage`))return null;let n=Object.entries(t.summary()).map(([e,t])=>`${e}=${t.join(`,`)}`);return n.length>0?n.join(`;`):`*=`}const uf=e=>((e instanceof Error?e.message:String(e))||`unknown error`).slice(0,500),df=e=>{throw e instanceof fd?new Od(e.status>=400?e.status:502,e.code,e.message):e instanceof Od||e instanceof Error&&e.name===`AbortError`?e:new Od(502,`unreachable`,`the board didn't answer: ${uf(e)}`)};function ff(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null&&r!==!1){if(n===`label`&&Array.isArray(r))for(let[e,n]of r)t.append(`label`,n===null?e:`${e}=${n.join(`|`)}`);else if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}function pf(e,t){let n=(t.headers.get(`content-disposition`)??``).match(/filename\*=UTF-8''([^;]+)/)?.[1],r=`file`;try{n&&(r=decodeURIComponent(n))}catch{}return{attachment:{id:e,name:r,type:t.headers.get(`content-type`)??`application/octet-stream`,size:Number(t.headers.get(`content-length`)??0)},data:t.body??/* @__PURE__ */ new Uint8Array}}function mf(e,t,n){if(e!==void 0&&!/^https?:\/\/[^/]/.test(e))throw Error(`http: ${e} isn't a URL: pass the board's, like https://board.example.com/api/board`);if(e===void 0&&!n)throw Error(`http: pass the board's URL: outside Node there's no environment to find it in`);let r=(e??n.url()).replace(/\/+$/,``),i=t.fetch??n?.fetch(r)??((e,t)=>globalThis.fetch(e,t)),a=null,o={},s=[],c=null,l=()=>c??=wd(rf(o,s)).then(e=>e.slice(0,32)),u=()=>{if(!a)throw Error(`http: this backend isn't serving a board yet: pass it to board({ backend })`);return a},d=(e,t)=>xd({url:r,fetch:i,profile:e===void 0?()=>n?.profile().profile??null:e,session:t||e===null?null:()=>n?.profile().session??null}),f=d(null,!0),p=/* @__PURE__ */ new Map;function m(e){if(!af.test(e))throw new Od(400,`invalid_request`,`as: ${e}: profiles start with a letter and use up to 32 letters, numbers, and hyphens`);let t=p.get(e);return t||p.set(e,t=d(e,!0)),t}let h=/* @__PURE__ */ new Map;function g(e){let t=JSON.stringify(e??(e===null?null:`\0`)),n=h.get(t);return n||h.set(t,n=d(e,!1)),n}function _(e){return e.origin.via?.kind===`engine`?f:e.origin.via?.kind===`client`?(e.self!==null&&m(e.self),g(`profile`in e?e.profile:e.self??void 0)):m(e.self??`client`)}let v=null,y=()=>(v??=i(r).then(async e=>{if(!e.ok)throw new Od(e.status>=400?e.status:502,`no_board`,`no board at ${r} (${e.status})`);return await e.json()},df)).catch(e=>{throw v=null,e}),b=null,x=()=>b??=f.me().then(e=>e.principal).catch(e=>{throw b=null,e}),S=async e=>Dd(await x(),e);async function C(e,t,n,i){let a=ud[t],o={...n},s=a.path.replace(/:(\w+)/g,(e,t)=>{let n=o[t];return delete o[t],encodeURIComponent(String(n))}),c;if(t===`upload`){let{data:t,name:r,type:a}=n;if(t.byteLength>4194304){let n=await e.upload({data:t,name:r??`file`,...a?{type:a}:{}}).catch(df);return Response.json({attachment:n})}c=await e.request(s,{method:`POST`,body:t,headers:{...a?{"content-type":a}:{},...r===null?{}:{"x-board-filename":encodeURIComponent(r)}},signal:i}).catch(df)}else c=a.method===`GET`?await e.request(`${s}${ff(o)}`,{signal:i}).catch(df):await e.request(s,{method:`POST`,body:new TextEncoder().encode(JSON.stringify(o)),headers:{"content-type":`application/json`},signal:i}).catch(df);if(c.ok)return c;try{let e=await c.json();if(e.error?.message)throw new Od(c.status,e.error.code??`error`,e.error.message)}catch(e){if(e instanceof Od)throw e}throw new Od(502,`remote_error`,`${r} answered ${c.status}`)}async function w(e,t,n,a){if(e===`me`){let{principal:e,author:n,actor:r}=t;return{actor:r.id,principal:e.id,kind:r.kind,handle:r.handle,name:r.name,avatar:r.avatar,profile:n.profile,session:n.session,expiresAt:e.expiresAt?.toISOString()??null,can:e.access.summary()}}if(of.has(e))throw Md(`this board's callers act as its project on ${r}, which can't tell them apart: ${e} is the project's own to do there`);let s=lf(t),c=t.actor.avatar?.startsWith(`https://`)?t.actor.avatar:void 0,l=xd({url:r,fetch:i,profile:{name:cf(t.actor.handle,Object.keys(o)),...c?{avatar:c}:{}},session:null,...s===null?{}:{headers:{"x-board-scope":s}}});(e===`post`||e===`posted`)&&typeof n.id==`string`&&(n={...n,id:await S(await Td(`board-gateway`,t.principal.id,n.id)).catch(df)});let u=await C(l,e,n,a);return e===`attachment`?pf(String(n.id),u):u.json()}async function T(e,t,n,r){let i=I();if(`identity`in t)return w(e,t.identity,n,r);let a=_(t);`self`in t&&t.origin.via?.kind===`engine`&&await i,(e===`post`||e===`posted`)&&`self`in t&&typeof n.id==`string`&&Ed.test(n.id)&&(n={...n,id:await S(n.id).catch(df)});let o=await C(a,e,n,r);return e===`attachment`?pf(String(n.id),o):o.json()}let E={...Object.fromEntries(zd.map(e=>[e,(t,n,r)=>T(e,t,n,r)])),async discovery(){return y()},async readSource(e,t,n){return`self`in e&&u().sync.some(e=>e.key===t.key)?u().readSource(t.key,t.target,t.limit??50):T(`readSource`,e,t,n)},async synced(e,t,n){let{targets:r}=await T(`synced`,e,t,n);return{targets:await Promise.all(r.map(async e=>({...e,url:e.url??(e.thread!==null&&e.message!==null?await u().linkOf(e.key,e.thread,e.message):null)})))}},async linked(e,t,n){let r=()=>new Od(404,`message_not_found`,`no message on this board for that link`),i=await(async()=>{for(let{platform:e,thread:r,message:i}of u().locate(t.url))for(let t of u().sync.filter(t=>t.platform===e)){let e=await f.syncFind({thread:`${t.key}:${r}`,...i===null?{}:{message:i}},{signal:n}).catch(df),a=i===null?e.thread===null?null:(await f.syncThread(e.thread).catch(df)).root:e.message;if(a!==null)return a}return null})();if(i===null)return T(`linked`,e,t,n);try{return await E.message(e,{id:i},n)}catch(e){throw e instanceof Od&&e.status===404?r():e}},async typing(e,t,n){let{targets:r}=await T(`typing`,e,t,n);if(!(`self`in e)||u().sync.length===0)return{targets:r};let{message:i,replies:a}=await E.message(e,{id:t.id},n),o=await u().typing([i,...a],t.status).catch(e=>(console.warn(`[board] skipped typing where this board syncs:`,uf(e)),[]));return{targets:[...r,...o]}}},D=e=>e?.startsWith(`https://`)?e:null,O=null,k=null;async function A(e){let t=await l();return O&&O.url===e&&O.result.hash===t&&Date.now()-O.at<1e4?O.result:(k??=f.register({url:e,watch:o,...s.length>0?{sync:s}:{}}).then(t=>(O={url:e,at:Date.now(),result:t},t)).finally(()=>{k=null}),k)}async function j(e){let t={};if(!u().subscriptions[e.watcher])t={skip:!0};else try{await u().run(e.watcher,e.event,{trigger:`watch:${e.watcher}:${e.id}`,attempt:e.attempt+1})}catch(n){console.error(`[board] watcher ${e.watcher} failed:`,n),t={error:uf(n)}}await f.ack(e.id,{lease:e.lease,...t}).catch(e=>console.error(`[board] couldn't ack a match:`,uf(e)))}async function M(){let e=0,t=Date.now()+24e4;for(;Date.now()<t;){let t=await f.matches({limit:10});if(t.length===0)break;await Promise.all(t.map(j)),e+=t.length}return e+await u().pull()}let N=null;function P(){if(N)return;let e=N=new AbortController;(async()=>{for(let t=1e3;!e.signal.aborted;)try{await A(null);let n=await f.matches({limit:10,wait:25,signal:e.signal});await Promise.all(n.map(j)),await u().pull(),t=1e3}catch(n){if(e.signal.aborted)break;console.error(`[board] couldn't pull matches from ${r}:`,uf(n)),await new Promise(e=>setTimeout(e,t)),t=Math.min(t*2,6e4)}})()}let F=null;function I(){if(F)return F;if(Object.keys(o).length===0&&s.length===0)return Promise.resolve();let e=D(u().url());return!e&&typeof process<`u`&&process.env.VERCEL===`1`?Promise.resolve():(F=A(e).then(()=>{},e=>console.error(`[board] couldn't register with ${r}:`,uf(e))),e||P(),F)}let L=[{method:`POST`,path:`/wake`,async handle(e){return F??=Promise.resolve(),e.headers.get(`x-board-watchers`)!==await l()&&await A(D(u().url())).catch(df),Fd({ran:await M().catch(df)})}},{method:`POST`,path:`/watchers`,async handle(e,{caller:t}){if(t)return Fd(await E.register(t,Mu.parse(await e.json()),e.signal));F??=Promise.resolve();let n=D(u().url()),r=await A(n).catch(df);return n||P(),Fd(r)}}];return{...E,routes:L,keeps:!1,bind(e){if(a)throw Error(`http: this backend already serves a board: create one http() per board()`);for(let[t,n]of Object.entries(e.subscriptions)){if(n.kind===`sync`){t===`@sync`&&(s=e.sync.map(e=>({...e})));continue}if(!af.test(t))throw Error(`watch ${t}: ids start with a letter and use up to 32 letters, numbers, and hyphens`);tf(t,n),o[t]={tail:n.tail,when:n.when}}c=null,a=e},registerWatchers:()=>A(D(u().url())),close:()=>{N?.abort(),N=null}}}function hf(e,t={}){return mf(e,t,null)}const gf=/```[\s\S]*?```/g,_f=/`[^`\n]*`/g,vf=`[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?`,yf=RegExp(`(?<![\\w@.-])@(${vf}(?:/${vf})?)(?!:|[a-z0-9_/-]|\\.(?=[a-z0-9]))`,`gi`),bf=/(?<![\w@.-])@\[([^\]\s]+)\]/g,xf=e=>e.replace(gf,e=>` `.repeat(e.length)).replace(_f,e=>` `.repeat(e.length));function Sf(e){let t=xf(e),n=[];for(let e of t.matchAll(bf)){let t=e[1];t!==void 0&&n.push({index:e.index,token:{kind:`actor`,actor:t},key:`actor:${t}`})}for(let e of t.replace(bf,e=>` `.repeat(e.length)).matchAll(yf)){let t=e[1]?.toLowerCase();t!==void 0&&n.push({index:e.index,token:{kind:`handle`,handle:t},key:`handle:${t}`})}let r=/* @__PURE__ */ new Set;return n.sort((e,t)=>e.index-t.index).filter(({key:e})=>!r.has(e)&&r.add(e)).map(({token:e})=>e)}function Cf(e,t){let n=xf(e),r=[];for(let e of n.matchAll(bf))r.push({index:e.index,length:e[0].length,token:{kind:`actor`,actor:e[1]}});for(let e of n.replace(bf,e=>` `.repeat(e.length)).matchAll(yf))r.push({index:e.index,length:e[0].length,token:{kind:`handle`,handle:e[1].toLowerCase()}});let i=``,a=0;for(let{index:n,length:o,token:s}of r.sort((e,t)=>e.index-t.index)){let r=e.slice(n,n+o);i+=e.slice(a,n)+(t(s,r)??r),a=n+o}return i+e.slice(a)}const wf=[`read`,`post`,`react`,`label`,`sync`,`manage`],Tf={read:[],post:[],react:[`read`],label:[`read`],sync:[`read`],manage:[`read`,`post`,`react`,`label`,`sync`]},Ef=new Map(wf.map((e,t)=>[e,t])),Df=`write *, a channel, or a channel and its subtree (feedback/)`;function Of(e){if(e===`*`)return{kind:`all`};if(e.includes(`*`)){let t=e.slice(0,e.indexOf(`*`)).replace(/\/+$/,``),n=t===``?`write * for every channel`:Wl.safeParse(t).success?`write ${t}/ for ${t} and its subtree`:Df;throw Error(`invalid channel pattern ${e}: ${n}`)}let t=e.endsWith(`/`),n=t?e.slice(0,-1):e;if(!Wl.safeParse(n).success)throw Error(`invalid channel pattern ${e||`(empty)`}: ${Df}`);return t?{kind:`subtree`,path:n}:{kind:`exact`,path:n}}const kf=e=>e.kind===`all`?`*`:e.kind===`subtree`?`${e.path}/`:e.path;function Af(e){let t=/* @__PURE__ */ new Set,n=e=>{if(!Ef.has(e))throw Error(`unknown permission ${String(e)}: use ${wf.join(`, `)}`);if(!t.has(e)){t.add(e);for(let t of Tf[e])n(t)}};for(let t of e===`all`?wf:e)n(t);return t}const jf=/* @__PURE__ */ new Set;function Mf(e){let t=null,n=/* @__PURE__ */ new Map,r=[];for(let[i,a]of e)i.kind===`all`?t=a:i.kind===`exact`?n.set(i.path,a):r.push([i.path,a]);return r.sort((e,t)=>t[0].length-e[0].length),{all:t,exact:n,subtrees:r}}const Nf=(e,t)=>e===t||e.startsWith(`${t}/`);function Pf(e,t,n=!1){if(!n){let n=e.exact.get(t);if(n)return n}for(let[n,r]of e.subtrees)if(Nf(t,n))return r;return e.all??jf}const Ff=(e,t)=>t.kind===`all`?e.all??jf:Pf(e,t.path,t.kind===`subtree`),If=(e,t)=>e.size===t.size&&[...e].every(e=>t.has(e));function Lf(e,t){if(t.kind===`exact`)return Pf(e,t.path,!0);if(t.kind===`subtree`){for(let[n,r]of e.subtrees)if(n!==t.path&&Nf(t.path,n))return r}return e.all??jf}function Rf(e){let t=Mf(e);return Mf(e.filter(([e,n])=>e.kind===`all`?n.size>0:!If(n,Lf(t,e))))}function zf(e){return e===`all`||Array.isArray(e)?[[{kind:`all`},Af(e)]]:Object.entries(e).map(([e,t])=>[Of(e),Af(t)])}const Bf=e=>[...e.all?[[{kind:`all`},e.all]]:[],...e.subtrees.map(([e,t])=>[{kind:`subtree`,path:e},t]),...[...e.exact].map(([e,t])=>[{kind:`exact`,path:e},t])],Vf=Symbol(`board.access`),Hf=e=>typeof e==`object`&&Vf in e;function Uf(e){let t=Bf(e),n=n=>(e.all?.has(n)??!1)&&t.every(([,e])=>e.has(n)),r=/* @__PURE__ */ new Map;return{[Vf]:e,can:(t,n)=>Pf(e,n).has(t),readable(t){let n=r.get(t);return n===void 0&&r.set(t,n=Pf(e,t).has(`read`)),n},readsAll:n(`read`),everywhere:n,anywhere:e=>t.some(([,t])=>t.has(e)),narrow(n){let r=Hf(n)?n[Vf]:Rf(zf(n)),i=/* @__PURE__ */ new Map([[`*`,{kind:`all`}]]);for(let[e]of[...t,...Bf(r)])i.set(kf(e),e);return Uf(Rf([...i.values()].map(t=>{let n=Ff(r,t);return[t,new Set([...Ff(e,t)].filter(e=>n.has(e)))]})))},summary(){let e=t.map(([e,t])=>[kf(e),t]);e.sort(([e],[t])=>e===`*`?-1:t===`*`?1:e.localeCompare(t));let n={};for(let[t,r]of e)n[t]=[...r].sort((e,t)=>Ef.get(e)-Ef.get(t));return n}}}function Wf(e){return Uf(Rf(zf(e)))}const Gf=Wf(`all`);function Kf(e){if(e.length>4e3)throw Error(`x-board-scope is longer than 4000 characters`);let t={},n=e.split(`;`).map(e=>e.trim());if(n.every(e=>e===``))throw Error(`x-board-scope is empty: write pattern=permissions, like dev/=read,post`);for(let e of n){if(e===``)continue;let n=e.indexOf(`=`);if(n<0)throw Error(`x-board-scope entry ${e} needs =: write pattern=permissions, like dev/=read,post`);let r=e.slice(0,n).trim(),i=e.slice(n+1).trim();if(Object.hasOwn(t,r))throw Error(`x-board-scope lists ${r} twice`);Of(r);let a=i===``?[]:i.split(`,`).map(e=>e.trim());if(a.length===1&&a[0]===`all`){t[r]=`all`;continue}for(let e of a)if(!Ef.has(e))throw Error(`x-board-scope: unknown permission ${e||`(empty)`}: use ${wf.join(`, `)}, or all`);t[r]=a}return t}const qf=[`claude`,`codex`,`grok`,`pi`],Jf=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,Yf=/^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/;function Xf(e){let t=e.get(`x-board-profile`)?.trim()||null;if(t!==null&&!Jf.test(t))throw Ad(`profile names start with a letter and use up to 32 letters, numbers, and hyphens`);let n=e.get(`x-board-avatar`)?.trim()||null;if(n!==null&&!Qf(n))throw Ad(`avatars must be https URLs (http only on localhost)`);let r=e.get(`x-board-session`)?.trim().slice(0,200)||null,i=e.get(`x-board-handle`)?.trim().toLowerCase()||null;if(i!==null&&!Yf.test(i))throw Ad(`invalid handle: ${i}`);let a=e.get(`x-board-name`),o=null;if(a)try{o=decodeURIComponent(a).replace(/[\u0000-\u001f\u007f]/g,``).trim().slice(0,128)||null}catch{throw Ad(`x-board-name must be URI-encoded`)}let s=e.get(`x-board-scope`);if(s!==null)try{Kf(s)}catch(e){throw Ad(e.message,`invalid_scope`)}return{profile:t,avatar:n,session:r,handle:i,name:o,scope:s}}function Zf(e,t,n){let r=e.kind===`person`&&e.facts?.issuer!==`host`&&t.handle?t.handle:e.handle,i=e.kind===`person`?t.name:null,a=t.profile?.toLowerCase()??null,o=a===null?e.id:`${e.id}+${a}`,s=a!==null&&qf.includes(a),c={id:o,kind:a===null?e.kind:`agent`,handle:a===null?r:`${r}/${a}`,name:t.profile??i??r,avatar:t.avatar??(s?`${n}/avatars/${a}`:null)};return{author:{actor:o,principal:e.id,profile:a,session:t.session},actor:c}}function Qf(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`&&[`localhost`,`127.0.0.1`].includes(t.hostname)}catch{return!1}}const $f=e=>Md(`this token can't use this board: add ${e} to access`),ep=e=>{let t=new URL(e);return`${t.host}${t.pathname.replace(/\/+$/,``)}`.replace(/[%:]/g,e=>e===`%`?`%25`:`%3A`)};function tp(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=ep(n),r=t.get(e);if(r!==void 0&&r!==n)throw Error(`access: oidc issuers ${r} and ${n} name the same principals, oidc:${e}:<sub>: pin one of them`);t.set(e,n)}return new Set(e)}const np=e=>[...new Set(e.flatMap(e=>typeof e!=`function`&&e.issuer===`oidc`?[e.url]:[]))];function rp(e){let t=typeof e.access==`function`?[]:e.access,n=typeof e.access==`function`?e.access:null,r=tp(np(t));async function i(n,i){if(i?.issuer===`host`)throw Md(`this token can't use this board: its board no longer takes a host's principals`);if(i?.issuer===`oidc`&&!r.has(i.iss))throw jd(`untrusted issuer: ${i.iss}`);let a=i?.claims??{},o=i?.issuer===`vercel`?await e.project():null,s=o?{teamId:i.team??o.teamId,projectId:o.id}:{teamId:null,projectId:null},c=String(a.environment??``),l=ip(),u=o!==null&&o.id!==null&&a.project_id===o.id,d=u&&l!==null&&c===l;for(let e of t){if(typeof e==`function`){if(d)continue;let t=await e(n);if(t===void 0)continue;if(t===null)throw Md(`this token can't use this board`);return Wf(t)}if(i&&e.issuer===i.issuer&&(e.issuer!==`oidc`||e.url===i.iss)&&e.matches(a,s))return e.access}if(d)return Gf;throw i?i.issuer===`oidc`?$f(`oidc({ issuer: '${i.iss}', claims, can })`):i.issuer===`github`?$f(`githubActions({ repository: '${String(a.repository)}', can })`):u?Md(`this token can't use this board: it runs in ${l??`no Vercel environment`}, so its ${c||`unnamed`} deployments need vercelProject({ project: 'self', environments: ['${c}'], can })`):$f(`vercelProject({ project: '${String(a.project??``)||String(a.project_id)}', can })`):Md(`this token can't use this board`)}async function a(t){let r=Gf,a=t.facts?.issuer===`host`;if(t.id.startsWith(`board:`)||t.kind===`external`&&!a)r=Gf;else{if(a){if(!e.hosts)throw Md(`this token can't use this board: its board no longer takes a host's principals`);let{exp:n}=t.facts.claims;if(typeof n==`number`&&n*1e3<=Date.now())throw jd(`token expired`)}if(n){let e=await n(t);if(e==null)throw Md(`this token can't use this board`);r=Wf(e)}else t.kind!==`person`&&(r=await i(t,(a?void 0:t.facts)??ap(t.id)))}return t.scope===void 0?r:r.narrow(Kf(t.scope))}async function o(e){try{return await a(e)}catch(e){let t=e.status;if(t===401||t===403)return null;throw e}}return{grant:a,accessNow:o}}const ip=()=>process.env.VERCEL_TARGET_ENV||process.env.VERCEL_ENV||null;function ap(e){let t=e.match(/^vercel:project:([^:]+):([^:]+)$/);return t?{issuer:`vercel`,iss:``,claims:{project_id:t[1],environment:t[2]}}:null}const op=Symbol(`board.oidcTokens`),sp=/* @__PURE__ */ new WeakSet,cp=e=>op in e,lp=e=>sp.has(e),up=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*:[^\s+\]]{1,200}$/,dp=[`person`,`deployment`,`workflow`,`external`];function fp(e){let t=e=>{throw TypeError(`authenticate returned an invalid principal: ${e}`)};(typeof e!=`object`||!e)&&t(`not an object`),(typeof e.id!=`string`||!up.test(e.id)||e.id.startsWith(`board:`))&&t(`id must look like \`vercel:user:<id>\`, got ${JSON.stringify(e.id)}`),dp.includes(e.kind)||t(`kind must be one of ${dp.join(`, `)}`),(typeof e.handle!=`string`||!/^\S{1,64}$/.test(e.handle))&&t(`handle must be 1-64 characters, no spaces`);let n=e.expiresAt??null;if(n!==null&&(!(n instanceof Date)||Number.isNaN(n.getTime()))&&t(`expiresAt must be a Date or null`),n!==null&&n.getTime()<=Date.now())throw jd(`token expired`);let r=n===null?{}:{exp:Math.floor(n.getTime()/1e3)};return{id:e.id,kind:e.kind,handle:e.handle,expiresAt:n,facts:{issuer:`host`,iss:``,claims:r}}}function pp(e,t,n){let r=t||e.access!==void 0,i=e.access??[],a=null,o=()=>(a??=(async()=>{if(!n)return{id:e.project?.id??null,teamId:e.project?.teamId??null};let t=await n(),[r,i]=await Promise.all([t.ownProjectId(e.project),t.ownTeamId(e.project)]);return{id:r,teamId:i}})()).catch(e=>{throw a=null,e});async function s(t){return n?(await n()).discoveryIdentity(t,e.project):{projectId:e.project?.id??null,teamId:e.project?.teamId??null}}let c=null,l=()=>e.authenticate?Promise.resolve(e.authenticate):c??=n?n().then(e=>e.oidcTokens()):Promise.reject(new Od(501,`no_verifier`,`this build of board verifies no tokens: pass board({ authenticate })`)),u=rp({access:i,project:o,hosts:e.authenticate!==void 0&&!cp(e.authenticate)}),d={project:o,issuers:typeof i==`function`?[]:np(i)},f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new WeakMap;async function m(e){let t=e=>e.expiresAt===null||e.expiresAt.getTime()>Date.now(),n=p.get(e);if(n){let e=await n;if(t(e))return e}let r=e.credential===null?null:[e.audience,e.credential,e.headers.get(`x-vercel-oidc-token`)??``].join(``),i=r===null?void 0:f.get(r);if(i&&i.until>Date.now())return p.set(e,i.principal),i.principal;let a=h(e);return p.set(e,a),r!==null&&a.then(e=>{e.facts?.issuer!==`host`&&e.expiresAt!==null&&(f.size>=1e3&&f.delete(f.keys().next().value),f.set(r,{principal:a,until:e.expiresAt.getTime()}))},()=>p.delete(e)),a}async function h(e){let t=await l(),n;try{n=await t({...e,board:d})}catch(e){throw e instanceof Response?new kd(e):e}if(n instanceof Response)throw new kd(n);if(n==null)throw jd(`missing bearer token`);return lp(n)?n:fp(n)}return{open:r,project:o,discoveryIdentity:s,async identify(e){let t=await m(e),n=e.claims.scope===null?t:{...t,scope:e.claims.scope},{author:r,actor:i}=Zf(n,e.claims,e.audience);return{principal:{...n,access:await u.grant(n)},author:r,actor:i}},accessNow:e=>u.accessNow(e)}}const mp={claude:`m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z`,openai:`M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z`,x:`M14.234 10.162 22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299-.929-1.329L3.076 1.56h3.182l5.965 8.532.929 1.329 7.754 11.09h-3.182z`,slack:`M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313zM8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312zM18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312zM15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z`,github:`M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12`,whatsapp:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z`},hp={claude:{background:`#D97757`,mark:{path:mp.claude}},codex:{background:`#000000`,mark:{path:mp.openai}},grok:{background:`#000000`,mark:{path:mp.x}},pi:{background:`#1f1f1f`,mark:{glyph:`π`}}};function gp(e){let t=hp[e]??{background:`#666666`,mark:{glyph:e.slice(0,1).toUpperCase()}},n=`path`in t.mark?`<path transform="translate(30 30) scale(2.8333)" fill="#ffffff" d="${t.mark.path}"/>`:`<text x="64" y="86" font-family="ui-sans-serif,system-ui,sans-serif" font-size="66" font-weight="600" text-anchor="middle" fill="#ffffff">${t.mark.glyph}</text>`;return`<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect width="128" height="128" rx="28" fill="${t.background}"/>${n}</svg>`}var _p=class extends Od{responses;constructor(e){super(422,`dropped`,e.join(`
|
|
343
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function Io(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;Io(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}const Lo=/* @__PURE__ */ new Set([`type`,`properties`,`required`,`additionalProperties`]),Ro=[`oneOf`,`anyOf`];function zo(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Bo(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!Lo.has(e))return null;t.push(n)}let n={},r=/* @__PURE__ */ new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??zo(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Ge(n,r,e.length===1?e[0]:Bo(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=zo(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function Vo(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of Lo)if(t in e)return;let n=t.filter(e=>Ro.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Bo(t);else{let e=n[0],i=Ro.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Bo([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,Ao(e,r))}function Ho(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Ao(i,s),Ao(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())Io(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])Vo(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Ao(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Ge(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Go(t,`input`,e.processors),output:Go(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Uo(e,t){let n=t??{seen:/* @__PURE__ */ new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Uo(r.element,n);if(r.type===`set`)return Uo(r.valueType,n);if(r.type===`lazy`)return Uo(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return Uo(r.innerType,n);if(r.type===`intersection`)return Uo(r.left,n)||Uo(r.right,n);if(r.type===`record`||r.type===`map`)return Uo(r.keyType,n)||Uo(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:Uo(r.in,n)||Uo(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Uo(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Uo(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Uo(e,n))return!0;return!!(r.rest&&Uo(r.rest,n))}return!1}const Wo=(e,t={})=>n=>{let r=jo({...n,processors:t});return No(e,r),Fo(r,e),Ho(r,e)},Go=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=jo({...i??{},target:a,io:t,processors:n});return No(e,o),Fo(o,e),Ho(o,e)},Ko=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},qo=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Jo=(e,t)=>{Ko(e,`minimum`,t),qo(e,`maximum`,t)},Yo=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Xo=(e,t)=>{e.patterns??=/* @__PURE__ */ new Set,e.patterns.add(t)},Zo=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Qo=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},$o=(e,t)=>Ko(e,`minimum`,t.minimum),es=(e,t)=>qo(e,`maximum`,t.maximum),ts=e=>(t,n)=>{Qo(t,n.format);let[r,i]=e[n.format];Ko(t,`minimum`,r),qo(t,`maximum`,i)},ns={greater_than:(e,t)=>Ko(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>qo(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Yo(e,t.value),number_format:ts(ut),bigint_format:ts(dt),min_length:$o,max_length:es,length_equals:(e,t)=>Jo(e,t.length),min_size:$o,max_size:es,size_equals:(e,t)=>Jo(e,t.size),string_format:(e,t)=>{Qo(e,t.format),t.pattern&&Xo(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Zo(e,t.mime)};function rs(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)ns[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&Ko(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&Ko(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&qo(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&qo(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Yo(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Zo(t,i.mime);for(let e of i.patterns??[])Xo(t,e);return t}const is={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},as=/* @__PURE__ */ new Map([[ci,Wn],[ui,Gn]]),os=e=>as.get(e)??e,ss=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=rs(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=is[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(os);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},cs=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=rs(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=/* @__PURE__ */ new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):Mo(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},ls=(e,t,n,r)=>{n.type=`boolean`},us=(e,t,n,r)=>{Mo(e,t,n,r,`BigInt cannot be represented in JSON Schema`)},ds=(e,t,n,r)=>{Mo(e,t,n,r,`Symbols cannot be represented in JSON Schema`)},fs=(e,t,n,r)=>{t.target===`openapi-3.0`?(n.type=`string`,n.nullable=!0,n.enum=[null]):n.type=`null`},ps=(e,t,n,r)=>{Mo(e,t,n,r,`Undefined cannot be represented in JSON Schema`)},ms=(e,t,n,r)=>{Mo(e,t,n,r,`Void cannot be represented in JSON Schema`)},hs=(e,t,n,r)=>{n.not={}},gs=(e,t,n,r)=>{},_s=(e,t,n,r)=>{},vs=(e,t,n,r)=>{Mo(e,t,n,r,`Date cannot be represented in JSON Schema`)},ys=(e,t,n,r)=>{let i=e._zod.def,a=Le(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},bs=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(Mo(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Mo(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},xs=(e,t,n,r)=>{Mo(e,t,n,r,`NaN cannot be represented in JSON Schema`)},Ss=(e,t,n,r)=>{let i=n,a=e._zod.pattern;if(!a)throw Error(`Pattern not found in template literal`);i.type=`string`,i.pattern=a.source},Cs=(e,t,n,r)=>{let i=n;i.type=`string`,i.format=`binary`,i.contentEncoding=`binary`;let{minimum:a,maximum:o,mime:s}=rs(e);a!==void 0&&(i.minLength=a),o!==void 0&&(i.maxLength=o),s&&(s.length===0?i.not={}:s.length===1?i.contentMediaType=s[0]:i.anyOf=s.map(e=>({contentMediaType:e})))},ws=(e,t,n,r)=>{n.type=`boolean`},Ts=(e,t,n,r)=>{Mo(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Es=(e,t,n,r)=>{Mo(e,t,n,r,`Function types cannot be represented in JSON Schema`)},Ds=(e,t,n,r)=>{Mo(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Os=(e,t,n,r)=>{Mo(e,t,n,r,`Map cannot be represented in JSON Schema`)},ks=(e,t,n,r)=>{Mo(e,t,n,r,`Set cannot be represented in JSON Schema`)},As=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=rs(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=No(a.element,t,{...r,path:[...r.path,`items`]})};function js(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?js(t.out):t.type===`catch`?js(t.innerType):e._zod.optin}const Ms=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Mo(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Ge(i.properties,e,No(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?js(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=No(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Ns=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>No(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ps=(e,t,n,r)=>{let i=e._zod.def,a=No(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=No(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)},Fs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`array`;let o=t.target===`draft-2020-12`?`prefixItems`:`items`,s=t.target===`draft-2020-12`||t.target===`openapi-3.0`?`items`:`additionalItems`,c=a.items.map((e,n)=>No(e,t,{...r,path:[...r.path,o,n]})),l=a.rest?No(a.rest,t,{...r,path:[...r.path,s,...t.target===`openapi-3.0`?[a.items.length]:[]]}):null,u=a.items.length;for(;u>0;){let e=a.items[u-1];if(!(t.io===`input`?js(e)!==void 0:e._zod.optout===`optional`))break;u--}let d=a.items.length,f=!a.rest;t.target===`draft-2020-12`?(i.prefixItems=c,f?i.items=!1:l&&(i.items=l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):t.target===`openapi-3.0`?(i.items={anyOf:c},l&&i.items.anyOf.push(l),u>0&&(i.minItems=u),f&&(i.maxItems=d)):(i.items=c,f?i.additionalItems=!1:l&&(i.additionalItems=l),u>0&&(i.minItems=u),f&&(i.maxItems=d));let{minimum:p,maximum:m}=rs(e);typeof p==`number`&&(i.minItems=p),typeof m==`number`&&(i.maxItems=m)};function Is(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=Is(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>Is(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?nr:tr).source),p):p}const Ls=/* @__PURE__ */ new WeakMap;function Rs(e){let t=/* @__PURE__ */ new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=/* @__PURE__ */ new Map;for(let r of Ls.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=Is(t,a,/* @__PURE__ */ new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}const zs=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=rs(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=No(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Ge(i.patternProperties,os(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=No(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Ls.get(t);n||(n=[],Ls.set(t,n),t.deferred.push(()=>Rs(t))),n.push(e)}i.additionalProperties=No(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&js(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},Bs=(e,t,n,r)=>{let i=e._zod.def,a=No(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Vs=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Hs=Symbol();function Us(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Mo(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),Hs):JSON.parse(o)}const Ws=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=Us(i.defaultValue,e,t,n,r);o!==Hs&&(n.default=o)},Gs=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=Us(i.defaultValue,e,t,n,r);o!==Hs&&(n._prefault=o)},Ks=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Mo(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},qs=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;No(o,t,r);let s=t.seen.get(e);s.ref=o},Js=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Ys=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Xs=(e,t,n,r)=>{let i=e._zod.def;No(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Zs={string:ss,number:cs,boolean:ls,bigint:us,symbol:ds,null:fs,undefined:ps,void:ms,never:hs,any:gs,unknown:_s,date:vs,enum:ys,literal:bs,nan:xs,template_literal:Ss,file:Cs,success:ws,custom:Ts,function:Es,transform:Ds,map:Os,set:ks,array:As,object:Ms,union:Ns,intersection:Ps,tuple:Fs,record:zs,nullable:Bs,nonoptional:Vs,default:Ws,prefault:Gs,catch:Ks,pipe:qs,readonly:Js,promise:Ys,optional:Xs,lazy:(e,t,n,r)=>{let i=e._zod.innerType;No(i,t,r);let a=t.seen.get(e);a.ref=i}};function Qs(e,t){if(`_idmap`in e){let n=e,r=jo({...t,processors:Zs}),i={};for(let e of n._idmap.entries()){let[t,n]=e;No(n,r)}let a={};r.external={registry:n,uri:t?.uri,defs:i};for(let e of n._idmap.entries()){let[t,n]=e;Fo(r,n),Ge(a,t,Ho(r,n))}return Object.keys(i).length>0&&(a.__shared={[r.target===`draft-2020-12`?`$defs`:`definitions`]:i}),{schemas:a}}let n=jo({...t,processors:Zs});return No(e,n),Fo(n,e),Ho(n,e)}const $s=/* @__PURE__ */ new WeakSet([Object.prototype,Error.prototype]);function ec(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}const tc=(e,t)=>{an.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);$s.has(n)||($s.add(n),ec(n,`format`,e=>t=>cn(e,t)),ec(n,`flatten`,e=>t=>sn(e,t)),ec(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ze,2)}),ec(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ze,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},nc=/*@__PURE__*/ G(`ZodError`,tc),rc=/*@__PURE__*/ G(`ZodError`,tc,void 0,{Parent:Error}),ic=/* @__PURE__ */ un(rc),ac=/* @__PURE__ */ dn(rc),oc=/* @__PURE__ */ fn(rc),sc=/* @__PURE__ */ mn(rc),cc=/* @__PURE__ */ bn(rc),lc=/* @__PURE__ */ xn(rc),uc=/* @__PURE__ */ Sn(rc),dc=/* @__PURE__ */ Cn(rc),fc=/* @__PURE__ */ wn(rc),pc=/* @__PURE__ */ Tn(rc),mc=/* @__PURE__ */ En(rc),hc=/* @__PURE__ */ Dn(rc);function gc(){Xt.localeError||Zt(va())}function _c(){Xt.memoizer||Zt({memoizer:ha()})}const vc=/*@__PURE__*/ G(`ZodType`,(e,t)=>(gc(),Er.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(Qe(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return ct(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Rl(e,t))},superRefine(e,t){return this.check(zl(e,t))},overwrite(e){return this.check(/* @__PURE__ */ yo(e))},optional(){return yl(this)},exactOptional(){return xl(this)},nullable(){return Cl(this)},nullish(){return yl(Cl(this))},nonoptional(e){return kl(this,e)},array(){return nl(this)},or(e){return al([this,e])},and(e){return ll(this,e)},transform(e){return Nl(this,_l(e))},default(e){return Tl(this,e)},prefault(e){return Dl(this,e)},catch(e){return jl(this,e)},pipe(e){return Nl(this,e)},readonly(){return Fl(this)},describe(e){let t=this.clone();return Sa.add(t,{description:e}),t},meta(...e){if(e.length===0)return Sa.get(this);let t=this.clone();return Sa.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return Pt(this,`~standard`,{...kr(this),jsonSchema:{input:Go(this,`input`),output:Go(this,`output`)}})},set"~standard"(e){Nt(this,`~standard`,e)},parse:function e(t,n){return ic(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await ac(this,t,n,{callee:e})},safeParse(e,t){return oc(this,e,t)},async safeParseAsync(e,t){return sc(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Nt(this,`spa`,e)},validate(e,t){return _n(this,e,t)},validateAsync(e,t){return yn(this,e,t)},encode:function e(t,n){return cc(this,t,n,{callee:e})},decode:function e(t,n){return lc(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await uc(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await dc(this,t,n,{callee:e})},safeEncode(e,t){return fc(this,e,t)},safeDecode(e,t){return pc(this,e,t)},async safeEncodeAsync(e,t){return mc(this,e,t)},async safeDecodeAsync(e,t){return hc(this,e,t)},toJSONSchema(e){return Wo(this,{})(e)},get description(){return Sa.get(this)?.description},get _def(){return this._zod.def}}),yc=/*@__PURE__*/ G(`_ZodString`,(e,t)=>{Ar.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ss(e,t,n,r)},/*@__PURE__*/ Ft({format:e=>rs(e).format??null,minLength:e=>rs(e).minimum??null,maxLength:e=>rs(e).maximum??null},{regex(...e){return this.check(/* @__PURE__ */ po(...e))},includes(...e){return this.check(/* @__PURE__ */ go(...e))},startsWith(...e){return this.check(/* @__PURE__ */ _o(...e))},endsWith(...e){return this.check(/* @__PURE__ */ vo(...e))},min(...e){return this.check(/* @__PURE__ */ uo(...e))},max(...e){return this.check(/* @__PURE__ */ lo(...e))},length(...e){return this.check(/* @__PURE__ */ fo(...e))},nonempty(...e){return this.check(/* @__PURE__ */ uo(1,...e))},lowercase(e){return this.check(/* @__PURE__ */ mo(e))},uppercase(e){return this.check(/* @__PURE__ */ ho(e))},trim(){return this.check(/* @__PURE__ */ xo())},normalize(...e){return this.check(/* @__PURE__ */ bo(...e))},toLowerCase(){return this.check(/* @__PURE__ */ So())},toUpperCase(){return this.check(/* @__PURE__ */ Co())},slugify(){return this.check(/* @__PURE__ */ wo())}})),bc=/*@__PURE__*/ G(`ZodString`,(e,t)=>{Ar.init(e,t),yc.init(e,t)},{email(e){return this.check(/* @__PURE__ */ Ta(Ec,e))},url(e){return this.check(/* @__PURE__ */ ja(kc,e))},jwt(e){return this.check(/* @__PURE__ */ Ka(Wc,e))},emoji(e){return this.check(/* @__PURE__ */ Ma(Ac,e))},guid(e){return this.check(/* @__PURE__ */ Ea(Dc,e))},uuid(e){return this.check(/* @__PURE__ */ Da(Oc,e))},uuidv4(e){return this.check(/* @__PURE__ */ Oa(Oc,e))},uuidv6(e){return this.check(/* @__PURE__ */ ka(Oc,e))},uuidv7(e){return this.check(/* @__PURE__ */ Aa(Oc,e))},nanoid(e){return this.check(/* @__PURE__ */ Na(jc,e))},cuid(e){return this.check(/* @__PURE__ */ Pa(Mc,e))},cuid2(e){return this.check(/* @__PURE__ */ Fa(Nc,e))},ulid(e){return this.check(/* @__PURE__ */ Ia(Pc,e))},base64(e){return this.check(/* @__PURE__ */ Ua(Vc,e))},base64url(e){return this.check(/* @__PURE__ */ Wa(Hc,e))},xid(e){return this.check(/* @__PURE__ */ La(Fc,e))},ksuid(e){return this.check(/* @__PURE__ */ Ra(Ic,e))},ipv4(e){return this.check(/* @__PURE__ */ za(Lc,e))},ipv6(e){return this.check(/* @__PURE__ */ Ba(Rc,e))},cidrv4(e){return this.check(/* @__PURE__ */ Va(zc,e))},cidrv6(e){return this.check(/* @__PURE__ */ Ha(Bc,e))},e164(e){return this.check(/* @__PURE__ */ Ga(Uc,e))},datetime(e){return this.check(/* @__PURE__ */ qa(Sc,e))},date(e){return this.check(/* @__PURE__ */ Ja(Cc,e))},time(e){return this.check(/* @__PURE__ */ Ya(wc,e))},duration(e){return this.check(/* @__PURE__ */ Xa(Tc,e))}});function K(e){return/* @__PURE__ */ wa(bc,e)}const xc=/*@__PURE__*/ G(`ZodStringFormat`,(e,t)=>{jr.init(e,t),yc.init(e,t)}),Sc=/*@__PURE__*/ G(`ZodISODateTime`,(e,t)=>{Xr.init(e,t),xc.init(e,t)}),Cc=/*@__PURE__*/ G(`ZodISODate`,(e,t)=>{Zr.init(e,t),xc.init(e,t)}),wc=/*@__PURE__*/ G(`ZodISOTime`,(e,t)=>{Qr.init(e,t),xc.init(e,t)}),Tc=/*@__PURE__*/ G(`ZodISODuration`,(e,t)=>{$r.init(e,t),xc.init(e,t)}),Ec=/*@__PURE__*/ G(`ZodEmail`,(e,t)=>{Pr.init(e,t),xc.init(e,t)}),Dc=/*@__PURE__*/ G(`ZodGUID`,(e,t)=>{Mr.init(e,t),xc.init(e,t)}),Oc=/*@__PURE__*/ G(`ZodUUID`,(e,t)=>{Nr.init(e,t),xc.init(e,t)}),kc=/*@__PURE__*/ G(`ZodURL`,(e,t)=>{Hr.init(e,t),xc.init(e,t)}),Ac=/*@__PURE__*/ G(`ZodEmoji`,(e,t)=>{Ur.init(e,t),xc.init(e,t)}),jc=/*@__PURE__*/ G(`ZodNanoID`,(e,t)=>{Wr.init(e,t),xc.init(e,t)}),Mc=/*@__PURE__*/ G(`ZodCUID`,(e,t)=>{Gr.init(e,t),xc.init(e,t)}),Nc=/*@__PURE__*/ G(`ZodCUID2`,(e,t)=>{Kr.init(e,t),xc.init(e,t)}),Pc=/*@__PURE__*/ G(`ZodULID`,(e,t)=>{qr.init(e,t),xc.init(e,t)}),Fc=/*@__PURE__*/ G(`ZodXID`,(e,t)=>{Jr.init(e,t),xc.init(e,t)}),Ic=/*@__PURE__*/ G(`ZodKSUID`,(e,t)=>{Yr.init(e,t),xc.init(e,t)}),Lc=/*@__PURE__*/ G(`ZodIPv4`,(e,t)=>{ei.init(e,t),xc.init(e,t)}),Rc=/*@__PURE__*/ G(`ZodIPv6`,(e,t)=>{ri.init(e,t),xc.init(e,t)}),zc=/*@__PURE__*/ G(`ZodCIDRv4`,(e,t)=>{ii.init(e,t),xc.init(e,t)}),Bc=/*@__PURE__*/ G(`ZodCIDRv6`,(e,t)=>{oi.init(e,t),xc.init(e,t)}),Vc=/*@__PURE__*/ G(`ZodBase64`,(e,t)=>{li.init(e,t),xc.init(e,t)}),Hc=/*@__PURE__*/ G(`ZodBase64URL`,(e,t)=>{fi.init(e,t),xc.init(e,t)}),Uc=/*@__PURE__*/ G(`ZodE164`,(e,t)=>{pi.init(e,t),xc.init(e,t)}),Wc=/*@__PURE__*/ G(`ZodJWT`,(e,t)=>{hi.init(e,t),xc.init(e,t)}),Gc=/*@__PURE__*/ G(`ZodNumber`,(e,t)=>{gi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cs(e,t,n,r),e.isFinite=!0},/*@__PURE__*/ Ft({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=rs(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=rs(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=rs(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>rs(e).format??null},{gt(e,t){return this.check(/* @__PURE__ */ oo(e,t))},gte(e,t){return this.check(/* @__PURE__ */ so(e,t))},min(e,t){return this.check(/* @__PURE__ */ so(e,t))},lt(e,t){return this.check(/* @__PURE__ */ io(e,t))},lte(e,t){return this.check(/* @__PURE__ */ ao(e,t))},max(e,t){return this.check(/* @__PURE__ */ ao(e,t))},int(e){return this.check(Jc(e))},safe(e){return this.check(Jc(e))},positive(e){return this.check(/* @__PURE__ */ oo(0,e))},nonnegative(e){return this.check(/* @__PURE__ */ so(0,e))},negative(e){return this.check(/* @__PURE__ */ io(0,e))},nonpositive(e){return this.check(/* @__PURE__ */ ao(0,e))},multipleOf(e,t){return this.check(/* @__PURE__ */ co(e,t))},step(e,t){return this.check(/* @__PURE__ */ co(e,t))},finite(){return this}}));function Kc(e){return/* @__PURE__ */ Za(Gc,e)}const qc=/*@__PURE__*/ G(`ZodNumberFormat`,(e,t)=>{_i.init(e,t),Gc.init(e,t)});function Jc(e){return/* @__PURE__ */ $a(qc,e)}const Yc=/*@__PURE__*/ G(`ZodBoolean`,(e,t)=>{vi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ls(e,t,n,r)});function Xc(e){return/* @__PURE__ */ eo(Yc,e)}const Zc=/*@__PURE__*/ G(`ZodUnknown`,(e,t)=>{yi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Qc(){return/* @__PURE__ */ no(Zc)}const $c=/*@__PURE__*/ G(`ZodNever`,(e,t)=>{bi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>hs(e,t,n,r)});function el(e){return/* @__PURE__ */ ro($c,e)}const tl=/*@__PURE__*/ G(`ZodArray`,(e,t)=>{_c(),Si.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>As(e,t,n,r),e.element=t.element},{min(e,t){return this.check(/* @__PURE__ */ uo(e,t))},nonempty(e){return this.check(/* @__PURE__ */ uo(1,e))},max(e,t){return this.check(/* @__PURE__ */ lo(e,t))},length(e,t){return this.check(/* @__PURE__ */ fo(e,t))},unwrap(){return this.element}});function nl(e,t){return/* @__PURE__ */ To(tl,e,t)}const rl=/*@__PURE__*/ G(`ZodObject`,(e,t)=>{_c(),Oi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ms(e,t,n,r),Ht(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return pl(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(Qe(this._zod.def,{catchall:e}))},passthrough(){return this.clone(Qe(this._zod.def,{catchall:Qc()}))},loose(){return this.clone(Qe(this._zod.def,{catchall:Qc()}))},strict(){return this.clone(Qe(this._zod.def,{catchall:el()}))},strip(){return this.clone(Qe(this._zod.def,{catchall:void 0}))},extend(e){return ht(this,e)},safeExtend(e){return _t(this,e)},merge(e){return vt(this,e)},pick(e){return ft(this,e)},omit(e){return mt(this,e)},partial(...e){return yt(vl,this,e[0])},exactPartial(...e){return yt(bl,this,e[0],`exactPartial`)},required(...e){return bt(Ol,this,e[0])}});function q(e,t){let n={type:`object`,shape:e??{},...U(t)};return new rl(n)}const il=/*@__PURE__*/ G(`ZodUnion`,(e,t)=>{Ai.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ns(e,t,n,r),e.options=t.options});function al(e,t){return new il({type:`union`,options:e,...U(t)})}const ol=/*@__PURE__*/ G(`ZodDiscriminatedUnion`,(e,t)=>{il.init(e,t),Mi.init(e,t)});function sl(e,t,n){return new ol({type:`union`,options:t,discriminator:e,...U(n)})}const cl=/*@__PURE__*/ G(`ZodIntersection`,(e,t)=>{Ni.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ps(e,t,n,r)});function ll(e,t){return new cl({type:`intersection`,left:e,right:t})}const ul=/*@__PURE__*/ G(`ZodRecord`,(e,t)=>{_c(),Ii.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zs(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function dl(e,t,n){return!t||!t._zod?new ul({type:`record`,keyType:K(),valueType:e,...U(t)}):new ul({type:`record`,keyType:e,valueType:t,...U(n)})}const fl=/*@__PURE__*/ G(`ZodEnum`,(e,t)=>{Li.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ys(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new fl({...t,checks:[],...U(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new fl({...t,checks:[],...U(r),entries:i})}});function pl(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new fl({type:`enum`,entries:n,...U(t)})}const ml=/*@__PURE__*/ G(`ZodLiteral`,(e,t)=>{Ri.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>bs(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function hl(e,t){return new ml({type:`literal`,values:Array.isArray(e)?e:[e],...U(t)})}const gl=/*@__PURE__*/ G(`ZodTransform`,(e,t)=>{_c(),zi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ds(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Yt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(jt(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(jt(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function _l(e){return new gl({type:`transform`,transform:e})}const vl=/*@__PURE__*/ G(`ZodOptional`,(e,t)=>{Vi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yl(e){return new vl({type:`optional`,innerType:e})}const bl=/*@__PURE__*/ G(`ZodExactOptional`,(e,t)=>{Hi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function xl(e){return new bl({type:`optional`,innerType:e})}const Sl=/*@__PURE__*/ G(`ZodNullable`,(e,t)=>{Ui.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Cl(e){return new Sl({type:`nullable`,innerType:e})}const wl=/*@__PURE__*/ G(`ZodDefault`,(e,t)=>{Wi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ws(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Tl(e,t){return new wl({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const El=/*@__PURE__*/ G(`ZodPrefault`,(e,t)=>{Ki.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Dl(e,t){return new El({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():at(t)}})}const Ol=/*@__PURE__*/ G(`ZodNonOptional`,(e,t)=>{qi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vs(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function kl(e,t){return new Ol({type:`nonoptional`,innerType:e,...U(t)})}const Al=/*@__PURE__*/ G(`ZodCatch`,(e,t)=>{Xi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ks(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function jl(e,t){return new Al({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Ut(t)})}const Ml=/*@__PURE__*/ G(`ZodPipe`,(e,t)=>{Zi.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qs(e,t,n,r),e.in=t.in,e.out=t.out});function Nl(e,t){return new Ml({type:`pipe`,in:e,out:t})}const Pl=/*@__PURE__*/ G(`ZodReadonly`,(e,t)=>{$i.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Js(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Fl(e){return new Pl({type:`readonly`,innerType:e})}const Il=/*@__PURE__*/ G(`ZodCustom`,(e,t)=>{ta.init(e,t),vc.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ts(e,t,n,r)});function Ll(e,t){return/* @__PURE__ */ Eo(Il,e??(()=>!0),t)}function Rl(e,t={}){return/* @__PURE__ */ Do(Il,e,t)}function zl(e,t){return/* @__PURE__ */ Oo(e,t)}function Bl(e){return/* @__PURE__ */ Qa(Gc,e)}function Vl(e){return/* @__PURE__ */ to(Yc,e)}const Hl=1e4,Ul=`[a-z0-9][a-z0-9_-]*`,Wl=K().max(80).regex(RegExp(`^${Ul}(?:/${Ul})*$`),`invalid channel path`),Gl=e=>!e.includes(`\0`)&&e.isWellFormed(),Kl=e=>e.replaceAll(`\0`,``).toWellFormed(),ql=K().max(Hl).refine(e=>e.trim().length>0,`message text is empty`).refine(Gl,`message text has a NUL character or a lone surrogate`),Jl=Kc().int().positive(),Yl=/* @__PURE__ */ new Set([...Object.getOwnPropertyNames(Object.prototype),`prototype`]),Xl=e=>!Yl.has(e),Zl=K().max(64).regex(/^[a-z0-9][a-z0-9_.-]*$/,`invalid label key`).refine(Xl,`label key is a reserved name`),Ql=dl(Zl,K().max(256).refine(Gl,`label value has a NUL character or a lone surrogate`)),$l=K().max(64).regex(/^[a-z0-9_+-]+$/,`invalid emoji name`).refine(Xl,`emoji name is a reserved name`),eu=K().min(1).max(256);al([pl([`person`,`agent`,`deployment`,`workflow`,`external`]),hl(`profile`)]);const tu=e=>e===`profile`?`agent`:e;K().min(1).max(128).refine(Gl,`handle has a NUL character or a lone surrogate`);function nu(e){if(e===null)return null;try{return new URL(e).protocol===`https:`?e:null}catch{return null}}q({actor:eu,principal:K().min(1),profile:K().nullable(),session:K().nullable()});const ru=K().regex(/^[A-Za-z0-9_-]{22}$/,`invalid attachment id`);q({id:ru,name:K().min(1).max(255),type:K().min(1).max(255),size:Kc().int().nonnegative()}),K().regex(/^[A-Za-z][A-Za-z0-9-]{0,31}$/,`ids start with a letter and use up to 32 letters, numbers, and hyphens`);const iu=K().min(3).max(300),au=q({channel:iu.optional(),thread:iu,subthread:iu.nullable(),message:K().min(1).max(300),context:K().max(300).nullable()}),ou=q({author:K().min(1).max(256),text:K().max(Hl),createdAt:K().max(64).nullable(),files:nl(q({name:K().min(1).max(1e3),url:K().max(4e3).nullable()})).max(20)}),su=q({url:K().min(1).max(4e3),message:Jl.nullable(),snapshot:ou.nullable(),unavailable:K().max(300).nullable()}),cu=q({id:K().min(1),handle:K().min(1),name:K().min(1),avatar:K().nullable(),isBot:Xc()}),lu=q({type:pl([`image`,`file`,`video`,`audio`]),name:K().max(1e3).optional(),mimeType:K().max(255).optional(),size:Kc().int().nonnegative().optional(),url:K().max(4e3).optional(),fetchMetadata:dl(K(),K().max(4e3)).optional()}),uu=q({url:K().min(1).max(4e3),thread:iu,message:K().min(1).max(300),snapshot:ou.nullable()}),du=q({channel:iu,thread:iu,subthread:iu.nullable()}),fu=sl(`kind`,[q({kind:hl(`message`),...du.shape,message:K(),isRoot:Xc(),text:K(),context:K().nullable(),author:cu,files:nl(lu).max(20).optional(),links:nl(uu).max(10).optional()}),q({kind:hl(`edited`),...du.shape,message:K(),text:K(),author:cu,links:nl(uu).max(10).optional(),linksOnly:Xc().optional()}),q({kind:hl(`deleted`),...du.shape,message:K()}),q({kind:hl(`reaction`),...du.shape,message:K(),emoji:K(),added:Xc(),author:cu}),q({kind:hl(`lifecycle`),...du.omit({subthread:!0}).shape,type:K(),title:K(),url:K().nullable(),labels:dl(K(),K()),unset:nl(K()),owns:nl(K()).optional(),reply:K().nullable(),createRoot:Xc(),retitled:Xc().optional(),author:cu})]),pu=e=>e.slice(e.indexOf(`:`)+1).includes(`:`),mu=e=>{let t=e.indexOf(`:`),n=e.slice(t+1).indexOf(`:`);return n===-1?e:e.slice(0,t+1+n)},hu=(e,t)=>`${e}|${t}`,gu=K().min(1).max(128),_u=gu,vu=al([K(),nl(K())]).transform(e=>Array.isArray(e)?e:[e]),yu=K().regex(/^[a-z0-9][a-z0-9_.-]*(=.*)?$/,`label filters look like key, key=value, or key=a|b`).transform(e=>{let t=e.indexOf(`=`);return t===-1?[e,null]:[e.slice(0,t),e.slice(t+1).split(`|`)]}),bu=q({target:iu,kind:pl([`channel`,`thread`])}),xu=q({channel:K().optional(),re:_u.optional(),by:K().optional(),mentions:K().optional(),label:vu.pipe(nl(yu)).optional(),from:K().min(1).max(64).optional(),text:K().min(1).max(200).optional()}),Su=xu.extend({after:gu.optional(),before:_u.optional(),limit:Bl().int().min(1).max(500).optional()}),Cu=xu.extend({after:gu.optional(),limit:Bl().int().min(1).max(500).optional()}),wu=xu.extend({after:gu.optional(),wait:Bl().min(0).max(300).optional(),all:Vl().optional()}),Tu=q({channel:Wl.optional(),re:gu.optional(),text:K().max(Hl).default(``),labels:Ql.optional(),noSync:Xc().optional(),sync:nl(al([K().min(3).max(300),bu])).max(10).optional(),id:K().min(1).max(200).refine(Gl,`id has a NUL character or a lone surrogate`).optional(),attachments:nl(ru).max(10).optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a post needs `channel`; a reply needs `re`"}).refine(e=>!(e.noSync&&e.sync?.length),{message:"`noSync` and `sync` contradict each other"}),Eu=K().regex(/^\d+(\.\d+)?(s|m|h|d)$/,`durations look like 30s, 30m, 12h, or 1d`),Du=K().datetime({offset:!0}),Ou=q({channel:Wl.optional(),re:gu.optional(),text:K().max(Hl).default(``),labels:Ql.optional(),noSync:Xc().optional(),attachments:nl(ru).max(10).optional(),in:Eu.optional(),at:Du.optional(),every:Eu.optional(),until:Du.optional(),for:Eu.optional(),times:Kc().int().positive().optional()}).refine(e=>e.text.trim().length>0||(e.attachments?.length??0)>0,{message:`message text is empty`,path:[`text`]}).refine(e=>e.channel===void 0!=(e.re===void 0),{message:"a schedule needs `channel` for a new thread, or `re` for a reply"}).refine(e=>e.in!==void 0||e.at!==void 0||e.every!==void 0,{message:"say when: `in`, `at`, or `every`"}).refine(e=>e.in===void 0||e.at===void 0,{message:"`in` and `at` contradict each other"}).refine(e=>[e.until,e.for,e.times].filter(e=>e!==void 0).length<=1,{message:"pick one stop: `until`, `for`, or `times`"}).refine(e=>e.every!==void 0||e.until===void 0&&e.for===void 0&&e.times===void 0,{message:"`until`, `for`, and `times` stop a repeat: add `every`"}),ku=q({re:_u.optional(),channel:K().optional(),by:K().optional(),all:Vl().optional()}),Au=q({target:K().min(3).max(300)}),ju=q({channel:K().optional(),limit:Bl().int().min(1).max(500).optional()}),Mu=q({url:K().url().max(500).refine(e=>/^https:\/\//.test(e),`wake-ups go over https`).transform(e=>e.replace(/\/+$/,``)).nullable().optional(),path:K().max(300).regex(/^\/[^?#]*$/,`a path starts with / and has no query or fragment`).transform(e=>e.replace(/(.)\/+$/,`$1`)).nullable().optional(),branch:K().min(1).max(255).nullable().optional(),watch:dl(K().max(100),q({tail:K().max(1e3),when:pl([`matches`,`enters`]).default(`matches`)})).refine(e=>Object.keys(e).length<=32,`a board registers at most 32 watchers`),sync:nl(q({key:K().min(1).max(64),platform:K().min(1).max(64),signIn:Xc().default(!1)})).max(32).optional()}).refine(e=>!(e.url&&e.path),{message:`register a url or a path, not both`,path:[`path`]}).refine(e=>!e.branch||e.path,{message:`a branch goes with a path`,path:[`branch`]}),Nu=q({limit:Bl().int().min(1).max(50).optional(),wait:Bl().min(0).max(25).optional()}),Pu=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional(),skip:Xc().optional()}),Fu=q({target:K().min(1).max(4e3),limit:Bl().int().min(1).max(200).optional()}),Iu=q({url:K().url().max(4e3)}),Lu=q({actor:K().min(1).max(256)}),Ru=K().min(1).max(64),zu=q({thread:iu,message:K().min(1).max(300).optional()}),Bu=su.extend({message:gu.nullable()}),Vu=cu.extend({avatar:K().nullable().transform(nu)}),Hu={author:Vu,from:Ru.nullable()},Uu=q({key:Ru,channel:iu,thread:iu}),Wu={origin:zu.optional(),message:gu.optional()},Gu=sl(`op`,[q({op:hl(`post`),...Hu,origin:au.nullable().default(null),source:Uu.optional(),channel:Wl.optional(),re:gu.optional(),text:K().max(Hl).default(``),labels:Ql.optional(),noSync:Xc().optional(),attachments:nl(ru).max(10).optional(),links:nl(Bu).max(10).optional(),id:K().min(1).max(200).refine(Gl,`id has a NUL character or a lone surrogate`).optional()}),q({op:hl(`edit`),...Hu,...Wu,text:ql,source:Uu.optional()}),q({op:hl(`delete`),...Hu,...Wu}),q({op:hl(`react`),...Hu,...Wu,emoji:$l,remove:Xc().optional()}),q({op:hl(`labels`),...Hu,...Wu,set:Ql.optional(),unset:nl(Zl).optional()}),q({op:hl(`links`),...Hu,...Wu,links:nl(Bu).max(10)}),q({op:hl(`seen`),author:Vu})]),Ku=nl(K().min(1).max(300)).max(10).nullable(),qu=sl(`kind`,[q({kind:hl(`message`),message:gu,target:iu,external:q({thread:iu,message:K().min(1).max(300),asUser:hl(!0).optional()}),files:Ku.optional()}),q({kind:hl(`files`),message:gu,target:iu,files:Ku}),q({kind:hl(`failed`),message:gu,target:iu,error:K().min(1).max(500)}),q({kind:hl(`thread`),message:gu,target:iu,targetKind:pl([`channel`,`thread`]),cause:pl([`config`,`request`])})]),Ju=q({code:K().min(1).max(64).optional(),post:K().min(1).max(200).optional(),thread:iu.optional(),message:K().min(1).max(300).optional(),account:eu.optional(),person:eu.optional()}),Yu=q({message:vu.pipe(nl(gu).min(1).max(100))}),Xu=q({by:eu,since:Bl().int().nonnegative()}),Zu=q({events:nl(q({id:K().min(1).max(300),event:fu,raw:Qc()})).min(1).max(50)}),Qu=q({limit:Bl().int().min(1).max(50).optional()}),$u=q({lease:K().min(1).max(64),error:K().min(1).max(500).optional()}),ed=q({sync:Ru}),td=q({sync:Ru,account:Vu,code:K().min(1).max(64),message:K().max(1024).optional(),method:pl([`code`,`consent`]).optional()}),nd=q({sync:Ru,code:K().min(1).max(64)}),rd=q({account:eu}),id=q({name:K().max(1024).nullable().optional(),type:K().max(1024).nullable().optional(),size:Kc().int().positive().max(Ae,`direct uploads are at most ${Ae/1024/1024} MB`)}),ad=q({text:ql}),od=q({}).optional(),sd=q({status:K().trim().min(1).max(100).optional()}).optional(),cd=q({emoji:$l,remove:Xc().optional()}),ld=q({set:Ql.optional(),unset:nl(Zl).optional()}).refine(e=>e.set!==void 0||e.unset!==void 0,{message:"nothing to change: pass `set` or `unset`"}),ud={discovery:{method:`GET`,path:`/`},me:{method:`GET`,path:`/me`},channels:{method:`GET`,path:`/channels`},actors:{method:`GET`,path:`/actors`},messages:{method:`GET`,path:`/messages`,query:Su},message:{method:`GET`,path:`/messages/:id`},threads:{method:`GET`,path:`/threads`,query:Cu},post:{method:`POST`,path:`/messages`,body:Tu},edit:{method:`POST`,path:`/messages/:id/edit`,body:ad},delete:{method:`POST`,path:`/messages/:id/delete`,body:od},react:{method:`POST`,path:`/messages/:id/reactions`,body:cd},label:{method:`POST`,path:`/messages/:id/labels`,body:ld},sync:{method:`POST`,path:`/messages/:id/sync`,body:Au},synced:{method:`GET`,path:`/messages/:id/sync`},linked:{method:`GET`,path:`/links`,query:Iu},typing:{method:`POST`,path:`/messages/:id/typing`,body:sd},schedule:{method:`POST`,path:`/schedules`,body:Ou},schedules:{method:`GET`,path:`/schedules`,query:ku},cancelSchedule:{method:`POST`,path:`/schedules/:id/cancel`},posted:{method:`GET`,path:`/posts/:id`},inbox:{method:`GET`,path:`/inbox/:key`,query:ju},inboxPush:{method:`POST`,path:`/inbox/:key`,body:Zu},inboxNext:{method:`GET`,path:`/inbox/:key/next`,query:Qu},inboxAck:{method:`POST`,path:`/inbox/:key/:id/ack`,body:$u},syncImport:{method:`POST`,path:`/sync/imports`,body:Gu},syncReceipt:{method:`POST`,path:`/sync/receipts`,body:qu},syncThread:{method:`GET`,path:`/sync/threads/:thread`},syncFind:{method:`GET`,path:`/sync/find`,query:Ju},syncCopies:{method:`GET`,path:`/sync/copies`,query:Yu},syncRoots:{method:`GET`,path:`/sync/roots`,query:Xu},syncCode:{method:`POST`,path:`/sync/codes`,body:ed},syncAccount:{method:`POST`,path:`/sync/accounts`,body:td},syncUnlink:{method:`POST`,path:`/sync/accounts/unlink`,body:rd},readSource:{method:`GET`,path:`/sources/:key/read`,query:Fu},webhook:{method:`POST`,path:`/webhooks/:key`},events:{method:`GET`,path:`/events`,query:wu},avatar:{method:`GET`,path:`/avatars/:name`},upload:{method:`POST`,path:`/attachments`},attachment:{method:`GET`,path:`/attachments/:id`},uploadStart:{method:`POST`,path:`/attachments/uploads`,body:id},uploadFinish:{method:`POST`,path:`/attachments/uploads/:id`},openapi:{method:`GET`,path:`/openapi.json`},identity:{method:`GET`,path:`/identity`},signIn:{method:`GET`,path:`/identity/sign-in`,query:nd},signedIn:{method:`GET`,path:`/identity/signed-in`,query:nd},identityUnlink:{method:`POST`,path:`/identity/unlink`,body:Lu},watchers:{method:`GET`,path:`/watchers`},register:{method:`POST`,path:`/watchers`,body:Mu},matches:{method:`GET`,path:`/watchers/matches`,query:Nu},ack:{method:`POST`,path:`/watchers/matches/:id/ack`,body:Pu},wake:{method:`POST`,path:`/wake`}};async function*dd(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=()=>void n.cancel().catch(()=>{});t?.addEventListener(`abort`,a,{once:!0});try{for(;;){let{value:e,done:t}=await n.read();if(t)return;i+=r.decode(e,{stream:!0});let a;for(;(a=i.search(/\r?\n\r?\n/))!==-1;){let e=i.slice(0,a);i=i.slice(a).replace(/^\r?\n\r?\n/,``);let t={},n=[];for(let r of e.split(/\r?\n/)){if(r===``||r.startsWith(`:`))continue;let e=r.indexOf(`:`),i=e===-1?r:r.slice(0,e),a=e===-1?``:r.slice(e+1).replace(/^ /,``);i===`data`?n.push(a):i===`id`?t.id=a:i===`event`&&(t.event=a)}n.length>0&&(t.data=n.join(`
|
|
344
|
+
`)),(t.id!==void 0||t.data!==void 0)&&(yield t)}}}finally{t?.removeEventListener(`abort`,a),n.releaseLock()}}var fd=class extends Error{code;status;constructor(e,t,n){super(t),this.name=`BoardError`,this.code=e,this.status=n}};const pd=async e=>typeof e==`function`?await e():e,md=e=>{let{at:t,until:n,...r}=hd(e);return{...r,...t===void 0?{}:{at:t instanceof Date?t.toISOString():t},...n===void 0?{}:{until:n instanceof Date?n.toISOString():n}}},hd=e=>{if(typeof e==`string`)return{text:e};let{attachments:t,...n}=e;return t?.length?{...n,attachments:t.map(e=>typeof e==`string`?e:e.id)}:n},gd={ms:1,s:1e3,m:6e4,h:36e5,d:864e5};function _d(e){if(typeof e==`number`)return e;let t=e.trim().match(/^(\d+(?:\.\d+)?)(ms|s|m|h|d)?$/);if(!t)throw new fd(`invalid_duration`,`invalid duration: ${e}`,0);return Number(t[1])*gd[t[2]??`ms`]}const vd=e=>encodeURIComponent(e);function yd(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null){if(n===`label`){let e=Array.isArray(r)?r:typeof r==`object`?Object.entries(r).map(([e,t])=>`${e}=${String(t)}`):[r];for(let n of e)t.append(`label`,String(n))}else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}const bd=(e,t)=>t?.length?{...e,unknownMentions:t}:e;function xd(e){let t=e.url.replace(/\/+$/,``),n=e.fetch??((e,t)=>globalThis.fetch(e,t)),r=e.storeFetch??((e,t)=>globalThis.fetch(e,t));async function i(t,n){let r={...e.headers?await pd(e.headers):{}};if(!t)return r;e.token!==void 0&&(r.authorization=`Bearer ${await pd(e.token)}`);let i=n===void 0?e.profile===void 0?null:await pd(e.profile):n;if(i!==null){let{name:e,avatar:t}=typeof i==`string`?{name:i,avatar:void 0}:i;r[`x-board-profile`]=e,t&&(r[`x-board-avatar`]=t)}else{let t=e.person===void 0?null:await pd(e.person);t?.name&&(r[`x-board-name`]=encodeURIComponent(t.name)),t?.avatar&&(r[`x-board-avatar`]=t.avatar)}let a=n===void 0?e.session===void 0?null:await pd(e.session):null;a&&(r[`x-board-session`]=a);let o=e.handle===void 0?null:await pd(e.handle);return o&&(r[`x-board-handle`]=o),r}async function a(e,r,a={}){let o=await n(`${t}${r}`,{method:e,headers:{...await i(a.auth??!0),...a.body===void 0?{}:{"content-type":`application/json`},...a.headers},...a.body===void 0?{}:{body:JSON.stringify(a.body)},...a.signal?{signal:a.signal}:{}});if(!o.ok)throw await Sd(o);return o}async function o(e,t,n){return await(await a(e,t,n)).json()}let s=(e={})=>e;async function c(e={},t){return o(`GET`,`/events${yd(e)}`,t?{signal:t}:{})}return{url:t,request:async(e,r={})=>n(`${t}${e}`,{method:r.method??`GET`,headers:{...r.headers,...await i(!0,r.as)},...r.body?{body:r.body}:{},...r.signal?{signal:r.signal}:{}}),discovery:()=>o(`GET`,`/`,{auth:!1}),me:()=>o(`GET`,`/me`),channels:async()=>(await o(`GET`,`/channels`)).channels,actors:async()=>(await o(`GET`,`/actors`)).actors,identity:()=>o(`GET`,`/identity`),unlinkAccount:e=>o(`POST`,`/identity/unlink`,{body:{actor:e}}),messages:(e={})=>o(`GET`,`/messages${yd(e)}`),thread:e=>o(`GET`,`/messages/${vd(e)}`),posted:async e=>(await o(`GET`,`/posts/${vd(e)}`)).message,threads:(e={})=>o(`GET`,`/threads${yd(e)}`),async post(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{channel:e,...hd(t)}});return bd(n,r)},async reply(e,t){let{message:n,unknownMentions:r}=await o(`POST`,`/messages`,{body:{re:e,...hd(t)}});return bd(n,r)},async schedule(e,t){let{schedule:n,unknownMentions:r}=await o(`POST`,`/schedules`,{body:{...typeof e==`string`?{channel:e}:{re:e.re},...md(t)}});return bd(n,r)},schedules:async(e={})=>(await o(`GET`,`/schedules${yd(e)}`)).schedules,cancelSchedule:e=>o(`POST`,`/schedules/${vd(e)}/cancel`,{body:{}}),async upload(e){let a=e.type||(e.data instanceof Blob?e.data.type:``)||Ne(e.name),s=e.data instanceof Blob?e.data.size:e.data.byteLength;if(s>4194304){if(s>104857600)throw new fd(`too_large`,`attachments are at most ${Ae/1024/1024} MB`,413);let t=await o(`POST`,`/attachments/uploads`,{body:{name:e.name,type:a,size:s}}).catch(e=>{throw e instanceof fd&&e.status===404&&e.code===`not_found`?new fd(`too_large`,`this board takes files of at most ${Oe/1024/1024} MB`,413):e}),n=await r(t.url,{method:`PUT`,headers:t.headers,body:e.data});if(!n.ok)throw new fd(`upload_failed`,`the blob store refused the file: ${n.status} ${(await n.text().catch(()=>``)).slice(0,300)||n.statusText}`,n.status);return(await o(`POST`,`/attachments/uploads/${encodeURIComponent(t.id)}`,{body:{}})).attachment}let c=await n(`${t}/attachments`,{method:`POST`,headers:{...await i(!0),"content-type":a,"x-board-filename":encodeURIComponent(e.name)},body:e.data});if(!c.ok)throw await Sd(c);return(await c.json()).attachment},download:(e,t={})=>a(`GET`,`/attachments/${encodeURIComponent(e)}`,t.signal?{signal:t.signal}:{}),edit:(e,t)=>o(`POST`,`/messages/${vd(e)}/edit`,{body:{text:t}}),delete:e=>o(`POST`,`/messages/${vd(e)}/delete`,{body:{}}),react:(e,t,n={})=>o(`POST`,`/messages/${vd(e)}/reactions`,{body:{emoji:Ee(t),...n}}),label:(e,t)=>o(`POST`,`/messages/${vd(e)}/labels`,{body:t}),typing:async(e,t)=>(await o(`POST`,`/messages/${vd(e)}/typing`,{body:t?{status:t}:{}})).targets,sync:((e,t)=>t===void 0?o(`GET`,`/messages/${vd(e)}/sync`):o(`POST`,`/messages/${vd(e)}/sync`,{body:{target:t}})),linked:e=>o(`GET`,`/links${yd({url:e})}`),inbox:async(e,t={})=>(await o(`GET`,`/inbox/${e}${yd(t)}`)).events,register:e=>o(`POST`,`/watchers`,{body:e}),watchers:async()=>(await o(`GET`,`/watchers`)).watchers,matches:async(e={})=>{let{signal:t,...n}=e;return(await o(`GET`,`/watchers/matches${yd(n)}`,t?{signal:t}:{})).matches},ack:(e,t)=>o(`POST`,`/watchers/matches/${encodeURIComponent(e)}/ack`,{body:t}),readSource:(e,t,n={})=>o(`GET`,`/sources/${e}/read${yd({target:t,...n})}`),poll:c,syncImport:e=>o(`POST`,`/sync/imports`,{body:e}),syncReceipt:e=>o(`POST`,`/sync/receipts`,{body:e}),syncThread:e=>o(`GET`,`/sync/threads/${vd(e)}`),syncFind:(e,t={})=>o(`GET`,`/sync/find${yd(e)}`,t.signal?{signal:t.signal}:{}),syncCopies:async e=>(await o(`GET`,`/sync/copies?${e.map(e=>`message=${encodeURIComponent(e)}`).join(`&`)}`)).copies,syncRoots:async(e,t)=>(await o(`GET`,`/sync/roots${yd({by:e,since:t instanceof Date?t.getTime():t})}`)).roots,inboxPush:(e,t)=>o(`POST`,`/inbox/${vd(e)}`,{body:{events:t}}),inboxNext:async(e,t={})=>(await o(`GET`,`/inbox/${vd(e)}/next${yd(t)}`)).items,inboxAck:(e,t,n)=>o(`POST`,`/inbox/${vd(e)}/${vd(t)}/ack`,{body:n}),syncCode:e=>o(`POST`,`/sync/codes`,{body:{sync:e}}),syncAccount:e=>o(`POST`,`/sync/accounts`,{body:e}),syncUnlink:e=>o(`POST`,`/sync/accounts/unlink`,{body:{account:e}}),async*events(e={},t={}){let n=e.after,r=0;for(;!t.signal?.aborted;){let i;try{i=await a(`GET`,`/events${yd({...s(e),after:n})}`,{headers:{accept:`text/event-stream`},...t.signal?{signal:t.signal}:{}})}catch(e){if(t.signal?.aborted)return;if(e instanceof fd&&e.status>=400&&e.status<500)throw e;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)));continue}r=0;try{for await(let e of dd(i.body,t.signal))e.id!==void 0&&(n=e.id),e.event===`board`&&e.data&&(yield JSON.parse(e.data))}catch{if(t.signal?.aborted)return;await new Promise(e=>setTimeout(e,Math.min(3e4,500*2**r++)))}}},async wait(e={},t={}){let n=Date.now()+_d(t.timeout??`30m`),r=e.after??(await c({...e,after:void 0,wait:0},t.signal)).cursor;for(;Date.now()<n&&!t.signal?.aborted;){let i=Math.max(0,Math.min(25,Math.ceil((n-Date.now())/1e3))),a=await c({...e,after:r,wait:i},t.signal);if(a.events.length>0)return a.events[0];r=a.cursor}return null}}}async function Sd(e){try{let t=await e.json();if(t.error?.message)return new fd(t.error.code??`error`,t.error.message,e.status)}catch{}return new fd(`http_error`,`${e.status} ${e.statusText}`,e.status)}const Cd=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);async function wd(e){return Cd(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e))))}async function Td(...e){let t=new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(e)))).slice(0,16);t[6]=t[6]&15|128,t[8]=t[8]&63|128;let n=Cd(t);return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20,32)}`}const Ed=/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,Dd=async(e,t)=>`key:${e}:${(await wd(`board-key\u001f${t}`)).slice(0,32)}`;var Od=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}},kd=class extends Od{response;constructor(e){super(e.status,`rejected`,`rejected with ${e.status}`),this.response=e}};const Ad=(e,t=`invalid_request`)=>new Od(400,t,e),jd=e=>new Od(401,`unauthorized`,e),Md=e=>new Od(403,`forbidden`,e),Nd=(e,t=`not_found`)=>new Od(404,t,e),Pd=()=>new Od(409,`duplicate_id`,`that id was already used for a different write`),Fd=(e,t=200,n)=>new Response(JSON.stringify(e),{status:t,headers:{"content-type":`application/json`,...n}});function Id(e){if(e instanceof kd)return e.response;if(e instanceof Od)return Fd({error:{code:e.code,message:e.message}},e.status);if(e instanceof nc){let t=e.issues[0],n=t?.path.length?`${t.path.join(`.`)}: `:``;return Fd({error:{code:`invalid_request`,message:`${n}${t?.message??`invalid request`}`}},400)}let t=e?.code;return t===`INVALID_PAYLOAD`?Fd({error:{code:`invalid_request`,message:e.message}},400):t===`PARTIAL_DUPLICATE_BATCH`||t===`DUPLICATE_EVENT_ID`?Id(Pd()):t===`STORE_UNAVAILABLE`||t===`STORE_NOT_CONFIGURED`?Fd({error:{code:`unavailable`,message:e.message}},503):(console.error(`[board]`,e),Fd({error:{code:`internal`,message:`internal error`}},500))}const Ld=`0.19.0`,Rd=[`avatar`,`openapi`,`webhook`,`signIn`,`signedIn`,`identityUnlink`,`sync`],zd=/* @__PURE__ */ `discovery.me.channels.actors.identity.messages.threads.message.post.posted.edit.delete.react.label.schedule.schedules.cancelSchedule.upload.attachment.uploadStart.uploadFinish.watchers.register.matches.ack.events.syncImport.syncReceipt.syncThread.syncFind.syncCopies.syncRoots.inboxPush.inboxNext.inboxAck.inbox.syncCode.syncAccount.syncUnlink.typing.readSource.synced.linked`.split(`.`),Bd=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function Vd(e,t,n,r){let i=t.split(`/`).filter(Boolean),a=i.map(e=>e.startsWith(`:`)?`/([^/]+)`:`/${Bd(e)}`).join(``);return{method:e,pattern:RegExp(`${a}$`),names:i.filter(e=>e.startsWith(`:`)).map(e=>e.slice(1)),target:n,segments:i.length,literals:i.filter(e=>!e.startsWith(`:`)).length,own:r}}function Hd(e,t){let n=[...Rd.map(e=>Vd(ud[e].method,ud[e].path,{kind:`board`,name:e},!1)),...zd.filter(e=>e!==`discovery`).map(e=>Vd(ud[e].method,ud[e].path,{kind:`protocol`,name:e},!1)),...e.map(e=>Vd(e.method,e.path,{kind:`backend`,route:e},!0))].sort((e,t)=>t.segments-e.segments||t.literals-e.literals||Number(t.own)-Number(e.own)),r=(e,t,n)=>{let r={};try{e.names.forEach((e,t)=>r[e]=decodeURIComponent(n[t]))}catch{return null}let i=e.names[0];return{target:e.target,base:t,param:i===void 0?null:r[i],params:r}},i=e=>({target:{kind:`protocol`,name:`discovery`},base:e,param:null,params:{},root:!0});return function(e,a){let o=a.length>1?a.replace(/\/+$/,``):a;if(t!==void 0){let a=t.replace(/\/+$/,``);if(o!==a&&!o.startsWith(`${a}/`))return null;let s=o.slice(a.length)||`/`;if(s===`/`)return e===`GET`?i(a):null;for(let t of n){let n=t.method===e?s.match(RegExp(`^${t.pattern.source}`)):null;if(n)return r(t,a,n.slice(1))}return null}for(let t of n){if(t.method!==e)continue;let n=o.match(t.pattern);if(n)return r(t,o.slice(0,n.index),n.slice(1))}return e===`GET`?i(o===`/`?``:o):null}}function Ud(e){let t={};for(let n of new Set(e.searchParams.keys())){let r=e.searchParams.getAll(n);t[n]=r.length>1?r:r[0]}return t}async function Wd(e){let t=await e.text();if(t.trim()!==``)try{return JSON.parse(t)}catch{throw Ad(`request body is not valid JSON`)}}const Gd=()=>new Od(413,`too_large`,`attachments are at most ${Oe/1024/1024} MB`);async function Kd(e,t){if(Number(e.headers.get(`content-length`)??0)>t)throw Gd();let n=[],r=0;for await(let i of e.body??[]){if(r+=i.byteLength,r>t)throw Gd();n.push(i)}let i=new Uint8Array(r),a=0;for(let e of n)i.set(e,a),a+=e.byteLength;return i}function qd(){let e={};for(let[t,n]of Object.entries(ud)){let r=n.path.replace(/:(\w+)/g,`{$1}`),i={operationId:t};`query`in n&&(i[`x-query-schema`]=Qs(n.query,{io:`input`})),`body`in n&&(i.requestBody={content:{"application/json":{schema:Qs(n.body,{io:`input`})}}}),(e[r]??={})[n.method.toLowerCase()]=i}return{openapi:`3.1.0`,info:{title:`board`,version:Ld},paths:e}}const Jd={re:{type:`string`},by:{type:`string`},mentions:{type:`string`},label:{type:`string`,multiple:!0},from:{type:`string`},text:{type:`string`}};function Yd(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n];r===`--mentions`?e[n+1]?.startsWith(`@`)?t.push(`--mentions=${e[++n]}`):t.push(`--mentions=me`):t.push(r)}return t}function Xd(e){let t=[],n=null,r=null;for(let i=0;i<e.length;i++){let a=e[i];r?a===r?r=null:a===`\\`&&r===`"`&&i+1<e.length?n+=e[++i]:n+=a:/\s/.test(a)?(n!==null&&t.push(n),n=null):a===`"`||a===`'`?(r=a,n??=``):n=a===`\\`&&i+1<e.length?(n??``)+e[++i]:(n??``)+a}if(r)throw Error(`unterminated ${r}`);return n!==null&&t.push(n),t}const Zd={...Jd,all:{type:`boolean`}};function Qd(e){let t={},n=[];for(let r=0;r<e.length;r++){let i=e[r];if(i===`--`){n.push(...e.slice(r+1));break}if(!i.startsWith(`-`)||i===`-`){n.push(i);continue}let a=i.indexOf(`=`),o=i.startsWith(`--`)?i.slice(2,a===-1?void 0:a):null,s=o!==null&&Object.hasOwn(Zd,o)?Zd[o]:null;if(!s)throw Error(`${o===null?i.slice(0,2):`--${o}`} isn't a filter`);if(s.type===`boolean`){if(a!==-1)throw Error(`--${o} takes no value`);t[o]=!0;continue}let c;if(a!==-1)c=i.slice(a+1);else{let t=e[r+1];if(t===void 0||t.length>1&&t.startsWith(`-`))throw Error(`--${o} needs a value`);c=t,r++}t[o]=`multiple`in s?[...t[o]??[],c]:c}return{values:t,positionals:n}}function $d(e){let{values:t,positionals:n}=Qd(Yd(Xd(e)));if(n.length>1)throw Error(`expected one channel, got: ${n.join(` `)}`);let r=n[0],i=xu.safeParse({...r?{channel:r}:{},...t.re?{re:t.re.replace(/^#/,``)}:{},...t.by?{by:t.by.replace(/^@/,``)}:{},...t.mentions?{mentions:t.mentions.replace(/^@/,``)}:{},...t.label?.length?{label:t.label}:{},...t.from?{from:t.from}:{},...t.text?{text:t.text}:{}});if(!i.success){let e=i.error.issues[0];throw Error(`${e?.path.length?`--${String(e.path[0])}: `:``}${e?.message??`invalid filters`}`)}return{filters:i.data,all:t.all===!0}}const ef=e=>e.channel!==void 0||e.re!==void 0||e.by!==void 0||e.mentions!==void 0||e.from!==void 0||e.text!==void 0||(e.label?.length??0)>0;function tf(e,t){let n,r;try{({filters:n,all:r}=$d(t.tail))}catch(t){throw Error(`watch ${e}: ${t.message}`)}if(n.mentions===`me`)throw Error(`watch ${e}: a watcher has no "me": use --mentions @handle`);let i=ef(n);if(t.when===`enters`&&!i)throw Error(`watch ${e}: \`when: enters\` needs a filter to enter`);return{filters:n,criteria:i,enters:t.when===`enters`,all:r}}const nf=(e,t)=>e<t?-1:+(e>t);function rf(e,t=[]){let n=Object.keys(e).sort(nf).map(t=>[t,e[t].tail,e[t].when]);return t.length>0&&n.push([`sync`,[...t].sort((e,t)=>nf(e.key,t.key)).map(e=>[e.key,e.platform,e.signIn])]),JSON.stringify(n)}const af=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,of=/* @__PURE__ */ new Set([`identity`,`edit`,`delete`,`schedule`,`cancelSchedule`,`upload`,`uploadStart`,`uploadFinish`,`watchers`,`register`,`matches`,`ack`,`syncImport`,`syncReceipt`,`syncThread`,`syncFind`,`syncCopies`,`syncRoots`,`inboxPush`,`inboxNext`,`inboxAck`,`inbox`,`syncCode`,`syncAccount`,`syncUnlink`]);function sf(e){let t=e.replace(/[^A-Za-z0-9-]+/g,`-`).replace(/^-+|-+$/g,``);return/^[A-Za-z]/.test(t)||(t=`u-${t}`),t.slice(0,32).replace(/-+$/,``)}function cf(e,t){let n=new Set([...t,`middleware`,`client`].map(e=>e.toLowerCase())),r=sf(e),i=r;for(let e=2;n.has(i.toLowerCase());e++)i=`${r.slice(0,31-String(e).length)}-${e}`;return i}function lf(e){let{access:t}=e.principal;if(t.everywhere(`manage`))return null;let n=Object.entries(t.summary()).map(([e,t])=>`${e}=${t.join(`,`)}`);return n.length>0?n.join(`;`):`*=`}const uf=e=>((e instanceof Error?e.message:String(e))||`unknown error`).slice(0,500),df=e=>{throw e instanceof fd?new Od(e.status>=400?e.status:502,e.code,e.message):e instanceof Od||e instanceof Error&&e.name===`AbortError`?e:new Od(502,`unreachable`,`the board didn't answer: ${uf(e)}`)};function ff(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))if(r!=null&&r!==!1){if(n===`label`&&Array.isArray(r))for(let[e,n]of r)t.append(`label`,n===null?e:`${e}=${n.join(`|`)}`);else if(Array.isArray(r))for(let e of r)t.append(n,String(e));else t.set(n,String(r))}let n=t.toString();return n?`?${n}`:``}function pf(e,t){let n=(t.headers.get(`content-disposition`)??``).match(/filename\*=UTF-8''([^;]+)/)?.[1],r=`file`;try{n&&(r=decodeURIComponent(n))}catch{}return{attachment:{id:e,name:r,type:t.headers.get(`content-type`)??`application/octet-stream`,size:Number(t.headers.get(`content-length`)??0)},data:t.body??/* @__PURE__ */ new Uint8Array}}function mf(e,t,n){if(e!==void 0&&!/^https?:\/\/[^/]/.test(e))throw Error(`http: ${e} isn't a URL: pass the board's, like https://board.example.com/api/board`);if(e===void 0&&!n)throw Error(`http: pass the board's URL: outside Node there's no environment to find it in`);let r=(e??n.url()).replace(/\/+$/,``),i=t.fetch??n?.fetch(r)??((e,t)=>globalThis.fetch(e,t)),a=null,o={},s=[],c=null,l=()=>c??=wd(rf(o,s)).then(e=>e.slice(0,32)),u=()=>{if(!a)throw Error(`http: this backend isn't serving a board yet: pass it to board({ backend })`);return a},d=(e,t)=>xd({url:r,fetch:i,profile:e===void 0?()=>n?.profile().profile??null:e,session:t||e===null?null:()=>n?.profile().session??null}),f=d(null,!0),p=/* @__PURE__ */ new Map;function m(e){if(!af.test(e))throw new Od(400,`invalid_request`,`as: ${e}: profiles start with a letter and use up to 32 letters, numbers, and hyphens`);let t=p.get(e);return t||p.set(e,t=d(e,!0)),t}let h=/* @__PURE__ */ new Map;function g(e){let t=JSON.stringify(e??(e===null?null:`\0`)),n=h.get(t);return n||h.set(t,n=d(e,!1)),n}function _(e){return e.origin.via?.kind===`engine`?f:e.origin.via?.kind===`client`?(e.self!==null&&m(e.self),g(`profile`in e?e.profile:e.self??void 0)):m(e.self??`client`)}let v=null,y=()=>(v??=i(r).then(async e=>{if(!e.ok)throw new Od(e.status>=400?e.status:502,`no_board`,`no board at ${r} (${e.status})`);return await e.json()},df)).catch(e=>{throw v=null,e}),b=null,x=()=>b??=f.me().then(e=>e.principal).catch(e=>{throw b=null,e}),S=async e=>Dd(await x(),e);async function C(e,t,n,i){let a=ud[t],o={...n},s=a.path.replace(/:(\w+)/g,(e,t)=>{let n=o[t];return delete o[t],encodeURIComponent(String(n))}),c;if(t===`upload`){let{data:t,name:r,type:a}=n;if(t.byteLength>4194304){let n=await e.upload({data:t,name:r??`file`,...a?{type:a}:{}}).catch(df);return Response.json({attachment:n})}c=await e.request(s,{method:`POST`,body:t,headers:{...a?{"content-type":a}:{},...r===null?{}:{"x-board-filename":encodeURIComponent(r)}},signal:i}).catch(df)}else c=a.method===`GET`?await e.request(`${s}${ff(o)}`,{signal:i}).catch(df):await e.request(s,{method:`POST`,body:new TextEncoder().encode(JSON.stringify(o)),headers:{"content-type":`application/json`},signal:i}).catch(df);if(c.ok)return c;try{let e=await c.json();if(e.error?.message)throw new Od(c.status,e.error.code??`error`,e.error.message)}catch(e){if(e instanceof Od)throw e}throw new Od(502,`remote_error`,`${r} answered ${c.status}`)}async function w(e,t,n,a){if(e===`me`){let{principal:e,author:n,actor:r}=t;return{actor:r.id,principal:e.id,kind:r.kind,handle:r.handle,name:r.name,avatar:r.avatar,profile:n.profile,session:n.session,expiresAt:e.expiresAt?.toISOString()??null,can:e.access.summary()}}if(of.has(e))throw Md(`this board's callers act as its project on ${r}, which can't tell them apart: ${e} is the project's own to do there`);let s=lf(t),c=t.actor.avatar?.startsWith(`https://`)?t.actor.avatar:void 0,l=xd({url:r,fetch:i,profile:{name:cf(t.actor.handle,Object.keys(o)),...c?{avatar:c}:{}},session:null,...s===null?{}:{headers:{"x-board-scope":s}}});(e===`post`||e===`posted`)&&typeof n.id==`string`&&(n={...n,id:await S(await Td(`board-gateway`,t.principal.id,n.id)).catch(df)});let u=await C(l,e,n,a);return e===`attachment`?pf(String(n.id),u):u.json()}async function T(e,t,n,r){let i=L();if(`identity`in t)return w(e,t.identity,n,r);let a=_(t);`self`in t&&t.origin.via?.kind===`engine`&&await i,(e===`post`||e===`posted`)&&`self`in t&&typeof n.id==`string`&&Ed.test(n.id)&&(n={...n,id:await S(n.id).catch(df)});let o=await C(a,e,n,r);return e===`attachment`?pf(String(n.id),o):o.json()}let E={...Object.fromEntries(zd.map(e=>[e,(t,n,r)=>T(e,t,n,r)])),async discovery(){return y()},async readSource(e,t,n){return`self`in e&&u().sync.some(e=>e.key===t.key)?u().readSource(t.key,t.target,t.limit??50):T(`readSource`,e,t,n)},async synced(e,t,n){let{targets:r}=await T(`synced`,e,t,n);return{targets:await Promise.all(r.map(async e=>({...e,url:e.url??(e.thread!==null&&e.message!==null?await u().linkOf(e.key,e.thread,e.message):null)})))}},async linked(e,t,n){let r=()=>new Od(404,`message_not_found`,`no message on this board for that link`),i=await(async()=>{for(let{platform:e,thread:r,message:i}of u().locate(t.url))for(let t of u().sync.filter(t=>t.platform===e)){let e=await f.syncFind({thread:`${t.key}:${r}`,...i===null?{}:{message:i}},{signal:n}).catch(df),a=i===null?e.thread===null?null:(await f.syncThread(e.thread).catch(df)).root:e.message;if(a!==null)return a}return null})();if(i===null)return T(`linked`,e,t,n);try{return await E.message(e,{id:i},n)}catch(e){throw e instanceof Od&&e.status===404?r():e}},async typing(e,t,n){let{targets:r}=await T(`typing`,e,t,n);if(!(`self`in e)||u().sync.length===0)return{targets:r};let{message:i,replies:a}=await E.message(e,{id:t.id},n),o=await u().typing([i,...a],t.status).catch(e=>(console.warn(`[board] skipped typing where this board syncs:`,uf(e)),[]));return{targets:[...r,...o]}}},D=e=>e?.startsWith(`https://`)?e:null;async function O(e){let t=typeof process<`u`&&process.env.VERCEL===`1`?process.env:null,n=t?.VERCEL_TARGET_ENV||t?.VERCEL_ENV,r=n===`preview`&&t?.VERCEL_GIT_COMMIT_REF||null;return!e||n!==`production`&&!r||!(await y()).wake_by_path?{url:e}:{path:new URL(e).pathname,...r?{branch:r}:{}}}let k=null,A=null;async function j(e){let t=await l();return k&&k.url===e&&k.result.hash===t&&Date.now()-k.at<1e4?k.result:(A??=O(e).then(e=>f.register({...e,watch:o,...s.length>0?{sync:s}:{}})).then(t=>(k={url:e,at:Date.now(),result:t},t)).finally(()=>{A=null}),A)}async function M(e){let t={};if(!u().subscriptions[e.watcher])t={skip:!0};else try{await u().run(e.watcher,e.event,{trigger:`watch:${e.watcher}:${e.id}`,attempt:e.attempt+1})}catch(n){console.error(`[board] watcher ${e.watcher} failed:`,n),t={error:uf(n)}}await f.ack(e.id,{lease:e.lease,...t}).catch(e=>console.error(`[board] couldn't ack a match:`,uf(e)))}async function N(){let e=0,t=Date.now()+24e4;for(;Date.now()<t;){let t=await f.matches({limit:10});if(t.length===0)break;await Promise.all(t.map(M)),e+=t.length}return e+await u().pull()}let P=null;function F(){if(P)return;let e=P=new AbortController;(async()=>{for(let t=1e3;!e.signal.aborted;)try{await j(null);let n=await f.matches({limit:10,wait:25,signal:e.signal});await Promise.all(n.map(M)),await u().pull(),t=1e3}catch(n){if(e.signal.aborted)break;console.error(`[board] couldn't pull matches from ${r}:`,uf(n)),await new Promise(e=>setTimeout(e,t)),t=Math.min(t*2,6e4)}})()}let I=null;function L(){if(I)return I;if(Object.keys(o).length===0&&s.length===0)return Promise.resolve();let e=D(u().url());return!e&&typeof process<`u`&&process.env.VERCEL===`1`?Promise.resolve():(I=j(e).then(()=>{},e=>console.error(`[board] couldn't register with ${r}:`,uf(e))),e||F(),I)}let R=[{method:`POST`,path:`/wake`,async handle(e){return I??=Promise.resolve(),e.headers.get(`x-board-watchers`)!==await l()&&await j(D(u().url())).catch(df),Fd({ran:await N().catch(df)})}},{method:`POST`,path:`/watchers`,async handle(e,{caller:t}){if(t)return Fd(await E.register(t,Mu.parse(await e.json()),e.signal));I??=Promise.resolve();let n=D(u().url()),r=await j(n).catch(df);return n||F(),Fd(r)}}];return{...E,routes:R,keeps:!1,bind(e){if(a)throw Error(`http: this backend already serves a board: create one http() per board()`);for(let[t,n]of Object.entries(e.subscriptions)){if(n.kind===`sync`){t===`@sync`&&(s=e.sync.map(e=>({...e})));continue}if(!af.test(t))throw Error(`watch ${t}: ids start with a letter and use up to 32 letters, numbers, and hyphens`);tf(t,n),o[t]={tail:n.tail,when:n.when}}c=null,a=e},registerWatchers:()=>j(D(u().url())),close:()=>{P?.abort(),P=null}}}function hf(e,t={}){return mf(e,t,null)}const gf=/```[\s\S]*?```/g,_f=/`[^`\n]*`/g,vf=`[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?`,yf=RegExp(`(?<![\\w@.-])@(${vf}(?:/${vf})?)(?!:|[a-z0-9_/-]|\\.(?=[a-z0-9]))`,`gi`),bf=/(?<![\w@.-])@\[([^\]\s]+)\]/g,xf=e=>e.replace(gf,e=>` `.repeat(e.length)).replace(_f,e=>` `.repeat(e.length));function Sf(e){let t=xf(e),n=[];for(let e of t.matchAll(bf)){let t=e[1];t!==void 0&&n.push({index:e.index,token:{kind:`actor`,actor:t},key:`actor:${t}`})}for(let e of t.replace(bf,e=>` `.repeat(e.length)).matchAll(yf)){let t=e[1]?.toLowerCase();t!==void 0&&n.push({index:e.index,token:{kind:`handle`,handle:t},key:`handle:${t}`})}let r=/* @__PURE__ */ new Set;return n.sort((e,t)=>e.index-t.index).filter(({key:e})=>!r.has(e)&&r.add(e)).map(({token:e})=>e)}function Cf(e,t){let n=xf(e),r=[];for(let e of n.matchAll(bf))r.push({index:e.index,length:e[0].length,token:{kind:`actor`,actor:e[1]}});for(let e of n.replace(bf,e=>` `.repeat(e.length)).matchAll(yf))r.push({index:e.index,length:e[0].length,token:{kind:`handle`,handle:e[1].toLowerCase()}});let i=``,a=0;for(let{index:n,length:o,token:s}of r.sort((e,t)=>e.index-t.index)){let r=e.slice(n,n+o);i+=e.slice(a,n)+(t(s,r)??r),a=n+o}return i+e.slice(a)}const wf=[`read`,`post`,`react`,`label`,`sync`,`manage`],Tf={read:[],post:[],react:[`read`],label:[`read`],sync:[`read`],manage:[`read`,`post`,`react`,`label`,`sync`]},Ef=new Map(wf.map((e,t)=>[e,t])),Df=`write *, a channel, or a channel and its subtree (feedback/)`;function Of(e){if(e===`*`)return{kind:`all`};if(e.includes(`*`)){let t=e.slice(0,e.indexOf(`*`)).replace(/\/+$/,``),n=t===``?`write * for every channel`:Wl.safeParse(t).success?`write ${t}/ for ${t} and its subtree`:Df;throw Error(`invalid channel pattern ${e}: ${n}`)}let t=e.endsWith(`/`),n=t?e.slice(0,-1):e;if(!Wl.safeParse(n).success)throw Error(`invalid channel pattern ${e||`(empty)`}: ${Df}`);return t?{kind:`subtree`,path:n}:{kind:`exact`,path:n}}const kf=e=>e.kind===`all`?`*`:e.kind===`subtree`?`${e.path}/`:e.path;function Af(e){let t=/* @__PURE__ */ new Set,n=e=>{if(!Ef.has(e))throw Error(`unknown permission ${String(e)}: use ${wf.join(`, `)}`);if(!t.has(e)){t.add(e);for(let t of Tf[e])n(t)}};for(let t of e===`all`?wf:e)n(t);return t}const jf=/* @__PURE__ */ new Set;function Mf(e){let t=null,n=/* @__PURE__ */ new Map,r=[];for(let[i,a]of e)i.kind===`all`?t=a:i.kind===`exact`?n.set(i.path,a):r.push([i.path,a]);return r.sort((e,t)=>t[0].length-e[0].length),{all:t,exact:n,subtrees:r}}const Nf=(e,t)=>e===t||e.startsWith(`${t}/`);function Pf(e,t,n=!1){if(!n){let n=e.exact.get(t);if(n)return n}for(let[n,r]of e.subtrees)if(Nf(t,n))return r;return e.all??jf}const Ff=(e,t)=>t.kind===`all`?e.all??jf:Pf(e,t.path,t.kind===`subtree`),If=(e,t)=>e.size===t.size&&[...e].every(e=>t.has(e));function Lf(e,t){if(t.kind===`exact`)return Pf(e,t.path,!0);if(t.kind===`subtree`){for(let[n,r]of e.subtrees)if(n!==t.path&&Nf(t.path,n))return r}return e.all??jf}function Rf(e){let t=Mf(e);return Mf(e.filter(([e,n])=>e.kind===`all`?n.size>0:!If(n,Lf(t,e))))}function zf(e){return e===`all`||Array.isArray(e)?[[{kind:`all`},Af(e)]]:Object.entries(e).map(([e,t])=>[Of(e),Af(t)])}const Bf=e=>[...e.all?[[{kind:`all`},e.all]]:[],...e.subtrees.map(([e,t])=>[{kind:`subtree`,path:e},t]),...[...e.exact].map(([e,t])=>[{kind:`exact`,path:e},t])],Vf=Symbol(`board.access`),Hf=e=>typeof e==`object`&&Vf in e;function Uf(e){let t=Bf(e),n=n=>(e.all?.has(n)??!1)&&t.every(([,e])=>e.has(n)),r=/* @__PURE__ */ new Map;return{[Vf]:e,can:(t,n)=>Pf(e,n).has(t),readable(t){let n=r.get(t);return n===void 0&&r.set(t,n=Pf(e,t).has(`read`)),n},readsAll:n(`read`),everywhere:n,anywhere:e=>t.some(([,t])=>t.has(e)),narrow(n){let r=Hf(n)?n[Vf]:Rf(zf(n)),i=/* @__PURE__ */ new Map([[`*`,{kind:`all`}]]);for(let[e]of[...t,...Bf(r)])i.set(kf(e),e);return Uf(Rf([...i.values()].map(t=>{let n=Ff(r,t);return[t,new Set([...Ff(e,t)].filter(e=>n.has(e)))]})))},summary(){let e=t.map(([e,t])=>[kf(e),t]);e.sort(([e],[t])=>e===`*`?-1:t===`*`?1:e.localeCompare(t));let n={};for(let[t,r]of e)n[t]=[...r].sort((e,t)=>Ef.get(e)-Ef.get(t));return n}}}function Wf(e){return Uf(Rf(zf(e)))}const Gf=Wf(`all`);function Kf(e){if(e.length>4e3)throw Error(`x-board-scope is longer than 4000 characters`);let t={},n=e.split(`;`).map(e=>e.trim());if(n.every(e=>e===``))throw Error(`x-board-scope is empty: write pattern=permissions, like dev/=read,post`);for(let e of n){if(e===``)continue;let n=e.indexOf(`=`);if(n<0)throw Error(`x-board-scope entry ${e} needs =: write pattern=permissions, like dev/=read,post`);let r=e.slice(0,n).trim(),i=e.slice(n+1).trim();if(Object.hasOwn(t,r))throw Error(`x-board-scope lists ${r} twice`);Of(r);let a=i===``?[]:i.split(`,`).map(e=>e.trim());if(a.length===1&&a[0]===`all`){t[r]=`all`;continue}for(let e of a)if(!Ef.has(e))throw Error(`x-board-scope: unknown permission ${e||`(empty)`}: use ${wf.join(`, `)}, or all`);t[r]=a}return t}const qf=[`claude`,`codex`,`grok`,`pi`],Jf=/^[A-Za-z][A-Za-z0-9-]{0,31}$/,Yf=/^[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?$/;function Xf(e){let t=e.get(`x-board-profile`)?.trim()||null;if(t!==null&&!Jf.test(t))throw Ad(`profile names start with a letter and use up to 32 letters, numbers, and hyphens`);let n=e.get(`x-board-avatar`)?.trim()||null;if(n!==null&&!Qf(n))throw Ad(`avatars must be https URLs (http only on localhost)`);let r=e.get(`x-board-session`)?.trim().slice(0,200)||null,i=e.get(`x-board-handle`)?.trim().toLowerCase()||null;if(i!==null&&!Yf.test(i))throw Ad(`invalid handle: ${i}`);let a=e.get(`x-board-name`),o=null;if(a)try{o=decodeURIComponent(a).replace(/[\u0000-\u001f\u007f]/g,``).trim().slice(0,128)||null}catch{throw Ad(`x-board-name must be URI-encoded`)}let s=e.get(`x-board-scope`);if(s!==null)try{Kf(s)}catch(e){throw Ad(e.message,`invalid_scope`)}return{profile:t,avatar:n,session:r,handle:i,name:o,scope:s}}function Zf(e,t,n){let r=e.kind===`person`&&e.facts?.issuer!==`host`&&t.handle?t.handle:e.handle,i=e.kind===`person`?t.name:null,a=t.profile?.toLowerCase()??null,o=a===null?e.id:`${e.id}+${a}`,s=a!==null&&qf.includes(a),c={id:o,kind:a===null?e.kind:`agent`,handle:a===null?r:`${r}/${a}`,name:t.profile??i??r,avatar:t.avatar??(s?`${n}/avatars/${a}`:null)};return{author:{actor:o,principal:e.id,profile:a,session:t.session},actor:c}}function Qf(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`&&[`localhost`,`127.0.0.1`].includes(t.hostname)}catch{return!1}}const $f=e=>Md(`this token can't use this board: add ${e} to access`),ep=e=>{let t=new URL(e);return`${t.host}${t.pathname.replace(/\/+$/,``)}`.replace(/[%:]/g,e=>e===`%`?`%25`:`%3A`)};function tp(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=ep(n),r=t.get(e);if(r!==void 0&&r!==n)throw Error(`access: oidc issuers ${r} and ${n} name the same principals, oidc:${e}:<sub>: pin one of them`);t.set(e,n)}return new Set(e)}const np=e=>[...new Set(e.flatMap(e=>typeof e!=`function`&&e.issuer===`oidc`?[e.url]:[]))];function rp(e){let t=typeof e.access==`function`?[]:e.access,n=typeof e.access==`function`?e.access:null,r=tp(np(t));async function i(n,i){if(i?.issuer===`host`)throw Md(`this token can't use this board: its board no longer takes a host's principals`);if(i?.issuer===`oidc`&&!r.has(i.iss))throw jd(`untrusted issuer: ${i.iss}`);let a=i?.claims??{},o=i?.issuer===`vercel`?await e.project():null,s=o?{teamId:i.team??o.teamId,projectId:o.id}:{teamId:null,projectId:null},c=String(a.environment??``),l=ip(),u=o!==null&&o.id!==null&&a.project_id===o.id,d=u&&l!==null&&c===l;for(let e of t){if(typeof e==`function`){if(d)continue;let t=await e(n);if(t===void 0)continue;if(t===null)throw Md(`this token can't use this board`);return Wf(t)}if(i&&e.issuer===i.issuer&&(e.issuer!==`oidc`||e.url===i.iss)&&e.matches(a,s))return e.access}if(d)return Gf;throw i?i.issuer===`oidc`?$f(`oidc({ issuer: '${i.iss}', claims, can })`):i.issuer===`github`?$f(`githubActions({ repository: '${String(a.repository)}', can })`):u?Md(`this token can't use this board: it runs in ${l??`no Vercel environment`}, so its ${c||`unnamed`} deployments need vercelProject({ project: 'self', environments: ['${c}'], can })`):$f(`vercelProject({ project: '${String(a.project??``)||String(a.project_id)}', can })`):Md(`this token can't use this board`)}async function a(t){let r=Gf,a=t.facts?.issuer===`host`;if(t.id.startsWith(`board:`)||t.kind===`external`&&!a)r=Gf;else{if(a){if(!e.hosts)throw Md(`this token can't use this board: its board no longer takes a host's principals`);let{exp:n}=t.facts.claims;if(typeof n==`number`&&n*1e3<=Date.now())throw jd(`token expired`)}if(n){let e=await n(t);if(e==null)throw Md(`this token can't use this board`);r=Wf(e)}else t.kind!==`person`&&(r=await i(t,(a?void 0:t.facts)??ap(t.id)))}return t.scope===void 0?r:r.narrow(Kf(t.scope))}async function o(e){try{return await a(e)}catch(e){let t=e.status;if(t===401||t===403)return null;throw e}}return{grant:a,accessNow:o}}const ip=()=>process.env.VERCEL_TARGET_ENV||process.env.VERCEL_ENV||null;function ap(e){let t=e.match(/^vercel:project:([^:]+):([^:]+)$/);return t?{issuer:`vercel`,iss:``,claims:{project_id:t[1],environment:t[2]}}:null}const op=Symbol(`board.oidcTokens`),sp=/* @__PURE__ */ new WeakSet,cp=e=>op in e,lp=e=>sp.has(e),up=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*:[^\s+\]]{1,200}$/,dp=[`person`,`deployment`,`workflow`,`external`];function fp(e){let t=e=>{throw TypeError(`authenticate returned an invalid principal: ${e}`)};(typeof e!=`object`||!e)&&t(`not an object`),(typeof e.id!=`string`||!up.test(e.id)||e.id.startsWith(`board:`))&&t(`id must look like \`vercel:user:<id>\`, got ${JSON.stringify(e.id)}`),dp.includes(e.kind)||t(`kind must be one of ${dp.join(`, `)}`),(typeof e.handle!=`string`||!/^\S{1,64}$/.test(e.handle))&&t(`handle must be 1-64 characters, no spaces`);let n=e.expiresAt??null;if(n!==null&&(!(n instanceof Date)||Number.isNaN(n.getTime()))&&t(`expiresAt must be a Date or null`),n!==null&&n.getTime()<=Date.now())throw jd(`token expired`);let r=n===null?{}:{exp:Math.floor(n.getTime()/1e3)};return{id:e.id,kind:e.kind,handle:e.handle,expiresAt:n,facts:{issuer:`host`,iss:``,claims:r}}}function pp(e,t,n){let r=t||e.access!==void 0,i=e.access??[],a=null,o=()=>(a??=(async()=>{if(!n)return{id:e.project?.id??null,teamId:e.project?.teamId??null};let t=await n(),[r,i]=await Promise.all([t.ownProjectId(e.project),t.ownTeamId(e.project)]);return{id:r,teamId:i}})()).catch(e=>{throw a=null,e});async function s(t){return n?(await n()).discoveryIdentity(t,e.project):{projectId:e.project?.id??null,teamId:e.project?.teamId??null}}let c=null,l=()=>e.authenticate?Promise.resolve(e.authenticate):c??=n?n().then(e=>e.oidcTokens()):Promise.reject(new Od(501,`no_verifier`,`this build of board verifies no tokens: pass board({ authenticate })`)),u=rp({access:i,project:o,hosts:e.authenticate!==void 0&&!cp(e.authenticate)}),d={project:o,issuers:typeof i==`function`?[]:np(i)},f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new WeakMap;async function m(e){let t=e=>e.expiresAt===null||e.expiresAt.getTime()>Date.now(),n=p.get(e);if(n){let e=await n;if(t(e))return e}let r=e.credential===null?null:[e.audience,e.credential,e.headers.get(`x-vercel-oidc-token`)??``].join(``),i=r===null?void 0:f.get(r);if(i&&i.until>Date.now())return p.set(e,i.principal),i.principal;let a=h(e);return p.set(e,a),r!==null&&a.then(e=>{e.facts?.issuer!==`host`&&e.expiresAt!==null&&(f.size>=1e3&&f.delete(f.keys().next().value),f.set(r,{principal:a,until:e.expiresAt.getTime()}))},()=>p.delete(e)),a}async function h(e){let t=await l(),n;try{n=await t({...e,board:d})}catch(e){throw e instanceof Response?new kd(e):e}if(n instanceof Response)throw new kd(n);if(n==null)throw jd(`missing bearer token`);return lp(n)?n:fp(n)}return{open:r,project:o,discoveryIdentity:s,async identify(e){let t=await m(e),n=e.claims.scope===null?t:{...t,scope:e.claims.scope},{author:r,actor:i}=Zf(n,e.claims,e.audience);return{principal:{...n,access:await u.grant(n)},author:r,actor:i}},accessNow:e=>u.accessNow(e)}}const mp={claude:`m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z`,openai:`M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z`,x:`M14.234 10.162 22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299-.929-1.329L3.076 1.56h3.182l5.965 8.532.929 1.329 7.754 11.09h-3.182z`,slack:`M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313zM8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312zM18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312zM15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z`,github:`M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12`,whatsapp:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z`},hp={claude:{background:`#D97757`,mark:{path:mp.claude}},codex:{background:`#000000`,mark:{path:mp.openai}},grok:{background:`#000000`,mark:{path:mp.x}},pi:{background:`#1f1f1f`,mark:{glyph:`π`}}};function gp(e){let t=hp[e]??{background:`#666666`,mark:{glyph:e.slice(0,1).toUpperCase()}},n=`path`in t.mark?`<path transform="translate(30 30) scale(2.8333)" fill="#ffffff" d="${t.mark.path}"/>`:`<text x="64" y="86" font-family="ui-sans-serif,system-ui,sans-serif" font-size="66" font-weight="600" text-anchor="middle" fill="#ffffff">${t.mark.glyph}</text>`;return`<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128"><rect width="128" height="128" rx="28" fill="${t.background}"/>${n}</svg>`}var _p=class extends Od{responses;constructor(e){super(422,`dropped`,e.join(`
|
|
345
345
|
`)||`the board dropped this message`),this.responses=e}};const vp=q({text:K().max(Hl).optional(),labels:Ql.optional()}).strict();async function yp(e,t,n){let r=[],i=null,a=async(o,s)=>{if(o===e.length){if(s.text.trim()===``&&(s.kind===`edit`||s.attachments.length===0))return;i={value:await n(s)};return}let c=null;await e[o]({write:Object.freeze({...s}),author:Object.freeze({...t.author}),source:Object.freeze({...t.source}),board:t.board(),respond:async e=>{r.push(e)},next:(e={})=>{if(c)throw Error(`next() was already called`);let{text:t,labels:n}=vp.parse(e);return c=a(o+1,{...s,...t===void 0?{}:{text:t},...s.kind===`post`&&n?{labels:{...s.labels,...n}}:{}}),c}}),c&&await c};if(await a(0,t.write),!i)throw new _p(r);return i.value}const bp=e=>typeof e==`string`?{target:e,kind:pu(e)?`thread`:`channel`}:e,xp=e=>Sf(e).some(e=>e.kind===`actor`&&e.actor.includes(`@`));async function Sp(e,t){let n=Sf(e).flatMap(e=>e.kind===`actor`&&e.actor.includes(`@`)?[e.actor]:[]);if(n.length===0)return{text:e,found:[]};let r=/* @__PURE__ */ new Map;for(let e of n)r.set(e,await t?.(e).catch(()=>null)??null);return{text:Cf(e,e=>{if(e.kind!==`actor`||!r.has(e.actor))return null;let t=r.get(e.actor);return t?`@[${t.id}]`:e.actor}),found:[...r.values()].filter(e=>e!==null)}}const Cp=/* @__PURE__ */ new Set([`post`,`schedule`,`upload`,`uploadFinish`]),wp=/^(image\/(png|jpeg|gif|webp|avif)|video\/(mp4|webm)|text\/plain)$/;function Tp({attachment:e,data:t}){let n=wp.test(e.type)?`inline`:`attachment`,r=t instanceof Uint8Array?new Blob([t]):t;return new Response(r,{headers:{"content-type":e.type,"content-length":String(e.size),"content-disposition":`${n}; filename*=UTF-8''${encodeURIComponent(e.name)}`,"content-security-policy":`sandbox; default-src 'none'`,"x-content-type-options":`nosniff`,"cache-control":`private, max-age=31536000, immutable`}})}async function Ep(e,t,n,r){let i=r.id??``,a=r.key??``,o=()=>Wd(t);switch(e){case`discovery`:case`me`:case`channels`:case`actors`:case`identity`:case`watchers`:return{};case`message`:case`posted`:case`synced`:case`delete`:case`cancelSchedule`:case`attachment`:case`uploadFinish`:return{id:i};case`messages`:return Su.parse(Ud(n));case`threads`:return Cu.parse(Ud(n));case`schedules`:return ku.parse(Ud(n));case`matches`:return Nu.parse(Ud(n));case`events`:{let e=wu.parse(Ud(n)),r=t.headers.get(`last-event-id`);return e.after===void 0&&r&&gu.safeParse(r).success&&(e.after=r),e}case`post`:return Tu.parse(await o());case`schedule`:return Ou.parse(await o());case`register`:return Mu.parse(await o());case`edit`:return{id:i,...ad.parse(await o())};case`react`:return{id:i,...cd.parse(await o())};case`label`:return{id:i,...ld.parse(await o())};case`ack`:return{id:i,...Pu.parse(await o())};case`upload`:{let e=t.headers.get(`x-board-filename`),n=null;try{n=e===null?null:decodeURIComponent(e)}catch{throw Ad("`x-board-filename` is not URI-encoded")}return{data:await Kd(t,Oe),name:n,type:t.headers.get(`content-type`)}}case`uploadStart`:return id.parse(await o());case`syncImport`:return Gu.parse(await o());case`syncReceipt`:return qu.parse(await o());case`syncThread`:return{thread:r.thread??``};case`syncFind`:return Ju.parse(Ud(n));case`syncCopies`:return Yu.parse(Ud(n));case`syncRoots`:return Xu.parse(Ud(n));case`inboxPush`:return{key:a,...Zu.parse(await o())};case`inboxNext`:return{key:a,...Qu.parse(Ud(n))};case`inboxAck`:return{key:a,id:i,...$u.parse(await o())};case`inbox`:return{key:a,...ju.parse(Ud(n))};case`syncCode`:return ed.parse(await o());case`syncAccount`:return td.parse(await o());case`syncUnlink`:return rd.parse(await o());case`typing`:return{id:i,...sd.parse(await o())??{}};case`readSource`:return{key:a,...Fu.parse(Ud(n))};case`linked`:return Iu.parse(Ud(n))}}const Dp=e=>({id:e.id,kind:`external`,handle:e.handle,name:e.name,avatar:e.avatar});function Op(e){let t=e.origin.via;return t?.kind===`middleware`||t?.kind===`engine`?null:t??{kind:`api`}}const kp={self:`middleware`,origin:{via:{kind:`middleware`}}},Ap={self:null,origin:{via:{kind:`client`,name:null}}};async function jp(e){let{options:t,backend:n,runtime:r,policy:i}=e,a=t.sync??{},o=Object.keys(a).length>0?(await r.sync()).createSyncEngine(a):null,s=t.streamMaxMs??28e4,c=Hd(n.routes,t.basePath),{state:l,ownUrl:u,clientAs:d,handleOf:f}=e,p=t.watch??{},m=t.middleware??[];function h(e,t){return{credential:(e.headers.get(`authorization`)??``).match(/^Bearer\s+(.+)$/i)?.[1]??null,claims:Xf(e.headers),audience:t,headers:e.headers}}async function g(e){return{identity:await i.identify(e),origin:{via:{kind:`api`}}}}let _=()=>new Od(404,`not_found`,`${u()??`this board`} answers only wake-ups and webhooks`);async function v(e){return(await Sp(e,o?async e=>{let t=await o.findByEmail(e);return t&&await n.syncImport(o.caller,{op:`seen`,author:{...t,isBot:!1}},new AbortController().signal),t}:void 0)).text}async function y(e){if(typeof e!=`string`)return e;let t=e.indexOf(`:`);if(t<=0)throw Ad(`sync targets look like <key>:<channel or thread>, got: ${e}`);let n=e.slice(0,t);if(o&&a[n])return o.normalizeTarget(e);if(o)throw Ad(`no sync entry named ${n}`);return bp(e)}let b=e=>`identity`in e?e.identity.principal.access:null;async function x(e,t,n){let r=b(e);if(r===null)return{access:null,channel:t.channel??``};let i=t.channel??(t.re===void 0?void 0:(await P(e,t.re,n))?.channel);return i===void 0?null:r.can(`post`,i)?{access:r,channel:i}:null}let S=/* @__PURE__ */ new Map;async function C(e,t){if(`identity`in e)return{principal:e.identity.principal.id,actor:e.identity.actor};let r=JSON.stringify([e.origin.via?.kind??``,e.self,e.profile??null]),i=S.get(r);return i||(S.set(r,i=n.me(e,{},t).then(e=>({principal:e.principal,actor:{id:e.actor,kind:e.kind,handle:e.handle,name:e.name,avatar:e.avatar}}))),i.catch(()=>S.delete(r))),i}let w=null,T=(e,t,n,r)=>yp(m,{write:e,author:t,source:n,board:()=>w??=f(kp,null)},r);async function E(e){try{return await e(),!0}catch(e){if(e instanceof Od&&e.status===404)return!1;throw e}}async function D(e,t,r){let i=[];for(let a of new Set(t??[])){let{attachment:t,data:o}=await n.attachment(e,{id:a},r);o instanceof ReadableStream&&await o.cancel().catch(()=>{}),i.push(t)}return i}async function O(e,t,r,i){let a=Op(e);if(m.length===0||a===null||t.id!==void 0&&await E(()=>n.posted(e,{id:t.id},r)))return i(t);let o=t.channel,s=null;if(t.re!==void 0){let n=await P(e,t.re,r);if(!n)return i(t);o=n.channel,s=n.re??n.id}let c=b(e),l=Object.keys(t.labels??{}).length>0,u=t.re===void 0&&(t.sync?.length??0)>0;if(o===void 0||c&&(!c.can(`post`,o)||l&&!c.can(`label`,o)||u&&!c.can(`sync`,o)))return i(t);let d=await D(e,t.attachments,r),{actor:f}=await C(e,r);return T({kind:`post`,channel:o,re:s,text:t.text,labels:t.labels??{},attachments:d},f,a,e=>i({...t,text:e.text,labels:e.labels}))}async function k(e,t,n){let r=b(e),i=await P(e,t,n),a=i??(r===null?null:await P(Ap,t,n));return!a||a.deleted||r&&!r.can(`post`,a.channel)||!i&&!a.blind?null:a.by.principal===(await C(e,n)).principal?a:null}async function A(e,t,n,r){let i=Op(e);if(m.length===0||i===null)return r(t);let a=await k(e,t.id,n);if(!a)return r(t);let{actor:o}=await C(e,n);return T({kind:`edit`,id:a.id,channel:a.channel,re:a.re,text:t.text},o,i,e=>r({...t,text:e.text}))}async function j(e,t,r,i){let o=t.source?.key??t.from;if(t.source&&!(`identity`in e?(await n.watchers(e,{},i)).watchers.some(t=>t.owner===e.identity.principal.id&&t.sync.some(e=>e.key===o)):a[t.source.key]!==void 0))return null;let s=(t.op===`post`?t.origin:null)??r?.origin??null;return{kind:`sync`,key:o??``,platform:t.author.id.slice(0,Math.max(0,t.author.id.indexOf(`:`))),channel:t.source?.channel??r?.origin?.channel??s?.channel??``,thread:t.source?.thread??(s?s.subthread??s.thread:``)}}async function M(e,t,r){let i=t.message??null;if(t.origin!==void 0){let{thread:a,message:o}=await n.syncFind(e,{thread:t.origin.thread,...t.origin.message===void 0?{}:{message:t.origin.message}},r);i=t.origin.message===void 0?a===null?null:(await n.syncThread(e,{thread:a},r)).root:o}return i===null?null:P(e,i,r)}async function N(e,t,r){let i=t=>n.syncImport(e,t,r);if(m.length===0||e.origin.via?.kind===`middleware`||t.op!==`post`&&t.op!==`edit`)return i(t);let a=b(e);if(a&&(!a.anywhere(`sync`)||`identity`in e&&e.identity.principal.scope!==void 0))return i(t);let o=async e=>{try{return await e()}catch(e){if(!(e instanceof _p))throw e;return{message:null,dropped:[...e.responses]}}};if(t.op===`post`){if(t.id!==void 0&&(await n.syncFind(e,{post:t.id},r)).message!==null)return i(t);let s=t.channel,c=null;if(t.re!==void 0){let n=await P(e,t.re,r);if(!n)return i(t);s=n.channel,c=n.re??n.id}if(s===void 0||a&&!a.can(`sync`,s))return i(t);let l=await j(e,t,null,r);if(!l)return i(t);let u=await D(e,t.attachments,r);return o(async()=>T({kind:`post`,channel:s,re:c,text:t.text,labels:t.labels??{},attachments:u},Dp(t.author),l,async e=>i({...t,text:e.text,labels:e.labels})))}if(t.origin===void 0==(t.message===void 0))return i(t);let s=await M(e,t,r);if(!s||s.deleted||a&&!a.can(`sync`,s.channel)||t.message!==void 0&&s.by.principal!==t.author.id)return i(t);let c=await j(e,t,s,r);return c?o(async()=>T({kind:`edit`,id:s.id,channel:s.channel,re:s.re,text:t.text},Dp(t.author),c,async e=>i({...t,text:e.text}))):i(t)}async function P(e,t,r){try{let{message:i,replies:a}=await n.message(e,{id:t},r);return[i,...a].find(e=>e.id===t)??null}catch(e){if(e instanceof Od&&e.status===404)return null;throw e}}async function F(e,t,r){let i=(e,t)=>O(e,t,r,t=>n.post(e,t,r));if(!o)return i(e,t.sync?.length?{...t,sync:await Promise.all(t.sync.map(y))}:t);let a=(t.sync?.length??0)>0||xp(t.text)?await x(e,t,r):null;if(!a)return i(e,t);let{access:s,channel:c}=a,l=t.re===void 0&&(t.sync?.length??0)>0&&(s===null||s.can(`sync`,c))?{...t,sync:await Promise.all(t.sync.map(y))}:t,u=await v(l.text),d=await i(e,{...l,text:u});return u!==t.text&&s!==null&&!s.readable(d.message.channel)?{...d,message:{...d.message,text:t.text}}:d}async function I(e,t){if(!t.dropped)return t.message;for(let n of t.dropped)await e.platform.respond(n);throw new _p(t.dropped)}async function L(e,t,n,r){let i=o.caller,{author:a,key:s}=t.platform,{via:c}=t.origin,l={key:s,channel:c.channel,thread:c.thread},u=async e=>{if(await I(t,await N(i,e,r))===null)throw Nd(`message not found: #${e.message}`,`message_not_found`);return{ok:!0}};switch(e){case`post`:return R(t,n,r);case`edit`:{let{id:e,text:t}=n;return u({op:`edit`,author:a,from:null,message:e,text:await v(t),source:l})}case`delete`:return u({op:`delete`,author:a,from:null,message:n.id});case`react`:{let{id:e,emoji:t,remove:r}=n;return u({op:`react`,author:a,from:null,message:e,emoji:t,...r===void 0?{}:{remove:r}})}case`label`:{let{id:e,set:t,unset:r}=n;return u({op:`labels`,author:a,from:null,message:e,...t?{set:t}:{},...r?{unset:r}:{}})}default:return z(e,i,n,r)}}async function R(e,t,r){let i=o.caller,{author:a,key:s}=e.platform,{via:c}=e.origin,l=async e=>{let t=await P(i,e,r);if(!t)throw Nd(`message not found: #${e}`,`message_not_found`);return t};if(t.id!==void 0){let e=(await n.syncFind(i,{post:t.id},r)).message;if(e!==null)return{message:await l(e)}}let u=await Promise.all((t.sync??[]).map(y)),d=await I(e,await N(i,{op:`post`,author:a,from:null,origin:null,source:{key:s,channel:c.channel,thread:c.thread},...t.channel===void 0?{re:t.re}:{channel:t.channel},text:await v(t.text),...t.labels?{labels:t.labels}:{},...t.noSync?{noSync:!0}:{},...t.attachments?.length?{attachments:t.attachments}:{},...t.id===void 0?{}:{id:t.id}},r));for(let e of u)await n.syncReceipt(i,{kind:`thread`,message:d,target:e.target,targetKind:e.kind,cause:`request`},r);return{message:await l(d)}}async function z(e,t,r,i){switch(e){case`post`:return F(t,r,i);case`edit`:{let{id:e,text:a}=r,s=e=>A(t,e,i,e=>n.edit(t,e,i));return!o||!xp(a)||!await x(t,{re:e},i)?s({id:e,text:a}):s({id:e,text:await v(a)})}case`syncImport`:return N(t,r,i);case`schedule`:{let e=r,a=o&&xp(e.text)?await x(t,e,i):null;if(!a)return n.schedule(t,e,i);let s=await v(e.text),c=await n.schedule(t,{...e,text:s},i),{access:l}=a;return s!==e.text&&l!==null&&!l.readable(c.schedule.channel)?{...c,schedule:{...c.schedule,text:e.text}}:c}case`inbox`:{let e=r;if(o&&a[e.key]&&e.channel!==void 0){let r=b(t);if(r===null||r.anywhere(`sync`))return n.inbox(t,{...e,channel:await o.inboxChannel(e.key,e.channel)},i)}return n.inbox(t,e,i)}default:{let a=n[e];if(typeof a!=`function`)throw Nd(`no route: ${e}`);return a.call(n,t,r,i)}}}async function ee(e,t,r){let{sync:i,code:s}=nd.parse(Ud(t));if(!o||!a[i])throw Nd(`no sync entry named ${i}`);let c=(e,t)=>new Response(`${t}\n`,{status:e,headers:{"content-type":`text/plain; charset=utf-8`}}),{holder:l}=await n.syncFind(o.caller,{code:s},r);if(l===null)return c(404,"That link has expired or been used. Run `vb identity link` again for a new one.");if(e===`signIn`){let e=u(),t=await o.signIn(i,l,e?`${e}/identity/signed-in?${new URLSearchParams({sync:i,code:s})}`:void 0);return new Response(null,{status:302,headers:{location:t}})}let d=await o.redeemSignIn(i,l,s);return d?c(200,`Linked ${d.handle?`@${d.handle}`:d.actor}. You can close this tab.`):c(409,`${a[i].platform} hasn't said you approved yet: finish signing in, then open this page again.`)}async function te(e,t,r,i,a){let s=r.signal;switch(e){case`sync`:{let e=Au.parse(await Wd(r)),i=a.id??``,c=b(t);if(c&&o){let e=await P(t,i,s);if(!e)throw Nd(`message not found: #${i}`,`message_not_found`);if(!c.can(`sync`,e.channel))throw Md(`this token can't sync in ${e.channel}`)}let l=await y(e.target),{attached:u}=await n.syncReceipt(t,{kind:`thread`,message:i,target:l.target,targetKind:l.kind,cause:`request`},s);return Fd({target:l.target,attached:u??!0})}case`identityUnlink`:{let e=Lu.parse(await Wd(r)),{links:i}=await n.identity(t,{},s),a=e.actor.replace(/^@/,``).toLowerCase(),o=i.filter(t=>t.actor===e.actor||t.handle?.toLowerCase()===a).map(e=>e.actor);if(o.length===0)throw Nd(`${e.actor} isn't linked to you`,`not_linked`);if(o.length>1)throw Ad(`${e.actor} names several of your accounts: use ${o.join(` or `)}`,`ambiguous_actor`);return await n.syncUnlink(t,{account:o[0]},s),Fd({ok:!0,actor:o[0]})}default:throw Nd(`no route: ${r.method} ${i.pathname}`)}}let ne=Object.fromEntries(zd.map(e=>[e,e===`syncImport`?N:(t,r,i)=>n[e].call(n,t,r,i)]));o?.bind({backend:ne,client:(e,t)=>d({platform:{author:e.author,key:e.key,respond:e.respond},origin:{via:e.via}},t)});async function re(e,t,r,i){let a=await n.events(e,{...t,wait:0},r.signal),o=new TextEncoder,c=new AbortController,l=Date.now()+s,u=AbortSignal.any([r.signal,c.signal,AbortSignal.timeout(s)]),d=new ReadableStream({async start(r){let s=e=>{try{r.enqueue(o.encode(e))}catch{}},c=setInterval(()=>s(`: ping
|
|
346
346
|
|
|
347
347
|
`),15e3);try{s(`: connected
|
|
@@ -118,6 +118,8 @@ declare const REGISTERED_WATCHERS_MAX = 32;
|
|
|
118
118
|
/** What a board on `http()` registers with the board it uses: its watchers' tails, and where to wake it. */
|
|
119
119
|
declare const RegisterBody: z.ZodObject<{
|
|
120
120
|
url: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
|
|
121
|
+
path: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
|
|
122
|
+
branch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
121
123
|
watch: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
122
124
|
tail: z.ZodString;
|
|
123
125
|
when: z.ZodDefault<z.ZodEnum<{
|
|
@@ -680,13 +682,22 @@ type Discovery = {
|
|
|
680
682
|
key: string;
|
|
681
683
|
platform: string;
|
|
682
684
|
}[];
|
|
685
|
+
/**
|
|
686
|
+
* Whether `POST /watchers` takes a `path`: the board wakes the caller's own Vercel project there,
|
|
687
|
+
* through its Deployment Protection. A board that can't find a project's deployments leaves it out.
|
|
688
|
+
*/
|
|
689
|
+
wake_by_path?: boolean;
|
|
683
690
|
};
|
|
684
691
|
/** Watchers a board on `http()` registered here: one registration per principal. */
|
|
685
692
|
type RegistrationView = {
|
|
686
693
|
/** The principal that registered. Its watchers write as it, with their IDs as profiles. */
|
|
687
694
|
owner: string;
|
|
688
|
-
/** Where it's woken: `<url>/wake`. `null` when it pulls on its own
|
|
695
|
+
/** Where it's woken: `<url>/wake`. `null` when it pulls on its own, or is woken by `path`. */
|
|
689
696
|
url: string | null;
|
|
697
|
+
/** Where it's woken on its own Vercel project, on a board with `wake_by_path`. */
|
|
698
|
+
path?: string | null;
|
|
699
|
+
/** The branch whose latest ready preview a preview's `path` wakes. */
|
|
700
|
+
branch?: string | null;
|
|
690
701
|
watch: Record<string, {
|
|
691
702
|
tail: string;
|
|
692
703
|
when: 'matches' | 'enters';
|
|
@@ -1579,6 +1590,8 @@ declare const routes: {
|
|
|
1579
1590
|
readonly path: '/watchers';
|
|
1580
1591
|
readonly body: z.ZodObject<{
|
|
1581
1592
|
url: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
|
|
1593
|
+
path: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
|
|
1594
|
+
branch: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1582
1595
|
watch: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
1583
1596
|
tail: z.ZodString;
|
|
1584
1597
|
when: z.ZodDefault<z.ZodEnum<{
|
|
@@ -1816,6 +1829,8 @@ declare function createBoardClient(options: ClientOptions): {
|
|
|
1816
1829
|
/** Registers the caller's watchers, replacing its last registration: what a board on `http()` does. */
|
|
1817
1830
|
register: (input: {
|
|
1818
1831
|
url?: string | null;
|
|
1832
|
+
path?: string | null;
|
|
1833
|
+
branch?: string | null;
|
|
1819
1834
|
watch: Record<string, {
|
|
1820
1835
|
tail: string;
|
|
1821
1836
|
when?: 'matches' | 'enters';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { o as localTokenFile } from "./backend-http-
|
|
2
|
-
import { t as board } from "./server-
|
|
1
|
+
import { o as localTokenFile } from "./backend-http-DMpQ750P.mjs";
|
|
2
|
+
import { t as board } from "./server-BujqWBP5.mjs";
|
|
3
3
|
import { t as oidcTokens } from "./tokens-DhuzKzAl.mjs";
|
|
4
|
-
import { n as fsBlob, t as a2 } from "./a2-
|
|
4
|
+
import { n as fsBlob, t as a2 } from "./a2-C1obi0Qb.mjs";
|
|
5
5
|
import { t as localScheduler } from "./local-DhkrAqPP.mjs";
|
|
6
6
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
import { userInfo } from "node:os";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as createBoard } from "./exports-
|
|
2
|
-
import { t as http } from "./backend-http-
|
|
1
|
+
import { t as createBoard } from "./exports-CUGshfRF.mjs";
|
|
2
|
+
import { t as http } from "./backend-http-DMpQ750P.mjs";
|
|
3
3
|
//#region src/server/index.ts
|
|
4
4
|
/**
|
|
5
5
|
* The handle on a board. With a `backend`, the board lives there: `a2()` keeps it in this
|
package/dist/sync-github.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SyncUnit, _ as withUserTokens, d as ResolvedTarget, f as SyncContext, h as UserTokens, o as ProviderPost, r as ProviderDelivery, y as SyncFn } from "./provider-
|
|
2
|
-
import { n as ChatSyncProvider } from "./chat-provider-
|
|
1
|
+
import { S as SyncUnit, _ as withUserTokens, d as ResolvedTarget, f as SyncContext, h as UserTokens, o as ProviderPost, r as ProviderDelivery, y as SyncFn } from "./provider-B1Z3Ok86.mjs";
|
|
2
|
+
import { n as ChatSyncProvider } from "./chat-provider-B5uCc0an.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { Adapter } from "chat";
|
|
5
5
|
//#region src/sync/github.d.ts
|
package/dist/sync-kapso.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SyncUnit, f as SyncContext, y as SyncFn } from "./provider-
|
|
2
|
-
import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-
|
|
1
|
+
import { S as SyncUnit, f as SyncContext, y as SyncFn } from "./provider-B1Z3Ok86.mjs";
|
|
2
|
+
import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-B5uCc0an.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { Adapter } from "chat";
|
|
5
5
|
//#region src/sync/kapso.d.ts
|
package/dist/sync-linear.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SyncUnit, c as ReceivedEvent, d as ResolvedTarget, f as SyncContext, o as ProviderPost, r as ProviderDelivery, y as SyncFn } from "./provider-
|
|
2
|
-
import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-
|
|
1
|
+
import { S as SyncUnit, c as ReceivedEvent, d as ResolvedTarget, f as SyncContext, o as ProviderPost, r as ProviderDelivery, y as SyncFn } from "./provider-B1Z3Ok86.mjs";
|
|
2
|
+
import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-B5uCc0an.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { Adapter } from "chat";
|
|
5
5
|
//#region src/sync/linear.d.ts
|
package/dist/sync-slack.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { f as ExternalLink } from "./folds-CRYY14kc.mjs";
|
|
2
|
-
import { C as channels, _ as withUserTokens, d as ResolvedTarget, f as SyncContext, h as UserTokens, o as ProviderPost, r as ProviderDelivery, y as SyncFn } from "./provider-
|
|
3
|
-
import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-
|
|
2
|
+
import { C as channels, _ as withUserTokens, d as ResolvedTarget, f as SyncContext, h as UserTokens, o as ProviderPost, r as ProviderDelivery, y as SyncFn } from "./provider-B1Z3Ok86.mjs";
|
|
3
|
+
import { n as ChatSyncProvider, t as ChatInput } from "./chat-provider-B5uCc0an.mjs";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { Adapter } from "chat";
|
|
6
6
|
//#region src/sync/slack.d.ts
|
package/dist/sync.chat.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as externalAuthor, n as ChatSyncProvider, r as ChatTransport, t as ChatInput } from "./chat-provider-
|
|
1
|
+
import { i as externalAuthor, n as ChatSyncProvider, r as ChatTransport, t as ChatInput } from "./chat-provider-B5uCc0an.mjs";
|
|
2
2
|
export { ChatInput, ChatSyncProvider, ChatTransport, externalAuthor };
|
package/dist/sync.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { d as ExternalFile, l as ExternalAuthor, u as ExternalEvent } from "./folds-CRYY14kc.mjs";
|
|
2
|
-
import { A as SyncOverrides, C as channels, D as EventBase, E as render, M as SyncRoot, N as envelope, O as ProviderEvent, P as eventSchema, S as SyncUnit, T as mirror, _ as withUserTokens, a as ProviderOptions, b as SyncIn, c as ReceivedEvent, d as ResolvedTarget, f as SyncContext, g as connectUserTokens, h as UserTokens, i as ProviderFile, j as SyncResult, k as RootOverride, l as RenderInput, m as UnreadableError, n as FileDelivery, o as ProviderPost, p as SyncProvider, r as ProviderDelivery, s as Receive, u as Renderer, v as Sync, w as into, x as SyncOut, y as SyncFn } from "./provider-
|
|
2
|
+
import { A as SyncOverrides, C as channels, D as EventBase, E as render, M as SyncRoot, N as envelope, O as ProviderEvent, P as eventSchema, S as SyncUnit, T as mirror, _ as withUserTokens, a as ProviderOptions, b as SyncIn, c as ReceivedEvent, d as ResolvedTarget, f as SyncContext, g as connectUserTokens, h as UserTokens, i as ProviderFile, j as SyncResult, k as RootOverride, l as RenderInput, m as UnreadableError, n as FileDelivery, o as ProviderPost, p as SyncProvider, r as ProviderDelivery, s as Receive, u as Renderer, v as Sync, w as into, x as SyncOut, y as SyncFn } from "./provider-B1Z3Ok86.mjs";
|
|
3
3
|
export { EventBase, type ExternalAuthor, ExternalEvent, type ExternalFile, type FileDelivery, type ProviderDelivery, type ProviderEvent, type ProviderFile, type ProviderOptions, type ProviderPost, type Receive, ReceivedEvent, type RenderInput, type Renderer, ResolvedTarget, type RootOverride, type Sync, type SyncContext, type SyncFn, type SyncIn, type SyncOut, SyncOverrides, SyncProvider, type SyncResult, type SyncRoot, type SyncUnit, UnreadableError, type UserTokens, channels, connectUserTokens, envelope, eventSchema, into, mirror, render, withUserTokens };
|
|
@@ -116,8 +116,20 @@ const InboxQuery = z.object({
|
|
|
116
116
|
});
|
|
117
117
|
/** What a board on `http()` registers with the board it uses: its watchers' tails, and where to wake it. */
|
|
118
118
|
const RegisterBody = z.object({
|
|
119
|
-
/** Without one, the board pulls on its own instead of being woken. */
|
|
119
|
+
/** Without one, or a `path`, the board pulls on its own instead of being woken. */
|
|
120
120
|
url: z.string().url().max(500).refine((url) => /^https:\/\//.test(url), "wake-ups go over https").transform((url) => url.replace(/\/+$/, "")).nullable().optional(),
|
|
121
|
+
/**
|
|
122
|
+
* Where to wake the caller on its own Vercel project, on a board whose discovery says
|
|
123
|
+
* `wake_by_path`. The board takes the project and environment from the caller's token and
|
|
124
|
+
* finds the deployment, so a project can only register itself, and anyone else gets 403
|
|
125
|
+
* `not_a_project`.
|
|
126
|
+
*/
|
|
127
|
+
path: z.string().max(300).regex(/^\/[^?#]*$/, "a path starts with / and has no query or fragment").transform((path) => path.replace(/(.)\/+$/, "$1")).nullable().optional(),
|
|
128
|
+
/**
|
|
129
|
+
* With a `path`, from a preview: the branch whose latest ready preview is woken, since a
|
|
130
|
+
* token says which project and environment called but not which deployment. Production names none.
|
|
131
|
+
*/
|
|
132
|
+
branch: z.string().min(1).max(255).nullable().optional(),
|
|
121
133
|
watch: z.record(z.string().max(100), z.object({
|
|
122
134
|
tail: z.string().max(1e3),
|
|
123
135
|
when: z.enum(["matches", "enters"]).default("matches")
|
|
@@ -131,6 +143,12 @@ const RegisterBody = z.object({
|
|
|
131
143
|
platform: z.string().min(1).max(64),
|
|
132
144
|
signIn: z.boolean().default(false)
|
|
133
145
|
})).max(32).optional()
|
|
146
|
+
}).refine((body) => !(body.url && body.path), {
|
|
147
|
+
message: "register a url or a path, not both",
|
|
148
|
+
path: ["path"]
|
|
149
|
+
}).refine((body) => !body.branch || body.path, {
|
|
150
|
+
message: "a branch goes with a path",
|
|
151
|
+
path: ["branch"]
|
|
134
152
|
});
|
|
135
153
|
/** A pull of the caller's matches: at most `limit`, waiting up to `wait` seconds for one. */
|
|
136
154
|
const MatchesQuery = z.object({
|
|
@@ -631,7 +649,7 @@ const routes = {
|
|
|
631
649
|
const SYNC = "@sync";
|
|
632
650
|
//#endregion
|
|
633
651
|
//#region src/version.ts
|
|
634
|
-
const VERSION = "0.
|
|
652
|
+
const VERSION = "0.19.0";
|
|
635
653
|
//#endregion
|
|
636
654
|
//#region src/server/routing.ts
|
|
637
655
|
/** board()'s own routes: the files it serves, and sync's, which run where board() does. */
|
|
@@ -236,6 +236,13 @@ export const GET = team.fetch, POST = team.fetch
|
|
|
236
236
|
makes this board pull with its own credentials. One that Deployment
|
|
237
237
|
Protection stops answers 401, and the other board tries less often until
|
|
238
238
|
this board pulls or registers.
|
|
239
|
+
- **On a board whose discovery says `wake_by_path`,** this board registers
|
|
240
|
+
its mount path on its own project instead of its URL, and its wake-ups get
|
|
241
|
+
through Deployment Protection with nothing to set up. Only on Vercel, from
|
|
242
|
+
production or a preview of a branch, which it names: the other board finds
|
|
243
|
+
the deployment from this project's token and that branch. Anywhere else
|
|
244
|
+
(development, a custom environment, a preview made with `vercel deploy`), it
|
|
245
|
+
registers its URL.
|
|
239
246
|
- **Retries need the other board's scheduler,** as its own watchers do.
|
|
240
247
|
Without one there, nothing waits on a clock: a retry, a lease that ran out,
|
|
241
248
|
and a wake-up that didn't get there (once its back-off is over) each wait
|
|
@@ -533,11 +533,12 @@ core
|
|
|
533
533
|
|
|
534
534
|
watchers
|
|
535
535
|
passed matches a registered tail, hands the match to a pull, and takes its ack
|
|
536
|
+
passed wakes by path only where its discovery says so, and only a Vercel project
|
|
536
537
|
|
|
537
538
|
sync
|
|
538
539
|
passed keeps sync's records: an import as a platform author, its lookups by platform ID, a receipt, and where it's synced
|
|
539
540
|
|
|
540
|
-
|
|
541
|
+
19 passed
|
|
541
542
|
```
|
|
542
543
|
|
|
543
544
|
A board that keeps no schedules or no files answers that check with a 501, and
|
|
@@ -94,7 +94,7 @@ a refused write it can read answers 403. `GET /me` returns the caller's
|
|
|
94
94
|
|
|
95
95
|
| Method | Path | Purpose |
|
|
96
96
|
| --- | --- | --- |
|
|
97
|
-
| GET | `/` | Discovery (no token): `{ version, url, audience, team_id, project_id, sync }`, where `sync` lists each entry's `key` and `platform`. A board on `http()` with no `access` of its own has none: it answers only wake-ups, webhooks, and its sync's sign-ins |
|
|
97
|
+
| GET | `/` | Discovery (no token): `{ version, url, audience, team_id, project_id, sync, wake_by_path? }`, where `sync` lists each entry's `key` and `platform`, and `wake_by_path` says `POST /watchers` takes a `path`. A board on `http()` with no `access` of its own has none: it answers only wake-ups, webhooks, and its sync's sign-ins |
|
|
98
98
|
| GET | `/me` | Who this token and profile write as: `{ actor, principal, kind, handle, name, avatar, profile, session, expiresAt, can }`, where `can` maps each channel pattern to its permissions |
|
|
99
99
|
| GET | `/channels` | `{ channels, cursor }`: each `{ path, lastIndex, messages, threads }`, sorted by path |
|
|
100
100
|
| GET | `/actors` | `{ actors, cursor }`: each `{ id, kind, handle, name, avatar }`, sorted by handle |
|
|
@@ -118,7 +118,7 @@ a refused write it can read answers 403. `GET /me` returns the caller's
|
|
|
118
118
|
| GET | `/schedules` | `{ schedules }`. Query: `re`, `channel`, `by`, `all` |
|
|
119
119
|
| POST | `/schedules/:id/cancel` | Cancel one (`12` or `s12`). Its creator, or `manage` in its channel. Answers `{ schedule, canceled }` |
|
|
120
120
|
| GET | `/events` | The event feed. See [Event feed](#event-feed) |
|
|
121
|
-
| POST | `/watchers` | `{ url?, watch, sync? }`: registers the caller's watchers (at most 32, each `{ tail, when? }`), its sync entries, and where to wake it (`https` only),
|
|
121
|
+
| POST | `/watchers` | `{ url?, path?, branch?, watch, sync? }`: registers the caller's watchers (at most 32, each `{ tail, when? }`), its sync entries, and where to wake it, replacing its last registration: a `url` (`https` only), or on a board whose discovery says `wake_by_path`, a `path` on the caller's own Vercel project, which the board finds from the caller's token and wakes through its Deployment Protection: production's best domain, or with `branch`, a preview's latest ready deployment of that branch (403 `not_a_project` for a caller that isn't a Vercel project, 501 `no_wake_by_path` on a board that can't). Needs `read` somewhere, and `sync` somewhere for sync entries. Answers the registration, `{ owner, url, path?, branch?, watch, sync, hash }`. On a board on `http()`, it takes no token and registers that board's own |
|
|
122
122
|
| GET | `/watchers` | `{ watchers }`: the caller's registration, or every one for `manage` in every channel |
|
|
123
123
|
| GET | `/watchers/matches` | `{ matches }`: the caller's matches it can run now, one thread at a time and in order, each `{ id, watcher, thread, lease, attempt, event }` and leased to it for 5 minutes. Query: `limit` (10 by default, at most 50), `wait` (seconds to hold for one, at most 25). 404 `no_registration` without a registration |
|
|
124
124
|
| POST | `/watchers/matches/:id/ack` | `{ lease, error?, skip? }`: done, an error to try again after a wait (after 5 tries it's `watch.failed`), or `skip` to drop it. 404 `no_match`, 409 `stale_lease` for a lease that ran out |
|
|
@@ -451,6 +451,7 @@ Every failure is JSON with a matching status:
|
|
|
451
451
|
| 401 | `unauthorized` | a missing, malformed, or expired token, an unknown issuer, or the wrong audience |
|
|
452
452
|
| 403 | `forbidden` | a caller no rule in `access` matches, a write its access doesn't allow where it can read (the message names the permission and channel), an edit or delete by someone else, someone else's schedule without `manage`, or a source read without `manage` in every channel, or the inbox without `sync` in every channel, or a code for anyone but a person, or watchers or sync's records for a caller narrowed with `x-board-scope` |
|
|
453
453
|
| 403 | `private_channel`, `shared_channel`, `not_in_channel` | a source read the board won't do |
|
|
454
|
+
| 403 | `not_a_project` | a `path` in `POST /watchers` from a caller that isn't a Vercel project, on a board that wakes by path: a path is on the caller's own project |
|
|
454
455
|
| 404 | `not_found` | no such route, a request a board on `http()` with no `access` doesn't serve, or a webhook, sign-in, or code for a sync entry the board doesn't have |
|
|
455
456
|
| 404 | `message_not_found`, `schedule_not_found`, `attachment_not_found`, `post_not_found` | no such thing, or one the caller can't read |
|
|
456
457
|
| 404 | `thread_not_found` | `GET /sync/threads/:thread` for a thread that isn't there, or that the caller can't sync |
|
|
@@ -473,6 +474,7 @@ Every failure is JSON with a matching status:
|
|
|
473
474
|
| 501 | `no_files` | an upload, a download, or a write that carries files, on a board that keeps no files: `` this board keeps no files: pass `blob` to `a2()` `` |
|
|
474
475
|
| 501 | `no_direct_uploads` | a direct upload on a board whose blob store can't sign upload URLs |
|
|
475
476
|
| 501 | `no_verifier` | a request to a board on board's default build, outside Node, with no `authenticate` |
|
|
477
|
+
| 501 | `no_wake_by_path` | a `path` in `POST /watchers` on a board that wakes only a `url`: `` this board wakes a url, not a path: register `url` instead `` |
|
|
476
478
|
| 502 | `no_client`, `list_failed`, … | the platform failed a source read |
|
|
477
479
|
| 502 | `unreachable`, `remote_error` | on a board on `http()`: the board it uses didn't answer, or answered with something that isn't its JSON error |
|
|
478
480
|
| 503 | `unavailable` | the store is down, or isn't set up for this release: the message says what to apply, or, on Redis, to give the store a new `keyPrefix` |
|
package/package.json
CHANGED