@wu529778790/open-im 0.3.8 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +23 -2
- package/dist/shared/ai-task.js +5 -4
- package/dist/telegram/event-handler.js +3 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -192,8 +192,29 @@ else if (args[0] === 'restart') {
|
|
|
192
192
|
await stopService().catch((err) => {
|
|
193
193
|
console.error('停止服务时出错:', err);
|
|
194
194
|
});
|
|
195
|
-
// 等待进程完全退出
|
|
196
|
-
|
|
195
|
+
// 等待进程完全退出 AND Telegram API 释放连接(至少 3 秒)
|
|
196
|
+
// Telegram 需要时间释放 bot 实例,否则会出现 409 Conflict 错误
|
|
197
|
+
const pid = await readPid();
|
|
198
|
+
if (pid) {
|
|
199
|
+
// 持续检查直到进程真正退出(最多 15 秒)
|
|
200
|
+
const maxWait = 15000;
|
|
201
|
+
const checkInterval = 500;
|
|
202
|
+
let waited = 0;
|
|
203
|
+
while (waited < maxWait) {
|
|
204
|
+
if (!(await isProcessRunning(pid))) {
|
|
205
|
+
// 进程已退出,再等待 3 秒让 Telegram API 完全释放
|
|
206
|
+
const remainingWait = 3000;
|
|
207
|
+
console.log(`进程已退出,等待 ${remainingWait / 1000} 秒让 Telegram API 释放连接...`);
|
|
208
|
+
await new Promise(resolve => setTimeout(resolve, remainingWait));
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
await new Promise(resolve => setTimeout(resolve, checkInterval));
|
|
212
|
+
waited += checkInterval;
|
|
213
|
+
}
|
|
214
|
+
if (waited >= maxWait) {
|
|
215
|
+
console.log('警告: 进程退出超时,继续启动...');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
197
218
|
console.log('\n正在重新启动服务...\n');
|
|
198
219
|
await startService();
|
|
199
220
|
}
|
package/dist/shared/ai-task.js
CHANGED
|
@@ -12,10 +12,11 @@ function buildCompletionNote(result, sessionManager, ctx) {
|
|
|
12
12
|
parts.push(toolInfo);
|
|
13
13
|
if (result.model)
|
|
14
14
|
parts.push(result.model);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
// 获取当前的总轮数(不再累加,因为已经在请求开始时累加了)
|
|
16
|
+
const currentTurns = ctx.threadId
|
|
17
|
+
? sessionManager.addTurnsForThread(ctx.userId, ctx.threadId, 0)
|
|
18
|
+
: sessionManager.addTurns(ctx.userId, 0);
|
|
19
|
+
const ctxWarning = getContextWarning(currentTurns);
|
|
19
20
|
if (ctxWarning)
|
|
20
21
|
parts.push(ctxWarning);
|
|
21
22
|
return parts.join(' | ');
|
|
@@ -79,6 +79,9 @@ export function setupTelegramHandlers(bot, config, sessionManager) {
|
|
|
79
79
|
});
|
|
80
80
|
registerPermissionSender('telegram', {});
|
|
81
81
|
async function handleAIRequest(userId, chatId, prompt, workDir, convId, _threadCtx, replyToMessageId) {
|
|
82
|
+
// 在用户每次发送消息时就累加计数,确保提示能轮换显示
|
|
83
|
+
const currentTurns = sessionManager.addTurns(userId, 1);
|
|
84
|
+
log.info(`User request: total turns = ${currentTurns} for user ${userId}`);
|
|
82
85
|
const toolAdapter = getAdapter(config.aiCommand);
|
|
83
86
|
if (!toolAdapter) {
|
|
84
87
|
await sendTextReply(chatId, `未配置 AI 工具: ${config.aiCommand}`);
|