needle-cloud 2.4.4 → 2.4.5

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,{Buffer as t}from"buffer";import n,{UserScope as r}from"@logto/browser";globalThis.Buffer=t;var o,i={Basic:[r.Profile,r.Email],Payment:["read:accounting","write:accounting"],All:[r.Profile,r.Email,r.Roles,r.CustomData,r.Organizations,r.OrganizationRoles].concat(["all","read","write","delete","invite","download","create:org","write:org","delete:org","read:accounting","write:accounting","read:usage"])},s=["Needle Engine"],a="https://auth.needle.tools",u=void 0,l=[],c=null,f=null,d=null,h=null,p=new Array;function m(){p.forEach(function(e){try{e()}catch(e){console.error(e)}})}var g=!1,v={setDebug:function(e){g=e},baseUrl:window.location.origin,redirectUri:window.location.origin,postSignOutRedirectUri:window.location.origin,onChanged:function(e){return p.includes(e)||p.push(e),function(){for(;;){var t=p.indexOf(e);if(!(t>=0))break;p.splice(t,1)}}},ready:function(){return f?f.then(function(){return!0}):Promise.reject(new Error("Auth not initialized"))},init:function(e){return f||(f=function(e){try{var t,n,r=function(){var e=b(!0);if(!e)return v.checkIsAuthenticated().then(function(e){return!e||v.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&&(g=e.debug),g&&console.debug("Auth.init",e),null!=e&&e.scopes){switch(e.scopes){case"all":e.scopes=i.All;break;case"payment":e.scopes=i.Payment}l=e.scopes}l.length<=0&&(t=l).push.apply(t,i.Basic.concat(i.Payment)),g&&console.debug("Auth.init","Use scopes",l),null!=e&&e.appId?(null==(n=h)?void 0:n.logtoConfig.appId)!==(u=e.appId)&&(g&&console.debug("Auth.init","App ID changed, resetting client"),h=null):(u="2x82zzh5xuudmiotdy2ux",g&&console.debug("Auth.init","Use default app ID",u));var o=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(a))return w().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=b();t&&(console.log("Restore query before login",t,"Current:",e.search),e.search=t),window.history.replaceState({},"",e.href)}).catch(function(e){console.error(e)})}(),s=function(){if(o instanceof Promise)return Promise.resolve(o.then(function(e){return!0})).then(function(){})}();return Promise.resolve(s&&s.then?s.then(r):r())}catch(e){return Promise.reject(e)}}(e))},isAuthenticated:function(){return o},checkIsAuthenticated:function(){return w().isAuthenticated().then(function(e){return o=e,e})},getUserInfo:function(){return c},getUserId:function(){return c?c.sub:null},getName:function(){return c?c.username?c.username:c.name?c.name:c.email?c.email.split("@")[0]:null:null},requestUserInfo:function(){return d||(d=v.checkIsAuthenticated().then(function(e){return e?w().fetchUserInfo().then(function(e){var t;return g&&(null==e?void 0:e.sub)!=(null==(t=c)?void 0:t.sub)&&console.debug("UserInfo",e),c=e,m(),e}).catch(function(e){return console.error(e),c=null,m(),null}):(c=null,m(),null)}))},requestAccessToken:function(e){return g&&console.debug("requestAccessToken",{org_id:e}),e?w().getOrganizationToken(e):w().getAccessToken("https://cloud.needle.tools/api",e||void 0)},signIn:function(e){return v.checkIsAuthenticated().then(function(t){if(0==t){var n;if(null==(n=u)||!n.length)throw new Error("App ID is not set: Make sure to call 'init' first");y(),null!=e&&e.signUp?w().signIn({redirectUri:v.redirectUri,firstScreen:"register",interactionMode:"signUp"}):w().signIn(v.redirectUri)}})},getDefaultTeamId:function(){var e,t=null==(e=c)?void 0:e.custom_data,n=null==t?void 0:t.default_org;return"string"==typeof n?n:void 0},signOut:function(){return d=null,v.checkIsAuthenticated().then(function(e){if(1==e){var t;if(null==(t=u)||!t.length)throw new Error("App ID is not set: Make sure to call 'init' first");y(),w().signOut(v.postSignOutRedirectUri)}})}};function y(){sessionStorage.setItem("needle-auth:query",window.location.search)}function b(e){void 0===e&&(e=!0);var t=sessionStorage.getItem("needle-auth:query");return t?(e&&sessionStorage.removeItem("needle-auth:query"),t):""}function w(){if(!h){if(!u)throw new Error("App ID is not set: Make sure to call 'init' first");var e={endpoint:a,appId:u,scopes:l,resources:["https://cloud.needle.tools/api"]};g&&console.warn("Creating auth client:",g,e),h=new n(e)}return h}function _(e,t){this.v=e,this.k=t}function P(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 x(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 _(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 S(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 E(t.call(e));n="@@asyncIterator",r="@@iterator"}throw new TypeError("Object is not async iterable")}function E(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 E=function(e){this.s=e,this.n=e.next},E.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 E(e)}function j(e){return new _(e,0)}function T(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 P(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)?P(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 k(){return k=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},k.apply(null,arguments)}function W(e){return W=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},W(e)}function O(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(O=function(){return!!e})()}function R(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 U(){U=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 v?t:v).prototype),s=new O(r||[]);return o(i,"_invoke",{value:j(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",g={};function v(){}function y(){}function b(){}var w={};l(w,s,function(){return this});var _=Object.getPrototypeOf,P=_&&_(_(R([])));P&&P!==n&&r.call(P,s)&&(w=P);var x=b.prototype=v.prototype=Object.create(w);function S(e){["next","throw","return"].forEach(function(t){l(e,t,function(e){return this._invoke(t,e)})})}function E(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 j(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===g)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===g)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")),g;var i=f(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,g;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,g):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,g)}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 W(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function R(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(x,"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(x),e},t.awrap=function(e){return{__await:e}},S(E.prototype),l(E.prototype,a,function(){return this}),t.AsyncIterator=E,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var s=new E(c(e,n,r,o),i);return t.isGeneratorFunction(n)?s:s.next().then(function(e){return e.done?e.value:s.next()})},S(x),l(x,u,"Generator"),l(x,s,function(){return this}),l(x,"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=R,O.prototype={constructor:O,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(W),!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,g):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),g},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),W(n),g}},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;W(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:R(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),g}},t}function A(e,t){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},A(e,t)}function z(e){return function(){return new C(e.apply(this,arguments))}}function C(e){var t,n;function r(t,n){try{var i=e[t](n),s=i.value,a=s instanceof _;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 L(e){var t="function"==typeof Map?new Map:void 0;return L=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(O())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var o=new(e.bind.apply(e,r));return n&&A(o,n.prototype),o}(e,arguments,W(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),A(n,e)},L(e)}function N(){N=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)),A(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&&A(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)},N.apply(this,arguments)}C.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},C.prototype.next=function(e){return this._invoke("next",e)},C.prototype.throw=function(e){return this._invoke("throw",e)},C.prototype.return=function(e){return this._invoke("return",e)};var F=/*#__PURE__*/function(e){function t(){var t;return(t=e.call(this)||this).addEventListener("click",function(){v.isAuthenticated()?v.signOut():v.signIn()}),t}var n,r;r=e,(n=t).prototype=Object.create(r.prototype),n.prototype.constructor=n,A(n,r);var o=t.prototype;return o.connectedCallback=function(){var e=this;console.debug("Login button connected..."),this.__update(),this.__unsubscribeOnChange=v.onChanged(function(){e.__update()})},o.disconnectedCallback=function(){var e;null==(e=this.__unsubscribeOnChange)||e.call(this)},o.__update=function(){this.innerHTML=v.isAuthenticated()?"Logout":"Login"},t}(/*#__PURE__*/L(HTMLButtonElement));if(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",F,{extends:"button"});var I={status:"/v1/status",version:"/v1/version",api:"/v1/api",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",update_payment_method:"/v1/account/update_payment_method",get_billing:"/v1/account/get_billing",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"},ai:{llmstxt:"/v1/ai/llmstxt",chat:"/v1/ai/chat",chat_personal:"/v1/ai/chat/personal",list_chats:"/v1/ai/chat/list",chat_tool_result:"/v1/ai/chat/tool-result",chat_stop:"/v1/ai/chat/stop",ask:"/v1/ai/ask",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"},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",request_start:"/v1/jobs/request_start",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_results_stats:"/v1/jobs/results_stats",post_usage:"/v1/jobs/post_usage",get_status:"/v1/jobs/status",get_org:"/v1/jobs/org",query:"/v1/jobs/query",request_job_that_needs_stats:"/v1/jobs/job_needs_stats"},worker:{ping:"/v1/worker/ping",get_available_count:"/v1/worker/get_available_count",post_available_info:"/v1/worker/post_available_info",get_available_info:"/v1/worker/get_available_info"},local_projects:{get:{user:"/v1/local_projects/user",by_id:"/v1/local_projects/"},post:"/v1/local_projects"}};function B(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 M={credentials:"omit"},D=function(e,t){try{var n=e.baseUrl+I.account.get_licenses,r=k({},t),o=k({},r,B(e));return Promise.resolve(fetch(n,k({},M,{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 q(e,t){return function(){return e.apply(t,arguments)}}const{toString:J}=Object.prototype,{getPrototypeOf:H}=Object,G=(V=Object.create(null),e=>{const t=J.call(e);return V[t]||(V[t]=t.slice(8,-1).toLowerCase())});var V;const K=e=>(e=e.toLowerCase(),t=>G(t)===e),$=e=>t=>typeof t===e,{isArray:X}=Array,Y=$("undefined"),Z=K("ArrayBuffer"),Q=$("string"),ee=$("function"),te=$("number"),ne=e=>null!==e&&"object"==typeof e,re=e=>{if("object"!==G(e))return!1;const t=H(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},oe=K("Date"),ie=K("File"),se=K("Blob"),ae=K("FileList"),ue=K("URLSearchParams"),[le,ce,fe,de]=["ReadableStream","Request","Response","Headers"].map(K);function he(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),X(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{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 pe(e,t){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 me="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,ge=e=>!Y(e)&&e!==me,ve=(ye="undefined"!=typeof Uint8Array&&H(Uint8Array),e=>ye&&e instanceof ye);var ye;const be=K("HTMLFormElement"),we=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),_e=K("RegExp"),Pe=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};he(n,(n,o)=>{let i;!1!==(i=t(n,o,e))&&(r[o]=i||n)}),Object.defineProperties(e,r)},xe="abcdefghijklmnopqrstuvwxyz",Se="0123456789",Ee={DIGIT:Se,ALPHA:xe,ALPHA_DIGIT:xe+xe.toUpperCase()+Se},je=K("AsyncFunction"),Te=(ke="function"==typeof setImmediate,We=ee(me.postMessage),ke?setImmediate:We?(Oe=`axios@${Math.random()}`,Re=[],me.addEventListener("message",({source:e,data:t})=>{e===me&&t===Oe&&Re.length&&Re.shift()()},!1),e=>{Re.push(e),me.postMessage(Oe,"*")}):e=>setTimeout(e));var ke,We,Oe,Re;const Ue="undefined"!=typeof queueMicrotask?queueMicrotask.bind(me):"undefined"!=typeof process&&process.nextTick||Te;var Ae={isArray:X,isArrayBuffer:Z,isBuffer:function(e){return null!==e&&!Y(e)&&null!==e.constructor&&!Y(e.constructor)&&ee(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{let t;return e&&("function"==typeof FormData&&e instanceof FormData||ee(e.append)&&("formdata"===(t=G(e))||"object"===t&&ee(e.toString)&&"[object FormData]"===e.toString()))},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&Z(e.buffer),t},isString:Q,isNumber:te,isBoolean:e=>!0===e||!1===e,isObject:ne,isPlainObject:re,isReadableStream:le,isRequest:ce,isResponse:fe,isHeaders:de,isUndefined:Y,isDate:oe,isFile:ie,isBlob:se,isRegExp:_e,isFunction:ee,isStream:e=>ne(e)&&ee(e.pipe),isURLSearchParams:ue,isTypedArray:ve,isFileList:ae,forEach:he,merge:function e(){const{caseless:t}=ge(this)&&this||{},n={},r=(r,o)=>{const i=t&&pe(n,o)||o;n[i]=re(n[i])&&re(r)?e(n[i],r):re(r)?e({},r):X(r)?r.slice():r};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&he(arguments[e],r);return n},extend:(e,t,n,{allOwnKeys:r}={})=>(he(t,(t,r)=>{e[r]=n&&ee(t)?q(t,n):t},{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),e.prototype.constructor=e,Object.defineProperty(e,"super",{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&&H(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:G,kindOfTest:K,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(X(e))return e;let t=e.length;if(!te(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[Symbol.iterator]).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:be,hasOwnProperty:we,hasOwnProp:we,reduceDescriptors:Pe,freezeMethods:e=>{Pe(e,(t,n)=>{if(ee(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;ee(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 X(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:pe,global:me,isContextDefined:ge,ALPHABET:Ee,generateString:(e=16,t=Ee.ALPHA_DIGIT)=>{let n="";const{length:r}=t;for(;e--;)n+=t[Math.random()*r|0];return n},isSpecCompliantForm:function(e){return!!(e&&ee(e.append)&&"FormData"===e[Symbol.toStringTag]&&e[Symbol.iterator])},toJSONObject:e=>{const t=new Array(10),n=(e,r)=>{if(ne(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[r]=e;const o=X(e)?[]:{};return he(e,(e,t)=>{const i=n(e,r+1);!Y(i)&&(o[t]=i)}),t[r]=void 0,o}}return e};return n(e,0)},isAsyncFn:je,isThenable:e=>e&&(ne(e)||ee(e))&&ee(e.then)&&ee(e.catch),setImmediate:Te,asap:Ue};function ze(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o)}Ae.inherits(ze,Error,{toJSON:function(){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:Ae.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const Ce=ze.prototype,Le={};function Ne(e){return Ae.isPlainObject(e)||Ae.isArray(e)}function Fe(e){return Ae.endsWith(e,"[]")?e.slice(0,-2):e}function Ie(e,t,n){return e?e.concat(t).map(function(e,t){return e=Fe(e),!n&&t?"["+e+"]":e}).join(n?".":""):t}["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Le[e]={value:e}}),Object.defineProperties(ze,Le),Object.defineProperty(Ce,"isAxiosError",{value:!0}),ze.from=(e,t,n,r,o,i)=>{const s=Object.create(Ce);return Ae.toFlatObject(e,s,function(e){return e!==Error.prototype},e=>"isAxiosError"!==e),ze.call(s,e.message,t,n,r,o),s.cause=e,s.name=e.name,i&&Object.assign(s,i),s};const Be=Ae.toFlatObject(Ae,{},null,function(e){return/^is[A-Z]/.test(e)});function Me(e,t,n){if(!Ae.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const r=(n=Ae.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(e,t){return!Ae.isUndefined(t[e])})).metaTokens,o=n.visitor||l,i=n.dots,s=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&Ae.isSpecCompliantForm(t);if(!Ae.isFunction(o))throw new TypeError("visitor must be a function");function u(e){if(null===e)return"";if(Ae.isDate(e))return e.toISOString();if(!a&&Ae.isBlob(e))throw new ze("Blob is not supported. Use a Buffer instead.");return Ae.isArrayBuffer(e)||Ae.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function l(e,n,o){let a=e;if(e&&!o&&"object"==typeof e)if(Ae.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=JSON.stringify(e);else if(Ae.isArray(e)&&function(e){return Ae.isArray(e)&&!e.some(Ne)}(e)||(Ae.isFileList(e)||Ae.endsWith(n,"[]"))&&(a=Ae.toArray(e)))return n=Fe(n),a.forEach(function(e,r){!Ae.isUndefined(e)&&null!==e&&t.append(!0===s?Ie([n],r,i):null===s?n:n+"[]",u(e))}),!1;return!!Ne(e)||(t.append(Ie(o,n,i),u(e)),!1)}const c=[],f=Object.assign(Be,{defaultVisitor:l,convertValue:u,isVisitable:Ne});if(!Ae.isObject(e))throw new TypeError("data must be an object");return function e(n,r){if(!Ae.isUndefined(n)){if(-1!==c.indexOf(n))throw Error("Circular reference detected in "+r.join("."));c.push(n),Ae.forEach(n,function(n,i){!0===(!(Ae.isUndefined(n)||null===n)&&o.call(t,n,Ae.isString(i)?i.trim():i,r,f))&&e(n,r?r.concat(i):[i])}),c.pop()}}(e),t}function De(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(e){return t[e]})}function qe(e,t){this._pairs=[],e&&Me(e,this,t)}const Je=qe.prototype;function He(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function Ge(e,t,n){if(!t)return e;const r=n&&n.encode||He,o=n&&n.serialize;let i;if(i=o?o(t,n):Ae.isURLSearchParams(t)?t.toString():new qe(t,n).toString(r),i){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+i}return e}Je.append=function(e,t){this._pairs.push([e,t])},Je.toString=function(e){const t=e?function(t){return e.call(this,t,De)}:De;return this._pairs.map(function(e){return t(e[0])+"="+t(e[1])},"").join("&")};var Ve=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){Ae.forEach(this.handlers,function(t){null!==t&&e(t)})}},Ke={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},$e={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:qe,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const Xe="undefined"!=typeof window&&"undefined"!=typeof document,Ye=(Ze="undefined"!=typeof navigator&&navigator.product,Xe&&["ReactNative","NativeScript","NS"].indexOf(Ze)<0);var Ze,Qe={__proto__:null,hasBrowserEnv:Xe,hasStandardBrowserWebWorkerEnv:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,hasStandardBrowserEnv:Ye,origin:Xe&&window.location.href||"http://localhost",...$e};function et(e){function t(e,n,r,o){let i=e[o++];if("__proto__"===i)return!0;const s=Number.isFinite(+i),a=o>=e.length;return i=!i&&Ae.isArray(r)?r.length:i,a?(r[i]=Ae.hasOwnProp(r,i)?[r[i],n]:n,!s):(r[i]&&Ae.isObject(r[i])||(r[i]=[]),t(e,n,r[i],o)&&Ae.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(Ae.isFormData(e)&&Ae.isFunction(e.entries)){const n={};return Ae.forEachEntry(e,(e,r)=>{t(function(e){return Ae.matchAll(/\w+|\[(\w*)]/g,e).map(e=>"[]"===e[0]?"":e[1]||e[0])}(e),r,n,0)}),n}return null}const tt={transitional:Ke,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=Ae.isObject(e);if(o&&Ae.isHTMLForm(e)&&(e=new FormData(e)),Ae.isFormData(e))return r?JSON.stringify(et(e)):e;if(Ae.isArrayBuffer(e)||Ae.isBuffer(e)||Ae.isStream(e)||Ae.isFile(e)||Ae.isBlob(e)||Ae.isReadableStream(e))return e;if(Ae.isArrayBufferView(e))return e.buffer;if(Ae.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let i;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return Me(e,new Qe.classes.URLSearchParams,Object.assign({visitor:function(e,t,n,r){return Qe.isNode&&Ae.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((i=Ae.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return Me(i?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(Ae.isString(e))try{return(0,JSON.parse)(e),Ae.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(0,JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||tt.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(Ae.isResponse(e)||Ae.isReadableStream(e))return e;if(e&&Ae.isString(e)&&(n&&!this.responseType||r)){const n=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw ze.from(e,ze.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Qe.classes.FormData,Blob:Qe.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};Ae.forEach(["delete","get","head","post","put","patch"],e=>{tt.headers[e]={}});var nt=tt;const rt=Ae.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"]),ot=Symbol("internals");function it(e){return e&&String(e).trim().toLowerCase()}function st(e){return!1===e||null==e?e:Ae.isArray(e)?e.map(st):String(e)}function at(e,t,n,r,o){return Ae.isFunction(r)?r.call(this,t,n):(o&&(t=n),Ae.isString(t)?Ae.isString(r)?-1!==t.indexOf(r):Ae.isRegExp(r)?r.test(t):void 0:void 0)}class ut{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=it(t);if(!o)throw new Error("header name must be a non-empty string");const i=Ae.findKey(r,o);(!i||void 0===r[i]||!0===n||void 0===n&&!1!==r[i])&&(r[i||t]=st(e))}const i=(e,t)=>Ae.forEach(e,(e,n)=>o(e,n,t));if(Ae.isPlainObject(e)||e instanceof this.constructor)i(e,t);else if(Ae.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(),!n||t[n]&&rt[n]||("set-cookie"===n?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t})(e),t);else if(Ae.isHeaders(e))for(const[t,r]of e.entries())o(r,t,n);else null!=e&&o(t,e,n);return this}get(e,t){if(e=it(e)){const n=Ae.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(Ae.isFunction(t))return t.call(this,e,n);if(Ae.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=it(e)){const n=Ae.findKey(this,e);return!(!n||void 0===this[n]||t&&!at(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=it(e)){const o=Ae.findKey(n,e);!o||t&&!at(0,n[o],o,t)||(delete n[o],r=!0)}}return Ae.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&&!at(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}normalize(e){const t=this,n={};return Ae.forEach(this,(r,o)=>{const i=Ae.findKey(n,o);if(i)return t[i]=st(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]=st(r),n[s]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return Ae.forEach(this,(n,r)=>{null!=n&&!1!==n&&(t[r]=e&&Ae.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")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach(e=>n.set(e)),n}static accessor(e){const t=(this[ot]=this[ot]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=it(e);t[r]||(function(e,t){const n=Ae.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})})}(n,e),t[r]=!0)}return Ae.isArray(e)?e.forEach(r):r(e),this}}ut.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),Ae.reduceDescriptors(ut.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[n]=e}}}),Ae.freezeMethods(ut);var lt=ut;function ct(e,t){const n=this||nt,r=t||n,o=lt.from(r.headers);let i=r.data;return Ae.forEach(e,function(e){i=e.call(n,i,o.normalize(),t?t.status:void 0)}),o.normalize(),i}function ft(e){return!(!e||!e.__CANCEL__)}function dt(e,t,n){ze.call(this,null==e?"canceled":e,ze.ERR_CANCELED,t,n),this.name="CanceledError"}function ht(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new ze("Request failed with status code "+n.status,[ze.ERR_BAD_REQUEST,ze.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}Ae.inherits(dt,ze,{__CANCEL__:!0});const pt=(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(e,t){let n,r,o=0,i=1e3/t;const s=(t,i=Date.now())=>{o=i,n=null,r&&(clearTimeout(r),r=null),e.apply(null,t)};return[(...e)=>{const t=Date.now(),a=t-o;a>=i?s(e,t):(n=e,r||(r=setTimeout(()=>{r=null,s(n)},i-a)))},()=>n&&s(n)]}(n=>{const i=n.loaded,s=n.lengthComputable?n.total:void 0,a=i-r,u=o(a);r=i,e({loaded:i,total:s,progress:s?i/s:void 0,bytes:a,rate:u||void 0,estimated:u&&s&&i<=s?(s-i)/u:void 0,event:n,lengthComputable:null!=s,[t?"download":"upload"]:!0})},n)},mt=(e,t)=>{const n=null!=e;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},gt=e=>(...t)=>Ae.asap(()=>e(...t));var vt=Qe.hasStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let n;function r(n){let r=n;return e&&(t.setAttribute("href",r),r=t.href),t.setAttribute("href",r),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:"/"===t.pathname.charAt(0)?t.pathname:"/"+t.pathname}}return n=r(window.location.href),function(e){const t=Ae.isString(e)?r(e):e;return t.protocol===n.protocol&&t.host===n.host}}():function(){return!0},yt=Qe.hasStandardBrowserEnv?{write(e,t,n,r,o,i){const s=[e+"="+encodeURIComponent(t)];Ae.isNumber(n)&&s.push("expires="+new Date(n).toGMTString()),Ae.isString(r)&&s.push("path="+r),Ae.isString(o)&&s.push("domain="+o),!0===i&&s.push("secure"),document.cookie=s.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function bt(e,t){return e&&!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)?function(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}const wt=e=>e instanceof lt?{...e}:e;function _t(e,t){t=t||{};const n={};function r(e,t,n){return Ae.isPlainObject(e)&&Ae.isPlainObject(t)?Ae.merge.call({caseless:n},e,t):Ae.isPlainObject(t)?Ae.merge({},t):Ae.isArray(t)?t.slice():t}function o(e,t,n){return Ae.isUndefined(t)?Ae.isUndefined(e)?void 0:r(void 0,e,n):r(e,t,n)}function i(e,t){if(!Ae.isUndefined(t))return r(void 0,t)}function s(e,t){return Ae.isUndefined(t)?Ae.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,i){return i in t?r(n,o):i in e?r(void 0,n):void 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,responseEncoding:s,validateStatus:a,headers:(e,t)=>o(wt(e),wt(t),!0)};return Ae.forEach(Object.keys(Object.assign({},e,t)),function(r){const i=u[r]||o,s=i(e[r],t[r],r);Ae.isUndefined(s)&&i!==a||(n[r]=s)}),n}var Pt=e=>{const t=_t({},e);let n,{data:r,withXSRFToken:o,xsrfHeaderName:i,xsrfCookieName:s,headers:a,auth:u}=t;if(t.headers=a=lt.from(a),t.url=Ge(bt(t.baseURL,t.url),e.params,e.paramsSerializer),u&&a.set("Authorization","Basic "+btoa((u.username||"")+":"+(u.password?unescape(encodeURIComponent(u.password)):""))),Ae.isFormData(r))if(Qe.hasStandardBrowserEnv||Qe.hasStandardBrowserWebWorkerEnv)a.setContentType(void 0);else if(!1!==(n=a.getContentType())){const[e,...t]=n?n.split(";").map(e=>e.trim()).filter(Boolean):[];a.setContentType([e||"multipart/form-data",...t].join("; "))}if(Qe.hasStandardBrowserEnv&&(o&&Ae.isFunction(o)&&(o=o(t)),o||!1!==o&&vt(t.url))){const e=i&&s&&yt.read(s);e&&a.set(i,e)}return t},xt="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise(function(t,n){const r=Pt(e);let o=r.data;const i=lt.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 g(){if(!m)return;const r=lt.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders());ht(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=g:m.onreadystatechange=function(){m&&4===m.readyState&&(0!==m.status||m.responseURL&&0===m.responseURL.indexOf("file:"))&&setTimeout(g)},m.onabort=function(){m&&(n(new ze("Request aborted",ze.ECONNABORTED,e,m)),m=null)},m.onerror=function(){n(new ze("Network Error",ze.ERR_NETWORK,e,m)),m=null},m.ontimeout=function(){let t=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";r.timeoutErrorMessage&&(t=r.timeoutErrorMessage),n(new ze(t,(r.transitional||Ke).clarifyTimeoutError?ze.ETIMEDOUT:ze.ECONNABORTED,e,m)),m=null},void 0===o&&i.setContentType(null),"setRequestHeader"in m&&Ae.forEach(i.toJSON(),function(e,t){m.setRequestHeader(t,e)}),Ae.isUndefined(r.withCredentials)||(m.withCredentials=!!r.withCredentials),f&&"json"!==f&&(m.responseType=r.responseType),h&&([u,c]=pt(h,!0),m.addEventListener("progress",u)),d&&m.upload&&([a,l]=pt(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(),m=null)},r.cancelToken&&r.cancelToken.subscribe(s),r.signal&&(r.signal.aborted?s():r.signal.addEventListener("abort",s)));const v=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(r.url);v&&-1===Qe.protocols.indexOf(v)?n(new ze("Unsupported protocol "+v+":",ze.ERR_BAD_REQUEST,e)):m.send(o||null)})},St=(e,t)=>{let n,r=new AbortController;const o=function(e){if(!n){n=!0,s();const t=e instanceof Error?e:this.reason;r.abort(t instanceof ze?t:new dt(t instanceof Error?t.message:t))}};let i=t&&setTimeout(()=>{o(new ze(`timeout ${t} of ms exceeded`,ze.ETIMEDOUT))},t);const s=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(e=>{e&&(e.removeEventListener?e.removeEventListener("abort",o):e.unsubscribe(o))}),e=null)};e.forEach(e=>e&&e.addEventListener&&e.addEventListener("abort",o));const{signal:a}=r;return a.unsubscribe=s,[a,()=>{i&&clearTimeout(i),i=null}]};const Et=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},jt=(e,t,n,r,o)=>{const i=async function*(e,t,n){for await(const r of e)yield*Et(ArrayBuffer.isView(r)?r:await n(String(r)),t)}(e,t,o);let s,a=0,u=e=>{s||(s=!0,r&&r(e))};return new ReadableStream({async pull(e){try{const{done:t,value:r}=await i.next();if(t)return u(),void e.close();if(n){let e=a+=r.byteLength;n(e)}e.enqueue(new Uint8Array(r))}catch(e){throw u(e),e}},cancel:e=>(u(e),i.return())},{highWaterMark:2})},Tt="function"==typeof fetch&&"function"==typeof Request&&"function"==typeof Response,kt=Tt&&"function"==typeof ReadableStream,Wt=Tt&&("function"==typeof TextEncoder?(Ot=new TextEncoder,e=>Ot.encode(e)):async e=>new Uint8Array(await new Response(e).arrayBuffer()));var Ot;const Rt=(e,...t)=>{try{return!!e(...t)}catch(e){return!1}},Ut=kt&&Rt(()=>{let e=!1;const t=new Request(Qe.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),At=kt&&Rt(()=>Ae.isReadableStream(new Response("").body)),zt={stream:At&&(e=>e.body)};var Ct;Tt&&(Ct=new Response,["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!zt[e]&&(zt[e]=Ae.isFunction(Ct[e])?t=>t[e]():(t,n)=>{throw new ze(`Response type '${e}' is not supported`,ze.ERR_NOT_SUPPORT,n)})}));const Lt={http:null,xhr:xt,fetch:Tt&&(async e=>{let{url:t,method:n,data:r,signal:o,cancelToken:i,timeout:s,onDownloadProgress:a,onUploadProgress:u,responseType:l,headers:c,withCredentials:f="same-origin",fetchOptions:d}=Pt(e);l=l?(l+"").toLowerCase():"text";let h,p,[m,g]=o||i||s?St([o,i],s):[];const v=()=>{!h&&setTimeout(()=>{m&&m.unsubscribe()}),h=!0};let y;try{if(u&&Ut&&"get"!==n&&"head"!==n&&0!==(y=await(async(e,t)=>{const n=Ae.toFiniteNumber(e.getContentLength());return null==n?(async e=>null==e?0:Ae.isBlob(e)?e.size:Ae.isSpecCompliantForm(e)?(await new Request(e).arrayBuffer()).byteLength:Ae.isArrayBufferView(e)||Ae.isArrayBuffer(e)?e.byteLength:(Ae.isURLSearchParams(e)&&(e+=""),Ae.isString(e)?(await Wt(e)).byteLength:void 0))(t):n})(c,r))){let e,n=new Request(t,{method:"POST",body:r,duplex:"half"});if(Ae.isFormData(r)&&(e=n.headers.get("content-type"))&&c.setContentType(e),n.body){const[e,t]=mt(y,pt(gt(u)));r=jt(n.body,65536,e,t,Wt)}}Ae.isString(f)||(f=f?"include":"omit"),p=new Request(t,{...d,signal:m,method:n.toUpperCase(),headers:c.normalize().toJSON(),body:r,duplex:"half",credentials:f});let o=await fetch(p);const i=At&&("stream"===l||"response"===l);if(At&&(a||i)){const e={};["status","statusText","headers"].forEach(t=>{e[t]=o[t]});const t=Ae.toFiniteNumber(o.headers.get("content-length")),[n,r]=a&&mt(t,pt(gt(a),!0))||[];o=new Response(jt(o.body,65536,n,()=>{r&&r(),i&&v()},Wt),e)}l=l||"text";let s=await zt[Ae.findKey(zt,l)||"text"](o,e);return!i&&v(),g&&g(),await new Promise((t,n)=>{ht(t,n,{data:s,headers:lt.from(o.headers),status:o.status,statusText:o.statusText,config:e,request:p})})}catch(t){if(v(),t&&"TypeError"===t.name&&/fetch/i.test(t.message))throw Object.assign(new ze("Network Error",ze.ERR_NETWORK,e,p),{cause:t.cause||t});throw ze.from(t,t&&t.code,e,p)}})};Ae.forEach(Lt,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}});const Nt=e=>`- ${e}`,Ft=e=>Ae.isFunction(e)||null===e||!1===e;var It=e=>{e=Ae.isArray(e)?e:[e];const{length:t}=e;let n,r;const o={};for(let i=0;i<t;i++){let t;if(n=e[i],r=n,!Ft(n)&&(r=Lt[(t=String(n)).toLowerCase()],void 0===r))throw new ze(`Unknown adapter '${t}'`);if(r)break;o[t||"#"+i]=r}if(!r){const e=Object.entries(o).map(([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build"));throw new ze("There is no suitable adapter to dispatch the request "+(t?e.length>1?"since :\n"+e.map(Nt).join("\n"):" "+Nt(e[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return r};function Bt(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dt(null,e)}function Mt(e){return Bt(e),e.headers=lt.from(e.headers),e.data=ct.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1),It(e.adapter||nt.adapter)(e).then(function(t){return Bt(e),t.data=ct.call(e,e.transformResponse,t),t.headers=lt.from(t.headers),t},function(t){return ft(t)||(Bt(e),t&&t.response&&(t.response.data=ct.call(e,e.transformResponse,t.response),t.response.headers=lt.from(t.response.headers))),Promise.reject(t)})}const Dt={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Dt[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});const qt={};Dt.transitional=function(e,t,n){function r(e,t){return"[Axios v1.7.4] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,i)=>{if(!1===e)throw new ze(r(o," has been removed"+(t?" in "+t:"")),ze.ERR_DEPRECATED);return t&&!qt[o]&&(qt[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)}};var Jt={assertOptions:function(e,t,n){if("object"!=typeof e)throw new ze("options must be an object",ze.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const i=r[o],s=t[i];if(s){const t=e[i],n=void 0===t||s(t,i,e);if(!0!==n)throw new ze("option "+i+" must be "+n,ze.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new ze("Unknown option "+i,ze.ERR_BAD_OPTION)}},validators:Dt};const Ht=Jt.validators;class Gt{constructor(e){this.defaults=e,this.interceptors={request:new Ve,response:new Ve}}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=t.stack?t.stack.replace(/^.+\n/,""):"";try{e.stack?n&&!String(e.stack).endsWith(n.replace(/^.+\n.+\n/,""))&&(e.stack+="\n"+n):e.stack=n}catch(e){}}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=_t(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;void 0!==n&&Jt.assertOptions(n,{silentJSONParsing:Ht.transitional(Ht.boolean),forcedJSONParsing:Ht.transitional(Ht.boolean),clarifyTimeoutError:Ht.transitional(Ht.boolean)},!1),null!=r&&(Ae.isFunction(r)?t.paramsSerializer={serialize:r}:Jt.assertOptions(r,{encode:Ht.function,serialize:Ht.function},!0)),t.method=(t.method||this.defaults.method||"get").toLowerCase();let i=o&&Ae.merge(o.common,o[t.method]);o&&Ae.forEach(["delete","get","head","post","put","patch","common"],e=>{delete o[e]}),t.headers=lt.concat(i,o);const s=[];let a=!0;this.interceptors.request.forEach(function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,s.unshift(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=[Mt.bind(this),void 0];for(e.unshift.apply(e,s),e.push.apply(e,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=0;f<c;){const e=s[f++],t=s[f++];try{d=e(d)}catch(e){t.call(this,e);break}}try{l=Mt.call(this,d)}catch(e){return Promise.reject(e)}for(f=0,c=u.length;f<c;)l=l.then(u[f++],u[f++]);return l}getUri(e){return Ge(bt((e=_t(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}Ae.forEach(["delete","get","head","options"],function(e){Gt.prototype[e]=function(t,n){return this.request(_t(n||{},{method:e,url:t,data:(n||{}).data}))}}),Ae.forEach(["post","put","patch"],function(e){function t(t){return function(n,r,o){return this.request(_t(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}Gt.prototype[e]=t(),Gt.prototype[e+"Form"]=t(!0)});var Vt=Gt;class Kt{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)}static source(){let e;return{token:new Kt(function(t){e=t}),cancel:e}}}var $t=Kt;const Xt={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};Object.entries(Xt).forEach(([e,t])=>{Xt[t]=e});var Yt=Xt;const Zt=function e(t){const n=new Vt(t),r=q(Vt.prototype.request,n);return Ae.extend(r,Vt.prototype,n,{allOwnKeys:!0}),Ae.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(_t(t,n))},r}(nt);Zt.Axios=Vt,Zt.CanceledError=dt,Zt.CancelToken=$t,Zt.isCancel=ft,Zt.VERSION="1.7.4",Zt.toFormData=Me,Zt.AxiosError=ze,Zt.Cancel=Zt.CanceledError,Zt.all=function(e){return Promise.all(e)},Zt.spread=function(e){return function(t){return e.apply(null,t)}},Zt.isAxiosError=function(e){return Ae.isObject(e)&&!0===e.isAxiosError},Zt.mergeConfig=_t,Zt.AxiosHeaders=lt,Zt.formToJSON=e=>et(Ae.isHTMLForm(e)?new FormData(e):e),Zt.getAdapter=It,Zt.HttpStatusCode=Yt,Zt.default=Zt;var Qt=Zt;const{CanceledError:en}=Qt;var tn=function(e,t){try{var n=t.baseUrl+I.jobs.post_update,r=k({},B(t),{job_id:e.identifier,status:e.status});return Promise.resolve(fetch(n,k({},M,{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 nn(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function rn(e,t,n){if(!e.s){if(n instanceof on){if(!n.s)return void(n.o=rn.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(rn.bind(null,e,t),rn.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var on=/*#__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{rn(r,1,i(this.v))}catch(e){rn(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?rn(r,1,t?t(o):o):n?rn(r,1,n(o)):rn(r,2,o)}catch(e){rn(r,2,e)}},r},e}();function sn(e){return e instanceof on&&1&e.s}function an(e,t,n){for(var r;;){var o=e();if(sn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!sn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!sn(s)){r=2;break}}}var a=new on,u=rn.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&&!sn(s))return void s.then(f).then(void 0,u);if(!(o=e())||sn(o)&&!o.v)return void rn(a,1,i);if(o.then)return void o.then(c).then(void 0,u);sn(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):rn(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):rn(a,1,i)}}var un,ln,cn=16777216,fn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},dn={__proto__:null,default:{}},hn=(un=function(t){!function(){var n="input is invalid type",r="object"==typeof window,o=r?window:{};o.JS_MD5_NO_WINDOW&&(r=!1);var i=!r&&"object"==typeof self,s=!o.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;s?o=fn:i&&(o=self);var a,u=!o.JS_MD5_NO_COMMON_JS&&t.exports,l=!o.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),f=[128,32768,8388608,-2147483648],d=[0,8,16,24],h=["hex","array","digest","buffer","arrayBuffer","base64"],p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),m=[];if(l){var g=new ArrayBuffer(68);a=new Uint8Array(g),m=new Uint32Array(g)}var v=Array.isArray;!o.JS_MD5_NO_NODE_JS&&v||(v=function(e){return"[object Array]"===Object.prototype.toString.call(e)});var y=ArrayBuffer.isView;!l||!o.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&y||(y=function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer});var b=function(e){var t=typeof e;if("string"===t)return[e,!0];if("object"!==t||null===e)throw new Error(n);if(l&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!v(e)&&!y(e))throw new Error(n);return[e,!1]},w=function(e){return function(t){return new P(!0).update(t)[e]()}},_=function(e){return function(t,n){return new x(t,!0).update(n)[e]()}};function P(e){if(e)m[0]=m[16]=m[1]=m[2]=m[3]=m[4]=m[5]=m[6]=m[7]=m[8]=m[9]=m[10]=m[11]=m[12]=m[13]=m[14]=m[15]=0,this.blocks=m,this.buffer8=a;else if(l){var t=new ArrayBuffer(68);this.buffer8=new Uint8Array(t),this.blocks=new Uint32Array(t)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function x(e,t){var n,r=b(e);if(e=r[0],r[1]){var o,i=[],s=e.length,a=0;for(n=0;n<s;++n)(o=e.charCodeAt(n))<128?i[a++]=o:o<2048?(i[a++]=192|o>>>6,i[a++]=128|63&o):o<55296||o>=57344?(i[a++]=224|o>>>12,i[a++]=128|o>>>6&63,i[a++]=128|63&o):(o=65536+((1023&o)<<10|1023&e.charCodeAt(++n)),i[a++]=240|o>>>18,i[a++]=128|o>>>12&63,i[a++]=128|o>>>6&63,i[a++]=128|63&o);e=i}e.length>64&&(e=new P(!0).update(e).array());var u=[],l=[];for(n=0;n<64;++n){var c=e[n]||0;u[n]=92^c,l[n]=54^c}P.call(this,t),this.update(l),this.oKeyPad=u,this.inner=!0,this.sharedMemory=t}P.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");for(var t,n,r=b(e),o=r[1],i=0,s=(e=r[0]).length,a=this.blocks,u=this.buffer8;i<s;){if(this.hashed&&(this.hashed=!1,a[0]=a[16],a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),o)if(l)for(n=this.start;i<s&&n<64;++i)(t=e.charCodeAt(i))<128?u[n++]=t:t<2048?(u[n++]=192|t>>>6,u[n++]=128|63&t):t<55296||t>=57344?(u[n++]=224|t>>>12,u[n++]=128|t>>>6&63,u[n++]=128|63&t):(t=65536+((1023&t)<<10|1023&e.charCodeAt(++i)),u[n++]=240|t>>>18,u[n++]=128|t>>>12&63,u[n++]=128|t>>>6&63,u[n++]=128|63&t);else for(n=this.start;i<s&&n<64;++i)(t=e.charCodeAt(i))<128?a[n>>>2]|=t<<d[3&n++]:t<2048?(a[n>>>2]|=(192|t>>>6)<<d[3&n++],a[n>>>2]|=(128|63&t)<<d[3&n++]):t<55296||t>=57344?(a[n>>>2]|=(224|t>>>12)<<d[3&n++],a[n>>>2]|=(128|t>>>6&63)<<d[3&n++],a[n>>>2]|=(128|63&t)<<d[3&n++]):(t=65536+((1023&t)<<10|1023&e.charCodeAt(++i)),a[n>>>2]|=(240|t>>>18)<<d[3&n++],a[n>>>2]|=(128|t>>>12&63)<<d[3&n++],a[n>>>2]|=(128|t>>>6&63)<<d[3&n++],a[n>>>2]|=(128|63&t)<<d[3&n++]);else if(l)for(n=this.start;i<s&&n<64;++i)u[n++]=e[i];else for(n=this.start;i<s&&n<64;++i)a[n>>>2]|=e[i]<<d[3&n++];this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},P.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[t>>>2]|=f[3&t],t>=56&&(this.hashed||this.hash(),e[0]=e[16],e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.bytes<<3,e[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},P.prototype.hash=function(){var e,t,n,r,o,i,s=this.blocks;this.first?t=((t=((e=((e=s[0]-680876937)<<7|e>>>25)-271733879|0)^(n=((n=(-271733879^(r=((r=(-1732584194^2004318071&e)+s[1]-117830708)<<12|r>>>20)+e|0)&(-271733879^e))+s[2]-1126478375)<<17|n>>>15)+r|0)&(r^e))+s[3]-1316259209)<<22|t>>>10)+n|0:(e=this.h0,t=this.h1,t=((t+=((e=((e+=((r=this.h3)^t&((n=this.h2)^r))+s[0]-680876936)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[1]-389564586)<<12|r>>>20)+e|0)&(e^t))+s[2]+606105819)<<17|n>>>15)+r|0)&(r^e))+s[3]-1044525330)<<22|t>>>10)+n|0),t=((t+=((e=((e+=(r^t&(n^r))+s[4]-176418897)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[5]+1200080426)<<12|r>>>20)+e|0)&(e^t))+s[6]-1473231341)<<17|n>>>15)+r|0)&(r^e))+s[7]-45705983)<<22|t>>>10)+n|0,t=((t+=((e=((e+=(r^t&(n^r))+s[8]+1770035416)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[9]-1958414417)<<12|r>>>20)+e|0)&(e^t))+s[10]-42063)<<17|n>>>15)+r|0)&(r^e))+s[11]-1990404162)<<22|t>>>10)+n|0,t=((t+=((e=((e+=(r^t&(n^r))+s[12]+1804603682)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[13]-40341101)<<12|r>>>20)+e|0)&(e^t))+s[14]-1502002290)<<17|n>>>15)+r|0)&(r^e))+s[15]+1236535329)<<22|t>>>10)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[1]-165796510)<<5|e>>>27)+t|0)^t))+s[6]-1069501632)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[11]+643717713)<<14|n>>>18)+r|0)^r))+s[0]-373897302)<<20|t>>>12)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[5]-701558691)<<5|e>>>27)+t|0)^t))+s[10]+38016083)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[15]-660478335)<<14|n>>>18)+r|0)^r))+s[4]-405537848)<<20|t>>>12)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[9]+568446438)<<5|e>>>27)+t|0)^t))+s[14]-1019803690)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[3]-187363961)<<14|n>>>18)+r|0)^r))+s[8]+1163531501)<<20|t>>>12)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[13]-1444681467)<<5|e>>>27)+t|0)^t))+s[2]-51403784)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[7]+1735328473)<<14|n>>>18)+r|0)^r))+s[12]-1926607734)<<20|t>>>12)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[5]-378558)<<4|e>>>28)+t|0))+s[8]-2022574463)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[11]+1839030562)<<16|n>>>16)+r|0))+s[14]-35309556)<<23|t>>>9)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[1]-1530992060)<<4|e>>>28)+t|0))+s[4]+1272893353)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[7]-155497632)<<16|n>>>16)+r|0))+s[10]-1094730640)<<23|t>>>9)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[13]+681279174)<<4|e>>>28)+t|0))+s[0]-358537222)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[3]-722521979)<<16|n>>>16)+r|0))+s[6]+76029189)<<23|t>>>9)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[9]-640364487)<<4|e>>>28)+t|0))+s[12]-421815835)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[15]+530742520)<<16|n>>>16)+r|0))+s[2]-995338651)<<23|t>>>9)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[0]-198630844)<<6|e>>>26)+t|0)|~n))+s[7]+1126891415)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[14]-1416354905)<<15|n>>>17)+r|0)|~e))+s[5]-57434055)<<21|t>>>11)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[12]+1700485571)<<6|e>>>26)+t|0)|~n))+s[3]-1894986606)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[10]-1051523)<<15|n>>>17)+r|0)|~e))+s[1]-2054922799)<<21|t>>>11)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[8]+1873313359)<<6|e>>>26)+t|0)|~n))+s[15]-30611744)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[6]-1560198380)<<15|n>>>17)+r|0)|~e))+s[13]+1309151649)<<21|t>>>11)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[4]-145523070)<<6|e>>>26)+t|0)|~n))+s[11]-1120210379)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[2]+718787259)<<15|n>>>17)+r|0)|~e))+s[9]-343485551)<<21|t>>>11)+n|0,this.first?(this.h0=e+1732584193|0,this.h1=t-271733879|0,this.h2=n-1732584194|0,this.h3=r+271733878|0,this.first=!1):(this.h0=this.h0+e|0,this.h1=this.h1+t|0,this.h2=this.h2+n|0,this.h3=this.h3+r|0)},P.prototype.toString=P.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3;return c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[n>>>4&15]+c[15&n]+c[n>>>12&15]+c[n>>>8&15]+c[n>>>20&15]+c[n>>>16&15]+c[n>>>28&15]+c[n>>>24&15]+c[r>>>4&15]+c[15&r]+c[r>>>12&15]+c[r>>>8&15]+c[r>>>20&15]+c[r>>>16&15]+c[r>>>28&15]+c[r>>>24&15]},P.prototype.array=P.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3;return[255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&n,n>>>8&255,n>>>16&255,n>>>24&255,255&r,r>>>8&255,r>>>16&255,r>>>24&255]},P.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(16),t=new Uint32Array(e);return t[0]=this.h0,t[1]=this.h1,t[2]=this.h2,t[3]=this.h3,e},P.prototype.buffer=P.prototype.arrayBuffer,P.prototype.base64=function(){for(var e,t,n,r="",o=this.array(),i=0;i<15;)e=o[i++],t=o[i++],n=o[i++],r+=p[e>>>2]+p[63&(e<<4|t>>>4)]+p[63&(t<<2|n>>>6)]+p[63&n];return r+(p[(e=o[i])>>>2]+p[e<<4&63]+"==")},(x.prototype=new P).finalize=function(){if(P.prototype.finalize.call(this),this.inner){this.inner=!1;var e=this.array();P.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(e),P.prototype.finalize.call(this)}};var S=function(){var t=w("hex");s&&(t=function(t){var r,i=dn,s=e.Buffer;return r=s.from&&!o.JS_MD5_NO_BUFFER_FROM?s.from:function(e){return new s(e)},function(e){if("string"==typeof e)return i.createHash("md5").update(e,"utf8").digest("hex");if(null==e)throw new Error(n);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),v(e)||y(e)||e.constructor===s?i.createHash("md5").update(r(e)).digest("hex"):t(e)}}(t)),t.create=function(){return new P},t.update=function(e){return t.create().update(e)};for(var r=0;r<h.length;++r){var i=h[r];t[i]=w(i)}return t}();S.md5=S,S.md5.hmac=function(){var e=_("hex");e.create=function(e){return new x(e)},e.update=function(t,n){return e.create(t).update(n)};for(var t=0;t<h.length;++t){var n=h[t];e[n]=_(n)}return e}(),u?t.exports=S:o.md5=S}()},un(ln={exports:{}}),ln.exports);function pn(e,t=0){return yn(e,t,2).getUint16(0,!0)}function mn(e,t=0){return yn(e,t,4).getUint32(0,!0)}function gn(e,t=0,n=e.byteLength){const r=e.slice(t,t+n);return bn.decode(new Uint8Array(r))}function vn(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 yn(e,t,n){const r=e.slice(t,t+n);return new DataView(new Uint8Array(r).buffer)}const bn=new TextDecoder("utf8"),wn=[["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 _n(e){return e.flatMap(([e,t,n,r={},o=[]])=>[[e,t,n,r],...o])}function Pn(e,t){const n=pn(e,26),r=gn(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=mn(e,18),r=mn(e,22),o=pn(e,28);if(n===r){const r=gn(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 xn=function(e){return _n(e).map(([e,t,n,{offset:r=0}={}])=>n.length+r).reduce((e,t)=>t>e?t:e,0)}(wn);function Sn(e,t){for(const[n,r,o,{exact:i=!0,offset:s=0}={},a=[]]of t)if(vn(e,o,s)){if("zip"===n&&!i)return Pn(e.buffer,{ext:n,mime:r});if(!i&&a.length)for(const[t,n,r,{offset:o=0}={}]of a)if(vn(e,r,o))return{ext:t,mime:n};return{ext:n,mime:r}}}function En(e){var t=hn.md5.create();return t.update(e),t.base64()}function jn(e,t){void 0===t&&(t=void 0);var n=function(e,{extra:t=!1,hint:n}={}){const r=new Uint8Array(e.slice(0,xn));if(n){const e=function(e,{ext:t,mime:n}){return t||n?_n(e).filter(e=>e[0]===t||e[1]===n):[]}(wn,n);if(e.length>0){const t=Sn(r,e);if(void 0!==t)return t}}return Sn(r,wn)||(t?function(e){return function(e){try{const t=gn(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=Tn(t)),s}function Tn(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 kn(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 Wn(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))}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var On=function(e){try{return Promise.resolve(new Promise(function(t){return setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},Rn=/*#__PURE__*/N(/^image_(\d+)_|^mesh_lod_(\d+)_/,{image_lod:1,mesh_lod:2});function Un(e,t,n){if(!e.s){if(n instanceof An){if(!n.s)return void(n.o=Un.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Un.bind(null,e,t),Un.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var An=/*#__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{Un(r,1,i(this.v))}catch(e){Un(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Un(r,1,t?t(o):o):n?Un(r,1,n(o)):Un(r,2,o)}catch(e){Un(r,2,e)}},r},e}();function zn(e){return e instanceof An&&1&e.s}function Cn(e){return e.includes("\\u")?JSON.parse('"'+e+'"'):decodeURIComponent(e)}function Ln(e){for(var t,n=Infinity,r=[],o=T(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 Nn=/*#__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}();function Fn(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function In(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)}function Bn(e,t,n){if(!e.s){if(n instanceof Mn){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)}}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var Mn=/*#__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 Dn(e){return e instanceof Mn&&1&e.s}function qn(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(!Dn(a))return void a.then(s,o||(o=Bn.bind(null,r=new Mn,2)));a=a.v}r?Bn(r,1,a):r=a}catch(e){Bn(r||(r=new Mn),2,e)}}(),r}function Jn(e,t,n){for(var r;;){var o=e();if(Dn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Dn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Dn(s)){r=2;break}}}var a=new Mn,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&&!Dn(s))return void s.then(f).then(void 0,u);if(!(o=e())||Dn(o)&&!o.v)return void Bn(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Dn(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)}}var Hn=[];function Gn(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];l?t.push("S3 "+l+(c?": "+c:"")):u&&t.push(u.slice(0,200))}e.message&&t.push(String(e.message))}catch(e){}return 0===t.length&&e.message&&t.push(String(e.message)),t.length?t.join(" — "):"unknown upload error"}var Vn=12e4;function Kn(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 $n=["chat_url"];function Xn(e){return Yn.apply(this,arguments)}function Yn(){return Yn=z(/*#__PURE__*/U().mark(function e(t){var n,r,o,i,s,a,u,l,c,f;return U().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,j(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=T(a);case 16:if((l=u()).done){e.next=24;break}if(!(c=Zn(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=Zn(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]])})),Yn.apply(this,arguments)}function Zn(e){for(var t,n=null,r="",o=void 0,i=T(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"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":a={type:"error",message:decodeURIComponent(r)};break;case"stopped":a={type:"stopped"};break;case"tool_call":a=k({type:"tool_call"},JSON.parse(r));break;case"tool_result":a=k({type:"tool_result"},JSON.parse(r));break;case"elicitation":a=k({type:"elicitation"},JSON.parse(r));break;case"done":var u=JSON.parse(r),l=u.chat_url;a={type:"done",token_usage:R(u,$n)},l&&(a.chat_url=l);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 Qn(e,t){var n=B(e);return null!=t&&t.personal&&(n["x-needle-ai-chat"]="personal"),null!=t&&t.instanceId&&(n["x-needle-instance-id"]=t.instanceId),n}var er=function(e,t){try{var n=new URL(e.baseUrl+I.ai.chat),r=Qn(e,t);return r["Content-Type"]="application/json",Promise.resolve(fetch(n,k({},M,{method:"POST",headers:r,body:JSON.stringify({type:"new_message",slug:t.slug,message:t.message,stream:!1,source:t.source,full_url:t.full_url,pathname:t.pathname,context:t.context})}))).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 send chat message ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},tr=function(e){try{var t=new URL(e.baseUrl+I.ai.list_chats),n=Qn(e);return Promise.resolve(fetch(t,k({},M,{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 nr(e,t){return t.stream?function(e,t){return rr.apply(this,arguments)}(e,t):er(e,t)}function rr(){return rr=z(/*#__PURE__*/U().mark(function e(t,n){var r,o,i,s;return U().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new URL(t.baseUrl+I.ai.chat),(o=Qn(t,n))["Content-Type"]="application/json",i={type:"new_message",slug:n.slug,message:n.message,stream:!0,source:n.source,full_url:n.full_url,pathname:n.pathname,context:n.context},e.next=6,j(fetch(r,k({},M,{method:"POST",headers:o,body:JSON.stringify(i)})));case 6:if((s=e.sent).ok){e.next=12;break}return e.next=10,j(s.text());case 10:throw new Error("Failed to stream chat message ("+s.status+"): "+e.sent);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(x(S(Xn(s.body))),"t0",15);case 15:case"end":return e.stop()}},e)})),rr.apply(this,arguments)}var or=globalThis.crypto.randomUUID();function ir(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.onToolRequest,l=r.toolReadyTimeout,c=void 0===l?5e3:l,f=r.personal,d=void 0!==f&&f,h=null,p=null,m=null,g=!1;function v(e){return y.apply(this,arguments)}function y(){return(y=z(/*#__PURE__*/U().mark(function e(t){var n,r,o,i,s,a;return U().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=!1,r=!1,e.prev=2,i=S(t);case 4:return e.next=6,j(i.next());case 6:if(!(n=!(s=e.sent).done)){e.next=14;break}return"done"===(a=s.value).type&&(h=a.token_usage,a.chat_url&&(p=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,j(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;c>0&&(r=setTimeout(function(){n(new Error("ChatSession: WebSocket tool connection timed out after "+c+"ms. Tools will not be available for this chat session."))},c)),m=function(e,t){var n=t.source,r=void 0===n?"editor":n,o=t.tools,i=t.onToolRequest,s=t.onOpen,a=t.onClose,u=t.onError,l=t.reconnect,c=void 0===l||l,f=t.reconnectInterval,d=void 0===f?3e3:f,h=t.maxReconnectAttempts,p=void 0===h?10:h,m=or,g=null,v=!1,y=0,b=null,w=[].concat(void 0===o?[]:o);function _(e){g&&1===g.readyState&&g.send(JSON.stringify(e))}function P(){_({type:"register",source:r,instanceId:m,tools:w})}return function t(){if(!v){if(g){try{g.close(1e3,"client reconnecting")}catch(e){}g=null}var n=function(){var t=""+e.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")+I.ai.ws+"?token="+encodeURIComponent(e.authToken);return e.org&&(t+="&org="+encodeURIComponent(e.org)),t+"&instance="+encodeURIComponent(m)}();(g=new WebSocket(n)).onopen=function(){y=0,P(),null==s||s()},g.onmessage=function(e){!function(e){try{var t=JSON.parse(e);if("execute_tool"===t.type&&t.requestId&&t.toolName){var n=t.requestId,r=t.toolName,o=t.args||{};if(!i)return void _({type:"tool_error",requestId:n,error:"No tool handler registered"});Promise.resolve().then(function(){return i(r,o)}).then(function(e){_(e.error?{type:"tool_error",requestId:n,error:e.error}:{type:"tool_result",requestId:n,result:e.result})}).catch(function(e){_({type:"tool_error",requestId:n,error:(null==e?void 0:e.message)||String(e)})})}}catch(e){}}("string"==typeof e.data?e.data:String(e.data))},g.onclose=function(e){var n,r;g=null,null==a||a(),"replaced"!==("string"==typeof(null==e?void 0:e.reason)?e.reason:null!=(n=null==e||null==(r=e.reason)||null==r.toString?void 0:r.toString())?n:"")&&4001!==(null==e?void 0:e.code)?!v&&c&&(y>=p?null==u||u(new Error("Max reconnect attempts ("+p+") reached")):(y++,b=setTimeout(function(){b=null,t()},d))):v=!0},g.onerror=function(t){var n=e.baseUrl.replace(/\/$/,"");null==u||u((null==t?void 0:t.error)||new Error("WebSocket error: can not connect to "+n+". Please try again later."))}}}(),{instanceId:m,updateTools:function(e){w=[].concat(e),P()},sendPresence:function(e){_(k({type:"presence"},e))},close:function(){v=!0,b&&(clearTimeout(b),b=null),g&&(g.close(1e3,"client closed"),g=null)},get connected(){return null!==g&&1===g.readyState}}}(e,{source:i,tools:a,onToolRequest:u,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 b={get ready(){return n},sendMessage:function(t,r,o){return z(/*#__PURE__*/U().mark(function s(){var a,u,l;return U().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,j(n);case 2:if(!g){s.next=4;break}throw new Error("ChatSession is closed");case 4:return l=nr(e,{slug:t,message:r,stream:!0,source:i,personal:d,instanceId:null!=(a=null==(u=m)?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}),s.delegateYield(x(S(v(l))),"t0",6);case 6:case"end":return s.stop()}},s)}))()},sendMessageSync:function(t,r,o){return Promise.resolve(n).then(function(){var n,s;if(g)throw new Error("ChatSession is closed");return Promise.resolve(nr(e,{slug:t,message:r,stream:!1,source:i,personal:d,instanceId:null!=(n=null==(s=m)?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})).then(function(e){return e.token_usage&&(h=e.token_usage),e.chat_url&&(p=e.chat_url),e})})},interruptChat:function(t){try{return Promise.resolve(function(e,t,n){try{var r=new URL(e.baseUrl+I.ai.chat_stop),o=Qn(e,n);return o["Content-Type"]="application/json",Promise.resolve(fetch(r,k({},M,{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:d}))}catch(e){return Promise.reject(e)}},readChat:function(t,n){try{return Promise.resolve(function(e,t,n){try{return null!=n&&n.reconnect?function(e,t,n){try{var r=new URL(e.baseUrl+I.ai.chat+"/"+encodeURIComponent(t)),o=Qn(e,n);return o.Accept="text/event-stream",Promise.resolve(fetch(r,k({},M,{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?Xn(e.body):null})}catch(e){return Promise.reject(e)}}(e,t,n):function(e,t,n){try{var r=new URL(e.baseUrl+I.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=Qn(e,n);return Promise.resolve(fetch(r,k({},M,{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)}}(e,t,{offset:null==n?void 0:n.offset,limit:null==n?void 0:n.limit,personal:d})).then(function(e){return e.chat_url&&(p=e.chat_url),e})}catch(e){return Promise.reject(e)}},listChats:function(){try{return Promise.resolve(tr(e))}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){m&&m.updateTools(e)},get usage(){return h},get chatUrl(){return p},get toolsConnected(){var e,t;return null!=(e=null==(t=m)?void 0:t.connected)&&e},get instanceId(){var e,t;return null!=(e=null==(t=m)?void 0:t.instanceId)?e:null},close:function(){g=!0,m&&(m.close(),m=null)}};return b}var sr=function(e,t){try{return Promise.resolve(t?{authToken:t,org:e||void 0}:v.requestAccessToken(e).then(function(t){return{authToken:t,org:e||void 0}}))}catch(e){return Promise.reject(e)}},ar=function(e,t){try{return Promise.resolve(sr(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||Tn(e.name);e=new File([e.buffer],e.name,{type:n})}else e.type||(e=new File([e],e.name,{type:Tn(e.name)}));var r,o=e;return null==t&&(t=e.webkitRelativePath||""),o.path=t+e.name,o}(e)});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=T(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=T(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=T(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 g=function(e){for(var t,n=new Array,r=/(mesh_lod|image)_\d_(.{1,50})/,o=T(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=Ln(n)[0])?a:null;var a}(m);return g?t=g:(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 v=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(v.length>=1)return t=function(e){for(var t,n,r=Ln(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}(v),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 _=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(_.length>1)return n="Invalid upload: Multiple splat files found. Upload them as separate content items.",console.error(n,_.map(function(e){return e.path||e.name})),{error:n};if(1===_.length)return _[0];if(1===e.length&&!e[0].arrayBuffer&&e[0].path.toLowerCase().startsWith("http"))return e[0];var P=e.filter(function(e){return e.name.toLowerCase().endsWith("package.json")});if(1===P.length)return P[0];if(P.length>1)return n="Invalid upload: Multiple package.json files found. This is currently not supported.",console.error(n,P),{error:n};var x=e.filter(function(e){return e.name.toLowerCase().endsWith(".mtlx")});if(x.length>1)return n="Invalid upload: Multiple mtlx files found. This is currently not supported.",console.error(n,x),{error:n};if(1===x.length)return x[0];var S=e.filter(function(e){var t=e.name.toLowerCase();return t.endsWith(".exr")||t.endsWith(".hdr")||t.endsWith(".hdri")});return S.length>1?(n="Invalid upload: Multiple HDRI files found. Upload them as separate content items.",console.error(n,S.map(function(e){return e.path||e.name})),{error:n}):1===S.length?t=S[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(zn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!zn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!zn(s)){r=2;break}}}var a=new An,u=Un.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&&!zn(s))return void s.then(f).then(void 0,u);if(!(o=e())||zn(o)&&!o.v)return void Un(a,1,i);if(o.then)return void o.then(c).then(void 0,u);zn(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):Un(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Un(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)&&Rn.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__*/N(/"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=T(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+"/"+Cn(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,g=T(e);!(m=g()).done;){var v=m.value;if(v.webkitRelativePath===p||v.name==p){h=!0,console.log("✅ Found dependency in name or webkit: "+v.name+" || "+v.webkitRelativePath+" ");break}if(v.path===p){h=!0,console.log("✅ Found dependency in path: "+v.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;function f(r){var o,i,a,l,f,d,h;if(c)return r;function p(r){function o(){return Promise.resolve(fetch(m+I.upload.request,k({},M,{method:"POST",headers:v,body:JSON.stringify(b)})).catch(function(e){return"fetch failed"==e.message||"Failed to fetch"==e.message?"Network error. Make sure you are connected to the internet and "+m+" 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(){if(!_interrupt){var t,o=function(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,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()).then(function(t){return console.error("Failed to complete upload ("+l.status+"): "+t),e=1,{success:!1,error:"Failed to complete upload"}})}();return n&&n.then?n.then(t):t(n)}h=!0,console.log("Upload Done: All files uploaded to "+r.id);var a=k({},B(e),{id:r.id});"none"!=u&&console.log("Completing upload - notify server");var l=null,f=0,d=Jn(function(){return!n&&f<5},function(){return f++},function(){return Promise.resolve(On(1e3*f)).then(function(){var e=AbortSignal.timeout(6e4+5e3*f);return Promise.resolve(fetch(m+I.upload.done,k({},M,{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)?"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(tn({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)},i=function(){if(x)return Promise.resolve(tn({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};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(m+I.upload.cancel,k({},M,{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()-v<1e3)return!1;if(!h||"completed"===n){v=Date.now();var i=Math.floor(d/c*100);return"debug"===u&&console.log("SET STATUS: "+n,t,i),tn({identifier:r.id,status:n,status_message:t,progress:i},e),!0}"none"!=u&&console.warn("Invalid status update...")}var v=Date.now();null!=(i=n)&&i.onStart&&n.onStart(r.id,r.content_id);var b=Date.now(),_=new Nn(s.length,c/1024/1024),P=new Array,x=!1,S=[].concat(s),E=s.length,j=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))}}(),T=In(function(){var o;function i(){return Promise.resolve(Promise.all(P).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),x=!0)})).then(function(){})}var a=qn(S,function(i){var a;if(null!=(a=n)&&null!=(a=a.abort)&&a.aborted)return console.debug("Upload aborted"),void(o=1);if(x)return console.debug("Upload failed"),void(o=1);if(P.length<10){console.debug("Uploading file "+i+"/"+s.length+": "+s[i].name);var l=0,h=0,m=y.files[i],g=m.filename,v=w[i],S=m.content_length,j=m.content_type,T=s[i],W=T.name.endsWith(".gz")?"gzip":T.name.endsWith(".br")?"br":void 0,O=function(e){try{var t,n=function(t){var n;function o(e){var t=function(){var e;if(!h)return console.error("Failed to upload file "+a),Promise.resolve(tn({identifier:r,status:"failed",status_message:"Failed to upload file ("+a+"): "+(null==(e=w)?void 0:e.substring(0,200)),error:"Failed to upload file "+a},v)).then(function(){throw new Error("Failed to upload file "+a)})}();return!t||!t.then||t.then(function(e){return!0})}if(null==x)throw new Error('Failed to get presigned url for "'+a+'" "'+f+'" \n'+S);var i=x.presigned_url,h=!1,w=null,_=0,P=Jn(function(){return!n&&_<5},function(){return _++},function(){function t(){var t;if(null!=y&&null!=(t=y.abort)&&t.aborted)throw new en("Upload aborted");var r={"Content-Type":f,"Content-MD5":l};b&&(r["Content-Length"]=c.toString()),d&&(r["Content-Encoding"]=d),0===_&&"none"!=g&&console.log("Uploading file "+p+"/"+m+": "+a),"debug"===g&&console.debug("PUT with headers",r);var o=new AbortController,v=!1,P=function(){return o.abort()};null!=y&&y.abort&&(y.abort.aborted?o.abort():y.abort.addEventListener("abort",P,{once:!0}));var S=Kn(Vn,function(){v=!0,o.abort()});return S.reset(),Promise.resolve(Qt.put(i,u,k({},M,{withCredentials:!1,signal:o.signal,headers:r,onUploadProgress:function(t){S.reset(),e.onProgress(t)}})).catch(function(e){var t;if(null!=y&&null!=(t=y.abort)&&t.aborted)throw new en("Upload aborted");return v?(w="stalled: no upload progress for 120s","none"!==g&&console.error("Upload stalled (PUT) ("+p+", "+a+") after 120s with no progress"),null):(w=Gn(e),e instanceof en||("none"!==g&&console.error("Failed to upload file (PUT) ("+p+", "+a+') "'+w+'"'),"debug"===g&&(console.log(r,{fileSize:c}),e.response?console.debug(e.response):console.debug(e))),null)}).finally(function(){S.cancel(),null!=y&&y.abort&&y.abort.removeEventListener("abort",P)})).then(function(e){if(e)return 200!==e.status?(w=Gn({response:e}),void console.debug("Failed ("+e.status+" "+e.status+") to upload file "+s.name+' to "'+x.path+'". Retrying...')):(h=!0,"info"===g&&console.log("Uploaded file "+p+"/"+m+' "'+a+'" ('+f+", "+kn(c)+")"),void(n=1))})}var r=function(){if(_>0)return"none"!==g&&console.log("Retry PUT #"+_+" for file "+a),Promise.resolve(On(1e3*_)).then(function(){})}();return r&&r.then?r.then(t):t()});return P&&P.then?P.then(o):o()};if(e.fileSize>=67108864)return function(e){try{var t=function(e,t,n){try{return Promise.resolve(fetch(e,k({},M,{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,g=e.retryDelayMs,v=e.putPart,y=c.baseUrl,b=function(){return k({},B(c),{"Content-Type":"application/json",org:c.org,job_id:n})},w=k({},b(),{filesize:l.toString()}),_=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?cn: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,g=e.onProgress,v=e.signal,y=e.checkCancelled,b=function(){try{var e;if(v&&v.aborted)return Promise.resolve(!0);var t=function(){if(y)return nn(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=cn),!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(an(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=nn(function(){return Promise.resolve(function(e){try{var t,r,o=function(n){if(t)return n;throw r||new Error("Failed to upload part "+e.partNumber)},s=i.get(e.partNumber);if(!s)throw new Error("Missing presigned url for part "+e.partNumber);var f=0,d=an(function(){return!t&&f<=u},function(){return f++},function(){return Promise.resolve(b()).then(function(o){function i(){return nn(function(){var r=n(e.start,e.end);return Promise.resolve(h({url:s,payload:r,partNumber:e.partNumber,size:e.size,signal:v})).then(function(n){if(!n)throw new Error("No ETag returned for part "+e.partNumber);a.push({part_number:e.partNumber,etag:n}),l+=e.size,g&&g(l),t=1})},function(e){return r=e,Promise.resolve(b()).then(function(t){if(t)throw e})})}if(o)throw new Error("Upload aborted");var u=function(){if(f>0&&c>0)return Promise.resolve((e=c*f,new Promise(function(t){return setTimeout(t,e)}))).then(function(){});var e}();return u&&u.then?u.then(i):i()})});return Promise.resolve(d&&d.then?d.then(o):o(d))}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:g,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+I.upload.multipart_create,k({},M,{method:"POST",headers:w,body:_}))).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+I.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:v||function(e){return function(e){var t=e.url,n=e.payload,r=e.partNumber,o=e.contentType,i=e.signal;try{var s=i,a=new AbortController,u=!1,l=function(){return a.abort()};s&&(s.aborted?a.abort():s.addEventListener("abort",l,{once:!0}));var c=Kn(Vn,function(){u=!0,a.abort()});return c.reset(),Promise.resolve(In(function(){return Fn(function(){return Promise.resolve(Qt.put(t,n,k({},M,{withCredentials:!1,signal:a.signal,headers:{"Content-Type":o},onUploadProgress:function(){return c.reset()}}))).then(function(e){var t,n;if(200!==e.status)throw new Error(Gn({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!=s&&s.aborted)throw e;if(u)throw new Error("Part "+r+" stalled: no progress for 120s");throw new Error(Gn(e))})},function(e,t){if(c.cancel(),s&&s.removeEventListener("abort",l),e)throw t;return t}))}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+I.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+I.upload.multipart_abort,k({},M,{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 r=e.uploadId,o=e.uploadRequestPUTUrl,i=e.entrypointPath,s=e.file,a=e.fileName,u=e.fileBuffer,l=e.fileMd5,c=e.fileSize,f=e.fileType,d=e.content_encoding,h=e.fileIndex,p=e.fileNumber,m=e.fileCount,g=e.loglevel,v=e.args,y=e.options,b=e.experimental;"info"===g&&console.log('Uploading file "'+s.name+'" type='+f+" ("+c+") "+s.type+" with hash "+l);var w=k({},B(v),{"Content-Type":"application/json",org:v.org,job_id:r,filesize:c.toString(),progress:(h/m*100).toFixed(0)}),_={filename:a,entrypoint:i,"content-type":f,"content-md5":l,"content-encoding":d,output_index:0};"debug"===g&&console.debug("Requesting presigned URL with headers",w);var P=JSON.stringify(_),x=null,S="",E=0,j=Jn(function(){return!t&&E<5},function(){return E++},function(){var e;if(null==x){if(null!=y&&null!=(e=y.abort)&&e.aborted)throw new Error("Upload aborted");return Promise.resolve(On(200*E)).then(function(){return Promise.resolve(fetch(o,k({},M,{method:"POST",headers:w,body:P})).then(function(e){try{var t,n=function(n){return t?n:Promise.resolve(e.json())},r=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(n){return S=n,console.log(o),console.warn('Failed to get presigned url for "'+a+'" "'+f+'" ('+e.status+").\n→ Retrying..."),t=1,null})}();return Promise.resolve(r&&r.then?r.then(n):n(r))}catch(e){return Promise.reject(e)}}).catch(function(e){return S=e.message,console.warn("Failed to get presigned url "+e.message+", retrying..."),null})).then(function(e){x=e})})}t=1});return Promise.resolve(j&&j.then?j.then(n):n())}catch(e){return Promise.reject(e)}}({uploadId:r.id,uploadRequestPUTUrl:r.request_put_url,entrypointPath:f,file:s[i],fileName:g,fileMd5:m.content_md5,fileBuffer:v,fileType:j,content_encoding:W,fileSize:S,fileIndex:i,fileNumber:i+1,fileCount:E,loglevel:u,experimental:t.experimental,args:e,options:n,onProgress:function(e){var t,r=e.progress||0,o=(l=s[i].size*r)-h;if(h=l,d+=o,null!=(t=n)&&t.progress){var a=d/c,u=s.length,f=s[i].size,m=(Date.now()-b)/1e3,v=_.updateProgress(d/1024/1024);n.progress({uploadedBytes:d,totalBytes:c,progress01:a,fileName:s[i].name,fileSize:f,fileProgress01:r,fileIndex:i,totalFiles:u,estimatedTimeLeftDisplay:v.estimatedTimeRemainingString,estimatedTimeLeft:v.estimatedTimeRemaining,elapsedTime:m}),p("Uploading file "+(i+1)+"/"+u+" ("+g+"): "+(100*r).toFixed(0)+"% of "+kn(c)+". Finished in approx. "+v.estimatedTimeRemainingString,"running",!1)}}}).then(function(e){if(!0!==e)return e;for(var t=P.length-1;t>=0;t--)P[t]===O&&P.splice(t,1);p("Uploaded "+kn(d)+" of "+kn(c)+" for "+s[i].name,"running")}).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),x=!0)});P.push(O)}var R=function(){if(P.length>=10)return Promise.resolve(Promise.race(P)).then(function(){})}();return R&&R.then?R.then(function(){}):void 0},function(){return o});return a&&a.then?a.then(i):i()},function(e,t){if(j(),e)throw t;return t});return T&&T.then?T.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)})}var i=Fn(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=Wn(e,n);if(null===r)return null;if(0===r.length)return null;var o=Wn(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&&(y.width=e.width,y.height=e.height)})},function(e){"debug"===u&&console.warn("readImageResolution failed; uploading without dimensions",e)});return i&&i.then?i.then(o):o()}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 m=e.baseUrl,g="Bearer "+e.authToken,v=k({},B(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&&(v.content_id=n.content_id),null!=(i=n)&&i.type&&(v.type=n.type),null!=(a=n)&&a.name&&(v.name=encodeURIComponent(n.name)),null!=(l=n)&&l.parent_job_id&&(v.parent_job_id=n.parent_job_id);var y={entrypoint:(null==(f=t.entrypoint)?void 0:f.path)||(null==(d=t.entrypoint)?void 0:d.name),files:[]};null!=(h=n)&&h.content_type&&(y.content_type=n.content_type);var b={outputs:[y]},w=[],_=qn(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=jn(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=En(t);w[e]=t,y.files[e]={filename:o,content_type:f,content_length:c,content_md5:h}})},function(){});return _&&_.then?_.then(p):p()}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."};var d=function(){if(!t.raw)return qn(s,function(e){var r=s[e],o=r.name.toLowerCase();return function(){var i;if(o.endsWith(".html")||o.endsWith(".js")||o.endsWith(".css"))return"none"!==(null==(i=n)?void 0:i.loglevel)&&console.log("gZip compressing file: "+r.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)||jn(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)}}(r).catch(function(e){return{error:"Error compressing "+r.name+": "+e.message}})).then(function(o){var i;if(null!==o){if("error"in o)return c=1,{success:!1,error:o.error,status:500};if(!o)return c=1,{success:!1,error:"Failed to compress "+r.name,status:500};var a=t.entrypoint===r;s[e]=o,a&&(t.entrypoint=o),"none"!==(null==(i=n)?void 0:i.loglevel)&&console.log("gZip compressed file: "+r.name+" "+(a?"(entrypoint)":""))}else{var u;"none"!==(null==(u=n)?void 0:u.loglevel)&&console.error("Did not compress file: "+r.name)}})}()},function(){return c});"none"!=u&&console.warn("Raw upload - skipping gzip compression of files")}();return d&&d.then?d.then(f):f(d)})}catch(e){return Promise.reject(e)}}(e,t,n);return Hn.push(r),Promise.resolve(r.finally(function(){var e=Hn.indexOf(r);e>=0&&Hn.splice(e,1)}))}catch(e){return Promise.reject(e)}}(k({baseUrl:"https://cloud.needle.tools/api"},n,t),{triggered_by:"web",entrypoint:void 0,files:r},{name:t.name,abort:t.abort}).then(function(e){return"error"in e?{error:e.error}:{job_id:e.id,content_id:e.content_id,url:e.url,skipped:e.uploadSkipped}})})}catch(e){return Promise.reject(e)}},ur=function(e){try{return Promise.resolve(sr()).then(function(t){if(!t)return!1;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,s),D(k({baseUrl:"https://cloud.needle.tools/api"},t),{type:"user","x-needle-product":n.join(",")}).then(function(e){for(var t,n=T(e);!(t=n()).done;)if(t.value.valid)return!0;return!1})})}catch(e){return Promise.reject(e)}},lr=function(e){try{return Promise.resolve(sr()).then(function(t){if(!t)return null;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,s),D(k({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)}},cr=function(e){try{return Promise.resolve(sr(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")+I.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:k({},B({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)}}(k({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)}},fr=function(e,t){try{return Promise.resolve(hr(null==t?void 0:t.org)).then(function(n){return Promise.resolve(sr(n,null==t?void 0:t.authToken)).then(function(t){return ir(k({baseUrl:"https://cloud.needle.tools/api"},t),e)})})}catch(e){return Promise.reject(e)}},dr=function(e){try{return Promise.resolve(hr(null==e?void 0:e.org)).then(function(t){return Promise.resolve(sr(t,null==e?void 0:e.authToken)).then(function(e){return tr(k({baseUrl:"https://cloud.needle.tools/api"},e))})})}catch(e){return Promise.reject(e)}},hr=function(e){try{return Promise.resolve(e||v.getDefaultTeamId())}catch(e){return Promise.reject(e)}};function pr(e){return function(e,t){void 0===t&&(t={});try{var n=new URL("https://cloud.needle.tools/api"+I.public.content_list);if(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,k({},M,{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 mr(e){return function(e,t){try{var n="https://cloud.needle.tools/api"+I.public.content_list+"/"+encodeURIComponent(t);return Promise.resolve(fetch(n,k({},M,{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)}var gr=["org","authToken"],vr=function(e,t){void 0===t&&(t={});try{return Promise.resolve(sr(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+I.content.root+"/"+t,r=B(e);return Promise.resolve(fetch(n,k({},M,{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 get content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(k({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},yr=function(e){void 0===e&&(e={});try{var t=e.org,n=e.authToken,r=R(e,gr);return Promise.resolve(sr(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+I.content.root);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=B(e);return Promise.resolve(fetch(n,k({},M,{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)}}(k({baseUrl:"https://cloud.needle.tools/api"},e),r)})}catch(e){return Promise.reject(e)}},br=function(e){try{var t=new URL("https://cloud.needle.tools/api"+I.account.buy_licenses);return Promise.resolve(sr()).then(function(n){var r={mode:"payment",price_id:e.price_id,return_url:window.location.href,cancel_url:window.location.href};return Promise.resolve(fetch(t,{method:"POST",headers:k({"Content-Type":"application/json"},B(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}):{ok:!1,status:400}}):{ok:!1,status:e.status}})})}catch(e){return Promise.reject(e)}};export{v as Auth,i as AuthScopes,F as NeedleLoginButton,fr as createChatSession,vr as getContent,cr as getDeployments,mr as getPublicContent,lr as getUserLicenses,dr as listChats,yr as listContent,pr as listPublicContent,ur as ownsProduct,br as startCheckoutSession,ar as uploadFiles};
1
+ import e,{Buffer as t}from"buffer";import n,{UserScope as r}from"@logto/browser";globalThis.Buffer=t;var o,i={Basic:[r.Profile,r.Email],Payment:["read:accounting","write:accounting"],All:[r.Profile,r.Email,r.Roles,r.CustomData,r.Organizations,r.OrganizationRoles].concat(["all","read","write","delete","invite","download","create:org","write:org","delete:org","read:accounting","write:accounting","read:usage"])},s=["Needle Engine"],a="https://auth.needle.tools",u=void 0,l=[],c=null,f=null,d=null,h=null,p=new Array;function m(){p.forEach(function(e){try{e()}catch(e){console.error(e)}})}var g=!1,v={setDebug:function(e){g=e},baseUrl:window.location.origin,redirectUri:window.location.origin,postSignOutRedirectUri:window.location.origin,onChanged:function(e){return p.includes(e)||p.push(e),function(){for(;;){var t=p.indexOf(e);if(!(t>=0))break;p.splice(t,1)}}},ready:function(){return f?f.then(function(){return!0}):Promise.reject(new Error("Auth not initialized"))},init:function(e){return f||(f=function(e){try{var t,n,r=function(){var e=b(!0);if(!e)return v.checkIsAuthenticated().then(function(e){return!e||v.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&&(g=e.debug),g&&console.debug("Auth.init",e),null!=e&&e.scopes){switch(e.scopes){case"all":e.scopes=i.All;break;case"payment":e.scopes=i.Payment}l=e.scopes}l.length<=0&&(t=l).push.apply(t,i.Basic.concat(i.Payment)),g&&console.debug("Auth.init","Use scopes",l),null!=e&&e.appId?(null==(n=h)?void 0:n.logtoConfig.appId)!==(u=e.appId)&&(g&&console.debug("Auth.init","App ID changed, resetting client"),h=null):(u="2x82zzh5xuudmiotdy2ux",g&&console.debug("Auth.init","Use default app ID",u));var o=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(a))return w().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=b();t&&(console.log("Restore query before login",t,"Current:",e.search),e.search=t),window.history.replaceState({},"",e.href)}).catch(function(e){console.error(e)})}(),s=function(){if(o instanceof Promise)return Promise.resolve(o.then(function(e){return!0})).then(function(){})}();return Promise.resolve(s&&s.then?s.then(r):r())}catch(e){return Promise.reject(e)}}(e))},isAuthenticated:function(){return o},checkIsAuthenticated:function(){return w().isAuthenticated().then(function(e){return o=e,e})},getUserInfo:function(){return c},getUserId:function(){return c?c.sub:null},getName:function(){return c?c.username?c.username:c.name?c.name:c.email?c.email.split("@")[0]:null:null},requestUserInfo:function(){return d||(d=v.checkIsAuthenticated().then(function(e){return e?w().fetchUserInfo().then(function(e){var t;return g&&(null==e?void 0:e.sub)!=(null==(t=c)?void 0:t.sub)&&console.debug("UserInfo",e),c=e,m(),e}).catch(function(e){return console.error(e),c=null,m(),null}):(c=null,m(),null)}))},requestAccessToken:function(e){return g&&console.debug("requestAccessToken",{org_id:e}),e?w().getOrganizationToken(e):w().getAccessToken("https://cloud.needle.tools/api",e||void 0)},signIn:function(e){return v.checkIsAuthenticated().then(function(t){if(0==t){var n;if(null==(n=u)||!n.length)throw new Error("App ID is not set: Make sure to call 'init' first");y(),null!=e&&e.signUp?w().signIn({redirectUri:v.redirectUri,firstScreen:"register",interactionMode:"signUp"}):w().signIn(v.redirectUri)}})},getDefaultTeamId:function(){var e,t=null==(e=c)?void 0:e.custom_data,n=null==t?void 0:t.default_org;return"string"==typeof n?n:void 0},signOut:function(){return d=null,v.checkIsAuthenticated().then(function(e){if(1==e){var t;if(null==(t=u)||!t.length)throw new Error("App ID is not set: Make sure to call 'init' first");y(),w().signOut(v.postSignOutRedirectUri)}})}};function y(){sessionStorage.setItem("needle-auth:query",window.location.search)}function b(e){void 0===e&&(e=!0);var t=sessionStorage.getItem("needle-auth:query");return t?(e&&sessionStorage.removeItem("needle-auth:query"),t):""}function w(){if(!h){if(!u)throw new Error("App ID is not set: Make sure to call 'init' first");var e={endpoint:a,appId:u,scopes:l,resources:["https://cloud.needle.tools/api"]};g&&console.warn("Creating auth client:",g,e),h=new n(e)}return h}function _(e,t){this.v=e,this.k=t}function P(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 x(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 _(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 S(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 E(t.call(e));n="@@asyncIterator",r="@@iterator"}throw new TypeError("Object is not async iterable")}function E(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 E=function(e){this.s=e,this.n=e.next},E.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 E(e)}function j(e){return new _(e,0)}function T(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 P(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)?P(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 k(){return k=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},k.apply(null,arguments)}function W(e){return W=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},W(e)}function O(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(O=function(){return!!e})()}function R(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 U(){U=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 v?t:v).prototype),s=new O(r||[]);return o(i,"_invoke",{value:j(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",g={};function v(){}function y(){}function b(){}var w={};l(w,s,function(){return this});var _=Object.getPrototypeOf,P=_&&_(_(R([])));P&&P!==n&&r.call(P,s)&&(w=P);var x=b.prototype=v.prototype=Object.create(w);function S(e){["next","throw","return"].forEach(function(t){l(e,t,function(e){return this._invoke(t,e)})})}function E(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 j(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===g)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===g)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")),g;var i=f(o,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,g;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,g):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,g)}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 W(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function R(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(x,"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(x),e},t.awrap=function(e){return{__await:e}},S(E.prototype),l(E.prototype,a,function(){return this}),t.AsyncIterator=E,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var s=new E(c(e,n,r,o),i);return t.isGeneratorFunction(n)?s:s.next().then(function(e){return e.done?e.value:s.next()})},S(x),l(x,u,"Generator"),l(x,s,function(){return this}),l(x,"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=R,O.prototype={constructor:O,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(W),!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,g):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),g},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),W(n),g}},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;W(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:R(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),g}},t}function A(e,t){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},A(e,t)}function z(e){return function(){return new C(e.apply(this,arguments))}}function C(e){var t,n;function r(t,n){try{var i=e[t](n),s=i.value,a=s instanceof _;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 L(e){var t="function"==typeof Map?new Map:void 0;return L=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(O())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var o=new(e.bind.apply(e,r));return n&&A(o,n.prototype),o}(e,arguments,W(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),A(n,e)},L(e)}function N(){N=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)),A(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&&A(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)},N.apply(this,arguments)}C.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},C.prototype.next=function(e){return this._invoke("next",e)},C.prototype.throw=function(e){return this._invoke("throw",e)},C.prototype.return=function(e){return this._invoke("return",e)};var F=/*#__PURE__*/function(e){function t(){var t;return(t=e.call(this)||this).addEventListener("click",function(){v.isAuthenticated()?v.signOut():v.signIn()}),t}var n,r;r=e,(n=t).prototype=Object.create(r.prototype),n.prototype.constructor=n,A(n,r);var o=t.prototype;return o.connectedCallback=function(){var e=this;console.debug("Login button connected..."),this.__update(),this.__unsubscribeOnChange=v.onChanged(function(){e.__update()})},o.disconnectedCallback=function(){var e;null==(e=this.__unsubscribeOnChange)||e.call(this)},o.__update=function(){this.innerHTML=v.isAuthenticated()?"Logout":"Login"},t}(/*#__PURE__*/L(HTMLButtonElement));if(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",F,{extends:"button"});var I={status:"/v1/status",version:"/v1/version",api:"/v1/api",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",update_payment_method:"/v1/account/update_payment_method",get_billing:"/v1/account/get_billing",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"},ai:{llmstxt:"/v1/ai/llmstxt",chat:"/v1/ai/chat",chat_personal:"/v1/ai/chat/personal",list_chats:"/v1/ai/chat/list",chat_tool_result:"/v1/ai/chat/tool-result",chat_stop:"/v1/ai/chat/stop",ask:"/v1/ai/ask",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"},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",request_start:"/v1/jobs/request_start",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_results_stats:"/v1/jobs/results_stats",post_usage:"/v1/jobs/post_usage",get_status:"/v1/jobs/status",get_org:"/v1/jobs/org",query:"/v1/jobs/query",request_job_that_needs_stats:"/v1/jobs/job_needs_stats"},worker:{ping:"/v1/worker/ping",get_available_count:"/v1/worker/get_available_count",post_available_info:"/v1/worker/post_available_info",get_available_info:"/v1/worker/get_available_info"},local_projects:{get:{user:"/v1/local_projects/user",by_id:"/v1/local_projects/"},post:"/v1/local_projects"}};function B(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 D={credentials:"omit"},M=function(e,t){try{var n=e.baseUrl+I.account.get_licenses,r=k({},t),o=k({},r,B(e));return Promise.resolve(fetch(n,k({},D,{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 q(e,t){return function(){return e.apply(t,arguments)}}const{toString:J}=Object.prototype,{getPrototypeOf:H}=Object,G=(V=Object.create(null),e=>{const t=J.call(e);return V[t]||(V[t]=t.slice(8,-1).toLowerCase())});var V;const K=e=>(e=e.toLowerCase(),t=>G(t)===e),$=e=>t=>typeof t===e,{isArray:X}=Array,Y=$("undefined"),Z=K("ArrayBuffer"),Q=$("string"),ee=$("function"),te=$("number"),ne=e=>null!==e&&"object"==typeof e,re=e=>{if("object"!==G(e))return!1;const t=H(e);return!(null!==t&&t!==Object.prototype&&null!==Object.getPrototypeOf(t)||Symbol.toStringTag in e||Symbol.iterator in e)},oe=K("Date"),ie=K("File"),se=K("Blob"),ae=K("FileList"),ue=K("URLSearchParams"),[le,ce,fe,de]=["ReadableStream","Request","Response","Headers"].map(K);function he(e,t,{allOwnKeys:n=!1}={}){if(null==e)return;let r,o;if("object"!=typeof e&&(e=[e]),X(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{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 pe(e,t){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 me="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,ge=e=>!Y(e)&&e!==me,ve=(ye="undefined"!=typeof Uint8Array&&H(Uint8Array),e=>ye&&e instanceof ye);var ye;const be=K("HTMLFormElement"),we=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),_e=K("RegExp"),Pe=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};he(n,(n,o)=>{let i;!1!==(i=t(n,o,e))&&(r[o]=i||n)}),Object.defineProperties(e,r)},xe="abcdefghijklmnopqrstuvwxyz",Se="0123456789",Ee={DIGIT:Se,ALPHA:xe,ALPHA_DIGIT:xe+xe.toUpperCase()+Se},je=K("AsyncFunction"),Te=(ke="function"==typeof setImmediate,We=ee(me.postMessage),ke?setImmediate:We?(Oe=`axios@${Math.random()}`,Re=[],me.addEventListener("message",({source:e,data:t})=>{e===me&&t===Oe&&Re.length&&Re.shift()()},!1),e=>{Re.push(e),me.postMessage(Oe,"*")}):e=>setTimeout(e));var ke,We,Oe,Re;const Ue="undefined"!=typeof queueMicrotask?queueMicrotask.bind(me):"undefined"!=typeof process&&process.nextTick||Te;var Ae={isArray:X,isArrayBuffer:Z,isBuffer:function(e){return null!==e&&!Y(e)&&null!==e.constructor&&!Y(e.constructor)&&ee(e.constructor.isBuffer)&&e.constructor.isBuffer(e)},isFormData:e=>{let t;return e&&("function"==typeof FormData&&e instanceof FormData||ee(e.append)&&("formdata"===(t=G(e))||"object"===t&&ee(e.toString)&&"[object FormData]"===e.toString()))},isArrayBufferView:function(e){let t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&Z(e.buffer),t},isString:Q,isNumber:te,isBoolean:e=>!0===e||!1===e,isObject:ne,isPlainObject:re,isReadableStream:le,isRequest:ce,isResponse:fe,isHeaders:de,isUndefined:Y,isDate:oe,isFile:ie,isBlob:se,isRegExp:_e,isFunction:ee,isStream:e=>ne(e)&&ee(e.pipe),isURLSearchParams:ue,isTypedArray:ve,isFileList:ae,forEach:he,merge:function e(){const{caseless:t}=ge(this)&&this||{},n={},r=(r,o)=>{const i=t&&pe(n,o)||o;n[i]=re(n[i])&&re(r)?e(n[i],r):re(r)?e({},r):X(r)?r.slice():r};for(let e=0,t=arguments.length;e<t;e++)arguments[e]&&he(arguments[e],r);return n},extend:(e,t,n,{allOwnKeys:r}={})=>(he(t,(t,r)=>{e[r]=n&&ee(t)?q(t,n):t},{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),e.prototype.constructor=e,Object.defineProperty(e,"super",{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&&H(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},kindOf:G,kindOfTest:K,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(X(e))return e;let t=e.length;if(!te(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},forEachEntry:(e,t)=>{const n=(e&&e[Symbol.iterator]).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:be,hasOwnProperty:we,hasOwnProp:we,reduceDescriptors:Pe,freezeMethods:e=>{Pe(e,(t,n)=>{if(ee(e)&&-1!==["arguments","caller","callee"].indexOf(n))return!1;ee(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 X(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:pe,global:me,isContextDefined:ge,ALPHABET:Ee,generateString:(e=16,t=Ee.ALPHA_DIGIT)=>{let n="";const{length:r}=t;for(;e--;)n+=t[Math.random()*r|0];return n},isSpecCompliantForm:function(e){return!!(e&&ee(e.append)&&"FormData"===e[Symbol.toStringTag]&&e[Symbol.iterator])},toJSONObject:e=>{const t=new Array(10),n=(e,r)=>{if(ne(e)){if(t.indexOf(e)>=0)return;if(!("toJSON"in e)){t[r]=e;const o=X(e)?[]:{};return he(e,(e,t)=>{const i=n(e,r+1);!Y(i)&&(o[t]=i)}),t[r]=void 0,o}}return e};return n(e,0)},isAsyncFn:je,isThenable:e=>e&&(ne(e)||ee(e))&&ee(e.then)&&ee(e.catch),setImmediate:Te,asap:Ue};function ze(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o)}Ae.inherits(ze,Error,{toJSON:function(){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:Ae.toJSONObject(this.config),code:this.code,status:this.response&&this.response.status?this.response.status:null}}});const Ce=ze.prototype,Le={};function Ne(e){return Ae.isPlainObject(e)||Ae.isArray(e)}function Fe(e){return Ae.endsWith(e,"[]")?e.slice(0,-2):e}function Ie(e,t,n){return e?e.concat(t).map(function(e,t){return e=Fe(e),!n&&t?"["+e+"]":e}).join(n?".":""):t}["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{Le[e]={value:e}}),Object.defineProperties(ze,Le),Object.defineProperty(Ce,"isAxiosError",{value:!0}),ze.from=(e,t,n,r,o,i)=>{const s=Object.create(Ce);return Ae.toFlatObject(e,s,function(e){return e!==Error.prototype},e=>"isAxiosError"!==e),ze.call(s,e.message,t,n,r,o),s.cause=e,s.name=e.name,i&&Object.assign(s,i),s};const Be=Ae.toFlatObject(Ae,{},null,function(e){return/^is[A-Z]/.test(e)});function De(e,t,n){if(!Ae.isObject(e))throw new TypeError("target must be an object");t=t||new FormData;const r=(n=Ae.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(e,t){return!Ae.isUndefined(t[e])})).metaTokens,o=n.visitor||l,i=n.dots,s=n.indexes,a=(n.Blob||"undefined"!=typeof Blob&&Blob)&&Ae.isSpecCompliantForm(t);if(!Ae.isFunction(o))throw new TypeError("visitor must be a function");function u(e){if(null===e)return"";if(Ae.isDate(e))return e.toISOString();if(!a&&Ae.isBlob(e))throw new ze("Blob is not supported. Use a Buffer instead.");return Ae.isArrayBuffer(e)||Ae.isTypedArray(e)?a&&"function"==typeof Blob?new Blob([e]):Buffer.from(e):e}function l(e,n,o){let a=e;if(e&&!o&&"object"==typeof e)if(Ae.endsWith(n,"{}"))n=r?n:n.slice(0,-2),e=JSON.stringify(e);else if(Ae.isArray(e)&&function(e){return Ae.isArray(e)&&!e.some(Ne)}(e)||(Ae.isFileList(e)||Ae.endsWith(n,"[]"))&&(a=Ae.toArray(e)))return n=Fe(n),a.forEach(function(e,r){!Ae.isUndefined(e)&&null!==e&&t.append(!0===s?Ie([n],r,i):null===s?n:n+"[]",u(e))}),!1;return!!Ne(e)||(t.append(Ie(o,n,i),u(e)),!1)}const c=[],f=Object.assign(Be,{defaultVisitor:l,convertValue:u,isVisitable:Ne});if(!Ae.isObject(e))throw new TypeError("data must be an object");return function e(n,r){if(!Ae.isUndefined(n)){if(-1!==c.indexOf(n))throw Error("Circular reference detected in "+r.join("."));c.push(n),Ae.forEach(n,function(n,i){!0===(!(Ae.isUndefined(n)||null===n)&&o.call(t,n,Ae.isString(i)?i.trim():i,r,f))&&e(n,r?r.concat(i):[i])}),c.pop()}}(e),t}function Me(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(e){return t[e]})}function qe(e,t){this._pairs=[],e&&De(e,this,t)}const Je=qe.prototype;function He(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function Ge(e,t,n){if(!t)return e;const r=n&&n.encode||He,o=n&&n.serialize;let i;if(i=o?o(t,n):Ae.isURLSearchParams(t)?t.toString():new qe(t,n).toString(r),i){const t=e.indexOf("#");-1!==t&&(e=e.slice(0,t)),e+=(-1===e.indexOf("?")?"?":"&")+i}return e}Je.append=function(e,t){this._pairs.push([e,t])},Je.toString=function(e){const t=e?function(t){return e.call(this,t,Me)}:Me;return this._pairs.map(function(e){return t(e[0])+"="+t(e[1])},"").join("&")};var Ve=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){Ae.forEach(this.handlers,function(t){null!==t&&e(t)})}},Ke={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},$e={isBrowser:!0,classes:{URLSearchParams:"undefined"!=typeof URLSearchParams?URLSearchParams:qe,FormData:"undefined"!=typeof FormData?FormData:null,Blob:"undefined"!=typeof Blob?Blob:null},protocols:["http","https","file","blob","url","data"]};const Xe="undefined"!=typeof window&&"undefined"!=typeof document,Ye=(Ze="undefined"!=typeof navigator&&navigator.product,Xe&&["ReactNative","NativeScript","NS"].indexOf(Ze)<0);var Ze,Qe={__proto__:null,hasBrowserEnv:Xe,hasStandardBrowserWebWorkerEnv:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope&&"function"==typeof self.importScripts,hasStandardBrowserEnv:Ye,origin:Xe&&window.location.href||"http://localhost",...$e};function et(e){function t(e,n,r,o){let i=e[o++];if("__proto__"===i)return!0;const s=Number.isFinite(+i),a=o>=e.length;return i=!i&&Ae.isArray(r)?r.length:i,a?(r[i]=Ae.hasOwnProp(r,i)?[r[i],n]:n,!s):(r[i]&&Ae.isObject(r[i])||(r[i]=[]),t(e,n,r[i],o)&&Ae.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(Ae.isFormData(e)&&Ae.isFunction(e.entries)){const n={};return Ae.forEachEntry(e,(e,r)=>{t(function(e){return Ae.matchAll(/\w+|\[(\w*)]/g,e).map(e=>"[]"===e[0]?"":e[1]||e[0])}(e),r,n,0)}),n}return null}const tt={transitional:Ke,adapter:["xhr","http","fetch"],transformRequest:[function(e,t){const n=t.getContentType()||"",r=n.indexOf("application/json")>-1,o=Ae.isObject(e);if(o&&Ae.isHTMLForm(e)&&(e=new FormData(e)),Ae.isFormData(e))return r?JSON.stringify(et(e)):e;if(Ae.isArrayBuffer(e)||Ae.isBuffer(e)||Ae.isStream(e)||Ae.isFile(e)||Ae.isBlob(e)||Ae.isReadableStream(e))return e;if(Ae.isArrayBufferView(e))return e.buffer;if(Ae.isURLSearchParams(e))return t.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let i;if(o){if(n.indexOf("application/x-www-form-urlencoded")>-1)return function(e,t){return De(e,new Qe.classes.URLSearchParams,Object.assign({visitor:function(e,t,n,r){return Qe.isNode&&Ae.isBuffer(e)?(this.append(t,e.toString("base64")),!1):r.defaultVisitor.apply(this,arguments)}},t))}(e,this.formSerializer).toString();if((i=Ae.isFileList(e))||n.indexOf("multipart/form-data")>-1){const t=this.env&&this.env.FormData;return De(i?{"files[]":e}:e,t&&new t,this.formSerializer)}}return o||r?(t.setContentType("application/json",!1),function(e,t,n){if(Ae.isString(e))try{return(0,JSON.parse)(e),Ae.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(0,JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){const t=this.transitional||tt.transitional,n=t&&t.forcedJSONParsing,r="json"===this.responseType;if(Ae.isResponse(e)||Ae.isReadableStream(e))return e;if(e&&Ae.isString(e)&&(n&&!this.responseType||r)){const n=!(t&&t.silentJSONParsing)&&r;try{return JSON.parse(e)}catch(e){if(n){if("SyntaxError"===e.name)throw ze.from(e,ze.ERR_BAD_RESPONSE,this,null,this.response);throw e}}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Qe.classes.FormData,Blob:Qe.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};Ae.forEach(["delete","get","head","post","put","patch"],e=>{tt.headers[e]={}});var nt=tt;const rt=Ae.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"]),ot=Symbol("internals");function it(e){return e&&String(e).trim().toLowerCase()}function st(e){return!1===e||null==e?e:Ae.isArray(e)?e.map(st):String(e)}function at(e,t,n,r,o){return Ae.isFunction(r)?r.call(this,t,n):(o&&(t=n),Ae.isString(t)?Ae.isString(r)?-1!==t.indexOf(r):Ae.isRegExp(r)?r.test(t):void 0:void 0)}class ut{constructor(e){e&&this.set(e)}set(e,t,n){const r=this;function o(e,t,n){const o=it(t);if(!o)throw new Error("header name must be a non-empty string");const i=Ae.findKey(r,o);(!i||void 0===r[i]||!0===n||void 0===n&&!1!==r[i])&&(r[i||t]=st(e))}const i=(e,t)=>Ae.forEach(e,(e,n)=>o(e,n,t));if(Ae.isPlainObject(e)||e instanceof this.constructor)i(e,t);else if(Ae.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(),!n||t[n]&&rt[n]||("set-cookie"===n?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t})(e),t);else if(Ae.isHeaders(e))for(const[t,r]of e.entries())o(r,t,n);else null!=e&&o(t,e,n);return this}get(e,t){if(e=it(e)){const n=Ae.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(Ae.isFunction(t))return t.call(this,e,n);if(Ae.isRegExp(t))return t.exec(e);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,t){if(e=it(e)){const n=Ae.findKey(this,e);return!(!n||void 0===this[n]||t&&!at(0,this[n],n,t))}return!1}delete(e,t){const n=this;let r=!1;function o(e){if(e=it(e)){const o=Ae.findKey(n,e);!o||t&&!at(0,n[o],o,t)||(delete n[o],r=!0)}}return Ae.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&&!at(0,this[o],o,e,!0)||(delete this[o],r=!0)}return r}normalize(e){const t=this,n={};return Ae.forEach(this,(r,o)=>{const i=Ae.findKey(n,o);if(i)return t[i]=st(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]=st(r),n[s]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const t=Object.create(null);return Ae.forEach(this,(n,r)=>{null!=n&&!1!==n&&(t[r]=e&&Ae.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")}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...t){const n=new this(e);return t.forEach(e=>n.set(e)),n}static accessor(e){const t=(this[ot]=this[ot]={accessors:{}}).accessors,n=this.prototype;function r(e){const r=it(e);t[r]||(function(e,t){const n=Ae.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(e,n,o){return this[r].call(this,t,e,n,o)},configurable:!0})})}(n,e),t[r]=!0)}return Ae.isArray(e)?e.forEach(r):r(e),this}}ut.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),Ae.reduceDescriptors(ut.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(e){this[n]=e}}}),Ae.freezeMethods(ut);var lt=ut;function ct(e,t){const n=this||nt,r=t||n,o=lt.from(r.headers);let i=r.data;return Ae.forEach(e,function(e){i=e.call(n,i,o.normalize(),t?t.status:void 0)}),o.normalize(),i}function ft(e){return!(!e||!e.__CANCEL__)}function dt(e,t,n){ze.call(this,null==e?"canceled":e,ze.ERR_CANCELED,t,n),this.name="CanceledError"}function ht(e,t,n){const r=n.config.validateStatus;n.status&&r&&!r(n.status)?t(new ze("Request failed with status code "+n.status,[ze.ERR_BAD_REQUEST,ze.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n)):e(n)}Ae.inherits(dt,ze,{__CANCEL__:!0});const pt=(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(e,t){let n,r,o=0,i=1e3/t;const s=(t,i=Date.now())=>{o=i,n=null,r&&(clearTimeout(r),r=null),e.apply(null,t)};return[(...e)=>{const t=Date.now(),a=t-o;a>=i?s(e,t):(n=e,r||(r=setTimeout(()=>{r=null,s(n)},i-a)))},()=>n&&s(n)]}(n=>{const i=n.loaded,s=n.lengthComputable?n.total:void 0,a=i-r,u=o(a);r=i,e({loaded:i,total:s,progress:s?i/s:void 0,bytes:a,rate:u||void 0,estimated:u&&s&&i<=s?(s-i)/u:void 0,event:n,lengthComputable:null!=s,[t?"download":"upload"]:!0})},n)},mt=(e,t)=>{const n=null!=e;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},gt=e=>(...t)=>Ae.asap(()=>e(...t));var vt=Qe.hasStandardBrowserEnv?function(){const e=/(msie|trident)/i.test(navigator.userAgent),t=document.createElement("a");let n;function r(n){let r=n;return e&&(t.setAttribute("href",r),r=t.href),t.setAttribute("href",r),{href:t.href,protocol:t.protocol?t.protocol.replace(/:$/,""):"",host:t.host,search:t.search?t.search.replace(/^\?/,""):"",hash:t.hash?t.hash.replace(/^#/,""):"",hostname:t.hostname,port:t.port,pathname:"/"===t.pathname.charAt(0)?t.pathname:"/"+t.pathname}}return n=r(window.location.href),function(e){const t=Ae.isString(e)?r(e):e;return t.protocol===n.protocol&&t.host===n.host}}():function(){return!0},yt=Qe.hasStandardBrowserEnv?{write(e,t,n,r,o,i){const s=[e+"="+encodeURIComponent(t)];Ae.isNumber(n)&&s.push("expires="+new Date(n).toGMTString()),Ae.isString(r)&&s.push("path="+r),Ae.isString(o)&&s.push("domain="+o),!0===i&&s.push("secure"),document.cookie=s.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read:()=>null,remove(){}};function bt(e,t){return e&&!/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)?function(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t}const wt=e=>e instanceof lt?{...e}:e;function _t(e,t){t=t||{};const n={};function r(e,t,n){return Ae.isPlainObject(e)&&Ae.isPlainObject(t)?Ae.merge.call({caseless:n},e,t):Ae.isPlainObject(t)?Ae.merge({},t):Ae.isArray(t)?t.slice():t}function o(e,t,n){return Ae.isUndefined(t)?Ae.isUndefined(e)?void 0:r(void 0,e,n):r(e,t,n)}function i(e,t){if(!Ae.isUndefined(t))return r(void 0,t)}function s(e,t){return Ae.isUndefined(t)?Ae.isUndefined(e)?void 0:r(void 0,e):r(void 0,t)}function a(n,o,i){return i in t?r(n,o):i in e?r(void 0,n):void 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,responseEncoding:s,validateStatus:a,headers:(e,t)=>o(wt(e),wt(t),!0)};return Ae.forEach(Object.keys(Object.assign({},e,t)),function(r){const i=u[r]||o,s=i(e[r],t[r],r);Ae.isUndefined(s)&&i!==a||(n[r]=s)}),n}var Pt=e=>{const t=_t({},e);let n,{data:r,withXSRFToken:o,xsrfHeaderName:i,xsrfCookieName:s,headers:a,auth:u}=t;if(t.headers=a=lt.from(a),t.url=Ge(bt(t.baseURL,t.url),e.params,e.paramsSerializer),u&&a.set("Authorization","Basic "+btoa((u.username||"")+":"+(u.password?unescape(encodeURIComponent(u.password)):""))),Ae.isFormData(r))if(Qe.hasStandardBrowserEnv||Qe.hasStandardBrowserWebWorkerEnv)a.setContentType(void 0);else if(!1!==(n=a.getContentType())){const[e,...t]=n?n.split(";").map(e=>e.trim()).filter(Boolean):[];a.setContentType([e||"multipart/form-data",...t].join("; "))}if(Qe.hasStandardBrowserEnv&&(o&&Ae.isFunction(o)&&(o=o(t)),o||!1!==o&&vt(t.url))){const e=i&&s&&yt.read(s);e&&a.set(i,e)}return t},xt="undefined"!=typeof XMLHttpRequest&&function(e){return new Promise(function(t,n){const r=Pt(e);let o=r.data;const i=lt.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 g(){if(!m)return;const r=lt.from("getAllResponseHeaders"in m&&m.getAllResponseHeaders());ht(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=g:m.onreadystatechange=function(){m&&4===m.readyState&&(0!==m.status||m.responseURL&&0===m.responseURL.indexOf("file:"))&&setTimeout(g)},m.onabort=function(){m&&(n(new ze("Request aborted",ze.ECONNABORTED,e,m)),m=null)},m.onerror=function(){n(new ze("Network Error",ze.ERR_NETWORK,e,m)),m=null},m.ontimeout=function(){let t=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";r.timeoutErrorMessage&&(t=r.timeoutErrorMessage),n(new ze(t,(r.transitional||Ke).clarifyTimeoutError?ze.ETIMEDOUT:ze.ECONNABORTED,e,m)),m=null},void 0===o&&i.setContentType(null),"setRequestHeader"in m&&Ae.forEach(i.toJSON(),function(e,t){m.setRequestHeader(t,e)}),Ae.isUndefined(r.withCredentials)||(m.withCredentials=!!r.withCredentials),f&&"json"!==f&&(m.responseType=r.responseType),h&&([u,c]=pt(h,!0),m.addEventListener("progress",u)),d&&m.upload&&([a,l]=pt(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(),m=null)},r.cancelToken&&r.cancelToken.subscribe(s),r.signal&&(r.signal.aborted?s():r.signal.addEventListener("abort",s)));const v=function(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}(r.url);v&&-1===Qe.protocols.indexOf(v)?n(new ze("Unsupported protocol "+v+":",ze.ERR_BAD_REQUEST,e)):m.send(o||null)})},St=(e,t)=>{let n,r=new AbortController;const o=function(e){if(!n){n=!0,s();const t=e instanceof Error?e:this.reason;r.abort(t instanceof ze?t:new dt(t instanceof Error?t.message:t))}};let i=t&&setTimeout(()=>{o(new ze(`timeout ${t} of ms exceeded`,ze.ETIMEDOUT))},t);const s=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(e=>{e&&(e.removeEventListener?e.removeEventListener("abort",o):e.unsubscribe(o))}),e=null)};e.forEach(e=>e&&e.addEventListener&&e.addEventListener("abort",o));const{signal:a}=r;return a.unsubscribe=s,[a,()=>{i&&clearTimeout(i),i=null}]};const Et=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},jt=(e,t,n,r,o)=>{const i=async function*(e,t,n){for await(const r of e)yield*Et(ArrayBuffer.isView(r)?r:await n(String(r)),t)}(e,t,o);let s,a=0,u=e=>{s||(s=!0,r&&r(e))};return new ReadableStream({async pull(e){try{const{done:t,value:r}=await i.next();if(t)return u(),void e.close();if(n){let e=a+=r.byteLength;n(e)}e.enqueue(new Uint8Array(r))}catch(e){throw u(e),e}},cancel:e=>(u(e),i.return())},{highWaterMark:2})},Tt="function"==typeof fetch&&"function"==typeof Request&&"function"==typeof Response,kt=Tt&&"function"==typeof ReadableStream,Wt=Tt&&("function"==typeof TextEncoder?(Ot=new TextEncoder,e=>Ot.encode(e)):async e=>new Uint8Array(await new Response(e).arrayBuffer()));var Ot;const Rt=(e,...t)=>{try{return!!e(...t)}catch(e){return!1}},Ut=kt&&Rt(()=>{let e=!1;const t=new Request(Qe.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),At=kt&&Rt(()=>Ae.isReadableStream(new Response("").body)),zt={stream:At&&(e=>e.body)};var Ct;Tt&&(Ct=new Response,["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!zt[e]&&(zt[e]=Ae.isFunction(Ct[e])?t=>t[e]():(t,n)=>{throw new ze(`Response type '${e}' is not supported`,ze.ERR_NOT_SUPPORT,n)})}));const Lt={http:null,xhr:xt,fetch:Tt&&(async e=>{let{url:t,method:n,data:r,signal:o,cancelToken:i,timeout:s,onDownloadProgress:a,onUploadProgress:u,responseType:l,headers:c,withCredentials:f="same-origin",fetchOptions:d}=Pt(e);l=l?(l+"").toLowerCase():"text";let h,p,[m,g]=o||i||s?St([o,i],s):[];const v=()=>{!h&&setTimeout(()=>{m&&m.unsubscribe()}),h=!0};let y;try{if(u&&Ut&&"get"!==n&&"head"!==n&&0!==(y=await(async(e,t)=>{const n=Ae.toFiniteNumber(e.getContentLength());return null==n?(async e=>null==e?0:Ae.isBlob(e)?e.size:Ae.isSpecCompliantForm(e)?(await new Request(e).arrayBuffer()).byteLength:Ae.isArrayBufferView(e)||Ae.isArrayBuffer(e)?e.byteLength:(Ae.isURLSearchParams(e)&&(e+=""),Ae.isString(e)?(await Wt(e)).byteLength:void 0))(t):n})(c,r))){let e,n=new Request(t,{method:"POST",body:r,duplex:"half"});if(Ae.isFormData(r)&&(e=n.headers.get("content-type"))&&c.setContentType(e),n.body){const[e,t]=mt(y,pt(gt(u)));r=jt(n.body,65536,e,t,Wt)}}Ae.isString(f)||(f=f?"include":"omit"),p=new Request(t,{...d,signal:m,method:n.toUpperCase(),headers:c.normalize().toJSON(),body:r,duplex:"half",credentials:f});let o=await fetch(p);const i=At&&("stream"===l||"response"===l);if(At&&(a||i)){const e={};["status","statusText","headers"].forEach(t=>{e[t]=o[t]});const t=Ae.toFiniteNumber(o.headers.get("content-length")),[n,r]=a&&mt(t,pt(gt(a),!0))||[];o=new Response(jt(o.body,65536,n,()=>{r&&r(),i&&v()},Wt),e)}l=l||"text";let s=await zt[Ae.findKey(zt,l)||"text"](o,e);return!i&&v(),g&&g(),await new Promise((t,n)=>{ht(t,n,{data:s,headers:lt.from(o.headers),status:o.status,statusText:o.statusText,config:e,request:p})})}catch(t){if(v(),t&&"TypeError"===t.name&&/fetch/i.test(t.message))throw Object.assign(new ze("Network Error",ze.ERR_NETWORK,e,p),{cause:t.cause||t});throw ze.from(t,t&&t.code,e,p)}})};Ae.forEach(Lt,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch(e){}Object.defineProperty(e,"adapterName",{value:t})}});const Nt=e=>`- ${e}`,Ft=e=>Ae.isFunction(e)||null===e||!1===e;var It=e=>{e=Ae.isArray(e)?e:[e];const{length:t}=e;let n,r;const o={};for(let i=0;i<t;i++){let t;if(n=e[i],r=n,!Ft(n)&&(r=Lt[(t=String(n)).toLowerCase()],void 0===r))throw new ze(`Unknown adapter '${t}'`);if(r)break;o[t||"#"+i]=r}if(!r){const e=Object.entries(o).map(([e,t])=>`adapter ${e} `+(!1===t?"is not supported by the environment":"is not available in the build"));throw new ze("There is no suitable adapter to dispatch the request "+(t?e.length>1?"since :\n"+e.map(Nt).join("\n"):" "+Nt(e[0]):"as no adapter specified"),"ERR_NOT_SUPPORT")}return r};function Bt(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dt(null,e)}function Dt(e){return Bt(e),e.headers=lt.from(e.headers),e.data=ct.call(e,e.transformRequest),-1!==["post","put","patch"].indexOf(e.method)&&e.headers.setContentType("application/x-www-form-urlencoded",!1),It(e.adapter||nt.adapter)(e).then(function(t){return Bt(e),t.data=ct.call(e,e.transformResponse,t),t.headers=lt.from(t.headers),t},function(t){return ft(t)||(Bt(e),t&&t.response&&(t.response.data=ct.call(e,e.transformResponse,t.response),t.response.headers=lt.from(t.response.headers))),Promise.reject(t)})}const Mt={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Mt[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});const qt={};Mt.transitional=function(e,t,n){function r(e,t){return"[Axios v1.7.4] Transitional option '"+e+"'"+t+(n?". "+n:"")}return(n,o,i)=>{if(!1===e)throw new ze(r(o," has been removed"+(t?" in "+t:"")),ze.ERR_DEPRECATED);return t&&!qt[o]&&(qt[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)}};var Jt={assertOptions:function(e,t,n){if("object"!=typeof e)throw new ze("options must be an object",ze.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const i=r[o],s=t[i];if(s){const t=e[i],n=void 0===t||s(t,i,e);if(!0!==n)throw new ze("option "+i+" must be "+n,ze.ERR_BAD_OPTION_VALUE)}else if(!0!==n)throw new ze("Unknown option "+i,ze.ERR_BAD_OPTION)}},validators:Mt};const Ht=Jt.validators;class Gt{constructor(e){this.defaults=e,this.interceptors={request:new Ve,response:new Ve}}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=t.stack?t.stack.replace(/^.+\n/,""):"";try{e.stack?n&&!String(e.stack).endsWith(n.replace(/^.+\n.+\n/,""))&&(e.stack+="\n"+n):e.stack=n}catch(e){}}throw e}}_request(e,t){"string"==typeof e?(t=t||{}).url=e:t=e||{},t=_t(this.defaults,t);const{transitional:n,paramsSerializer:r,headers:o}=t;void 0!==n&&Jt.assertOptions(n,{silentJSONParsing:Ht.transitional(Ht.boolean),forcedJSONParsing:Ht.transitional(Ht.boolean),clarifyTimeoutError:Ht.transitional(Ht.boolean)},!1),null!=r&&(Ae.isFunction(r)?t.paramsSerializer={serialize:r}:Jt.assertOptions(r,{encode:Ht.function,serialize:Ht.function},!0)),t.method=(t.method||this.defaults.method||"get").toLowerCase();let i=o&&Ae.merge(o.common,o[t.method]);o&&Ae.forEach(["delete","get","head","post","put","patch","common"],e=>{delete o[e]}),t.headers=lt.concat(i,o);const s=[];let a=!0;this.interceptors.request.forEach(function(e){"function"==typeof e.runWhen&&!1===e.runWhen(t)||(a=a&&e.synchronous,s.unshift(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=[Dt.bind(this),void 0];for(e.unshift.apply(e,s),e.push.apply(e,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=0;f<c;){const e=s[f++],t=s[f++];try{d=e(d)}catch(e){t.call(this,e);break}}try{l=Dt.call(this,d)}catch(e){return Promise.reject(e)}for(f=0,c=u.length;f<c;)l=l.then(u[f++],u[f++]);return l}getUri(e){return Ge(bt((e=_t(this.defaults,e)).baseURL,e.url),e.params,e.paramsSerializer)}}Ae.forEach(["delete","get","head","options"],function(e){Gt.prototype[e]=function(t,n){return this.request(_t(n||{},{method:e,url:t,data:(n||{}).data}))}}),Ae.forEach(["post","put","patch"],function(e){function t(t){return function(n,r,o){return this.request(_t(o||{},{method:e,headers:t?{"Content-Type":"multipart/form-data"}:{},url:n,data:r}))}}Gt.prototype[e]=t(),Gt.prototype[e+"Form"]=t(!0)});var Vt=Gt;class Kt{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)}static source(){let e;return{token:new Kt(function(t){e=t}),cancel:e}}}var $t=Kt;const Xt={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};Object.entries(Xt).forEach(([e,t])=>{Xt[t]=e});var Yt=Xt;const Zt=function e(t){const n=new Vt(t),r=q(Vt.prototype.request,n);return Ae.extend(r,Vt.prototype,n,{allOwnKeys:!0}),Ae.extend(r,n,null,{allOwnKeys:!0}),r.create=function(n){return e(_t(t,n))},r}(nt);Zt.Axios=Vt,Zt.CanceledError=dt,Zt.CancelToken=$t,Zt.isCancel=ft,Zt.VERSION="1.7.4",Zt.toFormData=De,Zt.AxiosError=ze,Zt.Cancel=Zt.CanceledError,Zt.all=function(e){return Promise.all(e)},Zt.spread=function(e){return function(t){return e.apply(null,t)}},Zt.isAxiosError=function(e){return Ae.isObject(e)&&!0===e.isAxiosError},Zt.mergeConfig=_t,Zt.AxiosHeaders=lt,Zt.formToJSON=e=>et(Ae.isHTMLForm(e)?new FormData(e):e),Zt.getAdapter=It,Zt.HttpStatusCode=Yt,Zt.default=Zt;var Qt=Zt;const{CanceledError:en}=Qt;var tn=function(e,t){try{var n=t.baseUrl+I.jobs.post_update,r=k({},B(t),{job_id:e.identifier,status:e.status});return Promise.resolve(fetch(n,k({},D,{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 nn(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function rn(e,t,n){if(!e.s){if(n instanceof on){if(!n.s)return void(n.o=rn.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(rn.bind(null,e,t),rn.bind(null,e,2));e.s=t,e.v=n;var r=e.o;r&&r(e)}}var on=/*#__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{rn(r,1,i(this.v))}catch(e){rn(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?rn(r,1,t?t(o):o):n?rn(r,1,n(o)):rn(r,2,o)}catch(e){rn(r,2,e)}},r},e}();function sn(e){return e instanceof on&&1&e.s}function an(e,t,n){for(var r;;){var o=e();if(sn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!sn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!sn(s)){r=2;break}}}var a=new on,u=rn.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&&!sn(s))return void s.then(f).then(void 0,u);if(!(o=e())||sn(o)&&!o.v)return void rn(a,1,i);if(o.then)return void o.then(c).then(void 0,u);sn(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):rn(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):rn(a,1,i)}}var un,ln,cn=16777216,fn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},dn={__proto__:null,default:{}},hn=(un=function(t){!function(){var n="input is invalid type",r="object"==typeof window,o=r?window:{};o.JS_MD5_NO_WINDOW&&(r=!1);var i=!r&&"object"==typeof self,s=!o.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;s?o=fn:i&&(o=self);var a,u=!o.JS_MD5_NO_COMMON_JS&&t.exports,l=!o.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,c="0123456789abcdef".split(""),f=[128,32768,8388608,-2147483648],d=[0,8,16,24],h=["hex","array","digest","buffer","arrayBuffer","base64"],p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),m=[];if(l){var g=new ArrayBuffer(68);a=new Uint8Array(g),m=new Uint32Array(g)}var v=Array.isArray;!o.JS_MD5_NO_NODE_JS&&v||(v=function(e){return"[object Array]"===Object.prototype.toString.call(e)});var y=ArrayBuffer.isView;!l||!o.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&y||(y=function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer});var b=function(e){var t=typeof e;if("string"===t)return[e,!0];if("object"!==t||null===e)throw new Error(n);if(l&&e.constructor===ArrayBuffer)return[new Uint8Array(e),!1];if(!v(e)&&!y(e))throw new Error(n);return[e,!1]},w=function(e){return function(t){return new P(!0).update(t)[e]()}},_=function(e){return function(t,n){return new x(t,!0).update(n)[e]()}};function P(e){if(e)m[0]=m[16]=m[1]=m[2]=m[3]=m[4]=m[5]=m[6]=m[7]=m[8]=m[9]=m[10]=m[11]=m[12]=m[13]=m[14]=m[15]=0,this.blocks=m,this.buffer8=a;else if(l){var t=new ArrayBuffer(68);this.buffer8=new Uint8Array(t),this.blocks=new Uint32Array(t)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}function x(e,t){var n,r=b(e);if(e=r[0],r[1]){var o,i=[],s=e.length,a=0;for(n=0;n<s;++n)(o=e.charCodeAt(n))<128?i[a++]=o:o<2048?(i[a++]=192|o>>>6,i[a++]=128|63&o):o<55296||o>=57344?(i[a++]=224|o>>>12,i[a++]=128|o>>>6&63,i[a++]=128|63&o):(o=65536+((1023&o)<<10|1023&e.charCodeAt(++n)),i[a++]=240|o>>>18,i[a++]=128|o>>>12&63,i[a++]=128|o>>>6&63,i[a++]=128|63&o);e=i}e.length>64&&(e=new P(!0).update(e).array());var u=[],l=[];for(n=0;n<64;++n){var c=e[n]||0;u[n]=92^c,l[n]=54^c}P.call(this,t),this.update(l),this.oKeyPad=u,this.inner=!0,this.sharedMemory=t}P.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");for(var t,n,r=b(e),o=r[1],i=0,s=(e=r[0]).length,a=this.blocks,u=this.buffer8;i<s;){if(this.hashed&&(this.hashed=!1,a[0]=a[16],a[16]=a[1]=a[2]=a[3]=a[4]=a[5]=a[6]=a[7]=a[8]=a[9]=a[10]=a[11]=a[12]=a[13]=a[14]=a[15]=0),o)if(l)for(n=this.start;i<s&&n<64;++i)(t=e.charCodeAt(i))<128?u[n++]=t:t<2048?(u[n++]=192|t>>>6,u[n++]=128|63&t):t<55296||t>=57344?(u[n++]=224|t>>>12,u[n++]=128|t>>>6&63,u[n++]=128|63&t):(t=65536+((1023&t)<<10|1023&e.charCodeAt(++i)),u[n++]=240|t>>>18,u[n++]=128|t>>>12&63,u[n++]=128|t>>>6&63,u[n++]=128|63&t);else for(n=this.start;i<s&&n<64;++i)(t=e.charCodeAt(i))<128?a[n>>>2]|=t<<d[3&n++]:t<2048?(a[n>>>2]|=(192|t>>>6)<<d[3&n++],a[n>>>2]|=(128|63&t)<<d[3&n++]):t<55296||t>=57344?(a[n>>>2]|=(224|t>>>12)<<d[3&n++],a[n>>>2]|=(128|t>>>6&63)<<d[3&n++],a[n>>>2]|=(128|63&t)<<d[3&n++]):(t=65536+((1023&t)<<10|1023&e.charCodeAt(++i)),a[n>>>2]|=(240|t>>>18)<<d[3&n++],a[n>>>2]|=(128|t>>>12&63)<<d[3&n++],a[n>>>2]|=(128|t>>>6&63)<<d[3&n++],a[n>>>2]|=(128|63&t)<<d[3&n++]);else if(l)for(n=this.start;i<s&&n<64;++i)u[n++]=e[i];else for(n=this.start;i<s&&n<64;++i)a[n>>>2]|=e[i]<<d[3&n++];this.lastByteIndex=n,this.bytes+=n-this.start,n>=64?(this.start=n-64,this.hash(),this.hashed=!0):this.start=n}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296|0,this.bytes=this.bytes%4294967296),this},P.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[t>>>2]|=f[3&t],t>=56&&(this.hashed||this.hash(),e[0]=e[16],e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.bytes<<3,e[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},P.prototype.hash=function(){var e,t,n,r,o,i,s=this.blocks;this.first?t=((t=((e=((e=s[0]-680876937)<<7|e>>>25)-271733879|0)^(n=((n=(-271733879^(r=((r=(-1732584194^2004318071&e)+s[1]-117830708)<<12|r>>>20)+e|0)&(-271733879^e))+s[2]-1126478375)<<17|n>>>15)+r|0)&(r^e))+s[3]-1316259209)<<22|t>>>10)+n|0:(e=this.h0,t=this.h1,t=((t+=((e=((e+=((r=this.h3)^t&((n=this.h2)^r))+s[0]-680876936)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[1]-389564586)<<12|r>>>20)+e|0)&(e^t))+s[2]+606105819)<<17|n>>>15)+r|0)&(r^e))+s[3]-1044525330)<<22|t>>>10)+n|0),t=((t+=((e=((e+=(r^t&(n^r))+s[4]-176418897)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[5]+1200080426)<<12|r>>>20)+e|0)&(e^t))+s[6]-1473231341)<<17|n>>>15)+r|0)&(r^e))+s[7]-45705983)<<22|t>>>10)+n|0,t=((t+=((e=((e+=(r^t&(n^r))+s[8]+1770035416)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[9]-1958414417)<<12|r>>>20)+e|0)&(e^t))+s[10]-42063)<<17|n>>>15)+r|0)&(r^e))+s[11]-1990404162)<<22|t>>>10)+n|0,t=((t+=((e=((e+=(r^t&(n^r))+s[12]+1804603682)<<7|e>>>25)+t|0)^(n=((n+=(t^(r=((r+=(n^e&(t^n))+s[13]-40341101)<<12|r>>>20)+e|0)&(e^t))+s[14]-1502002290)<<17|n>>>15)+r|0)&(r^e))+s[15]+1236535329)<<22|t>>>10)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[1]-165796510)<<5|e>>>27)+t|0)^t))+s[6]-1069501632)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[11]+643717713)<<14|n>>>18)+r|0)^r))+s[0]-373897302)<<20|t>>>12)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[5]-701558691)<<5|e>>>27)+t|0)^t))+s[10]+38016083)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[15]-660478335)<<14|n>>>18)+r|0)^r))+s[4]-405537848)<<20|t>>>12)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[9]+568446438)<<5|e>>>27)+t|0)^t))+s[14]-1019803690)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[3]-187363961)<<14|n>>>18)+r|0)^r))+s[8]+1163531501)<<20|t>>>12)+n|0,t=((t+=((r=((r+=(t^n&((e=((e+=(n^r&(t^n))+s[13]-1444681467)<<5|e>>>27)+t|0)^t))+s[2]-51403784)<<9|r>>>23)+e|0)^e&((n=((n+=(e^t&(r^e))+s[7]+1735328473)<<14|n>>>18)+r|0)^r))+s[12]-1926607734)<<20|t>>>12)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[5]-378558)<<4|e>>>28)+t|0))+s[8]-2022574463)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[11]+1839030562)<<16|n>>>16)+r|0))+s[14]-35309556)<<23|t>>>9)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[1]-1530992060)<<4|e>>>28)+t|0))+s[4]+1272893353)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[7]-155497632)<<16|n>>>16)+r|0))+s[10]-1094730640)<<23|t>>>9)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[13]+681279174)<<4|e>>>28)+t|0))+s[0]-358537222)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[3]-722521979)<<16|n>>>16)+r|0))+s[6]+76029189)<<23|t>>>9)+n|0,t=((t+=((i=(r=((r+=((o=t^n)^(e=((e+=(o^r)+s[9]-640364487)<<4|e>>>28)+t|0))+s[12]-421815835)<<11|r>>>21)+e|0)^e)^(n=((n+=(i^t)+s[15]+530742520)<<16|n>>>16)+r|0))+s[2]-995338651)<<23|t>>>9)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[0]-198630844)<<6|e>>>26)+t|0)|~n))+s[7]+1126891415)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[14]-1416354905)<<15|n>>>17)+r|0)|~e))+s[5]-57434055)<<21|t>>>11)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[12]+1700485571)<<6|e>>>26)+t|0)|~n))+s[3]-1894986606)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[10]-1051523)<<15|n>>>17)+r|0)|~e))+s[1]-2054922799)<<21|t>>>11)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[8]+1873313359)<<6|e>>>26)+t|0)|~n))+s[15]-30611744)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[6]-1560198380)<<15|n>>>17)+r|0)|~e))+s[13]+1309151649)<<21|t>>>11)+n|0,t=((t+=((r=((r+=(t^((e=((e+=(n^(t|~r))+s[4]-145523070)<<6|e>>>26)+t|0)|~n))+s[11]-1120210379)<<10|r>>>22)+e|0)^((n=((n+=(e^(r|~t))+s[2]+718787259)<<15|n>>>17)+r|0)|~e))+s[9]-343485551)<<21|t>>>11)+n|0,this.first?(this.h0=e+1732584193|0,this.h1=t-271733879|0,this.h2=n-1732584194|0,this.h3=r+271733878|0,this.first=!1):(this.h0=this.h0+e|0,this.h1=this.h1+t|0,this.h2=this.h2+n|0,this.h3=this.h3+r|0)},P.prototype.toString=P.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3;return c[e>>>4&15]+c[15&e]+c[e>>>12&15]+c[e>>>8&15]+c[e>>>20&15]+c[e>>>16&15]+c[e>>>28&15]+c[e>>>24&15]+c[t>>>4&15]+c[15&t]+c[t>>>12&15]+c[t>>>8&15]+c[t>>>20&15]+c[t>>>16&15]+c[t>>>28&15]+c[t>>>24&15]+c[n>>>4&15]+c[15&n]+c[n>>>12&15]+c[n>>>8&15]+c[n>>>20&15]+c[n>>>16&15]+c[n>>>28&15]+c[n>>>24&15]+c[r>>>4&15]+c[15&r]+c[r>>>12&15]+c[r>>>8&15]+c[r>>>20&15]+c[r>>>16&15]+c[r>>>28&15]+c[r>>>24&15]},P.prototype.array=P.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3;return[255&e,e>>>8&255,e>>>16&255,e>>>24&255,255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&n,n>>>8&255,n>>>16&255,n>>>24&255,255&r,r>>>8&255,r>>>16&255,r>>>24&255]},P.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(16),t=new Uint32Array(e);return t[0]=this.h0,t[1]=this.h1,t[2]=this.h2,t[3]=this.h3,e},P.prototype.buffer=P.prototype.arrayBuffer,P.prototype.base64=function(){for(var e,t,n,r="",o=this.array(),i=0;i<15;)e=o[i++],t=o[i++],n=o[i++],r+=p[e>>>2]+p[63&(e<<4|t>>>4)]+p[63&(t<<2|n>>>6)]+p[63&n];return r+(p[(e=o[i])>>>2]+p[e<<4&63]+"==")},(x.prototype=new P).finalize=function(){if(P.prototype.finalize.call(this),this.inner){this.inner=!1;var e=this.array();P.call(this,this.sharedMemory),this.update(this.oKeyPad),this.update(e),P.prototype.finalize.call(this)}};var S=function(){var t=w("hex");s&&(t=function(t){var r,i=dn,s=e.Buffer;return r=s.from&&!o.JS_MD5_NO_BUFFER_FROM?s.from:function(e){return new s(e)},function(e){if("string"==typeof e)return i.createHash("md5").update(e,"utf8").digest("hex");if(null==e)throw new Error(n);return e.constructor===ArrayBuffer&&(e=new Uint8Array(e)),v(e)||y(e)||e.constructor===s?i.createHash("md5").update(r(e)).digest("hex"):t(e)}}(t)),t.create=function(){return new P},t.update=function(e){return t.create().update(e)};for(var r=0;r<h.length;++r){var i=h[r];t[i]=w(i)}return t}();S.md5=S,S.md5.hmac=function(){var e=_("hex");e.create=function(e){return new x(e)},e.update=function(t,n){return e.create(t).update(n)};for(var t=0;t<h.length;++t){var n=h[t];e[n]=_(n)}return e}(),u?t.exports=S:o.md5=S}()},un(ln={exports:{}}),ln.exports);function pn(e,t=0){return yn(e,t,2).getUint16(0,!0)}function mn(e,t=0){return yn(e,t,4).getUint32(0,!0)}function gn(e,t=0,n=e.byteLength){const r=e.slice(t,t+n);return bn.decode(new Uint8Array(r))}function vn(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 yn(e,t,n){const r=e.slice(t,t+n);return new DataView(new Uint8Array(r).buffer)}const bn=new TextDecoder("utf8"),wn=[["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 _n(e){return e.flatMap(([e,t,n,r={},o=[]])=>[[e,t,n,r],...o])}function Pn(e,t){const n=pn(e,26),r=gn(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=mn(e,18),r=mn(e,22),o=pn(e,28);if(n===r){const r=gn(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 xn=function(e){return _n(e).map(([e,t,n,{offset:r=0}={}])=>n.length+r).reduce((e,t)=>t>e?t:e,0)}(wn);function Sn(e,t){for(const[n,r,o,{exact:i=!0,offset:s=0}={},a=[]]of t)if(vn(e,o,s)){if("zip"===n&&!i)return Pn(e.buffer,{ext:n,mime:r});if(!i&&a.length)for(const[t,n,r,{offset:o=0}={}]of a)if(vn(e,r,o))return{ext:t,mime:n};return{ext:n,mime:r}}}function En(e){var t=hn.md5.create();return t.update(e),t.base64()}function jn(e,t){void 0===t&&(t=void 0);var n=function(e,{extra:t=!1,hint:n}={}){const r=new Uint8Array(e.slice(0,xn));if(n){const e=function(e,{ext:t,mime:n}){return t||n?_n(e).filter(e=>e[0]===t||e[1]===n):[]}(wn,n);if(e.length>0){const t=Sn(r,e);if(void 0!==t)return t}}return Sn(r,wn)||(t?function(e){return function(e){try{const t=gn(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=Tn(t)),s}function Tn(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 kn(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 Wn(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))}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var On=function(e){try{return Promise.resolve(new Promise(function(t){return setTimeout(t,e)}))}catch(e){return Promise.reject(e)}},Rn=/*#__PURE__*/N(/^image_(\d+)_|^mesh_lod_(\d+)_/,{image_lod:1,mesh_lod:2});function Un(e,t,n){if(!e.s){if(n instanceof An){if(!n.s)return void(n.o=Un.bind(null,e,t));1&t&&(t=n.s),n=n.v}if(n&&n.then)return void n.then(Un.bind(null,e,t),Un.bind(null,e,2));e.s=t,e.v=n;const r=e.o;r&&r(e)}}var An=/*#__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{Un(r,1,i(this.v))}catch(e){Un(r,2,e)}return r}return this}return this.o=function(e){try{var o=e.v;1&e.s?Un(r,1,t?t(o):o):n?Un(r,1,n(o)):Un(r,2,o)}catch(e){Un(r,2,e)}},r},e}();function zn(e){return e instanceof An&&1&e.s}function Cn(e){return e.includes("\\u")?JSON.parse('"'+e+'"'):decodeURIComponent(e)}function Ln(e){for(var t,n=Infinity,r=[],o=T(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 Nn=/*#__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}();function Fn(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}function In(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)}function Bn(e,t,n){if(!e.s){if(n instanceof Dn){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)}}"undefined"==typeof Symbol||Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"));var Dn=/*#__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 Mn(e){return e instanceof Dn&&1&e.s}function qn(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(!Mn(a))return void a.then(s,o||(o=Bn.bind(null,r=new Dn,2)));a=a.v}r?Bn(r,1,a):r=a}catch(e){Bn(r||(r=new Dn),2,e)}}(),r}function Jn(e,t,n){for(var r;;){var o=e();if(Mn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!Mn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Mn(s)){r=2;break}}}var a=new Dn,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&&!Mn(s))return void s.then(f).then(void 0,u);if(!(o=e())||Mn(o)&&!o.v)return void Bn(a,1,i);if(o.then)return void o.then(c).then(void 0,u);Mn(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)}}var Hn=[];function Gn(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];l?t.push("S3 "+l+(c?": "+c:"")):u&&t.push(u.slice(0,200))}e.message&&t.push(String(e.message))}catch(e){}return 0===t.length&&e.message&&t.push(String(e.message)),t.length?t.join(" — "):"unknown upload error"}var Vn=12e4;function Kn(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 $n=["chat_url"];function Xn(e){return Yn.apply(this,arguments)}function Yn(){return Yn=z(/*#__PURE__*/U().mark(function e(t){var n,r,o,i,s,a,u,l,c,f;return U().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,j(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=T(a);case 16:if((l=u()).done){e.next=24;break}if(!(c=Zn(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=Zn(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]])})),Yn.apply(this,arguments)}function Zn(e){for(var t,n=null,r="",o=void 0,i=T(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"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":a={type:"error",message:decodeURIComponent(r)};break;case"stopped":a={type:"stopped"};break;case"tool_call":a=k({type:"tool_call"},JSON.parse(r));break;case"tool_result":a=k({type:"tool_result"},JSON.parse(r));break;case"elicitation":a=k({type:"elicitation"},JSON.parse(r));break;case"done":var u=JSON.parse(r),l=u.chat_url;a={type:"done",token_usage:R(u,$n)},l&&(a.chat_url=l);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 Qn(e,t){var n=B(e);return null!=t&&t.personal&&(n["x-needle-ai-chat"]="personal"),null!=t&&t.instanceId&&(n["x-needle-instance-id"]=t.instanceId),n}var er=function(e,t){try{var n=new URL(e.baseUrl+I.ai.chat),r=Qn(e,t);return r["Content-Type"]="application/json",Promise.resolve(fetch(n,k({},D,{method:"POST",headers:r,body:JSON.stringify({type:"new_message",slug:t.slug,message:t.message,stream:!1,source:t.source,full_url:t.full_url,pathname:t.pathname,context:t.context})}))).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 send chat message ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}},tr=function(e){try{var t=new URL(e.baseUrl+I.ai.list_chats),n=Qn(e);return Promise.resolve(fetch(t,k({},D,{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 nr(e,t){return t.stream?function(e,t){return rr.apply(this,arguments)}(e,t):er(e,t)}function rr(){return rr=z(/*#__PURE__*/U().mark(function e(t,n){var r,o,i,s;return U().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=new URL(t.baseUrl+I.ai.chat),(o=Qn(t,n))["Content-Type"]="application/json",i={type:"new_message",slug:n.slug,message:n.message,stream:!0,source:n.source,full_url:n.full_url,pathname:n.pathname,context:n.context},e.next=6,j(fetch(r,k({},D,{method:"POST",headers:o,body:JSON.stringify(i)})));case 6:if((s=e.sent).ok){e.next=12;break}return e.next=10,j(s.text());case 10:throw new Error("Failed to stream chat message ("+s.status+"): "+e.sent);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(x(S(Xn(s.body))),"t0",15);case 15:case"end":return e.stop()}},e)})),rr.apply(this,arguments)}var or=globalThis.crypto.randomUUID();function ir(e){if("string"!=typeof e||0===e.length)return null;try{return new URL(e).host}catch(e){return null}}function sr(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.onToolRequest,l=r.toolReadyTimeout,c=void 0===l?5e3:l,f=r.personal,d=void 0!==f&&f,h=null,p=null,m=null,g=!1;function v(e){return y.apply(this,arguments)}function y(){return(y=z(/*#__PURE__*/U().mark(function e(t){var n,r,o,i,s,a;return U().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=!1,r=!1,e.prev=2,i=S(t);case 4:return e.next=6,j(i.next());case 6:if(!(n=!(s=e.sent).done)){e.next=14;break}return"done"===(a=s.value).type&&(h=a.token_usage,a.chat_url&&(p=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,j(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;c>0&&(r=setTimeout(function(){n(new Error("ChatSession: WebSocket tool connection timed out after "+c+"ms. Tools will not be available for this chat session."))},c)),m=function(e,t){var n=t.source,r=void 0===n?"editor":n,o=t.tools,i=t.onToolRequest,s=t.onOpen,a=t.onClose,u=t.onError,l=t.reconnect,c=void 0===l||l,f=t.reconnectInterval,d=void 0===f?3e3:f,h=t.maxReconnectAttempts,p=void 0===h?10:h,m=or,g=null,v=!1,y=0,b=null,w=[].concat(void 0===o?[]:o),_=null,P=null;if("undefined"!=typeof document&&"function"==typeof document.addEventListener){var x=function(t){var n,r,o,i;r=e.baseUrl,o=ir(null==(n=t)?void 0:n.blockedURI),i=ir(r),null!==o&&null!==i&&o===i&&(_=t)};document.addEventListener("securitypolicyviolation",x),P=function(){return document.removeEventListener("securitypolicyviolation",x)}}function S(e){g&&1===g.readyState&&g.send(JSON.stringify(e))}function E(){S({type:"register",source:r,instanceId:m,tools:w})}return function t(){if(!v){if(g){try{g.close(1e3,"client reconnecting")}catch(e){}g=null}var n=function(){var t=""+e.baseUrl.replace(/\/$/,"").replace(/^http/,"ws")+I.ai.ws+"?token="+encodeURIComponent(e.authToken);return e.org&&(t+="&org="+encodeURIComponent(e.org)),t+"&instance="+encodeURIComponent(m)}();(g=new WebSocket(n)).onopen=function(){y=0,E(),null==s||s()},g.onmessage=function(e){!function(e){try{var t=JSON.parse(e);if("execute_tool"===t.type&&t.requestId&&t.toolName){var n=t.requestId,r=t.toolName,o=t.args||{};if(!i)return void S({type:"tool_error",requestId:n,error:"No tool handler registered"});Promise.resolve().then(function(){return i(r,o)}).then(function(e){S(e.error?{type:"tool_error",requestId:n,error:e.error}:{type:"tool_result",requestId:n,result:e.result})}).catch(function(e){S({type:"tool_error",requestId:n,error:(null==e?void 0:e.message)||String(e)})})}}catch(e){}}("string"==typeof e.data?e.data:String(e.data))},g.onclose=function(e){var n,r;g=null,null==a||a(),"replaced"!==("string"==typeof(null==e?void 0:e.reason)?e.reason:null!=(n=null==e||null==(r=e.reason)||null==r.toString?void 0:r.toString())?n:"")&&4001!==(null==e?void 0:e.code)?!v&&c&&(y>=p?null==u||u(new Error("Max reconnect attempts ("+p+") reached")):(y++,b=setTimeout(function(){b=null,t()},d))):v=!0},g.onerror=function(t){null==u||u((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||ir(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,_))}}}(),{instanceId:m,updateTools:function(e){w=[].concat(e),E()},sendPresence:function(e){S(k({type:"presence"},e))},close:function(){v=!0,b&&(clearTimeout(b),b=null),P&&(P(),P=null),g&&(g.close(1e3,"client closed"),g=null)},get connected(){return null!==g&&1===g.readyState}}}(e,{source:i,tools:a,onToolRequest:u,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 b={get ready(){return n},sendMessage:function(t,r,o){return z(/*#__PURE__*/U().mark(function s(){var a,u,l;return U().wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,j(n);case 2:if(!g){s.next=4;break}throw new Error("ChatSession is closed");case 4:return l=nr(e,{slug:t,message:r,stream:!0,source:i,personal:d,instanceId:null!=(a=null==(u=m)?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}),s.delegateYield(x(S(v(l))),"t0",6);case 6:case"end":return s.stop()}},s)}))()},sendMessageSync:function(t,r,o){return Promise.resolve(n).then(function(){var n,s;if(g)throw new Error("ChatSession is closed");return Promise.resolve(nr(e,{slug:t,message:r,stream:!1,source:i,personal:d,instanceId:null!=(n=null==(s=m)?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})).then(function(e){return e.token_usage&&(h=e.token_usage),e.chat_url&&(p=e.chat_url),e})})},interruptChat:function(t){try{return Promise.resolve(function(e,t,n){try{var r=new URL(e.baseUrl+I.ai.chat_stop),o=Qn(e,n);return o["Content-Type"]="application/json",Promise.resolve(fetch(r,k({},D,{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:d}))}catch(e){return Promise.reject(e)}},readChat:function(t,n){try{return Promise.resolve(function(e,t,n){try{return null!=n&&n.reconnect?function(e,t,n){try{var r=new URL(e.baseUrl+I.ai.chat+"/"+encodeURIComponent(t)),o=Qn(e,n);return o.Accept="text/event-stream",Promise.resolve(fetch(r,k({},D,{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?Xn(e.body):null})}catch(e){return Promise.reject(e)}}(e,t,n):function(e,t,n){try{var r=new URL(e.baseUrl+I.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=Qn(e,n);return Promise.resolve(fetch(r,k({},D,{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)}}(e,t,{offset:null==n?void 0:n.offset,limit:null==n?void 0:n.limit,personal:d})).then(function(e){return e.chat_url&&(p=e.chat_url),e})}catch(e){return Promise.reject(e)}},listChats:function(){try{return Promise.resolve(tr(e))}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){m&&m.updateTools(e)},get usage(){return h},get chatUrl(){return p},get toolsConnected(){var e,t;return null!=(e=null==(t=m)?void 0:t.connected)&&e},get instanceId(){var e,t;return null!=(e=null==(t=m)?void 0:t.instanceId)?e:null},close:function(){g=!0,m&&(m.close(),m=null)}};return b}var ar=function(e,t){try{return Promise.resolve(t?{authToken:t,org:e||void 0}:v.requestAccessToken(e).then(function(t){return{authToken:t,org:e||void 0}}))}catch(e){return Promise.reject(e)}},ur=function(e,t){try{return Promise.resolve(ar(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||Tn(e.name);e=new File([e.buffer],e.name,{type:n})}else e.type||(e=new File([e],e.name,{type:Tn(e.name)}));var r,o=e;return null==t&&(t=e.webkitRelativePath||""),o.path=t+e.name,o}(e)});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=T(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=T(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=T(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 g=function(e){for(var t,n=new Array,r=/(mesh_lod|image)_\d_(.{1,50})/,o=T(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=Ln(n)[0])?a:null;var a}(m);return g?t=g:(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 v=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(v.length>=1)return t=function(e){for(var t,n,r=Ln(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}(v),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 _=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(_.length>1)return n="Invalid upload: Multiple splat files found. Upload them as separate content items.",console.error(n,_.map(function(e){return e.path||e.name})),{error:n};if(1===_.length)return _[0];if(1===e.length&&!e[0].arrayBuffer&&e[0].path.toLowerCase().startsWith("http"))return e[0];var P=e.filter(function(e){return e.name.toLowerCase().endsWith("package.json")});if(1===P.length)return P[0];if(P.length>1)return n="Invalid upload: Multiple package.json files found. This is currently not supported.",console.error(n,P),{error:n};var x=e.filter(function(e){return e.name.toLowerCase().endsWith(".mtlx")});if(x.length>1)return n="Invalid upload: Multiple mtlx files found. This is currently not supported.",console.error(n,x),{error:n};if(1===x.length)return x[0];var S=e.filter(function(e){var t=e.name.toLowerCase();return t.endsWith(".exr")||t.endsWith(".hdr")||t.endsWith(".hdri")});return S.length>1?(n="Invalid upload: Multiple HDRI files found. Upload them as separate content items.",console.error(n,S.map(function(e){return e.path||e.name})),{error:n}):1===S.length?t=S[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(zn(o)&&(o=o.v),!o)return i;if(o.then){r=0;break}var i=n();if(i&&i.then){if(!zn(i)){r=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!zn(s)){r=2;break}}}var a=new An,u=Un.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&&!zn(s))return void s.then(f).then(void 0,u);if(!(o=e())||zn(o)&&!o.v)return void Un(a,1,i);if(o.then)return void o.then(c).then(void 0,u);zn(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):Un(a,1,i)}function f(){(o=e())?o.then?o.then(c).then(void 0,u):c(o):Un(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)&&Rn.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__*/N(/"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=T(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+"/"+Cn(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,g=T(e);!(m=g()).done;){var v=m.value;if(v.webkitRelativePath===p||v.name==p){h=!0,console.log("✅ Found dependency in name or webkit: "+v.name+" || "+v.webkitRelativePath+" ");break}if(v.path===p){h=!0,console.log("✅ Found dependency in path: "+v.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;function f(r){var o,i,a,l,f,d,h;if(c)return r;function p(r){function o(){return Promise.resolve(fetch(m+I.upload.request,k({},D,{method:"POST",headers:v,body:JSON.stringify(b)})).catch(function(e){return"fetch failed"==e.message||"Failed to fetch"==e.message?"Network error. Make sure you are connected to the internet and "+m+" 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(){if(!_interrupt){var t,o=function(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,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()).then(function(t){return console.error("Failed to complete upload ("+l.status+"): "+t),e=1,{success:!1,error:"Failed to complete upload"}})}();return n&&n.then?n.then(t):t(n)}h=!0,console.log("Upload Done: All files uploaded to "+r.id);var a=k({},B(e),{id:r.id});"none"!=u&&console.log("Completing upload - notify server");var l=null,f=0,d=Jn(function(){return!n&&f<5},function(){return f++},function(){return Promise.resolve(On(1e3*f)).then(function(){var e=AbortSignal.timeout(6e4+5e3*f);return Promise.resolve(fetch(m+I.upload.done,k({},D,{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)?"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(tn({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)},i=function(){if(x)return Promise.resolve(tn({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};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(m+I.upload.cancel,k({},D,{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()-v<1e3)return!1;if(!h||"completed"===n){v=Date.now();var i=Math.floor(d/c*100);return"debug"===u&&console.log("SET STATUS: "+n,t,i),tn({identifier:r.id,status:n,status_message:t,progress:i},e),!0}"none"!=u&&console.warn("Invalid status update...")}var v=Date.now();null!=(i=n)&&i.onStart&&n.onStart(r.id,r.content_id);var b=Date.now(),_=new Nn(s.length,c/1024/1024),P=new Array,x=!1,S=[].concat(s),E=s.length,j=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))}}(),T=In(function(){var o;function i(){return Promise.resolve(Promise.all(P).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),x=!0)})).then(function(){})}var a=qn(S,function(i){var a;if(null!=(a=n)&&null!=(a=a.abort)&&a.aborted)return console.debug("Upload aborted"),void(o=1);if(x)return console.debug("Upload failed"),void(o=1);if(P.length<10){console.debug("Uploading file "+i+"/"+s.length+": "+s[i].name);var l=0,h=0,m=y.files[i],g=m.filename,v=w[i],S=m.content_length,j=m.content_type,T=s[i],W=T.name.endsWith(".gz")?"gzip":T.name.endsWith(".br")?"br":void 0,O=function(e){try{var t,n=function(t){var n;function o(e){var t=function(){var e;if(!h)return console.error("Failed to upload file "+a),Promise.resolve(tn({identifier:r,status:"failed",status_message:"Failed to upload file ("+a+"): "+(null==(e=w)?void 0:e.substring(0,200)),error:"Failed to upload file "+a},v)).then(function(){throw new Error("Failed to upload file "+a)})}();return!t||!t.then||t.then(function(e){return!0})}if(null==x)throw new Error('Failed to get presigned url for "'+a+'" "'+f+'" \n'+S);var i=x.presigned_url,h=!1,w=null,_=0,P=Jn(function(){return!n&&_<5},function(){return _++},function(){function t(){var t;if(null!=y&&null!=(t=y.abort)&&t.aborted)throw new en("Upload aborted");var r={"Content-Type":f,"Content-MD5":l};b&&(r["Content-Length"]=c.toString()),d&&(r["Content-Encoding"]=d),0===_&&"none"!=g&&console.log("Uploading file "+p+"/"+m+": "+a),"debug"===g&&console.debug("PUT with headers",r);var o=new AbortController,v=!1,P=function(){return o.abort()};null!=y&&y.abort&&(y.abort.aborted?o.abort():y.abort.addEventListener("abort",P,{once:!0}));var S=Kn(Vn,function(){v=!0,o.abort()});return S.reset(),Promise.resolve(Qt.put(i,u,k({},D,{withCredentials:!1,signal:o.signal,headers:r,onUploadProgress:function(t){S.reset(),e.onProgress(t)}})).catch(function(e){var t;if(null!=y&&null!=(t=y.abort)&&t.aborted)throw new en("Upload aborted");return v?(w="stalled: no upload progress for 120s","none"!==g&&console.error("Upload stalled (PUT) ("+p+", "+a+") after 120s with no progress"),null):(w=Gn(e),e instanceof en||("none"!==g&&console.error("Failed to upload file (PUT) ("+p+", "+a+') "'+w+'"'),"debug"===g&&(console.log(r,{fileSize:c}),e.response?console.debug(e.response):console.debug(e))),null)}).finally(function(){S.cancel(),null!=y&&y.abort&&y.abort.removeEventListener("abort",P)})).then(function(e){if(e)return 200!==e.status?(w=Gn({response:e}),void console.debug("Failed ("+e.status+" "+e.status+") to upload file "+s.name+' to "'+x.path+'". Retrying...')):(h=!0,"info"===g&&console.log("Uploaded file "+p+"/"+m+' "'+a+'" ('+f+", "+kn(c)+")"),void(n=1))})}var r=function(){if(_>0)return"none"!==g&&console.log("Retry PUT #"+_+" for file "+a),Promise.resolve(On(1e3*_)).then(function(){})}();return r&&r.then?r.then(t):t()});return P&&P.then?P.then(o):o()};if(e.fileSize>=67108864)return function(e){try{var t=function(e,t,n){try{return Promise.resolve(fetch(e,k({},D,{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,g=e.retryDelayMs,v=e.putPart,y=c.baseUrl,b=function(){return k({},B(c),{"Content-Type":"application/json",org:c.org,job_id:n})},w=k({},b(),{filesize:l.toString()}),_=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?cn: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,g=e.onProgress,v=e.signal,y=e.checkCancelled,b=function(){try{var e;if(v&&v.aborted)return Promise.resolve(!0);var t=function(){if(y)return nn(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=cn),!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(an(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=nn(function(){return Promise.resolve(function(e){try{var t,r,o=function(n){if(t)return n;throw r||new Error("Failed to upload part "+e.partNumber)},s=i.get(e.partNumber);if(!s)throw new Error("Missing presigned url for part "+e.partNumber);var f=0,d=an(function(){return!t&&f<=u},function(){return f++},function(){return Promise.resolve(b()).then(function(o){function i(){return nn(function(){var r=n(e.start,e.end);return Promise.resolve(h({url:s,payload:r,partNumber:e.partNumber,size:e.size,signal:v})).then(function(n){if(!n)throw new Error("No ETag returned for part "+e.partNumber);a.push({part_number:e.partNumber,etag:n}),l+=e.size,g&&g(l),t=1})},function(e){return r=e,Promise.resolve(b()).then(function(t){if(t)throw e})})}if(o)throw new Error("Upload aborted");var u=function(){if(f>0&&c>0)return Promise.resolve((e=c*f,new Promise(function(t){return setTimeout(t,e)}))).then(function(){});var e}();return u&&u.then?u.then(i):i()})});return Promise.resolve(d&&d.then?d.then(o):o(d))}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:g,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+I.upload.multipart_create,k({},D,{method:"POST",headers:w,body:_}))).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+I.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:v||function(e){return function(e){var t=e.url,n=e.payload,r=e.partNumber,o=e.contentType,i=e.signal;try{var s=i,a=new AbortController,u=!1,l=function(){return a.abort()};s&&(s.aborted?a.abort():s.addEventListener("abort",l,{once:!0}));var c=Kn(Vn,function(){u=!0,a.abort()});return c.reset(),Promise.resolve(In(function(){return Fn(function(){return Promise.resolve(Qt.put(t,n,k({},D,{withCredentials:!1,signal:a.signal,headers:{"Content-Type":o},onUploadProgress:function(){return c.reset()}}))).then(function(e){var t,n;if(200!==e.status)throw new Error(Gn({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!=s&&s.aborted)throw e;if(u)throw new Error("Part "+r+" stalled: no progress for 120s");throw new Error(Gn(e))})},function(e,t){if(c.cancel(),s&&s.removeEventListener("abort",l),e)throw t;return t}))}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+I.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+I.upload.multipart_abort,k({},D,{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 r=e.uploadId,o=e.uploadRequestPUTUrl,i=e.entrypointPath,s=e.file,a=e.fileName,u=e.fileBuffer,l=e.fileMd5,c=e.fileSize,f=e.fileType,d=e.content_encoding,h=e.fileIndex,p=e.fileNumber,m=e.fileCount,g=e.loglevel,v=e.args,y=e.options,b=e.experimental;"info"===g&&console.log('Uploading file "'+s.name+'" type='+f+" ("+c+") "+s.type+" with hash "+l);var w=k({},B(v),{"Content-Type":"application/json",org:v.org,job_id:r,filesize:c.toString(),progress:(h/m*100).toFixed(0)}),_={filename:a,entrypoint:i,"content-type":f,"content-md5":l,"content-encoding":d,output_index:0};"debug"===g&&console.debug("Requesting presigned URL with headers",w);var P=JSON.stringify(_),x=null,S="",E=0,j=Jn(function(){return!t&&E<5},function(){return E++},function(){var e;if(null==x){if(null!=y&&null!=(e=y.abort)&&e.aborted)throw new Error("Upload aborted");return Promise.resolve(On(200*E)).then(function(){return Promise.resolve(fetch(o,k({},D,{method:"POST",headers:w,body:P})).then(function(e){try{var t,n=function(n){return t?n:Promise.resolve(e.json())},r=function(){if(!e.ok)return Promise.resolve(e.text()).then(function(n){return S=n,console.log(o),console.warn('Failed to get presigned url for "'+a+'" "'+f+'" ('+e.status+").\n→ Retrying..."),t=1,null})}();return Promise.resolve(r&&r.then?r.then(n):n(r))}catch(e){return Promise.reject(e)}}).catch(function(e){return S=e.message,console.warn("Failed to get presigned url "+e.message+", retrying..."),null})).then(function(e){x=e})})}t=1});return Promise.resolve(j&&j.then?j.then(n):n())}catch(e){return Promise.reject(e)}}({uploadId:r.id,uploadRequestPUTUrl:r.request_put_url,entrypointPath:f,file:s[i],fileName:g,fileMd5:m.content_md5,fileBuffer:v,fileType:j,content_encoding:W,fileSize:S,fileIndex:i,fileNumber:i+1,fileCount:E,loglevel:u,experimental:t.experimental,args:e,options:n,onProgress:function(e){var t,r=e.progress||0,o=(l=s[i].size*r)-h;if(h=l,d+=o,null!=(t=n)&&t.progress){var a=d/c,u=s.length,f=s[i].size,m=(Date.now()-b)/1e3,v=_.updateProgress(d/1024/1024);n.progress({uploadedBytes:d,totalBytes:c,progress01:a,fileName:s[i].name,fileSize:f,fileProgress01:r,fileIndex:i,totalFiles:u,estimatedTimeLeftDisplay:v.estimatedTimeRemainingString,estimatedTimeLeft:v.estimatedTimeRemaining,elapsedTime:m}),p("Uploading file "+(i+1)+"/"+u+" ("+g+"): "+(100*r).toFixed(0)+"% of "+kn(c)+". Finished in approx. "+v.estimatedTimeRemainingString,"running",!1)}}}).then(function(e){if(!0!==e)return e;for(var t=P.length-1;t>=0;t--)P[t]===O&&P.splice(t,1);p("Uploaded "+kn(d)+" of "+kn(c)+" for "+s[i].name,"running")}).catch(function(e){var t;null!=(t=n)&&null!=(t=t.abort)&&t.aborted?console.warn("Upload aborted"):(console.error(e.message),x=!0)});P.push(O)}var R=function(){if(P.length>=10)return Promise.resolve(Promise.race(P)).then(function(){})}();return R&&R.then?R.then(function(){}):void 0},function(){return o});return a&&a.then?a.then(i):i()},function(e,t){if(j(),e)throw t;return t});return T&&T.then?T.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)})}var i=Fn(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=Wn(e,n);if(null===r)return null;if(0===r.length)return null;var o=Wn(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&&(y.width=e.width,y.height=e.height)})},function(e){"debug"===u&&console.warn("readImageResolution failed; uploading without dimensions",e)});return i&&i.then?i.then(o):o()}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 m=e.baseUrl,g="Bearer "+e.authToken,v=k({},B(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&&(v.content_id=n.content_id),null!=(i=n)&&i.type&&(v.type=n.type),null!=(a=n)&&a.name&&(v.name=encodeURIComponent(n.name)),null!=(l=n)&&l.parent_job_id&&(v.parent_job_id=n.parent_job_id);var y={entrypoint:(null==(f=t.entrypoint)?void 0:f.path)||(null==(d=t.entrypoint)?void 0:d.name),files:[]};null!=(h=n)&&h.content_type&&(y.content_type=n.content_type);var b={outputs:[y]},w=[],_=qn(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=jn(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=En(t);w[e]=t,y.files[e]={filename:o,content_type:f,content_length:c,content_md5:h}})},function(){});return _&&_.then?_.then(p):p()}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."};var d=function(){if(!t.raw)return qn(s,function(e){var r=s[e],o=r.name.toLowerCase();return function(){var i;if(o.endsWith(".html")||o.endsWith(".js")||o.endsWith(".css"))return"none"!==(null==(i=n)?void 0:i.loglevel)&&console.log("gZip compressing file: "+r.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)||jn(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)}}(r).catch(function(e){return{error:"Error compressing "+r.name+": "+e.message}})).then(function(o){var i;if(null!==o){if("error"in o)return c=1,{success:!1,error:o.error,status:500};if(!o)return c=1,{success:!1,error:"Failed to compress "+r.name,status:500};var a=t.entrypoint===r;s[e]=o,a&&(t.entrypoint=o),"none"!==(null==(i=n)?void 0:i.loglevel)&&console.log("gZip compressed file: "+r.name+" "+(a?"(entrypoint)":""))}else{var u;"none"!==(null==(u=n)?void 0:u.loglevel)&&console.error("Did not compress file: "+r.name)}})}()},function(){return c});"none"!=u&&console.warn("Raw upload - skipping gzip compression of files")}();return d&&d.then?d.then(f):f(d)})}catch(e){return Promise.reject(e)}}(e,t,n);return Hn.push(r),Promise.resolve(r.finally(function(){var e=Hn.indexOf(r);e>=0&&Hn.splice(e,1)}))}catch(e){return Promise.reject(e)}}(k({baseUrl:"https://cloud.needle.tools/api"},n,t),{triggered_by:"web",entrypoint:void 0,files:r},{name:t.name,abort:t.abort}).then(function(e){return"error"in e?{error:e.error}:{job_id:e.id,content_id:e.content_id,url:e.url,skipped:e.uploadSkipped}})})}catch(e){return Promise.reject(e)}},lr=function(e){try{return Promise.resolve(ar()).then(function(t){if(!t)return!1;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,s),M(k({baseUrl:"https://cloud.needle.tools/api"},t),{type:"user","x-needle-product":n.join(",")}).then(function(e){for(var t,n=T(e);!(t=n()).done;)if(t.value.valid)return!0;return!1})})}catch(e){return Promise.reject(e)}},cr=function(e){try{return Promise.resolve(ar()).then(function(t){if(!t)return null;var n=Array.isArray(e.product)?e.product:[e.product];return n.push.apply(n,s),M(k({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)}},fr=function(e){try{return Promise.resolve(ar(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")+I.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:k({},B({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)}}(k({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)}},dr=function(e,t){try{return Promise.resolve(pr(null==t?void 0:t.org)).then(function(n){return Promise.resolve(ar(n,null==t?void 0:t.authToken)).then(function(t){return sr(k({baseUrl:"https://cloud.needle.tools/api"},t),e)})})}catch(e){return Promise.reject(e)}},hr=function(e){try{return Promise.resolve(pr(null==e?void 0:e.org)).then(function(t){return Promise.resolve(ar(t,null==e?void 0:e.authToken)).then(function(e){return tr(k({baseUrl:"https://cloud.needle.tools/api"},e))})})}catch(e){return Promise.reject(e)}},pr=function(e){try{return Promise.resolve(e||v.getDefaultTeamId())}catch(e){return Promise.reject(e)}};function mr(e){return function(e,t){void 0===t&&(t={});try{var n=new URL("https://cloud.needle.tools/api"+I.public.content_list);if(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,k({},D,{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 gr(e){return function(e,t){try{var n="https://cloud.needle.tools/api"+I.public.content_list+"/"+encodeURIComponent(t);return Promise.resolve(fetch(n,k({},D,{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)}var vr=["org","authToken"],yr=function(e,t){void 0===t&&(t={});try{return Promise.resolve(ar(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+I.content.root+"/"+t,r=B(e);return Promise.resolve(fetch(n,k({},D,{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 get content ("+e.status+"): "+t)})}();return n&&n.then?n.then(t):t()})}catch(e){return Promise.reject(e)}}(k({baseUrl:"https://cloud.needle.tools/api"},t),e)})}catch(e){return Promise.reject(e)}},br=function(e){void 0===e&&(e={});try{var t=e.org,n=e.authToken,r=R(e,vr);return Promise.resolve(ar(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+I.content.root);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=B(e);return Promise.resolve(fetch(n,k({},D,{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)}}(k({baseUrl:"https://cloud.needle.tools/api"},e),r)})}catch(e){return Promise.reject(e)}},wr=function(e){try{var t=new URL("https://cloud.needle.tools/api"+I.account.buy_licenses);return Promise.resolve(ar()).then(function(n){var r={mode:"payment",price_id:e.price_id,return_url:window.location.href,cancel_url:window.location.href};return Promise.resolve(fetch(t,{method:"POST",headers:k({"Content-Type":"application/json"},B(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}):{ok:!1,status:400}}):{ok:!1,status:e.status}})})}catch(e){return Promise.reject(e)}};export{v as Auth,i as AuthScopes,F as NeedleLoginButton,dr as createChatSession,yr as getContent,fr as getDeployments,gr as getPublicContent,cr as getUserLicenses,hr as listChats,br as listContent,mr as listPublicContent,lr as ownsProduct,wr as startCheckoutSession,ur as uploadFiles};