From 2d67c9b2a075d8d6c7e1d15029f497f1905dafd3 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 3 Mar 2026 05:06:02 +0000 Subject: [PATCH] fix: repair Feishu reset hook typing and stabilize secret resolver timeout --- extensions/feishu/src/bot.ts | 8 +- .../feishu/src/feishu-command-handler.ts | 88 +++++++++++-------- src/secrets/resolve.test.ts | 2 +- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/extensions/feishu/src/bot.ts b/extensions/feishu/src/bot.ts index f3fcc9a03a2..2a4ac9a3063 100644 --- a/extensions/feishu/src/bot.ts +++ b/extensions/feishu/src/bot.ts @@ -450,7 +450,11 @@ function formatSubMessageContent(content: string, contentType: string): string { } } -function checkBotMentioned(event: FeishuMessageEvent, botOpenId?: string, botName?: string): boolean { +function checkBotMentioned( + event: FeishuMessageEvent, + botOpenId?: string, + botName?: string, +): boolean { if (!botOpenId) return false; // Check for @all (@_all in Feishu) — treat as mentioning every bot const rawContent = event.message.content ?? ""; @@ -886,7 +890,7 @@ export async function handleFeishuMessage(params: { return; } - let ctx = parseFeishuMessageEvent(event, botOpenId, botName ?? account.config?.botName); + let ctx = parseFeishuMessageEvent(event, botOpenId, botName); const isGroup = ctx.chatType === "group"; const isDirect = !isGroup; const senderUserId = event.sender.sender_id.user_id?.trim() || undefined; diff --git a/extensions/feishu/src/feishu-command-handler.ts b/extensions/feishu/src/feishu-command-handler.ts index e3dba51c957..70283ea4288 100644 --- a/extensions/feishu/src/feishu-command-handler.ts +++ b/extensions/feishu/src/feishu-command-handler.ts @@ -1,49 +1,59 @@ -import type { PluginHookRunner } from "openclaw/plugin-sdk"; -import { DEFAULT_RESET_TRIGGERS } from "../../../config/sessions/types.js"; +const DEFAULT_RESET_TRIGGERS = ["/new", "/reset"] as const; + +type FeishuBeforeResetContext = { + cfg: Record; + sessionEntry: Record; + previousSessionEntry?: Record; + commandSource: string; + timestamp: number; +}; + +type FeishuBeforeResetEvent = { + type: "command"; + action: "new" | "reset"; + context: FeishuBeforeResetContext; +}; + +type FeishuBeforeResetRunner = { + runBeforeReset: ( + event: FeishuBeforeResetEvent, + ctx: { agentId: string; sessionKey: string }, + ) => Promise; +}; /** - * Handle Feishu command messages and trigger appropriate hooks + * Handle Feishu command messages and trigger reset hooks. */ export async function handleFeishuCommand( messageText: string, sessionKey: string, - hookRunner: PluginHookRunner, - context: { - cfg: any; - sessionEntry: any; - previousSessionEntry?: any; - commandSource: string; - timestamp: number; - } + hookRunner: FeishuBeforeResetRunner, + context: FeishuBeforeResetContext, ): Promise { - // Check if message is a reset command const trimmed = messageText.trim().toLowerCase(); - const isResetCommand = DEFAULT_RESET_TRIGGERS.some(trigger => - trimmed === trigger || trimmed.startsWith(`${trigger} `) + const isResetCommand = DEFAULT_RESET_TRIGGERS.some( + (trigger) => trimmed === trigger || trimmed.startsWith(`${trigger} `), + ); + if (!isResetCommand) { + return false; + } + + const command = trimmed.split(" ")[0]; + const action: "new" | "reset" = command === "/new" ? "new" : "reset"; + await hookRunner.runBeforeReset( + { + type: "command", + action, + context: { + ...context, + commandSource: "feishu", + }, + }, + { + agentId: "main", + sessionKey, + }, ); - if (isResetCommand) { - // Extract the actual command (without arguments) - const command = trimmed.split(' ')[0]; - - // Trigger the before_reset hook - await hookRunner.runBeforeReset( - { - type: "command", - action: command.replace('/', '') as "new" | "reset", - context: { - ...context, - commandSource: "feishu" - } - }, - { - agentId: "main", // or extract from sessionKey - sessionKey - } - ); - - return true; // Command was handled - } - - return false; // Not a command we handle -} \ No newline at end of file + return true; +} diff --git a/src/secrets/resolve.test.ts b/src/secrets/resolve.test.ts index d49bfe71a3c..716ab5af7fa 100644 --- a/src/secrets/resolve.test.ts +++ b/src/secrets/resolve.test.ts @@ -217,7 +217,7 @@ describe("secret ref resolver", () => { source: "exec", command: scriptPath, passEnv: ["PATH"], - timeoutMs: 500, + timeoutMs: 1500, }, }, },