@agentage/extension-probe 0.1.0 → 0.4.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/README.md CHANGED
@@ -1,46 +1,80 @@
1
1
  # extension-probe
2
2
 
3
3
  The probe extension: one agentage extension with every part kind, the template every later
4
- extension copies. Today it has the api part: `GET /api/v1/echo?msg=hi` answers
5
- `{"success":true,"data":{"msg":"hi"}}` in the standard envelope, with an `agcid` header. The part
6
- code is only `create(ctx)` in [`src/api/index.ts`](src/api/index.ts); the kit
7
- [`@agentage/extension`](https://github.com/agentage/platform) owns the server, `/health`, the
8
- discovery document and the envelope. There is no Dockerfile: the kit's build tool builds the image.
4
+ extension copies. Each part is only `create(ctx)` (the ui part a `widgets` map); the kit
5
+ [`@agentage/extension`](https://github.com/agentage/platform) owns servers, ports, `/health`,
6
+ discovery, the envelope, the store connection, the scheduler and the command line. There is no
7
+ Dockerfile and no compose file: the kit's tool builds one image per part and runs them locally.
9
8
 
10
- ## Install
9
+ | Part | Source | Serves |
10
+ | ------ | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
11
+ | pages | [`src/pages`](src/pages/index.ts) | `/`: `probe {version} · {commit}` |
12
+ | ui | [`src/ui`](src/ui/index.ts) (`<probe-echo>`, React on `@agentage/widget`) | `/ui/{version}/probe.js`, `harness.html` |
13
+ | api | [`src/api`](src/api/index.ts) | `GET /api/v1/echo?msg=` (`probe:read`), `GET /api/v1/ticks?limit=&cursor=`, `openapi.json` |
14
+ | mcp | [`src/mcp`](src/mcp/index.ts) | `POST /mcp`: `probe__echo` (`probe:read`; [`probe.mcpc.json`](probe.mcpc.json)) |
15
+ | worker | [`src/worker`](src/worker/index.ts) | job `tick`, every minute, a row in `ticks` |
16
+ | store | [`migrations/`](migrations), [`seeds/`](seeds) | postgres; the api image's `node dist/store/migrate.js` applies them |
17
+ | cli | [`src/cli`](src/cli/index.ts) | `agentage ping [msg]` prints `pong` |
11
18
 
12
- ```bash
13
- npm ci
14
- npm run build
15
- ```
19
+ ## Install and run
16
20
 
17
- Until `@agentage/extension` is on npm, install it from a packed kit (see `scripts/kit-lock.mjs`):
21
+ Needs Node 22+, npm 10+, Docker, `git` and `jq`. On a clean machine, from nothing:
18
22
 
19
23
  ```bash
20
- (cd ../platform && npm ci && npm run build && npm pack -w @agentage/extension --pack-destination ../extension-probe/.kit)
21
- node scripts/kit-lock.mjs local .kit/agentage-extension-0.1.0.tgz && npm ci
22
- node scripts/kit-lock.mjs registry # before committing
24
+ git clone https://github.com/agentage/extension-probe && cd extension-probe
25
+ npm ci # the cli comes with it: npx agentage is the lockfile's
26
+ npx agentage extension up # last line: ready 7 parts healthy <n> s
27
+ echo "http://localhost:4280/ui/$(jq -r .version package.json)/harness.html" # open, click ping: pong hi
28
+ curl -s localhost:4280/.well-known/agentage-extension.json
29
+ T=$(npx agentage extension token --scope probe:read) # aga_... from the dev issuer on localhost:4281
30
+ curl -s -H "Authorization: Bearer $T" "localhost:4280/api/v1/echo?msg=hi" # {"success":true,"data":{"msg":"hi","caller":"usr_dev"}}
31
+ npx agentage extension install . # linked @agentage/extension-probe (working copy)
32
+ npx agentage ping # pong
33
+ npx agentage extension down # removed 8 containers · 1 network · 1 volume
23
34
  ```
24
35
 
25
- ## Run the image locally
36
+ A global `agentage` (0.42.0 or later) works the same as `npx agentage`. `up` builds the five part
37
+ images from the release recipe, writes `.agentage/record.json` from the local image digests (so
38
+ discovery is valid), starts postgres, runs the migrate job, the dev issuer (4281) and a Traefik
39
+ gateway (4280) with the URL layout of a deployment, then waits until every part is healthy and
40
+ prints `ready 7 parts healthy` and the seconds it took (15 to 35 s once the base images are pulled). Each checkout is
41
+ its own compose project, so `down` in one never touches another; a second checkout's `up` is
42
+ refused while the first holds 4280. On a kept volume (`down --keep-data`) the store line says
43
+ `1 migration already applied · 1 seed already applied`.
44
+
45
+ ## Verify
46
+
47
+ What CI runs, in order, with the counts a green run prints (2026-11-06):
26
48
 
27
49
  ```bash
28
- node ../platform/packages/extension/dist/tool/cli.js build # or: agentage extension build
29
- docker run --rm --network host ghcr.io/agentage/probe-api:0.1.0
30
- curl -s 127.0.0.1:3000/health # loopback only; commit = the build commit
31
- curl -s '127.0.0.1:3000/api/v1/echo?msg=hi'
32
- curl -s 127.0.0.1:3000/.well-known/agentage-extension.json
50
+ npm run verify # 31 tests passed, coverage over 70 %
51
+ npx agentage extension up # ready 7 parts healthy <n> s
52
+ scripts/image-smoke.sh "$(git rev-parse HEAD)" # 5 lines: PASS {part} commit ... ok
53
+ npx playwright install chromium # once; a bare Linux also needs --with-deps
54
+ npm run test:e2e # 10 passed (smoke and the widget tests)
33
55
  ```
34
56
 
35
- ## Verify
57
+ Then the gate of [agentage/e2e](https://github.com/agentage/e2e) (private: needs read access)
58
+ against the same `up`, from a checkout of that repo:
36
59
 
37
60
  ```bash
38
- npm run verify
61
+ npm ci && npx playwright install --with-deps chromium
62
+ PROBE_DIR=/path/to/extension-probe npm run e2e -- probe gate local # 55 passed, 5 skipped
39
63
  ```
40
64
 
65
+ `PROBE_DIR` lets the gate read `probe.mcpc.json`, `openapi.json` and the cli part from this
66
+ checkout; without it the cli part tests skip. The 5 skipped need a deployed release (the pinned
67
+ version, the release commit, the release record twice, the HTTPS redirect). CI fails a gate that
68
+ executed fewer than 30 tests or none of the cli part, and the job is bounded at 10 minutes (about 3
69
+ today).
70
+ Dependabot runs get no secrets, so they skip the agentage/e2e checkout and the gate (`up`, the
71
+ image smoke and `npm run test:e2e` still run).
72
+
41
73
  ## Release
42
74
 
43
75
  A `v*` tag equal to the `package.json` version runs `.github/workflows/release.yml`: it builds and
44
- pushes `ghcr.io/agentage/probe-api:{version}`, attaches the build record with the image digests to
45
- the GitHub release as `agentage-extension.json`, and publishes `@agentage/extension-probe` to npm
46
- with provenance.
76
+ pushes `ghcr.io/agentage/probe-{pages,ui,api,mcp,worker}:{version}`, attaches the build record with
77
+ the five digests to the GitHub release as `agentage-extension.json`, and publishes
78
+ `@agentage/extension-probe` to npm with provenance. A version's images never change: a re-run keeps
79
+ the released images and record and only retries npm, and a tag moved to another commit is refused
80
+ (`scripts/release-guard.sh`); a fix ships as a new version.
@@ -1,11 +1,44 @@
1
1
  {
2
2
  "id": "probe",
3
- "version": "0.1.0",
4
- "commit": "471a6d3373c868b4b19fed3cb1d48cdf4c0282d7",
5
- "buildTime": "2026-11-03T22:56:15Z",
3
+ "version": "0.4.0",
4
+ "commit": "2b9c8c03fa7ae5bb0aa776911bdd1182ad307e96",
5
+ "buildTime": "2026-11-06T19:22:16Z",
6
6
  "parts": {
7
+ "pages": {
8
+ "image": "ghcr.io/agentage/probe-pages@sha256:8f754f8102b8884854f6b420ec38d894404699b47f94504ed889e694d9d19230"
9
+ },
10
+ "ui": {
11
+ "image": "ghcr.io/agentage/probe-ui@sha256:07a92d7a8593e6344ed97ce6d1c5ce31f0cdbec933dee6ed42e9193ae9e9771b"
12
+ },
7
13
  "api": {
8
- "image": "ghcr.io/agentage/probe-api@sha256:1a89dafc7eec2cb388b0b77c1c8ebc52bf65d49e7f9b6cf8a47a2ca979666850"
14
+ "image": "ghcr.io/agentage/probe-api@sha256:272c30f862129f85b839bd66ebda59d2d97d86202a8149589d634a5c74412d22"
15
+ },
16
+ "mcp": {
17
+ "image": "ghcr.io/agentage/probe-mcp@sha256:b556e969b420f10912f8550e58b417f52434e1cef3443f6a90846a4530c1996f"
18
+ },
19
+ "worker": {
20
+ "image": "ghcr.io/agentage/probe-worker@sha256:a6577f396970743cc28adecb7331de7c059323ab11abcc344bcd838e98c3122d"
21
+ },
22
+ "store": {
23
+ "kind": "postgres",
24
+ "migrations": 1
9
25
  }
10
- }
26
+ },
27
+ "openapi": "/api/v1/openapi.json",
28
+ "tools": [
29
+ {
30
+ "name": "probe__echo",
31
+ "scope": "probe:read"
32
+ }
33
+ ],
34
+ "widgets": [
35
+ {
36
+ "name": "echo",
37
+ "element": "probe-echo",
38
+ "module": "/ui/0.4.0/probe.js"
39
+ }
40
+ ],
41
+ "commands": [
42
+ "ping"
43
+ ]
11
44
  }
@@ -1,3 +1,3 @@
1
1
  import { Router } from 'express';
2
2
  import { type PartContext } from '@agentage/extension';
3
- export declare const create: (_ctx: PartContext) => Router;
3
+ export declare const create: (ctx: PartContext) => Router;
package/dist/api/index.js CHANGED
@@ -1,12 +1,19 @@
1
1
  import { Router } from 'express';
2
2
  import { ok, parse } from '@agentage/extension';
3
- import { EchoQuerySchema } from './echo.schema.js';
4
- // The api part: mounted by the kit at /api/v1/; the caller field arrives with the token check.
5
- export const create = (_ctx) => {
3
+ import { EchoQuerySchema } from '../lib/echo.schema.js';
4
+ import { recentTicks, TicksQuerySchema } from '../lib/ticks.js';
5
+ // The kit mounts this router at /api/v1/.
6
+ export const create = (ctx) => {
6
7
  const router = Router();
7
8
  router.get('/echo', (req, res) => {
8
9
  const { msg } = parse(EchoQuerySchema, req.query, 'Invalid query');
9
- res.json(ok({ msg }));
10
+ res.json(ok({ msg, caller: ctx.auth.caller(req)?.sub }));
11
+ });
12
+ router.get('/ticks', async (req, res) => {
13
+ const query = parse(TicksQuerySchema, req.query, 'Invalid query');
14
+ const { ticks, total, nextCursor } = await recentTicks(ctx.store, query);
15
+ const pagination = { limit: query.limit, total, ...(nextCursor ? { nextCursor } : {}) };
16
+ res.json(ok(ticks, { pagination }));
10
17
  });
11
18
  return router;
12
19
  };
@@ -0,0 +1,4 @@
1
+ import { type CliContext } from '@agentage/extension';
2
+ export declare function create({ out, args }: CliContext): {
3
+ ping: () => Promise<number>;
4
+ };
@@ -0,0 +1,11 @@
1
+ import {} from '@agentage/extension';
2
+ // One handler per command in agentage.commands: `agentage ping [msg]`.
3
+ export function create({ out, args }) {
4
+ return {
5
+ ping: async () => {
6
+ const { msg } = args;
7
+ out.log(msg ? `pong ${msg}` : 'pong');
8
+ return 0;
9
+ },
10
+ };
11
+ }
@@ -0,0 +1,17 @@
1
+ import { type Store } from '@agentage/extension';
2
+ import { z } from 'zod';
3
+ export declare const TicksQuerySchema: z.ZodObject<{
4
+ limit: z.ZodPipe<z.ZodDefault<z.ZodCoercedNumber<unknown>>, z.ZodTransform<number, number>>;
5
+ cursor: z.ZodOptional<z.ZodString>;
6
+ }, z.core.$strict>;
7
+ export type TicksQuery = z.infer<typeof TicksQuerySchema>;
8
+ export interface Tick {
9
+ id: string;
10
+ job: string;
11
+ tickedAt: string;
12
+ }
13
+ export declare const recentTicks: (store: Store, query: TicksQuery) => Promise<{
14
+ ticks: Tick[];
15
+ total: number;
16
+ nextCursor: string | undefined;
17
+ }>;
@@ -0,0 +1,32 @@
1
+ import {} from '@agentage/extension';
2
+ import { z } from 'zod';
3
+ // api-standards section 3: default 50, a limit above 200 is clamped, not refused.
4
+ const MAX_LIMIT = 200;
5
+ export const TicksQuerySchema = z.strictObject({
6
+ limit: z.coerce
7
+ .number()
8
+ .int()
9
+ .min(1)
10
+ .default(50)
11
+ .describe(`page size; a limit above ${MAX_LIMIT} is clamped to ${MAX_LIMIT}`)
12
+ .transform((limit) => Math.min(limit, MAX_LIMIT)),
13
+ cursor: z
14
+ .string()
15
+ .regex(/^[0-9]{1,19}$/)
16
+ .optional(),
17
+ });
18
+ const PAGE = `select id, job, ticked_at from ticks
19
+ where ($1::bigint is null or id < $1::bigint) order by id desc limit $2`;
20
+ // Newest first; one row past the page says whether a next page exists, its cursor is the last id.
21
+ export const recentTicks = async (store, query) => {
22
+ const { rows: page } = await store.query(PAGE, [query.cursor ?? null, query.limit + 1]);
23
+ const rows = page.slice(0, query.limit);
24
+ const { rows: count } = await store.query('select count(*)::int as n from ticks');
25
+ const ticks = rows.map((row) => ({
26
+ id: String(row.id),
27
+ job: row.job,
28
+ tickedAt: new Date(row.ticked_at).toISOString(),
29
+ }));
30
+ const last = page.length > query.limit ? ticks.at(-1)?.id : undefined;
31
+ return { ticks, total: count[0]?.n ?? 0, nextCursor: last };
32
+ };
@@ -0,0 +1,2 @@
1
+ import { type McpContext } from '@agentage/extension';
2
+ export declare function create(ctx: McpContext): void;
@@ -0,0 +1,11 @@
1
+ import {} from '@agentage/extension';
2
+ import { z } from 'zod';
3
+ // The kit serves this tool as probe__echo on POST /mcp.
4
+ export function create(ctx) {
5
+ ctx.tool('echo', {
6
+ description: 'Echo a message back',
7
+ scope: 'read',
8
+ input: z.object({ msg: z.string().max(200) }),
9
+ output: z.object({ msg: z.string() }),
10
+ }, async ({ msg }) => ({ msg: `pong ${msg}` }));
11
+ }
@@ -0,0 +1,2 @@
1
+ import { type PagesContext, type PagesSite } from '@agentage/extension';
2
+ export declare const create: (ctx: PagesContext) => PagesSite;
@@ -0,0 +1,3 @@
1
+ import { versionPage } from '@agentage/extension';
2
+ // The kit serves this map; "/" names what runs: probe {version} · {commit}.
3
+ export const create = (ctx) => ({ '/': versionPage(ctx) });
@@ -0,0 +1,38 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="agentage-extension" content="probe" />
7
+ <meta name="agentage-version" content="0.4.0" />
8
+ <title>probe 0.4.0 widgets</title>
9
+ <style>
10
+ :root {
11
+ color-scheme: dark;
12
+ background: oklch(0.085 0.013 277);
13
+ color: oklch(0.97 0.003 277);
14
+ }
15
+ @media (prefers-color-scheme: light) {
16
+ :root {
17
+ color-scheme: light;
18
+ background: oklch(1 0 0);
19
+ color: oklch(0.18 0.032 277);
20
+ }
21
+ }
22
+ body {
23
+ margin: 0;
24
+ padding: 24px;
25
+ font-family: system-ui, sans-serif;
26
+ }
27
+ main {
28
+ display: grid;
29
+ gap: 16px;
30
+ max-width: 420px;
31
+ }
32
+ </style>
33
+ <script type="module" src="./harness.js"></script>
34
+ </head>
35
+ <body>
36
+ <main id="widgets" aria-label="probe widgets"></main>
37
+ </body>
38
+ </html>
@@ -0,0 +1 @@
1
+ var x=(e,t)=>Object.assign(new Error(t),{name:"HostError",code:e});function Ze(e,t){return typeof t=="bigint"?t.toString():t}var oe=class{constructor(t){this._getter=t,this._value=void 0}get value(){let t=this._getter;return t!==void 0&&(this._value=t(),this._getter=void 0),this._value}};function ie(e){return new oe(e)}function ke(e){return e==null}function se(e){let t=e.startsWith("^")?1:0,r=e.endsWith("$")?e.length-1:e.length;return e.slice(t,r)}function ce(e,t,r){Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0})}function Pe(e){let t=Object.getOwnPropertyDescriptor(e,"shape");return t?.get?t.get.raw:t?.value}var ue="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function U(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Ae(e){if(U(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!="function")return!0;let r=t.prototype;return!(U(r)===!1||Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)}function W(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(e,t,r){let n=new e._zod.constr(t??e._zod.def);return(!t||r?.parent)&&(n._zod.parent=e),n}function $(e){let t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Se(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout==="optional")}function P(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue!==!0)return!0;return!1}function Ee(e,t=0){if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(e.issues[r]?.continue===!1)return!0;return!1}function I(e,t){return t.map(r=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(e),r})}function N(e){return typeof e=="string"?e:e?.message}function ae(e){let t=[];for(let r of e??[]){let n=r._zod.def;if(!/_(length|size)$|_equals$/.test(n.check))break;let o=n.maximum??n.length??n.size;o>=0&&t.push([o,r])}return t}function X(e,t,r){var n;for(let o=t;o<e.length;o++)(n=e[o]).schema??(n.schema=r)}function A(e,t,r){var n;let o=e.inst?._zod?.traits;o?.has("$ZodType")&&(o.has("$ZodCheck")?(n=e).schema??(n.schema=e.inst):e.schema=e.inst);let i=e.schema!==e.inst?e.schema?._zod.def?.error:void 0,c=e.message?e.message:N(e.inst?._zod.def?.error?.(e))??N(i?.(e))??N(t?.error?.(e))??N(r.customError?.(e))??N(r.localeError?.(e))??"Invalid input",s={};for(let a of Object.keys(e))a==="inst"||a==="schema"||a==="continue"||a==="input"||a==="__proto__"||(s[a]=e[a]);return s.path??(s.path=[]),s.message=c,t?.reportInput&&(s.input=e.input),s}var Wt=/[\uD800-\uDBFF]/;function le(e){let t=e.length;if(!Wt.test(e))return t;let r=t;for(let n=0;n<t-1;n++)(e.charCodeAt(n)&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320&&(r--,n++);return r}function pe(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Ce(e,t){for(let r in t){let n=Object.getOwnPropertyDescriptor(t,r);n.get?Object.defineProperty(e,r,{...n,enumerable:!1}):Gt(e,r,n.value)}}function M(e,t,r,n=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:n,value:r}),r}function fe(e,t,r){return M(e,t,r,!1)}function Gt(e,t,r){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?r:M(this,t,r.bind(this))},set(n){M(this,t,n)}})}function Xt(e,t){let r=Object.getPrototypeOf(e);return t in r?void 0:r}var ne,C=!1,Ht={configurable:!0,get(){C=!0}};function Z(e,t,r){let n=Object.getPrototypeOf(e._zod);if(t in n&&ne!==e._zod){ne=void 0;return}ne=e._zod,Object.defineProperty(n,t,{configurable:!0,get(){Object.defineProperty(this,t,Ht);let o=C;C=!1;try{let i=r(this);return C?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:i}),C=C||o,i}catch(i){throw delete this[t],C=C||o,i}},set(o){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:o})}})}function Ie(e,t,r,n){let o=Xt(e,t);o&&Object.defineProperty(o,t,{configurable:!0,get(){let i={configurable:!0,writable:!0,enumerable:n,value:void 0};return Object.defineProperty(this,t,i),i.value=r(this),Object.defineProperty(this,t,i),i.value},set(i){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:n,value:i})}})}var Me;var de={value:void 0,enumerable:!1},Oe="captureStackTrace"in Error?Error:null;function Jt(e){let t=Oe;if(t){let r=t.stackTraceLimit;if(typeof r=="number"){try{t.stackTraceLimit=0}catch{return Oe=null,new e}try{return new e}finally{t.stackTraceLimit=r}}}return new e}function h(e,t,r,n){let o={};function i(p){this.def=p,this.constr=f,this.traits=new Set}i.prototype=o;let c=r,s=c&&new WeakSet;function a(p,m){if(p._zod){if(p._zod.traits.has(e))return}else{de.value=new i(m);try{Object.defineProperty(p,"_zod",de)}finally{de.value=void 0}}if(p._zod.traits.add(e),t(p,m),s){let g=Object.getPrototypeOf(p),y=p._zod.constr.prototype,k=g;for(;k&&k!==y;)k=Object.getPrototypeOf(k);let R=k??g;s.has(R)||(s.add(R),Ce(R,c))}let d=f.prototype;for(let g in d)Object.prototype.hasOwnProperty.call(d,g)&&(g in p||(p[g]=d[g].bind(p)))}let u=n?.Parent??Object;class l extends u{}Object.defineProperty(l,"name",{value:e});function f(p){let m=n?.Parent?Jt(l):this;a(m,p);let d=m._zod.deferred;if(d){for(let y of d)y();m._zod.deferred=void 0}let g=globalThis.__zod_globalConfig?.postProcessor;return g&&g(m),m}return Object.defineProperty(f,"init",{value:a}),Object.defineProperty(f,Symbol.hasInstance,{value:p=>n?.Parent&&p instanceof n.Parent?!0:p?._zod?.traits?.has(e)}),Object.defineProperty(f,"name",{value:e}),f}var S=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}};(Me=globalThis).__zod_globalConfig??(Me.__zod_globalConfig={});var j=globalThis.__zod_globalConfig;function E(e){return e&&Object.assign(j,e),j}function qt(){let e=this._zod;return e.message??(e.message=JSON.stringify(e.def,Ze,2)),e.message}function Yt(e){this._zod.message=e}var Qt={get:qt,set:Yt,enumerable:!0,configurable:!0},he={value:void 0,enumerable:!1},Te=new WeakSet([Object.prototype,Error.prototype]),Re=(e,t)=>{e.name="$ZodError",he.value=t,Object.defineProperty(e,"issues",he),he.value=void 0,Object.defineProperty(e,"message",Qt);let r=Object.getPrototypeOf(e);Te.has(r)||(Te.add(r),Object.defineProperty(r,"toString",{configurable:!0,enumerable:!1,get(){let n=()=>this.message;return Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0}),n},set(n){Object.defineProperty(this,"toString",{value:n,configurable:!0,writable:!0})}}))},nn=h("$ZodError",Re),F=h("$ZodError",Re,void 0,{Parent:Error});var tr=e=>{let t=(r,n,o,i)=>{let c=o?{...o,async:!1}:{async:!1},s=r._zod.run({value:n,issues:[]},c);if(s instanceof Promise)throw new S;if(s.issues.length){let a=new(i?.Err??e)(s.issues.map(u=>A(u,c,E())));throw ue(a,i?.callee??t),a}return s.value};return t},ge=tr(F),rr=e=>{let t=async(r,n,o,i)=>{let c=o?{...o,async:!0}:{async:!0},s=r._zod.run({value:n,issues:[]},c);if(s instanceof Promise&&(s=await s),s.issues.length){let a=new(i?.Err??e)(s.issues.map(u=>A(u,c,E())));throw ue(a,i?.callee??t),a}return s.value};return t},_e=rr(F),nr=e=>(t,r,n)=>{let o=n?{...n,async:!1}:{async:!1},i=t._zod.run({value:r,issues:[]},o);if(i instanceof Promise)throw new S;return i.issues.length?je(e,i.issues,o):{success:!0,data:i.value}},xe=nr(F);function je(e,t,r){let n;return{success:!1,get error(){return n||(n=new e(t.map(o=>A(o,r,E()))),t=void 0,r=void 0),n},set error(o){n=o,t=void 0,r=void 0}}}var or=e=>async(t,r,n)=>{let o=n?{...n,async:!0}:{async:!0},i=t._zod.run({value:r,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?je(e,i.issues,o):{success:!0,data:i.value}},$e=or(F);var Le=/^[\s\S]{0,}$/;var ze=/^-?\d+(?:\.\d+)?$/,De=/^(?:true|false)$/i,Ne=/^null$/i;var B=h("$ZodCheck",(e,t)=>{var r;e._zod??(e._zod={}),e._zod.def=t,(r=e._zod).onattach??(r.onattach=[])});var Fe=e=>{let t=e.value;return!ke(t)&&t.length!==void 0};var Be=h("$ZodCheckMaxLength",(e,t)=>{var r;B.init(e,t),(r=e._zod.def).when??(r.when=Fe),e._zod.check=n=>{let o=n.value,i=o.length;if((typeof o=="string"&&i>t.maximum?le(o):i)<=t.maximum)return;let s=pe(o);n.issues.push({origin:s,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Ke=h("$ZodCheckMinLength",(e,t)=>{var r;B.init(e,t),(r=e._zod.def).when??(r.when=Fe),e._zod.check=n=>{let o=n.value,i=o.length;if((typeof o=="string"&&i>=t.minimum&&i<t.minimum*2?le(o):i)>=t.minimum)return;let s=pe(o);n.issues.push({origin:s,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}});var ir=h("$ZodCheckStringFormat",(e,t)=>{var r,n;B.init(e,t),t.pattern?(r=e._zod).check??(r.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(n=e._zod).check??(n.check=()=>{})}),Ve=h("$ZodCheckRegex",(e,t)=>{ir.init(e,t),e._zod.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}});var We={major:4,minor:6,patch:7};var v=h("$ZodType",(e,t)=>{var r;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=We;let n=e._zod.def.checks,o=e._zod.traits.has("$ZodCheck")?[e,...n??[]]:n?.length?[...n]:[];for(let i of o)for(let c of i._zod.onattach)c(e);if(o.length===0)(r=e._zod).deferred??(r.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let i=(s,a,u)=>{if(s.memo)return s;let l=P(s),f;for(let p of a){if(p._zod.def.when){if(Ee(s)||!p._zod.def.when(s))continue}else if(l)continue;let m=s.issues.length,d=p._zod.check(s);if(d instanceof Promise&&u?.async===!1)throw new S;if(f||d instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await d,s.issues.length!==m&&(X(s.issues,m,e),l||(l=P(s,m)))});else{if(s.issues.length===m)continue;X(s.issues,m,e),l||(l=P(s,m))}}return f?f.then(()=>s):s},c=(s,a,u)=>{if(P(s))return s.aborted=!0,s;let l=i(a,o,u);if(l instanceof Promise){if(u.async===!1)throw new S;return l.then(f=>e._zod.parse(f,u))}return e._zod.parse(l,u)};e._zod.run=(s,a)=>{if(a.skipChecks)return e._zod.parse(s,a);if(a.direction==="backward"){let l=e._zod.parse({value:s.value,issues:[]},{...a,skipChecks:!0});return l instanceof Promise?l.then(f=>c(f,s,a)):c(l,s,a)}let u=e._zod.parse(s,a);if(u instanceof Promise){if(a.async===!1)throw new S;return u.then(l=>i(l,o,a))}return i(u,o,a)}}},{get"~standard"(){return fe(this,"~standard",ar(this))},set"~standard"(e){M(this,"~standard",e)}}),Je=(e,t)=>e.issues.length?{issues:e.issues.map(r=>A(r,t,E()))}:{value:e.value};async function ur(e,t){let r={async:!0};return Je(await e._zod.run({value:t,issues:[]},r),r)}function ar(e){return{validate:t=>{let r={async:!1};try{let n=e._zod.run({value:t,issues:[]},r);if(!(n instanceof Promise))return Je(n,r)}catch{}return ur(e,t)},vendor:"zod",version:1}}var qe=h("$ZodString",(e,t)=>{v.init(e,t),e._zod.pattern=t.pattern??Le,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}});var Ye=h("$ZodNumber",(e,t)=>{v.init(e,t),e._zod.pattern=ze,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=Number(r.value)}catch{}let o=r.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return r;let i=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:String(o):void 0;return r.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...i?{received:i}:{}}),r}});var Qe=h("$ZodBoolean",(e,t)=>{v.init(e,t),e._zod.pattern=De,e._zod.parse=(r,n)=>{if(t.coerce)try{r.value=!!r.value}catch{}let o=r.value;return typeof o=="boolean"||r.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),r}});var et=h("$ZodNull",(e,t)=>{v.init(e,t),e._zod.pattern=Ne,e._zod.values=new Set([null]),e._zod.parse=(r,n)=>{let o=r.value;return o===null||r.issues.push({expected:"null",code:"invalid_type",input:o,inst:e}),r}});var tt=h("$ZodUnknown",(e,t)=>{v.init(e,t),e._zod.parse=r=>r});function lr(e,t){let r=ae(e._zod.def.checks);if(!r.length)return;let n=Math.min(...r.map(i=>i[0])),o=e._zod.parse;e._zod.parse=(i,c)=>{let s=t(i.value);if(s>n&&!c?.skipChecks&&c?.direction!=="backward"){for(let[a,u]of ae(e._zod.def.checks))if(s>a&&u._zod.def.when(i)){let l=i.issues.length;return u._zod.check(i),i.issues[l].continue=!1,X(i.issues,l,e),i}}return o(i,c)}}var pr=e=>Array.isArray(e)?e.length:-1;function Ge(e,t,r){e.issues.length&&t.issues.push(...I(r,e.issues)),t.value[r]=e.value}var rt=h("$ZodArray",(e,t)=>{v.init(e,t);let r=j.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=r?r.alloc(e,n,Array(i.length),o):Array(i.length);let c=[],s=o?.abortEarly;for(let a=0;a<i.length;a++){let u=i[a],l=t.element._zod.run({value:u,issues:[]},o);if(l instanceof Promise)c.push(l.then(f=>Ge(f,n,a)));else if(Ge(l,n,a),s&&l.issues.length!==0&&P(l))break}return c.length?Promise.all(c).then(()=>n):n},lr(e,pr)});function H(e,t,r,n,o,i){let c=r in n,s=i==="optional";if(!(!c&&s&&o==="optional")){if(e.issues.length){if(o!==void 0&&s&&!c)return;t.issues.push(...I(r,e.issues))}if(!c&&o===void 0){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[r]});return}e.value===void 0?(c||o==="defaulted"&&!s)&&(t.value[r]=void 0):t.value[r]=e.value}}var fr=[];function dr(e){let t=Object.keys(e.shape),r=Object.getOwnPropertySymbols(e.shape),n=r.length?r:fr,o=n.length?[...t,...n]:t;for(let c of o)if(!e.shape?.[c]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${String(c)}": expected a Zod schema`);let i=Se(e.shape);return{...e,allKeys:o,symbolKeys:n,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(i)}}function mr(e,t,r,n,o,i,c){let s=[],a=o.keySet,u=o.catchall._zod,l=u.def.type,f=u.optin,p=u.optout,m=0;for(let d in t){if(c&&r.issues.length!==m){if(P(r,m))break;m=r.issues.length}if(a.has(d))continue;if(d==="__proto__"){l==="never"&&s.push(d);continue}if(l==="never"){s.push(d);continue}let g=u.run({value:t[d],issues:[]},n);g instanceof Promise?e.push(g.then(y=>H(y,r,d,t,f,p))):H(g,r,d,t,f,p)}return s.length&&r.issues.push({code:"unrecognized_keys",keys:s,input:t,inst:i,continue:!0}),e.length?Promise.all(e).then(()=>r):r}var nt=h("$ZodObject",(e,t)=>{v.init(e,t);let r=Object.getOwnPropertyDescriptor(t,"shape"),n=r?.get?r.get.raw:t.shape??{};if(n){let u=()=>{let l={...n};return Object.defineProperty(t,"shape",{value:l}),u.raw=l,l};u.raw=n,Object.defineProperty(t,"shape",{get:u})}let o=ie(()=>dr(t));Z(e,"propValues",u=>{let l=u.def.shape,f={};for(let p in l){let m=l[p]._zod;if(m.values){Object.prototype.hasOwnProperty.call(f,p)||ce(f,p,new Set);for(let d of m.values)f[p].add(d);m.optin!==void 0&&f[p].add(void 0)}}return f});let i=U,c=t.catchall,s,a=j.memoizer;a?.attach(e),e._zod.parse=(u,l)=>{s??(s=o.value);let f=u.value;if(!i(f))return u.issues.push({expected:"object",code:"invalid_type",input:f,inst:e}),u;u.value=a?a.alloc(e,u,{},l):{};let p=[],m=s.shape,d=l?.abortEarly,g=u.issues.length;for(let y of s.allKeys){if(d&&u.issues.length!==g){if(P(u,g))break;g=u.issues.length}if(y==="__proto__")continue;let k=m[y],R=k._zod.optin,ye=k._zod.optout,re=k._zod.run({value:f[y],issues:[]},l);re instanceof Promise?p.push(re.then(Vt=>H(Vt,u,y,f,R,ye))):H(re,u,y,f,R,ye)}return c?mr(p,f,u,l,o.value,e,d===!0):p.length?Promise.all(p).then(()=>u):u}});function Xe(e,t,r,n){for(let i of e)if(i.issues.length===0)return t.value=i.value,t;let o=e.filter(i=>!P(i));return o.length===1?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:r,errors:e.map(i=>i.issues.map(c=>A(c,n,E())))}),t)}var ve=h("$ZodUnion",(e,t)=>{v.init(e,t),Z(e,"optin",n=>n.def.options.some(o=>o._zod.optin==="defaulted")?"defaulted":n.def.options.some(o=>o._zod.optin!==void 0)?"optional":void 0),Z(e,"optout",n=>n.def.options.some(o=>o._zod.optout==="optional")?"optional":void 0),Z(e,"values",n=>{if(n.def.options.every(o=>o._zod.values))return new Set(n.def.options.flatMap(o=>Array.from(o._zod.values)))}),Z(e,"pattern",n=>{if(n.def.options.every(o=>o._zod.pattern)){let o=n.def.options.map(i=>i._zod.pattern);return new RegExp(`^(${o.map(i=>se(i.source)).join("|")})$`)}});let r=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(n,o)=>{if(r)return r(n,o);let i=!1,c=[];for(let s of t.options){let a=s._zod.run({value:n.value,issues:[]},o);if(a instanceof Promise)c.push(a),i=!0;else{if(a.issues.length===0)return a;c.push(a)}}return i?Promise.all(c).then(s=>Xe(s,n,e,o)):Xe(c,n,e,o)}});function hr(e){let t=new Map;for(let r of e.options){let n=r._zod.propValues?.[e.discriminator];if(!n||n.size===0)throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(r)}"`);for(let o of n)if(t.has(o)){if(o!==void 0)throw new Error(`Duplicate discriminator value "${String(o)}"`);t.set(o,null)}else t.set(o,r)}return t}var ot=h("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,ve.init(e,t);let r=e._zod.parse;Z(e,"propValues",o=>{let i={},c=0;for(let s of o.def.options){let a=s._zod.propValues;if(!a||Object.keys(a).length===0)throw new Error(`Invalid discriminated union option at index "${o.def.options.indexOf(s)}"`);a[o.def.discriminator]?.has(void 0)&&c++;for(let[u,l]of Object.entries(a)){Object.prototype.hasOwnProperty.call(i,u)||ce(i,u,new Set);for(let f of l)i[u].add(f)}}return!o.def.unionFallback&&c>1&&i[o.def.discriminator]?.delete(void 0),i}),t.options.forEach((o,i)=>{let c=Pe(o._zod.def);if(c&&!Object.prototype.hasOwnProperty.call(c,t.discriminator))throw new Error(`Invalid discriminated union option at index "${i}"`)});let n=ie(()=>hr(t));e._zod.parse=(o,i)=>{let c=o.value;if(!U(c))return o.issues.push({code:"invalid_type",expected:"object",input:c,inst:e}),o;let s=c?.[t.discriminator],a=n.value.get(s);return a&&(s!==void 0||i.direction!=="backward")?a._zod.run(o,i):t.unionFallback||i.direction==="backward"?r(o,i):(o.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,options:Array.from(n.value.keys()).filter(u=>n.value.get(u)!==null),input:c,path:[t.discriminator],inst:e}),o)}});var it=h("$ZodRecord",(e,t)=>{v.init(e,t);let r=j.memoizer;r?.attach(e),e._zod.parse=(n,o)=>{let i=n.value;if(!Ae(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;let c=[],s=t.keyType._zod.values;if(s&&!t.partial){n.value=r?r.alloc(e,n,{},o):{};let a=new Set;for(let l of s)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){if(a.add(typeof l=="number"?l.toString():l),l==="__proto__")continue;let f=t.keyType._zod.run({value:l,issues:[]},o);if(f instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(f.issues.length){n.issues.push({code:"invalid_key",origin:"record",issues:f.issues.map(d=>A(d,o,E())),input:l,path:[l],inst:e});continue}let p=f.value;if(p==="__proto__")continue;let m=t.valueType._zod.run({value:i[l],issues:[]},o);m instanceof Promise?c.push(m.then(d=>{d.issues.length&&n.issues.push(...I(l,d.issues)),n.value[p]=d.value})):(m.issues.length&&n.issues.push(...I(l,m.issues)),n.value[p]=m.value)}let u;for(let l in i)if(!a.has(l))if(t.mode==="loose"){if(l==="__proto__")continue;n.value[l]=i[l]}else u=u??[],u.push(l);u&&u.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:u,continue:!0})}else{n.value=r?r.alloc(e,n,{},o):{};let a;for(let u of Reflect.ownKeys(i)){if(u==="__proto__"||!Object.prototype.propertyIsEnumerable.call(i,u))continue;let l=t.keyType._zod.run({value:u,issues:[]},o);if(l instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof u=="string"&&ze.test(u)&&l.issues.length){let d=t.keyType._zod.run({value:Number(u),issues:[]},o);if(d instanceof Promise)throw new Error("Async schemas not supported in object keys currently");d.issues.length===0&&(l=d)}if(l.issues.length){t.mode==="loose"?n.value[u]=i[u]:s?(a=a??[],a.push(u)):n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map(d=>A(d,o,E())),input:u,path:[u],inst:e});continue}let p=l.value;if(p==="__proto__")continue;let m=t.valueType._zod.run({value:i[u],issues:[]},o);m instanceof Promise?c.push(m.then(d=>{d.issues.length&&n.issues.push(...I(u,d.issues)),n.value[p]=d.value})):(m.issues.length&&n.issues.push(...I(u,m.issues)),n.value[p]=m.value)}a&&a.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:a,continue:!0})}return c.length?Promise.all(c).then(()=>n):n}});var st=h("$ZodLiteral",(e,t)=>{v.init(e,t);let r=new Set(t.values);e._zod.values=r,Z(e,"pattern",n=>{let o=n.def.values;return new RegExp(o.length?`^(${o.map(i=>typeof i=="string"?W(i):i?W(i.toString()):String(i)).join("|")})$`:"^[^\\s\\S]$")}),e._zod.parse=(n,o)=>{let i=n.value;return r.has(i)||n.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),n}});function He(e,t){return e.value=t.issues.length?void 0:t.value,e}var ct=h("$ZodOptional",(e,t)=>{v.init(e,t),Z(e,"optin",r=>r.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),e._zod.optout="optional",Z(e,"values",r=>{let n=r.def.innerType._zod.values;return n?new Set([...n,void 0]):void 0}),Z(e,"pattern",r=>{let n=r.def.innerType._zod.pattern;return n?new RegExp(`^(${se(n.source)})?$`):void 0}),e._zod.parse=(r,n)=>{if(r.value===void 0){if(t.innerType._zod.optin!=="defaulted")return r;let o=t.innerType._zod.run({value:r.value,issues:[]},n);return o instanceof Promise?o.then(i=>He(r,i)):He(r,o)}return t.innerType._zod.run(r,n)}});function ut(e){return e.checks&&(e.checks=[...e.checks]),e}function at(e,t){return new e(ut({type:"string",...$(t)}))}function lt(e,t){return new e(ut({type:"number",checks:[],...$(t)}))}function pt(e,t){return new e({type:"boolean",...$(t)})}function ft(e,t){return new e({type:"null",...$(t)})}function dt(e){return new e({type:"unknown"})}function T(e,t){return new Be({check:"max_length",...$(t),maximum:e})}function L(e,t){return new Ke({check:"min_length",...$(t),minimum:e})}function D(e,t){return new Ve({check:"string_format",format:"regex",...$(t),pattern:e})}var b=h("ZodMiniType",(e,t)=>{if(!e._zod)throw new Error("Uninitialized schema in ZodMiniType.");v.init(e,t),e.def=t,e.type=t.type},{get with(){return this.check},set with(e){M(this,"with",e)},parse(e,t){return ge(this,e,t,{callee:this.parse})},parseAsync(e,t){return _e(this,e,t,{callee:this.parseAsync})},safeParse(e,t){return xe(this,e,t)},safeParseAsync(e,t){return $e(this,e,t)},check(...e){let t=this.def;return this.clone({...t,checks:[...t.checks??[],...e.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]},{parent:!0})},clone(e,t){return G(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},apply(e,...t){return t.length===0?e(this):e(this,...t)}}),xr=h("ZodMiniString",(e,t)=>{qe.init(e,t),b.init(e,t)});function _(e){return at(xr,e)}var $r=h("ZodMiniNumber",(e,t)=>{Ye.init(e,t),b.init(e,t)});function be(e){return lt($r,e)}var zr=h("ZodMiniBoolean",(e,t)=>{Qe.init(e,t),b.init(e,t)});function ht(e){return pt(zr,e)}var vr=h("ZodMiniNull",(e,t)=>{et.init(e,t),b.init(e,t)});function gt(e){return ft(vr,e)}var br=h("ZodMiniUnknown",(e,t)=>{tt.init(e,t),b.init(e,t)});function K(){return dt(br)}var wr=h("ZodMiniArray",(e,t)=>{rt.init(e,t),b.init(e,t)});function J(e,t){return new wr({type:"array",element:e,...$(t)})}var yr=h("ZodMiniObject",(e,t)=>{nt.init(e,t),b.init(e,t),Ie(e,"shape",r=>r._zod.def.shape,!1)});function z(e,t){let r={type:"object",shape:e??{},...$(t)};return new yr(r)}var Zr=h("ZodMiniUnion",(e,t)=>{ve.init(e,t),b.init(e,t)});function _t(e,t){return new Zr({type:"union",options:e,...$(t)})}var kr=h("ZodMiniDiscriminatedUnion",(e,t)=>{ot.init(e,t),b.init(e,t)});function xt(e,t,r){return new kr({type:"union",options:t,discriminator:e,...$(r)})}var mt=h("ZodMiniRecord",(e,t)=>{it.init(e,t),b.init(e,t)});function $t(e,t,r){return!t||!t._zod?new mt({type:"record",keyType:_(),valueType:e,...$(t)}):new mt({type:"record",keyType:e,valueType:t,...$(r)})}var Pr=h("ZodMiniLiteral",(e,t)=>{st.init(e,t),b.init(e,t)});function V(e,t){return new Pr({type:"literal",values:Array.isArray(e)?e:[e],...$(t)})}var Ar=h("ZodMiniOptional",(e,t)=>{ct.init(e,t),b.init(e,t)});function w(e){return new Ar({type:"optional",innerType:e})}var zt=z({code:_(),message:_()}),we=z({jsonrpc:w(V("2.0")),id:w(_t([_(),be(),gt()])),result:w(K()),error:w(z({code:be(),message:_()}))}),vt=z({content:w(J(K())),structuredContent:w($t(_(),K())),isError:w(ht())}),bt=z({error:zt}),wt=z({type:V("text"),text:_()}),Y=xt("success",[z({success:V(!0),data:w(K())}),z({success:V(!1),error:zt})]);var yt=3e4,Q=(e={},t=yt)=>{let r=AbortSignal.timeout(t);return{...e,signal:e.signal?AbortSignal.any([e.signal,r]):r}},ee=e=>t=>{throw t?.name!=="TimeoutError"?t:x("TIMEOUT",`${e} did not answer in ${yt/1e3} s`)};var Cr=(e,t)=>{let r=new Headers(e?.headers);return r.has("Accept")||r.set("Accept","application/json"),t&&r.set("Authorization",`Bearer ${t}`),{...e,headers:r}},Ir=async e=>{try{return await e.json()}catch{return}},Zt=async(e,t,r,n)=>{if(!r.startsWith("/"))throw x("BAD_PATH",`api path must start with /: ${r}`);let{res:o,body:i}=await e(`/api/v1${r}`,Q(Cr(n,await t()))).then(async s=>({res:s,body:await Ir(s)})).catch(ee(`/api/v1${r}`)),c=Y.safeParse(i);if(!c.success)throw x(`HTTP_${o.status}`,`api answered ${o.status}`);if(!c.data.success)throw x(c.data.error.code,c.data.error.message);return c.data.data};var kt=()=>globalThis.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark";var Mr=e=>(e.headers.get("content-type")??"").includes("text/event-stream"),Pt=e=>{try{return JSON.parse(e)}catch{return}},Or=(e,t)=>{let r=e.split(/\r?\n/).filter(n=>n.startsWith("data:")).map(n=>Pt(n.slice(5).trim())).map(n=>we.safeParse(n)).flatMap(n=>n.success?[n.data]:[]);return r.find(n=>n.id===t)??r.at(-1)},Tr=(e,t)=>{let r=Y.safeParse(e);return r.success&&!r.data.success?x(r.data.error.code,r.data.error.message):x(`HTTP_${t}`,`MCP answered ${t} without a JSON-RPC message`)},At=async(e,t)=>{let r=await e.text(),n=Mr(e)?Or(r,t):Pt(r),o=we.safeParse(n);if(o.success&&(o.data.result!==void 0||o.data.error))return o.data;throw Tr(n,e.status)};var St="2026-07-28",Rr=(e,t)=>{let r=new Headers({"Content-Type":"application/json",Accept:"application/json, text/event-stream","MCP-Protocol-Version":St,"Mcp-Method":"tools/call","Mcp-Name":e});return t&&r.set("Authorization",`Bearer ${t}`),r},jr=(e,t,r,n)=>({jsonrpc:"2.0",id:e,method:"tools/call",params:{name:t,arguments:r,_meta:{"io.modelcontextprotocol/protocolVersion":St,"io.modelcontextprotocol/clientInfo":n.clientInfo,"io.modelcontextprotocol/clientCapabilities":{}}}}),Lr=e=>e.content?.map(t=>wt.safeParse(t)).find(t=>t.success)?.data?.text,Dr=e=>{let t=bt.safeParse(e.structuredContent);return t.success?x(t.data.error.code,t.data.error.message):x("TOOL_ERROR",Lr(e)??"the tool reported an error")},Et=async(e,t,r)=>{let n=e.nextId(),o=Rr(t,await e.token()),i=JSON.stringify(jr(n,t,r,e)),c=await e.fetch("/mcp",Q({method:"POST",headers:o,body:i})).then(a=>At(a,n)).catch(ee(t));if(c.error)throw x(String(c.error.code),c.error.message);let s=vt.safeParse(c.result);if(!s.success)throw x("BAD_RESULT","the tool answered an invalid result");if(s.data.isError)throw Dr(s.data);return s.data.structuredContent??{}};var Ct="0.1.1";var Nr=e=>x("FOREIGN_TOOL",`a ${e} widget calls only ${e}__ tools`),Ur=()=>Promise.resolve(void 0),Fr=(e,t)=>({extension:e,version:t,path:globalThis.location?.pathname??"/",theme:kt()}),It=e=>{let t=e.fetch??((c,s)=>fetch(c,s)),r=e.token??Ur,n=0,o={name:e.clientName??"agentage-widget",version:Ct},i={fetch:t,token:r,clientInfo:o,nextId:()=>++n};return{tool:(c,s={})=>c.startsWith(`${e.id}__`)?Et(i,c,s):Promise.reject(Nr(e.id)),api:(c,s)=>Zt(t,r,c,s),context:Fr(e.id,e.version)}};var Mt=/^[a-z][a-z0-9-]*$/,te=_().check(T(32),D(Mt,"a widget name is lowercase kebab-case")),Ot=_().check(T(32),D(Mt,"an extension id is lowercase kebab-case"));var Br=z({widget:w(te),token:w(_().check(L(1),T(4096)))}),Kr=z({id:Ot,version:_().check(L(1),T(64))}),Tt=(e,t)=>e.querySelector(`meta[name="${t}"]`)?.content,Rt=(e,t)=>e.get(t)??void 0,jt=(e,t)=>{let r=Kr.parse({id:Tt(e,"agentage-extension"),version:Tt(e,"agentage-version")}),n=new URLSearchParams(t),o=Br.parse({widget:Rt(n,"widget"),token:Rt(n,"token")});return{...r,...o}};var Vr=J(z({name:te,element:_().check(D(/^[a-z][a-z0-9]*(-[a-z0-9-]+)+$/)),module:_()})),Lt=async(e,t)=>{let r=await e(t);if(!r.ok)throw new Error(`widgets.json answered ${r.status}`);return Vr.parse(await r.json())},Dt=(e,t)=>{if(!t)return e;let r=e.filter(n=>n.name===t);if(r.length===0)throw new Error(`no widget named ${t}`);return r},Nt=(e,t)=>t.map(r=>e.appendChild(e.ownerDocument.createElement(r.element))),Ut=(e,t)=>{let r=e.ownerDocument.createElement("p");r.setAttribute("role","alert"),r.textContent=t,e.append(r)};var Wr="http://localhost:4281/token",Gr=new Set(["localhost","127.0.0.1"]),Xr=z({token:_().check(L(1))}),Hr=5e3,Jr=async e=>{let t=await e.fetch(Wr,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({scope:`${e.id}:read`}),signal:AbortSignal.timeout(Hr)});if(!t.ok)throw new Error(`dev issuer answered ${t.status}`);let r=Xr.safeParse(await t.json());if(!r.success)throw new Error("dev issuer answered without a token");return r.data.token},Ft=async e=>{if(e.token)return e.token;if(Gr.has(e.hostname))try{return await Jr(e)}catch(t){e.warn(`agentage harness: no dev token (${t.message}), calling anonymously`);return}};var Bt=(e,t)=>fetch(e,t),qr=()=>{let e=new URL(location.href);e.searchParams.has("token")&&(e.searchParams.delete("token"),history.replaceState(null,"",e))},Yr=async e=>{let t=jt(document,location.search);qr();let r=s=>console.warn(s),n={id:t.id,hostname:location.hostname,fetch:Bt,warn:r},o=Ft({...n,token:t.token}),i={id:t.id,version:t.version,clientName:"agentage-harness"};globalThis.__agentageHost=()=>It({...i,token:()=>o}),await import(new URL(`./${t.id}.js`,document.baseURI).href);let c=await Lt(Bt,new URL("./widgets.json",document.baseURI).href);Nt(e,Dt(c,t.widget))},Kt=document.getElementById("widgets")??document.body;Yr(Kt).catch(e=>Ut(Kt,`harness: ${e.message}`));