UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

91 lines (90 loc) • 3.35 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { c as normalizeToolPolicyName } from "./tool-policy-shared-BHvBopvF.mjs"; import { n as matchesAnyGlobPattern, t as compileGlobPatterns } from "./glob-pattern-BfbeUKrV.mjs"; //#region src/commands/doctor/shared/legacy-tool-policy-scopes.ts /** * Core-owned config roots only. plugins.entries.*.config is opaque plugin-owned * data; repairing tool policies there belongs to the owning plugin's doctor * contract (legacyConfigRules), never to a core migration. */ const TOOL_POLICY_ROOTS = [ "tools", "agents", "channels", "gateway" ]; /** True when a config path addresses a tool policy scope holding allow/alsoAllow/deny lists. */ function isToolPolicyPath(e) { if (e.at(-1) === "tools" || e.includes("toolsBySender")) return true; const t = e.lastIndexOf("byProvider"); return t >= 0 && e.slice(0, t).includes("tools"); } //#endregion //#region src/commands/doctor/shared/legacy-tool-name-migration.ts const TASK_SUGGESTION_TOOL_NAME_MIGRATION = { legacyName: "spawn_task", canonicalName: "suggest_task" }; const IMAGE_INSPECTION_TOOL_NAME_MIGRATION = { legacyName: "image", canonicalName: "view_image" }; function inspectLegacyToolNameList(e, t) { if (!Array.isArray(e)) return null; const n = e.filter((e) => typeof e === "string"); const r = normalizeToolPolicyName(t.legacyName); const i = compileGlobPatterns({ raw: n, normalize: normalizeToolPolicyName }); const a = n.some((e) => normalizeToolPolicyName(e) === r); return { exactLegacy: a, appendCanonical: !a && matchesAnyGlobPattern(r, i) && !matchesAnyGlobPattern(normalizeToolPolicyName(t.canonicalName), i) }; } function hasLegacyToolNameList(e, t) { const n = inspectLegacyToolNameList(e, t); return n?.exactLegacy === true || n?.appendCanonical === true; } function migrateLegacyToolNameList(e, t) { const n = inspectLegacyToolNameList(e, t); if (!n || !Array.isArray(e)) return false; if (n.exactLegacy) { const n = normalizeToolPolicyName(t.legacyName); for (const [r, i] of e.entries()) if (typeof i === "string" && normalizeToolPolicyName(i) === n) e[r] = t.canonicalName; } if (n.appendCanonical) e.push(t.canonicalName); return n.exactLegacy || n.appendCanonical; } function visitLegacyToolName(e, t, n, r, i) { if (Array.isArray(e)) { for (const [a, o] of e.entries()) visitLegacyToolName(o, [...t, String(a)], n, r, i); return; } if (!isRecord(e)) return; const a = isToolPolicyPath(t) ? [ "allow", "alsoAllow", "deny" ] : []; if (Object.hasOwn(e, "toolsAllow")) a.push("toolsAllow"); for (const o of a) { const a = e[o]; if (!(r ? migrateLegacyToolNameList(a, n) : hasLegacyToolNameList(a, n))) continue; i.push([...t, o].join(".")); } for (const [a, o] of Object.entries(e)) visitLegacyToolName(o, [...t, a], n, r, i); } function findLegacyToolNamePaths(e, t, n = []) { const r = []; visitLegacyToolName(e, n, t, false, r); return r; } function migrateLegacyToolNamePolicies(e, t, n = []) { const r = []; visitLegacyToolName(e, n, t, true, r); return r; } //#endregion export { migrateLegacyToolNameList as a, isToolPolicyPath as c, hasLegacyToolNameList as i, TASK_SUGGESTION_TOOL_NAME_MIGRATION as n, migrateLegacyToolNamePolicies as o, findLegacyToolNamePaths as r, TOOL_POLICY_ROOTS as s, IMAGE_INSPECTION_TOOL_NAME_MIGRATION as t };