@wu529778790/open-im 0.3.4 → 0.3.5

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.
@@ -114,7 +114,23 @@ export function setupTelegramHandlers(bot, config, sessionManager) {
114
114
  // 流式输出时显示最后 N 个字符(增加到 1500 以提高流畅度)
115
115
  const STREAM_PREVIEW_LENGTH = 1500;
116
116
  // 执行更新(串行化)
117
- const performUpdate = async (content, toolNote) => {
117
+ const performUpdate = async (content, toolNote, isComplete = false) => {
118
+ // 如果是完成更新,需要优先处理,取消待处理的更新
119
+ if (isComplete) {
120
+ // 清除防抖定时器
121
+ if (debounceTimer) {
122
+ clearTimeout(debounceTimer);
123
+ debounceTimer = null;
124
+ }
125
+ // 如果有更新正在进行,等待它完成
126
+ while (updateInProgress) {
127
+ await new Promise(resolve => setTimeout(resolve, 50));
128
+ }
129
+ // 重置状态,确保完成更新能立即执行
130
+ updateInProgress = false;
131
+ scheduledContent = null;
132
+ scheduledToolNote = undefined;
133
+ }
118
134
  if (updateInProgress) {
119
135
  // 如果有更新正在进行,保存当前内容待更新
120
136
  scheduledContent = content;
@@ -222,8 +238,16 @@ export function setupTelegramHandlers(bot, config, sessionManager) {
222
238
  },
223
239
  sendComplete: async (content, note) => {
224
240
  throttle.reset();
225
- // 完成时,只发送最终结果,不包含思考内容
226
- await sendFinalMessages(chatId, msgId, content, note, toolId);
241
+ // 完成时,直接调用 updateMessage 更新状态,绕过流式更新机制
242
+ // 确保完成状态能够立即生效,移除停止按钮
243
+ try {
244
+ await sendFinalMessages(chatId, msgId, content, note, toolId);
245
+ }
246
+ catch (err) {
247
+ log.error('Failed to send complete message:', err);
248
+ // 如果发送失败,至少尝试更新状态
249
+ await updateMessage(chatId, msgId, content, 'done', note, toolId);
250
+ }
227
251
  },
228
252
  sendError: async (error) => {
229
253
  throttle.reset();
@@ -104,6 +104,8 @@ export async function updateMessage(chatId, messageId, content, status, note, to
104
104
  else if (status === 'done' || status === 'error') {
105
105
  // 完成或错误时,显式移除停止按钮(使用空的 inline_keyboard)
106
106
  opts.reply_markup = { inline_keyboard: [] };
107
+ // 添加日志,帮助诊断
108
+ log.info(`Updating message to ${status} status (removing stop button) for ${chatId}:${messageId}`);
107
109
  }
108
110
  // 流式输出时使用纯文本,避免 Markdown 解析导致内容减少
109
111
  // 只在完成时应用 Markdown 格式
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, Cursor)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",