inistate-core 0.1.0 → 0.1.1
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/LICENSE +14 -3
- package/README.md +3 -3
- package/dist/index.js +4 -4
- package/package.json +11 -3
package/LICENSE
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
INISTATE CORE — FREE-USE END USER LICENSE AGREEMENT
|
|
2
|
-
Version 1.
|
|
2
|
+
Version 1.1
|
|
3
3
|
|
|
4
4
|
Copyright (c) GNEY SOFTWARE PTE LTD. All rights reserved.
|
|
5
5
|
|
|
@@ -30,8 +30,19 @@ this Agreement grants no rights to its source code.
|
|
|
30
30
|
official published package for installation by end users under this
|
|
31
31
|
Agreement;
|
|
32
32
|
(d) remove or alter any proprietary notices, labels, or this Agreement;
|
|
33
|
-
(e) use the Software
|
|
34
|
-
|
|
33
|
+
(e) use the Software, its output, or any behavior, interface, data schema,
|
|
34
|
+
structure, know-how, or other information observed in or derived from it,
|
|
35
|
+
to design, develop, train, market, distribute, or operate any product,
|
|
36
|
+
service, model, or platform that competes with, or is intended as a
|
|
37
|
+
substitute for, the Software or the Inistate Platform;
|
|
38
|
+
(f) use the Software to provide to any third party — whether for a fee or
|
|
39
|
+
free of charge — a workflow, state-machine, process-automation, low-code,
|
|
40
|
+
or backend-as-a-service offering that substitutes for the Inistate
|
|
41
|
+
Platform;
|
|
42
|
+
(g) use the Software to conduct competitive analysis or benchmarking for the
|
|
43
|
+
purpose of building a competing product or service, or publish or
|
|
44
|
+
disclose the results of any such benchmarking, in each case without
|
|
45
|
+
Licensor's prior written consent.
|
|
35
46
|
|
|
36
47
|
3. OPEN COMPONENTS
|
|
37
48
|
The Software embeds and is designed to interoperate with separately published
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# inistate-core
|
|
2
2
|
|
|
3
|
-
**A free, local runtime for
|
|
3
|
+
**A free, local runtime for governed state-machine workflows — the deterministic floor of the Inistate stack.**
|
|
4
4
|
|
|
5
5
|
`inistate-core` runs governed state-machine workflows on persistence *you* control, driven over the [Model Context Protocol](https://modelcontextprotocol.io). One command, zero config, no account, no token, no network. Any MCP-compatible agent can drive it.
|
|
6
6
|
|
|
@@ -228,7 +228,7 @@ Build your own substrate adapter by implementing a small async `SubstrateDriver`
|
|
|
228
228
|
|
|
229
229
|
## Scaffold a schema from an existing table
|
|
230
230
|
|
|
231
|
-
Already have a Notion database, Airtable table, or SQLite table? Generate a starter
|
|
231
|
+
Already have a Notion database, Airtable table, or SQLite table? Generate a starter module schema from it — columns become typed fields, and a detected status column becomes states:
|
|
232
232
|
|
|
233
233
|
```bash
|
|
234
234
|
inistate-core scaffold notion://<databaseId> # needs INISTATE_NOTION_TOKEN
|
|
@@ -278,6 +278,6 @@ The engine and storage adapters are kept clean of governance/UI/history concepts
|
|
|
278
278
|
|
|
279
279
|
## License
|
|
280
280
|
|
|
281
|
-
`inistate-core` is **free to use** but **not open source**. It ships under a proprietary free-use EULA (see [LICENSE](LICENSE)): run it anywhere, forever, at no cost — including in production — but the engine source is closed and no patent rights are granted. The embedded Inistate schema and MCP server are separately published under MIT.
|
|
281
|
+
`inistate-core` is **free to use** but **not open source**. It ships under a proprietary free-use EULA (see [LICENSE](https://github.com/Inistate/inistate-core/blob/main/LICENSE)): run it anywhere, forever, at no cost — including in production — but the engine source is closed and no patent rights are granted. The embedded Inistate schema and MCP server are separately published under MIT.
|
|
282
282
|
|
|
283
283
|
© GNEY SOFTWARE PTE LTD.
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*!
|
|
3
|
-
* inistate-core v0.1.
|
|
3
|
+
* inistate-core v0.1.1
|
|
4
4
|
* Copyright (c) GNEY SOFTWARE PTE LTD. All rights reserved.
|
|
5
5
|
* Use governed by the Inistate Core Free-Use EULA (see LICENSE).
|
|
6
6
|
* Copying, redistribution, and reverse engineering are restricted.
|
|
@@ -225,7 +225,7 @@ expect: `+t.props.size+`
|
|
|
225
225
|
actual: `+t._bytesEmitted)}),e.on("close",function(){t._paused||t._buffer.length?(t._buffer.push(aX),t._read()):t.emit("close")}),e.on("error",function(r){t.emit("error",r)}),t._read()};Xa.prototype._read=function(){var t=this;if(!t._paused){if(!t._stream)return t._getStream();if(t._buffer.length){for(var e=t._buffer,r=0,i=e.length;r<i;r++){var n=e[r];if(n===sX?t.emit("end"):n===aX?t.emit("close"):t.emit("data",n),t._paused){t._buffer=e.slice(r);return}}t._buffer.length=0}}};Xa.prototype.pause=function(t){var e=this;e._paused||(t=t||e,e._paused=!0,e._stream&&e._stream.pause(),e.emit("pause",t))};Xa.prototype.resume=function(t){var e=this;e._paused&&(t=t||e,e.emit("resume",t),e._paused=!1,e._stream&&e._stream.resume(),e._read())}});var fX=w((mPe,uX)=>{uX.exports=gy;var PEe=be(),lX=za();PEe(gy,lX);function gy(t){var e=this;if(!(e instanceof gy))throw new Error("SocketReader must be called as constructor.");if(!(t.type==="Socket"&&t.Socket))throw new Error("Non-socket type "+t.type);lX.call(e,t)}gy.prototype._read=function(){var t=this;t._paused||t._ended||(t.emit("end"),t.emit("close"),t._ended=!0)}});var pk=w((yPe,cX)=>{cX.exports=Va;var dk=za(),qEe=Hc(),LEe=be(),BEe=Er();LEe(Va,dk);function Va(t){var e=this;if(!(e instanceof Va))throw new Error("ProxyReader must be called as constructor.");e.props=t,e._buffer=[],e.ready=!1,dk.call(e,t)}Va.prototype._stat=function(){var t=this,e=t.props,r=e.follow?"stat":"lstat";BEe[r](e.path,function(i,n){var s;i||!n?s="File":s=qEe(n),e[s]=!0,e.type=t.type=s,t._old=n,t._addProxy(dk(e,n))})};Va.prototype._addProxy=function(t){var e=this;if(e._proxyTarget)return e.error("proxy already set");e._proxyTarget=t,t._proxy=e,["error","data","end","close","linkpath","entry","entryEnd","child","childEnd","warn","stat"].forEach(function(i){t.on(i,e.emit.bind(e,i))}),e.emit("proxy",t),t.on("ready",function(){e.ready=!0,e.emit("ready")});var r=e._buffer;e._buffer.length=0,r.forEach(function(i){t[i[0]].apply(t,i[1])})};Va.prototype.pause=function(){return this._proxyTarget?this._proxyTarget.pause():!1};Va.prototype.resume=function(){return this._proxyTarget?this._proxyTarget.resume():!1}});var za=w((vPe,pX)=>{pX.exports=gi;var jEe=Er(),$Ee=Y("stream").Stream,UEe=be(),gk=Y("path"),mk=Hc(),my=gi.hardLinks={},hX=py();UEe(gi,hX);var dX=uk();function gi(t,e){var r=this;if(!(r instanceof gi))return new gi(t,e);typeof t=="string"&&(t={path:t});var i,n;switch(t.type&&typeof t.type=="function"?(i=t.type,n=i):(i=mk(t),n=gi),e&&!i&&(i=mk(e),t[i]=!0,t.type=i),i){case"Directory":n=ck();break;case"Link":case"File":n=hk();break;case"SymbolicLink":n=dX;break;case"Socket":n=fX();break;case null:n=pk();break}if(!(r instanceof n))return new n(t);hX.call(r),t.path||r.error("Must provide a path",null,!0),r.readable=!0,r.writable=!1,r.type=i,r.props=t,r.depth=t.depth=t.depth||0,r.parent=t.parent||null,r.root=t.root||t.parent&&t.parent.root||r,r._path=r.path=gk.resolve(t.path),process.platform==="win32"&&(r.path=r._path=r.path.replace(/\?/g,"_"),r._path.length>=260&&(r._swallowErrors=!0,r._path="\\\\?\\"+r.path.replace(/\//g,"\\"))),r.basename=t.basename=gk.basename(r.path),r.dirname=t.dirname=gk.dirname(r.path),t.parent=t.root=null,r.size=t.size,r.filter=typeof t.filter=="function"?t.filter:null,t.sort==="alpha"&&(t.sort=WEe),r._stat(e)}function WEe(t,e){return t===e?0:t.toLowerCase()>e.toLowerCase()?1:t.toLowerCase()<e.toLowerCase()?-1:t>e?1:-1}gi.prototype._stat=function(t){var e=this,r=e.props,i=r.follow?"stat":"lstat";t?process.nextTick(n.bind(null,null,t)):jEe[i](e._path,n);function n(s,a){if(s)return e.error(s);if(Object.keys(a).forEach(function(p){r[p]=a[p]}),e.size!==void 0&&r.size!==e.size)return e.error("incorrect size");e.size=r.size;var o=mk(r),u=r.hardlinks!==!1;if(u&&o!=="Directory"&&r.nlink&&r.nlink>1){var f=r.dev+":"+r.ino;my[f]===e._path||!my[f]?my[f]=e._path:(o=e.type=e.props.type="Link",e.Link=e.props.Link=!0,e.linkpath=e.props.linkpath=my[f],e._stat=e._read=dX.prototype._read)}if(e.type&&e.type!==o&&e.error("Unexpected type: "+o),e.filter){var c=e._proxy||e;if(!e.filter.call(c,c,r)){e._disowned||(e.abort(),e.emit("end"),e.emit("close"));return}}var h=["_stat","stat","ready"],d=0;(function p(){if(e._aborted){e.emit("end"),e.emit("close");return}if(e._paused&&e.type!=="Directory"){e.once("resume",p);return}var g=h[d++];if(!g)return e._read();e.emit(g,r),p()})()}};gi.prototype.pipe=function(t){var e=this;return typeof t.add=="function"&&e.on("entry",function(r){var i=t.add(r);i===!1&&e.pause()}),$Ee.prototype.pipe.apply(this,arguments)};gi.prototype.pause=function(t){this._paused=!0,t=t||this,this.emit("pause",t),this._stream&&this._stream.pause(t)};gi.prototype.resume=function(t){this._paused=!1,t=t||this,this.emit("resume",t),this._stream&&this._stream.resume(t),this._read()};gi.prototype._read=function(){this.error("Cannot read unknown type: "+this.type)}});var wk=w((_Pe,xX)=>{xX.exports=_k;_k.sync=bX;var Xe=Y("assert"),vX=Y("path"),gX=Y("fs"),tu=void 0;try{tu=cc()}catch{}var _X=parseInt("666",8),HEe={nosort:!0,silent:!0},yk=0,Vc=process.platform==="win32";function wX(t){var e=["unlink","chmod","stat","lstat","rmdir","readdir"];if(e.forEach(function(r){t[r]=t[r]||gX[r],r=r+"Sync",t[r]=t[r]||gX[r]}),t.maxBusyTries=t.maxBusyTries||3,t.emfileWait=t.emfileWait||1e3,t.glob===!1&&(t.disableGlob=!0),t.disableGlob!==!0&&tu===void 0)throw Error("glob dependency not found, set `options.disableGlob = true` if intentional");t.disableGlob=t.disableGlob||!1,t.glob=t.glob||HEe}function _k(t,e,r){typeof e=="function"&&(r=e,e={}),Xe(t,"rimraf: missing path"),Xe.equal(typeof t,"string","rimraf: path should be a string"),Xe.equal(typeof r,"function","rimraf: callback function required"),Xe(e,"rimraf: invalid options argument provided"),Xe.equal(typeof e,"object","rimraf: options should be object"),wX(e);var i=0,n=null,s=0;if(e.disableGlob||!tu.hasMagic(t))return o(null,[t]);e.lstat(t,function(u,f){if(!u)return o(null,[t]);tu(t,e.glob,o)});function a(u){n=n||u,--s===0&&r(n)}function o(u,f){if(u)return r(u);if(s=f.length,s===0)return r();f.forEach(function(c){vk(c,e,function h(d){if(d){if((d.code==="EBUSY"||d.code==="ENOTEMPTY"||d.code==="EPERM")&&i<e.maxBusyTries){i++;var p=i*100;return setTimeout(function(){vk(c,e,h)},p)}if(d.code==="EMFILE"&&yk<e.emfileWait)return setTimeout(function(){vk(c,e,h)},yk++);d.code==="ENOENT"&&(d=null)}yk=0,a(d)})})}}function vk(t,e,r){Xe(t),Xe(e),Xe(typeof r=="function"),e.lstat(t,function(i,n){if(i&&i.code==="ENOENT")return r(null);if(i&&i.code==="EPERM"&&Vc&&mX(t,e,i,r),n&&n.isDirectory())return yy(t,e,i,r);e.unlink(t,function(s){if(s){if(s.code==="ENOENT")return r(null);if(s.code==="EPERM")return Vc?mX(t,e,s,r):yy(t,e,s,r);if(s.code==="EISDIR")return yy(t,e,s,r)}return r(s)})})}function mX(t,e,r,i){Xe(t),Xe(e),Xe(typeof i=="function"),r&&Xe(r instanceof Error),e.chmod(t,_X,function(n){n?i(n.code==="ENOENT"?null:r):e.stat(t,function(s,a){s?i(s.code==="ENOENT"?null:r):a.isDirectory()?yy(t,e,r,i):e.unlink(t,i)})})}function yX(t,e,r){Xe(t),Xe(e),r&&Xe(r instanceof Error);try{e.chmodSync(t,_X)}catch(n){if(n.code==="ENOENT")return;throw r}try{var i=e.statSync(t)}catch(n){if(n.code==="ENOENT")return;throw r}i.isDirectory()?vy(t,e,r):e.unlinkSync(t)}function yy(t,e,r,i){Xe(t),Xe(e),r&&Xe(r instanceof Error),Xe(typeof i=="function"),e.rmdir(t,function(n){n&&(n.code==="ENOTEMPTY"||n.code==="EEXIST"||n.code==="EPERM")?zEe(t,e,i):n&&n.code==="ENOTDIR"?i(r):i(n)})}function zEe(t,e,r){Xe(t),Xe(e),Xe(typeof r=="function"),e.readdir(t,function(i,n){if(i)return r(i);var s=n.length;if(s===0)return e.rmdir(t,r);var a;n.forEach(function(o){_k(vX.join(t,o),e,function(u){if(!a){if(u)return r(a=u);--s===0&&e.rmdir(t,r)}})})})}function bX(t,e){e=e||{},wX(e),Xe(t,"rimraf: missing path"),Xe.equal(typeof t,"string","rimraf: path should be a string"),Xe(e,"rimraf: missing options"),Xe.equal(typeof e,"object","rimraf: options should be object");var r;if(e.disableGlob||!tu.hasMagic(t))r=[t];else try{e.lstatSync(t),r=[t]}catch{r=tu.sync(t,e.glob)}if(r.length)for(var i=0;i<r.length;i++){var t=r[i];try{var n=e.lstatSync(t)}catch(a){if(a.code==="ENOENT")return;a.code==="EPERM"&&Vc&&yX(t,e,a)}try{n&&n.isDirectory()?vy(t,e,null):e.unlinkSync(t)}catch(a){if(a.code==="ENOENT")return;if(a.code==="EPERM")return Vc?yX(t,e,a):vy(t,e,a);if(a.code!=="EISDIR")throw a;vy(t,e,a)}}}function vy(t,e,r){Xe(t),Xe(e),r&&Xe(r instanceof Error);try{e.rmdirSync(t)}catch(i){if(i.code==="ENOENT")return;if(i.code==="ENOTDIR")throw r;(i.code==="ENOTEMPTY"||i.code==="EEXIST"||i.code==="EPERM")&&XEe(t,e)}}function XEe(t,e){Xe(t),Xe(e),e.readdirSync(t).forEach(function(a){bX(vX.join(t,a),e)});var r=Vc?100:1,i=0;do{var n=!0;try{var s=e.rmdirSync(t,e);return n=!1,s}finally{if(++i<r&&n)continue}}while(!0)}});var bk=w((wPe,TX)=>{var Gc=Y("path"),SX=Y("fs"),EX=parseInt("0777",8);TX.exports=ru.mkdirp=ru.mkdirP=ru;function ru(t,e,r,i){typeof e=="function"?(r=e,e={}):(!e||typeof e!="object")&&(e={mode:e});var n=e.mode,s=e.fs||SX;n===void 0&&(n=EX),i||(i=null);var a=r||function(){};t=Gc.resolve(t),s.mkdir(t,n,function(o){if(!o)return i=i||t,a(null,i);switch(o.code){case"ENOENT":if(Gc.dirname(t)===t)return a(o);ru(Gc.dirname(t),e,function(u,f){u?a(u,f):ru(t,e,a,f)});break;default:s.stat(t,function(u,f){u||!f.isDirectory()?a(o,i):a(null,i)});break}})}ru.sync=function t(e,r,i){(!r||typeof r!="object")&&(r={mode:r});var n=r.mode,s=r.fs||SX;n===void 0&&(n=EX),i||(i=null),e=Gc.resolve(e);try{s.mkdirSync(e,n),i=i||e}catch(o){switch(o.code){case"ENOENT":i=t(Gc.dirname(e),r,i),t(e,r,i);break;default:var a;try{a=s.statSync(e)}catch{throw o}if(!a.isDirectory())throw o;break}}return i}});var _y=w((bPe,CX)=>{CX.exports=xk;function xk(t){if(t._collected)return;if(t._paused)return t.on("resume",xk.bind(null,t));t._collected=!0,t.pause(),t.on("data",r),t.on("end",r);var e=[];function r(a){typeof a=="string"&&(a=new Buffer(a)),!(Buffer.isBuffer(a)&&!a.length)&&e.push(a)}t.on("entry",n);var i=[];function n(a){xk(a),i.push(a)}t.on("proxy",s);function s(a){a.pause()}t.pipe=(function(a){return function(o){var u=0;(function c(){var h=i[u++];if(!h)return f();h.on("end",c),o?o.add(h):t.emit("entry",h)})();function f(){t.removeListener("entry",n),t.removeListener("data",r),t.removeListener("end",r),t.pipe=a,o&&t.pipe(o),e.forEach(function(c){c?t.emit("data",c):t.emit("end")}),t.resume()}return o}})(t.pipe)}});var Sk=w((xPe,RX)=>{RX.exports=Rs;var wy=iu(),VEe=be(),GEe=bk(),kX=Y("path"),ZEe=_y();VEe(Rs,wy);function Rs(t){var e=this;e instanceof Rs||e.error("DirWriter must be called as constructor.",null,!0),(t.type!=="Directory"||!t.Directory)&&e.error("Non-directory type "+t.type+" "+JSON.stringify(t),null,!0),wy.call(this,t)}Rs.prototype._create=function(){var t=this;GEe(t._path,wy.dirmode,function(e){if(e)return t.error(e);t.ready=!0,t.emit("ready"),t._process()})};Rs.prototype.write=function(){return!0};Rs.prototype.end=function(){this._ended=!0,this._process()};Rs.prototype.add=function(t){var e=this;return ZEe(t),!e.ready||e._currentEntry?(e._buffer.push(t),!1):e._ended?e.error("add after end"):(e._buffer.push(t),e._process(),this._buffer.length===0)};Rs.prototype._process=function(){var t=this;if(t._processing)return;var e=t._buffer.shift();if(!e){t.emit("drain"),t._ended&&t._finish();return}t._processing=!0,t.emit("entry",e);var r=e,i;do{if(i=r._path||r.path,i===t.root._path||i===t._path||i&&i.indexOf(t._path)===0)return t._processing=!1,e._collected&&e.pipe(),t._process();r=r.parent}while(r);var n={parent:t,root:t.root||t,type:e.type,depth:t.depth+1};i=e._path||e.path||e.props.path,e.parent&&(i=i.substr(e.parent._path.length+1)),n.path=kX.join(t.path,kX.join("/",i)),n.filter=t.filter,Object.keys(e.props).forEach(function(u){n.hasOwnProperty(u)||(n[u]=e.props[u])});var s=t._currentChild=new wy(n);s.on("ready",function(){e.pipe(s),e.resume()}),s.on("error",function(u){s._swallowErrors?(t.warn(u),s.emit("end"),s.emit("close")):t.emit("error",u)}),s.on("close",o);var a=!1;function o(){a||(a=!0,t._currentChild=null,t._processing=!1,t._process())}}});var Ek=w((SPe,DX)=>{DX.exports=Zc;var OX=Er(),IX=iu(),YEe=be(),KEe=Y("path"),QEe=wk();YEe(Zc,IX);function Zc(t){var e=this;if(!(e instanceof Zc))throw new Error("LinkWriter must be called as constructor.");if(!(t.type==="Link"&&t.Link||t.type==="SymbolicLink"&&t.SymbolicLink))throw new Error("Non-link type "+t.type);t.linkpath===""&&(t.linkpath="."),t.linkpath||e.error("Need linkpath property to create "+t.type),IX.call(this,t)}Zc.prototype._create=function(){var t=this,e=t.type==="Link"||process.platform==="win32",r=e?"link":"symlink",i=e?KEe.resolve(t.dirname,t.linkpath):t.linkpath;if(e)return AX(t,i,r);OX.readlink(t._path,function(n,s){if(s&&s===i)return NX(t);AX(t,i,r)})};function AX(t,e,r){QEe(t._path,function(i){if(i)return t.error(i);JEe(t,e,r)})}function JEe(t,e,r){OX[r](e,t._path,function(i){if(i)if((i.code==="ENOENT"||i.code==="EACCES"||i.code==="EPERM")&&process.platform==="win32")t.ready=!0,t.emit("ready"),t.emit("end"),t.emit("close"),t.end=t._finish=function(){};else return t.error(i);NX(t)})}function NX(t){t.ready=!0,t.emit("ready"),t._ended&&!t._finished&&t._finish()}Zc.prototype.end=function(){this._ended=!0,this.ready&&(this._finished=!0,this._finish())}});var Tk=w((EPe,MX)=>{MX.exports=Ga;var eTe=Er(),by=iu(),tTe=be(),FX={};tTe(Ga,by);function Ga(t){var e=this;if(!(e instanceof Ga))throw new Error("FileWriter must be called as constructor.");if(t.type!=="File"||!t.File)throw new Error("Non-file type "+t.type);e._buffer=[],e._bytesWritten=0,by.call(this,t)}Ga.prototype._create=function(){var t=this;if(!t._stream){var e={};t.props.flags&&(e.flags=t.props.flags),e.mode=by.filemode,t._old&&t._old.blksize&&(e.bufferSize=t._old.blksize),t._stream=eTe.createWriteStream(t._path,e),t._stream.on("open",function(){t.ready=!0,t._buffer.forEach(function(r){r===FX?t._stream.end():t._stream.write(r)}),t.emit("ready"),t.emit("drain")}),t._stream.on("error",function(r){t.emit("error",r)}),t._stream.on("drain",function(){t.emit("drain")}),t._stream.on("close",function(){t._finish()})}};Ga.prototype.write=function(t){var e=this;if(e._bytesWritten+=t.length,!e.ready){if(!Buffer.isBuffer(t)&&typeof t!="string")throw new Error("invalid write data");return e._buffer.push(t),!1}var r=e._stream.write(t);return r===!1&&e._stream._queue?e._stream._queue.length<=2:r};Ga.prototype.end=function(t){var e=this;return t&&e.write(t),e.ready?e._stream.end():(e._buffer.push(FX),!1)};Ga.prototype._finish=function(){var t=this;typeof t.size=="number"&&t._bytesWritten!==t.size&&t.error(`Did not get expected byte count.
|
|
226
226
|
expect: `+t.size+`
|
|
227
227
|
actual: `+t._bytesWritten),by.prototype._finish.call(t)}});var kk=w((TPe,PX)=>{PX.exports=As;var Ck=iu(),rTe=Hc(),iTe=be(),nTe=_y(),sTe=Y("fs");iTe(As,Ck);function As(t){var e=this;if(!(e instanceof As))throw new Error("ProxyWriter must be called as constructor.");e.props=t,e._needDrain=!1,Ck.call(e,t)}As.prototype._stat=function(){var t=this,e=t.props,r=e.follow?"stat":"lstat";sTe[r](e.path,function(i,n){var s;i||!n?s="File":s=rTe(n),e[s]=!0,e.type=t.type=s,t._old=n,t._addProxy(Ck(e,n))})};As.prototype._addProxy=function(t){var e=this;if(e._proxy)return e.error("proxy already set");e._proxy=t,["ready","error","close","pipe","drain","warn"].forEach(function(i){t.on(i,e.emit.bind(e,i))}),e.emit("proxy",t);var r=e._buffer;r.forEach(function(i){t[i[0]].apply(t,i[1])}),e._buffer.length=0,e._needsDrain&&e.emit("drain")};As.prototype.add=function(t){return nTe(t),this._proxy?this._proxy.add(t):(this._buffer.push(["add",[t]]),this._needDrain=!0,!1)};As.prototype.write=function(t){return this._proxy?this._proxy.write(t):(this._buffer.push(["write",[t]]),this._needDrain=!0,!1)};As.prototype.end=function(t){return this._proxy?this._proxy.end(t):(this._buffer.push(["end",[t]]),!1)}});var iu=w((CPe,zX)=>{zX.exports=ei;var Jr=Er(),aTe=be(),oTe=wk(),lTe=bk(),Yc=Y("path"),LX=process.platform==="win32"?0:process.umask(),BX=Hc(),jX=py();aTe(ei,jX);ei.dirmode=parseInt("0777",8)&~LX;ei.filemode=parseInt("0666",8)&~LX;var uTe=Sk(),fTe=Ek(),cTe=Tk(),hTe=kk();function ei(t,e){var r=this;typeof t=="string"&&(t={path:t});var i=BX(t),n=ei;switch(i){case"Directory":n=uTe;break;case"File":n=cTe;break;case"Link":case"SymbolicLink":n=fTe;break;default:n=hTe;break}if(!(r instanceof n))return new n(t);jX.call(r),t.path||r.error("Must provide a path",null,!0),r.type=t.type,r.props=t,r.depth=t.depth||0,r.clobber=t.clobber===!1?t.clobber:!0,r.parent=t.parent||null,r.root=t.root||t.parent&&t.parent.root||r,r._path=r.path=Yc.resolve(t.path),process.platform==="win32"&&(r.path=r._path=r.path.replace(/\?/g,"_"),r._path.length>=260&&(r._swallowErrors=!0,r._path="\\\\?\\"+r.path.replace(/\//g,"\\"))),r.basename=Yc.basename(t.path),r.dirname=Yc.dirname(t.path),r.linkpath=t.linkpath||null,t.parent=t.root=null,r.size=t.size,typeof t.mode=="string"&&(t.mode=parseInt(t.mode,8)),r.readable=!1,r.writable=!0,r._buffer=[],r.ready=!1,r.filter=typeof t.filter=="function"?t.filter:null,r._stat(e)}ei.prototype._create=function(){var t=this;Jr[t.props.follow?"stat":"lstat"](t._path,function(e){if(e)return t.warn("Cannot create "+t._path+`
|
|
228
|
-
Unsupported type: `+t.type,"ENOTSUP");t._finish()})};ei.prototype._stat=function(t){var e=this,r=e.props,i=r.follow?"stat":"lstat",n=e._proxy||e;t?s(null,t):Jr[i](e._path,s);function s(a,o){if(e.filter&&!e.filter.call(n,n,o)){e._aborted=!0,e.emit("end"),e.emit("close");return}if(a||!o)return Rk(e);e._old=o;var u=BX(o);if(u!==e.type||e.type==="File"&&o.nlink>1)return oTe(e._path,function(f){if(f)return e.error(f);e._old=null,Rk(e)});Rk(e)}};function Rk(t){lTe(Yc.dirname(t._path),ei.dirmode,function(e,r){return e?t.error(e):(t._madeDir=r,t._create())})}function $X(t,e,r,i,n){var s=e.mode,a=e.follow||t.type!=="SymbolicLink"?"chmod":"lchmod";if(!Jr[a]||typeof s!="number")return n();var o=r.mode&parseInt("0777",8);if(s=s&parseInt("0777",8),s===o)return n();Jr[a](i,s,n)}function UX(t,e,r,i,n){if(process.platform==="win32"||!process.getuid||process.getuid()!==0||typeof e.uid!="number"&&typeof e.gid!="number"||r.uid===e.uid&&r.gid===e.gid)return n();var s=t.props.follow||t.type!=="SymbolicLink"?"chown":"lchown";if(!Jr[s])return n();typeof e.uid!="number"&&(e.uid=r.uid),typeof e.gid!="number"&&(e.gid=r.gid),Jr[s](i,e.uid,e.gid,n)}function WX(t,e,r,i,n){if(!Jr.utimes||process.platform==="win32")return n();var s=e.follow||t.type!=="SymbolicLink"?"utimes":"lutimes";if(s==="lutimes"&&!Jr[s]&&(s="utimes"),!Jr[s])return n();var a=r.atime,o=r.mtime,u=e.atime,f=e.mtime;if(u===void 0&&(u=a),f===void 0&&(f=o),qX(u)||(u=new Date(u)),qX(f)||(u=new Date(f)),u.getTime()===a.getTime()&&f.getTime()===o.getTime())return n();Jr[s](i,u,f,n)}ei.prototype._finish=function(){var t=this;if(t._finishing)return;t._finishing=!0;var e=0,r=null,i=!1;if(t._old)t._old.atime=new Date(0),t._old.mtime=new Date(0),s(t._old);else{var n=t.props.follow?"stat":"lstat";Jr[n](t._path,function(o,u){if(o)if(o.code==="ENOENT"&&(t.type==="Link"||t.type==="SymbolicLink")&&process.platform==="win32"){t.ready=!0,t.emit("ready"),t.emit("end"),t.emit("close"),t.end=t._finish=function(){};return}else return t.error(o);s(t._old=u)})}return;function s(o){e+=3,$X(t,t.props,o,t._path,a("chmod")),UX(t,t.props,o,t._path,a("chown")),WX(t,t.props,o,t._path,a("utimes"))}function a(o){return function(u){if(r)return;if(u)return u.fstream_finish_call=o,t.error(r=u);if(--e>0||i)return;if(i=!0,t._madeDir)HX(t,t._path,f);else return f();function f(c){if(c)return c.fstream_finish_call="setupMadeDir",t.error(c);t.emit("end"),t.emit("close")}}}};function HX(t,e,r){var i=t._madeDir,n=Yc.dirname(e);dTe(t,n,function(s){if(s)return r(s);if(n===i)return r();HX(t,n,r)})}function dTe(t,e,r){var i={};Object.keys(t.props).forEach(function(o){i[o]=t.props[o],o==="mode"&&t.type!=="Directory"&&(i[o]=i[o]|parseInt("0111",8))});var n=3,s=null;Jr.stat(e,function(o,u){if(o)return r(s=o);$X(t,i,u,e,a),UX(t,i,u,e,a),WX(t,i,u,e,a)});function a(o){if(!s){if(o)return r(s=o);if(--n===0)return r()}}}ei.prototype.pipe=function(){this.error("Can't pipe from writable stream")};ei.prototype.add=function(){this.error("Can't add to non-Directory type")};ei.prototype.write=function(){return!0};function pTe(t){return Object.prototype.toString.call(t)}function qX(t){return typeof t=="object"&&pTe(t)==="[object Date]"}});var Ak=w(De=>{De.Abstract=py();De.Reader=za();De.Writer=iu();De.File={Reader:hk(),Writer:Tk()};De.Dir={Reader:ck(),Writer:Sk()};De.Link={Reader:uk(),Writer:Ek()};De.Proxy={Reader:pk(),Writer:kk()};De.Reader.Dir=De.DirReader=De.Dir.Reader;De.Reader.File=De.FileReader=De.File.Reader;De.Reader.Link=De.LinkReader=De.Link.Reader;De.Reader.Proxy=De.ProxyReader=De.Proxy.Reader;De.Writer.Dir=De.DirWriter=De.Dir.Writer;De.Writer.File=De.FileWriter=De.File.Writer;De.Writer.Link=De.LinkWriter=De.Link.Writer;De.Writer.Proxy=De.ProxyWriter=De.Proxy.Writer;De.collect=_y()});var VX=w((RPe,XX)=>{XX.exports=wTe;var gTe=iy(),mTe=Ak().Writer,Ok=Y("path"),yTe=Y("stream"),vTe=ak(),_Te=Ts();function wTe(t){t.path=Ok.resolve(Ok.normalize(t.path));var e=new gTe(t),r=new yTe.Writable({objectMode:!0});r._write=function(n,s,a){if(n.type=="Directory")return a();var o=Ok.join(t.path,n.path);if(o.indexOf(t.path)!=0)return a();let u=t.getWriter?t.getWriter({path:o}):mTe({path:o});n.pipe(u).on("error",a).on("close",a)};var i=vTe(e,r);return e.once("crx-header",function(n){i.crxHeader=n}),e.pipe(r).on("finish",function(){i.emit("close")}),i.promise=function(){return new _Te(function(n,s){i.on("close",n),i.on("error",s)})},i}});var GX=w((APe,xy)=>{var Pt=(function(t){"use strict";var e=1e7,r=7,i=9007199254740992,n=d(i),s="0123456789abcdefghijklmnopqrstuvwxyz",a=typeof BigInt=="function";function o(m,x,A,D){return typeof m>"u"?o[0]:typeof x<"u"?+x==10&&!A?le(m):ri(m,x,A,D):le(m)}function u(m,x){this.value=m,this.sign=x,this.isSmall=!1}u.prototype=Object.create(o.prototype);function f(m){this.value=m,this.sign=m<0,this.isSmall=!0}f.prototype=Object.create(o.prototype);function c(m){this.value=m}c.prototype=Object.create(o.prototype);function h(m){return-i<m&&m<i}function d(m){return m<1e7?[m]:m<1e14?[m%1e7,Math.floor(m/1e7)]:[m%1e7,Math.floor(m/1e7)%1e7,Math.floor(m/1e14)]}function p(m){g(m);var x=m.length;if(x<4&&$(m,n)<0)switch(x){case 0:return 0;case 1:return m[0];case 2:return m[0]+m[1]*e;default:return m[0]+(m[1]+m[2]*e)*e}return m}function g(m){for(var x=m.length;m[--x]===0;);m.length=x+1}function y(m){for(var x=new Array(m),A=-1;++A<m;)x[A]=0;return x}function v(m){return m>0?Math.floor(m):Math.ceil(m)}function b(m,x){var A=m.length,D=x.length,X=new Array(A),j=0,V=e,Q,ne;for(ne=0;ne<D;ne++)Q=m[ne]+x[ne]+j,j=Q>=V?1:0,X[ne]=Q-j*V;for(;ne<A;)Q=m[ne]+j,j=Q===V?1:0,X[ne++]=Q-j*V;return j>0&&X.push(j),X}function k(m,x){return m.length>=x.length?b(m,x):b(x,m)}function N(m,x){var A=m.length,D=new Array(A),X=e,j,V;for(V=0;V<A;V++)j=m[V]-X+x,x=Math.floor(j/X),D[V]=j-x*X,x+=1;for(;x>0;)D[V++]=x%X,x=Math.floor(x/X);return D}u.prototype.add=function(m){var x=le(m);if(this.sign!==x.sign)return this.subtract(x.negate());var A=this.value,D=x.value;return x.isSmall?new u(N(A,Math.abs(D)),this.sign):new u(k(A,D),this.sign)},u.prototype.plus=u.prototype.add,f.prototype.add=function(m){var x=le(m),A=this.value;if(A<0!==x.sign)return this.subtract(x.negate());var D=x.value;if(x.isSmall){if(h(A+D))return new f(A+D);D=d(Math.abs(D))}return new u(N(D,Math.abs(A)),A<0)},f.prototype.plus=f.prototype.add,c.prototype.add=function(m){return new c(this.value+le(m).value)},c.prototype.plus=c.prototype.add;function E(m,x){var A=m.length,D=x.length,X=new Array(A),j=0,V=e,Q,ne;for(Q=0;Q<D;Q++)ne=m[Q]-j-x[Q],ne<0?(ne+=V,j=1):j=0,X[Q]=ne;for(Q=D;Q<A;Q++){if(ne=m[Q]-j,ne<0)ne+=V;else{X[Q++]=ne;break}X[Q]=ne}for(;Q<A;Q++)X[Q]=m[Q];return g(X),X}function U(m,x,A){var D;return $(m,x)>=0?D=E(m,x):(D=E(x,m),A=!A),D=p(D),typeof D=="number"?(A&&(D=-D),new f(D)):new u(D,A)}function ee(m,x,A){var D=m.length,X=new Array(D),j=-x,V=e,Q,ne;for(Q=0;Q<D;Q++)ne=m[Q]+j,j=Math.floor(ne/V),ne%=V,X[Q]=ne<0?ne+V:ne;return X=p(X),typeof X=="number"?(A&&(X=-X),new f(X)):new u(X,A)}u.prototype.subtract=function(m){var x=le(m);if(this.sign!==x.sign)return this.add(x.negate());var A=this.value,D=x.value;return x.isSmall?ee(A,Math.abs(D),this.sign):U(A,D,this.sign)},u.prototype.minus=u.prototype.subtract,f.prototype.subtract=function(m){var x=le(m),A=this.value;if(A<0!==x.sign)return this.add(x.negate());var D=x.value;return x.isSmall?new f(A-D):ee(D,Math.abs(A),A>=0)},f.prototype.minus=f.prototype.subtract,c.prototype.subtract=function(m){return new c(this.value-le(m).value)},c.prototype.minus=c.prototype.subtract,u.prototype.negate=function(){return new u(this.value,!this.sign)},f.prototype.negate=function(){var m=this.sign,x=new f(-this.value);return x.sign=!m,x},c.prototype.negate=function(){return new c(-this.value)},u.prototype.abs=function(){return new u(this.value,!1)},f.prototype.abs=function(){return new f(Math.abs(this.value))},c.prototype.abs=function(){return new c(this.value>=0?this.value:-this.value)};function F(m,x){var A=m.length,D=x.length,X=A+D,j=y(X),V=e,Q,ne,he,we,ve;for(he=0;he<A;++he){we=m[he];for(var Ce=0;Ce<D;++Ce)ve=x[Ce],Q=we*ve+j[he+Ce],ne=Math.floor(Q/V),j[he+Ce]=Q-ne*V,j[he+Ce+1]+=ne}return g(j),j}function L(m,x){var A=m.length,D=new Array(A),X=e,j=0,V,Q;for(Q=0;Q<A;Q++)V=m[Q]*x+j,j=Math.floor(V/X),D[Q]=V-j*X;for(;j>0;)D[Q++]=j%X,j=Math.floor(j/X);return D}function I(m,x){for(var A=[];x-- >0;)A.push(0);return A.concat(m)}function Z(m,x){var A=Math.max(m.length,x.length);if(A<=30)return F(m,x);A=Math.ceil(A/2);var D=m.slice(A),X=m.slice(0,A),j=x.slice(A),V=x.slice(0,A),Q=Z(X,V),ne=Z(D,j),he=Z(k(X,D),k(V,j)),we=k(k(Q,I(E(E(he,Q),ne),A)),I(ne,2*A));return g(we),we}function H(m,x){return-.012*m-.012*x+15e-6*m*x>0}u.prototype.multiply=function(m){var x=le(m),A=this.value,D=x.value,X=this.sign!==x.sign,j;if(x.isSmall){if(D===0)return o[0];if(D===1)return this;if(D===-1)return this.negate();if(j=Math.abs(D),j<e)return new u(L(A,j),X);D=d(j)}return H(A.length,D.length)?new u(Z(A,D),X):new u(F(A,D),X)},u.prototype.times=u.prototype.multiply;function O(m,x,A){return m<e?new u(L(x,m),A):new u(F(x,d(m)),A)}f.prototype._multiplyBySmall=function(m){return h(m.value*this.value)?new f(m.value*this.value):O(Math.abs(m.value),d(Math.abs(this.value)),this.sign!==m.sign)},u.prototype._multiplyBySmall=function(m){return m.value===0?o[0]:m.value===1?this:m.value===-1?this.negate():O(Math.abs(m.value),this.value,this.sign!==m.sign)},f.prototype.multiply=function(m){return le(m)._multiplyBySmall(this)},f.prototype.times=f.prototype.multiply,c.prototype.multiply=function(m){return new c(this.value*le(m).value)},c.prototype.times=c.prototype.multiply;function q(m){var x=m.length,A=y(x+x),D=e,X,j,V,Q,ne;for(V=0;V<x;V++){Q=m[V],j=0-Q*Q;for(var he=V;he<x;he++)ne=m[he],X=2*(Q*ne)+A[V+he]+j,j=Math.floor(X/D),A[V+he]=X-j*D;A[V+x]=j}return g(A),A}u.prototype.square=function(){return new u(q(this.value),!1)},f.prototype.square=function(){var m=this.value*this.value;return h(m)?new f(m):new u(q(d(Math.abs(this.value))),!1)},c.prototype.square=function(m){return new c(this.value*this.value)};function B(m,x){var A=m.length,D=x.length,X=e,j=y(x.length),V=x[D-1],Q=Math.ceil(X/(2*V)),ne=L(m,Q),he=L(x,Q),we,ve,Ce,gt,er,In,fu;for(ne.length<=A&&ne.push(0),he.push(0),V=he[D-1],ve=A-D;ve>=0;ve--){for(we=X-1,ne[ve+D]!==V&&(we=Math.floor((ne[ve+D]*X+ne[ve+D-1])/V)),Ce=0,gt=0,In=he.length,er=0;er<In;er++)Ce+=we*he[er],fu=Math.floor(Ce/X),gt+=ne[ve+er]-(Ce-fu*X),Ce=fu,gt<0?(ne[ve+er]=gt+X,gt=-1):(ne[ve+er]=gt,gt=0);for(;gt!==0;){for(we-=1,Ce=0,er=0;er<In;er++)Ce+=ne[ve+er]-X+he[er],Ce<0?(ne[ve+er]=Ce+X,Ce=0):(ne[ve+er]=Ce,Ce=1);gt+=Ce}j[ve]=we}return ne=T(ne,Q)[0],[p(j),p(ne)]}function J(m,x){for(var A=m.length,D=x.length,X=[],j=[],V=e,Q,ne,he,we,ve;A;){if(j.unshift(m[--A]),g(j),$(j,x)<0){X.push(0);continue}ne=j.length,he=j[ne-1]*V+j[ne-2],we=x[D-1]*V+x[D-2],ne>D&&(he=(he+1)*V),Q=Math.ceil(he/we);do{if(ve=L(x,Q),$(ve,j)<=0)break;Q--}while(Q);X.push(Q),j=E(j,ve)}return X.reverse(),[p(X),p(j)]}function T(m,x){var A=m.length,D=y(A),X=e,j,V,Q,ne;for(Q=0,j=A-1;j>=0;--j)ne=Q*X+m[j],V=v(ne/x),Q=ne-V*x,D[j]=V|0;return[D,Q|0]}function M(m,x){var A,D=le(x);if(a)return[new c(m.value/D.value),new c(m.value%D.value)];var X=m.value,j=D.value,V;if(j===0)throw new Error("Cannot divide by zero");if(m.isSmall)return D.isSmall?[new f(v(X/j)),new f(X%j)]:[o[0],m];if(D.isSmall){if(j===1)return[m,o[0]];if(j==-1)return[m.negate(),o[0]];var Q=Math.abs(j);if(Q<e){A=T(X,Q),V=p(A[0]);var ne=A[1];return m.sign&&(ne=-ne),typeof V=="number"?(m.sign!==D.sign&&(V=-V),[new f(V),new f(ne)]):[new u(V,m.sign!==D.sign),new f(ne)]}j=d(Q)}var he=$(X,j);if(he===-1)return[o[0],m];if(he===0)return[o[m.sign===D.sign?1:-1],o[0]];X.length+j.length<=200?A=B(X,j):A=J(X,j),V=A[0];var we=m.sign!==D.sign,ve=A[1],Ce=m.sign;return typeof V=="number"?(we&&(V=-V),V=new f(V)):V=new u(V,we),typeof ve=="number"?(Ce&&(ve=-ve),ve=new f(ve)):ve=new u(ve,Ce),[V,ve]}u.prototype.divmod=function(m){var x=M(this,m);return{quotient:x[0],remainder:x[1]}},c.prototype.divmod=f.prototype.divmod=u.prototype.divmod,u.prototype.divide=function(m){return M(this,m)[0]},c.prototype.over=c.prototype.divide=function(m){return new c(this.value/le(m).value)},f.prototype.over=f.prototype.divide=u.prototype.over=u.prototype.divide,u.prototype.mod=function(m){return M(this,m)[1]},c.prototype.mod=c.prototype.remainder=function(m){return new c(this.value%le(m).value)},f.prototype.remainder=f.prototype.mod=u.prototype.remainder=u.prototype.mod,u.prototype.pow=function(m){var x=le(m),A=this.value,D=x.value,X,j,V;if(D===0)return o[1];if(A===0)return o[0];if(A===1)return o[1];if(A===-1)return x.isEven()?o[1]:o[-1];if(x.sign)return o[0];if(!x.isSmall)throw new Error("The exponent "+x.toString()+" is too large.");if(this.isSmall&&h(X=Math.pow(A,D)))return new f(v(X));for(j=this,V=o[1];D&!0&&(V=V.times(j),--D),D!==0;)D/=2,j=j.square();return V},f.prototype.pow=u.prototype.pow,c.prototype.pow=function(m){var x=le(m),A=this.value,D=x.value,X=BigInt(0),j=BigInt(1),V=BigInt(2);if(D===X)return o[1];if(A===X)return o[0];if(A===j)return o[1];if(A===BigInt(-1))return x.isEven()?o[1]:o[-1];if(x.isNegative())return new c(X);for(var Q=this,ne=o[1];(D&j)===j&&(ne=ne.times(Q),--D),D!==X;)D/=V,Q=Q.square();return ne},u.prototype.modPow=function(m,x){if(m=le(m),x=le(x),x.isZero())throw new Error("Cannot take modPow with modulus 0");var A=o[1],D=this.mod(x);for(m.isNegative()&&(m=m.multiply(o[-1]),D=D.modInv(x));m.isPositive();){if(D.isZero())return o[0];m.isOdd()&&(A=A.multiply(D).mod(x)),m=m.divide(2),D=D.square().mod(x)}return A},c.prototype.modPow=f.prototype.modPow=u.prototype.modPow;function $(m,x){if(m.length!==x.length)return m.length>x.length?1:-1;for(var A=m.length-1;A>=0;A--)if(m[A]!==x[A])return m[A]>x[A]?1:-1;return 0}u.prototype.compareAbs=function(m){var x=le(m),A=this.value,D=x.value;return x.isSmall?1:$(A,D)},f.prototype.compareAbs=function(m){var x=le(m),A=Math.abs(this.value),D=x.value;return x.isSmall?(D=Math.abs(D),A===D?0:A>D?1:-1):-1},c.prototype.compareAbs=function(m){var x=this.value,A=le(m).value;return x=x>=0?x:-x,A=A>=0?A:-A,x===A?0:x>A?1:-1},u.prototype.compare=function(m){if(m===1/0)return-1;if(m===-1/0)return 1;var x=le(m),A=this.value,D=x.value;return this.sign!==x.sign?x.sign?1:-1:x.isSmall?this.sign?-1:1:$(A,D)*(this.sign?-1:1)},u.prototype.compareTo=u.prototype.compare,f.prototype.compare=function(m){if(m===1/0)return-1;if(m===-1/0)return 1;var x=le(m),A=this.value,D=x.value;return x.isSmall?A==D?0:A>D?1:-1:A<0!==x.sign?A<0?-1:1:A<0?1:-1},f.prototype.compareTo=f.prototype.compare,c.prototype.compare=function(m){if(m===1/0)return-1;if(m===-1/0)return 1;var x=this.value,A=le(m).value;return x===A?0:x>A?1:-1},c.prototype.compareTo=c.prototype.compare,u.prototype.equals=function(m){return this.compare(m)===0},c.prototype.eq=c.prototype.equals=f.prototype.eq=f.prototype.equals=u.prototype.eq=u.prototype.equals,u.prototype.notEquals=function(m){return this.compare(m)!==0},c.prototype.neq=c.prototype.notEquals=f.prototype.neq=f.prototype.notEquals=u.prototype.neq=u.prototype.notEquals,u.prototype.greater=function(m){return this.compare(m)>0},c.prototype.gt=c.prototype.greater=f.prototype.gt=f.prototype.greater=u.prototype.gt=u.prototype.greater,u.prototype.lesser=function(m){return this.compare(m)<0},c.prototype.lt=c.prototype.lesser=f.prototype.lt=f.prototype.lesser=u.prototype.lt=u.prototype.lesser,u.prototype.greaterOrEquals=function(m){return this.compare(m)>=0},c.prototype.geq=c.prototype.greaterOrEquals=f.prototype.geq=f.prototype.greaterOrEquals=u.prototype.geq=u.prototype.greaterOrEquals,u.prototype.lesserOrEquals=function(m){return this.compare(m)<=0},c.prototype.leq=c.prototype.lesserOrEquals=f.prototype.leq=f.prototype.lesserOrEquals=u.prototype.leq=u.prototype.lesserOrEquals,u.prototype.isEven=function(){return(this.value[0]&1)===0},f.prototype.isEven=function(){return(this.value&1)===0},c.prototype.isEven=function(){return(this.value&BigInt(1))===BigInt(0)},u.prototype.isOdd=function(){return(this.value[0]&1)===1},f.prototype.isOdd=function(){return(this.value&1)===1},c.prototype.isOdd=function(){return(this.value&BigInt(1))===BigInt(1)},u.prototype.isPositive=function(){return!this.sign},f.prototype.isPositive=function(){return this.value>0},c.prototype.isPositive=f.prototype.isPositive,u.prototype.isNegative=function(){return this.sign},f.prototype.isNegative=function(){return this.value<0},c.prototype.isNegative=f.prototype.isNegative,u.prototype.isUnit=function(){return!1},f.prototype.isUnit=function(){return Math.abs(this.value)===1},c.prototype.isUnit=function(){return this.abs().value===BigInt(1)},u.prototype.isZero=function(){return!1},f.prototype.isZero=function(){return this.value===0},c.prototype.isZero=function(){return this.value===BigInt(0)},u.prototype.isDivisibleBy=function(m){var x=le(m);return x.isZero()?!1:x.isUnit()?!0:x.compareAbs(2)===0?this.isEven():this.mod(x).isZero()},c.prototype.isDivisibleBy=f.prototype.isDivisibleBy=u.prototype.isDivisibleBy;function z(m){var x=m.abs();if(x.isUnit())return!1;if(x.equals(2)||x.equals(3)||x.equals(5))return!0;if(x.isEven()||x.isDivisibleBy(3)||x.isDivisibleBy(5))return!1;if(x.lesser(49))return!0}function re(m,x){for(var A=m.prev(),D=A,X=0,j,V,Q,ne;D.isEven();)D=D.divide(2),X++;e:for(Q=0;Q<x.length;Q++)if(!m.lesser(x[Q])&&(ne=Pt(x[Q]).modPow(D,m),!(ne.isUnit()||ne.equals(A)))){for(j=X-1;j!=0;j--){if(ne=ne.square().mod(m),ne.isUnit())return!1;if(ne.equals(A))continue e}return!1}return!0}u.prototype.isPrime=function(m){var x=z(this);if(x!==t)return x;var A=this.abs(),D=A.bitLength();if(D<=64)return re(A,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var X=Math.log(2)*D.toJSNumber(),j=Math.ceil(m===!0?2*Math.pow(X,2):X),V=[],Q=0;Q<j;Q++)V.push(Pt(Q+2));return re(A,V)},c.prototype.isPrime=f.prototype.isPrime=u.prototype.isPrime,u.prototype.isProbablePrime=function(m,x){var A=z(this);if(A!==t)return A;for(var D=this.abs(),X=m===t?5:m,j=[],V=0;V<X;V++)j.push(Pt.randBetween(2,D.minus(2),x));return re(D,j)},c.prototype.isProbablePrime=f.prototype.isProbablePrime=u.prototype.isProbablePrime,u.prototype.modInv=function(m){for(var x=Pt.zero,A=Pt.one,D=le(m),X=this.abs(),j,V,Q;!X.isZero();)j=D.divide(X),V=x,Q=D,x=A,D=X,A=V.subtract(j.multiply(A)),X=Q.subtract(j.multiply(X));if(!D.isUnit())throw new Error(this.toString()+" and "+m.toString()+" are not co-prime");return x.compare(0)===-1&&(x=x.add(m)),this.isNegative()?x.negate():x},c.prototype.modInv=f.prototype.modInv=u.prototype.modInv,u.prototype.next=function(){var m=this.value;return this.sign?ee(m,1,this.sign):new u(N(m,1),this.sign)},f.prototype.next=function(){var m=this.value;return m+1<i?new f(m+1):new u(n,!1)},c.prototype.next=function(){return new c(this.value+BigInt(1))},u.prototype.prev=function(){var m=this.value;return this.sign?new u(N(m,1),!0):ee(m,1,this.sign)},f.prototype.prev=function(){var m=this.value;return m-1>-i?new f(m-1):new u(n,!0)},c.prototype.prev=function(){return new c(this.value-BigInt(1))};for(var se=[1];2*se[se.length-1]<=e;)se.push(2*se[se.length-1]);var ue=se.length,pe=se[ue-1];function Ye(m){return Math.abs(m)<=e}u.prototype.shiftLeft=function(m){var x=le(m).toJSNumber();if(!Ye(x))throw new Error(String(x)+" is too large for shifting.");if(x<0)return this.shiftRight(-x);var A=this;if(A.isZero())return A;for(;x>=ue;)A=A.multiply(pe),x-=ue-1;return A.multiply(se[x])},c.prototype.shiftLeft=f.prototype.shiftLeft=u.prototype.shiftLeft,u.prototype.shiftRight=function(m){var x,A=le(m).toJSNumber();if(!Ye(A))throw new Error(String(A)+" is too large for shifting.");if(A<0)return this.shiftLeft(-A);for(var D=this;A>=ue;){if(D.isZero()||D.isNegative()&&D.isUnit())return D;x=M(D,pe),D=x[1].isNegative()?x[0].prev():x[0],A-=ue-1}return x=M(D,se[A]),x[1].isNegative()?x[0].prev():x[0]},c.prototype.shiftRight=f.prototype.shiftRight=u.prototype.shiftRight;function Se(m,x,A){x=le(x);for(var D=m.isNegative(),X=x.isNegative(),j=D?m.not():m,V=X?x.not():x,Q=0,ne=0,he=null,we=null,ve=[];!j.isZero()||!V.isZero();)he=M(j,pe),Q=he[1].toJSNumber(),D&&(Q=pe-1-Q),we=M(V,pe),ne=we[1].toJSNumber(),X&&(ne=pe-1-ne),j=he[0],V=we[0],ve.push(A(Q,ne));for(var Ce=A(D?1:0,X?1:0)!==0?Pt(-1):Pt(0),gt=ve.length-1;gt>=0;gt-=1)Ce=Ce.multiply(pe).add(Pt(ve[gt]));return Ce}u.prototype.not=function(){return this.negate().prev()},c.prototype.not=f.prototype.not=u.prototype.not,u.prototype.and=function(m){return Se(this,m,function(x,A){return x&A})},c.prototype.and=f.prototype.and=u.prototype.and,u.prototype.or=function(m){return Se(this,m,function(x,A){return x|A})},c.prototype.or=f.prototype.or=u.prototype.or,u.prototype.xor=function(m){return Se(this,m,function(x,A){return x^A})},c.prototype.xor=f.prototype.xor=u.prototype.xor;var Be=1<<30,je=(e&-e)*(e&-e)|Be;function Ae(m){var x=m.value,A=typeof x=="number"?x|Be:typeof x=="bigint"?x|BigInt(Be):x[0]+x[1]*e|je;return A&-A}function Ke(m,x){if(x.compareTo(m)<=0){var A=Ke(m,x.square(x)),D=A.p,X=A.e,j=D.multiply(x);return j.compareTo(m)<=0?{p:j,e:X*2+1}:{p:D,e:X*2}}return{p:Pt(1),e:0}}u.prototype.bitLength=function(){var m=this;return m.compareTo(Pt(0))<0&&(m=m.negate().subtract(Pt(1))),m.compareTo(Pt(0))===0?Pt(0):Pt(Ke(m,Pt(2)).e).add(Pt(1))},c.prototype.bitLength=f.prototype.bitLength=u.prototype.bitLength;function pt(m,x){return m=le(m),x=le(x),m.greater(x)?m:x}function Nt(m,x){return m=le(m),x=le(x),m.lesser(x)?m:x}function Br(m,x){if(m=le(m).abs(),x=le(x).abs(),m.equals(x))return m;if(m.isZero())return x;if(x.isZero())return m;for(var A=o[1],D,X;m.isEven()&&x.isEven();)D=Nt(Ae(m),Ae(x)),m=m.divide(D),x=x.divide(D),A=A.multiply(D);for(;m.isEven();)m=m.divide(Ae(m));do{for(;x.isEven();)x=x.divide(Ae(x));m.greater(x)&&(X=x,x=m,m=X),x=x.subtract(m)}while(!x.isZero());return A.isUnit()?m:m.multiply(A)}function ti(m,x){return m=le(m).abs(),x=le(x).abs(),m.divide(Br(m,x)).multiply(x)}function Ui(m,x,A){m=le(m),x=le(x);var D=A||Math.random,X=Nt(m,x),j=pt(m,x),V=j.subtract(X).add(1);if(V.isSmall)return X.add(Math.floor(D()*V));for(var Q=Cr(V,e).value,ne=[],he=!0,we=0;we<Q.length;we++){var ve=he?Q[we]+(we+1<Q.length?Q[we+1]/e:0):e,Ce=v(D()*ve);ne.push(Ce),Ce<Q[we]&&(he=!1)}return X.add(o.fromArray(ne,e,!1))}var ri=function(m,x,A,D){A=A||s,m=String(m),D||(m=m.toLowerCase(),A=A.toLowerCase());var X=m.length,j,V=Math.abs(x),Q={};for(j=0;j<A.length;j++)Q[A[j]]=j;for(j=0;j<X;j++){var ne=m[j];if(ne!=="-"&&ne in Q&&Q[ne]>=V){if(ne==="1"&&V===1)continue;throw new Error(ne+" is not a valid digit in base "+x+".")}}x=le(x);var he=[],we=m[0]==="-";for(j=we?1:0;j<m.length;j++){var ne=m[j];if(ne in Q)he.push(le(Q[ne]));else if(ne==="<"){var ve=j;do j++;while(m[j]!==">"&&j<m.length);he.push(le(m.slice(ve+1,j)))}else throw new Error(ne+" is not a valid character")}return jr(he,x,we)};function jr(m,x,A){var D=o[0],X=o[1],j;for(j=m.length-1;j>=0;j--)D=D.add(m[j].times(X)),X=X.times(x);return A?D.negate():D}function Wi(m,x){return x=x||s,m<x.length?x[m]:"<"+m+">"}function Cr(m,x){if(x=Pt(x),x.isZero()){if(m.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(x.equals(-1)){if(m.isZero())return{value:[0],isNegative:!1};if(m.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-m.toJSNumber())).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var A=Array.apply(null,Array(m.toJSNumber()-1)).map(Array.prototype.valueOf,[0,1]);return A.unshift([1]),{value:[].concat.apply([],A),isNegative:!1}}var D=!1;if(m.isNegative()&&x.isPositive()&&(D=!0,m=m.abs()),x.isUnit())return m.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(m.toJSNumber())).map(Number.prototype.valueOf,1),isNegative:D};for(var X=[],j=m,V;j.isNegative()||j.compareAbs(x)>=0;){V=j.divmod(x),j=V.quotient;var Q=V.remainder;Q.isNegative()&&(Q=x.minus(Q).abs(),j=j.next()),X.push(Q.toJSNumber())}return X.push(j.toJSNumber()),{value:X.reverse(),isNegative:D}}function Ka(m,x,A){var D=Cr(m,x);return(D.isNegative?"-":"")+D.value.map(function(X){return Wi(X,A)}).join("")}u.prototype.toArray=function(m){return Cr(this,m)},f.prototype.toArray=function(m){return Cr(this,m)},c.prototype.toArray=function(m){return Cr(this,m)},u.prototype.toString=function(m,x){if(m===t&&(m=10),m!==10||x)return Ka(this,m,x);for(var A=this.value,D=A.length,X=String(A[--D]),j="0000000",V;--D>=0;)V=String(A[D]),X+=j.slice(V.length)+V;var Q=this.sign?"-":"";return Q+X},f.prototype.toString=function(m,x){return m===t&&(m=10),m!=10||x?Ka(this,m,x):String(this.value)},c.prototype.toString=f.prototype.toString,c.prototype.toJSON=u.prototype.toJSON=f.prototype.toJSON=function(){return this.toString()},u.prototype.valueOf=function(){return parseInt(this.toString(),10)},u.prototype.toJSNumber=u.prototype.valueOf,f.prototype.valueOf=function(){return this.value},f.prototype.toJSNumber=f.prototype.valueOf,c.prototype.valueOf=c.prototype.toJSNumber=function(){return parseInt(this.toString(),10)};function kr(m){if(h(+m)){var x=+m;if(x===v(x))return a?new c(BigInt(x)):new f(x);throw new Error("Invalid integer: "+m)}var A=m[0]==="-";A&&(m=m.slice(1));var D=m.split(/e/i);if(D.length>2)throw new Error("Invalid integer: "+D.join("e"));if(D.length===2){var X=D[1];if(X[0]==="+"&&(X=X.slice(1)),X=+X,X!==v(X)||!h(X))throw new Error("Invalid integer: "+X+" is not a valid exponent.");var j=D[0],V=j.indexOf(".");if(V>=0&&(X-=j.length-V-1,j=j.slice(0,V)+j.slice(V+1)),X<0)throw new Error("Cannot include negative exponent part for integers");j+=new Array(X+1).join("0"),m=j}var Q=/^([0-9][0-9]*)$/.test(m);if(!Q)throw new Error("Invalid integer: "+m);if(a)return new c(BigInt(A?"-"+m:m));for(var ne=[],he=m.length,we=r,ve=he-we;he>0;)ne.push(+m.slice(ve,he)),ve-=we,ve<0&&(ve=0),he-=we;return g(ne),new u(ne,A)}function On(m){if(a)return new c(BigInt(m));if(h(m)){if(m!==v(m))throw new Error(m+" is not an integer.");return new f(m)}return kr(m.toString())}function le(m){return typeof m=="number"?On(m):typeof m=="string"?kr(m):typeof m=="bigint"?new c(m):m}for(var W=0;W<1e3;W++)o[W]=le(W),W>0&&(o[-W]=le(-W));return o.one=o[1],o.zero=o[0],o.minusOne=o[-1],o.max=pt,o.min=Nt,o.gcd=Br,o.lcm=ti,o.isInstance=function(m){return m instanceof u||m instanceof f||m instanceof c},o.randBetween=Ui,o.fromArray=function(m,x,A){return jr(m.map(le),le(x||10),A)},o})();typeof xy<"u"&&xy.hasOwnProperty("exports")&&(xy.exports=Pt);typeof define=="function"&&define.amd&&define(function(){return Pt})});var KX=w((OPe,YX)=>{var Os=GX(),Sy=Y("stream");(!Sy.Writable||!Sy.Writable.prototype.destroy)&&(Sy=Tn());var Ey;function bTe(){var t=3988292384,e,r,i;for(Ey=[],r=0;r<256;r++){for(e=r,i=0;i<8;i++)e=e&1?t^e>>>1:e=e>>>1;Ey[r]=e>>>0}}function ZX(t,e){return Ey||bTe(),t.charCodeAt&&(t=t.charCodeAt(0)),Os(e).shiftRight(8).and(16777215).xor(Ey[Os(e).xor(t).and(255)]).value}function nu(){if(!(this instanceof nu))return new nu;this.key0=305419896,this.key1=591751049,this.key2=878082192}nu.prototype.update=function(t){this.key0=ZX(t,this.key0),this.key1=Os(this.key0).and(255).and(4294967295).add(this.key1),this.key1=Os(this.key1).multiply(134775813).add(1).and(4294967295).value,this.key2=ZX(Os(this.key1).shiftRight(24).and(255),this.key2)};nu.prototype.decryptByte=function(t){var e=Os(this.key2).or(2);return t=t^Os(e).multiply(Os(e^1)).shiftRight(8).and(255),this.update(t),t};nu.prototype.stream=function(){var t=Sy.Transform(),e=this;return t._transform=function(r,i,n){for(var s=0;s<r.length;s++)r[s]=e.decryptByte(r[s]);this.push(r),n()},t};YX.exports=nu});var JX=w((IPe,QX)=>{var xTe=Ts(),STe=KX(),ETe=Qm(),Kc=Y("stream"),TTe=bc(),CTe=Y("zlib"),kTe=ty(),RTe=Hl(),ATe=ry();(!Kc.Writable||!Kc.Writable.prototype.destroy)&&(Kc=Tn());QX.exports=function(e,r,i,n){var s=ETe(),a=Kc.PassThrough(),o=e.stream(r);return o.pipe(s).on("error",function(u){a.emit("error",u)}),a.vars=s.pull(30).then(function(u){var f=TTe.parse(u).word32lu("signature").word16lu("versionsNeededToExtract").word16lu("flags").word16lu("compressionMethod").word16lu("lastModifiedTime").word16lu("lastModifiedDate").word32lu("crc32").word32lu("compressedSize").word32lu("uncompressedSize").word16lu("fileNameLength").word16lu("extraFieldLength").vars;return f.lastModifiedDateTime=ATe(f.lastModifiedDate,f.lastModifiedTime),s.pull(f.fileNameLength).then(function(c){return f.fileName=c.toString("utf8"),s.pull(f.extraFieldLength)}).then(function(c){var h;return f.extra=kTe(c,f),n&&n.compressedSize&&(f=n),f.flags&1&&(h=s.pull(12).then(function(d){if(!i)throw new Error("MISSING_PASSWORD");var p=STe();String(i).split("").forEach(function(v){p.update(v)});for(var g=0;g<d.length;g++)d[g]=p.decryptByte(d[g]);f.decrypt=p,f.compressedSize-=12;var y=f.flags&8?f.lastModifiedTime>>8&255:f.crc32>>24&255;if(d[11]!==y)throw new Error("BAD_PASSWORD");return f})),xTe.resolve(h).then(function(){return a.emit("vars",f),f})})}),a.vars.then(function(u){var f=!(u.flags&8)||u.compressedSize>0,c,h=u.compressionMethod?CTe.createInflateRaw():Kc.PassThrough();f?(a.size=u.uncompressedSize,c=u.compressedSize):(c=RTe.alloc(4),c.writeUInt32LE(134695760,0));var d=s.stream(c);u.decrypt&&(d=d.pipe(u.decrypt.stream())),d.pipe(h).on("error",function(p){a.emit("error",p)}).pipe(a).on("finish",function(){o.destroy?o.destroy():o.abort?o.abort():o.close?o.close():o.push?o.push():console.log("warning - unable to close stream")})}).catch(function(u){a.emit("error",u)}),a}});var rV=w((NPe,tV)=>{var eh=bc(),Jc=Qm(),OTe=JX(),Qc=Ts(),ITe=ey(),NTe=ty(),DTe=Hl(),Ik=Y("path"),FTe=Ak().Writer,MTe=ry(),eV=DTe.alloc(4);eV.writeUInt32LE(101010256,0);function PTe(t){var e=t.stream(0).pipe(Jc());return e.pull(4).then(function(r){var i=r.readUInt32LE(0);if(i===875721283){var n;return e.pull(12).then(function(s){n=eh.parse(s).word32lu("version").word32lu("pubKeyLength").word32lu("signatureLength").vars}).then(function(){return e.pull(n.pubKeyLength+n.signatureLength)}).then(function(s){return n.publicKey=s.slice(0,n.pubKeyLength),n.signature=s.slice(n.pubKeyLength),n.size=16+n.pubKeyLength+n.signatureLength,n})}})}function qTe(t,e){var r=eh.parse(e).word32lu("signature").word32lu("diskNumber").word64lu("offsetToStartOfCentralDirectory").word32lu("numberOfDisks").vars;if(r.signature!=117853008)throw new Error("invalid zip64 end of central dir locator signature (0x07064b50): 0x"+r.signature.toString(16));var i=Jc();return t.stream(r.offsetToStartOfCentralDirectory).pipe(i),i.pull(56)}function LTe(t){var e=eh.parse(t).word32lu("signature").word64lu("sizeOfCentralDirectory").word16lu("version").word16lu("versionsNeededToExtract").word32lu("diskNumber").word32lu("diskStart").word64lu("numberOfRecordsOnDisk").word64lu("numberOfRecords").word64lu("sizeOfCentralDirectory").word64lu("offsetToStartOfCentralDirectory").vars;if(e.signature!=101075792)throw new Error("invalid zip64 end of central dir locator signature (0x06064b50): 0x0"+e.signature.toString(16));return e}tV.exports=function(e,r){var i=Jc(),n=Jc(),s=r&&r.tailSize||80,a,o,u,f;return r&&r.crx&&(o=PTe(e)),e.size().then(function(c){return a=c,e.stream(Math.max(0,c-s)).on("error",function(h){i.emit("error",h)}).pipe(i),i.pull(eV)}).then(function(){return Qc.props({directory:i.pull(22),crxHeader:o})}).then(function(c){var h=c.directory;if(u=c.crxHeader&&c.crxHeader.size||0,f=eh.parse(h).word32lu("signature").word16lu("diskNumber").word16lu("diskStart").word16lu("numberOfRecordsOnDisk").word16lu("numberOfRecords").word32lu("sizeOfCentralDirectory").word32lu("offsetToStartOfCentralDirectory").word16lu("commentLength").vars,f.numberOfRecords==65535||f.numberOfRecords==65535||f.offsetToStartOfCentralDirectory==4294967295){let p=a-(s-i.match+20),g=Jc();return e.stream(p).pipe(g),g.pull(20).then(function(y){return qTe(e,y)}).then(function(y){f=LTe(y)})}else f.offsetToStartOfCentralDirectory+=u}).then(function(){if(f.commentLength)return i.pull(f.commentLength).then(function(c){f.comment=c.toString("utf8")})}).then(function(){return e.stream(f.offsetToStartOfCentralDirectory).pipe(n),f.extract=function(c){if(!c||!c.path)throw new Error("PATH_MISSING");return c.path=Ik.resolve(Ik.normalize(c.path)),f.files.then(function(h){return Qc.map(h,function(d){if(d.type!="Directory"){var p=Ik.join(c.path,d.path);if(p.indexOf(c.path)==0){var g=c.getWriter?c.getWriter({path:p}):FTe({path:p});return new Qc(function(y,v){d.stream(c.password).on("error",v).pipe(g).on("close",y).on("error",v)})}}},{concurrency:c.concurrency>1?c.concurrency:1})})},f.files=Qc.mapSeries(Array(f.numberOfRecords),function(){return n.pull(46).then(function(c){var h=eh.parse(c).word32lu("signature").word16lu("versionMadeBy").word16lu("versionsNeededToExtract").word16lu("flags").word16lu("compressionMethod").word16lu("lastModifiedTime").word16lu("lastModifiedDate").word32lu("crc32").word32lu("compressedSize").word32lu("uncompressedSize").word16lu("fileNameLength").word16lu("extraFieldLength").word16lu("fileCommentLength").word16lu("diskNumber").word16lu("internalFileAttributes").word32lu("externalFileAttributes").word32lu("offsetToLocalFileHeader").vars;return h.offsetToLocalFileHeader+=u,h.lastModifiedDateTime=MTe(h.lastModifiedDate,h.lastModifiedTime),n.pull(h.fileNameLength).then(function(d){return h.pathBuffer=d,h.path=d.toString("utf8"),h.isUnicode=(h.flags&2048)!=0,n.pull(h.extraFieldLength)}).then(function(d){return h.extra=NTe(d,h),n.pull(h.fileCommentLength)}).then(function(d){return h.comment=d,h.type=h.uncompressedSize===0&&/[\/\\]$/.test(h.path)?"Directory":"File",h.stream=function(p){return OTe(e,h.offsetToLocalFileHeader,p,h)},h.buffer=function(p){return ITe(h.stream(p))},h})})}),Qc.props(f)})}});var sV=w((DPe,nV)=>{var iV=Er(),Ty=Ts(),th=rV(),Cy=Y("stream");(!Cy.Writable||!Cy.Writable.prototype.destroy)&&(Cy=Tn());nV.exports={buffer:function(t,e){var r={stream:function(i,n){var s=Cy.PassThrough();return s.end(t.slice(i,n)),s},size:function(){return Ty.resolve(t.length)}};return th(r,e)},file:function(t,e){var r={stream:function(i,n){return iV.createReadStream(t,{start:i,end:n&&i+n})},size:function(){return new Ty(function(i,n){iV.stat(t,function(s,a){s?n(s):i(a.size)})})}};return th(r,e)},url:function(t,e,r){if(typeof e=="string"&&(e={url:e}),!e.url)throw"URL missing";e.headers=e.headers||{};var i={stream:function(n,s){var a=Object.create(e);return a.headers=Object.create(e.headers),a.headers.range="bytes="+n+"-"+(s||""),t(a)},size:function(){return new Ty(function(n,s){var a=t(e);a.on("response",function(o){a.abort(),o.headers["content-length"]?n(o.headers["content-length"]):s(new Error("Missing content length header"))}).on("error",s)})}};return th(i,r)},s3:function(t,e,r){var i={size:function(){return new Ty(function(n,s){t.headObject(e,function(a,o){a?s(a):n(o.ContentLength)})})},stream:function(n,s){var a={};for(var o in e)a[o]=e[o];return a.Range="bytes="+n+"-"+(s||""),t.getObject(a).createReadStream()}};return th(i,r)},custom:function(t,e){return th(t,e)}}});var aV=w(rh=>{"use strict";mW();wW();s_();rh.Parse=iy();rh.ParseOne=Y5();rh.Extract=VX();rh.Open=sV()});var EV=w((MPe,An)=>{var Qe=Y("fs"),Ry=Y("os"),qt=Y("path"),oV=Y("crypto"),ji={fs:Qe.constants,os:Ry.constants},lV="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",hV=/XXXXXX/,BTe=3,dV=(ji.O_CREAT||ji.fs.O_CREAT)|(ji.O_EXCL||ji.fs.O_EXCL)|(ji.O_RDWR||ji.fs.O_RDWR),jTe=Ry.platform()==="win32",$Te=ji.EBADF||ji.os.errno.EBADF,UTe=ji.ENOENT||ji.os.errno.ENOENT,pV=448,gV=384,WTe="exit",su=[],mV=Qe.rmdirSync.bind(Qe),yV=!1;function HTe(t,e){return Qe.rm(t,{recursive:!0},e)}function vV(t){return Qe.rmSync(t,{recursive:!0})}function Mk(t,e){let r=au(t,e),i=r[0],n=r[1];e1e(i,function(s,a){if(s)return n(s);let o=a.tries;(function u(){try{let f=wV(a);Qe.stat(f,function(c){if(!c)return o-- >0?u():n(new Error("Could not get a unique tmp filename, max tries reached "+f));n(null,f)})}catch(f){n(f)}})()})}function Pk(t){let e=au(t),r=e[0],i=t1e(r),n=i.tries;do{let s=wV(i);try{Qe.statSync(s)}catch{return s}}while(n-- >0);throw new Error("Could not get a unique tmp filename, max tries reached")}function zTe(t,e){let r=au(t,e),i=r[0],n=r[1];Mk(i,function(a,o){if(a)return n(a);Qe.open(o,dV,i.mode||gV,function(f,c){if(f)return n(f);if(i.discardDescriptor)return Qe.close(c,function(d){return n(d,o,void 0,Dk(o,-1,i,!1))});{let h=i.discardDescriptor||i.detachDescriptor;n(null,o,c,Dk(o,h?-1:c,i,!1))}})})}function XTe(t){let e=au(t),r=e[0],i=r.discardDescriptor||r.detachDescriptor,n=Pk(r),s=Qe.openSync(n,dV,r.mode||gV);return r.discardDescriptor&&(Qe.closeSync(s),s=void 0),{name:n,fd:s,removeCallback:Dk(n,i?-1:s,r,!0)}}function VTe(t,e){let r=au(t,e),i=r[0],n=r[1];Mk(i,function(a,o){if(a)return n(a);Qe.mkdir(o,i.mode||pV,function(f){if(f)return n(f);n(null,o,_V(o,i,!1))})})}function GTe(t){let e=au(t),r=e[0],i=Pk(r);return Qe.mkdirSync(i,r.mode||pV),{name:i,removeCallback:_V(i,r,!0)}}function ZTe(t,e){let r=function(i){if(i&&!Fk(i))return e(i);e()};0<=t[0]?Qe.close(t[0],function(){Qe.unlink(t[1],r)}):Qe.unlink(t[1],r)}function YTe(t){let e=null;try{0<=t[0]&&Qe.closeSync(t[0])}catch(r){if(!r1e(r)&&!Fk(r))throw r}finally{try{Qe.unlinkSync(t[1])}catch(r){Fk(r)||(e=r)}}if(e!==null)throw e}function Dk(t,e,r,i){let n=ky(YTe,[e,t],i),s=ky(ZTe,[e,t],i,n);return r.keep||su.unshift(n),i?n:s}function _V(t,e,r){let i=e.unsafeCleanup?HTe:Qe.rmdir.bind(Qe),n=e.unsafeCleanup?vV:mV,s=ky(n,t,r),a=ky(i,t,r,s);return e.keep||su.unshift(s),r?s:a}function ky(t,e,r,i){let n=!1;return function s(a){if(!n){let o=i||s,u=su.indexOf(o);return u>=0&&su.splice(u,1),n=!0,r||t===mV||t===vV?t(e):t(e,a||function(){})}}}function KTe(){if(yV)for(;su.length;)try{su[0]()}catch{}}function uV(t){let e=[],r=null;try{r=oV.randomBytes(t)}catch{r=oV.pseudoRandomBytes(t)}for(let i=0;i<t;i++)e.push(lV[r[i]%lV.length]);return e.join("")}function Tr(t){return typeof t>"u"}function au(t,e){if(typeof t=="function")return[{},t];if(Tr(t))return[{},e];let r={};for(let i of Object.getOwnPropertyNames(t))r[i]=t[i];return[r,e]}function QTe(t,e,r){let i=qt.isAbsolute(t)?t:qt.join(e,t);Qe.stat(i,function(n){n?Qe.realpath(qt.dirname(i),function(s,a){if(s)return r(s);r(null,qt.join(a,qt.basename(i)))}):Qe.realpath(i,r)})}function JTe(t,e){let r=qt.isAbsolute(t)?t:qt.join(e,t);try{return Qe.statSync(r),Qe.realpathSync(r)}catch{let n=Qe.realpathSync(qt.dirname(r));return qt.join(n,qt.basename(r))}}function wV(t){let e=t.tmpdir;if(!Tr(t.name))return qt.join(e,t.dir,t.name);if(!Tr(t.template))return qt.join(e,t.dir,t.template).replace(hV,uV(6));let r=[t.prefix?t.prefix:"tmp","-",process.pid,"-",uV(12),t.postfix?"-"+t.postfix:""].join("");return qt.join(e,t.dir,r)}function Nk(t,e){if(typeof e!="string")throw new Error(`${t} option must be a string, got "${typeof e}".`);if(e.includes(".."))throw new Error("Relative value not allowed");return e}function bV(t){if(!Tr(t.name)){let e=t.name;if(qt.isAbsolute(e))throw new Error(`name option must not contain an absolute path, found "${e}".`);let r=qt.basename(e);if(r===".."||r==="."||r!==e)throw new Error(`name option must not contain a path, found "${e}".`)}if(!Tr(t.template)){if(typeof t.template!="string")throw new Error(`template option must be a string, got "${typeof t.template}".`);if(!t.template.match(hV))throw new Error(`Invalid template, found "${t.template}".`)}if(!Tr(t.tries)&&isNaN(t.tries)||t.tries<0)throw new Error(`Invalid tries, found "${t.tries}".`);t.tries=Tr(t.name)?t.tries||BTe:1,t.keep=!!t.keep,t.detachDescriptor=!!t.detachDescriptor,t.discardDescriptor=!!t.discardDescriptor,t.unsafeCleanup=!!t.unsafeCleanup,t.prefix=Tr(t.prefix)?"":Nk("prefix",t.prefix),t.postfix=Tr(t.postfix)?"":Nk("postfix",t.postfix),t.template=Tr(t.template)?void 0:Nk("template",t.template)}function fV(t,e,r,i){if(Tr(e))return i(null);QTe(e,r,function(n,s){if(n)return i(n);let a=qt.relative(r,s);if(a.startsWith("..")||qt.isAbsolute(a))return i(new Error(`${t} option must be relative to "${r}", found "${a}".`));i(null,a)})}function cV(t,e,r){if(Tr(e))return;let i=JTe(e,r),n=qt.relative(r,i);if(n.startsWith("..")||qt.isAbsolute(n))throw new Error(`${t} option must be relative to "${r}", found "${n}".`);return n}function e1e(t,e){n1e(t,function(r,i){if(r)return e(r);t.tmpdir=i;try{bV(t,i)}catch(n){return e(n)}fV("dir",t.dir,i,function(n,s){if(n)return e(n);t.dir=Tr(s)?"":s,fV("template",t.template,i,function(a,o){if(a)return e(a);t.template=o,e(null,t)})})})}function t1e(t){let e=t.tmpdir=SV(t);bV(t,e);let r=cV("dir",t.dir,e);return t.dir=Tr(r)?"":r,t.template=cV("template",t.template,e),t}function r1e(t){return xV(t,-$Te,"EBADF")}function Fk(t){return xV(t,-UTe,"ENOENT")}function xV(t,e,r){return jTe?t.code===r:t.code===r&&t.errno===e}function i1e(){yV=!0}function n1e(t,e){return Qe.realpath(t&&t.tmpdir||Ry.tmpdir(),e)}function SV(t){return Qe.realpathSync(t&&t.tmpdir||Ry.tmpdir())}process.addListener(WTe,KTe);Object.defineProperty(An.exports,"tmpdir",{enumerable:!0,configurable:!1,get:function(){return SV()}});An.exports.dir=VTe;An.exports.dirSync=GTe;An.exports.file=zTe;An.exports.fileSync=XTe;An.exports.tmpName=Mk;An.exports.tmpNameSync=Pk;An.exports.setGracefulCleanup=i1e});var CV=w((PPe,TV)=>{TV.exports=async function*(e){let r=[];e.on("data",o=>r.push(o));let i,n=new Promise(o=>i=o),s=!1;e.on("end",()=>{s=!0,i()});let a=!1;for(e.on("error",o=>{a=o,i()});!s||r.length>0;)if(r.length===0?(e.resume(),await Promise.race([s1e(e,"data"),n])):(e.pause(),yield r.shift()),a)throw a;i()};function s1e(t,e){return new Promise(r=>{let i=!1,n=()=>{i||(i=!0,t.removeListener(e,n),r())};t.addListener(e,n)})}});var OV=w((qPe,AV)=>{var{EventEmitter:a1e}=Y("events"),o1e=bf(),l1e=wt(),Ay=sr(),kV=mt(),u1e=Vi(),f1e=Lh(),RV=Bh(),qk=class extends a1e{constructor({workbook:e,id:r,iterator:i,options:n}){super(),this.workbook=e,this.id=r,this.iterator=i,this.options=n||{},this.name=`Sheet${this.id}`,this._columns=null,this._keys={},this._dimensions=new u1e}destroy(){throw new Error("Invalid Operation: destroy")}get dimensions(){return this._dimensions}get columns(){return this._columns}getColumn(e){if(typeof e=="string"){let r=this._keys[e];if(r)return r;e=kV.l2n(e)}if(this._columns||(this._columns=[]),e>this._columns.length){let r=this._columns.length+1;for(;r<=e;)this._columns.push(new RV(this,r++))}return this._columns[e-1]}getColumnKey(e){return this._keys[e]}setColumnKey(e,r){this._keys[e]=r}deleteColumnKey(e){delete this._keys[e]}eachColumnKey(e){l1e.each(this._keys,e)}async read(){try{for await(let e of this.parse())for(let{eventType:r,value:i}of e)this.emit(r,i);this.emit("finished")}catch(e){this.emit("error",e)}}async*[Symbol.asyncIterator](){for await(let e of this.parse())for(let{eventType:r,value:i}of e)r==="row"&&(yield i)}async*parse(){let{iterator:e,options:r}=this,i=!1,n=!1,s=null;switch(r.worksheets){case"emit":i=!0;break;case"prep":break;default:break}switch(r.hyperlinks){case"emit":n=!0;break;case"cache":this.hyperlinks=s={};break;default:break}if(!i&&!n&&!s)return;let{sharedStrings:a,styles:o,properties:u}=this.workbook,f=!1,c=!1,h=!1,d=null,p=null,g=null,y=null;for await(let v of o1e(e)){let b=[];for(let{eventType:k,value:N}of v)if(k==="opentag"){let E=N;if(i)switch(E.name){case"cols":f=!0,d=[];break;case"sheetData":c=!0;break;case"col":f&&d.push({min:parseInt(E.attributes.min,10),max:parseInt(E.attributes.max,10),width:parseFloat(E.attributes.width),styleId:parseInt(E.attributes.style||"0",10)});break;case"row":if(c){let U=parseInt(E.attributes.r,10);if(p=new f1e(this,U),E.attributes.ht&&(p.height=parseFloat(E.attributes.ht)),E.attributes.s){let ee=parseInt(E.attributes.s,10),F=o.getStyleModel(ee);F&&(p.style=F)}}break;case"c":p&&(g={ref:E.attributes.r,s:parseInt(E.attributes.s,10),t:E.attributes.t});break;case"f":g&&(y=g.f={text:""});break;case"v":g&&(y=g.v={text:""});break;case"is":case"t":g&&(y=g.v={text:""});break;case"mergeCell":break;default:break}if(n||s)switch(E.name){case"hyperlinks":h=!0;break;case"hyperlink":if(h){let U={ref:E.attributes.ref,rId:E.attributes["r:id"]};n?b.push({eventType:"hyperlink",value:U}):s[U.ref]=U}break;default:break}}else if(k==="text")i&&y&&(y.text+=N);else if(k==="closetag"){let E=N;if(i)switch(E.name){case"cols":f=!1,this._columns=RV.fromModel(d);break;case"sheetData":c=!1;break;case"row":this._dimensions.expandRow(p),b.push({eventType:"row",value:p}),p=null;break;case"c":if(p&&g){let U=kV.decodeAddress(g.ref),ee=p.getCell(U.col);if(g.s){let F=o.getStyleModel(g.s);F&&(ee.style=F)}if(g.f){let F={formula:g.f.text};g.v&&(g.t==="str"?F.result=Ay.xmlDecode(g.v.text):F.result=parseFloat(g.v.text)),ee.value=F}else if(g.v)switch(g.t){case"s":{let F=parseInt(g.v.text,10);a?ee.value=a[F]:ee.value={sharedString:F};break}case"inlineStr":case"str":ee.value=Ay.xmlDecode(g.v.text);break;case"e":ee.value={error:g.v.text};break;case"b":ee.value=parseInt(g.v.text,10)!==0;break;default:Ay.isDateFmt(ee.numFmt)?ee.value=Ay.excelToDate(parseFloat(g.v.text),u.model&&u.model.date1904):ee.value=parseFloat(g.v.text);break}if(s){let F=s[g.ref];F&&(ee.text=ee.value,ee.value=void 0,ee.hyperlink=F)}g=null}break;default:break}(n||s)&&E.name==="hyperlinks"&&(h=!1)}b.length>0&&(yield b)}}};AV.exports=qk});var NV=w((LPe,IV)=>{var{EventEmitter:c1e}=Y("events"),h1e=bf(),d1e=ni(),p1e=es(),Lk=class extends c1e{constructor({workbook:e,id:r,iterator:i,options:n}){super(),this.workbook=e,this.id=r,this.iterator=i,this.options=n}get count(){return this.hyperlinks&&this.hyperlinks.length||0}each(e){return this.hyperlinks.forEach(e)}async read(){let{iterator:e,options:r}=this,i=!1,n=null;switch(r.hyperlinks){case"emit":i=!0;break;case"cache":this.hyperlinks=n={};break;default:break}if(!i&&!n){this.emit("finished");return}try{for await(let s of h1e(e))for(let{eventType:a,value:o}of s)if(a==="opentag"){let u=o;if(u.name==="Relationship"){let f=u.attributes.Id;switch(u.attributes.Type){case p1e.Hyperlink:{let c={type:d1e.RelationshipType.Styles,rId:f,target:u.attributes.Target,targetMode:u.attributes.TargetMode};i?this.emit("hyperlink",c):n[c.rId]=c}break;default:break}}}this.emit("finished")}catch(s){this.emit("error",s)}}};IV.exports=Lk});var PV=w((BPe,MV)=>{var Bk=Y("fs"),{EventEmitter:g1e}=Y("events"),{PassThrough:m1e,Readable:y1e}=nr(),v1e=Y("stream"),_1e=aV(),FV=EV(),Za=CV(),w1e=bf(),DV=mp(),b1e=xp(),x1e=wp(),S1e=OV(),E1e=NV();FV.setGracefulCleanup();var Oy=class extends g1e{constructor(e,r={}){super(),this.input=e,this.options={worksheets:"emit",sharedStrings:"cache",hyperlinks:"ignore",styles:"ignore",entries:"ignore",...r},this.styles=new DV,this.styles.init()}_getStream(e){if(e instanceof v1e.Readable||e instanceof y1e)return e;if(typeof e=="string")return Bk.createReadStream(e);throw new Error(`Could not recognise input: ${e}`)}async read(e,r){try{for await(let{eventType:i,value:n}of this.parse(e,r))switch(i){case"shared-strings":this.emit(i,n);break;case"worksheet":this.emit(i,n),await n.read();break;case"hyperlinks":this.emit(i,n);break}this.emit("end"),this.emit("finished")}catch(i){this.emit("error",i)}}async*[Symbol.asyncIterator](){for await(let{eventType:e,value:r}of this.parse())e==="worksheet"&&(yield r)}async*parse(e,r){r&&(this.options=r);let i=this.stream=this._getStream(e||this.input),n=_1e.Parse({forceStream:!0});i.pipe(n);let s=[];for await(let a of Za(n)){let o,u;switch(a.path){case"_rels/.rels":break;case"xl/_rels/workbook.xml.rels":await this._parseRels(a);break;case"xl/workbook.xml":await this._parseWorkbook(a);break;case"xl/sharedStrings.xml":yield*this._parseSharedStrings(a);break;case"xl/styles.xml":await this._parseStyles(a);break;default:a.path.match(/xl\/worksheets\/sheet\d+[.]xml/)?(o=a.path.match(/xl\/worksheets\/sheet(\d+)[.]xml/),u=o[1],this.sharedStrings&&this.workbookRels?yield*this._parseWorksheet(Za(a),u):await new Promise((f,c)=>{FV.file((h,d,p,g)=>{if(h)return c(h);s.push({sheetNo:u,path:d,tempFileCleanupCallback:g});let y=Bk.createWriteStream(d);return y.on("error",c),a.pipe(y),y.on("finish",()=>f())})})):a.path.match(/xl\/worksheets\/_rels\/sheet\d+[.]xml.rels/)&&(o=a.path.match(/xl\/worksheets\/_rels\/sheet(\d+)[.]xml.rels/),u=o[1],yield*this._parseHyperlinks(Za(a),u));break}a.autodrain()}for(let{sheetNo:a,path:o,tempFileCleanupCallback:u}of s){let f=Bk.createReadStream(o);f[Symbol.asyncIterator]||(f=f.pipe(new m1e)),yield*this._parseWorksheet(f,a),u()}}_emitEntry(e){this.options.entries==="emit"&&this.emit("entry",e)}async _parseRels(e){let r=new x1e;this.workbookRels=await r.parseStream(Za(e))}async _parseWorkbook(e){this._emitEntry({type:"workbook"});let r=new b1e;await r.parseStream(Za(e)),this.properties=r.map.workbookPr,this.model=r.model}async*_parseSharedStrings(e){switch(this._emitEntry({type:"shared-strings"}),this.options.sharedStrings){case"cache":this.sharedStrings=[];break;case"emit":break;default:return}let r=null,i=[],n=0,s=null;for await(let a of w1e(Za(e)))for(let{eventType:o,value:u}of a)if(o==="opentag"){let f=u;switch(f.name){case"b":s=s||{},s.bold=!0;break;case"charset":s=s||{},s.charset=parseInt(f.attributes.charset,10);break;case"color":s=s||{},s.color={},f.attributes.rgb&&(s.color.argb=f.attributes.argb),f.attributes.val&&(s.color.argb=f.attributes.val),f.attributes.theme&&(s.color.theme=f.attributes.theme);break;case"family":s=s||{},s.family=parseInt(f.attributes.val,10);break;case"i":s=s||{},s.italic=!0;break;case"outline":s=s||{},s.outline=!0;break;case"rFont":s=s||{},s.name=f.value;break;case"si":s=null,i=[],r=null;break;case"sz":s=s||{},s.size=parseInt(f.attributes.val,10);break;case"strike":break;case"t":r=null;break;case"u":s=s||{},s.underline=!0;break;case"vertAlign":s=s||{},s.vertAlign=f.attributes.val;break}}else if(o==="text")r=r?r+u:u;else if(o==="closetag")switch(u.name){case"r":i.push({font:s,text:r}),s=null,r=null;break;case"si":this.options.sharedStrings==="cache"?this.sharedStrings.push(i.length?{richText:i}:r):this.options.sharedStrings==="emit"&&(yield{index:n++,text:i.length?{richText:i}:r}),i=[],s=null,r=null;break}}async _parseStyles(e){this._emitEntry({type:"styles"}),this.options.styles==="cache"&&(this.styles=new DV,await this.styles.parseStream(Za(e)))}*_parseWorksheet(e,r){this._emitEntry({type:"worksheet",id:r});let i=new S1e({workbook:this,id:r,iterator:e,options:this.options}),n=(this.workbookRels||[]).find(a=>a.Target===`worksheets/sheet${r}.xml`),s=n&&(this.model.sheets||[]).find(a=>a.rId===n.Id);s&&(i.id=s.id,i.name=s.name,i.state=s.state),this.options.worksheets==="emit"&&(yield{eventType:"worksheet",value:i})}*_parseHyperlinks(e,r){this._emitEntry({type:"hyperlinks",id:r});let i=new E1e({workbook:this,id:r,iterator:e,options:this.options});this.options.hyperlinks==="emit"&&(yield{eventType:"hyperlinks",value:i})}};Oy.Options={worksheets:["emit","ignore"],sharedStrings:["cache","emit","ignore"],hyperlinks:["cache","emit","ignore"],styles:["cache","ignore"],entries:["emit","ignore"]};MV.exports=Oy});var BV=w((jPe,LV)=>{var qV={Workbook:T6(),ModelContainer:k6(),stream:{xlsx:{WorkbookWriter:pW(),WorkbookReader:PV()}}};Object.assign(qV,ni());LV.exports=qV});var $V=w(($Pe,jV)=>{if(parseInt(process.versions.node.split(".")[0],10)<10)throw new Error("For node versions older than 10, please use the ES5 Import: https://github.com/exceljs/exceljs#es5-imports");jV.exports=BV()});import{StdioServerTransport as dCe}from"@modelcontextprotocol/sdk/server/stdio.js";import{createServer as pCe}from"inistate-mcp";import{homedir as Y7}from"node:os";import{join as K7}from"node:path";function Q7(){return K7(Y7(),".inistate","core.db")}function Ds(t){let e=t.trim();if(e==="memory"||e===":memory:")return"memory";let r=/^([a-z][a-z0-9+.-]*):\/\//i.exec(e);return r?r[1].toLowerCase():"sqlite"}function OR(t=process.env){let e=(t.INISTATE_CORE_DB||"").trim()||Q7(),r,i=(t.INISTATE_CORE_CONNECTIONS||"").trim();if(i){let u;try{u=JSON.parse(i)}catch(f){throw new Error(`INISTATE_CORE_CONNECTIONS is not valid JSON: ${f instanceof Error?f.message:String(f)}`)}if(!u||typeof u!="object"||Array.isArray(u))throw new Error('INISTATE_CORE_CONNECTIONS must be a JSON object mapping module names to connection targets, e.g. {"NEC":"notion://<dbId>"}.');r=u}let n=r?"connections":Ds(e),a=(t.INISTATE_MCP_MODE||"").trim().toLowerCase()==="configure"?"configure":"runtime",o=t.INISTATE_LOG!=="0";return{dbTarget:e,scheme:n,mode:a,logEnabled:o,connections:r}}function yr(t){return(e,r)=>{if(!t)return;let i={ts:new Date().toISOString(),msg:e,...r};console.error(JSON.stringify(i))}}import{resolve as Q1e}from"node:path";import{pathToFileURL as J1e}from"node:url";var Fs=class t extends Error{code;details;constructor(e,r,i){super(r),this.name="EngineError",this.code=e,i&&(this.details=i),Object.setPrototypeOf(this,t.prototype)}};function ii(t){return new Fs("NOT_FOUND",t)}function kh(t,e="One or more fields failed validation"){return new Fs("VALIDATION_FAILED",e,t)}function IR(t){return new Fs("ILLEGAL_TRANSITION",t)}function NR(t){return new Fs("CONFLICT",t)}function DR(t){return t instanceof Fs}function MR(t){if(!t)return;let e=t.indexOf("(");return e===-1?t:t.slice(0,e)}function Wy(t){return t==null?!0:typeof t=="string"?t.trim()==="":Array.isArray(t)?t.length===0:!1}function J7(t){let e=t.trim();return e===""?!1:!Number.isNaN(Number(e))}function e9(t){return typeof t=="string"&&t.includes("@")&&t.includes(".")}function t9(t){if(typeof t!="string")return!1;try{let e=new URL(t);return!!e.protocol&&!!e.host}catch{return!1}}function Nn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function FR(t,e){return typeof t[e]=="string"&&t[e].length>0}function PR(t,e,r){switch(e){case"Integer":return typeof r=="number"&&Number.isInteger(r)||typeof r=="string"&&/^[-+]?\d+$/.test(r.trim())?null:`${t} must be a whole number`;case"Number":case"Currency":return typeof r=="number"&&Number.isFinite(r)||typeof r=="string"&&J7(r)?null:`${t} must be a number`;case"Date":return typeof r=="string"&&!Number.isNaN(Date.parse(r))?null:`${t} must be a valid date (e.g. 2026-03-01)`;case"DateTime":return typeof r=="string"&&!Number.isNaN(Date.parse(r))?null:`${t} must be a valid date-time (ISO 8601)`;case"DateRange":return Nn(r)&&typeof r.from=="string"&&typeof r.to=="string"&&!Number.isNaN(Date.parse(r.from))&&!Number.isNaN(Date.parse(r.to))?null:`${t} must have a valid from and to date`;case"YesNo":return typeof r=="boolean"||typeof r=="string"&&["true","false","yes","no"].includes(r.trim().toLowerCase())?null:`${t} must be true or false`;case"Email":{let i=Array.isArray(r)?r:[r];for(let n of i)if(!e9(n))return`${t} contains an invalid email address: ${String(n)}`;return null}case"Link":return t9(r)?null:`${t} must be a valid URL`;case"Image":case"File":return Nn(r)&&FR(r,"path")?null:`${t} must be a file object with a path (e.g. { name, path })`;case"Images":case"Files":{if(!Array.isArray(r))return`${t} must be an array of file objects (e.g. [{ name, path }])`;for(let i of r)if(!Nn(i)||!FR(i,"path"))return`${t} entries must be file objects with a path (e.g. { name, path })`;return null}case"Module":return Nn(r)&&"id"in r&&"value"in r?null:`${t} must be a reference object { value, id }`;case"Modules":{if(!Array.isArray(r))return`${t} must be an array of reference objects { value, id }`;for(let i of r)if(!Nn(i)||!("id"in i)||!("value"in i))return`${t} entries must be reference objects { value, id }`;return null}case"User":return Nn(r)&&"id"in r&&"value"in r&&"username"in r?null:`${t} must be a user reference { value, id, username }`;case"Users":{if(!Array.isArray(r))return`${t} must be an array of user references { value, id, username }`;for(let i of r)if(!Nn(i)||!("id"in i)||!("value"in i)||!("username"in i))return`${t} entries must be user references { value, id, username }`;return null}default:return null}}function qR(t){let e=new Map;for(let r of t)r?.name&&e.set(r.name,r);return e}function r9(t){return t?.fields?t.fields.map(e=>typeof e=="string"?{name:e}:e):[]}function Rh(t,e,r,i){let n=[],s=qR(t.information),a=t.activities.find(f=>f.name===e),o=r9(a);for(let[f,c]of Object.entries(r)){if(Wy(c))continue;let h=s.get(f);if(!h?.type)continue;let d=MR(h.type);if(d==="Table"){let g=i9(f,h,c);n.push(...g);continue}let p=PR(f,d,c);p&&n.push({field:f,message:p})}let u={...i,...r};for(let f of o)f.required&&Wy(u[f.name])&&n.push({field:f.name,message:`${f.name} is required`});return n}function i9(t,e,r){if(!Array.isArray(r))return[{field:t,message:`${t} must be a table (an array of rows)`}];let i=qR(e.fields??[]),n=[];return r.forEach((s,a)=>{if(!Nn(s)){n.push({field:`${t}[${a}]`,message:`${t}[${a}] must be a row object`});return}for(let[o,u]of Object.entries(s)){if(Wy(u))continue;let f=i.get(o);if(!f?.type)continue;let c=MR(f.type);if(c==="Table")continue;let h=`${t}[${a}].${o}`,d=PR(h,c,u);d&&n.push({field:h,message:d})}}),n}function n9(){return new Date().toISOString()}function Ah(t){return{name:String(t.name??""),information:Array.isArray(t.information)?t.information:[],states:Array.isArray(t.states)?t.states:[],activities:Array.isArray(t.activities)?t.activities:[],flows:Array.isArray(t.flows)?t.flows:[]}}function LR(t){return t.states.length>0}function Hy(t){return LR(t)?(t.states.find(r=>r.initial===!0)??t.states[0])?.name??null:null}function s9(t,e,r){let i=e===null||e==="";for(let n of t.flows)if(n.activity===r&&(i||n.from===""||n.from===e))return n;return null}function Ih(t,e){let r={},i=e===null||e==="";for(let n of t.flows)(i||n.from===""||n.from===e)&&(r[n.activity]??=[]).push(n.to);return{currentState:e,transitions:r}}var Oh=class{constructor(e){this.store=e}store;capabilities(){return{workspaces:!1,governedHistory:!1,files:!1,authorization:!1}}listModuleDefinitions(){return this.store.listModules().map(e=>e.definition)}getModuleDefinition(e){return this.store.getModule(e)?.definition??null}getStructure(e){let r=this.getModuleDefinition(e);return r?Ah(r):null}putModuleDefinition(e,r){this.store.putModule({name:e,definition:r})}renameModule(e,r){this.store.renameModule(e,r)}getEntry(e,r){return this.store.getEntry(e,r)}queryEntries(e,r){return this.store.queryEntries(e,r)}transitionsFor(e,r){let i=this.getStructure(e);return i?Ih(i,r):{currentState:r,transitions:{}}}submitActivity(e){let r=this.store.getModule(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let i=Ah(r.definition);if(e.idempotencyKey){let o=this.store.getIdempotent(e.idempotencyKey);if(o!==void 0)return o}let n=e.activity,s=e.input??{},a=e.entryId===void 0||n==="create";return this.store.transaction(o=>{let u=n9(),f;if(a){let c=Rh(i,n,s,{});if(c.length)throw kh(c);let h=o.insertEntry({module:e.module,state:Hy(i),version:1,data:s,createdAt:u,updatedAt:u});f={module:e.module,activity:n,entry:h,created:!0,deleted:!1}}else{let c=o.getEntry(e.module,e.entryId);if(!c)throw ii(`Entry not found: ${String(e.entryId)}`);if(e.expectedVersion!==void 0&&c.version!==e.expectedVersion)throw NR(`Version conflict on entry ${String(e.entryId)}: expected ${e.expectedVersion}, found ${c.version}`);if(n==="delete")o.deleteEntry(e.module,e.entryId),f={module:e.module,activity:n,entry:null,created:!1,deleted:!0};else if(n==="edit"||!LR(i)){let h=Rh(i,n,s,c.data);if(h.length)throw kh(h);let d={...c,data:{...c.data,...s},version:c.version+1,updatedAt:u};o.updateEntry(d),f={module:e.module,activity:n,entry:d,created:!1,deleted:!1}}else{let h=s9(i,c.state,n);if(!h)throw IR(`No flow permits activity '${n}' from state '${c.state??"\u2014"}' in module '${e.module}'`);let d=Rh(i,n,s,c.data);if(d.length)throw kh(d);let p={...c,data:{...c.data,...s},state:h.to,version:c.version+1,updatedAt:u};o.updateEntry(p),f={module:e.module,activity:n,entry:p,created:!1,deleted:!1}}}return e.idempotencyKey&&o.recordIdempotent(e.idempotencyKey,f),f})}submitActivities(e,r,i){return i.map(n=>{try{let s=this.submitActivity({module:e,activity:r,entryId:n.entryId,input:n.input,idempotencyKey:n.idempotencyKey,expectedVersion:n.expectedVersion});return{ok:!0,clientRef:n.clientRef,result:s}}catch(s){let a=s;return{ok:!1,clientRef:n.clientRef,code:a.code??"ERROR",message:a.message??String(s),details:a.details}}})}};import{readFileSync as jR,existsSync as $R}from"node:fs";import{dirname as UR,resolve as yu}from"node:path";import{fileURLToPath as a9}from"node:url";var o9=UR(a9(import.meta.url));function l9(t){let e=t;for(let r=0;r<8;r++){let i=yu(e,"data");if($R(yu(i,"inistate-schema.json")))return i;let n=UR(e);if(n===e)break;e=n}return yu(t,"../../data")}var WR=l9(o9),u9=yu(WR,"inistate-schema.json"),BR=yu(WR,"facts-module-design-guide.md"),Hi=JSON.parse(jR(u9,"utf-8")),DCe=$R(BR)?jR(BR,"utf-8"):"The FACTS Module Design Guide is not available in this distribution.",HR=["FieldType","FieldDefinition","SubFieldDefinition","StateDefinition","FileFieldValue","FileFieldInput","ModuleFieldValue","UserFieldValue","ErrorResponse"],f9=[...HR,"EntryData","Entry","EntryList","ActivityForm","ActivitySubmission","AvailableActivities","ActivityResult","FilterOperators"],c9=[...HR,"ActivityDefinition","ActivityFieldRef","FlowDefinition","ModuleSchema"];function h9(t,e){let r={};if(!t)return r;for(let i of e)i in t&&(r[i]=t[i]);return r}function zR(t){return{$schema:Hi.$schema,title:Hi.title,description:Hi.description,version:Hi.version,definitions:h9(Hi.definitions,t)}}var FCe=zR(f9),MCe=zR(c9),Xy=Hi.definitions?.FieldType?.enum??["Text","MultiText","Integer","Number","Currency","Date","DateTime","DateRange","Selection","Tag","YesNo","Email","Phone","Link","Image","Images","File","Files","Module","Modules","User","Users","Table","Signature","Formula"],d9=Hi.definitions?.ActivityDefinition?.properties?.actor?.enum??["human","ai","hybrid"],p9=Hi.workflow_guide?.state_color_system?.palette??{},Nh=Object.keys(p9),zy=Hi.workflow_guide?.state_color_system?.keyword_hints??{};function Vy(t){return t.startsWith("Selection(")&&t.endsWith(")")?!0:Xy.includes(t)}function XR(t){return Nh.length===0?/^#[0-9A-Fa-f]{6}$/.test(t):Nh.includes(t)}function VR(t){return d9.includes(t)}function GR(t){let e=t.toLowerCase();if((zy["#1E6B45"]||[]).some(s=>e.includes(s)))return"#1E6B45";if((zy["#8B2D2D"]||[]).some(s=>e.includes(s)))return"#8B2D2D";let n=["#2A7B50","#C0392B","#A07828","#6B4D91","#2968A8","#5A6070"];for(let s of n)if((zy[s]||[]).some(o=>e.includes(o)))return s;return"#2968A8"}function vu(t,e="create"){let r=[],i=[],n=t.name||"",s=t.information||[],a=t.states||[],o=t.activities||[],u=t.flows||[],f=a.length>0;!n&&e==="create"&&r.push("Module name is required.");let c=new Set;for(let h of s)c.has(h.name)&&r.push(`Duplicate field name: '${h.name}'.`),c.add(h.name);for(let h of s)if(h.type&&!Vy(h.type)&&r.push(`Field '${h.name}' has invalid type '${h.type}'. Valid types: ${Xy.join(", ")}.`),h.type==="Table")if(!h.fields||!Array.isArray(h.fields)||h.fields.length===0)r.push(`Table field '${h.name}' has no sub-fields defined.`);else for(let d of h.fields)d.type&&!Vy(d.type)&&r.push(`Table field '${h.name}' sub-field '${d.name}' has invalid type '${d.type}'.`);if(f){let h=a.filter(E=>E.initial===!0);h.length===0?r.push("No initial state defined \u2014 exactly one state must have initial: true."):h.length>1&&r.push(`Multiple initial states: ${h.map(E=>`'${E.name}'`).join(", ")}. Exactly one is allowed.`);let d=new Set;for(let E of a)d.has(E.name)&&r.push(`Duplicate state name: '${E.name}'.`),d.add(E.name);for(let E of a)E.color&&!XR(E.color)&&r.push(`State '${E.name}' has invalid color '${E.color}'. Valid colors: ${Nh.join(", ")}.`),E.color||i.push(`State '${E.name}' has no color \u2014 will use default.`);let p=new Set;for(let E of o)p.has(E.name)&&r.push(`Duplicate activity name: '${E.name}'.`),p.add(E.name);for(let E of o){if(E.actor&&!VR(E.actor)&&r.push(`Activity '${E.name}' has invalid actor '${E.actor}'. Valid: human, ai, hybrid.`),E.confidence_threshold!==void 0&&E.confidence_threshold!==null&&(E.confidence_threshold<0||E.confidence_threshold>1)&&r.push(`Activity '${E.name}' confidence_threshold must be between 0 and 1.`),E.fields&&Array.isArray(E.fields))for(let U of E.fields){let ee=typeof U=="string"?U:U.name;c.has(ee)||r.push(`Activity '${E.name}' references field '${ee}' which is not defined in information. Available fields: ${[...c].join(", ")}.`)}E.actor==="ai"&&(!E.confidence_threshold&&E.confidence_threshold!==0&&i.push(`Activity '${E.name}' has no confidence_threshold \u2014 AI agents will not be gated on this activity.`),E.ai_hint||i.push(`Activity '${E.name}' has actor 'ai' but no ai_hint \u2014 agents may struggle to execute correctly.`))}for(let E of u)E.from!==""&&!d.has(E.from)&&r.push(`Flow references state '${E.from}' (from) which is not defined. Available states: ${[...d].join(", ")}.`),d.has(E.to)||r.push(`Flow references state '${E.to}' (to) which is not defined. Available states: ${[...d].join(", ")}.`),p.has(E.activity)||r.push(`Flow from '${E.from}' to '${E.to}' references activity '${E.activity}' which is not defined in activities. Available activities: ${[...p].join(", ")}.`);let g=h.length>0?h[0].name:"",y=new Set(u.map(E=>E.to));for(let E of a)E.name!==g&&!y.has(E.name)&&i.push(`State '${E.name}' is unreachable \u2014 no flows lead to it.`);let v=new Set(u.map(E=>E.activity));for(let E of o)v.has(E.name)||i.push(`Activity '${E.name}' is not used in any flow.`);let b=new Set(u.map(E=>E.from)),k=a.filter(E=>!b.has(E.name));k.length===0&&i.push("No terminal states \u2014 process may run indefinitely.");let N={field_count:s.length,state_count:a.length,activity_count:o.length,flow_count:u.length,initial_state:g,terminal_states:k.map(E=>E.name),ai_activities:o.filter(E=>E.actor==="ai").length,hybrid_activities:o.filter(E=>E.actor==="hybrid").length,gated_activities:o.filter(E=>E.confidence_threshold&&E.confidence_threshold>0).length};return{valid:r.length===0,errors:r,warnings:i,summary:r.length===0?N:null}}return{valid:r.length===0,errors:r,warnings:i,summary:r.length===0?{field_count:s.length,module_type:"record_list"}:null}}var Rr=class t extends Error{structured;constructor(e){super(e.message),this.name="StructuredError",this.structured=e,Object.setPrototypeOf(this,t.prototype)}};function eo(t,e){let r=t?.[e];return Array.isArray(r)?r:[]}function mi(t){if(t instanceof Rr)return t;if(DR(t))switch(t.code){case"NOT_FOUND":return new Rr({error:"Not found",message:t.message,agent_action:"Verify the module name or entry ID. Do not retry with the same values."});case"VALIDATION_FAILED":return new Rr({error:"Validation failed",message:t.message,details:t.details,agent_action:"Surface details[].field and details[].message, correct the input, and retry."});case"ILLEGAL_TRANSITION":return new Rr({error:"Illegal transition",message:t.message,agent_action:"This activity is not legal from the entry's current state. Call get_form or get_entry to see availableActivities, then submit a permitted activity."});case"CONFLICT":return new Rr({error:"Conflict",message:t.message,agent_action:"The entry changed since you read it. Re-read it with get_entry and retry with the new version."})}return new Rr({error:"Request failed",message:t instanceof Error?t.message:String(t),agent_action:"Unexpected error. Report to the user."})}function Gy(t,e){let r=Ih(t,e);return{standard:["edit","delete"],custom:Object.keys(r.transitions),stateFlow:{currentState:r.currentState,transitions:r.transitions}}}function ZR(t,e,r){return{module:t,entryId:e.id,documentId:e.documentId,state:e.state,date:e.createdAt,data:e.data,version:e.version,createdDate:e.createdAt,updatedDate:e.updatedAt,availableActivities:Gy(r,e.state)}}var Dh=class{kind="local";engine;constructor(e){this.engine=e}capabilities(){let e=this.engine.capabilities();return{workspaces:e.workspaces,governedHistory:e.governedHistory,files:e.files,authorization:e.authorization,modes:["runtime","configure"]}}async listModules(){try{let r=this.engine.listModuleDefinitions().map(i=>{let n=Ah(i);return{name:n.name,icon:i.icon??null,description:i.description??null,type:n.states.length>0?"workflow":"record_list"}});return{list:r,totalItems:r.length}}catch(e){throw mi(e)}}async getModuleSchema(e){try{let r=this.engine.getModuleDefinition(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let i={name:r.name,icon:r.icon,description:r.description,information:eo(r,"information"),states:eo(r,"states")};return e.tier==="extended"?{...i,activities:eo(r,"activities"),flows:eo(r,"flows")}:i}catch(r){throw mi(r)}}async getModuleCanvas(e){try{let r=this.engine.getModuleDefinition(e.module);if(!r)throw ii(`Module not found: ${e.module}`);return{id:r.id??r.name,...r}}catch(r){throw mi(r)}}async createModule(e){try{let r=vu(e,"create");if(!r.valid)throw new Rr({error:"Validation failed",message:r.errors.join(" ")||"Schema validation failed",details:r.errors.map(n=>({field:"schema",message:n})),agent_action:"Fix the schema errors and retry. Call validate_design to check before submitting."});let i=String(e.name??"");if(this.engine.getModuleDefinition(i))throw new Rr({error:"Module already exists",message:`A module named '${i}' already exists.`,agent_action:"Use update_module to modify it, or choose a different name."});return this.engine.putModuleDefinition(i,e),{id:i,name:i,message:`Module '${i}' created`,warnings:r.warnings,summary:r.summary}}catch(r){throw mi(r)}}async updateModule(e){try{let r=String(e.id),i=this.engine.getModuleDefinition(r);if(!i)throw ii(`Module not found: ${r}`);let n={...i};for(let o of["icon","description","information","states","activities","flows"])o in e.patch&&(n[o]=e.patch[o]);let s=e.patch.name!==void 0?String(e.patch.name):r;n.name=s;let a=vu(n,"update");if(!a.valid)throw new Rr({error:"Validation failed",message:a.errors.join(" ")||"Schema validation failed",details:a.errors.map(o=>({field:"schema",message:o})),agent_action:"Fix the schema errors and retry. Call validate_design to check before submitting."});if(s!==r){if(this.engine.getModuleDefinition(s))throw new Rr({error:"Validation failed",message:`Cannot rename to '${s}' \u2014 a module with that name already exists.`,agent_action:"Choose a different name."});this.engine.renameModule(r,s)}return this.engine.putModuleDefinition(s,n),{id:s,name:s,message:`Module '${s}' updated`,warnings:a.warnings}}catch(r){throw mi(r)}}async listEntries(e){try{let r=this.engine.getStructure(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let{items:i,total:n}=this.engine.queryEntries(e.module,{state:e.state,search:e.search,filters:e.filters,sortBy:e.sortBy,sortDirection:e.sortDirection,page:e.currentPage,pageSize:e.pageSize,fields:e.fields});return{moduleId:e.module,page:e.currentPage??0,pageSize:e.pageSize??50,totalItems:n,list:i.map(s=>ZR(e.module,s,r))}}catch(r){throw mi(r)}}async getEntry(e){try{let r=this.engine.getStructure(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let i=this.engine.getEntry(e.module,e.entryId);if(!i)throw ii(`Entry not found: ${String(e.entryId)}`);return ZR(e.module,i,r)}catch(r){throw mi(r)}}async getForm(e){try{let r=this.engine.getModuleDefinition(e.module),i=this.engine.getStructure(e.module);if(!r||!i)throw ii(`Module not found: ${e.module}`);let n=eo(r,"information"),s=new Map(n.map(y=>[String(y.name),y])),a=eo(r,"activities").find(y=>y.name===e.activity),o=Array.isArray(a?.fields)?a.fields:[],f=(o.length>0?o.map(y=>typeof y=="string"?{name:y}:y):n.map(y=>({name:String(y.name)}))).map(y=>{let v=s.get(y.name)??{},b={type:v.type,required:y.required??!1,readOnly:y.readOnly??!1},k=y.options??v.options;return k&&(b.options=k),v.fields&&(b.fields=v.fields),{[y.name]:b}}),c={},h,d=Hy(i);if(e.entryId!==void 0&&e.entryId!==null){let y=this.engine.getEntry(e.module,e.entryId);y&&(c=y.data,h=y.documentId,d=y.state)}let g=Ih(i,d).transitions[e.activity]??[];return{module:e.module,activity:e.activity,entryId:e.entryId??null,documentId:h,form:f,defaults:c,states:g,availableActivities:Gy(i,d)}}catch(r){throw mi(r)}}async submitActivity(e){try{let r=this.engine.submitActivity({module:e.module,activity:e.activity,entryId:e.entryId,input:e.input,idempotencyKey:e.idempotencyKey,expectedVersion:e.expectedVersion});if(r.deleted)return{module:e.module,activity:e.activity,entryId:e.entryId,deleted:!0,message:null};let i=r.entry,n=this.engine.getStructure(e.module);return{module:e.module,activity:e.activity,entryId:i.id,documentId:i.documentId,state:i.state,version:i.version,message:null,availableActivities:Gy(n,i.state)}}catch(r){throw mi(r)}}async submitActivities(e){try{let r=this.engine.submitActivities(e.module,e.activity,e.items),i=0,n=0,s=r.map(a=>{if(a.ok){i++;let o=a.result;if(o.deleted)return{success:!0,clientRef:a.clientRef,deleted:!0};let u=o.entry;return{success:!0,clientRef:a.clientRef,entryId:u.id,documentId:u.documentId,state:u.state,version:u.version}}return n++,{success:!1,clientRef:a.clientRef,error:a.code,message:a.message,details:a.details}});return{module:e.module,activity:e.activity,results:s,summary:{total:r.length,succeeded:i,failed:n}}}catch(r){throw mi(r)}}};function g9(t){let e=t.split(/[^A-Za-z0-9]+/).filter(Boolean);return e.length>=2?e.map(i=>i[0]).join("").slice(0,4).toUpperCase():((e[0]??"REC").replace(/[^A-Za-z0-9]/g,"").slice(0,3)||"REC").toUpperCase()}function Ms(t,e){return`${g9(t)}-${String(e).padStart(4,"0")}`}function tr(t){return String(t??"").toLowerCase()}function Ar(t){if(typeof t=="number")return t;if(typeof t=="string"&&t.trim()!==""&&!Number.isNaN(Number(t)))return Number(t);if(typeof t=="string"){let e=Date.parse(t);if(!Number.isNaN(e))return e}return null}function m9(t,e){for(let[r,i]of Object.entries(e))switch(r){case"is":if(t!==i)return!1;break;case"not":if(t===i)return!1;break;case"contains":if(!tr(t).includes(tr(i)))return!1;break;case"startsWith":if(!tr(t).startsWith(tr(i)))return!1;break;case"endsWith":if(!tr(t).endsWith(tr(i)))return!1;break;case"min":case"after":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n<s)return!1;break}case"max":case"before":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n>s)return!1;break}case"above":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n<=s)return!1;break}case"below":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n>=s)return!1;break}case"between":{if(!Array.isArray(i)||i.length!==2)return!1;let n=Ar(t),s=Ar(i[0]),a=Ar(i[1]);if(n===null||s===null||a===null||n<s||n>a)return!1;break}case"empty":{let n=t==null||t===""||Array.isArray(t)&&t.length===0;if(!!i!==n)return!1;break}case"exists":{let n=t!=null;if(!!i!==n)return!1;break}case"excludes":if(tr(t).includes(tr(i)))return!1;break;case"yes":if(!(t===!0||tr(t)==="true"||tr(t)==="yes"))return!1;break;case"no":if(!(t===!1||tr(t)==="false"||tr(t)==="no"))return!1;break;default:break}return!0}function y9(t,e,r){let i=t.data[e];return r!==null&&typeof r=="object"&&!Array.isArray(r)?m9(i,r):typeof i=="string"||typeof r=="string"?tr(i)===tr(r):i===r}function YR(t,e){for(let[r,i]of Object.entries(e)){if(r==="or"&&Array.isArray(i)){if(!i.some(s=>s&&typeof s=="object"&&YR(t,s)))return!1;continue}if(!y9(t,r,i))return!1}return!0}function v9(t,e){let r=e.toLowerCase();if(t.documentId.toLowerCase().includes(r))return!0;for(let i of Object.values(t.data))if(typeof i=="string"&&i.toLowerCase().includes(r))return!0;return!1}function to(t,e){let r=t;e.state&&(r=r.filter(u=>u.state===e.state)),e.search&&(r=r.filter(u=>v9(u,e.search))),e.filters&&(r=r.filter(u=>YR(u,e.filters)));let i=r.length;if(e.sortBy){let u=e.sortDirection==="desc"?-1:1,f=e.sortBy;r=[...r].sort((c,h)=>{let d=c.data[f],p=h.data[f],g=Ar(d),y=Ar(p);return g!==null&&y!==null?(g-y)*u:tr(d).localeCompare(tr(p))*u})}let n=e.pageSize&&e.pageSize>0?Math.min(e.pageSize,500):50,a=(e.page&&e.page>0?e.page:0)*n,o=r.slice(a,a+n);if(e.fields&&e.fields.length>0){let u=new Set(e.fields);o=o.map(f=>({...f,data:Object.fromEntries(Object.entries(f.data).filter(([c])=>u.has(c)))}))}return{items:o,total:i}}var Or=t=>structuredClone(t);function _9(t){let e=new Map;for(let[r,i]of t)e.set(r,new Map([...i].map(([n,s])=>[n,Or(s)])));return e}var ro=class{modules=new Map;entries=new Map;idem=new Map;counters=new Map;init(){}close(){}getModule(e){let r=this.modules.get(e);return r?Or(r):null}listModules(){return[...this.modules.values()].map(Or)}putModule(e){this.modules.set(e.name,Or(e))}renameModule(e,r){if(e===r)return;let i=this.modules.get(e);i&&(this.modules.delete(e),this.modules.set(r,{...i,name:r}));let n=this.entries.get(e);if(n){this.entries.delete(e);for(let a of n.values())a.module=r;this.entries.set(r,n)}let s=this.counters.get(e);s!==void 0&&(this.counters.delete(e),this.counters.set(r,s))}getEntry(e,r){let i=this.entries.get(e)?.get(String(r));return i?Or(i):null}queryEntries(e,r){let i=[...this.entries.get(e)?.values()??[]].map(Or);return to(i,r)}getIdempotent(e){return this.idem.has(e)?Or(this.idem.get(e)):void 0}transaction(e){let r={entries:_9(this.entries),idem:new Map(this.idem),counters:new Map(this.counters)},n=e({getEntry:(s,a)=>{let o=r.entries.get(s)?.get(String(a));return o?Or(o):null},insertEntry:s=>{let a=(r.counters.get(s.module)??0)+1;r.counters.set(s.module,a);let o={id:a,documentId:Ms(s.module,a),module:s.module,state:s.state,version:s.version,data:Or(s.data),createdAt:s.createdAt,updatedAt:s.updatedAt},u=r.entries.get(s.module);return u||(u=new Map,r.entries.set(s.module,u)),u.set(String(a),o),Or(o)},updateEntry:s=>{let a=r.entries.get(s.module);if(!a)throw new Error(`module not loaded: ${s.module}`);return a.set(String(s.id),Or(s)),Or(s)},deleteEntry:(s,a)=>{r.entries.get(s)?.delete(String(a))},recordIdempotent:(s,a)=>{r.idem.set(s,Or(a))}});return this.entries=r.entries,this.idem=r.idem,this.counters=r.counters,n}};import w9 from"better-sqlite3";import{mkdirSync as b9}from"node:fs";import{dirname as x9}from"node:path";function KR(t){return{id:t.id,documentId:t.document_id,module:t.module,state:t.state,version:t.version,data:JSON.parse(t.data),createdAt:t.created_at,updatedAt:t.updated_at}}var Ps=class{db;constructor(e){e!==":memory:"&&b9(x9(e),{recursive:!0}),this.db=new w9(e),this.db.pragma("journal_mode = WAL"),this.db.pragma("synchronous = NORMAL"),this.db.pragma("foreign_keys = ON"),this.init()}init(){this.db.exec(`
|
|
228
|
+
Unsupported type: `+t.type,"ENOTSUP");t._finish()})};ei.prototype._stat=function(t){var e=this,r=e.props,i=r.follow?"stat":"lstat",n=e._proxy||e;t?s(null,t):Jr[i](e._path,s);function s(a,o){if(e.filter&&!e.filter.call(n,n,o)){e._aborted=!0,e.emit("end"),e.emit("close");return}if(a||!o)return Rk(e);e._old=o;var u=BX(o);if(u!==e.type||e.type==="File"&&o.nlink>1)return oTe(e._path,function(f){if(f)return e.error(f);e._old=null,Rk(e)});Rk(e)}};function Rk(t){lTe(Yc.dirname(t._path),ei.dirmode,function(e,r){return e?t.error(e):(t._madeDir=r,t._create())})}function $X(t,e,r,i,n){var s=e.mode,a=e.follow||t.type!=="SymbolicLink"?"chmod":"lchmod";if(!Jr[a]||typeof s!="number")return n();var o=r.mode&parseInt("0777",8);if(s=s&parseInt("0777",8),s===o)return n();Jr[a](i,s,n)}function UX(t,e,r,i,n){if(process.platform==="win32"||!process.getuid||process.getuid()!==0||typeof e.uid!="number"&&typeof e.gid!="number"||r.uid===e.uid&&r.gid===e.gid)return n();var s=t.props.follow||t.type!=="SymbolicLink"?"chown":"lchown";if(!Jr[s])return n();typeof e.uid!="number"&&(e.uid=r.uid),typeof e.gid!="number"&&(e.gid=r.gid),Jr[s](i,e.uid,e.gid,n)}function WX(t,e,r,i,n){if(!Jr.utimes||process.platform==="win32")return n();var s=e.follow||t.type!=="SymbolicLink"?"utimes":"lutimes";if(s==="lutimes"&&!Jr[s]&&(s="utimes"),!Jr[s])return n();var a=r.atime,o=r.mtime,u=e.atime,f=e.mtime;if(u===void 0&&(u=a),f===void 0&&(f=o),qX(u)||(u=new Date(u)),qX(f)||(u=new Date(f)),u.getTime()===a.getTime()&&f.getTime()===o.getTime())return n();Jr[s](i,u,f,n)}ei.prototype._finish=function(){var t=this;if(t._finishing)return;t._finishing=!0;var e=0,r=null,i=!1;if(t._old)t._old.atime=new Date(0),t._old.mtime=new Date(0),s(t._old);else{var n=t.props.follow?"stat":"lstat";Jr[n](t._path,function(o,u){if(o)if(o.code==="ENOENT"&&(t.type==="Link"||t.type==="SymbolicLink")&&process.platform==="win32"){t.ready=!0,t.emit("ready"),t.emit("end"),t.emit("close"),t.end=t._finish=function(){};return}else return t.error(o);s(t._old=u)})}return;function s(o){e+=3,$X(t,t.props,o,t._path,a("chmod")),UX(t,t.props,o,t._path,a("chown")),WX(t,t.props,o,t._path,a("utimes"))}function a(o){return function(u){if(r)return;if(u)return u.fstream_finish_call=o,t.error(r=u);if(--e>0||i)return;if(i=!0,t._madeDir)HX(t,t._path,f);else return f();function f(c){if(c)return c.fstream_finish_call="setupMadeDir",t.error(c);t.emit("end"),t.emit("close")}}}};function HX(t,e,r){var i=t._madeDir,n=Yc.dirname(e);dTe(t,n,function(s){if(s)return r(s);if(n===i)return r();HX(t,n,r)})}function dTe(t,e,r){var i={};Object.keys(t.props).forEach(function(o){i[o]=t.props[o],o==="mode"&&t.type!=="Directory"&&(i[o]=i[o]|parseInt("0111",8))});var n=3,s=null;Jr.stat(e,function(o,u){if(o)return r(s=o);$X(t,i,u,e,a),UX(t,i,u,e,a),WX(t,i,u,e,a)});function a(o){if(!s){if(o)return r(s=o);if(--n===0)return r()}}}ei.prototype.pipe=function(){this.error("Can't pipe from writable stream")};ei.prototype.add=function(){this.error("Can't add to non-Directory type")};ei.prototype.write=function(){return!0};function pTe(t){return Object.prototype.toString.call(t)}function qX(t){return typeof t=="object"&&pTe(t)==="[object Date]"}});var Ak=w(De=>{De.Abstract=py();De.Reader=za();De.Writer=iu();De.File={Reader:hk(),Writer:Tk()};De.Dir={Reader:ck(),Writer:Sk()};De.Link={Reader:uk(),Writer:Ek()};De.Proxy={Reader:pk(),Writer:kk()};De.Reader.Dir=De.DirReader=De.Dir.Reader;De.Reader.File=De.FileReader=De.File.Reader;De.Reader.Link=De.LinkReader=De.Link.Reader;De.Reader.Proxy=De.ProxyReader=De.Proxy.Reader;De.Writer.Dir=De.DirWriter=De.Dir.Writer;De.Writer.File=De.FileWriter=De.File.Writer;De.Writer.Link=De.LinkWriter=De.Link.Writer;De.Writer.Proxy=De.ProxyWriter=De.Proxy.Writer;De.collect=_y()});var VX=w((RPe,XX)=>{XX.exports=wTe;var gTe=iy(),mTe=Ak().Writer,Ok=Y("path"),yTe=Y("stream"),vTe=ak(),_Te=Ts();function wTe(t){t.path=Ok.resolve(Ok.normalize(t.path));var e=new gTe(t),r=new yTe.Writable({objectMode:!0});r._write=function(n,s,a){if(n.type=="Directory")return a();var o=Ok.join(t.path,n.path);if(o.indexOf(t.path)!=0)return a();let u=t.getWriter?t.getWriter({path:o}):mTe({path:o});n.pipe(u).on("error",a).on("close",a)};var i=vTe(e,r);return e.once("crx-header",function(n){i.crxHeader=n}),e.pipe(r).on("finish",function(){i.emit("close")}),i.promise=function(){return new _Te(function(n,s){i.on("close",n),i.on("error",s)})},i}});var GX=w((APe,xy)=>{var Pt=(function(t){"use strict";var e=1e7,r=7,i=9007199254740992,n=d(i),s="0123456789abcdefghijklmnopqrstuvwxyz",a=typeof BigInt=="function";function o(m,x,A,D){return typeof m>"u"?o[0]:typeof x<"u"?+x==10&&!A?le(m):ri(m,x,A,D):le(m)}function u(m,x){this.value=m,this.sign=x,this.isSmall=!1}u.prototype=Object.create(o.prototype);function f(m){this.value=m,this.sign=m<0,this.isSmall=!0}f.prototype=Object.create(o.prototype);function c(m){this.value=m}c.prototype=Object.create(o.prototype);function h(m){return-i<m&&m<i}function d(m){return m<1e7?[m]:m<1e14?[m%1e7,Math.floor(m/1e7)]:[m%1e7,Math.floor(m/1e7)%1e7,Math.floor(m/1e14)]}function p(m){g(m);var x=m.length;if(x<4&&$(m,n)<0)switch(x){case 0:return 0;case 1:return m[0];case 2:return m[0]+m[1]*e;default:return m[0]+(m[1]+m[2]*e)*e}return m}function g(m){for(var x=m.length;m[--x]===0;);m.length=x+1}function y(m){for(var x=new Array(m),A=-1;++A<m;)x[A]=0;return x}function v(m){return m>0?Math.floor(m):Math.ceil(m)}function b(m,x){var A=m.length,D=x.length,X=new Array(A),j=0,V=e,Q,ne;for(ne=0;ne<D;ne++)Q=m[ne]+x[ne]+j,j=Q>=V?1:0,X[ne]=Q-j*V;for(;ne<A;)Q=m[ne]+j,j=Q===V?1:0,X[ne++]=Q-j*V;return j>0&&X.push(j),X}function k(m,x){return m.length>=x.length?b(m,x):b(x,m)}function N(m,x){var A=m.length,D=new Array(A),X=e,j,V;for(V=0;V<A;V++)j=m[V]-X+x,x=Math.floor(j/X),D[V]=j-x*X,x+=1;for(;x>0;)D[V++]=x%X,x=Math.floor(x/X);return D}u.prototype.add=function(m){var x=le(m);if(this.sign!==x.sign)return this.subtract(x.negate());var A=this.value,D=x.value;return x.isSmall?new u(N(A,Math.abs(D)),this.sign):new u(k(A,D),this.sign)},u.prototype.plus=u.prototype.add,f.prototype.add=function(m){var x=le(m),A=this.value;if(A<0!==x.sign)return this.subtract(x.negate());var D=x.value;if(x.isSmall){if(h(A+D))return new f(A+D);D=d(Math.abs(D))}return new u(N(D,Math.abs(A)),A<0)},f.prototype.plus=f.prototype.add,c.prototype.add=function(m){return new c(this.value+le(m).value)},c.prototype.plus=c.prototype.add;function E(m,x){var A=m.length,D=x.length,X=new Array(A),j=0,V=e,Q,ne;for(Q=0;Q<D;Q++)ne=m[Q]-j-x[Q],ne<0?(ne+=V,j=1):j=0,X[Q]=ne;for(Q=D;Q<A;Q++){if(ne=m[Q]-j,ne<0)ne+=V;else{X[Q++]=ne;break}X[Q]=ne}for(;Q<A;Q++)X[Q]=m[Q];return g(X),X}function U(m,x,A){var D;return $(m,x)>=0?D=E(m,x):(D=E(x,m),A=!A),D=p(D),typeof D=="number"?(A&&(D=-D),new f(D)):new u(D,A)}function ee(m,x,A){var D=m.length,X=new Array(D),j=-x,V=e,Q,ne;for(Q=0;Q<D;Q++)ne=m[Q]+j,j=Math.floor(ne/V),ne%=V,X[Q]=ne<0?ne+V:ne;return X=p(X),typeof X=="number"?(A&&(X=-X),new f(X)):new u(X,A)}u.prototype.subtract=function(m){var x=le(m);if(this.sign!==x.sign)return this.add(x.negate());var A=this.value,D=x.value;return x.isSmall?ee(A,Math.abs(D),this.sign):U(A,D,this.sign)},u.prototype.minus=u.prototype.subtract,f.prototype.subtract=function(m){var x=le(m),A=this.value;if(A<0!==x.sign)return this.add(x.negate());var D=x.value;return x.isSmall?new f(A-D):ee(D,Math.abs(A),A>=0)},f.prototype.minus=f.prototype.subtract,c.prototype.subtract=function(m){return new c(this.value-le(m).value)},c.prototype.minus=c.prototype.subtract,u.prototype.negate=function(){return new u(this.value,!this.sign)},f.prototype.negate=function(){var m=this.sign,x=new f(-this.value);return x.sign=!m,x},c.prototype.negate=function(){return new c(-this.value)},u.prototype.abs=function(){return new u(this.value,!1)},f.prototype.abs=function(){return new f(Math.abs(this.value))},c.prototype.abs=function(){return new c(this.value>=0?this.value:-this.value)};function F(m,x){var A=m.length,D=x.length,X=A+D,j=y(X),V=e,Q,ne,he,we,ve;for(he=0;he<A;++he){we=m[he];for(var Ce=0;Ce<D;++Ce)ve=x[Ce],Q=we*ve+j[he+Ce],ne=Math.floor(Q/V),j[he+Ce]=Q-ne*V,j[he+Ce+1]+=ne}return g(j),j}function L(m,x){var A=m.length,D=new Array(A),X=e,j=0,V,Q;for(Q=0;Q<A;Q++)V=m[Q]*x+j,j=Math.floor(V/X),D[Q]=V-j*X;for(;j>0;)D[Q++]=j%X,j=Math.floor(j/X);return D}function I(m,x){for(var A=[];x-- >0;)A.push(0);return A.concat(m)}function Z(m,x){var A=Math.max(m.length,x.length);if(A<=30)return F(m,x);A=Math.ceil(A/2);var D=m.slice(A),X=m.slice(0,A),j=x.slice(A),V=x.slice(0,A),Q=Z(X,V),ne=Z(D,j),he=Z(k(X,D),k(V,j)),we=k(k(Q,I(E(E(he,Q),ne),A)),I(ne,2*A));return g(we),we}function H(m,x){return-.012*m-.012*x+15e-6*m*x>0}u.prototype.multiply=function(m){var x=le(m),A=this.value,D=x.value,X=this.sign!==x.sign,j;if(x.isSmall){if(D===0)return o[0];if(D===1)return this;if(D===-1)return this.negate();if(j=Math.abs(D),j<e)return new u(L(A,j),X);D=d(j)}return H(A.length,D.length)?new u(Z(A,D),X):new u(F(A,D),X)},u.prototype.times=u.prototype.multiply;function O(m,x,A){return m<e?new u(L(x,m),A):new u(F(x,d(m)),A)}f.prototype._multiplyBySmall=function(m){return h(m.value*this.value)?new f(m.value*this.value):O(Math.abs(m.value),d(Math.abs(this.value)),this.sign!==m.sign)},u.prototype._multiplyBySmall=function(m){return m.value===0?o[0]:m.value===1?this:m.value===-1?this.negate():O(Math.abs(m.value),this.value,this.sign!==m.sign)},f.prototype.multiply=function(m){return le(m)._multiplyBySmall(this)},f.prototype.times=f.prototype.multiply,c.prototype.multiply=function(m){return new c(this.value*le(m).value)},c.prototype.times=c.prototype.multiply;function q(m){var x=m.length,A=y(x+x),D=e,X,j,V,Q,ne;for(V=0;V<x;V++){Q=m[V],j=0-Q*Q;for(var he=V;he<x;he++)ne=m[he],X=2*(Q*ne)+A[V+he]+j,j=Math.floor(X/D),A[V+he]=X-j*D;A[V+x]=j}return g(A),A}u.prototype.square=function(){return new u(q(this.value),!1)},f.prototype.square=function(){var m=this.value*this.value;return h(m)?new f(m):new u(q(d(Math.abs(this.value))),!1)},c.prototype.square=function(m){return new c(this.value*this.value)};function B(m,x){var A=m.length,D=x.length,X=e,j=y(x.length),V=x[D-1],Q=Math.ceil(X/(2*V)),ne=L(m,Q),he=L(x,Q),we,ve,Ce,gt,er,In,fu;for(ne.length<=A&&ne.push(0),he.push(0),V=he[D-1],ve=A-D;ve>=0;ve--){for(we=X-1,ne[ve+D]!==V&&(we=Math.floor((ne[ve+D]*X+ne[ve+D-1])/V)),Ce=0,gt=0,In=he.length,er=0;er<In;er++)Ce+=we*he[er],fu=Math.floor(Ce/X),gt+=ne[ve+er]-(Ce-fu*X),Ce=fu,gt<0?(ne[ve+er]=gt+X,gt=-1):(ne[ve+er]=gt,gt=0);for(;gt!==0;){for(we-=1,Ce=0,er=0;er<In;er++)Ce+=ne[ve+er]-X+he[er],Ce<0?(ne[ve+er]=Ce+X,Ce=0):(ne[ve+er]=Ce,Ce=1);gt+=Ce}j[ve]=we}return ne=T(ne,Q)[0],[p(j),p(ne)]}function J(m,x){for(var A=m.length,D=x.length,X=[],j=[],V=e,Q,ne,he,we,ve;A;){if(j.unshift(m[--A]),g(j),$(j,x)<0){X.push(0);continue}ne=j.length,he=j[ne-1]*V+j[ne-2],we=x[D-1]*V+x[D-2],ne>D&&(he=(he+1)*V),Q=Math.ceil(he/we);do{if(ve=L(x,Q),$(ve,j)<=0)break;Q--}while(Q);X.push(Q),j=E(j,ve)}return X.reverse(),[p(X),p(j)]}function T(m,x){var A=m.length,D=y(A),X=e,j,V,Q,ne;for(Q=0,j=A-1;j>=0;--j)ne=Q*X+m[j],V=v(ne/x),Q=ne-V*x,D[j]=V|0;return[D,Q|0]}function M(m,x){var A,D=le(x);if(a)return[new c(m.value/D.value),new c(m.value%D.value)];var X=m.value,j=D.value,V;if(j===0)throw new Error("Cannot divide by zero");if(m.isSmall)return D.isSmall?[new f(v(X/j)),new f(X%j)]:[o[0],m];if(D.isSmall){if(j===1)return[m,o[0]];if(j==-1)return[m.negate(),o[0]];var Q=Math.abs(j);if(Q<e){A=T(X,Q),V=p(A[0]);var ne=A[1];return m.sign&&(ne=-ne),typeof V=="number"?(m.sign!==D.sign&&(V=-V),[new f(V),new f(ne)]):[new u(V,m.sign!==D.sign),new f(ne)]}j=d(Q)}var he=$(X,j);if(he===-1)return[o[0],m];if(he===0)return[o[m.sign===D.sign?1:-1],o[0]];X.length+j.length<=200?A=B(X,j):A=J(X,j),V=A[0];var we=m.sign!==D.sign,ve=A[1],Ce=m.sign;return typeof V=="number"?(we&&(V=-V),V=new f(V)):V=new u(V,we),typeof ve=="number"?(Ce&&(ve=-ve),ve=new f(ve)):ve=new u(ve,Ce),[V,ve]}u.prototype.divmod=function(m){var x=M(this,m);return{quotient:x[0],remainder:x[1]}},c.prototype.divmod=f.prototype.divmod=u.prototype.divmod,u.prototype.divide=function(m){return M(this,m)[0]},c.prototype.over=c.prototype.divide=function(m){return new c(this.value/le(m).value)},f.prototype.over=f.prototype.divide=u.prototype.over=u.prototype.divide,u.prototype.mod=function(m){return M(this,m)[1]},c.prototype.mod=c.prototype.remainder=function(m){return new c(this.value%le(m).value)},f.prototype.remainder=f.prototype.mod=u.prototype.remainder=u.prototype.mod,u.prototype.pow=function(m){var x=le(m),A=this.value,D=x.value,X,j,V;if(D===0)return o[1];if(A===0)return o[0];if(A===1)return o[1];if(A===-1)return x.isEven()?o[1]:o[-1];if(x.sign)return o[0];if(!x.isSmall)throw new Error("The exponent "+x.toString()+" is too large.");if(this.isSmall&&h(X=Math.pow(A,D)))return new f(v(X));for(j=this,V=o[1];D&!0&&(V=V.times(j),--D),D!==0;)D/=2,j=j.square();return V},f.prototype.pow=u.prototype.pow,c.prototype.pow=function(m){var x=le(m),A=this.value,D=x.value,X=BigInt(0),j=BigInt(1),V=BigInt(2);if(D===X)return o[1];if(A===X)return o[0];if(A===j)return o[1];if(A===BigInt(-1))return x.isEven()?o[1]:o[-1];if(x.isNegative())return new c(X);for(var Q=this,ne=o[1];(D&j)===j&&(ne=ne.times(Q),--D),D!==X;)D/=V,Q=Q.square();return ne},u.prototype.modPow=function(m,x){if(m=le(m),x=le(x),x.isZero())throw new Error("Cannot take modPow with modulus 0");var A=o[1],D=this.mod(x);for(m.isNegative()&&(m=m.multiply(o[-1]),D=D.modInv(x));m.isPositive();){if(D.isZero())return o[0];m.isOdd()&&(A=A.multiply(D).mod(x)),m=m.divide(2),D=D.square().mod(x)}return A},c.prototype.modPow=f.prototype.modPow=u.prototype.modPow;function $(m,x){if(m.length!==x.length)return m.length>x.length?1:-1;for(var A=m.length-1;A>=0;A--)if(m[A]!==x[A])return m[A]>x[A]?1:-1;return 0}u.prototype.compareAbs=function(m){var x=le(m),A=this.value,D=x.value;return x.isSmall?1:$(A,D)},f.prototype.compareAbs=function(m){var x=le(m),A=Math.abs(this.value),D=x.value;return x.isSmall?(D=Math.abs(D),A===D?0:A>D?1:-1):-1},c.prototype.compareAbs=function(m){var x=this.value,A=le(m).value;return x=x>=0?x:-x,A=A>=0?A:-A,x===A?0:x>A?1:-1},u.prototype.compare=function(m){if(m===1/0)return-1;if(m===-1/0)return 1;var x=le(m),A=this.value,D=x.value;return this.sign!==x.sign?x.sign?1:-1:x.isSmall?this.sign?-1:1:$(A,D)*(this.sign?-1:1)},u.prototype.compareTo=u.prototype.compare,f.prototype.compare=function(m){if(m===1/0)return-1;if(m===-1/0)return 1;var x=le(m),A=this.value,D=x.value;return x.isSmall?A==D?0:A>D?1:-1:A<0!==x.sign?A<0?-1:1:A<0?1:-1},f.prototype.compareTo=f.prototype.compare,c.prototype.compare=function(m){if(m===1/0)return-1;if(m===-1/0)return 1;var x=this.value,A=le(m).value;return x===A?0:x>A?1:-1},c.prototype.compareTo=c.prototype.compare,u.prototype.equals=function(m){return this.compare(m)===0},c.prototype.eq=c.prototype.equals=f.prototype.eq=f.prototype.equals=u.prototype.eq=u.prototype.equals,u.prototype.notEquals=function(m){return this.compare(m)!==0},c.prototype.neq=c.prototype.notEquals=f.prototype.neq=f.prototype.notEquals=u.prototype.neq=u.prototype.notEquals,u.prototype.greater=function(m){return this.compare(m)>0},c.prototype.gt=c.prototype.greater=f.prototype.gt=f.prototype.greater=u.prototype.gt=u.prototype.greater,u.prototype.lesser=function(m){return this.compare(m)<0},c.prototype.lt=c.prototype.lesser=f.prototype.lt=f.prototype.lesser=u.prototype.lt=u.prototype.lesser,u.prototype.greaterOrEquals=function(m){return this.compare(m)>=0},c.prototype.geq=c.prototype.greaterOrEquals=f.prototype.geq=f.prototype.greaterOrEquals=u.prototype.geq=u.prototype.greaterOrEquals,u.prototype.lesserOrEquals=function(m){return this.compare(m)<=0},c.prototype.leq=c.prototype.lesserOrEquals=f.prototype.leq=f.prototype.lesserOrEquals=u.prototype.leq=u.prototype.lesserOrEquals,u.prototype.isEven=function(){return(this.value[0]&1)===0},f.prototype.isEven=function(){return(this.value&1)===0},c.prototype.isEven=function(){return(this.value&BigInt(1))===BigInt(0)},u.prototype.isOdd=function(){return(this.value[0]&1)===1},f.prototype.isOdd=function(){return(this.value&1)===1},c.prototype.isOdd=function(){return(this.value&BigInt(1))===BigInt(1)},u.prototype.isPositive=function(){return!this.sign},f.prototype.isPositive=function(){return this.value>0},c.prototype.isPositive=f.prototype.isPositive,u.prototype.isNegative=function(){return this.sign},f.prototype.isNegative=function(){return this.value<0},c.prototype.isNegative=f.prototype.isNegative,u.prototype.isUnit=function(){return!1},f.prototype.isUnit=function(){return Math.abs(this.value)===1},c.prototype.isUnit=function(){return this.abs().value===BigInt(1)},u.prototype.isZero=function(){return!1},f.prototype.isZero=function(){return this.value===0},c.prototype.isZero=function(){return this.value===BigInt(0)},u.prototype.isDivisibleBy=function(m){var x=le(m);return x.isZero()?!1:x.isUnit()?!0:x.compareAbs(2)===0?this.isEven():this.mod(x).isZero()},c.prototype.isDivisibleBy=f.prototype.isDivisibleBy=u.prototype.isDivisibleBy;function z(m){var x=m.abs();if(x.isUnit())return!1;if(x.equals(2)||x.equals(3)||x.equals(5))return!0;if(x.isEven()||x.isDivisibleBy(3)||x.isDivisibleBy(5))return!1;if(x.lesser(49))return!0}function re(m,x){for(var A=m.prev(),D=A,X=0,j,V,Q,ne;D.isEven();)D=D.divide(2),X++;e:for(Q=0;Q<x.length;Q++)if(!m.lesser(x[Q])&&(ne=Pt(x[Q]).modPow(D,m),!(ne.isUnit()||ne.equals(A)))){for(j=X-1;j!=0;j--){if(ne=ne.square().mod(m),ne.isUnit())return!1;if(ne.equals(A))continue e}return!1}return!0}u.prototype.isPrime=function(m){var x=z(this);if(x!==t)return x;var A=this.abs(),D=A.bitLength();if(D<=64)return re(A,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var X=Math.log(2)*D.toJSNumber(),j=Math.ceil(m===!0?2*Math.pow(X,2):X),V=[],Q=0;Q<j;Q++)V.push(Pt(Q+2));return re(A,V)},c.prototype.isPrime=f.prototype.isPrime=u.prototype.isPrime,u.prototype.isProbablePrime=function(m,x){var A=z(this);if(A!==t)return A;for(var D=this.abs(),X=m===t?5:m,j=[],V=0;V<X;V++)j.push(Pt.randBetween(2,D.minus(2),x));return re(D,j)},c.prototype.isProbablePrime=f.prototype.isProbablePrime=u.prototype.isProbablePrime,u.prototype.modInv=function(m){for(var x=Pt.zero,A=Pt.one,D=le(m),X=this.abs(),j,V,Q;!X.isZero();)j=D.divide(X),V=x,Q=D,x=A,D=X,A=V.subtract(j.multiply(A)),X=Q.subtract(j.multiply(X));if(!D.isUnit())throw new Error(this.toString()+" and "+m.toString()+" are not co-prime");return x.compare(0)===-1&&(x=x.add(m)),this.isNegative()?x.negate():x},c.prototype.modInv=f.prototype.modInv=u.prototype.modInv,u.prototype.next=function(){var m=this.value;return this.sign?ee(m,1,this.sign):new u(N(m,1),this.sign)},f.prototype.next=function(){var m=this.value;return m+1<i?new f(m+1):new u(n,!1)},c.prototype.next=function(){return new c(this.value+BigInt(1))},u.prototype.prev=function(){var m=this.value;return this.sign?new u(N(m,1),!0):ee(m,1,this.sign)},f.prototype.prev=function(){var m=this.value;return m-1>-i?new f(m-1):new u(n,!0)},c.prototype.prev=function(){return new c(this.value-BigInt(1))};for(var se=[1];2*se[se.length-1]<=e;)se.push(2*se[se.length-1]);var ue=se.length,pe=se[ue-1];function Ye(m){return Math.abs(m)<=e}u.prototype.shiftLeft=function(m){var x=le(m).toJSNumber();if(!Ye(x))throw new Error(String(x)+" is too large for shifting.");if(x<0)return this.shiftRight(-x);var A=this;if(A.isZero())return A;for(;x>=ue;)A=A.multiply(pe),x-=ue-1;return A.multiply(se[x])},c.prototype.shiftLeft=f.prototype.shiftLeft=u.prototype.shiftLeft,u.prototype.shiftRight=function(m){var x,A=le(m).toJSNumber();if(!Ye(A))throw new Error(String(A)+" is too large for shifting.");if(A<0)return this.shiftLeft(-A);for(var D=this;A>=ue;){if(D.isZero()||D.isNegative()&&D.isUnit())return D;x=M(D,pe),D=x[1].isNegative()?x[0].prev():x[0],A-=ue-1}return x=M(D,se[A]),x[1].isNegative()?x[0].prev():x[0]},c.prototype.shiftRight=f.prototype.shiftRight=u.prototype.shiftRight;function Se(m,x,A){x=le(x);for(var D=m.isNegative(),X=x.isNegative(),j=D?m.not():m,V=X?x.not():x,Q=0,ne=0,he=null,we=null,ve=[];!j.isZero()||!V.isZero();)he=M(j,pe),Q=he[1].toJSNumber(),D&&(Q=pe-1-Q),we=M(V,pe),ne=we[1].toJSNumber(),X&&(ne=pe-1-ne),j=he[0],V=we[0],ve.push(A(Q,ne));for(var Ce=A(D?1:0,X?1:0)!==0?Pt(-1):Pt(0),gt=ve.length-1;gt>=0;gt-=1)Ce=Ce.multiply(pe).add(Pt(ve[gt]));return Ce}u.prototype.not=function(){return this.negate().prev()},c.prototype.not=f.prototype.not=u.prototype.not,u.prototype.and=function(m){return Se(this,m,function(x,A){return x&A})},c.prototype.and=f.prototype.and=u.prototype.and,u.prototype.or=function(m){return Se(this,m,function(x,A){return x|A})},c.prototype.or=f.prototype.or=u.prototype.or,u.prototype.xor=function(m){return Se(this,m,function(x,A){return x^A})},c.prototype.xor=f.prototype.xor=u.prototype.xor;var Be=1<<30,je=(e&-e)*(e&-e)|Be;function Ae(m){var x=m.value,A=typeof x=="number"?x|Be:typeof x=="bigint"?x|BigInt(Be):x[0]+x[1]*e|je;return A&-A}function Ke(m,x){if(x.compareTo(m)<=0){var A=Ke(m,x.square(x)),D=A.p,X=A.e,j=D.multiply(x);return j.compareTo(m)<=0?{p:j,e:X*2+1}:{p:D,e:X*2}}return{p:Pt(1),e:0}}u.prototype.bitLength=function(){var m=this;return m.compareTo(Pt(0))<0&&(m=m.negate().subtract(Pt(1))),m.compareTo(Pt(0))===0?Pt(0):Pt(Ke(m,Pt(2)).e).add(Pt(1))},c.prototype.bitLength=f.prototype.bitLength=u.prototype.bitLength;function pt(m,x){return m=le(m),x=le(x),m.greater(x)?m:x}function Nt(m,x){return m=le(m),x=le(x),m.lesser(x)?m:x}function Br(m,x){if(m=le(m).abs(),x=le(x).abs(),m.equals(x))return m;if(m.isZero())return x;if(x.isZero())return m;for(var A=o[1],D,X;m.isEven()&&x.isEven();)D=Nt(Ae(m),Ae(x)),m=m.divide(D),x=x.divide(D),A=A.multiply(D);for(;m.isEven();)m=m.divide(Ae(m));do{for(;x.isEven();)x=x.divide(Ae(x));m.greater(x)&&(X=x,x=m,m=X),x=x.subtract(m)}while(!x.isZero());return A.isUnit()?m:m.multiply(A)}function ti(m,x){return m=le(m).abs(),x=le(x).abs(),m.divide(Br(m,x)).multiply(x)}function Ui(m,x,A){m=le(m),x=le(x);var D=A||Math.random,X=Nt(m,x),j=pt(m,x),V=j.subtract(X).add(1);if(V.isSmall)return X.add(Math.floor(D()*V));for(var Q=Cr(V,e).value,ne=[],he=!0,we=0;we<Q.length;we++){var ve=he?Q[we]+(we+1<Q.length?Q[we+1]/e:0):e,Ce=v(D()*ve);ne.push(Ce),Ce<Q[we]&&(he=!1)}return X.add(o.fromArray(ne,e,!1))}var ri=function(m,x,A,D){A=A||s,m=String(m),D||(m=m.toLowerCase(),A=A.toLowerCase());var X=m.length,j,V=Math.abs(x),Q={};for(j=0;j<A.length;j++)Q[A[j]]=j;for(j=0;j<X;j++){var ne=m[j];if(ne!=="-"&&ne in Q&&Q[ne]>=V){if(ne==="1"&&V===1)continue;throw new Error(ne+" is not a valid digit in base "+x+".")}}x=le(x);var he=[],we=m[0]==="-";for(j=we?1:0;j<m.length;j++){var ne=m[j];if(ne in Q)he.push(le(Q[ne]));else if(ne==="<"){var ve=j;do j++;while(m[j]!==">"&&j<m.length);he.push(le(m.slice(ve+1,j)))}else throw new Error(ne+" is not a valid character")}return jr(he,x,we)};function jr(m,x,A){var D=o[0],X=o[1],j;for(j=m.length-1;j>=0;j--)D=D.add(m[j].times(X)),X=X.times(x);return A?D.negate():D}function Wi(m,x){return x=x||s,m<x.length?x[m]:"<"+m+">"}function Cr(m,x){if(x=Pt(x),x.isZero()){if(m.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(x.equals(-1)){if(m.isZero())return{value:[0],isNegative:!1};if(m.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-m.toJSNumber())).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var A=Array.apply(null,Array(m.toJSNumber()-1)).map(Array.prototype.valueOf,[0,1]);return A.unshift([1]),{value:[].concat.apply([],A),isNegative:!1}}var D=!1;if(m.isNegative()&&x.isPositive()&&(D=!0,m=m.abs()),x.isUnit())return m.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(m.toJSNumber())).map(Number.prototype.valueOf,1),isNegative:D};for(var X=[],j=m,V;j.isNegative()||j.compareAbs(x)>=0;){V=j.divmod(x),j=V.quotient;var Q=V.remainder;Q.isNegative()&&(Q=x.minus(Q).abs(),j=j.next()),X.push(Q.toJSNumber())}return X.push(j.toJSNumber()),{value:X.reverse(),isNegative:D}}function Ka(m,x,A){var D=Cr(m,x);return(D.isNegative?"-":"")+D.value.map(function(X){return Wi(X,A)}).join("")}u.prototype.toArray=function(m){return Cr(this,m)},f.prototype.toArray=function(m){return Cr(this,m)},c.prototype.toArray=function(m){return Cr(this,m)},u.prototype.toString=function(m,x){if(m===t&&(m=10),m!==10||x)return Ka(this,m,x);for(var A=this.value,D=A.length,X=String(A[--D]),j="0000000",V;--D>=0;)V=String(A[D]),X+=j.slice(V.length)+V;var Q=this.sign?"-":"";return Q+X},f.prototype.toString=function(m,x){return m===t&&(m=10),m!=10||x?Ka(this,m,x):String(this.value)},c.prototype.toString=f.prototype.toString,c.prototype.toJSON=u.prototype.toJSON=f.prototype.toJSON=function(){return this.toString()},u.prototype.valueOf=function(){return parseInt(this.toString(),10)},u.prototype.toJSNumber=u.prototype.valueOf,f.prototype.valueOf=function(){return this.value},f.prototype.toJSNumber=f.prototype.valueOf,c.prototype.valueOf=c.prototype.toJSNumber=function(){return parseInt(this.toString(),10)};function kr(m){if(h(+m)){var x=+m;if(x===v(x))return a?new c(BigInt(x)):new f(x);throw new Error("Invalid integer: "+m)}var A=m[0]==="-";A&&(m=m.slice(1));var D=m.split(/e/i);if(D.length>2)throw new Error("Invalid integer: "+D.join("e"));if(D.length===2){var X=D[1];if(X[0]==="+"&&(X=X.slice(1)),X=+X,X!==v(X)||!h(X))throw new Error("Invalid integer: "+X+" is not a valid exponent.");var j=D[0],V=j.indexOf(".");if(V>=0&&(X-=j.length-V-1,j=j.slice(0,V)+j.slice(V+1)),X<0)throw new Error("Cannot include negative exponent part for integers");j+=new Array(X+1).join("0"),m=j}var Q=/^([0-9][0-9]*)$/.test(m);if(!Q)throw new Error("Invalid integer: "+m);if(a)return new c(BigInt(A?"-"+m:m));for(var ne=[],he=m.length,we=r,ve=he-we;he>0;)ne.push(+m.slice(ve,he)),ve-=we,ve<0&&(ve=0),he-=we;return g(ne),new u(ne,A)}function On(m){if(a)return new c(BigInt(m));if(h(m)){if(m!==v(m))throw new Error(m+" is not an integer.");return new f(m)}return kr(m.toString())}function le(m){return typeof m=="number"?On(m):typeof m=="string"?kr(m):typeof m=="bigint"?new c(m):m}for(var W=0;W<1e3;W++)o[W]=le(W),W>0&&(o[-W]=le(-W));return o.one=o[1],o.zero=o[0],o.minusOne=o[-1],o.max=pt,o.min=Nt,o.gcd=Br,o.lcm=ti,o.isInstance=function(m){return m instanceof u||m instanceof f||m instanceof c},o.randBetween=Ui,o.fromArray=function(m,x,A){return jr(m.map(le),le(x||10),A)},o})();typeof xy<"u"&&xy.hasOwnProperty("exports")&&(xy.exports=Pt);typeof define=="function"&&define.amd&&define(function(){return Pt})});var KX=w((OPe,YX)=>{var Os=GX(),Sy=Y("stream");(!Sy.Writable||!Sy.Writable.prototype.destroy)&&(Sy=Tn());var Ey;function bTe(){var t=3988292384,e,r,i;for(Ey=[],r=0;r<256;r++){for(e=r,i=0;i<8;i++)e=e&1?t^e>>>1:e=e>>>1;Ey[r]=e>>>0}}function ZX(t,e){return Ey||bTe(),t.charCodeAt&&(t=t.charCodeAt(0)),Os(e).shiftRight(8).and(16777215).xor(Ey[Os(e).xor(t).and(255)]).value}function nu(){if(!(this instanceof nu))return new nu;this.key0=305419896,this.key1=591751049,this.key2=878082192}nu.prototype.update=function(t){this.key0=ZX(t,this.key0),this.key1=Os(this.key0).and(255).and(4294967295).add(this.key1),this.key1=Os(this.key1).multiply(134775813).add(1).and(4294967295).value,this.key2=ZX(Os(this.key1).shiftRight(24).and(255),this.key2)};nu.prototype.decryptByte=function(t){var e=Os(this.key2).or(2);return t=t^Os(e).multiply(Os(e^1)).shiftRight(8).and(255),this.update(t),t};nu.prototype.stream=function(){var t=Sy.Transform(),e=this;return t._transform=function(r,i,n){for(var s=0;s<r.length;s++)r[s]=e.decryptByte(r[s]);this.push(r),n()},t};YX.exports=nu});var JX=w((IPe,QX)=>{var xTe=Ts(),STe=KX(),ETe=Qm(),Kc=Y("stream"),TTe=bc(),CTe=Y("zlib"),kTe=ty(),RTe=Hl(),ATe=ry();(!Kc.Writable||!Kc.Writable.prototype.destroy)&&(Kc=Tn());QX.exports=function(e,r,i,n){var s=ETe(),a=Kc.PassThrough(),o=e.stream(r);return o.pipe(s).on("error",function(u){a.emit("error",u)}),a.vars=s.pull(30).then(function(u){var f=TTe.parse(u).word32lu("signature").word16lu("versionsNeededToExtract").word16lu("flags").word16lu("compressionMethod").word16lu("lastModifiedTime").word16lu("lastModifiedDate").word32lu("crc32").word32lu("compressedSize").word32lu("uncompressedSize").word16lu("fileNameLength").word16lu("extraFieldLength").vars;return f.lastModifiedDateTime=ATe(f.lastModifiedDate,f.lastModifiedTime),s.pull(f.fileNameLength).then(function(c){return f.fileName=c.toString("utf8"),s.pull(f.extraFieldLength)}).then(function(c){var h;return f.extra=kTe(c,f),n&&n.compressedSize&&(f=n),f.flags&1&&(h=s.pull(12).then(function(d){if(!i)throw new Error("MISSING_PASSWORD");var p=STe();String(i).split("").forEach(function(v){p.update(v)});for(var g=0;g<d.length;g++)d[g]=p.decryptByte(d[g]);f.decrypt=p,f.compressedSize-=12;var y=f.flags&8?f.lastModifiedTime>>8&255:f.crc32>>24&255;if(d[11]!==y)throw new Error("BAD_PASSWORD");return f})),xTe.resolve(h).then(function(){return a.emit("vars",f),f})})}),a.vars.then(function(u){var f=!(u.flags&8)||u.compressedSize>0,c,h=u.compressionMethod?CTe.createInflateRaw():Kc.PassThrough();f?(a.size=u.uncompressedSize,c=u.compressedSize):(c=RTe.alloc(4),c.writeUInt32LE(134695760,0));var d=s.stream(c);u.decrypt&&(d=d.pipe(u.decrypt.stream())),d.pipe(h).on("error",function(p){a.emit("error",p)}).pipe(a).on("finish",function(){o.destroy?o.destroy():o.abort?o.abort():o.close?o.close():o.push?o.push():console.log("warning - unable to close stream")})}).catch(function(u){a.emit("error",u)}),a}});var rV=w((NPe,tV)=>{var eh=bc(),Jc=Qm(),OTe=JX(),Qc=Ts(),ITe=ey(),NTe=ty(),DTe=Hl(),Ik=Y("path"),FTe=Ak().Writer,MTe=ry(),eV=DTe.alloc(4);eV.writeUInt32LE(101010256,0);function PTe(t){var e=t.stream(0).pipe(Jc());return e.pull(4).then(function(r){var i=r.readUInt32LE(0);if(i===875721283){var n;return e.pull(12).then(function(s){n=eh.parse(s).word32lu("version").word32lu("pubKeyLength").word32lu("signatureLength").vars}).then(function(){return e.pull(n.pubKeyLength+n.signatureLength)}).then(function(s){return n.publicKey=s.slice(0,n.pubKeyLength),n.signature=s.slice(n.pubKeyLength),n.size=16+n.pubKeyLength+n.signatureLength,n})}})}function qTe(t,e){var r=eh.parse(e).word32lu("signature").word32lu("diskNumber").word64lu("offsetToStartOfCentralDirectory").word32lu("numberOfDisks").vars;if(r.signature!=117853008)throw new Error("invalid zip64 end of central dir locator signature (0x07064b50): 0x"+r.signature.toString(16));var i=Jc();return t.stream(r.offsetToStartOfCentralDirectory).pipe(i),i.pull(56)}function LTe(t){var e=eh.parse(t).word32lu("signature").word64lu("sizeOfCentralDirectory").word16lu("version").word16lu("versionsNeededToExtract").word32lu("diskNumber").word32lu("diskStart").word64lu("numberOfRecordsOnDisk").word64lu("numberOfRecords").word64lu("sizeOfCentralDirectory").word64lu("offsetToStartOfCentralDirectory").vars;if(e.signature!=101075792)throw new Error("invalid zip64 end of central dir locator signature (0x06064b50): 0x0"+e.signature.toString(16));return e}tV.exports=function(e,r){var i=Jc(),n=Jc(),s=r&&r.tailSize||80,a,o,u,f;return r&&r.crx&&(o=PTe(e)),e.size().then(function(c){return a=c,e.stream(Math.max(0,c-s)).on("error",function(h){i.emit("error",h)}).pipe(i),i.pull(eV)}).then(function(){return Qc.props({directory:i.pull(22),crxHeader:o})}).then(function(c){var h=c.directory;if(u=c.crxHeader&&c.crxHeader.size||0,f=eh.parse(h).word32lu("signature").word16lu("diskNumber").word16lu("diskStart").word16lu("numberOfRecordsOnDisk").word16lu("numberOfRecords").word32lu("sizeOfCentralDirectory").word32lu("offsetToStartOfCentralDirectory").word16lu("commentLength").vars,f.numberOfRecords==65535||f.numberOfRecords==65535||f.offsetToStartOfCentralDirectory==4294967295){let p=a-(s-i.match+20),g=Jc();return e.stream(p).pipe(g),g.pull(20).then(function(y){return qTe(e,y)}).then(function(y){f=LTe(y)})}else f.offsetToStartOfCentralDirectory+=u}).then(function(){if(f.commentLength)return i.pull(f.commentLength).then(function(c){f.comment=c.toString("utf8")})}).then(function(){return e.stream(f.offsetToStartOfCentralDirectory).pipe(n),f.extract=function(c){if(!c||!c.path)throw new Error("PATH_MISSING");return c.path=Ik.resolve(Ik.normalize(c.path)),f.files.then(function(h){return Qc.map(h,function(d){if(d.type!="Directory"){var p=Ik.join(c.path,d.path);if(p.indexOf(c.path)==0){var g=c.getWriter?c.getWriter({path:p}):FTe({path:p});return new Qc(function(y,v){d.stream(c.password).on("error",v).pipe(g).on("close",y).on("error",v)})}}},{concurrency:c.concurrency>1?c.concurrency:1})})},f.files=Qc.mapSeries(Array(f.numberOfRecords),function(){return n.pull(46).then(function(c){var h=eh.parse(c).word32lu("signature").word16lu("versionMadeBy").word16lu("versionsNeededToExtract").word16lu("flags").word16lu("compressionMethod").word16lu("lastModifiedTime").word16lu("lastModifiedDate").word32lu("crc32").word32lu("compressedSize").word32lu("uncompressedSize").word16lu("fileNameLength").word16lu("extraFieldLength").word16lu("fileCommentLength").word16lu("diskNumber").word16lu("internalFileAttributes").word32lu("externalFileAttributes").word32lu("offsetToLocalFileHeader").vars;return h.offsetToLocalFileHeader+=u,h.lastModifiedDateTime=MTe(h.lastModifiedDate,h.lastModifiedTime),n.pull(h.fileNameLength).then(function(d){return h.pathBuffer=d,h.path=d.toString("utf8"),h.isUnicode=(h.flags&2048)!=0,n.pull(h.extraFieldLength)}).then(function(d){return h.extra=NTe(d,h),n.pull(h.fileCommentLength)}).then(function(d){return h.comment=d,h.type=h.uncompressedSize===0&&/[\/\\]$/.test(h.path)?"Directory":"File",h.stream=function(p){return OTe(e,h.offsetToLocalFileHeader,p,h)},h.buffer=function(p){return ITe(h.stream(p))},h})})}),Qc.props(f)})}});var sV=w((DPe,nV)=>{var iV=Er(),Ty=Ts(),th=rV(),Cy=Y("stream");(!Cy.Writable||!Cy.Writable.prototype.destroy)&&(Cy=Tn());nV.exports={buffer:function(t,e){var r={stream:function(i,n){var s=Cy.PassThrough();return s.end(t.slice(i,n)),s},size:function(){return Ty.resolve(t.length)}};return th(r,e)},file:function(t,e){var r={stream:function(i,n){return iV.createReadStream(t,{start:i,end:n&&i+n})},size:function(){return new Ty(function(i,n){iV.stat(t,function(s,a){s?n(s):i(a.size)})})}};return th(r,e)},url:function(t,e,r){if(typeof e=="string"&&(e={url:e}),!e.url)throw"URL missing";e.headers=e.headers||{};var i={stream:function(n,s){var a=Object.create(e);return a.headers=Object.create(e.headers),a.headers.range="bytes="+n+"-"+(s||""),t(a)},size:function(){return new Ty(function(n,s){var a=t(e);a.on("response",function(o){a.abort(),o.headers["content-length"]?n(o.headers["content-length"]):s(new Error("Missing content length header"))}).on("error",s)})}};return th(i,r)},s3:function(t,e,r){var i={size:function(){return new Ty(function(n,s){t.headObject(e,function(a,o){a?s(a):n(o.ContentLength)})})},stream:function(n,s){var a={};for(var o in e)a[o]=e[o];return a.Range="bytes="+n+"-"+(s||""),t.getObject(a).createReadStream()}};return th(i,r)},custom:function(t,e){return th(t,e)}}});var aV=w(rh=>{"use strict";mW();wW();s_();rh.Parse=iy();rh.ParseOne=Y5();rh.Extract=VX();rh.Open=sV()});var EV=w((MPe,An)=>{var Qe=Y("fs"),Ry=Y("os"),qt=Y("path"),oV=Y("crypto"),ji={fs:Qe.constants,os:Ry.constants},lV="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",hV=/XXXXXX/,BTe=3,dV=(ji.O_CREAT||ji.fs.O_CREAT)|(ji.O_EXCL||ji.fs.O_EXCL)|(ji.O_RDWR||ji.fs.O_RDWR),jTe=Ry.platform()==="win32",$Te=ji.EBADF||ji.os.errno.EBADF,UTe=ji.ENOENT||ji.os.errno.ENOENT,pV=448,gV=384,WTe="exit",su=[],mV=Qe.rmdirSync.bind(Qe),yV=!1;function HTe(t,e){return Qe.rm(t,{recursive:!0},e)}function vV(t){return Qe.rmSync(t,{recursive:!0})}function Mk(t,e){let r=au(t,e),i=r[0],n=r[1];e1e(i,function(s,a){if(s)return n(s);let o=a.tries;(function u(){try{let f=wV(a);Qe.stat(f,function(c){if(!c)return o-- >0?u():n(new Error("Could not get a unique tmp filename, max tries reached "+f));n(null,f)})}catch(f){n(f)}})()})}function Pk(t){let e=au(t),r=e[0],i=t1e(r),n=i.tries;do{let s=wV(i);try{Qe.statSync(s)}catch{return s}}while(n-- >0);throw new Error("Could not get a unique tmp filename, max tries reached")}function zTe(t,e){let r=au(t,e),i=r[0],n=r[1];Mk(i,function(a,o){if(a)return n(a);Qe.open(o,dV,i.mode||gV,function(f,c){if(f)return n(f);if(i.discardDescriptor)return Qe.close(c,function(d){return n(d,o,void 0,Dk(o,-1,i,!1))});{let h=i.discardDescriptor||i.detachDescriptor;n(null,o,c,Dk(o,h?-1:c,i,!1))}})})}function XTe(t){let e=au(t),r=e[0],i=r.discardDescriptor||r.detachDescriptor,n=Pk(r),s=Qe.openSync(n,dV,r.mode||gV);return r.discardDescriptor&&(Qe.closeSync(s),s=void 0),{name:n,fd:s,removeCallback:Dk(n,i?-1:s,r,!0)}}function VTe(t,e){let r=au(t,e),i=r[0],n=r[1];Mk(i,function(a,o){if(a)return n(a);Qe.mkdir(o,i.mode||pV,function(f){if(f)return n(f);n(null,o,_V(o,i,!1))})})}function GTe(t){let e=au(t),r=e[0],i=Pk(r);return Qe.mkdirSync(i,r.mode||pV),{name:i,removeCallback:_V(i,r,!0)}}function ZTe(t,e){let r=function(i){if(i&&!Fk(i))return e(i);e()};0<=t[0]?Qe.close(t[0],function(){Qe.unlink(t[1],r)}):Qe.unlink(t[1],r)}function YTe(t){let e=null;try{0<=t[0]&&Qe.closeSync(t[0])}catch(r){if(!r1e(r)&&!Fk(r))throw r}finally{try{Qe.unlinkSync(t[1])}catch(r){Fk(r)||(e=r)}}if(e!==null)throw e}function Dk(t,e,r,i){let n=ky(YTe,[e,t],i),s=ky(ZTe,[e,t],i,n);return r.keep||su.unshift(n),i?n:s}function _V(t,e,r){let i=e.unsafeCleanup?HTe:Qe.rmdir.bind(Qe),n=e.unsafeCleanup?vV:mV,s=ky(n,t,r),a=ky(i,t,r,s);return e.keep||su.unshift(s),r?s:a}function ky(t,e,r,i){let n=!1;return function s(a){if(!n){let o=i||s,u=su.indexOf(o);return u>=0&&su.splice(u,1),n=!0,r||t===mV||t===vV?t(e):t(e,a||function(){})}}}function KTe(){if(yV)for(;su.length;)try{su[0]()}catch{}}function uV(t){let e=[],r=null;try{r=oV.randomBytes(t)}catch{r=oV.pseudoRandomBytes(t)}for(let i=0;i<t;i++)e.push(lV[r[i]%lV.length]);return e.join("")}function Tr(t){return typeof t>"u"}function au(t,e){if(typeof t=="function")return[{},t];if(Tr(t))return[{},e];let r={};for(let i of Object.getOwnPropertyNames(t))r[i]=t[i];return[r,e]}function QTe(t,e,r){let i=qt.isAbsolute(t)?t:qt.join(e,t);Qe.stat(i,function(n){n?Qe.realpath(qt.dirname(i),function(s,a){if(s)return r(s);r(null,qt.join(a,qt.basename(i)))}):Qe.realpath(i,r)})}function JTe(t,e){let r=qt.isAbsolute(t)?t:qt.join(e,t);try{return Qe.statSync(r),Qe.realpathSync(r)}catch{let n=Qe.realpathSync(qt.dirname(r));return qt.join(n,qt.basename(r))}}function wV(t){let e=t.tmpdir;if(!Tr(t.name))return qt.join(e,t.dir,t.name);if(!Tr(t.template))return qt.join(e,t.dir,t.template).replace(hV,uV(6));let r=[t.prefix?t.prefix:"tmp","-",process.pid,"-",uV(12),t.postfix?"-"+t.postfix:""].join("");return qt.join(e,t.dir,r)}function Nk(t,e){if(typeof e!="string")throw new Error(`${t} option must be a string, got "${typeof e}".`);if(e.includes(".."))throw new Error("Relative value not allowed");return e}function bV(t){if(!Tr(t.name)){let e=t.name;if(qt.isAbsolute(e))throw new Error(`name option must not contain an absolute path, found "${e}".`);let r=qt.basename(e);if(r===".."||r==="."||r!==e)throw new Error(`name option must not contain a path, found "${e}".`)}if(!Tr(t.template)){if(typeof t.template!="string")throw new Error(`template option must be a string, got "${typeof t.template}".`);if(!t.template.match(hV))throw new Error(`Invalid template, found "${t.template}".`)}if(!Tr(t.tries)&&isNaN(t.tries)||t.tries<0)throw new Error(`Invalid tries, found "${t.tries}".`);t.tries=Tr(t.name)?t.tries||BTe:1,t.keep=!!t.keep,t.detachDescriptor=!!t.detachDescriptor,t.discardDescriptor=!!t.discardDescriptor,t.unsafeCleanup=!!t.unsafeCleanup,t.prefix=Tr(t.prefix)?"":Nk("prefix",t.prefix),t.postfix=Tr(t.postfix)?"":Nk("postfix",t.postfix),t.template=Tr(t.template)?void 0:Nk("template",t.template)}function fV(t,e,r,i){if(Tr(e))return i(null);QTe(e,r,function(n,s){if(n)return i(n);let a=qt.relative(r,s);if(a.startsWith("..")||qt.isAbsolute(a))return i(new Error(`${t} option must be relative to "${r}", found "${a}".`));i(null,a)})}function cV(t,e,r){if(Tr(e))return;let i=JTe(e,r),n=qt.relative(r,i);if(n.startsWith("..")||qt.isAbsolute(n))throw new Error(`${t} option must be relative to "${r}", found "${n}".`);return n}function e1e(t,e){n1e(t,function(r,i){if(r)return e(r);t.tmpdir=i;try{bV(t,i)}catch(n){return e(n)}fV("dir",t.dir,i,function(n,s){if(n)return e(n);t.dir=Tr(s)?"":s,fV("template",t.template,i,function(a,o){if(a)return e(a);t.template=o,e(null,t)})})})}function t1e(t){let e=t.tmpdir=SV(t);bV(t,e);let r=cV("dir",t.dir,e);return t.dir=Tr(r)?"":r,t.template=cV("template",t.template,e),t}function r1e(t){return xV(t,-$Te,"EBADF")}function Fk(t){return xV(t,-UTe,"ENOENT")}function xV(t,e,r){return jTe?t.code===r:t.code===r&&t.errno===e}function i1e(){yV=!0}function n1e(t,e){return Qe.realpath(t&&t.tmpdir||Ry.tmpdir(),e)}function SV(t){return Qe.realpathSync(t&&t.tmpdir||Ry.tmpdir())}process.addListener(WTe,KTe);Object.defineProperty(An.exports,"tmpdir",{enumerable:!0,configurable:!1,get:function(){return SV()}});An.exports.dir=VTe;An.exports.dirSync=GTe;An.exports.file=zTe;An.exports.fileSync=XTe;An.exports.tmpName=Mk;An.exports.tmpNameSync=Pk;An.exports.setGracefulCleanup=i1e});var CV=w((PPe,TV)=>{TV.exports=async function*(e){let r=[];e.on("data",o=>r.push(o));let i,n=new Promise(o=>i=o),s=!1;e.on("end",()=>{s=!0,i()});let a=!1;for(e.on("error",o=>{a=o,i()});!s||r.length>0;)if(r.length===0?(e.resume(),await Promise.race([s1e(e,"data"),n])):(e.pause(),yield r.shift()),a)throw a;i()};function s1e(t,e){return new Promise(r=>{let i=!1,n=()=>{i||(i=!0,t.removeListener(e,n),r())};t.addListener(e,n)})}});var OV=w((qPe,AV)=>{var{EventEmitter:a1e}=Y("events"),o1e=bf(),l1e=wt(),Ay=sr(),kV=mt(),u1e=Vi(),f1e=Lh(),RV=Bh(),qk=class extends a1e{constructor({workbook:e,id:r,iterator:i,options:n}){super(),this.workbook=e,this.id=r,this.iterator=i,this.options=n||{},this.name=`Sheet${this.id}`,this._columns=null,this._keys={},this._dimensions=new u1e}destroy(){throw new Error("Invalid Operation: destroy")}get dimensions(){return this._dimensions}get columns(){return this._columns}getColumn(e){if(typeof e=="string"){let r=this._keys[e];if(r)return r;e=kV.l2n(e)}if(this._columns||(this._columns=[]),e>this._columns.length){let r=this._columns.length+1;for(;r<=e;)this._columns.push(new RV(this,r++))}return this._columns[e-1]}getColumnKey(e){return this._keys[e]}setColumnKey(e,r){this._keys[e]=r}deleteColumnKey(e){delete this._keys[e]}eachColumnKey(e){l1e.each(this._keys,e)}async read(){try{for await(let e of this.parse())for(let{eventType:r,value:i}of e)this.emit(r,i);this.emit("finished")}catch(e){this.emit("error",e)}}async*[Symbol.asyncIterator](){for await(let e of this.parse())for(let{eventType:r,value:i}of e)r==="row"&&(yield i)}async*parse(){let{iterator:e,options:r}=this,i=!1,n=!1,s=null;switch(r.worksheets){case"emit":i=!0;break;case"prep":break;default:break}switch(r.hyperlinks){case"emit":n=!0;break;case"cache":this.hyperlinks=s={};break;default:break}if(!i&&!n&&!s)return;let{sharedStrings:a,styles:o,properties:u}=this.workbook,f=!1,c=!1,h=!1,d=null,p=null,g=null,y=null;for await(let v of o1e(e)){let b=[];for(let{eventType:k,value:N}of v)if(k==="opentag"){let E=N;if(i)switch(E.name){case"cols":f=!0,d=[];break;case"sheetData":c=!0;break;case"col":f&&d.push({min:parseInt(E.attributes.min,10),max:parseInt(E.attributes.max,10),width:parseFloat(E.attributes.width),styleId:parseInt(E.attributes.style||"0",10)});break;case"row":if(c){let U=parseInt(E.attributes.r,10);if(p=new f1e(this,U),E.attributes.ht&&(p.height=parseFloat(E.attributes.ht)),E.attributes.s){let ee=parseInt(E.attributes.s,10),F=o.getStyleModel(ee);F&&(p.style=F)}}break;case"c":p&&(g={ref:E.attributes.r,s:parseInt(E.attributes.s,10),t:E.attributes.t});break;case"f":g&&(y=g.f={text:""});break;case"v":g&&(y=g.v={text:""});break;case"is":case"t":g&&(y=g.v={text:""});break;case"mergeCell":break;default:break}if(n||s)switch(E.name){case"hyperlinks":h=!0;break;case"hyperlink":if(h){let U={ref:E.attributes.ref,rId:E.attributes["r:id"]};n?b.push({eventType:"hyperlink",value:U}):s[U.ref]=U}break;default:break}}else if(k==="text")i&&y&&(y.text+=N);else if(k==="closetag"){let E=N;if(i)switch(E.name){case"cols":f=!1,this._columns=RV.fromModel(d);break;case"sheetData":c=!1;break;case"row":this._dimensions.expandRow(p),b.push({eventType:"row",value:p}),p=null;break;case"c":if(p&&g){let U=kV.decodeAddress(g.ref),ee=p.getCell(U.col);if(g.s){let F=o.getStyleModel(g.s);F&&(ee.style=F)}if(g.f){let F={formula:g.f.text};g.v&&(g.t==="str"?F.result=Ay.xmlDecode(g.v.text):F.result=parseFloat(g.v.text)),ee.value=F}else if(g.v)switch(g.t){case"s":{let F=parseInt(g.v.text,10);a?ee.value=a[F]:ee.value={sharedString:F};break}case"inlineStr":case"str":ee.value=Ay.xmlDecode(g.v.text);break;case"e":ee.value={error:g.v.text};break;case"b":ee.value=parseInt(g.v.text,10)!==0;break;default:Ay.isDateFmt(ee.numFmt)?ee.value=Ay.excelToDate(parseFloat(g.v.text),u.model&&u.model.date1904):ee.value=parseFloat(g.v.text);break}if(s){let F=s[g.ref];F&&(ee.text=ee.value,ee.value=void 0,ee.hyperlink=F)}g=null}break;default:break}(n||s)&&E.name==="hyperlinks"&&(h=!1)}b.length>0&&(yield b)}}};AV.exports=qk});var NV=w((LPe,IV)=>{var{EventEmitter:c1e}=Y("events"),h1e=bf(),d1e=ni(),p1e=es(),Lk=class extends c1e{constructor({workbook:e,id:r,iterator:i,options:n}){super(),this.workbook=e,this.id=r,this.iterator=i,this.options=n}get count(){return this.hyperlinks&&this.hyperlinks.length||0}each(e){return this.hyperlinks.forEach(e)}async read(){let{iterator:e,options:r}=this,i=!1,n=null;switch(r.hyperlinks){case"emit":i=!0;break;case"cache":this.hyperlinks=n={};break;default:break}if(!i&&!n){this.emit("finished");return}try{for await(let s of h1e(e))for(let{eventType:a,value:o}of s)if(a==="opentag"){let u=o;if(u.name==="Relationship"){let f=u.attributes.Id;switch(u.attributes.Type){case p1e.Hyperlink:{let c={type:d1e.RelationshipType.Styles,rId:f,target:u.attributes.Target,targetMode:u.attributes.TargetMode};i?this.emit("hyperlink",c):n[c.rId]=c}break;default:break}}}this.emit("finished")}catch(s){this.emit("error",s)}}};IV.exports=Lk});var PV=w((BPe,MV)=>{var Bk=Y("fs"),{EventEmitter:g1e}=Y("events"),{PassThrough:m1e,Readable:y1e}=nr(),v1e=Y("stream"),_1e=aV(),FV=EV(),Za=CV(),w1e=bf(),DV=mp(),b1e=xp(),x1e=wp(),S1e=OV(),E1e=NV();FV.setGracefulCleanup();var Oy=class extends g1e{constructor(e,r={}){super(),this.input=e,this.options={worksheets:"emit",sharedStrings:"cache",hyperlinks:"ignore",styles:"ignore",entries:"ignore",...r},this.styles=new DV,this.styles.init()}_getStream(e){if(e instanceof v1e.Readable||e instanceof y1e)return e;if(typeof e=="string")return Bk.createReadStream(e);throw new Error(`Could not recognise input: ${e}`)}async read(e,r){try{for await(let{eventType:i,value:n}of this.parse(e,r))switch(i){case"shared-strings":this.emit(i,n);break;case"worksheet":this.emit(i,n),await n.read();break;case"hyperlinks":this.emit(i,n);break}this.emit("end"),this.emit("finished")}catch(i){this.emit("error",i)}}async*[Symbol.asyncIterator](){for await(let{eventType:e,value:r}of this.parse())e==="worksheet"&&(yield r)}async*parse(e,r){r&&(this.options=r);let i=this.stream=this._getStream(e||this.input),n=_1e.Parse({forceStream:!0});i.pipe(n);let s=[];for await(let a of Za(n)){let o,u;switch(a.path){case"_rels/.rels":break;case"xl/_rels/workbook.xml.rels":await this._parseRels(a);break;case"xl/workbook.xml":await this._parseWorkbook(a);break;case"xl/sharedStrings.xml":yield*this._parseSharedStrings(a);break;case"xl/styles.xml":await this._parseStyles(a);break;default:a.path.match(/xl\/worksheets\/sheet\d+[.]xml/)?(o=a.path.match(/xl\/worksheets\/sheet(\d+)[.]xml/),u=o[1],this.sharedStrings&&this.workbookRels?yield*this._parseWorksheet(Za(a),u):await new Promise((f,c)=>{FV.file((h,d,p,g)=>{if(h)return c(h);s.push({sheetNo:u,path:d,tempFileCleanupCallback:g});let y=Bk.createWriteStream(d);return y.on("error",c),a.pipe(y),y.on("finish",()=>f())})})):a.path.match(/xl\/worksheets\/_rels\/sheet\d+[.]xml.rels/)&&(o=a.path.match(/xl\/worksheets\/_rels\/sheet(\d+)[.]xml.rels/),u=o[1],yield*this._parseHyperlinks(Za(a),u));break}a.autodrain()}for(let{sheetNo:a,path:o,tempFileCleanupCallback:u}of s){let f=Bk.createReadStream(o);f[Symbol.asyncIterator]||(f=f.pipe(new m1e)),yield*this._parseWorksheet(f,a),u()}}_emitEntry(e){this.options.entries==="emit"&&this.emit("entry",e)}async _parseRels(e){let r=new x1e;this.workbookRels=await r.parseStream(Za(e))}async _parseWorkbook(e){this._emitEntry({type:"workbook"});let r=new b1e;await r.parseStream(Za(e)),this.properties=r.map.workbookPr,this.model=r.model}async*_parseSharedStrings(e){switch(this._emitEntry({type:"shared-strings"}),this.options.sharedStrings){case"cache":this.sharedStrings=[];break;case"emit":break;default:return}let r=null,i=[],n=0,s=null;for await(let a of w1e(Za(e)))for(let{eventType:o,value:u}of a)if(o==="opentag"){let f=u;switch(f.name){case"b":s=s||{},s.bold=!0;break;case"charset":s=s||{},s.charset=parseInt(f.attributes.charset,10);break;case"color":s=s||{},s.color={},f.attributes.rgb&&(s.color.argb=f.attributes.argb),f.attributes.val&&(s.color.argb=f.attributes.val),f.attributes.theme&&(s.color.theme=f.attributes.theme);break;case"family":s=s||{},s.family=parseInt(f.attributes.val,10);break;case"i":s=s||{},s.italic=!0;break;case"outline":s=s||{},s.outline=!0;break;case"rFont":s=s||{},s.name=f.value;break;case"si":s=null,i=[],r=null;break;case"sz":s=s||{},s.size=parseInt(f.attributes.val,10);break;case"strike":break;case"t":r=null;break;case"u":s=s||{},s.underline=!0;break;case"vertAlign":s=s||{},s.vertAlign=f.attributes.val;break}}else if(o==="text")r=r?r+u:u;else if(o==="closetag")switch(u.name){case"r":i.push({font:s,text:r}),s=null,r=null;break;case"si":this.options.sharedStrings==="cache"?this.sharedStrings.push(i.length?{richText:i}:r):this.options.sharedStrings==="emit"&&(yield{index:n++,text:i.length?{richText:i}:r}),i=[],s=null,r=null;break}}async _parseStyles(e){this._emitEntry({type:"styles"}),this.options.styles==="cache"&&(this.styles=new DV,await this.styles.parseStream(Za(e)))}*_parseWorksheet(e,r){this._emitEntry({type:"worksheet",id:r});let i=new S1e({workbook:this,id:r,iterator:e,options:this.options}),n=(this.workbookRels||[]).find(a=>a.Target===`worksheets/sheet${r}.xml`),s=n&&(this.model.sheets||[]).find(a=>a.rId===n.Id);s&&(i.id=s.id,i.name=s.name,i.state=s.state),this.options.worksheets==="emit"&&(yield{eventType:"worksheet",value:i})}*_parseHyperlinks(e,r){this._emitEntry({type:"hyperlinks",id:r});let i=new E1e({workbook:this,id:r,iterator:e,options:this.options});this.options.hyperlinks==="emit"&&(yield{eventType:"hyperlinks",value:i})}};Oy.Options={worksheets:["emit","ignore"],sharedStrings:["cache","emit","ignore"],hyperlinks:["cache","emit","ignore"],styles:["cache","ignore"],entries:["emit","ignore"]};MV.exports=Oy});var BV=w((jPe,LV)=>{var qV={Workbook:T6(),ModelContainer:k6(),stream:{xlsx:{WorkbookWriter:pW(),WorkbookReader:PV()}}};Object.assign(qV,ni());LV.exports=qV});var $V=w(($Pe,jV)=>{if(parseInt(process.versions.node.split(".")[0],10)<10)throw new Error("For node versions older than 10, please use the ES5 Import: https://github.com/exceljs/exceljs#es5-imports");jV.exports=BV()});import{StdioServerTransport as dCe}from"@modelcontextprotocol/sdk/server/stdio.js";import{createServer as pCe}from"inistate-mcp";import{homedir as Y7}from"node:os";import{join as K7}from"node:path";function Q7(){return K7(Y7(),".inistate","core.db")}function Ds(t){let e=t.trim();if(e==="memory"||e===":memory:")return"memory";let r=/^([a-z][a-z0-9+.-]*):\/\//i.exec(e);return r?r[1].toLowerCase():"sqlite"}function OR(t=process.env){let e=(t.INISTATE_CORE_DB||"").trim()||Q7(),r,i=(t.INISTATE_CORE_CONNECTIONS||"").trim();if(i){let u;try{u=JSON.parse(i)}catch(f){throw new Error(`INISTATE_CORE_CONNECTIONS is not valid JSON: ${f instanceof Error?f.message:String(f)}`)}if(!u||typeof u!="object"||Array.isArray(u))throw new Error('INISTATE_CORE_CONNECTIONS must be a JSON object mapping module names to connection targets, e.g. {"NEC":"notion://<dbId>"}.');r=u}let n=r?"connections":Ds(e),a=(t.INISTATE_MCP_MODE||"").trim().toLowerCase()==="configure"?"configure":"runtime",o=t.INISTATE_LOG!=="0";return{dbTarget:e,scheme:n,mode:a,logEnabled:o,connections:r}}function yr(t){return(e,r)=>{if(!t)return;let i={ts:new Date().toISOString(),msg:e,...r};console.error(JSON.stringify(i))}}import{resolve as Q1e}from"node:path";import{pathToFileURL as J1e}from"node:url";var Fs=class t extends Error{code;details;constructor(e,r,i){super(r),this.name="EngineError",this.code=e,i&&(this.details=i),Object.setPrototypeOf(this,t.prototype)}};function ii(t){return new Fs("NOT_FOUND",t)}function kh(t,e="One or more fields failed validation"){return new Fs("VALIDATION_FAILED",e,t)}function IR(t){return new Fs("ILLEGAL_TRANSITION",t)}function NR(t){return new Fs("CONFLICT",t)}function DR(t){return t instanceof Fs}function MR(t){if(!t)return;let e=t.indexOf("(");return e===-1?t:t.slice(0,e)}function Wy(t){return t==null?!0:typeof t=="string"?t.trim()==="":Array.isArray(t)?t.length===0:!1}function J7(t){let e=t.trim();return e===""?!1:!Number.isNaN(Number(e))}function e9(t){return typeof t=="string"&&t.includes("@")&&t.includes(".")}function t9(t){if(typeof t!="string")return!1;try{let e=new URL(t);return!!e.protocol&&!!e.host}catch{return!1}}function Nn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function FR(t,e){return typeof t[e]=="string"&&t[e].length>0}function PR(t,e,r){switch(e){case"Integer":return typeof r=="number"&&Number.isInteger(r)||typeof r=="string"&&/^[-+]?\d+$/.test(r.trim())?null:`${t} must be a whole number`;case"Number":case"Currency":return typeof r=="number"&&Number.isFinite(r)||typeof r=="string"&&J7(r)?null:`${t} must be a number`;case"Date":return typeof r=="string"&&!Number.isNaN(Date.parse(r))?null:`${t} must be a valid date (e.g. 2026-03-01)`;case"DateTime":return typeof r=="string"&&!Number.isNaN(Date.parse(r))?null:`${t} must be a valid date-time (ISO 8601)`;case"DateRange":return Nn(r)&&typeof r.from=="string"&&typeof r.to=="string"&&!Number.isNaN(Date.parse(r.from))&&!Number.isNaN(Date.parse(r.to))?null:`${t} must have a valid from and to date`;case"YesNo":return typeof r=="boolean"||typeof r=="string"&&["true","false","yes","no"].includes(r.trim().toLowerCase())?null:`${t} must be true or false`;case"Email":{let i=Array.isArray(r)?r:[r];for(let n of i)if(!e9(n))return`${t} contains an invalid email address: ${String(n)}`;return null}case"Link":return t9(r)?null:`${t} must be a valid URL`;case"Image":case"File":return Nn(r)&&FR(r,"path")?null:`${t} must be a file object with a path (e.g. { name, path })`;case"Images":case"Files":{if(!Array.isArray(r))return`${t} must be an array of file objects (e.g. [{ name, path }])`;for(let i of r)if(!Nn(i)||!FR(i,"path"))return`${t} entries must be file objects with a path (e.g. { name, path })`;return null}case"Module":return Nn(r)&&"id"in r&&"value"in r?null:`${t} must be a reference object { value, id }`;case"Modules":{if(!Array.isArray(r))return`${t} must be an array of reference objects { value, id }`;for(let i of r)if(!Nn(i)||!("id"in i)||!("value"in i))return`${t} entries must be reference objects { value, id }`;return null}case"User":return Nn(r)&&"id"in r&&"value"in r&&"username"in r?null:`${t} must be a user reference { value, id, username }`;case"Users":{if(!Array.isArray(r))return`${t} must be an array of user references { value, id, username }`;for(let i of r)if(!Nn(i)||!("id"in i)||!("value"in i)||!("username"in i))return`${t} entries must be user references { value, id, username }`;return null}default:return null}}function qR(t){let e=new Map;for(let r of t)r?.name&&e.set(r.name,r);return e}function r9(t){return t?.fields?t.fields.map(e=>typeof e=="string"?{name:e}:e):[]}function Rh(t,e,r,i){let n=[],s=qR(t.information),a=t.activities.find(f=>f.name===e),o=r9(a);for(let[f,c]of Object.entries(r)){if(Wy(c))continue;let h=s.get(f);if(!h?.type)continue;let d=MR(h.type);if(d==="Table"){let g=i9(f,h,c);n.push(...g);continue}let p=PR(f,d,c);p&&n.push({field:f,message:p})}let u={...i,...r};for(let f of o)f.required&&Wy(u[f.name])&&n.push({field:f.name,message:`${f.name} is required`});return n}function i9(t,e,r){if(!Array.isArray(r))return[{field:t,message:`${t} must be a table (an array of rows)`}];let i=qR(e.fields??[]),n=[];return r.forEach((s,a)=>{if(!Nn(s)){n.push({field:`${t}[${a}]`,message:`${t}[${a}] must be a row object`});return}for(let[o,u]of Object.entries(s)){if(Wy(u))continue;let f=i.get(o);if(!f?.type)continue;let c=MR(f.type);if(c==="Table")continue;let h=`${t}[${a}].${o}`,d=PR(h,c,u);d&&n.push({field:h,message:d})}}),n}function n9(){return new Date().toISOString()}function Ah(t){return{name:String(t.name??""),information:Array.isArray(t.information)?t.information:[],states:Array.isArray(t.states)?t.states:[],activities:Array.isArray(t.activities)?t.activities:[],flows:Array.isArray(t.flows)?t.flows:[]}}function LR(t){return t.states.length>0}function Hy(t){return LR(t)?(t.states.find(r=>r.initial===!0)??t.states[0])?.name??null:null}function s9(t,e,r){let i=e===null||e==="";for(let n of t.flows)if(n.activity===r&&(i||n.from===""||n.from===e))return n;return null}function Ih(t,e){let r={},i=e===null||e==="";for(let n of t.flows)(i||n.from===""||n.from===e)&&(r[n.activity]??=[]).push(n.to);return{currentState:e,transitions:r}}var Oh=class{constructor(e){this.store=e}store;capabilities(){return{workspaces:!1,governedHistory:!1,files:!1,authorization:!1}}listModuleDefinitions(){return this.store.listModules().map(e=>e.definition)}getModuleDefinition(e){return this.store.getModule(e)?.definition??null}getStructure(e){let r=this.getModuleDefinition(e);return r?Ah(r):null}putModuleDefinition(e,r){this.store.putModule({name:e,definition:r})}renameModule(e,r){this.store.renameModule(e,r)}getEntry(e,r){return this.store.getEntry(e,r)}queryEntries(e,r){return this.store.queryEntries(e,r)}transitionsFor(e,r){let i=this.getStructure(e);return i?Ih(i,r):{currentState:r,transitions:{}}}submitActivity(e){let r=this.store.getModule(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let i=Ah(r.definition);if(e.idempotencyKey){let o=this.store.getIdempotent(e.idempotencyKey);if(o!==void 0)return o}let n=e.activity,s=e.input??{},a=e.entryId===void 0||n==="create";return this.store.transaction(o=>{let u=n9(),f;if(a){let c=Rh(i,n,s,{});if(c.length)throw kh(c);let h=o.insertEntry({module:e.module,state:Hy(i),version:1,data:s,createdAt:u,updatedAt:u});f={module:e.module,activity:n,entry:h,created:!0,deleted:!1}}else{let c=o.getEntry(e.module,e.entryId);if(!c)throw ii(`Entry not found: ${String(e.entryId)}`);if(e.expectedVersion!==void 0&&c.version!==e.expectedVersion)throw NR(`Version conflict on entry ${String(e.entryId)}: expected ${e.expectedVersion}, found ${c.version}`);if(n==="delete")o.deleteEntry(e.module,e.entryId),f={module:e.module,activity:n,entry:null,created:!1,deleted:!0};else if(n==="edit"||!LR(i)){let h=Rh(i,n,s,c.data);if(h.length)throw kh(h);let d={...c,data:{...c.data,...s},version:c.version+1,updatedAt:u};o.updateEntry(d),f={module:e.module,activity:n,entry:d,created:!1,deleted:!1}}else{let h=s9(i,c.state,n);if(!h)throw IR(`No flow permits activity '${n}' from state '${c.state??"\u2014"}' in module '${e.module}'`);let d=Rh(i,n,s,c.data);if(d.length)throw kh(d);let p={...c,data:{...c.data,...s},state:h.to,version:c.version+1,updatedAt:u};o.updateEntry(p),f={module:e.module,activity:n,entry:p,created:!1,deleted:!1}}}return e.idempotencyKey&&o.recordIdempotent(e.idempotencyKey,f),f})}submitActivities(e,r,i){return i.map(n=>{try{let s=this.submitActivity({module:e,activity:r,entryId:n.entryId,input:n.input,idempotencyKey:n.idempotencyKey,expectedVersion:n.expectedVersion});return{ok:!0,clientRef:n.clientRef,result:s}}catch(s){let a=s;return{ok:!1,clientRef:n.clientRef,code:a.code??"ERROR",message:a.message??String(s),details:a.details}}})}};import{readFileSync as jR,existsSync as $R}from"node:fs";import{dirname as UR,resolve as yu}from"node:path";import{fileURLToPath as a9}from"node:url";var o9=UR(a9(import.meta.url));function l9(t){let e=t;for(let r=0;r<8;r++){let i=yu(e,"data");if($R(yu(i,"inistate-schema.json")))return i;let n=UR(e);if(n===e)break;e=n}return yu(t,"../../data")}var WR=l9(o9),u9=yu(WR,"inistate-schema.json"),BR=yu(WR,"facts-module-design-guide.md"),Hi=JSON.parse(jR(u9,"utf-8")),DCe=$R(BR)?jR(BR,"utf-8"):"The Module Design Guide is not available in this distribution.",HR=["FieldType","FieldDefinition","SubFieldDefinition","StateDefinition","FileFieldValue","FileFieldInput","ModuleFieldValue","UserFieldValue","ErrorResponse"],f9=[...HR,"EntryData","Entry","EntryList","ActivityForm","ActivitySubmission","AvailableActivities","ActivityResult","FilterOperators"],c9=[...HR,"ActivityDefinition","ActivityFieldRef","FlowDefinition","ModuleSchema"];function h9(t,e){let r={};if(!t)return r;for(let i of e)i in t&&(r[i]=t[i]);return r}function zR(t){return{$schema:Hi.$schema,title:Hi.title,description:Hi.description,version:Hi.version,definitions:h9(Hi.definitions,t)}}var FCe=zR(f9),MCe=zR(c9),Xy=Hi.definitions?.FieldType?.enum??["Text","MultiText","Integer","Number","Currency","Date","DateTime","DateRange","Selection","Tag","YesNo","Email","Phone","Link","Image","Images","File","Files","Module","Modules","User","Users","Table","Signature","Formula"],d9=Hi.definitions?.ActivityDefinition?.properties?.actor?.enum??["human","ai","hybrid"],p9=Hi.workflow_guide?.state_color_system?.palette??{},Nh=Object.keys(p9),zy=Hi.workflow_guide?.state_color_system?.keyword_hints??{};function Vy(t){return t.startsWith("Selection(")&&t.endsWith(")")?!0:Xy.includes(t)}function XR(t){return Nh.length===0?/^#[0-9A-Fa-f]{6}$/.test(t):Nh.includes(t)}function VR(t){return d9.includes(t)}function GR(t){let e=t.toLowerCase();if((zy["#1E6B45"]||[]).some(s=>e.includes(s)))return"#1E6B45";if((zy["#8B2D2D"]||[]).some(s=>e.includes(s)))return"#8B2D2D";let n=["#2A7B50","#C0392B","#A07828","#6B4D91","#2968A8","#5A6070"];for(let s of n)if((zy[s]||[]).some(o=>e.includes(o)))return s;return"#2968A8"}function vu(t,e="create"){let r=[],i=[],n=t.name||"",s=t.information||[],a=t.states||[],o=t.activities||[],u=t.flows||[],f=a.length>0;!n&&e==="create"&&r.push("Module name is required.");let c=new Set;for(let h of s)c.has(h.name)&&r.push(`Duplicate field name: '${h.name}'.`),c.add(h.name);for(let h of s)if(h.type&&!Vy(h.type)&&r.push(`Field '${h.name}' has invalid type '${h.type}'. Valid types: ${Xy.join(", ")}.`),h.type==="Table")if(!h.fields||!Array.isArray(h.fields)||h.fields.length===0)r.push(`Table field '${h.name}' has no sub-fields defined.`);else for(let d of h.fields)d.type&&!Vy(d.type)&&r.push(`Table field '${h.name}' sub-field '${d.name}' has invalid type '${d.type}'.`);if(f){let h=a.filter(E=>E.initial===!0);h.length===0?r.push("No initial state defined \u2014 exactly one state must have initial: true."):h.length>1&&r.push(`Multiple initial states: ${h.map(E=>`'${E.name}'`).join(", ")}. Exactly one is allowed.`);let d=new Set;for(let E of a)d.has(E.name)&&r.push(`Duplicate state name: '${E.name}'.`),d.add(E.name);for(let E of a)E.color&&!XR(E.color)&&r.push(`State '${E.name}' has invalid color '${E.color}'. Valid colors: ${Nh.join(", ")}.`),E.color||i.push(`State '${E.name}' has no color \u2014 will use default.`);let p=new Set;for(let E of o)p.has(E.name)&&r.push(`Duplicate activity name: '${E.name}'.`),p.add(E.name);for(let E of o){if(E.actor&&!VR(E.actor)&&r.push(`Activity '${E.name}' has invalid actor '${E.actor}'. Valid: human, ai, hybrid.`),E.confidence_threshold!==void 0&&E.confidence_threshold!==null&&(E.confidence_threshold<0||E.confidence_threshold>1)&&r.push(`Activity '${E.name}' confidence_threshold must be between 0 and 1.`),E.fields&&Array.isArray(E.fields))for(let U of E.fields){let ee=typeof U=="string"?U:U.name;c.has(ee)||r.push(`Activity '${E.name}' references field '${ee}' which is not defined in information. Available fields: ${[...c].join(", ")}.`)}E.actor==="ai"&&(!E.confidence_threshold&&E.confidence_threshold!==0&&i.push(`Activity '${E.name}' has no confidence_threshold \u2014 AI agents will not be gated on this activity.`),E.ai_hint||i.push(`Activity '${E.name}' has actor 'ai' but no ai_hint \u2014 agents may struggle to execute correctly.`))}for(let E of u)E.from!==""&&!d.has(E.from)&&r.push(`Flow references state '${E.from}' (from) which is not defined. Available states: ${[...d].join(", ")}.`),d.has(E.to)||r.push(`Flow references state '${E.to}' (to) which is not defined. Available states: ${[...d].join(", ")}.`),p.has(E.activity)||r.push(`Flow from '${E.from}' to '${E.to}' references activity '${E.activity}' which is not defined in activities. Available activities: ${[...p].join(", ")}.`);let g=h.length>0?h[0].name:"",y=new Set(u.map(E=>E.to));for(let E of a)E.name!==g&&!y.has(E.name)&&i.push(`State '${E.name}' is unreachable \u2014 no flows lead to it.`);let v=new Set(u.map(E=>E.activity));for(let E of o)v.has(E.name)||i.push(`Activity '${E.name}' is not used in any flow.`);let b=new Set(u.map(E=>E.from)),k=a.filter(E=>!b.has(E.name));k.length===0&&i.push("No terminal states \u2014 process may run indefinitely.");let N={field_count:s.length,state_count:a.length,activity_count:o.length,flow_count:u.length,initial_state:g,terminal_states:k.map(E=>E.name),ai_activities:o.filter(E=>E.actor==="ai").length,hybrid_activities:o.filter(E=>E.actor==="hybrid").length,gated_activities:o.filter(E=>E.confidence_threshold&&E.confidence_threshold>0).length};return{valid:r.length===0,errors:r,warnings:i,summary:r.length===0?N:null}}return{valid:r.length===0,errors:r,warnings:i,summary:r.length===0?{field_count:s.length,module_type:"record_list"}:null}}var Rr=class t extends Error{structured;constructor(e){super(e.message),this.name="StructuredError",this.structured=e,Object.setPrototypeOf(this,t.prototype)}};function eo(t,e){let r=t?.[e];return Array.isArray(r)?r:[]}function mi(t){if(t instanceof Rr)return t;if(DR(t))switch(t.code){case"NOT_FOUND":return new Rr({error:"Not found",message:t.message,agent_action:"Verify the module name or entry ID. Do not retry with the same values."});case"VALIDATION_FAILED":return new Rr({error:"Validation failed",message:t.message,details:t.details,agent_action:"Surface details[].field and details[].message, correct the input, and retry."});case"ILLEGAL_TRANSITION":return new Rr({error:"Illegal transition",message:t.message,agent_action:"This activity is not legal from the entry's current state. Call get_form or get_entry to see availableActivities, then submit a permitted activity."});case"CONFLICT":return new Rr({error:"Conflict",message:t.message,agent_action:"The entry changed since you read it. Re-read it with get_entry and retry with the new version."})}return new Rr({error:"Request failed",message:t instanceof Error?t.message:String(t),agent_action:"Unexpected error. Report to the user."})}function Gy(t,e){let r=Ih(t,e);return{standard:["edit","delete"],custom:Object.keys(r.transitions),stateFlow:{currentState:r.currentState,transitions:r.transitions}}}function ZR(t,e,r){return{module:t,entryId:e.id,documentId:e.documentId,state:e.state,date:e.createdAt,data:e.data,version:e.version,createdDate:e.createdAt,updatedDate:e.updatedAt,availableActivities:Gy(r,e.state)}}var Dh=class{kind="local";engine;constructor(e){this.engine=e}capabilities(){let e=this.engine.capabilities();return{workspaces:e.workspaces,governedHistory:e.governedHistory,files:e.files,authorization:e.authorization,modes:["runtime","configure"]}}async listModules(){try{let r=this.engine.listModuleDefinitions().map(i=>{let n=Ah(i);return{name:n.name,icon:i.icon??null,description:i.description??null,type:n.states.length>0?"workflow":"record_list"}});return{list:r,totalItems:r.length}}catch(e){throw mi(e)}}async getModuleSchema(e){try{let r=this.engine.getModuleDefinition(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let i={name:r.name,icon:r.icon,description:r.description,information:eo(r,"information"),states:eo(r,"states")};return e.tier==="extended"?{...i,activities:eo(r,"activities"),flows:eo(r,"flows")}:i}catch(r){throw mi(r)}}async getModuleCanvas(e){try{let r=this.engine.getModuleDefinition(e.module);if(!r)throw ii(`Module not found: ${e.module}`);return{id:r.id??r.name,...r}}catch(r){throw mi(r)}}async createModule(e){try{let r=vu(e,"create");if(!r.valid)throw new Rr({error:"Validation failed",message:r.errors.join(" ")||"Schema validation failed",details:r.errors.map(n=>({field:"schema",message:n})),agent_action:"Fix the schema errors and retry. Call validate_design to check before submitting."});let i=String(e.name??"");if(this.engine.getModuleDefinition(i))throw new Rr({error:"Module already exists",message:`A module named '${i}' already exists.`,agent_action:"Use update_module to modify it, or choose a different name."});return this.engine.putModuleDefinition(i,e),{id:i,name:i,message:`Module '${i}' created`,warnings:r.warnings,summary:r.summary}}catch(r){throw mi(r)}}async updateModule(e){try{let r=String(e.id),i=this.engine.getModuleDefinition(r);if(!i)throw ii(`Module not found: ${r}`);let n={...i};for(let o of["icon","description","information","states","activities","flows"])o in e.patch&&(n[o]=e.patch[o]);let s=e.patch.name!==void 0?String(e.patch.name):r;n.name=s;let a=vu(n,"update");if(!a.valid)throw new Rr({error:"Validation failed",message:a.errors.join(" ")||"Schema validation failed",details:a.errors.map(o=>({field:"schema",message:o})),agent_action:"Fix the schema errors and retry. Call validate_design to check before submitting."});if(s!==r){if(this.engine.getModuleDefinition(s))throw new Rr({error:"Validation failed",message:`Cannot rename to '${s}' \u2014 a module with that name already exists.`,agent_action:"Choose a different name."});this.engine.renameModule(r,s)}return this.engine.putModuleDefinition(s,n),{id:s,name:s,message:`Module '${s}' updated`,warnings:a.warnings}}catch(r){throw mi(r)}}async listEntries(e){try{let r=this.engine.getStructure(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let{items:i,total:n}=this.engine.queryEntries(e.module,{state:e.state,search:e.search,filters:e.filters,sortBy:e.sortBy,sortDirection:e.sortDirection,page:e.currentPage,pageSize:e.pageSize,fields:e.fields});return{moduleId:e.module,page:e.currentPage??0,pageSize:e.pageSize??50,totalItems:n,list:i.map(s=>ZR(e.module,s,r))}}catch(r){throw mi(r)}}async getEntry(e){try{let r=this.engine.getStructure(e.module);if(!r)throw ii(`Module not found: ${e.module}`);let i=this.engine.getEntry(e.module,e.entryId);if(!i)throw ii(`Entry not found: ${String(e.entryId)}`);return ZR(e.module,i,r)}catch(r){throw mi(r)}}async getForm(e){try{let r=this.engine.getModuleDefinition(e.module),i=this.engine.getStructure(e.module);if(!r||!i)throw ii(`Module not found: ${e.module}`);let n=eo(r,"information"),s=new Map(n.map(y=>[String(y.name),y])),a=eo(r,"activities").find(y=>y.name===e.activity),o=Array.isArray(a?.fields)?a.fields:[],f=(o.length>0?o.map(y=>typeof y=="string"?{name:y}:y):n.map(y=>({name:String(y.name)}))).map(y=>{let v=s.get(y.name)??{},b={type:v.type,required:y.required??!1,readOnly:y.readOnly??!1},k=y.options??v.options;return k&&(b.options=k),v.fields&&(b.fields=v.fields),{[y.name]:b}}),c={},h,d=Hy(i);if(e.entryId!==void 0&&e.entryId!==null){let y=this.engine.getEntry(e.module,e.entryId);y&&(c=y.data,h=y.documentId,d=y.state)}let g=Ih(i,d).transitions[e.activity]??[];return{module:e.module,activity:e.activity,entryId:e.entryId??null,documentId:h,form:f,defaults:c,states:g,availableActivities:Gy(i,d)}}catch(r){throw mi(r)}}async submitActivity(e){try{let r=this.engine.submitActivity({module:e.module,activity:e.activity,entryId:e.entryId,input:e.input,idempotencyKey:e.idempotencyKey,expectedVersion:e.expectedVersion});if(r.deleted)return{module:e.module,activity:e.activity,entryId:e.entryId,deleted:!0,message:null};let i=r.entry,n=this.engine.getStructure(e.module);return{module:e.module,activity:e.activity,entryId:i.id,documentId:i.documentId,state:i.state,version:i.version,message:null,availableActivities:Gy(n,i.state)}}catch(r){throw mi(r)}}async submitActivities(e){try{let r=this.engine.submitActivities(e.module,e.activity,e.items),i=0,n=0,s=r.map(a=>{if(a.ok){i++;let o=a.result;if(o.deleted)return{success:!0,clientRef:a.clientRef,deleted:!0};let u=o.entry;return{success:!0,clientRef:a.clientRef,entryId:u.id,documentId:u.documentId,state:u.state,version:u.version}}return n++,{success:!1,clientRef:a.clientRef,error:a.code,message:a.message,details:a.details}});return{module:e.module,activity:e.activity,results:s,summary:{total:r.length,succeeded:i,failed:n}}}catch(r){throw mi(r)}}};function g9(t){let e=t.split(/[^A-Za-z0-9]+/).filter(Boolean);return e.length>=2?e.map(i=>i[0]).join("").slice(0,4).toUpperCase():((e[0]??"REC").replace(/[^A-Za-z0-9]/g,"").slice(0,3)||"REC").toUpperCase()}function Ms(t,e){return`${g9(t)}-${String(e).padStart(4,"0")}`}function tr(t){return String(t??"").toLowerCase()}function Ar(t){if(typeof t=="number")return t;if(typeof t=="string"&&t.trim()!==""&&!Number.isNaN(Number(t)))return Number(t);if(typeof t=="string"){let e=Date.parse(t);if(!Number.isNaN(e))return e}return null}function m9(t,e){for(let[r,i]of Object.entries(e))switch(r){case"is":if(t!==i)return!1;break;case"not":if(t===i)return!1;break;case"contains":if(!tr(t).includes(tr(i)))return!1;break;case"startsWith":if(!tr(t).startsWith(tr(i)))return!1;break;case"endsWith":if(!tr(t).endsWith(tr(i)))return!1;break;case"min":case"after":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n<s)return!1;break}case"max":case"before":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n>s)return!1;break}case"above":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n<=s)return!1;break}case"below":{let n=Ar(t),s=Ar(i);if(n===null||s===null||n>=s)return!1;break}case"between":{if(!Array.isArray(i)||i.length!==2)return!1;let n=Ar(t),s=Ar(i[0]),a=Ar(i[1]);if(n===null||s===null||a===null||n<s||n>a)return!1;break}case"empty":{let n=t==null||t===""||Array.isArray(t)&&t.length===0;if(!!i!==n)return!1;break}case"exists":{let n=t!=null;if(!!i!==n)return!1;break}case"excludes":if(tr(t).includes(tr(i)))return!1;break;case"yes":if(!(t===!0||tr(t)==="true"||tr(t)==="yes"))return!1;break;case"no":if(!(t===!1||tr(t)==="false"||tr(t)==="no"))return!1;break;default:break}return!0}function y9(t,e,r){let i=t.data[e];return r!==null&&typeof r=="object"&&!Array.isArray(r)?m9(i,r):typeof i=="string"||typeof r=="string"?tr(i)===tr(r):i===r}function YR(t,e){for(let[r,i]of Object.entries(e)){if(r==="or"&&Array.isArray(i)){if(!i.some(s=>s&&typeof s=="object"&&YR(t,s)))return!1;continue}if(!y9(t,r,i))return!1}return!0}function v9(t,e){let r=e.toLowerCase();if(t.documentId.toLowerCase().includes(r))return!0;for(let i of Object.values(t.data))if(typeof i=="string"&&i.toLowerCase().includes(r))return!0;return!1}function to(t,e){let r=t;e.state&&(r=r.filter(u=>u.state===e.state)),e.search&&(r=r.filter(u=>v9(u,e.search))),e.filters&&(r=r.filter(u=>YR(u,e.filters)));let i=r.length;if(e.sortBy){let u=e.sortDirection==="desc"?-1:1,f=e.sortBy;r=[...r].sort((c,h)=>{let d=c.data[f],p=h.data[f],g=Ar(d),y=Ar(p);return g!==null&&y!==null?(g-y)*u:tr(d).localeCompare(tr(p))*u})}let n=e.pageSize&&e.pageSize>0?Math.min(e.pageSize,500):50,a=(e.page&&e.page>0?e.page:0)*n,o=r.slice(a,a+n);if(e.fields&&e.fields.length>0){let u=new Set(e.fields);o=o.map(f=>({...f,data:Object.fromEntries(Object.entries(f.data).filter(([c])=>u.has(c)))}))}return{items:o,total:i}}var Or=t=>structuredClone(t);function _9(t){let e=new Map;for(let[r,i]of t)e.set(r,new Map([...i].map(([n,s])=>[n,Or(s)])));return e}var ro=class{modules=new Map;entries=new Map;idem=new Map;counters=new Map;init(){}close(){}getModule(e){let r=this.modules.get(e);return r?Or(r):null}listModules(){return[...this.modules.values()].map(Or)}putModule(e){this.modules.set(e.name,Or(e))}renameModule(e,r){if(e===r)return;let i=this.modules.get(e);i&&(this.modules.delete(e),this.modules.set(r,{...i,name:r}));let n=this.entries.get(e);if(n){this.entries.delete(e);for(let a of n.values())a.module=r;this.entries.set(r,n)}let s=this.counters.get(e);s!==void 0&&(this.counters.delete(e),this.counters.set(r,s))}getEntry(e,r){let i=this.entries.get(e)?.get(String(r));return i?Or(i):null}queryEntries(e,r){let i=[...this.entries.get(e)?.values()??[]].map(Or);return to(i,r)}getIdempotent(e){return this.idem.has(e)?Or(this.idem.get(e)):void 0}transaction(e){let r={entries:_9(this.entries),idem:new Map(this.idem),counters:new Map(this.counters)},n=e({getEntry:(s,a)=>{let o=r.entries.get(s)?.get(String(a));return o?Or(o):null},insertEntry:s=>{let a=(r.counters.get(s.module)??0)+1;r.counters.set(s.module,a);let o={id:a,documentId:Ms(s.module,a),module:s.module,state:s.state,version:s.version,data:Or(s.data),createdAt:s.createdAt,updatedAt:s.updatedAt},u=r.entries.get(s.module);return u||(u=new Map,r.entries.set(s.module,u)),u.set(String(a),o),Or(o)},updateEntry:s=>{let a=r.entries.get(s.module);if(!a)throw new Error(`module not loaded: ${s.module}`);return a.set(String(s.id),Or(s)),Or(s)},deleteEntry:(s,a)=>{r.entries.get(s)?.delete(String(a))},recordIdempotent:(s,a)=>{r.idem.set(s,Or(a))}});return this.entries=r.entries,this.idem=r.idem,this.counters=r.counters,n}};import w9 from"better-sqlite3";import{mkdirSync as b9}from"node:fs";import{dirname as x9}from"node:path";function KR(t){return{id:t.id,documentId:t.document_id,module:t.module,state:t.state,version:t.version,data:JSON.parse(t.data),createdAt:t.created_at,updatedAt:t.updated_at}}var Ps=class{db;constructor(e){e!==":memory:"&&b9(x9(e),{recursive:!0}),this.db=new w9(e),this.db.pragma("journal_mode = WAL"),this.db.pragma("synchronous = NORMAL"),this.db.pragma("foreign_keys = ON"),this.init()}init(){this.db.exec(`
|
|
229
229
|
CREATE TABLE IF NOT EXISTS modules (
|
|
230
230
|
name TEXT PRIMARY KEY,
|
|
231
231
|
definition TEXT NOT NULL
|
|
@@ -264,7 +264,7 @@ Unsupported type: `+t.type,"ENOTSUP");t._finish()})};ei.prototype._stat=function
|
|
|
264
264
|
|
|
265
265
|
You are connected to the **local Core backend**, not the Inistate Platform.
|
|
266
266
|
|
|
267
|
-
**What Core does:** it runs
|
|
267
|
+
**What Core does:** it runs governed state-machine workflows on local persistence and enforces
|
|
268
268
|
the *present state* of each record \u2014 only legal transitions, validated forms,
|
|
269
269
|
atomic writes. The reliability invariants (atomicity, illegal-transition
|
|
270
270
|
rejection, idempotency, optimistic concurrency, crash durability) are the
|
|
@@ -297,7 +297,7 @@ backend swap, not a migration.
|
|
|
297
297
|
`))}function hCe(t){let e={};for(let r=0;r<t.length;r++){let i=t[r],n=i.startsWith("--")?i.indexOf("="):-1,s=i.startsWith("--")?i.slice(2,n===-1?void 0:n):null,a=n===-1?void 0:i.slice(n+1);s==="name"||s==="state"||s==="table"?e[s]=a??t[++r]:!i.startsWith("--")&&!e.target&&(e.target=i)}return e}async function u7(t){let{target:e,name:r,state:i,table:n}=hCe(t);if(!e){console.error("Usage: inistate-core scaffold <notion://db | airtable://base/table | ./file.db --table T> [--name M] [--state Col]"),process.exitCode=1;return}let s=await Fy(e,{table:n}),a=My(s,{name:r,state:i}),{suggestions:o,validation:u}=a;console.error(`
|
|
298
298
|
Scaffolded from ${o.source}`),console.error(`Module: ${a.schema.name} \xB7 type: ${o.module_type}${o.detected_state?` \xB7 state column: ${o.detected_state}`:""}`),console.error(`Fields: ${a.schema.information.length}${o.module_type==="workflow"?` \xB7 states: ${a.schema.states.length}`:""}`),console.error(`validate_design: ${u.valid?"valid":"INVALID"}${u.errors.length?` \u2014 ${u.errors.length} error(s)`:""}${u.warnings.length?` \xB7 ${u.warnings.length} warning(s)`:""}`);for(let f of u.errors)console.error(` error: ${f}`);for(let f of u.warnings)console.error(` warning: ${f}`);console.error(`
|
|
299
299
|
Next steps:`);for(let f of o.next_steps)console.error(` \u2022 ${f}`);console.error(`
|
|
300
|
-
--- ModuleSchema (stdout) ---`),console.log(JSON.stringify(a.schema,null,2))}var uu="0.1.
|
|
300
|
+
--- ModuleSchema (stdout) ---`),console.log(JSON.stringify(a.schema,null,2))}var uu="0.1.1";function gCe(){console.log(`inistate-core ${uu} \u2014 free, local runtime for governed state-machine workflows
|
|
301
301
|
|
|
302
302
|
Usage:
|
|
303
303
|
inistate-core Run the MCP server on stdio (default)
|
package/package.json
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inistate-core",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Free, local runtime for
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Free, local runtime for governed state-machine workflows — the deterministic floor of the Inistate stack. Runs governed state machines on persistence you control (SQLite by default), driven over MCP.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "GNEY SOFTWARE PTE LTD",
|
|
7
|
-
"license": "
|
|
7
|
+
"license": "LicenseRef-Inistate-Core-EULA",
|
|
8
8
|
"private": false,
|
|
9
|
+
"homepage": "https://github.com/Inistate/inistate-core#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Inistate/inistate-core.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Inistate/inistate-core/issues"
|
|
16
|
+
},
|
|
9
17
|
"bin": {
|
|
10
18
|
"inistate-core": "./dist/index.js"
|
|
11
19
|
},
|