sliccy 1.64.3 → 1.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui/assets/{fs-CjCas3-3.js → fs-D15vM8w-.js} +1 -1
- package/dist/ui/assets/{index-CP8O9WCU.js → index-EsFCM-v9.js} +10 -10
- package/dist/ui/assets/lick-manager-CYt5gTMJ.js +1 -0
- package/dist/ui/assets/secret-env-BgnqXd0b.js +1 -0
- package/dist/ui/assets/shell-CXxb3SHl.js +1 -0
- package/dist/ui/assets/{skills-BvmPIG17.js → skills-CIHtxU5p.js} +1 -1
- package/dist/ui/assets/{skills-BSwzC62S.js → skills-D9PbVsND.js} +1 -1
- package/dist/ui/assets/sprinkle-renderer-DtPUK5jf.js +1 -0
- package/dist/ui/index.html +3 -3
- package/dist/ui/packages/webapp/index.html +3 -3
- package/package.json +1 -1
- package/dist/ui/assets/lick-manager-BVqr-e_y.js +0 -1
- package/dist/ui/assets/secret-env-B32GVtBN.js +0 -1
- package/dist/ui/assets/shell-zRiJffsM.js +0 -1
- package/dist/ui/assets/sprinkle-renderer-CJ4wOw20.js +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import{a as e,n as t,o as n,r,t as i}from"./chunk-zsgVPwQN.js";import{t as a}from"./logger-B-No_qN_.js";var o=i(((e,t)=>{t.exports=n;function n(e){var t,n;if(typeof e!=`function`)throw Error(`expected a function but got `+e);return function(){return t?n:(t=!0,n=e.apply(this,arguments),n)}}})),s=i((()=>{(function(e){function t(e,t){var n;return n=e instanceof Buffer?e:Buffer.from(e.buffer,e.byteOffset,e.byteLength),n.toString(t)}var n=function(e){return Buffer.from(e)};function r(e){for(var t=0,n=Math.min(256*256,e.length+1),r=new Uint16Array(n),i=[],a=0;;){var o=t<e.length;if(!o||a>=n-1){var s=r.subarray(0,a);if(i.push(String.fromCharCode.apply(null,s)),!o)return i.join(``);e=e.subarray(t),t=0,a=0}var c=e[t++];if(!(c&128))r[a++]=c;else if((c&224)==192){var l=e[t++]&63;r[a++]=(c&31)<<6|l}else if((c&240)==224){var l=e[t++]&63,u=e[t++]&63;r[a++]=(c&31)<<12|l<<6|u}else if((c&248)==240){var l=e[t++]&63,u=e[t++]&63,d=e[t++]&63,f=(c&7)<<18|l<<12|u<<6|d;f>65535&&(f-=65536,r[a++]=f>>>10&1023|55296,f=56320|f&1023),r[a++]=f}}}function i(e){for(var t=0,n=e.length,r=0,i=Math.max(32,n+(n>>>1)+7),a=new Uint8Array(i>>>3<<3);t<n;){var o=e.charCodeAt(t++);if(o>=55296&&o<=56319){if(t<n){var s=e.charCodeAt(t);(s&64512)==56320&&(++t,o=((o&1023)<<10)+(s&1023)+65536)}if(o>=55296&&o<=56319)continue}if(r+4>a.length){i+=8,i*=1+t/e.length*2,i=i>>>3<<3;var c=new Uint8Array(i);c.set(a),a=c}if(!(o&4294967168)){a[r++]=o;continue}else if(!(o&4294965248))a[r++]=o>>>6&31|192;else if(!(o&4294901760))a[r++]=o>>>12&15|224,a[r++]=o>>>6&63|128;else if(!(o&4292870144))a[r++]=o>>>18&7|240,a[r++]=o>>>12&63|128,a[r++]=o>>>6&63|128;else continue;a[r++]=o&63|128}return a.slice?a.slice(0,r):a.subarray(0,r)}var a=`Failed to `,o=function(e,t,n){if(e)throw Error(`${a}${t}: the '${n}' option is unsupported.`)},s=typeof Buffer==`function`&&Buffer.from,c=s?n:i;function l(){this.encoding=`utf-8`}l.prototype.encode=function(e,t){return o(t&&t.stream,`encode`,`stream`),c(e)};function u(e){var t;try{var n=new Blob([e],{type:`text/plain;charset=UTF-8`});t=URL.createObjectURL(n);var r=new XMLHttpRequest;return r.open(`GET`,t,!1),r.send(),r.responseText}finally{t&&URL.revokeObjectURL(t)}}var d=!s&&typeof Blob==`function`&&typeof URL==`function`&&typeof URL.createObjectURL==`function`,f=[`utf-8`,`utf8`,`unicode-1-1-utf-8`],p=r;s?p=t:d&&(p=function(e){try{return u(e)}catch{return r(e)}});var m=`construct 'TextDecoder'`,h=`${a} ${m}: the `;function g(e,t){o(t&&t.fatal,m,`fatal`),e||=`utf-8`;var n;if(n=s?Buffer.isEncoding(e):f.indexOf(e.toLowerCase())!==-1,!n)throw RangeError(`${h} encoding label provided ('${e}') is invalid.`);this.encoding=e,this.fatal=!1,this.ignoreBOM=!1}g.prototype.decode=function(e,t){o(t&&t.stream,`decode`,`stream`);var n;return n=e instanceof Uint8Array?e:e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer):new Uint8Array(e),p(n,this.encoding)},e.TextEncoder=e.TextEncoder||l,e.TextDecoder=e.TextDecoder||g})(typeof window<`u`?window:typeof globalThis<`u`?globalThis:void 0)})),c=i(((e,t)=>{s(),t.exports={encode:e=>new TextEncoder().encode(e),decode:e=>new TextDecoder().decode(e)}})),l=i(((e,t)=>{t.exports=n;function n(e,t,n){var r;return function(){if(!t)return e.apply(this,arguments);var i=this,a=arguments,o=n&&!r;if(clearTimeout(r),r=setTimeout(function(){if(r=null,!o)return e.apply(i,a)},t),o)return e.apply(this,arguments)}}})),u=i(((e,t)=>{function n(e){if(e.length===0)return`.`;let t=a(e);return t=t.reduce(c,[]),i(...t)}function r(...e){let t=``;for(let r of e)t=r.startsWith(`/`)?r:n(i(t,r));return t}function i(...e){if(e.length===0)return``;let t=e.join(`/`);return t=t.replace(/\/{2,}/g,`/`),t}function a(e){if(e.length===0)return[];if(e===`/`)return[`/`];let t=e.split(`/`);return t[t.length-1]===``&&t.pop(),e[0]===`/`?t[0]=`/`:t[0]!==`.`&&t.unshift(`.`),t}function o(e){let t=e.lastIndexOf(`/`);if(t===-1)throw Error(`Cannot get dirname of "${e}"`);return t===0?`/`:e.slice(0,t)}function s(e){if(e===`/`)throw Error(`Cannot get basename of "${e}"`);let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function c(e,t){if(e.length===0)return e.push(t),e;if(t===`.`)return e;if(t===`..`){if(e.length===1){if(e[0]===`/`)throw Error(`Unable to normalize path - traverses above root directory`);if(e[0]===`.`)return e.push(t),e}return e[e.length-1]===`..`?(e.push(`..`),e):(e.pop(),e)}return e.push(t),e}t.exports={join:i,normalize:n,split:a,basename:s,dirname:o,resolve:r}})),d=i(((e,t)=>{function n(e){return class extends Error{constructor(...t){super(...t),this.code=e,this.message?this.message=e+`: `+this.message:this.message=e}}}t.exports={EEXIST:n(`EEXIST`),ENOENT:n(`ENOENT`),ENOTDIR:n(`ENOTDIR`),ENOTEMPTY:n(`ENOTEMPTY`),ETIMEDOUT:n(`ETIMEDOUT`),EISDIR:n(`EISDIR`)}})),f=i(((e,t)=>{var n=u(),{EEXIST:r,ENOENT:i,ENOTDIR:a,ENOTEMPTY:o,EISDIR:s}=d(),c=0;t.exports=class{constructor(){}_makeRoot(e=new Map){return e.set(c,{mode:511,type:`dir`,size:0,ino:0,mtimeMs:Date.now()}),e}activate(e=null){e===null?this._root=new Map([[`/`,this._makeRoot()]]):typeof e==`string`?this._root=new Map([[`/`,this._makeRoot(this.parse(e))]]):this._root=e}get activated(){return!!this._root}deactivate(){this._root=void 0}size(){return this._countInodes(this._root.get(`/`))-1}_countInodes(e){let t=1;for(let[n,r]of e)n!==c&&(t+=this._countInodes(r));return t}autoinc(){return this._maxInode(this._root.get(`/`))+1}_maxInode(e){let t=e.get(c).ino;for(let[n,r]of e)n!==c&&(t=Math.max(t,this._maxInode(r)));return t}print(e=this._root.get(`/`)){let t=``,n=(e,r)=>{for(let[i,a]of e){if(i===0)continue;let e=a.get(c),o=e.mode.toString(8);t+=`${` `.repeat(r)}${i}\t${o}`,e.type===`file`?t+=`\t${e.size}\t${e.mtimeMs}\n`:(t+=`
|
|
2
2
|
`,n(a,r+1))}};return n(e,0),t}parse(e){let t=0;function n(e){let n=++t,r=e.length===1?`dir`:`file`,[i,a,o]=e;return i=parseInt(i,8),a=a?parseInt(a):0,o=o?parseInt(o):Date.now(),new Map([[c,{mode:i,type:r,size:a,mtimeMs:o,ino:n}]])}let r=e.trim().split(`
|
|
3
|
-
`),i=this._makeRoot(),a=[{indent:-1,node:i},{indent:0,node:null}];for(let e of r){let t=e.match(/^\t*/)[0].length;e=e.slice(t);let[r,...i]=e.split(` `),o=n(i);if(t<=a[a.length-1].indent)for(;t<=a[a.length-1].indent;)a.pop();a.push({indent:t,node:o}),a[a.length-2].node.set(r,o)}return i}_lookup(e,t=!0){let r=this._root,a=`/`,o=n.split(e);for(let s=0;s<o.length;++s){let l=o[s];if(r=r.get(l),!r)throw new i(e);if(t||s<o.length-1){let e=r.get(c);if(e.type===`symlink`){let t=n.resolve(a,e.target);r=this._lookup(t)}a=a?n.join(a,l):l}}return r}mkdir(e,{mode:t}){if(e===`/`)throw new r;let i=this._lookup(n.dirname(e)),a=n.basename(e);if(i.has(a))throw new r;let o=new Map,s={mode:t,type:`dir`,size:0,mtimeMs:Date.now(),ino:this.autoinc()};o.set(c,s),i.set(a,o)}rmdir(e){let t=this._lookup(e);if(t.get(c).type!==`dir`)throw new a;if(t.size>1)throw new o;let r=this._lookup(n.dirname(e)),i=n.basename(e);r.delete(i)}readdir(e){let t=this._lookup(e);if(t.get(c).type!==`dir`)throw new a;return[...t.keys()].filter(e=>typeof e==`string`)}writeStat(e,t,{mode:r}){let i,a;try{a=this.stat(e)}catch{}if(a!==void 0){if(a.type===`dir`)throw new s;r??=a.mode,i=a.ino}r??=438,i??=this.autoinc();let o=this._lookup(n.dirname(e)),l=n.basename(e),u={mode:r,type:`file`,size:t,mtimeMs:Date.now(),ino:i},d=new Map;return d.set(c,u),o.set(l,d),u}unlink(e){let t=this._lookup(n.dirname(e)),r=n.basename(e);t.delete(r)}rename(e,t){let r=n.basename(t),i=this._lookup(e);this._lookup(n.dirname(t)).set(r,i),this.unlink(e)}stat(e){return this._lookup(e).get(c)}lstat(e){return this._lookup(e,!1).get(c)}readlink(e){return this._lookup(e,!1).get(c).target}symlink(e,t){let r,i;try{let e=this.stat(t);i===null&&(i=e.mode),r=e.ino}catch{}i??=40960,r??=this.autoinc();let a=this._lookup(n.dirname(t)),o=n.basename(t),s={mode:i,type:`symlink`,target:e,size:0,mtimeMs:Date.now(),ino:r},l=new Map;return l.set(c,s),a.set(o,l),s}_du(e){let t=0;for(let[n,r]of e.entries())n===c?t+=r.size:t+=this._du(r);return t}du(e){let t=this._lookup(e);return this._du(t)}}})),p=r({Store:()=>S,clear:()=>y,close:()=>x,del:()=>v,get:()=>h,keys:()=>b,set:()=>g,update:()=>_});function m(){return C||=new S,C}function h(e,t=m()){let n;return t._withIDBStore(`readwrite`,t=>{n=t.get(e)}).then(()=>n.result)}function g(e,t,n=m()){return n._withIDBStore(`readwrite`,n=>{n.put(t,e)})}function _(e,t,n=m()){return n._withIDBStore(`readwrite`,n=>{let r=n.get(e);r.onsuccess=()=>{n.put(t(r.result),e)}})}function v(e,t=m()){return t._withIDBStore(`readwrite`,t=>{t.delete(e)})}function y(e=m()){return e._withIDBStore(`readwrite`,e=>{e.clear()})}function b(e=m()){let t=[];return e._withIDBStore(`readwrite`,e=>{(e.openKeyCursor||e.openCursor).call(e).onsuccess=function(){this.result&&(t.push(this.result.key),this.result.continue())}}).then(()=>t)}function x(e=m()){return e._close()}var S,C,w=t((()=>{S=class{constructor(e=`keyval-store`,t=`keyval`){this.storeName=t,this._dbName=e,this._storeName=t,this._init()}_init(){this._dbp||=new Promise((e,t)=>{let n=indexedDB.open(this._dbName);n.onerror=()=>t(n.error),n.onsuccess=()=>e(n.result),n.onupgradeneeded=()=>{n.result.createObjectStore(this._storeName)}})}_withIDBStore(e,t){return this._init(),this._dbp.then(n=>new Promise((r,i)=>{let a=n.transaction(this.storeName,e);a.oncomplete=()=>r(),a.onabort=a.onerror=()=>i(a.error),t(a.objectStore(this.storeName))}))}_close(){return this._init(),this._dbp.then(e=>{e.close(),this._dbp=void 0})}}})),T=i(((t,n)=>{var r=(w(),e(p));n.exports=class{constructor(e,t){this._database=e,this._storename=t,this._store=new r.Store(this._database,this._storename)}saveSuperblock(e){return r.set(`!root`,e,this._store)}loadSuperblock(){return r.get(`!root`,this._store)}readFile(e){return r.get(e,this._store)}writeFile(e,t){return r.set(e,t,this._store)}unlink(e){return r.del(e,this._store)}wipe(){return r.clear(this._store)}close(){return r.close(this._store)}}})),E=i(((e,t)=>{t.exports=class{constructor(e){this._url=e}loadSuperblock(){return fetch(this._url+`/.superblock.txt`).then(e=>e.ok?e.text():null)}async readFile(e){let t=await fetch(this._url+e);if(t.status===200)return t.arrayBuffer();throw Error(`ENOENT`)}async sizeFile(e){let t=await fetch(this._url+e,{method:`HEAD`});if(t.status===200)return t.headers.get(`content-length`);throw Error(`ENOENT`)}}})),D=i(((t,n)=>{var r=(w(),e(p)),i=e=>new Promise(t=>setTimeout(t,e));n.exports=class{constructor(e,t){this._id=Math.random(),this._database=e,this._storename=t,this._store=new r.Store(this._database,this._storename),this._lock=null}async has({margin:e=2e3}={}){if(this._lock&&this._lock.holder===this._id){let t=Date.now();return this._lock.expires>t+e?!0:await this.renew()}else return!1}async renew({ttl:e=5e3}={}){let t;return await r.update(`lock`,n=>{let r=Date.now()+e;return t=n&&n.holder===this._id,this._lock=t?{holder:this._id,expires:r}:n,this._lock},this._store),t}async acquire({ttl:e=5e3}={}){let t,n,i;if(await r.update(`lock`,r=>{let a=Date.now(),o=a+e;return n=r&&r.expires<a,t=r===void 0||n,i=r&&r.holder===this._id,this._lock=t?{holder:this._id,expires:o}:r,this._lock},this._store),i)throw Error(`Mutex double-locked`);return t}async wait({interval:e=100,limit:t=6e3,ttl:n}={}){for(;t--;){if(await this.acquire({ttl:n}))return!0;await i(e)}throw Error(`Mutex timeout`)}async release({force:e=!1}={}){let t,n,i;if(await r.update(`lock`,r=>(t=e||r&&r.holder===this._id,n=r===void 0,i=r&&r.holder!==this._id,this._lock=t?void 0:r,this._lock),this._store),await r.close(this._store),!t&&!e){if(n)throw Error(`Mutex double-freed`);if(i)throw Error(`Mutex lost ownership`)}return t}}})),O=i(((e,t)=>{t.exports=class{constructor(e){this._id=Math.random(),this._database=e,this._has=!1,this._release=null}async has(){return this._has}async acquire(){return new Promise(e=>{navigator.locks.request(this._database+`_lock`,{ifAvailable:!0},t=>(this._has=!!t,e(!!t),new Promise(e=>{this._release=e})))})}async wait({timeout:e=6e5}={}){return new Promise((t,n)=>{let r=new AbortController;setTimeout(()=>{r.abort(),n(Error(`Mutex timeout`))},e),navigator.locks.request(this._database+`_lock`,{signal:r.signal},e=>(this._has=!!e,t(!!e),new Promise(e=>{this._release=e})))})}async release({force:e=!1}={}){this._has=!1,this._release?this._release():e&&navigator.locks.request(this._database+`_lock`,{steal:!0},e=>!0)}}})),k=i(((e,t)=>{var{encode:n,decode:r}=c(),i=l(),a=f(),{ENOENT:o,ENOTEMPTY:s,ETIMEDOUT:p}=d(),m=T(),h=E(),g=D(),_=O(),v=u();t.exports=class{constructor(){this.saveSuperblock=i(()=>{this.flush()},500)}async init(e,{wipe:t,url:n,urlauto:r,fileDbName:i=e,db:o=null,fileStoreName:s=e+`_files`,lockDbName:c=e+`_lock`,lockStoreName:l=e+`_lock`}={}){this._name=e,this._idb=o||new m(i,s),this._mutex=navigator.locks?new _(e):new g(c,l),this._cache=new a(e),this._opts={wipe:t,url:n},this._needsWipe=!!t,n&&(this._http=new h(n),this._urlauto=!!r)}async activate(){if(this._cache.activated)return;this._needsWipe&&(this._needsWipe=!1,await this._idb.wipe(),await this._mutex.release({force:!0})),await this._mutex.has()||await this._mutex.wait();let e=await this._idb.loadSuperblock();if(e)this._cache.activate(e);else if(this._http){let e=await this._http.loadSuperblock();this._cache.activate(e),await this._saveSuperblock()}else this._cache.activate();if(!await this._mutex.has())throw new p}async deactivate(){await this._mutex.has()&&await this._saveSuperblock(),this._cache.deactivate();try{await this._mutex.release()}catch(e){console.log(e)}await this._idb.close()}async _saveSuperblock(){this._cache.activated&&(this._lastSavedAt=Date.now(),await this._idb.saveSuperblock(this._cache._root))}_writeStat(e,t,n){let r=v.split(v.dirname(e)),i=r.shift();for(let e of r){i=v.join(i,e);try{this._cache.mkdir(i,{mode:511})}catch{}}return this._cache.writeStat(e,t,n)}async readFile(e,t){let n=typeof t==`string`?t:t&&t.encoding;if(n&&n!==`utf8`)throw Error(`Only "utf8" encoding is supported in readFile`);let i=null,a=null;try{a=this._cache.stat(e),i=await this._idb.readFile(a.ino)}catch(e){if(!this._urlauto)throw e}if(!i&&this._http){let t=this._cache.lstat(e);for(;t.type===`symlink`;)e=v.resolve(v.dirname(e),t.target),t=this._cache.lstat(e);i=await this._http.readFile(e)}if(i&&((!a||a.size!=i.byteLength)&&(a=await this._writeStat(e,i.byteLength,{mode:a?a.mode:438}),this.saveSuperblock()),n===`utf8`?i=r(i):i.toString=()=>r(i)),!a)throw new o(e);return i}async writeFile(e,t,r){let{mode:i,encoding:a=`utf8`}=r;if(typeof t==`string`){if(a!==`utf8`)throw Error(`Only "utf8" encoding is supported in writeFile`);t=n(t)}let o=await this._cache.writeStat(e,t.byteLength,{mode:i});await this._idb.writeFile(o.ino,t)}async unlink(e,t){let n=this._cache.lstat(e);this._cache.unlink(e),n.type!==`symlink`&&await this._idb.unlink(n.ino)}readdir(e,t){return this._cache.readdir(e)}mkdir(e,t){let{mode:n=511}=t;this._cache.mkdir(e,{mode:n})}rmdir(e,t){if(e===`/`)throw new s;this._cache.rmdir(e)}rename(e,t){this._cache.rename(e,t)}stat(e,t){return this._cache.stat(e)}lstat(e,t){return this._cache.lstat(e)}readlink(e,t){return this._cache.readlink(e)}symlink(e,t){this._cache.symlink(e,t)}async backFile(e,t){let n=await this._http.sizeFile(e);await this._writeStat(e,n,t)}du(e){return this._cache.du(e)}flush(){return this._saveSuperblock()}}})),A=i(((e,t)=>{t.exports=class{constructor(e){this.type=e.type,this.mode=e.mode,this.size=e.size,this.ino=e.ino,this.mtimeMs=e.mtimeMs,this.ctimeMs=e.ctimeMs||e.mtimeMs,this.uid=1,this.gid=1,this.dev=1}isFile(){return this.type===`file`}isDirectory(){return this.type===`dir`}isSymbolicLink(){return this.type===`symlink`}}})),j=i(((e,t)=>{var n=k(),r=A(),i=u();function a(e,t,...n){return e=i.normalize(e),(t===void 0||typeof t==`function`)&&(t={}),typeof t==`string`&&(t={encoding:t}),[e,t,...n]}function o(e,t,n,...r){return e=i.normalize(e),(n===void 0||typeof n==`function`)&&(n={}),typeof n==`string`&&(n={encoding:n}),[e,t,n,...r]}function s(e,t,...n){return[i.normalize(e),i.normalize(t),...n]}t.exports=class{constructor(e,t={}){this.init=this.init.bind(this),this.readFile=this._wrap(this.readFile,a,!1),this.writeFile=this._wrap(this.writeFile,o,!0),this.unlink=this._wrap(this.unlink,a,!0),this.readdir=this._wrap(this.readdir,a,!1),this.mkdir=this._wrap(this.mkdir,a,!0),this.rmdir=this._wrap(this.rmdir,a,!0),this.rename=this._wrap(this.rename,s,!0),this.stat=this._wrap(this.stat,a,!1),this.lstat=this._wrap(this.lstat,a,!1),this.readlink=this._wrap(this.readlink,a,!1),this.symlink=this._wrap(this.symlink,s,!0),this.backFile=this._wrap(this.backFile,a,!0),this.du=this._wrap(this.du,a,!1),this._deactivationPromise=null,this._deactivationTimeout=null,this._activationPromise=null,this._operations=new Set,e&&this.init(e,t)}async init(...e){return this._initPromiseResolve&&await this._initPromise,this._initPromise=this._init(...e),this._initPromise}async _init(e,t={}){await this._gracefulShutdown(),this._activationPromise&&await this._deactivate(),this._backend&&this._backend.destroy&&await this._backend.destroy(),this._backend=t.backend||new n,this._backend.init&&await this._backend.init(e,t),this._initPromiseResolve&&=(this._initPromiseResolve(),null),t.defer||this.stat(`/`)}async _gracefulShutdown(){this._operations.size>0&&(this._isShuttingDown=!0,await new Promise(e=>this._gracefulShutdownResolve=e),this._isShuttingDown=!1,this._gracefulShutdownResolve=null)}_wrap(e,t,n){return async(...r)=>{r=t(...r);let i={name:e.name,args:r};this._operations.add(i);try{return await this._activate(),await e.apply(this,r)}finally{this._operations.delete(i),n&&this._backend.saveSuperblock(),this._operations.size===0&&(this._deactivationTimeout||clearTimeout(this._deactivationTimeout),this._deactivationTimeout=setTimeout(this._deactivate.bind(this),500))}}}async _activate(){this._initPromise||console.warn(Error(`Attempted to use LightningFS ${this._name} before it was initialized.`)),await this._initPromise,this._deactivationTimeout&&=(clearTimeout(this._deactivationTimeout),null),this._deactivationPromise&&await this._deactivationPromise,this._deactivationPromise=null,this._activationPromise||=this._backend.activate?this._backend.activate():Promise.resolve(),await this._activationPromise}async _deactivate(){return this._activationPromise&&await this._activationPromise,this._deactivationPromise||=this._backend.deactivate?this._backend.deactivate():Promise.resolve(),this._activationPromise=null,this._gracefulShutdownResolve&&this._gracefulShutdownResolve(),this._deactivationPromise}async readFile(e,t){return this._backend.readFile(e,t)}async writeFile(e,t,n){return await this._backend.writeFile(e,t,n),null}async unlink(e,t){return await this._backend.unlink(e,t),null}async readdir(e,t){return this._backend.readdir(e,t)}async mkdir(e,t){return await this._backend.mkdir(e,t),null}async rmdir(e,t){return await this._backend.rmdir(e,t),null}async rename(e,t){return await this._backend.rename(e,t),null}async stat(e,t){return new r(await this._backend.stat(e,t))}async lstat(e,t){return new r(await this._backend.lstat(e,t))}async readlink(e,t){return this._backend.readlink(e,t)}async symlink(e,t){return await this._backend.symlink(e,t),null}async backFile(e,t){return await this._backend.backFile(e,t),null}async du(e){return this._backend.du(e)}async flush(){return this._backend.flush()}}})),M=n(i(((e,t)=>{var n=o(),r=j();function i(e,t){return typeof e==`function`&&(t=e),t=n(t),[(...e)=>t(null,...e),t]}t.exports=class{constructor(...e){this.promises=new r(...e),this.init=this.init.bind(this),this.readFile=this.readFile.bind(this),this.writeFile=this.writeFile.bind(this),this.unlink=this.unlink.bind(this),this.readdir=this.readdir.bind(this),this.mkdir=this.mkdir.bind(this),this.rmdir=this.rmdir.bind(this),this.rename=this.rename.bind(this),this.stat=this.stat.bind(this),this.lstat=this.lstat.bind(this),this.readlink=this.readlink.bind(this),this.symlink=this.symlink.bind(this),this.backFile=this.backFile.bind(this),this.du=this.du.bind(this),this.flush=this.flush.bind(this)}init(e,t){return this.promises.init(e,t)}readFile(e,t,n){let[r,a]=i(t,n);this.promises.readFile(e,t).then(r).catch(a)}writeFile(e,t,n,r){let[a,o]=i(n,r);this.promises.writeFile(e,t,n).then(a).catch(o)}unlink(e,t,n){let[r,a]=i(t,n);this.promises.unlink(e,t).then(r).catch(a)}readdir(e,t,n){let[r,a]=i(t,n);this.promises.readdir(e,t).then(r).catch(a)}mkdir(e,t,n){let[r,a]=i(t,n);this.promises.mkdir(e,t).then(r).catch(a)}rmdir(e,t,n){let[r,a]=i(t,n);this.promises.rmdir(e,t).then(r).catch(a)}rename(e,t,n){let[r,a]=i(n);this.promises.rename(e,t).then(r).catch(a)}stat(e,t,n){let[r,a]=i(t,n);this.promises.stat(e).then(r).catch(a)}lstat(e,t,n){let[r,a]=i(t,n);this.promises.lstat(e).then(r).catch(a)}readlink(e,t,n){let[r,a]=i(t,n);this.promises.readlink(e).then(r).catch(a)}symlink(e,t,n){let[r,a]=i(n);this.promises.symlink(e,t).then(r).catch(a)}backFile(e,t,n){let[r,a]=i(t,n);this.promises.backFile(e,t).then(r).catch(a)}du(e,t){let[n,r]=i(t);this.promises.du(e).then(n).catch(r)}flush(e){let[t,n]=i(e);this.promises.flush().then(t).catch(n)}}}))(),1),N=class extends Error{constructor(e,t,n){super(`${e}: ${t}${n?` '${n}'`:``}`),this.code=e,this.path=n,this.name=`FsError`}};function P(e){if(!e||e===`/`)return`/`;e.startsWith(`/`)||(e=`/`+e);let t=e.split(`/`),n=[];for(let e of t)e===``||e===`.`||(e===`..`?n.pop():n.push(e));return`/`+n.join(`/`)}function F(e){let t=P(e);if(t===`/`)return{dir:`/`,base:``};let n=t.lastIndexOf(`/`);return{dir:n===0?`/`:t.slice(0,n),base:t.slice(n+1)}}function I(...e){return P(e.join(`/`))}var L=`slicc-mount-table`,R=1,z=`mounts`;function B(){return new Promise((e,t)=>{let n=indexedDB.open(L,R);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(z)||e.createObjectStore(z)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function V(e,t){let n=await B();try{let r=n.transaction(z,`readwrite`);r.objectStore(z).put(t,e),await new Promise((e,t)=>{r.oncomplete=()=>e(),r.onerror=()=>t(r.error),r.onabort=()=>t(r.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{n.close()}}async function H(e){let t=await B();try{let n=t.transaction(z,`readwrite`);n.objectStore(z).delete(e),await new Promise((e,t)=>{n.oncomplete=()=>e(),n.onerror=()=>t(n.error),n.onabort=()=>t(n.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{t.close()}}async function U(){let e=await B();try{let t=e.transaction(z,`readonly`),n=t.objectStore(z),r=()=>t.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`),i=await new Promise((e,i)=>{let a=n.getAllKeys();a.onsuccess=()=>e(a.result),a.onerror=()=>i(a.error),t.onabort=()=>i(r())}),a=await new Promise((e,i)=>{let a=n.getAll();a.onsuccess=()=>e(a.result),a.onerror=()=>i(a.error),t.onabort=()=>i(r())});return i.map((e,t)=>({path:e,handle:a[t]}))}finally{e.close()}}async function W(){let e=await B();try{let t=e.transaction(z,`readwrite`);t.objectStore(z).clear(),await new Promise((e,n)=>{t.oncomplete=()=>e(),t.onerror=()=>n(t.error),t.onabort=()=>n(t.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{e.close()}}var G=10,K=class e{lfs;rawFs;_ready;mountPoints=new Map;watcher=null;dbName;mountSyncChannel=null;constructor(e,t){this.dbName=e;let n=new M.default(e,{wipe:t});if(this.rawFs=n,this.lfs=n.promises,this._ready=this.lfs.stat(`/`).then(()=>{}).catch(()=>{}),typeof BroadcastChannel<`u`)try{this.mountSyncChannel=new BroadcastChannel(`vfs-mount-sync:${e}`),this.mountSyncChannel.onmessage=e=>{let{type:t,path:n,handle:r}=e.data??{};t===`mount`&&typeof n==`string`&&r?(this.mountPoints.set(n,r),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])):t===`unmount`&&typeof n==`string`&&(this.mountPoints.delete(n),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]))}}catch{}}static async create(t){let n=t?.dbName??`browser-fs`,r=t?.wipe??!1,i=new e(n,r);return await i._ready,r&&await W().catch(()=>{}),i}getLightningFS(){return this.lfs}setWatcher(e){this.watcher=e}getWatcher(){return this.watcher}async dispose(){this.mountSyncChannel?.close(),this.mountSyncChannel=null,this.watcher?.dispose(),this.watcher=null;let e=this.lfs;if(e._deactivationTimeout&&=(clearTimeout(e._deactivationTimeout),null),e._operations?.size>0&&await e._gracefulShutdown?.(),e._backend?.saveSuperblock?.cancel&&e._backend.saveSuperblock.cancel(),e._backend){try{e._backend.flush&&await e._backend.flush()}catch{}e._backend.deactivate&&await e._backend.deactivate()}if(e._backend=null,e._activationPromise=null,e._deactivationPromise=null,e._initPromise=null,typeof indexedDB<`u`&&indexedDB.deleteDatabase)try{let e=indexedDB.deleteDatabase(this.dbName);await new Promise((t,n)=>{e.onsuccess=()=>t(),e.onerror=()=>n(e.error)})}catch{}}getCacheFS(){try{let e=this.lfs._backend?._cache;return e?.activated&&e._root instanceof Map?e:null}catch{return null}}readDirSync(e){let t=P(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=n.readdir(t),r=[];for(let i of e){let e=t===`/`?`/${i}`:`${t}/${i}`;try{let t=n.lstat(e),a=t.type===`symlink`?`symlink`:t.type===`dir`?`directory`:`file`;r.push({name:i,type:a})}catch{}}return r}catch{return null}}statSync(e){let t=P(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=this.resolveSymlinksSync(n,t);if(e===null)return null;let r=n.lstat(e);return{type:r.type===`dir`?`directory`:`file`,size:r.size??0,mtime:r.mtimeMs??Date.now(),ctime:r.mtimeMs??Date.now()}}catch{return null}}resolveSymlinksSync(e,t,n={count:0}){let r=t.split(`/`).filter(Boolean),i=`/`;for(let t of r){i=i===`/`?`/${t}`:`${i}/${t}`;try{let t=e.lstat(i);if(t.type===`symlink`){if(++n.count>G)return null;let r=t.target;if(r.startsWith(`/`))i=P(r);else{let{dir:e}=F(i);i=P(I(e,r))}let a=this.resolveSymlinksSync(e,i,n);if(a===null)return null;i=a}}catch{return null}}return i}lstatSync(e){let t=P(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=n.lstat(t);return e.type===`symlink`?{type:`symlink`,size:e.size??0,mtime:e.mtimeMs??Date.now(),ctime:e.mtimeMs??Date.now(),isSymlink:!0,symlinkTarget:e.target}:{type:e.type===`dir`?`directory`:`file`,size:e.size??0,mtime:e.mtimeMs??Date.now(),ctime:e.mtimeMs??Date.now()}}catch{return null}}async mount(e,t){let n=P(e);if(this.mountPoints.has(n))throw new N(`EEXIST`,`mount point is already mounted`,n);try{if((await this.lstat(n)).type!==`directory`)throw new N(`ENOTDIR`,`mount point must be a directory`,n);if((await this.readDir(n)).length>0)throw new N(`ENOTEMPTY`,`mount point must be empty to avoid shadowing existing files`,n)}catch(e){if(!(e instanceof N)||e.code!==`ENOENT`)throw e}let{dir:r}=F(n);r!==`/`&&await this.mkdir(r,{recursive:!0});try{await this.lfs.mkdir(n)}catch{}this.mountPoints.set(n,t);try{this.mountSyncChannel?.postMessage({type:`mount`,path:n,handle:t})}catch{}this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]);try{await V(n,t)}catch{}}async unmount(e){let t=P(e);this.mountPoints.delete(t);try{this.mountSyncChannel?.postMessage({type:`unmount`,path:t})}catch{}this.watcher?.notify([{type:`modify`,path:t,entryType:`directory`}]);try{await H(t)}catch{}}listMounts(){return[...this.mountPoints.keys()]}isPathUnderMount(e){for(let t of this.mountPoints.keys())if(e===t||e.startsWith(t+`/`))return!0;return!1}findMount(e){let t=null;for(let[n,r]of this.mountPoints)(e===n||e.startsWith(n+`/`))&&(!t||n.length>t.mountPath.length)&&(t={mountPath:n,handle:r});return t?e===t.mountPath?{handle:t.handle,relParts:[]}:{handle:t.handle,relParts:e.slice(t.mountPath.length+1).split(`/`).filter(Boolean)}:null}static async fsaNavDir(e,t,n=!1){let r=e;for(let e of t)r=await r.getDirectoryHandle(e,{create:n});return r}static async fsaGetFile(t,n,r=!1){return(await e.fsaNavDir(t,n.slice(0,-1),r)).getFileHandle(n[n.length-1],{create:r})}convertFsaError(e,t){if(e instanceof N)return e;if(e instanceof Error){if(e.name===`NotFoundError`)return new N(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatchError`)return new N(`ENOTDIR`,`not a directory`,t);if(e.name===`NotAllowedError`)return new N(`EINVAL`,`permission denied`,t);if(e.name===`InvalidModificationError`)return new N(`ENOTEMPTY`,`directory not empty`,t)}return new N(`EINVAL`,e instanceof Error?e.message:String(e),t)}async readFile(t,n){let r=P(t),i=this.findMount(r);if(i){if(i.relParts.length===0)throw new N(`EISDIR`,`is a directory`,r);try{let t=await(await e.fsaGetFile(i.handle,i.relParts)).getFile();return(n?.encoding??`utf-8`)===`utf-8`?await t.text():new Uint8Array(await t.arrayBuffer())}catch(e){throw this.convertFsaError(e,r)}}let a=await this.resolveSymlinks(r);try{return(n?.encoding??`utf-8`)===`utf-8`?await this.lfs.readFile(a,{encoding:`utf8`}):await this.lfs.readFile(a)}catch(e){throw this.convertError(e,r)}}async writeFile(t,n,r){let i=P(t),a=this.findMount(i);if(a){if(a.relParts.length===0)throw new N(`EISDIR`,`is a directory`,i);let t=!1;try{await this.stat(i),t=!0}catch{}try{let t=await(await e.fsaGetFile(a.handle,a.relParts,!0)).createWritable(),r=typeof n==`string`?new TextEncoder().encode(n):n instanceof Uint8Array?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n);await t.write(r),await t.close()}catch(e){throw this.convertFsaError(e,i)}this.watcher?.notify([{type:t?`modify`:`create`,path:i,entryType:`file`}]);return}let o;try{o=await this.resolveSymlinks(i)}catch{o=i}let s=!1;try{await this.lfs.stat(o),s=!0}catch{}let{dir:c}=F(o);c!==`/`&&await this.mkdir(c,{recursive:!0});try{await this.lfs.writeFile(o,n)}catch(e){throw this.convertError(e,i)}this.watcher?.notify([{type:s?`modify`:`create`,path:o,entryType:`file`}])}async readDir(t){let n=P(t),r=this.findMount(n);if(r)try{let t=r.relParts.length===0?r.handle:await e.fsaNavDir(r.handle,r.relParts),i=new Map;for await(let[e,n]of t)i.set(e,{name:e,type:n.kind===`directory`?`directory`:`file`});let a=n===`/`?`/`:`${n}/`;for(let e of this.mountPoints.keys()){if(e===n||!e.startsWith(a))continue;let t=e.slice(a.length);!t||t.includes(`/`)||i.has(t)||i.set(t,{name:t,type:`directory`})}return[...i.values()]}catch(e){throw this.convertFsaError(e,n)}let i=await this.resolveSymlinks(n);try{let e=await this.lfs.readdir(i),t=[];for(let n of e){let e=i===`/`?`/${n}`:`${i}/${n}`;try{let r=await this.lfs.lstat(e);r.isSymbolicLink()?t.push({name:n,type:`symlink`}):t.push({name:n,type:r.isDirectory()?`directory`:`file`})}catch{}}return t}catch(e){throw this.convertError(e,n)}}async mkdir(t,n){let r=P(t);if(r===`/`)return;let i=this.findMount(r);if(i){if(i.relParts.length===0)return;try{let t=await this.exists(r);await e.fsaNavDir(i.handle,i.relParts,!0),t||this.watcher?.notify([{type:`create`,path:r,entryType:`directory`}])}catch(e){throw this.convertFsaError(e,r)}return}if(n?.recursive){let e=r.split(`/`).filter(Boolean),t=``;for(let n of e){t+=`/`+n;try{await this.lfs.mkdir(t)}catch(e){if(e instanceof Error&&!e.message.includes(`EEXIST`))throw this.convertError(e,t)}}}else{try{await this.lfs.mkdir(r)}catch(e){throw this.convertError(e,r)}this.watcher?.notify([{type:`create`,path:r,entryType:`directory`}])}}async rm(t,n){let r=P(t),i=this.findMount(r);if(i){if(i.relParts.length===0)throw new N(`EINVAL`,`cannot remove a mount point — use unmount`,r);let t;try{t=(await this.stat(r)).type}catch{}try{let t=i.relParts.slice(0,-1),r=i.relParts[i.relParts.length-1];await(t.length===0?i.handle:await e.fsaNavDir(i.handle,t)).removeEntry(r,{recursive:n?.recursive})}catch(e){throw this.convertFsaError(e,r)}this.watcher?.notify([{type:`delete`,path:r,entryType:t}]);return}try{let e=await this.lfs.lstat(r);e.isSymbolicLink()?await this.lfs.unlink(r):e.isDirectory()?n?.recursive?await this.rmRecursive(r):await this.lfs.rmdir(r):await this.lfs.unlink(r)}catch(e){throw this.convertError(e,r)}this.watcher?.notify([{type:`delete`,path:r}])}async rmRecursive(e){let t=await this.lfs.readdir(e);for(let n of t){let t=e===`/`?`/${n}`:`${e}/${n}`;(await this.lfs.stat(t)).isDirectory()?await this.rmRecursive(t):await this.lfs.unlink(t)}await this.lfs.rmdir(e)}async stat(t){let n=P(t),r=this.findMount(n);if(r){if(r.relParts.length===0)try{let e=await this.lfs.stat(n);return{type:`directory`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch{return{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}try{try{let t=await(await e.fsaGetFile(r.handle,r.relParts)).getFile();return{type:`file`,size:t.size,mtime:t.lastModified,ctime:t.lastModified}}catch{return await e.fsaNavDir(r.handle,r.relParts),{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}}catch(e){throw this.convertFsaError(e,n)}}let i=await this.resolveSymlinks(n);try{let e=await this.lfs.stat(i);return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch(e){throw this.convertError(e,n)}}async exists(e){let t=P(e),n=this.findMount(t);if(n){if(n.relParts.length===0)return!0;try{return await this.stat(t),!0}catch{return!1}}try{return await this.stat(t),!0}catch{try{return await this.lfs.lstat(t),!0}catch{return!1}}}async rename(e,t){let n=P(e),r=P(t),i;try{i=(await this.lstat(n)).type}catch{}try{await this.lfs.rename(n,r)}catch(e){throw this.convertError(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:i},{type:`create`,path:r,entryType:i}])}async readTextFile(e){return await this.readFile(e,{encoding:`utf-8`})}async*walk(e,t){let n=P(e),r=t??new Set,i;try{i=await this.realpath(n)}catch{i=n}if(r.has(i))return;r.add(i);let a=await this.readDir(n);for(let e of a){let t=n===`/`?`/${e.name}`:`${n}/${e.name}`;if(e.type===`file`)yield t;else if(e.type===`symlink`)try{let e=await this.stat(t);e.type===`file`?yield t:e.type===`directory`&&(yield*this.walk(t,r))}catch{}else yield*this.walk(t,r)}}async copyFile(e,t){if((await this.stat(e)).type===`directory`)throw new N(`EISDIR`,`is a directory`,e);let n=await this.readFile(e,{encoding:`binary`});await this.writeFile(t,n)}dirname(e){return F(P(e)).dir}basename(e){return F(P(e)).base}async symlink(e,t){let n=P(t);if(this.findMount(n))throw new N(`EINVAL`,`symlinks not supported on mounted filesystems`,n);let{dir:r}=F(n);r!==`/`&&await this.mkdir(r,{recursive:!0});try{await this.lfs.symlink(e,n)}catch(e){throw this.convertError(e,n)}this.watcher?.notify([{type:`create`,path:n,entryType:`symlink`}])}async readlink(e){let t=P(e);try{return await this.lfs.readlink(t)}catch(e){throw this.convertError(e,t)}}async lstat(e){let t=P(e);if(this.findMount(t))return this.stat(t);try{let e=await this.lfs.lstat(t);if(e.isSymbolicLink()){let n=await this.lfs.readlink(t);return{type:`symlink`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,isSymlink:!0,symlinkTarget:n}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch(e){throw this.convertError(e,t)}}async realpath(e,t=0){let n=P(e);if(this.findMount(n))return n;let r=n.split(`/`).filter(Boolean),i=`/`,a=t;for(let t of r){i=i===`/`?`/${t}`:`${i}/${t}`;try{if((await this.lfs.lstat(i)).isSymbolicLink()){if(++a>G)throw new N(`ELOOP`,`too many levels of symbolic links`,e);let t=await this.lfs.readlink(i);if(t.startsWith(`/`))i=P(t);else{let{dir:e}=F(i);i=P(I(e,t))}i=await this.realpath(i,a)}}catch(e){throw e instanceof N?e:this.convertError(e,i)}}return i}async resolveSymlinks(e){return this.findMount(e)?e:this.realpath(e)}convertError(e,t){if(e instanceof N)return e;let n=e instanceof Error?e.message:String(e);return n.includes(`ENOENT`)?new N(`ENOENT`,`no such file or directory`,t):n.includes(`EEXIST`)?new N(`EEXIST`,`file already exists`,t):n.includes(`ENOTDIR`)?new N(`ENOTDIR`,`not a directory`,t):n.includes(`EISDIR`)?new N(`EISDIR`,`is a directory`,t):n.includes(`ENOTEMPTY`)?new N(`ENOTEMPTY`,`directory not empty`,t):n.includes(`ELOOP`)?new N(`ELOOP`,`too many levels of symbolic links`,t):new N(`EINVAL`,n,t)}},q=class{vfs;allowedPrefixes;readOnlyPrefixes;constructor(e,t,n=[]){this.vfs=e;let r=e=>{let t=P(e);return t.endsWith(`/`)?t:t+`/`};this.allowedPrefixes=t.map(r),this.readOnlyPrefixes=n.map(r)}getAllPrefixes(){let e=this.vfs.listMounts().map(e=>e.endsWith(`/`)?e:e+`/`);return[...this.allowedPrefixes,...this.readOnlyPrefixes,...e]}isAllowed(e){let t=P(e);return this.getAllPrefixes().some(e=>t===e.slice(0,-1)||t.startsWith(e)||t===`/`||e.startsWith(t+`/`))}isAllowedStrict(e){let t=P(e);return this.getAllPrefixes().some(e=>t===e.slice(0,-1)||t.startsWith(e))}isWritable(e){let t=P(e);return this.allowedPrefixes.some(e=>t===e.slice(0,-1)||t.startsWith(e))}checkWrite(e){if(!this.isWritable(e))throw new N(`EACCES`,`permission denied`,P(e))}async resolveAndCheckRead(e){try{let t=await this.vfs.realpath(e);if(!this.isAllowedStrict(t))throw new N(`ENOENT`,`no such file or directory`,P(e));return t}catch(t){throw t instanceof N?t:new N(`ENOENT`,`no such file or directory`,P(e))}}async resolveAndCheckWrite(e){try{let t=await this.vfs.realpath(e);if(!this.isWritable(t))throw new N(`EACCES`,`permission denied`,P(e));return t}catch(t){throw t instanceof N?t:new N(`EACCES`,`permission denied`,P(e))}}getUnderlyingFS(){return this.vfs}getLightningFS(){return this.vfs.getLightningFS()}async readFile(e,t){if(!this.isAllowedStrict(e))throw new N(`ENOENT`,`no such file or directory`,P(e));let n=await this.resolveAndCheckRead(e);return this.vfs.readFile(n,t)}async readDir(e){if(!this.isAllowed(e))return[];let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return[]}let n=await this.vfs.readDir(t);if(!this.isAllowedStrict(e)){let t=P(e);return n.filter(e=>{let n=t===`/`?`/${e.name}`:`${t}/${e.name}`;return this.isAllowed(n)})}return n}async stat(e){if(!this.isAllowed(e))throw new N(`ENOENT`,`no such file or directory`,P(e));if(this.isAllowedStrict(e)){let t=await this.resolveAndCheckRead(e);return this.vfs.stat(t)}return this.vfs.stat(e)}async exists(e){if(!this.isAllowed(e))return!1;if(this.isAllowedStrict(e))try{await this.resolveAndCheckRead(e)}catch{return!1}return this.vfs.exists(e)}async readTextFile(e){if(!this.isAllowedStrict(e))throw new N(`ENOENT`,`no such file or directory`,P(e));let t=await this.resolveAndCheckRead(e);return this.vfs.readTextFile(t)}async*walk(e){if(!this.isAllowed(e))return;let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return}for await(let e of this.vfs.walk(t))this.isAllowed(e)&&(yield e)}async writeFile(e,t,n){this.checkWrite(e);let r=this.vfs.dirname(e),i=this.vfs.basename(e);try{let t=await this.vfs.realpath(r);if(!this.isWritable(t+`/`+i))throw new N(`EACCES`,`permission denied`,P(e))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}try{(await this.vfs.lstat(e)).type===`symlink`&&await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.writeFile(e,t,n)}async mkdir(e,t){this.checkWrite(e);let n=this.vfs.dirname(e),r=this.vfs.basename(e);try{let t=await this.vfs.realpath(n);if(!this.isWritable(t+`/`+r))throw new N(`EACCES`,`permission denied`,P(e))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.mkdir(e,t)}async rm(e,t){this.checkWrite(e);try{(await this.vfs.lstat(e)).type===`symlink`||await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.rm(e,t)}async rename(e,t){this.checkWrite(e),this.checkWrite(t),await this.resolveAndCheckWrite(e);let n=this.vfs.dirname(t),r=this.vfs.basename(t);try{let e=await this.vfs.realpath(n);if(!this.isWritable(e+`/`+r))throw new N(`EACCES`,`permission denied`,P(t))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.rename(e,t)}async copyFile(e,t){if(!this.isAllowed(e))throw new N(`ENOENT`,`no such file or directory`,P(e));this.checkWrite(t);let n=await this.resolveAndCheckRead(e),r=this.vfs.dirname(t),i=this.vfs.basename(t);try{let e=await this.vfs.realpath(r);if(!this.isWritable(e+`/`+i))throw new N(`EACCES`,`permission denied`,P(t))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}try{(await this.vfs.lstat(t)).type===`symlink`&&await this.resolveAndCheckWrite(t)}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.copyFile(n,t)}async symlink(e,t){this.checkWrite(t);let n=this.vfs.dirname(t),r=this.vfs.basename(t);try{let e=await this.vfs.realpath(n);if(!this.isWritable(e+`/`+r))throw new N(`EACCES`,`permission denied`,P(t))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.symlink(e,t)}async readlink(e){if(!this.isAllowedStrict(e))throw new N(`ENOENT`,`no such file or directory`,P(e));let t=await this.vfs.readlink(e),n;if(n=t.startsWith(`/`)?P(t):P(this.vfs.dirname(e)+`/`+t),!this.isAllowedStrict(n))throw new N(`ENOENT`,`no such file or directory`,P(e));return t}async lstat(e){if(!this.isAllowed(e))throw new N(`ENOENT`,`no such file or directory`,P(e));return this.vfs.lstat(e)}watch(e,t,n){if(!this.isAllowed(e))throw new N(`EACCES`,`permission denied`,P(e));let r=this.vfs.getWatcher();if(!r)throw new N(`EINVAL`,`no watcher configured`);return r.watch(P(e),t,n)}dirname(e){return this.vfs.dirname(e)}basename(e){return this.vfs.basename(e)}async dispose(){await this.vfs.dispose()}},J=a(`fs-watcher`),Y=0;function X(e,t){return t===`/`||e===t||e.startsWith(t+`/`)}var Z=class{registrations=new Map;watch(e,t,n){let r=`fsw-${++Y}`;return this.registrations.set(r,{id:r,basePath:e,filter:t,callback:n}),J.debug(`Watch registered`,{id:r,basePath:e}),()=>{this.registrations.delete(r),J.debug(`Watch unregistered`,{id:r})}}notify(e){if(e.length!==0)for(let[,t]of this.registrations){let n=e.filter(e=>X(e.path,t.basePath)&&t.filter(e.path));if(n.length>0)try{t.callback(n)}catch(e){J.error(`Watch callback error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}}}dispose(){this.registrations.clear(),J.debug(`All watchers disposed`)}get size(){return this.registrations.size}},Q=r({VirtualFS:()=>K});export{U as a,F as c,K as i,N as l,Z as n,I as o,q as r,P as s,Q as t};
|
|
3
|
+
`),i=this._makeRoot(),a=[{indent:-1,node:i},{indent:0,node:null}];for(let e of r){let t=e.match(/^\t*/)[0].length;e=e.slice(t);let[r,...i]=e.split(` `),o=n(i);if(t<=a[a.length-1].indent)for(;t<=a[a.length-1].indent;)a.pop();a.push({indent:t,node:o}),a[a.length-2].node.set(r,o)}return i}_lookup(e,t=!0){let r=this._root,a=`/`,o=n.split(e);for(let s=0;s<o.length;++s){let l=o[s];if(r=r.get(l),!r)throw new i(e);if(t||s<o.length-1){let e=r.get(c);if(e.type===`symlink`){let t=n.resolve(a,e.target);r=this._lookup(t)}a=a?n.join(a,l):l}}return r}mkdir(e,{mode:t}){if(e===`/`)throw new r;let i=this._lookup(n.dirname(e)),a=n.basename(e);if(i.has(a))throw new r;let o=new Map,s={mode:t,type:`dir`,size:0,mtimeMs:Date.now(),ino:this.autoinc()};o.set(c,s),i.set(a,o)}rmdir(e){let t=this._lookup(e);if(t.get(c).type!==`dir`)throw new a;if(t.size>1)throw new o;let r=this._lookup(n.dirname(e)),i=n.basename(e);r.delete(i)}readdir(e){let t=this._lookup(e);if(t.get(c).type!==`dir`)throw new a;return[...t.keys()].filter(e=>typeof e==`string`)}writeStat(e,t,{mode:r}){let i,a;try{a=this.stat(e)}catch{}if(a!==void 0){if(a.type===`dir`)throw new s;r??=a.mode,i=a.ino}r??=438,i??=this.autoinc();let o=this._lookup(n.dirname(e)),l=n.basename(e),u={mode:r,type:`file`,size:t,mtimeMs:Date.now(),ino:i},d=new Map;return d.set(c,u),o.set(l,d),u}unlink(e){let t=this._lookup(n.dirname(e)),r=n.basename(e);t.delete(r)}rename(e,t){let r=n.basename(t),i=this._lookup(e);this._lookup(n.dirname(t)).set(r,i),this.unlink(e)}stat(e){return this._lookup(e).get(c)}lstat(e){return this._lookup(e,!1).get(c)}readlink(e){return this._lookup(e,!1).get(c).target}symlink(e,t){let r,i;try{let e=this.stat(t);i===null&&(i=e.mode),r=e.ino}catch{}i??=40960,r??=this.autoinc();let a=this._lookup(n.dirname(t)),o=n.basename(t),s={mode:i,type:`symlink`,target:e,size:0,mtimeMs:Date.now(),ino:r},l=new Map;return l.set(c,s),a.set(o,l),s}_du(e){let t=0;for(let[n,r]of e.entries())n===c?t+=r.size:t+=this._du(r);return t}du(e){let t=this._lookup(e);return this._du(t)}}})),p=r({Store:()=>S,clear:()=>y,close:()=>x,del:()=>v,get:()=>h,keys:()=>b,set:()=>g,update:()=>_});function m(){return C||=new S,C}function h(e,t=m()){let n;return t._withIDBStore(`readwrite`,t=>{n=t.get(e)}).then(()=>n.result)}function g(e,t,n=m()){return n._withIDBStore(`readwrite`,n=>{n.put(t,e)})}function _(e,t,n=m()){return n._withIDBStore(`readwrite`,n=>{let r=n.get(e);r.onsuccess=()=>{n.put(t(r.result),e)}})}function v(e,t=m()){return t._withIDBStore(`readwrite`,t=>{t.delete(e)})}function y(e=m()){return e._withIDBStore(`readwrite`,e=>{e.clear()})}function b(e=m()){let t=[];return e._withIDBStore(`readwrite`,e=>{(e.openKeyCursor||e.openCursor).call(e).onsuccess=function(){this.result&&(t.push(this.result.key),this.result.continue())}}).then(()=>t)}function x(e=m()){return e._close()}var S,C,w=t((()=>{S=class{constructor(e=`keyval-store`,t=`keyval`){this.storeName=t,this._dbName=e,this._storeName=t,this._init()}_init(){this._dbp||=new Promise((e,t)=>{let n=indexedDB.open(this._dbName);n.onerror=()=>t(n.error),n.onsuccess=()=>e(n.result),n.onupgradeneeded=()=>{n.result.createObjectStore(this._storeName)}})}_withIDBStore(e,t){return this._init(),this._dbp.then(n=>new Promise((r,i)=>{let a=n.transaction(this.storeName,e);a.oncomplete=()=>r(),a.onabort=a.onerror=()=>i(a.error),t(a.objectStore(this.storeName))}))}_close(){return this._init(),this._dbp.then(e=>{e.close(),this._dbp=void 0})}}})),T=i(((t,n)=>{var r=(w(),e(p));n.exports=class{constructor(e,t){this._database=e,this._storename=t,this._store=new r.Store(this._database,this._storename)}saveSuperblock(e){return r.set(`!root`,e,this._store)}loadSuperblock(){return r.get(`!root`,this._store)}readFile(e){return r.get(e,this._store)}writeFile(e,t){return r.set(e,t,this._store)}unlink(e){return r.del(e,this._store)}wipe(){return r.clear(this._store)}close(){return r.close(this._store)}}})),E=i(((e,t)=>{t.exports=class{constructor(e){this._url=e}loadSuperblock(){return fetch(this._url+`/.superblock.txt`).then(e=>e.ok?e.text():null)}async readFile(e){let t=await fetch(this._url+e);if(t.status===200)return t.arrayBuffer();throw Error(`ENOENT`)}async sizeFile(e){let t=await fetch(this._url+e,{method:`HEAD`});if(t.status===200)return t.headers.get(`content-length`);throw Error(`ENOENT`)}}})),D=i(((t,n)=>{var r=(w(),e(p)),i=e=>new Promise(t=>setTimeout(t,e));n.exports=class{constructor(e,t){this._id=Math.random(),this._database=e,this._storename=t,this._store=new r.Store(this._database,this._storename),this._lock=null}async has({margin:e=2e3}={}){if(this._lock&&this._lock.holder===this._id){let t=Date.now();return this._lock.expires>t+e?!0:await this.renew()}else return!1}async renew({ttl:e=5e3}={}){let t;return await r.update(`lock`,n=>{let r=Date.now()+e;return t=n&&n.holder===this._id,this._lock=t?{holder:this._id,expires:r}:n,this._lock},this._store),t}async acquire({ttl:e=5e3}={}){let t,n,i;if(await r.update(`lock`,r=>{let a=Date.now(),o=a+e;return n=r&&r.expires<a,t=r===void 0||n,i=r&&r.holder===this._id,this._lock=t?{holder:this._id,expires:o}:r,this._lock},this._store),i)throw Error(`Mutex double-locked`);return t}async wait({interval:e=100,limit:t=6e3,ttl:n}={}){for(;t--;){if(await this.acquire({ttl:n}))return!0;await i(e)}throw Error(`Mutex timeout`)}async release({force:e=!1}={}){let t,n,i;if(await r.update(`lock`,r=>(t=e||r&&r.holder===this._id,n=r===void 0,i=r&&r.holder!==this._id,this._lock=t?void 0:r,this._lock),this._store),await r.close(this._store),!t&&!e){if(n)throw Error(`Mutex double-freed`);if(i)throw Error(`Mutex lost ownership`)}return t}}})),O=i(((e,t)=>{t.exports=class{constructor(e){this._id=Math.random(),this._database=e,this._has=!1,this._release=null}async has(){return this._has}async acquire(){return new Promise(e=>{navigator.locks.request(this._database+`_lock`,{ifAvailable:!0},t=>(this._has=!!t,e(!!t),new Promise(e=>{this._release=e})))})}async wait({timeout:e=6e5}={}){return new Promise((t,n)=>{let r=new AbortController;setTimeout(()=>{r.abort(),n(Error(`Mutex timeout`))},e),navigator.locks.request(this._database+`_lock`,{signal:r.signal},e=>(this._has=!!e,t(!!e),new Promise(e=>{this._release=e})))})}async release({force:e=!1}={}){this._has=!1,this._release?this._release():e&&navigator.locks.request(this._database+`_lock`,{steal:!0},e=>!0)}}})),k=i(((e,t)=>{var{encode:n,decode:r}=c(),i=l(),a=f(),{ENOENT:o,ENOTEMPTY:s,ETIMEDOUT:p}=d(),m=T(),h=E(),g=D(),_=O(),v=u();t.exports=class{constructor(){this.saveSuperblock=i(()=>{this.flush()},500)}async init(e,{wipe:t,url:n,urlauto:r,fileDbName:i=e,db:o=null,fileStoreName:s=e+`_files`,lockDbName:c=e+`_lock`,lockStoreName:l=e+`_lock`}={}){this._name=e,this._idb=o||new m(i,s),this._mutex=navigator.locks?new _(e):new g(c,l),this._cache=new a(e),this._opts={wipe:t,url:n},this._needsWipe=!!t,n&&(this._http=new h(n),this._urlauto=!!r)}async activate(){if(this._cache.activated)return;this._needsWipe&&(this._needsWipe=!1,await this._idb.wipe(),await this._mutex.release({force:!0})),await this._mutex.has()||await this._mutex.wait();let e=await this._idb.loadSuperblock();if(e)this._cache.activate(e);else if(this._http){let e=await this._http.loadSuperblock();this._cache.activate(e),await this._saveSuperblock()}else this._cache.activate();if(!await this._mutex.has())throw new p}async deactivate(){await this._mutex.has()&&await this._saveSuperblock(),this._cache.deactivate();try{await this._mutex.release()}catch(e){console.log(e)}await this._idb.close()}async _saveSuperblock(){this._cache.activated&&(this._lastSavedAt=Date.now(),await this._idb.saveSuperblock(this._cache._root))}_writeStat(e,t,n){let r=v.split(v.dirname(e)),i=r.shift();for(let e of r){i=v.join(i,e);try{this._cache.mkdir(i,{mode:511})}catch{}}return this._cache.writeStat(e,t,n)}async readFile(e,t){let n=typeof t==`string`?t:t&&t.encoding;if(n&&n!==`utf8`)throw Error(`Only "utf8" encoding is supported in readFile`);let i=null,a=null;try{a=this._cache.stat(e),i=await this._idb.readFile(a.ino)}catch(e){if(!this._urlauto)throw e}if(!i&&this._http){let t=this._cache.lstat(e);for(;t.type===`symlink`;)e=v.resolve(v.dirname(e),t.target),t=this._cache.lstat(e);i=await this._http.readFile(e)}if(i&&((!a||a.size!=i.byteLength)&&(a=await this._writeStat(e,i.byteLength,{mode:a?a.mode:438}),this.saveSuperblock()),n===`utf8`?i=r(i):i.toString=()=>r(i)),!a)throw new o(e);return i}async writeFile(e,t,r){let{mode:i,encoding:a=`utf8`}=r;if(typeof t==`string`){if(a!==`utf8`)throw Error(`Only "utf8" encoding is supported in writeFile`);t=n(t)}let o=await this._cache.writeStat(e,t.byteLength,{mode:i});await this._idb.writeFile(o.ino,t)}async unlink(e,t){let n=this._cache.lstat(e);this._cache.unlink(e),n.type!==`symlink`&&await this._idb.unlink(n.ino)}readdir(e,t){return this._cache.readdir(e)}mkdir(e,t){let{mode:n=511}=t;this._cache.mkdir(e,{mode:n})}rmdir(e,t){if(e===`/`)throw new s;this._cache.rmdir(e)}rename(e,t){this._cache.rename(e,t)}stat(e,t){return this._cache.stat(e)}lstat(e,t){return this._cache.lstat(e)}readlink(e,t){return this._cache.readlink(e)}symlink(e,t){this._cache.symlink(e,t)}async backFile(e,t){let n=await this._http.sizeFile(e);await this._writeStat(e,n,t)}du(e){return this._cache.du(e)}flush(){return this._saveSuperblock()}}})),A=i(((e,t)=>{t.exports=class{constructor(e){this.type=e.type,this.mode=e.mode,this.size=e.size,this.ino=e.ino,this.mtimeMs=e.mtimeMs,this.ctimeMs=e.ctimeMs||e.mtimeMs,this.uid=1,this.gid=1,this.dev=1}isFile(){return this.type===`file`}isDirectory(){return this.type===`dir`}isSymbolicLink(){return this.type===`symlink`}}})),j=i(((e,t)=>{var n=k(),r=A(),i=u();function a(e,t,...n){return e=i.normalize(e),(t===void 0||typeof t==`function`)&&(t={}),typeof t==`string`&&(t={encoding:t}),[e,t,...n]}function o(e,t,n,...r){return e=i.normalize(e),(n===void 0||typeof n==`function`)&&(n={}),typeof n==`string`&&(n={encoding:n}),[e,t,n,...r]}function s(e,t,...n){return[i.normalize(e),i.normalize(t),...n]}t.exports=class{constructor(e,t={}){this.init=this.init.bind(this),this.readFile=this._wrap(this.readFile,a,!1),this.writeFile=this._wrap(this.writeFile,o,!0),this.unlink=this._wrap(this.unlink,a,!0),this.readdir=this._wrap(this.readdir,a,!1),this.mkdir=this._wrap(this.mkdir,a,!0),this.rmdir=this._wrap(this.rmdir,a,!0),this.rename=this._wrap(this.rename,s,!0),this.stat=this._wrap(this.stat,a,!1),this.lstat=this._wrap(this.lstat,a,!1),this.readlink=this._wrap(this.readlink,a,!1),this.symlink=this._wrap(this.symlink,s,!0),this.backFile=this._wrap(this.backFile,a,!0),this.du=this._wrap(this.du,a,!1),this._deactivationPromise=null,this._deactivationTimeout=null,this._activationPromise=null,this._operations=new Set,e&&this.init(e,t)}async init(...e){return this._initPromiseResolve&&await this._initPromise,this._initPromise=this._init(...e),this._initPromise}async _init(e,t={}){await this._gracefulShutdown(),this._activationPromise&&await this._deactivate(),this._backend&&this._backend.destroy&&await this._backend.destroy(),this._backend=t.backend||new n,this._backend.init&&await this._backend.init(e,t),this._initPromiseResolve&&=(this._initPromiseResolve(),null),t.defer||this.stat(`/`)}async _gracefulShutdown(){this._operations.size>0&&(this._isShuttingDown=!0,await new Promise(e=>this._gracefulShutdownResolve=e),this._isShuttingDown=!1,this._gracefulShutdownResolve=null)}_wrap(e,t,n){return async(...r)=>{r=t(...r);let i={name:e.name,args:r};this._operations.add(i);try{return await this._activate(),await e.apply(this,r)}finally{this._operations.delete(i),n&&this._backend.saveSuperblock(),this._operations.size===0&&(this._deactivationTimeout||clearTimeout(this._deactivationTimeout),this._deactivationTimeout=setTimeout(this._deactivate.bind(this),500))}}}async _activate(){this._initPromise||console.warn(Error(`Attempted to use LightningFS ${this._name} before it was initialized.`)),await this._initPromise,this._deactivationTimeout&&=(clearTimeout(this._deactivationTimeout),null),this._deactivationPromise&&await this._deactivationPromise,this._deactivationPromise=null,this._activationPromise||=this._backend.activate?this._backend.activate():Promise.resolve(),await this._activationPromise}async _deactivate(){return this._activationPromise&&await this._activationPromise,this._deactivationPromise||=this._backend.deactivate?this._backend.deactivate():Promise.resolve(),this._activationPromise=null,this._gracefulShutdownResolve&&this._gracefulShutdownResolve(),this._deactivationPromise}async readFile(e,t){return this._backend.readFile(e,t)}async writeFile(e,t,n){return await this._backend.writeFile(e,t,n),null}async unlink(e,t){return await this._backend.unlink(e,t),null}async readdir(e,t){return this._backend.readdir(e,t)}async mkdir(e,t){return await this._backend.mkdir(e,t),null}async rmdir(e,t){return await this._backend.rmdir(e,t),null}async rename(e,t){return await this._backend.rename(e,t),null}async stat(e,t){return new r(await this._backend.stat(e,t))}async lstat(e,t){return new r(await this._backend.lstat(e,t))}async readlink(e,t){return this._backend.readlink(e,t)}async symlink(e,t){return await this._backend.symlink(e,t),null}async backFile(e,t){return await this._backend.backFile(e,t),null}async du(e){return this._backend.du(e)}async flush(){return this._backend.flush()}}})),M=n(i(((e,t)=>{var n=o(),r=j();function i(e,t){return typeof e==`function`&&(t=e),t=n(t),[(...e)=>t(null,...e),t]}t.exports=class{constructor(...e){this.promises=new r(...e),this.init=this.init.bind(this),this.readFile=this.readFile.bind(this),this.writeFile=this.writeFile.bind(this),this.unlink=this.unlink.bind(this),this.readdir=this.readdir.bind(this),this.mkdir=this.mkdir.bind(this),this.rmdir=this.rmdir.bind(this),this.rename=this.rename.bind(this),this.stat=this.stat.bind(this),this.lstat=this.lstat.bind(this),this.readlink=this.readlink.bind(this),this.symlink=this.symlink.bind(this),this.backFile=this.backFile.bind(this),this.du=this.du.bind(this),this.flush=this.flush.bind(this)}init(e,t){return this.promises.init(e,t)}readFile(e,t,n){let[r,a]=i(t,n);this.promises.readFile(e,t).then(r).catch(a)}writeFile(e,t,n,r){let[a,o]=i(n,r);this.promises.writeFile(e,t,n).then(a).catch(o)}unlink(e,t,n){let[r,a]=i(t,n);this.promises.unlink(e,t).then(r).catch(a)}readdir(e,t,n){let[r,a]=i(t,n);this.promises.readdir(e,t).then(r).catch(a)}mkdir(e,t,n){let[r,a]=i(t,n);this.promises.mkdir(e,t).then(r).catch(a)}rmdir(e,t,n){let[r,a]=i(t,n);this.promises.rmdir(e,t).then(r).catch(a)}rename(e,t,n){let[r,a]=i(n);this.promises.rename(e,t).then(r).catch(a)}stat(e,t,n){let[r,a]=i(t,n);this.promises.stat(e).then(r).catch(a)}lstat(e,t,n){let[r,a]=i(t,n);this.promises.lstat(e).then(r).catch(a)}readlink(e,t,n){let[r,a]=i(t,n);this.promises.readlink(e).then(r).catch(a)}symlink(e,t,n){let[r,a]=i(n);this.promises.symlink(e,t).then(r).catch(a)}backFile(e,t,n){let[r,a]=i(t,n);this.promises.backFile(e,t).then(r).catch(a)}du(e,t){let[n,r]=i(t);this.promises.du(e).then(n).catch(r)}flush(e){let[t,n]=i(e);this.promises.flush().then(t).catch(n)}}}))(),1),N=class extends Error{constructor(e,t,n){super(`${e}: ${t}${n?` '${n}'`:``}`),this.code=e,this.path=n,this.name=`FsError`}};function P(e){if(!e||e===`/`)return`/`;e.startsWith(`/`)||(e=`/`+e);let t=e.split(`/`),n=[];for(let e of t)e===``||e===`.`||(e===`..`?n.pop():n.push(e));return`/`+n.join(`/`)}function F(e){let t=P(e);if(t===`/`)return{dir:`/`,base:``};let n=t.lastIndexOf(`/`);return{dir:n===0?`/`:t.slice(0,n),base:t.slice(n+1)}}function I(...e){return P(e.join(`/`))}var L=`slicc-mount-table`,R=1,z=`mounts`;function B(){return new Promise((e,t)=>{let n=indexedDB.open(L,R);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(z)||e.createObjectStore(z)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function V(e,t){let n=await B();try{let r=n.transaction(z,`readwrite`);r.objectStore(z).put(t,e),await new Promise((e,t)=>{r.oncomplete=()=>e(),r.onerror=()=>t(r.error),r.onabort=()=>t(r.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{n.close()}}async function H(e){let t=await B();try{let n=t.transaction(z,`readwrite`);n.objectStore(z).delete(e),await new Promise((e,t)=>{n.oncomplete=()=>e(),n.onerror=()=>t(n.error),n.onabort=()=>t(n.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{t.close()}}async function U(){let e=await B();try{let t=e.transaction(z,`readonly`),n=t.objectStore(z),r=()=>t.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`),i=await new Promise((e,i)=>{let a=n.getAllKeys();a.onsuccess=()=>e(a.result),a.onerror=()=>i(a.error),t.onabort=()=>i(r())}),a=await new Promise((e,i)=>{let a=n.getAll();a.onsuccess=()=>e(a.result),a.onerror=()=>i(a.error),t.onabort=()=>i(r())});return i.map((e,t)=>({path:e,handle:a[t]}))}finally{e.close()}}async function W(){let e=await B();try{let t=e.transaction(z,`readwrite`);t.objectStore(z).clear(),await new Promise((e,n)=>{t.oncomplete=()=>e(),t.onerror=()=>n(t.error),t.onabort=()=>n(t.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{e.close()}}var G=10,K=class e{lfs;rawFs;_ready;mountPoints=new Map;watcher=null;dbName;mountSyncChannel=null;constructor(e,t){this.dbName=e;let n=new M.default(e,{wipe:t});if(this.rawFs=n,this.lfs=n.promises,this._ready=this.lfs.stat(`/`).then(()=>{}).catch(()=>{}),typeof BroadcastChannel<`u`)try{this.mountSyncChannel=new BroadcastChannel(`vfs-mount-sync:${e}`),this.mountSyncChannel.onmessage=e=>{let{type:t,path:n,handle:r}=e.data??{};t===`mount`&&typeof n==`string`&&r?(this.mountPoints.set(n,r),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])):t===`unmount`&&typeof n==`string`&&(this.mountPoints.delete(n),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]))}}catch{}}static async create(t){let n=t?.dbName??`browser-fs`,r=t?.wipe??!1,i=new e(n,r);return await i._ready,r&&await W().catch(()=>{}),i}getLightningFS(){return this.lfs}setWatcher(e){this.watcher=e}getWatcher(){return this.watcher}async dispose(){this.mountSyncChannel?.close(),this.mountSyncChannel=null,this.watcher?.dispose(),this.watcher=null;let e=this.lfs;if(e._deactivationTimeout&&=(clearTimeout(e._deactivationTimeout),null),e._operations?.size>0&&await e._gracefulShutdown?.(),e._backend?.saveSuperblock?.cancel&&e._backend.saveSuperblock.cancel(),e._backend){try{e._backend.flush&&await e._backend.flush()}catch{}e._backend.deactivate&&await e._backend.deactivate()}if(e._backend=null,e._activationPromise=null,e._deactivationPromise=null,e._initPromise=null,typeof indexedDB<`u`&&indexedDB.deleteDatabase)try{let e=indexedDB.deleteDatabase(this.dbName);await new Promise((t,n)=>{e.onsuccess=()=>t(),e.onerror=()=>n(e.error)})}catch{}}getCacheFS(){try{let e=this.lfs._backend?._cache;return e?.activated&&e._root instanceof Map?e:null}catch{return null}}readDirSync(e){let t=P(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=n.readdir(t),r=[];for(let i of e){let e=t===`/`?`/${i}`:`${t}/${i}`;try{let t=n.lstat(e),a=t.type===`symlink`?`symlink`:t.type===`dir`?`directory`:`file`;r.push({name:i,type:a})}catch{}}return r}catch{return null}}statSync(e){let t=P(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=this.resolveSymlinksSync(n,t);if(e===null)return null;let r=n.lstat(e);return{type:r.type===`dir`?`directory`:`file`,size:r.size??0,mtime:r.mtimeMs??Date.now(),ctime:r.mtimeMs??Date.now()}}catch{return null}}resolveSymlinksSync(e,t,n={count:0}){let r=t.split(`/`).filter(Boolean),i=`/`;for(let t of r){i=i===`/`?`/${t}`:`${i}/${t}`;try{let t=e.lstat(i);if(t.type===`symlink`){if(++n.count>G)return null;let r=t.target;if(r.startsWith(`/`))i=P(r);else{let{dir:e}=F(i);i=P(I(e,r))}let a=this.resolveSymlinksSync(e,i,n);if(a===null)return null;i=a}}catch{return null}}return i}lstatSync(e){let t=P(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=n.lstat(t);return e.type===`symlink`?{type:`symlink`,size:e.size??0,mtime:e.mtimeMs??Date.now(),ctime:e.mtimeMs??Date.now(),isSymlink:!0,symlinkTarget:e.target}:{type:e.type===`dir`?`directory`:`file`,size:e.size??0,mtime:e.mtimeMs??Date.now(),ctime:e.mtimeMs??Date.now()}}catch{return null}}async mount(e,t){let n=P(e);if(this.mountPoints.has(n))throw new N(`EEXIST`,`mount point is already mounted`,n);try{if((await this.lstat(n)).type!==`directory`)throw new N(`ENOTDIR`,`mount point must be a directory`,n);if((await this.readDir(n)).length>0)throw new N(`ENOTEMPTY`,`mount point must be empty to avoid shadowing existing files`,n)}catch(e){if(!(e instanceof N)||e.code!==`ENOENT`)throw e}let{dir:r}=F(n);r!==`/`&&await this.mkdir(r,{recursive:!0});try{await this.lfs.mkdir(n)}catch{}this.mountPoints.set(n,t);try{this.mountSyncChannel?.postMessage({type:`mount`,path:n,handle:t})}catch{}this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]);try{await V(n,t)}catch{}}async unmount(e){let t=P(e);this.mountPoints.delete(t);try{this.mountSyncChannel?.postMessage({type:`unmount`,path:t})}catch{}this.watcher?.notify([{type:`modify`,path:t,entryType:`directory`}]);try{await H(t)}catch{}}listMounts(){return[...this.mountPoints.keys()]}isPathUnderMount(e){for(let t of this.mountPoints.keys())if(e===t||e.startsWith(t+`/`))return!0;return!1}findMount(e){let t=null;for(let[n,r]of this.mountPoints)(e===n||e.startsWith(n+`/`))&&(!t||n.length>t.mountPath.length)&&(t={mountPath:n,handle:r});return t?e===t.mountPath?{handle:t.handle,relParts:[]}:{handle:t.handle,relParts:e.slice(t.mountPath.length+1).split(`/`).filter(Boolean)}:null}static async fsaNavDir(e,t,n=!1){let r=e;for(let e of t)r=await r.getDirectoryHandle(e,{create:n});return r}static async fsaGetFile(t,n,r=!1){return(await e.fsaNavDir(t,n.slice(0,-1),r)).getFileHandle(n[n.length-1],{create:r})}convertFsaError(e,t){if(e instanceof N)return e;if(e instanceof Error){if(e.name===`NotFoundError`)return new N(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatchError`)return new N(`ENOTDIR`,`not a directory`,t);if(e.name===`NotAllowedError`)return new N(`EINVAL`,`permission denied`,t);if(e.name===`InvalidModificationError`)return new N(`ENOTEMPTY`,`directory not empty`,t)}return new N(`EINVAL`,e instanceof Error?e.message:String(e),t)}async readFile(t,n){let r=P(t),i=this.findMount(r);if(i){if(i.relParts.length===0)throw new N(`EISDIR`,`is a directory`,r);try{let t=await(await e.fsaGetFile(i.handle,i.relParts)).getFile();return(n?.encoding??`utf-8`)===`utf-8`?await t.text():new Uint8Array(await t.arrayBuffer())}catch(e){throw this.convertFsaError(e,r)}}let a=await this.resolveSymlinks(r);try{return(n?.encoding??`utf-8`)===`utf-8`?await this.lfs.readFile(a,{encoding:`utf8`}):await this.lfs.readFile(a)}catch(e){throw this.convertError(e,r)}}async writeFile(t,n,r){let i=P(t),a=this.findMount(i);if(a){if(a.relParts.length===0)throw new N(`EISDIR`,`is a directory`,i);let t=!1;try{await this.stat(i),t=!0}catch{}try{let t=await(await e.fsaGetFile(a.handle,a.relParts,!0)).createWritable(),r=typeof n==`string`?new TextEncoder().encode(n):n instanceof Uint8Array?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n);await t.write(r),await t.close()}catch(e){throw this.convertFsaError(e,i)}this.watcher?.notify([{type:t?`modify`:`create`,path:i,entryType:`file`}]);return}let o;try{o=await this.resolveSymlinks(i)}catch{o=i}let s=!1;try{await this.lfs.stat(o),s=!0}catch{}let{dir:c}=F(o);c!==`/`&&await this.mkdir(c,{recursive:!0});try{await this.lfs.writeFile(o,n)}catch(e){throw this.convertError(e,i)}this.watcher?.notify([{type:s?`modify`:`create`,path:o,entryType:`file`}])}async readDir(t){let n=P(t),r=this.findMount(n);if(r)try{let t=r.relParts.length===0?r.handle:await e.fsaNavDir(r.handle,r.relParts),i=new Map;for await(let[e,n]of t)i.set(e,{name:e,type:n.kind===`directory`?`directory`:`file`});let a=n===`/`?`/`:`${n}/`;for(let e of this.mountPoints.keys()){if(e===n||!e.startsWith(a))continue;let t=e.slice(a.length);!t||t.includes(`/`)||i.has(t)||i.set(t,{name:t,type:`directory`})}return[...i.values()]}catch(e){throw this.convertFsaError(e,n)}let i=await this.resolveSymlinks(n);try{let e=await this.lfs.readdir(i),t=[];for(let n of e){let e=i===`/`?`/${n}`:`${i}/${n}`;try{let r=await this.lfs.lstat(e);r.isSymbolicLink()?t.push({name:n,type:`symlink`}):t.push({name:n,type:r.isDirectory()?`directory`:`file`})}catch{}}return t}catch(e){throw this.convertError(e,n)}}async mkdir(t,n){let r=P(t);if(r===`/`)return;let i=this.findMount(r);if(i){if(i.relParts.length===0)return;try{let t=await this.exists(r);await e.fsaNavDir(i.handle,i.relParts,!0),t||this.watcher?.notify([{type:`create`,path:r,entryType:`directory`}])}catch(e){throw this.convertFsaError(e,r)}return}if(n?.recursive){let e=r.split(`/`).filter(Boolean),t=``;for(let n of e){t+=`/`+n;try{await this.lfs.mkdir(t)}catch(e){if(e instanceof Error&&!e.message.includes(`EEXIST`))throw this.convertError(e,t)}}}else{try{await this.lfs.mkdir(r)}catch(e){throw this.convertError(e,r)}this.watcher?.notify([{type:`create`,path:r,entryType:`directory`}])}}async rm(t,n){let r=P(t),i=this.findMount(r);if(i){if(i.relParts.length===0)throw new N(`EINVAL`,`cannot remove a mount point — use unmount`,r);let t;try{t=(await this.stat(r)).type}catch{}try{let t=i.relParts.slice(0,-1),r=i.relParts[i.relParts.length-1];await(t.length===0?i.handle:await e.fsaNavDir(i.handle,t)).removeEntry(r,{recursive:n?.recursive})}catch(e){throw this.convertFsaError(e,r)}this.watcher?.notify([{type:`delete`,path:r,entryType:t}]);return}try{let e=await this.lfs.lstat(r);e.isSymbolicLink()?await this.lfs.unlink(r):e.isDirectory()?n?.recursive?await this.rmRecursive(r):await this.lfs.rmdir(r):await this.lfs.unlink(r)}catch(e){throw this.convertError(e,r)}this.watcher?.notify([{type:`delete`,path:r}])}async rmRecursive(e){let t=await this.lfs.readdir(e);for(let n of t){let t=e===`/`?`/${n}`:`${e}/${n}`;(await this.lfs.stat(t)).isDirectory()?await this.rmRecursive(t):await this.lfs.unlink(t)}await this.lfs.rmdir(e)}async stat(t){let n=P(t),r=this.findMount(n);if(r){if(r.relParts.length===0)try{let e=await this.lfs.stat(n);return{type:`directory`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch{return{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}try{try{let t=await(await e.fsaGetFile(r.handle,r.relParts)).getFile();return{type:`file`,size:t.size,mtime:t.lastModified,ctime:t.lastModified}}catch{return await e.fsaNavDir(r.handle,r.relParts),{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}}catch(e){throw this.convertFsaError(e,n)}}let i=await this.resolveSymlinks(n);try{let e=await this.lfs.stat(i);return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch(e){throw this.convertError(e,n)}}async exists(e){let t=P(e),n=this.findMount(t);if(n){if(n.relParts.length===0)return!0;try{return await this.stat(t),!0}catch{return!1}}try{return await this.stat(t),!0}catch{try{return await this.lfs.lstat(t),!0}catch{return!1}}}async rename(e,t){let n=P(e),r=P(t),i;try{i=(await this.lstat(n)).type}catch{}try{await this.lfs.rename(n,r)}catch(e){throw this.convertError(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:i},{type:`create`,path:r,entryType:i}])}async readTextFile(e){return await this.readFile(e,{encoding:`utf-8`})}async*walk(e,t){let n=P(e),r=t??new Set,i;try{i=await this.realpath(n)}catch{i=n}if(r.has(i))return;r.add(i);let a=await this.readDir(n);for(let e of a){let t=n===`/`?`/${e.name}`:`${n}/${e.name}`;if(e.type===`file`)yield t;else if(e.type===`symlink`)try{let e=await this.stat(t);e.type===`file`?yield t:e.type===`directory`&&(yield*this.walk(t,r))}catch{}else yield*this.walk(t,r)}}async copyFile(e,t){if((await this.stat(e)).type===`directory`)throw new N(`EISDIR`,`is a directory`,e);let n=await this.readFile(e,{encoding:`binary`});await this.writeFile(t,n)}dirname(e){return F(P(e)).dir}basename(e){return F(P(e)).base}async symlink(e,t){let n=P(t);if(this.findMount(n))throw new N(`EINVAL`,`symlinks not supported on mounted filesystems`,n);let{dir:r}=F(n);r!==`/`&&await this.mkdir(r,{recursive:!0});try{await this.lfs.symlink(e,n)}catch(e){throw this.convertError(e,n)}this.watcher?.notify([{type:`create`,path:n,entryType:`symlink`}])}async readlink(e){let t=P(e);try{return await this.lfs.readlink(t)}catch(e){throw this.convertError(e,t)}}async lstat(e){let t=P(e);if(this.findMount(t))return this.stat(t);try{let e=await this.lfs.lstat(t);if(e.isSymbolicLink()){let n=await this.lfs.readlink(t);return{type:`symlink`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,isSymlink:!0,symlinkTarget:n}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch(e){throw this.convertError(e,t)}}async realpath(e,t=0){let n=P(e);if(this.findMount(n))return n;let r=n.split(`/`).filter(Boolean),i=`/`,a=t;for(let t of r){i=i===`/`?`/${t}`:`${i}/${t}`;try{if((await this.lfs.lstat(i)).isSymbolicLink()){if(++a>G)throw new N(`ELOOP`,`too many levels of symbolic links`,e);let t=await this.lfs.readlink(i);if(t.startsWith(`/`))i=P(t);else{let{dir:e}=F(i);i=P(I(e,t))}i=await this.realpath(i,a)}}catch(e){throw e instanceof N?e:this.convertError(e,i)}}return i}async resolveSymlinks(e){return this.findMount(e)?e:this.realpath(e)}convertError(e,t){if(e instanceof N)return e;let n=e instanceof Error?e.message:String(e);return n.includes(`ENOENT`)?new N(`ENOENT`,`no such file or directory`,t):n.includes(`EEXIST`)?new N(`EEXIST`,`file already exists`,t):n.includes(`ENOTDIR`)?new N(`ENOTDIR`,`not a directory`,t):n.includes(`EISDIR`)?new N(`EISDIR`,`is a directory`,t):n.includes(`ENOTEMPTY`)?new N(`ENOTEMPTY`,`directory not empty`,t):n.includes(`ELOOP`)?new N(`ELOOP`,`too many levels of symbolic links`,t):new N(`EINVAL`,n,t)}},q=class{vfs;allowedPrefixes;readOnlyPrefixes;constructor(e,t,n=[]){this.vfs=e;let r=e=>{let t=P(e);return t.endsWith(`/`)?t:t+`/`};this.allowedPrefixes=t.map(r),this.readOnlyPrefixes=n.map(r)}getAllPrefixes(){let e=this.vfs.listMounts().map(e=>e.endsWith(`/`)?e:e+`/`);return[...this.allowedPrefixes,...this.readOnlyPrefixes,...e]}isAllowed(e){let t=P(e);return this.getAllPrefixes().some(e=>t===e.slice(0,-1)||t.startsWith(e)||t===`/`||e.startsWith(t+`/`))}isAllowedStrict(e){let t=P(e);return this.getAllPrefixes().some(e=>t===e.slice(0,-1)||t.startsWith(e))}isWritable(e){let t=P(e);return this.allowedPrefixes.some(e=>t===e.slice(0,-1)||t.startsWith(e))}checkWrite(e){if(!this.isWritable(e))throw new N(`EACCES`,`permission denied`,P(e))}async resolveAndCheckRead(e){try{let t=await this.vfs.realpath(e);if(!this.isAllowedStrict(t))throw new N(`ENOENT`,`no such file or directory`,P(e));return t}catch(t){throw t instanceof N?t:new N(`ENOENT`,`no such file or directory`,P(e))}}async resolveAndCheckWrite(e){try{let t=await this.vfs.realpath(e);if(!this.isWritable(t))throw new N(`EACCES`,`permission denied`,P(e));return t}catch(t){throw t instanceof N?t:new N(`EACCES`,`permission denied`,P(e))}}getUnderlyingFS(){return this.vfs}getLightningFS(){return this.vfs.getLightningFS()}async readFile(e,t){if(!this.isAllowedStrict(e))throw new N(`ENOENT`,`no such file or directory`,P(e));let n=await this.resolveAndCheckRead(e);return this.vfs.readFile(n,t)}async readDir(e){if(!this.isAllowed(e))return[];let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return[]}let n=await this.vfs.readDir(t);if(!this.isAllowedStrict(e)){let t=P(e);return n.filter(e=>{let n=t===`/`?`/${e.name}`:`${t}/${e.name}`;return this.isAllowed(n)})}return n}async stat(e){if(!this.isAllowed(e))throw new N(`ENOENT`,`no such file or directory`,P(e));if(this.isAllowedStrict(e)){let t=await this.resolveAndCheckRead(e);return this.vfs.stat(t)}return this.vfs.stat(e)}scanPathForSymlinks(e,t){let n=P(e);if(n===`/`)return!1;let r=n.slice(1).split(`/`),i=t?r.length:r.length-1,a=``;for(let e=0;e<i;e++){a=a+`/`+r[e];let t=this.vfs.lstatSync(a);if(t===null)return null;if(t.type===`symlink`)return!0}return!1}statSync(e){return!this.isAllowedStrict(e)||this.scanPathForSymlinks(e,!0)!==!1?null:this.vfs.statSync(e)}lstatSync(e){return!this.isAllowed(e)||this.scanPathForSymlinks(e,!1)!==!1?null:this.vfs.lstatSync(e)}readDirSync(e){if(!this.isAllowed(e)||this.scanPathForSymlinks(e,!0)!==!1)return null;let t=this.vfs.readDirSync(e);if(t===null)return null;if(this.isAllowedStrict(e))return t;let n=P(e);return t.filter(e=>{let t=n===`/`?`/${e.name}`:`${n}/${e.name}`;return this.isAllowed(t)})}async realpath(e){let t;try{t=await this.vfs.realpath(e)}catch(t){throw t instanceof N?t:new N(`ENOENT`,`no such file or directory`,P(e))}if(!this.isAllowedStrict(t))throw new N(`ENOENT`,`no such file or directory`,P(e));return t}async exists(e){if(!this.isAllowed(e))return!1;if(this.isAllowedStrict(e))try{await this.resolveAndCheckRead(e)}catch{return!1}return this.vfs.exists(e)}async readTextFile(e){if(!this.isAllowedStrict(e))throw new N(`ENOENT`,`no such file or directory`,P(e));let t=await this.resolveAndCheckRead(e);return this.vfs.readTextFile(t)}async*walk(e){if(!this.isAllowed(e))return;let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return}for await(let e of this.vfs.walk(t))this.isAllowed(e)&&(yield e)}async writeFile(e,t,n){this.checkWrite(e);let r=this.vfs.dirname(e),i=this.vfs.basename(e);try{let t=await this.vfs.realpath(r);if(!this.isWritable(t+`/`+i))throw new N(`EACCES`,`permission denied`,P(e))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}try{(await this.vfs.lstat(e)).type===`symlink`&&await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.writeFile(e,t,n)}async mkdir(e,t){this.checkWrite(e);let n=this.vfs.dirname(e),r=this.vfs.basename(e);try{let t=await this.vfs.realpath(n);if(!this.isWritable(t+`/`+r))throw new N(`EACCES`,`permission denied`,P(e))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.mkdir(e,t)}async rm(e,t){this.checkWrite(e);try{(await this.vfs.lstat(e)).type===`symlink`||await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.rm(e,t)}async rename(e,t){this.checkWrite(e),this.checkWrite(t),await this.resolveAndCheckWrite(e);let n=this.vfs.dirname(t),r=this.vfs.basename(t);try{let e=await this.vfs.realpath(n);if(!this.isWritable(e+`/`+r))throw new N(`EACCES`,`permission denied`,P(t))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.rename(e,t)}async copyFile(e,t){if(!this.isAllowed(e))throw new N(`ENOENT`,`no such file or directory`,P(e));this.checkWrite(t);let n=await this.resolveAndCheckRead(e),r=this.vfs.dirname(t),i=this.vfs.basename(t);try{let e=await this.vfs.realpath(r);if(!this.isWritable(e+`/`+i))throw new N(`EACCES`,`permission denied`,P(t))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}try{(await this.vfs.lstat(t)).type===`symlink`&&await this.resolveAndCheckWrite(t)}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.copyFile(n,t)}async symlink(e,t){this.checkWrite(t);let n=this.vfs.dirname(t),r=this.vfs.basename(t);try{let e=await this.vfs.realpath(n);if(!this.isWritable(e+`/`+r))throw new N(`EACCES`,`permission denied`,P(t))}catch(e){if(e instanceof N&&e.code===`EACCES`)throw e}return this.vfs.symlink(e,t)}async readlink(e){if(!this.isAllowedStrict(e))throw new N(`ENOENT`,`no such file or directory`,P(e));let t=await this.vfs.readlink(e),n;if(n=t.startsWith(`/`)?P(t):P(this.vfs.dirname(e)+`/`+t),!this.isAllowedStrict(n))throw new N(`ENOENT`,`no such file or directory`,P(e));return t}async lstat(e){if(!this.isAllowed(e))throw new N(`ENOENT`,`no such file or directory`,P(e));let t=P(e),n=this.vfs.dirname(t),r=this.vfs.basename(t),i;if(n===t)i=n;else try{i=await this.vfs.realpath(n)}catch{throw new N(`ENOENT`,`no such file or directory`,t)}let a=i===`/`?`/${r}`:`${i}/${r}`;if(!this.isAllowed(a))throw new N(`ENOENT`,`no such file or directory`,t);return this.vfs.lstat(a)}watch(e,t,n){if(!this.isAllowed(e))throw new N(`EACCES`,`permission denied`,P(e));let r=this.vfs.getWatcher();if(!r)throw new N(`EINVAL`,`no watcher configured`);return r.watch(P(e),t,n)}dirname(e){return this.vfs.dirname(e)}basename(e){return this.vfs.basename(e)}async dispose(){await this.vfs.dispose()}},J=a(`fs-watcher`),Y=0;function X(e,t){return t===`/`||e===t||e.startsWith(t+`/`)}var Z=class{registrations=new Map;watch(e,t,n){let r=`fsw-${++Y}`;return this.registrations.set(r,{id:r,basePath:e,filter:t,callback:n}),J.debug(`Watch registered`,{id:r,basePath:e}),()=>{this.registrations.delete(r),J.debug(`Watch unregistered`,{id:r})}}notify(e){if(e.length!==0)for(let[,t]of this.registrations){let n=e.filter(e=>X(e.path,t.basePath)&&t.filter(e.path));if(n.length>0)try{t.callback(n)}catch(e){J.error(`Watch callback error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}}}dispose(){this.registrations.clear(),J.debug(`All watchers disposed`)}get size(){return this.registrations.size}},Q=r({VirtualFS:()=>K});export{U as a,F as c,K as i,N as l,Z as n,I as o,q as r,P as s,Q as t};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/slicc-editor-BZFYYDy6.js","assets/preload-helper-D4M6sveU.js","assets/dist-D3v74401.js","assets/sql-wasm-CLEWdRiw.js","assets/chunk-zsgVPwQN.js","assets/__vite-browser-external-fVHSRdZ9.js","assets/pyodide-BIt8RVoH.js","assets/es-DlWKrNhH.js","assets/pako-djzWUVJp.js","assets/dist-Di8uHUFs.js","assets/provider-settings-DDuKtmwj.js","assets/provider-settings-CzImpUb7.js","assets/env-api-keys-qwjmVNjS.js","assets/simple-options-DZXt61Q2.js","assets/json-parse-JW3qhabb.js","assets/openai-Cn7eGqwa.js","assets/tray-follower-status-LqS6IS1u.js","assets/logger-B-No_qN_.js","assets/providers-BjLZ1m3N.js","assets/skills-
|
|
2
|
-
import{o as e,t}from"./chunk-zsgVPwQN.js";import{t as n}from"./logger-B-No_qN_.js";import{t as r}from"./preload-helper-D4M6sveU.js";import{c as i,f as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _,y as v}from"./tray-follower-status-LqS6IS1u.js";import{A as y,C as b,M as x,O as S,_ as C,b as w,c as T,h as E,j as D,k as ee,n as O,o as k,r as te,s as A,v as ne,w as re,x as ie,y as ae}from"./provider-settings-CzImpUb7.js";import{f as j,l as M,p as N,s as oe,u as P}from"./constants-Dqhmtsws.js";import{a as se,i as F,l as I,n as ce,o as le,r as ue,s as L}from"./fs-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/slicc-editor-BZFYYDy6.js","assets/preload-helper-D4M6sveU.js","assets/dist-D3v74401.js","assets/sql-wasm-CLEWdRiw.js","assets/chunk-zsgVPwQN.js","assets/__vite-browser-external-fVHSRdZ9.js","assets/pyodide-BIt8RVoH.js","assets/es-DlWKrNhH.js","assets/pako-djzWUVJp.js","assets/dist-Di8uHUFs.js","assets/provider-settings-DDuKtmwj.js","assets/provider-settings-CzImpUb7.js","assets/env-api-keys-qwjmVNjS.js","assets/simple-options-DZXt61Q2.js","assets/json-parse-JW3qhabb.js","assets/openai-Cn7eGqwa.js","assets/tray-follower-status-LqS6IS1u.js","assets/logger-B-No_qN_.js","assets/providers-BjLZ1m3N.js","assets/skills-CIHtxU5p.js","assets/constants-Dqhmtsws.js","assets/skills-D9PbVsND.js","assets/fs-D15vM8w-.js","assets/xterm-BmfB5bmM.css","assets/offscreen-client-BMlTH2Sh.js","assets/cdp-Dln7uDXr.js","assets/cost-command-DhUP8Ozj.js","assets/bsh-watchdog-UyxqvRBs.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e,t}from"./chunk-zsgVPwQN.js";import{t as n}from"./logger-B-No_qN_.js";import{t as r}from"./preload-helper-D4M6sveU.js";import{c as i,f as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _,y as v}from"./tray-follower-status-LqS6IS1u.js";import{A as y,C as b,M as x,O as S,_ as C,b as w,c as T,h as E,j as D,k as ee,n as O,o as k,r as te,s as A,v as ne,w as re,x as ie,y as ae}from"./provider-settings-CzImpUb7.js";import{f as j,l as M,p as N,s as oe,u as P}from"./constants-Dqhmtsws.js";import{a as se,i as F,l as I,n as ce,o as le,r as ue,s as L}from"./fs-D15vM8w-.js";import{d as de,n as fe}from"./skills-D9PbVsND.js";import{a as pe,c as me,d as he,i as ge,l as _e,n as ve,o as ye,r as be,s as xe,u as Se}from"./cdp-Dln7uDXr.js";import{_ as Ce,a as we,b as Te,c as Ee,d as De,f as Oe,g as ke,h as Ae,i as je,l as Me,m as Ne,n as Pe,o as Fe,p as Ie,r as Le,s as Re,t as ze,u as Be,v as Ve,x as R,y as He}from"./db-QbwB670D.js";import{a as Ue,i as We,n as Ge,o as z,r as Ke,s as qe}from"./cost-command-DhUP8Ozj.js";import{t as Je}from"./pako-djzWUVJp.js";import{t as Ye}from"./magick-wasm-zICxCuIf.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function Xe(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Ze=Xe();function Qe(e){Ze=e}var $e={exec:()=>null};function B(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(tt.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var et=(()=>{try{return!0}catch{return!1}})(),tt={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,`i`),blockquoteBeginRegex:e=>RegExp(`^ {0,${Math.min(3,e-1)}}>`)},nt=/^(?:[ \t]*(?:\n|$))+/,rt=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,it=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,at=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ot=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,st=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,ct=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,lt=B(ct).replace(/bull/g,st).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),ut=B(ct).replace(/bull/g,st).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),dt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ft=/^[^\n]+/,pt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,mt=B(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,pt).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),ht=B(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,st).getRegex(),gt=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,_t=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,vt=B(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,_t).replace(`tag`,gt).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),yt=B(dt).replace(`hr`,at).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,gt).getRegex(),bt={blockquote:B(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,yt).getRegex(),code:rt,def:mt,fences:it,heading:ot,hr:at,html:vt,lheading:lt,list:ht,newline:nt,paragraph:yt,table:$e,text:ft},xt=B(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,at).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,gt).getRegex(),St={...bt,lheading:ut,table:xt,paragraph:B(dt).replace(`hr`,at).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,xt).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,gt).getRegex()},Ct={...bt,html:B(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,_t).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:$e,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:B(dt).replace(`hr`,at).replace(`heading`,` *#{1,6} *[^
|
|
3
3
|
]`).replace(`lheading`,lt).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},wt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Tt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Et=/^( {2,}|\\)\n(?!\s*$)/,Dt=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Ot=/[\p{P}\p{S}]/u,kt=/[\s\p{P}\p{S}]/u,At=/[^\s\p{P}\p{S}]/u,jt=B(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,kt).getRegex(),Mt=/(?!~)[\p{P}\p{S}]/u,Nt=/(?!~)[\s\p{P}\p{S}]/u,Pt=/(?:[^\s\p{P}\p{S}]|~)/u,Ft=B(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,et?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),It=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Lt=B(It,`u`).replace(/punct/g,Ot).getRegex(),Rt=B(It,`u`).replace(/punct/g,Mt).getRegex(),zt=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Bt=B(zt,`gu`).replace(/notPunctSpace/g,At).replace(/punctSpace/g,kt).replace(/punct/g,Ot).getRegex(),Vt=B(zt,`gu`).replace(/notPunctSpace/g,Pt).replace(/punctSpace/g,Nt).replace(/punct/g,Mt).getRegex(),Ht=B(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,At).replace(/punctSpace/g,kt).replace(/punct/g,Ot).getRegex(),Ut=B(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,Ot).getRegex(),Wt=B(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,At).replace(/punctSpace/g,kt).replace(/punct/g,Ot).getRegex(),Gt=B(/\\(punct)/,`gu`).replace(/punct/g,Ot).getRegex(),Kt=B(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),qt=B(_t).replace(`(?:-->|$)`,`-->`).getRegex(),Jt=B(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,qt).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Yt=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Xt=B(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,Yt).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Zt=B(/^!?\[(label)\]\[(ref)\]/).replace(`label`,Yt).replace(`ref`,pt).getRegex(),Qt=B(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,pt).getRegex(),$t=B(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Zt).replace(`nolink`,Qt).getRegex(),en=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,tn={_backpedal:$e,anyPunctuation:Gt,autolink:Kt,blockSkip:Ft,br:Et,code:Tt,del:$e,delLDelim:$e,delRDelim:$e,emStrongLDelim:Lt,emStrongRDelimAst:Bt,emStrongRDelimUnd:Ht,escape:wt,link:Xt,nolink:Qt,punctuation:jt,reflink:Zt,reflinkSearch:$t,tag:Jt,text:Dt,url:$e},nn={...tn,link:B(/^!?\[(label)\]\((.*?)\)/).replace(`label`,Yt).getRegex(),reflink:B(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,Yt).getRegex()},rn={...tn,emStrongRDelimAst:Vt,emStrongLDelim:Rt,delLDelim:Ut,delRDelim:Wt,url:B(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,en).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:B(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,en).getRegex()},an={...rn,br:B(Et).replace(`{2,}`,`*`).getRegex(),text:B(rn.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},on={normal:bt,gfm:St,pedantic:Ct},sn={normal:tn,gfm:rn,breaks:an,pedantic:nn},cn={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},ln=e=>cn[e];function un(e,t){if(t){if(tt.escapeTest.test(e))return e.replace(tt.escapeReplace,ln)}else if(tt.escapeTestNoEncode.test(e))return e.replace(tt.escapeReplaceNoEncode,ln);return e}function dn(e){try{e=encodeURI(e).replace(tt.percentDecode,`%`)}catch{return null}return e}function fn(e,t){let n=e.replace(tt.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(tt.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``);for(;r<n.length;r++)n[r]=n[r].trim().replace(tt.slashPipe,`|`);return n}function pn(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function mn(e){let t=e.split(`
|
|
4
4
|
`),n=t.length-1;for(;n>=0&&!t[n].trim();)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
|
|
5
5
|
`)}function hn(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function gn(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function _n(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function vn(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
|
@@ -239,7 +239,7 @@ ${t.includes(`<slicc-editor`)?`<script src="/slicc-editor.js"><\/script>`:``}
|
|
|
239
239
|
${t.includes(`<slicc-diff`)?`<script src="/slicc-diff.js"><\/script>`:``}
|
|
240
240
|
<script src="/lucide-icons.js"><\/script>
|
|
241
241
|
</head>
|
|
242
|
-
<body class="sprinkle-inline">${t}</body></html>`;if(li)return mi(e,r,n);let i=document.createElement(`iframe`);i.setAttribute(`sandbox`,`allow-scripts allow-same-origin`),i.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,i.srcdoc=r,e.appendChild(i);let a=e=>{if(e.source!==i.contentWindow)return;let t=e.data;t?.type&&(t.type===`inline-sprinkle-lick`?n(t.action,t.data):t.type===`inline-sprinkle-height`&&(i.style.height=t.height+`px`))};return window.addEventListener(`message`,a),{dispose(){window.removeEventListener(`message`,a),i.remove()}}}function fi(e,t){let n=e.querySelectorAll(`pre > code.language-shtml`);if(n.length===0)return[];let r=[];for(let e of n){let n=e.parentElement,i=e.textContent??``,a=document.createElement(`div`);a.className=`msg__inline-sprinkle`,n.replaceWith(a),r.push(di(a,i,t))}return r}function pi(e){for(let t of e)try{t.dispose()}catch{}e.length=0}function mi(e,t,n){let r=document.createElement(`iframe`);r.src=chrome.runtime.getURL(`sprinkle-sandbox.html`),r.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,e.appendChild(r);let i=e=>{if(e.source!==r.contentWindow)return;let t=e.data;t?.type&&(t.type===`inline-sprinkle-lick`?n(t.action,t.data):t.type===`inline-sprinkle-height`&&(r.style.height=t.height+`px`))};return window.addEventListener(`message`,i),r.addEventListener(`load`,()=>{r.contentWindow?.postMessage({type:`inline-sprinkle-render`,srcdoc:t},`*`)},{once:!0}),{dispose(){window.removeEventListener(`message`,i),r.remove()}}}var hi=n(`tool-ui-renderer`),gi=typeof chrome<`u`&&!!chrome?.runtime?.id,_i=class{container;iframe=null;inlineSprinkle=null;messageHandler=null;requestId;nonce;constructor(e,t){this.container=e,this.requestId=t,this.nonce=crypto.randomUUID()}async render(e){gi?await this.renderInSandbox(e):this.renderWithInlineSprinkle(e)}async renderInSandbox(e){let t=document.createElement(`iframe`);t.src=chrome.runtime.getURL(`tool-ui-sandbox.html`),t.style.cssText=`width: 100%; border: none; min-height: 60px;`,this.iframe=t,await new Promise((e,n)=>{let r=setTimeout(()=>{hi.error(`Tool UI iframe load timed out`),t.remove(),this.iframe=null,n(Error(`tool-ui sandbox iframe load timed out`))},5e3);t.addEventListener(`load`,()=>{clearTimeout(r),e()},{once:!0}),t.addEventListener(`error`,()=>{clearTimeout(r),t.remove(),this.iframe=null,n(Error(`tool-ui sandbox iframe failed to load`))},{once:!0}),this.container.appendChild(t)}),this.messageHandler=e=>{if(e.source!==t.contentWindow)return;let n=e.data;if(n?.type){if(n.nonce!==this.nonce){hi.warn(`Tool UI message nonce mismatch`,{expected:this.nonce,received:n.nonce});return}n.type===`tool-ui-action`&&n.id===this.requestId?(hi.info(`Tool UI action received`,{id:n.id,action:n.action}),v.handleAction(n.id,{action:n.action,data:n.data})):n.type===`tool-ui-rendered`&&n.id===this.requestId?n.height&&this.iframe&&(this.iframe.style.height=`${Math.max(60,n.height)}px`):n.type===`tool-ui-resize`&&n.id===this.requestId&&n.height&&this.iframe&&(this.iframe.style.height=`${Math.max(60,n.height)}px`)}},window.addEventListener(`message`,this.messageHandler);let{collectThemeCSS:n}=await r(async()=>{let{collectThemeCSS:e}=await import(`./sprinkle-renderer-CJ4wOw20.js`);return{collectThemeCSS:e}},[]),i=n();t.contentWindow.postMessage({type:`tool-ui-render`,id:this.requestId,nonce:this.nonce,html:e,themeCSS:i},`*`)}renderWithInlineSprinkle(e){let t=document.createElement(`div`);t.className=`msg__inline-sprinkle`,this.container.appendChild(t),this.inlineSprinkle=di(t,e,(e,t)=>{hi.info(`Tool UI action (inline sprinkle)`,{id:this.requestId,action:e}),v.handleAction(this.requestId,{action:e,data:t})})}dispose(){this.messageHandler&&=(window.removeEventListener(`message`,this.messageHandler),null),this.iframe&&=(this.iframe.remove(),null),this.inlineSprinkle&&=(this.inlineSprinkle.dispose(),null)}},vi=new Map;function yi(e,t,n){let r=vi.get(t);r&&r.dispose();let i=new _i(e,t);return vi.set(t,i),i.render(n).catch(e=>{hi.error(`Failed to render tool UI`,{requestId:t,error:e.message})}),i}function bi(e){let t=vi.get(e);t&&(t.dispose(),vi.delete(e))}var xi=n(`chat-panel`);function Si(){return Date.now().toString(36)+Math.random().toString(36).slice(2,8)}var Ci={bash:`$`,browser:`B`,read_file:`R`,write_file:`W`,edit_file:`E`,javascript:`JS`,delegate_to_scoop:`D`,send_message:`M`,schedule_task:`T`,list_scoops:`LS`,list_tasks:`LT`,register_scoop:`RS`,update_global_memory:`GM`};function wi(e){return Ci[e]??`?`}function Ti(e){return e.role===`assistant`?Gr(e.content):Wr(e.content)}var Ei=class{container;messagesEl;messagesInner;inputArea;textarea;sendBtn;stopBtn;micBtn;voiceInput=null;voiceMode=!1;keydownListener=null;messages=[];agent=null;unsubscribe=null;isStreaming=!1;currentStreamId=null;sessionStore;sessionId;readOnly=!1;terminalOutputCallback=null;currentScoopName=null;autoScrollAttached=!0;lastScrollTop=0;jumpPill;onDeleteQueuedMessage=null;pendingDeltaText=``;streamingRafId=null;inlineSprinkles=new Map;onInlineSprinkleLick;modelSelectorEl;handoffsEl;pendingHandoffs=[];onAcceptPendingHandoff=null;onDismissPendingHandoff=null;onModelChange;constructor(e){this.container=e,this.sessionStore=new Zr,this.sessionId=`default`,this.render()}setAgent(e){this.unsubscribe?.(),this.agent=e,this.unsubscribe=e.onEvent(e=>this.handleAgentEvent(e))}onTerminalOutput(e){this.terminalOutputCallback=e}setDeleteQueuedMessageCallback(e){this.onDeleteQueuedMessage=e}async initSession(e){await this.sessionStore.init(),this.sessionId=e??`default`;let t=await this.sessionStore.load(this.sessionId);t&&t.messages.length>0&&(this.messages=t.messages.map(e=>({...e,isStreaming:!1})),this.renderMessages())}async clearSession(){this.messages=[],this.renderMessages(),await this.sessionStore.delete(this.sessionId)}async deleteSessionById(e){await this.sessionStore.delete(e)}async switchToContext(e,t,n){await this.persistSessionAsync(),this.setStreamingState(!1),this.currentStreamId=null,this.cancelPendingDelta(),this.sessionId=e,this.currentScoopName=n??null,this.setReadOnly(t);let r=await this.sessionStore.load(this.sessionId);r&&r.messages.length>0?this.messages=r.messages.map(e=>({...e,isStreaming:!1})):this.messages=[],this.renderMessages()}setReadOnly(e){this.readOnly=e,this.inputArea&&(this.inputArea.style.display=e?`none`:``)}async persistSessionAsync(){try{await this.sessionStore.saveMessages(this.sessionId,this.messages)}catch{}}setProcessing(e){e?this.setStreamingState(!0):this.setStreamingState(!1)}addSystemMessage(e){let t={id:Si(),role:`assistant`,content:e,timestamp:Date.now()};this.messages.push(t),this.appendMessageEl(t),this.persistSession()}addLickMessage(e,t,n){let r={id:e,role:`user`,content:t,timestamp:Date.now(),source:`lick`,channel:n};this.messages.push(r),this.appendMessageEl(r),this.persistSession()}getMessages(){return[...this.messages]}loadMessages(e){this.messages=e.map(e=>({...e,isStreaming:!1})),this.renderMessages(),this.persistSession(),this.renderModelSelector()}clear(){this.messages=[],this.renderMessages(),this.renderModelSelector()}setPendingHandoffs(e){this.pendingHandoffs=[...e],this.renderPendingHandoffs()}setPendingHandoffActions(e){this.onAcceptPendingHandoff=e.onAccept,this.onDismissPendingHandoff=e.onDismiss,this.renderPendingHandoffs()}addUserMessage(e){let t={id:Si(),role:`user`,content:e,timestamp:Date.now()};this.messages.push(t),this.appendMessageEl(t)}deleteQueuedMessage(e){let t=this.messages.findIndex(t=>t.id===e);if(t===-1)return;this.messages.splice(t,1);let n=this.messagesEl.querySelector(`[data-msg-id="${e}"]`);n&&n.remove(),this.persistSession(),this.onDeleteQueuedMessage?.(e)}render(){this.container.innerHTML=``,this.container.classList.add(`chat`),this.messagesEl=document.createElement(`div`),this.messagesEl.className=`chat__messages`,this.messagesInner=document.createElement(`div`),this.messagesInner.className=`chat__messages-inner`,this.messagesEl.appendChild(this.messagesInner),this.handoffsEl=document.createElement(`div`),this.handoffsEl.className=`chat__handoffs`,this.handoffsEl.hidden=!0,this.messagesEl.appendChild(this.handoffsEl),this.container.appendChild(this.messagesEl),this.renderPendingHandoffs(),this.messagesEl.addEventListener(`scroll`,()=>{let{scrollTop:e,scrollHeight:t,clientHeight:n}=this.messagesEl;t-e-n<=250?(this.autoScrollAttached=!0,this.hideJumpPill()):e<this.lastScrollTop&&(this.autoScrollAttached=!1),this.lastScrollTop=e},{passive:!0}),this.inputArea=document.createElement(`div`);let e=this.inputArea;e.className=`chat__input-area`;let t=document.createElement(`div`);t.className=`chat__input-area-inner`,this.textarea=document.createElement(`textarea`),this.textarea.className=`chat__textarea`,this.textarea.placeholder=`What shall we build?`,this.textarea.rows=1,this.sendBtn=document.createElement(`button`),this.sendBtn.className=`chat__send-btn`,this.sendBtn.innerHTML=`<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor"><path d="M10 1.25C5.167 1.25 1.25 5.167 1.25 10s3.917 8.75 8.75 8.75 8.75-3.918 8.75-8.75S14.833 1.25 10 1.25zm3.527 8.284a.75.75 0 0 1-1.06 0L10.75 7.82v6.172a.75.75 0 0 1-1.5 0V7.812L7.527 9.534a.75.75 0 1 1-1.06-1.06l2.998-2.998a.75.75 0 0 1 1.06-.001l3.002 2.998a.75.75 0 0 1 0 1.061z"/></svg>`,this.sendBtn.dataset.tooltip=`Send message`,this.sendBtn.dataset.tooltipPos=`top`,this.stopBtn=document.createElement(`button`),this.stopBtn.className=`chat__stop-btn`,this.stopBtn.innerHTML=`<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor"><path d="M13.75 4H6.25A2.25 2.25 0 0 0 4 6.25v7.5A2.25 2.25 0 0 0 6.25 16h7.5A2.25 2.25 0 0 0 16 13.75v-7.5A2.25 2.25 0 0 0 13.75 4z"/></svg>`,this.stopBtn.dataset.tooltip=`Stop generation`,this.stopBtn.style.display=`none`,this.micBtn=document.createElement(`button`),this.micBtn.className=`chat__mic-btn`;let n=`http://www.w3.org/2000/svg`,r=document.createElementNS(n,`svg`);r.setAttribute(`width`,`16`),r.setAttribute(`height`,`16`),r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`fill`,`none`),r.setAttribute(`stroke`,`currentColor`),r.setAttribute(`stroke-width`,`2`),r.setAttribute(`stroke-linecap`,`round`),r.setAttribute(`stroke-linejoin`,`round`);let i=document.createElementNS(n,`path`);i.setAttribute(`d`,`M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z`);let a=document.createElementNS(n,`path`);a.setAttribute(`d`,`M19 10v2a7 7 0 0 1-14 0v-2`);let o=document.createElementNS(n,`line`);o.setAttribute(`x1`,`12`),o.setAttribute(`y1`,`19`),o.setAttribute(`x2`,`12`),o.setAttribute(`y2`,`23`);let s=document.createElementNS(n,`line`);s.setAttribute(`x1`,`8`),s.setAttribute(`y1`,`23`),s.setAttribute(`x2`,`16`),s.setAttribute(`y2`,`23`),r.append(i,a,o,s),this.micBtn.appendChild(r),this.micBtn.dataset.tooltip=`Voice (Ctrl+Shift+V)`;let c=document.createElement(`div`);c.className=`chat__input-wrapper`,c.appendChild(this.textarea);let l=document.createElement(`div`);l.className=`chat__action-bar`;let u=document.createElement(`div`);u.className=`chat__action-bar-left`,u.appendChild(this.micBtn),l.appendChild(u),this.modelSelectorEl=document.createElement(`div`),this.modelSelectorEl.className=`chat__model-selector`,this.renderModelSelector(),l.appendChild(this.modelSelectorEl);let d=document.createElement(`div`);d.className=`chat__action-bar-right`,d.appendChild(this.sendBtn),d.appendChild(this.stopBtn),l.appendChild(d),c.appendChild(l),t.appendChild(c),e.appendChild(t),this.container.appendChild(e),this.jumpPill=document.createElement(`button`),this.jumpPill.className=`chat__jump-pill`,this.jumpPill.textContent=`↓ New activity`,this.jumpPill.addEventListener(`click`,()=>{this.autoScrollAttached=!0,this.hideJumpPill(),this.scrollToBottom(!0)}),this.container.appendChild(this.jumpPill),this.textarea.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),this.sendMessage())}),this.textarea.addEventListener(`input`,()=>{this.textarea.style.height=`auto`,this.textarea.style.height=Math.min(this.textarea.scrollHeight,120)+`px`}),this.sendBtn.addEventListener(`click`,()=>this.sendMessage()),this.stopBtn.addEventListener(`click`,()=>{this.agent?.stop();for(let e of this.messages)e.queued&&(e.queued=!1,this.updateMessageEl(e.id));this.setStreamingState(!1)}),this.voiceInput=new ti({onTranscript:(e,t)=>{this.textarea.value=e,this.textarea.style.height=`auto`,this.textarea.style.height=Math.min(this.textarea.scrollHeight,120)+`px`},onStateChange:e=>{e===`error`?(this.voiceMode=!1,this.micBtn.classList.remove(`chat__mic-btn--active`,`chat__mic-btn--listening`)):this.voiceMode?e===`listening`&&this.micBtn.classList.add(`chat__mic-btn--listening`):this.micBtn.classList.toggle(`chat__mic-btn--listening`,e===`listening`)},onError:e=>{xi.debug(`Voice input error`,{error:e}),!(this.voiceMode&&e.includes(`No speech detected`))&&this.addSystemMessage(e)},autoSend:!0,onAutoSend:e=>{this.textarea.value=e,this.sendMessage()},onAutoDisable:()=>{this.voiceMode=!1,this.micBtn.classList.remove(`chat__mic-btn--active`,`chat__mic-btn--listening`),this.addSystemMessage(`Voice mode disabled after 2 minutes of inactivity.`)},lang:ri()}),this.micBtn.addEventListener(`click`,()=>{this.toggleVoiceMode()}),this.keydownListener=e=>{e.shiftKey&&(e.ctrlKey||e.metaKey)&&e.key===`V`&&(e.preventDefault(),this.toggleVoiceMode())},document.addEventListener(`keydown`,this.keydownListener)}renderPendingHandoffs(){if(!this.handoffsEl)return;if(this.pendingHandoffs.length===0){this.handoffsEl.hidden=!0,this.handoffsEl.innerHTML=``;return}let e=this.pendingHandoffs.length===1?`1 pending handoff`:`${this.pendingHandoffs.length} pending handoffs`;this.handoffsEl.hidden=!1,this.handoffsEl.innerHTML=`
|
|
242
|
+
<body class="sprinkle-inline">${t}</body></html>`;if(li)return mi(e,r,n);let i=document.createElement(`iframe`);i.setAttribute(`sandbox`,`allow-scripts allow-same-origin`),i.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,i.srcdoc=r,e.appendChild(i);let a=e=>{if(e.source!==i.contentWindow)return;let t=e.data;t?.type&&(t.type===`inline-sprinkle-lick`?n(t.action,t.data):t.type===`inline-sprinkle-height`&&(i.style.height=t.height+`px`))};return window.addEventListener(`message`,a),{dispose(){window.removeEventListener(`message`,a),i.remove()}}}function fi(e,t){let n=e.querySelectorAll(`pre > code.language-shtml`);if(n.length===0)return[];let r=[];for(let e of n){let n=e.parentElement,i=e.textContent??``,a=document.createElement(`div`);a.className=`msg__inline-sprinkle`,n.replaceWith(a),r.push(di(a,i,t))}return r}function pi(e){for(let t of e)try{t.dispose()}catch{}e.length=0}function mi(e,t,n){let r=document.createElement(`iframe`);r.src=chrome.runtime.getURL(`sprinkle-sandbox.html`),r.style.cssText=`width:100%;border:none;overflow:hidden;display:block;`,e.appendChild(r);let i=e=>{if(e.source!==r.contentWindow)return;let t=e.data;t?.type&&(t.type===`inline-sprinkle-lick`?n(t.action,t.data):t.type===`inline-sprinkle-height`&&(r.style.height=t.height+`px`))};return window.addEventListener(`message`,i),r.addEventListener(`load`,()=>{r.contentWindow?.postMessage({type:`inline-sprinkle-render`,srcdoc:t},`*`)},{once:!0}),{dispose(){window.removeEventListener(`message`,i),r.remove()}}}var hi=n(`tool-ui-renderer`),gi=typeof chrome<`u`&&!!chrome?.runtime?.id,_i=class{container;iframe=null;inlineSprinkle=null;messageHandler=null;requestId;nonce;constructor(e,t){this.container=e,this.requestId=t,this.nonce=crypto.randomUUID()}async render(e){gi?await this.renderInSandbox(e):this.renderWithInlineSprinkle(e)}async renderInSandbox(e){let t=document.createElement(`iframe`);t.src=chrome.runtime.getURL(`tool-ui-sandbox.html`),t.style.cssText=`width: 100%; border: none; min-height: 60px;`,this.iframe=t,await new Promise((e,n)=>{let r=setTimeout(()=>{hi.error(`Tool UI iframe load timed out`),t.remove(),this.iframe=null,n(Error(`tool-ui sandbox iframe load timed out`))},5e3);t.addEventListener(`load`,()=>{clearTimeout(r),e()},{once:!0}),t.addEventListener(`error`,()=>{clearTimeout(r),t.remove(),this.iframe=null,n(Error(`tool-ui sandbox iframe failed to load`))},{once:!0}),this.container.appendChild(t)}),this.messageHandler=e=>{if(e.source!==t.contentWindow)return;let n=e.data;if(n?.type){if(n.nonce!==this.nonce){hi.warn(`Tool UI message nonce mismatch`,{expected:this.nonce,received:n.nonce});return}n.type===`tool-ui-action`&&n.id===this.requestId?(hi.info(`Tool UI action received`,{id:n.id,action:n.action}),v.handleAction(n.id,{action:n.action,data:n.data})):n.type===`tool-ui-rendered`&&n.id===this.requestId?n.height&&this.iframe&&(this.iframe.style.height=`${Math.max(60,n.height)}px`):n.type===`tool-ui-resize`&&n.id===this.requestId&&n.height&&this.iframe&&(this.iframe.style.height=`${Math.max(60,n.height)}px`)}},window.addEventListener(`message`,this.messageHandler);let{collectThemeCSS:n}=await r(async()=>{let{collectThemeCSS:e}=await import(`./sprinkle-renderer-DtPUK5jf.js`);return{collectThemeCSS:e}},[]),i=n();t.contentWindow.postMessage({type:`tool-ui-render`,id:this.requestId,nonce:this.nonce,html:e,themeCSS:i},`*`)}renderWithInlineSprinkle(e){let t=document.createElement(`div`);t.className=`msg__inline-sprinkle`,this.container.appendChild(t),this.inlineSprinkle=di(t,e,(e,t)=>{hi.info(`Tool UI action (inline sprinkle)`,{id:this.requestId,action:e}),v.handleAction(this.requestId,{action:e,data:t})})}dispose(){this.messageHandler&&=(window.removeEventListener(`message`,this.messageHandler),null),this.iframe&&=(this.iframe.remove(),null),this.inlineSprinkle&&=(this.inlineSprinkle.dispose(),null)}},vi=new Map;function yi(e,t,n){let r=vi.get(t);r&&r.dispose();let i=new _i(e,t);return vi.set(t,i),i.render(n).catch(e=>{hi.error(`Failed to render tool UI`,{requestId:t,error:e.message})}),i}function bi(e){let t=vi.get(e);t&&(t.dispose(),vi.delete(e))}var xi=n(`chat-panel`);function Si(){return Date.now().toString(36)+Math.random().toString(36).slice(2,8)}var Ci={bash:`$`,browser:`B`,read_file:`R`,write_file:`W`,edit_file:`E`,javascript:`JS`,delegate_to_scoop:`D`,send_message:`M`,schedule_task:`T`,list_scoops:`LS`,list_tasks:`LT`,register_scoop:`RS`,update_global_memory:`GM`};function wi(e){return Ci[e]??`?`}function Ti(e){return e.role===`assistant`?Gr(e.content):Wr(e.content)}var Ei=class{container;messagesEl;messagesInner;inputArea;textarea;sendBtn;stopBtn;micBtn;voiceInput=null;voiceMode=!1;keydownListener=null;messages=[];agent=null;unsubscribe=null;isStreaming=!1;currentStreamId=null;sessionStore;sessionId;readOnly=!1;terminalOutputCallback=null;currentScoopName=null;autoScrollAttached=!0;lastScrollTop=0;jumpPill;onDeleteQueuedMessage=null;pendingDeltaText=``;streamingRafId=null;inlineSprinkles=new Map;onInlineSprinkleLick;modelSelectorEl;handoffsEl;pendingHandoffs=[];onAcceptPendingHandoff=null;onDismissPendingHandoff=null;onModelChange;constructor(e){this.container=e,this.sessionStore=new Zr,this.sessionId=`default`,this.render()}setAgent(e){this.unsubscribe?.(),this.agent=e,this.unsubscribe=e.onEvent(e=>this.handleAgentEvent(e))}onTerminalOutput(e){this.terminalOutputCallback=e}setDeleteQueuedMessageCallback(e){this.onDeleteQueuedMessage=e}async initSession(e){await this.sessionStore.init(),this.sessionId=e??`default`;let t=await this.sessionStore.load(this.sessionId);t&&t.messages.length>0&&(this.messages=t.messages.map(e=>({...e,isStreaming:!1})),this.renderMessages())}async clearSession(){this.messages=[],this.renderMessages(),await this.sessionStore.delete(this.sessionId)}async deleteSessionById(e){await this.sessionStore.delete(e)}async switchToContext(e,t,n){await this.persistSessionAsync(),this.setStreamingState(!1),this.currentStreamId=null,this.cancelPendingDelta(),this.sessionId=e,this.currentScoopName=n??null,this.setReadOnly(t);let r=await this.sessionStore.load(this.sessionId);r&&r.messages.length>0?this.messages=r.messages.map(e=>({...e,isStreaming:!1})):this.messages=[],this.renderMessages()}setReadOnly(e){this.readOnly=e,this.inputArea&&(this.inputArea.style.display=e?`none`:``)}async persistSessionAsync(){try{await this.sessionStore.saveMessages(this.sessionId,this.messages)}catch{}}setProcessing(e){e?this.setStreamingState(!0):this.setStreamingState(!1)}addSystemMessage(e){let t={id:Si(),role:`assistant`,content:e,timestamp:Date.now()};this.messages.push(t),this.appendMessageEl(t),this.persistSession()}addLickMessage(e,t,n){let r={id:e,role:`user`,content:t,timestamp:Date.now(),source:`lick`,channel:n};this.messages.push(r),this.appendMessageEl(r),this.persistSession()}getMessages(){return[...this.messages]}loadMessages(e){this.messages=e.map(e=>({...e,isStreaming:!1})),this.renderMessages(),this.persistSession(),this.renderModelSelector()}clear(){this.messages=[],this.renderMessages(),this.renderModelSelector()}setPendingHandoffs(e){this.pendingHandoffs=[...e],this.renderPendingHandoffs()}setPendingHandoffActions(e){this.onAcceptPendingHandoff=e.onAccept,this.onDismissPendingHandoff=e.onDismiss,this.renderPendingHandoffs()}addUserMessage(e){let t={id:Si(),role:`user`,content:e,timestamp:Date.now()};this.messages.push(t),this.appendMessageEl(t)}deleteQueuedMessage(e){let t=this.messages.findIndex(t=>t.id===e);if(t===-1)return;this.messages.splice(t,1);let n=this.messagesEl.querySelector(`[data-msg-id="${e}"]`);n&&n.remove(),this.persistSession(),this.onDeleteQueuedMessage?.(e)}render(){this.container.innerHTML=``,this.container.classList.add(`chat`),this.messagesEl=document.createElement(`div`),this.messagesEl.className=`chat__messages`,this.messagesInner=document.createElement(`div`),this.messagesInner.className=`chat__messages-inner`,this.messagesEl.appendChild(this.messagesInner),this.handoffsEl=document.createElement(`div`),this.handoffsEl.className=`chat__handoffs`,this.handoffsEl.hidden=!0,this.messagesEl.appendChild(this.handoffsEl),this.container.appendChild(this.messagesEl),this.renderPendingHandoffs(),this.messagesEl.addEventListener(`scroll`,()=>{let{scrollTop:e,scrollHeight:t,clientHeight:n}=this.messagesEl;t-e-n<=250?(this.autoScrollAttached=!0,this.hideJumpPill()):e<this.lastScrollTop&&(this.autoScrollAttached=!1),this.lastScrollTop=e},{passive:!0}),this.inputArea=document.createElement(`div`);let e=this.inputArea;e.className=`chat__input-area`;let t=document.createElement(`div`);t.className=`chat__input-area-inner`,this.textarea=document.createElement(`textarea`),this.textarea.className=`chat__textarea`,this.textarea.placeholder=`What shall we build?`,this.textarea.rows=1,this.sendBtn=document.createElement(`button`),this.sendBtn.className=`chat__send-btn`,this.sendBtn.innerHTML=`<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor"><path d="M10 1.25C5.167 1.25 1.25 5.167 1.25 10s3.917 8.75 8.75 8.75 8.75-3.918 8.75-8.75S14.833 1.25 10 1.25zm3.527 8.284a.75.75 0 0 1-1.06 0L10.75 7.82v6.172a.75.75 0 0 1-1.5 0V7.812L7.527 9.534a.75.75 0 1 1-1.06-1.06l2.998-2.998a.75.75 0 0 1 1.06-.001l3.002 2.998a.75.75 0 0 1 0 1.061z"/></svg>`,this.sendBtn.dataset.tooltip=`Send message`,this.sendBtn.dataset.tooltipPos=`top`,this.stopBtn=document.createElement(`button`),this.stopBtn.className=`chat__stop-btn`,this.stopBtn.innerHTML=`<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor"><path d="M13.75 4H6.25A2.25 2.25 0 0 0 4 6.25v7.5A2.25 2.25 0 0 0 6.25 16h7.5A2.25 2.25 0 0 0 16 13.75v-7.5A2.25 2.25 0 0 0 13.75 4z"/></svg>`,this.stopBtn.dataset.tooltip=`Stop generation`,this.stopBtn.style.display=`none`,this.micBtn=document.createElement(`button`),this.micBtn.className=`chat__mic-btn`;let n=`http://www.w3.org/2000/svg`,r=document.createElementNS(n,`svg`);r.setAttribute(`width`,`16`),r.setAttribute(`height`,`16`),r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`fill`,`none`),r.setAttribute(`stroke`,`currentColor`),r.setAttribute(`stroke-width`,`2`),r.setAttribute(`stroke-linecap`,`round`),r.setAttribute(`stroke-linejoin`,`round`);let i=document.createElementNS(n,`path`);i.setAttribute(`d`,`M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z`);let a=document.createElementNS(n,`path`);a.setAttribute(`d`,`M19 10v2a7 7 0 0 1-14 0v-2`);let o=document.createElementNS(n,`line`);o.setAttribute(`x1`,`12`),o.setAttribute(`y1`,`19`),o.setAttribute(`x2`,`12`),o.setAttribute(`y2`,`23`);let s=document.createElementNS(n,`line`);s.setAttribute(`x1`,`8`),s.setAttribute(`y1`,`23`),s.setAttribute(`x2`,`16`),s.setAttribute(`y2`,`23`),r.append(i,a,o,s),this.micBtn.appendChild(r),this.micBtn.dataset.tooltip=`Voice (Ctrl+Shift+V)`;let c=document.createElement(`div`);c.className=`chat__input-wrapper`,c.appendChild(this.textarea);let l=document.createElement(`div`);l.className=`chat__action-bar`;let u=document.createElement(`div`);u.className=`chat__action-bar-left`,u.appendChild(this.micBtn),l.appendChild(u),this.modelSelectorEl=document.createElement(`div`),this.modelSelectorEl.className=`chat__model-selector`,this.renderModelSelector(),l.appendChild(this.modelSelectorEl);let d=document.createElement(`div`);d.className=`chat__action-bar-right`,d.appendChild(this.sendBtn),d.appendChild(this.stopBtn),l.appendChild(d),c.appendChild(l),t.appendChild(c),e.appendChild(t),this.container.appendChild(e),this.jumpPill=document.createElement(`button`),this.jumpPill.className=`chat__jump-pill`,this.jumpPill.textContent=`↓ New activity`,this.jumpPill.addEventListener(`click`,()=>{this.autoScrollAttached=!0,this.hideJumpPill(),this.scrollToBottom(!0)}),this.container.appendChild(this.jumpPill),this.textarea.addEventListener(`keydown`,e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),this.sendMessage())}),this.textarea.addEventListener(`input`,()=>{this.textarea.style.height=`auto`,this.textarea.style.height=Math.min(this.textarea.scrollHeight,120)+`px`}),this.sendBtn.addEventListener(`click`,()=>this.sendMessage()),this.stopBtn.addEventListener(`click`,()=>{this.agent?.stop();for(let e of this.messages)e.queued&&(e.queued=!1,this.updateMessageEl(e.id));this.setStreamingState(!1)}),this.voiceInput=new ti({onTranscript:(e,t)=>{this.textarea.value=e,this.textarea.style.height=`auto`,this.textarea.style.height=Math.min(this.textarea.scrollHeight,120)+`px`},onStateChange:e=>{e===`error`?(this.voiceMode=!1,this.micBtn.classList.remove(`chat__mic-btn--active`,`chat__mic-btn--listening`)):this.voiceMode?e===`listening`&&this.micBtn.classList.add(`chat__mic-btn--listening`):this.micBtn.classList.toggle(`chat__mic-btn--listening`,e===`listening`)},onError:e=>{xi.debug(`Voice input error`,{error:e}),!(this.voiceMode&&e.includes(`No speech detected`))&&this.addSystemMessage(e)},autoSend:!0,onAutoSend:e=>{this.textarea.value=e,this.sendMessage()},onAutoDisable:()=>{this.voiceMode=!1,this.micBtn.classList.remove(`chat__mic-btn--active`,`chat__mic-btn--listening`),this.addSystemMessage(`Voice mode disabled after 2 minutes of inactivity.`)},lang:ri()}),this.micBtn.addEventListener(`click`,()=>{this.toggleVoiceMode()}),this.keydownListener=e=>{e.shiftKey&&(e.ctrlKey||e.metaKey)&&e.key===`V`&&(e.preventDefault(),this.toggleVoiceMode())},document.addEventListener(`keydown`,this.keydownListener)}renderPendingHandoffs(){if(!this.handoffsEl)return;if(this.pendingHandoffs.length===0){this.handoffsEl.hidden=!0,this.handoffsEl.innerHTML=``;return}let e=this.pendingHandoffs.length===1?`1 pending handoff`:`${this.pendingHandoffs.length} pending handoffs`;this.handoffsEl.hidden=!1,this.handoffsEl.innerHTML=`
|
|
243
243
|
<div class="chat__handoffs-inner">
|
|
244
244
|
<div class="chat__handoffs-header">${jr(e)}</div>
|
|
245
245
|
${this.pendingHandoffs.map(e=>this.renderPendingHandoffCard(e)).join(``)}
|
|
@@ -254,7 +254,7 @@ ${t.includes(`<slicc-diff`)?`<script src="/slicc-diff.js"><\/script>`:``}
|
|
|
254
254
|
</div>
|
|
255
255
|
</section>
|
|
256
256
|
`}toggleVoiceMode(){this.voiceMode=!this.voiceMode,this.micBtn.classList.toggle(`chat__mic-btn--active`,this.voiceMode),this.voiceMode?this.voiceInput?.start():this.voiceInput?.stop()}sendMessage(){let e=this.textarea.value.trim();if(!e)return;this.autoScrollAttached=!0,this.hideJumpPill();let t=this.isStreaming,n={id:Si(),role:`user`,content:e,timestamp:Date.now(),queued:t||void 0};this.messages.push(n),this.appendMessageEl(n),this.persistSession(),this.textarea.value=``,this.textarea.style.height=`auto`,this.isStreaming||this.setStreamingState(!0),this.agent?.sendMessage(e,n.id)}handleAgentEvent(e){switch(xi.debug(`Agent event`,{type:e.type}),e.type){case`message_start`:this.handleMessageStart(e.messageId);break;case`content_delta`:this.handleContentDelta(e.messageId,e.text);break;case`content_done`:this.handleContentDone(e.messageId);break;case`tool_use_start`:this.handleToolUseStart(e.messageId,e.toolName,e.toolInput);break;case`tool_result`:this.handleToolResult(e.messageId,e.toolName,e.result,e.isError);break;case`tool_ui`:this.handleToolUI(e.messageId,e.toolName,e.requestId,e.html);break;case`tool_ui_done`:this.handleToolUIDone(e.messageId,e.requestId);break;case`turn_end`:this.handleTurnEnd(e.messageId);break;case`error`:this.handleError(e.error);break;case`screenshot`:break;case`terminal_output`:this.terminalOutputCallback?.(e.text);break}}handleMessageStart(e){this.setStreamingState(!0),this.currentStreamId=e;let t={id:e,role:`assistant`,content:``,timestamp:Date.now(),isStreaming:!0,toolCalls:[]};this.messages.push(t),this.appendMessageEl(t)}handleContentDelta(e,t){this.findMessage(e)&&(this.pendingDeltaText+=t,this.streamingRafId===null&&(this.streamingRafId=requestAnimationFrame(()=>this.flushPendingDelta())))}handleContentDone(e){if(this.pendingDeltaText&&this.currentStreamId===e){let t=this.findMessage(e);t&&(t.content+=this.pendingDeltaText)}this.cancelPendingDelta();let t=this.findMessage(e);t&&(t.isStreaming=!1,this.updateMessageEl(e))}handleToolUseStart(e,t,n){let r=this.findMessage(e);r&&(r.toolCalls||=[],r.toolCalls.push({id:Si(),name:t,input:n}),this.updateMessageEl(e))}handleToolResult(e,t,n,r){let i=this.findMessage(e);if(!i||!i.toolCalls)return;let a=[...i.toolCalls].reverse().find(e=>e.name===t&&e.result===void 0);if(a){let e=n.match(/<img:(data:image\/[^>]+)>/);a.result=n.replace(/<img:data:image\/[^>]+>/g,``).trim(),e&&(a._screenshotDataUrl=e[1]),a.isError=r}this.updateMessageEl(e)}handleToolUI(e,t,n,r,i=0){let a=this.findMessage(e);if(!a||!a.toolCalls){if(i<10){setTimeout(()=>this.handleToolUI(e,t,n,r,i+1),100);return}xi.warn(`handleToolUI: message or toolCalls not found after retries`,{messageId:e});return}let o=[...a.toolCalls].reverse().find(e=>e.name===t&&e.result===void 0);if(!o){xi.warn(`handleToolUI: no matching tool call found`,{messageId:e,toolName:t});return}o._toolUIRequestId=n;let s=this.messagesEl.querySelector(`[data-msg-id="${e}"]`);if(!s){if(i<10){setTimeout(()=>this.handleToolUI(e,t,n,r,i+1),100);return}xi.warn(`handleToolUI: wrapper element not found after retries`,{messageId:e});return}let c=[...s.querySelectorAll(`.tool-call`)].reverse().find(e=>e.querySelector(`.tool-call__name`)?.textContent===t);if(c){c instanceof HTMLDetailsElement&&(c.open=!0);let e=c.querySelector(`.tool-call__ui`);e||(e=document.createElement(`div`),e.className=`tool-call__ui`,c.appendChild(e)),yi(e,n,r)}else i<10?setTimeout(()=>this.handleToolUI(e,t,n,r,i+1),100):xi.warn(`handleToolUI: tool call element not found in DOM after retries`,{toolName:t})}handleToolUIDone(e,t){bi(t)}handleTurnEnd(e){this.setStreamingState(!1),this.currentStreamId=null,this.persistSession()}handleError(e){this.setStreamingState(!1),this.currentStreamId=null;let t=this.messages[this.messages.length-1];if(t?.role===`assistant`&&t.isStreaming)t.isStreaming=!1,t.content+=`\n\n**Error:** ${e}`,this.updateMessageEl(t.id);else{let t={id:Si(),role:`assistant`,content:`**Error:** ${e}`,timestamp:Date.now()};this.messages.push(t),this.appendMessageEl(t)}this.persistSession()}setStreamingState(e){this.isStreaming=e;try{this.renderModelSelector()}catch{}if(this.stopBtn.style.display=e?`flex`:`none`,this.sendBtn.style.display=e?`none`:`flex`,this.textarea.disabled=!1,e){this.voiceInput?.isListening()&&this.voiceInput.stop(),this.micBtn.classList.remove(`chat__mic-btn--listening`);let e=this.messages.find(e=>e.queued);e&&(e.queued=!1,this.updateMessageEl(e.id))}e||(this.voiceMode?(this.micBtn.classList.add(`chat__mic-btn--listening`),this.voiceInput?.start()):this.textarea.focus())}renderModelSelector(){let e=this.modelSelectorEl;if(!e)return;for(;e.firstChild;)e.removeChild(e.firstChild);let t=A(),n=C(),r=ne(),i=[];for(let e of t)for(let t of e.models)i.push({providerId:e.providerId,id:t.id,name:t.name,reasoning:t.reasoning});i.sort((e,t)=>e.reasoning===t.reasoning?e.name.localeCompare(t.name):e.reasoning?-1:1);let a=i.find(e=>e.id===n&&e.providerId===r)||i[0];if(!a)return;let o=this.isStreaming,s=document.createElement(`button`);if(s.className=`chat__model-btn chat__model-btn--compact`,o&&s.classList.add(`chat__model-btn--disabled`),s.textContent=a.name,!o){let e=document.createElement(`span`);e.className=`chat__model-chevron`,e.innerHTML=`<svg width="12" height="12" viewBox="0 0 16 16" fill="currentColor"><path d="M4.5 6l3.5 4 3.5-4z"/></svg>`,s.appendChild(e)}if(o)e.appendChild(s);else{let t=!1,a=document.createElement(`div`);a.className=`chat__model-menu`;let o=()=>{for(a.style.display=t?`block`:`none`;a.firstChild;)a.removeChild(a.firstChild);if(t)for(let e of i){let i=document.createElement(`div`);i.className=`chat__model-menu-item`;let o=e.id===n&&e.providerId===r;o&&i.classList.add(`chat__model-menu-item--active`);let s=document.createElement(`span`);if(s.textContent=e.name,i.appendChild(s),o){let e=document.createElement(`span`);e.className=`chat__model-check`,e.innerHTML=`<svg width="14" height="14" viewBox="0 0 16 16" fill="currentColor"><path d="M6.5 12.5l-4-4 1.4-1.4 2.6 2.6 5.6-5.6 1.4 1.4z"/></svg>`,i.appendChild(e)}i.addEventListener(`click`,()=>{let n=`${e.providerId}:${e.id}`;b(n),this.onModelChange?.(n),t=!1,this.renderModelSelector()}),a.appendChild(i)}};s.addEventListener(`click`,e=>{e.stopPropagation(),t=!t,o()}),document.addEventListener(`click`,()=>{t=!1,o()},{once:!0}),e.appendChild(s),e.appendChild(a),o()}}refreshModelSelector(){this.renderModelSelector()}findMessage(e){return this.messages.find(t=>t.id===e)}flushPendingDelta(){if(this.streamingRafId=null,!this.pendingDeltaText||!this.currentStreamId)return;let e=this.findMessage(this.currentStreamId);if(!e){this.pendingDeltaText=``;return}e.content+=this.pendingDeltaText,this.pendingDeltaText=``,this.updateStreamingContent(this.currentStreamId)}cancelPendingDelta(){this.streamingRafId!==null&&(cancelAnimationFrame(this.streamingRafId),this.streamingRafId=null),this.pendingDeltaText=``}updateStreamingContent(e){let t=this.findMessage(e);if(!t)return;let n=this.messagesEl.querySelector(`[data-msg-id="${e}"]`);if(!n)return;let r=n.querySelector(`.msg__content`);if(r){if(r.innerHTML=Ti(t),t.isStreaming){let e=document.createElement(`span`);e.className=`streaming-cursor`,r.appendChild(e)}}else if(t.content.trim().length>0){this.updateMessageEl(e);return}this.scrollToBottom()}renderMessages(){this.disposeAllInlineSprinkles(),this.messagesInner.innerHTML=``;let e=null,t=0,n=-1;for(let e=this.messages.length-1;e>=0;e--)if(this.messages[e].role===`assistant`){n=e;break}for(let r=0;r<this.messages.length;r++){let i=this.messages[r],a=this.shouldShowLabel(i,e,t),o=this.createMessageEl(i,a,r===n);this.messagesInner.appendChild(o),e=i.role,t=i.timestamp}this.autoScrollAttached=!0,this.hideJumpPill(),this.scrollToBottom(!0)}appendMessageEl(e){let t=this.messagesInner.querySelector(`.msg__feedback`);t&&t.remove();let n=this.messages.length>=2?this.messages[this.messages.length-2]:null,r=this.shouldShowLabel(e,n?.role??null,n?.timestamp??0),i=e.role===`assistant`,a=this.createMessageEl(e,r,i);this.messagesInner.appendChild(a),this.scrollToBottom()}shouldShowLabel(e,t,n){return e.source===`lick`||e.channel===`webhook`||e.channel===`cron`||e.role!==t||e.timestamp-n>12e4}updateMessageEl(e){let t=this.findMessage(e);if(!t)return;let n=this.messagesEl.querySelector(`[data-msg-id="${e}"]`);if(n){this.disposeInlineSprinklesForMessage(e);let r=this.messages.indexOf(t),i=r>0?this.messages[r-1]:null,a=this.shouldShowLabel(t,i?.role??null,i?.timestamp??0),o=!1;if(t.role===`assistant`){let e=-1;for(let t=this.messages.length-1;t>=0;t--)if(this.messages[t].role===`assistant`){e=t;break}o=r===e}let s=this.createMessageEl(t,a,o);n.replaceWith(s)}this.scrollToBottom()}createMessageEl(e,t=!0,n=!1){if(e.source===`lick`||e.channel===`webhook`||e.channel===`cron`||e.channel===`fswatch`){let t=document.createElement(`div`);return t.className=`msg-group`,t.setAttribute(`data-msg-id`,e.id),t.appendChild(this.createLickEl(e)),t}let r=document.createElement(`div`);r.className=`msg-group${t?``:` msg-group--continuation`}`,r.setAttribute(`data-msg-id`,e.id);let i=document.createElement(`div`);if(i.className=`msg msg--${e.role}${e.queued?` msg--queued`:``}`,t){let t,n,r=this.currentScoopName!==null;e.role===`user`?e.source===`delegation`||e.channel===`delegation`?(t=`S`,n=`sliccy`):(t=`U`,n=`You`):r?(t=(this.currentScoopName||`S`).charAt(0).toUpperCase(),n=`@${this.currentScoopName}`):e.source&&e.source!==`cone`?(t=e.source.charAt(0).toUpperCase(),n=e.source):(t=`S`,n=`sliccy`);let a=document.createElement(`div`);a.className=`msg__role`;let o=document.createElement(`span`);if(o.className=`msg__icon`,o.textContent=t,a.appendChild(o),a.appendChild(document.createTextNode(` ${n}`)),e.queued){let t=document.createElement(`span`);t.className=`msg__queued-badge`,t.textContent=`queued`,a.appendChild(t);let n=document.createElement(`button`);n.className=`msg__queued-delete`,n.textContent=`×`,n.title=`Remove queued message`,n.addEventListener(`click`,t=>{t.stopPropagation(),this.deleteQueuedMessage(e.id)}),a.appendChild(n)}i.appendChild(a)}let a=(e.source===`lick`||e.channel===`webhook`||e.channel===`cron`||e.channel===`fswatch`)&&this.sessionId===`session-cone`,o=e.source&&e.source!==`cone`&&e.source!==`lick`&&e.role===`assistant`&&this.sessionId===`session-cone`;if(a||o){let t=document.createElement(`details`);t.className=`msg__collapsible`;let n=document.createElement(`summary`);n.className=`msg__summary`,n.textContent=e.content.slice(0,60).replace(/\n/g,` `)+(e.content.length>60?`...`:``),t.appendChild(n);let r=document.createElement(`div`);r.className=`msg__content`,r.innerHTML=Ti(e),e.isStreaming||this.hydrateInlineSprinklesInEl(r,e.id),t.appendChild(r),i.appendChild(t)}else{let t=document.createElement(`div`);if(t.className=`msg__content`,t.innerHTML=Ti(e),e.isStreaming){let e=document.createElement(`span`);e.className=`streaming-cursor`,t.appendChild(e)}else this.hydrateInlineSprinklesInEl(t,e.id);i.appendChild(t)}let s=e.content.trim().length>0;if(s&&r.appendChild(i),e.toolCalls)for(let t of e.toolCalls)r.appendChild(this.createToolCallEl(t));return e.role===`assistant`&&!e.isStreaming&&!e.queued&&s&&n&&r.appendChild(this.createFeedbackRow()),r}createFeedbackRow(){let e=document.createElement(`div`);e.className=`msg__feedback`;let t=document.createElement(`button`);return t.className=`msg__feedback-btn`,t.dataset.tooltip=`Copy chat`,t.setAttribute(`aria-label`,`Copy chat`),t.innerHTML=`<svg width="16" height="16" viewBox="0 0 20 20" fill="currentColor"><path d="m11.75,18h-7.5c-1.24,0-2.25-1.01-2.25-2.25v-7.5c0-1.24,1.01-2.25,2.25-2.25.41,0,.75.34.75.75s-.34.75-.75.75c-.41,0-.75.34-.75.75v7.5c0,.41.34.75.75.75h7.5c.41,0,.75-.34.75-.75,0-.41.34-.75.75-.75s.75.34.75.75c0,1.24-1.01,2.25-2.25,2.25Z"/><path d="m6.75,5c-.41,0-.75-.34-.75-.75,0-1.24,1.01-2.25,2.25-2.25.41,0,.75.34.75.75s-.34.75-.75.75c-.41,0-.75.34-.75.75,0,.41-.34.75-.75.75Z"/><path d="m13,3.5h-2c-.41,0-.75-.34-.75-.75s.34-.75.75-.75h2c.41,0,.75.34.75.75s-.34.75-.75.75Z"/><path d="m13,14h-2c-.41,0-.75-.34-.75-.75s.34-.75.75-.75h2c.41,0,.75.34.75.75s-.34.75-.75.75Z"/><path d="m15.75,14c-.41,0-.75-.34-.75-.75s.34-.75.75-.75c.41,0,.75-.34.75-.75,0-.41.34-.75.75-.75s.75.34.75.75c0,1.24-1.01,2.25-2.25,2.25Z"/><path d="m17.25,5c-.41,0-.75-.34-.75-.75,0-.41-.34-.75-.75-.75-.41,0-.75-.34-.75-.75s.34-.75.75-.75c1.24,0,2.25,1.01,2.25,2.25,0,.41-.34.75-.75.75Z"/><path d="m17.25,9.75c-.41,0-.75-.34-.75-.75v-2c0-.41.34-.75.75-.75s.75.34.75.75v2c0,.41-.34.75-.75.75Z"/><path d="m6.75,9.75c-.41,0-.75-.34-.75-.75v-2c0-.41.34-.75.75-.75s.75.34.75.75v2c0,.41-.34.75-.75.75Z"/><path d="m8.25,14c-1.24,0-2.25-1.01-2.25-2.25,0-.41.34-.75.75-.75s.75.34.75.75c0,.41.34.75.75.75.41,0,.75.34.75.75s-.34.75-.75.75Z"/></svg>`,t.addEventListener(`click`,async()=>{let e=this.getMessages(),n=``;for(let t of e){let e=t.role===`user`?`User`:`Assistant`;if(n+=`## ${e}\n${t.content}\n\n`,t.toolCalls)for(let e of t.toolCalls)n+=`### Tool: ${e.name}\nInput: ${JSON.stringify(e.input,null,2)}\nResult: ${e.result??``}\n\n`}await navigator.clipboard.writeText(n),t.style.color=`var(--s2-positive)`,setTimeout(()=>{t.style.color=``},1500)}),e.appendChild(t),e}createLickEl(e){let t=document.createElement(`details`);t.className=`lick`;let n=e.channel===`webhook`?`Webhook`:e.channel===`cron`?`Cron`:e.channel===`fswatch`?`File Watch`:`Event`,r=document.createElement(`summary`);r.className=`lick__header`,r.innerHTML=`<span class="lick__icon">E</span> <span class="lick__type">${n}</span>`;let i=document.createElement(`span`);i.className=`lick__preview`;let a=e.content.replace(/\[Webhook Event:.*?\]\n```json\n?/s,``).slice(0,50);i.textContent=a.replace(/\n/g,` `)+(a.length>=50?`...`:``),r.appendChild(i),t.appendChild(r);let o=document.createElement(`div`);return o.className=`lick__details`,o.innerHTML=Wr(e.content),t.appendChild(o),t}createToolCallEl(e){wi(e.name);let t=document.createElement(`details`);t.className=`tool-call`;let n=document.createElement(`summary`);if(n.className=`tool-call__header`,n.innerHTML=`<span class="tool-call__icon"><svg width="10" height="10" viewBox="0 0 10 10" fill="currentColor"><path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg></span> <span class="tool-call__name">${jr(e.name)}</span>`,e.input!==void 0){let t=document.createElement(`span`);t.className=`tool-call__preview`;let r=typeof e.input==`string`?e.input:JSON.stringify(e.input);t.textContent=r.slice(0,40)+(r.length>40?`...`:``),n.appendChild(t)}let r=document.createElement(`span`);e.result===void 0?r.className=`tool-call__status tool-call__status--running`:e.isError?(r.className=`tool-call__status tool-call__status--error`,r.textContent=`failed`):(r.className=`tool-call__status tool-call__status--success`,r.textContent=`✓`),n.appendChild(r),t.appendChild(n);let i=document.createElement(`div`);if(i.className=`tool-call__details`,e.input!==void 0){let t=document.createElement(`div`);t.className=`tool-call__input`;let n=document.createElement(`div`);n.className=`tool-call__label`,n.textContent=`Input:`,t.appendChild(n);let r=document.createElement(`pre`);r.innerHTML=Kr(e.input),t.appendChild(r),i.appendChild(t)}if(e.result!==void 0){let t=document.createElement(`div`);t.className=`tool-call__result${e.isError?` tool-call__result--error`:``}`;let n=document.createElement(`div`);n.className=`tool-call__label`,n.textContent=e.isError?`Error:`:`Result:`,t.appendChild(n);let r=document.createElement(`pre`);r.textContent=e.result,t.appendChild(r),i.appendChild(t)}let a=e._screenshotDataUrl;if(a){let e=document.createElement(`img`);e.src=a,e.className=`tool-call__screenshot`,e.title=`Click to view full size`,e.addEventListener(`click`,e=>{e.stopPropagation();let t=window.open(`about:blank`);if(t){let e=t.document.createElement(`img`);e.src=a,t.document.title=`Screenshot`,t.document.body.style.margin=`0`,t.document.body.style.background=document.documentElement.classList.contains(`theme-light`)?`#f0f0f0`:`#141414`,t.document.body.appendChild(e)}}),i.appendChild(e)}return t.appendChild(i),t}scrollToBottom(e=!1){if(!e&&!this.autoScrollAttached){this.showJumpPill();return}requestAnimationFrame(()=>{this.messagesEl.scrollTop=this.messagesEl.scrollHeight,this.lastScrollTop=this.messagesEl.scrollTop})}showJumpPill(){this.jumpPill.classList.add(`chat__jump-pill--visible`)}hideJumpPill(){this.jumpPill.classList.remove(`chat__jump-pill--visible`)}persistSession(){this.sessionStore.saveMessages(this.sessionId,this.messages).catch(()=>{})}disposeInlineSprinklesForMessage(e){let t=this.inlineSprinkles.get(e);t&&(pi(t),this.inlineSprinkles.delete(e))}disposeAllInlineSprinkles(){for(let[,e]of this.inlineSprinkles)pi(e);this.inlineSprinkles.clear()}hydrateInlineSprinklesInEl(e,t){let n=fi(e,(e,t)=>this.onInlineSprinkleLick?.(e,t));n.length&&this.inlineSprinkles.set(t,n)}dispose(){this.cancelPendingDelta(),this.disposeAllInlineSprinkles(),this.unsubscribe?.(),this.voiceInput?.destroy(),this.keydownListener&&=(document.removeEventListener(`keydown`,this.keydownListener),null),this.container.innerHTML=``}},Di=class{container;terminalViewEl;previewViewEl;previewEmptyEl;previewBtn;shell=null;activeView=`terminal`;onClearTerminal;constructor(e,t={}){this.container=e,this.onClearTerminal=t.onClearTerminal??null,this.render()}async mountShell(e){this.shell?.setPreviewStateListener(null),this.shell=e;let t=document.createElement(`div`);t.className=`terminal-panel__mount`,this.terminalViewEl.appendChild(t),await e.mount(t);let n=t.querySelector(`.terminal-panel__terminal-host`),r=t.querySelector(`.terminal-panel__preview`);if(!n||!r)throw Error(`terminal mount did not create expected hosts`);this.terminalViewEl.replaceChildren(n),this.previewViewEl.replaceChildren(this.previewEmptyEl),this.previewViewEl.appendChild(r),e.setPreviewStateListener(e=>this.handlePreviewStateChange(e))}clearTerminal(){this.shell?.clearTerminal()}async runCommand(e){return this.shell?(/^\s*imgcat(?:\s|$)/.test(e)||this.setActiveView(`terminal`),this.shell.executeCommandInTerminal(e)):{stdout:``,stderr:`terminal is unavailable
|
|
257
|
-
`,exitCode:1}}refit(){this.shell?.refit()}getBodyElement(){return this.container}render(){this.container.innerHTML=``,this.container.classList.add(`terminal-panel`);let e=document.createElement(`div`);e.className=`file-browser__header`;let t=document.createElement(`span`);if(t.className=`file-browser__header-title`,t.textContent=`Terminal`,e.appendChild(t),this.onClearTerminal){let t=document.createElement(`button`);t.className=`file-browser__header-btn`,t.dataset.tooltip=`Clear Terminal`,t.setAttribute(`aria-label`,`Clear Terminal`),t.innerHTML=`<svg width="14" height="14" viewBox="0 0 20 20" fill="none"><path d="m8.249,15.021c-.4,0-.733-.317-.748-.72l-.25-6.5c-.017-.414.307-.763.72-.778.01-.001.021-.001.03-.001.4,0,.733.317.748.72l.25,6.5c.017.414-.307.763-.72.778-.01.001-.021.001-.03.001Z" fill="currentColor"/><path d="m11.751,15.021c-.01,0-.02,0-.03-.001-.413-.016-.736-.364-.72-.778l.25-6.5c.015-.403.348-.72.748-.72.01,0,.02,0,.03.001.413.016.736.364.72.778l-.25,6.5c-.015.403-.348.72-.748.72Z" fill="currentColor"/><path d="m17,4h-3.5v-.75c0-1.24-1.01-2.25-2.25-2.25h-2.5c-1.24,0-2.25,1.01-2.25,2.25v.75h-3.5c-.414,0-.75.336-.75.75s.336.75.75.75h.52l.422,10.342c.048,1.21,1.036,2.158,2.248,2.158h7.619c1.212,0,2.2-.948,2.248-2.158l.422-10.342h.52c.414,0,.75-.336.75-.75s-.336-.75-.75-.75Zm-9-.75c0-.413.337-.75.75-.75h2.5c.413,0,.75.337.75.75v.75h-4v-.75Zm6.56,12.531c-.017.403-.346.719-.75.719h-7.619c-.404,0-.733-.316-.75-.719l-.42-10.281h9.959l-.42,10.281Z" fill="currentColor"/></svg>`,t.addEventListener(`click`,()=>this.onClearTerminal()),e.appendChild(t)}this.previewBtn=document.createElement(`button`),this.previewBtn.className=`file-browser__header-btn`,this.previewBtn.setAttribute(`aria-label`,`Toggle preview`),this.previewBtn.dataset.tooltip=`Preview`,this.previewBtn.disabled=!0;let n=`http://www.w3.org/2000/svg`,r=document.createElementNS(n,`svg`);r.setAttribute(`width`,`16`),r.setAttribute(`height`,`16`),r.setAttribute(`viewBox`,`0 0 20 20`),r.setAttribute(`fill`,`none`),r.setAttribute(`stroke`,`currentColor`),r.setAttribute(`stroke-width`,`1.5`),r.setAttribute(`stroke-linecap`,`round`),r.setAttribute(`stroke-linejoin`,`round`);let i=document.createElementNS(n,`path`);i.setAttribute(`d`,`M2 10s3-6 8-6 8 6 8 6-3 6-8 6-8-6-8-6z`),r.appendChild(i);let a=document.createElementNS(n,`circle`);a.setAttribute(`cx`,`10`),a.setAttribute(`cy`,`10`),a.setAttribute(`r`,`2.5`),r.appendChild(a),this.previewBtn.appendChild(r),this.previewBtn.addEventListener(`click`,()=>{this.previewBtn.disabled||this.setActiveView(this.activeView===`preview`?`terminal`:`preview`)}),e.appendChild(this.previewBtn),this.container.appendChild(e),this.terminalViewEl=document.createElement(`div`),this.terminalViewEl.className=`terminal-panel__view`,this.container.appendChild(this.terminalViewEl),this.previewViewEl=document.createElement(`div`),this.previewViewEl.className=`terminal-panel__view`,this.container.appendChild(this.previewViewEl),this.previewEmptyEl=document.createElement(`div`),this.previewEmptyEl.className=`terminal-panel__empty-state`,this.previewEmptyEl.textContent=`Run imgcat to preview media here.`,this.previewViewEl.appendChild(this.previewEmptyEl),this.setActiveView(`terminal`)}dispose(){this.shell?.setPreviewStateListener(null),this.shell?.dispose(),this.container.innerHTML=``}setActiveView(e){this.activeView=e,this.previewBtn.classList.toggle(`file-browser__header-btn--active`,e===`preview`),this.terminalViewEl.style.display=e===`terminal`?`flex`:`none`,this.previewViewEl.style.display=e===`preview`?`flex`:`none`,e===`terminal`&&this.refit()}handlePreviewStateChange(e){this.previewBtn.disabled=!e,this.previewEmptyEl.style.display=e?`none`:`flex`,e?this.setActiveView(`preview`):this.activeView===`preview`&&this.setActiveView(`terminal`)}};function Oi(e){return e<1024?e+` B`:e<1024*1024?(e/1024).toFixed(1)+`K`:e<1024*1024*1024?(e/(1024*1024)).toFixed(1)+`M`:(e/(1024*1024*1024)).toFixed(1)+`G`}function ki(e){let t=`http://www.w3.org/2000/svg`,n=document.createElementNS(t,`svg`);n.setAttribute(`width`,`14`),n.setAttribute(`height`,`14`),n.setAttribute(`viewBox`,`0 0 20 20`),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke`,`currentColor`),n.setAttribute(`stroke-width`,`1.5`),n.setAttribute(`stroke-linecap`,`round`),n.setAttribute(`stroke-linejoin`,`round`),n.style.flexShrink=`0`;for(let r of e){let e=document.createElementNS(t,`path`);e.setAttribute(`d`,r),n.appendChild(e)}return n}function Ai(){return ki([`M2 6V5a1 1 0 0 1 1-1h4l2 2h8a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V6z`])}function ji(){return ki([`M6 2h5l5 5v9a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z`,`M11 2v5h5`])}function Mi(e){let t=`http://www.w3.org/2000/svg`,n=document.createElementNS(t,`svg`);n.setAttribute(`width`,`10`),n.setAttribute(`height`,`10`),n.setAttribute(`viewBox`,`0 0 20 20`),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke`,`currentColor`),n.setAttribute(`stroke-width`,`2`),n.setAttribute(`stroke-linecap`,`round`),n.setAttribute(`stroke-linejoin`,`round`),n.style.flexShrink=`0`,n.style.transition=`transform 130ms ease`,e&&(n.style.transform=`rotate(90deg)`);let r=document.createElementNS(t,`path`);return r.setAttribute(`d`,`M7 5l5 5-5 5`),n.appendChild(r),n}function Ni(e){return`'${e.replace(/'/g,`'\\''`)}'`}function Pi(e){return`${f(e)?`imgcat`:`cat`} ${Ni(e)}`}var Fi=class{container;bodyEl;fs=null;expandedDirs=new Set([`/`]);refreshTimer=null;onRunCommand;selectedPath=null;keydownHandler=null;constructor(e,t={}){this.container=e,this.onRunCommand=t.onRunCommand??null,this.render()}setFs(e){this.fs=e,this.refresh(),this.refreshTimer=setInterval(()=>this.refresh(),3e3)}async refresh(){if(!this.fs)return;let e=document.createElement(`div`);try{await this.renderDir(`/`,e,0)}catch(e){console.warn(`[FileBrowser] Refresh failed:`,e instanceof Error?e.message:String(e));return}if(e.innerHTML===this.bodyEl.innerHTML){this.applySelection();return}let t=this.container.contains(document.activeElement);for(;this.bodyEl.firstChild;)this.bodyEl.removeChild(this.bodyEl.firstChild);for(;e.firstChild;)this.bodyEl.appendChild(e.firstChild);this.applySelection(),t&&this.selectedPath&&this.bodyEl.querySelector(`.file-browser__item--selected`)?.focus()}render(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.container.classList.add(`file-browser`);let e=document.createElement(`div`);e.className=`file-browser__header`;let t=document.createElement(`span`);t.className=`file-browser__header-title`,t.textContent=`Files`,e.appendChild(t),this.container.appendChild(e),this.bodyEl=document.createElement(`div`),this.bodyEl.className=`file-browser__body`,this.container.appendChild(this.bodyEl),this.setupKeydown()}async renderDir(e,t,n){if(!this.fs)return;let r;try{r=await this.fs.readDir(e)}catch(t){console.warn(`[FileBrowser] readDir failed:`,e,t instanceof Error?t.message:String(t));return}let i=r.filter(e=>e.type===`directory`).sort((e,t)=>e.name.localeCompare(t.name)),a=r.filter(e=>e.type===`file`).sort((e,t)=>e.name.localeCompare(t.name));for(let r of[...i,...a]){let i=e===`/`?`/`+r.name:e+`/`+r.name,a=document.createElement(`div`);if(a.className=`file-browser__item`,a.style.paddingLeft=12+n*16+`px`,a.dataset.path=r.type===`directory`&&!i.endsWith(`/`)?i+`/`:i,r.type===`directory`){let e=this.expandedDirs.has(i),o=document.createElement(`span`);o.className=`file-browser__arrow`,o.appendChild(Mi(e)),a.appendChild(o);let s=document.createElement(`span`);s.className=`file-browser__icon`,s.appendChild(Ai()),a.appendChild(s);let c=document.createElement(`span`);c.className=`file-browser__name`,c.textContent=r.name,a.appendChild(c);let l=document.createElement(`button`);l.className=`file-browser__action-btn`,l.style.marginLeft=`auto`,l.textContent=`ZIP`,l.title=`Download as ZIP`,l.addEventListener(`click`,e=>{e.stopPropagation(),this.downloadDirAsZip(i,r.name)}),a.appendChild(l),a.style.cursor=`pointer`,a.addEventListener(`click`,()=>{this.selectPath(i,`directory`),this.expandedDirs.has(i)?this.expandedDirs.delete(i):this.expandedDirs.add(i),this.refresh()}),t.appendChild(a),e&&await this.renderDir(i,t,n+1)}else{let e=document.createElement(`span`);e.className=`file-browser__arrow`,a.appendChild(e);let n=document.createElement(`span`);n.className=`file-browser__icon`,n.appendChild(ji()),a.appendChild(n);let o=document.createElement(`span`);o.className=`file-browser__name`,o.textContent=r.name,a.appendChild(o);try{let e=await this.fs.stat(i),t=document.createElement(`span`);t.className=`file-browser__size`,t.textContent=Oi(e.size),a.appendChild(t)}catch(e){console.warn(`[FileBrowser] stat failed:`,i,e instanceof Error?e.message:String(e))}let s=document.createElement(`button`);s.className=`file-browser__action-btn`,s.style.marginLeft=`8px`,s.textContent=`CAT`,s.title=this.onRunCommand?f(i)?`Preview media in terminal`:`Preview in terminal`:`Terminal unavailable`,s.disabled=!this.onRunCommand,s.addEventListener(`click`,e=>{e.stopPropagation(),this.previewFile(i)}),a.appendChild(s),a.addEventListener(`click`,()=>{this.selectPath(i,`file`)}),t.appendChild(a)}}}async collectFiles(e,t){if(!this.fs)return{};let n={},r=await this.fs.readDir(e);for(let i of r){let r=e===`/`?`/`+i.name:e+`/`+i.name,a=t?t+`/`+i.name:i.name;if(i.type===`directory`){let e=await this.collectFiles(r,a);Object.assign(n,e)}else{let e=await this.fs.readFile(r,{encoding:`binary`});n[a]=e instanceof Uint8Array?e:new TextEncoder().encode(e)}}return n}async downloadDirAsZip(e,t){if(this.fs)try{let n=N(await this.collectFiles(e,``)),r=new Blob([n.buffer],{type:`application/zip`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t+`.zip`,a.click(),URL.revokeObjectURL(i)}catch(t){console.error(`[FileBrowser] ZIP download failed:`,e,t instanceof Error?t.message:String(t))}}previewFile(e){if(!this.onRunCommand)return;let t=Pi(e);Promise.resolve(this.onRunCommand(t)).catch(t=>{console.error(`[FileBrowser] Preview command failed:`,e,t instanceof Error?t.message:String(t))})}selectPath(e,t){this.selectedPath=t===`directory`&&!e.endsWith(`/`)?e+`/`:e,this.applySelection(),this.bodyEl.querySelector(`.file-browser__item--selected`)?.focus()}applySelection(){let e=this.bodyEl.querySelector(`.file-browser__item--selected`);if(e&&(e.classList.remove(`file-browser__item--selected`),e.removeAttribute(`tabindex`)),!this.selectedPath)return;let t=this.bodyEl.querySelectorAll(`.file-browser__item`);for(let e of t)if(e.dataset.path===this.selectedPath){e.classList.add(`file-browser__item--selected`),e.tabIndex=0;break}}setupKeydown(){this.keydownHandler=e=>{!(e.metaKey||e.ctrlKey)||e.key!==`c`||this.selectedPath&&window.getSelection()?.isCollapsed!==!1&&(e.preventDefault(),navigator.clipboard.writeText(this.selectedPath).then(()=>{this.flashCopyFeedback()}).catch(e=>{console.warn(`[FileBrowser] Clipboard write failed:`,e instanceof Error?e.message:String(e))}))},this.container.addEventListener(`keydown`,this.keydownHandler)}flashCopyFeedback(){let e=this.bodyEl.querySelector(`.file-browser__item--selected`);e&&(e.classList.add(`file-browser__item--copy-flash`),setTimeout(()=>{e.classList.remove(`file-browser__item--copy-flash`)},300))}dispose(){for(this.keydownHandler&&=(this.container.removeEventListener(`keydown`,this.keydownHandler),null),this.refreshTimer&&=(clearInterval(this.refreshTimer),null);this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},Ii=class{container;bodyEl;orchestrator=null;selectedScoopJid=null;refreshTimer=null;constructor(e){this.container=e,this.render()}setOrchestrator(e){this.orchestrator=e,this.refresh(),this.refreshTimer=setInterval(()=>this.refresh(),5e3)}setSelectedScoop(e){this.selectedScoopJid=e,this.refresh()}async refresh(){if(!this.orchestrator)return;let e=document.createElement(`div`);e.className=`memory-panel__content`;let t=document.createElement(`div`);t.className=`memory-panel__section`;let n=document.createElement(`div`);n.className=`memory-panel__section-header`,n.textContent=`Global Memory (/shared/CLAUDE.md)`,t.appendChild(n);let r=document.createElement(`div`);r.className=`memory-panel__memory-content`;try{r.textContent=await this.orchestrator.getGlobalMemory()||`(empty)`}catch{r.textContent=`(not available)`}if(t.appendChild(r),e.appendChild(t),this.selectedScoopJid){let t=this.orchestrator.getScoopContext(this.selectedScoopJid),n=this.orchestrator.getScoop(this.selectedScoopJid);if(t&&n){let r=document.createElement(`div`);r.className=`memory-panel__section`;let i=document.createElement(`div`);i.className=`memory-panel__section-header`,i.textContent=`${n.isCone?`Cone`:`Scoop`}: ${n.assistantLabel}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`memory-panel__memory-content`;try{let e=t.getFS();if(e){let t=n.isCone?`/workspace/CLAUDE.md`:`/scoops/${n.folder}/CLAUDE.md`,r=await e.readFile(t,{encoding:`utf-8`});a.textContent=typeof r==`string`?r:new TextDecoder().decode(r)}else a.textContent=`(filesystem not ready)`}catch{a.textContent=`(no memory file yet)`}r.appendChild(a),e.appendChild(r)}}if(e.innerHTML!==this.bodyEl.innerHTML){for(;this.bodyEl.firstChild;)this.bodyEl.removeChild(this.bodyEl.firstChild);for(;e.firstChild;)this.bodyEl.appendChild(e.firstChild)}}render(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.container.classList.add(`memory-panel`),this.bodyEl=document.createElement(`div`),this.bodyEl.className=`memory-panel__body`,this.container.appendChild(this.bodyEl)}dispose(){this.refreshTimer&&=(clearInterval(this.refreshTimer),null)}},Li=n(`scoops-panel`),Ri=class e{container;orchestrator=null;callbacks;selectedScoopJid=null;scoopStatuses=new Map;expanded=!1;eyesEl=null;hoveredJid=null;lastProcessingJid=null;coneJid=null;leftPupilGroup=null;rightPupilGroup=null;eyesSvg=null;mouseMoveBound=null;constructor(e,t){this.container=e,this.callbacks=t,this.render()}dispose(){this.mouseMoveBound&&=(document.removeEventListener(`mousemove`,this.mouseMoveBound),null),this.eyesEl?.remove(),this.eyesEl=null,this.eyesSvg=null,this.leftPupilGroup=null,this.rightPupilGroup=null,document.querySelectorAll(`.scoop-fixed-tooltip`).forEach(e=>e.remove())}toggleExpanded(){this.expanded=!this.expanded,this.container.classList.toggle(`layout__scoops--expanded`,this.expanded)}static LEFT_EYE={cx:55,cy:50,r:38};static RIGHT_EYE={cx:145,cy:50,r:38};static PUPIL_R=18;static MAX_OFFSET=16;createEyesEl(){let t=`http://www.w3.org/2000/svg`,n=document.createElement(`div`);n.className=`scoop-eyes`;let r=document.createElementNS(t,`svg`);r.setAttribute(`viewBox`,`0 0 200 100`),r.setAttribute(`width`,`100%`),r.setAttribute(`height`,`100%`);let{LEFT_EYE:i,RIGHT_EYE:a,PUPIL_R:o}=e,s=e=>{let n=document.createElementNS(t,`circle`);n.setAttribute(`cx`,String(e.cx)),n.setAttribute(`cy`,String(e.cy)),n.setAttribute(`r`,String(e.r)),n.setAttribute(`fill`,`#fff`),n.setAttribute(`stroke`,`#000`),n.setAttribute(`stroke-width`,`4`),r.appendChild(n);let i=document.createElementNS(t,`g`),a=document.createElementNS(t,`circle`);a.setAttribute(`cx`,String(e.cx)),a.setAttribute(`cy`,String(e.cy)),a.setAttribute(`r`,String(o)),a.setAttribute(`fill`,`#000`),i.appendChild(a);let s=document.createElementNS(t,`circle`);return s.setAttribute(`cx`,String(e.cx-o*.3)),s.setAttribute(`cy`,String(e.cy-o*.35)),s.setAttribute(`r`,String(o*.4)),s.setAttribute(`fill`,`#fff`),i.appendChild(s),r.appendChild(i),i};return this.leftPupilGroup=s(i),this.rightPupilGroup=s(a),n.appendChild(r),this.eyesSvg=r,this.mouseMoveBound||(this.mouseMoveBound=e=>this.onMouseMove(e),document.addEventListener(`mousemove`,this.mouseMoveBound)),n}onMouseMove(t){if(!this.eyesSvg||!this.leftPupilGroup||!this.rightPupilGroup)return;let n=this.eyesSvg.getBoundingClientRect();if(n.width===0||n.height===0)return;let r=200/n.width,i=100/n.height,a=(t.clientX-n.left)*r,o=(t.clientY-n.top)*i,{LEFT_EYE:s,RIGHT_EYE:c,MAX_OFFSET:l}=e;this.positionPupilGroup(this.leftPupilGroup,s.cx,s.cy,a,o,l),this.positionPupilGroup(this.rightPupilGroup,c.cx,c.cy,a,o,l)}positionPupilGroup(e,t,n,r,i,a){let o=r-t,s=i-n,c=Math.sqrt(o*o+s*s),l=Math.min(c,a),u=c>0?o/c*l:0,d=c>0?s/c*l:0;e.setAttribute(`transform`,`translate(${u},${d})`)}resolveEyesOwner(){if(this.hoveredJid&&this.hasScoopItem(this.hoveredJid))return this.hoveredJid;if(this.lastProcessingJid&&this.scoopStatuses.get(this.lastProcessingJid)===`processing`&&this.hasScoopItem(this.lastProcessingJid))return this.lastProcessingJid;for(let[e,t]of this.scoopStatuses)if(t===`processing`&&this.hasScoopItem(e))return this.lastProcessingJid=e,e;return this.coneJid}hasScoopItem(e){return!!this.container.querySelector(`.scoop-item[data-jid="${CSS.escape(e)}"]`)}moveEyes(){this.eyesEl||=this.createEyesEl();let e=this.resolveEyesOwner();if(!e)return;let t=this.container.querySelector(`.scoop-item[data-jid="${CSS.escape(e)}"]`);if(!t)return;let n=t.querySelector(`.scoop-icon-wrap`);n&&this.eyesEl.parentElement!==n&&n.appendChild(this.eyesEl)}setOrchestrator(e){this.orchestrator=e,this.refreshScoops()}updateScoopStatus(e,t){this.scoopStatuses.set(e,t),t===`processing`&&(this.lastProcessingJid=e),this.refreshScoops()}refreshScoops(){if(!this.orchestrator)return;document.querySelectorAll(`.scoop-fixed-tooltip`).forEach(e=>e.remove());let e=this.orchestrator.getScoops(),t=e.find(e=>e.isCone),n=e.filter(e=>!e.isCone),r=`http://www.w3.org/2000/svg`,i=[`#e8457a`,`#f08c5a`,`#9b6dd7`,`#42b8a0`,`#d4953e`],a=[`#fde4ec`,`#fef0e4`,`#efe4f8`,`#e0f5ef`,`#fef3e0`],o=this.container.querySelector(`.scoop-cone-header`);if(o){for(;o.firstChild;)o.removeChild(o.firstChild);if(t){this.coneJid=t.jid;let e=this.scoopStatuses.get(t.jid)??`inactive`,n=t.jid===this.selectedScoopJid,i=`#e07030`,a=`#fef0e0`,s=document.createElement(`div`);s.className=`scoop-item scoop-item--cone ${n?`selected`:``} status-${e}`,s.dataset.jid=t.jid,s.setAttribute(`aria-label`,t.assistantLabel),s.style.setProperty(`--scoop-accent`,i),s.style.setProperty(`--scoop-accent-bg`,a);let c=document.createElement(`div`);c.className=`scoop-icon-wrap scoop-icon-wrap--cone`,c.style.background=a,c.style.width=`40px`,c.style.height=`40px`;let l=document.createElementNS(r,`svg`);if(l.setAttribute(`width`,`24`),l.setAttribute(`height`,`24`),l.setAttribute(`viewBox`,`70 330 440 570`),l.innerHTML=`<path d="M108.22,414.88l189.84,460.03c1.36,3.3,6.09,3.16,7.25-.22l159.34-463.34c.87-2.53-1.03-5.16-3.7-5.13l-349.18,3.32c-2.74.03-4.59,2.82-3.55,5.35Z" fill="${i}" stroke="${i}" stroke-linejoin="round" stroke-width="12"/><path d="M261.93,482.48h0c15.03-15.03,4.46-40.72-16.79-40.83h0c-21.37-.11-32.14,25.72-17.03,40.83h0c9.34,9.34,24.48,9.34,33.82,0Z" fill="${a}"/><path d="M384.85,527.49l-51.82,51.82c-2.24,2.24-2.24,5.86,0,8.1l55.71,55.71c2.24,2.24,5.86,2.24,8.1,0h0c.62-.62,1.08-1.36,1.37-2.19l26.52-77.11c.71-2.07.18-4.36-1.37-5.91l-30.41-30.41c-2.24-2.24-5.86-2.24-8.1,0Z" fill="${a}"/><rect x="274.59" y="463.59" width="84.73" height="95.66" rx="42.36" ry="42.36" transform="translate(-268.79 373.91) rotate(-45)" fill="${a}"/><rect x="291.06" y="603.84" width="72.24" height="90.24" rx="36.12" ry="36.12" transform="translate(-363.06 421.43) rotate(-45)" fill="${a}"/><path d="M371.7,684.58l-25.94,25.94c-2.24,2.24-2.24,5.86,0,8.1l12.67,12.67c2.99,2.99,8.09,1.82,9.46-2.19l13.28-38.61c1.97-5.74-5.17-10.2-9.46-5.91Z" fill="${a}"/><path d="M159.42,564.14l2.73,6.83c1.52,3.82,6.46,4.83,9.37,1.93l2.05-2.05c2.24-2.24,2.24-5.86,0-8.1l-4.78-4.78c-4.4-4.4-11.67.39-9.37,6.17Z" fill="${a}"/><path d="M243.92,633.11l-48.65-48.65c-5.24-5.24-13.74-5.24-18.99,0h0c-3.8,3.8-4.97,9.49-2.98,14.47l27.77,69.54c3.58,8.95,15.14,11.33,21.96,4.51l20.89-20.89c5.24-5.24,5.24-13.74,0-18.99Z" fill="${a}"/><path d="M211.32,533.1h0c14.11-14.11,14.11-36.98,0-51.08l-34.94-34.94c-.72-.72-.72-1.89,0-2.62h0c1.16-1.16.34-3.15-1.3-3.16l-11.23-.06c-25.62-.13-43.23,25.72-33.73,49.51l5.37,13.45c1.82,4.55,4.54,8.68,8,12.15l16.74,16.74c14.11,14.11,36.98,14.11,51.08,0Z" fill="${a}"/><path d="M263.74,792.53h0c-5.69,5.69-7.45,14.23-4.46,21.71l22.5,56.36c6.92,17.34,31.68,16.74,37.75-.92l8.66-25.2c2.5-7.28.64-15.35-4.8-20.79l-31.17-31.17c-7.87-7.87-20.62-7.87-28.48,0Z" fill="${a}"/><path d="M392.94,503.07l40.81-40.81c2.24-2.24,5.86-2.24,8.1,0l.06.06c2.24,2.24,2.24,5.86,0,8.1l-40.81,40.81c-2.24,2.24-2.24,5.86,0,8.1l22.48,22.48c2.99,2.99,8.09,1.82,9.46-2.19l30.71-89.32c1.27-3.71-1.47-7.57-5.39-7.59l-120.63-.6c-5.11-.03-7.69,6.16-4.08,9.77l51.18,51.18c2.24,2.24,5.86,2.24,8.1,0Z" fill="${a}"/><rect x="217.18" y="527.25" width="72.24" height="95.66" rx="36.12" ry="36.12" transform="translate(-332.45 347.55) rotate(-45)" fill="${a}"/><path d="M350.28,739.46h0c-9.24-9.24-24.22-9.24-33.46,0l-13.94,13.94c-9.24,9.24-9.24,24.22,0,33.46l6.81,6.81c12.37,12.37,33.42,7.5,39.1-9.04l7.13-20.75c2.94-8.55.75-18.03-5.64-24.42Z" fill="${a}"/><path d="M234.18,749.12l13.2,33.06c1.52,3.82,6.46,4.83,9.37,1.93l9.93-9.93c2.24-2.24,2.24-5.86,0-8.1l-23.13-23.13c-4.4-4.4-11.67.39-9.37,6.17Z" fill="${a}"/><rect x="236.26" y="661.25" width="67.04" height="90.24" rx="33.52" ry="33.52" transform="translate(-420.46 397.65) rotate(-45)" fill="${a}"/><ellipse cx="288.37" cy="404.38" rx="182.34" ry="67.01" fill="${i}" stroke="${i}" stroke-miterlimit="10" stroke-width="12"/>`,c.appendChild(l),e===`processing`||e===`ready`||e===`error`){let t=document.createElement(`span`);t.className=`scoop-dot scoop-dot--${e}`,c.appendChild(t)}s.appendChild(c);let u=document.createElement(`div`);u.className=`scoop-info`;let d=document.createElement(`div`);if(d.className=`scoop-name`,d.textContent=t.assistantLabel,u.appendChild(d),e===`processing`||e===`error`){let t=document.createElement(`div`);t.className=`scoop-subtitle`,t.textContent=e===`processing`?`Working…`:`Error`,u.appendChild(t)}s.appendChild(u);let f=document.createElement(`div`);if(f.className=`scoop-actions`,e===`processing`){let e=document.createElement(`span`);e.className=`scoop-spin-dot`,f.appendChild(e)}else if(e===`error`){let e=document.createElement(`span`);e.className=`scoop-err-dot`,f.appendChild(e)}s.appendChild(f),s.addEventListener(`click`,()=>this.selectScoop(t)),s.addEventListener(`mouseenter`,()=>{this.hoveredJid=t.jid,this.moveEyes()}),s.addEventListener(`mouseleave`,()=>{this.hoveredJid===t.jid&&(this.hoveredJid=null),this.moveEyes()});let p=t.assistantLabel;s.addEventListener(`mouseenter`,()=>{if(this.expanded)return;let e=document.createElement(`div`);e.className=`scoop-fixed-tooltip`,e.textContent=p,document.body.appendChild(e);let t=s.getBoundingClientRect();e.style.top=`${t.top+t.height/2}px`,e.style.left=`${t.right+8}px`,s.__tip=e}),s.addEventListener(`mouseleave`,()=>{let e=s.__tip;e&&(e.remove(),s.__tip=null)}),o.appendChild(s)}}let s=this.container.querySelector(`.scoops-list`);if(s){for(;s.firstChild;)s.removeChild(s.firstChild);if(n.length===0){this.callbacks.onScoopsChanged?.(e),this.moveEyes();return}for(let e=0;e<n.length;e++){let t=n[e],o=this.scoopStatuses.get(t.jid)??`inactive`,c=t.jid===this.selectedScoopJid,l=i[e%i.length],u=a[e%a.length],d=document.createElement(`div`);d.className=`scoop-item ${c?`selected`:``} status-${o}`,d.dataset.jid=t.jid;let f=t.assistantLabel.replace(/-scoop$/,``);d.setAttribute(`aria-label`,f),d.style.setProperty(`--scoop-accent`,l),d.style.setProperty(`--scoop-accent-bg`,u);let p=document.createElement(`div`);p.className=`scoop-icon-wrap`,p.style.background=u;let m=document.createElementNS(r,`svg`);m.setAttribute(`width`,`20`),m.setAttribute(`height`,`20`),m.setAttribute(`viewBox`,`0 0 580 470`);let h=document.createElementNS(r,`path`);if(h.setAttribute(`d`,`M566.75,340.67c0-29.85-12.97-56.87-33.96-76.47,4.8-9.98,7.44-20.71,7.44-31.9,0-38.29-30.62-71.33-74.92-86.77.33-3.07.51-6.17.51-9.3,0-69.72-84.29-126.24-188.26-126.24s-188.26,56.52-188.26,126.24c0,4,.29,7.95.83,11.86-34.94,15.4-58.48,44.25-58.48,77.34,0,18.21,7.15,35.15,19.39,49.26-25.1,19.88-41.05,49.47-41.05,82.54,0,59.85,52.15,108.37,116.49,108.37,10.83,0,21.3-1.4,31.26-3.98,31.42,41.91,83.55,69.34,142.55,69.34,64.73,0,121.2-33,151.11-81.94,63.8-.57,115.34-48.85,115.34-108.34Z`),h.setAttribute(`fill`,l),h.setAttribute(`stroke`,l),h.setAttribute(`stroke-width`,`10`),m.appendChild(h),p.appendChild(m),o===`processing`||o===`ready`||o===`error`){let e=document.createElement(`span`);e.className=`scoop-dot scoop-dot--${o}`,p.appendChild(e)}d.appendChild(p);let g=document.createElement(`div`);g.className=`scoop-info`;let _=document.createElement(`div`);if(_.className=`scoop-name`,_.textContent=f,g.appendChild(_),o===`processing`||o===`error`){let e=document.createElement(`div`);e.className=`scoop-subtitle`,e.textContent=o===`processing`?`Working…`:`Error`,g.appendChild(e)}d.appendChild(g);let v=document.createElement(`div`);if(v.className=`scoop-actions`,o===`processing`){let e=document.createElement(`span`);e.className=`scoop-spin-dot`,v.appendChild(e)}else if(o===`error`){let e=document.createElement(`span`);e.className=`scoop-err-dot`,v.appendChild(e)}d.appendChild(v),d.addEventListener(`click`,()=>{this.selectScoop(t)}),d.addEventListener(`mouseenter`,()=>{this.hoveredJid=t.jid,this.moveEyes()}),d.addEventListener(`mouseleave`,()=>{this.hoveredJid===t.jid&&(this.hoveredJid=null),this.moveEyes()}),d.addEventListener(`mouseenter`,()=>{if(this.expanded)return;let e=document.createElement(`div`);e.className=`scoop-fixed-tooltip`,e.textContent=f,document.body.appendChild(e);let t=d.getBoundingClientRect();e.style.top=`${t.top+t.height/2}px`,e.style.left=`${t.right+8}px`,d.__tip=e}),d.addEventListener(`mouseleave`,()=>{let e=d.__tip;e&&(e.remove(),d.__tip=null)}),s.appendChild(d)}this.callbacks.onScoopsChanged?.(e),this.moveEyes()}}selectScoop(e){this.selectedScoopJid=e.jid,this.refreshScoops(),this.callbacks.onScoopSelect(e);let t=new URL(window.location.href);e.isCone?t.searchParams.delete(`scoop`):t.searchParams.set(`scoop`,e.folder),history.replaceState(null,``,t.toString())}selectScoopByFolder(e){if(!this.orchestrator)return;let t=this.orchestrator.getScoops().find(t=>t.folder===e);t&&this.selectScoop(t)}setSelectedJid(e){this.selectedScoopJid=e,this.refreshScoops()}getSelectedScoopJid(){return this.selectedScoopJid}async deleteScoop(e){if(!this.orchestrator)return;let t=this.orchestrator.getScoop(e);if(t){if(t.isCone){alert(`Cannot delete the cone`);return}if(confirm(`Delete scoop "${t.name}"? This cannot be undone.`)){try{await this.orchestrator.unregisterScoop(e)}catch(e){let t=e instanceof Error?e.message:String(e);alert(t);return}this.selectedScoopJid===e&&(this.selectedScoopJid=null),this.refreshScoops(),Li.info(`Scoop deleted`,{jid:e,name:t.name})}}}async createScoop(e,t=!1){if(!this.orchestrator)throw Error(`Orchestrator not set`);let n=t?`cone`:this.sanitizeFolderName(e)+`-scoop`,r=t?`cone_${Date.now()}`:`scoop_${n}_${Date.now()}`,i={jid:r,name:e,folder:n,trigger:t?void 0:`@${n}`,requiresTrigger:!t,isCone:t,type:t?`cone`:`scoop`,assistantLabel:t?`sliccy`:n,addedAt:new Date().toISOString()};return await this.orchestrator.registerScoop(i),this.refreshScoops(),Li.info(`Scoop created`,{jid:r,name:e,isCone:t}),i}sanitizeFolderName(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,50)||`scoop`}render(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);let e=document.createElement(`div`);e.className=`scoops-panel`;let t=document.createElement(`div`);t.className=`scoop-cone-header`,e.appendChild(t);let n=document.createElement(`div`);n.className=`scoops-list`,e.appendChild(n),this.container.appendChild(e);let r=document.createElement(`style`);r.textContent=`
|
|
257
|
+
`,exitCode:1}}refit(){this.shell?.refit()}getBodyElement(){return this.container}render(){this.container.innerHTML=``,this.container.classList.add(`terminal-panel`);let e=document.createElement(`div`);e.className=`file-browser__header`;let t=document.createElement(`span`);if(t.className=`file-browser__header-title`,t.textContent=`Terminal`,e.appendChild(t),this.onClearTerminal){let t=document.createElement(`button`);t.className=`file-browser__header-btn`,t.dataset.tooltip=`Clear Terminal`,t.setAttribute(`aria-label`,`Clear Terminal`),t.innerHTML=`<svg width="14" height="14" viewBox="0 0 20 20" fill="none"><path d="m8.249,15.021c-.4,0-.733-.317-.748-.72l-.25-6.5c-.017-.414.307-.763.72-.778.01-.001.021-.001.03-.001.4,0,.733.317.748.72l.25,6.5c.017.414-.307.763-.72.778-.01.001-.021.001-.03.001Z" fill="currentColor"/><path d="m11.751,15.021c-.01,0-.02,0-.03-.001-.413-.016-.736-.364-.72-.778l.25-6.5c.015-.403.348-.72.748-.72.01,0,.02,0,.03.001.413.016.736.364.72.778l-.25,6.5c-.015.403-.348.72-.748.72Z" fill="currentColor"/><path d="m17,4h-3.5v-.75c0-1.24-1.01-2.25-2.25-2.25h-2.5c-1.24,0-2.25,1.01-2.25,2.25v.75h-3.5c-.414,0-.75.336-.75.75s.336.75.75.75h.52l.422,10.342c.048,1.21,1.036,2.158,2.248,2.158h7.619c1.212,0,2.2-.948,2.248-2.158l.422-10.342h.52c.414,0,.75-.336.75-.75s-.336-.75-.75-.75Zm-9-.75c0-.413.337-.75.75-.75h2.5c.413,0,.75.337.75.75v.75h-4v-.75Zm6.56,12.531c-.017.403-.346.719-.75.719h-7.619c-.404,0-.733-.316-.75-.719l-.42-10.281h9.959l-.42,10.281Z" fill="currentColor"/></svg>`,t.addEventListener(`click`,()=>this.onClearTerminal()),e.appendChild(t)}this.previewBtn=document.createElement(`button`),this.previewBtn.className=`file-browser__header-btn`,this.previewBtn.setAttribute(`aria-label`,`Toggle preview`),this.previewBtn.dataset.tooltip=`Preview`,this.previewBtn.disabled=!0;let n=`http://www.w3.org/2000/svg`,r=document.createElementNS(n,`svg`);r.setAttribute(`width`,`16`),r.setAttribute(`height`,`16`),r.setAttribute(`viewBox`,`0 0 20 20`),r.setAttribute(`fill`,`none`),r.setAttribute(`stroke`,`currentColor`),r.setAttribute(`stroke-width`,`1.5`),r.setAttribute(`stroke-linecap`,`round`),r.setAttribute(`stroke-linejoin`,`round`);let i=document.createElementNS(n,`path`);i.setAttribute(`d`,`M2 10s3-6 8-6 8 6 8 6-3 6-8 6-8-6-8-6z`),r.appendChild(i);let a=document.createElementNS(n,`circle`);a.setAttribute(`cx`,`10`),a.setAttribute(`cy`,`10`),a.setAttribute(`r`,`2.5`),r.appendChild(a),this.previewBtn.appendChild(r),this.previewBtn.addEventListener(`click`,()=>{this.previewBtn.disabled||this.setActiveView(this.activeView===`preview`?`terminal`:`preview`)}),e.appendChild(this.previewBtn),this.container.appendChild(e),this.terminalViewEl=document.createElement(`div`),this.terminalViewEl.className=`terminal-panel__view`,this.container.appendChild(this.terminalViewEl),this.previewViewEl=document.createElement(`div`),this.previewViewEl.className=`terminal-panel__view`,this.container.appendChild(this.previewViewEl),this.previewEmptyEl=document.createElement(`div`),this.previewEmptyEl.className=`terminal-panel__empty-state`,this.previewEmptyEl.textContent=`Run imgcat to preview media here.`,this.previewViewEl.appendChild(this.previewEmptyEl),this.setActiveView(`terminal`)}dispose(){this.shell?.setPreviewStateListener(null),this.shell?.dispose(),this.container.innerHTML=``}setActiveView(e){this.activeView=e,this.previewBtn.classList.toggle(`file-browser__header-btn--active`,e===`preview`),this.terminalViewEl.style.display=e===`terminal`?`flex`:`none`,this.previewViewEl.style.display=e===`preview`?`flex`:`none`,e===`terminal`&&this.refit()}handlePreviewStateChange(e){this.previewBtn.disabled=!e,this.previewEmptyEl.style.display=e?`none`:`flex`,e?this.setActiveView(`preview`):this.activeView===`preview`&&this.setActiveView(`terminal`)}};function Oi(e){return e<1024?e+` B`:e<1024*1024?(e/1024).toFixed(1)+`K`:e<1024*1024*1024?(e/(1024*1024)).toFixed(1)+`M`:(e/(1024*1024*1024)).toFixed(1)+`G`}function ki(e){let t=`http://www.w3.org/2000/svg`,n=document.createElementNS(t,`svg`);n.setAttribute(`width`,`14`),n.setAttribute(`height`,`14`),n.setAttribute(`viewBox`,`0 0 20 20`),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke`,`currentColor`),n.setAttribute(`stroke-width`,`1.5`),n.setAttribute(`stroke-linecap`,`round`),n.setAttribute(`stroke-linejoin`,`round`),n.style.flexShrink=`0`;for(let r of e){let e=document.createElementNS(t,`path`);e.setAttribute(`d`,r),n.appendChild(e)}return n}function Ai(){return ki([`M2 6V5a1 1 0 0 1 1-1h4l2 2h8a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V6z`])}function ji(){return ki([`M6 2h5l5 5v9a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z`,`M11 2v5h5`])}function Mi(e){let t=`http://www.w3.org/2000/svg`,n=document.createElementNS(t,`svg`);n.setAttribute(`width`,`10`),n.setAttribute(`height`,`10`),n.setAttribute(`viewBox`,`0 0 20 20`),n.setAttribute(`fill`,`none`),n.setAttribute(`stroke`,`currentColor`),n.setAttribute(`stroke-width`,`2`),n.setAttribute(`stroke-linecap`,`round`),n.setAttribute(`stroke-linejoin`,`round`),n.style.flexShrink=`0`,n.style.transition=`transform 130ms ease`,e&&(n.style.transform=`rotate(90deg)`);let r=document.createElementNS(t,`path`);return r.setAttribute(`d`,`M7 5l5 5-5 5`),n.appendChild(r),n}function Ni(e){return`'${e.replace(/'/g,`'\\''`)}'`}function Pi(e){return`${f(e)?`imgcat`:`cat`} ${Ni(e)}`}var Fi=class{container;bodyEl;fs=null;expandedDirs=new Set([`/`]);refreshTimer=null;onRunCommand;selectedPath=null;keydownHandler=null;constructor(e,t={}){this.container=e,this.onRunCommand=t.onRunCommand??null,this.render()}setFs(e){this.fs=e,this.refresh(),this.refreshTimer=setInterval(()=>this.refresh(),3e3)}async refresh(){if(!this.fs)return;let e=document.createElement(`div`);try{await this.renderDir(`/`,e,0)}catch(e){console.warn(`[FileBrowser] Refresh failed:`,e instanceof Error?e.message:String(e));return}if(e.innerHTML===this.bodyEl.innerHTML){this.applySelection();return}let t=this.container.contains(document.activeElement);for(;this.bodyEl.firstChild;)this.bodyEl.removeChild(this.bodyEl.firstChild);for(;e.firstChild;)this.bodyEl.appendChild(e.firstChild);this.applySelection(),t&&this.selectedPath&&this.bodyEl.querySelector(`.file-browser__item--selected`)?.focus()}render(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.container.classList.add(`file-browser`);let e=document.createElement(`div`);e.className=`file-browser__header`;let t=document.createElement(`span`);t.className=`file-browser__header-title`,t.textContent=`Files`,e.appendChild(t),this.container.appendChild(e),this.bodyEl=document.createElement(`div`),this.bodyEl.className=`file-browser__body`,this.container.appendChild(this.bodyEl),this.setupKeydown()}async renderDir(e,t,n){if(!this.fs)return;let r;try{r=await this.fs.readDir(e)}catch(t){console.warn(`[FileBrowser] readDir failed:`,e,t instanceof Error?t.message:String(t));return}let i=r.filter(e=>e.type===`directory`).sort((e,t)=>e.name.localeCompare(t.name)),a=r.filter(e=>e.type===`file`).sort((e,t)=>e.name.localeCompare(t.name));for(let r of[...i,...a]){let i=e===`/`?`/`+r.name:e+`/`+r.name,a=document.createElement(`div`);if(a.className=`file-browser__item`,a.style.paddingLeft=12+n*16+`px`,a.dataset.path=r.type===`directory`&&!i.endsWith(`/`)?i+`/`:i,r.type===`directory`){let e=this.expandedDirs.has(i),o=document.createElement(`span`);o.className=`file-browser__arrow`,o.appendChild(Mi(e)),a.appendChild(o);let s=document.createElement(`span`);s.className=`file-browser__icon`,s.appendChild(Ai()),a.appendChild(s);let c=document.createElement(`span`);c.className=`file-browser__name`,c.textContent=r.name,a.appendChild(c);let l=document.createElement(`button`);l.className=`file-browser__action-btn`,l.style.marginLeft=`auto`,l.textContent=`ZIP`,l.title=`Download as ZIP`,l.addEventListener(`click`,e=>{e.stopPropagation(),this.downloadDirAsZip(i,r.name)}),a.appendChild(l),a.style.cursor=`pointer`,a.addEventListener(`click`,()=>{this.selectPath(i,`directory`),this.expandedDirs.has(i)?this.expandedDirs.delete(i):this.expandedDirs.add(i),this.refresh()}),t.appendChild(a),e&&await this.renderDir(i,t,n+1)}else{let e=document.createElement(`span`);e.className=`file-browser__arrow`,a.appendChild(e);let n=document.createElement(`span`);n.className=`file-browser__icon`,n.appendChild(ji()),a.appendChild(n);let o=document.createElement(`span`);o.className=`file-browser__name`,o.textContent=r.name,a.appendChild(o);try{let e=await this.fs.stat(i),t=document.createElement(`span`);t.className=`file-browser__size`,t.textContent=Oi(e.size),a.appendChild(t)}catch(e){console.warn(`[FileBrowser] stat failed:`,i,e instanceof Error?e.message:String(e))}let s=document.createElement(`button`);s.className=`file-browser__action-btn`,s.style.marginLeft=`8px`,s.textContent=`CAT`,s.title=this.onRunCommand?f(i)?`Preview media in terminal`:`Preview in terminal`:`Terminal unavailable`,s.disabled=!this.onRunCommand,s.addEventListener(`click`,e=>{e.stopPropagation(),this.previewFile(i)}),a.appendChild(s),a.addEventListener(`click`,()=>{this.selectPath(i,`file`)}),t.appendChild(a)}}}async collectFiles(e,t){if(!this.fs)return{};let n={},r=await this.fs.readDir(e);for(let i of r){let r=e===`/`?`/`+i.name:e+`/`+i.name,a=t?t+`/`+i.name:i.name;if(i.type===`directory`){let e=await this.collectFiles(r,a);Object.assign(n,e)}else{let e=await this.fs.readFile(r,{encoding:`binary`});n[a]=e instanceof Uint8Array?e:new TextEncoder().encode(e)}}return n}async downloadDirAsZip(e,t){if(this.fs)try{let n=N(await this.collectFiles(e,``)),r=new Blob([n.buffer],{type:`application/zip`}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t+`.zip`,a.click(),URL.revokeObjectURL(i)}catch(t){console.error(`[FileBrowser] ZIP download failed:`,e,t instanceof Error?t.message:String(t))}}previewFile(e){if(!this.onRunCommand)return;let t=Pi(e);Promise.resolve(this.onRunCommand(t)).catch(t=>{console.error(`[FileBrowser] Preview command failed:`,e,t instanceof Error?t.message:String(t))})}selectPath(e,t){this.selectedPath=t===`directory`&&!e.endsWith(`/`)?e+`/`:e,this.applySelection(),this.bodyEl.querySelector(`.file-browser__item--selected`)?.focus()}applySelection(){let e=this.bodyEl.querySelector(`.file-browser__item--selected`);if(e&&(e.classList.remove(`file-browser__item--selected`),e.removeAttribute(`tabindex`)),!this.selectedPath)return;let t=this.bodyEl.querySelectorAll(`.file-browser__item`);for(let e of t)if(e.dataset.path===this.selectedPath){e.classList.add(`file-browser__item--selected`),e.tabIndex=0;break}}setupKeydown(){this.keydownHandler=e=>{!(e.metaKey||e.ctrlKey)||e.key!==`c`||this.selectedPath&&window.getSelection()?.isCollapsed!==!1&&(e.preventDefault(),navigator.clipboard.writeText(this.selectedPath).then(()=>{this.flashCopyFeedback()}).catch(e=>{console.warn(`[FileBrowser] Clipboard write failed:`,e instanceof Error?e.message:String(e))}))},this.container.addEventListener(`keydown`,this.keydownHandler)}flashCopyFeedback(){let e=this.bodyEl.querySelector(`.file-browser__item--selected`);e&&(e.classList.add(`file-browser__item--copy-flash`),setTimeout(()=>{e.classList.remove(`file-browser__item--copy-flash`)},300))}dispose(){for(this.keydownHandler&&=(this.container.removeEventListener(`keydown`,this.keydownHandler),null),this.refreshTimer&&=(clearInterval(this.refreshTimer),null);this.container.firstChild;)this.container.removeChild(this.container.firstChild)}},Ii=class{container;bodyEl;orchestrator=null;selectedScoopJid=null;refreshTimer=null;constructor(e){this.container=e,this.render()}setOrchestrator(e){this.orchestrator=e,this.refresh(),this.refreshTimer=setInterval(()=>this.refresh(),5e3)}setSelectedScoop(e){this.selectedScoopJid=e,this.refresh()}async refresh(){if(!this.orchestrator)return;let e=document.createElement(`div`);e.className=`memory-panel__content`;let t=document.createElement(`div`);t.className=`memory-panel__section`;let n=document.createElement(`div`);n.className=`memory-panel__section-header`,n.textContent=`Global Memory (/shared/CLAUDE.md)`,t.appendChild(n);let r=document.createElement(`div`);r.className=`memory-panel__memory-content`;try{r.textContent=await this.orchestrator.getGlobalMemory()||`(empty)`}catch{r.textContent=`(not available)`}if(t.appendChild(r),e.appendChild(t),this.selectedScoopJid){let t=this.orchestrator.getScoopContext(this.selectedScoopJid),n=this.orchestrator.getScoop(this.selectedScoopJid);if(t&&n){let r=document.createElement(`div`);r.className=`memory-panel__section`;let i=document.createElement(`div`);i.className=`memory-panel__section-header`,i.textContent=`${n.isCone?`Cone`:`Scoop`}: ${n.assistantLabel}`,r.appendChild(i);let a=document.createElement(`div`);a.className=`memory-panel__memory-content`;try{let e=t.getFS();if(e){let t=n.isCone?`/workspace/CLAUDE.md`:`/scoops/${n.folder}/CLAUDE.md`,r=await e.readFile(t,{encoding:`utf-8`});a.textContent=typeof r==`string`?r:new TextDecoder().decode(r)}else a.textContent=`(filesystem not ready)`}catch{a.textContent=`(no memory file yet)`}r.appendChild(a),e.appendChild(r)}}if(e.innerHTML!==this.bodyEl.innerHTML){for(;this.bodyEl.firstChild;)this.bodyEl.removeChild(this.bodyEl.firstChild);for(;e.firstChild;)this.bodyEl.appendChild(e.firstChild)}}render(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);this.container.classList.add(`memory-panel`),this.bodyEl=document.createElement(`div`),this.bodyEl.className=`memory-panel__body`,this.container.appendChild(this.bodyEl)}dispose(){this.refreshTimer&&=(clearInterval(this.refreshTimer),null)}},Li=n(`scoops-panel`),Ri=class e{container;orchestrator=null;callbacks;selectedScoopJid=null;scoopStatuses=new Map;expanded=!1;eyesEl=null;hoveredJid=null;lastProcessingJid=null;coneJid=null;leftPupilGroup=null;rightPupilGroup=null;eyesSvg=null;mouseMoveBound=null;constructor(e,t){this.container=e,this.callbacks=t,this.render()}dispose(){this.mouseMoveBound&&=(document.removeEventListener(`mousemove`,this.mouseMoveBound),null),this.eyesEl?.remove(),this.eyesEl=null,this.eyesSvg=null,this.leftPupilGroup=null,this.rightPupilGroup=null,document.querySelectorAll(`.scoop-fixed-tooltip`).forEach(e=>e.remove())}toggleExpanded(){this.expanded=!this.expanded,this.container.classList.toggle(`layout__scoops--expanded`,this.expanded)}static LEFT_EYE={cx:55,cy:50,r:38};static RIGHT_EYE={cx:145,cy:50,r:38};static PUPIL_R=18;static MAX_OFFSET=16;createEyesEl(){let t=`http://www.w3.org/2000/svg`,n=document.createElement(`div`);n.className=`scoop-eyes`;let r=document.createElementNS(t,`svg`);r.setAttribute(`viewBox`,`0 0 200 100`),r.setAttribute(`width`,`100%`),r.setAttribute(`height`,`100%`);let{LEFT_EYE:i,RIGHT_EYE:a,PUPIL_R:o}=e,s=e=>{let n=document.createElementNS(t,`circle`);n.setAttribute(`cx`,String(e.cx)),n.setAttribute(`cy`,String(e.cy)),n.setAttribute(`r`,String(e.r)),n.setAttribute(`fill`,`#fff`),n.setAttribute(`stroke`,`#000`),n.setAttribute(`stroke-width`,`4`),r.appendChild(n);let i=document.createElementNS(t,`g`),a=document.createElementNS(t,`circle`);a.setAttribute(`cx`,String(e.cx)),a.setAttribute(`cy`,String(e.cy)),a.setAttribute(`r`,String(o)),a.setAttribute(`fill`,`#000`),i.appendChild(a);let s=document.createElementNS(t,`circle`);return s.setAttribute(`cx`,String(e.cx-o*.3)),s.setAttribute(`cy`,String(e.cy-o*.35)),s.setAttribute(`r`,String(o*.4)),s.setAttribute(`fill`,`#fff`),i.appendChild(s),r.appendChild(i),i};return this.leftPupilGroup=s(i),this.rightPupilGroup=s(a),n.appendChild(r),this.eyesSvg=r,this.mouseMoveBound||(this.mouseMoveBound=e=>this.onMouseMove(e),document.addEventListener(`mousemove`,this.mouseMoveBound)),n}onMouseMove(t){if(!this.eyesSvg||!this.leftPupilGroup||!this.rightPupilGroup)return;let n=this.eyesSvg.getBoundingClientRect();if(n.width===0||n.height===0)return;let r=200/n.width,i=100/n.height,a=(t.clientX-n.left)*r,o=(t.clientY-n.top)*i,{LEFT_EYE:s,RIGHT_EYE:c,MAX_OFFSET:l}=e;this.positionPupilGroup(this.leftPupilGroup,s.cx,s.cy,a,o,l),this.positionPupilGroup(this.rightPupilGroup,c.cx,c.cy,a,o,l)}positionPupilGroup(e,t,n,r,i,a){let o=r-t,s=i-n,c=Math.sqrt(o*o+s*s),l=Math.min(c,a),u=c>0?o/c*l:0,d=c>0?s/c*l:0;e.setAttribute(`transform`,`translate(${u},${d})`)}resolveEyesOwner(){if(this.hoveredJid&&this.hasScoopItem(this.hoveredJid))return this.hoveredJid;if(this.lastProcessingJid&&this.scoopStatuses.get(this.lastProcessingJid)===`processing`&&this.hasScoopItem(this.lastProcessingJid))return this.lastProcessingJid;for(let[e,t]of this.scoopStatuses)if(t===`processing`&&this.hasScoopItem(e))return this.lastProcessingJid=e,e;return this.coneJid}hasScoopItem(e){return!!this.container.querySelector(`.scoop-item[data-jid="${CSS.escape(e)}"]`)}moveEyes(){this.eyesEl||=this.createEyesEl();let e=this.resolveEyesOwner();if(!e)return;let t=this.container.querySelector(`.scoop-item[data-jid="${CSS.escape(e)}"]`);if(!t)return;let n=t.querySelector(`.scoop-icon-wrap`);n&&this.eyesEl.parentElement!==n&&n.appendChild(this.eyesEl)}setOrchestrator(e){this.orchestrator=e,this.refreshScoops()}updateScoopStatus(e,t){this.scoopStatuses.set(e,t),t===`processing`&&(this.lastProcessingJid=e),this.refreshScoops()}refreshScoops(){if(!this.orchestrator)return;document.querySelectorAll(`.scoop-fixed-tooltip`).forEach(e=>e.remove());let e=this.orchestrator.getScoops(),t=e.find(e=>e.isCone),n=e.filter(e=>!e.isCone),r=`http://www.w3.org/2000/svg`,i=[`#e8457a`,`#f08c5a`,`#9b6dd7`,`#42b8a0`,`#d4953e`],a=[`#fde4ec`,`#fef0e4`,`#efe4f8`,`#e0f5ef`,`#fef3e0`],o=this.container.querySelector(`.scoop-cone-header`);if(o){for(;o.firstChild;)o.removeChild(o.firstChild);if(t){this.coneJid=t.jid;let e=this.scoopStatuses.get(t.jid)??`inactive`,n=t.jid===this.selectedScoopJid,i=`#e07030`,a=`#fef0e0`,s=document.createElement(`div`);s.className=`scoop-item scoop-item--cone ${n?`selected`:``} status-${e}`,s.dataset.jid=t.jid,s.setAttribute(`aria-label`,t.assistantLabel),s.style.setProperty(`--scoop-accent`,i),s.style.setProperty(`--scoop-accent-bg`,a);let c=document.createElement(`div`);c.className=`scoop-icon-wrap scoop-icon-wrap--cone`,c.style.background=a,c.style.width=`40px`,c.style.height=`40px`;let l=document.createElementNS(r,`svg`);if(l.setAttribute(`width`,`24`),l.setAttribute(`height`,`24`),l.setAttribute(`viewBox`,`70 330 440 570`),l.innerHTML=`<path d="M108.22,414.88l189.84,460.03c1.36,3.3,6.09,3.16,7.25-.22l159.34-463.34c.87-2.53-1.03-5.16-3.7-5.13l-349.18,3.32c-2.74.03-4.59,2.82-3.55,5.35Z" fill="${i}" stroke="${i}" stroke-linejoin="round" stroke-width="12"/><path d="M261.93,482.48h0c15.03-15.03,4.46-40.72-16.79-40.83h0c-21.37-.11-32.14,25.72-17.03,40.83h0c9.34,9.34,24.48,9.34,33.82,0Z" fill="${a}"/><path d="M384.85,527.49l-51.82,51.82c-2.24,2.24-2.24,5.86,0,8.1l55.71,55.71c2.24,2.24,5.86,2.24,8.1,0h0c.62-.62,1.08-1.36,1.37-2.19l26.52-77.11c.71-2.07.18-4.36-1.37-5.91l-30.41-30.41c-2.24-2.24-5.86-2.24-8.1,0Z" fill="${a}"/><rect x="274.59" y="463.59" width="84.73" height="95.66" rx="42.36" ry="42.36" transform="translate(-268.79 373.91) rotate(-45)" fill="${a}"/><rect x="291.06" y="603.84" width="72.24" height="90.24" rx="36.12" ry="36.12" transform="translate(-363.06 421.43) rotate(-45)" fill="${a}"/><path d="M371.7,684.58l-25.94,25.94c-2.24,2.24-2.24,5.86,0,8.1l12.67,12.67c2.99,2.99,8.09,1.82,9.46-2.19l13.28-38.61c1.97-5.74-5.17-10.2-9.46-5.91Z" fill="${a}"/><path d="M159.42,564.14l2.73,6.83c1.52,3.82,6.46,4.83,9.37,1.93l2.05-2.05c2.24-2.24,2.24-5.86,0-8.1l-4.78-4.78c-4.4-4.4-11.67.39-9.37,6.17Z" fill="${a}"/><path d="M243.92,633.11l-48.65-48.65c-5.24-5.24-13.74-5.24-18.99,0h0c-3.8,3.8-4.97,9.49-2.98,14.47l27.77,69.54c3.58,8.95,15.14,11.33,21.96,4.51l20.89-20.89c5.24-5.24,5.24-13.74,0-18.99Z" fill="${a}"/><path d="M211.32,533.1h0c14.11-14.11,14.11-36.98,0-51.08l-34.94-34.94c-.72-.72-.72-1.89,0-2.62h0c1.16-1.16.34-3.15-1.3-3.16l-11.23-.06c-25.62-.13-43.23,25.72-33.73,49.51l5.37,13.45c1.82,4.55,4.54,8.68,8,12.15l16.74,16.74c14.11,14.11,36.98,14.11,51.08,0Z" fill="${a}"/><path d="M263.74,792.53h0c-5.69,5.69-7.45,14.23-4.46,21.71l22.5,56.36c6.92,17.34,31.68,16.74,37.75-.92l8.66-25.2c2.5-7.28.64-15.35-4.8-20.79l-31.17-31.17c-7.87-7.87-20.62-7.87-28.48,0Z" fill="${a}"/><path d="M392.94,503.07l40.81-40.81c2.24-2.24,5.86-2.24,8.1,0l.06.06c2.24,2.24,2.24,5.86,0,8.1l-40.81,40.81c-2.24,2.24-2.24,5.86,0,8.1l22.48,22.48c2.99,2.99,8.09,1.82,9.46-2.19l30.71-89.32c1.27-3.71-1.47-7.57-5.39-7.59l-120.63-.6c-5.11-.03-7.69,6.16-4.08,9.77l51.18,51.18c2.24,2.24,5.86,2.24,8.1,0Z" fill="${a}"/><rect x="217.18" y="527.25" width="72.24" height="95.66" rx="36.12" ry="36.12" transform="translate(-332.45 347.55) rotate(-45)" fill="${a}"/><path d="M350.28,739.46h0c-9.24-9.24-24.22-9.24-33.46,0l-13.94,13.94c-9.24,9.24-9.24,24.22,0,33.46l6.81,6.81c12.37,12.37,33.42,7.5,39.1-9.04l7.13-20.75c2.94-8.55.75-18.03-5.64-24.42Z" fill="${a}"/><path d="M234.18,749.12l13.2,33.06c1.52,3.82,6.46,4.83,9.37,1.93l9.93-9.93c2.24-2.24,2.24-5.86,0-8.1l-23.13-23.13c-4.4-4.4-11.67.39-9.37,6.17Z" fill="${a}"/><rect x="236.26" y="661.25" width="67.04" height="90.24" rx="33.52" ry="33.52" transform="translate(-420.46 397.65) rotate(-45)" fill="${a}"/><ellipse cx="288.37" cy="404.38" rx="182.34" ry="67.01" fill="${i}" stroke="${i}" stroke-miterlimit="10" stroke-width="12"/>`,c.appendChild(l),e===`processing`||e===`ready`||e===`error`){let t=document.createElement(`span`);t.className=`scoop-dot scoop-dot--${e}`,c.appendChild(t)}s.appendChild(c);let u=document.createElement(`div`);u.className=`scoop-info`;let d=document.createElement(`div`);if(d.className=`scoop-name`,d.textContent=t.assistantLabel,u.appendChild(d),e===`processing`||e===`error`){let t=document.createElement(`div`);t.className=`scoop-subtitle`,t.textContent=e===`processing`?`Working…`:`Error`,u.appendChild(t)}s.appendChild(u);let f=document.createElement(`div`);if(f.className=`scoop-actions`,e===`processing`){let e=document.createElement(`span`);e.className=`scoop-spin-dot`,f.appendChild(e)}else if(e===`error`){let e=document.createElement(`span`);e.className=`scoop-err-dot`,f.appendChild(e)}s.appendChild(f),s.addEventListener(`click`,()=>this.selectScoop(t)),s.addEventListener(`mouseenter`,()=>{this.hoveredJid=t.jid,this.moveEyes()}),s.addEventListener(`mouseleave`,()=>{this.hoveredJid===t.jid&&(this.hoveredJid=null),this.moveEyes()});let p=t.assistantLabel;s.addEventListener(`mouseenter`,()=>{if(this.expanded)return;let e=document.createElement(`div`);e.className=`scoop-fixed-tooltip`,e.textContent=p,document.body.appendChild(e);let t=s.getBoundingClientRect();e.style.top=`${t.top+t.height/2}px`,e.style.left=`${t.right+8}px`,s.__tip=e}),s.addEventListener(`mouseleave`,()=>{let e=s.__tip;e&&(e.remove(),s.__tip=null)}),o.appendChild(s)}}let s=this.container.querySelector(`.scoops-list`);if(s){for(;s.firstChild;)s.removeChild(s.firstChild);if(n.length===0){this.callbacks.onScoopsChanged?.(e),this.moveEyes();return}for(let e=0;e<n.length;e++){let t=n[e],o=this.scoopStatuses.get(t.jid)??`inactive`,c=t.jid===this.selectedScoopJid,l=i[e%i.length],u=a[e%a.length],d=document.createElement(`div`);d.className=`scoop-item ${c?`selected`:``} status-${o}`,d.dataset.jid=t.jid;let f=t.assistantLabel.replace(/-scoop$/,``);d.setAttribute(`aria-label`,f),d.style.setProperty(`--scoop-accent`,l),d.style.setProperty(`--scoop-accent-bg`,u);let p=document.createElement(`div`);p.className=`scoop-icon-wrap`,p.style.background=u;let m=document.createElementNS(r,`svg`);m.setAttribute(`width`,`20`),m.setAttribute(`height`,`20`),m.setAttribute(`viewBox`,`0 0 580 470`);let h=document.createElementNS(r,`path`);if(h.setAttribute(`d`,`M566.75,340.67c0-29.85-12.97-56.87-33.96-76.47,4.8-9.98,7.44-20.71,7.44-31.9,0-38.29-30.62-71.33-74.92-86.77.33-3.07.51-6.17.51-9.3,0-69.72-84.29-126.24-188.26-126.24s-188.26,56.52-188.26,126.24c0,4,.29,7.95.83,11.86-34.94,15.4-58.48,44.25-58.48,77.34,0,18.21,7.15,35.15,19.39,49.26-25.1,19.88-41.05,49.47-41.05,82.54,0,59.85,52.15,108.37,116.49,108.37,10.83,0,21.3-1.4,31.26-3.98,31.42,41.91,83.55,69.34,142.55,69.34,64.73,0,121.2-33,151.11-81.94,63.8-.57,115.34-48.85,115.34-108.34Z`),h.setAttribute(`fill`,l),h.setAttribute(`stroke`,l),h.setAttribute(`stroke-width`,`10`),m.appendChild(h),p.appendChild(m),o===`processing`||o===`ready`||o===`error`){let e=document.createElement(`span`);e.className=`scoop-dot scoop-dot--${o}`,p.appendChild(e)}d.appendChild(p);let g=document.createElement(`div`);g.className=`scoop-info`;let _=document.createElement(`div`);if(_.className=`scoop-name`,_.textContent=f,g.appendChild(_),o===`processing`||o===`error`){let e=document.createElement(`div`);e.className=`scoop-subtitle`,e.textContent=o===`processing`?`Working…`:`Error`,g.appendChild(e)}d.appendChild(g);let v=document.createElement(`div`);if(v.className=`scoop-actions`,o===`processing`){let e=document.createElement(`span`);e.className=`scoop-spin-dot`,v.appendChild(e)}else if(o===`error`){let e=document.createElement(`span`);e.className=`scoop-err-dot`,v.appendChild(e)}d.appendChild(v),d.addEventListener(`click`,()=>{this.selectScoop(t)}),d.addEventListener(`mouseenter`,()=>{this.hoveredJid=t.jid,this.moveEyes()}),d.addEventListener(`mouseleave`,()=>{this.hoveredJid===t.jid&&(this.hoveredJid=null),this.moveEyes()}),d.addEventListener(`mouseenter`,()=>{if(this.expanded)return;let e=document.createElement(`div`);e.className=`scoop-fixed-tooltip`,e.textContent=f,document.body.appendChild(e);let t=d.getBoundingClientRect();e.style.top=`${t.top+t.height/2}px`,e.style.left=`${t.right+8}px`,d.__tip=e}),d.addEventListener(`mouseleave`,()=>{let e=d.__tip;e&&(e.remove(),d.__tip=null)}),s.appendChild(d)}this.callbacks.onScoopsChanged?.(e),this.moveEyes()}}selectScoop(e){this.selectedScoopJid=e.jid,this.refreshScoops(),this.callbacks.onScoopSelect(e);let t=new URL(window.location.href);e.isCone?t.searchParams.delete(`scoop`):t.searchParams.set(`scoop`,e.folder),history.replaceState(null,``,t.toString())}selectScoopByFolder(e){if(!this.orchestrator)return;let t=this.orchestrator.getScoops().find(t=>t.folder===e);t&&this.selectScoop(t)}setSelectedJid(e){this.selectedScoopJid=e,this.refreshScoops()}getSelectedScoopJid(){return this.selectedScoopJid}async deleteScoop(e){if(!this.orchestrator)return;let t=this.orchestrator.getScoop(e);if(t){if(t.isCone){alert(`Cannot delete the cone`);return}if(confirm(`Delete scoop "${t.name}"? This cannot be undone.`)){try{await this.orchestrator.unregisterScoop(e)}catch(e){let t=e instanceof Error?e.message:String(e);alert(t);return}this.selectedScoopJid===e&&(this.selectedScoopJid=null),this.refreshScoops(),Li.info(`Scoop deleted`,{jid:e,name:t.name})}}}async createCone(e=`Cone`){if(!this.orchestrator)throw Error(`Orchestrator not set`);let t={jid:`cone_${Date.now()}`,name:e,folder:`cone`,requiresTrigger:!1,isCone:!0,type:`cone`,assistantLabel:`sliccy`,addedAt:new Date().toISOString()};return await this.orchestrator.registerScoop(t),this.refreshScoops(),Li.info(`Cone created`,{jid:t.jid,name:e}),t}render(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);let e=document.createElement(`div`);e.className=`scoops-panel`;let t=document.createElement(`div`);t.className=`scoop-cone-header`,e.appendChild(t);let n=document.createElement(`div`);n.className=`scoops-list`,e.appendChild(n),this.container.appendChild(e);let r=document.createElement(`style`);r.textContent=`
|
|
258
258
|
.scoops-panel {
|
|
259
259
|
display: flex;
|
|
260
260
|
flex-direction: column;
|
|
@@ -1807,7 +1807,7 @@ Examples:
|
|
|
1807
1807
|
`,stderr:``,exitCode:0};if(n){let n=new Map;for(let e of o){let t=e.entry.source.repo,r=n.get(t);r?r.push(e):n.set(t,[e])}let r=o.length,i=0,a=Date.now(),s=``,c=``,l=0,u=await Promise.allSettled(Array.from(n.entries()).map(async([n,o])=>{let[c,l]=n.split(`/`),u=await Q_(c,l,t);if(u.status===`not_found`||u.status===`error`){let e=u.status===`not_found`?`upskill: repository ${n} not found\n`:`upskill: failed to fetch ${n}: ${u.message}\n`,t=[];for(let e of o){i++,((Date.now()-a)/1e3).toFixed(1);let o=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${e.entry.name}" from ${n}: repo fetch failed${o}\n`,t.push({ok:!1,name:e.entry.name,error:`repo fetch failed for ${n}`})}return{errors:e,results:t}}let d=$_(u.files),f=[],p=new Map;for(let e of Object.keys(d))if(e.endsWith(`/SKILL.md`)){let t=e.replace(/\/SKILL\.md$/,``),n=t.split(`/`).pop()||t;p.set(n,t)}for(let t of o){let o=t.entry.source,c,l;if(o.skill){let e=p.get(o.skill);if(e)c=e,l=o.skill;else if(o.path)c=o.path.replace(/^\/|\/$/g,``),l=o.skill;else{let e=`skill "${o.skill}" not found in ${n}`;f.push({ok:!1,name:t.entry.name,error:e}),i++;let c=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${t.entry.name}" from ${n}: ${e}${c}\n`;continue}}else if(o.path)c=o.path.replace(/^\/|\/$/g,``),l=t.entry.name;else{let e=p.get(t.entry.name);if(e)c=e,l=t.entry.name;else{let e=`skill "${t.entry.name}" not found in ${n} and no explicit path provided`;f.push({ok:!1,name:t.entry.name,error:e}),i++;let o=i<r?` (~${Math.round((r-i)*(Date.now()-a)/i/1e3)}s remaining)`:``;s+=`[${i}/${r}] Failed "${t.entry.name}" from ${n}: ${e}${o}\n`;continue}}let u=Date.now(),m=await iv(c,l,d,e,!1);i++;let h=((Date.now()-u)/1e3).toFixed(1),g=(Date.now()-a)/i,_=Math.round((r-i)*g/1e3),v=i<r?` (~${_}s remaining)`:``;m.ok?(f.push({ok:!0,name:l}),s+=`[${i}/${r}] Installed "${l}" from ${n} (${h}s)${v}\n`):(f.push({ok:!1,name:l,error:m.error}),s+=`[${i}/${r}] Failed "${l}" from ${n}: ${m.error}${v}\n`)}return{errors:``,results:f}}));for(let e of u){if(e.status===`rejected`){c+=`upskill: unexpected error: ${e.reason}\n`;continue}e.value.errors&&(c+=e.value.errors);for(let t of e.value.results)t.ok?l++:t.error&&(c+=`upskill: ${t.error}\n`)}let d=((Date.now()-a)/1e3).toFixed(1);return l>0&&(s+=`\nInstalled ${l} recommended skill(s) in ${d}s\n`,await rv()),{stdout:s,stderr:c,exitCode:+!!c}}let s=`Recommended skills for you:
|
|
1808
1808
|
|
|
1809
1809
|
`,c=0;for(let e of o){c++;let t=C_(e.entry.source);s+=` ${c}. ${e.entry.displayName.padEnd(35)} score: ${Math.round(e.score)}\n`,s+=` ${e.entry.description}\n`,s+=` Match: ${e.matchReasons.join(`, `)}\n`,s+=` Install: ${t}\n\n`}return s+=`To install all recommended: upskill recommendations --install
|
|
1810
|
-
`,{stdout:s,stderr:``,exitCode:0}}function lv(e,t){return z(`upskill`,async(n,i)=>{if(n.length===0||n.includes(`--help`)||n.includes(`-h`))return H_();let a=[],o,s=!1,c=!1,l=!1,u=``,d,f=``,p=1,m=0;for(;m<n.length;){let i=n[m];if(i===`search`){let e=n.slice(m+1),t=e.indexOf(`--page`);t>=0&&(p=parseInt(e[t+1],10)||1,e.splice(t,2)),f=e.join(` `);break}else if(i===`recommendations`)return cv(e,t,n.includes(`--install`));else if(i===`list`){let t=await(await r(()=>import(`./skills-
|
|
1810
|
+
`,{stdout:s,stderr:``,exitCode:0}}function lv(e,t){return z(`upskill`,async(n,i)=>{if(n.length===0||n.includes(`--help`)||n.includes(`-h`))return H_();let a=[],o,s=!1,c=!1,l=!1,u=``,d,f=``,p=1,m=0;for(;m<n.length;){let i=n[m];if(i===`search`){let e=n.slice(m+1),t=e.indexOf(`--page`);t>=0&&(p=parseInt(e[t+1],10)||1,e.splice(t,2)),f=e.join(` `);break}else if(i===`recommendations`)return cv(e,t,n.includes(`--install`));else if(i===`list`){let t=await(await r(()=>import(`./skills-CIHtxU5p.js`),__vite__mapDeps([19,20,21,22,4,17]))).discoverSkills(e);return t.length===0?{stdout:`No discoverable local skills found.\n\n${N_()}${P_()}`,stderr:``,exitCode:0}:{stdout:z_(t,`Discoverable local skills`),stderr:``,exitCode:0}}else if(i===`info`||i===`read`){let t=n[m+1];if(!t)return{stdout:``,stderr:`upskill: ${i} requires a skill name\n`,exitCode:1};let a=await r(()=>import(`./skills-CIHtxU5p.js`),__vite__mapDeps([19,20,21,22,4,17]));if(i===`info`){let n=await a.getSkillInfo(e,t);return n?{stdout:B_(n),stderr:``,exitCode:0}:{stdout:``,stderr:`upskill: skill "${t}" not found\n`,exitCode:1}}else{let n=await a.readSkillInstructions(e,t);return n===null?{stdout:``,stderr:`upskill: no SKILL.md found for "${t}"\n`,exitCode:1}:{stdout:n+`
|
|
1811
1811
|
`,stderr:``,exitCode:0}}}else if(i===`--skill`)a.push(n[++m]);else if(i===`--path`||i===`-p`)o=n[++m];else if(i===`--list`)s=!0;else if(i===`--all`)c=!0;else if(i===`--force`)l=!0;else if(i===`--branch`||i===`-b`){let e=n[m+1];if(!e||e.startsWith(`-`))return{stdout:``,stderr:`upskill: --branch requires a value
|
|
1812
1812
|
`,exitCode:1};d=n[++m]}else i.startsWith(`-`)||(u=i);m++}if(f)return q_(f,t,p);if(!u)return H_();let h=nv(u);if(h){let n=i.getRegisteredCommands?.()??[];return J_(h,e,t,l,n)}if(u.startsWith(`tessl:`)){let n=u.slice(6);if(!n)return{stdout:``,stderr:`upskill: tessl: requires a skill name
|
|
1813
1813
|
`,exitCode:1};let r=await Z_(n,t);if(`error`in r)return{stdout:``,stderr:`upskill: ${r.error}\n`,exitCode:1};let i=await k_(t);return tv(r.owner,r.repo,r.skillPath,r.skillName,e,i,l,t)}let g=ov(u);if(g){let{owner:n,repo:r}=g,i=d??g.branch,f=await k_(t),p=await ev(n,r,f,o,t,i);if(p.error)return{stdout:``,stderr:`upskill: failed to list skills: ${p.error}\n`,exitCode:1};if(p.skills.length===0)return{stdout:`No skills found in ${n}/${r}${o?`/`+o:``}\n`,stderr:``,exitCode:0};if(s){let e=`Available skills in ${n}/${r}:\n\n`;for(let t of p.skills)e+=` ${t.name.padEnd(30)} ${t.path}\n`;return e+=`\nFound ${p.skills.length} skill(s)\n`,e+=`\nTo install: upskill ${u} --skill <name>\n`,e+=`To install all: upskill ${u} --all\n`,{stdout:e,stderr:``,exitCode:0}}let m=p.skills;if(a.length>0){m=p.skills.filter(e=>a.includes(e.name));for(let e of a)if(!p.skills.find(t=>t.name===e))return{stdout:``,stderr:`upskill: skill "${e}" not found in ${n}/${r}\n`,exitCode:1}}else if(!c){let e=`Available skills in ${n}/${r}:\n\n`;for(let t of p.skills)e+=` ${t.name.padEnd(30)} ${t.path}\n`;return e+=`\nFound ${p.skills.length} skill(s)\n`,e+=`\nTo install specific skills: upskill ${u} --skill <name>\n`,e+=`To install all: upskill ${u} --all\n`,{stdout:e,stderr:``,exitCode:0}}let h=``,_=``,v=0,y=m.length,b=Date.now();if(y>1){let a=await Q_(n,r,t,i);if(a.status===`not_found`)return{stdout:``,stderr:`upskill: ${i?`branch "${i}" in ${n}/${r}`:`repository ${n}/${r}`} not found\n`,exitCode:1};if(a.status===`error`)return{stdout:``,stderr:`upskill: failed to fetch ${n}/${r}: ${a.message}\n`,exitCode:1};let o=$_(a.files);for(let t=0;t<m.length;t++){let i=m[t],a=await iv(i.path,i.name,o,e,l),s=t+1,c=((Date.now()-b)/1e3).toFixed(1),u=(Date.now()-b)/s,d=Math.round((y-s)*u/1e3),f=s<y?` (~${d}s remaining)`:``;a.ok?(h+=`[${s}/${y}] Installed "${i.name}" from ${n}/${r} (${c}s)${f}\n`,v++):(h+=`[${s}/${y}] Failed "${i.name}": ${a.error}${f}\n`,_+=`upskill: ${a.error}\n`)}}else for(let a of m){let o=await tv(n,r,a.path,a.name,e,f,l,t,i);o.exitCode===0?(h+=o.stdout,v++):_+=o.stderr}let x=((Date.now()-b)/1e3).toFixed(1);return v>0&&(h+=`\nInstalled ${v} skill(s)${y>1?` in ${x}s`:``}\n`,await rv()),{stdout:h,stderr:_,exitCode:+!!_}}return{stdout:``,stderr:`upskill: unrecognized source "${u}"\n\nExpected: owner/repo, clawhub:<slug>, tessl:<name>, or https://clawhub.ai/user/skill\n`,exitCode:1}})}function uv(e){return z(`skill`,async(t,n)=>{if(t.length===0||t.includes(`--help`)||t.includes(`-h`))return{stdout:`usage: skill <command> [options]
|
|
@@ -1831,7 +1831,7 @@ Examples:
|
|
|
1831
1831
|
skill list
|
|
1832
1832
|
skill info bluebubbles
|
|
1833
1833
|
skill read bluebubbles
|
|
1834
|
-
`,stderr:``,exitCode:0};let i=t[0],a=await r(()=>import(`./skills-
|
|
1834
|
+
`,stderr:``,exitCode:0};let i=t[0],a=await r(()=>import(`./skills-CIHtxU5p.js`),__vite__mapDeps([19,20,21,22,4,17]));try{switch(i){case`list`:{let t=await a.discoverSkills(e);return t.length===0?{stdout:`No discoverable skills found.\n\n${N_()}${P_()}\nInstall install-managed skills with: upskill owner/repo --all\n`,stderr:``,exitCode:0}:{stdout:z_(t,`Discoverable skills`),stderr:``,exitCode:0}}case`info`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: info requires a skill name
|
|
1835
1835
|
`,exitCode:1};let r=await a.getSkillInfo(e,n);return r?{stdout:B_(r),stderr:``,exitCode:0}:{stdout:``,stderr:`skill: "${n}" not found\n`,exitCode:1}}case`read`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: read requires a skill name
|
|
1836
1836
|
`,exitCode:1};let r=await a.readSkillInstructions(e,n);return r===null?{stdout:``,stderr:`skill: no SKILL.md found for "${n}"\n`,exitCode:1}:{stdout:r+`
|
|
1837
1837
|
`,stderr:``,exitCode:0}}case`install`:{let n=t[1];if(!n)return{stdout:``,stderr:`skill: install requires a skill name
|
|
@@ -13022,7 +13022,7 @@ The following skills are available. To use a skill, first read its full instruct
|
|
|
13022
13022
|
${e.map(e=>{let t=e.metadata.allowedTools?` Allowed tools: ${e.metadata.allowedTools.join(`, `)}\n`:``;return`- **${e.metadata.name}**: ${e.metadata.description}\n${t} Path: ${e.path}`}).join(`
|
|
13023
13023
|
`)}
|
|
13024
13024
|
---`}async function Hy(e,t=`/workspace/skills`){let n=Fy();for(let[r,i]of Object.entries(n)){let n=r.slice(18),a=n.startsWith(`/workspace/skills`),o=n.startsWith(`/workspace/scripts`);if(!a&&!o)continue;let s=n;a&&t!==`/workspace/skills`&&(s=n.replace(`/workspace/skills`,t)),o&&t!==`/workspace/skills`&&(s=t.replace(`/workspace/skills`,``)+n);try{await e.stat(s)}catch{let t=s.substring(0,s.lastIndexOf(`/`));try{await e.mkdir(t,{recursive:!0})}catch{}await e.writeFile(s,i),jy.info(`Created default file`,{path:s})}}}async function Uy(e){let t=Fy();for(let[n,r]of Object.entries(t)){let t=n.slice(18);if(t.startsWith(`/shared/`))try{await e.stat(t)}catch{let n=t.substring(0,t.lastIndexOf(`/`));try{await e.mkdir(n,{recursive:!0})}catch{}await e.writeFile(t,r),jy.info(`Created default shared file`,{path:t})}}}var Wy=n(`scoop-management-tools`);function Gy(e){let{scoop:t,onSendMessage:n,onFeedScoop:r,getScoops:i,getScoopTabState:a,onScoopScoop:o,onDropScoop:s,onSetGlobalMemory:c,getGlobalMemory:l}=e,u=[];return u.push({name:`send_message`,description:`Send a progress message while still working. Your final output is also sent.`,inputSchema:{type:`object`,properties:{text:{type:`string`,description:`The message text to send`},sender:{type:`string`,description:`Optional sender name/role (e.g., "Researcher"). Defaults to assistant name.`}},required:[`text`]},execute:async e=>{let{text:r,sender:i}=e;return n(r,i),Wy.info(`Message sent`,{scoopFolder:t.folder,textLength:r.length}),{content:`Message sent.`}}}),t.isCone&&r&&u.push({name:`feed_scoop`,description:`Give a scoop a task. Provide a complete, self-contained prompt — the scoop has no access to your conversation. You'll be notified when it finishes.`,inputSchema:{type:`object`,properties:{scoop_name:{type:`string`,description:`The scoop folder name (e.g., "test-scoop"). Use list_scoops to see available scoops.`},prompt:{type:`string`,description:`Complete, self-contained instructions for the scoop. Include ALL context — the scoop cannot see your conversation.`}},required:[`scoop_name`,`prompt`]},execute:async e=>{let{scoop_name:t,prompt:n}=e,a=i().find(e=>e.folder===t||e.name===t);if(!a)return{content:`Scoop "${t}" not found. Available: ${i().filter(e=>!e.isCone).map(e=>e.folder).join(`, `)}`,isError:!0};if(a.isCone)return{content:`Cannot feed the cone (yourself).`,isError:!0};try{return await r(a.jid,n),Wy.info(`Fed scoop`,{target:a.folder,promptLength:n.length}),{content:`Task sent to ${a.folder}. You will be notified when it completes.`}}catch(e){return{content:`Failed to feed scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),t.isCone&&(u.push({name:`list_scoops`,description:`List all registered scoops.`,inputSchema:{type:`object`,properties:{}},execute:async()=>{let e=i();return e.length===0?{content:`No scoops registered.`}:{content:`Registered scoops:\n${e.map(e=>{let t=a?.(e.jid),n=t?.status??`unknown`,r=t?.lastActivity?new Date(t.lastActivity).toLocaleString(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0}):``,i=r?` — ${n} (since ${r})`:` — ${n}`;return e.isCone?`- ${e.assistantLabel} (${e.folder}) [CONE]${i}`:`- ${e.name} (${e.folder})${i}`}).join(`
|
|
13025
|
-
`)}`}}}),o&&u.push({name:`scoop_scoop`,description:`Create a new scoop. Optionally specify a model and/or a prompt. If prompt is provided, the scoop starts working immediately after creation (no separate feed_scoop needed).`,inputSchema:{type:`object`,properties:{name:{type:`string`,description:`Display name for the scoop (e.g., "hero-block")`},model:{type:`string`,description:`Model ID for this scoop (e.g., "claude-sonnet-4-6"). If omitted, uses the same model as the cone.`},prompt:{type:`string`,description:`Task prompt for the scoop. If provided, the scoop starts working immediately after creation.`}},required:[`name`]},execute:async e=>{let{name:t,model:n,prompt:i}=e,a=t.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,50)+`-scoop`;try{let e=await o({name:t,folder:a,trigger:`@${a}`,isCone:!1,type:`scoop`,requiresTrigger:!0,assistantLabel:a,addedAt:new Date().toISOString(),config:n?{modelId:n}:
|
|
13025
|
+
`)}`}}}),o&&u.push({name:`scoop_scoop`,description:`Create a new scoop. Optionally specify a model and/or a prompt. If prompt is provided, the scoop starts working immediately after creation (no separate feed_scoop needed).`,inputSchema:{type:`object`,properties:{name:{type:`string`,description:`Display name for the scoop (e.g., "hero-block")`},model:{type:`string`,description:`Model ID for this scoop (e.g., "claude-sonnet-4-6"). If omitted, uses the same model as the cone.`},prompt:{type:`string`,description:`Task prompt for the scoop. If provided, the scoop starts working immediately after creation.`}},required:[`name`]},execute:async e=>{let{name:t,model:n,prompt:i}=e,a=t.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,50)+`-scoop`;try{let e=await o({name:t,folder:a,trigger:`@${a}`,isCone:!1,type:`scoop`,requiresTrigger:!0,assistantLabel:a,addedAt:new Date().toISOString(),config:{...n?{modelId:n}:{},visiblePaths:[`/workspace/`]},configSchemaVersion:1});if(Wy.info(`Scoop created`,{name:t,folder:a}),i&&r){try{await r(e.jid,i)}catch(e){let n=e instanceof Error?e.message:String(e);return Wy.error(`Auto-feed failed`,{name:t,error:n}),{content:`Scoop "${t}" created as "${a}" but the initial task could not be sent: ${n}. Use feed_scoop to retry.`,isError:!0}}return{content:`Scoop "${t}" created as "${a}" and task sent. It is now working on it.`}}return{content:`Scoop "${t}" created as "${a}". Use feed_scoop to give it a task.`}}catch(e){return{content:`Failed to create scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),s&&u.push({name:`drop_scoop`,description:`Remove a scoop and stop its work. The scoop will be unregistered and its context destroyed.`,inputSchema:{type:`object`,properties:{scoop_name:{type:`string`,description:`The scoop folder name (e.g., "test-scoop"). Use list_scoops to see available scoops.`}},required:[`scoop_name`]},execute:async e=>{let{scoop_name:t}=e,n=i().find(e=>e.folder===t||e.name===t);if(!n)return{content:`Scoop "${t}" not found. Available: ${i().filter(e=>!e.isCone).map(e=>e.folder).join(`, `)}`,isError:!0};if(n.isCone)return{content:`Cannot drop the cone (yourself).`,isError:!0};try{return await s(n.jid),Wy.info(`Scoop dropped`,{name:n.name,folder:n.folder}),{content:`Scoop "${n.name}" (${n.folder}) has been dropped.`}}catch(e){return{content:`Failed to drop scoop: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}}),c&&l&&u.push({name:`update_global_memory`,description:`Update the global CLAUDE.md memory file that is shared across all scoops. Use this instead of write_file for /shared/CLAUDE.md.`,inputSchema:{type:`object`,properties:{content:{type:`string`,description:`The new content for the global memory file`}},required:[`content`]},execute:async e=>{let{content:t}=e;try{return await c(t),Wy.info(`Global memory updated`),{content:`Global memory updated successfully.`}}catch(e){return{content:`Failed to update global memory: ${e instanceof Error?e.message:String(e)}`,isError:!0}}}})),u}var Ky=n(`secret-env`);async function qy(){if(typeof chrome<`u`&&chrome?.runtime?.id)return{};try{let e=await fetch(`/api/secrets/masked`);if(!e.ok)return Ky.warn(`Failed to fetch masked secrets`,{status:e.status}),{};let t=await e.json();if(!Array.isArray(t)||t.length===0)return{};let n={};for(let e of t)e.name&&e.maskedValue&&(n[e.name]=e.maskedValue);return Object.keys(n).length>0&&Ky.info(`Loaded masked secrets into shell env`,{count:Object.keys(n).length}),n}catch(e){return Ky.debug(`Could not fetch masked secrets (server may be unavailable)`,{error:e instanceof Error?e.message:String(e)}),{}}}var Jy=n(`scoop-context`);function Yy(e){return/image exceeds.*maximum/i.test(e)||/Could not process image/i.test(e)||/invalid.*image/i.test(e)||/image.*too (large|big)/i.test(e)}var Xy=class{scoop;callbacks;fs=null;shell=null;agent=null;status=`initializing`;isProcessing=!1;disposed=!1;didStreamDeltas=!1;unsubscribe=null;sessionStore=null;sessionId;sessionCreatedAt=0;isRecovering=!1;skillsFs=null;skillsDir=`/workspace/skills`;constructor(e,t,n,r,i){this.scoop=e,this.callbacks=t,this.fs=n,this.sessionStore=r??null,this.skillsFs=i??null,this.sessionId=e.jid}async init(){this.setStatus(`initializing`);try{if(!this.fs)throw Error(`Filesystem not provided`);Jy.info(`Filesystem ready`,{folder:this.scoop.folder}),await this.ensureDirectoryStructure();let e=this.scoop.isCone?`/`:`/scoops/${this.scoop.folder}/workspace`,t=this.callbacks.getBrowserAPI();this.skillsDir=`/workspace/skills`,this.scoop.isCone&&await Hy(this.fs,this.skillsDir);let n=this.skillsFs??this.fs,r=await qy();this.shell=new Xv({fs:this.fs,cwd:e,env:Object.keys(r).length>0?r:void 0,browserAPI:t,jshDiscoveryFs:this.skillsFs?n:void 0}),Jy.info(`WasmShell initialized`,{folder:this.scoop.folder});let i=await Ry(n,this.skillsDir),a=Gy({scoop:this.scoop,onSendMessage:this.callbacks.onSendMessage,getScoops:this.callbacks.getScoops,getScoopTabState:this.callbacks.getScoopTabState,onFeedScoop:this.callbacks.onFeedScoop,onScoopScoop:this.callbacks.onScoopScoop,onDropScoop:this.callbacks.onDropScoop,onSetGlobalMemory:this.callbacks.setGlobalMemory,getGlobalMemory:this.callbacks.getGlobalMemory}),o=ee([...Qv(this.fs),oy(this.shell),...a]),s=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`,c=``;try{let e=await this.fs.readFile(s,{encoding:`utf-8`});c=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}let l=await this.callbacks.getGlobalMemory();if(l)try{this.scoop.isCone&&await(`getUnderlyingFS`in this.fs?this.fs.getUnderlyingFS():this.fs).writeFile(`/shared/CLAUDE.md`,l)}catch{}if(!T()){let e=ne();throw Error(`No API key configured for provider "${e}"`)}let u=this.scoop.config?.modelId?ie(this.scoop.config.modelId):w(),d=this.scoop.isCone?`Cone`:`Scoop "${this.scoop.name}"`;console.log(`[model] ${d} using model: ${u.id} (provider: ${u.provider})`);let f=this.buildSystemPrompt(l,c,i),p=[];if(this.sessionStore)try{let e=await this.sessionStore.load(this.sessionId);e&&(p=e.messages,this.sessionCreatedAt=e.createdAt,Jy.info(`Restored agent session`,{folder:this.scoop.folder,messageCount:p.length}))}catch(e){Jy.error(`Failed to restore agent session`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.callbacks.onError(`Conversation history could not be restored. Starting fresh.`)}let m=S({model:u,getApiKey:()=>T()??void 0});if(this.disposed)return;this.agent=new D({initialState:{model:u,tools:o,systemPrompt:f,messages:p},getApiKey:()=>T()??void 0,transformContext:m}),this.unsubscribe=this.agent.subscribe(e=>this.handleAgentEvent(e)),this.setStatus(`ready`),Jy.info(`ScoopContext initialized`,{folder:this.scoop.folder,toolCount:o.length})}catch(e){if(this.disposed)return;let t=e instanceof Error?e.message:String(e);Jy.error(`ScoopContext init failed`,{folder:this.scoop.folder,error:t}),this.setStatus(`error`),this.callbacks.onError(`Failed to initialize: ${t}`)}}async prompt(e){if(!this.agent){this.callbacks.onError(`Agent not initialized`);return}let t=this.agent.state?.isStreaming??!1;if(this.isProcessing||t){Jy.info(`Queueing prompt via followUp while processing`,{folder:this.scoop.folder,isProcessing:this.isProcessing,agentIsStreaming:t}),this.agent.followUp({role:`user`,content:[{type:`text`,text:e}],timestamp:Date.now()});return}this.isProcessing=!0,this.didStreamDeltas=!1,this.setStatus(`processing`);try{await this.agent.prompt(e)}catch(e){if(!this.disposed){let t=e instanceof Error?e.message:String(e);Jy.error(`Agent error`,{folder:this.scoop.folder,error:t}),this.callbacks.onError(t)}}finally{this.isProcessing=!1,this.setStatus(`ready`)}}stop(){this.agent?.clearAllQueues?.(),this.agent?.abort?.(),this.isProcessing=!1,this.setStatus(`ready`)}clearMessages(){this.agent&&(this.agent.state.messages=[])}getAgentMessages(){return this.agent?.state?.messages?structuredClone(this.agent.state.messages):[]}getSessionId(){return this.sessionId}getFS(){return this.fs}getShell(){return this.shell}updateModel(){if(!this.agent)return;let e=w();this.agent.state.model=e,Jy.info(`Model updated on running agent`,{folder:this.scoop.folder,model:e.id})}async reloadSkills(){if(!this.agent)return;let e=await Ry(this.skillsFs??this.fs,this.skillsDir),t=``,n=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`;try{let e=await this.fs.readFile(n,{encoding:`utf-8`});t=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}let r=await this.callbacks.getGlobalMemory(),i=this.buildSystemPrompt(r,t,e);this.agent.state.systemPrompt=i,Jy.info(`Skills reloaded`,{folder:this.scoop.folder,skillCount:e.length})}dispose(){this.disposed=!0,this.agent?.clearAllQueues?.(),this.agent?.abort?.(),this.unsubscribe?.(),this.shell?.dispose(),this.agent=null,this.shell=null,this.fs=null}setStatus(e){this.disposed||(this.status=e,this.callbacks.onStatusChange(e))}handleAgentEvent(e){if(!this.disposed)switch(e.type){case`message_update`:{let t=e.assistantMessageEvent;t.type===`text_delta`&&(this.didStreamDeltas=!0,this.callbacks.onResponse(t.delta,!0));break}case`tool_execution_start`:this.callbacks.onToolStart?.(e.toolName,e.args);break;case`tool_execution_update`:{let t=e.partialResult;for(let n of t?.content??[])n.type===`tool_ui`&&n.requestId&&n.html?this.callbacks.onToolUI?.(e.toolName,n.requestId,n.html):n.type===`tool_ui_done`&&n.requestId&&this.callbacks.onToolUIDone?.(n.requestId);break}case`tool_execution_end`:{let t=e.result,n=[];for(let e of t?.content??[])e.type===`text`&&e.text&&n.push(e.text),e.type===`image`&&e.data&&e.mimeType&&n.push(`<img:data:${e.mimeType};base64,${e.data}>`);this.callbacks.onToolEnd?.(e.toolName,n.join(`
|
|
13026
13026
|
`),e.isError);break}case`message_end`:if(e.message.role===`assistant`){let t=e.message.content.filter(e=>e.type===`text`).map(e=>e.text).join(``);t&&!this.didStreamDeltas&&this.callbacks.onResponse(t,!1)}break;case`turn_end`:this.callbacks.onResponseDone();break;case`agent_end`:{let t=e.messages;if(t.length>0){let e=t[t.length-1];if(e.role===`assistant`&&e.errorMessage){let n=e.errorMessage;if(!this.isRecovering&&Yy(n)){this.recoverFromImageError(t);break}if(!this.isRecovering&&x(e)){this.recoverFromOverflow(t);break}this.isRecovering=!1,this.callbacks.onError(n)}else this.isRecovering=!1}let n=this.agent?.state?.messages??e.messages;this.sessionStore&&n.length>0&&this.sessionStore.save({id:this.sessionId,messages:n,config:{},createdAt:this.sessionCreatedAt||Date.now(),updatedAt:Date.now()}).catch(e=>{Jy.error(`Failed to save agent session`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)})});break}}}recoverFromOverflow(e){if(this.agent){Jy.warn(`Context overflow detected, attempting recovery`,{folder:this.scoop.folder,messageCount:e.length}),this.isRecovering=`overflow`,this.callbacks.onResponse(`Context window exceeded — recovering by trimming oversized messages...`,!1);try{let t=e.slice(0,-1),n=0;for(let e=t.length-1;e>=0&&n<5;e--){let r=t[e];if(!Array.isArray(r.content))continue;let i=0;for(let e of r.content)e.type===`text`&&e.text&&(i+=e.text.length),e.type===`image`&&e.data&&(i+=e.data.length);if(i>4e4){let a={type:`text`,text:`[Content removed: ${r.role===`toolResult`?`tool result`:r.role} was too large for context window (${Math.round(i/1e3)}K chars). The operation completed but output could not be retained.]`};if(r.role===`assistant`){let n=r.content.filter(e=>e.type===`toolCall`);t[e]={...r,content:[a,...n]}}else t[e]={...r,content:[a]};n++,Jy.info(`Replaced oversized message`,{index:e,role:r.role,size:i,preservedToolCalls:r.role===`assistant`?r.content.filter(e=>e.type===`toolCall`).length:0})}}this.agent.state.messages=t;let r=n>0?`[System: Context overflow recovered. ${n} oversized message(s) were replaced with placeholders to fit within the context window. The conversation continues — you may need to re-read files or re-run commands if their output was removed.]`:`[System: Context overflow recovered. Older messages were trimmed. The conversation continues — compaction will summarize history on the next turn.]`;this.agent.prompt(r).catch(e=>{Jy.error(`Recovery re-prompt failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Context overflow recovery failed: ${e instanceof Error?e.message:String(e)}`)})}catch(e){Jy.error(`Recovery failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Context overflow recovery failed: ${e instanceof Error?e.message:String(e)}`)}}}recoverFromImageError(e){if(this.agent){Jy.warn(`Image processing error detected, attempting recovery`,{folder:this.scoop.folder,messageCount:e.length}),this.isRecovering=`image`,this.callbacks.onResponse(`Image rejected by API — removing problematic images and continuing...`,!1);try{let t=e.slice(0,-1),n=0,r=Math.max(0,t.length-10);for(let e=t.length-1;e>=r;e--){let r=t[e];if(!Array.isArray(r.content)||!r.content.some(e=>e.type===`image`))continue;let i=r.content.filter(e=>e.type!==`image`);i.length===0?t[e]={...r,content:[{type:`text`,text:`[Image removed: rejected by API]`}]}:t[e]={...r,content:i},n++}this.agent.state.messages=t;let i=`[System: An image was rejected by the API and has been removed from the conversation (${n} message(s) affected). The conversation continues without the image.]`;this.agent.prompt(i).catch(e=>{Jy.error(`Image recovery re-prompt failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Image error recovery failed: ${e instanceof Error?e.message:String(e)}`)})}catch(e){Jy.error(`Image recovery failed`,{folder:this.scoop.folder,error:e instanceof Error?e.message:String(e)}),this.isRecovering=!1,this.callbacks.onError(`Image error recovery failed: ${e instanceof Error?e.message:String(e)}`)}}}async ensureDirectoryStructure(){if(!this.fs)return;let e=this.scoop.isCone?[`/workspace`,`/shared`,`/scoops`,`/home`,`/tmp`,`/mnt`]:[`/scoops/${this.scoop.folder}`,`/scoops/${this.scoop.folder}/workspace`,`/scoops/${this.scoop.folder}/home`,`/scoops/${this.scoop.folder}/tmp`,`/shared`];for(let t of e)try{await this.fs.mkdir(t,{recursive:!0})}catch{}let t=this.scoop.isCone?`/workspace/CLAUDE.md`:`/scoops/${this.scoop.folder}/CLAUDE.md`;try{await this.fs.readFile(t)}catch{let e=`# ${this.scoop.assistantLabel} Memory
|
|
13027
13027
|
|
|
13028
13028
|
${this.scoop.isCone?`Role: Cone (main orchestrator)`:`Scoop: ${this.scoop.name}`}
|
|
@@ -13103,11 +13103,11 @@ ${e}
|
|
|
13103
13103
|
${this.scoop.isCone?`CONE`:`SCOOP`} MEMORY (${this.scoop.name}):
|
|
13104
13104
|
${t}
|
|
13105
13105
|
---`);let a=Vy(n);return a&&(i+=a),i}},Zy=n(`scheduler`),Qy=class{callbacks;pollInterval=null;running=!1;constructor(e){this.callbacks=e}start(){this.running||(this.running=!0,this.pollInterval=window.setInterval(()=>this.checkTasks(),6e4),this.checkTasks(),Zy.info(`Scheduler started`))}stop(){this.pollInterval&&=(clearInterval(this.pollInterval),null),this.running=!1,Zy.info(`Scheduler stopped`)}async createTask(e,t,n,r){let i={id:`task-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,groupFolder:e,prompt:t,scheduleType:n,scheduleValue:r,status:`active`,nextRun:this.calculateNextRun(n,r),lastRun:null,createdAt:new Date().toISOString()};return await He(i),Zy.info(`Task created`,{id:i.id,groupFolder:e,scheduleType:n}),i}async updateTask(e,t){let n=await Ne(e);if(!n)return null;let r={...n,...t};return(t.scheduleType||t.scheduleValue)&&(r.nextRun=this.calculateNextRun(r.scheduleType,r.scheduleValue)),await He(r),Zy.info(`Task updated`,{id:e,updates:Object.keys(t)}),r}async pauseTask(e){return await this.updateTask(e,{status:`paused`})!==null}async resumeTask(e){return await Ne(e)?(await this.updateTask(e,{status:`active`}),!0):!1}async deleteTask(e){return await Ne(e)?(await we(e),Zy.info(`Task deleted`,{id:e}),!0):!1}async getTasksByScoop(e){return(await Me()).filter(t=>t.groupFolder===e)}async getAllTasks(){return Me()}async checkTasks(){let e=await Me(),t=new Date;for(let n of e)n.status===`active`&&n.nextRun&&(new Date(n.nextRun)>t||await this.runTask(n))}async runTask(e){let t=this.callbacks.getScoop(e.groupFolder);if(!t){Zy.warn(`Task scoop not found`,{taskId:e.id,groupFolder:e.groupFolder});return}Zy.info(`Running task`,{id:e.id,groupFolder:e.groupFolder});try{let n=new Date().toISOString(),r=this.calculateNextRun(e.scheduleType,e.scheduleValue),i=e.scheduleType===`once`?`completed`:e.status;await He({...e,lastRun:n,nextRun:r,status:i}),await this.callbacks.onTaskRun(e,t),Zy.info(`Task completed`,{id:e.id})}catch(t){Zy.error(`Task execution failed`,{id:e.id,error:t instanceof Error?t.message:String(t)})}}calculateNextRun(e,t){let n=new Date;switch(e){case`cron`:return this.getNextCronTime(t,n)?.toISOString()??null;case`interval`:{let e=parseInt(t,10);return isNaN(e)||e<=0?null:new Date(n.getTime()+e).toISOString()}case`once`:return new Date(t)>n?t:null;default:return null}}getNextCronTime(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=new Date(t);c.setSeconds(0),c.setMilliseconds(0),c.setMinutes(c.getMinutes()+1);for(let e=0;e<527040;e++){if(this.cronMatches(c,r,i,a,o,s))return c;c.setMinutes(c.getMinutes()+1)}return null}cronMatches(e,t,n,r,i,a){return this.cronFieldMatches(e.getMinutes(),t)&&this.cronFieldMatches(e.getHours(),n)&&this.cronFieldMatches(e.getDate(),r)&&this.cronFieldMatches(e.getMonth()+1,i)&&this.cronFieldMatches(e.getDay(),a)}cronFieldMatches(e,t){if(t===`*`)return!0;if(t.includes(`,`))return t.split(`,`).some(t=>this.cronFieldMatches(e,t.trim()));if(t.includes(`-`)){let[n,r]=t.split(`-`).map(e=>parseInt(e,10));return e>=n&&e<=r}if(t.includes(`/`)){let[n,r]=t.split(`/`),i=parseInt(r,10);if(n===`*`)return e%i===0;let a=parseInt(n,10);return e>=a&&(e-a)%i===0}return parseInt(t,10)===e}},$y=n(`lick-manager`),eb=class{webhooks=new Map;crontasks=new Map;cronInterval=null;eventHandler=null;async init(){await Ae();let e=await Be();for(let t of e)this.webhooks.set(t.id,t);$y.info(`Loaded webhooks`,{count:this.webhooks.size});let t=await Re();for(let e of t)this.crontasks.set(e.id,e);$y.info(`Loaded crontasks`,{count:this.crontasks.size}),this.cronInterval=setInterval(()=>this.runCronScheduler(),6e4),$y.info(`Cron scheduler started`)}dispose(){this.cronInterval&&=(clearInterval(this.cronInterval),null)}setEventHandler(e){this.eventHandler=e}emitEvent(e){$y.info(`External lick event`,{type:e.type,target:e.targetScoop}),this.eventHandler?.(e)}async createWebhook(e,t,n){let r=this.generateId(),i={id:r,name:e,createdAt:new Date().toISOString(),filter:n,scoop:t};return n&&this.compileFilter(n,!0),this.webhooks.set(r,i),await Te(i),$y.info(`Webhook created`,{id:r,name:e,scoop:t}),i}async deleteWebhook(e){return this.webhooks.has(e)?(this.webhooks.delete(e),await Fe(e),$y.info(`Webhook deleted`,{id:e}),!0):!1}listWebhooks(){return Array.from(this.webhooks.values())}getWebhook(e){return this.webhooks.get(e)}handleWebhookEvent(e,t,n){let r=this.webhooks.get(e);if(!r){$y.warn(`Webhook not found`,{webhookId:e});return}let i={type:`webhook`,webhookId:e,webhookName:r.name,targetScoop:r.scoop,timestamp:new Date().toISOString(),headers:t,body:n};if(r.filter)try{let t=this.compileFilter(r.filter,!0)(i);if(t===!1){$y.debug(`Webhook event dropped by filter`,{webhookId:e,name:r.name});return}typeof t==`object`&&t&&(i=t)}catch(t){$y.error(`Webhook filter error`,{webhookId:e,error:t instanceof Error?t.message:String(t)})}$y.info(`Webhook event received`,{webhookId:e,name:r.name,targetScoop:r.scoop}),this.eventHandler?.(i)}async createCronTask(e,t,n,r){let i=this.getNextCronTime(t,new Date);if(!i)throw Error(`Invalid cron expression`);r&&this.compileFilter(r,!1);let a=this.generateId(),o={id:a,name:e,cron:t,scoop:n,filter:r,nextRun:i.toISOString(),lastRun:null,status:`active`,createdAt:new Date().toISOString()};return this.crontasks.set(a,o),await ke(o),$y.info(`Cron task created`,{id:a,name:e,cron:t,scoop:n}),o}async deleteCronTask(e){return this.crontasks.has(e)?(this.crontasks.delete(e),await Pe(e),$y.info(`Cron task deleted`,{id:e}),!0):!1}listCronTasks(){return Array.from(this.crontasks.values())}getCronTask(e){return this.crontasks.get(e)}getLicksForScoop(e,t){let n=n=>n===e||n===t||`${n}-scoop`===t;return{webhooks:Array.from(this.webhooks.values()).filter(e=>n(e.scoop)),cronTasks:Array.from(this.crontasks.values()).filter(e=>n(e.scoop))}}async runCronScheduler(){let e=new Date;for(let t of this.crontasks.values()){if(t.status!==`active`||!t.nextRun||new Date(t.nextRun)>e)continue;let n={time:e.toISOString()};if(t.filter)try{let r=this.compileFilter(t.filter,!1)(null);if(r===!1){$y.debug(`Cron task skipped by filter`,{id:t.id,name:t.name}),t.nextRun=this.getNextCronTime(t.cron,e)?.toISOString()??null,t.lastRun=e.toISOString(),await ke(t);continue}typeof r==`object`&&r&&(n=r)}catch(e){$y.error(`Cron filter error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}let r={type:`cron`,cronId:t.id,cronName:t.name,targetScoop:t.scoop,timestamp:e.toISOString(),body:n};$y.info(`Cron task running`,{id:t.id,name:t.name}),this.eventHandler?.(r),t.nextRun=this.getNextCronTime(t.cron,e)?.toISOString()??null,t.lastRun=e.toISOString(),await ke(t)}}generateId(){let e=``;for(let t=0;t<12;t++)e+=`abcdefghijklmnopqrstuvwxyz0123456789`[Math.floor(Math.random()*36)];return e}compileFilter(e,t){try{return t?Function(`event`,`return (${e})(event);`):Function(`return (${e})();`)}catch(e){throw Error(`Invalid filter function: ${e instanceof Error?e.message:String(e)}`)}}getNextCronTime(e,t){let n=e.trim().split(/\s+/);if(n.length!==5)return null;let[r,i,a,o,s]=n,c=new Date(t);c.setSeconds(0),c.setMilliseconds(0),c.setMinutes(c.getMinutes()+1);let l=(e,t)=>{if(t===`*`)return!0;if(t.includes(`,`))return t.split(`,`).some(t=>l(e,t.trim()));if(t.includes(`-`)){let[n,r]=t.split(`-`).map(e=>parseInt(e,10));return e>=n&&e<=r}if(t.includes(`/`)){let[n,r]=t.split(`/`),i=parseInt(r,10);if(n===`*`)return e%i===0;let a=parseInt(n,10);return e>=a&&(e-a)%i===0}return parseInt(t,10)===e};for(let e=0;e<527040;e++){if(l(c.getMinutes(),r)&&l(c.getHours(),i)&&l(c.getDate(),a)&&l(c.getMonth()+1,o)&&l(c.getDay(),s))return c;c.setMinutes(c.getMinutes()+1)}return null}};function tb(e,t,n){if(t.length===0&&n.length===0)return null;let r=[];t.length>0&&r.push(`${t.length} active webhook${t.length>1?`s`:``}`),n.length>0&&r.push(`${n.length} active cron task${n.length>1?`s`:``}`);let i=[...t.map(e=>` webhook delete ${e.id}`),...n.map(e=>` crontask delete ${e.id}`)].join(`
|
|
13106
|
-
`);return Error(`Cannot remove scoop '${e}': it has ${r.join(` and `)}. Unregister them first:\n${i}`)}var nb=null;function rb(){return nb||=new eb,nb}var Q=n(`orchestrator`),ib=120*1e3,ab=class{scoops=new Map;tabs=new Map;contexts=new Map;messageQueues=new Map;lastAgentTimestamp=new Map;container;callbacks;config;pollInterval=null;scheduler=null;globalMemoryCache=``;sharedFs=null;scoopResponseBuffer=new Map;lickManager=null;sessionStore=null;fsWatcher=null;idleTimers=new Map;droppedScoopCosts=[];constructor(e,t,n={name:`sliccy`,triggerPattern:/^@sliccy\b/i}){this.container=e,this.callbacks=t,this.config=n}async init(){await Ae(),this.sharedFs=await F.create({dbName:`slicc-fs`}),this.sessionStore=new y,this.fsWatcher=new ce,this.sharedFs.setWatcher(this.fsWatcher),globalThis.__slicc_fs_watcher=this.fsWatcher,await this.ensureRootStructure();let e=await Ee();for(let t of Object.values(e)){t.isCone&&(t.trigger=void 0,t.requiresTrigger=!1,t.assistantLabel=t.assistantLabel||`sliccy`),this.scoops.set(t.jid,t),this.messageQueues.set(t.jid,[]);let e=await Ie(`lastAgentTs_${t.jid}`);e&&this.lastAgentTimestamp.set(t.jid,e)}await this.ensureGlobalMemory(),this.scheduler=new Qy({onTaskRun:async(e,t)=>{Q.info(`Running scheduled task`,{taskId:e.id,scoop:t.name}),await this.sendPrompt(t.jid,`[SCHEDULED TASK]\n\n${e.prompt}`,`scheduler`,`Scheduled Task`)},getScoop:e=>{for(let t of this.scoops.values())if(t.folder===e)return t}}),this.scheduler.start(),Q.info(`Orchestrator initialized`,{scoopCount:this.scoops.size});for(let e of this.scoops.values())await this.createScoopTab(e.jid);Ke(()=>this.getSessionCosts()),this.startMessageLoop()}async ensureRootStructure(){if(this.sharedFs)for(let e of[`/workspace`,`/shared`,`/scoops`,`/home`,`/tmp`,`/mnt`])try{await this.sharedFs.mkdir(e,{recursive:!0})}catch{}}async ensureGlobalMemory(){if(this.sharedFs){await Uy(this.sharedFs);try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{Q.warn(`Global memory file not found after creating defaults`)}}}async getGlobalMemory(){if(this.globalMemoryCache)return this.globalMemoryCache;if(this.sharedFs)try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}return this.globalMemoryCache}async setGlobalMemory(e){this.sharedFs&&(await this.sharedFs.writeFile(`/shared/CLAUDE.md`,e),this.globalMemoryCache=e,Q.info(`Global memory updated`))}getSharedFS(){return this.sharedFs}setLickManager(e){this.lickManager=e,globalThis.__slicc_lick_handler=e=>{this.lickManager?.emitEvent(e)}}async registerScoop(e){await Ve(e),this.scoops.set(e.jid,e),this.messageQueues.set(e.jid,[]),Q.info(`Scoop registered`,{jid:e.jid,name:e.name})
|
|
13106
|
+
`);return Error(`Cannot remove scoop '${e}': it has ${r.join(` and `)}. Unregister them first:\n${i}`)}var nb=null;function rb(){return nb||=new eb,nb}var Q=n(`orchestrator`),ib=120*1e3,ab=class{scoops=new Map;tabs=new Map;contexts=new Map;messageQueues=new Map;lastAgentTimestamp=new Map;container;callbacks;config;pollInterval=null;scheduler=null;globalMemoryCache=``;sharedFs=null;scoopResponseBuffer=new Map;lickManager=null;sessionStore=null;fsWatcher=null;idleTimers=new Map;droppedScoopCosts=[];constructor(e,t,n={name:`sliccy`,triggerPattern:/^@sliccy\b/i}){this.container=e,this.callbacks=t,this.config=n}async init(){await Ae(),this.sharedFs=await F.create({dbName:`slicc-fs`}),this.sessionStore=new y,this.fsWatcher=new ce,this.sharedFs.setWatcher(this.fsWatcher),globalThis.__slicc_fs_watcher=this.fsWatcher,await this.ensureRootStructure();let e=await Ee();for(let t of Object.values(e)){t.isCone&&(t.trigger=void 0,t.requiresTrigger=!1,t.assistantLabel=t.assistantLabel||`sliccy`),this.migrateScoopConfig(t),this.scoops.set(t.jid,t),this.messageQueues.set(t.jid,[]);let e=await Ie(`lastAgentTs_${t.jid}`);e&&this.lastAgentTimestamp.set(t.jid,e)}await this.ensureGlobalMemory(),this.scheduler=new Qy({onTaskRun:async(e,t)=>{Q.info(`Running scheduled task`,{taskId:e.id,scoop:t.name}),await this.sendPrompt(t.jid,`[SCHEDULED TASK]\n\n${e.prompt}`,`scheduler`,`Scheduled Task`)},getScoop:e=>{for(let t of this.scoops.values())if(t.folder===e)return t}}),this.scheduler.start(),Q.info(`Orchestrator initialized`,{scoopCount:this.scoops.size});for(let e of this.scoops.values())await this.createScoopTab(e.jid);Ke(()=>this.getSessionCosts()),this.startMessageLoop()}migrateScoopConfig(e){if(e.isCone)return;let t=e.configSchemaVersion??0;t>=1||(t<1&&(e.config={...e.config,visiblePaths:e.config?.visiblePaths??[`/workspace/`]}),e.configSchemaVersion=1)}async ensureRootStructure(){if(this.sharedFs)for(let e of[`/workspace`,`/shared`,`/scoops`,`/home`,`/tmp`,`/mnt`])try{await this.sharedFs.mkdir(e,{recursive:!0})}catch{}}async ensureGlobalMemory(){if(this.sharedFs){await Uy(this.sharedFs);try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{Q.warn(`Global memory file not found after creating defaults`)}}}async getGlobalMemory(){if(this.globalMemoryCache)return this.globalMemoryCache;if(this.sharedFs)try{let e=await this.sharedFs.readFile(`/shared/CLAUDE.md`,{encoding:`utf-8`});this.globalMemoryCache=typeof e==`string`?e:new TextDecoder().decode(e)}catch{}return this.globalMemoryCache}async setGlobalMemory(e){this.sharedFs&&(await this.sharedFs.writeFile(`/shared/CLAUDE.md`,e),this.globalMemoryCache=e,Q.info(`Global memory updated`))}getSharedFS(){return this.sharedFs}setLickManager(e){this.lickManager=e,globalThis.__slicc_lick_handler=e=>{this.lickManager?.emitEvent(e)}}async registerScoop(e){await Ve(e),this.scoops.set(e.jid,e),this.messageQueues.set(e.jid,[]),Q.info(`Scoop registered`,{jid:e.jid,name:e.name});try{await this.createScoopTab(e.jid)}catch(t){throw Q.error(`Scoop init failed`,{jid:e.jid,name:e.name,error:t instanceof Error?t.message:String(t)}),await this.destroyScoopTab(e.jid).catch(()=>{}),this.scoops.delete(e.jid),this.messageQueues.delete(e.jid),await je(e.jid).catch(t=>{Q.warn(`Failed to rollback scoop registration`,{jid:e.jid,name:e.name,error:t instanceof Error?t.message:String(t)})}),t}}async unregisterScoop(e){let t=this.scoops.get(e);if(t&&this.lickManager){let{webhooks:e,cronTasks:n}=this.lickManager.getLicksForScoop(t.name,t.folder),r=tb(t.folder,e,n);if(r)throw r}this.snapshotScoopCost(e),this.clearIdleTimer(e),await this.destroyScoopTab(e),this.sessionStore?.delete(e).catch(t=>{Q.warn(`Failed to delete agent session`,{jid:e,error:t instanceof Error?t.message:String(t)})}),await je(e),this.scoops.delete(e),this.messageQueues.delete(e),this.lastAgentTimestamp.delete(e),this.scoopResponseBuffer.delete(e),Q.info(`Scoop unregistered`,{jid:e})}getScoops(){return Array.from(this.scoops.values())}getScoop(e){return this.scoops.get(e)}async resetFilesystem(){for(let[e,t]of this.contexts.entries())this.clearIdleTimer(e),t.stop(),this.contexts.delete(e);this.sharedFs=await F.create({dbName:`slicc-fs`,wipe:!0}),this.fsWatcher&&this.sharedFs.setWatcher(this.fsWatcher),await this.ensureRootStructure(),await this.ensureGlobalMemory(),await Hy(this.sharedFs).catch(e=>{Q.warn(`Failed to re-seed default skills`,{error:e instanceof Error?e.message:String(e)})}),this.droppedScoopCosts=[],Q.info(`Filesystem reset and defaults re-seeded`)}async clearAllMessages(){await ze(),this.sessionStore&&await this.sessionStore.clearAll().catch(e=>{Q.warn(`Failed to clear agent sessions`,{error:e instanceof Error?e.message:String(e)})});for(let e of this.contexts.values())e.clearMessages();this.lastAgentTimestamp.clear();for(let e of this.scoops.keys())this.messageQueues.set(e,[]);this.droppedScoopCosts=[],Q.info(`All messages cleared`)}async handleMessage(e){Q.info(`handleMessage`,{id:e.id,chatJid:e.chatJid,sender:e.senderName,channel:e.channel,contentPreview:e.content.slice(0,80)});let t=this.scoops.get(e.chatJid);Rv(t?.isCone?`cone`:t?.name??`unknown`,localStorage.getItem(`selected-model`)??`unknown`),await Ce(e),await this.routeToScoop(e)}async delegateToScoop(e,t,n){let r=this.scoops.get(e);if(!r)throw Error(`Scoop not found: ${e}`);let i={id:`delegate-${Date.now()}-${Math.random().toString(36).slice(2)}`,chatJid:e,senderId:`cone`,senderName:n,content:t,timestamp:new Date().toISOString(),fromAssistant:!0,channel:`delegation`};await Ce(i),this.callbacks.onIncomingMessage?.(e,i),Q.info(`Delegating to scoop`,{scoopJid:e,scoopName:r.name,promptLength:t.length}),this.sendPrompt(e,t,`cone`,n).catch(t=>{let n=t instanceof Error?t.message:String(t);Q.error(`Delegation failed`,{scoopJid:e,error:n}),this.callbacks.onError(e,`Delegation failed: ${n}`)})}async routeToScoop(e){let t=this.scoops.get(e.chatJid);if(!t){Q.info(`routeToScoop: unregistered target`,{chatJid:e.chatJid});return}let n=e.channel===`webhook`||e.channel===`cron`||e.channel===`fswatch`||e.channel===`sprinkle`;if(!t.isCone&&t.requiresTrigger&&t.trigger&&!n&&!e.content.includes(t.trigger)){Q.info(`routeToScoop: trigger not found in content`,{chatJid:e.chatJid,trigger:t.trigger,contentPreview:e.content.slice(0,80)});return}let r=this.messageQueues.get(e.chatJid)??[];r.push(e),this.messageQueues.set(e.chatJid,r);let i=this.tabs.get(e.chatJid);if(Q.debug(`routeToScoop: queued`,{chatJid:e.chatJid,scoopName:t.name,tabStatus:i?.status??`no-tab`,queueLength:r.length}),i?.status===`error`){Q.info(`routeToScoop: tab in error state, retrying init`,{chatJid:e.chatJid});try{await this.createScoopTab(e.chatJid),i=this.tabs.get(e.chatJid)}catch{Q.warn(`routeToScoop: retry init failed`,{chatJid:e.chatJid})}}i?.status===`ready`&&await this.processScoopQueue(e.chatJid)}async createScoopTab(e){let t=this.scoops.get(e);if(!t)throw Error(`Scoop not found: ${e}`);if(this.contexts.has(e))if(this.tabs.get(e)?.status===`error`)Q.info(`Re-creating context after error`,{jid:e}),this.contexts.get(e)?.dispose(),this.contexts.delete(e),this.tabs.delete(e);else{Q.debug(`Context already exists`,{jid:e});return}if(!this.sharedFs)throw Error(`Shared filesystem not initialized`);let n=`scoop-${t.folder}-${Date.now()}`,r=t.isCone?this.sharedFs:new ue(this.sharedFs,[`/scoops/${t.folder}/`,`/shared/`],t.config?.visiblePaths?[...t.config.visiblePaths]:[]),i=new Xy(t,{onResponse:(n,r)=>{if(this.scoops.has(e)&&(this.callbacks.onResponse(e,n,r),!t.isCone))if(r){let t=this.scoopResponseBuffer.get(e)??``;this.scoopResponseBuffer.set(e,t+n)}else this.scoopResponseBuffer.set(e,n)},onResponseDone:()=>{if(!this.scoops.has(e))return;let t=this.tabs.get(e);t&&(t.lastActivity=new Date().toISOString(),this.tabs.set(e,t)),this.callbacks.onResponseDone(e)},onError:t=>{if(!this.scoops.has(e))return;let n=this.tabs.get(e);n&&(n.status=`error`,n.error=t,this.tabs.set(e,n)),this.callbacks.onError(e,t),this.callbacks.onStatusChange(e,`error`)},onStatusChange:n=>{if(!this.scoops.has(e))return;let r=this.tabs.get(e);if(r&&(r.status=n,r.lastActivity=new Date().toISOString(),this.tabs.set(e,r)),this.callbacks.onStatusChange(e,n),n===`ready`&&!t.isCone){let n=this.scoopResponseBuffer.get(e);if(this.scoopResponseBuffer.delete(e),n){let r=Array.from(this.scoops.values()).find(e=>e.isCone);if(r){let i=n.length>2e3?n.slice(0,2e3)+`
|
|
13107
13107
|
... (truncated)`:n,a={id:`scoop-done-${e}-${Date.now()}`,chatJid:r.jid,senderId:t.folder,senderName:t.assistantLabel,content:`[@${t.assistantLabel} completed]:\n${i}`,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-notify`};Q.info(`Routing scoop completion to cone`,{scoop:t.folder,responseLength:n.length}),this.handleMessage(a).catch(e=>{let n=e instanceof Error?e.message:String(e);Q.error(`Failed to route scoop completion to cone`,{scoop:t.folder,error:n}),this.callbacks.onError(r.jid,`Scoop ${t.folder} completed but notification failed: ${n}`)})}}}},onToolStart:(t,n)=>{this.callbacks.onToolStart?.(e,t,n)},onToolEnd:(t,n,r)=>{this.callbacks.onToolEnd?.(e,t,n,r)},onToolUI:(t,n,r)=>{this.callbacks.onToolUI?.(e,t,n,r)},onToolUIDone:t=>{this.callbacks.onToolUIDone?.(e,t)},onSendMessage:(t,n)=>{this.callbacks.onSendMessage(e,`${n?`[${n}] `:``}${t}`)},getScoops:()=>this.getScoops(),getScoopTabState:t.isCone?e=>this.tabs.get(e):void 0,onFeedScoop:t.isCone?(e,n)=>this.delegateToScoop(e,n,t.assistantLabel):void 0,onScoopScoop:t.isCone?async e=>{let t={...e,jid:`scoop_${e.folder}_${Date.now()}`};return await this.registerScoop(t),t}:void 0,onDropScoop:t.isCone?async e=>{await this.unregisterScoop(e)}:void 0,getGlobalMemory:()=>this.getGlobalMemory(),setGlobalMemory:t.isCone?e=>this.setGlobalMemory(e):void 0,getBrowserAPI:()=>this.callbacks.getBrowserAPI()},r,this.sessionStore??void 0,this.sharedFs??void 0);this.contexts.set(e,i),this.tabs.set(e,{jid:e,contextId:n,status:`initializing`,lastActivity:new Date().toISOString()}),await i.init();let a=this.tabs.get(e);a&&a.status===`initializing`&&(a.status=`ready`,this.tabs.set(e,a),this.callbacks.onStatusChange(e,`ready`));let o=this.scoops.get(e);o&&!o.isCone&&this.startIdleTimer(e),Q.info(`Scoop context created`,{jid:e,contextId:n})}async destroyScoopTab(e){this.clearIdleTimer(e);let t=this.contexts.get(e);t&&(t.dispose(),this.contexts.delete(e),this.tabs.delete(e),Q.info(`Scoop context destroyed`,{jid:e}))}isProcessing(e){return this.tabs.get(e)?.status===`processing`}getScoopContext(e){return this.contexts.get(e)}async clearQueuedMessages(e){let t=this.messageQueues.get(e);if(t&&t.length>0){for(let e of t)await Le(e.id);this.messageQueues.set(e,[])}}async deleteQueuedMessage(e,t){let n=this.messageQueues.get(e);if(n){let e=n.findIndex(e=>e.id===t);e!==-1&&n.splice(e,1)}await Le(t)}async getMessagesForScoop(e){return De(e)}async waitForTabReady(e,t=1e4){let n=Date.now();for(;Date.now()-n<t;){let t=this.tabs.get(e);if(!t)return!1;if(t.status===`ready`||t.status===`processing`)return!0;if(t.status===`error`)return!1;await new Promise(e=>setTimeout(e,100))}return Q.warn(`Timed out waiting for tab to become ready`,{jid:e}),!1}async sendPrompt(e,t,n,r){let i=this.contexts.get(e);i||=(await this.createScoopTab(e),this.contexts.get(e));let a=this.tabs.get(e);if(a?.status===`initializing`){if(Q.debug(`Context initializing, waiting to send message`,{jid:e}),!await this.waitForTabReady(e)){Q.error(`Context did not become ready in time, dropping prompt`,{jid:e});return}i=this.contexts.get(e),a=this.tabs.get(e)}if(!i){Q.error(`Context not found after creation`,{jid:e});return}this.clearIdleTimer(e),this.scoopResponseBuffer.delete(e),a&&(a.status=`processing`,a.lastActivity=new Date().toISOString(),this.tabs.set(e,a),this.callbacks.onStatusChange(e,`processing`)),Q.debug(`Prompt sent to scoop`,{jid:e,textLength:t.length}),await i.prompt(t)}async processScoopQueue(e){let t=this.messageQueues.get(e);if(!t||t.length===0){Q.debug(`processScoopQueue: empty queue`,{jid:e});return}let n=this.tabs.get(e);if(n?.status!==`ready`){Q.debug(`processScoopQueue: tab not ready`,{jid:e,status:n?.status??`no-tab`});return}let r=this.scoops.get(e),i=r?.assistantLabel??e,a=this.lastAgentTimestamp.get(e)??``,o=await Oe(e,a,i);if(Q.debug(`processScoopQueue: DB query`,{jid:e,scoopName:r?.name,excludeName:i,since:a,dbMessageCount:o.length,queueLength:t.length}),o.length===0){Q.debug(`processScoopQueue: no messages from DB, clearing queue`,{jid:e}),this.messageQueues.set(e,[]);return}let s=o.map(e=>`[${new Date(e.timestamp).toLocaleString(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,hour12:!0})}] ${e.senderName}: ${e.content}`).join(`
|
|
13108
13108
|
`);this.messageQueues.set(e,[]);let c=o[o.length-1];this.lastAgentTimestamp.set(e,c.timestamp),await R(`lastAgentTs_${e}`,c.timestamp),await this.sendPrompt(e,s,c.senderId,c.senderName)}startMessageLoop(){this.pollInterval||=window.setInterval(()=>{for(let e of this.scoops.keys())this.tabs.get(e)?.status===`ready`&&this.processScoopQueue(e).catch(t=>{let n=t instanceof Error?t.message:String(t);Q.error(`Message queue processing failed`,{jid:e,error:n}),this.callbacks.onError(e,`Queue processing failed: ${n}`)})},2e3)}stopMessageLoop(){this.pollInterval&&=(clearInterval(this.pollInterval),null)}updateModel(){for(let e of this.contexts.values())e.updateModel();Q.info(`Model updated on all active contexts`,{contextCount:this.contexts.size})}async reloadAllSkills(){let e=[];for(let[t,n]of this.contexts){let r=this.tabs.get(t);(r?.status===`ready`||r?.status===`processing`)&&e.push(n.reloadSkills().catch(e=>{Q.warn(`Failed to reload skills for scoop`,{jid:t,error:e instanceof Error?e.message:String(e)})}))}await Promise.all(e),Q.info(`Skills reloaded across all contexts`,{count:e.length})}stopScoop(e){let t=this.contexts.get(e);t&&t.stop()}buildScoopCost(e,t){let n=t.getAgentMessages().filter(e=>e.role===`assistant`);if(n.length===0)return null;let r={input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},i=new Map;for(let e of n)r.input+=e.usage.input,r.output+=e.usage.output,r.cacheRead+=e.usage.cacheRead,r.cacheWrite+=e.usage.cacheWrite,r.totalTokens+=e.usage.totalTokens,r.cost.input+=e.usage.cost.input,r.cost.output+=e.usage.cost.output,r.cost.cacheRead+=e.usage.cost.cacheRead,r.cost.cacheWrite+=e.usage.cost.cacheWrite,r.cost.total+=e.usage.cost.total,i.set(e.model,(i.get(e.model)??0)+1);let a=``,o=0;for(let[e,t]of i)t>o&&(a=e,o=t);return{name:e.assistantLabel,type:e.isCone?`cone`:`scoop`,model:a,usage:r,turns:n.length}}snapshotScoopCost(e){let t=this.scoops.get(e),n=this.contexts.get(e);if(!t||!n)return;let r=this.buildScoopCost(t,n);r&&this.droppedScoopCosts.push(r)}getSessionCosts(){let e=[];for(let t of this.scoops.values()){let n=this.contexts.get(t.jid);if(!n)continue;let r=this.buildScoopCost(t,n);r&&e.push(r)}return e.push(...this.droppedScoopCosts),e}startIdleTimer(e){if(this.clearIdleTimer(e),this.tabs.get(e)?.status===`processing`)return;let t=setTimeout(()=>{this.idleTimers.delete(e);let t=this.scoops.get(e);if(!t||t.isCone||this.tabs.get(e)?.status!==`ready`)return;let n=Array.from(this.scoops.values()).find(e=>e.isCone);if(!n)return;let r={id:`scoop-idle-${e}-${Date.now()}`,chatJid:n.jid,senderId:t.folder,senderName:t.assistantLabel,content:`[@${t.assistantLabel} idle]: Scoop "${t.name}" has been ready for 2 minutes without receiving any work. This is expected if the scoop is waiting for webhooks or cron tasks. If you intended to delegate work, use feed_scoop to send a prompt.`,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`scoop-idle`};Q.info(`Scoop idle timeout`,{jid:e,scoop:t.folder}),this.handleMessage(r).catch(t=>{let n=t instanceof Error?t.message:String(t);Q.error(`Failed to send idle notification`,{jid:e,error:n})})},ib);this.idleTimers.set(e,t)}clearIdleTimer(e){let t=this.idleTimers.get(e);t&&(clearTimeout(t),this.idleTimers.delete(e))}async shutdown(){this.stopMessageLoop();for(let e of this.idleTimers.keys())this.clearIdleTimer(e);this.scheduler?.stop(),this.scheduler=null;for(let e of this.contexts.keys())await this.destroyScoopTab(e);Q.info(`Orchestrator shutdown`)}};n(`heartbeat`);var ob=n(`tray-follower`);function sb(e){let t=new URL(e);return t.searchParams.set(`json`,`true`),t.toString()}async function cb(e){let t=sb(e.joinUrl),n=await hb(await(e.fetchImpl??fetch)(t,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({controllerId:e.controllerId,runtime:e.runtime})}));return ob.info(`Follower tray attach response`,{trayId:n.trayId,action:n.result.action,code:n.result.code,participantCount:n.participantCount}),lb(n)}function lb(e){let t={trayId:e.trayId,controllerId:e.controllerId,participantCount:e.participantCount,leader:e.leader,action:e.result.action,code:e.result.code,iceServers:e.iceServers};return e.result.action===`wait`?{...t,retryAfterMs:e.result.retryAfterMs}:e.result.action===`signal`?{...t,bootstrap:e.result.bootstrap}:e.result.action===`fail`?{...t,error:e.result.error}:t}async function ub(e){return mb(await gb(e,{action:`poll`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,cursor:e.cursor}))}async function db(e){return mb(await gb(e,{action:`answer`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,answer:e.answer}))}async function fb(e){return mb(await gb(e,{action:`ice-candidate`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,candidate:e.candidate}))}async function pb(e){return mb(await gb(e,{action:`retry`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,runtime:e.runtime}))}function mb(e){return{trayId:e.trayId,controllerId:e.controllerId,participantCount:e.participantCount,leader:e.leader,bootstrap:e.bootstrap,events:e.events}}async function hb(e){let t=null,n=null;try{t=await e.text(),n=JSON.parse(t)}catch{}if(!_b(n)){let n=t?t.slice(0,200):`(empty)`;throw ob.warn(`Tray follower attach returned an invalid response`,{status:e.status,body:n}),Error(`Tray follower attach returned an invalid response (${e.status}): ${n}`)}return n}async function gb(e,t){let n=sb(e.joinUrl),r=await(e.fetchImpl??fetch)(n,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),i=await r.json().catch(()=>null);if(!vb(i))throw Error(`Tray follower bootstrap returned an invalid response (${r.status})`);return i}function _b(e){if(!e||typeof e!=`object`)return!1;let t=e;if(typeof t.trayId!=`string`||typeof t.controllerId!=`string`||t.role!==`follower`||typeof t.participantCount!=`number`)return!1;let n=t.result;if(!n||typeof n!=`object`)return!1;let r=n;return r.action===`wait`?(r.code===`LEADER_NOT_ELECTED`||r.code===`LEADER_NOT_CONNECTED`)&&typeof r.retryAfterMs==`number`:r.action===`signal`?r.code===`LEADER_CONNECTED`&&yb(r.bootstrap):r.action===`fail`?(r.code===`INVALID_JOIN_CAPABILITY`||r.code===`TRAY_EXPIRED`)&&typeof r.error==`string`:!1}function vb(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.trayId==`string`&&typeof t.controllerId==`string`&&t.role===`follower`&&typeof t.participantCount==`number`&&yb(t.bootstrap)&&Array.isArray(t.events)}function yb(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.controllerId==`string`&&typeof t.bootstrapId==`string`&&typeof t.attempt==`number`&&typeof t.state==`string`&&typeof t.expiresAt==`string`&&typeof t.cursor==`number`&&typeof t.maxRetries==`number`&&typeof t.retriesRemaining==`number`}var bb=n(`tray-webrtc`),xb=`tray-control`,Sb=250,Cb=class{peerConnectionFactory;dataChannelLabel;peers=new Map;iceServers;constructor(e){this.options=e,this.iceServers=e.iceServers,this.peerConnectionFactory=e.peerConnectionFactory??(()=>Eb(this.iceServers)),this.dataChannelLabel=e.dataChannelLabel??xb}setIceServers(e){this.iceServers=e}async handleControlMessage(e){e.type===`follower.join_requested`?(e.iceServers&&!this.iceServers&&(this.iceServers=e.iceServers),await this.handleJoinRequested(e)):e.type===`bootstrap.answer`?await this.peers.get(e.bootstrapId)?.peer.setRemoteDescription(e.answer):e.type===`bootstrap.ice_candidate`&&await this.peers.get(e.bootstrapId)?.peer.addIceCandidate(e.candidate)}getPeers(){return Array.from(this.peers.values()).map(({state:e})=>({...e}))}getChannel(e){return this.peers.get(e)?.channel??null}stop(){for(let e of this.peers.values())e.peer.close();this.peers.clear()}async handleJoinRequested(e){this.closeControllerPeers(e.controllerId);let t=this.peerConnectionFactory(),n={controllerId:e.controllerId,bootstrapId:e.bootstrapId,attempt:e.attempt,state:`connecting`,connectedAt:null,runtime:e.runtime},r=t.createDataChannel(this.dataChannelLabel);this.peers.set(e.bootstrapId,{state:n,peer:t,channel:r}),t.addEventListener(`icecandidate`,({candidate:t})=>{let n=Ob(t);n&&this.options.sendControlMessage({type:`bootstrap.ice_candidate`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,candidate:n})}),t.addEventListener(`connectionstatechange`,()=>{let n=this.peers.get(e.bootstrapId);n&&(n.state.state===`connected`?(t.connectionState===`disconnected`||t.connectionState===`failed`)&&(bb.warn(`Leader peer connection state changed post-connect`,{bootstrapId:e.bootstrapId,state:t.connectionState}),this.options.onPeerDisconnected?.(e.bootstrapId,`Peer connection ${t.connectionState}`)):t.connectionState===`failed`&&this.failPeer(e,`Leader peer connection failed before the data channel opened`))}),r.addEventListener(`open`,()=>{let t=this.peers.get(e.bootstrapId);!t||t.state.state===`connected`||(t.state.state=`connected`,t.state.connectedAt=new Date().toISOString(),this.options.onPeerConnected?.({...t.state},t.channel))}),r.addEventListener(`close`,()=>{let t=this.peers.get(e.bootstrapId);t&&(t.state.state===`connected`?(bb.warn(`Leader data channel closed post-connect`,{bootstrapId:e.bootstrapId}),this.options.onPeerDisconnected?.(e.bootstrapId,`Data channel closed`)):this.failPeer(e,`Leader data channel closed before opening`))}),r.addEventListener(`error`,()=>{let t=this.peers.get(e.bootstrapId);t&&(t.state.state===`connected`?(bb.warn(`Leader data channel error post-connect`,{bootstrapId:e.bootstrapId}),this.options.onPeerDisconnected?.(e.bootstrapId,`Data channel error`)):this.failPeer(e,`Leader data channel failed before opening`))});try{let n=await t.createOffer();await t.setLocalDescription(n),this.options.sendControlMessage({type:`bootstrap.offer`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,offer:Db(t.localDescription??n,`offer`)})}catch(t){this.failPeer(e,t instanceof Error?t.message:String(t))}}closeControllerPeers(e){for(let[t,n]of this.peers.entries())n.state.controllerId===e&&(n.peer.close(),this.peers.delete(t))}failPeer(e,t){let n=this.peers.get(e.bootstrapId);if(n){n.peer.close(),this.peers.delete(e.bootstrapId);try{this.options.sendControlMessage({type:`bootstrap.failed`,controllerId:e.controllerId,bootstrapId:e.bootstrapId,code:`WEBRTC_BOOTSTRAP_FAILED`,message:t,retryable:!0,retryAfterMs:1e3})}catch(e){bb.warn(`Failed to report tray bootstrap failure`,{error:e instanceof Error?e.message:String(e)})}}}},wb=class{fetchImpl;peerConnectionFactory;controllerIdFactory;sleep;pollIntervalMs;iceServers;activePeer=null;stopped=!1;constructor(e){this.options=e,this.fetchImpl=e.fetchImpl??fetch,this.iceServers=e.iceServers,this.peerConnectionFactory=e.peerConnectionFactory??(()=>Eb(this.iceServers)),this.controllerIdFactory=e.controllerIdFactory??(()=>crypto.randomUUID()),this.sleep=e.sleep??(e=>new Promise(t=>setTimeout(t,e))),this.pollIntervalMs=e.pollIntervalMs??Sb}async start(){this.stopped=!1;let e=this.controllerIdFactory(),t=Date.now();p({state:`connecting`,joinUrl:this.options.joinUrl,trayId:null,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:0,lastAttachCode:null,connectingSince:t,lastError:null}),bb.info(`Follower tray join starting`,{joinUrl:this.options.joinUrl});let n=0;for(;;){kb(this.stopped),n++;let t;try{t=await cb({joinUrl:this.options.joinUrl,controllerId:e,runtime:this.options.runtime,fetchImpl:this.fetchImpl})}catch(e){let t=e instanceof Error?e.message:String(e);throw p({...h(),attachAttempts:n,lastError:t}),e}if(p({...h(),attachAttempts:n,lastAttachCode:t.code}),t.action===`wait`){let e=t.retryAfterMs??1e3;bb.info(`Follower tray attach waiting`,{attempt:n,code:t.code,retryAfterMs:e}),n%10==0&&bb.warn(`Follower tray attach still waiting after ${n} attempts`,{attempt:n,code:t.code,retryAfterMs:e}),await this.sleep(e);continue}if(t.action===`fail`||!t.bootstrap){let e=t.error??`Tray follower attach failed (${t.code})`;throw p({state:`error`,joinUrl:this.options.joinUrl,trayId:null,error:e,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:e}),bb.warn(`Follower tray attach failed`,{error:e}),Error(e)}t.iceServers&&(this.iceServers=t.iceServers);try{let r=await this.completeBootstrap(t.trayId,e,t.bootstrap);return p({state:`connected`,joinUrl:this.options.joinUrl,trayId:r.trayId,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:null}),bb.info(`Follower tray connected`,{trayId:r.trayId,controllerId:e}),r}catch(e){let r=e instanceof Error?e.message:String(e);throw p({state:`error`,joinUrl:this.options.joinUrl,trayId:t.trayId,error:r,lastPingTime:null,reconnectAttempts:0,attachAttempts:n,lastAttachCode:t.code,connectingSince:null,lastError:r}),bb.warn(`Follower tray bootstrap failed`,{error:r}),e}}}stop(){this.stopped=!0,this.activePeer?.peer.close(),this.activePeer?.channel?.close(),this.activePeer=null,p({state:`inactive`,joinUrl:null,trayId:null,error:null,lastPingTime:null,reconnectAttempts:0,attachAttempts:0,lastAttachCode:null,connectingSince:null,lastError:null})}async completeBootstrap(e,t,n){let r=n,i=0;for(this.activePeer=this.createFollowerPeer(t,r.bootstrapId);;){if(kb(this.stopped),this.activePeer.open&&this.activePeer.channel)return{trayId:e,controllerId:t,bootstrapId:r.bootstrapId,channel:this.activePeer.channel};if(this.activePeer.openError)throw Error(this.activePeer.openError);let n=await ub({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,cursor:i,fetchImpl:this.fetchImpl});r=n.bootstrap,i=r.cursor;try{for(let e of n.events)if(e.type===`bootstrap.offer`){await this.activePeer.peer.setRemoteDescription(e.offer);let n=await this.activePeer.peer.createAnswer();await this.activePeer.peer.setLocalDescription(n),await db({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,answer:Db(this.activePeer.peer.localDescription??n,`answer`),fetchImpl:this.fetchImpl})}else if(e.type===`bootstrap.ice_candidate`)await this.activePeer.peer.addIceCandidate(e.candidate);else if(e.type===`bootstrap.failed`)throw Error(e.failure.message)}catch(e){if(r.failure?.retryable&&r.retriesRemaining>0){r=(await pb({joinUrl:this.options.joinUrl,controllerId:t,bootstrapId:r.bootstrapId,runtime:this.options.runtime,fetchImpl:this.fetchImpl})).bootstrap,i=0,this.activePeer.peer.close(),this.activePeer=this.createFollowerPeer(t,r.bootstrapId);continue}throw e}this.activePeer.open||await this.sleep(this.pollIntervalMs)}}createFollowerPeer(e,t){let n=this.peerConnectionFactory(),r={peer:n,channel:null,open:!1,openError:null};return n.addEventListener(`connectionstatechange`,()=>{r.open&&(n.connectionState===`disconnected`||n.connectionState===`failed`)&&(bb.warn(`Follower peer connection state changed post-connect`,{bootstrapId:t,state:n.connectionState}),this.options.onDisconnected?.(`Peer connection ${n.connectionState}`))}),n.addEventListener(`datachannel`,({channel:e})=>{r.channel=e,e.addEventListener(`open`,()=>{r.open=!0}),e.addEventListener(`close`,()=>{r.open?(bb.warn(`Follower data channel closed post-connect`,{bootstrapId:t}),this.options.onDisconnected?.(`Data channel closed`)):r.openError=`Follower data channel closed before opening`}),e.addEventListener(`error`,()=>{r.open?(bb.warn(`Follower data channel error post-connect`,{bootstrapId:t}),this.options.onDisconnected?.(`Data channel error`)):r.openError=`Follower data channel failed before opening`})}),n.addEventListener(`icecandidate`,({candidate:n})=>{let r=Ob(n);r&&fb({joinUrl:this.options.joinUrl,controllerId:e,bootstrapId:t,candidate:r,fetchImpl:this.fetchImpl}).catch(e=>{bb.warn(`Failed to send follower ICE candidate`,{error:e instanceof Error?e.message:String(e)})})}),r}};function Tb(e,t){let n=t.baseDelayMs??1e3,r=t.backoffMultiplier??2,i=t.maxDelayMs??3e4,a=t.maxAttempts??10,o=t.sleep??e.sleep??(e=>new Promise(t=>setTimeout(t,e))),s=!1,c=!1,l=null,u={cancel(){s=!0,c=!1,l?.stop(),l=null},get reconnecting(){return c}},d=()=>{let t=new wb({...e,sleep:o,onDisconnected:e=>{s||(bb.warn(`Follower disconnected, starting reconnect loop`,{reason:e}),f(e))}});return l=t,{manager:t,connectionPromise:t.start()}},f=async u=>{if(s||c)return;c=!0,l?.stop(),l=null;let f=0,m=n,g=u??`Unknown disconnect`;for(;!s&&f<a&&(f++,t.onReconnecting?.(f),p({...h(),state:`reconnecting`,error:null,reconnectAttempts:f}),bb.info(`Reconnect attempt`,{attempt:f,delay:m}),await o(m),!s);){let n=null;try{let r=d();n=r.manager;let i=await r.connectionPromise;if(s){n.stop();break}c=!1,p({...h(),state:`connected`,joinUrl:e.joinUrl,trayId:i.trayId,error:null,lastPingTime:null,reconnectAttempts:0,connectingSince:null,lastError:null}),bb.info(`Reconnect successful`,{attempt:f,trayId:i.trayId}),t.onConnected(i);return}catch(e){g=e instanceof Error?e.message:String(e),bb.warn(`Reconnect attempt failed`,{attempt:f,error:g}),n?.stop(),l=null}m=Math.min(m*r,i)}s||(c=!1,p({...h(),state:`error`,error:`Reconnect failed after ${f} attempts: ${g}`,reconnectAttempts:f}),bb.warn(`Reconnect gave up`,{attempts:f,lastError:g}),t.onGaveUp?.(g))},{connectionPromise:m}=d();return m.then(e=>{s||t.onConnected(e)}).catch(e=>{s||bb.warn(`Initial follower connection failed`,{error:e instanceof Error?e.message:String(e)})}),u}function Eb(e){if(typeof RTCPeerConnection>`u`)throw Error(`RTCPeerConnection is not available in this runtime`);let t=e?.length?{iceServers:e}:void 0;return new RTCPeerConnection(t)}function Db(e,t){if(!e||e.type!==t||typeof e.sdp!=`string`)throw Error(`Expected a local ${t} description before signaling`);return{type:e.type,sdp:e.sdp}}function Ob(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.candidate==`string`?{candidate:t.candidate,sdpMid:typeof t.sdpMid==`string`?t.sdpMid:null,sdpMLineIndex:typeof t.sdpMLineIndex==`number`?t.sdpMLineIndex:null,usernameFragment:typeof t.usernameFragment==`string`?t.usernameFragment:null}:null}function kb(e){if(e)throw Error(`Tray follower stopped before WebRTC bootstrap completed`)}var Ab=64*1024;async function jb(e,t){try{switch(t.op){case`readFile`:return await Mb(e,t.path,t.encoding);case`writeFile`:return[await Nb(e,t.path,t.content,t.encoding)];case`stat`:return[await Pb(e,t.path)];case`readDir`:return[await Fb(e,t.path)];case`mkdir`:return[await Ib(e,t.path,t.recursive)];case`rm`:return[await Lb(e,t.path,t.recursive)];case`exists`:return[await Rb(e,t.path)];case`walk`:return[await zb(e,t.path)];default:return[{ok:!1,error:`Unknown fs operation: ${t.op}`}]}}catch(e){return[Vb(e)]}}async function Mb(e,t,n){return(n??`utf-8`)===`utf-8`?Bb(await e.readFile(t,{encoding:`utf-8`}),`utf-8`):Bb(Hb(await e.readFile(t,{encoding:`binary`})),`base64`)}async function Nb(e,t,n,r){if(r===`base64`){let r=Ub(n);await e.writeFile(t,r)}else await e.writeFile(t,n);return{ok:!0,data:{type:`void`}}}async function Pb(e,t){return{ok:!0,data:{type:`stat`,stat:await e.stat(t)}}}async function Fb(e,t){return{ok:!0,data:{type:`dirEntries`,entries:await e.readDir(t)}}}async function Ib(e,t,n){return await e.mkdir(t,{recursive:n}),{ok:!0,data:{type:`void`}}}async function Lb(e,t,n){return await e.rm(t,{recursive:n}),{ok:!0,data:{type:`void`}}}async function Rb(e,t){return{ok:!0,data:{type:`exists`,exists:await e.exists(t)}}}async function zb(e,t){let n=[];for await(let r of e.walk(t))n.push(r);return{ok:!0,data:{type:`paths`,paths:n}}}function Bb(e,t){if(e.length<=Ab)return[{ok:!0,data:{type:`file`,content:e,encoding:t}}];let n=Math.ceil(e.length/Ab),r=[];for(let i=0;i<n;i++){let a=i*Ab,o=e.slice(a,a+Ab);r.push({ok:!0,data:{type:`file`,content:o,encoding:t},chunkIndex:i,totalChunks:n})}return r}function Vb(e){return e instanceof Error&&`code`in e?{ok:!1,error:e.message,code:e.code}:{ok:!1,error:e instanceof Error?e.message:String(e)}}function Hb(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)}function Ub(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}var Wb=class{runtimes=new Map;dirty=!1;setTargets(e,t){this.runtimes.set(e,t),this.dirty=!0}removeRuntime(e){this.runtimes.delete(e)&&(this.dirty=!0)}getEntries(){this.dirty=!1;let e=[];for(let[t,n]of this.runtimes)for(let r of n)e.push({targetId:`${t}:${r.targetId}`,localTargetId:r.targetId,runtimeId:t,title:r.title,url:r.url,isLocal:!1});return e}hasChanged(){return this.dirty}getRuntimeIds(){return[...this.runtimes.keys()]}},Gb=n(`data-channel-keepalive`),Kb=class{sendPing;onDead;intervalMs;maxMissed;timer=null;missedPongs=0;awaitingPong=!1;stopped=!1;constructor(e){this.sendPing=e.sendPing,this.onDead=e.onDead,this.intervalMs=e.intervalMs??1e4,this.maxMissed=e.maxMissed??3}start(){this.timer||this.stopped||(this.timer=setInterval(()=>this.tick(),this.intervalMs))}stop(){this.stopped=!0,this.timer&&=(clearInterval(this.timer),null)}receivePong(){this.awaitingPong=!1,this.missedPongs=0}receivePing(){this.missedPongs=0,this.awaitingPong=!1}get missed(){return this.missedPongs}tick(){if(!this.stopped){if(this.awaitingPong&&(this.missedPongs++,Gb.debug(`Missed pong`,{missedPongs:this.missedPongs,maxMissed:this.maxMissed}),this.missedPongs>=this.maxMissed)){Gb.warn(`Channel declared dead`,{missedPongs:this.missedPongs}),this.stop(),this.onDead();return}this.awaitingPong=!0,this.sendPing()}}},qb=n(`tray-leader-sync`);function Jb(e){return e?e.includes(`standalone`)?`standalone`:e.includes(`extension`)?`extension`:e.includes(`electron`)?`electron`:`unknown`:`unknown`}var Yb=class{followers=new Map;registry=new Wb;runtimeToBootstrap=new Map;pendingCDPRoutes=new Map;cdpChunkBuffers=new Map;remoteTransports=new Map;pendingTabOpenRoutes=new Map;tabOpenResolvers=new Map;pendingFsRoutes=new Map;fsResolvers=new Map;constructor(e){this.options=e}addFollower(e,t,n){this.removeFollower(e);let r=ge(t),i=r.onMessage(t=>{this.handleFollowerMessage(e,t)}),a=new Kb({sendPing:()=>r.send({type:`ping`}),onDead:()=>{qb.warn(`Follower keepalive dead, removing follower`,{bootstrapId:e}),this.removeFollower(e),this.options.onFollowerDead?.(e)}});a.start(),this.followers.set(e,{bootstrapId:e,sync:r,unsubscribe:i,keepalive:a,runtime:n?.runtime,connectedAt:n?.connectedAt,lastActivity:Date.now(),floatType:Jb(n?.runtime)}),qb.info(`Follower added to sync`,{bootstrapId:e,followerCount:this.followers.size}),this.sendSnapshotToFollower(e);let o=this.getConnectedEntries();o.length>0&&r.send({type:`targets.registry`,targets:o})}removeFollower(e){let t=this.followers.get(e);if(t){t.keepalive.stop(),t.unsubscribe(),t.sync.close(),this.followers.delete(e);for(let[t,n]of this.runtimeToBootstrap)if(n===e){this.cleanupRemoteTransports(t),this.registry.removeRuntime(t),this.runtimeToBootstrap.delete(t);break}this.registry.hasChanged()&&this.broadcastTargetRegistry(),qb.info(`Follower removed from sync`,{bootstrapId:e,followerCount:this.followers.size})}}broadcastEvent(e){if(this.followers.size===0)return;let t={type:`agent_event`,event:e,scoopJid:this.options.getScoopJid()};for(let e of this.followers.values())e.sync.send(t)}broadcastUserMessage(e,t){if(this.followers.size===0)return;let n={type:`user_message_echo`,text:e,messageId:t,scoopJid:this.options.getScoopJid()};for(let e of this.followers.values())e.sync.send(n)}broadcastStatus(e){if(this.followers.size===0)return;let t={type:`status`,scoopStatus:e};for(let e of this.followers.values())e.sync.send(t)}sendSnapshotToFollower(e){let t=this.followers.get(e);if(!t)return;let n=this.options.getMessages(),r=this.options.getScoopJid();me(t.sync,n,r),qb.debug(`Snapshot sent to follower`,{bootstrapId:e,messageCount:n.length})}handleFollowerMessage(e,t){switch(t.type){case`user_message`:qb.info(`Follower user message received`,{bootstrapId:e,messageId:t.messageId}),this.options.onFollowerMessage(t.text,t.messageId);break;case`abort`:qb.info(`Follower abort received`,{bootstrapId:e}),this.options.onFollowerAbort();break;case`request_snapshot`:qb.info(`Follower snapshot request received`,{bootstrapId:e}),this.sendSnapshotToFollower(e);break;case`targets.advertise`:qb.info(`Follower targets advertised`,{bootstrapId:e,runtimeId:t.runtimeId,targetCount:t.targets.length});for(let e of[...this.remoteTransports.keys()]){let n=e.substring(0,e.indexOf(`:`));n!==`leader`&&!this.runtimeToBootstrap.has(n)&&n!==t.runtimeId&&(this.remoteTransports.get(e)?.disconnect(),this.remoteTransports.delete(e),qb.debug(`Cleaned up orphaned remote transport on advertise`,{key:e}))}this.runtimeToBootstrap.set(t.runtimeId,e),this.registry.setTargets(t.runtimeId,t.targets),this.broadcastTargetRegistry();break;case`cdp.request`:{let{requestId:n,targetRuntimeId:r,localTargetId:i,method:a,params:o,sessionId:s}=t;r===`leader`?this.executeLocalCDP(n,i,a,o,s,e):this.forwardCDPRequest(n,r,i,a,o,s,e);break}case`cdp.response`:this.handleCDPResponse(t);break;case`cdp.event`:this.handleCDPEvent(e,t.method,t.params,t.sessionId);break;case`tab.open`:{let{requestId:n,targetRuntimeId:r,url:i}=t;r===`leader`?this.executeLocalTabOpen(n,i,e):this.forwardTabOpen(n,r,i,e);break}case`tab.opened`:this.handleTabOpenResponse(t.requestId,t.targetId);break;case`tab.open.error`:this.handleTabOpenError(t.requestId,t.error);break;case`fs.request`:{let{requestId:n,targetRuntimeId:r,request:i}=t;r===`leader`?this.executeLocalFs(n,i,e):this.forwardFsRequest(n,r,i,e);break}case`fs.response`:this.handleFsResponse(t.requestId,t.response);break;case`ping`:{let t=this.followers.get(e);t&&(t.keepalive.receivePing(),t.lastActivity=Date.now(),t.sync.send({type:`pong`}));break}case`pong`:{let t=this.followers.get(e);t&&(t.keepalive.receivePong(),t.lastActivity=Date.now());break}}}setLocalTargets(e){this.registry.setTargets(`leader`,e),this.registry.hasChanged()&&this.broadcastTargetRegistry()}broadcastTargetRegistry(){if(this.followers.size===0)return;let e={type:`targets.registry`,targets:this.getConnectedEntries()};for(let t of this.followers.values())t.sync.send(e)}getTargets(){return this.getConnectedEntries()}getConnectedEntries(){return this.registry.getEntries().filter(e=>{if(e.runtimeId===`leader`)return!0;let t=this.runtimeToBootstrap.get(e.runtimeId);return t?this.followers.has(t):!1})}createRemoteTransport(e,t){let n=new ve({sendCDPRequest:(n,r,i,a)=>{let o=this.runtimeToBootstrap.get(e),s=o?this.followers.get(o):void 0;if(!s){this.remoteTransports.get(`${e}:${t}`)?.handleResponse(n,void 0,`Target runtime "${e}" not connected`);return}this.pendingCDPRoutes.set(n,{requesterBootstrapId:`__leader__`,requestId:n}),s.sync.send({type:`cdp.request`,requestId:n,localTargetId:t,method:r,params:i,sessionId:a})}});return this.remoteTransports.set(`${e}:${t}`,n),n}removeRemoteTransport(e,t){let n=`${e}:${t}`,r=this.remoteTransports.get(n);r&&(r.disconnect(),this.remoteTransports.delete(n))}cleanupRemoteTransports(e){let t=`${e}:`;for(let e of[...this.remoteTransports.keys()])e.startsWith(t)&&(this.remoteTransports.get(e)?.disconnect(),this.remoteTransports.delete(e),qb.debug(`Cleaned up stale remote transport`,{key:e}))}getConnectedFollowers(){return[...this.runtimeToBootstrap.entries()].map(([e,t])=>{let n=this.followers.get(t);return{runtimeId:e,runtime:n?.runtime,connectedAt:n?.connectedAt,lastActivity:n?.lastActivity,floatType:n?.floatType}})}getBestFollowerForTeleport(){let e=[];for(let[t,n]of this.runtimeToBootstrap){let r=this.followers.get(n);r&&e.push({runtimeId:t,bootstrapId:n,floatType:r.floatType,lastActivity:r.lastActivity})}if(e.length===0)return null;let t=e.filter(e=>e.floatType===`standalone`),n=t.length>0?t:e;return n.sort((e,t)=>t.lastActivity-e.lastActivity),n[0]}get hasFollowers(){return this.followers.size>0}stop(){for(let e of[...this.followers.keys()])this.removeFollower(e)}async executeLocalCDP(e,t,n,r,i,a){let o=this.followers.get(a);if(!o)return;let s=this.options.browserTransport;if(!s){o.sync.send({type:`cdp.response`,requestId:e,error:`Leader has no browser transport`});return}try{let t=await s.send(n,r,i);xe(o.sync,e,t)}catch(t){o.sync.send({type:`cdp.response`,requestId:e,error:t instanceof Error?t.message:String(t)})}}forwardCDPRequest(e,t,n,r,i,a,o){let s=this.runtimeToBootstrap.get(t),c=s?this.followers.get(s):void 0,l=this.followers.get(o);if(!c){l&&l.sync.send({type:`cdp.response`,requestId:e,error:`Target runtime "${t}" not connected`});return}this.pendingCDPRoutes.set(e,{requesterBootstrapId:o,requestId:e}),c.sync.send({type:`cdp.request`,requestId:e,localTargetId:n,method:r,params:i,sessionId:a})}handleCDPResponse(e){let{requestId:t,result:n,error:r,chunkData:i,chunkIndex:a,totalChunks:o}=e,s=this.pendingCDPRoutes.get(t);if(!s)return;let c=pe(this.cdpChunkBuffers,e);if(!c)return;if(this.pendingCDPRoutes.delete(t),s.requesterBootstrapId===`__leader__`){for(let e of this.remoteTransports.values())e.handleResponse(t,c.result,c.error);return}let l=this.followers.get(s.requesterBootstrapId);l&&xe(l.sync,t,c.result,c.error)}handleCDPEvent(e,t,n,r){let i;for(let[t,n]of this.runtimeToBootstrap)if(n===e){i=t;break}if(!i)return;let a=`${i}:`;for(let[e,r]of this.remoteTransports)e.startsWith(a)&&r.handleEvent(t,n)}openRemoteTab(e,t){let n=this.runtimeToBootstrap.get(e),r=n?this.followers.get(n):void 0;if(!r)return Promise.reject(Error(`Target runtime "${e}" not connected`));let i=`tab-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((e,n)=>{this.tabOpenResolvers.set(i,{resolve:e,reject:n}),this.pendingTabOpenRoutes.set(i,{requesterBootstrapId:`__leader__`,requestId:i}),r.sync.send({type:`tab.open`,requestId:i,url:t})})}async executeLocalTabOpen(e,t,n){let r=this.followers.get(n);if(!r)return;let i=this.options.browserTransport;if(!i){r.sync.send({type:`tab.open.error`,requestId:e,error:`Leader has no browser transport`});return}try{let n=(await i.send(`Target.createTarget`,{url:t,background:!0})).targetId;r.sync.send({type:`tab.opened`,requestId:e,targetId:`leader:${n}`})}catch(t){r.sync.send({type:`tab.open.error`,requestId:e,error:t instanceof Error?t.message:String(t)})}}forwardTabOpen(e,t,n,r){let i=this.runtimeToBootstrap.get(t),a=i?this.followers.get(i):void 0,o=this.followers.get(r);if(!a){o&&o.sync.send({type:`tab.open.error`,requestId:e,error:`Target runtime "${t}" not connected`});return}this.pendingTabOpenRoutes.set(e,{requesterBootstrapId:r,requestId:e}),a.sync.send({type:`tab.open`,requestId:e,url:n})}handleTabOpenResponse(e,t){let n=this.pendingTabOpenRoutes.get(e);if(!n)return;if(this.pendingTabOpenRoutes.delete(e),n.requesterBootstrapId===`__leader__`){let n=this.tabOpenResolvers.get(e);n&&(this.tabOpenResolvers.delete(e),n.resolve(t));return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`tab.opened`,requestId:e,targetId:t})}handleTabOpenError(e,t){let n=this.pendingTabOpenRoutes.get(e);if(!n)return;if(this.pendingTabOpenRoutes.delete(e),n.requesterBootstrapId===`__leader__`){let n=this.tabOpenResolvers.get(e);n&&(this.tabOpenResolvers.delete(e),n.reject(Error(t)));return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`tab.open.error`,requestId:e,error:t})}async executeLocalFs(e,t,n){let r=this.followers.get(n);if(!r)return;let i=this.options.vfs;if(!i){r.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Leader has no VFS`}});return}let a=await jb(i,t);for(let t of a)r.sync.send({type:`fs.response`,requestId:e,response:t})}forwardFsRequest(e,t,n,r){let i=this.runtimeToBootstrap.get(t),a=i?this.followers.get(i):void 0,o=this.followers.get(r);if(!a){o&&o.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Target runtime "${t}" not connected`}});return}this.pendingFsRoutes.set(e,{requesterBootstrapId:r,requestId:e,chunks:[],totalChunks:1}),a.sync.send({type:`fs.request`,requestId:e,request:n})}handleFsResponse(e,t){let n=this.pendingFsRoutes.get(e);if(!n){let n=this.fsResolvers.get(e);if(n){n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),n.resolve(n.responses))}return}if(n.requesterBootstrapId===`__leader__`){let n=this.fsResolvers.get(e);if(n){n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),this.pendingFsRoutes.delete(e),n.resolve(n.responses))}return}let r=this.followers.get(n.requesterBootstrapId);r&&r.sync.send({type:`fs.response`,requestId:e,response:t}),n.chunks.push(t),n.totalChunks=t.ok&&t.totalChunks||1,n.chunks.length>=n.totalChunks&&this.pendingFsRoutes.delete(e)}sendFsRequest(e,t){if(e===`leader`){let e=this.options.vfs;return e?jb(e,t):Promise.resolve([{ok:!1,error:`Leader has no VFS`}])}let n=this.runtimeToBootstrap.get(e),r=n?this.followers.get(n):void 0;if(!r)return Promise.resolve([{ok:!1,error:`Target runtime "${e}" not connected`}]);let i=`fs-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((e,n)=>{this.fsResolvers.set(i,{resolve:e,reject:n,responses:[]}),this.pendingFsRoutes.set(i,{requesterBootstrapId:`__leader__`,requestId:i,chunks:[],totalChunks:1}),r.sync.send({type:`fs.request`,requestId:i,request:t})})}},Xb=n(`tray-follower-sync`),Zb=class{sync;eventListeners=new Set;unsubscribe;keepalive;latestSnapshot=null;sentMessageIds=new Set;targetEntries=[];remoteTransports=new Map;cdpChunkBuffers=new Map;snapshotChunkBuffer=null;remoteCDPSessions=new Set;cdpEventCleanups=[];tabOpenResolvers=new Map;fsResolvers=new Map;constructor(e,t={}){this.options=t,this.sync=be(e),this.unsubscribe=this.sync.onMessage(e=>{this.handleLeaderMessage(e)}),this.keepalive=new Kb({sendPing:()=>this.sync.send({type:`ping`}),onDead:()=>{Xb.warn(`Leader keepalive dead, cleaning up`),this.handleDisconnect(`Keepalive timeout — leader not responding`),this.options.onDead?.()}}),this.keepalive.start(),e.addEventListener(`close`,()=>{Xb.warn(`Data channel closed`),this.handleDisconnect(`Data channel closed`)}),e.addEventListener(`error`,()=>{Xb.warn(`Data channel error`),this.handleDisconnect(`Data channel error`)})}sendMessage(e,t){let n=t??`follower-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;this.sentMessageIds.add(n),this.sync.send({type:`user_message`,text:e,messageId:n}),Xb.info(`Sent user message to leader`,{messageId:n})}onEvent(e){return this.eventListeners.add(e),()=>this.eventListeners.delete(e)}stop(){this.sync.send({type:`abort`}),Xb.info(`Sent abort to leader`)}requestSnapshot(){this.sync.send({type:`request_snapshot`})}getLatestSnapshot(){return this.latestSnapshot}close(){this.keepalive.stop(),this.unsubscribe(),this.sync.close(),this.eventListeners.clear(),this.cleanupCDPEventForwarding(),Xb.info(`Follower sync closed`)}advertiseTargets(e,t){this.sync.send({type:`targets.advertise`,targets:e,runtimeId:t})}getTargets(){return this.targetEntries}disconnected=!1;handleDisconnect(e){this.disconnected||(this.disconnected=!0,p({...h(),state:`error`,error:e}),this.emitEvent({type:`error`,error:`Connection to leader lost: ${e}`}),this.keepalive.stop(),this.cleanupCDPEventForwarding(),this.unsubscribe(),this.sync.close(),this.options.onDisconnect?.(e))}handleLeaderMessage(e){switch(e.type){case`snapshot`:Xb.info(`Snapshot received from leader`,{messageCount:e.messages.length,scoopJid:e.scoopJid}),this.snapshotChunkBuffer=null,this.latestSnapshot={messages:e.messages,scoopJid:e.scoopJid},this.options.onSnapshot?.(e.messages,e.scoopJid);break;case`snapshot_chunk`:{let t=ye(this.snapshotChunkBuffer,e);this.snapshotChunkBuffer=t.buffer,t.result&&(Xb.info(`Chunked snapshot reassembled from leader`,{messageCount:t.result.messages.length,scoopJid:t.result.scoopJid}),this.latestSnapshot=t.result,this.options.onSnapshot?.(t.result.messages,t.result.scoopJid));break}case`agent_event`:this.emitEvent(e.event);break;case`user_message_echo`:if(this.sentMessageIds.has(e.messageId)){this.sentMessageIds.delete(e.messageId),Xb.debug(`Skipping own message echo`,{messageId:e.messageId});break}Xb.info(`User message echo received`,{messageId:e.messageId,scoopJid:e.scoopJid}),this.options.onUserMessage?.(e.text,e.messageId,e.scoopJid);break;case`status`:this.options.onStatus?.(e.scoopStatus);break;case`error`:Xb.warn(`Error from leader`,{error:e.error}),this.emitEvent({type:`error`,error:e.error});break;case`targets.registry`:Xb.info(`Target registry received from leader`,{targetCount:e.targets.length}),this.targetEntries=e.targets,this.options.onTargetsUpdated?.(this.targetEntries);break;case`cdp.request`:{let{requestId:t,localTargetId:n,method:r,params:i,sessionId:a}=e;this.executeLocalCDP(t,n,r,i,a);break}case`cdp.response`:this.routeCDPResponse(e);break;case`cdp.event`:for(let t of this.remoteTransports.values())t.handleEvent(e.method,e.params);break;case`tab.open`:this.executeLocalTabOpen(e.requestId,e.url);break;case`tab.opened`:{let t=this.tabOpenResolvers.get(e.requestId);t&&(this.tabOpenResolvers.delete(e.requestId),t.resolve(e.targetId));break}case`tab.open.error`:{let t=this.tabOpenResolvers.get(e.requestId);t&&(this.tabOpenResolvers.delete(e.requestId),t.reject(Error(e.error)));break}case`fs.request`:this.executeLocalFs(e.requestId,e.request);break;case`fs.response`:this.routeFsResponse(e.requestId,e.response);break;case`ping`:this.keepalive.receivePing(),this.sync.send({type:`pong`});break;case`pong`:this.keepalive.receivePong(),u(Date.now());break}}emitEvent(e){for(let t of this.eventListeners)try{t(e)}catch(t){Xb.error(`Listener error`,{eventType:e.type,error:t instanceof Error?t.message:String(t)})}}createRemoteTransport(e,t){let n=new ve({sendCDPRequest:(n,r,i,a)=>{this.sync.send({type:`cdp.request`,requestId:n,targetRuntimeId:e,localTargetId:t,method:r,params:i,sessionId:a})}});return this.remoteTransports.set(`${e}:${t}`,n),n}removeRemoteTransport(e,t){let n=`${e}:${t}`,r=this.remoteTransports.get(n);r&&(r.disconnect(),this.remoteTransports.delete(n))}openRemoteTab(e,t){let n=`tab-open-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((r,i)=>{this.tabOpenResolvers.set(n,{resolve:r,reject:i}),this.sync.send({type:`tab.open`,requestId:n,targetRuntimeId:e,url:t})})}async executeLocalTabOpen(e,t){let n=this.options.browserTransport;if(!n){this.sync.send({type:`tab.open.error`,requestId:e,error:`Follower has no browser transport`});return}try{let r=(await n.send(`Target.createTarget`,{url:t,background:!0})).targetId;this.sync.send({type:`tab.opened`,requestId:e,targetId:r}),this.options.onTargetsChanged?.()}catch(t){this.sync.send({type:`tab.open.error`,requestId:e,error:t instanceof Error?t.message:String(t)})}}async executeLocalCDP(e,t,n,r,i){let a=this.options.browserTransport;if(!a){this.sync.send({type:`cdp.response`,requestId:e,error:`Follower has no browser transport`});return}try{let t=await a.send(n,r,i);if(n===`Target.attachToTarget`&&t.sessionId){let e=t.sessionId;this.remoteCDPSessions.add(e),this.setupCDPEventForwarding(a,e),Xb.debug(`Tracking remote CDP session`,{remoteSessionId:e})}n===`Target.detachFromTarget`&&i&&this.remoteCDPSessions.has(i)&&(this.remoteCDPSessions.delete(i),Xb.debug(`Removed remote CDP session on detach`,{sessionId:i})),xe(this.sync,e,t)}catch(t){this.sync.send({type:`cdp.response`,requestId:e,error:t instanceof Error?t.message:String(t)})}}setupCDPEventForwarding(e,t){for(let n of[`Page.frameNavigated`,`Page.loadEventFired`,`Page.domContentEventFired`,`Network.responseReceived`,`Network.loadingFinished`,`Network.requestWillBeSent`]){let r=e=>{if(e.sessionId!==t||!this.remoteCDPSessions.has(t))return;let{sessionId:r,...i}=e;this.sync.send({type:`cdp.event`,method:n,params:i,sessionId:t})};e.on(n,r),this.cdpEventCleanups.push(()=>e.off(n,r))}}cleanupCDPEventForwarding(){for(let e of this.cdpEventCleanups)e();this.cdpEventCleanups.length=0,this.remoteCDPSessions.clear()}routeCDPResponse(e){let t=pe(this.cdpChunkBuffers,e);if(t)for(let n of this.remoteTransports.values())n.handleResponse(e.requestId,t.result,t.error)}async executeLocalFs(e,t){let n=this.options.vfs;if(!n){this.sync.send({type:`fs.response`,requestId:e,response:{ok:!1,error:`Follower has no VFS`}});return}let r=await jb(n,t);for(let t of r)this.sync.send({type:`fs.response`,requestId:e,response:t})}routeFsResponse(e,t){let n=this.fsResolvers.get(e);if(!n)return;n.responses.push(t);let r=t.ok&&t.totalChunks||1;n.responses.length>=r&&(this.fsResolvers.delete(e),n.resolve(n.responses))}sendFsRequest(e,t){let n=`fs-${Date.now()}-${Math.random().toString(36).slice(2,8)}`;return new Promise((r,i)=>{this.fsResolvers.set(n,{resolve:r,reject:i,responses:[]}),this.sync.send({type:`fs.request`,requestId:n,targetRuntimeId:e,request:t})})}};function Qb(e,t){if(t)return`extension`;try{return tx(new URL(e))?`electron-overlay`:`standalone`}catch{return`standalone`}}function $b(e,t){return e===`electron-overlay`||e===`standalone`&&t}function ex(e){try{let t=new URL(e).searchParams.get(`tab`);return t&&Ji(t)?t:Ki}catch{return Ki}}function tx(e){return e.pathname===`/electron`||e.pathname===`/electron/`||e.searchParams.get(`runtime`)===`electron-overlay`}function nx(e){let t=new URL(e);return`${t.protocol===`https:`?`wss:`:`ws:`}//${t.host}/licks-ws`}function rx(e,t){return`${new URL(e).origin}/webhooks/${t}`}function ix(e,t){return`${e.replace(/\/+$/,``)}/${t.replace(/^\/+/,``)}`}function ax(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`slicc-electron-overlay:set-tab`}var ox=[`/shared/sprinkles`];async function sx(e){let t=new Map;for(let n of ox)await e.exists(n)&&await cx(e,n,t);return await cx(e,`/`,t),t}async function cx(e,t,n){for await(let r of e.walk(t)){if(!r.endsWith(`.shtml`))continue;let t=lx(r);if(!n.has(t)){let i;try{i=await e.readFile(r,{encoding:`utf-8`})??``}catch{i=``}n.set(t,{name:t,path:r,title:ux(i,t),autoOpen:dx(i)})}}}function lx(e){let t=e.split(`/`).pop()??e;return t.endsWith(`.shtml`)?t.slice(0,-6):t}function ux(e,t){let n=e.match(/data-sprinkle-title=["']([^"']+)["']/);if(n)return n[1];let r=e.match(/<title>([^<]+)<\/title>/i);return r?r[1].trim():t}function dx(e){return/data-sprinkle-autoopen\b/.test(e)}var fx=n(`sprinkle-manager`),px=`slicc-open-sprinkles`,mx=class{fs;bridge;callbacks;availableSprinkles=new Map;watcherUnsub;openSprinkles=new Map;constructor(e,t,n,r){this.fs=e,this.bridge=new Nh(e,t,e=>this.close(e),r),this.callbacks=n}async restoreOpenSprinkles(){try{let e=localStorage.getItem(px);if(!e){for(let e of this.availableSprinkles.values())if(e.autoOpen)try{await this.open(e.name)}catch{fx.warn(`Failed to auto-open sprinkle`,{name:e.name})}return}let t=JSON.parse(e);for(let e of t)try{await this.open(e)}catch{fx.warn(`Failed to restore sprinkle`,{name:e})}}catch{}}persistOpenSprinkles(){try{localStorage.setItem(px,JSON.stringify([...this.openSprinkles.keys()]))}catch{}}async openNewAutoOpenSprinkles(){await this.refresh();for(let e of this.availableSprinkles.values())if(e.autoOpen&&!this.openSprinkles.has(e.name))try{await this.open(e.name),fx.info(`Auto-opened new sprinkle after install`,{name:e.name})}catch{fx.warn(`Failed to auto-open new sprinkle`,{name:e.name})}}async refresh(){this.availableSprinkles=await sx(this.fs),fx.info(`Discovered sprinkles`,{count:this.availableSprinkles.size})}async open(e,t){if(this.openSprinkles.has(e)){fx.info(`Sprinkle already open`,{name:e});return}let n=this.availableSprinkles.get(e);if(n||=(await this.refresh(),this.availableSprinkles.get(e)),!n)throw Error(`Sprinkle not found: ${e}`);let r=await this.fs.readFile(n.path,{encoding:`utf-8`}),i=document.createElement(`div`);i.className=`sprinkle-panel`,i.style.cssText=`width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden;`,i.dataset.sprinkle=e,this.openSprinkles.set(e,{renderer:null,container:i}),this.callbacks.addSprinkle(e,n.title,i,t);let a=new oi(i,this.bridge.createAPI(e));await a.render(r,e),this.openSprinkles.get(e).renderer=a,this.persistOpenSprinkles(),Bv(e),fx.info(`Sprinkle opened`,{name:e,title:n.title})}close(e){let t=this.openSprinkles.get(e);t&&(t.renderer?.dispose(),t.container.remove(),this.bridge.removeSprinkle(e),this.openSprinkles.delete(e),this.callbacks.removeSprinkle(e),this.persistOpenSprinkles(),fx.info(`Sprinkle closed`,{name:e}))}available(){return Array.from(this.availableSprinkles.values())}opened(){return Array.from(this.openSprinkles.keys())}setupWatcher(e){this.watcherUnsub=e.watch(`/workspace`,e=>e.endsWith(`.shtml`),()=>void this.refresh())}dispose(){this.watcherUnsub?.()}sendToSprinkle(e,t){let n=this.openSprinkles.get(e);if(!n){fx.warn(`Cannot send to closed sprinkle`,{name:e});return}this.bridge.pushUpdate(e,t),n.renderer.pushUpdate(t)}};function hx(e){try{let t=new URL(e);return`${t.origin}${t.pathname}`}catch{return e}}function gx(e){let t=[],{payload:n}=e;if(n.title&&t.push(`# ${n.title}`),t.push(`A new handoff was accepted from ${hx(e.sourceUrl)}.`),t.push(`## Instruction`),t.push(n.instruction),n.urls&&n.urls.length>0){t.push(`## URLs`);for(let e of n.urls)t.push(`- ${e}`)}if(n.context&&(t.push(`## Context`),t.push(n.context)),n.acceptanceCriteria&&n.acceptanceCriteria.length>0){t.push(`## Acceptance Criteria`);for(let e of n.acceptanceCriteria)t.push(`- ${e}`)}return n.notes&&(t.push(`## Notes`),t.push(n.notes)),t.join(`
|
|
13109
13109
|
|
|
13110
|
-
`)}function _x(e,t){return e.receivedAt.localeCompare(t.receivedAt)}var vx=class{onPendingHandoffsChange;pendingByHandoffId=new Map;constructor(e){this.onPendingHandoffsChange=e.onPendingHandoffsChange}injectHandoff(e,t=`local`){let n=`injected-${Date.now()}-${Math.random().toString(36).slice(2)}`;return this.pendingByHandoffId.set(n,{handoffId:n,sourceUrl:t,payload:e,receivedAt:new Date().toISOString()}),this.emitChange(),n}clearHandoff(e){let t=this.pendingByHandoffId.get(e)??null;return this.pendingByHandoffId.delete(e),t&&this.emitChange(),{handoff:t,targetIds:[]}}emitChange(){this.onPendingHandoffsChange?.([...this.pendingByHandoffId.values()].sort(_x))}},$=n(`main`),yx=`slicc-pending-mount`,bx=`pendingMount`;async function xx(e){let t=await new Promise((e,t)=>{let n=indexedDB.open(yx,1);n.onupgradeneeded=()=>n.result.createObjectStore(`handles`),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),n=t.transaction(`handles`,`readwrite`);n.objectStore(`handles`).put(e,bx),await new Promise(e=>n.oncomplete=()=>e()),t.close()}async function Sx(e){let t;try{t=await new Promise((e,t)=>{let n=indexedDB.open(yx,1);n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}catch{return}let n=t.transaction(`handles`,`readwrite`),r=await new Promise(e=>{let t=n.objectStore(`handles`).get(bx);t.onsuccess=()=>e(t.result),t.onerror=()=>e(void 0)});if(r){n.objectStore(`handles`).delete(bx),await new Promise(e=>n.oncomplete=()=>e());let t=`/mnt/${r.name}`;await e.mount(t,r),$.info(`Mounted folder from welcome onboarding`,{name:r.name,path:t})}t.close()}function Cx(){let e=document.createElement(`div`);e.className=`skill-drop-overlay`;let t=document.createElement(`div`);t.className=`skill-drop-overlay__card`;let n=document.createElement(`div`);n.className=`skill-drop-overlay__title`,t.appendChild(n);let r=document.createElement(`div`);return r.className=`skill-drop-overlay__desc`,t.appendChild(r),e.appendChild(t),document.body.appendChild(e),{show(t,i){n.textContent=t,r.textContent=i,e.classList.add(`skill-drop-overlay--visible`)},hide(){e.classList.remove(`skill-drop-overlay--visible`)}}}function wx(){let e=document.createElement(`div`);return e.className=`skill-drop-toast-container`,document.body.appendChild(e),(t,n)=>{let r=document.createElement(`div`);r.className=`skill-drop-toast skill-drop-toast--${n}`,r.textContent=t,e.appendChild(r),requestAnimationFrame(()=>r.classList.add(`skill-drop-toast--visible`)),window.setTimeout(()=>{r.classList.remove(`skill-drop-toast--visible`),window.setTimeout(()=>r.remove(),180)},4200)}}function Tx(e,t,n){let r=Cx(),i=0,a=!1,o=()=>{i=0,a||r.hide()};window.addEventListener(`dragenter`,e=>{ga(e.dataTransfer)&&(e.preventDefault(),i+=1,a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragover`,e=>{ga(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`),a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragleave`,()=>{i!==0&&(i=Math.max(0,i-1),i===0&&!a&&r.hide())}),window.addEventListener(`dragend`,o),window.addEventListener(`blur`,o),window.addEventListener(`drop`,async s=>{let c=_a(s.dataTransfer);if(!c){o();return}if(s.preventDefault(),i=0,a){r.hide(),t(`Another .skill installation is already in progress.`,`error`);return}a=!0,r.show(`Installing skill…`,c.name);try{let r=await de(e,c);await n(),t(`Installed "${r.skillName}" to ${r.destinationPath} (${r.fileCount} files). Run "skill install ${r.skillName}" to apply it.`,`success`)}catch(e){t(`Failed to install dropped skill: ${e instanceof Error?e.message:String(e)}`,`error`)}finally{a=!1,r.hide()}})}async function Ex(e){let{OffscreenClient:t}=await r(async()=>{let{OffscreenClient:e}=await import(`./offscreen-client-BMlTH2Sh.js`);return{OffscreenClient:e}},__vite__mapDeps([24,17])),{VirtualFS:n}=await r(async()=>{let{VirtualFS:e}=await import(`./fs-CjCas3-3.js`).then(e=>e.t);return{VirtualFS:e}},__vite__mapDeps([22,4,17])),i=new $i(e,!0);window.__slicc_debug_tabs=e=>i.setDebugTabs(e),await i.panels.chat.initSession(`session-cone`);let a=null,o=await n.create({dbName:`slicc-fs`});i.panels.fileBrowser.setFs(o),$.info(`File browser wired to shared VFS (local IndexedDB)`);let s=new BroadcastChannel(`preview-vfs`);s.onmessage=e=>{if(e.data?.type!==`preview-vfs-read`)return;let{id:t,path:n,asText:r}=e.data;(async()=>{try{let e=r?`utf-8`:`binary`,i=await o.readFile(n,{encoding:e});s.postMessage({type:`preview-vfs-response`,id:t,content:i})}catch(e){let r=e instanceof Error?e.message:String(e);r.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:n,error:r}),s.postMessage({type:`preview-vfs-response`,id:t,error:r})}})()},Tx(o,wx(),async()=>{await i.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await r(async()=>{let{WasmShell:e}=await import(`./shell-zRiJffsM.js`);return{WasmShell:e}},[]),{PanelCdpProxy:t,BrowserAPI:n}=await r(async()=>{let{PanelCdpProxy:e,BrowserAPI:t}=await import(`./cdp-Dln7uDXr.js`).then(e=>e.t);return{PanelCdpProxy:e,BrowserAPI:t}},__vite__mapDeps([25,4,1,17])),{fetchSecretEnvVars:a}=await r(async()=>{let{fetchSecretEnvVars:e}=await import(`./secret-env-B32GVtBN.js`);return{fetchSecretEnvVars:e}},[]),s=new t;await s.connect();let c=new n(s),l=await a(),u=new e({fs:o,browserAPI:c,env:Object.keys(l).length>0?l:void 0});await i.panels.terminal.mountShell(u),$.info(`Terminal mounted with shared VFS and BrowserAPI (CDP proxy)`)}catch(e){$.warn(`Failed to mount shell to terminal`,e)}{let{registerSessionCostsProvider:e}=await r(async()=>{let{registerSessionCostsProvider:e}=await import(`./cost-command-DhUP8Ozj.js`).then(e=>e.t);return{registerSessionCostsProvider:e}},__vite__mapDeps([26,4]));e(()=>new Promise(e=>{chrome.runtime.sendMessage({source:`panel`,payload:{type:`get-session-costs`}},t=>{if(chrome.runtime.lastError||!t?.ok){e([]);return}e(t.costs??[])})}))}let l,u=new Set,d=e=>{i.setPendingHandoffCount(e.length),i.panels.chat.setPendingHandoffs(e)},f=async e=>{a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid),i.setScoopSwitcherSelected?.(e.jid),i.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=e.isCone?void 0:e.name;await i.panels.chat.switchToContext(t,!e.isCone,n),l.isProcessing(e.jid)&&i.panels.chat.setProcessing(!0)};l=new t({onStatusChange:(e,t)=>{i.panels.scoops.updateScoopStatus(e,t),i.updateScoopSwitcherStatus?.(e,t),a?.jid===e&&(i.setAgentProcessing(t===`processing`),t===`processing`?i.panels.chat.setProcessing(!0):t===`ready`&&i.panels.chat.setProcessing(!1))},onScoopCreated:e=>{i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),a||(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))},onScoopListUpdate:()=>{let e=new Set(l.getScoops().map(e=>e.folder));for(let t of u)e.has(t)||i.panels.chat.deleteSessionById(`session-${t}`);if(u=e,i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),!a){let e=l.getScoops().find(e=>e.isCone);e&&(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))}},onIncomingMessage:(e,t)=>{if(a?.jid===e){let e=t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content;i.panels.chat.addUserMessage(e)}},onPendingHandoffsChange:d,onReady:async()=>{try{$.info(`Offscreen engine ready, scoop count:`,l.getScoops().length),window.localStorage.getItem(`slicc.trayJoinUrl`)&&chrome.runtime.sendMessage({source:`panel`,payload:{type:`refresh-tray-runtime`}}).catch(()=>{});let e=a??l.getScoops().find(e=>e.isCone)??l.getScoops()[0];e&&(a=e,l.selectedScoopJid=e.jid,await f(e))}catch(e){$.error(`Failed to initialize on ready`,{error:e instanceof Error?e.message:String(e)})}}}),l.setLocalFS(o);let p=l.createAgentHandle();i.panels.chat.setAgent(p),i.panels.chat.setPendingHandoffActions({onAccept:async e=>{let t=l.getScoops().find(e=>e.isCone);if(!t){$.warn(`Cannot accept handoff without a cone scoop`,{handoffId:e.handoffId});return}await f(t),i.setActiveTab(`chat`),p.sendMessage(gx(e),`handoff-${e.handoffId}`),l.acceptPendingHandoff(e.handoffId)},onDismiss:e=>{l.dismissPendingHandoff(e.handoffId)}}),l.requestPendingHandoffs(),i.panels.scoops.setOrchestrator(l),i.panels.memory.setOrchestrator(l),i.setScoopSwitcherOrchestrator?.(l),i.onScoopSelect=f,i.onModelChange=e=>{localStorage.setItem(`selected-model`,e),l.updateModel()},i.onClearChat=async()=>{let e=l.getScoops();for(let t of e){let e=t.isCone?`session-cone`:`session-${t.folder}`;await i.panels.chat.deleteSessionById(e)}l.clearAllMessages()},i.onClearFilesystem=async()=>{l.clearFilesystem()},i.panels.chat.onInlineSprinkleLick=(e,t)=>{l.sendSprinkleLick(`inline`,{action:e,data:t})};let m=new mx(o,async e=>{if(e.type===`sprinkle`){if(e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&o.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome completion marker`,e)),n===`shortcut-migrate`&&m.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&Sx(o).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await xx(t),m.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),m.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}return}l.sendSprinkleLick(e.sprinkleName,e.body,e.targetScoop)}},{addSprinkle:(e,t,n,r)=>i.addSprinkle(e,t,n,r),removeSprinkle:e=>i.removeSprinkle(e)},()=>{let e=l.getScoops().find(e=>e.isCone);e&&l.stopScoop(e.jid)});if(window.__slicc_sprinkleManager=m,window.__slicc_reloadSkills=()=>(chrome.runtime.sendMessage({source:`panel`,payload:{type:`reload-skills`}}),Promise.resolve()),l.setSprinkleOpHandler(e=>{let{id:t,op:n,name:r,data:i}=e;console.log(`[main-ext] sprinkle-op handler called`,{id:t,op:n,name:r}),(async()=>{try{let e;switch(n){case`list`:await m.refresh(),e=m.available();break;case`opened`:e=m.opened();break;case`refresh`:await m.refresh(),e=m.available().length;break;case`open`:await m.open(r),e=!0;break;case`close`:m.close(r),e=!0;break;case`send`:m.sendToSprinkle(r,i),e=!0;break;case`openNewAutoOpen`:await m.openNewAutoOpenSprinkles(),e=!0;break}console.log(`[main-ext] sprinkle-op response sending`,{id:t,op:n,result:typeof e}),chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,result:e}}).catch(()=>{})}catch(e){chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,error:e instanceof Error?e.message:String(e)}}).catch(()=>{})}})()}),await m.refresh(),i.onSprinkleClose=e=>m.close(e),i.getAvailableSprinkles=()=>{let e=new Set(m.opened());return m.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},i.onOpenSprinkle=(e,t)=>m.open(e,t),i.updateAddButtons(),await m.restoreOpenSprinkles(),!await o.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await o.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await o.exists(`/shared/.welcomed`)&&!c(window.localStorage)&&m.available().some(e=>e.name===`welcome`))try{await m.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}$.info(`SprinkleManager initialized (extension mode)`),l.requestState(),$.info(`Extension UI connected to offscreen agent engine`),Lv().catch(()=>{})}function Dx(){if(typeof chrome<`u`&&chrome?.runtime?.id)return;let e=new Blob([`
|
|
13110
|
+
`)}function _x(e,t){return e.receivedAt.localeCompare(t.receivedAt)}var vx=class{onPendingHandoffsChange;pendingByHandoffId=new Map;constructor(e){this.onPendingHandoffsChange=e.onPendingHandoffsChange}injectHandoff(e,t=`local`){let n=`injected-${Date.now()}-${Math.random().toString(36).slice(2)}`;return this.pendingByHandoffId.set(n,{handoffId:n,sourceUrl:t,payload:e,receivedAt:new Date().toISOString()}),this.emitChange(),n}clearHandoff(e){let t=this.pendingByHandoffId.get(e)??null;return this.pendingByHandoffId.delete(e),t&&this.emitChange(),{handoff:t,targetIds:[]}}emitChange(){this.onPendingHandoffsChange?.([...this.pendingByHandoffId.values()].sort(_x))}},$=n(`main`),yx=`slicc-pending-mount`,bx=`pendingMount`;async function xx(e){let t=await new Promise((e,t)=>{let n=indexedDB.open(yx,1);n.onupgradeneeded=()=>n.result.createObjectStore(`handles`),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}),n=t.transaction(`handles`,`readwrite`);n.objectStore(`handles`).put(e,bx),await new Promise(e=>n.oncomplete=()=>e()),t.close()}async function Sx(e){let t;try{t=await new Promise((e,t)=>{let n=indexedDB.open(yx,1);n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}catch{return}let n=t.transaction(`handles`,`readwrite`),r=await new Promise(e=>{let t=n.objectStore(`handles`).get(bx);t.onsuccess=()=>e(t.result),t.onerror=()=>e(void 0)});if(r){n.objectStore(`handles`).delete(bx),await new Promise(e=>n.oncomplete=()=>e());let t=`/mnt/${r.name}`;await e.mount(t,r),$.info(`Mounted folder from welcome onboarding`,{name:r.name,path:t})}t.close()}function Cx(){let e=document.createElement(`div`);e.className=`skill-drop-overlay`;let t=document.createElement(`div`);t.className=`skill-drop-overlay__card`;let n=document.createElement(`div`);n.className=`skill-drop-overlay__title`,t.appendChild(n);let r=document.createElement(`div`);return r.className=`skill-drop-overlay__desc`,t.appendChild(r),e.appendChild(t),document.body.appendChild(e),{show(t,i){n.textContent=t,r.textContent=i,e.classList.add(`skill-drop-overlay--visible`)},hide(){e.classList.remove(`skill-drop-overlay--visible`)}}}function wx(){let e=document.createElement(`div`);return e.className=`skill-drop-toast-container`,document.body.appendChild(e),(t,n)=>{let r=document.createElement(`div`);r.className=`skill-drop-toast skill-drop-toast--${n}`,r.textContent=t,e.appendChild(r),requestAnimationFrame(()=>r.classList.add(`skill-drop-toast--visible`)),window.setTimeout(()=>{r.classList.remove(`skill-drop-toast--visible`),window.setTimeout(()=>r.remove(),180)},4200)}}function Tx(e,t,n){let r=Cx(),i=0,a=!1,o=()=>{i=0,a||r.hide()};window.addEventListener(`dragenter`,e=>{ga(e.dataTransfer)&&(e.preventDefault(),i+=1,a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragover`,e=>{ga(e.dataTransfer)&&(e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect=`copy`),a||r.show(`Drop .skill to install`,`Unpack into /workspace/skills/{name}.`))}),window.addEventListener(`dragleave`,()=>{i!==0&&(i=Math.max(0,i-1),i===0&&!a&&r.hide())}),window.addEventListener(`dragend`,o),window.addEventListener(`blur`,o),window.addEventListener(`drop`,async s=>{let c=_a(s.dataTransfer);if(!c){o();return}if(s.preventDefault(),i=0,a){r.hide(),t(`Another .skill installation is already in progress.`,`error`);return}a=!0,r.show(`Installing skill…`,c.name);try{let r=await de(e,c);await n(),t(`Installed "${r.skillName}" to ${r.destinationPath} (${r.fileCount} files). Run "skill install ${r.skillName}" to apply it.`,`success`)}catch(e){t(`Failed to install dropped skill: ${e instanceof Error?e.message:String(e)}`,`error`)}finally{a=!1,r.hide()}})}async function Ex(e){let{OffscreenClient:t}=await r(async()=>{let{OffscreenClient:e}=await import(`./offscreen-client-BMlTH2Sh.js`);return{OffscreenClient:e}},__vite__mapDeps([24,17])),{VirtualFS:n}=await r(async()=>{let{VirtualFS:e}=await import(`./fs-D15vM8w-.js`).then(e=>e.t);return{VirtualFS:e}},__vite__mapDeps([22,4,17])),i=new $i(e,!0);window.__slicc_debug_tabs=e=>i.setDebugTabs(e),await i.panels.chat.initSession(`session-cone`);let a=null,o=await n.create({dbName:`slicc-fs`});i.panels.fileBrowser.setFs(o),$.info(`File browser wired to shared VFS (local IndexedDB)`);let s=new BroadcastChannel(`preview-vfs`);s.onmessage=e=>{if(e.data?.type!==`preview-vfs-read`)return;let{id:t,path:n,asText:r}=e.data;(async()=>{try{let e=r?`utf-8`:`binary`,i=await o.readFile(n,{encoding:e});s.postMessage({type:`preview-vfs-response`,id:t,content:i})}catch(e){let r=e instanceof Error?e.message:String(e);r.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:n,error:r}),s.postMessage({type:`preview-vfs-response`,id:t,error:r})}})()},Tx(o,wx(),async()=>{await i.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await r(async()=>{let{WasmShell:e}=await import(`./shell-CXxb3SHl.js`);return{WasmShell:e}},[]),{PanelCdpProxy:t,BrowserAPI:n}=await r(async()=>{let{PanelCdpProxy:e,BrowserAPI:t}=await import(`./cdp-Dln7uDXr.js`).then(e=>e.t);return{PanelCdpProxy:e,BrowserAPI:t}},__vite__mapDeps([25,4,1,17])),{fetchSecretEnvVars:a}=await r(async()=>{let{fetchSecretEnvVars:e}=await import(`./secret-env-BgnqXd0b.js`);return{fetchSecretEnvVars:e}},[]),s=new t;await s.connect();let c=new n(s),l=await a(),u=new e({fs:o,browserAPI:c,env:Object.keys(l).length>0?l:void 0});await i.panels.terminal.mountShell(u),$.info(`Terminal mounted with shared VFS and BrowserAPI (CDP proxy)`)}catch(e){$.warn(`Failed to mount shell to terminal`,e)}{let{registerSessionCostsProvider:e}=await r(async()=>{let{registerSessionCostsProvider:e}=await import(`./cost-command-DhUP8Ozj.js`).then(e=>e.t);return{registerSessionCostsProvider:e}},__vite__mapDeps([26,4]));e(()=>new Promise(e=>{chrome.runtime.sendMessage({source:`panel`,payload:{type:`get-session-costs`}},t=>{if(chrome.runtime.lastError||!t?.ok){e([]);return}e(t.costs??[])})}))}let l,u=new Set,d=e=>{i.setPendingHandoffCount(e.length),i.panels.chat.setPendingHandoffs(e)},f=async e=>{a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid),i.setScoopSwitcherSelected?.(e.jid),i.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=e.isCone?void 0:e.name;await i.panels.chat.switchToContext(t,!e.isCone,n),l.isProcessing(e.jid)&&i.panels.chat.setProcessing(!0)};l=new t({onStatusChange:(e,t)=>{i.panels.scoops.updateScoopStatus(e,t),i.updateScoopSwitcherStatus?.(e,t),a?.jid===e&&(i.setAgentProcessing(t===`processing`),t===`processing`?i.panels.chat.setProcessing(!0):t===`ready`&&i.panels.chat.setProcessing(!1))},onScoopCreated:e=>{i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),a||(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))},onScoopListUpdate:()=>{let e=new Set(l.getScoops().map(e=>e.folder));for(let t of u)e.has(t)||i.panels.chat.deleteSessionById(`session-${t}`);if(u=e,i.panels.scoops.refreshScoops(),i.refreshScoopSwitcher?.(),!a){let e=l.getScoops().find(e=>e.isCone);e&&(a=e,l.selectedScoopJid=e.jid,i.panels.memory.setSelectedScoop(e.jid))}},onIncomingMessage:(e,t)=>{if(a?.jid===e){let e=t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content;i.panels.chat.addUserMessage(e)}},onPendingHandoffsChange:d,onReady:async()=>{try{$.info(`Offscreen engine ready, scoop count:`,l.getScoops().length),window.localStorage.getItem(`slicc.trayJoinUrl`)&&chrome.runtime.sendMessage({source:`panel`,payload:{type:`refresh-tray-runtime`}}).catch(()=>{});let e=a??l.getScoops().find(e=>e.isCone)??l.getScoops()[0];e&&(a=e,l.selectedScoopJid=e.jid,await f(e))}catch(e){$.error(`Failed to initialize on ready`,{error:e instanceof Error?e.message:String(e)})}}}),l.setLocalFS(o);let p=l.createAgentHandle();i.panels.chat.setAgent(p),i.panels.chat.setPendingHandoffActions({onAccept:async e=>{let t=l.getScoops().find(e=>e.isCone);if(!t){$.warn(`Cannot accept handoff without a cone scoop`,{handoffId:e.handoffId});return}await f(t),i.setActiveTab(`chat`),p.sendMessage(gx(e),`handoff-${e.handoffId}`),l.acceptPendingHandoff(e.handoffId)},onDismiss:e=>{l.dismissPendingHandoff(e.handoffId)}}),l.requestPendingHandoffs(),i.panels.scoops.setOrchestrator(l),i.panels.memory.setOrchestrator(l),i.setScoopSwitcherOrchestrator?.(l),i.onScoopSelect=f,i.onModelChange=e=>{localStorage.setItem(`selected-model`,e),l.updateModel()},i.onClearChat=async()=>{let e=l.getScoops();for(let t of e){let e=t.isCone?`session-cone`:`session-${t.folder}`;await i.panels.chat.deleteSessionById(e)}l.clearAllMessages()},i.onClearFilesystem=async()=>{l.clearFilesystem()},i.panels.chat.onInlineSprinkleLick=(e,t)=>{l.sendSprinkleLick(`inline`,{action:e,data:t})};let m=new mx(o,async e=>{if(e.type===`sprinkle`){if(e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&o.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome completion marker`,e)),n===`shortcut-migrate`&&m.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&Sx(o).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await xx(t),m.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),m.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}return}l.sendSprinkleLick(e.sprinkleName,e.body,e.targetScoop)}},{addSprinkle:(e,t,n,r)=>i.addSprinkle(e,t,n,r),removeSprinkle:e=>i.removeSprinkle(e)},()=>{let e=l.getScoops().find(e=>e.isCone);e&&l.stopScoop(e.jid)});if(window.__slicc_sprinkleManager=m,window.__slicc_reloadSkills=()=>(chrome.runtime.sendMessage({source:`panel`,payload:{type:`reload-skills`}}),Promise.resolve()),l.setSprinkleOpHandler(e=>{let{id:t,op:n,name:r,data:i}=e;console.log(`[main-ext] sprinkle-op handler called`,{id:t,op:n,name:r}),(async()=>{try{let e;switch(n){case`list`:await m.refresh(),e=m.available();break;case`opened`:e=m.opened();break;case`refresh`:await m.refresh(),e=m.available().length;break;case`open`:await m.open(r),e=!0;break;case`close`:m.close(r),e=!0;break;case`send`:m.sendToSprinkle(r,i),e=!0;break;case`openNewAutoOpen`:await m.openNewAutoOpenSprinkles(),e=!0;break}console.log(`[main-ext] sprinkle-op response sending`,{id:t,op:n,result:typeof e}),chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,result:e}}).catch(()=>{})}catch(e){chrome.runtime.sendMessage({source:`panel`,payload:{type:`sprinkle-op-response`,id:t,error:e instanceof Error?e.message:String(e)}}).catch(()=>{})}})()}),await m.refresh(),i.onSprinkleClose=e=>m.close(e),i.getAvailableSprinkles=()=>{let e=new Set(m.opened());return m.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},i.onOpenSprinkle=(e,t)=>m.open(e,t),i.updateAddButtons(),await m.restoreOpenSprinkles(),!await o.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await o.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await o.exists(`/shared/.welcomed`)&&!c(window.localStorage)&&m.available().some(e=>e.name===`welcome`))try{await m.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}$.info(`SprinkleManager initialized (extension mode)`),l.requestState(),$.info(`Extension UI connected to offscreen agent engine`),Lv().catch(()=>{})}function Dx(){if(typeof chrome<`u`&&chrome?.runtime?.id)return;let e=new Blob([`
|
|
13111
13111
|
let lastPong = Date.now();
|
|
13112
13112
|
let frozen = false;
|
|
13113
13113
|
setInterval(() => {
|
|
@@ -13135,4 +13135,4 @@ ${t}
|
|
|
13135
13135
|
#app > .tab-content > .tab-content__panel {
|
|
13136
13136
|
height: 100%;
|
|
13137
13137
|
}
|
|
13138
|
-
`,document.head.appendChild(t),window.addEventListener(`message`,e=>{e.source===window.parent&&ax(e.data)&&u.setActiveTab(ex(`http://localhost/?tab=${e.data.tab??``}`))}),window.addEventListener(`keydown`,e=>{e.code===`Semicolon`&&(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&!e.repeat&&(e.preventDefault(),e.stopPropagation(),window.parent.postMessage({type:`slicc-electron-overlay:toggle`},`*`))},!0)}let f=wx();await u.panels.chat.initSession(`session-cone`),$.info(`Session initialized`);let p=new Se,m=e=>{u.setPendingHandoffCount(e.length),u.panels.chat.setPendingHandoffs(e)},h=new Set,_=e=>{$.debug(`Emit to UI`,{type:e.type,listenerCount:h.size});for(let t of h)try{t(e)}catch(t){$.error(`Listener error`,{eventType:e.type,error:t instanceof Error?t.message:String(t)})}},v=null,y=new Map,b=new Map;function x(){return Date.now().toString(36)+Math.random().toString(36).slice(2,8)}function S(e){let t=b.get(e);return t||(t=[],b.set(e,t)),t}function C(e,t){let n=S(e),r=y.get(e);if(r){let e=n.find(e=>e.id===r);if(e)return e}r=`scoop-${e}-${x()}`,y.set(e,r);let i=w.getScoops().find(t=>t.jid===e),a=i?.isCone?`cone`:i?.name??`unknown`,o={id:r,role:`assistant`,content:``,timestamp:Date.now(),toolCalls:[],isStreaming:!0,source:a,channel:t};return n.push(o),v?.jid===e&&_({type:`message_start`,messageId:r}),o}let w=new ab(u.getIframeContainer(),{onResponse:(e,t,n)=>{let r=C(e);n?r.content+=t:(r.content=t,r.isStreaming=!1),v?.jid===e&&(_({type:`content_delta`,messageId:r.id,text:t}),n||_({type:`content_done`,messageId:r.id}))},onResponseDone:e=>{let t=S(e),n=y.get(e);if(n){let r=t.find(e=>e.id===n);r&&(r.isStreaming=!1),v?.jid===e&&_({type:`content_done`,messageId:n}),y.delete(e)}},onSendMessage:(e,t)=>{$.debug(`Send message requested`,{targetJid:e,textLength:t.length});let n=`msg-${x()}`,r={id:n,chatJid:e,senderId:`assistant`,senderName:`sliccy`,content:t,timestamp:new Date().toISOString(),fromAssistant:!0,channel:`web`};w.handleMessage(r),S(e).push({id:n,role:`assistant`,content:t,timestamp:Date.now()}),v?.jid===e&&(_({type:`message_start`,messageId:n}),_({type:`content_delta`,messageId:n,text:t}),_({type:`content_done`,messageId:n}))},onStatusChange:(e,t)=>{if(u.panels.scoops.updateScoopStatus(e,t),u.updateScoopSwitcherStatus?.(e,t),v?.jid===e){if(u.setAgentProcessing(t===`processing`),t===`processing`)u.panels.chat.setProcessing(!0);else if(t===`ready`){u.panels.chat.setProcessing(!1);let t=y.get(e)??`done-${e}-${x()}`;y.delete(e),_({type:`turn_end`,messageId:t})}}},onError:(e,t)=>{$.error(`Scoop error`,{scoopJid:e,error:t}),v?.jid===e&&_({type:`error`,error:t})},getBrowserAPI:()=>p,onToolStart:(e,t,n)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let r=C(e);r.toolCalls||=[],r.toolCalls.push({id:x(),name:t,input:n}),v?.jid===e&&_({type:`tool_use_start`,messageId:r.id,toolName:t,toolInput:n})},onToolEnd:(e,t,n,r)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let i=S(e),a=y.get(e);if(a){let e=i.find(e=>e.id===a);if(e?.toolCalls){let i=[...e.toolCalls].reverse().find(e=>e.name===t&&e.result===void 0);i&&(i.result=n,i.isError=r)}}v?.jid===e&&a&&_({type:`tool_result`,messageId:a,toolName:t,result:n,isError:r})},onToolUI:(e,t,n,r)=>{let i=y.get(e);i?_({type:`tool_ui`,messageId:i,toolName:t,requestId:n,html:r}):$.warn(`Cannot emit tool_ui - no message ID for scoop`,{scoopJid:e,requestId:n})},onToolUIDone:(e,t)=>{let n=y.get(e);n&&_({type:`tool_ui_done`,messageId:n,requestId:t})},onIncomingMessage:(e,t)=>{let n={id:t.id,role:`user`,content:t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content,timestamp:new Date(t.timestamp).getTime(),source:t.channel===`delegation`?`delegation`:void 0,channel:t.channel};S(e).push(n),v?.jid===e&&(_({type:`message_start`,messageId:t.id}),_({type:`content_delta`,messageId:t.id,text:n.content}),_({type:`content_done`,messageId:t.id}))}});await w.init(),u.panels.scoops.setOrchestrator(w),u.panels.memory.setOrchestrator(w),u.setScoopSwitcherOrchestrator?.(w);let E=w.getSharedFS();if(E){u.panels.fileBrowser.setFs(E),$.info(`File browser wired to shared VFS`);let e=new BroadcastChannel(`preview-vfs`);e.onmessage=t=>{if(t.data?.type!==`preview-vfs-read`)return;let{id:n,path:r,asText:i}=t.data;(async()=>{try{let t=i?`utf-8`:`binary`,a=await E.readFile(r,{encoding:t});e.postMessage({type:`preview-vfs-response`,id:n,content:a})}catch(t){let i=t instanceof Error?t.message:String(t);i.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:r,error:i}),e.postMessage({type:`preview-vfs-response`,id:n,error:i})}})()},Tx(E,(e,t)=>{t===`error`?$.warn(`Dropped skill install failed`,{message:e}):$.info(`Dropped skill installed`,{message:e}),f(e,t)},async()=>{await u.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await r(async()=>{let{WasmShell:e}=await import(`./shell-zRiJffsM.js`);return{WasmShell:e}},[]),{fetchSecretEnvVars:t}=await r(async()=>{let{fetchSecretEnvVars:e}=await import(`./secret-env-B32GVtBN.js`);return{fetchSecretEnvVars:e}},[]),n=await t(),i=new e({fs:E,browserAPI:p,env:Object.keys(n).length>0?n:void 0});await u.panels.terminal.mountShell(i),$.info(`Terminal mounted with shared VFS`);try{let{BshWatchdog:e}=await r(async()=>{let{BshWatchdog:e}=await import(`./bsh-watchdog-UyxqvRBs.js`);return{BshWatchdog:e}},__vite__mapDeps([27,17])),t=new e({browserAPI:p,scriptCatalog:i.getScriptCatalog(),fs:E});t.start(),window.addEventListener(`beforeunload`,()=>t.stop(),{once:!0}),$.info(`BSH navigation watchdog started`)}catch(e){$.warn(`Failed to start BSH watchdog`,e)}}catch(e){$.warn(`Failed to mount shell to terminal`,e)}}let D=w.getScoops(),ee=D.some(e=>e.isCone);if(a)$.info(`Skipping local cone bootstrap while joining a tray without a configured provider`);else if(!ee)v=await u.panels.scoops.createScoop(`Cone`,!0),$.info(`Created cone`);else{let e=new URLSearchParams(window.location.search).get(`scoop`);if(e){let t=D.find(t=>t.folder===e);t?(v=t,$.info(`Restored scoop from URL`,{folder:e})):v=D.find(e=>e.isCone)??D[0]}else v=D.find(e=>e.isCone)??D[0]}v&&u.panels.memory.setSelectedScoop(v.jid);let k=null,te=null,A={sendMessage(e,t){if(!v){_({type:`error`,error:`No scoop selected`});return}let n={id:t??`msg-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,chatJid:v.jid,senderId:`user`,senderName:`User`,content:e,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`web`};S(v.jid).push({id:n.id,role:`user`,content:e,timestamp:Date.now()}),k?.broadcastUserMessage(e,n.id),w.handleMessage(n),w.createScoopTab(v.jid)},onEvent(e){return h.add(e),()=>h.delete(e)},stop(){v&&(w.stopScoop(v.jid),w.clearQueuedMessages(v.jid).catch(e=>{$.error(`Failed to clear queued messages on stop`,{error:e instanceof Error?e.message:String(e)})}))}};u.panels.chat.setAgent(A),u.panels.chat.setPendingHandoffActions({onAccept:async e=>{let t=w.getScoops().find(e=>e.isCone);if(!t){$.warn(`Cannot accept handoff without a cone scoop`,{handoffId:e.handoffId});return}await oe(t),u.setActiveTab(`chat`),A.sendMessage(gx(e),`handoff-${e.handoffId}`);let n=te?.clearHandoff(e.handoffId);n&&await Promise.allSettled(n.targetIds.map(e=>p.closePage(e)))},onDismiss:async e=>{let t=te?.clearHandoff(e.handoffId);t&&await Promise.allSettled(t.targetIds.map(e=>p.closePage(e)))}}),u.panels.chat.setDeleteQueuedMessageCallback(e=>{if(v){w.deleteQueuedMessage(v.jid,e).catch(t=>{$.error(`Failed to delete queued message`,{messageId:e,error:t instanceof Error?t.message:String(t)})});let t=b.get(v.jid);if(t){let n=t.findIndex(t=>t.id===e);n!==-1&&t.splice(n,1)}}}),$.info(`Cone agent handle wired to chat UI`);let{getLickManager:ne}=await r(async()=>{let{getLickManager:e}=await import(`./lick-manager-BVqr-e_y.js`);return{getLickManager:e}},[]),ie=ne();await ie.init(),w.setLickManager(ie);let ae=e=>{let t=e.type===`webhook`,n=e.type===`sprinkle`,r=e.type===`fswatch`,i=e.type===`session-reload`,a=t?e.webhookName:n?e.sprinkleName:r?e.fswatchName:i?`session-reload`:e.cronName,o=t?e.webhookId:n?e.sprinkleName:r?e.fswatchId:i?`session-reload`:e.cronId,s=e.type;if($.debug(`Lick event`,{type:e.type,name:a,targetScoop:e.targetScoop}),n&&e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&E?.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome marker`,e)),n===`shortcut-migrate`&&j?.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&E&&Sx(E).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(n&&e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){(async()=>{try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await xx(t),j?.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),j?.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}})();return}let c=w.getScoops(),l;if(l=e.targetScoop?c.find(t=>t.name===e.targetScoop||t.folder===e.targetScoop||t.folder===`${e.targetScoop}-scoop`):c.find(e=>e.isCone),l){let c=`${s}-${o}-${Date.now()}`,d=`[${t?`Webhook Event`:n?`Sprinkle Event`:r?`File Watch Event`:i?`Session Reload`:`Cron Event`}: ${a}]\n\`\`\`json\n${JSON.stringify(e.body,null,2)}\n\`\`\``,f={id:c,chatJid:l.jid,senderId:s,senderName:`${s}:${a}`,content:d,timestamp:e.timestamp,fromAssistant:!1,channel:s};S(l.jid).push({id:c,role:`user`,content:d,timestamp:Date.now(),source:`lick`,channel:s}),v?.jid===l.jid&&u.panels.chat.addLickMessage(c,d,s),$.info(`Routing lick to scoop`,{type:s,name:a,scoopJid:l.jid}),w.handleMessage(f)}else $.warn(`Lick target scoop not found`,{targetScoop:e.targetScoop})};ie.setEventHandler(ae),E&&se().then(async e=>{if(e.length===0)return;let t=[];for(let{path:n,handle:r}of e)try{if(!(`queryPermission`in r)){t.push({path:n,dirName:r.name});continue}await r.queryPermission({mode:`readwrite`})===`granted`?(await E.mount(n,r),$.info(`Restored mount from previous session`,{path:n,name:r.name})):t.push({path:n,dirName:r.name})}catch{t.push({path:n,dirName:r.name})}t.length>0&&ae({type:`session-reload`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{reason:`mount-recovery`,mounts:t}})}).catch(e=>$.warn(`Failed to restore persisted mounts`,e)),u.panels.chat.onInlineSprinkleLick=(e,t)=>{ae({type:`sprinkle`,sprinkleName:`inline`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{action:e,data:t}})};let j=null;if(E){if(j=new mx(E,ae,{addSprinkle:(e,t,n,r)=>u.addSprinkle(e,t,n,r),removeSprinkle:e=>u.removeSprinkle(e)},()=>{let e=w.getScoops().find(e=>e.isCone);e&&(w.stopScoop(e.jid),w.clearQueuedMessages(e.jid).catch(e=>{$.error(`Failed to clear queued messages on sprinkle stopCone`,{error:e instanceof Error?e.message:String(e)})}))}),window.__slicc_sprinkleManager=j,window.__slicc_reloadSkills=()=>w.reloadAllSkills(),await j.refresh(),u.onSprinkleClose=e=>j.close(e),u.getAvailableSprinkles=()=>{let e=new Set(j.opened());return j.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},u.onOpenSprinkle=(e,t)=>j.open(e,t),u.updateAddButtons(),!await E.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await E.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await E.exists(`/shared/.welcomed`)&&!a&&j.available().some(e=>e.name===`welcome`))try{await j.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}await j.restoreOpenSprinkles(),$.info(`SprinkleManager initialized`)}let M=()=>{let e=nx(window.location.href),t=new WebSocket(e);t.onopen=()=>{$.info(`Lick WebSocket connected`)},t.onmessage=async e=>{try{let n=JSON.parse(e.data);if(n.requestId){let e;try{switch(n.type){case`list_webhooks`:e={type:`response`,requestId:n.requestId,data:ie.listWebhooks()};break;case`create_webhook`:{let t=await ie.createWebhook(n.name||`default`,n.scoop,n.filter),r=Kp().session,i=r?.webhookUrl?ix(r.webhookUrl,t.id):rx(window.location.href,t.id);e={type:`response`,requestId:n.requestId,data:{...t,url:i}};break}case`delete_webhook`:e=await ie.deleteWebhook(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Webhook not found`}};break;case`list_crontasks`:e={type:`response`,requestId:n.requestId,data:ie.listCronTasks()};break;case`create_crontask`:{if(!n.name)throw Error(`name is required`);if(!n.cron)throw Error(`cron is required`);let t=await ie.createCronTask(n.name,n.cron,n.scoop,n.filter);e={type:`response`,requestId:n.requestId,data:t};break}case`delete_crontask`:e=await ie.deleteCronTask(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Cron task not found`}};break;case`tray_status`:{let t=Kp();e={type:`response`,requestId:n.requestId,data:{state:t.state,joinUrl:t.session?.joinUrl??null,workerBaseUrl:t.session?.workerBaseUrl??null,trayId:t.session?.trayId??null}};break}default:e={type:`response`,requestId:n.requestId,error:`Unknown request type: ${n.type}`}}}catch(t){e={type:`response`,requestId:n.requestId,error:t instanceof Error?t.message:String(t)}}t.send(JSON.stringify(e));return}n.type===`webhook_event`&&ie.handleWebhookEvent(n.webhookId,n.headers,n.body),n.type===`handoff_event`&&te&&te.injectHandoff(n.payload,n.sourceUrl)}catch(e){$.error(`Failed to process lick message`,{error:e instanceof Error?e.message:String(e)})}},t.onclose=()=>{$.warn(`Lick WebSocket disconnected, reconnecting in 3s...`),setTimeout(M,3e3)},t.onerror=e=>{$.error(`Lick WebSocket error`,{error:String(e)})}};M(),u.onModelChange=e=>{localStorage.setItem(`selected-model`,e),w.updateModel()};let N=new Set;u.onClearChat=async()=>{await w.clearAllMessages(),b.clear(),N.clear()},u.onClearFilesystem=async()=>{await w.resetFilesystem()};let oe=async e=>{$.info(`Scoop selected`,{jid:e.jid,name:e.name}),v=e,w.createScoopTab(e.jid),u.panels.memory.setSelectedScoop(e.jid),u.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=b.get(e.jid),r=!N.has(e.jid),i=e.isCone?void 0:e.name;if(!r&&n&&n.length>0)await u.panels.chat.switchToContext(t,!e.isCone,i),u.panels.chat.loadMessages(n);else{if(await u.panels.chat.switchToContext(t,!e.isCone,i),u.panels.chat.getMessages().length===0){let t=await w.getMessagesForScoop(e.jid);for(let e of t){let t=e.channel===`webhook`||e.channel===`cron`,n=e.channel===`delegation`;t?u.panels.chat.addUserMessage(e.content):n?u.panels.chat.addUserMessage(`**[Instructions from sliccy]**\n\n${e.content}`):e.fromAssistant?(_({type:`message_start`,messageId:e.id}),_({type:`content_delta`,messageId:e.id,text:e.content}),_({type:`content_done`,messageId:e.id})):u.panels.chat.addUserMessage(e.content)}}let n=u.panels.chat.getMessages(),r=new Set(n.map(e=>e.id)),a=S(e.jid),o=a.filter(e=>!r.has(e.id));a.length=0,a.push(...n,...o),o.length>0&&u.panels.chat.loadMessages(a)}e.isCone&&w.isProcessing(e.jid)&&u.panels.chat.setProcessing(!0),N.add(e.jid)};if(u.onScoopSelect=oe,v&&(w.createScoopTab(v.jid),await oe(v)),te=new vx({onPendingHandoffsChange:m}),l===`standalone`||l===`electron-overlay`){let e=await i(),t=$b(l,e!==null)?s:null,n=await g({locationHref:window.location.href,storage:window.localStorage,envBaseUrl:null,defaultWorkerBaseUrl:t,runtimeConfigFetcher:async()=>e}),r=null,a=null,o=null;$h(()=>k?(e,t)=>k.sendFsRequest(e,t):r?(e,t)=>r.sendFsRequest(e,t):null),Bf(()=>k?()=>k.getBestFollowerForTeleport():null),Vf(()=>k?()=>k.getConnectedFollowers():null);let c=e=>{o&&=(clearInterval(o),null),r?.close();let t=`follower-${e.bootstrapId}`,n=new Zb(e.channel,{browserTransport:p.getTransport(),browserAPI:p,onSnapshot:e=>{u.panels.chat.loadMessages(e)},onUserMessage:e=>{u.panels.chat.addUserMessage(e)},onStatus:e=>{u.panels.chat.setProcessing(e===`processing`)},onTargetsChanged:()=>void i()});r=n,p.setTrayTargetProvider(n),u.panels.chat.setAgent(n),n.requestSnapshot();let i=async()=>{try{let e=await p.listPages();n.advertiseTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})),t)}catch{}};o=setInterval(i,5e3),i(),$.info(`Follower sync wired to chat panel`,{trayId:e.trayId})},f=e=>{a?.cancel(),o&&=(clearInterval(o),null),r?.close(),r=null,a=Tb({joinUrl:e,runtime:`slicc-standalone`,fetchImpl:em()},{onConnected:e=>c(e),onReconnecting:e=>{$.info(`Follower reconnecting`,{attempt:e})},onGaveUp:e=>{$.warn(`Follower reconnect gave up`,{lastError:e})}})};if(window.addEventListener(`slicc:tray-join`,(e=>{f(e.detail.joinUrl)})),window.addEventListener(`beforeunload`,()=>{o&&clearInterval(o),r?.close(),a?.cancel()},{once:!0}),n?.joinUrl)f(n.joinUrl);else if(n?.workerBaseUrl){let e,t,r,i,a=()=>{t=new Yb({browserTransport:p.getTransport(),browserAPI:p,getMessages:()=>u.panels.chat.getMessages(),getScoopJid:()=>v?.jid??`cone`,onFollowerMessage:(e,t)=>{u.panels.chat.addUserMessage(e),A.sendMessage(e,t)},onFollowerAbort:()=>{A.stop()}}),k=t,nm(()=>t.getConnectedFollowers()),p.setTrayTargetProvider(t),i&&clearInterval(i);let n=async()=>{try{let e=await p.listPages();t.setLocalTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})))}catch{}};i=setInterval(n,5e3),n(),r=new Cb({sendControlMessage:t=>e.sendControlMessage(t),onPeerConnected:(e,n)=>{$.info(`Tray follower data channel opened`,{controllerId:e.controllerId,bootstrapId:e.bootstrapId,attempt:e.attempt,runtime:e.runtime}),t.addFollower(e.bootstrapId,n,{runtime:e.runtime,connectedAt:e.connectedAt??void 0})}})};a(),h.add(e=>{t.broadcastEvent(e)}),e=new Xp({workerBaseUrl:n.workerBaseUrl,runtime:`slicc-standalone`,fetchImpl:em(),onControlMessage:e=>{if(e.type===`webhook.event`){ie.handleWebhookEvent(e.webhookId,e.headers,e.body);return}r.handleControlMessage(e).catch(e=>{$.warn(`Tray leader bootstrap handling failed`,{error:e instanceof Error?e.message:String(e)})})}}),am(async()=>{t.stop(),r.stop(),e.stop(),await e.clearSession();let n=await e.start(),i=d(window.location.href,n.workerBaseUrl,n.trayId);return i!==window.location.href&&window.history.replaceState(window.history.state,``,i),a(),Kp()}),e.start().then(e=>{let t=d(window.location.href,e.workerBaseUrl,e.trayId);t!==window.location.href&&window.history.replaceState(window.history.state,``,t)}).catch(e=>{$.warn(`Leader tray join failed`,{error:e instanceof Error?e.message:String(e)})}),window.addEventListener(`beforeunload`,()=>{clearInterval(i),t.stop(),r.stop(),e.stop()},{once:!0})}}$.info(`Orchestrator initialized — cone+scoops ready`,{scoopCount:w.getScoops().length}),Lv().catch(()=>{})}Ox().catch(e=>{$.error(`Fatal error`,e);let t=document.getElementById(`app`);if(t){let n=document.createElement(`div`);n.style.cssText=`padding: 2rem; text-align: center;`;let r=document.createElement(`h1`);r.style.color=`var(--s2-negative, #e34850)`,r.textContent=`Failed to start`;let i=document.createElement(`p`);i.style.color=`var(--s2-content-tertiary, #717171)`,i.textContent=e.message,n.appendChild(r),n.appendChild(i);let a=document.createElement(`button`);for(a.textContent=`Reset all data & reload`,a.style.cssText=`margin-top: 1rem; padding: 0.5rem 1.5rem; background: var(--s2-negative, #e34850); color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 14px;`,a.addEventListener(`click`,async()=>{a.disabled=!0,a.textContent=`Resetting…`;let e=await indexedDB.databases();await Promise.all(e.map(e=>e.name?new Promise(t=>{let n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.onblocked=()=>t()}):Promise.resolve())),location.reload()}),n.appendChild(a);t.firstChild;)t.removeChild(t.firstChild);t.appendChild(n)}});export{Xv as a,ci as c,qy as i,ai as l,tb as n,Ta as o,rb as r,oi as s,eb as t};
|
|
13138
|
+
`,document.head.appendChild(t),window.addEventListener(`message`,e=>{e.source===window.parent&&ax(e.data)&&u.setActiveTab(ex(`http://localhost/?tab=${e.data.tab??``}`))}),window.addEventListener(`keydown`,e=>{e.code===`Semicolon`&&(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&!e.repeat&&(e.preventDefault(),e.stopPropagation(),window.parent.postMessage({type:`slicc-electron-overlay:toggle`},`*`))},!0)}let f=wx();await u.panels.chat.initSession(`session-cone`),$.info(`Session initialized`);let p=new Se,m=e=>{u.setPendingHandoffCount(e.length),u.panels.chat.setPendingHandoffs(e)},h=new Set,_=e=>{$.debug(`Emit to UI`,{type:e.type,listenerCount:h.size});for(let t of h)try{t(e)}catch(t){$.error(`Listener error`,{eventType:e.type,error:t instanceof Error?t.message:String(t)})}},v=null,y=new Map,b=new Map;function x(){return Date.now().toString(36)+Math.random().toString(36).slice(2,8)}function S(e){let t=b.get(e);return t||(t=[],b.set(e,t)),t}function C(e,t){let n=S(e),r=y.get(e);if(r){let e=n.find(e=>e.id===r);if(e)return e}r=`scoop-${e}-${x()}`,y.set(e,r);let i=w.getScoops().find(t=>t.jid===e),a=i?.isCone?`cone`:i?.name??`unknown`,o={id:r,role:`assistant`,content:``,timestamp:Date.now(),toolCalls:[],isStreaming:!0,source:a,channel:t};return n.push(o),v?.jid===e&&_({type:`message_start`,messageId:r}),o}let w=new ab(u.getIframeContainer(),{onResponse:(e,t,n)=>{let r=C(e);n?r.content+=t:(r.content=t,r.isStreaming=!1),v?.jid===e&&(_({type:`content_delta`,messageId:r.id,text:t}),n||_({type:`content_done`,messageId:r.id}))},onResponseDone:e=>{let t=S(e),n=y.get(e);if(n){let r=t.find(e=>e.id===n);r&&(r.isStreaming=!1),v?.jid===e&&_({type:`content_done`,messageId:n}),y.delete(e)}},onSendMessage:(e,t)=>{$.debug(`Send message requested`,{targetJid:e,textLength:t.length});let n=`msg-${x()}`,r={id:n,chatJid:e,senderId:`assistant`,senderName:`sliccy`,content:t,timestamp:new Date().toISOString(),fromAssistant:!0,channel:`web`};w.handleMessage(r),S(e).push({id:n,role:`assistant`,content:t,timestamp:Date.now()}),v?.jid===e&&(_({type:`message_start`,messageId:n}),_({type:`content_delta`,messageId:n,text:t}),_({type:`content_done`,messageId:n}))},onStatusChange:(e,t)=>{if(u.panels.scoops.updateScoopStatus(e,t),u.updateScoopSwitcherStatus?.(e,t),v?.jid===e){if(u.setAgentProcessing(t===`processing`),t===`processing`)u.panels.chat.setProcessing(!0);else if(t===`ready`){u.panels.chat.setProcessing(!1);let t=y.get(e)??`done-${e}-${x()}`;y.delete(e),_({type:`turn_end`,messageId:t})}}},onError:(e,t)=>{$.error(`Scoop error`,{scoopJid:e,error:t}),v?.jid===e&&_({type:`error`,error:t})},getBrowserAPI:()=>p,onToolStart:(e,t,n)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let r=C(e);r.toolCalls||=[],r.toolCalls.push({id:x(),name:t,input:n}),v?.jid===e&&_({type:`tool_use_start`,messageId:r.id,toolName:t,toolInput:n})},onToolEnd:(e,t,n,r)=>{if(new Set([`send_message`,`list_scoops`,`list_tasks`]).has(t))return;let i=S(e),a=y.get(e);if(a){let e=i.find(e=>e.id===a);if(e?.toolCalls){let i=[...e.toolCalls].reverse().find(e=>e.name===t&&e.result===void 0);i&&(i.result=n,i.isError=r)}}v?.jid===e&&a&&_({type:`tool_result`,messageId:a,toolName:t,result:n,isError:r})},onToolUI:(e,t,n,r)=>{let i=y.get(e);i?_({type:`tool_ui`,messageId:i,toolName:t,requestId:n,html:r}):$.warn(`Cannot emit tool_ui - no message ID for scoop`,{scoopJid:e,requestId:n})},onToolUIDone:(e,t)=>{let n=y.get(e);n&&_({type:`tool_ui_done`,messageId:n,requestId:t})},onIncomingMessage:(e,t)=>{let n={id:t.id,role:`user`,content:t.channel===`delegation`?`**[Instructions from sliccy]**\n\n${t.content}`:t.content,timestamp:new Date(t.timestamp).getTime(),source:t.channel===`delegation`?`delegation`:void 0,channel:t.channel};S(e).push(n),v?.jid===e&&(_({type:`message_start`,messageId:t.id}),_({type:`content_delta`,messageId:t.id,text:n.content}),_({type:`content_done`,messageId:t.id}))}});await w.init(),u.panels.scoops.setOrchestrator(w),u.panels.memory.setOrchestrator(w),u.setScoopSwitcherOrchestrator?.(w);let E=w.getSharedFS();if(E){u.panels.fileBrowser.setFs(E),$.info(`File browser wired to shared VFS`);let e=new BroadcastChannel(`preview-vfs`);e.onmessage=t=>{if(t.data?.type!==`preview-vfs-read`)return;let{id:n,path:r,asText:i}=t.data;(async()=>{try{let t=i?`utf-8`:`binary`,a=await E.readFile(r,{encoding:t});e.postMessage({type:`preview-vfs-response`,id:n,content:a})}catch(t){let i=t instanceof Error?t.message:String(t);i.includes(`ENOENT`)||$.error(`Preview VFS read failed`,{path:r,error:i}),e.postMessage({type:`preview-vfs-response`,id:n,error:i})}})()},Tx(E,(e,t)=>{t===`error`?$.warn(`Dropped skill install failed`,{message:e}):$.info(`Dropped skill installed`,{message:e}),f(e,t)},async()=>{await u.panels.fileBrowser.refresh()});try{let{WasmShell:e}=await r(async()=>{let{WasmShell:e}=await import(`./shell-CXxb3SHl.js`);return{WasmShell:e}},[]),{fetchSecretEnvVars:t}=await r(async()=>{let{fetchSecretEnvVars:e}=await import(`./secret-env-BgnqXd0b.js`);return{fetchSecretEnvVars:e}},[]),n=await t(),i=new e({fs:E,browserAPI:p,env:Object.keys(n).length>0?n:void 0});await u.panels.terminal.mountShell(i),$.info(`Terminal mounted with shared VFS`);try{let{BshWatchdog:e}=await r(async()=>{let{BshWatchdog:e}=await import(`./bsh-watchdog-UyxqvRBs.js`);return{BshWatchdog:e}},__vite__mapDeps([27,17])),t=new e({browserAPI:p,scriptCatalog:i.getScriptCatalog(),fs:E});t.start(),window.addEventListener(`beforeunload`,()=>t.stop(),{once:!0}),$.info(`BSH navigation watchdog started`)}catch(e){$.warn(`Failed to start BSH watchdog`,e)}}catch(e){$.warn(`Failed to mount shell to terminal`,e)}}let D=w.getScoops(),ee=D.some(e=>e.isCone);if(a)$.info(`Skipping local cone bootstrap while joining a tray without a configured provider`);else if(!ee)v=await u.panels.scoops.createCone(),$.info(`Created cone`);else{let e=new URLSearchParams(window.location.search).get(`scoop`);if(e){let t=D.find(t=>t.folder===e);t?(v=t,$.info(`Restored scoop from URL`,{folder:e})):v=D.find(e=>e.isCone)??D[0]}else v=D.find(e=>e.isCone)??D[0]}v&&u.panels.memory.setSelectedScoop(v.jid);let k=null,te=null,A={sendMessage(e,t){if(!v){_({type:`error`,error:`No scoop selected`});return}let n={id:t??`msg-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,chatJid:v.jid,senderId:`user`,senderName:`User`,content:e,timestamp:new Date().toISOString(),fromAssistant:!1,channel:`web`};S(v.jid).push({id:n.id,role:`user`,content:e,timestamp:Date.now()}),k?.broadcastUserMessage(e,n.id),w.handleMessage(n),w.createScoopTab(v.jid)},onEvent(e){return h.add(e),()=>h.delete(e)},stop(){v&&(w.stopScoop(v.jid),w.clearQueuedMessages(v.jid).catch(e=>{$.error(`Failed to clear queued messages on stop`,{error:e instanceof Error?e.message:String(e)})}))}};u.panels.chat.setAgent(A),u.panels.chat.setPendingHandoffActions({onAccept:async e=>{let t=w.getScoops().find(e=>e.isCone);if(!t){$.warn(`Cannot accept handoff without a cone scoop`,{handoffId:e.handoffId});return}await oe(t),u.setActiveTab(`chat`),A.sendMessage(gx(e),`handoff-${e.handoffId}`);let n=te?.clearHandoff(e.handoffId);n&&await Promise.allSettled(n.targetIds.map(e=>p.closePage(e)))},onDismiss:async e=>{let t=te?.clearHandoff(e.handoffId);t&&await Promise.allSettled(t.targetIds.map(e=>p.closePage(e)))}}),u.panels.chat.setDeleteQueuedMessageCallback(e=>{if(v){w.deleteQueuedMessage(v.jid,e).catch(t=>{$.error(`Failed to delete queued message`,{messageId:e,error:t instanceof Error?t.message:String(t)})});let t=b.get(v.jid);if(t){let n=t.findIndex(t=>t.id===e);n!==-1&&t.splice(n,1)}}}),$.info(`Cone agent handle wired to chat UI`);let{getLickManager:ne}=await r(async()=>{let{getLickManager:e}=await import(`./lick-manager-CYt5gTMJ.js`);return{getLickManager:e}},[]),ie=ne();await ie.init(),w.setLickManager(ie);let ae=e=>{let t=e.type===`webhook`,n=e.type===`sprinkle`,r=e.type===`fswatch`,i=e.type===`session-reload`,a=t?e.webhookName:n?e.sprinkleName:r?e.fswatchName:i?`session-reload`:e.cronName,o=t?e.webhookId:n?e.sprinkleName:r?e.fswatchId:i?`session-reload`:e.cronId,s=e.type;if($.debug(`Lick event`,{type:e.type,name:a,targetScoop:e.targetScoop}),n&&e.sprinkleName===`welcome`){let t=e.body,n=t?.action;(n===`onboarding-complete`||n===`shortcut-migrate`)&&E?.writeFile(`/shared/.welcomed`,`1`).catch(e=>$.warn(`Failed to persist welcome marker`,e)),n===`shortcut-migrate`&&j?.close(`welcome`),n===`onboarding-complete`&&t?.data?.mountWorkspace&&E&&Sx(E).catch(e=>$.warn(`Failed to mount workspace from onboarding`,e))}if(n&&e.sprinkleName===`welcome`&&e.body?.action===`request-mount`){(async()=>{try{let e=window;if(!e.showDirectoryPicker)throw Error(`showDirectoryPicker not supported`);let t=await e.showDirectoryPicker({mode:`readwrite`});await xx(t),j?.sendToSprinkle(`welcome`,{action:`mount-complete`,dirName:t.name})}catch(e){e.name!==`AbortError`&&$.warn(`Mount picker failed`,e),j?.sendToSprinkle(`welcome`,{action:`mount-cancelled`})}})();return}let c=w.getScoops(),l;if(l=e.targetScoop?c.find(t=>t.name===e.targetScoop||t.folder===e.targetScoop||t.folder===`${e.targetScoop}-scoop`):c.find(e=>e.isCone),l){let c=`${s}-${o}-${Date.now()}`,d=`[${t?`Webhook Event`:n?`Sprinkle Event`:r?`File Watch Event`:i?`Session Reload`:`Cron Event`}: ${a}]\n\`\`\`json\n${JSON.stringify(e.body,null,2)}\n\`\`\``,f={id:c,chatJid:l.jid,senderId:s,senderName:`${s}:${a}`,content:d,timestamp:e.timestamp,fromAssistant:!1,channel:s};S(l.jid).push({id:c,role:`user`,content:d,timestamp:Date.now(),source:`lick`,channel:s}),v?.jid===l.jid&&u.panels.chat.addLickMessage(c,d,s),$.info(`Routing lick to scoop`,{type:s,name:a,scoopJid:l.jid}),w.handleMessage(f)}else $.warn(`Lick target scoop not found`,{targetScoop:e.targetScoop})};ie.setEventHandler(ae),E&&se().then(async e=>{if(e.length===0)return;let t=[];for(let{path:n,handle:r}of e)try{if(!(`queryPermission`in r)){t.push({path:n,dirName:r.name});continue}await r.queryPermission({mode:`readwrite`})===`granted`?(await E.mount(n,r),$.info(`Restored mount from previous session`,{path:n,name:r.name})):t.push({path:n,dirName:r.name})}catch{t.push({path:n,dirName:r.name})}t.length>0&&ae({type:`session-reload`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{reason:`mount-recovery`,mounts:t}})}).catch(e=>$.warn(`Failed to restore persisted mounts`,e)),u.panels.chat.onInlineSprinkleLick=(e,t)=>{ae({type:`sprinkle`,sprinkleName:`inline`,targetScoop:void 0,timestamp:new Date().toISOString(),body:{action:e,data:t}})};let j=null;if(E){if(j=new mx(E,ae,{addSprinkle:(e,t,n,r)=>u.addSprinkle(e,t,n,r),removeSprinkle:e=>u.removeSprinkle(e)},()=>{let e=w.getScoops().find(e=>e.isCone);e&&(w.stopScoop(e.jid),w.clearQueuedMessages(e.jid).catch(e=>{$.error(`Failed to clear queued messages on sprinkle stopCone`,{error:e instanceof Error?e.message:String(e)})}))}),window.__slicc_sprinkleManager=j,window.__slicc_reloadSkills=()=>w.reloadAllSkills(),await j.refresh(),u.onSprinkleClose=e=>j.close(e),u.getAvailableSprinkles=()=>{let e=new Set(j.opened());return j.available().filter(t=>!e.has(t.name)).map(e=>({name:e.name,title:e.title}))},u.onOpenSprinkle=(e,t)=>j.open(e,t),u.updateAddButtons(),!await E.exists(`/shared/.welcomed`)&&localStorage.getItem(`slicc-welcomed`)&&(await E.writeFile(`/shared/.welcomed`,`1`).catch(()=>{}),localStorage.removeItem(`slicc-welcomed`)),!await E.exists(`/shared/.welcomed`)&&!a&&j.available().some(e=>e.name===`welcome`))try{await j.open(`welcome`)}catch(e){$.warn(`Failed to open welcome sprinkle`,e)}await j.restoreOpenSprinkles(),$.info(`SprinkleManager initialized`)}let M=()=>{let e=nx(window.location.href),t=new WebSocket(e);t.onopen=()=>{$.info(`Lick WebSocket connected`)},t.onmessage=async e=>{try{let n=JSON.parse(e.data);if(n.requestId){let e;try{switch(n.type){case`list_webhooks`:e={type:`response`,requestId:n.requestId,data:ie.listWebhooks()};break;case`create_webhook`:{let t=await ie.createWebhook(n.name||`default`,n.scoop,n.filter),r=Kp().session,i=r?.webhookUrl?ix(r.webhookUrl,t.id):rx(window.location.href,t.id);e={type:`response`,requestId:n.requestId,data:{...t,url:i}};break}case`delete_webhook`:e=await ie.deleteWebhook(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Webhook not found`}};break;case`list_crontasks`:e={type:`response`,requestId:n.requestId,data:ie.listCronTasks()};break;case`create_crontask`:{if(!n.name)throw Error(`name is required`);if(!n.cron)throw Error(`cron is required`);let t=await ie.createCronTask(n.name,n.cron,n.scoop,n.filter);e={type:`response`,requestId:n.requestId,data:t};break}case`delete_crontask`:e=await ie.deleteCronTask(n.id)?{type:`response`,requestId:n.requestId,data:{ok:!0}}:{type:`response`,requestId:n.requestId,data:{error:`Cron task not found`}};break;case`tray_status`:{let t=Kp();e={type:`response`,requestId:n.requestId,data:{state:t.state,joinUrl:t.session?.joinUrl??null,workerBaseUrl:t.session?.workerBaseUrl??null,trayId:t.session?.trayId??null}};break}default:e={type:`response`,requestId:n.requestId,error:`Unknown request type: ${n.type}`}}}catch(t){e={type:`response`,requestId:n.requestId,error:t instanceof Error?t.message:String(t)}}t.send(JSON.stringify(e));return}n.type===`webhook_event`&&ie.handleWebhookEvent(n.webhookId,n.headers,n.body),n.type===`handoff_event`&&te&&te.injectHandoff(n.payload,n.sourceUrl)}catch(e){$.error(`Failed to process lick message`,{error:e instanceof Error?e.message:String(e)})}},t.onclose=()=>{$.warn(`Lick WebSocket disconnected, reconnecting in 3s...`),setTimeout(M,3e3)},t.onerror=e=>{$.error(`Lick WebSocket error`,{error:String(e)})}};M(),u.onModelChange=e=>{localStorage.setItem(`selected-model`,e),w.updateModel()};let N=new Set;u.onClearChat=async()=>{await w.clearAllMessages(),b.clear(),N.clear()},u.onClearFilesystem=async()=>{await w.resetFilesystem()};let oe=async e=>{$.info(`Scoop selected`,{jid:e.jid,name:e.name}),v=e,w.createScoopTab(e.jid),u.panels.memory.setSelectedScoop(e.jid),u.panels.scoops.setSelectedJid(e.jid);let t=e.isCone?`session-cone`:`session-${e.folder}`,n=b.get(e.jid),r=!N.has(e.jid),i=e.isCone?void 0:e.name;if(!r&&n&&n.length>0)await u.panels.chat.switchToContext(t,!e.isCone,i),u.panels.chat.loadMessages(n);else{if(await u.panels.chat.switchToContext(t,!e.isCone,i),u.panels.chat.getMessages().length===0){let t=await w.getMessagesForScoop(e.jid);for(let e of t){let t=e.channel===`webhook`||e.channel===`cron`,n=e.channel===`delegation`;t?u.panels.chat.addUserMessage(e.content):n?u.panels.chat.addUserMessage(`**[Instructions from sliccy]**\n\n${e.content}`):e.fromAssistant?(_({type:`message_start`,messageId:e.id}),_({type:`content_delta`,messageId:e.id,text:e.content}),_({type:`content_done`,messageId:e.id})):u.panels.chat.addUserMessage(e.content)}}let n=u.panels.chat.getMessages(),r=new Set(n.map(e=>e.id)),a=S(e.jid),o=a.filter(e=>!r.has(e.id));a.length=0,a.push(...n,...o),o.length>0&&u.panels.chat.loadMessages(a)}e.isCone&&w.isProcessing(e.jid)&&u.panels.chat.setProcessing(!0),N.add(e.jid)};if(u.onScoopSelect=oe,v&&(w.createScoopTab(v.jid),await oe(v)),te=new vx({onPendingHandoffsChange:m}),l===`standalone`||l===`electron-overlay`){let e=await i(),t=$b(l,e!==null)?s:null,n=await g({locationHref:window.location.href,storage:window.localStorage,envBaseUrl:null,defaultWorkerBaseUrl:t,runtimeConfigFetcher:async()=>e}),r=null,a=null,o=null;$h(()=>k?(e,t)=>k.sendFsRequest(e,t):r?(e,t)=>r.sendFsRequest(e,t):null),Bf(()=>k?()=>k.getBestFollowerForTeleport():null),Vf(()=>k?()=>k.getConnectedFollowers():null);let c=e=>{o&&=(clearInterval(o),null),r?.close();let t=`follower-${e.bootstrapId}`,n=new Zb(e.channel,{browserTransport:p.getTransport(),browserAPI:p,onSnapshot:e=>{u.panels.chat.loadMessages(e)},onUserMessage:e=>{u.panels.chat.addUserMessage(e)},onStatus:e=>{u.panels.chat.setProcessing(e===`processing`)},onTargetsChanged:()=>void i()});r=n,p.setTrayTargetProvider(n),u.panels.chat.setAgent(n),n.requestSnapshot();let i=async()=>{try{let e=await p.listPages();n.advertiseTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})),t)}catch{}};o=setInterval(i,5e3),i(),$.info(`Follower sync wired to chat panel`,{trayId:e.trayId})},f=e=>{a?.cancel(),o&&=(clearInterval(o),null),r?.close(),r=null,a=Tb({joinUrl:e,runtime:`slicc-standalone`,fetchImpl:em()},{onConnected:e=>c(e),onReconnecting:e=>{$.info(`Follower reconnecting`,{attempt:e})},onGaveUp:e=>{$.warn(`Follower reconnect gave up`,{lastError:e})}})};if(window.addEventListener(`slicc:tray-join`,(e=>{f(e.detail.joinUrl)})),window.addEventListener(`beforeunload`,()=>{o&&clearInterval(o),r?.close(),a?.cancel()},{once:!0}),n?.joinUrl)f(n.joinUrl);else if(n?.workerBaseUrl){let e,t,r,i,a=()=>{t=new Yb({browserTransport:p.getTransport(),browserAPI:p,getMessages:()=>u.panels.chat.getMessages(),getScoopJid:()=>v?.jid??`cone`,onFollowerMessage:(e,t)=>{u.panels.chat.addUserMessage(e),A.sendMessage(e,t)},onFollowerAbort:()=>{A.stop()}}),k=t,nm(()=>t.getConnectedFollowers()),p.setTrayTargetProvider(t),i&&clearInterval(i);let n=async()=>{try{let e=await p.listPages();t.setLocalTargets(e.map(e=>({targetId:e.targetId,title:e.title,url:e.url})))}catch{}};i=setInterval(n,5e3),n(),r=new Cb({sendControlMessage:t=>e.sendControlMessage(t),onPeerConnected:(e,n)=>{$.info(`Tray follower data channel opened`,{controllerId:e.controllerId,bootstrapId:e.bootstrapId,attempt:e.attempt,runtime:e.runtime}),t.addFollower(e.bootstrapId,n,{runtime:e.runtime,connectedAt:e.connectedAt??void 0})}})};a(),h.add(e=>{t.broadcastEvent(e)}),e=new Xp({workerBaseUrl:n.workerBaseUrl,runtime:`slicc-standalone`,fetchImpl:em(),onControlMessage:e=>{if(e.type===`webhook.event`){ie.handleWebhookEvent(e.webhookId,e.headers,e.body);return}r.handleControlMessage(e).catch(e=>{$.warn(`Tray leader bootstrap handling failed`,{error:e instanceof Error?e.message:String(e)})})}}),am(async()=>{t.stop(),r.stop(),e.stop(),await e.clearSession();let n=await e.start(),i=d(window.location.href,n.workerBaseUrl,n.trayId);return i!==window.location.href&&window.history.replaceState(window.history.state,``,i),a(),Kp()}),e.start().then(e=>{let t=d(window.location.href,e.workerBaseUrl,e.trayId);t!==window.location.href&&window.history.replaceState(window.history.state,``,t)}).catch(e=>{$.warn(`Leader tray join failed`,{error:e instanceof Error?e.message:String(e)})}),window.addEventListener(`beforeunload`,()=>{clearInterval(i),t.stop(),r.stop(),e.stop()},{once:!0})}}$.info(`Orchestrator initialized — cone+scoops ready`,{scoopCount:w.getScoops().length}),Lv().catch(()=>{})}Ox().catch(e=>{$.error(`Fatal error`,e);let t=document.getElementById(`app`);if(t){let n=document.createElement(`div`);n.style.cssText=`padding: 2rem; text-align: center;`;let r=document.createElement(`h1`);r.style.color=`var(--s2-negative, #e34850)`,r.textContent=`Failed to start`;let i=document.createElement(`p`);i.style.color=`var(--s2-content-tertiary, #717171)`,i.textContent=e.message,n.appendChild(r),n.appendChild(i);let a=document.createElement(`button`);for(a.textContent=`Reset all data & reload`,a.style.cssText=`margin-top: 1rem; padding: 0.5rem 1.5rem; background: var(--s2-negative, #e34850); color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 14px;`,a.addEventListener(`click`,async()=>{a.disabled=!0,a.textContent=`Resetting…`;let e=await indexedDB.databases();await Promise.all(e.map(e=>e.name?new Promise(t=>{let n=indexedDB.deleteDatabase(e.name);n.onsuccess=()=>t(),n.onerror=()=>t(),n.onblocked=()=>t()}):Promise.resolve())),location.reload()}),n.appendChild(a);t.firstChild;)t.removeChild(t.firstChild);t.appendChild(n)}});export{Xv as a,ci as c,qy as i,ai as l,tb as n,Ta as o,rb as r,oi as s,eb as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./index-EsFCM-v9.js";export{e as getLickManager};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e}from"./index-EsFCM-v9.js";export{e as fetchSecretEnvVars};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./index-EsFCM-v9.js";export{e as WasmShell};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,l as r,o as i,r as a,s as o,t as s,u as c}from"./constants-Dqhmtsws.js";import{a as l,c as u,d,f,h as p,i as m,l as h,m as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C}from"./skills-
|
|
1
|
+
import{a as e,c as t,d as n,l as r,o as i,r as a,s as o,t as s,u as c}from"./constants-Dqhmtsws.js";import{a as l,c as u,d,f,h as p,i as m,l as h,m as g,n as _,o as v,p as y,r as b,s as x,t as S,u as C}from"./skills-D9PbVsND.js";export{s as MANIFEST_FILE,a as MAX_SKILL_ARCHIVE_SIZE_BYTES,e as SKILLS_DIR,i as SKILLS_SYSTEM_VERSION,o as SKILL_ARCHIVE_EXTENSION,t as SKILL_FILE,r as SLICC_DIR,c as STATE_FILE,n as WORKSPACE_SKILLS_PATH,x as applySkill,f as checkConflicts,y as checkDependencies,l as discoverSkillCandidates,_ as discoverSkills,u as getAppliedSkills,b as getSkillInfo,h as initSkillsSystem,d as installSkillFromDrop,g as parseManifestContent,p as readManifest,m as readSkillInstructions,C as readState,v as resolveSkillNameCollisions,S as uninstallSkill};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as e,d as t,f as n,l as r,n as i,o as a,s as o,t as s,u as c}from"./constants-Dqhmtsws.js";import{c as l,o as u}from"./fs-
|
|
1
|
+
import{c as e,d as t,f as n,l as r,n as i,o as a,s as o,t as s,u as c}from"./constants-Dqhmtsws.js";import{c as l,o as u}from"./fs-D15vM8w-.js";function d(e){let t={},n=e.split(`
|
|
2
2
|
`),r=null,i=!1,a={},o=null;for(let e of n){let n=e.trim();if(!n||n.startsWith(`#`))continue;if(n.startsWith(`- `)){let e=n.slice(2).trim();i&&o?o.push(e):r&&r.push(e);continue}let s=n.indexOf(`:`);if(s===-1)continue;let c=n.slice(0,s).trim(),l=n.slice(s+1).trim(),u=e.search(/\S/);if(c===`structured`){i=!0,a={},t.structured=a;continue}if(i&&u>=2){if(u>=4&&o)continue;l===``||l===`[]`?(o=[],a[c]=o):(a[c]=l,o=null);continue}u===0&&(i=!1),l===``||l===`[]`?(r=[],t[c]=r):(t[c]=l,r=null)}return t}function f(e,t=s){let n=d(e);if(!n.skill||typeof n.skill!=`string`)throw Error(`Invalid manifest: missing 'skill' field in ${t}`);if(!n.version||typeof n.version!=`string`)throw Error(`Invalid manifest: missing 'version' field in ${t}`);return{skill:n.skill,version:n.version,description:n.description||``,adds:n.adds||[],modifies:n.modifies||[],structured:n.structured,conflicts:n.conflicts||[],depends:n.depends||[],test:n.test,author:n.author}}async function p(e,t){let n=`${t}/${s}`;return f(await e.readTextFile(n),n)}function m(e,t){let n=(e.depends||[]).filter(e=>!t.includes(e));return{ok:n.length===0,missing:n}}function h(e,t){let n=(e.conflicts||[]).filter(e=>t.includes(e));return{ok:n.length===0,conflicting:n}}var g=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,_=class extends Error{};function v(e){return new TextDecoder().decode(e)}function y(e){let t=e.replace(/\\/g,`/`);if(!t||t.endsWith(`/`))return null;if(t.startsWith(`/`)||/^[A-Za-z]:\//.test(t))throw Error(`Blocked suspicious path "${e}".`);let n=t.split(`/`);if(n.some(e=>e===``||e===`.`||e===`..`))throw Error(`Blocked suspicious path "${e}".`);return n.join(`/`)}function b(e){if(!g.test(e))throw Error(`Invalid manifest: skill name "${e}" must be a simple directory name.`)}function x(e){let t=[];for(let[n,r]of Object.entries(e)){let e=y(n);e&&t.push({originalPath:n,path:e,bytes:r})}return t}function S(e){let t=e.filter(e=>e.path===`manifest.yaml`||e.path.endsWith(`/manifest.yaml`));if(t.length===0)throw Error(`Skill archive is missing ${s}.`);if(t.length>1)throw Error(`Skill archive contains multiple ${s} files.`);return t[0]}function C(e){let t=0,r=0;return n(e,{filter(e){if(t++,t>1e3)throw new _(`Skill archives may contain at most ${i} entries.`);if(r+=e.originalSize,r>52428800)throw new _(`Skill archives must expand to 50 MB or smaller after extraction.`);return!0}})}function w(e){return u(t,`.${e}.tmp-${`${Date.now()}-${Math.random().toString(16).slice(2,8)}`}`)}async function T(e,n){if(!n.name.toLowerCase().endsWith(`.skill`))throw Error(`Only ${o} archives can be installed with drag and drop.`);if(n.size>52428800)throw Error(`Skill archives must be 50 MB or smaller.`);let r;try{r=C(new Uint8Array(await n.arrayBuffer()))}catch(e){if(e instanceof _)throw e;let t=e instanceof Error?e.message:String(e);throw Error(`Invalid .skill archive: ${t}`)}let i=x(r),a=S(i),c=f(v(a.bytes),a.path);b(c.skill);let d=u(t,c.skill);if(await e.exists(d))throw Error(`Skill "${c.skill}" already exists at ${d}.`);let p=w(c.skill),m=a.path===`manifest.yaml`?``:a.path.slice(0,-(s.length+1));await e.mkdir(p,{recursive:!0});try{let t=0;for(let n of i){if(m&&(n.path===m||!n.path.startsWith(`${m}/`)))continue;let r=m?n.path.slice(m.length+1):n.path;if(!r)continue;let i=u(p,r),{dir:a}=l(i);a!==`/`&&await e.mkdir(a,{recursive:!0}),await e.writeFile(i,n.bytes),t++}return await e.rename(p,d),{skillName:c.skill,destinationPath:d,fileCount:t}}catch(t){throw await e.exists(p)&&await e.rm(p,{recursive:!0}),t}}var E=`/${r}/${c}`;async function D(e){try{await e.mkdir(`/${r}`)}catch{}try{await e.stat(E)}catch{let t={version:a,applied_skills:[]};await e.writeFile(E,JSON.stringify(t,null,2))}}async function O(e){try{let t=await e.readTextFile(E);return JSON.parse(t)}catch(e){if(typeof e==`object`&&e&&e.code===`ENOENT`)return{version:a,applied_skills:[]};throw e}}async function k(e,t){await D(e),await e.writeFile(E,JSON.stringify(t,null,2))}async function A(e){return(await O(e)).applied_skills.map(e=>e.name)}async function j(e,t){let n=await O(e);n.applied_skills=n.applied_skills.filter(e=>e.name!==t.name),n.applied_skills.push(t),await k(e,n)}async function M(e,t){let n=await O(e);n.applied_skills=n.applied_skills.filter(e=>e.name!==t),await k(e,n)}async function N(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest(`SHA-256`,t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,`0`)).join(``)}function P(e){return e.startsWith(`/`)?{valid:!1,error:`Absolute path not allowed: ${e}`}:e.split(`/`).some(e=>e===`..`)?{valid:!1,error:`Path traversal not allowed: ${e}`}:e.includes(`%2e%2e`)||e.includes(`%2E%2E`)?{valid:!1,error:`Encoded path traversal not allowed: ${e}`}:{valid:!0}}async function F(e,t){let n=t.split(`/`).filter(Boolean),r=``;for(let t of n){r+=`/`+t;try{await e.mkdir(r)}catch{}}}async function I(e,t,n=`/workspace/skills`){let r=`${n}/${t}`;await D(e);let i;try{i=await p(e,r)}catch(e){return{success:!1,skill:t,version:`unknown`,error:`Failed to read manifest: ${e instanceof Error?e.message:String(e)}`}}if(i.skill!==t)return{success:!1,skill:t,version:i.version,error:`Manifest skill name "${i.skill}" does not match directory name "${t}"`};let a=await A(e);if(a.includes(i.skill))return{success:!1,skill:i.skill,version:i.version,error:`Skill "${i.skill}" is already installed`};let o=m(i,a);if(!o.ok)return{success:!1,skill:i.skill,version:i.version,error:`Missing dependencies: ${o.missing.join(`, `)}`};let s=h(i,a);if(!s.ok)return{success:!1,skill:i.skill,version:i.version,error:`Conflicting skills: ${s.conflicting.join(`, `)}`};let c={},l=[];try{if(i.adds&&i.adds.length>0)for(let t of i.adds){let n=P(t);if(!n.valid)return{success:!1,skill:i.skill,version:i.version,error:n.error};let a=`${r}/add/${t}`,o=`/${t}`;try{let n=o.substring(0,o.lastIndexOf(`/`));n&&await F(e,n),await e.copyFile(a,o),l.push(t),c[t]=await N(await e.readTextFile(o))}catch(e){return{success:!1,skill:i.skill,version:i.version,error:`Failed to copy ${t}: ${e instanceof Error?e.message:String(e)}`}}}if(i.modifies&&i.modifies.length>0)for(let t of i.modifies){let n=P(t);if(!n.valid)return{success:!1,skill:i.skill,version:i.version,error:n.error};let a=`${r}/modify/${t}`;try{let n=await e.readTextFile(a),r=``;try{r=await e.readTextFile(`/${t}`)}catch{}let i;if(n.includes(`// APPEND_AFTER:`)){let e=n.split(`
|
|
3
3
|
`),t=e.find(e=>e.includes(`// APPEND_AFTER:`))?.split(`// APPEND_AFTER:`)[1]?.trim(),a=e.filter(e=>!e.includes(`// APPEND_AFTER:`)).join(`
|
|
4
4
|
`);if(t&&r.includes(t)){let e=r.indexOf(t)+t.length,n=r.indexOf(`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e}from"./index-EsFCM-v9.js";export{e as collectThemeCSS};
|
package/dist/ui/index.html
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>slicc</title>
|
|
7
7
|
<link rel="icon" type="image/png" href="/logos/sliccy-color-1scoops-32x32.png" />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-EsFCM-v9.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-zsgVPwQN.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-D4M6sveU.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/logger-B-No_qN_.js">
|
|
12
|
-
<link rel="modulepreload" crossorigin href="/assets/fs-
|
|
12
|
+
<link rel="modulepreload" crossorigin href="/assets/fs-D15vM8w-.js">
|
|
13
13
|
<link rel="modulepreload" crossorigin href="/assets/env-api-keys-qwjmVNjS.js">
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/assets/simple-options-DZXt61Q2.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/json-parse-JW3qhabb.js">
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<link rel="modulepreload" crossorigin href="/assets/cdp-Dln7uDXr.js">
|
|
23
23
|
<link rel="modulepreload" crossorigin href="/assets/db-QbwB670D.js">
|
|
24
24
|
<link rel="modulepreload" crossorigin href="/assets/magick-wasm-zICxCuIf.js">
|
|
25
|
-
<link rel="modulepreload" crossorigin href="/assets/skills-
|
|
25
|
+
<link rel="modulepreload" crossorigin href="/assets/skills-D9PbVsND.js">
|
|
26
26
|
<link rel="stylesheet" crossorigin href="/assets/index-BKr9s8eO.css">
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>slicc</title>
|
|
7
7
|
<link rel="icon" type="image/png" href="/logos/sliccy-color-1scoops-32x32.png" />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-EsFCM-v9.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-zsgVPwQN.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-D4M6sveU.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/logger-B-No_qN_.js">
|
|
12
|
-
<link rel="modulepreload" crossorigin href="/assets/fs-
|
|
12
|
+
<link rel="modulepreload" crossorigin href="/assets/fs-D15vM8w-.js">
|
|
13
13
|
<link rel="modulepreload" crossorigin href="/assets/env-api-keys-qwjmVNjS.js">
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/assets/simple-options-DZXt61Q2.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/json-parse-JW3qhabb.js">
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<link rel="modulepreload" crossorigin href="/assets/cdp-Dln7uDXr.js">
|
|
23
23
|
<link rel="modulepreload" crossorigin href="/assets/db-QbwB670D.js">
|
|
24
24
|
<link rel="modulepreload" crossorigin href="/assets/magick-wasm-zICxCuIf.js">
|
|
25
|
-
<link rel="modulepreload" crossorigin href="/assets/skills-
|
|
25
|
+
<link rel="modulepreload" crossorigin href="/assets/skills-D9PbVsND.js">
|
|
26
26
|
<link rel="stylesheet" crossorigin href="/assets/index-BKr9s8eO.css">
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./index-CP8O9WCU.js";export{e as getLickManager};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./index-CP8O9WCU.js";export{e as fetchSecretEnvVars};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e}from"./index-CP8O9WCU.js";export{e as WasmShell};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as e}from"./index-CP8O9WCU.js";export{e as collectThemeCSS};
|