openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
51 lines (50 loc) • 2.63 kB
JavaScript
import { r as resolveAgentConfig } from "./agent-scope-config-DmXgFGKP.mjs";
import { o as resolveAgentRoute } from "./resolve-route-DBnTWpM6.mjs";
import "./routing-DmgGYTrU.mjs";
import "./agent-scope-runtime-CDpr-vor.mjs";
import { n as resolveXGuestSettings } from "./guest-policy-BBy19wHq.mjs";
import { r as openXGuestUsage } from "./guest-usage-B1U2k5CF.mjs";
//#region extensions/x/src/guests.ts
function resolveXGuestContainmentError(e, t) {
const n = resolveAgentConfig(e, t);
if ((n?.tools?.fs?.workspaceOnly ?? e.tools?.fs?.workspaceOnly) !== true) return `X guest mode requires agents.entries.${t}.tools.fs.workspaceOnly=true (or tools.fs.workspaceOnly=true) and the OpenClaw clone as the agent working directory.`;
const r = n?.skills ?? e.agents?.defaults?.skills;
if (!r || r.length !== 0) return `X guest mode requires agents.entries.${t}.skills=[] so read cannot access external skill directories.`;
const i = n?.sandbox;
const a = e.agents?.defaults?.sandbox;
if ((i?.mode ?? a?.mode ?? "off") !== "off") return `X guest mode requires agents.entries.${t}.sandbox.mode="off" and workspace-only file tools; sandbox mounts can expose files outside the repository.`;
const o = e.messages?.queue?.byChannel?.x ?? e.messages?.queue?.mode ?? "steer";
if (o !== "followup" && o !== "collect") return "X guest mode requires messages.queue.byChannel.x=\"followup\" or \"collect\" (or messages.queue.mode with either value) so guests cannot steer or interrupt an active turn.";
}
function resolveXGuestReadinessError(e, t, n) {
const r = /* @__PURE__ */ new Set(["__x_guest_default__", ...(e.bindings ?? []).flatMap((e) => e.match.channel === "x" && e.match.peer?.kind === "group" ? [e.match.peer.id] : [])]);
let i;
try {
i = n ? [n] : [...r].map((n) => resolveAgentRoute({
cfg: e,
channel: "x",
accountId: t,
peer: {
kind: "group",
id: n
}
}).agentId);
} catch {
return "X guest mode requires valid X agent bindings. Add a channel-wide X binding and correct any missing target agents.";
}
const a = [...new Set(i)].flatMap((t) => resolveXGuestContainmentError(e, t) ?? []);
return a.length ? a.join(" ") : void 0;
}
async function getXGuestStatus(e, t, n, r) {
const { enabled: i, maxMentionsPerAuthorPerDay: a } = resolveXGuestSettings(t);
const o = i ? resolveXGuestReadinessError(n, t.accountId, r) : void 0;
return {
enabled: i,
helpersAvailable: true,
maxMentionsPerAuthorPerDay: a,
...o ? { blockedReason: o } : {},
...await openXGuestUsage(e).counts(t.accountId)
};
}
//#endregion
export { resolveXGuestContainmentError as n, getXGuestStatus as t };