@wu529778790/open-im 1.8.1-beta.17 → 1.8.1-beta.19
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.
|
@@ -19,7 +19,6 @@ export declare class CommandHandler {
|
|
|
19
19
|
private deps;
|
|
20
20
|
constructor(deps: CommandHandlerDeps);
|
|
21
21
|
dispatch(text: string, chatId: string, userId: string, platform: 'dingtalk' | 'feishu' | 'qq' | 'telegram' | 'wechat' | 'wework' | 'workbuddy', handleClaudeRequest: ClaudeRequestHandler): Promise<boolean>;
|
|
22
|
-
private getClearHistoryHint;
|
|
23
22
|
private handleHelp;
|
|
24
23
|
private handleNew;
|
|
25
24
|
private handlePwd;
|
package/dist/commands/handler.js
CHANGED
|
@@ -16,9 +16,9 @@ export class CommandHandler {
|
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
if (t === '/help')
|
|
19
|
-
return this.handleHelp(chatId
|
|
19
|
+
return this.handleHelp(chatId);
|
|
20
20
|
if (t === '/new')
|
|
21
|
-
return this.handleNew(chatId, userId
|
|
21
|
+
return this.handleNew(chatId, userId);
|
|
22
22
|
if (t === '/pwd')
|
|
23
23
|
return this.handlePwd(chatId, userId);
|
|
24
24
|
if (t === '/status')
|
|
@@ -33,18 +33,7 @@ export class CommandHandler {
|
|
|
33
33
|
}
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
return platform === 'feishu'
|
|
38
|
-
? '💡 提示:如需清除本对话的历史消息,请点击飞书聊天右上角「...」→ 清除聊天记录'
|
|
39
|
-
: platform === 'wechat'
|
|
40
|
-
? '💡 提示:如需清除本对话的历史消息,请清除聊天记录'
|
|
41
|
-
: platform === 'dingtalk'
|
|
42
|
-
? '💡 提示:如需清除本对话的历史消息,请在钉钉中清空聊天记录'
|
|
43
|
-
: platform === 'workbuddy'
|
|
44
|
-
? '💡 提示:如需清除本对话的历史消息,请清除聊天记录'
|
|
45
|
-
: '💡 提示:如需清除本对话的历史消息,请点击 Telegram 聊天右上角 ⋮ → 清除历史';
|
|
46
|
-
}
|
|
47
|
-
async handleHelp(chatId, platform) {
|
|
36
|
+
async handleHelp(chatId) {
|
|
48
37
|
const help = [
|
|
49
38
|
'📋 可用命令:',
|
|
50
39
|
'',
|
|
@@ -53,16 +42,14 @@ export class CommandHandler {
|
|
|
53
42
|
'/status - 显示状态',
|
|
54
43
|
'/cd <路径> - 切换工作目录',
|
|
55
44
|
'/pwd - 当前工作目录',
|
|
56
|
-
'',
|
|
57
|
-
this.getClearHistoryHint(platform),
|
|
58
45
|
].join('\n');
|
|
59
46
|
await this.deps.sender.sendTextReply(chatId, help);
|
|
60
47
|
return true;
|
|
61
48
|
}
|
|
62
|
-
async handleNew(chatId, userId
|
|
49
|
+
async handleNew(chatId, userId) {
|
|
63
50
|
const ok = this.deps.sessionManager.newSession(userId);
|
|
64
51
|
await this.deps.sender.sendTextReply(chatId, ok
|
|
65
|
-
?
|
|
52
|
+
? '✅ AI 会话已重置,下一条消息将使用全新上下文。'
|
|
66
53
|
: '当前没有活动会话。');
|
|
67
54
|
return true;
|
|
68
55
|
}
|
|
@@ -103,8 +90,7 @@ export class CommandHandler {
|
|
|
103
90
|
try {
|
|
104
91
|
const resolved = await this.deps.sessionManager.setWorkDir(userId, dir);
|
|
105
92
|
await this.deps.sender.sendTextReply(chatId, `📁 工作目录已切换到: ${escapePathForMarkdown(resolved)}\n\n` +
|
|
106
|
-
`🔄 AI
|
|
107
|
-
this.getClearHistoryHint(platform));
|
|
93
|
+
`🔄 AI 会话已重置,下一条消息将使用全新上下文。`);
|
|
108
94
|
}
|
|
109
95
|
catch (err) {
|
|
110
96
|
await this.deps.sender.sendTextReply(chatId, err instanceof Error ? err.message : String(err));
|
|
@@ -150,27 +150,38 @@ export function setupFeishuHandlers(config, sessionManager) {
|
|
|
150
150
|
const toolId = aiCommand;
|
|
151
151
|
// 使用 CardKit 打字机效果(80ms 节流,约 12 次/秒,比 patch 5 QPS 更流畅)
|
|
152
152
|
let cardHandle;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// 检测是否为飞书权限不足
|
|
159
|
-
if (isPermissionError(err)) {
|
|
160
|
-
const guide = buildPermissionGuideMessage(err);
|
|
161
|
-
await sendPermissionFallback(chatId, guide).catch((err) => {
|
|
162
|
-
log.warn('Permission fallback send failed:', err);
|
|
163
|
-
});
|
|
153
|
+
const MAX_SEND_RETRIES = 3;
|
|
154
|
+
for (let attempt = 1; attempt <= MAX_SEND_RETRIES; attempt++) {
|
|
155
|
+
try {
|
|
156
|
+
cardHandle = await sendThinkingCard(chatId, toolId);
|
|
157
|
+
break;
|
|
164
158
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
catch (err) {
|
|
160
|
+
const isRetryable = err && typeof err === 'object' && 'code' in err &&
|
|
161
|
+
(err.code === 'ETIMEDOUT' || err.code === 'ECONNRESET' || err.code === 'ECONNREFUSED');
|
|
162
|
+
if (isRetryable && attempt < MAX_SEND_RETRIES) {
|
|
163
|
+
log.warn(`sendThinkingCard attempt ${attempt}/${MAX_SEND_RETRIES} failed (${err.code}), retrying...`);
|
|
164
|
+
await new Promise((r) => setTimeout(r, 1000 * attempt));
|
|
165
|
+
continue;
|
|
168
166
|
}
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
log.error(`Failed to send thinking card after ${attempt} attempts:`, err);
|
|
168
|
+
// 检测是否为飞书权限不足
|
|
169
|
+
if (isPermissionError(err)) {
|
|
170
|
+
const guide = buildPermissionGuideMessage(err);
|
|
171
|
+
await sendPermissionFallback(chatId, guide).catch((err) => {
|
|
172
|
+
log.warn('Permission fallback send failed:', err);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
try {
|
|
177
|
+
await sendTextReply(chatId, '启动 AI 处理失败,请重试。');
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
log.warn('Failed to send startup error reply:', err);
|
|
181
|
+
}
|
|
171
182
|
}
|
|
183
|
+
return;
|
|
172
184
|
}
|
|
173
|
-
return;
|
|
174
185
|
}
|
|
175
186
|
const { messageId: msgId, cardId } = cardHandle;
|
|
176
187
|
const stopTyping = startTypingLoop(chatId);
|