needle-cloud 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import e,{UserScope as t}from"@logto/browser";var n,r={Basic:[t.Profile,t.Email],Payment:["read:accounting","write:accounting"],All:[t.Profile,t.Email,t.Roles,t.CustomData,t.Organizations,t.OrganizationRoles].concat(["all","read","write","delete","invite","download","create:org","write:org","delete:org","read:accounting","write:accounting","read:usage"])},o=["Needle Engine"],i="[Needle Cloud]",s="https://auth.needle.tools",a=void 0,u=[],l=null,c=null,f=null,d=null,h=new Array;function p(){h.forEach(function(e){try{e()}catch(e){v.error(e)}})}var m=!1,v=console,g=Promise.resolve();function y(e){var t=g.then(function(){var t,n=null==(t=globalThis.navigator)?void 0:t.locks;return null!=n&&n.request?n.request("needle-auth:token-exchange:"+a,e):e()});return g=t.then(function(){},function(){}),t}var b,w,P,_,j,E=(b=function(e){return m&&v.debug(i,"requestAccessToken",{org_id:e}),y(function(){return e?R().getOrganizationToken(e):R().getAccessToken("https://cloud.needle.tools/api",e||void 0)}).catch(function(e){throw S(e),e})},w=new Map,function(e){var t=null==e?"\0none":String(e),n=w.get(t);if(n)return n;var r=function(){try{return Promise.resolve(b(e))}catch(e){return Promise.reject(e)}}().finally(function(){w.get(t)===r&&w.delete(t)});return w.set(t,r),r});function S(e){return!!function(e){var t,n;if(!e||"object"!=typeof e)return!1;var r=e,o=function(e){if("string"!=typeof e)return!1;var t=e.replace(/^oidc\./,"");return"invalid_grant"===t||"invalid_target"===t};return o(r.code)||o(null==(t=r.data)?void 0:t.error)||o(null==(n=r.data)?void 0:n.code)}(e)&&(v.warn(i,"Stored session is no longer valid — clearing tokens (sign in again)"),n=!1,R().clearAllTokens().catch(function(){}),!0)}var x=function(){var e,t;return null!=(e=null==(t=globalThis.location)?void 0:t.origin)?e:""},T={setLogger:function(e){v=e},setDebug:function(e){m=e},get baseUrl(){var e;return null!=(e=P)?e:P=x()},set baseUrl(e){P=e},get redirectUri(){var e;return null!=(e=_)?e:_=x()},set redirectUri(e){_=e},get postSignOutRedirectUri(){var e;return null!=(e=j)?e:j=x()},set postSignOutRedirectUri(e){j=e},onChanged:function(e){return h.includes(e)||h.push(e),function(){for(;;){var t=h.indexOf(e);if(!(t>=0))break;h.splice(t,1)}}},ready:function(){return c?c.then(function(){return!0}):Promise.reject(new Error("Auth not initialized"))},init:function(e){return c||(c=function(e){try{var t,n,o=function(){var e=O(!0);if(!e)return T.checkIsAuthenticated().then(function(e){return!e||T.requestUserInfo().then(function(){return!0})});var t=new URL(window.location.href);return t.search=e,window.history.replaceState({},"",t.href),Promise.resolve(!0)};if(null!=e&&e.debug&&(m=e.debug),m&&v.debug(i,"Auth.init",e),null!=e&&e.scopes){switch(e.scopes){case"all":e.scopes=r.All;break;case"payment":e.scopes=r.Payment}u=e.scopes}u.length<=0&&(t=u).push.apply(t,r.Basic.concat(r.Payment)),m&&v.debug(i,"Auth.init","Use scopes",u),null!=e&&e.appId?(null==(n=d)?void 0:n.logtoConfig.appId)!==(a=e.appId)&&(m&&v.debug(i,"Auth.init","App ID changed, resetting client"),d=null):(a="2x82zzh5xuudmiotdy2ux",m&&v.debug(i,"Auth.init","Use default app ID",a));var l=function(){var e,t=new URL(window.location.href);if(t.searchParams.has("code")&&t.searchParams.has("state")&&null!=(e=t.searchParams.get("iss"))&&e.includes(s))return R().handleSignInCallback(t.href).then(function(){var e=new URL(window.location.href);e.pathname=e.pathname.replace("callback",""),e.searchParams.delete("code"),e.searchParams.delete("state"),e.searchParams.delete("iss");var t=O();t&&(v.info(i,"Restore query before login",t,"Current:",e.search),e.search=t),window.history.replaceState({},"",e.href)}).catch(function(e){v.error(e)})}(),c=function(){if(l instanceof Promise)return Promise.resolve(l.then(function(e){return!0})).then(function(){})}();return Promise.resolve(c&&c.then?c.then(o):o())}catch(e){return Promise.reject(e)}}(e))},isAuthenticated:function(){return n},checkIsAuthenticated:function(){return R().isAuthenticated().then(function(e){return n=e,e})},getUserInfo:function(){return l},getUserId:function(){return l?l.sub:null},getName:function(){return l?l.username?l.username:l.name?l.name:l.email?l.email.split("@")[0]:null:null},requestUserInfo:function(){return f||(f=T.checkIsAuthenticated().then(function(e){return e?y(function(){return R().fetchUserInfo()}).then(function(e){var t;return m&&(null==e?void 0:e.sub)!=(null==(t=l)?void 0:t.sub)&&v.debug(i,"UserInfo",e),l=e,p(),e}).catch(function(e){return v.error(e),S(e),l=null,p(),null}):(l=null,p(),null)}))},requestAccessToken:function(e){return E(null!=e?e:void 0)},signIn:function(e){return T.checkIsAuthenticated().then(function(t){if(0==t){var n;if(null==(n=a)||!n.length)throw new Error("App ID is not set: Make sure to call 'init' first");k(),null!=e&&e.signUp?R().signIn({redirectUri:T.redirectUri,firstScreen:"register",interactionMode:"signUp"}):R().signIn(T.redirectUri)}})},getDefaultTeamId:function(){var e,t=null==(e=l)?void 0:e.custom_data,n=null==t?void 0:t.default_org;return"string"==typeof n?n:void 0},signOut:function(){return f=null,T.checkIsAuthenticated().then(function(e){if(1==e){var t;if(null==(t=a)||!t.length)throw new Error("App ID is not set: Make sure to call 'init' first");k(),R().signOut(T.postSignOutRedirectUri)}})}};function k(){sessionStorage.setItem("needle-auth:query",window.location.search)}function O(e){void 0===e&&(e=!0);var t=sessionStorage.getItem("needle-auth:query");return t?(e&&sessionStorage.removeItem("needle-auth:query"),t):""}function R(){if(!d){if(!a)throw new Error("App ID is not set: Make sure to call 'init' first");var t={endpoint:s,appId:a,scopes:u,resources:["https://cloud.needle.tools/api"]};m&&v.warn(i,"Creating auth client:",m,t),d=new e(t)}return d}function U(e,t){this.v=e,this.k=t}function C(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function A(e){var t={},n=!1;function r(t,r){return n=!0,r=new Promise(function(n){n(e[t](r))}),{done:!1,value:new U(r,1)}}return t["undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator"]=function(){return this},t.next=function(e){return n?(n=!1,e):r("next",e)},"function"==typeof e.throw&&(t.throw=function(e){if(n)throw n=!1,e;return r("throw",e)}),"function"==typeof e.return&&(t.return=function(e){return n?(n=!1,e):r("return",e)}),t}function W(e){var t,n,r,o=2;for("undefined"!=typeof Symbol&&(n=Symbol.asyncIterator,r=Symbol.iterator);o--;){if(n&&null!=(t=e[n]))return t.call(e);if(r&&null!=(t=e[r]))return new N(t.call(e));n="@@asyncIterator",r="@@iterator"}throw new TypeError("Object is not async iterable")}function N(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:t}})}return N=function(e){this.s=e,this.n=e.next},N.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var n=this.s.return;return void 0===n?Promise.resolve({value:e,done:!0}):t(n.apply(this.s,arguments))},throw:function(e){var n=this.s.return;return void 0===n?Promise.reject(e):t(n.apply(this.s,arguments))}},new N(e)}function I(e){return new U(e,0)}function L(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return C(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?C(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(){return F=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},F.apply(null,arguments)}function z(e){return z=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},z(e)}function D(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,J(e,t)}function M(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(M=function(){return!!e})()}function B(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function q(){q=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=Object.create((t&&t.prototype instanceof g?t:g).prototype),s=new R(r||[]);return o(i,"_invoke",{value:x(e,n,s)}),i}function f(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=c;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",v={};function g(){}function y(){}function b(){}var w={};l(w,s,function(){return this});var P=Object.getPrototypeOf,_=P&&P(P(U([])));_&&_!==n&&r.call(_,s)&&(w=_);var j=b.prototype=g.prototype=Object.create(w);function E(e){["next","throw","return"].forEach(function(t){l(e,t,function(e){return this._invoke(t,e)})})}function S(e,t){function n(o,i,s,a){var u=f(e[o],e,i);if("throw"!==u.type){var l=u.arg,c=l.value;return c&&"object"==typeof c&&r.call(c,"__await")?t.resolve(c.__await).then(function(e){n("next",e,s,a)},function(e){n("throw",e,s,a)}):t.resolve(c).then(function(e){l.value=e,s(l)},function(e){return n("throw",e,s,a)})}a(u.arg)}var i;o(this,"_invoke",{value:function(e,r){function o(){return new t(function(t,o){n(e,r,t,o)})}return i=i?i.then(o,o):o()}})}function x(t,n,r){var o=d;return function(i,s){if(o===p)throw Error("Generator is already running");if(o===m){if("throw"===i)throw s;return{value:e,done:!0}}for(r.method=i,r.arg=s;;){var a=r.delegate;if(a){var u=T(a,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===d)throw o=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=p;var l=f(t,n,r);if("normal"===l.type){if(o=r.done?m:h,l.arg===v)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(o=m,r.method="throw",r.arg=l.arg)}}}function T(t,n){var r=n.method,o=t.iterator[r];if(o===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,T(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var i=f(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,v;var s=i.arg;return s?s.done?(n[t.resultName]=s.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,v):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function k(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function U(t){if(t||""===t){var n=t[s];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function n(){for(;++o<t.length;)if(r.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=e,n.done=!0,n};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return y.prototype=b,o(j,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:y,configurable:!0}),y.displayName=l(b,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,l(e,u,"GeneratorFunction")),e.prototype=Object.create(j),e},t.awrap=function(e){return{__await:e}},E(S.prototype),l(S.prototype,a,function(){return this}),t.AsyncIterator=S,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var s=new S(c(e,n,r,o),i);return t.isGeneratorFunction(n)?s:s.next().then(function(e){return e.done?e.value:s.next()})},E(j),l(j,u,"Generator"),l(j,s,function(){return this}),l(j,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},t.values=U,R.prototype={constructor:R,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function o(r,o){return a.type="throw",a.arg=t,n.next=r,o&&(n.method="next",n.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return o("end");if(s.tryLoc<=this.prev){var u=r.call(s,"catchLoc"),l=r.call(s,"finallyLoc");if(u&&l){if(this.prev<s.catchLoc)return o(s.catchLoc,!0);if(this.prev<s.finallyLoc)return o(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return o(s.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return o(s.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),O(n),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;O(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:U(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function J(e,t){return J=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},J(e,t)}function H(e){return function(){return new G(e.apply(this,arguments))}}function G(e){var t,n;function r(t,n){try{var i=e[t](n),s=i.value,a=s instanceof U;Promise.resolve(a?s.v:s).then(function(n){if(a){var u="return"===t?"return":"next";if(!s.k||n.done)return r(u,n);n=e[u](n).value}o(i.done?"return":"normal",n)},function(e){r("throw",e)})}catch(e){o("throw",e)}}function o(e,o){switch(e){case"return":t.resolve({value:o,done:!0});break;case"throw":t.reject(o);break;default:t.resolve({value:o,done:!1})}(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,o){return new Promise(function(i,s){var a={key:e,arg:o,resolve:i,reject:s,next:null};n?n=n.next=a:(t=n=a,r(e,o))})},"function"!=typeof e.return&&(this.return=void 0)}function V(e){var t="function"==typeof Map?new Map:void 0;return V=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(M())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var o=new(e.bind.apply(e,r));return n&&J(o,n.prototype),o}(e,arguments,z(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),J(n,e)},V(e)}function $(){$=function(e,t){return new n(e,void 0,t)};var e=RegExp.prototype,t=new WeakMap;function n(e,r,o){var i=RegExp(e,r);return t.set(i,o||t.get(e)),J(i,n.prototype)}function r(e,n){var r=t.get(n);return Object.keys(r).reduce(function(t,n){var o=r[n];if("number"==typeof o)t[n]=e[o];else{for(var i=0;void 0===e[o[i]]&&i+1<o.length;)i++;t[n]=e[o[i]]}return t},Object.create(null))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&J(e,t)}(n,RegExp),n.prototype.exec=function(t){var n=e.exec.call(this,t);if(n){n.groups=r(n,this);var o=n.indices;o&&(o.groups=r(o,this))}return n},n.prototype[Symbol.replace]=function(n,o){if("string"==typeof o){var i=t.get(this);return e[Symbol.replace].call(this,n,o.replace(/\$<([^>]+)>/g,function(e,t){var n=i[t];return"$"+(Array.isArray(n)?n.join("$"):n)}))}if("function"==typeof o){var s=this;return e[Symbol.replace].call(this,n,function(){var e=arguments;return"object"!=typeof e[e.length-1]&&(e=[].slice.call(e)).push(r(e,s)),o.apply(this,e)})}return e[Symbol.replace].call(this,n,o)},$.apply(this,arguments)}G.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},G.prototype.next=function(e){return this._invoke("next",e)},G.prototype.throw=function(e){return this._invoke("throw",e)},G.prototype.return=function(e){return this._invoke("return",e)};var K=void 0;if("undefined"!=typeof HTMLButtonElement&&"undefined"!=typeof customElements)if(K=/*#__PURE__*/function(e){function t(){var t;return(t=e.call(this)||this).addEventListener("click",function(){T.isAuthenticated()?T.signOut():T.signIn()}),t}D(t,e);var n=t.prototype;return n.connectedCallback=function(){var e=this;console.debug("Login button connected..."),this.__update(),this.__unsubscribeOnChange=T.onChanged(function(){e.__update()})},n.disconnectedCallback=function(){var e;null==(e=this.__unsubscribeOnChange)||e.call(this)},n.__update=function(){this.innerHTML=T.isAuthenticated()?"Logout":"Login"},t}(/*#__PURE__*/V(HTMLButtonElement)),customElements.get("needle-login-button"))try{("localhost"===window.location.hostname||/^(127|192\.168|10\.|172\.(1[6-9]|2[0-9]|3[0-1]))\./.test(window.location.hostname))&&console.debug("needle-login-button is already defined.")}catch(e){}else customElements.define("needle-login-button",K,{extends:"button"});var X=/*#__PURE__*/function(e){function t(t,n,r){var o;return(o=e.call(this,r)||this).name="ApiError",o.status=t,o.body=n,o}return D(t,e),t}(/*#__PURE__*/V(Error)),Y={status:"/v1/status",version:"/v1/version",api:"/v1/api",runtime_snapshots:{release_get:"/v1/runtime-releases",get:"/v1/runtime-snapshots/:hash",file:"/v1/runtime-snapshots/:hash/files/*"},usage:{get:"/v1/usage"},affiliate:{get:"/v1/affiliate/get",link_clicked:"/v1/affiliate/link_clicked"},account:{public_key:"/v1/account/public_key",post_machine:"/v1/account/machine",connect:"/v1/account/connect",get_licenses:"/v1/account/get/licenses",set_license_active:"/v1/account/set_license_active",set_licenses_active:"/v1/account/set_licenses_active",buy_licenses:"/v1/account/buy_licenses",update_licenses:"/v1/account/update_licenses",preview_invitation:"/v1/account/preview_invitation",update_payment_method:"/v1/account/update_payment_method",get_billing:"/v1/account/get_billing",generate_invoice:"/v1/account/generate_invoice",resume_subscription:"/v1/account/resume_subscription",cancel_subscription:"/v1/account/cancel_subscription",start_billingportal_session:"/v1/account/start_billingportal_session",post_preferences:"/v1/account/preferences",get_preferences:"/v1/account/preferences"},payment:{info:"/v1/payment/info",create:"/v1/payment/create"},ai:{llmstxt:"/v1/ai/llmstxt",chat:"/v1/ai/chat",chat_personal:"/v1/ai/chat/personal",list_chats:"/v1/ai/chat/list",chat_image:"/v1/ai/chat/image",chat_tool_result:"/v1/ai/chat/tool-result",chat_stop:"/v1/ai/chat/stop",chat_file_edits:"/v1/ai/file-edits",chat_file_edit_undo:"/v1/ai/file-edits/undo",chat_enqueue:"/v1/ai/chat/enqueue",chat_enqueue_cancel:"/v1/ai/chat/enqueue/cancel",ask:"/v1/ai/ask",completions:"/v1/ai/completions",evaluate:"/v1/ai/evaluate",post_settings:"/v1/ai/chat/settings",ws:"/v1/ws",cli_ws:"/v1/cli/ws"},organizations:{get:"/v1/organizations/get",orgs_details:"/v1/organizations/details",licenses:"/v1/organizations/licenses",get_invitations:"/v1/organizations/get_invitations"},events:{get:"/v1/events/get",post:"/v1/events/post",list:"/v1/events/list"},reports:{get:"/v1/reports/get",post:"/v1/reports/post"},diagnostics:{download_failed:"/v1/diagnostics/download-failed"},questionnaire:{get:"/v1/questionnaires/get",post:"/v1/questionnaires/post"},roadmap:{get:"/v1/roadmap/get",post_vote:"/v1/roadmap/post"},tokens:{create:"/v1/tokens/create",delete:"/v1/tokens/delete",list:"/v1/tokens/list"},get:{stats:"/v1/get/stats",jobs:"/v1/list/jobs",deployments:"/v1/list/deployments",discounts:"/v1/get/discounts"},files:{entry:"/v1/files/:identifier/:version/",file:"/v1/files/:identifier/:version/*"},view:{get_analytics:"/v1/view/analytics",get_public_info:"/v1/view/public/info",post_version:"/v1/view/post_version"},content:{root:"/v1/content",download:"/v1/content/download",detail:"/v1/content/:identifier",update:"/v1/content/:identifier",delete:"/v1/content/:identifier",restore:"/v1/content/:identifier/restore",visits:"/v1/content/:identifier/visits",domains:"/v1/content/:identifier/domains",domain_item:"/v1/content/:identifier/domains/:hostname",domain_verify:"/v1/content/:identifier/domains/:hostname/verify"},analytics:{content_list:"/v1/analytics/content-list"},public:{content_list:"/v1/public/content",content_detail:"/v1/public/content/:identifier"},collections:{list:"/v1/collections/list",get:"/v1/collections/get",create:"/v1/collections/create",update:"/v1/collections/update",delete:"/v1/collections/delete",add_item:"/v1/collections/add-item",remove_item:"/v1/collections/remove-item",reorder_items:"/v1/collections/reorder-items"},projects:{create:"/v1/projects/create",list:"/v1/projects/list",head:"/v1/projects/head",push:"/v1/projects/push",pull:"/v1/projects/pull",delete:"/v1/projects/delete",restore:"/v1/projects/restore",archive:"/v1/projects/archive",unarchive:"/v1/projects/unarchive",clone:"/v1/projects/clone",update:"/v1/projects/update",blobs_check:"/v1/projects/blobs/check",blobs_upload:"/v1/projects/blobs/upload",blobs_complete:"/v1/projects/blobs/complete",blobs_download:"/v1/projects/blobs/download",revisions:"/v1/projects/revisions",revisions_update:"/v1/projects/revisions/update",deployments:"/v1/projects/deployments",promote:"/v1/projects/promote",promotions:"/v1/projects/promotions"},upload:{request:"/v1/upload/request",request_put_url:"/v1/upload/put",update_results:"/v1/upload/results",done:"/v1/upload/done",cancel:"/v1/upload/cancel",multipart_create:"/v1/upload/multipart/create",multipart_part_urls:"/v1/upload/multipart/part-urls",multipart_complete:"/v1/upload/multipart/complete",multipart_abort:"/v1/upload/multipart/abort"},jobs:{create:"/v1/jobs/create",get_id:"/v1/jobs/get_id",presigned_url:"/v1/jobs/presigned-url",presigned_urls:"/v1/jobs/presigned-urls",download_urls:"/v1/jobs/download-urls",request_restart:"/v1/jobs/restart",delete:"/v1/jobs/delete",post_update:"/v1/jobs/update",post_usage:"/v1/jobs/post_usage",get_status:"/v1/jobs/status",get_org:"/v1/jobs/org",query:"/v1/jobs/query"},worker:{get_available_count:"/v1/worker/get_available_count"},local_projects:{get:{user:"/v1/local_projects/user",by_id:"/v1/local_projects/"},post:"/v1/local_projects"}};function Z(e){var t={authorization:"Bearer "+e.authToken};return e.org&&(t["x-needle-cloud-org"]=e.org),e.roles&&(t.roles=e.roles.join(",")),e.roles_org&&(t.roles_org=e.roles_org.join(",")),t}var Q={credentials:"omit"},ee=function(e,t){try{var n=e.baseUrl+Y.account.get_licenses,r=F({},t),o=F({},r,Z(e));return Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:o})).catch(function(e){return console.error(e),null})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json()).then(function(e){return e.licenses})}if(!e)return[];var r=function(){if(!e.ok){var n=e.statusText;return Promise.resolve(e.text()).then(function(e){return console.error(n,e),t=1,[]})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}};function te(e,t){return function(){return e.apply(t,arguments)}}const{toString:ne}=Object.prototype,{getPrototypeOf:re}=Object,{iterator:oe,toStringTag:ie}=Symbol,se=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),ae=(e,t)=>{let n=e;const r=[];for(;null!=n&&n!==Object.prototype;){if(-1!==r.indexOf(n))return!1;if(r.push(n),se(n,t))return!0;n=re(n)}return!1},ue=(le=Object.create(null),e=>{const t=ne.call(e);return le[t]||(le[t]=t.slice(8,-1).toLowerCase())});var le;const ce=e=>(e=e.toLowerCase(),t=>ue(t)===e),fe=e=>t=>typeof t===e,{isArray:de}=Array,he=fe("undefined");function pe(e){return null!==e&&!he(e)&&null!==e.constructor&&!he(e.constructor)&&ge(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const me=ce("ArrayBuffer"),ve=fe("string"),ge=fe("function"),ye=fe("number"),be=e=>null!==e&&"object"==typeof e,we=e=>{if(!be(e))return!1;const t=re(e);return!(null!==t&&t!==Object.prototype&&null!==re(t)||ae(e,ie)||ae(e,oe))},Pe=ce("Date"),_e=ce("File"),je=ce("Blob"),Ee=ce("FileList"),Se=ce("Set"),xe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Te=void 0!==xe.FormData?xe.FormData:void 0,ke=ce("URLSearchParams"),[Oe,Re,Ue,Ce]=["ReadableStream","Request","Response","Headers"].map(ce);function Ae(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),de(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(pe(e))return;const o=n?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let s;for(r=0;r<i;r++)s=o[r],t.call(null,e[s],s,e)}}function We(e,t){if(pe(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r,o=n.length;for(;o-- >0;)if(r=n[o],t===r.toLowerCase())return r;return null}const Ne="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,Ie=e=>!he(e)&&e!==Ne,Le=(Fe="undefined"!=typeof Uint8Array&&re(Uint8Array),e=>Fe&&e instanceof Fe);var Fe;const ze=ce("HTMLFormElement"),{propertyIsEnumerable:De}=Object.prototype,Me=ce("RegExp"),Be=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Ae(n,(n,o)=>{let i;!1!==(i=t(n,o,e))&&(r[o]=i||n)}),Object.defineProperties(e,r)},qe=ce("AsyncFunction"),Je=(He="function"==typeof setImmediate,Ge=ge(Ne.postMessage),He?setImmediate:Ge?(Ve=`axios@${Math.random()}`,$e=[],Ne.addEventListener("message",({source:e,data:t})=>{e===Ne&&t===Ve&&$e.length&&$e.shift()()},!1),e=>{$e.push(e),Ne.postMessage(Ve,"*")}):e=>setTimeout(e));var He,Ge,Ve,$e;const Ke="undefined"!=typeof queueMicrotask?queueMicrotask.bind(Ne):"undefined"!=typeof process&&process.nextTick||Je,Xe=e=>null!=e&&ge(e[oe]);var Ye={isArray:de,isArrayBuffer:me,isBuffer:pe,isFormData:e=>{if(!e)return!1;if(Te&&e instanceof Te)return!0;const t=re(e);if(!t||t===Object.prototype)return!1;if(!ge(e.append))return!1;const n=ue(e);return"formdata"===n||"object"===n&&ge(e.toString)&&"[object FormData]"===e.toString()},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&me(e.buffer),t},isString:ve,isNumber:ye,isBoolean:e=>!0===e||!1===e,isObject:be,isPlainObject:we,isEmptyObject:e=>{if(!be(e)||pe(e))return!1;try{return 0===Object.keys(e).length&&Object.getPrototypeOf(e)===Object.prototype}catch(e){return!1}},isReadableStream:Oe,isRequest:Re,isResponse:Ue,isHeaders:Ce,isUndefined:he,isDate:Pe,isFile:_e,isReactNativeBlob:e=>!(!e||void 0===e.uri),isReactNative:e=>e&&void 0!==e.getParts,isBlob:je,isRegExp:Me,isFunction:ge,isStream:e=>be(e)&&ge(e.pipe),isURLSearchParams:ke,isTypedArray:Le,isFileList:Ee,forEach:Ae,merge:function e(...t){const{caseless:n,skipUndefined:r}=Ie(this)&&this||{},o={},i=(t,i)=>{if("__proto__"===i||"constructor"===i||"prototype"===i)return;const s=n&&"string"==typeof i&&We(o,i)||i,a=se(o,s)?o[s]:void 0;we(a)&&we(t)?o[s]=e(a,t):we(t)?o[s]=e({},t):de(t)?o[s]=t.slice():r&&he(t)||(o[s]=t)};for(let e=0,n=t.length;e<n;e++){const n=t[e];if(!n||pe(n))continue;if(Ae(n,i),"object"!=typeof n||de(n))continue;const r=Object.getOwnPropertySymbols(n);for(let e=0;e<r.length;e++){const t=r[e];De.call(n,t)&&i(n[t],t)}}return o},extend:(e,t,n,{allOwnKeys:r}={})=>(Ae(t,(t,r)=>{n&&ge(t)?Object.defineProperty(e,r,{__proto__:null,value:te(t,n),writable:!0,enumerable:!0,configurable:!0}):Object.defineProperty(e,r,{__proto__:null,value:t,writable:!0,enumerable:!0,configurable:!0})},{allOwnKeys:r}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),Object.defineProperty(e.prototype,"constructor",{__proto__:null,value:e,writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(e,"super",{__proto__:null,value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,r)=>{let o,i,s;const a={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),i=o.length;i-- >0;)s=o[i],r&&!r(s,e,t)||a[s]||(t[s]=e[s],a[s]=!0);e=!1!==n&&re(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:ue,kindOfTest:ce,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length);const r=e.indexOf(t,n-=t.length);return-1!==r&&r===n},toArray:e=>{if(!e)return null;if(de(e))return e;let t=e.length;if(!ye(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[oe]).call(e);let r;for(;(r=n.next())&&!r.done;){const n=r.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const r=[];for(;null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:ze,hasOwnProperty:se,hasOwnProp:se,hasOwnInPrototypeChain:ae,getSafeProp:(e,t)=>null!=e&&ae(e,t)?e[t]:void 0,reduceDescriptors:Be,freezeMethods:e=>{Be(e,(t,n)=>{if(ge(e)&&["arguments","caller","callee"].includes(n))return!1;ge(e[n])&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))})},toObjectSet:(e,t)=>{const n={},r=e=>{e.forEach(e=>{n[e]=!0})};return de(e)?r(e):r(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(e,t,n){return t.toUpperCase()+n}),noop:()=>{},toFiniteNumber:(e,t)=>null!=e&&Number.isFinite(e=+e)?e:t,findKey:We,global:Ne,isContextDefined:Ie,isSpecCompliantForm:function(e){return!!(e&&ge(e.append)&&"FormData"===e[ie]&&e[oe])},toJSONObject:e=>{const t=new WeakSet,n=e=>{if(be(e)){if(t.has(e))return;if(pe(e))return e;if(!("toJSON"in e)){let r;if(t.add(e),Se(e)){r=[];for(const t of e){const e=n(t);!he(e)&&r.push(e)}}else r=de(e)?[]:{},Ae(e,(e,t)=>{const o=n(e);!he(o)&&(r[t]=o)});return t.delete(e),r}}return e};return n(e)},isAsyncFn:qe,isThenable:e=>e&&(be(e)||ge(e))&&ge(e.then)&&ge(e.catch),setImmediate:Je,asap:Ke,isIterable:Xe,isSafeIterable:e=>null!=e&&ae(e,oe)&&Xe(e)};const Ze=Ye.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Qe=new RegExp("[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+","g"),et=new RegExp("[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+","g");function tt(e,t){return Ye.isArray(e)?e.map(e=>tt(e,t)):function(e){let t=0,n=e.length;for(;t<n;){const n=e.charCodeAt(t);if(9!==n&&32!==n)break;t+=1}for(;n>t;){const t=e.charCodeAt(n-1);if(9!==t&&32!==t)break;n-=1}return 0===t&&n===e.length?e:e.slice(t,n)}(String(e).replace(t,""))}function nt(e){const t=Object.create(null);return Ye.forEach(e.toJSON(),(e,n)=>{t[n]=(e=>tt(e,et))(e)}),t}const rt=Symbol("internals");function ot(e){return e&&String(e).trim().toLowerCase()}function it(e){return!1===e||null==e?e:Ye.isArray(e)?e.map(it):(e=>tt(e,Qe))(String(e))}const st=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function at(e){let t=0,n=e.length;for(;t<n;){const n=e.charCodeAt(t);if(9!==n&&32!==n)break;t+=1}for(;n>t;){const t=e.charCodeAt(n-1);if(9!==t&&32!==t)break;n-=1}return 0===t&&n===e.length?e:e.slice(t,n)}function ut(e,t,n,r,o){return Ye.isFunction(r)?r.call(this,t,n):(o&&(t=n),Ye.isString(t)?Ye.isString(r)?-1!==t.indexOf(r):Ye.isRegExp(r)?r.test(t):void 0:void 0)}class lt{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=ot(t);if(!o)return;const i=Ye.findKey(r,o);(!i||void 0===r[i]||!0===n||void 0===n&&!1!==r[i])&&(r[i||t]=it(e))}const i=(e,t)=>Ye.forEach(e,(e,n)=>o(e,n,t));if(Ye.isPlainObject(e)||e instanceof this.constructor)i(e,t);else if(Ye.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim()))i((e=>{const t={};let n,r,o;return e&&e.split("\n").forEach(function(e){o=e.indexOf(":"),n=e.substring(0,o).trim().toLowerCase(),r=e.substring(o+1).trim();const i=Ye.hasOwnProp(t,n);!n||i&&Ye.hasOwnProp(Ze,n)||("set-cookie"===n?i?t[n].push(r):t[n]=[r]:t[n]=i?t[n]+", "+r:r)}),t})(e),t);else if(Ye.isObject(e)&&Ye.isSafeIterable(e)){let n,r,o=Object.create(null);for(const t of e){if(!Ye.isArray(t))throw new TypeError("Object iterator must return a key-value pair");r=t[0],Ye.hasOwnProp(o,r)?(n=o[r],o[r]=Ye.isArray(n)?[...n,t[1]]:[n,t[1]]):o[r]=t[1]}i(o,t)}else null!=e&&o(t,e,n);return this}get(e,t){if(e=ot(e)){const n=Ye.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}(e);if(Ye.isFunction(t))return t.call(this,e,n);if(Ye.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=ot(e)){const n=Ye.findKey(this,e);return!(!n||void 0===this[n]||t&&!ut(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=ot(e)){const o=Ye.findKey(n,e);!o||t&&!ut(0,n[o],o,t)||(delete n[o],r=!0)}}return Ye.isArray(e)?e.forEach(o):o(e),r}clear(e){const t=Object.keys(this);let n=t.length,r=!1;for(;n--;){const o=t[n];e&&!ut(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}normalize(e){const t=this,n={};return Ye.forEach(this,(r,o)=>{const i=Ye.findKey(n,o);if(i)return t[i]=it(r),void delete t[o];const s=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,t,n)=>t.toUpperCase()+n)}(o):String(o).trim();s!==o&&delete t[o],t[s]=it(r),n[s]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return Ye.forEach(this,(n,r)=>{null!=n&&!1!==n&&(t[r]=e&&Ye.isArray(n)?n.join(", "):n)}),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,t])=>e+": "+t).join("\n")}getSetCookie(){const e=this.get("set-cookie");return Ye.isArray(e)?e:null==e||!1===e?[]:[e]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static parseParameters(e){return function(e){const t=Object.create(null),n=String(e);let r=0,o=!1,i=!1;function s(e){const o=at(n.slice(r,e)),i=o.indexOf("=");if(i<1)return;const s=at(o.slice(0,i));if(!st.test(s))return;const a=s.toLowerCase();if("__proto__"===a||"constructor"===a||"prototype"===a)return;const u=at(o.slice(i+1));t[a]=function(e){const t=e.length-1;if(t<1||34!==e.charCodeAt(0)||34!==e.charCodeAt(t))return e;let n="";for(let r=1;r<t;r++){const o=e.charCodeAt(r);if(34===o)return e;if(92===o&&(r+=1,r>=t))return e;n+=e[r]}return n}(u)}for(let e=0;e<n.length;e++){const t=n.charCodeAt(e);o?i?i=!1:92===t?i=!0:34===t&&(o=!1):34===t?o=!0:44!==t&&59!==t||(s(e),r=e+1)}return s(n.length),t}(e)}static concat(e,...t){const n=new this(e);return t.forEach(e=>n.set(e)),n}static accessor(e){const t=(this[rt]=this[rt]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=ot(e);t[r]||(function(e,t){const n=Ye.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{__proto__:null,value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})})}(n,e),t[r]=!0)}return Ye.isArray(e)?e.forEach(r):r(e),this}}lt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),Ye.reduceDescriptors(lt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[n]=e}}}),Ye.freezeMethods(lt);var ct=lt;const ft="[REDACTED ****]";class dt extends Error{static from(e,t,n,r,o,i){let s=e.message;!s&&Ye.isArray(e.errors)&&e.errors.length&&(s=function(e){return e.errors.map(e=>{try{return function(e){try{return String(e)}catch(e){return""}}(e&&e.message?e.message:e)}catch(e){return""}}).filter(Boolean).join("; ")||e.name||"AggregateError"}(e));const a=new dt(s,t||e.code,n,r,o);return Object.defineProperty(a,"cause",{__proto__:null,value:e,writable:!0,enumerable:!1,configurable:!0}),a.name=e.name,null!=e.status&&null==a.status&&(a.status=e.status),i&&Object.assign(a,i),a}constructor(e,t,n,r,o){super(e),Object.defineProperty(this,"message",{__proto__:null,value:e,enumerable:!0,writable:!0,configurable:!0}),this.name="AxiosError",this.isAxiosError=!0,t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status)}toJSON(){const e=this.config,t=e&&Ye.hasOwnProp(e,"redact")?e.redact:void 0,n=Ye.isArray(t)&&t.length>0?function(e,t){const n=new Set(t.map(e=>String(e).toLowerCase())),r=[],o=e=>{if(null===e||"object"!=typeof e)return e;if(Ye.isBuffer(e))return e;if(-1!==r.indexOf(e))return;let t;if(e instanceof ct&&(e=e.toJSON()),r.push(e),Ye.isArray(e))t=[],e.forEach((e,n)=>{const r=o(e);Ye.isUndefined(r)||(t[n]=r)});else{if(!Ye.isPlainObject(e)&&function(e){if(Ye.hasOwnProp(e,"toJSON"))return!0;let t=Object.getPrototypeOf(e);for(;t&&t!==Object.prototype;){if(Ye.hasOwnProp(t,"toJSON"))return!0;t=Object.getPrototypeOf(t)}return!1}(e))return r.pop(),e;t=Object.create(null);for(const[r,i]of Object.entries(e)){const e=n.has(r.toLowerCase())?ft:o(i);Ye.isUndefined(e)||(t[r]=e)}}return r.pop(),t};return o(e)}(e,t):Ye.toJSONObject(e);return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:n,code:this.code,status:this.status}}}dt.ERR_BAD_OPTION_VALUE="ERR_BAD_OPTION_VALUE",dt.ERR_BAD_OPTION="ERR_BAD_OPTION",dt.ECONNABORTED="ECONNABORTED",dt.ETIMEDOUT="ETIMEDOUT",dt.ECONNREFUSED="ECONNREFUSED",dt.ERR_NETWORK="ERR_NETWORK",dt.ERR_FR_TOO_MANY_REDIRECTS="ERR_FR_TOO_MANY_REDIRECTS",dt.ERR_DEPRECATED="ERR_DEPRECATED",dt.ERR_BAD_RESPONSE="ERR_BAD_RESPONSE",dt.ERR_BAD_REQUEST="ERR_BAD_REQUEST",dt.ERR_CANCELED="ERR_CANCELED",dt.ERR_NOT_SUPPORT="ERR_NOT_SUPPORT",dt.ERR_INVALID_URL="ERR_INVALID_URL",dt.ERR_FORM_DATA_DEPTH_EXCEEDED="ERR_FORM_DATA_DEPTH_EXCEEDED";var ht=dt;const pt=100;function mt(e){return Ye.isPlainObject(e)||Ye.isArray(e)}function vt(e){return Ye.endsWith(e,"[]")?e.slice(0,-2):e}function gt(e,t,n){return e?e.concat(t).map(function(e,t){return e=vt(e),!n&&t?"["+e+"]":e}).join(n?".":""):t}const yt=Ye.toFlatObject(Ye,{},null,function(e){return/^is[A-Z]/.test(e)});function bt(e,t,n){if(!Ye.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const r=(n=Ye.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(e,t){return!Ye.isUndefined(t[e])})).metaTokens,o=n.visitor||h,i=n.dots,s=n.indexes,a=n.Blob||"undefined"!=typeof Blob&&Blob,u=void 0===n.maxDepth?pt:n.maxDepth,l=a&&Ye.isSpecCompliantForm(t),c=[];if(!Ye.isFunction(o))throw new TypeError("visitor must be a function");function f(e){if(null===e)return"";if(Ye.isDate(e))return e.toISOString();if(Ye.isBoolean(e))return e.toString();if(!l&&Ye.isBlob(e))throw new ht("Blob is not supported. Use a Buffer instead.");if(Ye.isArrayBuffer(e)||Ye.isTypedArray(e)){if(l&&"function"==typeof a)return new a([e]);throw new ht("Blob is not supported. Use a Buffer instead.",ht.ERR_NOT_SUPPORT)}return e}function d(e){if(e>u)throw new ht("Object is too deeply nested ("+e+" levels). Max depth: "+u,ht.ERR_FORM_DATA_DEPTH_EXCEEDED)}function h(e,n,o){let a=e;if(Ye.isReactNative(t)&&Ye.isReactNativeBlob(e))return t.append(gt(o,n,i),f(e)),!1;if(e&&!o&&"object"==typeof e)if(Ye.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=function(e,t){if(Infinity===u)return JSON.stringify(e);const n=[];return JSON.stringify(e,function(e,t){if(!Ye.isObject(t))return t;for(;n.length&&n[n.length-1]!==this;)n.pop();return n.push(t),d(1+n.length-1),t})}(e);else if(Ye.isArray(e)&&function(e){return Ye.isArray(e)&&!e.some(mt)}(e)||(Ye.isFileList(e)||Ye.endsWith(n,"[]"))&&(a=Ye.toArray(e)))return n=vt(n),a.forEach(function(e,r){!Ye.isUndefined(e)&&null!==e&&t.append(!0===s?gt([n],r,i):null===s?n:n+"[]",f(e))}),!1;return!!mt(e)||(t.append(gt(o,n,i),f(e)),!1)}const p=Object.assign(yt,{defaultVisitor:h,convertValue:f,isVisitable:mt});if(!Ye.isObject(e))throw new TypeError("data must be an object");return function e(n,r,i=0){if(!Ye.isUndefined(n)){if(d(i),-1!==c.indexOf(n))throw new Error("Circular reference detected in "+r.join("."));c.push(n),Ye.forEach(n,function(n,s){!0===(!(Ye.isUndefined(n)||null===n)&&o.call(t,n,Ye.isString(s)?s.trim():s,r,p))&&e(n,r?r.concat(s):[s],i+1)}),c.pop()}}(e),t}function wt(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"};return encodeURIComponent(e).replace(/[!'()~]|%20/g,function(e){return t[e]})}function Pt(e,t){this._pairs=[],e&&bt(e,this,t)}const _t=Pt.prototype;function jt(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Et(e,t,n){if(!t)return e;e=e||"";const r=Ye.isFunction(n)?{serialize:n}:n,o=Ye.getSafeProp(r,"encode")||jt,i=Ye.getSafeProp(r,"serialize");let s;if(s=i?i(t,r):Ye.isURLSearchParams(t)?t.toString():new Pt(t,r).toString(o),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}_t.append=function(e,t){this._pairs.push([e,t])},_t.toString=function(e){const t=e?t=>e.call(this,t,wt):wt;return this._pairs.map(function(e){return t(e[0])+"="+t(e[1])},"").join("&")};var St=class{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){Ye.forEach(this.handlers,function(t){null!==t&&e(t)})}},xt={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1,legacyInterceptorReqResOrdering:!0,advertiseZstdAcceptEncoding:!1,validateStatusUndefinedResolves:!0},Tt={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:Pt,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const kt="undefined"!=typeof window&&"undefined"!=typeof document,Ot="object"==typeof navigator&&navigator||void 0,Rt=kt&&(!Ot||["ReactNative","NativeScript","NS"].indexOf(Ot.product)<0);var Ut={__proto__:null,hasBrowserEnv:kt,hasStandardBrowserWebWorkerEnv:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,hasStandardBrowserEnv:Rt,navigator:Ot,origin:kt&&window.location.href||"http://localhost",...Tt};const Ct=pt;function At(e){if(e>Ct)throw new ht("FormData field is too deeply nested ("+e+" levels). Max depth: "+Ct,ht.ERR_FORM_DATA_DEPTH_EXCEEDED)}function Wt(e){function t(e,n,r,o){At(o);let i=e[o++];if("__proto__"===i)return!0;const s=Number.isFinite(+i),a=o>=e.length;return i=!i&&Ye.isArray(r)?r.length:i,a?(r[i]=Ye.hasOwnProp(r,i)?Ye.isArray(r[i])?r[i].concat(n):[r[i],n]:n,!s):(Ye.hasOwnProp(r,i)&&Ye.isObject(r[i])||(r[i]=[]),t(e,n,r[i],o)&&Ye.isArray(r[i])&&(r[i]=function(e){const t={},n=Object.keys(e);let r;const o=n.length;let i;for(r=0;r<o;r++)i=n[r],t[i]=e[i];return t}(r[i])),!s)}if(Ye.isFormData(e)&&Ye.isFunction(e.entries)){const n={};return Ye.forEachEntry(e,(e,r)=>{t(function(e){const t=[],n=/[^.[\]]+|\[([^.[\]]*)]/g;let r;for(;null!==(r=n.exec(e));)At(t.length),t.push("[]"===r[0]?"":r[1]||r[0]);return t}(e),r,n,0)}),n}return null}const Nt=(e,t)=>null!=e&&Ye.hasOwnProp(e,t)?e[t]:void 0,It={transitional:xt,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=Ye.isObject(e);if(o&&Ye.isHTMLForm(e)&&(e=new FormData(e)),Ye.isFormData(e))return r?JSON.stringify(Wt(e)):e;if(Ye.isArrayBuffer(e)||Ye.isBuffer(e)||Ye.isStream(e)||Ye.isFile(e)||Ye.isBlob(e)||Ye.isReadableStream(e))return e;if(Ye.isArrayBufferView(e))return e.buffer;if(Ye.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let i;if(o){const t=Nt(this,"formSerializer");if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return bt(e,new Ut.classes.URLSearchParams,{visitor:function(e,t,n,r){return Ut.isNode&&Ye.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)},...t})}(e,t).toString();if((i=Ye.isFileList(e))||n.indexOf("multipart/form-data")>-1){const n=Nt(this,"env"),r=n&&n.FormData;return bt(i?{"files[]":e}:e,r&&new r,t)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(Ye.isString(e))try{return(0,JSON.parse)(e),Ye.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(0,JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=Nt(this,"transitional")||It.transitional,n=t&&t.forcedJSONParsing,r=Nt(this,"responseType"),o="json"===r;if(Ye.isResponse(e)||Ye.isReadableStream(e))return e;if(e&&Ye.isString(e)&&(n&&!r||o)){const n=!(t&&t.silentJSONParsing)&&o;try{return JSON.parse(e,Nt(this,"parseReviver"))}catch(e){if(n){if("SyntaxError"===e.name)throw ht.from(e,ht.ERR_BAD_RESPONSE,this,null,Nt(this,"response"));throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Ut.classes.FormData,Blob:Ut.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};Ye.forEach(["delete","get","head","post","put","patch","query"],e=>{It.headers[e]={}});var Lt=It;function Ft(e,t){const n=this||Lt,r=t||n,o=ct.from(r.headers);let i=r.data;return Ye.forEach(e,function(e){i=e.call(n,i,o.normalize(),t?t.status:void 0)}),o.normalize(),i}function zt(e){return!(!e||!e.__CANCEL__)}var Dt=class extends ht{constructor(e,t,n){super(null==e?"canceled":e,ht.ERR_CANCELED,t,n),this.name="CanceledError",this.__CANCEL__=!0}};function Mt(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new ht("Request failed with status code "+n.status,n.status>=400&&n.status<500?ht.ERR_BAD_REQUEST:ht.ERR_BAD_RESPONSE,n.config,n.request,n)):e(n)}const Bt=(e,t,n=3)=>{let r=0;const o=function(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o,i=0,s=0;return t=void 0!==t?t:1e3,function(a){const u=Date.now(),l=r[s];o||(o=u),n[i]=a,r[i]=u;let c=s,f=0;for(;c!==i;)f+=n[c++],c%=e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),u-o<t)return;const d=l&&u-l;return d?Math.round(1e3*f/d):void 0}}(50,250);return function(n,i){let s,a,u=0,l=1e3/i;const c=(n,i=Date.now())=>{u=i,s=null,a&&(clearTimeout(a),a=null),(n=>{if(!n||"number"!=typeof n.loaded)return;const i=n.loaded,s=n.lengthComputable?n.total:void 0,a=Math.max(0,null!=s?Math.min(i,s):i),u=Math.max(0,a-r),l=o(u);r=Math.max(r,a),e({loaded:a,total:s,progress:s?a/s:void 0,bytes:u,rate:l||void 0,estimated:l&&s?(s-a)/l:void 0,event:n,lengthComputable:null!=s,[t?"download":"upload"]:!0})})(...n)};return[(...e)=>{const t=Date.now(),n=t-u;n>=l?c(e,t):(s=e,a||(a=setTimeout(()=>{a=null,c(s)},l-n)))},()=>s&&c(s)]}(0,n)},qt=(e,t)=>{const n=null!=e;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Jt=(e,t=Ye.asap)=>(...n)=>t(()=>e(...n));var Ht,Gt,Vt=Ut.hasStandardBrowserEnv?(Ht=new URL(Ut.origin),Gt=Ut.navigator&&/(msie|trident)/i.test(Ut.navigator.userAgent),e=>(e=new URL(e,Ut.origin),Ht.protocol===e.protocol&&Ht.host===e.host&&(Gt||Ht.port===e.port))):()=>!0,$t=Ut.hasStandardBrowserEnv?{write(e,t,n,r,o,i,s){if("undefined"==typeof document)return;const a=[`${e}=${encodeURIComponent(t)}`];Ye.isNumber(n)&&a.push(`expires=${new Date(n).toUTCString()}`),Ye.isString(r)&&a.push(`path=${r}`),Ye.isString(o)&&a.push(`domain=${o}`),!0===i&&a.push("secure"),Ye.isString(s)&&a.push(`SameSite=${s}`),document.cookie=a.join("; ")},read(e){if("undefined"==typeof document)return null;const t=document.cookie.split(";");for(let n=0;n<t.length;n++){const r=t[n].replace(/^\s+/,""),o=r.indexOf("=");if(-1!==o&&r.slice(0,o)===e)try{return decodeURIComponent(r.slice(o+1))}catch(e){return r.slice(o+1)}}return null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read:()=>null,remove(){}};const Kt=/^https?:(?!\/\/)/i,Xt=/[\t\n\r]/g;function Yt(e,t){if("string"==typeof e){const n=function(e){return function(e){let t=0;for(;t<e.length&&e.charCodeAt(t)<=32;)t++;return e.slice(t)}(e).replace(Xt,"")}(e);if(Kt.test(n))throw new ht(`Invalid URL ${JSON.stringify(function(e){const t=e.replace(/^(https?:\/{0,2})[^/?#]*@/i,`$1${ft}@`),n=t.indexOf("#"),r=(-1===n?t:t.slice(0,n)).replace(/([?&][^=&#]*=)[^&#]*/g,`$1${ft}`);return-1===n?r:`${r}#${o=t.slice(n+1),o?o.replace(/(^|&)([^=&]*=)?[^&]+/g,(e,t,n="")=>`${t}${n}${ft}`):o}`;var o}(n))}: missing "//" after protocol`,ht.ERR_INVALID_URL,t)}}function Zt(e,t,n,r){Yt(t,r);let o=!("string"==typeof(i=t)&&/^([a-z][a-z\d+\-.]*:)?\/\//i.test(i));var i;return e&&(o||!1===n)?(Yt(e,r),function(e,t){if(!t)return e;let n=e.length;for(;n>0&&47===e.charCodeAt(n-1);)n--;return e.slice(0,n)+"/"+t.replace(/^\/+/,"")}(e,t)):t}const Qt=e=>e instanceof ct?{...e}:e,en=e=>Object.getOwnPropertySymbols&&Object.getOwnPropertyDescriptor?Object.keys(e).concat(Object.getOwnPropertySymbols(e).filter(t=>Object.getOwnPropertyDescriptor(e,t).enumerable)):Object.keys(e);function tn(e,t){e=e||{},t=t||{};const n=Object.create(null);function r(e,t,n,r){return Ye.isPlainObject(e)&&Ye.isPlainObject(t)?Ye.merge.call({caseless:r},e,t):Ye.isPlainObject(t)?Ye.merge({},t):Ye.isArray(t)?t.slice():t}function o(e,t,n,o){return Ye.isUndefined(t)?Ye.isUndefined(e)?void 0:r(void 0,e,0,o):r(e,t,0,o)}function i(e,t){if(!Ye.isUndefined(t))return r(void 0,t)}function s(e,t){return Ye.isUndefined(t)?Ye.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,i){return Ye.hasOwnProp(t,i)?r(n,o):Ye.hasOwnProp(e,i)?r(void 0,n):void 0}Object.defineProperty(n,"hasOwnProperty",{__proto__:null,value:Object.prototype.hasOwnProperty,enumerable:!1,writable:!0,configurable:!0});const u={url:i,method:i,data:i,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,withXSRFToken:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,allowedSocketPaths:s,responseEncoding:s,validateStatus:a,headers:(e,t,n)=>o(Qt(e),Qt(t),0,!0)};return Ye.forEach(en({...e,...t}),function(r){if("__proto__"===r||"constructor"===r||"prototype"===r)return;const i=Ye.hasOwnProp(u,r)?u[r]:o,s=i(Ye.hasOwnProp(e,r)?e[r]:void 0,Ye.hasOwnProp(t,r)?t[r]:void 0,r);Ye.isUndefined(s)&&i!==a||(n[r]=s)}),Ye.hasOwnProp(t,"validateStatus")&&Ye.isUndefined(t.validateStatus)&&!1===function(n){const r=Ye.hasOwnProp(t,"transitional")?t.transitional:void 0;if(!Ye.isUndefined(r)){if(!Ye.isPlainObject(r))return;if(Ye.hasOwnProp(r,n))return r[n]}const o=Ye.hasOwnProp(e,"transitional")?e.transitional:void 0;if(Ye.isPlainObject(o)&&Ye.hasOwnProp(o,n))return o[n]}("validateStatusUndefinedResolves")&&(Ye.hasOwnProp(e,"validateStatus")?n.validateStatus=r(void 0,e.validateStatus):delete n.validateStatus),n}const nn=["content-type","content-length"];function rn(e){const t=tn({},e),n=e=>Ye.hasOwnProp(t,e)?t[e]:void 0,r=n("data");let o=n("withXSRFToken");const i=n("xsrfHeaderName"),s=n("xsrfCookieName");let a=n("headers");const u=n("auth"),l=n("baseURL"),c=n("allowAbsoluteUrls"),f=n("url");if(t.headers=a=ct.from(a),t.url=Et(Zt(l,f,c,t),n("params"),n("paramsSerializer")),u){const t=Ye.getSafeProp(u,"username")||"",n=Ye.getSafeProp(u,"password")||"";try{a.set("Authorization","Basic "+btoa(t+":"+(n?encodeURIComponent(n).replace(/%([0-9A-F]{2})/gi,(e,t)=>String.fromCharCode(parseInt(t,16))):"")))}catch(t){throw ht.from(t,ht.ERR_BAD_OPTION_VALUE,e)}}if(Ye.isFormData(r)&&(Ut.hasStandardBrowserEnv||Ut.hasStandardBrowserWebWorkerEnv||Ye.isReactNative(r)?a.setContentType(void 0):Ye.isFunction(r.getHeaders)&&function(e,t,n){"content-only"===n?Object.entries(t||{}).forEach(([t,n])=>{nn.includes(t.toLowerCase())&&e.set(t,n)}):e.set(t)}(a,r.getHeaders(),n("formDataHeaderPolicy"))),Ut.hasStandardBrowserEnv&&(Ye.isFunction(o)&&(o=o(t)),!0===o||null==o&&Vt(t.url))){const e=i&&s&&$t.read(s);e&&a.set(i,e)}return t}var on="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise(function(t,n){const r=rn(e);let o=r.data;const i=ct.from(r.headers).normalize();let s,a,u,l,c,{responseType:f,onUploadProgress:d,onDownloadProgress:h}=r;function p(){l&&l(),c&&c(),r.cancelToken&&r.cancelToken.unsubscribe(s),r.signal&&r.signal.removeEventListener("abort",s)}let m=new XMLHttpRequest;function v(){if(!m)return;const r=ct.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders());Mt(function(e){t(e),p()},function(e){n(e),p()},{data:f&&"text"!==f&&"json"!==f?m.response:m.responseText,status:m.status,statusText:m.statusText,headers:r,config:e,request:m}),m=null}m.open(r.method.toUpperCase(),r.url,!0),m.timeout=r.timeout,"onloadend"in m?m.onloadend=v:m.onreadystatechange=function(){m&&4===m.readyState&&(0!==m.status||m.responseURL&&m.responseURL.startsWith("file:"))&&setTimeout(v)},m.onabort=function(){m&&(n(new ht("Request aborted",ht.ECONNABORTED,e,m)),p(),m=null)},m.onerror=function(t){const r=new ht(t&&t.message?t.message:"Network Error",ht.ERR_NETWORK,e,m);r.event=t||null,n(r),p(),m=null},m.ontimeout=function(){let t=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";r.timeoutErrorMessage&&(t=r.timeoutErrorMessage),n(new ht(t,(r.transitional||xt).clarifyTimeoutError?ht.ETIMEDOUT:ht.ECONNABORTED,e,m)),p(),m=null},void 0===o&&i.setContentType(null),"setRequestHeader"in m&&Ye.forEach(nt(i),function(e,t){m.setRequestHeader(t,e)}),Ye.isUndefined(r.withCredentials)||(m.withCredentials=!!r.withCredentials),f&&"json"!==f&&(m.responseType=r.responseType),h&&([u,c]=Bt(h,!0),m.addEventListener("progress",u)),d&&m.upload&&([a,l]=Bt(d),m.upload.addEventListener("progress",a),m.upload.addEventListener("loadend",l)),(r.cancelToken||r.signal)&&(s=t=>{m&&(n(!t||t.type?new Dt(null,e,m):t),m.abort(),p(),m=null)},r.cancelToken&&r.cancelToken.subscribe(s),r.signal&&(r.signal.aborted?s():r.signal.addEventListener("abort",s)));const g=function(e){const t=/^([-+\w]{1,25}):(?:\/\/)?/.exec(e);return t&&t[1]||""}(r.url);if(g&&!Ut.protocols.includes(g))return n(new ht("Unsupported protocol "+g+":",ht.ERR_BAD_REQUEST,e)),void p();m.send(o||null)})},sn=(e,t)=>{if(e=e?e.filter(Boolean):[],!t&&!e.length)return;const n=new AbortController;let r=!1;const o=function(e){if(!r){r=!0,s();const t=e instanceof Error?e:this.reason;n.abort(t instanceof ht?t:new Dt(t instanceof Error?t.message:t))}};let i=t&&setTimeout(()=>{i=null,o(new ht(`timeout of ${t}ms exceeded`,ht.ETIMEDOUT))},t);const s=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(e=>{e.unsubscribe?e.unsubscribe(o):e.removeEventListener("abort",o)}),e=null)};e.forEach(e=>{r||(e.aborted?o.call(e):e.addEventListener("abort",o,{once:!0}))});const{signal:a}=n;return a.unsubscribe=()=>Ye.asap(s),a};const an=function*(e,t){let n=e.byteLength;if(!t||n<t)return void(yield e);let r,o=0;for(;o<n;)r=o+t,yield e.slice(o,r),o=r},un=(e,t,n,r)=>{const o=async function*(e,t){for await(const n of async function*(e){if(e[Symbol.asyncIterator])return void(yield*e);const t=e.getReader();try{for(;;){const{done:e,value:n}=await t.read();if(e)break;yield n}}finally{await t.cancel()}}(e))yield*an(n,t)}(e,t);let i,s=0,a=e=>{i||(i=!0,r&&r(e))};return new ReadableStream({async pull(e){try{const{done:t,value:r}=await o.next();if(t)return a(),void e.close();if(n){let e=s+=r.byteLength;n(e)}e.enqueue(new Uint8Array(r))}catch(e){throw a(e),e}},cancel:e=>(a(e),o.return())},{highWaterMark:2})},ln=e=>e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102,cn=(e,t,n)=>t+2<n&&ln(e.charCodeAt(t+1))&&ln(e.charCodeAt(t+2)),fn=e=>e<=57?e-48:(223&e)-55,dn=e=>e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||43===e||47===e||45===e||95===e,hn=e=>{const t=e.length;let n=0,r=0,o=!1;for(let s=0;s<t;s++){let a=e.charCodeAt(s);37===a&&cn(e,s,t)&&(a=16*fn(e.charCodeAt(s+1))+fn(e.charCodeAt(s+2)),s+=2),9!==(i=a)&&10!==i&&12!==i&&13!==i&&32!==i&&(61!==a?!dn(a)||r>0?o=!0:n++:r++)}var i;return o||r>2||r>0&&(n+r)%4!=0||n%4==1?(e=>{const t=e.length;let n=0;return t>0&&61===e.charCodeAt(t-1)&&(n++,t>1&&61===e.charCodeAt(t-2)&&n++),Math.floor(3*(t-n)/4)})(e):(e=>{const t=e%4;return 3*Math.floor(e/4)+(2===t?1:3===t?2:0)})(n)},pn="1.19.0",{isFunction:mn}=Ye,vn=e=>{if(!Ye.isString(e))return e;try{return decodeURIComponent(e)}catch(t){return e}},gn=(e,...t)=>{try{return!!e(...t)}catch(e){return!1}},yn=e=>{const t=null!=Ye.global?Ye.global:globalThis,{ReadableStream:n,TextEncoder:r}=t;e=Ye.merge.call({skipUndefined:!0},{Request:t.Request,Response:t.Response},e);const{fetch:o,Request:i,Response:s}=e,a=o?mn(o):"function"==typeof fetch,u=mn(i),l=mn(s);if(!a)return!1;const c=a&&mn(n),f=a&&("function"==typeof r?(d=new r,e=>d.encode(e)):async e=>new Uint8Array(await new i(e).arrayBuffer()));var d;const h=u&&c&&gn(()=>{let e=!1;const t=new i(Ut.origin,{body:new n,method:"POST",get duplex(){return e=!0,"half"}}),r=t.headers.has("Content-Type");return null!=t.body&&t.body.cancel(),e&&!r}),p=l&&c&&gn(()=>Ye.isReadableStream(new s("").body)),m={stream:p&&(e=>e.body)};a&&["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!m[e]&&(m[e]=(t,n)=>{let r=t&&t[e];if(r)return r.call(t);throw new ht(`Response type '${e}' is not supported`,ht.ERR_NOT_SUPPORT,n)})});const v=async e=>{if(null==e)return 0;if(Ye.isBlob(e))return e.size;if(Ye.isSpecCompliantForm(e)){const t=new i(Ut.origin,{method:"POST",body:e});return(await t.arrayBuffer()).byteLength}return Ye.isArrayBufferView(e)||Ye.isArrayBuffer(e)?e.byteLength:(Ye.isURLSearchParams(e)&&(e+=""),Ye.isString(e)?(await f(e)).byteLength:void 0)};return async e=>{let{url:t,method:n,data:a,signal:l,cancelToken:f,timeout:d,onDownloadProgress:g,onUploadProgress:y,responseType:b,headers:w,withCredentials:P="same-origin",fetchOptions:_,maxContentLength:j,maxBodyLength:E}=rn(e);const S=Ye.isNumber(j)&&j>-1,x=Ye.isNumber(E)&&E>-1;let T=o||fetch;b=b?(b+"").toLowerCase():"text";let k=sn([l,f&&f.toAbortSignal()],d),O=null;const R=k&&k.unsubscribe&&(()=>{k.unsubscribe()});let U,C=null;const A=()=>new ht("Request body larger than maxBodyLength limit",ht.ERR_BAD_REQUEST,e,O);try{let o;const l=Ye.hasOwnProp(e,"auth")?e.auth:void 0;if(l&&(o={username:Ye.getSafeProp(l,"username")||"",password:Ye.getSafeProp(l,"password")||""}),(e=>{const t=e.indexOf("://");let n=e;return-1!==t&&(n=n.slice(t+3)),n.includes("@")||n.includes(":")})(t)){const e=new URL(t,Ut.origin);o||!e.username&&!e.password||(o={username:vn(e.username),password:vn(e.password)}),(e.username||e.password)&&(e.username="",e.password="",t=e.href)}if(o&&(w.delete("authorization"),w.set("Authorization","Basic "+btoa(encodeURIComponent((o.username||"")+":"+(o.password||"")).replace(/%([0-9A-F]{2})/gi,(e,t)=>String.fromCharCode(parseInt(t,16)))))),S&&"string"==typeof t&&t.startsWith("data:")&&function(e){const t="string"==typeof e?e.indexOf("#"):-1;return((e,t)=>{if(!e||"string"!=typeof e)return 0;if(!e.startsWith("data:"))return 0;const n=e.indexOf(",");if(n<0)return 0;const r=e.slice(5,n),o=e.slice(n+1);if(/;base64/i.test(r))return t(o);let i=0;for(let e=0,t=o.length;e<t;e++){const n=o.charCodeAt(e);if(37===n&&cn(o,e,t))i+=1,e+=2;else if(n<128)i+=1;else if(n<2048)i+=2;else if(n>=55296&&n<=56319&&e+1<t){const t=o.charCodeAt(e+1);t>=56320&&t<=57343?(i+=4,e++):i+=3}else i+=3}return i})(-1===t?e:e.slice(0,t),hn)}(t)>j)throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O);if(x&&"get"!==n&&"head"!==n){const e=await v(a);if("number"==typeof e&&isFinite(e)&&(U=e,e>E))throw A()}const f=x&&(Ye.isReadableStream(a)||Ye.isStream(a)),d=(e,t,n)=>un(e,65536,e=>{if(x&&e>E)throw C=A();t&&t(e)},n);if(h&&"get"!==n&&"head"!==n&&(y||f)){if(U=null==U?await(async(e,t)=>{const n=Ye.toFiniteNumber(e.getContentLength());return null==n?v(t):n})(w,a):U,0!==U||f){let e,n=new i(t,{method:"POST",body:a,duplex:"half"});if(Ye.isFormData(a)&&(e=n.headers.get("content-type"))&&w.setContentType(e),n.body){const[e,t]=y&&qt(U,Bt(Jt(y)))||[];a=d(n.body,e,t)}}}else if(f&&!u&&c&&"get"!==n&&"head"!==n)a=d(a);else if(f&&u&&!h&&"get"!==n&&"head"!==n)throw new ht("Stream request bodies are not supported by the current fetch implementation",ht.ERR_NOT_SUPPORT,e,O);Ye.isString(P)||(P=P?"include":"omit");const W=u&&"credentials"in i.prototype;if(Ye.isFormData(a)){const e=w.getContentType();e&&/^multipart\/form-data/i.test(e)&&!/boundary=/i.test(e)&&w.delete("content-type")}w.set("User-Agent","axios/"+pn,!1);const N={..._,signal:k,method:n.toUpperCase(),headers:nt(w.normalize()),body:a,duplex:"half",credentials:W?P:void 0};O=u&&new i(t,N);let I=await(u?T(O,_):T(t,N));const L=ct.from(I.headers);if(S){const t=Ye.toFiniteNumber(L.getContentLength());if(null!=t&&t>j)throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O)}const F=p&&("stream"===b||"response"===b);if(p&&I.body&&(g||S||F&&R)){const t={};["status","statusText","headers"].forEach(e=>{t[e]=I[e]});const n=Ye.toFiniteNumber(L.getContentLength()),[r,o]=g&&qt(n,Bt(Jt(g),!0))||[];let i=0;I=new s(un(I.body,65536,t=>{if(S&&(i=t,i>j))throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O);r&&r(t)},()=>{o&&o(),R&&R()}),t)}b=b||"text";let z=await m[Ye.findKey(m,b)||"text"](I,e);if(S&&!p&&!F){let t;if(null!=z&&("number"==typeof z.byteLength?t=z.byteLength:"number"==typeof z.size?t=z.size:"string"==typeof z&&(t="function"==typeof r?(new r).encode(z).byteLength:z.length)),"number"==typeof t&&t>j)throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O)}return!F&&R&&R(),await new Promise((t,n)=>{Mt(t,n,{data:z,headers:ct.from(I.headers),status:I.status,statusText:I.statusText,config:e,request:O})})}catch(t){if(R&&R(),k&&k.aborted&&k.reason instanceof ht){const n=k.reason;throw n.config=e,O&&(n.request=O),t!==n&&Object.defineProperty(n,"cause",{__proto__:null,value:t,writable:!0,enumerable:!1,configurable:!0}),n}if(C)throw O&&!C.request&&(C.request=O),C;if(t instanceof ht)throw O&&!t.request&&(t.request=O),t;if(t&&"TypeError"===t.name&&/Load failed|fetch/i.test(t.message)){const n=new ht("Network Error",ht.ERR_NETWORK,e,O,t&&t.response);throw Object.defineProperty(n,"cause",{__proto__:null,value:t.cause||t,writable:!0,enumerable:!1,configurable:!0}),n}throw ht.from(t,t&&t.code,e,O,t&&t.response)}}},bn=new Map,wn=e=>{let t=e&&e.env||{};const{fetch:n,Request:r,Response:o}=t,i=[r,o,n];let s,a,u=i.length,l=bn;for(;u--;)s=i[u],a=l.get(s),void 0===a&&l.set(s,a=u?new Map:yn(t)),l=a;return a};wn();const Pn={http:null,xhr:on,fetch:{get:wn}};Ye.forEach(Pn,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{__proto__:null,value:t})}catch(e){}Object.defineProperty(e,"adapterName",{__proto__:null,value:t})}});const _n=e=>`- ${e}`,jn=e=>Ye.isFunction(e)||null===e||!1===e;var En=function(e,t){e=Ye.isArray(e)?e:[e];const{length:n}=e;let r,o;const i={};for(let s=0;s<n;s++){let n;if(r=e[s],o=r,!jn(r)&&(o=Pn[(n=String(r)).toLowerCase()],void 0===o))throw new ht(`Unknown adapter '${n}'`);if(o&&(Ye.isFunction(o)||(o=o.get(t))))break;i[n||"#"+s]=o}if(!o){const e=Object.entries(i).map(([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build"));let t=n?e.length>1?"since :\n"+e.map(_n).join("\n"):" "+_n(e[0]):"as no adapter specified";throw new ht("There is no suitable adapter to dispatch the request "+t,ht.ERR_NOT_SUPPORT)}return o};function Sn(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Dt(null,e)}function xn(e){return Sn(e),e.headers=ct.from(e.headers),e.data=Ft.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1),En(e.adapter||Lt.adapter,e)(e).then(function(t){Sn(e),e.response=t;try{t.data=Ft.call(e,e.transformResponse,t)}finally{delete e.response}return t.headers=ct.from(t.headers),t},function(t){if(!zt(t)&&(Sn(e),t&&t.response)){e.response=t.response;try{t.response.data=Ft.call(e,e.transformResponse,t.response)}finally{delete e.response}t.response.headers=ct.from(t.response.headers)}return Promise.reject(t)})}const Tn={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Tn[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});const kn={};Tn.transitional=function(e,t,n){function r(e,t){return"[Axios v"+pn+"] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,i)=>{if(!1===e)throw new ht(r(o," has been removed"+(t?" in "+t:"")),ht.ERR_DEPRECATED);return t&&!kn[o]&&(kn[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,i)}},Tn.spelling=function(e){return(t,n)=>(console.warn(`${n} is likely a misspelling of ${e}`),!0)};var On={assertOptions:function(e,t,n){if("object"!=typeof e||null===e)throw new ht("options must be an object",ht.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const i=r[o],s=Object.prototype.hasOwnProperty.call(t,i)?t[i]:void 0;if(s){const t=e[i],n=void 0===t||s(t,i,e);if(!0!==n)throw new ht("option "+i+" must be "+n,ht.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new ht("Unknown option "+i,ht.ERR_BAD_OPTION)}},validators:Tn};const Rn=On.validators;class Un{constructor(e){this.defaults=e||{},this.interceptors={request:new St,response:new St}}async request(e,t){try{return await this._request(e,t)}catch(e){if(e instanceof Error){let t={};Error.captureStackTrace?Error.captureStackTrace(t):t=new Error;const n=(()=>{if(!t.stack)return"";const e=t.stack.indexOf("\n");return-1===e?"":t.stack.slice(e+1)})();try{if(e.stack){if(n){const t=n.indexOf("\n"),r=-1===t?-1:n.indexOf("\n",t+1),o=-1===r?"":n.slice(r+1);String(e.stack).endsWith(o)||(e.stack+="\n"+n)}}else e.stack=n}catch(e){}}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=tn(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;void 0!==n&&On.assertOptions(n,{silentJSONParsing:Rn.transitional(Rn.boolean),forcedJSONParsing:Rn.transitional(Rn.boolean),clarifyTimeoutError:Rn.transitional(Rn.boolean),legacyInterceptorReqResOrdering:Rn.transitional(Rn.boolean),advertiseZstdAcceptEncoding:Rn.transitional(Rn.boolean),validateStatusUndefinedResolves:Rn.transitional(Rn.boolean)},!1),null!=r&&(Ye.isFunction(r)?t.paramsSerializer={serialize:r}:On.assertOptions(r,{encode:Rn.function,serialize:Rn.function},!0)),void 0!==t.allowAbsoluteUrls||(t.allowAbsoluteUrls=void 0===this.defaults.allowAbsoluteUrls||this.defaults.allowAbsoluteUrls),On.assertOptions(t,{baseUrl:Rn.spelling("baseURL"),withXsrfToken:Rn.spelling("withXSRFToken")},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase();let i=o&&Ye.merge(o.common,o[t.method]);o&&Ye.forEach(["delete","get","head","post","put","patch","query","common"],e=>{delete o[e]}),t.headers=ct.concat(i,o);const s=[];let a=!0;this.interceptors.request.forEach(function(e){if("function"==typeof e.runWhen&&!1===e.runWhen(t))return;a=a&&e.synchronous;const n=t.transitional||xt;n&&n.legacyInterceptorReqResOrdering?s.unshift(e.fulfilled,e.rejected):s.push(e.fulfilled,e.rejected)});const u=[];let l;this.interceptors.response.forEach(function(e){u.push(e.fulfilled,e.rejected)});let c,f=0;if(!a){const e=[xn.bind(this),void 0];for(e.unshift(...s),e.push(...u),c=e.length,l=Promise.resolve(t);f<c;)l=l.then(e[f++],e[f++]);return l}c=s.length;let d=t;for(;f<c;){const e=s[f++],t=s[f++];try{d=e?e(d):d}catch(e){if(!t){l=Promise.reject(e);break}try{const n=t.call(this,e);Ye.isThenable(n)&&(l=Promise.resolve(n).then(()=>xn.call(this,d)))}catch(e){l=Promise.reject(e)}break}}if(!l)try{l=xn.call(this,d)}catch(e){l=Promise.reject(e)}for(f=0,c=u.length;f<c;)l=l.then(u[f++],u[f++]);return l}getUri(e){return Et(Zt((e=tn(this.defaults,e)).baseURL,e.url,e.allowAbsoluteUrls,e),e.params,e.paramsSerializer)}}Ye.forEach(["delete","get","head","options"],function(e){Un.prototype[e]=function(t,n){return this.request(tn(n||{},{method:e,url:t,data:n&&Ye.hasOwnProp(n,"data")?n.data:void 0}))}}),Ye.forEach(["post","put","patch","query"],function(e){function t(t){return function(n,r,o){return this.request(tn(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}Un.prototype[e]=t(),"query"!==e&&(Un.prototype[e+"Form"]=t(!0))});var Cn=Un;class An{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise(function(e){t=e});const n=this;this.promise.then(e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null}),this.promise.then=e=>{let t;const r=new Promise(e=>{n.subscribe(e),t=e}).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e(function(e,r,o){n.reason||(n.reason=new Dt(e,r,o),t(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}toAbortSignal(){const e=new AbortController,t=t=>{e.abort(t)};return this.subscribe(t),e.signal.unsubscribe=()=>this.unsubscribe(t),e.signal}static source(){let e;return{token:new An(function(t){e=t}),cancel:e}}}var Wn=An;const Nn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerReturnsAnUnknownError:520,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Nn).forEach(([e,t])=>{Nn[t]=e});var In=Nn;const Ln=function e(t){const n=new Cn(t),r=te(Cn.prototype.request,n);return Ye.extend(r,Cn.prototype,n,{allOwnKeys:!0}),Ye.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(tn(t,n))},r}(Lt);Ln.Axios=Cn,Ln.CanceledError=Dt,Ln.CancelToken=Wn,Ln.isCancel=zt,Ln.VERSION=pn,Ln.toFormData=bt,Ln.AxiosError=ht,Ln.Cancel=Ln.CanceledError,Ln.all=function(e){return Promise.all(e)},Ln.spread=function(e){return function(t){return e.apply(null,t)}},Ln.isAxiosError=function(e){return Ye.isObject(e)&&!0===e.isAxiosError},Ln.mergeConfig=tn,Ln.AxiosHeaders=ct,Ln.formToJSON=e=>Wt(Ye.isHTMLForm(e)?new FormData(e):e),Ln.getAdapter=En,Ln.HttpStatusCode=In,Ln.default=Ln;var Fn=Ln;const{CanceledError:zn}=Fn;var Dn=/screenshot(\-\d+?)?\.needle\.(webp|png|jpg|jpeg)/,Mn=function(e,t){try{var n=t.baseUrl+Y.jobs.post_update,r=F({},Z(t),{job_id:e.identifier,status:e.status});return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:r,body:JSON.stringify({status_message:e.status_message,error:e.error,progress:e.progress})})).catch(function(e){return console.error(e),null})).then(function(e){return!!e&&e.ok})}catch(e){return Promise.reject(e)}};function Bn(e,t,n){if(!e.s){if(n instanceof qn){if(!n.s)return void(n.o=Bn.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Bn.bind(null,e,t),Bn.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var qn=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Bn(r,1,i(this.v))}catch(e){Bn(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Bn(r,1,t?t(o):o):n?Bn(r,1,n(o)):Bn(r,2,o)}catch(e){Bn(r,2,e)}},r},e}();function Jn(e){return e instanceof qn&&1&e.s}var Hn=function(e,t){void 0===t&&(t={});try{var n,r,o=function(e){return n?e:{ok:!1,error:r,attempts:j,reason:"attempts-exhausted"}},i=t.maxAttempts,s=void 0===i?Gn:i,a=t.budgetMs,u=void 0===a?Kn:a,l=t.baseMs,c=void 0===l?Vn:l,f=t.maxMs,d=void 0===f?$n:f,h=t.isRetryable,p=void 0===h?Zn:h,m=t.sleep,v=void 0===m?Qn:m,g=t.now,y=void 0===g?Date.now:g,b=t.random,w=void 0===b?Math.random:b,P=t.onRetry,_=y(),j=0,E=function(e,t,n){for(var r;;){var o=e();if(Jn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Jn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Jn(s)){r=2;break}}}var a=new qn,u=Bn.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!Jn(s))return void s.then(f).then(void 0,u);if(!(o=e())||Jn(o)&&!o.v)return void Bn(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Jn(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):Bn(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Bn(a,1,i)}}(function(){return!n&&j<s},void 0,function(){return j++,function(t,r){try{var o=Promise.resolve(e(j)).then(function(e){return n=1,{ok:!0,value:e,attempts:j}})}catch(e){return r(e)}return o&&o.then?o.then(void 0,r):o}(0,function(e){if(r=e,!p(e))return n=1,{ok:!1,error:e,attempts:j,reason:"permanent"};if(j>=s)return n=1,{ok:!1,error:e,attempts:j,reason:"attempts-exhausted"};var t=function(e,t){void 0===t&&(t={});var n=t.baseMs,r=void 0===n?Vn:n,o=t.maxMs,i=void 0===o?$n:o,s=t.random,a=void 0===s?Math.random:s,u=Math.max(1,Math.floor(e)),l=Math.min(i,r*Math.pow(2,u-1))/2;return Math.max(1,Math.round(l+a()*l))}(j,{baseMs:c,maxMs:d,random:w});return y()-_+t>=u?(n=1,{ok:!1,error:e,attempts:j,reason:"budget-exhausted"}):(null==P||P({attempt:j,waitMs:t,error:e}),Promise.resolve(v(t)).then(function(){}))})});return Promise.resolve(E&&E.then?E.then(o):o(E))}catch(e){return Promise.reject(e)}},Gn=6,Vn=1e3,$n=15e3,Kn=9e4,Xn=new Set(["CERT_HAS_EXPIRED","UNABLE_TO_VERIFY_LEAF_SIGNATURE","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","ERR_TLS_CERT_ALTNAME_INVALID"]),Yn=new Set([408,429]);function Zn(e){var t;if(function(e){var t=null==e?void 0:e.name,n=null==e?void 0:e.code;return"CanceledError"===t||"AbortError"===t||"ERR_CANCELED"===n||"ABORT_ERR"===n}(e))return!1;var n=null==e||null==(t=e.response)?void 0:t.status;if("number"==typeof n&&n>0)return!!Yn.has(n)||!(n>=400&&n<500);var r=function(e){var t,n,r=null!=(t=null==e?void 0:e.code)?t:null==e||null==(n=e.cause)?void 0:n.code;return"string"==typeof r&&r.length?r:null}(e);return!r||!Xn.has(r)}function Qn(e){return new Promise(function(t){return setTimeout(t,e)})}function er(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function tr(e,t,n){if(!e.s){if(n instanceof nr){if(!n.s)return void(n.o=tr.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(tr.bind(null,e,t),tr.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var nr=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{tr(r,1,i(this.v))}catch(e){tr(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?tr(r,1,t?t(o):o):n?tr(r,1,n(o)):tr(r,2,o)}catch(e){tr(r,2,e)}},r},e}();function rr(e){return e instanceof nr&&1&e.s}var or,ir,sr=16777216,ar=67108864,ur=(or=function(e,t){e.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function n(e,t){var n=e[0],r=e[1],o=e[2],i=e[3];r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[0]-680876936|0)<<7|n>>>25)+r|0)&r|~n&o)+t[1]-389564586|0)<<12|i>>>20)+n|0)&n|~i&r)+t[2]+606105819|0)<<17|o>>>15)+i|0)&i|~o&n)+t[3]-1044525330|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[4]-176418897|0)<<7|n>>>25)+r|0)&r|~n&o)+t[5]+1200080426|0)<<12|i>>>20)+n|0)&n|~i&r)+t[6]-1473231341|0)<<17|o>>>15)+i|0)&i|~o&n)+t[7]-45705983|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[8]+1770035416|0)<<7|n>>>25)+r|0)&r|~n&o)+t[9]-1958414417|0)<<12|i>>>20)+n|0)&n|~i&r)+t[10]-42063|0)<<17|o>>>15)+i|0)&i|~o&n)+t[11]-1990404162|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[12]+1804603682|0)<<7|n>>>25)+r|0)&r|~n&o)+t[13]-40341101|0)<<12|i>>>20)+n|0)&n|~i&r)+t[14]-1502002290|0)<<17|o>>>15)+i|0)&i|~o&n)+t[15]+1236535329|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[1]-165796510|0)<<5|n>>>27)+r|0)&o|r&~o)+t[6]-1069501632|0)<<9|i>>>23)+n|0)&r|n&~r)+t[11]+643717713|0)<<14|o>>>18)+i|0)&n|i&~n)+t[0]-373897302|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[5]-701558691|0)<<5|n>>>27)+r|0)&o|r&~o)+t[10]+38016083|0)<<9|i>>>23)+n|0)&r|n&~r)+t[15]-660478335|0)<<14|o>>>18)+i|0)&n|i&~n)+t[4]-405537848|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[9]+568446438|0)<<5|n>>>27)+r|0)&o|r&~o)+t[14]-1019803690|0)<<9|i>>>23)+n|0)&r|n&~r)+t[3]-187363961|0)<<14|o>>>18)+i|0)&n|i&~n)+t[8]+1163531501|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[13]-1444681467|0)<<5|n>>>27)+r|0)&o|r&~o)+t[2]-51403784|0)<<9|i>>>23)+n|0)&r|n&~r)+t[7]+1735328473|0)<<14|o>>>18)+i|0)&n|i&~n)+t[12]-1926607734|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[5]-378558|0)<<4|n>>>28)+r|0)^r^o)+t[8]-2022574463|0)<<11|i>>>21)+n|0)^n^r)+t[11]+1839030562|0)<<16|o>>>16)+i|0)^i^n)+t[14]-35309556|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[1]-1530992060|0)<<4|n>>>28)+r|0)^r^o)+t[4]+1272893353|0)<<11|i>>>21)+n|0)^n^r)+t[7]-155497632|0)<<16|o>>>16)+i|0)^i^n)+t[10]-1094730640|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[13]+681279174|0)<<4|n>>>28)+r|0)^r^o)+t[0]-358537222|0)<<11|i>>>21)+n|0)^n^r)+t[3]-722521979|0)<<16|o>>>16)+i|0)^i^n)+t[6]+76029189|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[9]-640364487|0)<<4|n>>>28)+r|0)^r^o)+t[12]-421815835|0)<<11|i>>>21)+n|0)^n^r)+t[15]+530742520|0)<<16|o>>>16)+i|0)^i^n)+t[2]-995338651|0)<<23|r>>>9)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[0]-198630844|0)<<6|n>>>26)+r|0)|~o))+t[7]+1126891415|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[14]-1416354905|0)<<15|o>>>17)+i|0)|~n))+t[5]-57434055|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[12]+1700485571|0)<<6|n>>>26)+r|0)|~o))+t[3]-1894986606|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[10]-1051523|0)<<15|o>>>17)+i|0)|~n))+t[1]-2054922799|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[8]+1873313359|0)<<6|n>>>26)+r|0)|~o))+t[15]-30611744|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[6]-1560198380|0)<<15|o>>>17)+i|0)|~n))+t[13]+1309151649|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[4]-145523070|0)<<6|n>>>26)+r|0)|~o))+t[11]-1120210379|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[2]+718787259|0)<<15|o>>>17)+i|0)|~n))+t[9]-343485551|0)<<21|r>>>11)+o|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=o+e[2]|0,e[3]=i+e[3]|0}function r(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}function o(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n}function i(e){var t,o,i,s,a,u,l=e.length,c=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=l;t+=64)n(c,r(e.substring(t-64,t)));for(o=(e=e.substring(t-64)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<o;t+=1)i[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55)for(n(c,i),t=0;t<16;t+=1)i[t]=0;return s=(s=8*l).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),u=parseInt(s[1],16)||0,i[14]=a,i[15]=u,n(c,i),c}function s(e){var n,r="";for(n=0;n<4;n+=1)r+=t[e>>8*n+4&15]+t[e>>8*n&15];return r}function a(e){var t;for(t=0;t<e.length;t+=1)e[t]=s(e[t]);return e.join("")}function u(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function l(e){var t,n=[],r=e.length;for(t=0;t<r-1;t+=2)n.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,n)}function c(){this.reset()}return a(i("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function e(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(t,n){var r,o,i,s,a=this.byteLength,u=e(t,a),l=a;return void 0!==n&&(l=e(n,a)),u>l?new ArrayBuffer(0):(r=l-u,o=new ArrayBuffer(r),i=new Uint8Array(o),s=new Uint8Array(this,u,r),i.set(s),o)}}(),c.prototype.append=function(e){return this.appendBinary(u(e)),this},c.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,o=this._buff.length;for(t=64;t<=o;t+=64)n(this._hash,r(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},c.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=a(this._hash),e&&(n=l(n)),this.reset(),n},c.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},c.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},c.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},c.prototype._finish=function(e,t){var r,o,i,s=t;if(e[s>>2]|=128<<(s%4<<3),s>55)for(n(this._hash,e),s=0;s<16;s+=1)e[s]=0;r=(r=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(r[2],16),i=parseInt(r[1],16)||0,e[14]=o,e[15]=i,n(this._hash,e)},c.hash=function(e,t){return c.hashBinary(u(e),t)},c.hashBinary=function(e,t){var n=a(i(e));return t?l(n):n},(c.ArrayBuffer=function(){this.reset()}).prototype.append=function(e){var t,r,i,s,a=(r=this._buff.buffer,i=e,(s=new Uint8Array(r.byteLength+i.byteLength)).set(new Uint8Array(r)),s.set(new Uint8Array(i),r.byteLength),s),u=a.length;for(this._length+=e.byteLength,t=64;t<=u;t+=64)n(this._hash,o(a.subarray(t-64,t)));return this._buff=t-64<u?new Uint8Array(a.buffer.slice(t-64)):new Uint8Array(0),this},c.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=a(this._hash),e&&(n=l(n)),this.reset(),n},c.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.ArrayBuffer.prototype.getState=function(){var e=c.prototype.getState.call(this);return e.buff=String.fromCharCode.apply(null,new Uint8Array(e.buff)),e},c.ArrayBuffer.prototype.setState=function(e){return e.buff=function(e,t){var n,r=e.length,o=new ArrayBuffer(r),i=new Uint8Array(o);for(n=0;n<r;n+=1)i[n]=e.charCodeAt(n);return i}(e.buff),c.prototype.setState.call(this,e)},c.ArrayBuffer.prototype.destroy=c.prototype.destroy,c.ArrayBuffer.prototype._finish=c.prototype._finish,c.ArrayBuffer.hash=function(e,t){var r=a(function(e){var t,r,i,s,a,u,l=e.length,c=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=l;t+=64)n(c,o(e.subarray(t-64,t)));for(r=(e=t-64<l?e.subarray(t-64):new Uint8Array(0)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<r;t+=1)i[t>>2]|=e[t]<<(t%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55)for(n(c,i),t=0;t<16;t+=1)i[t]=0;return s=(s=8*l).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),u=parseInt(s[1],16)||0,i[14]=a,i[15]=u,n(c,i),c}(new Uint8Array(e)));return t?l(r):r},c}()},or(ir={exports:{}}),ir.exports);function lr(e,t=0){return hr(e,t,2).getUint16(0,!0)}function cr(e,t=0){return hr(e,t,4).getUint32(0,!0)}function fr(e,t=0,n=e.byteLength){const r=e.slice(t,t+n);return pr.decode(new Uint8Array(r))}function dr(e,t,n=0){if(e.length<t.length+n)return!1;for(const[r,o]of t.entries())if(null!==o&&o!==e[r+n])return!1;return!0}function hr(e,t,n){const r=e.slice(t,t+n);return new DataView(new Uint8Array(r).buffer)}const pr=new TextDecoder("utf8"),mr=[["db","application/vnd.sqlite3",[83,81,76,105,116,101,32,102,111,114,109,97,116,32,51,0]],["woff","font/woff",[119,79,70,70]],["woff2","font/woff2",[119,79,70,50]],["bmp","image/bmp",[66,77]],["gif","image/gif",[71,73,70,56,55,97]],["gif","image/gif",[71,73,70,56,57,97]],["heic","image/heic",[102,116,121,112,104,101,105],{offset:4}],["heic","image/heic",[102,116,121,112,109],{offset:4}],["ico","image/x-icon",[0,0,1,0]],["jpg","image/jpeg",[255,216,255]],["pdf","application/pdf",[37,80,68,70,45]],["png","image/png",[137,80,78,71,13,10,26,10]],["7z","application/x-7z-compressed",[55,122,188,175,39,28]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,0]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,1,0]],["rtf","application/rtf",[123,92,114,116,102,49]],["bz2","application/x-bzip2",[66,90,104]],["gz","application/gzip",[31,139]],["tar","application/x-tar",[117,115,116,97,114,0,48,48],{offset:257}],["tar","application/x-tar",[117,115,116,97,114,32,32,0],{offset:257}],["tif","image/tiff",[73,73,42,0]],["tiff","image/tiff",[77,77,0,42]],["zip","application/zip",[80,75,3,4],{exact:!1}],["zip","application/zip",[80,75,5,6]],["mp3","audio/mp3",[255,251]],["mp3","audio/mp3",[255,243]],["mp3","audio/mp3",[255,242]],["mp3","audio/mp3",[73,68,51]],["mp4","video/mp4",[102,116,121,112,105,115,111,109],{offset:4}],["avi","video/x-msvideo",[82,73,70,70,null,null,null,null,65,86,73,32]],["wav","audio/wav",[82,73,70,70,null,null,null,null,87,65,86,69]],["ogx","application/ogg",[79,103,103,83],{exact:!1},[["oga","audio/ogg",[127,70,76,65,67],{offset:28}],["ogg","audio/ogg",[1,118,111,114,98,105,115],{offset:28}],["ogm","video/ogg",[1,118,105,100,101,111,0],{offset:28}],["ogv","video/ogg",[128,116,104,101,111,114,97],{offset:28}]]],["webp","image/webp",[82,73,70,70,null,null,null,null,87,69,66,80]],["psd","image/vnd.adobe.photoshop",[56,66,80,83]],["flac","audio/x-flac",[102,76,97,67]],["wasm","application/wasm",[0,97,115,109]],["deb","application/x-deb",[33,60,97,114,99,104,62,10]],["exe","application/x-msdownload",[77,90]],["exe","application/x-msdownload",[90,77]],["class","application/java-vm",[202,254,186,190]]];function vr(e){return e.flatMap(([e,t,n,r={},o=[]])=>[[e,t,n,r],...o])}function gr(e,t){const n=lr(e,26),r=fr(e,30,n),[o]=r.split("/"),i=r.endsWith(".xml");return"META-INF"===o?{ext:"jar",mime:"application/java-archive"}:"ppt"===o&&i?{ext:"pptx",mime:"application/vnd.openxmlformats-officedocument.presentationml.presentation"}:"word"===o&&i?{ext:"docx",mime:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"}:"xl"===o&&i?{ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}:"mimetype"===o?function(e,t){const n=cr(e,18),r=cr(e,22),o=lr(e,28);if(n===r){const r=fr(e,30+t+o,n);if("application/vnd.oasis.opendocument.presentation"===r)return{ext:"odp",mime:r};if("application/vnd.oasis.opendocument.spreadsheet"===r)return{ext:"ods",mime:r};if("application/vnd.oasis.opendocument.text"===r)return{ext:"odt",mime:r};if("application/epub+zip"===r)return{ext:"epub",mime:r}}}(e,n)??t:t}const yr=function(e){return vr(e).map(([e,t,n,{offset:r=0}={}])=>n.length+r).reduce((e,t)=>t>e?t:e,0)}(mr);function br(e,t){for(const[n,r,o,{exact:i=!0,offset:s=0}={},a=[]]of t)if(dr(e,o,s)){if("zip"===n&&!i)return gr(e.buffer,{ext:n,mime:r});if(!i&&a.length)for(const[t,n,r,{offset:o=0}={}]of a)if(dr(e,r,o))return{ext:t,mime:n};return{ext:n,mime:r}}}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var wr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Pr(e){return function(e){for(var t="",n=0;n<e.length;n+=3){var r=e.charCodeAt(n),o=n+1<e.length?e.charCodeAt(n+1):0,i=n+2<e.length?e.charCodeAt(n+2):0;t+=wr[r>>2]+wr[(3&r)<<4|o>>4]+(n+1<e.length?wr[(15&o)<<2|i>>6]:"=")+(n+2<e.length?wr[63&i]:"=")}return t}(ur.ArrayBuffer.hash(e,!0))}function _r(e,t){void 0===t&&(t=void 0);var n=function(e,{extra:t=!1,hint:n}={}){const r=new Uint8Array(e.slice(0,yr));if(n){const e=function(e,{ext:t,mime:n}){return t||n?vr(e).filter(e=>e[0]===t||e[1]===n):[]}(mr,n);if(e.length>0){const t=br(r,e);if(void 0!==t)return t}}return br(r,mr)||(t?function(e){return function(e){try{const t=fr(e);if(!function(e){for(let t=0;t<e.length;t++)try{const n=e.charCodeAt(t);if(65533===n||n<=8)return!1}catch{return!1}return!0}(t))return;try{return JSON.parse(t),{ext:"json",mime:"application/json"}}catch{return{ext:"txt",mime:"text/plain"}}}catch{return}}(e)}(e):void 0)}(e);if(n)return n.mime;for(var r=new Uint8Array(e).subarray(0,4),o="",i=0;i<r.length;i++)o+=r[i].toString(16);var s="unknown";switch(o){case"676c5446":s="model/gltf-binary";break;case"89504e47":s="image/png";break;case"ffd8ffe0":case"ffd8ffe1":case"ffd8ffe2":case"ffd8ffe3":case"ffd8ffe8":s="image/jpeg";break;default:s="unknown"}return"unknown"===s&&"string"==typeof t&&(s=jr(t)),s}function jr(e){var t=e.toLowerCase(),n="";return t.endsWith(".html")||t.endsWith(".html.gz")||t.endsWith(".html.br")?n="text/html":t.endsWith(".js")||t.endsWith(".js.gz")||t.endsWith(".js.br")||t.endsWith(".mjs")||t.endsWith(".mjs.gz")||t.endsWith(".mjs.br")||t.endsWith(".cjs")||t.endsWith(".cjs.gz")||t.endsWith(".cjs.br")?n="application/javascript":t.endsWith(".wasm")?n="application/wasm":t.endsWith(".css")||t.endsWith(".css.gz")||t.endsWith(".css.br")?n="text/css":t.endsWith(".json")?n="application/json":t.endsWith(".txt")?n="text/plain":t.endsWith(".md")?n="text/markdown":t.endsWith(".yaml")||t.endsWith(".yml")?n="application/yaml":t.endsWith(".bin")?n="application/octet-stream":t.endsWith(".png")?n="image/png":t.endsWith(".jpg")||t.endsWith(".jpeg")?n="image/jpeg":t.endsWith(".gif")?n="image/gif":t.endsWith(".webp")?n="image/webp":t.endsWith(".avif")?n="image/avif":t.endsWith(".bmp")?n="image/bmp":t.endsWith(".tiff")||t.endsWith(".tif")?n="image/tiff":t.endsWith(".ico")?n="image/x-icon":t.endsWith(".svg")?n="image/svg+xml":t.endsWith(".xml")?n="application/xml":t.endsWith(".hdr")?n="image/vnd.radiance":t.endsWith(".exr")?n="image/x-exr":t.endsWith(".ktx2")?n="image/ktx2":t.endsWith(".ktx")?n="image/ktx":t.endsWith(".dds")?n="image/vnd-ms.dds":t.endsWith(".ogg")?n="audio/ogg":t.endsWith(".mp3")?n="audio/mpeg":t.endsWith(".wav")?n="audio/wave":t.endsWith(".flac")?n="audio/flac":t.endsWith(".m4a")?n="audio/mp4":t.endsWith(".aac")?n="audio/aac":t.endsWith(".mp4")?n="video/mp4":t.endsWith(".webm")?n="video/webm":t.endsWith(".mov")?n="video/quicktime":t.endsWith(".woff2")?n="font/woff2":t.endsWith(".woff")?n="font/woff":t.endsWith(".ttf")?n="font/ttf":t.endsWith(".otf")?n="font/otf":t.endsWith(".zip")?n="application/zip":t.endsWith(".glb")?n="model/gltf-binary":t.endsWith(".gltf")?n="model/gltf+json":t.endsWith(".vrm")?n="model/gltf-binary":t.endsWith(".usdz")?n="model/vnd.usdz+zip":t.endsWith(".usda")?n="model/vnd.usd-usda":t.endsWith(".usdc")?n="model/vnd.usd-usdc":t.endsWith(".usd")?n="model/vnd.usd-usd":t.endsWith(".mtl")?n="model/mtl":t.endsWith(".obj")?n="model/obj":t.endsWith(".fbx")?n="model/vnd.autodesk.fbx":t.endsWith(".stl")?n="model/stl":t.endsWith(".mtlx")?n="application/materialx+xml":t.endsWith(".ply")?n="model/ply":t.endsWith(".dae")?n="model/vnd.collada+xml":t.endsWith(".3mf")?n="model/3mf":(t.endsWith(".splat")||t.endsWith(".spz")||t.endsWith(".ksplat")||t.endsWith(".sog")||t.endsWith(".sogs"))&&(n="application/octet-stream"),n}function Er(e){return"string"==typeof e&&0!==e.length&&e.toLowerCase().endsWith(".exr")}function Sr(e){if("string"!=typeof e||0===e.length)return!1;var t=e.toLowerCase();return t.endsWith(".hdr")||t.endsWith(".hdri")}function xr(e){return"string"==typeof e&&0!==e.length&&/\.pmrem(\d+x\d+)?\.ktx2$/i.test(e)}function Tr(e,t,n){void 0===t&&(t=void 0),void 0===n&&(n=!0);var r=Math.abs(e);if(r>=1099511627776){var o=n?" TB":"";return(e/1099511627776).toFixed(void 0===t?2:t)+o}if(r>=1073741824){var i=n?" GB":"";return(e/1073741824).toFixed(void 0===t?2:t)+i}if(r>=1048576){var s=n?" MB":"";return(e/1048576).toFixed(void 0===t?1:t)+s}if(r>=1024){var a=n?" KB":"";return(e/1024).toFixed(void 0===t?0:t)+a}var u=n?" B":"";return e.toFixed(0)+u}function kr(e,t){for(var n=t;n<e.length&&0!==e[n];)n++;return n>=e.length?null:new TextDecoder("latin1").decode(e.subarray(t,n))}function Or(e){return"object"!=typeof e||null===e||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e))}function Rr(e){return Array.isArray(e)?e:[]}function Ur(e){return"number"==typeof e&&Number.isSafeInteger(e)&&e>=0?e:null}function Cr(e){return Array.isArray(e)&&3===e.length&&e.every(function(e){return"number"==typeof e&&Number.isFinite(e)})?[e[0],e[1],e[2]]:null}function Ar(e){return Rr(e).filter(function(e){return"string"==typeof e})}function Wr(e,t){e.meshes+=t.meshes,e.primitives+=t.primitives,e.vertices=null===e.vertices||null===t.vertices?null:e.vertices+t.vertices,e.triangles=null===e.triangles||null===t.triangles?null:e.triangles+t.triangles}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var Nr=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Ir(e){var t,n=new Set([].concat(Rr(e.buffers),Rr(e.images)).map(function(e){return Or(e).uri}).filter(function(e){return"string"==typeof e&&!e.startsWith("data:")})),r=new Set,o=1;function i(e){for(var t,o=1,i=L(e);!(t=i()).done;){var s=Rr(Or(Or(Or(t.value).extensions).NEEDLE_progressive).lods).map(function(e){return Or(e).path}).filter(function(e){return"string"==typeof e});if(s.length){r.add("NEEDLE_progressive"),o=Math.max(o,s.length+1);for(var a,u=L(s);!(a=u()).done;)n.add(a.value)}}return o}o=i(Rr(e.meshes)),t=i(Rr(e.textures));for(var s,a=L(Rr(e.nodes));!(s=a()).done;){var u=Rr(Or(Or(Or(s.value).extensions).MSFT_lod).ids);u.length&&(r.add("MSFT_lod"),o=Math.max(o,u.length+1))}return{progressive:r.size>0,mechanisms:[].concat(r),meshLodLevels:o,textureLodLevels:t,dependencies:[].concat(n).sort()}}function Lr(e){var t=new Set,n=new Set,r=!1;function o(e){var n=Ur(e);null===n?r=!0:t.add(n)}for(var i,s=L(Rr(e.meshes));!(i=s()).done;)for(var a,u=L(Rr(Or(i.value).primitives));!(a=u()).done;){for(var l=Or(a.value),c=0,f=Object.values(Or(l.attributes));c<f.length;c++)o(f[c]);void 0!==l.indices&&o(l.indices);for(var d,h=L(Rr(l.targets));!(d=h()).done;)for(var p=0,m=Object.values(Or(d.value));p<m.length;p++)o(m[p]);"KHR_draco_mesh_compression"in Or(l.extensions)&&n.add("KHR_draco_mesh_compression")}for(var v,g=L(Rr(e.bufferViews));!(v=g()).done;)"EXT_meshopt_compression"in Or(Or(v.value).extensions)&&n.add("EXT_meshopt_compression");for(var y,b=Rr(e.accessors),w={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},P={SCALAR:[1,1],VEC2:[1,2],VEC3:[1,3],VEC4:[1,4],MAT2:[2,2],MAT3:[3,3],MAT4:[4,4]},_=0,j=L(t);!(y=j()).done;){var E=Or(b[y.value]),S=Ur(E.count),x=w[String(E.componentType)],T=P[String(E.type)];if(x&&T&&null!==S){var k=T[0],O=T[1]*x;_+=S*k*(k>1?4*Math.ceil(O/4):O)}else r=!0}return{nodeCount:Rr(e.nodes).length,meshCompression:[].concat(n).sort(),geometryBytesEstimate:r||!Number.isSafeInteger(_)?null:_,geometryAssumption:"Unique dense mesh accessors, no renderer overhead"}}var Fr=function(e){try{return Promise.resolve(new Promise(function(t){return setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},zr=/*#__PURE__*/$(/^image_(\d+)_|^mesh_lod_(\d+)_/,{image_lod:1,mesh_lod:2});function Dr(e,t,n){if(!e.s){if(n instanceof Mr){if(!n.s)return void(n.o=Dr.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Dr.bind(null,e,t),Dr.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var Mr=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Dr(r,1,i(this.v))}catch(e){Dr(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Dr(r,1,t?t(o):o):n?Dr(r,1,n(o)):Dr(r,2,o)}catch(e){Dr(r,2,e)}},r},e}();function Br(e){return e instanceof Mr&&1&e.s}function qr(e){return e.includes("\\u")?JSON.parse('"'+e+'"'):decodeURIComponent(e)}function Jr(e){for(var t,n=Infinity,r=[],o=L(e);!(t=o()).done;){var i=t.value,s=i.path.split("/").length;s<n?(n=s,r=[i]):s===n&&r.push(i)}return r}var Hr,Gr=/*#__PURE__*/function(){function e(e,t){this.totalFiles=e,this.estimatedTotalSize=t,this.uploadedSize=0,this.startTime=Date.now(),this.lastUpdateTime=this.startTime,this.lastUploadedSize=0,this.speedEMA=null,this.emaFactor=.1,this.smoothedRemainingTime=null,this.recentSpeeds=new Array,this.maxRecentSpeeds=20,this.initialEstimateThreshold=.05}var t=e.prototype;return t.updateProgress=function(e){var t=Date.now(),n=(t-this.lastUpdateTime)/1e3,r=e-this.lastUploadedSize;if(this.uploadedSize=e,n>0&&r>0){this.recentSpeeds.push(r/n),this.recentSpeeds.length>this.maxRecentSpeeds&&this.recentSpeeds.shift();var o=this.recentSpeeds.reduce(function(e,t){return e+t},0)/this.recentSpeeds.length;this.speedEMA=null===this.speedEMA?o:this.emaFactor*o+(1-this.emaFactor)*this.speedEMA}this.lastUpdateTime=t,this.lastUploadedSize=e;var i,s=this.uploadedSize/this.estimatedTotalSize,a=(t-this.startTime)/1e3,u=this.speedEMA&&this.speedEMA>0?this.speedEMA:this.uploadedSize/a;return i=u>0?(this.estimatedTotalSize-this.uploadedSize)/u:Infinity,this.smoothedRemainingTime=s>=this.initialEstimateThreshold?null===this.smoothedRemainingTime?i:.9*this.smoothedRemainingTime+.1*i:a/s-a,this.smoothedRemainingTime=Math.max(this.smoothedRemainingTime,(this.estimatedTotalSize-this.uploadedSize)/u),{progress:100*s,estimatedTimeRemaining:Math.round(this.smoothedRemainingTime),estimatedTimeRemainingString:this.smoothedRemainingTime>3?this.__formatTime(this.smoothedRemainingTime):"few seconds"}},t.__formatTime=function(e){if(!isFinite(e))return"Calculating...";if(e<60)return Math.round(e)+"sec";var t=Math.floor(e/60);if(t<60)return t+"min";var n=Math.floor(t/60);if(n<24)return n+"h "+t%60+"min";var r=Math.floor(n/24);return r<=10?r+"d":"Calculating..."},e}(),Vr=function(e){void 0===e&&(e={});try{var t;return(null!=(t=e.isNode)?t:"undefined"!=typeof process&&null!=(n=process.versions)&&n.node)?Hr?Promise.resolve(Hr):Promise.resolve(Promise.all([import("node:http"),import("node:https")])).then(function(e){for(var t=e[1].default,n=new e[0].default.Agent({keepAlive:!0}),r=new t.Agent({keepAlive:!0}),o=0,i=[n,r];o<i.length;o++){var s=i[o];s.createConnection=Kr(s.createConnection,$r)}return Hr={httpAgent:n,httpsAgent:r}}):Promise.resolve({})}catch(e){return Promise.reject(e)}var n},$r=15e3;function Kr(e,t,n){return void 0===n&&(n={setTimeout:setTimeout,clearTimeout:clearTimeout}),function(r,o){var i=e.call(this,r,o);if(!i||"function"!=typeof i.once)return i;var s=n.setTimeout(function(){var e=new Error("connect timeout: no connection within "+t/1e3+"s");e.code="ETIMEDOUT",i.destroy(e)},t),a=function(){return n.clearTimeout(s)};return i.once("connect",a),i.once("secureConnect",a),i.once("error",a),i.once("close",a),i}}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));const Xr="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Yr(e,t,n){if(!e.s){if(n instanceof Zr){if(!n.s)return void(n.o=Yr.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Yr.bind(null,e,t),Yr.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Zr=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Yr(r,1,i(this.v))}catch(e){Yr(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Yr(r,1,t?t(o):o):n?Yr(r,1,n(o)):Yr(r,2,o)}catch(e){Yr(r,2,e)}},r},e}();function Qr(e){return e instanceof Zr&&1&e.s}function eo(e,t,n){var r,o,i=-1;return function s(a){try{for(;++i<e.length&&(!n||!n());)if((a=t(i))&&a.then){if(!Qr(a))return void a.then(s,o||(o=Yr.bind(null,r=new Zr,2)));a=a.v}r?Yr(r,1,a):r=a}catch(e){Yr(r||(r=new Zr),2,e)}}(),r}function to(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function no(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}var ro=[],oo=[".html",".js",".css"],io=[".gz",".br"];function so(e){return"path"in e&&e.path?e.path:e.name}function ao(e){var t,n=null==e||null==(t=e.config)?void 0:t.url;if(!n)return null;try{return new URL(n).host}catch(e){return null}}var uo={ECONNRESET:"connection reset before the upload completed",ECONNREFUSED:"connection refused by the storage host",ECONNABORTED:"connection aborted — timed out or closed mid-request",ENOTFOUND:"DNS lookup failed for the storage host",EAI_AGAIN:"DNS lookup failed temporarily — resolver unavailable",ETIMEDOUT:"connection timed out",EPIPE:"connection closed while sending the file",EHOSTUNREACH:"storage host unreachable from this network",ENETUNREACH:"network unreachable",EPROTO:"TLS or protocol error",ERR_NETWORK:"network error — the request never reached the storage host",CERT_HAS_EXPIRED:"the TLS certificate for the storage host has expired",UNABLE_TO_VERIFY_LEAF_SIGNATURE:"the TLS certificate for the storage host could not be verified",DEPTH_ZERO_SELF_SIGNED_CERT:"a self-signed TLS certificate was presented for the storage host",SELF_SIGNED_CERT_IN_CHAIN:"a self-signed TLS certificate was presented for the storage host"};function lo(e){if(!e)return"unknown upload error";var t=[];try{var n=e.response,r=null==n?void 0:n.status,o=null==n?void 0:n.statusText;r&&t.push("HTTP "+r+(o?" "+o:""));var i=null==n?void 0:n.data;if(null!=i){var s,a,u;if("string"==typeof i)u=i;else try{u=JSON.stringify(i)}catch(e){u=String(i)}var l=null==(s=u.match(/<Code>([^<]+)<\/Code>/))?void 0:s[1],c=null==(a=u.match(/<Message>([^<]+)<\/Message>/))?void 0:a[1];if(l)t.push("S3 "+l+(c?": "+c:""));else if(function(e){return/^\s*(<!DOCTYPE\s+html|<html[\s>])/i.test(e)}(u)){var f=ao(e);t.push("blocked by a network filter or proxy"+(f?" before it reached "+f:"")+" — ask your network administrator to allow this host")}else u&&t.push(u.slice(0,200))}var d=null;if(!n&&(d=function(e){var t,n,r=null!=(t=null==e?void 0:e.code)?t:null==e||null==(n=e.cause)?void 0:n.code;return"string"==typeof r&&r.length?r:null}(e),d)){var h=uo[d];t.push(h?d+" ("+h+")":d);var p=ao(e);p&&t.push("while uploading to "+p)}var m=e.message?String(e.message):"",v=r&&/^Request failed with status code \d+$/.test(m)||null!==d&&m.includes(d);m&&!v&&t.push(m)}catch(e){}return 0===t.length&&e.message&&t.push(String(e.message)),t.length?t.join(" — "):"unknown upload error"}var co=12e4;function fo(e,t){var n=null,r=!1,o=function(){n&&(clearTimeout(n),n=null)};return{reset:function(){r||(o(),n=setTimeout(function(){r=!0,n=null,t()},e))},cancel:o}}var ho="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function po(e,t,n){if(!e.s){if(n instanceof mo){if(!n.s)return void(n.o=po.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(po.bind(null,e,t),po.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var mo=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{po(r,1,i(this.v))}catch(e){po(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?po(r,1,t?t(o):o):n?po(r,1,n(o)):po(r,2,o)}catch(e){po(r,2,e)}},r},e}();function vo(e){return e instanceof mo&&1&e.s}function go(e,t,n){if(!e.s){if(n instanceof yo){if(!n.s)return void(n.o=go.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(go.bind(null,e,t),go.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var yo=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{go(r,1,i(this.v))}catch(e){go(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?go(r,1,t?t(o):o):n?go(r,1,n(o)):go(r,2,o)}catch(e){go(r,2,e)}},r},e}();function bo(e){return e instanceof yo&&1&e.s}function wo(e,t,n){if(!e.s){if(n instanceof Po){if(!n.s)return void(n.o=wo.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(wo.bind(null,e,t),wo.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var Po=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{wo(r,1,i(this.v))}catch(e){wo(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?wo(r,1,t?t(o):o):n?wo(r,1,n(o)):wo(r,2,o)}catch(e){wo(r,2,e)}},r},e}();function _o(e){return e instanceof Po&&1&e.s}var jo=function(e,t,n,r,o){try{var i=new URL(""+e.baseUrl+t+"/"+encodeURIComponent(n));return Promise.resolve(fetch(i,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(null!=r?r:{})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to "+o+" project ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},Eo=function(e,t,n,r,o){try{var i=Z(e),s=new Headers({authorization:i.authorization,"content-type":"application/json"});return i["x-needle-cloud-org"]&&s.set("x-needle-cloud-org",i["x-needle-cloud-org"]),Promise.resolve(fetch(e.baseUrl+"/v1/projects/"+encodeURIComponent(t)+"/diagnostics/"+n,F({},Q,{method:r,headers:s,signal:AbortSignal.timeout(3e4)},void 0===o?{}:{body:JSON.stringify(o)}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Diagnostics request failed ("+e.status+")")})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}};function So(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function xo(e){return"number"==typeof e&&Number.isSafeInteger(e)&&e>=0}function To(e){if(!(So(e)&&xo(e.requestIndex)&&!(e.requestIndex<1)&&"string"==typeof e.model&&e.model&&xo(e.requestBytes)&&xo(e.messagesBytes)&&xo(e.toolsBytes)&&xo(e.messageCount)&&xo(e.toolCount)&&So(e.messageRoles)))throw new Error("Invalid chat request diagnostics");for(var t=Object.create(null),n=0,r=0,o=Object.entries(e.messageRoles);r<o.length;r++){var i=o[r],s=i[0],a=i[1];if(!xo(a))throw new Error("Invalid chat request diagnostic role count");t[s]=a,n+=a}if(n!==e.messageCount)throw new Error("Inconsistent chat request diagnostic message count");return{requestIndex:e.requestIndex,model:e.model,requestBytes:e.requestBytes,messagesBytes:e.messagesBytes,toolsBytes:e.toolsBytes,messageCount:e.messageCount,toolCount:e.toolCount,messageRoles:t}}function ko(e){var t;try{t=JSON.parse(e)}catch(e){return null}if(!(t&&"object"==typeof t&&"code"in t&&"ai_allowance_exhausted"===t.code&&"limit_reached"in t&&!0===t.limit_reached&&"message"in t&&"string"==typeof t.message&&"account_id"in t&&"string"==typeof t.account_id&&"actions"in t&&Array.isArray(t.actions)))return null;for(var n,r=[],o=L(t.actions);!(n=o()).done;){var i=n.value;if(!i||"object"!=typeof i||!("kind"in i)||"top_up"!==i.kind&&"view_usage"!==i.kind||!("label"in i)||"string"!=typeof i.label||!("url"in i)||"string"!=typeof i.url)return null;var s=void 0;try{s=new URL(i.url)}catch(e){return null}if("https:"!==s.protocol&&"http:"!==s.protocol)return null;r.push({kind:i.kind,label:i.label,url:i.url})}return{code:t.code,limit_reached:!0,message:t.message,account_id:t.account_id,actions:r}}var Oo=/*#__PURE__*/function(e){function t(t,n,r){var o;return void 0===r&&(r=null),(o=e.call(this,t)||this).name="AIChatError",o.status=n,o.details=r,o}return D(t,e),t}(/*#__PURE__*/V(Error)),Ro=["chat_url"];function Uo(e){return Co.apply(this,arguments)}function Co(){return Co=H(/*#__PURE__*/q().mark(function e(t){var n,r,o,i,s,a,u,l,c,f;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=t.getReader(),r=new TextDecoder,o="",e.prev=3;case 4:return e.next=7,I(n.read());case 7:if(s=(i=e.sent).value,!i.done){e.next=12;break}return e.abrupt("break",26);case 12:o+=r.decode(s,{stream:!0}),a=o.split("\n\n"),o=a.pop()||"",u=L(a);case 16:if((l=u()).done){e.next=24;break}if(!(c=Ao(l.value))){e.next=22;break}return e.next=22,c;case 22:e.next=16;break;case 24:e.next=4;break;case 26:if(!o.trim()){e.next=31;break}if(!(f=Ao(o))){e.next=31;break}return e.next=31,f;case 31:return e.prev=31,n.releaseLock(),e.finish(31);case 34:case"end":return e.stop()}},e,null,[[3,,31,34]])})),Co.apply(this,arguments)}function Ao(e){for(var t,n=null,r="",o=void 0,i=L(e.split("\n"));!(t=i()).done;){var s=t.value;s.startsWith("event: ")?n=s.slice(7).trim():s.startsWith("data: ")?r=s.slice(6):s.startsWith("id: ")&&(o=parseInt(s.slice(4).trim(),10))}if(!n)return null;var a=null;switch(n){case"request_diagnostics":a={type:"request_diagnostics",diagnostics:To(JSON.parse(r))};break;case"delta":a={type:"delta",content:decodeURIComponent(r)};break;case"message":a={type:"message",content:decodeURIComponent(r)};break;case"status":a={type:"status",message:decodeURIComponent(r)};break;case"error":var u=decodeURIComponent(r),l=ko(u);a=l?{type:"error",message:l.message,details:l}:{type:"error",message:u};break;case"notice":a={type:"notice",message:decodeURIComponent(r)};break;case"stopped":a={type:"stopped"};break;case"tool-input-available":case"tool-output-available":a=F({},JSON.parse(r),{type:n});break;case"tool_call":a=F({type:"tool_call"},JSON.parse(r));break;case"tool_result":a=F({type:"tool_result"},JSON.parse(r));break;case"file_change":a=F({type:"file_change"},JSON.parse(r));break;case"local_preview":a=F({type:"local_preview"},JSON.parse(r));break;case"message_inserted":a=F({type:"message_inserted"},JSON.parse(r));break;case"elicitation":a=F({type:"elicitation"},JSON.parse(r));break;case"done":var c=JSON.parse(r),f=c.chat_url;a={type:"done",token_usage:B(c,Ro)},f&&(a.chat_url=f);break;case"message_id":a={type:"message_id",message_id:decodeURIComponent(r)};break;case"chat_id":a={type:"chat_id",chat_id:decodeURIComponent(r)}}return a&&void 0!==o&&(a.id=o),a}function Wo(e,t){var n,r=Z(e);return null!=t&&t.personal&&(r["x-needle-ai-chat"]="personal"),null!=t&&t.instanceId&&(r["x-needle-instance-id"]=t.instanceId),!0===(null==t||null==(n=t.capabilities)?void 0:n.inlineToolCalls)&&(r["x-needle-chat-inline-tools"]="1"),r}var No=function(e,t){try{var n=new URL(e.baseUrl+Y.ai.chat),r=Wo(e,t);return r["Content-Type"]="application/json",Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:r,body:JSON.stringify({type:"new_message",slug:t.slug,message:t.message,stream:!1,project_id:t.projectId,source:t.source,allow_file_edits:!0===t.allowFileEdits,file_edit_session_id:!0===t.allowFileEdits?t.fileEditSessionId:void 0,allow_local_commands:!0===t.allowLocalCommands,local_command_session_id:!0===t.allowLocalCommands?t.localCommandSessionId:void 0,full_url:t.full_url,pathname:t.pathname,context:t.context,disabled_tools:t.disabled_tools,tool_policy:t.toolPolicy})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Oo("Failed to send chat message ("+e.status+"): "+t,e.status,ko(t))})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},Io=function(e,t,n){try{return null!=n&&n.reconnect?function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)),o=Wo(e,n);return o.Accept="text/event-stream",Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:o,signal:null==n?void 0:n.signal}))).then(function(e){var t;return e.ok&&null!=(t=e.headers.get("content-type"))&&t.includes("text/event-stream")&&e.body?Uo(e.body):null})}catch(e){return Promise.reject(e)}}(e,t,n):function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t));null!=(null==n?void 0:n.limit)&&r.searchParams.set("limit",String(n.limit)),null!=(null==n?void 0:n.offset)&&r.searchParams.set("offset",String(n.offset));var o=Wo(e,n);return Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:o}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to read chat ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,n)}catch(e){return Promise.reject(e)}},Lo=function(e){try{var t=new URL(e.baseUrl+Y.ai.list_chats);void 0!==e.limit&&t.searchParams.set("limit",String(e.limit)),void 0!==e.chatId&&t.searchParams.set("chat_id",e.chatId),void 0!==e.projectId&&t.searchParams.set("project_id",e.projectId);var n=Wo(e);return Promise.resolve(fetch(t,F({},Q,{method:"GET",headers:n}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to list chats ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}};function Fo(e,t){return t.stream?function(e,t){return zo.apply(this,arguments)}(e,t):No(e,t)}function zo(){return(zo=H(/*#__PURE__*/q().mark(function e(t,n){var r,o,i,s,a;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new URL(t.baseUrl+Y.ai.chat),(o=Wo(t,n))["Content-Type"]="application/json",i={type:"new_message",slug:n.slug,message:n.message,stream:!0,project_id:n.projectId,source:n.source,allow_file_edits:!0===n.allowFileEdits,file_edit_session_id:!0===n.allowFileEdits?n.fileEditSessionId:void 0,allow_local_commands:!0===n.allowLocalCommands,local_command_session_id:!0===n.allowLocalCommands?n.localCommandSessionId:void 0,full_url:n.full_url,pathname:n.pathname,context:n.context,disabled_tools:n.disabled_tools,tool_policy:n.toolPolicy},e.next=6,I(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(i)})));case 6:if((s=e.sent).ok){e.next=12;break}return e.next=10,I(s.text());case 10:throw new Oo("Failed to stream chat message ("+s.status+"): "+(a=e.sent),s.status,ko(a));case 12:if(s.body){e.next=14;break}throw new Error("Response body is null — streaming not supported in this environment");case 14:return e.delegateYield(A(W(Uo(s.body))),"t0",15);case 15:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Do(e,t){return Mo.apply(this,arguments)}function Mo(){return(Mo=H(/*#__PURE__*/q().mark(function e(t,n){var r,o,i,s,a;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new URL(t.baseUrl+Y.ai.chat),(o=Wo(t,n))["Content-Type"]="application/json",i={type:"elicitation_response",slug:n.slug,action_id:n.action_id,value:n.value,text:n.text,canceled:n.canceled,file_edit_session_id:n.fileEditSessionId,local_command_session_id:n.localCommandSessionId,allow_file_edits:!0===n.allowFileEdits,allow_local_commands:!0===n.allowLocalCommands,full_url:n.full_url,stream:!0},e.next=6,I(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(i)})));case 6:if((s=e.sent).ok){e.next=12;break}return e.next=10,I(s.text());case 10:throw new Oo("Failed to send elicitation response ("+s.status+"): "+(a=e.sent),s.status,ko(a));case 12:if(s.body){e.next=14;break}throw new Error("Response body is null — streaming not supported in this environment");case 14:return e.delegateYield(A(W(Uo(s.body))),"t0",15);case 15:case"end":return e.stop()}},e)}))).apply(this,arguments)}var Bo=/*#__PURE__*/function(e){function t(t,n,r,o){var i;return(i=e.call(this,t,n,"Evaluation failed ("+t+"): "+r)||this).name="AIEvaluationError",i.code=o,i.details=ko(n),i}return D(t,e),t}(X),qo=function(){var e=globalThis.crypto;if(null!=e&&e.randomUUID)return e.randomUUID();var t=new Uint8Array(16);if(null!=e&&e.getRandomValues)e.getRandomValues(t);else for(var n=0;n<16;n++)t[n]=Math.floor(256*Math.random());t[6]=15&t[6]|64,t[8]=63&t[8]|128;var r=Array.from(t,function(e){return e.toString(16).padStart(2,"0")}).join("");return r.slice(0,8)+"-"+r.slice(8,12)+"-"+r.slice(12,16)+"-"+r.slice(16,20)+"-"+r.slice(20)}();function Jo(e){if("string"!=typeof e||0===e.length)return null;try{return new URL(e).host}catch(e){return null}}function Ho(e,t){var n,r=t||{},o=r.source,i=void 0===o?"sdk":o,s=r.tools,a=void 0===s?[]:s,u=r.toolCatalog,l=r.onToolRequest,c=r.toolReadyTimeout,f=void 0===c?5e3:c,d=r.personal,h=void 0!==d&&d,p=r.capabilities,m=r.createWebSocket,v=void 0===(null==t?void 0:t.toolPolicy)?void 0:structuredClone(t.toolPolicy),g=null,y=null,b=null,w=!1;function P(e){return _.apply(this,arguments)}function _(){return(_=H(/*#__PURE__*/q().mark(function e(t){var n,r,o,i,s,a;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=!1,r=!1,e.prev=2,i=W(t);case 4:return e.next=6,I(i.next());case 6:if(!(n=!(s=e.sent).done)){e.next=14;break}return"done"===(a=s.value).type&&(g=a.token_usage,a.chat_url&&(y=a.chat_url)),e.next=11,a;case 11:n=!1,e.next=4;break;case 14:e.next=20;break;case 16:e.prev=16,e.t0=e.catch(2),r=!0,o=e.t0;case 20:if(e.prev=20,e.prev=21,!n||null==i.return){e.next=25;break}return e.next=25,I(i.return());case 25:if(e.prev=25,!r){e.next=28;break}throw o;case 28:return e.finish(25);case 29:return e.finish(20);case 30:case"end":return e.stop()}},e,null,[[2,16,20,30],[21,,25,29]])}))).apply(this,arguments)}n=a.length>0?new Promise(function(t,n){var r=null;f>0&&(r=setTimeout(function(){n(new Error("ChatSession: WebSocket tool connection timed out after "+f+"ms. Tools will not be available for this chat session."))},f)),b=function(e,t){var n=t.source,r=void 0===n?"editor":n,o=t.tools,i=t.toolCatalog,s=t.onToolRequest,a=t.onOpen,u=t.onClose,l=t.onError,c=t.reconnect,f=void 0===c||c,d=t.reconnectInterval,h=void 0===d?3e3:d,p=t.maxReconnectAttempts,m=void 0===p?10:p,v=t.heartbeatInterval,g=void 0===v?3e4:v,y=t.heartbeatTimeout,b=void 0===y?75e3:y,w=t.createWebSocket,P=void 0===w?function(e){return new WebSocket(e)}:w,_=qo,j=null,E=!1,S=0,x=null,T=null,k=0,O=!1,R=3,U=0,C=[].concat(void 0===o?[]:o),A=i?[].concat(i):void 0,W=!1,N=null,I=null;if("undefined"!=typeof document&&"function"==typeof document.addEventListener){var L=function(t){var n,r,o,i;r=e.baseUrl,o=Jo(null==(n=t)?void 0:n.blockedURI),i=Jo(r),null!==o&&null!==i&&o===i&&(N=t)};document.addEventListener("securitypolicyviolation",L),I=function(){return document.removeEventListener("securitypolicyviolation",L)}}function z(e){j&&1===j.readyState&&j.send(JSON.stringify(e))}function D(){z(F({type:"register",source:r,instanceId:_,tools:W&&A?A:C},W&&A?{discoveryOwner:"cloud"}:{}))}function M(){T&&(clearInterval(T),T=null)}function B(){!E&&f&&(x||(S>=m?null==l||l(new Error("Max reconnect attempts ("+m+") reached")):(S++,x=setTimeout(function(){x=null,q()},h))))}function q(){if(!E){if(j){try{j.close(1e3,"client reconnecting")}catch(e){}j=null}var t=function(){var t=""+e.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")+Y.ai.ws+"?token="+encodeURIComponent(e.authToken);return e.org&&(t+="&org="+encodeURIComponent(e.org)),t+"&instance="+encodeURIComponent(_)}();(j=P(t)).onopen=function(){W=!1,S=0,D(),M(),g&&b&&(k=Date.now(),O=!1,U=0,T=setInterval(function(){if(!E&&j){if(Date.now()-k>b){if(!O)return void(++U>=R&&M());M();var e=j;j=null;try{e.close(1e3,"heartbeat timeout")}catch(e){}return null==u||u(),void B()}z({type:"ping"})}},g)),null==a||a()},j.onmessage=function(e){k=Date.now();var t="string"==typeof e.data?e.data:String(e.data);!O&&t.includes('"pong"')&&(O=!0),function(e){try{var t,n=JSON.parse(e);if("registered"===n.type&&1===(null==(t=n.capabilities)?void 0:t.toolDiscovery)&&A&&!W&&(W=!0,D()),"execute_tool"===n.type&&n.requestId&&n.toolName){var r=n.requestId,o=n.toolName,i=n.args||{},a=F({chatId:"string"==typeof n.chatId&&n.chatId?n.chatId:null,requestId:r},Array.isArray(n.allowedSdkMethods)?{allowedSdkMethods:n.allowedSdkMethods.filter(function(e){return"string"==typeof e})}:{});if(!s)return void z({type:"tool_error",requestId:r,error:"No tool handler registered"});Promise.resolve().then(function(){return s(o,i,a)}).then(function(e){if(e.error)z({type:"tool_error",requestId:r,error:e.error});else{var t=Array.isArray(e.images)&&e.images.length>0?e.images:void 0;z(F({type:"tool_result",requestId:r,result:e.result},t?{images:t}:{}))}}).catch(function(e){z({type:"tool_error",requestId:r,error:(null==e?void 0:e.message)||String(e)})})}}catch(e){}}(t)},j.onclose=function(e){var t,n;j=null,M(),null==u||u(),"replaced"!==("string"==typeof(null==e?void 0:e.reason)?e.reason:null!=(t=null==e||null==(n=e.reason)||null==n.toString?void 0:n.toString())?t:"")&&4001!==(null==e?void 0:e.code)?B():E=!0},j.onerror=function(t){null==l||l((null==t?void 0:t.error)||function(e,t){var n=String(null!=e?e:"").replace(/\/+$/,"");if(!t)return new Error("WebSocket error: can not connect to "+n+". Please try again later.");var r="string"==typeof t.violatedDirective&&t.violatedDirective?t.violatedDirective:"connect-src",o="string"==typeof t.documentHost&&t.documentHost||Jo(t.documentURI)||"this page";return new Error("Blocked by the Content Security Policy of "+o+": it does not allow connections to "+n+" (violated "+r+"). This is a restriction of the page you are on, not a problem with Needle Cloud, so retrying will not help. Allow "+n+" in that page's "+r+", or use the inspector on another page.")}(e.baseUrl,N))}}}return q(),{instanceId:_,updateTools:function(e,t){C=[].concat(e),void 0!==t&&(A=[].concat(t)),D()},sendPresence:function(e){z(F({type:"presence"},e))},close:function(){E=!0,M(),x&&(clearTimeout(x),x=null),I&&(I(),I=null),j&&(j.close(1e3,"client closed"),j=null)},get connected(){return null!==j&&1===j.readyState}}}(e,F({source:i,tools:a,toolCatalog:u,onToolRequest:l},m?{createWebSocket:m}:{},{onOpen:function(){r&&clearTimeout(r),t()},onError:function(e){r&&clearTimeout(r),n(new Error("ChatSession: WebSocket tool connection failed: "+e.message))}}))}):Promise.resolve();var j={get ready(){return n},sendMessage:function(t,r,o){return H(/*#__PURE__*/q().mark(function s(){var a,u,l;return q().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,I(n);case 2:if(!w){s.next=4;break}throw new Error("ChatSession is closed");case 4:return l=Fo(e,{slug:t,message:r,stream:!0,projectId:null==o?void 0:o.projectId,source:i,allowFileEdits:!0===(null==o?void 0:o.allowFileEdits),fileEditSessionId:null==o?void 0:o.fileEditSessionId,allowLocalCommands:!0===(null==o?void 0:o.allowLocalCommands),localCommandSessionId:null==o?void 0:o.localCommandSessionId,personal:h,capabilities:p,instanceId:null!=(a=null==(u=b)?void 0:u.instanceId)?a:null,full_url:null==o?void 0:o.full_url,pathname:null==o?void 0:o.pathname,context:null==o?void 0:o.context,disabled_tools:null==o?void 0:o.disabled_tools,toolPolicy:v}),s.delegateYield(A(W(P(l))),"t0",6);case 6:case"end":return s.stop()}},s)}))()},sendElicitationResponse:function(t,r,o){return H(/*#__PURE__*/q().mark(function s(){var a,u;return q().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,I(n);case 2:if(!w){s.next=4;break}throw new Error("ChatSession is closed");case 4:return s.delegateYield(A(W(P(Do(e,F({slug:t},r,{source:i,personal:h,capabilities:p,instanceId:null!=(a=null==(u=b)?void 0:u.instanceId)?a:null,full_url:null==o?void 0:o.full_url,allowFileEdits:!0===(null==o?void 0:o.allowFileEdits),fileEditSessionId:null==o?void 0:o.fileEditSessionId,allowLocalCommands:!0===(null==o?void 0:o.allowLocalCommands),localCommandSessionId:null==o?void 0:o.localCommandSessionId}))))),"t0",5);case 5:case"end":return s.stop()}},s)}))()},sendMessageSync:function(t,r,o){return Promise.resolve(n).then(function(){var n,s;if(w)throw new Error("ChatSession is closed");return Promise.resolve(Fo(e,{slug:t,message:r,stream:!1,projectId:null==o?void 0:o.projectId,source:i,allowFileEdits:!0===(null==o?void 0:o.allowFileEdits),fileEditSessionId:null==o?void 0:o.fileEditSessionId,allowLocalCommands:!0===(null==o?void 0:o.allowLocalCommands),localCommandSessionId:null==o?void 0:o.localCommandSessionId,personal:h,capabilities:p,instanceId:null!=(n=null==(s=b)?void 0:s.instanceId)?n:null,full_url:null==o?void 0:o.full_url,pathname:null==o?void 0:o.pathname,context:null==o?void 0:o.context,disabled_tools:null==o?void 0:o.disabled_tools,toolPolicy:v})).then(function(e){return e.token_usage&&(g=e.token_usage),e.chat_url&&(y=e.chat_url),e})})},interruptChat:function(t){try{return Promise.resolve(function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat_stop),o=Wo(e,n);return o["Content-Type"]="application/json",Promise.resolve(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify({slug:t})}))).then(function(e){return function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to interrupt chat ("+e.status+"): "+t)})}()})}catch(e){return Promise.reject(e)}}(e,t,{personal:h}))}catch(e){return Promise.reject(e)}},listTools:function(t,r){try{if(w)throw new Error("ChatSession is closed");return Promise.resolve(n).then(function(){var n,o;return function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)+"/tools");return void 0!==(null==n?void 0:n.cursor)&&r.searchParams.set("cursor",n.cursor),void 0!==(null==n?void 0:n.limit)&&r.searchParams.set("limit",String(n.limit)),Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:Wo(e,n)}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Oo("Could not list chat tools ("+e.status+"): "+t,e.status)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,F({},r,{personal:h,instanceId:null!=(n=null==(o=b)?void 0:o.instanceId)?n:null}))})}catch(e){return Promise.reject(e)}},updateToolPreferences:function(t,r){try{if(w)throw new Error("ChatSession is closed");return Promise.resolve(n).then(function(){var n,o;return function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)+"/tools"),i=Wo(e,r);return i["Content-Type"]="application/json",Promise.resolve(fetch(o,F({},Q,{method:"PATCH",headers:i,body:JSON.stringify(n)}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Oo("Could not save chat tool preferences ("+e.status+"): "+t,e.status)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,r,{personal:h,instanceId:null!=(n=null==(o=b)?void 0:o.instanceId)?n:null})})}catch(e){return Promise.reject(e)}},enqueueMessage:function(t,n){try{return Promise.resolve(function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.ai.chat_enqueue),i=Wo(e,r);return i["Content-Type"]="application/json",Promise.resolve(fetch(o,F({},Q,{method:"POST",headers:i,body:JSON.stringify({slug:t,id:n.id,content:n.content})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to enqueue chat message ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,n,{personal:h}))}catch(e){return Promise.reject(e)}},cancelEnqueuedMessage:function(t,n){try{return Promise.resolve(function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.ai.chat_enqueue_cancel),i=Wo(e,r);return i["Content-Type"]="application/json",Promise.resolve(fetch(o,F({},Q,{method:"POST",headers:i,body:JSON.stringify({slug:t,id:n})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to cancel queued chat message ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,n,{personal:h}))}catch(e){return Promise.reject(e)}},readChat:function(t,n){try{return Promise.resolve(Io(e,t,{offset:null==n?void 0:n.offset,limit:null==n?void 0:n.limit,personal:h,capabilities:p})).then(function(e){return e.chat_url&&(y=e.chat_url),e})}catch(e){return Promise.reject(e)}},reconnectChat:function(t){try{return Promise.resolve(Io(e,t,{personal:h,capabilities:p,reconnect:!0})).then(function(e){return e?P(e):null})}catch(e){return Promise.reject(e)}},associateProject:function(t,n){try{if(w)throw new Error("ChatSession is closed");return Promise.resolve(function(e,t,n,r){try{return Promise.resolve(fetch(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)+"/projects",F({},Q,{method:"POST",headers:F({},Wo(e,r),{"Content-Type":"application/json"}),body:JSON.stringify({project_id:n})}))).then(function(e){return function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to associate chat project ("+e.status+"): "+t)})}()})}catch(e){return Promise.reject(e)}}(e,t,n,{personal:h})).then(function(){})}catch(e){return Promise.reject(e)}},listChats:function(t){try{return Promise.resolve(Lo(F({},e,{projectId:null==t?void 0:t.projectId})))}catch(e){return Promise.reject(e)}},newChat:function(){return(t=null==(e=globalThis.crypto)||null==e.randomUUID?void 0:e.randomUUID())?"chat-"+t:"chat-"+Date.now().toString(36)+"-"+Math.random().toString(36).slice(2,10);var e,t},updateTools:function(e,t){b&&b.updateTools(e,t)},get usage(){return g},get chatUrl(){return y},get toolsConnected(){var e,t;return null!=(e=null==(t=b)?void 0:t.connected)&&e},get instanceId(){var e,t;return null!=(e=null==(t=b)?void 0:t.instanceId)?e:null},close:function(){w=!0,b&&(b.close(),b=null)}};return j}var Go=function(e,t){try{var n;return Promise.resolve((null!=(n=e.fetch)?n:globalThis.fetch)(t)).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Runtime lookup failed (HTTP "+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}};function Vo(e,t,n){if("tool-input-available"===n.type){var r=e?[].concat(e):t?[{type:"text",text:t}]:[];return r.some(function(e){return"dynamic-tool"===e.type&&e.toolCallId===n.toolCallId})||r.push(F({type:"dynamic-tool",toolCallId:n.toolCallId,toolName:n.toolName,input:n.input,state:"input-available"},n.title?{title:n.title}:{})),r}if(!e)return e;if("tool-output-available"===n.type)return e.map(function(e){return"dynamic-tool"===e.type&&e.toolCallId===n.toolCallId?F({},e,{state:"output-available",output:n.output}):e});if("delta"===n.type){var o=[].concat(e),i=o.at(-1);return"text"===(null==i?void 0:i.type)?o[o.length-1]=F({},i,{text:i.text+n.content}):o.push({type:"text",text:n.content}),o}if("message"===n.type){var s=e.filter(function(e){return"text"===e.type}).map(function(e){return e.text}).join("");if(n.content.startsWith(s)&&n.content.length>s.length)return Vo(e,t,{type:"delta",content:n.content.slice(s.length)});if(s!==n.content)return}return e}var $o=new Set(["a","an","the","to","for","in","of","and","or","tool","tools","scene","editor","use","with","please","i","want","can","my"]);function Ko(e){var t;return null!=(t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().match(/[a-z0-9]+/g))?t:[]}function Xo(e){return e.length>4&&e.endsWith("ies")?e.slice(0,-3)+"y":e.length>4&&e.endsWith("s")?e.slice(0,-1):e}function Yo(e,t){void 0===t&&(t={});var n=t.query,r=void 0===n?"":n,o=t.limit,i=void 0===o?3:o,s=t.offset,a=void 0===s?0:s;if("string"!=typeof r||r.length>1024)throw new Error("query must be a string of at most 1024 characters");if(!Number.isInteger(i)||i<1||i>20)throw new Error("limit must be an integer from 1 to 20");if(!Number.isInteger(a)||a<0)throw new Error("offset must be a nonnegative integer");var u=Ko(r),l=u.filter(function(e){return!$o.has(e)}),c=Array.from(new Set((l.length?l:u.filter(function(e){return"scene"===e||"editor"===e})).map(Xo))),f=e.map(function(e){var t,n=new Set(Ko(e.name).map(Xo)),o=new Set((null!=(t=e.tags)?t:[]).flatMap(Ko).map(Xo)),i=new Set(Ko(e.description).map(Xo)),s=(e.name.toLowerCase()===r.trim().toLowerCase()?1e3:0)+c.reduce(function(e,t){return e+(n.has(t)?20:o.has(t)?12:i.has(t)?2:0)},0);return{tool:e,score:s}}).filter(function(e){return e.score>0}).sort(function(e,t){return t.score-e.score||e.tool.name.localeCompare(t.tool.name)});if(!f.length)return{tools:[],index:[].concat(e).sort(function(e,t){return e.name.localeCompare(t.name)}).slice(a,a+i).map(function(e){return{name:e.name,description:e.description.slice(0,180)}}),totalMatched:0,totalAvailable:e.length,offset:a,hasMore:a+i<e.length};for(var d,h=f.slice(a,a+i),p=new Map,m=L(h);!(d=m()).done;)for(var v,g=L(new Set(null!=(y=d.value.tool.guidance)?y:[]));!(v=g()).done;){var y,b,w=v.value;p.set(w,(null!=(b=p.get(w))?b:0)+1)}var P=Array.from(p).filter(function(e){return e[1]>1}).map(function(e){return e[0]}),_=new Set(P);return F({},P.length?{guidance:P}:{},{tools:h.map(function(e){var t,n=e.tool;return F({name:n.name,description:n.description,inputSchema:n.inputSchema},n.outputSchema?{outputSchema:n.outputSchema}:{},n.invocation?{invocation:n.invocation}:{},null!=(t=n.guidance)&&t.some(function(e){return!_.has(e)})?{guidance:Array.from(new Set(n.guidance.filter(function(e){return!_.has(e)})))}:{})}),totalMatched:f.length,totalAvailable:e.length,offset:a,hasMore:a+i<f.length})}var Zo=function(e,t){try{return Promise.resolve(t?{authToken:t,org:e||void 0}:T.requestAccessToken(e).then(function(t){return{authToken:t,org:e||void 0}}))}catch(e){return Promise.reject(e)}},Qo=["org","authToken"],ei=["org","authToken"],ti=["org","authToken"],ni=function(e,t){void 0===t&&(t={});try{if(!e)throw new Error("A content identifier is required");return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=""+e.baseUrl+Y.content.root+"/"+t,r=Z(e);return Promise.resolve(fetch(n,F({},Q,{method:"DELETE",headers:r}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to delete content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},ri=function(e,t){try{if(!e)throw new Error("A content identifier is required");var n=t||{},r=n.org,o=n.authToken,i=B(n,ti),s=si.filter(function(e){return e in i});if(s.length)throw new Error(s.join(" and ")+" cannot be changed through updateContent — visibility must be changed deliberately, not as part of a metadata update.");if(!Object.keys(i).length)throw new Error("Nothing to update — pass at least one field");return Promise.resolve(Zo(r,o)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return Promise.resolve(function(e,t,n){try{var r=function(){return Promise.resolve(fetch(o,F({},Q,{method:"PATCH",headers:F({},i,{"Content-Type":"application/json"}),body:JSON.stringify(s)})).catch(function(e){return{error:e.message,status:500}})).then(function(e){var t;function r(r){return t?r:Promise.resolve(e.json()).then(function(e){var t=function(){if(e.upload_thumbnail&&n.thumbnail){var t,r=function(){o&&console.error("Failed to upload thumbnail",o.status,o.error)},o=null,i=0,s=function(e,t,n){for(var r;;){var o=e();if(_o(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!_o(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!_o(s)){r=2;break}}}var a=new Po,u=wo.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!_o(s))return void s.then(f).then(void 0,u);if(!(o=e())||_o(o)&&!o.v)return void wo(a,1,i);if(o.then)return void o.then(c).then(void 0,u);_o(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):wo(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):wo(a,1,i)}}(function(){return!t&&i<5},function(){return i++},function(){var r=e.upload_thumbnail;return Promise.resolve(fetch(r.put_url,{method:"PUT",headers:{"Content-Type":r.content_type,"Content-MD5":r.content_md5},body:n.thumbnail}).catch(function(e){return{error:e.message,status:500}})).then(function(e){var n=function(){if("error"in e)return o=e,Promise.resolve(Fr(100*i)).then(function(){});var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){return o={error:t,status:e.status},Promise.resolve(Fr(100*i)).then(function(){})});o=null,t=1}();return n&&n.then?n.then(function(){}):void 0}();if(n&&n.then)return n.then(function(){})})});return s&&s.then?s.then(r):r()}}();return t&&t.then?t.then(function(){return{success:!0}}):{success:!0}})}if("error"in e)return e;var o=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(n){return t=1,{error:n,status:e.status}})}();return o&&o.then?o.then(r):r(o)})},o=""+e.baseUrl+Y.content.root+"/"+t,i=Z(e),s=F({},n),a=function(){if(n.thumbnail){var e=n.thumbnail;return Promise.resolve(e.arrayBuffer()).then(function(t){var n=Pr(t);s.upload_thumbnail={name:e.name,content_size:e.size,content_type:e.type,content_md5:n}})}}();return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e,i)).then(function(e){if(e&&"error"in e)throw new Error(e.error);return{success:!0}})})}catch(e){return Promise.reject(e)}},oi=function(e,t){void 0===t&&(t={});try{var n=t.org,r=t.authToken,o=B(t,ei);return Promise.resolve(Zo(n,r)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t,n){void 0===n&&(n={});try{var r=new URL(""+e.baseUrl+Y.content.root+"/"+encodeURIComponent(t));n.include_metadata&&r.searchParams.set("include_metadata",n.include_metadata),n.item&&r.searchParams.set("item",n.item);var o=Z(e);return Promise.resolve(fetch(r.toString(),F({},Q,{method:"GET",headers:o}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to get content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e,o)})}catch(e){return Promise.reject(e)}},ii=function(e){void 0===e&&(e={});try{var t=e.org,n=e.authToken,r=B(e,Qo);return Promise.resolve(Zo(t,n)).then(function(e){if(null==e||!e.authToken)throw new Error("Not authenticated");return function(e,t){void 0===t&&(t={});try{var n=new URL(e.baseUrl+Y.content.root);t.include_metadata&&n.searchParams.set("include_metadata",t.include_metadata),void 0!==t.include_projects&&n.searchParams.set("include_projects",String(t.include_projects)),t.content_type&&n.searchParams.set("content_type",t.content_type),t.content_format&&n.searchParams.set("content_format",t.content_format),t.search&&n.searchParams.set("search",t.search),t.tags&&n.searchParams.set("tags",t.tags),t.types&&n.searchParams.set("types",t.types),t.trash&&n.searchParams.set("trash","true"),t.is_public&&n.searchParams.set("is_public","true"),t.page&&n.searchParams.set("page",String(t.page)),t.limit&&n.searchParams.set("limit",String(t.limit)),t.collection_id&&n.searchParams.set("collection_id",t.collection_id),t.offset&&n.searchParams.set("offset",String(t.offset));var r=Z(e);return Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:r}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to list content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},e),r)})}catch(e){return Promise.reject(e)}},si=["password","is_public"],ai=["thumbnail","metadata","progress","verify"],ui=function(e,t){try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(n){if(!n)throw new Error("Not authenticated");var r=e.map(function(e){return function(e,t){if(void 0===t&&(t=null),"object"==typeof(r=e)&&"string"==typeof r.name&&"string"==typeof r.mimetype){var n=e.mimetype||jr(e.name);e=new File([e.buffer],e.name,{type:n})}else e.type||(e=new File([e],e.name,{type:jr(e.name)}));var r,o=e;return null==t&&(t=e.webkitRelativePath||""),o.path=t+e.name,o}(e)}),o=t.thumbnail,i=t.metadata,s=t.progress,a=t.verify;return function(e,t,n){void 0===n&&(n=void 0);try{var r=function(e,t,n){void 0===n&&(n=void 0);try{for(var r,o,i=function(e){var t=[];return{files:e.filter(function(e){var n=e.name||"";return!(!n||n.endsWith("/"))||(t.push({name:n,reason:"directory-entry"}),!1)}),skipped:t}}(t.files),s=i.files,a=L(i.skipped);!(o=a()).done;)console.warn('[upload] Skipping directory entry: "'+o.value.name+'"');t.files=s;var u=(null==(r=n)?void 0:r.loglevel)||"none";if(!s.length)return"none"!=u&&console.error("No files to upload"),Promise.resolve({success:!1,error:"No files to upload"});if(!t.entrypoint){var l=function(e){var t=null,n="",r=e.filter(function(e){return"index.html"===e.name.toLowerCase()||"index.html.gz"===e.name.toLowerCase()||"index.html.br"===e.name.toLowerCase()});if(1===r.length)return r[0];var o=e.filter(function(e){return e.name.toLowerCase().endsWith(".html")||e.name.toLowerCase().endsWith(".htm")||e.name.toLowerCase().endsWith(".html.gz")||e.name.toLowerCase().endsWith(".html.br")});if(1===o.length)return o[0];if(o.length>1){for(var i,s=new Map,a=L(o);!(i=a()).done;){var u=i.value,l=u.path.split("/"),c=s.get(l.length);c||s.set(l.length,c=[]),c.push(u)}var f=Array.from(s.keys()).sort(function(e,t){return e-t});if(f.length>0)for(var d,h=L(f);!(d=h()).done;){var p=s.get(d.value);if(p)return p.find(function(e){return"index.html"===e.name.toLowerCase()||"index.html.gz"===e.name.toLowerCase()||"index.html.br"===e.name.toLowerCase()})||p[0]}return n="Invalid upload: Multiple HTML files found but could not determine root.",console.error(n,o.map(function(e){return e.path||e.name})),{error:n}}var m=e.filter(function(e){return e.name.toLowerCase().endsWith(".glb")||e.name.toLowerCase().endsWith(".gltf")||e.name.toLowerCase().endsWith(".vrm")});if(m.length>1){var v=function(e){for(var t,n=new Array,r=/(mesh_lod|image)_\d_(.{1,50})/,o=L(e);!(t=o()).done;){var i=t.value;if(!r.test(i.name)){var s=i.name.toLowerCase();(s.endsWith(".gltf")||s.endsWith(".vrm")||s.endsWith(".glb"))&&n.push(i)}}return 1==n.length?n[0]:null!=(a=Jr(n)[0])?a:null;var a}(m);return v?t=v:(n="Invalid upload: Multiple glb/glTF/vrm files found. This is currently not supported.",console.error(n,m.map(function(e){return e.path||e.name})),{error:n})}if(1===m.length)return m[0];var g=e.filter(function(e){return e.name.toLowerCase().endsWith(".usdz")||e.name.toLowerCase().endsWith(".usd")||e.name.toLowerCase().endsWith(".usda")||e.name.toLowerCase().endsWith(".usdc")});if(g.length>=1)return t=function(e){for(var t,n,r=Jr(e),o=function(){var e=s[i],t=r.find(function(t){return t.name.toLowerCase().endsWith("."+e)});if(t)return{v:t}},i=0,s=["usda","usdz","usd","usdc"];i<s.length;i++)if(n=o())return n.v;return null!=(t=r[0])?t:null}(g),t;var y=e.filter(function(e){return e.name.toLowerCase().endsWith(".fbx")});if(y.length>1)return n="Invalid upload: Multiple fbx files found. This is currently not supported.",console.error(n,y),{error:n};if(1===y.length)return y[0];var b=e.filter(function(e){return e.name.toLowerCase().endsWith(".obj")});if(b.length>1)return n="Invalid upload: Multiple obj files found. This is currently not supported.",console.error(n,b),{error:n};if(1===b.length)return b[0];var w=e.filter(function(e){return e.name.toLowerCase().endsWith(".stl")});if(w.length>1)return n="Invalid upload: Multiple stl files found. This is currently not supported.",console.error(n,w),{error:n};if(1===w.length)return w[0];var P=e.filter(function(e){var t=e.name.toLowerCase();return t.endsWith(".ply")||t.endsWith(".splat")||t.endsWith(".spz")||t.endsWith(".ksplat")||t.endsWith(".sog")||t.endsWith(".sogs")});if(P.length>1)return n="Invalid upload: Multiple splat files found. Upload them as separate content items.",console.error(n,P.map(function(e){return e.path||e.name})),{error:n};if(1===P.length)return P[0];if(1===e.length&&!e[0].arrayBuffer&&e[0].path.toLowerCase().startsWith("http"))return e[0];var _=e.filter(function(e){return e.name.toLowerCase().endsWith("package.json")});if(1===_.length)return _[0];if(_.length>1)return n="Invalid upload: Multiple package.json files found. This is currently not supported.",console.error(n,_),{error:n};var j=e.filter(function(e){return e.name.toLowerCase().endsWith(".mtlx")});if(j.length>1)return n="Invalid upload: Multiple mtlx files found. This is currently not supported.",console.error(n,j),{error:n};if(1===j.length)return j[0];var E=e.filter(function(e){var t=e.name.toLowerCase();return Er(t)||Sr(t)||xr(t)});return E.length>1?(n="Invalid upload: Multiple HDRI files found. Upload them as separate content items.",console.error(n,E.map(function(e){return e.path||e.name})),{error:n}):1===E.length?t=E[0]:t||{error:"No supported file to upload found..."}}(s);if(null==l)return Promise.resolve({success:!1,error:"No entrypoint file found"});if("object"==typeof l&&"error"in l)return Promise.resolve({success:!1,error:l.error});"info"===u&&console.log("Entrypoint: "+l.name),t.entrypoint=l}return t.entrypoint&&!s.includes(t.entrypoint)&&s.push(t.entrypoint),Promise.resolve(function(e){try{var t,n=function(e){return t?e:{success:!0,vrm_count:o,gltf_count:i,glb_count:s}};if(e.length>5e3)return Promise.resolve({success:!1,error:"Too many files. Maximum filecount is 5000"});var r=0,o=0,i=0,s=0,a=e.length-1,u=function(e,t,n){for(var r;;){var o=e();if(Br(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Br(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Br(s)){r=2;break}}}var a=new Mr,u=Dr.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!Br(s))return void s.then(f).then(void 0,u);if(!(o=e())||Br(o)&&!o.v)return void Dr(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Br(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):Dr(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Dr(a,1,i)}}(function(){return!t&&a>=0},function(){return a--},function(){var n=e[a];if((r+=n.size)>1073741824){var u={success:!1,error:"Total file size exceeds limit of "+1024..toFixed(0)+" MB. Please reduce the size of your upload."};return t=1,u}var l,c=n.name.toLocaleLowerCase();if(".ds_store"!==c)return c.endsWith(".gltf")?i++:c.endsWith(".glb")?(l=c)&&zr.test(l)||s++:c.endsWith(".vrm")&&o++,function(){if(c.endsWith(".gltf"))return i+=1,console.log("Found glTF file "+n.name+". Will check if all dependencies are available\n",e),Promise.resolve(n.text()).then(function(r){var o,i=r.matchAll(/*#__PURE__*/$(/"uri"\s*:\s*"(.*?)"/g,{value:1}));if(i){var s=JSON.parse(r);if("2.0"!==s.asset.version)return console.warn("⚠ glTF version is not 2.0. This is currently not supported."),t=1,{success:!1,error:"glTF version "+s.asset.version+" is unsupported.Please use glTF 2.0."};for(var a,u=null==(o=n.path)?void 0:o.split("/"),l=u.splice(0,u.length-1).join("/"),c=L(i);!(a=c()).done;){var f,d=null==(f=a.value.groups)?void 0:f.value;if(d){var h=!1;if(d.startsWith("http://")||d.startsWith("https://")||d.startsWith("www.")){console.log("✅ Found remote dependency "+d+" ");break}if(d.startsWith("data:")){console.log("✅ Found embedded dependency "+d+" ");break}var p=(l+"/"+qr(d)).split("/").reduce(function(e,t){return"."===t||(".."===t?e.pop():null!=t&&t.length&&e.push(t)),e},[]).join("/");console.log('❓ Check if local dependency exists "'+p+'"');for(var m,v=L(e);!(m=v()).done;){var g=m.value;if(g.webkitRelativePath===p||g.name==p){h=!0,console.log("✅ Found dependency in name or webkit: "+g.name+" || "+g.webkitRelativePath+" ");break}if(g.path===p){h=!0,console.log("✅ Found dependency in path: "+g.path+" ");break}}if(!h)return console.warn("⚠ Missing dependency "+d,l),t=1,{success:!1,error:"Missing resource: "+d}}}}})}();e.splice(a,1)});return Promise.resolve(u&&u.then?u.then(n):n(u))}catch(e){return Promise.reject(e)}}(s)).then(function(r){var o,i,a,l,c,f;if("error"in r)return{success:!1,error:r.error||"Failed to validate files"};if(null!=(o=t.entrypoint)&&o.name.endsWith(".htm")||null!=(i=t.entrypoint)&&i.name.endsWith(".html")||null!=(a=t.entrypoint)&&a.name.endsWith(".html.gz")||null!=(l=t.entrypoint)&&l.name.endsWith(".html.br"))n||(n={}),n.type="deployment";else if(r.vrm_count>10)return{success:!1,error:"Multiple model files found - this is not supported for asset uploads. Please upload a single model file only."};return Promise.resolve(function(e,t){void 0===t&&(t={});try{var n,r=function(e){return n?e:{files:f,entrypoint:d}},o=t.raw,i=t.loglevel,s=void 0===i?"none":i,a=t.entrypoint,u=void 0===a?null:a,l=function(){var e;"none"!==s&&(e=console).log.apply(e,[].slice.call(arguments))};if(void 0!==o&&o)return"none"!==s&&console.warn("Raw upload - skipping gzip compression of files"),Promise.resolve({files:e,entrypoint:u});var c=new Set(e.map(so)),f=[],d=u,h=function(e,t,n){if("function"==typeof e[Xr]){var r,o,i,s=e[Xr]();if(function e(a){try{for(;!((r=s.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!Qr(a))return void a.then(e,i||(i=Yr.bind(null,o=new Zr,2)));a=a.v}o?Yr(o,1,a):o=a}catch(e){Yr(o||(o=new Zr),2,e)}}(),s.return){var a=function(e){try{r.done||s.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return eo(u,function(e){return t(u[e])},n)}(e,function(t){var r=so(t),o=t.name.toLowerCase();if(oo.some(function(e){return o.endsWith(e)})){var i,a=io.find(function(e){return c.has(""+r+e)});if(!a)return l("gZip compressing file: "+t.name),Promise.resolve(function(e){try{return Promise.resolve(import("./pako.esm-01431bd2.js")).then(function(t){return Promise.resolve(e.arrayBuffer()).then(function(n){var r=t.gzip(new Uint8Array(n)).buffer.slice(0);if(r.byteLength>51200&&r.byteLength>=n.byteLength){if(n.byteLength>0)return null}else if(!(r instanceof ArrayBuffer))return console.error("gzipCompress: Invalid ArrayBuffer"),{error:'Gzip compressing failed for "'+e.name+'" (unexpected result)'};return function(e,t,n){var r;void 0===n&&(n=void 0);var o=function(e,t,n){for(var r=0;;){var o=e.indexOf("\\",r);if(-1===o)break;r=o+1,e=e.replace("\\","/")}return e}(e).split("/").pop()||e,i=(null==(r=n)?void 0:r.type)||_r(t,e),s=new File([t],o,{type:i});return s.path=e,s}(("path"in e?e.path:e.name)+".gz",r,{type:"application/gzip"})})})}catch(e){return Promise.reject(e)}}(t).catch(function(e){return{error:"Error compressing "+t.name+": "+e.message}})).then(function(r){if(null===r)return"none"!==s&&console.error("Did not compress file: "+t.name),void f.push(t);if("error"in r)return n=1,{files:e,entrypoint:u,error:r.error};if(!r)return n=1,{files:e,entrypoint:u,error:"Failed to compress "+t.name};var o=u===t;f.push(r),o&&(d=r),l("gZip compressed file: "+t.name+" "+(o?"(entrypoint)":""))});l("Skipping gzip compression, using pre-compressed file: "+r+a),u===t&&(d=null!=(i=e.find(function(e){return so(e)===""+r+a}))?i:d)}else f.push(t)},function(){return n});return Promise.resolve(h&&h.then?h.then(r):r(h))}catch(e){return Promise.reject(e)}}(s,{raw:t.raw,loglevel:null!=(c=null==(f=n)?void 0:f.loglevel)?c:u,entrypoint:t.entrypoint})).then(function(r){var o,i,a,l,c,f,d,h,p;function m(r){var o;function i(){return Promise.resolve(fetch(v+Y.upload.request,F({},Q,{method:"POST",headers:y,body:JSON.stringify(w)})).catch(function(e){return"fetch failed"==e.message||"Failed to fetch"==e.message?"Network error. Make sure you are connected to the internet and "+v+" is reachable.":(console.error("Failed to begin upload\n",e),null)})).then(function(r){var o;function i(i){return o?i:Promise.resolve(r.json()).then(function(r){var o,i;function a(){var t;function o(o){var i;if(t)return o;function a(t){var n;if(i)return t;function o(){var e;function t(t){return e?t:("none"!=u&&console.log("Upload complete"),Promise.resolve(l.json()).then(function(e){return{success:!0,type:e.type,uploadSkipped:!1,id:e.id,content_id:e.content_id,url:e.url,edit_url:e.edit_url,filesUploaded:s.length,totalSize:c}}))}if(!l)return console.error("Failed to complete upload"),{success:!1,error:"Failed to complete upload"};var n=function(){if(!l.ok)return 524===l.status?(console.error("Failed to complete upload: Gateway Timeout"),e=1,{success:!1,error:"Failed to complete upload: Gateway Timeout"}):Promise.resolve(l.text().catch(function(){return""})).then(function(t){console.error("Failed to complete upload ("+l.status+"): "+t);var n=t?t.substring(0,300):"status "+l.status;return e=1,{success:!1,error:"Failed to complete upload: "+n}})}();return n&&n.then?n.then(t):t(n)}h=!0,console.log("Upload Done: All files uploaded to "+r.id);var a=F({},Z(e),{id:r.id});"none"!=u&&console.log("Completing upload - notify server");var l=null,f=0,d=function(e,t,n){for(var r;;){var o=e();if(Qr(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Qr(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Qr(s)){r=2;break}}}var a=new Zr,u=Yr.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!Qr(s))return void s.then(f).then(void 0,u);if(!(o=e())||Qr(o)&&!o.v)return void Yr(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Qr(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):Yr(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Yr(a,1,i)}}(function(){return!n&&f<5},function(){return f++},function(){return Promise.resolve(Fr(1e3*f)).then(function(){var e=AbortSignal.timeout(6e4+5e3*f);return Promise.resolve(fetch(v+Y.upload.done,F({},Q,{method:"POST",headers:a,signal:e})).catch(function(e){return console.error("Failed to complete upload ("+(f+1)+" / 5)",e.message),null})).then(function(e){var t,r;!0!==(null==(t=l=e)?void 0:t.ok)?l&&l.status>=400&&l.status<500?n=1:"none"!=u&&f<4&&console.warn("Failed to complete upload ("+((null==(r=l)?void 0:r.status)||"no status")+"): will retry in 1 second"):n=1})})});return d&&d.then?d.then(o):o()}var l=function(t){if(null!=(t=n)&&null!=(t=t.abort)&&t.aborted)return Promise.resolve(Mn({identifier:r.id,status:"canceled",status_message:"Upload aborted",error:"Upload aborted"},e)).then(function(){return i=1,{success:!1,error:"Upload aborted"}})}();return l&&l.then?l.then(a):a(l)}var i=function(){if(E)return Promise.resolve(Mn({identifier:r.id,status:"failed",error:"Failed to upload files"},e)).then(function(){return t=1,{success:!1,error:"Failed to upload files"}})}();return i&&i.then?i.then(o):o(i)}"debug"===u&&console.debug("BeginResponse",r);var l,c=s.reduce(function(e,t){return e+t.size},0);if("exists"===r.type)return"none"!=u&&console.log("Upload already exists",r.id),null!=(l=n)&&l.onStart&&n.onStart(r.id,r.content_id),{success:!0,uploadSkipped:!0,id:r.id,type:r.job_type,content_id:r.content_id,filesUploaded:s.length,totalSize:c,url:r.url,edit_url:r.edit_url};var f=t.entrypoint.webkitRelativePath||t.entrypoint.name,d=0;null==(o=n)||null==(o=o.abort)||o.addEventListener("abort",function(){try{return console.log("Upload aborted: Cancelling upload"),Promise.resolve(fetch(v+Y.upload.cancel,F({},Q,{method:"POST",headers:{authorization:g,id:r.id}}))).then(function(){})}catch(e){return Promise.reject(e)}});var h=!1;function p(t,n,o){if(void 0===o&&(o=!1),!o&&Date.now()-m<1e3)return!1;if(!h||"completed"===n){m=Date.now();var i=Math.floor(d/c*100);return"debug"===u&&console.log("SET STATUS: "+n,t,i),Mn({identifier:r.id,status:n,status_message:t,progress:i},e),!0}"none"!=u&&console.warn("Invalid status update...")}var m=Date.now();null!=(i=n)&&i.onStart&&n.onStart(r.id,r.content_id);var y=Date.now(),w=new Gr(s.length,c/1024/1024),_=new Array,j=function(e){for(var t,n=0,r=L(e);!(t=r()).done;){var o=t.value;Number.isFinite(o)&&o>=0&&(n=Math.max(n,o))}return n>=ar?2:n>=16777216?4:10}(b.files.map(function(e){return e.content_length}));"debug"===u&&console.debug("Upload file concurrency: "+j);var E=!1,S=[].concat(s),x=s.length,T=function(e,t){void 0===t&&(t=25e3);var n=!1,r=setInterval(function(){if(!n)try{var e=p("Upload in progress","running",!0);e&&"function"==typeof e.then&&e.catch(function(e){console.warn("[upload] heartbeat tick failed:",e)})}catch(e){console.warn("[upload] heartbeat tick threw:",e)}},t);return r&&"function"==typeof r.unref&&r.unref(),function(){n||(n=!0,clearInterval(r))}}(),k=no(function(){function o(){var e;return null!=(e=n)&&null!=(e=e.abort)&&e.aborted?console.debug("Upload aborted"):E&&console.debug("Upload failed"),Promise.resolve(Promise.all(_).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),E=!0)})).then(function(){})}var i=eo(S,function(o){var i;if(!(E||null!=(i=n)&&null!=(i=i.abort)&&i.aborted)){if(_.length<j){console.debug("Uploading file "+o+"/"+s.length+": "+s[o].name);var a=0,l=0,h=b.files[o],m=h.filename,v=P[o],g=h.content_length,S=h.content_type,T=s[o],k=T.name.endsWith(".gz")?"gzip":T.name.endsWith(".br")?"br":void 0,O=function(e){try{if(e.fileSize>=ar)return function(e){try{var t=function(e,t,n){try{return Promise.resolve(fetch(e,F({},Q,{method:"POST",headers:t,body:JSON.stringify(n)}))).then(function(t){function n(e){return t.json()}var r=function(){if(!t.ok)return Promise.resolve(t.text().catch(function(){return""})).then(function(n){throw new Error(e+" "+t.status+": "+n)})}();return r&&r.then?r.then(n):n()})}catch(e){return Promise.reject(e)}},n=e.uploadId,r=e.entrypointPath,o=e.file,i=e.fileName,s=e.fileMd5,a=e.fileType,u=e.content_encoding,l=e.fileSize,c=e.args,f=e.options,d=e.onProgress,h=e.partSize,p=e.concurrency,m=e.maxRetries,v=e.retryDelayMs,g=e.putPart,y=c.baseUrl,b=function(){return F({},Z(c),{"Content-Type":"application/json",org:c.org,job_id:n})},w=F({},b(),{filesize:l.toString()}),P=JSON.stringify({filename:i,entrypoint:r,"content-type":a,"content-md5":s,"content-encoding":u,output_index:0});return Promise.resolve(function(e){var t=e.size,n=e.slice,r=e.partSize,o=void 0===r?sr:r,i=e.concurrency,s=void 0===i?4:i,a=e.maxRetries,u=void 0===a?5:a,l=e.retryDelayMs,c=void 0===l?1e3:l,f=e.createUpload,d=e.getPartUrls,h=e.putPart,p=e.completeUpload,m=e.abortUpload,v=e.onProgress,g=e.signal,y=e.checkCancelled,b=function(){try{var e;if(g&&g.aborted)return Promise.resolve(!0);var t=function(){if(y)return er(function(){return Promise.resolve(y()).then(function(t){return e=1,!!t})},function(){return e=1,!1})}();return Promise.resolve(t&&t.then?t.then(function(t){return!!e&&t}):!!e&&t)}catch(e){return Promise.reject(e)}};return Promise.resolve(b()).then(function(e){if(e)throw new Error("Upload aborted");var r=function(e,t){if(void 0===t&&(t=sr),!Number.isFinite(e)||e<=0)return[];for(var n=Math.max(t,5242880,Math.ceil(e/1e4)),r=[],o=0,i=1;o<e;){var s=Math.min(o+n,e);r.push({partNumber:i,start:o,end:s,size:s-o}),o=s,i++}return r}(t,o);if(0===r.length)throw new Error("Nothing to upload (size <= 0)");return Promise.resolve(f()).then(function(e){var t=e.upload_id,o=e.key;return Promise.resolve(d(t,o,r.map(function(e){return e.partNumber}))).then(function(e){var i=new Map(e.map(function(e){return[e.part_number,e.url]})),a=[],l=0,f=null,d=[].concat(r),y=Math.max(1,Math.min(s,r.length));return Promise.resolve(Promise.all(Array.from({length:y},function(){return function(){try{var e;return Promise.resolve(function(e,t,n){for(var r;;){var o=e();if(rr(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!rr(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!rr(s)){r=2;break}}}var a=new nr,u=tr.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!rr(s))return void s.then(f).then(void 0,u);if(!(o=e())||rr(o)&&!o.v)return void tr(a,1,i);if(o.then)return void o.then(c).then(void 0,u);rr(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):tr(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):tr(a,1,i)}}(function(){return!e&&d.length>0},void 0,function(){function t(t){if(t)e=1;else{var r=d.shift();if(r){var o=er(function(){return Promise.resolve(function(e){try{var t=i.get(e.partNumber);if(!t)throw new Error("Missing presigned url for part "+e.partNumber);var r=!1;return Promise.resolve(Hn(function(){return Promise.resolve(b()).then(function(o){if(o)throw r=!0,new Error("Upload aborted");return er(function(){var r=n(e.start,e.end);return Promise.resolve(h({url:t,payload:r,partNumber:e.partNumber,size:e.size,signal:g})).then(function(t){if(!t)throw new Error("No ETag returned for part "+e.partNumber);return t})},function(e){return Promise.resolve(b()).then(function(t){throw t&&(r=!0),e})})})},F({maxAttempts:u+1,baseMs:c,isRetryable:function(e){return!r&&Zn(e)}},c>0?{}:{sleep:function(){return Promise.resolve()}}))).then(function(t){if(!t.ok)throw t.error||new Error("Failed to upload part "+e.partNumber);a.push({part_number:e.partNumber,etag:t.value}),l+=e.size,v&&v(l)})}catch(e){return Promise.reject(e)}}(r)).then(function(){})},function(t){f=f||t,e=1});return o&&o.then?o.then(function(){}):void 0}e=1}}return f?t(f):Promise.resolve(b()).then(t)}))}catch(e){return Promise.reject(e)}}()}))).then(function(){function e(e){function n(e){return a.sort(function(e,t){return e.part_number-t.part_number}),Promise.resolve(p(t,o,a)).then(function(){return{ok:!0,key:o,upload_id:t,parts:r.length}})}var i=function(){if(e)return Promise.resolve(m(t,o).catch(function(){})).then(function(){throw f||new Error("Upload aborted")})}();return i&&i.then?i.then(n):n()}return f?e(f):Promise.resolve(b()).then(e)})})})})}({size:l,partSize:h,concurrency:p,maxRetries:m,retryDelayMs:v,slice:function(e,t){return o.slice(e,t)},signal:null==f?void 0:f.abort,onProgress:function(e){d&&d({loaded:e,total:l,progress:l?e/l:0})},createUpload:function(){try{return Promise.resolve(fetch(y+Y.upload.multipart_create,F({},Q,{method:"POST",headers:w,body:P}))).then(function(e){function t(t){return Promise.resolve(e.json()).then(function(e){return{upload_id:e.upload_id,key:e.key}})}var n=function(){if(!e.ok)return Promise.resolve(e.text().catch(function(){return""})).then(function(t){throw new Error("multipart/create "+e.status+": "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},getPartUrls:function(e,n,r){try{return Promise.resolve(t(y+Y.upload.multipart_part_urls,b(),{key:n,upload_id:e,part_numbers:r})).then(function(e){return e.urls})}catch(e){return Promise.reject(e)}},putPart:g||function(e){return function(e){var t=e.url,n=e.payload,r=e.partNumber,o=e.contentType,i=e.signal;try{var s=function(e){var s=Pr(e),a=i,u=new AbortController,l=!1,c=function(){return u.abort()};a&&(a.aborted?u.abort():a.addEventListener("abort",c,{once:!0}));var f=fo(co,function(){l=!0,u.abort()});return f.reset(),no(function(){return to(function(){var e=Fn.put;return Promise.resolve(Vr()).then(function(r){return Promise.resolve(e.call(Fn,t,n,F({},Q,r,{withCredentials:!1,signal:u.signal,headers:{"Content-Type":o,"Content-MD5":s},onUploadProgress:function(){return f.reset()}}))).then(function(e){var t,n;if(200!==e.status)throw new Error(lo({response:e}));var r=(null==(t=e.headers)?void 0:t.etag)||(null==(n=e.headers)?void 0:n.ETag);if(!r)throw new Error("part PUT returned no ETag (is the bucket's CORS exposeHeaders:etag set?)");return r})})},function(e){if(null!=a&&a.aborted)throw e;if(l)throw new Error("Part "+r+" stalled: no progress for 120s");throw new Error(lo(e))})},function(e,t){if(f.cancel(),a&&a.removeEventListener("abort",c),e)throw t;return t})},a=n instanceof Uint8Array;return Promise.resolve(a?s(new Uint8Array(n).buffer):Promise.resolve(n.arrayBuffer()).then(s))}catch(e){return Promise.reject(e)}}({url:e.url,payload:e.payload,partNumber:e.partNumber,signal:e.signal,contentType:a})},completeUpload:function(e,n,r){try{return t(y+Y.upload.multipart_complete,b(),{key:n,upload_id:e,parts:r})}catch(e){return Promise.reject(e)}},abortUpload:function(e,t){try{return Promise.resolve(fetch(y+Y.upload.multipart_abort,F({},Q,{method:"POST",headers:b(),body:JSON.stringify({key:t,upload_id:e})})).catch(function(){})).then(function(){})}catch(e){return Promise.reject(e)}}})).then(function(){return!0})}catch(e){return Promise.reject(e)}}(e);var t=e.uploadId,n=e.uploadRequestPUTUrl,r=e.entrypointPath,o=e.file,i=e.fileName,s=e.fileBuffer,a=e.fileMd5,u=e.fileSize,l=e.fileType,c=e.content_encoding,f=e.fileIndex,d=e.fileNumber,h=e.fileCount,p=e.loglevel,m=e.args,v=e.options,g=e.experimental;"info"===p&&console.log('Uploading file "'+o.name+'" type='+l+" ("+u+") "+o.type+" with hash "+a);var y=F({},Z(m),{"Content-Type":"application/json",org:m.org,job_id:t,filesize:u.toString(),progress:(f/h*100).toFixed(0)}),b={filename:i,entrypoint:r,"content-type":l,"content-md5":a,"content-encoding":c,output_index:0};"debug"===p&&console.debug("Requesting presigned URL with headers",y);var w=JSON.stringify(b),P=null,_="";return Promise.resolve(Hn(function(){try{var e;if(null!=v&&null!=(e=v.abort)&&e.aborted)throw new zn("Upload aborted");return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:y,body:w}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text().catch(function(){return""})).then(function(t){throw _=t,{response:{status:e.status,statusText:e.statusText,data:t}}})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},{baseMs:500,onRetry:function(e){var t=e.attempt,n=e.waitMs;console.warn('Failed to get presigned url for "'+i+'" "'+l+'": '+lo(e.error)+"\n→ Retry #"+t+" in "+n+"ms")}})).then(function(n){if(n.ok)P=n.value;else if(n.error instanceof zn)throw n.error;if(null==P){var r=_||lo(n.error);throw new Error('Failed to get presigned url for "'+i+'" "'+l+'" \n'+r)}var o=P.presigned_url,f=!1,y=null,b=[],w=0;return Promise.resolve(Hn(function(t){try{var n;if(null!=v&&null!=(n=v.abort)&&n.aborted)throw new zn("Upload aborted");var r={"Content-Type":l,"Content-MD5":a};g&&(r["Content-Length"]=u.toString()),c&&(r["Content-Encoding"]=c),1===t&&"none"!=p&&console.log("Uploading file "+d+"/"+h+": "+i),"debug"===p&&console.debug("PUT with headers",r);var f=new AbortController,m=!1,w=function(){return f.abort()};null!=v&&v.abort&&(v.abort.aborted?f.abort():v.abort.addEventListener("abort",w,{once:!0}));var P=fo(co,function(){m=!0,f.abort()});return P.reset(),Promise.resolve(no(function(){return to(function(){var t=Fn.put;return Promise.resolve(Vr()).then(function(n){return Promise.resolve(t.call(Fn,o,s,F({},Q,n,{withCredentials:!1,signal:f.signal,headers:r,onUploadProgress:function(t){P.reset(),e.onProgress(t)}}))).then(function(e){if(200!==e.status)throw{response:e};return e})})},function(e){var t;if(null!=v&&null!=(t=v.abort)&&t.aborted)throw new zn("Upload aborted");if(m)throw b.push(y="stalled: no upload progress for 120s"),"none"!==p&&console.error("Upload stalled (PUT) ("+d+", "+i+") after 120s with no progress"),new Error(y);throw y=lo(e),b.push(y),e instanceof zn||("none"!==p&&console.error("Failed to upload file (PUT) ("+d+", "+i+') "'+y+'"'),"debug"===p&&(console.log(r,{fileSize:u}),e.response?console.debug(e.response):console.debug(e))),e})},function(e,t){if(P.cancel(),null!=v&&v.abort&&v.abort.removeEventListener("abort",w),e)throw t;return t}))}catch(e){return Promise.reject(e)}},{onRetry:function(e){"none"!==p&&console.log("Retry PUT #"+e.attempt+" for file "+i+" in "+e.waitMs+"ms")}})).then(function(e){if(w=e.attempts,e.ok)f=!0,"info"===p&&console.log("Uploaded file "+d+"/"+h+' "'+i+'" ('+l+", "+Tr(u)+")");else if(e.error instanceof zn)throw e.error;var n=function(){if(!f){var e,n=null!=(e=function(e){if(!Array.isArray(e))return null;for(var t,n=[],r=L(e);!(t=r()).done;){var o=t.value;if("string"==typeof o){var i=o.trim();i&&!n.includes(i)&&n.push(i)}}return n.length?n.join("; "):null}(b))?e:y,r=function(e,t,n){var r="string"==typeof t?t.trim():"",o="number"==typeof n&&n>1?" after "+n+" attempts":"";return r?"Failed to upload file "+e+o+": "+(r.length>400?r.slice(0,400)+"…":r):"Failed to upload file "+e+o}(i,n,w);return console.error(r),Promise.resolve(Mn({identifier:t,status:"failed",status_message:(o=r,s="string"==typeof o?o:String(null!=o?o:""),s.length<=255?s:s.slice(0,254)+"…"),error:"Failed to upload file "+i},m)).then(function(){throw new Error(r)})}var o,s}();return!n||!n.then||n.then(function(e){return!0})})})}catch(e){return Promise.reject(e)}}({uploadId:r.id,uploadRequestPUTUrl:r.request_put_url,entrypointPath:f,file:s[o],fileName:m,fileMd5:h.content_md5,fileBuffer:v,fileType:S,content_encoding:k,fileSize:g,fileIndex:o,fileNumber:o+1,fileCount:x,loglevel:u,experimental:t.experimental,args:e,options:n,onProgress:function(e){var t,r=e.progress||0,i=(a=s[o].size*r)-l;if(l=a,d+=i,null!=(t=n)&&t.progress){var u=d/c,f=s.length,h=s[o].size,v=(Date.now()-y)/1e3,g=w.updateProgress(d/1024/1024);n.progress({uploadedBytes:d,totalBytes:c,progress01:u,fileName:s[o].name,fileSize:h,fileProgress01:r,fileIndex:o,totalFiles:f,estimatedTimeLeftDisplay:g.estimatedTimeRemainingString,estimatedTimeLeft:g.estimatedTimeRemaining,elapsedTime:v}),p("Uploading file "+(o+1)+"/"+f+" ("+m+"): "+(100*r).toFixed(0)+"% of "+Tr(c)+". Finished in approx. "+g.estimatedTimeRemainingString,"running",!1)}}}).then(function(e){if(!0!==e)return e;for(var t=_.length-1;t>=0;t--)_[t]===O&&_.splice(t,1);p("Uploaded "+Tr(d)+" of "+Tr(c)+" for "+s[o].name,"running")}).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),E=!0)});_.push(O)}var R=function(){if(_.length>=j)return Promise.resolve(Promise.race(_)).then(function(){})}();return R&&R.then?R.then(function(){}):void 0}});return i&&i.then?i.then(o):o()},function(e,t){if(T(),e)throw t;return t});return k&&k.then?k.then(a):a()})}if(null===r||"string"==typeof r)return{success:!1,error:r||"Failed to begin upload"};var a=function(){if(!r.ok)return Promise.resolve(r.text()).then(function(e){if(e.startsWith("{")){var t=JSON.parse(e);if("error"in t)return o=1,{success:!1,status:r.status,error:t.error}}return"none"!=u&&console.error("Failed to begin upload\n",r.status,e),o=1,{success:!1,status:r.status,error:""+e}})}();return a&&a.then?a.then(i):i(a)})}if("deployment"!==(null==(o=n)?void 0:o.type)){var a,l=t.entrypoint.name.toLowerCase();if(l.endsWith(".glb")||l.endsWith(".gltf"))try{var c,f=P[s.indexOf(t.entrypoint)],d=l.endsWith(".glb")?function(e){var t=e instanceof Uint8Array?e:new Uint8Array(e);if(t.byteLength<20)throw new Error("Buffer too small to be a GLB");var n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(1179937895!==n.getUint32(0,!0))throw new Error("Not a GLB (magic mismatch)");var r=n.getUint32(12,!0);if(1313821514!==n.getUint32(16,!0))throw new Error("First chunk is not JSON");var o=20+r;if(o>t.byteLength)throw new Error("JSON chunk exceeds buffer length");var i=t.subarray(20,o),s=(new TextDecoder).decode(i);return JSON.parse(s)}(f):JSON.parse((new TextDecoder).decode(f));a=function(e){return function(e){if(!e)return!1;var t=!e.nodes||0===e.nodes.length,n=!e.meshes||0===e.meshes.length,r=Array.isArray(e.materials)&&1===e.materials.length;return t&&n&&r}(e)?"material":"3d-asset"}(d),"string"==typeof(null==(c=d.asset)?void 0:c.version)&&d.asset.version.startsWith("2.")&&(b.technical_metadata=function(e){var t=Or(e.asset),n=/^(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})$/;if("string"!=typeof t.version||!n.test(t.version)||2!==Number(t.version.split(".")[0]))throw new Error("Metadata collection requires glTF 2.0-compatible asset versions");if(void 0!==t.minVersion&&("string"!=typeof t.minVersion||!n.test(t.minVersion)||"2.0"!==t.minVersion))throw new Error("Metadata collection supports a minimum glTF version of 2.0");var r=Rr(e.nodes),o=Rr(e.meshes),i=Rr(e.accessors),s=Rr(e.scenes),a=Rr(e.animations),u=Rr(e.skins),l=new Set;"2.0"!==t.version&&l.add("newer-gltf-version:"+t.version);var c=function(e){var t=Ur(e);return Or(null===t?void 0:i[t])};function f(e){var t=Rr(Or(e).primitives),n={meshes:1,primitives:0,vertices:0,triangles:0};n.primitives=t.length;for(var r,o=L(t);!(r=o()).done;){var i,s=Or(r.value),a=Ur(c(Or(s.attributes).POSITION).count),u=void 0===s.indices?a:Ur(c(s.indices).count),f=null!=(i=s.mode)?i:4,d="number"==typeof f&&f>=0&&f<=3?0:null===u?null:4===f?Math.floor(u/3):5===f||6===f?Math.max(0,u-2):null;null!==a&&null!==d||l.add("geometry-counts-unavailable"),Wr(n,{meshes:0,primitives:0,vertices:a,triangles:d})}return n}for(var d,h={meshes:0,primitives:0,vertices:0,triangles:0},p=L(o);!(d=p()).done;)Wr(h,f(d.value));for(var m=s.map(function(e,t){var n=Or(e),i=Rr(n.nodes),s={meshes:0,primitives:0,vertices:0,triangles:0},a=[Infinity,Infinity,Infinity],u=[-Infinity,-Infinity,-Infinity],d=!1,h=!1,p=!1;function m(e,t,n){var i=Ur(e);if(null===i||!r[i]||n.has(i))return l.add("invalid-scene-hierarchy"),void(d=!0);var v,g,y=Or(r[i]),b=(v=t,g=function(e){var t,n;if(Array.isArray(e.matrix)&&16===e.matrix.length&&e.matrix.every(function(e){return"number"==typeof e&&Number.isFinite(e)}))return[].concat(e.matrix);var r=null!=(t=Cr(e.translation))?t:[0,0,0],o=r[0],i=r[1],s=r[2],a=null!=(n=Cr(e.scale))?n:[1,1,1],u=a[0],l=a[1],c=a[2],f=e.rotation,d=Array.isArray(f)&&4===f.length&&f.every(function(e){return"number"==typeof e&&Number.isFinite(e)})?f:[0,0,0,1],h=d[0],p=d[1],m=d[2],v=d[3];return[(1-2*(p*p+m*m))*u,2*(h*p+m*v)*u,2*(h*m-p*v)*u,0,2*(h*p-m*v)*l,(1-2*(h*h+m*m))*l,2*(p*m+h*v)*l,0,2*(h*m+p*v)*c,2*(p*m-h*v)*c,(1-2*(h*h+p*p))*c,0,o,i,s,1]}(y),Array.from({length:16},function(e,t){var n=t%4,r=Math.floor(t/4);return v[n]*g[4*r]+v[n+4]*g[4*r+1]+v[n+8]*g[4*r+2]+v[n+12]*g[4*r+3]})),w=new Set(n);if(w.add(i),void 0!==y.mesh){var P=Ur(y.mesh),_=null===P?void 0:o[P];if(_){Wr(s,f(_));for(var j,E=L(Rr(Or(_).primitives));!(j=E()).done;){var S=Or(j.value),x=c(Or(S.attributes).POSITION),T=Cr(x.min),k=Cr(x.max);if(T&&k){h||(h=void 0!==y.skin||Rr(S.targets).length>0),p=!0;for(var O=0;O<8;O++)for(var R=1&O?k[0]:T[0],U=2&O?k[1]:T[1],C=4&O?k[2]:T[2],A=0;A<3;A++){var W=b[A]*R+b[A+4]*U+b[A+8]*C+b[A+12];a[A]=Math.min(a[A],W),u[A]=Math.max(u[A],W)}}else d=!0,l.add("bounds-unavailable")}}else l.add("missing-mesh"),d=!0}for(var N,I=L(Rr(y.children));!(N=I()).done;)m(N.value,b,w)}for(var v,g=L(i);!(v=g()).done;)m(v.value,Nr,new Set);var y=null;if(p&&!d){var b=[(u[0]+a[0])/2,(u[1]+a[1])/2,(u[2]+a[2])/2];y={min:a,max:u,dimensions:[u[0]-a[0],u[1]-a[1],u[2]-a[2]],center:b,originOffset:[-b[0],-b[1],-b[2]],pose:"default",approximate:h}}return F({index:t},"string"==typeof n.name?{name:n.name}:{},{rootCount:i.length,geometry:s,bounds:y})}),v=a.map(function(e,t){for(var n,r=Or(e),o=Rr(r.samplers),i=Infinity,s=-Infinity,a=0===o.length,u=L(o);!(n=u()).done;){var f=c(Or(n.value).input),d=Rr(f.min)[0],h=Rr(f.max)[0];"number"!=typeof d||"number"!=typeof h||!Number.isFinite(d)||!Number.isFinite(h)||h<d?a=!0:(i=Math.min(i,d),s=Math.max(s,h))}return a&&l.add("animation-duration-unavailable"),F({index:t},"string"==typeof r.name?{name:r.name}:{},{duration:a?null:s-i,trackCount:Rr(r.channels).length})}),g=Or(t.extras),y={},b=0,w=["author","license","source","title"];b<w.length;b++){var P=w[b];"string"==typeof g[P]&&(y[P]=g[P])}var _=Ur(e.scene);null!==_&&_>=s.length&&l.add("invalid-default-scene");for(var j,E=0,S=L(o);!(j=S()).done;)for(var x,T=L(Rr(Or(j.value).primitives));!(x=T()).done;)E+=Rr(Or(x.value).targets).length;return{schemaVersion:1,collectorVersion:4,status:l.size?"partial":"complete",issues:[].concat(l),asset:F({version:t.version},"string"==typeof t.minVersion?{minVersion:t.minVersion}:{},"string"==typeof t.generator?{generator:t.generator}:{},"string"==typeof t.copyright?{copyright:t.copyright}:{},{attribution:y}),sceneCount:s.length,defaultSceneIndex:null!==_&&_<s.length?_:null,scenes:m,geometry:h,resourceUsage:Lr(e),materialCount:Rr(e.materials).length,animationCount:a.length,animations:v,skinCount:u.length,jointCount:new Set(u.flatMap(function(e){return Rr(Or(e).joints)})).size,morphTargetCount:E,textureCount:Rr(e.textures).length,imageCount:Rr(e.images).length,materialVariantCount:Rr(Or(Or(e.extensions).KHR_materials_variants).variants).length,extensionsUsed:Ar(e.extensionsUsed),extensionsRequired:Ar(e.extensionsRequired),loading:Ir(e),unit:"meter"}}(d))}catch(e){return{success:!1,error:'Failed to inspect "'+t.entrypoint.name+'": '+e.message}}else l.endsWith(".mtlx")?a="material":(Er(l)||Sr(l)||xr(l))&&(a="hdri");if(a){var h;if(null!=(h=n)&&h.content_type&&n.content_type!==a)return{success:!1,error:'Content type mismatch: "'+t.entrypoint.name+'" contains "'+a+'" but "'+n.content_type+'" was requested.'};b.content_type=a}}var p=to(function(){return Promise.resolve(function(e){try{var t,n=function(e){var n,o,i,s,a;return t?e:null!=(n=null!=(o=null!=(i=null!=(s=null!=(a=function(e){if(e.length<24)return null;if(137!==e[0]||80!==e[1]||78!==e[2]||71!==e[3])return null;if(13!==e[4]||10!==e[5]||26!==e[6]||10!==e[7])return null;var t=new DataView(e.buffer,e.byteOffset),n=t.getUint32(16,!1),r=t.getUint32(20,!1);return n&&r?{width:n,height:r}:null}(r))?a:function(e){if(e.length<28)return null;for(var t=[171,75,84,88,32,50,48,187,13,10,26,10],n=0;n<t.length;n++)if(e[n]!==t[n])return null;var r=new DataView(e.buffer,e.byteOffset),o=r.getUint32(20,!0),i=r.getUint32(24,!0);return o&&i?{width:o,height:i}:null}(r))?s:function(e){if(e.length<16)return null;if(118!==e[0]||47!==e[1]||49!==e[2]||1!==e[3])return null;for(var t=new DataView(e.buffer,e.byteOffset),n=8;n<e.length;){var r=kr(e,n);if(null===r)return null;if(0===r.length)return null;var o=kr(e,n+=r.length+1);if(null===o)return null;if((n+=o.length+1)+4>e.length)return null;var i=t.getInt32(n,!0);if(n+=4,i<0||n+i>e.length)return null;if("dataWindow"===r&&"box2i"===o&&16===i){var s=t.getInt32(n,!0),a=t.getInt32(n+4,!0),u=t.getInt32(n+8,!0)-s+1,l=t.getInt32(n+12,!0)-a+1;return u<=0||l<=0?null:{width:u,height:l}}n+=i}return null}(r))?i:function(e){if(e.length<30)return null;if(82!==e[0]||73!==e[1]||70!==e[2]||70!==e[3])return null;if(87!==e[8]||69!==e[9]||66!==e[10]||80!==e[11])return null;var t=String.fromCharCode(e[12],e[13],e[14],e[15]);if("VP8 "===t){var n=16383&(e[26]|e[27]<<8),r=16383&(e[28]|e[29]<<8);return n&&r?{width:n,height:r}:null}return"VP8L"===t?47!==e[20]?null:{width:1+(16383&(e[21]|e[22]<<8)),height:1+(16383&(e[22]>>6|e[23]<<2|(15&e[24])<<10))}:"VP8X"===t?{width:1+(e[24]|e[25]<<8|e[26]<<16),height:1+(e[27]|e[28]<<8|e[29]<<16)}:null}(r))?o:function(e){if(e.length<4)return null;if(255!==e[0]||216!==e[1])return null;for(var t=2;t<e.length-8;){for(;t<e.length&&255===e[t];)t++;if(t>=e.length)return null;var n=e[t++];if(!(1===n||n>=208&&n<=217)){if(t+2>e.length)return null;var r=e[t]<<8|e[t+1];if(r<2||t+r>e.length)return null;if(n>=192&&n<=207&&196!==n&&200!==n&&204!==n){if(t+7>e.length)return null;var o=e[t+3]<<8|e[t+4],i=e[t+5]<<8|e[t+6];return i&&o?{width:i,height:o}:null}t+=r}}return null}(r))?n:function(e){if(e.length<10)return null;if(35!==e[0]||63!==e[1])return null;var t=new TextDecoder("latin1").decode(e.subarray(0,Math.min(e.length,4096))).match(/[+-]Y\s+(\d+)\s+[+-]X\s+(\d+)/);if(!t)return null;var n=parseInt(t[1],10),r=parseInt(t[2],10);return r&&n?{width:r,height:n}:null}(r)};if(!e||"function"!=typeof e.slice||"number"!=typeof e.size)return Promise.resolve(null);var r,o=Math.min(e.size,65536);if(o<=0)return Promise.resolve(null);var i=function(t,n){try{var i=Promise.resolve(e.slice(0,o).arrayBuffer()).then(function(e){r=new Uint8Array(e)})}catch(e){return n()}return i&&i.then?i.then(void 0,n):i}(0,function(){return t=1,null});return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}}(t.entrypoint)).then(function(e){e&&(b.width=e.width,b.height=e.height)})},function(e){"debug"===u&&console.warn("readImageResolution failed; uploading without dimensions",e)});return p&&p.then?p.then(i):i()}if(r.error)return{success:!1,error:r.error,status:500};t.files=s=r.files,t.entrypoint=r.entrypoint,s.sort(function(e,t){return e.name.includes(".needle")&&!t.name.includes(".needle")?-1:!e.name.includes(".needle")&&t.name.includes(".needle")?1:0});var v=e.baseUrl,g="Bearer "+e.authToken,y=F({},Z(e),{triggered_by:t.triggered_by,filename:""+encodeURIComponent(t.entrypoint.name),"total-files":s.length.toString(),"total-files-size":s.reduce(function(e,t){return e+t.size},0).toString()});null!=(o=n)&&o.content_id&&(y.content_id=n.content_id),null!=(i=n)&&i.type&&(y.type=n.type),null!=(a=n)&&a.name&&(y.name=encodeURIComponent(n.name)),null!=(l=n)&&l.parent_job_id&&(y.parent_job_id=n.parent_job_id);var b={entrypoint:(null==(c=t.entrypoint)?void 0:c.path)||(null==(f=t.entrypoint)?void 0:f.name),files:[]};null!=(d=n)&&d.content_type&&(b.content_type=n.content_type);var w=F({outputs:[b]},t.metadata?{metadata:t.metadata}:{},!1===(null==(h=n)?void 0:h.optimizations)?{optimizations:!1}:{},!0===(null==(p=n)?void 0:p.verify)?{verify:!0}:{}),P=[],_=eo(s,function(e){var t,r=s[e],o=r.path||r.webkitRelativePath||r.name;if(null!=(t=o)&&t.includes(":"))throw new Error("Invalid filename: "+o);return Promise.resolve(r.arrayBuffer()).then(function(t){var i,s,a,u,l,c=r.size,f=r.type;if(null!=(i=f)&&i.length&&"unknown"!==f.toLowerCase()||(f=_r(t,o)),"deployment"===(null==(s=n)?void 0:s.type)){var d=(u=f,l=(a=o).toLowerCase(),"application/gzip"===u||"application/brotli"===u?(l.endsWith(".html.gz")||l.endsWith(".html.br")?(u="text/html",a=a.substring(0,a.length-3)):l.endsWith(".js.gz")||l.endsWith(".js.br")||l.endsWith(".mjs.gz")||l.endsWith(".mjs.br")||l.endsWith(".cjs.gz")||l.endsWith(".cjs.br")?(u="application/javascript",a=a.substring(0,a.length-3)):l.endsWith(".css.gz")||l.endsWith(".css.br")?(u="text/css",a=a.substring(0,a.length-3)):l.endsWith(".json.gz")||l.endsWith(".json.br")?(u="text/json",a=a.substring(0,a.length-3)):l.endsWith(".txt.gz")||l.endsWith(".txt.br")?(u="text/plain",a=a.substring(0,a.length-3)):l.endsWith(".wasm.gz")||l.endsWith(".wasm.br")?(u="application/wasm",a=a.substring(0,a.length-3)):l.endsWith(".bin.gz")||l.endsWith(".bin.br")?(u="application/octet-stream",a=a.substring(0,a.length-3)):l.endsWith(".png.gz")||l.endsWith(".png.br")?(u="image/png",a=a.substring(0,a.length-3)):l.endsWith(".jpg.gz")||l.endsWith(".jpg.br")||l.endsWith(".jpeg.gz")||l.endsWith(".jpeg.br")?(u="image/jpeg",a=a.substring(0,a.length-3)):l.endsWith(".gif.gz")||l.endsWith(".gif.br")?(u="image/gif",a=a.substring(0,a.length-3)):l.endsWith(".webp.gz")||l.endsWith(".webp.br")?(u="image/webp",a=a.substring(0,a.length-3)):l.endsWith(".svg.gz")||l.endsWith(".svg.br")?(u="image/svg+xml",a=a.substring(0,a.length-3)):l.endsWith(".xml.gz")||l.endsWith(".xml.br")?(u="application/xml",a=a.substring(0,a.length-3)):l.endsWith(".ico.gz")||l.endsWith(".ico.br")?(u="image/x-icon",a=a.substring(0,a.length-3)):l.endsWith(".avif.gz")||l.endsWith(".avif.br")?(u="image/avif",a=a.substring(0,a.length-3)):l.endsWith(".bmp.gz")||l.endsWith(".bmp.br")?(u="image/bmp",a=a.substring(0,a.length-3)):l.endsWith(".tiff.gz")||l.endsWith(".tiff.br")||l.endsWith(".tif.gz")||l.endsWith(".tif.br")?(u="image/tiff",a=a.substring(0,a.length-3)):l.endsWith(".hdr.gz")||l.endsWith(".hdr.br")?(u="image/vnd.radiance",a=a.substring(0,a.length-3)):l.endsWith(".exr.gz")||l.endsWith(".exr.br")?(u="image/x-exr",a=a.substring(0,a.length-3)):l.endsWith(".ktx2.gz")||l.endsWith(".ktx2.br")?(u="image/ktx2",a=a.substring(0,a.length-3)):l.endsWith(".ktx.gz")||l.endsWith(".ktx.br")?(u="image/ktx",a=a.substring(0,a.length-3)):l.endsWith(".dds.gz")||l.endsWith(".dds.br")?(u="image/vnd-ms.dds",a=a.substring(0,a.length-3)):l.endsWith(".webm.gz")||l.endsWith(".webm.br")?(u="video/webm",a=a.substring(0,a.length-3)):l.endsWith(".mp4.gz")||l.endsWith(".mp4.br")?(u="video/mp4",a=a.substring(0,a.length-3)):l.endsWith(".mov.gz")||l.endsWith(".mov.br")?(u="video/quicktime",a=a.substring(0,a.length-3)):l.endsWith(".mp3.gz")||l.endsWith(".mp3.br")?(u="audio/mpeg",a=a.substring(0,a.length-3)):l.endsWith(".wav.gz")||l.endsWith(".wav.br")?(u="audio/wave",a=a.substring(0,a.length-3)):l.endsWith(".ogg.gz")||l.endsWith(".ogg.br")?(u="audio/ogg",a=a.substring(0,a.length-3)):l.endsWith(".flac.gz")||l.endsWith(".flac.br")?(u="audio/flac",a=a.substring(0,a.length-3)):l.endsWith(".m4a.gz")||l.endsWith(".m4a.br")?(u="audio/mp4",a=a.substring(0,a.length-3)):l.endsWith(".aac.gz")||l.endsWith(".aac.br")?(u="audio/aac",a=a.substring(0,a.length-3)):l.endsWith(".woff2.gz")||l.endsWith(".woff2.br")?(u="font/woff2",a=a.substring(0,a.length-3)):l.endsWith(".woff.gz")||l.endsWith(".woff.br")?(u="font/woff",a=a.substring(0,a.length-3)):l.endsWith(".ttf.gz")||l.endsWith(".ttf.br")?(u="font/ttf",a=a.substring(0,a.length-3)):l.endsWith(".otf.gz")||l.endsWith(".otf.br")?(u="font/otf",a=a.substring(0,a.length-3)):l.endsWith(".md.gz")||l.endsWith(".md.br")?(u="text/markdown",a=a.substring(0,a.length-3)):l.endsWith(".yaml.gz")||l.endsWith(".yaml.br")||l.endsWith(".yml.gz")||l.endsWith(".yml.br")?(u="application/yaml",a=a.substring(0,a.length-3)):l.endsWith(".zip.gz")||l.endsWith(".zip.br")?(u="application/zip",a=a.substring(0,a.length-3)):l.endsWith(".glb.gz")||l.endsWith(".glb.br")?(u="model/gltf-binary",a=a.substring(0,a.length-3)):l.endsWith(".gltf.gz")||l.endsWith(".gltf.br")?(u="model/gltf+json",a=a.substring(0,a.length-3)):l.endsWith(".vrm.gz")||l.endsWith(".vrm.br")?(u="model/gltf-binary",a=a.substring(0,a.length-3)):l.endsWith(".usdz.gz")||l.endsWith(".usdz.br")?(u="model/vnd.usdz+zip",a=a.substring(0,a.length-3)):l.endsWith(".usda.gz")||l.endsWith(".usda.br")?(u="model/vnd.usd-usda",a=a.substring(0,a.length-3)):l.endsWith(".usdc.gz")||l.endsWith(".usdc.br")?(u="model/vnd.usd-usdc",a=a.substring(0,a.length-3)):l.endsWith(".usd.gz")||l.endsWith(".usd.br")?(u="model/vnd.usd-usd",a=a.substring(0,a.length-3)):l.endsWith(".obj.gz")||l.endsWith(".obj.br")?(u="model/obj",a=a.substring(0,a.length-3)):l.endsWith(".mtl.gz")||l.endsWith(".mtl.br")?(u="model/mtl",a=a.substring(0,a.length-3)):l.endsWith(".stl.gz")||l.endsWith(".stl.br")?(u="model/stl",a=a.substring(0,a.length-3)):l.endsWith(".mtlx.gz")||l.endsWith(".mtlx.br")?(u="application/materialx+xml",a=a.substring(0,a.length-3)):l.endsWith(".ply.gz")||l.endsWith(".ply.br")?(u="model/ply",a=a.substring(0,a.length-3)):l.endsWith(".dae.gz")||l.endsWith(".dae.br")?(u="model/vnd.collada+xml",a=a.substring(0,a.length-3)):l.endsWith(".3mf.gz")||l.endsWith(".3mf.br")?(u="model/3mf",a=a.substring(0,a.length-3)):(l.endsWith(".splat.gz")||l.endsWith(".splat.br")||l.endsWith(".spz.gz")||l.endsWith(".spz.br")||l.endsWith(".ksplat.gz")||l.endsWith(".ksplat.br")||l.endsWith(".sog.gz")||l.endsWith(".sog.br")||l.endsWith(".sogs.gz")||l.endsWith(".sogs.br"))&&(u="application/octet-stream",a=a.substring(0,a.length-3)),{filename:a,mimetype:u}):null);d&&(o=d.filename,f=d.mimetype)}var h=Pr(t);P[e]=t,b.files[e]={filename:o,content_type:f,content_length:c,content_md5:h}})},function(){});return _&&_.then?_.then(m):m()})})}catch(e){return Promise.reject(e)}}(e,t,n);return ro.push(r),Promise.resolve(r.finally(function(){var e=ro.indexOf(r);e>=0&&ro.splice(e,1)}))}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n,B(t,ai)),F({triggered_by:"web",entrypoint:void 0,files:r},i?{metadata:i}:{}),{name:t.name,abort:t.abort,progress:s,verify:a,type:t.type,content_id:t.content_id}).then(function(e){try{if("error"in e)return Promise.resolve({error:e.error});var n={job_id:e.id,content_id:e.content_id,url:e.url,skipped:e.uploadSkipped},r=function(){if(o&&e.content_id){var r=function(n,r){try{var i=Promise.resolve(ri(e.content_id,{thumbnail:o,org:null!=(s=t.org)?s:void 0,authToken:null!=(a=t.authToken)?a:void 0})).then(function(){})}catch(e){return r(e)}var s,a;return i&&i.then?i.then(void 0,r):i}(0,function(e){var t=e instanceof Error?e.message:String(e);console.error("[needle-cloud] Upload succeeded but the thumbnail could not be set:",t),n.thumbnail_error=t});if(r&&r.then)return r.then(function(){})}}();return Promise.resolve(r&&r.then?r.then(function(){return n}):n)}catch(e){return Promise.reject(e)}})})}catch(e){return Promise.reject(e)}},li=function(e){try{return Promise.resolve(Zo()).then(function(t){if(!t)return!1;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,o),ee(F({baseUrl:"https://cloud.needle.tools/api"},t),{type:"user","x-needle-product":n.join(",")}).then(function(e){for(var t,n=L(e);!(t=n()).done;)if(t.value.valid)return!0;return!1})})}catch(e){return Promise.reject(e)}},ci=function(e){try{return Promise.resolve(Zo()).then(function(t){if(!t)return null;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,o),ee(F({baseUrl:"https://cloud.needle.tools/api"},t),{type:"user","x-needle-product":n.join(",")}).then(function(t){return!0===e.includeInvalid?t:t.filter(function(e){return e.valid})})})}catch(e){return Promise.reject(e)}},fi=function(e){try{return Promise.resolve(Zo(e.org)).then(function(t){if(!t)throw new Error("Not authenticated");return Promise.resolve(function(e){try{var t=new URL((e.endpoint||"https://cloud.needle.tools/api")+Y.get.deployments);return t.searchParams.append("offset",e.offset.toString()),t.searchParams.append("limit",e.limit.toString()),e.names&&t.searchParams.append("name",e.names.map(function(e){return e.trim()}).join(",")),Promise.resolve(fetch(t,{method:"GET",headers:F({},Z({authToken:e.authToken,org:e.org}))})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json())}var r=function(){if(!e.ok){var n=e.status;return Promise.resolve(e.text()).then(function(e){return t=1,{status:n,error:e}})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}(F({endpoint:"https://cloud.needle.tools/api"},t,{offset:e.offset||0,limit:e.limit||10})).catch(function(e){return e})).then(function(e){if(!e||e instanceof Error)return[];var t=e;return Array.isArray(t.deployments)?t.deployments.map(function(e){return{name:e.name,url:e.url}}):[]})})}catch(e){return Promise.reject(e)}},di=function(e,t,n,r){return Promise.resolve(vi(null==r?void 0:r.org)).then(function(o){return Promise.resolve(Zo(o,null==r?void 0:r.authToken)).then(function(r){return function(e,t,n,r){try{var o=new Headers(Z(e));return o.set("Content-Type","application/json"),Promise.resolve(fetch(new URL(e.baseUrl+Y.ai.evaluate),F({},Q,{method:"POST",headers:Object.fromEntries(o),body:JSON.stringify({state:t,questions:n}),signal:null==r?void 0:r.signal}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){var n,r,o,i;null!=(n=e.headers.get("content-type"))&&n.includes("application/json")&&(i=JSON.parse(t));var s="string"==typeof(null==(r=i)?void 0:r.message)?i.message:t;throw new Bo(e.status,t,s,"string"==typeof(null==(o=i)?void 0:o.code)?i.code:void 0)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},r),e,t,n)})})},hi=function(e,t,n){return Promise.resolve(vi(null==n?void 0:n.org)).then(function(r){return Promise.resolve(Zo(r,null==n?void 0:n.authToken)).then(function(n){return function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.completions),o=Z(e);return o["Content-Type"]="application/json",Promise.resolve(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(F({message:t},null!=(null==n?void 0:n.system)?{system:n.system}:{},null!=(null==n?void 0:n.max_tokens)?{max_tokens:n.max_tokens}:{})),signal:null==n?void 0:n.signal}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text().catch(function(){return""})).then(function(t){throw new Error("Completion failed ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t)})})},pi=function(e,t){return Promise.resolve(vi(null==t?void 0:t.org)).then(function(n){return Promise.resolve(Zo(n,null==t?void 0:t.authToken)).then(function(t){return Ho(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})})},mi=function(e){return Promise.resolve(vi(null==e?void 0:e.org)).then(function(t){return Promise.resolve(Zo(t,null==e?void 0:e.authToken)).then(function(t){return Lo(F({baseUrl:"https://cloud.needle.tools/api"},t,{projectId:null==e?void 0:e.projectId}))})})},vi=function(e){try{return Promise.resolve(e||T.getDefaultTeamId())}catch(e){return Promise.reject(e)}};function gi(e){return function(e,t){void 0===t&&(t={});try{var n=new URL("https://cloud.needle.tools/api"+Y.public.content_list);if(t.include_metadata&&n.searchParams.set("include_metadata",t.include_metadata),t.content_type&&n.searchParams.set("content_type",t.content_type),t.content_format&&n.searchParams.set("content_format",t.content_format),t.org_id){var r=(Array.isArray(t.org_id)?t.org_id:[t.org_id]).map(function(e){return e.trim()}).filter(function(e){return e.length>0}).join(",");r&&n.searchParams.set("org_id",r)}return t.search&&n.searchParams.set("search",t.search),t.limit&&n.searchParams.set("limit",String(t.limit)),t.cursor&&n.searchParams.set("cursor",t.cursor),!0===t.include_protected&&n.searchParams.set("include_protected","true"),Promise.resolve(fetch(n,F({},Q,{method:"GET"}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to list public content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(0,e)}function yi(e,t){return void 0===t&&(t={}),function(e,t,n){void 0===n&&(n={});try{var r=new URL("https://cloud.needle.tools/api"+Y.public.content_list+"/"+encodeURIComponent(t));return n.include_metadata&&r.searchParams.set("include_metadata",n.include_metadata),Promise.resolve(fetch(r,F({},Q,{method:"GET"}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to get public content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(0,e,t)}var bi=["org","authToken","download","pollIntervalMs","timeoutMs","signal","onProgress"],wi=function(e){try{var t=e||{},n=t.org,r=t.authToken,o=t.download,i=t.pollIntervalMs,s=t.timeoutMs,a=t.signal,u=t.onProgress,l=B(t,bi);if(null==l||!l.prompt)throw new Error("A prompt is required to generate a 3D asset");return Promise.resolve(Zo(n,r)).then(function(e){if(null==e||!e.authToken)throw new Error("Not authenticated");var t={onProgress:u,pollIntervalMs:i,timeoutMs:s};return void 0!==o&&(t.download=o),Promise.resolve(function(e,t,n){void 0===n&&(n={});try{var r=n.download,o=void 0===r||r,i=n.pollIntervalMs,s=void 0===i?2e3:i,a=n.timeoutMs,u=void 0===a?9e5:a,l=n.onProgress,c=e.signal;return Promise.resolve(function(e,t){try{var n;if(null!=(n=e.signal)&&n.aborted)return Promise.resolve({error:"The 3D generation request was cancelled"});var r=e.baseUrl+Y.jobs.create,o=F({},Z(e),{"content-type":"application/json"}),i={type:"ai-3d-asset",triggered_by:e.trigger_type,parameters:F({},t)};return Promise.resolve(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(i),signal:e.signal})).catch(function(e){return function(e){return"AbortError"===(null==e?void 0:e.name)||"TimeoutError"===(null==e?void 0:e.name)}(e)?{__aborted:!0}:(console.error("Failed to request 3D asset generation: "+(null==e?void 0:e.message)),{__failed:(null==e?void 0:e.message)||"Request failed"})})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json().catch(function(e){return console.error(e),null})).then(function(e){return null!=e&&e.job?e:{error:"The server did not return a job"}})}if("__aborted"in e)return{error:"The 3D generation request was cancelled"};if("__failed"in e)return{error:e.__failed};var r=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(n){return console.error("Failed to request 3D asset generation ("+e.status+"): "+n),t=1,{error:n||"Request failed ("+e.status+")"}})}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}(e,t)).then(function(t){var n;function r(t){return n?t:null!=c&&c.aborted?{error:"Waiting for the 3D asset was cancelled",job:i}:o?Promise.resolve(function(e){try{return Promise.resolve(function(e){try{if(!e.identifier)return Promise.resolve(null);var t=F({},Z(e));return Promise.resolve(fetch(e.baseUrl+Y.jobs.query,F({},Q,{method:"POST",headers:t,body:JSON.stringify({job_id:e.identifier,fields:e.fields,content_format:e.content_format,content_type:e.content_type})})).catch(function(e){return console.error(e),null})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json().catch(function(e){return console.error(e),null})).then(function(e){return null==e?null:e.job})}var r=null==e?(t=1,null):function(){if(!e.ok){var n=e.status;return Promise.resolve(e.text()).then(function(e){return console.error("Failed to get job",n,e),t=1,null})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}({baseUrl:e.baseUrl,authToken:e.authToken,org:e.org,identifier:e.identifier,fields:["results"],content_format:e.content_format})).then(function(t){var n;function r(e){return n?e:{files:i}}if(null==t||!t.results)return{error:"Job "+e.identifier+" did not produce any result files"};var o=t.results;if(!o.bucket||!o.directory)return{error:"Job "+e.identifier+" has incomplete result data"};var i=[],s=function(e,t,n){if("function"==typeof e[ho]){var r,o,i,s=e[ho]();if(function e(a){try{for(;!((r=s.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!vo(a))return void a.then(e,i||(i=po.bind(null,o=new mo,2)));a=a.v}o?po(o,1,a):o=a}catch(e){po(o||(o=new mo),2,e)}}(),s.return){var a=function(e){try{r.done||s.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return function(e,t,n){var r,o,i=-1;return function s(a){try{for(;++i<e.length&&(!n||!n());)if((a=t(i))&&a.then){if(!vo(a))return void a.then(s,o||(o=po.bind(null,r=new mo,2)));a=a.v}r?po(r,1,a):r=a}catch(e){po(r||(r=new mo),2,e)}}(),r}(u,function(e){return t(u[e])},n)}(o.files,function(t){var r;if(!((r=t.filename).startsWith(".extras/")||r.startsWith(".extras\\")||r.endsWith("screenshot.needle.webp")||Dn.test(r)||r.endsWith(".needle.log")))return Promise.resolve(function(e,t,n){try{return Promise.resolve(fetch(e.baseUrl+Y.jobs.presigned_url,F({},Q,{method:"POST",headers:F({},Z(e),{job_id:t}),body:JSON.stringify(n)})).catch(function(e){return console.error(e),null})).then(function(e){return e&&e.ok?Promise.resolve(e.text()):(console.error("Failed to get presigned download URL",null==e?void 0:e.status),null)})}catch(e){return Promise.reject(e)}}(e,e.identifier,{bucket:o.bucket,key:o.directory+"/"+t.filename})).then(function(e){if(e)return Promise.resolve(fetch(e).catch(function(e){return console.error(e),null})).then(function(e){if(e&&e.ok)return Promise.resolve(e.arrayBuffer().catch(function(e){return console.error(e),null})).then(function(e){if(!e)return n=1,{error:"Failed to read downloaded file: "+t.filename};i.push({filename:t.filename,data:e})});console.error("Failed to download ("+(null==e?void 0:e.status)+" | "+(null==e?void 0:e.statusText)+"): "+t.filename)});console.error("Failed to get presigned URL for: "+t.filename)})},function(){return n});return s&&s.then?s.then(r):r(s)})}catch(e){return Promise.reject(e)}}({baseUrl:e.baseUrl,authToken:e.authToken,org:i.org,identifier:i.identifier,content_format:"glb"})).then(function(e){if("error"in e)return{error:e.error,job:i};var t=e.files.find(function(e){return e.filename.toLowerCase().endsWith(".glb")});return t?{job:i,glb:t.data,filename:t.filename}:{error:"The finished asset did not contain a GLB file",job:i}}):{job:i}}if("error"in t)return t;var i=t.job;if("canceled"===i.status)return{error:i.status_message||"The generation request was canceled",job:i};var a=Date.now(),f=i.status,d=function(e,t,n){for(var r;;){var o=e();if(bo(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!bo(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!bo(s)){r=2;break}}}var a=new yo,u=go.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!bo(s))return void s.then(f).then(void 0,u);if(!(o=e())||bo(o)&&!o.v)return void go(a,1,i);if(o.then)return void o.then(c).then(void 0,u);bo(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):go(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):go(a,1,i)}}(function(){return!n&&"completed"!==f},void 0,function(){if(null!=c&&c.aborted)return n=1,{error:"Waiting for the 3D asset was cancelled",job:i};if(Date.now()-a>u){var t={error:"Generation did not finish within "+Math.round(u/1e3)+"s",job:i};return n=1,t}return Promise.resolve(function(e,t){return t?t.aborted?Promise.resolve():new Promise(function(n){var r=setTimeout(function(){t.removeEventListener("abort",o),n(void 0)},e);function o(){clearTimeout(r),n(void 0)}t.addEventListener("abort",o,{once:!0})}):Fr(e)}(s,c)).then(function(){return null!=c&&c.aborted?(n=1,{error:"Waiting for the 3D asset was cancelled",job:i}):Promise.resolve(function(e,t){return Promise.resolve(function(e,t){try{var n=t.baseUrl+Y.jobs.get_status,r=F({},Z(t),{job_id:e,org:t.org});return Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:r})).catch(function(e){return t.verbose?console.error("Failed to get job status",e):console.error("Failed to get job status",e.message),null})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json())}if(!e)return{failed:!0};var r=function(){if(!e.ok){var n=e.status;return Promise.resolve(e.text()).then(function(r){return console.error("Failed to get status",n,r),t=1,{failed:!0,httpStatus:e.status}})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}(e,t)).then(function(e){return e&&"failed"in e?null:e})}(i.identifier,{baseUrl:e.baseUrl,authToken:e.authToken,org:i.org})).then(function(e){if(e&&(null==l||l(e),"failed"===(f=e.status)||"canceled"===f))return n=1,{error:e.error||e.status_message||"Generation "+f,job:i}})})});return d&&d.then?d.then(r):r(d)})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},e,{trigger_type:"web",signal:a}),l,t)).then(function(e){if("error"in e)throw new Error(e.error);return e})})}catch(e){return Promise.reject(e)}},Pi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.promotions);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list project promotions ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},_i=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.promote);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to promote project asset ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},ji=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.deployments);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to record project deployment ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ei=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.deployments);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list project deployments ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Si=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.revisions_update);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to update project revision ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},xi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.revisions);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list project revisions ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ti=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.blobs_download);return n.searchParams.set("hash",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}if(404===e.status)return null;var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to request blob download ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},ki=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.blobs_complete);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({hash:t})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to complete blob upload ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Oi=function(e,t,n,r){void 0===n&&(n={}),void 0===r&&(r=void 0);try{return Promise.resolve(Zo(n.org,n.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.projects.blobs_upload),i=null==r?void 0:r.filename,s=i&&jr(i)||void 0;return Promise.resolve(fetch(o,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({hash:t,size:n,filename:i,mimetype:s})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to request blob upload ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t,r)})}catch(e){return Promise.reject(e)}},Ri=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.blobs_check);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({hashes:t})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to check project blobs ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ui=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Zo(n.org,n.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t,n){return jo(e,Y.projects.update,t,n,"update")}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t)})}catch(e){return Promise.reject(e)}},Ci=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t,n){return void 0===n&&(n={}),jo(e,Y.projects.clone,t,n,"clone")}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,{name:t.name})})}catch(e){return Promise.reject(e)}},Ai=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){return jo(e,Y.projects.unarchive,t,{},"unarchive")}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Wi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){return jo(e,Y.projects.archive,t,{},"archive")}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ni=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){return jo(e,Y.projects.restore,t,{},"restore")}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ii=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(""+e.baseUrl+Y.projects.delete+"/"+encodeURIComponent(t));return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to delete project ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Li=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Zo(n.org,n.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(r,o){try{var i=Promise.resolve(function(e,t,n){try{var r=new URL(e.baseUrl+Y.projects.pull);return r.searchParams.set("project",t),void 0!==n&&r.searchParams.set("revision",String(n)),Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to pull project revision ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t))}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(e instanceof X&&404===e.status)return null;throw e})})}catch(e){return Promise.reject(e)}},Fi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.push);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to push project revision ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},zi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.head);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to get project head ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Di=function(e){void 0===e&&(e={});try{return Promise.resolve(Zo(e.org,e.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){void 0===t&&(t={});try{var n=new URL(e.baseUrl+Y.projects.list);return t.kind&&n.searchParams.set("kind",t.kind),t.state&&n.searchParams.set("state",t.state),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list projects ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),{kind:e.kind,state:e.state})})}catch(e){return Promise.reject(e)}},Mi=function(e,t){try{if(null==t||!t.kind)throw new Error("createProject: 'kind' is required (product discriminator, e.g. \"web-project\")");return Promise.resolve(Zo(t.org,t.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.create);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to create project ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),{name:e,kind:t.kind})})}catch(e){return Promise.reject(e)}},Bi=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Gi(n)).then(function(n){return function(e,t,n){return Eo(e,t,"reports","POST",n)}(n,e,t)})}catch(e){return Promise.reject(e)}},qi=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Gi(n)).then(function(n){return function(e,t,n){return Eo(e,t,"records","POST",n)}(n,e,t)})}catch(e){return Promise.reject(e)}},Ji=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Gi(n)).then(function(n){return function(e,t,n){return Eo(e,t,"policy","PUT",{enabled:n})}(n,e,t)})}catch(e){return Promise.reject(e)}},Hi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Gi(t)).then(function(t){return function(e,t){return Eo(e,t,"policy","GET")}(t,e)})}catch(e){return Promise.reject(e)}},Gi=function(e){try{return Promise.resolve(Zo(e.org,e.authToken)).then(function(e){if(null==e||!e.authToken)throw new Error("Not authenticated");return F({baseUrl:"https://cloud.needle.tools/api"},e)})}catch(e){return Promise.reject(e)}},Vi=function(e){try{var t=new URL("https://cloud.needle.tools/api"+Y.account.buy_licenses);return Promise.resolve(Zo()).then(function(n){var r={mode:"payment",price_id:e.price_id,tracking:e.tracking,affiliate_code:e.affiliateCode,return_url:window.location.href,cancel_url:window.location.href};return Promise.resolve(fetch(t,{method:"POST",headers:F({"Content-Type":"application/json"},Z(n)),body:JSON.stringify(r)})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return"session_url"in e?(window.location.href=e.session_url,{ok:!0,status:200,checkoutId:e.checkoutId}):{ok:!1,status:400}}):{ok:!1,status:e.status}})})}catch(e){return Promise.reject(e)}},$i=function(e,t){try{var n,r;if(!e)return Promise.resolve(null);var o=null!=(n=null==t?void 0:t.fetch)?n:globalThis.fetch,i=new URL((null!=(r=null==t?void 0:t.baseUrl)?r:"https://cloud.needle.tools/api")+Y.payment.info);return i.searchParams.set("product",e),null!=t&&t.price&&i.searchParams.set("price",t.price),Promise.resolve(function(e,t){try{var n=Promise.resolve(o(i.toString())).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return"number"!=typeof(null==e?void 0:e.amount)||"string"!=typeof(null==e?void 0:e.currency)?null:e}):null})}catch(e){return null}return n&&n.then?n.then(void 0,function(){return null}):n}())}catch(e){return Promise.reject(e)}},Ki=function(e,t){try{var n;if(!e)return Promise.resolve(null);var r=null!=(n=null==t?void 0:t.fetch)?n:globalThis.fetch;return Promise.resolve(Zo(null==t?void 0:t.org,null==t?void 0:t.authToken).catch(function(){return null})).then(function(n){var o,i,s;if(null==n||!n.authToken)return null;var a=new URL((null!=(o=null==t?void 0:t.baseUrl)?o:"https://cloud.needle.tools/api")+Y.payment.create);return a.searchParams.set("product",e),null!=t&&t.price&&a.searchParams.set("price",t.price),null!=t&&t.promoCode&&a.searchParams.set("promo",t.promoCode),void 0!==(null==t?void 0:t.affiliateCode)&&a.searchParams.set("affiliate_code",t.affiliateCode),null!=t&&t.app&&a.searchParams.set("app",t.app),void 0!==(null==t||null==(i=t.tracking)?void 0:i.source)&&a.searchParams.set("source",t.tracking.source),void 0!==(null==t||null==(s=t.tracking)?void 0:s.attemptId)&&a.searchParams.set("attempt_id",t.tracking.attemptId),"number"==typeof(null==t?void 0:t.mode)&&a.searchParams.set("mode",String(t.mode)),function(e,t){try{var o=Promise.resolve(r(a.toString(),{headers:F({Accept:"application/json"},Z(n))})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return"string"==typeof(null==e?void 0:e.url)&&"string"==typeof(null==e?void 0:e.checkoutId)?{url:e.url,checkoutId:e.checkoutId}:null}):null})}catch(e){return null}return o&&o.then?o.then(void 0,function(){return null}):o}()})}catch(e){return Promise.reject(e)}};function Xi(e){return function(e,t){try{if(!/^[a-f0-9]{64}$/.test(t))throw new Error("Invalid runtime snapshot identifier");return Go(e,new URL(e.baseUrl.replace(/\/$/,"")+Y.runtime_snapshots.get.replace(":hash",t)))}catch(e){return Promise.reject(e)}}({baseUrl:"https://cloud.needle.tools/api"},e)}function Yi(e,t){return function(e,t,n){try{var r=new URL(e.baseUrl.replace(/\/$/,"")+Y.runtime_snapshots.release_get);return r.searchParams.set("runtime",t),r.searchParams.set("version",n),Go(e,r)}catch(e){return Promise.reject(e)}}({baseUrl:"https://cloud.needle.tools/api"},e,t)}export{Oo as AIChatError,T as Auth,r as AuthScopes,K as NeedleLoginButton,hi as aiComplete,di as aiEvaluate,Wi as archiveProject,Ri as checkProjectBlobs,Ki as checkoutProduct,Ci as cloneProject,ki as completeProjectBlobUpload,pi as createChatSession,Mi as createProject,ni as deleteContent,Ii as deleteProject,Yo as discoverTools,wi as generate3dAsset,oi as getContent,fi as getDeployments,$i as getProductInformation,Ei as getProjectDeployments,Hi as getProjectDiagnosticPolicy,zi as getProjectHead,Pi as getProjectPromotions,yi as getPublicContent,Yi as getRuntimeRelease,Xi as getRuntimeSnapshot,ci as getUserLicenses,mi as listChats,ii as listContent,xi as listProjectRevisions,Di as listProjects,gi as listPublicContent,li as ownsProduct,_i as promoteProjectAsset,Li as pullProjectRevision,Fi as pushProjectRevision,ji as recordProjectDeployment,Ti as requestProjectBlobDownload,Oi as requestProjectBlobUpload,Ni as restoreProject,Ji as setProjectDiagnosticPolicy,Vi as startCheckoutSession,Bi as submitProjectBugReport,Ai as unarchiveProject,ri as updateContent,Vo as updateInlineChatParts,Ui as updateProject,Si as updateProjectRevision,ui as uploadFiles,qi as uploadProjectDiagnosticPart};
1
+ import e,{UserScope as t}from"@logto/browser";var n,r={Basic:[t.Profile,t.Email],Payment:["read:accounting","write:accounting"],All:[t.Profile,t.Email,t.Roles,t.CustomData,t.Organizations,t.OrganizationRoles].concat(["all","read","write","delete","invite","download","create:org","write:org","delete:org","read:accounting","write:accounting","read:usage"])},o=["Needle Engine"],i="[Needle Cloud]",s="https://auth.needle.tools",a=void 0,u=[],l=null,c=null,f=null,d=null,h=new Array;function p(){h.forEach(function(e){try{e()}catch(e){v.error(e)}})}var m=!1,v=console,g=Promise.resolve();function y(e){var t=g.then(function(){var t,n=null==(t=globalThis.navigator)?void 0:t.locks;return null!=n&&n.request?n.request("needle-auth:token-exchange:"+a,e):e()});return g=t.then(function(){},function(){}),t}var b,w,P,_,j,E=(b=function(e){return m&&v.debug(i,"requestAccessToken",{org_id:e}),y(function(){return e?R().getOrganizationToken(e):R().getAccessToken("https://cloud.needle.tools/api",e||void 0)}).catch(function(e){throw S(e),e})},w=new Map,function(e){var t=null==e?"\0none":String(e),n=w.get(t);if(n)return n;var r=function(){try{return Promise.resolve(b(e))}catch(e){return Promise.reject(e)}}().finally(function(){w.get(t)===r&&w.delete(t)});return w.set(t,r),r});function S(e){return!!function(e){var t,n;if(!e||"object"!=typeof e)return!1;var r=e,o=function(e){if("string"!=typeof e)return!1;var t=e.replace(/^oidc\./,"");return"invalid_grant"===t||"invalid_target"===t};return o(r.code)||o(null==(t=r.data)?void 0:t.error)||o(null==(n=r.data)?void 0:n.code)}(e)&&(v.warn(i,"Stored session is no longer valid — clearing tokens (sign in again)"),n=!1,R().clearAllTokens().catch(function(){}),!0)}var x=function(){var e,t;return null!=(e=null==(t=globalThis.location)?void 0:t.origin)?e:""},T={setLogger:function(e){v=e},setDebug:function(e){m=e},get baseUrl(){var e;return null!=(e=P)?e:P=x()},set baseUrl(e){P=e},get redirectUri(){var e;return null!=(e=_)?e:_=x()},set redirectUri(e){_=e},get postSignOutRedirectUri(){var e;return null!=(e=j)?e:j=x()},set postSignOutRedirectUri(e){j=e},onChanged:function(e){return h.includes(e)||h.push(e),function(){for(;;){var t=h.indexOf(e);if(!(t>=0))break;h.splice(t,1)}}},ready:function(){return c?c.then(function(){return!0}):Promise.reject(new Error("Auth not initialized"))},init:function(e){return c||(c=function(e){try{var t,n,o=function(){var e=O(!0);if(!e)return T.checkIsAuthenticated().then(function(e){return!e||T.requestUserInfo().then(function(){return!0})});var t=new URL(window.location.href);return t.search=e,window.history.replaceState({},"",t.href),Promise.resolve(!0)};if(null!=e&&e.debug&&(m=e.debug),m&&v.debug(i,"Auth.init",e),null!=e&&e.scopes){switch(e.scopes){case"all":e.scopes=r.All;break;case"payment":e.scopes=r.Payment}u=e.scopes}u.length<=0&&(t=u).push.apply(t,r.Basic.concat(r.Payment)),m&&v.debug(i,"Auth.init","Use scopes",u),null!=e&&e.appId?(null==(n=d)?void 0:n.logtoConfig.appId)!==(a=e.appId)&&(m&&v.debug(i,"Auth.init","App ID changed, resetting client"),d=null):(a="2x82zzh5xuudmiotdy2ux",m&&v.debug(i,"Auth.init","Use default app ID",a));var l=function(){var e,t=new URL(window.location.href);if(t.searchParams.has("code")&&t.searchParams.has("state")&&null!=(e=t.searchParams.get("iss"))&&e.includes(s))return R().handleSignInCallback(t.href).then(function(){var e=new URL(window.location.href);e.pathname=e.pathname.replace("callback",""),e.searchParams.delete("code"),e.searchParams.delete("state"),e.searchParams.delete("iss");var t=O();t&&(v.info(i,"Restore query before login",t,"Current:",e.search),e.search=t),window.history.replaceState({},"",e.href)}).catch(function(e){v.error(e)})}(),c=function(){if(l instanceof Promise)return Promise.resolve(l.then(function(e){return!0})).then(function(){})}();return Promise.resolve(c&&c.then?c.then(o):o())}catch(e){return Promise.reject(e)}}(e))},isAuthenticated:function(){return n},checkIsAuthenticated:function(){return R().isAuthenticated().then(function(e){return n=e,e})},getUserInfo:function(){return l},getUserId:function(){return l?l.sub:null},getName:function(){return l?l.username?l.username:l.name?l.name:l.email?l.email.split("@")[0]:null:null},requestUserInfo:function(){return f||(f=T.checkIsAuthenticated().then(function(e){return e?y(function(){return R().fetchUserInfo()}).then(function(e){var t;return m&&(null==e?void 0:e.sub)!=(null==(t=l)?void 0:t.sub)&&v.debug(i,"UserInfo",e),l=e,p(),e}).catch(function(e){return v.error(e),S(e),l=null,p(),null}):(l=null,p(),null)}))},requestAccessToken:function(e){return E(null!=e?e:void 0)},signIn:function(e){return T.checkIsAuthenticated().then(function(t){if(0==t){var n;if(null==(n=a)||!n.length)throw new Error("App ID is not set: Make sure to call 'init' first");k(),null!=e&&e.signUp?R().signIn({redirectUri:T.redirectUri,firstScreen:"register",interactionMode:"signUp"}):R().signIn(T.redirectUri)}})},getDefaultTeamId:function(){var e,t=null==(e=l)?void 0:e.custom_data,n=null==t?void 0:t.default_org;return"string"==typeof n?n:void 0},signOut:function(){return f=null,T.checkIsAuthenticated().then(function(e){if(1==e){var t;if(null==(t=a)||!t.length)throw new Error("App ID is not set: Make sure to call 'init' first");k(),R().signOut(T.postSignOutRedirectUri)}})}};function k(){sessionStorage.setItem("needle-auth:query",window.location.search)}function O(e){void 0===e&&(e=!0);var t=sessionStorage.getItem("needle-auth:query");return t?(e&&sessionStorage.removeItem("needle-auth:query"),t):""}function R(){if(!d){if(!a)throw new Error("App ID is not set: Make sure to call 'init' first");var t={endpoint:s,appId:a,scopes:u,resources:["https://cloud.needle.tools/api"]};m&&v.warn(i,"Creating auth client:",m,t),d=new e(t)}return d}function U(e,t){this.v=e,this.k=t}function C(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function A(e){var t={},n=!1;function r(t,r){return n=!0,r=new Promise(function(n){n(e[t](r))}),{done:!1,value:new U(r,1)}}return t["undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator"]=function(){return this},t.next=function(e){return n?(n=!1,e):r("next",e)},"function"==typeof e.throw&&(t.throw=function(e){if(n)throw n=!1,e;return r("throw",e)}),"function"==typeof e.return&&(t.return=function(e){return n?(n=!1,e):r("return",e)}),t}function W(e){var t,n,r,o=2;for("undefined"!=typeof Symbol&&(n=Symbol.asyncIterator,r=Symbol.iterator);o--;){if(n&&null!=(t=e[n]))return t.call(e);if(r&&null!=(t=e[r]))return new N(t.call(e));n="@@asyncIterator",r="@@iterator"}throw new TypeError("Object is not async iterable")}function N(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then(function(e){return{value:e,done:t}})}return N=function(e){this.s=e,this.n=e.next},N.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var n=this.s.return;return void 0===n?Promise.resolve({value:e,done:!0}):t(n.apply(this.s,arguments))},throw:function(e){var n=this.s.return;return void 0===n?Promise.reject(e):t(n.apply(this.s,arguments))}},new N(e)}function I(e){return new U(e,0)}function L(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return C(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?C(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(){return F=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},F.apply(null,arguments)}function z(e){return z=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},z(e)}function D(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,J(e,t)}function M(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(M=function(){return!!e})()}function B(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function q(){q=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var i=Object.create((t&&t.prototype instanceof g?t:g).prototype),s=new R(r||[]);return o(i,"_invoke",{value:x(e,n,s)}),i}function f(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=c;var d="suspendedStart",h="suspendedYield",p="executing",m="completed",v={};function g(){}function y(){}function b(){}var w={};l(w,s,function(){return this});var P=Object.getPrototypeOf,_=P&&P(P(U([])));_&&_!==n&&r.call(_,s)&&(w=_);var j=b.prototype=g.prototype=Object.create(w);function E(e){["next","throw","return"].forEach(function(t){l(e,t,function(e){return this._invoke(t,e)})})}function S(e,t){function n(o,i,s,a){var u=f(e[o],e,i);if("throw"!==u.type){var l=u.arg,c=l.value;return c&&"object"==typeof c&&r.call(c,"__await")?t.resolve(c.__await).then(function(e){n("next",e,s,a)},function(e){n("throw",e,s,a)}):t.resolve(c).then(function(e){l.value=e,s(l)},function(e){return n("throw",e,s,a)})}a(u.arg)}var i;o(this,"_invoke",{value:function(e,r){function o(){return new t(function(t,o){n(e,r,t,o)})}return i=i?i.then(o,o):o()}})}function x(t,n,r){var o=d;return function(i,s){if(o===p)throw Error("Generator is already running");if(o===m){if("throw"===i)throw s;return{value:e,done:!0}}for(r.method=i,r.arg=s;;){var a=r.delegate;if(a){var u=T(a,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===d)throw o=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=p;var l=f(t,n,r);if("normal"===l.type){if(o=r.done?m:h,l.arg===v)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(o=m,r.method="throw",r.arg=l.arg)}}}function T(t,n){var r=n.method,o=t.iterator[r];if(o===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,T(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var i=f(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,v;var s=i.arg;return s?s.done?(n[t.resultName]=s.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,v):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function k(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function U(t){if(t||""===t){var n=t[s];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function n(){for(;++o<t.length;)if(r.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=e,n.done=!0,n};return i.next=i}}throw new TypeError(typeof t+" is not iterable")}return y.prototype=b,o(j,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:y,configurable:!0}),y.displayName=l(b,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,l(e,u,"GeneratorFunction")),e.prototype=Object.create(j),e},t.awrap=function(e){return{__await:e}},E(S.prototype),l(S.prototype,a,function(){return this}),t.AsyncIterator=S,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var s=new S(c(e,n,r,o),i);return t.isGeneratorFunction(n)?s:s.next().then(function(e){return e.done?e.value:s.next()})},E(j),l(j,u,"Generator"),l(j,s,function(){return this}),l(j,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},t.values=U,R.prototype={constructor:R,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function o(r,o){return a.type="throw",a.arg=t,n.next=r,o&&(n.method="next",n.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return o("end");if(s.tryLoc<=this.prev){var u=r.call(s,"catchLoc"),l=r.call(s,"finallyLoc");if(u&&l){if(this.prev<s.catchLoc)return o(s.catchLoc,!0);if(this.prev<s.finallyLoc)return o(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return o(s.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return o(s.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),O(n),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;O(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:U(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function J(e,t){return J=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},J(e,t)}function H(e){return function(){return new G(e.apply(this,arguments))}}function G(e){var t,n;function r(t,n){try{var i=e[t](n),s=i.value,a=s instanceof U;Promise.resolve(a?s.v:s).then(function(n){if(a){var u="return"===t?"return":"next";if(!s.k||n.done)return r(u,n);n=e[u](n).value}o(i.done?"return":"normal",n)},function(e){r("throw",e)})}catch(e){o("throw",e)}}function o(e,o){switch(e){case"return":t.resolve({value:o,done:!0});break;case"throw":t.reject(o);break;default:t.resolve({value:o,done:!1})}(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,o){return new Promise(function(i,s){var a={key:e,arg:o,resolve:i,reject:s,next:null};n?n=n.next=a:(t=n=a,r(e,o))})},"function"!=typeof e.return&&(this.return=void 0)}function V(e){var t="function"==typeof Map?new Map:void 0;return V=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return function(e,t,n){if(M())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var o=new(e.bind.apply(e,r));return n&&J(o,n.prototype),o}(e,arguments,z(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),J(n,e)},V(e)}function $(){$=function(e,t){return new n(e,void 0,t)};var e=RegExp.prototype,t=new WeakMap;function n(e,r,o){var i=RegExp(e,r);return t.set(i,o||t.get(e)),J(i,n.prototype)}function r(e,n){var r=t.get(n);return Object.keys(r).reduce(function(t,n){var o=r[n];if("number"==typeof o)t[n]=e[o];else{for(var i=0;void 0===e[o[i]]&&i+1<o.length;)i++;t[n]=e[o[i]]}return t},Object.create(null))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&J(e,t)}(n,RegExp),n.prototype.exec=function(t){var n=e.exec.call(this,t);if(n){n.groups=r(n,this);var o=n.indices;o&&(o.groups=r(o,this))}return n},n.prototype[Symbol.replace]=function(n,o){if("string"==typeof o){var i=t.get(this);return e[Symbol.replace].call(this,n,o.replace(/\$<([^>]+)>/g,function(e,t){var n=i[t];return"$"+(Array.isArray(n)?n.join("$"):n)}))}if("function"==typeof o){var s=this;return e[Symbol.replace].call(this,n,function(){var e=arguments;return"object"!=typeof e[e.length-1]&&(e=[].slice.call(e)).push(r(e,s)),o.apply(this,e)})}return e[Symbol.replace].call(this,n,o)},$.apply(this,arguments)}G.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},G.prototype.next=function(e){return this._invoke("next",e)},G.prototype.throw=function(e){return this._invoke("throw",e)},G.prototype.return=function(e){return this._invoke("return",e)};var K=void 0;if("undefined"!=typeof HTMLButtonElement&&"undefined"!=typeof customElements)if(K=/*#__PURE__*/function(e){function t(){var t;return(t=e.call(this)||this).addEventListener("click",function(){T.isAuthenticated()?T.signOut():T.signIn()}),t}D(t,e);var n=t.prototype;return n.connectedCallback=function(){var e=this;console.debug("Login button connected..."),this.__update(),this.__unsubscribeOnChange=T.onChanged(function(){e.__update()})},n.disconnectedCallback=function(){var e;null==(e=this.__unsubscribeOnChange)||e.call(this)},n.__update=function(){this.innerHTML=T.isAuthenticated()?"Logout":"Login"},t}(/*#__PURE__*/V(HTMLButtonElement)),customElements.get("needle-login-button"))try{("localhost"===window.location.hostname||/^(127|192\.168|10\.|172\.(1[6-9]|2[0-9]|3[0-1]))\./.test(window.location.hostname))&&console.debug("needle-login-button is already defined.")}catch(e){}else customElements.define("needle-login-button",K,{extends:"button"});var X=/*#__PURE__*/function(e){function t(t,n,r){var o;return(o=e.call(this,r)||this).name="ApiError",o.status=t,o.body=n,o}return D(t,e),t}(/*#__PURE__*/V(Error)),Y={status:"/v1/status",version:"/v1/version",api:"/v1/api",runtime_snapshots:{release_get:"/v1/runtime-releases",get:"/v1/runtime-snapshots/:hash",file:"/v1/runtime-snapshots/:hash/files/*"},usage:{get:"/v1/usage"},affiliate:{get:"/v1/affiliate/get",link_clicked:"/v1/affiliate/link_clicked"},account:{public_key:"/v1/account/public_key",post_machine:"/v1/account/machine",connect:"/v1/account/connect",get_licenses:"/v1/account/get/licenses",set_license_active:"/v1/account/set_license_active",set_licenses_active:"/v1/account/set_licenses_active",buy_licenses:"/v1/account/buy_licenses",update_licenses:"/v1/account/update_licenses",preview_invitation:"/v1/account/preview_invitation",update_payment_method:"/v1/account/update_payment_method",get_billing:"/v1/account/get_billing",generate_invoice:"/v1/account/generate_invoice",resume_subscription:"/v1/account/resume_subscription",cancel_subscription:"/v1/account/cancel_subscription",start_billingportal_session:"/v1/account/start_billingportal_session",post_preferences:"/v1/account/preferences",get_preferences:"/v1/account/preferences"},payment:{info:"/v1/payment/info",create:"/v1/payment/create"},ai:{llmstxt:"/v1/ai/llmstxt",chat:"/v1/ai/chat",chat_personal:"/v1/ai/chat/personal",list_chats:"/v1/ai/chat/list",chat_image:"/v1/ai/chat/image",chat_tool_result:"/v1/ai/chat/tool-result",chat_stop:"/v1/ai/chat/stop",chat_file_edits:"/v1/ai/file-edits",chat_file_edit_undo:"/v1/ai/file-edits/undo",chat_enqueue:"/v1/ai/chat/enqueue",chat_enqueue_cancel:"/v1/ai/chat/enqueue/cancel",ask:"/v1/ai/ask",completions:"/v1/ai/completions",evaluate:"/v1/ai/evaluate",post_settings:"/v1/ai/chat/settings",ws:"/v1/ws",cli_ws:"/v1/cli/ws"},organizations:{get:"/v1/organizations/get",orgs_details:"/v1/organizations/details",licenses:"/v1/organizations/licenses",get_invitations:"/v1/organizations/get_invitations"},events:{get:"/v1/events/get",post:"/v1/events/post",list:"/v1/events/list"},reports:{get:"/v1/reports/get",post:"/v1/reports/post"},diagnostics:{download_failed:"/v1/diagnostics/download-failed"},questionnaire:{get:"/v1/questionnaires/get",post:"/v1/questionnaires/post"},roadmap:{get:"/v1/roadmap/get",post_vote:"/v1/roadmap/post"},tokens:{create:"/v1/tokens/create",delete:"/v1/tokens/delete",list:"/v1/tokens/list"},get:{stats:"/v1/get/stats",jobs:"/v1/list/jobs",deployments:"/v1/list/deployments",discounts:"/v1/get/discounts"},files:{entry:"/v1/files/:identifier/:version/",file:"/v1/files/:identifier/:version/*"},view:{get_analytics:"/v1/view/analytics",get_public_info:"/v1/view/public/info",post_version:"/v1/view/post_version"},content:{root:"/v1/content",download:"/v1/content/download",detail:"/v1/content/:identifier",update:"/v1/content/:identifier",delete:"/v1/content/:identifier",restore:"/v1/content/:identifier/restore",visits:"/v1/content/:identifier/visits",domains:"/v1/content/:identifier/domains",domain_item:"/v1/content/:identifier/domains/:hostname",domain_verify:"/v1/content/:identifier/domains/:hostname/verify"},analytics:{content_list:"/v1/analytics/content-list"},public:{content_list:"/v1/public/content",content_detail:"/v1/public/content/:identifier"},collections:{list:"/v1/collections/list",get:"/v1/collections/get",create:"/v1/collections/create",update:"/v1/collections/update",delete:"/v1/collections/delete",add_item:"/v1/collections/add-item",remove_item:"/v1/collections/remove-item",reorder_items:"/v1/collections/reorder-items"},projects:{create:"/v1/projects/create",list:"/v1/projects/list",head:"/v1/projects/head",push:"/v1/projects/push",pull:"/v1/projects/pull",delete:"/v1/projects/delete",restore:"/v1/projects/restore",archive:"/v1/projects/archive",unarchive:"/v1/projects/unarchive",clone:"/v1/projects/clone",update:"/v1/projects/update",blobs_check:"/v1/projects/blobs/check",blobs_upload:"/v1/projects/blobs/upload",blobs_complete:"/v1/projects/blobs/complete",blobs_download:"/v1/projects/blobs/download",revisions:"/v1/projects/revisions",revisions_update:"/v1/projects/revisions/update",deployments:"/v1/projects/deployments",promote:"/v1/projects/promote",promotions:"/v1/projects/promotions"},upload:{request:"/v1/upload/request",request_put_url:"/v1/upload/put",update_results:"/v1/upload/results",done:"/v1/upload/done",cancel:"/v1/upload/cancel",multipart_create:"/v1/upload/multipart/create",multipart_part_urls:"/v1/upload/multipart/part-urls",multipart_complete:"/v1/upload/multipart/complete",multipart_abort:"/v1/upload/multipart/abort"},jobs:{create:"/v1/jobs/create",get_id:"/v1/jobs/get_id",presigned_url:"/v1/jobs/presigned-url",presigned_urls:"/v1/jobs/presigned-urls",download_urls:"/v1/jobs/download-urls",request_restart:"/v1/jobs/restart",delete:"/v1/jobs/delete",post_update:"/v1/jobs/update",post_usage:"/v1/jobs/post_usage",get_status:"/v1/jobs/status",get_org:"/v1/jobs/org",query:"/v1/jobs/query"},worker:{get_available_count:"/v1/worker/get_available_count"},local_projects:{get:{user:"/v1/local_projects/user",by_id:"/v1/local_projects/"},post:"/v1/local_projects"}};function Z(e){var t={authorization:"Bearer "+e.authToken};return e.org&&(t["x-needle-cloud-org"]=e.org),e.roles&&(t.roles=e.roles.join(",")),e.roles_org&&(t.roles_org=e.roles_org.join(",")),t}var Q={credentials:"omit"},ee=function(e,t){try{var n=e.baseUrl+Y.account.get_licenses,r=F({},t),o=F({},r,Z(e));return Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:o})).catch(function(e){return console.error(e),null})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json()).then(function(e){return e.licenses})}if(!e)return[];var r=function(){if(!e.ok){var n=e.statusText;return Promise.resolve(e.text()).then(function(e){return console.error(n,e),t=1,[]})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}};function te(e,t){return function(){return e.apply(t,arguments)}}const{toString:ne}=Object.prototype,{getPrototypeOf:re}=Object,{iterator:oe,toStringTag:ie}=Symbol,se=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),ae=(e,t)=>{let n=e;const r=[];for(;null!=n&&n!==Object.prototype;){if(-1!==r.indexOf(n))return!1;if(r.push(n),se(n,t))return!0;n=re(n)}return!1},ue=(le=Object.create(null),e=>{const t=ne.call(e);return le[t]||(le[t]=t.slice(8,-1).toLowerCase())});var le;const ce=e=>(e=e.toLowerCase(),t=>ue(t)===e),fe=e=>t=>typeof t===e,{isArray:de}=Array,he=fe("undefined");function pe(e){return null!==e&&!he(e)&&null!==e.constructor&&!he(e.constructor)&&ge(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const me=ce("ArrayBuffer"),ve=fe("string"),ge=fe("function"),ye=fe("number"),be=e=>null!==e&&"object"==typeof e,we=e=>{if(!be(e))return!1;const t=re(e);return!(null!==t&&t!==Object.prototype&&null!==re(t)||ae(e,ie)||ae(e,oe))},Pe=ce("Date"),_e=ce("File"),je=ce("Blob"),Ee=ce("FileList"),Se=ce("Set"),xe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Te=void 0!==xe.FormData?xe.FormData:void 0,ke=ce("URLSearchParams"),[Oe,Re,Ue,Ce]=["ReadableStream","Request","Response","Headers"].map(ce);function Ae(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),de(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(pe(e))return;const o=n?Object.getOwnPropertyNames(e):Object.keys(e),i=o.length;let s;for(r=0;r<i;r++)s=o[r],t.call(null,e[s],s,e)}}function We(e,t){if(pe(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r,o=n.length;for(;o-- >0;)if(r=n[o],t===r.toLowerCase())return r;return null}const Ne="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,Ie=e=>!he(e)&&e!==Ne,Le=(Fe="undefined"!=typeof Uint8Array&&re(Uint8Array),e=>Fe&&e instanceof Fe);var Fe;const ze=ce("HTMLFormElement"),{propertyIsEnumerable:De}=Object.prototype,Me=ce("RegExp"),Be=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Ae(n,(n,o)=>{let i;!1!==(i=t(n,o,e))&&(r[o]=i||n)}),Object.defineProperties(e,r)},qe=ce("AsyncFunction"),Je=(He="function"==typeof setImmediate,Ge=ge(Ne.postMessage),He?setImmediate:Ge?(Ve=`axios@${Math.random()}`,$e=[],Ne.addEventListener("message",({source:e,data:t})=>{e===Ne&&t===Ve&&$e.length&&$e.shift()()},!1),e=>{$e.push(e),Ne.postMessage(Ve,"*")}):e=>setTimeout(e));var He,Ge,Ve,$e;const Ke="undefined"!=typeof queueMicrotask?queueMicrotask.bind(Ne):"undefined"!=typeof process&&process.nextTick||Je,Xe=e=>null!=e&&ge(e[oe]);var Ye={isArray:de,isArrayBuffer:me,isBuffer:pe,isFormData:e=>{if(!e)return!1;if(Te&&e instanceof Te)return!0;const t=re(e);if(!t||t===Object.prototype)return!1;if(!ge(e.append))return!1;const n=ue(e);return"formdata"===n||"object"===n&&ge(e.toString)&&"[object FormData]"===e.toString()},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&me(e.buffer),t},isString:ve,isNumber:ye,isBoolean:e=>!0===e||!1===e,isObject:be,isPlainObject:we,isEmptyObject:e=>{if(!be(e)||pe(e))return!1;try{return 0===Object.keys(e).length&&Object.getPrototypeOf(e)===Object.prototype}catch(e){return!1}},isReadableStream:Oe,isRequest:Re,isResponse:Ue,isHeaders:Ce,isUndefined:he,isDate:Pe,isFile:_e,isReactNativeBlob:e=>!(!e||void 0===e.uri),isReactNative:e=>e&&void 0!==e.getParts,isBlob:je,isRegExp:Me,isFunction:ge,isStream:e=>be(e)&&ge(e.pipe),isURLSearchParams:ke,isTypedArray:Le,isFileList:Ee,forEach:Ae,merge:function e(...t){const{caseless:n,skipUndefined:r}=Ie(this)&&this||{},o={},i=(t,i)=>{if("__proto__"===i||"constructor"===i||"prototype"===i)return;const s=n&&"string"==typeof i&&We(o,i)||i,a=se(o,s)?o[s]:void 0;we(a)&&we(t)?o[s]=e(a,t):we(t)?o[s]=e({},t):de(t)?o[s]=t.slice():r&&he(t)||(o[s]=t)};for(let e=0,n=t.length;e<n;e++){const n=t[e];if(!n||pe(n))continue;if(Ae(n,i),"object"!=typeof n||de(n))continue;const r=Object.getOwnPropertySymbols(n);for(let e=0;e<r.length;e++){const t=r[e];De.call(n,t)&&i(n[t],t)}}return o},extend:(e,t,n,{allOwnKeys:r}={})=>(Ae(t,(t,r)=>{n&&ge(t)?Object.defineProperty(e,r,{__proto__:null,value:te(t,n),writable:!0,enumerable:!0,configurable:!0}):Object.defineProperty(e,r,{__proto__:null,value:t,writable:!0,enumerable:!0,configurable:!0})},{allOwnKeys:r}),e),trim:e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""),stripBOM:e=>(65279===e.charCodeAt(0)&&(e=e.slice(1)),e),inherits:(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),Object.defineProperty(e.prototype,"constructor",{__proto__:null,value:e,writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(e,"super",{__proto__:null,value:t.prototype}),n&&Object.assign(e.prototype,n)},toFlatObject:(e,t,n,r)=>{let o,i,s;const a={};if(t=t||{},null==e)return t;do{for(o=Object.getOwnPropertyNames(e),i=o.length;i-- >0;)s=o[i],r&&!r(s,e,t)||a[s]||(t[s]=e[s],a[s]=!0);e=!1!==n&&re(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:ue,kindOfTest:ce,endsWith:(e,t,n)=>{e=String(e),(void 0===n||n>e.length)&&(n=e.length);const r=e.indexOf(t,n-=t.length);return-1!==r&&r===n},toArray:e=>{if(!e)return null;if(de(e))return e;let t=e.length;if(!ye(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[oe]).call(e);let r;for(;(r=n.next())&&!r.done;){const n=r.value;t.call(e,n[0],n[1])}},matchAll:(e,t)=>{let n;const r=[];for(;null!==(n=e.exec(t));)r.push(n);return r},isHTMLForm:ze,hasOwnProperty:se,hasOwnProp:se,hasOwnInPrototypeChain:ae,getSafeProp:(e,t)=>null!=e&&ae(e,t)?e[t]:void 0,reduceDescriptors:Be,freezeMethods:e=>{Be(e,(t,n)=>{if(ge(e)&&["arguments","caller","callee"].includes(n))return!1;ge(e[n])&&(t.enumerable=!1,"writable"in t?t.writable=!1:t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")}))})},toObjectSet:(e,t)=>{const n={},r=e=>{e.forEach(e=>{n[e]=!0})};return de(e)?r(e):r(String(e).split(t)),n},toCamelCase:e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(e,t,n){return t.toUpperCase()+n}),noop:()=>{},toFiniteNumber:(e,t)=>null!=e&&Number.isFinite(e=+e)?e:t,findKey:We,global:Ne,isContextDefined:Ie,isSpecCompliantForm:function(e){return!!(e&&ge(e.append)&&"FormData"===e[ie]&&e[oe])},toJSONObject:e=>{const t=new WeakSet,n=e=>{if(be(e)){if(t.has(e))return;if(pe(e))return e;if(!("toJSON"in e)){let r;if(t.add(e),Se(e)){r=[];for(const t of e){const e=n(t);!he(e)&&r.push(e)}}else r=de(e)?[]:{},Ae(e,(e,t)=>{const o=n(e);!he(o)&&(r[t]=o)});return t.delete(e),r}}return e};return n(e)},isAsyncFn:qe,isThenable:e=>e&&(be(e)||ge(e))&&ge(e.then)&&ge(e.catch),setImmediate:Je,asap:Ke,isIterable:Xe,isSafeIterable:e=>null!=e&&ae(e,oe)&&Xe(e)};const Ze=Ye.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Qe=new RegExp("[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+","g"),et=new RegExp("[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+","g");function tt(e,t){return Ye.isArray(e)?e.map(e=>tt(e,t)):function(e){let t=0,n=e.length;for(;t<n;){const n=e.charCodeAt(t);if(9!==n&&32!==n)break;t+=1}for(;n>t;){const t=e.charCodeAt(n-1);if(9!==t&&32!==t)break;n-=1}return 0===t&&n===e.length?e:e.slice(t,n)}(String(e).replace(t,""))}function nt(e){const t=Object.create(null);return Ye.forEach(e.toJSON(),(e,n)=>{t[n]=(e=>tt(e,et))(e)}),t}const rt=Symbol("internals");function ot(e){return e&&String(e).trim().toLowerCase()}function it(e){return!1===e||null==e?e:Ye.isArray(e)?e.map(it):(e=>tt(e,Qe))(String(e))}const st=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function at(e){let t=0,n=e.length;for(;t<n;){const n=e.charCodeAt(t);if(9!==n&&32!==n)break;t+=1}for(;n>t;){const t=e.charCodeAt(n-1);if(9!==t&&32!==t)break;n-=1}return 0===t&&n===e.length?e:e.slice(t,n)}function ut(e,t,n,r,o){return Ye.isFunction(r)?r.call(this,t,n):(o&&(t=n),Ye.isString(t)?Ye.isString(r)?-1!==t.indexOf(r):Ye.isRegExp(r)?r.test(t):void 0:void 0)}class lt{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=ot(t);if(!o)return;const i=Ye.findKey(r,o);(!i||void 0===r[i]||!0===n||void 0===n&&!1!==r[i])&&(r[i||t]=it(e))}const i=(e,t)=>Ye.forEach(e,(e,n)=>o(e,n,t));if(Ye.isPlainObject(e)||e instanceof this.constructor)i(e,t);else if(Ye.isString(e)&&(e=e.trim())&&!/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim()))i((e=>{const t={};let n,r,o;return e&&e.split("\n").forEach(function(e){o=e.indexOf(":"),n=e.substring(0,o).trim().toLowerCase(),r=e.substring(o+1).trim();const i=Ye.hasOwnProp(t,n);!n||i&&Ye.hasOwnProp(Ze,n)||("set-cookie"===n?i?t[n].push(r):t[n]=[r]:t[n]=i?t[n]+", "+r:r)}),t})(e),t);else if(Ye.isObject(e)&&Ye.isSafeIterable(e)){let n,r,o=Object.create(null);for(const t of e){if(!Ye.isArray(t))throw new TypeError("Object iterator must return a key-value pair");r=t[0],Ye.hasOwnProp(o,r)?(n=o[r],o[r]=Ye.isArray(n)?[...n,t[1]]:[n,t[1]]):o[r]=t[1]}i(o,t)}else null!=e&&o(t,e,n);return this}get(e,t){if(e=ot(e)){const n=Ye.findKey(this,e);if(n){const e=this[n];if(!t)return e;if(!0===t)return function(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}(e);if(Ye.isFunction(t))return t.call(this,e,n);if(Ye.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=ot(e)){const n=Ye.findKey(this,e);return!(!n||void 0===this[n]||t&&!ut(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=ot(e)){const o=Ye.findKey(n,e);!o||t&&!ut(0,n[o],o,t)||(delete n[o],r=!0)}}return Ye.isArray(e)?e.forEach(o):o(e),r}clear(e){const t=Object.keys(this);let n=t.length,r=!1;for(;n--;){const o=t[n];e&&!ut(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}normalize(e){const t=this,n={};return Ye.forEach(this,(r,o)=>{const i=Ye.findKey(n,o);if(i)return t[i]=it(r),void delete t[o];const s=e?function(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,t,n)=>t.toUpperCase()+n)}(o):String(o).trim();s!==o&&delete t[o],t[s]=it(r),n[s]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return Ye.forEach(this,(n,r)=>{null!=n&&!1!==n&&(t[r]=e&&Ye.isArray(n)?n.join(", "):n)}),t}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,t])=>e+": "+t).join("\n")}getSetCookie(){const e=this.get("set-cookie");return Ye.isArray(e)?e:null==e||!1===e?[]:[e]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static parseParameters(e){return function(e){const t=Object.create(null),n=String(e);let r=0,o=!1,i=!1;function s(e){const o=at(n.slice(r,e)),i=o.indexOf("=");if(i<1)return;const s=at(o.slice(0,i));if(!st.test(s))return;const a=s.toLowerCase();if("__proto__"===a||"constructor"===a||"prototype"===a)return;const u=at(o.slice(i+1));t[a]=function(e){const t=e.length-1;if(t<1||34!==e.charCodeAt(0)||34!==e.charCodeAt(t))return e;let n="";for(let r=1;r<t;r++){const o=e.charCodeAt(r);if(34===o)return e;if(92===o&&(r+=1,r>=t))return e;n+=e[r]}return n}(u)}for(let e=0;e<n.length;e++){const t=n.charCodeAt(e);o?i?i=!1:92===t?i=!0:34===t&&(o=!1):34===t?o=!0:44!==t&&59!==t||(s(e),r=e+1)}return s(n.length),t}(e)}static concat(e,...t){const n=new this(e);return t.forEach(e=>n.set(e)),n}static accessor(e){const t=(this[rt]=this[rt]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=ot(e);t[r]||(function(e,t){const n=Ye.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{__proto__:null,value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})})}(n,e),t[r]=!0)}return Ye.isArray(e)?e.forEach(r):r(e),this}}lt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),Ye.reduceDescriptors(lt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[n]=e}}}),Ye.freezeMethods(lt);var ct=lt;const ft="[REDACTED ****]";class dt extends Error{static from(e,t,n,r,o,i){let s=e.message;!s&&Ye.isArray(e.errors)&&e.errors.length&&(s=function(e){return e.errors.map(e=>{try{return function(e){try{return String(e)}catch(e){return""}}(e&&e.message?e.message:e)}catch(e){return""}}).filter(Boolean).join("; ")||e.name||"AggregateError"}(e));const a=new dt(s,t||e.code,n,r,o);return Object.defineProperty(a,"cause",{__proto__:null,value:e,writable:!0,enumerable:!1,configurable:!0}),a.name=e.name,null!=e.status&&null==a.status&&(a.status=e.status),i&&Object.assign(a,i),a}constructor(e,t,n,r,o){super(e),Object.defineProperty(this,"message",{__proto__:null,value:e,enumerable:!0,writable:!0,configurable:!0}),this.name="AxiosError",this.isAxiosError=!0,t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status)}toJSON(){const e=this.config,t=e&&Ye.hasOwnProp(e,"redact")?e.redact:void 0,n=Ye.isArray(t)&&t.length>0?function(e,t){const n=new Set(t.map(e=>String(e).toLowerCase())),r=[],o=e=>{if(null===e||"object"!=typeof e)return e;if(Ye.isBuffer(e))return e;if(-1!==r.indexOf(e))return;let t;if(e instanceof ct&&(e=e.toJSON()),r.push(e),Ye.isArray(e))t=[],e.forEach((e,n)=>{const r=o(e);Ye.isUndefined(r)||(t[n]=r)});else{if(!Ye.isPlainObject(e)&&function(e){if(Ye.hasOwnProp(e,"toJSON"))return!0;let t=Object.getPrototypeOf(e);for(;t&&t!==Object.prototype;){if(Ye.hasOwnProp(t,"toJSON"))return!0;t=Object.getPrototypeOf(t)}return!1}(e))return r.pop(),e;t=Object.create(null);for(const[r,i]of Object.entries(e)){const e=n.has(r.toLowerCase())?ft:o(i);Ye.isUndefined(e)||(t[r]=e)}}return r.pop(),t};return o(e)}(e,t):Ye.toJSONObject(e);return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:n,code:this.code,status:this.status}}}dt.ERR_BAD_OPTION_VALUE="ERR_BAD_OPTION_VALUE",dt.ERR_BAD_OPTION="ERR_BAD_OPTION",dt.ECONNABORTED="ECONNABORTED",dt.ETIMEDOUT="ETIMEDOUT",dt.ECONNREFUSED="ECONNREFUSED",dt.ERR_NETWORK="ERR_NETWORK",dt.ERR_FR_TOO_MANY_REDIRECTS="ERR_FR_TOO_MANY_REDIRECTS",dt.ERR_DEPRECATED="ERR_DEPRECATED",dt.ERR_BAD_RESPONSE="ERR_BAD_RESPONSE",dt.ERR_BAD_REQUEST="ERR_BAD_REQUEST",dt.ERR_CANCELED="ERR_CANCELED",dt.ERR_NOT_SUPPORT="ERR_NOT_SUPPORT",dt.ERR_INVALID_URL="ERR_INVALID_URL",dt.ERR_FORM_DATA_DEPTH_EXCEEDED="ERR_FORM_DATA_DEPTH_EXCEEDED";var ht=dt;const pt=100;function mt(e){return Ye.isPlainObject(e)||Ye.isArray(e)}function vt(e){return Ye.endsWith(e,"[]")?e.slice(0,-2):e}function gt(e,t,n){return e?e.concat(t).map(function(e,t){return e=vt(e),!n&&t?"["+e+"]":e}).join(n?".":""):t}const yt=Ye.toFlatObject(Ye,{},null,function(e){return/^is[A-Z]/.test(e)});function bt(e,t,n){if(!Ye.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const r=(n=Ye.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(e,t){return!Ye.isUndefined(t[e])})).metaTokens,o=n.visitor||h,i=n.dots,s=n.indexes,a=n.Blob||"undefined"!=typeof Blob&&Blob,u=void 0===n.maxDepth?pt:n.maxDepth,l=a&&Ye.isSpecCompliantForm(t),c=[];if(!Ye.isFunction(o))throw new TypeError("visitor must be a function");function f(e){if(null===e)return"";if(Ye.isDate(e))return e.toISOString();if(Ye.isBoolean(e))return e.toString();if(!l&&Ye.isBlob(e))throw new ht("Blob is not supported. Use a Buffer instead.");if(Ye.isArrayBuffer(e)||Ye.isTypedArray(e)){if(l&&"function"==typeof a)return new a([e]);throw new ht("Blob is not supported. Use a Buffer instead.",ht.ERR_NOT_SUPPORT)}return e}function d(e){if(e>u)throw new ht("Object is too deeply nested ("+e+" levels). Max depth: "+u,ht.ERR_FORM_DATA_DEPTH_EXCEEDED)}function h(e,n,o){let a=e;if(Ye.isReactNative(t)&&Ye.isReactNativeBlob(e))return t.append(gt(o,n,i),f(e)),!1;if(e&&!o&&"object"==typeof e)if(Ye.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=function(e,t){if(Infinity===u)return JSON.stringify(e);const n=[];return JSON.stringify(e,function(e,t){if(!Ye.isObject(t))return t;for(;n.length&&n[n.length-1]!==this;)n.pop();return n.push(t),d(1+n.length-1),t})}(e);else if(Ye.isArray(e)&&function(e){return Ye.isArray(e)&&!e.some(mt)}(e)||(Ye.isFileList(e)||Ye.endsWith(n,"[]"))&&(a=Ye.toArray(e)))return n=vt(n),a.forEach(function(e,r){!Ye.isUndefined(e)&&null!==e&&t.append(!0===s?gt([n],r,i):null===s?n:n+"[]",f(e))}),!1;return!!mt(e)||(t.append(gt(o,n,i),f(e)),!1)}const p=Object.assign(yt,{defaultVisitor:h,convertValue:f,isVisitable:mt});if(!Ye.isObject(e))throw new TypeError("data must be an object");return function e(n,r,i=0){if(!Ye.isUndefined(n)){if(d(i),-1!==c.indexOf(n))throw new Error("Circular reference detected in "+r.join("."));c.push(n),Ye.forEach(n,function(n,s){!0===(!(Ye.isUndefined(n)||null===n)&&o.call(t,n,Ye.isString(s)?s.trim():s,r,p))&&e(n,r?r.concat(s):[s],i+1)}),c.pop()}}(e),t}function wt(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+"};return encodeURIComponent(e).replace(/[!'()~]|%20/g,function(e){return t[e]})}function Pt(e,t){this._pairs=[],e&&bt(e,this,t)}const _t=Pt.prototype;function jt(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Et(e,t,n){if(!t)return e;e=e||"";const r=Ye.isFunction(n)?{serialize:n}:n,o=Ye.getSafeProp(r,"encode")||jt,i=Ye.getSafeProp(r,"serialize");let s;if(s=i?i(t,r):Ye.isURLSearchParams(t)?t.toString():new Pt(t,r).toString(o),s){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+s}return e}_t.append=function(e,t){this._pairs.push([e,t])},_t.toString=function(e){const t=e?t=>e.call(this,t,wt):wt;return this._pairs.map(function(e){return t(e[0])+"="+t(e[1])},"").join("&")};var St=class{constructor(){this.handlers=[]}use(e,t,n){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!n&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){Ye.forEach(this.handlers,function(t){null!==t&&e(t)})}},xt={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1,legacyInterceptorReqResOrdering:!0,advertiseZstdAcceptEncoding:!1,validateStatusUndefinedResolves:!0},Tt={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:Pt,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const kt="undefined"!=typeof window&&"undefined"!=typeof document,Ot="object"==typeof navigator&&navigator||void 0,Rt=kt&&(!Ot||["ReactNative","NativeScript","NS"].indexOf(Ot.product)<0);var Ut={__proto__:null,hasBrowserEnv:kt,hasStandardBrowserWebWorkerEnv:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,hasStandardBrowserEnv:Rt,navigator:Ot,origin:kt&&window.location.href||"http://localhost",...Tt};const Ct=pt;function At(e){if(e>Ct)throw new ht("FormData field is too deeply nested ("+e+" levels). Max depth: "+Ct,ht.ERR_FORM_DATA_DEPTH_EXCEEDED)}function Wt(e){function t(e,n,r,o){At(o);let i=e[o++];if("__proto__"===i)return!0;const s=Number.isFinite(+i),a=o>=e.length;return i=!i&&Ye.isArray(r)?r.length:i,a?(r[i]=Ye.hasOwnProp(r,i)?Ye.isArray(r[i])?r[i].concat(n):[r[i],n]:n,!s):(Ye.hasOwnProp(r,i)&&Ye.isObject(r[i])||(r[i]=[]),t(e,n,r[i],o)&&Ye.isArray(r[i])&&(r[i]=function(e){const t={},n=Object.keys(e);let r;const o=n.length;let i;for(r=0;r<o;r++)i=n[r],t[i]=e[i];return t}(r[i])),!s)}if(Ye.isFormData(e)&&Ye.isFunction(e.entries)){const n={};return Ye.forEachEntry(e,(e,r)=>{t(function(e){const t=[],n=/[^.[\]]+|\[([^.[\]]*)]/g;let r;for(;null!==(r=n.exec(e));)At(t.length),t.push("[]"===r[0]?"":r[1]||r[0]);return t}(e),r,n,0)}),n}return null}const Nt=(e,t)=>null!=e&&Ye.hasOwnProp(e,t)?e[t]:void 0,It={transitional:xt,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=Ye.isObject(e);if(o&&Ye.isHTMLForm(e)&&(e=new FormData(e)),Ye.isFormData(e))return r?JSON.stringify(Wt(e)):e;if(Ye.isArrayBuffer(e)||Ye.isBuffer(e)||Ye.isStream(e)||Ye.isFile(e)||Ye.isBlob(e)||Ye.isReadableStream(e))return e;if(Ye.isArrayBufferView(e))return e.buffer;if(Ye.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let i;if(o){const t=Nt(this,"formSerializer");if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return bt(e,new Ut.classes.URLSearchParams,{visitor:function(e,t,n,r){return Ut.isNode&&Ye.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)},...t})}(e,t).toString();if((i=Ye.isFileList(e))||n.indexOf("multipart/form-data")>-1){const n=Nt(this,"env"),r=n&&n.FormData;return bt(i?{"files[]":e}:e,r&&new r,t)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(Ye.isString(e))try{return(0,JSON.parse)(e),Ye.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(0,JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=Nt(this,"transitional")||It.transitional,n=t&&t.forcedJSONParsing,r=Nt(this,"responseType"),o="json"===r;if(Ye.isResponse(e)||Ye.isReadableStream(e))return e;if(e&&Ye.isString(e)&&(n&&!r||o)){const n=!(t&&t.silentJSONParsing)&&o;try{return JSON.parse(e,Nt(this,"parseReviver"))}catch(e){if(n){if("SyntaxError"===e.name)throw ht.from(e,ht.ERR_BAD_RESPONSE,this,null,Nt(this,"response"));throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Ut.classes.FormData,Blob:Ut.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};Ye.forEach(["delete","get","head","post","put","patch","query"],e=>{It.headers[e]={}});var Lt=It;function Ft(e,t){const n=this||Lt,r=t||n,o=ct.from(r.headers);let i=r.data;return Ye.forEach(e,function(e){i=e.call(n,i,o.normalize(),t?t.status:void 0)}),o.normalize(),i}function zt(e){return!(!e||!e.__CANCEL__)}var Dt=class extends ht{constructor(e,t,n){super(null==e?"canceled":e,ht.ERR_CANCELED,t,n),this.name="CanceledError",this.__CANCEL__=!0}};function Mt(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new ht("Request failed with status code "+n.status,n.status>=400&&n.status<500?ht.ERR_BAD_REQUEST:ht.ERR_BAD_RESPONSE,n.config,n.request,n)):e(n)}const Bt=(e,t,n=3)=>{let r=0;const o=function(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o,i=0,s=0;return t=void 0!==t?t:1e3,function(a){const u=Date.now(),l=r[s];o||(o=u),n[i]=a,r[i]=u;let c=s,f=0;for(;c!==i;)f+=n[c++],c%=e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),u-o<t)return;const d=l&&u-l;return d?Math.round(1e3*f/d):void 0}}(50,250);return function(n,i){let s,a,u=0,l=1e3/i;const c=(n,i=Date.now())=>{u=i,s=null,a&&(clearTimeout(a),a=null),(n=>{if(!n||"number"!=typeof n.loaded)return;const i=n.loaded,s=n.lengthComputable?n.total:void 0,a=Math.max(0,null!=s?Math.min(i,s):i),u=Math.max(0,a-r),l=o(u);r=Math.max(r,a),e({loaded:a,total:s,progress:s?a/s:void 0,bytes:u,rate:l||void 0,estimated:l&&s?(s-a)/l:void 0,event:n,lengthComputable:null!=s,[t?"download":"upload"]:!0})})(...n)};return[(...e)=>{const t=Date.now(),n=t-u;n>=l?c(e,t):(s=e,a||(a=setTimeout(()=>{a=null,c(s)},l-n)))},()=>s&&c(s)]}(0,n)},qt=(e,t)=>{const n=null!=e;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Jt=(e,t=Ye.asap)=>(...n)=>t(()=>e(...n));var Ht,Gt,Vt=Ut.hasStandardBrowserEnv?(Ht=new URL(Ut.origin),Gt=Ut.navigator&&/(msie|trident)/i.test(Ut.navigator.userAgent),e=>(e=new URL(e,Ut.origin),Ht.protocol===e.protocol&&Ht.host===e.host&&(Gt||Ht.port===e.port))):()=>!0,$t=Ut.hasStandardBrowserEnv?{write(e,t,n,r,o,i,s){if("undefined"==typeof document)return;const a=[`${e}=${encodeURIComponent(t)}`];Ye.isNumber(n)&&a.push(`expires=${new Date(n).toUTCString()}`),Ye.isString(r)&&a.push(`path=${r}`),Ye.isString(o)&&a.push(`domain=${o}`),!0===i&&a.push("secure"),Ye.isString(s)&&a.push(`SameSite=${s}`),document.cookie=a.join("; ")},read(e){if("undefined"==typeof document)return null;const t=document.cookie.split(";");for(let n=0;n<t.length;n++){const r=t[n].replace(/^\s+/,""),o=r.indexOf("=");if(-1!==o&&r.slice(0,o)===e)try{return decodeURIComponent(r.slice(o+1))}catch(e){return r.slice(o+1)}}return null},remove(e){this.write(e,"",Date.now()-864e5,"/")}}:{write(){},read:()=>null,remove(){}};const Kt=/^https?:(?!\/\/)/i,Xt=/[\t\n\r]/g;function Yt(e,t){if("string"==typeof e){const n=function(e){return function(e){let t=0;for(;t<e.length&&e.charCodeAt(t)<=32;)t++;return e.slice(t)}(e).replace(Xt,"")}(e);if(Kt.test(n))throw new ht(`Invalid URL ${JSON.stringify(function(e){const t=e.replace(/^(https?:\/{0,2})[^/?#]*@/i,`$1${ft}@`),n=t.indexOf("#"),r=(-1===n?t:t.slice(0,n)).replace(/([?&][^=&#]*=)[^&#]*/g,`$1${ft}`);return-1===n?r:`${r}#${o=t.slice(n+1),o?o.replace(/(^|&)([^=&]*=)?[^&]+/g,(e,t,n="")=>`${t}${n}${ft}`):o}`;var o}(n))}: missing "//" after protocol`,ht.ERR_INVALID_URL,t)}}function Zt(e,t,n,r){Yt(t,r);let o=!("string"==typeof(i=t)&&/^([a-z][a-z\d+\-.]*:)?\/\//i.test(i));var i;return e&&(o||!1===n)?(Yt(e,r),function(e,t){if(!t)return e;let n=e.length;for(;n>0&&47===e.charCodeAt(n-1);)n--;return e.slice(0,n)+"/"+t.replace(/^\/+/,"")}(e,t)):t}const Qt=e=>e instanceof ct?{...e}:e,en=e=>Object.getOwnPropertySymbols&&Object.getOwnPropertyDescriptor?Object.keys(e).concat(Object.getOwnPropertySymbols(e).filter(t=>Object.getOwnPropertyDescriptor(e,t).enumerable)):Object.keys(e);function tn(e,t){e=e||{},t=t||{};const n=Object.create(null);function r(e,t,n,r){return Ye.isPlainObject(e)&&Ye.isPlainObject(t)?Ye.merge.call({caseless:r},e,t):Ye.isPlainObject(t)?Ye.merge({},t):Ye.isArray(t)?t.slice():t}function o(e,t,n,o){return Ye.isUndefined(t)?Ye.isUndefined(e)?void 0:r(void 0,e,0,o):r(e,t,0,o)}function i(e,t){if(!Ye.isUndefined(t))return r(void 0,t)}function s(e,t){return Ye.isUndefined(t)?Ye.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,i){return Ye.hasOwnProp(t,i)?r(n,o):Ye.hasOwnProp(e,i)?r(void 0,n):void 0}Object.defineProperty(n,"hasOwnProperty",{__proto__:null,value:Object.prototype.hasOwnProperty,enumerable:!1,writable:!0,configurable:!0});const u={url:i,method:i,data:i,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,withXSRFToken:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,allowedSocketPaths:s,responseEncoding:s,validateStatus:a,headers:(e,t,n)=>o(Qt(e),Qt(t),0,!0)};return Ye.forEach(en({...e,...t}),function(r){if("__proto__"===r||"constructor"===r||"prototype"===r)return;const i=Ye.hasOwnProp(u,r)?u[r]:o,s=i(Ye.hasOwnProp(e,r)?e[r]:void 0,Ye.hasOwnProp(t,r)?t[r]:void 0,r);Ye.isUndefined(s)&&i!==a||(n[r]=s)}),Ye.hasOwnProp(t,"validateStatus")&&Ye.isUndefined(t.validateStatus)&&!1===function(n){const r=Ye.hasOwnProp(t,"transitional")?t.transitional:void 0;if(!Ye.isUndefined(r)){if(!Ye.isPlainObject(r))return;if(Ye.hasOwnProp(r,n))return r[n]}const o=Ye.hasOwnProp(e,"transitional")?e.transitional:void 0;if(Ye.isPlainObject(o)&&Ye.hasOwnProp(o,n))return o[n]}("validateStatusUndefinedResolves")&&(Ye.hasOwnProp(e,"validateStatus")?n.validateStatus=r(void 0,e.validateStatus):delete n.validateStatus),n}const nn=["content-type","content-length"];function rn(e){const t=tn({},e),n=e=>Ye.hasOwnProp(t,e)?t[e]:void 0,r=n("data");let o=n("withXSRFToken");const i=n("xsrfHeaderName"),s=n("xsrfCookieName");let a=n("headers");const u=n("auth"),l=n("baseURL"),c=n("allowAbsoluteUrls"),f=n("url");if(t.headers=a=ct.from(a),t.url=Et(Zt(l,f,c,t),n("params"),n("paramsSerializer")),u){const t=Ye.getSafeProp(u,"username")||"",n=Ye.getSafeProp(u,"password")||"";try{a.set("Authorization","Basic "+btoa(t+":"+(n?encodeURIComponent(n).replace(/%([0-9A-F]{2})/gi,(e,t)=>String.fromCharCode(parseInt(t,16))):"")))}catch(t){throw ht.from(t,ht.ERR_BAD_OPTION_VALUE,e)}}if(Ye.isFormData(r)&&(Ut.hasStandardBrowserEnv||Ut.hasStandardBrowserWebWorkerEnv||Ye.isReactNative(r)?a.setContentType(void 0):Ye.isFunction(r.getHeaders)&&function(e,t,n){"content-only"===n?Object.entries(t||{}).forEach(([t,n])=>{nn.includes(t.toLowerCase())&&e.set(t,n)}):e.set(t)}(a,r.getHeaders(),n("formDataHeaderPolicy"))),Ut.hasStandardBrowserEnv&&(Ye.isFunction(o)&&(o=o(t)),!0===o||null==o&&Vt(t.url))){const e=i&&s&&$t.read(s);e&&a.set(i,e)}return t}var on="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise(function(t,n){const r=rn(e);let o=r.data;const i=ct.from(r.headers).normalize();let s,a,u,l,c,{responseType:f,onUploadProgress:d,onDownloadProgress:h}=r;function p(){l&&l(),c&&c(),r.cancelToken&&r.cancelToken.unsubscribe(s),r.signal&&r.signal.removeEventListener("abort",s)}let m=new XMLHttpRequest;function v(){if(!m)return;const r=ct.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders());Mt(function(e){t(e),p()},function(e){n(e),p()},{data:f&&"text"!==f&&"json"!==f?m.response:m.responseText,status:m.status,statusText:m.statusText,headers:r,config:e,request:m}),m=null}m.open(r.method.toUpperCase(),r.url,!0),m.timeout=r.timeout,"onloadend"in m?m.onloadend=v:m.onreadystatechange=function(){m&&4===m.readyState&&(0!==m.status||m.responseURL&&m.responseURL.startsWith("file:"))&&setTimeout(v)},m.onabort=function(){m&&(n(new ht("Request aborted",ht.ECONNABORTED,e,m)),p(),m=null)},m.onerror=function(t){const r=new ht(t&&t.message?t.message:"Network Error",ht.ERR_NETWORK,e,m);r.event=t||null,n(r),p(),m=null},m.ontimeout=function(){let t=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";r.timeoutErrorMessage&&(t=r.timeoutErrorMessage),n(new ht(t,(r.transitional||xt).clarifyTimeoutError?ht.ETIMEDOUT:ht.ECONNABORTED,e,m)),p(),m=null},void 0===o&&i.setContentType(null),"setRequestHeader"in m&&Ye.forEach(nt(i),function(e,t){m.setRequestHeader(t,e)}),Ye.isUndefined(r.withCredentials)||(m.withCredentials=!!r.withCredentials),f&&"json"!==f&&(m.responseType=r.responseType),h&&([u,c]=Bt(h,!0),m.addEventListener("progress",u)),d&&m.upload&&([a,l]=Bt(d),m.upload.addEventListener("progress",a),m.upload.addEventListener("loadend",l)),(r.cancelToken||r.signal)&&(s=t=>{m&&(n(!t||t.type?new Dt(null,e,m):t),m.abort(),p(),m=null)},r.cancelToken&&r.cancelToken.subscribe(s),r.signal&&(r.signal.aborted?s():r.signal.addEventListener("abort",s)));const g=function(e){const t=/^([-+\w]{1,25}):(?:\/\/)?/.exec(e);return t&&t[1]||""}(r.url);if(g&&!Ut.protocols.includes(g))return n(new ht("Unsupported protocol "+g+":",ht.ERR_BAD_REQUEST,e)),void p();m.send(o||null)})},sn=(e,t)=>{if(e=e?e.filter(Boolean):[],!t&&!e.length)return;const n=new AbortController;let r=!1;const o=function(e){if(!r){r=!0,s();const t=e instanceof Error?e:this.reason;n.abort(t instanceof ht?t:new Dt(t instanceof Error?t.message:t))}};let i=t&&setTimeout(()=>{i=null,o(new ht(`timeout of ${t}ms exceeded`,ht.ETIMEDOUT))},t);const s=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(e=>{e.unsubscribe?e.unsubscribe(o):e.removeEventListener("abort",o)}),e=null)};e.forEach(e=>{r||(e.aborted?o.call(e):e.addEventListener("abort",o,{once:!0}))});const{signal:a}=n;return a.unsubscribe=()=>Ye.asap(s),a};const an=function*(e,t){let n=e.byteLength;if(!t||n<t)return void(yield e);let r,o=0;for(;o<n;)r=o+t,yield e.slice(o,r),o=r},un=(e,t,n,r)=>{const o=async function*(e,t){for await(const n of async function*(e){if(e[Symbol.asyncIterator])return void(yield*e);const t=e.getReader();try{for(;;){const{done:e,value:n}=await t.read();if(e)break;yield n}}finally{await t.cancel()}}(e))yield*an(n,t)}(e,t);let i,s=0,a=e=>{i||(i=!0,r&&r(e))};return new ReadableStream({async pull(e){try{const{done:t,value:r}=await o.next();if(t)return a(),void e.close();if(n){let e=s+=r.byteLength;n(e)}e.enqueue(new Uint8Array(r))}catch(e){throw a(e),e}},cancel:e=>(a(e),o.return())},{highWaterMark:2})},ln=e=>e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102,cn=(e,t,n)=>t+2<n&&ln(e.charCodeAt(t+1))&&ln(e.charCodeAt(t+2)),fn=e=>e<=57?e-48:(223&e)-55,dn=e=>e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||43===e||47===e||45===e||95===e,hn=e=>{const t=e.length;let n=0,r=0,o=!1;for(let s=0;s<t;s++){let a=e.charCodeAt(s);37===a&&cn(e,s,t)&&(a=16*fn(e.charCodeAt(s+1))+fn(e.charCodeAt(s+2)),s+=2),9!==(i=a)&&10!==i&&12!==i&&13!==i&&32!==i&&(61!==a?!dn(a)||r>0?o=!0:n++:r++)}var i;return o||r>2||r>0&&(n+r)%4!=0||n%4==1?(e=>{const t=e.length;let n=0;return t>0&&61===e.charCodeAt(t-1)&&(n++,t>1&&61===e.charCodeAt(t-2)&&n++),Math.floor(3*(t-n)/4)})(e):(e=>{const t=e%4;return 3*Math.floor(e/4)+(2===t?1:3===t?2:0)})(n)},pn="1.19.0",{isFunction:mn}=Ye,vn=e=>{if(!Ye.isString(e))return e;try{return decodeURIComponent(e)}catch(t){return e}},gn=(e,...t)=>{try{return!!e(...t)}catch(e){return!1}},yn=e=>{const t=null!=Ye.global?Ye.global:globalThis,{ReadableStream:n,TextEncoder:r}=t;e=Ye.merge.call({skipUndefined:!0},{Request:t.Request,Response:t.Response},e);const{fetch:o,Request:i,Response:s}=e,a=o?mn(o):"function"==typeof fetch,u=mn(i),l=mn(s);if(!a)return!1;const c=a&&mn(n),f=a&&("function"==typeof r?(d=new r,e=>d.encode(e)):async e=>new Uint8Array(await new i(e).arrayBuffer()));var d;const h=u&&c&&gn(()=>{let e=!1;const t=new i(Ut.origin,{body:new n,method:"POST",get duplex(){return e=!0,"half"}}),r=t.headers.has("Content-Type");return null!=t.body&&t.body.cancel(),e&&!r}),p=l&&c&&gn(()=>Ye.isReadableStream(new s("").body)),m={stream:p&&(e=>e.body)};a&&["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!m[e]&&(m[e]=(t,n)=>{let r=t&&t[e];if(r)return r.call(t);throw new ht(`Response type '${e}' is not supported`,ht.ERR_NOT_SUPPORT,n)})});const v=async e=>{if(null==e)return 0;if(Ye.isBlob(e))return e.size;if(Ye.isSpecCompliantForm(e)){const t=new i(Ut.origin,{method:"POST",body:e});return(await t.arrayBuffer()).byteLength}return Ye.isArrayBufferView(e)||Ye.isArrayBuffer(e)?e.byteLength:(Ye.isURLSearchParams(e)&&(e+=""),Ye.isString(e)?(await f(e)).byteLength:void 0)};return async e=>{let{url:t,method:n,data:a,signal:l,cancelToken:f,timeout:d,onDownloadProgress:g,onUploadProgress:y,responseType:b,headers:w,withCredentials:P="same-origin",fetchOptions:_,maxContentLength:j,maxBodyLength:E}=rn(e);const S=Ye.isNumber(j)&&j>-1,x=Ye.isNumber(E)&&E>-1;let T=o||fetch;b=b?(b+"").toLowerCase():"text";let k=sn([l,f&&f.toAbortSignal()],d),O=null;const R=k&&k.unsubscribe&&(()=>{k.unsubscribe()});let U,C=null;const A=()=>new ht("Request body larger than maxBodyLength limit",ht.ERR_BAD_REQUEST,e,O);try{let o;const l=Ye.hasOwnProp(e,"auth")?e.auth:void 0;if(l&&(o={username:Ye.getSafeProp(l,"username")||"",password:Ye.getSafeProp(l,"password")||""}),(e=>{const t=e.indexOf("://");let n=e;return-1!==t&&(n=n.slice(t+3)),n.includes("@")||n.includes(":")})(t)){const e=new URL(t,Ut.origin);o||!e.username&&!e.password||(o={username:vn(e.username),password:vn(e.password)}),(e.username||e.password)&&(e.username="",e.password="",t=e.href)}if(o&&(w.delete("authorization"),w.set("Authorization","Basic "+btoa(encodeURIComponent((o.username||"")+":"+(o.password||"")).replace(/%([0-9A-F]{2})/gi,(e,t)=>String.fromCharCode(parseInt(t,16)))))),S&&"string"==typeof t&&t.startsWith("data:")&&function(e){const t="string"==typeof e?e.indexOf("#"):-1;return((e,t)=>{if(!e||"string"!=typeof e)return 0;if(!e.startsWith("data:"))return 0;const n=e.indexOf(",");if(n<0)return 0;const r=e.slice(5,n),o=e.slice(n+1);if(/;base64/i.test(r))return t(o);let i=0;for(let e=0,t=o.length;e<t;e++){const n=o.charCodeAt(e);if(37===n&&cn(o,e,t))i+=1,e+=2;else if(n<128)i+=1;else if(n<2048)i+=2;else if(n>=55296&&n<=56319&&e+1<t){const t=o.charCodeAt(e+1);t>=56320&&t<=57343?(i+=4,e++):i+=3}else i+=3}return i})(-1===t?e:e.slice(0,t),hn)}(t)>j)throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O);if(x&&"get"!==n&&"head"!==n){const e=await v(a);if("number"==typeof e&&isFinite(e)&&(U=e,e>E))throw A()}const f=x&&(Ye.isReadableStream(a)||Ye.isStream(a)),d=(e,t,n)=>un(e,65536,e=>{if(x&&e>E)throw C=A();t&&t(e)},n);if(h&&"get"!==n&&"head"!==n&&(y||f)){if(U=null==U?await(async(e,t)=>{const n=Ye.toFiniteNumber(e.getContentLength());return null==n?v(t):n})(w,a):U,0!==U||f){let e,n=new i(t,{method:"POST",body:a,duplex:"half"});if(Ye.isFormData(a)&&(e=n.headers.get("content-type"))&&w.setContentType(e),n.body){const[e,t]=y&&qt(U,Bt(Jt(y)))||[];a=d(n.body,e,t)}}}else if(f&&!u&&c&&"get"!==n&&"head"!==n)a=d(a);else if(f&&u&&!h&&"get"!==n&&"head"!==n)throw new ht("Stream request bodies are not supported by the current fetch implementation",ht.ERR_NOT_SUPPORT,e,O);Ye.isString(P)||(P=P?"include":"omit");const W=u&&"credentials"in i.prototype;if(Ye.isFormData(a)){const e=w.getContentType();e&&/^multipart\/form-data/i.test(e)&&!/boundary=/i.test(e)&&w.delete("content-type")}w.set("User-Agent","axios/"+pn,!1);const N={..._,signal:k,method:n.toUpperCase(),headers:nt(w.normalize()),body:a,duplex:"half",credentials:W?P:void 0};O=u&&new i(t,N);let I=await(u?T(O,_):T(t,N));const L=ct.from(I.headers);if(S){const t=Ye.toFiniteNumber(L.getContentLength());if(null!=t&&t>j)throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O)}const F=p&&("stream"===b||"response"===b);if(p&&I.body&&(g||S||F&&R)){const t={};["status","statusText","headers"].forEach(e=>{t[e]=I[e]});const n=Ye.toFiniteNumber(L.getContentLength()),[r,o]=g&&qt(n,Bt(Jt(g),!0))||[];let i=0;I=new s(un(I.body,65536,t=>{if(S&&(i=t,i>j))throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O);r&&r(t)},()=>{o&&o(),R&&R()}),t)}b=b||"text";let z=await m[Ye.findKey(m,b)||"text"](I,e);if(S&&!p&&!F){let t;if(null!=z&&("number"==typeof z.byteLength?t=z.byteLength:"number"==typeof z.size?t=z.size:"string"==typeof z&&(t="function"==typeof r?(new r).encode(z).byteLength:z.length)),"number"==typeof t&&t>j)throw new ht("maxContentLength size of "+j+" exceeded",ht.ERR_BAD_RESPONSE,e,O)}return!F&&R&&R(),await new Promise((t,n)=>{Mt(t,n,{data:z,headers:ct.from(I.headers),status:I.status,statusText:I.statusText,config:e,request:O})})}catch(t){if(R&&R(),k&&k.aborted&&k.reason instanceof ht){const n=k.reason;throw n.config=e,O&&(n.request=O),t!==n&&Object.defineProperty(n,"cause",{__proto__:null,value:t,writable:!0,enumerable:!1,configurable:!0}),n}if(C)throw O&&!C.request&&(C.request=O),C;if(t instanceof ht)throw O&&!t.request&&(t.request=O),t;if(t&&"TypeError"===t.name&&/Load failed|fetch/i.test(t.message)){const n=new ht("Network Error",ht.ERR_NETWORK,e,O,t&&t.response);throw Object.defineProperty(n,"cause",{__proto__:null,value:t.cause||t,writable:!0,enumerable:!1,configurable:!0}),n}throw ht.from(t,t&&t.code,e,O,t&&t.response)}}},bn=new Map,wn=e=>{let t=e&&e.env||{};const{fetch:n,Request:r,Response:o}=t,i=[r,o,n];let s,a,u=i.length,l=bn;for(;u--;)s=i[u],a=l.get(s),void 0===a&&l.set(s,a=u?new Map:yn(t)),l=a;return a};wn();const Pn={http:null,xhr:on,fetch:{get:wn}};Ye.forEach(Pn,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{__proto__:null,value:t})}catch(e){}Object.defineProperty(e,"adapterName",{__proto__:null,value:t})}});const _n=e=>`- ${e}`,jn=e=>Ye.isFunction(e)||null===e||!1===e;var En=function(e,t){e=Ye.isArray(e)?e:[e];const{length:n}=e;let r,o;const i={};for(let s=0;s<n;s++){let n;if(r=e[s],o=r,!jn(r)&&(o=Pn[(n=String(r)).toLowerCase()],void 0===o))throw new ht(`Unknown adapter '${n}'`);if(o&&(Ye.isFunction(o)||(o=o.get(t))))break;i[n||"#"+s]=o}if(!o){const e=Object.entries(i).map(([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build"));let t=n?e.length>1?"since :\n"+e.map(_n).join("\n"):" "+_n(e[0]):"as no adapter specified";throw new ht("There is no suitable adapter to dispatch the request "+t,ht.ERR_NOT_SUPPORT)}return o};function Sn(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Dt(null,e)}function xn(e){return Sn(e),e.headers=ct.from(e.headers),e.data=Ft.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1),En(e.adapter||Lt.adapter,e)(e).then(function(t){Sn(e),e.response=t;try{t.data=Ft.call(e,e.transformResponse,t)}finally{delete e.response}return t.headers=ct.from(t.headers),t},function(t){if(!zt(t)&&(Sn(e),t&&t.response)){e.response=t.response;try{t.response.data=Ft.call(e,e.transformResponse,t.response)}finally{delete e.response}t.response.headers=ct.from(t.response.headers)}return Promise.reject(t)})}const Tn={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Tn[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});const kn={};Tn.transitional=function(e,t,n){function r(e,t){return"[Axios v"+pn+"] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,i)=>{if(!1===e)throw new ht(r(o," has been removed"+(t?" in "+t:"")),ht.ERR_DEPRECATED);return t&&!kn[o]&&(kn[o]=!0,console.warn(r(o," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(n,o,i)}},Tn.spelling=function(e){return(t,n)=>(console.warn(`${n} is likely a misspelling of ${e}`),!0)};var On={assertOptions:function(e,t,n){if("object"!=typeof e||null===e)throw new ht("options must be an object",ht.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const i=r[o],s=Object.prototype.hasOwnProperty.call(t,i)?t[i]:void 0;if(s){const t=e[i],n=void 0===t||s(t,i,e);if(!0!==n)throw new ht("option "+i+" must be "+n,ht.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new ht("Unknown option "+i,ht.ERR_BAD_OPTION)}},validators:Tn};const Rn=On.validators;class Un{constructor(e){this.defaults=e||{},this.interceptors={request:new St,response:new St}}async request(e,t){try{return await this._request(e,t)}catch(e){if(e instanceof Error){let t={};Error.captureStackTrace?Error.captureStackTrace(t):t=new Error;const n=(()=>{if(!t.stack)return"";const e=t.stack.indexOf("\n");return-1===e?"":t.stack.slice(e+1)})();try{if(e.stack){if(n){const t=n.indexOf("\n"),r=-1===t?-1:n.indexOf("\n",t+1),o=-1===r?"":n.slice(r+1);String(e.stack).endsWith(o)||(e.stack+="\n"+n)}}else e.stack=n}catch(e){}}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=tn(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;void 0!==n&&On.assertOptions(n,{silentJSONParsing:Rn.transitional(Rn.boolean),forcedJSONParsing:Rn.transitional(Rn.boolean),clarifyTimeoutError:Rn.transitional(Rn.boolean),legacyInterceptorReqResOrdering:Rn.transitional(Rn.boolean),advertiseZstdAcceptEncoding:Rn.transitional(Rn.boolean),validateStatusUndefinedResolves:Rn.transitional(Rn.boolean)},!1),null!=r&&(Ye.isFunction(r)?t.paramsSerializer={serialize:r}:On.assertOptions(r,{encode:Rn.function,serialize:Rn.function},!0)),void 0!==t.allowAbsoluteUrls||(t.allowAbsoluteUrls=void 0===this.defaults.allowAbsoluteUrls||this.defaults.allowAbsoluteUrls),On.assertOptions(t,{baseUrl:Rn.spelling("baseURL"),withXsrfToken:Rn.spelling("withXSRFToken")},!0),t.method=(t.method||this.defaults.method||"get").toLowerCase();let i=o&&Ye.merge(o.common,o[t.method]);o&&Ye.forEach(["delete","get","head","post","put","patch","query","common"],e=>{delete o[e]}),t.headers=ct.concat(i,o);const s=[];let a=!0;this.interceptors.request.forEach(function(e){if("function"==typeof e.runWhen&&!1===e.runWhen(t))return;a=a&&e.synchronous;const n=t.transitional||xt;n&&n.legacyInterceptorReqResOrdering?s.unshift(e.fulfilled,e.rejected):s.push(e.fulfilled,e.rejected)});const u=[];let l;this.interceptors.response.forEach(function(e){u.push(e.fulfilled,e.rejected)});let c,f=0;if(!a){const e=[xn.bind(this),void 0];for(e.unshift(...s),e.push(...u),c=e.length,l=Promise.resolve(t);f<c;)l=l.then(e[f++],e[f++]);return l}c=s.length;let d=t;for(;f<c;){const e=s[f++],t=s[f++];try{d=e?e(d):d}catch(e){if(!t){l=Promise.reject(e);break}try{const n=t.call(this,e);Ye.isThenable(n)&&(l=Promise.resolve(n).then(()=>xn.call(this,d)))}catch(e){l=Promise.reject(e)}break}}if(!l)try{l=xn.call(this,d)}catch(e){l=Promise.reject(e)}for(f=0,c=u.length;f<c;)l=l.then(u[f++],u[f++]);return l}getUri(e){return Et(Zt((e=tn(this.defaults,e)).baseURL,e.url,e.allowAbsoluteUrls,e),e.params,e.paramsSerializer)}}Ye.forEach(["delete","get","head","options"],function(e){Un.prototype[e]=function(t,n){return this.request(tn(n||{},{method:e,url:t,data:n&&Ye.hasOwnProp(n,"data")?n.data:void 0}))}}),Ye.forEach(["post","put","patch","query"],function(e){function t(t){return function(n,r,o){return this.request(tn(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}Un.prototype[e]=t(),"query"!==e&&(Un.prototype[e+"Form"]=t(!0))});var Cn=Un;class An{constructor(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");let t;this.promise=new Promise(function(e){t=e});const n=this;this.promise.then(e=>{if(!n._listeners)return;let t=n._listeners.length;for(;t-- >0;)n._listeners[t](e);n._listeners=null}),this.promise.then=e=>{let t;const r=new Promise(e=>{n.subscribe(e),t=e}).then(e);return r.cancel=function(){n.unsubscribe(t)},r},e(function(e,r,o){n.reason||(n.reason=new Dt(e,r,o),t(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){this.reason?e(this.reason):this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1)}toAbortSignal(){const e=new AbortController,t=t=>{e.abort(t)};return this.subscribe(t),e.signal.unsubscribe=()=>this.unsubscribe(t),e.signal}static source(){let e;return{token:new An(function(t){e=t}),cancel:e}}}var Wn=An;const Nn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511,WebServerReturnsAnUnknownError:520,WebServerIsDown:521,ConnectionTimedOut:522,OriginIsUnreachable:523,TimeoutOccurred:524,SslHandshakeFailed:525,InvalidSslCertificate:526};Object.entries(Nn).forEach(([e,t])=>{Nn[t]=e});var In=Nn;const Ln=function e(t){const n=new Cn(t),r=te(Cn.prototype.request,n);return Ye.extend(r,Cn.prototype,n,{allOwnKeys:!0}),Ye.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(tn(t,n))},r}(Lt);Ln.Axios=Cn,Ln.CanceledError=Dt,Ln.CancelToken=Wn,Ln.isCancel=zt,Ln.VERSION=pn,Ln.toFormData=bt,Ln.AxiosError=ht,Ln.Cancel=Ln.CanceledError,Ln.all=function(e){return Promise.all(e)},Ln.spread=function(e){return function(t){return e.apply(null,t)}},Ln.isAxiosError=function(e){return Ye.isObject(e)&&!0===e.isAxiosError},Ln.mergeConfig=tn,Ln.AxiosHeaders=ct,Ln.formToJSON=e=>Wt(Ye.isHTMLForm(e)?new FormData(e):e),Ln.getAdapter=En,Ln.HttpStatusCode=In,Ln.default=Ln;var Fn=Ln;const{CanceledError:zn}=Fn;var Dn=/screenshot(\-\d+?)?\.needle\.(webp|png|jpg|jpeg)/,Mn=function(e,t){try{var n=t.baseUrl+Y.jobs.post_update,r=F({},Z(t),{job_id:e.identifier,status:e.status});return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:r,body:JSON.stringify({status_message:e.status_message,error:e.error,progress:e.progress})})).catch(function(e){return console.error(e),null})).then(function(e){return!!e&&e.ok})}catch(e){return Promise.reject(e)}};function Bn(e,t,n){if(!e.s){if(n instanceof qn){if(!n.s)return void(n.o=Bn.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Bn.bind(null,e,t),Bn.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var qn=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Bn(r,1,i(this.v))}catch(e){Bn(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Bn(r,1,t?t(o):o):n?Bn(r,1,n(o)):Bn(r,2,o)}catch(e){Bn(r,2,e)}},r},e}();function Jn(e){return e instanceof qn&&1&e.s}var Hn=function(e,t){void 0===t&&(t={});try{var n,r,o=function(e){return n?e:{ok:!1,error:r,attempts:j,reason:"attempts-exhausted"}},i=t.maxAttempts,s=void 0===i?Gn:i,a=t.budgetMs,u=void 0===a?Kn:a,l=t.baseMs,c=void 0===l?Vn:l,f=t.maxMs,d=void 0===f?$n:f,h=t.isRetryable,p=void 0===h?Zn:h,m=t.sleep,v=void 0===m?Qn:m,g=t.now,y=void 0===g?Date.now:g,b=t.random,w=void 0===b?Math.random:b,P=t.onRetry,_=y(),j=0,E=function(e,t,n){for(var r;;){var o=e();if(Jn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Jn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Jn(s)){r=2;break}}}var a=new qn,u=Bn.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!Jn(s))return void s.then(f).then(void 0,u);if(!(o=e())||Jn(o)&&!o.v)return void Bn(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Jn(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):Bn(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Bn(a,1,i)}}(function(){return!n&&j<s},void 0,function(){return j++,function(t,r){try{var o=Promise.resolve(e(j)).then(function(e){return n=1,{ok:!0,value:e,attempts:j}})}catch(e){return r(e)}return o&&o.then?o.then(void 0,r):o}(0,function(e){if(r=e,!p(e))return n=1,{ok:!1,error:e,attempts:j,reason:"permanent"};if(j>=s)return n=1,{ok:!1,error:e,attempts:j,reason:"attempts-exhausted"};var t=function(e,t){void 0===t&&(t={});var n=t.baseMs,r=void 0===n?Vn:n,o=t.maxMs,i=void 0===o?$n:o,s=t.random,a=void 0===s?Math.random:s,u=Math.max(1,Math.floor(e)),l=Math.min(i,r*Math.pow(2,u-1))/2;return Math.max(1,Math.round(l+a()*l))}(j,{baseMs:c,maxMs:d,random:w});return y()-_+t>=u?(n=1,{ok:!1,error:e,attempts:j,reason:"budget-exhausted"}):(null==P||P({attempt:j,waitMs:t,error:e}),Promise.resolve(v(t)).then(function(){}))})});return Promise.resolve(E&&E.then?E.then(o):o(E))}catch(e){return Promise.reject(e)}},Gn=6,Vn=1e3,$n=15e3,Kn=9e4,Xn=new Set(["CERT_HAS_EXPIRED","UNABLE_TO_VERIFY_LEAF_SIGNATURE","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","ERR_TLS_CERT_ALTNAME_INVALID"]),Yn=new Set([408,429]);function Zn(e){var t;if(function(e){var t=null==e?void 0:e.name,n=null==e?void 0:e.code;return"CanceledError"===t||"AbortError"===t||"ERR_CANCELED"===n||"ABORT_ERR"===n}(e))return!1;var n=null==e||null==(t=e.response)?void 0:t.status;if("number"==typeof n&&n>0)return!!Yn.has(n)||!(n>=400&&n<500);var r=function(e){var t,n,r=null!=(t=null==e?void 0:e.code)?t:null==e||null==(n=e.cause)?void 0:n.code;return"string"==typeof r&&r.length?r:null}(e);return!r||!Xn.has(r)}function Qn(e){return new Promise(function(t){return setTimeout(t,e)})}function er(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function tr(e,t,n){if(!e.s){if(n instanceof nr){if(!n.s)return void(n.o=tr.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(tr.bind(null,e,t),tr.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var nr=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{tr(r,1,i(this.v))}catch(e){tr(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?tr(r,1,t?t(o):o):n?tr(r,1,n(o)):tr(r,2,o)}catch(e){tr(r,2,e)}},r},e}();function rr(e){return e instanceof nr&&1&e.s}var or,ir,sr=16777216,ar=67108864,ur=(or=function(e,t){e.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function n(e,t){var n=e[0],r=e[1],o=e[2],i=e[3];r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[0]-680876936|0)<<7|n>>>25)+r|0)&r|~n&o)+t[1]-389564586|0)<<12|i>>>20)+n|0)&n|~i&r)+t[2]+606105819|0)<<17|o>>>15)+i|0)&i|~o&n)+t[3]-1044525330|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[4]-176418897|0)<<7|n>>>25)+r|0)&r|~n&o)+t[5]+1200080426|0)<<12|i>>>20)+n|0)&n|~i&r)+t[6]-1473231341|0)<<17|o>>>15)+i|0)&i|~o&n)+t[7]-45705983|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[8]+1770035416|0)<<7|n>>>25)+r|0)&r|~n&o)+t[9]-1958414417|0)<<12|i>>>20)+n|0)&n|~i&r)+t[10]-42063|0)<<17|o>>>15)+i|0)&i|~o&n)+t[11]-1990404162|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[12]+1804603682|0)<<7|n>>>25)+r|0)&r|~n&o)+t[13]-40341101|0)<<12|i>>>20)+n|0)&n|~i&r)+t[14]-1502002290|0)<<17|o>>>15)+i|0)&i|~o&n)+t[15]+1236535329|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[1]-165796510|0)<<5|n>>>27)+r|0)&o|r&~o)+t[6]-1069501632|0)<<9|i>>>23)+n|0)&r|n&~r)+t[11]+643717713|0)<<14|o>>>18)+i|0)&n|i&~n)+t[0]-373897302|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[5]-701558691|0)<<5|n>>>27)+r|0)&o|r&~o)+t[10]+38016083|0)<<9|i>>>23)+n|0)&r|n&~r)+t[15]-660478335|0)<<14|o>>>18)+i|0)&n|i&~n)+t[4]-405537848|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[9]+568446438|0)<<5|n>>>27)+r|0)&o|r&~o)+t[14]-1019803690|0)<<9|i>>>23)+n|0)&r|n&~r)+t[3]-187363961|0)<<14|o>>>18)+i|0)&n|i&~n)+t[8]+1163531501|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[13]-1444681467|0)<<5|n>>>27)+r|0)&o|r&~o)+t[2]-51403784|0)<<9|i>>>23)+n|0)&r|n&~r)+t[7]+1735328473|0)<<14|o>>>18)+i|0)&n|i&~n)+t[12]-1926607734|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[5]-378558|0)<<4|n>>>28)+r|0)^r^o)+t[8]-2022574463|0)<<11|i>>>21)+n|0)^n^r)+t[11]+1839030562|0)<<16|o>>>16)+i|0)^i^n)+t[14]-35309556|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[1]-1530992060|0)<<4|n>>>28)+r|0)^r^o)+t[4]+1272893353|0)<<11|i>>>21)+n|0)^n^r)+t[7]-155497632|0)<<16|o>>>16)+i|0)^i^n)+t[10]-1094730640|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[13]+681279174|0)<<4|n>>>28)+r|0)^r^o)+t[0]-358537222|0)<<11|i>>>21)+n|0)^n^r)+t[3]-722521979|0)<<16|o>>>16)+i|0)^i^n)+t[6]+76029189|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[9]-640364487|0)<<4|n>>>28)+r|0)^r^o)+t[12]-421815835|0)<<11|i>>>21)+n|0)^n^r)+t[15]+530742520|0)<<16|o>>>16)+i|0)^i^n)+t[2]-995338651|0)<<23|r>>>9)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[0]-198630844|0)<<6|n>>>26)+r|0)|~o))+t[7]+1126891415|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[14]-1416354905|0)<<15|o>>>17)+i|0)|~n))+t[5]-57434055|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[12]+1700485571|0)<<6|n>>>26)+r|0)|~o))+t[3]-1894986606|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[10]-1051523|0)<<15|o>>>17)+i|0)|~n))+t[1]-2054922799|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[8]+1873313359|0)<<6|n>>>26)+r|0)|~o))+t[15]-30611744|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[6]-1560198380|0)<<15|o>>>17)+i|0)|~n))+t[13]+1309151649|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[4]-145523070|0)<<6|n>>>26)+r|0)|~o))+t[11]-1120210379|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[2]+718787259|0)<<15|o>>>17)+i|0)|~n))+t[9]-343485551|0)<<21|r>>>11)+o|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=o+e[2]|0,e[3]=i+e[3]|0}function r(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}function o(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n}function i(e){var t,o,i,s,a,u,l=e.length,c=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=l;t+=64)n(c,r(e.substring(t-64,t)));for(o=(e=e.substring(t-64)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<o;t+=1)i[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55)for(n(c,i),t=0;t<16;t+=1)i[t]=0;return s=(s=8*l).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),u=parseInt(s[1],16)||0,i[14]=a,i[15]=u,n(c,i),c}function s(e){var n,r="";for(n=0;n<4;n+=1)r+=t[e>>8*n+4&15]+t[e>>8*n&15];return r}function a(e){var t;for(t=0;t<e.length;t+=1)e[t]=s(e[t]);return e.join("")}function u(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function l(e){var t,n=[],r=e.length;for(t=0;t<r-1;t+=2)n.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,n)}function c(){this.reset()}return a(i("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function e(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(t,n){var r,o,i,s,a=this.byteLength,u=e(t,a),l=a;return void 0!==n&&(l=e(n,a)),u>l?new ArrayBuffer(0):(r=l-u,o=new ArrayBuffer(r),i=new Uint8Array(o),s=new Uint8Array(this,u,r),i.set(s),o)}}(),c.prototype.append=function(e){return this.appendBinary(u(e)),this},c.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,o=this._buff.length;for(t=64;t<=o;t+=64)n(this._hash,r(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},c.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=a(this._hash),e&&(n=l(n)),this.reset(),n},c.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},c.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},c.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},c.prototype._finish=function(e,t){var r,o,i,s=t;if(e[s>>2]|=128<<(s%4<<3),s>55)for(n(this._hash,e),s=0;s<16;s+=1)e[s]=0;r=(r=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(r[2],16),i=parseInt(r[1],16)||0,e[14]=o,e[15]=i,n(this._hash,e)},c.hash=function(e,t){return c.hashBinary(u(e),t)},c.hashBinary=function(e,t){var n=a(i(e));return t?l(n):n},(c.ArrayBuffer=function(){this.reset()}).prototype.append=function(e){var t,r,i,s,a=(r=this._buff.buffer,i=e,(s=new Uint8Array(r.byteLength+i.byteLength)).set(new Uint8Array(r)),s.set(new Uint8Array(i),r.byteLength),s),u=a.length;for(this._length+=e.byteLength,t=64;t<=u;t+=64)n(this._hash,o(a.subarray(t-64,t)));return this._buff=t-64<u?new Uint8Array(a.buffer.slice(t-64)):new Uint8Array(0),this},c.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=a(this._hash),e&&(n=l(n)),this.reset(),n},c.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.ArrayBuffer.prototype.getState=function(){var e=c.prototype.getState.call(this);return e.buff=String.fromCharCode.apply(null,new Uint8Array(e.buff)),e},c.ArrayBuffer.prototype.setState=function(e){return e.buff=function(e,t){var n,r=e.length,o=new ArrayBuffer(r),i=new Uint8Array(o);for(n=0;n<r;n+=1)i[n]=e.charCodeAt(n);return i}(e.buff),c.prototype.setState.call(this,e)},c.ArrayBuffer.prototype.destroy=c.prototype.destroy,c.ArrayBuffer.prototype._finish=c.prototype._finish,c.ArrayBuffer.hash=function(e,t){var r=a(function(e){var t,r,i,s,a,u,l=e.length,c=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=l;t+=64)n(c,o(e.subarray(t-64,t)));for(r=(e=t-64<l?e.subarray(t-64):new Uint8Array(0)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<r;t+=1)i[t>>2]|=e[t]<<(t%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55)for(n(c,i),t=0;t<16;t+=1)i[t]=0;return s=(s=8*l).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),u=parseInt(s[1],16)||0,i[14]=a,i[15]=u,n(c,i),c}(new Uint8Array(e)));return t?l(r):r},c}()},or(ir={exports:{}}),ir.exports);function lr(e,t=0){return hr(e,t,2).getUint16(0,!0)}function cr(e,t=0){return hr(e,t,4).getUint32(0,!0)}function fr(e,t=0,n=e.byteLength){const r=e.slice(t,t+n);return pr.decode(new Uint8Array(r))}function dr(e,t,n=0){if(e.length<t.length+n)return!1;for(const[r,o]of t.entries())if(null!==o&&o!==e[r+n])return!1;return!0}function hr(e,t,n){const r=e.slice(t,t+n);return new DataView(new Uint8Array(r).buffer)}const pr=new TextDecoder("utf8"),mr=[["db","application/vnd.sqlite3",[83,81,76,105,116,101,32,102,111,114,109,97,116,32,51,0]],["woff","font/woff",[119,79,70,70]],["woff2","font/woff2",[119,79,70,50]],["bmp","image/bmp",[66,77]],["gif","image/gif",[71,73,70,56,55,97]],["gif","image/gif",[71,73,70,56,57,97]],["heic","image/heic",[102,116,121,112,104,101,105],{offset:4}],["heic","image/heic",[102,116,121,112,109],{offset:4}],["ico","image/x-icon",[0,0,1,0]],["jpg","image/jpeg",[255,216,255]],["pdf","application/pdf",[37,80,68,70,45]],["png","image/png",[137,80,78,71,13,10,26,10]],["7z","application/x-7z-compressed",[55,122,188,175,39,28]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,0]],["rar","application/x-rar-compressed",[82,97,114,33,26,7,1,0]],["rtf","application/rtf",[123,92,114,116,102,49]],["bz2","application/x-bzip2",[66,90,104]],["gz","application/gzip",[31,139]],["tar","application/x-tar",[117,115,116,97,114,0,48,48],{offset:257}],["tar","application/x-tar",[117,115,116,97,114,32,32,0],{offset:257}],["tif","image/tiff",[73,73,42,0]],["tiff","image/tiff",[77,77,0,42]],["zip","application/zip",[80,75,3,4],{exact:!1}],["zip","application/zip",[80,75,5,6]],["mp3","audio/mp3",[255,251]],["mp3","audio/mp3",[255,243]],["mp3","audio/mp3",[255,242]],["mp3","audio/mp3",[73,68,51]],["mp4","video/mp4",[102,116,121,112,105,115,111,109],{offset:4}],["avi","video/x-msvideo",[82,73,70,70,null,null,null,null,65,86,73,32]],["wav","audio/wav",[82,73,70,70,null,null,null,null,87,65,86,69]],["ogx","application/ogg",[79,103,103,83],{exact:!1},[["oga","audio/ogg",[127,70,76,65,67],{offset:28}],["ogg","audio/ogg",[1,118,111,114,98,105,115],{offset:28}],["ogm","video/ogg",[1,118,105,100,101,111,0],{offset:28}],["ogv","video/ogg",[128,116,104,101,111,114,97],{offset:28}]]],["webp","image/webp",[82,73,70,70,null,null,null,null,87,69,66,80]],["psd","image/vnd.adobe.photoshop",[56,66,80,83]],["flac","audio/x-flac",[102,76,97,67]],["wasm","application/wasm",[0,97,115,109]],["deb","application/x-deb",[33,60,97,114,99,104,62,10]],["exe","application/x-msdownload",[77,90]],["exe","application/x-msdownload",[90,77]],["class","application/java-vm",[202,254,186,190]]];function vr(e){return e.flatMap(([e,t,n,r={},o=[]])=>[[e,t,n,r],...o])}function gr(e,t){const n=lr(e,26),r=fr(e,30,n),[o]=r.split("/"),i=r.endsWith(".xml");return"META-INF"===o?{ext:"jar",mime:"application/java-archive"}:"ppt"===o&&i?{ext:"pptx",mime:"application/vnd.openxmlformats-officedocument.presentationml.presentation"}:"word"===o&&i?{ext:"docx",mime:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"}:"xl"===o&&i?{ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}:"mimetype"===o?function(e,t){const n=cr(e,18),r=cr(e,22),o=lr(e,28);if(n===r){const r=fr(e,30+t+o,n);if("application/vnd.oasis.opendocument.presentation"===r)return{ext:"odp",mime:r};if("application/vnd.oasis.opendocument.spreadsheet"===r)return{ext:"ods",mime:r};if("application/vnd.oasis.opendocument.text"===r)return{ext:"odt",mime:r};if("application/epub+zip"===r)return{ext:"epub",mime:r}}}(e,n)??t:t}const yr=function(e){return vr(e).map(([e,t,n,{offset:r=0}={}])=>n.length+r).reduce((e,t)=>t>e?t:e,0)}(mr);function br(e,t){for(const[n,r,o,{exact:i=!0,offset:s=0}={},a=[]]of t)if(dr(e,o,s)){if("zip"===n&&!i)return gr(e.buffer,{ext:n,mime:r});if(!i&&a.length)for(const[t,n,r,{offset:o=0}={}]of a)if(dr(e,r,o))return{ext:t,mime:n};return{ext:n,mime:r}}}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var wr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function Pr(e){return function(e){for(var t="",n=0;n<e.length;n+=3){var r=e.charCodeAt(n),o=n+1<e.length?e.charCodeAt(n+1):0,i=n+2<e.length?e.charCodeAt(n+2):0;t+=wr[r>>2]+wr[(3&r)<<4|o>>4]+(n+1<e.length?wr[(15&o)<<2|i>>6]:"=")+(n+2<e.length?wr[63&i]:"=")}return t}(ur.ArrayBuffer.hash(e,!0))}function _r(e,t){void 0===t&&(t=void 0);var n=function(e,{extra:t=!1,hint:n}={}){const r=new Uint8Array(e.slice(0,yr));if(n){const e=function(e,{ext:t,mime:n}){return t||n?vr(e).filter(e=>e[0]===t||e[1]===n):[]}(mr,n);if(e.length>0){const t=br(r,e);if(void 0!==t)return t}}return br(r,mr)||(t?function(e){return function(e){try{const t=fr(e);if(!function(e){for(let t=0;t<e.length;t++)try{const n=e.charCodeAt(t);if(65533===n||n<=8)return!1}catch{return!1}return!0}(t))return;try{return JSON.parse(t),{ext:"json",mime:"application/json"}}catch{return{ext:"txt",mime:"text/plain"}}}catch{return}}(e)}(e):void 0)}(e);if(n)return n.mime;for(var r=new Uint8Array(e).subarray(0,4),o="",i=0;i<r.length;i++)o+=r[i].toString(16);var s="unknown";switch(o){case"676c5446":s="model/gltf-binary";break;case"89504e47":s="image/png";break;case"ffd8ffe0":case"ffd8ffe1":case"ffd8ffe2":case"ffd8ffe3":case"ffd8ffe8":s="image/jpeg";break;default:s="unknown"}return"unknown"===s&&"string"==typeof t&&(s=jr(t)),s}function jr(e){var t=e.toLowerCase(),n="";return t.endsWith(".html")||t.endsWith(".html.gz")||t.endsWith(".html.br")?n="text/html":t.endsWith(".js")||t.endsWith(".js.gz")||t.endsWith(".js.br")||t.endsWith(".mjs")||t.endsWith(".mjs.gz")||t.endsWith(".mjs.br")||t.endsWith(".cjs")||t.endsWith(".cjs.gz")||t.endsWith(".cjs.br")?n="application/javascript":t.endsWith(".wasm")?n="application/wasm":t.endsWith(".css")||t.endsWith(".css.gz")||t.endsWith(".css.br")?n="text/css":t.endsWith(".json")?n="application/json":t.endsWith(".txt")?n="text/plain":t.endsWith(".md")?n="text/markdown":t.endsWith(".yaml")||t.endsWith(".yml")?n="application/yaml":t.endsWith(".bin")?n="application/octet-stream":t.endsWith(".png")?n="image/png":t.endsWith(".jpg")||t.endsWith(".jpeg")?n="image/jpeg":t.endsWith(".gif")?n="image/gif":t.endsWith(".webp")?n="image/webp":t.endsWith(".avif")?n="image/avif":t.endsWith(".bmp")?n="image/bmp":t.endsWith(".tiff")||t.endsWith(".tif")?n="image/tiff":t.endsWith(".ico")?n="image/x-icon":t.endsWith(".svg")?n="image/svg+xml":t.endsWith(".xml")?n="application/xml":t.endsWith(".hdr")?n="image/vnd.radiance":t.endsWith(".exr")?n="image/x-exr":t.endsWith(".ktx2")?n="image/ktx2":t.endsWith(".ktx")?n="image/ktx":t.endsWith(".dds")?n="image/vnd-ms.dds":t.endsWith(".ogg")?n="audio/ogg":t.endsWith(".mp3")?n="audio/mpeg":t.endsWith(".wav")?n="audio/wave":t.endsWith(".flac")?n="audio/flac":t.endsWith(".m4a")?n="audio/mp4":t.endsWith(".aac")?n="audio/aac":t.endsWith(".mp4")?n="video/mp4":t.endsWith(".webm")?n="video/webm":t.endsWith(".mov")?n="video/quicktime":t.endsWith(".woff2")?n="font/woff2":t.endsWith(".woff")?n="font/woff":t.endsWith(".ttf")?n="font/ttf":t.endsWith(".otf")?n="font/otf":t.endsWith(".zip")?n="application/zip":t.endsWith(".glb")?n="model/gltf-binary":t.endsWith(".gltf")?n="model/gltf+json":t.endsWith(".vrm")?n="model/gltf-binary":t.endsWith(".usdz")?n="model/vnd.usdz+zip":t.endsWith(".usda")?n="model/vnd.usd-usda":t.endsWith(".usdc")?n="model/vnd.usd-usdc":t.endsWith(".usd")?n="model/vnd.usd-usd":t.endsWith(".mtl")?n="model/mtl":t.endsWith(".obj")?n="model/obj":t.endsWith(".fbx")?n="model/vnd.autodesk.fbx":t.endsWith(".stl")?n="model/stl":t.endsWith(".mtlx")?n="application/materialx+xml":t.endsWith(".ply")?n="model/ply":t.endsWith(".dae")?n="model/vnd.collada+xml":t.endsWith(".3mf")?n="model/3mf":(t.endsWith(".splat")||t.endsWith(".spz")||t.endsWith(".ksplat")||t.endsWith(".sog")||t.endsWith(".sogs"))&&(n="application/octet-stream"),n}function Er(e){return"string"==typeof e&&0!==e.length&&e.toLowerCase().endsWith(".exr")}function Sr(e){if("string"!=typeof e||0===e.length)return!1;var t=e.toLowerCase();return t.endsWith(".hdr")||t.endsWith(".hdri")}function xr(e){return"string"==typeof e&&0!==e.length&&/\.pmrem(\d+x\d+)?\.ktx2$/i.test(e)}function Tr(e,t,n){void 0===t&&(t=void 0),void 0===n&&(n=!0);var r=Math.abs(e);if(r>=1099511627776){var o=n?" TB":"";return(e/1099511627776).toFixed(void 0===t?2:t)+o}if(r>=1073741824){var i=n?" GB":"";return(e/1073741824).toFixed(void 0===t?2:t)+i}if(r>=1048576){var s=n?" MB":"";return(e/1048576).toFixed(void 0===t?1:t)+s}if(r>=1024){var a=n?" KB":"";return(e/1024).toFixed(void 0===t?0:t)+a}var u=n?" B":"";return e.toFixed(0)+u}function kr(e,t){for(var n=t;n<e.length&&0!==e[n];)n++;return n>=e.length?null:new TextDecoder("latin1").decode(e.subarray(t,n))}function Or(e){return"object"!=typeof e||null===e||Array.isArray(e)?{}:Object.fromEntries(Object.entries(e))}function Rr(e){return Array.isArray(e)?e:[]}function Ur(e){return"number"==typeof e&&Number.isSafeInteger(e)&&e>=0?e:null}function Cr(e){return Array.isArray(e)&&3===e.length&&e.every(function(e){return"number"==typeof e&&Number.isFinite(e)})?[e[0],e[1],e[2]]:null}function Ar(e){return Rr(e).filter(function(e){return"string"==typeof e})}function Wr(e,t){e.meshes+=t.meshes,e.primitives+=t.primitives,e.vertices=null===e.vertices||null===t.vertices?null:e.vertices+t.vertices,e.triangles=null===e.triangles||null===t.triangles?null:e.triangles+t.triangles}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var Nr=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];function Ir(e){var t,n=new Set([].concat(Rr(e.buffers),Rr(e.images)).map(function(e){return Or(e).uri}).filter(function(e){return"string"==typeof e&&!e.startsWith("data:")})),r=new Set,o=1;function i(e){for(var t,o=1,i=L(e);!(t=i()).done;){var s=Rr(Or(Or(Or(t.value).extensions).NEEDLE_progressive).lods).map(function(e){return Or(e).path}).filter(function(e){return"string"==typeof e});if(s.length){r.add("NEEDLE_progressive"),o=Math.max(o,s.length+1);for(var a,u=L(s);!(a=u()).done;)n.add(a.value)}}return o}o=i(Rr(e.meshes)),t=i(Rr(e.textures));for(var s,a=L(Rr(e.nodes));!(s=a()).done;){var u=Rr(Or(Or(Or(s.value).extensions).MSFT_lod).ids);u.length&&(r.add("MSFT_lod"),o=Math.max(o,u.length+1))}return{progressive:r.size>0,mechanisms:[].concat(r),meshLodLevels:o,textureLodLevels:t,dependencies:[].concat(n).sort()}}function Lr(e){var t=new Set,n=new Set,r=!1;function o(e){var n=Ur(e);null===n?r=!0:t.add(n)}for(var i,s=L(Rr(e.meshes));!(i=s()).done;)for(var a,u=L(Rr(Or(i.value).primitives));!(a=u()).done;){for(var l=Or(a.value),c=0,f=Object.values(Or(l.attributes));c<f.length;c++)o(f[c]);void 0!==l.indices&&o(l.indices);for(var d,h=L(Rr(l.targets));!(d=h()).done;)for(var p=0,m=Object.values(Or(d.value));p<m.length;p++)o(m[p]);"KHR_draco_mesh_compression"in Or(l.extensions)&&n.add("KHR_draco_mesh_compression")}for(var v,g=L(Rr(e.bufferViews));!(v=g()).done;)"EXT_meshopt_compression"in Or(Or(v.value).extensions)&&n.add("EXT_meshopt_compression");for(var y,b=Rr(e.accessors),w={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4},P={SCALAR:[1,1],VEC2:[1,2],VEC3:[1,3],VEC4:[1,4],MAT2:[2,2],MAT3:[3,3],MAT4:[4,4]},_=0,j=L(t);!(y=j()).done;){var E=Or(b[y.value]),S=Ur(E.count),x=w[String(E.componentType)],T=P[String(E.type)];if(x&&T&&null!==S){var k=T[0],O=T[1]*x;_+=S*k*(k>1?4*Math.ceil(O/4):O)}else r=!0}return{nodeCount:Rr(e.nodes).length,meshCompression:[].concat(n).sort(),geometryBytesEstimate:r||!Number.isSafeInteger(_)?null:_,geometryAssumption:"Unique dense mesh accessors, no renderer overhead"}}var Fr=function(e){try{return Promise.resolve(new Promise(function(t){return setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},zr=/*#__PURE__*/$(/^image_(\d+)_|^mesh_lod_(\d+)_/,{image_lod:1,mesh_lod:2});function Dr(e,t,n){if(!e.s){if(n instanceof Mr){if(!n.s)return void(n.o=Dr.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Dr.bind(null,e,t),Dr.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var Mr=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Dr(r,1,i(this.v))}catch(e){Dr(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Dr(r,1,t?t(o):o):n?Dr(r,1,n(o)):Dr(r,2,o)}catch(e){Dr(r,2,e)}},r},e}();function Br(e){return e instanceof Mr&&1&e.s}function qr(e){return e.includes("\\u")?JSON.parse('"'+e+'"'):decodeURIComponent(e)}function Jr(e){for(var t,n=Infinity,r=[],o=L(e);!(t=o()).done;){var i=t.value,s=i.path.split("/").length;s<n?(n=s,r=[i]):s===n&&r.push(i)}return r}var Hr,Gr=/*#__PURE__*/function(){function e(e,t){this.totalFiles=e,this.estimatedTotalSize=t,this.uploadedSize=0,this.startTime=Date.now(),this.lastUpdateTime=this.startTime,this.lastUploadedSize=0,this.speedEMA=null,this.emaFactor=.1,this.smoothedRemainingTime=null,this.recentSpeeds=new Array,this.maxRecentSpeeds=20,this.initialEstimateThreshold=.05}var t=e.prototype;return t.updateProgress=function(e){var t=Date.now(),n=(t-this.lastUpdateTime)/1e3,r=e-this.lastUploadedSize;if(this.uploadedSize=e,n>0&&r>0){this.recentSpeeds.push(r/n),this.recentSpeeds.length>this.maxRecentSpeeds&&this.recentSpeeds.shift();var o=this.recentSpeeds.reduce(function(e,t){return e+t},0)/this.recentSpeeds.length;this.speedEMA=null===this.speedEMA?o:this.emaFactor*o+(1-this.emaFactor)*this.speedEMA}this.lastUpdateTime=t,this.lastUploadedSize=e;var i,s=this.uploadedSize/this.estimatedTotalSize,a=(t-this.startTime)/1e3,u=this.speedEMA&&this.speedEMA>0?this.speedEMA:this.uploadedSize/a;return i=u>0?(this.estimatedTotalSize-this.uploadedSize)/u:Infinity,this.smoothedRemainingTime=s>=this.initialEstimateThreshold?null===this.smoothedRemainingTime?i:.9*this.smoothedRemainingTime+.1*i:a/s-a,this.smoothedRemainingTime=Math.max(this.smoothedRemainingTime,(this.estimatedTotalSize-this.uploadedSize)/u),{progress:100*s,estimatedTimeRemaining:Math.round(this.smoothedRemainingTime),estimatedTimeRemainingString:this.smoothedRemainingTime>3?this.__formatTime(this.smoothedRemainingTime):"few seconds"}},t.__formatTime=function(e){if(!isFinite(e))return"Calculating...";if(e<60)return Math.round(e)+"sec";var t=Math.floor(e/60);if(t<60)return t+"min";var n=Math.floor(t/60);if(n<24)return n+"h "+t%60+"min";var r=Math.floor(n/24);return r<=10?r+"d":"Calculating..."},e}(),Vr=function(e){void 0===e&&(e={});try{var t;return(null!=(t=e.isNode)?t:"undefined"!=typeof process&&null!=(n=process.versions)&&n.node)?Hr?Promise.resolve(Hr):Promise.resolve(Promise.all([import("node:http"),import("node:https")])).then(function(e){for(var t=e[1].default,n=new e[0].default.Agent({keepAlive:!0}),r=new t.Agent({keepAlive:!0}),o=0,i=[n,r];o<i.length;o++){var s=i[o];s.createConnection=Kr(s.createConnection,$r)}return Hr={httpAgent:n,httpsAgent:r}}):Promise.resolve({})}catch(e){return Promise.reject(e)}var n},$r=15e3;function Kr(e,t,n){return void 0===n&&(n={setTimeout:setTimeout,clearTimeout:clearTimeout}),function(r,o){var i=e.call(this,r,o);if(!i||"function"!=typeof i.once)return i;var s=n.setTimeout(function(){var e=new Error("connect timeout: no connection within "+t/1e3+"s");e.code="ETIMEDOUT",i.destroy(e)},t),a=function(){return n.clearTimeout(s)};return i.once("connect",a),i.once("secureConnect",a),i.once("error",a),i.once("close",a),i}}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));const Xr="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Yr(e,t,n){if(!e.s){if(n instanceof Zr){if(!n.s)return void(n.o=Yr.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Yr.bind(null,e,t),Yr.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var Zr=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{Yr(r,1,i(this.v))}catch(e){Yr(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Yr(r,1,t?t(o):o):n?Yr(r,1,n(o)):Yr(r,2,o)}catch(e){Yr(r,2,e)}},r},e}();function Qr(e){return e instanceof Zr&&1&e.s}function eo(e,t,n){var r,o,i=-1;return function s(a){try{for(;++i<e.length&&(!n||!n());)if((a=t(i))&&a.then){if(!Qr(a))return void a.then(s,o||(o=Yr.bind(null,r=new Zr,2)));a=a.v}r?Yr(r,1,a):r=a}catch(e){Yr(r||(r=new Zr),2,e)}}(),r}function to(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function no(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,n)}var ro=[],oo=[".html",".js",".css"],io=[".gz",".br"];function so(e){return"path"in e&&e.path?e.path:e.name}function ao(e){var t,n=null==e||null==(t=e.config)?void 0:t.url;if(!n)return null;try{return new URL(n).host}catch(e){return null}}var uo={ECONNRESET:"connection reset before the upload completed",ECONNREFUSED:"connection refused by the storage host",ECONNABORTED:"connection aborted — timed out or closed mid-request",ENOTFOUND:"DNS lookup failed for the storage host",EAI_AGAIN:"DNS lookup failed temporarily — resolver unavailable",ETIMEDOUT:"connection timed out",EPIPE:"connection closed while sending the file",EHOSTUNREACH:"storage host unreachable from this network",ENETUNREACH:"network unreachable",EPROTO:"TLS or protocol error",ERR_NETWORK:"network error — the request never reached the storage host",CERT_HAS_EXPIRED:"the TLS certificate for the storage host has expired",UNABLE_TO_VERIFY_LEAF_SIGNATURE:"the TLS certificate for the storage host could not be verified",DEPTH_ZERO_SELF_SIGNED_CERT:"a self-signed TLS certificate was presented for the storage host",SELF_SIGNED_CERT_IN_CHAIN:"a self-signed TLS certificate was presented for the storage host"};function lo(e){if(!e)return"unknown upload error";var t=[];try{var n=e.response,r=null==n?void 0:n.status,o=null==n?void 0:n.statusText;r&&t.push("HTTP "+r+(o?" "+o:""));var i=null==n?void 0:n.data;if(null!=i){var s,a,u;if("string"==typeof i)u=i;else try{u=JSON.stringify(i)}catch(e){u=String(i)}var l=null==(s=u.match(/<Code>([^<]+)<\/Code>/))?void 0:s[1],c=null==(a=u.match(/<Message>([^<]+)<\/Message>/))?void 0:a[1];if(l)t.push("S3 "+l+(c?": "+c:""));else if(function(e){return/^\s*(<!DOCTYPE\s+html|<html[\s>])/i.test(e)}(u)){var f=ao(e);t.push("blocked by a network filter or proxy"+(f?" before it reached "+f:"")+" — ask your network administrator to allow this host")}else u&&t.push(u.slice(0,200))}var d=null;if(!n&&(d=function(e){var t,n,r=null!=(t=null==e?void 0:e.code)?t:null==e||null==(n=e.cause)?void 0:n.code;return"string"==typeof r&&r.length?r:null}(e),d)){var h=uo[d];t.push(h?d+" ("+h+")":d);var p=ao(e);p&&t.push("while uploading to "+p)}var m=e.message?String(e.message):"",v=r&&/^Request failed with status code \d+$/.test(m)||null!==d&&m.includes(d);m&&!v&&t.push(m)}catch(e){}return 0===t.length&&e.message&&t.push(String(e.message)),t.length?t.join(" — "):"unknown upload error"}var co=12e4;function fo(e,t){var n=null,r=!1,o=function(){n&&(clearTimeout(n),n=null)};return{reset:function(){r||(o(),n=setTimeout(function(){r=!0,n=null,t()},e))},cancel:o}}var ho="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function po(e,t,n){if(!e.s){if(n instanceof mo){if(!n.s)return void(n.o=po.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(po.bind(null,e,t),po.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var mo=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{po(r,1,i(this.v))}catch(e){po(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?po(r,1,t?t(o):o):n?po(r,1,n(o)):po(r,2,o)}catch(e){po(r,2,e)}},r},e}();function vo(e){return e instanceof mo&&1&e.s}function go(e,t,n){if(!e.s){if(n instanceof yo){if(!n.s)return void(n.o=go.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(go.bind(null,e,t),go.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var yo=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{go(r,1,i(this.v))}catch(e){go(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?go(r,1,t?t(o):o):n?go(r,1,n(o)):go(r,2,o)}catch(e){go(r,2,e)}},r},e}();function bo(e){return e instanceof yo&&1&e.s}function wo(e,t,n){if(!e.s){if(n instanceof Po){if(!n.s)return void(n.o=wo.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(wo.bind(null,e,t),wo.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var Po=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,n){var r=new e,o=this.s;if(o){var i=1&o?t:n;if(i){try{wo(r,1,i(this.v))}catch(e){wo(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?wo(r,1,t?t(o):o):n?wo(r,1,n(o)):wo(r,2,o)}catch(e){wo(r,2,e)}},r},e}();function _o(e){return e instanceof Po&&1&e.s}var jo=function(e,t,n,r,o){try{var i=new URL(""+e.baseUrl+t+"/"+encodeURIComponent(n));return Promise.resolve(fetch(i,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(null!=r?r:{})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to "+o+" project ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},Eo=function(e,t,n,r,o){try{var i=Z(e),s=new Headers({authorization:i.authorization,"content-type":"application/json"});i["x-needle-cloud-org"]&&s.set("x-needle-cloud-org",i["x-needle-cloud-org"]);var a="POST"===r&&("records"===n||"reports"===n),u=o&&"object"==typeof o?o:{},l=a?F({},u,{application:"application"in u&&void 0!==u.application?u.application:"needle-editor",kind:"records"===n?"record":"report",project_id:t}):o,c=a?e.baseUrl+"/v1/diagnostics":e.baseUrl+"/v1/projects/"+encodeURIComponent(null!=t?t:"")+"/diagnostics/"+n;return Promise.resolve(fetch(c,F({},Q,{method:r,headers:s,signal:AbortSignal.timeout(3e4)},void 0===o?{}:{body:JSON.stringify(l)}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Diagnostics request failed ("+e.status+")")})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}};function So(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function xo(e){return"number"==typeof e&&Number.isSafeInteger(e)&&e>=0}function To(e){if(!(So(e)&&xo(e.requestIndex)&&!(e.requestIndex<1)&&"string"==typeof e.model&&e.model&&xo(e.requestBytes)&&xo(e.messagesBytes)&&xo(e.toolsBytes)&&xo(e.messageCount)&&xo(e.toolCount)&&So(e.messageRoles)))throw new Error("Invalid chat request diagnostics");for(var t=Object.create(null),n=0,r=0,o=Object.entries(e.messageRoles);r<o.length;r++){var i=o[r],s=i[0],a=i[1];if(!xo(a))throw new Error("Invalid chat request diagnostic role count");t[s]=a,n+=a}if(n!==e.messageCount)throw new Error("Inconsistent chat request diagnostic message count");return{requestIndex:e.requestIndex,model:e.model,requestBytes:e.requestBytes,messagesBytes:e.messagesBytes,toolsBytes:e.toolsBytes,messageCount:e.messageCount,toolCount:e.toolCount,messageRoles:t}}function ko(e){var t;try{t=JSON.parse(e)}catch(e){return null}if(!(t&&"object"==typeof t&&"code"in t&&"ai_allowance_exhausted"===t.code&&"limit_reached"in t&&!0===t.limit_reached&&"message"in t&&"string"==typeof t.message&&"account_id"in t&&"string"==typeof t.account_id&&"actions"in t&&Array.isArray(t.actions)))return null;for(var n,r=[],o=L(t.actions);!(n=o()).done;){var i=n.value;if(!i||"object"!=typeof i||!("kind"in i)||"top_up"!==i.kind&&"view_usage"!==i.kind||!("label"in i)||"string"!=typeof i.label||!("url"in i)||"string"!=typeof i.url)return null;var s=void 0;try{s=new URL(i.url)}catch(e){return null}if("https:"!==s.protocol&&"http:"!==s.protocol)return null;r.push({kind:i.kind,label:i.label,url:i.url})}return{code:t.code,limit_reached:!0,message:t.message,account_id:t.account_id,actions:r}}var Oo=/*#__PURE__*/function(e){function t(t,n,r){var o;return void 0===r&&(r=null),(o=e.call(this,t)||this).name="AIChatError",o.status=n,o.details=r,o}return D(t,e),t}(/*#__PURE__*/V(Error)),Ro=["chat_url"];function Uo(e){return Co.apply(this,arguments)}function Co(){return Co=H(/*#__PURE__*/q().mark(function e(t){var n,r,o,i,s,a,u,l,c,f;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=t.getReader(),r=new TextDecoder,o="",e.prev=3;case 4:return e.next=7,I(n.read());case 7:if(s=(i=e.sent).value,!i.done){e.next=12;break}return e.abrupt("break",26);case 12:o+=r.decode(s,{stream:!0}),a=o.split("\n\n"),o=a.pop()||"",u=L(a);case 16:if((l=u()).done){e.next=24;break}if(!(c=Ao(l.value))){e.next=22;break}return e.next=22,c;case 22:e.next=16;break;case 24:e.next=4;break;case 26:if(!o.trim()){e.next=31;break}if(!(f=Ao(o))){e.next=31;break}return e.next=31,f;case 31:return e.prev=31,n.releaseLock(),e.finish(31);case 34:case"end":return e.stop()}},e,null,[[3,,31,34]])})),Co.apply(this,arguments)}function Ao(e){for(var t,n=null,r="",o=void 0,i=L(e.split("\n"));!(t=i()).done;){var s=t.value;s.startsWith("event: ")?n=s.slice(7).trim():s.startsWith("data: ")?r=s.slice(6):s.startsWith("id: ")&&(o=parseInt(s.slice(4).trim(),10))}if(!n)return null;var a=null;switch(n){case"request_diagnostics":a={type:"request_diagnostics",diagnostics:To(JSON.parse(r))};break;case"delta":a={type:"delta",content:decodeURIComponent(r)};break;case"message":a={type:"message",content:decodeURIComponent(r)};break;case"status":a={type:"status",message:decodeURIComponent(r)};break;case"error":var u=decodeURIComponent(r),l=ko(u);a=l?{type:"error",message:l.message,details:l}:{type:"error",message:u};break;case"notice":a={type:"notice",message:decodeURIComponent(r)};break;case"stopped":a={type:"stopped"};break;case"tool-input-available":case"tool-output-available":a=F({},JSON.parse(r),{type:n});break;case"tool_call":a=F({type:"tool_call"},JSON.parse(r));break;case"tool_result":a=F({type:"tool_result"},JSON.parse(r));break;case"file_change":a=F({type:"file_change"},JSON.parse(r));break;case"local_preview":a=F({type:"local_preview"},JSON.parse(r));break;case"message_inserted":a=F({type:"message_inserted"},JSON.parse(r));break;case"elicitation":a=F({type:"elicitation"},JSON.parse(r));break;case"done":var c=JSON.parse(r),f=c.chat_url;a={type:"done",token_usage:B(c,Ro)},f&&(a.chat_url=f);break;case"message_id":a={type:"message_id",message_id:decodeURIComponent(r)};break;case"chat_id":a={type:"chat_id",chat_id:decodeURIComponent(r)}}return a&&void 0!==o&&(a.id=o),a}function Wo(e,t){var n,r,o=Z(e);return null!=t&&t.personal&&(o["x-needle-ai-chat"]="personal"),null!=t&&t.instanceId&&(o["x-needle-instance-id"]=t.instanceId),!0===(null==t||null==(n=t.capabilities)?void 0:n.questionForms)&&(o["x-needle-chat-question-forms"]="1"),!0===(null==t||null==(r=t.capabilities)?void 0:r.inlineToolCalls)&&(o["x-needle-chat-inline-tools"]="1"),o}var No=function(e,t){try{var n=new URL(e.baseUrl+Y.ai.chat),r=Wo(e,t);return r["Content-Type"]="application/json",Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:r,body:JSON.stringify({type:"new_message",slug:t.slug,message:t.message,stream:!1,project_id:t.projectId,source:t.source,allow_file_edits:!0===t.allowFileEdits,file_edit_session_id:!0===t.allowFileEdits?t.fileEditSessionId:void 0,allow_local_commands:!0===t.allowLocalCommands,local_command_session_id:!0===t.allowLocalCommands?t.localCommandSessionId:void 0,full_url:t.full_url,pathname:t.pathname,context:t.context,disabled_tools:t.disabled_tools,tool_policy:t.toolPolicy})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Oo("Failed to send chat message ("+e.status+"): "+t,e.status,ko(t))})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},Io=function(e,t,n){try{return null!=n&&n.reconnect?function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)),o=Wo(e,n);return o.Accept="text/event-stream",Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:o,signal:null==n?void 0:n.signal}))).then(function(e){var t;return e.ok&&null!=(t=e.headers.get("content-type"))&&t.includes("text/event-stream")&&e.body?Uo(e.body):null})}catch(e){return Promise.reject(e)}}(e,t,n):function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t));null!=(null==n?void 0:n.limit)&&r.searchParams.set("limit",String(n.limit)),null!=(null==n?void 0:n.offset)&&r.searchParams.set("offset",String(n.offset));var o=Wo(e,n);return Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:o}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to read chat ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,n)}catch(e){return Promise.reject(e)}},Lo=function(e){try{var t=new URL(e.baseUrl+Y.ai.list_chats);void 0!==e.limit&&t.searchParams.set("limit",String(e.limit)),void 0!==e.chatId&&t.searchParams.set("chat_id",e.chatId),void 0!==e.projectId&&t.searchParams.set("project_id",e.projectId);var n=Wo(e);return Promise.resolve(fetch(t,F({},Q,{method:"GET",headers:n}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to list chats ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}};function Fo(e,t){return t.stream?function(e,t){return zo.apply(this,arguments)}(e,t):No(e,t)}function zo(){return(zo=H(/*#__PURE__*/q().mark(function e(t,n){var r,o,i,s,a;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new URL(t.baseUrl+Y.ai.chat),(o=Wo(t,n))["Content-Type"]="application/json",i={type:"new_message",slug:n.slug,message:n.message,stream:!0,project_id:n.projectId,source:n.source,allow_file_edits:!0===n.allowFileEdits,file_edit_session_id:!0===n.allowFileEdits?n.fileEditSessionId:void 0,allow_local_commands:!0===n.allowLocalCommands,local_command_session_id:!0===n.allowLocalCommands?n.localCommandSessionId:void 0,full_url:n.full_url,pathname:n.pathname,context:n.context,disabled_tools:n.disabled_tools,tool_policy:n.toolPolicy},e.next=6,I(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(i)})));case 6:if((s=e.sent).ok){e.next=12;break}return e.next=10,I(s.text());case 10:throw new Oo("Failed to stream chat message ("+s.status+"): "+(a=e.sent),s.status,ko(a));case 12:if(s.body){e.next=14;break}throw new Error("Response body is null — streaming not supported in this environment");case 14:return e.delegateYield(A(W(Uo(s.body))),"t0",15);case 15:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Do(e,t){return Mo.apply(this,arguments)}function Mo(){return(Mo=H(/*#__PURE__*/q().mark(function e(t,n){var r,o,i,s,a;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new URL(t.baseUrl+Y.ai.chat),(o=Wo(t,n))["Content-Type"]="application/json",i={type:"elicitation_response",slug:n.slug,action_id:n.action_id,value:n.value,text:n.text,answers:n.answers,canceled:n.canceled,file_edit_session_id:n.fileEditSessionId,local_command_session_id:n.localCommandSessionId,allow_file_edits:!0===n.allowFileEdits,allow_local_commands:!0===n.allowLocalCommands,full_url:n.full_url,stream:!0},e.next=6,I(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(i)})));case 6:if((s=e.sent).ok){e.next=12;break}return e.next=10,I(s.text());case 10:throw new Oo("Failed to send elicitation response ("+s.status+"): "+(a=e.sent),s.status,ko(a));case 12:if(s.body){e.next=14;break}throw new Error("Response body is null — streaming not supported in this environment");case 14:return e.delegateYield(A(W(Uo(s.body))),"t0",15);case 15:case"end":return e.stop()}},e)}))).apply(this,arguments)}var Bo=/*#__PURE__*/function(e){function t(t,n,r,o){var i;return(i=e.call(this,t,n,"Evaluation failed ("+t+"): "+r)||this).name="AIEvaluationError",i.code=o,i.details=ko(n),i}return D(t,e),t}(X),qo=function(){var e=globalThis.crypto;if(null!=e&&e.randomUUID)return e.randomUUID();var t=new Uint8Array(16);if(null!=e&&e.getRandomValues)e.getRandomValues(t);else for(var n=0;n<16;n++)t[n]=Math.floor(256*Math.random());t[6]=15&t[6]|64,t[8]=63&t[8]|128;var r=Array.from(t,function(e){return e.toString(16).padStart(2,"0")}).join("");return r.slice(0,8)+"-"+r.slice(8,12)+"-"+r.slice(12,16)+"-"+r.slice(16,20)+"-"+r.slice(20)}();function Jo(e){if("string"!=typeof e||0===e.length)return null;try{return new URL(e).host}catch(e){return null}}function Ho(e,t){var n,r=t||{},o=r.source,i=void 0===o?"sdk":o,s=r.tools,a=void 0===s?[]:s,u=r.toolCatalog,l=r.onToolRequest,c=r.toolReadyTimeout,f=void 0===c?5e3:c,d=r.personal,h=void 0!==d&&d,p=r.capabilities,m=r.createWebSocket,v=void 0===(null==t?void 0:t.toolPolicy)?void 0:structuredClone(t.toolPolicy),g=null,y=null,b=null,w=!1;function P(e){return _.apply(this,arguments)}function _(){return(_=H(/*#__PURE__*/q().mark(function e(t){var n,r,o,i,s,a;return q().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=!1,r=!1,e.prev=2,i=W(t);case 4:return e.next=6,I(i.next());case 6:if(!(n=!(s=e.sent).done)){e.next=14;break}return"done"===(a=s.value).type&&(g=a.token_usage,a.chat_url&&(y=a.chat_url)),e.next=11,a;case 11:n=!1,e.next=4;break;case 14:e.next=20;break;case 16:e.prev=16,e.t0=e.catch(2),r=!0,o=e.t0;case 20:if(e.prev=20,e.prev=21,!n||null==i.return){e.next=25;break}return e.next=25,I(i.return());case 25:if(e.prev=25,!r){e.next=28;break}throw o;case 28:return e.finish(25);case 29:return e.finish(20);case 30:case"end":return e.stop()}},e,null,[[2,16,20,30],[21,,25,29]])}))).apply(this,arguments)}n=a.length>0?new Promise(function(t,n){var r=null;f>0&&(r=setTimeout(function(){n(new Error("ChatSession: WebSocket tool connection timed out after "+f+"ms. Tools will not be available for this chat session."))},f)),b=function(e,t){var n=t.source,r=void 0===n?"editor":n,o=t.tools,i=t.toolCatalog,s=t.onToolRequest,a=t.onOpen,u=t.onClose,l=t.onError,c=t.reconnect,f=void 0===c||c,d=t.reconnectInterval,h=void 0===d?3e3:d,p=t.maxReconnectAttempts,m=void 0===p?10:p,v=t.heartbeatInterval,g=void 0===v?3e4:v,y=t.heartbeatTimeout,b=void 0===y?75e3:y,w=t.createWebSocket,P=void 0===w?function(e){return new WebSocket(e)}:w,_=qo,j=null,E=!1,S=0,x=null,T=null,k=0,O=!1,R=3,U=0,C=[].concat(void 0===o?[]:o),A=i?[].concat(i):void 0,W=!1,N=null,I=null;if("undefined"!=typeof document&&"function"==typeof document.addEventListener){var L=function(t){var n,r,o,i;r=e.baseUrl,o=Jo(null==(n=t)?void 0:n.blockedURI),i=Jo(r),null!==o&&null!==i&&o===i&&(N=t)};document.addEventListener("securitypolicyviolation",L),I=function(){return document.removeEventListener("securitypolicyviolation",L)}}function z(e){j&&1===j.readyState&&j.send(JSON.stringify(e))}function D(){z(F({type:"register",source:r,instanceId:_,tools:W&&A?A:C},W&&A?{discoveryOwner:"cloud"}:{}))}function M(){T&&(clearInterval(T),T=null)}function B(){!E&&f&&(x||(S>=m?null==l||l(new Error("Max reconnect attempts ("+m+") reached")):(S++,x=setTimeout(function(){x=null,q()},h))))}function q(){if(!E){if(j){try{j.close(1e3,"client reconnecting")}catch(e){}j=null}var t=function(){var t=""+e.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")+Y.ai.ws+"?token="+encodeURIComponent(e.authToken);return e.org&&(t+="&org="+encodeURIComponent(e.org)),t+"&instance="+encodeURIComponent(_)}();(j=P(t)).onopen=function(){W=!1,S=0,D(),M(),g&&b&&(k=Date.now(),O=!1,U=0,T=setInterval(function(){if(!E&&j){if(Date.now()-k>b){if(!O)return void(++U>=R&&M());M();var e=j;j=null;try{e.close(1e3,"heartbeat timeout")}catch(e){}return null==u||u(),void B()}z({type:"ping"})}},g)),null==a||a()},j.onmessage=function(e){k=Date.now();var t="string"==typeof e.data?e.data:String(e.data);!O&&t.includes('"pong"')&&(O=!0),function(e){try{var t,n=JSON.parse(e);if("registered"===n.type&&1===(null==(t=n.capabilities)?void 0:t.toolDiscovery)&&A&&!W&&(W=!0,D()),"execute_tool"===n.type&&n.requestId&&n.toolName){var r=n.requestId,o=n.toolName,i=n.args||{},a=F({chatId:"string"==typeof n.chatId&&n.chatId?n.chatId:null,requestId:r},Array.isArray(n.allowedSdkMethods)?{allowedSdkMethods:n.allowedSdkMethods.filter(function(e){return"string"==typeof e})}:{});if(!s)return void z({type:"tool_error",requestId:r,error:"No tool handler registered"});Promise.resolve().then(function(){return s(o,i,a)}).then(function(e){if(e.error)z({type:"tool_error",requestId:r,error:e.error});else{var t=Array.isArray(e.images)&&e.images.length>0?e.images:void 0;z(F({type:"tool_result",requestId:r,result:e.result},t?{images:t}:{}))}}).catch(function(e){z({type:"tool_error",requestId:r,error:(null==e?void 0:e.message)||String(e)})})}}catch(e){}}(t)},j.onclose=function(e){var t,n;j=null,M(),null==u||u(),"replaced"!==("string"==typeof(null==e?void 0:e.reason)?e.reason:null!=(t=null==e||null==(n=e.reason)||null==n.toString?void 0:n.toString())?t:"")&&4001!==(null==e?void 0:e.code)?B():E=!0},j.onerror=function(t){null==l||l((null==t?void 0:t.error)||function(e,t){var n=String(null!=e?e:"").replace(/\/+$/,"");if(!t)return new Error("WebSocket error: can not connect to "+n+". Please try again later.");var r="string"==typeof t.violatedDirective&&t.violatedDirective?t.violatedDirective:"connect-src",o="string"==typeof t.documentHost&&t.documentHost||Jo(t.documentURI)||"this page";return new Error("Blocked by the Content Security Policy of "+o+": it does not allow connections to "+n+" (violated "+r+"). This is a restriction of the page you are on, not a problem with Needle Cloud, so retrying will not help. Allow "+n+" in that page's "+r+", or use the inspector on another page.")}(e.baseUrl,N))}}}return q(),{instanceId:_,updateTools:function(e,t){C=[].concat(e),void 0!==t&&(A=[].concat(t)),D()},sendPresence:function(e){z(F({type:"presence"},e))},close:function(){E=!0,M(),x&&(clearTimeout(x),x=null),I&&(I(),I=null),j&&(j.close(1e3,"client closed"),j=null)},get connected(){return null!==j&&1===j.readyState}}}(e,F({source:i,tools:a,toolCatalog:u,onToolRequest:l},m?{createWebSocket:m}:{},{onOpen:function(){r&&clearTimeout(r),t()},onError:function(e){r&&clearTimeout(r),n(new Error("ChatSession: WebSocket tool connection failed: "+e.message))}}))}):Promise.resolve();var j={get ready(){return n},sendMessage:function(t,r,o){return H(/*#__PURE__*/q().mark(function s(){var a,u,l;return q().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,I(n);case 2:if(!w){s.next=4;break}throw new Error("ChatSession is closed");case 4:return l=Fo(e,{slug:t,message:r,stream:!0,projectId:null==o?void 0:o.projectId,source:i,allowFileEdits:!0===(null==o?void 0:o.allowFileEdits),fileEditSessionId:null==o?void 0:o.fileEditSessionId,allowLocalCommands:!0===(null==o?void 0:o.allowLocalCommands),localCommandSessionId:null==o?void 0:o.localCommandSessionId,personal:h,capabilities:p,instanceId:null!=(a=null==(u=b)?void 0:u.instanceId)?a:null,full_url:null==o?void 0:o.full_url,pathname:null==o?void 0:o.pathname,context:null==o?void 0:o.context,disabled_tools:null==o?void 0:o.disabled_tools,toolPolicy:v}),s.delegateYield(A(W(P(l))),"t0",6);case 6:case"end":return s.stop()}},s)}))()},sendElicitationResponse:function(t,r,o){return H(/*#__PURE__*/q().mark(function s(){var a,u;return q().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,I(n);case 2:if(!w){s.next=4;break}throw new Error("ChatSession is closed");case 4:return s.delegateYield(A(W(P(Do(e,F({slug:t},r,{source:i,personal:h,capabilities:p,instanceId:null!=(a=null==(u=b)?void 0:u.instanceId)?a:null,full_url:null==o?void 0:o.full_url,allowFileEdits:!0===(null==o?void 0:o.allowFileEdits),fileEditSessionId:null==o?void 0:o.fileEditSessionId,allowLocalCommands:!0===(null==o?void 0:o.allowLocalCommands),localCommandSessionId:null==o?void 0:o.localCommandSessionId}))))),"t0",5);case 5:case"end":return s.stop()}},s)}))()},sendMessageSync:function(t,r,o){return Promise.resolve(n).then(function(){var n,s;if(w)throw new Error("ChatSession is closed");return Promise.resolve(Fo(e,{slug:t,message:r,stream:!1,projectId:null==o?void 0:o.projectId,source:i,allowFileEdits:!0===(null==o?void 0:o.allowFileEdits),fileEditSessionId:null==o?void 0:o.fileEditSessionId,allowLocalCommands:!0===(null==o?void 0:o.allowLocalCommands),localCommandSessionId:null==o?void 0:o.localCommandSessionId,personal:h,capabilities:p,instanceId:null!=(n=null==(s=b)?void 0:s.instanceId)?n:null,full_url:null==o?void 0:o.full_url,pathname:null==o?void 0:o.pathname,context:null==o?void 0:o.context,disabled_tools:null==o?void 0:o.disabled_tools,toolPolicy:v})).then(function(e){return e.token_usage&&(g=e.token_usage),e.chat_url&&(y=e.chat_url),e})})},interruptChat:function(t){try{return Promise.resolve(function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat_stop),o=Wo(e,n);return o["Content-Type"]="application/json",Promise.resolve(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify({slug:t})}))).then(function(e){return function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to interrupt chat ("+e.status+"): "+t)})}()})}catch(e){return Promise.reject(e)}}(e,t,{personal:h}))}catch(e){return Promise.reject(e)}},listTools:function(t,r){try{if(w)throw new Error("ChatSession is closed");return Promise.resolve(n).then(function(){var n,o;return function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)+"/tools");return void 0!==(null==n?void 0:n.cursor)&&r.searchParams.set("cursor",n.cursor),void 0!==(null==n?void 0:n.limit)&&r.searchParams.set("limit",String(n.limit)),Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:Wo(e,n)}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Oo("Could not list chat tools ("+e.status+"): "+t,e.status)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,F({},r,{personal:h,instanceId:null!=(n=null==(o=b)?void 0:o.instanceId)?n:null}))})}catch(e){return Promise.reject(e)}},updateToolPreferences:function(t,r){try{if(w)throw new Error("ChatSession is closed");return Promise.resolve(n).then(function(){var n,o;return function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)+"/tools"),i=Wo(e,r);return i["Content-Type"]="application/json",Promise.resolve(fetch(o,F({},Q,{method:"PATCH",headers:i,body:JSON.stringify(n)}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Oo("Could not save chat tool preferences ("+e.status+"): "+t,e.status)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,r,{personal:h,instanceId:null!=(n=null==(o=b)?void 0:o.instanceId)?n:null})})}catch(e){return Promise.reject(e)}},enqueueMessage:function(t,n){try{return Promise.resolve(function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.ai.chat_enqueue),i=Wo(e,r);return i["Content-Type"]="application/json",Promise.resolve(fetch(o,F({},Q,{method:"POST",headers:i,body:JSON.stringify({slug:t,id:n.id,content:n.content})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to enqueue chat message ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,n,{personal:h}))}catch(e){return Promise.reject(e)}},cancelEnqueuedMessage:function(t,n){try{return Promise.resolve(function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.ai.chat_enqueue_cancel),i=Wo(e,r);return i["Content-Type"]="application/json",Promise.resolve(fetch(o,F({},Q,{method:"POST",headers:i,body:JSON.stringify({slug:t,id:n})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to cancel queued chat message ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(e,t,n,{personal:h}))}catch(e){return Promise.reject(e)}},readChat:function(t,n){try{return Promise.resolve(Io(e,t,{offset:null==n?void 0:n.offset,limit:null==n?void 0:n.limit,personal:h,capabilities:p})).then(function(e){return e.chat_url&&(y=e.chat_url),e})}catch(e){return Promise.reject(e)}},reconnectChat:function(t){try{return Promise.resolve(Io(e,t,{personal:h,capabilities:p,reconnect:!0})).then(function(e){return e?P(e):null})}catch(e){return Promise.reject(e)}},associateProject:function(t,n){try{if(w)throw new Error("ChatSession is closed");return Promise.resolve(function(e,t,n,r){try{return Promise.resolve(fetch(e.baseUrl+Y.ai.chat+"/"+encodeURIComponent(t)+"/projects",F({},Q,{method:"POST",headers:F({},Wo(e,r),{"Content-Type":"application/json"}),body:JSON.stringify({project_id:n})}))).then(function(e){return function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to associate chat project ("+e.status+"): "+t)})}()})}catch(e){return Promise.reject(e)}}(e,t,n,{personal:h})).then(function(){})}catch(e){return Promise.reject(e)}},listChats:function(t){try{return Promise.resolve(Lo(F({},e,{projectId:null==t?void 0:t.projectId})))}catch(e){return Promise.reject(e)}},newChat:function(){return(t=null==(e=globalThis.crypto)||null==e.randomUUID?void 0:e.randomUUID())?"chat-"+t:"chat-"+Date.now().toString(36)+"-"+Math.random().toString(36).slice(2,10);var e,t},updateTools:function(e,t){b&&b.updateTools(e,t)},get usage(){return g},get chatUrl(){return y},get toolsConnected(){var e,t;return null!=(e=null==(t=b)?void 0:t.connected)&&e},get instanceId(){var e,t;return null!=(e=null==(t=b)?void 0:t.instanceId)?e:null},close:function(){w=!0,b&&(b.close(),b=null)}};return j}var Go=function(e,t){try{var n;return Promise.resolve((null!=(n=e.fetch)?n:globalThis.fetch)(t)).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Runtime lookup failed (HTTP "+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}};function Vo(e,t,n){if("tool-input-available"===n.type){var r=e?[].concat(e):t?[{type:"text",text:t}]:[];return r.some(function(e){return"dynamic-tool"===e.type&&e.toolCallId===n.toolCallId})||r.push(F({type:"dynamic-tool",toolCallId:n.toolCallId,toolName:n.toolName,input:n.input,state:"input-available"},n.title?{title:n.title}:{})),r}if(!e)return e;if("tool-output-available"===n.type)return e.map(function(e){return"dynamic-tool"===e.type&&e.toolCallId===n.toolCallId?F({},e,{state:"output-available",output:n.output}):e});if("delta"===n.type){var o=[].concat(e),i=o.at(-1);return"text"===(null==i?void 0:i.type)?o[o.length-1]=F({},i,{text:i.text+n.content}):o.push({type:"text",text:n.content}),o}if("message"===n.type){var s=e.filter(function(e){return"text"===e.type}).map(function(e){return e.text}).join("");if(n.content.startsWith(s)&&n.content.length>s.length)return Vo(e,t,{type:"delta",content:n.content.slice(s.length)});if(s!==n.content)return}return e}var $o=new Set(["a","an","the","to","for","in","of","and","or","tool","tools","scene","editor","use","with","please","i","want","can","my"]);function Ko(e){var t;return null!=(t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").toLowerCase().match(/[a-z0-9]+/g))?t:[]}function Xo(e){return e.length>4&&e.endsWith("ies")?e.slice(0,-3)+"y":e.length>4&&e.endsWith("s")?e.slice(0,-1):e}function Yo(e,t){void 0===t&&(t={});var n=t.query,r=void 0===n?"":n,o=t.limit,i=void 0===o?3:o,s=t.offset,a=void 0===s?0:s;if("string"!=typeof r||r.length>1024)throw new Error("query must be a string of at most 1024 characters");if(!Number.isInteger(i)||i<1||i>20)throw new Error("limit must be an integer from 1 to 20");if(!Number.isInteger(a)||a<0)throw new Error("offset must be a nonnegative integer");var u=Ko(r),l=u.filter(function(e){return!$o.has(e)}),c=Array.from(new Set((l.length?l:u.filter(function(e){return"scene"===e||"editor"===e})).map(Xo))),f=e.map(function(e){var t,n=new Set(Ko(e.name).map(Xo)),o=new Set((null!=(t=e.tags)?t:[]).flatMap(Ko).map(Xo)),i=new Set(Ko(e.description).map(Xo)),s=(e.name.toLowerCase()===r.trim().toLowerCase()?1e3:0)+c.reduce(function(e,t){return e+(n.has(t)?20:o.has(t)?12:i.has(t)?2:0)},0);return{tool:e,score:s}}).filter(function(e){return e.score>0}).sort(function(e,t){return t.score-e.score||e.tool.name.localeCompare(t.tool.name)});if(!f.length)return{tools:[],index:[].concat(e).sort(function(e,t){return e.name.localeCompare(t.name)}).slice(a,a+i).map(function(e){return{name:e.name,description:e.description.slice(0,180)}}),totalMatched:0,totalAvailable:e.length,offset:a,hasMore:a+i<e.length};for(var d,h=f.slice(a,a+i),p=new Map,m=L(h);!(d=m()).done;)for(var v,g=L(new Set(null!=(y=d.value.tool.guidance)?y:[]));!(v=g()).done;){var y,b,w=v.value;p.set(w,(null!=(b=p.get(w))?b:0)+1)}var P=Array.from(p).filter(function(e){return e[1]>1}).map(function(e){return e[0]}),_=new Set(P);return F({},P.length?{guidance:P}:{},{tools:h.map(function(e){var t,n=e.tool;return F({name:n.name,description:n.description,inputSchema:n.inputSchema},n.outputSchema?{outputSchema:n.outputSchema}:{},n.invocation?{invocation:n.invocation}:{},null!=(t=n.guidance)&&t.some(function(e){return!_.has(e)})?{guidance:Array.from(new Set(n.guidance.filter(function(e){return!_.has(e)})))}:{})}),totalMatched:f.length,totalAvailable:e.length,offset:a,hasMore:a+i<f.length})}var Zo=function(e,t){try{return Promise.resolve(t?{authToken:t,org:e||void 0}:T.requestAccessToken(e).then(function(t){return{authToken:t,org:e||void 0}}))}catch(e){return Promise.reject(e)}},Qo=["org","authToken"],ei=["org","authToken"],ti=["org","authToken"],ni=function(e,t){void 0===t&&(t={});try{if(!e)throw new Error("A content identifier is required");return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=""+e.baseUrl+Y.content.root+"/"+t,r=Z(e);return Promise.resolve(fetch(n,F({},Q,{method:"DELETE",headers:r}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to delete content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},ri=function(e,t){try{if(!e)throw new Error("A content identifier is required");var n=t||{},r=n.org,o=n.authToken,i=B(n,ti),s=si.filter(function(e){return e in i});if(s.length)throw new Error(s.join(" and ")+" cannot be changed through updateContent — visibility must be changed deliberately, not as part of a metadata update.");if(!Object.keys(i).length)throw new Error("Nothing to update — pass at least one field");return Promise.resolve(Zo(r,o)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return Promise.resolve(function(e,t,n){try{var r=function(){return Promise.resolve(fetch(o,F({},Q,{method:"PATCH",headers:F({},i,{"Content-Type":"application/json"}),body:JSON.stringify(s)})).catch(function(e){return{error:e.message,status:500}})).then(function(e){var t;function r(r){return t?r:Promise.resolve(e.json()).then(function(e){var t=function(){if(e.upload_thumbnail&&n.thumbnail){var t,r=function(){o&&console.error("Failed to upload thumbnail",o.status,o.error)},o=null,i=0,s=function(e,t,n){for(var r;;){var o=e();if(_o(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!_o(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!_o(s)){r=2;break}}}var a=new Po,u=wo.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!_o(s))return void s.then(f).then(void 0,u);if(!(o=e())||_o(o)&&!o.v)return void wo(a,1,i);if(o.then)return void o.then(c).then(void 0,u);_o(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):wo(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):wo(a,1,i)}}(function(){return!t&&i<5},function(){return i++},function(){var r=e.upload_thumbnail;return Promise.resolve(fetch(r.put_url,{method:"PUT",headers:{"Content-Type":r.content_type,"Content-MD5":r.content_md5},body:n.thumbnail}).catch(function(e){return{error:e.message,status:500}})).then(function(e){var n=function(){if("error"in e)return o=e,Promise.resolve(Fr(100*i)).then(function(){});var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){return o={error:t,status:e.status},Promise.resolve(Fr(100*i)).then(function(){})});o=null,t=1}();return n&&n.then?n.then(function(){}):void 0}();if(n&&n.then)return n.then(function(){})})});return s&&s.then?s.then(r):r()}}();return t&&t.then?t.then(function(){return{success:!0}}):{success:!0}})}if("error"in e)return e;var o=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(n){return t=1,{error:n,status:e.status}})}();return o&&o.then?o.then(r):r(o)})},o=""+e.baseUrl+Y.content.root+"/"+t,i=Z(e),s=F({},n),a=function(){if(n.thumbnail){var e=n.thumbnail;return Promise.resolve(e.arrayBuffer()).then(function(t){var n=Pr(t);s.upload_thumbnail={name:e.name,content_size:e.size,content_type:e.type,content_md5:n}})}}();return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e,i)).then(function(e){if(e&&"error"in e)throw new Error(e.error);return{success:!0}})})}catch(e){return Promise.reject(e)}},oi=function(e,t){void 0===t&&(t={});try{var n=t.org,r=t.authToken,o=B(t,ei);return Promise.resolve(Zo(n,r)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t,n){void 0===n&&(n={});try{var r=new URL(""+e.baseUrl+Y.content.root+"/"+encodeURIComponent(t));n.sort_by&&r.searchParams.set("sort_by",n.sort_by),n.sort_direction&&r.searchParams.set("sort_direction",n.sort_direction),n.include_metadata&&r.searchParams.set("include_metadata",n.include_metadata),n.item&&r.searchParams.set("item",n.item);var o=Z(e);return Promise.resolve(fetch(r.toString(),F({},Q,{method:"GET",headers:o}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to get content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e,o)})}catch(e){return Promise.reject(e)}},ii=function(e){void 0===e&&(e={});try{var t=e.org,n=e.authToken,r=B(e,Qo);return Promise.resolve(Zo(t,n)).then(function(e){if(null==e||!e.authToken)throw new Error("Not authenticated");return function(e,t){void 0===t&&(t={});try{var n=new URL(e.baseUrl+Y.content.root);t.sort_by&&n.searchParams.set("sort_by",t.sort_by),t.sort_direction&&n.searchParams.set("sort_direction",t.sort_direction),t.include_metadata&&n.searchParams.set("include_metadata",t.include_metadata),void 0!==t.include_projects&&n.searchParams.set("include_projects",String(t.include_projects)),t.content_type&&n.searchParams.set("content_type",t.content_type),t.content_format&&n.searchParams.set("content_format",t.content_format),t.search&&n.searchParams.set("search",t.search),t.tags&&n.searchParams.set("tags",t.tags),t.types&&n.searchParams.set("types",t.types),t.trash&&n.searchParams.set("trash","true"),t.is_public&&n.searchParams.set("is_public","true"),t.page&&n.searchParams.set("page",String(t.page)),t.limit&&n.searchParams.set("limit",String(t.limit)),t.collection_id&&n.searchParams.set("collection_id",t.collection_id),t.offset&&n.searchParams.set("offset",String(t.offset));var r=Z(e);return Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:r}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to list content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},e),r)})}catch(e){return Promise.reject(e)}},si=["password","is_public"],ai=["thumbnail","metadata","progress","verify"],ui=function(e,t){try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(n){if(!n)throw new Error("Not authenticated");var r=e.map(function(e){return function(e,t){if(void 0===t&&(t=null),"object"==typeof(r=e)&&"string"==typeof r.name&&"string"==typeof r.mimetype){var n=e.mimetype||jr(e.name);e=new File([e.buffer],e.name,{type:n})}else e.type||(e=new File([e],e.name,{type:jr(e.name)}));var r,o=e;return null==t&&(t=e.webkitRelativePath||""),o.path=t+e.name,o}(e)}),o=t.thumbnail,i=t.metadata,s=t.progress,a=t.verify;return function(e,t,n){void 0===n&&(n=void 0);try{var r=function(e,t,n){void 0===n&&(n=void 0);try{for(var r,o,i=function(e){var t=[];return{files:e.filter(function(e){var n=e.name||"";return!(!n||n.endsWith("/"))||(t.push({name:n,reason:"directory-entry"}),!1)}),skipped:t}}(t.files),s=i.files,a=L(i.skipped);!(o=a()).done;)console.warn('[upload] Skipping directory entry: "'+o.value.name+'"');t.files=s;var u=(null==(r=n)?void 0:r.loglevel)||"none";if(!s.length)return"none"!=u&&console.error("No files to upload"),Promise.resolve({success:!1,error:"No files to upload"});if(!t.entrypoint){var l=function(e){var t=null,n="",r=e.filter(function(e){return"index.html"===e.name.toLowerCase()||"index.html.gz"===e.name.toLowerCase()||"index.html.br"===e.name.toLowerCase()});if(1===r.length)return r[0];var o=e.filter(function(e){return e.name.toLowerCase().endsWith(".html")||e.name.toLowerCase().endsWith(".htm")||e.name.toLowerCase().endsWith(".html.gz")||e.name.toLowerCase().endsWith(".html.br")});if(1===o.length)return o[0];if(o.length>1){for(var i,s=new Map,a=L(o);!(i=a()).done;){var u=i.value,l=u.path.split("/"),c=s.get(l.length);c||s.set(l.length,c=[]),c.push(u)}var f=Array.from(s.keys()).sort(function(e,t){return e-t});if(f.length>0)for(var d,h=L(f);!(d=h()).done;){var p=s.get(d.value);if(p)return p.find(function(e){return"index.html"===e.name.toLowerCase()||"index.html.gz"===e.name.toLowerCase()||"index.html.br"===e.name.toLowerCase()})||p[0]}return n="Invalid upload: Multiple HTML files found but could not determine root.",console.error(n,o.map(function(e){return e.path||e.name})),{error:n}}var m=e.filter(function(e){return e.name.toLowerCase().endsWith(".glb")||e.name.toLowerCase().endsWith(".gltf")||e.name.toLowerCase().endsWith(".vrm")});if(m.length>1){var v=function(e){for(var t,n=new Array,r=/(mesh_lod|image)_\d_(.{1,50})/,o=L(e);!(t=o()).done;){var i=t.value;if(!r.test(i.name)){var s=i.name.toLowerCase();(s.endsWith(".gltf")||s.endsWith(".vrm")||s.endsWith(".glb"))&&n.push(i)}}return 1==n.length?n[0]:null!=(a=Jr(n)[0])?a:null;var a}(m);return v?t=v:(n="Invalid upload: Multiple glb/glTF/vrm files found. This is currently not supported.",console.error(n,m.map(function(e){return e.path||e.name})),{error:n})}if(1===m.length)return m[0];var g=e.filter(function(e){return e.name.toLowerCase().endsWith(".usdz")||e.name.toLowerCase().endsWith(".usd")||e.name.toLowerCase().endsWith(".usda")||e.name.toLowerCase().endsWith(".usdc")});if(g.length>=1)return t=function(e){for(var t,n,r=Jr(e),o=function(){var e=s[i],t=r.find(function(t){return t.name.toLowerCase().endsWith("."+e)});if(t)return{v:t}},i=0,s=["usda","usdz","usd","usdc"];i<s.length;i++)if(n=o())return n.v;return null!=(t=r[0])?t:null}(g),t;var y=e.filter(function(e){return e.name.toLowerCase().endsWith(".fbx")});if(y.length>1)return n="Invalid upload: Multiple fbx files found. This is currently not supported.",console.error(n,y),{error:n};if(1===y.length)return y[0];var b=e.filter(function(e){return e.name.toLowerCase().endsWith(".obj")});if(b.length>1)return n="Invalid upload: Multiple obj files found. This is currently not supported.",console.error(n,b),{error:n};if(1===b.length)return b[0];var w=e.filter(function(e){return e.name.toLowerCase().endsWith(".stl")});if(w.length>1)return n="Invalid upload: Multiple stl files found. This is currently not supported.",console.error(n,w),{error:n};if(1===w.length)return w[0];var P=e.filter(function(e){var t=e.name.toLowerCase();return t.endsWith(".ply")||t.endsWith(".splat")||t.endsWith(".spz")||t.endsWith(".ksplat")||t.endsWith(".sog")||t.endsWith(".sogs")});if(P.length>1)return n="Invalid upload: Multiple splat files found. Upload them as separate content items.",console.error(n,P.map(function(e){return e.path||e.name})),{error:n};if(1===P.length)return P[0];if(1===e.length&&!e[0].arrayBuffer&&e[0].path.toLowerCase().startsWith("http"))return e[0];var _=e.filter(function(e){return e.name.toLowerCase().endsWith("package.json")});if(1===_.length)return _[0];if(_.length>1)return n="Invalid upload: Multiple package.json files found. This is currently not supported.",console.error(n,_),{error:n};var j=e.filter(function(e){return e.name.toLowerCase().endsWith(".mtlx")});if(j.length>1)return n="Invalid upload: Multiple mtlx files found. This is currently not supported.",console.error(n,j),{error:n};if(1===j.length)return j[0];var E=e.filter(function(e){var t=e.name.toLowerCase();return Er(t)||Sr(t)||xr(t)});return E.length>1?(n="Invalid upload: Multiple HDRI files found. Upload them as separate content items.",console.error(n,E.map(function(e){return e.path||e.name})),{error:n}):1===E.length?t=E[0]:t||{error:"No supported file to upload found..."}}(s);if(null==l)return Promise.resolve({success:!1,error:"No entrypoint file found"});if("object"==typeof l&&"error"in l)return Promise.resolve({success:!1,error:l.error});"info"===u&&console.log("Entrypoint: "+l.name),t.entrypoint=l}return t.entrypoint&&!s.includes(t.entrypoint)&&s.push(t.entrypoint),Promise.resolve(function(e){try{var t,n=function(e){return t?e:{success:!0,vrm_count:o,gltf_count:i,glb_count:s}};if(e.length>5e3)return Promise.resolve({success:!1,error:"Too many files. Maximum filecount is 5000"});var r=0,o=0,i=0,s=0,a=e.length-1,u=function(e,t,n){for(var r;;){var o=e();if(Br(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Br(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Br(s)){r=2;break}}}var a=new Mr,u=Dr.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!Br(s))return void s.then(f).then(void 0,u);if(!(o=e())||Br(o)&&!o.v)return void Dr(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Br(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):Dr(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Dr(a,1,i)}}(function(){return!t&&a>=0},function(){return a--},function(){var n=e[a];if((r+=n.size)>1073741824){var u={success:!1,error:"Total file size exceeds limit of "+1024..toFixed(0)+" MB. Please reduce the size of your upload."};return t=1,u}var l,c=n.name.toLocaleLowerCase();if(".ds_store"!==c)return c.endsWith(".gltf")?i++:c.endsWith(".glb")?(l=c)&&zr.test(l)||s++:c.endsWith(".vrm")&&o++,function(){if(c.endsWith(".gltf"))return i+=1,console.log("Found glTF file "+n.name+". Will check if all dependencies are available\n",e),Promise.resolve(n.text()).then(function(r){var o,i=r.matchAll(/*#__PURE__*/$(/"uri"\s*:\s*"(.*?)"/g,{value:1}));if(i){var s=JSON.parse(r);if("2.0"!==s.asset.version)return console.warn("⚠ glTF version is not 2.0. This is currently not supported."),t=1,{success:!1,error:"glTF version "+s.asset.version+" is unsupported.Please use glTF 2.0."};for(var a,u=null==(o=n.path)?void 0:o.split("/"),l=u.splice(0,u.length-1).join("/"),c=L(i);!(a=c()).done;){var f,d=null==(f=a.value.groups)?void 0:f.value;if(d){var h=!1;if(d.startsWith("http://")||d.startsWith("https://")||d.startsWith("www.")){console.log("✅ Found remote dependency "+d+" ");break}if(d.startsWith("data:")){console.log("✅ Found embedded dependency "+d+" ");break}var p=(l+"/"+qr(d)).split("/").reduce(function(e,t){return"."===t||(".."===t?e.pop():null!=t&&t.length&&e.push(t)),e},[]).join("/");console.log('❓ Check if local dependency exists "'+p+'"');for(var m,v=L(e);!(m=v()).done;){var g=m.value;if(g.webkitRelativePath===p||g.name==p){h=!0,console.log("✅ Found dependency in name or webkit: "+g.name+" || "+g.webkitRelativePath+" ");break}if(g.path===p){h=!0,console.log("✅ Found dependency in path: "+g.path+" ");break}}if(!h)return console.warn("⚠ Missing dependency "+d,l),t=1,{success:!1,error:"Missing resource: "+d}}}}})}();e.splice(a,1)});return Promise.resolve(u&&u.then?u.then(n):n(u))}catch(e){return Promise.reject(e)}}(s)).then(function(r){var o,i,a,l,c,f;if("error"in r)return{success:!1,error:r.error||"Failed to validate files"};if(null!=(o=t.entrypoint)&&o.name.endsWith(".htm")||null!=(i=t.entrypoint)&&i.name.endsWith(".html")||null!=(a=t.entrypoint)&&a.name.endsWith(".html.gz")||null!=(l=t.entrypoint)&&l.name.endsWith(".html.br"))n||(n={}),n.type="deployment";else if(r.vrm_count>10)return{success:!1,error:"Multiple model files found - this is not supported for asset uploads. Please upload a single model file only."};return Promise.resolve(function(e,t){void 0===t&&(t={});try{var n,r=function(e){return n?e:{files:f,entrypoint:d}},o=t.raw,i=t.loglevel,s=void 0===i?"none":i,a=t.entrypoint,u=void 0===a?null:a,l=function(){var e;"none"!==s&&(e=console).log.apply(e,[].slice.call(arguments))};if(void 0!==o&&o)return"none"!==s&&console.warn("Raw upload - skipping gzip compression of files"),Promise.resolve({files:e,entrypoint:u});var c=new Set(e.map(so)),f=[],d=u,h=function(e,t,n){if("function"==typeof e[Xr]){var r,o,i,s=e[Xr]();if(function e(a){try{for(;!((r=s.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!Qr(a))return void a.then(e,i||(i=Yr.bind(null,o=new Zr,2)));a=a.v}o?Yr(o,1,a):o=a}catch(e){Yr(o||(o=new Zr),2,e)}}(),s.return){var a=function(e){try{r.done||s.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return eo(u,function(e){return t(u[e])},n)}(e,function(t){var r=so(t),o=t.name.toLowerCase();if(oo.some(function(e){return o.endsWith(e)})){var i,a=io.find(function(e){return c.has(""+r+e)});if(!a)return l("gZip compressing file: "+t.name),Promise.resolve(function(e){try{return Promise.resolve(import("./pako.esm-01431bd2.js")).then(function(t){return Promise.resolve(e.arrayBuffer()).then(function(n){var r=t.gzip(new Uint8Array(n)).buffer.slice(0);if(r.byteLength>51200&&r.byteLength>=n.byteLength){if(n.byteLength>0)return null}else if(!(r instanceof ArrayBuffer))return console.error("gzipCompress: Invalid ArrayBuffer"),{error:'Gzip compressing failed for "'+e.name+'" (unexpected result)'};return function(e,t,n){var r;void 0===n&&(n=void 0);var o=function(e,t,n){for(var r=0;;){var o=e.indexOf("\\",r);if(-1===o)break;r=o+1,e=e.replace("\\","/")}return e}(e).split("/").pop()||e,i=(null==(r=n)?void 0:r.type)||_r(t,e),s=new File([t],o,{type:i});return s.path=e,s}(("path"in e?e.path:e.name)+".gz",r,{type:"application/gzip"})})})}catch(e){return Promise.reject(e)}}(t).catch(function(e){return{error:"Error compressing "+t.name+": "+e.message}})).then(function(r){if(null===r)return"none"!==s&&console.error("Did not compress file: "+t.name),void f.push(t);if("error"in r)return n=1,{files:e,entrypoint:u,error:r.error};if(!r)return n=1,{files:e,entrypoint:u,error:"Failed to compress "+t.name};var o=u===t;f.push(r),o&&(d=r),l("gZip compressed file: "+t.name+" "+(o?"(entrypoint)":""))});l("Skipping gzip compression, using pre-compressed file: "+r+a),u===t&&(d=null!=(i=e.find(function(e){return so(e)===""+r+a}))?i:d)}else f.push(t)},function(){return n});return Promise.resolve(h&&h.then?h.then(r):r(h))}catch(e){return Promise.reject(e)}}(s,{raw:t.raw,loglevel:null!=(c=null==(f=n)?void 0:f.loglevel)?c:u,entrypoint:t.entrypoint})).then(function(r){var o,i,a,l,c,f,d,h,p;function m(r){var o;function i(){var r,o;return null!=(r=n)&&null!=(r=r.abort)&&r.aborted?{success:!1,error:"Upload aborted"}:Promise.resolve(fetch(v+Y.upload.request,F({signal:null==(o=n)?void 0:o.abort},Q,{method:"POST",headers:y,body:JSON.stringify(w)})).catch(function(e){var t;return null!=(t=n)&&null!=(t=t.abort)&&t.aborted?"Upload aborted":"fetch failed"==e.message||"Failed to fetch"==e.message?"Network error. Make sure you are connected to the internet and "+v+" is reachable.":(console.error("Failed to begin upload\n",e),null)})).then(function(r){var o;function i(i){return o?i:Promise.resolve(r.json()).then(function(r){var o,i,a;function l(){var t;function o(o){var i,a,l,c;if(t)return o;function f(e){var t,r;if(l)return e;function o(e){return r?e:("none"!=u&&console.log("Upload complete"),Promise.resolve(p.json()).then(function(e){var t;return null!=(t=n)&&null!=(t=t.abort)&&t.aborted?{success:!1,error:"Upload aborted"}:{success:!0,type:e.type,uploadSkipped:!1,id:e.id,content_id:e.content_id,url:e.url,edit_url:e.edit_url,filesUploaded:s.length,totalSize:d}}))}if(null!=(t=n)&&null!=(t=t.abort)&&t.aborted)return{success:!1,error:"Upload aborted"};if(!p)return console.error("Failed to complete upload"),{success:!1,error:"Failed to complete upload"};var i=function(){if(!p.ok)return 524===p.status?(console.error("Failed to complete upload: Gateway Timeout"),r=1,{success:!1,error:"Failed to complete upload: Gateway Timeout"}):Promise.resolve(p.text().catch(function(){return""})).then(function(e){console.error("Failed to complete upload ("+p.status+"): "+e);var t=e?e.substring(0,300):"status "+p.status;return r=1,{success:!1,error:"Failed to complete upload: "+t}})}();return i&&i.then?i.then(o):o(i)}if(null!=(i=n)&&null!=(i=i.abort)&&i.aborted)return Mn({identifier:r.id,status:"canceled",status_message:"Upload aborted",error:"Upload aborted"},e).catch(function(e){return console.error("Could not report canceled upload status",e)}),{success:!1,error:"Upload aborted"};m=!0,null==(a=n)||null==a.onFinalize||a.onFinalize(),y=!0,console.log("Upload Done: All files uploaded to "+r.id);var h=F({},Z(e),{id:r.id});"none"!=u&&console.log("Completing upload - notify server");var p=null,g=0,b=function(e,t,n){for(var r;;){var o=e();if(Qr(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Qr(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Qr(s)){r=2;break}}}var a=new Zr,u=Yr.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!Qr(s))return void s.then(f).then(void 0,u);if(!(o=e())||Qr(o)&&!o.v)return void Yr(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Qr(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):Yr(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Yr(a,1,i)}}(function(){return!(c||l)&&g<5},function(){return g++},function(){var e;return null!=(e=n)&&null!=(e=e.abort)&&e.aborted?(l=1,{success:!1,error:"Upload aborted"}):Promise.resolve(Fr(1e3*g)).then(function(){var e,t;if(null!=(e=n)&&null!=(e=e.abort)&&e.aborted)return l=1,{success:!1,error:"Upload aborted"};var r=AbortSignal.timeout(6e4+5e3*g);return Promise.resolve(fetch(v+Y.upload.done,F({},Q,{method:"POST",headers:h,signal:null!=(t=n)&&t.abort?AbortSignal.any([r,n.abort]):r})).catch(function(e){return console.error("Failed to complete upload ("+(g+1)+" / 5)",e.message),null})).then(function(e){var t,n;!0!==(null==(t=p=e)?void 0:t.ok)?p&&p.status>=400&&p.status<500?c=1:"none"!=u&&g<4&&console.warn("Failed to complete upload ("+((null==(n=p)?void 0:n.status)||"no status")+"): will retry in 1 second"):c=1})})});return b&&b.then?b.then(f):f(b)}var i=function(){if(T)return Promise.resolve(Mn({identifier:r.id,status:"failed",error:"Failed to upload files"},e)).then(function(){return t=1,{success:!1,error:"Failed to upload files"}})}();return i&&i.then?i.then(o):o(i)}"debug"===u&&console.debug("BeginResponse",r);var c,f,d=s.reduce(function(e,t){return e+t.size},0);if(null!=(o=n)&&null!=(o=o.abort)&&o.aborted)return{success:!1,error:"Upload aborted"};if("exists"===r.type)return null==(c=n)||null==c.onFinalize||c.onFinalize(),"none"!=u&&console.log("Upload already exists",r.id),null!=(f=n)&&f.onStart&&n.onStart(r.id,r.content_id),{success:!0,uploadSkipped:!0,id:r.id,type:r.job_type,content_id:r.content_id,filesUploaded:s.length,totalSize:d,url:r.url,edit_url:r.edit_url};var h=t.entrypoint.webkitRelativePath||t.entrypoint.name,p=0,m=!1;null==(i=n)||null==(i=i.abort)||i.addEventListener("abort",function(){m||(console.log("Upload aborted: Cancelling upload"),fetch(v+Y.upload.cancel,F({},Q,{method:"POST",headers:{authorization:g,id:r.id}})).then(function(e){if(!e.ok)throw new Error("Cancel returned HTTP "+e.status)}).catch(function(e){return console.error("Could not notify the server of upload cancellation",e)}))},{once:!0});var y=!1;function w(t,n,o){if(void 0===o&&(o=!1),!o&&Date.now()-_<1e3)return!1;if(!y||"completed"===n){_=Date.now();var i=Math.floor(p/d*100);return"debug"===u&&console.log("SET STATUS: "+n,t,i),Mn({identifier:r.id,status:n,status_message:t,progress:i},e),!0}"none"!=u&&console.warn("Invalid status update...")}var _=Date.now();null!=(a=n)&&a.onStart&&n.onStart(r.id,r.content_id);var j=Date.now(),E=new Gr(s.length,d/1024/1024),S=new Array,x=function(e){for(var t,n=0,r=L(e);!(t=r()).done;){var o=t.value;Number.isFinite(o)&&o>=0&&(n=Math.max(n,o))}return n>=ar?2:n>=16777216?4:10}(b.files.map(function(e){return e.content_length}));"debug"===u&&console.debug("Upload file concurrency: "+x);var T=!1,k=[].concat(s),O=s.length,R=function(e,t){void 0===t&&(t=25e3);var n=!1,r=setInterval(function(){if(!n)try{var e=w("Upload in progress","running",!0);e&&"function"==typeof e.then&&e.catch(function(e){console.warn("[upload] heartbeat tick failed:",e)})}catch(e){console.warn("[upload] heartbeat tick threw:",e)}},t);return r&&"function"==typeof r.unref&&r.unref(),function(){n||(n=!0,clearInterval(r))}}(),U=no(function(){function o(){var e;return null!=(e=n)&&null!=(e=e.abort)&&e.aborted?console.debug("Upload aborted"):T&&console.debug("Upload failed"),Promise.resolve(Promise.all(S).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),T=!0)})).then(function(){})}var i=eo(k,function(o){var i;if(!(T||null!=(i=n)&&null!=(i=i.abort)&&i.aborted)){if(S.length<x){console.debug("Uploading file "+o+"/"+s.length+": "+s[o].name);var a=0,l=0,c=b.files[o],f=c.filename,m=P[o],v=c.content_length,g=c.content_type,y=s[o],_=y.name.endsWith(".gz")?"gzip":y.name.endsWith(".br")?"br":void 0,k=function(e){try{if(e.fileSize>=ar)return function(e){try{var t=function(e,t,n){try{return Promise.resolve(fetch(e,F({},Q,{method:"POST",headers:t,body:JSON.stringify(n)}))).then(function(t){function n(e){return t.json()}var r=function(){if(!t.ok)return Promise.resolve(t.text().catch(function(){return""})).then(function(n){throw new Error(e+" "+t.status+": "+n)})}();return r&&r.then?r.then(n):n()})}catch(e){return Promise.reject(e)}},n=e.uploadId,r=e.entrypointPath,o=e.file,i=e.fileName,s=e.fileMd5,a=e.fileType,u=e.content_encoding,l=e.fileSize,c=e.args,f=e.options,d=e.onProgress,h=e.partSize,p=e.concurrency,m=e.maxRetries,v=e.retryDelayMs,g=e.putPart,y=c.baseUrl,b=function(){return F({},Z(c),{"Content-Type":"application/json",org:c.org,job_id:n})},w=F({},b(),{filesize:l.toString()}),P=JSON.stringify({filename:i,entrypoint:r,"content-type":a,"content-md5":s,"content-encoding":u,output_index:0});return Promise.resolve(function(e){var t=e.size,n=e.slice,r=e.partSize,o=void 0===r?sr:r,i=e.concurrency,s=void 0===i?4:i,a=e.maxRetries,u=void 0===a?5:a,l=e.retryDelayMs,c=void 0===l?1e3:l,f=e.createUpload,d=e.getPartUrls,h=e.putPart,p=e.completeUpload,m=e.abortUpload,v=e.onProgress,g=e.signal,y=e.checkCancelled,b=function(){try{var e;if(g&&g.aborted)return Promise.resolve(!0);var t=function(){if(y)return er(function(){return Promise.resolve(y()).then(function(t){return e=1,!!t})},function(){return e=1,!1})}();return Promise.resolve(t&&t.then?t.then(function(t){return!!e&&t}):!!e&&t)}catch(e){return Promise.reject(e)}};return Promise.resolve(b()).then(function(e){if(e)throw new Error("Upload aborted");var r=function(e,t){if(void 0===t&&(t=sr),!Number.isFinite(e)||e<=0)return[];for(var n=Math.max(t,5242880,Math.ceil(e/1e4)),r=[],o=0,i=1;o<e;){var s=Math.min(o+n,e);r.push({partNumber:i,start:o,end:s,size:s-o}),o=s,i++}return r}(t,o);if(0===r.length)throw new Error("Nothing to upload (size <= 0)");return Promise.resolve(f()).then(function(e){var t=e.upload_id,o=e.key;return Promise.resolve(d(t,o,r.map(function(e){return e.partNumber}))).then(function(e){var i=new Map(e.map(function(e){return[e.part_number,e.url]})),a=[],l=0,f=null,d=[].concat(r),y=Math.max(1,Math.min(s,r.length));return Promise.resolve(Promise.all(Array.from({length:y},function(){return function(){try{var e;return Promise.resolve(function(e,t,n){for(var r;;){var o=e();if(rr(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!rr(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!rr(s)){r=2;break}}}var a=new nr,u=tr.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!rr(s))return void s.then(f).then(void 0,u);if(!(o=e())||rr(o)&&!o.v)return void tr(a,1,i);if(o.then)return void o.then(c).then(void 0,u);rr(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):tr(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):tr(a,1,i)}}(function(){return!e&&d.length>0},void 0,function(){function t(t){if(t)e=1;else{var r=d.shift();if(r){var o=er(function(){return Promise.resolve(function(e){try{var t=i.get(e.partNumber);if(!t)throw new Error("Missing presigned url for part "+e.partNumber);var r=!1;return Promise.resolve(Hn(function(){return Promise.resolve(b()).then(function(o){if(o)throw r=!0,new Error("Upload aborted");return er(function(){var r=n(e.start,e.end);return Promise.resolve(h({url:t,payload:r,partNumber:e.partNumber,size:e.size,signal:g})).then(function(t){if(!t)throw new Error("No ETag returned for part "+e.partNumber);return t})},function(e){return Promise.resolve(b()).then(function(t){throw t&&(r=!0),e})})})},F({maxAttempts:u+1,baseMs:c,isRetryable:function(e){return!r&&Zn(e)}},c>0?{}:{sleep:function(){return Promise.resolve()}}))).then(function(t){if(!t.ok)throw t.error||new Error("Failed to upload part "+e.partNumber);a.push({part_number:e.partNumber,etag:t.value}),l+=e.size,v&&v(l)})}catch(e){return Promise.reject(e)}}(r)).then(function(){})},function(t){f=f||t,e=1});return o&&o.then?o.then(function(){}):void 0}e=1}}return f?t(f):Promise.resolve(b()).then(t)}))}catch(e){return Promise.reject(e)}}()}))).then(function(){function e(e){function n(e){return a.sort(function(e,t){return e.part_number-t.part_number}),Promise.resolve(p(t,o,a)).then(function(){return{ok:!0,key:o,upload_id:t,parts:r.length}})}var i=function(){if(e)return Promise.resolve(m(t,o).catch(function(){})).then(function(){throw f||new Error("Upload aborted")})}();return i&&i.then?i.then(n):n()}return f?e(f):Promise.resolve(b()).then(e)})})})})}({size:l,partSize:h,concurrency:p,maxRetries:m,retryDelayMs:v,slice:function(e,t){return o.slice(e,t)},signal:null==f?void 0:f.abort,onProgress:function(e){d&&d({loaded:e,total:l,progress:l?e/l:0})},createUpload:function(){try{return Promise.resolve(fetch(y+Y.upload.multipart_create,F({},Q,{method:"POST",headers:w,body:P}))).then(function(e){function t(t){return Promise.resolve(e.json()).then(function(e){return{upload_id:e.upload_id,key:e.key}})}var n=function(){if(!e.ok)return Promise.resolve(e.text().catch(function(){return""})).then(function(t){throw new Error("multipart/create "+e.status+": "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},getPartUrls:function(e,n,r){try{return Promise.resolve(t(y+Y.upload.multipart_part_urls,b(),{key:n,upload_id:e,part_numbers:r})).then(function(e){return e.urls})}catch(e){return Promise.reject(e)}},putPart:g||function(e){return function(e){var t=e.url,n=e.payload,r=e.partNumber,o=e.contentType,i=e.signal;try{var s=function(e){var s=Pr(e),a=i,u=new AbortController,l=!1,c=function(){return u.abort()};a&&(a.aborted?u.abort():a.addEventListener("abort",c,{once:!0}));var f=fo(co,function(){l=!0,u.abort()});return f.reset(),no(function(){return to(function(){var e=Fn.put;return Promise.resolve(Vr()).then(function(r){return Promise.resolve(e.call(Fn,t,n,F({},Q,r,{withCredentials:!1,signal:u.signal,headers:{"Content-Type":o,"Content-MD5":s},onUploadProgress:function(){return f.reset()}}))).then(function(e){var t,n;if(200!==e.status)throw new Error(lo({response:e}));var r=(null==(t=e.headers)?void 0:t.etag)||(null==(n=e.headers)?void 0:n.ETag);if(!r)throw new Error("part PUT returned no ETag (is the bucket's CORS exposeHeaders:etag set?)");return r})})},function(e){if(null!=a&&a.aborted)throw e;if(l)throw new Error("Part "+r+" stalled: no progress for 120s");throw new Error(lo(e))})},function(e,t){if(f.cancel(),a&&a.removeEventListener("abort",c),e)throw t;return t})},a=n instanceof Uint8Array;return Promise.resolve(a?s(new Uint8Array(n).buffer):Promise.resolve(n.arrayBuffer()).then(s))}catch(e){return Promise.reject(e)}}({url:e.url,payload:e.payload,partNumber:e.partNumber,signal:e.signal,contentType:a})},completeUpload:function(e,n,r){try{return t(y+Y.upload.multipart_complete,b(),{key:n,upload_id:e,parts:r})}catch(e){return Promise.reject(e)}},abortUpload:function(e,t){try{return Promise.resolve(fetch(y+Y.upload.multipart_abort,F({},Q,{method:"POST",headers:b(),body:JSON.stringify({key:t,upload_id:e})})).catch(function(){})).then(function(){})}catch(e){return Promise.reject(e)}}})).then(function(){return!0})}catch(e){return Promise.reject(e)}}(e);var t=e.uploadId,n=e.uploadRequestPUTUrl,r=e.entrypointPath,o=e.file,i=e.fileName,s=e.fileBuffer,a=e.fileMd5,u=e.fileSize,l=e.fileType,c=e.content_encoding,f=e.fileIndex,d=e.fileNumber,h=e.fileCount,p=e.loglevel,m=e.args,v=e.options,g=e.experimental;"info"===p&&console.log('Uploading file "'+o.name+'" type='+l+" ("+u+") "+o.type+" with hash "+a);var y=F({},Z(m),{"Content-Type":"application/json",org:m.org,job_id:t,filesize:u.toString(),progress:(f/h*100).toFixed(0)}),b={filename:i,entrypoint:r,"content-type":l,"content-md5":a,"content-encoding":c,output_index:0};"debug"===p&&console.debug("Requesting presigned URL with headers",y);var w=JSON.stringify(b),P=null,_="";return Promise.resolve(Hn(function(){try{var e;if(null!=v&&null!=(e=v.abort)&&e.aborted)throw new zn("Upload aborted");return Promise.resolve(fetch(n,F({},Q,{signal:null==v?void 0:v.abort,method:"POST",headers:y,body:w}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text().catch(function(){return""})).then(function(t){throw _=t,{response:{status:e.status,statusText:e.statusText,data:t}}})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},{baseMs:500,onRetry:function(e){var t=e.attempt,n=e.waitMs;console.warn('Failed to get presigned url for "'+i+'" "'+l+'": '+lo(e.error)+"\n→ Retry #"+t+" in "+n+"ms")}})).then(function(n){if(n.ok)P=n.value;else if(n.error instanceof zn)throw n.error;if(null==P){var r=_||lo(n.error);throw new Error('Failed to get presigned url for "'+i+'" "'+l+'" \n'+r)}var o=P.presigned_url,f=!1,y=null,b=[],w=0;return Promise.resolve(Hn(function(t){try{var n;if(null!=v&&null!=(n=v.abort)&&n.aborted)throw new zn("Upload aborted");var r={"Content-Type":l,"Content-MD5":a};g&&(r["Content-Length"]=u.toString()),c&&(r["Content-Encoding"]=c),1===t&&"none"!=p&&console.log("Uploading file "+d+"/"+h+": "+i),"debug"===p&&console.debug("PUT with headers",r);var f=new AbortController,m=!1,w=function(){return f.abort()};null!=v&&v.abort&&(v.abort.aborted?f.abort():v.abort.addEventListener("abort",w,{once:!0}));var P=fo(co,function(){m=!0,f.abort()});return P.reset(),Promise.resolve(no(function(){return to(function(){var t=Fn.put;return Promise.resolve(Vr()).then(function(n){return Promise.resolve(t.call(Fn,o,s,F({},Q,n,{withCredentials:!1,signal:f.signal,headers:r,onUploadProgress:function(t){P.reset(),e.onProgress(t)}}))).then(function(e){if(200!==e.status)throw{response:e};return e})})},function(e){var t;if(null!=v&&null!=(t=v.abort)&&t.aborted)throw new zn("Upload aborted");if(m)throw b.push(y="stalled: no upload progress for 120s"),"none"!==p&&console.error("Upload stalled (PUT) ("+d+", "+i+") after 120s with no progress"),new Error(y);throw y=lo(e),b.push(y),e instanceof zn||("none"!==p&&console.error("Failed to upload file (PUT) ("+d+", "+i+') "'+y+'"'),"debug"===p&&(console.log(r,{fileSize:u}),e.response?console.debug(e.response):console.debug(e))),e})},function(e,t){if(P.cancel(),null!=v&&v.abort&&v.abort.removeEventListener("abort",w),e)throw t;return t}))}catch(e){return Promise.reject(e)}},{onRetry:function(e){"none"!==p&&console.log("Retry PUT #"+e.attempt+" for file "+i+" in "+e.waitMs+"ms")}})).then(function(e){if(w=e.attempts,e.ok)f=!0,"info"===p&&console.log("Uploaded file "+d+"/"+h+' "'+i+'" ('+l+", "+Tr(u)+")");else if(e.error instanceof zn)throw e.error;var n=function(){if(!f){var e,n=null!=(e=function(e){if(!Array.isArray(e))return null;for(var t,n=[],r=L(e);!(t=r()).done;){var o=t.value;if("string"==typeof o){var i=o.trim();i&&!n.includes(i)&&n.push(i)}}return n.length?n.join("; "):null}(b))?e:y,r=function(e,t,n){var r="string"==typeof t?t.trim():"",o="number"==typeof n&&n>1?" after "+n+" attempts":"";return r?"Failed to upload file "+e+o+": "+(r.length>400?r.slice(0,400)+"…":r):"Failed to upload file "+e+o}(i,n,w);return console.error(r),Promise.resolve(Mn({identifier:t,status:"failed",status_message:(o=r,s="string"==typeof o?o:String(null!=o?o:""),s.length<=255?s:s.slice(0,254)+"…"),error:"Failed to upload file "+i},m)).then(function(){throw new Error(r)})}var o,s}();return!n||!n.then||n.then(function(e){return!0})})})}catch(e){return Promise.reject(e)}}({uploadId:r.id,uploadRequestPUTUrl:r.request_put_url,entrypointPath:h,file:s[o],fileName:f,fileMd5:c.content_md5,fileBuffer:m,fileType:g,content_encoding:_,fileSize:v,fileIndex:o,fileNumber:o+1,fileCount:O,loglevel:u,experimental:t.experimental,args:e,options:n,onProgress:function(e){var t,r=e.progress||0,i=(a=s[o].size*r)-l;if(l=a,p+=i,null!=(t=n)&&t.progress){var u=p/d,c=s.length,h=s[o].size,m=(Date.now()-j)/1e3,v=E.updateProgress(p/1024/1024);n.progress({uploadedBytes:p,totalBytes:d,progress01:u,fileName:s[o].name,fileSize:h,fileProgress01:r,fileIndex:o,totalFiles:c,estimatedTimeLeftDisplay:v.estimatedTimeRemainingString,estimatedTimeLeft:v.estimatedTimeRemaining,elapsedTime:m}),w("Uploading file "+(o+1)+"/"+c+" ("+f+"): "+(100*r).toFixed(0)+"% of "+Tr(d)+". Finished in approx. "+v.estimatedTimeRemainingString,"running",!1)}}}).then(function(e){if(!0!==e)return e;for(var t=S.length-1;t>=0;t--)S[t]===k&&S.splice(t,1);w("Uploaded "+Tr(p)+" of "+Tr(d)+" for "+s[o].name,"running")}).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),T=!0)});S.push(k)}var R=function(){if(S.length>=x)return Promise.resolve(Promise.race(S)).then(function(){})}();return R&&R.then?R.then(function(){}):void 0}});return i&&i.then?i.then(o):o()},function(e,t){if(R(),e)throw t;return t});return U&&U.then?U.then(l):l()})}if(null===r||"string"==typeof r)return{success:!1,error:r||"Failed to begin upload"};var a=function(){if(!r.ok)return Promise.resolve(r.text()).then(function(e){if(e.startsWith("{")){var t=JSON.parse(e);if("error"in t)return o=1,{success:!1,status:r.status,error:t.error}}return"none"!=u&&console.error("Failed to begin upload\n",r.status,e),o=1,{success:!1,status:r.status,error:""+e}})}();return a&&a.then?a.then(i):i(a)})}if("deployment"!==(null==(o=n)?void 0:o.type)){var a,l=t.entrypoint.name.toLowerCase();if(l.endsWith(".glb")||l.endsWith(".gltf"))try{var c,f=P[s.indexOf(t.entrypoint)],d=l.endsWith(".glb")?function(e){var t=e instanceof Uint8Array?e:new Uint8Array(e);if(t.byteLength<20)throw new Error("Buffer too small to be a GLB");var n=new DataView(t.buffer,t.byteOffset,t.byteLength);if(1179937895!==n.getUint32(0,!0))throw new Error("Not a GLB (magic mismatch)");var r=n.getUint32(12,!0);if(1313821514!==n.getUint32(16,!0))throw new Error("First chunk is not JSON");var o=20+r;if(o>t.byteLength)throw new Error("JSON chunk exceeds buffer length");var i=t.subarray(20,o),s=(new TextDecoder).decode(i);return JSON.parse(s)}(f):JSON.parse((new TextDecoder).decode(f));a=function(e){return function(e){if(!e)return!1;var t=!e.nodes||0===e.nodes.length,n=!e.meshes||0===e.meshes.length,r=Array.isArray(e.materials)&&1===e.materials.length;return t&&n&&r}(e)?"material":"3d-asset"}(d),"string"==typeof(null==(c=d.asset)?void 0:c.version)&&d.asset.version.startsWith("2.")&&(b.technical_metadata=function(e){var t=Or(e.asset),n=/^(0|[1-9][0-9]{0,8})\.(0|[1-9][0-9]{0,8})$/;if("string"!=typeof t.version||!n.test(t.version)||2!==Number(t.version.split(".")[0]))throw new Error("Metadata collection requires glTF 2.0-compatible asset versions");if(void 0!==t.minVersion&&("string"!=typeof t.minVersion||!n.test(t.minVersion)||"2.0"!==t.minVersion))throw new Error("Metadata collection supports a minimum glTF version of 2.0");var r=Rr(e.nodes),o=Rr(e.meshes),i=Rr(e.accessors),s=Rr(e.scenes),a=Rr(e.animations),u=Rr(e.skins),l=new Set;"2.0"!==t.version&&l.add("newer-gltf-version:"+t.version);var c=function(e){var t=Ur(e);return Or(null===t?void 0:i[t])};function f(e){var t=Rr(Or(e).primitives),n={meshes:1,primitives:0,vertices:0,triangles:0};n.primitives=t.length;for(var r,o=L(t);!(r=o()).done;){var i,s=Or(r.value),a=Ur(c(Or(s.attributes).POSITION).count),u=void 0===s.indices?a:Ur(c(s.indices).count),f=null!=(i=s.mode)?i:4,d="number"==typeof f&&f>=0&&f<=3?0:null===u?null:4===f?Math.floor(u/3):5===f||6===f?Math.max(0,u-2):null;null!==a&&null!==d||l.add("geometry-counts-unavailable"),Wr(n,{meshes:0,primitives:0,vertices:a,triangles:d})}return n}for(var d,h={meshes:0,primitives:0,vertices:0,triangles:0},p=L(o);!(d=p()).done;)Wr(h,f(d.value));for(var m=s.map(function(e,t){var n=Or(e),i=Rr(n.nodes),s={meshes:0,primitives:0,vertices:0,triangles:0},a=[Infinity,Infinity,Infinity],u=[-Infinity,-Infinity,-Infinity],d=!1,h=!1,p=!1;function m(e,t,n){var i=Ur(e);if(null===i||!r[i]||n.has(i))return l.add("invalid-scene-hierarchy"),void(d=!0);var v,g,y=Or(r[i]),b=(v=t,g=function(e){var t,n;if(Array.isArray(e.matrix)&&16===e.matrix.length&&e.matrix.every(function(e){return"number"==typeof e&&Number.isFinite(e)}))return[].concat(e.matrix);var r=null!=(t=Cr(e.translation))?t:[0,0,0],o=r[0],i=r[1],s=r[2],a=null!=(n=Cr(e.scale))?n:[1,1,1],u=a[0],l=a[1],c=a[2],f=e.rotation,d=Array.isArray(f)&&4===f.length&&f.every(function(e){return"number"==typeof e&&Number.isFinite(e)})?f:[0,0,0,1],h=d[0],p=d[1],m=d[2],v=d[3];return[(1-2*(p*p+m*m))*u,2*(h*p+m*v)*u,2*(h*m-p*v)*u,0,2*(h*p-m*v)*l,(1-2*(h*h+m*m))*l,2*(p*m+h*v)*l,0,2*(h*m+p*v)*c,2*(p*m-h*v)*c,(1-2*(h*h+p*p))*c,0,o,i,s,1]}(y),Array.from({length:16},function(e,t){var n=t%4,r=Math.floor(t/4);return v[n]*g[4*r]+v[n+4]*g[4*r+1]+v[n+8]*g[4*r+2]+v[n+12]*g[4*r+3]})),w=new Set(n);if(w.add(i),void 0!==y.mesh){var P=Ur(y.mesh),_=null===P?void 0:o[P];if(_){Wr(s,f(_));for(var j,E=L(Rr(Or(_).primitives));!(j=E()).done;){var S=Or(j.value),x=c(Or(S.attributes).POSITION),T=Cr(x.min),k=Cr(x.max);if(T&&k){h||(h=void 0!==y.skin||Rr(S.targets).length>0),p=!0;for(var O=0;O<8;O++)for(var R=1&O?k[0]:T[0],U=2&O?k[1]:T[1],C=4&O?k[2]:T[2],A=0;A<3;A++){var W=b[A]*R+b[A+4]*U+b[A+8]*C+b[A+12];a[A]=Math.min(a[A],W),u[A]=Math.max(u[A],W)}}else d=!0,l.add("bounds-unavailable")}}else l.add("missing-mesh"),d=!0}for(var N,I=L(Rr(y.children));!(N=I()).done;)m(N.value,b,w)}for(var v,g=L(i);!(v=g()).done;)m(v.value,Nr,new Set);var y=null;if(p&&!d){var b=[(u[0]+a[0])/2,(u[1]+a[1])/2,(u[2]+a[2])/2];y={min:a,max:u,dimensions:[u[0]-a[0],u[1]-a[1],u[2]-a[2]],center:b,originOffset:[-b[0],-b[1],-b[2]],pose:"default",approximate:h}}return F({index:t},"string"==typeof n.name?{name:n.name}:{},{rootCount:i.length,geometry:s,bounds:y})}),v=a.map(function(e,t){for(var n,r=Or(e),o=Rr(r.samplers),i=Infinity,s=-Infinity,a=0===o.length,u=L(o);!(n=u()).done;){var f=c(Or(n.value).input),d=Rr(f.min)[0],h=Rr(f.max)[0];"number"!=typeof d||"number"!=typeof h||!Number.isFinite(d)||!Number.isFinite(h)||h<d?a=!0:(i=Math.min(i,d),s=Math.max(s,h))}return a&&l.add("animation-duration-unavailable"),F({index:t},"string"==typeof r.name?{name:r.name}:{},{duration:a?null:s-i,trackCount:Rr(r.channels).length})}),g=Or(t.extras),y={},b=0,w=["author","license","source","title"];b<w.length;b++){var P=w[b];"string"==typeof g[P]&&(y[P]=g[P])}var _=Ur(e.scene);null!==_&&_>=s.length&&l.add("invalid-default-scene");for(var j,E=0,S=L(o);!(j=S()).done;)for(var x,T=L(Rr(Or(j.value).primitives));!(x=T()).done;)E+=Rr(Or(x.value).targets).length;return{schemaVersion:1,collectorVersion:4,status:l.size?"partial":"complete",issues:[].concat(l),asset:F({version:t.version},"string"==typeof t.minVersion?{minVersion:t.minVersion}:{},"string"==typeof t.generator?{generator:t.generator}:{},"string"==typeof t.copyright?{copyright:t.copyright}:{},{attribution:y}),sceneCount:s.length,defaultSceneIndex:null!==_&&_<s.length?_:null,scenes:m,geometry:h,resourceUsage:Lr(e),materialCount:Rr(e.materials).length,animationCount:a.length,animations:v,skinCount:u.length,jointCount:new Set(u.flatMap(function(e){return Rr(Or(e).joints)})).size,morphTargetCount:E,textureCount:Rr(e.textures).length,imageCount:Rr(e.images).length,materialVariantCount:Rr(Or(Or(e.extensions).KHR_materials_variants).variants).length,extensionsUsed:Ar(e.extensionsUsed),extensionsRequired:Ar(e.extensionsRequired),loading:Ir(e),unit:"meter"}}(d))}catch(e){return{success:!1,error:'Failed to inspect "'+t.entrypoint.name+'": '+e.message}}else l.endsWith(".mtlx")?a="material":(Er(l)||Sr(l)||xr(l))&&(a="hdri");if(a){var h;if(null!=(h=n)&&h.content_type&&n.content_type!==a)return{success:!1,error:'Content type mismatch: "'+t.entrypoint.name+'" contains "'+a+'" but "'+n.content_type+'" was requested.'};b.content_type=a}}var p=to(function(){return Promise.resolve(function(e){try{var t,n=function(e){var n,o,i,s,a;return t?e:null!=(n=null!=(o=null!=(i=null!=(s=null!=(a=function(e){if(e.length<24)return null;if(137!==e[0]||80!==e[1]||78!==e[2]||71!==e[3])return null;if(13!==e[4]||10!==e[5]||26!==e[6]||10!==e[7])return null;var t=new DataView(e.buffer,e.byteOffset),n=t.getUint32(16,!1),r=t.getUint32(20,!1);return n&&r?{width:n,height:r}:null}(r))?a:function(e){if(e.length<28)return null;for(var t=[171,75,84,88,32,50,48,187,13,10,26,10],n=0;n<t.length;n++)if(e[n]!==t[n])return null;var r=new DataView(e.buffer,e.byteOffset),o=r.getUint32(20,!0),i=r.getUint32(24,!0);return o&&i?{width:o,height:i}:null}(r))?s:function(e){if(e.length<16)return null;if(118!==e[0]||47!==e[1]||49!==e[2]||1!==e[3])return null;for(var t=new DataView(e.buffer,e.byteOffset),n=8;n<e.length;){var r=kr(e,n);if(null===r)return null;if(0===r.length)return null;var o=kr(e,n+=r.length+1);if(null===o)return null;if((n+=o.length+1)+4>e.length)return null;var i=t.getInt32(n,!0);if(n+=4,i<0||n+i>e.length)return null;if("dataWindow"===r&&"box2i"===o&&16===i){var s=t.getInt32(n,!0),a=t.getInt32(n+4,!0),u=t.getInt32(n+8,!0)-s+1,l=t.getInt32(n+12,!0)-a+1;return u<=0||l<=0?null:{width:u,height:l}}n+=i}return null}(r))?i:function(e){if(e.length<30)return null;if(82!==e[0]||73!==e[1]||70!==e[2]||70!==e[3])return null;if(87!==e[8]||69!==e[9]||66!==e[10]||80!==e[11])return null;var t=String.fromCharCode(e[12],e[13],e[14],e[15]);if("VP8 "===t){var n=16383&(e[26]|e[27]<<8),r=16383&(e[28]|e[29]<<8);return n&&r?{width:n,height:r}:null}return"VP8L"===t?47!==e[20]?null:{width:1+(16383&(e[21]|e[22]<<8)),height:1+(16383&(e[22]>>6|e[23]<<2|(15&e[24])<<10))}:"VP8X"===t?{width:1+(e[24]|e[25]<<8|e[26]<<16),height:1+(e[27]|e[28]<<8|e[29]<<16)}:null}(r))?o:function(e){if(e.length<4)return null;if(255!==e[0]||216!==e[1])return null;for(var t=2;t<e.length-8;){for(;t<e.length&&255===e[t];)t++;if(t>=e.length)return null;var n=e[t++];if(!(1===n||n>=208&&n<=217)){if(t+2>e.length)return null;var r=e[t]<<8|e[t+1];if(r<2||t+r>e.length)return null;if(n>=192&&n<=207&&196!==n&&200!==n&&204!==n){if(t+7>e.length)return null;var o=e[t+3]<<8|e[t+4],i=e[t+5]<<8|e[t+6];return i&&o?{width:i,height:o}:null}t+=r}}return null}(r))?n:function(e){if(e.length<10)return null;if(35!==e[0]||63!==e[1])return null;var t=new TextDecoder("latin1").decode(e.subarray(0,Math.min(e.length,4096))).match(/[+-]Y\s+(\d+)\s+[+-]X\s+(\d+)/);if(!t)return null;var n=parseInt(t[1],10),r=parseInt(t[2],10);return r&&n?{width:r,height:n}:null}(r)};if(!e||"function"!=typeof e.slice||"number"!=typeof e.size)return Promise.resolve(null);var r,o=Math.min(e.size,65536);if(o<=0)return Promise.resolve(null);var i=function(t,n){try{var i=Promise.resolve(e.slice(0,o).arrayBuffer()).then(function(e){r=new Uint8Array(e)})}catch(e){return n()}return i&&i.then?i.then(void 0,n):i}(0,function(){return t=1,null});return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(e){return Promise.reject(e)}}(t.entrypoint)).then(function(e){e&&(b.width=e.width,b.height=e.height)})},function(e){"debug"===u&&console.warn("readImageResolution failed; uploading without dimensions",e)});return p&&p.then?p.then(i):i()}if(r.error)return{success:!1,error:r.error,status:500};t.files=s=r.files,t.entrypoint=r.entrypoint,s.sort(function(e,t){return e.name.includes(".needle")&&!t.name.includes(".needle")?-1:!e.name.includes(".needle")&&t.name.includes(".needle")?1:0});var v=e.baseUrl,g="Bearer "+e.authToken,y=F({},Z(e),{triggered_by:t.triggered_by,filename:""+encodeURIComponent(t.entrypoint.name),"total-files":s.length.toString(),"total-files-size":s.reduce(function(e,t){return e+t.size},0).toString()});null!=(o=n)&&o.content_id&&(y.content_id=n.content_id),null!=(i=n)&&i.type&&(y.type=n.type),null!=(a=n)&&a.name&&(y.name=encodeURIComponent(n.name)),null!=(l=n)&&l.parent_job_id&&(y.parent_job_id=n.parent_job_id);var b={entrypoint:(null==(c=t.entrypoint)?void 0:c.path)||(null==(f=t.entrypoint)?void 0:f.name),files:[]};null!=(d=n)&&d.content_type&&(b.content_type=n.content_type);var w=F({outputs:[b]},t.metadata?{metadata:t.metadata}:{},!1===(null==(h=n)?void 0:h.optimizations)?{optimizations:!1}:{},!0===(null==(p=n)?void 0:p.verify)?{verify:!0}:{}),P=[],_=eo(s,function(e){var t,r=s[e],o=r.path||r.webkitRelativePath||r.name;if(null!=(t=o)&&t.includes(":"))throw new Error("Invalid filename: "+o);return Promise.resolve(r.arrayBuffer()).then(function(t){var i,s,a,u,l,c=r.size,f=r.type;if(null!=(i=f)&&i.length&&"unknown"!==f.toLowerCase()||(f=_r(t,o)),"deployment"===(null==(s=n)?void 0:s.type)){var d=(u=f,l=(a=o).toLowerCase(),"application/gzip"===u||"application/brotli"===u?(l.endsWith(".html.gz")||l.endsWith(".html.br")?(u="text/html",a=a.substring(0,a.length-3)):l.endsWith(".js.gz")||l.endsWith(".js.br")||l.endsWith(".mjs.gz")||l.endsWith(".mjs.br")||l.endsWith(".cjs.gz")||l.endsWith(".cjs.br")?(u="application/javascript",a=a.substring(0,a.length-3)):l.endsWith(".css.gz")||l.endsWith(".css.br")?(u="text/css",a=a.substring(0,a.length-3)):l.endsWith(".json.gz")||l.endsWith(".json.br")?(u="text/json",a=a.substring(0,a.length-3)):l.endsWith(".txt.gz")||l.endsWith(".txt.br")?(u="text/plain",a=a.substring(0,a.length-3)):l.endsWith(".wasm.gz")||l.endsWith(".wasm.br")?(u="application/wasm",a=a.substring(0,a.length-3)):l.endsWith(".bin.gz")||l.endsWith(".bin.br")?(u="application/octet-stream",a=a.substring(0,a.length-3)):l.endsWith(".png.gz")||l.endsWith(".png.br")?(u="image/png",a=a.substring(0,a.length-3)):l.endsWith(".jpg.gz")||l.endsWith(".jpg.br")||l.endsWith(".jpeg.gz")||l.endsWith(".jpeg.br")?(u="image/jpeg",a=a.substring(0,a.length-3)):l.endsWith(".gif.gz")||l.endsWith(".gif.br")?(u="image/gif",a=a.substring(0,a.length-3)):l.endsWith(".webp.gz")||l.endsWith(".webp.br")?(u="image/webp",a=a.substring(0,a.length-3)):l.endsWith(".svg.gz")||l.endsWith(".svg.br")?(u="image/svg+xml",a=a.substring(0,a.length-3)):l.endsWith(".xml.gz")||l.endsWith(".xml.br")?(u="application/xml",a=a.substring(0,a.length-3)):l.endsWith(".ico.gz")||l.endsWith(".ico.br")?(u="image/x-icon",a=a.substring(0,a.length-3)):l.endsWith(".avif.gz")||l.endsWith(".avif.br")?(u="image/avif",a=a.substring(0,a.length-3)):l.endsWith(".bmp.gz")||l.endsWith(".bmp.br")?(u="image/bmp",a=a.substring(0,a.length-3)):l.endsWith(".tiff.gz")||l.endsWith(".tiff.br")||l.endsWith(".tif.gz")||l.endsWith(".tif.br")?(u="image/tiff",a=a.substring(0,a.length-3)):l.endsWith(".hdr.gz")||l.endsWith(".hdr.br")?(u="image/vnd.radiance",a=a.substring(0,a.length-3)):l.endsWith(".exr.gz")||l.endsWith(".exr.br")?(u="image/x-exr",a=a.substring(0,a.length-3)):l.endsWith(".ktx2.gz")||l.endsWith(".ktx2.br")?(u="image/ktx2",a=a.substring(0,a.length-3)):l.endsWith(".ktx.gz")||l.endsWith(".ktx.br")?(u="image/ktx",a=a.substring(0,a.length-3)):l.endsWith(".dds.gz")||l.endsWith(".dds.br")?(u="image/vnd-ms.dds",a=a.substring(0,a.length-3)):l.endsWith(".webm.gz")||l.endsWith(".webm.br")?(u="video/webm",a=a.substring(0,a.length-3)):l.endsWith(".mp4.gz")||l.endsWith(".mp4.br")?(u="video/mp4",a=a.substring(0,a.length-3)):l.endsWith(".mov.gz")||l.endsWith(".mov.br")?(u="video/quicktime",a=a.substring(0,a.length-3)):l.endsWith(".mp3.gz")||l.endsWith(".mp3.br")?(u="audio/mpeg",a=a.substring(0,a.length-3)):l.endsWith(".wav.gz")||l.endsWith(".wav.br")?(u="audio/wave",a=a.substring(0,a.length-3)):l.endsWith(".ogg.gz")||l.endsWith(".ogg.br")?(u="audio/ogg",a=a.substring(0,a.length-3)):l.endsWith(".flac.gz")||l.endsWith(".flac.br")?(u="audio/flac",a=a.substring(0,a.length-3)):l.endsWith(".m4a.gz")||l.endsWith(".m4a.br")?(u="audio/mp4",a=a.substring(0,a.length-3)):l.endsWith(".aac.gz")||l.endsWith(".aac.br")?(u="audio/aac",a=a.substring(0,a.length-3)):l.endsWith(".woff2.gz")||l.endsWith(".woff2.br")?(u="font/woff2",a=a.substring(0,a.length-3)):l.endsWith(".woff.gz")||l.endsWith(".woff.br")?(u="font/woff",a=a.substring(0,a.length-3)):l.endsWith(".ttf.gz")||l.endsWith(".ttf.br")?(u="font/ttf",a=a.substring(0,a.length-3)):l.endsWith(".otf.gz")||l.endsWith(".otf.br")?(u="font/otf",a=a.substring(0,a.length-3)):l.endsWith(".md.gz")||l.endsWith(".md.br")?(u="text/markdown",a=a.substring(0,a.length-3)):l.endsWith(".yaml.gz")||l.endsWith(".yaml.br")||l.endsWith(".yml.gz")||l.endsWith(".yml.br")?(u="application/yaml",a=a.substring(0,a.length-3)):l.endsWith(".zip.gz")||l.endsWith(".zip.br")?(u="application/zip",a=a.substring(0,a.length-3)):l.endsWith(".glb.gz")||l.endsWith(".glb.br")?(u="model/gltf-binary",a=a.substring(0,a.length-3)):l.endsWith(".gltf.gz")||l.endsWith(".gltf.br")?(u="model/gltf+json",a=a.substring(0,a.length-3)):l.endsWith(".vrm.gz")||l.endsWith(".vrm.br")?(u="model/gltf-binary",a=a.substring(0,a.length-3)):l.endsWith(".usdz.gz")||l.endsWith(".usdz.br")?(u="model/vnd.usdz+zip",a=a.substring(0,a.length-3)):l.endsWith(".usda.gz")||l.endsWith(".usda.br")?(u="model/vnd.usd-usda",a=a.substring(0,a.length-3)):l.endsWith(".usdc.gz")||l.endsWith(".usdc.br")?(u="model/vnd.usd-usdc",a=a.substring(0,a.length-3)):l.endsWith(".usd.gz")||l.endsWith(".usd.br")?(u="model/vnd.usd-usd",a=a.substring(0,a.length-3)):l.endsWith(".obj.gz")||l.endsWith(".obj.br")?(u="model/obj",a=a.substring(0,a.length-3)):l.endsWith(".mtl.gz")||l.endsWith(".mtl.br")?(u="model/mtl",a=a.substring(0,a.length-3)):l.endsWith(".stl.gz")||l.endsWith(".stl.br")?(u="model/stl",a=a.substring(0,a.length-3)):l.endsWith(".mtlx.gz")||l.endsWith(".mtlx.br")?(u="application/materialx+xml",a=a.substring(0,a.length-3)):l.endsWith(".ply.gz")||l.endsWith(".ply.br")?(u="model/ply",a=a.substring(0,a.length-3)):l.endsWith(".dae.gz")||l.endsWith(".dae.br")?(u="model/vnd.collada+xml",a=a.substring(0,a.length-3)):l.endsWith(".3mf.gz")||l.endsWith(".3mf.br")?(u="model/3mf",a=a.substring(0,a.length-3)):(l.endsWith(".splat.gz")||l.endsWith(".splat.br")||l.endsWith(".spz.gz")||l.endsWith(".spz.br")||l.endsWith(".ksplat.gz")||l.endsWith(".ksplat.br")||l.endsWith(".sog.gz")||l.endsWith(".sog.br")||l.endsWith(".sogs.gz")||l.endsWith(".sogs.br"))&&(u="application/octet-stream",a=a.substring(0,a.length-3)),{filename:a,mimetype:u}):null);d&&(o=d.filename,f=d.mimetype)}var h=Pr(t);P[e]=t,b.files[e]={filename:o,content_type:f,content_length:c,content_md5:h}})},function(){});return _&&_.then?_.then(m):m()})})}catch(e){return Promise.reject(e)}}(e,t,n);return ro.push(r),Promise.resolve(r.finally(function(){var e=ro.indexOf(r);e>=0&&ro.splice(e,1)}))}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n,B(t,ai)),F({triggered_by:"web",entrypoint:void 0,files:r},i?{metadata:i}:{}),{name:t.name,abort:t.abort,progress:s,verify:a,type:t.type,content_id:t.content_id}).then(function(e){try{if("error"in e)return Promise.resolve({error:e.error});var n={job_id:e.id,content_id:e.content_id,url:e.url,skipped:e.uploadSkipped},r=function(){if(o&&e.content_id){var r=function(n,r){try{var i=Promise.resolve(ri(e.content_id,{thumbnail:o,org:null!=(s=t.org)?s:void 0,authToken:null!=(a=t.authToken)?a:void 0})).then(function(){})}catch(e){return r(e)}var s,a;return i&&i.then?i.then(void 0,r):i}(0,function(e){var t=e instanceof Error?e.message:String(e);console.error("[needle-cloud] Upload succeeded but the thumbnail could not be set:",t),n.thumbnail_error=t});if(r&&r.then)return r.then(function(){})}}();return Promise.resolve(r&&r.then?r.then(function(){return n}):n)}catch(e){return Promise.reject(e)}})})}catch(e){return Promise.reject(e)}},li=function(e){try{return Promise.resolve(Zo()).then(function(t){if(!t)return!1;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,o),ee(F({baseUrl:"https://cloud.needle.tools/api"},t),{type:"user","x-needle-product":n.join(",")}).then(function(e){for(var t,n=L(e);!(t=n()).done;)if(t.value.valid)return!0;return!1})})}catch(e){return Promise.reject(e)}},ci=function(e){try{return Promise.resolve(Zo()).then(function(t){if(!t)return null;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,o),ee(F({baseUrl:"https://cloud.needle.tools/api"},t),{type:"user","x-needle-product":n.join(",")}).then(function(t){return!0===e.includeInvalid?t:t.filter(function(e){return e.valid})})})}catch(e){return Promise.reject(e)}},fi=function(e){try{return Promise.resolve(Zo(e.org)).then(function(t){if(!t)throw new Error("Not authenticated");return Promise.resolve(function(e){try{var t=new URL((e.endpoint||"https://cloud.needle.tools/api")+Y.get.deployments);return t.searchParams.append("offset",e.offset.toString()),t.searchParams.append("limit",e.limit.toString()),e.names&&t.searchParams.append("name",e.names.map(function(e){return e.trim()}).join(",")),Promise.resolve(fetch(t,{method:"GET",headers:F({},Z({authToken:e.authToken,org:e.org}))})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json())}var r=function(){if(!e.ok){var n=e.status;return Promise.resolve(e.text()).then(function(e){return t=1,{status:n,error:e}})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}(F({endpoint:"https://cloud.needle.tools/api"},t,{offset:e.offset||0,limit:e.limit||10})).catch(function(e){return e})).then(function(e){if(!e||e instanceof Error)return[];var t=e;return Array.isArray(t.deployments)?t.deployments.map(function(e){return{name:e.name,url:e.url}}):[]})})}catch(e){return Promise.reject(e)}},di=function(e,t,n,r){return Promise.resolve(vi(null==r?void 0:r.org)).then(function(o){return Promise.resolve(Zo(o,null==r?void 0:r.authToken)).then(function(r){return function(e,t,n,r){try{var o=new Headers(Z(e));return o.set("Content-Type","application/json"),Promise.resolve(fetch(new URL(e.baseUrl+Y.ai.evaluate),F({},Q,{method:"POST",headers:Object.fromEntries(o),body:JSON.stringify({state:t,questions:n}),signal:null==r?void 0:r.signal}))).then(function(e){function t(t){return e.json()}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){var n,r,o,i;null!=(n=e.headers.get("content-type"))&&n.includes("application/json")&&(i=JSON.parse(t));var s="string"==typeof(null==(r=i)?void 0:r.message)?i.message:t;throw new Bo(e.status,t,s,"string"==typeof(null==(o=i)?void 0:o.code)?i.code:void 0)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},r),e,t,n)})})},hi=function(e,t,n){return Promise.resolve(vi(null==n?void 0:n.org)).then(function(r){return Promise.resolve(Zo(r,null==n?void 0:n.authToken)).then(function(n){return function(e,t,n){try{var r=new URL(e.baseUrl+Y.ai.completions),o=Z(e);return o["Content-Type"]="application/json",Promise.resolve(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(F({message:t},null!=(null==n?void 0:n.system)?{system:n.system}:{},null!=(null==n?void 0:n.max_tokens)?{max_tokens:n.max_tokens}:{})),signal:null==n?void 0:n.signal}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text().catch(function(){return""})).then(function(t){throw new Error("Completion failed ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t)})})},pi=function(e,t){return Promise.resolve(vi(null==t?void 0:t.org)).then(function(n){return Promise.resolve(Zo(n,null==t?void 0:t.authToken)).then(function(t){return Ho(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})})},mi=function(e){return Promise.resolve(vi(null==e?void 0:e.org)).then(function(t){return Promise.resolve(Zo(t,null==e?void 0:e.authToken)).then(function(t){return Lo(F({baseUrl:"https://cloud.needle.tools/api"},t,{projectId:null==e?void 0:e.projectId}))})})},vi=function(e){try{return Promise.resolve(e||T.getDefaultTeamId())}catch(e){return Promise.reject(e)}};function gi(e){return function(e,t){void 0===t&&(t={});try{var n=new URL("https://cloud.needle.tools/api"+Y.public.content_list);if(t.sort_by&&n.searchParams.set("sort_by",t.sort_by),t.sort_direction&&n.searchParams.set("sort_direction",t.sort_direction),t.include_metadata&&n.searchParams.set("include_metadata",t.include_metadata),t.content_type&&n.searchParams.set("content_type",t.content_type),t.content_format&&n.searchParams.set("content_format",t.content_format),t.org_id){var r=(Array.isArray(t.org_id)?t.org_id:[t.org_id]).map(function(e){return e.trim()}).filter(function(e){return e.length>0}).join(",");r&&n.searchParams.set("org_id",r)}return t.search&&n.searchParams.set("search",t.search),t.limit&&n.searchParams.set("limit",String(t.limit)),t.cursor&&n.searchParams.set("cursor",t.cursor),!0===t.include_protected&&n.searchParams.set("include_protected","true"),Promise.resolve(fetch(n,F({},Q,{method:"GET"}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to list public content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(0,e)}function yi(e,t){return void 0===t&&(t={}),function(e,t,n){void 0===n&&(n={});try{var r=new URL("https://cloud.needle.tools/api"+Y.public.content_list+"/"+encodeURIComponent(t));return n.sort_by&&r.searchParams.set("sort_by",n.sort_by),n.sort_direction&&r.searchParams.set("sort_direction",n.sort_direction),n.include_metadata&&r.searchParams.set("include_metadata",n.include_metadata),Promise.resolve(fetch(r,F({},Q,{method:"GET"}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new Error("Failed to get public content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(0,e,t)}var bi=["org","authToken","download","pollIntervalMs","timeoutMs","signal","onProgress"],wi=function(e){try{var t=e||{},n=t.org,r=t.authToken,o=t.download,i=t.pollIntervalMs,s=t.timeoutMs,a=t.signal,u=t.onProgress,l=B(t,bi);if(null==l||!l.prompt)throw new Error("A prompt is required to generate a 3D asset");return Promise.resolve(Zo(n,r)).then(function(e){if(null==e||!e.authToken)throw new Error("Not authenticated");var t={onProgress:u,pollIntervalMs:i,timeoutMs:s};return void 0!==o&&(t.download=o),Promise.resolve(function(e,t,n){void 0===n&&(n={});try{var r=n.download,o=void 0===r||r,i=n.pollIntervalMs,s=void 0===i?2e3:i,a=n.timeoutMs,u=void 0===a?9e5:a,l=n.onProgress,c=e.signal;return Promise.resolve(function(e,t){try{var n;if(null!=(n=e.signal)&&n.aborted)return Promise.resolve({error:"The 3D generation request was cancelled"});var r=e.baseUrl+Y.jobs.create,o=F({},Z(e),{"content-type":"application/json"}),i={type:"ai-3d-asset",triggered_by:e.trigger_type,parameters:F({},t)};return Promise.resolve(fetch(r,F({},Q,{method:"POST",headers:o,body:JSON.stringify(i),signal:e.signal})).catch(function(e){return function(e){return"AbortError"===(null==e?void 0:e.name)||"TimeoutError"===(null==e?void 0:e.name)}(e)?{__aborted:!0}:(console.error("Failed to request 3D asset generation: "+(null==e?void 0:e.message)),{__failed:(null==e?void 0:e.message)||"Request failed"})})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json().catch(function(e){return console.error(e),null})).then(function(e){return null!=e&&e.job?e:{error:"The server did not return a job"}})}if("__aborted"in e)return{error:"The 3D generation request was cancelled"};if("__failed"in e)return{error:e.__failed};var r=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(n){return console.error("Failed to request 3D asset generation ("+e.status+"): "+n),t=1,{error:n||"Request failed ("+e.status+")"}})}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}(e,t)).then(function(t){var n;function r(t){return n?t:null!=c&&c.aborted?{error:"Waiting for the 3D asset was cancelled",job:i}:o?Promise.resolve(function(e){try{return Promise.resolve(function(e){try{if(!e.identifier)return Promise.resolve(null);var t=F({},Z(e));return Promise.resolve(fetch(e.baseUrl+Y.jobs.query,F({},Q,{method:"POST",headers:t,body:JSON.stringify({job_id:e.identifier,fields:e.fields,content_format:e.content_format,content_type:e.content_type})})).catch(function(e){return console.error(e),null})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json().catch(function(e){return console.error(e),null})).then(function(e){return null==e?null:e.job})}var r=null==e?(t=1,null):function(){if(!e.ok){var n=e.status;return Promise.resolve(e.text()).then(function(e){return console.error("Failed to get job",n,e),t=1,null})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}({baseUrl:e.baseUrl,authToken:e.authToken,org:e.org,identifier:e.identifier,fields:["results"],content_format:e.content_format})).then(function(t){var n;function r(e){return n?e:{files:i}}if(null==t||!t.results)return{error:"Job "+e.identifier+" did not produce any result files"};var o=t.results;if(!o.bucket||!o.directory)return{error:"Job "+e.identifier+" has incomplete result data"};var i=[],s=function(e,t,n){if("function"==typeof e[ho]){var r,o,i,s=e[ho]();if(function e(a){try{for(;!((r=s.next()).done||n&&n());)if((a=t(r.value))&&a.then){if(!vo(a))return void a.then(e,i||(i=po.bind(null,o=new mo,2)));a=a.v}o?po(o,1,a):o=a}catch(e){po(o||(o=new mo),2,e)}}(),s.return){var a=function(e){try{r.done||s.return()}catch(e){}return e};if(o&&o.then)return o.then(a,function(e){throw a(e)});a()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var u=[],l=0;l<e.length;l++)u.push(e[l]);return function(e,t,n){var r,o,i=-1;return function s(a){try{for(;++i<e.length&&(!n||!n());)if((a=t(i))&&a.then){if(!vo(a))return void a.then(s,o||(o=po.bind(null,r=new mo,2)));a=a.v}r?po(r,1,a):r=a}catch(e){po(r||(r=new mo),2,e)}}(),r}(u,function(e){return t(u[e])},n)}(o.files,function(t){var r;if(!((r=t.filename).startsWith(".extras/")||r.startsWith(".extras\\")||r.endsWith("screenshot.needle.webp")||Dn.test(r)||r.endsWith(".needle.log")))return Promise.resolve(function(e,t,n){try{return Promise.resolve(fetch(e.baseUrl+Y.jobs.presigned_url,F({},Q,{method:"POST",headers:F({},Z(e),{job_id:t}),body:JSON.stringify(n)})).catch(function(e){return console.error(e),null})).then(function(e){return e&&e.ok?Promise.resolve(e.text()):(console.error("Failed to get presigned download URL",null==e?void 0:e.status),null)})}catch(e){return Promise.reject(e)}}(e,e.identifier,{bucket:o.bucket,key:o.directory+"/"+t.filename})).then(function(e){if(e)return Promise.resolve(fetch(e).catch(function(e){return console.error(e),null})).then(function(e){if(e&&e.ok)return Promise.resolve(e.arrayBuffer().catch(function(e){return console.error(e),null})).then(function(e){if(!e)return n=1,{error:"Failed to read downloaded file: "+t.filename};i.push({filename:t.filename,data:e})});console.error("Failed to download ("+(null==e?void 0:e.status)+" | "+(null==e?void 0:e.statusText)+"): "+t.filename)});console.error("Failed to get presigned URL for: "+t.filename)})},function(){return n});return s&&s.then?s.then(r):r(s)})}catch(e){return Promise.reject(e)}}({baseUrl:e.baseUrl,authToken:e.authToken,org:i.org,identifier:i.identifier,content_format:"glb"})).then(function(e){if("error"in e)return{error:e.error,job:i};var t=e.files.find(function(e){return e.filename.toLowerCase().endsWith(".glb")});return t?{job:i,glb:t.data,filename:t.filename}:{error:"The finished asset did not contain a GLB file",job:i}}):{job:i}}if("error"in t)return t;var i=t.job;if("canceled"===i.status)return{error:i.status_message||"The generation request was canceled",job:i};var a=Date.now(),f=i.status,d=function(e,t,n){for(var r;;){var o=e();if(bo(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!bo(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!bo(s)){r=2;break}}}var a=new yo,u=go.bind(null,a,2);return(0===r?o.then(c):1===r?i.then(l):s.then(f)).then(void 0,u),a;function l(r){i=r;do{if(t&&(s=t())&&s.then&&!bo(s))return void s.then(f).then(void 0,u);if(!(o=e())||bo(o)&&!o.v)return void go(a,1,i);if(o.then)return void o.then(c).then(void 0,u);bo(i=n())&&(i=i.v)}while(!i||!i.then);i.then(l).then(void 0,u)}function c(e){e?(i=n())&&i.then?i.then(l).then(void 0,u):l(i):go(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):go(a,1,i)}}(function(){return!n&&"completed"!==f},void 0,function(){if(null!=c&&c.aborted)return n=1,{error:"Waiting for the 3D asset was cancelled",job:i};if(Date.now()-a>u){var t={error:"Generation did not finish within "+Math.round(u/1e3)+"s",job:i};return n=1,t}return Promise.resolve(function(e,t){return t?t.aborted?Promise.resolve():new Promise(function(n){var r=setTimeout(function(){t.removeEventListener("abort",o),n(void 0)},e);function o(){clearTimeout(r),n(void 0)}t.addEventListener("abort",o,{once:!0})}):Fr(e)}(s,c)).then(function(){return null!=c&&c.aborted?(n=1,{error:"Waiting for the 3D asset was cancelled",job:i}):Promise.resolve(function(e,t){return Promise.resolve(function(e,t){try{var n=t.baseUrl+Y.jobs.get_status,r=F({},Z(t),{job_id:e,org:t.org});return Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:r})).catch(function(e){return t.verbose?console.error("Failed to get job status",e):console.error("Failed to get job status",e.message),null})).then(function(e){var t;function n(n){return t?n:Promise.resolve(e.json())}if(!e)return{failed:!0};var r=function(){if(!e.ok){var n=e.status;return Promise.resolve(e.text()).then(function(r){return console.error("Failed to get status",n,r),t=1,{failed:!0,httpStatus:e.status}})}}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}}(e,t)).then(function(e){return e&&"failed"in e?null:e})}(i.identifier,{baseUrl:e.baseUrl,authToken:e.authToken,org:i.org})).then(function(e){if(e&&(null==l||l(e),"failed"===(f=e.status)||"canceled"===f))return n=1,{error:e.error||e.status_message||"Generation "+f,job:i}})})});return d&&d.then?d.then(r):r(d)})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},e,{trigger_type:"web",signal:a}),l,t)).then(function(e){if("error"in e)throw new Error(e.error);return e})})}catch(e){return Promise.reject(e)}},Pi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.promotions);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list project promotions ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},_i=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.promote);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to promote project asset ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},ji=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.deployments);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to record project deployment ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ei=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.deployments);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list project deployments ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Si=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.revisions_update);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to update project revision ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},xi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.revisions);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list project revisions ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ti=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.blobs_download);return n.searchParams.set("hash",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}if(404===e.status)return null;var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to request blob download ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},ki=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.blobs_complete);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({hash:t})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to complete blob upload ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Oi=function(e,t,n,r){void 0===n&&(n={}),void 0===r&&(r=void 0);try{return Promise.resolve(Zo(n.org,n.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t,n,r){try{var o=new URL(e.baseUrl+Y.projects.blobs_upload),i=null==r?void 0:r.filename,s=i&&jr(i)||void 0;return Promise.resolve(fetch(o,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({hash:t,size:n,filename:i,mimetype:s})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to request blob upload ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t,r)})}catch(e){return Promise.reject(e)}},Ri=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.blobs_check);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({hashes:t})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to check project blobs ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ui=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Zo(n.org,n.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t,n){return jo(e,Y.projects.update,t,n,"update")}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t)})}catch(e){return Promise.reject(e)}},Ci=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t,n){return void 0===n&&(n={}),jo(e,Y.projects.clone,t,n,"clone")}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,{name:t.name})})}catch(e){return Promise.reject(e)}},Ai=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){return jo(e,Y.projects.unarchive,t,{},"unarchive")}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Wi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){return jo(e,Y.projects.archive,t,{},"archive")}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ni=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){return jo(e,Y.projects.restore,t,{},"restore")}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Ii=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(""+e.baseUrl+Y.projects.delete+"/"+encodeURIComponent(t));return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify({})}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to delete project ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Li=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Zo(n.org,n.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(r,o){try{var i=Promise.resolve(function(e,t,n){try{var r=new URL(e.baseUrl+Y.projects.pull);return r.searchParams.set("project",t),void 0!==n&&r.searchParams.set("revision",String(n)),Promise.resolve(fetch(r,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to pull project revision ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),e,t))}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){if(e instanceof X&&404===e.status)return null;throw e})})}catch(e){return Promise.reject(e)}},Fi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.push);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to push project revision ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},zi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Zo(t.org,t.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.head);return n.searchParams.set("project",t),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to get project head ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},Di=function(e){void 0===e&&(e={});try{return Promise.resolve(Zo(e.org,e.authToken)).then(function(t){if(null==t||!t.authToken)throw new Error("Not authenticated");return function(e,t){void 0===t&&(t={});try{var n=new URL(e.baseUrl+Y.projects.list);return t.kind&&n.searchParams.set("kind",t.kind),t.state&&n.searchParams.set("state",t.state),Promise.resolve(fetch(n,F({},Q,{method:"GET",headers:Z(e)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to list projects ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},t),{kind:e.kind,state:e.state})})}catch(e){return Promise.reject(e)}},Mi=function(e,t){try{if(null==t||!t.kind)throw new Error("createProject: 'kind' is required (product discriminator, e.g. \"web-project\")");return Promise.resolve(Zo(t.org,t.authToken)).then(function(n){if(null==n||!n.authToken)throw new Error("Not authenticated");return function(e,t){try{var n=new URL(e.baseUrl+Y.projects.create);return Promise.resolve(fetch(n,F({},Q,{method:"POST",headers:Z(e),body:JSON.stringify(t)}))).then(function(e){function t(t){return Promise.resolve(e.json())}var n=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(t){throw new X(e.status,t,"Failed to create project ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(F({baseUrl:"https://cloud.needle.tools/api"},n),{name:e,kind:t.kind})})}catch(e){return Promise.reject(e)}},Bi=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Gi(n)).then(function(n){return function(e,t,n){return Eo(e,t,"reports","POST",n)}(n,e,t)})}catch(e){return Promise.reject(e)}},qi=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Gi(n)).then(function(n){return function(e,t,n){return Eo(e,t,"records","POST",n)}(n,e,t)})}catch(e){return Promise.reject(e)}},Ji=function(e,t,n){void 0===n&&(n={});try{return Promise.resolve(Gi(n)).then(function(n){return function(e,t,n){return Eo(e,t,"policy","PUT",{enabled:n})}(n,e,t)})}catch(e){return Promise.reject(e)}},Hi=function(e,t){void 0===t&&(t={});try{return Promise.resolve(Gi(t)).then(function(t){return function(e,t){return Eo(e,t,"policy","GET")}(t,e)})}catch(e){return Promise.reject(e)}},Gi=function(e){try{return Promise.resolve(Zo(e.org,e.authToken)).then(function(e){if(null==e||!e.authToken)throw new Error("Not authenticated");return F({baseUrl:"https://cloud.needle.tools/api"},e)})}catch(e){return Promise.reject(e)}},Vi=function(e){try{var t=new URL("https://cloud.needle.tools/api"+Y.account.buy_licenses);return Promise.resolve(Zo()).then(function(n){var r={mode:"payment",price_id:e.price_id,tracking:e.tracking,affiliate_code:e.affiliateCode,return_url:window.location.href,cancel_url:window.location.href};return Promise.resolve(fetch(t,{method:"POST",headers:F({"Content-Type":"application/json"},Z(n)),body:JSON.stringify(r)})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return"session_url"in e?(window.location.href=e.session_url,{ok:!0,status:200,checkoutId:e.checkoutId}):{ok:!1,status:400}}):{ok:!1,status:e.status}})})}catch(e){return Promise.reject(e)}},$i=function(e,t){try{var n,r;if(!e)return Promise.resolve(null);var o=null!=(n=null==t?void 0:t.fetch)?n:globalThis.fetch,i=new URL((null!=(r=null==t?void 0:t.baseUrl)?r:"https://cloud.needle.tools/api")+Y.payment.info);return i.searchParams.set("product",e),null!=t&&t.price&&i.searchParams.set("price",t.price),Promise.resolve(function(e,t){try{var n=Promise.resolve(o(i.toString())).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return"number"!=typeof(null==e?void 0:e.amount)||"string"!=typeof(null==e?void 0:e.currency)?null:e}):null})}catch(e){return null}return n&&n.then?n.then(void 0,function(){return null}):n}())}catch(e){return Promise.reject(e)}},Ki=function(e,t){try{var n;if(!e)return Promise.resolve(null);var r=null!=(n=null==t?void 0:t.fetch)?n:globalThis.fetch;return Promise.resolve(Zo(null==t?void 0:t.org,null==t?void 0:t.authToken).catch(function(){return null})).then(function(n){var o,i,s;if(null==n||!n.authToken)return null;var a=new URL((null!=(o=null==t?void 0:t.baseUrl)?o:"https://cloud.needle.tools/api")+Y.payment.create);return a.searchParams.set("product",e),null!=t&&t.price&&a.searchParams.set("price",t.price),null!=t&&t.promoCode&&a.searchParams.set("promo",t.promoCode),void 0!==(null==t?void 0:t.affiliateCode)&&a.searchParams.set("affiliate_code",t.affiliateCode),null!=t&&t.app&&a.searchParams.set("app",t.app),void 0!==(null==t||null==(i=t.tracking)?void 0:i.source)&&a.searchParams.set("source",t.tracking.source),void 0!==(null==t||null==(s=t.tracking)?void 0:s.attemptId)&&a.searchParams.set("attempt_id",t.tracking.attemptId),"number"==typeof(null==t?void 0:t.mode)&&a.searchParams.set("mode",String(t.mode)),function(e,t){try{var o=Promise.resolve(r(a.toString(),{headers:F({Accept:"application/json"},Z(n))})).then(function(e){return e.ok?Promise.resolve(e.json()).then(function(e){return"string"==typeof(null==e?void 0:e.url)&&"string"==typeof(null==e?void 0:e.checkoutId)?{url:e.url,checkoutId:e.checkoutId}:null}):null})}catch(e){return null}return o&&o.then?o.then(void 0,function(){return null}):o}()})}catch(e){return Promise.reject(e)}};function Xi(e){return function(e,t){try{if(!/^[a-f0-9]{64}$/.test(t))throw new Error("Invalid runtime snapshot identifier");return Go(e,new URL(e.baseUrl.replace(/\/$/,"")+Y.runtime_snapshots.get.replace(":hash",t)))}catch(e){return Promise.reject(e)}}({baseUrl:"https://cloud.needle.tools/api"},e)}function Yi(e,t){return function(e,t,n){try{var r=new URL(e.baseUrl.replace(/\/$/,"")+Y.runtime_snapshots.release_get);return r.searchParams.set("runtime",t),r.searchParams.set("version",n),Go(e,r)}catch(e){return Promise.reject(e)}}({baseUrl:"https://cloud.needle.tools/api"},e,t)}export{Oo as AIChatError,T as Auth,r as AuthScopes,K as NeedleLoginButton,hi as aiComplete,di as aiEvaluate,Wi as archiveProject,Ri as checkProjectBlobs,Ki as checkoutProduct,Ci as cloneProject,ki as completeProjectBlobUpload,pi as createChatSession,Mi as createProject,ni as deleteContent,Ii as deleteProject,Yo as discoverTools,wi as generate3dAsset,oi as getContent,fi as getDeployments,$i as getProductInformation,Ei as getProjectDeployments,Hi as getProjectDiagnosticPolicy,zi as getProjectHead,Pi as getProjectPromotions,yi as getPublicContent,Yi as getRuntimeRelease,Xi as getRuntimeSnapshot,ci as getUserLicenses,mi as listChats,ii as listContent,xi as listProjectRevisions,Di as listProjects,gi as listPublicContent,li as ownsProduct,_i as promoteProjectAsset,Li as pullProjectRevision,Fi as pushProjectRevision,ji as recordProjectDeployment,Ti as requestProjectBlobDownload,Oi as requestProjectBlobUpload,Ni as restoreProject,Ji as setProjectDiagnosticPolicy,Vi as startCheckoutSession,Bi as submitProjectBugReport,Ai as unarchiveProject,ri as updateContent,Vo as updateInlineChatParts,Ui as updateProject,Si as updateProjectRevision,ui as uploadFiles,qi as uploadProjectDiagnosticPart};