cc-ding 0.0.5 → 0.1.0
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/bin/cc-ding.js +36 -1
- package/dist/resource/ocr-arm64 +0 -0
- package/dist/resource/ocr-x64 +0 -0
- package/dist/src/biz/api-key-manager.js +3 -1
- package/dist/src/biz/cc-ding-cli.js +85 -1
- package/dist/src/biz/claude-process.js +39 -1
- package/dist/src/biz/commands.js +6 -1
- package/dist/src/biz/cron.js +21 -1
- package/dist/src/biz/doctor.js +2 -1
- package/dist/src/biz/image.js +12 -1
- package/dist/src/biz/lock.js +1 -1
- package/dist/src/biz/messaging.js +6 -1
- package/dist/src/biz/notify.js +1 -0
- package/dist/src/biz/quote.js +5 -1
- package/dist/src/biz/recorder.js +9 -0
- package/dist/src/biz/session.js +13 -1
- package/dist/src/biz/task.js +24 -1
- package/dist/src/biz/types.js +1 -1
- package/dist/src/common.js +1 -1
- package/dist/src/constants.js +1 -1
- package/package.json +7 -5
- package/resource/ocr-arm64 +0 -0
- package/resource/ocr-x64 +0 -0
package/dist/bin/cc-ding.js
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const common_1=require("../src/common"),commander_1=require("commander"),session_1=require("../src/biz/session"),path_1=__importDefault(require("path")),cc_ding_cli_1=require("../src/biz/cc-ding-cli"),lock_1=require("../src/biz/lock"),doctor_1=require("../src/biz/doctor"),notify_1=require("../src/biz/notify"),fs_1=__importDefault(require("fs"));(0,common_1.loadEnv)(),process.removeAllListeners("warning"),process.setMaxListeners(0),process.on("uncaughtException",function(e){console.log("Caught exception: "+e),process.exit(1)});const program=new commander_1.Command;program.addHelpText("before",`
|
|
3
|
+
cc-ding for connect ClaudeCode to DingDingRobot
|
|
4
|
+
`).addHelpText("after",`
|
|
5
|
+
Examples:
|
|
6
|
+
$ cc-ding init -ci {clientId} -cs {clientSecret} -m {mobile}
|
|
7
|
+
$ cc-ding run -ci {clientId}
|
|
8
|
+
`).version((0,common_1.projUtil)().getPkgVersion()),program.command("init").description("\u521D\u59CB\u5316cc-ding\u914D\u7F6E\u6587\u4EF6, \u751F\u6210\u6700\u7B80config.json").requiredOption("-ci, --clientId <value>","clientId").requiredOption("-cs, --clientSecret <value>","clientSecret (\u9489\u9489Stream\u8FDE\u63A5\u5BC6\u94A5)").requiredOption("-m, --mobile <value>","mobile (\u81EA\u5DF1\u7684\u624B\u673A\u53F7, \u81EA\u52A8\u52A0\u5165\u767D\u540D\u5355)").option("-cn, --clientName <value>","clientName (\u673A\u5668\u4EBA\u540D\u79F0, \u53EF\u9009)").action(async e=>{const n=process.version.slice(1);parseInt(n.split(".")[0],10)<24&&(console.log(`
|
|
9
|
+
\u274C Node \u7248\u672C\u8FC7\u4F4E\uFF0C\u65E0\u6CD5\u6267\u884C init \u547D\u4EE4`),console.log(` \u5F53\u524D\u7248\u672C\uFF1A${n}`),console.log(" \u8981\u6C42\uFF1ANode >= 24"),console.log(`
|
|
10
|
+
\u{1F4A1} \u8BF7\u5347\u7EA7 Node \u7248\u672C\u540E\u91CD\u65B0\u8FD0\u884C
|
|
11
|
+
`),process.exit(1));const i=`${`${(0,session_1.getHomeDir)()}/.cc-ding/${e.clientId}`}/config.json`;fs_1.default.existsSync(i)&&(console.log(`\u914D\u7F6E\u6587\u4EF6\u5DF2\u5B58\u5728: ${i}`),console.log("\u5982\u9700\u91CD\u65B0\u521D\u59CB\u5316, \u8BF7\u5148\u5220\u9664\u5DF2\u6709\u914D\u7F6E\u6587\u4EF6"),process.exit(1));const t={clientName:e.clientName||"cc\u52A9\u624B",owner:e.mobile,whiteUserList:[e.mobile],clientSecret:e.clientSecret,defaultDingToken:"<\u515C\u5E95\u9489\u9489\u673A\u5668\u4EBAToken-\u7528\u4E8E\u65E0dingToken\u7FA4\u7684\u6D88\u606F\u63A5\u6536>",conversations:[],includeThinking:!1,resultOnly:!0,debug:!1,taskQueueSize:10,taskHandlerCount:1,sessionMaxConcurrency:20};(0,session_1.initClientDir)(e.clientId,t),console.log("\u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210:",i),console.log(""),console.log("\u540E\u7EED\u6B65\u9AA4:"),console.log(" 1. \u7F16\u8F91 config.json \u6DFB\u52A0 conversations \u914D\u7F6E(\u7FA4\u804A\u9700\u914D\u7F6EdingToken)"),console.log(" 2. \u542F\u52A8\u673A\u5668\u4EBA: cc-ding run -ci",e.clientId),console.log(" 3. \u63A8\u8350PM2\u542F\u52A8:"),console.log(` pm2 start --name "cc-ding-${e.clientId}" npx -- -p cc-ding cc-ding run -ci ${e.clientId}`)}),program.command("run").description(`
|
|
12
|
+
- \u529F\u80FD: \u9489\u9489\u673A\u5668\u4EBA\u5BF9\u63A5\u672C\u5730Claude, \u652F\u6301\u4F1A\u8BDD\u6A21\u5F0F\u548C\u4EFB\u52A1\u961F\u5217\u6A21\u5F0F
|
|
13
|
+
- \u4F1A\u8BDD\u6570\u636E\u8DEF\u5F84: ~/.cc-ding/{clientId}/{MD5}/.sessions/{claudeSessionId}/session.{json|log}
|
|
14
|
+
- \u4EFB\u52A1\u6570\u636E\u8DEF\u5F84: ~/.cc-ding/{clientId}/{MD5}/.tasks/{\u65F6\u95F4\u6233}/task.{json|log}
|
|
15
|
+
- \u5B9A\u65F6\u4EFB\u52A1\u6570\u636E: ~/.cc-ding/{clientId}/cron.json
|
|
16
|
+
- \u542F\u52A8\u65B9\u5F0F: pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding run -ci {clientId}
|
|
17
|
+
- \u4F1A\u8BDD\u6A21\u5F0F\u8BF4\u660E
|
|
18
|
+
- \u4F1A\u8BDDID: \u7531 Claude \u5206\u914D\u7684 claudeSessionId
|
|
19
|
+
- \u7ED3\u675F\u4F1A\u8BDD: /end
|
|
20
|
+
- \u65B0\u4F1A\u8BDD: /new [\u521D\u59CB\u6D88\u606F] \u5F3A\u5236\u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD\u5E76\u5F00\u542F\u65B0\u4F1A\u8BDD
|
|
21
|
+
- \u6062\u590D\u4F1A\u8BDD: /resume [\u4F1A\u8BDDID] \u6062\u590D\u6307\u5B9A\u5386\u53F2\u4F1A\u8BDD, \u4E0D\u6307\u5B9A\u5219\u6062\u590D\u6700\u8FD1\u4E00\u4E2A
|
|
22
|
+
- \u4F1A\u8BDD\u6301\u4E45\u5316: \u6D3B\u8DC3\u4F1A\u8BDD\u81EA\u52A8\u4FDD\u5B58\u5230 active.json, \u670D\u52A1\u91CD\u542F\u540E\u81EA\u52A8\u6062\u590D
|
|
23
|
+
- \u7FA4\u5185\u591A\u7528\u6237: \u5141\u8BB8\u7FA4\u5185\u6240\u6709\u767D\u540D\u5355\u7528\u6237\u53C2\u4E0E\u5BF9\u8BDD
|
|
24
|
+
- /help: \u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4(\u542B\u7248\u672C\u3001\u4F5C\u8005\u3001\u6587\u6863\u94FE\u63A5); /{\u547D\u4EE4} --help \u67E5\u770B\u547D\u4EE4\u8BE6\u7EC6\u7528\u6CD5
|
|
25
|
+
- \u56FE\u7247\u6D88\u606F\u652F\u6301
|
|
26
|
+
- \u652F\u6301\u63A5\u6536\u9489\u9489\u56FE\u7247\u6D88\u606F(picture)\u548C\u5BCC\u6587\u672C\u6D88\u606F(richText, \u542B\u5185\u5D4C\u56FE\u7247)
|
|
27
|
+
- \u56FE\u7247\u81EA\u52A8\u4E0B\u8F7D\u4FDD\u5B58\u5230 <\u4F1A\u8BDD\u76EE\u5F55>/.images/ \u4E0B
|
|
28
|
+
- useLocalOcr: \u9ED8\u8BA4\u5F00\u542F, \u4F7F\u7528\u672C\u5730OCR\u8BC6\u522B\u56FE\u7247\u6587\u5B57, \u540C\u65F6\u4F20\u5165\u539F\u56FE\u8DEF\u5F84\u4F9BClaude\u81EA\u4E3B\u67E5\u770B
|
|
29
|
+
- \u914D\u7F6E\u65B9\u5F0F: conversations[].useLocalOcr = false \u53EF\u5173\u95EDOCR(\u9002\u7528\u4E8E\u652F\u6301\u56FE\u7247\u8BC6\u522B\u7684\u6A21\u578B)
|
|
30
|
+
- \u4EFB\u52A1\u6A21\u5F0F\u8BF4\u660E
|
|
31
|
+
- \u4EFB\u52A1ID: \u4EFB\u52A1\u63A5\u6536\u65F6\u95F4\u6233
|
|
32
|
+
- API Key \u6C60\u5316\u7BA1\u7406(\u53EF\u9009, \u914D\u7F6EapiKeyCfg\u540E\u542F\u7528)
|
|
33
|
+
- 429\u81EA\u52A8\u5207\u6362: \u81EA\u52A8\u5207\u6362\u5230API Key\u6A21\u5F0F
|
|
34
|
+
- Key\u8F6E\u6362: API Key\u9047\u5230429\u6216\u8FDE\u7EEDTPM\u4E0D\u7A33\u5B9A\u65F6\u81EA\u52A8\u6362Key
|
|
35
|
+
- \u8DE8\u5929\u91CD\u7F6E: \u6BCF\u65E5\u81EA\u52A8\u91CD\u7F6EAPI Key\u72B6\u6001
|
|
36
|
+
`).requiredOption("-ci, --clientId <value>","clientId").action(async e=>{(0,session_1.ensureClientDir)(e.clientId);const n=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding",e.clientId);(0,lock_1.acquirePidLock)(n,e.clientId),await new cc_ding_cli_1.DingClaude(e.clientId).run()}),program.command("doctor").description("\u68C0\u67E5\u6307\u5B9Aclient\u7684\u914D\u7F6E\u6587\u4EF6schema\u5408\u6CD5\u6027\u548C\u6709\u6548\u6027").requiredOption("-ci, --clientId <value>","clientId").action(async e=>{const n=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding",e.clientId),c=(0,doctor_1.runDoctor)(n);(0,doctor_1.printDoctorResults)(c)}),program.command("notify").description("\u901A\u8FC7\u9489\u9489\u673A\u5668\u4EBA\u53D1\u9001\u6D88\u606F\u5230\u6307\u5B9A\u7FA4").requiredOption("-ci, --clientId <value>","clientId").requiredOption("-c, --conversations <value>","\u76EE\u6807\u4F1A\u8BDDID\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF09").requiredOption("-m, --message <value>","\u6D88\u606F\u5185\u5BB9").option("-at, --atUserIds <value>","@ \u6307\u5B9A\u7528\u6237\uFF08\u591A\u4E2A\u7528\u9017\u53F7\u5206\u9694\uFF09").option("-md, --markdown","\u4F7F\u7528 Markdown \u683C\u5F0F\u53D1\u9001",!1).action(async e=>{const n=e.conversations.split(",").map(i=>i.trim()).filter(Boolean),c=e.atUserIds?e.atUserIds.split(",").map(i=>i.trim()).filter(Boolean):[];console.log(`\u{1F4E4} \u53D1\u9001\u6D88\u606F\u5230 ${n.length} \u4E2A\u4F1A\u8BDD...`);const o=await(0,notify_1.sendNotify)({clientId:e.clientId,message:e.message,conversationIds:n,atUserIds:c,markdown:e.markdown});console.log(`
|
|
37
|
+
\u2705 \u6210\u529F: ${o.success}, \u274C \u5931\u8D25: ${o.fail}`),process.exit(o.fail>0?1:0)}),program.parse(process.argv);
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
'use strict';const a1_0x456413=a1_0x125f;function a1_0x125f(_0x2322b8,_0x55c887){_0x2322b8=_0x2322b8-0xa7;const _0x2d464d=a1_0x2d46();let _0x125f8b=_0x2d464d[_0x2322b8];return _0x125f8b;}(function(_0x8d2d5b,_0x4b8ce8){const _0x5707e7=a1_0x125f,_0x4f4026=_0x8d2d5b();while(!![]){try{const _0x37fee5=-parseInt(_0x5707e7(0xb2))/0x1+-parseInt(_0x5707e7(0x128))/0x2*(parseInt(_0x5707e7(0xc9))/0x3)+-parseInt(_0x5707e7(0xe9))/0x4*(parseInt(_0x5707e7(0x11c))/0x5)+parseInt(_0x5707e7(0x10f))/0x6+parseInt(_0x5707e7(0x10c))/0x7+parseInt(_0x5707e7(0xf4))/0x8+-parseInt(_0x5707e7(0xf2))/0x9*(-parseInt(_0x5707e7(0xd1))/0xa);if(_0x37fee5===_0x4b8ce8)break;else _0x4f4026['push'](_0x4f4026['shift']());}catch(_0x203ac8){_0x4f4026['push'](_0x4f4026['shift']());}}}(a1_0x2d46,0x2df3a));var __importDefault=this&&this['__importDefault']||function(_0x39459d){const _0x115bea=a1_0x125f;return _0x39459d&&_0x39459d[_0x115bea(0xa9)]?_0x39459d:{'default':_0x39459d};};Object['defineProperty'](exports,'__esModule',{'value':!![]}),exports[a1_0x456413(0xfd)]=saveClientConfig,exports[a1_0x456413(0xf6)]=resetApiKeyCfg,exports[a1_0x456413(0xdc)]=scheduleApiKeyCfgDailyReset,exports[a1_0x456413(0xd6)]=settingLabel,exports[a1_0x456413(0x104)]=rotateApiKey,exports[a1_0x456413(0x11f)]=pickValidApiKey,exports[a1_0x456413(0xc4)]=ensureSettingsWithApiKey,exports[a1_0x456413(0xc7)]=isQuotaExhaustedError,exports['isAuthenticationError']=isAuthenticationError,exports[a1_0x456413(0x121)]=readApiKeyFromSettings,exports[a1_0x456413(0xea)]=getForceEnabledSettingsPath,exports['startupCheck']=startupCheck;function a1_0x2d46(){const _0x445905=['default','slice',']\x20==============================\x0a','./session','clientSecret\x20(钉钉\x20Stream\x20Client\x20密钥)','\x20个群配置','settings-tpl.json\x20根元素不是对象','apiKeyCfg.claudeSettings\x20为空,无可用\x20Key','29215HYPKIS','.cc-ding','whiteUserList','pickValidApiKey','keys','readApiKeyFromSettings','claudeSettings','getHomeDir','ANTHROPIC_AUTH_TOKEN','claude\x20命令不可用,请确认\x20Claude\x20Code\x20CLI\x20已安装','CLAUDE_SMALL_FAST_MODEL','settings-tpl.json','34faJCWU','settings-tpl.json\x20解析失败:\x20','exit','toISOString','...','PASS','level','settings-tpl.json\x20不存在:\x20','\x20警告,\x20','getFullYear','dateUtil','push','__esModule','linkConversationId','getClientDir','getMonth',',\x20model:\x20','isArray','config.json\x20','timestamp','clientSecret','256485YBmdUB','群工作目录已就绪:\x20','add','settings-tpl.json\x20有效,env\x20包含:\x20','filter','owner\x20(机器人\x20owner)','pipe','conversationId','\x20致命','which\x20claude','apiKey','apiKeyCfg.claudeSettings\x20不是数组,API\x20Key\x20轮换功能不可用','\x20缺少\x20apiKey','conversations[','random','\x20isValid\x20类型异常:\x20','config.json\x20缺少必填字段:\x20',']\x20启动自检发现致命错误,进程退出','ensureSettingsWithApiKey','[WARN]\x20','settings-ding.json','isQuotaExhaustedError','\x20conversationId\x20重复:\x20','46971EZvtsP','path','conversations','工作目录不可写:\x20','join','some','message','readFileSync','4078590VtDhNZ','群工作目录创建失败:\x20',']\x20已写入\x20Claude\x20配置到\x20','utf-8','resetTime','settingLabel','test','env',',\x20smallModel:\x20',']\x20apiKeyCfg\x20已重置\x20(所有\x20Claude\x20Setting\x20isValid=true)','\x20缺少\x20model','scheduleApiKeyCfgDailyReset','apiKeyCfg','boolean',']\x20从模板创建\x20settings-ding.json:\x20','conversations\x20共\x20','getConversationDir','existsSync','conversations\x20为空数组,可通过\x20/reg\x20命令动态注册','model','FATAL','format','baseUrl','log','140tCFMSL','getForceEnabledSettingsPath','conversationTitle','has','\x20—\x20','\x20apiKey\x20重复:\x20','stringify','WARN','memo','9SeODzh','isValid','509520wkVQIN','\x20缺少\x20conversationId','resetApiKeyCfg',',创建\x20settings-ding.json\x20时将使用空模板','utils-ok','getTime','writeFileSync','/config.json',']\x20检测到\x20settings-ding.json\x20FORCE_ENABLE=','saveClientConfig','getDate',']\x20==========\x20启动自检\x20==========','length','claude\x20命令可用',']\x20Claude\x20Setting\x20已失效:\x20','\x22\x20未在\x20conversations\x20中找到','rotateApiKey','ANTHROPIC_BASE_URL','parse','\x20项,有效\x20','owner','smallModel','object',']\x20apiKeyCfg\x20每日重置已调度,下次重置:\x20','671349pwfSYb','\x20通过,\x20','apiKeyCfg.claudeSettings\x20共\x20','2087526KwKxzg','.claude','ANTHROPIC_MODEL','config','find'];a1_0x2d46=function(){return _0x445905;};return a1_0x2d46();}const fs_1=__importDefault(require('fs')),path_1=__importDefault(require(a1_0x456413(0xca))),child_process_1=require('child_process'),session_1=require(a1_0x456413(0x117)),utils_ok_1=require(a1_0x456413(0xf8));function saveClientConfig(_0x57d208){const _0x24e7bb=a1_0x456413,_0x491d4b=_0x57d208[_0x24e7bb(0xab)]()+_0x24e7bb(0xfb);try{fs_1['default'][_0x24e7bb(0xfa)](_0x491d4b,JSON[_0x24e7bb(0xef)](_0x57d208[_0x24e7bb(0x112)],null,0x2),'utf-8');}catch(_0xee673){console['error']('['+(0x0,session_1[_0x24e7bb(0xb0)])()+']\x20保存\x20config.json\x20失败:',_0xee673);}}function resetApiKeyCfg(_0x2a9ab5){const _0x46343e=a1_0x456413,_0x585bc4=_0x2a9ab5[_0x46343e(0x112)][_0x46343e(0xdd)];if(!_0x585bc4)return;const _0x35e080=new Date();_0x585bc4['resetTime']=utils_ok_1[_0x46343e(0xa7)]['mm'](_0x35e080[_0x46343e(0xf9)]())[_0x46343e(0xe6)]('YYYY-MM-DD\x20HH:mm:ss');let _0xe07065=0x0;for(const _0x3bb3d3 of _0x585bc4['claudeSettings']){!_0x3bb3d3[_0x46343e(0xf3)]&&(_0x3bb3d3['isValid']=!![],_0xe07065++);}_0xe07065>0x0&&console[_0x46343e(0xe8)]('['+(0x0,session_1[_0x46343e(0xb0)])()+']\x20'+_0xe07065+'\x20个已失效\x20Claude\x20Setting\x20重新标记为有效'),saveClientConfig(_0x2a9ab5),console[_0x46343e(0xe8)]('['+(0x0,session_1[_0x46343e(0xb0)])()+_0x46343e(0xda));}function scheduleApiKeyCfgDailyReset(_0x23c28b){const _0x5138b2=()=>{const _0x54fbae=a1_0x125f,_0x4abd55=new Date(),_0x431ffc=new Date(_0x4abd55[_0x54fbae(0x131)](),_0x4abd55[_0x54fbae(0xac)](),_0x4abd55[_0x54fbae(0xfe)]()+0x1,0x0,0x0,0x0,0x0),_0x53e0be=_0x431ffc[_0x54fbae(0xf9)]()-_0x4abd55[_0x54fbae(0xf9)]();setTimeout(()=>{const _0x337bc5=_0x54fbae;console[_0x337bc5(0xe8)]('['+(0x0,session_1[_0x337bc5(0xb0)])()+']\x20定时重置\x20apiKeyCfg\x20(每天0点)'),resetApiKeyCfg(_0x23c28b),_0x5138b2();},_0x53e0be),console[_0x54fbae(0xe8)]('['+(0x0,session_1[_0x54fbae(0xb0)])()+_0x54fbae(0x10b)+_0x431ffc[_0x54fbae(0x12b)]());};_0x5138b2();}function settingLabel(_0x349385){const _0xd39266=a1_0x456413;return _0x349385[_0xd39266(0xf1)]?_0x349385[_0xd39266(0xf1)]:_0xd39266(0x12c)+_0x349385[_0xd39266(0xbc)][_0xd39266(0x115)](-0x6);}function findSettingLabel(_0x216c79,_0x8db208){const _0x55955a=a1_0x456413,_0x30e9d6=_0x216c79[_0x55955a(0x113)](_0x245786=>_0x245786['apiKey']===_0x8db208);return _0x30e9d6?settingLabel(_0x30e9d6):_0x55955a(0x12c)+_0x8db208['slice'](-0x6);}function rotateApiKey(_0x5dfeeb,_0x4fbfe4){const _0x218b8b=a1_0x456413,_0x12c5f6=_0x5dfeeb[_0x218b8b(0x112)]['apiKeyCfg'];if(!_0x12c5f6)return null;for(const _0x55972d of _0x12c5f6['claudeSettings']){if(_0x55972d[_0x218b8b(0xbc)]===_0x4fbfe4&&_0x55972d['isValid']){_0x55972d[_0x218b8b(0xf3)]=![];break;}}const _0x530b84=_0x12c5f6[_0x218b8b(0x122)]['filter'](_0xc75af3=>_0xc75af3[_0x218b8b(0xf3)])[_0x218b8b(0x100)],_0x1507ca=findSettingLabel(_0x12c5f6[_0x218b8b(0x122)],_0x4fbfe4);return console[_0x218b8b(0xe8)]('['+(0x0,session_1[_0x218b8b(0xb0)])()+_0x218b8b(0x102)+_0x1507ca+',\x20剩余有效:\x20'+_0x530b84),saveClientConfig(_0x5dfeeb),pickValidApiKey(_0x5dfeeb);}function pickValidApiKey(_0x3eb232){const _0x312d9a=a1_0x456413,_0x3bfbb7=_0x3eb232[_0x312d9a(0x112)]['apiKeyCfg'];if(!_0x3bfbb7)return null;const _0xe7ac5=_0x3bfbb7[_0x312d9a(0x122)][_0x312d9a(0xb6)](_0xe5f137=>_0xe5f137[_0x312d9a(0xf3)]);if(_0xe7ac5['length']===0x0)return null;return _0xe7ac5[Math['floor'](Math[_0x312d9a(0xc0)]()*_0xe7ac5[_0x312d9a(0x100)])];}function ensureSettingsWithApiKey(_0x403d89,_0x42d31e){const _0x243186=a1_0x456413,_0x5b20ce=path_1[_0x243186(0x114)]['join'](_0x403d89,_0x243186(0x110)),_0x448ece=path_1[_0x243186(0x114)][_0x243186(0xcd)](_0x5b20ce,'settings-ding.json');let _0x527e0a={};if(fs_1[_0x243186(0x114)]['existsSync'](_0x448ece))try{_0x527e0a=JSON['parse'](fs_1[_0x243186(0x114)][_0x243186(0xd0)](_0x448ece,_0x243186(0xd4)));}catch{_0x527e0a={};}else{const _0x2da54f=path_1['default'][_0x243186(0xcd)]((0x0,session_1[_0x243186(0x123)])(),_0x243186(0x11d),_0x243186(0x127));if(fs_1[_0x243186(0x114)][_0x243186(0xe2)](_0x2da54f))try{_0x527e0a=JSON[_0x243186(0x106)](fs_1['default'][_0x243186(0xd0)](_0x2da54f,_0x243186(0xd4))),console[_0x243186(0xe8)]('['+(0x0,session_1[_0x243186(0xb0)])()+_0x243186(0xdf)+_0x2da54f);}catch{_0x527e0a={};}}!_0x527e0a[_0x243186(0xd8)]&&(_0x527e0a[_0x243186(0xd8)]={});let _0x536c7e=![];_0x527e0a[_0x243186(0xd8)][_0x243186(0x124)]!==_0x42d31e['apiKey']&&(_0x527e0a[_0x243186(0xd8)][_0x243186(0x124)]=_0x42d31e[_0x243186(0xbc)],_0x536c7e=!![]);_0x42d31e[_0x243186(0xe7)]&&_0x527e0a[_0x243186(0xd8)]['ANTHROPIC_BASE_URL']!==_0x42d31e[_0x243186(0xe7)]&&(_0x527e0a[_0x243186(0xd8)][_0x243186(0x105)]=_0x42d31e[_0x243186(0xe7)],_0x536c7e=!![]);_0x42d31e[_0x243186(0xe4)]&&_0x527e0a['env'][_0x243186(0x111)]!==_0x42d31e[_0x243186(0xe4)]&&(_0x527e0a['env'][_0x243186(0x111)]=_0x42d31e[_0x243186(0xe4)],_0x536c7e=!![]);const _0x29297a=_0x42d31e[_0x243186(0x109)]||_0x42d31e['model'];return _0x29297a&&_0x527e0a['env'][_0x243186(0x126)]!==_0x29297a&&(_0x527e0a[_0x243186(0xd8)]['CLAUDE_SMALL_FAST_MODEL']=_0x29297a,_0x536c7e=!![]),_0x536c7e&&(fs_1[_0x243186(0x114)]['mkdirSync'](_0x5b20ce,{'recursive':!![]}),fs_1[_0x243186(0x114)][_0x243186(0xfa)](_0x448ece,JSON['stringify'](_0x527e0a,null,0x2),_0x243186(0xd4)),console[_0x243186(0xe8)]('['+(0x0,session_1[_0x243186(0xb0)])()+_0x243186(0xd3)+_0x448ece+'\x20('+settingLabel(_0x42d31e)+_0x243186(0xad)+_0x42d31e[_0x243186(0xe4)]+_0x243186(0xd9)+_0x29297a+')')),_0x448ece;}function isQuotaExhaustedError(_0x1eca93){const _0x5642fb=a1_0x456413;if(/Request\s+rejected.*429/i[_0x5642fb(0xd7)](_0x1eca93))return!![];if(/429.*Request\s+rejected/i['test'](_0x1eca93))return!![];if(/429.*(?:超过.*上限|使用上限|配额|quota|capacity)/i[_0x5642fb(0xd7)](_0x1eca93))return!![];if(/(?:超过.*上限|使用上限|配额|quota|capacity).*429/i[_0x5642fb(0xd7)](_0x1eca93))return!![];return![];}function isAuthenticationError(_0x434481){const _0x5285ad=a1_0x456413;if(/authentication_error/i[_0x5285ad(0xd7)](_0x434481))return!![];if(/401.*(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth)/i[_0x5285ad(0xd7)](_0x434481))return!![];if(/(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth).*401/i['test'](_0x434481))return!![];return![];}function readApiKeyFromSettings(_0x31972b){const _0x201b62=a1_0x456413,_0x239751=path_1[_0x201b62(0x114)][_0x201b62(0xcd)](_0x31972b,'.claude',_0x201b62(0xc6));if(!fs_1[_0x201b62(0x114)][_0x201b62(0xe2)](_0x239751))return null;try{const _0xe85b1a=JSON[_0x201b62(0x106)](fs_1[_0x201b62(0x114)][_0x201b62(0xd0)](_0x239751,_0x201b62(0xd4)));return _0xe85b1a[_0x201b62(0xd8)]?.[_0x201b62(0x124)]||null;}catch{return null;}}function getForceEnabledSettingsPath(_0x35eef9){const _0xe00be4=a1_0x456413,_0x19a6c5=path_1['default'][_0xe00be4(0xcd)](_0x35eef9,_0xe00be4(0x110),'settings-ding.json');if(!fs_1[_0xe00be4(0x114)]['existsSync'](_0x19a6c5))return null;try{const _0x1c2687=JSON[_0xe00be4(0x106)](fs_1[_0xe00be4(0x114)][_0xe00be4(0xd0)](_0x19a6c5,_0xe00be4(0xd4))),_0x4ee1d3=_0x1c2687[_0xe00be4(0xd8)]?.['FORCE_ENABLE'];if(_0x4ee1d3!==undefined&&_0x4ee1d3!==![]&&_0x4ee1d3!=='')return console[_0xe00be4(0xe8)]('['+(0x0,session_1[_0xe00be4(0xb0)])()+_0xe00be4(0xfc)+_0x4ee1d3+',强制使用该配置'),_0x19a6c5;return null;}catch{return null;}}function startupCheck(_0x2f159f){const _0xa5f20c=a1_0x456413,_0x5dc717=[],_0x4ff22e=_0x2f159f['config'],_0x220af4=_0x2f159f[_0xa5f20c(0xab)](),_0x491db5=[{'key':_0xa5f20c(0xb1),'label':_0xa5f20c(0x118)},{'key':_0xa5f20c(0x11e),'label':'whiteUserList\x20(白名单用户)'},{'key':_0xa5f20c(0x108),'label':_0xa5f20c(0xb7)}];for(const {key:_0xb88534,label:_0x471542}of _0x491db5){const _0x50b952=_0x4ff22e[_0xb88534];_0x50b952===undefined||_0x50b952===null||_0x50b952===''||Array[_0xa5f20c(0xae)](_0x50b952)&&_0x50b952[_0xa5f20c(0x100)]===0x0?_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xe5),'message':_0xa5f20c(0xc2)+_0x471542}):_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0x12d),'message':_0xa5f20c(0xaf)+_0x471542+'\x20✓'});}if(!Array[_0xa5f20c(0xae)](_0x4ff22e[_0xa5f20c(0xcb)]))_0x5dc717[_0xa5f20c(0xa8)]({'level':'FATAL','message':'conversations\x20应为数组或已配置'});else{if(_0x4ff22e['conversations'][_0xa5f20c(0x100)]===0x0)_0x5dc717['push']({'level':_0xa5f20c(0x12d),'message':_0xa5f20c(0xe3)});else{const _0x405c9c=new Set();for(let _0x18a2a7=0x0;_0x18a2a7<_0x4ff22e[_0xa5f20c(0xcb)]['length'];_0x18a2a7++){const _0x482d52=_0x4ff22e[_0xa5f20c(0xcb)][_0x18a2a7],_0x202b21=_0xa5f20c(0xbf)+_0x18a2a7+']';if(!_0x482d52['conversationId'])_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xe5),'message':_0x202b21+_0xa5f20c(0xf5)});else _0x405c9c[_0xa5f20c(0xec)](_0x482d52['conversationId'])?_0x5dc717[_0xa5f20c(0xa8)]({'level':'WARN','message':_0x202b21+_0xa5f20c(0xc8)+_0x482d52['conversationId']}):_0x405c9c[_0xa5f20c(0xb4)](_0x482d52[_0xa5f20c(0xb9)]);_0x482d52[_0xa5f20c(0xaa)]&&!_0x4ff22e[_0xa5f20c(0xcb)][_0xa5f20c(0xce)](_0x3bd877=>_0x3bd877[_0xa5f20c(0xb9)]===_0x482d52[_0xa5f20c(0xaa)])&&_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':_0x202b21+'\x20linkConversationId\x20\x22'+_0x482d52['linkConversationId']+_0xa5f20c(0x103)});}_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0x12d),'message':_0xa5f20c(0xe0)+_0x4ff22e[_0xa5f20c(0xcb)]['length']+_0xa5f20c(0x119)});}}if(_0x4ff22e[_0xa5f20c(0xdd)]){const _0x45d464=_0x4ff22e[_0xa5f20c(0xdd)];_0x45d464['resetTime']&&_0x5dc717[_0xa5f20c(0xa8)]({'level':'PASS','message':'apiKeyCfg\x20上次重置时间:\x20'+_0x45d464[_0xa5f20c(0xd5)]});if(!Array['isArray'](_0x45d464[_0xa5f20c(0x122)]))_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':_0xa5f20c(0xbd)});else{if(_0x45d464[_0xa5f20c(0x122)][_0xa5f20c(0x100)]===0x0)_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':_0xa5f20c(0x11b)});else{const _0x2c2488=new Set();for(let _0xf2cc34=0x0;_0xf2cc34<_0x45d464[_0xa5f20c(0x122)][_0xa5f20c(0x100)];_0xf2cc34++){const _0x1078cc=_0x45d464['claudeSettings'][_0xf2cc34],_0x33dc9f='apiKeyCfg.claudeSettings['+_0xf2cc34+']';if(!_0x1078cc['apiKey'])_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xe5),'message':_0x33dc9f+_0xa5f20c(0xbe)});else _0x2c2488[_0xa5f20c(0xec)](_0x1078cc[_0xa5f20c(0xbc)])?_0x5dc717[_0xa5f20c(0xa8)]({'level':'WARN','message':_0x33dc9f+_0xa5f20c(0xee)+settingLabel(_0x1078cc)}):_0x2c2488['add'](_0x1078cc[_0xa5f20c(0xbc)]);!_0x1078cc[_0xa5f20c(0xe7)]&&_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':_0x33dc9f+'\x20缺少\x20baseUrl'}),!_0x1078cc[_0xa5f20c(0xe4)]&&_0x5dc717['push']({'level':_0xa5f20c(0xf0),'message':_0x33dc9f+_0xa5f20c(0xdb)}),typeof _0x1078cc[_0xa5f20c(0xf3)]!==_0xa5f20c(0xde)&&_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':_0x33dc9f+_0xa5f20c(0xc1)+typeof _0x1078cc['isValid']});}const _0x40e1fc=_0x45d464[_0xa5f20c(0x122)][_0xa5f20c(0xb6)](_0x441640=>_0x441640['isValid'])[_0xa5f20c(0x100)];_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0x12d),'message':_0xa5f20c(0x10e)+_0x45d464[_0xa5f20c(0x122)][_0xa5f20c(0x100)]+_0xa5f20c(0x107)+_0x40e1fc});}}}const _0x3dacab=path_1[_0xa5f20c(0x114)][_0xa5f20c(0xcd)]((0x0,session_1['getHomeDir'])(),_0xa5f20c(0x11d),'settings-tpl.json');if(fs_1[_0xa5f20c(0x114)][_0xa5f20c(0xe2)](_0x3dacab))try{const _0x2da787=JSON['parse'](fs_1['default'][_0xa5f20c(0xd0)](_0x3dacab,_0xa5f20c(0xd4)));if(typeof _0x2da787!==_0xa5f20c(0x10a)||_0x2da787===null)_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':_0xa5f20c(0x11a)});else{if(!_0x2da787[_0xa5f20c(0xd8)]||typeof _0x2da787[_0xa5f20c(0xd8)]!=='object')_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':'settings-tpl.json\x20缺少\x20env\x20字段,创建\x20settings-ding.json\x20时将不包含预配置环境变量'});else{const _0x3b17c1=Object[_0xa5f20c(0x120)](_0x2da787[_0xa5f20c(0xd8)]);_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0x12d),'message':_0xa5f20c(0xb5)+(_0x3b17c1['join'](',\x20')||'(空)')});}}}catch(_0x443629){_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xf0),'message':_0xa5f20c(0x129)+(_0x443629 instanceof Error?_0x443629['message']:_0x443629)});}else _0x5dc717['push']({'level':_0xa5f20c(0xf0),'message':_0xa5f20c(0x12f)+_0x3dacab+_0xa5f20c(0xf7)});try{(0x0,child_process_1['execSync'])(_0xa5f20c(0xbb),{'stdio':_0xa5f20c(0xb8)}),_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0x12d),'message':_0xa5f20c(0x101)});}catch{_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xe5),'message':_0xa5f20c(0x125)});}try{const _0xbbeccc=path_1[_0xa5f20c(0x114)][_0xa5f20c(0xcd)](_0x220af4,'.healthcheck');fs_1[_0xa5f20c(0x114)][_0xa5f20c(0xfa)](_0xbbeccc,'ok',_0xa5f20c(0xd4)),fs_1['default']['unlinkSync'](_0xbbeccc),_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0x12d),'message':'工作目录可写:\x20'+_0x220af4});}catch(_0x268cb2){_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0xe5),'message':_0xa5f20c(0xcc)+_0x220af4+_0xa5f20c(0xed)+(_0x268cb2 instanceof Error?_0x268cb2['message']:_0x268cb2)});}if(Array['isArray'](_0x4ff22e[_0xa5f20c(0xcb)]))for(const _0x9d62dc of _0x4ff22e[_0xa5f20c(0xcb)]){const _0x17023c=_0x2f159f[_0xa5f20c(0xe1)](_0x9d62dc[_0xa5f20c(0xb9)]);try{fs_1[_0xa5f20c(0x114)]['mkdirSync'](_0x17023c,{'recursive':!![]}),_0x5dc717[_0xa5f20c(0xa8)]({'level':_0xa5f20c(0x12d),'message':_0xa5f20c(0xb3)+(_0x9d62dc[_0xa5f20c(0xeb)]||_0x9d62dc['conversationId'])});}catch(_0x36c496){_0x5dc717[_0xa5f20c(0xa8)]({'level':'WARN','message':_0xa5f20c(0xd2)+_0x17023c+_0xa5f20c(0xed)+(_0x36c496 instanceof Error?_0x36c496[_0xa5f20c(0xcf)]:_0x36c496)});}}console[_0xa5f20c(0xe8)]('\x0a['+(0x0,session_1[_0xa5f20c(0xb0)])()+_0xa5f20c(0xff));const _0x47b19d=_0x5dc717[_0xa5f20c(0xce)](_0x2a2e30=>_0x2a2e30[_0xa5f20c(0x12e)]===_0xa5f20c(0xe5));for(const _0x21bd38 of _0x5dc717){const _0x1ceb28=_0x21bd38[_0xa5f20c(0x12e)]===_0xa5f20c(0x12d)?'✓':_0x21bd38[_0xa5f20c(0x12e)]===_0xa5f20c(0xe5)?'✗':'⚠',_0x4348c6=_0x21bd38[_0xa5f20c(0x12e)]===_0xa5f20c(0x12d)?_0x21bd38[_0xa5f20c(0xcf)]:_0x21bd38[_0xa5f20c(0x12e)]==='FATAL'?'[FATAL]\x20'+_0x21bd38[_0xa5f20c(0xcf)]:_0xa5f20c(0xc5)+_0x21bd38[_0xa5f20c(0xcf)];console['log']('\x20\x20'+_0x1ceb28+'\x20'+_0x4348c6);}const _0x45b838=_0x5dc717[_0xa5f20c(0xb6)](_0x5abbfb=>_0x5abbfb[_0xa5f20c(0x12e)]===_0xa5f20c(0x12d))[_0xa5f20c(0x100)],_0x21fbc1=_0x5dc717[_0xa5f20c(0xb6)](_0x4a3a62=>_0x4a3a62[_0xa5f20c(0x12e)]===_0xa5f20c(0xf0))[_0xa5f20c(0x100)],_0x4dc19c=_0x5dc717[_0xa5f20c(0xb6)](_0x25703d=>_0x25703d[_0xa5f20c(0x12e)]===_0xa5f20c(0xe5))[_0xa5f20c(0x100)];console['log']('['+(0x0,session_1[_0xa5f20c(0xb0)])()+']\x20自检完成:\x20'+_0x45b838+_0xa5f20c(0x10d)+_0x21fbc1+_0xa5f20c(0x130)+_0x4dc19c+_0xa5f20c(0xba)),console[_0xa5f20c(0xe8)]('['+(0x0,session_1[_0xa5f20c(0xb0)])()+_0xa5f20c(0x116)),_0x47b19d&&(console['error']('['+(0x0,session_1[_0xa5f20c(0xb0)])()+_0xa5f20c(0xc3)),process[_0xa5f20c(0x12a)](0x1));}
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(s){return s&&s.__esModule?s:{default:s}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveClientConfig=saveClientConfig,exports.resetApiKeyCfg=resetApiKeyCfg,exports.scheduleApiKeyCfgDailyReset=scheduleApiKeyCfgDailyReset,exports.settingLabel=settingLabel,exports.rotateApiKey=rotateApiKey,exports.pickValidApiKey=pickValidApiKey,exports.ensureSettingsWithApiKey=ensureSettingsWithApiKey,exports.isQuotaExhaustedError=isQuotaExhaustedError,exports.isAuthenticationError=isAuthenticationError,exports.readApiKeyFromSettings=readApiKeyFromSettings,exports.getForceEnabledSettingsPath=getForceEnabledSettingsPath,exports.startupCheck=startupCheck;const fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),child_process_1=require("child_process"),session_1=require("./session"),utils_ok_1=require("utils-ok");function saveClientConfig(s){const e=`${s.getClientDir()}/config.json`;try{fs_1.default.writeFileSync(e,JSON.stringify(s.config,null,2),"utf-8")}catch(n){console.error(`[${(0,session_1.timestamp)()}] \u4FDD\u5B58 config.json \u5931\u8D25:`,n)}}function resetApiKeyCfg(s){const e=s.config.apiKeyCfg;if(!e)return;const n=new Date;e.resetTime=utils_ok_1.dateUtil.mm(n.getTime()).format("YYYY-MM-DD HH:mm:ss");let i=0;for(const l of e.claudeSettings)l.isValid||(l.isValid=!0,i++);i>0&&console.log(`[${(0,session_1.timestamp)()}] ${i} \u4E2A\u5DF2\u5931\u6548 Claude Setting \u91CD\u65B0\u6807\u8BB0\u4E3A\u6709\u6548`),saveClientConfig(s),console.log(`[${(0,session_1.timestamp)()}] apiKeyCfg \u5DF2\u91CD\u7F6E (\u6240\u6709 Claude Setting isValid=true)`)}function scheduleApiKeyCfgDailyReset(s){const e=()=>{const n=new Date,i=new Date(n.getFullYear(),n.getMonth(),n.getDate()+1,0,0,0,0),l=i.getTime()-n.getTime();setTimeout(()=>{console.log(`[${(0,session_1.timestamp)()}] \u5B9A\u65F6\u91CD\u7F6E apiKeyCfg (\u6BCF\u59290\u70B9)`),resetApiKeyCfg(s),e()},l),console.log(`[${(0,session_1.timestamp)()}] apiKeyCfg \u6BCF\u65E5\u91CD\u7F6E\u5DF2\u8C03\u5EA6\uFF0C\u4E0B\u6B21\u91CD\u7F6E: ${i.toISOString()}`)};e()}function settingLabel(s){return s.memo?s.memo:`...${s.apiKey.slice(-6)}`}function findSettingLabel(s,e){const n=s.find(i=>i.apiKey===e);return n?settingLabel(n):`...${e.slice(-6)}`}function rotateApiKey(s,e){const n=s.config.apiKeyCfg;if(!n)return null;for(const r of n.claudeSettings)if(r.apiKey===e&&r.isValid){r.isValid=!1;break}const i=n.claudeSettings.filter(r=>r.isValid).length,l=findSettingLabel(n.claudeSettings,e);return console.log(`[${(0,session_1.timestamp)()}] Claude Setting \u5DF2\u5931\u6548: ${l}, \u5269\u4F59\u6709\u6548: ${i}`),saveClientConfig(s),pickValidApiKey(s)}function pickValidApiKey(s){const e=s.config.apiKeyCfg;if(!e)return null;const n=e.claudeSettings.filter(i=>i.isValid);return n.length===0?null:n[Math.floor(Math.random()*n.length)]}function ensureSettingsWithApiKey(s,e){const n=path_1.default.join(s,".claude"),i=path_1.default.join(n,"settings-ding.json");let l={};if(fs_1.default.existsSync(i))try{l=JSON.parse(fs_1.default.readFileSync(i,"utf-8"))}catch{l={}}else{const g=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding","settings-tpl.json");if(fs_1.default.existsSync(g))try{l=JSON.parse(fs_1.default.readFileSync(g,"utf-8")),console.log(`[${(0,session_1.timestamp)()}] \u4ECE\u6A21\u677F\u521B\u5EFA settings-ding.json: ${g}`)}catch{l={}}}l.env||(l.env={});let r=!1;l.env.ANTHROPIC_AUTH_TOKEN!==e.apiKey&&(l.env.ANTHROPIC_AUTH_TOKEN=e.apiKey,r=!0),e.baseUrl&&l.env.ANTHROPIC_BASE_URL!==e.baseUrl&&(l.env.ANTHROPIC_BASE_URL=e.baseUrl,r=!0),e.model&&l.env.ANTHROPIC_MODEL!==e.model&&(l.env.ANTHROPIC_MODEL=e.model,r=!0);const f=e.smallModel||e.model;return f&&l.env.CLAUDE_SMALL_FAST_MODEL!==f&&(l.env.CLAUDE_SMALL_FAST_MODEL=f,r=!0),r&&(fs_1.default.mkdirSync(n,{recursive:!0}),fs_1.default.writeFileSync(i,JSON.stringify(l,null,2),"utf-8"),console.log(`[${(0,session_1.timestamp)()}] \u5DF2\u5199\u5165 Claude \u914D\u7F6E\u5230 ${i} (${settingLabel(e)}, model: ${e.model}, smallModel: ${f})`)),i}function isQuotaExhaustedError(s){return!!(/Request\s+rejected.*429/i.test(s)||/429.*Request\s+rejected/i.test(s)||/429.*(?:超过.*上限|使用上限|配额|quota|capacity)/i.test(s)||/(?:超过.*上限|使用上限|配额|quota|capacity).*429/i.test(s))}function isAuthenticationError(s){return!!(/authentication_error/i.test(s)||/401.*(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth)/i.test(s)||/(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth).*401/i.test(s))}function readApiKeyFromSettings(s){const e=path_1.default.join(s,".claude","settings-ding.json");if(!fs_1.default.existsSync(e))return null;try{return JSON.parse(fs_1.default.readFileSync(e,"utf-8")).env?.ANTHROPIC_AUTH_TOKEN||null}catch{return null}}function getForceEnabledSettingsPath(s){const e=path_1.default.join(s,".claude","settings-ding.json");if(!fs_1.default.existsSync(e))return null;try{const i=JSON.parse(fs_1.default.readFileSync(e,"utf-8")).env?.FORCE_ENABLE;return i!==void 0&&i!==!1&&i!==""?(console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230 settings-ding.json FORCE_ENABLE=${i}\uFF0C\u5F3A\u5236\u4F7F\u7528\u8BE5\u914D\u7F6E`),e):null}catch{return null}}function startupCheck(s){const e=[],n=s.config,i=s.getClientDir(),l=[{key:"clientSecret",label:"clientSecret (\u9489\u9489 Stream Client \u5BC6\u94A5)"},{key:"whiteUserList",label:"whiteUserList (\u767D\u540D\u5355\u7528\u6237)"},{key:"owner",label:"owner (\u673A\u5668\u4EBA owner)"}];for(const{key:t,label:a}of l){const o=n[t];o==null||o===""||Array.isArray(o)&&o.length===0?e.push({level:"FATAL",message:`config.json \u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5: ${a}`}):e.push({level:"PASS",message:`config.json ${a} \u2713`})}if(!Array.isArray(n.conversations))e.push({level:"FATAL",message:"conversations \u5E94\u4E3A\u6570\u7EC4\u6216\u5DF2\u914D\u7F6E"});else if(n.conversations.length===0)e.push({level:"PASS",message:"conversations \u4E3A\u7A7A\u6570\u7EC4\uFF0C\u53EF\u901A\u8FC7 /reg \u547D\u4EE4\u52A8\u6001\u6CE8\u518C"});else{const t=new Set;for(let a=0;a<n.conversations.length;a++){const o=n.conversations[a],c=`conversations[${a}]`;o.conversationId?t.has(o.conversationId)?e.push({level:"WARN",message:`${c} conversationId \u91CD\u590D: ${o.conversationId}`}):t.add(o.conversationId):e.push({level:"FATAL",message:`${c} \u7F3A\u5C11 conversationId`}),o.linkConversationId&&!n.conversations.some(u=>u.conversationId===o.linkConversationId)&&e.push({level:"WARN",message:`${c} linkConversationId "${o.linkConversationId}" \u672A\u5728 conversations \u4E2D\u627E\u5230`})}e.push({level:"PASS",message:`conversations \u5171 ${n.conversations.length} \u4E2A\u7FA4\u914D\u7F6E`})}if(n.apiKeyCfg){const t=n.apiKeyCfg;if(t.resetTime&&e.push({level:"PASS",message:`apiKeyCfg \u4E0A\u6B21\u91CD\u7F6E\u65F6\u95F4: ${t.resetTime}`}),!Array.isArray(t.claudeSettings))e.push({level:"WARN",message:"apiKeyCfg.claudeSettings \u4E0D\u662F\u6570\u7EC4\uFF0CAPI Key \u8F6E\u6362\u529F\u80FD\u4E0D\u53EF\u7528"});else if(t.claudeSettings.length===0)e.push({level:"WARN",message:"apiKeyCfg.claudeSettings \u4E3A\u7A7A\uFF0C\u65E0\u53EF\u7528 Key"});else{const a=new Set;for(let c=0;c<t.claudeSettings.length;c++){const u=t.claudeSettings[c],d=`apiKeyCfg.claudeSettings[${c}]`;u.apiKey?a.has(u.apiKey)?e.push({level:"WARN",message:`${d} apiKey \u91CD\u590D: ${settingLabel(u)}`}):a.add(u.apiKey):e.push({level:"FATAL",message:`${d} \u7F3A\u5C11 apiKey`}),u.baseUrl||e.push({level:"WARN",message:`${d} \u7F3A\u5C11 baseUrl`}),u.model||e.push({level:"WARN",message:`${d} \u7F3A\u5C11 model`}),typeof u.isValid!="boolean"&&e.push({level:"WARN",message:`${d} isValid \u7C7B\u578B\u5F02\u5E38: ${typeof u.isValid}`})}const o=t.claudeSettings.filter(c=>c.isValid).length;e.push({level:"PASS",message:`apiKeyCfg.claudeSettings \u5171 ${t.claudeSettings.length} \u9879\uFF0C\u6709\u6548 ${o}`})}}const r=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding","settings-tpl.json");if(fs_1.default.existsSync(r))try{const t=JSON.parse(fs_1.default.readFileSync(r,"utf-8"));if(typeof t!="object"||t===null)e.push({level:"WARN",message:"settings-tpl.json \u6839\u5143\u7D20\u4E0D\u662F\u5BF9\u8C61"});else if(!t.env||typeof t.env!="object")e.push({level:"WARN",message:"settings-tpl.json \u7F3A\u5C11 env \u5B57\u6BB5\uFF0C\u521B\u5EFA settings-ding.json \u65F6\u5C06\u4E0D\u5305\u542B\u9884\u914D\u7F6E\u73AF\u5883\u53D8\u91CF"});else{const a=Object.keys(t.env);e.push({level:"PASS",message:`settings-tpl.json \u6709\u6548\uFF0Cenv \u5305\u542B: ${a.join(", ")||"(\u7A7A)"}`})}}catch(t){e.push({level:"WARN",message:`settings-tpl.json \u89E3\u6790\u5931\u8D25: ${t instanceof Error?t.message:t}`})}else e.push({level:"WARN",message:`settings-tpl.json \u4E0D\u5B58\u5728: ${r}\uFF0C\u521B\u5EFA settings-ding.json \u65F6\u5C06\u4F7F\u7528\u7A7A\u6A21\u677F`});try{(0,child_process_1.execSync)("which claude",{stdio:"pipe"}),e.push({level:"PASS",message:"claude \u547D\u4EE4\u53EF\u7528"})}catch{e.push({level:"FATAL",message:"claude \u547D\u4EE4\u4E0D\u53EF\u7528\uFF0C\u8BF7\u786E\u8BA4 Claude Code CLI \u5DF2\u5B89\u88C5"})}try{const t=path_1.default.join(i,".healthcheck");fs_1.default.writeFileSync(t,"ok","utf-8"),fs_1.default.unlinkSync(t),e.push({level:"PASS",message:`\u5DE5\u4F5C\u76EE\u5F55\u53EF\u5199: ${i}`})}catch(t){e.push({level:"FATAL",message:`\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u53EF\u5199: ${i} \u2014 ${t instanceof Error?t.message:t}`})}if(Array.isArray(n.conversations))for(const t of n.conversations){const a=s.getConversationDir(t.conversationId);try{fs_1.default.mkdirSync(a,{recursive:!0}),e.push({level:"PASS",message:`\u7FA4\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u5C31\u7EEA: ${t.conversationTitle||t.conversationId}`})}catch(o){e.push({level:"WARN",message:`\u7FA4\u5DE5\u4F5C\u76EE\u5F55\u521B\u5EFA\u5931\u8D25: ${a} \u2014 ${o instanceof Error?o.message:o}`})}}console.log(`
|
|
2
|
+
[${(0,session_1.timestamp)()}] ========== \u542F\u52A8\u81EA\u68C0 ==========`);const f=e.some(t=>t.level==="FATAL");for(const t of e){const a=t.level==="PASS"?"\u2713":t.level==="FATAL"?"\u2717":"\u26A0",o=t.level==="PASS"?t.message:t.level==="FATAL"?`[FATAL] ${t.message}`:`[WARN] ${t.message}`;console.log(` ${a} ${o}`)}const g=e.filter(t=>t.level==="PASS").length,p=e.filter(t=>t.level==="WARN").length,v=e.filter(t=>t.level==="FATAL").length;console.log(`[${(0,session_1.timestamp)()}] \u81EA\u68C0\u5B8C\u6210: ${g} \u901A\u8FC7, ${p} \u8B66\u544A, ${v} \u81F4\u547D`),console.log(`[${(0,session_1.timestamp)()}] ==============================
|
|
3
|
+
`),f&&(console.error(`[${(0,session_1.timestamp)()}] \u542F\u52A8\u81EA\u68C0\u53D1\u73B0\u81F4\u547D\u9519\u8BEF\uFF0C\u8FDB\u7A0B\u9000\u51FA`),process.exit(1))}
|
|
@@ -1 +1,85 @@
|
|
|
1
|
-
'use strict';const a2_0x14d974=a2_0x2a4e;(function(_0x3fb46f,_0xbf5196){const _0x44f3fc=a2_0x2a4e,_0x1639c2=_0x3fb46f();while(!![]){try{const _0x4a50d8=parseInt(_0x44f3fc(0x1da))/0x1*(-parseInt(_0x44f3fc(0xde))/0x2)+-parseInt(_0x44f3fc(0x1ee))/0x3+parseInt(_0x44f3fc(0x115))/0x4*(-parseInt(_0x44f3fc(0x188))/0x5)+-parseInt(_0x44f3fc(0x112))/0x6+-parseInt(_0x44f3fc(0x1f3))/0x7*(parseInt(_0x44f3fc(0x123))/0x8)+parseInt(_0x44f3fc(0x1bc))/0x9+parseInt(_0x44f3fc(0x164))/0xa;if(_0x4a50d8===_0xbf5196)break;else _0x1639c2['push'](_0x1639c2['shift']());}catch(_0x411b8a){_0x1639c2['push'](_0x1639c2['shift']());}}}(a2_0x3f9c,0xa8bcc));function a2_0x2a4e(_0x35dbf7,_0x2bdaf1){_0x35dbf7=_0x35dbf7-0xbb;const _0x3f9c85=a2_0x3f9c();let _0x2a4e57=_0x3f9c85[_0x35dbf7];return _0x2a4e57;}var __createBinding=this&&this[a2_0x14d974(0x218)]||(Object[a2_0x14d974(0x1bf)]?function(_0x4f33fb,_0x5200b1,_0x181e4a,_0x2018d5){const _0x2786bc=a2_0x14d974;if(_0x2018d5===undefined)_0x2018d5=_0x181e4a;var _0x118f5d=Object[_0x2786bc(0x182)](_0x5200b1,_0x181e4a);(!_0x118f5d||(_0x2786bc(0x119)in _0x118f5d?!_0x5200b1[_0x2786bc(0xf0)]:_0x118f5d[_0x2786bc(0x130)]||_0x118f5d[_0x2786bc(0x155)]))&&(_0x118f5d={'enumerable':!![],'get':function(){return _0x5200b1[_0x181e4a];}}),Object[_0x2786bc(0x103)](_0x4f33fb,_0x2018d5,_0x118f5d);}:function(_0x153760,_0x282536,_0x2ae5c1,_0x4086d0){if(_0x4086d0===undefined)_0x4086d0=_0x2ae5c1;_0x153760[_0x4086d0]=_0x282536[_0x2ae5c1];}),__setModuleDefault=this&&this[a2_0x14d974(0x179)]||(Object[a2_0x14d974(0x1bf)]?function(_0x483f33,_0x40c00a){const _0x99cd24=a2_0x14d974;Object['defineProperty'](_0x483f33,_0x99cd24(0x15c),{'enumerable':!![],'value':_0x40c00a});}:function(_0x1e2d56,_0x4b1d85){const _0x13c781=a2_0x14d974;_0x1e2d56[_0x13c781(0x15c)]=_0x4b1d85;}),__importStar=this&&this[a2_0x14d974(0x125)]||(function(){var _0x231b06=function(_0x349098){return _0x231b06=Object['getOwnPropertyNames']||function(_0x45e80b){const _0x103771=a2_0x2a4e;var _0xd8932b=[];for(var _0x3a74db in _0x45e80b)if(Object['prototype'][_0x103771(0xc2)][_0x103771(0x181)](_0x45e80b,_0x3a74db))_0xd8932b[_0xd8932b['length']]=_0x3a74db;return _0xd8932b;},_0x231b06(_0x349098);};return function(_0x154eb1){const _0x542a58=a2_0x2a4e;if(_0x154eb1&&_0x154eb1[_0x542a58(0xf0)])return _0x154eb1;var _0x168be5={};if(_0x154eb1!=null){for(var _0x28c0e7=_0x231b06(_0x154eb1),_0x2c9e8d=0x0;_0x2c9e8d<_0x28c0e7[_0x542a58(0x206)];_0x2c9e8d++)if(_0x28c0e7[_0x2c9e8d]!==_0x542a58(0x15c))__createBinding(_0x168be5,_0x154eb1,_0x28c0e7[_0x2c9e8d]);}return __setModuleDefault(_0x168be5,_0x154eb1),_0x168be5;};}()),__importDefault=this&&this[a2_0x14d974(0x12f)]||function(_0x535caa){const _0x2983b4=a2_0x14d974;return _0x535caa&&_0x535caa[_0x2983b4(0xf0)]?_0x535caa:{'default':_0x535caa};};function a2_0x3f9c(){const _0x418a86=['❌\x20只有机器人\x20owner\x20才能执行此操作','receiveReply','executeClaudeQuery','text','15865WPjDSr',':**\x20','resolveAndValidatePath','❌\x20路径不存在或不是目录:\x20**','sendClaudeResponseToDing','⚠️\x20','###\x20🌐\x20全局核心配置\x0a','-\x20图片文件:\x20','✅\x20已移除\x20','parseMqCommand','add','appendSessionLog','/task\x20','statSync','claudeSettings','handleMkdirCommand','extractQuoteInfo','find','botMsgGetCallback',']\x20注册新群:\x20','start\x20cmd\x20/k\x20\x22cd\x20/d\x20','tasksDeleted','whiteUserList','resetApiKeyCfg','push','parseOpenCommand','session',']\x20创建工作目录:\x20','path','isOwner','Error:\x20DingStreamClient\x20init\x20failed.','processRichTextMessage','parseCommandHelp','task','isDirectory','key','**\x20已暂停','getOneTodoTask','❌\x20路径已存在但不是目录:\x20`','###\x20📝\x20任务队列信息\x0a','📋\x20任务已收到,完成后我会回复','✅\x20已添加\x20','splice','parseRmCommand','findLatestSession','../common','./quote','formatHelpOverview','assistant','switchToSession','messageQueue','exec','3123369loPuVo','resolveToUserId','isMobile','create','sanitizeOutput','format','📂\x20已在文件管理器中打开:\x0a```\x0a','activeSessions','min','列出\x20','**\x0a\x0a💡\x20输入\x20`/help`\x20查看所有可用命令','resetTime','explorer\x20\x22','map','sendDingMessage','dingToken','抱歉,您暂无使用权限,请联系应用机器人owner授权...','truncateMsg','恢复定时任务\x20','层):\x0a```\x0a','useLocalOcr','isValidCronExpression','errors','⚠️\x20图片下载失败,请重试或使用文字描述','rmSync','content','-\x20**群名称:**\x20','atSender','del','\x0a...(输出已截断)','6719yQJPui','writeFileSync','mkdirSync','cancelTask',']\x20启动任务处理器\x20#','socketCallBackResponse','(空,使用全局白名单)','timestamp','parse','debugLog','saveClientConfig','parseClaudeStreamLine','\x20到当前群白名单\x0a当前白名单:\x20','join','getConversationConfig','message','sendCronNoNotifyError','./cron','existsSync','###\x20🤖\x20群配置信息\x0a','3685410KODdYC','delete','create_nl','platform','📂\x20','828569lLnPOZ','./task','⏸️\x20定时任务\x20**','description','apiKeyCfg','创建定时任务:\x20','type','imagesDeleted','getPkgVersion','getSessionDir','preBash','/session.json','\x0a💡\x20可编辑\x20config.json\x20补充更多配置','暂停定时任务\x20','removeJob','trim','utf-8','sessionsDeleted','⏳\x20正在分析定时任务描述...','length','user','-\x20**dingToken:**\x20','`\x0a\x0a💡\x20格式:\x20`分\x20时\x20日\x20月\x20周`,如\x20`0\x209\x20*\x20*\x20*`','\x20不在当前群白名单中','startNewSession','❌\x20未找到命令:\x20**','`\x0a最后修改时间:\x20','finishTask',']\x20群配置:\x20','DEFAULT_TASK_HANDLER_COUNT','connect','startsWith','conversationType','###\x20💬\x20当前会话信息\x0a','defaultDingToken','⚠️\x20该群未注册,请先使用\x20`/cfg`\x20命令注册','conversationConfig','__createBinding','findHistorySession','⚠️\x20无法解析手机号:\x20','robotCode','resume','richText','start','parseResetApiKeyCfgCommand','未找到定时任务:\x20','pictureDownloadCode','getTasksDir','hasOwnProperty','scheduleApiKeyCfgDailyReset','CronEngine','staffId','getOrCreateLogSession','darwin','❌\x20路径超出工作目录范围','收到消息:\x20群=','DEFAULT_SESSION_MAX_CONCURRENCY','cronExpression','-\x20**atSender:**\x20false\x20(不\x20@\x20发送人)','messageId','run','▶️\x20定时任务\x20**','检测到引用消息:\x20quoteMessageId=','root','parseCfgCommand','conversationId','create_cron','getActiveSessionsFile','✅\x20文件创建成功:\x20`','parseVersionCommand','✅\x20目录创建成功:\x20`','./session','**\x20已删除','requireOwnerOrSingleChat','child_process','\x0a\x0a💡\x20你也可以直接指定cron表达式:\x20`/cron\x200\x209\x20*\x20*\x20*\x20任务描述`','292zgLhKc','sanitizeLogContent','/cron\x20','❌\x20当前群未配置\x20dingToken\x20且无客户端级\x20defaultDingToken,\x20定时任务无法主动发送消息,\x20请联系管理员配置','cleanCache',')\x20类型=','unlinkSync','replace','parseCleanCommand','cronEngine','all','❌\x20目录创建失败:\x20`','now','✅\x20群配置已刷新','Fatal\x20error','hasNotifyCapability','🚀\x20请输入您的问题开始新会话','✅\x20已从队尾移除\x20','__esModule','findActiveSession','pause','抱歉,该群的机器人未在服务端注册,请联系应用机器人owner注册(','**\x20的目录','parsePwdCommand','processPictureMessage','cancel','📨\x20消息队列\x20(','[cron]','filter','config',',\x20会话ID=','⚠️\x20目录已存在:\x20`','slice','log','./messaging','parseMkdirCommand','getClientConfig','defineProperty','❌\x20打开失败:\x20','saveActiveSession','sessionDir','markdown','list','getSessionsDir','YYYY-MM-DD\x20HH:mm:ss','❌\x20只有机器人\x20owner\x20才能清除所有群缓存','addJob','dingStreamClient','-\x20**receiveReply:**\x20false\x20(不回复确认消息)','./api-key-manager','listJobs','✅\x20执行成功\x0a```\x0a','4871094xJXMMl','-\x20**会话类型:**\x20','clientSecret','208ulaaOI','parseInfoCommand','substring','当前工作目录','get','quoteText','conversationTitle','handleSessionMessage','picture','formatCronJobInfo','DingClaude','./commands','getClientDir','parseContinueSessionCommand','48kzdqrh','...','__importStar','/cron\x20resume\x20',']\x20[SYSTEM]:\x20创建会话用于记录\x20/cron\x20命令操作\x0a','❌\x20无效的cron表达式:\x20`','❌\x20删除失败:\x20`','-\x20**linkConversationId:**\x20','❌\x20未找到定时任务:\x20','analyzeAndCreate',']\x20钉钉机器人服务启动,clientId:\x20','prompt','__importDefault','writable','-\x20**工作目录:**\x20','✅\x20定时任务\x20**','/v1.0/im/bot/messages/get','isValid','\x0a```','data','**版本:**\x20','./image','⚠️\x20未找到已结束的会话','\x0a-\x20重置时间:\x20','resolveUserId','parseLsCommand','senderStaffId',']\x20任务处理器数量:\x20','loadActiveSessions','formatConversationInfo','requireOwner','formatSessionInfo','`\x0a原因:\x20','getConversationDir','❌\x20只有机器人\x20owner\x20才能操作其他群的配置','then','interruptClaudeProcess','countTodoTask','exit','dateUtil','formatPromptWithQuote','folder','\x0a\x0a**stderr:**\x0a```\x0a','runTaskHandlerLoop','\x20条消息','\x20行日志:\x0a```\x0a','clientId','input','###\x20💬\x20当前会话信息\x0a无活跃会话','\x20&&\x20','configurable','❌\x20路径已存在但不是文件:\x20`','senderNick','job','error','⚠️\x20当前无活跃会话或暂无日志','\x0a💡\x20活跃会话已保留','default','robot','DEFAULT_TASK_QUEUE_SIZE','saveTask','handleCronCommand','resolve','📭\x20当前无排队消息','stringify','42405980WvxIaH','authCheck','handleRmCommand','utils-ok','(无输出)','getSessionId','readSessionLogTail','findSubdirByName','定时任务分析失败:\x20','updateSessionFile','parseCronCommand','(未配置群级白名单,使用全局白名单)','userIdToPhone','(无历史数据)','endSession','**\x20已恢复','./claude-process','resolveAllPhonesInConfig','registerCallbackListener','\x20条消息\x0a','🧹\x20缓存清理完成','__setModuleDefault','some','formatTaskInfo','toggleJob','linkConversationId','open\x20-a\x20Terminal\x20\x22','handleTouchCommand','✅\x20已删除','call','getOwnPropertyDescriptor','conversations'];a2_0x3f9c=function(){return _0x418a86;};return a2_0x3f9c();}Object[a2_0x14d974(0x103)](exports,a2_0x14d974(0xf0),{'value':!![]}),exports[a2_0x14d974(0x11f)]=void 0x0;const child_process_1=require(a2_0x14d974(0xdc)),utils_ok_1=require(a2_0x14d974(0x167)),fs_1=__importDefault(require('fs')),path_1=__importDefault(require(a2_0x14d974(0x1a4))),common_1=require(a2_0x14d974(0x1b5)),quote_1=require(a2_0x14d974(0x1b6)),messaging_1=require(a2_0x14d974(0x100)),image_1=require(a2_0x14d974(0x138)),commands_1=require(a2_0x14d974(0x120)),messaging_2=require('./messaging'),claude_process_1=require(a2_0x14d974(0x174)),session_1=require(a2_0x14d974(0xd9)),task_1=require(a2_0x14d974(0x1f4)),api_key_manager_1=require(a2_0x14d974(0x10f)),cron_1=require(a2_0x14d974(0x1eb)),TOOL_VERSION=(0x0,common_1['projUtil'])()[a2_0x14d974(0x1fb)]();class DingClaude{constructor(_0x3cf962){const _0x874c98=a2_0x14d974;this['resolvedPhones']={},this['activeSessions']=new Map(),this[_0x874c98(0xca)]=0x5,this['DEFAULT_TASK_HANDLER_COUNT']=0x1,this[_0x874c98(0x15e)]=0x32,this[_0x874c98(0x1ca)]=_0x2032ef=>(0x0,messaging_2[_0x874c98(0x1ca)])(this,_0x2032ef),this[_0x874c98(0x18c)]=(_0x1b8877,_0x7399ca,_0x1175f3,_0x1609f5)=>(0x0,messaging_2[_0x874c98(0x18c)])(this,_0x1b8877,_0x7399ca,_0x1175f3,_0x1609f5),this[_0x874c98(0x1e5)]=claude_process_1[_0x874c98(0x1e5)],this[_0x874c98(0x147)]=(_0x53435c,_0x43640)=>(0x0,claude_process_1['interruptClaudeProcess'])(_0x53435c,_0x43640),this[_0x874c98(0x186)]=(_0x4ec1d5,_0xbdd15f,_0x26577c)=>(0x0,claude_process_1[_0x874c98(0x186)])(this,_0x4ec1d5,_0xbdd15f,_0x26577c),this[_0x874c98(0x121)]=()=>(0x0,session_1[_0x874c98(0x121)])(this),this[_0x874c98(0x102)]=()=>(0x0,session_1['getClientConfig'])(this),this[_0x874c98(0x165)]=(_0x50cd39,_0x5d64a6)=>(0x0,session_1[_0x874c98(0x165)])(this,_0x50cd39,_0x5d64a6),this['isOwner']=_0x54df67=>(0x0,session_1[_0x874c98(0x1a5)])(this,_0x54df67),this[_0x874c98(0x1e3)]=(_0x3f81d5,..._0x520bbc)=>(0x0,session_1[_0x874c98(0x1e3)])(this,_0x3f81d5,..._0x520bbc),this['hashConversationId']=_0x104537=>(0x0,session_1['hashConversationId'])(this,_0x104537),this[_0x874c98(0x1e8)]=_0x37ad7c=>(0x0,session_1[_0x874c98(0x1e8)])(this,_0x37ad7c),this[_0x874c98(0x144)]=_0x16e3ba=>(0x0,session_1[_0x874c98(0x144)])(this,_0x16e3ba),this[_0x874c98(0x109)]=_0x26cf61=>(0x0,session_1[_0x874c98(0x109)])(this,_0x26cf61),this[_0x874c98(0xc1)]=_0x2d9182=>(0x0,session_1['getTasksDir'])(this,_0x2d9182),this['getSessionDir']=_0x312e4d=>(0x0,session_1[_0x874c98(0x1fc)])(this,_0x312e4d),this['getSessionId']=session_1[_0x874c98(0x169)],this[_0x874c98(0x142)]=_0x8bb070=>(0x0,session_1[_0x874c98(0x142)])(this,_0x8bb070),this[_0x874c98(0x16a)]=(_0x326f6c,_0x48d223)=>(0x0,session_1[_0x874c98(0x16a)])(this,_0x326f6c,_0x48d223),this['findActiveSession']=_0x429f4f=>(0x0,session_1[_0x874c98(0xf1)])(this,_0x429f4f),this['findHistorySession']=(_0xc86e2e,_0x73f332)=>(0x0,session_1[_0x874c98(0x219)])(this,_0xc86e2e,_0x73f332),this[_0x874c98(0x1b4)]=_0x384619=>(0x0,session_1[_0x874c98(0x1b4)])(this,_0x384619),this[_0x874c98(0x16d)]=(_0x400e63,_0x1cb8e2)=>(0x0,session_1[_0x874c98(0x16d)])(this,_0x400e63,_0x1cb8e2),this[_0x874c98(0x193)]=session_1[_0x874c98(0x193)],this[_0x874c98(0xd5)]=_0x1f50c3=>(0x0,session_1[_0x874c98(0xd5)])(this,_0x1f50c3),this[_0x874c98(0x105)]=_0x23524f=>(0x0,session_1[_0x874c98(0x105)])(this,_0x23524f),this[_0x874c98(0x13f)]=()=>(0x0,session_1[_0x874c98(0x13f)])(this),this[_0x874c98(0x172)]=(_0x56b9c9,_0x4c2756)=>(0x0,session_1['endSession'])(this,_0x56b9c9,_0x4c2756),this['switchToSession']=(_0x1c90c1,_0x1a1e29,_0x3f48ab,_0x47baef,_0x17469c)=>(0x0,session_1[_0x874c98(0x1b9)])(this,_0x1c90c1,_0x1a1e29,_0x3f48ab,_0x47baef,_0x17469c),this[_0x874c98(0x20b)]=_0x266c35=>(0x0,session_1[_0x874c98(0x20b)])(this,_0x266c35),this[_0x874c98(0x11c)]=_0x262f0c=>(0x0,session_1['handleSessionMessage'])(this,_0x262f0c),this['cleanCache']=(_0x16fa62,_0xfb6016=!![])=>(0x0,session_1[_0x874c98(0xe2)])(this,_0x16fa62,_0xfb6016),this[_0x874c98(0x17b)]=()=>(0x0,task_1[_0x874c98(0x17b)])(this),this[_0x874c98(0x1dd)]=(_0x47ab98,_0xed19dc)=>(0x0,task_1[_0x874c98(0x1dd)])(this,_0x47ab98,_0xed19dc),this[_0x874c98(0x148)]=()=>(0x0,task_1[_0x874c98(0x148)])(this),this[_0x874c98(0x1ad)]=()=>(0x0,task_1[_0x874c98(0x1ad)])(this),this[_0x874c98(0x20e)]=_0x4a05c2=>(0x0,task_1[_0x874c98(0x20e)])(this,_0x4a05c2),this['handleTask']=()=>(0x0,task_1['handleTask'])(this),this[_0x874c98(0x14e)]=()=>(0x0,task_1['runTaskHandlerLoop'])(this),this[_0x874c98(0x15f)]=_0x5dcd79=>(0x0,task_1[_0x874c98(0x15f)])(this,_0x5dcd79),this[_0x874c98(0x151)]=_0x3cf962,this['config']=(0x0,session_1[_0x874c98(0x102)])(this);try{this[_0x874c98(0x10d)]=new utils_ok_1['DingStreamClient']({'clientId':_0x3cf962,'clientSecret':this['config'][_0x874c98(0x114)],'keepAlive':!![],'debug':this['config']['debug']??![]});}catch(_0x405ab7){console[_0x874c98(0x159)](_0x874c98(0x1a6),_0x405ab7),process[_0x874c98(0x149)](0x1);}this['cronEngine']=new cron_1[(_0x874c98(0xc4))](this);}async[a2_0x14d974(0x141)](_0x2694b8,_0x231ae6,_0x34383f){const _0x4641d8=a2_0x14d974;if(!this[_0x4641d8(0x1a5)](_0x34383f))return await this[_0x4641d8(0x1ca)]({'conversationId':_0x2694b8,'sessionWebhook':_0x231ae6,'content':_0x4641d8(0x184),'msgType':_0x4641d8(0x107)}),![];return!![];}async[a2_0x14d974(0xdb)](_0x5d41a5,_0x3fd229,_0x168301,_0x2f756e){const _0x3a5e5d=a2_0x14d974;if(this['isOwner'](_0x168301))return!![];if(_0x2f756e?.['conversationType']==='1')return!![];return await this[_0x3a5e5d(0x1ca)]({'conversationId':_0x5d41a5,'sessionWebhook':_0x3fd229,'content':'❌\x20只有机器人\x20owner\x20才能执行此操作','msgType':_0x3a5e5d(0x107)}),![];}async[a2_0x14d974(0x160)](_0x4600a4,_0x4e14cc){const _0x5d8d3d=a2_0x14d974,{conversationId:_0x5cf7d0,sessionWebhook:_0x16f8ef,senderStaffId:_0xe6b131,senderNick:_0xf8bf89,conversationConfig:_0x5f0c7a}=_0x4e14cc;switch(_0x4600a4[_0x5d8d3d(0x1f9)]){case _0x5d8d3d(0x108):{const _0x33e286=await this[_0x5d8d3d(0xc6)](_0x5cf7d0,_0x16f8ef,_0xe6b131,_0xf8bf89,_0x5f0c7a,!![]),_0x12bab0=this['cronEngine'][_0x5d8d3d(0x110)](_0x5cf7d0);_0x33e286[_0x5d8d3d(0x106)]&&(this[_0x5d8d3d(0x193)](_0x33e286['sessionDir'],_0x5d8d3d(0x207),'/cron\x20list'),this[_0x5d8d3d(0x193)](_0x33e286[_0x5d8d3d(0x106)],'assistant',_0x5d8d3d(0x1c5)+_0x12bab0[_0x5d8d3d(0x206)]+'\x20个定时任务'));await this['sendDingMessage']({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':(0x0,cron_1['formatCronJobList'])(_0x12bab0),'msgType':_0x5d8d3d(0x107)});return;}case _0x5d8d3d(0x1ef):{const _0x20366e=this[_0x5d8d3d(0xe7)][_0x5d8d3d(0x201)](_0x4600a4['id']),_0x2ef058=await this['getOrCreateLogSession'](_0x5cf7d0,_0x16f8ef,_0xe6b131,_0xf8bf89,_0x5f0c7a);_0x2ef058['sessionDir']&&(this['appendSessionLog'](_0x2ef058[_0x5d8d3d(0x106)],_0x5d8d3d(0x207),'/cron\x20delete\x20'+_0x4600a4['id']),this[_0x5d8d3d(0x193)](_0x2ef058[_0x5d8d3d(0x106)],_0x5d8d3d(0x1b8),_0x20366e?'删除定时任务\x20'+_0x4600a4['id']:'未找到定时任务:\x20'+_0x4600a4['id']));await this['sendDingMessage']({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':_0x20366e?_0x5d8d3d(0x132)+_0x4600a4['id']+_0x5d8d3d(0xda):'❌\x20未找到定时任务:\x20'+_0x4600a4['id'],'msgType':_0x5d8d3d(0x107)});return;}case _0x5d8d3d(0xf2):{const _0x2248aa=this[_0x5d8d3d(0xe7)][_0x5d8d3d(0x17c)](_0x4600a4['id'],![]),_0x3d196a=await this['getOrCreateLogSession'](_0x5cf7d0,_0x16f8ef,_0xe6b131,_0xf8bf89,_0x5f0c7a);_0x3d196a['sessionDir']&&(this[_0x5d8d3d(0x193)](_0x3d196a[_0x5d8d3d(0x106)],_0x5d8d3d(0x207),'/cron\x20pause\x20'+_0x4600a4['id']),this[_0x5d8d3d(0x193)](_0x3d196a[_0x5d8d3d(0x106)],_0x5d8d3d(0x1b8),_0x2248aa?_0x5d8d3d(0x200)+_0x4600a4['id']:_0x5d8d3d(0xbf)+_0x4600a4['id']));await this[_0x5d8d3d(0x1ca)]({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':_0x2248aa?_0x5d8d3d(0x1f5)+_0x4600a4['id']+_0x5d8d3d(0x1ac):_0x5d8d3d(0x12b)+_0x4600a4['id'],'msgType':'markdown'});return;}case _0x5d8d3d(0xbb):{const _0x58c9e2=this['cronEngine']['toggleJob'](_0x4600a4['id'],!![]),_0x443e79=await this[_0x5d8d3d(0xc6)](_0x5cf7d0,_0x16f8ef,_0xe6b131,_0xf8bf89,_0x5f0c7a);_0x443e79[_0x5d8d3d(0x106)]&&(this[_0x5d8d3d(0x193)](_0x443e79[_0x5d8d3d(0x106)],'user',_0x5d8d3d(0x126)+_0x4600a4['id']),this['appendSessionLog'](_0x443e79[_0x5d8d3d(0x106)],_0x5d8d3d(0x1b8),_0x58c9e2?_0x5d8d3d(0x1ce)+_0x4600a4['id']:_0x5d8d3d(0xbf)+_0x4600a4['id']));await this[_0x5d8d3d(0x1ca)]({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':_0x58c9e2?_0x5d8d3d(0xcf)+_0x4600a4['id']+_0x5d8d3d(0x173):_0x5d8d3d(0x12b)+_0x4600a4['id'],'msgType':'markdown'});return;}case _0x5d8d3d(0xd4):{if(!(0x0,cron_1[_0x5d8d3d(0x1d1)])(_0x4600a4['cronExpression'])){await this[_0x5d8d3d(0x1ca)]({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':_0x5d8d3d(0x128)+_0x4600a4[_0x5d8d3d(0xcb)]+_0x5d8d3d(0x209),'msgType':_0x5d8d3d(0x107)});return;}if(!this[_0x5d8d3d(0xed)](_0x4e14cc['conversationConfig'])){await this['sendCronNoNotifyError'](_0x5cf7d0,_0x16f8ef);return;}const _0x9053c=this[_0x5d8d3d(0xe7)][_0x5d8d3d(0x10c)]({'conversationId':_0x5cf7d0,'cronExpression':_0x4600a4[_0x5d8d3d(0xcb)],'description':this['sanitizeLogContent'](_0x4600a4[_0x5d8d3d(0x12e)][_0x5d8d3d(0x117)](0x0,0x32)),'prompt':_0x4600a4[_0x5d8d3d(0x12e)],'senderStaffId':_0xe6b131,'senderNick':_0xf8bf89}),_0x9d3515=await this[_0x5d8d3d(0xc6)](_0x5cf7d0,_0x16f8ef,_0xe6b131,_0xf8bf89,_0x5f0c7a);_0x9d3515[_0x5d8d3d(0x106)]&&(this[_0x5d8d3d(0x193)](_0x9d3515[_0x5d8d3d(0x106)],_0x5d8d3d(0x207),'/cron\x20'+_0x4600a4[_0x5d8d3d(0xcb)]+'\x20'+this['sanitizeLogContent'](_0x4600a4[_0x5d8d3d(0x12e)])),this[_0x5d8d3d(0x193)](_0x9d3515[_0x5d8d3d(0x106)],_0x5d8d3d(0x1b8),'创建定时任务:\x20'+_0x9053c['id']+'\x20['+_0x9053c[_0x5d8d3d(0xcb)]+']\x20'+_0x9053c[_0x5d8d3d(0x1f6)]));await this[_0x5d8d3d(0x1ca)]({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':(0x0,cron_1[_0x5d8d3d(0x11e)])(_0x9053c),'msgType':'markdown'});return;}case _0x5d8d3d(0x1f0):{if(!this['hasNotifyCapability'](_0x4e14cc[_0x5d8d3d(0x217)])){await this['sendCronNoNotifyError'](_0x5cf7d0,_0x16f8ef);return;}await this['sendDingMessage']({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':_0x5d8d3d(0x205)});const _0x3c7a12=await this['cronEngine'][_0x5d8d3d(0x12c)](_0x5cf7d0,_0x4600a4[_0x5d8d3d(0x152)],_0xe6b131,_0xf8bf89),_0x1cb36f=await this[_0x5d8d3d(0xc6)](_0x5cf7d0,_0x16f8ef,_0xe6b131,_0xf8bf89,_0x5f0c7a);_0x3c7a12[_0x5d8d3d(0x158)]?(_0x1cb36f[_0x5d8d3d(0x106)]&&(this[_0x5d8d3d(0x193)](_0x1cb36f[_0x5d8d3d(0x106)],'user',_0x5d8d3d(0xe0)+this[_0x5d8d3d(0xdf)](_0x4600a4[_0x5d8d3d(0x152)])),this[_0x5d8d3d(0x193)](_0x1cb36f[_0x5d8d3d(0x106)],_0x5d8d3d(0x1b8),_0x5d8d3d(0x1f8)+_0x3c7a12[_0x5d8d3d(0x158)]['id']+'\x20['+_0x3c7a12[_0x5d8d3d(0x158)][_0x5d8d3d(0xcb)]+']\x20'+_0x3c7a12['job'][_0x5d8d3d(0x1f6)])),await this[_0x5d8d3d(0x1ca)]({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':(0x0,cron_1['formatCronJobInfo'])(_0x3c7a12[_0x5d8d3d(0x158)]),'msgType':'markdown'})):(_0x1cb36f[_0x5d8d3d(0x106)]&&(this[_0x5d8d3d(0x193)](_0x1cb36f[_0x5d8d3d(0x106)],_0x5d8d3d(0x207),_0x5d8d3d(0xe0)+this[_0x5d8d3d(0xdf)](_0x4600a4['input'])),this[_0x5d8d3d(0x193)](_0x1cb36f['sessionDir'],_0x5d8d3d(0x1b8),_0x5d8d3d(0x16c)+_0x3c7a12[_0x5d8d3d(0x159)])),await this['sendDingMessage']({'conversationId':_0x5cf7d0,'sessionWebhook':_0x16f8ef,'content':'❌\x20定时任务分析失败:\x20'+_0x3c7a12[_0x5d8d3d(0x159)]+_0x5d8d3d(0xdd),'msgType':_0x5d8d3d(0x107)}));return;}}}[a2_0x14d974(0xdf)](_0x5b791a){const _0x23666d=a2_0x14d974;return _0x5b791a[_0x23666d(0xe5)](/\n/g,'\x5cn')[_0x23666d(0xe5)](/\r/g,'\x5cr');}[a2_0x14d974(0x1c0)](_0x273832){const _0x24a4e4=a2_0x14d974,_0x314433=_0x273832[_0x24a4e4(0xe5)](/\r\n/g,'\x0a'),_0x7d30a1=0x1f40;if(_0x314433[_0x24a4e4(0x206)]>_0x7d30a1)return _0x314433[_0x24a4e4(0x117)](0x0,_0x7d30a1)+_0x24a4e4(0x1d9);return _0x314433;}[a2_0x14d974(0x1cd)](_0x4bffee,_0x1c3b92=0x64){const _0x5957f9=a2_0x14d974,_0x5de864=_0x4bffee['replace'](/\n/g,'\x20')[_0x5957f9(0x202)]();return _0x5de864[_0x5957f9(0x206)]>_0x1c3b92?_0x5de864[_0x5957f9(0xfe)](0x0,_0x1c3b92)+_0x5957f9(0x124):_0x5de864;}async[a2_0x14d974(0xc6)](_0x788b67,_0x1f87ad,_0x971d5b,_0x43ab7d,_0x499649,_0x270a85=![]){const _0x579054=a2_0x14d974,_0xd3323c=this[_0x579054(0xf1)](_0x788b67);if(_0xd3323c){const _0x279861=this[_0x579054(0x1fc)](_0xd3323c[_0x579054(0x1a2)]['session']);return{'sessionDir':_0x279861,'isNew':![]};}if(_0x270a85)return{'sessionDir':null,'isNew':![]};const _0x9ace19=Date[_0x579054(0xea)](),_0x34c815={'conversationId':_0x788b67,'sessionWebhook':_0x1f87ad,'startTime':_0x9ace19,'startTimeStr':utils_ok_1[_0x579054(0x14a)]['mm'](_0x9ace19)[_0x579054(0x1c1)]('YYYY-MM-DD-HH-mm-ss'),'startStaffId':_0x971d5b,'startNickName':_0x579054(0xf9)+_0x43ab7d},_0x373d5b=this[_0x579054(0x1fc)](_0x34c815);return fs_1[_0x579054(0x15c)][_0x579054(0x1dc)](_0x373d5b,{'recursive':!![]}),fs_1[_0x579054(0x15c)]['writeFileSync'](_0x373d5b+_0x579054(0x1fe),JSON[_0x579054(0x163)](_0x34c815,null,0x2),_0x579054(0x203)),fs_1[_0x579054(0x15c)]['appendFileSync'](_0x373d5b+'/session.log','['+(0x0,session_1['timestamp'])()+_0x579054(0x127),_0x579054(0x203)),{'sessionDir':_0x373d5b,'isNew':!![]};}['hasNotifyCapability'](_0x2b7fb5){const _0x57ecc9=a2_0x14d974;return!!(_0x2b7fb5[_0x57ecc9(0x1cb)]||this[_0x57ecc9(0xfb)][_0x57ecc9(0x215)]);}async[a2_0x14d974(0x1ea)](_0xb95715,_0x2e7d94){const _0x3f9c39=a2_0x14d974;await this[_0x3f9c39(0x1ca)]({'conversationId':_0xb95715,'sessionWebhook':_0x2e7d94,'content':_0x3f9c39(0xe1),'msgType':_0x3f9c39(0x107)});}[a2_0x14d974(0x18a)](_0x57e14a,_0x35d3b9){const _0x3df5b4=a2_0x14d974,_0x1c3291=this['getConversationDir'](_0x57e14a);if(_0x35d3b9[_0x3df5b4(0x212)]('/'))return{'absolutePath':'','error':'❌\x20路径不能使用绝对路径(不能以\x20/\x20开头)'};const _0x4e9c56=path_1[_0x3df5b4(0x15c)]['resolve'](_0x1c3291,_0x35d3b9);if(!_0x4e9c56[_0x3df5b4(0x212)](_0x1c3291))return{'absolutePath':'','error':'❌\x20路径超出工作目录范围'};return{'absolutePath':_0x4e9c56};}async[a2_0x14d974(0x197)](_0x37871d,_0x5415c2,_0xafffcb){const _0x4735d5=a2_0x14d974,{absolutePath:_0x310a98,error:_0x53904d}=this[_0x4735d5(0x18a)](_0x37871d,_0xafffcb);if(_0x53904d){await this['sendDingMessage']({'conversationId':_0x37871d,'sessionWebhook':_0x5415c2,'content':_0x53904d,'msgType':'markdown'});return;}try{const _0x492cc3=fs_1[_0x4735d5(0x15c)]['statSync'](_0x310a98);_0x492cc3[_0x4735d5(0x1aa)]()?await this[_0x4735d5(0x1ca)]({'conversationId':_0x37871d,'sessionWebhook':_0x5415c2,'content':_0x4735d5(0xfd)+_0xafffcb+'`','msgType':_0x4735d5(0x107)}):await this[_0x4735d5(0x1ca)]({'conversationId':_0x37871d,'sessionWebhook':_0x5415c2,'content':_0x4735d5(0x1ae)+_0xafffcb+'`','msgType':_0x4735d5(0x107)});return;}catch{}try{fs_1[_0x4735d5(0x15c)][_0x4735d5(0x1dc)](_0x310a98,{'recursive':!![]}),await this[_0x4735d5(0x1ca)]({'conversationId':_0x37871d,'sessionWebhook':_0x5415c2,'content':_0x4735d5(0xd8)+_0xafffcb+'`','msgType':'markdown'});}catch(_0x4f5d7e){await this[_0x4735d5(0x1ca)]({'conversationId':_0x37871d,'sessionWebhook':_0x5415c2,'content':_0x4735d5(0xe9)+_0xafffcb+_0x4735d5(0x143)+(_0x4f5d7e instanceof Error?_0x4f5d7e[_0x4735d5(0x1e9)]:String(_0x4f5d7e)),'msgType':'markdown'});}}async[a2_0x14d974(0x166)](_0x4e133b,_0x34653e,_0x4c95c1){const _0x2a3cdb=a2_0x14d974,{absolutePath:_0x3a8665,error:_0x2d2162}=this['resolveAndValidatePath'](_0x4e133b,_0x4c95c1);if(_0x2d2162){await this['sendDingMessage']({'conversationId':_0x4e133b,'sessionWebhook':_0x34653e,'content':_0x2d2162,'msgType':_0x2a3cdb(0x107)});return;}let _0xb0af84;try{_0xb0af84=fs_1[_0x2a3cdb(0x15c)]['statSync'](_0x3a8665);}catch{await this[_0x2a3cdb(0x1ca)]({'conversationId':_0x4e133b,'sessionWebhook':_0x34653e,'content':'❌\x20路径不存在:\x20`'+_0x4c95c1+'`','msgType':_0x2a3cdb(0x107)});return;}const _0x1fa7d0=_0xb0af84[_0x2a3cdb(0x1aa)]();try{_0x1fa7d0?fs_1[_0x2a3cdb(0x15c)][_0x2a3cdb(0x1d4)](_0x3a8665,{'recursive':!![],'force':!![]}):fs_1[_0x2a3cdb(0x15c)][_0x2a3cdb(0xe4)](_0x3a8665),await this['sendDingMessage']({'conversationId':_0x4e133b,'sessionWebhook':_0x34653e,'content':_0x2a3cdb(0x180)+(_0x1fa7d0?'目录':'文件')+':\x20`'+_0x4c95c1+'`','msgType':_0x2a3cdb(0x107)});}catch(_0xaa5cfb){await this[_0x2a3cdb(0x1ca)]({'conversationId':_0x4e133b,'sessionWebhook':_0x34653e,'content':_0x2a3cdb(0x129)+_0x4c95c1+_0x2a3cdb(0x143)+(_0xaa5cfb instanceof Error?_0xaa5cfb[_0x2a3cdb(0x1e9)]:String(_0xaa5cfb)),'msgType':_0x2a3cdb(0x107)});}}async[a2_0x14d974(0x17f)](_0x9cdf15,_0x5ee30d,_0xccec8f){const _0x8e9b9=a2_0x14d974,{absolutePath:_0x50011e,error:_0x46e130}=this[_0x8e9b9(0x18a)](_0x9cdf15,_0xccec8f);if(_0x46e130){await this[_0x8e9b9(0x1ca)]({'conversationId':_0x9cdf15,'sessionWebhook':_0x5ee30d,'content':_0x46e130,'msgType':'markdown'});return;}try{const _0x2ee6ac=fs_1['default'][_0x8e9b9(0x195)](_0x50011e);_0x2ee6ac['isFile']()?await this[_0x8e9b9(0x1ca)]({'conversationId':_0x9cdf15,'sessionWebhook':_0x5ee30d,'content':'⚠️\x20文件已存在:\x20`'+_0xccec8f+_0x8e9b9(0x20d)+utils_ok_1[_0x8e9b9(0x14a)]['mm'](_0x2ee6ac['mtime'])['format'](_0x8e9b9(0x10a)),'msgType':_0x8e9b9(0x107)}):await this[_0x8e9b9(0x1ca)]({'conversationId':_0x9cdf15,'sessionWebhook':_0x5ee30d,'content':_0x8e9b9(0x156)+_0xccec8f+'`','msgType':_0x8e9b9(0x107)});return;}catch{}try{const _0x4db11c=path_1[_0x8e9b9(0x15c)]['dirname'](_0x50011e);fs_1[_0x8e9b9(0x15c)]['mkdirSync'](_0x4db11c,{'recursive':!![]}),fs_1[_0x8e9b9(0x15c)][_0x8e9b9(0x1db)](_0x50011e,'',_0x8e9b9(0x203)),await this[_0x8e9b9(0x1ca)]({'conversationId':_0x9cdf15,'sessionWebhook':_0x5ee30d,'content':_0x8e9b9(0xd6)+_0xccec8f+'`','msgType':_0x8e9b9(0x107)});}catch(_0x25a57d){await this[_0x8e9b9(0x1ca)]({'conversationId':_0x9cdf15,'sessionWebhook':_0x5ee30d,'content':'❌\x20文件创建失败:\x20`'+_0xccec8f+'`\x0a原因:\x20'+(_0x25a57d instanceof Error?_0x25a57d['message']:String(_0x25a57d)),'msgType':_0x8e9b9(0x107)});}}async['botMsgGetCallback'](_0x172dce){const _0x2c959c=a2_0x14d974;this[_0x2c959c(0x10d)][_0x2c959c(0x1df)](_0x172dce['headers'][_0x2c959c(0xcd)],'');const _0x87096e=JSON[_0x2c959c(0x1e2)](_0x172dce[_0x2c959c(0x136)]),{senderNick:_0x1f50b0,senderStaffId:_0x2feb3d,conversationId:_0x27df03,conversationTitle:_0x51594d,sessionWebhook:_0x11e179,msgtype:_0x89fd99,conversationType:_0x379be9}=_0x87096e,_0x57d3f9=_0x87096e[_0x2c959c(0x187)]?.[_0x2c959c(0x1d5)]?.[_0x2c959c(0x202)]()??'';this[_0x2c959c(0x1e3)](_0x2c959c(0xc9)+_0x51594d+'('+_0x27df03+'),\x20发送者='+_0x1f50b0+'('+_0x2feb3d+'),\x20类型='+_0x89fd99+',\x20内容='+_0x57d3f9[_0x2c959c(0x117)](0x0,0x32));if(!this[_0x2c959c(0x165)](_0x2feb3d,_0x27df03)){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'atUserId':_0x2feb3d,'content':_0x2c959c(0x1cc)});return;}const _0x5dca14=this[_0x2c959c(0x1e8)](_0x27df03);let _0xc2e69e;if(_0x89fd99===_0x2c959c(0x11d)&&_0x87096e[_0x2c959c(0xc0)]){const _0x216353=this[_0x2c959c(0x144)](_0x27df03),_0x91e903=_0x5dca14?.[_0x2c959c(0x1d0)]!==![],_0xb8b046=await(0x0,image_1[_0x2c959c(0xf6)])(this,_0x87096e[_0x2c959c(0xc0)],_0x87096e['robotCode'],_0x216353,_0x91e903,_0x57d3f9||undefined);if(!_0xb8b046){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'atUserId':_0x2feb3d,'content':_0x2c959c(0x1d3)});return;}_0xc2e69e=_0xb8b046;}else{if(_0x89fd99===_0x2c959c(0xbc)&&_0x87096e[_0x2c959c(0x1d5)]?.['richText']){const _0x224ef3=this[_0x2c959c(0x144)](_0x27df03),_0x5d0e4d=_0x5dca14?.[_0x2c959c(0x1d0)]!==![];_0xc2e69e=await(0x0,image_1[_0x2c959c(0x1a7)])(this,_0x87096e[_0x2c959c(0x1d5)][_0x2c959c(0xbc)],_0x87096e[_0x2c959c(0x21b)],_0x224ef3,_0x5d0e4d);}else{_0xc2e69e=_0x57d3f9;if(!_0xc2e69e)return;}}if(!_0xc2e69e['startsWith']('/')&&_0x89fd99===_0x2c959c(0x187)){const _0x31f202=(0x0,quote_1[_0x2c959c(0x198)])(_0x87096e);if(_0x31f202){this[_0x2c959c(0x1e3)](_0x2c959c(0xd0)+_0x31f202['quoteMessageId']);if(_0x31f202['quoteMessageId']&&!_0x31f202['quoteText']){const _0x4c3d50=await(0x0,messaging_1['fetchQuotedMessage'])(this,_0x31f202['quoteMessageId']);if(_0x4c3d50)_0x31f202[_0x2c959c(0x11a)]=_0x4c3d50;}_0x31f202['quoteText']&&(_0xc2e69e=(0x0,quote_1[_0x2c959c(0x14b)])(_0xc2e69e,_0x31f202));}}const _0x461b33=(0x0,commands_1[_0x2c959c(0xd2)])(_0xc2e69e);if(_0x461b33!==null){if(_0x461b33[_0x2c959c(0xd3)]&&_0x5dca14?.['conversationType']!=='1'&&!this[_0x2c959c(0x1a5)](_0x2feb3d)){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x145),'msgType':_0x2c959c(0x107)});return;}if(!await this[_0x2c959c(0xdb)](_0x27df03,_0x11e179,_0x2feb3d,_0x5dca14))return;const _0x5e76ad=_0x461b33[_0x2c959c(0xd3)]||_0x27df03,_0x5bed7f=_0x5e76ad!==_0x27df03,_0x5499b0=_0x5bed7f?this[_0x2c959c(0xfb)][_0x2c959c(0x183)][_0x2c959c(0x199)](_0x9c8da4=>_0x9c8da4[_0x2c959c(0xd3)]===_0x5e76ad):_0x5dca14,_0x28cf45=!!(_0x461b33[_0x2c959c(0x1cb)]||_0x461b33[_0x2c959c(0x17d)]||_0x461b33['whiteUserList']&&_0x461b33['whiteUserList']['length']>0x0||_0x461b33['conversationTitle']||_0x461b33[_0x2c959c(0x1d7)]!==undefined||_0x461b33['receiveReply']!==undefined||_0x461b33[_0x2c959c(0x1fd)]!==undefined);if(_0x5499b0&&_0x28cf45){if(_0x461b33[_0x2c959c(0x11b)])_0x5499b0[_0x2c959c(0x11b)]=_0x461b33['conversationTitle'];if(_0x379be9&&!_0x5bed7f)_0x5499b0[_0x2c959c(0x213)]=_0x379be9;if(_0x461b33[_0x2c959c(0x1cb)])_0x5499b0[_0x2c959c(0x1cb)]=_0x461b33[_0x2c959c(0x1cb)];if(_0x461b33['linkConversationId'])_0x5499b0[_0x2c959c(0x17d)]=_0x461b33[_0x2c959c(0x17d)];if(_0x461b33[_0x2c959c(0x1d7)]!==undefined)_0x5499b0[_0x2c959c(0x1d7)]=_0x461b33[_0x2c959c(0x1d7)];if(_0x461b33[_0x2c959c(0x185)]!==undefined)_0x5499b0[_0x2c959c(0x185)]=_0x461b33[_0x2c959c(0x185)];if(_0x461b33[_0x2c959c(0x1fd)]!==undefined)_0x5499b0['preBash']=_0x461b33[_0x2c959c(0x1fd)];if(_0x461b33[_0x2c959c(0x19e)]&&_0x461b33[_0x2c959c(0x19e)][_0x2c959c(0x206)]>0x0){_0x5499b0[_0x2c959c(0x19e)]=_0x461b33[_0x2c959c(0x19e)];for(const _0x1f419d of _0x461b33[_0x2c959c(0x19e)]){(0x0,session_1[_0x2c959c(0x1be)])(_0x1f419d)&&await(0x0,session_1[_0x2c959c(0x13b)])(this,_0x1f419d);}}(0x0,api_key_manager_1[_0x2c959c(0x1e4)])(this),console[_0x2c959c(0xff)]('['+(0x0,session_1[_0x2c959c(0x1e1)])()+']\x20刷新群配置:\x20'+(_0x5499b0[_0x2c959c(0x11b)]||_0x5e76ad)+'('+_0x5e76ad+')');}else{if(!_0x5499b0){const _0x3319d4={'conversationId':_0x5e76ad,'conversationType':_0x5bed7f?'1':_0x379be9,'conversationTitle':_0x461b33[_0x2c959c(0x11b)]||(_0x5bed7f?'':_0x51594d)};if(_0x461b33['dingToken'])_0x3319d4[_0x2c959c(0x1cb)]=_0x461b33[_0x2c959c(0x1cb)];if(_0x461b33[_0x2c959c(0x17d)])_0x3319d4[_0x2c959c(0x17d)]=_0x461b33[_0x2c959c(0x17d)];if(_0x461b33[_0x2c959c(0x1d7)]!==undefined)_0x3319d4[_0x2c959c(0x1d7)]=_0x461b33[_0x2c959c(0x1d7)];if(_0x461b33['receiveReply']!==undefined)_0x3319d4[_0x2c959c(0x185)]=_0x461b33[_0x2c959c(0x185)];if(_0x461b33[_0x2c959c(0x1fd)]!==undefined)_0x3319d4[_0x2c959c(0x1fd)]=_0x461b33[_0x2c959c(0x1fd)];if(_0x461b33[_0x2c959c(0x19e)]&&_0x461b33[_0x2c959c(0x19e)][_0x2c959c(0x206)]>0x0){_0x3319d4[_0x2c959c(0x19e)]=_0x461b33[_0x2c959c(0x19e)];for(const _0x255474 of _0x461b33[_0x2c959c(0x19e)]){(0x0,session_1[_0x2c959c(0x1be)])(_0x255474)&&await(0x0,session_1[_0x2c959c(0x13b)])(this,_0x255474);}}this[_0x2c959c(0xfb)]['conversations'][_0x2c959c(0x1a0)](_0x3319d4),(0x0,api_key_manager_1[_0x2c959c(0x1e4)])(this),console[_0x2c959c(0xff)]('['+(0x0,session_1[_0x2c959c(0x1e1)])()+_0x2c959c(0x19b)+(_0x3319d4['conversationTitle']||_0x5e76ad)+'('+_0x5e76ad+_0x2c959c(0xe3)+(_0x3319d4['conversationType']||'-'));}}const _0x44c819=this[_0x2c959c(0x144)](_0x5e76ad);!fs_1[_0x2c959c(0x15c)][_0x2c959c(0x1ec)](_0x44c819)&&(fs_1[_0x2c959c(0x15c)][_0x2c959c(0x1dc)](_0x44c819,{'recursive':!![]}),console['log']('['+(0x0,session_1[_0x2c959c(0x1e1)])()+_0x2c959c(0x1a3)+_0x44c819));const _0x450e60=_0x5499b0||this[_0x2c959c(0x1e8)](_0x5e76ad),_0x482191=[_0x5499b0?_0x2c959c(0xeb):'✅\x20群已注册',_0x2c959c(0x1d6)+(_0x450e60?.[_0x2c959c(0x11b)]||_0x5e76ad),'-\x20**群ID:**\x20'+_0x5e76ad];if(_0x450e60?.[_0x2c959c(0x213)])_0x482191[_0x2c959c(0x1a0)](_0x2c959c(0x113)+(_0x450e60['conversationType']==='1'?'单聊':_0x450e60[_0x2c959c(0x213)]==='2'?'群聊':_0x450e60['conversationType']));if(_0x450e60?.[_0x2c959c(0x1cb)])_0x482191[_0x2c959c(0x1a0)](_0x2c959c(0x208)+_0x450e60[_0x2c959c(0x1cb)][_0x2c959c(0x117)](0x0,0x8)+'...');else _0x482191['push']('-\x20**dingToken:**\x20(未指定,\x20使用\x20defaultDingToken)');if(_0x450e60?.[_0x2c959c(0x17d)])_0x482191[_0x2c959c(0x1a0)](_0x2c959c(0x12a)+_0x450e60[_0x2c959c(0x17d)]);if(_0x450e60?.[_0x2c959c(0x1d7)]===![])_0x482191[_0x2c959c(0x1a0)](_0x2c959c(0xcc));if(_0x450e60?.[_0x2c959c(0x185)]===![])_0x482191[_0x2c959c(0x1a0)](_0x2c959c(0x10e));if(_0x450e60?.[_0x2c959c(0x19e)]?.[_0x2c959c(0x206)]){const _0x4e4b64=_0x450e60[_0x2c959c(0x19e)][_0x2c959c(0x1c9)](_0x23af90=>{if((0x0,session_1['isMobile'])(_0x23af90))return _0x23af90;return(0x0,session_1['userIdToPhone'])(this,_0x23af90)||_0x23af90;})[_0x2c959c(0x1e7)](',\x20');_0x482191[_0x2c959c(0x1a0)]('-\x20**whiteUserList:**\x20'+_0x4e4b64);}_0x482191[_0x2c959c(0x1a0)](_0x2c959c(0x131)+_0x44c819),_0x482191[_0x2c959c(0x1a0)](_0x2c959c(0x1ff)),await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x482191[_0x2c959c(0x1e7)]('\x0a'),'msgType':_0x2c959c(0x107)});return;}if((0x0,commands_1['parseHelpCommand'])(_0xc2e69e)){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':(0x0,commands_1[_0x2c959c(0x1b7)])(TOOL_VERSION,this['isOwner'](_0x2feb3d)),'msgType':_0x2c959c(0x107)});return;}if((0x0,commands_1[_0x2c959c(0xd7)])(_0xc2e69e)){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x137)+TOOL_VERSION,'msgType':_0x2c959c(0x107)});return;}const _0x10a22f=(0x0,commands_1[_0x2c959c(0x1a8)])(_0xc2e69e);if(_0x10a22f){const _0x5cf1f5=(0x0,commands_1['getCommandByName'])(_0x10a22f);_0x5cf1f5?await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':(0x0,commands_1['formatCommandHelp'])(_0x5cf1f5),'msgType':_0x2c959c(0x107)}):await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x20c)+_0x10a22f+_0x2c959c(0x1c6),'msgType':_0x2c959c(0x107)});return;}if(!_0x5dca14){console['log']('未注册的机器人,群:'+_0x51594d+','+_0x27df03);this[_0x2c959c(0x1a5)](_0x2feb3d)?await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'atUserId':_0x2feb3d,'content':_0x2c959c(0x216),'msgType':_0x2c959c(0x107)}):await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'atUserId':_0x2feb3d,'content':_0x2c959c(0xf3)+_0x27df03+')...'});return;}const _0x9dd00c=(0x0,commands_1[_0x2c959c(0xe6)])(_0xc2e69e);if(_0x9dd00c!==null){if(_0x9dd00c===_0x2c959c(0xe8)&&_0x5dca14?.[_0x2c959c(0x213)]!=='1'&&!this['isOwner'](_0x2feb3d)){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x10b),'msgType':_0x2c959c(0x107)});return;}if(!await this[_0x2c959c(0xdb)](_0x27df03,_0x11e179,_0x2feb3d,_0x5dca14))return;const _0x11a374=_0x9dd00c==='all'?null:_0x27df03,_0x8feb66=this[_0x2c959c(0xe2)](_0x11a374,!![]),_0x1f331e=[];_0x1f331e[_0x2c959c(0x1a0)](_0x2c959c(0x178));if(_0x8feb66['sessionsDeleted']>0x0)_0x1f331e[_0x2c959c(0x1a0)]('-\x20会话目录:\x20'+_0x8feb66[_0x2c959c(0x204)]+'\x20个');if(_0x8feb66[_0x2c959c(0x19d)]>0x0)_0x1f331e['push']('-\x20任务目录:\x20'+_0x8feb66['tasksDeleted']+'\x20个');if(_0x8feb66[_0x2c959c(0x1fa)]>0x0)_0x1f331e[_0x2c959c(0x1a0)](_0x2c959c(0x18f)+_0x8feb66['imagesDeleted']+'\x20个');_0x8feb66[_0x2c959c(0x204)]===0x0&&_0x8feb66[_0x2c959c(0x19d)]===0x0&&_0x8feb66[_0x2c959c(0x1fa)]===0x0&&_0x1f331e['push'](_0x2c959c(0x171));_0x1f331e[_0x2c959c(0x1a0)](_0x2c959c(0x15b));_0x8feb66[_0x2c959c(0x1d2)][_0x2c959c(0x206)]>0x0&&_0x1f331e[_0x2c959c(0x1a0)]('\x0a⚠️\x20错误:\x20'+_0x8feb66[_0x2c959c(0x1d2)][_0x2c959c(0x1e7)](';\x20'));await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x1f331e[_0x2c959c(0x1e7)]('\x0a'),'msgType':_0x2c959c(0x107)});return;}if((0x0,commands_1[_0x2c959c(0xbe)])(_0xc2e69e)){if(!await this['requireOwner'](_0x27df03,_0x11e179,_0x2feb3d))return;if(!this[_0x2c959c(0xfb)][_0x2c959c(0x1f7)]){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'⚠️\x20未配置\x20apiKeyCfg,无需重置','msgType':_0x2c959c(0x107)});return;}(0x0,api_key_manager_1['resetApiKeyCfg'])(this);const _0x259ea4=this[_0x2c959c(0xfb)][_0x2c959c(0x1f7)][_0x2c959c(0x196)][_0x2c959c(0xfa)](_0x3e9b7a=>_0x3e9b7a[_0x2c959c(0x134)])[_0x2c959c(0x206)];await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'✅\x20apiKeyCfg\x20已重置\x0a-\x20有效\x20Key\x20数:\x20'+_0x259ea4+'/'+this[_0x2c959c(0xfb)][_0x2c959c(0x1f7)]['claudeSettings'][_0x2c959c(0x206)]+_0x2c959c(0x13a)+(this['config'][_0x2c959c(0x1f7)][_0x2c959c(0x1c7)]||'-'),'msgType':'markdown'});return;}const _0x5d2aa7=(0x0,commands_1['parseAuthCommand'])(_0xc2e69e);if(_0x5d2aa7){if(!await this[_0x2c959c(0x141)](_0x27df03,_0x11e179,_0x2feb3d))return;const _0x5467aa=_0x5dca14[_0x2c959c(0x19e)];if(_0x5d2aa7['type']===_0x2c959c(0x108)){const _0x18ff26=_0x5467aa&&_0x5467aa[_0x2c959c(0x206)]>0x0?_0x5467aa[_0x2c959c(0x1c9)](_0x17b764=>{const _0x2d1900=_0x2c959c,_0x1d5ebd=(0x0,session_1[_0x2d1900(0x170)])(this,_0x17b764);return'-\x20'+(_0x1d5ebd||_0x17b764);})[_0x2c959c(0x1e7)]('\x0a'):_0x2c959c(0x16f);await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'📋\x20**当前群白名单**\x0a'+_0x18ff26,'msgType':_0x2c959c(0x107)});return;}if(_0x5d2aa7[_0x2c959c(0x1f9)]===_0x2c959c(0x192)){let _0x59f1b8=_0x5d2aa7[_0x2c959c(0xc5)];if((0x0,session_1[_0x2c959c(0x1be)])(_0x5d2aa7['staffId'])){_0x59f1b8=await(0x0,session_1[_0x2c959c(0x13b)])(this,_0x5d2aa7[_0x2c959c(0xc5)]);if(!_0x59f1b8){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x21a)+_0x5d2aa7['staffId'],'msgType':_0x2c959c(0x107)});return;}}const _0x5877d1=_0x5467aa?.[_0x2c959c(0x17a)](_0x51b8fe=>(0x0,session_1[_0x2c959c(0x1bd)])(this,_0x51b8fe)===_0x59f1b8);if(_0x5877d1){const _0x4ad9b7=(0x0,session_1[_0x2c959c(0x170)])(this,_0x59f1b8)||_0x59f1b8;await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x18d)+_0x4ad9b7+'\x20已在当前群白名单中','msgType':_0x2c959c(0x107)});return;}!_0x5dca14[_0x2c959c(0x19e)]&&(_0x5dca14['whiteUserList']=[]);_0x5dca14['whiteUserList'][_0x2c959c(0x1a0)](_0x5d2aa7['staffId']),(0x0,api_key_manager_1[_0x2c959c(0x1e4)])(this);const _0x1b5ac4=_0x5dca14[_0x2c959c(0x19e)][_0x2c959c(0x1c9)](_0x176507=>{const _0x51f1dd=_0x2c959c,_0x45b7d6=(0x0,session_1[_0x51f1dd(0x1bd)])(this,_0x176507);return(0x0,session_1['userIdToPhone'])(this,_0x45b7d6)||_0x176507;}),_0x5bbfee=(0x0,session_1[_0x2c959c(0x1be)])(_0x5d2aa7['staffId'])?_0x5d2aa7['staffId']:(0x0,session_1['userIdToPhone'])(this,_0x5d2aa7[_0x2c959c(0xc5)])||_0x5d2aa7[_0x2c959c(0xc5)];await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x1b1)+_0x5bbfee+_0x2c959c(0x1e6)+_0x1b5ac4['join'](',\x20'),'msgType':_0x2c959c(0x107)});return;}if(_0x5d2aa7['type']===_0x2c959c(0x1d8)){let _0xd7b528=_0x5d2aa7[_0x2c959c(0xc5)];if((0x0,session_1[_0x2c959c(0x1be)])(_0x5d2aa7['staffId'])){_0xd7b528=await(0x0,session_1[_0x2c959c(0x13b)])(this,_0x5d2aa7['staffId']);if(!_0xd7b528){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x21a)+_0x5d2aa7[_0x2c959c(0xc5)],'msgType':_0x2c959c(0x107)});return;}}const _0x4eb44f=_0x5467aa?.['findIndex'](_0x451963=>(0x0,session_1[_0x2c959c(0x1bd)])(this,_0x451963)===_0xd7b528)??-0x1;if(_0x4eb44f<0x0){const _0x5e4daf=(0x0,session_1[_0x2c959c(0x170)])(this,_0xd7b528)||_0xd7b528;await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x18d)+_0x5e4daf+_0x2c959c(0x20a),'msgType':_0x2c959c(0x107)});return;}const _0x2cc79f=_0x5dca14['whiteUserList'][_0x4eb44f];_0x5dca14['whiteUserList'][_0x2c959c(0x1b2)](_0x4eb44f,0x1);_0x5dca14[_0x2c959c(0x19e)][_0x2c959c(0x206)]===0x0&&delete _0x5dca14[_0x2c959c(0x19e)];(0x0,api_key_manager_1[_0x2c959c(0x1e4)])(this);const _0x34d2e8=_0x5dca14[_0x2c959c(0x19e)]?.['length']?_0x5dca14[_0x2c959c(0x19e)]['map'](_0x5951f4=>{const _0x509004=_0x2c959c,_0x28c09c=(0x0,session_1['resolveToUserId'])(this,_0x5951f4);return(0x0,session_1[_0x509004(0x170)])(this,_0x28c09c)||_0x5951f4;})[_0x2c959c(0x1e7)](',\x20'):_0x2c959c(0x1e0),_0x4f8d82=(0x0,session_1['userIdToPhone'])(this,_0xd7b528)||_0x2cc79f;await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x190)+_0x4f8d82+'\x0a当前白名单:\x20'+_0x34d2e8,'msgType':_0x2c959c(0x107)});return;}}const _0x2f4cc5=(0x0,commands_1[_0x2c959c(0x1a1)])(_0xc2e69e);if(_0x2f4cc5!==null){if(!await this[_0x2c959c(0x141)](_0x27df03,_0x11e179,_0x2feb3d))return;const _0x47d915=this[_0x2c959c(0x144)](_0x27df03),{exec:_0x286483}=await Promise[_0x2c959c(0x161)]()[_0x2c959c(0x146)](()=>__importStar(require(_0x2c959c(0xdc)))),_0x432645=process[_0x2c959c(0x1f1)];try{_0x2f4cc5===_0x2c959c(0x14c)?(_0x432645===_0x2c959c(0xc7)?_0x286483('open\x20\x22'+_0x47d915+'\x22'):_0x286483(_0x2c959c(0x1c8)+_0x47d915+'\x22'),await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x1c2)+_0x47d915+_0x2c959c(0x135),'msgType':_0x2c959c(0x107)})):(_0x432645===_0x2c959c(0xc7)?_0x286483(_0x2c959c(0x17e)+_0x47d915+'\x22'):_0x286483(_0x2c959c(0x19c)+_0x47d915+'\x22',{'shell':'cmd.exe'}),await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'💻\x20已在终端中打开:\x0a```\x0a'+_0x47d915+'\x0a```','msgType':_0x2c959c(0x107)}));}catch(_0x3a835c){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x104)+(_0x3a835c instanceof Error?_0x3a835c[_0x2c959c(0x1e9)]:String(_0x3a835c)),'msgType':_0x2c959c(0x107)});}return;}const _0x3cc099=(0x0,commands_1[_0x2c959c(0x16e)])(_0xc2e69e);if(_0x3cc099){await this[_0x2c959c(0x160)](_0x3cc099,{'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'senderStaffId':_0x2feb3d,'senderNick':_0x1f50b0,'conversationConfig':_0x5dca14});return;}if((0x0,commands_1[_0x2c959c(0xf5)])(_0xc2e69e)){const _0x1d049b=this[_0x2c959c(0x144)](_0x27df03);await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'📂\x20当前工作目录:\x0a```\x0a'+_0x1d049b+'\x0a```','msgType':_0x2c959c(0x107)});return;}const _0x58bd1b=(0x0,commands_1[_0x2c959c(0x101)])(_0xc2e69e);if(_0x58bd1b!==null){await this[_0x2c959c(0x197)](_0x27df03,_0x11e179,_0x58bd1b);return;}const _0x163ecc=(0x0,commands_1['parseTouchCommand'])(_0xc2e69e);if(_0x163ecc!==null){await this[_0x2c959c(0x17f)](_0x27df03,_0x11e179,_0x163ecc);return;}const _0x3c9645=(0x0,commands_1[_0x2c959c(0x1b3)])(_0xc2e69e);if(_0x3c9645!==null){await this[_0x2c959c(0x166)](_0x27df03,_0x11e179,_0x3c9645);return;}const _0x4e7c1e=(0x0,commands_1['parseBashCommand'])(_0xc2e69e);if(_0x4e7c1e!==null){const _0x10bef4=this[_0x2c959c(0x144)](_0x27df03),_0x22d124=[];if(this[_0x2c959c(0xfb)][_0x2c959c(0x1fd)])_0x22d124['push'](this[_0x2c959c(0xfb)]['preBash']);if(_0x5dca14?.[_0x2c959c(0x1fd)])_0x22d124[_0x2c959c(0x1a0)](_0x5dca14['preBash']);const _0x17369f=_0x22d124[_0x2c959c(0x206)]>0x0?_0x22d124[_0x2c959c(0x1e7)](_0x2c959c(0x154))+_0x2c959c(0x154)+_0x4e7c1e:_0x4e7c1e,_0x210d90=this;(0x0,child_process_1[_0x2c959c(0x1bb)])(_0x17369f,{'cwd':_0x10bef4,'timeout':0x7530,'maxBuffer':0x400*0x400},async(_0x4febf4,_0x3d3a36,_0x17fd69)=>{const _0x5d85d5=_0x2c959c;try{let _0xe9524;if(_0x4febf4)_0xe9524='❌\x20命令执行失败\x0a```\x0a'+_0x4febf4[_0x5d85d5(0x1e9)]+_0x5d85d5(0x135),_0x17fd69&&(_0xe9524+=_0x5d85d5(0x14d)+_0x210d90[_0x5d85d5(0x1c0)](_0x17fd69)+_0x5d85d5(0x135));else{const _0x1933dd=_0x3d3a36||_0x5d85d5(0x168);_0xe9524=_0x5d85d5(0x111)+_0x210d90[_0x5d85d5(0x1c0)](_0x1933dd)+_0x5d85d5(0x135),_0x17fd69&&(_0xe9524+=_0x5d85d5(0x14d)+_0x210d90[_0x5d85d5(0x1c0)](_0x17fd69)+_0x5d85d5(0x135));}await _0x210d90[_0x5d85d5(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0xe9524,'msgType':_0x5d85d5(0x107)});}catch(_0xaa05e8){console[_0x5d85d5(0x159)]('[bash]\x20发送消息失败:',_0xaa05e8);}});return;}if(/^\/new(?:\s|$)/i['test'](_0xc2e69e)){const _0x587b28=this[_0x2c959c(0xf1)](_0x27df03);_0x587b28&&(console[_0x2c959c(0xff)]('收到新会话命令,结束旧会话:\x20群='+_0x587b28[_0x2c959c(0x1a2)]['session']['conversationId']+_0x2c959c(0xfc)+this[_0x2c959c(0x169)](_0x587b28[_0x2c959c(0x1a2)][_0x2c959c(0x1a2)])),this[_0x2c959c(0x147)](_0x587b28[_0x2c959c(0x1a2)],'新会话命令中断正在执行的\x20Claude\x20进程'),this[_0x2c959c(0x1c3)][_0x2c959c(0x1ef)](_0x587b28[_0x2c959c(0x1ab)]),this[_0x2c959c(0x105)](_0x587b28[_0x2c959c(0x1ab)]));const _0x2dea11=_0xc2e69e['replace'](/^\/new\s*/i,'')[_0x2c959c(0x202)]();_0x2dea11?await this['startNewSession']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'senderStaffId':_0x2feb3d,'senderNick':_0x1f50b0,'message':_0x2dea11,'conversationConfig':_0x5dca14}):await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'atUserId':_0x2feb3d,'content':_0x2c959c(0xee)});return;}const _0x26d605=(0x0,commands_1[_0x2c959c(0x122)])(_0xc2e69e);if(_0x26d605!==null&&_0x5dca14){let _0x544aa6=_0x26d605;if(!_0x544aa6){const _0xefe528=(0x0,session_1[_0x2c959c(0x1b4)])(this,_0x27df03);if(!_0xefe528){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'atUserId':_0x2feb3d,'content':_0x2c959c(0x139),'msgType':'markdown'});return;}_0x544aa6=(0x0,session_1[_0x2c959c(0x169)])(_0xefe528);}await this[_0x2c959c(0x1b9)](_0x27df03,_0x11e179,_0x544aa6,_0x2feb3d,_0x5dca14);return;}const _0x4a0af8=(0x0,commands_1['parseLogCommand'])(_0xc2e69e);if(_0x4a0af8!==null){const _0x147726=this[_0x2c959c(0x16a)](_0x27df03,_0x4a0af8);_0x147726?await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'📋\x20最近\x20'+_0x4a0af8+_0x2c959c(0x150)+_0x147726+_0x2c959c(0x135),'msgType':_0x2c959c(0x107)}):await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x15a)});return;}const _0x401dd9=(0x0,commands_1[_0x2c959c(0x116)])(_0xc2e69e);if(_0x401dd9!==null){const _0x26389c=[],_0x25b2fa=this[_0x2c959c(0x144)](_0x27df03);(_0x401dd9===_0x2c959c(0xe8)||_0x401dd9===_0x2c959c(0x15d))&&(_0x26389c[_0x2c959c(0x1a0)](_0x2c959c(0x18e)+(0x0,commands_1['formatGlobalConfig'])(this[_0x2c959c(0xfb)])),_0x26389c[_0x2c959c(0x1a0)](_0x2c959c(0x1ed)+(0x0,commands_1[_0x2c959c(0x140)])(_0x5dca14,_0x27df03,_0x558781=>(0x0,session_1[_0x2c959c(0x170)])(this,_0x558781),_0x25b2fa)));if(_0x401dd9===_0x2c959c(0xe8)||_0x401dd9==='session'){const _0x5330ed=this['formatSessionInfo'](_0x27df03);_0x5330ed?_0x26389c['push'](_0x2c959c(0x214)+_0x5330ed):_0x26389c[_0x2c959c(0x1a0)](_0x2c959c(0x153));}(_0x401dd9===_0x2c959c(0xe8)||_0x401dd9===_0x2c959c(0x1a9))&&_0x26389c[_0x2c959c(0x1a0)](_0x2c959c(0x1af)+this[_0x2c959c(0x17b)]());await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x26389c[_0x2c959c(0x1e7)]('\x0a\x0a'),'msgType':_0x2c959c(0x107)});return;}const _0x45b15d=(0x0,commands_1[_0x2c959c(0x13c)])(_0xc2e69e);if(_0x45b15d!==null){const {target:_0xbd1c31,depth:_0x67c09}=_0x45b15d,_0x434a24=this[_0x2c959c(0x144)](_0x27df03);let _0x4847cf=_0x434a24,_0x406cb0=_0x2c959c(0x118);if(_0xbd1c31&&_0xbd1c31!==_0x2c959c(0xd1)){if(_0xbd1c31[_0x2c959c(0x212)]('./')||_0xbd1c31[_0x2c959c(0x212)]('../')||_0xbd1c31[_0x2c959c(0x212)]('/')){const _0x1863b5=path_1['default'][_0x2c959c(0x161)](_0x434a24,_0xbd1c31);if(fs_1[_0x2c959c(0x15c)][_0x2c959c(0x1ec)](_0x1863b5)&&fs_1[_0x2c959c(0x15c)]['statSync'](_0x1863b5)[_0x2c959c(0x1aa)]()){if(!_0x1863b5[_0x2c959c(0x212)](_0x434a24)){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0xc8),'msgType':_0x2c959c(0x107)});return;}_0x4847cf=_0x1863b5,_0x406cb0=_0xbd1c31;}else{await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x18b)+_0xbd1c31+'**','msgType':_0x2c959c(0x107)});return;}}else{const _0x5e14e5=(0x0,commands_1[_0x2c959c(0x16b)])(_0x434a24,_0xbd1c31);if(_0x5e14e5)_0x4847cf=_0x5e14e5,_0x406cb0=_0xbd1c31;else{await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'❌\x20未找到名为\x20**'+_0xbd1c31+_0x2c959c(0xf4),'msgType':_0x2c959c(0x107)});return;}}}const _0x449de4=(0x0,commands_1['getDirectoryStructure'])(_0x4847cf,0x0,_0x67c09);await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x1f2)+_0x406cb0+'\x20(展开'+_0x67c09+_0x2c959c(0x1cf)+_0x449de4+'\x0a```','msgType':_0x2c959c(0x107)});return;}const _0x119282=(0x0,task_1['parseTaskCancelCommand'])(_0xc2e69e);if(_0x119282){const _0x856f8a=this[_0x2c959c(0x1dd)](_0x119282,_0x27df03);await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x856f8a,'msgType':_0x2c959c(0x107)});return;}if(_0xc2e69e['startsWith'](_0x2c959c(0x194))){const _0x317a40=_0xc2e69e[_0x2c959c(0x117)](0x6)['trim']();_0x317a40&&(await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'atUserId':_0x2feb3d,'content':_0x2c959c(0x1b0)}),await this[_0x2c959c(0x15f)]({'conversationId':_0x27df03,'prompt':_0x317a40,'senderStaffId':_0x2feb3d,'senderNickName':_0x1f50b0,'sessionWebhook':_0x11e179}));return;}const _0x147b2f=(0x0,commands_1[_0x2c959c(0x191)])(_0xc2e69e);if(_0x147b2f){const _0x57051c=this[_0x2c959c(0xf1)](_0x27df03),_0x7e3cd6=_0x57051c?.[_0x2c959c(0x1a2)][_0x2c959c(0x1ba)]??[];switch(_0x147b2f[_0x2c959c(0x1f9)]){case _0x2c959c(0x108):{if(_0x7e3cd6[_0x2c959c(0x206)]===0x0)await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x162),'msgType':_0x2c959c(0x107)});else{const _0x5c533f=_0x7e3cd6['map']((_0x50c6be,_0x97177b)=>_0x97177b+0x1+'.\x20**'+(_0x50c6be[_0x2c959c(0x157)]||_0x50c6be[_0x2c959c(0x13d)])+_0x2c959c(0x189)+this[_0x2c959c(0x1cd)](_0x50c6be['message']));await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0xf8)+_0x7e3cd6[_0x2c959c(0x206)]+'\x20条)\x0a'+_0x5c533f[_0x2c959c(0x1e7)]('\x0a'),'msgType':'markdown'});}return;}case _0x2c959c(0xf7):{if(_0x7e3cd6[_0x2c959c(0x206)]===0x0){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x162),'msgType':'markdown'});return;}const _0x25610e=Math[_0x2c959c(0x1c4)](_0x147b2f['count'],_0x7e3cd6[_0x2c959c(0x206)]),_0x4b6ff1=_0x7e3cd6[_0x2c959c(0x1b2)](_0x7e3cd6[_0x2c959c(0x206)]-_0x25610e,_0x25610e),_0x586333=_0x4b6ff1[_0x2c959c(0x1c9)]((_0x59ccd2,_0x5e6276)=>_0x5e6276+0x1+'.\x20**'+(_0x59ccd2[_0x2c959c(0x157)]||_0x59ccd2[_0x2c959c(0x13d)])+_0x2c959c(0x189)+this[_0x2c959c(0x1cd)](_0x59ccd2[_0x2c959c(0x1e9)]));await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0xef)+_0x25610e+_0x2c959c(0x177)+_0x586333[_0x2c959c(0x1e7)]('\x0a'),'msgType':'markdown'});return;}case'cancelAll':{if(_0x7e3cd6[_0x2c959c(0x206)]===0x0){await this[_0x2c959c(0x1ca)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':_0x2c959c(0x162),'msgType':'markdown'});return;}const _0x132331=_0x7e3cd6[_0x2c959c(0x206)];_0x7e3cd6[_0x2c959c(0x206)]=0x0,await this['sendDingMessage']({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'content':'✅\x20已清空消息队列,共移除\x20'+_0x132331+_0x2c959c(0x14f),'msgType':_0x2c959c(0x107)});return;}}}await this[_0x2c959c(0x11c)]({'conversationId':_0x27df03,'sessionWebhook':_0x11e179,'senderStaffId':_0x2feb3d,'senderNick':_0x1f50b0,'message':_0xc2e69e,'conversationConfig':_0x5dca14});}async[a2_0x14d974(0xce)](){const _0x40c9f1=a2_0x14d974,_0x55bea3=Array['isArray'](this[_0x40c9f1(0xfb)]['conversations'])?this[_0x40c9f1(0xfb)][_0x40c9f1(0x183)]:[],_0x212d22=this[_0x40c9f1(0xfb)]['taskHandlerCount']??this[_0x40c9f1(0x210)],_0x3ebc21=_0x55bea3[_0x40c9f1(0x206)]>0x0;console[_0x40c9f1(0xff)]('['+(0x0,session_1['timestamp'])()+_0x40c9f1(0x12d)+this[_0x40c9f1(0x151)]),console[_0x40c9f1(0xff)]('['+(0x0,session_1[_0x40c9f1(0x1e1)])()+_0x40c9f1(0x20f)+_0x55bea3[_0x40c9f1(0x1c9)](_0x208aeb=>_0x208aeb[_0x40c9f1(0x11b)]||_0x208aeb[_0x40c9f1(0xd3)])[_0x40c9f1(0x1e7)](',\x20')),(0x0,api_key_manager_1['startupCheck'])(this),await(0x0,session_1[_0x40c9f1(0x175)])(this);this['config']['apiKeyCfg']&&((0x0,api_key_manager_1[_0x40c9f1(0x19f)])(this),(0x0,api_key_manager_1[_0x40c9f1(0xc3)])(this));this['loadActiveSessions'](),this['cronEngine'][_0x40c9f1(0xbd)]();_0x3ebc21&&console[_0x40c9f1(0xff)]('['+(0x0,session_1[_0x40c9f1(0x1e1)])()+_0x40c9f1(0x13e)+_0x212d22);this['dingStreamClient'][_0x40c9f1(0x176)](_0x40c9f1(0x133),async _0x324e66=>{const _0xe594eb=_0x40c9f1;await this[_0xe594eb(0x19a)](_0x324e66);});const _0xbfe829=[];if(_0x3ebc21)for(let _0x2180c2=0x0;_0x2180c2<_0x212d22;_0x2180c2++){console[_0x40c9f1(0xff)]('['+(0x0,session_1[_0x40c9f1(0x1e1)])()+_0x40c9f1(0x1de)+(_0x2180c2+0x1)),_0xbfe829['push'](this[_0x40c9f1(0x14e)]()['catch'](_0x4b7691=>console[_0x40c9f1(0x159)]('任务处理器\x20#'+(_0x2180c2+0x1)+'\x20错误:',_0x4b7691)));}const _0x2340ba=this[_0x40c9f1(0x10d)][_0x40c9f1(0x211)]()['catch'](_0x374f6d=>{const _0x1dbcac=_0x40c9f1;console[_0x1dbcac(0x159)](_0x1dbcac(0xec),_0x374f6d),process[_0x1dbcac(0x149)](0x1);});await Promise[_0x40c9f1(0xe8)]([_0x2340ba,..._0xbfe829]);}}exports[a2_0x14d974(0x11f)]=DingClaude;
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(T,i,s,n){n===void 0&&(n=s);var o=Object.getOwnPropertyDescriptor(i,s);(!o||("get"in o?!i.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return i[s]}}),Object.defineProperty(T,n,o)}):(function(T,i,s,n){n===void 0&&(n=s),T[n]=i[s]})),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(T,i){Object.defineProperty(T,"default",{enumerable:!0,value:i})}):function(T,i){T.default=i}),__importStar=this&&this.__importStar||(function(){var T=function(i){return T=Object.getOwnPropertyNames||function(s){var n=[];for(var o in s)Object.prototype.hasOwnProperty.call(s,o)&&(n[n.length]=o);return n},T(i)};return function(i){if(i&&i.__esModule)return i;var s={};if(i!=null)for(var n=T(i),o=0;o<n.length;o++)n[o]!=="default"&&__createBinding(s,i,n[o]);return __setModuleDefault(s,i),s}})(),__importDefault=this&&this.__importDefault||function(T){return T&&T.__esModule?T:{default:T}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DingClaude=void 0;const child_process_1=require("child_process"),utils_ok_1=require("utils-ok"),fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),common_1=require("../common"),quote_1=require("./quote"),messaging_1=require("./messaging"),image_1=require("./image"),commands_1=require("./commands"),messaging_2=require("./messaging"),claude_process_1=require("./claude-process"),recorder_1=require("./recorder"),session_1=require("./session"),task_1=require("./task"),api_key_manager_1=require("./api-key-manager"),cron_1=require("./cron"),TOOL_VERSION=(0,common_1.projUtil)().getPkgVersion();class DingClaude{constructor(i){this.resolvedPhones={},this.activeSessions=new Map,this.pendingAuthRequests=new Map,this.recorderModeConversations=new Set,this.DEFAULT_SESSION_MAX_CONCURRENCY=5,this.DEFAULT_TASK_HANDLER_COUNT=1,this.DEFAULT_TASK_QUEUE_SIZE=50,this.sendDingMessage=s=>(0,messaging_2.sendDingMessage)(this,s),this.sendClaudeResponseToDing=(s,n,o,e)=>(0,messaging_2.sendClaudeResponseToDing)(this,s,n,o,e),this.parseClaudeStreamLine=claude_process_1.parseClaudeStreamLine,this.interruptClaudeProcess=(s,n)=>(0,claude_process_1.interruptClaudeProcess)(s,n),this.executeClaudeQuery=(s,n,o)=>(0,claude_process_1.executeClaudeQuery)(this,s,n,o),this.getClientDir=()=>(0,session_1.getClientDir)(this),this.getClientConfig=()=>(0,session_1.getClientConfig)(this),this.authCheck=(s,n)=>(0,session_1.authCheck)(this,s,n),this.isOwner=s=>(0,session_1.isOwner)(this,s),this.debugLog=(s,...n)=>(0,session_1.debugLog)(this,s,...n),this.hashConversationId=s=>(0,session_1.hashConversationId)(this,s),this.getConversationConfig=s=>(0,session_1.getConversationConfig)(this,s),this.getConversationDir=s=>(0,session_1.getConversationDir)(this,s),this.getSessionsDir=s=>(0,session_1.getSessionsDir)(this,s),this.getTasksDir=s=>(0,session_1.getTasksDir)(this,s),this.getSessionDir=s=>(0,session_1.getSessionDir)(this,s),this.getSessionId=session_1.getSessionId,this.formatSessionInfo=s=>(0,session_1.formatSessionInfo)(this,s),this.readSessionLogTail=(s,n)=>(0,session_1.readSessionLogTail)(this,s,n),this.findActiveSession=s=>(0,session_1.findActiveSession)(this,s),this.findHistorySession=(s,n)=>(0,session_1.findHistorySession)(this,s,n),this.findLatestSession=s=>(0,session_1.findLatestSession)(this,s),this.updateSessionFile=(s,n)=>(0,session_1.updateSessionFile)(this,s,n),this.appendSessionLog=session_1.appendSessionLog,this.getActiveSessionsFile=s=>(0,session_1.getActiveSessionsFile)(this,s),this.saveActiveSession=s=>(0,session_1.saveActiveSession)(this,s),this.loadActiveSessions=()=>(0,session_1.loadActiveSessions)(this),this.endSession=(s,n)=>(0,session_1.endSession)(this,s,n),this.switchToSession=(s,n,o,e,c)=>(0,session_1.switchToSession)(this,s,n,o,e,c),this.startNewSession=s=>(0,session_1.startNewSession)(this,s),this.handleSessionMessage=s=>(0,session_1.handleSessionMessage)(this,s),this.cleanCache=(s,n=!0)=>(0,session_1.cleanCache)(this,s,n),this.formatTaskInfo=()=>(0,task_1.formatTaskInfo)(this),this.cancelTask=(s,n)=>(0,task_1.cancelTask)(this,s,n),this.countTodoTask=()=>(0,task_1.countTodoTask)(this),this.getOneTodoTask=()=>(0,task_1.getOneTodoTask)(this),this.finishTask=s=>(0,task_1.finishTask)(this,s),this.handleTask=()=>(0,task_1.handleTask)(this),this.runTaskHandlerLoop=()=>(0,task_1.runTaskHandlerLoop)(this),this.saveTask=s=>(0,task_1.saveTask)(this,s),this.clientId=i,this.config=(0,session_1.getClientConfig)(this);try{this.dingStreamClient=new utils_ok_1.DingStreamClient({clientId:i,clientSecret:this.config.clientSecret,keepAlive:!0,debug:this.config.debug??!1})}catch(s){console.error("Error: DingStreamClient init failed.",s),process.exit(1)}this.cronEngine=new cron_1.CronEngine(this)}async requireOwner(i,s,n){return this.isOwner(n)?!0:(await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async requireOwnerOrSingleChat(i,s,n,o){return this.isOwner(n)||o?.conversationType==="1"?!0:(await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async handleAuthRequest(i){const{senderStaffId:s,senderNick:n,conversationId:o,conversationType:e,conversationTitle:c,sessionWebhook:a}=i;if(!this.config.ownerConversationId){await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:["\u62B1\u6B49,\u60A8\u6682\u65E0\u4F7F\u7528\u6743\u9650","\u8BF7\u5C06\u4EE5\u4E0B\u4FE1\u606F\u53D1\u9001\u7ED9\u673A\u5668\u4EBA\u7BA1\u7406\u5458,\u7531\u7BA1\u7406\u5458\u901A\u8FC7\u547D\u4EE4\u6CE8\u518C:",`- **\u4F1A\u8BDDID:** \`${o}\``,`- **\u6CE8\u518C\u547D\u4EE4:** \`/cfg --conversationId ${o}\``].join(`
|
|
2
|
+
`),msgType:"markdown"});return}for(const k of this.pendingAuthRequests.values())if(k.senderStaffId===s&&k.conversationId===o){await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:"\u23F3 \u6388\u6743\u7533\u8BF7\u5DF2\u53D1\u9001\uFF0C\u8BF7\u7B49\u5F85\u7BA1\u7406\u5458\u5BA1\u6279...",msgType:"markdown"});return}const g=`r${Date.now().toString(36)}`,l={id:g,senderStaffId:s,senderNick:n,conversationId:o,conversationType:e,conversationTitle:c,requestTime:Date.now()};this.pendingAuthRequests.set(g,l),console.log(`[${(0,session_1.timestamp)()}] \u65B0\u6388\u6743\u7533\u8BF7: id=${g}, userId=${s}, \u6635\u79F0=${n}, \u4F1A\u8BDD=${o}`);const v=["\u{1F4CB} **\u6536\u5230\u6388\u6743\u7533\u8BF7**",`- **\u7528\u6237ID:** ${s}`,`- **\u6635\u79F0:** ${n}`,`- **\u4F1A\u8BDDID:** ${o}`,c?`- **\u4F1A\u8BDD\u6807\u9898:** ${c}`:"",`- **\u4F1A\u8BDD\u7C7B\u578B:** ${e==="1"?"\u5355\u804A":e==="2"?"\u7FA4\u804A":e||"-"}`,"",`\u56DE\u590D \`/auth approve ${g}\` \u901A\u8FC7`,`\u56DE\u590D \`/auth reject ${g}\` \u62D2\u7EDD`].filter(Boolean).join(`
|
|
3
|
+
`);await(0,messaging_1.sendOwnerMessage)(this,v,"markdown")?await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:"\u2705 \u5DF2\u5411\u7BA1\u7406\u5458\u53D1\u9001\u6388\u6743\u7533\u8BF7\uFF0C\u8BF7\u7B49\u5F85\u5BA1\u6279...",msgType:"markdown"}):(this.pendingAuthRequests.delete(g),await this.sendDingMessage({conversationId:o,sessionWebhook:a,content:"\u274C \u6388\u6743\u7533\u8BF7\u53D1\u9001\u5931\u8D25\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u624B\u52A8\u6388\u6743",msgType:"markdown"}))}async handleCronCommand(i,s){const{conversationId:n,sessionWebhook:o,senderStaffId:e,senderNick:c,conversationConfig:a}=s;switch(i.type){case"list":{const g=await this.getOrCreateLogSession(n,o,e,c,a,!0),l=this.cronEngine.listJobs(n);g.sessionDir&&(this.appendSessionLog(g.sessionDir,"user","/cron list"),this.appendSessionLog(g.sessionDir,"assistant",`\u5217\u51FA ${l.length} \u4E2A\u5B9A\u65F6\u4EFB\u52A1`)),await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:(0,cron_1.formatCronJobList)(l),msgType:"markdown"});return}case"delete":{const g=this.cronEngine.removeJob(i.id),l=await this.getOrCreateLogSession(n,o,e,c,a);l.sessionDir&&(this.appendSessionLog(l.sessionDir,"user",`/cron delete ${i.id}`),this.appendSessionLog(l.sessionDir,"assistant",g?`\u5220\u9664\u5B9A\u65F6\u4EFB\u52A1 ${i.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${i.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:g?`\u2705 \u5B9A\u65F6\u4EFB\u52A1 **${i.id}** \u5DF2\u5220\u9664`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${i.id}`,msgType:"markdown"});return}case"pause":{const g=this.cronEngine.toggleJob(i.id,!1),l=await this.getOrCreateLogSession(n,o,e,c,a);l.sessionDir&&(this.appendSessionLog(l.sessionDir,"user",`/cron pause ${i.id}`),this.appendSessionLog(l.sessionDir,"assistant",g?`\u6682\u505C\u5B9A\u65F6\u4EFB\u52A1 ${i.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${i.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:g?`\u23F8\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${i.id}** \u5DF2\u6682\u505C`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${i.id}`,msgType:"markdown"});return}case"resume":{const g=this.cronEngine.toggleJob(i.id,!0),l=await this.getOrCreateLogSession(n,o,e,c,a);l.sessionDir&&(this.appendSessionLog(l.sessionDir,"user",`/cron resume ${i.id}`),this.appendSessionLog(l.sessionDir,"assistant",g?`\u6062\u590D\u5B9A\u65F6\u4EFB\u52A1 ${i.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${i.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:g?`\u25B6\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${i.id}** \u5DF2\u6062\u590D`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${i.id}`,msgType:"markdown"});return}case"create_cron":{if(!(0,cron_1.isValidCronExpression)(i.cronExpression)){await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:`\u274C \u65E0\u6548\u7684cron\u8868\u8FBE\u5F0F: \`${i.cronExpression}\`
|
|
4
|
+
|
|
5
|
+
\u{1F4A1} \u683C\u5F0F: \`\u5206 \u65F6 \u65E5 \u6708 \u5468\`\uFF0C\u5982 \`0 9 * * *\``,msgType:"markdown"});return}if(!this.hasNotifyCapability(s.conversationConfig)){await this.sendCronNoNotifyError(n,o);return}const g=this.cronEngine.addJob({conversationId:n,cronExpression:i.cronExpression,description:this.sanitizeLogContent(i.prompt.substring(0,50)),prompt:i.prompt,senderStaffId:e,senderNick:c}),l=await this.getOrCreateLogSession(n,o,e,c,a);l.sessionDir&&(this.appendSessionLog(l.sessionDir,"user",`/cron ${i.cronExpression} ${this.sanitizeLogContent(i.prompt)}`),this.appendSessionLog(l.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${g.id} [${g.cronExpression}] ${g.description}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:(0,cron_1.formatCronJobInfo)(g),msgType:"markdown"});return}case"create_nl":{if(!this.hasNotifyCapability(s.conversationConfig)){await this.sendCronNoNotifyError(n,o);return}await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:"\u23F3 \u6B63\u5728\u5206\u6790\u5B9A\u65F6\u4EFB\u52A1\u63CF\u8FF0..."});const g=await this.cronEngine.analyzeAndCreate(n,i.input,e,c),l=await this.getOrCreateLogSession(n,o,e,c,a);g.job?(l.sessionDir&&(this.appendSessionLog(l.sessionDir,"user",`/cron ${this.sanitizeLogContent(i.input)}`),this.appendSessionLog(l.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${g.job.id} [${g.job.cronExpression}] ${g.job.description}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:(0,cron_1.formatCronJobInfo)(g.job),msgType:"markdown"})):(l.sessionDir&&(this.appendSessionLog(l.sessionDir,"user",`/cron ${this.sanitizeLogContent(i.input)}`),this.appendSessionLog(l.sessionDir,"assistant",`\u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${g.error}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:o,content:`\u274C \u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${g.error}
|
|
6
|
+
|
|
7
|
+
\u{1F4A1} \u4F60\u4E5F\u53EF\u4EE5\u76F4\u63A5\u6307\u5B9Acron\u8868\u8FBE\u5F0F: \`/cron 0 9 * * * \u4EFB\u52A1\u63CF\u8FF0\``,msgType:"markdown"}));return}}}sanitizeLogContent(i){return i.replace(/\n/g,"\\n").replace(/\r/g,"\\r")}sanitizeOutput(i){const s=i.replace(/\r\n/g,`
|
|
8
|
+
`),n=8e3;return s.length>n?s.substring(0,n)+`
|
|
9
|
+
...(\u8F93\u51FA\u5DF2\u622A\u65AD)`:s}truncateMsg(i,s=100){const n=i.replace(/\n/g," ").trim();return n.length>s?n.slice(0,s)+"...":n}async getOrCreateLogSession(i,s,n,o,e,c=!1){const a=this.findActiveSession(i);if(a)return{sessionDir:this.getSessionDir(a.session.session),isNew:!1};if(c)return{sessionDir:null,isNew:!1};const g=Date.now(),l={conversationId:i,sessionWebhook:s,startTime:g,startTimeStr:utils_ok_1.dateUtil.mm(g).format("YYYY-MM-DD-HH-mm-ss"),startStaffId:n,startNickName:`[cron]${o}`},v=this.getSessionDir(l);return fs_1.default.mkdirSync(v,{recursive:!0}),fs_1.default.writeFileSync(`${v}/session.json`,JSON.stringify(l,null,2),"utf-8"),fs_1.default.appendFileSync(`${v}/session.log`,`[${(0,session_1.timestamp)()}] [SYSTEM]: \u521B\u5EFA\u4F1A\u8BDD\u7528\u4E8E\u8BB0\u5F55 /cron \u547D\u4EE4\u64CD\u4F5C
|
|
10
|
+
`,"utf-8"),{sessionDir:v,isNew:!0}}hasNotifyCapability(i){return!!(i.dingToken||this.config.defaultDingToken)}async sendCronNoNotifyError(i,s){await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:"\u274C \u5F53\u524D\u7FA4\u672A\u914D\u7F6E dingToken \u4E14\u65E0\u5BA2\u6237\u7AEF\u7EA7 defaultDingToken, \u5B9A\u65F6\u4EFB\u52A1\u65E0\u6CD5\u4E3B\u52A8\u53D1\u9001\u6D88\u606F, \u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u914D\u7F6E",msgType:"markdown"})}resolveAndValidatePath(i,s){const n=this.getConversationDir(i);if(s.startsWith("/"))return{absolutePath:"",error:"\u274C \u8DEF\u5F84\u4E0D\u80FD\u4F7F\u7528\u7EDD\u5BF9\u8DEF\u5F84\uFF08\u4E0D\u80FD\u4EE5 / \u5F00\u5934\uFF09"};const o=path_1.default.resolve(n,s);return o.startsWith(n)?{absolutePath:o}:{absolutePath:"",error:"\u274C \u8DEF\u5F84\u8D85\u51FA\u5DE5\u4F5C\u76EE\u5F55\u8303\u56F4"}}async handleMkdirCommand(i,s,n){const{absolutePath:o,error:e}=this.resolveAndValidatePath(i,n);if(e){await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:e,msgType:"markdown"});return}try{fs_1.default.statSync(o).isDirectory()?await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u26A0\uFE0F \u76EE\u5F55\u5DF2\u5B58\u5728: \`${n}\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u274C \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u76EE\u5F55: \`${n}\``,msgType:"markdown"});return}catch{}try{fs_1.default.mkdirSync(o,{recursive:!0}),await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u2705 \u76EE\u5F55\u521B\u5EFA\u6210\u529F: \`${n}\``,msgType:"markdown"})}catch(c){await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u274C \u76EE\u5F55\u521B\u5EFA\u5931\u8D25: \`${n}\`
|
|
11
|
+
\u539F\u56E0: ${c instanceof Error?c.message:String(c)}`,msgType:"markdown"})}}async handleRmCommand(i,s,n){const{absolutePath:o,error:e}=this.resolveAndValidatePath(i,n);if(e){await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:e,msgType:"markdown"});return}let c;try{c=fs_1.default.statSync(o)}catch{await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u274C \u8DEF\u5F84\u4E0D\u5B58\u5728: \`${n}\``,msgType:"markdown"});return}const a=c.isDirectory();try{a?fs_1.default.rmSync(o,{recursive:!0,force:!0}):fs_1.default.unlinkSync(o),await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u2705 \u5DF2\u5220\u9664${a?"\u76EE\u5F55":"\u6587\u4EF6"}: \`${n}\``,msgType:"markdown"})}catch(g){await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u274C \u5220\u9664\u5931\u8D25: \`${n}\`
|
|
12
|
+
\u539F\u56E0: ${g instanceof Error?g.message:String(g)}`,msgType:"markdown"})}}async handleTouchCommand(i,s,n){const{absolutePath:o,error:e}=this.resolveAndValidatePath(i,n);if(e){await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:e,msgType:"markdown"});return}try{const c=fs_1.default.statSync(o);c.isFile()?await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u26A0\uFE0F \u6587\u4EF6\u5DF2\u5B58\u5728: \`${n}\`
|
|
13
|
+
\u6700\u540E\u4FEE\u6539\u65F6\u95F4: ${utils_ok_1.dateUtil.mm(c.mtime).format("YYYY-MM-DD HH:mm:ss")}`,msgType:"markdown"}):await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u274C \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u6587\u4EF6: \`${n}\``,msgType:"markdown"});return}catch{}try{const c=path_1.default.dirname(o);fs_1.default.mkdirSync(c,{recursive:!0}),fs_1.default.writeFileSync(o,"","utf-8"),await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u2705 \u6587\u4EF6\u521B\u5EFA\u6210\u529F: \`${n}\``,msgType:"markdown"})}catch(c){await this.sendDingMessage({conversationId:i,sessionWebhook:s,content:`\u274C \u6587\u4EF6\u521B\u5EFA\u5931\u8D25: \`${n}\`
|
|
14
|
+
\u539F\u56E0: ${c instanceof Error?c.message:String(c)}`,msgType:"markdown"})}}async botMsgGetCallback(i){this.dingStreamClient.socketCallBackResponse(i.headers.messageId,"");const s=JSON.parse(i.data),{senderNick:n,senderStaffId:o,conversationId:e,conversationTitle:c,sessionWebhook:a,msgtype:g,conversationType:l}=s,v=s.text?.content?.trim()??"";if(this.debugLog(`\u6536\u5230\u6D88\u606F: \u7FA4=${c}(${e}), \u53D1\u9001\u8005=${n}(${o}), \u7C7B\u578B=${g}, \u5185\u5BB9=${v.substring(0,50)}`),!this.authCheck(o,e)){await this.handleAuthRequest({senderStaffId:o,senderNick:n,conversationId:e,conversationType:l,conversationTitle:s.conversationTitle,sessionWebhook:a});return}const w=this.getConversationConfig(e),k=(0,commands_1.parseRecorderCommand)(v);if(k!==null){if(!this.isOwner(o)||l!=="1"){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u274C Recorder \u6A21\u5F0F\u4EC5\u9650 owner \u5355\u804A\u4F7F\u7528",msgType:"markdown"});return}if(k==="on"){this.recorderModeConversations.add(e);const t=(0,recorder_1.getRecorderDir)(this,e);console.log(`[${(0,session_1.timestamp)()}] [recorder] \u5F00\u542F recorder \u6A21\u5F0F: conversationId=${e}, dir=${t}`),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F534} Recorder \u6A21\u5F0F\u5DF2\u5F00\u542F
|
|
15
|
+
- \u6240\u6709\u6D88\u606F\u5C06\u88AB\u5206\u7C7B\u8BB0\u5F55\u5230\u672C\u5730
|
|
16
|
+
- \u4FDD\u5B58\u76EE\u5F55: \`${t}\`
|
|
17
|
+
- \u53D1\u9001 \`/recorder exit\` \u5173\u95ED`,msgType:"markdown"})}else this.recorderModeConversations.delete(e),console.log(`[${(0,session_1.timestamp)()}] [recorder] \u5173\u95ED recorder \u6A21\u5F0F: conversationId=${e}`),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u2B1C Recorder \u6A21\u5F0F\u5DF2\u5173\u95ED\uFF0C\u6062\u590D\u6B63\u5E38\u5904\u7406",msgType:"markdown"});return}if(this.recorderModeConversations.has(e)){try{await(0,recorder_1.recordMessage)(this,s,e),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u8BB0\u5F55 ${g}`})}catch(t){console.error(`[${(0,session_1.timestamp)()}] [recorder] \u8BB0\u5F55\u6D88\u606F\u5931\u8D25:`,t),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u274C \u8BB0\u5F55\u5931\u8D25: ${t instanceof Error?t.message:String(t)}`})}return}let u;if(g==="picture"&&s.pictureDownloadCode){const t=this.getConversationDir(e),r=w?.useLocalOcr!==!1,d=await(0,image_1.processPictureMessage)(this,s.pictureDownloadCode,s.robotCode,t,r,v||void 0);if(!d){await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:o,content:"\u26A0\uFE0F \u56FE\u7247\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u4F7F\u7528\u6587\u5B57\u63CF\u8FF0"});return}u=d}else if(g==="richText"&&s.content?.richText){const t=this.getConversationDir(e),r=w?.useLocalOcr!==!1;u=await(0,image_1.processRichTextMessage)(this,s.content.richText,s.robotCode,t,r)}else if(u=v,!u)return;if(!u.startsWith("/")&&g==="text"){const t=(0,quote_1.extractQuoteInfo)(s);if(t){if(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F: quoteMessageId=${t.quoteMessageId}`),t.quoteMessageId&&!t.quoteText){const r=await(0,messaging_1.fetchQuotedMessage)(this,t.quoteMessageId);r&&(t.quoteText=r)}t.quoteText&&(u=(0,quote_1.formatPromptWithQuote)(u,t))}}const h=(0,commands_1.parseCfgCommand)(u);if(h!==null){if(h.conversationId&&w?.conversationType!=="1"&&!this.isOwner(o)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u64CD\u4F5C\u5176\u4ED6\u7FA4\u7684\u914D\u7F6E",msgType:"markdown"});return}if(!await this.requireOwnerOrSingleChat(e,a,o,w))return;const t=h.conversationId||e,r=t!==e,d=r?this.config.conversations.find(C=>C.conversationId===t):w,p=!!(h.dingToken||h.linkConversationId||h.whiteUserList&&h.whiteUserList.length>0||h.conversationTitle||h.atSender!==void 0||h.receiveReply!==void 0||h.preBash!==void 0);if(d&&p){if(h.conversationTitle&&(d.conversationTitle=h.conversationTitle),l&&!r&&(d.conversationType=l),h.dingToken&&(d.dingToken=h.dingToken),h.linkConversationId&&(d.linkConversationId=h.linkConversationId),h.atSender!==void 0&&(d.atSender=h.atSender),h.receiveReply!==void 0&&(d.receiveReply=h.receiveReply),h.preBash!==void 0&&(d.preBash=h.preBash),h.whiteUserList&&h.whiteUserList.length>0){d.whiteUserList=h.whiteUserList;for(const C of h.whiteUserList)(0,session_1.isMobile)(C)&&await(0,session_1.resolveUserId)(this,C)}(0,api_key_manager_1.saveClientConfig)(this),console.log(`[${(0,session_1.timestamp)()}] \u5237\u65B0\u7FA4\u914D\u7F6E: ${d.conversationTitle||t}(${t})`)}else if(!d){const C={conversationId:t,conversationType:r?"1":l,conversationTitle:h.conversationTitle||(r?"":c)};if(h.dingToken&&(C.dingToken=h.dingToken),h.linkConversationId&&(C.linkConversationId=h.linkConversationId),h.atSender!==void 0&&(C.atSender=h.atSender),h.receiveReply!==void 0&&(C.receiveReply=h.receiveReply),h.preBash!==void 0&&(C.preBash=h.preBash),h.whiteUserList&&h.whiteUserList.length>0){C.whiteUserList=h.whiteUserList;for(const $ of h.whiteUserList)(0,session_1.isMobile)($)&&await(0,session_1.resolveUserId)(this,$)}this.config.conversations.push(C),(0,api_key_manager_1.saveClientConfig)(this),console.log(`[${(0,session_1.timestamp)()}] \u6CE8\u518C\u65B0\u7FA4: ${C.conversationTitle||t}(${t}) \u7C7B\u578B=${C.conversationType||"-"}`)}const D=this.getConversationDir(t);fs_1.default.existsSync(D)||(fs_1.default.mkdirSync(D,{recursive:!0}),console.log(`[${(0,session_1.timestamp)()}] \u521B\u5EFA\u5DE5\u4F5C\u76EE\u5F55: ${D}`));const m=d||this.getConversationConfig(t),f=[d?"\u2705 \u7FA4\u914D\u7F6E\u5DF2\u5237\u65B0":"\u2705 \u7FA4\u5DF2\u6CE8\u518C",`- **\u7FA4\u540D\u79F0:** ${m?.conversationTitle||t}`,`- **\u7FA4ID:** ${t}`];if(m?.conversationType&&f.push(`- **\u4F1A\u8BDD\u7C7B\u578B:** ${m.conversationType==="1"?"\u5355\u804A":m.conversationType==="2"?"\u7FA4\u804A":m.conversationType}`),m?.dingToken?f.push(`- **dingToken:** ${m.dingToken.substring(0,8)}...`):f.push("- **dingToken:** (\u672A\u6307\u5B9A, \u4F7F\u7528 defaultDingToken)"),m?.linkConversationId&&f.push(`- **linkConversationId:** ${m.linkConversationId}`),m?.atSender===!1&&f.push("- **atSender:** false (\u4E0D @ \u53D1\u9001\u4EBA)"),m?.receiveReply===!1&&f.push("- **receiveReply:** false (\u4E0D\u56DE\u590D\u786E\u8BA4\u6D88\u606F)"),m?.whiteUserList?.length){const C=m.whiteUserList.map($=>(0,session_1.isMobile)($)?$:(0,session_1.userIdToPhone)(this,$)||$).join(", ");f.push(`- **whiteUserList:** ${C}`)}f.push(`- **\u5DE5\u4F5C\u76EE\u5F55:** ${D}`),f.push(`
|
|
18
|
+
\u{1F4A1} \u53EF\u7F16\u8F91 config.json \u8865\u5145\u66F4\u591A\u914D\u7F6E`),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:f.join(`
|
|
19
|
+
`),msgType:"markdown"});return}if((0,commands_1.parseHelpCommand)(u)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:(0,commands_1.formatHelpOverview)(TOOL_VERSION,this.isOwner(o)),msgType:"markdown"});return}if((0,commands_1.parseVersionCommand)(u)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`**\u7248\u672C:** ${TOOL_VERSION}`,msgType:"markdown"});return}const M=(0,commands_1.parseCommandHelp)(u);if(M){const t=(0,commands_1.getCommandByName)(M);t?await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:(0,commands_1.formatCommandHelp)(t),msgType:"markdown"}):await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u274C \u672A\u627E\u5230\u547D\u4EE4: **${M}**
|
|
20
|
+
|
|
21
|
+
\u{1F4A1} \u8F93\u5165 \`/help\` \u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4`,msgType:"markdown"});return}if(!w){console.log(`\u672A\u6CE8\u518C\u7684\u673A\u5668\u4EBA,\u7FA4:${c},${e}`),this.isOwner(o)?await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:o,content:"\u26A0\uFE0F \u8BE5\u7FA4\u672A\u6CE8\u518C\uFF0C\u8BF7\u5148\u4F7F\u7528 `/cfg` \u547D\u4EE4\u6CE8\u518C",msgType:"markdown"}):await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:o,content:`\u62B1\u6B49,\u8BE5\u7FA4\u7684\u673A\u5668\u4EBA\u672A\u5728\u670D\u52A1\u7AEF\u6CE8\u518C,\u8BF7\u8054\u7CFB\u5E94\u7528\u673A\u5668\u4EBAowner\u6CE8\u518C(${e})...`});return}const I=(0,commands_1.parseCleanCommand)(u);if(I!==null){if(I==="all"&&w?.conversationType!=="1"&&!this.isOwner(o)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6E05\u9664\u6240\u6709\u7FA4\u7F13\u5B58",msgType:"markdown"});return}if(!await this.requireOwnerOrSingleChat(e,a,o,w))return;const t=I==="all"?null:e,r=this.cleanCache(t,!0),d=[];d.push("\u{1F9F9} \u7F13\u5B58\u6E05\u7406\u5B8C\u6210"),r.sessionsDeleted>0&&d.push(`- \u4F1A\u8BDD\u76EE\u5F55: ${r.sessionsDeleted} \u4E2A`),r.tasksDeleted>0&&d.push(`- \u4EFB\u52A1\u76EE\u5F55: ${r.tasksDeleted} \u4E2A`),r.imagesDeleted>0&&d.push(`- \u56FE\u7247\u6587\u4EF6: ${r.imagesDeleted} \u4E2A`),r.sessionsDeleted===0&&r.tasksDeleted===0&&r.imagesDeleted===0&&d.push("(\u65E0\u5386\u53F2\u6570\u636E)"),d.push(`
|
|
22
|
+
\u{1F4A1} \u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u4FDD\u7559`),r.errors.length>0&&d.push(`
|
|
23
|
+
\u26A0\uFE0F \u9519\u8BEF: ${r.errors.join("; ")}`),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:d.join(`
|
|
24
|
+
`),msgType:"markdown"});return}if((0,commands_1.parseResetApiKeyCfgCommand)(u)){if(!await this.requireOwner(e,a,o))return;if(!this.config.apiKeyCfg){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u26A0\uFE0F \u672A\u914D\u7F6E apiKeyCfg\uFF0C\u65E0\u9700\u91CD\u7F6E",msgType:"markdown"});return}(0,api_key_manager_1.resetApiKeyCfg)(this);const t=this.config.apiKeyCfg.claudeSettings.filter(r=>r.isValid).length;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 apiKeyCfg \u5DF2\u91CD\u7F6E
|
|
25
|
+
- \u6709\u6548 Key \u6570: ${t}/${this.config.apiKeyCfg.claudeSettings.length}
|
|
26
|
+
- \u91CD\u7F6E\u65F6\u95F4: ${this.config.apiKeyCfg.resetTime||"-"}`,msgType:"markdown"});return}const y=(0,commands_1.parseAuthCommand)(u);if(y){if(!await this.requireOwner(e,a,o))return;if(y.type==="approve"||y.type==="reject"){const r=this.pendingAuthRequests.get(y.requestId);if(!r){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u274C \u672A\u627E\u5230\u6388\u6743\u7533\u8BF7: ${y.requestId}`,msgType:"markdown"});return}if(this.pendingAuthRequests.delete(y.requestId),y.type==="approve"){let d=this.config.conversations.find(p=>p.conversationId===r.conversationId);d||(d={conversationId:r.conversationId,conversationType:r.conversationType||"1",conversationTitle:r.conversationTitle},this.config.conversations.push(d)),d.whiteUserList||(d.whiteUserList=[]),d.whiteUserList.includes(r.senderStaffId)||d.whiteUserList.push(r.senderStaffId),(0,api_key_manager_1.saveClientConfig)(this),console.log(`[${(0,session_1.timestamp)()}] \u6388\u6743\u7533\u8BF7\u901A\u8FC7: id=${y.requestId}, userId=${r.senderStaffId}`),await(0,messaging_1.sendMessageToUser)(this,r.senderStaffId,"\u2705 \u60A8\u7684\u6388\u6743\u7533\u8BF7\u5DF2\u901A\u8FC7\uFF0C\u73B0\u5728\u53EF\u4EE5\u5F00\u59CB\u4F7F\u7528\u4E86","markdown"),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u901A\u8FC7\u6388\u6743\u7533\u8BF7
|
|
27
|
+
- **\u7528\u6237ID:** ${r.senderStaffId}
|
|
28
|
+
- **\u6635\u79F0:** ${r.senderNick}
|
|
29
|
+
- **\u4F1A\u8BDDID:** ${r.conversationId}`,msgType:"markdown"})}else console.log(`[${(0,session_1.timestamp)()}] \u6388\u6743\u7533\u8BF7\u62D2\u7EDD: id=${y.requestId}, userId=${r.senderStaffId}`),await(0,messaging_1.sendMessageToUser)(this,r.senderStaffId,"\u274C \u60A8\u7684\u6388\u6743\u7533\u8BF7\u5DF2\u88AB\u62D2\u7EDD","markdown"),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u62D2\u7EDD\u6388\u6743\u7533\u8BF7
|
|
30
|
+
- **\u7528\u6237ID:** ${r.senderStaffId}
|
|
31
|
+
- **\u6635\u79F0:** ${r.senderNick}`,msgType:"markdown"});return}const t=w.whiteUserList;if(y.type==="list"){const r=t&&t.length>0?t.map(d=>`- ${(0,session_1.userIdToPhone)(this,d)||d}`).join(`
|
|
32
|
+
`):"(\u672A\u914D\u7F6E\u7FA4\u7EA7\u767D\u540D\u5355\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)";await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4CB} **\u5F53\u524D\u7FA4\u767D\u540D\u5355**
|
|
33
|
+
${r}`,msgType:"markdown"});return}if(y.type==="add"){let r=y.staffId;if((0,session_1.isMobile)(y.staffId)&&(r=await(0,session_1.resolveUserId)(this,y.staffId),!r)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${y.staffId}`,msgType:"markdown"});return}if(t?.some(m=>(0,session_1.resolveToUserId)(this,m)===r)){const m=(0,session_1.userIdToPhone)(this,r)||r;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u26A0\uFE0F ${m} \u5DF2\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}w.whiteUserList||(w.whiteUserList=[]),w.whiteUserList.push(y.staffId),(0,api_key_manager_1.saveClientConfig)(this);const p=w.whiteUserList.map(m=>{const f=(0,session_1.resolveToUserId)(this,m);return(0,session_1.userIdToPhone)(this,f)||m}),D=(0,session_1.isMobile)(y.staffId)?y.staffId:(0,session_1.userIdToPhone)(this,y.staffId)||y.staffId;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u6DFB\u52A0 ${D} \u5230\u5F53\u524D\u7FA4\u767D\u540D\u5355
|
|
34
|
+
\u5F53\u524D\u767D\u540D\u5355: ${p.join(", ")}`,msgType:"markdown"});return}if(y.type==="del"){let r=y.staffId;if((0,session_1.isMobile)(y.staffId)&&(r=await(0,session_1.resolveUserId)(this,y.staffId),!r)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${y.staffId}`,msgType:"markdown"});return}const d=t?.findIndex(f=>(0,session_1.resolveToUserId)(this,f)===r)??-1;if(d<0){const f=(0,session_1.userIdToPhone)(this,r)||r;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u26A0\uFE0F ${f} \u4E0D\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}const p=w.whiteUserList[d];w.whiteUserList.splice(d,1),w.whiteUserList.length===0&&delete w.whiteUserList,(0,api_key_manager_1.saveClientConfig)(this);const D=w.whiteUserList?.length?w.whiteUserList.map(f=>{const C=(0,session_1.resolveToUserId)(this,f);return(0,session_1.userIdToPhone)(this,C)||f}).join(", "):"(\u7A7A\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)",m=(0,session_1.userIdToPhone)(this,r)||p;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u79FB\u9664 ${m}
|
|
35
|
+
\u5F53\u524D\u767D\u540D\u5355: ${D}`,msgType:"markdown"});return}}const L=(0,commands_1.parseOpenCommand)(u);if(L!==null){if(!await this.requireOwner(e,a,o))return;const t=this.getConversationDir(e),{exec:r}=await Promise.resolve().then(()=>__importStar(require("child_process"))),d=process.platform;try{L==="folder"?(r(d==="darwin"?`open "${t}"`:`explorer "${t}"`),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4C2} \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u6253\u5F00:
|
|
36
|
+
\`\`\`
|
|
37
|
+
${t}
|
|
38
|
+
\`\`\``,msgType:"markdown"})):L==="code"?r("which code",p=>{if(p){this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u274C \u672A\u68C0\u6D4B\u5230 VS Code `code` \u547D\u4EE4\n\u8BF7\u5B89\u88C5 VS Code \u5E76\u901A\u8FC7 Command Palette \u5B89\u88C5 Shell Command",msgType:"markdown"});return}r(`code "${t}"`),this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4BB} \u5DF2\u5728 VS Code \u4E2D\u6253\u5F00:
|
|
39
|
+
\`\`\`
|
|
40
|
+
${t}
|
|
41
|
+
\`\`\``,msgType:"markdown"})}):(d==="darwin"?r(`open -a Terminal "${t}"`):r(`start cmd /k "cd /d ${t}"`,{shell:"cmd.exe"}),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4BB} \u5DF2\u5728\u7EC8\u7AEF\u4E2D\u6253\u5F00:
|
|
42
|
+
\`\`\`
|
|
43
|
+
${t}
|
|
44
|
+
\`\`\``,msgType:"markdown"}))}catch(p){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u274C \u6253\u5F00\u5931\u8D25: ${p instanceof Error?p.message:String(p)}`,msgType:"markdown"})}return}const b=(0,commands_1.parseCronCommand)(u);if(b){await this.handleCronCommand(b,{conversationId:e,sessionWebhook:a,senderStaffId:o,senderNick:n,conversationConfig:w});return}if((0,commands_1.parsePwdCommand)(u)){const t=this.getConversationDir(e);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4C2} \u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55:
|
|
45
|
+
\`\`\`
|
|
46
|
+
${t}
|
|
47
|
+
\`\`\``,msgType:"markdown"});return}const q=(0,commands_1.parseMkdirCommand)(u);if(q!==null){await this.handleMkdirCommand(e,a,q);return}const A=(0,commands_1.parseTouchCommand)(u);if(A!==null){await this.handleTouchCommand(e,a,A);return}const E=(0,commands_1.parseRmCommand)(u);if(E!==null){await this.handleRmCommand(e,a,E);return}const U=(0,commands_1.parseBashCommand)(u);if(U!==null){const t=this.getConversationDir(e),r=[];this.config.preBash&&r.push(this.config.preBash),w?.preBash&&r.push(w.preBash);const d=r.length>0?`${r.join(" ; ")} ; ${U}`:U,p=this;(0,child_process_1.exec)(d,{cwd:t,timeout:3e4,maxBuffer:1024*1024},async(D,m,f)=>{try{let C;if(D)C=`\u274C \u547D\u4EE4\u6267\u884C\u5931\u8D25
|
|
48
|
+
\`\`\`
|
|
49
|
+
${D.message}
|
|
50
|
+
\`\`\``,f&&(C+=`
|
|
51
|
+
|
|
52
|
+
**stderr:**
|
|
53
|
+
\`\`\`
|
|
54
|
+
${p.sanitizeOutput(f)}
|
|
55
|
+
\`\`\``);else{const $=m||"(\u65E0\u8F93\u51FA)";C=`\u2705 \u6267\u884C\u6210\u529F
|
|
56
|
+
\`\`\`
|
|
57
|
+
${p.sanitizeOutput($)}
|
|
58
|
+
\`\`\``,f&&(C+=`
|
|
59
|
+
|
|
60
|
+
**stderr:**
|
|
61
|
+
\`\`\`
|
|
62
|
+
${p.sanitizeOutput(f)}
|
|
63
|
+
\`\`\``)}await p.sendDingMessage({conversationId:e,sessionWebhook:a,content:C,msgType:"markdown"})}catch(C){console.error("[bash] \u53D1\u9001\u6D88\u606F\u5931\u8D25:",C)}});return}if(/^\/new(?:\s|$)/i.test(u)){const t=this.findActiveSession(e);t&&(console.log(`\u6536\u5230\u65B0\u4F1A\u8BDD\u547D\u4EE4\uFF0C\u7ED3\u675F\u65E7\u4F1A\u8BDD: \u7FA4=${t.session.session.conversationId}, \u4F1A\u8BDDID=${this.getSessionId(t.session.session)}`),this.interruptClaudeProcess(t.session,"\u65B0\u4F1A\u8BDD\u547D\u4EE4\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B"),this.activeSessions.delete(t.key),this.saveActiveSession(t.key));const r=u.replace(/^\/new\s*/i,"").trim();r?await this.startNewSession({conversationId:e,sessionWebhook:a,senderStaffId:o,senderNick:n,message:r,conversationConfig:w}):await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:o,content:"\u{1F680} \u8BF7\u8F93\u5165\u60A8\u7684\u95EE\u9898\u5F00\u59CB\u65B0\u4F1A\u8BDD"});return}const P=(0,commands_1.parseContinueSessionCommand)(u);if(P!==null&&w){let t=P;if(!t){const r=(0,session_1.findLatestSession)(this,e);if(!r){await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:o,content:"\u26A0\uFE0F \u672A\u627E\u5230\u5DF2\u7ED3\u675F\u7684\u4F1A\u8BDD",msgType:"markdown"});return}t=(0,session_1.getSessionId)(r)}await this.switchToSession(e,a,t,o,w);return}const _=(0,commands_1.parseLogCommand)(u);if(_!==null){const t=this.readSessionLogTail(e,_);t?await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4CB} \u6700\u8FD1 ${_} \u884C\u65E5\u5FD7:
|
|
64
|
+
\`\`\`
|
|
65
|
+
${t}
|
|
66
|
+
\`\`\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u6D3B\u8DC3\u4F1A\u8BDD\u6216\u6682\u65E0\u65E5\u5FD7"});return}const S=(0,commands_1.parseInfoCommand)(u);if(S!==null){const t=[],r=this.getConversationDir(e);if((S==="all"||S==="robot")&&(t.push(`### \u{1F310} \u5168\u5C40\u6838\u5FC3\u914D\u7F6E
|
|
67
|
+
`+(0,commands_1.formatGlobalConfig)(this.config)),t.push(`### \u{1F916} \u7FA4\u914D\u7F6E\u4FE1\u606F
|
|
68
|
+
`+(0,commands_1.formatConversationInfo)(w,e,d=>(0,session_1.userIdToPhone)(this,d),r))),S==="all"||S==="session"){const d=this.formatSessionInfo(e);d?t.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
|
|
69
|
+
`+d):t.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
|
|
70
|
+
\u65E0\u6D3B\u8DC3\u4F1A\u8BDD`)}(S==="all"||S==="task")&&t.push(`### \u{1F4DD} \u4EFB\u52A1\u961F\u5217\u4FE1\u606F
|
|
71
|
+
`+this.formatTaskInfo()),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:t.join(`
|
|
72
|
+
|
|
73
|
+
`),msgType:"markdown"});return}const N=(0,commands_1.parseLsCommand)(u);if(N!==null){const{target:t,depth:r}=N,d=this.getConversationDir(e);let p=d,D="\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55";if(t&&t!=="root")if(t.startsWith("./")||t.startsWith("../")||t.startsWith("/")){const f=path_1.default.resolve(d,t);if(fs_1.default.existsSync(f)&&fs_1.default.statSync(f).isDirectory()){if(!f.startsWith(d)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u274C \u8DEF\u5F84\u8D85\u51FA\u5DE5\u4F5C\u76EE\u5F55\u8303\u56F4",msgType:"markdown"});return}p=f,D=t}else{await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u274C \u8DEF\u5F84\u4E0D\u5B58\u5728\u6216\u4E0D\u662F\u76EE\u5F55: **${t}**`,msgType:"markdown"});return}}else{const f=(0,commands_1.findSubdirByName)(d,t);if(f)p=f,D=t;else{await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u274C \u672A\u627E\u5230\u540D\u4E3A **${t}** \u7684\u76EE\u5F55`,msgType:"markdown"});return}}const m=(0,commands_1.getDirectoryStructure)(p,0,r);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4C2} ${D} (\u5C55\u5F00${r}\u5C42):
|
|
74
|
+
\`\`\`
|
|
75
|
+
${m}
|
|
76
|
+
\`\`\``,msgType:"markdown"});return}const x=(0,task_1.parseTaskCancelCommand)(u);if(x){const t=this.cancelTask(x,e);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:t,msgType:"markdown"});return}if(u.startsWith("/task ")){const t=u.substring(6).trim();t&&(await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:o,content:"\u{1F4CB} \u4EFB\u52A1\u5DF2\u6536\u5230,\u5B8C\u6210\u540E\u6211\u4F1A\u56DE\u590D"}),await this.saveTask({conversationId:e,prompt:t,senderStaffId:o,senderNickName:n,sessionWebhook:a}));return}const O=(0,commands_1.parseMqCommand)(u);if(O){const r=this.findActiveSession(e)?.session.messageQueue??[];switch(O.type){case"list":{if(r.length===0)await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});else{const d=r.map((p,D)=>`${D+1}. **${p.senderNick||p.senderStaffId}:** ${this.truncateMsg(p.message)}`);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4E8} \u6D88\u606F\u961F\u5217 (${r.length} \u6761)
|
|
77
|
+
${d.join(`
|
|
78
|
+
`)}`,msgType:"markdown"})}return}case"cancel":{if(r.length===0){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}const d=Math.min(O.count,r.length),D=r.splice(r.length-d,d).map((m,f)=>`${f+1}. **${m.senderNick||m.senderStaffId}:** ${this.truncateMsg(m.message)}`);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u4ECE\u961F\u5C3E\u79FB\u9664 ${d} \u6761\u6D88\u606F
|
|
79
|
+
${D.join(`
|
|
80
|
+
`)}`,msgType:"markdown"});return}case"cancelAll":{if(r.length===0){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}const d=r.length;r.length=0,await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u6E05\u7A7A\u6D88\u606F\u961F\u5217\uFF0C\u5171\u79FB\u9664 ${d} \u6761\u6D88\u606F`,msgType:"markdown"});return}}}if((0,commands_1.parseGoonCommand)(u)){const t=this.activeSessions.get(e);if(!t){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD"});return}if(t.currentProcess)console.log(`[${(0,session_1.timestamp)()}] /goon: \u7EC8\u6B62\u5F53\u524D Claude \u8FDB\u7A0B\u5E76\u6807\u8BB0 goonPending`),t.goonPending=!0,t.interrupted=!0,t.currentProcess.kill("SIGINT"),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u{1F504} \u6B63\u5728\u91CD\u542F Claude \u8FDB\u7A0B..."});else{console.log(`[${(0,session_1.timestamp)()}] /goon: \u65E0\u8FD0\u884C\u4E2D\u8FDB\u7A0B\uFF0C\u76F4\u63A5\u53D1\u9001"\u7EE7\u7EED"`),t.isProcessing=!0;try{await(0,claude_process_1.executeClaudeQuery)(this,t.session,"\u7EE7\u7EED",{senderNick:n,senderStaffId:o})}finally{t.isProcessing=!1}}return}const R=(0,commands_1.parseCcCommand)(u);if(R!==null){const t=this.activeSessions.get(e);if(!t){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u53D1\u9001\u6D88\u606F\u5F00\u59CB\u4F1A\u8BDD"});return}if(t.isProcessing){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u23F3 \u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u7B49..."});return}t.isProcessing=!0;try{await(0,claude_process_1.executeClaudeQuery)(this,t.session,R,{senderNick:n,senderStaffId:o})}finally{t.isProcessing=!1}return}if((0,commands_1.parseClaudeMdCommand)(u)){const t=this.getConversationDir(e),r=path_1.default.join(t,".claude","CLAUDE.md");if(fs_1.default.existsSync(r)){const d=fs_1.default.readFileSync(r,"utf-8"),p=d.length>8e3?d.substring(0,8e3)+`
|
|
81
|
+
...(\u5185\u5BB9\u8FC7\u957F\u5DF2\u622A\u65AD)`:d;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4C4} **CLAUDE.md**
|
|
82
|
+
\`\`\`
|
|
83
|
+
${p}
|
|
84
|
+
\`\`\``,msgType:"markdown"})}else await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u26A0\uFE0F \u672A\u627E\u5230 CLAUDE.md
|
|
85
|
+
\u8DEF\u5F84: \`${r}\``,msgType:"markdown"});return}await this.handleSessionMessage({conversationId:e,sessionWebhook:a,senderStaffId:o,senderNick:n,message:u,conversationConfig:w})}async run(){const i=Array.isArray(this.config.conversations)?this.config.conversations:[],s=this.config.taskHandlerCount??this.DEFAULT_TASK_HANDLER_COUNT,n=i.length>0;console.log(`[${(0,session_1.timestamp)()}] \u9489\u9489\u673A\u5668\u4EBA\u670D\u52A1\u542F\u52A8\uFF0CclientId: ${this.clientId}`),console.log(`[${(0,session_1.timestamp)()}] \u7FA4\u914D\u7F6E: ${i.map(c=>c.conversationTitle||c.conversationId).join(", ")}`),(0,api_key_manager_1.startupCheck)(this),await(0,session_1.resolveAllPhonesInConfig)(this),this.config.apiKeyCfg&&((0,api_key_manager_1.resetApiKeyCfg)(this),(0,api_key_manager_1.scheduleApiKeyCfgDailyReset)(this)),this.loadActiveSessions(),this.cronEngine.start(),n&&console.log(`[${(0,session_1.timestamp)()}] \u4EFB\u52A1\u5904\u7406\u5668\u6570\u91CF: ${s}`),this.dingStreamClient.registerCallbackListener("/v1.0/im/bot/messages/get",async c=>{await this.botMsgGetCallback(c)});const o=[];if(n)for(let c=0;c<s;c++)console.log(`[${(0,session_1.timestamp)()}] \u542F\u52A8\u4EFB\u52A1\u5904\u7406\u5668 #${c+1}`),o.push(this.runTaskHandlerLoop().catch(a=>console.error(`\u4EFB\u52A1\u5904\u7406\u5668 #${c+1} \u9519\u8BEF:`,a)));const e=this.dingStreamClient.connect().catch(c=>{console.error("Fatal error",c),process.exit(1)});await Promise.all([e,...o])}}exports.DingClaude=DingClaude;
|