diff --git a/src/__tests__/ask-user-question.test.ts b/src/__tests__/ask-user-question.test.ts index 84b02ec..c2a5038 100644 --- a/src/__tests__/ask-user-question.test.ts +++ b/src/__tests__/ask-user-question.test.ts @@ -54,8 +54,8 @@ describe('buildAskUserQuestionCard', () => { expect(actionGroup.tag).toBe('action'); expect(actionGroup.actions).toHaveLength(2); - // First option should be primary - expect(actionGroup.actions[0].type).toBe('primary'); + // All options should be default (no misleading "primary" highlight) + expect(actionGroup.actions[0].type).toBe('default'); expect(actionGroup.actions[0].text.content).toBe('Option A'); expect(actionGroup.actions[0].value).toEqual({ action: 'ask_user_answer', @@ -65,7 +65,6 @@ describe('buildAskUserQuestionCard', () => { optionLabel: 'Option A', }); - // Second option should be default expect(actionGroup.actions[1].type).toBe('default'); expect(actionGroup.actions[1].text.content).toBe('Option B'); }); diff --git a/src/feishu/event-handler.ts b/src/feishu/event-handler.ts index 412690f..c215a61 100644 --- a/src/feishu/event-handler.ts +++ b/src/feishu/event-handler.ts @@ -132,8 +132,13 @@ interface PendingQuestion { /** questionId → PendingQuestion */ const pendingQuestions = new Map(); -/** AskUserQuestion 等待超时(5 分钟) */ -const ASK_USER_TIMEOUT_MS = 5 * 60 * 1000; +/** AskUserQuestion 等待超时(毫秒)。0 表示永不超时(默认)。 */ +const ASK_USER_TIMEOUT_MS = (() => { + const raw = process.env.ASK_USER_TIMEOUT_MS; + if (raw === undefined || raw === '') return 0; + const n = Number(raw); + return Number.isFinite(n) && n > 0 ? n : 0; +})(); /** * 创建 AskUserQuestion 回调(供 executeClaudeTask / executeDirectTask 共用) @@ -161,15 +166,17 @@ function createAskUserHandler(chatId: string, getThreadReplyMsgId: () => string chatId, }; - pending.timeoutTimer = setTimeout(() => { - pendingQuestions.delete(questionId); - reject(new Error('AskUserQuestion timed out')); - }, ASK_USER_TIMEOUT_MS); + if (ASK_USER_TIMEOUT_MS > 0) { + pending.timeoutTimer = setTimeout(() => { + pendingQuestions.delete(questionId); + reject(new Error('AskUserQuestion timed out')); + }, ASK_USER_TIMEOUT_MS); + } pendingQuestions.set(questionId, pending); // 发送卡片(在话题内回复或直接发到群) - // 如果发送失败,立即 reject 而非等待 5 分钟超时 + // 如果发送失败,立即 reject 而非等待用户回答(避免任务永久挂起) const trySendCard = async () => { try { const threadMsgId = getThreadReplyMsgId(); diff --git a/src/feishu/message-builder.ts b/src/feishu/message-builder.ts index 94460b0..32b22aa 100644 --- a/src/feishu/message-builder.ts +++ b/src/feishu/message-builder.ts @@ -1282,7 +1282,7 @@ export function buildAskUserQuestionCard( const buttons = q.options.map((opt, oi) => ({ tag: 'button', text: { tag: 'plain_text', content: opt.label }, - type: oi === 0 ? 'primary' : 'default', + type: 'default', value: { action: 'ask_user_answer', questionId,