import{createRequire as i}from"module";import{fileURLToPath as a}from"url";import{registerHandlers as u}from"@zibby/core/function-skill-registry.js";import{registerSkill as c}from"@zibby/agent-workflow";var p=i(import.meta.url);function f(){try{return p.resolve("@zibby/core/function-bridge.js")}catch{return null}}var m=import.meta.url;function h(){let e=Error.prepareStackTrace;try{Error.prepareStackTrace=(l,o)=>o;let t=new Error().stack;for(let l=2;l<t.length;l++){let o=t[l].getFileName();if(o&&o!==m&&!o.startsWith("node:"))return o.startsWith("file://")?a(o):o}return null}finally{Error.prepareStackTrace=e}}function y(e){if(!e||typeof e!="object")return{type:"object",properties:{},required:[]};let r={},t=[];for(let[l,o]of Object.entries(e))if(typeof o=="string")r[l]={type:o},t.push(l);else{let{required:s,...n}=o;r[l]=n,s!==!1&&t.push(l)}return{type:"object",properties:r,required:t}}function v(e,r,t){if(typeof t.handler!="function")throw new Error(`Skill "${e}" must have a handler function`);let l={[e]:t.handler},o=[{name:e,description:t.description||"",input_schema:y(t.input)}];return u(e,l,o),{id:e,type:"function",serverName:e,allowedTools:[`mcp__${e}__*`],description:t.description||`Function skill: ${e}`,envKeys:[],tools:o,resolve(){let s=f();return s?{command:"node",args:[s,r,e]}:null}}}function k(e,r){return{id:e,type:"mcp",serverName:r.serverName||e,allowedTools:r.allowedTools||[`mcp__${r.serverName||e}__*`],description:r.description||`MCP skill: ${e}`,envKeys:r.envKeys||[],tools:r.tools||[],resolve:r.resolve,...r.cursorKey&&{cursorKey:r.cursorKey},...r.sessionEnvKey&&{sessionEnvKey:r.sessionEnvKey}}}function d(e,r){let t;if("handler"in r){if(typeof r.handler!="function")throw new Error(`Skill "${e}" must have a handler function`);let l=h();if(!l)throw new Error(`Could not resolve caller file for skill "${e}".`);t=v(e,l,r)}else if(typeof r.resolve=="function")t=k(e,r);else throw new Error(`Skill "${e}" must have either a handler (function skill) or resolve (MCP skill).`);return c(t),t}var S=d;export{S as functionSkill,d as skill};
