@qqbrowser/qbot-claw-launcher 0.10.26 → 0.10.27

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/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.26",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.27",exports.IS_DEBUG_BUILD=!1;
package/dist/server.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var R=exports&&exports.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.watchParentProcess=x;const F=R(require("http")),S=R(require("fs")),N=R(require("path")),d=require("./config"),n=require("./utils"),B=require("./history-viewer"),o=require("./reportLog"),C=require("./installer"),M=require("./build"),y=require("./state"),$=require("child_process"),W=require("./service"),L=require("./filePicker"),k=require("./fileSecurityCheck"),b=require("./authMiddleware"),U=require("./qbotclaw-routes"),v=10485760,D=10,J=!1,w={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"),Q=require("./api/auth-client");let G=new Q.AuthClient({usePipe:!0});exports.server=F.default.createServer(async(m,s)=>{const p=m.url||"";if(p.startsWith("/v1/")){await(0,q.handleOpenAIProxy)(m,s,G);return}const E=(0,b.authenticateRequest)(m);if(!E.ok){(0,n.sendJSON)(s,E.statusCode,{ok:!1,status:"\u5931\u8D25",message:E.message});return}if(p==="/api/version"){let a="unknown";try{a=(await(0,n.execCommand)(`"${d.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 t="0.0.0";if(S.default.existsSync(d.PYTHON_BIN))try{t=(await(0,n.execCommand)(`"${d.PYTHON_BIN}" --version`)).trim(),(0,o.log)(`[version] python \u7248\u672C: ${t}`)}catch(i){(0,o.log)(`[version] \u83B7\u53D6 python \u7248\u672C\u5931\u8D25: ${i.message}`),t=`error: ${i.message}`}(0,n.sendJSON)(s,200,{status:"\u6210\u529F",launcher:M.LAUNCHER_VERSION,node:a,qbotclaw:r,python:t});return}if(p==="/api/port"){const a=exports.server.address(),r=a&&typeof a=="object"?a.port:null,t=(0,y.readState)();(0,n.sendJSON)(s,200,{status:"\u6210\u529F",launcher:r,qbotclaw:t.gatewayPort??2e3,mcpWs:t.mcpWsPort??8765}),(0,o.log)(`[port] launcher: ${r}, qbotclaw: ${t.gatewayPort}, mcpWs: ${t.mcpWsPort}`);return}if(p==="/api/status"){const a=(0,y.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 t=[{name:"gateway",port:a.gatewayPort},{name:"mcpWs",port:a.mcpWsPort}];for(const{name:i,port:u}of t){if(!u){r.push(`${i} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,y.isPortAvailable)(u)&&r.push(`${i} \u7AEF\u53E3 (${u}) \u65E0\u670D\u52A1\u76D1\u542C`)}r.length===0?(0,n.sendJSON)(s,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,n.sendJSON)(s,200,{ok:!1,message:r.join("\uFF1B")});return}if(p==="/api/restart"){try{const a=(0,y.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:t,mcpWsPort:i,...u}=a;(0,y.writeState)(u),(0,o.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpWsPort"),await(0,C.configAndRunQBotClaw)(),(0,o.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const e=(0,y.readState)(),l=exports.server.address(),c=l&&typeof l=="object"?l.port:null;(0,n.sendJSON)(s,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:c,qbotclaw:e.gatewayPort??2e3,mcpWs:e.mcpWsPort??8765,gatewayToken:(0,W.getOrCreateGatewayToken)()})}catch(a){(0,o.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(s,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${a.message}`})}return}if(p==="/api/wechat/history"){try{if(!S.default.existsSync(d.SESSIONS_FILE)){(0,n.sendJSON)(s,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(S.default.readFileSync(d.SESSIONS_FILE,"utf-8"));let r=null,t=0;for(const[e,l]of Object.entries(a))if(e.includes("openclaw-weixin")){const f=l.updatedAt??0;f>t&&(t=f,r=e)}if(!r){(0,n.sendJSON)(s,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const u=r.split(":").slice(2).join(":");(0,n.sendJSON)(s,200,{ok:!0,sessionKey:u,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)(s,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(p==="/api/chat/latest"){try{if(!S.default.existsSync(d.SESSIONS_FILE)){(0,n.sendJSON)(s,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(S.default.readFileSync(d.SESSIONS_FILE,"utf-8"));let r=null,t=0;for(const[u,e]of Object.entries(a)){if(u.includes("openclaw-weixin"))continue;const c=e.updatedAt??0;c>t&&(t=c,r=u)}if(!r){(0,n.sendJSON)(s,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u975E\u5FAE\u4FE1\u4F1A\u8BDD"});return}const i=a[r];(0,n.sendJSON)(s,200,{ok:!0,sessionId:i.sessionId??"",sessionKey:r,updatedAt:t,message:"\u83B7\u53D6\u6210\u529F"})}catch(a){(0,o.log)(`[chat/latest] \u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(s,500,{ok:!1,sessionId:"",message:`\u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(p==="/api/chat/history"){(0,B.getChatHistory)().then(a=>{(0,n.sendJSON)(s,200,{ok:!0,data:a,message:"\u83B7\u53D6\u6210\u529F"})}).catch(a=>{(0,o.log)(`[chat/history] \u8BFB\u53D6\u5386\u53F2\u8BB0\u5F55\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(s,500,{ok:!1,data:[],message:`\u8BFB\u53D6\u5386\u53F2\u8BB0\u5F55\u5931\u8D25: ${a.message}`})});return}if(p==="/api/installing"){(0,n.sendJSON)(s,200,{installing:C.isInstalling});return}if(p==="/api/install"||p.startsWith("/api/install?")){const a=new URL(p,"http://localhost"),r=a.searchParams.get("version")||void 0,t=a.searchParams.get("overrideConfig")==="true";if(!r){(0,n.sendJSON)(s,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,n.sendJSON)(s,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}s.writeHead(200,{"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,C.runInstall)(s,r,t);return}if(p.startsWith("/api/watch")){const r=new URL(p,"http://localhost").searchParams.get("ppid");if(!r||isNaN(Number(r))){(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u6709\u6548\u7684 ppid \u53C2\u6570\uFF0C\u7528\u6CD5: GET /api/watch?ppid=12345"});return}const t=parseInt(r,10);try{process.kill(t,0)}catch{(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:`\u8FDB\u7A0B ${t} \u4E0D\u5B58\u5728`});return}const i=(0,y.readState)();(0,y.writeState)({...i,ppid:t}),x(t),(0,n.sendJSON)(s,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${t}`});return}if(!(p.startsWith("/api/qbotclaw/")&&await(0,U.handleQBotClawRoutes)(m,s,p))){if(p.startsWith("/api/uninstall")){const r=new URL(p,"http://localhost").searchParams.get("keepWorkspace")==="true";s.writeHead(200,{"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const t=(i,u,e)=>{if(s.writable)try{s.write(JSON.stringify({status:i,file:u,msg:e})+`
2
- `)}catch{}};try{t("\u6210\u529F","","\u6B63\u5728\u505C\u6B62 QBotClaw...");const i=(0,y.readState)();if(i.gatewayPid)try{process.kill(i.gatewayPid,"SIGTERM"),(0,o.log)(`[uninstall] \u5DF2\u505C\u6B62 QBotClaw gateway \u8FDB\u7A0B pid: ${i.gatewayPid}`),t("\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`),t("\u6210\u529F","",`QBotClaw gateway \u8FDB\u7A0B ${i.gatewayPid} \u53EF\u80FD\u5DF2\u9000\u51FA`)}else t("\u6210\u529F","","QBotClaw \u672A\u5728\u8FD0\u884C");t("\u6210\u529F","",`\u6B63\u5728\u6267\u884C npm uninstall -g ${d.NPM_PACKAGE_NAME}...`);try{await new Promise((e,l)=>{const c=(0,$.spawn)(d.NPM_BIN,["--userconfig",d.NPM_RC,"uninstall","-g",d.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${d.NODE_BIN_DIR}${N.default.delimiter}${process.env.PATH}`},shell:process.platform==="win32",windowsHide:!0});c.stdout?.on("data",f=>{(0,o.log)(`[uninstall] npm: ${f.toString().trim()}`)}),c.stderr?.on("data",f=>{(0,o.log)(`[uninstall] npm stderr: ${f.toString().trim()}`)}),c.on("close",f=>{f===0?e():l(new Error(`npm uninstall \u9000\u51FA\u7801: ${f}`))}),c.on("error",f=>l(f))}),(0,o.log)(`[uninstall] npm uninstall -g ${d.NPM_PACKAGE_NAME} \u6210\u529F`),t("\u6210\u529F","",`npm uninstall -g ${d.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(e){(0,o.log)(`[uninstall] npm uninstall \u5931\u8D25: ${e.message}`),t("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${e.message}`)}t("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${d.QBOT_CLAW_DIR}...`);const u=[];if(S.default.existsSync(d.QBOT_CLAW_DIR)){const e=S.default.readdirSync(d.QBOT_CLAW_DIR);for(const l of e){const c=N.default.join(d.QBOT_CLAW_DIR,l);if(r&&l==="workspace"){t("\u6210\u529F",c,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{S.default.statSync(c).isDirectory()?S.default.rmSync(c,{recursive:!0,force:!0}):S.default.unlinkSync(c),t("\u6210\u529F",c,"\u5DF2\u5220\u9664")}catch(f){(0,o.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${c} - ${f.message}`),t("\u5931\u8D25",c,`\u5220\u9664\u5931\u8D25: ${f.message}`),u.push(c)}}if(u.length>0){t("\u6210\u529F","",`${u.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const l of u)try{process.platform==="win32"?(0,$.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,$.execSync)(`rm -rf "${l}"`),(0,o.log)(`[uninstall] \u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u6210\u529F: ${l}`),t("\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}`),t("\u5931\u8D25",l,`\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u4E5F\u5931\u8D25: ${c.message}`)}}if(r)t("\u6210\u529F",d.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{S.default.rmSync(d.QBOT_CLAW_DIR,{recursive:!0,force:!0}),t("\u6210\u529F",d.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,$.execSync)(`rmdir /s /q "${d.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,$.execSync)(`rm -rf "${d.QBOT_CLAW_DIR}"`),t("\u6210\u529F",d.QBOT_CLAW_DIR,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(c){t("\u5931\u8D25",d.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.message}`)}}}else t("\u6210\u529F",d.QBOT_CLAW_DIR,"\u76EE\u5F55\u4E0D\u5B58\u5728\uFF0C\u65E0\u9700\u6E05\u7406");t("\u6210\u529F","","\u5378\u8F7D\u5B8C\u6210")}catch(i){(0,o.log)(`[uninstall] \u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`),t("\u5931\u8D25","",`\u5378\u8F7D\u8FC7\u7A0B\u5F02\u5E38: ${i.message}`)}s.end(),setTimeout(()=>{(0,o.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(p==="/api/file-picker"&&m.method==="POST"){if((0,L.isFilePickerBusy)()){(0,n.sendJSON)(s,409,{ok:!1,code:w.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 a="";m.on("data",r=>{a+=r.toString()}),m.on("end",async()=>{let r=!1,t=v,i=D,u=J;if(a){let e;try{e=JSON.parse(a)}catch{(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(e.extensions!==void 0&&(!Array.isArray(e.extensions)||!e.extensions.every(l=>typeof l=="string"))){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}if(e.multiple!==void 0){if(typeof e.multiple!="boolean"){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}r=e.multiple}if(e.title!==void 0&&(typeof e.title!="string"||e.title.length>200)){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}if(e.maxFileSize!==void 0){if(typeof e.maxFileSize!="number"||e.maxFileSize<=0||!Number.isFinite(e.maxFileSize)){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}t=Math.min(e.maxFileSize,v)}if(e.maxFileCount!==void 0){if(typeof e.maxFileCount!="number"||e.maxFileCount<=0||!Number.isInteger(e.maxFileCount)){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}i=Math.min(e.maxFileCount,D)}if(J&&e.allowDirectory!==void 0){if(typeof e.allowDirectory!="boolean"){(0,n.sendJSON)(s,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}u=e.allowDirectory}}r||(i=1);try{const e=await(0,L.showFilePicker)({multiple:r,allowDirectory:u});if(!e||e.length===0){(0,n.sendJSON)(s,200,{ok:!1,code:w.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(u){const _=e.slice(0,i).map(T=>({name:N.default.basename(T),path:T,size:0,mimeType:"inode/directory"})),h=e.length>i;(0,n.sendJSON)(s,200,{ok:!0,files:_,message:h?`\u5DF2\u9009\u62E9 ${_.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${e.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${i} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${_.length} \u4E2A\u76EE\u5F55`});return}let l=!1,c=e;e.length>i&&(c=e.slice(0,i),l=!0);const f=[],g=[];for(const _ of c){const h=(0,k.readFileInfo)(_,t);h.ok?f.push({name:h.name,path:h.path,size:h.size,mimeType:h.mimeType}):g.push({path:h.path,reason:h.reason,code:h.code})}const O=[];if(f.length>0&&O.push(`\u6210\u529F\u8BFB\u53D6 ${f.length} \u4E2A\u6587\u4EF6`),g.length>0){const _=g.map(h=>`${N.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");O.push(`${g.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${_}\uFF09`)}l&&O.push(`\u5171\u9009\u62E9 ${e.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${i} \u4E2A\u5DF2\u622A\u65AD`);const P=f.length===0&&g.length>0;(0,n.sendJSON)(s,200,{ok:!P,code:P?g[0].code:void 0,files:f,failedFiles:g.length>0?g:void 0,message:O.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(e){(0,o.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${e.message}`);let l=w.INTERNAL_ERROR;e.message.includes("\u8D85\u65F6")?l=w.DIALOG_TIMEOUT:e.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(l=w.PLATFORM_NOT_SUPPORTED),(0,n.sendJSON)(s,500,{ok:!1,code:l,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,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 path\uFF08\u9700 Base64 \u7F16\u7801\uFF09\uFF0C\u7528\u6CD5: GET /api/reveal?path=<base64\u7F16\u7801\u7684\u6587\u4EF6\u7EDD\u5BF9\u8DEF\u5F84>"});return}let t;try{t=Buffer.from(r,"base64").toString("utf-8")}catch{(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"path \u53C2\u6570 Base64 \u89E3\u7801\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u4F20\u5165\u5408\u6CD5\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32"});return}if(!t||t.trim()===""){(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const i=(0,k.validateFilePath)(t);if(!i.valid){const g=i.reason;g.includes("\u975E\u6CD5\u5B57\u7B26")?(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:g}):g.includes("\u4E0D\u5B58\u5728")?(0,n.sendJSON)(s,404,{status:"\u5931\u8D25",message:g}):g.includes("\u65E0\u6CD5\u89E3\u6790")?(0,n.sendJSON)(s,400,{status:"\u5931\u8D25",message:g}):((0,o.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${t}\uFF0C\u539F\u56E0: ${g}`),(0,n.sendJSON)(s,403,{status:"\u5931\u8D25",message:g}));return}const u=N.default.resolve(t),e=process.platform;let l,c,f={stdio:"ignore",windowsHide:!0};e==="darwin"?(l="open",c=["-R",u]):e==="win32"?(l="explorer.exe",c=[`/select,"${u}"`],f={...f,shell:!0}):(l="xdg-open",c=[N.default.dirname(u)]),(0,o.log)(`\u6267\u884C\u547D\u4EE4: ${l} ${c.join(" ")}`);try{await new Promise((g,O)=>{const P=(0,$.spawn)(l,c,f),_=setTimeout(()=>{P.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);P.on("close",h=>{clearTimeout(_),e==="win32"||h===0||h===1?g():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${h}`))}),P.on("error",h=>{clearTimeout(_),O(h)})}),(0,o.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${u}`),(0,n.sendJSON)(s,200,{status:"\u6210\u529F",message:`\u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${u}`})}catch(g){(0,o.log)(`[reveal] \u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${g.message}`),(0,n.sendJSON)(s,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${g.message}`})}return}(0,n.sendJSON)(s,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})}});let A=null,I=null;function x(m){if(!m)return;if(A&&I===m){(0,o.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${m}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}A?((0,o.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${I}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${m}`),clearInterval(A),A=null,I=null):(0,o.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${m}`);const s=setInterval(()=>{try{process.kill(m,0)}catch{(0,o.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${m} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(s),A=null,I=null,(0,y.stopGateway)(),(0,y.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);s.unref(),A=s,I=m}
1
+ "use strict";var E=exports&&exports.__importDefault||function(p){return p&&p.__esModule?p:{default:p}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.server=void 0,exports.watchParentProcess=x;const F=E(require("http")),S=E(require("fs")),P=E(require("path")),u=require("./config"),n=require("./utils"),b=require("./history-viewer"),o=require("./reportLog"),R=require("./installer"),B=require("./build"),y=require("./state"),A=require("child_process"),W=require("./service"),k=require("./filePicker"),L=require("./fileSecurityCheck"),M=require("./authMiddleware"),U=require("./qbotclaw-routes"),v=10485760,J=10,D=!1,w={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"),q=require("./api/auth-client");let G=new q.AuthClient({usePipe:!0});exports.server=F.default.createServer(async(p,e)=>{const g=p.url||"";if(g.startsWith("/v1/")){await(0,Q.handleOpenAIProxy)(p,e,G);return}const C=(0,M.authenticateRequest)(p);if(!C.ok){(0,n.sendJSON)(e,C.statusCode,{ok:!1,status:"\u5931\u8D25",message:C.message});return}if(g==="/api/version"){let a="unknown";try{a=(await(0,n.execCommand)(`"${u.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(S.default.existsSync(u.PYTHON_BIN))try{s=(await(0,n.execCommand)(`"${u.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)(e,200,{status:"\u6210\u529F",launcher:B.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,y.readState)();(0,n.sendJSON)(e,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,y.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:d}of s){if(!d){r.push(`${i} \u7AEF\u53E3\u672A\u914D\u7F6E\uFF08\u72B6\u6001\u4E2D\u65E0\u5BF9\u5E94\u7AEF\u53E3\u53F7\uFF09`);continue}await(0,y.isPortAvailable)(d)&&r.push(`${i} \u7AEF\u53E3 (${d}) \u65E0\u670D\u52A1\u76D1\u542C`)}r.length===0?(0,n.sendJSON)(e,200,{ok:!0,message:"\u6240\u6709\u670D\u52A1\u8FD0\u884C\u6B63\u5E38"}):(0,n.sendJSON)(e,200,{ok:!1,message:r.join("\uFF1B")});return}if(g==="/api/restart"){try{const a=(0,y.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,...d}=a;(0,y.writeState)(d),(0,o.log)("[restart] \u5DF2\u6E05\u9664 gatewayPid, gatewayPort, mcpWsPort"),await(0,R.configAndRunQBotClaw)(),(0,o.log)("[restart] QBotClaw gateway \u91CD\u542F\u5B8C\u6210");const t=(0,y.readState)(),l=exports.server.address(),c=l&&typeof l=="object"?l.port:null;(0,n.sendJSON)(e,200,{ok:!0,message:"QBotClaw gateway \u91CD\u542F\u6210\u529F",launcher:c,qbotclaw:t.gatewayPort??2e3,mcpWs:t.mcpWsPort??8765,gatewayToken:(0,W.getOrCreateGatewayToken)()})}catch(a){(0,o.log)(`[restart] \u91CD\u542F\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(e,500,{ok:!1,message:`\u91CD\u542F\u5931\u8D25: ${a.message}`})}return}if(g==="/api/wechat/enable"){try{if(!S.default.existsSync(u.QBOT_CLAW_CONFIG_PATH)){(0,n.sendJSON)(e,200,{ok:!1,enabled:!1,message:"\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728"});return}const r=JSON.parse(S.default.readFileSync(u.QBOT_CLAW_CONFIG_PATH,"utf-8"))?.channels?.["openclaw-weixin"];if(!r){(0,n.sendJSON)(e,200,{ok:!0,enabled:!1,message:"\u672A\u627E\u5230\u5FAE\u4FE1\u6E20\u9053\u914D\u7F6E"});return}(0,n.sendJSON)(e,200,{ok:!0,enabled:!!r.enabled,message:r.enabled?"\u5FAE\u4FE1\u5DF2\u7ED1\u5B9A":"\u5FAE\u4FE1\u672A\u7ED1\u5B9A"})}catch(a){(0,o.log)(`[wechat/enable] \u8BFB\u53D6\u5FAE\u4FE1\u7ED1\u5B9A\u72B6\u6001\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(e,500,{ok:!1,enabled:!1,message:`\u8BFB\u53D6\u5FAE\u4FE1\u7ED1\u5B9A\u72B6\u6001\u5931\u8D25: ${a.message}`})}return}if(g==="/api/wechat/history"){try{if(!S.default.existsSync(u.SESSIONS_FILE)){(0,n.sendJSON)(e,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(S.default.readFileSync(u.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[t,l]of Object.entries(a))if(t.includes("openclaw-weixin")){const f=l.updatedAt??0;f>s&&(s=f,r=t)}if(!r){(0,n.sendJSON)(e,404,{ok:!1,sessionKey:"",message:"\u672A\u627E\u5230\u5FAE\u4FE1\u4F1A\u8BDD"});return}const d=r.split(":").slice(2).join(":");(0,n.sendJSON)(e,200,{ok:!0,sessionKey:d,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)(e,500,{ok:!1,sessionKey:"",message:`\u8BFB\u53D6\u5FAE\u4FE1\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(g==="/api/chat/latest"){try{if(!S.default.existsSync(u.SESSIONS_FILE)){(0,n.sendJSON)(e,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u4F1A\u8BDD\u6587\u4EF6"});return}const a=JSON.parse(S.default.readFileSync(u.SESSIONS_FILE,"utf-8"));let r=null,s=0;for(const[d,t]of Object.entries(a)){if(d.includes("openclaw-weixin"))continue;const c=t.updatedAt??0;c>s&&(s=c,r=d)}if(!r){(0,n.sendJSON)(e,404,{ok:!1,sessionId:"",message:"\u672A\u627E\u5230\u975E\u5FAE\u4FE1\u4F1A\u8BDD"});return}const i=a[r];(0,n.sendJSON)(e,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)(e,500,{ok:!1,sessionId:"",message:`\u8BFB\u53D6\u4F1A\u8BDD\u5931\u8D25: ${a.message}`})}return}if(g==="/api/chat/history"){(0,b.getChatHistory)().then(a=>{(0,n.sendJSON)(e,200,{ok:!0,data:a,message:"\u83B7\u53D6\u6210\u529F"})}).catch(a=>{(0,o.log)(`[chat/history] \u8BFB\u53D6\u5386\u53F2\u8BB0\u5F55\u5931\u8D25: ${a.message}`),(0,n.sendJSON)(e,500,{ok:!1,data:[],message:`\u8BFB\u53D6\u5386\u53F2\u8BB0\u5F55\u5931\u8D25: ${a.message}`})});return}if(g==="/api/installing"){(0,n.sendJSON)(e,200,{installing:R.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)(e,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,n.sendJSON)(e,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}e.writeHead(200,{"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"}),(0,R.runInstall)(e,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)(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(r,10);try{process.kill(s,0)}catch{(0,n.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}),x(s),(0,n.sendJSON)(e,200,{status:"\u6210\u529F",message:`\u5DF2\u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${s}`});return}if(!(g.startsWith("/api/qbotclaw/")&&await(0,U.handleQBotClawRoutes)(p,e,g))){if(g.startsWith("/api/uninstall")){const r=new URL(g,"http://localhost").searchParams.get("keepWorkspace")==="true";e.writeHead(200,{"Content-Type":"text/plain; charset=utf-8","Transfer-Encoding":"chunked","Cache-Control":"no-cache"});const s=(i,d,t)=>{if(e.writable)try{e.write(JSON.stringify({status:i,file:d,msg:t})+`
2
+ `)}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,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 ${u.NPM_PACKAGE_NAME}...`);try{await new Promise((t,l)=>{const c=(0,A.spawn)(u.NPM_BIN,["--userconfig",u.NPM_RC,"uninstall","-g",u.NPM_PACKAGE_NAME],{env:{...process.env,PATH:`${u.NODE_BIN_DIR}${P.default.delimiter}${process.env.PATH}`},shell:process.platform==="win32",windowsHide:!0});c.stdout?.on("data",f=>{(0,o.log)(`[uninstall] npm: ${f.toString().trim()}`)}),c.stderr?.on("data",f=>{(0,o.log)(`[uninstall] npm stderr: ${f.toString().trim()}`)}),c.on("close",f=>{f===0?t():l(new Error(`npm uninstall \u9000\u51FA\u7801: ${f}`))}),c.on("error",f=>l(f))}),(0,o.log)(`[uninstall] npm uninstall -g ${u.NPM_PACKAGE_NAME} \u6210\u529F`),s("\u6210\u529F","",`npm uninstall -g ${u.NPM_PACKAGE_NAME} \u6210\u529F`)}catch(t){(0,o.log)(`[uninstall] npm uninstall \u5931\u8D25: ${t.message}`),s("\u5931\u8D25","",`npm uninstall \u5931\u8D25: ${t.message}`)}s("\u6210\u529F","",`\u6B63\u5728\u6E05\u7406\u76EE\u5F55 ${u.QBOT_CLAW_DIR}...`);const d=[];if(S.default.existsSync(u.QBOT_CLAW_DIR)){const t=S.default.readdirSync(u.QBOT_CLAW_DIR);for(const l of t){const c=P.default.join(u.QBOT_CLAW_DIR,l);if(r&&l==="workspace"){s("\u6210\u529F",c,"\u4FDD\u7559 workspace \u76EE\u5F55");continue}try{S.default.statSync(c).isDirectory()?S.default.rmSync(c,{recursive:!0,force:!0}):S.default.unlinkSync(c),s("\u6210\u529F",c,"\u5DF2\u5220\u9664")}catch(f){(0,o.log)(`[uninstall] \u5220\u9664\u5931\u8D25: ${c} - ${f.message}`),s("\u5931\u8D25",c,`\u5220\u9664\u5931\u8D25: ${f.message}`),d.push(c)}}if(d.length>0){s("\u6210\u529F","",`${d.length} \u4E2A\u9879\u76EE\u5220\u9664\u5931\u8D25\uFF0C\u4F7F\u7528 rm \u547D\u4EE4\u91CD\u8BD5...`);for(const l of d)try{process.platform==="win32"?(0,A.execSync)(`rmdir /s /q "${l}"`,{windowsHide:!0}):(0,A.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",u.QBOT_CLAW_DIR,"\u4FDD\u7559\u6839\u76EE\u5F55\uFF08workspace \u6A21\u5F0F\uFF09");else try{S.default.rmSync(u.QBOT_CLAW_DIR,{recursive:!0,force:!0}),s("\u6210\u529F",u.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,A.execSync)(`rmdir /s /q "${u.QBOT_CLAW_DIR}"`,{windowsHide:!0}):(0,A.execSync)(`rm -rf "${u.QBOT_CLAW_DIR}"`),s("\u6210\u529F",u.QBOT_CLAW_DIR,"\u7CFB\u7EDF\u547D\u4EE4\u91CD\u8BD5\u5220\u9664\u6839\u76EE\u5F55\u6210\u529F")}catch(c){s("\u5931\u8D25",u.QBOT_CLAW_DIR,`\u5220\u9664\u6839\u76EE\u5F55\u5931\u8D25: ${c.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,o.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,o.log)("[uninstall] \u5378\u8F7D\u6D41\u7A0B\u7ED3\u675F\uFF0Clauncher \u8FDB\u7A0B\u9000\u51FA"),process.exit(0)},500);return}if(g==="/api/file-picker"&&p.method==="POST"){if((0,k.isFilePickerBusy)()){(0,n.sendJSON)(e,409,{ok:!1,code:w.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 a="";p.on("data",r=>{a+=r.toString()}),p.on("end",async()=>{let r=!1,s=v,i=J,d=D;if(a){let t;try{t=JSON.parse(a)}catch{(0,n.sendJSON)(e,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u8BF7\u6C42\u4F53\u5FC5\u987B\u662F\u5408\u6CD5\u7684 JSON"});return}if(t.extensions!==void 0&&(!Array.isArray(t.extensions)||!t.extensions.every(l=>typeof l=="string"))){(0,n.sendJSON)(e,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 extensions \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"});return}if(t.multiple!==void 0){if(typeof t.multiple!="boolean"){(0,n.sendJSON)(e,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 multiple \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}r=t.multiple}if(t.title!==void 0&&(typeof t.title!="string"||t.title.length>200)){(0,n.sendJSON)(e,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 title \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u4E14\u957F\u5EA6\u4E0D\u8D85\u8FC7 200"});return}if(t.maxFileSize!==void 0){if(typeof t.maxFileSize!="number"||t.maxFileSize<=0||!Number.isFinite(t.maxFileSize)){(0,n.sendJSON)(e,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileSize \u5FC5\u987B\u662F\u6B63\u6570"});return}s=Math.min(t.maxFileSize,v)}if(t.maxFileCount!==void 0){if(typeof t.maxFileCount!="number"||t.maxFileCount<=0||!Number.isInteger(t.maxFileCount)){(0,n.sendJSON)(e,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 maxFileCount \u5FC5\u987B\u662F\u6B63\u6574\u6570"});return}i=Math.min(t.maxFileCount,J)}if(D&&t.allowDirectory!==void 0){if(typeof t.allowDirectory!="boolean"){(0,n.sendJSON)(e,400,{ok:!1,code:w.INVALID_PARAMS,files:[],message:"\u53C2\u6570 allowDirectory \u5FC5\u987B\u662F\u5E03\u5C14\u503C"});return}d=t.allowDirectory}}r||(i=1);try{const t=await(0,k.showFilePicker)({multiple:r,allowDirectory:d});if(!t||t.length===0){(0,n.sendJSON)(e,200,{ok:!1,code:w.CANCELLED,files:[],message:"\u7528\u6237\u53D6\u6D88\u4E86\u6587\u4EF6\u9009\u62E9"});return}if(d){const _=t.slice(0,i).map(T=>({name:P.default.basename(T),path:T,size:0,mimeType:"inode/directory"})),h=t.length>i;(0,n.sendJSON)(e,200,{ok:!0,files:_,message:h?`\u5DF2\u9009\u62E9 ${_.length} \u4E2A\u76EE\u5F55\uFF08\u5171\u9009\u62E9 ${t.length} \u4E2A\uFF0C\u8D85\u51FA\u4E0A\u9650 ${i} \u4E2A\u5DF2\u622A\u65AD\uFF09`:`\u5DF2\u9009\u62E9 ${_.length} \u4E2A\u76EE\u5F55`});return}let l=!1,c=t;t.length>i&&(c=t.slice(0,i),l=!0);const f=[],m=[];for(const _ of c){const h=(0,L.readFileInfo)(_,s);h.ok?f.push({name:h.name,path:h.path,size:h.size,mimeType:h.mimeType}):m.push({path:h.path,reason:h.reason,code:h.code})}const O=[];if(f.length>0&&O.push(`\u6210\u529F\u8BFB\u53D6 ${f.length} \u4E2A\u6587\u4EF6`),m.length>0){const _=m.map(h=>`${P.default.basename(h.path)}: ${h.reason}`).join("\uFF1B");O.push(`${m.length} \u4E2A\u6587\u4EF6\u5931\u8D25\uFF08${_}\uFF09`)}l&&O.push(`\u5171\u9009\u62E9 ${t.length} \u4E2A\u6587\u4EF6\uFF0C\u8D85\u51FA\u4E0A\u9650 ${i} \u4E2A\u5DF2\u622A\u65AD`);const N=f.length===0&&m.length>0;(0,n.sendJSON)(e,200,{ok:!N,code:N?m[0].code:void 0,files:f,failedFiles:m.length>0?m:void 0,message:O.join("\uFF1B")||"\u6587\u4EF6\u9009\u62E9\u6210\u529F"})}catch(t){(0,o.log)(`[file-picker] \u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${t.message}`);let l=w.INTERNAL_ERROR;t.message.includes("\u8D85\u65F6")?l=w.DIALOG_TIMEOUT:t.message.includes("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0")&&(l=w.PLATFORM_NOT_SUPPORTED),(0,n.sendJSON)(e,500,{ok:!1,code:l,files:[],message:`\u6587\u4EF6\u9009\u62E9\u5931\u8D25: ${t.message}`})}});return}if(g.startsWith("/api/reveal")){console.log(`[reveal] \u5B8C\u6574URL: ${g}`);const r=new URL(g,"http://localhost").searchParams.get("path")?.replace(/ /g,"+")??null;if(!r){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570 path\uFF08\u9700 Base64 \u7F16\u7801\uFF09\uFF0C\u7528\u6CD5: GET /api/reveal?path=<base64\u7F16\u7801\u7684\u6587\u4EF6\u7EDD\u5BF9\u8DEF\u5F84>"});return}let s;try{s=Buffer.from(r,"base64").toString("utf-8")}catch{(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"path \u53C2\u6570 Base64 \u89E3\u7801\u5931\u8D25\uFF0C\u8BF7\u786E\u4FDD\u4F20\u5165\u5408\u6CD5\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32"});return}if(!s||s.trim()===""){(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:"Base64 \u89E3\u7801\u540E\u8DEF\u5F84\u4E3A\u7A7A"});return}const i=(0,L.validateFilePath)(s);if(!i.valid){const m=i.reason;m.includes("\u975E\u6CD5\u5B57\u7B26")?(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:m}):m.includes("\u4E0D\u5B58\u5728")?(0,n.sendJSON)(e,404,{status:"\u5931\u8D25",message:m}):m.includes("\u65E0\u6CD5\u89E3\u6790")?(0,n.sendJSON)(e,400,{status:"\u5931\u8D25",message:m}):((0,o.log)(`[reveal] \u5B89\u5168\u68C0\u67E5\u88AB\u62D2\u7EDD: ${s}\uFF0C\u539F\u56E0: ${m}`),(0,n.sendJSON)(e,403,{status:"\u5931\u8D25",message:m}));return}const d=P.default.resolve(s),t=process.platform;let l,c,f={stdio:"ignore",windowsHide:!0};t==="darwin"?(l="open",c=["-R",d]):t==="win32"?(l="explorer.exe",c=[`/select,"${d}"`],f={...f,shell:!0}):(l="xdg-open",c=[P.default.dirname(d)]),(0,o.log)(`\u6267\u884C\u547D\u4EE4: ${l} ${c.join(" ")}`);try{await new Promise((m,O)=>{const N=(0,A.spawn)(l,c,f),_=setTimeout(()=>{N.kill(),O(new Error("\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u8D85\u65F6\uFF085\u79D2\uFF09"))},5e3);N.on("close",h=>{clearTimeout(_),t==="win32"||h===0||h===1?m():O(new Error(`\u8FDB\u7A0B\u9000\u51FA\u7801: ${h}`))}),N.on("error",h=>{clearTimeout(_),O(h)})}),(0,o.log)(`[reveal] \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u663E\u793A: ${d}`),(0,n.sendJSON)(e,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)(e,500,{status:"\u5931\u8D25",message:`\u6253\u5F00\u6587\u4EF6\u7BA1\u7406\u5668\u5931\u8D25: ${m.message}`})}return}(0,n.sendJSON)(e,404,{status:"\u5931\u8D25",message:"\u63A5\u53E3\u4E0D\u5B58\u5728"})}});let $=null,I=null;function x(p){if(!p)return;if($&&I===p){(0,o.log)(`[watchParentProcess] \u5DF2\u5728\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${p}\uFF0C\u8DF3\u8FC7\u91CD\u590D\u76D1\u542C`);return}$?((0,o.log)(`[watchParentProcess] \u5DF2\u6709\u76D1\u63A7\uFF08ppid: ${I}\uFF09\uFF0C\u505C\u6B62\u65E7\u7684\u76D1\u63A7\uFF0C\u91CD\u65B0\u76D1\u63A7 ppid: ${p}`),clearInterval($),$=null,I=null):(0,o.log)(`[watchParentProcess] \u5F00\u59CB\u76D1\u63A7\u7236\u8FDB\u7A0B ppid: ${p}`);const e=setInterval(()=>{try{process.kill(p,0)}catch{(0,o.log)(`[watchParentProcess] \u7236\u8FDB\u7A0B ${p} \u5DF2\u9000\u51FA\uFF0C\u5F00\u59CB\u6E05\u7406\u5E76\u9000\u51FA`),clearInterval(e),$=null,I=null,(0,y.stopGateway)(),(0,y.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);e.unref(),$=e,I=p}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qqbrowser/qbot-claw-launcher",
3
- "version": "0.10.26",
3
+ "version": "0.10.27",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {