cc-ding 0.3.0 → 0.4.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 +16 -4
- package/dist/src/biz/api-key-manager.js +3 -3
- package/dist/src/biz/cc-ding-cli.js +69 -64
- package/dist/src/biz/claude-process.js +32 -32
- package/dist/src/biz/claude-sdk.js +2 -0
- package/dist/src/biz/command-route.js +1 -0
- package/dist/src/biz/commands.js +5 -5
- package/dist/src/biz/cron.js +5 -6
- package/dist/src/biz/doctor.js +1 -1
- package/dist/src/biz/lock.js +1 -1
- package/dist/src/biz/messaging.js +5 -5
- package/dist/src/biz/notify.js +1 -1
- package/dist/src/biz/platform.js +2 -0
- package/dist/src/biz/secrets.js +1 -0
- package/dist/src/biz/session.js +3 -3
- package/dist/src/biz/task.js +22 -23
- package/package.json +7 -11
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
|
|
|
97
97
|
| 命令 | 说明 |
|
|
98
98
|
|------|------|
|
|
99
99
|
| `/ls [目录] [层数]` | 查看目录结构 |
|
|
100
|
-
| `/bash <命令>` |
|
|
100
|
+
| `/bash <命令>` | 执行任意命令(仅 owner/管理员,执行记录审计日志 `bash-audit.log`) |
|
|
101
101
|
|
|
102
102
|
#### 管理命令(仅 owner)
|
|
103
103
|
|
|
@@ -152,9 +152,15 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
|
|
|
152
152
|
| `apiKeyCfg` | API Key 池化:429 自动切换、每日 0 点重置 |
|
|
153
153
|
| `useLocalOcr` | 图片本地 OCR(默认 `true`),模型支持图片时可设 `false` |
|
|
154
154
|
| `linkConversationId` | 关联群 ID,多群共享同一 Claude 会话上下文 |
|
|
155
|
-
| `permissionMode` | Claude 进程权限模式(默认 `bypassPermissions
|
|
155
|
+
| `permissionMode` | Claude 进程权限模式(默认 `acceptEdits`;`bypassPermissions` 需显式配置,启动时会告警),可选: `default`、`acceptEdits`、`plan`、`auto`、`bypassPermissions`、`dontAsk` |
|
|
156
156
|
| `preBash` | 全局 `/bash` 前置命令 |
|
|
157
157
|
|
|
158
|
+
#### 安全说明
|
|
159
|
+
|
|
160
|
+
- 敏感字段(`clientSecret`、`dingToken`、`defaultDingToken`、`apiKeyCfg[].apiKey`)支持 `$ENV:VAR_NAME` 形式引用环境变量,避免明文落盘,例如 `"clientSecret": "$ENV:DING_SECRET"`
|
|
161
|
+
- `config.json` 与 `settings-ding.json` 写入时自动收紧为 `600` 权限
|
|
162
|
+
- `/bash` 仅限 owner/管理员执行,所有命令记录到 `~/.cc-ding/{clientId}/bash-audit.log`
|
|
163
|
+
|
|
158
164
|
### 数据存储
|
|
159
165
|
|
|
160
166
|
所有数据存储在 `~/.cc-ding/{clientId}/` 目录下:
|
|
@@ -263,7 +269,7 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
|
|
|
263
269
|
| Command | Description |
|
|
264
270
|
|---------|-------------|
|
|
265
271
|
| `/ls [dir] [depth]` | View directory structure |
|
|
266
|
-
| `/bash <cmd>` | Execute arbitrary commands (
|
|
272
|
+
| `/bash <cmd>` | Execute arbitrary commands (owner/admin only, audited in `bash-audit.log`) |
|
|
267
273
|
|
|
268
274
|
#### Admin (owner only)
|
|
269
275
|
|
|
@@ -318,9 +324,15 @@ pm2 start --name "cc-ding-{clientId}" npx -- -p cc-ding cc-ding run -ci {clientI
|
|
|
318
324
|
| `apiKeyCfg` | API Key pooling: auto-switch on 429, daily reset at midnight |
|
|
319
325
|
| `useLocalOcr` | Local image OCR (default `true`); set `false` if model supports images natively |
|
|
320
326
|
| `linkConversationId` | Link groups to share one Claude session context |
|
|
321
|
-
| `permissionMode` | Claude process permission mode (default `bypassPermissions`), options: `default`, `acceptEdits`, `plan`, `auto`, `bypassPermissions`, `dontAsk` |
|
|
327
|
+
| `permissionMode` | Claude process permission mode (default `acceptEdits`; `bypassPermissions` must be set explicitly and warns at startup), options: `default`, `acceptEdits`, `plan`, `auto`, `bypassPermissions`, `dontAsk` |
|
|
322
328
|
| `preBash` | Global pre-bash command for `/bash` |
|
|
323
329
|
|
|
330
|
+
#### Security Notes
|
|
331
|
+
|
|
332
|
+
- Sensitive fields (`clientSecret`, `dingToken`, `defaultDingToken`, `apiKeyCfg[].apiKey`) support `$ENV:VAR_NAME` references to environment variables, e.g. `"clientSecret": "$ENV:DING_SECRET"`
|
|
333
|
+
- `config.json` and `settings-ding.json` are written with `600` permissions
|
|
334
|
+
- `/bash` is restricted to owner/admin; all commands are audited in `~/.cc-ding/{clientId}/bash-audit.log`
|
|
335
|
+
|
|
324
336
|
### Data Storage
|
|
325
337
|
|
|
326
338
|
All data is stored under `~/.cc-ding/{clientId}/`:
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var __importDefault=this&&this.__importDefault||function(s){return s&&s.__esModule?s:{default:s}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveClientConfig=saveClientConfig,exports.resetApiKeyCfg=resetApiKeyCfg,exports.scheduleApiKeyCfgDailyReset=scheduleApiKeyCfgDailyReset,exports.settingLabel=settingLabel,exports.rotateApiKey=rotateApiKey,exports.pickValidApiKey=pickValidApiKey,exports.ensureSettingsWithApiKey=ensureSettingsWithApiKey,exports.isQuotaExhaustedError=isQuotaExhaustedError,exports.isAuthenticationError=isAuthenticationError,exports.readApiKeyFromSettings=readApiKeyFromSettings,exports.getForceEnabledSettingsPath=getForceEnabledSettingsPath,exports.startupCheck=startupCheck;const fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),child_process_1=require("child_process"),session_1=require("./session"),utils_ok_1=require("utils-ok");function saveClientConfig(s){const e=`${s.getClientDir()}/config.json`;try{fs_1.default.writeFileSync(e,JSON.stringify(s.config,null,2),"utf-8")}catch(n){console.error(`[${(0,session_1.timestamp)()}] \u4FDD\u5B58 config.json \u5931\u8D25:`,n)}}function resetApiKeyCfg(s){const e=s.config.apiKeyCfg;if(!e)return;const n=new Date;e.resetTime=utils_ok_1.dateUtil.mm(n.getTime()).format("YYYY-MM-DD HH:mm:ss");let i=0;for(const l of e.claudeSettings)l.isValid||(l.isValid=!0,i++);i>0&&console.log(`[${(0,session_1.timestamp)()}] ${i} \u4E2A\u5DF2\u5931\u6548 Claude Setting \u91CD\u65B0\u6807\u8BB0\u4E3A\u6709\u6548`),saveClientConfig(s),console.log(`[${(0,session_1.timestamp)()}] apiKeyCfg \u5DF2\u91CD\u7F6E (\u6240\u6709 Claude Setting isValid=true)`)}function scheduleApiKeyCfgDailyReset(s){const e=()=>{const n=new Date,i=new Date(n.getFullYear(),n.getMonth(),n.getDate()+1,0,0,0,0),l=i.getTime()-n.getTime();setTimeout(()=>{console.log(`[${(0,session_1.timestamp)()}] \u5B9A\u65F6\u91CD\u7F6E apiKeyCfg (\u6BCF\u59290\u70B9)`),resetApiKeyCfg(s),e()},l),console.log(`[${(0,session_1.timestamp)()}] apiKeyCfg \u6BCF\u65E5\u91CD\u7F6E\u5DF2\u8C03\u5EA6\uFF0C\u4E0B\u6B21\u91CD\u7F6E: ${i.toISOString()}`)};e()}function settingLabel(s){return s.memo?s.memo:`...${s.apiKey.slice(-6)}`}function findSettingLabel(s,e){const n=s.find(i=>i.apiKey===e);return n?settingLabel(n):`...${e.slice(-6)}`}function rotateApiKey(s,e){const n=s.config.apiKeyCfg;if(!n)return null;for(const r of n.claudeSettings)if(r.apiKey===e&&r.isValid){r.isValid=!1;break}const i=n.claudeSettings.filter(r=>r.isValid).length,l=findSettingLabel(n.claudeSettings,e);return console.log(`[${(0,session_1.timestamp)()}] Claude Setting \u5DF2\u5931\u6548: ${l}, \u5269\u4F59\u6709\u6548: ${i}`),saveClientConfig(s),pickValidApiKey(s)}function pickValidApiKey(s){const e=s.config.apiKeyCfg;if(!e)return null;const n=e.claudeSettings.filter(i=>i.isValid);return n.length===0?null:n[Math.floor(Math.random()*n.length)]}function ensureSettingsWithApiKey(s,e){const n=path_1.default.join(s,".claude"),i=path_1.default.join(n,"settings-ding.json");let l={};if(fs_1.default.existsSync(i))try{l=JSON.parse(fs_1.default.readFileSync(i,"utf-8"))}catch{l={}}else{const g=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding","settings-tpl.json");if(fs_1.default.existsSync(g))try{l=JSON.parse(fs_1.default.readFileSync(g,"utf-8")),console.log(`[${(0,session_1.timestamp)()}] \u4ECE\u6A21\u677F\u521B\u5EFA settings-ding.json: ${g}`)}catch{l={}}}l.env||(l.env={});let r=!1;l.env.ANTHROPIC_AUTH_TOKEN!==e.apiKey&&(l.env.ANTHROPIC_AUTH_TOKEN=e.apiKey,r=!0),e.baseUrl&&l.env.ANTHROPIC_BASE_URL!==e.baseUrl&&(l.env.ANTHROPIC_BASE_URL=e.baseUrl,r=!0),e.model&&l.env.ANTHROPIC_MODEL!==e.model&&(l.env.ANTHROPIC_MODEL=e.model,r=!0);const f=e.smallModel||e.model;return f&&l.env.CLAUDE_SMALL_FAST_MODEL!==f&&(l.env.CLAUDE_SMALL_FAST_MODEL=f,r=!0),r&&(fs_1.default.mkdirSync(n,{recursive:!0}),fs_1.default.writeFileSync(i,JSON.stringify(l,null,2),"utf-8"),console.log(`[${(0,session_1.timestamp)()}] \u5DF2\u5199\u5165 Claude \u914D\u7F6E\u5230 ${i} (${settingLabel(e)}, model: ${e.model}, smallModel: ${f})`)),i}function isQuotaExhaustedError(s){return!!(/Request\s+rejected.*429/i.test(s)||/429.*Request\s+rejected/i.test(s)||/429.*(?:超过.*上限|使用上限|配额|quota|capacity)/i.test(s)||/(?:超过.*上限|使用上限|配额|quota|capacity).*429/i.test(s))}function isAuthenticationError(s){return!!(/authentication_error/i.test(s)||/401.*(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth)/i.test(s)||/(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth).*401/i.test(s))}function readApiKeyFromSettings(s){const e=path_1.default.join(s,".claude","settings-ding.json");if(!fs_1.default.existsSync(e))return null;try{return JSON.parse(fs_1.default.readFileSync(e,"utf-8")).env?.ANTHROPIC_AUTH_TOKEN||null}catch{return null}}function getForceEnabledSettingsPath(s){const e=path_1.default.join(s,".claude","settings-ding.json");if(!fs_1.default.existsSync(e))return null;try{const i=JSON.parse(fs_1.default.readFileSync(e,"utf-8")).env?.FORCE_ENABLE;return i!==void 0&&i!==!1&&i!==""?(console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230 settings-ding.json FORCE_ENABLE=${i}\uFF0C\u5F3A\u5236\u4F7F\u7528\u8BE5\u914D\u7F6E`),e):null}catch{return null}}function startupCheck(s){const e=[],n=s.config,i=s.getClientDir(),l=[{key:"clientSecret",label:"clientSecret (\u9489\u9489 Stream Client \u5BC6\u94A5)"},{key:"whiteUserList",label:"whiteUserList (\u767D\u540D\u5355\u7528\u6237)"},{key:"owner",label:"owner (\u673A\u5668\u4EBA owner)"}];for(const{key:t,label:a}of l){const o=n[t];o==null||o===""||Array.isArray(o)&&o.length===0?e.push({level:"FATAL",message:`config.json \u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5: ${a}`}):e.push({level:"PASS",message:`config.json ${a} \u2713`})}if(!Array.isArray(n.conversations))e.push({level:"FATAL",message:"conversations \u5E94\u4E3A\u6570\u7EC4\u6216\u5DF2\u914D\u7F6E"});else if(n.conversations.length===0)e.push({level:"PASS",message:"conversations \u4E3A\u7A7A\u6570\u7EC4\uFF0C\u53EF\u901A\u8FC7 /reg \u547D\u4EE4\u52A8\u6001\u6CE8\u518C"});else{const t=new Set;for(let a=0;a<n.conversations.length;a++){const o=n.conversations[a],c=`conversations[${a}]`;o.conversationId?t.has(o.conversationId)?e.push({level:"WARN",message:`${c} conversationId \u91CD\u590D: ${o.conversationId}`}):t.add(o.conversationId):e.push({level:"FATAL",message:`${c} \u7F3A\u5C11 conversationId`}),o.linkConversationId&&!n.conversations.some(u=>u.conversationId===o.linkConversationId)&&e.push({level:"WARN",message:`${c} linkConversationId "${o.linkConversationId}" \u672A\u5728 conversations \u4E2D\u627E\u5230`})}e.push({level:"PASS",message:`conversations \u5171 ${n.conversations.length} \u4E2A\u7FA4\u914D\u7F6E`})}if(n.apiKeyCfg){const t=n.apiKeyCfg;if(t.resetTime&&e.push({level:"PASS",message:`apiKeyCfg \u4E0A\u6B21\u91CD\u7F6E\u65F6\u95F4: ${t.resetTime}`}),!Array.isArray(t.claudeSettings))e.push({level:"WARN",message:"apiKeyCfg.claudeSettings \u4E0D\u662F\u6570\u7EC4\uFF0CAPI Key \u8F6E\u6362\u529F\u80FD\u4E0D\u53EF\u7528"});else if(t.claudeSettings.length===0)e.push({level:"WARN",message:"apiKeyCfg.claudeSettings \u4E3A\u7A7A\uFF0C\u65E0\u53EF\u7528 Key"});else{const a=new Set;for(let c=0;c<t.claudeSettings.length;c++){const u=t.claudeSettings[c],d=`apiKeyCfg.claudeSettings[${c}]`;u.apiKey?a.has(u.apiKey)?e.push({level:"WARN",message:`${d} apiKey \u91CD\u590D: ${settingLabel(u)}`}):a.add(u.apiKey):e.push({level:"FATAL",message:`${d} \u7F3A\u5C11 apiKey`}),u.baseUrl||e.push({level:"WARN",message:`${d} \u7F3A\u5C11 baseUrl`}),u.model||e.push({level:"WARN",message:`${d} \u7F3A\u5C11 model`}),typeof u.isValid!="boolean"&&e.push({level:"WARN",message:`${d} isValid \u7C7B\u578B\u5F02\u5E38: ${typeof u.isValid}`})}const o=t.claudeSettings.filter(c=>c.isValid).length;e.push({level:"PASS",message:`apiKeyCfg.claudeSettings \u5171 ${t.claudeSettings.length} \u9879\uFF0C\u6709\u6548 ${o}`})}}const r=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding","settings-tpl.json");if(fs_1.default.existsSync(r))try{const t=JSON.parse(fs_1.default.readFileSync(r,"utf-8"));if(typeof t!="object"||t===null)e.push({level:"WARN",message:"settings-tpl.json \u6839\u5143\u7D20\u4E0D\u662F\u5BF9\u8C61"});else if(!t.env||typeof t.env!="object")e.push({level:"WARN",message:"settings-tpl.json \u7F3A\u5C11 env \u5B57\u6BB5\uFF0C\u521B\u5EFA settings-ding.json \u65F6\u5C06\u4E0D\u5305\u542B\u9884\u914D\u7F6E\u73AF\u5883\u53D8\u91CF"});else{const a=Object.keys(t.env);e.push({level:"PASS",message:`settings-tpl.json \u6709\u6548\uFF0Cenv \u5305\u542B: ${a.join(", ")||"(\u7A7A)"}`})}}catch(t){e.push({level:"WARN",message:`settings-tpl.json \u89E3\u6790\u5931\u8D25: ${t instanceof Error?t.message:t}`})}else e.push({level:"WARN",message:`settings-tpl.json \u4E0D\u5B58\u5728: ${r}\uFF0C\u521B\u5EFA settings-ding.json \u65F6\u5C06\u4F7F\u7528\u7A7A\u6A21\u677F`});try{(0,child_process_1.execSync)("which claude",{stdio:"pipe"}),e.push({level:"PASS",message:"claude \u547D\u4EE4\u53EF\u7528"})}catch{e.push({level:"FATAL",message:"claude \u547D\u4EE4\u4E0D\u53EF\u7528\uFF0C\u8BF7\u786E\u8BA4 Claude Code CLI \u5DF2\u5B89\u88C5"})}try{const t=path_1.default.join(i,".healthcheck");fs_1.default.writeFileSync(t,"ok","utf-8"),fs_1.default.unlinkSync(t),e.push({level:"PASS",message:`\u5DE5\u4F5C\u76EE\u5F55\u53EF\u5199: ${i}`})}catch(t){e.push({level:"FATAL",message:`\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u53EF\u5199: ${i} \u2014 ${t instanceof Error?t.message:t}`})}if(Array.isArray(n.conversations))for(const t of n.conversations){const a=s.getConversationDir(t.conversationId);try{fs_1.default.mkdirSync(a,{recursive:!0}),e.push({level:"PASS",message:`\u7FA4\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u5C31\u7EEA: ${t.conversationTitle||t.conversationId}`})}catch(o){e.push({level:"WARN",message:`\u7FA4\u5DE5\u4F5C\u76EE\u5F55\u521B\u5EFA\u5931\u8D25: ${a} \u2014 ${o instanceof Error?o.message:o}`})}}console.log(`
|
|
2
|
-
[${(0,session_1.timestamp)()}] ========== \u542F\u52A8\u81EA\u68C0 ==========`);const
|
|
3
|
-
`),
|
|
1
|
+
"use strict";var __importDefault=this&&this.__importDefault||function(s){return s&&s.__esModule?s:{default:s}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveClientConfig=saveClientConfig,exports.resetApiKeyCfg=resetApiKeyCfg,exports.scheduleApiKeyCfgDailyReset=scheduleApiKeyCfgDailyReset,exports.settingLabel=settingLabel,exports.rotateApiKey=rotateApiKey,exports.pickValidApiKey=pickValidApiKey,exports.ensureSettingsWithApiKey=ensureSettingsWithApiKey,exports.isQuotaExhaustedError=isQuotaExhaustedError,exports.isAuthenticationError=isAuthenticationError,exports.readApiKeyFromSettings=readApiKeyFromSettings,exports.getForceEnabledSettingsPath=getForceEnabledSettingsPath,exports.startupCheck=startupCheck;const fs_1=__importDefault(require("fs")),path_1=__importDefault(require("path")),child_process_1=require("child_process"),session_1=require("./session"),utils_ok_1=require("utils-ok"),secrets_1=require("./secrets"),platform_1=require("./platform");function saveClientConfig(s){const e=`${s.getClientDir()}/config.json`;try{fs_1.default.writeFileSync(e,JSON.stringify(s.config,null,2),{encoding:"utf-8",mode:(0,platform_1.isWindows)()?void 0:384}),(0,platform_1.isWindows)()||fs_1.default.chmodSync(e,384)}catch(n){console.error(`[${(0,session_1.timestamp)()}] \u4FDD\u5B58 config.json \u5931\u8D25:`,n)}}function resetApiKeyCfg(s){const e=s.config.apiKeyCfg;if(!e)return;const n=new Date;e.resetTime=utils_ok_1.dateUtil.mm(n.getTime()).format("YYYY-MM-DD HH:mm:ss");let i=0;for(const l of e.claudeSettings)l.isValid||(l.isValid=!0,i++);i>0&&console.log(`[${(0,session_1.timestamp)()}] ${i} \u4E2A\u5DF2\u5931\u6548 Claude Setting \u91CD\u65B0\u6807\u8BB0\u4E3A\u6709\u6548`),saveClientConfig(s),console.log(`[${(0,session_1.timestamp)()}] apiKeyCfg \u5DF2\u91CD\u7F6E (\u6240\u6709 Claude Setting isValid=true)`)}function scheduleApiKeyCfgDailyReset(s){const e=()=>{const n=new Date,i=new Date(n.getFullYear(),n.getMonth(),n.getDate()+1,0,0,0,0),l=i.getTime()-n.getTime();setTimeout(()=>{console.log(`[${(0,session_1.timestamp)()}] \u5B9A\u65F6\u91CD\u7F6E apiKeyCfg (\u6BCF\u59290\u70B9)`),resetApiKeyCfg(s),e()},l),console.log(`[${(0,session_1.timestamp)()}] apiKeyCfg \u6BCF\u65E5\u91CD\u7F6E\u5DF2\u8C03\u5EA6\uFF0C\u4E0B\u6B21\u91CD\u7F6E: ${i.toISOString()}`)};e()}function settingLabel(s){return s.memo?s.memo:`...${s.apiKey.slice(-6)}`}function findSettingLabel(s,e){const n=s.find(i=>(0,secrets_1.resolveSecret)(i.apiKey)===(0,secrets_1.resolveSecret)(e));return n?settingLabel(n):`...${e.slice(-6)}`}function rotateApiKey(s,e){const n=s.config.apiKeyCfg;if(!n)return null;for(const r of n.claudeSettings)if((0,secrets_1.resolveSecret)(r.apiKey)===(0,secrets_1.resolveSecret)(e)&&r.isValid){r.isValid=!1;break}const i=n.claudeSettings.filter(r=>r.isValid).length,l=findSettingLabel(n.claudeSettings,e);return console.log(`[${(0,session_1.timestamp)()}] Claude Setting \u5DF2\u5931\u6548: ${l}, \u5269\u4F59\u6709\u6548: ${i}`),saveClientConfig(s),pickValidApiKey(s)}function pickValidApiKey(s){const e=s.config.apiKeyCfg;if(!e)return null;const n=e.claudeSettings.filter(i=>i.isValid);return n.length===0?null:n[Math.floor(Math.random()*n.length)]}function ensureSettingsWithApiKey(s,e){const n=path_1.default.join(s,".claude"),i=path_1.default.join(n,"settings-ding.json");let l={};if(fs_1.default.existsSync(i))try{l=JSON.parse(fs_1.default.readFileSync(i,"utf-8"))}catch{l={}}else{const g=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding","settings-tpl.json");if(fs_1.default.existsSync(g))try{l=JSON.parse(fs_1.default.readFileSync(g,"utf-8")),console.log(`[${(0,session_1.timestamp)()}] \u4ECE\u6A21\u677F\u521B\u5EFA settings-ding.json: ${g}`)}catch{l={}}}l.env||(l.env={});let r=!1;const f=(0,secrets_1.resolveSecret)(e.apiKey);l.env.ANTHROPIC_AUTH_TOKEN!==f&&(l.env.ANTHROPIC_AUTH_TOKEN=f,r=!0),e.baseUrl&&l.env.ANTHROPIC_BASE_URL!==e.baseUrl&&(l.env.ANTHROPIC_BASE_URL=e.baseUrl,r=!0),e.model&&l.env.ANTHROPIC_MODEL!==e.model&&(l.env.ANTHROPIC_MODEL=e.model,r=!0);const d=e.smallModel||e.model;return d&&l.env.CLAUDE_SMALL_FAST_MODEL!==d&&(l.env.CLAUDE_SMALL_FAST_MODEL=d,r=!0),r&&(fs_1.default.mkdirSync(n,{recursive:!0}),fs_1.default.writeFileSync(i,JSON.stringify(l,null,2),{encoding:"utf-8",mode:(0,platform_1.isWindows)()?void 0:384}),(0,platform_1.isWindows)()||fs_1.default.chmodSync(i,384),console.log(`[${(0,session_1.timestamp)()}] \u5DF2\u5199\u5165 Claude \u914D\u7F6E\u5230 ${i} (${settingLabel(e)}, model: ${e.model}, smallModel: ${d})`)),i}function isQuotaExhaustedError(s){return!!(/Request\s+rejected.*429/i.test(s)||/429.*Request\s+rejected/i.test(s)||/429.*(?:超过.*上限|使用上限|配额|quota|capacity)/i.test(s)||/(?:超过.*上限|使用上限|配额|quota|capacity).*429/i.test(s))}function isAuthenticationError(s){return!!(/authentication_error/i.test(s)||/401.*(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth)/i.test(s)||/(?:未授权|unauthorized|invalid\s*(?:key|token|api)|auth).*401/i.test(s))}function readApiKeyFromSettings(s){const e=path_1.default.join(s,".claude","settings-ding.json");if(!fs_1.default.existsSync(e))return null;try{return JSON.parse(fs_1.default.readFileSync(e,"utf-8")).env?.ANTHROPIC_AUTH_TOKEN||null}catch{return null}}function getForceEnabledSettingsPath(s){const e=path_1.default.join(s,".claude","settings-ding.json");if(!fs_1.default.existsSync(e))return null;try{const i=JSON.parse(fs_1.default.readFileSync(e,"utf-8")).env?.FORCE_ENABLE;return i!==void 0&&i!==!1&&i!==""?(console.log(`[${(0,session_1.timestamp)()}] \u68C0\u6D4B\u5230 settings-ding.json FORCE_ENABLE=${i}\uFF0C\u5F3A\u5236\u4F7F\u7528\u8BE5\u914D\u7F6E`),e):null}catch{return null}}function startupCheck(s){const e=[],n=s.config,i=s.getClientDir(),l=[{key:"clientSecret",label:"clientSecret (\u9489\u9489 Stream Client \u5BC6\u94A5)"},{key:"whiteUserList",label:"whiteUserList (\u767D\u540D\u5355\u7528\u6237)"},{key:"owner",label:"owner (\u673A\u5668\u4EBA owner)"}];for(const{key:t,label:o}of l){const a=n[t];a==null||a===""||Array.isArray(a)&&a.length===0?e.push({level:"FATAL",message:`config.json \u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5: ${o}`}):e.push({level:"PASS",message:`config.json ${o} \u2713`})}if(!Array.isArray(n.conversations))e.push({level:"FATAL",message:"conversations \u5E94\u4E3A\u6570\u7EC4\u6216\u5DF2\u914D\u7F6E"});else if(n.conversations.length===0)e.push({level:"PASS",message:"conversations \u4E3A\u7A7A\u6570\u7EC4\uFF0C\u53EF\u901A\u8FC7 /reg \u547D\u4EE4\u52A8\u6001\u6CE8\u518C"});else{const t=new Set;for(let o=0;o<n.conversations.length;o++){const a=n.conversations[o],c=`conversations[${o}]`;a.conversationId?t.has(a.conversationId)?e.push({level:"WARN",message:`${c} conversationId \u91CD\u590D: ${a.conversationId}`}):t.add(a.conversationId):e.push({level:"FATAL",message:`${c} \u7F3A\u5C11 conversationId`}),a.linkConversationId&&!n.conversations.some(u=>u.conversationId===a.linkConversationId)&&e.push({level:"WARN",message:`${c} linkConversationId "${a.linkConversationId}" \u672A\u5728 conversations \u4E2D\u627E\u5230`})}e.push({level:"PASS",message:`conversations \u5171 ${n.conversations.length} \u4E2A\u7FA4\u914D\u7F6E`})}for(const t of n.conversations||[])if(t.permissionMode==="bypassPermissions"){const o=t.conversationTitle||t.conversationId;e.push({level:"WARN",message:`\u4F1A\u8BDD "${o}" \u914D\u7F6E\u4E86 bypassPermissions\uFF0CClaude \u5C06\u8DF3\u8FC7\u6240\u6709\u6743\u9650\u786E\u8BA4\uFF0C\u8BF7\u786E\u8BA4\u8BE5\u7FA4\u6210\u5458\u53EF\u4FE1`})}if(!(0,platform_1.isWindows)()){const t=path_1.default.join(i,"config.json");try{const o=fs_1.default.statSync(t).mode&511;o&63&&(fs_1.default.chmodSync(t,384),e.push({level:"WARN",message:`config.json \u6743\u9650\u8FC7\u5BBD (${o.toString(8)})\uFF0C\u5DF2\u81EA\u52A8\u6536\u7D27\u4E3A 600`}))}catch{}}const r=[{value:n.clientSecret,label:"clientSecret"},{value:n.defaultDingToken,label:"defaultDingToken"},...(n.conversations||[]).map((t,o)=>({value:t.dingToken,label:`conversations[${o}].dingToken`})),...(n.apiKeyCfg?.claudeSettings||[]).map((t,o)=>({value:t.apiKey,label:`apiKeyCfg.claudeSettings[${o}].apiKey`}))];for(const{value:t,label:o}of r)(0,secrets_1.isEnvRef)(t)&&!(0,secrets_1.resolveSecret)(t)&&e.push({level:"FATAL",message:`${o} \u5F15\u7528\u7684\u73AF\u5883\u53D8\u91CF\u672A\u8BBE\u7F6E: ${t}`});if(n.apiKeyCfg){const t=n.apiKeyCfg;if(t.resetTime&&e.push({level:"PASS",message:`apiKeyCfg \u4E0A\u6B21\u91CD\u7F6E\u65F6\u95F4: ${t.resetTime}`}),!Array.isArray(t.claudeSettings))e.push({level:"WARN",message:"apiKeyCfg.claudeSettings \u4E0D\u662F\u6570\u7EC4\uFF0CAPI Key \u8F6E\u6362\u529F\u80FD\u4E0D\u53EF\u7528"});else if(t.claudeSettings.length===0)e.push({level:"WARN",message:"apiKeyCfg.claudeSettings \u4E3A\u7A7A\uFF0C\u65E0\u53EF\u7528 Key"});else{const o=new Set;for(let c=0;c<t.claudeSettings.length;c++){const u=t.claudeSettings[c],p=`apiKeyCfg.claudeSettings[${c}]`;u.apiKey?o.has(u.apiKey)?e.push({level:"WARN",message:`${p} apiKey \u91CD\u590D: ${settingLabel(u)}`}):o.add(u.apiKey):e.push({level:"FATAL",message:`${p} \u7F3A\u5C11 apiKey`}),u.baseUrl||e.push({level:"WARN",message:`${p} \u7F3A\u5C11 baseUrl`}),u.model||e.push({level:"WARN",message:`${p} \u7F3A\u5C11 model`}),typeof u.isValid!="boolean"&&e.push({level:"WARN",message:`${p} isValid \u7C7B\u578B\u5F02\u5E38: ${typeof u.isValid}`})}const a=t.claudeSettings.filter(c=>c.isValid).length;e.push({level:"PASS",message:`apiKeyCfg.claudeSettings \u5171 ${t.claudeSettings.length} \u9879\uFF0C\u6709\u6548 ${a}`})}}const f=path_1.default.join((0,session_1.getHomeDir)(),".cc-ding","settings-tpl.json");if(fs_1.default.existsSync(f))try{const t=JSON.parse(fs_1.default.readFileSync(f,"utf-8"));if(typeof t!="object"||t===null)e.push({level:"WARN",message:"settings-tpl.json \u6839\u5143\u7D20\u4E0D\u662F\u5BF9\u8C61"});else if(!t.env||typeof t.env!="object")e.push({level:"WARN",message:"settings-tpl.json \u7F3A\u5C11 env \u5B57\u6BB5\uFF0C\u521B\u5EFA settings-ding.json \u65F6\u5C06\u4E0D\u5305\u542B\u9884\u914D\u7F6E\u73AF\u5883\u53D8\u91CF"});else{const o=Object.keys(t.env);e.push({level:"PASS",message:`settings-tpl.json \u6709\u6548\uFF0Cenv \u5305\u542B: ${o.join(", ")||"(\u7A7A)"}`})}}catch(t){e.push({level:"WARN",message:`settings-tpl.json \u89E3\u6790\u5931\u8D25: ${t instanceof Error?t.message:t}`})}else e.push({level:"WARN",message:`settings-tpl.json \u4E0D\u5B58\u5728: ${f}\uFF0C\u521B\u5EFA settings-ding.json \u65F6\u5C06\u4F7F\u7528\u7A7A\u6A21\u677F`});try{(0,child_process_1.execSync)(process.platform==="win32"?"where claude":"which claude",{stdio:"pipe"}),e.push({level:"PASS",message:"claude \u547D\u4EE4\u53EF\u7528"})}catch{e.push({level:"FATAL",message:"claude \u547D\u4EE4\u4E0D\u53EF\u7528\uFF0C\u8BF7\u786E\u8BA4 Claude Code CLI \u5DF2\u5B89\u88C5"})}try{const t=path_1.default.join(i,".healthcheck");fs_1.default.writeFileSync(t,"ok","utf-8"),fs_1.default.unlinkSync(t),e.push({level:"PASS",message:`\u5DE5\u4F5C\u76EE\u5F55\u53EF\u5199: ${i}`})}catch(t){e.push({level:"FATAL",message:`\u5DE5\u4F5C\u76EE\u5F55\u4E0D\u53EF\u5199: ${i} \u2014 ${t instanceof Error?t.message:t}`})}if(Array.isArray(n.conversations))for(const t of n.conversations){const o=s.getConversationDir(t.conversationId);try{fs_1.default.mkdirSync(o,{recursive:!0}),e.push({level:"PASS",message:`\u7FA4\u5DE5\u4F5C\u76EE\u5F55\u5DF2\u5C31\u7EEA: ${t.conversationTitle||t.conversationId}`})}catch(a){e.push({level:"WARN",message:`\u7FA4\u5DE5\u4F5C\u76EE\u5F55\u521B\u5EFA\u5931\u8D25: ${o} \u2014 ${a instanceof Error?a.message:a}`})}}console.log(`
|
|
2
|
+
[${(0,session_1.timestamp)()}] ========== \u542F\u52A8\u81EA\u68C0 ==========`);const d=e.some(t=>t.level==="FATAL");for(const t of e){const o=t.level==="PASS"?"\u2713":t.level==="FATAL"?"\u2717":"\u26A0",a=t.level==="PASS"?t.message:t.level==="FATAL"?`[FATAL] ${t.message}`:`[WARN] ${t.message}`;console.log(` ${o} ${a}`)}const g=e.filter(t=>t.level==="PASS").length,v=e.filter(t=>t.level==="WARN").length,m=e.filter(t=>t.level==="FATAL").length;console.log(`[${(0,session_1.timestamp)()}] \u81EA\u68C0\u5B8C\u6210: ${g} \u901A\u8FC7, ${v} \u8B66\u544A, ${m} \u81F4\u547D`),console.log(`[${(0,session_1.timestamp)()}] ==============================
|
|
3
|
+
`),d&&(console.error(`[${(0,session_1.timestamp)()}] \u542F\u52A8\u81EA\u68C0\u53D1\u73B0\u81F4\u547D\u9519\u8BEF\uFF0C\u8FDB\u7A0B\u9000\u51FA`),process.exit(1))}
|
|
@@ -1,85 +1,90 @@
|
|
|
1
|
-
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(
|
|
2
|
-
|
|
3
|
-
`)
|
|
1
|
+
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(v,r,t,n){n===void 0&&(n=t);var a=Object.getOwnPropertyDescriptor(r,t);(!a||("get"in a?!r.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(v,n,a)}):(function(v,r,t,n){n===void 0&&(n=t),v[n]=r[t]})),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(v,r){Object.defineProperty(v,"default",{enumerable:!0,value:r})}):function(v,r){v.default=r}),__importStar=this&&this.__importStar||(function(){var v=function(r){return v=Object.getOwnPropertyNames||function(t){var n=[];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(n[n.length]=a);return n},v(r)};return function(r){if(r&&r.__esModule)return r;var t={};if(r!=null)for(var n=v(r),a=0;a<n.length;a++)n[a]!=="default"&&__createBinding(t,r,n[a]);return __setModuleDefault(t,r),t}})(),__importDefault=this&&this.__importDefault||function(v){return v&&v.__esModule?v:{default:v}};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"),menu_1=require("./menu"),session_1=require("./session"),task_1=require("./task"),todo_1=require("./todo"),commands_2=require("./commands"),api_key_manager_1=require("./api-key-manager"),secrets_1=require("./secrets"),command_route_1=require("./command-route"),cron_1=require("./cron"),platform_1=require("./platform"),TOOL_VERSION=(0,common_1.projUtil)().getPkgVersion();class DingClaude{constructor(r){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=t=>(0,messaging_2.sendDingMessage)(this,t),this.sendClaudeResponseToDing=(t,n,a,s)=>(0,messaging_2.sendClaudeResponseToDing)(this,t,n,a,s),this.parseClaudeStreamLine=claude_process_1.parseClaudeStreamLine,this.interruptClaudeProcess=(t,n)=>(0,claude_process_1.interruptClaudeProcess)(t,n),this.executeClaudeQuery=(t,n,a)=>(0,claude_process_1.executeClaudeQuery)(this,t,n,a),this.getClientDir=()=>(0,session_1.getClientDir)(this),this.getClientConfig=()=>(0,session_1.getClientConfig)(this),this.authCheck=(t,n)=>(0,session_1.authCheck)(this,t,n),this.isOwner=t=>(0,session_1.isOwner)(this,t),this.isAdmin=t=>(0,session_1.isAdmin)(this,t),this.debugLog=(t,...n)=>(0,session_1.debugLog)(this,t,...n),this.hashConversationId=t=>(0,session_1.hashConversationId)(this,t),this.getConversationConfig=t=>(0,session_1.getConversationConfig)(this,t),this.getConversationDir=t=>(0,session_1.getConversationDir)(this,t),this.getSessionsDir=t=>(0,session_1.getSessionsDir)(this,t),this.getTasksDir=t=>(0,session_1.getTasksDir)(this,t),this.getSessionDir=t=>(0,session_1.getSessionDir)(this,t),this.getSessionId=session_1.getSessionId,this.formatSessionInfo=t=>(0,session_1.formatSessionInfo)(this,t),this.readSessionLogTail=(t,n)=>(0,session_1.readSessionLogTail)(this,t,n),this.findActiveSession=t=>(0,session_1.findActiveSession)(this,t),this.findHistorySession=(t,n)=>(0,session_1.findHistorySession)(this,t,n),this.findLatestSession=t=>(0,session_1.findLatestSession)(this,t),this.updateSessionFile=(t,n)=>(0,session_1.updateSessionFile)(this,t,n),this.appendSessionLog=session_1.appendSessionLog,this.getActiveSessionsFile=t=>(0,session_1.getActiveSessionsFile)(this,t),this.saveActiveSession=t=>(0,session_1.saveActiveSession)(this,t),this.loadActiveSessions=()=>(0,session_1.loadActiveSessions)(this),this.endSession=(t,n)=>(0,session_1.endSession)(this,t,n),this.switchToSession=(t,n,a,s,g)=>(0,session_1.switchToSession)(this,t,n,a,s,g),this.startNewSession=t=>(0,session_1.startNewSession)(this,t),this.handleSessionMessage=t=>(0,session_1.handleSessionMessage)(this,t),this.cleanCache=(t,n=!0)=>(0,session_1.cleanCache)(this,t,n),this.formatTaskInfo=()=>(0,task_1.formatTaskInfo)(this),this.cancelTask=(t,n)=>(0,task_1.cancelTask)(this,t,n),this.countTodoTask=()=>(0,task_1.countTodoTask)(this),this.getOneTodoTask=()=>(0,task_1.getOneTodoTask)(this),this.finishTask=t=>(0,task_1.finishTask)(this,t),this.handleTask=()=>(0,task_1.handleTask)(this),this.runTaskHandlerLoop=()=>(0,task_1.runTaskHandlerLoop)(this),this.saveTask=t=>(0,task_1.saveTask)(this,t),this.clientId=r,this.config=(0,session_1.getClientConfig)(this);try{this.dingStreamClient=new utils_ok_1.DingStreamClient({clientId:r,clientSecret:(0,secrets_1.resolveSecret)(this.config.clientSecret),keepAlive:!0,debug:this.config.debug??!1})}catch(t){console.error("Error: DingStreamClient init failed.",t),process.exit(1)}this.cronEngine=new cron_1.CronEngine(this)}async requireOwnerOrAdmin(r,t,n){return this.isOwner(n)||this.isAdmin(n)?!0:(await this.sendDingMessage({conversationId:r,sessionWebhook:t,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u6216\u7BA1\u7406\u5458\u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}appendBashAudit(r,t,n){try{const a=path_1.default.join(this.getClientDir(),"bash-audit.log"),s=`[${(0,session_1.timestamp)()}] conversation=${r} user=${t} cmd=${JSON.stringify(n)}
|
|
2
|
+
`;fs_1.default.appendFileSync(a,s,{encoding:"utf-8",mode:(0,platform_1.isWindows)()?void 0:384})}catch(a){console.error("\u5199\u5165 bash \u5BA1\u8BA1\u65E5\u5FD7\u5931\u8D25:",a)}}async requireOwner(r,t,n){return this.isOwner(n)?!0:(await this.sendDingMessage({conversationId:r,sessionWebhook:t,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async requireOwnerOrSingleChat(r,t,n,a){return this.isOwner(n)||a?.conversationType==="1"?!0:(await this.sendDingMessage({conversationId:r,sessionWebhook:t,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6267\u884C\u6B64\u64CD\u4F5C",msgType:"markdown"}),!1)}async handleAuthRequest(r){const{senderStaffId:t,senderNick:n,conversationId:a,conversationType:s,conversationTitle:g,sessionWebhook:i}=r;if(!this.config.ownerConversationId){await this.sendDingMessage({conversationId:a,sessionWebhook:i,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:** \`${a}\``,`- **\u6CE8\u518C\u547D\u4EE4:** \`/cfg --conversationId ${a}\``].join(`
|
|
3
|
+
`),msgType:"markdown"});return}for(const I of this.pendingAuthRequests.values())if(I.senderStaffId===t&&I.conversationId===a){await this.sendDingMessage({conversationId:a,sessionWebhook:i,content:"\u23F3 \u6388\u6743\u7533\u8BF7\u5DF2\u53D1\u9001\uFF0C\u8BF7\u7B49\u5F85\u7BA1\u7406\u5458\u5BA1\u6279...",msgType:"markdown"});return}const h=`r${Date.now().toString(36)}`,m={id:h,senderStaffId:t,senderNick:n,conversationId:a,conversationType:s,conversationTitle:g,requestTime:Date.now()};this.pendingAuthRequests.set(h,m),console.log(`[${(0,session_1.timestamp)()}] \u65B0\u6388\u6743\u7533\u8BF7: id=${h}, userId=${t}, \u6635\u79F0=${n}, \u4F1A\u8BDD=${a}`);const $=["\u{1F4CB} **\u6536\u5230\u6388\u6743\u7533\u8BF7**",`- **\u7528\u6237ID:** ${t}`,`- **\u6635\u79F0:** ${n}`,`- **\u4F1A\u8BDDID:** ${a}`,g?`- **\u4F1A\u8BDD\u6807\u9898:** ${g}`:"",`- **\u4F1A\u8BDD\u7C7B\u578B:** ${s==="1"?"\u5355\u804A":s==="2"?"\u7FA4\u804A":s||"-"}`,"",`\u56DE\u590D \`/auth approve ${h}\` \u901A\u8FC7`,`\u56DE\u590D \`/auth reject ${h}\` \u62D2\u7EDD`].filter(Boolean).join(`
|
|
4
|
+
`);await(0,messaging_1.sendOwnerMessage)(this,$,"markdown")?await this.sendDingMessage({conversationId:a,sessionWebhook:i,content:"\u2705 \u5DF2\u5411\u7BA1\u7406\u5458\u53D1\u9001\u6388\u6743\u7533\u8BF7\uFF0C\u8BF7\u7B49\u5F85\u5BA1\u6279...",msgType:"markdown"}):(this.pendingAuthRequests.delete(h),await this.sendDingMessage({conversationId:a,sessionWebhook:i,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(r,t){const{conversationId:n,sessionWebhook:a,senderStaffId:s,senderNick:g,conversationConfig:i}=t;switch(r.type){case"list":{const h=await this.getOrCreateLogSession(n,a,s,g,i,!0),m=this.cronEngine.listJobs(n);h.sessionDir&&(this.appendSessionLog(h.sessionDir,"user","/cron list"),this.appendSessionLog(h.sessionDir,"assistant",`\u5217\u51FA ${m.length} \u4E2A\u5B9A\u65F6\u4EFB\u52A1`)),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:(0,cron_1.formatCronJobList)(m),msgType:"markdown"});return}case"delete":{const h=this.cronEngine.removeJob(r.id),m=await this.getOrCreateLogSession(n,a,s,g,i);m.sessionDir&&(this.appendSessionLog(m.sessionDir,"user",`/cron delete ${r.id}`),this.appendSessionLog(m.sessionDir,"assistant",h?`\u5220\u9664\u5B9A\u65F6\u4EFB\u52A1 ${r.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${r.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:h?`\u2705 \u5B9A\u65F6\u4EFB\u52A1 **${r.id}** \u5DF2\u5220\u9664`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${r.id}`,msgType:"markdown"});return}case"pause":{const h=this.cronEngine.toggleJob(r.id,!1),m=await this.getOrCreateLogSession(n,a,s,g,i);m.sessionDir&&(this.appendSessionLog(m.sessionDir,"user",`/cron pause ${r.id}`),this.appendSessionLog(m.sessionDir,"assistant",h?`\u6682\u505C\u5B9A\u65F6\u4EFB\u52A1 ${r.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${r.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:h?`\u23F8\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${r.id}** \u5DF2\u6682\u505C`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${r.id}`,msgType:"markdown"});return}case"resume":{const h=this.cronEngine.toggleJob(r.id,!0),m=await this.getOrCreateLogSession(n,a,s,g,i);m.sessionDir&&(this.appendSessionLog(m.sessionDir,"user",`/cron resume ${r.id}`),this.appendSessionLog(m.sessionDir,"assistant",h?`\u6062\u590D\u5B9A\u65F6\u4EFB\u52A1 ${r.id}`:`\u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${r.id}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:h?`\u25B6\uFE0F \u5B9A\u65F6\u4EFB\u52A1 **${r.id}** \u5DF2\u6062\u590D`:`\u274C \u672A\u627E\u5230\u5B9A\u65F6\u4EFB\u52A1: ${r.id}`,msgType:"markdown"});return}case"create_cron":{if(!(0,cron_1.isValidCronExpression)(r.cronExpression)){await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u274C \u65E0\u6548\u7684cron\u8868\u8FBE\u5F0F: \`${r.cronExpression}\`
|
|
4
5
|
|
|
5
|
-
\u{1F4A1} \u683C\u5F0F: \`\u5206 \u65F6 \u65E5 \u6708 \u5468\`\uFF0C\u5982 \`0 9 * * *\``,msgType:"markdown"});return}if(!this.hasNotifyCapability(t.conversationConfig)){await this.sendCronNoNotifyError(
|
|
6
|
+
\u{1F4A1} \u683C\u5F0F: \`\u5206 \u65F6 \u65E5 \u6708 \u5468\`\uFF0C\u5982 \`0 9 * * *\``,msgType:"markdown"});return}if(!this.hasNotifyCapability(t.conversationConfig)){await this.sendCronNoNotifyError(n,a);return}const h=this.cronEngine.addJob({conversationId:n,cronExpression:r.cronExpression,description:this.sanitizeLogContent(r.prompt.substring(0,50)),prompt:r.prompt,senderStaffId:s,senderNick:g}),m=await this.getOrCreateLogSession(n,a,s,g,i);m.sessionDir&&(this.appendSessionLog(m.sessionDir,"user",`/cron ${r.cronExpression} ${this.sanitizeLogContent(r.prompt)}`),this.appendSessionLog(m.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${h.id} [${h.cronExpression}] ${h.description}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:(0,cron_1.formatCronJobInfo)(h),msgType:"markdown"});return}case"create_nl":{if(!this.hasNotifyCapability(t.conversationConfig)){await this.sendCronNoNotifyError(n,a);return}await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:"\u23F3 \u6B63\u5728\u5206\u6790\u5B9A\u65F6\u4EFB\u52A1\u63CF\u8FF0..."});const h=await this.cronEngine.analyzeAndCreate(n,r.input,s,g),m=await this.getOrCreateLogSession(n,a,s,g,i);h.job?(m.sessionDir&&(this.appendSessionLog(m.sessionDir,"user",`/cron ${this.sanitizeLogContent(r.input)}`),this.appendSessionLog(m.sessionDir,"assistant",`\u521B\u5EFA\u5B9A\u65F6\u4EFB\u52A1: ${h.job.id} [${h.job.cronExpression}] ${h.job.description}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:(0,cron_1.formatCronJobInfo)(h.job),msgType:"markdown"})):(m.sessionDir&&(this.appendSessionLog(m.sessionDir,"user",`/cron ${this.sanitizeLogContent(r.input)}`),this.appendSessionLog(m.sessionDir,"assistant",`\u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${h.error}`)),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u274C \u5B9A\u65F6\u4EFB\u52A1\u5206\u6790\u5931\u8D25: ${h.error}
|
|
6
7
|
|
|
7
|
-
\u{1F4A1} \u4F60\u4E5F\u53EF\u4EE5\u76F4\u63A5\u6307\u5B9Acron\u8868\u8FBE\u5F0F: \`/cron 0 9 * * * \u4EFB\u52A1\u63CF\u8FF0\``,msgType:"markdown"}));return}}}async handleTodoCommand(r,t){const{conversationId:
|
|
8
|
+
\u{1F4A1} \u4F60\u4E5F\u53EF\u4EE5\u76F4\u63A5\u6307\u5B9Acron\u8868\u8FBE\u5F0F: \`/cron 0 9 * * * \u4EFB\u52A1\u63CF\u8FF0\``,msgType:"markdown"}));return}}}async handleMenuCommand(r,t){const{conversationId:n,sessionWebhook:a,senderStaffId:s}=t;if((r.type==="add"||r.type==="del")&&r.isGlobal&&!this.isOwner(s)){await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:"\u274C \u5168\u5C40\u83DC\u5355\u4EC5 owner \u53EF\u7BA1\u7406",msgType:"markdown"});return}switch(r.type){case"show":{const g=(0,menu_1.getMergedMenu)(this,n,s),i=(0,menu_1.loadMenuData)(this).global.length;g.length>0&&(0,menu_1.setPendingSelection)(n,s,a,g),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:(0,menu_1.formatMenuDisplay)(g,i),msgType:"markdown"});return}case"add":{const g=(0,menu_1.addMenuItem)(this,n,s,r.isGlobal,"",r.command);await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u2705 \u5DF2\u6DFB\u52A0${r.isGlobal?"\u5168\u5C40":"\u4E2A\u4EBA"}\u5FEB\u6377\u6307\u4EE4: **${g.label}** \u2192 \`${g.command}\``,msgType:"markdown"});return}case"del":{const g=(0,menu_1.deleteMenuItem)(this,n,s,r.isGlobal,String(r.index));await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:g.success?`\u2705 \u5DF2\u5220\u9664${r.isGlobal?"\u5168\u5C40":"\u4E2A\u4EBA"}\u5FEB\u6377\u6307\u4EE4: **${g.deletedItem.label}**`:`\u26A0\uFE0F ${g.error}`,msgType:"markdown"});return}case"list":{await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:(0,menu_1.formatMenuList)(this,n,s,r.isGlobal),msgType:"markdown"});return}case"trigger":{(0,menu_1.setUserTrigger)(this,s,r.word),await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u2705 \u83DC\u5355\u89E6\u53D1\u8BCD\u5DF2\u8BBE\u7F6E\u4E3A \`${r.word}\`\uFF0C\u53D1\u9001\u8BE5\u8BCD\u5373\u53EF\u5524\u8D77\u83DC\u5355`,msgType:"markdown"});return}}}async handleTodoCommand(r,t){const{conversationId:n,sessionWebhook:a,senderStaffId:s,senderNick:g}=t;if(r.type==="mode"){(0,todo_1.setIdMode)(this,n,r.mode);const i=r.mode==="staffId"?"\u5DE5\u53F7(staffId)":"\u9489\u9489ID(dingtalkId)";await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u2705 \u7528\u6237\u6807\u8BC6\u6A21\u5F0F\u5DF2\u5207\u6362\u4E3A: **${i}**
|
|
8
9
|
|
|
9
|
-
\u65B0\u6DFB\u52A0\u7684\u5F85\u529E\u5C06\u4F7F\u7528\u6B64\u6A21\u5F0F\u8BB0\u5F55\u8D1F\u8D23\u4EBA`,msgType:"markdown"});return}if(r.type==="list"){const i=(0,todo_1.getSortedTodoItems)(this,
|
|
10
|
+
\u65B0\u6DFB\u52A0\u7684\u5F85\u529E\u5C06\u4F7F\u7528\u6B64\u6A21\u5F0F\u8BB0\u5F55\u8D1F\u8D23\u4EBA`,msgType:"markdown"});return}if(r.type==="list"){const i=(0,todo_1.getSortedTodoItems)(this,n),h=(0,todo_1.getReminderHour)(this,n),$=(0,todo_1.getIdMode)(this,n)==="staffId"?"\u5DE5\u53F7\u6A21\u5F0F":"\u9489\u9489ID\u6A21\u5F0F",y=(0,todo_1.formatTodoList)(i,h),I=`\u{1F4CC} \u5F53\u524D\u6807\u8BC6\u6A21\u5F0F: **${$}**
|
|
10
11
|
|
|
11
|
-
${
|
|
12
|
-
`),
|
|
13
|
-
...(\u8F93\u51FA\u5DF2\u622A\u65AD)`:t}truncateMsg(r,t=100){const
|
|
14
|
-
`,"utf-8"),{sessionDir
|
|
12
|
+
${y}`;await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:I,msgType:"markdown"});return}if(r.type==="remind"){(0,todo_1.setReminderHour)(this,n,r.hour);const i=r.hour===null?"\u23F0 \u6BCF\u65E5\u63D0\u9192\u5DF2\u5173\u95ED":`\u23F0 \u6BCF\u65E5\u63D0\u9192\u5DF2\u8BBE\u7F6E\u4E3A ${r.hour}:00`;await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:i});return}if(r.type==="done"){const i=(0,todo_1.doneTodoItem)(this,n,r.index);i.success&&i.item?await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u2705 \u5DF2\u5B8C\u6210: ~~${i.item.content}~~ _@${i.item.assigneeNick}_`,msgType:"markdown"}):await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u274C ${i.error}`});return}if(r.type==="remove"){if(r.index==="all"){const i=(0,todo_1.clearAllTodoItems)(this,n);i.success?await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u{1F5D1}\uFE0F \u5DF2\u6E05\u7A7A ${i.count} \u6761\u5F85\u529E`}):await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u274C ${i.error}`})}else{const i=(0,todo_1.deleteTodoItem)(this,n,r.index);i.success&&i.item?await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664: ~~${i.item.content}~~`,msgType:"markdown"}):await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:`\u274C ${i.error}`})}return}if(r.type==="add"){const i=(0,todo_1.getIdMode)(this,n),h=r.assigneeId||s,m=r.assigneeNick||g,$=r.deadline&&(0,todo_1.parseDeadline)(r.deadline)||(0,todo_1.getDefaultDeadline)(),y=(0,todo_1.addTodoItem)(this,n,{content:r.content,assigneeStaffId:h,assigneeNick:m,deadline:$,assigneeIdType:i}),l=(0,todo_1.getSortedTodoItems)(this,n).findIndex(M=>M.content===y.content&&M.createdAt===y.createdAt)+1,k=(0,todo_1.formatTodoItemCreated)(y,l);await this.sendDingMessage({conversationId:n,sessionWebhook:a,content:k,msgType:"markdown"});return}}sanitizeLogContent(r){return r.replace(/\n/g,"\\n").replace(/\r/g,"\\r")}sanitizeOutput(r){const t=r.replace(/\r\n/g,`
|
|
13
|
+
`),n=8e3;return t.length>n?t.substring(0,n)+`
|
|
14
|
+
...(\u8F93\u51FA\u5DF2\u622A\u65AD)`:t}truncateMsg(r,t=100){const n=r.replace(/\n/g," ").trim();return n.length>t?n.slice(0,t)+"...":n}async getOrCreateLogSession(r,t,n,a,s,g=!1){const i=this.findActiveSession(r);if(i)return{sessionDir:this.getSessionDir(i.session.session),isNew:!1};if(g)return{sessionDir:null,isNew:!1};const h=Date.now(),m={conversationId:r,sessionWebhook:t,startTime:h,startTimeStr:utils_ok_1.dateUtil.mm(h).format("YYYY-MM-DD-HH-mm-ss"),startStaffId:n,startNickName:`[cron]${a}`},$=this.getSessionDir(m);return fs_1.default.mkdirSync($,{recursive:!0}),fs_1.default.writeFileSync(`${$}/session.json`,JSON.stringify(m,null,2),"utf-8"),fs_1.default.appendFileSync(`${$}/session.log`,`[${(0,session_1.timestamp)()}] [SYSTEM]: \u521B\u5EFA\u4F1A\u8BDD\u7528\u4E8E\u8BB0\u5F55 /cron \u547D\u4EE4\u64CD\u4F5C
|
|
15
|
+
`,"utf-8"),{sessionDir:$,isNew:!0}}hasNotifyCapability(r){return!!(r.dingToken||this.config.defaultDingToken)}async sendCronNoNotifyError(r,t){await this.sendDingMessage({conversationId:r,sessionWebhook:t,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"})}async botMsgGetCallback(r){this.dingStreamClient.socketCallBackResponse(r.headers.messageId,"");const t=JSON.parse(r.data),{senderNick:n,senderStaffId:a,conversationId:s,conversationTitle:g,sessionWebhook:i,msgtype:h,conversationType:m}=t,$=t.text?.content?.trim()??"";if(this.debugLog(`\u6536\u5230\u6D88\u606F: \u7FA4=${g}(${s}), \u53D1\u9001\u8005=${n}(${a}), \u7C7B\u578B=${h}, \u5185\u5BB9=${$.substring(0,50)}`),!this.authCheck(a,s)){await this.handleAuthRequest({senderStaffId:a,senderNick:n,conversationId:s,conversationType:m,conversationTitle:t.conversationTitle,sessionWebhook:i});return}const y=this.getConversationConfig(s);let I=(0,commands_1.parseRecorderCommandEnhanced)($);if(I==="exit"&&/^\/(?:exit|e)$/i.test($)&&!this.recorderModeConversations.has(s)&&(I=null),I!==null){if(!this.isOwner(a)||m!=="1"){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u274C Recorder \u6A21\u5F0F\u4EC5\u9650 owner \u5355\u804A\u4F7F\u7528",msgType:"markdown"});return}if(I==="on"){this.recorderModeConversations.add(s);const e=(0,recorder_1.getRecorderDir)(this,s);console.log(`[${(0,session_1.timestamp)()}] [recorder] \u5F00\u542F recorder \u6A21\u5F0F: conversationId=${s}, dir=${e}`),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F534} Recorder \u6A21\u5F0F\u5DF2\u5F00\u542F
|
|
15
16
|
- \u6240\u6709\u6D88\u606F\u5C06\u88AB\u5206\u7C7B\u8BB0\u5F55\u5230\u672C\u5730
|
|
16
|
-
- \u4FDD\u5B58\u76EE\u5F55: \`${
|
|
17
|
-
- \u53D1\u9001 \`/recorder exit\` \u5173\u95ED`,msgType:"markdown"})}else this.recorderModeConversations.delete(
|
|
18
|
-
\u{1F4A1} \u53EF\u7F16\u8F91 config.json \u8865\u5145\u66F4\u591A\u914D\u7F6E`),await this.sendDingMessage({conversationId:
|
|
19
|
-
`),msgType:"markdown"})
|
|
17
|
+
- \u4FDD\u5B58\u76EE\u5F55: \`${e}\`
|
|
18
|
+
- \u53D1\u9001 \`/recorder exit\` \u5173\u95ED`,msgType:"markdown"})}else this.recorderModeConversations.delete(s),console.log(`[${(0,session_1.timestamp)()}] [recorder] \u5173\u95ED recorder \u6A21\u5F0F: conversationId=${s}`),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u2B1C Recorder \u6A21\u5F0F\u5DF2\u5173\u95ED\uFF0C\u6062\u590D\u6B63\u5E38\u5904\u7406",msgType:"markdown"});return}if(this.recorderModeConversations.has(s)){try{await(0,recorder_1.recordMessage)(this,t,s),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u8BB0\u5F55 ${h}`})}catch(e){console.error(`[${(0,session_1.timestamp)()}] [recorder] \u8BB0\u5F55\u6D88\u606F\u5931\u8D25:`,e),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u274C \u8BB0\u5F55\u5931\u8D25: ${e instanceof Error?e.message:String(e)}`})}return}let l;if(h==="picture"&&t.pictureDownloadCode){const e=this.getConversationDir(s),d=y?.useLocalOcr!==!1,o=await(0,image_1.processPictureMessage)(this,t.pictureDownloadCode,t.robotCode,e,d,$||void 0);if(!o){await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u26A0\uFE0F \u56FE\u7247\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u6216\u4F7F\u7528\u6587\u5B57\u63CF\u8FF0"});return}l=o}else if(h==="richText"&&t.content?.richText){const e=this.getConversationDir(s),d=y?.useLocalOcr!==!1;l=await(0,image_1.processRichTextMessage)(this,t.content.richText,t.robotCode,e,d)}else if(h==="file"){const e=(0,image_1.extractDownloadCode)(t);if(e){const d=this.getConversationDir(s),o=await(0,image_1.processFileMessage)(this,e,t.robotCode,d,$||void 0);if(!o){await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u26A0\uFE0F \u6587\u4EF6\u4E0B\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5"});return}l=o}else{await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6\u6587\u4EF6\u4E0B\u8F7D\u94FE\u63A5\uFF0C\u8BF7\u91CD\u65B0\u53D1\u9001"});return}}else{if(l=$,!l){const e=(0,quote_1.extractQuoteInfo)(t);if(e){if(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F(\u65E0\u6B63\u6587): quoteMessageId=${e.quoteMessageId}`),e.quoteMessageId&&!e.quoteText){const d=await(0,messaging_1.fetchQuotedMessage)(this,e.quoteMessageId);d&&(e.quoteText=d)}e.quoteText&&(l=(0,quote_1.formatPromptWithQuote)("",e))}}if(!l)return}if(!l.startsWith("/")&&h==="text"&&$){const e=(0,quote_1.extractQuoteInfo)(t);if(e){if(this.debugLog(`\u68C0\u6D4B\u5230\u5F15\u7528\u6D88\u606F: quoteMessageId=${e.quoteMessageId}`),e.quoteMessageId&&!e.quoteText){const d=await(0,messaging_1.fetchQuotedMessage)(this,e.quoteMessageId);d&&(e.quoteText=d)}e.quoteText&&(l=(0,quote_1.formatPromptWithQuote)(l,e))}}if(h==="text"&&l&&!l.startsWith("/")){if(l.toLowerCase()===(0,menu_1.getUserTrigger)(this,a).toLowerCase())l="/menu";else if(/^\d+$/.test(l)&&(0,menu_1.hasPendingSelection)(s,a)){const e=(0,menu_1.getPendingSelection)(s,a);(0,menu_1.clearPendingSelection)(s,a);const d=parseInt(l,10);if(d<1||d>e.mergedItems.length){await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:`\u26A0\uFE0F \u5E8F\u53F7\u65E0\u6548\uFF0C\u83DC\u5355\u5171 ${e.mergedItems.length} \u9879`});return}const o=e.mergedItems[d-1];console.log(`[${(0,session_1.timestamp)()}] [menu] ${n} \u9009\u62E9\u5FEB\u6377\u6307\u4EE4: ${o.label} \u2192 ${o.command}`),l=o.command}}const k=[(0,command_route_1.route)("/cfg",()=>(0,commands_1.parseCfgCommand)(l),async e=>{if(e.conversationId&&!this.isOwner(a)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,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(s,i,a,y))return;const d=e.conversationId||s,o=d!==s,c=o?this.config.conversations.find(D=>D.conversationId===d):y,u=!!(e.dingToken||e.linkConversationId||e.whiteUserList&&e.whiteUserList.length>0||e.conversationTitle||e.atSender!==void 0||e.receiveReply!==void 0||e.preBash!==void 0||e.permissionMode!==void 0);if(c&&u){if(e.conversationTitle&&(c.conversationTitle=e.conversationTitle),m&&!o&&(c.conversationType=m),e.dingToken&&(c.dingToken=e.dingToken),e.linkConversationId&&(c.linkConversationId=e.linkConversationId),e.atSender!==void 0&&(c.atSender=e.atSender),e.receiveReply!==void 0&&(c.receiveReply=e.receiveReply),e.preBash!==void 0&&(c.preBash=e.preBash),e.permissionMode!==void 0&&(c.permissionMode=e.permissionMode),e.whiteUserList&&e.whiteUserList.length>0){c.whiteUserList=e.whiteUserList;for(const D of e.whiteUserList)(0,session_1.isMobile)(D)&&await(0,session_1.resolveUserId)(this,D)}(0,api_key_manager_1.saveClientConfig)(this),console.log(`[${(0,session_1.timestamp)()}] \u5237\u65B0\u7FA4\u914D\u7F6E: ${c.conversationTitle||d}(${d})`)}else if(!c){const D={conversationId:d,conversationType:o?"1":m,conversationTitle:e.conversationTitle||(o?"":g)};if(e.dingToken&&(D.dingToken=e.dingToken),e.linkConversationId&&(D.linkConversationId=e.linkConversationId),e.atSender!==void 0&&(D.atSender=e.atSender),e.receiveReply!==void 0&&(D.receiveReply=e.receiveReply),e.preBash!==void 0&&(D.preBash=e.preBash),e.permissionMode!==void 0&&(D.permissionMode=e.permissionMode),e.whiteUserList&&e.whiteUserList.length>0){D.whiteUserList=e.whiteUserList;for(const T of e.whiteUserList)(0,session_1.isMobile)(T)&&await(0,session_1.resolveUserId)(this,T)}this.config.conversations.push(D),(0,api_key_manager_1.saveClientConfig)(this),console.log(`[${(0,session_1.timestamp)()}] \u6CE8\u518C\u65B0\u7FA4: ${D.conversationTitle||d}(${d}) \u7C7B\u578B=${D.conversationType||"-"}`)}const p=this.getConversationDir(d);fs_1.default.existsSync(p)||(fs_1.default.mkdirSync(p,{recursive:!0}),console.log(`[${(0,session_1.timestamp)()}] \u521B\u5EFA\u5DE5\u4F5C\u76EE\u5F55: ${p}`));const f=c||this.getConversationConfig(d),w=[c?"\u2705 \u7FA4\u914D\u7F6E\u5DF2\u5237\u65B0":"\u2705 \u7FA4\u5DF2\u6CE8\u518C",`- **\u7FA4\u540D\u79F0:** ${f?.conversationTitle||d}`,`- **\u7FA4ID:** ${d}`];if(f?.conversationType&&w.push(`- **\u4F1A\u8BDD\u7C7B\u578B:** ${f.conversationType==="1"?"\u5355\u804A":f.conversationType==="2"?"\u7FA4\u804A":f.conversationType}`),f?.dingToken?w.push(`- **dingToken:** ${f.dingToken.substring(0,8)}...`):w.push("- **dingToken:** (\u672A\u6307\u5B9A, \u4F7F\u7528 defaultDingToken)"),f?.linkConversationId&&w.push(`- **linkConversationId:** ${f.linkConversationId}`),f?.atSender===!1&&w.push("- **atSender:** false (\u4E0D @ \u53D1\u9001\u4EBA)"),f?.receiveReply===!1&&w.push("- **receiveReply:** false (\u4E0D\u56DE\u590D\u786E\u8BA4\u6D88\u606F)"),f?.permissionMode&&w.push(`- **permissionMode:** ${f.permissionMode}`),f?.whiteUserList?.length){const D=f.whiteUserList.map(T=>(0,session_1.isMobile)(T)?T:(0,session_1.userIdToPhone)(this,T)||T).join(", ");w.push(`- **whiteUserList:** ${D}`)}w.push(`- **\u5DE5\u4F5C\u76EE\u5F55:** ${p}`),w.push(`
|
|
19
|
+
\u{1F4A1} \u53EF\u7F16\u8F91 config.json \u8865\u5145\u66F4\u591A\u914D\u7F6E`),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:w.join(`
|
|
20
|
+
`),msgType:"markdown"})}),(0,command_route_1.route)("/help",()=>(0,commands_1.parseHelpCommand)(l),async()=>{await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:(0,commands_1.formatHelpOverview)(TOOL_VERSION,this.isOwner(a)),msgType:"markdown"})}),(0,command_route_1.route)("/version",()=>(0,commands_1.parseVersionCommand)(l),async()=>{await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`**\u7248\u672C:** ${TOOL_VERSION}`,msgType:"markdown"})}),(0,command_route_1.route)("cmd-help",()=>(0,commands_1.parseCommandHelp)(l),async e=>{const d=(0,commands_1.getCommandByName)(e);d?await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:(0,commands_1.formatCommandHelp)(d),msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u274C \u672A\u627E\u5230\u547D\u4EE4: **${e}**
|
|
20
21
|
|
|
21
|
-
\u{1F4A1} \u8F93\u5165 \`/help\` \u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4`,msgType:"markdown"})
|
|
22
|
-
\u{1F4A1} \u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u4FDD\u7559`),
|
|
23
|
-
\u26A0\uFE0F \u9519\u8BEF: ${
|
|
24
|
-
`),msgType:"markdown"})
|
|
25
|
-
- \u6709\u6548 Key \u6570: ${
|
|
26
|
-
- \u91CD\u7F6E\u65F6\u95F4: ${this.config.apiKeyCfg.resetTime||"-"}`,msgType:"markdown"})
|
|
27
|
-
- **\u7528\u6237ID:** ${
|
|
28
|
-
- **\u6635\u79F0:** ${
|
|
29
|
-
- **\u4F1A\u8BDDID:** ${
|
|
30
|
-
- **\u7528\u6237ID:** ${
|
|
31
|
-
- **\u6635\u79F0:** ${
|
|
32
|
-
`):"(\u672A\u914D\u7F6E\u7FA4\u7EA7\u767D\u540D\u5355\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)";await this.sendDingMessage({conversationId:
|
|
33
|
-
${
|
|
34
|
-
`):"(\u672A\u914D\u7F6E\u7BA1\u7406\u5458)";await this.sendDingMessage({conversationId:
|
|
35
|
-
${
|
|
36
|
-
\u5F53\u524D\u767D\u540D\u5355: ${u.join(", ")}`,msgType:"markdown"});return}if(
|
|
37
|
-
\u5F53\u524D\u767D\u540D\u5355: ${
|
|
22
|
+
\u{1F4A1} \u8F93\u5165 \`/help\` \u67E5\u770B\u6240\u6709\u53EF\u7528\u547D\u4EE4`,msgType:"markdown"})}),(0,command_route_1.route)("/reboot",()=>(0,commands_1.parseRebootCommand)(l),async e=>{if(!await this.requireOwnerOrAdmin(s,i,a))return;if(e.tag&&!/^[\w.\-]+$/.test(e.tag)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u274C \u65E0\u6548\u7684 tag\uFF0C\u4EC5\u5141\u8BB8\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u70B9\u3001\u6A2A\u7EBF\u548C\u4E0B\u5212\u7EBF",msgType:"markdown"});return}const d=e.tag?`@${e.tag}`:"",o=e.update?`pnpm add -g cc-ding${d}`:null,c=`cc-ding-${this.clientId}`;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:o?`\u2705 \u66F4\u65B0\u5E76\u91CD\u542F\uFF0C\u6B63\u5728\u6267\u884C ${o}...`:"\u2705 cc-ding \u6B63\u5728\u91CD\u542F\u4E2D...",msgType:"markdown"});const u=path_1.default.join(this.getClientDir(),".reboot_pending");fs_1.default.writeFileSync(u,JSON.stringify({conversationId:s,senderStaffId:a,sessionWebhook:i,update:e.update}),"utf-8"),setTimeout(()=>{console.log(`[${(0,session_1.timestamp)()}] \u6267\u884C pm2 restart ${c}${o?" (\u542B\u66F4\u65B0)":""}`),(0,child_process_1.exec)(`${o?`${o} && `:""}pm2 restart "${c}"`,{timeout:6e4},p=>{p&&console.error(`[${(0,session_1.timestamp)()}] pm2 restart \u5931\u8D25:`,p)})},1e3)})];for(const e of k)if(await e.tryHandle())return;if(!y){console.log(`\u672A\u6CE8\u518C\u7684\u673A\u5668\u4EBA,\u7FA4:${g},${s}`),this.isOwner(a)?await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u26A0\uFE0F \u8BE5\u7FA4\u672A\u6CE8\u518C\uFF0C\u8BF7\u5148\u4F7F\u7528 `/cfg` \u547D\u4EE4\u6CE8\u518C",msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,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(${s})...`});return}const M=[(0,command_route_1.route)("/clean",()=>(0,commands_1.parseCleanCommand)(l),async e=>{if(e==="all"&&y?.conversationType!=="1"&&!this.isOwner(a)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u274C \u53EA\u6709\u673A\u5668\u4EBA owner \u624D\u80FD\u6E05\u9664\u6240\u6709\u7FA4\u7F13\u5B58",msgType:"markdown"});return}if(!await this.requireOwnerOrSingleChat(s,i,a,y))return;const d=e==="all"?null:s,o=this.cleanCache(d,!0),c=[];c.push("\u{1F9F9} \u7F13\u5B58\u6E05\u7406\u5B8C\u6210"),o.sessionsDeleted>0&&c.push(`- \u4F1A\u8BDD\u76EE\u5F55: ${o.sessionsDeleted} \u4E2A`),o.tasksDeleted>0&&c.push(`- \u4EFB\u52A1\u76EE\u5F55: ${o.tasksDeleted} \u4E2A`),o.imagesDeleted>0&&c.push(`- \u56FE\u7247\u6587\u4EF6: ${o.imagesDeleted} \u4E2A`),o.sessionsDeleted===0&&o.tasksDeleted===0&&o.imagesDeleted===0&&c.push("(\u65E0\u5386\u53F2\u6570\u636E)"),c.push(`
|
|
23
|
+
\u{1F4A1} \u6D3B\u8DC3\u4F1A\u8BDD\u5DF2\u4FDD\u7559`),o.errors.length>0&&c.push(`
|
|
24
|
+
\u26A0\uFE0F \u9519\u8BEF: ${o.errors.join("; ")}`),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:c.join(`
|
|
25
|
+
`),msgType:"markdown"})}),(0,command_route_1.route)("/reset-apikeycfg",()=>(0,commands_1.parseResetApiKeyCfgCommand)(l),async()=>{if(!await this.requireOwner(s,i,a))return;if(!this.config.apiKeyCfg){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u26A0\uFE0F \u672A\u914D\u7F6E apiKeyCfg\uFF0C\u65E0\u9700\u91CD\u7F6E",msgType:"markdown"});return}(0,api_key_manager_1.resetApiKeyCfg)(this);const e=this.config.apiKeyCfg.claudeSettings.filter(d=>d.isValid).length;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 apiKeyCfg \u5DF2\u91CD\u7F6E
|
|
26
|
+
- \u6709\u6548 Key \u6570: ${e}/${this.config.apiKeyCfg.claudeSettings.length}
|
|
27
|
+
- \u91CD\u7F6E\u65F6\u95F4: ${this.config.apiKeyCfg.resetTime||"-"}`,msgType:"markdown"})}),(0,command_route_1.route)("/auth",()=>(0,commands_1.parseAuthCommand)(l),async e=>{if(!await this.requireOwner(s,i,a))return;if(e.type==="approve"||e.type==="reject"){const o=this.pendingAuthRequests.get(e.requestId);if(!o){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u274C \u672A\u627E\u5230\u6388\u6743\u7533\u8BF7: ${e.requestId}`,msgType:"markdown"});return}if(this.pendingAuthRequests.delete(e.requestId),e.type==="approve"){let c=this.config.conversations.find(u=>u.conversationId===o.conversationId);c||(c={conversationId:o.conversationId,conversationType:o.conversationType||"1",conversationTitle:o.conversationTitle},this.config.conversations.push(c)),c.whiteUserList||(c.whiteUserList=[]),c.whiteUserList.includes(o.senderStaffId)||c.whiteUserList.push(o.senderStaffId),(0,api_key_manager_1.saveClientConfig)(this),console.log(`[${(0,session_1.timestamp)()}] \u6388\u6743\u7533\u8BF7\u901A\u8FC7\u5C06: id=${e.requestId}, userId=${o.senderStaffId}`),await(0,messaging_1.sendMessageToUser)(this,o.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:s,sessionWebhook:i,content:`\u2705 \u5DF2\u901A\u8FC7\u6388\u6743\u7533\u8BF7
|
|
28
|
+
- **\u7528\u6237ID:** ${o.senderStaffId}
|
|
29
|
+
- **\u6635\u79F0:** ${o.senderNick}
|
|
30
|
+
- **\u4F1A\u8BDDID:** ${o.conversationId}`,msgType:"markdown"})}else console.log(`[${(0,session_1.timestamp)()}] \u6388\u6743\u7533\u8BF7\u62D2\u7EDD: id=${e.requestId}, userId=${o.senderStaffId}`),await(0,messaging_1.sendMessageToUser)(this,o.senderStaffId,"\u274C \u60A8\u7684\u6388\u6743\u7533\u8BF7\u5DF2\u88AB\u62D2\u7EDD","markdown"),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u62D2\u7EDD\u6388\u6743\u7533\u8BF7
|
|
31
|
+
- **\u7528\u6237ID:** ${o.senderStaffId}
|
|
32
|
+
- **\u6635\u79F0:** ${o.senderNick}`,msgType:"markdown"});return}const d=y.whiteUserList;if(e.type==="list"){const o=d&&d.length>0?d.map(c=>`- ${(0,session_1.userIdToPhone)(this,c)||c}`).join(`
|
|
33
|
+
`):"(\u672A\u914D\u7F6E\u7FA4\u7EA7\u767D\u540D\u5355\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)";await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4CB} **\u5F53\u524D\u7FA4\u767D\u540D\u5355**
|
|
34
|
+
${o}`,msgType:"markdown"});return}if(e.type==="adminList"){const o=this.config.adminUserList&&this.config.adminUserList.length>0?this.config.adminUserList.map(c=>`- ${(0,session_1.userIdToPhone)(this,c)||c}`).join(`
|
|
35
|
+
`):"(\u672A\u914D\u7F6E\u7BA1\u7406\u5458)";await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F451} **\u7BA1\u7406\u5458\u5217\u8868**
|
|
36
|
+
${o}`,msgType:"markdown"});return}if(e.type==="adminAdd"){let o=e.staffId;if((0,session_1.isMobile)(e.staffId)&&(o=await(0,session_1.resolveUserId)(this,e.staffId),!o)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}if(this.config.adminUserList?.some(p=>(0,session_1.resolveToUserId)(this,p)===o)){const p=(0,session_1.userIdToPhone)(this,o)||o;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F ${p} \u5DF2\u5728\u7BA1\u7406\u5458\u5217\u8868\u4E2D`,msgType:"markdown"});return}this.config.adminUserList||(this.config.adminUserList=[]),this.config.adminUserList.push(e.staffId),(0,api_key_manager_1.saveClientConfig)(this);const u=(0,session_1.isMobile)(e.staffId)?e.staffId:(0,session_1.userIdToPhone)(this,e.staffId)||e.staffId;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u6DFB\u52A0 ${u} \u5230\u7BA1\u7406\u5458\u5217\u8868`,msgType:"markdown"});return}if(e.type==="adminRm"){let o=e.staffId;if((0,session_1.isMobile)(e.staffId)&&(o=await(0,session_1.resolveUserId)(this,e.staffId),!o)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}const c=this.config.adminUserList?.findIndex(f=>(0,session_1.resolveToUserId)(this,f)===o)??-1;if(c<0){const f=(0,session_1.userIdToPhone)(this,o)||o;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F ${f} \u4E0D\u5728\u7BA1\u7406\u5458\u5217\u8868\u4E2D`,msgType:"markdown"});return}const u=this.config.adminUserList[c];this.config.adminUserList.splice(c,1),this.config.adminUserList.length===0&&delete this.config.adminUserList,(0,api_key_manager_1.saveClientConfig)(this);const p=(0,session_1.userIdToPhone)(this,o)||u;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u79FB\u9664 ${p}`,msgType:"markdown"});return}if(e.type==="add"){let o=e.staffId;if((0,session_1.isMobile)(e.staffId)&&(o=await(0,session_1.resolveUserId)(this,e.staffId),!o)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}if(d?.some(f=>(0,session_1.resolveToUserId)(this,f)===o)){const f=(0,session_1.userIdToPhone)(this,o)||o;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F ${f} \u5DF2\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}y.whiteUserList||(y.whiteUserList=[]),y.whiteUserList.push(e.staffId),(0,api_key_manager_1.saveClientConfig)(this);const u=y.whiteUserList.map(f=>{const w=(0,session_1.resolveToUserId)(this,f);return(0,session_1.userIdToPhone)(this,w)||f}),p=(0,session_1.isMobile)(e.staffId)?e.staffId:(0,session_1.userIdToPhone)(this,e.staffId)||e.staffId;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u6DFB\u52A0 ${p} \u5230\u5F53\u524D\u7FA4\u767D\u540D\u5355
|
|
37
|
+
\u5F53\u524D\u767D\u540D\u5355: ${u.join(", ")}`,msgType:"markdown"});return}if(e.type==="del"){let o=e.staffId;if((0,session_1.isMobile)(e.staffId)&&(o=await(0,session_1.resolveUserId)(this,e.staffId),!o)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F \u65E0\u6CD5\u89E3\u6790\u624B\u673A\u53F7: ${e.staffId}`,msgType:"markdown"});return}const c=d?.findIndex(w=>(0,session_1.resolveToUserId)(this,w)===o)??-1;if(c<0){const w=(0,session_1.userIdToPhone)(this,o)||o;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F ${w} \u4E0D\u5728\u5F53\u524D\u7FA4\u767D\u540D\u5355\u4E2D`,msgType:"markdown"});return}const u=y.whiteUserList[c];y.whiteUserList.splice(c,1),y.whiteUserList.length===0&&delete y.whiteUserList,(0,api_key_manager_1.saveClientConfig)(this);const p=y.whiteUserList?.length?y.whiteUserList.map(w=>{const D=(0,session_1.resolveToUserId)(this,w);return(0,session_1.userIdToPhone)(this,D)||w}).join(", "):"(\u7A7A\uFF0C\u4F7F\u7528\u5168\u5C40\u767D\u540D\u5355)",f=(0,session_1.userIdToPhone)(this,o)||u;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u79FB\u9664 ${f}
|
|
38
|
+
\u5F53\u524D\u767D\u540D\u5355: ${p}`,msgType:"markdown"});return}}),(0,command_route_1.route)("/open",()=>(0,commands_1.parseOpenCommand)(l),async e=>{if(!await this.requireOwner(s,i,a))return;const d=this.getConversationDir(s),{exec:o}=await Promise.resolve().then(()=>__importStar(require("child_process"))),c=process.platform;try{if(e==="folder")o(c==="darwin"?`open "${d}"`:`explorer "${d}"`),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4C2} \u5DF2\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u6253\u5F00:
|
|
38
39
|
\`\`\`
|
|
39
|
-
${
|
|
40
|
-
\`\`\``,msgType:"markdown"})
|
|
40
|
+
${d}
|
|
41
|
+
\`\`\``,msgType:"markdown"});else if(e==="code"){const u=(0,platform_1.isWindows)()?"where code":"which code";o(u,p=>{if(p){this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u274C \u672A\u68C0\u6D4B\u5230 VS Code `code` \u547D\u4EE4\n\u8BF7\u5B89\u88C5 VS Code \u5E76\u5C06 `code` \u6DFB\u52A0\u5230 PATH",msgType:"markdown"});return}o(`code "${d}"`),this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4BB} \u5DF2\u5728 VS Code \u4E2D\u6253\u5F00:
|
|
41
42
|
\`\`\`
|
|
42
|
-
${
|
|
43
|
-
\`\`\``,msgType:"markdown"})})
|
|
43
|
+
${d}
|
|
44
|
+
\`\`\``,msgType:"markdown"})})}else c==="darwin"?o(`open -a Terminal "${d}"`):c==="win32"?o(`start "" cmd /k "cd /d "${d}""`,{shell:"cmd.exe"}):o(`xdg-open "${d}"`),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4BB} \u5DF2\u5728\u7EC8\u7AEF\u4E2D\u6253\u5F00:
|
|
44
45
|
\`\`\`
|
|
45
|
-
${
|
|
46
|
-
\`\`\``,msgType:"markdown"})
|
|
46
|
+
${d}
|
|
47
|
+
\`\`\``,msgType:"markdown"})}catch(u){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u274C \u6253\u5F00\u5931\u8D25: ${u instanceof Error?u.message:String(u)}`,msgType:"markdown"})}}),(0,command_route_1.route)("/cron",()=>(0,commands_1.parseCronCommand)(l),async e=>{await this.handleCronCommand(e,{conversationId:s,sessionWebhook:i,senderStaffId:a,senderNick:n,conversationConfig:y})}),(0,command_route_1.route)("/todo",()=>(0,commands_2.parseTodoCommand)(l,t.atUsers),async e=>{await this.handleTodoCommand(e,{conversationId:s,sessionWebhook:i,senderStaffId:a,senderNick:n})}),(0,command_route_1.route)("/menu",()=>(0,commands_1.parseMenuCommand)(l),async e=>{await this.handleMenuCommand(e,{conversationId:s,sessionWebhook:i,senderStaffId:a})}),(0,command_route_1.route)("/bash",()=>(0,commands_1.parseBashCommand)(l),async e=>{if(!await this.requireOwnerOrAdmin(s,i,a))return;this.appendBashAudit(s,a,e);const d=this.getConversationDir(s),o=[];this.config.preBash&&o.push(this.config.preBash),y?.preBash&&o.push(y.preBash);const c=o.length>0?`${o.join(" ; ")} ; ${e}`:e,u=this;(0,child_process_1.exec)(c,{cwd:d,timeout:3e4,maxBuffer:1024*1024},async(p,f,w)=>{try{let D;if(p)D=`\u274C \u547D\u4EE4\u6267\u884C\u5931\u8D25
|
|
47
48
|
\`\`\`
|
|
48
|
-
${
|
|
49
|
-
\`\`\``,
|
|
49
|
+
${p.message}
|
|
50
|
+
\`\`\``,w&&(D+=`
|
|
50
51
|
|
|
51
52
|
**stderr:**
|
|
52
53
|
\`\`\`
|
|
53
|
-
${u.sanitizeOutput(
|
|
54
|
-
\`\`\``);else{const
|
|
54
|
+
${u.sanitizeOutput(w)}
|
|
55
|
+
\`\`\``);else{const T=f||"(\u65E0\u8F93\u51FA)";D=`\u2705 \u6267\u884C\u6210\u529F
|
|
55
56
|
\`\`\`
|
|
56
|
-
${u.sanitizeOutput(
|
|
57
|
-
\`\`\``,
|
|
57
|
+
${u.sanitizeOutput(T)}
|
|
58
|
+
\`\`\``,w&&(D+=`
|
|
58
59
|
|
|
59
60
|
**stderr:**
|
|
60
61
|
\`\`\`
|
|
61
|
-
${u.sanitizeOutput(
|
|
62
|
-
\`\`\``)}await u.sendDingMessage({conversationId:
|
|
62
|
+
${u.sanitizeOutput(w)}
|
|
63
|
+
\`\`\``)}await u.sendDingMessage({conversationId:s,sessionWebhook:i,content:D,msgType:"markdown"})}catch(D){console.error("[bash] \u53D1\u9001\u6D88\u606F\u5931\u8D25:",D)}})}),(0,command_route_1.route)("/new",()=>/^\/new(?:\s|$)/i.test(l),async()=>{const e=this.findActiveSession(s);e&&(console.log(`\u6536\u5230\u65B0\u4F1A\u8BDD\u547D\u4EE4\uFF0C\u7ED3\u675F\u65E7\u4F1A\u8BDD: \u7FA4=${e.session.session.conversationId}, \u4F1A\u8BDDID=${this.getSessionId(e.session.session)}`),this.interruptClaudeProcess(e.session,"\u65B0\u4F1A\u8BDD\u547D\u4EE4\u4E2D\u65AD\u6B63\u5728\u6267\u884C\u7684 Claude \u8FDB\u7A0B"),this.activeSessions.delete(e.key),this.saveActiveSession(e.key));const d=l.replace(/^\/new\s*/i,"").trim();d?await this.startNewSession({conversationId:s,sessionWebhook:i,senderStaffId:a,senderNick:n,message:d,conversationConfig:y}):await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u{1F680} \u8BF7\u8F93\u5165\u60A8\u7684\u95EE\u9898\u5F00\u59CB\u65B0\u4F1A\u8BDD"})}),(0,command_route_1.route)("/resume",()=>(0,commands_1.parseContinueSessionCommand)(l),async e=>{let d=e;if(!d){const o=(0,session_1.findLatestSession)(this,s);if(!o){await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u26A0\uFE0F \u672A\u627E\u5230\u5DF2\u7ED3\u675F\u7684\u4F1A\u8BDD",msgType:"markdown"});return}d=(0,session_1.getSessionId)(o)}await this.switchToSession(s,i,d,a,y)}),(0,command_route_1.route)("/log",()=>(0,commands_1.parseLogCommand)(l),async e=>{const d=this.readSessionLogTail(s,e);d?await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4CB} \u6700\u8FD1 ${e} \u884C\u65E5\u5FD7:
|
|
63
64
|
\`\`\`
|
|
64
|
-
${
|
|
65
|
-
\`\`\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:
|
|
66
|
-
`+(0,commands_1.formatGlobalConfig)(this.config)),
|
|
67
|
-
`+(0,commands_1.formatConversationInfo)(
|
|
68
|
-
`+
|
|
69
|
-
\u65E0\u6D3B\u8DC3\u4F1A\u8BDD`)}(
|
|
70
|
-
`+this.formatTaskInfo()),await this.sendDingMessage({conversationId:
|
|
65
|
+
${d}
|
|
66
|
+
\`\`\``,msgType:"markdown"}):await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u26A0\uFE0F \u5F53\u524D\u65E0\u6D3B\u8DC3\u4F1A\u8BDD\u6216\u6682\u65E0\u65E5\u5FD7"})}),(0,command_route_1.route)("/info",()=>(0,commands_1.parseInfoCommand)(l),async e=>{const d=[],o=this.getConversationDir(s);if((e==="all"||e==="robot")&&(d.push(`### \u{1F310} \u5168\u5C40\u6838\u5FC3\u914D\u7F6E
|
|
67
|
+
`+(0,commands_1.formatGlobalConfig)(this.config)),d.push(`### \u{1F916} \u7FA4\u914D\u7F6E\u4FE1\u606F
|
|
68
|
+
`+(0,commands_1.formatConversationInfo)(y,s,c=>(0,session_1.userIdToPhone)(this,c),o))),e==="all"||e==="session"){const c=this.formatSessionInfo(s);c?d.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
|
|
69
|
+
`+c):d.push(`### \u{1F4AC} \u5F53\u524D\u4F1A\u8BDD\u4FE1\u606F
|
|
70
|
+
\u65E0\u6D3B\u8DC3\u4F1A\u8BDD`)}(e==="all"||e==="task")&&d.push(`### \u{1F4DD} \u4EFB\u52A1\u961F\u5217\u4FE1\u606F
|
|
71
|
+
`+this.formatTaskInfo()),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:d.join(`
|
|
71
72
|
|
|
72
|
-
`),msgType:"markdown"})
|
|
73
|
+
`),msgType:"markdown"})}),(0,command_route_1.route)("/ls",()=>(0,commands_1.parseLsCommand)(l),async e=>{const{target:d,depth:o}=e,c=this.getConversationDir(s);let u=c,p="\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55";if(d&&d!=="root")if(d.startsWith("./")||d.startsWith("../")||d.startsWith("/")){const w=path_1.default.resolve(c,d);if(fs_1.default.existsSync(w)&&fs_1.default.statSync(w).isDirectory()){if(!w.startsWith(c)){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u274C \u8DEF\u5F84\u8D85\u51FA\u5DE5\u4F5C\u76EE\u5F55\u8303\u56F4",msgType:"markdown"});return}u=w,p=d}else{await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u274C \u8DEF\u5F84\u4E0D\u5B58\u5728\u6216\u4E0D\u662F\u76EE\u5F55: **${d}**`,msgType:"markdown"});return}}else{const w=(0,commands_1.findSubdirByName)(c,d);if(w)u=w,p=d;else{await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u274C \u672A\u627E\u5230\u540D\u4E3A **${d}** \u7684\u76EE\u5F55`,msgType:"markdown"});return}}const f=(0,commands_1.getDirectoryStructure)(u,0,o);await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4C2} ${p} (\u5C55\u5F00${o}\u5C42):
|
|
73
74
|
\`\`\`
|
|
74
|
-
${
|
|
75
|
-
\`\`\``,msgType:"markdown"})
|
|
76
|
-
${
|
|
77
|
-
`)}`,msgType:"markdown"})}return}case"
|
|
78
|
-
${
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
${f}
|
|
76
|
+
\`\`\``,msgType:"markdown"})}),(0,command_route_1.route)("/task cancel",()=>(0,task_1.parseTaskCancelCommand)(l)||null,async e=>{const d=this.cancelTask(e,s);await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:d,msgType:"markdown"})}),(0,command_route_1.route)("/task",()=>l.startsWith("/task ")||null,async()=>{const e=l.substring(6).trim();e&&(await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u{1F4CB} \u4EFB\u52A1\u5DF2\u6536\u5230,\u5B8C\u6210\u540E\u6211\u4F1A\u56DE\u590D"}),await this.saveTask({conversationId:s,prompt:e,senderStaffId:a,senderNickName:n,sessionWebhook:i}))}),(0,command_route_1.route)("/mq",()=>(0,commands_1.parseMqCommand)(l),async e=>{const o=this.findActiveSession(s)?.session.messageQueue??[];switch(e.type){case"list":{if(o.length===0)await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});else{const c=o.map((u,p)=>`${p+1}. **${u.senderNick||u.senderStaffId}:** ${this.truncateMsg(u.message)}`);await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4E8} \u6D88\u606F\u961F\u5217 (${o.length} \u6761)
|
|
77
|
+
${c.join(`
|
|
78
|
+
`)}`,msgType:"markdown"})}return}case"front":{if(o.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}let c=o.length-1;for(let p=o.length-1;p>=0;p--)if(o[p].senderStaffId===a){c=p;break}if(c===0){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u2139\uFE0F \u8BE5\u6D88\u606F\u5DF2\u5728\u961F\u9996\uFF0C\u65E0\u9700\u63D2\u961F",msgType:"markdown"});return}const[u]=o.splice(c,1);o.unshift(u),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u63D2\u961F\u5230\u961F\u9996
|
|
79
|
+
1. **${u.senderNick||u.senderStaffId}:** ${this.truncateMsg(u.message)}`,msgType:"markdown"});return}case"rm":{if(o.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}const c=[...new Set(e.indices)],u=c.filter(T=>T>=1&&T<=o.length).sort((T,L)=>L-T),p=c.filter(T=>T<1||T>o.length);if(u.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F \u5E8F\u53F7\u65E0\u6548\uFF0C\u5F53\u524D\u961F\u5217\u5171 ${o.length} \u6761`,msgType:"markdown"});return}const f=[];for(const T of u)f.unshift(o.splice(T-1,1)[0]);const w=f.map(T=>`- **${T.senderNick||T.senderStaffId}:** ${this.truncateMsg(T.message)}`);let D=`\u2705 \u5DF2\u5220\u9664 ${f.length} \u6761\u6D88\u606F
|
|
80
|
+
${w.join(`
|
|
81
|
+
`)}`;p.length>0&&(D+=`
|
|
82
|
+
\u26A0\uFE0F \u5DF2\u5FFD\u7565\u65E0\u6548\u5E8F\u53F7: ${p.join(", ")}`),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:D,msgType:"markdown"});return}case"cancel":{if(o.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}const c=Math.min(e.count,o.length),p=o.splice(o.length-c,c).map((f,w)=>`${w+1}. **${f.senderNick||f.senderStaffId}:** ${this.truncateMsg(f.message)}`);await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u4ECE\u961F\u5C3E\u79FB\u9664 ${c} \u6761\u6D88\u606F
|
|
83
|
+
${p.join(`
|
|
84
|
+
`)}`,msgType:"markdown"});return}case"cancelAll":{if(o.length===0){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u{1F4ED} \u5F53\u524D\u65E0\u6392\u961F\u6D88\u606F",msgType:"markdown"});return}const c=o.length;o.length=0,await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u2705 \u5DF2\u6E05\u7A7A\u6D88\u606F\u961F\u5217\uFF0C\u5171\u79FB\u9664 ${c} \u6761\u6D88\u606F`,msgType:"markdown"});return}}}),(0,command_route_1.route)("/!",()=>(0,commands_1.parseInterruptCommand)(l),async()=>{const e=this.findActiveSession(s);if(!e){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD"});return}const d=e.session;if(!d.currentProcess){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u2139\uFE0F \u5F53\u524D\u6CA1\u6709\u6B63\u5728\u6267\u884C\u7684\u4EFB\u52A1"});return}(0,claude_process_1.interruptClaudeProcess)(d,`/!: ${n} \u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1`);const o=d.messageQueue.length;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:o>0?`\u23F9 \u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1\uFF0C\u5F00\u59CB\u5904\u7406\u961F\u5217\u4E2D\u7684 ${o} \u6761\u6D88\u606F`:"\u23F9 \u5DF2\u4E2D\u65AD\u5F53\u524D\u4EFB\u52A1"})}),(0,command_route_1.route)("/goon",()=>(0,commands_1.parseGoonCommand)(l),async()=>{const e=this.activeSessions.get(s);if(!e){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD"});return}if(e.currentProcess){console.log(`[${(0,session_1.timestamp)()}] /goon: \u7EC8\u6B62\u5F53\u524D Claude \u8FDB\u7A0B`),e.interrupted=!0,(0,platform_1.isWindows)()?e.currentProcess.kill():e.currentProcess.kill("SIGINT"),await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u{1F504} \u6B63\u5728\u91CD\u542F Claude \u8FDB\u7A0B..."}),e.goonPending=!1,e.isProcessing=!0;try{await(0,claude_process_1.executeClaudeQuery)(this,e.session,"\u7EE7\u7EED",{senderNick:e.session.startNickName,senderStaffId:e.lastSenderStaffId,permissionMode:e.conversationConfig.permissionMode})}finally{e.isProcessing=!1}}else{console.log(`[${(0,session_1.timestamp)()}] /goon: \u65E0\u8FD0\u884C\u4E2D\u8FDB\u7A0B\uFF0C\u76F4\u63A5\u53D1\u9001"\u7EE7\u7EED"`),e.isProcessing=!0;try{await(0,claude_process_1.executeClaudeQuery)(this,e.session,"\u7EE7\u7EED",{senderNick:n,senderStaffId:a,permissionMode:e.conversationConfig.permissionMode})}finally{e.isProcessing=!1}}}),(0,command_route_1.route)("/cc",()=>(0,commands_1.parseCcCommand)(l),async e=>{const d=this.activeSessions.get(s);if(!d){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u26A0\uFE0F \u5F53\u524D\u6CA1\u6709\u6D3B\u8DC3\u4F1A\u8BDD\uFF0C\u8BF7\u5148\u53D1\u9001\u6D88\u606F\u5F00\u59CB\u4F1A\u8BDD"});return}if(d.isProcessing){await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:"\u23F3 \u6B63\u5728\u5904\u7406\u4E2D\uFF0C\u8BF7\u7A0D\u7B49..."});return}d.isProcessing=!0;try{d.conversationConfig.receiveReply!==!1&&await this.sendDingMessage({conversationId:s,sessionWebhook:i,atUserId:a,content:"\u{1F4E5} \u5DF2\u6536\u5230\uFF0C\u6B63\u5728\u5904\u7406..."}).catch(()=>{}),await(0,claude_process_1.executeClaudeQuery)(this,d.session,e,{senderNick:n,senderStaffId:a,permissionMode:d.conversationConfig.permissionMode})}finally{d.isProcessing=!1}}),(0,command_route_1.route)("/claude.md",()=>(0,commands_1.parseClaudeMdCommand)(l),async()=>{const e=this.getConversationDir(s),d=path_1.default.join(e,".claude","CLAUDE.md");if(fs_1.default.existsSync(d)){const o=fs_1.default.readFileSync(d,"utf-8"),c=o.length>8e3?o.substring(0,8e3)+`
|
|
85
|
+
...(\u5185\u5BB9\u8FC7\u957F\u5DF2\u622A\u65AD)`:o;await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u{1F4C4} **CLAUDE.md**
|
|
81
86
|
\`\`\`
|
|
82
|
-
${
|
|
83
|
-
\`\`\``,msgType:"markdown"})}else await this.sendDingMessage({conversationId:
|
|
84
|
-
\u8DEF\u5F84: \`${
|
|
85
|
-
**\u7248\u672C:** ${TOOL_VERSION}`);let a;const
|
|
87
|
+
${c}
|
|
88
|
+
\`\`\``,msgType:"markdown"})}else await this.sendDingMessage({conversationId:s,sessionWebhook:i,content:`\u26A0\uFE0F \u672A\u627E\u5230 CLAUDE.md
|
|
89
|
+
\u8DEF\u5F84: \`${d}\``,msgType:"markdown"})})];for(const e of M)if(await e.tryHandle())return;let S=l;const C=[];if(t.atUsers&&t.atUsers.length>0){const e=t.chatbotUserId;for(const d of t.atUsers){const o=d.staffId||d.dingtalkId;!o||o===a||o===e||o.startsWith("$:LWCP_v1:")||C.push(o)}}if(C.length>0)for(const e of C){const d=await(0,session_1.resolveUserIdName)(this,e),o=d?`${d}(${e})`:e;S=S.replace(/\u200b/g,o)}await this.handleSessionMessage({conversationId:s,sessionWebhook:i,senderStaffId:a,senderNick:n,message:S,conversationConfig:y})}async notifyPendingReboot(){const r=path_1.default.join(this.getClientDir(),".reboot_pending");if(fs_1.default.existsSync(r))try{const t=JSON.parse(fs_1.default.readFileSync(r,"utf-8"));fs_1.default.unlinkSync(r);let n="\u2705 cc-ding \u5DF2\u91CD\u542F\u5B8C\u6210";t.update&&(n+=`
|
|
90
|
+
**\u7248\u672C:** ${TOOL_VERSION}`);let a;const s=this.activeSessions.get(t.conversationId);if(s)a=s.session.sessionWebhook;else if(t.sessionWebhook)a=t.sessionWebhook,console.log(`[${(0,session_1.timestamp)()}] \u91CD\u542F\u540E\u672A\u627E\u5230\u6D3B\u8DC3\u4F1A\u8BDD\uFF0C\u4F7F\u7528\u4FDD\u5B58\u7684 sessionWebhook \u53D1\u9001\u901A\u77E5`);else{console.log(`[${(0,session_1.timestamp)()}] \u91CD\u542F\u540E\u672A\u627E\u5230\u6D3B\u8DC3\u4F1A\u8BDD\u4E14\u65E0\u4FDD\u5B58\u7684 webhook\uFF0C\u8DF3\u8FC7\u901A\u77E5`);return}await this.sendDingMessage({conversationId:t.conversationId,sessionWebhook:a,content:n,msgType:"markdown",atUserId:t.senderStaffId}),console.log(`[${(0,session_1.timestamp)()}] \u91CD\u542F\u5B8C\u6210\u901A\u77E5\u5DF2\u53D1\u9001`)}catch(t){try{const n=fs_1.default.readFileSync(r,"utf-8");console.error(`[${(0,session_1.timestamp)()}] .reboot_pending \u5185\u5BB9:`,n)}catch{}console.error(`[${(0,session_1.timestamp)()}] \u5904\u7406\u91CD\u542F\u901A\u77E5\u5931\u8D25:`,t);try{fs_1.default.unlinkSync(r)}catch{}}}startConnectionWatchdog(){let n=Date.now();setInterval(()=>{const a=this.dingStreamClient;if(a.connected){n=Date.now();return}const s=Date.now()-n;if(s>=6e4){console.log(`[${(0,session_1.timestamp)()}] \u8FDE\u63A5\u76D1\u63A7: \u5DF2\u65AD\u5F00 ${s/1e3}s\uFF0C\u5F3A\u5236\u91CD\u65B0\u8FDE\u63A5`),n=Date.now();try{a.disconnect()}catch{}a.connect().catch(g=>{console.error(`[${(0,session_1.timestamp)()}] \u5F3A\u5236\u91CD\u8FDE\u5931\u8D25:`,g)})}else this.debugLog(`\u8FDE\u63A5\u76D1\u63A7: \u5DF2\u65AD\u5F00 ${s/1e3}s\uFF0C\u7B49\u5F85\u81EA\u52A8\u91CD\u8FDE...`)},3e4)}async run(){const r=Array.isArray(this.config.conversations)?this.config.conversations:[],t=this.config.taskHandlerCount??this.DEFAULT_TASK_HANDLER_COUNT,n=r.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: ${r.map(g=>g.conversationTitle||g.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(),(0,claude_process_1.injectStartupContexts)(this),await this.notifyPendingReboot(),this.cronEngine.start(),(0,menu_1.startSelectionCleanupTimer)(),this.startConnectionWatchdog(),n&&console.log(`[${(0,session_1.timestamp)()}] \u4EFB\u52A1\u5904\u7406\u5668\u6570\u91CF: ${t}`),this.dingStreamClient.registerCallbackListener("/v1.0/im/bot/messages/get",async g=>{await this.botMsgGetCallback(g)});const a=[];if(n)for(let g=0;g<t;g++)console.log(`[${(0,session_1.timestamp)()}] \u542F\u52A8\u4EFB\u52A1\u5904\u7406\u5668 #${g+1}`),a.push(this.runTaskHandlerLoop().catch(i=>console.error(`\u4EFB\u52A1\u5904\u7406\u5668 #${g+1} \u9519\u8BEF:`,i)));const s=this.dingStreamClient.connect().catch(g=>{console.error("Fatal error",g),process.exit(1)});await Promise.all([s,...a])}}exports.DingClaude=DingClaude;
|