dopx
Version:
Add beautiful components to your apps 🐳
37 lines (35 loc) • 4.44 kB
JavaScript
import { R, X, H } from './chunk-CAUXGYZZ.js';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
var u=new Server({name:"dopx",version:"0.0.1"},{capabilities:{resources:{},tools:{}}});u.setRequestHandler(ListToolsRequestSchema,async()=>({tools:[{name:"init",description:"Initialize a new project using a registry style project structure.",inputSchema:zodToJsonSchema(z.object({}))},{name:"get_items",description:"List all the available items in the registry",inputSchema:zodToJsonSchema(z.object({}))},{name:"get_item",description:"Get an item from the registry",inputSchema:zodToJsonSchema(z.object({name:z.string().describe("The name of the item to get from the registry. This is required.")}))},{name:"add_item",description:"Add an item from the registry",inputSchema:zodToJsonSchema(z.object({name:z.string().describe("The name of the item to add to the registry. This is required.")}))}]}));u.setRequestHandler(CallToolRequestSchema,async n=>{try{if(!n.params.arguments)throw new Error("Arguments are required");let e=process.env.REGISTRY_URL;if(!e)throw new Error("REGISTRY_URL is not set");switch(n.params.name){case"init":{let t=await h(e),r=t.items.find(a=>a.type==="registry:style"),s="To initialize a new project, run the following command:\n ```bash\n npx dopx init\n ```\n - This will install all the dependencies and theme for the project.\n - If running the init command installs a rules i.e registry.mdc file, you should follow the instructions in the file to configure the project.\n ",c=t.items.find(a=>a.type==="registry:file"&&a.name==="rules");return c&&(s+=`
You should also install the rules for the project.
\`\`\`bash
npx dopx add ${o(c.name,e)}
\`\`\`
`),r?{content:[{type:"text",text:`To initialize a new project using the ${r.name} style, run the following command:
\`\`\`bash
npx dopx init ${o(r.name,e)}
\`\`\`
`}]}:{content:[{type:"text",text:s}]}}case"get_items":{let t=await h(e);return t.items?{content:[{type:"text",text:`The following items are available in the registry:
${JSON.stringify(t.items.map(r=>`- ${r.name} (${r.type}): ${r.description}`),null,2)}.
- To install and use an item in your project, you run the following command:
\`\`\`bash
npx dopx add ${o("NAME_OF_THE_ITEM",e)}
\`\`\`
- Example: npx dopx add ${o(t.items[0].name,e)} to install the ${t.items[0].name} item.
- To install multiple registry.items, you can do the following:
\`\`\`bash
npx dopx add ${o("NAME_OF_THE_ITEM_1",e)} ${o("NAME_OF_THE_ITEM_2",e)}
\`\`\`
- Before using any item, you need to add it first.
- Adding the items will install all dependencies for the item and format the code as per the project.
- Example components should not be installed directly unless asked. These components should be used as a reference to build other components.
`}]}:{content:[{type:"text",text:"No items found in the registry"}]}}case"get_item":{let t=z.string().parse(n.params.arguments.name);if(!t)throw new Error("Name is required");let r=o(t,e),s=await R(r,"");return {content:[{type:"text",text:JSON.stringify(s,null,2)}]}}case"add_item":{let t=z.string().parse(n.params.arguments.name);if(!t)throw new Error("Name is required");let r=o(t,e);return await R(r,"")?{content:[{type:"text",text:`To install the ${t} item, run the following command:
\`\`\`bash
npx dopx add ${r}
\`\`\``}]}:{content:[{type:"text",text:`Item ${t} not found in the registry.`}]}}default:throw new Error(`Tool ${n.params.name} not found`)}}catch(e){throw e instanceof z.ZodError?new Error(`Invalid input: ${JSON.stringify(e.errors)}`):e}});async function h(n){let[e]=await X([n],{useCache:!1});return H.parse(e)}function o(n,e){return `${e.replace(/\/registry\.json$/,"")}/${n}.json`}
export { u as a };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-RNFW37EL.js.map