broods 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright (c) 2026 Beeblast
3
+ Copyright (c) 2026 BeeBlast
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/account.d.ts CHANGED
@@ -76,7 +76,7 @@ declare const MODEL_PROVIDERS: {
76
76
  };
77
77
  readonly perplexity: {
78
78
  readonly label: "Perplexity";
79
- readonly modelPlaceholder: "sonar-pro";
79
+ readonly modelPlaceholder: "low";
80
80
  };
81
81
  readonly togetherai: {
82
82
  readonly label: "Together.ai";
@@ -612,7 +612,7 @@ declare const AGENT_POLICY_ACTIONS: readonly ["agent.invoke", "tool.call", "work
612
612
  * resource route. Roles carry the same PolicyDocument shape as agent policies;
613
613
  * each caller passes its action set to `normalizePolicyDocument`.
614
614
  */
615
- declare const API_POLICY_ACTIONS: readonly ["account:read", "account:write", "agents:read", "agents:write", "channels:read", "channels:write", "crons:read", "crons:write", "env:read", "env:write", "hooks:read", "hooks:write", "mcp:read", "mcp:write", "policies:read", "policies:write", "sandboxes:read", "sandboxes:write", "skills:read", "skills:write", "tools:read", "tools:write", "workspaces:read", "workspaces:write"];
615
+ declare const API_POLICY_ACTIONS: readonly ["account:read", "account:write", "agents:read", "agents:write", "channels:read", "channels:write", "crons:read", "crons:write", "env:read", "env:write", "hooks:read", "hooks:write", "mcp:read", "mcp:write", "policies:read", "policies:write", "sandboxes:read", "sandboxes:write", "skills:read", "skills:write", "workspaces:read", "workspaces:write"];
616
616
  type AgentPolicyAction = (typeof AGENT_POLICY_ACTIONS)[number];
617
617
  type ApiPolicyAction = (typeof API_POLICY_ACTIONS)[number];
618
618
  type PolicyAction = AgentPolicyAction | ApiPolicyAction;
@@ -731,6 +731,10 @@ interface Skill {
731
731
  * (`********`) on reads.
732
732
  */
733
733
 
734
+ /** A config PATCH body: objects merge key by key, `null` deletes a key, arrays and scalars replace. */
735
+ type ConfigPatch<T> = T extends readonly unknown[] ? T : T extends object ? {
736
+ [K in keyof T]?: ConfigPatch<T[K]> | null;
737
+ } : T;
734
738
  interface BroodsAccountClientOptions {
735
739
  /** Base URL of the broods gateway. Falls back to `BROODS_BASE_URL`, then `https://gateway.broods.app`. */
736
740
  baseUrl?: string;
@@ -778,7 +782,7 @@ interface AccountEnvVar {
778
782
  interface UpdateAgentInput {
779
783
  name?: string;
780
784
  description?: string | null;
781
- config?: unknown;
785
+ config?: ConfigPatch<AgentConfig>;
782
786
  }
783
787
  /** Public workspace record returned by the workspaces routes. */
784
788
  interface AccountWorkspace {
@@ -921,9 +925,11 @@ interface AccountMcp {
921
925
  stageId: string;
922
926
  name: string;
923
927
  description?: string;
924
- transport: "http" | "hosted";
928
+ transport: "http" | "hosted" | "machine";
925
929
  /** External servers only; a hosted row has no endpoint of its own. */
926
930
  url?: string;
931
+ /** Machine servers only: the machine sandbox (by name) whose daemon serves it. */
932
+ sandbox?: string;
927
933
  /** Hosted servers only: content hash of the uploaded bundle. */
928
934
  sha256?: string;
929
935
  headers?: Record<string, string>;
@@ -937,12 +943,14 @@ interface AccountMcp {
937
943
  }
938
944
  /**
939
945
  * Fields accepted by `POST /v1/mcp`: `url` connects, `bundle` uploads inline
940
- * (≤10 MB); a larger bundle goes through `uploadMcpBundle` first.
946
+ * (≤10 MB); a larger bundle goes through `uploadMcpBundle` first; `sandbox`
947
+ * runs it on that machine sandbox's daemon.
941
948
  */
942
949
  interface CreateMcpInput {
943
950
  name: string;
944
951
  description?: string;
945
952
  url?: string;
953
+ sandbox?: string;
946
954
  bundle?: string;
947
955
  bundleStorageId?: string;
948
956
  sha256?: string;
@@ -955,6 +963,7 @@ interface UpdateMcpInput {
955
963
  name?: string;
956
964
  description?: string;
957
965
  url?: string;
966
+ sandbox?: string;
958
967
  bundle?: string;
959
968
  bundleStorageId?: string;
960
969
  sha256?: string;
@@ -1064,7 +1073,7 @@ declare class BroodsAccountClient {
1064
1073
  createAgent(input: {
1065
1074
  name: string;
1066
1075
  description?: string;
1067
- config: unknown;
1076
+ config: AgentConfig;
1068
1077
  }): Promise<CreateAgentResult>;
1069
1078
  getAgent(agentId: string): Promise<AccountAgent | null>;
1070
1079
  /** PATCH an agent. `config` deep-merges into the stored config; `null` leaves delete keys. Returns null when the agent is gone. */
@@ -1089,13 +1098,13 @@ declare class BroodsAccountClient {
1089
1098
  createWorkspace(input: {
1090
1099
  name: string;
1091
1100
  description?: string;
1092
- config?: unknown;
1101
+ config?: WorkspaceConfig;
1093
1102
  }): Promise<AccountWorkspace>;
1094
1103
  getWorkspace(workspaceId: string): Promise<AccountWorkspace | null>;
1095
1104
  updateWorkspace(workspaceId: string, patch: {
1096
1105
  name?: string;
1097
1106
  description?: string | null;
1098
- config?: unknown;
1107
+ config?: ConfigPatch<WorkspaceConfig>;
1099
1108
  }): Promise<AccountWorkspace | null>;
1100
1109
  deleteWorkspace(workspaceId: string): Promise<boolean>;
1101
1110
  /** Flat listing of every file in the workspace's S3-backed filesystem. Returns [] when the workspace is gone. */
@@ -1108,22 +1117,22 @@ declare class BroodsAccountClient {
1108
1117
  contentBase64: string;
1109
1118
  contentType?: string;
1110
1119
  }): Promise<WorkspaceFileEntry>;
1111
- /** Rename a workspace file or folder. Returns false when the workspace or source path is gone. */
1112
- renameWorkspaceFile(workspaceId: string, path: string, newPath: string): Promise<boolean>;
1113
- /** Delete a workspace file or folder. Returns false when the workspace or path is gone. */
1114
- deleteWorkspaceFile(workspaceId: string, path: string): Promise<boolean>;
1120
+ /** Rename a workspace file or folder. Returns how many objects moved; throws when the workspace or source path is gone. */
1121
+ renameWorkspaceFile(workspaceId: string, path: string, newPath: string): Promise<number>;
1122
+ /** Delete a workspace file or folder. Returns how many objects were deleted, 0 when the workspace or path is gone. */
1123
+ deleteWorkspaceFile(workspaceId: string, path: string): Promise<number>;
1115
1124
  listSandboxes(): Promise<AccountSandbox[]>;
1116
1125
  createSandbox(input: {
1117
1126
  name: string;
1118
1127
  description?: string;
1119
- config?: unknown;
1128
+ config?: SandboxConfig;
1120
1129
  }): Promise<AccountSandbox>;
1121
1130
  getSandbox(sandboxId: string): Promise<AccountSandbox | null>;
1122
- /** PATCH a sandbox config. `config` fully replaces the stored config. Returns null when the sandbox is gone. */
1131
+ /** PATCH a sandbox config. `config` deep-merges into the stored config; `null` leaves delete keys. Returns null when the sandbox is gone. */
1123
1132
  updateSandbox(sandboxId: string, patch: {
1124
1133
  name?: string;
1125
1134
  description?: string | null;
1126
- config?: unknown;
1135
+ config?: ConfigPatch<SandboxConfig>;
1127
1136
  }): Promise<AccountSandbox | null>;
1128
1137
  deleteSandbox(sandboxId: string): Promise<boolean>;
1129
1138
  /** Suspend a persistent sandbox reservation. Throws on 404/403/409 (missing sandbox, foreign reservation, or unsupported provider). */
@@ -1216,4 +1225,4 @@ declare class BroodsAccountClient {
1216
1225
  }
1217
1226
 
1218
1227
  export { BroodsAccountApiError, BroodsAccountClient, envPlaceholder, resolveEnvCredential };
1219
- export type { AccountAgent, AccountChannel, AccountEnvVar, AccountMcp, AccountPolicy, AccountRole, AccountSandbox, AccountWorkspace, AssumeRoleResult, BroodsAccount, BroodsAccountClientOptions, ChannelRecordConfig, CreateAgentResult, CreateMcpInput, DeleteAccountResult, McpOauthInput, RotateSecretResult, SandboxLifecycleResult, SandboxSnapshotResult, SandboxTerminalTicket, SkillUploadInput, StageScope, UpdateAgentInput, UpdateMcpInput, WorkspaceFileEntry };
1228
+ export type { AccountAgent, AccountChannel, AccountEnvVar, AccountMcp, AccountPolicy, AccountRole, AccountSandbox, AccountWorkspace, AssumeRoleResult, BroodsAccount, BroodsAccountClientOptions, ChannelRecordConfig, ConfigPatch, CreateAgentResult, CreateMcpInput, DeleteAccountResult, McpOauthInput, RotateSecretResult, SandboxLifecycleResult, SandboxSnapshotResult, SandboxTerminalTicket, SkillUploadInput, StageScope, UpdateAgentInput, UpdateMcpInput, WorkspaceFileEntry };
package/dist/account.js CHANGED
@@ -1 +1 @@
1
- import{m,Te,U,B}from"./chunk-h06c1tg3.js";export{m as BroodsAccountApiError,B as BroodsAccountClient,Te as envPlaceholder,U as resolveEnvCredential};
1
+ import{m,Oe,B,Z}from"./chunk-a09r7men.js";export{m as BroodsAccountApiError,Z as BroodsAccountClient,Oe as envPlaceholder,B as resolveEnvCredential};
@@ -0,0 +1,66 @@
1
+ var at,ke=Object.freeze({status:"aborted"});function Z(i,f,m){function h(v,b){if(!v._zod)Object.defineProperty(v,"_zod",{value:{def:b,constr:z,traits:new Set},enumerable:!1});if(v._zod.traits.has(i))return;v._zod.traits.add(i),f(v,b);let w=z.prototype,P=Object.keys(w);for(let O=0;O<P.length;O++){let T=P[O];if(!(T in v))v[T]=w[T].bind(v)}}let _=m?.Parent??Object;class g extends _{}Object.defineProperty(g,"name",{value:i});function z(v){var b;let w=m?.Parent?new g:this;h(w,v),(b=w._zod).deferred??(b.deferred=[]);for(let P of w._zod.deferred)P();return w}return Object.defineProperty(z,"init",{value:h}),Object.defineProperty(z,Symbol.hasInstance,{value:(v)=>{if(m?.Parent&&v instanceof m.Parent)return!0;return v?._zod?.traits?.has(i)}}),Object.defineProperty(z,"name",{value:i}),z}var yc=Symbol("zod_brand");class X extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class ye extends Error{constructor(i){super(`Encountered unidirectional transform during encode: ${i}`);this.name="ZodEncodeError"}}(at=globalThis).__zod_globalConfig??(at.__zod_globalConfig={});var _e=globalThis.__zod_globalConfig;function y(i){if(i)Object.assign(_e,i);return _e}function Fe(i){let f=Object.values(i).filter((h)=>typeof h==="number");return Object.entries(i).filter(([h,_])=>f.indexOf(+h)===-1).map(([h,_])=>_)}function de(i,f="|"){return i.map((m)=>pe(m)).join(f)}function $e(i,f){if(typeof f==="bigint")return f.toString();return f}function be(i){return{get value(){{let m=i();return Object.defineProperty(this,"value",{value:m}),m}throw Error("cached value already set")}}}function Ue(i){return i===null||i===void 0}function Me(i){let f=i.startsWith("^")?1:0,m=i.endsWith("$")?i.length-1:i.length;return i.slice(f,m)}function lt(i,f){let m=i/f,h=Math.round(m),_=Number.EPSILON*Math.max(Math.abs(m),1);if(Math.abs(m-h)<_)return 0;return m-h}var pt=Symbol("evaluating");function N(i,f,m){let h=void 0;Object.defineProperty(i,f,{get(){if(h===pt)return;if(h===void 0)h=pt,h=m();return h},set(_){Object.defineProperty(i,f,{value:_})},configurable:!0})}function ce(i,f,m){Object.defineProperty(i,f,{value:m,writable:!0,enumerable:!0,configurable:!0})}function Q(...i){let f={};for(let m of i){let h=Object.getOwnPropertyDescriptors(m);Object.assign(f,h)}return Object.defineProperties({},f)}function cr(i){return JSON.stringify(i)}function ft(i){return i.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var ur="captureStackTrace"in Error?Error.captureStackTrace:(...i)=>{};function ge(i){return typeof i==="object"&&i!==null&&!Array.isArray(i)}var dt=be(()=>{if(_e.jitless)return!1;if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(i){return!1}});function ue(i){if(ge(i)===!1)return!1;let f=i.constructor;if(f===void 0)return!0;if(typeof f!=="function")return!0;let m=f.prototype;if(ge(m)===!1)return!1;if(Object.prototype.hasOwnProperty.call(m,"isPrototypeOf")===!1)return!1;return!0}function ar(i){if(ue(i))return{...i};if(Array.isArray(i))return[...i];if(i instanceof Map)return new Map(i);if(i instanceof Set)return new Set(i);return i}var mt=new Set(["string","number","symbol"]);function ee(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Y(i,f,m){let h=new i._zod.constr(f??i._zod.def);if(!f||m?.parent)h._zod.parent=i;return h}function S(i){let f=i;if(!f)return{};if(typeof f==="string")return{error:()=>f};if(f?.message!==void 0){if(f?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");f.error=f.message}if(delete f.message,typeof f.error==="string")return{...f,error:()=>f.error};return f}function pe(i){if(typeof i==="bigint")return i.toString()+"n";if(typeof i==="string")return`"${i}"`;return`${i}`}function ht(i){return Object.keys(i).filter((f)=>i[f]._zod.optin==="optional"&&i[f]._zod.optout==="optional")}var _t={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-340282346638528860000000000000000000000,340282346638528860000000000000000000000],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function ei(i,f){let m=i._zod.def,h=m.checks;if(h&&h.length>0)throw Error(".pick() cannot be used on object schemas containing refinements");let g=Q(i._zod.def,{get shape(){let z={};for(let v in f){if(!(v in m.shape))throw Error(`Unrecognized key: "${v}"`);if(!f[v])continue;z[v]=m.shape[v]}return ce(this,"shape",z),z},checks:[]});return Y(i,g)}function ri(i,f){let m=i._zod.def,h=m.checks;if(h&&h.length>0)throw Error(".omit() cannot be used on object schemas containing refinements");let g=Q(i._zod.def,{get shape(){let z={...i._zod.def.shape};for(let v in f){if(!(v in m.shape))throw Error(`Unrecognized key: "${v}"`);if(!f[v])continue;delete z[v]}return ce(this,"shape",z),z},checks:[]});return Y(i,g)}function ti(i,f){if(!ue(f))throw Error("Invalid input to extend: expected a plain object");let m=i._zod.def.checks;if(m&&m.length>0){let g=i._zod.def.shape;for(let z in f)if(Object.getOwnPropertyDescriptor(g,z)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}let _=Q(i._zod.def,{get shape(){let g={...i._zod.def.shape,...f};return ce(this,"shape",g),g}});return Y(i,_)}function oi(i,f){if(!ue(f))throw Error("Invalid input to safeExtend: expected a plain object");let m=Q(i._zod.def,{get shape(){let h={...i._zod.def.shape,...f};return ce(this,"shape",h),h}});return Y(i,m)}function ni(i,f){if(i._zod.def.checks?.length)throw Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");let m=Q(i._zod.def,{get shape(){let h={...i._zod.def.shape,...f._zod.def.shape};return ce(this,"shape",h),h},get catchall(){return f._zod.def.catchall},checks:f._zod.def.checks??[]});return Y(i,m)}function si(i,f,m){let _=f._zod.def.checks;if(_&&_.length>0)throw Error(".partial() cannot be used on object schemas containing refinements");let z=Q(f._zod.def,{get shape(){let v=f._zod.def.shape,b={...v};if(m)for(let w in m){if(!(w in v))throw Error(`Unrecognized key: "${w}"`);if(!m[w])continue;b[w]=i?new i({type:"optional",innerType:v[w]}):v[w]}else for(let w in v)b[w]=i?new i({type:"optional",innerType:v[w]}):v[w];return ce(this,"shape",b),b},checks:[]});return Y(f,z)}function ii(i,f,m){let h=Q(f._zod.def,{get shape(){let _=f._zod.def.shape,g={..._};if(m)for(let z in m){if(!(z in g))throw Error(`Unrecognized key: "${z}"`);if(!m[z])continue;g[z]=new i({type:"nonoptional",innerType:_[z]})}else for(let z in _)g[z]=new i({type:"nonoptional",innerType:_[z]});return ce(this,"shape",g),g}});return Y(f,h)}function ae(i,f=0){if(i.aborted===!0)return!0;for(let m=f;m<i.issues.length;m++)if(i.issues[m]?.continue!==!0)return!0;return!1}function gt(i,f=0){if(i.aborted===!0)return!0;for(let m=f;m<i.issues.length;m++)if(i.issues[m]?.continue===!1)return!0;return!1}function te(i,f){return f.map((m)=>{var h;return(h=m).path??(h.path=[]),m.path.unshift(i),m})}function Le(i){return typeof i==="string"?i:i?.message}function G(i,f,m){let h=i.message?i.message:Le(i.inst?._zod.def?.error?.(i))??Le(f?.error?.(i))??Le(m.customError?.(i))??Le(m.localeError?.(i))??"Invalid input",{inst:_,continue:g,input:z,...v}=i;if(v.path??(v.path=[]),v.message=h,f?.reportInput)v.input=z;return v}function Je(i){if(Array.isArray(i))return"array";if(typeof i==="string")return"string";return"unknown"}function Ee(i){let f=typeof i;switch(f){case"number":return Number.isNaN(i)?"nan":"number";case"object":{if(i===null)return"null";if(Array.isArray(i))return"array";let m=i;if(m&&Object.getPrototypeOf(m)!==Object.prototype&&"constructor"in m&&m.constructor)return m.constructor.name}}return f}function le(...i){let[f,m,h]=i;if(typeof f==="string")return{message:f,code:"custom",input:m,inst:h};return{...f}}var xt=(i,f)=>{i.name="$ZodError",Object.defineProperty(i,"_zod",{value:i._zod,enumerable:!1}),Object.defineProperty(i,"issues",{value:f,enumerable:!1}),i.message=JSON.stringify(f,$e,2),Object.defineProperty(i,"toString",{value:()=>i.message,enumerable:!1})},Be=Z("$ZodError",xt),pr=Z("$ZodError",xt,{Parent:Error});function zt(i,f=(m)=>m.message){let m={},h=[];for(let _ of i.issues)if(_.path.length>0)m[_.path[0]]=m[_.path[0]]||[],m[_.path[0]].push(f(_));else h.push(f(_));return{formErrors:h,fieldErrors:m}}function vt(i,f=(m)=>m.message){let m={_errors:[]},h=(_,g=[])=>{for(let z of _.issues)if(z.code==="invalid_union"&&z.errors.length)z.errors.map((v)=>h({issues:v},[...g,...z.path]));else if(z.code==="invalid_key")h({issues:z.issues},[...g,...z.path]);else if(z.code==="invalid_element")h({issues:z.issues},[...g,...z.path]);else{let v=[...g,...z.path];if(v.length===0)m._errors.push(f(z));else{let b=m,w=0;while(w<v.length){let P=v[w];if(w!==v.length-1)b[P]=b[P]||{_errors:[]};else b[P]=b[P]||{_errors:[]},b[P]._errors.push(f(z));b=b[P],w++}}}};return h(i),m}function ci(i){let f=[],m=i.map((h)=>typeof h==="object"?h.key:h);for(let h of m)if(typeof h==="number")f.push(`[${h}]`);else if(typeof h==="symbol")f.push(`[${JSON.stringify(String(h))}]`);else if(/[^\w$]/.test(h))f.push(`[${JSON.stringify(h)}]`);else{if(f.length)f.push(".");f.push(h)}return f.join("")}function Ae(i){let f=[],m=[...i.issues].sort((h,_)=>(h.path??[]).length-(_.path??[]).length);for(let h of m)if(f.push(`✖ ${h.message}`),h.path?.length)f.push(` → at ${ci(h.path)}`);return f.join(`
2
+ `)}var Ve=(i)=>(f,m,h,_)=>{let g=h?{...h,async:!1}:{async:!1},z=f._zod.run({value:m,issues:[]},g);if(z instanceof Promise)throw new X;if(z.issues.length){let v=new(_?.Err??i)(z.issues.map((b)=>G(b,g,y())));throw ur(v,_?.callee),v}return z.value};var We=(i)=>async(f,m,h,_)=>{let g=h?{...h,async:!0}:{async:!0},z=f._zod.run({value:m,issues:[]},g);if(z instanceof Promise)z=await z;if(z.issues.length){let v=new(_?.Err??i)(z.issues.map((b)=>G(b,g,y())));throw ur(v,_?.callee),v}return z.value};var we=(i)=>(f,m,h)=>{let _=h?{...h,async:!1}:{async:!1},g=f._zod.run({value:m,issues:[]},_);if(g instanceof Promise)throw new X;return g.issues.length?{success:!1,error:new(i??Be)(g.issues.map((z)=>G(z,_,y())))}:{success:!0,data:g.value}},yt=we(pr),Ze=(i)=>async(f,m,h)=>{let _=h?{...h,async:!0}:{async:!0},g=f._zod.run({value:m,issues:[]},_);if(g instanceof Promise)g=await g;return g.issues.length?{success:!1,error:new i(g.issues.map((z)=>G(z,_,y())))}:{success:!0,data:g.value}},$t=Ze(pr),bt=(i)=>(f,m,h)=>{let _=h?{...h,direction:"backward"}:{direction:"backward"};return Ve(i)(f,m,_)};var wt=(i)=>(f,m,h)=>Ve(i)(f,m,h);var kt=(i)=>async(f,m,h)=>{let _=h?{...h,direction:"backward"}:{direction:"backward"};return We(i)(f,m,_)};var Zt=(i)=>async(f,m,h)=>We(i)(f,m,h);var Pt=(i)=>(f,m,h)=>{let _=h?{...h,direction:"backward"}:{direction:"backward"};return we(i)(f,m,_)};var St=(i)=>(f,m,h)=>we(i)(f,m,h);var Ot=(i)=>async(f,m,h)=>{let _=h?{...h,direction:"backward"}:{direction:"backward"};return Ze(i)(f,m,_)};var Et=(i)=>async(f,m,h)=>Ze(i)(f,m,h);var It=/^[cC][0-9a-z]{6,}$/,Tt=/^[0-9a-z]+$/,Nt=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,At=/^[0-9a-vA-V]{20}$/,jt=/^[A-Za-z0-9]{27}$/,Ct=/^[a-zA-Z0-9_-]{21}$/,Rt=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;var Dt=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,lr=(i)=>{if(!i)return/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/;return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${i}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`)};var Lt=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;var ai="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Ft(){return new RegExp(ai,"u")}var Ut=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Mt=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;var Jt=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Bt=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Vt=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,fr=/^[A-Za-z0-9_-]*$/;var Wt=/^https?$/,Kt=/^\+[1-9]\d{6,14}$/,Gt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",qt=new RegExp(`^${Gt}$`);function Yt(i){return typeof i.precision==="number"?i.precision===-1?"(?:[01]\\d|2[0-3]):[0-5]\\d":i.precision===0?"(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d":`(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\.\\d{${i.precision}}`:"(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?"}function Xt(i){return new RegExp(`^${Yt(i)}$`)}function Ht(i){let f=Yt({precision:i.precision}),m=["Z"];if(i.local)m.push("");if(i.offset)m.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");let h=`${f}(?:${m.join("|")})`;return new RegExp(`^${Gt}T(?:${h})$`)}var Qt=(i)=>{let f=i?`[\\s\\S]{${i?.minimum??0},${i?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${f}$`)};var eo=/^-?\d+$/,dr=/^-?\d+(?:\.\d+)?$/,ro=/^(?:true|false)$/i,to=/^null$/i;var oo=/^[^A-Z]*$/,no=/^[^a-z]*$/;var V=Z("$ZodCheck",(i,f)=>{var m;i._zod??(i._zod={}),i._zod.def=f,(m=i._zod).onattach??(m.onattach=[])}),so={number:"number",bigint:"bigint",object:"date"},mr=Z("$ZodCheckLessThan",(i,f)=>{V.init(i,f);let m=so[typeof f.value];i._zod.onattach.push((h)=>{let _=h._zod.bag,g=(f.inclusive?_.maximum:_.exclusiveMaximum)??Number.POSITIVE_INFINITY;if(f.value<g)if(f.inclusive)_.maximum=f.value;else _.exclusiveMaximum=f.value}),i._zod.check=(h)=>{if(f.inclusive?h.value<=f.value:h.value<f.value)return;h.issues.push({origin:m,code:"too_big",maximum:typeof f.value==="object"?f.value.getTime():f.value,input:h.value,inclusive:f.inclusive,inst:i,continue:!f.abort})}}),hr=Z("$ZodCheckGreaterThan",(i,f)=>{V.init(i,f);let m=so[typeof f.value];i._zod.onattach.push((h)=>{let _=h._zod.bag,g=(f.inclusive?_.minimum:_.exclusiveMinimum)??Number.NEGATIVE_INFINITY;if(f.value>g)if(f.inclusive)_.minimum=f.value;else _.exclusiveMinimum=f.value}),i._zod.check=(h)=>{if(f.inclusive?h.value>=f.value:h.value>f.value)return;h.issues.push({origin:m,code:"too_small",minimum:typeof f.value==="object"?f.value.getTime():f.value,input:h.value,inclusive:f.inclusive,inst:i,continue:!f.abort})}}),io=Z("$ZodCheckMultipleOf",(i,f)=>{V.init(i,f),i._zod.onattach.push((m)=>{var h;(h=m._zod.bag).multipleOf??(h.multipleOf=f.value)}),i._zod.check=(m)=>{if(typeof m.value!==typeof f.value)throw Error("Cannot mix number and bigint in multiple_of check.");if(typeof m.value==="bigint"?m.value%f.value===BigInt(0):lt(m.value,f.value)===0)return;m.issues.push({origin:typeof m.value,code:"not_multiple_of",divisor:f.value,input:m.value,inst:i,continue:!f.abort})}}),co=Z("$ZodCheckNumberFormat",(i,f)=>{V.init(i,f),f.format=f.format||"float64";let m=f.format?.includes("int"),h=m?"int":"number",[_,g]=_t[f.format];i._zod.onattach.push((z)=>{let v=z._zod.bag;if(v.format=f.format,v.minimum=_,v.maximum=g,m)v.pattern=eo}),i._zod.check=(z)=>{let v=z.value;if(m){if(!Number.isInteger(v)){z.issues.push({expected:h,format:f.format,code:"invalid_type",continue:!1,input:v,inst:i});return}if(!Number.isSafeInteger(v)){if(v>0)z.issues.push({input:v,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:i,origin:h,inclusive:!0,continue:!f.abort});else z.issues.push({input:v,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:i,origin:h,inclusive:!0,continue:!f.abort});return}}if(v<_)z.issues.push({origin:"number",input:v,code:"too_small",minimum:_,inclusive:!0,inst:i,continue:!f.abort});if(v>g)z.issues.push({origin:"number",input:v,code:"too_big",maximum:g,inclusive:!0,inst:i,continue:!f.abort})}});var uo=Z("$ZodCheckMaxLength",(i,f)=>{var m;V.init(i,f),(m=i._zod.def).when??(m.when=(h)=>{let _=h.value;return!Ue(_)&&_.length!==void 0}),i._zod.onattach.push((h)=>{let _=h._zod.bag.maximum??Number.POSITIVE_INFINITY;if(f.maximum<_)h._zod.bag.maximum=f.maximum}),i._zod.check=(h)=>{let _=h.value;if(_.length<=f.maximum)return;let z=Je(_);h.issues.push({origin:z,code:"too_big",maximum:f.maximum,inclusive:!0,input:_,inst:i,continue:!f.abort})}}),ao=Z("$ZodCheckMinLength",(i,f)=>{var m;V.init(i,f),(m=i._zod.def).when??(m.when=(h)=>{let _=h.value;return!Ue(_)&&_.length!==void 0}),i._zod.onattach.push((h)=>{let _=h._zod.bag.minimum??Number.NEGATIVE_INFINITY;if(f.minimum>_)h._zod.bag.minimum=f.minimum}),i._zod.check=(h)=>{let _=h.value;if(_.length>=f.minimum)return;let z=Je(_);h.issues.push({origin:z,code:"too_small",minimum:f.minimum,inclusive:!0,input:_,inst:i,continue:!f.abort})}}),po=Z("$ZodCheckLengthEquals",(i,f)=>{var m;V.init(i,f),(m=i._zod.def).when??(m.when=(h)=>{let _=h.value;return!Ue(_)&&_.length!==void 0}),i._zod.onattach.push((h)=>{let _=h._zod.bag;_.minimum=f.length,_.maximum=f.length,_.length=f.length}),i._zod.check=(h)=>{let _=h.value,g=_.length;if(g===f.length)return;let z=Je(_),v=g>f.length;h.issues.push({origin:z,...v?{code:"too_big",maximum:f.length}:{code:"too_small",minimum:f.length},inclusive:!0,exact:!0,input:h.value,inst:i,continue:!f.abort})}}),Se=Z("$ZodCheckStringFormat",(i,f)=>{var m,h;if(V.init(i,f),i._zod.onattach.push((_)=>{let g=_._zod.bag;if(g.format=f.format,f.pattern)g.patterns??(g.patterns=new Set),g.patterns.add(f.pattern)}),f.pattern)(m=i._zod).check??(m.check=(_)=>{if(f.pattern.lastIndex=0,f.pattern.test(_.value))return;_.issues.push({origin:"string",code:"invalid_format",format:f.format,input:_.value,...f.pattern?{pattern:f.pattern.toString()}:{},inst:i,continue:!f.abort})});else(h=i._zod).check??(h.check=()=>{})}),lo=Z("$ZodCheckRegex",(i,f)=>{Se.init(i,f),i._zod.check=(m)=>{if(f.pattern.lastIndex=0,f.pattern.test(m.value))return;m.issues.push({origin:"string",code:"invalid_format",format:"regex",input:m.value,pattern:f.pattern.toString(),inst:i,continue:!f.abort})}}),fo=Z("$ZodCheckLowerCase",(i,f)=>{f.pattern??(f.pattern=oo),Se.init(i,f)}),mo=Z("$ZodCheckUpperCase",(i,f)=>{f.pattern??(f.pattern=no),Se.init(i,f)}),ho=Z("$ZodCheckIncludes",(i,f)=>{V.init(i,f);let m=ee(f.includes),h=new RegExp(typeof f.position==="number"?`^.{${f.position}}${m}`:m);f.pattern=h,i._zod.onattach.push((_)=>{let g=_._zod.bag;g.patterns??(g.patterns=new Set),g.patterns.add(h)}),i._zod.check=(_)=>{if(_.value.includes(f.includes,f.position))return;_.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:f.includes,input:_.value,inst:i,continue:!f.abort})}}),_o=Z("$ZodCheckStartsWith",(i,f)=>{V.init(i,f);let m=new RegExp(`^${ee(f.prefix)}.*`);f.pattern??(f.pattern=m),i._zod.onattach.push((h)=>{let _=h._zod.bag;_.patterns??(_.patterns=new Set),_.patterns.add(m)}),i._zod.check=(h)=>{if(h.value.startsWith(f.prefix))return;h.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:f.prefix,input:h.value,inst:i,continue:!f.abort})}}),go=Z("$ZodCheckEndsWith",(i,f)=>{V.init(i,f);let m=new RegExp(`.*${ee(f.suffix)}$`);f.pattern??(f.pattern=m),i._zod.onattach.push((h)=>{let _=h._zod.bag;_.patterns??(_.patterns=new Set),_.patterns.add(m)}),i._zod.check=(h)=>{if(h.value.endsWith(f.suffix))return;h.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:f.suffix,input:h.value,inst:i,continue:!f.abort})}});var xo=Z("$ZodCheckOverwrite",(i,f)=>{V.init(i,f),i._zod.check=(m)=>{m.value=f.tx(m.value)}});class _r{constructor(i=[]){if(this.content=[],this.indent=0,this)this.args=i}indented(i){this.indent+=1,i(this),this.indent-=1}write(i){if(typeof i==="function"){i(this,{execution:"sync"}),i(this,{execution:"async"});return}let m=i.split(`
3
+ `).filter((g)=>g),h=Math.min(...m.map((g)=>g.length-g.trimStart().length)),_=m.map((g)=>g.slice(h)).map((g)=>" ".repeat(this.indent*2)+g);for(let g of _)this.content.push(g)}compile(){let i=Function,f=this?.args,h=[...(this?.content??[""]).map((_)=>` ${_}`)];return new i(...f,h.join(`
4
+ `))}}var vo={major:4,minor:4,patch:3};var C=Z("$ZodType",(i,f)=>{var m;i??(i={}),i._zod.def=f,i._zod.bag=i._zod.bag||{},i._zod.version=vo;let h=[...i._zod.def.checks??[]];if(i._zod.traits.has("$ZodCheck"))h.unshift(i);for(let _ of h)for(let g of _._zod.onattach)g(i);if(h.length===0)(m=i._zod).deferred??(m.deferred=[]),i._zod.deferred?.push(()=>{i._zod.run=i._zod.parse});else{let _=(z,v,b)=>{let w=ae(z),P;for(let O of v){if(O._zod.def.when){if(gt(z))continue;if(!O._zod.def.when(z))continue}else if(w)continue;let T=z.issues.length,E=O._zod.check(z);if(E instanceof Promise&&b?.async===!1)throw new X;if(P||E instanceof Promise)P=(P??Promise.resolve()).then(async()=>{if(await E,z.issues.length===T)return;if(!w)w=ae(z,T)});else{if(z.issues.length===T)continue;if(!w)w=ae(z,T)}}if(P)return P.then(()=>z);return z},g=(z,v,b)=>{if(ae(z))return z.aborted=!0,z;let w=_(v,h,b);if(w instanceof Promise){if(b.async===!1)throw new X;return w.then((P)=>i._zod.parse(P,b))}return i._zod.parse(w,b)};i._zod.run=(z,v)=>{if(v.skipChecks)return i._zod.parse(z,v);if(v.direction==="backward"){let w=i._zod.parse({value:z.value,issues:[]},{...v,skipChecks:!0});if(w instanceof Promise)return w.then((P)=>g(P,z,v));return g(w,z,v)}let b=i._zod.parse(z,v);if(b instanceof Promise){if(v.async===!1)throw new X;return b.then((w)=>_(w,h,v))}return _(b,h,v)}}N(i,"~standard",()=>({validate:(_)=>{try{let g=yt(i,_);return g.success?{value:g.data}:{issues:g.error?.issues}}catch(g){return $t(i,_).then((z)=>z.success?{value:z.data}:{issues:z.error?.issues})}},vendor:"zod",version:1}))}),Ye=Z("$ZodString",(i,f)=>{C.init(i,f),i._zod.pattern=[...i?._zod.bag?.patterns??[]].pop()??Qt(i._zod.bag),i._zod.parse=(m,h)=>{if(f.coerce)try{m.value=String(m.value)}catch(_){}if(typeof m.value==="string")return m;return m.issues.push({expected:"string",code:"invalid_type",input:m.value,inst:i}),m}}),F=Z("$ZodStringFormat",(i,f)=>{Se.init(i,f),Ye.init(i,f)}),Oo=Z("$ZodGUID",(i,f)=>{f.pattern??(f.pattern=Dt),F.init(i,f)}),Eo=Z("$ZodUUID",(i,f)=>{if(f.version){let h={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[f.version];if(h===void 0)throw Error(`Invalid UUID version: "${f.version}"`);f.pattern??(f.pattern=lr(h))}else f.pattern??(f.pattern=lr());F.init(i,f)}),Io=Z("$ZodEmail",(i,f)=>{f.pattern??(f.pattern=Lt),F.init(i,f)}),To=Z("$ZodURL",(i,f)=>{F.init(i,f),i._zod.check=(m)=>{try{let h=m.value.trim();if(!f.normalize&&f.protocol?.source===Wt.source){if(!/^https?:\/\//i.test(h)){m.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:m.value,inst:i,continue:!f.abort});return}}let _=new URL(h);if(f.hostname){if(f.hostname.lastIndex=0,!f.hostname.test(_.hostname))m.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:f.hostname.source,input:m.value,inst:i,continue:!f.abort})}if(f.protocol){if(f.protocol.lastIndex=0,!f.protocol.test(_.protocol.endsWith(":")?_.protocol.slice(0,-1):_.protocol))m.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:f.protocol.source,input:m.value,inst:i,continue:!f.abort})}if(f.normalize)m.value=_.href;else m.value=h;return}catch(h){m.issues.push({code:"invalid_format",format:"url",input:m.value,inst:i,continue:!f.abort})}}}),No=Z("$ZodEmoji",(i,f)=>{f.pattern??(f.pattern=Ft()),F.init(i,f)}),Ao=Z("$ZodNanoID",(i,f)=>{f.pattern??(f.pattern=Ct),F.init(i,f)}),jo=Z("$ZodCUID",(i,f)=>{f.pattern??(f.pattern=It),F.init(i,f)}),Co=Z("$ZodCUID2",(i,f)=>{f.pattern??(f.pattern=Tt),F.init(i,f)}),Ro=Z("$ZodULID",(i,f)=>{f.pattern??(f.pattern=Nt),F.init(i,f)}),Do=Z("$ZodXID",(i,f)=>{f.pattern??(f.pattern=At),F.init(i,f)}),Lo=Z("$ZodKSUID",(i,f)=>{f.pattern??(f.pattern=jt),F.init(i,f)}),Fo=Z("$ZodISODateTime",(i,f)=>{f.pattern??(f.pattern=Ht(f)),F.init(i,f)}),Uo=Z("$ZodISODate",(i,f)=>{f.pattern??(f.pattern=qt),F.init(i,f)}),Mo=Z("$ZodISOTime",(i,f)=>{f.pattern??(f.pattern=Xt(f)),F.init(i,f)}),Jo=Z("$ZodISODuration",(i,f)=>{f.pattern??(f.pattern=Rt),F.init(i,f)}),Bo=Z("$ZodIPv4",(i,f)=>{f.pattern??(f.pattern=Ut),F.init(i,f),i._zod.bag.format="ipv4"}),Vo=Z("$ZodIPv6",(i,f)=>{f.pattern??(f.pattern=Mt),F.init(i,f),i._zod.bag.format="ipv6",i._zod.check=(m)=>{try{new URL(`http://[${m.value}]`)}catch{m.issues.push({code:"invalid_format",format:"ipv6",input:m.value,inst:i,continue:!f.abort})}}});var Wo=Z("$ZodCIDRv4",(i,f)=>{f.pattern??(f.pattern=Jt),F.init(i,f)}),Ko=Z("$ZodCIDRv6",(i,f)=>{f.pattern??(f.pattern=Bt),F.init(i,f),i._zod.check=(m)=>{let h=m.value.split("/");try{if(h.length!==2)throw Error();let[_,g]=h;if(!g)throw Error();let z=Number(g);if(`${z}`!==g)throw Error();if(z<0||z>128)throw Error();new URL(`http://[${_}]`)}catch{m.issues.push({code:"invalid_format",format:"cidrv6",input:m.value,inst:i,continue:!f.abort})}}});function Go(i){if(i==="")return!0;if(/\s/.test(i))return!1;if(i.length%4!==0)return!1;try{return atob(i),!0}catch{return!1}}var qo=Z("$ZodBase64",(i,f)=>{f.pattern??(f.pattern=Vt),F.init(i,f),i._zod.bag.contentEncoding="base64",i._zod.check=(m)=>{if(Go(m.value))return;m.issues.push({code:"invalid_format",format:"base64",input:m.value,inst:i,continue:!f.abort})}});function pi(i){if(!fr.test(i))return!1;let f=i.replace(/[-_]/g,(h)=>h==="-"?"+":"/"),m=f.padEnd(Math.ceil(f.length/4)*4,"=");return Go(m)}var Yo=Z("$ZodBase64URL",(i,f)=>{f.pattern??(f.pattern=fr),F.init(i,f),i._zod.bag.contentEncoding="base64url",i._zod.check=(m)=>{if(pi(m.value))return;m.issues.push({code:"invalid_format",format:"base64url",input:m.value,inst:i,continue:!f.abort})}}),Xo=Z("$ZodE164",(i,f)=>{f.pattern??(f.pattern=Kt),F.init(i,f)});function li(i,f=null){try{let m=i.split(".");if(m.length!==3)return!1;let[h]=m;if(!h)return!1;let _=JSON.parse(atob(h));if("typ"in _&&_?.typ!=="JWT")return!1;if(!_.alg)return!1;if(f&&(!("alg"in _)||_.alg!==f))return!1;return!0}catch{return!1}}var Ho=Z("$ZodJWT",(i,f)=>{F.init(i,f),i._zod.check=(m)=>{if(li(m.value,f.alg))return;m.issues.push({code:"invalid_format",format:"jwt",input:m.value,inst:i,continue:!f.abort})}});var xr=Z("$ZodNumber",(i,f)=>{C.init(i,f),i._zod.pattern=i._zod.bag.pattern??dr,i._zod.parse=(m,h)=>{if(f.coerce)try{m.value=Number(m.value)}catch(z){}let _=m.value;if(typeof _==="number"&&!Number.isNaN(_)&&Number.isFinite(_))return m;let g=typeof _==="number"?Number.isNaN(_)?"NaN":!Number.isFinite(_)?"Infinity":void 0:void 0;return m.issues.push({expected:"number",code:"invalid_type",input:_,inst:i,...g?{received:g}:{}}),m}}),Qo=Z("$ZodNumberFormat",(i,f)=>{co.init(i,f),xr.init(i,f)}),en=Z("$ZodBoolean",(i,f)=>{C.init(i,f),i._zod.pattern=ro,i._zod.parse=(m,h)=>{if(f.coerce)try{m.value=Boolean(m.value)}catch(g){}let _=m.value;if(typeof _==="boolean")return m;return m.issues.push({expected:"boolean",code:"invalid_type",input:_,inst:i}),m}});var rn=Z("$ZodNull",(i,f)=>{C.init(i,f),i._zod.pattern=to,i._zod.values=new Set([null]),i._zod.parse=(m,h)=>{let _=m.value;if(_===null)return m;return m.issues.push({expected:"null",code:"invalid_type",input:_,inst:i}),m}}),tn=Z("$ZodAny",(i,f)=>{C.init(i,f),i._zod.parse=(m)=>m}),on=Z("$ZodUnknown",(i,f)=>{C.init(i,f),i._zod.parse=(m)=>m}),nn=Z("$ZodNever",(i,f)=>{C.init(i,f),i._zod.parse=(m,h)=>(m.issues.push({expected:"never",code:"invalid_type",input:m.value,inst:i}),m)});function yo(i,f,m){if(i.issues.length)f.issues.push(...te(m,i.issues));f.value[m]=i.value}var sn=Z("$ZodArray",(i,f)=>{C.init(i,f),i._zod.parse=(m,h)=>{let _=m.value;if(!Array.isArray(_))return m.issues.push({expected:"array",code:"invalid_type",input:_,inst:i}),m;m.value=Array(_.length);let g=[];for(let z=0;z<_.length;z++){let v=_[z],b=f.element._zod.run({value:v,issues:[]},h);if(b instanceof Promise)g.push(b.then((w)=>yo(w,m,z)));else yo(b,m,z)}if(g.length)return Promise.all(g).then(()=>m);return m}});function qe(i,f,m,h,_,g){let z=m in h;if(i.issues.length){if(_&&g&&!z)return;f.issues.push(...te(m,i.issues))}if(!z&&!_){if(!i.issues.length)f.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[m]});return}if(i.value===void 0){if(z)f.value[m]=void 0}else f.value[m]=i.value}function cn(i){let f=Object.keys(i.shape);for(let h of f)if(!i.shape?.[h]?._zod?.traits?.has("$ZodType"))throw Error(`Invalid element at key "${h}": expected a Zod schema`);let m=ht(i.shape);return{...i,keys:f,keySet:new Set(f),numKeys:f.length,optionalKeys:new Set(m)}}function un(i,f,m,h,_,g){let z=[],v=_.keySet,b=_.catchall._zod,w=b.def.type,P=b.optin==="optional",O=b.optout==="optional";for(let T in f){if(T==="__proto__")continue;if(v.has(T))continue;if(w==="never"){z.push(T);continue}let E=b.run({value:f[T],issues:[]},h);if(E instanceof Promise)i.push(E.then((A)=>qe(A,m,T,f,P,O)));else qe(E,m,T,f,P,O)}if(z.length)m.issues.push({code:"unrecognized_keys",keys:z,input:f,inst:g});if(!i.length)return m;return Promise.all(i).then(()=>m)}var fi=Z("$ZodObject",(i,f)=>{if(C.init(i,f),!Object.getOwnPropertyDescriptor(f,"shape")?.get){let v=f.shape;Object.defineProperty(f,"shape",{get:()=>{let b={...v};return Object.defineProperty(f,"shape",{value:b}),b}})}let h=be(()=>cn(f));N(i._zod,"propValues",()=>{let v=f.shape,b={};for(let w in v){let P=v[w]._zod;if(P.values){b[w]??(b[w]=new Set);for(let O of P.values)b[w].add(O)}}return b});let _=ge,g=f.catchall,z;i._zod.parse=(v,b)=>{z??(z=h.value);let w=v.value;if(!_(w))return v.issues.push({expected:"object",code:"invalid_type",input:w,inst:i}),v;v.value={};let P=[],O=z.shape;for(let T of z.keys){let E=O[T],A=E._zod.optin==="optional",ve=E._zod.optout==="optional",J=E._zod.run({value:w[T],issues:[]},b);if(J instanceof Promise)P.push(J.then((sr)=>qe(sr,v,T,w,A,ve)));else qe(J,v,T,w,A,ve)}if(!g)return P.length?Promise.all(P).then(()=>v):v;return un(P,w,v,b,h.value,i)}}),an=Z("$ZodObjectJIT",(i,f)=>{fi.init(i,f);let m=i._zod.parse,h=be(()=>cn(f)),_=(T)=>{let E=new _r(["shape","payload","ctx"]),A=h.value,ve=(q)=>{let M=cr(q);return`shape[${M}]._zod.run({ value: input[${M}], issues: [] }, ctx)`};E.write("const input = payload.value;");let J=Object.create(null),sr=0;for(let q of A.keys)J[q]=`key_${sr++}`;E.write("const newResult = {};");for(let q of A.keys){let M=J[q],B=cr(q),ct=T[q],ut=ct?._zod?.optin==="optional",Qs=ct?._zod?.optout==="optional";if(E.write(`const ${M} = ${ve(q)};`),ut&&Qs)E.write(`
5
+ if (${M}.issues.length) {
6
+ if (${B} in input) {
7
+ payload.issues = payload.issues.concat(${M}.issues.map(iss => ({
8
+ ...iss,
9
+ path: iss.path ? [${B}, ...iss.path] : [${B}]
10
+ })));
11
+ }
12
+ }
13
+
14
+ if (${M}.value === undefined) {
15
+ if (${B} in input) {
16
+ newResult[${B}] = undefined;
17
+ }
18
+ } else {
19
+ newResult[${B}] = ${M}.value;
20
+ }
21
+
22
+ `);else if(!ut)E.write(`
23
+ const ${M}_present = ${B} in input;
24
+ if (${M}.issues.length) {
25
+ payload.issues = payload.issues.concat(${M}.issues.map(iss => ({
26
+ ...iss,
27
+ path: iss.path ? [${B}, ...iss.path] : [${B}]
28
+ })));
29
+ }
30
+ if (!${M}_present && !${M}.issues.length) {
31
+ payload.issues.push({
32
+ code: "invalid_type",
33
+ expected: "nonoptional",
34
+ input: undefined,
35
+ path: [${B}]
36
+ });
37
+ }
38
+
39
+ if (${M}_present) {
40
+ if (${M}.value === undefined) {
41
+ newResult[${B}] = undefined;
42
+ } else {
43
+ newResult[${B}] = ${M}.value;
44
+ }
45
+ }
46
+
47
+ `);else E.write(`
48
+ if (${M}.issues.length) {
49
+ payload.issues = payload.issues.concat(${M}.issues.map(iss => ({
50
+ ...iss,
51
+ path: iss.path ? [${B}, ...iss.path] : [${B}]
52
+ })));
53
+ }
54
+
55
+ if (${M}.value === undefined) {
56
+ if (${B} in input) {
57
+ newResult[${B}] = undefined;
58
+ }
59
+ } else {
60
+ newResult[${B}] = ${M}.value;
61
+ }
62
+
63
+ `)}E.write("payload.value = newResult;"),E.write("return payload;");let Hs=E.compile();return(q,M)=>Hs(T,q,M)},g,z=ge,v=!_e.jitless,w=v&&dt.value,P=f.catchall,O;i._zod.parse=(T,E)=>{O??(O=h.value);let A=T.value;if(!z(A))return T.issues.push({expected:"object",code:"invalid_type",input:A,inst:i}),T;if(v&&w&&E?.async===!1&&E.jitless!==!0){if(!g)g=_(f.shape);if(T=g(T,E),!P)return T;return un([],A,T,E,O,i)}return m(T,E)}});function $o(i,f,m,h){for(let g of i)if(g.issues.length===0)return f.value=g.value,f;let _=i.filter((g)=>!ae(g));if(_.length===1)return f.value=_[0].value,_[0];return f.issues.push({code:"invalid_union",input:f.value,inst:m,errors:i.map((g)=>g.issues.map((z)=>G(z,h,y())))}),f}var zr=Z("$ZodUnion",(i,f)=>{C.init(i,f),N(i._zod,"optin",()=>f.options.some((h)=>h._zod.optin==="optional")?"optional":void 0),N(i._zod,"optout",()=>f.options.some((h)=>h._zod.optout==="optional")?"optional":void 0),N(i._zod,"values",()=>{if(f.options.every((h)=>h._zod.values))return new Set(f.options.flatMap((h)=>Array.from(h._zod.values)));return}),N(i._zod,"pattern",()=>{if(f.options.every((h)=>h._zod.pattern)){let h=f.options.map((_)=>_._zod.pattern);return new RegExp(`^(${h.map((_)=>Me(_.source)).join("|")})$`)}return});let m=f.options.length===1?f.options[0]._zod.run:null;i._zod.parse=(h,_)=>{if(m)return m(h,_);let g=!1,z=[];for(let v of f.options){let b=v._zod.run({value:h.value,issues:[]},_);if(b instanceof Promise)z.push(b),g=!0;else{if(b.issues.length===0)return b;z.push(b)}}if(!g)return $o(z,h,i,_);return Promise.all(z).then((v)=>$o(v,h,i,_))}});var pn=Z("$ZodDiscriminatedUnion",(i,f)=>{f.inclusive=!1,zr.init(i,f);let m=i._zod.parse;N(i._zod,"propValues",()=>{let _={};for(let g of f.options){let z=g._zod.propValues;if(!z||Object.keys(z).length===0)throw Error(`Invalid discriminated union option at index "${f.options.indexOf(g)}"`);for(let[v,b]of Object.entries(z)){if(!_[v])_[v]=new Set;for(let w of b)_[v].add(w)}}return _});let h=be(()=>{let _=f.options,g=new Map;for(let z of _){let v=z._zod.propValues?.[f.discriminator];if(!v||v.size===0)throw Error(`Invalid discriminated union option at index "${f.options.indexOf(z)}"`);for(let b of v){if(g.has(b))throw Error(`Duplicate discriminator value "${String(b)}"`);g.set(b,z)}}return g});i._zod.parse=(_,g)=>{let z=_.value;if(!ge(z))return _.issues.push({code:"invalid_type",expected:"object",input:z,inst:i}),_;let v=h.value.get(z?.[f.discriminator]);if(v)return v._zod.run(_,g);if(f.unionFallback||g.direction==="backward")return m(_,g);return _.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:f.discriminator,options:Array.from(h.value.keys()),input:z,path:[f.discriminator],inst:i}),_}}),ln=Z("$ZodIntersection",(i,f)=>{C.init(i,f),i._zod.parse=(m,h)=>{let _=m.value,g=f.left._zod.run({value:_,issues:[]},h),z=f.right._zod.run({value:_,issues:[]},h);if(g instanceof Promise||z instanceof Promise)return Promise.all([g,z]).then(([b,w])=>bo(m,b,w));return bo(m,g,z)}});function gr(i,f){if(i===f)return{valid:!0,data:i};if(i instanceof Date&&f instanceof Date&&+i===+f)return{valid:!0,data:i};if(ue(i)&&ue(f)){let m=Object.keys(f),h=Object.keys(i).filter((g)=>m.indexOf(g)!==-1),_={...i,...f};for(let g of h){let z=gr(i[g],f[g]);if(!z.valid)return{valid:!1,mergeErrorPath:[g,...z.mergeErrorPath]};_[g]=z.data}return{valid:!0,data:_}}if(Array.isArray(i)&&Array.isArray(f)){if(i.length!==f.length)return{valid:!1,mergeErrorPath:[]};let m=[];for(let h=0;h<i.length;h++){let _=i[h],g=f[h],z=gr(_,g);if(!z.valid)return{valid:!1,mergeErrorPath:[h,...z.mergeErrorPath]};m.push(z.data)}return{valid:!0,data:m}}return{valid:!1,mergeErrorPath:[]}}function bo(i,f,m){let h=new Map,_;for(let v of f.issues)if(v.code==="unrecognized_keys"){_??(_=v);for(let b of v.keys){if(!h.has(b))h.set(b,{});h.get(b).l=!0}}else i.issues.push(v);for(let v of m.issues)if(v.code==="unrecognized_keys")for(let b of v.keys){if(!h.has(b))h.set(b,{});h.get(b).r=!0}else i.issues.push(v);let g=[...h].filter(([,v])=>v.l&&v.r).map(([v])=>v);if(g.length&&_)i.issues.push({..._,keys:g});if(ae(i))return i;let z=gr(f.value,m.value);if(!z.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(z.mergeErrorPath)}`);return i.value=z.data,i}var fn=Z("$ZodRecord",(i,f)=>{C.init(i,f),i._zod.parse=(m,h)=>{let _=m.value;if(!ue(_))return m.issues.push({expected:"record",code:"invalid_type",input:_,inst:i}),m;let g=[],z=f.keyType._zod.values;if(z){m.value={};let v=new Set;for(let w of z)if(typeof w==="string"||typeof w==="number"||typeof w==="symbol"){v.add(typeof w==="number"?w.toString():w);let P=f.keyType._zod.run({value:w,issues:[]},h);if(P instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(P.issues.length){m.issues.push({code:"invalid_key",origin:"record",issues:P.issues.map((E)=>G(E,h,y())),input:w,path:[w],inst:i});continue}let O=P.value,T=f.valueType._zod.run({value:_[w],issues:[]},h);if(T instanceof Promise)g.push(T.then((E)=>{if(E.issues.length)m.issues.push(...te(w,E.issues));m.value[O]=E.value}));else{if(T.issues.length)m.issues.push(...te(w,T.issues));m.value[O]=T.value}}let b;for(let w in _)if(!v.has(w))b=b??[],b.push(w);if(b&&b.length>0)m.issues.push({code:"unrecognized_keys",input:_,inst:i,keys:b})}else{m.value={};for(let v of Reflect.ownKeys(_)){if(v==="__proto__")continue;if(!Object.prototype.propertyIsEnumerable.call(_,v))continue;let b=f.keyType._zod.run({value:v,issues:[]},h);if(b instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(typeof v==="string"&&dr.test(v)&&b.issues.length){let O=f.keyType._zod.run({value:Number(v),issues:[]},h);if(O instanceof Promise)throw Error("Async schemas not supported in object keys currently");if(O.issues.length===0)b=O}if(b.issues.length){if(f.mode==="loose")m.value[v]=_[v];else m.issues.push({code:"invalid_key",origin:"record",issues:b.issues.map((O)=>G(O,h,y())),input:v,path:[v],inst:i});continue}let P=f.valueType._zod.run({value:_[v],issues:[]},h);if(P instanceof Promise)g.push(P.then((O)=>{if(O.issues.length)m.issues.push(...te(v,O.issues));m.value[b.value]=O.value}));else{if(P.issues.length)m.issues.push(...te(v,P.issues));m.value[b.value]=P.value}}}if(g.length)return Promise.all(g).then(()=>m);return m}});var dn=Z("$ZodEnum",(i,f)=>{C.init(i,f);let m=Fe(f.entries),h=new Set(m);i._zod.values=h,i._zod.pattern=new RegExp(`^(${m.filter((_)=>mt.has(typeof _)).map((_)=>typeof _==="string"?ee(_):_.toString()).join("|")})$`),i._zod.parse=(_,g)=>{let z=_.value;if(h.has(z))return _;return _.issues.push({code:"invalid_value",values:m,input:z,inst:i}),_}}),mn=Z("$ZodLiteral",(i,f)=>{if(C.init(i,f),f.values.length===0)throw Error("Cannot create literal schema with no valid values");let m=new Set(f.values);i._zod.values=m,i._zod.pattern=new RegExp(`^(${f.values.map((h)=>typeof h==="string"?ee(h):h?ee(h.toString()):String(h)).join("|")})$`),i._zod.parse=(h,_)=>{let g=h.value;if(m.has(g))return h;return h.issues.push({code:"invalid_value",values:f.values,input:g,inst:i}),h}});var hn=Z("$ZodTransform",(i,f)=>{C.init(i,f),i._zod.optin="optional",i._zod.parse=(m,h)=>{if(h.direction==="backward")throw new ye(i.constructor.name);let _=f.transform(m.value,m);if(h.async)return(_ instanceof Promise?_:Promise.resolve(_)).then((z)=>(m.value=z,m.fallback=!0,m));if(_ instanceof Promise)throw new X;return m.value=_,m.fallback=!0,m}});function wo(i,f){if(f===void 0&&(i.issues.length||i.fallback))return{issues:[],value:void 0};return i}var vr=Z("$ZodOptional",(i,f)=>{C.init(i,f),i._zod.optin="optional",i._zod.optout="optional",N(i._zod,"values",()=>f.innerType._zod.values?new Set([...f.innerType._zod.values,void 0]):void 0),N(i._zod,"pattern",()=>{let m=f.innerType._zod.pattern;return m?new RegExp(`^(${Me(m.source)})?$`):void 0}),i._zod.parse=(m,h)=>{if(f.innerType._zod.optin==="optional"){let _=m.value,g=f.innerType._zod.run(m,h);if(g instanceof Promise)return g.then((z)=>wo(z,_));return wo(g,_)}if(m.value===void 0)return m;return f.innerType._zod.run(m,h)}}),_n=Z("$ZodExactOptional",(i,f)=>{vr.init(i,f),N(i._zod,"values",()=>f.innerType._zod.values),N(i._zod,"pattern",()=>f.innerType._zod.pattern),i._zod.parse=(m,h)=>f.innerType._zod.run(m,h)}),gn=Z("$ZodNullable",(i,f)=>{C.init(i,f),N(i._zod,"optin",()=>f.innerType._zod.optin),N(i._zod,"optout",()=>f.innerType._zod.optout),N(i._zod,"pattern",()=>{let m=f.innerType._zod.pattern;return m?new RegExp(`^(${Me(m.source)}|null)$`):void 0}),N(i._zod,"values",()=>f.innerType._zod.values?new Set([...f.innerType._zod.values,null]):void 0),i._zod.parse=(m,h)=>{if(m.value===null)return m;return f.innerType._zod.run(m,h)}}),xn=Z("$ZodDefault",(i,f)=>{C.init(i,f),i._zod.optin="optional",N(i._zod,"values",()=>f.innerType._zod.values),i._zod.parse=(m,h)=>{if(h.direction==="backward")return f.innerType._zod.run(m,h);if(m.value===void 0)return m.value=f.defaultValue,m;let _=f.innerType._zod.run(m,h);if(_ instanceof Promise)return _.then((g)=>ko(g,f));return ko(_,f)}});function ko(i,f){if(i.value===void 0)i.value=f.defaultValue;return i}var zn=Z("$ZodPrefault",(i,f)=>{C.init(i,f),i._zod.optin="optional",N(i._zod,"values",()=>f.innerType._zod.values),i._zod.parse=(m,h)=>{if(h.direction==="backward")return f.innerType._zod.run(m,h);if(m.value===void 0)m.value=f.defaultValue;return f.innerType._zod.run(m,h)}}),vn=Z("$ZodNonOptional",(i,f)=>{C.init(i,f),N(i._zod,"values",()=>{let m=f.innerType._zod.values;return m?new Set([...m].filter((h)=>h!==void 0)):void 0}),i._zod.parse=(m,h)=>{let _=f.innerType._zod.run(m,h);if(_ instanceof Promise)return _.then((g)=>Zo(g,i));return Zo(_,i)}});function Zo(i,f){if(!i.issues.length&&i.value===void 0)i.issues.push({code:"invalid_type",expected:"nonoptional",input:i.value,inst:f});return i}var yn=Z("$ZodCatch",(i,f)=>{C.init(i,f),i._zod.optin="optional",N(i._zod,"optout",()=>f.innerType._zod.optout),N(i._zod,"values",()=>f.innerType._zod.values),i._zod.parse=(m,h)=>{if(h.direction==="backward")return f.innerType._zod.run(m,h);let _=f.innerType._zod.run(m,h);if(_ instanceof Promise)return _.then((g)=>{if(m.value=g.value,g.issues.length)m.value=f.catchValue({...m,error:{issues:g.issues.map((z)=>G(z,h,y()))},input:m.value}),m.issues=[],m.fallback=!0;return m});if(m.value=_.value,_.issues.length)m.value=f.catchValue({...m,error:{issues:_.issues.map((g)=>G(g,h,y()))},input:m.value}),m.issues=[],m.fallback=!0;return m}});var yr=Z("$ZodPipe",(i,f)=>{C.init(i,f),N(i._zod,"values",()=>f.in._zod.values),N(i._zod,"optin",()=>f.in._zod.optin),N(i._zod,"optout",()=>f.out._zod.optout),N(i._zod,"propValues",()=>f.in._zod.propValues),i._zod.parse=(m,h)=>{if(h.direction==="backward"){let g=f.out._zod.run(m,h);if(g instanceof Promise)return g.then((z)=>Ge(z,f.in,h));return Ge(g,f.in,h)}let _=f.in._zod.run(m,h);if(_ instanceof Promise)return _.then((g)=>Ge(g,f.out,h));return Ge(_,f.out,h)}});function Ge(i,f,m){if(i.issues.length)return i.aborted=!0,i;return f._zod.run({value:i.value,issues:i.issues,fallback:i.fallback},m)}var $n=Z("$ZodPreprocess",(i,f)=>{yr.init(i,f)}),bn=Z("$ZodReadonly",(i,f)=>{C.init(i,f),N(i._zod,"propValues",()=>f.innerType._zod.propValues),N(i._zod,"values",()=>f.innerType._zod.values),N(i._zod,"optin",()=>f.innerType?._zod?.optin),N(i._zod,"optout",()=>f.innerType?._zod?.optout),i._zod.parse=(m,h)=>{if(h.direction==="backward")return f.innerType._zod.run(m,h);let _=f.innerType._zod.run(m,h);if(_ instanceof Promise)return _.then(Po);return Po(_)}});function Po(i){return i.value=Object.freeze(i.value),i}var wn=Z("$ZodLazy",(i,f)=>{C.init(i,f),N(i._zod,"innerType",()=>{let m=f;if(!m._cachedInner)m._cachedInner=f.getter();return m._cachedInner}),N(i._zod,"pattern",()=>i._zod.innerType?._zod?.pattern),N(i._zod,"propValues",()=>i._zod.innerType?._zod?.propValues),N(i._zod,"optin",()=>i._zod.innerType?._zod?.optin??void 0),N(i._zod,"optout",()=>i._zod.innerType?._zod?.optout??void 0),i._zod.parse=(m,h)=>i._zod.innerType._zod.run(m,h)}),kn=Z("$ZodCustom",(i,f)=>{V.init(i,f),C.init(i,f),i._zod.parse=(m,h)=>m,i._zod.check=(m)=>{let h=m.value,_=f.fn(h);if(_ instanceof Promise)return _.then((g)=>So(g,m,h,i));So(_,m,h,i);return}});function So(i,f,m,h){if(!i){let _={code:"custom",input:m,inst:h,path:[...h._zod.def.path??[]],continue:!h._zod.def.abort};if(h._zod.def.params)_.params=h._zod.def.params;f.issues.push(le(_))}}var Zn,Uc=Symbol("ZodOutput"),Mc=Symbol("ZodInput");class Pn{constructor(){this._map=new WeakMap,this._idmap=new Map}add(i,...f){let m=f[0];if(this._map.set(i,m),m&&typeof m==="object"&&"id"in m)this._idmap.set(m.id,i);return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(i){let f=this._map.get(i);if(f&&typeof f==="object"&&"id"in f)this._idmap.delete(f.id);return this._map.delete(i),this}get(i){let f=i._zod.parent;if(f){let m={...this.get(f)??{}};delete m.id;let h={...m,...this._map.get(i)};return Object.keys(h).length?h:void 0}return this._map.get(i)}has(i){return this._map.has(i)}}function di(){return new Pn}(Zn=globalThis).__zod_globalRegistry??(Zn.__zod_globalRegistry=di());var he=globalThis.__zod_globalRegistry;function Sn(i,f){return new i({type:"string",...S(f)})}function $r(i,f){return new i({type:"string",format:"email",check:"string_format",abort:!1,...S(f)})}function br(i,f){return new i({type:"string",format:"guid",check:"string_format",abort:!1,...S(f)})}function On(i,f){return new i({type:"string",format:"uuid",check:"string_format",abort:!1,...S(f)})}function En(i,f){return new i({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...S(f)})}function In(i,f){return new i({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...S(f)})}function Tn(i,f){return new i({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...S(f)})}function wr(i,f){return new i({type:"string",format:"url",check:"string_format",abort:!1,...S(f)})}function Nn(i,f){return new i({type:"string",format:"emoji",check:"string_format",abort:!1,...S(f)})}function An(i,f){return new i({type:"string",format:"nanoid",check:"string_format",abort:!1,...S(f)})}function jn(i,f){return new i({type:"string",format:"cuid",check:"string_format",abort:!1,...S(f)})}function Cn(i,f){return new i({type:"string",format:"cuid2",check:"string_format",abort:!1,...S(f)})}function Rn(i,f){return new i({type:"string",format:"ulid",check:"string_format",abort:!1,...S(f)})}function Dn(i,f){return new i({type:"string",format:"xid",check:"string_format",abort:!1,...S(f)})}function Ln(i,f){return new i({type:"string",format:"ksuid",check:"string_format",abort:!1,...S(f)})}function Fn(i,f){return new i({type:"string",format:"ipv4",check:"string_format",abort:!1,...S(f)})}function Un(i,f){return new i({type:"string",format:"ipv6",check:"string_format",abort:!1,...S(f)})}function Mn(i,f){return new i({type:"string",format:"cidrv4",check:"string_format",abort:!1,...S(f)})}function Jn(i,f){return new i({type:"string",format:"cidrv6",check:"string_format",abort:!1,...S(f)})}function Bn(i,f){return new i({type:"string",format:"base64",check:"string_format",abort:!1,...S(f)})}function Vn(i,f){return new i({type:"string",format:"base64url",check:"string_format",abort:!1,...S(f)})}function Wn(i,f){return new i({type:"string",format:"e164",check:"string_format",abort:!1,...S(f)})}function Kn(i,f){return new i({type:"string",format:"jwt",check:"string_format",abort:!1,...S(f)})}function Gn(i,f){return new i({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...S(f)})}function qn(i,f){return new i({type:"string",format:"date",check:"string_format",...S(f)})}function Yn(i,f){return new i({type:"string",format:"time",check:"string_format",precision:null,...S(f)})}function Xn(i,f){return new i({type:"string",format:"duration",check:"string_format",...S(f)})}function Hn(i,f){return new i({type:"number",checks:[],...S(f)})}function Ce(i,f){return new i({type:"number",coerce:!0,checks:[],...S(f)})}function Qn(i,f){return new i({type:"number",check:"number_format",abort:!1,format:"safeint",...S(f)})}function es(i,f){return new i({type:"boolean",...S(f)})}function rs(i,f){return new i({type:"null",...S(f)})}function ts(i){return new i({type:"any"})}function os(i){return new i({type:"unknown"})}function ns(i,f){return new i({type:"never",...S(f)})}function Xe(i,f){return new mr({check:"less_than",...S(f),value:i,inclusive:!1})}function Oe(i,f){return new mr({check:"less_than",...S(f),value:i,inclusive:!0})}function He(i,f){return new hr({check:"greater_than",...S(f),value:i,inclusive:!1})}function Ie(i,f){return new hr({check:"greater_than",...S(f),value:i,inclusive:!0})}function Qe(i,f){return new io({check:"multiple_of",...S(f),value:i})}function er(i,f){return new uo({check:"max_length",...S(f),maximum:i})}function xe(i,f){return new ao({check:"min_length",...S(f),minimum:i})}function rr(i,f){return new po({check:"length_equals",...S(f),length:i})}function kr(i,f){return new lo({check:"string_format",format:"regex",...S(f),pattern:i})}function Zr(i){return new fo({check:"string_format",format:"lowercase",...S(i)})}function Pr(i){return new mo({check:"string_format",format:"uppercase",...S(i)})}function Sr(i,f){return new ho({check:"string_format",format:"includes",...S(f),includes:i})}function Or(i,f){return new _o({check:"string_format",format:"starts_with",...S(f),prefix:i})}function Er(i,f){return new go({check:"string_format",format:"ends_with",...S(f),suffix:i})}function ie(i){return new xo({check:"overwrite",tx:i})}function Ir(i){return ie((f)=>f.normalize(i))}function Tr(){return ie((i)=>i.trim())}function Nr(){return ie((i)=>i.toLowerCase())}function Ar(){return ie((i)=>i.toUpperCase())}function jr(){return ie((i)=>ft(i))}function ss(i,f,m){return new i({type:"array",element:f,...S(m)})}function is(i,f,m){return new i({type:"custom",check:"custom",fn:f,...S(m)})}function cs(i,f){let m=mi((h)=>(h.addIssue=(_)=>{if(typeof _==="string")h.issues.push(le(_,h.value,m._zod.def));else{let g=_;if(g.fatal)g.continue=!1;g.code??(g.code="custom"),g.input??(g.input=h.value),g.inst??(g.inst=m),g.continue??(g.continue=!m._zod.def.abort),h.issues.push(le(g))}},i(h.value,h)),f);return m}function mi(i,f){let m=new V({check:"custom",...S(f)});return m._zod.check=i,m}function Ne(i){let f=i?.target??"draft-2020-12";if(f==="draft-4")f="draft-04";if(f==="draft-7")f="draft-07";return{processors:i.processors??{},metadataRegistry:i?.metadata??he,target:f,unrepresentable:i?.unrepresentable??"throw",override:i?.override??(()=>{}),io:i?.io??"output",counter:0,seen:new Map,cycles:i?.cycles??"ref",reused:i?.reused??"inline",external:i?.external??void 0}}function D(i,f,m={path:[],schemaPath:[]}){var h;let _=i._zod.def,g=f.seen.get(i);if(g){if(g.count++,m.schemaPath.includes(i))g.cycle=m.path;return g.schema}let z={schema:{},count:1,cycle:void 0,path:m.path};f.seen.set(i,z);let v=i._zod.toJSONSchema?.();if(v)z.schema=v;else{let P={...m,schemaPath:[...m.schemaPath,i],path:m.path};if(i._zod.processJSONSchema)i._zod.processJSONSchema(f,z.schema,P);else{let T=z.schema,E=f.processors[_.type];if(!E)throw Error(`[toJSONSchema]: Non-representable type encountered: ${_.type}`);E(i,f,T,P)}let O=i._zod.parent;if(O){if(!z.ref)z.ref=O;D(O,f,P),f.seen.get(O).isParent=!0}}let b=f.metadataRegistry.get(i);if(b)Object.assign(z.schema,b);if(f.io==="input"&&W(i))delete z.schema.examples,delete z.schema.default;if(f.io==="input"&&"_prefault"in z.schema)(h=z.schema).default??(h.default=z.schema._prefault);return delete z.schema._prefault,f.seen.get(i).schema}function je(i,f){let m=i.seen.get(f);if(!m)throw Error("Unprocessed schema. This is a bug in Zod.");let h=new Map;for(let z of i.seen.entries()){let v=i.metadataRegistry.get(z[0])?.id;if(v){let b=h.get(v);if(b&&b!==z[0])throw Error(`Duplicate schema id "${v}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);h.set(v,z[0])}}let _=(z)=>{let v=i.target==="draft-2020-12"?"$defs":"definitions";if(i.external){let O=i.external.registry.get(z[0])?.id,T=i.external.uri??((A)=>A);if(O)return{ref:T(O)};let E=z[1].defId??z[1].schema.id??`schema${i.counter++}`;return z[1].defId=E,{defId:E,ref:`${T("__shared")}#/${v}/${E}`}}if(z[1]===m)return{ref:"#"};let w=`${"#"}/${v}/`,P=z[1].schema.id??`__schema${i.counter++}`;return{defId:P,ref:w+P}},g=(z)=>{if(z[1].schema.$ref)return;let v=z[1],{ref:b,defId:w}=_(z);if(v.def={...v.schema},w)v.defId=w;let P=v.schema;for(let O in P)delete P[O];P.$ref=b};if(i.cycles==="throw")for(let z of i.seen.entries()){let v=z[1];if(v.cycle)throw Error(`Cycle detected: #/${v.cycle?.join("/")}/<root>
64
+
65
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let z of i.seen.entries()){let v=z[1];if(f===z[0]){g(z);continue}if(i.external){let w=i.external.registry.get(z[0])?.id;if(f!==z[0]&&w){g(z);continue}}if(i.metadataRegistry.get(z[0])?.id){g(z);continue}if(v.cycle){g(z);continue}if(v.count>1){if(i.reused==="ref"){g(z);continue}}}}function Re(i,f){let m=i.seen.get(f);if(!m)throw Error("Unprocessed schema. This is a bug in Zod.");let h=(v)=>{let b=i.seen.get(v);if(b.ref===null)return;let w=b.def??b.schema,P={...w},O=b.ref;if(b.ref=null,O){h(O);let E=i.seen.get(O),A=E.schema;if(A.$ref&&(i.target==="draft-07"||i.target==="draft-04"||i.target==="openapi-3.0"))w.allOf=w.allOf??[],w.allOf.push(A);else Object.assign(w,A);if(Object.assign(w,P),v._zod.parent===O)for(let J in w){if(J==="$ref"||J==="allOf")continue;if(!(J in P))delete w[J]}if(A.$ref&&E.def)for(let J in w){if(J==="$ref"||J==="allOf")continue;if(J in E.def&&JSON.stringify(w[J])===JSON.stringify(E.def[J]))delete w[J]}}let T=v._zod.parent;if(T&&T!==O){h(T);let E=i.seen.get(T);if(E?.schema.$ref){if(w.$ref=E.schema.$ref,E.def)for(let A in w){if(A==="$ref"||A==="allOf")continue;if(A in E.def&&JSON.stringify(w[A])===JSON.stringify(E.def[A]))delete w[A]}}}i.override({zodSchema:v,jsonSchema:w,path:b.path??[]})};for(let v of[...i.seen.entries()].reverse())h(v[0]);let _={};if(i.target==="draft-2020-12")_.$schema="https://json-schema.org/draft/2020-12/schema";else if(i.target==="draft-07")_.$schema="http://json-schema.org/draft-07/schema#";else if(i.target==="draft-04")_.$schema="http://json-schema.org/draft-04/schema#";else if(i.target==="openapi-3.0");if(i.external?.uri){let v=i.external.registry.get(f)?.id;if(!v)throw Error("Schema is missing an `id` property");_.$id=i.external.uri(v)}Object.assign(_,m.def??m.schema);let g=i.metadataRegistry.get(f)?.id;if(g!==void 0&&_.id===g)delete _.id;let z=i.external?.defs??{};for(let v of i.seen.entries()){let b=v[1];if(b.def&&b.defId){if(b.def.id===b.defId)delete b.def.id;z[b.defId]=b.def}}if(i.external);else if(Object.keys(z).length>0)if(i.target==="draft-2020-12")_.$defs=z;else _.definitions=z;try{let v=JSON.parse(JSON.stringify(_));return Object.defineProperty(v,"~standard",{value:{...f["~standard"],jsonSchema:{input:Te(f,"input",i.processors),output:Te(f,"output",i.processors)}},enumerable:!1,writable:!1}),v}catch(v){throw Error("Error converting schema to JSON.")}}function W(i,f){let m=f??{seen:new Set};if(m.seen.has(i))return!1;m.seen.add(i);let h=i._zod.def;if(h.type==="transform")return!0;if(h.type==="array")return W(h.element,m);if(h.type==="set")return W(h.valueType,m);if(h.type==="lazy")return W(h.getter(),m);if(h.type==="promise"||h.type==="optional"||h.type==="nonoptional"||h.type==="nullable"||h.type==="readonly"||h.type==="default"||h.type==="prefault")return W(h.innerType,m);if(h.type==="intersection")return W(h.left,m)||W(h.right,m);if(h.type==="record"||h.type==="map")return W(h.keyType,m)||W(h.valueType,m);if(h.type==="pipe"){if(i._zod.traits.has("$ZodCodec"))return!0;return W(h.in,m)||W(h.out,m)}if(h.type==="object"){for(let _ in h.shape)if(W(h.shape[_],m))return!0;return!1}if(h.type==="union"){for(let _ of h.options)if(W(_,m))return!0;return!1}if(h.type==="tuple"){for(let _ of h.items)if(W(_,m))return!0;if(h.rest&&W(h.rest,m))return!0;return!1}return!1}var us=(i,f={})=>(m)=>{let h=Ne({...m,processors:f});return D(i,h),je(h,i),Re(h,i)},Te=(i,f,m={})=>(h)=>{let{libraryOptions:_,target:g}=h??{},z=Ne({..._??{},target:g,io:f,processors:m});return D(i,z),je(z,i),Re(z,i)};var hi={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Cr=(i,f,m,h)=>{let _=m;_.type="string";let{minimum:g,maximum:z,format:v,patterns:b,contentEncoding:w}=i._zod.bag;if(typeof g==="number")_.minLength=g;if(typeof z==="number")_.maxLength=z;if(v){if(_.format=hi[v]??v,_.format==="")delete _.format;if(v==="time")delete _.format}if(w)_.contentEncoding=w;if(b&&b.size>0){let P=[...b];if(P.length===1)_.pattern=P[0].source;else if(P.length>1)_.allOf=[...P.map((O)=>({...f.target==="draft-07"||f.target==="draft-04"||f.target==="openapi-3.0"?{type:"string"}:{},pattern:O.source}))]}},Rr=(i,f,m,h)=>{let _=m,{minimum:g,maximum:z,format:v,multipleOf:b,exclusiveMaximum:w,exclusiveMinimum:P}=i._zod.bag;if(typeof v==="string"&&v.includes("int"))_.type="integer";else _.type="number";let O=typeof P==="number"&&P>=(g??Number.NEGATIVE_INFINITY),T=typeof w==="number"&&w<=(z??Number.POSITIVE_INFINITY),E=f.target==="draft-04"||f.target==="openapi-3.0";if(O)if(E)_.minimum=P,_.exclusiveMinimum=!0;else _.exclusiveMinimum=P;else if(typeof g==="number")_.minimum=g;if(T)if(E)_.maximum=w,_.exclusiveMaximum=!0;else _.exclusiveMaximum=w;else if(typeof z==="number")_.maximum=z;if(typeof b==="number")_.multipleOf=b},Dr=(i,f,m,h)=>{m.type="boolean"},ps=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("BigInt cannot be represented in JSON Schema")},ls=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Symbols cannot be represented in JSON Schema")},Lr=(i,f,m,h)=>{if(f.target==="openapi-3.0")m.type="string",m.nullable=!0,m.enum=[null];else m.type="null"},fs=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Undefined cannot be represented in JSON Schema")},ds=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Void cannot be represented in JSON Schema")},Fr=(i,f,m,h)=>{m.not={}},Ur=(i,f,m,h)=>{},Mr=(i,f,m,h)=>{},ms=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Date cannot be represented in JSON Schema")},Jr=(i,f,m,h)=>{let _=i._zod.def,g=Fe(_.entries);if(g.every((z)=>typeof z==="number"))m.type="number";if(g.every((z)=>typeof z==="string"))m.type="string";m.enum=g},Br=(i,f,m,h)=>{let _=i._zod.def,g=[];for(let z of _.values)if(z===void 0){if(f.unrepresentable==="throw")throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof z==="bigint")if(f.unrepresentable==="throw")throw Error("BigInt literals cannot be represented in JSON Schema");else g.push(Number(z));else g.push(z);if(g.length===0);else if(g.length===1){let z=g[0];if(m.type=z===null?"null":typeof z,f.target==="draft-04"||f.target==="openapi-3.0")m.enum=[z];else m.const=z}else{if(g.every((z)=>typeof z==="number"))m.type="number";if(g.every((z)=>typeof z==="string"))m.type="string";if(g.every((z)=>typeof z==="boolean"))m.type="boolean";if(g.every((z)=>z===null))m.type="null";m.enum=g}},hs=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("NaN cannot be represented in JSON Schema")},_s=(i,f,m,h)=>{let _=m,g=i._zod.pattern;if(!g)throw Error("Pattern not found in template literal");_.type="string",_.pattern=g.source},gs=(i,f,m,h)=>{let _=m,g={type:"string",format:"binary",contentEncoding:"binary"},{minimum:z,maximum:v,mime:b}=i._zod.bag;if(z!==void 0)g.minLength=z;if(v!==void 0)g.maxLength=v;if(b)if(b.length===1)g.contentMediaType=b[0],Object.assign(_,g);else Object.assign(_,g),_.anyOf=b.map((w)=>({contentMediaType:w}));else Object.assign(_,g)},xs=(i,f,m,h)=>{m.type="boolean"},Vr=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Custom types cannot be represented in JSON Schema")},zs=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Function types cannot be represented in JSON Schema")},Wr=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Transforms cannot be represented in JSON Schema")},vs=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Map cannot be represented in JSON Schema")},ys=(i,f,m,h)=>{if(f.unrepresentable==="throw")throw Error("Set cannot be represented in JSON Schema")},Kr=(i,f,m,h)=>{let _=m,g=i._zod.def,{minimum:z,maximum:v}=i._zod.bag;if(typeof z==="number")_.minItems=z;if(typeof v==="number")_.maxItems=v;_.type="array",_.items=D(g.element,f,{...h,path:[...h.path,"items"]})},Gr=(i,f,m,h)=>{let _=m,g=i._zod.def;_.type="object",_.properties={};let z=g.shape;for(let w in z)_.properties[w]=D(z[w],f,{...h,path:[...h.path,"properties",w]});let v=new Set(Object.keys(z)),b=new Set([...v].filter((w)=>{let P=g.shape[w]._zod;if(f.io==="input")return P.optin===void 0;else return P.optout===void 0}));if(b.size>0)_.required=Array.from(b);if(g.catchall?._zod.def.type==="never")_.additionalProperties=!1;else if(!g.catchall){if(f.io==="output")_.additionalProperties=!1}else if(g.catchall)_.additionalProperties=D(g.catchall,f,{...h,path:[...h.path,"additionalProperties"]})},qr=(i,f,m,h)=>{let _=i._zod.def,g=_.inclusive===!1,z=_.options.map((v,b)=>D(v,f,{...h,path:[...h.path,g?"oneOf":"anyOf",b]}));if(g)m.oneOf=z;else m.anyOf=z},Yr=(i,f,m,h)=>{let _=i._zod.def,g=D(_.left,f,{...h,path:[...h.path,"allOf",0]}),z=D(_.right,f,{...h,path:[...h.path,"allOf",1]}),v=(w)=>("allOf"in w)&&Object.keys(w).length===1,b=[...v(g)?g.allOf:[g],...v(z)?z.allOf:[z]];m.allOf=b},$s=(i,f,m,h)=>{let _=m,g=i._zod.def;_.type="array";let z=f.target==="draft-2020-12"?"prefixItems":"items",v=f.target==="draft-2020-12"?"items":f.target==="openapi-3.0"?"items":"additionalItems",b=g.items.map((T,E)=>D(T,f,{...h,path:[...h.path,z,E]})),w=g.rest?D(g.rest,f,{...h,path:[...h.path,v,...f.target==="openapi-3.0"?[g.items.length]:[]]}):null;if(f.target==="draft-2020-12"){if(_.prefixItems=b,w)_.items=w}else if(f.target==="openapi-3.0"){if(_.items={anyOf:b},w)_.items.anyOf.push(w);if(_.minItems=b.length,!w)_.maxItems=b.length}else if(_.items=b,w)_.additionalItems=w;let{minimum:P,maximum:O}=i._zod.bag;if(typeof P==="number")_.minItems=P;if(typeof O==="number")_.maxItems=O},Xr=(i,f,m,h)=>{let _=m,g=i._zod.def;_.type="object";let z=g.keyType,b=z._zod.bag?.patterns;if(g.mode==="loose"&&b&&b.size>0){let P=D(g.valueType,f,{...h,path:[...h.path,"patternProperties","*"]});_.patternProperties={};for(let O of b)_.patternProperties[O.source]=P}else{if(f.target==="draft-07"||f.target==="draft-2020-12")_.propertyNames=D(g.keyType,f,{...h,path:[...h.path,"propertyNames"]});_.additionalProperties=D(g.valueType,f,{...h,path:[...h.path,"additionalProperties"]})}let w=z._zod.values;if(w){let P=[...w].filter((O)=>typeof O==="string"||typeof O==="number");if(P.length>0)_.required=P}},Hr=(i,f,m,h)=>{let _=i._zod.def,g=D(_.innerType,f,h),z=f.seen.get(i);if(f.target==="openapi-3.0")z.ref=_.innerType,m.nullable=!0;else m.anyOf=[g,{type:"null"}]},Qr=(i,f,m,h)=>{let _=i._zod.def;D(_.innerType,f,h);let g=f.seen.get(i);g.ref=_.innerType},et=(i,f,m,h)=>{let _=i._zod.def;D(_.innerType,f,h);let g=f.seen.get(i);g.ref=_.innerType,m.default=JSON.parse(JSON.stringify(_.defaultValue))},rt=(i,f,m,h)=>{let _=i._zod.def;D(_.innerType,f,h);let g=f.seen.get(i);if(g.ref=_.innerType,f.io==="input")m._prefault=JSON.parse(JSON.stringify(_.defaultValue))},tt=(i,f,m,h)=>{let _=i._zod.def;D(_.innerType,f,h);let g=f.seen.get(i);g.ref=_.innerType;let z;try{z=_.catchValue(void 0)}catch{throw Error("Dynamic catch values are not supported in JSON Schema")}m.default=z},ot=(i,f,m,h)=>{let _=i._zod.def,g=_.in._zod.traits.has("$ZodTransform"),z=f.io==="input"?g?_.out:_.in:_.out;D(z,f,h);let v=f.seen.get(i);v.ref=z},nt=(i,f,m,h)=>{let _=i._zod.def;D(_.innerType,f,h);let g=f.seen.get(i);g.ref=_.innerType,m.readOnly=!0},bs=(i,f,m,h)=>{let _=i._zod.def;D(_.innerType,f,h);let g=f.seen.get(i);g.ref=_.innerType},tr=(i,f,m,h)=>{let _=i._zod.def;D(_.innerType,f,h);let g=f.seen.get(i);g.ref=_.innerType},st=(i,f,m,h)=>{let _=i._zod.innerType;D(_,f,h);let g=f.seen.get(i);g.ref=_},as={string:Cr,number:Rr,boolean:Dr,bigint:ps,symbol:ls,null:Lr,undefined:fs,void:ds,never:Fr,any:Ur,unknown:Mr,date:ms,enum:Jr,literal:Br,nan:hs,template_literal:_s,file:gs,success:xs,custom:Vr,function:zs,transform:Wr,map:vs,set:ys,array:Kr,object:Gr,union:qr,intersection:Yr,tuple:$s,record:Xr,nullable:Hr,nonoptional:Qr,default:et,prefault:rt,catch:tt,pipe:ot,readonly:nt,promise:bs,optional:tr,lazy:st};function me(i,f){if("_idmap"in i){let h=i,_=Ne({...f,processors:as}),g={};for(let b of h._idmap.entries()){let[w,P]=b;D(P,_)}let z={},v={registry:h,uri:f?.uri,defs:g};_.external=v;for(let b of h._idmap.entries()){let[w,P]=b;je(_,P),z[w]=Re(_,P)}if(Object.keys(g).length>0){let b=_.target==="draft-2020-12"?"$defs":"definitions";z.__shared={[b]:g}}return{schemas:z}}let m=Ne({...f,processors:as});return D(i,m),je(m,i),Re(m,i)}var $i=Z("ZodISODateTime",(i,f)=>{Fo.init(i,f),U.init(i,f)});function j(i){return Gn($i,i)}var bi=Z("ZodISODate",(i,f)=>{Uo.init(i,f),U.init(i,f)});function fe(i){return qn(bi,i)}var wi=Z("ZodISOTime",(i,f)=>{Mo.init(i,f),U.init(i,f)});function ws(i){return Yn(wi,i)}var ki=Z("ZodISODuration",(i,f)=>{Jo.init(i,f),U.init(i,f)});function ks(i){return Xn(ki,i)}var Si=(i,f)=>{Be.init(i,f),i.name="ZodError",Object.defineProperties(i,{format:{value:(m)=>vt(i,m)},flatten:{value:(m)=>zt(i,m)},addIssue:{value:(m)=>{i.issues.push(m),i.message=JSON.stringify(i.issues,$e,2)}},addIssues:{value:(m)=>{i.issues.push(...m),i.message=JSON.stringify(i.issues,$e,2)}},isEmpty:{get(){return i.issues.length===0}}})};var K=Z("ZodError",Si,{Parent:Error});var Zs=Ve(K),Ps=We(K),ne=we(K),Ss=Ze(K),Os=bt(K),Es=wt(K),Is=kt(K),Ts=Zt(K),Ns=Pt(K),As=St(K),js=Ot(K),Cs=Et(K);var Rs=new WeakMap;function De(i,f,m){let h=Object.getPrototypeOf(i),_=Rs.get(h);if(!_)_=new Set,Rs.set(h,_);if(_.has(f))return;_.add(f);for(let g in m){let z=m[g];Object.defineProperty(h,g,{configurable:!0,enumerable:!1,get(){let v=z.bind(this);return Object.defineProperty(this,g,{configurable:!0,writable:!0,enumerable:!0,value:v}),v},set(v){Object.defineProperty(this,g,{configurable:!0,writable:!0,enumerable:!0,value:v})}})}}var L=Z("ZodType",(i,f)=>(C.init(i,f),Object.assign(i["~standard"],{jsonSchema:{input:Te(i,"input"),output:Te(i,"output")}}),i.toJSONSchema=us(i,{}),i.def=f,i.type=f.type,Object.defineProperty(i,"_def",{value:f}),i.parse=(m,h)=>Zs(i,m,h,{callee:i.parse}),i.safeParse=(m,h)=>ne(i,m,h),i.parseAsync=async(m,h)=>Ps(i,m,h,{callee:i.parseAsync}),i.safeParseAsync=async(m,h)=>Ss(i,m,h),i.spa=i.safeParseAsync,i.encode=(m,h)=>Os(i,m,h),i.decode=(m,h)=>Es(i,m,h),i.encodeAsync=async(m,h)=>Is(i,m,h),i.decodeAsync=async(m,h)=>Ts(i,m,h),i.safeEncode=(m,h)=>Ns(i,m,h),i.safeDecode=(m,h)=>As(i,m,h),i.safeEncodeAsync=async(m,h)=>js(i,m,h),i.safeDecodeAsync=async(m,h)=>Cs(i,m,h),De(i,"ZodType",{check(...m){let h=this.def;return this.clone(Q(h,{checks:[...h.checks??[],...m.map((_)=>typeof _==="function"?{_zod:{check:_,def:{check:"custom"},onattach:[]}}:_)]}),{parent:!0})},with(...m){return this.check(...m)},clone(m,h){return Y(this,m,h)},brand(){return this},register(m,h){return m.add(this,h),this},refine(m,h){return this.check(zc(m,h))},superRefine(m,h){return this.check(vc(m,h))},overwrite(m){return this.check(ie(m))},optional(){return u(this)},exactOptional(){return sc(this)},nullable(){return Us(this)},nullish(){return u(Us(this))},nonoptional(m){return lc(this,m)},array(){return n(this)},or(m){return c([this,m])},and(m){return k(this,m)},transform(m){return Ms(this,Gs(m))},default(m){return uc(this,m)},prefault(m){return pc(this,m)},catch(m){return dc(this,m)},pipe(m){return Ms(this,m)},readonly(){return _c(this)},describe(m){let h=this.clone();return he.add(h,{description:m}),h},meta(...m){if(m.length===0)return he.get(this);let h=this.clone();return he.add(h,m[0]),h},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(m){return m(this)}}),Object.defineProperty(i,"description",{get(){return he.get(i)?.description},configurable:!0}),i)),Js=Z("_ZodString",(i,f)=>{Ye.init(i,f),L.init(i,f),i._zod.processJSONSchema=(h,_,g)=>Cr(i,h,_,g);let m=i._zod.bag;i.format=m.format??null,i.minLength=m.minimum??null,i.maxLength=m.maximum??null,De(i,"_ZodString",{regex(...h){return this.check(kr(...h))},includes(...h){return this.check(Sr(...h))},startsWith(...h){return this.check(Or(...h))},endsWith(...h){return this.check(Er(...h))},min(...h){return this.check(xe(...h))},max(...h){return this.check(er(...h))},length(...h){return this.check(rr(...h))},nonempty(...h){return this.check(xe(1,...h))},lowercase(h){return this.check(Zr(h))},uppercase(h){return this.check(Pr(h))},trim(){return this.check(Tr())},normalize(...h){return this.check(Ir(...h))},toLowerCase(){return this.check(Nr())},toUpperCase(){return this.check(Ar())},slugify(){return this.check(jr())}})}),Ei=Z("ZodString",(i,f)=>{Ye.init(i,f),Js.init(i,f),i.email=(m)=>i.check($r(Bs,m)),i.url=(m)=>i.check(wr(Vs,m)),i.jwt=(m)=>i.check(Kn(Vi,m)),i.emoji=(m)=>i.check(Nn(Ii,m)),i.guid=(m)=>i.check(br(Ds,m)),i.uuid=(m)=>i.check(On(nr,m)),i.uuidv4=(m)=>i.check(En(nr,m)),i.uuidv6=(m)=>i.check(In(nr,m)),i.uuidv7=(m)=>i.check(Tn(nr,m)),i.nanoid=(m)=>i.check(An(Ti,m)),i.guid=(m)=>i.check(br(Ds,m)),i.cuid=(m)=>i.check(jn(Ni,m)),i.cuid2=(m)=>i.check(Cn(Ai,m)),i.ulid=(m)=>i.check(Rn(ji,m)),i.base64=(m)=>i.check(Bn(Mi,m)),i.base64url=(m)=>i.check(Vn(Ji,m)),i.xid=(m)=>i.check(Dn(Ci,m)),i.ksuid=(m)=>i.check(Ln(Ri,m)),i.ipv4=(m)=>i.check(Fn(Di,m)),i.ipv6=(m)=>i.check(Un(Li,m)),i.cidrv4=(m)=>i.check(Mn(Fi,m)),i.cidrv6=(m)=>i.check(Jn(Ui,m)),i.e164=(m)=>i.check(Wn(Bi,m)),i.datetime=(m)=>i.check(j(m)),i.date=(m)=>i.check(fe(m)),i.time=(m)=>i.check(ws(m)),i.duration=(m)=>i.check(ks(m))});function e(i){return Sn(Ei,i)}var U=Z("ZodStringFormat",(i,f)=>{F.init(i,f),Js.init(i,f)}),Bs=Z("ZodEmail",(i,f)=>{Io.init(i,f),U.init(i,f)});function ze(i){return $r(Bs,i)}var Ds=Z("ZodGUID",(i,f)=>{Oo.init(i,f),U.init(i,f)});var nr=Z("ZodUUID",(i,f)=>{Eo.init(i,f),U.init(i,f)});var Vs=Z("ZodURL",(i,f)=>{To.init(i,f),U.init(i,f)});function re(i){return wr(Vs,i)}var Ii=Z("ZodEmoji",(i,f)=>{No.init(i,f),U.init(i,f)});var Ti=Z("ZodNanoID",(i,f)=>{Ao.init(i,f),U.init(i,f)});var Ni=Z("ZodCUID",(i,f)=>{jo.init(i,f),U.init(i,f)});var Ai=Z("ZodCUID2",(i,f)=>{Co.init(i,f),U.init(i,f)});var ji=Z("ZodULID",(i,f)=>{Ro.init(i,f),U.init(i,f)});var Ci=Z("ZodXID",(i,f)=>{Do.init(i,f),U.init(i,f)});var Ri=Z("ZodKSUID",(i,f)=>{Lo.init(i,f),U.init(i,f)});var Di=Z("ZodIPv4",(i,f)=>{Bo.init(i,f),U.init(i,f)});var Li=Z("ZodIPv6",(i,f)=>{Vo.init(i,f),U.init(i,f)});var Fi=Z("ZodCIDRv4",(i,f)=>{Wo.init(i,f),U.init(i,f)});var Ui=Z("ZodCIDRv6",(i,f)=>{Ko.init(i,f),U.init(i,f)});var Mi=Z("ZodBase64",(i,f)=>{qo.init(i,f),U.init(i,f)});var Ji=Z("ZodBase64URL",(i,f)=>{Yo.init(i,f),U.init(i,f)});var Bi=Z("ZodE164",(i,f)=>{Xo.init(i,f),U.init(i,f)});var Vi=Z("ZodJWT",(i,f)=>{Ho.init(i,f),U.init(i,f)});var oe=Z("ZodNumber",(i,f)=>{xr.init(i,f),L.init(i,f),i._zod.processJSONSchema=(h,_,g)=>Rr(i,h,_,g),De(i,"ZodNumber",{gt(h,_){return this.check(He(h,_))},gte(h,_){return this.check(Ie(h,_))},min(h,_){return this.check(Ie(h,_))},lt(h,_){return this.check(Xe(h,_))},lte(h,_){return this.check(Oe(h,_))},max(h,_){return this.check(Oe(h,_))},int(h){return this.check(Ls(h))},safe(h){return this.check(Ls(h))},positive(h){return this.check(He(0,h))},nonnegative(h){return this.check(Ie(0,h))},negative(h){return this.check(Xe(0,h))},nonpositive(h){return this.check(Oe(0,h))},multipleOf(h,_){return this.check(Qe(h,_))},step(h,_){return this.check(Qe(h,_))},finite(){return this}});let m=i._zod.bag;i.minValue=Math.max(m.minimum??Number.NEGATIVE_INFINITY,m.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,i.maxValue=Math.min(m.maximum??Number.POSITIVE_INFINITY,m.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,i.isInt=(m.format??"").includes("int")||Number.isSafeInteger(m.multipleOf??0.5),i.isFinite=!0,i.format=m.format??null});function o(i){return Hn(oe,i)}var Wi=Z("ZodNumberFormat",(i,f)=>{Qo.init(i,f),oe.init(i,f)});function Ls(i){return Qn(Wi,i)}var Ki=Z("ZodBoolean",(i,f)=>{en.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Dr(i,m,h,_)});function a(i){return es(Ki,i)}var Gi=Z("ZodNull",(i,f)=>{rn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Lr(i,m,h,_)});function I(i){return rs(Gi,i)}var qi=Z("ZodAny",(i,f)=>{tn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Ur(i,m,h,_)});function Pe(){return ts(qi)}var Yi=Z("ZodUnknown",(i,f)=>{on.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Mr(i,m,h,_)});function l(){return os(Yi)}var Xi=Z("ZodNever",(i,f)=>{nn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Fr(i,m,h,_)});function Hi(i){return ns(Xi,i)}var Qi=Z("ZodArray",(i,f)=>{sn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Kr(i,m,h,_),i.element=f.element,De(i,"ZodArray",{min(m,h){return this.check(xe(m,h))},nonempty(m){return this.check(xe(1,m))},max(m,h){return this.check(er(m,h))},length(m,h){return this.check(rr(m,h))},unwrap(){return this.element}})});function n(i,f){return ss(Qi,i,f)}var Ws=Z("ZodObject",(i,f)=>{an.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Gr(i,m,h,_),N(i,"shape",()=>f.shape),De(i,"ZodObject",{keyof(){return p(Object.keys(this._zod.def.shape))},catchall(m){return this.clone({...this._zod.def,catchall:m})},passthrough(){return this.clone({...this._zod.def,catchall:l()})},loose(){return this.clone({...this._zod.def,catchall:l()})},strict(){return this.clone({...this._zod.def,catchall:Hi()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(m){return ti(this,m)},safeExtend(m){return oi(this,m)},merge(m){return ni(this,m)},pick(m){return ei(this,m)},omit(m){return ri(this,m)},partial(...m){return si(qs,this,m[0])},required(...m){return ii(Ys,this,m[0])}})});function t(i,f){let m={type:"object",shape:i??{},...S(f)};return new Ws(m)}function d(i,f){return new Ws({type:"object",shape:i,catchall:l(),...S(f)})}var Ks=Z("ZodUnion",(i,f)=>{zr.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>qr(i,m,h,_),i.options=f.options});function c(i,f){return new Ks({type:"union",options:i,...S(f)})}var ec=Z("ZodDiscriminatedUnion",(i,f)=>{Ks.init(i,f),pn.init(i,f)});function R(i,f,m){return new ec({type:"union",options:f,discriminator:i,...S(m)})}var rc=Z("ZodIntersection",(i,f)=>{ln.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Yr(i,m,h,_)});function k(i,f){return new rc({type:"intersection",left:i,right:f})}var Fs=Z("ZodRecord",(i,f)=>{fn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Xr(i,m,h,_),i.keyType=f.keyType,i.valueType=f.valueType});function s(i,f,m){if(!f||!f._zod)return new Fs({type:"record",keyType:e(),valueType:i,...S(f)});return new Fs({type:"record",keyType:i,valueType:f,...S(m)})}var it=Z("ZodEnum",(i,f)=>{dn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(h,_,g)=>Jr(i,h,_,g),i.enum=f.entries,i.options=Object.values(f.entries);let m=new Set(Object.keys(f.entries));i.extract=(h,_)=>{let g={};for(let z of h)if(m.has(z))g[z]=f.entries[z];else throw Error(`Key ${z} not found in enum`);return new it({...f,checks:[],...S(_),entries:g})},i.exclude=(h,_)=>{let g={...f.entries};for(let z of h)if(m.has(z))delete g[z];else throw Error(`Key ${z} not found in enum`);return new it({...f,checks:[],...S(_),entries:g})}});function p(i,f){let m=Array.isArray(i)?Object.fromEntries(i.map((h)=>[h,h])):i;return new it({type:"enum",entries:m,...S(f)})}var tc=Z("ZodLiteral",(i,f)=>{mn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Br(i,m,h,_),i.values=new Set(f.values),Object.defineProperty(i,"value",{get(){if(f.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return f.values[0]}})});function r(i,f){return new tc({type:"literal",values:Array.isArray(i)?i:[i],...S(f)})}var oc=Z("ZodTransform",(i,f)=>{hn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Wr(i,m,h,_),i._zod.parse=(m,h)=>{if(h.direction==="backward")throw new ye(i.constructor.name);m.addIssue=(g)=>{if(typeof g==="string")m.issues.push(le(g,m.value,f));else{let z=g;if(z.fatal)z.continue=!1;z.code??(z.code="custom"),z.input??(z.input=m.value),z.inst??(z.inst=i),m.issues.push(le(z))}};let _=f.transform(m.value,m);if(_ instanceof Promise)return _.then((g)=>(m.value=g,m.fallback=!0,m));return m.value=_,m.fallback=!0,m}});function Gs(i){return new oc({type:"transform",transform:i})}var qs=Z("ZodOptional",(i,f)=>{vr.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>tr(i,m,h,_),i.unwrap=()=>i._zod.def.innerType});function u(i){return new qs({type:"optional",innerType:i})}var nc=Z("ZodExactOptional",(i,f)=>{_n.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>tr(i,m,h,_),i.unwrap=()=>i._zod.def.innerType});function sc(i){return new nc({type:"optional",innerType:i})}var ic=Z("ZodNullable",(i,f)=>{gn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Hr(i,m,h,_),i.unwrap=()=>i._zod.def.innerType});function Us(i){return new ic({type:"nullable",innerType:i})}var cc=Z("ZodDefault",(i,f)=>{xn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>et(i,m,h,_),i.unwrap=()=>i._zod.def.innerType,i.removeDefault=i.unwrap});function uc(i,f){return new cc({type:"default",innerType:i,get defaultValue(){return typeof f==="function"?f():ar(f)}})}var ac=Z("ZodPrefault",(i,f)=>{zn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>rt(i,m,h,_),i.unwrap=()=>i._zod.def.innerType});function pc(i,f){return new ac({type:"prefault",innerType:i,get defaultValue(){return typeof f==="function"?f():ar(f)}})}var Ys=Z("ZodNonOptional",(i,f)=>{vn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Qr(i,m,h,_),i.unwrap=()=>i._zod.def.innerType});function lc(i,f){return new Ys({type:"nonoptional",innerType:i,...S(f)})}var fc=Z("ZodCatch",(i,f)=>{yn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>tt(i,m,h,_),i.unwrap=()=>i._zod.def.innerType,i.removeCatch=i.unwrap});function dc(i,f){return new fc({type:"catch",innerType:i,catchValue:typeof f==="function"?f:()=>f})}var Xs=Z("ZodPipe",(i,f)=>{yr.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>ot(i,m,h,_),i.in=f.in,i.out=f.out});function Ms(i,f){return new Xs({type:"pipe",in:i,out:f})}var mc=Z("ZodPreprocess",(i,f)=>{Xs.init(i,f),$n.init(i,f)}),hc=Z("ZodReadonly",(i,f)=>{bn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>nt(i,m,h,_),i.unwrap=()=>i._zod.def.innerType});function _c(i){return new hc({type:"readonly",innerType:i})}var gc=Z("ZodLazy",(i,f)=>{wn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>st(i,m,h,_),i.unwrap=()=>i._zod.def.getter()});function H(i){return new gc({type:"lazy",getter:i})}var xc=Z("ZodCustom",(i,f)=>{kn.init(i,f),L.init(i,f),i._zod.processJSONSchema=(m,h,_)=>Vr(i,m,h,_)});function zc(i,f={}){return is(xc,i,f)}function vc(i,f){return cs(i,f)}function x(i,f){return new mc({type:"pipe",in:Gs(i),out:f})}
66
+ export{ke,y,de,pe,Ee,Ae,Ce,me,j,fe,ne,e,ze,re,oe,o,a,I,Pe,l,n,t,d,c,R,k,s,p,r,u,H,x};
@@ -0,0 +1 @@
1
+ import{P,i,F,M,X,Q,ee,b,T,te,ae,ce,Se,be,ve,_e,le,ue,we,Re,$e,N}from"./chunk-6fg5av4s.js";var z=class{_readBuffer;_started=!1;_closed=!1;constructor(r=le.stdin,s=le.stdout,c){this._stdin=r,this._stdout=s,this._readBuffer=new ve({maxBufferSize:c?.maxBufferSize})}onclose;onerror;onmessage;_ondata=(r)=>{try{this._readBuffer.append(r),this.processReadBuffer()}catch(s){this.onerror?.(s),this.close().catch(()=>{})}};_onerror=(r)=>{this.onerror?.(r)};_onstdouterror=(r)=>{this.onerror?.(r),this.close().catch(()=>{})};async start(){if(this._started)throw Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror),this._stdout.on("error",this._onstdouterror)}processReadBuffer(){while(!0)try{let r=this._readBuffer.readMessage();if(r===null)break;this.onmessage?.(r)}catch(r){this.onerror?.(r)}}async close(){if(this._closed)return;if(this._closed=!0,this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdout.off("error",this._onstdouterror),this._stdin.listenerCount("data")===0)this._stdin.pause();this._readBuffer.clear(),this.onclose?.()}send(r){if(this._closed)return Promise.reject(Error("StdioServerTransport is closed"));return new Promise((s,c)=>{let l=_e(r),t=!1,f=(_)=>{if(t)return;t=!0,this._stdout.off("error",f),this._stdout.off("drain",p),c(_)},p=()=>{if(t)return;t=!0,this._stdout.off("error",f),this._stdout.off("drain",p),s()};if(this._stdout.once("error",f),this._stdout.write(l)){if(t)return;t=!0,this._stdout.off("error",f),s()}else if(!t)this._stdout.once("drain",p)})}},j=3000,A=class{onclose;onerror;onmessage;_closed=!1;_pendingRequests=new Set;_drainWaiters=[];constructor(r,s,c){this._wire=r,this._onInstanceClose=s,this._outboundIntercept=c}async start(){}async send(r,s){if(te(r)||ae(r)){let{id:c}=r;if(c!==void 0)this._settle(c)}if(this._closed)return;if(this._outboundIntercept?.(r)==="handled")return;return this._wire.send(r,s)}setProtocolVersion=(r)=>{this._wire.setProtocolVersion?.(r)};deliver(r,s){if(this._closed)return;if(b(r))this._pendingRequests.add(r.id);else if(T(r)&&r.method==="notifications/cancelled"){let c=r.params?.requestId;if(c!==void 0)this._settle(c)}this.onmessage?.(r,s)}async whenRequestsAnswered(r){if(this._closed||this._pendingRequests.size===0)return!0;return await new Promise((s)=>{let c=()=>{clearTimeout(l),s(!0)},l=setTimeout(()=>{this._drainWaiters=this._drainWaiters.filter((t)=>t!==c),s(!1)},r);this._drainWaiters.push(c)})}async close(){if(this._closed)return;this._closed=!0,this._pendingRequests.clear(),this._releaseDrainWaiters();try{this._onInstanceClose()}finally{this.onclose?.()}}_settle(r){if(this._pendingRequests.delete(r),this._pendingRequests.size===0)this._releaseDrainWaiters()}_releaseDrainWaiters(){let r=this._drainWaiters;this._drainWaiters=[];for(let s of r)s()}};function J(r){let s=r.params;if(r.method==="initialize"&&!ce(s)){let f=s!==null&&typeof s==="object"&&typeof s.protocolVersion==="string"?s.protocolVersion:void 0;return{kind:"legacy",reason:"initialize",...f!==void 0&&{requestedVersion:f}}}if(!X(s))return{kind:"legacy",reason:"no-claim"};let c=M(s),l=(c===void 0?[]:ee(c))[0];if(l!==void 0)return{kind:"invalid-envelope",issue:l};let t=Q(s);if(t===void 0||!P.includes(t))return{kind:"unsupported-revision",requested:t??"unknown"};return{kind:"modern",revision:t,classification:{era:"modern",revision:t}}}function g(r,s={}){let c=s.legacy??"serve",l=s.transport??new z,t={phase:"opening"},f,p=!1,_=()=>p||t.phase==="closed",d=(e)=>{try{s.onerror?.(e)}catch{}},y=(e,n,o,a)=>l.send({jsonrpc:"2.0",id:e,error:{code:n,message:o,...a!==void 0&&{data:a}}}).catch((u)=>d(h(u))),w=new we(s.maxSubscriptions??ue),k=(e)=>{if(!T(e))return;let n=w.routeOutbound(e);if(n==="passthrough")return;for(let o of n)l.send({jsonrpc:"2.0",...o}).catch((a)=>d(h(a)));return"handled"},I=async(e)=>{if(b(e)&&e.method==="subscriptions/listen"){let n=M(e.params),o=X(e.params)?(n===void 0?[]:ee(n))[0]:{key:"_meta",problem:"the per-request envelope is required on protocol revision 2026-07-28"},a=Q(e.params),u;if(o!==void 0)u={jsonrpc:"2.0",id:e.id,error:{code:-32602,message:`Invalid _meta envelope: ${o.key}: ${o.problem}`}};else if(a===void 0||!P.includes(a)){let v=new F({supported:[...P],requested:a??"unknown"});u={jsonrpc:"2.0",id:e.id,error:{code:v.code,message:v.message,data:v.data}}}else u=w.serve(e);return await l.send("error"in u?u:{jsonrpc:"2.0",method:u.method,params:u.params}).catch((v)=>d(h(v))),!0}if(T(e)&&e.method==="notifications/cancelled"){let n=e.params?.requestId;if(n!==void 0&&w.cancel(n))return!0}return!1},q=(e,n,o)=>{let a=Se({kind:"legacy",reason:n,...o!==void 0&&{requestedVersion:o}},P);if(a===void 0)return Promise.resolve();return d(Error(`Rejected 2025-era request on a modern-only stdio connection (${a.cell}): ${a.message}`)),y(e.id,a.code,a.message,a.data)},D=(e)=>{if(p||e===f)return;C()},m=async(e,n)=>{let o=await r({era:e}),a=o instanceof N?o.server:o;if(e==="modern")be(a,n),Re(a,P),w.setServerCapabilities(a.getCapabilities(),$e(a));let u=new A(l,()=>D(u),e==="modern"?k:void 0);return await o.connect(u),{product:o,channel:u}},R=(e)=>e.product.close().catch((n)=>d(h(n))),V=async(e)=>{f=e.channel;try{if(!await e.channel.whenRequestsAnswered(j))d(Error(`Discarded the probe instance with requests still unanswered after ${j}ms; continuing with the fallback`));await e.product.close()}catch(n){d(h(n))}finally{f=void 0}},B=async(e)=>{if(t.phase==="closed")return;if(t.phase==="pinned"){if(t.era==="modern"&&b(e)&&e.method==="initialize"&&!ce(e.params)){await q(e,"initialize",e.params!==null&&typeof e.params==="object"&&typeof e.params.protocolVersion==="string"?e.params.protocolVersion:void 0);return}if(t.era==="modern"&&await I(e))return;t.instance.channel.deliver(e);return}if(!b(e)&&!T(e)){d(Error("Discarded a JSON-RPC response received before the connection negotiated an era"));return}let n=J(e);switch(n.kind){case"invalid-envelope":{let o=`Invalid _meta envelope for protocol revision 2026-07-28: ${n.issue.key}: ${n.issue.problem}`;if(b(e))await y(e.id,i.InvalidParams,o,{envelope:n.issue});else d(Error(`Discarded a notification with a malformed envelope: ${o}`));return}case"unsupported-revision":if(b(e)){let o=new F({supported:[...P],requested:n.requested});d(o),await y(e.id,o.code,o.message,o.data)}else d(Error(`Discarded a notification claiming unsupported protocol revision ${n.requested}`));return;case"modern":if(b(e)&&e.method==="server/discover"){if(t.phase==="probe"){t.instance.channel.deliver(e,{classification:n.classification});return}let o=await m("modern",n.revision);if(_()){await R(o);return}t={phase:"probe",instance:o},o.channel.deliver(e,{classification:n.classification});return}if(t.phase==="probe"){if(T(e)){t.instance.channel.deliver(e,{classification:n.classification});return}t={phase:"pinned",era:"modern",instance:t.instance}}else{let o=await m("modern",n.revision);if(_()){await R(o);return}t={phase:"pinned",era:"modern",instance:o}}if(await I(e))return;t.instance.channel.deliver(e,{classification:n.classification});return;case"legacy":{if(c==="reject"){if(b(e))await q(e,n.reason,n.requestedVersion);return}if(t.phase==="probe"){if(await V(t.instance),_())return;t={phase:"opening"}}let o=await m("legacy");if(_()){await R(o);return}t={phase:"pinned",era:"legacy",instance:o},t.instance.channel.deliver(e);return}}},S=[],E=!1,W=async()=>{if(E)return;E=!0;try{while(S.length>0){let e=S.shift();try{await B(e)}catch(n){if(b(e))await y(e.id,i.InternalError,"Internal server error");d(h(n))}}}finally{E=!1}},C=async()=>{if(p||t.phase==="closed")return;p=!0;let e=t;t={phase:"closed"};for(let n of w.teardownAll())await l.send(n).catch((o)=>d(h(o)));if(e.phase==="probe"||e.phase==="pinned")await e.instance.product.close().catch((n)=>d(h(n)));await l.close().catch((n)=>d(h(n)))};l.onmessage=(e)=>{S.push(e),W()},l.onerror=(e)=>{if(d(e),t.phase==="probe"||t.phase==="pinned")t.instance.channel.onerror?.(e)},l.onclose=()=>{if(p||t.phase==="closed")return;p=!0;let e=t;if(t={phase:"closed"},e.phase==="probe"||e.phase==="pinned")e.instance.product.close().catch((n)=>d(h(n)))};let O=l.start().catch((e)=>{throw d(h(e)),e});return O.catch(()=>{}),{close:async()=>{await O.catch(()=>{}),await C()}}}function h(r){return r instanceof Error?r:Error(String(r))}export{g as serveStdio};
@@ -0,0 +1,19 @@
1
+ import{getToolName as St,isToolUIPart as J,readUIMessageStream as wt}from"ai";import{convertToModelMessages as te,generateId as ee,getToolName as re,isToolUIPart as Q}from"ai";var H=String.fromCharCode(27),ve=new RegExp(`${H}\\[[0-?]*[ -/]*[@-~]`,"g"),M=new RegExp(`^${H}\\[[0-?]*[ -/]*[@-~]`);function h(t){let e=0,r=0;while(r<t.length){let s=t.slice(r).match(M);if(s){r+=s[0].length;continue}let a=t.codePointAt(r);if(a==null)break;let i=String.fromCodePoint(a);e+=K(a),r+=i.length}return e}function v(t,e){if(e<=0)return"";let r="",s=0,a=0;while(a<t.length&&s<e){let i=t.slice(a).match(M);if(i){r+=i[0],a+=i[0].length;continue}let o=t.codePointAt(a);if(o==null)break;let u=String.fromCodePoint(o),l=K(o);if(l>0&&s+l>e)break;r+=u,a+=u.length,s+=l}while(a<t.length){let i=t.slice(a).match(M);if(!i)break;r+=i[0],a+=i[0].length}return r}function K(t){if(t===9)return 4;if(t<32||t>=127&&t<160)return 0;if(at(t))return 0;return nt(t)?2:1}function at(t){return t>=768&&t<=879||t>=1155&&t<=1161||t>=1425&&t<=1469||t===1471||t>=1473&&t<=1474||t>=1476&&t<=1477||t===1479||t>=1552&&t<=1562||t>=1611&&t<=1631||t===1648||t>=1750&&t<=1756||t>=1759&&t<=1764||t>=1767&&t<=1768||t>=1770&&t<=1773||t===1809||t>=1840&&t<=1866||t>=1958&&t<=1968||t>=2027&&t<=2035||t>=2070&&t<=2073||t>=2075&&t<=2083||t>=2085&&t<=2087||t>=2089&&t<=2093||t>=2137&&t<=2139||t>=2259&&t<=2306||t===2362||t===2364||t>=2369&&t<=2376||t===2381||t>=2385&&t<=2391||t===8205||t>=65024&&t<=65039||t>=917760&&t<=917999}function nt(t){return t>=4352&&(t<=4447||t===9001||t===9002||t>=11904&&t<=42191&&t!==12351||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65040&&t<=65049||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=65504&&t<=65510||t>=127744&&t<=128591||t>=129280&&t<=129535||t>=131072&&t<=262141)}function g(t,{multiline:e=!1}={}){let r="";for(let s of t){let a=s.charCodeAt(0);if(s===`
2
+ `&&e)r+=`
3
+ `;else if(s==="\t")r+=" ";else if(a<32||a>=127&&a<=159)r+=`\\u${a.toString(16).padStart(4,"0")}`;else r+=s}return r}var d={bold:"\x1B[1m",boldOff:"\x1B[22m",italic:"\x1B[3m",italicOff:"\x1B[23m"},it="─";function ot(t){let e=g(t,{multiline:!0}).split(`
4
+ `),r=[];for(let s=0;s<e.length;s+=1){let a=ut(e,s);if(a!=null){r.push(...pt(a)),s=a.endIndex-1;continue}r.push(lt(e[s]??""))}return r.join(`
5
+ `)}function lt(t){if(t.startsWith("### "))return p(`▶ ${t.slice(4)}`);if(t.startsWith("## "))return p(`■ ${t.slice(3)}`);if(t.startsWith("# "))return p(`█ ${t.slice(2)}`);let e=t.match(/^(\s*)[-+*]\s+(.*)$/);if(e){let[,r,s=""]=e;return p(`${r}•${s.length>0?` ${s}`:""}`)}if(/^\d+\. /.test(t))return p(t.replace(/^(\d+)\. /,"$1. "));if(t.startsWith("> "))return p(`│ ${t.slice(2)}`);return p(t)}function p(t){return t.replace(/`([^`]+)`/g,"$1").replace(/\*\*([^*\n]+)\*\*/g,`${d.bold}$1${d.boldOff}`).replace(/__([^_\n]+)__/g,`${d.bold}$1${d.boldOff}`).replace(/\*([^*\n]+)\*/g,`${d.italic}$1${d.italicOff}`).replace(/_([^_\n]+)_/g,`${d.italic}$1${d.italicOff}`)}function ut(t,e){let r=k(t[e]??"");if(r==null||r.length<2)return;let s=k(t[e+1]??"");if(s==null||s.length!==r.length)return;let a=ct(s);if(a==null)return;let i=[],o=e+2;while(o<t.length){let u=k(t[o]??"");if(u==null)break;i.push(dt(u,r.length)),o+=1}return{alignments:a,endIndex:o,header:r,rows:i}}function k(t){if(!t.includes("|"))return;let e=t.trim();if(e.startsWith("|"))e=e.slice(1);if(e.endsWith("|")&&!e.endsWith("\\|"))e=e.slice(0,-1);let r=[],s="";for(let a=0;a<e.length;a+=1){let i=e[a],o=e[a+1];if(i==="\\"&&o==="|"){s+="|",a+=1;continue}if(i==="|"){r.push(s.trim()),s="";continue}s+=i}return r.push(s.trim()),r}function ct(t){let e=[];for(let r of t){let s=r.match(/^(:)?-{3,}(:)?$/);if(s==null)return;let[,a,i]=s;e.push(a!=null&&i!=null?"center":i!=null?"right":"left")}return e}function dt(t,e){return Array.from({length:e},(r,s)=>t[s]??"")}function pt(t){let e=t.header.map((i)=>`${d.bold}${p(i)}${d.boldOff}`),r=t.rows.map((i)=>i.map(p)),s=[e,...r],a=t.alignments.map((i,o)=>Math.max(3,...s.map((u)=>h(u[o]??""))));return[E(e,a,t.alignments),a.map((i)=>it.repeat(i)).join(" "),...r.map((i)=>E(i,a,t.alignments))]}function E(t,e,r){return t.map((s,a)=>ht(s,e[a]??0,r[a]??"left")).join(" ")}function ht(t,e,r){let s=Math.max(0,e-h(t));if(r==="right")return`${" ".repeat(s)}${t}`;if(r==="center"){let a=Math.floor(s/2),i=s-a;return`${" ".repeat(a)}${t}${" ".repeat(i)}`}return`${t}${" ".repeat(s)}`}var j="─";function ft(t){let e=Math.max(20,t.width),r=Math.max(8,t.height),s=3,i=r-3-2,o=t.visibleBodyLines.slice(0,i);while(o.length<i)o.push("");return[A(e,t.title,t.rightTitle),...o.map((l)=>U(l,e)),R(e),A(e,t.inputActive?"Input":"Status"),U(t.inputActive?`> ${g(t.input)}${t.inputCursorVisible===!1?" ":"█"}`:g(t.status??"Streaming... ↑/↓ scroll · Ctrl+C quit"),e),R(e)].join(`
6
+ `)}function A(t,e,r){e=g(e),r=r==null?void 0:g(r);let s=Math.max(0,t-2),a=e?v(` ${e} `,s):"",i=r?v(` ${r} `,Math.max(0,s-h(a))):"",o=Math.max(0,s-h(a)-h(i));return`┌${a}${j.repeat(o)}${i}┐`}function R(t){return`└${j.repeat(t-2)}┘`}function U(t,e){let r=e-4,s=v(t,r),a=" ".repeat(Math.max(0,r-h(s)));return`│ ${s}${a} │`}var y="\x1B",mt=`${y}[H`,gt=`${y}[2J`,vt=`${y}[2K`,yt=`${y}[?2026h`,bt=`${y}[?2026l`,xt=class{#e;#r;#i;#c=!1;#d=!1;constructor(t,e){this.#r=t.write.bind(t),this.#e=e?.useSynchronizedUpdates??!0,t.write=(r,s,a)=>{if(!this.#c)this.#d=!0;return this.#r(r,s,a)}}present(t){let e=Tt(t),r=this.#i&&!this.#d?kt(this.#i,e):`${mt}${gt}${t}`;if(this.#i=e,this.#d=!1,r.length===0)return;this.#S(r)}reset(){this.#i=void 0}#S(t){this.#c=!0;try{if(!this.#e){this.#r(t);return}this.#r(`${yt}${t}${bt}`)}finally{this.#c=!1}}};function Tt(t){return{lines:t.split(`
7
+ `)}}function kt(t,e){let r="",s=Math.max(t.lines.length,e.lines.length);for(let a=0;a<s;a++){let i=e.lines[a];if(t.lines[a]===i)continue;r+=`${y}[${a+1};1H${vt}${i??""}`}return r}var Mt="outputTokensPerSecond",c={reset:"\x1B[0m",dim:"\x1B[2m",user:"\x1B[96m",assistant:"\x1B[92m",reasoning:"\x1B[94m",tool:"\x1B[95m",error:"\x1B[91m"},$t={user:{color:c.user,border:"─"},assistant:{color:c.assistant,border:"─"},reasoning:{color:c.reasoning,border:"·"},tool:{color:c.tool,border:"─"},error:{color:c.error,border:"─"}},Ct=500,It=new Intl.Segmenter(void 0,{granularity:"grapheme"}),m="↑/↓ · PgUp/PgDn · Esc/Ctrl+C",Bt="↑/↓ · PgUp/PgDn · q/Esc/Ctrl+C",b=`Processing input... ${m}`,L=`Processing tool results... ${m}`,S=`Streaming... ${m}`,O=`Executing tools... ${m}`,C=class{#e;#r;#i;#c;#d;#S;#F;#a=[];#u="";#g=!1;#p=0;#I="";#s=S;#w=!1;#n=!1;#h;#B;#f;#v;#y=!0;#b;#o;#x;#E;constructor(t){this.#e=t?.input??process.stdin,this.#r=t?.output??process.stdout,this.#i=t?.frameBuffer??new xt(this.#r),this.#c=t?.tools??"auto-collapsed",this.#d=t?.reasoning??"auto-collapsed",this.#S=t?.responseStatistics??Mt,this.#F=t?.contextSize,this.#B=t?.contextSize}async readPrompt(t){return this.#A(t),this.#g=!0,this.#u=t?.initialPrompt??"",this.#s=`Type a prompt and press Enter · ${m}`,this.#K(),this.#t(),await new Promise((e,r)=>{this.#o=(s)=>{let a=T(s);switch(a.type){case"character":this.#u+=a.value,this.#U(),this.#t();break;case"backspace":this.#u=Pt(this.#u),this.#U(),this.#t();break;case"enter":{let i=this.#u;this.#g=!1,this.#C(),this.#s=b,this.#N(i),this.#u="",this.#t(),this.#l(),e(i);break}case"up":case"down":this.#T(a.type);break;case"page-up":case"page-down":this.#$(a.type);break;case"ctrl-l":this.#k();break;case"escape":case"ctrl-c":this.#C(),this.#R(),r(w());break;case"ignore":break}},this.#M()})}async renderStream(t,e){this.#A(e),this.#g=!1,this.#s=b,this.#j(e?.submittedPrompt),this.#n=!1,this.#h=void 0,this.#f=void 0,this.#v=void 0;let r={tools:e?.tools??this.#c,reasoning:e?.reasoning??this.#d,responseStatistics:e?.responseStatistics??this.#S};this.#t();let s=new Promise((o)=>{this.#E=o});this.#o=(o)=>this.#H(o),this.#M();let a,i=Dt(this.#G(t.uiMessageStream));try{let o=wt({message:t.message,stream:i,onError:(u)=>this.#q("Error",At(u))});for await(let u of Et(o,s)){if(this.#n)break;a=u,this.#D(u,r)}if(!this.#n&&a&&this.#f!=null)this.#D(a,r)}finally{if(this.#E=void 0,this.#n)t.abort?.();if(this.#l(),this.#s=this.#n?"Interrupted":e?.continueSession?`Done · Enter another prompt · ${m}`:`Done · ${Bt}`,this.#t(),await this.#Z(e),this.#n||!e?.continueSession)this.#R()}if(this.#n)throw w();return a}async readToolApproval(t,e){return this.#A(e),this.#g=!1,this.#s=`Approve ${Ft(t)}? y/n · ${m}`,this.#n=!1,this.#t(),await new Promise((r,s)=>{this.#o=(a)=>{let i=T(a);switch(i.type){case"character":{let o=i.value.toLowerCase();if(o==="y")this.#s=`Approved · ${b}`,this.#l(),this.#t(),r({approved:!0});else if(o==="n")this.#s=`Denied · ${b}`,this.#l(),this.#t(),r({approved:!1,reason:"Denied by user."});break}case"up":case"down":this.#T(i.type);break;case"page-up":case"page-down":this.#$(i.type);break;case"ctrl-l":this.#k();break;case"escape":case"ctrl-c":this.#n=!0,this.#R(),s(w());break;default:break}},this.#M()})}#A(t){if(this.#I=t?.title??this.#I,this.#B=t?.contextSize??this.#F,this.#w)return;if(this.#w=!0,this.#i.reset(),this.#r.write("\x1B[?1049h\x1B[?25l"),this.#e.isTTY)this.#e.setRawMode?.(!0),this.#e.resume();this.#x=()=>this.#k(),this.#r.on("resize",this.#x)}#R(){if(this.#l(),this.#C(),!this.#w)return;if(this.#e.isTTY)this.#e.setRawMode?.(!1),this.#e.pause();if(this.#x)this.#r.off("resize",this.#x),this.#x=void 0;this.#r.write("\x1B[?25h\x1B[?1049l"),this.#i.reset(),this.#w=!1}#M(){if(this.#o)this.#e.on("data",this.#o)}#l(){if(this.#o)this.#e.off("data",this.#o),this.#o=void 0}#H(t){let e=T(t);switch(e.type){case"up":case"down":this.#T(e.type);break;case"page-up":case"page-down":this.#$(e.type);break;case"ctrl-l":this.#k();break;case"escape":case"ctrl-c":this.#n=!0,this.#E?.();break;default:break}}#T(t,e=1){let r=t==="up"?e:-e;this.#p=this.#_(this.#p+r),this.#t()}#$(t){this.#T(t==="page-up"?"up":"down",this.#W())}#K(){this.#C(),this.#U(),this.#b=setInterval(()=>{this.#y=!this.#y,this.#t()},Ct),this.#b.unref?.()}#C(){if(this.#b)clearInterval(this.#b),this.#b=void 0;this.#y=!0}#U(){this.#y=!0}#j(t){if(t==null)return;let e=this.#a.at(-1);if(e?.kind==="user"&&e.content===t)return;this.#N(t)}#N(t){let e=this.#m();this.#a.push({kind:"user",title:"User",content:t}),this.#O(e)}#D(t,e){let r=this.#m(),s=new Set,a=Jt(t.metadata);this.#h=a.totalTokens??this.#h,this.#f=a.outputTokens??this.#f,this.#v=a.outputTokensPerSecond??this.#v;for(let[i,o]of t.parts.entries()){let u=Nt(t.id,i);switch(o.type){case"text":{let l=o.text.trim();if(l.length===0)break;s.add(u),this.#L({id:u,kind:"assistant",title:"Assistant",rightTitle:Zt({totalTokens:this.#h,outputTokens:this.#f,outputTokensPerSecond:this.#v},e.responseStatistics),content:l});break}case"reasoning":{let l=o.text.trim();if(e.reasoning==="hidden"||l.length===0)break;s.add(u),this.#L({id:u,kind:"reasoning",title:"Reasoning",content:l,collapsed:W(t,i,e.reasoning,e)});break}default:if(J(o)){if(e.tools==="hidden")break;s.add(u),this.#L({id:u,...Rt(o,{mode:e.tools,collapsed:W(t,i,e.tools,e)})})}break}}this.#J(t.id,s),this.#O(r)}#L(t){let e=t.id?this.#a.find((r)=>r.id===t.id):void 0;if(e){let r=e.cache;e.kind=t.kind,e.title=t.title,e.rightTitle=t.rightTitle,e.content=t.content,e.collapsed=t.collapsed,e.cache=r&&G(t,r)?r:void 0;return}this.#a.push(t)}#J(t,e){let r=`${t}:`;this.#a=this.#a.filter((s)=>s.id==null||!s.id.startsWith(r)||e.has(s.id))}async*#G(t){let e=!1;for await(let r of qt(t)){let s=Ot(r,{hasPendingToolResults:e});if(r.type==="start-step")e=!1;else if(Wt(r))e=!0;if(s&&this.#s!==s)this.#s=s,this.#t();else if(Lt(r)&&this.#s!==S)this.#s=S,this.#t();if(r.type==="error")this.#q("Error",r.errorText);if(r.type==="finish"){let a=jt(r);this.#h=a.totalTokens,this.#f=a.outputTokens,this.#v=a.outputTokensPerSecond}yield r}}#q(t,e){let r=this.#m();this.#a.push({kind:"error",title:t,content:e}),this.#O(r)}#O(t){if(this.#p!==0){let e=this.#m()-t;this.#p=this.#_(this.#p+e)}this.#t()}#t(){let t=ft({width:this.#z(),height:this.#V(),title:this.#I,rightTitle:Z(this.#h,this.#B),visibleBodyLines:this.#Y(),input:this.#u,inputActive:this.#g,inputCursorVisible:this.#y,status:this.#s});this.#i.present(t)}#k(){this.#i.reset(),this.#t()}#Y(){if(this.#a.length===0)return["Waiting for input..."];let t=this.#W(),e=this.#m(),r=Math.max(0,e-t-this.#p),s=r+t,a=[],i=0;for(let o of this.#a){let u=F(o,this.#z()-4),l=i+u.length;if(l>r&&i<s)a.push(...u.slice(Math.max(0,r-i),s-i));if(a.length>=t)break;i=l}return a}#_(t){let e=Math.max(0,this.#m()-this.#W());return Math.min(Math.max(0,t),e)}#m(){if(this.#a.length===0)return 1;let t=0;for(let e of this.#a)t+=F(e,this.#z()-4).length;return t}#W(){return Math.max(1,this.#V()-5)}#z(){return Math.max(20,this.#r.columns??80)}#V(){return Math.max(8,this.#r.rows??24)}async#Z(t){if(t?.waitForExit===!1||!this.#e.isTTY||this.#n)return;await new Promise((e)=>{this.#o=(r)=>{let s=T(r);switch(s.type){case"up":case"down":this.#T(s.type);break;case"page-up":case"page-down":this.#$(s.type);break;case"ctrl-l":this.#k();break;case"escape":this.#l(),e();break;case"character":if(s.value==="q")this.#l(),e();break;case"ctrl-c":this.#l(),process.exitCode=130,e();break;default:break}},this.#M()})}};function w(){return Error("Interrupted")}async function*Et(t,e){let r=t[Symbol.asyncIterator](),s=e.then(()=>({done:!0,value:void 0}));while(!0){let a=await Promise.race([r.next(),s]);if(a.done)break;yield a.value}}function At(t){if(t instanceof Error)return t.message;if(typeof t==="string")return t;return JSON.stringify(t)}function Rt(t,e){let r=St(t),s=`Tool · ${t.title??r}`,a="input"in t?t.input:void 0,i=a===void 0?"Input: (streaming...)":`Input:
8
+ ${z(a)}`,o=zt(t);if(e.collapsed)return{kind:"tool",title:s,rightTitle:o,content:"",collapsed:!0};switch(t.state){case"input-streaming":return{kind:"tool",title:s,rightTitle:o,content:i};case"input-available":return{kind:"tool",title:s,rightTitle:o,content:i};case"approval-requested":return{kind:"tool",title:s,rightTitle:o,content:i};case"approval-responded":return{kind:"tool",title:s,rightTitle:o,content:i};case"output-available":return{kind:"tool",title:s,rightTitle:o,content:`${i}
9
+
10
+ Output:
11
+ ${z(t.output)}`};case"output-error":return{kind:"error",title:`Tool Error · ${t.title??r}`,rightTitle:o,content:`${i}
12
+
13
+ Error:
14
+ ${t.errorText}`};case"output-denied":return{kind:"error",title:`Tool Denied · ${t.title??r}`,rightTitle:o,content:`${i}
15
+
16
+ Reason: ${t.approval.reason??"denied"}`}}}function W(t,e,r,s){switch(r){case"collapsed":return!0;case"auto-collapsed":return t.parts.slice(e+1).some((a)=>Ut(a,s));case"full":case"hidden":return!1}}function Ut(t,e){switch(t.type){case"text":return t.text.trim().length>0;case"reasoning":return e.reasoning!=="hidden"&&t.text.trim().length>0;default:return J(t)&&e.tools!=="hidden"}}function Lt(t){switch(t.type){case"text-start":case"text-delta":case"reasoning-start":case"reasoning-delta":case"tool-input-start":case"tool-input-delta":return!0;default:return!1}}function Ot(t,{hasPendingToolResults:e}){switch(t.type){case"start-step":return e?L:b;case"tool-output-available":case"tool-output-error":case"tool-output-denied":return L;case"tool-input-available":return O;case"tool-approval-response":return t.approved?O:void 0;default:return}}function Wt(t){switch(t.type){case"tool-output-available":case"tool-output-error":case"tool-output-denied":return!0;default:return!1}}function zt(t){switch(t.state){case"input-streaming":return"waiting";case"approval-requested":return"approval requested";case"input-available":return"executing";case"approval-responded":return t.approval.approved?"executing":"denied";case"output-available":case"output-error":return"done";case"output-denied":return"denied"}}function z(t){if(typeof t==="string")return t;return JSON.stringify(t,null,2)}function Ft(t){return`tool ${t.title??t.toolName}`}function Nt(t,e){return`${t}:${e}`}function Dt(t){if(t instanceof ReadableStream)return t;return new ReadableStream({async start(e){try{for await(let r of t)e.enqueue(r);e.close()}catch(r){e.error(r)}}})}async function*qt(t){if(t instanceof ReadableStream){let e=t.getReader();try{while(!0){let{done:r,value:s}=await e.read();if(r)return;yield s}}finally{e.releaseLock()}return}yield*t}function F(t,e){if(t.cache&&G(t,t.cache,e))return t.cache.lines;let r=_t(t,e);return t.cache={width:e,kind:t.kind,title:t.title,rightTitle:t.rightTitle,content:t.content,collapsed:t.collapsed===!0,lines:r},r}function G(t,e,r=e.width){return e.width===r&&e.kind===t.kind&&e.title===t.title&&e.rightTitle===t.rightTitle&&e.content===t.content&&e.collapsed===(t.collapsed===!0)}function _t(t,e){let r=$t[t.kind],s=Math.max(1,e-4),a=` ${g(t.title)} `,i=t.rightTitle?` ${g(t.rightTitle)} `:"";if(t.collapsed){let f=Math.max(0,e-2-a.length-i.length),rt=`${r.color}╭${a}${r.border.repeat(f)}${i}╮${c.reset}`,st=`${r.color}╰${r.border.repeat(Math.max(0,e-2))}╯${c.reset}`;return[rt,st]}let o=Math.max(0,e-2-a.length-i.length),u=`${r.color}╭${a}${r.border.repeat(o)}${i}╮${c.reset}`,l=`${r.color}╰${r.border.repeat(Math.max(0,e-2))}╯${c.reset}`,x=(t.content.length>0?ot(t.content):c.dim+"(streaming...)"+c.reset).split(`
17
+ `).flatMap((f)=>Ht(f,s));return[u,...x.map((f)=>Vt(f,s,r.color)),l]}function Vt(t,e,r){let s=v(t,e),a=" ".repeat(Math.max(0,e-h(s)));return`${r}│${c.reset} ${s}${a} ${r}│${c.reset}`}function Ht(t,e){if(t.length===0)return[""];let r=[],s=t;while(h(s)>e){let a=Kt(s,e);r.push(s.slice(0,a).trimEnd()),s=s.slice(a).trimStart()}return r.push(s),r}function Kt(t,e){let s=v(t,e+1).lastIndexOf(" ");if(s>0)return s;return v(t,e).length}function jt(t){let e="usage"in t?t.usage:void 0,r="messageMetadata"in t?t.messageMetadata?.usage:void 0,s="messageMetadata"in t?t.messageMetadata?.performance:void 0;return{totalTokens:Y(e??r),outputTokens:B(e??r),outputTokensPerSecond:s?.outputTokensPerSecond}}function Jt(t){let e=t;return{totalTokens:Y(e?.usage),outputTokens:B(e?.usage),outputTokensPerSecond:e?.performance?.outputTokensPerSecond}}function Y(t){let e=t?.totalTokens;if(typeof e==="number")return e;if(typeof e?.total==="number")return e.total;let r=Gt(t),s=B(t);if(r!=null&&s!=null)return r+s}function Gt(t){let e=t?.inputTokens;if(typeof e==="number")return e;if(typeof e?.total==="number")return e.total;return t?.promptTokens}function B(t){let e=t?.outputTokens;if(typeof e==="number")return e;if(typeof e?.total==="number")return e.total;return t?.completionTokens}function Z(t,e){if(t==null)return;let r=`${t.toLocaleString()} ${t===1?"token":"tokens"}`,s=Yt(t,e);return s==null?r:`${r} ${s}`}function Yt(t,e){if(e==null||e<=0||!Number.isFinite(e))return;return`${Math.round(t/e*100).toLocaleString()}%`}function Zt(t,e){if(e==="outputTokensPerSecond")return Qt(t.outputTokensPerSecond);return Z(t.outputTokens)}function Qt(t){if(t==null)return;return`${Xt(t)} tok/s`}function Xt(t){return Number.isInteger(t)?t.toLocaleString():t.toLocaleString(void 0,{maximumFractionDigits:1})}function Pt(t){let e=0;for(let{index:r}of It.segment(t))e=r;return t.slice(0,e)}function T(t){let e=t.toString("utf8");switch(e){case"\f":return{type:"ctrl-l"};case"\x03":return{type:"ctrl-c"};case"\x1B":return{type:"escape"};case"\r":case`
18
+ `:return{type:"enter"};case"":case"\b":return{type:"backspace"};case"\x1B[A":return{type:"up"};case"\x1B[B":return{type:"down"};case"\x1B[5~":return{type:"page-up"};case"\x1B[6~":return{type:"page-down"};default:if(e>=" "&&e!=="")return{type:"character",value:e};return{type:"ignore"}}}var se="outputTokensPerSecond",ae=class{constructor(t){this.chatId=ee(),this.agent=t.agent,this.transport=t.transport,this.renderer=ie(t)??ne(t),this.title=t.title,this.tools=t.tools??"auto-collapsed",this.reasoning=t.reasoning??"auto-collapsed",this.responseStatistics=t.responseStatistics??se,this.contextSize=t.contextSize,this.sandbox=t.sandbox}async run(){let t=this.title,e=[],r=0,s=()=>`message-${++r}`,a,i=!1,o=!1;while(!0){if(!o){if(a==null){if(!this.renderer.readPrompt){if(i)return;throw Error("No prompt was provided and the renderer does not support prompt input.")}try{a=await this.renderer.readPrompt({title:t})}catch(l){if(V(l))return;throw l}if(a==null)return}e.push(ue(s(),a)),i=!0}let u=await this.streamMessages([...e],s);try{let l=await this.renderer.renderStream(u,{title:t,submittedPrompt:a,continueSession:Boolean(this.renderer.readPrompt),tools:this.tools,reasoning:this.reasoning,responseStatistics:this.responseStatistics,contextSize:this.contextSize,waitForExit:!1});if(l&&l.parts.length>0){let n=ce(l);if(n.length>0){if(!this.renderer.readToolApproval)throw Error("Tool approval was requested, but the renderer does not support tool approval input.");for(let x of n){let f=await this.renderer.readToolApproval(x,{title:t});de(l,x,f)}D(e,l,o),o=!0,a=void 0;continue}D(e,l,o)}}catch(l){if(V(l))return;throw l}o=!1,a=void 0}}async streamMessages(t,e){let r=new AbortController,s=()=>r.abort();if(this.transport)return{uiMessageStream:await this.transport.sendMessages({trigger:"submit-message",chatId:this.chatId,messageId:void 0,messages:t,abortSignal:r.signal}),message:I(t),abort:s};let a=this.agent,i=await a.stream({prompt:await te(t,{tools:a.tools}),abortSignal:r.signal,options:void 0,experimental_sandbox:this.sandbox});return{uiMessageStream:oe(i.fullStream,e,t),message:I(t),abort:s}}};function ne(t){return t.tools===void 0&&t.reasoning===void 0&&t.responseStatistics===void 0&&t.contextSize===void 0?new C:new C({tools:t.tools,reasoning:t.reasoning,responseStatistics:t.responseStatistics,contextSize:t.contextSize})}function ie(t){if(t.renderer)return t.renderer;if(!t.screen&&!t.userInput)return;return new C({tools:t.tools,reasoning:t.reasoning,responseStatistics:t.responseStatistics,contextSize:t.contextSize,input:t.userInput,output:t.screen})}async function*oe(t,e,r=[]){let s=new Set,a=new Set,i=new Set,o,u,l=!1;yield{type:"start",messageId:I(r)?.id??e()};for await(let n of t)switch(n.type){case"text-start":s.add(n.id),yield{type:"text-start",id:n.id,providerMetadata:n.providerMetadata};break;case"text-delta":if(!s.has(n.id))s.add(n.id),yield{type:"text-start",id:n.id,providerMetadata:n.providerMetadata};yield{type:"text-delta",id:n.id,delta:n.text,providerMetadata:n.providerMetadata};break;case"text-end":s.delete(n.id),yield{type:"text-end",id:n.id,providerMetadata:n.providerMetadata};break;case"reasoning-start":a.add(n.id),yield{type:"reasoning-start",id:n.id,providerMetadata:n.providerMetadata};break;case"reasoning-delta":if(!a.has(n.id))a.add(n.id),yield{type:"reasoning-start",id:n.id,providerMetadata:n.providerMetadata};yield{type:"reasoning-delta",id:n.id,delta:n.text,providerMetadata:n.providerMetadata};break;case"reasoning-end":a.delete(n.id),yield{type:"reasoning-end",id:n.id,providerMetadata:n.providerMetadata};break;case"tool-input-start":yield{type:"tool-input-start",toolCallId:n.id,toolName:n.toolName,providerExecuted:n.providerExecuted,providerMetadata:n.providerMetadata,toolMetadata:n.toolMetadata,dynamic:n.dynamic,title:n.title};break;case"tool-input-delta":yield{type:"tool-input-delta",toolCallId:n.id,inputTextDelta:n.delta};break;case"tool-call":i.add(n.toolCallId),yield{type:"tool-input-available",toolCallId:n.toolCallId,toolName:n.toolName,input:n.input,providerExecuted:n.providerExecuted,providerMetadata:n.providerMetadata,toolMetadata:n.toolMetadata,dynamic:n.dynamic,title:n.title};break;case"tool-approval-request":if(!i.has(n.toolCall.toolCallId))i.add(n.toolCall.toolCallId),yield{type:"tool-input-available",toolCallId:n.toolCall.toolCallId,toolName:n.toolCall.toolName,input:n.toolCall.input,providerExecuted:n.toolCall.providerExecuted,providerMetadata:n.toolCall.providerMetadata,toolMetadata:n.toolCall.toolMetadata,dynamic:n.toolCall.dynamic,title:n.toolCall.title};yield{type:"tool-approval-request",approvalId:n.approvalId,toolCallId:n.toolCall.toolCallId,isAutomatic:n.isAutomatic};break;case"tool-approval-response":yield{type:"tool-approval-response",approvalId:n.approvalId,approved:n.approved,reason:n.reason,providerExecuted:n.providerExecuted};break;case"tool-result":yield{type:"tool-output-available",toolCallId:n.toolCallId,output:n.output,providerExecuted:n.providerExecuted,providerMetadata:n.providerMetadata,toolMetadata:n.toolMetadata,dynamic:n.dynamic,preliminary:n.preliminary};break;case"tool-error":yield{type:"tool-output-error",toolCallId:n.toolCallId,errorText:q(n.error),providerExecuted:n.providerExecuted,providerMetadata:n.providerMetadata,toolMetadata:n.toolMetadata,dynamic:n.dynamic};break;case"tool-output-denied":yield{type:"tool-output-denied",toolCallId:n.toolCallId};break;case"source":if(n.sourceType==="url")yield{type:"source-url",sourceId:n.id,url:n.url,title:n.title,providerMetadata:n.providerMetadata};else yield{type:"source-document",sourceId:n.id,mediaType:n.mediaType,title:n.title,filename:n.filename,providerMetadata:n.providerMetadata};break;case"file":yield{type:"file",url:_(n.file.mediaType,n.file.base64),mediaType:n.file.mediaType,providerMetadata:n.providerMetadata};break;case"reasoning-file":yield{type:"reasoning-file",url:_(n.file.mediaType,n.file.base64),mediaType:n.file.mediaType,providerMetadata:n.providerMetadata};break;case"start-step":yield{type:"start-step"};break;case"finish-step":o=n.usage,u=n.performance,yield{type:"finish-step"};break;case"finish":yield*N(s,a),l=!0,yield{type:"finish",finishReason:n.finishReason,messageMetadata:le(o??n.totalUsage,u)};break;case"abort":yield{type:"abort",reason:n.reason};break;case"error":yield{type:"error",errorText:q(n.error)};break}if(!l)yield*N(s,a),yield{type:"finish"}}function le(t,e){if(t?.totalTokens==null&&t?.outputTokens==null&&e?.outputTokensPerSecond==null)return;return{...t?.totalTokens==null&&t?.outputTokens==null?{}:{usage:{...t.totalTokens==null?{}:{totalTokens:t.totalTokens},...t.outputTokens==null?{}:{outputTokens:t.outputTokens}}},...e?.outputTokensPerSecond==null?{}:{performance:{outputTokensPerSecond:e.outputTokensPerSecond}}}}function*N(t,e){for(let r of t)yield{type:"text-end",id:r};t.clear();for(let r of e)yield{type:"reasoning-end",id:r};e.clear()}function ue(t,e){return{id:t,role:"user",parts:[{type:"text",text:e}]}}function D(t,e,r){if(r&&t.at(-1)?.role==="assistant"){t[t.length-1]=e;return}t.push(e)}function I(t){let e=t.at(-1);return e?.role==="assistant"?e:void 0}function ce(t){let e=[];for(let[r,s]of t.parts.entries()){if(!Q(s)||s.state!=="approval-requested"||s.approval.isAutomatic===!0)continue;e.push({approvalId:s.approval.id,toolCallId:s.toolCallId,toolName:re(s),title:s.title,input:s.input,providerExecuted:s.providerExecuted,messageId:t.id,partIndex:r})}return e}function de(t,e,r){let s=t.parts[e.partIndex];if(!s||!Q(s)||s.toolCallId!==e.toolCallId)throw Error(`Could not find tool approval request ${e.approvalId}.`);s.state="approval-responded",s.approval={id:e.approvalId,approved:r.approved,...r.reason?{reason:r.reason}:{}}}function q(t){if(t instanceof Error)return t.message;if(typeof t==="string")return t;return JSON.stringify(t)}function _(t,e){return`data:${t};base64,${e}`}function V(t){return t instanceof Error&&t.message==="Interrupted"}async function X(t){await new ae(t).run()}import{convertToModelMessages as pe,generateId as P,toTextStream as he,toUIMessageStream as fe}from"ai";async function $e(t){if(t.prompt!==void 0)me(t.prompt);await X({title:`broods · ${t.agent.name}`,tools:"full",transport:new tt(t.client,t.agent)})}async function Ce(t){let e=he({stream:et(t.client.stream(t.agent,{input:t.prompt}),void 0,()=>{})});for await(let r of e)process.stdout.write(r);process.stdout.write(`
19
+ `)}async function me(t){let e=process.stdin.listenerCount("data"),r=Date.now()+1e4;while(process.stdin.listenerCount("data")<=e){if(Date.now()>r)return;await new Promise((s)=>setTimeout(s,20))}process.stdin.emit("data",Buffer.from(t)),process.stdin.emit("data",Buffer.from("\r"))}class tt{client;agent;conversationKey=`tui-${P()}`;sentApprovals=new Set;sentUserTurns=0;constructor(t,e){this.client=t;this.agent=e}async reconnectToStream(){return null}async sendMessages(t){let e=this.pendingEvents(await pe(t.messages));if(e.events.length===0)throw Error("Nothing new to send: the agent already saw this turn.");let r=this.client.stream(this.agent,{conversationKey:this.conversationKey,events:e.events});return fe({stream:et(r,t.abortSignal,e.commit),originalMessages:t.messages,generateMessageId:P,sendSources:!0})}pendingEvents(t){let e=[],r=[],s=0;for(let a of t){if(a.role==="user"){if(s+=1,s>this.sentUserTurns)e.push(a);continue}if(a.role!=="tool")continue;for(let i of a.content)if(i.type==="tool-approval-response"&&!this.sentApprovals.has(i.approvalId))r.push(i)}if(r.length>0)e.push({role:"tool",content:r});return{events:e,commit:()=>{this.sentUserTurns=s;for(let a of r)this.sentApprovals.add(a.approvalId)}}}}function ge(t){return new Promise((e)=>{if(!t)return;let r=()=>e({done:!0,value:void 0});if(t.aborted)r();else t.addEventListener("abort",r,{once:!0})})}function et(t,e,r){let s=!1,a=()=>void t.return(void 0);return new ReadableStream({pull:async function(i){let o=await Promise.race([t.next(),ge(e)]);if(e?.aborted){a(),i.close();return}if(!s)s=!0,r();if(o.done)i.close();else i.enqueue(o.value)},cancel:a})}export{$e as runAgentTui,Ce as streamAgentText};