@imgly/plugin-ai-image-generation-web
Version:
AI image generation plugin for the CE.SDK editor
5 lines • 243 kB
JavaScript
var so=Object.create;var tr=Object.defineProperty;var lo=Object.getOwnPropertyDescriptor;var uo=Object.getOwnPropertyNames;var co=Object.getPrototypeOf,po=Object.prototype.hasOwnProperty;var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var go=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of uo(t))!po.call(e,n)&&n!==i&&tr(e,n,{get:()=>t[n],enumerable:!(r=lo(t,n))||r.enumerable});return e};var mo=(e,t,i)=>(i=e!=null?so(co(e)):{},go(t||!e||!e.__esModule?tr(i,"default",{value:e,enumerable:!0}):i,e));var _i=S(V=>{"use strict";var kp=V&&V.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(V,"__esModule",{value:!0});V.TARGET_URL_HEADER=void 0;V.withMiddleware=Cp;V.withProxy=Pp;function Cp(...e){let t=i=>typeof i=="function";return i=>kp(this,void 0,void 0,function*(){let r=Object.assign({},i);for(let n of e.filter(t))r=yield n(r);return r})}V.TARGET_URL_HEADER="x-fal-target-url";function Pp(e){let t=i=>Promise.resolve(i);return typeof window>"u"?t:i=>i.headers&&V.TARGET_URL_HEADER in i?t(i):Promise.resolve(Object.assign(Object.assign({},i),{url:e.targetUrl,headers:Object.assign(Object.assign({},i.headers||{}),{[V.TARGET_URL_HEADER]:i.url})}))}});var ie=S(K=>{"use strict";var Wr=K&&K.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(K,"__esModule",{value:!0});K.ValidationError=K.ApiError=void 0;K.defaultResponseHandler=Yr;K.resultResponseHandler=qp;var $p="x-fal-request-id",$e=class extends Error{constructor({message:t,status:i,body:r}){super(t),this.name="ApiError",this.status=i,this.body=r}};K.ApiError=$e;var wt=class extends $e{constructor(t){super(t),this.name="ValidationError"}get fieldErrors(){return typeof this.body.detail=="string"?[{loc:["body"],msg:this.body.detail,type:"value_error"}]:this.body.detail||[]}getFieldErrors(t){return this.fieldErrors.filter(i=>i.loc[i.loc.length-1]===t)}};K.ValidationError=wt;function Yr(e){return Wr(this,void 0,void 0,function*(){var t;let{status:i,statusText:r}=e,n=(t=e.headers.get("Content-Type"))!==null&&t!==void 0?t:"";if(!e.ok){if(n.includes("application/json")){let a=yield e.json(),o=i===422?wt:$e;throw new o({message:a.message||r,status:i,body:a})}throw new $e({message:`HTTP ${i}: ${r}`,status:i})}return n.includes("application/json")?e.json():n.includes("text/html")?e.text():n.includes("application/octet-stream")?e.arrayBuffer():e.text()})}function qp(e){return Wr(this,void 0,void 0,function*(){return{data:yield Yr(e),requestId:e.headers.get($p)||""}})}});var re=S(N=>{"use strict";var Op=N&&N.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(N,"__esModule",{value:!0});N.ensureEndpointIdFormat=Zr;N.parseEndpointId=jp;N.isValidUrl=Mp;N.throttle=Fp;N.isReact=Rp;N.isPlainObject=Np;N.sleep=Bp;function Zr(e){if(e.split("/").length>1)return e;let[,i,r]=/^([0-9]+)-([a-zA-Z0-9-]+)$/.exec(e)||[];if(i&&r)return`${i}/${r}`;throw new Error(`Invalid app id: ${e}. Must be in the format <appOwner>/<appId>`)}var Dp=["workflows","comfy"];function jp(e){let i=Zr(e).split("/");return Dp.includes(i[0])?{owner:i[1],alias:i[2],path:i.slice(3).join("/")||void 0,namespace:i[0]}:{owner:i[0],alias:i[1],path:i.slice(2).join("/")||void 0}}function Mp(e){try{let{host:t}=new URL(e);return/(fal\.(ai|run))$/.test(t)}catch{return!1}}function Fp(e,t,i=!1){let r,n;return(...a)=>{!n&&i?(e(...a),n=Date.now()):(r&&clearTimeout(r),r=setTimeout(()=>{Date.now()-n>=t&&(e(...a),n=Date.now())},t-(Date.now()-n)))}}var bi;function Rp(){if(bi===void 0){let e=new Error().stack;bi=!!e&&(e.includes("node_modules/react-dom/")||e.includes("node_modules/next/"))}return bi}function Np(e){return!!e&&Object.getPrototypeOf(e)===Object.prototype}function Bp(e){return Op(this,void 0,void 0,function*(){return new Promise(t=>setTimeout(t,e))})}});var tt=S(M=>{"use strict";var zp=M&&M.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(M,"__esModule",{value:!0});M.DEFAULT_RETRY_OPTIONS=M.DEFAULT_RETRYABLE_STATUS_CODES=void 0;M.isRetryableError=Jr;M.calculateBackoffDelay=Xr;M.executeWithRetry=Vp;var Up=ie(),Lp=re();M.DEFAULT_RETRYABLE_STATUS_CODES=[429,502,503,504];M.DEFAULT_RETRY_OPTIONS={maxRetries:3,baseDelay:1e3,maxDelay:3e4,backoffMultiplier:2,retryableStatusCodes:M.DEFAULT_RETRYABLE_STATUS_CODES,enableJitter:!0};function Jr(e,t){return e instanceof Up.ApiError&&t.includes(e.status)}function Xr(e,t,i,r,n){let a=Math.min(t*Math.pow(r,e),i);if(n){let o=.25*a*(Math.random()*2-1);return Math.max(0,a+o)}return a}function Vp(e,t,i){return zp(this,void 0,void 0,function*(){let r={totalAttempts:0,totalDelay:0},n;for(let a=0;a<=t.maxRetries;a++){r.totalAttempts++;try{return{result:yield e(),metrics:r}}catch(o){if(n=o,r.lastError=o,a===t.maxRetries||!Jr(o,t.retryableStatusCodes))throw o;let s=Xr(a,t.baseDelay,t.maxDelay,t.backoffMultiplier,t.enableJitter);r.totalDelay+=s,i&&i(a+1,o,s),yield(0,Lp.sleep)(s)}}throw n})}});var en=S((Lf,Kp)=>{Kp.exports={name:"@fal-ai/client",description:"The fal.ai client for JavaScript and TypeScript",version:"1.6.2",license:"MIT",repository:{type:"git",url:"https://github.com/fal-ai/fal-js.git",directory:"libs/client"},keywords:["fal","client","ai","ml","typescript"],exports:{".":"./src/index.js","./endpoints":"./src/types/endpoints.js"},typesVersions:{"*":{endpoints:["src/types/endpoints.d.ts"]}},main:"./src/index.js",types:"./src/index.d.ts",dependencies:{"@msgpack/msgpack":"^3.0.0-beta2","eventsource-parser":"^1.1.2",robot3:"^0.4.1"},engines:{node:">=18.0.0"},type:"commonjs"}});var St=S(xt=>{"use strict";Object.defineProperty(xt,"__esModule",{value:!0});xt.isBrowser=Gp;xt.getUserAgent=Hp;function Gp(){return typeof window<"u"&&typeof window.document<"u"}var It=null;function Hp(){if(It!==null)return It;let e=en();return It=`${e.name}/${e.version}`,It}});var Et=S(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});ne.credentialsFromEnv=void 0;ne.resolveDefaultFetch=nn;ne.createConfig=Xp;ne.getRestApiUrl=eg;var tn=_i(),Qp=ie(),rn=tt(),Wp=St();function nn(){if(typeof fetch>"u")throw new Error("Your environment does not support fetch. Please provide your own fetch implementation.");return fetch}function Yp(){return typeof process<"u"&&process.env&&(typeof process.env.FAL_KEY<"u"||typeof process.env.FAL_KEY_ID<"u"&&typeof process.env.FAL_KEY_SECRET<"u")}var Zp=()=>{if(Yp())return typeof process.env.FAL_KEY<"u"?process.env.FAL_KEY:process.env.FAL_KEY_ID?`${process.env.FAL_KEY_ID}:${process.env.FAL_KEY_SECRET}`:void 0};ne.credentialsFromEnv=Zp;var Jp={credentials:ne.credentialsFromEnv,suppressLocalCredentialsWarning:!1,requestMiddleware:e=>Promise.resolve(e),responseHandler:Qp.defaultResponseHandler,retry:rn.DEFAULT_RETRY_OPTIONS};function Xp(e){var t;let i=Object.assign(Object.assign(Object.assign({},Jp),e),{fetch:(t=e.fetch)!==null&&t!==void 0?t:nn(),retry:Object.assign(Object.assign({},rn.DEFAULT_RETRY_OPTIONS),e.retry||{})});e.proxyUrl&&(i=Object.assign(Object.assign({},i),{requestMiddleware:(0,tn.withMiddleware)(i.requestMiddleware,(0,tn.withProxy)({targetUrl:e.proxyUrl}))}));let{credentials:r,suppressLocalCredentialsWarning:n}=i,a=typeof r=="function"?r():r;return(0,Wp.isBrowser)()&&a&&!n&&console.warn("The fal credentials are exposed in the browser's environment. That's not recommended for production use cases."),i}function eg(){return"https://rest.alpha.fal.ai"}});var qe=S(ae=>{"use strict";var an=ae&&ae.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})},tg=ae&&ae.__rest||function(e,t){var i={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(i[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(i[r[n]]=e[r[n]]);return i};Object.defineProperty(ae,"__esModule",{value:!0});ae.dispatchRequest=rg;ae.buildUrl=ng;var on=tt(),sn=St(),vi=re(),ig=typeof navigator<"u"&&navigator?.userAgent==="Cloudflare-Workers";function rg(e){return an(this,void 0,void 0,function*(){var t;let{targetUrl:i,input:r,config:n,options:a={}}=e,{credentials:o,requestMiddleware:s,responseHandler:d,fetch:u}=n,l=Object.assign(Object.assign({},n.retry),a.retry||{}),c=()=>an(this,void 0,void 0,function*(){var p,h,y;let w=(0,sn.isBrowser)()?{}:{"User-Agent":(0,sn.getUserAgent)()},g=typeof o=="function"?o():o,{method:f,url:b,headers:_}=yield s({method:((h=(p=e.method)!==null&&p!==void 0?p:a.method)!==null&&h!==void 0?h:"post").toUpperCase(),url:i,headers:e.headers}),k=g?{Authorization:`Key ${g}`}:{},P=Object.assign(Object.assign(Object.assign(Object.assign({},k),{Accept:"application/json","Content-Type":"application/json"}),w),_??{}),{responseHandler:H,retry:$}=a,te=tg(a,["responseHandler","retry"]),Q=yield u(b,Object.assign(Object.assign(Object.assign(Object.assign({},te),{method:f,headers:Object.assign(Object.assign({},P),(y=te.headers)!==null&&y!==void 0?y:{})}),!ig&&{mode:"cors"}),{signal:a.signal,body:f.toLowerCase()!=="get"&&r?JSON.stringify(r):void 0}));return yield(H??d)(Q)}),m;for(let p=0;p<=l.maxRetries;p++)try{return yield c()}catch(h){if(m=h,p===l.maxRetries||!(0,on.isRetryableError)(h,l.retryableStatusCodes)||((t=a.signal)===null||t===void 0?void 0:t.aborted))throw h;let w=(0,on.calculateBackoffDelay)(p,l.baseDelay,l.maxDelay,l.backoffMultiplier,l.enableJitter);yield(0,vi.sleep)(w)}throw m})}function ng(e,t={}){var i,r;let n=((i=t.method)!==null&&i!==void 0?i:"post").toLowerCase(),a=((r=t.path)!==null&&r!==void 0?r:"").replace(/^\//,"").replace(/\/{2,}/,"/"),o=t.input,s=Object.assign(Object.assign({},t.query||{}),n==="get"?o:{}),d=Object.keys(s).length>0?`?${new URLSearchParams(s).toString()}`:"";if((0,vi.isValidUrl)(e))return`${e.endsWith("/")?e:`${e}/`}${a}${d}`;let u=(0,vi.ensureEndpointIdFormat)(e);return`${`https://${t.subdomain?`${t.subdomain}.`:""}fal.run/${u}/${a}`.replace(/\/$/,"")}${d}`}});var un=S(wi=>{"use strict";Object.defineProperty(wi,"__esModule",{value:!0});function ag(e){let t,i,r,n,a,o,s;return d(),{feed:u,reset:d};function d(){t=!0,i="",r=0,n=-1,a=void 0,o=void 0,s=""}function u(c){i=i?i+c:c,t&&og(i)&&(i=i.slice(ln.length)),t=!1;let m=i.length,p=0,h=!1;for(;p<m;){h&&(i[p]===`
`&&++p,h=!1);let y=-1,w=n,g;for(let f=r;y<0&&f<m;++f)g=i[f],g===":"&&w<0?w=f-p:g==="\r"?(h=!0,y=f-p):g===`
`&&(y=f-p);if(y<0){r=m-p,n=w;break}else r=0,n=-1;l(i,p,w,y),p+=y+1}p===m?i="":p>0&&(i=i.slice(p))}function l(c,m,p,h){if(h===0){s.length>0&&(e({type:"event",id:a,event:o||void 0,data:s.slice(0,-1)}),s="",a=void 0),o=void 0;return}let y=p<0,w=c.slice(m,m+(y?h:p)),g=0;y?g=h:c[m+p+1]===" "?g=p+2:g=p+1;let f=m+g,b=h-g,_=c.slice(f,f+b).toString();if(w==="data")s+=_?"".concat(_,`
`):`
`;else if(w==="event")o=_;else if(w==="id"&&!_.includes("\0"))a=_;else if(w==="retry"){let k=parseInt(_,10);Number.isNaN(k)||e({type:"reconnect-interval",value:k})}}}var ln=[239,187,191];function og(e){return ln.every((t,i)=>e.charCodeAt(i)===t)}wi.createParser=ag});var Ii=S(oe=>{"use strict";var sg=oe&&oe.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})};Object.defineProperty(oe,"__esModule",{value:!0});oe.TOKEN_EXPIRATION_SECONDS=void 0;oe.getTemporaryAuthToken=dg;var lg=Et(),ug=qe(),cg=re();oe.TOKEN_EXPIRATION_SECONDS=120;function dg(e,t){return sg(this,void 0,void 0,function*(){let i=(0,cg.parseEndpointId)(e),r=yield(0,ug.dispatchRequest)({method:"POST",targetUrl:`${(0,lg.getRestApiUrl)()}/tokens/`,config:t,input:{allowed_apps:[i.alias],token_expiration:oe.TOKEN_EXPIRATION_SECONDS}});return typeof r!="string"&&r.detail?r.detail:r})}});var Si=S(B=>{"use strict";var De=B&&B.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})},it=B&&B.__await||function(e){return this instanceof it?(this.v=e,this):new it(e)},pg=B&&B.__asyncGenerator||function(e,t,i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=i.apply(e,t||[]),n,a=[];return n={},s("next"),s("throw"),s("return",o),n[Symbol.asyncIterator]=function(){return this},n;function o(p){return function(h){return Promise.resolve(h).then(p,c)}}function s(p,h){r[p]&&(n[p]=function(y){return new Promise(function(w,g){a.push([p,y,w,g])>1||d(p,y)})},h&&(n[p]=h(n[p])))}function d(p,h){try{u(r[p](h))}catch(y){m(a[0][3],y)}}function u(p){p.value instanceof it?Promise.resolve(p.value.v).then(l,c):m(a[0][2],p)}function l(p){d("next",p)}function c(p){d("throw",p)}function m(p,h){p(h),a.shift(),a.length&&d(a[0][0],a[0][1])}};Object.defineProperty(B,"__esModule",{value:!0});B.FalStream=void 0;B.createStreamingClient=fg;var gg=un(),mg=Ii(),cn=qe(),Oe=ie(),xi="text/event-stream",hg=15*1e3,Tt=class{constructor(t,i,r){var n;this.listeners=new Map,this.buffer=[],this.currentData=void 0,this.lastEventTimestamp=0,this.streamClosed=!1,this._requestId=null,this.abortController=new AbortController,this.start=()=>De(this,void 0,void 0,function*(){var a,o;let{endpointId:s,options:d}=this,{input:u,method:l="post",connectionMode:c="server"}=d;try{if(c==="client"){let m=yield(0,mg.getTemporaryAuthToken)(s,this.config),{fetch:p}=this.config,h=new URL(this.url);h.searchParams.set("fal_jwt_token",m);let y=yield p(h.toString(),{method:l.toUpperCase(),headers:{accept:(a=d.accept)!==null&&a!==void 0?a:xi,"content-type":"application/json"},body:u&&l!=="get"?JSON.stringify(u):void 0,signal:this.abortController.signal});return this._requestId=y.headers.get("x-fal-request-id"),yield this.handleResponse(y)}return yield(0,cn.dispatchRequest)({method:l.toUpperCase(),targetUrl:this.url,input:u,config:this.config,options:{headers:{accept:(o=d.accept)!==null&&o!==void 0?o:xi},responseHandler:m=>De(this,void 0,void 0,function*(){return this._requestId=m.headers.get("x-fal-request-id"),yield this.handleResponse(m)}),signal:this.abortController.signal}})}catch(m){this.handleError(m)}}),this.handleResponse=a=>De(this,void 0,void 0,function*(){var o,s;if(!a.ok){try{yield(0,Oe.defaultResponseHandler)(a)}catch(y){this.emit("error",y)}return}let d=a.body;if(!d){this.emit("error",new Oe.ApiError({message:"Response body is empty.",status:400,body:void 0}));return}if(!((o=a.headers.get("content-type"))!==null&&o!==void 0?o:"").startsWith(xi)){let y=d.getReader(),w=()=>{y.read().then(({done:g,value:f})=>{if(g){this.emit("done",this.currentData);return}this.currentData=f,this.emit("data",f),w()})};w();return}let l=new TextDecoder("utf-8"),c=a.body.getReader(),m=(0,gg.createParser)(y=>{if(y.type==="event"){let w=y.data;try{let g=JSON.parse(w);this.buffer.push(g),this.currentData=g,this.emit("data",g),this.emit("message",g)}catch(g){this.emit("error",g)}}}),p=(s=this.options.timeout)!==null&&s!==void 0?s:hg,h=()=>De(this,void 0,void 0,function*(){let{value:y,done:w}=yield c.read();this.lastEventTimestamp=Date.now(),m.feed(l.decode(y)),Date.now()-this.lastEventTimestamp>p&&this.emit("error",new Oe.ApiError({message:`Event stream timed out after ${(p/1e3).toFixed(0)} seconds with no messages.`,status:408})),w?this.emit("done",this.currentData):h().catch(this.handleError)});h().catch(this.handleError)}),this.handleError=a=>{var o;if(a.name==="AbortError"||this.signal.aborted)return;let s=a instanceof Oe.ApiError?a:new Oe.ApiError({message:(o=a.message)!==null&&o!==void 0?o:"An unknown error occurred",status:500});this.emit("error",s)},this.on=(a,o)=>{var s;this.listeners.has(a)||this.listeners.set(a,[]),(s=this.listeners.get(a))===null||s===void 0||s.push(o)},this.emit=(a,o)=>{let s=this.listeners.get(a)||[];for(let d of s)d(o)},this.done=()=>De(this,void 0,void 0,function*(){return this.donePromise}),this.abort=a=>{this.streamClosed||this.abortController.abort(a)},this.endpointId=t,this.config=i,this.url=(n=r.url)!==null&&n!==void 0?n:(0,cn.buildUrl)(t,{path:"/stream",query:r.queryParams}),this.options=r,this.donePromise=new Promise((a,o)=>{this.streamClosed&&o(new Oe.ApiError({message:"Streaming connection is already closed.",status:400,body:void 0})),this.signal.addEventListener("abort",()=>{var s;a((s=this.currentData)!==null&&s!==void 0?s:{})}),this.on("done",s=>{this.streamClosed=!0,a(s)}),this.on("error",s=>{this.streamClosed=!0,o(s)})}),r.signal&&r.signal.addEventListener("abort",()=>{this.abortController.abort()}),this.start().catch(this.handleError)}[Symbol.asyncIterator](){return pg(this,arguments,function*(){let i=!0,r=()=>i=!1;for(this.on("error",r),this.on("done",r);i||this.buffer.length>0;){let n=this.buffer.shift();n&&(yield yield it(n)),yield it(new Promise(a=>setTimeout(a,16)))}})}get signal(){return this.abortController.signal}get requestId(){return this._requestId}};B.FalStream=Tt;function fg({config:e,storage:t}){return{stream(i,r){return De(this,void 0,void 0,function*(){let n=r.input?yield t.transformInput(r.input):void 0;return new Tt(i,e,Object.assign(Object.assign({},r),{input:n}))})}}}});var mn=S(se=>{"use strict";var he=se&&se.__awaiter||function(e,t,i,r){function n(a){return a instanceof i?a:new i(function(o){o(a)})}return new(i||(i=Promise))(function(a,o){function s(l){try{u(r.next(l))}catch(c){o(c)}}function d(l){try{u(r.throw(l))}catch(c){o(c)}}function u(l){l.done?a(l.value):n(l.value).then(s,d)}u((r=r.apply(e,t||[])).next())})},yg=se&&se.__rest||function(e,t){var i={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(i[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,r=Object.getOwnPropertySymbols(e);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(i[r[n]]=e[r[n]]);return i};Object.defineProperty(se,"__esModule",{value:!0});se.createQueueClient=void 0;var Z=qe(),_g=ie(),gn=tt(),bg=Si(),At=re(),dn=500,pn={maxRetries:3,baseDelay:1e3,maxDelay:6e4,retryableStatusCodes:gn.DEFAULT_RETRYABLE_STATUS_CODES},vg={maxRetries:5,baseDelay:1e3,maxDelay:3e4,retryableStatusCodes:[...gn.DEFAULT_RETRYABLE_STATUS_CODES,500]},wg=({config:e,storage:t})=>{let i={submit(r,n){return he(this,void 0,void 0,function*(){let{webhookUrl:a,priority:o,hint:s}=n,d=yg(n,["webhookUrl","priority","hint"]),u=n.input?yield t.transformInput(n.input):void 0;return(0,Z.dispatchRequest)({method:n.method,targetUrl:(0,Z.buildUrl)(r,Object.assign(Object.assign({},d),{subdomain:"queue",query:a?{fal_webhook:a}:void 0})),headers:Object.assign({"x-fal-queue-priority":o??"normal"},s&&{"x-fal-runner-hint":s}),input:u,config:e,options:{signal:n.abortSignal,retry:pn}})})},status(r,n){return he(this,arguments,void 0,function*(a,{requestId:o,logs:s=!1,abortSignal:d}){let u=(0,At.parseEndpointId)(a),l=u.namespace?`${u.namespace}/`:"";return(0,Z.dispatchRequest)({method:"get",targetUrl:(0,Z.buildUrl)(`${l}${u.owner}/${u.alias}`,{subdomain:"queue",query:{logs:s?"1":"0"},path:`/requests/${o}/status`}),config:e,options:{signal:d,retry:vg}})})},streamStatus(r,n){return he(this,arguments,void 0,function*(a,{requestId:o,logs:s=!1,connectionMode:d}){let u=(0,At.parseEndpointId)(a),l=u.namespace?`${u.namespace}/`:"",c={logs:s?"1":"0"},m=(0,Z.buildUrl)(`${l}${u.owner}/${u.alias}`,{subdomain:"queue",path:`/requests/${o}/status/stream`,query:c});return new bg.FalStream(a,e,{url:m,method:"get",connectionMode:d,queryParams:c})})},subscribeToStatus(r,n){return he(this,void 0,void 0,function*(){let a=n.requestId,o=n.timeout,s,d=()=>{};if(n.mode==="streaming"){let u=yield i.streamStatus(r,{requestId:a,logs:n.logs,connectionMode:"connectionMode"in n?n.connectionMode:void 0}),l=[];o&&(s=setTimeout(()=>{throw u.abort(),i.cancel(r,{requestId:a}).catch(d),new Error(`Client timed out waiting for the request to complete after ${o}ms`)},o)),u.on("data",m=>{n.onQueueUpdate&&("logs"in m&&Array.isArray(m.logs)&&m.logs.length>0&&l.push(...m.logs),n.onQueueUpdate("logs"in m?Object.assign(Object.assign({},m),{logs:l}):m))});let c=yield u.done();return s&&clearTimeout(s),c}return new Promise((u,l)=>{var c;let m,p="pollInterval"in n&&typeof n.pollInterval=="number"&&(c=n.pollInterval)!==null&&c!==void 0?c:dn,h=()=>{s&&clearTimeout(s),m&&clearTimeout(m)};o&&(s=setTimeout(()=>{h(),i.cancel(r,{requestId:a}).catch(d),l(new Error(`Client timed out waiting for the request to complete after ${o}ms`))},o));let y=()=>he(this,void 0,void 0,function*(){var w;try{let g=yield i.status(r,{requestId:a,logs:(w=n.logs)!==null&&w!==void 0?w:!1,abortSignal:n.abortSignal});if(n.onQueueUpdate&&n.onQueueUpdate(g),g.status==="COMPLETED"){h(),u(g);return}m=setTimeout(y,p)}catch(g){h(),l(g)}});y().catch(l)})})},result(r,n){return he(this,arguments,void 0,function*(a,{requestId:o,abortSignal:s}){let d=(0,At.parseEndpointId)(a),u=d.namespace?`${d.namespace}/`:"";return(0,Z.dispatchRequest)({method:"get",targetUrl:(0,Z.buildUrl)(`${u}${d.owner}/${d.alias}`,{subdomain:"queue",path:`/requests/${o}`}),config:Object.assign(Object.assign({},e),{responseHandler:_g.resultResponseHandler}),options:{signal:s,retry:pn}})})},cancel(r,n){return he(this,arguments,void 0,function*(a,{requestId:o,abortSignal:s}){let d=(0,At.parseEndpointId)(a),u=d.namespace?`${d.namespace}/`:"";yield(0,Z.dispatchRequest)({method:"put",targetUrl:(0,Z.buildUrl)(`${u}${d.owner}/${d.alias}`,{subdomain:"queue",path:`/requests/${o}/cancel`}),config:e,options:{signal:s}})})}};return i};se.createQueueClient=wg});var kt=S(J=>{"use strict";Object.defineProperty(J,"__esModule",{value:!0});J.utf8Count=Ig;J.utf8EncodeJs=hn;J.utf8EncodeTE=fn;J.utf8Encode=Eg;J.utf8DecodeJs=yn;J.utf8DecodeTD=_n;J.utf8Decode=Cg;function Ig(e){let t=e.length,i=0,r=0;for(;r<t;){let n=e.charCodeAt(r++);if(n&4294967168)if(!(n&4294965248))i+=2;else{if(n>=55296&&n<=56319&&r<t){let a=e.charCodeAt(r);(a&64512)===56320&&(++r,n=((n&1023)<<10)+(a&1023)+65536)}n&4294901760?i+=4:i+=3}else{i++;continue}}return i}function hn(e,t,i){let r=e.length,n=i,a=0;for(;a<r;){let o=e.charCodeAt(a++);if(o&4294967168)if(!(o&4294965248))t[n++]=o>>6&31|192;else{if(o>=55296&&o<=56319&&a<r){let s=e.charCodeAt(a);(s&64512)===56320&&(++a,o=((o&1023)<<10)+(s&1023)+65536)}o&4294901760?(t[n++]=o>>18&7|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128):(t[n++]=o>>12&15|224,t[n++]=o>>6&63|128)}else{t[n++]=o;continue}t[n++]=o&63|128}}var xg=new TextEncoder,Sg=50;function fn(e,t,i){xg.encodeInto(e,t.subarray(i))}function Eg(e,t,i){e.length>Sg?fn(e,t,i):hn(e,t,i)}var Tg=4096;function yn(e,t,i){let r=t,n=r+i,a=[],o="";for(;r<n;){let s=e[r++];if(!(s&128))a.push(s);else if((s&224)===192){let d=e[r++]&63;a.push((s&31)<<6|d)}else if((s&240)===224){let d=e[r++]&63,u=e[r++]&63;a.push((s&31)<<12|d<<6|u)}else if((s&248)===240){let d=e[r++]&63,u=e[r++]&63,l=e[r++]&63,c=(s&7)<<18|d<<12|u<<6|l;c>65535&&(c-=65536,a.push(c>>>10&1023|55296),c=56320|c&1023),a.push(c)}else a.push(s);a.length>=Tg&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}var Ag=new TextDecoder,kg=200;function _n(e,t,i){let r=e.subarray(t,t+i);return Ag.decode(r)}function Cg(e,t,i){return i>kg?_n(e,t,i):yn(e,t,i)}});var Ti=S(Ct=>{"use strict";Object.defineProperty(Ct,"__esModule",{value:!0});Ct.ExtData=void 0;var Ei=class{constructor(t,i){this.type=t,this.data=i}};Ct.ExtData=Ei});var $t=S(Pt=>{"use strict";Object.defineProperty(Pt,"__esModule",{value:!0});Pt.DecodeError=void 0;var Ai=class e extends Error{constructor(t){super(t);let i=Object.create(e.prototype);Object.setPrototypeOf(this,i),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:e.name})}};Pt.DecodeError=Ai});var qt=S(le=>{"use strict";Object.defineProperty(le,"__esModule",{value:!0});le.UINT32_MAX=void 0;le.setUint64=Pg;le.setInt64=$g;le.getInt64=qg;le.getUint64=Og;le.UINT32_MAX=4294967295;function Pg(e,t,i){let r=i/4294967296,n=i;e.setUint32(t,r),e.setUint32(t+4,n)}function $g(e,t,i){let r=Math.floor(i/4294967296),n=i;e.setUint32(t,r),e.setUint32(t+4,n)}function qg(e,t){let i=e.getInt32(t),r=e.getUint32(t+4);return i*4294967296+r}function Og(e,t){let i=e.getUint32(t),r=e.getUint32(t+4);return i*4294967296+r}});var ki=S(F=>{"use strict";Object.defineProperty(F,"__esModule",{value:!0});F.timestampExtension=F.EXT_TIMESTAMP=void 0;F.encodeTimeSpecToTimestamp=vn;F.encodeDateToTimeSpec=wn;F.encodeTimestampExtension=In;F.decodeTimestampToTimeSpec=xn;F.decodeTimestampExtension=Sn;var Dg=$t(),bn=qt();F.EXT_TIMESTAMP=-1;var jg=4294967296-1,Mg=17179869184-1;function vn({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=Mg)if(t===0&&e<=jg){let i=new Uint8Array(4);return new DataView(i.buffer).setUint32(0,e),i}else{let i=e/4294967296,r=e&4294967295,n=new Uint8Array(8),a=new DataView(n.buffer);return a.setUint32(0,t<<2|i&3),a.setUint32(4,r),n}else{let i=new Uint8Array(12),r=new DataView(i.buffer);return r.setUint32(0,t),(0,bn.setInt64)(r,4,e),i}}function wn(e){let t=e.getTime(),i=Math.floor(t/1e3),r=(t-i*1e3)*1e6,n=Math.floor(r/1e9);return{sec:i+n,nsec:r-n*1e9}}function In(e){if(e instanceof Date){let t=wn(e);return vn(t)}else return null}function xn(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:t.getUint32(0),nsec:0};case 8:{let i=t.getUint32(0),r=t.getUint32(4),n=(i&3)*4294967296+r,a=i>>>2;return{sec:n,nsec:a}}case 12:{let i=(0,bn.getInt64)(t,4),r=t.getUint32(0);return{sec:i,nsec:r}}default:throw new Dg.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function Sn(e){let t=xn(e);return new Date(t.sec*1e3+t.nsec/1e6)}F.timestampExtension={type:F.EXT_TIMESTAMP,encode:In,decode:Sn}});var jt=S(Dt=>{"use strict";Object.defineProperty(Dt,"__esModule",{value:!0});Dt.ExtensionCodec=void 0;var Ot=Ti(),Fg=ki(),rt=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(Fg.timestampExtension)}register({type:t,encode:i,decode:r}){if(t>=0)this.encoders[t]=i,this.decoders[t]=r;else{let n=-1-t;this.builtInEncoders[n]=i,this.builtInDecoders[n]=r}}tryToEncode(t,i){for(let r=0;r<this.builtInEncoders.length;r++){let n=this.builtInEncoders[r];if(n!=null){let a=n(t,i);if(a!=null){let o=-1-r;return new Ot.ExtData(o,a)}}}for(let r=0;r<this.encoders.length;r++){let n=this.encoders[r];if(n!=null){let a=n(t,i);if(a!=null){let o=r;return new Ot.ExtData(o,a)}}}return t instanceof Ot.ExtData?t:null}decode(t,i,r){let n=i<0?this.builtInDecoders[-1-i]:this.decoders[i];return n?n(t,i,r):new Ot.ExtData(i,t)}};Dt.ExtensionCodec=rt;rt.defaultCodec=new rt});var Pi=S(Ci=>{"use strict";Object.defineProperty(Ci,"__esModule",{value:!0});Ci.ensureUint8Array=Ng;function Rg(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer}function Ng(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Rg(e)?new Uint8Array(e):Uint8Array.from(e)}});var qi=S(G=>{"use strict";Object.defineProperty(G,"__esModule",{value:!0});G.Encoder=G.DEFAULT_INITIAL_BUFFER_SIZE=G.DEFAULT_MAX_DEPTH=void 0;var En=kt(),Bg=jt(),Tn=qt(),zg=Pi();G.DEFAULT_MAX_DEPTH=100;G.DEFAULT_INITIAL_BUFFER_SIZE=2048;var $i=class e{constructor(t){this.entered=!1,this.extensionCodec=t?.extensionCodec??Bg.ExtensionCodec.defaultCodec,this.context=t?.context,this.useBigInt64=t?.useBigInt64??!1,this.maxDepth=t?.maxDepth??G.DEFAULT_MAX_DEPTH,this.initialBufferSize=t?.initialBufferSize??G.DEFAULT_INITIAL_BUFFER_SIZE,this.sortKeys=t?.sortKeys??!1,this.forceFloat32=t?.forceFloat32??!1,this.ignoreUndefined=t?.ignoreUndefined??!1,this.forceIntegerToFloat=t?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(t){if(this.entered)return this.clone().encodeSharedRef(t);try{return this.entered=!0,this.reinitializeState(),this.doEncode(t,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(t){if(this.entered)return this.clone().encode(t);try{return this.entered=!0,this.reinitializeState(),this.doEncode(t,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(t,i){if(i>this.maxDepth)throw new Error(`Too deep objects in depth ${i}`);t==null?this.encodeNil():typeof t=="boolean"?this.encodeBoolean(t):typeof t=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(t):this.encodeNumber(t):typeof t=="string"?this.encodeString(t):this.useBigInt64&&typeof t=="bigint"?this.encodeBigInt64(t):this.encodeObject(t,i)}ensureBufferSizeToWrite(t){let i=this.pos+t;this.view.byteLength<i&&this.resizeBuffer(i*2)}resizeBuffer(t){let i=new ArrayBuffer(t),r=new Uint8Array(i),n=new DataView(i);r.set(this.bytes),this.view=n,this.bytes=r}encodeNil(){this.writeU8(192)}encodeBoolean(t){t===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(t){!this.forceIntegerToFloat&&Number.isSafeInteger(t)?t>=0?t<128?this.writeU8(t):t<256?(this.writeU8(204),this.writeU8(t)):t<65536?(this.writeU8(205),this.writeU16(t)):t<4294967296?(this.writeU8(206),this.writeU32(t)):this.useBigInt64?this.encodeNumberAsFloat(t):(this.writeU8(207),this.writeU64(t)):t>=-32?this.writeU8(224|t+32):t>=-128?(this.writeU8(208),this.writeI8(t)):t>=-32768?(this.writeU8(209),this.writeI16(t)):t>=-2147483648?(this.writeU8(210),this.writeI32(t)):this.useBigInt64?this.encodeNumberAsFloat(t):(this.writeU8(211),this.writeI64(t)):this.encodeNumberAsFloat(t)}encodeNumberAsFloat(t){this.forceFloat32?(this.writeU8(202),this.writeF32(t)):(this.writeU8(203),this.writeF64(t))}encodeBigInt64(t){t>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(t)):(this.writeU8(211),this.writeBigInt64(t))}writeStringHeader(t){if(t<32)this.writeU8(160+t);else if(t<256)this.writeU8(217),this.writeU8(t);else if(t<65536)this.writeU8(218),this.writeU16(t);else if(t<4294967296)this.writeU8(219),this.writeU32(t);else throw new Error(`Too long string: ${t} bytes in UTF-8`)}encodeString(t){let r=(0,En.utf8Count)(t);this.ensureBufferSizeToWrite(5+r),this.writeStringHeader(r),(0,En.utf8Encode)(t,this.bytes,this.pos),this.pos+=r}encodeObject(t,i){let r=this.extensionCodec.tryToEncode(t,this.context);if(r!=null)this.encodeExtension(r);else if(Array.isArray(t))this.encodeArray(t,i);else if(ArrayBuffer.isView(t))this.encodeBinary(t);else if(typeof t=="object")this.encodeMap(t,i);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(t)}`)}encodeBinary(t){let i=t.byteLength;if(i<256)this.writeU8(196),this.writeU8(i);else if(i<65536)this.writeU8(197),this.writeU16(i);else if(i<4294967296)this.writeU8(198),this.writeU32(i);else throw new Error(`Too large binary: ${i}`);let r=(0,zg.ensureUint8Array)(t);this.writeU8a(r)}encodeArray(t,i){let r=t.length;if(r<16)this.writeU8(144+r);else if(r<65536)this.writeU8(220),this.writeU16(r);else if(r<4294967296)this.writeU8(221),this.writeU32(r);else throw new Error(`Too large array: ${r}`);for(let n of t)this.doEncode(n,i+1)}countWithoutUndefined(t,i){let r=0;for(let n of i)t[n]!==void 0&&r++;return r}encodeMap(t,i){let r=Object.keys(t);this.sortKeys&&r.sort();let n=this.ignoreUndefined?this.countWithoutUndefined(t,r):r.length;if(n<16)this.writeU8(128+n);else if(n<65536)this.writeU8(222),this.writeU16(n);else if(n<4294967296)this.writeU8(223),this.writeU32(n);else throw new Error(`Too large map object: ${n}`);for(let a of r){let o=t[a];this.ignoreUndefined&&o===void 0||(this.encodeString(a),this.doEncode(o,i+1))}}encodeExtension(t){if(typeof t.data=="function"){let r=t.data(this.pos+6),n=r.length;if(n>=4294967296)throw new Error(`Too large extension object: ${n}`);this.writeU8(201),this.writeU32(n),this.writeI8(t.type),this.writeU8a(r);return}let i=t.data.length;if(i===1)this.writeU8(212);else if(i===2)this.writeU8(213);else if(i===4)this.writeU8(214);else if(i===8)this.writeU8(215);else if(i===16)this.writeU8(216);else if(i<256)this.writeU8(199),this.writeU8(i);else if(i<65536)this.writeU8(200),this.writeU16(i);else if(i<4294967296)this.writeU8(201),this.writeU32(i);else throw new Error(`Too large extension object: ${i}`);this.writeI8(t.type),this.writeU8a(t.data)}writeU8(t){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,t),this.pos++}writeU8a(t){let i=t.length;this.ensureBufferSizeToWrite(i),this.bytes.set(t,this.pos),this.pos+=i}writeI8(t){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,t),this.pos++}writeU16(t){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,t),this.pos+=2}writeI16(t){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,t),this.pos+=2}writeU32(t){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,t),this.pos+=4}writeI32(t){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,t),this.pos+=4}writeF32(t){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,t),this.pos+=4}writeF64(t){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,t),this.pos+=8}writeU64(t){this.ensureBufferSizeToWrite(8),(0,Tn.setUint64)(this.view,this.pos,t),this.pos+=8}writeI64(t){this.ensureBufferSizeToWrite(8),(0,Tn.setInt64)(this.view,this.pos,t),this.pos+=8}writeBigUint64(t){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,t),this.pos+=8}writeBigInt64(t){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,t),this.pos+=8}};G.Encoder=$i});var An=S(Oi=>{"use strict";Object.defineProperty(Oi,"__esModule",{value:!0});Oi.encode=Lg;var Ug=qi();function Lg(e,t){return new Ug.Encoder(t).encodeSharedRef(e)}});var kn=S(Di=>{"use strict";Object.defineProperty(Di,"__esModule",{value:!0});Di.prettyByte=Vg;function Vg(e){return`${e<0?"-":""}0x${Math.abs(e).toString(16).padStart(2,"0")}`}});var Cn=S(Mt=>{"use strict";Object.defineProperty(Mt,"__esModule",{value:!0});Mt.CachedKeyDecoder=void 0;var Kg=kt(),Gg=16,Hg=16,ji=class{constructor(t=Gg,i=Hg){this.hit=0,this.miss=0,this.maxKeyLength=t,this.maxLengthPerKey=i,this.caches=[];for(let r=0;r<this.maxKeyLength;r++)this.caches.push([])}canBeCached(t){return t>0&&t<=this.maxKeyLength}find(t,i,r){let n=this.caches[r-1];e:for(let a of n){let o=a.bytes;for(let s=0;s<r;s++)if(o[s]!==t[i+s])continue e;return a.str}return null}store(t,i){let r=this.caches[t.length-1],n={bytes:t,str:i};r.length>=this.maxLengthPerKey?r[Math.random()*r.length|0]=n:r.push(n)}decode(t,i,r){let n=this.find(t,i,r);if(n!=null)return this.hit++,n;this.miss++;let a=(0,Kg.utf8DecodeJs)(t,i,r),o=Uint8Array.prototype.slice.call(t,i,i+r);return this.store(o,a),a}};Mt.CachedKeyDecoder=ji});var Rt=S(Ft=>{"use strict";Object.defineProperty(Ft,"__esModule",{value:!0});Ft.Decoder=void 0;var Mi=kn(),Qg=jt(),fe=qt(),Wg=kt(),Pn=Pi(),Yg=Cn(),X=$t(),Fi="array",at="map_key",qn="map_value",Zg=e=>{if(typeof e=="string"||typeof e=="number")return e;throw new X.DecodeError("The type of key must be string or number but "+typeof e)},Ri=class{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(t){let i=this.getUninitializedStateFromPool();i.type=Fi,i.position=0,i.size=t,i.array=new Array(t)}pushMapState(t){let i=this.getUninitializedStateFromPool();i.type=at,i.readCount=0,i.size=t,i.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let t={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(t)}return this.stack[this.stackHeadPosition]}release(t){if(this.stack[this.stackHeadPosition]!==t)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(t.type===Fi){let r=t;r.size=0,r.array=void 0,r.position=0,r.type=void 0}if(t.type===at||t.type===qn){let r=t;r.size=0,r.map=void 0,r.readCount=0,r.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},nt=-1,Bi=new DataView(new ArrayBuffer(0)),Jg=new Uint8Array(Bi.buffer);try{Bi.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var $n=new RangeError("Insufficient data"),Xg=new Yg.CachedKeyDecoder,Ni=class e{constructor(t){this.totalPos=0,this.pos=0,this.view=Bi,this.bytes=Jg,this.headByte=nt,this.stack=new Ri,this.entered=!1,this.extensionCodec=t?.extensionCodec??Qg.ExtensionCodec.defaultCodec,this.context=t?.context,this.useBigInt64=t?.useBigInt64??!1,this.rawStrings=t?.rawStrings??!1,this.maxStrLength=t?.maxStrLength??fe.UINT32_MAX,this.maxBinLength=t?.maxBinLength??fe.UINT32_MAX,this.maxArrayLength=t?.maxArrayLength??fe.UINT32_MAX,this.maxMapLength=t?.maxMapLength??fe.UINT32_MAX,this.maxExtLength=t?.maxExtLength??fe.UINT32_MAX,this.keyDecoder=t?.keyDecoder!==void 0?t.keyDecoder:Xg,this.mapKeyConverter=t?.mapKeyConverter??Zg}clone(){return new e({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=nt,this.stack.reset()}setBuffer(t){let i=(0,Pn.ensureUint8Array)(t);this.bytes=i,this.view=new DataView(i.buffer,i.byteOffset,i.byteLength),this.pos=0}appendBuffer(t){if(this.headByte===nt&&!this.hasRemaining(1))this.setBuffer(t);else{let i=this.bytes.subarray(this.pos),r=(0,Pn.ensureUint8Array)(t),n=new Uint8Array(i.length+r.length);n.set(i),n.set(r,i.length),this.setBuffer(n)}}hasRemaining(t){return this.view.byteLength-this.pos>=t}createExtraByteError(t){let{view:i,pos:r}=this;return new RangeError(`Extra ${i.byteLength-r} of ${i.byteLength} byte(s) found at buffer[${t}]`)}decode(t){if(this.entered)return this.clone().decode(t);try{this.entered=!0,this.reinitializeState(),this.setBuffer(t);let i=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return i}finally{this.entered=!1}}*decodeMulti(t){if(this.entered){yield*this.clone().decodeMulti(t);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(t);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(t){if(this.entered)return this.clone().decodeAsync(t);try{this.entered=!0;let i=!1,r;for await(let s of t){if(i)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(s);try{r=this.doDecodeSync(),i=!0}catch(d){if(!(d instanceof RangeError))throw d}this.totalPos+=this.pos}if(i){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return r}let{headByte:n,pos:a,totalPos:o}=this;throw new RangeError(`Insufficient data in parsing ${(0,Mi.prettyByte)(n)} at ${o} (${a} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(t){return this.decodeMultiAsync(t,!0)}decodeStream(t){return this.decodeMultiAsync(t,!1)}async*decodeMultiAsync(t,i){if(this.entered){yield*this.clone().decodeMultiAsync(t,i);return}try{this.entered=!0;let r=i,n=-1;for await(let a of t){if(i&&n===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(a),r&&(n=this.readArraySize(),r=!1,this.complete());try{for(;yield this.doDecodeSync(),--n!==0;);}catch(o){if(!(o instanceof RangeError))throw o}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){let t=this.readHeadByte(),i;if(t>=224)i=t-256;else if(t<192)if(t<128)i=t;else if(t<144){let n=t-128;if(n!==0){this.pushMapState(n),this.complete();continue e}else i={}}else if(t<160){let n=t-144;if(n!==0){this.pushArrayState(n),this.complete();continue e}else i=[]}else{let n=t-160;i=this.decodeString(n,0)}else if(t===192)i=null;else if(t===194)i=!1;else if(t===195)i=!0;else if(t===202)i=this.readF32();else if(t===203)i=this.readF64();else if(t===204)i=this.readU8();else if(t===205)i=this.readU16();else if(t===206)i=this.readU32();else if(t===207)this.useBigInt64?i=this.readU64AsBigInt():i=this.readU64();else if(t===208)i=this.readI8();else if(t===209)i=this.readI16();else if(t===210)i=this.readI32();else if(t===211)this.useBigInt64?i=this.readI64AsBigInt():i=this.readI64();else if(t===217){let n=this.lookU8();i=this.decodeString(n,1)}else if(t===218){let n=this.lookU16();i=this.decodeString(n,2)}else if(t===219){let n=this.lookU32();i=this.decodeString(n,4)}else if(t===220){let n=this.readU16();if(n!==0){this.pushArrayState(n),this.complete();continue e}else i=[]}else if(t===221){let n=this.readU32();if(n!==0){this.pushArrayState(n),this.complete();continue e}else i=[]}else if(t===222){let n=this.readU16();if(n!==0){this.pushMapState(n),this.complete();continue e}else i={}}else if(t===223){let n=this.readU32();if(n!==0){this.pushMapState(n),this.complete();continue e}else i={}}else if(t===196){let n=this.lookU8();i=this.decodeBinary(n,1)}else if(t===197){let n=this.lookU16();i=this.decodeBinary(n,2)}else if(t===198){let n=this.lookU32();i=this.decodeBinary(n,4)}else if(t===212)i=this.decodeExtension(1,0);else if(t===213)i=this.decodeExtension(2,0);else if(t===214)i=this.decodeExtension(4,0);else if(t===215)i=this.decodeExtension(8,0);else if(t===216)i=this.decodeExtension(16,0);else if(t===199){let n=this.lookU8();i=this.decodeExtension(n,1)}else if(t===200){let n=this.lookU16();i=this.decodeExtension(n,2)}else if(t===201){let n=this.lookU32();i=this.decodeExtension(n,4)}else throw new X.DecodeError(`Unrecognized type byte: ${(0,Mi.prettyByte)(t)}`);this.complete();let r=this.stack;for(;r.length>0;){let n=r.top();if(n.type===Fi)if(n.array[n.position]=i,n.position++,n.position===n.size)i=n.array,r.release(n);else continue e;else if(n.type===at){if(i==="__proto__")throw new X.DecodeError("The key __proto__ is not allowed");n.key=this.mapKeyConverter(i),n.type=qn;continue e}else if(n.map[n.key]=i,n.readCount++,n.readCount===n.size)i=n.map,r.release(n);else{n.key=null,n.type=at;continue e}}return i}}readHeadByte(){return this.headByte===nt&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=nt}readArraySize(){let t=this.readHeadByte();switch(t){case 220:return this.readU16();case 221:return this.readU32();default:{if(t<160)return t-144;throw new X.DecodeError(`Unrecognized array type byte: ${(0,Mi.prettyByte)(t)}`)}}}pushMapState(t){if(t>this.maxMapLength)throw new X.DecodeError(`Max length exceeded: map length (${t}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(t)}pushArrayState(t){if(t>this.maxArrayLength)throw new X.DecodeError(`Max length exceeded: array length (${t}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(t)}decodeString(t,i){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(t,i):this.decodeBinary(t,i)}decodeUtf8String(t,i){if(t>this.maxStrLength)throw new X.DecodeError(`Max length exceeded: UTF-8 byte length (${t}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+i+t)throw $n;let r=this.pos+i,n;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(t)?n=this.keyDecoder.decode(this.bytes,r,t):n=(0,Wg.utf8Decode)(this.bytes,r,t),this.pos+=i+t,n}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===at:!1}decodeBinary(t,i){if(t>this.maxBinLength)throw new X.DecodeError(`Max length exceeded: bin length (${t}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(t+i))throw $n;let r=this.pos+i,n=this.bytes.subarray(r,r+t);return this.pos+=i+t,n}decodeExtension(t,i){if(t>this.maxExtLength)throw new X.DecodeError(`Max length exceeded: ext length (${t}) > maxExtLength (${this.maxExtLength})`);let r=this.view.getInt8(this.pos+i),n=this.decodeBinary(t,i+1);return this.extensionCodec.decode(n,r,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let t=this.view.getUint8(this.pos);return this.pos++,t}readI8(){let t=this.view.getInt8(this.pos);return this.pos++,t}readU16(){let t=this.view.getUint16(this.pos);return this.pos+=2,t}readI16(){let t=this.view.getInt16(this.pos);return this.pos+=2,t}readU32(){let t=this.view.getUint32(this.pos);return this.pos+=4,t}readI32(){let t=this.view.getInt32(this.pos);return this.pos+=4,t}readU64(){let t=(0,fe.getUint64)(this.view,this.pos);return this.pos+=8,t}readI64(){let t=(0,fe.getInt64)(this.view,this.pos);return this.pos+=8,t}readU64AsBigInt(){let t=this.view.getBigUint64(this.pos);return this.pos+=8,t}readI64AsBigInt(){let t=this.view.getBigInt64(this.pos);return this.pos+=8,t}readF32(){let t=this.view.getFloat32(this.pos);return this.pos+=4,t}readF64(){let t=this.view.getFloat64(this.pos);return this.pos+=8,t}};Ft.Decoder=Ni});var Dn=S(Nt=>{"use strict";Object.defineProperty(Nt,"__esModule",{value:!0});Nt.decode=em;Nt.decodeMulti=tm;var On=Rt();function em(e,t){return new On.Decoder(t).decode(e)}function tm(e,t){return new On.Decoder(t).decodeMulti(e)}});var Fn=S(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});ot.isAsyncIterable=jn;ot.asyncIterableFromStream=Mn;ot.ensureAsyncIterable=im;function jn(e){return e[Symbol.asyncIterator]!=null}async function*Mn(e){let t=e.getReader();try{for(;;){let{done:i,value:r}=await t.read();if(i)return;yield r}}finally{t.releaseLock()}}function im(e){return jn(e)?e:Mn(e)}});var Rn=S(st=>{"use strict";Object.defineProperty(st,"__esModule",{value:!0});st.decodeAsync=rm;st.decodeArrayStream=nm;st.decodeMultiStream=am;var zi=Rt(),Ui=Fn();async function rm(e,t){let i=(0,Ui.ensureAsyncIterable)(e);return new zi.Decoder(t).decodeAsync(i)}function nm(e,t){let i=(0,Ui.ensureAsyncIterable)(e);return new zi.Decoder(t).decodeArrayStream(i)}function am(e,t){let i=(0,Ui.ensureAsyncIterable)(e);return new zi.Decoder(t).decodeStream(i)}});var Bn=S(x=>{"use strict";Object.defineProperty(x,"__esModule",{value:!0});x.decodeTimestampExtension=x.encodeTimestampExtension=x.decodeTimestampToTimeSpec=x.encodeTimeSpecToTimestamp=x.encodeDateToTimeSpec=x.EXT_TIMESTAMP=x.ExtData=x.ExtensionCodec=x.Encoder=x.DecodeError=x.Decoder=x.decodeMultiStream=x.decodeArrayStream=x.decodeAsync=x.decodeMulti=x.decode=x.encode=void 0;var om=An();Object.defineProperty(x,"encode",{enumerable:!0,get:function(){return om.encode}});var Nn=Dn();Object.defineProperty(x,"decode",{enumerable:!0,get:function(){return Nn.decode}});Object.defineProperty(x,"decodeMulti",{enumerable:!0,get:function(){return Nn.decodeMulti}});var Li=Rn();Object.defineProperty(x,"decodeAsync",{enumerable:!0,get:function(){return Li.decodeAsync}});Object.defineProperty(x,"decodeArrayStream",{enumerable:!0,get:function(){return Li.decodeArrayStream}});Object.defineProperty(x,"decodeMultiStream",{enumerable:!0,get:function(){return Li.decodeMultiStream}});var sm=Rt();Object.defineProperty(x,"Decoder",{enumerable:!0,get:function(){return sm.Decoder}});var lm=$t();Object.defineProperty(x,"DecodeError",{enumerable:!0,get:function(){return lm.DecodeError}});var um=qi();Object.defineProperty(x,"Encoder",{enumerable:!0,get:function(){return um.Encoder}});var cm=jt();Object.defineProperty(x,"ExtensionCodec",{enumerable:!0,get:function(){return cm.ExtensionCodec}});var dm=Ti();Object.defineProperty(x,"ExtData",{enumerable:!0,get:function(){return dm.ExtData}});var je=ki();Object.defineProperty(x,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return je.EXT_TIMESTAMP}});Object.defineProperty(x,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return je.encodeDateToTimeSpec}});Object.defineProperty(x,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return je.encodeTimeSpecToTimestamp}});Object.defineProperty(x,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return je.decodeTimestampToTimeSpec}});Object.defineProperty(x,"encodeTimestampExtension",{enumerable:!0,get:function(){return je.encodeTimestampExtension}});Object.defineProperty(x,"decodeTimestampExtension",{enumerable:!0,get:function(){return je.decodeTimestampExtension}})});var ta=S(R=>{"use strict";Object.defineProperty(R,"__esModule",{value:!0});function q(e){return{enumerable:!0,value:e}}function zn(e){return{enumerable:!0,writable:!0,value:e}}var ye={},pm=()=>!0,Un=()=>({}),Vn=e=>e,gm=(e,t,i,r)=>e.apply(i,r)&&t.apply(i,r),mm=(e,t,i,[r,n])=>t.call(i,e.call(i,r,n),n),ue=(e,t)=>Object.freeze(Object.create(e,t));function Ln(e,t,i){return e.reduce((r,n)=>function(...a){ret