@qqbrowser/qbot-claw-launcher 0.9.53 → 0.9.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- "use strict";var n=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MCP_HTTP_PORT=exports.STATE_FILE=exports.MCPORTER_BIN=exports.OPENCLAW_BIN=exports.QBOTCLAW_BIN=exports.NPM_GLOBAL_MODULES=exports.NPM_PACKAGE_NAME=exports.QBOT_CLAW_CONFIG_PATH=exports.NODE_BIN_DIR=exports.NPM_RC=exports.NPM_BIN=exports.PYTHON_BIN=exports.NODE_BIN=exports.QBOT_CLAW_DIR=void 0;const _=n(require("path")),o=n(require("os"));exports.QBOT_CLAW_DIR=_.default.join(o.default.homedir(),".qbotclaw"),exports.NODE_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","node"),exports.PYTHON_BIN=_.default.join(exports.QBOT_CLAW_DIR,"python","bin","python3"),exports.NPM_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","npm"),exports.NPM_RC=_.default.join(exports.QBOT_CLAW_DIR,"node",".npmrc"),exports.NODE_BIN_DIR=_.default.dirname(exports.NODE_BIN),exports.QBOT_CLAW_CONFIG_PATH=_.default.join(exports.QBOT_CLAW_DIR,".openclaw-qbot.json"),exports.NPM_PACKAGE_NAME="@qqbrowser/openclaw-qbot",exports.NPM_GLOBAL_MODULES=_.default.join(exports.QBOT_CLAW_DIR,"node","lib","node_modules"),exports.QBOTCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","qb-qbot-claw"),exports.OPENCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","openclaw"),exports.MCPORTER_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","mcporter"),exports.STATE_FILE=_.default.join(exports.QBOT_CLAW_DIR,"launcher.json"),exports.DEFAULT_MCP_HTTP_PORT=38789;
1
+ "use strict";var n=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_MCP_HTTP_PORT=exports.SESSIONS_FILE=exports.STATE_FILE=exports.MCPORTER_BIN=exports.OPENCLAW_BIN=exports.QBOTCLAW_BIN=exports.NPM_GLOBAL_MODULES=exports.NPM_PACKAGE_NAME=exports.QBOT_CLAW_CONFIG_PATH=exports.NODE_BIN_DIR=exports.NPM_RC=exports.NPM_BIN=exports.PYTHON_BIN=exports.NODE_BIN=exports.QBOT_CLAW_DIR=void 0;const _=n(require("path")),o=n(require("os"));exports.QBOT_CLAW_DIR=_.default.join(o.default.homedir(),".qbotclaw"),exports.NODE_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","node"),exports.PYTHON_BIN=_.default.join(exports.QBOT_CLAW_DIR,"python","bin","python3"),exports.NPM_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","npm"),exports.NPM_RC=_.default.join(exports.QBOT_CLAW_DIR,"node",".npmrc"),exports.NODE_BIN_DIR=_.default.dirname(exports.NODE_BIN),exports.QBOT_CLAW_CONFIG_PATH=_.default.join(exports.QBOT_CLAW_DIR,".openclaw-qbot.json"),exports.NPM_PACKAGE_NAME="@qqbrowser/openclaw-qbot",exports.NPM_GLOBAL_MODULES=_.default.join(exports.QBOT_CLAW_DIR,"node","lib","node_modules"),exports.QBOTCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","qb-qbot-claw"),exports.OPENCLAW_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","openclaw"),exports.MCPORTER_BIN=_.default.join(exports.QBOT_CLAW_DIR,"node","bin","mcporter"),exports.STATE_FILE=_.default.join(exports.QBOT_CLAW_DIR,"launcher.json"),exports.SESSIONS_FILE=_.default.join(exports.QBOT_CLAW_DIR,"agents","main","sessions","sessions.json"),exports.DEFAULT_MCP_HTTP_PORT=38789;
package/dist/installer.js CHANGED
@@ -1,5 +1,6 @@
1
- "use strict";var d=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PYTHON_DIR=exports.installState=void 0,exports.runQBotClaw=N,exports.configAndRunQBotClaw=A,exports.runInstall=B;const l=d(require("fs")),u=d(require("path")),p=require("child_process"),i=require("./config"),w=require("./utils"),g=require("./state"),_=require("./quarantine"),o=require("./reportLog");function c(t,n,r,a){if(t&&t.writable){const e=n>0?Math.round(r/n*1e4)/100:0;try{t.write(JSON.stringify({status:"downloading",progress:e,totalSteps:n,currentStep:r,message:a})+`
2
- `)}catch{}}}exports.installState={status:"idle",message:"\u672A\u5F00\u59CB"},exports.PYTHON_DIR=u.default.join(i.QBOT_CLAW_DIR,"python");function N(t,n){return new Promise(r=>{const a=(0,p.spawn)(i.QBOTCLAW_BIN,t,{stdio:["ignore","pipe","pipe"],env:{PATH:i.NODE_BIN_DIR,HOME:process.env.HOME,OPENCLAW_TELEMETRY_GALIELO_GUID:process.env.QB_GUID||"",OPENCLAW_TELEMETRY_GALIELO_QIEMI36:process.env.QB_QIMEI36||""}});(0,o.log)(`[QBotClaw] \u6267\u884C: QBotClaw ${t.join(" ")}`),a.stdout.on("data",e=>{const s=e.toString();if(n&&n.writable)try{n.write(s)}catch{}}),a.stderr.on("data",e=>{const s=e.toString();if(n&&n.writable)try{n.write(s)}catch{}}),a.on("close",e=>{(0,o.log)(`[QBotClaw] \u6267\u884C\u5B8C\u6210\uFF0C\u9000\u51FA\u7801: ${e}`),r()}),a.on("error",e=>{(0,o.log)(`[QBotClaw] \u542F\u52A8\u5931\u8D25: ${e.message}`),r()})})}function m(){l.default.existsSync(i.QBOT_CLAW_DIR)||l.default.mkdirSync(i.QBOT_CLAW_DIR,{recursive:!0})}function C(){const t=u.default.join(exports.PYTHON_DIR,"pip.conf");if(l.default.existsSync(t)){(0,o.log)("pip.conf \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");return}const n=["[global]","index-url = https://mirrors.tencent.com/pypi/simple/",`cache-dir = ${u.default.join(exports.PYTHON_DIR,".pip-cache")}`,"","[install]",`prefix = ${exports.PYTHON_DIR}`,""].join(`
3
- `);l.default.writeFileSync(t,n,"utf-8"),(0,o.log)(`\u5DF2\u5199\u5165 pip.conf: ${t}`)}async function E(t){if(l.default.existsSync(i.MCPORTER_BIN)){(0,o.log)("mcporter \u5DF2\u5B89\u88C5\uFF0C\u8DF3\u8FC7");return}(0,o.log)("\u5F00\u59CB\u5B89\u88C5 mcporter..."),await new Promise((n,r)=>{const a=(0,p.spawn)(i.NPM_BIN,["--userconfig",i.NPM_RC,"install","-g","mcporter"],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${u.default.dirname(i.NPM_BIN)}:${process.env.PATH}`}});a.stdout.on("data",e=>{const s=`[mcporter] ${e.toString().trim()}`;(0,o.log)(s),c(t,0,0,s)}),a.stderr.on("data",e=>{const s=`[mcporter] ${e.toString().trim()}`;(0,o.log)(s),c(t,0,0,s)}),a.on("close",e=>{e===0?((0,o.log)("mcporter \u5B89\u88C5\u6210\u529F"),n()):r(new Error(`mcporter \u5B89\u88C5\u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${e}`))}),a.on("error",r)})}function P(t,n){return new Promise((r,a)=>{const e=(0,p.spawn)(i.NPM_BIN,["--userconfig",i.NPM_RC,...t],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${u.default.dirname(i.NPM_BIN)}:${process.env.PATH}`}});e.stdout.on("data",s=>{const f=`[npm] ${s.toString().trim()}`;(0,o.log)(f)}),e.stderr.on("data",s=>{const f=`[npm] ${s.toString().trim()}`;(0,o.log)(f)}),e.on("close",s=>{s===0?((0,o.log)(`${n} \u6210\u529F`),r()):a(new Error(`${n} \u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${s}`))}),e.on("error",a)})}async function I(t){const n=`${i.NPM_PACKAGE_NAME}@${t}`;(0,o.log)(`\u5F00\u59CB\u5B89\u88C5 ${n}\uFF08--ignore-scripts\uFF0C\u4EC5\u4E0B\u8F7D\u89E3\u538B\uFF09...`),await P(["install","-g","--ignore-scripts",n],`${n} \u4E0B\u8F7D\u89E3\u538B`)}async function O(t){const n=`${i.NPM_PACKAGE_NAME}@${t}`;(0,o.log)("\u5F00\u59CB npm rebuild\uFF08\u6267\u884C postinstall \u811A\u672C\uFF09..."),await P(["rebuild","-g",i.NPM_PACKAGE_NAME],`${n} rebuild`),(0,o.log)(`${n} \u5B89\u88C5\u6210\u529F`)}async function $(t,n,r){let a;if(l.default.existsSync(i.QBOT_CLAW_CONFIG_PATH))a=i.QBOT_CLAW_CONFIG_PATH,(0,o.log)(`\u4F7F\u7528\u5DF2\u6709\u914D\u7F6E\u6587\u4EF6: ${a}`);else{const s=u.default.join(i.NPM_GLOBAL_MODULES,i.NPM_PACKAGE_NAME,"preset-config.json");if(!l.default.existsSync(s)){(0,o.log)(`npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165: ${s}`);return}a=s,(0,o.log)(`\u4F7F\u7528 npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E: ${a}`)}let e;try{e=JSON.parse(l.default.readFileSync(a,"utf-8")),(0,o.log)(`\u5DF2\u8BFB\u53D6\u914D\u7F6E: ${a}`)}catch(s){(0,o.log)(`\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25: ${a}\uFF0C${s.message}\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165`);return}t!==void 0&&(e.gateway={...e.gateway??{},port:t},(0,o.log)(`\u5DF2\u5C06 gateway.port=${t} \u5199\u5165\u914D\u7F6E`)),e.plugins=e.plugins??{},e.plugins.entries=e.plugins.entries??{},e.plugins.entries["x5use-browser-control"]=e.plugins.entries["x5use-browser-control"]??{},e.plugins.entries["x5use-browser-control"].config={...e.plugins.entries["x5use-browser-control"].config??{},wsPort:r,httpPort:n},(0,o.log)(`\u5DF2\u5C06 x5use-browser-control wsPort=${r}, httpPort=${n} \u5199\u5165\u914D\u7F6E`),l.default.writeFileSync(i.QBOT_CLAW_CONFIG_PATH,JSON.stringify(e,null,2),"utf-8"),(0,o.log)(`\u914D\u7F6E\u6587\u4EF6\u5DF2\u5199\u5165: ${i.QBOT_CLAW_CONFIG_PATH}`)}async function A(){const t=(0,g.readState)();let n;t.gatewayPort&&!await(0,g.isPortAvailable)(t.gatewayPort)?(n=t.gatewayPort,(0,o.log)(`\u68C0\u6D4B\u5230 QBotClaw gateway \u5DF2\u5728\u7AEF\u53E3 ${n} \u8FD0\u884C\uFF0C\u590D\u7528\u539F\u7AEF\u53E3`)):n=await(0,w.findAvailablePort)(),(0,o.log)(`\u540E\u53F0\u542F\u52A8 QBotClaw gateway run --port ${n} --force`);const r=await(0,w.findAvailablePort)(i.DEFAULT_MCP_HTTP_PORT),a=await(0,w.findAvailablePort)();await $(n,r,a);const e=(0,p.spawn)(i.QBOTCLAW_BIN,["gateway","run","--port",String(n),"--force"],{stdio:"ignore",env:{PATH:i.NODE_BIN_DIR,HOME:process.env.HOME,OPENCLAW_NO_RESPAWN:"true",VENUS_API_KEY:"E9isWWfAr4VIFuIa5RbJaPxD@2040",OPENCLAW_TELEMETRY_GALIELO_GUID:process.env.QB_GUID||"",OPENCLAW_TELEMETRY_GALIELO_QIEMI36:process.env.QB_QIMEI36||""}});e.unref();const s=e.pid;(0,o.log)(`QBotClaw gateway \u5DF2\u5728\u540E\u53F0\u542F\u52A8\uFF0CPID: ${s}\uFF0C\u7AEF\u53E3: ${n}`),(0,g.writeState)({...(0,g.readState)(),gatewayPid:s,gatewayPort:n,mcpHttpPort:r,mcpWsPort:a})}function B(t,n){exports.installState={status:"downloading",message:"\u6B63\u5728\u5B89\u88C5...",startTime:new Date().toISOString()},(0,o.log)(`\u5F00\u59CB\u5B89\u88C5 ${i.NPM_PACKAGE_NAME}@${n}`),(async()=>{try{(0,g.stopGateway)(),m(),C();const r=5;let a=0;c(t,r,a,"\u5F00\u59CB\u5B89\u88C5 mcporter..."),await E(t),a++,c(t,r,a,"\u5F00\u59CB\u4E0B\u8F7D\u89E3\u538B QBotClaw..."),await I(n),a++,c(t,r,a,"npmDownloadQBotClaw \u5B8C\u6210"),await(0,_.fullScanClearQuarantine)("npm install --ignore-scripts \u5B8C\u6210\u540E\uFF0Crebuild \u524D"),a++,await(0,_.watchWorkspaceQuarantine)().catch(e=>{(0,o.log)(`[quarantine] watchWorkspaceQuarantine \u542F\u52A8\u5F02\u5E38: ${e.message}`)}),c(t,r,a,"\u5F00\u59CB npm rebuild..."),await O(n),a++,c(t,r,a,"npmRebuildQBotClaw \u5B8C\u6210");try{l.default.existsSync(i.OPENCLAW_BIN)||(l.default.symlinkSync(i.QBOTCLAW_BIN,i.OPENCLAW_BIN),(0,o.log)(`\u5DF2\u521B\u5EFA\u8F6F\u94FE\u63A5: ${i.OPENCLAW_BIN} -> ${i.QBOTCLAW_BIN}`))}catch(e){(0,o.log)(`\u521B\u5EFA openclaw \u8F6F\u94FE\u63A5\u5931\u8D25: ${e.message}`)}if(await(0,_.stopWatchWorkspaceQuarantine)().catch(e=>{(0,o.log)(`[quarantine] stopWatchWorkspaceQuarantine \u5F02\u5E38: ${e.message}`)}),exports.installState={status:"success",message:"\u5B89\u88C5\u6210\u529F",endTime:new Date().toISOString()},(0,o.log)("\u5B89\u88C5\u6210\u529F"),(0,o.refreshClawVersion)(n),c(t,r,a,"\u5F00\u59CB\u914D\u7F6E\u5E76\u542F\u52A8 QBotClaw gateway..."),await A(),a++,t.writable)try{t.end(JSON.stringify({status:"done",progress:100,message:"\u5B89\u88C5\u6210\u529F"})+`
4
- `)}catch{}}catch(r){if(await(0,_.stopWatchWorkspaceQuarantine)().catch(()=>{}),exports.installState={status:"failed",message:r.message,endTime:new Date().toISOString()},(0,o.log)(`\u5B89\u88C5\u5931\u8D25: ${r.message}`),t&&t.writable)try{t.end(JSON.stringify({status:"failed",progress:0,message:r.message})+`
5
- `)}catch{}}})()}
1
+ "use strict";var d=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PYTHON_DIR=exports.isInstalling=exports.installState=void 0,exports.runQBotClaw=A,exports.configAndRunQBotClaw=N,exports.runInstall=$;const c=d(require("fs")),u=d(require("path")),_=require("child_process"),s=require("./config"),w=require("./utils"),p=require("./state"),f=require("./quarantine"),a=require("./reportLog");function g(t,o,r,i){if(t&&t.writable){const e=o>0?Math.round(r/o*1e4)/100:0;try{t.write(JSON.stringify({status:"downloading",progress:e,totalSteps:o,currentStep:r,message:i})+`
2
+ `)}catch{}}}exports.installState={status:"idle",message:"\u672A\u5F00\u59CB"},exports.isInstalling=!1,exports.PYTHON_DIR=u.default.join(s.QBOT_CLAW_DIR,"python");function A(t,o){return new Promise(r=>{const i=(0,_.spawn)(s.QBOTCLAW_BIN,t,{stdio:["ignore","pipe","pipe"],env:{PATH:s.NODE_BIN_DIR,HOME:process.env.HOME,OPENCLAW_TELEMETRY_GALIELO_GUID:process.env.QB_GUID||"",OPENCLAW_TELEMETRY_GALIELO_QIEMI36:process.env.QB_QIMEI36||""}});(0,a.log)(`[QBotClaw] \u6267\u884C: QBotClaw ${t.join(" ")}`),i.stdout.on("data",e=>{const n=e.toString();if(o&&o.writable)try{o.write(n)}catch{}}),i.stderr.on("data",e=>{const n=e.toString();if(o&&o.writable)try{o.write(n)}catch{}}),i.on("close",e=>{(0,a.log)(`[QBotClaw] \u6267\u884C\u5B8C\u6210\uFF0C\u9000\u51FA\u7801: ${e}`),r()}),i.on("error",e=>{(0,a.log)(`[QBotClaw] \u542F\u52A8\u5931\u8D25: ${e.message}`),r()})})}function I(){c.default.existsSync(s.QBOT_CLAW_DIR)||c.default.mkdirSync(s.QBOT_CLAW_DIR,{recursive:!0})}function m(){const t=u.default.join(exports.PYTHON_DIR,"pip.conf");if(c.default.existsSync(t)){(0,a.log)("pip.conf \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");return}const o=["[global]","index-url = https://mirrors.tencent.com/pypi/simple/",`cache-dir = ${u.default.join(exports.PYTHON_DIR,".pip-cache")}`,"","[install]",`prefix = ${exports.PYTHON_DIR}`,""].join(`
3
+ `);c.default.writeFileSync(t,o,"utf-8"),(0,a.log)(`\u5DF2\u5199\u5165 pip.conf: ${t}`)}async function C(t){if(c.default.existsSync(s.MCPORTER_BIN)){(0,a.log)("mcporter \u5DF2\u5B89\u88C5\uFF0C\u8DF3\u8FC7");return}(0,a.log)("\u5F00\u59CB\u5B89\u88C5 mcporter..."),await new Promise((o,r)=>{const i=(0,_.spawn)(s.NPM_BIN,["--userconfig",s.NPM_RC,"install","-g","mcporter"],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${u.default.dirname(s.NPM_BIN)}:${process.env.PATH}`}});i.stdout.on("data",e=>{const n=`[mcporter] ${e.toString().trim()}`;(0,a.log)(n),g(t,0,0,n)}),i.stderr.on("data",e=>{const n=`[mcporter] ${e.toString().trim()}`;(0,a.log)(n),g(t,0,0,n)}),i.on("close",e=>{e===0?((0,a.log)("mcporter \u5B89\u88C5\u6210\u529F"),o()):r(new Error(`mcporter \u5B89\u88C5\u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${e}`))}),i.on("error",r)})}function P(t,o){return new Promise((r,i)=>{const e=(0,_.spawn)(s.NPM_BIN,["--userconfig",s.NPM_RC,...t],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${u.default.dirname(s.NPM_BIN)}:${process.env.PATH}`}});e.stdout.on("data",n=>{const l=`[npm] ${n.toString().trim()}`;(0,a.log)(l)}),e.stderr.on("data",n=>{const l=`[npm] ${n.toString().trim()}`;(0,a.log)(l)}),e.on("close",n=>{n===0?((0,a.log)(`${o} \u6210\u529F`),r()):i(new Error(`${o} \u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${n}`))}),e.on("error",i)})}async function E(t){const o=`${s.NPM_PACKAGE_NAME}@${t}`;(0,a.log)(`\u5F00\u59CB\u5B89\u88C5 ${o}\uFF08--ignore-scripts\uFF0C\u4EC5\u4E0B\u8F7D\u89E3\u538B\uFF09...`),await P(["install","-g","--ignore-scripts",o],`${o} \u4E0B\u8F7D\u89E3\u538B`)}async function O(t){const o=`${s.NPM_PACKAGE_NAME}@${t}`;(0,a.log)("\u5F00\u59CB npm rebuild\uFF08\u6267\u884C postinstall \u811A\u672C\uFF09..."),await P(["rebuild","-g",s.NPM_PACKAGE_NAME],`${o} rebuild`),(0,a.log)(`${o} \u5B89\u88C5\u6210\u529F`)}async function y(t,o,r,i){let e;if((0,a.log)(`\u8986\u76D6\u7528\u6237\u5DF2\u6709\u914D\u7F6E: ${i}`),!i&&c.default.existsSync(s.QBOT_CLAW_CONFIG_PATH))e=s.QBOT_CLAW_CONFIG_PATH,(0,a.log)(`\u4F7F\u7528\u5DF2\u6709\u914D\u7F6E\u6587\u4EF6: ${e}`);else{const l=u.default.join(s.NPM_GLOBAL_MODULES,s.NPM_PACKAGE_NAME,"preset-config.json");if(!c.default.existsSync(l)){(0,a.log)(`npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165: ${l}`);return}e=l,(0,a.log)(`\u4F7F\u7528 npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E: ${e}`)}let n;try{n=JSON.parse(c.default.readFileSync(e,"utf-8")),(0,a.log)(`\u5DF2\u8BFB\u53D6\u914D\u7F6E: ${e}`)}catch(l){(0,a.log)(`\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25: ${e}\uFF0C${l.message}\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165`);return}t!==void 0&&(n.gateway={...n.gateway??{},port:t},(0,a.log)(`\u5DF2\u5C06 gateway.port=${t} \u5199\u5165\u914D\u7F6E`)),n.plugins=n.plugins??{},n.plugins.entries=n.plugins.entries??{},n.plugins.entries["x5use-browser-control"]=n.plugins.entries["x5use-browser-control"]??{},n.plugins.entries["x5use-browser-control"].config={...n.plugins.entries["x5use-browser-control"].config??{},wsPort:r,httpPort:o},(0,a.log)(`\u5DF2\u5C06 x5use-browser-control wsPort=${r}, httpPort=${o} \u5199\u5165\u914D\u7F6E`),c.default.writeFileSync(s.QBOT_CLAW_CONFIG_PATH,JSON.stringify(n,null,2),"utf-8"),(0,a.log)(`\u914D\u7F6E\u6587\u4EF6\u5DF2\u5199\u5165: ${s.QBOT_CLAW_CONFIG_PATH}`)}async function N(t){const o=(0,p.readState)();let r;o.gatewayPort&&!await(0,p.isPortAvailable)(o.gatewayPort)?(r=o.gatewayPort,(0,a.log)(`\u68C0\u6D4B\u5230 QBotClaw gateway \u5DF2\u5728\u7AEF\u53E3 ${r} \u8FD0\u884C\uFF0C\u590D\u7528\u539F\u7AEF\u53E3`)):r=await(0,w.findAvailablePort)(),(0,a.log)(`\u540E\u53F0\u542F\u52A8 QBotClaw gateway run --port ${r} --force`);const i=await(0,w.findAvailablePort)(s.DEFAULT_MCP_HTTP_PORT),e=await(0,w.findAvailablePort)();await y(r,i,e,t);const n=(0,_.spawn)(s.QBOTCLAW_BIN,["gateway","run","--port",String(r),"--force"],{stdio:"ignore",env:{PATH:s.NODE_BIN_DIR,HOME:process.env.HOME,OPENCLAW_NO_RESPAWN:"true",VENUS_API_KEY:"E9isWWfAr4VIFuIa5RbJaPxD@2040",OPENCLAW_TELEMETRY_GALIELO_GUID:process.env.QB_GUID||"",OPENCLAW_TELEMETRY_GALIELO_QIEMI36:process.env.QB_QIMEI36||""}});n.unref();const l=n.pid;(0,a.log)(`QBotClaw gateway \u5DF2\u5728\u540E\u53F0\u542F\u52A8\uFF0CPID: ${l}\uFF0C\u7AEF\u53E3: ${r}`),(0,p.writeState)({...(0,p.readState)(),gatewayPid:l,gatewayPort:r,mcpHttpPort:i,mcpWsPort:e})}function $(t,o,r){if(exports.isInstalling){if((0,a.log)("[runInstall] \u5B89\u88C5\u6B63\u5728\u8FDB\u884C\u4E2D\uFF0C\u62D2\u7EDD\u91CD\u590D\u6267\u884C"),t&&t.writable)try{t.end(JSON.stringify({status:"failed",progress:0,message:"\u5B89\u88C5\u6B63\u5728\u8FDB\u884C\u4E2D\uFF0C\u8BF7\u52FF\u91CD\u590D\u64CD\u4F5C"})+`
4
+ `)}catch{}return}exports.isInstalling=!0,exports.installState={status:"downloading",message:"\u6B63\u5728\u5B89\u88C5...",startTime:new Date().toISOString()},(0,a.log)(`\u5F00\u59CB\u5B89\u88C5 ${s.NPM_PACKAGE_NAME}@${o}`),(async()=>{try{(0,p.stopGateway)(),I(),m();const i=5;let e=0;g(t,i,e,"\u5F00\u59CB\u5B89\u88C5 mcporter..."),await C(t),e++,g(t,i,e,"\u5F00\u59CB\u4E0B\u8F7D\u89E3\u538B QBotClaw..."),await E(o),e++,g(t,i,e,"npmDownloadQBotClaw \u5B8C\u6210"),await(0,f.fullScanClearQuarantine)("npm install --ignore-scripts \u5B8C\u6210\u540E\uFF0Crebuild \u524D"),e++,await(0,f.watchWorkspaceQuarantine)().catch(n=>{(0,a.log)(`[quarantine] watchWorkspaceQuarantine \u542F\u52A8\u5F02\u5E38: ${n.message}`)}),g(t,i,e,"\u5F00\u59CB npm rebuild..."),await O(o),e++,g(t,i,e,"npmRebuildQBotClaw \u5B8C\u6210");try{c.default.existsSync(s.OPENCLAW_BIN)||(c.default.symlinkSync(s.QBOTCLAW_BIN,s.OPENCLAW_BIN),(0,a.log)(`\u5DF2\u521B\u5EFA\u8F6F\u94FE\u63A5: ${s.OPENCLAW_BIN} -> ${s.QBOTCLAW_BIN}`))}catch(n){(0,a.log)(`\u521B\u5EFA openclaw \u8F6F\u94FE\u63A5\u5931\u8D25: ${n.message}`)}if(await(0,f.stopWatchWorkspaceQuarantine)().catch(n=>{(0,a.log)(`[quarantine] stopWatchWorkspaceQuarantine \u5F02\u5E38: ${n.message}`)}),exports.installState={status:"success",message:"\u5B89\u88C5\u6210\u529F",endTime:new Date().toISOString()},(0,a.log)("\u5B89\u88C5\u6210\u529F"),(0,a.refreshClawVersion)(o),g(t,i,e,"\u5F00\u59CB\u914D\u7F6E\u5E76\u542F\u52A8 QBotClaw gateway..."),await N(r),e++,t.writable)try{t.end(JSON.stringify({status:"done",progress:100,message:"\u5B89\u88C5\u6210\u529F"})+`
5
+ `)}catch{}}catch(i){if(await(0,f.stopWatchWorkspaceQuarantine)().catch(()=>{}),exports.installState={status:"failed",message:i.message,endTime:new Date().toISOString()},(0,a.log)(`\u5B89\u88C5\u5931\u8D25: ${i.message}`),t&&t.writable)try{t.end(JSON.stringify({status:"failed",progress:0,message:i.message})+`
6
+ `)}catch{}}finally{exports.isInstalling=!1}})()}
package/dist/server.js CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";var B=exports&&exports.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.watchParentProcess=I;const R=B(require("http")),h=B(require("fs")),y=B(require("path")),l=require("./config"),n=require("./utils"),s=require("./reportLog"),v=require("./installer"),b=require("./version"),P=require("./state"),A=require("child_process"),C={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Max-Age":"86400"};function L(u){for(const[e,g]of Object.entries(C))u.setHeader(e,g)}exports.server=R.default.createServer(async(u,e)=>{const g=u.url||"";if(L(e),u.method==="OPTIONS"){e.writeHead(204,C),e.end();return}if(g==="/api/version"){let r="unknown";try{r=(await(0,n.execCommand)(`"${l.NODE_BIN}" -v`)).trim(),(0,s.log)(`[version] node \u7248\u672C: ${r}`)}catch(i){(0,s.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${i.message}`),r=`error: ${i.message}`}const o=await(0,n.getQBotClawVersion)()??"0.0.0";(0,s.log)(`[version] qbotclaw \u7248\u672C: ${o}`);let t="0.0.0";if(h.default.existsSync(l.MCPORTER_BIN))try{t=(await(0,n.execCommand)(`"${l.NODE_BIN}" "${l.MCPORTER_BIN}" --version`)).trim(),(0,s.log)(`[version] mcporter \u7248\u672C: ${t}`)}catch(i){(0,s.log)(`[version] \u83B7\u53D6 mcporter \u7248\u672C\u5931\u8D25: ${i.message}`),t=`error: ${i.message}`}let a="0.0.0";if(h.default.existsSync(l.PYTHON_BIN))try{a=(await(0,n.execCommand)(`"${l.PYTHON_BIN}" --version`)).trim(),(0,s.log)(`[version] python \u7248\u672C: ${a}`)}catch(i){(0,s.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${i.message}`),a=`error: ${i.message}`}(0,n.sendJSON)(e,200,{status:"\u6210\u529F",launcher:b.LAUNCHER_VERSION,node:r,qbotclaw:o,mcporter:t,python:a});return}if(g==="/api/port"){const r=exports.server.address(),o=r&&typeof r=="object"?r.port:null,t=(0,P.readState)();(0,n.sendJSON)(e,200,{status:"\u6210\u529F",launcher:o,qbotclaw:t.gatewayPort??2e3,mcpHttp:t.mcpHttpPort??l.DEFAULT_MCP_HTTP_PORT,mcpWs:t.mcpWsPort??8765});return}if(g==="/api/status"){const r=(0,P.readState)(),o=[];if(r.gatewayPid)try{process.kill(r.gatewayPid,0)}catch{o.push(`gateway \u8FDB\u7A0B (pid: ${r.gatewayPid}) \u5DF2\u9000\u51FA`)}else o.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const t=[{name:"gateway",port:r.gatewayPort},{name:"mcpHttp",port:r.mcpHttpPort},{name:"mcpWs",port:r.mcpWsPort}];for(const{name:a,port:i}of t){if(!i){o.push(`${a} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,P.isPortAvailable)(i)&&o.push(`${a} \u7AEF\u53E3 (${i}) \u65E0\u670D\u52A1\u76D1\u542C`)}o.length===0?(0,n.sendJSON)(e,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,n.sendJSON)(e,200,{ok:!1,message:o.join("\uFF1B")});return}if(g==="/api/restart"){try{const r=(0,P.readState)();if(r.gatewayPid)try{process.kill(r.gatewayPid,"SIGTERM"),(0,s.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${r.gatewayPid}`)}catch{(0,s.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${r.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:o,gatewayPort:t,mcpHttpPort:a,mcpWsPort:i,...f}=r;(0,P.writeState)(f),(0,s.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpHttpPort, mcpWsPort"),await(0,v.configAndRunQBotClaw)(),(0,s.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const p=(0,P.readState)(),c=exports.server.address(),d=c&&typeof c=="object"?c.port:null;(0,n.sendJSON)(e,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:d,qbotclaw:p.gatewayPort??2e3,mcpHttp:p.mcpHttpPort??l.DEFAULT_MCP_HTTP_PORT,mcpWs:p.mcpWsPort??8765})}catch(r){(0,s.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${r.message}`),(0,n.sendJSON)(e,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${r.message}`})}return}if(g.startsWith("/api/install")&&!g.startsWith("/api/install/")){if(v.installState.status==="downloading"){(0,n.sendJSON)(e,200,{ok:"downloading",message:"\u6B63\u5728\u5B89\u88C5\u4E2D..."});return}const o=new URL(g,"http://localhost").searchParams.get("version")||void 0;if(!o){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 version\uFF0C\u7528\u6CD5: GET /api/install?version=x.x.x"});return}e.writeHead(200,{...C,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,v.runInstall)(e,o);return}if(g.startsWith("/api/watch")){const o=new URL(g,"http://localhost").searchParams.get("ppid");if(!o||isNaN(Number(o))){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u6709\u6548\u7684 ppid \u53C2\u6570\uFF0C\u7528\u6CD5: GET /api/watch?ppid=12345"});return}const t=parseInt(o,10);try{process.kill(t,0)}catch{(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${t} \u4E0D\u5B58\u5728`});return}const a=(0,P.readState)();(0,P.writeState)({...a,ppid:t}),I(t),(0,n.sendJSON)(e,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${t}`});return}if(g==="/api/qbotclaw"&&u.method==="POST"){let r="";u.on("data",o=>{r+=o.toString()}),u.on("end",()=>{let o;try{const t=JSON.parse(r);if(!Array.isArray(t.args)||t.args.length===0){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u53C2\u6570 args \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"});return}o=t.args.map(a=>String(a))}catch{(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(!h.default.existsSync(l.QBOTCLAW_BIN)){(0,n.sendJSON)(e,404,{status:"\u5931\u8D25",message:`qbotclaw \u53EF\u6267\u884C\u6587\u4EF6\u4E0D\u5B58\u5728: ${l.QBOTCLAW_BIN}`});return}e.writeHead(200,{...C,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,v.runQBotClaw)(o,e).then(()=>{e.end(`
1
+ "use strict";var I=exports&&exports.__importDefault||function(p){return p&&p.__esModule?p:{default:p}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.watchParentProcess=W;const R=I(require("http")),h=I(require("fs")),y=I(require("path")),l=require("./config"),n=require("./utils"),a=require("./reportLog"),_=require("./installer"),J=require("./version"),P=require("./state"),A=require("child_process"),N={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Authorization, X-Requested-With","Access-Control-Max-Age":"86400"};function b(p){for(const[t,d]of Object.entries(N))p.setHeader(t,d)}exports.server=R.default.createServer(async(p,t)=>{const d=p.url||"";if(b(t),p.method==="OPTIONS"){t.writeHead(204,N),t.end();return}if(d==="/api/version"){let r="unknown";try{r=(await(0,n.execCommand)(`"${l.NODE_BIN}" -v`)).trim(),(0,a.log)(`[version] node \u7248\u672C: ${r}`)}catch(i){(0,a.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${i.message}`),r=`error: ${i.message}`}const o=await(0,n.getQBotClawVersion)()??"0.0.0";(0,a.log)(`[version] qbotclaw \u7248\u672C: ${o}`);let e="0.0.0";if(h.default.existsSync(l.MCPORTER_BIN))try{e=(await(0,n.execCommand)(`"${l.NODE_BIN}" "${l.MCPORTER_BIN}" --version`)).trim(),(0,a.log)(`[version] mcporter \u7248\u672C: ${e}`)}catch(i){(0,a.log)(`[version] \u83B7\u53D6 mcporter \u7248\u672C\u5931\u8D25: ${i.message}`),e=`error: ${i.message}`}let s="0.0.0";if(h.default.existsSync(l.PYTHON_BIN))try{s=(await(0,n.execCommand)(`"${l.PYTHON_BIN}" --version`)).trim(),(0,a.log)(`[version] python \u7248\u672C: ${s}`)}catch(i){(0,a.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${i.message}`),s=`error: ${i.message}`}(0,n.sendJSON)(t,200,{status:"\u6210\u529F",launcher:J.LAUNCHER_VERSION,node:r,qbotclaw:o,mcporter:e,python:s});return}if(d==="/api/port"){const r=exports.server.address(),o=r&&typeof r=="object"?r.port:null,e=(0,P.readState)();(0,n.sendJSON)(t,200,{status:"\u6210\u529F",launcher:o,qbotclaw:e.gatewayPort??2e3,mcpHttp:e.mcpHttpPort??l.DEFAULT_MCP_HTTP_PORT,mcpWs:e.mcpWsPort??8765});return}if(d==="/api/status"){const r=(0,P.readState)(),o=[];if(r.gatewayPid)try{process.kill(r.gatewayPid,0)}catch{o.push(`gateway \u8FDB\u7A0B (pid: ${r.gatewayPid}) \u5DF2\u9000\u51FA`)}else o.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const e=[{name:"gateway",port:r.gatewayPort},{name:"mcpHttp",port:r.mcpHttpPort},{name:"mcpWs",port:r.mcpWsPort}];for(const{name:s,port:i}of e){if(!i){o.push(`${s} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,P.isPortAvailable)(i)&&o.push(`${s} \u7AEF\u53E3 (${i}) \u65E0\u670D\u52A1\u76D1\u542C`)}o.length===0?(0,n.sendJSON)(t,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,n.sendJSON)(t,200,{ok:!1,message:o.join("\uFF1B")});return}if(d==="/api/restart"){try{const r=(0,P.readState)();if(r.gatewayPid)try{process.kill(r.gatewayPid,"SIGTERM"),(0,a.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${r.gatewayPid}`)}catch{(0,a.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${r.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:o,gatewayPort:e,mcpHttpPort:s,mcpWsPort:i,...f}=r;(0,P.writeState)(f),(0,a.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpHttpPort, mcpWsPort"),await(0,_.configAndRunQBotClaw)(),(0,a.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const g=(0,P.readState)(),c=exports.server.address(),u=c&&typeof c=="object"?c.port:null;(0,n.sendJSON)(t,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:u,qbotclaw:g.gatewayPort??2e3,mcpHttp:g.mcpHttpPort??l.DEFAULT_MCP_HTTP_PORT,mcpWs:g.mcpWsPort??8765})}catch(r){(0,a.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${r.message}`),(0,n.sendJSON)(t,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${r.message}`})}return}if(d==="/api/wechat/history"){try{if(!h.default.existsSync(l.SESSIONS_FILE)){(0,n.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const r=JSON.parse(h.default.readFileSync(l.SESSIONS_FILE,"utf-8"));let o=null,e=0;for(const[f,g]of Object.entries(r))if(f.includes("openclaw-weixin")){const u=g.updatedAt??0;u>e&&(e=u,o=f)}if(!o){(0,n.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const i=o.split(":").slice(4).join(":");(0,n.sendJSON)(t,200,{ok:!0,sessionKey:i,message:"\u83B7\u53D6\u6210\u529F"})}catch(r){(0,a.log)(`[wechat/history] \u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${r.message}`),(0,n.sendJSON)(t,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${r.message}`})}return}if(d==="/api/installing"){(0,n.sendJSON)(t,200,{installing:_.isInstalling});return}if(d==="/api/install"||d.startsWith("/api/install?")){if(_.installState.status==="downloading"){(0,n.sendJSON)(t,200,{ok:"downloading",message:"\u6B63\u5728\u5B89\u88C5\u4E2D..."});return}const r=new URL(d,"http://localhost"),o=r.searchParams.get("version")||void 0,e=r.searchParams.get("overrideConfig")==="true";if(!o){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 version\uFF0C\u7528\u6CD5: GET /api/install?version=x.x.x"});return}t.writeHead(200,{...N,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,_.runInstall)(t,o,e);return}if(d.startsWith("/api/watch")){const o=new URL(d,"http://localhost").searchParams.get("ppid");if(!o||isNaN(Number(o))){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u6709\u6548\u7684 ppid \u53C2\u6570\uFF0C\u7528\u6CD5: GET /api/watch?ppid=12345"});return}const e=parseInt(o,10);try{process.kill(e,0)}catch{(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${e} \u4E0D\u5B58\u5728`});return}const s=(0,P.readState)();(0,P.writeState)({...s,ppid:e}),W(e),(0,n.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${e}`});return}if(d==="/api/qbotclaw"&&p.method==="POST"){let r="";p.on("data",o=>{r+=o.toString()}),p.on("end",()=>{let o;try{const e=JSON.parse(r);if(!Array.isArray(e.args)||e.args.length===0){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u53C2\u6570 args \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"});return}o=e.args.map(s=>String(s))}catch{(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(!h.default.existsSync(l.QBOTCLAW_BIN)){(0,n.sendJSON)(t,404,{status:"\u5931\u8D25",message:`qbotclaw \u53EF\u6267\u884C\u6587\u4EF6\u4E0D\u5B58\u5728: ${l.QBOTCLAW_BIN}`});return}t.writeHead(200,{...N,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,_.runQBotClaw)(o,t).then(()=>{t.end(`
2
2
  [\u6267\u884C\u6210\u529F]
3
- `)}).catch(t=>{e.end(`
4
- [\u542F\u52A8\u5931\u8D25: ${t.message}]
5
- `)})});return}if(g.startsWith("/api/uninstall")){const o=new URL(g,"http://localhost").searchParams.get("keepWorkspace")==="true";e.writeHead(200,{...C,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const t=(a,i,f)=>{if(e.writable)try{e.write(JSON.stringify({status:a,file:i,msg:f})+`
6
- `)}catch{}};try{t("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const a=(0,P.readState)();if(a.gatewayPid)try{process.kill(a.gatewayPid,"SIGTERM"),(0,s.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${a.gatewayPid}`),t("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${a.gatewayPid}`)}catch{(0,s.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${a.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),t("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${a.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else t("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");t("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${l.NPM_PACKAGE_NAME}...`);try{await new Promise((f,p)=>{const c=(0,A.spawn)(l.NPM_BIN,["--userconfig",l.NPM_RC,"uninstall","-g",l.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${l.NODE_BIN_DIR}:${process.env.PATH}`}});c.stdout?.on("data",d=>{(0,s.log)(`[uninstall] npm: ${d.toString().trim()}`)}),c.stderr?.on("data",d=>{(0,s.log)(`[uninstall] npm stderr: ${d.toString().trim()}`)}),c.on("close",d=>{d===0?f():p(new Error(`npm uninstall \u9000\u51FA\u7801: ${d}`))}),c.on("error",d=>p(d))}),(0,s.log)(`[uninstall] npm uninstall -g ${l.NPM_PACKAGE_NAME} \u6210\u529F`),t("\u6210\u529F","",`npm uninstall -g ${l.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(f){(0,s.log)(`[uninstall] npm uninstall \u5931\u8D25: ${f.message}`),t("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${f.message}`)}t("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${l.QBOT_CLAW_DIR}...`);const i=[];if(h.default.existsSync(l.QBOT_CLAW_DIR)){const f=h.default.readdirSync(l.QBOT_CLAW_DIR);for(const p of f){const c=y.default.join(l.QBOT_CLAW_DIR,p);if(o&&p==="workspace"){t("\u6210\u529F",c,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{h.default.statSync(c).isDirectory()?h.default.rmSync(c,{recursive:!0,force:!0}):h.default.unlinkSync(c),t("\u6210\u529F",c,"\u5DF2\u5220\u9664")}catch(d){(0,s.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${c} - ${d.message}`),t("\u5931\u8D25",c,`\u5220\u9664\u5931\u8D25: ${d.message}`),i.push(c)}}if(i.length>0){t("\u6210\u529F","",`${i.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const p of i)try{(0,A.execSync)(`rm -rf "${p}"`),(0,s.log)(`[uninstall] rm -rf \u91CD\u8BD5\u6210\u529F: ${p}`),t("\u6210\u529F",p,"rm \u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(c){(0,s.log)(`[uninstall] rm -rf \u91CD\u8BD5\u4E5F\u5931\u8D25: ${p} - ${c.message}`),t("\u5931\u8D25",p,`rm \u91CD\u8BD5\u4E5F\u5931\u8D25: ${c.message}`)}}if(o)t("\u6210\u529F",l.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{h.default.rmSync(l.QBOT_CLAW_DIR,{recursive:!0,force:!0}),t("\u6210\u529F",l.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(p){(0,s.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${p.message}`);try{(0,A.execSync)(`rm -rf "${l.QBOT_CLAW_DIR}"`),t("\u6210\u529F",l.QBOT_CLAW_DIR,"rm \u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(c){t("\u5931\u8D25",l.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.message}`)}}}else t("\u6210\u529F",l.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");t("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(a){(0,s.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${a.message}`),t("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${a.message}`)}e.end(),setTimeout(()=>{(0,s.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(g.startsWith("/api/reveal")){const o=new URL(g,"http://localhost").searchParams.get("path");if(!o){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 path\uFF08\u9700 Base64 \u7F16\u7801\uFF09\uFF0C\u7528\u6CD5: GET /api/reveal?path=<base64\u7F16\u7801\u7684\u6587\u4EF6\u7EDD\u5BF9\u8DEF\u5F84>"});return}let t;try{t=Buffer.from(o,"base64").toString("utf-8")}catch{(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"path \u53C2\u6570 Base64 \u89E3\u7801\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u4F20\u5165\u5408\u6CD5\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32"});return}if(!t||t.trim()===""){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}if(t.includes("\0")){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u8DEF\u5F84\u5305\u542B\u975E\u6CD5\u5B57\u7B26"});return}const a=y.default.resolve(t),i=process.platform==="win32"?["C:\\Windows","C:\\Program Files","C:\\Program Files (x86)","C:\\ProgramData"]:["/etc","/var","/usr","/bin","/sbin","/boot","/root","/sys","/proc","/dev","/lib","/lib64"],f=a.toLowerCase();for(const m of i)if(f===m.toLowerCase()||f.startsWith(m.toLowerCase()+y.default.sep)){(0,s.log)(`[reveal] \u8BBF\u95EE\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55\u88AB\u62D2\u7EDD: ${a}`),(0,n.sendJSON)(e,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55"});return}const p=y.default.basename(l.QBOT_CLAW_DIR),c=a.split(y.default.sep);for(const m of c)if(m.startsWith(".")&&m!=="."&&m!==".."&&m!==p){(0,s.log)(`[reveal] \u8BBF\u95EE\u9690\u85CF\u6587\u4EF6/\u76EE\u5F55\u88AB\u62D2\u7EDD: ${a}\uFF08\u5339\u914D\u6BB5: ${m}\uFF09`),(0,n.sendJSON)(e,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u9690\u85CF\u6587\u4EF6\u6216\u76EE\u5F55"});return}if(!h.default.existsSync(a)){(0,n.sendJSON)(e,404,{status:"\u5931\u8D25",message:`\u6587\u4EF6\u6216\u76EE\u5F55\u4E0D\u5B58\u5728: ${a}`});return}let d;try{d=h.default.realpathSync(a)}catch{(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u65E0\u6CD5\u89E3\u6790\u6587\u4EF6\u771F\u5B9E\u8DEF\u5F84"});return}if(d!==a){const m=d.toLowerCase();for(const w of i)if(m===w.toLowerCase()||m.startsWith(w.toLowerCase()+y.default.sep)){(0,s.log)(`[reveal] \u7B26\u53F7\u94FE\u63A5\u6307\u5411\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55\u88AB\u62D2\u7EDD: ${a} -> ${d}`),(0,n.sendJSON)(e,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55"});return}const $=d.split(y.default.sep);for(const w of $)if(w.startsWith(".")&&w!=="."&&w!==".."&&w!==p){(0,s.log)(`[reveal] \u7B26\u53F7\u94FE\u63A5\u6307\u5411\u9690\u85CF\u6587\u4EF6/\u76EE\u5F55\u88AB\u62D2\u7EDD: ${a} -> ${d}\uFF08\u5339\u914D\u6BB5: ${w}\uFF09`),(0,n.sendJSON)(e,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u9690\u85CF\u6587\u4EF6\u6216\u76EE\u5F55"});return}}const E=process.platform;let N,T;E==="darwin"?(N="open",T=["-R",a]):E==="win32"?(N="explorer",T=[`/select,${a}`]):(N="xdg-open",T=[y.default.dirname(a)]);try{await new Promise((m,$)=>{const w=(0,A.spawn)(N,T,{stdio:"ignore"}),W=setTimeout(()=>{w.kill(),$(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);w.on("close",_=>{clearTimeout(W),_===0||_===1?m():$(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${_}`))}),w.on("error",_=>{clearTimeout(W),$(_)})}),(0,s.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${a}`),(0,n.sendJSON)(e,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${a}`})}catch(m){(0,s.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`),(0,n.sendJSON)(e,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`})}return}(0,n.sendJSON)(e,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})});let S=null,O=null;function I(u){if(!u)return;if(S&&O===u){(0,s.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${u}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}S?((0,s.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${O}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${u}`),clearInterval(S),S=null,O=null):(0,s.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${u}`);const e=setInterval(()=>{try{process.kill(u,0)}catch{(0,s.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${u} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(e),S=null,O=null;const g=(0,P.readState)();if(g.gatewayPid)try{process.kill(g.gatewayPid,"SIGTERM"),(0,s.log)(`[watchParentProcess] \u5DF2\u53D1\u9001 SIGTERM \u7ED9 qbotclaw \u8FDB\u7A0B pid: ${g.gatewayPid}`)}catch{(0,s.log)(`[watchParentProcess] qbotclaw \u8FDB\u7A0B ${g.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}(0,P.clearState)(),(0,s.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,s.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,s.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);e.unref(),S=e,O=u}
3
+ `)}).catch(e=>{t.end(`
4
+ [\u542F\u52A8\u5931\u8D25: ${e.message}]
5
+ `)})});return}if(d.startsWith("/api/uninstall")){const o=new URL(d,"http://localhost").searchParams.get("keepWorkspace")==="true";t.writeHead(200,{...N,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const e=(s,i,f)=>{if(t.writable)try{t.write(JSON.stringify({status:s,file:i,msg:f})+`
6
+ `)}catch{}};try{e("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const s=(0,P.readState)();if(s.gatewayPid)try{process.kill(s.gatewayPid,"SIGTERM"),(0,a.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${s.gatewayPid}`),e("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${s.gatewayPid}`)}catch{(0,a.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${s.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),e("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${s.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else e("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");e("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${l.NPM_PACKAGE_NAME}...`);try{await new Promise((f,g)=>{const c=(0,A.spawn)(l.NPM_BIN,["--userconfig",l.NPM_RC,"uninstall","-g",l.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${l.NODE_BIN_DIR}:${process.env.PATH}`}});c.stdout?.on("data",u=>{(0,a.log)(`[uninstall] npm: ${u.toString().trim()}`)}),c.stderr?.on("data",u=>{(0,a.log)(`[uninstall] npm stderr: ${u.toString().trim()}`)}),c.on("close",u=>{u===0?f():g(new Error(`npm uninstall \u9000\u51FA\u7801: ${u}`))}),c.on("error",u=>g(u))}),(0,a.log)(`[uninstall] npm uninstall -g ${l.NPM_PACKAGE_NAME} \u6210\u529F`),e("\u6210\u529F","",`npm uninstall -g ${l.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(f){(0,a.log)(`[uninstall] npm uninstall \u5931\u8D25: ${f.message}`),e("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${f.message}`)}e("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${l.QBOT_CLAW_DIR}...`);const i=[];if(h.default.existsSync(l.QBOT_CLAW_DIR)){const f=h.default.readdirSync(l.QBOT_CLAW_DIR);for(const g of f){const c=y.default.join(l.QBOT_CLAW_DIR,g);if(o&&g==="workspace"){e("\u6210\u529F",c,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{h.default.statSync(c).isDirectory()?h.default.rmSync(c,{recursive:!0,force:!0}):h.default.unlinkSync(c),e("\u6210\u529F",c,"\u5DF2\u5220\u9664")}catch(u){(0,a.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${c} - ${u.message}`),e("\u5931\u8D25",c,`\u5220\u9664\u5931\u8D25: ${u.message}`),i.push(c)}}if(i.length>0){e("\u6210\u529F","",`${i.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const g of i)try{(0,A.execSync)(`rm -rf "${g}"`),(0,a.log)(`[uninstall] rm -rf \u91CD\u8BD5\u6210\u529F: ${g}`),e("\u6210\u529F",g,"rm \u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(c){(0,a.log)(`[uninstall] rm -rf \u91CD\u8BD5\u4E5F\u5931\u8D25: ${g} - ${c.message}`),e("\u5931\u8D25",g,`rm \u91CD\u8BD5\u4E5F\u5931\u8D25: ${c.message}`)}}if(o)e("\u6210\u529F",l.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{h.default.rmSync(l.QBOT_CLAW_DIR,{recursive:!0,force:!0}),e("\u6210\u529F",l.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(g){(0,a.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${g.message}`);try{(0,A.execSync)(`rm -rf "${l.QBOT_CLAW_DIR}"`),e("\u6210\u529F",l.QBOT_CLAW_DIR,"rm \u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(c){e("\u5931\u8D25",l.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.message}`)}}}else e("\u6210\u529F",l.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");e("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(s){(0,a.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${s.message}`),e("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${s.message}`)}t.end(),setTimeout(()=>{(0,a.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(d.startsWith("/api/reveal")){const o=new URL(d,"http://localhost").searchParams.get("path");if(!o){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 path\uFF08\u9700 Base64 \u7F16\u7801\uFF09\uFF0C\u7528\u6CD5: GET /api/reveal?path=<base64\u7F16\u7801\u7684\u6587\u4EF6\u7EDD\u5BF9\u8DEF\u5F84>"});return}let e;try{e=Buffer.from(o,"base64").toString("utf-8")}catch{(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"path \u53C2\u6570 Base64 \u89E3\u7801\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u4F20\u5165\u5408\u6CD5\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32"});return}if(!e||e.trim()===""){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}if(e.includes("\0")){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u8DEF\u5F84\u5305\u542B\u975E\u6CD5\u5B57\u7B26"});return}const s=y.default.resolve(e),i=process.platform==="win32"?["C:\\Windows","C:\\Program Files","C:\\Program Files (x86)","C:\\ProgramData"]:["/etc","/var","/usr","/bin","/sbin","/boot","/root","/sys","/proc","/dev","/lib","/lib64"],f=s.toLowerCase();for(const m of i)if(f===m.toLowerCase()||f.startsWith(m.toLowerCase()+y.default.sep)){(0,a.log)(`[reveal] \u8BBF\u95EE\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55\u88AB\u62D2\u7EDD: ${s}`),(0,n.sendJSON)(t,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55"});return}const g=y.default.basename(l.QBOT_CLAW_DIR),c=s.split(y.default.sep);for(const m of c)if(m.startsWith(".")&&m!=="."&&m!==".."&&m!==g){(0,a.log)(`[reveal] \u8BBF\u95EE\u9690\u85CF\u6587\u4EF6/\u76EE\u5F55\u88AB\u62D2\u7EDD: ${s}\uFF08\u5339\u914D\u6BB5: ${m}\uFF09`),(0,n.sendJSON)(t,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u9690\u85CF\u6587\u4EF6\u6216\u76EE\u5F55"});return}if(!h.default.existsSync(s)){(0,n.sendJSON)(t,404,{status:"\u5931\u8D25",message:`\u6587\u4EF6\u6216\u76EE\u5F55\u4E0D\u5B58\u5728: ${s}`});return}let u;try{u=h.default.realpathSync(s)}catch{(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"\u65E0\u6CD5\u89E3\u6790\u6587\u4EF6\u771F\u5B9E\u8DEF\u5F84"});return}if(u!==s){const m=u.toLowerCase();for(const w of i)if(m===w.toLowerCase()||m.startsWith(w.toLowerCase()+y.default.sep)){(0,a.log)(`[reveal] \u7B26\u53F7\u94FE\u63A5\u6307\u5411\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55\u88AB\u62D2\u7EDD: ${s} -> ${u}`),(0,n.sendJSON)(t,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u7CFB\u7EDF\u654F\u611F\u76EE\u5F55"});return}const $=u.split(y.default.sep);for(const w of $)if(w.startsWith(".")&&w!=="."&&w!==".."&&w!==g){(0,a.log)(`[reveal] \u7B26\u53F7\u94FE\u63A5\u6307\u5411\u9690\u85CF\u6587\u4EF6/\u76EE\u5F55\u88AB\u62D2\u7EDD: ${s} -> ${u}\uFF08\u5339\u914D\u6BB5: ${w}\uFF09`),(0,n.sendJSON)(t,403,{status:"\u5931\u8D25",message:"\u7981\u6B62\u8BBF\u95EE\u9690\u85CF\u6587\u4EF6\u6216\u76EE\u5F55"});return}}const E=process.platform;let T,v;E==="darwin"?(T="open",v=["-R",s]):E==="win32"?(T="explorer",v=[`/select,${s}`]):(T="xdg-open",v=[y.default.dirname(s)]);try{await new Promise((m,$)=>{const w=(0,A.spawn)(T,v,{stdio:"ignore"}),B=setTimeout(()=>{w.kill(),$(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);w.on("close",O=>{clearTimeout(B),O===0||O===1?m():$(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${O}`))}),w.on("error",O=>{clearTimeout(B),$(O)})}),(0,a.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${s}`),(0,n.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${s}`})}catch(m){(0,a.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`),(0,n.sendJSON)(t,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`})}return}(0,n.sendJSON)(t,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})});let S=null,C=null;function W(p){if(!p)return;if(S&&C===p){(0,a.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${p}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}S?((0,a.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${C}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${p}`),clearInterval(S),S=null,C=null):(0,a.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${p}`);const t=setInterval(()=>{try{process.kill(p,0)}catch{(0,a.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${p} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(t),S=null,C=null;const d=(0,P.readState)();if(d.gatewayPid)try{process.kill(d.gatewayPid,"SIGTERM"),(0,a.log)(`[watchParentProcess] \u5DF2\u53D1\u9001 SIGTERM \u7ED9 qbotclaw \u8FDB\u7A0B pid: ${d.gatewayPid}`)}catch{(0,a.log)(`[watchParentProcess] qbotclaw \u8FDB\u7A0B ${d.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}(0,P.clearState)(),(0,a.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,a.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,a.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);t.unref(),S=t,C=p}
package/dist/service.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";var l=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.startService=q,exports.stopService=h;const f=l(require("fs")),S=l(require("http")),g=require("crypto"),p=require("./server"),e=require("./state"),w=require("./config"),u=require("./version"),y=require("./installer"),_=require("./utils"),o=require("./reportLog");let c=null;function v(t){return new Promise(r=>{const s=S.default.get(`http://127.0.0.1:${t}/api/version`,a=>{let n="";a.on("data",i=>{n+=i.toString()}),a.on("end",()=>{try{const i=JSON.parse(n);r(i.launcher??null)}catch{r(null)}})});s.on("error",()=>r(null)),s.setTimeout(3e3,()=>{s.destroy(),r(null)})})}async function k(){const t=(0,e.readState)();if(!t.pid||!t.port)return null;try{process.kill(t.pid,0)}catch{return(0,e.clearState)(),null}if(await(0,e.isPortAvailable)(t.port))return(0,o.log)("\u7AEF\u53E3\u672A\u88AB\u5360\u7528\uFF0C\u8BF4\u660E\u72B6\u6001\u6587\u4EF6\u8FC7\u671F"),(0,e.clearState)(),null;const s=await v(t.port);if((0,o.log)(`[service] \u68C0\u6D4B\u5230\u6B63\u5728\u8FD0\u884C\u7684\u670D\u52A1\u7248\u672C: ${s??"unknown"}\uFF0C\u5F53\u524D\u7248\u672C: ${u.LAUNCHER_VERSION}`),s===u.LAUNCHER_VERSION)return(0,o.log)(`[service] \u7248\u672C\u4E00\u81F4\uFF0C\u590D\u7528\u5DF2\u6709\u670D\u52A1 (pid: ${t.pid}, port: ${t.port})`),!1;(0,o.log)(`[service] \u7248\u672C\u4E0D\u4E00\u81F4 (\u8FD0\u884C\u4E2D: ${s??"unknown"}, \u5F53\u524D: ${u.LAUNCHER_VERSION})\uFF0C\u6740\u6389\u65E7\u8FDB\u7A0B pid: ${t.pid}\uFF0C\u91CD\u65B0\u542F\u52A8`);try{process.kill(t.pid,"SIGTERM")}catch{}return(0,e.clearState)(),!0}async function q(t,r){if(await k()===!1){const n=(0,e.readState)();c=n.token??null,process.stdout.write(JSON.stringify({state:"success",pid:n.pid,port:n.port,token:c})+`
2
2
  `),process.stdout.uncork();return}const a=await(0,e.findAvailablePort)();c=(0,g.randomUUID)(),p.server.listen(a,"127.0.0.1",()=>{if((0,e.writeState)({pid:process.pid,port:a,token:c,...t?{ppid:t}:{}}),process.stdout.write(JSON.stringify({state:"success",pid:process.pid,port:a,token:c})+`
3
- `),process.stdout.uncork(),(0,p.watchParentProcess)(t),!f.default.existsSync(w.QBOTCLAW_BIN)){(0,o.log)("[service] qbotclaw \u672A\u5B89\u88C5\uFF0C\u4E0D\u81EA\u52A8\u542F\u52A8");return}(0,_.getQBotClawVersion)().then(n=>{const i=(0,e.readState)();if(n!==r){(0,o.log)(`[service] qbotclaw \u672C\u5730\u7248\u672C (${n??"unknown"}) \u4E0E\u671F\u671B\u7248\u672C (${r}) \u4E0D\u4E00\u81F4\uFF0C\u505C\u6B62\u5F53\u524D qbotclaw \u8FDB\u7A0B`),(0,e.stopGateway)();return}else i.gatewayPid&&i.gatewayPort?(0,o.log)(`[service] qbotclaw \u5DF2\u5728\u8FD0\u884C\uFF0Cpid: ${i.gatewayPid}, port: ${i.gatewayPort}`):((0,o.log)("[service] \u68C0\u6D4B\u5230 qbotclaw\uFF0C\u7248\u672C\u5339\u914D\uFF0C\u81EA\u52A8\u542F\u52A8 gateway..."),(0,y.configAndRunQBotClaw)().catch(d=>{(0,o.log)(`[service] \u81EA\u52A8\u542F\u52A8 gateway \u5931\u8D25: ${d.message}`)}))})}),process.on("SIGTERM",()=>{(0,e.clearState)(),(0,o.flushLogs)().finally(()=>{process.exit(0)})})}function h(){const t=(0,e.readState)();if(!t.pid){process.stdout.write(JSON.stringify({state:"err",pid:0,port:0})+`
3
+ `),process.stdout.uncork(),(0,p.watchParentProcess)(t),!f.default.existsSync(w.QBOTCLAW_BIN)){(0,o.log)("[service] qbotclaw \u672A\u5B89\u88C5\uFF0C\u4E0D\u81EA\u52A8\u542F\u52A8");return}(0,_.getQBotClawVersion)().then(n=>{const i=(0,e.readState)();if(n!==r){(0,o.log)(`[service] qbotclaw \u672C\u5730\u7248\u672C (${n??"unknown"}) \u4E0E\u671F\u671B\u7248\u672C (${r}) \u4E0D\u4E00\u81F4\uFF0C\u505C\u6B62\u5F53\u524D qbotclaw \u8FDB\u7A0B`),(0,e.stopGateway)();return}else i.gatewayPid&&i.gatewayPort?(0,o.log)(`[service] qbotclaw \u5DF2\u5728\u8FD0\u884C\uFF0Cpid: ${i.gatewayPid}, port: ${i.gatewayPort}`):((0,o.log)("[service] \u68C0\u6D4B\u5230 qbotclaw\uFF0C\u7248\u672C\u5339\u914D\uFF0C\u81EA\u52A8\u542F\u52A8 gateway..."),(0,y.configAndRunQBotClaw)().catch(d=>{(0,o.log)(`[service] \u81EA\u52A8\u542F\u52A8 gateway \u5931\u8D25: ${d.message}`)}))})}),process.on("SIGTERM",()=>{(0,e.stopGateway)(),(0,e.clearState)(),(0,o.flushLogs)().finally(()=>{process.exit(0)})})}function h(){const t=(0,e.readState)();if(!t.pid){process.stdout.write(JSON.stringify({state:"err",pid:0,port:0})+`
4
4
  `),process.stdout.uncork();return}try{process.kill(t.pid,"SIGTERM");const r=t.pid,s=t.port??0;(0,e.clearState)(),process.stdout.write(JSON.stringify({state:"success",pid:r,port:s})+`
5
5
  `),process.stdout.uncork()}catch(r){r.code==="ESRCH"&&(0,e.clearState)(),process.stdout.write(JSON.stringify({state:"err",pid:0,port:0})+`
6
6
  `),process.stdout.uncork()}}
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.9.53";
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.9.55";
@@ -26,7 +26,9 @@
26
26
  "README.md",
27
27
  "LICENSE"
28
28
  ],
29
- "scripts": {},
29
+ "scripts": {
30
+ "install": "echo 'Using prebuilt binary'"
31
+ },
30
32
  "engines": {
31
33
  "node": ">= 10.0.0"
32
34
  },
@@ -11,6 +11,7 @@
11
11
  "build/Release/xattr.node"
12
12
  ],
13
13
  "scripts": {
14
+ "install": "echo 'Using prebuilt binary'",
14
15
  "test": "standard && mocha && ts-readme-generator --check",
15
16
  "lint": "standard"
16
17
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qqbrowser/qbot-claw-launcher",
3
- "version": "0.9.53",
3
+ "version": "0.9.55",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "scripts": {
18
18
  "build": "node scripts/inject-version.js && tsc && node scripts/obfuscate.js && chmod +x dist/index.js",
19
- "prepack": "bash scripts/build-fs-xattr.sh && bash scripts/build-parcel-watcher.sh && rm -rf node_modules/fs-xattr && cp -r fs-xattr node_modules/fs-xattr && rm -rf node_modules/@parcel/watcher && mkdir -p node_modules/@parcel && cp -r parcel-watcher node_modules/@parcel/watcher && bash scripts/verify-universal-binary.sh",
19
+ "prepack": "bash scripts/build-fs-xattr.sh && bash scripts/build-parcel-watcher.sh && rm -rf node_modules/fs-xattr && cp -r fs-xattr node_modules/fs-xattr && rm -rf node_modules/@parcel/watcher && mkdir -p node_modules/@parcel && cp -r parcel-watcher node_modules/@parcel/watcher && bash scripts/clean-native-sources.sh && bash scripts/verify-universal-binary.sh",
20
20
  "start": "node dist/index.js",
21
21
  "dev": "ts-node src/index.ts",
22
22
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017-present Devon Govett
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,136 +0,0 @@
1
- # @parcel/watcher
2
-
3
- A native C++ Node module for querying and subscribing to filesystem events. Used by [Parcel 2](https://github.com/parcel-bundler/parcel).
4
-
5
- ## Features
6
-
7
- - **Watch** - subscribe to realtime recursive directory change notifications when files or directories are created, updated, or deleted.
8
- - **Query** - performantly query for historical change events in a directory, even when your program is not running.
9
- - **Native** - implemented in C++ for performance and low-level integration with the operating system.
10
- - **Cross platform** - includes backends for macOS, Linux, Windows, FreeBSD, and Watchman.
11
- - **Performant** - events are throttled in C++ so the JavaScript thread is not overwhelmed during large filesystem changes (e.g. `git checkout` or `npm install`).
12
- - **Scalable** - tens of thousands of files can be watched or queried at once with good performance.
13
-
14
- ## Example
15
-
16
- ```javascript
17
- const watcher = require('@parcel/watcher');
18
- const path = require('path');
19
-
20
- // Subscribe to events
21
- let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
22
- console.log(events);
23
- });
24
-
25
- // later on...
26
- await subscription.unsubscribe();
27
-
28
- // Get events since some saved snapshot in the past
29
- let snapshotPath = path.join(process.cwd(), 'snapshot.txt');
30
- let events = await watcher.getEventsSince(process.cwd(), snapshotPath);
31
-
32
- // Save a snapshot for later
33
- await watcher.writeSnapshot(process.cwd(), snapshotPath);
34
- ```
35
-
36
- ## Watching
37
-
38
- `@parcel/watcher` supports subscribing to realtime notifications of changes in a directory. It works recursively, so changes in sub-directories will also be emitted.
39
-
40
- Events are throttled and coalesced for performance during large changes like `git checkout` or `npm install`, and a single notification will be emitted with all of the events at the end.
41
-
42
- Only one notification will be emitted per file. For example, if a file was both created and updated since the last event, you'll get only a `create` event. If a file is both created and deleted, you will not be notifed of that file. Renames cause two events: a `delete` for the old name, and a `create` for the new name.
43
-
44
- ```javascript
45
- let subscription = await watcher.subscribe(process.cwd(), (err, events) => {
46
- console.log(events);
47
- });
48
- ```
49
-
50
- Events have two properties:
51
-
52
- - `type` - the event type: `create`, `update`, or `delete`.
53
- - `path` - the absolute path to the file or directory.
54
-
55
- To unsubscribe from change notifications, call the `unsubscribe` method on the returned subscription object.
56
-
57
- ```javascript
58
- await subscription.unsubscribe();
59
- ```
60
-
61
- `@parcel/watcher` has the following watcher backends, listed in priority order:
62
-
63
- - [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
64
- - [Watchman](https://facebook.github.io/watchman/) if installed
65
- - [inotify](http://man7.org/linux/man-pages/man7/inotify.7.html) on Linux
66
- - [ReadDirectoryChangesW](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v%3Dvs.85%29.aspx) on Windows
67
- - [kqueue](https://man.freebsd.org/cgi/man.cgi?kqueue) on FreeBSD, or as an alternative to FSEvents on macOS
68
-
69
- You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
70
-
71
- ## Querying
72
-
73
- `@parcel/watcher` also supports querying for historical changes made in a directory, even when your program is not running. This makes it easy to invalidate a cache and re-build only the files that have changed, for example. It can be **significantly** faster than traversing the entire filesystem to determine what files changed, depending on the platform.
74
-
75
- In order to query for historical changes, you first need a previous snapshot to compare to. This can be saved to a file with the `writeSnapshot` function, e.g. just before your program exits.
76
-
77
- ```javascript
78
- await watcher.writeSnapshot(dirPath, snapshotPath);
79
- ```
80
-
81
- When your program starts up, you can query for changes that have occurred since that snapshot using the `getEventsSince` function.
82
-
83
- ```javascript
84
- let events = await watcher.getEventsSince(dirPath, snapshotPath);
85
- ```
86
-
87
- The events returned are exactly the same as the events that would be passed to the `subscribe` callback (see above).
88
-
89
- `@parcel/watcher` has the following watcher backends, listed in priority order:
90
-
91
- - [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) on macOS
92
- - [Watchman](https://facebook.github.io/watchman/) if installed
93
- - [fts](http://man7.org/linux/man-pages/man3/fts.3.html) (brute force) on Linux and FreeBSD
94
- - [FindFirstFile](https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-findfirstfilea) (brute force) on Windows
95
-
96
- The FSEvents (macOS) and Watchman backends are significantly more performant than the brute force backends used by default on Linux and Windows, for example returning results in miliseconds instead of seconds for large directory trees. This is because a background daemon monitoring filesystem changes on those platforms allows us to query cached data rather than traversing the filesystem manually (brute force).
97
-
98
- macOS has good performance with FSEvents by default. For the best performance on other platforms, install [Watchman](https://facebook.github.io/watchman/) and it will be used by `@parcel/watcher` automatically.
99
-
100
- You can specify the exact backend you wish to use by passing the `backend` option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
101
-
102
- ## Options
103
-
104
- All of the APIs in `@parcel/watcher` support the following options, which are passed as an object as the last function argument.
105
-
106
- - `ignore` - an array of paths or glob patterns to ignore. uses [`is-glob`](https://github.com/micromatch/is-glob) to distinguish paths from globs. glob patterns are parsed with [`picomatch`](https://github.com/micromatch/picomatch) (see [features](https://github.com/micromatch/picomatch#globbing-features)).
107
- - paths can be relative or absolute and can either be files or directories. No events will be emitted about these files or directories or their children.
108
- - glob patterns match on relative paths from the root that is watched. No events will be emitted for matching paths.
109
- - `backend` - the name of an explicitly chosen backend to use. Allowed options are `"fs-events"`, `"watchman"`, `"inotify"`, `"kqueue"`, `"windows"`, or `"brute-force"` (only for querying). If the specified backend is not available on the current platform, the default backend will be used instead.
110
-
111
- ## WASM
112
-
113
- The `@parcel/watcher-wasm` package can be used in place of `@parcel/watcher` on unsupported platforms. It relies on the Node `fs` module, so in non-Node environments such as browsers, an `fs` polyfill will be needed.
114
-
115
- **Note**: the WASM implementation is significantly less efficient than the native implementations because it must crawl the file system to watch each directory individually. Use the native `@parcel/watcher` package wherever possible.
116
-
117
- ```js
118
- import {subscribe} from '@parcel/watcher-wasm';
119
-
120
- // Use the module as documented above.
121
- subscribe(/* ... */);
122
- ```
123
-
124
- ## Who is using this?
125
-
126
- - [Parcel 2](https://parceljs.org/)
127
- - [VSCode](https://code.visualstudio.com/updates/v1_62#_file-watching-changes)
128
- - [Tailwind CSS Intellisense](https://github.com/tailwindlabs/tailwindcss-intellisense)
129
- - [Gatsby Cloud](https://twitter.com/chatsidhartha/status/1435647412828196867)
130
- - [Nx](https://nx.dev)
131
- - [Nuxt](https://nuxt.com)
132
- - [Meteor](https://github.com/meteor/meteor)
133
-
134
- ## License
135
-
136
- MIT
@@ -1,48 +0,0 @@
1
- // @flow
2
- declare type FilePath = string;
3
- declare type GlobPattern = string;
4
-
5
- export type BackendType =
6
- | 'fs-events'
7
- | 'watchman'
8
- | 'inotify'
9
- | 'windows'
10
- | 'brute-force';
11
- export type EventType = 'create' | 'update' | 'delete';
12
- export interface Options {
13
- ignore?: Array<FilePath | GlobPattern>,
14
- backend?: BackendType
15
- }
16
- export type SubscribeCallback = (
17
- err: ?Error,
18
- events: Array<Event>
19
- ) => mixed;
20
- export interface AsyncSubscription {
21
- unsubscribe(): Promise<void>
22
- }
23
- export interface Event {
24
- path: FilePath,
25
- type: EventType
26
- }
27
- declare module.exports: {
28
- getEventsSince(
29
- dir: FilePath,
30
- snapshot: FilePath,
31
- opts?: Options
32
- ): Promise<Array<Event>>,
33
- subscribe(
34
- dir: FilePath,
35
- fn: SubscribeCallback,
36
- opts?: Options
37
- ): Promise<AsyncSubscription>,
38
- unsubscribe(
39
- dir: FilePath,
40
- fn: SubscribeCallback,
41
- opts?: Options
42
- ): Promise<void>,
43
- writeSnapshot(
44
- dir: FilePath,
45
- snapshot: FilePath,
46
- opts?: Options
47
- ): Promise<FilePath>
48
- }
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2013-2020 Linus Unnebäck
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,101 +0,0 @@
1
- # fs-xattr
2
-
3
- Node.js module for manipulating extended attributes.
4
-
5
- There are already some libraries for this, why use `fs-xattr`?
6
-
7
- - Very useful errors
8
- - No limits on value size
9
- - Clean and easy api
10
- - Proper asynchronous implementation
11
-
12
- ## Installation
13
-
14
- ```sh
15
- npm install --save fs-xattr
16
- ```
17
-
18
- ## Usage
19
-
20
- ```javascript
21
- import { getAttribute, setAttribute } from 'fs-xattr'
22
-
23
- await setAttribute('index.js', 'user.linusu.test', 'Hello, World!')
24
-
25
- console.log(await getAttribute('index.js', 'user.linusu.test'))
26
- //=> Hello, World!
27
- ```
28
-
29
- ## API
30
-
31
- ### `getAttribute(path, attr)`
32
-
33
- - `path` (`string`, required)
34
- - `attr` (`string`, required)
35
- - returns `Promise<Buffer>` - a `Promise` that will resolve with the value of the attribute.
36
-
37
- Get extended attribute `attr` from file at `path`.
38
-
39
- ### `getAttributeSync(path, attr)`
40
-
41
- - `path` (`string`, required)
42
- - `attr` (`string`, required)
43
- - returns `Buffer`
44
-
45
- Synchronous version of `getAttribute`.
46
-
47
- ### `setAttribute(path, attr, value)`
48
-
49
- - `path` (`string`, required)
50
- - `attr` (`string`, required)
51
- - `value` (`Buffer` or `string`, required)
52
- - returns `Promise<void>` - a `Promise` that will resolve when the value has been set.
53
-
54
- Set extended attribute `attr` to `value` on file at `path`.
55
-
56
- ### `setAttributeSync(path, attr, value)`
57
-
58
- - `path` (`string`, required)
59
- - `attr` (`string`, required)
60
- - `value` (`Buffer` or `string`, required)
61
-
62
- Synchronous version of `setAttribute`.
63
-
64
- ### `removeAttribute(path, attr)`
65
-
66
- - `path` (`string`, required)
67
- - `attr` (`string`, required)
68
- - returns `Promise<void>` - a `Promise` that will resolve when the value has been removed.
69
-
70
- Remove extended attribute `attr` on file at `path`.
71
-
72
- ### `removeAttributeSync(path, attr)`
73
-
74
- - `path` (`string`, required)
75
- - `attr` (`string`, required)
76
-
77
- Synchronous version of `removeAttribute`.
78
-
79
- ### `listAttributes(path)`
80
-
81
- - `path` (`string`, required)
82
- - returns `Promise<Array<string>>` - a `Promise` that will resolve with an array of strings, e.g. `['user.linusu.test', 'com.apple.FinderInfo']`.
83
-
84
- List all attributes on file at `path`.
85
-
86
- ### `listAttributesSync(path)`
87
-
88
- - `path` (`string`, required)
89
- - returns `Array<string>`
90
-
91
- Synchronous version of `listAttributes`.
92
-
93
- ## Namespaces
94
-
95
- For the large majority of Linux filesystem there are currently 4 supported namespaces (`user`, `trusted`, `security`, and `system`) you can use. Some other systems, like FreeBSD have only 2 (`user` and `system`).
96
-
97
- Be sure to use a namespace that is appropriate for your supported platforms. You can read more about this in [the "Extended File Attributes" Wikipedia article](https://en.wikipedia.org/wiki/Extended_file_attributes#Implementations).
98
-
99
- Using a namespace like `com.linusu.test` would work on macOS, but would give you the following error on Debian Linux:
100
-
101
- > Error \[ENOTSUP]: The file system does not support extended attributes or has the feature disabled.