UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 3.12 kB
import{i as getAgentWorkspaceAccess,t as WorkspaceAccessUnavailableError}from"./workspace-access-GnBgOJqh.mjs";import{r as resolveSkillFileHost}from"./skill-file-host-D4Dltnrr.mjs";import{n as resolveSkillReadPath}from"./workspace-skill-read-path-h3bWxMAN.mjs";import{o as isSkillSecretOwnerUnavailable,t as hasUnavailableSkillSecretOwners}from"./config-DyCaRdSv.mjs";import{l as prepareSkillResourceRoot}from"./refresh-DvybH61w.mjs";import{a as resolveCodeModeSkills,t as MAX_SKILL_INSTRUCTION_BYTES}from"./installed-skill-catalog-CLHKO6B7.mjs";import{t as resolveSessionSkillResourceCatalog}from"./session-placement-skill-resources-k9OXFg2C.mjs";import path from"node:path"; //!src/agents/installed-skill-runtime.ts 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=resolveSkillFileHost(a);const c=i.get(a.name);const l=c?.filePath===a.filePath?c.readContent:void 0;const assertCurrent=()=>{e.assertCurrent?.();r?.assertCurrent()};let reader;let d;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);d=readInstructions}else if(u?.loadSkills&&(s===`workspace`||s!==`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};const f=!n?.enabled&&!reader&&s!==`workspace`&&(s===`gateway`||!u?.loadSkills)&&path.isAbsolute(a.filePath)?prepareSkillResourceRoot(path.dirname(a.filePath),a.resourceRootIdentity):void 0;f?.catch(()=>void 0);const p=n?.enabled&&typeof l===`string`?c?.contentHash:a.contentHash;return{instructionDelivery:e.instructionDelivery,catalogRevision:p,name:a.name,promptListed:o.has(a.name),description:[a.description,a.locationNote].filter(Boolean).join(` `),location:resolveSkillReadPath(a),locationNote:a.locationNote,source:{filePath:a.filePath,readContent:n?.enabled?l:a.readContent},reader,resourceRoot:f,assertCurrent,readSearchContent:d}})}export{prepareInstalledSkillCatalog as t};