openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
52 lines (51 loc) • 3.17 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-1VuiLaaR.mjs";
import { t as formatCliCommand } from "./command-format-DwEdrDKL.mjs";
import { g as replyRunRegistry } from "./reply-run-registry.registry-ICalZVvY.mjs";
import "./reply-run-registry-1HN3_KMU.mjs";
import { i as resolveActiveEmbeddedRunSessionId } from "./active-run-projections-TAxZeJ_S.mjs";
import { a as isNativeCommandTurn, c as resolveCommandTurnContext, r as isAuthorizedTextSlashCommandTurn } from "./command-turn-context-TJGbDzsZ.mjs";
import { t as resolveCommandSourceSessionKey } from "./command-source-session-key-Ck-_YCeI.mjs";
//#region src/auto-reply/reply/explicit-steer-routing.ts
function parseSteerMessage(raw) {
const match = raw.trim().match(/^\/(?:steer|tell)(?:\s+([\s\S]*))?$/i);
return match ? (match[1] ?? "").trim() : null;
}
function listSteerCandidateSessionKeys(targetSessionKey) {
return targetSessionKey.includes(":slash:") ? [
targetSessionKey,
targetSessionKey.replace(":slash:", ":direct:"),
targetSessionKey.replace(":slash:", ":dm:")
] : [targetSessionKey];
}
/**
* Resolve an authorized explicit steer command to the exact session that owns
* an injectable active reply. This is intentionally read-only: callers decide
* whether to retarget session preparation or continue as an ordinary prompt.
*/
function resolveActiveExplicitSteerSessionKey(params) {
const commandTurn = resolveCommandTurnContext(params.ctx);
if (!isNativeCommandTurn(commandTurn) && !isAuthorizedTextSlashCommandTurn(commandTurn)) return;
if (!parseSteerMessage(params.commandBody ?? commandTurn.body ?? normalizeOptionalString(params.ctx.CommandBody) ?? normalizeOptionalString(params.ctx.BodyForCommands) ?? normalizeOptionalString(params.ctx.Body) ?? "")) return;
const sourceSessionKey = resolveCommandSourceSessionKey({
...params,
sessionKey: params.sessionKey ?? params.ctx.SessionKey
});
if (!sourceSessionKey) return;
for (const candidateKey of listSteerCandidateSessionKeys(sourceSessionKey)) if (replyRunRegistry.get(candidateKey) ? replyRunRegistry.resolveCurrentMessageInjectionTarget(candidateKey) !== void 0 : resolveActiveEmbeddedRunSessionId(candidateKey) !== void 0) return candidateKey;
}
//#endregion
//#region src/auto-reply/reply/elevated-unavailable.ts
function formatElevatedUnavailableMessage(params) {
return [
`elevated is not available right now (runtime=${params.runtimeSandboxed ? "sandboxed" : "direct"}).`,
params.failures.length > 0 ? `Failing gates: ${params.failures.map((f) => `${f.gate} (${f.key})`).join(", ")}` : "Failing gates: enabled (tools.elevated.enabled / agents.entries.*.tools.elevated.enabled), allowFrom (tools.elevated.allowFrom.<provider>).",
"Fix-it keys:",
"- tools.elevated.enabled",
"- tools.elevated.allowFrom.<provider>",
"- agents.entries.*.tools.elevated.enabled",
"- agents.entries.*.tools.elevated.allowFrom.<provider>",
...params.sessionKey ? [`See: ${formatCliCommand(`openclaw sandbox explain --session ${params.sessionKey}`)}`] : []
].join("\n");
}
//#endregion
export { parseSteerMessage as n, resolveActiveExplicitSteerSessionKey as r, formatElevatedUnavailableMessage as t };