UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

72 lines (71 loc) • 3.23 kB
import { r as resolveSkillFileHost } from "./skill-file-host-DYVvMKod.mjs"; import { n as resolveSkillReadPath } from "./workspace-skill-read-path-nJAkXHnD.mjs"; import { o as isSkillSecretOwnerUnavailable, t as hasUnavailableSkillSecretOwners } from "./config-C4hfYsYF.mjs"; import { i as getAgentWorkspaceAccess, t as WorkspaceAccessUnavailableError } from "./workspace-access-CnjZBg1i.mjs"; import { i as resolveCodeModeSkills, t as MAX_SKILL_INSTRUCTION_BYTES } from "./installed-skill-catalog-CG4V1K2u.mjs"; import { t as resolveSessionSkillResourceCatalog } from "./session-placement-skill-resources-Bo5z7XGN.mjs"; //#region src/agents/installed-skill-runtime.ts /** Bind already-admitted identities to the filesystem owner for this attempt. */ function prepareInstalledSkillCatalog(e) { const { snapshot: t, sandbox: n } = e; if (!t) return []; const r = n?.enabled ? resolveSessionSkillResourceCatalog(n.readOnlyResourceMounts) : void 0; const i = new Map(r?.snapshot.discoverySkills?.map((e) => [e.name, e])); const a = t.discoverySkills ?? t.resolvedSkills ?? []; const o = new Set(resolveCodeModeSkills({ skillsPrompt: t.prompt, candidates: a }).map((e) => e.name)); const s = t.discoverySkills ? void 0 : o; const c = new Map(t.skills.map((e) => [e.name, e.skillKey])); const l = hasUnavailableSkillSecretOwners(); const u = !n?.enabled ? getAgentWorkspaceAccess(e.workspaceDir, "loadSkills") : void 0; return a.filter((e) => !e.disableModelInvocation && (!s || s.has(e.name)) && (!l || c.get(e.name) !== void 0) && !isSkillSecretOwnerUnavailable(c.get(e.name) ?? e.name)).map((a) => { const s = i.get(a.name); const c = s?.filePath === a.filePath ? s.readContent : void 0; const assertCurrent = () => { e.assertCurrent?.(); r?.assertCurrent(); }; let reader; let l; if (n?.enabled) { const readInstructions = async (t, r) => { e.assertCurrent?.(); if (!n.fsBridge) throw new Error("Sandbox filesystem bridge is unavailable for skill reads."); const i = await n.fsBridge.readFile({ filePath: a.filePath, cwd: n.containerWorkdir, signal: r, maxBytes: t }); e.assertCurrent?.(); return i.toString("utf8"); }; reader = ({ signal: e }) => readInstructions(o.has(a.name) ? void 0 : MAX_SKILL_INSTRUCTION_BYTES, e); l = readInstructions; } else if (u?.loadSkills && (resolveSkillFileHost(a) === "workspace" || resolveSkillFileHost(a) !== "gateway" && !t.librarySelections?.some((e) => e.name === a.name))) reader = async ({ signal: t }) => { e.assertCurrent?.(); if (!u.skillResources) throw new WorkspaceAccessUnavailableError("Remote workspace skill reads are unavailable"); const n = await u.skillResources.readInstructions(a.filePath, { signal: t }); e.assertCurrent?.(); return n; }; return { name: a.name, promptListed: o.has(a.name), description: [a.description, a.locationNote].filter(Boolean).join("\n"), location: resolveSkillReadPath(a), locationNote: a.locationNote, source: { filePath: a.filePath, readContent: n?.enabled ? c : a.readContent }, reader, assertCurrent, readSearchContent: l }; }); } //#endregion export { prepareInstalledSkillCatalog as t };