* refactor: consume acpx runtime library * refactor: remove duplicated acpx runtime files * fix: update acpx runtime dependency * fix: preserve acp runtime error codes * fix: migrate legacy acpx session files * fix: update acpx runtime dependency * fix: import Dirent from node fs * ACPX: repin shared runtime engine * ACPX: repin runtime semantics fixes * ACPX: repin runtime contract cleanup * Extensions: repin ACPX after layout refactor * ACPX: drop legacy session migration * ACPX: drop direct ACP SDK dependency * Discord ACP: stop duplicate direct fallback replies * ACP: rename delivered text visibility hook * ACPX: pin extension to 0.5.0 * Deps: drop stale ACPX build-script allowlist * ACPX: add local development guidance * ACPX: document temporary pnpm exception flow * SDK: preserve legacy ACP visibility hook * ACP: keep reset commands on local path * ACP: make in-place reset start fresh session * ACP: recover broken bindings on fresh reset * ACP: defer fresh reset marker until close succeeds * ACP: reset bound sessions fresh again * Discord: ensure ACP bindings before /new * ACP: recover missing persistent sessions
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import type { OpenClawConfig } from "../../config/config.js";
|
|
import {
|
|
isCommandEnabled,
|
|
maybeResolveTextAlias,
|
|
shouldHandleTextCommands,
|
|
} from "../commands-registry.js";
|
|
import type { FinalizedMsgContext } from "../templating.js";
|
|
|
|
function resolveFirstContextText(
|
|
ctx: FinalizedMsgContext,
|
|
keys: Array<"BodyForAgent" | "BodyForCommands" | "CommandBody" | "RawBody" | "Body">,
|
|
): string {
|
|
for (const key of keys) {
|
|
const value = ctx[key];
|
|
if (typeof value === "string") {
|
|
return value;
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function resolveCommandCandidateText(ctx: FinalizedMsgContext): string {
|
|
return resolveFirstContextText(ctx, ["CommandBody", "BodyForCommands", "RawBody", "Body"]).trim();
|
|
}
|
|
|
|
function isResetCommandCandidate(text: string): boolean {
|
|
return /^\/(?:new|reset)(?:\s|$)/i.test(text);
|
|
}
|
|
|
|
export function shouldBypassAcpDispatchForCommand(
|
|
ctx: FinalizedMsgContext,
|
|
cfg: OpenClawConfig,
|
|
): boolean {
|
|
const candidate = resolveCommandCandidateText(ctx);
|
|
if (!candidate) {
|
|
return false;
|
|
}
|
|
const normalized = candidate.trim();
|
|
const allowTextCommands = shouldHandleTextCommands({
|
|
cfg,
|
|
surface: ctx.Surface ?? ctx.Provider ?? "",
|
|
commandSource: ctx.CommandSource,
|
|
});
|
|
if (!normalized.startsWith("/") && maybeResolveTextAlias(candidate, cfg) != null) {
|
|
return allowTextCommands;
|
|
}
|
|
|
|
if (isResetCommandCandidate(normalized)) {
|
|
return true;
|
|
}
|
|
|
|
if (!normalized.startsWith("!")) {
|
|
return false;
|
|
}
|
|
|
|
if (!ctx.CommandAuthorized) {
|
|
return false;
|
|
}
|
|
|
|
if (!isCommandEnabled(cfg, "bash")) {
|
|
return false;
|
|
}
|
|
|
|
return allowTextCommands;
|
|
}
|