import{existsSync as m}from"fs";import{fileURLToPath as f}from"url";import{dirname as _,resolve as y}from"path";import{resolveIntegrationToken as I}from"@zibby/core/backend-client.js";var g=Object.freeze({SENTRY:"sentry",JIRA:"jira",GITHUB:"github",GITLAB:"gitlab",SLACK:"slack",LARK:"lark",OPENAI_BILLING:"openai_billing",ANTHROPIC_BILLING:"anthropic_billing",CURSOR_ADMIN:"cursor_admin",NOTION:"notion",GOOGLE:"google",PLANE:"plane",LINEAR:"linear",FIGMA:"figma",HUBSPOT:"hubspot",OPEN_DESIGN:"open_design",LINKEDIN_PERSONAL:"linkedin_personal",LINKEDIN_BUSINESS:"linkedin_business",DISCORD:"discord"}),O=Object.freeze({sentry:{id:"sentry",name:"Sentry",connectPath:"/integrations?provider=sentry"},jira:{id:"jira",name:"Jira",connectPath:"/integrations?provider=jira"},github:{id:"github",name:"GitHub",connectPath:"/integrations?provider=github"},gitlab:{id:"gitlab",name:"GitLab",connectPath:"/integrations?provider=gitlab"},slack:{id:"slack",name:"Slack",connectPath:"/integrations?provider=slack"},lark:{id:"lark",name:"Lark",connectPath:"/integrations?provider=lark"},openai_billing:{id:"openai_billing",name:"OpenAI Admin",connectPath:"/integrations?provider=openai_billing"},anthropic_billing:{id:"anthropic_billing",name:"Anthropic Admin",connectPath:"/integrations?provider=anthropic_billing"},cursor_admin:{id:"cursor_admin",name:"Cursor Admin",connectPath:"/integrations?provider=cursor_admin"},notion:{id:"notion",name:"Notion",connectPath:"/integrations?provider=notion"},google:{id:"google",name:"Google Docs",connectPath:"/integrations?provider=google"},plane:{id:"plane",name:"Plane",connectPath:"/integrations?provider=plane"},linear:{id:"linear",name:"Linear",connectPath:"/integrations?provider=linear"},figma:{id:"figma",name:"Figma",connectPath:"/integrations?provider=figma"},hubspot:{id:"hubspot",name:"HubSpot",connectPath:"/integrations?provider=hubspot"},open_design:{id:"open_design",name:"OpenDesign",connectPath:"/integrations?provider=open_design"},linkedin_personal:{id:"linkedin_personal",name:"LinkedIn (Personal)",connectPath:"/integrations?provider=linkedin_personal"},linkedin_business:{id:"linkedin_business",name:"LinkedIn (Business)",connectPath:"/integrations?provider=linkedin_business"},discord:{id:"discord",name:"Discord",connectPath:"/integrations?provider=discord"}});function j(){if(process.env.MCP_SKILL_PATH)return process.env.MCP_SKILL_PATH;let r=_(f(import.meta.url)),t=y(r,"..","bin","mcp-skill.mjs");return m(t)?t:null}async function l(){let r=await I(g.OPEN_DESIGN),t=r?.token,e=r?.baseUrl;if(!t||typeof t!="string")throw new Error("OpenDesign is not connected: missing token. Connect it in Integrations.");if(!e||typeof e!="string")throw new Error("OpenDesign is not connected: missing baseUrl. Connect it in Integrations.");let n=e.replace(/\/+$/,"");return{token:t,baseUrl:n}}async function d(r,t={}){let{token:e,baseUrl:n}=await l(),i=`${n}/api${r}`;if(t.query&&typeof t.query=="object"){let a=new URLSearchParams;for(let[h,p]of Object.entries(t.query))p!=null&&p!==""&&a.set(h,String(p));let c=a.toString();c&&(i+=(i.includes("?")?"&":"?")+c)}let o={Authorization:`Bearer ${e}`,Accept:"application/json",...t.body?{"Content-Type":"application/json"}:{}},s=await fetch(i,{method:t.method||"GET",headers:o,body:t.body?JSON.stringify(t.body):void 0});return u(s,"OpenDesign")}async function u(r,t){if(!r.ok){let n=await r.text().catch(()=>""),i=n.slice(0,300);try{let o=JSON.parse(n),s=o?.code||o?.error?.code,a=o?.message||o?.error?.message||o?.error;(s||a)&&(i=[s?`[${s}]`:null,a].filter(Boolean).join(" ")||i)}catch{}throw new Error(`${t} API ${r.status}: ${i}`)}let e=await r.text().catch(()=>"");if(!e)return{};try{return JSON.parse(e)}catch{return{raw:e}}}var T={id:"open-design",serverName:"opendesign",allowedTools:["mcp__opendesign__*"],envKeys:[],description:"OpenDesign \u2014 list projects/designs, run the design agent, and export decks to PDF/HTML",promptFragment:`## OpenDesign (optional)
You may have access to the user's OpenDesign workspace (the Zibby-managed design/deck app) via its REST API. These tools are OPTIONAL \u2014 if OpenDesign is not connected they will return a "not connected" error; reach for them only when the task involves OpenDesign projects, designs, or exports. Tools (mcp__opendesign__*):

### Connectivity
- opendesign_health: Probe the OpenDesign instance (GET /api/health, no auth). Use to confirm the instance is reachable before other calls.

### Projects & designs
- opendesign_list_projects: List the projects in the workspace.
- opendesign_get_project: Get one project by id.
- opendesign_list_designs: List the live design artifacts in a project (pass projectId).
- opendesign_get_design: Get one live design artifact by id (pass projectId).

### Authoring agent
- opendesign_cli_run: Start an OpenDesign agent run (agentId + message; optional projectId / conversationId / model). Returns a runId.
- opendesign_cli_status: Poll a run's status by runId.

### Export
- opendesign_export_pdf: Export a project's deck to PDF (projectId + fileName; optional title / deck).
- opendesign_export_html: Fetch a project's HTML export by path (projectId + path; inline=1).

### Notes
- A design artifact lookup ALWAYS needs its projectId (it scopes the query).
- After opendesign_cli_run, poll opendesign_cli_status with the returned runId until the run is no longer running.`,resolve(){let r=j();if(!r)return{command:null,args:[],env:{},description:this.description};let t={};for(let e of this.envKeys)process.env[e]&&(t[e]=process.env[e]);return{type:"stdio",command:"node",args:[r,"../dist/opendesign.js","opendesignSkill"],env:t,description:this.description,alwaysLoad:!0}},async handleToolCall(r,t){try{switch(r){case"opendesign_health":{let{baseUrl:e}=await l(),n=await fetch(`${e}/api/health`,{method:"GET",headers:{Accept:"application/json"}}),i=await u(n,"OpenDesign");return JSON.stringify({ok:!0,health:i})}case"opendesign_list_projects":{let e=await d("/projects");return JSON.stringify(e)}case"opendesign_get_project":{let e=t?.id||t?.projectId;if(!e)return JSON.stringify({error:"id is required"});let n=await d(`/projects/${encodeURIComponent(e)}`);return JSON.stringify(n)}case"opendesign_list_designs":{let e=t?.projectId;if(!e)return JSON.stringify({error:"projectId is required"});let n=await d("/live-artifacts",{query:{projectId:e}});return JSON.stringify(n)}case"opendesign_get_design":{let e=t?.id,n=t?.projectId;if(!e)return JSON.stringify({error:"id is required"});if(!n)return JSON.stringify({error:"projectId is required"});let i=await d(`/live-artifacts/${encodeURIComponent(e)}`,{query:{projectId:n}});return JSON.stringify(i)}case"opendesign_export_pdf":{let e=t?.projectId||t?.id,{fileName:n,title:i,deck:o}=t||{};if(!e)return JSON.stringify({error:"projectId is required"});if(!n)return JSON.stringify({error:"fileName is required"});let s={fileName:n};i!==void 0&&(s.title=i),o!==void 0&&(s.deck=o);let a=await d(`/projects/${encodeURIComponent(e)}/export/pdf`,{method:"POST",body:s});return JSON.stringify(a)}case"opendesign_export_html":{let e=t?.projectId||t?.id,n=t?.path;if(!e)return JSON.stringify({error:"projectId is required"});if(!n)return JSON.stringify({error:"path is required (the export sub-path)"});let o=String(n).replace(/^\/+/,"").split("/").map(a=>encodeURIComponent(a)).join("/"),s=await d(`/projects/${encodeURIComponent(e)}/export/${o}`,{query:{inline:1}});return JSON.stringify(s)}case"opendesign_cli_run":{let{agentId:e,message:n,projectId:i,conversationId:o,model:s}=t||{};if(!e)return JSON.stringify({error:"agentId is required"});if(!n)return JSON.stringify({error:"message is required"});let a={agentId:e,message:n};i!==void 0&&(a.projectId=i),o!==void 0&&(a.conversationId=o),s!==void 0&&(a.model=s);let c=await d("/runs",{method:"POST",body:a});return JSON.stringify(c)}case"opendesign_cli_status":{let e=t?.id||t?.runId;if(!e)return JSON.stringify({error:"id (runId) is required"});let n=await d(`/runs/${encodeURIComponent(e)}`);return JSON.stringify(n)}default:return JSON.stringify({error:`Unknown tool: ${r}`})}}catch(e){return JSON.stringify({error:e.message})}},tools:[{name:"opendesign_health",description:"Probe the OpenDesign instance (GET /api/health, no auth). Use to confirm connectivity before other calls.",input_schema:{type:"object",properties:{}}},{name:"opendesign_list_projects",description:"List the projects in the OpenDesign workspace.",input_schema:{type:"object",properties:{}}},{name:"opendesign_get_project",description:"Get a single OpenDesign project by id.",input_schema:{type:"object",properties:{id:{type:"string",description:"The project id."}},required:["id"]}},{name:"opendesign_list_designs",description:"List the live design artifacts in an OpenDesign project. Requires the projectId, which scopes the query.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"The project id whose designs to list."}},required:["projectId"]}},{name:"opendesign_get_design",description:"Get a single live design artifact by id. Requires both the design id and its projectId.",input_schema:{type:"object",properties:{id:{type:"string",description:"The live-artifact (design) id."},projectId:{type:"string",description:"The project id the design belongs to (scopes the lookup)."}},required:["id","projectId"]}},{name:"opendesign_export_pdf",description:"Export an OpenDesign project deck to PDF. Returns the export result (e.g. a download URL/path).",input_schema:{type:"object",properties:{projectId:{type:"string",description:"The project id to export."},fileName:{type:"string",description:"The output PDF file name."},title:{type:"string",description:"Optional deck title for the PDF."},deck:{description:"Optional deck payload/override to render instead of the project's current deck."}},required:["projectId","fileName"]}},{name:"opendesign_export_html",description:"Fetch an OpenDesign project's HTML export by sub-path (requested inline). Requires projectId and the export path.",input_schema:{type:"object",properties:{projectId:{type:"string",description:"The project id to export."},path:{type:"string",description:'The export sub-path under /projects/:id/export/ (e.g. "index.html" or a slide path).'}},required:["projectId","path"]}},{name:"opendesign_cli_run",description:"Start an OpenDesign agent run. Returns a runId; poll opendesign_cli_status with it until the run finishes.",input_schema:{type:"object",properties:{agentId:{type:"string",description:"The OpenDesign agent id to run."},message:{type:"string",description:"The instruction/message to send to the agent."},projectId:{type:"string",description:"Optional project id to scope the run to."},conversationId:{type:"string",description:"Optional conversation id to continue an existing thread."},model:{type:"string",description:"Optional model id override for the run."}},required:["agentId","message"]}},{name:"opendesign_cli_status",description:"Poll the status of an OpenDesign agent run by its runId.",input_schema:{type:"object",properties:{id:{type:"string",description:"The runId returned by opendesign_cli_run."}},required:["id"]}}]};export{T as opendesignSkill};
