mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-09 12:22:53 +00:00
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.
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
|
|
import { normalizeCommandBody } from "./commands-registry.js";
|
|
import { stripInboundMetadata } from "./reply/strip-inbound-meta.js";
|
|
|
|
type SendPolicyOverride = "allow" | "deny";
|
|
|
|
function normalizeSendPolicyOverride(raw?: string | null): SendPolicyOverride | undefined {
|
|
const value = normalizeOptionalLowercaseString(raw);
|
|
if (!value) {
|
|
return undefined;
|
|
}
|
|
if (value === "allow" || value === "on") {
|
|
return "allow";
|
|
}
|
|
if (value === "deny" || value === "off") {
|
|
return "deny";
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function parseSendPolicyCommand(raw?: string): {
|
|
hasCommand: boolean;
|
|
mode?: SendPolicyOverride | "inherit";
|
|
} {
|
|
if (!raw) {
|
|
return { hasCommand: false };
|
|
}
|
|
const trimmed = raw.trim();
|
|
if (!trimmed) {
|
|
return { hasCommand: false };
|
|
}
|
|
const stripped = stripInboundMetadata(trimmed);
|
|
const normalized = normalizeCommandBody(stripped);
|
|
const match = normalized.match(/^\/send(?:\s+([a-zA-Z]+))?\s*$/i);
|
|
if (!match) {
|
|
return { hasCommand: false };
|
|
}
|
|
const token = normalizeOptionalLowercaseString(match[1]);
|
|
if (!token) {
|
|
return { hasCommand: true };
|
|
}
|
|
if (token === "inherit" || token === "default" || token === "reset") {
|
|
return { hasCommand: true, mode: "inherit" };
|
|
}
|
|
const mode = normalizeSendPolicyOverride(token);
|
|
return { hasCommand: true, mode };
|
|
}
|