@agentlang/lstudio 0.3.6 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,64 +42,6 @@ app.listen(4000, () => {
42
42
  });
43
43
  ```
44
44
 
45
- ## Development
46
-
47
- If you are developing this package (within the AgentLang repository):
48
-
49
- ### Building the Package
50
-
51
- To build and package the Studio UI for publishing:
52
-
53
- ```bash
54
- # From the studio workspace root
55
- npm run package:lstudio
56
- ```
57
-
58
- Or using nx directly:
59
-
60
- ```bash
61
- nx package lstudio
62
- ```
63
-
64
- This will:
65
-
66
- 1. Build the Studio UI in local mode
67
- 2. Copy the built files to `apps/lstudio/dist`
68
- 3. Create a `package.json` in the dist folder with publish configuration
69
-
70
- ### Publishing
71
-
72
- After packaging, publish to npm:
73
-
74
- ```bash
75
- cd apps/lstudio/dist
76
- npm publish --access public
77
- ```
78
-
79
- ### Local Testing
80
-
81
- To test the package locally before publishing, you can use `npm link`:
82
-
83
- **Step 1: Build and Link Locally**
84
-
85
- ```bash
86
- # Build the package
87
- npm run package:lstudio
88
-
89
- # Link the package globally
90
- cd apps/lstudio/dist
91
- npm link
92
- ```
93
-
94
- **Step 2: Link in Target Project**
95
-
96
- Navigate to your test project and link the package:
97
-
98
- ```bash
99
- cd /path/to/your/test-project
100
- npm link @agentlang/lstudio
101
- ```
102
-
103
45
  ## Package Contents
104
46
 
105
47
  The published package includes:
@@ -1 +1 @@
1
- import{E as I}from"./index-CjpHJARw.js";import"./_commonjsHelpers-D6-XlEtG.js";import"./index-ChvoNxcO.js";import"./preload-helper-BlTxHScW.js";import"./__vite-browser-external-DLjrMatA.js";import"./inherits_browser-nmOknR35-Bp0mvRSL.js";import"./index-6mKfgpcs-DsgiI2lM.js";import"./_commonjsHelpers-B4e78b8K-W3E8ocG7.js";import"./index-DsIu-45t-Bejjlpz4.js";import"./index-DSosZ5sh-Ceejs_jv.js";import"./index-69shuAsh-DF18H7zf.js";import"./index-BJBOx-Z---hbiLl7B.js";import"./index.browser-BHPvGrwi-6Mh8eUw-.js";import"./_commonjs-dynamic-modules-BpilXLfW-DfYEAvWy.js";import"./_commonjs-dynamic-modules-B7n8ZNar.js";var S=Object.defineProperty,A=(r,e,n)=>e in r?S(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n,g=(r,e,n)=>A(r,typeof e!="symbol"?e+"":e,n);function x(r,e){for(var n=0;n<e.length;n++){const o=e[n];if(typeof o!="string"&&!Array.isArray(o)){for(const t in o)if(t!=="default"&&!(t in r)){const i=Object.getOwnPropertyDescriptor(o,t);i&&Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:()=>o[t]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}function v(r){return{isFile:()=>r.isFile(),isDirectory:()=>r.isDirectory(),isSymbolicLink:()=>r.isSymbolicLink(),size:r.size,mtime:r.mtime}}class j{async readFile(e){return(void 0)(e,"utf8")}async readFileBuffer(e){return(void 0)(e)}async writeFile(e,n){const o=(void 0)(e);return await this.ensureDir(o),(void 0)(e,n)}async exists(e){try{return await(void 0)(e),!0}catch{return!1}}async mkdir(e){try{await(void 0)(e)}catch(n){if(n&&typeof n=="object"&&"code"in n&&n.code!=="EEXIST")throw n}}async readdir(e){return(void 0)(e)}async stat(e){const n=await(void 0)(e);return v(n)}async lstat(e){const n=await(void 0)(e);return v(n)}async unlink(e){return(void 0)(e)}async rmdir(e){return(void 0)(e)}async copyFile(e,n){const o=(void 0)(n);return await this.ensureDir(o),(void 0)(e,n)}async moveFile(e,n){const o=(void 0)(n);return await this.ensureDir(o),(void 0)(e,n)}async ensureDir(e){try{await(void 0)(e,{recursive:!0})}catch(n){if(n&&typeof n=="object"&&"code"in n&&n.code!=="EEXIST")throw n}}async removeDir(e){return(void 0)(e,{recursive:!0,force:!0})}async readDirectory(e){return(void 0)(e)}async writeFileSystemFromTree(e,n,o){for(const t of e){const i=(void 0)(n,t.path);if(t.type==="directory")await this.ensureDir(i),t.children&&await this.writeFileSystemFromTree(t.children,n,o);else{const s=await o(t.path);await this.writeFile(i,s)}}}}function T(){return new j}function E(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var F,z;function $(){if(z)return F;z=1;function r(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}function e(t,i){for(var s="",c=0,u=-1,a=0,f,l=0;l<=t.length;++l){if(l<t.length)f=t.charCodeAt(l);else{if(f===47)break;f=47}if(f===47){if(!(u===l-1||a===1))if(u!==l-1&&a===2){if(s.length<2||c!==2||s.charCodeAt(s.length-1)!==46||s.charCodeAt(s.length-2)!==46){if(s.length>2){var d=s.lastIndexOf("/");if(d!==s.length-1){d===-1?(s="",c=0):(s=s.slice(0,d),c=s.length-1-s.lastIndexOf("/")),u=l,a=0;continue}}else if(s.length===2||s.length===1){s="",c=0,u=l,a=0;continue}}i&&(s.length>0?s+="/..":s="..",c=2)}else s.length>0?s+="/"+t.slice(u+1,l):s=t.slice(u+1,l),c=l-u-1;u=l,a=0}else f===46&&a!==-1?++a:a=-1}return s}function n(t,i){var s=i.dir||i.root,c=i.base||(i.name||"")+(i.ext||"");return s?s===i.root?s+c:s+t+c:c}var o={resolve:function(){for(var t="",i=!1,s,c=arguments.length-1;c>=-1&&!i;c--){var u;c>=0?u=arguments[c]:(s===void 0&&(s=process.cwd()),u=s),r(u),u.length!==0&&(t=u+"/"+t,i=u.charCodeAt(0)===47)}return t=e(t,!i),i?t.length>0?"/"+t:"/":t.length>0?t:"."},normalize:function(t){if(r(t),t.length===0)return".";var i=t.charCodeAt(0)===47,s=t.charCodeAt(t.length-1)===47;return t=e(t,!i),t.length===0&&!i&&(t="."),t.length>0&&s&&(t+="/"),i?"/"+t:t},isAbsolute:function(t){return r(t),t.length>0&&t.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var t,i=0;i<arguments.length;++i){var s=arguments[i];r(s),s.length>0&&(t===void 0?t=s:t+="/"+s)}return t===void 0?".":o.normalize(t)},relative:function(t,i){if(r(t),r(i),t===i||(t=o.resolve(t),i=o.resolve(i),t===i))return"";for(var s=1;s<t.length&&t.charCodeAt(s)===47;++s);for(var c=t.length,u=c-s,a=1;a<i.length&&i.charCodeAt(a)===47;++a);for(var f=i.length,l=f-a,d=u<l?u:l,y=-1,h=0;h<=d;++h){if(h===d){if(l>d){if(i.charCodeAt(a+h)===47)return i.slice(a+h+1);if(h===0)return i.slice(a+h)}else u>d&&(t.charCodeAt(s+h)===47?y=h:h===0&&(y=0));break}var b=t.charCodeAt(s+h),k=i.charCodeAt(a+h);if(b!==k)break;b===47&&(y=h)}var m="";for(h=s+y+1;h<=c;++h)(h===c||t.charCodeAt(h)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+i.slice(a+y):(a+=y,i.charCodeAt(a)===47&&++a,i.slice(a))},_makeLong:function(t){return t},dirname:function(t){if(r(t),t.length===0)return".";for(var i=t.charCodeAt(0),s=i===47,c=-1,u=!0,a=t.length-1;a>=1;--a)if(i=t.charCodeAt(a),i===47){if(!u){c=a;break}}else u=!1;return c===-1?s?"/":".":s&&c===1?"//":t.slice(0,c)},basename:function(t,i){if(i!==void 0&&typeof i!="string")throw new TypeError('"ext" argument must be a string');r(t);var s=0,c=-1,u=!0,a;if(i!==void 0&&i.length>0&&i.length<=t.length){if(i.length===t.length&&i===t)return"";var f=i.length-1,l=-1;for(a=t.length-1;a>=0;--a){var d=t.charCodeAt(a);if(d===47){if(!u){s=a+1;break}}else l===-1&&(u=!1,l=a+1),f>=0&&(d===i.charCodeAt(f)?--f===-1&&(c=a):(f=-1,c=l))}return s===c?c=l:c===-1&&(c=t.length),t.slice(s,c)}else{for(a=t.length-1;a>=0;--a)if(t.charCodeAt(a)===47){if(!u){s=a+1;break}}else c===-1&&(u=!1,c=a+1);return c===-1?"":t.slice(s,c)}},extname:function(t){r(t);for(var i=-1,s=0,c=-1,u=!0,a=0,f=t.length-1;f>=0;--f){var l=t.charCodeAt(f);if(l===47){if(!u){s=f+1;break}continue}c===-1&&(u=!1,c=f+1),l===46?i===-1?i=f:a!==1&&(a=1):i!==-1&&(a=-1)}return i===-1||c===-1||a===0||a===1&&i===c-1&&i===s+1?"":t.slice(i,c)},format:function(t){if(t===null||typeof t!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof t);return n("/",t)},parse:function(t){r(t);var i={root:"",dir:"",base:"",ext:"",name:""};if(t.length===0)return i;var s=t.charCodeAt(0),c=s===47,u;c?(i.root="/",u=1):u=0;for(var a=-1,f=0,l=-1,d=!0,y=t.length-1,h=0;y>=u;--y){if(s=t.charCodeAt(y),s===47){if(!d){f=y+1;break}continue}l===-1&&(d=!1,l=y+1),s===46?a===-1?a=y:h!==1&&(h=1):a!==-1&&(h=-1)}return a===-1||l===-1||h===0||h===1&&a===l-1&&a===f+1?l!==-1&&(f===0&&c?i.base=i.name=t.slice(1,l):i.base=i.name=t.slice(f,l)):(f===0&&c?(i.name=t.slice(1,a),i.base=t.slice(1,l)):(i.name=t.slice(f,a),i.base=t.slice(f,l)),i.ext=t.slice(a,l)),f>0?i.dir=t.slice(0,f-1):c&&(i.dir="/"),i},sep:"/",delimiter:":",win32:null,posix:null};return o.posix=o,F=o,F}var D=$();const O=E(D),L=x({__proto__:null,default:O},[D]);function C(r){if(r&&typeof r=="object"){const e=r,n=typeof e.isFile=="function"?e.isFile():typeof e.isFile=="boolean"?e.isFile:e.type==="file"||!e.type&&!e.isDirectory,o=typeof e.isDirectory=="function"?e.isDirectory():typeof e.isDirectory=="boolean"?e.isDirectory:e.type==="dir"||e.type==="directory",t=typeof e.size=="number"?e.size:0;let i;return e.mtime instanceof Date?i=e.mtime:typeof e.mtime=="number"?i=new Date(e.mtime):typeof e.mtimeMs=="number"?i=new Date(e.mtimeMs):i=new Date,{isFile:()=>n,isDirectory:()=>o,isSymbolicLink:()=>!1,size:t,mtime:i}}return{isFile:()=>!0,isDirectory:()=>!1,isSymbolicLink:()=>!1,size:0,mtime:new Date}}class P{constructor(){g(this,"fs"),g(this,"initialized",!1),g(this,"path",L)}async initialize(e={}){if(this.initialized)return;const n=e.name||"fs",o=new I(n,{wipe:e.wipe});this.fs=o.promises,this.initialized=!0}ensureInitialized(){if(!this.initialized)throw new Error("LightningFileSystem is not initialized. Call initialize() first.")}async readFile(e){return this.ensureInitialized(),(await this.fs.readFile(e,{encoding:"utf8"})).toString()}async readFileBuffer(e){return this.ensureInitialized(),this.fs.readFile(e)}async writeFile(e,n){this.ensureInitialized();const o=e.substring(0,e.lastIndexOf("/"));return o&&await this.ensureDir(o),this.fs.writeFile(e,n)}async exists(e){this.ensureInitialized();try{return await this.fs.stat(e),!0}catch{return!1}}async mkdir(e,n){this.ensureInitialized();try{return await this.fs.mkdir(e,n)}catch(o){if(o&&typeof o=="object"&&"code"in o&&o.code!=="EEXIST")throw o}}async readdir(e){return this.ensureInitialized(),this.fs.readdir(e)}async stat(e){this.ensureInitialized();const n=await this.fs.stat(e);return C(n)}async lstat(e){this.ensureInitialized();const n=await this.fs.stat(e);return C(n)}async unlink(e){return this.ensureInitialized(),this.fs.unlink(e)}async rmdir(e){return this.ensureInitialized(),this.fs.rmdir(e)}async copyFile(e,n){this.ensureInitialized();const o=n.substring(0,n.lastIndexOf("/"));o&&await this.ensureDir(o);const t=await this.readFileBuffer(e);return this.writeFile(n,t)}async moveFile(e,n){this.ensureInitialized();const o=n.substring(0,n.lastIndexOf("/"));o&&await this.ensureDir(o),await this.copyFile(e,n),await this.unlink(e)}async ensureDir(e){if(this.ensureInitialized(),!await this.exists(e))try{await this.fs.mkdir(e,{recursive:!0})}catch(n){if(n&&typeof n=="object"&&"code"in n&&n.code!=="EEXIST")throw n}}async removeDir(e){if(this.ensureInitialized(),!await this.exists(e))return;if((await this.stat(e)).isFile())return this.unlink(e);const n=await this.readdir(e);for(const o of n){const t=`${e}/${o}`;await this.removeDir(t)}return this.rmdir(e)}async readDirectory(e){return this.ensureInitialized(),this.fs.readdir(e)}async writeFileSystemFromTree(e,n,o){for(const t of e){const i=this.path.join(n,t.path);if(t.type==="directory")await this.mkdir(i,{recursive:!0}),t.children&&await this.writeFileSystemFromTree(t.children,n,o);else{const s=await o(t.path);await this.writeFile(i,s)}}}}async function _(r){const e=new P;return await e.initialize(r),e}function B(){return"http://localhost:4000"}const p=B();function w(r){let e=r.replace(/^\/+/,"");const n=e.split("/");return n.length>1&&(e=n.slice(1).join("/")),e}function R(){return{async readFile(r){const e=w(r),n=await fetch(`${p}/file?path=${encodeURIComponent(e)}`);if(!n.ok)throw new Error(`Failed to read file ${r}: ${n.statusText}`);const{content:o}=await n.json();return o},async readFileBuffer(r){const e=await this.readFile(r);return Buffer.from(e,"utf-8")},async writeFile(r,e){const n=w(r),o=typeof e=="string"?e:e.toString("utf-8"),t=await fetch(`${p}/file`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n,content:o})});if(!t.ok)throw new Error(`Failed to write file ${r}: ${t.statusText}`)},async exists(r){const e=w(r);try{return(await fetch(`${p}/stat?path=${encodeURIComponent(e)}`)).ok}catch{return!1}},async mkdir(r){},async readdir(r){const e=w(r),n=await fetch(`${p}/files?path=${encodeURIComponent(e)}`);if(!n.ok)throw new Error(`Failed to read directory ${r}: ${n.statusText}`);return(await n.json()).map(o=>o.name)},async stat(r){const e=w(r),n=await fetch(`${p}/stat?path=${encodeURIComponent(e)}`);if(!n.ok)throw new Error(`Failed to stat ${r}: ${n.statusText}`);const{type:o,size:t,mtime:i}=await n.json();return{isFile:()=>o==="file",isDirectory:()=>o==="directory",isSymbolicLink:()=>!1,size:t,mtime:new Date(i)}},async lstat(r){return this.stat(r)},async unlink(r){throw new Error("File deletion not supported in CLI mode")},async rmdir(r){throw new Error("Directory deletion not supported in CLI mode")},async copyFile(r,e){const n=await this.readFile(r);await this.writeFile(e,n)},async moveFile(r,e){await this.copyFile(r,e)},async ensureDir(r){},async removeDir(r){throw new Error("Directory deletion not supported in CLI mode")},async readDirectory(r){return this.readdir(r)},async writeFileSystemFromTree(r,e,n){console.debug("writeFileSystemFromTree called - no-op in CLI mode")}}}async function te(r){return typeof window>"u"?T():r!=null&&r.useCliBackend?R():_(r)}export{R as createCliFS,te as createFS,_ as createLightningFS,T as createNodeFS};
1
+ import{E as I}from"./index-B0p_ycLi.js";import"./_commonjsHelpers-D6-XlEtG.js";import"./index-ChvoNxcO.js";import"./preload-helper-BlTxHScW.js";import"./__vite-browser-external-DLjrMatA.js";import"./inherits_browser-nmOknR35-Bp0mvRSL.js";import"./index-6mKfgpcs-DsgiI2lM.js";import"./_commonjsHelpers-B4e78b8K-W3E8ocG7.js";import"./index-DsIu-45t-Bejjlpz4.js";import"./index-DSosZ5sh-Ceejs_jv.js";import"./index-69shuAsh-DF18H7zf.js";import"./index-BJBOx-Z---hbiLl7B.js";import"./index.browser-BHPvGrwi-6Mh8eUw-.js";import"./_commonjs-dynamic-modules-BpilXLfW-DfYEAvWy.js";import"./_commonjs-dynamic-modules-B7n8ZNar.js";var S=Object.defineProperty,A=(r,e,n)=>e in r?S(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n,g=(r,e,n)=>A(r,typeof e!="symbol"?e+"":e,n);function x(r,e){for(var n=0;n<e.length;n++){const o=e[n];if(typeof o!="string"&&!Array.isArray(o)){for(const t in o)if(t!=="default"&&!(t in r)){const i=Object.getOwnPropertyDescriptor(o,t);i&&Object.defineProperty(r,t,i.get?i:{enumerable:!0,get:()=>o[t]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}function v(r){return{isFile:()=>r.isFile(),isDirectory:()=>r.isDirectory(),isSymbolicLink:()=>r.isSymbolicLink(),size:r.size,mtime:r.mtime}}class j{async readFile(e){return(void 0)(e,"utf8")}async readFileBuffer(e){return(void 0)(e)}async writeFile(e,n){const o=(void 0)(e);return await this.ensureDir(o),(void 0)(e,n)}async exists(e){try{return await(void 0)(e),!0}catch{return!1}}async mkdir(e){try{await(void 0)(e)}catch(n){if(n&&typeof n=="object"&&"code"in n&&n.code!=="EEXIST")throw n}}async readdir(e){return(void 0)(e)}async stat(e){const n=await(void 0)(e);return v(n)}async lstat(e){const n=await(void 0)(e);return v(n)}async unlink(e){return(void 0)(e)}async rmdir(e){return(void 0)(e)}async copyFile(e,n){const o=(void 0)(n);return await this.ensureDir(o),(void 0)(e,n)}async moveFile(e,n){const o=(void 0)(n);return await this.ensureDir(o),(void 0)(e,n)}async ensureDir(e){try{await(void 0)(e,{recursive:!0})}catch(n){if(n&&typeof n=="object"&&"code"in n&&n.code!=="EEXIST")throw n}}async removeDir(e){return(void 0)(e,{recursive:!0,force:!0})}async readDirectory(e){return(void 0)(e)}async writeFileSystemFromTree(e,n,o){for(const t of e){const i=(void 0)(n,t.path);if(t.type==="directory")await this.ensureDir(i),t.children&&await this.writeFileSystemFromTree(t.children,n,o);else{const s=await o(t.path);await this.writeFile(i,s)}}}}function T(){return new j}function E(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var F,z;function $(){if(z)return F;z=1;function r(t){if(typeof t!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(t))}function e(t,i){for(var s="",c=0,u=-1,a=0,f,l=0;l<=t.length;++l){if(l<t.length)f=t.charCodeAt(l);else{if(f===47)break;f=47}if(f===47){if(!(u===l-1||a===1))if(u!==l-1&&a===2){if(s.length<2||c!==2||s.charCodeAt(s.length-1)!==46||s.charCodeAt(s.length-2)!==46){if(s.length>2){var d=s.lastIndexOf("/");if(d!==s.length-1){d===-1?(s="",c=0):(s=s.slice(0,d),c=s.length-1-s.lastIndexOf("/")),u=l,a=0;continue}}else if(s.length===2||s.length===1){s="",c=0,u=l,a=0;continue}}i&&(s.length>0?s+="/..":s="..",c=2)}else s.length>0?s+="/"+t.slice(u+1,l):s=t.slice(u+1,l),c=l-u-1;u=l,a=0}else f===46&&a!==-1?++a:a=-1}return s}function n(t,i){var s=i.dir||i.root,c=i.base||(i.name||"")+(i.ext||"");return s?s===i.root?s+c:s+t+c:c}var o={resolve:function(){for(var t="",i=!1,s,c=arguments.length-1;c>=-1&&!i;c--){var u;c>=0?u=arguments[c]:(s===void 0&&(s=process.cwd()),u=s),r(u),u.length!==0&&(t=u+"/"+t,i=u.charCodeAt(0)===47)}return t=e(t,!i),i?t.length>0?"/"+t:"/":t.length>0?t:"."},normalize:function(t){if(r(t),t.length===0)return".";var i=t.charCodeAt(0)===47,s=t.charCodeAt(t.length-1)===47;return t=e(t,!i),t.length===0&&!i&&(t="."),t.length>0&&s&&(t+="/"),i?"/"+t:t},isAbsolute:function(t){return r(t),t.length>0&&t.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var t,i=0;i<arguments.length;++i){var s=arguments[i];r(s),s.length>0&&(t===void 0?t=s:t+="/"+s)}return t===void 0?".":o.normalize(t)},relative:function(t,i){if(r(t),r(i),t===i||(t=o.resolve(t),i=o.resolve(i),t===i))return"";for(var s=1;s<t.length&&t.charCodeAt(s)===47;++s);for(var c=t.length,u=c-s,a=1;a<i.length&&i.charCodeAt(a)===47;++a);for(var f=i.length,l=f-a,d=u<l?u:l,y=-1,h=0;h<=d;++h){if(h===d){if(l>d){if(i.charCodeAt(a+h)===47)return i.slice(a+h+1);if(h===0)return i.slice(a+h)}else u>d&&(t.charCodeAt(s+h)===47?y=h:h===0&&(y=0));break}var b=t.charCodeAt(s+h),k=i.charCodeAt(a+h);if(b!==k)break;b===47&&(y=h)}var m="";for(h=s+y+1;h<=c;++h)(h===c||t.charCodeAt(h)===47)&&(m.length===0?m+="..":m+="/..");return m.length>0?m+i.slice(a+y):(a+=y,i.charCodeAt(a)===47&&++a,i.slice(a))},_makeLong:function(t){return t},dirname:function(t){if(r(t),t.length===0)return".";for(var i=t.charCodeAt(0),s=i===47,c=-1,u=!0,a=t.length-1;a>=1;--a)if(i=t.charCodeAt(a),i===47){if(!u){c=a;break}}else u=!1;return c===-1?s?"/":".":s&&c===1?"//":t.slice(0,c)},basename:function(t,i){if(i!==void 0&&typeof i!="string")throw new TypeError('"ext" argument must be a string');r(t);var s=0,c=-1,u=!0,a;if(i!==void 0&&i.length>0&&i.length<=t.length){if(i.length===t.length&&i===t)return"";var f=i.length-1,l=-1;for(a=t.length-1;a>=0;--a){var d=t.charCodeAt(a);if(d===47){if(!u){s=a+1;break}}else l===-1&&(u=!1,l=a+1),f>=0&&(d===i.charCodeAt(f)?--f===-1&&(c=a):(f=-1,c=l))}return s===c?c=l:c===-1&&(c=t.length),t.slice(s,c)}else{for(a=t.length-1;a>=0;--a)if(t.charCodeAt(a)===47){if(!u){s=a+1;break}}else c===-1&&(u=!1,c=a+1);return c===-1?"":t.slice(s,c)}},extname:function(t){r(t);for(var i=-1,s=0,c=-1,u=!0,a=0,f=t.length-1;f>=0;--f){var l=t.charCodeAt(f);if(l===47){if(!u){s=f+1;break}continue}c===-1&&(u=!1,c=f+1),l===46?i===-1?i=f:a!==1&&(a=1):i!==-1&&(a=-1)}return i===-1||c===-1||a===0||a===1&&i===c-1&&i===s+1?"":t.slice(i,c)},format:function(t){if(t===null||typeof t!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof t);return n("/",t)},parse:function(t){r(t);var i={root:"",dir:"",base:"",ext:"",name:""};if(t.length===0)return i;var s=t.charCodeAt(0),c=s===47,u;c?(i.root="/",u=1):u=0;for(var a=-1,f=0,l=-1,d=!0,y=t.length-1,h=0;y>=u;--y){if(s=t.charCodeAt(y),s===47){if(!d){f=y+1;break}continue}l===-1&&(d=!1,l=y+1),s===46?a===-1?a=y:h!==1&&(h=1):a!==-1&&(h=-1)}return a===-1||l===-1||h===0||h===1&&a===l-1&&a===f+1?l!==-1&&(f===0&&c?i.base=i.name=t.slice(1,l):i.base=i.name=t.slice(f,l)):(f===0&&c?(i.name=t.slice(1,a),i.base=t.slice(1,l)):(i.name=t.slice(f,a),i.base=t.slice(f,l)),i.ext=t.slice(a,l)),f>0?i.dir=t.slice(0,f-1):c&&(i.dir="/"),i},sep:"/",delimiter:":",win32:null,posix:null};return o.posix=o,F=o,F}var D=$();const O=E(D),L=x({__proto__:null,default:O},[D]);function C(r){if(r&&typeof r=="object"){const e=r,n=typeof e.isFile=="function"?e.isFile():typeof e.isFile=="boolean"?e.isFile:e.type==="file"||!e.type&&!e.isDirectory,o=typeof e.isDirectory=="function"?e.isDirectory():typeof e.isDirectory=="boolean"?e.isDirectory:e.type==="dir"||e.type==="directory",t=typeof e.size=="number"?e.size:0;let i;return e.mtime instanceof Date?i=e.mtime:typeof e.mtime=="number"?i=new Date(e.mtime):typeof e.mtimeMs=="number"?i=new Date(e.mtimeMs):i=new Date,{isFile:()=>n,isDirectory:()=>o,isSymbolicLink:()=>!1,size:t,mtime:i}}return{isFile:()=>!0,isDirectory:()=>!1,isSymbolicLink:()=>!1,size:0,mtime:new Date}}class P{constructor(){g(this,"fs"),g(this,"initialized",!1),g(this,"path",L)}async initialize(e={}){if(this.initialized)return;const n=e.name||"fs",o=new I(n,{wipe:e.wipe});this.fs=o.promises,this.initialized=!0}ensureInitialized(){if(!this.initialized)throw new Error("LightningFileSystem is not initialized. Call initialize() first.")}async readFile(e){return this.ensureInitialized(),(await this.fs.readFile(e,{encoding:"utf8"})).toString()}async readFileBuffer(e){return this.ensureInitialized(),this.fs.readFile(e)}async writeFile(e,n){this.ensureInitialized();const o=e.substring(0,e.lastIndexOf("/"));return o&&await this.ensureDir(o),this.fs.writeFile(e,n)}async exists(e){this.ensureInitialized();try{return await this.fs.stat(e),!0}catch{return!1}}async mkdir(e,n){this.ensureInitialized();try{return await this.fs.mkdir(e,n)}catch(o){if(o&&typeof o=="object"&&"code"in o&&o.code!=="EEXIST")throw o}}async readdir(e){return this.ensureInitialized(),this.fs.readdir(e)}async stat(e){this.ensureInitialized();const n=await this.fs.stat(e);return C(n)}async lstat(e){this.ensureInitialized();const n=await this.fs.stat(e);return C(n)}async unlink(e){return this.ensureInitialized(),this.fs.unlink(e)}async rmdir(e){return this.ensureInitialized(),this.fs.rmdir(e)}async copyFile(e,n){this.ensureInitialized();const o=n.substring(0,n.lastIndexOf("/"));o&&await this.ensureDir(o);const t=await this.readFileBuffer(e);return this.writeFile(n,t)}async moveFile(e,n){this.ensureInitialized();const o=n.substring(0,n.lastIndexOf("/"));o&&await this.ensureDir(o),await this.copyFile(e,n),await this.unlink(e)}async ensureDir(e){if(this.ensureInitialized(),!await this.exists(e))try{await this.fs.mkdir(e,{recursive:!0})}catch(n){if(n&&typeof n=="object"&&"code"in n&&n.code!=="EEXIST")throw n}}async removeDir(e){if(this.ensureInitialized(),!await this.exists(e))return;if((await this.stat(e)).isFile())return this.unlink(e);const n=await this.readdir(e);for(const o of n){const t=`${e}/${o}`;await this.removeDir(t)}return this.rmdir(e)}async readDirectory(e){return this.ensureInitialized(),this.fs.readdir(e)}async writeFileSystemFromTree(e,n,o){for(const t of e){const i=this.path.join(n,t.path);if(t.type==="directory")await this.mkdir(i,{recursive:!0}),t.children&&await this.writeFileSystemFromTree(t.children,n,o);else{const s=await o(t.path);await this.writeFile(i,s)}}}}async function _(r){const e=new P;return await e.initialize(r),e}function B(){return"http://localhost:4000"}const p=B();function w(r){let e=r.replace(/^\/+/,"");const n=e.split("/");return n.length>1&&(e=n.slice(1).join("/")),e}function R(){return{async readFile(r){const e=w(r),n=await fetch(`${p}/file?path=${encodeURIComponent(e)}`);if(!n.ok)throw new Error(`Failed to read file ${r}: ${n.statusText}`);const{content:o}=await n.json();return o},async readFileBuffer(r){const e=await this.readFile(r);return Buffer.from(e,"utf-8")},async writeFile(r,e){const n=w(r),o=typeof e=="string"?e:e.toString("utf-8"),t=await fetch(`${p}/file`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n,content:o})});if(!t.ok)throw new Error(`Failed to write file ${r}: ${t.statusText}`)},async exists(r){const e=w(r);try{return(await fetch(`${p}/stat?path=${encodeURIComponent(e)}`)).ok}catch{return!1}},async mkdir(r){},async readdir(r){const e=w(r),n=await fetch(`${p}/files?path=${encodeURIComponent(e)}`);if(!n.ok)throw new Error(`Failed to read directory ${r}: ${n.statusText}`);return(await n.json()).map(o=>o.name)},async stat(r){const e=w(r),n=await fetch(`${p}/stat?path=${encodeURIComponent(e)}`);if(!n.ok)throw new Error(`Failed to stat ${r}: ${n.statusText}`);const{type:o,size:t,mtime:i}=await n.json();return{isFile:()=>o==="file",isDirectory:()=>o==="directory",isSymbolicLink:()=>!1,size:t,mtime:new Date(i)}},async lstat(r){return this.stat(r)},async unlink(r){throw new Error("File deletion not supported in CLI mode")},async rmdir(r){throw new Error("Directory deletion not supported in CLI mode")},async copyFile(r,e){const n=await this.readFile(r);await this.writeFile(e,n)},async moveFile(r,e){await this.copyFile(r,e)},async ensureDir(r){},async removeDir(r){throw new Error("Directory deletion not supported in CLI mode")},async readDirectory(r){return this.readdir(r)},async writeFileSystemFromTree(r,e,n){console.debug("writeFileSystemFromTree called - no-op in CLI mode")}}}async function te(r){return typeof window>"u"?T():r!=null&&r.useCliBackend?R():_(r)}export{R as createCliFS,te as createFS,_ as createLightningFS,T as createNodeFS};