@heyputer/puter.js 2.1.7 → 2.1.9

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/puter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  // Copyright 2024-present Puter Technologies Inc. All rights reserved.
2
- // Generated on 2025-11-28 18:15
2
+ // Generated on 2025-12-02 15:50
3
3
 
4
4
  (()=>{var e={9:e=>{e.exports=class{static ensure_array(e){return Array.isArray(e)?e:[e]}static add(...e){return e.reduce((e,t)=>e+t,0)}static split(e,t,s={}){s=s||{};const{trim:n,discard_empty:r}=s,i=[];s.trim&&i.push(e=>e.map(e=>e.trim())),s.discard_empty&&i.push(e=>e.filter(e=>e.length>0));let o=e.split(t);for(const e of i)o=e(o);return o}}},73:(e,t,s)=>{const{RemoveFromArrayDetachable:n}=s(498),{TTopics:r}=s(868),{install_in_instance:i}=s(912);e.exports={install_in_instance:(e,{parameters:t})=>{const s=e._get_merged_static_array("TOPICS");e._.topics={};for(const t of s)e._.topics[t]={listeners_:[]};e.mixin(r,{pub:(t,s)=>{if(t.includes("!"))throw new Error('"!" in event name reserved for future use');const n=e._.topics[t];if(n)for(const e of n.listeners_)e();else console.warn(`missing topic: ${n}`)},sub:(t,s)=>{const r=e._.topics[t];if(r)return r.listeners_.push(s),new n(r.listeners_,s);console.warn(`missing topic: ${r}`)}})}}},140:(e,t,s)=>{const{AdvancedBase:n}=s(952),r=s(891);class i extends n{static FEATURES=[r()]}e.exports={Emitter:i}},178:e=>{e.exports={install_in_instance_:(e,{parameters:t})=>{const s=e._get_merged_static_object("IMPLEMENTS");e._.impls={};for(const t in s){const n=s[t],r={};for(const t in n){const s=n[t];r[t]=s.bind(e)}e._.impls[t]=r}e.as=t=>e._.impls[t],e.list_traits=()=>Object.keys(e._.impls)},install_in_instance:(e,{parameters:t})=>{const s=e._get_inheritance_chain();e._.impls={},e.as=t=>e._.impls[t],e.list_traits=()=>Object.keys(e._.impls),e.mixin=(t,s)=>e._.impls[t]=s;for(const t of s){const s=t.IMPLEMENTS;if(!s)continue;const n=[...Object.getOwnPropertySymbols(s),...Object.keys(s)];for(const t of n){const n=e._.impls[t]??(e._.impls[t]={}),r=s[t];for(const t in r){const s=r[t];n[t]=s.bind(e)}}}}}},259:e=>{class t{static valueOf(){return this.value}}class s extends t{static value=1}class n extends t{static value=1e3*s}class r extends t{static value=60*n}class i extends t{static value=60*r}const o=Date.now(),a=new Date;e.exports={MILLISECOND:s,SECOND:n,MINUTE:r,HOUR:i,DAY:class extends t{static value=24*i},module_epoch:o,module_epoch_d:a,display_time:e=>{const t=e=>String(e).padStart(2,"0"),s=e.getFullYear(),n=t(e.getMonth()+1),r=t(e.getDate()),i=`${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`,o=s!==a.getFullYear(),c=o||e.getMonth()!==a.getMonth(),l=c||e.getDate()!==a.getDate();return o?`${s}-${n}-${r} ${i}`:c?`${n}-${r} ${i}`:l?`${r} ${i}`:i}}},274:e=>{function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=274,e.exports=t},294:(e,t,s)=>{const{AdvancedBase:n}=s(952),{Service:r}=s(866),{ServiceManager:i}=s(875),o=s(868);e.exports={AdvancedBase:n,system:{ServiceManager:i},libs:{promise:s(717),context:s(475),listener:s(498),log:s(346),string:s(519),time:s(259),smol:s(9),event:s(140)},features:{EmitterFeature:s(891)},concepts:{Service:r},traits:o}},314:e=>{e.exports={name:"Properties",depends:["Listeners"],install_in_instance:(e,{parameters:t})=>{const s=e._get_merged_static_object("PROPERTIES");e.onchange=(t,s)=>{e._.properties[t].listeners.push(s)},e._.properties={};for(const n in s){const r={definition:s[n],listeners:[],value:void 0};e._.properties[n]=r;let i=null;if("object"==typeof s[n]?(i=s[n],i.factory&&(i.value=i.factory({parameters:t}))):"function"==typeof s[n]&&(i={},i.value=s[n]()),null===i)throw new Error("this will never happen");if(Object.defineProperty(e,n,{get:()=>r.value,set:t=>{for(const s of e._.properties[n].listeners)s(t,{old_value:e[n]});const s=e[n],o=t;i.adapt&&(t=i.adapt(t)),r.value=t,i.post_set&&i.post_set.call(e,t,{intermediate_value:o,old_value:s})}}),r.value=i.value,s[n].construct){const r="string"==typeof s[n].construct?s[n].construct:n;e[n]=t[r]}}}}},346:(e,t,s)=>{const{AdvancedBase:n}=s(952),{TLogger:r,AS:i}=s(868);class o extends n{static MODULES={util:{inspect:e=>e}};static PROPERTIES={console:{construct:!0,factory:()=>console},format:()=>({info:{ansii:""},warn:{ansii:""},error:{ansii:"",err:!0},debug:{ansii:""}})};static IMPLEMENTS={[r]:{log(e,t,s,n){const r=(0,this.require)("util"),i=this.format[e];let o="";o+=`${i.ansii}[${e.toUpperCase()}] `,o+=t,Object.keys(s).length&&(o+=" ",o+=`${Object.entries(s).map(([e,t])=>`\n ${e}=${r.inspect(t)}`).join(" ")}\n`),(this.console??console)[i.err?"error":"log"](o,...n)}}}}class a extends n{static PROPERTIES={fields:{construct:!0,factory:()=>({})},delegate:{construct:!0,value:null,adapt:e=>i(e,r)}};static IMPLEMENTS={[r]:{log(e,t,s,n){return this.delegate.log(e,t,Object.assign({},this.fields,s),n)}}}}class c extends n{static PROPERTIES={impl:{value:()=>new o,adapt:e=>i(e,r),construct:!0},cat:{construct:!0}};static IMPLEMENTS={[r]:{log(e,t,s,n){console.log()}}};fields(e){const t=new a({fields:e,delegate:this.impl});return new c({impl:t})}info(e,...t){this.impl.log("info",e,{},t)}on(e){this.cat.on(e)}off(e){this.cat.off(e)}}e.exports={ArrayLogger:class extends n{static PROPERTIES={buffer:{factory:()=>[]}};static IMPLEMENTS={[r]:{log(e,t,s,n){this.buffer.push({level:e,message:t,fields:s,values:n})}}}},CategorizedToggleLogger:class extends n{static PROPERTIES={categories:{description:"categories that are enabled",factory:()=>({})},delegate:{construct:!0,value:null,adapt:e=>i(e,r)}};static IMPLEMENTS={[r]:{log(e,t,s,n){const r=s.category;if(this.categories[r])return this.delegate.log(e,t,s,n)}}};on(e){this.categories[e]=!0}off(e){delete this.categories[e]}},ToggleLogger:class extends n{static PROPERTIES={enabled:{construct:!0,value:!0},delegate:{construct:!0,value:null,adapt:e=>i(e,r)}};static IMPLEMENTS={[r]:{log(e,t,s,n){if(this.enabled)return this.delegate.log(e,t,s,n)}}}},ConsoleLogger:o,PrefixLogger:class extends n{static PROPERTIES={prefix:{construct:!0,value:""},delegate:{construct:!0,value:null,adapt:e=>i(e,r)}};static IMPLEMENTS={[r]:{log(e,t,s,n){return this.delegate.log(e,this.prefix+t,s,n)}}}},FieldsLogger:a,LoggerFacade:c}},429:(e,t,s)=>{"use strict";const n=s(614);function r(e,t){const s=e.toLowerCase(),n=t.toLowerCase();if(""===n)return!1;if(-1===n.indexOf("*")&&-1===n.indexOf("?")&&-1===n.indexOf("[")&&-1===n.indexOf("{"))return s===n;let i=n;const o=i.match(/\{([^}]+)\}/);if(o)return o[1].split(",").map(e=>i.replace(o[0],e.trim())).some(t=>r(e,t));let a="",c=0;for(;c<i.length;){const e=i[c];if("*"===e)a+=".*";else if("?"===e)a+=".";else if("["===e){let e=c+1,t="[";for(;e<i.length&&"]"!==i[e];)t+=i[e],e++;e<i.length?(t+="]",a+=t,c=e):a+="\\["}else/[.+^${}()|\\]/.test(e)?a+="\\"+e:a+=e;c++}try{return new RegExp("^"+a+"$","i").test(e)}catch(e){return s===n}}e.exports=class{constructor(e={}){"string"==typeof e&&(e={dbName:e}),this.store=new n,this.expireTimes=new n,this.db=null,this.dbName=e.dbName,this.dbVersion=e.dbVersion||1,this.isIndexedDBAvailable=!1,this.isInitialized=!1,this.initPromise=null,this.storeSet=(e,t)=>{this.store.set(e,t),this._initCleanupLoop(20),this.isIndexedDBAvailable&&this.db&&this._persistToIndexedDB(e,t)},this._initIndexedDB()}_initIndexedDB(){"undefined"!=typeof window&&window.indexedDB&&this.dbName?(this.isIndexedDBAvailable=!0,this.initPromise=this._setupIndexedDB()):this.isInitialized=!0}async _setupIndexedDB(){try{this.db=await this._openDatabase(),await this._loadFromIndexedDB(),this.isInitialized=!0}catch(e){console.warn("Failed to initialize IndexedDB:",e),this.isIndexedDBAvailable=!1,this.isInitialized=!0}}_openDatabase(){return new Promise((e,t)=>{const s=indexedDB.open(this.dbName,this.dbVersion);s.onerror=()=>t(s.error),s.onsuccess=()=>e(s.result),s.onupgradeneeded=e=>{const t=e.target.result;t.objectStoreNames.contains("store")||t.createObjectStore("store",{keyPath:"key"}),t.objectStoreNames.contains("expireTimes")||t.createObjectStore("expireTimes",{keyPath:"key"})}})}async _loadFromIndexedDB(){if(this.db)try{const e=this.db.transaction(["store","expireTimes"],"readonly"),t=e.objectStore("store"),s=e.objectStore("expireTimes"),n=t.getAll(),r=s.getAll(),[i,o]=await Promise.all([new Promise((e,t)=>{n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),new Promise((e,t)=>{r.onsuccess=()=>e(r.result),r.onerror=()=>t(r.error)})]);i.forEach(e=>{this.store.set(e.key,e.value)}),o.forEach(e=>{this.expireTimes.set(e.key,e.expireTime)});const a=Date.now();for(const[e,t]of this.expireTimes.entries())a>t&&(this.store.delete(e),this.expireTimes.delete(e),this._removeFromIndexedDB(e))}catch(e){console.warn("Failed to load data from IndexedDB:",e)}}async _persistToIndexedDB(e,t){if(this.db)try{this.db.transaction(["store"],"readwrite").objectStore("store").put({key:e,value:t})}catch(e){console.warn("Failed to persist to IndexedDB:",e)}}async _persistExpirationToIndexedDB(e,t){if(this.db)try{const s=this.db.transaction(["expireTimes"],"readwrite").objectStore("expireTimes");void 0!==t?s.put({key:e,expireTime:t}):s.delete(e)}catch(e){console.warn("Failed to persist expiration to IndexedDB:",e)}}async _removeFromIndexedDB(e){if(this.db)try{const t=this.db.transaction(["store","expireTimes"],"readwrite"),s=t.objectStore("store"),n=t.objectStore("expireTimes");s.delete(e),n.delete(e)}catch(e){console.warn("Failed to remove from IndexedDB:",e)}}async waitForInitialization(){this.isInitialized||this.initPromise&&await this.initPromise}set(e,t,s={}){const{NX:n=!1,XX:r=!1,GET:i=!1,EX:o,PX:a,EXAT:c,PXAT:l,KEEPTTL:h=!1}=s,u=n,d=r,p=i;let g=o?parseInt(o,10):void 0,f=a?parseInt(a,10):void 0,m=c?parseInt(c,10):void 0,y=l?parseInt(l,10):void 0;const b=h,w=this.store.has(e);if(d&&!w)return;if(u&&w)return;let v;if(p&&w&&(v=this.store.get(e)),this.storeSet(e,t),void 0!==g||void 0!==f||void 0!==m||void 0!==y||b){let t;void 0!==g?t=Date.now()+1e3*g:void 0!==f?t=Date.now()+f:void 0!==m?t=1e3*m:void 0!==y?t=y:b&&w&&(t=this.expireTimes.get(e)),void 0!==t&&(this.expireTimes.set(e,t),this.isIndexedDBAvailable&&this.db&&this._persistExpirationToIndexedDB(e,t))}else this.expireTimes.delete(e),this.isIndexedDBAvailable&&this.db&&this._persistExpirationToIndexedDB(e,void 0);return!p||v}get(e){if(!this._checkAndRemoveExpiredKey(e))return this.store.get(e)}del(...e){let t=0;for(const s of e)this._checkAndRemoveExpiredKey(s)||this.store.delete(s)&&(this.expireTimes.delete(s),this.isIndexedDBAvailable&&this.db&&this._removeFromIndexedDB(s),t++);return t}exists(...e){let t=0;for(const s of e)this._checkAndRemoveExpiredKey(s)||this.store.has(s)&&t++;return t}incr(e){return this.incrby(e,1)}incrby(e,t){let s=this.store.get(e);if(void 0===s)s=0;else if(!Number.isInteger(Number(s)))throw new Error("ERR value is not an integer");const n=Number(s)+t;return this.storeSet(e,n.toString()),n}decr(e){try{return this.decrby(e,1)}catch(e){throw e}}decrby(e,t){let s=this.store.get(e);if(void 0===s)s=0;else if(!Number.isInteger(Number(s)))throw new Error("ERR value is not an integer");const n=Number(s)-t;return this.storeSet(e,n.toString()),n}expire(e,t,s={}){if(!this.store.has(e))return 0;const{NX:n=!1,XX:r=!1,GT:i=!1,LT:o=!1}=s,a=Date.now(),c=this.expireTimes.get(e);return n&&void 0!==c||r&&void 0===c||i&&(void 0===c||c<=a+1e3*t)||o&&(void 0===c||c>=a+1e3*t)?0:(this.expireTimes.set(e,a+1e3*t),1)}keys(e){const t=[];for(const[s,n]of this.store.entries())if(r(s,e)){const e=this.expireTimes.get(s);(void 0===e||e>Date.now())&&t.push(s)}return t}mget(...e){return e.map(e=>this.get(e))}mset(...e){if(e.length%2!=0)throw new Error("MSET requires an even number of arguments");for(let t=0;t<e.length;t+=2)this.set(e[t],e[t+1]);return!0}renamenx(e,t){if(!this.store.has(e)||this.store.has(t))return 0;const s=this.store.get(e);if(this.store.delete(e),this.storeSet(t,s),this.expireTimes.has(e)){const s=this.expireTimes.get(e);this.expireTimes.delete(e),this.expireTimes.set(t,s)}return 1}randomkey(){const e=Array.from(this.store.keys());if(0!==e.length)return e[Math.floor(Math.random()*e.length)]}expireat(e,t,s={}){if("number"!=typeof t||isNaN(t))throw new Error("ERR invalid expire time in SETEX");if(!this.store.has(e))return 0;const{NX:n=!1,XX:r=!1,GT:i=!1,LT:o=!1}=s,a=1e3*t-Date.now();if(a<=0)return this.store.delete(e),this.expireTimes.delete(e),0;const c=this.pttl(e);return r&&-1===c||n&&-1!==c||i&&-1!==c&&a<=c||o&&-1!==c&&a>=c?0:this.pexpire(e,a)}pexpire(e,t,s={}){const{NX:n=!1,XX:r=!1,GT:i=!1,LT:o=!1}=s;if(n&&this.store.has(e)||r&&!this.store.has(e))return 0;if(i||o){const s=this.pttl(e);if(i&&s>=t||o&&s<=t)return 0}return this.expireTimes.set(e,Date.now()+t),1}pexpireat(e,t){const s=t-Date.now();return s<=0?(this.store.delete(e),this.expireTimes.delete(e),0):this.pexpire(e,s)}pttl(e){if(!this.store.has(e))return-2;if(!this.expireTimes.has(e))return-1;const t=this.expireTimes.get(e)-Date.now();return t>0?t:-2}ttl(e){if(!this.store.has(e))return-2;if(!this.expireTimes.has(e))return-1;const t=Math.floor((this.expireTimes.get(e)-Date.now())/1e3);return t>0?t:-2}persist(e){return this.store.has(e)&&this.expireTimes.has(e)?(this.expireTimes.delete(e),this.isIndexedDBAvailable&&this.db&&this._persistExpirationToIndexedDB(e,void 0),1):0}getrange(e,t,s){const n=this.get(e);return"string"!=typeof n?"":n.slice(t,s+1)}getset(e,t){const s=this.get(e);return this.set(e,t),s}setex(e,t,s){if(this.store.has(e))return this.set(e,t),this.expire(e,s),!0}setrange(e,t,s){if("number"!=typeof t||t<0)throw new Error("Invalid offset value");if("string"!=typeof s)throw new Error("Value must be a string");let n=this.get(e);void 0!==n&&void 0!==n||(n="");const r=n.slice(0,t)+s+n.slice(t+s.length);return this.set(e,r),r.length}strlen(e){const t=this.get(e);return void 0===t?0:t.length}msetnx(...e){if(e.length%2!=0)throw new Error("MSETNX requires an even number of arguments");for(let t=0;t<e.length;t+=2)if(this.store.has(e[t]))return 0;for(let t=0;t<e.length;t+=2)this.set(e[t],e[t+1]);return 1}incrbyfloat(e,t){let s=this.store.get(e);if(void 0===s)s=0;else if(isNaN(parseFloat(s)))throw new Error("ERR value is not a valid float");const n=parseFloat(s)+t;return this.storeSet(e,n.toString()),n}append(e,t){const s=this.get(e),n=void 0===s?t:s+t;return this.set(e,n),n.length}getbit(e,t){const s=this.get(e);if(void 0===s||t>=8*s.length)return 0;const n=Math.floor(t/8),r=7-t%8;return s.charCodeAt(n)>>r&1}setbit(e,t,s){if(0!==s&&1!==s)throw new Error("ERR bit is not an integer or out of range");let n=this.get(e);void 0===n&&(n="");const r=Math.floor(t/8),i=7-t%8;for(;r>=n.length;)n+="\0";const o=n.charCodeAt(r),a=o>>i&1,c=o&~(1<<i)|s<<i,l=String.fromCharCode(c),h=n.slice(0,r)+l+n.slice(r+1);return this.set(e,h),a}copy(e,t){const s=this.get(e);return void 0===s?0:(this.set(t,s),1)}rename(e,t){if(!this.store.has(e))throw new Error("ERR no such key");if(e===t)return!0;const s=this.store.get(e),n=this.expireTimes.get(e);return this.storeSet(t,s),this.store.delete(e),void 0!==n&&(this.expireTimes.set(t,n),this.expireTimes.delete(e)),!0}type(e){return this.store.has(e)?typeof this.store.get(e):"none"}sadd(e,...t){this.store.has(e)||this.storeSet(e,new Set);const s=this.store.get(e);if(!(s instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");let n=0;for(const e of t)s.has(e)||(s.add(e),n++);return n}scard(e){const t=this.store.get(e);if(void 0===t)return 0;if(!(t instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");return t.size}sdiff(e,...t){const s=this.store.get(e)||new Set;if(!(s instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");const n=new Set(s);for(const e of t){const t=this.store.get(e)||new Set;if(!(t instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");for(const e of t)n.delete(e)}return Array.from(n)}sdiffstore(e,t,...s){const n=this.sdiff(t,...s),r=new Set(n);return this.storeSet(e,r),r.size}sinter(...e){if(0===e.length)return[];const t=e.map(e=>{const t=this.store.get(e);if(void 0===t)return new Set;if(!(t instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");return t}),s=new Set(t[0]);for(let e=1;e<t.length;e++)for(const n of s)t[e].has(n)||s.delete(n);return Array.from(s)}sintercard(...e){return this.sinter(...e).length}sinterstore(e,...t){const s=this.sinter(...t),n=new Set(s);return this.storeSet(e,n),n.size}sismember(e,t){const s=this.store.get(e);if(void 0===s)return!1;if(!(s instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");return!!s.has(t)}smembers(e){const t=this.store.get(e);if(void 0===t)return[];if(!(t instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");return Array.from(t)}smismember(e,...t){const s=this.store.get(e)||new Set;if(!(s instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");return t.map(e=>s.has(e)?1:0)}smove(e,t,s){const n=this.store.get(e);if(void 0===n||!n.has(s))return 0;if(!(n instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");const r=this.store.get(t)||new Set;if(!(r instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");return n.delete(s),r.add(s),this.storeSet(t,r),1}spop(e,t=1){const s=this.store.get(e);if(void 0===s)return[];if(!(s instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");const n=[];for(const e of s){if(n.length>=t)break;n.push(e),s.delete(e)}return n}srandmember(e,t=1){const s=this.store.get(e);if(void 0===s)return[];if(!(s instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");const n=Array.from(s),r=[];for(let e=0;e<t&&e<n.length;e++){const e=Math.floor(Math.random()*n.length);r.push(n[e]),n.splice(e,1)}return r}srem(e,...t){const s=this.store.get(e);if(void 0===s)return 0;if(!(s instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");let n=0;for(const e of t)s.delete(e)&&n++;return n}sscan(e,t,s={}){const{match:n="*",count:r=10}=s,i=this.store.get(e);if(void 0===i)return[0,[]];if(!(i instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");const o=new RegExp(n.replace("*",".*")),a=Array.from(i),c=[];let l=t;for(let e=t;e<a.length&&c.length<r;e++)o.test(a[e])&&c.push(a[e]),l=e+1;return[l>=a.length?0:l,c]}sunion(...e){const t=new Set;for(const s of e){const e=this.store.get(s)||new Set;if(!(e instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");for(const s of e)t.add(s)}return Array.from(t)}sunionstore(e,...t){const s=new Set;for(const e of t){const t=this.store.get(e)||new Set;if(!(t instanceof Set))throw new Error("ERR Operation against a key holding the wrong kind of value");for(const e of t)s.add(e)}return this.storeSet(e,s),s.size}lset(e,t,s){const n=this.store.get(e);if(void 0===n)throw new Error("ERR no such key");if(!Array.isArray(n))throw new Error("ERR Operation against a key holding the wrong kind of value");if(t<0||t>=n.length)throw new Error("ERR index out of range");return n[t]=s,!0}ltrim(e,t,s){const n=this.store.get(e);if(void 0===n)return!0;if(!Array.isArray(n))throw new Error("ERR Operation against a key holding the wrong kind of value");const r=n.length,i=t>=0?t:Math.max(r+t,0),o=s>=0?s:Math.max(r+s,-1),a=n.slice(i,o+1);return this.storeSet(e,a),!0}rpop(e){const t=this.store.get(e);return void 0!==t&&Array.isArray(t)?t.pop():null}rpoplpush(e,t){const s=this.rpop(e);return void 0===s?null:(this.lpush(t,s),s)}rpush(e,...t){let s=this.store.get(e);if(void 0===s)s=[],this.storeSet(e,s);else if(!Array.isArray(s))throw new Error("ERR Operation against a key holding the wrong kind of value");return s.push(...t),s.length}rpushx(e,t){const s=this.store.get(e);return void 0!==s&&Array.isArray(s)?(s.push(t),s.length):0}lpush(e,...t){let s=this.store.get(e);if(void 0===s)s=[],this.storeSet(e,s);else if(!Array.isArray(s))throw new Error("ERR Operation against a key holding the wrong kind of value");return s.unshift(...t),s.length}lpushx(e,...t){const s=this.store.get(e);return void 0!==s&&Array.isArray(s)?(s.unshift(...t),s.length):0}lrange(e,t,s){const n=this.store.get(e);if(void 0===n||!Array.isArray(n))return[];const r=n.length,i=t>=0?t:Math.max(r+t,0),o=s>=0?s:Math.max(r+s,-1);return n.slice(i,o+1)}lrem(e,t,s){const n=this.store.get(e);if(void 0===n||!Array.isArray(n))return 0;let r=0;if(t>0)for(let e=0;e<n.length&&r<t;e++)n[e]===s&&(n.splice(e,1),r++,e--);else if(t<0)for(let e=n.length-1;e>=0&&r<-t;e--)n[e]===s&&(n.splice(e,1),r++);else r=n.filter(e=>e===s).length,this.storeSet(e,n.filter(e=>e!==s));return r}lmove(e,t,s,n){const r="LEFT"===n?"lpush":"rpush",i=this["LEFT"===s?"lpop":"rpop"](e);return void 0===i?null:(this[r](t,i),i)}lmpop(e,t,s){const n="LEFT"===s?"lpop":"rpop",r=[];for(let s=0;s<e;s++){const e=this[n](t);if(void 0===e)break;r.push(e)}return r}lpop(e){const t=this.store.get(e);return void 0!==t&&Array.isArray(t)?t.shift():null}lpos(e,t,s={}){const{rank:n=0,start:r=0,stop:i=-1}=s,o=this.store.get(e);if(void 0===o||!Array.isArray(o))return;let a=0;const c=o.length,l=r>=0?r:Math.max(c+r,0),h=i>=0?i:Math.max(c+i,-1);for(let e=l;e<=h;e++)if(o[e]===t){if(a===n)return e;a++}}brpoplpush(e,t,s){const n=this.brpop(e,s);return void 0===n?null:(this.lpush(t,n),n)}lindex(e,t){const s=this.store.get(e);return void 0!==s&&Array.isArray(s)?(t<0&&(t=s.length+t),void 0!==s[t]?s[t]:null):null}linsert(e,t,s,n){const r=this.store.get(e);if(void 0===r)return 0;if(!Array.isArray(r))throw new Error("ERR Operation against a key holding the wrong kind of value");const i=r.indexOf(s);if(-1===i)return 0;if("BEFORE"===t)r.splice(i,0,n);else{if("AFTER"!==t)throw new Error("ERR syntax error");r.splice(i+1,0,n)}return r.length}llen(e){const t=this.store.get(e);return void 0===t?0:t.length}blmove(e,t,s,n,r){const i="LEFT"===n?"lpush":"rpush",o=this["LEFT"===s?"blpop":"brpop"]([e],r);return void 0===o?null:(this[i](t,o[1]),o[1])}blmpop(e,t,...s){const n=[],r=1e3*t,i=1===s.length?"brpop":"brpoplpush",o=s.concat(r);for(let t=0;t<e;t++){const e=this[i](o);if(void 0===e)break;n.push(e)}return n}blpop(e,...t){return this.blmpop(1,e,...t)[0]}brpop(e,...t){const s=1e3*e,n=Date.now()+s;for(;Date.now()<n;)for(let e=0;e<t.length;e++){const s=t[e],n=this.store.get(s);if(void 0!==n&&Array.isArray(n)&&n.length>0){const e=n.pop();return 0===n.length&&this.store.delete(s),[s,e]}}return null}expiretime(e){return this.expireTimes.get(e)}pexpiretime(e){const t=this.expireTimes.get(e);return t?1e3*t:null}zadd(e,t,s){return this._checkAndRemoveExpiredKey(e)?0:(this.store.has(e)||this.storeSet(e,new n),this.store.get(e).set(s,Number(t)),1)}zcard(e){return this._checkAndRemoveExpiredKey(e)?0:this.store.has(e)?this.store.get(e).size:0}zcount(e,t,s){if(this._checkAndRemoveExpiredKey(e))return 0;if(!this.store.has(e))return 0;const n=this.store.get(e);let r=0;for(const e of n.values())e>=t&&e<=s&&r++;return r}zdiff(...e){if(0===e.length)return new Set;const t=e.map(e=>this._checkAndRemoveExpiredKey(e)?new n:this.store.get(e)||new n),s=new Set(t[0].keys());for(let e=1;e<t.length;e++)for(const n of t[e].keys())s.delete(n);return s}zdiffstore(e,...t){const s=this.ZDIFF(...t),r=new n;for(const e of s){const s=t.map(t=>{const s=this.store.get(t);return s?s.get(e):void 0}).filter(e=>void 0!==e);s.length>0&&r.set(e,Math.min(...s))}return this.storeSet(e,r),r.size}bzmpop(e,...t){const s=[];for(const n of t){const t=this.store.get(n);if(t&&t.size>0){const r=Array.from(t.entries()).sort((e,t)=>e[1]-t[1]).slice(0,e).map(([e,s])=>(t.delete(e),[e,s]));s.push([n,...r]);break}}return s}bzpopmax(e,t){const s=this.store.get(e);return s&&0!==s.size?[e,...Array.from(s.entries()).sort((e,t)=>t[1]-e[1]).slice(0,t).map(([e,t])=>(s.delete(e),[e,t]))]:[]}bzpopmin(e,t){const s=this.store.get(e);return s&&0!==s.size?[e,...Array.from(s.entries()).sort((e,t)=>e[1]-t[1]).slice(0,t).map(([e,t])=>(s.delete(e),[e,t]))]:[]}zincrby(e,t,s){this.store.has(e)||this.storeSet(e,new n);const r=this.store.get(e),i=(r.get(s)||0)+Number(t);return r.set(s,i),i}zinter(...e){if(0===e.length)return new Set;const t=e.map(e=>this.store.get(e)||new n),s=new Set(t[0].keys());for(let e=1;e<t.length;e++){const n=new Set;for(const r of t[e].keys())s.has(r)&&n.add(r);s.clear();for(const e of n)s.add(e)}return s}zintercard(...e){return this.ZINTER(...e).size}zinterstore(e,...t){const s=this.ZINTER(...t),r=new n;for(const e of s){const s=t.map(t=>{const s=this.store.get(t);return s?s.get(e):void 0}).filter(e=>void 0!==e);s.length>0&&r.set(e,Math.max(...s))}return this.storeSet(e,r),r.size}zlexcount(e,t,s){const r=this.store.get(e)||new n,i=Array.from(r.keys()).sort();let o=0;for(const e of i)e>=t&&e<=s&&o++;return o}zmpop(e,...t){const s=[];for(const n of t){const t=this.store.get(n);if(t&&t.size>0){const r=Array.from(t.entries()).sort((e,t)=>e[1]-t[1]).slice(0,e).map(([e,s])=>(t.delete(e),[e,s]));s.push([n,...r]);break}}return s}zmscore(e,...t){const s=this.store.get(e)||new n;return t.map(e=>s.get(e))}zpopmax(e,t){const s=this.store.get(e);return s&&0!==s.size?Array.from(s.entries()).sort((e,t)=>t[1]-e[1]).slice(0,t).map(([e,t])=>(s.delete(e),[e,t])):[]}zpopmin(e,t){const s=this.store.get(e);return s&&0!==s.size?Array.from(s.entries()).sort((e,t)=>e[1]-t[1]).slice(0,t).map(([e,t])=>(s.delete(e),[e,t])):[]}zrandmember(e,t=1){const s=this.store.get(e);if(!s||0===s.size)return[];const n=Array.from(s.keys()),r=[];for(let e=0;e<t;e++){const e=Math.floor(Math.random()*n.length);r.push(n[e])}return r}zrange(e,t,s){const r=this.store.get(e)||new n,i=Array.from(r.entries()).sort((e,t)=>e[1]-t[1]);return t<0&&(t=i.length+t),s<0&&(s=i.length+s),i.slice(t,s+1).map(([e,t])=>[e,t])}zrangebylex(e,t,s,r={}){const i=this.store.get(e)||new n;let o=Array.from(i.keys()).sort().filter(e=>e>=t&&e<=s);if(r.limit){const{offset:e,count:t}=r.limit;o=o.slice(e,e+t)}return o}zrangebyscore(e,t,s,r={}){const i=this.store.get(e)||new n;let o=Array.from(i.entries()).sort((e,t)=>e[1]-t[1]).filter(([,e])=>e>=t&&e<=s);if(o=r.withscores?o.map(([e,t])=>[e,t]):o.map(([e])=>e),r.limit){const{offset:e,count:t}=r.limit;o=o.slice(e,e+t)}return o}zrangestore(e,t,s,r){const i=this.store.get(t)||new n,o=Array.from(i.entries()).sort((e,t)=>e[1]-t[1]);s<0&&(s=o.length+s),r<0&&(r=o.length+r);const a=new n(o.slice(s,r+1));return this.storeSet(e,a),a.size}zrank(e,t){const s=this.store.get(e);if(!s)return;const n=Array.from(s.entries()).sort((e,t)=>e[1]-t[1]);for(let e=0;e<n.length;e++)if(n[e][0]===t)return e}zrem(e,...t){const s=this.store.get(e);if(!s)return 0;let n=0;for(const e of t)s.delete(e)&&n++;return n}zremrangebylex(e,t,s){const n=this.store.get(e);if(!n)return 0;const r=Array.from(n.keys()).sort();let i=0;for(const e of r)e>=t&&e<=s&&(n.delete(e),i++);return i}zremrangebyrank(e,t,s){const n=this.store.get(e);if(!n)return 0;const r=Array.from(n.entries()).sort((e,t)=>e[1]-t[1]);t<0&&(t=r.length+t),s<0&&(s=r.length+s);let i=0;for(let e=t;e<=s;e++)n.delete(r[e][0])&&i++;return i}zremrangebyscore(e,t,s){const n=this.store.get(e);if(!n)return 0;const r=Array.from(n.entries()).sort((e,t)=>e[1]-t[1]);let i=0;for(const[e,o]of r)o>=t&&o<=s&&(n.delete(e),i++);return i}zrevrange(e,t,s){const r=this.store.get(e)||new n,i=Array.from(r.entries()).sort((e,t)=>t[1]-e[1]);return t<0&&(t=i.length+t),s<0&&(s=i.length+s),i.slice(t,s+1).map(([e,t])=>[e,t])}zrevrangebylex(e,t,s,r={}){const i=this.store.get(e)||new n;let o=Array.from(i.keys()).sort().reverse().filter(e=>e>=s&&e<=t);if(r.limit){const{offset:e,count:t}=r.limit;o=o.slice(e,e+t)}return o}zrevrangebyscore(e,t,s,r={}){const i=this.store.get(e)||new n;let o=Array.from(i.entries()).sort((e,t)=>t[1]-e[1]).filter(([,e])=>e>=s&&e<=t);if(o=r.withscores?o.map(([e,t])=>[e,t]):o.map(([e])=>e),r.limit){const{offset:e,count:t}=r.limit;o=o.slice(e,e+t)}return o}zrevrank(e,t){const s=this.store.get(e);if(!s)return;const n=Array.from(s.entries()).sort((e,t)=>t[1]-e[1]);for(let e=0;e<n.length;e++)if(n[e][0]===t)return e}zscan(e,t,s={}){const r=this.store.get(e)||new n,i=Array.from(r.entries()).sort((e,t)=>e[1]-t[1]),o=[];let a=s.count||10,c=t;for(;a>0&&c<i.length;)s.match&&!new RegExp(s.match.replace("*",".*")).test(i[c][0])||(o.push(i[c]),a--),c++;return[c>=i.length?0:c,o]}zscore(e,t){const s=this.store.get(e);if(s)return s.get(t)}zunion(e){const t=new n;for(const s of e){const e=this.store.get(s);if(e)for(const[s,n]of e.entries())t.set(s,(t.get(s)||0)+n)}return Array.from(t.entries()).sort((e,t)=>e[1]-t[1])}zunionstore(e,t){const s=this.zunion(t),r=new n(s);return this.storeSet(e,r),r.size}geoadd(e,t,s,r){if("number"!=typeof t||"number"!=typeof s)throw new Error("Invalid longitude or latitude value");const i=this.store.get(e)||new n;if(!i.get(r)){const n={longitude:t,latitude:s};return i.set(r,n),this.storeSet(e,i),1}return 0}geodist(e,t,s,n="m"){const r=this.store.get(e);if(!r)return;const i=r.get(t),o=r.get(s);if(!i||!o)return;const a=this._haversineDistance(i.latitude,i.longitude,o.latitude,o.longitude);return this._convertDistance(a,n)}geohash(e,...t){const s=this.store.get(e);return s?t.map(e=>{const t=s.get(e);return t?this._encodeGeohash(t.latitude,t.longitude):null}):[]}geopos(e,...t){const s=this.store.get(e);return s?t.map(e=>{const t=s.get(e);return t?[t.latitude,t.longitude]:null}):[]}georadius(e,t,s,n,r="m"){const i=this.store.get(e);if(!i)return[];const o=this._convertDistance(n,r,"m"),a=[];for(const[e,n]of i.entries())this._haversineDistance(s,t,n.latitude,n.longitude)<=o&&a.push(e);return a}georadius_ro(e,t,s,n){return this.georadius(e,t,s,n,!0)}georadiusbymember(e,t,s){const n=this.geopos(e,t);if(n)return this.georadius(n[0],n[1],s,e)}georadiusbymember_ro(e,t,s){const n=this.geopos(e,t);if(n)return this.georadius(n[0],n[1],s,e,!0)}geosearch(e,t,s,n){return this.georadius(t,s,n,e)}geosearchstore(e,t,s,n,r){const i=this.georadius(s,n,r,t);return this.set(e,i),i.length}scan(e,t="*",s=10){const n=this.keys(t),r=Math.min(e+s,n.length);return[r===n.length?0:r,n.slice(e,r)]}sort(e,t="ASC",s=!1){const n=this.store.get(e);return Array.isArray(n)?n.slice().sort((e,n)=>s?"ASC"===t?e.localeCompare(n):n.localeCompare(e):"ASC"===t?e-n:n-e):[]}touch(...e){return e.reduce((e,t)=>e+(this.exists(t)?1:0),0)}sort_ro(e,t="ASC",s=!1){return this.sort(e,t,s)}unlink(...e){let t=0;for(const s of e)this.del(s)&&t++;return t}hset(e,t,s){this.store.has(e)||this.storeSet(e,new n);const r=this.store.get(e),i=!r.has(t);return r.set(t,s),i?1:0}hdel(e,...t){const s=this.store.get(e);if(!s)return 0;let n=0;for(const e of t)s.delete(e)&&n++;return n}hget(e,t){const s=this.store.get(e);return s?s.get(t):void 0}hgetall(e){const t=this.store.get(e);if(!t)return{};const s={};for(const[e,n]of t)s[e]=n;return s}hincrby(e,t,s){const r=this.store.get(e)||new n,i=parseInt(r.get(t)||0,10)+s;return r.set(t,i.toString()),this.storeSet(e,r),i}hincrbyfloat(e,t,s){const r=this.store.get(e)||new n,i=parseFloat(r.get(t)||0)+s;return r.set(t,i.toString()),this.storeSet(e,r),i}hkeys(e){const t=this.store.get(e);return t?Array.from(t.keys()):[]}hlen(e){const t=this.store.get(e);return t?t.size:0}hmget(e,...t){const s=this.store.get(e)||new n;return t.map(e=>s.get(e))}hmset(e,...t){const s=this.store.get(e)||new n;for(let e=0;e<t.length;e+=2){const n=t[e],r=t[e+1];s.set(n,r)}return this.storeSet(e,s),!0}hsetnx(e,t,s){const r=this.store.get(e)||new n;return r.has(t)?0:(r.set(t,s),this.storeSet(e,r),1)}hstrlen(e,t){const s=this.store.get(e),n=s?s.get(t):null;return n?n.length:0}hvals(e){const t=this.store.get(e);return t?Array.from(t.values()):[]}hscan(e,t,s="*",r=10){const i=this.store.get(e)||new n,o=Array.from(i.keys()).filter(e=>e.includes(s)),a=Math.min(t+r,o.length);return[a===o.length?0:a,o.slice(t,a).map(e=>[e,i.get(e)])]}hexists(e,t){const s=this.store.get(e);return s&&s.has(t)?1:0}hrandfield(e,t=1){const s=this.store.get(e);if(!s)return[];const n=Array.from(s.keys()),r=[];for(let e=0;e<t;e++){const e=Math.floor(Math.random()*n.length);r.push(n[e])}return r}_checkAndRemoveExpiredKey(e){const t=this.expireTimes.get(e);return!!(t&&Date.now()>t)&&(this.store.delete(e),this.expireTimes.delete(e),this.isIndexedDBAvailable&&this.db&&this._removeFromIndexedDB(e),!0)}_initCleanupLoop(e){1===this.store.size&&(this.cleanupLoop=setInterval(()=>{if(0===this.store.size&&this.cleanupLoop)clearInterval(this.cleanupLoop);else for(const e of this.expireTimes.keys())this._checkAndRemoveExpiredKey(e)},e),"object"==typeof this.cleanupLoop&&"function"==typeof this.cleanupLoop.unref&&this.cleanupLoop.unref())}_haversineDistance(e,t,s,n){const r=e=>e*Math.PI/180,i=r(s-e),o=r(n-t),a=Math.sin(i/2)*Math.sin(i/2)+Math.cos(r(e))*Math.cos(r(s))*Math.sin(o/2)*Math.sin(o/2);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*6371e3}_convertDistance(e,t,s){const n={m:1,km:.001,mi:621371e-9,ft:3.28084};if(!n[t]||!n[s])throw new Error("Invalid distance unit");return e*n[t]/n[s]}_encodeGeohash(e,t){let s="",n=-90,r=90,i=-180,o=180,a=!0,c=0,l=0;for(;s.length<12;){if(a){const e=(i+o)/2;t>e?(l=1+(l<<1),i=e):(l<<=1,o=e)}else{const t=(n+r)/2;e>t?(l=1+(l<<1),n=t):(l<<=1,r=t)}a=!a,c<4?c++:(s+="0123456789bcdefghjkmnpqrstuvwxyz"[l],c=0,l=0)}return s}flushall(){return this.store.clear(),this.expireTimes.clear(),this.isIndexedDBAvailable&&this.db&&this._clearIndexedDB(),!0}async _clearIndexedDB(){if(this.db)try{const e=this.db.transaction(["store","expireTimes"],"readwrite"),t=e.objectStore("store"),s=e.objectStore("expireTimes");t.clear(),s.clear()}catch(e){console.warn("Failed to clear IndexedDB:",e)}}}},475:e=>{class t{constructor(e={}){const t=Object.getOwnPropertyDescriptors(e);for(const e in t)Object.defineProperty(this,e,t[e])}follow(e,t){const s={};for(const n of t)Object.defineProperty(s,n,{get:()=>e[n]});return this.sub(s)}sub(e){void 0===e&&(e={});const s=Object.create(this),n={};for(const r in s)if(s[r]instanceof t){const t=e.hasOwnProperty(r)?e[r]:void 0;s[r]=s[r].sub(t),n[r]=!0}const r=Object.getOwnPropertyDescriptors(e);for(const e in r)n[e]||Object.defineProperty(s,e,r[e]);return s}}e.exports={Context:t}},498:(e,t,s)=>{const{FeatureBase:n}=s(533),{TDetachable:r}=s(868);class i extends n{static FEATURES=[s(178)];constructor(){super(),this.delegates=[],this.detached_=!1}add(e){this.detached_?e.detach():this.delegates.push(e)}static IMPLEMENTS={[r]:{detach(){this.detached_=!0;for(const e of this.delegates)e.detach()}}}}class o extends n{static FEATURES=[s(178)];constructor(){super(),this.also=()=>{}}also(e){return this.also=e,this}static IMPLEMENTS={[r]:{detach(){this.detach_(),this.also()}}}}e.exports={MultiDetachable:i,RemoveFromArrayDetachable:class extends o{constructor(e,t){super(),this.array=new WeakRef(e),this.element=t}detach_(){const e=this.array.deref();if(!e)return;const t=e.indexOf(this.element);-1!==t&&e.splice(t,1)}}}},519:e=>{e.exports={quot:e=>void 0===e?"[undefined]":null===e?"[null]":"function"==typeof e?"[function]":"object"==typeof e?"[object]":"number"==typeof e?`(${e})`:(e=(e=`${e}`).replace(/["`]/g,e=>'"'===e?"`":'"'),e=(e=JSON.stringify(`${e}`)).replace(/["`]/g,e=>'"'===e?"`":'"')),osclink:(e,t)=>(t||(t=e),`]8;;${e}\\${t}]8;;\\`),format_as_usd:e=>e<.01?e<1e-5?`$${e.toExponential(2)}`:`$${e.toFixed(5)}`:`$${e.toFixed(2)}`,wrap_text:(e,t=71)=>{const s=[],n=e.split(/\r?\n\s*\r?\n/);for(const e of n){const n=e.trim().replace(/\s+/g," ").split(" ");if(1===n.length&&""===n[0]){s.push("");continue}let r="";for(const e of n)0===r.length?r=e:r.length+1+e.length<=t?r+=` ${e}`:(s.push(r),r=e);r&&s.push(r),s.push("")}return s.length&&""===s[s.length-1]&&s.pop(),s},ansi_visible_length:e=>[{name:"oscAll",re:"/][^]*(?:|\\)/g"},{name:"osc8:start",re:/\x1B\]8;[^\x07\x1B\\]*;[^\x07\x1B\\]*(?:\x07|\x1B\\)/g},{name:"osc8:end",re:/\x1B\]8;;(?:\x07|\x1B\\)/g},{name:"csi",re:/\x1B\[[0-?]*[ -/]*[@-~]/g}].reduce((e,{re:t})=>e.replace(t,""),e).length}},533:(e,t,s)=>{const{BasicBase:n}=s(777);e.exports={FeatureBase:class extends n{constructor(e,...t){super(e,...t),this._={features:this._get_merged_static_array("FEATURES")};for(const t of this._.features)t.install_in_instance(this,{parameters:e||{}})}}}},614:e=>{"use strict";class t{#e;constructor(e=[]){this.#e=[new Map(e)]}get size(){return this.#e.reduce((e,t)=>e+t.size,0)}clear(){this.#e=[new Map]}delete(e){return this.#e.some(t=>t.delete(e))}get(e){for(const t of this.#e)if(t.has(e))return t.get(e)}has(e){return this.#e.some(t=>t.has(e))}set(e,t){let s=this.#e[0];for(const t of this.#e)if(t.has(e)){s=t;break}return!s.has(e)&&s.size>=8388608&&(this.#e.unshift(new Map),s=this.#e[0]),s.set(e,t),this}*[Symbol.iterator](){for(const e of this.#e)yield*e}*keys(){for(const e of this.#e)yield*e.keys()}*values(){for(const e of this.#e)yield*e.values()}*entries(){for(const e of this.#e)yield*e.entries()}forEach(e,t){for(const[s,n]of this)e.call(t,n,s,this)}}e.exports=t},659:e=>{e.exports={readme:"\n Normalized Asynchronous Request Invocation (NARI) Methods Feature\n\n This feature allows a class to define \"Nari methods\", which are methods\n that support both async/await and callback-style invocation, have\n positional arguments, and an options argument.\n\n \"the expected interface for methods in puter.js\"\n\n The underlying method will receive parameters as an object, with the\n positional arguments as keys in the object. The options argument will\n be merged into the parameters object unless the method spec specifies\n `separate_options: true`.\n\n Example:\n\n ```\n class MyClass extends AdvancedBase {\n static NARI_METHODS = {\n myMethod: {\n positional: ['param1', 'param2'],\n fn: ({ param1, param2 }) => {\n return param1 + param2;\n }\n }\n }\n }\n\n const instance = new MyClass();\n const result = instance.myMethod(1, 2); // returns 3\n ```\n\n The method can also be called with options and callbacks:\n\n ```\n instance.myMethod(1, 2, { option1: 'value' }, (result) => {\n console.log('success', result);\n }, (error) => {\n console.error('error', error);\n });\n ```\n ",install_in_instance:e=>{const t=e._get_merged_static_object("NARI_METHODS");e._.nariMethods={};for(const s in t){const n=t[s],r=n.fn.bind(e);e._.nariMethods[s]=r,e[s]=async(...e)=>{const t=n.firstarg_options&&"object"==typeof e[0]?0:n.positional.length,s=e.slice(0,t),i=e.slice(t),o={},a={},c={};for(const[e,t]of s.entries())o[n.positional[e]]=t;let l;"object"==typeof i[0]&&(Object.assign(a,i[0]),i.shift()),"function"==typeof i[0]?(c.success=i[0],i.shift()):a.success&&(c.success=a.success),"function"==typeof i[0]?(c.error=i[0],i.shift()):a.error&&(c.error=a.error),n.separate_options?o.options=a:Object.assign(o,a);try{l=await r(o)}catch(e){if(!c.error)throw e;c.error(e)}return c.success&&c.success(l),l}}}}},696:(e,t,s)=>{const{TTopics:n}=s(868);e.exports={install_in_instance:(e,{parameters:t})=>{const s=e._get_merged_static_array("HOOKS");e._.init_hooks=e._.init_hooks??[];for(const t of s)e._.init_hooks.push(()=>{e._.context.services.info(t.service).instance.as(n).sub(t.event,t.do.bind(e))})}}},717:e=>{class t{static STATUS_PENDING=Symbol("pending");static STATUS_RUNNING={};static STATUS_DONE=Symbol("done");constructor(){this.status_=this.constructor.STATUS_PENDING,this.donePromise=new Promise((e,t)=>{this.doneResolve=e,this.doneReject=t})}get status(){return this.status_}set status(e){this.status_=e,e===this.constructor.STATUS_DONE&&this.doneResolve()}resolve(e){this.status_=this.constructor.STATUS_DONE,this.doneResolve(e)}awaitDone(){return this.donePromise}then(e,...t){return this.donePromise.then(e,...t)}reject(e){this.status_=this.constructor.STATUS_DONE,this.doneReject(e)}onComplete(e){return this.then(e)}}class s{static TYPE_READ=Symbol("read");static TYPE_WRITE=Symbol("write");constructor(){this.queue=[],this.readers_=0,this.writer_=!1,this.on_empty_=()=>{},this.mode=this.constructor.TYPE_READ}get effective_mode(){return this.readers_>0?this.constructor.TYPE_READ:this.writer_?this.constructor.TYPE_WRITE:void 0}push_(e){0!==this.readers_||this.writer_||(this.mode=e.type),this.queue.push(e),this.check_queue_()}check_queue_(){if(0===this.queue.length)return void(0!==this.readers_||this.writer_||this.on_empty_());const e=()=>this.queue[0];if(0!==this.readers_||this.writer_||(this.mode=e().type),this.mode===this.constructor.TYPE_READ){for(;e()?.type===this.constructor.TYPE_READ;){const e=this.queue.shift();this.readers_++,(async()=>{await e.p_unlock,this.readers_--,this.check_queue_()})(),e.p_operation.resolve()}return}if(this.writer_)return;const t=this.queue.shift();this.writer_=!0,(async()=>{await t.p_unlock,this.writer_=!1,this.check_queue_()})(),t.p_operation.resolve()}async rlock(){const e=new t,s=new t,n={unlock:()=>{s.resolve()}};return this.push_({type:this.constructor.TYPE_READ,p_operation:e,p_unlock:s}),await e,n}async wlock(){const e=new t,s=new t,n={unlock:()=>{s.resolve()}};return this.push_({type:this.constructor.TYPE_WRITE,p_operation:e,p_unlock:s}),await e,n}}e.exports={TeePromise:t,Lock:class{constructor(){this._locked=!1,this._waiting=[]}async acquire(e){if(await new Promise(e=>{this._locked?this._waiting.push({resolve:e}):(this._locked=!0,e())}),e){let t;try{t=await e()}finally{this.release()}return t}}release(){if(this._waiting.length>0){const{resolve:e}=this._waiting.shift();e()}else this._locked=!1}},RWLock:s,asyncSafeSetInterval:async(e,t,s,n)=>{s=s??[],n=n??{};const{onBehindSchedule:r}=n,i=e=>new Promise(t=>setTimeout(t,e));for(;;){await i(t);const n=Date.now();await e(...s);const o=t-(Date.now()-n);if(o<0){if(r&&await r(-o))return}else await i(o)}},raceCase:async e=>Promise.race(Object.entries(e).map(([e,t])=>t.then(t=>[e,t])))}},777:e=>{class t{_get_inheritance_chain(){const e=[];let s=this.constructor;for(;s&&s!==t;)e.push(s),s=s.__proto__;return e.reverse()}_get_merged_static_array(e){const t=this._get_inheritance_chain(),s=[];let n=null;for(const r of t)r[e]&&r[e]!==n&&(n=r[e],s.push(...r[e]));return s}_get_merged_static_object(e){const t=this._get_inheritance_chain(),s={};for(const n of t)n[e]&&Object.assign(s,n[e]);return s}}e.exports={BasicBase:t}},866:(e,t,s)=>{const{AdvancedBase:n}=s(952),r=s(696),i=async()=>{},o=Symbol("TService");e.exports={TService:o,Service:class extends n{static FEATURES=[r];async __on(e,t){const s=this.__get_event_handler(e);return await s(e,...t)}__get_event_handler(e){return this[`__on_${e}`]?.bind?.(this)||this.constructor[`__on_${e}`]?.bind?.(this.constructor)||i}static create({parameters:e,context:t}){const s=new this;return s._.context=t,s.as(o).construct(e),s}static IMPLEMENTS={[o]:{init(...e){if(this._.init_hooks)for(const e of this._.init_hooks)e.call(this);if(this._init)return this._init(...e)},construct(e){this.$parameters={};for(const t in e)this.$parameters[t]=e[t];if(this._construct)return this._construct(e)},get_depends(){return[...this.constructor.DEPENDS??[],...this.get_depends?.()??[]]}}}}}},868:e=>{e.exports={TTopics:Symbol("TTopics"),TDetachable:Symbol("TDetachable"),TLogger:Symbol("TLogger"),AS:(e,t)=>e.constructor&&e.constructor.IMPLEMENTS&&e.constructor.IMPLEMENTS[t]?e.as(t):e}},875:(e,t,s)=>{const{AdvancedBase:n}=s(952),{TService:r}=s(866),i="running";e.exports={ServiceManager:class extends n{constructor({context:e}={}){super(),this.context=e,this.services_l_=[],this.services_m_={},this.service_infos_={},this.init_listeners_=[],this.waiting_={}}async register(e,t,s={}){await new Promise(e=>setTimeout(e,0));const n={name:e,instance:t.create({parameters:s.parameters??{},context:this.context}),status:"registering"};this.services_l_.push(n),this.services_m_[e]=n,await this.maybe_init_(e)}info(e){return this.services_m_[e]}get(e){const t=this.services_m_[e];if(!t)throw new Error(`Service not registered: ${e}`);if(t.status===i)return t.instance}async aget(e){return await this.wait_for_init([e]),this.get(e)}async wait_for_init(e){let t;await new Promise(s=>{t=()=>{if(0===this.get_waiting_for_(e).length){const e=this.init_listeners_.indexOf(t);return-1!==e&&this.init_listeners_.splice(e,1),s(),!0}},t()||this.init_listeners_.push(t)})}get_waiting_for_(e){const t=[];for(const s of e){const e=this.services_m_[s];e?e.status!==i&&t.push(s):t.push(s)}return t}async maybe_init_(e){const t=this.services_m_[e],s=t.instance.as(r).get_depends(),n=this.get_waiting_for_(s);if(0!==n.length){for(const t of n)this.waiting_[t]||(this.waiting_[t]=new Set),this.waiting_[t].add(e);t.status="pending",t.statusWaitingFor=n}else await this.init_service_(e)}async init_service_(e,t={}){const s=this.services_m_[e];s.status="initializing";const n=s.instance.as(r);await n.init(),s.status=i,s.statusStartTS=new Date;const o=this.waiting_[e],a=[];if(o)for(const e of o.values())a.push(this.maybe_init_(e,{no_init_listeners:!0}));if(await Promise.all(a),!t.no_init_listeners)for(const e of this.init_listeners_)await e()}}}},891:e=>{e.exports=({decorators:e}={})=>({install_in_instance(t,{parameters:s}){const n=t._.emitterFeature={};n.listeners_={},n.global_listeners_=[],n.callbackDecorators=e||[],t.emit=async(e,t,s)=>{s=s??{};const r=e.split("."),i=[];for(let r=0;r<n.global_listeners_.length;r++){let o=n.global_listeners_[r];for(const e of n.callbackDecorators)o=e(o);i.push(o(e,t,{...s,key:e}))}for(let o=0;o<r.length;o++){const a=o===r.length-1?r.join("."):`${r.slice(0,o+1).join(".")}.*`,c=n.listeners_[a];if(c)for(let r=0;r<c.length;r++){let o=c[r];for(const e of n.callbackDecorators)o=e(o);i.push(o(t,{...s,key:e}))}}return await Promise.all(i)},t.on=(e,t)=>{const s=n.listeners_[e]||(n.listeners_[e]=[]);return s.push(t),{detach:()=>{const e=s.indexOf(t);-1!==e&&s.splice(e,1)}}},t.on_all=e=>{n.global_listeners_.push(e)}}})},912:(e,t,s)=>{e.exports={install_in_instance:(e,{parameters:t})=>{const n=e._get_merged_static_object("MODULES");if(t.modules)for(const e in t.modules)n[e]=t.modules[e];e.modules=n,e.require=t=>e.modules[t]?e.modules[t]:s(274)(t)}}},952:(e,t,s)=>{const{FeatureBase:n}=s(533);class r extends n{static FEATURES=[s(912),s(314),s(178),s(659),s(73)]}e.exports={AdvancedBase:r}}},t={};function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,s),i.exports}s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";var e=s(294),t=s(429);const n=class{constructor(e={}){this.config={enabled:e.enabled??!1,...e}}updateConfig(e){this.config={...this.config,...e}}enable(){this.config.enabled=!0}disable(){this.config.enabled=!1}isEnabled(){return this.config.enabled}logRequest(e={}){if(!this.isEnabled())return;const{service:t="unknown",operation:s="unknown",params:n={},result:r=null,error:i=null}=e;let o="{}";if(n&&Object.keys(n).length>0)try{o=JSON.stringify(n)}catch(e){o="[Unable to serialize params]"}const a=`${t} - ${s} - ${o}`;i?console.error(a,{error:i.message||i,result:r}):console.log(a,r)}getStats(){return{enabled:this.config.enabled,config:{...this.config}}}},r=47;function i(e){return e===r}function o(e,t,s,n){let i="",o=0,a=-1,c=0,l=0;for(let h=0;h<=e.length;++h){if(h<e.length)l=e.charCodeAt(h);else{if(n(l))break;l=r}if(n(l)){if(a===h-1||1===c);else if(2===c){if(i.length<2||2!==o||46!==i.charCodeAt(i.length-1)||46!==i.charCodeAt(i.length-2)){if(i.length>2){const e=i.lastIndexOf(s);-1===e?(i="",o=0):(i=i.slice(0,e),o=i.length-1-i.lastIndexOf(i,s)),a=h,c=0;continue}if(0!==i.length){i="",o=0,a=h,c=0;continue}}t&&(i+=i.length>0?`${s}..`:"..",o=2)}else i.length>0?i+=`${s}${e.slice(a+1,h)}`:i=e.slice(a+1,h),o=h-a-1;a=h,c=0}else 46===l&&-1!==c?++c:c=-1}return i}const a={resolve(...e){let t="",s=!1;for(let n=e.length-1;n>=-1&&!s;n--){const i=n>=0?e[n]:"/";0!==i.length&&(t=`${i}/${t}`,s=i.charCodeAt(0)===r)}return t=o(t,!s,"/",i),s?`/${t}`:t.length>0?t:"."},normalize(e){if(0===e.length)return".";const t=e.charCodeAt(0)===r,s=e.charCodeAt(e.length-1)===r;return 0===(e=o(e,!t,"/",i)).length?t?"/":s?"./":".":(s&&(e+="/"),t?`/${e}`:e)},isAbsolute:e=>e.length>0&&e.charCodeAt(0)===r,join(...e){if(0===e.length)return".";let t;for(let s=0;s<e.length;++s){const n=e[s];n.length>0&&(void 0===t?t=n:t+=`/${n}`)}return void 0===t?".":a.normalize(t)},relative(e,t){if(e===t)return"";if((e=a.resolve(e))===(t=a.resolve(t)))return"";const s=e.length,n=s-1,i=t.length-1,o=n<i?n:i;let c=-1,l=0;for(;l<o;l++){const s=e.charCodeAt(1+l);if(s!==t.charCodeAt(1+l))break;s===r&&(c=l)}if(l===o)if(i>o){if(t.charCodeAt(1+l)===r)return t.slice(1+l+1);if(0===l)return t.slice(1+l)}else n>o&&(e.charCodeAt(1+l)===r?c=l:0===l&&(c=0));let h="";for(l=1+c+1;l<=s;++l)l!==s&&e.charCodeAt(l)!==r||(h+=0===h.length?"..":"/..");return`${h}${t.slice(1+c)}`},toNamespacedPath:e=>e,dirname(e){if(0===e.length)return".";const t=e.charCodeAt(0)===r;let s=-1,n=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===r){if(!n){s=t;break}}else n=!1;return-1===s?t?"/":".":t&&1===s?"//":e.slice(0,s)},basename(e,t){let s=0,n=-1,i=!0;if(void 0!==t&&t.length>0&&t.length<=e.length){if(t===e)return"";let o=t.length-1,a=-1;for(let c=e.length-1;c>=0;--c){const l=e.charCodeAt(c);if(l===r){if(!i){s=c+1;break}}else-1===a&&(i=!1,a=c+1),o>=0&&(l===t.charCodeAt(o)?-1===--o&&(n=c):(o=-1,n=a))}return s===n?n=a:-1===n&&(n=e.length),e.slice(s,n)}for(let t=e.length-1;t>=0;--t)if(e.charCodeAt(t)===r){if(!i){s=t+1;break}}else-1===n&&(i=!1,n=t+1);return-1===n?"":e.slice(s,n)},extname(e){let t=-1,s=0,n=-1,i=!0,o=0;for(let a=e.length-1;a>=0;--a){const c=e.charCodeAt(a);if(c!==r)-1===n&&(i=!1,n=a+1),46===c?-1===t?t=a:1!==o&&(o=1):-1!==t&&(o=-1);else if(!i){s=a+1;break}}return-1===t||-1===n||0===o||1===o&&t===n-1&&t===s+1?"":e.slice(t,n)},format:function(e,t){validateObject(t,"pathObject");const s=t.dir||t.root,n=t.base||`${t.name||""}${t.ext||""}`;return s?s===t.root?`${s}${n}`:`${s}${e}${n}`:n}.bind(null,"/"),parse(e){const t={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return t;const s=e.charCodeAt(0)===r;let n;s?(t.root="/",n=1):n=0;let i=-1,o=0,a=-1,c=!0,l=e.length-1,h=0;for(;l>=n;--l){const t=e.charCodeAt(l);if(t!==r)-1===a&&(c=!1,a=l+1),46===t?-1===i?i=l:1!==h&&(h=1):-1!==i&&(h=-1);else if(!c){o=l+1;break}}if(-1!==a){const n=0===o&&s?1:o;-1===i||0===h||1===h&&i===a-1&&i===o+1?t.base=t.name=e.slice(n,a):(t.name=e.slice(n,i),t.base=e.slice(n,a),t.ext=e.slice(i,a))}return o>0?t.dir=e.slice(0,o-1):s&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null},c=a;var l={},h={};l.length=0,l.getItem=function(e){return e in h?h[e]:null},l.setItem=function(e,t){void 0===t?l.removeItem(e):(h.hasOwnProperty(e)||l.length++,h[e]=`${t}`)},l.removeItem=function(e){h.hasOwnProperty(e)&&(delete h[e],l.length--)},l.key=function(e){return Object.keys(h)[e]||null},l.clear=function(){h={},l.length=0},"object"==typeof exports&&(module.exports=l);const u=l,d=Symbol("readyState"),p=Symbol("headers"),g=Symbol("response headers"),f=Symbol("AbortController"),m=Symbol("method"),y=Symbol("URL"),b=Symbol("MIME"),w=Symbol("dispatch"),v=Symbol("errored"),_=Symbol("timeout"),k=Symbol("timedOut"),A=Symbol("isResponseText");function T(...e){const t=e.reduce((e,t)=>e+t.length,0),s=new Uint8Array(t);return e.forEach((e,t,n)=>{const r=n.slice(0,t).reduce((e,t)=>e+t.length,0);s.set(e,r)}),s}async function x(e){const t=this.responseType||"text",s=new TextDecoder,n=this[b]||this[g].get("content-type")||"text/plain";switch(t){case"text":this.response=s.decode(e);break;case"blob":this.response=new Blob([e],{type:n});break;case"arraybuffer":this.response=e.buffer;break;case"json":this.response=JSON.parse(s.decode(e))}}const I=class extends EventTarget{onreadystatechange(){}set readyState(e){this[d]!==e&&(this[d]=e,this.dispatchEvent(new Event("readystatechange")),this.onreadystatechange(new Event("readystatechange")))}get readyState(){return this[d]}constructor(){super(),this.readyState=this.constructor.UNSENT,this.response=null,this.responseType="",this.responseURL="",this.status=0,this.statusText="",this.timeout=0,this.withCredentials=!1,this[p]=Object.create(null),this[p].accept="*/*",this[g]=Object.create(null),this[f]=new AbortController,this[m]="",this[y]="",this[b]="",this[v]=!1,this[_]=0,this[k]=!1,this[A]=!0}static get UNSENT(){return 0}static get OPENED(){return 1}static get HEADERS_RECEIVED(){return 2}static get LOADING(){return 3}static get DONE(){return 4}upload={addEventListener(){}};get responseText(){if(this[v])return null;if(this.readyState<this.constructor.HEADERS_RECEIVED)return"";if(this[A])return this.response;throw new DOMException("Response type not set to text","InvalidStateError")}get responseXML(){throw new Error("XML not supported")}[w](e){const t=`on${e.type}`;"function"==typeof this[t]&&this.addEventListener(e.type,this[t].bind(this),{once:!0}),this.dispatchEvent(e)}abort(){this[f].abort(),this.status=0,this.readyState=this.constructor.UNSENT}open(e,t){this.status=0,this[m]=e,this[y]=t,this.readyState=this.constructor.OPENED}setRequestHeader(e,t){e=String(e).toLowerCase(),void 0===this[p][e]?this[p][e]=String(t):this[p][e]+=`, ${t}`}overrideMimeType(e){this[b]=String(e)}getAllResponseHeaders(){return this[v]||this.readyState<this.constructor.HEADERS_RECEIVED?"":Array.from(this[g].entries().map(([e,t])=>`${e}: ${t}`)).join("\r\n")}getResponseHeader(e){const t=this[g].get(String(e).toLowerCase());return"string"==typeof t?t:null}send(e=null){this.timeout>0&&(this[_]=setTimeout(()=>{this[k]=!0,this[f].abort()},this.timeout));const t=this.responseType||"text";this[A]="text"===t,this.setRequestHeader("user-agent","puter-js/1.0"),this.setRequestHeader("origin","https://puter.work"),this.setRequestHeader("referer","https://puter.work/"),fetch(this[y],{method:this[m]||"GET",signal:this[f].signal,headers:this[p],credentials:this.withCredentials?"include":"same-origin",body:e}).then(async e=>{if(this.responseURL=e.url,this.status=e.status,this.statusText=e.statusText,this[g]=e.headers,this.readyState=this.constructor.HEADERS_RECEIVED,e.headers.get("content-type").includes("application/x-ndjson")||this.streamRequestBadForPerformance){let t=new Uint8Array;for await(const s of e.body)this.readyState=this.constructor.LOADING,t=T(t,s),x.call(this,t),this[w](new CustomEvent("progress"))}else{const t=[];for await(const s of e.body)t.push(s);x.call(this,T(...t))}this.readyState=this.constructor.DONE,this[w](new CustomEvent("load"))},e=>{let t="abort";"AbortError"!==e.name?(this[v]=!0,t="error"):this[k]&&(t="timeout"),this.readyState=this.constructor.DONE,this[w](new CustomEvent(t))}).finally(()=>this[w](new CustomEvent("loadend"))).finally(()=>{clearTimeout(this[_]),this[w](new CustomEvent("loadstart"))})}};"object"==typeof module&&module.exports?module.exports=I:(globalThis||self).XMLHttpRequestShim=I;const E=I;class S{constructor(){this.result=null,this.error=null,this.onloadend=null}readAsDataURL(e){const t=this;!async function(){try{let s;s=e&&"function"==typeof e.arrayBuffer?await e.arrayBuffer():e instanceof ArrayBuffer?e:ArrayBuffer.isView(e)?e.buffer:new Uint8Array(0).buffer;const n=function(e){const t=new Uint8Array(e).reduce((e,t)=>e+String.fromCharCode(t),"");return"function"==typeof btoa?btoa(t):Buffer.from(t,"binary").toString("base64")}(s),r=e&&e.type||"application/octet-stream";t.result="data:"+r+";base64,"+n,"function"==typeof t.onloadend&&t.onloadend()}catch(e){t.error=e,"function"==typeof t.onloadend&&t.onloadend()}}()}}async function P(e){if("blob"===e.responseType){const t=e.getResponseHeader("content-type");if(t.startsWith("application/json")){const t=await e.response.text();try{return JSON.parse(t)}catch(e){return t}}else if(t.startsWith("application/octet-stream"))return e.response;return{success:!0,result:e.response}}const t=e.responseText;try{return JSON.parse(t)}catch(e){return t}}function O(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))}function C(e,t,s,n="post",r="text/plain;actually=json",i=void 0){const o=new XMLHttpRequest;return o.open(n,t+e,!0),s&&o.setRequestHeader("Authorization",`Bearer ${s}`),o.setRequestHeader("Content-Type",r),o.responseType=i??"",globalThis.puter?.apiCallLogger?.isEnabled()&&(o._puterRequestId={method:n,service:"xhr",operation:e.replace(/^\//,""),params:{endpoint:e,contentType:r,responseType:i}}),o}function D(e,t,s){return e&&"function"==typeof e&&e(s),t(s)}function R(e,t,s,n,r){e.addEventListener("load",async function(e){if(globalThis.puter?.apiCallLogger?.isEnabled()&&this._puterRequestId){const e=await P(this).catch(()=>null);globalThis.puter.apiCallLogger.logRequest({service:this._puterRequestId.service,operation:this._puterRequestId.operation,params:this._puterRequestId.params,result:this.status>=400?null:e,error:this.status>=400?{message:this.statusText,status:this.status}:null})}return async function(e,t,s,n,r){const i=await P(r);return 401===r.status?(t&&"function"==typeof t&&t({status:401,message:"Unauthorized"}),n({status:401,message:"Unauthorized"})):200!==r.status?(t&&"function"==typeof t&&t(i),n(i)):(!1===i.success&&"permission_denied"===i.error?.code&&(await puter.ui.requestPermission({permission:"driver:puter-image-generation:generate"})).granted,e&&"function"==typeof e&&e(i),s(i))}(t,s,n,r,this)}),e.addEventListener("error",function(e){return globalThis.puter?.apiCallLogger?.isEnabled()&&this._puterRequestId&&globalThis.puter.apiCallLogger.logRequest({service:this._puterRequestId.service,operation:this._puterRequestId.operation,params:this._puterRequestId.params,error:{message:"Network error occurred",event:e.type}}),D(s,r,this)})}const L=()=>{};class M{static callback(e){return e&&"function"==typeof e?e:void 0}}function U(e,t,s,n,r={}){return async function(...i){let o={},a={};return 1!==i.length||"object"!=typeof i[0]||Array.isArray(i[0])?(e.forEach((e,t)=>{o[e]=i[t]}),a={success:i[e.length],error:i[e.length+1]}):(o={...i[0]},a={success:o.success,error:o.error},delete o.success,delete o.error),r.preprocess&&"function"==typeof r.preprocess&&(o=r.preprocess(o)),await async function(e,t,s,n,r,i){const o=new q;return B(e,o.resolve.bind(o),o.reject.bind(o),t,s,n,r,void 0,void 0,i),await o}(a,t,s,n,o,r)}}async function B(e={},t,s,n,r,i,o,a,c="text/plain;actually=json",l={}){let h=null;if(globalThis.puter?.apiCallLogger?.isEnabled()&&(h={interface:n,driver:r,method:i,args:o}),!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){return h&&globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:`${n}::${i}`,params:{interface:n,driver:r,method:i,args:o},error:{code:"auth_canceled",message:"Authentication canceled"}}),s({error:{code:"auth_canceled",message:"Authentication canceled"}})}const u=M.callback(e.success)??L,d=M.callback(e.error)??L,p=C("/drivers/call",puter.APIOrigin,void 0,"POST",c);h&&(p._puterDriverRequestInfo=h),l.responseType&&(p.responseType=l.responseType);let g=!1,f=null,m=0,y=!1,b="";const w=[];p.onreadystatechange=()=>{if(2===p.readyState){if("application/x-ndjson"!==p.getResponseHeader("Content-Type"))return;g=!0;const e=async function*(){for(;!y;){const e=new q;if(f=e.resolve.bind(e),await e,y)break;for(;w.length>0;){const e=w.shift();if(""===e.trim())continue;const t=JSON.parse(e);"string"==typeof t.text&&Object.defineProperty(t,"toString",{enumerable:!1,value:()=>t.text}),yield t}}}();return Object.defineProperty(e,"start",{enumerable:!1,value:async t=>{const s=new TextEncoder;for await(const n of e)t.enqueue(s.encode(n));t.close()}}),t(e)}4===p.readyState&&(y=!0,g&&f?.())},p.onprogress=function(){if(!f)return;const e=p.responseText.slice(m);m=p.responseText.length;let t=!1;for(let s=0;s<e.length;s++)b+=e[s],"\n"===e[s]&&(t=!0,w.push(b),b="");t&&f()},p.addEventListener("load",async function(r){if(g)return;const h=await P(r.target);if(this._puterDriverRequestInfo&&globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:`${this._puterDriverRequestInfo.interface}::${this._puterDriverRequestInfo.method}`,params:{interface:this._puterDriverRequestInfo.interface,driver:this._puterDriverRequestInfo.driver,method:this._puterDriverRequestInfo.method,args:this._puterDriverRequestInfo.args},result:r.status>=400||!1===h?.success?null:h,error:r.status>=400||!1===h?.success?h:null}),401===r.status||"token_auth_failed"===h?.code){if("token_auth_failed"===h?.code&&"web"===puter.env)try{puter.resetAuthToken(),await puter.ui.authenticateWithPuter()}catch(e){return s({error:{code:"auth_canceled",message:"Authentication canceled"}})}return d&&"function"==typeof d&&d({status:401,message:"Unauthorized"}),s({status:401,message:"Unauthorized"})}if(r.status&&200!==r.status)return d(h),s(h);{if(!1===h.success&&"permission_denied"===h.error?.code)return(await puter.ui.requestPermission({permission:`driver:${n}:${i}`})).granted?B(e,t,s,n,i,o,a,c,l):(d(h),s(h));if(!1===h.success)return d(h),s(h);let r=void 0!==h.result?h.result:h;return l.transform&&(r=await l.transform(r)),t.success&&u(r),t(r)}}),p.addEventListener("error",function(e){return this._puterDriverRequestInfo&&globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:`${this._puterDriverRequestInfo.interface}::${this._puterDriverRequestInfo.method}`,params:{interface:this._puterDriverRequestInfo.interface,driver:this._puterDriverRequestInfo.driver,method:this._puterDriverRequestInfo.method,args:this._puterDriverRequestInfo.args},error:{message:"Network error occurred",event:e.type}}),D(d,s,this)}),p.send(JSON.stringify({interface:n,driver:r,test_mode:l?.test_mode,method:i,args:o,auth_token:puter.authToken}))}class q{static STATUS_PENDING={};static STATUS_RUNNING={};static STATUS_DONE={};constructor(){this.status_=this.constructor.STATUS_PENDING,this.donePromise=new Promise((e,t)=>{this.doneResolve=e,this.doneReject=t})}get status(){return this.status_}set status(e){this.status_=e,e===this.constructor.STATUS_DONE&&this.doneResolve()}resolve(e){this.status_=this.constructor.STATUS_DONE,this.doneResolve(e)}awaitDone(){return this.donePromise}then(e,t){return this.donePromise.then(e,t)}reject(e){this.status_=this.constructor.STATUS_DONE,this.doneReject(e)}onComplete(e){return this.then(e)}}async function N(e){const t=new q,s=new(globalThis.FileReader||S);return s.onloadend=()=>t.resolve(s.result),s.readAsDataURL(e),await t}function j(e){return new Promise((t,s)=>{const n=new(globalThis.FileReader||S);n.onload=function(e){t(e.target.result)},n.onerror=function(e){s(e)},n.readAsDataURL(e)})}const F=e=>{if("string"!=typeof e)return"aws-polly";const t=e.toLowerCase();return"openai"===t?"openai":["elevenlabs","eleven","11labs","11-labs","eleven-labs","elevenlabs-tts"].includes(t)?"elevenlabs":"aws"===t||"polly"===t||"aws-polly"===t?"aws-polly":e},z=["black-forest-labs/","stabilityai/","togethercomputer/","playgroundai/","runwayml/","lightricks/","sg161222/","wavymulder/","prompthero/","bytedance-seed/","hidream-ai/","lykon/","qwen/","rundiffusion/","google/","ideogram/"],W=["flux","kling","sd3","stable-diffusion","kolors"],X=["minimax/","google/","bytedance/","pixverse/","kwaivgi/","vidu/","wan-ai/"],V=class{constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}async listModels(e){const t=this.authToken?{Authorization:`Bearer ${this.authToken}`}:{},s=async()=>{const s=await fetch(`${this.APIOrigin}/puterai/chat/models/details`,{headers:t});if(!s.ok)return null;const n=await s.json(),r=Array.isArray(n?.models)?n.models:[];return e?r.filter(t=>t.provider===e):r};return await(async()=>{try{const e=await s();if(null!==e)return e}catch(e){}try{return await(async()=>{const t=await puter.drivers.call("puter-chat-completion","ai-chat","models"),s=Array.isArray(t?.result)?t.result:[];return e?s.filter(t=>t.provider===e):s})()}catch(e){return[]}})()}async listModelProviders(){const e=await this.listModels(),t=new Set;return(e??[]).forEach(e=>{e?.provider&&t.add(e.provider)}),Array.from(t)}img2txt=async(...e)=>{if(!e||0===e.length)throw{message:"Arguments are required",code:"arguments_required"};const t=e=>"undefined"!=typeof Blob&&(e instanceof Blob||"undefined"!=typeof File&&e instanceof File),s=e=>e&&"object"==typeof e&&!Array.isArray(e)&&!t(e);let n={};s(e[0])?n={...e[0]}:n.source=e[0];let r=!1;for(let t=1;t<e.length;t++){const i=e[t];"boolean"==typeof i?r=r||i:s(i)&&(n={...n,...i})}"boolean"==typeof n.testMode&&(r=n.testMode);const i=(e=>{if(!e)return"aws-textract";const t=String(e).toLowerCase();return["aws","textract","aws-textract"].includes(t)?"aws-textract":["mistral","mistral-ocr"].includes(t)?"mistral":"aws-textract"})(n.provider);if(delete n.provider,delete n.testMode,!n.source)throw{message:"Source is required",code:"source_required"};if(t(n.source)?n.source=await j(n.source):n.source?.source&&t(n.source.source)&&(n.source=await j(n.source.source)),"string"==typeof n.source&&n.source.startsWith("data:")&&n.source.length>10485760)throw{message:"Input size cannot be larger than 10485760",code:"input_too_large"};const o=U(["source"],"puter-ocr",i,"recognize",{test_mode:r??!1,transform:async e=>(e=>{if(!e)return"";if(Array.isArray(e.blocks)&&e.blocks.length){let t="";for(const s of e.blocks)"string"==typeof s?.text&&(s.type&&"text/textract:LINE"!==s.type&&!s.type.startsWith("text/")||(t+=`${s.text}\n`));if(t.trim())return t}if(Array.isArray(e.pages)&&e.pages.length){const t=e.pages.map(e=>(e?.markdown||"").trim()).filter(Boolean).join("\n\n");if(t.trim())return t}return"string"==typeof e.document_annotation?e.document_annotation:"string"==typeof e.text?e.text:""})(e)});return await o.call(this,n)};txt2speech=async(...e)=>{let t={},s=!1;if(!e)throw{message:"Arguments are required",code:"arguments_required"};if("string"==typeof e[0]&&(t={text:e[0]}),e[1]&&"object"==typeof e[1]&&!Array.isArray(e[1]))Object.assign(t,e[1]);else if(e[1]&&"string"==typeof e[1])t.language=e[1],e[2]&&"string"==typeof e[2]&&(t.voice=e[2]),e[3]&&"string"==typeof e[3]&&(t.engine=e[3]);else if(e[1]&&"boolean"!=typeof e[1])throw{message:'Second argument must be an options object or language string. Use: txt2speech("text", { voice: "name", engine: "type", language: "code" }) or txt2speech("text", "language", "voice", "engine")',code:"invalid_arguments"};if(!t.text)throw{message:"Text parameter is required",code:"text_required"};const n=["standard","neural","long-form","generative"];let r=F(t.provider);if(t.engine&&"openai"===F(t.engine)&&!t.provider&&(r="openai"),t.engine&&"elevenlabs"===F(t.engine)&&!t.provider&&(r="elevenlabs"),"openai"===r)t.model||"string"!=typeof t.engine||(t.model=t.engine),t.voice||(t.voice="alloy"),t.model||(t.model="gpt-4o-mini-tts"),t.response_format||(t.response_format="mp3"),delete t.engine;else if("elevenlabs"===r)t.voice||(t.voice="21m00Tcm4TlvDq8ikWAM"),t.model||"string"!=typeof t.engine||(t.model=t.engine),t.model||(t.model="eleven_multilingual_v2"),t.output_format||t.response_format||(t.output_format="mp3_44100_128"),t.response_format&&!t.output_format&&(t.output_format=t.response_format),delete t.engine;else{if(r="aws-polly",t.engine&&!n.includes(t.engine))throw{message:`Invalid engine. Must be one of: ${n.join(", ")}`,code:"invalid_engine"};t.voice||(t.voice="Joanna"),t.engine||(t.engine="standard"),t.language||(t.language="en-US")}if(t.text.length>3e3)throw{message:"Input size cannot be larger than 3000",code:"input_too_large"};for(let t=0;t<e.length;t++)if("boolean"==typeof e[t]&&!0===e[t]){s=!0;break}const i="openai"===r?"openai-tts":"elevenlabs"===r?"elevenlabs-tts":"aws-polly";return await U(["source"],"puter-tts",i,"synthesize",{responseType:"blob",test_mode:s??!1,transform:async e=>{let t;if("string"==typeof e)t=e;else if(e instanceof Blob)t=await N(e);else if(e instanceof ArrayBuffer){const s=new Blob([e]);t=await N(s)}else{if(!e||"object"!=typeof e||"function"!=typeof e.arrayBuffer)throw{message:"Unexpected audio response format",code:"invalid_audio_response"};{const s=await e.arrayBuffer(),n=new Blob([s],{type:e.type||void 0});t=await N(n)}}const s=new(globalThis.Audio||Object);return s.src=t,s.toString=()=>t,s.valueOf=()=>t,s}}).call(this,t)};speech2speech=async(...e)=>{if(!e||!e.length)throw{message:"Arguments are required",code:"arguments_required"};const t=async e=>e instanceof Blob?await j(e):e;let s={},n=!1;const r=e[0];if(!r||"object"!=typeof r||Array.isArray(r)||r instanceof Blob?s.audio=await t(r):s={...r},!e[1]||"object"!=typeof e[1]||Array.isArray(e[1])||e[1]instanceof Blob?"boolean"==typeof e[1]&&(n=e[1]):s={...s,...e[1]},"boolean"==typeof e[2]&&(n=e[2]),s.file&&(s.audio=await t(s.file),delete s.file),s.audio instanceof Blob&&(s.audio=await t(s.audio)),!s.audio)throw{message:"Audio input is required",code:"audio_required"};if("string"==typeof s.audio&&s.audio.startsWith("data:")){const e=s.audio.split(",")[1]||"",t=e.endsWith("==")?2:e.endsWith("=")?1:0;if(Math.floor(3*e.length/4)-t>26214400)throw{message:"Input size cannot be larger than 25 MB",code:"input_too_large"}}const i=((e={})=>{const t={...e};return!t.voiceId||t.voice||t.voice_id||(t.voice=t.voiceId),!t.modelId||t.model||t.model_id||(t.model=t.modelId),t.outputFormat&&!t.output_format&&(t.output_format=t.outputFormat),t.voiceSettings&&!t.voice_settings&&(t.voice_settings=t.voiceSettings),t.fileFormat&&!t.file_format&&(t.file_format=t.fileFormat),void 0!==t.removeBackgroundNoise&&void 0===t.remove_background_noise&&(t.remove_background_noise=t.removeBackgroundNoise),void 0!==t.optimizeStreamingLatency&&void 0===t.optimize_streaming_latency&&(t.optimize_streaming_latency=t.optimizeStreamingLatency),void 0!==t.enableLogging&&void 0===t.enable_logging&&(t.enable_logging=t.enableLogging),delete t.voiceId,delete t.modelId,delete t.outputFormat,delete t.voiceSettings,delete t.fileFormat,delete t.removeBackgroundNoise,delete t.optimizeStreamingLatency,delete t.enableLogging,t})({...s});return delete i.provider,await U(["audio"],"puter-speech2speech","elevenlabs-voice-changer","convert",{responseType:"blob",test_mode:n,transform:async e=>{let t;if("string"==typeof e)t=e;else if(e instanceof Blob)t=await N(e);else if(e instanceof ArrayBuffer){const s=new Blob([e]);t=await N(s)}else{if(!e||"object"!=typeof e||"function"!=typeof e.arrayBuffer)throw{message:"Unexpected audio response format",code:"invalid_audio_response"};{const s=await e.arrayBuffer(),n=new Blob([s],{type:e.type||void 0});t=await N(n)}}const s=new Audio(t);return s.toString=()=>t,s.valueOf=()=>t,s}}).call(this,i)};speech2txt=async(...e)=>{if(!e||!e.length)throw{message:"Arguments are required",code:"arguments_required"};const t=async e=>e instanceof Blob?await j(e):e;let s={},n=!1;const r=e[0];if(!r||"object"!=typeof r||Array.isArray(r)||r instanceof Blob?s.file=await t(r):s={...r},!e[1]||"object"!=typeof e[1]||Array.isArray(e[1])||e[1]instanceof Blob?"boolean"==typeof e[1]&&(n=e[1]):s={...s,...e[1]},"boolean"==typeof e[2]&&(n=e[2]),s.audio&&(s.file=await t(s.audio),delete s.audio),s.file instanceof Blob&&(s.file=await t(s.file)),!s.file)throw{message:"Audio input is required",code:"audio_required"};if("string"==typeof s.file&&s.file.startsWith("data:")){const e=s.file.split(",")[1]||"",t=e.endsWith("==")?2:e.endsWith("=")?1:0;if(Math.floor(3*e.length/4)-t>26214400)throw{message:"Input size cannot be larger than 25 MB",code:"input_too_large"}}const i=s.translate?"translate":"transcribe",o={...s};delete o.translate;const a=o.response_format;return await U([],"puter-speech2txt","openai-speech2txt",i,{test_mode:n,transform:async e=>"text"===a&&e&&"object"==typeof e&&"string"==typeof e.text?e.text:e}).call(this,o)};txt2speech=Object.assign(this.txt2speech,{listEngines:async(e={})=>{let t="aws-polly",s={};"string"==typeof e?t=F(e):e&&"object"==typeof e&&(t=F(e.provider)||t,s={...e},delete s.provider),"openai"===t&&(s.provider="openai"),"elevenlabs"===t&&(s.provider="elevenlabs");const n="openai"===t?"openai-tts":"elevenlabs"===t?"elevenlabs-tts":"aws-polly";return await U(["source"],"puter-tts",n,"list_engines",{responseType:"text"}).call(this,s)},listVoices:async e=>{let t="aws-polly",s={};return"string"==typeof e?s.engine=e:e&&"object"==typeof e&&(t=F(e.provider)||t,s={...e},delete s.provider),"openai"===t&&(s.provider="openai",delete s.engine),"elevenlabs"===t&&(s.provider="elevenlabs"),U(["source"],"puter-tts","openai"===t?"openai-tts":"elevenlabs"===t?"elevenlabs-tts":"aws-polly","list_voices",{responseType:"text"}).call(this,s)}});chat=async(...e)=>{let t={},s={},n=!1,r="openai-completion";if(!e)throw{message:"Arguments are required",code:"arguments_required"};if("string"==typeof e[0]&&(t={messages:[{content:e[0]}]}),"string"!=typeof e[0]||e[1]&&"boolean"!=typeof e[1])if("string"==typeof e[0]&&("string"==typeof e[1]||e[1]instanceof File))e[1]instanceof File&&(e[1]=await j(e[1])),t={vision:!0,messages:[{content:[e[0],{image_url:{url:e[1]}}]}]};else if("string"==typeof e[0]&&Array.isArray(e[1])){for(let t=0;t<e[1].length;t++)e[1][t]={image_url:{url:e[1][t]}};t={vision:!0,messages:[{content:[e[0],...e[1]]}]}}else Array.isArray(e[0])&&(t={messages:e[0]});else t={messages:[{content:e[0]}]};("boolean"==typeof e[1]&&!0===e[1]||"boolean"==typeof e[2]&&!0===e[2]||"boolean"==typeof e[3]&&!0===e[3])&&(n=!0);const i=e=>"object"==typeof e&&!Array.isArray(e)&&null!==e;for(let t=0;t<e.length;t++)if(i(e[t])){s=e[t];break}s.model&&(t.model=s.model),s.temperature&&(t.temperature=s.temperature),s.max_tokens&&(t.max_tokens=s.max_tokens),t.model=t.model??"",t.model&&t.model.startsWith("anthropic/")&&(t.model=t.model.replace("anthropic/","")),"claude-3-5-sonnet"===t.model&&(t.model="claude-3-5-sonnet-latest"),"claude-3-7-sonnet"!==t.model&&"claude"!==t.model||(t.model="claude-3-7-sonnet-latest"),"claude-sonnet-4"!==t.model&&"claude-sonnet-4-latest"!==t.model||(t.model="claude-sonnet-4-20250514"),"claude-opus-4"!==t.model&&"claude-opus-4-latest"!==t.model||(t.model="claude-opus-4-20250514"),"mistral"===t.model&&(t.model="mistral-large-latest"),"groq"===t.model&&(t.model="llama3-8b-8192"),"deepseek"===t.model&&(t.model="deepseek-chat"),"o1-mini"===t.model&&(t.model="openrouter:openai/o1-mini"),t.model&&t.model.startsWith("openai/")&&(t.model=t.model.replace("openai/",""),r="openai-completion"),(t.model.startsWith("agentica-org/")||t.model.startsWith("ai21/")||t.model.startsWith("aion-labs/")||t.model.startsWith("alfredpros/")||t.model.startsWith("allenai/")||t.model.startsWith("alpindale/")||t.model.startsWith("amazon/")||t.model.startsWith("anthracite-org/")||t.model.startsWith("arcee-ai/")||t.model.startsWith("arliai/")||t.model.startsWith("baidu/")||t.model.startsWith("bytedance/")||t.model.startsWith("cognitivecomputations/")||t.model.startsWith("cohere/")||t.model.startsWith("deepseek/")||t.model.startsWith("eleutherai/")||t.model.startsWith("google/")||t.model.startsWith("gryphe/")||t.model.startsWith("inception/")||t.model.startsWith("infermatic/")||t.model.startsWith("liquid/")||t.model.startsWith("mancer/")||t.model.startsWith("meta-llama/")||t.model.startsWith("microsoft/")||t.model.startsWith("minimax/")||t.model.startsWith("mistralai/")||t.model.startsWith("moonshotai/")||t.model.startsWith("morph/")||t.model.startsWith("neversleep/")||t.model.startsWith("nousresearch/")||t.model.startsWith("nvidia/")||t.model.startsWith("openrouter/")||t.model.startsWith("perplexity/")||t.model.startsWith("pygmalionai/")||t.model.startsWith("qwen/")||t.model.startsWith("raifle/")||t.model.startsWith("rekaai/")||t.model.startsWith("sao10k/")||t.model.startsWith("sarvamai/")||t.model.startsWith("scb10x/")||t.model.startsWith("shisa-ai/")||t.model.startsWith("sophosympatheia/")||t.model.startsWith("switchpoint/")||t.model.startsWith("tencent/")||t.model.startsWith("thedrummer/")||t.model.startsWith("thudm/")||t.model.startsWith("tngtech/")||t.model.startsWith("undi95/")||t.model.startsWith("x-ai/")||t.model.startsWith("z-ai/"))&&(t.model=`openrouter:${t.model}`),!t.model||t.model.startsWith("gpt-")?r="openai-completion":t.model.startsWith("claude-")?r="claude":"meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"===t.model||"meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo"===t.model||"meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo"===t.model||"google/gemma-2-27b-it"===t.model?r="together-ai":t.model.startsWith("mistral-")||t.model.startsWith("codestral-")||t.model.startsWith("pixtral-")||t.model.startsWith("magistral-")||t.model.startsWith("devstral-")||t.model.startsWith("mistral-ocr-")||t.model.startsWith("open-mistral-")?r="mistral":["distil-whisper-large-v3-en","gemma2-9b-it","gemma-7b-it","llama-3.1-70b-versatile","llama-3.1-8b-instant","llama3-70b-8192","llama3-8b-8192","llama3-groq-70b-8192-tool-use-preview","llama3-groq-8b-8192-tool-use-preview","llama-guard-3-8b","mixtral-8x7b-32768","whisper-large-v3"].includes(t.model)?r="groq":"grok-beta"===t.model?r="xai":t.model.startsWith("grok-")?r="openrouter":"deepseek-chat"===t.model||"deepseek-reasoner"===t.model?r="deepseek":"gemini-1.5-flash"===t.model||"gemini-2.0-flash"===t.model||"gemini-2.5-flash"===t.model||"gemini-2.5-flash-lite"===t.model||"gemini-2.0-flash-lite"===t.model||"gemini-3-pro-preview"===t.model||"gemini-2.5-pro"===t.model?r="gemini":t.model.startsWith("openrouter:")?r="openrouter":t.model.startsWith("ollama:")&&(r="ollama"),void 0!==s.stream&&"boolean"==typeof s.stream&&(t.stream=s.stream),s.driver&&(r=s.driver);const o=["tools","response","reasoning","reasoning_effort","text","verbosity"];for(const e of o)s[e]&&(t[e]=s[e]);return""===t.model&&delete t.model,await U(["messages"],"puter-chat-completion",r,"complete",{test_mode:n??!1,transform:async e=>(e.toString=()=>e.message?.content,e.valueOf=()=>e.message?.content,e)}).call(this,t)};txt2img=async(...e)=>{let t={},s=!1;if(!e)throw{message:"Arguments are required",code:"arguments_required"};"string"==typeof e[0]&&(t={prompt:e[0]}),"boolean"==typeof e[1]&&!0===e[1]&&(s=!0),"string"==typeof e[0]&&"object"==typeof e[1]&&(t=e[1],t.prompt=e[0]),"object"==typeof e[0]&&(t=e[0]);let n="openai-image-generation";"nano-banana"===t.model&&(t.model="gemini-2.5-flash-image-preview"),"nano-banana-pro"===t.model&&(t.model="gemini-3-pro-image-preview");const r="string"==typeof t.driver?t.driver:void 0,i="string"==typeof t.provider?t.provider:"string"==typeof t.service?t.service:void 0,o="string"==typeof i?i.toLowerCase():void 0,a="string"==typeof t.model?t.model.toLowerCase():"",c="string"==typeof t.model&&(z.some(e=>a.startsWith(e))||W.some(e=>a.includes(e)));return r?n=r:"gemini"===o?n="gemini-image-generation":"together"===o||"together-ai"===o?n="together-image-generation":"gemini-2.5-flash-image-preview"===t.model||"gemini-3-pro-image-preview"===t.model?n="gemini-image-generation":c&&(n="together-image-generation"),await U(["prompt"],"puter-image-generation",n,"generate",{responseType:"blob",test_mode:s??!1,transform:async e=>{let t;if("string"==typeof e)t=e;else if(e instanceof Blob)t=await N(e);else if(e instanceof ArrayBuffer){const s=new Blob([e]);t=await N(s)}else{if(!e||"object"!=typeof e||"function"!=typeof e.arrayBuffer)throw{message:"Unexpected image response format",code:"invalid_image_response"};{const s=await e.arrayBuffer(),n=new Blob([s],{type:e.type||void 0});t=await N(n)}}let s=new(globalThis.Image||Object);return s.src=t,s.toString=()=>s.src,s.valueOf=()=>s.src,s}}).call(this,t)};txt2vid=async(...e)=>{let t={},s=!1;if(!e)throw{message:"Arguments are required",code:"arguments_required"};if("string"==typeof e[0]&&(t={prompt:e[0]}),"boolean"==typeof e[1]&&!0===e[1]&&(s=!0),"string"==typeof e[0]&&"object"==typeof e[1]&&(t=e[1],t.prompt=e[0]),"object"==typeof e[0]&&(t=e[0]),!t.prompt)throw{message:"Prompt parameter is required",code:"prompt_required"};t.model||(t.model="sora-2"),void 0!==t.duration&&void 0===t.seconds&&(t.seconds=t.duration);let n="openai-video-generation";const r="string"==typeof t.driver?t.driver:void 0,i=r?r.toLowerCase():void 0,o="string"==typeof t.provider?t.provider:"string"==typeof t.service?t.service:void 0,a="string"==typeof o?o.toLowerCase():void 0,c="string"==typeof t.model?t.model.toLowerCase():"",l="string"==typeof t.model&&X.some(e=>c.startsWith(e));return"together"===i||"together-ai"===i||"together-video-generation"===i?n="together-video-generation":"openai"===i?n="openai-video-generation":r?n=r:("together"===a||"together-ai"===a||l)&&(n="together-video-generation"),await U(["prompt"],"puter-video-generation",n,"generate",{responseType:"blob",test_mode:s??!1,transform:async e=>{let t=null,s=null;if(e instanceof Blob?(t=await N(e),s=e.type||"video/mp4"):"string"==typeof e?t=e:e&&"object"==typeof e&&(t=e.asset_url||e.url||e.href||null,s=e.mime_type||e.content_type||null),!t)return e;const n=globalThis.document?.createElement("video")||{setAttribute:()=>{}};return n.src=t,n.controls=!0,n.preload="metadata",s&&n.setAttribute("data-mime-type",s),n.setAttribute("data-source",t),n.toString=()=>n.src,n.valueOf=()=>n.src,n}}).call(this,t)}},G=class{constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}list=async(...e)=>{let t={};return"object"==typeof e[0]&&null!==e[0]&&(t.params=e[0]),t.predicate=["user-can-edit"],U(["uid"],"puter-apps",void 0,"select").call(this,t)};create=async(...e)=>{let t={};if("string"==typeof e[0]){let s=e[1],n=e[2]??e[0];t={object:{name:e[0],index_url:s,title:n}}}else if("object"==typeof e[0]&&null!==e[0]){let s=e[0];t={object:{name:s.name,index_url:s.indexURL,title:s.title??s.name,description:s.description,icon:s.icon,maximize_on_start:s.maximizeOnStart,background:s.background,filetype_associations:s.filetypeAssociations,metadata:s.metadata},options:{dedupe_name:s.dedupeName??!1}}}if(!t.object.name)throw{success:!1,error:{code:"invalid_request",message:"Name is required"}};if(!t.object.index_url)throw{success:!1,error:{code:"invalid_request",message:"Index URL is required"}};return await U(["object"],"puter-apps",void 0,"create").call(this,t)};update=async(...e)=>{let t={};if(Array.isArray(e)&&"string"==typeof e[0]){let s=e[1],n={name:s.name,index_url:s.indexURL,title:s.title,description:s.description,icon:s.icon,maximize_on_start:s.maximizeOnStart,background:s.background,filetype_associations:s.filetypeAssociations,metadata:s.metadata};t={id:{name:e[0]},object:n}}return await U(["object"],"puter-apps",void 0,"update").call(this,t)};get=async(...e)=>{let t={};return Array.isArray(e)&&"string"==typeof e[0]&&("object"==typeof e[1]&&null!==e[1]&&(t.params=e[1]),t.id={name:e[0]}),"object"==typeof e[0]&&null!==e[0]&&(t.params=e[0]),U(["uid"],"puter-apps",void 0,"read").call(this,t)};delete=async(...e)=>{let t={};return Array.isArray(e)&&"string"==typeof e[0]&&(t={id:{name:e[0]}}),U(["uid"],"puter-apps",void 0,"delete").call(this,t)};getDeveloperProfile=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{success:e[0],error:e[1]},new Promise((t,s)=>{let n;return n="object"==typeof e[0]&&null!==e[0]?e[0]:{success:e[0],error:e[1]},new Promise((e,t)=>{const s=C("/get-dev-profile",puter.APIOrigin,puter.authToken,"get");R(s,n.success,n.error,e,t),s.send()})})}},K=class{#t=1;constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}signIn=e=>(e=e||{},new Promise((t,s)=>{let n=this.#t++;var r=screen.width/2-300,i=screen.height/2-300;const o=window.open(`${puter.defaultGUIOrigin}/action/sign-in?embedded_in_popup=true&msg_id=${n}${window.crossOriginIsolated?"&cross_origin_isolated=true":""}${e.attempt_temp_user_creation?"&attempt_temp_user_creation=true":""}`,"Puter",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=600, top=${i}, left=${r}`),a=setInterval(()=>{o.closed&&(clearInterval(a),window.removeEventListener("message",c),s({error:"auth_window_closed",msg:"Authentication window was closed by the user without completing the process."}))},100);function c(e){e.data.msg_id==n&&(clearInterval(a),delete e.data.msg_id,delete e.data.msg,e.data.success?(puter.setAuthToken(e.data.token),t(e.data)):s(e.data),window.removeEventListener("message",c))}window.addEventListener("message",c)}));isSignedIn=()=>!!puter.authToken;getUser=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{success:e[0],error:e[1]},new Promise((e,s)=>{const n=C("/whoami",puter.APIOrigin,puter.authToken,"get");R(n,t.success,t.error,e,s),n.send()})};signOut=()=>{puter.resetAuthToken()};async whoami(){try{const e=await fetch(`${this.APIOrigin}/whoami`,{headers:{Authorization:`Bearer ${this.authToken}`}}),t=await e.json();return globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"whoami",params:{},result:t}),t}catch(e){throw globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"whoami",params:{},error:{message:e.message||e.toString(),stack:e.stack}}),e}}async getMonthlyUsage(){try{const e=await fetch(`${this.APIOrigin}/metering/usage`,{headers:{Authorization:`Bearer ${this.authToken}`}}),t=await e.json();return globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"usage",params:{},result:t}),t}catch(e){throw globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"usage",params:{},error:{message:e.message||e.toString(),stack:e.stack}}),e}}async getDetailedAppUsage(e){if(!e)throw new Error("appId is required");try{const t=await fetch(`${this.APIOrigin}/metering/usage/${e}`,{headers:{Authorization:`Bearer ${this.authToken}`}}),s=await t.json();return globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"detailed_app_usage",params:{appId:e},result:s}),s}catch(t){throw globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"detailed_app_usage",params:{appId:e},error:{message:t.message||t.toString(),stack:t.stack}}),t}}async getGlobalUsage(){try{const e=await fetch(`${this.APIOrigin}/metering/globalUsage`,{headers:{Authorization:`Bearer ${this.authToken}`}}),t=await e.json();return globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"global_usage",params:{},result:t}),t}catch(e){throw globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"auth",operation:"global_usage",params:{},error:{message:e.message||e.toString(),stack:e.stack}}),e}}};class H{constructor(e,t){this.context=e,this.parameters=t,this._init()}_init(){let e=new URL(location.href).searchParams.get("enabled_logs");e||(e=""),e=e.split(";");for(const t of e)""!==t&&this.context.puter.logger.on(t);globalThis.addEventListener("message",async e=>{e.source===globalThis.parent&&e.data.$&&"puterjs-debug"===e.data.$&&(console.log("Got a puter.js debug event!",e.data),"log.on"===e.data.cmd&&(console.log("Got instruction to turn logs on!"),this.context.puter.logger.on(e.data.category)))})}}class Y{constructor({context:e}){this.context=e,this.response_handlers=this.constructor.response_handlers}static response_handlers={"application/x-ndjson":async e=>async function*(e){const t=e.getReader();let s,n;for(;!n&&(({value:s,done:n}=await t.read()),!n);){const e=(new TextDecoder).decode(s).split("\n");for(const t of e)""!==t.trim()&&(yield JSON.parse(t))}}(e.body),"application/json":async e=>await e.json(),"application/octet-stream":async e=>await e.blob()};async call({driver:e,method_name:t,parameters:s}){try{const n=await fetch(`${this.context.APIOrigin}/drivers/call`,{headers:{"Content-Type":"text/plain;actually=json"},method:"POST",body:JSON.stringify({interface:e.iface_name,...e.service_name?{service:e.service_name}:{},method:t,args:s,auth_token:this.context.authToken})}),r=n.headers.get("content-type").split(";")[0].trim(),i=this.response_handlers[r];if(!i){const i=`unrecognized content type: ${r}`;throw console.error(i),console.error("creating blob so dev tools shows response..."),await n.blob(),globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:`${e.iface_name}::${t}`,params:{interface:e.iface_name,driver:e.service_name||e.iface_name,method:t,args:s},error:{message:i}}),new Error(i)}const o=await i(n);return globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:`${e.iface_name}::${t}`,params:{interface:e.iface_name,driver:e.service_name||e.iface_name,method:t,args:s},result:o}),o}catch(n){throw globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:`${e.iface_name}::${t}`,params:{interface:e.iface_name,driver:e.service_name||e.iface_name,method:t,args:s},error:{message:n.message||n.toString(),stack:n.stack}}),n}}}class Q{constructor({iface:e,iface_name:t,service_name:s,call_backend:n}){this.iface=e,this.iface_name=t,this.service_name=s,this.call_backend=n}async call(e,t){return await this.call_backend.call({driver:this,method_name:e,parameters:t})}}const Z=class{constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID,this.drivers_={},this.context={},Object.defineProperty(this.context,"authToken",{get:()=>this.authToken}),Object.defineProperty(this.context,"APIOrigin",{get:()=>this.APIOrigin})}_init({puter:e}){e.call=this.call.bind(this)}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}async list(){try{const e=await fetch(`${this.APIOrigin}/lsmod`,{headers:{Authorization:`Bearer ${this.authToken}`},method:"POST"}),t=await e.json();return globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:"list",params:{},result:t.interfaces}),t.interfaces}catch(e){throw globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"drivers",operation:"list",params:{},error:{message:e.message||e.toString(),stack:e.stack}}),e}}async get(e,t){t||(t=e);const s=`${e}:${t}`;return this.drivers_[s]?this.drivers_[s]:this.drivers_[s]=new Q({call_backend:new Y({context:this.context}),iface_name:e,service_name:t})}async call(...e){let t,s,n,r;4===e.length?[t,s,n,r]=e:3===e.length?[t,n,r]=e:2===e.length&&([t,r]=e,n=t);const i=await this.get(t,s);return await i.call(n,r)}},J=Object.create(null);J.open="0",J.close="1",J.ping="2",J.pong="3",J.message="4",J.upgrade="5",J.noop="6";const $=Object.create(null);Object.keys(J).forEach(e=>{$[J[e]]=e});const ee={type:"error",data:"parser error"},te="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),se="function"==typeof ArrayBuffer,ne=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,re=({type:e,data:t},s,n)=>te&&t instanceof Blob?s?n(t):ie(t,n):se&&(t instanceof ArrayBuffer||ne(t))?s?n(t):ie(new Blob([t]),n):n(J[e]+(t||"")),ie=(e,t)=>{const s=new FileReader;return s.onload=function(){const e=s.result.split(",")[1];t("b"+(e||""))},s.readAsDataURL(e)};function oe(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let ae;const ce="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let e=0;e<64;e++)ce["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(e)]=e;const le="function"==typeof ArrayBuffer,he=(e,t)=>{if("string"!=typeof e)return{type:"message",data:de(e,t)};const s=e.charAt(0);return"b"===s?{type:"message",data:ue(e.substring(1),t)}:$[s]?e.length>1?{type:$[s],data:e.substring(1)}:{type:$[s]}:ee},ue=(e,t)=>{if(le){const s=(e=>{let t,s,n,r,i,o=.75*e.length,a=e.length,c=0;"="===e[e.length-1]&&(o--,"="===e[e.length-2]&&o--);const l=new ArrayBuffer(o),h=new Uint8Array(l);for(t=0;t<a;t+=4)s=ce[e.charCodeAt(t)],n=ce[e.charCodeAt(t+1)],r=ce[e.charCodeAt(t+2)],i=ce[e.charCodeAt(t+3)],h[c++]=s<<2|n>>4,h[c++]=(15&n)<<4|r>>2,h[c++]=(3&r)<<6|63&i;return l})(e);return de(s,t)}return{base64:!0,data:e}},de=(e,t)=>"blob"===t?e instanceof Blob?e:new Blob([e]):e instanceof ArrayBuffer?e:e.buffer,pe=String.fromCharCode(30);function ge(){return new TransformStream({transform(e,t){!function(e,t){te&&e.data instanceof Blob?e.data.arrayBuffer().then(oe).then(t):se&&(e.data instanceof ArrayBuffer||ne(e.data))?t(oe(e.data)):re(e,!1,e=>{ae||(ae=new TextEncoder),t(ae.encode(e))})}(e,s=>{const n=s.length;let r;if(n<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,n);else if(n<65536){r=new Uint8Array(3);const e=new DataView(r.buffer);e.setUint8(0,126),e.setUint16(1,n)}else{r=new Uint8Array(9);const e=new DataView(r.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(n))}e.data&&"string"!=typeof e.data&&(r[0]|=128),t.enqueue(r),t.enqueue(s)})}})}let fe;function me(e){return e.reduce((e,t)=>e+t.length,0)}function ye(e,t){if(e[0].length===t)return e.shift();const s=new Uint8Array(t);let n=0;for(let r=0;r<t;r++)s[r]=e[0][n++],n===e[0].length&&(e.shift(),n=0);return e.length&&n<e[0].length&&(e[0]=e[0].slice(n)),s}function be(e){if(e)return function(e){for(var t in be.prototype)e[t]=be.prototype[t];return e}(e)}be.prototype.on=be.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},be.prototype.once=function(e,t){function s(){this.off(e,s),t.apply(this,arguments)}return s.fn=t,this.on(e,s),this},be.prototype.off=be.prototype.removeListener=be.prototype.removeAllListeners=be.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var s,n=this._callbacks["$"+e];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var r=0;r<n.length;r++)if((s=n[r])===t||s.fn===t){n.splice(r,1);break}return 0===n.length&&delete this._callbacks["$"+e],this},be.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),s=this._callbacks["$"+e],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(s){n=0;for(var r=(s=s.slice(0)).length;n<r;++n)s[n].apply(this,t)}return this},be.prototype.emitReserved=be.prototype.emit,be.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},be.prototype.hasListeners=function(e){return!!this.listeners(e).length};const we="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function ve(e,...t){return t.reduce((t,s)=>(e.hasOwnProperty(s)&&(t[s]=e[s]),t),{})}const _e=we.setTimeout,ke=we.clearTimeout;function Ae(e,t){t.useNativeTimers?(e.setTimeoutFn=_e.bind(we),e.clearTimeoutFn=ke.bind(we)):(e.setTimeoutFn=we.setTimeout.bind(we),e.clearTimeoutFn=we.clearTimeout.bind(we))}class Te extends Error{constructor(e,t,s){super(e),this.description=t,this.context=s,this.type="TransportError"}}class xe extends be{constructor(e){super(),this.writable=!1,Ae(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,s){return super.emitReserved("error",new Te(e,t,s)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(e){"open"===this.readyState&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=he(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){const e=this.opts.hostname;return-1===e.indexOf(":")?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(e){const t=function(e){let t="";for(let s in e)e.hasOwnProperty(s)&&(t.length&&(t+="&"),t+=encodeURIComponent(s)+"="+encodeURIComponent(e[s]));return t}(e);return t.length?"?"+t:""}}const Ie="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),Ee={};let Se,Pe=0,Oe=0;function Ce(e){let t="";do{t=Ie[e%64]+t,e=Math.floor(e/64)}while(e>0);return t}function De(){const e=Ce(+new Date);return e!==Se?(Pe=0,Se=e):e+"."+Ce(Pe++)}for(;Oe<64;Oe++)Ee[Ie[Oe]]=Oe;let Re=!1;try{Re="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(J){}const Le=Re;function Me(e){const t=e.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!t||Le))return new XMLHttpRequest}catch(e){}if(!t)try{return new(we[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}}function Ue(){}const Be=null!=new Me({xdomain:!1}).responseType;class qe extends be{constructor(e,t){super(),Ae(this,t),this.opts=t,this.method=t.method||"GET",this.uri=e,this.data=void 0!==t.data?t.data:null,this.create()}create(){var e;const t=ve(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd;const s=this.xhr=new Me(t);try{s.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){s.setDisableHeaderCheck&&s.setDisableHeaderCheck(!0);for(let e in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(e)&&s.setRequestHeader(e,this.opts.extraHeaders[e])}}catch(e){}if("POST"===this.method)try{s.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{s.setRequestHeader("Accept","*/*")}catch(e){}null===(e=this.opts.cookieJar)||void 0===e||e.addCookies(s),"withCredentials"in s&&(s.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(s.timeout=this.opts.requestTimeout),s.onreadystatechange=()=>{var e;3===s.readyState&&(null===(e=this.opts.cookieJar)||void 0===e||e.parseCookies(s)),4===s.readyState&&(200===s.status||1223===s.status?this.onLoad():this.setTimeoutFn(()=>{this.onError("number"==typeof s.status?s.status:0)},0))},s.send(this.data)}catch(e){return void this.setTimeoutFn(()=>{this.onError(e)},0)}"undefined"!=typeof document&&(this.index=qe.requestsCount++,qe.requests[this.index]=this)}onError(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}cleanup(e){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=Ue,e)try{this.xhr.abort()}catch(e){}"undefined"!=typeof document&&delete qe.requests[this.index],this.xhr=null}}onLoad(){const e=this.xhr.responseText;null!==e&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}function Ne(){for(let e in qe.requests)qe.requests.hasOwnProperty(e)&&qe.requests[e].abort()}qe.requestsCount=0,qe.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",Ne):"function"==typeof addEventListener&&addEventListener("onpagehide"in we?"pagehide":"unload",Ne,!1));const je="function"==typeof Promise&&"function"==typeof Promise.resolve?e=>Promise.resolve().then(e):(e,t)=>t(e,0),Fe=we.WebSocket||we.MozWebSocket,ze="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),We={websocket:class extends xe{constructor(e){super(e),this.supportsBinary=!e.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const e=this.uri(),t=this.opts.protocols,s=ze?{}:ve(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=ze?new Fe(e,t,s):t?new Fe(e,t):new Fe(e)}catch(e){return this.emitReserved("error",e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const s=e[t],n=t===e.length-1;re(s,this.supportsBinary,e=>{try{this.ws.send(e)}catch(e){}n&&je(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=De()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}check(){return!!Fe}},webtransport:class extends xe{get name(){return"webtransport"}doOpen(){"function"==typeof WebTransport&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(e=>{const t=function(e,t){fe||(fe=new TextDecoder);const s=[];let n=0,r=-1,i=!1;return new TransformStream({transform(o,a){for(s.push(o);;){if(0===n){if(me(s)<1)break;const e=ye(s,1);i=!(128&~e[0]),r=127&e[0],n=r<126?3:126===r?1:2}else if(1===n){if(me(s)<2)break;const e=ye(s,2);r=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),n=3}else if(2===n){if(me(s)<8)break;const e=ye(s,8),t=new DataView(e.buffer,e.byteOffset,e.length),i=t.getUint32(0);if(i>Math.pow(2,21)-1){a.enqueue(ee);break}r=i*Math.pow(2,32)+t.getUint32(4),n=3}else{if(me(s)<r)break;const e=ye(s,r);a.enqueue(he(i?e:fe.decode(e),t)),n=0}if(0===r||r>e){a.enqueue(ee);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),s=e.readable.pipeThrough(t).getReader(),n=ge();n.readable.pipeTo(e.writable),this.writer=n.writable.getWriter();const r=()=>{s.read().then(({done:e,value:t})=>{e||(this.onPacket(t),r())}).catch(e=>{})};r();const i={type:"open"};this.query.sid&&(i.data=`{"sid":"${this.query.sid}"}`),this.writer.write(i).then(()=>this.onOpen())})}))}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const s=e[t],n=t===e.length-1;this.writer.write(s).then(()=>{n&&je(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;null===(e=this.transport)||void 0===e||e.close()}},polling:class extends xe{constructor(e){if(super(e),this.polling=!1,"undefined"!=typeof location){const t="https:"===location.protocol;let s=location.port;s||(s=t?"443":"80"),this.xd="undefined"!=typeof location&&e.hostname!==location.hostname||s!==e.port}const t=e&&e.forceBase64;this.supportsBinary=Be&&!t,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(e){this.readyState="pausing";const t=()=>{this.readyState="paused",e()};if(this.polling||!this.writable){let e=0;this.polling&&(e++,this.once("pollComplete",function(){--e||t()})),this.writable||(e++,this.once("drain",function(){--e||t()}))}else t()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){((e,t)=>{const s=e.split(pe),n=[];for(let e=0;e<s.length;e++){const r=he(s[e],t);if(n.push(r),"error"===r.type)break}return n})(e,this.socket.binaryType).forEach(e=>{if("opening"===this.readyState&&"open"===e.type&&this.onOpen(),"close"===e.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(e)}),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}doClose(){const e=()=>{this.write([{type:"close"}])};"open"===this.readyState?e():this.once("open",e)}write(e){this.writable=!1,((e,t)=>{const s=e.length,n=new Array(s);let r=0;e.forEach((e,i)=>{re(e,!1,e=>{n[i]=e,++r===s&&t(n.join(pe))})})})(e,e=>{this.doWrite(e,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=De()),this.supportsBinary||t.sid||(t.b64=1),this.createUri(e,t)}request(e={}){return Object.assign(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new qe(this.uri(),e)}doWrite(e,t){const s=this.request({method:"POST",data:e});s.on("success",t),s.on("error",(e,t)=>{this.onError("xhr post error",e,t)})}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(e,t)=>{this.onError("xhr poll error",e,t)}),this.pollXhr=e}}},Xe=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Ve=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Ge(e){const t=e,s=e.indexOf("["),n=e.indexOf("]");-1!=s&&-1!=n&&(e=e.substring(0,s)+e.substring(s,n).replace(/:/g,";")+e.substring(n,e.length));let r=Xe.exec(e||""),i={},o=14;for(;o--;)i[Ve[o]]=r[o]||"";return-1!=s&&-1!=n&&(i.source=t,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=function(e,t){const s=t.replace(/\/{2,9}/g,"/").split("/");return"/"!=t.slice(0,1)&&0!==t.length||s.splice(0,1),"/"==t.slice(-1)&&s.splice(s.length-1,1),s}(0,i.path),i.queryKey=function(e,t){const s={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(e,t,n){t&&(s[t]=n)}),s}(0,i.query),i}class Ke extends be{constructor(e,t={}){super(),this.binaryType="arraybuffer",this.writeBuffer=[],e&&"object"==typeof e&&(t=e,e=null),e?(e=Ge(e),t.hostname=e.host,t.secure="https"===e.protocol||"wss"===e.protocol,t.port=e.port,e.query&&(t.query=e.query)):t.host&&(t.hostname=Ge(t.host).host),Ae(this,t),this.secure=null!=t.secure?t.secure:"undefined"!=typeof location&&"https:"===location.protocol,t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=t.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=t.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(e){let t={},s=e.split("&");for(let e=0,n=s.length;e<n;e++){let n=s[e].split("=");t[decodeURIComponent(n[0])]=decodeURIComponent(n[1])}return t}(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,"function"==typeof addEventListener&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);const s=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new We[e](s)}open(){let e;if(this.opts.rememberUpgrade&&Ke.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))e="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);e=this.transports[0]}this.readyState="opening";try{e=this.createTransport(e)}catch(e){return this.transports.shift(),void this.open()}e.open(),this.setTransport(e)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",e=>this.onClose("transport close",e))}probe(e){let t=this.createTransport(e),s=!1;Ke.priorWebsocketSuccess=!1;const n=()=>{s||(t.send([{type:"ping",data:"probe"}]),t.once("packet",e=>{if(!s)if("pong"===e.type&&"probe"===e.data){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;Ke.priorWebsocketSuccess="websocket"===t.name,this.transport.pause(()=>{s||"closed"!==this.readyState&&(l(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{const e=new Error("probe error");e.transport=t.name,this.emitReserved("upgradeError",e)}}))};function r(){s||(s=!0,l(),t.close(),t=null)}const i=e=>{const s=new Error("probe error: "+e);s.transport=t.name,r(),this.emitReserved("upgradeError",s)};function o(){i("transport closed")}function a(){i("socket closed")}function c(e){t&&e.name!==t.name&&r()}const l=()=>{t.removeListener("open",n),t.removeListener("error",i),t.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};t.once("open",n),t.once("error",i),t.once("close",o),this.once("close",a),this.once("upgrading",c),-1!==this.upgrades.indexOf("webtransport")&&"webtransport"!==e?this.setTimeoutFn(()=>{s||t.open()},200):t.open()}onOpen(){if(this.readyState="open",Ke.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade){let e=0;const t=this.upgrades.length;for(;e<t;e++)this.probe(this.upgrades[e])}}onPacket(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data)}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let e=1;for(let s=0;s<this.writeBuffer.length;s++){const n=this.writeBuffer[s].data;if(n&&(e+="string"==typeof(t=n)?function(e){let t=0,s=0;for(let n=0,r=e.length;n<r;n++)t=e.charCodeAt(n),t<128?s+=1:t<2048?s+=2:t<55296||t>=57344?s+=3:(n++,s+=4);return s}(t):Math.ceil(1.33*(t.byteLength||t.size))),s>0&&e>this.maxPayload)return this.writeBuffer.slice(0,s);e+=2}var t;return this.writeBuffer}write(e,t,s){return this.sendPacket("message",e,t,s),this}send(e,t,s){return this.sendPacket("message",e,t,s),this}sendPacket(e,t,s,n){if("function"==typeof t&&(n=t,t=void 0),"function"==typeof s&&(n=s,s=null),"closing"===this.readyState||"closed"===this.readyState)return;(s=s||{}).compress=!1!==s.compress;const r={type:e,data:t,options:s};this.emitReserved("packetCreate",r),this.writeBuffer.push(r),n&&this.once("flush",n),this.flush()}close(){const e=()=>{this.onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},s=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?s():e()}):this.upgrading?s():e()),this}onError(e){Ke.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,t){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const t=[];let s=0;const n=e.length;for(;s<n;s++)~this.transports.indexOf(e[s])&&t.push(e[s]);return t}}Ke.protocol=4;const He="function"==typeof ArrayBuffer,Ye=Object.prototype.toString,Qe="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Ye.call(Blob),Ze="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===Ye.call(File);function Je(e){return He&&(e instanceof ArrayBuffer||(e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer)(e))||Qe&&e instanceof Blob||Ze&&e instanceof File}function $e(e,t){if(!e||"object"!=typeof e)return!1;if(Array.isArray(e)){for(let t=0,s=e.length;t<s;t++)if($e(e[t]))return!0;return!1}if(Je(e))return!0;if(e.toJSON&&"function"==typeof e.toJSON&&1===arguments.length)return $e(e.toJSON(),!0);for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&$e(e[t]))return!0;return!1}function et(e){const t=[],s=e.data,n=e;return n.data=tt(s,t),n.attachments=t.length,{packet:n,buffers:t}}function tt(e,t){if(!e)return e;if(Je(e)){const s={_placeholder:!0,num:t.length};return t.push(e),s}if(Array.isArray(e)){const s=new Array(e.length);for(let n=0;n<e.length;n++)s[n]=tt(e[n],t);return s}if("object"==typeof e&&!(e instanceof Date)){const s={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(s[n]=tt(e[n],t));return s}return e}function st(e,t){return e.data=nt(e.data,t),delete e.attachments,e}function nt(e,t){if(!e)return e;if(e&&!0===e._placeholder){if("number"==typeof e.num&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}if(Array.isArray(e))for(let s=0;s<e.length;s++)e[s]=nt(e[s],t);else if("object"==typeof e)for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(e[s]=nt(e[s],t));return e}const rt=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var it;function ot(e){return"[object Object]"===Object.prototype.toString.call(e)}!function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"}(it||(it={}));class at extends be{constructor(e){super(),this.reviver=e}add(e){let t;if("string"==typeof e){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);const s=t.type===it.BINARY_EVENT;s||t.type===it.BINARY_ACK?(t.type=s?it.EVENT:it.ACK,this.reconstructor=new ct(t),0===t.attachments&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else{if(!Je(e)&&!e.base64)throw new Error("Unknown type: "+e);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t))}}decodeString(e){let t=0;const s={type:Number(e.charAt(0))};if(void 0===it[s.type])throw new Error("unknown packet type "+s.type);if(s.type===it.BINARY_EVENT||s.type===it.BINARY_ACK){const n=t+1;for(;"-"!==e.charAt(++t)&&t!=e.length;);const r=e.substring(n,t);if(r!=Number(r)||"-"!==e.charAt(t))throw new Error("Illegal attachments");s.attachments=Number(r)}if("/"===e.charAt(t+1)){const n=t+1;for(;++t&&","!==e.charAt(t)&&t!==e.length;);s.nsp=e.substring(n,t)}else s.nsp="/";const n=e.charAt(t+1);if(""!==n&&Number(n)==n){const n=t+1;for(;++t;){const s=e.charAt(t);if(null==s||Number(s)!=s){--t;break}if(t===e.length)break}s.id=Number(e.substring(n,t+1))}if(e.charAt(++t)){const n=this.tryParse(e.substr(t));if(!at.isPayloadValid(s.type,n))throw new Error("invalid payload");s.data=n}return s}tryParse(e){try{return JSON.parse(e,this.reviver)}catch(e){return!1}}static isPayloadValid(e,t){switch(e){case it.CONNECT:return ot(t);case it.DISCONNECT:return void 0===t;case it.CONNECT_ERROR:return"string"==typeof t||ot(t);case it.EVENT:case it.BINARY_EVENT:return Array.isArray(t)&&("number"==typeof t[0]||"string"==typeof t[0]&&-1===rt.indexOf(t[0]));case it.ACK:case it.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class ct{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const e=st(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}var lt=Object.freeze({__proto__:null,protocol:5,get PacketType(){return it},Encoder:class{constructor(e){this.replacer=e}encode(e){return e.type!==it.EVENT&&e.type!==it.ACK||!$e(e)?[this.encodeAsString(e)]:this.encodeAsBinary({type:e.type===it.EVENT?it.BINARY_EVENT:it.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id})}encodeAsString(e){let t=""+e.type;return e.type!==it.BINARY_EVENT&&e.type!==it.BINARY_ACK||(t+=e.attachments+"-"),e.nsp&&"/"!==e.nsp&&(t+=e.nsp+","),null!=e.id&&(t+=e.id),null!=e.data&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){const t=et(e),s=this.encodeAsString(t.packet),n=t.buffers;return n.unshift(s),n}},Decoder:at});function ht(e,t,s){return e.on(t,s),function(){e.off(t,s)}}const ut=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class dt extends be{constructor(e,t,s){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,s&&s.auth&&(this.auth=s.auth),this._opts=Object.assign({},s),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[ht(e,"open",this.onopen.bind(this)),ht(e,"packet",this.onpacket.bind(this)),ht(e,"error",this.onerror.bind(this)),ht(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){if(ut.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const s={type:it.EVENT,data:t,options:{}};if(s.options.compress=!1!==this.flags.compress,"function"==typeof t[t.length-1]){const e=this.ids++,n=t.pop();this._registerAckCallback(e,n),s.id=e}const n=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!n||!this.connected)||(this.connected?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(e,t){var s;const n=null!==(s=this.flags.timeout)&&void 0!==s?s:this._opts.ackTimeout;if(void 0===n)return void(this.acks[e]=t);const r=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&this.sendBuffer.splice(t,1);t.call(this,new Error("operation has timed out"))},n);this.acks[e]=(...e)=>{this.io.clearTimeoutFn(r),t.apply(this,[null,...e])}}emitWithAck(e,...t){const s=void 0!==this.flags.timeout||void 0!==this._opts.ackTimeout;return new Promise((n,r)=>{t.push((e,t)=>s?e?r(e):n(t):n(e)),this.emit(e,...t)})}_addToQueue(e){let t;"function"==typeof e[e.length-1]&&(t=e.pop());const s={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push((e,...n)=>{if(s===this._queue[0])return null!==e?s.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(e)):(this._queue.shift(),t&&t(null,...n)),s.pending=!1,this._drainQueue()}),this._queue.push(s),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||0===this._queue.length)return;const t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){"function"==typeof this.auth?this.auth(e=>{this._sendConnectPacket(e)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:it.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t)}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case it.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case it.EVENT:case it.BINARY_EVENT:this.onevent(e);break;case it.ACK:case it.BINARY_ACK:this.onack(e);break;case it.DISCONNECT:this.ondisconnect();break;case it.CONNECT_ERROR:this.destroy();const t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t)}}onevent(e){const t=e.data||[];null!=e.id&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const s of t)s.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&"string"==typeof e[e.length-1]&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let s=!1;return function(...n){s||(s=!0,t.packet({type:it.ACK,id:e,data:n}))}}onack(e){const t=this.acks[e.id];"function"==typeof t&&(t.apply(this,e.data),delete this.acks[e.id])}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:it.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let s=0;s<t.length;s++)if(e===t[s])return t.splice(s,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const t=this._anyOutgoingListeners;for(let s=0;s<t.length;s++)if(e===t[s])return t.splice(s,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const t=this._anyOutgoingListeners.slice();for(const s of t)s.apply(this,e.data)}}}function pt(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}pt.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),s=Math.floor(t*this.jitter*e);e=1&Math.floor(10*t)?e+s:e-s}return 0|Math.min(e,this.max)},pt.prototype.reset=function(){this.attempts=0},pt.prototype.setMin=function(e){this.ms=e},pt.prototype.setMax=function(e){this.max=e},pt.prototype.setJitter=function(e){this.jitter=e};class gt extends be{constructor(e,t){var s;super(),this.nsps={},this.subs=[],e&&"object"==typeof e&&(t=e,e=void 0),(t=t||{}).path=t.path||"/socket.io",this.opts=t,Ae(this,t),this.reconnection(!1!==t.reconnection),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(s=t.randomizationFactor)&&void 0!==s?s:.5),this.backoff=new pt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==t.timeout?2e4:t.timeout),this._readyState="closed",this.uri=e;const n=t.parser||lt;this.encoder=new n.Encoder,this.decoder=new n.Decoder,this._autoConnect=!1!==t.autoConnect,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}reconnectionAttempts(e){return void 0===e?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return void 0===e?this._reconnectionDelay:(this._reconnectionDelay=e,null===(t=this.backoff)||void 0===t||t.setMin(e),this)}randomizationFactor(e){var t;return void 0===e?this._randomizationFactor:(this._randomizationFactor=e,null===(t=this.backoff)||void 0===t||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return void 0===e?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,null===(t=this.backoff)||void 0===t||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new Ke(this.uri,this.opts);const t=this.engine,s=this;this._readyState="opening",this.skipReconnect=!1;const n=ht(t,"open",function(){s.onopen(),e&&e()}),r=t=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",t),e?e(t):this.maybeReconnectOnOpen()},i=ht(t,"error",r);if(!1!==this._timeout){const e=this._timeout,s=this.setTimeoutFn(()=>{n(),r(new Error("timeout")),t.close()},e);this.opts.autoUnref&&s.unref(),this.subs.push(()=>{this.clearTimeoutFn(s)})}return this.subs.push(n),this.subs.push(i),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(ht(e,"ping",this.onping.bind(this)),ht(e,"data",this.ondata.bind(this)),ht(e,"error",this.onerror.bind(this)),ht(e,"close",this.onclose.bind(this)),ht(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose("parse error",e)}}ondecoded(e){je(()=>{this.emitReserved("packet",e)},this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let s=this.nsps[e];return s?this._autoConnect&&!s.active&&s.connect():(s=new dt(this,e,t),this.nsps[e]=s),s}_destroy(e){const t=Object.keys(this.nsps);for(const e of t)if(this.nsps[e].active)return;this._close()}_packet(e){const t=this.encoder.encode(e);for(let s=0;s<t.length;s++)this.engine.write(t[s],e.options)}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(e,t){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();this._reconnecting=!0;const s=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),e.skipReconnect||e.open(t=>{t?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",t)):e.onreconnect()}))},t);this.opts.autoUnref&&s.unref(),this.subs.push(()=>{this.clearTimeoutFn(s)})}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const ft={};function mt(e,t){"object"==typeof e&&(t=e,e=void 0);const s=function(e,t="",s){let n=e;s=s||"undefined"!=typeof location&&location,null==e&&(e=s.protocol+"//"+s.host),"string"==typeof e&&("/"===e.charAt(0)&&(e="/"===e.charAt(1)?s.protocol+e:s.host+e),/^(https?|wss?):\/\//.test(e)||(e=void 0!==s?s.protocol+"//"+e:"https://"+e),n=Ge(e)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";const r=-1!==n.host.indexOf(":")?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+r+":"+n.port+t,n.href=n.protocol+"://"+r+(s&&s.port===n.port?"":":"+n.port),n}(e,(t=t||{}).path||"/socket.io"),n=s.source,r=s.id,i=s.path,o=ft[r]&&i in ft[r].nsps;let a;return t.forceNew||t["force new connection"]||!1===t.multiplex||o?a=new gt(n,t):(ft[r]||(ft[r]=new gt(n,t)),a=ft[r]),s.query&&!t.query&&(t.query=s.queryKey),a.socket(s.path,t)}Object.assign(mt,{Manager:gt,Socket:dt,io:mt,connect:mt});const yt=e=>("gui"===puter.env||(e||(e="."),e&&(e.startsWith("/")||e.startsWith("~")||!puter.appID)||(e=c.join("~/AppData",puter.appID,e))),e),bt=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{source:e[0],destination:e[1],overwrite:e[2]?.overwrite,new_name:e[2]?.newName||e[2]?.new_name,create_missing_parents:e[2]?.createMissingParents||e[2]?.create_missing_parents,new_metadata:e[2]?.newMetadata||e[2]?.new_metadata,original_client_socket_id:e[2]?.excludeSocketID||e[2]?.original_client_socket_id,success:e[3],error:e[4]},new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){s("Authentication failed.")}t.source=yt(t.source),t.destination=yt(t.destination);const n=C("/copy",this.APIOrigin,this.authToken);R(n,t.success,t.error,e,s),n.send(JSON.stringify({original_client_socket_id:this.socket.id,socket_id:this.socket.id,source:t.source,destination:t.destination,overwrite:t.overwrite,new_name:t.new_name||t.newName,dedupe_name:t.dedupe_name||t.dedupeName}))})},wt=function(...e){let t={};return"string"==typeof e[0]&&"object"==typeof e[1]&&!(e[1]instanceof Function)||"object"==typeof e[0]&&null!==e[0]?"string"==typeof e[0]?(t.path=e[0],Object.assign(t,e[1]),t.success=e[2],t.error=e[3]):t=e[0]:"string"==typeof e[0]&&(t.path=e[0],t.success=e[1],t.error=e[2]),new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){s("Authentication failed.")}const n=C("/mkdir",this.APIOrigin,this.authToken);R(n,t.success,t.error,e,s),t.path=yt(t.path),n.send(JSON.stringify({parent:c.dirname(t.path),path:c.basename(t.path),overwrite:t.overwrite??!1,dedupe_name:(t.rename||t.dedupeName)??!1,shortcut_to:t.shortcutTo,original_client_socket_id:this.socket.id,create_missing_parents:(t.recursive||t.createMissingParents)??!1}))})},vt=new Map,_t=async function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{path:e[0],options:"object"==typeof e[1]?e[1]:{},success:"object"==typeof e[1]?e[2]:e[1],error:"object"==typeof e[1]?e[3]:e[2]},new Promise(async(e,s)=>{let n;if(t.consistency||(t.consistency="strong"),t.path&&(n=`item:${t.path}`),!("eventual"!==t.consistency||t.returnSubdomains||t.returnPermissions||t.returnVersions||t.returnSize)){const t=await puter._cache.get(n);if(t)return void e(t)}const r=JSON.stringify({path:t.path,uid:t.uid,returnSubdomains:t.returnSubdomains,returnPermissions:t.returnPermissions,returnVersions:t.returnVersions,returnSize:t.returnSize,consistency:t.consistency}),i=vt.get(r),o=Date.now();if(i){if(o-i.timestamp<2e3){try{e(await i.promise)}catch(e){s(e)}return}vt.delete(r)}const a=new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){return void s("Authentication failed.")}const r=C("/stat",this.APIOrigin,void 0,"post","text/plain;actually=json");R(r,t.success,t.error,async t=>{JSON.stringify(t).length<=20971520&&puter._cache.set(n,t),e(t)},s);let i={};void 0!==t.uid?i.uid=t.uid:void 0!==t.path&&(i.path=yt(t.path)),i.return_subdomains=t.returnSubdomains,i.return_permissions=t.returnPermissions,i.return_versions=t.returnVersions,i.return_size=t.returnSize,i.auth_token=this.authToken,r.send(JSON.stringify(i))});vt.set(r,{promise:a,timestamp:o});try{const t=await a;vt.delete(r),e(t)}catch(e){vt.delete(r),s(e)}})},kt=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{source:e[0],destination:e[1],overwrite:e[2]?.overwrite,new_name:e[2]?.newName||e[2]?.new_name,create_missing_parents:e[2]?.createMissingParents||e[2]?.create_missing_parents,new_metadata:e[2]?.newMetadata||e[2]?.new_metadata,original_client_socket_id:e[2]?.excludeSocketID||e[2]?.original_client_socket_id},new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){s("Authentication failed.")}if(t.source=yt(t.source),t.destination=yt(t.destination),!t.new_name)try{if(!(await _t.bind(this)(t.destination)).is_dir)throw"is not directory"}catch(e){t.new_name=c.basename(t.destination),t.destination=c.dirname(t.destination)}const n=C("/move",this.APIOrigin,this.authToken);R(n,t.success,t.error,e,s),n.send(JSON.stringify({source:t.source,destination:t.destination,overwrite:t.overwrite,new_name:t.new_name||t.newName,create_missing_parents:t.create_missing_parents||t.createMissingParents,new_metadata:t.new_metadata||t.newMetadata,original_client_socket_id:t.excludeSocketID}))})},At=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{path:"string"==typeof e[0]?e[0]:"object"==typeof e[0]&&null!==e[0]?e[0].path:e[0],..."object"==typeof e[1]?e[1]:{success:e[1],error:e[2]}},new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){s("Authentication failed.")}t.path=yt(t.path);const n=C(`/read?${new URLSearchParams({file:t.path,...t.offset?{offset:t.offset}:{},...t.byte_count?{byte_count:t.byte_count}:{}}).toString()}`,this.APIOrigin,this.authToken,"get","application/json;charset=UTF-8","blob");R(n,t.success,t.error,e,s),n.send()})},Tt=new Map,xt=async function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{path:e[0],success:e[1],error:e[2]},new Promise(async(e,s)=>{if(t.consistency||(t.consistency="strong"),!t.path&&!t.uid)throw new Error({code:"NO_PATH_OR_UID",message:"Either path or uid must be provided."});let n;if(t.path&&(n=`readdir:${t.path}`),"eventual"===t.consistency){const t=await puter._cache.get(n);if(t)return void e(t)}const r=JSON.stringify({path:t.path,uid:t.uid,no_thumbs:t.no_thumbs,no_assocs:t.no_assocs,consistency:t.consistency}),i=Tt.get(r),o=Date.now();if(i){if(o-i.timestamp<2e3){try{e(await i.promise)}catch(e){s(e)}return}Tt.delete(r)}const a=new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){return void s("Authentication failed.")}const r=C("/readdir",this.APIOrigin,void 0,"post","text/plain;actually=json");R(r,t.success,t.error,async t=>{JSON.stringify(t).length<=104857600&&puter._cache.set(n,t);for(const e of t)puter._cache.set(`item:${e.path}`,e);e(t)},s);const i={no_thumbs:t.no_thumbs,no_assocs:t.no_assocs,auth_token:this.authToken};t.uid?i.uid=t.uid:t.path&&(i.path=yt(t.path)),r.send(JSON.stringify(i))});Tt.set(r,{promise:a,timestamp:o});try{const t=await a;Tt.delete(r),e(t)}catch(e){Tt.delete(r),s(e)}})},It=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{path:e[0],new_name:e[1],success:e[2],error:e[3]},new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){s("Authentication failed.")}const n=C("/rename",this.APIOrigin,this.authToken);R(n,t.success,t.error,e,s);let r={original_client_socket_id:t.excludeSocketID||t.original_client_socket_id,new_name:t.new_name||t.newName};void 0!==t.uid?r.uid=t.uid:void 0!==t.path&&(r.path=yt(t.path)),n.send(JSON.stringify(r))})},Et=function(...e){let t;return t={app_uid:e[0],items:e[1],success:e[2],error:e[3]},new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){s("Authentication failed.")}let n=t.items;Array.isArray(n)||(n=[n]);const r=C("/sign",this.APIOrigin,this.authToken);r.addEventListener("load",async function(r){const i=await P(this);if(200!==this.status)return t.error&&"function"==typeof t.error&&t.error(i),s(i);{let s,r=i,o=r.token;if(1==n.length)s={...r.signatures[0]};else{let e=[];for(let t=0;t<r.signatures.length;t++)e.push({...r.signatures[t]});s=e}return t.success&&"function"==typeof t.success&&t.success({token:o,items:s}),e({token:o,items:s})}}),r.upload.addEventListener("progress",function(e){}),r.addEventListener("error",function(e){return D(t.error,s,this)}),r.send(JSON.stringify({app_uid:t.app_uid,items:n}))})},St=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{success:e[0],error:e[1]},new Promise(async(e,s)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){s("Authentication failed.")}const n=C("/df",this.APIOrigin,this.authToken);R(n,t.success,t.error,e,s),n.send()})},Pt=async function(e,t){if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){throw"Authentication failed."}t=yt(t),e=yt(e);const s=c.basename(t),n={op:"symlink",path:c.dirname(t),name:s,target:e},r=new FormData;r.append("operation",JSON.stringify(n));try{const e=await fetch(`${this.APIOrigin}/batch`,{method:"POST",headers:{Authorization:`Bearer ${puter.authToken}`},body:r});if(200!==e.status){const t=await e.text();throw console.error("[symlink] fetch error: ",t),t}}catch(e){throw console.error("[symlink] fetch error: ",e),e}},Ot=async function(e,t,s={}){return new Promise(async(n,r)=>{const i=globalThis.DataTransfer||class{},o=globalThis.FileList||class{},a=globalThis.DataTransferItemList||class{};if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){r(e)}const l=e=>(s.error&&"function"==typeof s.error&&s.error(e),r(e));let h=new XMLHttpRequest;if("/"===t)return l("Can not upload to root directory.");t=yt(t);const u=O();s.init&&"function"==typeof s.init&&s.init(u,h);let d,p=0,g=0,f=0,m=!1;if(Array.isArray(e)&&e.length>0)for(let t=0;t<e.length;t++)(e[t]instanceof i||e[t]instanceof a)&&(m=!0);if(e instanceof a||e instanceof i||e[0]instanceof i||s.parsedDataTransferItems)d=s.parsedDataTransferItems?e:await puter.ui.getEntriesFromDataTransferItems(e),d.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.isDirectory&&t.isDirectory?0:e.size-t.size);else if(e instanceof File||e[0]instanceof File||e instanceof o||e[0]instanceof o){d=Array.isArray(e)?e:e instanceof o?Array.from(e):[e],d.sort((e,t)=>e.size-t.size);for(let e=0;e<d.length;e++)d[e].filepath=d[e].name,d[e].fullPath=d[e].name}else if(e instanceof Blob){d=[new File([e],s.name,{type:"application/octet-stream"})];for(let e=0;e<d.length;e++)d[e].filepath=d[e].name,d[e].fullPath=d[e].name}else{if("string"!=typeof e)return l({code:"field_invalid",message:"upload() items parameter is an invalid type"});d=[new File([e],"default.txt",{type:"text/plain"})];for(let e=0;e<d.length;e++)d[e].filepath=d[e].name,d[e].fullPath=d[e].name}let y,b=[],w={},v=[];for(let e=0;e<d.length;e++)if(d[e]){if(d[e].isDirectory)b.push({path:c.join(t,d[e].finalPath?d[e].finalPath:d[e].fullPath)});else{let n=d[e].finalPath?d[e].finalPath:d[e].fullPath,[r,i]=[n?.slice(0,n?.lastIndexOf("/")),n?.slice(n?.lastIndexOf("/")+1)];if(""!=i&&v.push(d[e]),s.createFileParent&&n.includes("/")){let e;r.split("/").forEach(s=>{e=e?`${e}/${s}`:s;let n=c.join(t,e);w[n]||(w[n]=!0,b.push({path:n}))})}}void 0!==d[e].size&&(f+=d[e].size)}if(0===b.length&&0===v.length)return l({code:"EMPTY_UPLOAD",message:"No files or directories to upload."});if("web"!==puter.env)try{if(y=await this.space(),y.capacity-y.used<f)return l({code:"NOT_ENOUGH_SPACE",message:"Not enough storage space available."})}catch(e){}f*=2;const _=new FormData;b.sort((e,t)=>t.path.length-e.path.length);let k=[];for(let e=0;e<b.length;e++){for(let s=0;s<v.length;s++)!v[s].puter_path_param&&c.join(t,v[s].filepath).startsWith(`${b[e].path}/`)&&(v[s].puter_path_param=`$dir_${e}/${c.basename(v[s].filepath)}`);for(let t=0;t<b.length;t++)!b[t].puter_path_param&&b[t].path.startsWith(`${b[e].path}/`)&&(b[t].puter_path_param=`$dir_${e}/${c.basename(b[t].path)}`)}for(let e=0;e<b.length;e++){let t=c.dirname(b[e].puter_path_param||b[e].path),n=b[e].puter_path_param||b[e].path;"/"!==t&&(n=n.replace(t,"")),k.push({op:"mkdir",parent:t,path:n,overwrite:s.overwrite??!1,dedupe_name:s.dedupeName??!0,create_missing_ancestors:s.createMissingAncestors??!0,as:`dir_${e}`})}k.reverse(),_.append("operation_id",u),_.append("socket_id",this.socket.id),_.append("original_client_socket_id",this.socket.id);for(let e=0;e<k.length;e++)_.append("operation",JSON.stringify(k[e]));if(!s.shortcutTo)for(let e=0;e<v.length;e++)_.append("fileinfo",JSON.stringify({name:v[e].name,type:v[e].type,size:v[e].size}));for(let e=0;e<v.length;e++)_.append("operation",JSON.stringify({op:s.shortcutTo?"shortcut":"write",dedupe_name:s.dedupeName??!0,overwrite:s.overwrite??!1,create_missing_ancestors:s.createMissingAncestors||s.createMissingParents,operation_id:u,path:v[e].puter_path_param&&c.dirname(v[e].puter_path_param??"")||v[e].filepath&&c.join(t,c.dirname(v[e].filepath))||"",name:c.basename(v[e].filepath),item_upload_id:e,shortcut_to:s.shortcutTo,shortcut_to_uid:s.shortcutTo,app_uid:s.appUID}));if(!s.shortcutTo)for(let e=0;e<v.length;e++)_.append("file",v[e]??"");const A=e=>{e.operation_id===u&&(g+=e.loaded_diff)};this.socket.on("upload.progress",A);let T=null;h.open("post",`${this.APIOrigin}/batch`,!0),h.setRequestHeader("Authorization",`Bearer ${this.authToken}`),h.upload.addEventListener("progress",function(e){let t;null===T?(t=e.loaded,T=0):t=e.loaded-T,T+=t,p+=t;let n=((g+p)/f*100).toFixed(2);n=n>100?100:n,s.progress&&"function"==typeof s.progress&&s.progress(u,n)});let x=setInterval(function(){let e=((g+p)/f*100).toFixed(2);e=e>100?100:e,s.progress&&"function"==typeof s.progress&&s.progress(u,e)},100);h.onabort=()=>{clearInterval(x),this.socket.off("upload.progress",A),s.abort&&"function"==typeof s.abort&&s.abort(u)},h.onreadystatechange=async e=>{if(4===h.readyState){const e=await P(h);if(h.status>=400&&h.status<600||s.strict&&218===h.status){if(clearInterval(x),this.socket.off("upload.progress",A),s.strict&&218===h.status){let t;for(let s=0;s<e.results?.length;s++)if(200!==e.results[s].status){t=e.results[s];break}return l(t)}return l(e)}{e&&e.results&&0!==e.results.length||puter.debugMode&&console.log("no results");let t=e.results;return t=1===t.length?t[0]:t,s.success&&"function"==typeof s.success&&s.success(t),clearInterval(x),this.socket.off("upload.progress",A),n(t)}}},s.start&&"function"==typeof s.start&&s.start(),h.send(_)})},Ct=async function(e,t,s={}){if(!e)throw new Error({code:"NO_TARGET_PATH",message:"No target path provided."});e instanceof File&&void 0===t&&(e=(t=e).name),s.strict=!0,s.overwrite=s.overwrite??!0,s.overwrite&&void 0===s.dedupeName&&(s.dedupeName=!1),e=yt(e);const n=c.basename(e),r=c.dirname(e);if("string"==typeof t?t=new File([t??""],n??"Untitled.txt",{type:"text/plain"}):t instanceof Blob?t=new File([t??""],n??"Untitled",{type:t.type}):(t instanceof ArrayBuffer||ArrayBuffer.isView(t))&&(t=new File([t],n??"Untitled",{type:"application/octet-stream"})),t||(t=new File([t??""],n)),!(t instanceof File))throw new Error({code:"field_invalid",message:"write() data parameter is an invalid type"});return this.upload(t,r,s)},Dt=class{constructor(e){this.readURL=e.readURL??e.read_url,this.writeURL=e.writeURL??e.write_url,this.metadataURL=e.metadataURL??e.metadata_url,this.name=e.name??e.fsentry_name,this.uid=e.uid??e.uuid??e.fsentry_uid??e.fsentry_id??e.fsentry_uuid??e.id,this.id=this.uid,this.uuid=this.uid,this.path=e.path??e.fsentry_path,this.size=e.size??e.fsentry_size,this.accessed=e.accessed??e.fsentry_accessed,this.modified=e.modified??e.fsentry_modified,this.created=e.created??e.fsentry_created,this.isDirectory=!!(e.isDirectory||e.is_dir||e.fsentry_is_dir);const t={};Object.defineProperty(this,"_internalProperties",{enumerable:!1,value:t}),t.signature=e.signature??(()=>new URL(this.writeURL??this.readURL).searchParams.get("signature"))(),t.expires=e.expires??(()=>new URL(this.writeURL??this.readURL).searchParams.get("expires"))(),Object.defineProperty(t,"file_signature",{get:()=>({read_url:this.readURL,write_url:this.writeURL,metadata_url:this.metadataURL,fsentry_accessed:this.accessed,fsentry_modified:this.modified,fsentry_created:this.created,fsentry_is_dir:this.isDirectory,fsentry_size:this.size,fsentry_name:this.name,path:this.path,uid:this.uid})})}write=async function(e){return puter.fs.write(this.path,new File([e],this.name),{overwrite:!0,dedupeName:!1})};watch=function(e){};open=function(e){};setAsWallpaper=function(e,t){};rename=function(e){return puter.fs.rename(this.uid,e)};move=function(e,t=!1,s){return puter.fs.move(this.path,e,t,s)};copy=function(e,t=!1,s=!1){return puter.fs.copy(this.path,e,t,s)};delete=function(){return puter.fs.delete(this.path)};versions=async function(){};trash=function(){};mkdir=async function(e,t=!1){if(!this.isDirectory)throw new Error("mkdir() can only be called on a directory");return puter.fs.mkdir(c.join(this.path,e))};metadata=async function(){};readdir=async function(){if(!this.isDirectory)throw new Error("readdir() can only be called on a directory");return puter.fs.readdir(this.path)};read=async function(){return puter.fs.read(this.path)}},Rt=async function(...e){let t;t="object"==typeof e[0]&&null!==e[0]?e[0]:{paths:e[0],recursive:e[1]?.recursive??!0,descendantsOnly:e[1]?.descendantsOnly??!1};let s=t.paths;return"string"==typeof s&&(s=[s]),new Promise(async(e,n)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){n("Authentication failed.")}const r=C("/delete",this.APIOrigin,this.authToken);R(r,t.success,t.error,e,n),s=s.map(e=>yt(e)),r.send(JSON.stringify({paths:s,descendants_only:(t.descendants_only||t.descendantsOnly)??!1,recursive:t.recursive??!0}))})},Lt=async function(e,t="24h"){return new Promise(async(s,n)=>{if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){n("Authentication failed.")}try{const{uid:r,is_dir:i}=await _t.call(this,e);if(i)return void n("Cannot create readUrl for directory");const o=C("/auth/create-access-token",this.APIOrigin,this.authToken);R(o,()=>{},()=>{},({token:e})=>{s(`${this.APIOrigin}/token-read?uid=${encodeURIComponent(r)}&token=${encodeURIComponent(e)}`)},n),o.send(JSON.stringify({expiresIn:t,permissions:[`fs:${r}:read`]}))}catch(e){n(e)}})},Mt="last_valid_ts";class Ut extends e.AdvancedBase{space=St;mkdir=wt;copy=bt;rename=It;upload=Ot;read=At;delete=Rt;move=kt;write=Ct;sign=Et;symlink=Pt;getReadURL=Lt;readdir=xt;stat=_t;FSItem=Dt;static NARI_METHODS={};constructor(e){super(),this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID,this.context=e,this.cacheUpdateTimer=null,this.initializeSocket();const t={};Object.defineProperty(t,"authToken",{get:()=>this.authToken}),Object.defineProperty(t,"APIOrigin",{get:()=>this.APIOrigin})}initializeSocket(){this.socket&&this.socket.disconnect(),this.socket=mt(this.APIOrigin,{auth:{auth_token:this.authToken},autoUnref:"nodejs"===this.context.env}),this.bindSocketEvents()}bindSocketEvents(){this.socket.on("item.renamed",e=>{puter._cache.flushall(),console.log("Flushed cache for item.renamed")}),this.socket.on("item.removed",e=>{puter._cache.flushall(),console.log("Flushed cache for item.removed")}),this.socket.on("item.added",e=>{puter._cache.del(`readdir:${c.dirname(e.path)}`),console.log(`deleted cache for readdir:${c.dirname(e.path)}`),puter._cache.del(`item:${c.dirname(e.path)}`),console.log(`deleted cache for item:${c.dirname(e.path)}`)}),this.socket.on("item.updated",e=>{puter._cache.flushall(),console.log("Flushed cache for item.updated")}),this.socket.on("item.moved",e=>{puter._cache.flushall(),console.log("Flushed cache for item.moved")}),this.socket.on("connect",()=>{puter.debugMode&&console.log("FileSystem Socket: Connected",this.socket.id)}),this.socket.on("disconnect",()=>{puter.debugMode&&console.log("FileSystem Socket: Disconnected")}),this.socket.on("reconnect",e=>{puter.debugMode&&console.log("FileSystem Socket: Reconnected",this.socket.id)}),this.socket.on("reconnect_attempt",e=>{puter.debugMode&&console.log("FileSystem Socket: Reconnection Attemps",e)}),this.socket.on("reconnect_error",e=>{puter.debugMode&&console.log("FileSystem Socket: Reconnection Error",e)}),this.socket.on("reconnect_failed",()=>{puter.debugMode&&console.log("FileSystem Socket: Reconnection Failed")}),this.socket.on("error",e=>{puter.debugMode&&console.error("FileSystem Socket Error:",e)})}setAuthToken(e){this.authToken=e,"gui"===this.context.env&&(this.checkCacheAndPurge(),this.startCacheUpdateTimer()),this.initializeSocket()}setAPIOrigin(e){this.APIOrigin=e,this.initializeSocket()}invalidateCache(){localStorage.setItem(Mt,"0"),puter._cache.flushall()}async getCacheTimestamp(){return new Promise((e,t)=>{const s=C("/cache/last-change-timestamp",this.APIOrigin,this.authToken,"get","application/json");R(s,void 0,void 0,async s=>{try{const t="string"==typeof s?JSON.parse(s):s;e(t.timestamp||Date.now())}catch(e){t(new Error("Failed to parse response"))}},t),s.send()})}async checkCacheAndPurge(){try{await this.getCacheTimestamp()-(parseInt(localStorage.getItem(Mt))||0)>2e3&&(console.log("Cache is not up to date, purging cache"),puter._cache.flushall(),localStorage.setItem(Mt,"0"))}catch(e){console.error("Error checking cache timestamp:",e)}}startCacheUpdateTimer(){"gui"===this.context.env&&(this.cacheUpdateTimer=setInterval(()=>{localStorage.setItem(Mt,Date.now().toString())},1e3))}stopCacheUpdateTimer(){this.cacheUpdateTimer&&(clearInterval(this.cacheUpdateTimer),this.cacheUpdateTimer=null)}}const Bt=class{constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}list=async(...e)=>(await U([],"puter-subdomains",void 0,"select")(...e)).filter(e=>!e.subdomain.startsWith("workers.puter."));create=async(...e)=>{let t={};return"string"==typeof e[0]&&1===e.length?(e[0].match(/^[a-z0-9]+\.puter\.(site|com)$/)&&(e[0]=e[0].split(".")[0]),t={object:{subdomain:e[0]}}):Array.isArray(e)&&2===e.length&&"string"==typeof e[0]?(e[0].match(/^[a-z0-9]+\.puter\.(site|com)$/)&&(e[0]=e[0].split(".")[0]),e[1]&&(e[1]=yt(e[1])),t={object:{subdomain:e[0],root_dir:e[1]}}):"object"==typeof e[0]&&(t={object:e[0]}),await U(["object"],"puter-subdomains",void 0,"create").call(this,t)};update=async(...e)=>{let t={};return Array.isArray(e)&&"string"==typeof e[0]&&(e[0].match(/^[a-z0-9]+\.puter\.(site|com)$/)&&(e[0]=e[0].split(".")[0]),e[1]&&(e[1]=yt(e[1])),t={id:{subdomain:e[0]},object:{root_dir:e[1]??null}}),await U(["object"],"puter-subdomains",void 0,"update").call(this,t)};get=async(...e)=>{let t={};return Array.isArray(e)&&"string"==typeof e[0]&&(e[0].match(/^[a-z0-9]+\.puter\.(site|com)$/)&&(e[0]=e[0].split(".")[0]),t={id:{subdomain:e[0]}}),U(["uid"],"puter-subdomains",void 0,"read").call(this,t)};delete=async(...e)=>{let t={};return Array.isArray(e)&&"string"==typeof e[0]&&(e[0].match(/^[a-z0-9]+\.puter\.(site|com)$/)&&(e[0]=e[0].split(".")[0]),t={id:{subdomain:e[0]}}),U(["uid"],"puter-subdomains",void 0,"delete").call(this,t)}};var qt=s(717);const Nt=["has_set_default_app_user_permissions","window_sidebar_width","sidebar_items","menubar_style","user_preferences.auto_arrange_desktop","user_preferences.show_hidden_files","user_preferences.language","user_preferences.clock_visible","toolbar_auto_hide_enabled","has_seen_welcome_window","desktop_item_positions","desktop_icons_hidden","taskbar_position","has_seen_toolbar_animation"];function jt(e,t){let s=(n=e,n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).replace(/\\\*/g,".*").replace(/\\\?/g,".").replace(/\\\[/g,"[").replace(/\\\]/g,"]").replace(/\\\^/g,"^");var n;return new RegExp(`^${s}$`).test(t)}const Ft=class{MAX_KEY_SIZE=1024;MAX_VALUE_SIZE=408576;constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID,this.gui_cached=new qt.TeePromise,this.gui_cache_init=new qt.TeePromise,(async()=>{await this.gui_cache_init,this.gui_cache_init=null;const e=await fetch(`${this.APIOrigin}/drivers/call`,{method:"POST",headers:{"Content-Type":"text/plain;actually=json"},body:JSON.stringify({interface:"puter-kvstore",method:"get",args:{key:Nt},auth_token:this.authToken})}),t=await e.json();if(!Array.isArray(t?.result))return this.gui_cached.resolve({}),void setTimeout(()=>{this.gui_cached=null},4e3);const s={};for(let e=0;e<Nt.length;e++)s[Nt[e]]=t.result[e];this.gui_cached.resolve(s),setTimeout(()=>{this.gui_cached=null},4e3)})()}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}set=U(["key","value","expireAt"],"puter-kvstore",void 0,"set",{preprocess:e=>{if(void 0===e.key||null===e.key)throw{message:"Key cannot be undefined",code:"key_undefined"};if(e.key.length>this.MAX_KEY_SIZE)throw{message:`Key size cannot be larger than ${this.MAX_KEY_SIZE}`,code:"key_too_large"};if(e.value&&e.value.length>this.MAX_VALUE_SIZE)throw{message:`Value size cannot be larger than ${this.MAX_VALUE_SIZE}`,code:"value_too_large"};return e}});async get(...e){return"string"==typeof e[0]&&Nt.includes(e[0])&&null!==this.gui_cached?(this.gui_cache_init&&this.gui_cache_init.resolve(),(await this.gui_cached)[e[0]]):await this.get_(...e)}get_=U(["key"],"puter-kvstore",void 0,"get",{preprocess:e=>{if(e.key.length>this.MAX_KEY_SIZE)throw{message:`Key size cannot be larger than ${this.MAX_KEY_SIZE}`,code:"key_too_large"};return e},transform:e=>e});incr=async(...e)=>{let t={};if(!e||0===e.length)throw{message:"Arguments are required",code:"arguments_required"};if(t.key=e[0],t.pathAndAmountMap=e[1]?"number"==typeof e[1]?{"":e[1]}:e[1]:{"":1},t.key.length>this.MAX_KEY_SIZE)throw{message:`Key size cannot be larger than ${this.MAX_KEY_SIZE}`,code:"key_too_large"};return U(["key"],"puter-kvstore",void 0,"incr").call(this,t)};decr=async(...e)=>{let t={};if(!e||0===e.length)throw{message:"Arguments are required",code:"arguments_required"};if(t.key=e[0],t.pathAndAmountMap=e[1]?"number"==typeof e[1]?{"":e[1]}:e[1]:{"":1},t.key.length>this.MAX_KEY_SIZE)throw{message:`Key size cannot be larger than ${this.MAX_KEY_SIZE}`,code:"key_too_large"};return U(["key"],"puter-kvstore",void 0,"decr").call(this,t)};expire=async(e,t)=>{let s={};if(s.key=e,s.ttl=t,s.key.length>this.MAX_KEY_SIZE)throw{message:`Key size cannot be larger than ${this.MAX_KEY_SIZE}`,code:"key_too_large"};return U(["key","ttl"],"puter-kvstore",void 0,"expire").call(this,s)};expireAt=async(e,t)=>{let s={};if(s.key=e,s.timestamp=t,s.key.length>this.MAX_KEY_SIZE)throw{message:`Key size cannot be larger than ${this.MAX_KEY_SIZE}`,code:"key_too_large"};return U(["key","timestamp"],"puter-kvstore",void 0,"expireAt").call(this,s)};del=U(["key"],"puter-kvstore",void 0,"del",{preprocess:e=>{if(e.key.length>this.MAX_KEY_SIZE)throw{message:`Key size cannot be larger than ${this.MAX_KEY_SIZE}`,code:"key_too_large"};return e}});list=async(...e)=>{let t,s={},n=!1;return e&&1===e.length&&!0===e[0]||e&&2===e.length&&!0===e[1]?(s={},n=!0):s={as:"keys"},(e&&1===e.length&&"string"==typeof e[0]||e&&2===e.length&&"string"==typeof e[0]&&!0===e[1])&&(t=e[0]),U([],"puter-kvstore",void 0,"list",{transform:e=>t?n?e.filter(e=>jt(t,e.key)):e.filter(e=>jt(t,e)):e}).call(this,s)};flush=U([],"puter-kvstore",void 0,"flush");clear=this.flush};class zt{#s;#n;constructor(e){this.#s=e,this.#n=(()=>{const e=new Map;for(let t of this.#s)e[t]=[];return e})()}emit(e,t){this.#s.includes(e)?this.#n[e].forEach(e=>{e(t)}):console.error(`Event name '${e}' not supported`)}on(e,t){if(this.#s.includes(e))return this.#n[e].push(t),this;console.error(`Event name '${e}' not supported`)}off(e,t){if(!this.#s.includes(e))return void console.error(`Event name '${e}' not supported`);const s=this.#n[e],n=s.indexOf(t);return-1!==n&&s.splice(n,1),this}}const Wt=new TextDecoder,Xt=new TextEncoder,Vt={1:"Reason unspecified or unknown. Returning a more specific reason should be preferred.",3:"Unexpected stream closure due to a network error.",65:"Stream creation failed due to invalid information. This could be sent if the destination was a reserved address or the port is invalid.",66:"Stream creation failed due to an unreachable destination host. This could be sent if the destination is an domain which does not resolve to anything.",67:"Stream creation timed out due to the destination server not responding.",68:"Stream creation failed due to the destination server refusing the connection.",71:"TCP data transfer timed out.",72:"Stream destination address/domain is intentionally blocked by the proxy server.",73:"Connection throttled by the server."};function Gt(e){let t=5;switch(e.packetType){case 1:e.hostEncoded=Xt.encode(e.hostname),t+=3+e.hostEncoded.length;break;case 2:t+=e.payload.byteLength;break;case 3:t+=4;break;case 4:t+=1;break;case 5:t+=2,e.password&&(t+=6),e.puterAuth&&(e.passwordEncoded=Xt.encode(e.puterAuth),t+=8+e.passwordEncoded.length);break;default:throw new Error("Not supported")}let s=new Uint8Array(t);const n=new DataView(s.buffer);switch(n.setUint8(0,e.packetType),n.setUint32(1,e.streamID,!0),e.packetType){case 1:n.setUint8(5,e.streamType),n.setUint16(6,e.port,!0),s.set(e.hostEncoded,8);break;case 2:s.set(e.payload,5);break;case 3:n.setUint32(5,e.remainingBuffer,!0);break;case 4:n.setUint8(5,e.reason);break;case 5:n.setUint8(5,2),n.setUint8(6,0),e.password&&(n.setUint8(7,2),n.setUint32(8,1,!0),n.setUint8(12,0)),e.puterAuth&&(n.setUint8(7,2),n.setUint32(8,5+e.passwordEncoded.length,!0),n.setUint8(12,0),n.setUint16(13,e.passwordEncoded.length,!0),s.set(e.passwordEncoded,15))}return s}class Kt{_ws;_nextStreamID=1;_bufferMax;onReady=void 0;streamMap=new Map;constructor(e,t){const s=()=>{this._ws=new WebSocket(e),this._ws.binaryType="arraybuffer",this._ws.onmessage=e=>{const n=function(e){const t=new DataView(e.buffer,e.byteOffset),s=t.getUint8(0),n=t.getUint32(1,!0);switch(s){case 1:return{packetType:s,streamID:n,streamType:t.getUint8(5),port:t.getUint16(6,!0),hostname:Wt.decode(e.subarray(8,e.length))};case 2:return{packetType:s,streamID:n,payload:e.subarray(5,e.length)};case 3:return{packetType:s,streamID:n,remainingBuffer:t.getUint32(5,!0)};case 4:return{packetType:s,streamID:n,reason:t.getUint8(5)};case 5:const r={};r.version_major=t.getUint8(5),r.version_minor=t.getUint8(6);let i=7;for(;i<e.length;){const s=t.getUint8(i),n=t.getUint32(i+1,!0),o=e.subarray(i+5,i+5+n);r[s]=o,i+=5+n}return{packetType:s,streamID:n,infoObj:r}}}(new Uint8Array(e.data));switch(n.packetType){case 2:this.streamMap.get(n.streamID).dataCallBack(n.payload.slice(0));break;case 3:if(0===n.streamID)return this._bufferMax=n.remainingBuffer,this._ws.onclose=()=>{setTimeout(s(),1e3)},void(this.onReady&&this.onReady());this.streamMap.get(n.streamID).buffer=n.remainingBuffer,this._continue();break;case 4:0!==n.streamID&&this.streamMap.get(n.streamID).closeCallBack(n.reason);break;case 5:t&&this._ws.send(Gt({packetType:5,streamID:0,puterAuth:t}))}}};s()}_continue(e){const t=this.streamMap.get(e).queue;for(let s=0;s<t.length;s++)this.write(e,t.shift())}register(e,t,s){const n=this._nextStreamID++;return this.streamMap.set(n,{queue:[],streamID:n,buffer:this._bufferMax,dataCallBack:s.dataCallBack,closeCallBack:s.closeCallBack}),this._ws.send(Gt({packetType:1,streamType:1,streamID:n,hostname:e,port:t})),n}write(e,t){const s=this.streamMap.get(e);s.buffer>0?(s.buffer--,this._ws.send(Gt({packetType:2,streamID:e,payload:t}))):s.queue.push(t)}close(e){this._ws.send(Gt({packetType:4,streamID:e,reason:2}))}}const Ht=new TextEncoder;let Yt,Qt={server:"wss://puter.cafe/",handler:void 0};class Zt extends zt{_events=new Map;_streamID;constructor(e,t){super(["data","drain","open","error","close","tlsdata","tlsopen","tlsclose"]),(async()=>{if(!puter.authToken&&puter.env,!Qt.handler){const{token:e,server:t}=await(await fetch(`${puter.APIOrigin}/wisp/relay-token/create`,{method:"POST",headers:{Authorization:puter.authToken?`Bearer ${puter.authToken}`:"","Content-Type":"application/json"},body:JSON.stringify({})})).json();Qt.handler=new Kt(t,e),await new Promise((e,t)=>{Qt.handler.onReady=e})}const s={dataCallBack:e=>{this.emit("data",e)},closeCallBack:e=>{if(2!==e)return this.emit("error",new Error(Vt[e])),void this.emit("close",!0);this.emit("close",!1)}};this._streamID=Qt.handler.register(e,t,s),setTimeout(()=>{this.emit("open",void 0)},0)})()}addListener(...e){this.on(...e)}write(e,t){if(e.buffer)Qt.handler.write(this._streamID,e),t&&t();else if(e.resize)e.write(this._streamID,new Uint8Array(e)),t&&t();else{if("string"!=typeof e)throw new Error("Invalid data type (not TypedArray, ArrayBuffer or String!!)");Qt.handler.write(this._streamID,Ht.encode(e)),t&&t()}}close(){Qt.handler.close(this._streamID)}}class Jt extends Zt{constructor(...e){super(...e),super.on("open",async()=>{Yt||(globalThis.ReadableByteStreamController||await import("https://unpkg.com/web-streams-polyfill@3.0.2/dist/polyfill.js"),Yt=await import("https://puter-net.b-cdn.net/rustls.js"),await Yt.default("https://puter-net.b-cdn.net/rustls.wasm"));let t=!1;const s=new ReadableStream({start:e=>{super.on("data",t=>{e.enqueue(t.buffer)}),super.on("close",()=>{t||e.close()})},pull:e=>{},cancel:()=>{t=!0}}),n=new WritableStream({write:e=>{super.write(e)},abort:()=>{super.close()},close:()=>{super.close()}});let r,i;try{const t=await Yt.connect_tls(s,n,e[0]);r=t.read,i=t.write}catch(e){return void this.emit("error",new Error(`TLS Handshake failed: ${e}`))}this.writer=i.getWriter();let o=r.getReader(),a=!1;this.emit("tlsopen",void 0);try{for(;!a;){const{done:e,value:t}=await o.read();a=e,a||this.emit("tlsdata",t)}this.emit("tlsclose",!1)}catch(e){this.emit("error",e),this.emit("tlsclose",!0)}})}on(e,t){return"data"===e||"open"===e||"close"===e?super.on(`tls${e}`,t):super.on(e,t)}write(e,t){if(e.buffer)this.writer.write(e.slice(0).buffer).then(t);else if(e.resize)this.writer.write(e).then(t);else{if("string"!=typeof e)throw new Error("Invalid data type (not TypedArray, ArrayBuffer or String!!)");this.writer.write(e).then(t)}}}function $t(...e){return new Promise(async(t,s)=>{try{const n=new Request(...e),r=new URL(n.url);let i,o=new Headers(n.headers);if("http:"===r.protocol)i=new puter.net.Socket(r.hostname,r.port||80);else{if("https:"!==r.protocol){const e=`Failed to fetch. URL scheme "${r.protocol}" is not supported.`;return globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"network",operation:"pFetch",params:{url:n.url,method:n.method},error:{message:e}}),void s(e)}i=new puter.net.tls.TLSSocket(r.hostname,r.port||443)}o.get("user-agent")||o.set("user-agent",navigator.userAgent);let a,c=`${n.method} ${r.pathname}${r.search} HTTP/1.1\r\nHost: ${r.host}\r\nConnection: close\r\n`;for(const[e,t]of o)c+=`${e}: ${t}\r\n`;if(n.body){if(a=new Uint8Array(await n.arrayBuffer()),o.has("content-length")){if(o.get("content-length")!==String(a.length))return s("Content-Length header does not match the body length. Please check your request.")}else o.set("content-length",a.length);c+=`Content-Length: ${a.length}\r\n`}c+="\r\n",i.on("open",async()=>{i.write(c),a&&i.write(a)});const l=new TextDecoder;let h="",u=-1;const d=[];let p=!1,g=-1,f=0,m=!1,y=-1,b=new Uint8Array(0);const w=new ReadableStream({start(e){function r(t){const s=new Uint8Array(b.length+t.length);for(s.set(b,0),s.set(t,b.length),b=s;;)if(y>0){if(!(b.length>=y+2)){e.enqueue(b),y-=b.length,b=new Uint8Array(0);break}{const t=b.slice(0,y);e.enqueue(t),b=b.slice(y+2),y=0}}else{let t=-1;for(let e=0;e+1<b.length;e++)if(13===b[e]&&10===b[e+1]){t=e;break}if(t<0)break;const s=l.decode(b.slice(0,t)).trim();if(y=parseInt(s,16),isNaN(y)&&e.error("Invalid chunk length from server"),b=b.slice(t+2),0===y)return p=!0,void e.close()}}i.on("data",s=>{if(-1===u||m||(e.enqueue(s),f+=s.length),-1===u&&(d.push(s),h+=l.decode(s,{stream:!0})),m&&r(s),-1!==h.indexOf("\r\n\r\n")){u=h.indexOf("\r\n\r\n"),h=h.slice(0,u);const s=function(e){const t=e.split("\r\n"),s=t.shift().split(" "),n=Number(s[1]),r=s.slice(2).join(" ")||"",i=[];for(const e of t){const t=e.split(": "),s=t[0],n=t.slice(1).join(": ");i.push([s,n])}return new Headers(i),{headers:new Headers(i),statusText:r,status:n}}(h);g=Number(s.headers.get("content-length")),m="chunked"===s.headers.get("transfer-encoding"),globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"network",operation:"pFetch",params:{url:n.url,method:n.method},result:{status:s.status,statusText:s.statusText}}),t(new Response(w,s));const i=function(...e){const t=e.reduce((e,t)=>e+t.length,0),s=new Uint8Array(t);return e.forEach((e,t,n)=>{const r=n.slice(0,t).reduce((e,t)=>e+t.length,0);s.set(e,r)}),s}(...d).slice(u+4);m?r(i):(f+=i.length,e.enqueue(i))}-1===g||f!==g||m||p||(p=!0,e.close())}),i.on("close",()=>{p||(p=!0,e.close())}),i.on("error",e=>{globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"network",operation:"pFetch",params:{url:n.url,method:n.method},error:{message:`Socket errored with the following reason: ${e}`}}),s(`Socket errored with the following reason: ${e}`)})}})}catch(e){globalThis.puter?.apiCallLogger?.isEnabled()&&globalThis.puter.apiCallLogger.logRequest({service:"network",operation:"pFetch",params:{url:reqObj.url,method:reqObj.method},error:{message:e.message||e.toString(),stack:e.stack}}),s(e)}})}const es=class{constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin,this.appID=e.appID}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}user=function(...e){let t;t="object"==typeof e[0]&&null!==e[0]?e[0]:{success:e[0],error:e[1]};let s="";return t?.query&&(s=`?${new URLSearchParams(t.query).toString()}`),new Promise((e,n)=>{const r=C(`/whoami${s}`,this.APIOrigin,this.authToken,"get");R(r,t.success,t.error,e,n),r.send()})};version=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{success:e[0],error:e[1]},new Promise((e,s)=>{const n=C("/version",this.APIOrigin,this.authToken,"get");R(n,t.success,t.error,e,s),n.send()})}};class ts{constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}async req_(e,t){const s=await fetch(this.APIOrigin+e,{method:t?"POST":"GET",headers:{Authorization:`Bearer ${this.authToken}`,"Content-Type":"application/json"},...t?{body:JSON.stringify(t)}:{}});return await s.json()}async grantUser(e,t){return await this.req_("/auth/grant-user-user",{target_username:e,permission:t})}async grantGroup(e,t){return await this.req_("/auth/grant-user-group",{group_uid:e,permission:t})}async grantApp(e,t){return await this.req_("/auth/grant-user-app",{app_uid:e,permission:t})}async grantAppAnyUser(e,t){return await this.req_("/auth/grant-dev-app",{app_uid:e,permission:t})}async grantOrigin(e,t){return await this.req_("/auth/grant-user-app",{origin:e,permission:t})}async revokeUser(e,t){return await this.req_("/auth/revoke-user-user",{target_username:e,permission:t})}async revokeGroup(e,t){return await this.req_("/auth/revoke-user-group",{group_uid:e,permission:t})}async revokeApp(e,t){return await this.req_("/auth/revoke-user-app",{app_uid:e,permission:t})}async revokeAppAnyUser(e,t){return await this.req_("/auth/revoke-dev-app",{app_uid:e,permission:t})}async revokeOrigin(e,t){return await this.req_("/auth/revoke-user-app",{origin:e,permission:t})}async createGroup(e={},t={}){return await this.req_("/group/create",{metadata:e,extra:t})}async addUsersToGroup(e,t){return await this.req_("/group/add-users",{uid:e,users:t??[]})}async removeUsersFromGroup(e,t){return await this.req_("/group/remove-users",{uid:e,users:t??[]})}async listGroups(){return await this.req_("/group/list")}}class ss extends Error{constructor(e){super(e),this.name="RequestError"}}class ns{constructor(e){this.authToken=e.authToken,this.APIOrigin=e.APIOrigin}setAuthToken(e){this.authToken=e}setAPIOrigin(e){this.APIOrigin=e}async req_(e,t,s){const n=await fetch(this.APIOrigin+t,{method:e,headers:{Authorization:`Bearer ${this.authToken}`,...s?{"Content-Type":"application/json"}:{}},...s?{body:JSON.stringify(s)}:{}});if(!n.ok){const e=await n.json(),t=new ss(e.message);throw t.response=e,t}return await n.json()}async create(e,t){return"string"==typeof e&&(e={text:e}),await this.req_("POST","/threads/create",{...e,...t?{parent:t}:{}})}async edit(e,t={}){"string"==typeof t&&(t={text:t}),await this.req_("PUT",`/threads/edit/${encodeURIComponent(e)}`,{...t})}async delete(e){await this.req_("DELETE",`/threads/${encodeURIComponent(e)}`)}async list(e,t,s){return await this.req_("POST",`/threads/list/${encodeURIComponent(e)}/${t}`,s??{})}async subscribe(e,t){puter.fs.socket.emit("thread.sub-request",{uid:e});const s=["post","edit","delete","child-edit","child-delete"];for(const n of s)puter.fs.socket.on(`thread.${n}`,s=>{s.subscription===e&&t(n,s)})}}class rs extends(globalThis.HTMLElement||Object){isUsingFileProtocol=()=>"file:"===window.location.protocol;constructor(e,t){let s;super(),this.reject=t,this.resolve=e,this.popupLaunched=!1,this.hasUserActivation=()=>{if(navigator.userActivation)return navigator.userActivation.hasBeenActive&&navigator.userActivation.isActive;try{const e=window.open("","_blank","width=1,height=1,left=-1000,top=-1000");return!!e&&(e.close(),!0)}catch(e){return!1}},this.launchPopup=()=>{try{let s=600,n=400,r="Puter";var e=screen.width/2-s/2,t=screen.height/2-n/2;return window.open(`${puter.defaultGUIOrigin}/?embedded_in_popup=true&request_auth=true${window.crossOriginIsolated?"&cross_origin_isolated=true":""}`,r,`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${s}, height=${n}, top=${t}, left=${e}`)}catch(e){return console.error("Failed to open popup:",e),null}},this.attachShadow({mode:"open"}),s="\n <style>\n dialog{\n background: transparent; \n border: none; \n box-shadow: none; \n outline: none;\n }\n .puter-dialog-content {\n border: 1px solid #e8e8e8;\n border-radius: 8px;\n padding: 20px;\n background: white;\n box-shadow: 0 0 9px 1px rgb(0 0 0 / 21%);\n padding: 80px 20px;\n -webkit-font-smoothing: antialiased;\n color: #575762;\n position: relative;\n background-image: url('data:image/webp;base64,UklGRlAbAABXRUJQVlA4WAoAAAAwAAAA8AIArQEAQUxQSB0AAAABB1ChiAgAKNL//xTR/9T//ve///3vf//73/+ZAwBWUDggDBsAAHAjAZ0BKvECrgE+nUyfTKWkMKsjk3mqEBOJaW6WwjzR/6prSfc95r2ztLOrL7Qmk8WYj6B+qfKm8C//+ufPmvfz/L6dZ/lf/79Rn1D/u8lf1n/h51GW/9DvL9u3/+z8//rLz8rv/Ho91qL//9Tf3+Dt29xsjEB3trEAO1CpmGKEcxEE0NTCpyVf/lDAyEBRUXwgPowMARkOmIbfb4QzfbEpqmW/oVDjCDhYdvNTH6wCem7jlfp6TsCUMhAr8Nka9YNDW//M1hIARGlp5TiuWo8zkVrq7MQ8sjAbL2ZDAR5HrshhvuQpLP42dIBC+d2vAQEWdwbMDviLsUYj7YuRYgd/nYcIbMPrxgnEqUps4UewgKUjphAD2DIgVLi0raUFF6zyUCN4z77Os61eB1TcZJ0RwsZHd++GEzQ7mz3e/8Gt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ga7OYz0Sdnw+dQk230G0weEIt9GN3BpWOiGAJZ69w4jr2D+6RkhzNmnY9n1qV05DE1BflAzIDxsPW78jJAFiz5aARulRgVFwgBnMuPWxvLmIXBvAAHy65muvCAsGfVex4ZHKCCv6XnQ2OW9EURTQsdw7Gb8bz9teGINBk3/fz0oAJ5e9QAAAA==');\n background-repeat: no-repeat;\n background-position: center center;\n background-size: 100% 100%;\n background-color: #fff;\n }\n \n dialog * {\n max-width: 500px;\n font-family: \"Helvetica Neue\", HelveticaNeue, Helvetica, Arial, sans-serif;\n }\n \n dialog p.about{\n text-align: center;\n font-size: 17px;\n padding: 10px 30px;\n font-weight: 400;\n -webkit-font-smoothing: antialiased;\n color: #404048;\n box-sizing: border-box;\n }\n \n dialog .buttons{\n display: flex;\n justify-content: center;\n align-items: center;\n flex-wrap: wrap;\n margin-top: 20px;\n text-align: center;\n margin-bottom: 20px;\n }\n \n .launch-auth-popup-footnote{\n font-size: 11px;\n color: #666;\n margin-top: 10px;\n /* footer at the bottom */\n position: absolute;\n left: 0;\n right: 0;\n bottom: 10px;\n text-align: center;\n margin: 0 10px;\n }\n \n dialog .close-btn{\n position: absolute;\n right: 15px;\n top: 10px;\n font-size: 17px;\n color: #8a8a8a;\n cursor: pointer;\n }\n \n dialog .close-btn:hover{\n color: #000;\n }\n \n /* ------------------------------------\n Button\n ------------------------------------*/\n \n dialog .button {\n color: #666666;\n background-color: #eeeeee;\n border-color: #eeeeee;\n font-size: 14px;\n text-decoration: none;\n text-align: center;\n line-height: 40px;\n height: 35px;\n padding: 0 30px;\n margin: 0;\n display: inline-block;\n appearance: none;\n cursor: pointer;\n border: none;\n -webkit-box-sizing: border-box;\n -moz-box-sizing: border-box;\n box-sizing: border-box;\n border-color: #b9b9b9;\n border-style: solid;\n border-width: 1px;\n line-height: 35px;\n background: -webkit-gradient(linear, left top, left bottom, from(#f6f6f6), to(#e1e1e1));\n background: linear-gradient(#f6f6f6, #e1e1e1);\n -webkit-box-shadow: inset 0px 1px 0px rgb(255 255 255 / 30%), 0 1px 2px rgb(0 0 0 / 15%);\n box-shadow: inset 0px 1px 0px rgb(255 255 255 / 30%), 0 1px 2px rgb(0 0 0 / 15%);\n border-radius: 4px;\n outline: none;\n -webkit-font-smoothing: antialiased;\n }\n \n dialog .button:focus-visible {\n border-color: rgb(118 118 118);\n }\n \n dialog .button:active, dialog .button.active, dialog .button.is-active, dialog .button.has-open-contextmenu {\n text-decoration: none;\n background-color: #eeeeee;\n border-color: #cfcfcf;\n color: #a9a9a9;\n -webkit-transition-duration: 0s;\n transition-duration: 0s;\n -webkit-box-shadow: inset 0 1px 3px rgb(0 0 0 / 20%);\n box-shadow: inset 0px 2px 3px rgb(0 0 0 / 36%), 0px 1px 0px white;\n }\n \n dialog .button.disabled, dialog .button.is-disabled, dialog .button:disabled {\n top: 0 !important;\n background: #EEE !important;\n border: 1px solid #DDD !important;\n text-shadow: 0 1px 1px white !important;\n color: #CCC !important;\n cursor: default !important;\n appearance: none !important;\n pointer-events: none;\n }\n \n dialog .button-action.disabled, dialog .button-action.is-disabled, dialog .button-action:disabled {\n background: #55a975 !important;\n border: 1px solid #60ab7d !important;\n text-shadow: none !important;\n color: #CCC !important;\n }\n \n dialog .button-primary.disabled, dialog .button-primary.is-disabled, dialog .button-primary:disabled {\n background: #8fc2e7 !important;\n border: 1px solid #98adbd !important;\n text-shadow: none !important;\n color: #f5f5f5 !important;\n }\n \n dialog .button-block {\n width: 100%;\n }\n \n dialog .button-primary {\n border-color: #088ef0;\n background: -webkit-gradient(linear, left top, left bottom, from(#34a5f8), to(#088ef0));\n background: linear-gradient(#34a5f8, #088ef0);\n color: white;\n }\n \n dialog .button-danger {\n border-color: #f00808;\n background: -webkit-gradient(linear, left top, left bottom, from(#f83434), to(#f00808));\n background: linear-gradient(#f83434, #f00808);\n color: white;\n }\n \n dialog .button-primary:active, dialog .button-primary.active, dialog .button-primary.is-active, dialog .button-primary-flat:active, dialog .button-primary-flat.active, dialog .button-primary-flat.is-active {\n background-color: #2798eb;\n border-color: #2798eb;\n color: #bedef5;\n }\n \n dialog .button-action {\n border-color: #08bf4e;\n background: -webkit-gradient(linear, left top, left bottom, from(#29d55d), to(#1ccd60));\n background: linear-gradient(#29d55d, #1ccd60);\n color: white;\n }\n \n dialog .button-action:active, dialog .button-action.active, dialog .button-action.is-active, dialog .button-action-flat:active, dialog .button-action-flat.active, dialog .button-action-flat.is-active {\n background-color: #27eb41;\n border-color: #27eb41;\n color: #bef5ca;\n }\n \n dialog .button-giant {\n font-size: 28px;\n height: 70px;\n line-height: 70px;\n padding: 0 70px;\n }\n \n dialog .button-jumbo {\n font-size: 24px;\n height: 60px;\n line-height: 60px;\n padding: 0 60px;\n }\n \n dialog .button-large {\n font-size: 20px;\n height: 50px;\n line-height: 50px;\n padding: 0 50px;\n }\n \n dialog .button-normal {\n font-size: 16px;\n height: 40px;\n line-height: 38px;\n padding: 0 40px;\n }\n \n dialog .button-small {\n height: 30px;\n line-height: 29px;\n padding: 0 30px;\n }\n \n dialog .button-tiny {\n font-size: 9.6px;\n height: 24px;\n line-height: 24px;\n padding: 0 24px;\n }\n \n #launch-auth-popup{\n margin-left: 10px; \n width: 200px; \n font-weight: 500; \n font-size: 15px;\n }\n dialog .button-auth{\n margin-bottom: 10px;\n }\n dialog a, dialog a:visited{\n color: rgb(0 69 238);\n text-decoration: none;\n }\n dialog a:hover{\n text-decoration: underline;\n }\n \n @media (max-width:480px) { \n .puter-dialog-content{\n padding: 50px 20px;\n }\n dialog .buttons{\n flex-direction: column-reverse;\n }\n dialog p.about{\n padding: 10px 0;\n }\n dialog .button-auth{\n width: 100% !important;\n margin:0 !important;\n margin-bottom: 10px !important;\n }\n }\n .error-container h1 {\n color: #e74c3c;\n font-size: 20px;\n text-align: center;\n }\n\n .puter-dialog-content a:focus{\n outline: none;\n }\n </style>","file:"===window.location.protocol?s+='<dialog>\n <div class="puter-dialog-content" style="padding: 20px 40px; background:white !important; font-size: 15px;">\n <span class="close-btn">&#x2715</span>\n <div class="error-container">\n <h1>Puter.js Error: Unsupported Protocol</h1>\n <p>It looks like you\'ve opened this file directly in your browser (using the <code style="font-family: monospace;">file:///</code> protocol) which is not supported by Puter.js for security reasons.</p>\n <p>To view this content properly, you need to serve it through a web server. Here are some options:</p>\n <ul>\n <li>Use a local development server (e.g., Python\'s built-in server or Node.js http-server)</li>\n <li>Upload the files to a web hosting service</li>\n <li>Use a local server application like XAMPP or MAMP</li>\n </ul>\n <p class="help-text">If you\'re not familiar with these options, consider reaching out to your development team or IT support for assistance.</p>\n </div>\n <p style="margin-top: 30px; border-top: 1px solid #eee; padding-top: 10px; text-align: center; font-size:13px;">\n <a href="https://docs.puter.com" target="_blank">Docs</a><span style="margin:10px; color: #CCC;">|</span>\n <a href="https://github.com/heyPuter/puter/" target="_blank">Github</a><span style="margin:10px; color: #CCC;">|</span>\n <a href="https://discord.com/invite/PQcx7Teh8u" target="_blank">Discord</a>\n </p>\n </div>\n </dialog>':s+='<dialog>\n <div class="puter-dialog-content">\n <span class="close-btn">&#x2715</span>\n <a href="https://puter.com" target="_blank" style="border:none; outline:none; display: block; width: 70px; height: 70px; margin: 0 auto; border-radius: 4px;"><img style="display: block; width: 70px; height: 70px; margin: 0 auto; border-radius: 4px;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAAKCJJREFUeJztnQl0U3X2x5VNFFGBAqVUFlkEZAcFFdlUkEHcYEYcBQSVRREEUUQZt1EUBGEQBxUYFkFZZF+KQBfovqfN9rK2TZq9SbM3SeGc/23zFzHvJU1Km/te+3vnczzYNnnfd9+9v9/97bfccg9FIDRf8BUQCIjgKyAQEMFXQCAggq+AQEAEXwGBgAi+AgIBEXwFBAIi+AoIBETwFRAIiOArIBAQwVdAICCCr4BAQARfAYGACL4CAgERfAUEAiL4CggERPAVEAiI4CsgEBDBV0AgIIKvgEBABF8BgYAIvgICARF8BQQC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dJtP2nO/a5Pz9JfSdcdO1W+fnPJ3+dJ+o4Qhz7+jNDw4CsgEBDBV0AgIIKvgEBABF8BgYAIvgICARF8BQQCIvgKCARE8BUQCIjgKyAQEMFXQCAggq+AQEAEXwGBgAi+AgIBEXwFBAIi+AoIBETwFRAIiOArIBAQwVdAICCCr4BAQARfAYGACL4CAgERfAUEAiL4CggERPAVEAiI4CsgEBDBV0AgIIKvgEBABF8BgYAIvgICARF8BQQCIvgKCARE8BUQCIjgKyAQEMFXQCAggq+AQEAEXwGBgAi+AgIBEXwFBAIi+AoIBETwFRAIiOArIBAQwVdAIODxf/VVGcawPhaZAAAAAElFTkSuQmCC"/></a>\n <p class="about">This website uses Puter to bring you safe, secure, and private AI and Cloud features.</p>\n <div class="buttons">\n <button class="button button-auth" id="launch-auth-popup-cancel">Cancel</button>\n <button class="button button-primary button-auth" id="launch-auth-popup" style="margin-left:10px;">Continue</button>\n </div>\n <p style="text-align: center; margin-top: -15px; font-size: 14px;">Powered by <a href="https://developer.puter.com/?utm_source=sdk-splash" target="_blank">Puter</a></p>\n <p class="launch-auth-popup-footnote">By clicking \'Continue\' you agree to Puter\'s <a href="https://puter.com/terms" target="_blank">Terms of Service</a> and <a href="https://puter.com/privacy" target="_blank">Privacy Policy</a>.</p>\n </div>\n </dialog>',this.shadowRoot.innerHTML=s,this.messageListener=async e=>{"puter.token"===e.data.msg&&(this.close(),puter.setAuthToken(e.data.token),puter.setAppID(e.data.app_uid),window.removeEventListener("message",this.messageListener),puter.puterAuthState.authGranted=!0,this.resolve(),puter.onAuth&&"function"==typeof puter.onAuth&&puter.getUser().then(e=>{puter.onAuth(e)}),puter.puterAuthState.isPromptOpen=!1,puter.puterAuthState.resolver&&(puter.puterAuthState.authGranted?puter.puterAuthState.resolver.resolve():puter.puterAuthState.resolver.reject(),puter.puterAuthState.resolver=null))}}cancelListener=()=>{this.close(),window.removeEventListener("message",this.messageListener),puter.puterAuthState.authGranted=!1,puter.puterAuthState.isPromptOpen=!1,this.reject(new Error("User cancelled the authentication")),puter.puterAuthState.resolver&&(puter.puterAuthState.resolver.reject(new Error("User cancelled the authentication")),puter.puterAuthState.resolver=null)};connectedCallback(){this.shadowRoot.querySelector("#launch-auth-popup")?.addEventListener("click",()=>{var e=screen.width/2-300,t=screen.height/2-200;window.open(`${puter.defaultGUIOrigin}/?embedded_in_popup=true&request_auth=true${window.crossOriginIsolated?"&cross_origin_isolated=true":""}`,"Puter",`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=400, top=${t}, left=${e}`)}),window.addEventListener("message",this.messageListener),this.shadowRoot.querySelector("#launch-auth-popup-cancel")?.addEventListener("click",this.cancelListener),this.shadowRoot.querySelector(".close-btn")?.addEventListener("click",this.cancelListener)}open(){if(this.hasUserActivation()){let s=600,n=400,r="Puter";var e=screen.width/2-s/2,t=screen.height/2-n/2;window.open(`${puter.defaultGUIOrigin}/?embedded_in_popup=true&request_auth=true${window.crossOriginIsolated?"&cross_origin_isolated=true":""}`,r,`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${s}, height=${n}, top=${t}, left=${e}`)}else this.shadowRoot.querySelector("dialog").showModal()}close(){this.shadowRoot.querySelector("dialog").close()}}rs.__proto__===globalThis.HTMLElement&&customElements.define("puter-dialog",rs);const is=rs,os=Symbol("FILE_SAVE_CANCELLED"),as=Symbol("FILE_OPEN_CANCELLED");class cs extends zt{#r="*";#i;#o;static from(e,t){const s=new cs(t,{target:e.appInstanceID,usesSDK:e.usesSDK});return s.response=e.response,s}constructor(e,{target:t,usesSDK:s}){super(["message","close"]),this.messageTarget=e.messageTarget,this.appInstanceID=e.appInstanceID,this.targetAppInstanceID=t,this.#i=!0,this.#o=s,this.log=e.puter.logger.fields({category:"ipc"}),this.log.fields({cons_source:e.appInstanceID,source:e.puter.appInstanceID,target:t}).info(`AppConnection created to ${t}`,this),globalThis.document&&window.addEventListener("message",e=>{if("messageToApp"===e.data.msg){if(e.data.appInstanceID!==this.targetAppInstanceID)return;return e.data.targetAppInstanceID!==this.appInstanceID?void console.error(`AppConnection received message intended for wrong app! appInstanceID=${this.appInstanceID}, target=${e.data.targetAppInstanceID}`):void this.emit("message",e.data.contents)}if("appClosed"===e.data.msg){if(e.data.appInstanceID!==this.targetAppInstanceID)return;this.#i=!1,this.emit("close",{appInstanceID:this.targetAppInstanceID,statusCode:e.data.statusCode})}})}get usesSDK(){return this.#o}postMessage(e){this.#i?this.#o?this.messageTarget.postMessage({msg:"messageToApp",appInstanceID:this.appInstanceID,targetAppInstanceID:this.targetAppInstanceID,targetAppOrigin:"*",contents:e},this.#r):console.warn("Trying to post message to a non-SDK app"):console.warn("Trying to post message on a closed AppConnection")}close(){this.#i?this.messageTarget.postMessage({msg:"closeApp",appInstanceID:this.appInstanceID,targetAppInstanceID:this.targetAppInstanceID},this.#r):console.warn("Trying to close an app on a closed AppConnection")}}const ls=class extends zt{#t=1;itemWatchCallbackFunctions=[];appInstanceID;parentInstanceID;#a=null;#c=[];#l;#h;#u;#s;#d=new Map;#p=!1;#g=null;#f(e,t,s={}){const n=this.#t++;this.messageTarget?.postMessage({msg:e,env:this.env,appInstanceID:this.appInstanceID,uuid:n,...s},"*"),this.#c[n]=t}#m(e,t){const s=this.util.rpc.getDehydrator({target:this.messageTarget});this.messageTarget?.postMessage({msg:e,env:this.env,appInstanceID:this.appInstanceID,value:s.dehydrate(t)},"*")}async#y({callback:e,method:t,parameters:s}){let n,r;await new Promise(e=>{n=new Promise(t=>{r=t,e()})});const i=this.util.rpc.registerCallback(r);this.messageTarget?.postMessage({$:"puter-ipc",v:2,appInstanceID:this.appInstanceID,env:this.env,msg:t,parameters:s,uuid:i},"*");const o=await n;return e&&e(o),o}constructor(e,{appInstanceID:t,parentInstanceID:s}){const n=["localeChanged","themeChanged","connection"];if(super(n),this.#s=n,this.context=e,this.appInstanceID=t,this.parentInstanceID=s,this.appID=e.appID,this.env=e.env,this.util=e.util,"app"===this.env)this.messageTarget=window.parent;else if("gui"===this.env)return;this.context=this.context.sub({appInstanceID:this.appInstanceID,messageTarget:this.messageTarget}),this.parentInstanceID&&(this.#a=new cs(this.context,{target:this.parentInstanceID,usesSDK:!0})),this.messageTarget?.postMessage({msg:"READY",appInstanceID:this.appInstanceID},"*"),globalThis.document&&window.addEventListener("focus",e=>{this.messageTarget?.postMessage({msg:"windowFocused",appInstanceID:this.appInstanceID},"*")});let r=null;globalThis.document&&window.addEventListener("message",async e=>{if(e.data){if(e.data.error)throw e.data.error;if(e.data.msg&&"focus"===e.data.msg)window.focus();else if(e.data.msg&&"click"===e.data.msg){const t=document.elementFromPoint(e.data.x,e.data.y);null!==t&&t.click()}else if(e.data.msg&&"drag"===e.data.msg){const t=document.elementFromPoint(e.data.x,e.data.y);if(t!==r){if(r){const t=new Event("dragleave",{bubbles:!0,cancelable:!0,clientX:e.data.x,clientY:e.data.y});r.dispatchEvent(t)}if(t){const s=new Event("dragenter",{bubbles:!0,cancelable:!0,clientX:e.data.x,clientY:e.data.y});t.dispatchEvent(s)}r=t}}else if(e.data.msg&&"drop"===e.data.msg){if(r){const t=new CustomEvent("drop",{bubbles:!0,cancelable:!0,detail:{clientX:e.data.x,clientY:e.data.y,items:e.data.items}});r.dispatchEvent(t),r=null}}else if("windowWillClose"===e.data.msg)void 0===this.#l?this.messageTarget?.postMessage({msg:!0,appInstanceID:this.appInstanceID,original_msg_id:e.data.msg_id},"*"):(this.messageTarget?.postMessage({msg:!1,appInstanceID:this.appInstanceID,original_msg_id:e.data.msg_id},"*"),this.#l());else if("itemsOpened"===e.data.msg)if(void 0===this.#h)this.messageTarget?.postMessage({msg:!0,appInstanceID:this.appInstanceID,original_msg_id:e.data.msg_id},"*");else{this.messageTarget?.postMessage({msg:!1,appInstanceID:this.appInstanceID,original_msg_id:e.data.msg_id},"*");let t=[];if(e.data.items.length>0)for(let s=0;s<e.data.items.length;s++)t.push(new Dt(e.data.items[s]));this.#h(t)}else if("getAppDataSucceeded"===e.data.msg){let t=new Dt(e.data.item);e.data.original_msg_id&&this.#c[e.data.original_msg_id]&&this.#c[e.data.original_msg_id](t)}else if("instancesOpenSucceeded"===e.data.msg)e.data.original_msg_id&&this.#c[e.data.original_msg_id]&&this.#c[e.data.original_msg_id](e.data.instancesOpen);else if("readAppDataFileSucceeded"===e.data.msg){let t=new Dt(e.data.item);e.data.original_msg_id&&this.#c[e.data.original_msg_id]&&this.#c[e.data.original_msg_id](t)}else if("readAppDataFileFailed"===e.data.msg)e.data.original_msg_id&&this.#c[e.data.original_msg_id]&&this.#c[e.data.original_msg_id](null);else if(void 0!==e.data.original_msg_id&&this.#c[e.data.original_msg_id]){if("fileOpenPicked"===e.data.msg){if(1===e.data.items.length)this.#c[e.data.original_msg_id](new Dt(e.data.items[0]));else if(e.data.items.length>1){let t=[];for(let s=0;s<e.data.items.length;s++)t.push(new Dt(e.data.items[s]));this.#c[e.data.original_msg_id](t)}}else if("directoryPicked"===e.data.msg){if(1===e.data.items.length)this.#c[e.data.original_msg_id](new Dt({uid:e.data.items[0].uid,name:e.data.items[0].fsentry_name,path:e.data.items[0].path,readURL:e.data.items[0].read_url,writeURL:e.data.items[0].write_url,metadataURL:e.data.items[0].metadata_url,isDirectory:!0,size:e.data.items[0].fsentry_size,accessed:e.data.items[0].fsentry_accessed,modified:e.data.items[0].fsentry_modified,created:e.data.items[0].fsentry_created}));else if(e.data.items.length>1){let t=[];for(let s=0;s<e.data.items.length;s++)t.push(new Dt(e.data.items[s]));this.#c[e.data.original_msg_id](t)}}else"colorPicked"===e.data.msg?this.#c[e.data.original_msg_id](e.data.color):"fontPicked"===e.data.msg?this.#c[e.data.original_msg_id](e.data.font):"alertResponded"===e.data.msg||"promptResponded"===e.data.msg?this.#c[e.data.original_msg_id](e.data.response):"languageReceived"===e.data.msg?this.#c[e.data.original_msg_id](e.data.language):"fileSaved"===e.data.msg?this.#c[e.data.original_msg_id](new Dt(e.data.saved_file)):"fileSaveCancelled"===e.data.msg?this.#c[e.data.original_msg_id](os):"fileOpenCancelled"===e.data.msg?this.#c[e.data.original_msg_id](as):this.#c[e.data.original_msg_id](e.data);delete this.#c[e.data.original_msg_id]}else if("itemChanged"===e.data.msg&&e.data.data&&e.data.data.uid)this.itemWatchCallbackFunctions[e.data.data.uid]&&"function"==typeof this.itemWatchCallbackFunctions[e.data.data.uid]&&this.itemWatchCallbackFunctions[e.data.data.uid](e.data.data);else if("broadcast"===e.data.msg){const{name:t,data:s}=e.data;if(!this.#s.includes(t))return;this.emit(t,s),this.#d.set(t,s)}else if("connection"===e.data.msg){e.data.usesSDK=!0;const t=cs.from(e.data,this.context),s=t=>{this.messageTarget?.postMessage({$:"connection-resp",connection:e.data.appInstanceID,accept:!0,value:t},"*")},n=t=>{this.messageTarget?.postMessage({$:"connection-resp",connection:e.data.appInstanceID,accept:!1,value:t},"*")};this.emit("connection",{conn:t,accept:s,reject:n})}}}),globalThis.document?.addEventListener("mousemove",async e=>{this.mouseX=e.clientX,this.mouseY=e.clientY,this.messageTarget?.postMessage({msg:"mouseMoved",appInstanceID:this.appInstanceID,x:this.mouseX,y:this.mouseY},"*")}),globalThis.document?.addEventListener("click",async e=>{this.mouseX=e.clientX,this.mouseY=e.clientY,this.messageTarget?.postMessage({msg:"mouseClicked",appInstanceID:this.appInstanceID,x:this.mouseX,y:this.mouseY},"*")})}onWindowClose(e){this.#l=e}onItemsOpened(e){if(!this.#h){let t=new URLSearchParams(globalThis.location.search);if(t.has("puter.item.name")&&t.has("puter.item.uid")&&t.has("puter.item.read_url")){let s=t.get("puter.item.path");s.startsWith("~/")||s.startsWith("/")||(s=`~/${s}`),e([new Dt({name:t.get("puter.item.name"),path:s,uid:t.get("puter.item.uid"),readURL:t.get("puter.item.read_url"),writeURL:t.get("puter.item.write_url"),metadataURL:t.get("puter.item.metadata_url"),size:t.get("puter.item.size"),accessed:t.get("puter.item.accessed"),modified:t.get("puter.item.modified"),created:t.get("puter.item.created")})])}}this.#h=e}wasLaunchedWithItems(){const e=new URLSearchParams(globalThis.location.search);return e.has("puter.item.name")&&e.has("puter.item.uid")&&e.has("puter.item.read_url")}onLaunchedWithItems(e){if(!this.#u){let t=new URLSearchParams(globalThis.location.search);if(t.has("puter.item.name")&&t.has("puter.item.uid")&&t.has("puter.item.read_url")){let s=t.get("puter.item.path");s.startsWith("~/")||s.startsWith("/")||(s=`~/${s}`),e([new Dt({name:t.get("puter.item.name"),path:s,uid:t.get("puter.item.uid"),readURL:t.get("puter.item.read_url"),writeURL:t.get("puter.item.write_url"),metadataURL:t.get("puter.item.metadata_url"),size:t.get("puter.item.size"),accessed:t.get("puter.item.accessed"),modified:t.get("puter.item.modified"),created:t.get("puter.item.created")})])}}this.#u=e}requestEmailConfirmation(){return new Promise((e,t)=>{this.#f("requestEmailConfirmation",e,{})})}alert(e,t,s,n){return new Promise(n=>{this.#f("ALERT",n,{message:e,buttons:t,options:s})})}openDevPaymentsAccount(){return new Promise(e=>{this.#f("openDevPaymentsAccount",e,{})})}instancesOpen(e){return new Promise(e=>{this.#f("getInstancesOpen",e,{})})}socialShare(e,t,s,n){return new Promise(n=>{this.#f("socialShare",n,{url:e,message:t,options:s})})}prompt(e,t,s,n){return new Promise(n=>{this.#f("PROMPT",n,{message:e,placeholder:t,options:s})})}showDirectoryPicker(e,t){return new Promise((t,s)=>{if(!globalThis.open)return s("This API is not compatible in Web Workers.");const n=this.#t++;if("app"===this.env)this.messageTarget?.postMessage({msg:"showDirectoryPicker",appInstanceID:this.appInstanceID,uuid:n,options:e,env:this.env},"*");else{let t=700,s=400,o="Puter: Open Directory";var r=screen.width/2-t/2,i=screen.height/2-s/2;window.open(`${puter.defaultGUIOrigin}/action/show-directory-picker?embedded_in_popup=true&msg_id=${n}&appInstanceID=${this.appInstanceID}&env=${this.env}&options=${JSON.stringify(e)}`,o,`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${t}, height=${s}, top=${i}, left=${r}`)}this.#c[n]=t})}showOpenFilePicker(t,s){const n=new e.libs.promise.TeePromise,r=new Promise((e,s)=>{if(!globalThis.open)return s("This API is not compatible in Web Workers.");const r=this.#t++;if("app"===this.env)this.messageTarget?.postMessage({msg:"showOpenFilePicker",appInstanceID:this.appInstanceID,uuid:r,options:t??{},env:this.env},"*");else{let e=700,s=400,n="Puter: Open File";var i=screen.width/2-e/2,o=screen.height/2-s/2;window.open(`${puter.defaultGUIOrigin}/action/show-open-file-picker?embedded_in_popup=true&msg_id=${r}&appInstanceID=${this.appInstanceID}&env=${this.env}&options=${JSON.stringify(t??{})}`,n,`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${e}, height=${s}, top=${o}, left=${i}`)}this.#c[r]=t=>{t!==as?(n.resolve(t),e(t)):n.resolve(void 0)}});return r.undefinedOnCancel=n,r}showFontPicker(e){return new Promise(t=>{this.#f("showFontPicker",t,{options:e??{}})})}showColorPicker(e){return new Promise(t=>{this.#f("showColorPicker",t,{options:e??{}})})}requestUpgrade(){return new Promise(e=>{this.#f("requestUpgrade",e,{})})}showSaveFilePicker(t,s,n){const r=new e.libs.promise.TeePromise,i=new Promise((e,i)=>{if(!globalThis.open)return i("This API is not compatible in Web Workers.");const o=this.#t++;n||"[object URL]"!==Object.prototype.toString.call(t)||(n="url");const a="url"===n?t.toString():void 0,c=["move","copy"].includes(n)?t:void 0;if("app"===this.env)this.messageTarget?.postMessage({msg:"showSaveFilePicker",appInstanceID:this.appInstanceID,content:a?void 0:t,save_type:n,url:a,source_path:c,suggestedName:s??"",env:this.env,uuid:o},"*");else{window.addEventListener("message",async e=>{"sendMeFileData"===e.data?.msg&&(e.source.postMessage({msg:"showSaveFilePickerPopup",content:a?void 0:t,url:a?a.toString():void 0,suggestedName:s??"",env:this.env,uuid:o},"*"),window.removeEventListener("message",this))});let e=new Blob([t],{type:"application/octet-stream"}),n=URL.createObjectURL(e),r=700,i=400,c="Puter: Save File";var l=screen.width/2-r/2,h=screen.height/2-i/2;window.open(`${puter.defaultGUIOrigin}/action/show-save-file-picker?embedded_in_popup=true&msg_id=${o}&appInstanceID=${this.appInstanceID}&env=${this.env}&blobUrl=${encodeURIComponent(n)}`,c,`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${r}, height=${i}, top=${h}, left=${l}`)}this.#c[o]=t=>{t!==os?(r.resolve(t),e(t)):r.resolve(void 0)}});return i.undefinedOnCancel=r,i}setWindowTitle(e,t,s){return"function"==typeof t?t=void 0:"object"==typeof t&&null!==t&&(t=t.id),new Promise(s=>{this.#f("setWindowTitle",s,{new_title:e,window_id:t})})}setWindowWidth(e,t,s){return"function"==typeof t?t=void 0:"object"==typeof t&&null!==t&&(t=t.id),new Promise(s=>{this.#f("setWindowWidth",s,{width:e,window_id:t})})}setWindowHeight(e,t,s){return"function"==typeof t?t=void 0:"object"==typeof t&&null!==t&&(t=t.id),new Promise(s=>{this.#f("setWindowHeight",s,{height:e,window_id:t})})}setWindowSize(e,t,s,n){return"function"==typeof s?s=void 0:"object"==typeof s&&null!==s&&(s=s.id),new Promise(n=>{this.#f("setWindowSize",n,{width:e,height:t,window_id:s})})}setWindowPosition(e,t,s,n){return"function"==typeof s?s=void 0:"object"==typeof s&&null!==s&&(s=s.id),new Promise(n=>{this.#f("setWindowPosition",n,{x:e,y:t,window_id:s})})}setWindowY(e,t,s){return"function"==typeof t?t=void 0:"object"==typeof t&&null!==t&&(t=t.id),new Promise(s=>{this.#f("setWindowY",s,{y:e,window_id:t})})}setWindowX(e,t,s){return"function"==typeof t?t=void 0:"object"==typeof t&&null!==t&&(t=t.id),new Promise(s=>{this.#f("setWindowX",s,{x:e,window_id:t})})}showWindow(){this.#m("showWindow")}hideWindow(){this.#m("hideWindow")}toggleWindow(){this.#m("toggleWindow")}setMenubar(e){this.#m("setMenubar",e)}requestPermission(e){return new Promise(t=>{if("app"===this.env)return new Promise(t=>{this.#f("requestPermission",t,{options:e})});t(!1)})}disableMenuItem(e){this.#m("disableMenuItem",{id:e})}enableMenuItem(e){this.#m("enableMenuItem",{id:e})}setMenuItemIcon(e,t){this.#m("setMenuItemIcon",{id:e,icon:t})}setMenuItemIconActive(e,t){this.#m("setMenuItemIconActive",{id:e,icon:t})}setMenuItemChecked(e,t){this.#m("setMenuItemChecked",{id:e,checked:t})}contextMenu(e){this.#m("contextMenu",e)}getEntriesFromDataTransferItems=async function(e,t={raw:!1}){const s=e=>{if(this.getEntriesFromDataTransferItems.didShowInfo)return;if("EncodingError"!==e.name)return;this.getEntriesFromDataTransferItems.didShowInfo=!0;const t=`${e.name} occurred within datatransfer-files-promise module\nError message: "${e.message}"\nTry serving html over http if currently you are running it from the filesystem.`;console.warn(t)},n=(e,t)=>new Promise((n,i)=>{e.readEntries(async e=>{let s=[];for(let n of e){const e=await r(n,t);s=s.concat(e)}n(s)},e=>{s(e),i(e)})}),r=async(e,r="")=>{if(null!==e){if(e.isFile){const n=await((e,n="")=>new Promise((r,i)=>{e.file(e=>{t.raw||(e.filepath=n+e.name),r(e)},e=>{s(e),i(e)})}))(e,r);return[n]}if(e.isDirectory){const t=await(async(e,t)=>{const s=e.createReader(),r=`${t+e.name}/`;let i,o=[];do{i=await n(s,r),o=o.concat(i)}while(i.length>0);return o})(e,r);return t.push(e),t}}};let i=[],o=[];for(let t=0,s=e.length;t<s;t++)o.push(e[t].webkitGetAsEntry());for(let e of o){const t=await r(e);i=i.concat(t)}return i};authenticateWithPuter(){if("web"===this.env)return this.authToken?new Promise(e=>{e()}):puter.puterAuthState.isPromptOpen?new Promise((e,t)=>{puter.puterAuthState.resolver={resolve:e,reject:t}}):(puter.puterAuthState.isPromptOpen=!0,puter.puterAuthState.authGranted=null,new Promise((e,t)=>{if(puter.authToken)e();else{const s=new is(e,t);document.body.appendChild(s),s.open()}}))}launchApp=async function(e,t,s){let n,r,i,o=e;if("object"==typeof o&&null!==o){const e=o;o=e.name||e.app_name,r=e.file_paths,t=t||e.args,s=s||e.callback,n=e.pseudonym,i=e.items}if(i){Array.isArray(i)||(i=[]);for(let e=0;e<i.length;e++)i[e]instanceof Dt&&(i[e]=i[e]._internalProperties.file_signature)}o&&o.includes("#(as)")&&([o,n]=o.split("#(as)")),o||(o=puter.appName);const a=await this.#y({method:"launchApp",callback:s,parameters:{app_name:o,file_paths:r,items:i,pseudonym:n,args:t}});return cs.from(a,this.context)};connectToInstance=async function(e){const t=await this.#y({method:"connectToInstance",parameters:{app_name:e}});return cs.from(t,this.context)};parentApp(){return this.#a}createWindow(e,t){return new Promise(t=>{this.#f("createWindow",e=>{t(e.window)},{options:e??{}})})}menubar(){document.querySelectorAll("style.puter-stylesheet").forEach(function(e){e.remove()});const e=document.createElement("style");e.classList.add("puter-stylesheet"),e.innerHTML="\n .--puter-menubar {\n border-bottom: 1px solid #e9e9e9;\n background-color: #fbf9f9;\n padding-top: 3px;\n padding-bottom: 2px;\n display: inline-block;\n position: fixed;\n top: 0;\n width: 100%;\n margin: 0;\n padding: 0;\n height: 31px;\n font-family: Arial, Helvetica, sans-serif;\n font-size: 13px;\n z-index: 9999;\n }\n \n .--puter-menubar, .--puter-menubar * {\n user-select: none;\n -webkit-user-select: none;\n cursor: default;\n }\n \n .--puter-menubar .dropdown-item-divider>hr {\n margin-top: 5px;\n margin-bottom: 5px;\n border-bottom: none;\n border-top: 1px solid #00000033;\n }\n \n .--puter-menubar>li {\n display: inline-block;\n padding: 10px 5px;\n }\n \n .--puter-menubar>li>ul {\n display: none;\n z-index: 999999999999;\n list-style: none;\n background-color: rgb(233, 233, 233);\n width: 200px;\n border: 1px solid #e4ebf3de;\n box-shadow: 0px 0px 5px #00000066;\n padding-left: 6px;\n padding-right: 6px;\n padding-top: 4px;\n padding-bottom: 4px;\n color: #333;\n border-radius: 4px;\n padding: 2px;\n min-width: 200px;\n margin-top: 5px;\n position: absolute;\n }\n \n .--puter-menubar .menubar-item {\n display: block;\n line-height: 24px;\n margin-top: -7px;\n text-align: center;\n border-radius: 3px;\n padding: 0 5px;\n }\n \n .--puter-menubar .menubar-item-open {\n background-color: rgb(216, 216, 216);\n }\n \n .--puter-menubar .dropdown-item {\n padding: 5px;\n padding: 5px 30px;\n list-style-type: none;\n user-select: none;\n font-size: 13px;\n }\n \n .--puter-menubar .dropdown-item-icon, .--puter-menubar .dropdown-item-icon-active {\n pointer-events: none;\n width: 18px;\n height: 18px;\n margin-left: -23px;\n margin-bottom: -4px;\n margin-right: 5px;\n }\n .--puter-menubar .dropdown-item-disabled .dropdown-item-icon{\n display: inline-block !important;\n }\n .--puter-menubar .dropdown-item-disabled .dropdown-item-icon-active{\n display: none !important;\n }\n .--puter-menubar .dropdown-item-icon-active {\n display:none;\n }\n .--puter-menubar .dropdown-item:hover .dropdown-item-icon{\n display: none;\n }\n .--puter-menubar .dropdown-item:hover .dropdown-item-icon-active{\n display: inline-block;\n }\n .--puter-menubar .dropdown-item-hide-icon .dropdown-item-icon, .--puter-menubar .dropdown-item-hide-icon .dropdown-item-icon-active{\n display: none !important;\n }\n .--puter-menubar .dropdown-item a {\n color: #333;\n text-decoration: none;\n }\n \n .--puter-menubar .dropdown-item:hover, .--puter-menubar .dropdown-item:hover a {\n background-color: rgb(59 134 226);\n color: white;\n border-radius: 4px;\n }\n \n .--puter-menubar .dropdown-item-disabled, .--puter-menubar .dropdown-item-disabled:hover {\n opacity: 0.5;\n background-color: transparent;\n color: initial;\n cursor: initial;\n pointer-events: none;\n }\n \n .--puter-menubar .menubar * {\n user-select: none;\n } \n ",(document.head||document.getElementsByTagName("head")[0]).appendChild(e),document.addEventListener("click",function(e){if(e.target.classList.contains("dropdown-item-disabled"))return!1;e.target.classList.contains("menubar-item")||(document.querySelectorAll(".menubar-item.menubar-item-open").forEach(function(e){e.classList.remove("menubar-item-open")}),document.querySelectorAll(".dropdown").forEach(e=>e.style.display="none"))}),window.addEventListener("blur",function(e){document.querySelectorAll(".dropdown").forEach(function(e){e.style.display="none"}),document.querySelectorAll(".menubar-item.menubar-item-open").forEach(e=>e.classList.remove("menubar-item-open"))}),document.querySelectorAll(".menubar-item").forEach(e=>e.addEventListener("mousedown",function(e){document.querySelectorAll(".dropdown").forEach(function(e){e.style.display="none"}),document.querySelectorAll(".menubar-item.menubar-item-open").forEach(function(t){t!=e.target&&t.classList.remove("menubar-item-open")}),this.classList.contains("menubar-item-open")?document.querySelectorAll(".menubar-item.menubar-item-open").forEach(function(e){e.classList.remove("menubar-item-open")}):e.target.classList.contains("dropdown-item")||(this.classList.add("menubar-item-open"),function(e){const t=[];if(!e.parentNode)return t;let s=e.parentNode.firstChild;for(;s;)1===s.nodeType&&s!==e&&t.push(s),s=s.nextSibling;return t}(this).forEach(function(e){e.style.display="block"}))})),document.querySelectorAll(".--puter-menubar .menubar-item").forEach(e=>e.addEventListener("mouseover",function(e){const t=document.querySelectorAll(".menubar-item.menubar-item-open");t.length>0&&t[0]!==e.target&&e.target.dispatchEvent(new Event("mousedown"))}))}on(e,t){super.on(e,t),this.#s.includes(e)&&this.#d.has(e)&&t(this.#d.get(e))}#b=null;#w=null;showSpinner(e){if(this.#p)return;if(!document.getElementById("puter-spinner-styles")){const e=document.createElement("style");e.id="puter-spinner-styles",e.textContent="\n .puter-loading-spinner {\n width: 50px;\n height: 50px;\n border: 5px solid #f3f3f3;\n border-top: 5px solid #3498db;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin-bottom: 10px;\n }\n \n .puter-loading-text {\n font-family: Arial, sans-serif;\n font-size: 16px;\n margin-top: 10px;\n text-align: center;\n width: 100%;\n }\n \n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n \n .puter-loading-container {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n min-height: 120px; \n background: #ffffff; \n border-radius: 10px;\n padding: 20px;\n min-width: 120px;\n }\n ",document.head.appendChild(e)}const t=document.createElement("div");t.classList.add("puter-loading-overlay"),Object.assign(t.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",backgroundColor:"rgba(255, 255, 255, 0.8)",zIndex:"2147483647",display:"flex",justifyContent:"center",alignItems:"center",pointerEvents:"all"});const s=document.createElement("div");s.classList.add("puter-loading-container"),s.innerHTML=`\n <div class="puter-loading-spinner"></div>\n <div class="puter-loading-text">${e??"Working..."}</div>\n `,t.appendChild(s),document.body.appendChild(t),this.#p=!0,this.#b=Date.now(),this.#g=setTimeout(()=>{this.#g=null},1e3)}hideSpinner(){if(!this.#p)return;this.#g&&(clearTimeout(this.#g),this.#g=null);const e=Date.now()-this.#b,t=Math.max(0,1200-e);t>0?(this.#w&&clearTimeout(this.#w),this.#w=setTimeout(()=>{this.#v()},t)):this.#v()}#v(){const e=document.querySelector(".puter-loading-overlay");e&&e.parentNode?.removeChild(e),this.#p=!1,this.#b=null,this.#w=null}isWorkingActive(){return this.#p}getLanguage(){return"gui"===this.env?new Promise(e=>{e(window.locale)}):new Promise(e=>{this.#f("getLanguage",e,{})})}},hs="9a9c83a4-7897-43a0-93b9-53217b84fde6";class us{#_=1;constructor(){this.callbacks=new Map}register_callback(e){const t=this.#_++;return this.callbacks.set(t,e),t}attach_to_source(e){e.addEventListener("message",e=>{const{data:t}=e;if(t&&"object"==typeof t&&t.$SCOPE===hs){const{id:e,args:s}=t,n=this.callbacks.get(e);n&&n(...s)}})}}class ds{constructor({callbackManager:e}){this.callbackManager=e}dehydrate(e){return this.dehydrate_value_(e)}dehydrate_value_(e){if("function"==typeof e){const t=this.callbackManager.register_callback(e);return{$SCOPE:hs,id:t}}if(Array.isArray(e))return e.map(this.dehydrate_value_.bind(this));if("object"==typeof e&&null!==e){const t={};for(const s in e)t[s]=this.dehydrate_value_(e[s]);return t}return e}}class ps{constructor({target:e}){this.target=e}hydrate(e){return this.hydrate_value_(e)}hydrate_value_(e){if(e&&"object"==typeof e&&e.$SCOPE===hs){const{id:t}=e;return(...e)=>{this.target.postMessage({$SCOPE:hs,id:t,args:e},"*")}}if(Array.isArray(e))return e.map(this.hydrate_value_.bind(this));if("object"==typeof e&&null!==e){const t={};for(const s in e)t[s]=this.hydrate_value_(e[s]);return t}return e}}class gs{constructor(){this.rpc=new fs}}class fs{constructor(){this.callbackManager=new us,this.callbackManager.attach_to_source(globalThis)}getDehydrator(){return new ds({callbackManager:this.callbackManager})}getHydrator({target:e}){return new ps({target:e})}registerCallback(e){return this.callbackManager.register_callback(e)}send(e,t,...s){e.postMessage({$SCOPE:hs,id:t,args:s},"*")}}class ms{constructor(e){this.authToken=e}async create(e,t,s){if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){throw"Authentication failed."}let n;"string"==typeof s&&(n=(await puter.apps.list()).find(e=>e.name===s).uid),e=e.toLocaleLowerCase();let r=await puter.kv.get("user-workers");r||(r={}),t=yt(t);const i=await U(["authorization","filePath","workerName","appId"],"workers","worker-service","create")(puter.authToken,t,e,n);if(!i.success)throw new Error(i?.errors||"Driver failed to execute, do you have the necessary permissions?");return r[e]={filePath:t,url:i.url,deployTime:Date.now(),createTime:Date.now()},await puter.kv.set("user-workers",r),i}async exec(...e){if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){throw"Authentication failed."}const t=new Request(...e);return t.headers.get("puter-auth")||t.headers.set("puter-auth",puter.authToken),fetch(t)}async list(){if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){throw"Authentication failed."}return await U([],"workers","worker-service","getFilePaths")()}async get(e){if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){throw"Authentication failed."}return e=e.toLocaleLowerCase(),(await U(["workerName"],"workers","worker-service","getFilePaths")(e))[0]}async delete(e){if(!puter.authToken&&"web"===puter.env)try{await puter.ui.authenticateWithPuter()}catch(e){throw"Authentication failed."}e=e.toLocaleLowerCase();const t=await U(["authorization","workerName"],"workers","worker-service","destroy")(puter.authToken,e);if(t.result){let t=await puter.kv.get("user-workers");return t||(t={}),delete t[e],await puter.kv.set("user-workers",t),!0}throw t.result||new Error("Worker doesn't exist"),new Error(t?.errors||"Driver failed to execute, do you have the necessary permissions?")}async getLoggingHandle(e){const t=await U([],"workers","worker-service","getLoggingUrl")(puter.authToken,e),s=new WebSocket(`${t}/${puter.authToken}/${e}`),n=new EventTarget;return n.onLog=e=>{},Object.defineProperty(n,"start",{enumerable:!1,value:async e=>{s.addEventListener("message",t=>{e.enqueue(JSON.parse(t.data))}),s.addEventListener("close",t=>{try{e.close()}catch(e){}})}}),Object.defineProperty(n,"cancel",{enumerable:!1,value:async()=>{s.close()}}),s.addEventListener("message",e=>{const t=new MessageEvent("log",{data:JSON.parse(e.data)});n.dispatchEvent(t),n.onLog(t)}),n.close=s.close,new Promise((e,t)=>{let r=!1;s.onopen=()=>{r=!0,e(n)},s.onerror=()=>{r||t("Failed to open logging connection")}})}}const{TTopics:ys}=e.traits;class bs extends e.concepts.Service{static TOPICS=["update"];static PROPERTIES={auth_token:{post_set(e){this.as(ys).pub("update")}},api_origin:{post_set(){this.as(ys).pub("update")}}};get_api_info(){const e=this,t={};return[["auth_token","auth_token"],["authToken","auth_token"],["APIOrigin","api_origin"],["api_origin","api_origin"]].forEach(([s,n])=>{Object.defineProperty(t,s,{get:()=>e[n],set:t=>e})}),t}}const ws="TFilesystem";class vs extends e.AdvancedBase{static PROPERTIES={delegate:()=>{}};constructor({delegate:e}){super(),this.delegate=e}static IMPLEMENTS={[ws]:{stat:async function(e){return this.delegate.stat(e)},readdir:async function(e){return this.delegate.readdir(e)}}}}class _s extends e.AdvancedBase{constructor({api_info:e}){super(),this.api_info=e}static IMPLEMENTS={[ws]:{stat:async function(e){this.ensure_auth_();const t=new qt.TeePromise,s=new C("/stat",this.api_info.APIOrigin,void 0,"post","text/plain;actually=json");R(s,void 0,void 0,t.resolve.bind(t),t.reject.bind(t));let n={};return void 0!==e.uid?n.uid=e.uid:void 0!==e.path&&(n.path=yt(e.path)),n.return_subdomains=e.returnSubdomains,n.return_permissions=e.returnPermissions,n.return_versions=e.returnVersions,n.return_size=e.returnSize,n.auth_token=this.api_info.authToken,s.send(JSON.stringify(n)),await t},readdir:async function(e){this.ensure_auth_();const t=new qt.TeePromise,s=new C("/readdir",this.api_info.APIOrigin,void 0,"post","text/plain;actually=json");return R(s,void 0,void 0,t.resolve.bind(t),t.reject.bind(t)),s.send(JSON.stringify({path:yt(e.path),auth_token:this.api_info.authToken})),await t}}};ensure_auth_(){if(!this.api_info.authToken&&"web"===puter.env)try{this.ui.authenticateWithPuter()}catch(e){throw new Error("Authentication failed.")}}}class ks extends e.AdvancedBase{static PROPERTIES={assocs_path_:()=>({}),assocs_uuid_:()=>({}),entries:()=>({})};get_entry_ei(e){if(Array.isArray(e)){for(const t of e){const e=this.get_entry_ei(t);if(e)return e}return}console.log("GET ENTRY EI",e);const t=this.assocs_path_[e]||this.assocs_uuid_[e]||e;if(t)return this.entries[t]}add_entry({id:e}={}){const t=e??O(),s={id:t,stat_has:{},stat_exp:0,locks:{stat:new qt.RWLock,members:new qt.RWLock}};return this.entries[t]=s,s}assoc_path(e,t){console.log("ASSOC PATH",e,t),this.assocs_path_[e]=t}assoc_uuid(e,t){e!==t&&(this.assocs_uuid_[e]=t)}}class As extends vs{constructor(e){super(e),this.cacheFS=new ks}static IMPLEMENTS={[ws]:{stat:async function(e){let t=this.cacheFS.get_entry_ei(e.path??e.uid);const s=["subdomains","permissions","versions","size"];let n,r,i={};for(const t of s)e[`return${t.charAt(0).toUpperCase()}${t.slice(1)}`]&&(i[t]=!0);if(t&&t.stat&&t.stat_exp>Date.now()){const e=await t.locks.stat.rlock();(e=>{for(const t of s)if(i[t]&&!e.stat_has[t])return!1;return!0})(t)&&(n=t.stat),e.unlock()}if(n)return console.log("CACHE HIT"),n;console.log("CACHE MISS"),t&&(r=await t.locks.stat.wlock()),console.log("DOING THE STAT",e);const o=await this.delegate.stat(e);let a=!!t;return t=this.cacheFS.get_entry_ei([o.uid,o.path]),t&&(a&&r.unlock(),r=await t.locks.stat.wlock()),t||(t=this.cacheFS.add_entry({id:o.uid}),this.cacheFS.assoc_path(o.path,t.id),this.cacheFS.assoc_uuid(o.uid,t.id),r=await t.locks.stat.wlock()),t.stat=o,t.stat_has={...i},t.stat_exp=Date.now()+5e3,r.unlock(),console.log("RETRUNING THE ENTRY",o),o},readdir:async function(e){let t=this.cacheFS.get_entry_ei([e.path,e.uid]);console.log("CENT",t,e);let s,n=null;if(t&&t.members&&t.members_exp>Date.now()){console.log("MEMBERS",t.members),n=[];const s=await t.locks.stat.rlock();for(const s of t.members){const t=this.cacheFS.get_entry_ei(s);if(!t||!t.stat||t.stat_exp<=Date.now()){console.log("NO MEMBER OR STAT",t),n=null;break}if(console.log("member",t),!e.no_assocs&&!t.stat_has.subdomains){n=null;break}if(!e.no_assocs&&!t.stat_has.apps){n=null;break}if(!e.no_thumbs&&!t.stat_has.thumbnail){n=null;break}console.log("PUSHING",t.stat),n.push(t.stat)}s.unlock()}if(console.log("STATS????",n),n)return n;t&&(s=await t.locks.members.wlock());const r=await this.delegate.readdir(e);t||(t=this.cacheFS.add_entry(e.uid?{id:e.uid}:{}),e.path&&this.cacheFS.assoc_path(e.path,t.id),s=await t.locks.members.wlock());let i=[];for(const t of r){let s=this.cacheFS.get_entry_ei([t.path,t.uid]);s||(s=this.cacheFS.add_entry({id:t.uid}),this.cacheFS.assoc_path(t.path,t.uid)),i.push(s.id),s.stat=t,s.stat_has={subdomains:!e.no_assocs,apps:!e.no_assocs,thumbnail:!e.no_thumbs},s.stat_exp=Date.now()+3e3}t.members=[];for(const e of i)t.members.push(e);return t.members_exp=Date.now()+5e3,s.unlock(),console.log("CACHE ENTRY?",t),r}}}}const Ts={id:"f485f1ba-de07-422c-8c4b-c2da057d4a44",uid:"f485f1ba-de07-422c-8c4b-c2da057d4a44",is_dir:!0,immutable:!0,name:"Test"};class xs extends e.AdvancedBase{constructor({rpc:e,messageTarget:t}){super(),this.rpc=e,this.messageTarget=t}static IMPLEMENTS={[ws]:{stat:async function(e){return Ts},readdir:async function(t){const s=new e.libs.promise.TeePromise,n=this.rpc.registerCallback(e=>{s.resolve(e)});return this.messageTarget.postMessage({$:"puter-fs",$callback:n,op:"readdir",args:t},"*"),await s}}}}class Is extends e.concepts.Service{static PROPERTIES={};static DEPENDS=["api-access"];static HOOKS=[{service:"api-access",event:"update",description:"\n re-initialize the socket connection whenever the\n authentication token or API origin is changed.\n ",async do(){this.initializeSocket()}}];_init(){this._.context.env,this.init_top_fs_(),this.initializeSocket()}init_app_fs_(){this.fs_nocache_=new xs({messageTarget:globalThis.parent,rpc:this._.context.util.rpc}).as(ws),this.filesystem=this.fs_nocache_}init_top_fs_(){const e=this._.context.services.get("api-access").get_api_info();this.fs_nocache_=new _s({api_info:e}).as(ws),this.fs_cache_=new As({delegate:this.fs_nocache_}).as(ws),this.fs_proxy_=new vs({delegate:this.fs_nocache_}),this.filesystem=this.fs_proxy_.as(ws)}cache_on(){this.fs_proxy_.delegate=this.fs_cache_}cache_off(){this.fs_proxy_.delegate=this.fs_nocache_}async initializeSocket(){this.socket&&this.socket.disconnect();const e=this._.context.services.get("api-access").get_api_info();void 0!==e.api_origin&&(this.socket=mt(e.api_origin,{auth:{auth_token:e.auth_token},autoUnref:"nodejs"===this._.context.env}),this.bindSocketEvents())}bindSocketEvents(){this.socket.on("connect",()=>{puter.debugMode&&console.log("FileSystem Socket: Connected",this.socket.id)}),this.socket.on("disconnect",()=>{puter.debugMode&&console.log("FileSystem Socket: Disconnected")}),this.socket.on("reconnect",e=>{puter.debugMode&&console.log("FileSystem Socket: Reconnected",this.socket.id)}),this.socket.on("reconnect_attempt",e=>{puter.debugMode&&console.log("FileSystem Socket: Reconnection Attemps",e)}),this.socket.on("reconnect_error",e=>{puter.debugMode&&console.log("FileSystem Socket: Reconnection Error",e)}),this.socket.on("reconnect_failed",()=>{puter.debugMode&&console.log("FileSystem Socket: Reconnection Failed")}),this.socket.on("error",e=>{puter.debugMode&&console.error("FileSystem Socket Error:",e)})}}const Es={id:"f485f1ba-de07-422c-8c4b-c2da057d4a44",uid:"f485f1ba-de07-422c-8c4b-c2da057d4a44",is_dir:!0,immutable:!0,name:"FromParentWindow"};class Ss extends e.concepts.Service{async _init(){const e=this._.context.services,t=this._.context.util;e.get("xd-incoming").register_tagged_listener("puter-fs",e=>{t.rpc.send(e.source,e.data.$callback,[Es])})}}class Ps extends e.concepts.Service{_init(){if(globalThis.when_puter_happens&&(!puter||"gui"===puter.env)){Array.isArray(globalThis.when_puter_happens)||(globalThis.when_puter_happens=[globalThis.when_puter_happens]);for(const e of globalThis.when_puter_happens)e({context:this._.context})}}}const Os=e.libs.promise.TeePromise;class Cs extends e.concepts.Service{_construct(){this.filter_listeners_=[],this.tagged_listeners_={}}_init(){globalThis.addEventListener("message",async e=>{for(const t of this.filter_listeners_){const s=new Os;if(t(e,s),await s)return}const t=e.data;if(!t)return;const s=t.$;if(s&&this.tagged_listeners_[s])for(const n of this.tagged_listeners_[s])n({data:t,source:e.source})})}register_filter_listener(e){this.filter_listeners_.push(e)}register_tagged_listener(e,t){this.tagged_listeners_[e]||(this.tagged_listeners_[e]=[]),this.tagged_listeners_[e].push(t)}}const Ds=function(){const s=new class{env;#k="https://api.puter.com";#A="https://puter.com";get defaultAPIOrigin(){return globalThis.PUTER_API_ORIGIN||"https://api.puter.com"}set defaultAPIOrigin(e){this.#k=e}get defaultGUIOrigin(){return globalThis.PUTER_ORIGIN||"https://puter.com"}set defaultGUIOrigin(e){this.#A=e}onAuth;puterAuthState={isPromptOpen:!1,authGranted:null,resolver:null};appInstanceID;parentInstanceID;static FSItem=Dt;eventHandlers={};debugMode=!1;initSubmodules=function(){this.util=new gs,this.registerModule("auth",K),this.registerModule("os",es),this.registerModule("fs",Ut),this.registerModule("ui",ls,{appInstanceID:this.appInstanceID,parentInstanceID:this.parentInstanceID}),this.registerModule("hosting",Bt),this.registerModule("apps",G),this.registerModule("ai",V),this.registerModule("kv",Ft),this.registerModule("threads",ns),this.registerModule("perms",ts),this.registerModule("drivers",Z),this.registerModule("debug",H),this.path=c};constructor(){this._cache=new t({dbName:"puter_cache"}),this._opscache=new t,this.modules_=[];const s=(new e.libs.context.Context).follow(this,["env","util","authToken","APIOrigin","appID"]);s.puter=this,this.services=new e.system.ServiceManager({context:s}),this.context=s,s.services=this.services;let r=new URLSearchParams(globalThis.location?.search);r.has("puter.app_instance_id")?this.env="app":!0===globalThis.puter_gui_enabled?this.env="gui":globalThis.WorkerGlobalScope?(globalThis.ServiceWorkerGlobalScope?(this.env="service-worker",globalThis.XMLHttpRequest||(globalThis.XMLHttpRequest=E),globalThis.location||(globalThis.location=new URL("https://puter.site/"))):this.env="web-worker",globalThis.localStorage||(globalThis.localStorage=u)):globalThis.process?(this.env="nodejs",globalThis.localStorage||(globalThis.localStorage=u),globalThis.XMLHttpRequest||(globalThis.XMLHttpRequest=E),globalThis.location||(globalThis.location=new URL("https://nodejs.puter.site/")),globalThis.addEventListener||(globalThis.addEventListener=()=>{})):this.env="web","gui"!==this.env&&location.hostname.replace(/\.$/,"")===new URL("https://puter.com").hostname&&(this.env="gui"),r.has("puter.args")?this.args=JSON.parse(decodeURIComponent(r.get("puter.args"))):this.args={},r.has("puter.app_instance_id")&&(this.appInstanceID=decodeURIComponent(r.get("puter.app_instance_id"))),r.has("puter.parent_instance_id")&&(this.parentInstanceID=decodeURIComponent(r.get("puter.parent_instance_id"))),r.has("puter.app.id")&&(this.appID=decodeURIComponent(r.get("puter.app.id"))),r.has("puter.app.name")&&(this.appName=decodeURIComponent(r.get("puter.app.name"))),this.appID&&(this.appDataPath=`~/AppData/${this.appID}`),this.APIOrigin=this.defaultAPIOrigin,r.has("puter.api_origin")&&"app"===this.env?this.APIOrigin=decodeURIComponent(r.get("puter.api_origin")):r.has("puter.domain")&&"app"===this.env&&(this.APIOrigin=`https://api.${r.get("puter.domain")}`);let i=new e.libs.log.ConsoleLogger;i=new e.libs.log.CategorizedToggleLogger({delegate:i});const o=i;if(this.logger=new e.libs.log.LoggerFacade({impl:i,cat:o}),this.apiCallLogger=new n({enabled:!1}),this.services.register("no-puter-yet",Ps),this.services.register("filesystem",Is),this.services.register("api-access",bs),this.services.register("xd-incoming",Cs),"app"!==this.env&&this.services.register("fs-relay",Ss),(async()=>{await this.services.wait_for_init(["api-access"]);const e=this.services.get("api-access");e.auth_token=this.authToken,e.api_origin=this.APIOrigin,[["authToken","auth_token"],["APIOrigin","api_origin"]].forEach(([t,s])=>{Object.defineProperty(this,t,{get:()=>e[s],set(t){e[s]=t}})})})(),"gui"===this.env)this.authToken=window.auth_token,this.initSubmodules();else if("app"===this.env){this.authToken=decodeURIComponent(r.get("puter.auth.token")),this.initSubmodules();try{localStorage.getItem("puter.auth.token")&&this.setAuthToken(localStorage.getItem("puter.auth.token")),localStorage.getItem("puter.app.id")&&this.setAppID(localStorage.getItem("puter.app.id"))}catch(e){console.error("Error accessing localStorage:",e)}}else if("web"===this.env){this.initSubmodules();try{localStorage.getItem("puter.auth.token")&&this.setAuthToken(localStorage.getItem("puter.auth.token")),localStorage.getItem("puter.app.id")&&this.setAppID(localStorage.getItem("puter.app.id"))}catch(e){console.error("Error accessing localStorage:",e)}}else"web-worker"!==this.env&&"service-worker"!==this.env&&"nodejs"!==this.env||this.initSubmodules();(async()=>{await this.services.wait_for_init(["api-access"]);const t=await this.auth.whoami();i=new e.libs.log.PrefixLogger({delegate:i,prefix:`[${t?.app_name??this.appInstanceID??"HOST"}] `}),this.logger.impl=i})(),this.lock_rao_=new e.libs.promise.Lock,this.p_can_request_rao_=new e.libs.promise.TeePromise,this.rao_requested_=!1,(async()=>{await this.services.wait_for_init(["api-access"]),this.p_can_request_rao_.resolve()})(),this.net={generateWispV1URL:async()=>{const{token:e,server:t}=await(await fetch(`${this.APIOrigin}/wisp/relay-token/create`,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`,"Content-Type":"application/json"},body:JSON.stringify({})})).json();return`${t}/${e}/`},Socket:Zt,tls:{TLSSocket:Jt},fetch:$t},this.workers=new ms(this.authToken),this.initNetworkMonitoring()}async request_rao_(){if(await this.p_can_request_rao_,"gui"===this.env)return;if(await this.lock_rao_.acquire(),this.rao_requested_)return void this.lock_rao_.release();let e=!1;try{const e=await fetch(`${this.APIOrigin}/rao`,{method:"POST",headers:{Authorization:`Bearer ${this.authToken}`,Origin:location.origin}});return await e.json()}catch(t){e=!0,console.error(t)}finally{this.lock_rao_.release()}e||(this.rao_requested_=!0)}registerModule(e,t,s={}){const n=new t(this.context,s);this.modules_.push(e),this[e]=n,n._init&&n._init({puter:this})}updateSubmodules(){for(const e of this.modules_)this[e]&&(this[e]?.setAuthToken?.(this.authToken),this[e]?.setAPIOrigin?.(this.APIOrigin))}setAppID=function(e){try{localStorage.setItem("puter.app.id",e)}catch(e){console.error("Error accessing localStorage:",e)}this.appID=e};setAuthToken=function(e){if(this.authToken=e,"web"===this.env||"app"===this.env)try{localStorage.setItem("puter.auth.token",e)}catch(e){console.error("Error accessing localStorage:",e)}"gui"===this.env&&setInterval(Ds.checkAndUpdateGUIFScache,1e4),this.updateSubmodules(),this.request_rao_(),this.getUser().then(e=>{this.whoami=e})};setAPIOrigin=function(e){this.APIOrigin=e,this.updateSubmodules()};resetAuthToken=function(){if(this.authToken=null,"web"===this.env||"app"===this.env)try{localStorage.removeItem("puter.auth.token")}catch(e){console.error("Error accessing localStorage:",e)}this.updateSubmodules()};exit=function(e=0){e&&"number"!=typeof e&&(console.warn("puter.exit() requires status code to be a number. Treating it as 1"),e=1),globalThis.parent.postMessage({msg:"exit",appInstanceID:this.appInstanceID,statusCode:e},"*")};randName=function(e="-"){const t=["helpful","sensible","loyal","honest","clever","capable","calm","smart","genius","bright","charming","creative","diligent","elegant","fancy","colorful","avid","active","gentle","happy","intelligent","jolly","kind","lively","merry","nice","optimistic","polite","quiet","relaxed","silly","victorious","witty","young","zealous","strong","brave","agile","bold"],s=["street","roof","floor","tv","idea","morning","game","wheel","shoe","bag","clock","pencil","pen","magnet","chair","table","house","dog","room","book","car","cat","tree","flower","bird","fish","sun","moon","star","cloud","rain","snow","wind","mountain","river","lake","sea","ocean","island","bridge","road","train","plane","ship","bicycle","horse","elephant","lion","tiger","bear","zebra","giraffe","monkey","snake","rabbit","duck","goose","penguin","frog","crab","shrimp","whale","octopus","spider","ant","bee","butterfly","dragonfly","ladybug","snail","camel","kangaroo","koala","panda","piglet","sheep","wolf","fox","deer","mouse","seal","chicken","cow","dinosaur","puppy","kitten","circle","square","garden","otter","bunny","meerkat","harp"];return t[Math.floor(Math.random()*t.length)]+e+s[Math.floor(Math.random()*s.length)]+e+Math.floor(1e4*Math.random())};getUser=function(...e){let t;return t="object"==typeof e[0]&&null!==e[0]?e[0]:{success:e[0],error:e[1]},new Promise((e,s)=>{const n=C("/whoami",this.APIOrigin,this.authToken,"get");R(n,t.success,t.error,e,s),n.send()})};print=function(...e){let t={};e.length>0&&"object"==typeof e[e.length-1]&&null!==e[e.length-1]&&("escapeHTML"in e[e.length-1]||"code"in e[e.length-1])&&(t=e.pop());for(let s of e)!0!==t.escapeHTML&&!0!==t.code||"string"!=typeof s||(s=s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")),!0===t.code&&(s=`<code><pre>${s}</pre></code>`),document.body.innerHTML+=s};configureAPILogging=function(e={}){return this.apiCallLogger&&this.apiCallLogger.updateConfig(e),this};enableAPILogging=function(e={}){return this.apiCallLogger&&this.apiCallLogger.updateConfig({...e,enabled:!0}),this};disableAPILogging=function(){return this.apiCallLogger&&this.apiCallLogger.disable(),this};initNetworkMonitoring=function(){if(void 0===globalThis.navigator||"function"!=typeof globalThis.addEventListener)return;let e=navigator.onLine;const t=()=>{const t=navigator.onLine;if(e&&!t){console.log("Network connection lost - purging cache");try{this._cache.flushall(),console.log("Cache purged successfully")}catch(e){console.error("Error purging cache:",e)}}e=t};globalThis.addEventListener("online",t),globalThis.addEventListener("offline",t),"undefined"!=typeof document&&document.addEventListener("visibilitychange",()=>{setTimeout(t,100)})};checkAndUpdateGUIFScache=function(){if("gui"!==Ds.env)return;if(!Ds.whoami)return;let e=Ds.whoami.username,t=`/${e}`,s=`/${e}/Desktop`,n=`/${e}/Documents`,r=`/${e}/Public`;Ds._cache.get(`item:${t}`)||(console.log(`/${e} item is not cached, refetching cache`),Ds.fs.stat(t)),Ds._cache.get(`item:${s}`)||(console.log(`/${e}/Desktop item is not cached, refetching cache`),Ds.fs.stat(s)),Ds._cache.get(`item:${n}`)||(console.log(`/${e}/Documents item is not cached, refetching cache`),Ds.fs.stat(n)),Ds._cache.get(`item:${r}`)||(console.log(`/${e}/Public item is not cached, refetching cache`),Ds.fs.stat(r)),Ds._cache.get(`readdir:${t}`)||(console.log(`/${e} is not cached, refetching cache`),Ds.fs.readdir(t)),Ds._cache.get(`readdir:${s}`)||(console.log(`/${e}/Desktop is not cached, refetching cache`),Ds.fs.readdir(s)),Ds._cache.get(`readdir:${n}`)||(console.log(`/${e}/Documents is not cached, refetching cache`),Ds.fs.readdir(n)),Ds._cache.get(`readdir:${r}`)||(console.log(`/${e}/Public is not cached, refetching cache`),Ds.fs.readdir(r))}};return s}();globalThis.puter=Ds,Ds.tools=[];const Rs=Ds.ui.parentApp();globalThis.puterParent=Rs,Rs&&(console.log("I have a parent, registering tools"),Rs.on("message",async e=>{if(console.log("Got tool req ",e),"requestTools"===e.$&&(console.log("Responding with tools"),Rs.postMessage({$:"providedTools",tools:JSON.parse(JSON.stringify(Ds.tools))})),"executeTool"===e.$){console.log("xecuting tools");const[t]=Ds.tools.filter(t=>t.function.name===e.toolName),s=await t.exec(e.parameters);Rs.postMessage({$:"toolResponse",response:s,tag:e.tag})}}),Rs.postMessage({$:"ready"})),globalThis.addEventListener&&globalThis.addEventListener("message",async e=>{e.origin===Ds.defaultGUIOrigin&&(e.data.msg&&"requestOrigin"===e.data.msg?e.source.postMessage({msg:"originResponse"},"*"):"puter.token"===e.data.msg&&(Ds.setAuthToken(e.data.token),Ds.setAppID(e.data.app_uid),Ds.puterAuthState.authGranted=!0,Ds.onAuth&&"function"==typeof Ds.onAuth&&Ds.getUser().then(e=>{Ds.onAuth(e)}),Ds.puterAuthState.isPromptOpen=!1,Ds.puterAuthState.resolver&&(Ds.puterAuthState.authGranted?Ds.puterAuthState.resolver.resolve():Ds.puterAuthState.resolver.reject(),Ds.puterAuthState.resolver=null)))})})()})();