@qqbrowser/qbot-claw-launcher 0.10.18 → 0.10.20

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.verifyOrigin=r,exports.authenticateRequest=u;const n=["https://quickstart.imtt.qq.com","https://quickstarttest.imtt.qq.com","https://browser.qq.com"];function r(e){const t=e.headers.origin;if(!t)return!1;if(t.startsWith("chrome-extension://")||t.startsWith("moz-extension://"))return!0;try{const s=new URL(t).origin;return n.some(i=>{try{return new URL(i).origin===s}catch{return!1}})}catch{return!1}}function u(e){return r(e)?{ok:!0,statusCode:200,message:""}:{ok:!1,statusCode:403,message:"\u8BF7\u6C42\u6765\u6E90\u4E0D\u5728\u5141\u8BB8\u5217\u8868\u4E2D"}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.verifyOrigin=i,exports.authenticateRequest=f;const a=require("./service"),o=["https://quickstart.imtt.qq.com","https://quickstarttest.imtt.qq.com","https://browser.qq.com"];function u(e){const r=e.headers.authorization;if(typeof r=="string"){const n=r.match(/^Bearer\s+(.+)$/i);if(n&&n[1])return n[1].trim()}const t=e.headers["x-gateway-token"];if(typeof t=="string"&&t.trim())return t.trim();if(Array.isArray(t)&&t.length>0&&t[0].trim())return t[0].trim();try{const s=new URL(e.url||"","http://localhost").searchParams.get("token");if(s&&s.trim())return s.trim()}catch{}}function c(e){const r=u(e);if(!r)return!1;const t=(0,a.getOrCreateGatewayToken)();return t?r===t:!1}function i(e){const r=e.headers.origin;if(!r)return!1;if(r.startsWith("chrome-extension://")||r.startsWith("moz-extension://"))return!0;try{const t=new URL(r).origin;return o.some(n=>{try{return new URL(n).origin===t}catch{return!1}})}catch{return!1}}function f(e){return i(e)?c(e)?{ok:!0,statusCode:200,message:""}:{ok:!1,statusCode:401,message:"gateway token \u7F3A\u5931\u6216\u4E0D\u5339\u914D"}:{ok:!1,statusCode:403,message:"\u8BF7\u6C42\u6765\u6E90\u4E0D\u5728\u5141\u8BB8\u5217\u8868\u4E2D"}}
package/dist/build.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IS_DEBUG_BUILD=exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.10.18",exports.IS_DEBUG_BUILD=!1;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IS_DEBUG_BUILD=exports.LAUNCHER_VERSION=void 0,exports.LAUNCHER_VERSION="0.10.20",exports.IS_DEBUG_BUILD=!1;
package/dist/server.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var L=exports&&exports.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.setGlobalAuthClient=z,exports.getGlobalAuthClient=j,exports.watchParentProcess=W;const U=L(require("http")),P=L(require("fs")),$=L(require("path")),f=require("./config"),n=require("./utils"),o=require("./reportLog"),k=require("./installer"),G=require("./build"),_=require("./state"),C=require("child_process"),Q=require("./service"),J=require("./filePicker"),x=require("./fileSecurityCheck"),F=require("./authMiddleware"),q=require("./qbotclaw-routes"),H="\u9009\u62E9\u6587\u4EF6",b=10485760,B=10,M=!1,y={CANCELLED:"CANCELLED",INVALID_PARAMS:"INVALID_PARAMS",DIALOG_BUSY:"DIALOG_BUSY",DIALOG_TIMEOUT:"DIALOG_TIMEOUT",PLATFORM_NOT_SUPPORTED:"PLATFORM_NOT_SUPPORTED",INTERNAL_ERROR:"INTERNAL_ERROR"},V=require("./openai-proxy"),K=require("./api/auth-client");let v=new K.AuthClient({usePipe:!0});function z(u){v=u}function j(){return v}const R={"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 Y(u){for(const[t,g]of Object.entries(R))u.setHeader(t,g)}exports.server=U.default.createServer(async(u,t)=>{const g=u.url||"";if(Y(t),u.method==="OPTIONS"){t.writeHead(204,R),t.end();return}if(g.startsWith("/v1/")){await(0,V.handleOpenAIProxy)(u,t,v);return}if(g==="/api/version"){let a="unknown";try{a=(await(0,n.execCommand)(`"${f.NODE_BIN}" -v`)).trim(),(0,o.log)(`[version] node \u7248\u672C: ${a}`)}catch(i){(0,o.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${i.message}`),a=`error: ${i.message}`}const r=await(0,n.getQBotClawVersion)()??"0.0.0";(0,o.log)(`[version] qbotclaw \u7248\u672C: ${r}`);let s="0.0.0";if(P.default.existsSync(f.PYTHON_BIN))try{s=(await(0,n.execCommand)(`"${f.PYTHON_BIN}" --version`)).trim(),(0,o.log)(`[version] python \u7248\u672C: ${s}`)}catch(i){(0,o.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${i.message}`),s=`error: ${i.message}`}(0,n.sendJSON)(t,200,{status:"\u6210\u529F",launcher:G.LAUNCHER_VERSION,node:a,qbotclaw:r,python:s});return}if(g==="/api/port"){const a=exports.server.address(),r=a&&typeof a=="object"?a.port:null,s=(0,_.readState)();(0,n.sendJSON)(t,200,{status:"\u6210\u529F",launcher:r,qbotclaw:s.gatewayPort??2e3,mcpWs:s.mcpWsPort??8765}),(0,o.log)(`[port] launcher: ${r}, qbotclaw: ${s.gatewayPort}, mcpWs: ${s.mcpWsPort}`);return}if(g==="/api/status"){const a=(0,_.readState)(),r=[];if(a.gatewayPid)try{process.kill(a.gatewayPid,0)}catch{r.push(`gateway \u8FDB\u7A0B (pid: ${a.gatewayPid}) \u5DF2\u9000\u51FA`)}else r.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const s=[{name:"gateway",port:a.gatewayPort},{name:"mcpWs",port:a.mcpWsPort}];for(const{name:i,port:p}of s){if(!p){r.push(`${i} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,_.isPortAvailable)(p)&&r.push(`${i} \u7AEF\u53E3 (${p}) \u65E0\u670D\u52A1\u76D1\u542C`)}r.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:r.join("\uFF1B")});return}if(g==="/api/restart"){try{const a=(0,_.readState)();if(a.gatewayPid)try{process.kill(a.gatewayPid,"SIGTERM"),(0,o.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${a.gatewayPid}`)}catch{(0,o.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${a.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:r,gatewayPort:s,mcpWsPort:i,...p}=a;(0,_.writeState)(p),(0,o.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpWsPort"),await(0,k.configAndRunQBotClaw)(),(0,o.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const d=(0,_.readState)(),l=exports.server.address(),c=l&&typeof l=="object"?l.port:null;(0,n.sendJSON)(t,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:c,qbotclaw:d.gatewayPort??2e3,mcpWs:d.mcpWsPort??8765,gatewayToken:(0,Q.getOrCreateGatewayToken)()})}catch(a){(0,o.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(t,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${a.message}`})}return}if(g==="/api/wechat/history"){try{if(!P.default.existsSync(f.SESSIONS_FILE)){(0,n.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(P.default.readFileSync(f.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[d,l]of Object.entries(a))if(d.includes("openclaw-weixin")){const e=l.updatedAt??0;e>s&&(s=e,r=d)}if(!r){(0,n.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const p=r.split(":").slice(2).join(":");(0,n.sendJSON)(t,200,{ok:!0,sessionKey:p,message:"\u83B7\u53D6\u6210\u529F"})}catch(a){(0,o.log)(`[wechat/history] \u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(t,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(g==="/api/chat/latest"){try{if(!P.default.existsSync(f.SESSIONS_FILE)){(0,n.sendJSON)(t,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(P.default.readFileSync(f.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[p,d]of Object.entries(a)){if(p.includes("openclaw-weixin"))continue;const c=d.updatedAt??0;c>s&&(s=c,r=p)}if(!r){(0,n.sendJSON)(t,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u975E\u5FAE\u4FE1\u4F1A\u8BDD"});return}const i=a[r];(0,n.sendJSON)(t,200,{ok:!0,sessionId:i.sessionId??"",sessionKey:r,updatedAt:s,message:"\u83B7\u53D6\u6210\u529F"})}catch(a){(0,o.log)(`[chat/latest] \u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(t,500,{ok:!1,sessionId:"",message:`\u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(g==="/api/installing"){(0,n.sendJSON)(t,200,{installing:k.isInstalling});return}if(g==="/api/install"||g.startsWith("/api/install?")){const a=new URL(g,"http://localhost"),r=a.searchParams.get("version")||void 0,s=a.searchParams.get("overrideConfig")==="true";if(!r){(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,{...R,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,k.runInstall)(t,r,s);return}if(g.startsWith("/api/watch")){const r=new URL(g,"http://localhost").searchParams.get("ppid");if(!r||isNaN(Number(r))){(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 s=parseInt(r,10);try{process.kill(s,0)}catch{(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${s} \u4E0D\u5B58\u5728`});return}const i=(0,_.readState)();(0,_.writeState)({...i,ppid:s}),W(s),(0,n.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${s}`});return}if(!(g.startsWith("/api/qbotclaw/")&&await(0,q.handleQBotClawRoutes)(u,t,g))){if(g.startsWith("/api/uninstall")){const r=new URL(g,"http://localhost").searchParams.get("keepWorkspace")==="true";t.writeHead(200,{...R,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const s=(i,p,d)=>{if(t.writable)try{t.write(JSON.stringify({status:i,file:p,msg:d})+`
2
- `)}catch{}};try{s("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const i=(0,_.readState)();if(i.gatewayPid)try{process.kill(i.gatewayPid,"SIGTERM"),(0,o.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,o.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 ${f.NPM_PACKAGE_NAME}...`);try{await new Promise((d,l)=>{const c=(0,C.spawn)(f.NPM_BIN,["--userconfig",f.NPM_RC,"uninstall","-g",f.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${f.NODE_BIN_DIR}${$.default.delimiter}${process.env.PATH}`},shell:process.platform==="win32",windowsHide:!0});c.stdout?.on("data",e=>{(0,o.log)(`[uninstall] npm: ${e.toString().trim()}`)}),c.stderr?.on("data",e=>{(0,o.log)(`[uninstall] npm stderr: ${e.toString().trim()}`)}),c.on("close",e=>{e===0?d():l(new Error(`npm uninstall \u9000\u51FA\u7801: ${e}`))}),c.on("error",e=>l(e))}),(0,o.log)(`[uninstall] npm uninstall -g ${f.NPM_PACKAGE_NAME} \u6210\u529F`),s("\u6210\u529F","",`npm uninstall -g ${f.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(d){(0,o.log)(`[uninstall] npm uninstall \u5931\u8D25: ${d.message}`),s("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${d.message}`)}s("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${f.QBOT_CLAW_DIR}...`);const p=[];if(P.default.existsSync(f.QBOT_CLAW_DIR)){const d=P.default.readdirSync(f.QBOT_CLAW_DIR);for(const l of d){const c=$.default.join(f.QBOT_CLAW_DIR,l);if(r&&l==="workspace"){s("\u6210\u529F",c,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{P.default.statSync(c).isDirectory()?P.default.rmSync(c,{recursive:!0,force:!0}):P.default.unlinkSync(c),s("\u6210\u529F",c,"\u5DF2\u5220\u9664")}catch(e){(0,o.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${c} - ${e.message}`),s("\u5931\u8D25",c,`\u5220\u9664\u5931\u8D25: ${e.message}`),p.push(c)}}if(p.length>0){s("\u6210\u529F","",`${p.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const l of p)try{process.platform==="win32"?(0,C.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,C.execSync)(`rm -rf "${l}"`),(0,o.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u6210\u529F: ${l}`),s("\u6210\u529F",l,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(c){(0,o.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${l} - ${c.message}`),s("\u5931\u8D25",l,`\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${c.message}`)}}if(r)s("\u6210\u529F",f.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{P.default.rmSync(f.QBOT_CLAW_DIR,{recursive:!0,force:!0}),s("\u6210\u529F",f.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(l){(0,o.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${l.message}`);try{process.platform==="win32"?(0,C.execSync)(`rmdir /s /q "${f.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,C.execSync)(`rm -rf "${f.QBOT_CLAW_DIR}"`),s("\u6210\u529F",f.QBOT_CLAW_DIR,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(c){s("\u5931\u8D25",f.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.message}`)}}}else s("\u6210\u529F",f.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");s("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(i){(0,o.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`),s("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`)}t.end(),setTimeout(()=>{(0,o.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(g==="/api/file-picker"&&u.method==="POST"){const a=(0,F.authenticateRequest)(u);if(!a.ok){(0,n.sendJSON)(t,a.statusCode,{ok:!1,message:a.message});return}if((0,J.isFilePickerBusy)()){(0,n.sendJSON)(t,409,{ok:!1,code:y.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 r="";u.on("data",s=>{r+=s.toString()}),u.on("end",async()=>{let s=[],i=!1,p=H,d=b,l=B,c=M;if(r){let e;try{e=JSON.parse(r)}catch{(0,n.sendJSON)(t,400,{ok:!1,code:y.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(e.extensions!==void 0){if(!Array.isArray(e.extensions)||!e.extensions.every(w=>typeof w=="string")){(0,n.sendJSON)(t,400,{ok:!1,code:y.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}s=e.extensions}if(e.multiple!==void 0){if(typeof e.multiple!="boolean"){(0,n.sendJSON)(t,400,{ok:!1,code:y.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}i=e.multiple}if(e.title!==void 0){if(typeof e.title!="string"||e.title.length>200){(0,n.sendJSON)(t,400,{ok:!1,code:y.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}p=e.title}if(e.maxFileSize!==void 0){if(typeof e.maxFileSize!="number"||e.maxFileSize<=0||!Number.isFinite(e.maxFileSize)){(0,n.sendJSON)(t,400,{ok:!1,code:y.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}d=Math.min(e.maxFileSize,b)}if(e.maxFileCount!==void 0){if(typeof e.maxFileCount!="number"||e.maxFileCount<=0||!Number.isInteger(e.maxFileCount)){(0,n.sendJSON)(t,400,{ok:!1,code:y.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}l=Math.min(e.maxFileCount,B)}if(M&&e.allowDirectory!==void 0){if(typeof e.allowDirectory!="boolean"){(0,n.sendJSON)(t,400,{ok:!1,code:y.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}c=e.allowDirectory}}i||(l=1);try{const e=await(0,J.showFilePicker)({extensions:s,multiple:i,title:p,allowDirectory:c});if(!e||e.length===0){(0,n.sendJSON)(t,200,{ok:!1,code:y.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(c){const I=e.slice(0,l).map(D=>({name:$.default.basename(D),path:D,size:0,mimeType:"inode/directory"})),h=e.length>l;(0,n.sendJSON)(t,200,{ok:!0,files:I,message:h?`\u5DF2\u9009\u62E9 ${I.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${e.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${l} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${I.length} \u4E2A\u76EE\u5F55`});return}let w=!1,m=e;e.length>l&&(m=e.slice(0,l),w=!0);const O=[],S=[];for(const I of m){const h=(0,x.readFileInfo)(I,d);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 N=[];if(O.length>0&&N.push(`\u6210\u529F\u8BFB\u53D6 ${O.length} \u4E2A\u6587\u4EF6`),S.length>0){const I=S.map(h=>`${$.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");N.push(`${S.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${I}\uFF09`)}w&&N.push(`\u5171\u9009\u62E9 ${e.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${l} \u4E2A\u5DF2\u622A\u65AD`);const A=O.length===0&&S.length>0;(0,n.sendJSON)(t,200,{ok:!A,code:A?S[0].code:void 0,files:O,failedFiles:S.length>0?S:void 0,message:N.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(e){(0,o.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`);let w=y.INTERNAL_ERROR;e.message.includes("\u8D85\u65F6")?w=y.DIALOG_TIMEOUT:e.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(w=y.PLATFORM_NOT_SUPPORTED),(0,n.sendJSON)(t,500,{ok:!1,code:w,files:[],message:`\u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`})}});return}if(g.startsWith("/api/reveal")){console.log(`[reveal] \u5B8C\u6574URL: ${g}`);const a=(0,F.authenticateRequest)(u);if(!a.ok){(0,n.sendJSON)(t,a.statusCode,{status:"\u5931\u8D25",message:a.message});return}const s=new URL(g,"http://localhost").searchParams.get("path")?.replace(/ /g,"+")??null;if(!s){(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 i;try{i=Buffer.from(s,"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(!i||i.trim()===""){(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const p=(0,x.validateFilePath)(i);if(!p.valid){const m=p.reason;m.includes("\u975E\u6CD5\u5B57\u7B26")?(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):m.includes("\u4E0D\u5B58\u5728")?(0,n.sendJSON)(t,404,{status:"\u5931\u8D25",message:m}):m.includes("\u65E0\u6CD5\u89E3\u6790")?(0,n.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):((0,o.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${i}\uFF0C\u539F\u56E0: ${m}`),(0,n.sendJSON)(t,403,{status:"\u5931\u8D25",message:m}));return}const d=$.default.resolve(i),l=process.platform;let c,e,w={stdio:"ignore",windowsHide:!0};l==="darwin"?(c="open",e=["-R",d]):l==="win32"?(c="explorer.exe",e=[`/select,"${d}"`],w={...w,shell:!0}):(c="xdg-open",e=[$.default.dirname(d)]),(0,o.log)(`\u6267\u884C\u547D\u4EE4: ${c} ${e.join(" ")}`);try{await new Promise((m,O)=>{const S=(0,C.spawn)(c,e,w),N=setTimeout(()=>{S.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);S.on("close",A=>{clearTimeout(N),l==="win32"||A===0||A===1?m():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${A}`))}),S.on("error",A=>{clearTimeout(N),O(A)})}),(0,o.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${d}`),(0,n.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${d}`})}catch(m){(0,o.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 T=null,E=null;function W(u){if(!u)return;if(T&&E===u){(0,o.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${u}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}T?((0,o.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${E}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${u}`),clearInterval(T),T=null,E=null):(0,o.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${u}`);const t=setInterval(()=>{try{process.kill(u,0)}catch{(0,o.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${u} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(t),T=null,E=null,(0,_.stopGateway)(),(0,_.clearState)(),(0,o.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,o.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,o.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);t.unref(),T=t,E=u}
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=j,exports.watchParentProcess=M;const W=L(require("http")),y=L(require("fs")),I=L(require("path")),g=require("./config"),a=require("./utils"),i=require("./reportLog"),k=require("./installer"),U=require("./build"),_=require("./state"),$=require("child_process"),G=require("./service"),J=require("./filePicker"),x=require("./fileSecurityCheck"),Q=require("./authMiddleware"),q=require("./qbotclaw-routes"),H="\u9009\u62E9\u6587\u4EF6",F=10485760,b=10,B=!1,S={CANCELLED:"CANCELLED",INVALID_PARAMS:"INVALID_PARAMS",DIALOG_BUSY:"DIALOG_BUSY",DIALOG_TIMEOUT:"DIALOG_TIMEOUT",PLATFORM_NOT_SUPPORTED:"PLATFORM_NOT_SUPPORTED",INTERNAL_ERROR:"INTERNAL_ERROR"},V=require("./openai-proxy"),K=require("./api/auth-client");let v=new K.AuthClient({usePipe:!0});function z(d){v=d}function j(){return v}const T={"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 Y(d){for(const[t,p]of Object.entries(T))d.setHeader(t,p)}exports.server=W.default.createServer(async(d,t)=>{const p=d.url||"";if(Y(t),d.method==="OPTIONS"){t.writeHead(204,T),t.end();return}if(p.startsWith("/v1/")){await(0,V.handleOpenAIProxy)(d,t,v);return}const R=(0,Q.authenticateRequest)(d);if(!R.ok){(0,a.sendJSON)(t,R.statusCode,{ok:!1,status:"\u5931\u8D25",message:R.message});return}if(p==="/api/version"){let n="unknown";try{n=(await(0,a.execCommand)(`"${g.NODE_BIN}" -v`)).trim(),(0,i.log)(`[version] node \u7248\u672C: ${n}`)}catch(o){(0,i.log)(`[version] \u83B7\u53D6 node \u7248\u672C\u5931\u8D25: ${o.message}`),n=`error: ${o.message}`}const r=await(0,a.getQBotClawVersion)()??"0.0.0";(0,i.log)(`[version] qbotclaw \u7248\u672C: ${r}`);let s="0.0.0";if(y.default.existsSync(g.PYTHON_BIN))try{s=(await(0,a.execCommand)(`"${g.PYTHON_BIN}" --version`)).trim(),(0,i.log)(`[version] python \u7248\u672C: ${s}`)}catch(o){(0,i.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${o.message}`),s=`error: ${o.message}`}(0,a.sendJSON)(t,200,{status:"\u6210\u529F",launcher:U.LAUNCHER_VERSION,node:n,qbotclaw:r,python:s});return}if(p==="/api/port"){const n=exports.server.address(),r=n&&typeof n=="object"?n.port:null,s=(0,_.readState)();(0,a.sendJSON)(t,200,{status:"\u6210\u529F",launcher:r,qbotclaw:s.gatewayPort??2e3,mcpWs:s.mcpWsPort??8765}),(0,i.log)(`[port] launcher: ${r}, qbotclaw: ${s.gatewayPort}, mcpWs: ${s.mcpWsPort}`);return}if(p==="/api/status"){const n=(0,_.readState)(),r=[];if(n.gatewayPid)try{process.kill(n.gatewayPid,0)}catch{r.push(`gateway \u8FDB\u7A0B (pid: ${n.gatewayPid}) \u5DF2\u9000\u51FA`)}else r.push("gateway \u8FDB\u7A0B\u672A\u542F\u52A8\uFF08\u72B6\u6001\u4E2D\u65E0 gatewayPid\uFF09");const s=[{name:"gateway",port:n.gatewayPort},{name:"mcpWs",port:n.mcpWsPort}];for(const{name:o,port:f}of s){if(!f){r.push(`${o} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,_.isPortAvailable)(f)&&r.push(`${o} \u7AEF\u53E3 (${f}) \u65E0\u670D\u52A1\u76D1\u542C`)}r.length===0?(0,a.sendJSON)(t,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,a.sendJSON)(t,200,{ok:!1,message:r.join("\uFF1B")});return}if(p==="/api/restart"){try{const n=(0,_.readState)();if(n.gatewayPid)try{process.kill(n.gatewayPid,"SIGTERM"),(0,i.log)(`[restart] \u5DF2\u53D1\u9001 SIGTERM \u7ED9\u65E7 gateway \u8FDB\u7A0B pid: ${n.gatewayPid}`)}catch{(0,i.log)(`[restart] \u65E7 gateway \u8FDB\u7A0B ${n.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA\uFF0C\u5FFD\u7565`)}const{gatewayPid:r,gatewayPort:s,mcpWsPort:o,...f}=n;(0,_.writeState)(f),(0,i.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpWsPort"),await(0,k.configAndRunQBotClaw)(),(0,i.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const c=(0,_.readState)(),l=exports.server.address(),e=l&&typeof l=="object"?l.port:null;(0,a.sendJSON)(t,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:e,qbotclaw:c.gatewayPort??2e3,mcpWs:c.mcpWsPort??8765,gatewayToken:(0,G.getOrCreateGatewayToken)()})}catch(n){(0,i.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(t,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${n.message}`})}return}if(p==="/api/wechat/history"){try{if(!y.default.existsSync(g.SESSIONS_FILE)){(0,a.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const n=JSON.parse(y.default.readFileSync(g.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[c,l]of Object.entries(n))if(c.includes("openclaw-weixin")){const u=l.updatedAt??0;u>s&&(s=u,r=c)}if(!r){(0,a.sendJSON)(t,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const f=r.split(":").slice(2).join(":");(0,a.sendJSON)(t,200,{ok:!0,sessionKey:f,message:"\u83B7\u53D6\u6210\u529F"})}catch(n){(0,i.log)(`[wechat/history] \u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(t,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${n.message}`})}return}if(p==="/api/chat/latest"){try{if(!y.default.existsSync(g.SESSIONS_FILE)){(0,a.sendJSON)(t,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const n=JSON.parse(y.default.readFileSync(g.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[f,c]of Object.entries(n)){if(f.includes("openclaw-weixin"))continue;const e=c.updatedAt??0;e>s&&(s=e,r=f)}if(!r){(0,a.sendJSON)(t,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u975E\u5FAE\u4FE1\u4F1A\u8BDD"});return}const o=n[r];(0,a.sendJSON)(t,200,{ok:!0,sessionId:o.sessionId??"",sessionKey:r,updatedAt:s,message:"\u83B7\u53D6\u6210\u529F"})}catch(n){(0,i.log)(`[chat/latest] \u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${n.message}`),(0,a.sendJSON)(t,500,{ok:!1,sessionId:"",message:`\u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${n.message}`})}return}if(p==="/api/installing"){(0,a.sendJSON)(t,200,{installing:k.isInstalling});return}if(p==="/api/install"||p.startsWith("/api/install?")){const n=new URL(p,"http://localhost"),r=n.searchParams.get("version")||void 0,s=n.searchParams.get("overrideConfig")==="true";if(!r){(0,a.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}if(!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(r)){(0,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:`version \u53C2\u6570\u683C\u5F0F\u4E0D\u5408\u6CD5\uFF08${r}\uFF09\uFF0C\u5FC5\u987B\u4E3A\u4E09\u6BB5\u5F0F\u7248\u672C\u53F7\uFF0C\u4F8B\u5982 1.2.3`});return}t.writeHead(200,{...T,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,k.runInstall)(t,r,s);return}if(p.startsWith("/api/watch")){const r=new URL(p,"http://localhost").searchParams.get("ppid");if(!r||isNaN(Number(r))){(0,a.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 s=parseInt(r,10);try{process.kill(s,0)}catch{(0,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${s} \u4E0D\u5B58\u5728`});return}const o=(0,_.readState)();(0,_.writeState)({...o,ppid:s}),M(s),(0,a.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${s}`});return}if(!(p.startsWith("/api/qbotclaw/")&&await(0,q.handleQBotClawRoutes)(d,t,p))){if(p.startsWith("/api/uninstall")){const r=new URL(p,"http://localhost").searchParams.get("keepWorkspace")==="true";t.writeHead(200,{...T,"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const s=(o,f,c)=>{if(t.writable)try{t.write(JSON.stringify({status:o,file:f,msg:c})+`
2
+ `)}catch{}};try{s("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const o=(0,_.readState)();if(o.gatewayPid)try{process.kill(o.gatewayPid,"SIGTERM"),(0,i.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${o.gatewayPid}`),s("\u6210\u529F","",`\u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${o.gatewayPid}`)}catch{(0,i.log)(`[uninstall] QBotClaw gateway \u8FDB\u7A0B ${o.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`),s("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${o.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 ${g.NPM_PACKAGE_NAME}...`);try{await new Promise((c,l)=>{const e=(0,$.spawn)(g.NPM_BIN,["--userconfig",g.NPM_RC,"uninstall","-g",g.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${g.NODE_BIN_DIR}${I.default.delimiter}${process.env.PATH}`},shell:process.platform==="win32",windowsHide:!0});e.stdout?.on("data",u=>{(0,i.log)(`[uninstall] npm: ${u.toString().trim()}`)}),e.stderr?.on("data",u=>{(0,i.log)(`[uninstall] npm stderr: ${u.toString().trim()}`)}),e.on("close",u=>{u===0?c():l(new Error(`npm uninstall \u9000\u51FA\u7801: ${u}`))}),e.on("error",u=>l(u))}),(0,i.log)(`[uninstall] npm uninstall -g ${g.NPM_PACKAGE_NAME} \u6210\u529F`),s("\u6210\u529F","",`npm uninstall -g ${g.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(c){(0,i.log)(`[uninstall] npm uninstall \u5931\u8D25: ${c.message}`),s("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${c.message}`)}s("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${g.QBOT_CLAW_DIR}...`);const f=[];if(y.default.existsSync(g.QBOT_CLAW_DIR)){const c=y.default.readdirSync(g.QBOT_CLAW_DIR);for(const l of c){const e=I.default.join(g.QBOT_CLAW_DIR,l);if(r&&l==="workspace"){s("\u6210\u529F",e,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{y.default.statSync(e).isDirectory()?y.default.rmSync(e,{recursive:!0,force:!0}):y.default.unlinkSync(e),s("\u6210\u529F",e,"\u5DF2\u5220\u9664")}catch(u){(0,i.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${e} - ${u.message}`),s("\u5931\u8D25",e,`\u5220\u9664\u5931\u8D25: ${u.message}`),f.push(e)}}if(f.length>0){s("\u6210\u529F","",`${f.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const l of f)try{process.platform==="win32"?(0,$.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,$.execSync)(`rm -rf "${l}"`),(0,i.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u6210\u529F: ${l}`),s("\u6210\u529F",l,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6210\u529F")}catch(e){(0,i.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${l} - ${e.message}`),s("\u5931\u8D25",l,`\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${e.message}`)}}if(r)s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{y.default.rmSync(g.QBOT_CLAW_DIR,{recursive:!0,force:!0}),s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u5DF2\u5220\u9664\u6839\u76EE\u5F55")}catch(l){(0,i.log)(`[uninstall] \u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${l.message}`);try{process.platform==="win32"?(0,$.execSync)(`rmdir /s /q "${g.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,$.execSync)(`rm -rf "${g.QBOT_CLAW_DIR}"`),s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(e){s("\u5931\u8D25",g.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${e.message}`)}}}else s("\u6210\u529F",g.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");s("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(o){(0,i.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${o.message}`),s("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${o.message}`)}t.end(),setTimeout(()=>{(0,i.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(p==="/api/file-picker"&&d.method==="POST"){if((0,J.isFilePickerBusy)()){(0,a.sendJSON)(t,409,{ok:!1,code:S.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 n="";d.on("data",r=>{n+=r.toString()}),d.on("end",async()=>{let r=[],s=!1,o=H,f=F,c=b,l=B;if(n){let e;try{e=JSON.parse(n)}catch{(0,a.sendJSON)(t,400,{ok:!1,code:S.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(e.extensions!==void 0){if(!Array.isArray(e.extensions)||!e.extensions.every(u=>typeof u=="string")){(0,a.sendJSON)(t,400,{ok:!1,code:S.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}r=e.extensions}if(e.multiple!==void 0){if(typeof e.multiple!="boolean"){(0,a.sendJSON)(t,400,{ok:!1,code:S.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}s=e.multiple}if(e.title!==void 0){if(typeof e.title!="string"||e.title.length>200){(0,a.sendJSON)(t,400,{ok:!1,code:S.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}o=e.title}if(e.maxFileSize!==void 0){if(typeof e.maxFileSize!="number"||e.maxFileSize<=0||!Number.isFinite(e.maxFileSize)){(0,a.sendJSON)(t,400,{ok:!1,code:S.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}f=Math.min(e.maxFileSize,F)}if(e.maxFileCount!==void 0){if(typeof e.maxFileCount!="number"||e.maxFileCount<=0||!Number.isInteger(e.maxFileCount)){(0,a.sendJSON)(t,400,{ok:!1,code:S.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}c=Math.min(e.maxFileCount,b)}if(B&&e.allowDirectory!==void 0){if(typeof e.allowDirectory!="boolean"){(0,a.sendJSON)(t,400,{ok:!1,code:S.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}l=e.allowDirectory}}s||(c=1);try{const e=await(0,J.showFilePicker)({extensions:r,multiple:s,title:o,allowDirectory:l});if(!e||e.length===0){(0,a.sendJSON)(t,200,{ok:!1,code:S.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(l){const A=e.slice(0,c).map(D=>({name:I.default.basename(D),path:D,size:0,mimeType:"inode/directory"})),h=e.length>c;(0,a.sendJSON)(t,200,{ok:!0,files:A,message:h?`\u5DF2\u9009\u62E9 ${A.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${e.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${A.length} \u4E2A\u76EE\u5F55`});return}let u=!1,m=e;e.length>c&&(m=e.slice(0,c),u=!0);const O=[],w=[];for(const A of m){const h=(0,x.readFileInfo)(A,f);h.ok?O.push({name:h.name,path:h.path,size:h.size,mimeType:h.mimeType}):w.push({path:h.path,reason:h.reason,code:h.code})}const N=[];if(O.length>0&&N.push(`\u6210\u529F\u8BFB\u53D6 ${O.length} \u4E2A\u6587\u4EF6`),w.length>0){const A=w.map(h=>`${I.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");N.push(`${w.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${A}\uFF09`)}u&&N.push(`\u5171\u9009\u62E9 ${e.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${c} \u4E2A\u5DF2\u622A\u65AD`);const P=O.length===0&&w.length>0;(0,a.sendJSON)(t,200,{ok:!P,code:P?w[0].code:void 0,files:O,failedFiles:w.length>0?w:void 0,message:N.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(e){(0,i.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`);let u=S.INTERNAL_ERROR;e.message.includes("\u8D85\u65F6")?u=S.DIALOG_TIMEOUT:e.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(u=S.PLATFORM_NOT_SUPPORTED),(0,a.sendJSON)(t,500,{ok:!1,code:u,files:[],message:`\u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`})}});return}if(p.startsWith("/api/reveal")){console.log(`[reveal] \u5B8C\u6574URL: ${p}`);const r=new URL(p,"http://localhost").searchParams.get("path")?.replace(/ /g,"+")??null;if(!r){(0,a.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 s;try{s=Buffer.from(r,"base64").toString("utf-8")}catch{(0,a.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(!s||s.trim()===""){(0,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const o=(0,x.validateFilePath)(s);if(!o.valid){const m=o.reason;m.includes("\u975E\u6CD5\u5B57\u7B26")?(0,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):m.includes("\u4E0D\u5B58\u5728")?(0,a.sendJSON)(t,404,{status:"\u5931\u8D25",message:m}):m.includes("\u65E0\u6CD5\u89E3\u6790")?(0,a.sendJSON)(t,400,{status:"\u5931\u8D25",message:m}):((0,i.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${s}\uFF0C\u539F\u56E0: ${m}`),(0,a.sendJSON)(t,403,{status:"\u5931\u8D25",message:m}));return}const f=I.default.resolve(s),c=process.platform;let l,e,u={stdio:"ignore",windowsHide:!0};c==="darwin"?(l="open",e=["-R",f]):c==="win32"?(l="explorer.exe",e=[`/select,"${f}"`],u={...u,shell:!0}):(l="xdg-open",e=[I.default.dirname(f)]),(0,i.log)(`\u6267\u884C\u547D\u4EE4: ${l} ${e.join(" ")}`);try{await new Promise((m,O)=>{const w=(0,$.spawn)(l,e,u),N=setTimeout(()=>{w.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);w.on("close",P=>{clearTimeout(N),c==="win32"||P===0||P===1?m():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${P}`))}),w.on("error",P=>{clearTimeout(N),O(P)})}),(0,i.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${f}`),(0,a.sendJSON)(t,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${f}`})}catch(m){(0,i.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`),(0,a.sendJSON)(t,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`})}return}(0,a.sendJSON)(t,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})}});let E=null,C=null;function M(d){if(!d)return;if(E&&C===d){(0,i.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}E?((0,i.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${C}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${d}`),clearInterval(E),E=null,C=null):(0,i.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${d}`);const t=setInterval(()=>{try{process.kill(d,0)}catch{(0,i.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${d} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(t),E=null,C=null,(0,_.stopGateway)(),(0,_.clearState)(),(0,i.log)("[watchParentProcess] \u72B6\u6001\u5DF2\u6E05\u7406\uFF0C\u5173\u95ED server \u5E76\u9000\u51FA"),exports.server.close(()=>{(0,i.log)("[watchParentProcess] server \u5DF2\u5173\u95ED\uFF0C\u8FDB\u7A0B\u9000\u51FA"),process.exit(0)}),setTimeout(()=>{(0,i.log)("[watchParentProcess] server.close \u8D85\u65F6\uFF0C\u5F3A\u5236\u9000\u51FA"),process.exit(0)},3e3).unref()}},3e3);t.unref(),E=t,C=d}
package/dist/service.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var S=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.readCurrentGatewayToken=w,exports.getOrCreateGatewayToken=v,exports.startService=b,exports.stopService=O;const f=S(require("fs")),k=require("crypto"),y=require("./server"),t=require("./state"),p=require("./config"),_=require("./build"),q=require("./installer"),T=require("./utils"),r=require("./reportLog"),o=require("./report");let d,s;const g="0526bec85002fe65ef10d33df0a8dfbe76917cd125f5a4ad";function w(){try{if(!f.default.existsSync(p.QBOT_CLAW_CONFIG_PATH))return(0,r.log)(`[service] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728: ${p.QBOT_CLAW_CONFIG_PATH}`),g;const e=f.default.readFileSync(p.QBOT_CLAW_CONFIG_PATH,"utf-8");return JSON.parse(e)?.gateway?.auth?.token||g}catch(e){return(0,r.log)(`[service] \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6 gateway.auth.token \u5931\u8D25: ${e.message}`),g}}function v(){return s||(s=require("crypto").randomBytes(24).toString("hex"),(0,r.log)(`[service] \u751F\u6210\u65B0\u7684 gateway token: ${s}`),s||w())}async function $(){const e=(0,t.readState)();if(!e.pid||!e.port)return null;try{process.kill(e.pid,0)}catch{return(0,t.clearState)(),null}if(await(0,t.isPortAvailable)(e.port))return(0,r.log)("\u7AEF\u53E3\u672A\u88AB\u5360\u7528\uFF0C\u8BF4\u660E\u72B6\u6001\u6587\u4EF6\u8FC7\u671F"),(0,t.clearState)(),null;const i=e.launcherVersion??null;if((0,r.log)(`[service] \u68C0\u6D4B\u5230\u6B63\u5728\u8FD0\u884C\u7684\u670D\u52A1\u7248\u672C: ${i??"unknown"}\uFF0C\u5F53\u524D\u7248\u672C: ${_.LAUNCHER_VERSION}`),i===_.LAUNCHER_VERSION)return(0,r.log)(`[service] \u7248\u672C\u4E00\u81F4\uFF0C\u590D\u7528\u5DF2\u6709\u670D\u52A1 (pid: ${e.pid}, port: ${e.port})`),!1;(0,r.log)(`[service] \u7248\u672C\u4E0D\u4E00\u81F4 (\u8FD0\u884C\u4E2D: ${i??"unknown"}, \u5F53\u524D: ${_.LAUNCHER_VERSION})\uFF0C\u6740\u6389\u65E7\u8FDB\u7A0B pid: ${e.pid}\uFF0C\u91CD\u65B0\u542F\u52A8`);try{process.kill(e.pid,"SIGTERM")}catch{}return(0,t.clearState)(),!0}async function b(e,n){if(await $()===!1){const a=(0,t.readState)();process.stdout.write(JSON.stringify({state:"success",pid:a.pid,port:a.port,gatewayToken:w()})+`
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 c=await(0,t.findAvailablePort)();y.server.listen(c,"127.0.0.1",async()=>{d=(0,k.randomUUID)(),(0,t.writeState)({pid:process.pid,port:c,token:d,launcherVersion:_.LAUNCHER_VERSION,...e?{ppid:e}:{}}),(0,y.watchParentProcess)(e),(0,o.report)({event_name:"qbot_claw_try_start"});let a;if(f.default.existsSync(p.QBOTCLAW_BIN))try{const l=await(0,T.getQBotClawVersion)(),u=(0,t.readState)();l!==n?((0,r.log)(`[service] qbotclaw \u672C\u5730\u7248\u672C (${l??"unknown"}) \u4E0E\u671F\u671B\u7248\u672C (${n}) \u4E0D\u4E00\u81F4\uFF0C\u505C\u6B62\u5F53\u524D qbotclaw \u8FDB\u7A0B`),(0,o.report)({event_name:"qbot_claw_need_update"}),(0,t.stopGateway)()):u.gatewayPid&&u.gatewayPort?((0,r.log)(`[service] qbotclaw \u5DF2\u5728\u8FD0\u884C\uFF0Cpid: ${u.gatewayPid}, port: ${u.gatewayPort}`),a=w(),(0,o.report)({event_name:"qbot_claw_version_match"}),(0,o.report)({event_name:"qbot_claw_reuse"})):((0,r.log)("[service] \u68C0\u6D4B\u5230 qbotclaw\uFF0C\u7248\u672C\u5339\u914D\uFF0C\u81EA\u52A8\u542F\u52A8 gateway..."),(0,o.report)({event_name:"qbot_claw_version_match"}),await(0,q.configAndRunQBotClaw)(),a=v())}catch(l){(0,r.log)(`[service] \u81EA\u52A8\u542F\u52A8 gateway \u5931\u8D25: ${l.message}`)}else(0,r.log)("[service] qbotclaw \u672A\u5B89\u88C5\uFF0C\u4E0D\u81EA\u52A8\u542F\u52A8"),(0,o.report)({event_name:"qbot_claw_need_install"});(0,r.log)(`[service] \u670D\u52A1\u542F\u52A8\u6210\u529F\uFF0Cpid: ${process.pid}, port: ${c}, token: ${d}`),process.stdout.write(JSON.stringify({state:"success",pid:process.pid,port:c,token:d,gatewayToken:a})+`
1
+ "use strict";var S=exports&&exports.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.readCurrentGatewayToken=w,exports.getOrCreateGatewayToken=y,exports.startService=b,exports.stopService=O;const f=S(require("fs")),k=require("crypto"),v=require("./server"),t=require("./state"),p=require("./config"),_=require("./build"),q=require("./installer"),T=require("./utils"),r=require("./reportLog"),o=require("./report");let d,s;const g="0526bec85002fe65ef10d33df0a8dfbe76917cd125f5a4ad";function w(){try{if(!f.default.existsSync(p.QBOT_CLAW_CONFIG_PATH))return(0,r.log)(`[service] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728: ${p.QBOT_CLAW_CONFIG_PATH}`),g;const e=f.default.readFileSync(p.QBOT_CLAW_CONFIG_PATH,"utf-8");return JSON.parse(e)?.gateway?.auth?.token||g}catch(e){return(0,r.log)(`[service] \u8BFB\u53D6\u914D\u7F6E\u6587\u4EF6 gateway.auth.token \u5931\u8D25: ${e.message}`),g}}function y(){return s||(s=require("crypto").randomBytes(24).toString("hex"),(0,r.log)(`[service] \u751F\u6210\u65B0\u7684 gateway token: ${s}`),s||w())}async function $(){const e=(0,t.readState)();if(!e.pid||!e.port)return null;try{process.kill(e.pid,0)}catch{return(0,t.clearState)(),null}if(await(0,t.isPortAvailable)(e.port))return(0,r.log)("\u7AEF\u53E3\u672A\u88AB\u5360\u7528\uFF0C\u8BF4\u660E\u72B6\u6001\u6587\u4EF6\u8FC7\u671F"),(0,t.clearState)(),null;const i=e.launcherVersion??null;if((0,r.log)(`[service] \u68C0\u6D4B\u5230\u6B63\u5728\u8FD0\u884C\u7684\u670D\u52A1\u7248\u672C: ${i??"unknown"}\uFF0C\u5F53\u524D\u7248\u672C: ${_.LAUNCHER_VERSION}`),i===_.LAUNCHER_VERSION)return(0,r.log)(`[service] \u7248\u672C\u4E00\u81F4\uFF0C\u590D\u7528\u5DF2\u6709\u670D\u52A1 (pid: ${e.pid}, port: ${e.port})`),!1;(0,r.log)(`[service] \u7248\u672C\u4E0D\u4E00\u81F4 (\u8FD0\u884C\u4E2D: ${i??"unknown"}, \u5F53\u524D: ${_.LAUNCHER_VERSION})\uFF0C\u6740\u6389\u65E7\u8FDB\u7A0B pid: ${e.pid}\uFF0C\u91CD\u65B0\u542F\u52A8`);try{process.kill(e.pid,"SIGTERM")}catch{}return(0,t.clearState)(),!0}async function b(e,n){if(await $()===!1){const a=(0,t.readState)();process.stdout.write(JSON.stringify({state:"success",pid:a.pid,port:a.port,gatewayToken:w()})+`
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 c=await(0,t.findAvailablePort)();v.server.listen(c,"127.0.0.1",async()=>{d=(0,k.randomUUID)(),(0,t.writeState)({pid:process.pid,port:c,token:d,launcherVersion:_.LAUNCHER_VERSION,...e?{ppid:e}:{}}),(0,v.watchParentProcess)(e),(0,o.report)({event_name:"qbot_claw_try_start"});let a=y();if(f.default.existsSync(p.QBOTCLAW_BIN))try{const l=await(0,T.getQBotClawVersion)(),u=(0,t.readState)();l!==n?((0,r.log)(`[service] qbotclaw \u672C\u5730\u7248\u672C (${l??"unknown"}) \u4E0E\u671F\u671B\u7248\u672C (${n}) \u4E0D\u4E00\u81F4\uFF0C\u505C\u6B62\u5F53\u524D qbotclaw \u8FDB\u7A0B`),(0,o.report)({event_name:"qbot_claw_need_update"}),(0,t.stopGateway)()):u.gatewayPid&&u.gatewayPort?((0,r.log)(`[service] qbotclaw \u5DF2\u5728\u8FD0\u884C\uFF0Cpid: ${u.gatewayPid}, port: ${u.gatewayPort}`),a=w(),(0,o.report)({event_name:"qbot_claw_version_match"}),(0,o.report)({event_name:"qbot_claw_reuse"})):((0,r.log)("[service] \u68C0\u6D4B\u5230 qbotclaw\uFF0C\u7248\u672C\u5339\u914D\uFF0C\u81EA\u52A8\u542F\u52A8 gateway..."),(0,o.report)({event_name:"qbot_claw_version_match"}),await(0,q.configAndRunQBotClaw)(),a=y())}catch(l){(0,r.log)(`[service] \u81EA\u52A8\u542F\u52A8 gateway \u5931\u8D25: ${l.message}`)}else(0,r.log)("[service] qbotclaw \u672A\u5B89\u88C5\uFF0C\u4E0D\u81EA\u52A8\u542F\u52A8"),(0,o.report)({event_name:"qbot_claw_need_install"});(0,r.log)(`[service] \u670D\u52A1\u542F\u52A8\u6210\u529F\uFF0Cpid: ${process.pid}, port: ${c}, token: ${d}`),process.stdout.write(JSON.stringify({state:"success",pid:process.pid,port:c,token:d,gatewayToken:a})+`
3
3
  `),process.stdout.uncork()}),process.on("SIGTERM",()=>{(0,t.stopGateway)(),(0,t.clearState)(),(0,r.flushLogs)().finally(()=>{process.exit(0)})})}function O(){(0,t.stopGateway)();const e=(0,t.readState)();if(!e.pid){(0,t.clearState)();return}try{process.kill(e.pid,"SIGTERM")}catch{}(0,t.clearState)()}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qqbrowser/qbot-claw-launcher",
3
- "version": "0.10.18",
3
+ "version": "0.10.20",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {