openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.53 kB
JavaScript
import{c as readFileDescriptorBoundedSync,o as openRootFileSync}from"./boundary-file-read-bB9An35K.mjs";import{t as SkillLibraryError}from"./skill-library-error-CRoBQyXe.mjs";import{n as serializeNativeErrorResponse}from"./native-error-response-vI2qu5y2.mjs";import{r as SKILL_LIBRARY_MAX_FILE_BYTES}from"./skill-library-QNfZhm1-.mjs";import{i as resolveSkillManifestMetadata,n as resolveSkillInvocationPolicy,t as parseSkillFrontmatter}from"./frontmatter-CvGHA96F.mjs";import{t as materializeSkill}from"./skill-materializer-Csds0NPO.mjs";import{c as readSkillLibraryManifestTreeOnWorker,u as skillLibraryRevisionDir}from"./bundle-CzmF1asv.mjs";import fs from"node:fs";import path from"node:path";
//!src/skills/library/filesystem.kernel.ts
function materializeSkillLibrarySelection(e,t,n){return e.map((e,r)=>{const i=t[r];if(!i)throw new SkillLibraryError(`NOT_FOUND`,`A pinned skill revision is unavailable; restore the library artifact or detach it explicitly.`);const a=skillLibraryRevisionDir(e.skillId,e.revision,n);const o=path.join(a,`SKILL.md`);const s=openRootFileSync({absolutePath:o,rootPath:a,boundaryLabel:`skill library revision`,maxBytes:SKILL_LIBRARY_MAX_FILE_BYTES,rejectHardlinks:true,symlinks:`reject`});if(!s.ok)throw new SkillLibraryError(`INVALID_BUNDLE`,`Pinned skill instructions could not be read; restore the library artifact or detach it explicitly.`,void 0,{cause:s.error});let c;try{c=readFileDescriptorBoundedSync(s.fd,SKILL_LIBRARY_MAX_FILE_BYTES).toString(`utf8`)}finally{fs.closeSync(s.fd)}const l=parseSkillFrontmatter(c);const u=resolveSkillManifestMetadata(l);const d=resolveSkillInvocationPolicy(l);const f=e.name;return{skill:materializeSkill({content:c,frontmatter:l,name:f,description:i.description,baseDir:a,filePath:o,source:`openclaw-library`,sourceOptions:{source:`openclaw-library`}}),frontmatter:l,invocation:d,metadata:{skillKey:f,os:u?.os,requires:u?.requires},disableCommandDispatch:true,syncSourceDir:a,syncDirName:`library-${e.skillId}-${e.revision}`}})}async function executeSkillLibraryFilesystemTask(e){try{if(e.kind===`selection`)return{kind:`selection`,entries:materializeSkillLibrarySelection(e.selections,e.revisions,{OPENCLAW_STATE_DIR:e.stateDir})};return{kind:`manifest`,files:await readSkillLibraryManifestTreeOnWorker(e.directory,e.manifestJson,e.revision)}}catch(e){return{kind:`error`,error:serializeNativeErrorResponse(e),libraryCode:e instanceof SkillLibraryError?e.code:void 0}}}export{materializeSkillLibrarySelection as n,executeSkillLibraryFilesystemTask as t};