cc-ding 0.0.5 → 0.2.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/README.md +249 -85
- 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 +13 -1
- package/dist/src/biz/lock.js +1 -1
- package/dist/src/biz/menu.js +3 -0
- package/dist/src/biz/messaging.js +6 -1
- package/dist/src/biz/notify.js +1 -0
- package/dist/src/biz/quote.js +9 -1
- package/dist/src/biz/recorder.js +9 -0
- package/dist/src/biz/session.js +14 -1
- package/dist/src/biz/task.js +24 -1
- package/dist/src/biz/todo.js +8 -0
- 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
|
@@ -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,o,s,n){n===void 0&&(n=s);var r=Object.getOwnPropertyDescriptor(o,s);(!r||("get"in r?!o.__esModule:r.writable||r.configurable))&&(r={enumerable:!0,get:function(){return o[s]}}),Object.defineProperty(T,n,r)}):(function(T,o,s,n){n===void 0&&(n=s),T[n]=o[s]})),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(T,o){Object.defineProperty(T,"default",{enumerable:!0,value:o})}):function(T,o){T.default=o}),__importStar=this&&this.__importStar||(function(){var T=function(o){return T=Object.getOwnPropertyNames||function(s){var n=[];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(n[n.length]=r);return n},T(o)};return function(o){if(o&&o.__esModule)return o;var s={};if(o!=null)for(var n=T(o),r=0;r<n.length;r++)n[r]!=="default"&&__createBinding(s,o,n[r]);return __setModuleDefault(s,o),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(o){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,r,e)=>(0,messaging_2.sendClaudeResponseToDing)(this,s,n,r,e),this.parseClaudeStreamLine=claude_process_1.parseClaudeStreamLine,this.interruptClaudeProcess=(s,n)=>(0,claude_process_1.interruptClaudeProcess)(s,n),this.executeClaudeQuery=(s,n,r)=>(0,claude_process_1.executeClaudeQuery)(this,s,n,r),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,r,e,c)=>(0,session_1.switchToSession)(this,s,n,r,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=o,this.config=(0,session_1.getClientConfig)(this);try{this.dingStreamClient=new utils_ok_1.DingStreamClient({clientId:o,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(o,s,n){return this.isOwner(n)?!0:(await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async requireOwnerOrSingleChat(o,s,n,r){return this.isOwner(n)||r?.conversationType==="1"?!0:(await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async handleAuthRequest(o){const{senderStaffId:s,senderNick:n,conversationId:r,conversationType:e,conversationTitle:c,sessionWebhook:a}=o;if(!this.config.ownerConversationId){await this.sendDingMessage({conversationId:r,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:** \`${r}\``,`- **\u6CE8\u518C\u547D\u4EE4:** \`/cfg --conversationId ${r}\``].join(`
|
|
2
|
+
`),msgType:"markdown"});return}for(const k of this.pendingAuthRequests.values())if(k.senderStaffId===s&&k.conversationId===r){await this.sendDingMessage({conversationId:r,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)}`,u={id:g,senderStaffId:s,senderNick:n,conversationId:r,conversationType:e,conversationTitle:c,requestTime:Date.now()};this.pendingAuthRequests.set(g,u),console.log(`[${(0,session_1.timestamp)()}] \u65B0\u6388\u6743\u7533\u8BF7: id=${g}, userId=${s}, \u6635\u79F0=${n}, \u4F1A\u8BDD=${r}`);const v=["\u{1F4CB} **\u6536\u5230\u6388\u6743\u7533\u8BF7**",`- **\u7528\u6237ID:** ${s}`,`- **\u6635\u79F0:** ${n}`,`- **\u4F1A\u8BDDID:** ${r}`,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:r,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:r,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(o,s){const{conversationId:n,sessionWebhook:r,senderStaffId:e,senderNick:c,conversationConfig:a}=s;switch(o.type){case"list":{const g=await this.getOrCreateLogSession(n,r,e,c,a,!0),u=this.cronEngine.listJobs(n);g.sessionDir&&(this.appendSessionLog(g.sessionDir,"user","/cron list"),this.appendSessionLog(g.sessionDir,"assistant",`\u5217\u51FA ${u.length} \u4E2A\u5B9A\u65F6\u4EFB\u52A1`)),await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:(0,cron_1.formatCronJobList)(u),msgType:"markdown"});return}case"delete":{const g=this.cronEngine.removeJob(o.id),u=await this.getOrCreateLogSession(n,r,e,c,a);u.sessionDir&&(this.appendSessionLog(u.sessionDir,"user",`/cron delete ${o.id}`),this.appendSessionLog(u.sessionDir,"assistant",g?`\u5220\u9664\u5B9A\u65F6\u4EFB\u52A1 ${o.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${o.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:g?`\u2705 \u5B9A\u65F6\u4EFB\u52A1 **${o.id}** \u5DF2\u5220\u9664`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${o.id}`,msgType:"markdown"});return}case"pause":{const g=this.cronEngine.toggleJob(o.id,!1),u=await this.getOrCreateLogSession(n,r,e,c,a);u.sessionDir&&(this.appendSessionLog(u.sessionDir,"user",`/cron pause ${o.id}`),this.appendSessionLog(u.sessionDir,"assistant",g?`\u6682\u505C\u5B9A\u65F6\u4EFB\u52A1 ${o.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${o.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:g?`\u23F8\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${o.id}** \u5DF2\u6682\u505C`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${o.id}`,msgType:"markdown"});return}case"resume":{const g=this.cronEngine.toggleJob(o.id,!0),u=await this.getOrCreateLogSession(n,r,e,c,a);u.sessionDir&&(this.appendSessionLog(u.sessionDir,"user",`/cron resume ${o.id}`),this.appendSessionLog(u.sessionDir,"assistant",g?`\u6062\u590D\u5B9A\u65F6\u4EFB\u52A1 ${o.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${o.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:g?`\u25B6\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${o.id}** \u5DF2\u6062\u590D`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${o.id}`,msgType:"markdown"});return}case"create_cron":{if(!(0,cron_1.isValidCronExpression)(o.cronExpression)){await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:`\u274C \u65E0\u6548\u7684cron\u8868\u8FBE\u5F0F: \`${o.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,r);return}const g=this.cronEngine.addJob({conversationId:n,cronExpression:o.cronExpression,description:this.sanitizeLogContent(o.prompt.substring(0,50)),prompt:o.prompt,senderStaffId:e,senderNick:c}),u=await this.getOrCreateLogSession(n,r,e,c,a);u.sessionDir&&(this.appendSessionLog(u.sessionDir,"user",`/cron ${o.cronExpression} ${this.sanitizeLogContent(o.prompt)}`),this.appendSessionLog(u.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${g.id} [${g.cronExpression}] ${g.description}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:(0,cron_1.formatCronJobInfo)(g),msgType:"markdown"});return}case"create_nl":{if(!this.hasNotifyCapability(s.conversationConfig)){await this.sendCronNoNotifyError(n,r);return}await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:"\u23F3 \u6B63\u5728\u5206\u6790\u5B9A\u65F6\u4EFB\u52A1\u63CF\u8FF0..."});const g=await this.cronEngine.analyzeAndCreate(n,o.input,e,c),u=await this.getOrCreateLogSession(n,r,e,c,a);g.job?(u.sessionDir&&(this.appendSessionLog(u.sessionDir,"user",`/cron ${this.sanitizeLogContent(o.input)}`),this.appendSessionLog(u.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${g.job.id} [${g.job.cronExpression}] ${g.job.description}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:r,content:(0,cron_1.formatCronJobInfo)(g.job),msgType:"markdown"})):(u.sessionDir&&(this.appendSessionLog(u.sessionDir,"user",`/cron ${this.sanitizeLogContent(o.input)}`),this.appendSessionLog(u.sessionDir,"assistant",`\u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${g.error}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:r,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(o){return o.replace(/\n/g,"\\n").replace(/\r/g,"\\r")}sanitizeOutput(o){const s=o.replace(/\r\n/g,`
|
|
8
|
+
`),n=8e3;return s.length>n?s.substring(0,n)+`
|
|
9
|
+
...(\u8F93\u51FA\u5DF2\u622A\u65AD)`:s}truncateMsg(o,s=100){const n=o.replace(/\n/g," ").trim();return n.length>s?n.slice(0,s)+"...":n}async getOrCreateLogSession(o,s,n,r,e,c=!1){const a=this.findActiveSession(o);if(a)return{sessionDir:this.getSessionDir(a.session.session),isNew:!1};if(c)return{sessionDir:null,isNew:!1};const g=Date.now(),u={conversationId:o,sessionWebhook:s,startTime:g,startTimeStr:utils_ok_1.dateUtil.mm(g).format("YYYY-MM-DD-HH-mm-ss"),startStaffId:n,startNickName:`[cron]${r}`},v=this.getSessionDir(u);return fs_1.default.mkdirSync(v,{recursive:!0}),fs_1.default.writeFileSync(`${v}/session.json`,JSON.stringify(u,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(o){return!!(o.dingToken||this.config.defaultDingToken)}async sendCronNoNotifyError(o,s){await this.sendDingMessage({conversationId:o,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(o,s){const n=this.getConversationDir(o);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 r=path_1.default.resolve(n,s);return r.startsWith(n)?{absolutePath:r}:{absolutePath:"",error:"\u274C \u8DEF\u5F84\u8D85\u51FA\u5DE5\u4F5C\u76EE\u5F55\u8303\u56F4"}}async handleMkdirCommand(o,s,n){const{absolutePath:r,error:e}=this.resolveAndValidatePath(o,n);if(e){await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:e,msgType:"markdown"});return}try{fs_1.default.statSync(r).isDirectory()?await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:`\u26A0\uFE0F \u76EE\u5F55\u5DF2\u5B58\u5728: \`${n}\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:`\u274C \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u76EE\u5F55: \`${n}\``,msgType:"markdown"});return}catch{}try{fs_1.default.mkdirSync(r,{recursive:!0}),await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:`\u2705 \u76EE\u5F55\u521B\u5EFA\u6210\u529F: \`${n}\``,msgType:"markdown"})}catch(c){await this.sendDingMessage({conversationId:o,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(o,s,n){const{absolutePath:r,error:e}=this.resolveAndValidatePath(o,n);if(e){await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:e,msgType:"markdown"});return}let c;try{c=fs_1.default.statSync(r)}catch{await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:`\u274C \u8DEF\u5F84\u4E0D\u5B58\u5728: \`${n}\``,msgType:"markdown"});return}const a=c.isDirectory();try{a?fs_1.default.rmSync(r,{recursive:!0,force:!0}):fs_1.default.unlinkSync(r),await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:`\u2705 \u5DF2\u5220\u9664${a?"\u76EE\u5F55":"\u6587\u4EF6"}: \`${n}\``,msgType:"markdown"})}catch(g){await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:`\u274C \u5220\u9664\u5931\u8D25: \`${n}\`
|
|
12
|
+
\u539F\u56E0: ${g instanceof Error?g.message:String(g)}`,msgType:"markdown"})}}async handleTouchCommand(o,s,n){const{absolutePath:r,error:e}=this.resolveAndValidatePath(o,n);if(e){await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:e,msgType:"markdown"});return}try{const c=fs_1.default.statSync(r);c.isFile()?await this.sendDingMessage({conversationId:o,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:o,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(r);fs_1.default.mkdirSync(c,{recursive:!0}),fs_1.default.writeFileSync(r,"","utf-8"),await this.sendDingMessage({conversationId:o,sessionWebhook:s,content:`\u2705 \u6587\u4EF6\u521B\u5EFA\u6210\u529F: \`${n}\``,msgType:"markdown"})}catch(c){await this.sendDingMessage({conversationId:o,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(o){this.dingStreamClient.socketCallBackResponse(o.headers.messageId,"");const s=JSON.parse(o.data),{senderNick:n,senderStaffId:r,conversationId:e,conversationTitle:c,sessionWebhook:a,msgtype:g,conversationType:u}=s,v=s.text?.content?.trim()??"";if(this.debugLog(`\u6536\u5230\u6D88\u606F: \u7FA4=${c}(${e}), \u53D1\u9001\u8005=${n}(${r}), \u7C7B\u578B=${g}, \u5185\u5BB9=${v.substring(0,50)}`),!this.authCheck(r,e)){await this.handleAuthRequest({senderStaffId:r,senderNick:n,conversationId:e,conversationType:u,conversationTitle:s.conversationTitle,sessionWebhook:a});return}const w=this.getConversationConfig(e),k=(0,commands_1.parseRecorderCommand)(v);if(k!==null){if(!this.isOwner(r)||u!=="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 l;if(g==="picture"&&s.pictureDownloadCode){const t=this.getConversationDir(e),i=w?.useLocalOcr!==!1,d=await(0,image_1.processPictureMessage)(this,s.pictureDownloadCode,s.robotCode,t,i,v||void 0);if(!d){await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:r,content:"\u26A0\uFE0F \u56FE\u7247\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u4F7F\u7528\u6587\u5B57\u63CF\u8FF0"});return}l=d}else if(g==="richText"&&s.content?.richText){const t=this.getConversationDir(e),i=w?.useLocalOcr!==!1;l=await(0,image_1.processRichTextMessage)(this,s.content.richText,s.robotCode,t,i)}else if(g==="file"){const t=(0,image_1.extractDownloadCode)(s);if(t){const i=this.getConversationDir(e),d=await(0,image_1.processFileMessage)(this,t,s.robotCode,i,v||void 0);if(!d){await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:r,content:"\u26A0\uFE0F \u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"});return}l=d}else{await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:r,content:"\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6\u6587\u4EF6\u4E0B\u8F7D\u94FE\u63A5\uFF0C\u8BF7\u91CD\u65B0\u53D1\u9001"});return}}else{if(l=v,!l){const t=(0,quote_1.extractQuoteInfo)(s);if(t){if(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F(\u65E0\u6B63\u6587): quoteMessageId=${t.quoteMessageId}`),t.quoteMessageId&&!t.quoteText){const i=await(0,messaging_1.fetchQuotedMessage)(this,t.quoteMessageId);i&&(t.quoteText=i)}t.quoteText&&(l=(0,quote_1.formatPromptWithQuote)("",t))}}if(!l)return}if(!l.startsWith("/")&&g==="text"&&v){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 i=await(0,messaging_1.fetchQuotedMessage)(this,t.quoteMessageId);i&&(t.quoteText=i)}t.quoteText&&(l=(0,quote_1.formatPromptWithQuote)(l,t))}}const h=(0,commands_1.parseCfgCommand)(l);if(h!==null){if(h.conversationId&&!this.isOwner(r)){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,r,w))return;const t=h.conversationId||e,i=t!==e,d=i?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),u&&!i&&(d.conversationType=u),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:i?"1":u,conversationTitle:h.conversationTitle||(i?"":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 y=this.getConversationDir(t);fs_1.default.existsSync(y)||(fs_1.default.mkdirSync(y,{recursive:!0}),console.log(`[${(0,session_1.timestamp)()}] \u521B\u5EFA\u5DE5\u4F5C\u76EE\u5F55: ${y}`));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:** ${y}`),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)(l)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:(0,commands_1.formatHelpOverview)(TOOL_VERSION,this.isOwner(r)),msgType:"markdown"});return}if((0,commands_1.parseVersionCommand)(l)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`**\u7248\u672C:** ${TOOL_VERSION}`,msgType:"markdown"});return}const M=(0,commands_1.parseCommandHelp)(l);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(r)?await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:r,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:r,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)(l);if(I!==null){if(I==="all"&&w?.conversationType!=="1"&&!this.isOwner(r)){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,r,w))return;const t=I==="all"?null:e,i=this.cleanCache(t,!0),d=[];d.push("\u{1F9F9} \u7F13\u5B58\u6E05\u7406\u5B8C\u6210"),i.sessionsDeleted>0&&d.push(`- \u4F1A\u8BDD\u76EE\u5F55: ${i.sessionsDeleted} \u4E2A`),i.tasksDeleted>0&&d.push(`- \u4EFB\u52A1\u76EE\u5F55: ${i.tasksDeleted} \u4E2A`),i.imagesDeleted>0&&d.push(`- \u56FE\u7247\u6587\u4EF6: ${i.imagesDeleted} \u4E2A`),i.sessionsDeleted===0&&i.tasksDeleted===0&&i.imagesDeleted===0&&d.push("(\u65E0\u5386\u53F2\u6570\u636E)"),d.push(`
|
|
22
|
+
\u{1F4A1} \u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u4FDD\u7559`),i.errors.length>0&&d.push(`
|
|
23
|
+
\u26A0\uFE0F \u9519\u8BEF: ${i.errors.join("; ")}`),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:d.join(`
|
|
24
|
+
`),msgType:"markdown"});return}if((0,commands_1.parseResetApiKeyCfgCommand)(l)){if(!await this.requireOwner(e,a,r))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(i=>i.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 D=(0,commands_1.parseAuthCommand)(l);if(D){if(!await this.requireOwner(e,a,r))return;if(D.type==="approve"||D.type==="reject"){const i=this.pendingAuthRequests.get(D.requestId);if(!i){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u274C \u672A\u627E\u5230\u6388\u6743\u7533\u8BF7: ${D.requestId}`,msgType:"markdown"});return}if(this.pendingAuthRequests.delete(D.requestId),D.type==="approve"){let d=this.config.conversations.find(p=>p.conversationId===i.conversationId);d||(d={conversationId:i.conversationId,conversationType:i.conversationType||"1",conversationTitle:i.conversationTitle},this.config.conversations.push(d)),d.whiteUserList||(d.whiteUserList=[]),d.whiteUserList.includes(i.senderStaffId)||d.whiteUserList.push(i.senderStaffId),(0,api_key_manager_1.saveClientConfig)(this),console.log(`[${(0,session_1.timestamp)()}] \u6388\u6743\u7533\u8BF7\u901A\u8FC7\u5C06: id=${D.requestId}, userId=${i.senderStaffId}`),await(0,messaging_1.sendMessageToUser)(this,i.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:** ${i.senderStaffId}
|
|
28
|
+
- **\u6635\u79F0:** ${i.senderNick}
|
|
29
|
+
- **\u4F1A\u8BDDID:** ${i.conversationId}`,msgType:"markdown"})}else console.log(`[${(0,session_1.timestamp)()}] \u6388\u6743\u7533\u8BF7\u62D2\u7EDD: id=${D.requestId}, userId=${i.senderStaffId}`),await(0,messaging_1.sendMessageToUser)(this,i.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:** ${i.senderStaffId}
|
|
31
|
+
- **\u6635\u79F0:** ${i.senderNick}`,msgType:"markdown"});return}const t=w.whiteUserList;if(D.type==="list"){const i=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
|
+
${i}`,msgType:"markdown"});return}if(D.type==="add"){let i=D.staffId;if((0,session_1.isMobile)(D.staffId)&&(i=await(0,session_1.resolveUserId)(this,D.staffId),!i)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${D.staffId}`,msgType:"markdown"});return}if(t?.some(m=>(0,session_1.resolveToUserId)(this,m)===i)){const m=(0,session_1.userIdToPhone)(this,i)||i;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(D.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}),y=(0,session_1.isMobile)(D.staffId)?D.staffId:(0,session_1.userIdToPhone)(this,D.staffId)||D.staffId;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u6DFB\u52A0 ${y} \u5230\u5F53\u524D\u7FA4\u767D\u540D\u5355
|
|
34
|
+
\u5F53\u524D\u767D\u540D\u5355: ${p.join(", ")}`,msgType:"markdown"});return}if(D.type==="del"){let i=D.staffId;if((0,session_1.isMobile)(D.staffId)&&(i=await(0,session_1.resolveUserId)(this,D.staffId),!i)){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${D.staffId}`,msgType:"markdown"});return}const d=t?.findIndex(f=>(0,session_1.resolveToUserId)(this,f)===i)??-1;if(d<0){const f=(0,session_1.userIdToPhone)(this,i)||i;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 y=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,i)||p;await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u2705 \u5DF2\u79FB\u9664 ${m}
|
|
35
|
+
\u5F53\u524D\u767D\u540D\u5355: ${y}`,msgType:"markdown"});return}}const L=(0,commands_1.parseOpenCommand)(l);if(L!==null){if(!await this.requireOwner(e,a,r))return;const t=this.getConversationDir(e),{exec:i}=await Promise.resolve().then(()=>__importStar(require("child_process"))),d=process.platform;try{L==="folder"?(i(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"?i("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}i(`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"?i(`open -a Terminal "${t}"`):i(`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 q=(0,commands_1.parseCronCommand)(l);if(q){await this.handleCronCommand(q,{conversationId:e,sessionWebhook:a,senderStaffId:r,senderNick:n,conversationConfig:w});return}if((0,commands_1.parsePwdCommand)(l)){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 O=(0,commands_1.parseMkdirCommand)(l);if(O!==null){await this.handleMkdirCommand(e,a,O);return}const A=(0,commands_1.parseTouchCommand)(l);if(A!==null){await this.handleTouchCommand(e,a,A);return}const P=(0,commands_1.parseRmCommand)(l);if(P!==null){await this.handleRmCommand(e,a,P);return}const U=(0,commands_1.parseBashCommand)(l);if(U!==null){const t=this.getConversationDir(e),i=[];this.config.preBash&&i.push(this.config.preBash),w?.preBash&&i.push(w.preBash);const d=i.length>0?`${i.join(" ; ")} ; ${U}`:U,p=this;(0,child_process_1.exec)(d,{cwd:t,timeout:3e4,maxBuffer:1024*1024},async(y,m,f)=>{try{let C;if(y)C=`\u274C \u547D\u4EE4\u6267\u884C\u5931\u8D25
|
|
48
|
+
\`\`\`
|
|
49
|
+
${y.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(l)){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 i=l.replace(/^\/new\s*/i,"").trim();i?await this.startNewSession({conversationId:e,sessionWebhook:a,senderStaffId:r,senderNick:n,message:i,conversationConfig:w}):await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:r,content:"\u{1F680} \u8BF7\u8F93\u5165\u60A8\u7684\u95EE\u9898\u5F00\u59CB\u65B0\u4F1A\u8BDD"});return}const E=(0,commands_1.parseContinueSessionCommand)(l);if(E!==null&&w){let t=E;if(!t){const i=(0,session_1.findLatestSession)(this,e);if(!i){await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:r,content:"\u26A0\uFE0F \u672A\u627E\u5230\u5DF2\u7ED3\u675F\u7684\u4F1A\u8BDD",msgType:"markdown"});return}t=(0,session_1.getSessionId)(i)}await this.switchToSession(e,a,t,r,w);return}const _=(0,commands_1.parseLogCommand)(l);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)(l);if(S!==null){const t=[],i=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),i))),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 x=(0,commands_1.parseLsCommand)(l);if(x!==null){const{target:t,depth:i}=x,d=this.getConversationDir(e);let p=d,y="\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,y=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,y=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,i);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4C2} ${y} (\u5C55\u5F00${i}\u5C42):
|
|
74
|
+
\`\`\`
|
|
75
|
+
${m}
|
|
76
|
+
\`\`\``,msgType:"markdown"});return}const N=(0,task_1.parseTaskCancelCommand)(l);if(N){const t=this.cancelTask(N,e);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:t,msgType:"markdown"});return}if(l.startsWith("/task ")){const t=l.substring(6).trim();t&&(await this.sendDingMessage({conversationId:e,sessionWebhook:a,atUserId:r,content:"\u{1F4CB} \u4EFB\u52A1\u5DF2\u6536\u5230,\u5B8C\u6210\u540E\u6211\u4F1A\u56DE\u590D"}),await this.saveTask({conversationId:e,prompt:t,senderStaffId:r,senderNickName:n,sessionWebhook:a}));return}const b=(0,commands_1.parseMqCommand)(l);if(b){const i=this.findActiveSession(e)?.session.messageQueue??[];switch(b.type){case"list":{if(i.length===0)await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});else{const d=i.map((p,y)=>`${y+1}. **${p.senderNick||p.senderStaffId}:** ${this.truncateMsg(p.message)}`);await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:`\u{1F4E8} \u6D88\u606F\u961F\u5217 (${i.length} \u6761)
|
|
77
|
+
${d.join(`
|
|
78
|
+
`)}`,msgType:"markdown"})}return}case"cancel":{if(i.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(b.count,i.length),y=i.splice(i.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
|
+
${y.join(`
|
|
80
|
+
`)}`,msgType:"markdown"});return}case"cancelAll":{if(i.length===0){await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}const d=i.length;i.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)(l)){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`),t.interrupted=!0,t.currentProcess.kill("SIGINT"),await this.sendDingMessage({conversationId:e,sessionWebhook:a,content:"\u{1F504} \u6B63\u5728\u91CD\u542F Claude \u8FDB\u7A0B..."}),t.goonPending=!1,t.isProcessing=!0;try{await(0,claude_process_1.executeClaudeQuery)(this,t.session,"\u7EE7\u7EED",{senderNick:t.session.startNickName,senderStaffId:t.lastSenderStaffId})}finally{t.isProcessing=!1}}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:r})}finally{t.isProcessing=!1}}return}const R=(0,commands_1.parseCcCommand)(l);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:r})}finally{t.isProcessing=!1}return}if((0,commands_1.parseClaudeMdCommand)(l)){const t=this.getConversationDir(e),i=path_1.default.join(t,".claude","CLAUDE.md");if(fs_1.default.existsSync(i)){const d=fs_1.default.readFileSync(i,"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: \`${i}\``,msgType:"markdown"});return}await this.handleSessionMessage({conversationId:e,sessionWebhook:a,senderStaffId:r,senderNick:n,message:l,conversationConfig:w})}async run(){const o=Array.isArray(this.config.conversations)?this.config.conversations:[],s=this.config.taskHandlerCount??this.DEFAULT_TASK_HANDLER_COUNT,n=o.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: ${o.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 r=[];if(n)for(let c=0;c<s;c++)console.log(`[${(0,session_1.timestamp)()}] \u542F\u52A8\u4EFB\u52A1\u5904\u7406\u5668 #${c+1}`),r.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,...r])}}exports.DingClaude=DingClaude;
|
|
@@ -1 +1,39 @@
|
|
|
1
|
-
'use strict';const a3_0x296b7e=a3_0x4d0a;(function(_0x51455f,_0x524c0f){const _0x135bf4=a3_0x4d0a,_0x5322c5=_0x51455f();while(!![]){try{const _0x512d8e=parseInt(_0x135bf4(0x1ab))/0x1+-parseInt(_0x135bf4(0x1b9))/0x2*(parseInt(_0x135bf4(0x19e))/0x3)+-parseInt(_0x135bf4(0x182))/0x4+-parseInt(_0x135bf4(0x1ae))/0x5*(parseInt(_0x135bf4(0x195))/0x6)+-parseInt(_0x135bf4(0x112))/0x7+parseInt(_0x135bf4(0x187))/0x8*(parseInt(_0x135bf4(0x172))/0x9)+parseInt(_0x135bf4(0x1a5))/0xa*(parseInt(_0x135bf4(0x1bc))/0xb);if(_0x512d8e===_0x524c0f)break;else _0x5322c5['push'](_0x5322c5['shift']());}catch(_0x209236){_0x5322c5['push'](_0x5322c5['shift']());}}}(a3_0x3a88,0xc105b));var __importDefault=this&&this['__importDefault']||function(_0x23e370){return _0x23e370&&_0x23e370['__esModule']?_0x23e370:{'default':_0x23e370};};Object['defineProperty'](exports,a3_0x296b7e(0x141),{'value':!![]}),exports['resolveClaudeSettingsPath']=resolveClaudeSettingsPath,exports['isRetryableApiError']=isRetryableApiError,exports[a3_0x296b7e(0x19b)]=parseClaudeStreamLine,exports[a3_0x296b7e(0x12d)]=interruptClaudeProcess,exports['executeClaudeQuery']=executeClaudeQuery;const fs_1=__importDefault(require('fs')),path_1=__importDefault(require('path')),readline_1=__importDefault(require(a3_0x296b7e(0x1af))),child_process_1=require('child_process'),messaging_1=require(a3_0x296b7e(0x163)),session_1=require('./session'),api_key_manager_1=require(a3_0x296b7e(0x128)),MAX_FAST_FAIL=0x14,API_RETRY_DELAY_MS=0x2710,FAST_FAIL_THRESHOLD_MS=0x2710;function resolveClaudeSettingsPath(_0x548b3f,_0x9babb6,_0x16dca6){const _0x5767e7=a3_0x296b7e,_0x53a933=(0x0,api_key_manager_1[_0x5767e7(0x171)])(_0x9babb6);if(_0x53a933)return _0x53a933;if(_0x548b3f[_0x5767e7(0x119)][_0x5767e7(0x133)]){const _0x4eaa0e=(0x0,api_key_manager_1['readApiKeyFromSettings'])(_0x9babb6);let _0x5a410c=null;_0x4eaa0e&&(_0x5a410c=_0x548b3f[_0x5767e7(0x119)][_0x5767e7(0x133)][_0x5767e7(0x18a)][_0x5767e7(0x1b1)](_0x5572d2=>_0x5572d2[_0x5767e7(0x1b2)]===_0x4eaa0e&&_0x5572d2['isValid'])||null);!_0x5a410c&&(_0x5a410c=(0x0,api_key_manager_1['pickValidApiKey'])(_0x548b3f));if(_0x5a410c)return(0x0,api_key_manager_1['ensureSettingsWithApiKey'])(_0x9babb6,_0x5a410c);}if(_0x548b3f[_0x5767e7(0x119)][_0x5767e7(0x133)])return undefined;if(_0x16dca6)return _0x16dca6;const _0x1fbb1f=path_1['default'][_0x5767e7(0x130)](_0x9babb6,_0x5767e7(0x199),_0x5767e7(0x1b5));if(fs_1[_0x5767e7(0x16f)][_0x5767e7(0x115)](_0x1fbb1f))return console['log']('['+(0x0,session_1[_0x5767e7(0x138)])()+_0x5767e7(0x12a)+_0x1fbb1f),_0x1fbb1f;return undefined;}function a3_0x3a88(){const _0x22a13e=['lastSenderStaffId','content','output','.claude','subtype','parseClaudeStreamLine','SIGINT','command','3KXxRmD','push','input',']\x20[SYSTEM]:\x20TPM\x20限流,','\x20(重试)','settingLabel','权限不足','10VmnJoe','description','getSessionDir','system','user','trim','1292839zwGtFq','permission_required','Claude\x20进程退出,代码:\x20','281330rpizKY','readline','toString','find','apiKey','--verbose','init','settings.json','requests\x20per\x20minute','catch','isFastFail','1283038TSaWdX','Claude\x20stdout:\x20','需要授权','14930949dGjxxV','isAuthenticationError','3459197XcMHhP','some','--resume','existsSync','--permission-mode',']\x20用户主动中断,忽略错误',']\x20检测到认证错误(401),通知用户','config','claudeSessionId','/session.log','rotateApiKey','session_id',']\x20[ERROR]:\x20','currentProcess','now',']\x20执行\x20Claude\x20查询[原生claude\x20模式]:\x20','overloaded','stringify','log','没有权限',']\x20TPM\x20限流连续快速失败\x20','prompt','./api-key-manager','TPM\x20限流,快速失败连续\x20',']\x20自动检测到\x20settings.json:\x20','stdout','not\x20authorized','interruptClaudeProcess','utf-8','conversationId','join','authorize','warn','apiKeyCfg','assistant',']\x20检测到\x20TPM\x20限流(快速失败),','thinking','tokens\x20per\x20minute','timestamp',']\x20Claude\x20返回了空的\x20result\x20且\x20responseBuffer\x20也为空,无内容可发送','error','length','tool_use',']\x20[SYSTEM]:\x20Claude\x20查询启动',']\x20TPM\x20限流快速失败连续','claude','includes','__esModule','requires\x20permission','spawn','getReplyWebhook',']\x20[SYSTEM]:\x20Claude\x20会话已失效,清除旧会话并重新发起\x0a',']\x20发送\x22继续\x22重试\x20(快速失败连续','kill','appendSessionLog','activeSessions','settings','close','tool','too\x20many\x20requests','result','toLowerCase','stderr','getConversationDir','permission\x20denied','\x0a```','发送钉钉消息失败:',']\x20Claude\x20进程退出,代码:\x20','write','readApiKeyFromSettings','message','parse',']\x20[WARN]:\x20','capacity','--agent','type','appendFileSync','rpm\x20limit','mkdirSync','has','RetryableApiError','./messaging','⚠️\x20Claude\x20需要授权,请人工介入',']\x20Claude\x20会话已失效:\x20','data','ratelimit','line','text','isArray','file_path',']\x20检测到需要授权,通知用户','sendClaudeResponseToDing','Claude\x20进程错误:','default','createInterface','getForceEnabledSettingsPath','9FMFBao','⚠️\x20认证失败(401),API\x20Key\x20无效或服务未授权,请检查配置','ConversationNotFoundError','--output-format','includeThinking','发送消息:\x20','debugLog','stream-json','pipe','s\x20后重试\x0a','...',']\x20[SYSTEM]:\x20API\x20Key\x20配额耗尽(429),切换到新\x20Key\x0a','bypassPermissions','test','query','Retryable\x20API\x20error\x20(TPM\x20limit\x20etc.)','24984FYUJMN','⚠️\x20Claude\x20处理完成但未返回任何内容,请重试或换种方式提问','isQuotaExhaustedError','sessionId','interrupted','1460904zXUROV','startStaffId','getReplyConversationId','claudeSettings','pattern','add','access\x20denied','get','substring','unknown','needs\x20permission','sendDingMessage',']\x20从\x20settings-ding.json\x20恢复\x20Claude\x20Setting:\x20',']\x20Claude\x20进程正常退出但未产生任何回复内容','96MApDuz'];a3_0x3a88=function(){return _0x22a13e;};return a3_0x3a88();}function a3_0x4d0a(_0x2bb193,_0x578fe2){_0x2bb193=_0x2bb193-0x111;const _0x3a8877=a3_0x3a88();let _0x4d0a0e=_0x3a8877[_0x2bb193];return _0x4d0a0e;}function isRetryableApiError(_0x1be766){const _0xb89e94=a3_0x296b7e;if(/\b429\b/[_0xb89e94(0x17f)](_0x1be766)&&!(0x0,api_key_manager_1[_0xb89e94(0x184)])(_0x1be766))return!![];if(/API\s*Error.*422/i['test'](_0x1be766))return!![];if(/\b422\b.*(?:TPM|额度超限|rate\s*limit|tokens?\s*per\s*minute)/i['test'](_0x1be766))return!![];if(/(?:TPM|额度超限).*\b422\b/i['test'](_0x1be766))return!![];const _0x11f469=_0x1be766['toLowerCase'](),_0x34b850=['rate\x20limit','rate_limit',_0xb89e94(0x167),_0xb89e94(0x14d),_0xb89e94(0x137),_0xb89e94(0x1b6),_0xb89e94(0x15f),_0xb89e94(0x122),_0xb89e94(0x15b),'temporarily\x20unavailable'];return _0x34b850['some'](_0x27c5cd=>_0x11f469[_0xb89e94(0x140)](_0x27c5cd));}function sleep(_0x32adb5){return new Promise(_0x2b79a7=>setTimeout(_0x2b79a7,_0x32adb5));}class RetryableApiError extends Error{constructor(_0x4b72ec,_0x2b9749=''){const _0x594ac1=a3_0x296b7e;super(_0x594ac1(0x181)+(_0x4b72ec?'\x20[fast\x20fail]':'')),this['name']=_0x594ac1(0x162),this['isFastFail']=_0x4b72ec,this[_0x594ac1(0x198)]=_0x2b9749;}}class ConversationNotFoundError extends Error{constructor(){const _0x48e856=a3_0x296b7e;super('Claude\x20conversation\x20not\x20found'),this['name']=_0x48e856(0x174);}}function isPermissionError(_0x56e3ae){const _0x2b9204=a3_0x296b7e,_0x13849b=_0x56e3ae[_0x2b9204(0x14f)](),_0x49b9b0=[_0x2b9204(0x152),_0x2b9204(0x1ac),_0x2b9204(0x191),_0x2b9204(0x142),'authorization\x20required',_0x2b9204(0x131),_0x2b9204(0x12c),_0x2b9204(0x18d),_0x2b9204(0x1bb),_0x2b9204(0x1a4),_0x2b9204(0x125)];return _0x49b9b0[_0x2b9204(0x113)](_0x507657=>_0x13849b[_0x2b9204(0x140)](_0x507657));}function isConversationNotFoundError(_0x5eeb23){const _0x59bb51=a3_0x296b7e;return/no conversation found with session id/i[_0x59bb51(0x17f)](_0x5eeb23);}function parseClaudeStreamLine(_0x2e4617,_0x45a4a0=![]){const _0x211b40=a3_0x296b7e;if(!_0x2e4617[_0x211b40(0x1aa)]())return null;try{const _0x29e78d=JSON[_0x211b40(0x159)](_0x2e4617);if(_0x29e78d[_0x211b40(0x15d)]==='system'&&_0x29e78d[_0x211b40(0x19a)]===_0x211b40(0x1b4)&&_0x29e78d[_0x211b40(0x11d)])return{'type':_0x211b40(0x1a8),'sessionId':_0x29e78d[_0x211b40(0x11d)]};if(_0x29e78d[_0x211b40(0x15d)]===_0x211b40(0x134)){const _0xac971a=_0x29e78d[_0x211b40(0x158)]?.['content'];if(Array['isArray'](_0xac971a)){const _0x1c0027=[];for(const _0x47137e of _0xac971a){if(_0x47137e[_0x211b40(0x15d)]==='text'&&_0x47137e['text'])_0x1c0027[_0x211b40(0x19f)](_0x47137e[_0x211b40(0x169)]);else _0x47137e[_0x211b40(0x15d)]===_0x211b40(0x136)&&_0x47137e[_0x211b40(0x136)]&&_0x45a4a0&&_0x1c0027[_0x211b40(0x19f)]('💭\x20**思考过程**\x0a```\x0a'+_0x47137e[_0x211b40(0x136)]+_0x211b40(0x153));}if(_0x1c0027[_0x211b40(0x13b)]>0x0)return{'type':_0x211b40(0x134),'content':_0x1c0027[_0x211b40(0x130)]('\x0a')};}else{if(_0x29e78d[_0x211b40(0x197)])return{'type':'assistant','content':typeof _0x29e78d[_0x211b40(0x197)]==='string'?_0x29e78d[_0x211b40(0x197)]:JSON[_0x211b40(0x123)](_0x29e78d[_0x211b40(0x197)])};}return{'type':'assistant'};}if(_0x29e78d[_0x211b40(0x15d)]==='result'){const _0x364298=_0x29e78d[_0x211b40(0x14e)]||'';return{'type':_0x211b40(0x14e),'content':typeof _0x364298==='string'?_0x364298:JSON[_0x211b40(0x123)](_0x364298)};}return{'type':_0x29e78d[_0x211b40(0x15d)]||'unknown'};}catch{return{'type':_0x211b40(0x169),'content':_0x2e4617};}}function interruptClaudeProcess(_0x413ee7,_0x34c327){const _0x3bba5e=a3_0x296b7e;if(!_0x413ee7[_0x3bba5e(0x11f)])return![];return console[_0x3bba5e(0x124)]('['+(0x0,session_1[_0x3bba5e(0x138)])()+']\x20'+_0x34c327),_0x413ee7[_0x3bba5e(0x186)]=!![],_0x413ee7[_0x3bba5e(0x11f)][_0x3bba5e(0x147)](_0x3bba5e(0x19c)),!![];}function runClaudeOnce(_0x512ffa,_0x5ecd05,_0x460e32,_0x1effd8,_0x2dd3b0,_0x10aa34,_0x40be32){const _0xac5f48=a3_0x296b7e;let _0x839b91=_0x512ffa[_0xac5f48(0x1a7)](_0x5ecd05),_0x3ddd19=_0x839b91+_0xac5f48(0x11b);!fs_1[_0xac5f48(0x16f)][_0xac5f48(0x115)](_0x839b91)&&fs_1[_0xac5f48(0x16f)][_0xac5f48(0x160)](_0x839b91,{'recursive':!![]});const _0x1ae1e5=Date[_0xac5f48(0x120)]();return new Promise((_0xb1d9aa,_0x54d565)=>{const _0x37a9b4=_0xac5f48,_0x2c4b10=(0x0,child_process_1[_0x37a9b4(0x143)])(_0x1effd8,_0x460e32,{'cwd':_0x2dd3b0,'stdio':[_0x37a9b4(0x17a),'pipe',_0x37a9b4(0x17a)]}),_0x7404f4=_0x512ffa['activeSessions'][_0x37a9b4(0x18e)](_0x5ecd05['conversationId']);_0x7404f4&&(_0x7404f4[_0x37a9b4(0x11f)]=_0x2c4b10);fs_1[_0x37a9b4(0x16f)][_0x37a9b4(0x15e)](_0x3ddd19,'['+(0x0,session_1[_0x37a9b4(0x138)])()+_0x37a9b4(0x13d)+(_0x40be32?_0x37a9b4(0x1a2):'')+'\x0a',_0x37a9b4(0x12e)),_0x2c4b10['stdin']?.[_0x37a9b4(0x156)](_0x10aa34+'\x0a'),_0x2c4b10['stdin']?.['end']();let _0x5c8626=!_0x40be32&&!!_0x5ecd05[_0x37a9b4(0x11a)],_0x48fe7f=[],_0x3f1770='',_0x4ea2f1='',_0xc54f86=![];const _0x315011=new Set(),_0x2e8dee=readline_1[_0x37a9b4(0x16f)][_0x37a9b4(0x170)]({'input':_0x2c4b10[_0x37a9b4(0x12b)]});_0x2e8dee['on'](_0x37a9b4(0x168),_0x33c97c=>{const _0xceb9d9=_0x37a9b4;_0x4ea2f1+=_0x33c97c+'\x0a',_0x512ffa[_0xceb9d9(0x178)](_0xceb9d9(0x1ba)+_0x33c97c[_0xceb9d9(0x18f)](0x0,0xc8)+(_0x33c97c[_0xceb9d9(0x13b)]>0xc8?'...':''));if(_0x512ffa['config']['debug'])try{fs_1['default'][_0xceb9d9(0x15e)](_0x3ddd19,'['+(0x0,session_1[_0xceb9d9(0x138)])()+']\x20[RAW]:\x20'+_0x33c97c+'\x0a',_0xceb9d9(0x12e));}catch{}const _0x459f24=parseClaudeStreamLine(_0x33c97c,_0x512ffa[_0xceb9d9(0x119)][_0xceb9d9(0x176)]??![]);if(_0x459f24){_0x459f24[_0xceb9d9(0x15d)]===_0xceb9d9(0x1a8)&&_0x459f24['sessionId']&&!_0x5c8626&&(_0x512ffa['updateSessionFile'](_0x5ecd05,{'claudeSessionId':_0x459f24[_0xceb9d9(0x185)]}),_0x5c8626=!![],_0x839b91=_0x512ffa[_0xceb9d9(0x1a7)](_0x5ecd05),_0x3ddd19=_0x839b91+_0xceb9d9(0x11b));if(_0x459f24[_0xceb9d9(0x15d)]===_0xceb9d9(0x134)){try{const _0x419ff8=JSON[_0xceb9d9(0x159)](_0x33c97c),_0x1b10f8=_0x419ff8?.[_0xceb9d9(0x158)]?.['content'];if(Array[_0xceb9d9(0x16a)](_0x1b10f8))for(const _0x3dd178 of _0x1b10f8){if(_0x3dd178[_0xceb9d9(0x15d)]===_0xceb9d9(0x13c)&&_0x3dd178['id']&&!_0x315011[_0xceb9d9(0x161)](_0x3dd178['id'])){_0x315011[_0xceb9d9(0x18c)](_0x3dd178['id']);const _0x2b1662=_0x3dd178['name']||_0xceb9d9(0x190);let _0xbbc96a='';if(_0x3dd178[_0xceb9d9(0x1a0)]){if(_0x3dd178[_0xceb9d9(0x1a0)][_0xceb9d9(0x19d)])_0xbbc96a=_0x3dd178[_0xceb9d9(0x1a0)][_0xceb9d9(0x19d)][_0xceb9d9(0x18f)](0x0,0xc8);else{if(_0x3dd178[_0xceb9d9(0x1a0)]['file_path'])_0xbbc96a=_0x3dd178[_0xceb9d9(0x1a0)][_0xceb9d9(0x16b)];else{if(_0x3dd178[_0xceb9d9(0x1a0)][_0xceb9d9(0x18b)])_0xbbc96a=_0x3dd178['input']['pattern'];else{if(_0x3dd178[_0xceb9d9(0x1a0)][_0xceb9d9(0x180)])_0xbbc96a=_0x3dd178[_0xceb9d9(0x1a0)]['query'];else{if(_0x3dd178[_0xceb9d9(0x1a0)][_0xceb9d9(0x1a6)])_0xbbc96a=_0x3dd178[_0xceb9d9(0x1a0)]['description'];else{if(_0x3dd178['input'][_0xceb9d9(0x127)])_0xbbc96a=_0x3dd178['input'][_0xceb9d9(0x127)][_0xceb9d9(0x18f)](0x0,0xc8);else _0xbbc96a=JSON['stringify'](_0x3dd178[_0xceb9d9(0x1a0)])[_0xceb9d9(0x18f)](0x0,0xc8);}}}}}}_0x512ffa[_0xceb9d9(0x148)](_0x839b91,_0xceb9d9(0x14c),''+_0x2b1662+(_0xbbc96a?':\x20'+_0xbbc96a:''));}}}catch{}_0x459f24[_0xceb9d9(0x197)]&&_0x48fe7f['push'](_0x459f24['content']);}if(_0x459f24[_0xceb9d9(0x15d)]===_0xceb9d9(0x14e)){const _0x2b809e=_0x512ffa[_0xceb9d9(0x119)]['resultOnly']??!![],_0x5c314f=(_0x459f24['content']||'')[_0xceb9d9(0x1aa)](),_0x4a42f7=_0x48fe7f['join']('\x0a')[_0xceb9d9(0x1aa)](),_0x38ef62=_0x2b809e?_0x5c314f||_0x4a42f7:_0x4a42f7;if(_0x38ef62){try{_0x512ffa[_0xceb9d9(0x148)](_0x839b91,'assistant',_0x38ef62);}catch{}const _0x4680d6=_0x512ffa[_0xceb9d9(0x149)][_0xceb9d9(0x18e)](_0x5ecd05[_0xceb9d9(0x12f)]),_0x11825e=_0x4680d6?.[_0xceb9d9(0x196)]||_0x5ecd05[_0xceb9d9(0x188)];_0xc54f86=!![],(0x0,messaging_1['sendClaudeResponseToDing'])(_0x512ffa,(0x0,session_1['getReplyConversationId'])(_0x5ecd05),(0x0,session_1[_0xceb9d9(0x144)])(_0x5ecd05),_0x11825e,_0x38ef62)[_0xceb9d9(0x1b7)](_0x2d875d=>console['error'](_0xceb9d9(0x154),_0x2d875d));}else console[_0xceb9d9(0x132)]('['+(0x0,session_1['timestamp'])()+_0xceb9d9(0x139));_0x48fe7f=[];}}}),_0x2c4b10[_0x37a9b4(0x150)]?.['on'](_0x37a9b4(0x166),_0x1bed29=>{const _0x12943f=_0x37a9b4,_0x56b6e8=_0x1bed29[_0x12943f(0x1b0)]();_0x3f1770+=_0x56b6e8;if((0x0,api_key_manager_1[_0x12943f(0x184)])(_0x56b6e8)){console[_0x12943f(0x124)]('['+(0x0,session_1[_0x12943f(0x138)])()+']\x20[Claude\x20stderr]\x20配额耗尽错误(429):\x20'+_0x56b6e8['trim']());try{fs_1['default'][_0x12943f(0x15e)](_0x3ddd19,'['+(0x0,session_1[_0x12943f(0x138)])()+']\x20[WARN]:\x20'+_0x56b6e8,_0x12943f(0x12e));}catch{}}else{if(isRetryableApiError(_0x56b6e8)){console[_0x12943f(0x124)]('['+(0x0,session_1['timestamp'])()+']\x20[Claude\x20stderr]\x20可重试API错误(422\x20TPM限流):\x20'+_0x56b6e8[_0x12943f(0x1aa)]());try{fs_1[_0x12943f(0x16f)][_0x12943f(0x15e)](_0x3ddd19,'['+(0x0,session_1[_0x12943f(0x138)])()+_0x12943f(0x15a)+_0x56b6e8,_0x12943f(0x12e));}catch{}}else{console[_0x12943f(0x13a)]('[Claude\x20stderr]:\x20'+_0x56b6e8);try{fs_1[_0x12943f(0x16f)][_0x12943f(0x15e)](_0x3ddd19,'['+(0x0,session_1['timestamp'])()+_0x12943f(0x11e)+_0x56b6e8,_0x12943f(0x12e));}catch{}}}}),_0x2c4b10['on'](_0x37a9b4(0x14b),_0x18c197=>{const _0x259e56=_0x37a9b4;console[_0x259e56(0x124)]('['+(0x0,session_1[_0x259e56(0x138)])()+_0x259e56(0x155)+_0x18c197);try{fs_1['default'][_0x259e56(0x15e)](_0x3ddd19,'['+(0x0,session_1['timestamp'])()+']\x20[SYSTEM]:\x20Claude\x20查询结束,退出码:\x20'+_0x18c197+'\x0a',_0x259e56(0x12e));}catch{}const _0x5703b3=_0x512ffa[_0x259e56(0x149)][_0x259e56(0x18e)](_0x5ecd05[_0x259e56(0x12f)]);_0x5703b3&&(_0x5703b3['currentProcess']=undefined);if(_0x48fe7f['length']>0x0){const _0x15f997=_0x48fe7f[_0x259e56(0x130)]('\x0a')[_0x259e56(0x1aa)]();if(_0x15f997){try{_0x512ffa['appendSessionLog'](_0x839b91,_0x259e56(0x134),_0x15f997);}catch{}const _0x559a16=_0x5703b3?.['lastSenderStaffId']||_0x5ecd05[_0x259e56(0x188)];_0xc54f86=!![],(0x0,messaging_1[_0x259e56(0x16d)])(_0x512ffa,(0x0,session_1['getReplyConversationId'])(_0x5ecd05),(0x0,session_1[_0x259e56(0x144)])(_0x5ecd05),_0x559a16,_0x15f997)[_0x259e56(0x1b7)](_0x286359=>console[_0x259e56(0x13a)](_0x259e56(0x154),_0x286359));}}if(_0x18c197===0x0&&!_0xc54f86&&!_0x5703b3?.[_0x259e56(0x186)]){console[_0x259e56(0x132)]('['+(0x0,session_1[_0x259e56(0x138)])()+_0x259e56(0x194));try{fs_1['default']['appendFileSync'](_0x3ddd19,'['+(0x0,session_1[_0x259e56(0x138)])()+']\x20[WARN]:\x20Claude\x20进程正常退出但未产生任何回复内容\x0a',_0x259e56(0x12e));}catch{}const _0x11bc3f=_0x5703b3?.[_0x259e56(0x196)]||_0x5ecd05[_0x259e56(0x188)];(0x0,messaging_1['sendDingMessage'])(_0x512ffa,{'conversationId':(0x0,session_1[_0x259e56(0x189)])(_0x5ecd05),'sessionWebhook':(0x0,session_1[_0x259e56(0x144)])(_0x5ecd05),'atUserId':_0x11bc3f,'content':_0x259e56(0x183)})[_0x259e56(0x1b7)](_0x523e40=>console[_0x259e56(0x13a)]('发送钉钉消息失败:',_0x523e40));}if(_0x18c197===0x0){_0xb1d9aa(0x0);return;}if(_0x5703b3?.[_0x259e56(0x186)]){console['log']('['+(0x0,session_1[_0x259e56(0x138)])()+_0x259e56(0x117)),_0x5703b3[_0x259e56(0x186)]=![],_0xb1d9aa(0x0);return;}const _0x39f0f0=_0x3f1770+'\x0a'+_0x4ea2f1;if((0x0,api_key_manager_1[_0x259e56(0x184)])(_0x39f0f0)){const _0x545358=Date[_0x259e56(0x120)]()-_0x1ae1e5,_0xfadd16=_0x545358<FAST_FAIL_THRESHOLD_MS;console[_0x259e56(0x124)]('['+(0x0,session_1['timestamp'])()+']\x20检测到配额耗尽错误(429),stdout匹配='+(0x0,api_key_manager_1[_0x259e56(0x184)])(_0x4ea2f1)+',\x20stderr匹配='+(0x0,api_key_manager_1[_0x259e56(0x184)])(_0x3f1770)),_0x54d565(new RetryableApiError(_0xfadd16,_0x39f0f0));return;}if((0x0,api_key_manager_1[_0x259e56(0x111)])(_0x39f0f0)){console[_0x259e56(0x124)]('['+(0x0,session_1[_0x259e56(0x138)])()+_0x259e56(0x118));const _0x5aebb8=_0x5703b3?.['lastSenderStaffId']||_0x5ecd05[_0x259e56(0x188)];(0x0,messaging_1[_0x259e56(0x192)])(_0x512ffa,{'conversationId':(0x0,session_1[_0x259e56(0x189)])(_0x5ecd05),'sessionWebhook':(0x0,session_1[_0x259e56(0x144)])(_0x5ecd05),'atUserId':_0x5aebb8,'content':_0x259e56(0x173)})['catch'](_0x5ae09d=>console['error']('发送钉钉消息失败:',_0x5ae09d)),_0xb1d9aa(_0x18c197??0x1);return;}if(isRetryableApiError(_0x39f0f0)){const _0x2806d0=Date[_0x259e56(0x120)]()-_0x1ae1e5,_0x47e9d7=_0x2806d0<FAST_FAIL_THRESHOLD_MS;_0x54d565(new RetryableApiError(_0x47e9d7,_0x39f0f0));return;}if(isPermissionError(_0x39f0f0)){console[_0x259e56(0x124)]('['+(0x0,session_1[_0x259e56(0x138)])()+_0x259e56(0x16c));const _0x1736a3=_0x5703b3?.[_0x259e56(0x196)]||_0x5ecd05[_0x259e56(0x188)];(0x0,messaging_1['sendDingMessage'])(_0x512ffa,{'conversationId':(0x0,session_1[_0x259e56(0x189)])(_0x5ecd05),'sessionWebhook':(0x0,session_1[_0x259e56(0x144)])(_0x5ecd05),'atUserId':_0x1736a3,'content':_0x259e56(0x164)})[_0x259e56(0x1b7)](_0x1c0aec=>console['error'](_0x259e56(0x154),_0x1c0aec)),_0xb1d9aa(_0x18c197??0x1);return;}if(_0x5ecd05['claudeSessionId']&&isConversationNotFoundError(_0x39f0f0)){console[_0x259e56(0x124)]('['+(0x0,session_1[_0x259e56(0x138)])()+_0x259e56(0x165)+_0x5ecd05[_0x259e56(0x11a)]+',通知外层重新发起新会话'),_0x54d565(new ConversationNotFoundError());return;}_0x54d565(new Error(_0x259e56(0x1ad)+_0x18c197));}),_0x2c4b10['on'](_0x37a9b4(0x13a),_0x2823d8=>{const _0x272aae=_0x37a9b4;console[_0x272aae(0x13a)](_0x272aae(0x16e),_0x2823d8),fs_1['default']['appendFileSync'](_0x3ddd19,'['+(0x0,session_1[_0x272aae(0x138)])()+']\x20[ERROR]:\x20进程错误:\x20'+_0x2823d8[_0x272aae(0x158)]+'\x0a',_0x272aae(0x12e)),_0x54d565(_0x2823d8);});});}async function executeClaudeQuery(_0x263a41,_0x577d15,_0x4a443e,_0x53fdef){const _0x1de6cc=a3_0x296b7e,{skill:_0x38f4f5,agent:_0x245f69,senderNick:_0x3ff261,senderStaffId:_0x8ca160}=_0x53fdef||{};let _0x3a256c=_0x263a41[_0x1de6cc(0x1a7)](_0x577d15),_0xaa67b6=_0x3a256c+_0x1de6cc(0x11b);const _0x3a2a82=_0x263a41[_0x1de6cc(0x151)](_0x577d15[_0x1de6cc(0x12f)]);fs_1['default'][_0x1de6cc(0x160)](_0x3a256c,{'recursive':!![]});let _0x5baf19=null;const _0x4597ac=(0x0,api_key_manager_1[_0x1de6cc(0x157)])(_0x3a2a82);_0x4597ac&&_0x263a41[_0x1de6cc(0x119)]['apiKeyCfg']&&(_0x5baf19=_0x263a41['config'][_0x1de6cc(0x133)][_0x1de6cc(0x18a)]['find'](_0x91d791=>_0x91d791['apiKey']===_0x4597ac&&_0x91d791['isValid'])||null,_0x5baf19&&console['log']('['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x193)+(0x0,api_key_manager_1[_0x1de6cc(0x1a3)])(_0x5baf19)));const _0xca352b=(0x0,api_key_manager_1[_0x1de6cc(0x171)])(_0x3a2a82);if(!_0xca352b&&_0x263a41[_0x1de6cc(0x119)][_0x1de6cc(0x133)]){_0x5baf19=(0x0,api_key_manager_1['pickValidApiKey'])(_0x263a41);if(!_0x5baf19){const _0x5ab7da=_0x8ca160||_0x577d15['startStaffId'];await(0x0,messaging_1[_0x1de6cc(0x192)])(_0x263a41,{'conversationId':(0x0,session_1[_0x1de6cc(0x189)])(_0x577d15),'sessionWebhook':(0x0,session_1['getReplyWebhook'])(_0x577d15),'atUserId':_0x5ab7da,'content':'⚠️\x20当前无可用配额(无可用\x20API\x20Key),请明天再试或联系管理员'});return;}}const _0x20d306=_0x3ff261&&_0x8ca160?_0x3ff261+'('+_0x8ca160+')':_0x1de6cc(0x190),_0xc72bb2=_0x4a443e+'\x20──\x20消息来自:\x20'+_0x20d306;_0x263a41['appendSessionLog'](_0x3a256c,_0x1de6cc(0x1a9),_0xc72bb2);const _0x41451d=_0x1de6cc(0x13f),_0x54a779=[_0x1de6cc(0x116),_0x1de6cc(0x17e),'--print',_0x1de6cc(0x175),_0x1de6cc(0x179),_0x1de6cc(0x1b3)];_0x245f69&&_0x54a779[_0x1de6cc(0x19f)](_0x1de6cc(0x15c),_0x245f69);const _0x4013d6=_0x38f4f5?'/'+_0x38f4f5+'\x20'+_0xc72bb2:_0xc72bb2;let _0x10e6fb=0x0;while(!![]){const _0x41b020=_0x10e6fb>0x0,_0x30e0b3=[..._0x54a779];_0x577d15['claudeSessionId']&&(_0x30e0b3[_0x1de6cc(0x19f)](_0x1de6cc(0x114),_0x577d15[_0x1de6cc(0x11a)]),!_0x41b020&&console[_0x1de6cc(0x124)]('['+(0x0,session_1['timestamp'])()+']\x20恢复\x20Claude\x20会话:\x20'+_0x577d15[_0x1de6cc(0x11a)]));const _0x4d7a84=resolveClaudeSettingsPath(_0x263a41,_0x3a2a82,_0x53fdef?.[_0x1de6cc(0x14a)]);_0x4d7a84&&_0x30e0b3[_0x1de6cc(0x19f)]('--settings',_0x4d7a84);let _0x10abc8;_0x41b020?(_0x10abc8='继续',console[_0x1de6cc(0x124)]('['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x146)+_0x10e6fb+'/'+MAX_FAST_FAIL+'次)'),fs_1[_0x1de6cc(0x16f)][_0x1de6cc(0x15e)](_0xaa67b6,'['+(0x0,session_1[_0x1de6cc(0x138)])()+']\x20[SYSTEM]:\x20TPM\x20限流,发送\x22继续\x22重试\x20(快速失败连续'+_0x10e6fb+'/'+MAX_FAST_FAIL+')\x0a',_0x1de6cc(0x12e))):_0x10abc8=_0x4013d6;console[_0x1de6cc(0x124)]('['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x121)+_0x41451d+'\x20'+_0x30e0b3['join']('\x20')),_0x263a41['debugLog'](_0x1de6cc(0x177)+_0x10abc8[_0x1de6cc(0x18f)](0x0,0x64)+_0x1de6cc(0x17c));try{await runClaudeOnce(_0x263a41,_0x577d15,_0x30e0b3,_0x41451d,_0x3a2a82,_0x10abc8,_0x41b020);return;}catch(_0x53996d){_0x3a256c=_0x263a41[_0x1de6cc(0x1a7)](_0x577d15),_0xaa67b6=_0x3a256c+_0x1de6cc(0x11b);if(_0x53996d instanceof RetryableApiError){if((0x0,api_key_manager_1[_0x1de6cc(0x184)])(_0x53996d[_0x1de6cc(0x198)])&&_0x263a41[_0x1de6cc(0x119)][_0x1de6cc(0x133)]){if(_0x5baf19){const _0x439108=(0x0,api_key_manager_1['rotateApiKey'])(_0x263a41,_0x5baf19[_0x1de6cc(0x1b2)]);if(_0x439108){_0x5baf19=_0x439108,_0x10e6fb=0x0,console[_0x1de6cc(0x124)]('['+(0x0,session_1[_0x1de6cc(0x138)])()+']\x20API\x20Key\x20配额耗尽(429),切换到新\x20Key:\x20'+(0x0,api_key_manager_1[_0x1de6cc(0x1a3)])(_0x439108)),fs_1[_0x1de6cc(0x16f)]['appendFileSync'](_0xaa67b6,'['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x17d),_0x1de6cc(0x12e));continue;}}const _0x701beb=_0x8ca160||_0x577d15[_0x1de6cc(0x188)];await(0x0,messaging_1[_0x1de6cc(0x192)])(_0x263a41,{'conversationId':(0x0,session_1['getReplyConversationId'])(_0x577d15),'sessionWebhook':(0x0,session_1[_0x1de6cc(0x144)])(_0x577d15),'atUserId':_0x701beb,'content':'⚠️\x20当前无可用配额/API\x20Key,请明天再试或联系管理员'});return;}if(_0x53996d[_0x1de6cc(0x1b8)]){_0x10e6fb++;if(_0x10e6fb>=MAX_FAST_FAIL){if(_0x5baf19&&_0x263a41[_0x1de6cc(0x119)][_0x1de6cc(0x133)]){const _0x42db8c=(0x0,api_key_manager_1[_0x1de6cc(0x11c)])(_0x263a41,_0x5baf19[_0x1de6cc(0x1b2)]);if(_0x42db8c){_0x5baf19=_0x42db8c,_0x10e6fb=0x0,console[_0x1de6cc(0x124)]('['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x126)+MAX_FAST_FAIL+'\x20次,切换到新\x20Key:\x20'+(0x0,api_key_manager_1[_0x1de6cc(0x1a3)])(_0x42db8c)),fs_1[_0x1de6cc(0x16f)][_0x1de6cc(0x15e)](_0xaa67b6,'['+(0x0,session_1[_0x1de6cc(0x138)])()+']\x20[SYSTEM]:\x20TPM\x20限流连续快速失败,切换到新\x20Key\x0a',_0x1de6cc(0x12e));continue;}}console[_0x1de6cc(0x124)]('['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x13e)+MAX_FAST_FAIL+'次,放弃'),fs_1['default']['appendFileSync'](_0xaa67b6,'['+(0x0,session_1['timestamp'])()+']\x20[SYSTEM]:\x20TPM\x20限流快速失败连续'+MAX_FAST_FAIL+'次,放弃\x0a','utf-8');throw new Error(_0x1de6cc(0x129)+MAX_FAST_FAIL+'\x20次');}console['log']('['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x135)+API_RETRY_DELAY_MS/0x3e8+'s\x20后重试\x20('+_0x10e6fb+'/'+MAX_FAST_FAIL+')');}else _0x10e6fb=0x0,console[_0x1de6cc(0x124)]('['+(0x0,session_1[_0x1de6cc(0x138)])()+']\x20检测到\x20TPM\x20限流(进程已运行一段时间),重置快速失败计数,'+API_RETRY_DELAY_MS/0x3e8+'s\x20后重试');fs_1[_0x1de6cc(0x16f)][_0x1de6cc(0x15e)](_0xaa67b6,'['+(0x0,session_1['timestamp'])()+_0x1de6cc(0x1a1)+API_RETRY_DELAY_MS/0x3e8+_0x1de6cc(0x17b),_0x1de6cc(0x12e)),await sleep(API_RETRY_DELAY_MS);continue;}if(_0x53996d instanceof ConversationNotFoundError){console[_0x1de6cc(0x124)]('['+(0x0,session_1['timestamp'])()+']\x20Claude\x20会话失效,清除\x20claudeSessionId\x20并重新发起'),fs_1[_0x1de6cc(0x16f)][_0x1de6cc(0x15e)](_0xaa67b6,'['+(0x0,session_1[_0x1de6cc(0x138)])()+_0x1de6cc(0x145),_0x1de6cc(0x12e));_0x577d15[_0x1de6cc(0x11a)]&&(_0x577d15[_0x1de6cc(0x11a)]=undefined,_0x263a41['updateSessionFile'](_0x577d15,{}));_0x10e6fb=0x0;continue;}throw _0x53996d;}}}
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveClaudeSettingsPath=resolveClaudeSettingsPath,exports.isRetryableApiError=isRetryableApiError,exports.parseClaudeStreamLine=parseClaudeStreamLine,exports.interruptClaudeProcess=interruptClaudeProcess,exports.executeClaudeQuery=executeClaudeQuery;const fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),readline_1=__importDefault(require("readline")),child_process_1=require("child_process"),messaging_1=require("./messaging"),session_1=require("./session"),api_key_manager_1=require("./api-key-manager"),MAX_FAST_FAIL=20,API_RETRY_DELAY_MS=1e4,FAST_FAIL_THRESHOLD_MS=1e4,MAX_TOTAL_RETRIES=10,MAX_RETRY_DURATION_MS=300*1e3,WATCHDOG_TIMEOUT_MS=300*1e3,WATCHDOG_CHECK_INTERVAL_MS=30*1e3;function resolveClaudeSettingsPath(t,e,i){const c=(0,api_key_manager_1.getForceEnabledSettingsPath)(e);if(c)return c;if(t.config.apiKeyCfg){const S=(0,api_key_manager_1.readApiKeyFromSettings)(e);let h=null;if(S&&(h=t.config.apiKeyCfg.claudeSettings.find(d=>d.apiKey===S&&d.isValid)||null),h||(h=(0,api_key_manager_1.pickValidApiKey)(t)),h)return(0,api_key_manager_1.ensureSettingsWithApiKey)(e,h)}if(t.config.apiKeyCfg)return;if(i)return i;const $=path_1.default.join(e,".claude","settings.json");if(fs_1.default.existsSync($))return console.log(`[${(0,session_1.timestamp)()}] \u81EA\u52A8\u68C0\u6D4B\u5230 settings.json: ${$}`),$}function isRetryableApiError(t){if(/\b429\b/.test(t)&&!(0,api_key_manager_1.isQuotaExhaustedError)(t)||/API\s*Error.*422/i.test(t)||/\b422\b.*(?:TPM|额度超限|rate\s*limit|tokens?\s*per\s*minute)/i.test(t)||/(?:TPM|额度超限).*\b422\b/i.test(t))return!0;const e=t.toLowerCase();return["rate limit","rate_limit","ratelimit","too many requests","tokens per minute","requests per minute","rpm limit","overloaded","capacity","temporarily unavailable"].some(c=>e.includes(c))}function sleep(t){return new Promise(e=>setTimeout(e,t))}class RetryableApiError extends Error{constructor(e,i=""){super(`Retryable API error (TPM limit etc.)${e?" [fast fail]":""}`),this.name="RetryableApiError",this.isFastFail=e,this.output=i}}class ConversationNotFoundError extends Error{constructor(){super("Claude conversation not found"),this.name="ConversationNotFoundError"}}class ContextWindowExceededError extends Error{constructor(){super("Context window exceeded: prompt tokens exceed maximum context window"),this.name="ContextWindowExceededError"}}function readLastLogLines(t,e){try{return fs_1.default.readFileSync(t,"utf-8").split(`
|
|
2
|
+
`).filter(Boolean).slice(-e).join(`
|
|
3
|
+
`)}catch{return""}}function isContextWindowExceededError(t){return/prompt tokens?\s*\(\s*\d+\s*\)\s*exceeds/i.test(t)||/exceeds?.*maximum context window/i.test(t)}function isPermissionError(t){const e=t.toLowerCase();return["permission denied","permission_required","needs permission","requires permission","authorization required","authorize","not authorized","access denied","\u9700\u8981\u6388\u6743","\u6743\u9650\u4E0D\u8DB3","\u6CA1\u6709\u6743\u9650"].some(c=>e.includes(c))}function isConversationNotFoundError(t){return/no conversation found with session id/i.test(t)}function parseClaudeStreamLine(t,e=!1){if(!t.trim())return null;try{const i=JSON.parse(t);if(i.type==="system"&&i.subtype==="init"&&i.session_id)return{type:"system",sessionId:i.session_id};if(i.type==="assistant"){const c=i.message?.content;if(Array.isArray(c)){const $=[];for(const S of c)S.type==="text"&&S.text?$.push(S.text):S.type==="thinking"&&S.thinking&&e&&$.push(`\u{1F4AD} **\u601D\u8003\u8FC7\u7A0B**
|
|
4
|
+
\`\`\`
|
|
5
|
+
${S.thinking}
|
|
6
|
+
\`\`\``);if($.length>0)return{type:"assistant",content:$.join(`
|
|
7
|
+
`)}}else if(i.content)return{type:"assistant",content:typeof i.content=="string"?i.content:JSON.stringify(i.content)};return{type:"assistant"}}if(i.type==="result"){const c=i.result||"";return{type:"result",content:typeof c=="string"?c:JSON.stringify(c)}}return{type:i.type||"unknown"}}catch{return{type:"text",content:t}}}function interruptClaudeProcess(t,e){return t.currentProcess?(console.log(`[${(0,session_1.timestamp)()}] ${e}`),t.interrupted=!0,t.currentProcess.kill("SIGINT"),!0):!1}function runClaudeOnce(t,e,i,c,$,S,h){let d=t.getSessionDir(e),f=`${d}/session.log`;fs_1.default.existsSync(d)||fs_1.default.mkdirSync(d,{recursive:!0});const m=Date.now();return new Promise((I,l)=>{const E=(0,child_process_1.spawn)(c,i,{cwd:$,stdio:["pipe","pipe","pipe"]}),v=t.activeSessions.get(e.conversationId);v&&(v.currentProcess=E,v.lastActivityTime=Date.now()),fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [SYSTEM]: Claude \u67E5\u8BE2\u542F\u52A8${h?" (\u91CD\u8BD5)":""}
|
|
8
|
+
`,"utf-8"),E.stdin?.write(`${S}
|
|
9
|
+
`),E.stdin?.end();let T=!h&&!!e.claudeSessionId,C=[],b="",P="",y=!1,w=!1,a=null;const R=new Set,k=()=>{v&&(v.lastActivityTime=Date.now())};a=setInterval(()=>{if(w){a&&clearInterval(a);return}const s=v?.lastActivityTime??m;if(Date.now()-s>=WATCHDOG_TIMEOUT_MS){console.warn(`[${(0,session_1.timestamp)()}] Watchdog: Claude \u8FDB\u7A0B ${WATCHDOG_TIMEOUT_MS/1e3}s \u65E0\u6D3B\u52A8\uFF0C\u901A\u77E5\u7528\u6237`);try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [SYSTEM]: Watchdog \u8D85\u65F6\uFF0C${WATCHDOG_TIMEOUT_MS/1e3}s \u65E0\u6D3B\u52A8\uFF0C\u5DF2\u901A\u77E5\u7528\u6237
|
|
10
|
+
`,"utf-8")}catch{}a&&clearInterval(a),a=null;const g=v?.lastSenderStaffId||e.startStaffId;(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:g,content:`\u23F0 Claude \u8FDB\u7A0B\u8D85\u8FC7 ${WATCHDOG_TIMEOUT_MS/1e3}s \u65E0\u54CD\u5E94\uFF0C\u53EF\u53D1\u9001 /goon \u5F3A\u5236\u91CD\u542F\u6062\u590D\uFF0C\u6216 /end \u7ED3\u675F\u4F1A\u8BDD`}).catch(r=>console.error("\u53D1\u9001 Watchdog \u901A\u77E5\u5931\u8D25:",r))}},WATCHDOG_CHECK_INTERVAL_MS),readline_1.default.createInterface({input:E.stdout}).on("line",s=>{if(P+=s+`
|
|
11
|
+
`,k(),t.debugLog(`Claude stdout: ${s.substring(0,200)}${s.length>200?"...":""}`),t.config.debug)try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [RAW]: ${s}
|
|
12
|
+
`,"utf-8")}catch{}const o=parseClaudeStreamLine(s,t.config.includeThinking??!1);if(o){if(o.type==="system"&&o.sessionId&&!T&&(t.updateSessionFile(e,{claudeSessionId:o.sessionId}),T=!0,d=t.getSessionDir(e),f=`${d}/session.log`),o.type==="assistant"){try{const r=JSON.parse(s)?.message?.content;if(Array.isArray(r)){for(const n of r)if(n.type==="tool_use"&&n.id&&!R.has(n.id)){R.add(n.id);const p=n.name||"unknown";let u="";n.input&&(n.input.command?u=n.input.command.substring(0,200):n.input.file_path?u=n.input.file_path:n.input.pattern?u=n.input.pattern:n.input.query?u=n.input.query:n.input.description?u=n.input.description:n.input.prompt?u=n.input.prompt.substring(0,200):u=JSON.stringify(n.input).substring(0,200)),t.appendSessionLog(d,"tool",`${p}${u?": "+u:""}`)}}}catch{}o.content&&C.push(o.content)}if(o.type==="result"){const g=t.config.resultOnly??!0,r=(o.content||"").trim(),n=C.join(`
|
|
13
|
+
`).trim(),p=g&&r||n;if(p&&!v?.interrupted){try{t.appendSessionLog(d,"assistant",p)}catch{}const M=t.activeSessions.get(e.conversationId)?.lastSenderStaffId||e.startStaffId;y=!0,(0,messaging_1.sendClaudeResponseToDing)(t,(0,session_1.getReplyConversationId)(e),(0,session_1.getReplyWebhook)(e),M,p).catch(A=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",A))}else console.warn(`[${(0,session_1.timestamp)()}] Claude \u8FD4\u56DE\u4E86\u7A7A\u7684 result \u4E14 responseBuffer \u4E5F\u4E3A\u7A7A\uFF0C\u65E0\u5185\u5BB9\u53EF\u53D1\u9001`);C=[]}}}),E.stderr?.on("data",s=>{const o=s.toString();if(b+=o,k(),(0,api_key_manager_1.isQuotaExhaustedError)(o)){console.log(`[${(0,session_1.timestamp)()}] [Claude stderr] \u914D\u989D\u8017\u5C3D\u9519\u8BEF(429): ${o.trim()}`);try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [WARN]: ${o}`,"utf-8")}catch{}}else if(isRetryableApiError(o)){console.log(`[${(0,session_1.timestamp)()}] [Claude stderr] \u53EF\u91CD\u8BD5API\u9519\u8BEF(422 TPM\u9650\u6D41): ${o.trim()}`);try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [WARN]: ${o}`,"utf-8")}catch{}}else{console.error(`[Claude stderr]: ${o}`);try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [ERROR]: ${o}`,"utf-8")}catch{}}}),E.on("close",s=>{w=!0,a&&(clearInterval(a),a=null),console.log(`[${(0,session_1.timestamp)()}] Claude \u8FDB\u7A0B\u9000\u51FA\uFF0C\u4EE3\u7801: ${s}`);try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [SYSTEM]: Claude \u67E5\u8BE2\u7ED3\u675F\uFF0C\u9000\u51FA\u7801: ${s}
|
|
14
|
+
`,"utf-8")}catch{}const o=t.activeSessions.get(e.conversationId);if(o&&(o.currentProcess=void 0),o?.interrupted){console.log(`[${(0,session_1.timestamp)()}] \u7528\u6237\u4E3B\u52A8\u4E2D\u65AD\uFF0C\u4E22\u5F03 responseBuffer (${C.length} \u6BB5)`),o.interrupted=!1,C=[],I(0);return}if(C.length>0){const r=C.join(`
|
|
15
|
+
`).trim();if(r){try{t.appendSessionLog(d,"assistant",r)}catch{}const n=o?.lastSenderStaffId||e.startStaffId;y=!0,(0,messaging_1.sendClaudeResponseToDing)(t,(0,session_1.getReplyConversationId)(e),(0,session_1.getReplyWebhook)(e),n,r).catch(p=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",p))}}if(s===0&&!y&&!o?.interrupted){console.warn(`[${(0,session_1.timestamp)()}] Claude \u8FDB\u7A0B\u6B63\u5E38\u9000\u51FA\u4F46\u672A\u4EA7\u751F\u4EFB\u4F55\u56DE\u590D\u5185\u5BB9`);try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [WARN]: Claude \u8FDB\u7A0B\u6B63\u5E38\u9000\u51FA\u4F46\u672A\u4EA7\u751F\u4EFB\u4F55\u56DE\u590D\u5185\u5BB9
|
|
16
|
+
`,"utf-8")}catch{}const r=o?.lastSenderStaffId||e.startStaffId;(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:r,content:"\u26A0\uFE0F Claude \u5904\u7406\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u4EFB\u4F55\u5185\u5BB9\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6362\u79CD\u65B9\u5F0F\u63D0\u95EE"}).catch(n=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",n))}if(s===0){I(0);return}const g=b+`
|
|
17
|
+
`+P;if((0,api_key_manager_1.isQuotaExhaustedError)(g)){const n=Date.now()-m<FAST_FAIL_THRESHOLD_MS;console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230\u914D\u989D\u8017\u5C3D\u9519\u8BEF(429)\uFF0Cstdout\u5339\u914D=${(0,api_key_manager_1.isQuotaExhaustedError)(P)}, stderr\u5339\u914D=${(0,api_key_manager_1.isQuotaExhaustedError)(b)}`),l(new RetryableApiError(n,g));return}if((0,api_key_manager_1.isAuthenticationError)(g)){console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230\u8BA4\u8BC1\u9519\u8BEF(401)\uFF0C\u901A\u77E5\u7528\u6237`);const r=o?.lastSenderStaffId||e.startStaffId;(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:r,content:"\u26A0\uFE0F \u8BA4\u8BC1\u5931\u8D25(401)\uFF0CAPI Key \u65E0\u6548\u6216\u670D\u52A1\u672A\u6388\u6743\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E"}).catch(n=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",n)),I(s??1);return}if(isRetryableApiError(g)){const n=Date.now()-m<FAST_FAIL_THRESHOLD_MS;l(new RetryableApiError(n,g));return}if(isPermissionError(g)){console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230\u9700\u8981\u6388\u6743\uFF0C\u901A\u77E5\u7528\u6237`);const r=o?.lastSenderStaffId||e.startStaffId;(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:r,content:"\u26A0\uFE0F Claude \u9700\u8981\u6388\u6743\uFF0C\u8BF7\u4EBA\u5DE5\u4ECB\u5165"}).catch(n=>console.error("\u53D1\u9001\u9489\u9489\u6D88\u606F\u5931\u8D25:",n)),I(s??1);return}if(e.claudeSessionId&&isConversationNotFoundError(g)){console.log(`[${(0,session_1.timestamp)()}] Claude \u4F1A\u8BDD\u5DF2\u5931\u6548: ${e.claudeSessionId}\uFF0C\u901A\u77E5\u5916\u5C42\u91CD\u65B0\u53D1\u8D77\u65B0\u4F1A\u8BDD`),l(new ConversationNotFoundError);return}if(isContextWindowExceededError(g)){console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230\u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\u9519\u8BEF(400)\uFF0C\u5C06\u81EA\u52A8\u53D1\u9001 /compact \u538B\u7F29\u4E0A\u4E0B\u6587`);try{fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [SYSTEM]: \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u5C06\u81EA\u52A8 /compact
|
|
18
|
+
`,"utf-8")}catch{}l(new ContextWindowExceededError);return}l(new Error(`Claude \u8FDB\u7A0B\u9000\u51FA\uFF0C\u4EE3\u7801: ${s}`))}),E.on("error",s=>{w=!0,a&&(clearInterval(a),a=null),console.error("Claude \u8FDB\u7A0B\u9519\u8BEF:",s),fs_1.default.appendFileSync(f,`[${(0,session_1.timestamp)()}] [ERROR]: \u8FDB\u7A0B\u9519\u8BEF: ${s.message}
|
|
19
|
+
`,"utf-8"),l(s)})})}async function executeClaudeQuery(t,e,i,c){const{skill:$,agent:S,senderNick:h,senderStaffId:d}=c||{};let f=t.getSessionDir(e),m=`${f}/session.log`;const I=t.getConversationDir(e.conversationId);fs_1.default.mkdirSync(f,{recursive:!0});let l=null;const E=(0,api_key_manager_1.readApiKeyFromSettings)(I);if(E&&t.config.apiKeyCfg&&(l=t.config.apiKeyCfg.claudeSettings.find(s=>s.apiKey===E&&s.isValid)||null,l&&console.log(`[${(0,session_1.timestamp)()}] \u4ECE settings-ding.json \u6062\u590D Claude Setting: ${(0,api_key_manager_1.settingLabel)(l)}`)),!(0,api_key_manager_1.getForceEnabledSettingsPath)(I)&&t.config.apiKeyCfg&&(l=(0,api_key_manager_1.pickValidApiKey)(t),!l)){const s=d||e.startStaffId;await(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:s,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u53EF\u7528\u914D\u989D\uFF08\u65E0\u53EF\u7528 API Key\uFF09\uFF0C\u8BF7\u660E\u5929\u518D\u8BD5\u6216\u8054\u7CFB\u7BA1\u7406\u5458"});return}const T=h&&d?`${i} \u2500\u2500 \u6D88\u606F\u6765\u81EA: ${h}(${d})`:i;t.appendSessionLog(f,"user",T);const C="claude",b=["--permission-mode","bypassPermissions","--print","--output-format","stream-json","--verbose"];t.config.skipSandbox&&b.push("--dangerous-skip-sandbox"),S&&b.push("--agent",S);const P=$?`/${$} ${T}`:T;let y=0,w=0,a=0;const R=[],k=t.activeSessions.get(e.conversationId),_=s=>{const o=t.activeSessions.get(e.conversationId);return!o||o!==k?(console.log(`[${(0,session_1.timestamp)()}] \u4F1A\u8BDD\u5DF2\u88AB\u7EC8\u6B62\uFF0C${s}`),!1):o.goonPending?(console.log(`[${(0,session_1.timestamp)()}] \u6536\u5230 /goon \u8BF7\u6C42\uFF0C${s}`),!1):!0};for(;;){if(!_("\u505C\u6B62\u91CD\u8BD5"))return;const s=y>0;if(w>=MAX_TOTAL_RETRIES||w>=3&&a>0&&Date.now()-a>MAX_RETRY_DURATION_MS){const n=w>=MAX_TOTAL_RETRIES?`\u603B\u91CD\u8BD5\u6B21\u6570\u5DF2\u8FBE ${MAX_TOTAL_RETRIES} \u6B21`:`\u91CD\u8BD5\u6301\u7EED\u65F6\u95F4\u8D85\u8FC7 ${MAX_RETRY_DURATION_MS/1e3}s\uFF08\u5DF2\u91CD\u8BD5 ${w} \u6B21\uFF09`;console.error(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230\u65E0\u9650\u91CD\u8BD5\u5FAA\u73AF: ${n}`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: \u68C0\u6D4B\u5230\u65E0\u9650\u91CD\u8BD5\u5FAA\u73AF\uFF0C${n}\uFF0C\u7EC8\u6B62\u91CD\u8BD5
|
|
20
|
+
`,"utf-8");const p=readLastLogLines(m,1),u=R.slice(-1)[0]||"",M=d||e.startStaffId;await(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:M,content:`\u{1F504} \u68C0\u6D4B\u5230 Claude \u9677\u5165\u65E0\u9650\u91CD\u8BD5\uFF0C\u5DF2\u7EC8\u6B62\uFF08${n}\uFF09
|
|
21
|
+
|
|
22
|
+
\u{1F4CB} \u6700\u8FD1\u91CD\u8BD5\u8BB0\u5F55\uFF1A
|
|
23
|
+
${u}
|
|
24
|
+
|
|
25
|
+
\u{1F4DD} \u6700\u8FD1\u65E5\u5FD7\uFF1A
|
|
26
|
+
\`\`\`
|
|
27
|
+
${p}
|
|
28
|
+
\`\`\`
|
|
29
|
+
|
|
30
|
+
\u{1F4A1} \u53EF\u5C1D\u8BD5\u53D1\u9001 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD\uFF0C\u6216 /end \u7ED3\u675F\u5F53\u524D\u4F1A\u8BDD`});return}const o=[...b];e.claudeSessionId&&(o.push("--resume",e.claudeSessionId),s||console.log(`[${(0,session_1.timestamp)()}] \u6062\u590D Claude \u4F1A\u8BDD: ${e.claudeSessionId}`));const g=resolveClaudeSettingsPath(t,I,c?.settings);g&&o.push("--settings",g);let r;s?(r="\u7EE7\u7EED",console.log(`[${(0,session_1.timestamp)()}] \u53D1\u9001"\u7EE7\u7EED"\u91CD\u8BD5 (\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${y}/${MAX_FAST_FAIL}\u6B21)`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\uFF0C\u53D1\u9001"\u7EE7\u7EED"\u91CD\u8BD5 (\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${y}/${MAX_FAST_FAIL})
|
|
31
|
+
`,"utf-8")):r=P,console.log(`[${(0,session_1.timestamp)()}] \u6267\u884C Claude \u67E5\u8BE2[\u539F\u751Fclaude \u6A21\u5F0F]: ${C} ${o.join(" ")}`),t.debugLog(`\u53D1\u9001\u6D88\u606F: ${r.substring(0,100)}...`);try{await runClaudeOnce(t,e,o,C,I,r,s);return}catch(n){if(f=t.getSessionDir(e),m=`${f}/session.log`,n instanceof RetryableApiError){if(w++,a=a||Date.now(),(0,api_key_manager_1.isQuotaExhaustedError)(n.output)&&t.config.apiKeyCfg){if(R.push(`[${(0,session_1.timestamp)()}] 429 \u914D\u989D\u8017\u5C3D\uFF0C\u5C1D\u8BD5\u8F6E\u6362 Key`),l){const u=(0,api_key_manager_1.rotateApiKey)(t,l.apiKey);if(u){l=u,y=0,console.log(`[${(0,session_1.timestamp)()}] API Key \u914D\u989D\u8017\u5C3D(429)\uFF0C\u5207\u6362\u5230\u65B0 Key: ${(0,api_key_manager_1.settingLabel)(u)}`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: API Key \u914D\u989D\u8017\u5C3D(429)\uFF0C\u5207\u6362\u5230\u65B0 Key
|
|
32
|
+
`,"utf-8");continue}}const p=d||e.startStaffId;await(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:p,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u53EF\u7528\u914D\u989D/API Key\uFF0C\u8BF7\u660E\u5929\u518D\u8BD5\u6216\u8054\u7CFB\u7BA1\u7406\u5458"});return}if(n.isFastFail){if(y++,y>=MAX_FAST_FAIL){if(l&&t.config.apiKeyCfg){const p=(0,api_key_manager_1.rotateApiKey)(t,l.apiKey);if(p){l=p,y=0,console.log(`[${(0,session_1.timestamp)()}] TPM \u9650\u6D41\u8FDE\u7EED\u5FEB\u901F\u5931\u8D25 ${MAX_FAST_FAIL} \u6B21\uFF0C\u5207\u6362\u5230\u65B0 Key: ${(0,api_key_manager_1.settingLabel)(p)}`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\u8FDE\u7EED\u5FEB\u901F\u5931\u8D25\uFF0C\u5207\u6362\u5230\u65B0 Key
|
|
33
|
+
`,"utf-8");continue}}throw console.log(`[${(0,session_1.timestamp)()}] TPM \u9650\u6D41\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${MAX_FAST_FAIL}\u6B21\uFF0C\u653E\u5F03`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED${MAX_FAST_FAIL}\u6B21\uFF0C\u653E\u5F03
|
|
34
|
+
`,"utf-8"),new Error(`TPM \u9650\u6D41\uFF0C\u5FEB\u901F\u5931\u8D25\u8FDE\u7EED ${MAX_FAST_FAIL} \u6B21`)}console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230 TPM \u9650\u6D41(\u5FEB\u901F\u5931\u8D25)\uFF0C${API_RETRY_DELAY_MS/1e3}s \u540E\u91CD\u8BD5 (${y}/${MAX_FAST_FAIL})`)}else y=0,console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230 TPM \u9650\u6D41(\u8FDB\u7A0B\u5DF2\u8FD0\u884C\u4E00\u6BB5\u65F6\u95F4)\uFF0C\u91CD\u7F6E\u5FEB\u901F\u5931\u8D25\u8BA1\u6570\uFF0C${API_RETRY_DELAY_MS/1e3}s \u540E\u91CD\u8BD5`);if(fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: TPM \u9650\u6D41\uFF0C${API_RETRY_DELAY_MS/1e3}s \u540E\u91CD\u8BD5
|
|
35
|
+
`,"utf-8"),R.push(`[${(0,session_1.timestamp)()}] TPM \u9650\u6D41\uFF0C${API_RETRY_DELAY_MS/1e3}s \u540E\u91CD\u8BD5`),await sleep(API_RETRY_DELAY_MS),!_("\u505C\u6B62\u5F53\u524D\u91CD\u8BD5"))return;continue}if(n instanceof ConversationNotFoundError){w++,a=a||Date.now(),R.push(`[${(0,session_1.timestamp)()}] \u4F1A\u8BDD\u5931\u6548\uFF0C\u6E05\u9664\u65E7\u4F1A\u8BDD`),console.log(`[${(0,session_1.timestamp)()}] Claude \u4F1A\u8BDD\u5931\u6548\uFF0C\u6E05\u9664 claudeSessionId \u5E76\u91CD\u65B0\u53D1\u8D77`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: Claude \u4F1A\u8BDD\u5DF2\u5931\u6548\uFF0C\u6E05\u9664\u65E7\u4F1A\u8BDD\u5E76\u91CD\u65B0\u53D1\u8D77
|
|
36
|
+
`,"utf-8"),e.claudeSessionId&&(e.claudeSessionId=void 0,t.updateSessionFile(e,{})),y=0;continue}if(n instanceof ContextWindowExceededError){w++,a=a||Date.now(),R.push(`[${(0,session_1.timestamp)()}] \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u81EA\u52A8 /compact`),console.log(`[${(0,session_1.timestamp)()}] \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u81EA\u52A8\u53D1\u9001 /compact \u538B\u7F29\u4E0A\u4E0B\u6587`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: \u4E0A\u4E0B\u6587\u7A97\u53E3\u8D85\u957F\uFF0C\u81EA\u52A8\u53D1\u9001 /compact \u538B\u7F29\u4E0A\u4E0B\u6587
|
|
37
|
+
`,"utf-8");const p=d||e.startStaffId;await(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:p,content:"\u{1F4E6} \u4E0A\u4E0B\u6587\u8D85\u957F\uFF0C\u6B63\u5728\u81EA\u52A8\u538B\u7F29\u4E0A\u4E0B\u6587(/compact)\u540E\u7EE7\u7EED..."});const u=[...b];e.claudeSessionId&&u.push("--resume",e.claudeSessionId);const M=resolveClaudeSettingsPath(t,I,c?.settings);M&&u.push("--settings",M);try{await runClaudeOnce(t,e,u,C,I,"/compact",!1),console.log(`[${(0,session_1.timestamp)()}] /compact \u6267\u884C\u6210\u529F\uFF0C\u53D1\u9001"\u7EE7\u7EED"\u6062\u590D\u6267\u884C`),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: /compact \u6267\u884C\u6210\u529F\uFF0C\u53D1\u9001"\u7EE7\u7EED"\u6062\u590D\u6267\u884C
|
|
38
|
+
`,"utf-8")}catch(A){throw console.error(`[${(0,session_1.timestamp)()}] /compact \u6267\u884C\u5931\u8D25:`,A),fs_1.default.appendFileSync(m,`[${(0,session_1.timestamp)()}] [SYSTEM]: /compact \u6267\u884C\u5931\u8D25: ${A instanceof Error?A.message:String(A)}
|
|
39
|
+
`,"utf-8"),await(0,messaging_1.sendDingMessage)(t,{conversationId:(0,session_1.getReplyConversationId)(e),sessionWebhook:(0,session_1.getReplyWebhook)(e),atUserId:p,content:"\u274C \u81EA\u52A8\u538B\u7F29\u4E0A\u4E0B\u6587(/compact)\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u53D1\u9001 /compact \u6216 /new \u5F00\u59CB\u65B0\u4F1A\u8BDD"}),new Error(`\u4E0A\u4E0B\u6587\u8D85\u957F\u4E14 /compact \u5931\u8D25: ${A instanceof Error?A.message:String(A)}`)}y=0;continue}throw n}}}
|