taximeter 0.2.0 → 0.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Taximeter
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Print a one-time stderr notice when the first encrypted CONNECT tunnel arrives, while preserving per-tunnel diagnostics and forwarding behavior. Add a manual Base Sepolia x402 verification workflow and document measured storage-reduction options.
8
+
9
+ ## 0.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Announce legacy ledger migration and save a standalone, WAL-aware schema-1 backup before upgrading. Abort the upgrade if the backup fails, retain completed backups for rollback, and document recovery using a separate database path. Extend the reproducible ledger benchmark to cover larger histories and task/agent partition counts.
14
+
3
15
  ## 0.2.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -12,12 +12,16 @@ from source with the quickstart below. Requires Node 20 or newer.
12
12
 
13
13
  ## A 20-second demo
14
14
 
15
- ![Taximeter allows 20 payments and blocks payment 21](docs/demo.gif)
15
+ ![Taximeter meters a real testnet payment and blocks the next payment](docs/demo.gif)
16
16
 
17
- This local recording shows 20 payments passing and payment 21 being blocked at
18
- an exact total of 140 atomic units. It uses synthetic x402 envelopes and never
19
- moves money. [Record the demo](https://github.com/Ding808/taximeter/blob/main/docs/RECORDING.md)
20
- with the simulation in the source checkout.
17
+ This recording sends **0.001 test USDC on Base Sepolia** through the actual CLI
18
+ proxy, verifies its canonical receipt and balance changes, then blocks the next
19
+ signed request at an exact budget of 1000 atomic units.
20
+ [View the transaction](https://sepolia.basescan.org/tx/0x10dc76728133356363ad1dd8d694a5e1eee2086fc3325ca572d3d035e7062c58)
21
+ or [reproduce the recording](https://github.com/Ding808/taximeter/blob/main/docs/RECORDING.md).
22
+ The official client signs and the facilitator settles; Taximeter observes and
23
+ gates. This proves one testnet flow with a local HTTP seller, not mainnet or
24
+ payment visibility inside HTTPS CONNECT.
21
25
 
22
26
  ## Why
23
27
 
@@ -51,7 +55,7 @@ Open a terminal in this source checkout, with Node 20+ and npm installed.
51
55
  You should now see:
52
56
 
53
57
  ```text
54
- Taximeter 0.2.0
58
+ Taximeter 0.2.2
55
59
  Proxy: http://127.0.0.1:8402
56
60
  Dashboard: http://127.0.0.1:8403
57
61
  Point an HTTP-proxy-aware agent at http://127.0.0.1:8402.
@@ -70,7 +74,7 @@ Choose the connection mode your agent supports:
70
74
  | HTTP forward proxy | Configure the client's HTTP proxy as `http://127.0.0.1:8402`. `HTTP_PROXY` works only in clients that honor it. | Plain HTTP payment requests and replies. |
71
75
  | Explicit upstream | Start with `--upstream` set to the real HTTP(S) API origin, then use the local proxy URL as the agent's API base URL. | HTTP or HTTPS upstream payments, without intercepting TLS. |
72
76
  | SDK | Put `withMeter(fetch, options)` **inside** the payment wrapper. See [SDK examples](docs/SDK.md). | Requests made through the supplied transport. |
73
- | HTTPS CONNECT | A proxy-aware HTTPS client may open a tunnel. | Encrypted bytes pass through, with an unmetered diagnostic. Payment headers are invisible. |
77
+ | HTTPS CONNECT | A proxy-aware HTTPS client may open a tunnel. | Encrypted bytes pass through. The first tunnel prints a stderr notice; every tunnel records an unmetered diagnostic. Payment headers are invisible. |
74
78
 
75
79
  In upstream mode, `/data` replaces any path prefix in the configured upstream URL.
76
80
  Use the API origin as the upstream and keep its path in the request. Native fetch
@@ -141,9 +145,20 @@ as text to prevent a spreadsheet application from rounding them.
141
145
  ## Configuration
142
146
 
143
147
  When upgrading from 0.1.x, upgrade all writers together. Opening an existing
144
- ledger builds the new budget index once and upgrades its schema; the source log
145
- is preserved. Older 0.1.x clients cannot reopen that migrated database. Parsed
146
- unknown assets now require an explicit opt-in as described below.
148
+ ledger prints `Migrating ledger…`, saves a standalone schema-1 backup beside it
149
+ at `<database>.backup-v1-<unique suffix>/ledger.db`, and prints the backup path
150
+ before building the budget index. The backup includes committed WAL records;
151
+ if it cannot be completed, the upgrade stops. Large ledgers take longer on this
152
+ first open. Fresh databases and already-upgraded ledgers do not create backups.
153
+
154
+ The source log is preserved, but older 0.1.x clients cannot reopen the upgraded
155
+ database. To roll back, stop all CLI and SDK writers, copy the saved `ledger.db`
156
+ to a **new database path**, and start 0.1.x with `--db` pointing there. Keep the
157
+ upgraded database: the backup does not contain payments made after migration.
158
+ Backups are retained until you remove them; a `ledger.partial.db` file means the
159
+ backup did not finish and must not be used for rollback. Progress goes to stderr,
160
+ so JSON report/export output stays machine-readable. Parsed unknown assets now
161
+ require an explicit opt-in as described below.
147
162
 
148
163
  No file is required. Start from [the example](taximeter.config.example.json) when
149
164
  needed. Precedence, highest first: flags, environment, explicit `--config` file,
@@ -217,6 +232,12 @@ Raw payment authorizations stay in the local audit ledger and JSON export. Treat
217
232
  them as sensitive. [Security guidance](SECURITY.md) describes the boundary and how
218
233
  to report a problem.
219
234
 
235
+ Storage grows with payment, retry, and diagnostic history. There is currently no
236
+ retention, prune, or compact command; `reset` archives the old database and does
237
+ not reclaim its disk space. Large-ledger users should monitor available space.
238
+ The [storage measurements and follow-up plan](https://github.com/Ding808/taximeter/blob/main/docs/STORAGE.md)
239
+ describe the measured costs and migration constraints.
240
+
220
241
  ## Contributing / license
221
242
 
222
243
  See the [contribution guide](https://github.com/Ding808/taximeter/blob/main/CONTRIBUTING.md)
@@ -812,7 +812,7 @@ body{font:14px Arial,Helvetica,sans-serif;color:#182b27;background:#fff;margin:4
812
812
  // src/ledger/store.ts
813
813
  import { mkdirSync } from "fs";
814
814
  import { dirname as dirname2 } from "path";
815
- import Database from "better-sqlite3";
815
+ import Database2 from "better-sqlite3";
816
816
  import { v7 as v73 } from "uuid";
817
817
  import { z as z8 } from "zod";
818
818
 
@@ -822,6 +822,26 @@ var __default = "CREATE TABLE schema_version (version INTEGER PRIMARY KEY);\nINS
822
822
  // migrations/002.sql
823
823
  var __default2 = "CREATE TABLE cache_cursors (\n id INTEGER PRIMARY KEY CHECK (id = 1),\n eventRowid INTEGER NOT NULL CHECK (eventRowid >= 0),\n outcomeRowid INTEGER NOT NULL CHECK (outcomeRowid >= 0)\n);\nINSERT INTO cache_cursors VALUES (1, 0, 0);\n\nCREATE TABLE cache_payments (\n paymentId TEXT PRIMARY KEY REFERENCES events(id),\n paymentKey TEXT NOT NULL UNIQUE,\n payload TEXT NOT NULL CHECK (json_valid(payload)),\n maxAttemptedAt TEXT\n);\n\nCREATE TABLE cache_attempts (\n paymentId TEXT NOT NULL REFERENCES cache_payments(paymentId),\n attemptId TEXT NOT NULL,\n firstTs TEXT NOT NULL,\n firstId TEXT NOT NULL,\n winnerTs TEXT NOT NULL,\n winnerId TEXT NOT NULL,\n status TEXT NOT NULL CHECK (status IN ('unknown', 'confirmed', 'failed')),\n payload TEXT NOT NULL CHECK (json_valid(payload)),\n PRIMARY KEY (paymentId, attemptId)\n);\nCREATE INDEX cache_attempt_selection ON cache_attempts (\n paymentId, status, firstTs, firstId COLLATE NOCASE, firstId DESC\n);\n\nCREATE TABLE cache_prefix (\n partitionKey TEXT NOT NULL,\n prefix TEXT NOT NULL,\n amount TEXT NOT NULL CHECK (amount <> '' AND amount NOT GLOB '*[^0-9]*'),\n PRIMARY KEY (partitionKey, prefix)\n) WITHOUT ROWID;\n\nINSERT INTO schema_version VALUES (2);\n";
824
824
 
825
+ // src/ledger/backup.ts
826
+ import { mkdtempSync, renameSync, writeFileSync } from "fs";
827
+ import { join as join2, resolve as resolve2 } from "path";
828
+ import Database from "better-sqlite3";
829
+ function backupLedger(path) {
830
+ const directory = mkdtempSync(`${resolve2(path)}.backup-v1-`);
831
+ const partial = join2(directory, "ledger.partial.db");
832
+ const destination = join2(directory, "ledger.db");
833
+ writeFileSync(partial, "", { flag: "wx", mode: 384 });
834
+ const reader = new Database(path, { readonly: true, fileMustExist: true });
835
+ try {
836
+ reader.pragma("synchronous = FULL");
837
+ reader.prepare("VACUUM INTO ?").run(partial);
838
+ } finally {
839
+ reader.close();
840
+ }
841
+ renameSync(partial, destination);
842
+ return destination;
843
+ }
844
+
825
845
  // src/ledger/cache.ts
826
846
  import { z as z7 } from "zod";
827
847
  var cursorSchema = z7.object({
@@ -1115,7 +1135,7 @@ var Ledger = class {
1115
1135
  constructor(input) {
1116
1136
  const path = z8.string().min(1).parse(input);
1117
1137
  if (path !== ":memory:") mkdirSync(dirname2(path), { recursive: true, mode: 448 });
1118
- this.database = new Database(path);
1138
+ this.database = new Database2(path);
1119
1139
  try {
1120
1140
  this.database.pragma("journal_mode = WAL");
1121
1141
  this.database.pragma("foreign_keys = ON");
@@ -1128,7 +1148,15 @@ var Ledger = class {
1128
1148
  const version3 = z8.object({ version: z8.union([z8.literal(1), z8.literal(2)]) }).parse(
1129
1149
  this.database.prepare("SELECT MAX(version) AS version FROM schema_version").get()
1130
1150
  );
1131
- if (version3.version === 1) this.database.exec(__default2);
1151
+ if (version3.version === 1) {
1152
+ if (table && path !== ":memory:") {
1153
+ process.stderr.write("Migrating ledger\u2026\n");
1154
+ const backup = backupLedger(path);
1155
+ process.stderr.write(`Ledger backup saved: ${backup}
1156
+ `);
1157
+ }
1158
+ this.database.exec(__default2);
1159
+ }
1132
1160
  const cache = new LedgerCache(this.database);
1133
1161
  cache.synchronize();
1134
1162
  return cache;
@@ -1215,6 +1243,7 @@ var Ledger = class {
1215
1243
  };
1216
1244
 
1217
1245
  // src/proxy/index.ts
1246
+ import { Console } from "console";
1218
1247
  import {
1219
1248
  createServer,
1220
1249
  request as httpRequest,
@@ -1228,6 +1257,9 @@ var incomingHeadersSchema = z9.record(
1228
1257
  z9.union([z9.string(), z9.array(z9.string()), z9.undefined()])
1229
1258
  );
1230
1259
  var sockets = /* @__PURE__ */ new WeakMap();
1260
+ var tlsUnmeteredMessage = "Encrypted CONNECT tunnel forwarded without payment visibility. Use the SDK or explicit upstream mode to meter HTTPS.";
1261
+ var notices = new Console({ stdout: process.stdout, stderr: process.stderr, ignoreErrors: true });
1262
+ var tlsNoticeShown = false;
1231
1263
  function normalizedHeaders(input) {
1232
1264
  const result = {};
1233
1265
  for (const [name, value] of Object.entries(incomingHeadersSchema.parse(input))) {
@@ -1368,11 +1400,14 @@ function createProxy(options) {
1368
1400
  const target = new URL(`http://${address}`);
1369
1401
  const port = z9.coerce.number().int().min(1).max(65535).parse(target.port || "80");
1370
1402
  const host = target.hostname.replace(/^\[|\]$/g, "");
1371
- meter.diagnose(
1372
- "tls_unmetered",
1373
- address,
1374
- "Encrypted CONNECT tunnel forwarded without payment visibility. Use the SDK or explicit upstream mode to meter HTTPS."
1375
- );
1403
+ meter.diagnose("tls_unmetered", address, tlsUnmeteredMessage);
1404
+ if (!tlsNoticeShown) {
1405
+ tlsNoticeShown = true;
1406
+ try {
1407
+ notices.error(tlsUnmeteredMessage);
1408
+ } catch {
1409
+ }
1410
+ }
1376
1411
  const upstream = connect(port, host, () => {
1377
1412
  client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
1378
1413
  upstream.write(head);
@@ -1469,7 +1504,7 @@ ${JSON.stringify(intake.body)}`
1469
1504
  async function closeProxy(server) {
1470
1505
  for (const socket of sockets.get(server) ?? []) socket.destroy();
1471
1506
  await new Promise(
1472
- (resolve2, reject) => server.close((error) => error ? reject(error) : resolve2())
1507
+ (resolve3, reject) => server.close((error) => error ? reject(error) : resolve3())
1473
1508
  );
1474
1509
  }
1475
1510
 
@@ -1477,7 +1512,7 @@ async function closeProxy(server) {
1477
1512
  import { z as z10 } from "zod";
1478
1513
 
1479
1514
  // package.json
1480
- var version = "0.2.0";
1515
+ var version = "0.2.2";
1481
1516
 
1482
1517
  // src/version.ts
1483
1518
  var version2 = z10.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/).parse(version);
package/dist/cli/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  totalSchema,
23
23
  totals,
24
24
  version
25
- } from "../chunk-NXK2MCRO.js";
25
+ } from "../chunk-DJPLFDD7.js";
26
26
 
27
27
  // src/cli/index.ts
28
28
  import { CommanderError } from "commander";
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  toJson,
19
19
  totals,
20
20
  version
21
- } from "./chunk-NXK2MCRO.js";
21
+ } from "./chunk-DJPLFDD7.js";
22
22
 
23
23
  // src/sdk/index.ts
24
24
  import { z } from "zod";
@@ -97,5 +97,5 @@ ${s.join(`
97
97
 
98
98
  `)}return J.write("payload.value = newResult;"),J.write("return payload;"),J.compile()};let h;const y=Bi,g=!Xt.jitless,z=g&&Ev.value,N=u.catchall;let w;l._zod.parse=(C,B)=>{w??(w=r.value);const X=C.value;return y(X)?g&&z&&B?.async===!1&&B.jitless!==!0?(h||(h=d(u.shape)),C=h(C,B),N?dp([],X,C,B,w,l):C):s(C,B):(C.issues.push({expected:"object",code:"invalid_type",input:X,inst:l}),C)}});function _m(l,u,s,r){for(const d of l)if(d.issues.length===0)return u.value=d.value,u;const o=l.filter(d=>!ua(d));return o.length===1?(u.value=o[0].value,o[0]):(u.issues.push({code:"invalid_union",input:u.value,inst:s,errors:l.map(d=>d.issues.map(h=>Kn(h,r,Ft())))}),u)}const Zb=M("$ZodUnion",(l,u)=>{Ne.init(l,u),ve(l,"optin",r=>r.def.options.some(o=>o._zod.optin==="defaulted")?"defaulted":r.def.options.some(o=>o._zod.optin!==void 0)?"optional":void 0),ve(l,"optout",r=>r.def.options.some(o=>o._zod.optout==="optional")?"optional":void 0),ve(l,"values",r=>{if(r.def.options.every(o=>o._zod.values))return new Set(r.def.options.flatMap(o=>Array.from(o._zod.values)))}),ve(l,"pattern",r=>{if(r.def.options.every(o=>o._zod.pattern)){const o=r.def.options.map(d=>d._zod.pattern);return new RegExp(`^(${o.map(d=>Ys(d.source)).join("|")})$`)}});const s=u.options.length===1?u.options[0]._zod.run:null;l._zod.parse=(r,o)=>{if(s)return s(r,o);let d=!1;const h=[];for(const y of u.options){const g=y._zod.run({value:r.value,issues:[]},o);if(g instanceof Promise)h.push(g),d=!0;else{if(g.issues.length===0)return g;h.push(g)}}return d?Promise.all(h).then(y=>_m(y,r,l,o)):_m(h,r,l,o)}}),wb=M("$ZodIntersection",(l,u)=>{Ne.init(l,u),l._zod.parse=(s,r)=>{const o=s.value,d=u.left._zod.run({value:o,issues:[]},r),h=u.right._zod.run({value:o,issues:[]},r);return d instanceof Promise||h instanceof Promise?Promise.all([d,h]).then(([g,p])=>Sm(s,g,p)):Sm(s,d,h)}});function Ds(l,u){if(l===u)return{valid:!0,data:l};if(l instanceof Date&&u instanceof Date&&+l==+u)return{valid:!0,data:l};if(ra(l)&&ra(u)){const s=Object.keys(u),r=Object.keys(l).filter(d=>s.indexOf(d)!==-1),o={...l,...u};Object.prototype.hasOwnProperty.call(o,"__proto__")&&delete o.__proto__;for(const d of r){if(d==="__proto__")continue;const h=Ds(l[d],u[d]);if(!h.valid)return{valid:!1,mergeErrorPath:[d,...h.mergeErrorPath]};o[d]=h.data}return{valid:!0,data:o}}if(Array.isArray(l)&&Array.isArray(u)){if(l.length!==u.length)return{valid:!1,mergeErrorPath:[]};const s=[];for(let r=0;r<l.length;r++){const o=l[r],d=u[r],h=Ds(o,d);if(!h.valid)return{valid:!1,mergeErrorPath:[r,...h.mergeErrorPath]};s.push(h.data)}return{valid:!0,data:s}}return{valid:!1,mergeErrorPath:[]}}function Sm(l,u,s){const r=new Map;let o;const d=new Map,h=(p,z)=>{let N;if(p.code==="unrecognized_keys"&&!p.path?.length)o??(o=p),N=p.keys;else if(p.code==="invalid_key"&&p.origin==="record"&&p.path?.length===1){const w=String(p.path[0]);d.has(w)||d.set(w,p),N=[w]}else return!1;for(const w of N)r.has(w)||r.set(w,{}),r.get(w)[z]=!0;return!0};for(const p of u.issues)h(p,"l")||l.issues.push(p);for(const p of s.issues)h(p,"r")||l.issues.push(p);const y=[...r].filter(([,p])=>p.l&&p.r).map(([p])=>p);if(y.length){const p=o?y.filter(z=>o.keys.includes(z)):[];p.length&&l.issues.push({...o,keys:p});for(const z of y)!p.includes(z)&&d.has(z)&&l.issues.push(d.get(z))}const g=Ds(u.value,s.value);if(!g.valid){if(ua(l))return l;throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(g.mergeErrorPath)}`)}return l.value=g.data,l}const Rb=M("$ZodRecord",(l,u)=>{Ne.init(l,u);const s=Xt.memoizer;s?.attach(l),l._zod.parse=(r,o)=>{const d=r.value;if(!ra(d))return r.issues.push({expected:"record",code:"invalid_type",input:d,inst:l}),r;const h=[],y=u.keyType._zod.values;if(y&&!u.partial){r.value=s?s.alloc(l,r,{},o):{};const g=new Set;for(const z of y)if(typeof z=="string"||typeof z=="number"||typeof z=="symbol"){if(g.add(typeof z=="number"?z.toString():z),z==="__proto__")continue;const N=u.keyType._zod.run({value:z,issues:[]},o);if(N instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(N.issues.length){r.issues.push({code:"invalid_key",origin:"record",issues:N.issues.map(B=>Kn(B,o,Ft())),input:z,path:[z],inst:l});continue}const w=N.value;if(w==="__proto__")continue;const C=u.valueType._zod.run({value:d[z],issues:[]},o);C instanceof Promise?h.push(C.then(B=>{B.issues.length&&r.issues.push(...ia(z,B.issues)),r.value[w]=B.value})):(C.issues.length&&r.issues.push(...ia(z,C.issues)),r.value[w]=C.value)}let p;for(const z in d)if(!g.has(z))if(u.mode==="loose"){if(z==="__proto__")continue;r.value[z]=d[z]}else p=p??[],p.push(z);p&&p.length>0&&r.issues.push({code:"unrecognized_keys",input:d,inst:l,keys:p,continue:!0})}else{r.value=s?s.alloc(l,r,{},o):{};let g;for(const p of Reflect.ownKeys(d)){if(p==="__proto__"||!Object.prototype.propertyIsEnumerable.call(d,p))continue;let z=u.keyType._zod.run({value:p,issues:[]},o);if(z instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof p=="string"&&Xs.test(p)&&z.issues.length){const B=u.keyType._zod.run({value:Number(p),issues:[]},o);if(B instanceof Promise)throw new Error("Async schemas not supported in object keys currently");B.issues.length===0&&(z=B)}if(z.issues.length){u.mode==="loose"?r.value[p]=d[p]:y?(g=g??[],g.push(p)):r.issues.push({code:"invalid_key",origin:"record",issues:z.issues.map(B=>Kn(B,o,Ft())),input:p,path:[p],inst:l});continue}const w=z.value;if(w==="__proto__")continue;const C=u.valueType._zod.run({value:d[p],issues:[]},o);C instanceof Promise?h.push(C.then(B=>{B.issues.length&&r.issues.push(...ia(p,B.issues)),r.value[w]=B.value})):(C.issues.length&&r.issues.push(...ia(p,C.issues)),r.value[w]=C.value)}g&&g.length>0&&r.issues.push({code:"unrecognized_keys",input:d,inst:l,keys:g,continue:!0})}return h.length?Promise.all(h).then(()=>r):r}}),Cb=M("$ZodEnum",(l,u)=>{Ne.init(l,u);const s=Xm(u.entries),r=new Set(s);l._zod.values=r;const o=s.filter(d=>Tv.has(typeof d));l._zod.pattern=new RegExp(o.length?`^(${o.map(d=>sa(d.toString())).join("|")})$`:"^[^\\s\\S]$"),l._zod.parse=(d,h)=>{const y=d.value;return r.has(y)||d.issues.push({code:"invalid_value",values:s,input:y,inst:l}),d}}),Bb=M("$ZodLiteral",(l,u)=>{Ne.init(l,u);const s=new Set(u.values);l._zod.values=s,l._zod.pattern=new RegExp(u.values.length?`^(${u.values.map(r=>typeof r=="string"?sa(r):r?sa(r.toString()):String(r)).join("|")})$`:"^[^\\s\\S]$"),l._zod.parse=(r,o)=>{const d=r.value;return s.has(d)||r.issues.push({code:"invalid_value",values:u.values,input:d,inst:l}),r}}),Hb=M("$ZodTransform",(l,u)=>{Ne.init(l,u),l._zod.optin="optional",Xt.memoizer?.guard(l),l._zod.parse=(s,r)=>{if(r.direction==="backward")throw new Fm(l.constructor.name);const o=u.transform(s.value,s);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(h=>(s.value=h,s));if(o instanceof Promise)throw new ca;return s.value=o,s}});function zm(l,u){return l.value=u.issues.length?void 0:u.value,l}const hp=M("$ZodOptional",(l,u)=>{Ne.init(l,u),ve(l,"optin",s=>s.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),l._zod.optout="optional",ve(l,"values",s=>{const r=s.def.innerType._zod.values;return r?new Set([...r,void 0]):void 0}),ve(l,"pattern",s=>{const r=s.def.innerType._zod.pattern;return r?new RegExp(`^(${Ys(r.source)})?$`):void 0}),l._zod.parse=(s,r)=>{if(s.value===void 0){if(u.innerType._zod.optin!=="defaulted")return s;const o=u.innerType._zod.run({value:s.value,issues:[]},r);return o instanceof Promise?o.then(d=>zm(s,d)):zm(s,o)}return u.innerType._zod.run(s,r)}}),qb=M("$ZodExactOptional",(l,u)=>{hp.init(l,u),ve(l,"values",s=>s.def.innerType._zod.values),ve(l,"pattern",s=>s.def.innerType._zod.pattern),l._zod.parse=(s,r)=>u.innerType._zod.run(s,r)}),Yb=M("$ZodNullable",(l,u)=>{Ne.init(l,u),ve(l,"optin",s=>s.def.innerType._zod.optin),ve(l,"optout",s=>s.def.innerType._zod.optout),ve(l,"pattern",s=>{const r=s.def.innerType._zod.pattern;return r?new RegExp(`^(${Ys(r.source)}|null)$`):void 0}),ve(l,"values",s=>s.def.innerType._zod.values?new Set([...s.def.innerType._zod.values,null]):void 0),l._zod.parse=(s,r)=>s.value===null?s:u.innerType._zod.run(s,r)}),$b=M("$ZodDefault",(l,u)=>{Ne.init(l,u),l._zod.optin="defaulted",ve(l,"values",s=>s.def.innerType._zod.values),l._zod.parse=(s,r)=>{if(r.direction==="backward")return u.innerType._zod.run(s,r);if(s.value===void 0)return s.value=u.defaultValue,s;const o=u.innerType._zod.run(s,r);return o instanceof Promise?o.then(d=>Em(d,u)):Em(o,u)}});function Em(l,u){return l.value===void 0&&(l.value=u.defaultValue),l}const kb=M("$ZodPrefault",(l,u)=>{Ne.init(l,u),l._zod.optin="defaulted",ve(l,"values",s=>s.def.innerType._zod.values),l._zod.parse=(s,r)=>(r.direction==="backward"||s.value===void 0&&(s.value=u.defaultValue),u.innerType._zod.run(s,r))}),Gb=M("$ZodNonOptional",(l,u)=>{Ne.init(l,u),ve(l,"values",s=>{const r=s.def.innerType._zod.values;return r?new Set([...r].filter(o=>o!==void 0)):void 0}),l._zod.parse=(s,r)=>{const o=u.innerType._zod.run(s,r);return o instanceof Promise?o.then(d=>Tm(d,l)):Tm(o,l)}});function Tm(l,u){return!l.issues.length&&l.value===void 0&&l.issues.push({code:"invalid_type",expected:"nonoptional",input:l.value,inst:u}),l}function Om(l,u,s,r){return u.issues.length?(l.value=s.catchValue({...u,value:l.value,error:{issues:u.issues.map(o=>Kn(o,r,Ft()))},input:l.value}),l):(l.value=u.value,u.memo&&(l.memo=!0),l)}const Lb=M("$ZodCatch",(l,u)=>{Ne.init(l,u),ve(l,"optin",s=>s.def.innerType._zod.optin==="defaulted"?"defaulted":"optional"),ve(l,"optout",s=>s.def.innerType._zod.optout),ve(l,"values",s=>s.def.innerType._zod.values),l._zod.parse=(s,r)=>{if(r.direction==="backward")return u.innerType._zod.run(s,r);const o=u.innerType._zod.run({value:s.value,issues:[]},r);return o instanceof Promise?o.then(d=>Om(s,d,u,r)):Om(s,o,u,r)}}),Xb=M("$ZodPipe",(l,u)=>{Ne.init(l,u),ve(l,"values",s=>s.def.in._zod.values),ve(l,"optin",s=>s.def.in._zod.optin),ve(l,"optout",s=>s.def.out._zod.optout),ve(l,"propValues",s=>s.def.in._zod.propValues),l._zod.parse=(s,r)=>{if(r.direction==="backward"){const d=u.out._zod.run(s,r);return d instanceof Promise?d.then(h=>Zi(h,u.in,r)):Zi(d,u.in,r)}const o=u.in._zod.run(s,r);return o instanceof Promise?o.then(d=>Zi(d,u.out,r)):Zi(o,u.out,r)}});function Zi(l,u,s){return l.issues.some(r=>r.code!=="unrecognized_keys")?(l.aborted=!0,l):u._zod.run({value:l.value,issues:l.issues},s)}const Qb=M("$ZodReadonly",(l,u)=>{Ne.init(l,u),ve(l,"propValues",s=>s.def.innerType._zod.propValues),ve(l,"values",s=>s.def.innerType._zod.values),ve(l,"optin",s=>s.def.innerType?._zod?.optin),ve(l,"optout",s=>s.def.innerType?._zod?.optout),l._zod.parse=(s,r)=>{if(r.direction==="backward")return u.innerType._zod.run(s,r);const o=u.innerType._zod.run(s,r);return o instanceof Promise?o.then(Am):Am(o)}});function Am(l){return l.memo||(l.value=Object.freeze(l.value)),l}const Vb=M("$ZodCustom",(l,u)=>{ht.init(l,u),Ne.init(l,u),l._zod.parse=(s,r)=>s,l._zod.check=s=>{const r=s.value,o=u.fn(r);if(o instanceof Promise)return o.then(d=>Nm(d,s,r,l));Nm(o,s,r,l)}});function Nm(l,u,s,r){if(!l){const o={code:"custom",input:s,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),u.issues.push(hu(o))}}class Kb extends Error{constructor(){super("Cannot parse a reference cycle that closes through a transform"),this.name="ZodCyclicError"}}const Us="~memo",jm=[];function Ts(l){return l.map(u=>u.path?{...u,path:u.path.slice()}:{...u})}const xm=new WeakMap;function mp(l,u){const s=xm.get(l);if(s!==void 0)return s;if(u.has(l))return!0;u.add(l);let r=!1;const o=y=>{!r&&y?._zod&&mp(y,u)&&(r=!0)},d=l._zod.def;switch(d.type){case"object":{for(const y of Reflect.ownKeys(d.shape))o(d.shape[y]);o(d.catchall);break}case"array":o(d.element);break;case"tuple":for(const y of d.items)o(y);o(d.rest);break;case"record":case"map":o(d.keyType),o(d.valueType);break;case"set":o(d.valueType);break;case"union":for(const y of d.options)o(y);break;case"intersection":o(d.left),o(d.right);break;case"optional":case"nullable":case"default":case"prefault":case"catch":case"readonly":case"nonoptional":case"promise":case"success":o(d.innerType);break;case"pipe":o(d.in),o(d.out);break;case"function":o(d.input),o(d.output);break;case"lazy":o(l._zod.innerType);break;case"template_literal":case"string":case"number":case"int":case"boolean":case"bigint":case"symbol":case"undefined":case"null":case"void":case"never":case"any":case"unknown":case"date":case"nan":case"enum":case"literal":case"file":case"transform":case"custom":break;default:for(const y in d){const g=Object.getOwnPropertyDescriptor(d,y);if(!g||g.get)continue;const p=g.value;if(!(!p||typeof p!="object")){if(p._zod)o(p);else if(Array.isArray(p))for(const z of p)o(z)}}}return u.delete(l),xm.set(l,r),r}function Jb(l,u){let s=l.buckets.get(u);return s||(s=new Map,l.buckets.set(u,s)),s}let wi;const Ri=[],Fb={alloc(l,u,s){const r=wi;if(!r)return s;wi=void 0;const o={value:s,issues:null};return r.set(u.value,o),Ri.push(o),s},guard(l){var u;(u=l._zod).deferred??(u.deferred=[]),l._zod.deferred.push(()=>{const s=l._zod.parse,r=(o,d)=>{if(d.direction!=="backward"&&Ib(d,o.value))throw new Kb;return s(o,d)};l._zod.parse=r,l._zod.run===s&&(l._zod.run=r)})},attach(l){var u;let s,r,o;(u=l._zod).deferred??(u.deferred=[]),l._zod.deferred.push(()=>{const d=l._zod.parse,h=(y,g)=>{if(s===void 0&&(s=mp(l,new Set),!s))return l._zod.parse=d,l._zod.run===h&&(l._zod.run=d),d(y,g);const p=y.value;if(p===null||typeof p!="object")return d(y,g);let z=g[Us];z||(z={buckets:new Map,backEdges:void 0},g[Us]=z);let N;r===g?N=o:(N=Jb(z,l),r=g,o=N);const w=N.get(p);if(w)return y.value=w.value,w.issues?w.issues.length&&y.issues.push(...Ts(w.issues)):(y.memo=!0,z.backEdges??(z.backEdges=new Set),z.backEdges.add(w.value)),y;wi=N;const C=Ri.length,B=d(y,g);wi=void 0;const X=Ri.length>C?Ri.pop():void 0;return B instanceof Promise?B.then(J=>(X&&(X.issues=J.issues.length?Ts(J.issues):jm),J)):(X&&(X.issues=B.issues.length?Ts(B.issues):jm),B)};l._zod.parse=h,l._zod.run===d&&(l._zod.run=h)})}};function Wb(){return Fb}function Ib(l,u){const s=l[Us]?.backEdges;return s!==void 0&&u!==null&&typeof u=="object"&&s.has(u)}const Pb=()=>{const l={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function u(d){return l[d]??null}const s={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",credit_card:"credit card number",jwt:"JWT",template_literal:"input"},r={nan:"NaN"};function o(d,h){return d==="number"&&typeof h=="number"&&!Number.isFinite(h)?String(h):r[d]??d}return d=>{switch(d.code){case"invalid_type":{const h=o(d.expected),y=Rv(d.input),g=o(y,d.input);return`Invalid input: expected ${h}, received ${g}`}case"invalid_value":return d.values.length===1?`Invalid input: expected ${Km(d.values[0])}`:`Invalid option: expected one of ${om(d.values,"|")}`;case"too_big":{const h=d.exact?"exactly ":d.inclusive?"<=":"<",y=u(d.origin);return y?`Too big: expected ${d.origin??"value"} to have ${h}${d.maximum.toString()} ${y.unit??"elements"}`:`Too big: expected ${d.origin??"value"} to be ${h}${d.maximum.toString()}`}case"too_small":{const h=d.exact?"exactly ":d.inclusive?">=":">",y=u(d.origin);return y?`Too small: expected ${d.origin} to have ${h}${d.minimum.toString()} ${y.unit}`:`Too small: expected ${d.origin} to be ${h}${d.minimum.toString()}`}case"invalid_format":{const h=d;return h.format==="starts_with"?`Invalid string: must start with "${h.prefix}"`:h.format==="ends_with"?`Invalid string: must end with "${h.suffix}"`:h.format==="includes"?`Invalid string: must include "${h.includes}"`:h.format==="regex"?`Invalid string: must match pattern ${h.pattern}`:`Invalid ${s[h.format]??d.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${d.divisor}`;case"unrecognized_keys":return`Unrecognized key${d.keys.length>1?"s":""}: ${om(d.keys,", ")}`;case"invalid_key":return`Invalid key in ${d.origin}`;case"invalid_union":return d.options&&Array.isArray(d.options)&&d.options.length>0?`Invalid discriminator value. Expected ${d.options.map(y=>`'${y}'`).join(" | ")}`:d.inclusive===!1?"Invalid input: more than one option matched":"Invalid input";case"invalid_element":return`Invalid value in ${d.origin}`;default:return"Invalid input"}}};function e_(){return{localeError:Pb()}}var Dm;class t_{constructor(){this._map=new WeakMap,this._idmap=new Map}add(u,...s){const r=s[0];return this._map.set(u,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,u),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(u){const s=this._map.get(u);return s&&typeof s=="object"&&"id"in s&&this._idmap.delete(s.id),this._map.delete(u),this}get(u){const s=u._zod.parent;if(s){const r={...this.get(s)??{}};delete r.id;const o={...r,...this._map.get(u)};return Object.keys(o).length?o:void 0}return this._map.get(u)}has(u){return this._map.has(u)}}function n_(){return new t_}(Dm=globalThis).__zod_globalRegistry??(Dm.__zod_globalRegistry=n_());const su=globalThis.__zod_globalRegistry;function l_(l,u){return new l({type:"string",...G(u)})}function a_(l,u){return new l({type:"string",format:"email",check:"string_format",abort:!1,...G(u)})}function u_(l,u){return new l({type:"string",format:"guid",check:"string_format",abort:!1,...G(u)})}function i_(l,u){return new l({type:"string",format:"uuid",check:"string_format",abort:!1,...G(u)})}function c_(l,u){return new l({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...G(u)})}function r_(l,u){return new l({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...G(u)})}function pp(l,u){return new l({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...G(u)})}function yp(l,u){return new l({type:"string",format:"url",check:"string_format",abort:!1,...G(u)})}function s_(l,u){return new l({type:"string",format:"emoji",check:"string_format",abort:!1,...G(u)})}function o_(l,u){return new l({type:"string",format:"nanoid",check:"string_format",abort:!1,...G(u)})}function f_(l,u){return new l({type:"string",format:"cuid",check:"string_format",abort:!1,...G(u)})}function d_(l,u){return new l({type:"string",format:"cuid2",check:"string_format",abort:!1,...G(u)})}function h_(l,u){return new l({type:"string",format:"ulid",check:"string_format",abort:!1,...G(u)})}function m_(l,u){return new l({type:"string",format:"xid",check:"string_format",abort:!1,...G(u)})}function p_(l,u){return new l({type:"string",format:"ksuid",check:"string_format",abort:!1,...G(u)})}function y_(l,u){return new l({type:"string",format:"ipv4",check:"string_format",abort:!1,...G(u)})}function g_(l,u){return new l({type:"string",format:"ipv6",check:"string_format",abort:!1,...G(u)})}function v_(l,u){return new l({type:"string",format:"cidrv4",check:"string_format",abort:!1,...G(u)})}function b_(l,u){return new l({type:"string",format:"cidrv6",check:"string_format",abort:!1,...G(u)})}function __(l,u){return new l({type:"string",format:"base64",check:"string_format",abort:!1,...G(u)})}function S_(l,u){return new l({type:"string",format:"base64url",check:"string_format",abort:!1,...G(u)})}function z_(l,u){return new l({type:"string",format:"e164",check:"string_format",abort:!1,...G(u)})}function E_(l,u){return new l({type:"string",format:"jwt",check:"string_format",abort:!1,...G(u)})}function gp(l,u){return new l({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...G(u)})}function T_(l,u){return new l({type:"string",format:"date",check:"string_format",...G(u)})}function O_(l,u){return new l({type:"string",format:"time",check:"string_format",precision:null,...G(u)})}function A_(l,u){return new l({type:"string",format:"duration",check:"string_format",...G(u)})}function N_(l,u){return new l({type:"number",checks:[],...G(u)})}function j_(l,u){return new l({type:"number",check:"number_format",abort:!1,format:"safeint",...G(u)})}function x_(l,u){return new l({type:"boolean",...G(u)})}function D_(l){return new l({type:"unknown"})}function U_(l,u){return new l({type:"never",...G(u)})}function Um(l,u){return new lp({check:"less_than",...G(u),value:l,inclusive:!1})}function Os(l,u){return new lp({check:"less_than",...G(u),value:l,inclusive:!0})}function Mm(l,u){return new ap({check:"greater_than",...G(u),value:l,inclusive:!1})}function As(l,u){return new ap({check:"greater_than",...G(u),value:l,inclusive:!0})}function Zm(l,u){return new Z0({check:"multiple_of",...G(u),value:l})}function vp(l,u){return new R0({check:"max_length",...G(u),maximum:l})}function Yi(l,u){return new C0({check:"min_length",...G(u),minimum:l})}function bp(l,u){return new B0({check:"length_equals",...G(u),length:l})}function M_(l,u){return new H0({check:"string_format",format:"regex",...G(u),pattern:l})}function Z_(l){return new q0({check:"string_format",format:"lowercase",...G(l)})}function w_(l){return new Y0({check:"string_format",format:"uppercase",...G(l)})}function R_(l,u){return new $0({check:"string_format",format:"includes",...G(u),includes:l})}function C_(l,u){return new k0({check:"string_format",format:"starts_with",...G(u),prefix:l})}function B_(l,u){return new G0({check:"string_format",format:"ends_with",...G(u),suffix:l})}function da(l){return new L0({check:"overwrite",tx:l})}function H_(l){return da(u=>u.normalize(l))}function q_(){return da(l=>l.trim())}function Y_(){return da(l=>l.toLowerCase())}function $_(){return da(l=>l.toUpperCase())}function k_(){return da(l=>zv(l))}function G_(l,u,s){return new l({type:"array",element:u,...G(s)})}function L_(l,u,s){return new l({type:"custom",check:"custom",fn:u,...G(s)})}function X_(l,u){const s=Q_(r=>(r.addIssue=o=>{if(typeof o=="string")r.issues.push(hu(o,r.value,s._zod.def));else{const d=o;d.fatal&&(d.continue=!1),d.code??(d.code="custom"),"input"in d||(d.input=r.value),d.inst??(d.inst=s),d.continue??(d.continue=!s._zod.def.abort),r.issues.push(hu(d))}},l(r.value,r)),u);return s}function Q_(l,u){const s=new ht({check:"custom",...G(u)});return s._zod.check=l,s}function fu(l,...u){for(const s of u)for(const r of Reflect.ownKeys(s))Object.prototype.propertyIsEnumerable.call(s,r)&&dt(l,r,s[r]);return l}function _p(l){let u=l?.target??"draft-2020-12";return u==="draft-4"&&(u="draft-04"),u==="draft-7"&&(u="draft-07"),{processors:l.processors??{},metadataRegistry:l?.metadata??su,target:u,unrepresentable:l?.unrepresentable??"throw",override:l?.override??(()=>{}),io:l?.io??"output",counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:l?.cycles??"ref",reused:l?.reused??"inline",intersections:[],deferred:[],external:l?.external??void 0}}function Jn(l,u,s,r,o){const d=typeof u.unrepresentable=="function"?u.unrepresentable({zodSchema:l,path:r.path,message:o}):u.unrepresentable;if(d==="any")return!1;if(d===void 0||d==="throw")throw new Error(o);return Object.assign(s,d),!0}function Ye(l,u,s={path:[],schemaPath:[]}){var r;const o=l._zod.def,d=u.seen.get(l);if(d)return d.count++,s.schemaPath.includes(l)&&(d.cycle=s.path),d.schema;const h={schema:{},count:1,cycle:void 0,path:s.path};u.seen.set(l,h),u.sharedDefsExtractedFor=void 0,u.sharedEmitDoneFor=void 0;const y=l._zod.toJSONSchema?.();if(y)h.schema=y;else{const z={...s,schemaPath:[...s.schemaPath,l],path:s.path};if(l._zod.processJSONSchema)l._zod.processJSONSchema(u,h.schema,z);else{const w=h.schema,C=u.processors[o.type];if(!C)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);C(l,u,w,z)}const N=l._zod.parent;N&&(h.ref||(h.ref=N),Ye(N,u,z),u.seen.get(N).isParent=!0)}const g=u.metadataRegistry.get(l);return g&&fu(h.schema,g),u.io==="input"&&lt(l)&&(delete h.schema.examples,delete h.schema.default),u.io==="input"&&"_prefault"in h.schema&&((r=h.schema).default??(r.default=h.schema._prefault)),delete h.schema._prefault,u.seen.get(l).schema}function wm(l){return l.replace(/~/g,"~0").replace(/\//g,"~1")}function Sp(l,u){const s=l.seen.get(u);if(!s)throw new Error("Unprocessed schema. This is a bug in Zod.");if(l.external&&l.sharedDefsExtractedFor===l.external)return;const r=new Map;for(const h of l.seen.entries()){const y=l.metadataRegistry.get(h[0])?.id;if(y){const g=r.get(y);if(g&&g!==h[0])throw new Error(`Duplicate schema id "${y}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(y,h[0])}}const o=h=>{const y=l.target==="draft-2020-12"?"$defs":"definitions";if(l.external){const N=l.external.registry.get(h[0])?.id,w=l.external.uri??(B=>B);if(N)return{ref:w(N)};const C=h[1].defId??h[1].schema.id??`schema${l.counter++}`;return h[1].defId=C,{defId:C,ref:`${w("__shared")}#/${y}/${wm(C)}`}}const g="#",p=`${g}/${y}/`;if(h[1]===s&&!h[1].schema.id)return{ref:g};const z=h[1].schema.id??`__schema${l.counter++}`;return{defId:z,ref:p+wm(z)}},d=h=>{if(h[1].schema.$ref)return;const y=h[1],{ref:g,defId:p}=o(h);y.def={...y.schema},p&&(y.defId=p);const z=y.schema;for(const N in z)delete z[N];z.$ref=g};if(l.cycles==="throw")for(const h of l.seen.entries()){const y=h[1];if(y.cycle)throw new Error(`Cycle detected: #/${y.cycle?.join("/")}/<root>
99
99
 
100
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const h of l.seen.entries()){const y=h[1];if(u===h[0]){d(h);continue}if(l.external){const p=l.external.registry.get(h[0])?.id;if(u!==h[0]&&p){d(h);continue}}if(l.metadataRegistry.get(h[0])?.id){d(h);continue}if(y.cycle){d(h);continue}if(y.count>1&&l.reused==="ref"){d(h);continue}}l.external&&(l.sharedDefsExtractedFor=l.external)}function zp(l){const u=l.anyOf;if(!Array.isArray(u)||u.length===0||l.type!==void 0)return;const s=[];for(const r of u){if(!r||typeof r!="object")return;zp(r);const o=Object.keys(r);if(o.length!==1||o[0]!=="type")return;const d=r.type;for(const h of Array.isArray(d)?d:[d]){if(typeof h!="string")return;s.includes(h)||s.push(h)}}delete l.anyOf,l.type=s.length===1?s[0]:s}const Ep=new Set(["type","properties","required","additionalProperties"]),Rm=["oneOf","anyOf"];function Cm(l){const u=l.additionalProperties;return u===void 0||u===!1||typeof u!="object"||u===null?null:Object.keys(u).length?u:null}function Ms(l){const u=[];for(const d of l){if(typeof d!="object"||d.type!=="object")return null;for(const h in d)if(!Ep.has(h))return null;u.push(d)}const s={},r=new Set;for(const d of u){for(const h in d.properties){if(Object.prototype.hasOwnProperty.call(s,h))continue;const y=[];for(const p of u){const z=p.properties?.[h]??Cm(p);z!=null&&(y.some(N=>JSON.stringify(N)===JSON.stringify(z))||y.push(z))}const g=y.length===1?y[0]:Ms(y)??{allOf:y};dt(s,h,g)}for(const h of d.required??[])r.add(h)}const o={type:"object",properties:s};if(r.size&&(o.required=[...r]),u.every(d=>d.additionalProperties===!1))o.additionalProperties=!1;else{const d=[];for(const h of u){const y=Cm(h);y&&!d.some(g=>JSON.stringify(g)===JSON.stringify(y))&&d.push(y)}d.length===1?o.additionalProperties=d[0]:d.length>1&&(o.additionalProperties={allOf:d})}return o}function V_(l){const u=l.allOf;if(!Array.isArray(u)||u.length<2)return;for(const o of Ep)if(o in l)return;const s=u.filter(o=>Rm.some(d=>Array.isArray(o[d])));let r=null;if(!s.length)r=Ms(u);else{const o=s[0],d=Rm.find(g=>Array.isArray(o[g]));if(Object.keys(o).length!==1)return;const h=u.filter(g=>g!==o),y=o[d].map(g=>Ms([...h,g]));if(y.some(g=>!g))return;r={[d]:y}}r&&(delete l.allOf,fu(l,r))}function Tp(l,u){const s=l.seen.get(u);if(!s)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=y=>{const g=l.seen.get(y);if(g.ref===null)return;const p=g.def??g.schema,z={...p},N=g.ref;if(g.ref=null,N){r(N);const C=l.seen.get(N),B=C.schema;if(B.$ref&&(l.target==="draft-07"||l.target==="draft-04"||l.target==="openapi-3.0")?(p.allOf=p.allOf??[],p.allOf.push(B)):fu(p,B),fu(p,z),y._zod.parent===N)for(const J in p)J==="$ref"||J==="allOf"||J in z||delete p[J];if(B.$ref&&C.def)for(const J in p)J==="$ref"||J==="allOf"||J in C.def&&JSON.stringify(p[J])===JSON.stringify(C.def[J])&&delete p[J]}const w=y._zod.parent;if(w&&w!==N){r(w);const C=l.seen.get(w);if(C?.schema.$ref&&(p.$ref=C.schema.$ref,C.def))for(const B in p)B==="$ref"||B==="allOf"||B in C.def&&JSON.stringify(p[B])===JSON.stringify(C.def[B])&&delete p[B]}l.override({zodSchema:y,jsonSchema:p,path:g.path??[]})};if(!l.external||l.sharedEmitDoneFor!==l.external){for(const y of[...l.seen.entries()].reverse())r(y[0]);if(l.target!=="openapi-3.0")for(const y of l.seen.entries())zp(y[1].def??y[1].schema);for(const y of l.deferred)y();if(l.intersections.length){const y=new Map;for(const g of l.seen.values())for(const p of[g.schema,g.def]){const z=p?.allOf;if(!Array.isArray(z))continue;const N=y.get(z);N?N.push(p):y.set(z,[p])}for(const g of l.intersections)for(const p of y.get(g)??[])V_(p)}}const o={};if(l.target==="draft-2020-12"?o.$schema="https://json-schema.org/draft/2020-12/schema":l.target==="draft-07"?o.$schema="http://json-schema.org/draft-07/schema#":l.target==="draft-04"?o.$schema="http://json-schema.org/draft-04/schema#":l.target,l.external?.uri){const y=l.external.registry.get(u)?.id;if(!y)throw new Error("Schema is missing an `id` property");o.$id=l.external.uri(y)}fu(o,s.defId?s.schema:s.def??s.schema);const d=l.metadataRegistry.get(u)?.id;d!==void 0&&o.id===d&&delete o.id;const h=l.external?.defs??{};if(!l.external||l.sharedEmitDoneFor!==l.external)for(const y of l.seen.entries()){const g=y[1];g.def&&g.defId&&(g.def.id===g.defId&&delete g.def.id,dt(h,g.defId,g.def))}l.external&&(l.sharedEmitDoneFor=l.external),l.external||Object.keys(h).length>0&&(l.target==="draft-2020-12"?o.$defs=h:o.definitions=h);try{const y=JSON.parse(JSON.stringify(o));return Object.defineProperty(y,"~standard",{value:{...u["~standard"],jsonSchema:{input:$i(u,"input",l.processors),output:$i(u,"output",l.processors)}},enumerable:!1,writable:!1}),y}catch{throw new Error("Error converting schema to JSON.")}}function lt(l,u){const s=u??{seen:new Set};if(s.seen.has(l))return!1;s.seen.add(l);const r=l._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return lt(r.element,s);if(r.type==="set")return lt(r.valueType,s);if(r.type==="lazy")return lt(r.getter(),s);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 lt(r.innerType,s);if(r.type==="intersection")return lt(r.left,s)||lt(r.right,s);if(r.type==="record"||r.type==="map")return lt(r.keyType,s)||lt(r.valueType,s);if(r.type==="pipe")return l._zod.traits.has("$ZodCodec")?!0:lt(r.in,s)||lt(r.out,s);if(r.type==="object"){for(const o in r.shape)if(lt(r.shape[o],s))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(lt(o,s))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(lt(o,s))return!0;return!!(r.rest&&lt(r.rest,s))}return!1}const K_=(l,u={})=>s=>{const r=_p({...s,processors:u});return Ye(l,r),Sp(r,l),Tp(r,l)},$i=(l,u,s={})=>r=>{const{libraryOptions:o,target:d}=r??{},h=_p({...o??{},target:d,io:u,processors:s});return Ye(l,h),Sp(h,l),Tp(h,l)},J_={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},F_=(l,u,s,r)=>{const o=s;o.type="string";const{minimum:d,maximum:h,format:y,patterns:g,contentEncoding:p,laxFormat:z}=l._zod.bag;if(typeof d=="number"&&(o.minLength=d),typeof h=="number"&&(o.maxLength=h),y&&(o.format=J_[y]??y,o.format===""&&delete o.format,(y==="time"||z)&&delete o.format),p&&(o.contentEncoding=p),g&&g.size>0){const N=[...g];N.length===1?o.pattern=N[0].source:N.length>1&&(o.allOf=[...N.map(w=>({...u.target==="draft-07"||u.target==="draft-04"||u.target==="openapi-3.0"?{type:"string"}:{},pattern:w.source}))])}},W_=(l,u,s,r)=>{const o=s,{minimum:d,maximum:h,format:y,multipleOf:g,exclusiveMaximum:p,exclusiveMinimum:z}=l._zod.bag;typeof y=="string"&&y.includes("int")?o.type="integer":o.type="number";const N=typeof z=="number"&&z>=(d??Number.NEGATIVE_INFINITY),w=typeof p=="number"&&p<=(h??Number.POSITIVE_INFINITY),C=u.target==="draft-04"||u.target==="openapi-3.0";N?C?(o.minimum=z,o.exclusiveMinimum=!0):o.exclusiveMinimum=z:typeof d=="number"&&(o.minimum=d),w?C?(o.maximum=p,o.exclusiveMaximum=!0):o.exclusiveMaximum=p:typeof h=="number"&&(o.maximum=h),typeof g=="number"&&(Number.isFinite(g)&&g!==0?o.multipleOf=Math.abs(g):Jn(l,u,o,r,`A multipleOf divisor of ${g} cannot be represented in JSON Schema`))},I_=(l,u,s,r)=>{s.type="boolean"},P_=(l,u,s,r)=>{s.not={}},e1=(l,u,s,r)=>{},t1=(l,u,s,r)=>{const o=l._zod.def,d=Xm(o.entries);if(d.length===0){s.not={};return}d.every(h=>typeof h=="number")&&(s.type="number"),d.every(h=>typeof h=="string")&&(s.type="string"),s.enum=d},n1=(l,u,s,r)=>{const o=l._zod.def;if(o.values.length===0){s.not={};return}const d=[];for(const h of o.values)if(h===void 0){if(Jn(l,u,s,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof h=="bigint"){if(Jn(l,u,s,r,"BigInt literals cannot be represented in JSON Schema"))return;d.push(Number(h))}else d.push(h);if(d.length!==0)if(d.length===1){const h=d[0];s.type=h===null?"null":typeof h,u.target==="draft-04"||u.target==="openapi-3.0"?s.enum=[h]:s.const=h}else d.every(h=>typeof h=="number")&&(s.type="number"),d.every(h=>typeof h=="string")&&(s.type="string"),d.every(h=>typeof h=="boolean")&&(s.type="boolean"),d.every(h=>h===null)&&(s.type="null"),s.enum=d},l1=(l,u,s,r)=>{Jn(l,u,s,r,"Custom types cannot be represented in JSON Schema")},a1=(l,u,s,r)=>{Jn(l,u,s,r,"Transforms cannot be represented in JSON Schema")},u1=(l,u,s,r)=>{const o=s,d=l._zod.def,{minimum:h,maximum:y}=l._zod.bag;typeof h=="number"&&(o.minItems=h),typeof y=="number"&&(o.maxItems=y),o.type="array",o.items=Ye(d.element,u,{...r,path:[...r.path,"items"]})};function ki(l){const u=l._zod.def;return u.type==="pipe"&&u.in._zod.traits.has("$ZodTransform")?ki(u.out):u.type==="catch"?ki(u.innerType):l._zod.optin}const i1=(l,u,s,r)=>{const o=s,d=l._zod.def,h=d.shape;if(Object.getOwnPropertySymbols(h).length&&Jn(l,u,o,r,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(const z in h)dt(o.properties,z,Ye(h[z],u,{...r,path:[...r.path,"properties",z]}));const g=new Set(Object.keys(h)),p=new Set([...g].filter(z=>{const N=d.shape[z];return u.io==="input"?ki(N)===void 0:N._zod.optout===void 0}));p.size>0&&(o.required=Array.from(p)),d.catchall?._zod.def.type==="never"?o.additionalProperties=!1:d.catchall?d.catchall&&(o.additionalProperties=Ye(d.catchall,u,{...r,path:[...r.path,"additionalProperties"]})):u.io==="output"&&(o.additionalProperties=!1)},c1=(l,u,s,r)=>{const o=l._zod.def,d=o.inclusive===!1,h=o.options.map((y,g)=>Ye(y,u,{...r,path:[...r.path,d?"oneOf":"anyOf",g]}));d?s.oneOf=h:s.anyOf=h},r1=(l,u,s,r)=>{const o=l._zod.def,d=Ye(o.left,u,{...r,path:[...r.path,"allOf",0]}),h=Ye(o.right,u,{...r,path:[...r.path,"allOf",1]}),y=p=>"allOf"in p&&Object.keys(p).length===1,g=[...y(d)?d.allOf:[d],...y(h)?h.allOf:[h]];s.allOf=g,u.intersections.push(g)};function Zs(l,u,s){if(u.$ref){if(s.has(u))return u;s.add(u);const B=l.get(u)?.def;if(!B)return u;const X=Zs(l,B,s);return X===B?u:X}for(const B of["anyOf","oneOf"]){const X=u[B];if(!Array.isArray(X))continue;const J=X.map(fe=>Zs(l,fe,s));J.some((fe,Re)=>fe!==X[Re])&&(u={...u,[B]:J})}const r=Array.isArray(u.type)?u.type:[u.type],o=!r.includes("string")&&r.some(B=>B==="number"||B==="integer"),d=u.enum??(u.const!==void 0?[u.const]:void 0);if(!o&&!d?.some(B=>typeof B=="number"))return u;const{minimum:h,maximum:y,exclusiveMinimum:g,exclusiveMaximum:p,multipleOf:z,format:N,id:w,...C}=u;return C.enum?C.enum=C.enum.map(B=>typeof B=="number"?String(B):B):typeof C.const=="number"&&(C.const=String(C.const)),o&&(C.type="string",d||(C.pattern=(r.includes("number")?Xs:np).source)),C}const ws=new WeakMap;function s1(l){const u=new Map;for(const r of l.seen.values())r.def&&!u.has(r.schema)&&u.set(r.schema,r);const s=new Map;for(const r of ws.get(l)??[]){const o=l.seen.get(r),d=(o?.def??o?.schema)?.propertyNames;if(!d||d===!0||s.has(d))continue;const h=Zs(u,d,new Set);h!==d&&s.set(d,h)}if(s.size)for(const r of l.seen.values())for(const o of[r.schema,r.def]){const d=o&&s.get(o.propertyNames);d&&(o.propertyNames=d)}}const o1=(l,u,s,r)=>{const o=s,d=l._zod.def;o.type="object";const h=d.keyType,g=h._zod.bag?.patterns;if(d.mode==="loose"&&g&&g.size>0){const N=Ye(d.valueType,u,{...r,path:[...r.path,"patternProperties","*"]});o.patternProperties={};for(const w of g)dt(o.patternProperties,w.source,N)}else{if(u.target==="draft-07"||u.target==="draft-2020-12"){o.propertyNames=Ye(d.keyType,u,{...r,path:[...r.path,"propertyNames"]});let N=ws.get(u);N||(N=[],ws.set(u,N),u.deferred.push(()=>s1(u))),N.push(l)}o.additionalProperties=Ye(d.valueType,u,{...r,path:[...r.path,"additionalProperties"]})}const p=h._zod.values,z=u.io==="input"&&ki(d.valueType)!==void 0;if(p&&!d.partial&&!z){const N=[...p].filter(w=>typeof w=="string"||typeof w=="number");N.length>0&&(o.required=N.map(String))}},f1=(l,u,s,r)=>{const o=l._zod.def,d=Ye(o.innerType,u,r),h=u.seen.get(l);u.target==="openapi-3.0"?(h.ref=o.innerType,s.nullable=!0):s.anyOf=[d,{type:"null"}]},d1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType},Ks=Symbol();function Op(l,u,s,r,o){let d=!1;const h=JSON.stringify(l,(y,g)=>typeof g!="bigint"?g:(d=!0,null));return d?(Jn(u,s,r,o,"BigInt defaults cannot be represented in JSON Schema"),Ks):JSON.parse(h)}const h1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType;const h=Op(o.defaultValue,l,u,s,r);h!==Ks&&(s.default=h)},m1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);if(d.ref=o.innerType,u.io!=="input")return;const h=Op(o.defaultValue,l,u,s,r);h!==Ks&&(s._prefault=h)},p1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType;let h;try{h=o.catchValue(void 0)}catch{Jn(l,u,s,r,"Dynamic catch values are not supported in JSON Schema");return}s.default=h},y1=(l,u,s,r)=>{const o=l._zod.def,d=o.in._zod.traits.has("$ZodTransform"),h=u.io==="input"?d?o.out:o.in:o.out;Ye(h,u,r);const y=u.seen.get(l);y.ref=h},g1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType,s.readOnly=!0},Ap=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType},Bm=new WeakSet([Object.prototype,Error.prototype]);function Ci(l,u,s){Object.defineProperty(l,u,{configurable:!0,enumerable:!1,get(){const r=s(this);return Object.defineProperty(this,u,{value:r,configurable:!0,writable:!0}),r},set(r){Object.defineProperty(this,u,{value:r,configurable:!0,writable:!0})}})}const v1=(l,u)=>{Im.init(l,u),l.name="ZodError";const s=Object.getPrototypeOf(l);Bm.has(s)||(Bm.add(s),Ci(s,"format",r=>o=>Jv(r,o)),Ci(s,"flatten",r=>o=>Kv(r,o)),Ci(s,"addIssue",r=>o=>{r.issues.push(o),r.message=JSON.stringify(r.issues,js,2)}),Ci(s,"addIssues",r=>o=>{r.issues.push(...o),r.message=JSON.stringify(r.issues,js,2)}),Object.defineProperty(s,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},qt=M("ZodError",v1,void 0,{Parent:Error}),b1=Gs(qt),_1=Ls(qt),S1=Li(qt),z1=Xi(qt),E1=Iv(qt),T1=Pv(qt),O1=e0(qt),A1=t0(qt),N1=n0(qt),j1=l0(qt),x1=a0(qt),D1=u0(qt);function U1(){Xt.localeError||Ft(e_())}function Vi(){Xt.memoizer||Ft({memoizer:Wb()})}const je=M("ZodType",(l,u)=>(U1(),Ne.init(l,u),l.def=u,l.type=u.type,l),{check(...l){const u=this.def;return this.clone(Wn(u,{checks:[...u.checks??[],...l.map(s=>typeof s=="function"?{_zod:{check:s,def:{check:"custom"},onattach:[]}}:s)]}),{parent:!0})},with(...l){return this.check(...l)},clone(l,u){return In(this,l,u)},brand(){return this},register(l,u){return l.add(this,u),this},refine(l,u){return this.check(OS(l,u))},superRefine(l,u){return this.check(AS(l,u))},overwrite(l){return this.check(da(l))},optional(){return $m(this)},exactOptional(){return hS(this)},nullable(){return km(this)},nullish(){return $m(km(this))},nonoptional(l){return bS(this,l)},array(){return et(this)},or(l){return iS([this,l])},and(l){return rS(this,l)},transform(l){return Gm(this,dS(l))},default(l){return yS(this,l)},prefault(l){return vS(this,l)},catch(l){return SS(this,l)},pipe(l){return Gm(this,l)},readonly(){return TS(this)},describe(l){const u=this.clone();return su.add(u,{description:l}),u},meta(...l){if(l.length===0)return su.get(this);const u=this.clone();return su.add(u,l[0]),u},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(l,...u){return u.length===0?l(this):l(this,...u)},get"~standard"(){return Jm(this,"~standard",{...up(this),jsonSchema:{input:$i(this,"input"),output:$i(this,"output")}})},set"~standard"(l){oa(this,"~standard",l)},parse:function l(u,s){return b1(this,u,s,{callee:l})},parseAsync:async function l(u,s){return await _1(this,u,s,{callee:l})},safeParse(l,u){return S1(this,l,u)},async safeParseAsync(l,u){return z1(this,l,u)},get spa(){return this?.safeParseAsync},set spa(l){oa(this,"spa",l)},encode:function l(u,s){return E1(this,u,s,{callee:l})},decode:function l(u,s){return T1(this,u,s,{callee:l})},encodeAsync:async function l(u,s){return await O1(this,u,s,{callee:l})},decodeAsync:async function l(u,s){return await A1(this,u,s,{callee:l})},safeEncode(l,u){return N1(this,l,u)},safeDecode(l,u){return j1(this,l,u)},async safeEncodeAsync(l,u){return x1(this,l,u)},async safeDecodeAsync(l,u){return D1(this,l,u)},toJSONSchema(l){return K_(this,{})(l)},get description(){return su.get(this)?.description},get _def(){return this._zod.def}}),Np=M("_ZodString",(l,u)=>{Vs.init(l,u),je.init(l,u),l._zod.processJSONSchema=(r,o,d)=>F_(l,r,o);const s=l._zod.bag;l.format=s.format??null,l.minLength=s.minimum??null,l.maxLength=s.maximum??null},{regex(...l){return this.check(M_(...l))},includes(...l){return this.check(R_(...l))},startsWith(...l){return this.check(C_(...l))},endsWith(...l){return this.check(B_(...l))},min(...l){return this.check(Yi(...l))},max(...l){return this.check(vp(...l))},length(...l){return this.check(bp(...l))},nonempty(...l){return this.check(Yi(1,...l))},lowercase(l){return this.check(Z_(l))},uppercase(l){return this.check(w_(l))},trim(){return this.check(q_())},normalize(...l){return this.check(H_(...l))},toLowerCase(){return this.check(Y_())},toUpperCase(){return this.check($_())},slugify(){return this.check(k_())}}),M1=M("ZodString",(l,u)=>{Vs.init(l,u),Np.init(l,u)},{email(l){return this.check(a_(C1,l))},url(l){return this.check(yp(xp,l))},jwt(l){return this.check(E_(P1,l))},emoji(l){return this.check(s_(q1,l))},guid(l){return this.check(u_(B1,l))},uuid(l){return this.check(i_(ou,l))},uuidv4(l){return this.check(c_(ou,l))},uuidv6(l){return this.check(r_(ou,l))},uuidv7(l){return this.check(pp(ou,l))},nanoid(l){return this.check(o_(Y1,l))},cuid(l){return this.check(f_($1,l))},cuid2(l){return this.check(d_(k1,l))},ulid(l){return this.check(h_(G1,l))},base64(l){return this.check(__(F1,l))},base64url(l){return this.check(S_(W1,l))},xid(l){return this.check(m_(L1,l))},ksuid(l){return this.check(p_(X1,l))},ipv4(l){return this.check(y_(Q1,l))},ipv6(l){return this.check(g_(V1,l))},cidrv4(l){return this.check(v_(K1,l))},cidrv6(l){return this.check(b_(J1,l))},e164(l){return this.check(z_(I1,l))},datetime(l){return this.check(gp(jp,l))},date(l){return this.check(T_(Z1,l))},time(l){return this.check(O_(w1,l))},duration(l){return this.check(A_(R1,l))}});function Se(l){return l_(M1,l)}const xe=M("ZodStringFormat",(l,u)=>{Ae.init(l,u),Np.init(l,u)}),jp=M("ZodISODateTime",(l,u)=>{sb.init(l,u),xe.init(l,u)}),Z1=M("ZodISODate",(l,u)=>{ob.init(l,u),xe.init(l,u)}),w1=M("ZodISOTime",(l,u)=>{fb.init(l,u),xe.init(l,u)}),R1=M("ZodISODuration",(l,u)=>{db.init(l,u),xe.init(l,u)}),C1=M("ZodEmail",(l,u)=>{J0.init(l,u),xe.init(l,u)}),B1=M("ZodGUID",(l,u)=>{V0.init(l,u),xe.init(l,u)}),ou=M("ZodUUID",(l,u)=>{K0.init(l,u),xe.init(l,u)});function du(l){return pp(ou,l)}const xp=M("ZodURL",(l,u)=>{tb.init(l,u),xe.init(l,u)});function H1(l){return yp(xp,l)}const q1=M("ZodEmoji",(l,u)=>{nb.init(l,u),xe.init(l,u)}),Y1=M("ZodNanoID",(l,u)=>{lb.init(l,u),xe.init(l,u)}),$1=M("ZodCUID",(l,u)=>{ab.init(l,u),xe.init(l,u)}),k1=M("ZodCUID2",(l,u)=>{ub.init(l,u),xe.init(l,u)}),G1=M("ZodULID",(l,u)=>{ib.init(l,u),xe.init(l,u)}),L1=M("ZodXID",(l,u)=>{cb.init(l,u),xe.init(l,u)}),X1=M("ZodKSUID",(l,u)=>{rb.init(l,u),xe.init(l,u)}),Q1=M("ZodIPv4",(l,u)=>{hb.init(l,u),xe.init(l,u)}),V1=M("ZodIPv6",(l,u)=>{pb.init(l,u),xe.init(l,u)}),K1=M("ZodCIDRv4",(l,u)=>{yb.init(l,u),xe.init(l,u)}),J1=M("ZodCIDRv6",(l,u)=>{vb.init(l,u),xe.init(l,u)}),F1=M("ZodBase64",(l,u)=>{bb.init(l,u),xe.init(l,u)}),W1=M("ZodBase64URL",(l,u)=>{Sb.init(l,u),xe.init(l,u)}),I1=M("ZodE164",(l,u)=>{zb.init(l,u),xe.init(l,u)}),P1=M("ZodJWT",(l,u)=>{Tb.init(l,u),xe.init(l,u)}),Dp=M("ZodNumber",(l,u)=>{op.init(l,u),je.init(l,u),l._zod.processJSONSchema=(r,o,d)=>W_(l,r,o,d);const s=l._zod.bag;l.minValue=Math.max(s.minimum??Number.NEGATIVE_INFINITY,s.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,l.maxValue=Math.min(s.maximum??Number.POSITIVE_INFINITY,s.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,l.isInt=(s.format??"").includes("int")||Number.isSafeInteger(s.multipleOf??.5),l.isFinite=!0,l.format=s.format??null},{gt(l,u){return this.check(Mm(l,u))},gte(l,u){return this.check(As(l,u))},min(l,u){return this.check(As(l,u))},lt(l,u){return this.check(Um(l,u))},lte(l,u){return this.check(Os(l,u))},max(l,u){return this.check(Os(l,u))},int(l){return this.check(Hm(l))},safe(l){return this.check(Hm(l))},positive(l){return this.check(Mm(0,l))},nonnegative(l){return this.check(As(0,l))},negative(l){return this.check(Um(0,l))},nonpositive(l){return this.check(Os(0,l))},multipleOf(l,u){return this.check(Zm(l,u))},step(l,u){return this.check(Zm(l,u))},finite(){return this}});function Lt(l){return N_(Dp,l)}const eS=M("ZodNumberFormat",(l,u)=>{Ob.init(l,u),Dp.init(l,u)});function Hm(l){return j_(eS,l)}const tS=M("ZodBoolean",(l,u)=>{Ab.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>I_(l,s,r)});function Rs(l){return x_(tS,l)}const nS=M("ZodUnknown",(l,u)=>{Nb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>e1()});function qm(){return D_(nS)}const lS=M("ZodNever",(l,u)=>{jb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>P_(l,s,r)});function Up(l){return U_(lS,l)}const aS=M("ZodArray",(l,u)=>{Vi(),xb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>u1(l,s,r,o),l.element=u.element},{min(l,u){return this.check(Yi(l,u))},nonempty(l){return this.check(Yi(1,l))},max(l,u){return this.check(vp(l,u))},length(l,u){return this.check(bp(l,u))},unwrap(){return this.element}});function et(l,u){return G_(aS,l,u)}const Mp=M("ZodObject",(l,u)=>{Vi(),Mb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>i1(l,s,r,o),Yv(l,"shape",s=>s._zod.def.shape,!1)},{keyof(){return Fn(Object.keys(this._zod.def.shape))},catchall(l){return this.clone({...this._zod.def,catchall:l})},passthrough(){return this.clone({...this._zod.def,catchall:qm()})},loose(){return this.clone({...this._zod.def,catchall:qm()})},strict(){return this.clone({...this._zod.def,catchall:Up()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(l){return xv(this,l)},safeExtend(l){return Dv(this,l)},merge(l){return Uv(this,l)},pick(l){return Nv(this,l)},omit(l){return jv(this,l)},partial(...l){return fm(Zp,this,l[0])},exactPartial(...l){return fm(wp,this,l[0],"exactPartial")},required(...l){return Mv(Rp,this,l[0])}});function Bt(l,u){const s={type:"object",shape:l??{},...G(u)};return new Mp(s)}function _n(l,u){return new Mp({type:"object",shape:l,catchall:Up(),...G(u)})}const uS=M("ZodUnion",(l,u)=>{Zb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>c1(l,s,r,o),l.options=u.options});function iS(l,u){return new uS({type:"union",options:l,...G(u)})}const cS=M("ZodIntersection",(l,u)=>{wb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>r1(l,s,r,o)});function rS(l,u){return new cS({type:"intersection",left:l,right:u})}const Ym=M("ZodRecord",(l,u)=>{Vi(),Rb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>o1(l,s,r,o),l.keyType=u.keyType,l.valueType=u.valueType});function sS(l,u,s){return!u||!u._zod?new Ym({type:"record",keyType:Se(),valueType:l,...G(u)}):new Ym({type:"record",keyType:l,valueType:u,...G(s)})}const Cs=M("ZodEnum",(l,u)=>{Cb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(r,o,d)=>t1(l,r,o),l.enum=u.entries,l.options=Object.values(u.entries);const s=new Set(Object.keys(u.entries));l.extract=(r,o)=>{const d={};for(const h of r)if(s.has(h))d[h]=u.entries[h];else throw new Error(`Key ${h} not found in enum`);return new Cs({...u,checks:[],...G(o),entries:d})},l.exclude=(r,o)=>{const d={...u.entries};for(const h of r)if(s.has(h))delete d[h];else throw new Error(`Key ${h} not found in enum`);return new Cs({...u,checks:[],...G(o),entries:d})}});function Fn(l,u){const s=Array.isArray(l)?Object.fromEntries(l.map(r=>[r,r])):l;return new Cs({type:"enum",entries:s,...G(u)})}const oS=M("ZodLiteral",(l,u)=>{Bb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>n1(l,s,r,o),l.values=new Set(u.values),Object.defineProperty(l,"value",{get(){if(u.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return u.values[0]}})});function Js(l,u){return new oS({type:"literal",values:Array.isArray(l)?l:[l],...G(u)})}const fS=M("ZodTransform",(l,u)=>{Vi(),Hb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>a1(l,s,r,o),l._zod.parse=(s,r)=>{if(r.direction==="backward")throw new Fm(l.constructor.name);s.addIssue=d=>{if(typeof d=="string")s.issues.push(hu(d,s.value,u));else{const h=d;h.fatal&&(h.continue=!1),h.code??(h.code="custom"),"input"in h||(h.input=s.value),h.inst??(h.inst=l),s.issues.push(hu(h))}};const o=u.transform(s.value,s);return o instanceof Promise?o.then(d=>(s.value=d,s)):(s.value=o,s)}});function dS(l){return new fS({type:"transform",transform:l})}const Zp=M("ZodOptional",(l,u)=>{hp.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>Ap(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function $m(l){return new Zp({type:"optional",innerType:l})}const wp=M("ZodExactOptional",(l,u)=>{qb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>Ap(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function hS(l){return new wp({type:"optional",innerType:l})}const mS=M("ZodNullable",(l,u)=>{Yb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>f1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function km(l){return new mS({type:"nullable",innerType:l})}const pS=M("ZodDefault",(l,u)=>{$b.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>h1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType,l.removeDefault=l.unwrap});function yS(l,u){return new pS({type:"default",innerType:l,get defaultValue(){return typeof u=="function"?u():Vm(u)}})}const gS=M("ZodPrefault",(l,u)=>{kb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>m1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function vS(l,u){return new gS({type:"prefault",innerType:l,get defaultValue(){return typeof u=="function"?u():Vm(u)}})}const Rp=M("ZodNonOptional",(l,u)=>{Gb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>d1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function bS(l,u){return new Rp({type:"nonoptional",innerType:l,...G(u)})}const _S=M("ZodCatch",(l,u)=>{Lb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>p1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType,l.removeCatch=l.unwrap});function SS(l,u){return new _S({type:"catch",innerType:l,catchValue:typeof u=="function"?u:kv(u)})}const zS=M("ZodPipe",(l,u)=>{Xb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>y1(l,s,r,o),l.in=u.in,l.out=u.out});function Gm(l,u){return new zS({type:"pipe",in:l,out:u})}const ES=M("ZodReadonly",(l,u)=>{Qb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>g1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function TS(l){return new ES({type:"readonly",innerType:l})}const Cp=M("ZodCustom",(l,u)=>{Vb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>l1(l,s,r,o)});function OS(l,u={}){return L_(Cp,l,u)}function AS(l,u){return X_(l,u)}function NS(l,u={}){const s=new Cp({type:"custom",check:"custom",fn:r=>r instanceof l,abort:!0,...G(u)});return s._zod.bag.Class=l,s._zod.check=r=>{r.value instanceof l||r.issues.push({code:"invalid_type",expected:l.name,input:r.value,inst:s,path:[...s._zod.def.path??[]]})},s}function _l(l){return gp(jp,l)}const Vn=Se().regex(/^(0|[1-9][0-9]*)$/),fa=Vn.max(78),Ki=H1().refine(l=>{const u=new URL(l);return["http:","https:"].includes(u.protocol)&&!u.username&&!u.password},"Expected an HTTP(S) URL without credentials"),Qe=Se().min(1).max(256),Bp=sS(Se(),Se());Bt({url:Ki,method:Se().min(1).max(64),headers:Bp});Bt({status:Lt().int().min(100).max(599),headers:Bp,body:NS(Uint8Array).optional()});const jS=Bt({id:du(),ts:_l(),rail:Js("x402"),attemptedAt:_l().optional(),status:Fn(["observed","blocked"]),reason:Se().optional(),amount:fa,decimals:Lt().int().min(0).max(255),decimalsKnown:Rs(),asset:Qe,assetSymbol:Qe.optional(),network:Qe,payTo:Qe,payer:Qe.optional(),resource:Ki,host:Qe,txHash:Se().optional(),taskId:Qe.optional(),agentId:Qe.optional(),raw:Se(),paymentKey:Se().min(1),settlementStatus:Fn(["unknown","confirmed","failed"]).default("unknown"),settlement_unknown:Rs().default(!0)});Bt({id:du(),ts:_l(),paymentId:du(),attemptId:du().optional(),attemptedAt:_l().optional(),status:Fn(["unknown","confirmed","failed"]),txHash:Se().optional(),reason:Se().optional()});const xS=Bt({id:du(),ts:_l(),code:Fn(["parse_failed","settlement_unknown","tls_unmetered","storage_failed"]),resource:Se(),message:Se()});Bt({error:Js("blocked_by_taximeter"),reason:Se(),budget:fa.nullable(),spent:Vn,remaining:fa.nullable()});const bl=_n({amount:fa,asset:Qe,network:Qe.optional(),window:Fn(["1h","24h","7d","30d"]).optional()}),DS=_n({allowHosts:et(Qe).default([]),denyHosts:et(Qe).default([]),allowPayTo:et(Qe).default([]),maxSinglePayment:fa.nullable().default("1000000"),maxSingleAsset:Qe.default("USDC"),unknownAsset:Fn(["allow","deny"]).default("deny")}),US=_n({proxy:Lt().int().min(0).max(65535).default(8402),dashboard:Lt().int().min(0).max(65535).default(8403)});_n({budgets:_n({perTask:bl.nullable().default({amount:"5000000",asset:"USDC"}),perAgent:bl.nullable().default({amount:"50000000",asset:"USDC",window:"24h"}),global:bl.nullable().default({amount:"100000000",asset:"USDC",window:"24h"})}).prefault({}),policy:DS.prefault({}),ports:US.prefault({}),db:Se().min(1).default("~/.taximeter/ledger.db"),upstream:Ki.optional()});_n({budgets:_n({perTask:bl.partial().nullable().optional(),perAgent:bl.partial().nullable().optional(),global:bl.partial().nullable().optional()}).optional(),policy:_n({allowHosts:et(Qe).optional(),denyHosts:et(Qe).optional(),allowPayTo:et(Qe).optional(),maxSinglePayment:fa.nullable().optional(),maxSingleAsset:Qe.optional(),unknownAsset:Fn(["allow","deny"]).optional()}).optional(),ports:_n({proxy:Lt().int().min(0).max(65535).optional(),dashboard:Lt().int().min(0).max(65535).optional()}).optional(),db:Se().min(1).optional(),upstream:Ki.optional()});const Bs=Bt({network:Se(),asset:Se(),assetSymbol:Se().optional(),decimals:Lt().int(),decimalsKnown:Rs(),amount:Vn,confirmedAmount:Vn,unknownAmount:Vn});function MS(l,u){const s=BigInt(l).toString();if(u===0)return s;const r=s.padStart(u+1,"0");return`${r.slice(0,-u)}.${r.slice(-u)}`}const ZS="0.2.0",wS=Se().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/).parse(ZS),RS=jS.omit({raw:!0}),Ns=Bs.extend({key:Se().nullable()}),CS=Bt({version:Js(wS),generatedAt:_l(),totalEvents:Lt().int(),blockedEvents:Lt().int(),unknownEvents:Lt().int(),totals:et(Bs),events:et(RS),diagnostics:et(xS),groups:Bt({task:et(Ns),agent:et(Ns),host:et(Ns)}),hours:et(Bt({ts:_l(),totals:et(Bs)})),globalBudget:bl.nullable(),budgets:et(Bt({network:Se(),asset:Se(),limit:Vn,spent:Vn,remaining:Vn,window:Se().nullable()})),proxy:Bt({port:Lt().int(),upstream:Se().optional()})});function Ht(l){return`${l.network}/${l.asset.toLowerCase()}`}function At(l,u){return u.decimalsKnown?MS(l,u.decimals):`${l} atomic units`}function Hp(l,u){const s=BigInt(u);if(s<=0n)return"0";const r=BigInt(l)*10000n/s,o=r<0n?0n:r>10000n?10000n:r;return`${o/100n}.${(o%100n).toString().padStart(2,"0")}`}function mu(l){return l==="eip155:8453"?"Base":l==="eip155:84532"?"Base Sepolia":l==="eip155:1"?"Ethereum":l}function Ji(l){return l.assetSymbol??`${l.asset.slice(0,8)}…${l.asset.slice(-6)}`}function bn(l){return new Date(l).toISOString().slice(11,19)}function BS(l,u){const s=l.map(p=>({ts:p.ts,amount:p.totals.find(z=>Ht(z)===u)?.amount??"0"})),r=s.reduce((p,z)=>p+BigInt(z.amount),0n),o=s.reduce((p,z)=>BigInt(z.amount)>p?BigInt(z.amount):p,0n);let d=0n;const h=BigInt(Math.max(s.length-1,1)),y=BigInt(Math.max(s.length,1)),g=s.map((p,z)=>(d+=BigInt(p.amount),{...p,x:(32n+BigInt(z)*936n/h).toString(),y:(184n-(r>0n?d*132n/r:0n)).toString(),barX:(32n+BigInt(z)*936n/y).toString(),barWidth:(936n/y-7n).toString(),barHeight:(o>0n?BigInt(p.amount)*106n/o:0n).toString(),barY:(138n-(o>0n?BigInt(p.amount)*106n/o:0n)).toString()}));return{series:g,points:g.map(p=>`${p.x},${p.y}`).join(" "),sum:r.toString(),maximum:o.toString()}}const Lm=[{view:"now",label:"Now"},{view:"task",label:"By task"},{view:"agent",label:"By agent"},{view:"host",label:"By host"},{view:"timeline",label:"Timeline"},{view:"export",label:"Export"}];function Fs(){return v.jsxs("span",{className:"wordmark",children:[v.jsxs("span",{className:"mark","aria-hidden":"true",children:[v.jsx("i",{}),v.jsx("i",{}),v.jsx("i",{})]}),"taximeter"]})}function HS({state:l}){const u=`http://127.0.0.1:${l.proxy.port}`;return v.jsxs("section",{className:"empty-state","aria-label":"Getting started",children:[v.jsxs("div",{className:"empty-heading",children:[v.jsx("span",{className:"eyebrow",children:"READY WHEN YOU ARE"}),v.jsx("h2",{children:"Your next payment starts the ledger."}),v.jsx("p",{children:"Point your agent at the local proxy. Taximeter records each supported payment and checks its budget before the replay goes upstream."})]}),v.jsxs("div",{className:"connection-instructions",children:[v.jsx("span",{className:"eyebrow",children:"YOUR LOCAL PROXY"}),v.jsx("code",{children:u}),v.jsx("p",{children:l.proxy.upstream?v.jsxs(v.Fragment,{children:["Requests forward to ",v.jsx("strong",{children:l.proxy.upstream}),"."]}):v.jsxs(v.Fragment,{children:["Use this address with an HTTP-proxy-aware client. For an explicit API base URL, restart with ",v.jsx("code",{children:"--upstream"})," set to your API."]})}),v.jsxs("p",{className:"connection-limit",children:["HTTPS CONNECT passes through unmetered. Use an explicit upstream or the"," ",v.jsx("code",{children:"withMeter"})," SDK to inspect HTTPS payments."]})]}),v.jsxs("div",{className:"empty-footer",children:[v.jsx("span",{children:"No payments recorded"}),v.jsx("span",{children:"No keys. No custody. Everything stays local."})]})]})}function qS({event:l}){const u=l.status==="blocked"?"Blocked":l.settlementStatus==="confirmed"?"Settled":l.settlementStatus==="failed"?"Failed":"Unknown",s=l.status==="blocked"?"blocked":l.settlementStatus;return v.jsx("span",{className:`event-status status-${s}`,title:l.reason??(u==="Settled"?"Settlement reported by the upstream":u==="Unknown"?"Settlement unknown; budget remains reserved":void 0),children:u})}function YS({state:l}){return v.jsxs("section",{className:"ledger-section",children:[v.jsxs("div",{className:"section-heading",children:[v.jsx("div",{children:v.jsxs("h2",{children:["Live ledger ",v.jsxs("span",{className:"muted",children:["/ latest ",l.events.length]})]})}),v.jsx("span",{className:"table-note",children:"All assets · times in UTC"})]}),v.jsx("div",{className:"table-scroll",children:v.jsxs("table",{className:"event-table",children:[v.jsx("thead",{children:v.jsxs("tr",{children:[v.jsx("th",{scope:"col",children:"Time"}),v.jsx("th",{scope:"col",children:"Resource"}),v.jsx("th",{scope:"col",children:"Task / agent"}),v.jsx("th",{scope:"col",children:"Network"}),v.jsx("th",{scope:"col",className:"numeric",children:"Amount"}),v.jsx("th",{scope:"col",children:"Asset"}),v.jsx("th",{scope:"col",className:"status-cell",children:"Status"})]})}),v.jsx("tbody",{children:l.events.map(u=>v.jsxs("tr",{className:u.status==="blocked"?"blocked-row":void 0,children:[v.jsx("td",{className:"mono time-cell",title:u.ts,children:bn(u.ts)}),v.jsx("td",{className:"resource-cell",children:v.jsx("a",{href:u.resource,target:"_blank",rel:"noreferrer",title:u.resource,children:u.host})}),v.jsxs("td",{className:"attribution-cell",title:`Task: ${u.taskId??"Unattributed"}
100
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const h of l.seen.entries()){const y=h[1];if(u===h[0]){d(h);continue}if(l.external){const p=l.external.registry.get(h[0])?.id;if(u!==h[0]&&p){d(h);continue}}if(l.metadataRegistry.get(h[0])?.id){d(h);continue}if(y.cycle){d(h);continue}if(y.count>1&&l.reused==="ref"){d(h);continue}}l.external&&(l.sharedDefsExtractedFor=l.external)}function zp(l){const u=l.anyOf;if(!Array.isArray(u)||u.length===0||l.type!==void 0)return;const s=[];for(const r of u){if(!r||typeof r!="object")return;zp(r);const o=Object.keys(r);if(o.length!==1||o[0]!=="type")return;const d=r.type;for(const h of Array.isArray(d)?d:[d]){if(typeof h!="string")return;s.includes(h)||s.push(h)}}delete l.anyOf,l.type=s.length===1?s[0]:s}const Ep=new Set(["type","properties","required","additionalProperties"]),Rm=["oneOf","anyOf"];function Cm(l){const u=l.additionalProperties;return u===void 0||u===!1||typeof u!="object"||u===null?null:Object.keys(u).length?u:null}function Ms(l){const u=[];for(const d of l){if(typeof d!="object"||d.type!=="object")return null;for(const h in d)if(!Ep.has(h))return null;u.push(d)}const s={},r=new Set;for(const d of u){for(const h in d.properties){if(Object.prototype.hasOwnProperty.call(s,h))continue;const y=[];for(const p of u){const z=p.properties?.[h]??Cm(p);z!=null&&(y.some(N=>JSON.stringify(N)===JSON.stringify(z))||y.push(z))}const g=y.length===1?y[0]:Ms(y)??{allOf:y};dt(s,h,g)}for(const h of d.required??[])r.add(h)}const o={type:"object",properties:s};if(r.size&&(o.required=[...r]),u.every(d=>d.additionalProperties===!1))o.additionalProperties=!1;else{const d=[];for(const h of u){const y=Cm(h);y&&!d.some(g=>JSON.stringify(g)===JSON.stringify(y))&&d.push(y)}d.length===1?o.additionalProperties=d[0]:d.length>1&&(o.additionalProperties={allOf:d})}return o}function V_(l){const u=l.allOf;if(!Array.isArray(u)||u.length<2)return;for(const o of Ep)if(o in l)return;const s=u.filter(o=>Rm.some(d=>Array.isArray(o[d])));let r=null;if(!s.length)r=Ms(u);else{const o=s[0],d=Rm.find(g=>Array.isArray(o[g]));if(Object.keys(o).length!==1)return;const h=u.filter(g=>g!==o),y=o[d].map(g=>Ms([...h,g]));if(y.some(g=>!g))return;r={[d]:y}}r&&(delete l.allOf,fu(l,r))}function Tp(l,u){const s=l.seen.get(u);if(!s)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=y=>{const g=l.seen.get(y);if(g.ref===null)return;const p=g.def??g.schema,z={...p},N=g.ref;if(g.ref=null,N){r(N);const C=l.seen.get(N),B=C.schema;if(B.$ref&&(l.target==="draft-07"||l.target==="draft-04"||l.target==="openapi-3.0")?(p.allOf=p.allOf??[],p.allOf.push(B)):fu(p,B),fu(p,z),y._zod.parent===N)for(const J in p)J==="$ref"||J==="allOf"||J in z||delete p[J];if(B.$ref&&C.def)for(const J in p)J==="$ref"||J==="allOf"||J in C.def&&JSON.stringify(p[J])===JSON.stringify(C.def[J])&&delete p[J]}const w=y._zod.parent;if(w&&w!==N){r(w);const C=l.seen.get(w);if(C?.schema.$ref&&(p.$ref=C.schema.$ref,C.def))for(const B in p)B==="$ref"||B==="allOf"||B in C.def&&JSON.stringify(p[B])===JSON.stringify(C.def[B])&&delete p[B]}l.override({zodSchema:y,jsonSchema:p,path:g.path??[]})};if(!l.external||l.sharedEmitDoneFor!==l.external){for(const y of[...l.seen.entries()].reverse())r(y[0]);if(l.target!=="openapi-3.0")for(const y of l.seen.entries())zp(y[1].def??y[1].schema);for(const y of l.deferred)y();if(l.intersections.length){const y=new Map;for(const g of l.seen.values())for(const p of[g.schema,g.def]){const z=p?.allOf;if(!Array.isArray(z))continue;const N=y.get(z);N?N.push(p):y.set(z,[p])}for(const g of l.intersections)for(const p of y.get(g)??[])V_(p)}}const o={};if(l.target==="draft-2020-12"?o.$schema="https://json-schema.org/draft/2020-12/schema":l.target==="draft-07"?o.$schema="http://json-schema.org/draft-07/schema#":l.target==="draft-04"?o.$schema="http://json-schema.org/draft-04/schema#":l.target,l.external?.uri){const y=l.external.registry.get(u)?.id;if(!y)throw new Error("Schema is missing an `id` property");o.$id=l.external.uri(y)}fu(o,s.defId?s.schema:s.def??s.schema);const d=l.metadataRegistry.get(u)?.id;d!==void 0&&o.id===d&&delete o.id;const h=l.external?.defs??{};if(!l.external||l.sharedEmitDoneFor!==l.external)for(const y of l.seen.entries()){const g=y[1];g.def&&g.defId&&(g.def.id===g.defId&&delete g.def.id,dt(h,g.defId,g.def))}l.external&&(l.sharedEmitDoneFor=l.external),l.external||Object.keys(h).length>0&&(l.target==="draft-2020-12"?o.$defs=h:o.definitions=h);try{const y=JSON.parse(JSON.stringify(o));return Object.defineProperty(y,"~standard",{value:{...u["~standard"],jsonSchema:{input:$i(u,"input",l.processors),output:$i(u,"output",l.processors)}},enumerable:!1,writable:!1}),y}catch{throw new Error("Error converting schema to JSON.")}}function lt(l,u){const s=u??{seen:new Set};if(s.seen.has(l))return!1;s.seen.add(l);const r=l._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return lt(r.element,s);if(r.type==="set")return lt(r.valueType,s);if(r.type==="lazy")return lt(r.getter(),s);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 lt(r.innerType,s);if(r.type==="intersection")return lt(r.left,s)||lt(r.right,s);if(r.type==="record"||r.type==="map")return lt(r.keyType,s)||lt(r.valueType,s);if(r.type==="pipe")return l._zod.traits.has("$ZodCodec")?!0:lt(r.in,s)||lt(r.out,s);if(r.type==="object"){for(const o in r.shape)if(lt(r.shape[o],s))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(lt(o,s))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(lt(o,s))return!0;return!!(r.rest&&lt(r.rest,s))}return!1}const K_=(l,u={})=>s=>{const r=_p({...s,processors:u});return Ye(l,r),Sp(r,l),Tp(r,l)},$i=(l,u,s={})=>r=>{const{libraryOptions:o,target:d}=r??{},h=_p({...o??{},target:d,io:u,processors:s});return Ye(l,h),Sp(h,l),Tp(h,l)},J_={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},F_=(l,u,s,r)=>{const o=s;o.type="string";const{minimum:d,maximum:h,format:y,patterns:g,contentEncoding:p,laxFormat:z}=l._zod.bag;if(typeof d=="number"&&(o.minLength=d),typeof h=="number"&&(o.maxLength=h),y&&(o.format=J_[y]??y,o.format===""&&delete o.format,(y==="time"||z)&&delete o.format),p&&(o.contentEncoding=p),g&&g.size>0){const N=[...g];N.length===1?o.pattern=N[0].source:N.length>1&&(o.allOf=[...N.map(w=>({...u.target==="draft-07"||u.target==="draft-04"||u.target==="openapi-3.0"?{type:"string"}:{},pattern:w.source}))])}},W_=(l,u,s,r)=>{const o=s,{minimum:d,maximum:h,format:y,multipleOf:g,exclusiveMaximum:p,exclusiveMinimum:z}=l._zod.bag;typeof y=="string"&&y.includes("int")?o.type="integer":o.type="number";const N=typeof z=="number"&&z>=(d??Number.NEGATIVE_INFINITY),w=typeof p=="number"&&p<=(h??Number.POSITIVE_INFINITY),C=u.target==="draft-04"||u.target==="openapi-3.0";N?C?(o.minimum=z,o.exclusiveMinimum=!0):o.exclusiveMinimum=z:typeof d=="number"&&(o.minimum=d),w?C?(o.maximum=p,o.exclusiveMaximum=!0):o.exclusiveMaximum=p:typeof h=="number"&&(o.maximum=h),typeof g=="number"&&(Number.isFinite(g)&&g!==0?o.multipleOf=Math.abs(g):Jn(l,u,o,r,`A multipleOf divisor of ${g} cannot be represented in JSON Schema`))},I_=(l,u,s,r)=>{s.type="boolean"},P_=(l,u,s,r)=>{s.not={}},e1=(l,u,s,r)=>{},t1=(l,u,s,r)=>{const o=l._zod.def,d=Xm(o.entries);if(d.length===0){s.not={};return}d.every(h=>typeof h=="number")&&(s.type="number"),d.every(h=>typeof h=="string")&&(s.type="string"),s.enum=d},n1=(l,u,s,r)=>{const o=l._zod.def;if(o.values.length===0){s.not={};return}const d=[];for(const h of o.values)if(h===void 0){if(Jn(l,u,s,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof h=="bigint"){if(Jn(l,u,s,r,"BigInt literals cannot be represented in JSON Schema"))return;d.push(Number(h))}else d.push(h);if(d.length!==0)if(d.length===1){const h=d[0];s.type=h===null?"null":typeof h,u.target==="draft-04"||u.target==="openapi-3.0"?s.enum=[h]:s.const=h}else d.every(h=>typeof h=="number")&&(s.type="number"),d.every(h=>typeof h=="string")&&(s.type="string"),d.every(h=>typeof h=="boolean")&&(s.type="boolean"),d.every(h=>h===null)&&(s.type="null"),s.enum=d},l1=(l,u,s,r)=>{Jn(l,u,s,r,"Custom types cannot be represented in JSON Schema")},a1=(l,u,s,r)=>{Jn(l,u,s,r,"Transforms cannot be represented in JSON Schema")},u1=(l,u,s,r)=>{const o=s,d=l._zod.def,{minimum:h,maximum:y}=l._zod.bag;typeof h=="number"&&(o.minItems=h),typeof y=="number"&&(o.maxItems=y),o.type="array",o.items=Ye(d.element,u,{...r,path:[...r.path,"items"]})};function ki(l){const u=l._zod.def;return u.type==="pipe"&&u.in._zod.traits.has("$ZodTransform")?ki(u.out):u.type==="catch"?ki(u.innerType):l._zod.optin}const i1=(l,u,s,r)=>{const o=s,d=l._zod.def,h=d.shape;if(Object.getOwnPropertySymbols(h).length&&Jn(l,u,o,r,"Symbol keys cannot be represented in JSON Schema"))return;o.type="object",o.properties={};for(const z in h)dt(o.properties,z,Ye(h[z],u,{...r,path:[...r.path,"properties",z]}));const g=new Set(Object.keys(h)),p=new Set([...g].filter(z=>{const N=d.shape[z];return u.io==="input"?ki(N)===void 0:N._zod.optout===void 0}));p.size>0&&(o.required=Array.from(p)),d.catchall?._zod.def.type==="never"?o.additionalProperties=!1:d.catchall?d.catchall&&(o.additionalProperties=Ye(d.catchall,u,{...r,path:[...r.path,"additionalProperties"]})):u.io==="output"&&(o.additionalProperties=!1)},c1=(l,u,s,r)=>{const o=l._zod.def,d=o.inclusive===!1,h=o.options.map((y,g)=>Ye(y,u,{...r,path:[...r.path,d?"oneOf":"anyOf",g]}));d?s.oneOf=h:s.anyOf=h},r1=(l,u,s,r)=>{const o=l._zod.def,d=Ye(o.left,u,{...r,path:[...r.path,"allOf",0]}),h=Ye(o.right,u,{...r,path:[...r.path,"allOf",1]}),y=p=>"allOf"in p&&Object.keys(p).length===1,g=[...y(d)?d.allOf:[d],...y(h)?h.allOf:[h]];s.allOf=g,u.intersections.push(g)};function Zs(l,u,s){if(u.$ref){if(s.has(u))return u;s.add(u);const B=l.get(u)?.def;if(!B)return u;const X=Zs(l,B,s);return X===B?u:X}for(const B of["anyOf","oneOf"]){const X=u[B];if(!Array.isArray(X))continue;const J=X.map(fe=>Zs(l,fe,s));J.some((fe,Re)=>fe!==X[Re])&&(u={...u,[B]:J})}const r=Array.isArray(u.type)?u.type:[u.type],o=!r.includes("string")&&r.some(B=>B==="number"||B==="integer"),d=u.enum??(u.const!==void 0?[u.const]:void 0);if(!o&&!d?.some(B=>typeof B=="number"))return u;const{minimum:h,maximum:y,exclusiveMinimum:g,exclusiveMaximum:p,multipleOf:z,format:N,id:w,...C}=u;return C.enum?C.enum=C.enum.map(B=>typeof B=="number"?String(B):B):typeof C.const=="number"&&(C.const=String(C.const)),o&&(C.type="string",d||(C.pattern=(r.includes("number")?Xs:np).source)),C}const ws=new WeakMap;function s1(l){const u=new Map;for(const r of l.seen.values())r.def&&!u.has(r.schema)&&u.set(r.schema,r);const s=new Map;for(const r of ws.get(l)??[]){const o=l.seen.get(r),d=(o?.def??o?.schema)?.propertyNames;if(!d||d===!0||s.has(d))continue;const h=Zs(u,d,new Set);h!==d&&s.set(d,h)}if(s.size)for(const r of l.seen.values())for(const o of[r.schema,r.def]){const d=o&&s.get(o.propertyNames);d&&(o.propertyNames=d)}}const o1=(l,u,s,r)=>{const o=s,d=l._zod.def;o.type="object";const h=d.keyType,g=h._zod.bag?.patterns;if(d.mode==="loose"&&g&&g.size>0){const N=Ye(d.valueType,u,{...r,path:[...r.path,"patternProperties","*"]});o.patternProperties={};for(const w of g)dt(o.patternProperties,w.source,N)}else{if(u.target==="draft-07"||u.target==="draft-2020-12"){o.propertyNames=Ye(d.keyType,u,{...r,path:[...r.path,"propertyNames"]});let N=ws.get(u);N||(N=[],ws.set(u,N),u.deferred.push(()=>s1(u))),N.push(l)}o.additionalProperties=Ye(d.valueType,u,{...r,path:[...r.path,"additionalProperties"]})}const p=h._zod.values,z=u.io==="input"&&ki(d.valueType)!==void 0;if(p&&!d.partial&&!z){const N=[...p].filter(w=>typeof w=="string"||typeof w=="number");N.length>0&&(o.required=N.map(String))}},f1=(l,u,s,r)=>{const o=l._zod.def,d=Ye(o.innerType,u,r),h=u.seen.get(l);u.target==="openapi-3.0"?(h.ref=o.innerType,s.nullable=!0):s.anyOf=[d,{type:"null"}]},d1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType},Ks=Symbol();function Op(l,u,s,r,o){let d=!1;const h=JSON.stringify(l,(y,g)=>typeof g!="bigint"?g:(d=!0,null));return d?(Jn(u,s,r,o,"BigInt defaults cannot be represented in JSON Schema"),Ks):JSON.parse(h)}const h1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType;const h=Op(o.defaultValue,l,u,s,r);h!==Ks&&(s.default=h)},m1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);if(d.ref=o.innerType,u.io!=="input")return;const h=Op(o.defaultValue,l,u,s,r);h!==Ks&&(s._prefault=h)},p1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType;let h;try{h=o.catchValue(void 0)}catch{Jn(l,u,s,r,"Dynamic catch values are not supported in JSON Schema");return}s.default=h},y1=(l,u,s,r)=>{const o=l._zod.def,d=o.in._zod.traits.has("$ZodTransform"),h=u.io==="input"?d?o.out:o.in:o.out;Ye(h,u,r);const y=u.seen.get(l);y.ref=h},g1=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType,s.readOnly=!0},Ap=(l,u,s,r)=>{const o=l._zod.def;Ye(o.innerType,u,r);const d=u.seen.get(l);d.ref=o.innerType},Bm=new WeakSet([Object.prototype,Error.prototype]);function Ci(l,u,s){Object.defineProperty(l,u,{configurable:!0,enumerable:!1,get(){const r=s(this);return Object.defineProperty(this,u,{value:r,configurable:!0,writable:!0}),r},set(r){Object.defineProperty(this,u,{value:r,configurable:!0,writable:!0})}})}const v1=(l,u)=>{Im.init(l,u),l.name="ZodError";const s=Object.getPrototypeOf(l);Bm.has(s)||(Bm.add(s),Ci(s,"format",r=>o=>Jv(r,o)),Ci(s,"flatten",r=>o=>Kv(r,o)),Ci(s,"addIssue",r=>o=>{r.issues.push(o),r.message=JSON.stringify(r.issues,js,2)}),Ci(s,"addIssues",r=>o=>{r.issues.push(...o),r.message=JSON.stringify(r.issues,js,2)}),Object.defineProperty(s,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},qt=M("ZodError",v1,void 0,{Parent:Error}),b1=Gs(qt),_1=Ls(qt),S1=Li(qt),z1=Xi(qt),E1=Iv(qt),T1=Pv(qt),O1=e0(qt),A1=t0(qt),N1=n0(qt),j1=l0(qt),x1=a0(qt),D1=u0(qt);function U1(){Xt.localeError||Ft(e_())}function Vi(){Xt.memoizer||Ft({memoizer:Wb()})}const je=M("ZodType",(l,u)=>(U1(),Ne.init(l,u),l.def=u,l.type=u.type,l),{check(...l){const u=this.def;return this.clone(Wn(u,{checks:[...u.checks??[],...l.map(s=>typeof s=="function"?{_zod:{check:s,def:{check:"custom"},onattach:[]}}:s)]}),{parent:!0})},with(...l){return this.check(...l)},clone(l,u){return In(this,l,u)},brand(){return this},register(l,u){return l.add(this,u),this},refine(l,u){return this.check(OS(l,u))},superRefine(l,u){return this.check(AS(l,u))},overwrite(l){return this.check(da(l))},optional(){return $m(this)},exactOptional(){return hS(this)},nullable(){return km(this)},nullish(){return $m(km(this))},nonoptional(l){return bS(this,l)},array(){return et(this)},or(l){return iS([this,l])},and(l){return rS(this,l)},transform(l){return Gm(this,dS(l))},default(l){return yS(this,l)},prefault(l){return vS(this,l)},catch(l){return SS(this,l)},pipe(l){return Gm(this,l)},readonly(){return TS(this)},describe(l){const u=this.clone();return su.add(u,{description:l}),u},meta(...l){if(l.length===0)return su.get(this);const u=this.clone();return su.add(u,l[0]),u},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(l,...u){return u.length===0?l(this):l(this,...u)},get"~standard"(){return Jm(this,"~standard",{...up(this),jsonSchema:{input:$i(this,"input"),output:$i(this,"output")}})},set"~standard"(l){oa(this,"~standard",l)},parse:function l(u,s){return b1(this,u,s,{callee:l})},parseAsync:async function l(u,s){return await _1(this,u,s,{callee:l})},safeParse(l,u){return S1(this,l,u)},async safeParseAsync(l,u){return z1(this,l,u)},get spa(){return this?.safeParseAsync},set spa(l){oa(this,"spa",l)},encode:function l(u,s){return E1(this,u,s,{callee:l})},decode:function l(u,s){return T1(this,u,s,{callee:l})},encodeAsync:async function l(u,s){return await O1(this,u,s,{callee:l})},decodeAsync:async function l(u,s){return await A1(this,u,s,{callee:l})},safeEncode(l,u){return N1(this,l,u)},safeDecode(l,u){return j1(this,l,u)},async safeEncodeAsync(l,u){return x1(this,l,u)},async safeDecodeAsync(l,u){return D1(this,l,u)},toJSONSchema(l){return K_(this,{})(l)},get description(){return su.get(this)?.description},get _def(){return this._zod.def}}),Np=M("_ZodString",(l,u)=>{Vs.init(l,u),je.init(l,u),l._zod.processJSONSchema=(r,o,d)=>F_(l,r,o);const s=l._zod.bag;l.format=s.format??null,l.minLength=s.minimum??null,l.maxLength=s.maximum??null},{regex(...l){return this.check(M_(...l))},includes(...l){return this.check(R_(...l))},startsWith(...l){return this.check(C_(...l))},endsWith(...l){return this.check(B_(...l))},min(...l){return this.check(Yi(...l))},max(...l){return this.check(vp(...l))},length(...l){return this.check(bp(...l))},nonempty(...l){return this.check(Yi(1,...l))},lowercase(l){return this.check(Z_(l))},uppercase(l){return this.check(w_(l))},trim(){return this.check(q_())},normalize(...l){return this.check(H_(...l))},toLowerCase(){return this.check(Y_())},toUpperCase(){return this.check($_())},slugify(){return this.check(k_())}}),M1=M("ZodString",(l,u)=>{Vs.init(l,u),Np.init(l,u)},{email(l){return this.check(a_(C1,l))},url(l){return this.check(yp(xp,l))},jwt(l){return this.check(E_(P1,l))},emoji(l){return this.check(s_(q1,l))},guid(l){return this.check(u_(B1,l))},uuid(l){return this.check(i_(ou,l))},uuidv4(l){return this.check(c_(ou,l))},uuidv6(l){return this.check(r_(ou,l))},uuidv7(l){return this.check(pp(ou,l))},nanoid(l){return this.check(o_(Y1,l))},cuid(l){return this.check(f_($1,l))},cuid2(l){return this.check(d_(k1,l))},ulid(l){return this.check(h_(G1,l))},base64(l){return this.check(__(F1,l))},base64url(l){return this.check(S_(W1,l))},xid(l){return this.check(m_(L1,l))},ksuid(l){return this.check(p_(X1,l))},ipv4(l){return this.check(y_(Q1,l))},ipv6(l){return this.check(g_(V1,l))},cidrv4(l){return this.check(v_(K1,l))},cidrv6(l){return this.check(b_(J1,l))},e164(l){return this.check(z_(I1,l))},datetime(l){return this.check(gp(jp,l))},date(l){return this.check(T_(Z1,l))},time(l){return this.check(O_(w1,l))},duration(l){return this.check(A_(R1,l))}});function Se(l){return l_(M1,l)}const xe=M("ZodStringFormat",(l,u)=>{Ae.init(l,u),Np.init(l,u)}),jp=M("ZodISODateTime",(l,u)=>{sb.init(l,u),xe.init(l,u)}),Z1=M("ZodISODate",(l,u)=>{ob.init(l,u),xe.init(l,u)}),w1=M("ZodISOTime",(l,u)=>{fb.init(l,u),xe.init(l,u)}),R1=M("ZodISODuration",(l,u)=>{db.init(l,u),xe.init(l,u)}),C1=M("ZodEmail",(l,u)=>{J0.init(l,u),xe.init(l,u)}),B1=M("ZodGUID",(l,u)=>{V0.init(l,u),xe.init(l,u)}),ou=M("ZodUUID",(l,u)=>{K0.init(l,u),xe.init(l,u)});function du(l){return pp(ou,l)}const xp=M("ZodURL",(l,u)=>{tb.init(l,u),xe.init(l,u)});function H1(l){return yp(xp,l)}const q1=M("ZodEmoji",(l,u)=>{nb.init(l,u),xe.init(l,u)}),Y1=M("ZodNanoID",(l,u)=>{lb.init(l,u),xe.init(l,u)}),$1=M("ZodCUID",(l,u)=>{ab.init(l,u),xe.init(l,u)}),k1=M("ZodCUID2",(l,u)=>{ub.init(l,u),xe.init(l,u)}),G1=M("ZodULID",(l,u)=>{ib.init(l,u),xe.init(l,u)}),L1=M("ZodXID",(l,u)=>{cb.init(l,u),xe.init(l,u)}),X1=M("ZodKSUID",(l,u)=>{rb.init(l,u),xe.init(l,u)}),Q1=M("ZodIPv4",(l,u)=>{hb.init(l,u),xe.init(l,u)}),V1=M("ZodIPv6",(l,u)=>{pb.init(l,u),xe.init(l,u)}),K1=M("ZodCIDRv4",(l,u)=>{yb.init(l,u),xe.init(l,u)}),J1=M("ZodCIDRv6",(l,u)=>{vb.init(l,u),xe.init(l,u)}),F1=M("ZodBase64",(l,u)=>{bb.init(l,u),xe.init(l,u)}),W1=M("ZodBase64URL",(l,u)=>{Sb.init(l,u),xe.init(l,u)}),I1=M("ZodE164",(l,u)=>{zb.init(l,u),xe.init(l,u)}),P1=M("ZodJWT",(l,u)=>{Tb.init(l,u),xe.init(l,u)}),Dp=M("ZodNumber",(l,u)=>{op.init(l,u),je.init(l,u),l._zod.processJSONSchema=(r,o,d)=>W_(l,r,o,d);const s=l._zod.bag;l.minValue=Math.max(s.minimum??Number.NEGATIVE_INFINITY,s.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,l.maxValue=Math.min(s.maximum??Number.POSITIVE_INFINITY,s.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,l.isInt=(s.format??"").includes("int")||Number.isSafeInteger(s.multipleOf??.5),l.isFinite=!0,l.format=s.format??null},{gt(l,u){return this.check(Mm(l,u))},gte(l,u){return this.check(As(l,u))},min(l,u){return this.check(As(l,u))},lt(l,u){return this.check(Um(l,u))},lte(l,u){return this.check(Os(l,u))},max(l,u){return this.check(Os(l,u))},int(l){return this.check(Hm(l))},safe(l){return this.check(Hm(l))},positive(l){return this.check(Mm(0,l))},nonnegative(l){return this.check(As(0,l))},negative(l){return this.check(Um(0,l))},nonpositive(l){return this.check(Os(0,l))},multipleOf(l,u){return this.check(Zm(l,u))},step(l,u){return this.check(Zm(l,u))},finite(){return this}});function Lt(l){return N_(Dp,l)}const eS=M("ZodNumberFormat",(l,u)=>{Ob.init(l,u),Dp.init(l,u)});function Hm(l){return j_(eS,l)}const tS=M("ZodBoolean",(l,u)=>{Ab.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>I_(l,s,r)});function Rs(l){return x_(tS,l)}const nS=M("ZodUnknown",(l,u)=>{Nb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>e1()});function qm(){return D_(nS)}const lS=M("ZodNever",(l,u)=>{jb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>P_(l,s,r)});function Up(l){return U_(lS,l)}const aS=M("ZodArray",(l,u)=>{Vi(),xb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>u1(l,s,r,o),l.element=u.element},{min(l,u){return this.check(Yi(l,u))},nonempty(l){return this.check(Yi(1,l))},max(l,u){return this.check(vp(l,u))},length(l,u){return this.check(bp(l,u))},unwrap(){return this.element}});function et(l,u){return G_(aS,l,u)}const Mp=M("ZodObject",(l,u)=>{Vi(),Mb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>i1(l,s,r,o),Yv(l,"shape",s=>s._zod.def.shape,!1)},{keyof(){return Fn(Object.keys(this._zod.def.shape))},catchall(l){return this.clone({...this._zod.def,catchall:l})},passthrough(){return this.clone({...this._zod.def,catchall:qm()})},loose(){return this.clone({...this._zod.def,catchall:qm()})},strict(){return this.clone({...this._zod.def,catchall:Up()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(l){return xv(this,l)},safeExtend(l){return Dv(this,l)},merge(l){return Uv(this,l)},pick(l){return Nv(this,l)},omit(l){return jv(this,l)},partial(...l){return fm(Zp,this,l[0])},exactPartial(...l){return fm(wp,this,l[0],"exactPartial")},required(...l){return Mv(Rp,this,l[0])}});function Bt(l,u){const s={type:"object",shape:l??{},...G(u)};return new Mp(s)}function _n(l,u){return new Mp({type:"object",shape:l,catchall:Up(),...G(u)})}const uS=M("ZodUnion",(l,u)=>{Zb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>c1(l,s,r,o),l.options=u.options});function iS(l,u){return new uS({type:"union",options:l,...G(u)})}const cS=M("ZodIntersection",(l,u)=>{wb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>r1(l,s,r,o)});function rS(l,u){return new cS({type:"intersection",left:l,right:u})}const Ym=M("ZodRecord",(l,u)=>{Vi(),Rb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>o1(l,s,r,o),l.keyType=u.keyType,l.valueType=u.valueType});function sS(l,u,s){return!u||!u._zod?new Ym({type:"record",keyType:Se(),valueType:l,...G(u)}):new Ym({type:"record",keyType:l,valueType:u,...G(s)})}const Cs=M("ZodEnum",(l,u)=>{Cb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(r,o,d)=>t1(l,r,o),l.enum=u.entries,l.options=Object.values(u.entries);const s=new Set(Object.keys(u.entries));l.extract=(r,o)=>{const d={};for(const h of r)if(s.has(h))d[h]=u.entries[h];else throw new Error(`Key ${h} not found in enum`);return new Cs({...u,checks:[],...G(o),entries:d})},l.exclude=(r,o)=>{const d={...u.entries};for(const h of r)if(s.has(h))delete d[h];else throw new Error(`Key ${h} not found in enum`);return new Cs({...u,checks:[],...G(o),entries:d})}});function Fn(l,u){const s=Array.isArray(l)?Object.fromEntries(l.map(r=>[r,r])):l;return new Cs({type:"enum",entries:s,...G(u)})}const oS=M("ZodLiteral",(l,u)=>{Bb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>n1(l,s,r,o),l.values=new Set(u.values),Object.defineProperty(l,"value",{get(){if(u.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return u.values[0]}})});function Js(l,u){return new oS({type:"literal",values:Array.isArray(l)?l:[l],...G(u)})}const fS=M("ZodTransform",(l,u)=>{Vi(),Hb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>a1(l,s,r,o),l._zod.parse=(s,r)=>{if(r.direction==="backward")throw new Fm(l.constructor.name);s.addIssue=d=>{if(typeof d=="string")s.issues.push(hu(d,s.value,u));else{const h=d;h.fatal&&(h.continue=!1),h.code??(h.code="custom"),"input"in h||(h.input=s.value),h.inst??(h.inst=l),s.issues.push(hu(h))}};const o=u.transform(s.value,s);return o instanceof Promise?o.then(d=>(s.value=d,s)):(s.value=o,s)}});function dS(l){return new fS({type:"transform",transform:l})}const Zp=M("ZodOptional",(l,u)=>{hp.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>Ap(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function $m(l){return new Zp({type:"optional",innerType:l})}const wp=M("ZodExactOptional",(l,u)=>{qb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>Ap(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function hS(l){return new wp({type:"optional",innerType:l})}const mS=M("ZodNullable",(l,u)=>{Yb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>f1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function km(l){return new mS({type:"nullable",innerType:l})}const pS=M("ZodDefault",(l,u)=>{$b.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>h1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType,l.removeDefault=l.unwrap});function yS(l,u){return new pS({type:"default",innerType:l,get defaultValue(){return typeof u=="function"?u():Vm(u)}})}const gS=M("ZodPrefault",(l,u)=>{kb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>m1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function vS(l,u){return new gS({type:"prefault",innerType:l,get defaultValue(){return typeof u=="function"?u():Vm(u)}})}const Rp=M("ZodNonOptional",(l,u)=>{Gb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>d1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function bS(l,u){return new Rp({type:"nonoptional",innerType:l,...G(u)})}const _S=M("ZodCatch",(l,u)=>{Lb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>p1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType,l.removeCatch=l.unwrap});function SS(l,u){return new _S({type:"catch",innerType:l,catchValue:typeof u=="function"?u:kv(u)})}const zS=M("ZodPipe",(l,u)=>{Xb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>y1(l,s,r,o),l.in=u.in,l.out=u.out});function Gm(l,u){return new zS({type:"pipe",in:l,out:u})}const ES=M("ZodReadonly",(l,u)=>{Qb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>g1(l,s,r,o),l.unwrap=()=>l._zod.def.innerType});function TS(l){return new ES({type:"readonly",innerType:l})}const Cp=M("ZodCustom",(l,u)=>{Vb.init(l,u),je.init(l,u),l._zod.processJSONSchema=(s,r,o)=>l1(l,s,r,o)});function OS(l,u={}){return L_(Cp,l,u)}function AS(l,u){return X_(l,u)}function NS(l,u={}){const s=new Cp({type:"custom",check:"custom",fn:r=>r instanceof l,abort:!0,...G(u)});return s._zod.bag.Class=l,s._zod.check=r=>{r.value instanceof l||r.issues.push({code:"invalid_type",expected:l.name,input:r.value,inst:s,path:[...s._zod.def.path??[]]})},s}function _l(l){return gp(jp,l)}const Vn=Se().regex(/^(0|[1-9][0-9]*)$/),fa=Vn.max(78),Ki=H1().refine(l=>{const u=new URL(l);return["http:","https:"].includes(u.protocol)&&!u.username&&!u.password},"Expected an HTTP(S) URL without credentials"),Qe=Se().min(1).max(256),Bp=sS(Se(),Se());Bt({url:Ki,method:Se().min(1).max(64),headers:Bp});Bt({status:Lt().int().min(100).max(599),headers:Bp,body:NS(Uint8Array).optional()});const jS=Bt({id:du(),ts:_l(),rail:Js("x402"),attemptedAt:_l().optional(),status:Fn(["observed","blocked"]),reason:Se().optional(),amount:fa,decimals:Lt().int().min(0).max(255),decimalsKnown:Rs(),asset:Qe,assetSymbol:Qe.optional(),network:Qe,payTo:Qe,payer:Qe.optional(),resource:Ki,host:Qe,txHash:Se().optional(),taskId:Qe.optional(),agentId:Qe.optional(),raw:Se(),paymentKey:Se().min(1),settlementStatus:Fn(["unknown","confirmed","failed"]).default("unknown"),settlement_unknown:Rs().default(!0)});Bt({id:du(),ts:_l(),paymentId:du(),attemptId:du().optional(),attemptedAt:_l().optional(),status:Fn(["unknown","confirmed","failed"]),txHash:Se().optional(),reason:Se().optional()});const xS=Bt({id:du(),ts:_l(),code:Fn(["parse_failed","settlement_unknown","tls_unmetered","storage_failed"]),resource:Se(),message:Se()});Bt({error:Js("blocked_by_taximeter"),reason:Se(),budget:fa.nullable(),spent:Vn,remaining:fa.nullable()});const bl=_n({amount:fa,asset:Qe,network:Qe.optional(),window:Fn(["1h","24h","7d","30d"]).optional()}),DS=_n({allowHosts:et(Qe).default([]),denyHosts:et(Qe).default([]),allowPayTo:et(Qe).default([]),maxSinglePayment:fa.nullable().default("1000000"),maxSingleAsset:Qe.default("USDC"),unknownAsset:Fn(["allow","deny"]).default("deny")}),US=_n({proxy:Lt().int().min(0).max(65535).default(8402),dashboard:Lt().int().min(0).max(65535).default(8403)});_n({budgets:_n({perTask:bl.nullable().default({amount:"5000000",asset:"USDC"}),perAgent:bl.nullable().default({amount:"50000000",asset:"USDC",window:"24h"}),global:bl.nullable().default({amount:"100000000",asset:"USDC",window:"24h"})}).prefault({}),policy:DS.prefault({}),ports:US.prefault({}),db:Se().min(1).default("~/.taximeter/ledger.db"),upstream:Ki.optional()});_n({budgets:_n({perTask:bl.partial().nullable().optional(),perAgent:bl.partial().nullable().optional(),global:bl.partial().nullable().optional()}).optional(),policy:_n({allowHosts:et(Qe).optional(),denyHosts:et(Qe).optional(),allowPayTo:et(Qe).optional(),maxSinglePayment:fa.nullable().optional(),maxSingleAsset:Qe.optional(),unknownAsset:Fn(["allow","deny"]).optional()}).optional(),ports:_n({proxy:Lt().int().min(0).max(65535).optional(),dashboard:Lt().int().min(0).max(65535).optional()}).optional(),db:Se().min(1).optional(),upstream:Ki.optional()});const Bs=Bt({network:Se(),asset:Se(),assetSymbol:Se().optional(),decimals:Lt().int(),decimalsKnown:Rs(),amount:Vn,confirmedAmount:Vn,unknownAmount:Vn});function MS(l,u){const s=BigInt(l).toString();if(u===0)return s;const r=s.padStart(u+1,"0");return`${r.slice(0,-u)}.${r.slice(-u)}`}const ZS="0.2.2",wS=Se().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/).parse(ZS),RS=jS.omit({raw:!0}),Ns=Bs.extend({key:Se().nullable()}),CS=Bt({version:Js(wS),generatedAt:_l(),totalEvents:Lt().int(),blockedEvents:Lt().int(),unknownEvents:Lt().int(),totals:et(Bs),events:et(RS),diagnostics:et(xS),groups:Bt({task:et(Ns),agent:et(Ns),host:et(Ns)}),hours:et(Bt({ts:_l(),totals:et(Bs)})),globalBudget:bl.nullable(),budgets:et(Bt({network:Se(),asset:Se(),limit:Vn,spent:Vn,remaining:Vn,window:Se().nullable()})),proxy:Bt({port:Lt().int(),upstream:Se().optional()})});function Ht(l){return`${l.network}/${l.asset.toLowerCase()}`}function At(l,u){return u.decimalsKnown?MS(l,u.decimals):`${l} atomic units`}function Hp(l,u){const s=BigInt(u);if(s<=0n)return"0";const r=BigInt(l)*10000n/s,o=r<0n?0n:r>10000n?10000n:r;return`${o/100n}.${(o%100n).toString().padStart(2,"0")}`}function mu(l){return l==="eip155:8453"?"Base":l==="eip155:84532"?"Base Sepolia":l==="eip155:1"?"Ethereum":l}function Ji(l){return l.assetSymbol??`${l.asset.slice(0,8)}…${l.asset.slice(-6)}`}function bn(l){return new Date(l).toISOString().slice(11,19)}function BS(l,u){const s=l.map(p=>({ts:p.ts,amount:p.totals.find(z=>Ht(z)===u)?.amount??"0"})),r=s.reduce((p,z)=>p+BigInt(z.amount),0n),o=s.reduce((p,z)=>BigInt(z.amount)>p?BigInt(z.amount):p,0n);let d=0n;const h=BigInt(Math.max(s.length-1,1)),y=BigInt(Math.max(s.length,1)),g=s.map((p,z)=>(d+=BigInt(p.amount),{...p,x:(32n+BigInt(z)*936n/h).toString(),y:(184n-(r>0n?d*132n/r:0n)).toString(),barX:(32n+BigInt(z)*936n/y).toString(),barWidth:(936n/y-7n).toString(),barHeight:(o>0n?BigInt(p.amount)*106n/o:0n).toString(),barY:(138n-(o>0n?BigInt(p.amount)*106n/o:0n)).toString()}));return{series:g,points:g.map(p=>`${p.x},${p.y}`).join(" "),sum:r.toString(),maximum:o.toString()}}const Lm=[{view:"now",label:"Now"},{view:"task",label:"By task"},{view:"agent",label:"By agent"},{view:"host",label:"By host"},{view:"timeline",label:"Timeline"},{view:"export",label:"Export"}];function Fs(){return v.jsxs("span",{className:"wordmark",children:[v.jsxs("span",{className:"mark","aria-hidden":"true",children:[v.jsx("i",{}),v.jsx("i",{}),v.jsx("i",{})]}),"taximeter"]})}function HS({state:l}){const u=`http://127.0.0.1:${l.proxy.port}`;return v.jsxs("section",{className:"empty-state","aria-label":"Getting started",children:[v.jsxs("div",{className:"empty-heading",children:[v.jsx("span",{className:"eyebrow",children:"READY WHEN YOU ARE"}),v.jsx("h2",{children:"Your next payment starts the ledger."}),v.jsx("p",{children:"Point your agent at the local proxy. Taximeter records each supported payment and checks its budget before the replay goes upstream."})]}),v.jsxs("div",{className:"connection-instructions",children:[v.jsx("span",{className:"eyebrow",children:"YOUR LOCAL PROXY"}),v.jsx("code",{children:u}),v.jsx("p",{children:l.proxy.upstream?v.jsxs(v.Fragment,{children:["Requests forward to ",v.jsx("strong",{children:l.proxy.upstream}),"."]}):v.jsxs(v.Fragment,{children:["Use this address with an HTTP-proxy-aware client. For an explicit API base URL, restart with ",v.jsx("code",{children:"--upstream"})," set to your API."]})}),v.jsxs("p",{className:"connection-limit",children:["HTTPS CONNECT passes through unmetered. Use an explicit upstream or the"," ",v.jsx("code",{children:"withMeter"})," SDK to inspect HTTPS payments."]})]}),v.jsxs("div",{className:"empty-footer",children:[v.jsx("span",{children:"No payments recorded"}),v.jsx("span",{children:"No keys. No custody. Everything stays local."})]})]})}function qS({event:l}){const u=l.status==="blocked"?"Blocked":l.settlementStatus==="confirmed"?"Settled":l.settlementStatus==="failed"?"Failed":"Unknown",s=l.status==="blocked"?"blocked":l.settlementStatus;return v.jsx("span",{className:`event-status status-${s}`,title:l.reason??(u==="Settled"?"Settlement reported by the upstream":u==="Unknown"?"Settlement unknown; budget remains reserved":void 0),children:u})}function YS({state:l}){return v.jsxs("section",{className:"ledger-section",children:[v.jsxs("div",{className:"section-heading",children:[v.jsx("div",{children:v.jsxs("h2",{children:["Live ledger ",v.jsxs("span",{className:"muted",children:["/ latest ",l.events.length]})]})}),v.jsx("span",{className:"table-note",children:"All assets · times in UTC"})]}),v.jsx("div",{className:"table-scroll",children:v.jsxs("table",{className:"event-table",children:[v.jsx("thead",{children:v.jsxs("tr",{children:[v.jsx("th",{scope:"col",children:"Time"}),v.jsx("th",{scope:"col",children:"Resource"}),v.jsx("th",{scope:"col",children:"Task / agent"}),v.jsx("th",{scope:"col",children:"Network"}),v.jsx("th",{scope:"col",className:"numeric",children:"Amount"}),v.jsx("th",{scope:"col",children:"Asset"}),v.jsx("th",{scope:"col",className:"status-cell",children:"Status"})]})}),v.jsx("tbody",{children:l.events.map(u=>v.jsxs("tr",{className:u.status==="blocked"?"blocked-row":void 0,children:[v.jsx("td",{className:"mono time-cell",title:u.ts,children:bn(u.ts)}),v.jsx("td",{className:"resource-cell",children:v.jsx("a",{href:u.resource,target:"_blank",rel:"noreferrer",title:u.resource,children:u.host})}),v.jsxs("td",{className:"attribution-cell",title:`Task: ${u.taskId??"Unattributed"}
101
101
  Agent: ${u.agentId??"Unattributed"}`,children:[v.jsx("span",{children:u.taskId??"Unattributed"}),u.agentId&&v.jsxs("span",{className:"secondary-label",children:[" / ",u.agentId]})]}),v.jsx("td",{className:"network-cell",children:mu(u.network)}),v.jsx("td",{className:"numeric mono",title:`${u.amount} atomic units`,children:At(u.amount,u)}),v.jsx("td",{title:`${u.network} / ${u.asset}`,className:"asset-cell",children:Ji(u)}),v.jsx("td",{className:"status-cell",children:v.jsx(qS,{event:u})})]},u.id))})]})}),v.jsx("p",{className:"ledger-footnote",children:"Settled means reported by the upstream. Unknown settlement remains reserved against the budget. Blocked attempts do not count as spend."})]})}function $S({state:l,active:u}){const s=u?l.budgets.find(p=>Ht(p)===Ht(u)):void 0,r=u??{decimals:l.globalBudget?.asset==="USDC"?6:0,decimalsKnown:l.globalBudget?.asset==="USDC"},o=s?.spent??u?.amount??"0",d=s?.limit??(u?void 0:l.globalBudget?.amount),h=s?.window??(u?void 0:l.globalBudget?.window),y=s?.remaining??d,g=d?Hp(o,d):"0";return v.jsxs("section",{className:"budget-hero","aria-label":"Current spend and budget",children:[v.jsxs("div",{className:"hero-value",children:[v.jsx("span",{className:"eyebrow",children:s||!u&&d?`BUDGET SPEND${h?` · ${h.toUpperCase()}`:""}`:"LEDGER TOTAL · ALL TIME"}),v.jsxs("div",{className:"hero-number mono",title:`${o} atomic units`,children:[At(o,r),v.jsx("span",{className:"hero-unit",children:u?.assetSymbol??(u?void 0:l.globalBudget?.asset)})]}),v.jsx("p",{children:u?`${mu(u.network)} · ${u.asset}`:"Waiting for the first supported payment"})]}),v.jsxs("div",{className:"budget-detail",children:[v.jsxs("div",{className:"budget-caption",children:[v.jsx("span",{children:d?"Active global budget":"No global budget for this asset"}),v.jsx("span",{className:"mono",children:d?`${At(d,r)} ${u?.assetSymbol??l.globalBudget?.asset??""}`:"Uncapped"})]}),v.jsx("div",{className:"budget-track",role:"img","aria-label":d?`${g}% of the active global budget used`:"No active budget meter",children:v.jsx("span",{style:{width:`${g}%`}})}),v.jsxs("div",{className:"budget-caption below",children:[v.jsx("span",{children:d&&y?v.jsxs(v.Fragment,{children:[v.jsx("strong",{className:"mono",children:At(y,r)})," remaining"]}):"Asset balances are never combined."}),v.jsx("span",{children:h?`Rolling ${h}`:"All time"})]}),v.jsx("p",{className:"scope-note",children:"Each network and token has its own balance."})]})]})}function kS({state:l,active:u}){return v.jsxs("div",{className:"totals-strip",children:[v.jsxs("span",{children:["Ledger total"," ",v.jsx("strong",{className:"mono",children:u?At(u.amount,u):"0"})]}),v.jsxs("span",{children:["Reported settled"," ",v.jsx("strong",{className:"mono",children:u?At(u.confirmedAmount,u):"0"})]}),v.jsxs("span",{children:["Settlement unknown"," ",v.jsx("strong",{className:"mono",children:u?At(u.unknownAmount,u):"0"})]}),v.jsxs("span",{className:"blocked-count",children:["Blocked ",v.jsx("strong",{className:"mono",children:l.blockedEvents})]})]})}function GS({state:l,active:u,field:s}){const[r,o]=vl.useState("highest"),d=l.groups[s].filter(g=>u&&Ht(g)===Ht(u)),h=[...d].sort((g,p)=>r==="name"?(g.key??"Unattributed").localeCompare(p.key??"Unattributed"):BigInt(g.amount)===BigInt(p.amount)?(g.key??"").localeCompare(p.key??""):(BigInt(g.amount)>BigInt(p.amount)?-1:1)*(r==="lowest"?-1:1)),y=d.reduce((g,p)=>BigInt(p.amount)>g?BigInt(p.amount):g,0n).toString();return v.jsxs("section",{className:"group-section",children:[v.jsxs("div",{className:"section-heading",children:[v.jsxs("h2",{children:["Spend by ",s]}),v.jsxs("span",{className:"table-note",children:["All time · ",d.length," ",s,d.length===1?"":"s"]})]}),d.length?v.jsx("div",{className:"table-scroll",children:v.jsxs("table",{className:"group-table",children:[v.jsx("thead",{children:v.jsxs("tr",{children:[v.jsx("th",{scope:"col",children:v.jsxs("button",{type:"button",onClick:()=>o("name"),children:[s==="task"?"Task":s==="agent"?"Agent":"Host"," ",r==="name"?"↓":"↕"]})}),v.jsx("th",{scope:"col",children:"Proportion"}),v.jsx("th",{scope:"col",className:"numeric",children:v.jsxs("button",{type:"button",onClick:()=>o(r==="highest"?"lowest":"highest"),children:["Spend ",r==="highest"?"↓":r==="lowest"?"↑":"↕"]})}),v.jsx("th",{scope:"col",className:"numeric",children:"Unknown"})]})}),v.jsx("tbody",{children:h.map(g=>v.jsxs("tr",{children:[v.jsx("td",{className:"group-name",children:g.key??"Unattributed"}),v.jsx("td",{className:"group-bar-cell",children:v.jsx("div",{className:"group-bar",children:v.jsx("span",{style:{width:`${Hp(g.amount,y)}%`}})})}),v.jsxs("td",{className:"numeric mono",children:[At(g.amount,g)," ",v.jsx("span",{className:"muted",children:g.assetSymbol})]}),v.jsx("td",{className:"numeric mono muted",children:At(g.unknownAmount,g)})]},`${g.key}/${Ht(g)}`))})]})}):v.jsxs("div",{className:"quiet-empty",children:[v.jsx("h3",{children:"No spend attributed yet."}),v.jsx("p",{children:"Payments will appear here as your agent uses the proxy or SDK."})]}),v.jsxs("p",{className:"ledger-footnote",children:["Bars compare ",u?Ji(u):"one asset"," on"," ",u?mu(u.network):"one network"," only. Missing labels appear as Unattributed."]})]})}function LS({state:l,active:u}){const s=BS(l.hours,u?Ht(u):""),r=s.series[0],o=s.series.at(-1),d=u?`${At(s.sum,u)} ${u.assetSymbol??""}`:"0",h=u?`${At(s.maximum,u)} ${u.assetSymbol??""}`:"0";return v.jsxs("section",{className:"timeline-section",children:[v.jsxs("div",{className:"section-heading",children:[v.jsx("h2",{children:"Spend over time"}),v.jsx("span",{className:"table-note",children:"Trailing 24 hours · UTC"})]}),v.jsxs("div",{className:"chart-heading",children:[v.jsx("h3",{children:"Cumulative spend"}),v.jsx("span",{className:"mono",children:d})]}),v.jsx("div",{className:"chart-scroll",children:v.jsxs("svg",{className:"chart",viewBox:"0 0 1000 224",role:"img","aria-label":`Cumulative spend over the trailing 24 hours: ${d}`,children:[v.jsx("title",{children:"Cumulative spend over the trailing 24 hours"}),v.jsx("line",{x1:"32",x2:"968",y1:"184",y2:"184",className:"chart-rule"}),v.jsx("line",{x1:"32",x2:"968",y1:"118",y2:"118",className:"chart-grid"}),v.jsx("line",{x1:"32",x2:"968",y1:"52",y2:"52",className:"chart-grid"}),v.jsx("text",{x:"32",y:"26",children:"0"}),v.jsx("text",{x:"968",y:"26",textAnchor:"end",children:d}),s.points&&v.jsx("polyline",{points:s.points,className:"sparkline"}),o&&v.jsx("circle",{cx:o.x,cy:o.y,r:"4",className:"chart-dot"}),v.jsx("text",{x:"32",y:"213",children:r?`${r.ts.slice(5,10)} ${bn(r.ts).slice(0,5)}`:"Start"}),v.jsx("text",{x:"968",y:"213",textAnchor:"end",children:o?`${o.ts.slice(5,10)} ${bn(o.ts).slice(0,5)}`:"Now"})]})}),v.jsxs("div",{className:"chart-heading hourly-heading",children:[v.jsx("h3",{children:"Spend per hour"}),v.jsxs("span",{className:"muted",children:["Peak ",v.jsx("strong",{className:"mono",children:h})]})]}),v.jsx("div",{className:"chart-scroll",children:v.jsxs("svg",{className:"chart hourly-chart",viewBox:"0 0 1000 176",role:"img","aria-label":`Hourly spend for the trailing 24 hours. Peak: ${h}`,children:[v.jsx("title",{children:"Spend per hour"}),v.jsx("line",{x1:"32",x2:"968",y1:"138",y2:"138",className:"chart-rule"}),s.series.map(y=>v.jsx("rect",{x:y.barX,y:y.barY,width:y.barWidth,height:y.barHeight,className:"hour-bar",children:v.jsxs("title",{children:[bn(y.ts).slice(0,5)," UTC: ",u?At(y.amount,u):"0"]})},y.ts)),v.jsx("text",{x:"32",y:"165",children:r?`${bn(r.ts).slice(0,5)} UTC`:"Start"}),v.jsx("text",{x:"968",y:"165",textAnchor:"end",children:o?`${bn(o.ts).slice(0,5)} UTC`:"Now"})]})}),v.jsx("p",{className:"ledger-footnote",children:"Includes reported settled and unresolved authorizations. Blocked attempts and known failed settlements are excluded. Hourly totals use the payment's latest attempt time."})]})}function XS({state:l}){return v.jsxs("section",{className:"export-section",children:[v.jsxs("div",{className:"section-heading",children:[v.jsx("h2",{children:"A statement you can keep."}),v.jsx("span",{className:"table-note",children:"All events · all assets"})]}),v.jsx("p",{className:"section-intro",children:"Download the local ledger with exact amounts and explicit settlement status. Assets and networks stay separate in every format."}),v.jsxs("div",{className:"export-options",children:[v.jsxs("a",{className:"export-option",href:"/api/export?format=csv",download:!0,children:[v.jsx("span",{className:"eyebrow",children:"FOR SPREADSHEETS"}),v.jsxs("strong",{children:["CSV"," ",v.jsx("span",{className:"download-arrow","aria-hidden":"true",children:"↗"})]}),v.jsx("span",{children:"One event per row. Atomic integer amounts."}),v.jsx("span",{className:"download-label",children:"Download CSV"})]}),v.jsxs("a",{className:"export-option",href:"/api/export?format=json",download:!0,children:[v.jsx("span",{className:"eyebrow",children:"FOR YOUR TOOLS"}),v.jsxs("strong",{children:["JSON"," ",v.jsx("span",{className:"download-arrow","aria-hidden":"true",children:"↗"})]}),v.jsx("span",{children:"Event history, totals, and audit payloads."}),v.jsx("span",{className:"download-label",children:"Download JSON"})]}),v.jsxs("a",{className:"export-option",href:"/api/export?format=invoice",download:!0,children:[v.jsx("span",{className:"eyebrow",children:"FOR YOUR RECORDS"}),v.jsxs("strong",{children:["Invoice"," ",v.jsx("span",{className:"download-arrow","aria-hidden":"true",children:"↗"})]}),v.jsx("span",{children:"Printable HTML. Open it to save as PDF."}),v.jsx("span",{className:"download-label",children:"Download invoice"})]})]}),v.jsxs("div",{className:"statement-preview",children:[v.jsxs("div",{className:"preview-heading",children:[v.jsx(Fs,{}),v.jsx("span",{children:"STATEMENT PREVIEW"})]}),v.jsxs("div",{className:"preview-summary",children:[v.jsxs("span",{children:["Ledger entries ",v.jsx("strong",{className:"mono",children:l.totalEvents})]}),v.jsxs("span",{children:["Blocked attempts ",v.jsx("strong",{className:"mono",children:l.blockedEvents})]}),v.jsxs("span",{children:["Unknown settlement ",v.jsx("strong",{className:"mono",children:l.unknownEvents})]})]}),v.jsx("div",{className:"table-scroll",children:v.jsxs("table",{children:[v.jsx("thead",{children:v.jsxs("tr",{children:[v.jsx("th",{scope:"col",children:"Asset / network"}),v.jsx("th",{scope:"col",className:"numeric",children:"Ledger total"}),v.jsx("th",{scope:"col",className:"numeric",children:"Atomic units"})]})}),v.jsx("tbody",{children:l.totals.length?l.totals.map(u=>v.jsxs("tr",{children:[v.jsxs("td",{children:[v.jsx("strong",{children:Ji(u)}),v.jsxs("span",{className:"secondary-label",children:[" · ",mu(u.network)]}),v.jsx("small",{className:"contract-address",children:u.asset})]}),v.jsx("td",{className:"numeric mono",children:At(u.amount,u)}),v.jsx("td",{className:"numeric mono",children:u.amount})]},Ht(u))):v.jsx("tr",{children:v.jsx("td",{colSpan:3,children:"No payments recorded."})})})]})}),v.jsx("p",{className:"ledger-footnote",children:"This preview shows totals. Downloads contain the full local ledger, including blocked attempts. The invoice is a spending record, not proof of on-chain settlement."})]})]})}function QS({state:l,connection:u="live",initialView:s="now"}){const[r,o]=vl.useState(s),[d,h]=vl.useState(""),y=l.totals.find(p=>Ht(p)===d)??l.totals[0],g=Lm.find(p=>p.view===r)?.label??"Now";return v.jsxs("div",{className:"app-shell",children:[v.jsxs("header",{className:"masthead",children:[v.jsxs("div",{className:"brand",children:[v.jsx(Fs,{}),v.jsx("span",{className:"brand-description",children:"A taximeter for your AI agents."})]}),v.jsxs("div",{className:`connection-state connection-${u}`,role:"status",children:[v.jsx("span",{className:"live-dot","aria-hidden":"true"}),u==="live"?"Local · live":u==="offline"?"Connection lost":"Connecting"]})]}),v.jsxs("nav",{className:"navigation","aria-label":"Ledger views",children:[Lm.map(p=>v.jsx("button",{type:"button","aria-current":p.view===r?"page":void 0,onClick:()=>o(p.view),children:p.label},p.view)),v.jsx("span",{className:"nav-date",children:new Date(l.generatedAt).toLocaleDateString("en-GB",{day:"2-digit",month:"short",year:"numeric",timeZone:"UTC"})})]}),v.jsxs("main",{children:[v.jsxs("div",{className:"page-heading",children:[v.jsxs("div",{children:[v.jsx("span",{className:"eyebrow",children:"YOUR LOCAL LEDGER"}),v.jsx("h1",{children:g==="Now"?"Every small charge. In view.":g})]}),r!=="export"&&l.totals.length>0&&v.jsxs("div",{className:"asset-selector",children:[v.jsx("label",{htmlFor:"asset-selector",children:"Balance"}),v.jsx("select",{id:"asset-selector",value:y?Ht(y):"",onChange:p=>h(p.currentTarget.value),children:l.totals.map(p=>v.jsxs("option",{value:Ht(p),children:[Ji(p)," · ",mu(p.network),l.totals.some(z=>z!==p&&z.network===p.network&&z.assetSymbol===p.assetSymbol)?` · ${p.asset.slice(0,8)}…`:""]},Ht(p)))})]})]}),u==="offline"&&v.jsxs("p",{className:"connection-warning",role:"alert",children:["The local meter is unavailable. Showing the last update from"," ",bn(l.generatedAt)," UTC. Reconnecting automatically."]}),r==="now"?v.jsxs(v.Fragment,{children:[v.jsx($S,{state:l,active:y}),v.jsx(kS,{state:l,active:y}),l.events.length?v.jsx(YS,{state:l}):v.jsx(HS,{state:l})]}):r==="task"||r==="agent"||r==="host"?v.jsx(GS,{state:l,active:y,field:r},r):r==="timeline"?v.jsx(LS,{state:l,active:y}):v.jsx(XS,{state:l}),l.diagnostics.length>0&&v.jsxs("details",{className:"diagnostics",children:[v.jsxs("summary",{children:["Diagnostics ",v.jsx("span",{className:"mono",children:l.diagnostics.length}),v.jsx("span",{className:"muted",children:" · recent observations"})]}),v.jsx("ul",{children:l.diagnostics.map(p=>v.jsxs("li",{children:[v.jsx("span",{className:"mono",children:bn(p.ts)}),v.jsx("strong",{children:p.code.replaceAll("_"," ")}),v.jsx("span",{children:p.message})]},p.id))})]}),v.jsxs("footer",{className:"page-footer",children:[v.jsx("span",{children:"Local ledger · x402 exact EIP-3009"}),v.jsxs("span",{children:["HTTPS CONNECT is unmetered · updated ",bn(l.generatedAt)," UTC"]}),v.jsxs("span",{className:"mono",children:["v",l.version]})]})]})]})}function VS(){const[l,u]=vl.useState(null),[s,r]=vl.useState("connecting");return vl.useEffect(()=>{const o=new AbortController;let d=!1;async function h(){if(!d){d=!0;try{const g=await fetch("/api/summary",{signal:o.signal,cache:"no-store"});if(!g.ok)throw new Error("Local meter unavailable");const p=CS.parse(await g.json());o.signal.aborted||(u(p),r("live"))}catch{o.signal.aborted||r("offline")}finally{d=!1}}}h();const y=setInterval(()=>{h()},1e3);return()=>{clearInterval(y),o.abort()}},[]),l?v.jsx(QS,{state:l,connection:s}):v.jsxs("div",{className:"loading-shell",children:[v.jsx(Fs,{}),v.jsx("span",{className:"eyebrow",children:"YOUR LOCAL LEDGER"}),v.jsx("h1",{children:s==="offline"?"The meter is not responding.":"Opening your ledger."}),v.jsx("p",{children:s==="offline"?"Keep Taximeter running, then leave this page open. It reconnects automatically.":"Reading the local ledger. Your payment history stays on this machine."}),v.jsx("code",{children:"taximeter start"})]})}const qp=document.getElementById("root");if(!qp)throw new Error("Dashboard root is unavailable");vv.createRoot(qp).render(v.jsx(vl.StrictMode,{children:v.jsx(VS,{})}));
@@ -6,7 +6,7 @@
6
6
  <meta name="color-scheme" content="light dark" />
7
7
  <meta name="description" content="A taximeter for your AI agents. Your local payment ledger." />
8
8
  <title>Taximeter — Local ledger</title>
9
- <script type="module" crossorigin src="/assets/index-BFxfiuVt.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-DSVhxCXF.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="/assets/index-De4zKRDL.css">
11
11
  </head>
12
12
  <body>
package/docs/SDK.md CHANGED
@@ -8,7 +8,7 @@ Install the registry release with `npm install taximeter`. From a source checkou
8
8
  run `npm ci` and `npm run build`, then save the examples at the repository root.
9
9
  Their `import "taximeter"` statements resolve the package's own built exports.
10
10
  To try a local build in another project, run `npm pack`, copy the resulting
11
- tarball there, and use `npm install ./taximeter-0.2.0.tgz`.
11
+ tarball there, and use `npm install ./taximeter-0.2.2.tgz`.
12
12
 
13
13
  ## Try it locally
14
14
 
@@ -112,6 +112,11 @@ The local example and factory were exercised with ordinary loopback traffic;
112
112
  the integration tests use synthetic x402 authorizations. No wallet or genuine
113
113
  payment was used to validate these examples.
114
114
 
115
+ A separate [live testnet example](https://github.com/Ding808/taximeter/tree/main/examples/live-testnet)
116
+ validates the actual CLI proxy with the official client, Express server, and a
117
+ Base Sepolia transfer. That evidence covers explicit upstream mode; it does not
118
+ turn the SDK factory above into a tested live-wallet integration.
119
+
115
120
  ## Options and lifecycle
116
121
 
117
122
  `withMeter(fetchImpl, options)` returns a fetch-compatible function with a
@@ -144,12 +149,20 @@ wrappers after their requests finish, then let the owner close the ledger.
144
149
  Reusing a closed wrapper passes requests directly to the original transport
145
150
  without metering. Do not use a closed wrapper for later payments.
146
151
 
147
- Version 0.2.0 upgrades existing ledgers to schema version 2 when opening them.
152
+ Version 0.2.x upgrades existing ledgers to schema version 2 when opening them.
148
153
  Source events and outcomes remain unchanged; the added budget index is rebuilt
149
154
  from those records. Upgrade all writers together. Older 0.1.x clients cannot
150
155
  reopen a migrated database. `ledger.rebuildCache()` repairs the derived index
151
156
  from the append-only log inside a transaction.
152
157
 
158
+ From 0.2.1, opening an on-disk schema-1 ledger prints `Migrating ledger…` to stderr
159
+ and saves a standalone, WAL-aware backup at
160
+ `<database>.backup-v1-<unique suffix>/ledger.db` before upgrading. The saved path
161
+ is printed before the synchronous backfill begins. A backup failure aborts the
162
+ upgrade; a backfill failure rolls it back and retains the completed backup.
163
+ Fresh and schema-2 databases skip this step. See the [rollback instructions](../README.md#configuration)
164
+ before using a backup with an older client.
165
+
153
166
  ## Fetch behavior and limits
154
167
 
155
168
  - Use a Node fetch implementation that accepts standard `string`, `URL`, or
package/docs/demo.gif CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taximeter",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A taximeter for your AI agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",