Files
openclaw/src/agents/embedded-agent-messaging.ts
Peter Steinberger 00d8d7ead0 refactor: extract normalization core package
Extract shared normalization/coercion helpers into private @openclaw/normalization-core workspace package while preserving existing plugin SDK helper subpaths.\n\nAlso keeps direct normalization-core imports internal, wires UI/build/loader resolution, and replaces the slow PR network CodeQL lane with a fast added-line boundary scan while retaining full CodeQL for scheduled/manual runs.\n\nVerification: local moved tests, plugin SDK boundary tests, extension loader tests, agents-support shard, UI build/test, build artifacts, lint, workflow guards, autoreview, and GitHub CI passed on PR head 963d893715.
2026-05-31 01:33:00 +01:00

48 lines
1.4 KiB
TypeScript

import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
import { getChannelPlugin, normalizeChannelId } from "../channels/plugins/index.js";
const CORE_MESSAGING_TOOLS = new Set(["sessions_send", "message"]);
const MESSAGE_TOOL_SEND_ACTIONS = new Set([
"send",
"thread-reply",
"sendWithEffect",
"sendAttachment",
"upload-file",
]);
export function isMessageToolSendActionName(action: unknown): boolean {
const normalized = normalizeOptionalString(action) ?? "";
return MESSAGE_TOOL_SEND_ACTIONS.has(normalized);
}
// Provider docking: any plugin with `actions` opts into messaging tool handling.
export function isMessagingTool(toolName: string): boolean {
if (CORE_MESSAGING_TOOLS.has(toolName)) {
return true;
}
const providerId = normalizeChannelId(toolName);
return Boolean(providerId && getChannelPlugin(providerId)?.actions);
}
export function isMessagingToolSendAction(
toolName: string,
args: Record<string, unknown>,
): boolean {
const action = normalizeOptionalString(args.action) ?? "";
if (toolName === "sessions_send") {
return true;
}
if (toolName === "message") {
return isMessageToolSendActionName(action);
}
const providerId = normalizeChannelId(toolName);
if (!providerId) {
return false;
}
const plugin = getChannelPlugin(providerId);
if (!plugin?.actions?.extractToolSend) {
return false;
}
return Boolean(plugin.actions.extractToolSend({ args })?.to);
}