fix: repair Feishu reset hook typing and stabilize secret resolver timeout

This commit is contained in:
Peter Steinberger
2026-03-03 05:06:02 +00:00
parent a9ec75fe81
commit 2d67c9b2a0
3 changed files with 56 additions and 42 deletions

View File

@@ -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;

View File

@@ -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<string, unknown>;
sessionEntry: Record<string, unknown>;
previousSessionEntry?: Record<string, unknown>;
commandSource: string;
timestamp: number;
};
type FeishuBeforeResetEvent = {
type: "command";
action: "new" | "reset";
context: FeishuBeforeResetContext;
};
type FeishuBeforeResetRunner = {
runBeforeReset: (
event: FeishuBeforeResetEvent,
ctx: { agentId: string; sessionKey: string },
) => Promise<void>;
};
/**
* 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<boolean> {
// 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
}
return true;
}

View File

@@ -217,7 +217,7 @@ describe("secret ref resolver", () => {
source: "exec",
command: scriptPath,
passEnv: ["PATH"],
timeoutMs: 500,
timeoutMs: 1500,
},
},
},