@wu529778790/open-im 1.0.2-beta.0 → 1.0.2-beta.2

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.
@@ -8,7 +8,6 @@ import { CommandHandler } from '../commands/handler.js';
8
8
  import { getAdapter } from '../adapters/registry.js';
9
9
  import { runAITask } from '../shared/ai-task.js';
10
10
  import { startTaskCleanup } from '../shared/task-cleanup.js';
11
- import { MessageDedup } from '../shared/message-dedup.js';
12
11
  import { THROTTLE_MS, IMAGE_DIR } from '../constants.js';
13
12
  import { setActiveChatId } from '../shared/active-chats.js';
14
13
  import { createLogger } from '../logger.js';
@@ -62,7 +61,6 @@ export function setupFeishuHandlers(config, sessionManager) {
62
61
  const requestQueue = new RequestQueue();
63
62
  const runningTasks = new Map();
64
63
  const stopTaskCleanup = startTaskCleanup(runningTasks);
65
- const dedup = new MessageDedup();
66
64
  const commandHandler = new CommandHandler({
67
65
  config,
68
66
  sessionManager,
@@ -72,7 +70,8 @@ export function setupFeishuHandlers(config, sessionManager) {
72
70
  });
73
71
  registerPermissionSender('feishu', {});
74
72
  async function handleAIRequest(userId, chatId, prompt, workDir, convId, _threadCtx, replyToMessageId) {
75
- log.info(`[handleAIRequest] START: userId=${userId}, chatId=${chatId}, prompt="${prompt.slice(0, 50)}..."`);
73
+ log.info(`[AI_REQUEST] userId=${userId}, chatId=${chatId}, promptLength=${prompt.length}`);
74
+ log.info(`[AI_REQUEST] Full prompt: "${prompt}"`);
76
75
  const toolAdapter = getAdapter(config.aiCommand);
77
76
  if (!toolAdapter) {
78
77
  log.error(`[handleAIRequest] No adapter found for: ${config.aiCommand}`);
@@ -169,12 +168,6 @@ export function setupFeishuHandlers(config, sessionManager) {
169
168
  return;
170
169
  }
171
170
  log.info(`Sender ID: ${senderId}`);
172
- // Dedup check
173
- const dedupKey = `${chatId}:${messageId}`;
174
- if (dedup.isDuplicate(dedupKey)) {
175
- log.info(`Duplicate message detected: ${dedupKey}`);
176
- return;
177
- }
178
171
  // Access control check
179
172
  if (!accessControl.isAllowed(senderId)) {
180
173
  log.warn(`Access denied for sender: ${senderId}`);
@@ -186,7 +179,8 @@ export function setupFeishuHandlers(config, sessionManager) {
186
179
  // Handle different message types
187
180
  if (msgType === 'text') {
188
181
  const text = content.text?.trim() ?? '';
189
- log.info(`Processing text message from ${senderId}: ${text}`);
182
+ log.info(`[MSG] Type=text, User=${senderId}, Length=${text.length}, Content="${text}"`);
183
+ log.info(`[MSG] Full content keys:`, Object.keys(content).join(', '));
190
184
  // Handle commands
191
185
  try {
192
186
  const handled = await commandHandler.dispatch(text, chatId, senderId, 'feishu', handleAIRequest);
@@ -213,6 +207,76 @@ export function setupFeishuHandlers(config, sessionManager) {
213
207
  sendTextReply(chatId, '您的请求已排队等待。').catch(() => { });
214
208
  }
215
209
  }
210
+ else if (msgType === 'post') {
211
+ // Feishu rich text/post messages - extract text content
212
+ const post = content?.post;
213
+ let text = '';
214
+ if (post?.content && Array.isArray(post.content)) {
215
+ // Log full structure for debugging
216
+ log.info(`[MSG] Post content structure:`, JSON.stringify(post.content).slice(0, 500));
217
+ // Extract text from rich text structure
218
+ for (const section of post.content) {
219
+ if (!section || typeof section !== 'object')
220
+ continue;
221
+ const tag = section?.tag;
222
+ // Handle different content types
223
+ if (tag === 'text' || tag === 'plain_text') {
224
+ const t = section?.text ?? '';
225
+ text += t;
226
+ }
227
+ else if (tag === 'heading' || tag === 'heading1' || tag === 'heading2' || tag === 'heading3') {
228
+ // Handle headings - might be nested structure
229
+ const headingText = section?.text;
230
+ if (typeof headingText === 'string') {
231
+ text += headingText;
232
+ }
233
+ else if (Array.isArray(headingText)) {
234
+ // Nested text elements in heading
235
+ for (const item of headingText) {
236
+ if (item && typeof item === 'object' && 'text' in item) {
237
+ text += item.text ?? '';
238
+ }
239
+ }
240
+ }
241
+ }
242
+ else {
243
+ // Log unhandled tags for debugging
244
+ log.info(`[MSG] Unhandled post tag: ${tag}, section:`, JSON.stringify(section).slice(0, 200));
245
+ }
246
+ }
247
+ }
248
+ text = text.trim();
249
+ log.info(`[MSG] Type=post, User=${senderId}, Length=${text.length}, Content="${text}"`);
250
+ if (!text) {
251
+ log.warn('[MSG] Post message has no extractable text content');
252
+ return;
253
+ }
254
+ // Handle commands
255
+ try {
256
+ const handled = await commandHandler.dispatch(text, chatId, senderId, 'feishu', handleAIRequest);
257
+ if (handled) {
258
+ log.info(`Command handled for post message: ${text}`);
259
+ return;
260
+ }
261
+ }
262
+ catch (err) {
263
+ log.error('Error in commandHandler.dispatch for post:', err);
264
+ }
265
+ // Handle AI request
266
+ log.info(`Enqueueing AI request for post message: ${text}`);
267
+ const workDir = sessionManager.getWorkDir(senderId);
268
+ const convId = sessionManager.getConvId(senderId);
269
+ const enqueueResult = requestQueue.enqueue(senderId, convId, text, async (prompt) => {
270
+ log.info(`Executing AI request for post: ${prompt}`);
271
+ await handleAIRequest(senderId, chatId, prompt, workDir, convId, undefined, messageId);
272
+ });
273
+ if (enqueueResult === 'rejected') {
274
+ sendTextReply(chatId, '请求队列已满,请稍后再试。').catch(() => { });
275
+ }
276
+ else if (enqueueResult === 'queued') {
277
+ sendTextReply(chatId, '您的请求已排队等待。').catch(() => { });
278
+ }
279
+ }
216
280
  else if (msgType === 'image') {
217
281
  const imageKey = content.image_key;
218
282
  if (!imageKey)
@@ -241,6 +305,10 @@ export function setupFeishuHandlers(config, sessionManager) {
241
305
  log.error('Error processing image message:', err);
242
306
  }
243
307
  }
308
+ else {
309
+ log.warn(`[MSG] Unsupported message type: ${msgType}, senderId=${senderId}`);
310
+ log.info(`[MSG] Content structure:`, JSON.stringify(content).slice(0, 500));
311
+ }
244
312
  }
245
313
  }
246
314
  catch (err) {
@@ -9,7 +9,6 @@ import { CommandHandler } from "../commands/handler.js";
9
9
  import { getAdapter } from "../adapters/registry.js";
10
10
  import { runAITask } from "../shared/ai-task.js";
11
11
  import { startTaskCleanup } from "../shared/task-cleanup.js";
12
- import { MessageDedup } from "../shared/message-dedup.js";
13
12
  import { TELEGRAM_THROTTLE_MS, IMAGE_DIR } from "../constants.js";
14
13
  import { setActiveChatId } from "../shared/active-chats.js";
15
14
  import { createLogger } from "../logger.js";
@@ -71,7 +70,6 @@ export function setupTelegramHandlers(bot, config, sessionManager) {
71
70
  const requestQueue = new RequestQueue();
72
71
  const runningTasks = new Map();
73
72
  const stopTaskCleanup = startTaskCleanup(runningTasks);
74
- const dedup = new MessageDedup();
75
73
  const commandHandler = new CommandHandler({
76
74
  config,
77
75
  sessionManager,
@@ -318,8 +316,6 @@ export function setupTelegramHandlers(bot, config, sessionManager) {
318
316
  const userId = String(ctx.from.id);
319
317
  const messageId = String(ctx.message.message_id);
320
318
  let text = ctx.message.text.trim();
321
- if (dedup.isDuplicate(`${chatId}:${messageId}`))
322
- return;
323
319
  if (!accessControl.isAllowed(userId)) {
324
320
  await sendTextReply(chatId, "抱歉,您没有访问权限。\n您的 ID: " + userId);
325
321
  return;
@@ -344,8 +340,6 @@ export function setupTelegramHandlers(bot, config, sessionManager) {
344
340
  const chatId = String(ctx.chat.id);
345
341
  const userId = String(ctx.from.id);
346
342
  const caption = ctx.message.caption?.trim() || "";
347
- if (dedup.isDuplicate(`${chatId}:${ctx.message.message_id}`))
348
- return;
349
343
  if (!accessControl.isAllowed(userId))
350
344
  return;
351
345
  setActiveChatId("telegram", chatId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wu529778790/open-im",
3
- "version": "1.0.2-beta.0",
3
+ "version": "1.0.2-beta.2",
4
4
  "description": "Multi-platform IM bridge for AI CLI tools (Claude, Codex, Cursor)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",