@qqbrowser/qbot-claw-launcher 0.9.70 → 0.9.72
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/installer.js +5 -9
- package/dist/server.js +2 -2
- package/dist/service.js +3 -3
- package/dist/state.js +1 -1
- package/dist/version.js +1 -1
- package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/README.md +30 -41
- package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/lib/constants.js +0 -4
- package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/lib/parse.js +0 -301
- package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/lib/picomatch.js +3 -11
- package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/package.json +27 -57
- package/node_modules/is-extglob/package.json +17 -48
- package/node_modules/is-glob/package.json +21 -61
- package/node_modules/node-addon-api/README.md +1 -1
- package/node_modules/node-addon-api/napi-inl.h +4 -61
- package/node_modules/node-addon-api/napi.h +6 -43
- package/node_modules/node-addon-api/package.json +20 -44
- package/package.json +1 -1
- /package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/LICENSE +0 -0
- /package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/index.js +0 -0
- /package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/lib/scan.js +0 -0
- /package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/lib/utils.js +0 -0
- /package/node_modules/{picomatch → @parcel/watcher/node_modules/picomatch}/posix.js +0 -0
package/dist/installer.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}catch{}}}exports.installState={status:"idle",message:"\u672A\u5F00\u59CB"},exports.isInstalling=!1,exports.PYTHON_DIR=
|
|
3
|
-
`);
|
|
4
|
-
|
|
5
|
-
`).
|
|
6
|
-
`)+`
|
|
7
|
-
`+r;c.default.writeFileSync(n,e,"utf-8")}else c.default.writeFileSync(n,r,"utf-8");(0,a.log)(`\u5DF2\u5C06 OPENCLAW_GATEWAY_TOKEN \u5199\u5165 ${n}`)}catch(o){(0,a.log)(`\u5199\u5165 .env \u6587\u4EF6\u5931\u8D25: ${o.message}`)}}async function N(t){const n=(0,p.readState)();let r;n.gatewayPort&&!await(0,p.isPortAvailable)(n.gatewayPort)?(r=n.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,f.findAvailablePort)(),(0,a.log)(`\u540E\u53F0\u542F\u52A8 QBotClaw gateway run --port ${r} --force`);const o=await(0,f.findAvailablePort)(s.DEFAULT_MCP_HTTP_PORT),i=await(0,f.findAvailablePort)();await L(r,o,i,t),B((0,w.getOrCreateGatewayToken)());const e=(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||"",OPENCLAW_GATEWAY_TOKEN:(0,w.getOrCreateGatewayToken)(),QBOTCLAW_LLM_BASE_URL:`http://127.0.0.1:${n.port}/v1`,QBOTCLAW_LLM_API_KEY:O.proxyApiKey}});e.unref();const l=e.pid;(0,a.log)(`QBotClaw gateway \u5DF2\u5728\u540E\u53F0\u542F\u52A8\uFF0CPID: ${l}\uFF0C\u7AEF\u53E3: ${r}, token ${(0,w.getOrCreateGatewayToken)()}`),(0,p.writeState)({...(0,p.readState)(),gatewayPid:l,gatewayPort:r,mcpHttpPort:o,mcpWsPort:i})}function S(t,n,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"})+`
|
|
8
|
-
`)}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}@${n}`),(async()=>{try{(0,p.stopGateway)(),y(),I();const o=5;let i=0;g(t,o,i,"\u5F00\u59CB\u5B89\u88C5 mcporter..."),await T(t),i++,g(t,o,i,"\u5F00\u59CB\u4E0B\u8F7D\u89E3\u538B QBotClaw..."),await m(n),i++,g(t,o,i,"npmDownloadQBotClaw \u5B8C\u6210"),await(0,d.fullScanClearQuarantine)("npm install --ignore-scripts \u5B8C\u6210\u540E\uFF0Crebuild \u524D"),i++,await(0,d.watchWorkspaceQuarantine)().catch(e=>{(0,a.log)(`[quarantine] watchWorkspaceQuarantine \u542F\u52A8\u5F02\u5E38: ${e.message}`)}),g(t,o,i,"\u5F00\u59CB npm rebuild..."),await $(n),i++,g(t,o,i,"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(e){(0,a.log)(`\u521B\u5EFA openclaw \u8F6F\u94FE\u63A5\u5931\u8D25: ${e.message}`)}if(await(0,d.stopWatchWorkspaceQuarantine)().catch(e=>{(0,a.log)(`[quarantine] stopWatchWorkspaceQuarantine \u5F02\u5E38: ${e.message}`)}),exports.installState={status:"success",message:"\u5B89\u88C5\u6210\u529F",endTime:new Date().toISOString()},(0,a.log)("\u5B89\u88C5\u6210\u529F"),(0,a.refreshClawVersion)(n),g(t,o,i,"\u5F00\u59CB\u914D\u7F6E\u5E76\u542F\u52A8 QBotClaw gateway..."),await N(r),i++,t.writable)try{const e=(0,w.getOrCreateGatewayToken)();t.end(JSON.stringify({status:"done",progress:100,message:"\u5B89\u88C5\u6210\u529F",gatewayToken:e})+`
|
|
9
|
-
`)}catch{}}catch(o){if(await(0,d.stopWatchWorkspaceQuarantine)().catch(()=>{}),exports.installState={status:"failed",message:o.message,endTime:new Date().toISOString()},(0,a.log)(`\u5B89\u88C5\u5931\u8D25: ${o.message}`),t&&t.writable)try{t.end(JSON.stringify({status:"failed",progress:0,message:o.message})+`
|
|
1
|
+
"use strict";var C=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=I,exports.configAndRunQBotClaw=y,exports.runInstall=Q;const g=C(require("fs")),p=C(require("path")),w=require("child_process"),i=require("./config"),f=require("./utils"),_=require("./state"),d=require("./quarantine"),e=require("./reportLog"),P=require("./service"),N=require("./openai-proxy");function u(t,o,l,r){if(t&&t.writable){const a=o>0?Math.round(l/o*1e4)/100:0;try{t.write(JSON.stringify({status:"downloading",progress:a,totalSteps:o,currentStep:l,message:r})+`
|
|
2
|
+
`)}catch{}}}exports.installState={status:"idle",message:"\u672A\u5F00\u59CB"},exports.isInstalling=!1,exports.PYTHON_DIR=p.default.join(i.QBOT_CLAW_DIR,"python");function I(t,o){return(0,e.log)(`[QBotClaw] \u6267\u884C: QBotClaw ${t.join(" ")}`),new Promise(l=>{const r=(0,_.readState)(),a=(0,w.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||"",QBOTCLAW_LLM_BASE_URL:`http://127.0.0.1:${r.port}/v1`,QBOTCLAW_LLM_API_KEY:N.proxyApiKey}});(0,e.log)(`[QBotClaw] \u6267\u884C: QBotClaw ${t.join(" ")}`),a.stdout.on("data",n=>{const s=n.toString();if(o&&o.writable)try{o.write(s)}catch{}}),a.stderr.on("data",n=>{const s=n.toString();if(o&&o.writable)try{o.write(s)}catch{}}),a.on("close",n=>{(0,e.log)(`[QBotClaw] \u6267\u884C\u5B8C\u6210\uFF0C\u9000\u51FA\u7801: ${n}`),l()}),a.on("error",n=>{(0,e.log)(`[QBotClaw] \u542F\u52A8\u5931\u8D25: ${n.message}`),l()})})}function m(){g.default.existsSync(i.QBOT_CLAW_DIR)||g.default.mkdirSync(i.QBOT_CLAW_DIR,{recursive:!0})}function $(){const t=p.default.join(exports.PYTHON_DIR,"pip.conf");if(g.default.existsSync(t)){(0,e.log)("pip.conf \u5DF2\u5B58\u5728\uFF0C\u8DF3\u8FC7");return}const o=["[global]","index-url = https://mirrors.tencent.com/pypi/simple/",`cache-dir = ${p.default.join(exports.PYTHON_DIR,".pip-cache")}`,"","[install]",`prefix = ${exports.PYTHON_DIR}`,""].join(`
|
|
3
|
+
`);g.default.writeFileSync(t,o,"utf-8"),(0,e.log)(`\u5DF2\u5199\u5165 pip.conf: ${t}`)}async function B(t){if(g.default.existsSync(i.MCPORTER_BIN)){(0,e.log)("mcporter \u5DF2\u5B89\u88C5\uFF0C\u8DF3\u8FC7");return}(0,e.log)("\u5F00\u59CB\u5B89\u88C5 mcporter..."),await new Promise((o,l)=>{const r=(0,w.spawn)(i.NPM_BIN,["--userconfig",i.NPM_RC,"install","-g","mcporter"],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${p.default.dirname(i.NPM_BIN)}:${process.env.PATH}`}});r.stdout.on("data",a=>{const n=`[mcporter] ${a.toString().trim()}`;(0,e.log)(n),u(t,0,0,n)}),r.stderr.on("data",a=>{const n=`[mcporter] ${a.toString().trim()}`;(0,e.log)(n),u(t,0,0,n)}),r.on("close",a=>{a===0?((0,e.log)("mcporter \u5B89\u88C5\u6210\u529F"),o()):l(new Error(`mcporter \u5B89\u88C5\u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${a}`))}),r.on("error",l)})}function O(t,o){return new Promise((l,r)=>{const a=(0,w.spawn)(i.NPM_BIN,["--userconfig",i.NPM_RC,...t],{stdio:["ignore","pipe","pipe"],env:{...process.env,PATH:`${p.default.dirname(i.NPM_BIN)}:${process.env.PATH}`}});a.stdout.on("data",n=>{const s=`[npm] ${n.toString().trim()}`;(0,e.log)(s)}),a.stderr.on("data",n=>{const s=`[npm] ${n.toString().trim()}`;(0,e.log)(s)}),a.on("close",n=>{n===0?((0,e.log)(`${o} \u6210\u529F`),l()):r(new Error(`${o} \u5931\u8D25\uFF0C\u9000\u51FA\u7801: ${n}`))}),a.on("error",r)})}async function E(t){const o=`${i.NPM_PACKAGE_NAME}@${t}`;(0,e.log)(`\u5F00\u59CB\u5B89\u88C5 ${o}\uFF08--ignore-scripts\uFF0C\u4EC5\u4E0B\u8F7D\u89E3\u538B\uFF09...`),await O(["install","-g","--ignore-scripts",o],`${o} \u4E0B\u8F7D\u89E3\u538B`)}async function T(t){const o=`${i.NPM_PACKAGE_NAME}@${t}`;(0,e.log)("\u5F00\u59CB npm rebuild\uFF08\u6267\u884C postinstall \u811A\u672C\uFF09..."),await O(["rebuild","-g",i.NPM_PACKAGE_NAME],`${o} rebuild`),(0,e.log)(`${o} \u5B89\u88C5\u6210\u529F`)}async function L(t,o,l,r,a){try{const c=await(0,f.execCommand)(`"${i.NODE_BIN}" "${i.QBOTCLAW_BIN}" config validate --json`);(0,e.log)(`[config validate] \u8F93\u51FA: ${c}`);const A=JSON.parse(c);A.valid!==!0?((0,e.log)(`[config validate] \u914D\u7F6E\u6821\u9A8C\u672A\u901A\u8FC7\uFF08valid=${A.valid}\uFF09\uFF0C\u5F3A\u5236\u8986\u76D6\u914D\u7F6E`),a=!0):(0,e.log)("[config validate] \u914D\u7F6E\u6821\u9A8C\u901A\u8FC7")}catch(c){(0,e.log)(`[config validate] \u6267\u884C\u5931\u8D25: ${c.message}\uFF0C\u5F3A\u5236\u8986\u76D6\u914D\u7F6E`),a=!0}let n;if((0,e.log)(`\u8986\u76D6\u7528\u6237\u5DF2\u6709\u914D\u7F6E: ${a}`),!a&&g.default.existsSync(i.QBOT_CLAW_CONFIG_PATH))n=i.QBOT_CLAW_CONFIG_PATH,(0,e.log)(`\u4F7F\u7528\u5DF2\u6709\u914D\u7F6E\u6587\u4EF6: ${n}`);else{const c=p.default.join(i.NPM_GLOBAL_MODULES,i.NPM_PACKAGE_NAME,"preset-config.json");if(!g.default.existsSync(c)){(0,e.log)(`npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165: ${c}`);return}n=c,(0,e.log)(`\u4F7F\u7528 npm \u5168\u5C40\u5B89\u88C5\u76EE\u5F55\u4E2D\u7684\u914D\u7F6E: ${n}`)}let s;try{s=JSON.parse(g.default.readFileSync(n,"utf-8")),(0,e.log)(`\u5DF2\u8BFB\u53D6\u914D\u7F6E: ${n}`)}catch(c){(0,e.log)(`\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25: ${n}\uFF0C${c.message}\uFF0C\u8DF3\u8FC7\u914D\u7F6E\u5199\u5165`);return}s.gateway={...s.gateway??{},port:t},s.gateway.auth={...s.gateway.auth??{},token:o},(0,e.log)(`\u5DF2\u5199\u5165 gateway.port=${t}, gateway.token=${o}`),s.plugins=s.plugins??{},s.plugins.entries=s.plugins.entries??{},s.plugins.entries["x5use-browser-control"]=s.plugins.entries["x5use-browser-control"]??{},s.plugins.entries["x5use-browser-control"].config={...s.plugins.entries["x5use-browser-control"].config??{},wsPort:r,httpPort:l},(0,e.log)(`\u5DF2\u5C06 x5use-browser-control wsPort=${r}, httpPort=${l} \u5199\u5165\u914D\u7F6E`),g.default.writeFileSync(i.QBOT_CLAW_CONFIG_PATH,JSON.stringify(s,null,2),"utf-8"),(0,e.log)(`\u914D\u7F6E\u6587\u4EF6\u5DF2\u5199\u5165: ${i.QBOT_CLAW_CONFIG_PATH}`)}async function y(t){const o=(0,_.readState)();let l;o.gatewayPort&&!await(0,_.isPortAvailable)(o.gatewayPort)?(l=o.gatewayPort,(0,e.log)(`\u68C0\u6D4B\u5230 QBotClaw gateway \u5DF2\u5728\u7AEF\u53E3 ${l} \u8FD0\u884C\uFF0C\u590D\u7528\u539F\u7AEF\u53E3`)):l=await(0,f.findAvailablePort)(),(0,e.log)(`\u540E\u53F0\u542F\u52A8 QBotClaw gateway run --port ${l} --force`);const r=await(0,f.findAvailablePort)(i.DEFAULT_MCP_HTTP_PORT),a=await(0,f.findAvailablePort)(),n=(0,P.getOrCreateGatewayToken)();await L(l,n,r,a,t);const s=(0,w.spawn)(i.QBOTCLAW_BIN,["gateway","run","--port",String(l),"--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||"",QBOTCLAW_LLM_BASE_URL:`http://127.0.0.1:${o.port}/v1`,QBOTCLAW_LLM_API_KEY:N.proxyApiKey}});s.unref();const c=s.pid;(0,e.log)(`QBotClaw gateway \u5DF2\u5728\u540E\u53F0\u542F\u52A8\uFF0CPID: ${c}\uFF0C\u7AEF\u53E3: ${l}, token ${(0,P.getOrCreateGatewayToken)()}`),(0,_.writeState)({...(0,_.readState)(),gatewayPid:c,gatewayPort:l,mcpHttpPort:r,mcpWsPort:a})}function Q(t,o,l){if(exports.isInstalling){if((0,e.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,e.log)(`\u5F00\u59CB\u5B89\u88C5 ${i.NPM_PACKAGE_NAME}@${o}`),(async()=>{try{(0,_.stopGateway)(),m(),$();const r=5;let a=0;u(t,r,a,"\u5F00\u59CB\u5B89\u88C5 mcporter..."),await B(t),a++,u(t,r,a,"\u5F00\u59CB\u4E0B\u8F7D\u89E3\u538B QBotClaw..."),await E(o),a++,u(t,r,a,"npmDownloadQBotClaw \u5B8C\u6210"),await(0,d.fullScanClearQuarantine)("npm install --ignore-scripts \u5B8C\u6210\u540E\uFF0Crebuild \u524D"),a++,await(0,d.watchWorkspaceQuarantine)().catch(n=>{(0,e.log)(`[quarantine] watchWorkspaceQuarantine \u542F\u52A8\u5F02\u5E38: ${n.message}`)}),u(t,r,a,"\u5F00\u59CB npm rebuild..."),await T(o),a++,u(t,r,a,"npmRebuildQBotClaw \u5B8C\u6210");try{g.default.existsSync(i.OPENCLAW_BIN)||(g.default.symlinkSync(i.QBOTCLAW_BIN,i.OPENCLAW_BIN),(0,e.log)(`\u5DF2\u521B\u5EFA\u8F6F\u94FE\u63A5: ${i.OPENCLAW_BIN} -> ${i.QBOTCLAW_BIN}`))}catch(n){(0,e.log)(`\u521B\u5EFA openclaw \u8F6F\u94FE\u63A5\u5931\u8D25: ${n.message}`)}if(await(0,d.stopWatchWorkspaceQuarantine)().catch(n=>{(0,e.log)(`[quarantine] stopWatchWorkspaceQuarantine \u5F02\u5E38: ${n.message}`)}),exports.installState={status:"success",message:"\u5B89\u88C5\u6210\u529F",endTime:new Date().toISOString()},(0,e.log)("\u5B89\u88C5\u6210\u529F"),(0,e.refreshClawVersion)(o),u(t,r,a,"\u5F00\u59CB\u914D\u7F6E\u5E76\u542F\u52A8 QBotClaw gateway..."),await y(l),a++,t.writable)try{const n=(0,P.getOrCreateGatewayToken)();t.end(JSON.stringify({status:"done",progress:100,message:"\u5B89\u88C5\u6210\u529F",gatewayToken:n})+`
|
|
5
|
+
`)}catch{}}catch(r){if(await(0,d.stopWatchWorkspaceQuarantine)().catch(()=>{}),exports.installState={status:"failed",message:r.message,endTime:new Date().toISOString()},(0,e.log)(`\u5B89\u88C5\u5931\u8D25: ${r.message}`),t&&t.writable)try{t.end(JSON.stringify({status:"failed",progress:0,message:r.message})+`
|
|
10
6
|
`)}catch{}}finally{exports.isInstalling=!1}})()}
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var L=exports&&exports.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.setGlobalAuthClient=z,exports.getGlobalAuthClient=K,exports.watchParentProcess=W;const U=L(require("http")),w=L(require("fs")),
|
|
1
|
+
"use strict";var L=exports&&exports.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.setGlobalAuthClient=z,exports.getGlobalAuthClient=K,exports.watchParentProcess=W;const U=L(require("http")),w=L(require("fs")),T=L(require("path")),u=require("./config"),a=require("./utils"),r=require("./reportLog"),I=require("./installer"),H=require("./version"),y=require("./state"),R=require("child_process"),G=require("./service"),J=require("./filePicker"),x=require("./fileSecurityCheck"),B=require("./authMiddleware"),Q="\u9009\u62E9\u6587\u4EF6",M=10485760,F=10,b=!1,P={CANCELLED:"CANCELLED",INVALID_PARAMS:"INVALID_PARAMS",DIALOG_BUSY:"DIALOG_BUSY",DIALOG_TIMEOUT:"DIALOG_TIMEOUT",PLATFORM_NOT_SUPPORTED:"PLATFORM_NOT_SUPPORTED",INTERNAL_ERROR:"INTERNAL_ERROR"},q=require("./openai-proxy"),V=require("./api/auth-client");let v=new V.AuthClient({usePipe:!0});function z(d){v=d}function K(){return v}const 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 j(d){for(const[e,f]of Object.entries(C))d.setHeader(e,f)}exports.server=U.default.createServer(async(d,e)=>{const f=d.url||"";if(j(e),d.method==="OPTIONS"){e.writeHead(204,C),e.end();return}if(f.startsWith("/v1/")){await(0,q.handleOpenAIProxy)(d,e,v);return}if(f==="/api/version"){let n="unknown";try{n=(await(0,a.execCommand)(`"${u.NODE_BIN}" -v`)).trim(),(0,r.log)(`[version] node \u7248\u672C: ${n}`)}catch(g){(0,r.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${g.message}`),n=`error: ${g.message}`}const o=await(0,a.getQBotClawVersion)()??"0.0.0";(0,r.log)(`[version] qbotclaw \u7248\u672C: ${o}`);let s="0.0.0";if(w.default.existsSync(u.MCPORTER_BIN))try{s=(await(0,a.execCommand)(`"${u.NODE_BIN}" "${u.MCPORTER_BIN}" --version`)).trim(),(0,r.log)(`[version] mcporter \u7248\u672C: ${s}`)}catch(g){(0,r.log)(`[version] \u83B7\u53D6 mcporter \u7248\u672C\u5931\u8D25: ${g.message}`),s=`error: ${g.message}`}let i="0.0.0";if(w.default.existsSync(u.PYTHON_BIN))try{i=(await(0,a.execCommand)(`"${u.PYTHON_BIN}" --version`)).trim(),(0,r.log)(`[version] python \u7248\u672C: ${i}`)}catch(g){(0,r.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${g.message}`),i=`error: ${g.message}`}(0,a.sendJSON)(e,200,{status:"\u6210\u529F",launcher:H.LAUNCHER_VERSION,node:n,qbotclaw:o,mcporter:s,python:i});return}if(f==="/api/port"){const n=exports.server.address(),o=n&&typeof n=="object"?n.port:null,s=(0,y.readState)();(0,a.sendJSON)(e,200,{status:"\u6210\u529F",launcher:o,qbotclaw:s.gatewayPort??2e3,mcpHttp:s.mcpHttpPort??u.DEFAULT_MCP_HTTP_PORT,mcpWs:s.mcpWsPort??8765}),(0,r.log)(`[port] launcher: ${o}, qbotclaw: ${s.gatewayPort}, mcpHttp: ${s.mcpHttpPort}, mcpWs: ${s.mcpWsPort}`);return}if(f==="/api/status"){const n=(0,y.readState)(),o=[];if(n.gatewayPid)try{process.kill(n.gatewayPid,0)}catch{o.push(`gateway \u8FDB\u7A0B (pid: ${n.gatewayPid}) \u5DF2\u9000\u51FA`)}else o.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const s=[{name:"gateway",port:n.gatewayPort},{name:"mcpHttp",port:n.mcpHttpPort},{name:"mcpWs",port:n.mcpWsPort}];for(const{name:i,port:g}of s){if(!g){o.push(`${i} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,y.isPortAvailable)(g)&&o.push(`${i} \u7AEF\u53E3 (${g}) \u65E0\u670D\u52A1\u76D1\u542C`)}o.length===0?(0,a.sendJSON)(e,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,a.sendJSON)(e,200,{ok:!1,message:o.join("\uFF1B")});return}if(f==="/api/restart"){try{const n=(0,y.readState)();if(n.gatewayPid)try{process.kill(n.gatewayPid,"SIGTERM"),(0,r.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${n.gatewayPid}`)}catch{(0,r.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${n.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:o,gatewayPort:s,mcpHttpPort:i,mcpWsPort:g,...m}=n;(0,y.writeState)(m),(0,r.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpHttpPort, mcpWsPort"),await(0,I.configAndRunQBotClaw)(),(0,r.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const c=(0,y.readState)(),l=exports.server.address(),t=l&&typeof l=="object"?l.port:null;(0,a.sendJSON)(e,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:t,qbotclaw:c.gatewayPort??2e3,mcpHttp:c.mcpHttpPort??u.DEFAULT_MCP_HTTP_PORT,mcpWs:c.mcpWsPort??8765,gatewayToken:(0,G.getOrCreateGatewayToken)()})}catch(n){(0,r.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(e,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${n.message}`})}return}if(f==="/api/wechat/history"){try{if(!w.default.existsSync(u.SESSIONS_FILE)){(0,a.sendJSON)(e,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const n=JSON.parse(w.default.readFileSync(u.SESSIONS_FILE,"utf-8"));let o=null,s=0;for(const[m,c]of Object.entries(n))if(m.includes("openclaw-weixin")){const t=c.updatedAt??0;t>s&&(s=t,o=m)}if(!o){(0,a.sendJSON)(e,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const g=o.split(":").slice(2).join(":");(0,a.sendJSON)(e,200,{ok:!0,sessionKey:g,message:"\u83B7\u53D6\u6210\u529F"})}catch(n){(0,r.log)(`[wechat/history] \u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(e,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${n.message}`})}return}if(f==="/api/installing"){(0,a.sendJSON)(e,200,{installing:I.isInstalling});return}if(f==="/api/install"||f.startsWith("/api/install?")){if(I.installState.status==="downloading"){(0,a.sendJSON)(e,200,{ok:"downloading",message:"\u6B63\u5728\u5B89\u88C5\u4E2D..."});return}const n=new URL(f,"http://localhost"),o=n.searchParams.get("version")||void 0,s=n.searchParams.get("overrideConfig")==="true";if(!o){(0,a.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,I.runInstall)(e,o,s);return}if(f.startsWith("/api/watch")){const o=new URL(f,"http://localhost").searchParams.get("ppid");if(!o||isNaN(Number(o))){(0,a.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 s=parseInt(o,10);try{process.kill(s,0)}catch{(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${s} \u4E0D\u5B58\u5728`});return}const i=(0,y.readState)();(0,y.writeState)({...i,ppid:s}),W(s),(0,a.sendJSON)(e,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${s}`});return}if(f==="/api/qbotclaw"&&d.method==="POST"){let n="";d.on("data",o=>{n+=o.toString()}),d.on("end",()=>{let o;try{const s=JSON.parse(n);if(!Array.isArray(s.args)||s.args.length===0){(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u53C2\u6570 args \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"});return}o=s.args.map(i=>String(i))}catch{(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(!w.default.existsSync(u.QBOTCLAW_BIN)){(0,a.sendJSON)(e,404,{status:"\u5931\u8D25",message:`qbotclaw \u53EF\u6267\u884C\u6587\u4EF6\u4E0D\u5B58\u5728: ${u.QBOTCLAW_BIN}`});return}e.writeHead(200,{...C,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,I.runQBotClaw)(o,e).then(()=>{e.end(`
|
|
2
2
|
[\u6267\u884C\u6210\u529F]
|
|
3
3
|
`)}).catch(s=>{e.end(`
|
|
4
4
|
[\u542F\u52A8\u5931\u8D25: ${s.message}]
|
|
5
5
|
`)})});return}if(f.startsWith("/api/uninstall")){const o=new URL(f,"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 s=(i,g,m)=>{if(e.writable)try{e.write(JSON.stringify({status:i,file:g,msg:m})+`
|
|
6
|
-
`)}catch{}};try{s("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const i=(0,y.readState)();if(i.gatewayPid)try{process.kill(i.gatewayPid,"SIGTERM"),(0,r.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${i.gatewayPid}`),s("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${i.gatewayPid}`)}catch{(0,r.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${i.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),s("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${i.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else s("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");s("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${u.NPM_PACKAGE_NAME}...`);try{await new Promise((m,c)=>{const l=(0,R.spawn)(u.NPM_BIN,["--userconfig",u.NPM_RC,"uninstall","-g",u.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${u.NODE_BIN_DIR}:${process.env.PATH}`}});l.stdout?.on("data",t=>{(0,r.log)(`[uninstall] npm: ${t.toString().trim()}`)}),l.stderr?.on("data",t=>{(0,r.log)(`[uninstall] npm stderr: ${t.toString().trim()}`)}),l.on("close",t=>{t===0?m():c(new Error(`npm uninstall \u9000\u51FA\u7801: ${t}`))}),l.on("error",t=>c(t))}),(0,r.log)(`[uninstall] npm uninstall -g ${u.NPM_PACKAGE_NAME} \u6210\u529F`),s("\u6210\u529F","",`npm uninstall -g ${u.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(m){(0,r.log)(`[uninstall] npm uninstall \u5931\u8D25: ${m.message}`),s("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${m.message}`)}s("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${u.QBOT_CLAW_DIR}...`);const g=[];if(w.default.existsSync(u.QBOT_CLAW_DIR)){const m=w.default.readdirSync(u.QBOT_CLAW_DIR);for(const c of m){const l=I.default.join(u.QBOT_CLAW_DIR,c);if(o&&c==="workspace"){s("\u6210\u529F",l,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{w.default.statSync(l).isDirectory()?w.default.rmSync(l,{recursive:!0,force:!0}):w.default.unlinkSync(l),s("\u6210\u529F",l,"\u5DF2\u5220\u9664")}catch(t){(0,r.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${l} - ${t.message}`),s("\u5931\u8D25",l,`\u5220\u9664\u5931\u8D25: ${t.message}`),g.push(l)}}if(g.length>0){s("\u6210\u529F","",`${g.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const c of g)try{(0,R.execSync)(`rm -rf "${c}"`),(0,r.log)(`[uninstall] rm -rf \u91CD\u8BD5\u6210\u529F: ${c}`),s("\u6210\u529F",c,"rm \u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(l){(0,r.log)(`[uninstall] rm -rf \u91CD\u8BD5\u4E5F\u5931\u8D25: ${c} - ${l.message}`),s("\u5931\u8D25",c,`rm \u91CD\u8BD5\u4E5F\u5931\u8D25: ${l.message}`)}}if(o)s("\u6210\u529F",u.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{w.default.rmSync(u.QBOT_CLAW_DIR,{recursive:!0,force:!0}),s("\u6210\u529F",u.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(c){(0,r.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.message}`);try{(0,R.execSync)(`rm -rf "${u.QBOT_CLAW_DIR}"`),s("\u6210\u529F",u.QBOT_CLAW_DIR,"rm \u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(l){s("\u5931\u8D25",u.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${l.message}`)}}}else s("\u6210\u529F",u.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");s("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(i){(0,r.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`),s("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`)}e.end(),setTimeout(()=>{(0,r.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(f==="/api/file-picker"&&d.method==="POST"){const n=(0,B.authenticateRequest)(d);if(!n.ok){(0,a.sendJSON)(e,n.statusCode,{ok:!1,message:n.message});return}if((0,J.isFilePickerBusy)()){(0,a.sendJSON)(e,409,{ok:!1,code:P.DIALOG_BUSY,files:[],message:"\u5DF2\u6709\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u6B63\u5728\u663E\u793A\uFF0C\u8BF7\u7B49\u5F85\u5F53\u524D\u5BF9\u8BDD\u6846\u5173\u95ED\u540E\u91CD\u8BD5"});return}let o="";d.on("data",s=>{o+=s.toString()}),d.on("end",async()=>{let s=[],i=!1,g=H,m=M,c=F,l=b;if(o){let t;try{t=JSON.parse(o)}catch{(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(t.extensions!==void 0){if(!Array.isArray(t.extensions)||!t.extensions.every(p=>typeof p=="string")){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}s=t.extensions}if(t.multiple!==void 0){if(typeof t.multiple!="boolean"){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}i=t.multiple}if(t.title!==void 0){if(typeof t.title!="string"||t.title.length>200){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}g=t.title}if(t.maxFileSize!==void 0){if(typeof t.maxFileSize!="number"||t.maxFileSize<=0||!Number.isFinite(t.maxFileSize)){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}m=Math.min(t.maxFileSize,M)}if(t.maxFileCount!==void 0){if(typeof t.maxFileCount!="number"||t.maxFileCount<=0||!Number.isInteger(t.maxFileCount)){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}c=Math.min(t.maxFileCount,F)}if(b&&t.allowDirectory!==void 0){if(typeof t.allowDirectory!="boolean"){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}l=t.allowDirectory}}i||(c=1);try{const t=await(0,J.showFilePicker)({extensions:s,multiple:i,title:g,allowDirectory:l});if(!t||t.length===0){(0,a.sendJSON)(e,200,{ok:!1,code:P.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(l){const N=t.slice(0,c).map(D=>({name:I.default.basename(D),path:D,size:0,mimeType:"inode/directory"})),h=t.length>c;(0,a.sendJSON)(e,200,{ok:!0,files:N,message:h?`\u5DF2\u9009\u62E9 ${N.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${t.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${N.length} \u4E2A\u76EE\u5F55`});return}let p=!1,A=t;t.length>c&&(A=t.slice(0,c),p=!0);const O=[],S=[];for(const N of A){const h=(0,x.readFileInfo)(N,m);h.ok?O.push({name:h.name,path:h.path,size:h.size,mimeType:h.mimeType}):S.push({path:h.path,reason:h.reason,code:h.code})}const _=[];if(O.length>0&&_.push(`\u6210\u529F\u8BFB\u53D6 ${O.length} \u4E2A\u6587\u4EF6`),S.length>0){const N=S.map(h=>`${I.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");_.push(`${S.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${N}\uFF09`)}p&&_.push(`\u5171\u9009\u62E9 ${t.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD`);const k=O.length===0&&S.length>0;(0,a.sendJSON)(e,200,{ok:!k,code:k?S[0].code:void 0,files:O,failedFiles:S.length>0?S:void 0,message:_.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(t){(0,r.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${t.message}`);let p=P.INTERNAL_ERROR;t.message.includes("\u8D85\u65F6")?p=P.DIALOG_TIMEOUT:t.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(p=P.PLATFORM_NOT_SUPPORTED),(0,a.sendJSON)(e,500,{ok:!1,code:p,files:[],message:`\u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${t.message}`})}});return}if(f.startsWith("/api/reveal")){const n=(0,B.authenticateRequest)(d);if(!n.ok){(0,a.sendJSON)(e,n.statusCode,{status:"\u5931\u8D25",message:n.message});return}const s=new URL(f,"http://localhost").searchParams.get("path");if(!s){(0,a.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 i;try{i=Buffer.from(s,"base64").toString("utf-8")}catch{(0,a.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(!i||i.trim()===""){(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const g=(0,x.validateFilePath)(i);if(!g.valid){const p=g.reason;p.includes("\u975E\u6CD5\u5B57\u7B26")?(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:p}):p.includes("\u4E0D\u5B58\u5728")?(0,a.sendJSON)(e,404,{status:"\u5931\u8D25",message:p}):p.includes("\u65E0\u6CD5\u89E3\u6790")?(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:p}):((0,r.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${i}\uFF0C\u539F\u56E0: ${p}`),(0,a.sendJSON)(e,403,{status:"\u5931\u8D25",message:p}));return}const m=I.default.resolve(i),c=process.platform;let l,t;c==="darwin"?(l="open",t=["-R",m]):c==="win32"?(l="explorer",t=[`/select,${m}`]):(l="xdg-open",t=[I.default.dirname(m)]);try{await new Promise((p,A)=>{const O=(0,R.spawn)(l,t,{stdio:"ignore"}),S=setTimeout(()=>{O.kill(),A(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);O.on("close",_=>{clearTimeout(S),_===0||_===1?p():A(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${_}`))}),O.on("error",_=>{clearTimeout(S),A(_)})}),(0,r.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${m}`),(0,a.sendJSON)(e,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${m}`})}catch(p){(0,r.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${p.message}`),(0,a.sendJSON)(e,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${p.message}`})}return}(0,a.sendJSON)(e,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})});let T=null,E=null;function W(d){if(!d)return;if(T&&E===d){(0,r.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}T?((0,r.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${E}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${d}`),clearInterval(T),T=null,E=null):(0,r.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}`);const e=setInterval(()=>{try{process.kill(d,0)}catch{(0,r.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${d} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(e),T=null,E=null;const f=(0,y.readState)();if(f.gatewayPid)try{process.kill(f.gatewayPid,"SIGTERM"),(0,r.log)(`[watchParentProcess] \u5DF2\u53D1\u9001 SIGTERM \u7ED9 qbotclaw \u8FDB\u7A0B pid: ${f.gatewayPid}`)}catch{(0,r.log)(`[watchParentProcess] qbotclaw \u8FDB\u7A0B ${f.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}(0,y.clearState)(),(0,r.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,r.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,r.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);e.unref(),T=e,E=d}
|
|
6
|
+
`)}catch{}};try{s("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const i=(0,y.readState)();if(i.gatewayPid)try{process.kill(i.gatewayPid,"SIGTERM"),(0,r.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${i.gatewayPid}`),s("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${i.gatewayPid}`)}catch{(0,r.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${i.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),s("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${i.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else s("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");s("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${u.NPM_PACKAGE_NAME}...`);try{await new Promise((m,c)=>{const l=(0,R.spawn)(u.NPM_BIN,["--userconfig",u.NPM_RC,"uninstall","-g",u.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${u.NODE_BIN_DIR}:${process.env.PATH}`}});l.stdout?.on("data",t=>{(0,r.log)(`[uninstall] npm: ${t.toString().trim()}`)}),l.stderr?.on("data",t=>{(0,r.log)(`[uninstall] npm stderr: ${t.toString().trim()}`)}),l.on("close",t=>{t===0?m():c(new Error(`npm uninstall \u9000\u51FA\u7801: ${t}`))}),l.on("error",t=>c(t))}),(0,r.log)(`[uninstall] npm uninstall -g ${u.NPM_PACKAGE_NAME} \u6210\u529F`),s("\u6210\u529F","",`npm uninstall -g ${u.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(m){(0,r.log)(`[uninstall] npm uninstall \u5931\u8D25: ${m.message}`),s("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${m.message}`)}s("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${u.QBOT_CLAW_DIR}...`);const g=[];if(w.default.existsSync(u.QBOT_CLAW_DIR)){const m=w.default.readdirSync(u.QBOT_CLAW_DIR);for(const c of m){const l=T.default.join(u.QBOT_CLAW_DIR,c);if(o&&c==="workspace"){s("\u6210\u529F",l,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{w.default.statSync(l).isDirectory()?w.default.rmSync(l,{recursive:!0,force:!0}):w.default.unlinkSync(l),s("\u6210\u529F",l,"\u5DF2\u5220\u9664")}catch(t){(0,r.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${l} - ${t.message}`),s("\u5931\u8D25",l,`\u5220\u9664\u5931\u8D25: ${t.message}`),g.push(l)}}if(g.length>0){s("\u6210\u529F","",`${g.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const c of g)try{(0,R.execSync)(`rm -rf "${c}"`),(0,r.log)(`[uninstall] rm -rf \u91CD\u8BD5\u6210\u529F: ${c}`),s("\u6210\u529F",c,"rm \u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(l){(0,r.log)(`[uninstall] rm -rf \u91CD\u8BD5\u4E5F\u5931\u8D25: ${c} - ${l.message}`),s("\u5931\u8D25",c,`rm \u91CD\u8BD5\u4E5F\u5931\u8D25: ${l.message}`)}}if(o)s("\u6210\u529F",u.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{w.default.rmSync(u.QBOT_CLAW_DIR,{recursive:!0,force:!0}),s("\u6210\u529F",u.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(c){(0,r.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.message}`);try{(0,R.execSync)(`rm -rf "${u.QBOT_CLAW_DIR}"`),s("\u6210\u529F",u.QBOT_CLAW_DIR,"rm \u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(l){s("\u5931\u8D25",u.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${l.message}`)}}}else s("\u6210\u529F",u.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");s("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(i){(0,r.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`),s("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`)}e.end(),setTimeout(()=>{(0,r.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(f==="/api/file-picker"&&d.method==="POST"){const n=(0,B.authenticateRequest)(d);if(!n.ok){(0,a.sendJSON)(e,n.statusCode,{ok:!1,message:n.message});return}if((0,J.isFilePickerBusy)()){(0,a.sendJSON)(e,409,{ok:!1,code:P.DIALOG_BUSY,files:[],message:"\u5DF2\u6709\u6587\u4EF6\u9009\u62E9\u5BF9\u8BDD\u6846\u6B63\u5728\u663E\u793A\uFF0C\u8BF7\u7B49\u5F85\u5F53\u524D\u5BF9\u8BDD\u6846\u5173\u95ED\u540E\u91CD\u8BD5"});return}let o="";d.on("data",s=>{o+=s.toString()}),d.on("end",async()=>{let s=[],i=!1,g=Q,m=M,c=F,l=b;if(o){let t;try{t=JSON.parse(o)}catch{(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(t.extensions!==void 0){if(!Array.isArray(t.extensions)||!t.extensions.every(p=>typeof p=="string")){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}s=t.extensions}if(t.multiple!==void 0){if(typeof t.multiple!="boolean"){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}i=t.multiple}if(t.title!==void 0){if(typeof t.title!="string"||t.title.length>200){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}g=t.title}if(t.maxFileSize!==void 0){if(typeof t.maxFileSize!="number"||t.maxFileSize<=0||!Number.isFinite(t.maxFileSize)){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}m=Math.min(t.maxFileSize,M)}if(t.maxFileCount!==void 0){if(typeof t.maxFileCount!="number"||t.maxFileCount<=0||!Number.isInteger(t.maxFileCount)){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}c=Math.min(t.maxFileCount,F)}if(b&&t.allowDirectory!==void 0){if(typeof t.allowDirectory!="boolean"){(0,a.sendJSON)(e,400,{ok:!1,code:P.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}l=t.allowDirectory}}i||(c=1);try{const t=await(0,J.showFilePicker)({extensions:s,multiple:i,title:g,allowDirectory:l});if(!t||t.length===0){(0,a.sendJSON)(e,200,{ok:!1,code:P.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(l){const N=t.slice(0,c).map(D=>({name:T.default.basename(D),path:D,size:0,mimeType:"inode/directory"})),h=t.length>c;(0,a.sendJSON)(e,200,{ok:!0,files:N,message:h?`\u5DF2\u9009\u62E9 ${N.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${t.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${N.length} \u4E2A\u76EE\u5F55`});return}let p=!1,A=t;t.length>c&&(A=t.slice(0,c),p=!0);const O=[],S=[];for(const N of A){const h=(0,x.readFileInfo)(N,m);h.ok?O.push({name:h.name,path:h.path,size:h.size,mimeType:h.mimeType}):S.push({path:h.path,reason:h.reason,code:h.code})}const _=[];if(O.length>0&&_.push(`\u6210\u529F\u8BFB\u53D6 ${O.length} \u4E2A\u6587\u4EF6`),S.length>0){const N=S.map(h=>`${T.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");_.push(`${S.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${N}\uFF09`)}p&&_.push(`\u5171\u9009\u62E9 ${t.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD`);const k=O.length===0&&S.length>0;(0,a.sendJSON)(e,200,{ok:!k,code:k?S[0].code:void 0,files:O,failedFiles:S.length>0?S:void 0,message:_.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(t){(0,r.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${t.message}`);let p=P.INTERNAL_ERROR;t.message.includes("\u8D85\u65F6")?p=P.DIALOG_TIMEOUT:t.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(p=P.PLATFORM_NOT_SUPPORTED),(0,a.sendJSON)(e,500,{ok:!1,code:p,files:[],message:`\u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${t.message}`})}});return}if(f.startsWith("/api/reveal")){console.log(`[reveal] \u5B8C\u6574URL: ${f}`);const n=(0,B.authenticateRequest)(d);if(!n.ok){(0,a.sendJSON)(e,n.statusCode,{status:"\u5931\u8D25",message:n.message});return}const s=new URL(f,"http://localhost").searchParams.get("path")?.replace(/ /g,"+")??null;if(!s){(0,a.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 i;try{i=Buffer.from(s,"base64").toString("utf-8")}catch{(0,a.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(!i||i.trim()===""){(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const g=(0,x.validateFilePath)(i);if(!g.valid){const p=g.reason;p.includes("\u975E\u6CD5\u5B57\u7B26")?(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:p}):p.includes("\u4E0D\u5B58\u5728")?(0,a.sendJSON)(e,404,{status:"\u5931\u8D25",message:p}):p.includes("\u65E0\u6CD5\u89E3\u6790")?(0,a.sendJSON)(e,400,{status:"\u5931\u8D25",message:p}):((0,r.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${i}\uFF0C\u539F\u56E0: ${p}`),(0,a.sendJSON)(e,403,{status:"\u5931\u8D25",message:p}));return}const m=T.default.resolve(i),c=process.platform;let l,t;c==="darwin"?(l="open",t=["-R",m]):c==="win32"?(l="explorer",t=[`/select,${m}`]):(l="xdg-open",t=[T.default.dirname(m)]);try{await new Promise((p,A)=>{const O=(0,R.spawn)(l,t,{stdio:"ignore"}),S=setTimeout(()=>{O.kill(),A(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);O.on("close",_=>{clearTimeout(S),_===0||_===1?p():A(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${_}`))}),O.on("error",_=>{clearTimeout(S),A(_)})}),(0,r.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${m}`),(0,a.sendJSON)(e,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${m}`})}catch(p){(0,r.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${p.message}`),(0,a.sendJSON)(e,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${p.message}`})}return}(0,a.sendJSON)(e,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})});let $=null,E=null;function W(d){if(!d)return;if($&&E===d){(0,r.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}$?((0,r.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${E}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${d}`),clearInterval($),$=null,E=null):(0,r.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}`);const e=setInterval(()=>{try{process.kill(d,0)}catch{(0,r.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${d} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(e),$=null,E=null;const f=(0,y.readState)();if(f.gatewayPid)try{process.kill(f.gatewayPid,"SIGTERM"),(0,r.log)(`[watchParentProcess] \u5DF2\u53D1\u9001 SIGTERM \u7ED9 qbotclaw \u8FDB\u7A0B pid: ${f.gatewayPid}`)}catch{(0,r.log)(`[watchParentProcess] qbotclaw \u8FDB\u7A0B ${f.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}(0,y.clearState)(),(0,r.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,r.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,r.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);e.unref(),$=e,E=d}
|
package/dist/service.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`),process.stdout.uncork(),(0,r.log)(`[service] \u7248\u672C\u4E00\u81F4\uFF0C\u590D\u7528\u5DF2\u6709\u670D\u52A1 (pid: ${a.pid}, port: ${a.port})`);return}const u=await(0,e.findAvailablePort)();d.server.listen(u,"127.0.0.1",()=>{
|
|
3
|
-
`),process.stdout.uncork()
|
|
1
|
+
"use strict";var g=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getOrCreateGatewayToken=f,exports.startService=q,exports.stopService=R;const w=g(require("fs")),S=require("crypto"),d=require("./server"),e=require("./state"),y=require("./config"),l=require("./version"),v=require("./installer"),_=require("./utils"),r=require("./reportLog");let p,i;function f(){return i||(i=require("crypto").randomBytes(24).toString("hex"),(0,r.log)(`[service] \u751F\u6210\u65B0\u7684 gateway token: ${i}`),i||"0526bec85002fe65ef10d33df0a8dfbe76917cd125f5a4ad")}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,r.log)("\u7AEF\u53E3\u672A\u88AB\u5360\u7528\uFF0C\u8BF4\u660E\u72B6\u6001\u6587\u4EF6\u8FC7\u671F"),(0,e.clearState)(),null;const o=t.launcherVersion??null;if((0,r.log)(`[service] \u68C0\u6D4B\u5230\u6B63\u5728\u8FD0\u884C\u7684\u670D\u52A1\u7248\u672C: ${o??"unknown"}\uFF0C\u5F53\u524D\u7248\u672C: ${l.LAUNCHER_VERSION}`),o===l.LAUNCHER_VERSION)return(0,r.log)(`[service] \u7248\u672C\u4E00\u81F4\uFF0C\u590D\u7528\u5DF2\u6709\u670D\u52A1 (pid: ${t.pid}, port: ${t.port})`),!1;(0,r.log)(`[service] \u7248\u672C\u4E0D\u4E00\u81F4 (\u8FD0\u884C\u4E2D: ${o??"unknown"}, \u5F53\u524D: ${l.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,s){if(await k()===!1){const a=(0,e.readState)();process.stdout.write(JSON.stringify({state:"success",pid:a.pid,port:a.port})+`
|
|
2
|
+
`),process.stdout.uncork(),(0,r.log)(`[service] \u7248\u672C\u4E00\u81F4\uFF0C\u590D\u7528\u5DF2\u6709\u670D\u52A1 (pid: ${a.pid}, port: ${a.port})`);return}const u=await(0,e.findAvailablePort)();d.server.listen(u,"127.0.0.1",async()=>{p=(0,S.randomUUID)();const a=f();if((0,e.writeState)({pid:process.pid,port:u,token:p,launcherVersion:l.LAUNCHER_VERSION,...t?{ppid:t}:{}}),(0,d.watchParentProcess)(t),w.default.existsSync(y.QBOTCLAW_BIN))try{const n=await(0,_.getQBotClawVersion)(),c=(0,e.readState)();n!==s?((0,r.log)(`[service] qbotclaw \u672C\u5730\u7248\u672C (${n??"unknown"}) \u4E0E\u671F\u671B\u7248\u672C (${s}) \u4E0D\u4E00\u81F4\uFF0C\u505C\u6B62\u5F53\u524D qbotclaw \u8FDB\u7A0B`),(0,e.stopGateway)()):c.gatewayPid&&c.gatewayPort?(0,r.log)(`[service] qbotclaw \u5DF2\u5728\u8FD0\u884C\uFF0Cpid: ${c.gatewayPid}, port: ${c.gatewayPort}`):((0,r.log)("[service] \u68C0\u6D4B\u5230 qbotclaw\uFF0C\u7248\u672C\u5339\u914D\uFF0C\u81EA\u52A8\u542F\u52A8 gateway..."),await(0,v.configAndRunQBotClaw)())}catch(n){(0,r.log)(`[service] \u81EA\u52A8\u542F\u52A8 gateway \u5931\u8D25: ${n.message}`)}else(0,r.log)("[service] qbotclaw \u672A\u5B89\u88C5\uFF0C\u4E0D\u81EA\u52A8\u542F\u52A8");process.stdout.write(JSON.stringify({state:"success",pid:process.pid,port:u,token:p,gatewayToken:a})+`
|
|
3
|
+
`),process.stdout.uncork()}),process.on("SIGTERM",()=>{(0,e.stopGateway)(),(0,e.clearState)(),(0,r.flushLogs)().finally(()=>{process.exit(0)})})}function R(){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 s=t.pid,o=t.port??0;(0,e.clearState)(),process.stdout.write(JSON.stringify({state:"success",pid:s,port:o})+`
|
|
5
5
|
`),process.stdout.uncork()}catch(s){s.code==="ESRCH"&&(0,e.clearState)(),process.stdout.write(JSON.stringify({state:"err",pid:0,port:0})+`
|
|
6
6
|
`),process.stdout.uncork()}}
|
package/dist/state.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.readState=l,exports.writeState=u,exports.clearState=y,exports.stopGateway=p,exports.isPortAvailable=o,exports.findAvailablePort=w;const e=c(require("fs")),f=c(require("path")),S=c(require("net")),d=require("child_process"),a=require("./config"),_=require("./reportLog");let i=null;function l(){if(i)return i;try{if(e.default.existsSync(a.STATE_FILE)){const t=JSON.parse(e.default.readFileSync(a.STATE_FILE,"utf-8"));return i=t,t}}catch{}return{}}function u(t){i=t;const r=f.default.dirname(a.STATE_FILE);e.default.existsSync(r)||e.default.mkdirSync(r,{recursive:!0}),e.default.writeFileSync(a.STATE_FILE,JSON.stringify(t,null,2))}function y(){i=null,e.default.existsSync(a.STATE_FILE)&&e.default.unlinkSync(a.STATE_FILE)}function p(){const t=l();try{(0,d.execSync)('pkill -f "openclaw-gateway" 2>/dev/null',{stdio:"ignore"}),(0,_.log)("\u5DF2\u901A\u8FC7 pkill \u6E05\u7406\u6240\u6709 openclaw-gateway \u6B8B\u7559\u8FDB\u7A0B")}catch{}const{gatewayPid:r,gatewayPort:n,mcpHttpPort:E,mcpWsPort:T,...s}=t;u(s)}function o(t){return new Promise(r=>{const n=S.default.createServer();n.once("error",()=>r(!1)),n.once("listening",()=>{n.close(()=>r(!0))}),n.listen(t,"127.0.0.1")})}async function w(){for(;;){const t=Math.floor(Math.random()*5e4)+1e4;if(await o(t))return t}}
|
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.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.9.72";
|
|
@@ -265,17 +265,6 @@ Compile a regular expression from the `state` object returned by the
|
|
|
265
265
|
* `returnState` **{Boolean}**: Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
|
266
266
|
* `returns` **{RegExp}**
|
|
267
267
|
|
|
268
|
-
**Example**
|
|
269
|
-
|
|
270
|
-
```js
|
|
271
|
-
const picomatch = require('picomatch');
|
|
272
|
-
const state = picomatch.parse('*.js');
|
|
273
|
-
// picomatch.compileRe(state[, options]);
|
|
274
|
-
|
|
275
|
-
console.log(picomatch.compileRe(state));
|
|
276
|
-
//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
277
|
-
```
|
|
278
|
-
|
|
279
268
|
### [.makeRe](lib/picomatch.js#L285)
|
|
280
269
|
|
|
281
270
|
Create a regular expression from a parsed glob pattern.
|
|
@@ -292,10 +281,10 @@ Create a regular expression from a parsed glob pattern.
|
|
|
292
281
|
|
|
293
282
|
```js
|
|
294
283
|
const picomatch = require('picomatch');
|
|
295
|
-
|
|
284
|
+
const state = picomatch.parse('*.js');
|
|
285
|
+
// picomatch.compileRe(state[, options]);
|
|
296
286
|
|
|
297
|
-
|
|
298
|
-
console.log(result);
|
|
287
|
+
console.log(picomatch.compileRe(state));
|
|
299
288
|
//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
|
300
289
|
```
|
|
301
290
|
|
|
@@ -334,9 +323,11 @@ The following options may be used with the main `picomatch()` function or any of
|
|
|
334
323
|
| `bash` | `boolean` | `false` | Follow bash matching rules more strictly - disallows backslashes as escape characters, and treats single stars as globstars (`**`). |
|
|
335
324
|
| `capture` | `boolean` | `undefined` | Return regex matches in supporting methods. |
|
|
336
325
|
| `contains` | `boolean` | `undefined` | Allows glob to match any part of the given string(s). |
|
|
326
|
+
| `cwd` | `string` | `process.cwd()` | Current working directory. Used by `picomatch.split()` |
|
|
337
327
|
| `debug` | `boolean` | `undefined` | Debug regular expressions when an error is thrown. |
|
|
338
328
|
| `dot` | `boolean` | `false` | Enable dotfile matching. By default, dotfiles are ignored unless a `.` is explicitly defined in the pattern, or `options.dot` is true |
|
|
339
329
|
| `expandRange` | `function` | `undefined` | Custom function for expanding ranges in brace patterns, such as `{a..z}`. The function receives the range values as two arguments, and it must return a string to be used in the generated regex. It's recommended that returned strings be wrapped in parentheses. |
|
|
330
|
+
| `failglob` | `boolean` | `false` | Throws an error if no matches are found. Based on the bash option of the same name. |
|
|
340
331
|
| `fastpaths` | `boolean` | `true` | To speed up processing, full parsing is skipped for a handful common glob patterns. Disable this behavior by setting this option to `false`. |
|
|
341
332
|
| `flags` | `string` | `undefined` | Regex flags to use in the generated regex. If defined, the `nocase` option will be overridden. |
|
|
342
333
|
| [format](#optionsformat) | `function` | `undefined` | Custom function for formatting the returned string. This is useful for removing leading slashes, converting Windows paths to Posix paths, etc. |
|
|
@@ -345,23 +336,26 @@ The following options may be used with the main `picomatch()` function or any of
|
|
|
345
336
|
| `literalBrackets` | `boolean` | `undefined` | When `true`, brackets in the glob pattern will be escaped so that only literal brackets will be matched. |
|
|
346
337
|
| `matchBase` | `boolean` | `false` | Alias for `basename` |
|
|
347
338
|
| `maxLength` | `number` | `65536` | Limit the max length of the input string. An error is thrown if the input string is longer than this value. |
|
|
348
|
-
| `maxExtglobRecursion` | `number\|boolean` | `0` | Limit nested quantified extglobs and other risky repeated extglob forms. When the limit is exceeded, the extglob is treated as a literal string instead of being compiled to regex. Set to `false` to disable this safeguard. |
|
|
349
339
|
| `nobrace` | `boolean` | `false` | Disable brace matching, so that `{a,b}` and `{1..3}` would be treated as literal characters. |
|
|
350
340
|
| `nobracket` | `boolean` | `undefined` | Disable matching with regex brackets. |
|
|
351
341
|
| `nocase` | `boolean` | `false` | Make matching case-insensitive. Equivalent to the regex `i` flag. Note that this option is overridden by the `flags` option. |
|
|
342
|
+
| `nodupes` | `boolean` | `true` | Deprecated, use `nounique` instead. This option will be removed in a future major release. By default duplicates are removed. Disable uniquification by setting this option to false. |
|
|
352
343
|
| `noext` | `boolean` | `false` | Alias for `noextglob` |
|
|
353
344
|
| `noextglob` | `boolean` | `false` | Disable support for matching with extglobs (like `+(a\|b)`) |
|
|
354
345
|
| `noglobstar` | `boolean` | `false` | Disable support for matching nested directories with globstars (`**`) |
|
|
355
346
|
| `nonegate` | `boolean` | `false` | Disable support for negating with leading `!` |
|
|
347
|
+
| `noquantifiers` | `boolean` | `false` | Disable support for regex quantifiers (like `a{1,2}`) and treat them as brace patterns to be expanded. |
|
|
356
348
|
| [onIgnore](#optionsonIgnore) | `function` | `undefined` | Function to be called on ignored items. |
|
|
357
349
|
| [onMatch](#optionsonMatch) | `function` | `undefined` | Function to be called on matched items. |
|
|
358
350
|
| [onResult](#optionsonResult) | `function` | `undefined` | Function to be called on all items, regardless of whether or not they are matched or ignored. |
|
|
359
351
|
| `posix` | `boolean` | `false` | Support POSIX character classes ("posix brackets"). |
|
|
352
|
+
| `posixSlashes` | `boolean` | `undefined` | Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself |
|
|
360
353
|
| `prepend` | `boolean` | `undefined` | String to prepend to the generated regex used for matching. |
|
|
361
354
|
| `regex` | `boolean` | `false` | Use regular expression rules for `+` (instead of matching literal `+`), and for stars that follow closing parentheses or brackets (as in `)*` and `]*`). |
|
|
362
355
|
| `strictBrackets` | `boolean` | `undefined` | Throw an error if brackets, braces, or parens are imbalanced. |
|
|
363
356
|
| `strictSlashes` | `boolean` | `undefined` | When true, picomatch won't match trailing slashes with single stars. |
|
|
364
357
|
| `unescape` | `boolean` | `undefined` | Remove backslashes preceding escaped characters in the glob pattern. By default, backslashes are retained. |
|
|
358
|
+
| `unixify` | `boolean` | `undefined` | Alias for `posixSlashes`, for backwards compatibility. |
|
|
365
359
|
| `windows` | `boolean` | `false` | Also accept backslashes as the path separator. |
|
|
366
360
|
|
|
367
361
|
### Scan Options
|
|
@@ -555,13 +549,6 @@ console.log(pm.isMatch('foo.bar', '!(foo).!(bar)')); // false
|
|
|
555
549
|
|
|
556
550
|
// supports nested extglobs
|
|
557
551
|
console.log(pm.isMatch('foo.bar', '!(!(foo)).!(!(bar))')); // true
|
|
558
|
-
|
|
559
|
-
// risky quantified extglobs are treated literally by default
|
|
560
|
-
console.log(pm.makeRe('+(a|aa)'));
|
|
561
|
-
//=> /^(?:\+\(a\|aa\))$/
|
|
562
|
-
|
|
563
|
-
// increase the limit to allow a small amount of nested quantified extglobs
|
|
564
|
-
console.log(pm.isMatch('aaa', '+(+(a))', { maxExtglobRecursion: 1 })); // true
|
|
565
552
|
```
|
|
566
553
|
|
|
567
554
|
#### POSIX brackets
|
|
@@ -598,7 +585,7 @@ See the [Bash Reference Manual](https://www.gnu.org/software/bash/manual/html_no
|
|
|
598
585
|
|
|
599
586
|
### Braces
|
|
600
587
|
|
|
601
|
-
Picomatch
|
|
588
|
+
Picomatch does not do brace expansion. For [brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) and advanced matching with braces, use [micromatch](https://github.com/micromatch/micromatch) instead. Picomatch has very basic support for braces.
|
|
602
589
|
|
|
603
590
|
### Matching special characters as literals
|
|
604
591
|
|
|
@@ -642,42 +629,44 @@ The following table shows which features are supported by [minimatch](https://gi
|
|
|
642
629
|
|
|
643
630
|
Performance comparison of picomatch and minimatch.
|
|
644
631
|
|
|
632
|
+
_(Pay special attention to the last three benchmarks. Minimatch freezes on long ranges.)_
|
|
633
|
+
|
|
645
634
|
```
|
|
646
635
|
# .makeRe star (*)
|
|
647
|
-
picomatch x
|
|
648
|
-
minimatch x
|
|
636
|
+
picomatch x 4,449,159 ops/sec ±0.24% (97 runs sampled)
|
|
637
|
+
minimatch x 632,772 ops/sec ±0.14% (98 runs sampled)
|
|
649
638
|
|
|
650
639
|
# .makeRe star; dot=true (*)
|
|
651
|
-
picomatch x
|
|
652
|
-
minimatch x
|
|
640
|
+
picomatch x 3,500,079 ops/sec ±0.26% (99 runs sampled)
|
|
641
|
+
minimatch x 564,916 ops/sec ±0.23% (96 runs sampled)
|
|
653
642
|
|
|
654
643
|
# .makeRe globstar (**)
|
|
655
|
-
picomatch x
|
|
656
|
-
minimatch x 1,
|
|
644
|
+
picomatch x 3,261,000 ops/sec ±0.27% (98 runs sampled)
|
|
645
|
+
minimatch x 1,664,766 ops/sec ±0.20% (100 runs sampled)
|
|
657
646
|
|
|
658
647
|
# .makeRe globstars (**/**/**)
|
|
659
|
-
picomatch x
|
|
660
|
-
minimatch x 1,
|
|
648
|
+
picomatch x 3,284,469 ops/sec ±0.18% (97 runs sampled)
|
|
649
|
+
minimatch x 1,435,880 ops/sec ±0.34% (95 runs sampled)
|
|
661
650
|
|
|
662
651
|
# .makeRe with leading star (*.txt)
|
|
663
|
-
picomatch x
|
|
664
|
-
minimatch x
|
|
652
|
+
picomatch x 3,100,197 ops/sec ±0.35% (99 runs sampled)
|
|
653
|
+
minimatch x 428,347 ops/sec ±0.42% (94 runs sampled)
|
|
665
654
|
|
|
666
655
|
# .makeRe - basic braces ({a,b,c}*.txt)
|
|
667
|
-
picomatch x
|
|
668
|
-
minimatch x 107,
|
|
656
|
+
picomatch x 443,578 ops/sec ±1.33% (89 runs sampled)
|
|
657
|
+
minimatch x 107,143 ops/sec ±0.35% (94 runs sampled)
|
|
669
658
|
|
|
670
659
|
# .makeRe - short ranges ({a..z}*.txt)
|
|
671
|
-
picomatch x
|
|
672
|
-
minimatch x 14,
|
|
660
|
+
picomatch x 415,484 ops/sec ±0.76% (96 runs sampled)
|
|
661
|
+
minimatch x 14,299 ops/sec ±0.26% (96 runs sampled)
|
|
673
662
|
|
|
674
663
|
# .makeRe - medium ranges ({1..100000}*.txt)
|
|
675
|
-
picomatch x
|
|
676
|
-
minimatch x 2
|
|
664
|
+
picomatch x 395,020 ops/sec ±0.87% (89 runs sampled)
|
|
665
|
+
minimatch x 2 ops/sec ±4.59% (10 runs sampled)
|
|
677
666
|
|
|
678
667
|
# .makeRe - long ranges ({1..10000000}*.txt)
|
|
679
|
-
picomatch x
|
|
680
|
-
minimatch
|
|
668
|
+
picomatch x 400,036 ops/sec ±0.83% (90 runs sampled)
|
|
669
|
+
minimatch (FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory)
|
|
681
670
|
```
|
|
682
671
|
|
|
683
672
|
<br>
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
const WIN_SLASH = '\\\\/';
|
|
4
4
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
5
5
|
|
|
6
|
-
const DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Posix glob regex
|
|
10
8
|
*/
|
|
@@ -71,7 +69,6 @@ const WINDOWS_CHARS = {
|
|
|
71
69
|
*/
|
|
72
70
|
|
|
73
71
|
const POSIX_REGEX_SOURCE = {
|
|
74
|
-
__proto__: null,
|
|
75
72
|
alnum: 'a-zA-Z0-9',
|
|
76
73
|
alpha: 'a-zA-Z',
|
|
77
74
|
ascii: '\\x00-\\x7F',
|
|
@@ -89,7 +86,6 @@ const POSIX_REGEX_SOURCE = {
|
|
|
89
86
|
};
|
|
90
87
|
|
|
91
88
|
module.exports = {
|
|
92
|
-
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
93
89
|
MAX_LENGTH: 1024 * 64,
|
|
94
90
|
POSIX_REGEX_SOURCE,
|
|
95
91
|
|