mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 10:50:58 +00:00
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
|
import { getChannelPlugin } from "./index.js";
|
|
import type { ChannelMessageActionContext } from "./types.js";
|
|
|
|
function requiresTrustedRequesterSender(ctx: ChannelMessageActionContext): boolean {
|
|
const plugin = getChannelPlugin(ctx.channel);
|
|
return Boolean(
|
|
plugin?.actions?.requiresTrustedRequesterSender?.({
|
|
action: ctx.action,
|
|
toolContext: ctx.toolContext,
|
|
}),
|
|
);
|
|
}
|
|
|
|
export async function dispatchChannelMessageAction(
|
|
ctx: ChannelMessageActionContext,
|
|
): Promise<AgentToolResult<unknown> | null> {
|
|
if (requiresTrustedRequesterSender(ctx) && !ctx.requesterSenderId?.trim()) {
|
|
throw new Error(
|
|
`Trusted sender identity is required for ${ctx.channel}:${ctx.action} in tool-driven contexts.`,
|
|
);
|
|
}
|
|
const plugin = getChannelPlugin(ctx.channel);
|
|
if (!plugin?.actions?.handleAction) {
|
|
return null;
|
|
}
|
|
if (plugin.actions.supportsAction && !plugin.actions.supportsAction({ action: ctx.action })) {
|
|
return null;
|
|
}
|
|
return await plugin.actions.handleAction(ctx);
|
|
}
|