mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-22 13:48:10 +00:00
fix: repair Feishu reset hook typing and stabilize secret resolver timeout
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user