UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

88 lines (87 loc) • 4.28 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { r as normalizeAgentIdStrict } from "./agent-id-CQjtp2ft.mjs"; import { c as normalizeOptionalAgentId } from "./session-key-CqAyZeVk.mjs"; import { c as resolveConfiguredAcpHarnessIds, l as resolveConfiguredAcpSubagentTargetIds } from "./agent-roster-t1ooUdXp.mjs"; import { o as resolveAgentEntry } from "./agent-scope-config-DmXgFGKP.mjs"; import { g as resolveRequesterSpawnTargetPolicy, h as describeTargetIdList } from "./subagent-capabilities-D82nSYzB.mjs"; import { r as resolveAcpAgentPolicyError, t as hasAcpAgentAllowlist } from "./policy-De5rDLTI.mjs"; import { t as getAcpRuntimeBackend } from "./registry-C2WH06NS.mjs"; import { t as resolveAcpSenderSpawnError } from "./acp-spawn-policy-BQ2YsISr.mjs"; //#region src/agents/subagents/spawn/acp-spawn-target.ts function resolveAcpAgentTarget(e) { const t = normalizeOptionalString(e.agentBackend) ?? normalizeOptionalString(e.cfg.acp?.backend) ?? getAcpRuntimeBackend()?.id; return { ok: true, agentId: e.agentId, ...e.configAgentId ? { configAgentId: e.configAgentId } : {}, ...t ? { backendId: t } : {} }; } function resolveTargetAcpAgentId(e) { const t = e.requestedAgentId === void 0 ? null : normalizeAgentIdStrict(e.requestedAgentId); if (t && !t.ok) return { ok: false, error: `agentId "${e.requestedAgentId}" was not found` }; const n = t?.value ?? normalizeOptionalAgentId(e.cfg.acp?.defaultAgent); if (n) { const t = resolveAgentEntry(e.cfg, n); if (t?.runtime?.type === "acp") return resolveAcpAgentTarget({ cfg: e.cfg, agentId: normalizeOptionalAgentId(t.runtime.acp?.agent) ?? n, configAgentId: n, agentBackend: t.runtime.acp?.backend }); if (t && !isExplicitlyAllowedAcpAgent(e.cfg, n)) return { ok: false, error: `agentId "${n}" is an OpenClaw config agent, not an ACP harness. Use runtime="subagent" or omit runtime for OpenClaw config agents. Use runtime="acp" only with external ACP harness ids such as codex, claude, droid, gemini, or opencode, or configure agents.entries.*.runtime.type="acp" with runtime.acp.agent.` }; return resolveAcpAgentTarget({ cfg: e.cfg, agentId: n, ...t ? { configAgentId: n } : {} }); } return { ok: false, error: "ACP target agent is not configured. Pass `agentId` in `sessions_spawn` or set `acp.defaultAgent` in config." }; } function isExplicitlyAllowedAcpAgent(e, t) { return (e.acp?.allowedAgents ?? []).some((e) => e.trim() === "*" || normalizeOptionalAgentId(e) === t); } /** * Describe the sessions_spawn `agentId` parameter for `runtime="acp"`. * Pass `subagentRequesterId` when the requester is a subagent or sender-restricted: * ACP spawns then also go through its requireAgentId and allowAgents policy. Pass * `sender` to apply the inherited sender restrictions ACP admission enforces. */ function describeAcpSpawnTargetParameter(e, t, n) { const r = n?.inheritedToolPolicySource === "sender"; const isAccepted = (r) => { const i = resolveTargetAcpAgentId({ requestedAgentId: r, cfg: e }); if (!i.ok) return false; const a = r ? [r, i.agentId] : [i.agentId]; return (!n || a.every((e) => !resolveAcpSenderSpawnError({ ...n, targetAgentId: e }))) && resolveAcpAgentPolicyError(e, i.agentId) === null && (t === void 0 || resolveRequesterSpawnTargetPolicy({ cfg: e, requesterAgentId: t, targetAgentId: i.agentId, requestedAgentId: r, configuredAgentIds: Array.from(resolveConfiguredAcpSubagentTargetIds(e)) }).ok); }; const i = normalizeOptionalAgentId(e.acp?.defaultAgent); const a = i && isAccepted() ? `Omit to use the configured ACP default ("${i}").` : "agentId is required."; const o = Array.from(resolveConfiguredAcpHarnessIds(e)).filter((e) => isAccepted(e)).toSorted((e, t) => e.localeCompare(t)); if (hasAcpAgentAllowlist(e) || t !== void 0 || r) return o.length > 0 ? `${describeTargetIdList("ACP harness id from", o)} ${a}` : `No ACP harness id is allowed. ${a}`; const s = o.length > 0 ? o : ["codex", "claude"].filter(isAccepted); return s.length > 0 ? `${describeTargetIdList("ACP harness id, for example", s)} ${a}` : `ACP harness id. ${a}`; } //#endregion export { resolveTargetAcpAgentId as n, describeAcpSpawnTargetParameter as t };