UNPKG

@imgly/plugin-ai-video-generation-web

Version:

AI video generation plugin for the CE.SDK editor

5 lines 191 kB
var Eo=Object.create;var ki=Object.defineProperty;var Ao=Object.getOwnPropertyDescriptor;var Co=Object.getOwnPropertyNames;var ko=Object.getPrototypeOf,Po=Object.prototype.hasOwnProperty;var T=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var qo=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Co(e))!Po.call(t,n)&&n!==i&&ki(t,n,{get:()=>e[n],enumerable:!(r=Ao(e,n))||r.enumerable});return t};var Vo=(t,e,i)=>(i=t!=null?Eo(ko(t)):{},qo(e||!t||!t.__esModule?ki(i,"default",{value:t,enumerable:!0}):i,t));var Ot=T(R=>{"use strict";var Gl=R&&R.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})};Object.defineProperty(R,"__esModule",{value:!0});R.TARGET_URL_HEADER=void 0;R.withMiddleware=Ql;R.withProxy=Wl;function Ql(...t){let e=i=>typeof i=="function";return i=>Gl(this,void 0,void 0,function*(){let r=Object.assign({},i);for(let n of t.filter(e))r=yield n(r);return r})}R.TARGET_URL_HEADER="x-fal-target-url";function Wl(t){let e=i=>Promise.resolve(i);return typeof window>"u"?e:i=>i.headers&&R.TARGET_URL_HEADER in i?e(i):Promise.resolve(Object.assign(Object.assign({},i),{url:t.targetUrl,headers:Object.assign(Object.assign({},i.headers||{}),{[R.TARGET_URL_HEADER]:i.url})}))}});var Q=T(U=>{"use strict";var er=U&&U.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})};Object.defineProperty(U,"__esModule",{value:!0});U.ValidationError=U.ApiError=void 0;U.defaultResponseHandler=tr;U.resultResponseHandler=Zl;var Yl="x-fal-request-id",ge=class extends Error{constructor({message:e,status:i,body:r}){super(e),this.name="ApiError",this.status=i,this.body=r}};U.ApiError=ge;var Xe=class extends ge{constructor(e){super(e),this.name="ValidationError"}get fieldErrors(){return typeof this.body.detail=="string"?[{loc:["body"],msg:this.body.detail,type:"value_error"}]:this.body.detail||[]}getFieldErrors(e){return this.fieldErrors.filter(i=>i.loc[i.loc.length-1]===e)}};U.ValidationError=Xe;function tr(t){return er(this,void 0,void 0,function*(){var e;let{status:i,statusText:r}=t,n=(e=t.headers.get("Content-Type"))!==null&&e!==void 0?e:"";if(!t.ok){if(n.includes("application/json")){let o=yield t.json(),s=i===422?Xe:ge;throw new s({message:o.message||r,status:i,body:o})}throw new ge({message:`HTTP ${i}: ${r}`,status:i})}return n.includes("application/json")?t.json():n.includes("text/html")?t.text():n.includes("application/octet-stream")?t.arrayBuffer():t.text()})}function Zl(t){return er(this,void 0,void 0,function*(){return{data:yield tr(t),requestId:t.headers.get(Yl)||""}})}});var W=T(O=>{"use strict";var Xl=O&&O.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})};Object.defineProperty(O,"__esModule",{value:!0});O.ensureEndpointIdFormat=ir;O.parseEndpointId=eu;O.isValidUrl=tu;O.throttle=iu;O.isReact=ru;O.isPlainObject=nu;O.sleep=ou;function ir(t){if(t.split("/").length>1)return t;let[,i,r]=/^([0-9]+)-([a-zA-Z0-9-]+)$/.exec(t)||[];if(i&&r)return`${i}/${r}`;throw new Error(`Invalid app id: ${t}. Must be in the format <appOwner>/<appId>`)}var Jl=["workflows","comfy"];function eu(t){let i=ir(t).split("/");return Jl.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 tu(t){try{let{host:e}=new URL(t);return/(fal\.(ai|run))$/.test(e)}catch{return!1}}function iu(t,e,i=!1){let r,n;return(...o)=>{!n&&i?(t(...o),n=Date.now()):(r&&clearTimeout(r),r=setTimeout(()=>{Date.now()-n>=e&&(t(...o),n=Date.now())},e-(Date.now()-n)))}}var Ft;function ru(){if(Ft===void 0){let t=new Error().stack;Ft=!!t&&(t.includes("node_modules/react-dom/")||t.includes("node_modules/next/"))}return Ft}function nu(t){return!!t&&Object.getPrototypeOf(t)===Object.prototype}function ou(t){return Xl(this,void 0,void 0,function*(){return new Promise(e=>setTimeout(e,t))})}});var Me=T(V=>{"use strict";var su=V&&V.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})};Object.defineProperty(V,"__esModule",{value:!0});V.DEFAULT_RETRY_OPTIONS=V.DEFAULT_RETRYABLE_STATUS_CODES=void 0;V.isRetryableError=rr;V.calculateBackoffDelay=nr;V.executeWithRetry=uu;var au=Q(),lu=W();V.DEFAULT_RETRYABLE_STATUS_CODES=[429,502,503,504];V.DEFAULT_RETRY_OPTIONS={maxRetries:3,baseDelay:1e3,maxDelay:3e4,backoffMultiplier:2,retryableStatusCodes:V.DEFAULT_RETRYABLE_STATUS_CODES,enableJitter:!0};function rr(t,e){return t instanceof au.ApiError&&e.includes(t.status)}function nr(t,e,i,r,n){let o=Math.min(e*Math.pow(r,t),i);if(n){let s=.25*o*(Math.random()*2-1);return Math.max(0,o+s)}return o}function uu(t,e,i){return su(this,void 0,void 0,function*(){let r={totalAttempts:0,totalDelay:0},n;for(let o=0;o<=e.maxRetries;o++){r.totalAttempts++;try{return{result:yield t(),metrics:r}}catch(s){if(n=s,r.lastError=s,o===e.maxRetries||!rr(s,e.retryableStatusCodes))throw s;let a=nr(o,e.baseDelay,e.maxDelay,e.backoffMultiplier,e.enableJitter);r.totalDelay+=a,i&&i(o+1,s,a),yield(0,lu.sleep)(a)}}throw n})}});var or=T((kg,du)=>{du.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 tt=T(et=>{"use strict";Object.defineProperty(et,"__esModule",{value:!0});et.isBrowser=cu;et.getUserAgent=pu;function cu(){return typeof window<"u"&&typeof window.document<"u"}var Je=null;function pu(){if(Je!==null)return Je;let t=or();return Je=`${t.name}/${t.version}`,Je}});var it=T(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.credentialsFromEnv=void 0;Y.resolveDefaultFetch=lr;Y.createConfig=bu;Y.getRestApiUrl=vu;var sr=Ot(),mu=Q(),ar=Me(),fu=tt();function lr(){if(typeof fetch>"u")throw new Error("Your environment does not support fetch. Please provide your own fetch implementation.");return fetch}function gu(){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 hu=()=>{if(gu())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};Y.credentialsFromEnv=hu;var yu={credentials:Y.credentialsFromEnv,suppressLocalCredentialsWarning:!1,requestMiddleware:t=>Promise.resolve(t),responseHandler:mu.defaultResponseHandler,retry:ar.DEFAULT_RETRY_OPTIONS};function bu(t){var e;let i=Object.assign(Object.assign(Object.assign({},yu),t),{fetch:(e=t.fetch)!==null&&e!==void 0?e:lr(),retry:Object.assign(Object.assign({},ar.DEFAULT_RETRY_OPTIONS),t.retry||{})});t.proxyUrl&&(i=Object.assign(Object.assign({},i),{requestMiddleware:(0,sr.withMiddleware)(i.requestMiddleware,(0,sr.withProxy)({targetUrl:t.proxyUrl}))}));let{credentials:r,suppressLocalCredentialsWarning:n}=i,o=typeof r=="function"?r():r;return(0,fu.isBrowser)()&&o&&!n&&console.warn("The fal credentials are exposed in the browser's environment. That's not recommended for production use cases."),i}function vu(){return"https://rest.alpha.fal.ai"}});var he=T(Z=>{"use strict";var ur=Z&&Z.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})},wu=Z&&Z.__rest||function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,r=Object.getOwnPropertySymbols(t);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(i[r[n]]=t[r[n]]);return i};Object.defineProperty(Z,"__esModule",{value:!0});Z.dispatchRequest=xu;Z.buildUrl=Tu;var dr=Me(),cr=tt(),Rt=W(),_u=typeof navigator<"u"&&navigator?.userAgent==="Cloudflare-Workers";function xu(t){return ur(this,void 0,void 0,function*(){var e;let{targetUrl:i,input:r,config:n,options:o={}}=t,{credentials:s,requestMiddleware:a,responseHandler:u,fetch:d}=n,l=Object.assign(Object.assign({},n.retry),o.retry||{}),c=()=>ur(this,void 0,void 0,function*(){var p,g,h;let v=(0,cr.isBrowser)()?{}:{"User-Agent":(0,cr.getUserAgent)()},f=typeof s=="function"?s():s,{method:y,url:I,headers:x}=yield a({method:((g=(p=t.method)!==null&&p!==void 0?p:o.method)!==null&&g!==void 0?g:"post").toUpperCase(),url:i,headers:t.headers}),q=f?{Authorization:`Key ${f}`}:{},It=Object.assign(Object.assign(Object.assign(Object.assign({},q),{Accept:"application/json","Content-Type":"application/json"}),v),x??{}),{responseHandler:St,retry:tg}=o,Ci=wu(o,["responseHandler","retry"]),So=yield d(I,Object.assign(Object.assign(Object.assign(Object.assign({},Ci),{method:y,headers:Object.assign(Object.assign({},It),(h=Ci.headers)!==null&&h!==void 0?h:{})}),!_u&&{mode:"cors"}),{signal:o.signal,body:y.toLowerCase()!=="get"&&r?JSON.stringify(r):void 0}));return yield(St??u)(So)}),m;for(let p=0;p<=l.maxRetries;p++)try{return yield c()}catch(g){if(m=g,p===l.maxRetries||!(0,dr.isRetryableError)(g,l.retryableStatusCodes)||((e=o.signal)===null||e===void 0?void 0:e.aborted))throw g;let v=(0,dr.calculateBackoffDelay)(p,l.baseDelay,l.maxDelay,l.backoffMultiplier,l.enableJitter);yield(0,Rt.sleep)(v)}throw m})}function Tu(t,e={}){var i,r;let n=((i=e.method)!==null&&i!==void 0?i:"post").toLowerCase(),o=((r=e.path)!==null&&r!==void 0?r:"").replace(/^\//,"").replace(/\/{2,}/,"/"),s=e.input,a=Object.assign(Object.assign({},e.query||{}),n==="get"?s:{}),u=Object.keys(a).length>0?`?${new URLSearchParams(a).toString()}`:"";if((0,Rt.isValidUrl)(t))return`${t.endsWith("/")?t:`${t}/`}${o}${u}`;let d=(0,Rt.ensureEndpointIdFormat)(t);return`${`https://${e.subdomain?`${e.subdomain}.`:""}fal.run/${d}/${o}`.replace(/\/$/,"")}${u}`}});var mr=T(Ut=>{"use strict";Object.defineProperty(Ut,"__esModule",{value:!0});function Iu(t){let e,i,r,n,o,s,a;return u(),{feed:d,reset:u};function u(){e=!0,i="",r=0,n=-1,o=void 0,s=void 0,a=""}function d(c){i=i?i+c:c,e&&Su(i)&&(i=i.slice(pr.length)),e=!1;let m=i.length,p=0,g=!1;for(;p<m;){g&&(i[p]===` `&&++p,g=!1);let h=-1,v=n,f;for(let y=r;h<0&&y<m;++y)f=i[y],f===":"&&v<0?v=y-p:f==="\r"?(g=!0,h=y-p):f===` `&&(h=y-p);if(h<0){r=m-p,n=v;break}else r=0,n=-1;l(i,p,v,h),p+=h+1}p===m?i="":p>0&&(i=i.slice(p))}function l(c,m,p,g){if(g===0){a.length>0&&(t({type:"event",id:o,event:s||void 0,data:a.slice(0,-1)}),a="",o=void 0),s=void 0;return}let h=p<0,v=c.slice(m,m+(h?g:p)),f=0;h?f=g:c[m+p+1]===" "?f=p+2:f=p+1;let y=m+f,I=g-f,x=c.slice(y,y+I).toString();if(v==="data")a+=x?"".concat(x,` `):` `;else if(v==="event")s=x;else if(v==="id"&&!x.includes("\0"))o=x;else if(v==="retry"){let q=parseInt(x,10);Number.isNaN(q)||t({type:"reconnect-interval",value:q})}}}var pr=[239,187,191];function Su(t){return pr.every((e,i)=>t.charCodeAt(i)===e)}Ut.createParser=Iu});var Lt=T(X=>{"use strict";var Eu=X&&X.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})};Object.defineProperty(X,"__esModule",{value:!0});X.TOKEN_EXPIRATION_SECONDS=void 0;X.getTemporaryAuthToken=Pu;var Au=it(),Cu=he(),ku=W();X.TOKEN_EXPIRATION_SECONDS=120;function Pu(t,e){return Eu(this,void 0,void 0,function*(){let i=(0,ku.parseEndpointId)(t),r=yield(0,Cu.dispatchRequest)({method:"POST",targetUrl:`${(0,Au.getRestApiUrl)()}/tokens/`,config:e,input:{allowed_apps:[i.alias],token_expiration:X.TOKEN_EXPIRATION_SECONDS}});return typeof r!="string"&&r.detail?r.detail:r})}});var Nt=T(F=>{"use strict";var be=F&&F.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})},De=F&&F.__await||function(t){return this instanceof De?(this.v=t,this):new De(t)},qu=F&&F.__asyncGenerator||function(t,e,i){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=i.apply(t,e||[]),n,o=[];return n={},a("next"),a("throw"),a("return",s),n[Symbol.asyncIterator]=function(){return this},n;function s(p){return function(g){return Promise.resolve(g).then(p,c)}}function a(p,g){r[p]&&(n[p]=function(h){return new Promise(function(v,f){o.push([p,h,v,f])>1||u(p,h)})},g&&(n[p]=g(n[p])))}function u(p,g){try{d(r[p](g))}catch(h){m(o[0][3],h)}}function d(p){p.value instanceof De?Promise.resolve(p.value.v).then(l,c):m(o[0][2],p)}function l(p){u("next",p)}function c(p){u("throw",p)}function m(p,g){p(g),o.shift(),o.length&&u(o[0][0],o[0][1])}};Object.defineProperty(F,"__esModule",{value:!0});F.FalStream=void 0;F.createStreamingClient=ju;var Vu=mr(),Mu=Lt(),fr=he(),ye=Q(),$t="text/event-stream",Du=15*1e3,rt=class{constructor(e,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=()=>be(this,void 0,void 0,function*(){var o,s;let{endpointId:a,options:u}=this,{input:d,method:l="post",connectionMode:c="server"}=u;try{if(c==="client"){let m=yield(0,Mu.getTemporaryAuthToken)(a,this.config),{fetch:p}=this.config,g=new URL(this.url);g.searchParams.set("fal_jwt_token",m);let h=yield p(g.toString(),{method:l.toUpperCase(),headers:{accept:(o=u.accept)!==null&&o!==void 0?o:$t,"content-type":"application/json"},body:d&&l!=="get"?JSON.stringify(d):void 0,signal:this.abortController.signal});return this._requestId=h.headers.get("x-fal-request-id"),yield this.handleResponse(h)}return yield(0,fr.dispatchRequest)({method:l.toUpperCase(),targetUrl:this.url,input:d,config:this.config,options:{headers:{accept:(s=u.accept)!==null&&s!==void 0?s:$t},responseHandler:m=>be(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=o=>be(this,void 0,void 0,function*(){var s,a;if(!o.ok){try{yield(0,ye.defaultResponseHandler)(o)}catch(h){this.emit("error",h)}return}let u=o.body;if(!u){this.emit("error",new ye.ApiError({message:"Response body is empty.",status:400,body:void 0}));return}if(!((s=o.headers.get("content-type"))!==null&&s!==void 0?s:"").startsWith($t)){let h=u.getReader(),v=()=>{h.read().then(({done:f,value:y})=>{if(f){this.emit("done",this.currentData);return}this.currentData=y,this.emit("data",y),v()})};v();return}let l=new TextDecoder("utf-8"),c=o.body.getReader(),m=(0,Vu.createParser)(h=>{if(h.type==="event"){let v=h.data;try{let f=JSON.parse(v);this.buffer.push(f),this.currentData=f,this.emit("data",f),this.emit("message",f)}catch(f){this.emit("error",f)}}}),p=(a=this.options.timeout)!==null&&a!==void 0?a:Du,g=()=>be(this,void 0,void 0,function*(){let{value:h,done:v}=yield c.read();this.lastEventTimestamp=Date.now(),m.feed(l.decode(h)),Date.now()-this.lastEventTimestamp>p&&this.emit("error",new ye.ApiError({message:`Event stream timed out after ${(p/1e3).toFixed(0)} seconds with no messages.`,status:408})),v?this.emit("done",this.currentData):g().catch(this.handleError)});g().catch(this.handleError)}),this.handleError=o=>{var s;if(o.name==="AbortError"||this.signal.aborted)return;let a=o instanceof ye.ApiError?o:new ye.ApiError({message:(s=o.message)!==null&&s!==void 0?s:"An unknown error occurred",status:500});this.emit("error",a)},this.on=(o,s)=>{var a;this.listeners.has(o)||this.listeners.set(o,[]),(a=this.listeners.get(o))===null||a===void 0||a.push(s)},this.emit=(o,s)=>{let a=this.listeners.get(o)||[];for(let u of a)u(s)},this.done=()=>be(this,void 0,void 0,function*(){return this.donePromise}),this.abort=o=>{this.streamClosed||this.abortController.abort(o)},this.endpointId=e,this.config=i,this.url=(n=r.url)!==null&&n!==void 0?n:(0,fr.buildUrl)(e,{path:"/stream",query:r.queryParams}),this.options=r,this.donePromise=new Promise((o,s)=>{this.streamClosed&&s(new ye.ApiError({message:"Streaming connection is already closed.",status:400,body:void 0})),this.signal.addEventListener("abort",()=>{var a;o((a=this.currentData)!==null&&a!==void 0?a:{})}),this.on("done",a=>{this.streamClosed=!0,o(a)}),this.on("error",a=>{this.streamClosed=!0,s(a)})}),r.signal&&r.signal.addEventListener("abort",()=>{this.abortController.abort()}),this.start().catch(this.handleError)}[Symbol.asyncIterator](){return qu(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 De(n)),yield De(new Promise(o=>setTimeout(o,16)))}})}get signal(){return this.abortController.signal}get requestId(){return this._requestId}};F.FalStream=rt;function ju({config:t,storage:e}){return{stream(i,r){return be(this,void 0,void 0,function*(){let n=r.input?yield e.transformInput(r.input):void 0;return new rt(i,t,Object.assign(Object.assign({},r),{input:n}))})}}}});var br=T(J=>{"use strict";var re=J&&J.__awaiter||function(t,e,i,r){function n(o){return o instanceof i?o:new i(function(s){s(o)})}return new(i||(i=Promise))(function(o,s){function a(l){try{d(r.next(l))}catch(c){s(c)}}function u(l){try{d(r.throw(l))}catch(c){s(c)}}function d(l){l.done?o(l.value):n(l.value).then(a,u)}d((r=r.apply(t,e||[])).next())})},Ou=J&&J.__rest||function(t,e){var i={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,r=Object.getOwnPropertySymbols(t);n<r.length;n++)e.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(t,r[n])&&(i[r[n]]=t[r[n]]);return i};Object.defineProperty(J,"__esModule",{value:!0});J.createQueueClient=void 0;var N=he(),Fu=Q(),yr=Me(),Ru=Nt(),nt=W(),gr=500,hr={maxRetries:3,baseDelay:1e3,maxDelay:6e4,retryableStatusCodes:yr.DEFAULT_RETRYABLE_STATUS_CODES},Uu={maxRetries:5,baseDelay:1e3,maxDelay:3e4,retryableStatusCodes:[...yr.DEFAULT_RETRYABLE_STATUS_CODES,500]},Lu=({config:t,storage:e})=>{let i={submit(r,n){return re(this,void 0,void 0,function*(){let{webhookUrl:o,priority:s,hint:a}=n,u=Ou(n,["webhookUrl","priority","hint"]),d=n.input?yield e.transformInput(n.input):void 0;return(0,N.dispatchRequest)({method:n.method,targetUrl:(0,N.buildUrl)(r,Object.assign(Object.assign({},u),{subdomain:"queue",query:o?{fal_webhook:o}:void 0})),headers:Object.assign({"x-fal-queue-priority":s??"normal"},a&&{"x-fal-runner-hint":a}),input:d,config:t,options:{signal:n.abortSignal,retry:hr}})})},status(r,n){return re(this,arguments,void 0,function*(o,{requestId:s,logs:a=!1,abortSignal:u}){let d=(0,nt.parseEndpointId)(o),l=d.namespace?`${d.namespace}/`:"";return(0,N.dispatchRequest)({method:"get",targetUrl:(0,N.buildUrl)(`${l}${d.owner}/${d.alias}`,{subdomain:"queue",query:{logs:a?"1":"0"},path:`/requests/${s}/status`}),config:t,options:{signal:u,retry:Uu}})})},streamStatus(r,n){return re(this,arguments,void 0,function*(o,{requestId:s,logs:a=!1,connectionMode:u}){let d=(0,nt.parseEndpointId)(o),l=d.namespace?`${d.namespace}/`:"",c={logs:a?"1":"0"},m=(0,N.buildUrl)(`${l}${d.owner}/${d.alias}`,{subdomain:"queue",path:`/requests/${s}/status/stream`,query:c});return new Ru.FalStream(o,t,{url:m,method:"get",connectionMode:u,queryParams:c})})},subscribeToStatus(r,n){return re(this,void 0,void 0,function*(){let o=n.requestId,s=n.timeout,a,u=()=>{};if(n.mode==="streaming"){let d=yield i.streamStatus(r,{requestId:o,logs:n.logs,connectionMode:"connectionMode"in n?n.connectionMode:void 0}),l=[];s&&(a=setTimeout(()=>{throw d.abort(),i.cancel(r,{requestId:o}).catch(u),new Error(`Client timed out waiting for the request to complete after ${s}ms`)},s)),d.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 d.done();return a&&clearTimeout(a),c}return new Promise((d,l)=>{var c;let m,p="pollInterval"in n&&typeof n.pollInterval=="number"&&(c=n.pollInterval)!==null&&c!==void 0?c:gr,g=()=>{a&&clearTimeout(a),m&&clearTimeout(m)};s&&(a=setTimeout(()=>{g(),i.cancel(r,{requestId:o}).catch(u),l(new Error(`Client timed out waiting for the request to complete after ${s}ms`))},s));let h=()=>re(this,void 0,void 0,function*(){var v;try{let f=yield i.status(r,{requestId:o,logs:(v=n.logs)!==null&&v!==void 0?v:!1,abortSignal:n.abortSignal});if(n.onQueueUpdate&&n.onQueueUpdate(f),f.status==="COMPLETED"){g(),d(f);return}m=setTimeout(h,p)}catch(f){g(),l(f)}});h().catch(l)})})},result(r,n){return re(this,arguments,void 0,function*(o,{requestId:s,abortSignal:a}){let u=(0,nt.parseEndpointId)(o),d=u.namespace?`${u.namespace}/`:"";return(0,N.dispatchRequest)({method:"get",targetUrl:(0,N.buildUrl)(`${d}${u.owner}/${u.alias}`,{subdomain:"queue",path:`/requests/${s}`}),config:Object.assign(Object.assign({},t),{responseHandler:Fu.resultResponseHandler}),options:{signal:a,retry:hr}})})},cancel(r,n){return re(this,arguments,void 0,function*(o,{requestId:s,abortSignal:a}){let u=(0,nt.parseEndpointId)(o),d=u.namespace?`${u.namespace}/`:"";yield(0,N.dispatchRequest)({method:"put",targetUrl:(0,N.buildUrl)(`${d}${u.owner}/${u.alias}`,{subdomain:"queue",path:`/requests/${s}/cancel`}),config:t,options:{signal:a}})})}};return i};J.createQueueClient=Lu});var ot=T(z=>{"use strict";Object.defineProperty(z,"__esModule",{value:!0});z.utf8Count=$u;z.utf8EncodeJs=vr;z.utf8EncodeTE=wr;z.utf8Encode=Bu;z.utf8DecodeJs=_r;z.utf8DecodeTD=xr;z.utf8Decode=Qu;function $u(t){let e=t.length,i=0,r=0;for(;r<e;){let n=t.charCodeAt(r++);if(n&4294967168)if(!(n&4294965248))i+=2;else{if(n>=55296&&n<=56319&&r<e){let o=t.charCodeAt(r);(o&64512)===56320&&(++r,n=((n&1023)<<10)+(o&1023)+65536)}n&4294901760?i+=4:i+=3}else{i++;continue}}return i}function vr(t,e,i){let r=t.length,n=i,o=0;for(;o<r;){let s=t.charCodeAt(o++);if(s&4294967168)if(!(s&4294965248))e[n++]=s>>6&31|192;else{if(s>=55296&&s<=56319&&o<r){let a=t.charCodeAt(o);(a&64512)===56320&&(++o,s=((s&1023)<<10)+(a&1023)+65536)}s&4294901760?(e[n++]=s>>18&7|240,e[n++]=s>>12&63|128,e[n++]=s>>6&63|128):(e[n++]=s>>12&15|224,e[n++]=s>>6&63|128)}else{e[n++]=s;continue}e[n++]=s&63|128}}var Nu=new TextEncoder,zu=50;function wr(t,e,i){Nu.encodeInto(t,e.subarray(i))}function Bu(t,e,i){t.length>zu?wr(t,e,i):vr(t,e,i)}var Ku=4096;function _r(t,e,i){let r=e,n=r+i,o=[],s="";for(;r<n;){let a=t[r++];if(!(a&128))o.push(a);else if((a&224)===192){let u=t[r++]&63;o.push((a&31)<<6|u)}else if((a&240)===224){let u=t[r++]&63,d=t[r++]&63;o.push((a&31)<<12|u<<6|d)}else if((a&248)===240){let u=t[r++]&63,d=t[r++]&63,l=t[r++]&63,c=(a&7)<<18|u<<12|d<<6|l;c>65535&&(c-=65536,o.push(c>>>10&1023|55296),c=56320|c&1023),o.push(c)}else o.push(a);o.length>=Ku&&(s+=String.fromCharCode(...o),o.length=0)}return o.length>0&&(s+=String.fromCharCode(...o)),s}var Hu=new TextDecoder,Gu=200;function xr(t,e,i){let r=t.subarray(e,e+i);return Hu.decode(r)}function Qu(t,e,i){return i>Gu?xr(t,e,i):_r(t,e,i)}});var Bt=T(st=>{"use strict";Object.defineProperty(st,"__esModule",{value:!0});st.ExtData=void 0;var zt=class{constructor(e,i){this.type=e,this.data=i}};st.ExtData=zt});var lt=T(at=>{"use strict";Object.defineProperty(at,"__esModule",{value:!0});at.DecodeError=void 0;var Kt=class t extends Error{constructor(e){super(e);let i=Object.create(t.prototype);Object.setPrototypeOf(this,i),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:t.name})}};at.DecodeError=Kt});var ut=T(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.UINT32_MAX=void 0;ee.setUint64=Wu;ee.setInt64=Yu;ee.getInt64=Zu;ee.getUint64=Xu;ee.UINT32_MAX=4294967295;function Wu(t,e,i){let r=i/4294967296,n=i;t.setUint32(e,r),t.setUint32(e+4,n)}function Yu(t,e,i){let r=Math.floor(i/4294967296),n=i;t.setUint32(e,r),t.setUint32(e+4,n)}function Zu(t,e){let i=t.getInt32(e),r=t.getUint32(e+4);return i*4294967296+r}function Xu(t,e){let i=t.getUint32(e),r=t.getUint32(e+4);return i*4294967296+r}});var Ht=T(M=>{"use strict";Object.defineProperty(M,"__esModule",{value:!0});M.timestampExtension=M.EXT_TIMESTAMP=void 0;M.encodeTimeSpecToTimestamp=Ir;M.encodeDateToTimeSpec=Sr;M.encodeTimestampExtension=Er;M.decodeTimestampToTimeSpec=Ar;M.decodeTimestampExtension=Cr;var Ju=lt(),Tr=ut();M.EXT_TIMESTAMP=-1;var ed=4294967296-1,td=17179869184-1;function Ir({sec:t,nsec:e}){if(t>=0&&e>=0&&t<=td)if(e===0&&t<=ed){let i=new Uint8Array(4);return new DataView(i.buffer).setUint32(0,t),i}else{let i=t/4294967296,r=t&4294967295,n=new Uint8Array(8),o=new DataView(n.buffer);return o.setUint32(0,e<<2|i&3),o.setUint32(4,r),n}else{let i=new Uint8Array(12),r=new DataView(i.buffer);return r.setUint32(0,e),(0,Tr.setInt64)(r,4,t),i}}function Sr(t){let e=t.getTime(),i=Math.floor(e/1e3),r=(e-i*1e3)*1e6,n=Math.floor(r/1e9);return{sec:i+n,nsec:r-n*1e9}}function Er(t){if(t instanceof Date){let e=Sr(t);return Ir(e)}else return null}function Ar(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{let i=e.getUint32(0),r=e.getUint32(4),n=(i&3)*4294967296+r,o=i>>>2;return{sec:n,nsec:o}}case 12:{let i=(0,Tr.getInt64)(e,4),r=e.getUint32(0);return{sec:i,nsec:r}}default:throw new Ju.DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${t.length}`)}}function Cr(t){let e=Ar(t);return new Date(e.sec*1e3+e.nsec/1e6)}M.timestampExtension={type:M.EXT_TIMESTAMP,encode:Er,decode:Cr}});var pt=T(ct=>{"use strict";Object.defineProperty(ct,"__esModule",{value:!0});ct.ExtensionCodec=void 0;var dt=Bt(),id=Ht(),je=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(id.timestampExtension)}register({type:e,encode:i,decode:r}){if(e>=0)this.encoders[e]=i,this.decoders[e]=r;else{let n=-1-e;this.builtInEncoders[n]=i,this.builtInDecoders[n]=r}}tryToEncode(e,i){for(let r=0;r<this.builtInEncoders.length;r++){let n=this.builtInEncoders[r];if(n!=null){let o=n(e,i);if(o!=null){let s=-1-r;return new dt.ExtData(s,o)}}}for(let r=0;r<this.encoders.length;r++){let n=this.encoders[r];if(n!=null){let o=n(e,i);if(o!=null){let s=r;return new dt.ExtData(s,o)}}}return e instanceof dt.ExtData?e:null}decode(e,i,r){let n=i<0?this.builtInDecoders[-1-i]:this.decoders[i];return n?n(e,i,r):new dt.ExtData(i,e)}};ct.ExtensionCodec=je;je.defaultCodec=new je});var Qt=T(Gt=>{"use strict";Object.defineProperty(Gt,"__esModule",{value:!0});Gt.ensureUint8Array=nd;function rd(t){return t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer}function nd(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):rd(t)?new Uint8Array(t):Uint8Array.from(t)}});var Yt=T(L=>{"use strict";Object.defineProperty(L,"__esModule",{value:!0});L.Encoder=L.DEFAULT_INITIAL_BUFFER_SIZE=L.DEFAULT_MAX_DEPTH=void 0;var kr=ot(),od=pt(),Pr=ut(),sd=Qt();L.DEFAULT_MAX_DEPTH=100;L.DEFAULT_INITIAL_BUFFER_SIZE=2048;var Wt=class t{constructor(e){this.entered=!1,this.extensionCodec=e?.extensionCodec??od.ExtensionCodec.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??L.DEFAULT_MAX_DEPTH,this.initialBufferSize=e?.initialBufferSize??L.DEFAULT_INITIAL_BUFFER_SIZE,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new t({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(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,i){if(i>this.maxDepth)throw new Error(`Too deep objects in depth ${i}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,i)}ensureBufferSizeToWrite(e){let i=this.pos+e;this.view.byteLength<i&&this.resizeBuffer(i*2)}resizeBuffer(e){let i=new ArrayBuffer(e),r=new Uint8Array(i),n=new DataView(i);r.set(this.bytes),this.view=n,this.bytes=r}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){let r=(0,kr.utf8Count)(e);this.ensureBufferSizeToWrite(5+r),this.writeStringHeader(r),(0,kr.utf8Encode)(e,this.bytes,this.pos),this.pos+=r}encodeObject(e,i){let r=this.extensionCodec.tryToEncode(e,this.context);if(r!=null)this.encodeExtension(r);else if(Array.isArray(e))this.encodeArray(e,i);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,i);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){let i=e.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,sd.ensureUint8Array)(e);this.writeU8a(r)}encodeArray(e,i){let r=e.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 e)this.doEncode(n,i+1)}countWithoutUndefined(e,i){let r=0;for(let n of i)e[n]!==void 0&&r++;return r}encodeMap(e,i){let r=Object.keys(e);this.sortKeys&&r.sort();let n=this.ignoreUndefined?this.countWithoutUndefined(e,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 o of r){let s=e[o];this.ignoreUndefined&&s===void 0||(this.encodeString(o),this.doEncode(s,i+1))}}encodeExtension(e){if(typeof e.data=="function"){let r=e.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(e.type),this.writeU8a(r);return}let i=e.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(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){let i=e.length;this.ensureBufferSizeToWrite(i),this.bytes.set(e,this.pos),this.pos+=i}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),(0,Pr.setUint64)(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),(0,Pr.setInt64)(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}};L.Encoder=Wt});var qr=T(Zt=>{"use strict";Object.defineProperty(Zt,"__esModule",{value:!0});Zt.encode=ld;var ad=Yt();function ld(t,e){return new ad.Encoder(e).encodeSharedRef(t)}});var Vr=T(Xt=>{"use strict";Object.defineProperty(Xt,"__esModule",{value:!0});Xt.prettyByte=ud;function ud(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}});var Mr=T(mt=>{"use strict";Object.defineProperty(mt,"__esModule",{value:!0});mt.CachedKeyDecoder=void 0;var dd=ot(),cd=16,pd=16,Jt=class{constructor(e=cd,i=pd){this.hit=0,this.miss=0,this.maxKeyLength=e,this.maxLengthPerKey=i,this.caches=[];for(let r=0;r<this.maxKeyLength;r++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,i,r){let n=this.caches[r-1];e:for(let o of n){let s=o.bytes;for(let a=0;a<r;a++)if(s[a]!==e[i+a])continue e;return o.str}return null}store(e,i){let r=this.caches[e.length-1],n={bytes:e,str:i};r.length>=this.maxLengthPerKey?r[Math.random()*r.length|0]=n:r.push(n)}decode(e,i,r){let n=this.find(e,i,r);if(n!=null)return this.hit++,n;this.miss++;let o=(0,dd.utf8DecodeJs)(e,i,r),s=Uint8Array.prototype.slice.call(e,i,i+r);return this.store(s,o),o}};mt.CachedKeyDecoder=Jt});var gt=T(ft=>{"use strict";Object.defineProperty(ft,"__esModule",{value:!0});ft.Decoder=void 0;var ei=Vr(),md=pt(),ne=ut(),fd=ot(),Dr=Qt(),gd=Mr(),B=lt(),ti="array",Fe="map_key",Or="map_value",hd=t=>{if(typeof t=="string"||typeof t=="number")return t;throw new B.DecodeError("The type of key must be string or number but "+typeof t)},ii=class{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let i=this.getUninitializedStateFromPool();i.type=ti,i.position=0,i.size=e,i.array=new Array(e)}pushMapState(e){let i=this.getUninitializedStateFromPool();i.type=Fe,i.readCount=0,i.size=e,i.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===ti){let r=e;r.size=0,r.array=void 0,r.position=0,r.type=void 0}if(e.type===Fe||e.type===Or){let r=e;r.size=0,r.map=void 0,r.readCount=0,r.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},Oe=-1,ni=new DataView(new ArrayBuffer(0)),yd=new Uint8Array(ni.buffer);try{ni.getInt8(0)}catch(t){if(!(t 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 jr=new RangeError("Insufficient data"),bd=new gd.CachedKeyDecoder,ri=class t{constructor(e){this.totalPos=0,this.pos=0,this.view=ni,this.bytes=yd,this.headByte=Oe,this.stack=new ii,this.entered=!1,this.extensionCodec=e?.extensionCodec??md.ExtensionCodec.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??ne.UINT32_MAX,this.maxBinLength=e?.maxBinLength??ne.UINT32_MAX,this.maxArrayLength=e?.maxArrayLength??ne.UINT32_MAX,this.maxMapLength=e?.maxMapLength??ne.UINT32_MAX,this.maxExtLength=e?.maxExtLength??ne.UINT32_MAX,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:bd,this.mapKeyConverter=e?.mapKeyConverter??hd}clone(){return new t({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=Oe,this.stack.reset()}setBuffer(e){let i=(0,Dr.ensureUint8Array)(e);this.bytes=i,this.view=new DataView(i.buffer,i.byteOffset,i.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===Oe&&!this.hasRemaining(1))this.setBuffer(e);else{let i=this.bytes.subarray(this.pos),r=(0,Dr.ensureUint8Array)(e),n=new Uint8Array(i.length+r.length);n.set(i),n.set(r,i.length),this.setBuffer(n)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:i,pos:r}=this;return new RangeError(`Extra ${i.byteLength-r} of ${i.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let i=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return i}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let i=!1,r;for await(let a of e){if(i)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(a);try{r=this.doDecodeSync(),i=!0}catch(u){if(!(u instanceof RangeError))throw u}this.totalPos+=this.pos}if(i){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return r}let{headByte:n,pos:o,totalPos:s}=this;throw new RangeError(`Insufficient data in parsing ${(0,ei.prettyByte)(n)} at ${s} (${o} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,i){if(this.entered){yield*this.clone().decodeMultiAsync(e,i);return}try{this.entered=!0;let r=i,n=-1;for await(let o of e){if(i&&n===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(o),r&&(n=this.readArraySize(),r=!1,this.complete());try{for(;yield this.doDecodeSync(),--n!==0;);}catch(s){if(!(s instanceof RangeError))throw s}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){let e=this.readHeadByte(),i;if(e>=224)i=e-256;else if(e<192)if(e<128)i=e;else if(e<144){let n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue e}else i={}}else if(e<160){let n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue e}else i=[]}else{let n=e-160;i=this.decodeString(n,0)}else if(e===192)i=null;else if(e===194)i=!1;else if(e===195)i=!0;else if(e===202)i=this.readF32();else if(e===203)i=this.readF64();else if(e===204)i=this.readU8();else if(e===205)i=this.readU16();else if(e===206)i=this.readU32();else if(e===207)this.useBigInt64?i=this.readU64AsBigInt():i=this.readU64();else if(e===208)i=this.readI8();else if(e===209)i=this.readI16();else if(e===210)i=this.readI32();else if(e===211)this.useBigInt64?i=this.readI64AsBigInt():i=this.readI64();else if(e===217){let n=this.lookU8();i=this.decodeString(n,1)}else if(e===218){let n=this.lookU16();i=this.decodeString(n,2)}else if(e===219){let n=this.lookU32();i=this.decodeString(n,4)}else if(e===220){let n=this.readU16();if(n!==0){this.pushArrayState(n),this.complete();continue e}else i=[]}else if(e===221){let n=this.readU32();if(n!==0){this.pushArrayState(n),this.complete();continue e}else i=[]}else if(e===222){let n=this.readU16();if(n!==0){this.pushMapState(n),this.complete();continue e}else i={}}else if(e===223){let n=this.readU32();if(n!==0){this.pushMapState(n),this.complete();continue e}else i={}}else if(e===196){let n=this.lookU8();i=this.decodeBinary(n,1)}else if(e===197){let n=this.lookU16();i=this.decodeBinary(n,2)}else if(e===198){let n=this.lookU32();i=this.decodeBinary(n,4)}else if(e===212)i=this.decodeExtension(1,0);else if(e===213)i=this.decodeExtension(2,0);else if(e===214)i=this.decodeExtension(4,0);else if(e===215)i=this.decodeExtension(8,0);else if(e===216)i=this.decodeExtension(16,0);else if(e===199){let n=this.lookU8();i=this.decodeExtension(n,1)}else if(e===200){let n=this.lookU16();i=this.decodeExtension(n,2)}else if(e===201){let n=this.lookU32();i=this.decodeExtension(n,4)}else throw new B.DecodeError(`Unrecognized type byte: ${(0,ei.prettyByte)(e)}`);this.complete();let r=this.stack;for(;r.length>0;){let n=r.top();if(n.type===ti)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===Fe){if(i==="__proto__")throw new B.DecodeError("The key __proto__ is not allowed");n.key=this.mapKeyConverter(i),n.type=Or;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=Fe;continue e}}return i}}readHeadByte(){return this.headByte===Oe&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Oe}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new B.DecodeError(`Unrecognized array type byte: ${(0,ei.prettyByte)(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new B.DecodeError(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new B.DecodeError(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,i){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,i):this.decodeBinary(e,i)}decodeUtf8String(e,i){if(e>this.maxStrLength)throw new B.DecodeError(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+i+e)throw jr;let r=this.pos+i,n;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?n=this.keyDecoder.decode(this.bytes,r,e):n=(0,fd.utf8Decode)(this.bytes,r,e),this.pos+=i+e,n}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===Fe:!1}decodeBinary(e,i){if(e>this.maxBinLength)throw new B.DecodeError(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+i))throw jr;let r=this.pos+i,n=this.bytes.subarray(r,r+e);return this.pos+=i+e,n}decodeExtension(e,i){if(e>this.maxExtLength)throw new B.DecodeError(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let r=this.view.getInt8(this.pos+i),n=this.decodeBinary(e,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 e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=(0,ne.getUint64)(this.view,this.pos);return this.pos+=8,e}readI64(){let e=(0,ne.getInt64)(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};ft.Decoder=ri});var Rr=T(ht=>{"use strict";Object.defineProperty(ht,"__esModule",{value:!0});ht.decode=vd;ht.decodeMulti=wd;var Fr=gt();function vd(t,e){return new Fr.Decoder(e).decode(t)}function wd(t,e){return new Fr.Decoder(e).decodeMulti(t)}});var $r=T(Re=>{"use strict";Object.defineProperty(Re,"__esModule",{value:!0});Re.isAsyncIterable=Ur;Re.asyncIterableFromStream=Lr;Re.ensureAsyncIterable=_d;function Ur(t){return t[Symbol.asyncIterator]!=null}async function*Lr(t){let e=t.getReader();try{for(;;){let{done:i,value:r}=await e.read();if(i)return;yield r}}finally{e.releaseLock()}}function _d(t){return Ur(t)?t:Lr(t)}});var Nr=T(Ue=>{"use strict";Object.defineProperty(Ue,"__esModule",{value:!0});Ue.decodeAsync=xd;Ue.decodeArrayStream=Td;Ue.decodeMultiStream=Id;var oi=gt(),si=$r();async function xd(t,e){let i=(0,si.ensureAsyncIterable)(t);return new oi.Decoder(e).decodeAsync(i)}function Td(t,e){let i=(0,si.ensureAsyncIterable)(t);return new oi.Decoder(e).decodeArrayStream(i)}function Id(t,e){let i=(0,si.ensureAsyncIterable)(t);return new oi.Decoder(e).decodeStream(i)}});var Br=T(w=>{"use strict";Object.defineProperty(w,"__esModule",{value:!0});w.decodeTimestampExtension=w.encodeTimestampExtension=w.decodeTimestampToTimeSpec=w.encodeTimeSpecToTimestamp=w.encodeDateToTimeSpec=w.EXT_TIMESTAMP=w.ExtData=w.ExtensionCodec=w.Encoder=w.DecodeError=w.Decoder=w.decodeMultiStream=w.decodeArrayStream=w.decodeAsync=w.decodeMulti=w.decode=w.encode=void 0;var Sd=qr();Object.defineProperty(w,"encode",{enumerable:!0,get:function(){return Sd.encode}});var zr=Rr();Object.defineProperty(w,"decode",{enumerable:!0,get:function(){return zr.decode}});Object.defineProperty(w,"decodeMulti",{enumerable:!0,get:function(){return zr.decodeMulti}});var ai=Nr();Object.defineProperty(w,"decodeAsync",{enumerable:!0,get:function(){return ai.decodeAsync}});Object.defineProperty(w,"decodeArrayStream",{enumerable:!0,get:function(){return ai.decodeArrayStream}});Object.defineProperty(w,"decodeMultiStream",{enumerable:!0,get:function(){return ai.decodeMultiStream}});var Ed=gt();Object.defineProperty(w,"Decoder",{enumerable:!0,get:function(){return Ed.Decoder}});var Ad=lt();Object.defineProperty(w,"DecodeError",{enumerable:!0,get:function(){return Ad.DecodeError}});var Cd=Yt();Object.defineProperty(w,"Encoder",{enumerable:!0,get:function(){return Cd.Encoder}});var kd=pt();Object.defineProperty(w,"ExtensionCodec",{enumerable:!0,get:function(){return kd.ExtensionCodec}});var Pd=Bt();Object.defineProperty(w,"ExtData",{enumerable:!0,get:function(){return Pd.ExtData}});var ve=Ht();Object.defineProperty(w,"EXT_TIMESTAMP",{enumerable:!0,get:function(){return ve.EXT_TIMESTAMP}});Object.defineProperty(w,"encodeDateToTimeSpec",{enumerable:!0,get:function(){return ve.encodeDateToTimeSpec}});Object.defineProperty(w,"encodeTimeSpecToTimestamp",{enumerable:!0,get:function(){return ve.encodeTimeSpecToTimestamp}});Object.defineProperty(w,"decodeTimestampToTimeSpec",{enumerable:!0,get:function(){return ve.decodeTimestampToTimeSpec}});Object.defineProperty(w,"encodeTimestampExtension",{enumerable:!0,get:function(){return ve.encodeTimestampExtension}});Object.defineProperty(w,"decodeTimestampExtension",{enumerable:!0,get:function(){return ve.decodeTimestampExtension}})});var sn=T(D=>{"use strict";Object.defineProperty(D,"__esModule",{value:!0});function P(t){return{enumerable:!0,value:t}}function Kr(t){return{enumerable:!0,writable:!0,value:t}}var oe={},qd=()=>!0,Hr=()=>({}),Qr=t=>t,Vd=(t,e,i,r)=>t.apply(i,r)&&e.apply(i,r),Md=(t,e,i,[r,n])=>e.call(i,t.call(i,r,n),n),te=(t,e)=>Object.freeze(Object.create(t,e));function Gr(t,e,i){return t.reduce((r,n)=>function(...o){return i(r,n,this,o)},e)}function Wr(t