broods 0.39.1 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.js +1 -1
- package/dist/{chunk-hd4f1h39.js → chunk-3fdkn6mk.js} +1 -1
- package/dist/chunk-3gnqn6ap.js +66 -0
- package/dist/chunk-5epfg4tw.js +5 -0
- package/dist/chunk-8bsz0vkr.js +4 -0
- package/dist/{chunk-9m85p3e3.js → chunk-keg0nsm2.js} +2 -2
- package/dist/chunk-n0kwmhw4.js +1 -0
- package/dist/chunk-p56s3q1t.js +15 -0
- package/dist/chunk-pf07c5ff.js +1 -0
- package/dist/{chunk-gtn2fwy2.js → chunk-ymkt9r21.js} +1 -1
- package/dist/cli/index.js +81 -100
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-9ex5d29v.js +0 -5
- package/dist/chunk-ccd2bc7s.js +0 -4
- package/dist/chunk-ck8t5hr5.js +0 -1
- package/dist/chunk-g60t36xv.js +0 -1
- package/dist/chunk-js5cjmhp.js +0 -66
- package/dist/chunk-qkytyr75.js +0 -15
package/dist/account.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{h,Oe,B,Z}from"./chunk-keg0nsm2.js";export{h as BroodsAccountApiError,Z as BroodsAccountClient,Oe as envPlaceholder,B as resolveEnvCredential};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{y,
|
|
1
|
+
import{y,de,pe,Ee}from"./chunk-3gnqn6ap.js";var c=()=>{let a={string:{unit:"characters",verb:"to have"},file:{unit:"bytes",verb:"to have"},array:{unit:"items",verb:"to have"},set:{unit:"items",verb:"to have"},map:{unit:"entries",verb:"to have"}};function n(t){return a[t]??null}let d={regex:"input",email:"email address",url:"URL",emoji:"emoji",uuid:"UUID",uuidv4:"UUIDv4",uuidv6:"UUIDv6",nanoid:"nanoid",guid:"GUID",cuid:"cuid",cuid2:"cuid2",ulid:"ULID",xid:"XID",ksuid:"KSUID",datetime:"ISO datetime",date:"ISO date",time:"ISO time",duration:"ISO duration",ipv4:"IPv4 address",ipv6:"IPv6 address",mac:"MAC address",cidrv4:"IPv4 range",cidrv6:"IPv6 range",base64:"base64-encoded string",base64url:"base64url-encoded string",json_string:"JSON string",e164:"E.164 number",jwt:"JWT",template_literal:"input"},o={nan:"NaN"};return(t)=>{switch(t.code){case"invalid_type":{let e=o[t.expected]??t.expected,r=Ee(t.input),l=o[r]??r;return`Invalid input: expected ${e}, received ${l}`}case"invalid_value":if(t.values.length===1)return`Invalid input: expected ${pe(t.values[0])}`;return`Invalid option: expected one of ${de(t.values,"|")}`;case"too_big":{let e=t.inclusive?"<=":"<",r=n(t.origin);if(r)return`Too big: expected ${t.origin??"value"} to have ${e}${t.maximum.toString()} ${r.unit??"elements"}`;return`Too big: expected ${t.origin??"value"} to be ${e}${t.maximum.toString()}`}case"too_small":{let e=t.inclusive?">=":">",r=n(t.origin);if(r)return`Too small: expected ${t.origin} to have ${e}${t.minimum.toString()} ${r.unit}`;return`Too small: expected ${t.origin} to be ${e}${t.minimum.toString()}`}case"invalid_format":{let e=t;if(e.format==="starts_with")return`Invalid string: must start with "${e.prefix}"`;if(e.format==="ends_with")return`Invalid string: must end with "${e.suffix}"`;if(e.format==="includes")return`Invalid string: must include "${e.includes}"`;if(e.format==="regex")return`Invalid string: must match pattern ${e.pattern}`;return`Invalid ${d[e.format]??t.format}`}case"not_multiple_of":return`Invalid number: must be a multiple of ${t.divisor}`;case"unrecognized_keys":return`Unrecognized key${t.keys.length>1?"s":""}: ${de(t.keys,", ")}`;case"invalid_key":return`Invalid key in ${t.origin}`;case"invalid_union":if(t.options&&Array.isArray(t.options)&&t.options.length>0)return`Invalid discriminator value. Expected ${t.options.map((r)=>`'${r}'`).join(" | ")}`;return"Invalid input";case"invalid_element":return`Invalid value in ${t.origin}`;default:return"Invalid input"}}};function i(){return{localeError:c()}}y(i());
|
|
@@ -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 fe=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??fe,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 he(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 fe.add(h,{description:m}),h},meta(...m){if(m.length===0)return fe.get(this);let h=this.clone();return fe.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 fe.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(he(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,he,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,5 @@
|
|
|
1
|
+
function V(e){if(e.events&&e.input!==void 0)throw Error("Run input accepts either `input` or `events`, not both");if(e.events&&e.events.length>0)return e.events;if(typeof e.input==="string")return[{role:"user",content:[{type:"text",text:e.input}]}];throw Error("Run input requires `input` (string) or a non-empty `events` array")}async function*ge(e){let n=e.getReader(),t=new TextDecoder,o="";try{while(!0){let{done:r,value:s}=await n.read();if(r)break;o+=t.decode(s,{stream:!0});let i=o.split(`
|
|
2
|
+
`);o=i.pop()??"";for(let a of i)if(a.startsWith("data: "))yield a.slice(6)}}finally{n.releaseLock()}}var Me=500,be=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,he=/^(?!0{32}$)[0-9a-f]{32}$/;function Te(e){return e==="DEBUG"||e==="INFO"||e==="WARN"||e==="ERROR"}function Ne(e){if(typeof e!=="object"||e===null)return!1;let n=e;if(n.type==="subscribe")return Re(n);if(n.type==="unsubscribe")return N(n.stream);if(n.type==="fetchTrace")return Ie(n.traceId);return!1}function je(e){return e==="task"||e==="cron"||e==="subtask"}function W(e){return typeof e==="string"&&be.test(e)}function Ie(e){return typeof e==="string"&&he.test(e)}function N(e){return e==="logs"||e==="traces"}function Re(e){let n=e.stream;if(!N(n))return!1;let t=e.backfill;if(t!==void 0&&(typeof t!=="number"||!Number.isSafeInteger(t)||t<0||t>500))return!1;if(e.liveOnly!==void 0&&typeof e.liveOnly!=="boolean")return!1;let o=e.minLevel;if(o!==void 0&&!Te(o))return!1;let r=e.sandboxId;return r===void 0||n==="logs"&&W(r)}import{readFileSync as Ce}from"node:fs";import{chmod as H,mkdir as Se,writeFile as ke}from"node:fs/promises";import{homedir as Ae}from"node:os";import{dirname as T,join as ve}from"node:path";var S="broods",_="_generated",O=ve(Ae(),".broods","config.json"),P="broods.app",B="dashboard",we="gateway";function z(e){let n=process.env.BROODS_TOKEN,t=e??process.env.BROODS_BASE_URL;if(n&&t)return{baseUrl:f(t),token:n,createdAt:new Date().toISOString()};let o=j();if(!o)return null;if(t)return o.logins[f(t)]??null;let r=process.env.BROODS_DASHBOARD_URL;if(r){let s=f(r);return Object.values(o.logins).find((i)=>i.dashboardUrl===s)??null}return o.logins[o.current]??null}async function G(e){let n=j()?.logins??{},t={current:e.baseUrl,logins:{...n,[e.baseUrl]:e}};await Se(T(O),{recursive:!0,mode:448}),await H(T(O),448),await K(O,`${JSON.stringify(t,null,2)}
|
|
3
|
+
`)}async function K(e,n){await ke(e,n,{encoding:"utf8",mode:384}),await H(e,384)}function b(){return process.env.BROODS_STAGE}function f(e){let n=e.length;while(n>0&&e.charCodeAt(n-1)===47)n-=1;return e.slice(0,n)}function D(e){try{let n=new URL(e);if(!n.hostname.startsWith(`${B}.`))return;let t=n.hostname.slice(B.length+1);if(t!==P&&!t.endsWith(`.${P}`))return;return n.hostname=`${we}.${t}`,f(n.origin)}catch{return}}function j(){try{let e=JSON.parse(Ce(O,"utf8"));if(typeof e.current!=="string"||!e.logins)return null;return{current:e.current,logins:e.logins}}catch{return null}}import{existsSync as q,readFileSync as Z,statSync as Ee}from"node:fs";import{join as X,resolve as Q}from"node:path";var M=new Map,Oe=new Set(Object.keys(process.env)),F=new Set;function m(e=process.cwd()){Pe(e);let n=z();return{dashboardUrl:process.env.BROODS_DASHBOARD_URL??n?.dashboardUrl,baseUrl:process.env.BROODS_BASE_URL??n?.baseUrl,token:n?.token,project:process.env.BROODS_PROJECT,stage:b()}}function L(){let e={};for(let[n,t]of Object.entries(process.env))if(typeof t==="string"&&!n.startsWith("BROODS_"))e[n]=t;return e}function A(e,n=process.cwd()){let t=process.env[e];if(t===void 0)return!1;let o=Q(n);for(let r of[".env.local",".env"]){let s=X(o,r);if(!q(s))continue;let i=ee(Z(s,"utf8"));if(i[e]!==void 0)return i[e]!==t}return!0}function Pe(e){let n=Q(e),t=process.env.BROODS_RELOAD_ENV==="1";for(let o of[".env",".env.local"]){let r=X(n,o);if(!q(r)){M.delete(r);continue}let s=Ee(r).mtimeMs,i=M.get(r);if(i&&i.mtimeMs===s)continue;M.set(r,{mtimeMs:s});for(let[a,u]of Object.entries(ee(Z(r,"utf8"))))if(t||!Oe.has(a)||F.has(a))process.env[a]=u,F.add(a)}}function ee(e){let n={};for(let t of e.split(/\r?\n/)){let o=t.trim();if(!o||o.startsWith("#"))continue;let r=o.startsWith("export ")?o.slice(7).trim():o,s=r.indexOf("=");if(s<=0)continue;let i=r.slice(0,s).trim();if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(i))continue;n[i]=$e(r.slice(s+1).trim())}return n}function $e(e){if(e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1).replace(/\\n/g,`
|
|
4
|
+
`).replace(/\\"/g,'"');if(e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);let n=e.indexOf(" #");return n>=0?e.slice(0,n).trimEnd():e}var E="https://gateway.broods.app";class ye extends Error{accepted;constructor(e){super(`Ingress ${e.eventId} was accepted asynchronously with status ${e.status??"queued"}`);this.accepted=e;this.name="IngressAcceptedError"}}class U{baseUrl;apiKey;fetchImpl;constructor(e={}){m(),this.baseUrl=J(e.baseUrl||e.host||process.env.BROODS_BASE_URL||process.env.BROODS_HOST||E),this.apiKey=e.apiKey||process.env.BROODS_API_KEY||void 0,this.fetchImpl=e.fetch??fetch}channelWebhookUrl(e){return`${this.baseUrl}${e.webhookPath.startsWith("/")?"":"/"}${e.webhookPath}`}accountWebhookUrl(e,n){let t=[e,n].map(encodeURIComponent);return`${this.baseUrl}/v1/webhooks/${t.join("/")}`}stageWebhookUrl(e,n,t){let o=[e,"dev",n,t].map(encodeURIComponent);return`${this.baseUrl}/v1/webhooks/${o.join("/")}`}agent(e,n){if(typeof e==="string"){let o=e,r=n??"";if(!r)throw Error(`Agent ${o} is missing a generated id. Run broods dev --once or broods deploy to sync it first.`);return{id:r,run:(s)=>this.run({...s,agentName:o,agentId:r}),runAsync:(s)=>this.runAsync({...s,agentName:o,agentId:r}),continue:(s)=>this.continue({...s,agentId:r}),stream:(s)=>this.stream({...s,agentName:o,agentId:r})}}let t=e;if(!t.id)throw Error(`Agent ${t.name} is missing a generated id. Run broods dev --once or broods deploy to sync it first.`);return{id:t.id,run:(o)=>this.run(t,o),runAsync:(o)=>this.runAsync(t,o),continue:(o)=>this.continue(t,o),stream:(o)=>this.stream(t,o)}}async run(e,n){let t=[],o="",r=n?this.stream(e,n):this.stream(e);for await(let s of r)if(t.push(s),s.type==="text-delta")o+=s.text;return{text:o,events:t}}async*stream(e,n){let t=n?{...n,agentId:e.id,agentName:e.name}:e,o=ne(t,"cli"),r=n?this.scopedUrl(e):`${this.baseUrl}/v1/runs`,s=await this.openStream(o,r);if(!s.ok)throw Error(`Run failed: ${s.status} ${await s.text()}`);if(s.status===202)throw new ye(te(await s.json(),o));if(!s.body)throw Error("Run response has no body");for await(let i of ge(s.body)){let a;try{a=JSON.parse(i)}catch{continue}if(a.type==="error")throw Error(`Agent run failed: ${_e(a.error)}`);yield a}}async runAsync(e,n){let t=n?{...n,agentId:e.id,agentName:e.name}:e,o={...ne(t,"async"),background:!0},r=n?this.scopedUrl(e):`${this.baseUrl}/v1/runs`;return this.postAcceptedRun(r,o,"Async run")}async continue(e,n){let t=n?e:null,o=n??e,r={agentId:t?t.id:e.agentId,eventId:o.eventId??`continue-${crypto.randomUUID()}`,conversationKey:o.conversationKey,continue:!0},s=t?this.scopedUrl(t):`${this.baseUrl}/v1/runs`;return this.postAcceptedRun(s,r,"Continue")}async getAsyncStatus(e){let n=this.resolveStatusUrl(e),t=await this.fetchJson(n,{method:"GET",headers:this.apiKeyHeaders()});if(t.status===404)return{status:"not_found"};if(!t.ok)throw Error(`Status check failed: ${t.status} ${await t.text()}`);return await t.json()}async waitForAsyncStatus(e,n={}){let t=Date.now()+(n.timeoutMs??180000),o=n.intervalMs??2000;while(Date.now()<t){if(n.signal?.aborted)throw Error("Async status polling aborted.");let r=await this.getAsyncStatus(e);if(r.status==="awaiting_approval"||r.status==="awaiting_input"||r.status==="completed"||r.status==="failed"||r.status==="expired"||r.status==="not_found")return r;await tn(o,n.signal)}throw Error("Polling timeout")}async createCron(e){let n=await this.fetchJson(`${this.baseUrl}/v1/crons`,{method:"POST",headers:this.apiKeyHeaders(),body:JSON.stringify(en(e))});if(n.status!==201)throw Error(`Create cron job failed: ${n.status} ${await n.text()}`);return await n.json()}async listCrons(){let e=await this.fetchJson(`${this.baseUrl}/v1/crons`,{method:"GET",headers:this.apiKeyHeaders()});if(!e.ok)throw Error(`List cron jobs failed: ${e.status} ${await e.text()}`);return(await e.json()).crons}async getCron(e){let n=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(e)}`,{method:"GET",headers:this.apiKeyHeaders()});if(n.status===404)return null;if(!n.ok)throw Error(`Get cron job failed: ${n.status} ${await n.text()}`);return await n.json()}async listCronRuns(e,n={}){let t=new URLSearchParams;if(n.limit!==void 0)t.set("limit",String(n.limit));let o=t.size>0?`?${t}`:"",r=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(e)}/runs${o}`,{method:"GET",headers:this.apiKeyHeaders()});if(!r.ok)throw Error(`List cron job runs failed: ${r.status} ${await r.text()}`);return(await r.json()).runs}async updateCron(e,n){let t=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(e)}`,{method:"PATCH",headers:this.apiKeyHeaders(),body:JSON.stringify(n)});if(!t.ok)throw Error(`Update cron job failed: ${t.status} ${await t.text()}`);return await t.json()}async deleteCron(e){let n=await this.fetchJson(`${this.baseUrl}/v1/crons/${encodeURIComponent(e)}`,{method:"DELETE",headers:this.apiKeyHeaders()});if(n.status===404)return!1;if(!n.ok)throw Error(`Delete cron job failed: ${n.status} ${await n.text()}`);return(await n.json()).deleted}scopedUrl(e){if(e.projectSlug&&e.stageSlug&&e.endpointId)return`${this.baseUrl}/v1/projects/${encodeURIComponent(e.projectSlug)}/stages/${encodeURIComponent(e.stageSlug)}/agents/${encodeURIComponent(e.endpointId)}`;return`${this.baseUrl}/v1/runs`}asyncAgentRun(e,n){return{...e,conversationKey:n,poll:()=>this.getAsyncStatus(e),wait:(t)=>this.waitForAsyncStatus(e,t)}}async postAcceptedRun(e,n,t){let o=await this.fetchJson(e,{method:"POST",headers:this.apiKeyHeaders(),body:JSON.stringify(n)});if(o.status!==202)throw Error(`${t} failed: ${o.status} ${await nn(o,"202 JSON")}`);return this.asyncAgentRun(te(await o.json(),n),n.conversationKey)}async openStream(e,n){if(this.apiKey)return await this.fetchCore(e,n,{Authorization:`Bearer ${this.apiKey}`});throw Error(`BroodsClient streams directly from the core service at ${this.baseUrl}. Provide apiKey. For a self-hosted core service, set host/baseUrl or BROODS_HOST/BROODS_BASE_URL.`)}async fetchCore(e,n,t){try{return await this.fetchImpl(n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...t},body:JSON.stringify(e)})}catch(o){throw Error(`Cannot access the broods core service at ${n}. The SDK uses ${E} by default; set host/baseUrl or BROODS_HOST/BROODS_BASE_URL to your own core service URL if your account uses a custom deployment. Cause: ${o instanceof Error?o.message:String(o)}`)}}apiKeyHeaders(){if(!this.apiKey)throw Error("BroodsClient requires apiKey or BROODS_API_KEY.");return{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`}}async fetchJson(e,n){try{return await this.fetchImpl(e,{...n,headers:{"Content-Type":"application/json",...n.headers}})}catch(t){throw Error(`Cannot access the broods core service at ${e}. Cause: ${t instanceof Error?t.message:String(t)}`)}}resolveStatusUrl(e){if(typeof e!=="string")return e.statusUrl;if(/^https?:\/\//.test(e))return e;return on(this.baseUrl,e)}}function J(e){let n=e.trim(),t=/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(n)?n:`https://${n}`;return f(t)}function ne(e,n){let t=e.eventId??`${n}-${Date.now()}`;return{agentId:e.agentId,eventId:t,conversationKey:e.conversationKey??t,events:V(e),...e.mode!==void 0?{mode:e.mode}:{},...e.idempotencyKey!==void 0?{idempotencyKey:e.idempotencyKey}:{},...e.system!==void 0?{system:e.system}:{},...e.model!==void 0?{model:e.model}:{}}}function _e(e){if(typeof e==="string")return e;if(!e||typeof e!=="object")return String(e);let n=e,t=n.data?.error?.message??n.message??n.responseBody??JSON.stringify(e),o=n.name?`${n.name}: `:"",r=n.statusCode?` (HTTP ${n.statusCode})`:"";return`${o}${t}${r}`}function te(e,n){if(!e||typeof e!=="object")throw Error("Async response must be an object");let t=e.statusUrl;if(typeof t!=="string"||t.length===0)throw Error("Async response missing statusUrl");let o=typeof e.runId==="string"?e.runId:ze(t);if(!o)throw Error("Async response missing runId");let r=typeof e.eventId==="string"?e.eventId:o,{status:s,requestedMode:i}=e;return{statusUrl:t,runId:o,eventId:r,agentId:n.agentId,...s==="accepted"||s==="queued"||s==="applied"||s==="processing"?{status:s}:{},...i==="reject"||i==="followup"||i==="collect"||i==="steer"?{requestedMode:i}:{}}}function ze(e){let n=new URL(e).pathname.match(/\/v1\/runs\/([^/]+)$/);return n?.[1]?decodeURIComponent(n[1]):void 0}function en(e){if("agentId"in e)return e;let n=e.agent,t=typeof n==="string"?n:n.id,{agent:o,...r}=e;return{...r,agentId:t}}async function nn(e,n){if((e.headers.get("content-type")??"").toLowerCase().includes("text/event-stream"))return await e.body?.cancel().catch(()=>{}),`expected ${n}, but the server returned an SSE stream. This usually means the core deployment ignored the background flag and ran the request on the direct streaming runner.`;let o=await e.text();if(o.length<=2000)return o;return`${o.slice(0,2000)}... [truncated ${o.length-2000} chars]`}function tn(e,n){return new Promise((t,o)=>{if(n?.aborted){o(Error("Async status polling aborted."));return}let r=setTimeout(t,e);n?.addEventListener("abort",()=>{clearTimeout(r),o(Error("Async status polling aborted."))},{once:!0})})}function on(e,n){return`${J(e)}/v1/runs/${encodeURIComponent(n)}`}var rn=2000,oe=0,R=1;class xe{baseUrl;apiKey;WebSocketImpl;connectTimeoutMs;constructor(e={}){if(m(),this.baseUrl=ue(e.baseUrl||e.host||process.env.BROODS_BASE_URL||process.env.BROODS_HOST||E),this.apiKey=e.apiKey||process.env.BROODS_API_KEY||"",!this.apiKey)throw Error("BroodsWebSocketClient requires apiKey or BROODS_API_KEY.");this.WebSocketImpl=e.WebSocket,this.connectTimeoutMs=e.connectTimeoutMs??rn}subscribe(e,n={}){let t=this.resolveWebSocket(),o=this.buildUrl(e),r=sn(e),s=ce(this.baseUrl),i=new t(o,C(this.apiKey)),a=!1,u=!1,l=setTimeout(()=>{if(!a)h(s)},this.connectTimeoutMs),v=(c=1000,x="client closed")=>{if(u)return;if(u=!0,clearTimeout(l),e.signal?.removeEventListener("abort",I),i.readyState===R||i.readyState===oe)i.close(c,x)},h=(c)=>{n.onError?.(c),v(1011,"websocket error")},me=()=>{n.onDone?.(),v(1000,"done")},I=()=>{if(i.readyState===R)i.send(JSON.stringify({type:"cancel"}));h(Error("WebSocket run aborted."))};return e.signal?.addEventListener("abort",I,{once:!0}),i.onopen=()=>{if(a=!0,clearTimeout(l),e.signal?.aborted){I();return}i.send(JSON.stringify({type:"execute",agentId:r,...e.answers?{answers:e.answers}:{events:V(e)},sessionId:e.sessionId,...e.eventId!==void 0?{eventId:e.eventId}:{},...e.mode!==void 0?{mode:e.mode}:{},...e.idempotencyKey!==void 0?{idempotencyKey:e.idempotencyKey}:{},...e.system!==void 0?{system:e.system}:{},...e.model!==void 0?{model:e.model}:{}}))},i.onmessage=(c)=>{if(typeof c.data!=="string")return;let x=se(c.data);if(!x)return;let k=ae(x,n);switch(n.onMessage?.(k),k.type){case"meta":n.onMeta?.(k);break;case"done":me();break;case"error":h(Error(re(k.error)));break}},i.onerror=()=>{h(s)},i.onclose=(c)=>{if(clearTimeout(l),e.signal?.removeEventListener("abort",I),u||c.code===1000)return;h(Error(c.reason||"WebSocket connection closed."))},{url:o,sendControl:function(c){if(i.readyState!==R)throw Error("WebSocket is not open");i.send(JSON.stringify({type:"control",...c}))},close:v}}attach(e,n={}){let t=this.resolveWebSocket(),o=this.buildUrl(e),r=new t(o,C(this.apiKey)),s=!1,i=(a=1000,u="client closed")=>{if(s)return;if(s=!0,r.readyState===R||r.readyState===oe)r.close(a,u)};return r.onopen=()=>r.send(JSON.stringify({type:"attach",...e,signal:void 0,agent:void 0})),r.onmessage=(a)=>{if(typeof a.data!=="string")return;let u=se(a.data);if(!u)return;let l=ae(u,n);if(n.onMessage?.(l),l.type==="done")n.onDone?.();if(l.type==="error")n.onError?.(Error(re(l.error)))},r.onerror=()=>n.onError?.(ce(this.baseUrl)),r.onclose=(a)=>{if(!s&&a.code!==1000)n.onError?.(Error(a.reason||"WebSocket connection closed."))},{url:o,sendControl:function(a){if(r.readyState!==R)throw Error("WebSocket is not open");r.send(JSON.stringify({type:"control",...a}))},close:i}}async*stream(e){let n=[],t=!1,o=null,r=null,s=()=>{r?.(),r=null},i=this.subscribe(e,{onMessage:function(a){n.push(a),s()},onDone:function(){t=!0,s()},onError:function(a){o=a,s()}});try{while(!0){if(n.length>0){yield n.shift();continue}if(o)throw o;if(t)return;await new Promise((a)=>{r=a})}}finally{i.close()}}buildUrl(e){let n=an(e),t=e.projectSlug??e.agent?.projectSlug,o=e.stageSlug??e.agent?.stageSlug,r=t&&o?`/projects/${encodeURIComponent(t)}/stages/${encodeURIComponent(o)}`:"";return`${Y(this.baseUrl)}/v1${r}/agents/${encodeURIComponent(n)}/ws`}resolveWebSocket(){let e=this.WebSocketImpl??globalThis.WebSocket;if(!e)throw Error("WebSocket is not available. Pass a WebSocket implementation in BroodsWebSocketClient options.");return e}}function Y(e){let n=new URL(ue(e));if(n.protocol==="https:")n.protocol="wss:";if(n.protocol==="http:")n.protocol="ws:";return f(n.toString())}function C(e){return["broods.v1",`broods.token.${e}`]}function re(e){if(typeof e==="string")return e;if(e&&typeof e==="object"&&typeof e.message==="string")return e.message;return e===void 0?"WebSocket stream error.":JSON.stringify(e)}function ue(e){let n=e.trim();if(/^wss?:\/\//.test(n))return f(n);return J(n)}function se(e){try{let n=JSON.parse(e);return typeof n==="object"&&n!==null&&typeof n.type==="string"?n:null}catch{return null}}function sn(e){let n=e.agentId??e.agent?.id??e.endpointId;if(!n)throw Error("WebSocket run requires agent, agentId, or endpointId.");return n}function an(e){let n=e.endpointId??e.agent?.endpointId??e.agent?.id;if(!n)throw Error("WebSocket run requires agent or endpointId.");return n}function ae(e,n){if(e.type!=="output")return e;let t=e;return n.onOutput?.(t),t.data}function ce(e){return Error(`Cannot access the WebSocket service at ${e}.`)}var de=Symbol.for("broods.resource"),pe=Symbol.for("broods.config"),fe=Symbol.for("broods.connection"),le=/^[A-Z][A-Z0-9_]{0,63}$/,qe=new Proxy((e)=>{if(!le.test(e))throw Error("env name must match /^[A-Z][A-Z0-9_]*$/ and be at most 64 characters.");return{__beeblastEnv:!0,name:e}},{get:function(e,n,t){if(typeof n==="string"&&le.test(n))throw Error(`env.${n} is not supported; use env("${n}")`);return Reflect.get(e,n,t)}});function De(e){let{name:n,description:t,...o}=e;return d("agent",n,t,o)}function Le(e){return{[pe]:!0,config:e}}function Ue(e){let{name:n,description:t,...o}=e;return d("cron",n,t,o)}function Fe(e){return e}function Be(e){let{name:n,description:t,...o}=e;return d("mcp",n,t,o)}function Ze(e){let{name:n,description:t,...o}=e;return d("policy",n,t,o)}function He(e){let{name:n,description:t,...o}=e;return d("sandbox",n,t,o)}function Ve(e){let{name:n,description:t,...o}=e;return d("skill",n,t,o)}function We(e){let{name:n,description:t,...o}=e;return d("workspace",n,t,o)}function Ge(e){return y("discord",e)}function Ke(e){return y("github",e)}function Je(e){return y("matrix",e)}function Ye(e){return y("pancake",e)}function Xe(e){return y("slack",e)}function Qe(e){return y("telegram",e)}function et(e){return y("zalo",e)}function tt(e){let{name:n,description:t,channelId:o,guildId:r,...s}=e;return p(n,t,o,r,s)}function nt(e){let{name:n,description:t,repo:o,...r}=e,[s,...i]=o.split("/");if(!s||i.length!==1||!i[0])throw Error(`Channel "${n}" repo must be "owner/name", not "${o}"`);return p(n,t,o,s,r)}function rt(e){let{name:n,description:t,channelId:o,...r}=e;return p(n,t,o,void 0,r)}function ot(e){let{name:n,description:t,conversationId:o,...r}=e;return p(n,t,o,void 0,r)}function st(e){let{name:n,description:t,channelId:o,teamId:r,...s}=e;return p(n,t,o,r,s)}function it(e){let{name:n,description:t,chatId:o,...r}=e;return p(n,t,o,void 0,r)}function at(e){let{name:n,description:t,chatId:o,...r}=e;return p(n,t,o,void 0,r)}function ie(e){return Boolean(e&&typeof e==="object"&&e[pe])}function w(e){return Boolean(e&&typeof e==="object"&&e[fe])}function g(e){return Boolean(e&&typeof e==="object"&&e[de])}function p(e,n,t,o,r){return d("channelRecord",e,n,{...r,externalId:t,...o?{workspaceRef:o}:{}})}function y(e,n){let{partition:t,...o}=n;return{[fe]:!0,kind:"connection",type:e,...t?{partition:t}:{},config:o}}function d(e,n,t,o){return{[de]:!0,kind:e,name:n,...t?{description:t}:{},config:o}}
|
|
5
|
+
export{V,ge,Me,Te,Ne,je,W,Ie,S,_,O,z,G,K,b,f,D,m,L,A,E,ye,U,J,xe,Y,C,qe,De,Le,Ue,Fe,Be,Ze,He,Ve,We,Ge,Ke,Je,Ye,Xe,Qe,et,tt,nt,rt,ot,st,it,at,ie,w,g};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{L,C}from"./chunk-5epfg4tw.js";import{e,o,a,l,n,t,d,R,s,p,r}from"./chunk-3gnqn6ap.js";import{se,fe,q}from"./cli/index.js";import{spawn as te}from"node:child_process";import{hostname as oe}from"node:os";import{performance as A}from"node:perf_hooks";var N=["cursor_position","double_click","hold_key","key","left_click","left_click_drag","left_mouse_down","left_mouse_up","middle_click","mouse_move","right_click","screenshot","scroll","triple_click","type","wait","zoom"];var _={badFrame:{code:4400,reason:"Malformed frame"},occupied:{code:4423,reason:"Already connected from another daemon"},replaced:{code:4409,reason:"Replaced by a newer connection"},unauthorized:{code:4401,reason:"Unauthorized; run broods login"},unknownSandbox:{code:4404,reason:"No machine sandbox with that name in this account"}};var H="/v1/machines/ws",P=t({action:p(N),coordinate:n(o().int()).length(2).optional().describe("[x, y] in screenshot pixels for mouse actions."),start_coordinate:n(o().int()).length(2).optional().describe("[x, y] where a left_click_drag starts."),text:e().optional().describe("Text for type, the key chord for key and hold_key, or modifiers to hold during a click, drag or scroll."),scroll_direction:p(["down","left","right","up"]).optional(),scroll_amount:o().int().min(1).optional().describe("Scroll clicks, default 3."),duration:o().min(0).max(300).optional().describe("Seconds for wait and hold_key."),region:n(o().int()).length(4).optional().describe("[x0, y0, x1, y1] of the screenshot to zoom into."),repeat:o().int().min(1).max(100).optional().describe("How many times to press the key.")}),U=P.extend({type:r("computer"),id:e()}),B=t({type:r("computer-result"),id:e(),text:e().optional(),image:t({data:e(),mediaType:e()}).optional(),app:e().optional(),error:e().optional()}),W=t({type:r("exec"),id:e(),code:e(),cwd:e().optional(),env:s(e(),e()).optional(),timeoutSeconds:o().positive(),outputLimitBytes:o().positive()}),G=t({type:r("hello"),sandbox:e().min(1),hostname:e().optional(),platform:e().optional(),computer:a().optional(),mcp:n(e()).optional(),instance:e().optional(),force:a().optional()}),J=t({type:r("mcp-call"),id:e(),server:e(),tool:e(),args:s(e(),l())}),K=t({type:r("mcp-list"),id:e(),server:e()}),X=t({type:r("mcp-result"),id:e(),result:d({content:n(l())}).optional(),error:e().optional()}),Y=t({type:r("mcp-tools"),id:e(),tools:n(d({name:e(),inputSchema:s(e(),l())})).optional(),error:e().optional()}),Z=t({type:r("ready"),sandboxId:e()}),Q=t({type:r("result"),id:e(),exitCode:o().nullable(),stdout:e(),stderr:e(),durationMs:o(),timedOut:a(),truncated:a()}),V=R("type",[U,W,J,K,Z]),ue=R("type",[B,G,X,Y,Q]);function T(i){let c=new URL(H,i);return c.protocol=c.protocol==="https:"?"wss:":"ws:",c.toString()}function D(i){return ee(V,i)}function ee(i,c){if(typeof c!=="string")return null;try{let u=i.safeParse(JSON.parse(c));return u.success?u.data:null}catch{return null}}var re=new Set([_.occupied.code,_.replaced.code,_.unauthorized.code,_.unknownSandbox.code]),z=72,k=30000,I=1000;function ne(i,c,u){return new Promise((f)=>{let m=A.now(),h=new E(i.outputLimitBytes),w=new E(i.outputLimitBytes),b=!1,x=!1,M=(y,O)=>{if(x)return;if(x=!0,clearTimeout(v),u?.removeEventListener("abort",g),O)w.append(Buffer.from(`${O}
|
|
2
|
+
`));f({type:"result",id:i.id,exitCode:y,stdout:h.text(),stderr:w.text(),durationMs:Math.round(A.now()-m),timedOut:b,truncated:h.truncated||w.truncated})},F=te("bash",["-lc",i.code],{cwd:i.cwd??c,env:{...L(),...i.env},detached:!0,stdio:["ignore","pipe","pipe"]}),S=()=>{if(!F.pid)return;try{process.kill(-F.pid,"SIGKILL")}catch{F.kill("SIGKILL")}},v=setTimeout(()=>{b=!0,S()},i.timeoutSeconds*1000),g=()=>{S(),M(null,"stopped: the daemon closed its socket")};if(u?.addEventListener("abort",g,{once:!0}),F.stdout.on("data",(y)=>h.append(y)),F.stderr.on("data",(y)=>w.append(y)),F.on("error",(y)=>M(null,y.message)),F.on("close",(y)=>M(y)),u?.aborted)g()})}async function we(i){let c=fe(),u=crypto.randomUUID(),f=i.mcpFile?await ce(i.mcpFile,i.log):null,m=i.computer?await ae(i.log):null,h=I;try{while(!i.signal.aborted){let w=Date.now(),b;try{b=await i.credential()}catch(M){if(M instanceof q)throw M;i.log(`stage session unavailable (${M instanceof Error?M.message:String(M)}), retrying in ${Math.round(h/1000)}s`),await se(h,i.signal),h=Math.min(h*2,k);continue}let x=await pe(i,b,u,c,m,f);if(i.signal.aborted)return;if(re.has(x.code))throw Error(x.reason||`core closed the socket (${x.code})`);if(Date.now()-w>k)h=I;i.log(`disconnected (${x.reason||x.code}), reconnecting in ${Math.round(h/1000)}s`),await se(h,i.signal),h=Math.min(h*2,k)}}finally{m?.stop(),await f?.stop()}}class E{#o=[];#e;#t=0;truncated=!1;constructor(i){this.#e=i}append(i){if(this.#t>=this.#e){this.truncated=!0;return}let c=this.#e-this.#t;if(i.byteLength>c){this.#o.push(i.subarray(0,c)),this.#t=this.#e,this.truncated=!0;return}this.#o.push(i),this.#t+=i.byteLength}text(){let i=Buffer.concat(this.#o).toString("utf8");return this.truncated?`${i}
|
|
3
|
+
[output truncated]`:i}}function ie(i){let c=[i.action];if(i.coordinate)c.push(`at ${i.coordinate.join(",")}`);if(i.text!==void 0)c.push(JSON.stringify(j(i.text)));if(i.region)c.push(`region ${i.region.join(",")}`);return c.join(" ")}function j(i){let c=i.trim().split(`
|
|
4
|
+
`)[0]??"";return c.length>z?`${c.slice(0,z)}…`:c}async function ae(i){let{startDesktop:c}=await import("./chunk-5tnnqapc.js"),{display:u,driver:f,permissions:m}=await c(!1);if(i(`computer use on, ${u.width}x${u.height} screenshots`),!m.screenRecording||!m.accessibility)i(" screen recording or accessibility is missing, run `broods machine --doctor --request`");return f}async function ce(i,c){let{McpHost:u,readMcpServersFile:f}=await import("./chunk-n0kwmhw4.js"),m=new u(f(i),c);return c(`mcp servers from ${i}: ${m.names().join(", ")}`),m}async function le(i,c,u){try{if(i.type==="mcp-list"){let m=await c.listTools(i.server);return u(` mcp ${i.server}: ${m.length} tools`),{type:"mcp-tools",id:i.id,tools:m}}u(` mcp ${i.server}.${i.tool}`);let f=await c.callTool(i.server,i.tool,i.args);return{type:"mcp-result",id:i.id,result:f}}catch(f){let m=f instanceof Error?f.message:String(f);return u(` mcp ${i.server}: ${m}`),{type:i.type==="mcp-call"?"mcp-result":"mcp-tools",id:i.id,error:m}}}function pe(i,c,u,f,m,h){return new Promise((w)=>{let b=new f(T(i.baseUrl),C(c)),x=new AbortController,M=()=>b.close(1000,"daemon stopped"),F=(v)=>{if(b.readyState===b.OPEN)b.send(JSON.stringify(v))},S=(v,g)=>{i.signal.removeEventListener("abort",M),x.abort(),w({code:v,reason:g})};i.signal.addEventListener("abort",M,{once:!0}),b.onopen=()=>F({type:"hello",sandbox:i.sandbox,hostname:oe(),platform:process.platform,computer:m!==null,mcp:h?.names(),instance:u,force:i.force}),b.onmessage=(v)=>{let g=D(v.data);if(g?.type==="ready"){i.log(`connected as ${i.sandbox} (${g.sandboxId})`);return}if(g?.type==="computer"&&m){i.log(` ${ie(g)}`),m.run(g).then((y)=>{if(y.error)i.log(` error: ${y.error}`);F(y)});return}if((g?.type==="mcp-call"||g?.type==="mcp-list")&&h){le(g,h,i.log).then(F);return}if(g?.type!=="exec")return;i.log(`$ ${j(g.code)}`),ne(g,i.cwd,x.signal).then((y)=>{i.log(` exit ${y.exitCode??"none"} in ${y.durationMs}ms${y.timedOut?" (timed out)":""}`),F(y)})},b.onerror=()=>S(1006,"connection failed"),b.onclose=(v)=>S(v.code,v.reason)})}export{we as runMachineDaemon};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var u=/^[A-Z][A-Z0-9_]*$/;class
|
|
2
|
-
export{
|
|
1
|
+
var u=/^[A-Z][A-Z0-9_]*$/;class h extends Error{status;body;constructor(e,t,n,s){super(`${e} ${t} failed with ${n}: ${s}`);this.name="BroodsAccountApiError",this.status=n,this.body=s}}function Oe(e){if(!u.test(e)||e.length>64)throw Error("envPlaceholder name must match /^[A-Z][A-Z0-9_]*$/ and be at most 64 characters.");return`\${${e}}`}function B(){return o("BROODS_SESSION_TOKEN")??o("BROODS_ACCOUNT_SECRET")}class Z{baseUrl;bearerToken;fetchImpl;constructor(e={}){let t=e.baseUrl??o("BROODS_BASE_URL")??"https://gateway.broods.app",n=e.sessionToken??e.accountSecret??B();if(!n)throw Error("BroodsAccountClient requires an accountSecret or sessionToken (or BROODS_ACCOUNT_SECRET / BROODS_SESSION_TOKEN).");let s=t.length;while(s>0&&t.charCodeAt(s-1)===47)s-=1;this.baseUrl=t.slice(0,s),this.bearerToken=n,this.fetchImpl=e.fetch??fetch}async getAccount(){let e=await this.request("GET","/v1/account");if(!e)throw new h("GET","/v1/account",404,"Account not found");return e.account}async updateAccount(e){return(await this.request("PATCH","/v1/account",e))?.account??null}async assumeRole(e,t={}){let n=await this.request("POST","/v1/account/assume-role",{roleId:e,...t.ttlSeconds!==void 0?{ttlSeconds:t.ttlSeconds}:{}});if(!n)throw new h("POST","/v1/account/assume-role",404,"Role not found");return n}async rotateSecret(){let e=await this.request("POST","/v1/account/rotate-secret");if(!e)throw new h("POST","/v1/account/rotate-secret",404,"Account not found");return e}async deleteAccount(){return await this.request("DELETE","/v1/account")??{deleted:!1}}webhookUrl(e,t){let n=[e,t].map(encodeURIComponent);return`${this.baseUrl}/v1/webhooks/${n.join("/")}`}async listAgents(){return(await this.request("GET","/v1/agents"))?.agents??[]}async createAgent(e){let t=await this.request("POST","/v1/agents",e);if(!t)throw new h("POST","/v1/agents",404,"Not found");return t}async getAgent(e){return await this.request("GET",`/v1/agents/${encodeURIComponent(e)}`)}async updateAgent(e,t){return await this.request("PATCH",`/v1/agents/${encodeURIComponent(e)}`,t)}async deleteAgent(e){return(await this.request("DELETE",`/v1/agents/${encodeURIComponent(e)}`))?.deleted??!1}async listEnvVars(){return(await this.request("GET","/v1/env"))?.env??[]}async setEnvVar(e,t){await this.request("PUT",`/v1/env/${encodeURIComponent(e)}`,{value:t})}async deleteEnvVar(e){return(await this.request("DELETE",`/v1/env/${encodeURIComponent(e)}`))?.deleted??!1}async listCrons(){return(await this.request("GET","/v1/crons"))?.crons??[]}async createCron(e){let t=await this.request("POST","/v1/crons",e);if(!t)throw new h("POST","/v1/crons",404,"Not found");return t}async getCron(e){return await this.request("GET",`/v1/crons/${encodeURIComponent(e)}`)}async updateCron(e,t){return await this.request("PATCH",`/v1/crons/${encodeURIComponent(e)}`,t)}async deleteCron(e){return(await this.request("DELETE",`/v1/crons/${encodeURIComponent(e)}`))?.deleted??!1}async listCronRuns(e,t={}){let n=t.limit!==void 0?`?limit=${t.limit}`:"";return(await this.request("GET",`/v1/crons/${encodeURIComponent(e)}/runs${n}`))?.runs??[]}async listWorkspaces(){return(await this.request("GET","/v1/workspaces"))?.workspaces??[]}async createWorkspace(e){let t=await this.request("POST","/v1/workspaces",e);if(!t)throw new h("POST","/v1/workspaces",404,"Not found");return t}async getWorkspace(e){return await this.request("GET",`/v1/workspaces/${encodeURIComponent(e)}`)}async updateWorkspace(e,t){return await this.request("PATCH",`/v1/workspaces/${encodeURIComponent(e)}`,t)}async deleteWorkspace(e){return(await this.request("DELETE",`/v1/workspaces/${encodeURIComponent(e)}`))?.deleted??!1}async listWorkspaceFiles(e){return(await this.request("GET",`/v1/workspaces/${encodeURIComponent(e)}/files`))?.files??[]}async getWorkspaceFileUrl(e,t){let n=`?path=${encodeURIComponent(t)}`;return(await this.request("GET",`/v1/workspaces/${encodeURIComponent(e)}/files${n}`))?.url??null}async uploadWorkspaceFile(e,t){let n=`/v1/workspaces/${encodeURIComponent(e)}/files`,s=await this.request("POST",n,t);if(!s)throw new h("POST",n,404,"Workspace not found");return s.file}async renameWorkspaceFile(e,t,n){return(await this.request("PATCH",`/v1/workspaces/${encodeURIComponent(e)}/files`,{path:t,newPath:n}))?.renamed??!1}async deleteWorkspaceFile(e,t){return(await this.request("DELETE",`/v1/workspaces/${encodeURIComponent(e)}/files`,{path:t}))?.deleted??!1}async listSandboxes(){return(await this.request("GET","/v1/sandboxes"))?.sandboxes??[]}async createSandbox(e){let t=await this.request("POST","/v1/sandboxes",e);if(!t)throw new h("POST","/v1/sandboxes",404,"Not found");return t}async getSandbox(e){return await this.request("GET",`/v1/sandboxes/${encodeURIComponent(e)}`)}async updateSandbox(e,t){return await this.request("PATCH",`/v1/sandboxes/${encodeURIComponent(e)}`,t)}async deleteSandbox(e){return(await this.request("DELETE",`/v1/sandboxes/${encodeURIComponent(e)}`))?.deleted??!1}async suspendSandbox(e,t){return await this.sandboxAction(e,"suspend",{reservationKey:t})}async resumeSandbox(e,t){return await this.sandboxAction(e,"resume",{reservationKey:t})}async terminateSandbox(e,t){return await this.sandboxAction(e,"terminate",{reservationKey:t})}async snapshotSandbox(e,t,n){return await this.sandboxAction(e,"snapshot",{reservationKey:t,name:n})}async openSandboxTerminal(e,t){return await this.sandboxAction(e,"terminal",{reservationKey:t})}async listMcp(e){let t=`/v1/mcp${i(e)}`,n=await this.request("GET",t);if(!n)throw new h("GET",t,404,"Not found");return n.servers??[]}async createMcp(e,t){let n=`/v1/mcp${i(e)}`,s=await this.request("POST",n,t);if(!s)throw new h("POST",n,404,"Not found");return s}async uploadMcpBundle(e){let n=await this.request("POST","/v1/mcp/uploads");if(!n?.uploadUrl)throw new h("POST","/v1/mcp/uploads",502,"response omitted uploadUrl");let s=await this.fetchImpl(n.uploadUrl,{method:"POST",headers:{"Content-Type":"application/javascript"},body:e});if(!s.ok)throw new h("POST","/v1/mcp/uploads",s.status,await s.text());let{storageId:r}=await s.json();if(!r)throw new h("POST","/v1/mcp/uploads",502,"upload response omitted storageId");let a=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e)),c=Array.from(new Uint8Array(a)).map((l)=>l.toString(16).padStart(2,"0")).join("");return{bundleStorageId:r,sha256:c}}async getMcp(e){return await this.request("GET",`/v1/mcp/${encodeURIComponent(e)}`)}async updateMcp(e,t){return await this.request("PATCH",`/v1/mcp/${encodeURIComponent(e)}`,t)}async deleteMcp(e){return(await this.request("DELETE",`/v1/mcp/${encodeURIComponent(e)}`))?.deleted??!1}async listPolicies(){return(await this.request("GET","/v1/policies"))?.policies??[]}async createPolicy(e){let t=await this.request("POST","/v1/policies",e);if(!t)throw new h("POST","/v1/policies",404,"Not found");return t}async getPolicy(e){return await this.request("GET",`/v1/policies/${encodeURIComponent(e)}`)}async updatePolicy(e,t){return await this.request("PATCH",`/v1/policies/${encodeURIComponent(e)}`,t)}async deletePolicy(e){return(await this.request("DELETE",`/v1/policies/${encodeURIComponent(e)}`))?.deleted??!1}async listRoles(){return(await this.request("GET","/v1/roles"))?.roles??[]}async createRole(e){let t=await this.request("POST","/v1/roles",e);if(!t)throw new h("POST","/v1/roles",404,"Not found");return t}async getRole(e){return await this.request("GET",`/v1/roles/${encodeURIComponent(e)}`)}async updateRole(e,t){return await this.request("PATCH",`/v1/roles/${encodeURIComponent(e)}`,t)}async deleteRole(e){return(await this.request("DELETE",`/v1/roles/${encodeURIComponent(e)}`))?.deleted??!1}async listChannels(){return(await this.request("GET","/v1/channels"))?.channels??[]}async createChannel(e){let t=await this.request("POST","/v1/channels",e);if(!t)throw new h("POST","/v1/channels",404,"Not found");return t}async getChannel(e){return await this.request("GET",`/v1/channels/${encodeURIComponent(e)}`)}async updateChannel(e,t){return await this.request("PATCH",`/v1/channels/${encodeURIComponent(e)}`,t)}async deleteChannel(e){return(await this.request("DELETE",`/v1/channels/${encodeURIComponent(e)}`))?.deleted??!1}async listSkills(){return(await this.request("GET","/v1/skills"))?.skills??[]}async createSkill(e){let t=await this.request("POST","/v1/skills",e);if(!t)throw new h("POST","/v1/skills",404,"Not found");return t}async getSkill(e){return await this.request("GET",`/v1/skills/${encodeURIComponent(e)}`)}async uploadSkill(e,t){let n=`/v1/skills/${encodeURIComponent(e)}`,s=await this.request("PUT",n,t);if(!s)throw new h("PUT",n,404,"Skill not found");return s}async deleteSkill(e){return(await this.request("DELETE",`/v1/skills/${encodeURIComponent(e)}`))?.deleted??!1}async sandboxAction(e,t,n){let s=`/v1/sandboxes/${encodeURIComponent(e)}/${t}`,r=await this.request("POST",s,n);if(!r)throw new h("POST",s,404,"Sandbox not found");return r}async request(e,t,n){let s=await this.fetchImpl(`${this.baseUrl}${t}`,{method:e,headers:{Authorization:`Bearer ${this.bearerToken}`,...n!==void 0?{"Content-Type":"application/json"}:{}},...n!==void 0?{body:JSON.stringify(n)}:{}});if(s.status===404)return null;if(!s.ok)throw new h(e,t,s.status,await s.text());return await s.json()}}function o(e){return typeof process<"u"?process?.env?.[e]:void 0}function i(e){return`?${new URLSearchParams({project:e.project,stage:e.stage}).toString()}`}
|
|
2
|
+
export{h,Oe,B,Z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{L}from"./chunk-5epfg4tw.js";import{Ae,e,n,t,s}from"./chunk-3gnqn6ap.js";import{readFileSync as m}from"node:fs";import{dirname as d,resolve as p}from"node:path";import{Client as g}from"@modelcontextprotocol/client";import{StdioClientTransport as h}from"@modelcontextprotocol/client/stdio";var f={name:"broods-machine",version:"1.0.0"},u=t({command:e().min(1),args:n(e()).default([]),env:s(e(),e()).optional(),cwd:e().optional()}),w=t({mcpServers:s(e(),u).refine((r)=>Object.keys(r).length>0,"lists no MCP servers")});class y{#t=new Map;#e;#r;constructor(r,o){this.#r=r,this.#e=o}async callTool(r,o,i){return await(await this.#n(r)).callTool({name:o,arguments:i})}async listTools(r){return(await(await this.#n(r)).listTools()).tools}names(){return[...this.#r.keys()]}async stop(){let r=[...this.#t.values()];this.#t.clear(),await Promise.all(r.map((o)=>o.then((i)=>i.close()).catch(()=>{})))}#n(r){let o=this.#r.get(r);if(!o)return Promise.reject(Error(`no MCP server named "${r}" in the --mcp file`));let i=this.#t.get(r);if(i)return i;let c=(async()=>{this.#e(`mcp ${r}: ${[o.command,...o.args].join(" ")}`);let a=new h({...o,env:{...L(),...o.env},stderr:"inherit"});a.onclose=()=>{if(this.#e(`mcp ${r}: exited`),this.#t.get(r)===c)this.#t.delete(r)};let l=new g(f);return await l.connect(a),l})();return c.catch(()=>{if(this.#t.get(r)===c)this.#t.delete(r)}),this.#t.set(r,c),c}}function b(r){let o=p(r),i=w.safeParse(v(o));if(!i.success)throw Error(`${o}: ${Ae(i.error)}`);return new Map(Object.entries(i.data.mcpServers).map(([c,a])=>[c,a.cwd?{...a,cwd:p(d(o),a.cwd)}:a]))}function v(r){try{return JSON.parse(m(r,"utf8"))}catch(o){throw Error(`could not read ${r}: ${o instanceof Error?o.message:String(o)}`)}}export{y as McpHost,b as readMcpServersFile};
|