openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 4.23 kB
JavaScript
import{t as asNonArrayRecord}from"./record-coerce-BTbqdJ3-.mjs";import{n as jsonResult}from"./tool-results-BkLNMSCi.mjs";import{o as getAgentToolAvailabilityBinding,t as bindAgentToolAvailability}from"./agent-tool-availability-DAMoDFPF.mjs";import{d as readToolStringParam,o as readNumberParam}from"./common-DIgvX97L.mjs";import{i as rememberSkillInstructionDelivery,n as formatSkillInstructions}from"./skill-instruction-result-mm50jgMT.mjs";import{i as resolveToolResultBudget,s as toolResultFitsBudget}from"./tool-result-limits-lcVBcKWC.mjs";import{n as readInstalledSkill,r as searchInstalledSkills}from"./installed-skill-catalog-CLHKO6B7.mjs";import{Type}from"typebox";
//!src/agents/tools/installed-skill-tools.ts
const SkillsSearchSchema=Type.Object({query:Type.String({minLength:1,maxLength:1e3}),limit:Type.Optional(Type.Integer({minimum:1,maximum:20}))});const SkillsReadSchema=Type.Object({name:Type.String({minLength:1}),relativePath:Type.Optional(Type.String({minLength:1}))});const DISPATCH_ENVELOPE_RESERVE_CHARS=512;function fitsModelOutput(e,t){return toolResultFitsBudget(JSON.stringify(e),{maxChars:t.maxChars-DISPATCH_ENVELOPE_RESERVE_CHARS,maxContextChars:t.maxContextChars-DISPATCH_ENVELOPE_RESERVE_CHARS*2})}function formatSkillInstructionsForModel(e,t,n){const r=formatSkillInstructions(e);if(!t||e.relativePath!==void 0||fitsModelOutput(r,t))return{text:r,whole:true};const i=e.content.split(`
`);const a=formatSkillInstructions({...e,content:``});const render=t=>{const r=n?`[Skill instructions incomplete: showing lines 1-${t} of ${i.length}. Before acting, read the rest with read(${JSON.stringify({path:e.location,offset:t+1})}) and follow each continuation until the end.]`:`[Skill instructions incomplete: showing lines 1-${t} of ${i.length}. Before acting, read the rest of ${e.location} from line ${t+1} with an available file tool. If none can read it, tell the user that this skill is too large to load and should move detail into references/ files.]`;return`${a}${i.slice(0,t).join(`
`)}\n\n${r}`};let o=0;let s=i.length-1;while(o<s){const e=Math.ceil((o+s)/2);if(fitsModelOutput(render(e),t))o=e;else s=e-1}return{text:render(o),whole:false}}function createInstalledSkillTools(e,t){if(e.length===0)return[];const n=resolveToolResultBudget(t?.modelContextWindowTokens);let r=false;const i={prepare(e,t){r=t.has(`read`)}};let a;return[bindAgentToolAvailability({name:`skills_search`,label:`Search Installed Skills`,description:`Find relevant installed, eligible skills by task or exact name, including skills omitted from the prompt directory. Searches names and descriptions, plus bounded instruction text when skill reads are allowed. Returns metadata only; coverage reports any incomplete body indexing. Read the selected skill's whole instructions before applying it. Does not search ClawHub or install anything.`,parameters:SkillsSearchSchema,execute:async(t,n,r)=>{r?.throwIfAborted();const i=asNonArrayRecord(n);const o=a;return jsonResult(await searchInstalledSkills(e,readToolStringParam(i,`query`,{required:true}),readNumberParam(i,`limit`),r,()=>o!==void 0&&a===o))}},{prepare(e,t){const n=t.get(`skills_read`);if(n&&getAgentToolAvailabilityBinding(n)===i)a??={};else a=void 0}}),bindAgentToolAvailability({name:`skills_read`,label:`Read Installed Skill`,description:`Load complete SKILL.md instructions for an exact installed skill name; search is not required first. Optional relativePath reads a UTF-8 text companion (up to 256 KiB) inside a local skill directory. Restricted placements are instruction-only. Does not execute files or grant command permissions.`,parameters:SkillsReadSchema,execute:async(t,i,a)=>{const o=asNonArrayRecord(i);const s=readToolStringParam(o,`name`,{required:true});const c=readToolStringParam(o,`relativePath`,{required:o.relativePath!==void 0||o.relative_path!==void 0,trim:false});const l=await readInstalledSkill(e,s,a,c);const{text:u,whole:d}=formatSkillInstructionsForModel(l,n,r);const f={content:[{type:`text`,text:u}],details:l};if(c===void 0&&d&&e.find(e=>e.name===s)?.instructionDelivery!==`forwarded`)rememberSkillInstructionDelivery(f,l.content);return f}},i)]}export{formatSkillInstructionsForModel as n,createInstalledSkillTools as t};