@hanzo/ui 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/dist/index.d.mts +16 -0
  2. package/dist/index.d.ts +16 -0
  3. package/dist/index.js +9458 -0
  4. package/dist/index.mjs +9449 -0
  5. package/dist/lib/utils.d.mts +2 -0
  6. package/dist/lib/utils.d.ts +2 -0
  7. package/dist/lib/utils.js +47 -0
  8. package/dist/lib/utils.mjs +28 -0
  9. package/dist/src/utils.d.mts +7 -0
  10. package/dist/src/utils.d.ts +7 -0
  11. package/dist/src/utils.js +47 -0
  12. package/dist/src/utils.mjs +28 -0
  13. package/dist/tailwind/index.d.mts +2 -0
  14. package/dist/tailwind/index.d.ts +2 -0
  15. package/dist/tailwind/index.js +2048 -0
  16. package/dist/tailwind/index.mjs +2017 -0
  17. package/dist/types/index.d.mts +12 -0
  18. package/dist/types/index.d.ts +12 -0
  19. package/dist/types/index.js +79 -0
  20. package/dist/types/index.mjs +56 -0
  21. package/package.json +151 -25
  22. package/MCP-INSTRUCTIONS.md +0 -73
  23. package/README-MCP.md +0 -175
  24. package/assets/ai-icons.tsx +0 -207
  25. package/assets/crypto.tsx +0 -33
  26. package/assets/file-type-icon.tsx +0 -66
  27. package/assets/file.tsx +0 -45
  28. package/assets/general.tsx +0 -2318
  29. package/assets/hanzo-logo.svg +0 -9
  30. package/assets/hanzo-logo.tsx +0 -15
  31. package/assets/index.ts +0 -8
  32. package/assets/index.tsx +0 -4
  33. package/assets/llm-provider.tsx +0 -1094
  34. package/blocks/components/accordian-block.tsx +0 -48
  35. package/blocks/components/block-component-props.ts +0 -11
  36. package/blocks/components/bullet-cards-block.tsx +0 -46
  37. package/blocks/components/card-block/index.tsx +0 -171
  38. package/blocks/components/card-block/link-out-button.tsx +0 -20
  39. package/blocks/components/card-block/util.ts +0 -28
  40. package/blocks/components/carte-blanche-block/index.tsx +0 -127
  41. package/blocks/components/carte-blanche-block/variant-content-left.tsx +0 -49
  42. package/blocks/components/content.tsx +0 -70
  43. package/blocks/components/cta-block.tsx +0 -115
  44. package/blocks/components/enh-heading-block.tsx +0 -204
  45. package/blocks/components/grid-block/grid-block-mutator.ts +0 -12
  46. package/blocks/components/grid-block/index.tsx +0 -83
  47. package/blocks/components/grid-block/mutator-registry.ts +0 -10
  48. package/blocks/components/grid-block/table-borders.mutator.ts +0 -47
  49. package/blocks/components/group-block.tsx +0 -83
  50. package/blocks/components/heading-block.tsx +0 -88
  51. package/blocks/components/image-block.tsx +0 -111
  52. package/blocks/components/index.ts +0 -30
  53. package/blocks/components/screenful-block/content.tsx +0 -123
  54. package/blocks/components/screenful-block/index.tsx +0 -107
  55. package/blocks/components/screenful-block/poster-background.tsx +0 -34
  56. package/blocks/components/screenful-block/video-background.tsx +0 -45
  57. package/blocks/components/space-block.tsx +0 -66
  58. package/blocks/components/video-block.tsx +0 -138
  59. package/blocks/def/accordian-block.ts +0 -14
  60. package/blocks/def/block.ts +0 -7
  61. package/blocks/def/bullet-cards-block.ts +0 -22
  62. package/blocks/def/card-block.ts +0 -22
  63. package/blocks/def/carte-blanche-block.ts +0 -21
  64. package/blocks/def/cta-block.ts +0 -19
  65. package/blocks/def/element-block.ts +0 -11
  66. package/blocks/def/enh-heading-block.ts +0 -44
  67. package/blocks/def/grid-block.ts +0 -16
  68. package/blocks/def/group-block.ts +0 -11
  69. package/blocks/def/heading-block.ts +0 -15
  70. package/blocks/def/image-block.ts +0 -31
  71. package/blocks/def/index.ts +0 -35
  72. package/blocks/def/screenful-block.ts +0 -54
  73. package/blocks/def/space-block.ts +0 -64
  74. package/blocks/def/video-block.ts +0 -9
  75. package/blocks/index.ts +0 -2
  76. package/components/index.ts +0 -56
  77. package/dist/button.d.ts +0 -1
  78. package/dist/button.js +0 -1
  79. package/dist/hooks/index.d.ts +0 -7
  80. package/dist/hooks/index.js +0 -7
  81. package/dist/hooks/use-click-away.d.ts +0 -2
  82. package/dist/hooks/use-click-away.js +0 -23
  83. package/dist/hooks/use-combined-refs.d.ts +0 -3
  84. package/dist/hooks/use-combined-refs.js +0 -18
  85. package/dist/hooks/use-copy-clipboard.d.ts +0 -9
  86. package/dist/hooks/use-copy-clipboard.js +0 -21
  87. package/dist/hooks/use-debounce.d.ts +0 -1
  88. package/dist/hooks/use-debounce.js +0 -13
  89. package/dist/hooks/use-fill-ids.d.ts +0 -8
  90. package/dist/hooks/use-fill-ids.js +0 -20
  91. package/dist/hooks/use-map.d.ts +0 -1
  92. package/dist/hooks/use-map.js +0 -20
  93. package/dist/hooks/use-measure.d.ts +0 -8
  94. package/dist/hooks/use-measure.js +0 -25
  95. package/dist/hooks/use-reverse-video-playback.d.ts +0 -1
  96. package/dist/hooks/use-reverse-video-playback.js +0 -41
  97. package/dist/hooks/use-scroll-restoration.d.ts +0 -8
  98. package/dist/hooks/use-scroll-restoration.js +0 -36
  99. package/dist/mcp/enhanced-server.d.ts +0 -29
  100. package/dist/mcp/enhanced-server.js +0 -1128
  101. package/dist/mcp/index.d.ts +0 -28
  102. package/dist/mcp/index.js +0 -436
  103. package/dist/registry/api.d.ts +0 -37
  104. package/dist/registry/api.js +0 -129
  105. package/dist/registry/index.d.ts +0 -353
  106. package/dist/registry/index.js +0 -45
  107. package/dist/utils.d.ts +0 -1
  108. package/dist/utils.js +0 -1
  109. package/environment.d.ts +0 -6
  110. package/helpers/file.ts +0 -33
  111. package/helpers/memoization.ts +0 -40
  112. package/primitives/accordion.tsx +0 -74
  113. package/primitives/action-button.tsx +0 -42
  114. package/primitives/alert-dialog.tsx +0 -185
  115. package/primitives/alert.tsx +0 -74
  116. package/primitives/apply-typography.tsx +0 -55
  117. package/primitives/aspect-ratio.tsx +0 -5
  118. package/primitives/avatar.tsx +0 -57
  119. package/primitives/background-beams.tsx +0 -142
  120. package/primitives/badge.tsx +0 -44
  121. package/primitives/breadcrumb.tsx +0 -130
  122. package/primitives/breakpoint-indicator.tsx +0 -19
  123. package/primitives/button.tsx +0 -82
  124. package/primitives/calendar.tsx +0 -72
  125. package/primitives/card.tsx +0 -97
  126. package/primitives/carousel.tsx +0 -237
  127. package/primitives/chat/chat-input-area.tsx +0 -87
  128. package/primitives/chat/chat-input.tsx +0 -71
  129. package/primitives/chat/files-preview.tsx +0 -330
  130. package/primitives/chat/index.ts +0 -6
  131. package/primitives/chat/json-form.tsx +0 -8
  132. package/primitives/chat/message-list.tsx +0 -307
  133. package/primitives/chat/message.tsx +0 -569
  134. package/primitives/chat/sqlite-preview.tsx +0 -215
  135. package/primitives/checkbox.tsx +0 -31
  136. package/primitives/collapsible.tsx +0 -9
  137. package/primitives/combobox.tsx +0 -239
  138. package/primitives/command.tsx +0 -149
  139. package/primitives/context-menu.tsx +0 -206
  140. package/primitives/copy-to-clipboard-icon.tsx +0 -60
  141. package/primitives/dialog-video-controller.tsx +0 -38
  142. package/primitives/dialog.tsx +0 -123
  143. package/primitives/dot-pattern.tsx +0 -57
  144. package/primitives/dots-loader.tsx +0 -13
  145. package/primitives/drawer.tsx +0 -110
  146. package/primitives/dropdown-menu.tsx +0 -199
  147. package/primitives/error-message.tsx +0 -19
  148. package/primitives/file-uploader.tsx +0 -200
  149. package/primitives/form.tsx +0 -183
  150. package/primitives/hover-card.tsx +0 -28
  151. package/primitives/icons/github.tsx +0 -14
  152. package/primitives/icons/index.ts +0 -18
  153. package/primitives/icons/youtube-logo.tsx +0 -59
  154. package/primitives/index-common.ts +0 -303
  155. package/primitives/index-next.ts +0 -4
  156. package/primitives/input-otp.tsx +0 -65
  157. package/primitives/input.tsx +0 -125
  158. package/primitives/label.tsx +0 -20
  159. package/primitives/list-adaptor.ts +0 -12
  160. package/primitives/list-box.tsx +0 -74
  161. package/primitives/loading-spinner.tsx +0 -33
  162. package/primitives/markdown-preview.tsx +0 -609
  163. package/primitives/mermaid.tsx +0 -196
  164. package/primitives/navigation-menu.tsx +0 -147
  165. package/primitives/next/image.tsx +0 -90
  166. package/primitives/next/index.ts +0 -7
  167. package/primitives/next/inline-icon.tsx +0 -36
  168. package/primitives/next/link-element.tsx +0 -109
  169. package/primitives/next/mdx-link.tsx +0 -22
  170. package/primitives/next/media-stack.tsx +0 -69
  171. package/primitives/next/nav-items.tsx +0 -45
  172. package/primitives/next/youtube-embed.tsx +0 -83
  173. package/primitives/pagination.tsx +0 -117
  174. package/primitives/popover.tsx +0 -32
  175. package/primitives/pretty-json-print.tsx +0 -28
  176. package/primitives/progress.tsx +0 -26
  177. package/primitives/prompt-textarea.tsx +0 -72
  178. package/primitives/qr-code.tsx +0 -112
  179. package/primitives/radio-group.tsx +0 -42
  180. package/primitives/resizable.tsx +0 -47
  181. package/primitives/scroll-area.tsx +0 -57
  182. package/primitives/search-input.tsx +0 -66
  183. package/primitives/select.tsx +0 -122
  184. package/primitives/separator.tsx +0 -25
  185. package/primitives/sheet.tsx +0 -139
  186. package/primitives/skeleton.tsx +0 -17
  187. package/primitives/slider.tsx +0 -62
  188. package/primitives/sonner.tsx +0 -35
  189. package/primitives/step-indicator.tsx +0 -69
  190. package/primitives/stepper.tsx +0 -272
  191. package/primitives/switch.tsx +0 -26
  192. package/primitives/table.tsx +0 -105
  193. package/primitives/tabs.tsx +0 -50
  194. package/primitives/text-area.tsx +0 -26
  195. package/primitives/text-link.tsx +0 -25
  196. package/primitives/textarea.tsx +0 -61
  197. package/primitives/textfield.tsx +0 -75
  198. package/primitives/toast.tsx +0 -30
  199. package/primitives/toggle-group.tsx +0 -63
  200. package/primitives/toggle.tsx +0 -44
  201. package/primitives/tooltip.tsx +0 -47
  202. package/primitives/video-player.tsx +0 -23
  203. package/public/r/accordion.json +0 -11
  204. package/public/r/alert.json +0 -11
  205. package/public/r/avatar.json +0 -11
  206. package/public/r/badge.json +0 -11
  207. package/public/r/button.json +0 -11
  208. package/public/r/card.json +0 -11
  209. package/public/r/checkbox.json +0 -11
  210. package/public/r/default.json +0 -6
  211. package/public/r/dialog.json +0 -11
  212. package/public/r/input.json +0 -11
  213. package/public/r/label.json +0 -11
  214. package/public/r/new-york.json +0 -6
  215. package/public/r/popover.json +0 -11
  216. package/public/r/select.json +0 -11
  217. package/public/r/table.json +0 -11
  218. package/public/r/tabs.json +0 -11
  219. package/public/r/toast.json +0 -11
  220. package/registry.json +0 -184
  221. package/src/button.ts +0 -1
  222. package/src/hooks/index.ts +0 -7
  223. package/src/hooks/use-click-away.ts +0 -31
  224. package/src/hooks/use-combined-refs.ts +0 -22
  225. package/src/hooks/use-copy-clipboard.ts +0 -30
  226. package/src/hooks/use-debounce.ts +0 -17
  227. package/src/hooks/use-fill-ids.ts +0 -25
  228. package/src/hooks/use-map.ts +0 -26
  229. package/src/hooks/use-measure.ts +0 -42
  230. package/src/hooks/use-reverse-video-playback.ts +0 -43
  231. package/src/hooks/use-scroll-restoration.ts +0 -50
  232. package/src/mcp/README.md +0 -141
  233. package/src/mcp/enhanced-server.ts +0 -1208
  234. package/src/mcp/index.ts +0 -518
  235. package/src/mcp/package.json +0 -10
  236. package/src/registry/api.ts +0 -164
  237. package/src/registry/index.ts +0 -60
  238. package/src/registry/package.json +0 -10
  239. package/src/utils.ts +0 -1
  240. package/tailwind/colors.tailwind.js +0 -53
  241. package/tailwind/fontFamily.tailwind.ts +0 -7
  242. package/tailwind/fontSize.tailwind.ts +0 -13
  243. package/tailwind/index.ts +0 -7
  244. package/tailwind/safelist.tailwind.js +0 -26
  245. package/tailwind/screens.tailwind.js +0 -8
  246. package/tailwind/spacing.tailwind.js +0 -65
  247. package/tailwind/tailwind.config.hanzo-preset.d.ts +0 -5
  248. package/tailwind/tailwind.config.hanzo-preset.js +0 -915
  249. package/tailwind/tw-font-desc.ts +0 -15
  250. package/tailwind/typo-plugin/get-plugin-styles.js +0 -679
  251. package/tailwind/typo-plugin/index.d.ts +0 -9
  252. package/tailwind/typo-plugin/index.js +0 -141
  253. package/tailwind/typo-plugin/utils.js +0 -60
  254. package/tailwind/typography-test.mdx +0 -35
  255. package/tailwind/z-index.tailwind.js +0 -71
  256. package/test/test-registry.js +0 -73
  257. package/test-imports.mjs +0 -19
  258. package/tsconfig.json +0 -22
  259. package/types/animation-def.ts +0 -3
  260. package/types/breakpoints.ts +0 -11
  261. package/types/bullet-item.ts +0 -10
  262. package/types/button-def.ts +0 -39
  263. package/types/dimensions.ts +0 -8
  264. package/types/grid-def.ts +0 -56
  265. package/types/image-def.ts +0 -32
  266. package/types/index.ts +0 -29
  267. package/types/link-def.ts +0 -56
  268. package/types/media-stack-def.ts +0 -31
  269. package/types/t-shirt-size.ts +0 -5
  270. package/types/tshirt-dimensions.ts +0 -20
  271. package/types/video-def.ts +0 -25
  272. package/util/blob.ts +0 -28
  273. package/util/copy-to-clipboard.ts +0 -17
  274. package/util/create-shadow-root.ts +0 -22
  275. package/util/date.ts +0 -83
  276. package/util/debounce.ts +0 -11
  277. package/util/file.ts +0 -15
  278. package/util/format-and-abbreviate-as-currency.ts +0 -125
  279. package/util/format-text.ts +0 -33
  280. package/util/format-to-max-char.ts +0 -68
  281. package/util/index-client.ts +0 -3
  282. package/util/index.ts +0 -9
  283. package/util/number-abbreviate.ts +0 -49
  284. package/util/specifier.ts +0 -43
  285. package/util/spread-to-transform.ts +0 -24
  286. package/util/step-animation.ts +0 -90
  287. package/util/timing.ts +0 -3
  288. package/util/toasts.tsx +0 -17
  289. package/util/two-way-map.ts +0 -19
  290. package/utils.ts +0 -9
@@ -1,28 +0,0 @@
1
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
- /**
3
- * MCP Server implementation for @hanzo/ui registry
4
- * Provides tools for interacting with the registry
5
- */
6
- export declare const server: Server<{
7
- method: string;
8
- params?: {
9
- [x: string]: unknown;
10
- _meta?: {
11
- [x: string]: unknown;
12
- progressToken?: string | number | undefined;
13
- } | undefined;
14
- } | undefined;
15
- }, {
16
- method: string;
17
- params?: {
18
- [x: string]: unknown;
19
- _meta?: {
20
- [x: string]: unknown;
21
- } | undefined;
22
- } | undefined;
23
- }, {
24
- [x: string]: unknown;
25
- _meta?: {
26
- [x: string]: unknown;
27
- } | undefined;
28
- }>;
package/dist/mcp/index.js DELETED
@@ -1,436 +0,0 @@
1
- import { registrySchema } from "../registry";
2
- import { fetchRegistry, getRegistryItem, getRegistryItemUrl } from "../registry/api";
3
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
- import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
- import { z } from "zod";
6
- import { zodToJsonSchema } from "zod-to-json-schema";
7
- // Get package version
8
- let packageVersion = "4.5.0";
9
- try {
10
- // eslint-disable-next-line @typescript-eslint/no-var-requires
11
- const packageJson = require("../../package.json");
12
- packageVersion = packageJson.version || packageVersion;
13
- }
14
- catch (error) {
15
- console.error("Could not load package.json for version", error);
16
- }
17
- /**
18
- * MCP Server implementation for @hanzo/ui registry
19
- * Provides tools for interacting with the registry
20
- */
21
- export const server = new Server({
22
- name: "hanzo-ui",
23
- version: packageVersion,
24
- }, {
25
- capabilities: {
26
- resources: {},
27
- tools: {},
28
- },
29
- });
30
- // Register the available tools
31
- server.setRequestHandler(ListToolsRequestSchema, async () => {
32
- return {
33
- tools: [
34
- {
35
- name: "init",
36
- description: "Initialize a new project using @hanzo/ui components and styles.",
37
- inputSchema: zodToJsonSchema(z.object({
38
- style: z.string().optional().describe("The style to use for the project (e.g., 'default' or 'new-york')"),
39
- })),
40
- },
41
- {
42
- name: "list_components",
43
- description: "List all available components in the registry",
44
- inputSchema: zodToJsonSchema(z.object({
45
- type: z.string().optional().describe("Filter components by type (e.g., 'ui', 'block')"),
46
- category: z.string().optional().describe("Filter components by category"),
47
- })),
48
- },
49
- {
50
- name: "get_component",
51
- description: "Get detailed information about a specific component",
52
- inputSchema: zodToJsonSchema(z.object({
53
- name: z
54
- .string()
55
- .describe("The name of the component to get from the registry"),
56
- })),
57
- },
58
- {
59
- name: "add_component",
60
- description: "Get instructions for adding a component to a project",
61
- inputSchema: zodToJsonSchema(z.object({
62
- name: z
63
- .string()
64
- .describe("The name of the component to add"),
65
- style: z
66
- .string()
67
- .optional()
68
- .describe("The style to use (default, new-york, etc.)"),
69
- })),
70
- },
71
- {
72
- name: "list_styles",
73
- description: "List all available styles in the registry",
74
- inputSchema: zodToJsonSchema(z.object({})),
75
- },
76
- {
77
- name: "search_registry",
78
- description: "Search the registry for components matching criteria",
79
- inputSchema: zodToJsonSchema(z.object({
80
- query: z
81
- .string()
82
- .describe("Search term to look for in component names and descriptions"),
83
- })),
84
- },
85
- ],
86
- };
87
- });
88
- // Handle tool calls
89
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
90
- try {
91
- // Ensure we have arguments
92
- const args = request.params.arguments || {};
93
- // Get registry URL from environment variable or use default
94
- const REGISTRY_URL = process.env.REGISTRY_URL || "https://ui.hanzo.ai/registry/registry.json";
95
- const registry = await getRegistry(REGISTRY_URL);
96
- switch (request.params.name) {
97
- case "init": {
98
- const style = args.style || "default";
99
- let text = `# Initialize a new project with @hanzo/ui
100
-
101
- To create a new project with @hanzo/ui components, follow these steps:
102
-
103
- 1. Create a new project first:
104
- \`\`\`bash
105
- # Using npm
106
- npm create next-app@latest my-app
107
-
108
- # Or using yarn
109
- yarn create next-app my-app
110
-
111
- # Or using pnpm
112
- pnpm create next-app my-app
113
- \`\`\`
114
-
115
- 2. Navigate to your project directory:
116
- \`\`\`bash
117
- cd my-app
118
- \`\`\`
119
-
120
- 3. Install @hanzo/ui and initialize it:
121
- \`\`\`bash
122
- npx @hanzo/ui@latest init${style ? ` --style=${style}` : ""}
123
- \`\`\`
124
-
125
- This will:
126
- - Install all necessary dependencies
127
- - Set up the project structure for @hanzo/ui
128
- - Configure tailwind.css with the appropriate theme
129
- - Add component configuration
130
- `;
131
- // Check if the registry has any additional setup instructions
132
- const setupConfig = registry.items.find((item) => item.type === "registry:config" && item.name === "setup");
133
- if (setupConfig) {
134
- text += `
135
- ## Additional Setup
136
-
137
- ${setupConfig.description || "Follow any additional setup instructions provided during initialization."}
138
- `;
139
- }
140
- return {
141
- content: [
142
- { type: "text", text }
143
- ],
144
- };
145
- }
146
- case "list_components": {
147
- // Filter components based on type and category if provided
148
- const typeFilter = args.type ? `ui:${args.type}` : null;
149
- const categoryFilter = args.category || null;
150
- let components = registry.items.filter(item => {
151
- // Filter by type if specified
152
- if (typeFilter && !item.type.includes(typeFilter)) {
153
- return false;
154
- }
155
- // Filter by category if specified
156
- if (categoryFilter && item.category !== categoryFilter) {
157
- return false;
158
- }
159
- return true;
160
- });
161
- // Group components by category if they have categories
162
- const hasCategories = components.some(item => item.category);
163
- let responseText = "# Available Components\n\n";
164
- if (hasCategories) {
165
- // Group by category
166
- const categorized = components.reduce((acc, item) => {
167
- const category = item.category || "Uncategorized";
168
- if (!acc[category]) {
169
- acc[category] = [];
170
- }
171
- acc[category].push(item);
172
- return acc;
173
- }, {});
174
- // Build response
175
- for (const [category, items] of Object.entries(categorized)) {
176
- responseText += `## ${category}\n\n`;
177
- items.forEach(item => {
178
- responseText += `- **${item.name}** - ${item.description || 'No description available'}\n`;
179
- });
180
- responseText += "\n";
181
- }
182
- }
183
- else {
184
- // Simple list
185
- components.forEach(item => {
186
- responseText += `- **${item.name}** (${item.type}) - ${item.description || 'No description available'}\n`;
187
- });
188
- }
189
- responseText += "\nTo get detailed information about a specific component, use the `get_component` tool.\n";
190
- responseText += "To add a component to your project, use the `add_component` tool.\n";
191
- return {
192
- content: [{ type: "text", text: responseText }],
193
- };
194
- }
195
- case "get_component": {
196
- const name = z.string().parse(args.name);
197
- if (!name) {
198
- throw new Error("Component name is required");
199
- }
200
- const itemUrl = getRegistryItemUrl(name, REGISTRY_URL);
201
- const component = await getRegistryItem(itemUrl, "");
202
- if (!component) {
203
- return {
204
- content: [
205
- {
206
- type: "text",
207
- text: `Component '${name}' not found in the registry.`,
208
- },
209
- ],
210
- };
211
- }
212
- // Build a markdown description of the component
213
- let componentDetails = `# ${component.name}\n\n`;
214
- if (component.description) {
215
- componentDetails += `${component.description}\n\n`;
216
- }
217
- componentDetails += `**Type:** ${component.type}\n`;
218
- if (component.category) {
219
- componentDetails += `**Category:** ${component.category}\n`;
220
- }
221
- // Dependencies
222
- if (component.dependencies && component.dependencies.length > 0) {
223
- componentDetails += `\n## Dependencies\n\n`;
224
- component.dependencies.forEach(dep => {
225
- componentDetails += `- ${dep}\n`;
226
- });
227
- }
228
- // Registry Dependencies
229
- if (component.registryDependencies && component.registryDependencies.length > 0) {
230
- componentDetails += `\n## Required Components\n\n`;
231
- componentDetails += `This component requires the following components that will be installed automatically:\n\n`;
232
- component.registryDependencies.forEach(dep => {
233
- componentDetails += `- ${dep}\n`;
234
- });
235
- }
236
- // Files
237
- if (component.files && component.files.length > 0) {
238
- componentDetails += `\n## Files\n\n`;
239
- component.files.forEach(file => {
240
- componentDetails += `- ${file.path} (${file.type})\n`;
241
- });
242
- }
243
- // Show example usage if available
244
- const exampleFile = component.files?.find(file => file.type === "registry:example");
245
- if (exampleFile && exampleFile.content) {
246
- componentDetails += `\n## Example Usage\n\n\`\`\`tsx\n${exampleFile.content}\n\`\`\`\n`;
247
- }
248
- // Add installation instructions
249
- componentDetails += `\n## Installation\n\n`;
250
- componentDetails += `Run the following command to add this component to your project:\n\n`;
251
- componentDetails += `\`\`\`bash\n`;
252
- componentDetails += `npx @hanzo/ui@latest add ${name}\n`;
253
- componentDetails += `\`\`\`\n`;
254
- return {
255
- content: [{ type: "text", text: componentDetails }],
256
- };
257
- }
258
- case "add_component": {
259
- const name = z.string().parse(args.name);
260
- const style = args.style || "default";
261
- if (!name) {
262
- throw new Error("Component name is required");
263
- }
264
- const itemUrl = getRegistryItemUrl(name, REGISTRY_URL);
265
- const component = await getRegistryItem(itemUrl, "");
266
- if (!component) {
267
- return {
268
- content: [
269
- {
270
- type: "text",
271
- text: `Component '${name}' not found in the registry.`,
272
- },
273
- ],
274
- };
275
- }
276
- // Check if the component has dependencies
277
- const hasDeps = component.registryDependencies && component.registryDependencies.length > 0;
278
- let instructions = `# Adding the ${name} Component\n\n`;
279
- // Main installation command
280
- instructions += `Run the following command to add the \`${name}\` component to your project:\n\n`;
281
- instructions += `\`\`\`bash\n`;
282
- instructions += `npx @hanzo/ui@latest add ${name} --style=${style}\n`;
283
- instructions += `\`\`\`\n\n`;
284
- // Explain what this will do
285
- instructions += `This will:\n`;
286
- instructions += `- Add the component file(s) to your project\n`;
287
- instructions += `- Install any required npm dependencies\n`;
288
- if (hasDeps) {
289
- instructions += `- Install required component dependencies: ${component.registryDependencies.join(", ")}\n`;
290
- }
291
- // Usage example
292
- instructions += `\n## Usage\n\nAfter adding the component, you can import it in your project:\n\n`;
293
- instructions += `\`\`\`tsx\n`;
294
- instructions += `import { ${name.charAt(0).toUpperCase() + name.slice(1)} } from "@/components/ui/${name}"\n\n`;
295
- // Add a simple example if possible
296
- if (component.type.includes("ui:")) {
297
- instructions += `export default function Example() {\n`;
298
- instructions += ` return <${name.charAt(0).toUpperCase() + name.slice(1)} />\n`;
299
- instructions += `}\n`;
300
- }
301
- instructions += `\`\`\`\n`;
302
- return {
303
- content: [
304
- {
305
- type: "text",
306
- text: instructions,
307
- },
308
- ],
309
- };
310
- }
311
- case "list_styles": {
312
- // Find all style-related items in the registry
313
- const styles = registry.items.filter(item => item.type === "registry:style" || item.type.includes("style"));
314
- let styleInfo = "# Available Styles\n\n";
315
- if (styles.length === 0) {
316
- styleInfo += "The registry does not define any specific styles.\n\n";
317
- styleInfo += "The default style will be used when installing components.\n";
318
- }
319
- else {
320
- styles.forEach(style => {
321
- styleInfo += `## ${style.name}\n\n`;
322
- styleInfo += `${style.description || 'No description available'}\n\n`;
323
- // Add usage info
324
- styleInfo += `**Usage:**\n\n`;
325
- styleInfo += `\`\`\`bash\n`;
326
- styleInfo += `# Initialize with this style\n`;
327
- styleInfo += `npx @hanzo/ui@latest init --style=${style.name}\n\n`;
328
- styleInfo += `# Install components with this style\n`;
329
- styleInfo += `npx @hanzo/ui@latest add [component] --style=${style.name}\n`;
330
- styleInfo += `\`\`\`\n\n`;
331
- });
332
- }
333
- return {
334
- content: [{ type: "text", text: styleInfo }],
335
- };
336
- }
337
- case "search_registry": {
338
- const query = z.string().parse(args.query).toLowerCase();
339
- if (!query || query.length < 2) {
340
- return {
341
- content: [
342
- {
343
- type: "text",
344
- text: "Please provide a search term with at least 2 characters.",
345
- },
346
- ],
347
- };
348
- }
349
- // Search through all items in the registry
350
- const results = registry.items.filter(item => {
351
- // Search in name
352
- if (item.name.toLowerCase().includes(query)) {
353
- return true;
354
- }
355
- // Search in description
356
- if (item.description?.toLowerCase().includes(query)) {
357
- return true;
358
- }
359
- // Search in category
360
- if (item.category?.toLowerCase().includes(query)) {
361
- return true;
362
- }
363
- return false;
364
- });
365
- if (results.length === 0) {
366
- return {
367
- content: [
368
- {
369
- type: "text",
370
- text: `No components found matching '${query}'. Try a different search term.`,
371
- },
372
- ],
373
- };
374
- }
375
- // Format the results
376
- let searchResults = `# Search Results for '${query}'\n\n`;
377
- searchResults += `Found ${results.length} matching components\n\n`;
378
- results.forEach(item => {
379
- searchResults += `## ${item.name}\n\n`;
380
- searchResults += `**Type:** ${item.type}\n`;
381
- if (item.category) {
382
- searchResults += `**Category:** ${item.category}\n`;
383
- }
384
- if (item.description) {
385
- searchResults += `\n${item.description}\n`;
386
- }
387
- searchResults += `\n**Installation:**\n\n`;
388
- searchResults += `\`\`\`bash\nnpx @hanzo/ui@latest add ${item.name}\n\`\`\`\n\n`;
389
- });
390
- return {
391
- content: [{ type: "text", text: searchResults }],
392
- };
393
- }
394
- default:
395
- throw new Error(`Tool ${request.params.name} not found`);
396
- }
397
- }
398
- catch (error) {
399
- if (error instanceof z.ZodError) {
400
- return {
401
- content: [
402
- {
403
- type: "text",
404
- text: `Invalid input: ${JSON.stringify(error.errors)}`,
405
- },
406
- ],
407
- };
408
- }
409
- throw error;
410
- }
411
- });
412
- /**
413
- * Fetches and parses the registry from the given URL
414
- * @param registryUrl - URL to the registry.json file
415
- * @returns The parsed registry object
416
- */
417
- async function getRegistry(registryUrl) {
418
- try {
419
- const [registryJson] = await fetchRegistry([registryUrl], {
420
- useCache: false,
421
- });
422
- return registrySchema.parse(registryJson);
423
- }
424
- catch (error) {
425
- console.error(`Failed to fetch registry from ${registryUrl}:`, error);
426
- // Return a minimal valid registry if we can't fetch the real one
427
- return {
428
- name: "hanzo-ui",
429
- items: [],
430
- };
431
- }
432
- }
433
- // Support CommonJS
434
- if (typeof module !== 'undefined') {
435
- module.exports = { server };
436
- }
@@ -1,37 +0,0 @@
1
- import { RegistryItem, Registry } from "./schemas";
2
- /**
3
- * Gets the full registry URL based on the registry name or URL provided
4
- * @param registry - Registry name, URL, or file path
5
- * @returns The complete registry URL
6
- */
7
- export declare function getRegistryUrl(registry: string): string;
8
- /**
9
- * Fetches a specific registry item by URL
10
- * @param itemUrl - The URL of the item to fetch
11
- * @param basePath - Base path for resolving imports
12
- * @returns The registry item or null if not found
13
- */
14
- export declare function getRegistryItem(itemUrl: string, basePath: string): Promise<RegistryItem | null>;
15
- /**
16
- * Resolves an import path relative to a base path
17
- * @param importPath - The import path to resolve
18
- * @param basePath - The base path to resolve against
19
- * @returns The resolved import path
20
- */
21
- export declare function resolveImport(importPath: string, basePath: string): string;
22
- /**
23
- * Fetches registry data from one or more paths
24
- * @param paths - Array of registry paths to fetch
25
- * @param options - Options for fetching the registry
26
- * @returns Array of registry data
27
- */
28
- export declare function fetchRegistry(paths: string[], options?: {
29
- useCache?: boolean;
30
- }): Promise<Registry[]>;
31
- /**
32
- * Gets the URL for a specific registry item
33
- * @param itemName - The name of the registry item
34
- * @param registryUrl - The base registry URL
35
- * @returns The URL for the specific registry item
36
- */
37
- export declare function getRegistryItemUrl(itemName: string, registryUrl: string): string;
@@ -1,129 +0,0 @@
1
- import { registryItemSchema } from "./schemas";
2
- const registryCache = new Map();
3
- /**
4
- * Gets the full registry URL based on the registry name or URL provided
5
- * @param registry - Registry name, URL, or file path
6
- * @returns The complete registry URL
7
- */
8
- export function getRegistryUrl(registry) {
9
- // Check if registry is a full URL
10
- if (registry.startsWith("http")) {
11
- return registry;
12
- }
13
- // Default to Hanzo registry if REGISTRY_BASE_URL is defined, otherwise use hanzo
14
- const baseUrl = process.env.REGISTRY_BASE_URL || "https://ui.hanzo.com/registry";
15
- // Check if registry is a path to a JSON file
16
- if (registry.endsWith(".json")) {
17
- return `${baseUrl}/${registry}`;
18
- }
19
- // Assume registry is a registry style
20
- return `${baseUrl}/${registry}/registry.json`;
21
- }
22
- /**
23
- * Fetches a specific registry item by URL
24
- * @param itemUrl - The URL of the item to fetch
25
- * @param basePath - Base path for resolving imports
26
- * @returns The registry item or null if not found
27
- */
28
- export async function getRegistryItem(itemUrl, basePath) {
29
- try {
30
- const response = await fetch(itemUrl);
31
- if (!response.ok) {
32
- console.error(`Failed to fetch registry item from ${itemUrl}: ${response.status} ${response.statusText}`);
33
- return null;
34
- }
35
- const item = await response.json();
36
- const validatedItem = registryItemSchema.safeParse(item);
37
- if (!validatedItem.success) {
38
- console.error(`Invalid registry item format: ${JSON.stringify(validatedItem.error)}`);
39
- return null;
40
- }
41
- // Process and resolve file paths
42
- if (validatedItem.data.files) {
43
- for (const file of validatedItem.data.files) {
44
- if (!file.content) {
45
- continue;
46
- }
47
- // If the file has a target, we resolve it from the target
48
- if (file.target) {
49
- file.target = resolveImport(file.target, basePath);
50
- }
51
- }
52
- }
53
- return validatedItem.data;
54
- }
55
- catch (error) {
56
- console.error(`Error fetching registry item: ${error}`);
57
- return null;
58
- }
59
- }
60
- /**
61
- * Resolves an import path relative to a base path
62
- * @param importPath - The import path to resolve
63
- * @param basePath - The base path to resolve against
64
- * @returns The resolved import path
65
- */
66
- export function resolveImport(importPath, basePath) {
67
- const importParts = importPath?.split("/");
68
- // Check if it's a relative import
69
- if (importPath.startsWith(".")) {
70
- return [basePath.replace(/^@/, ""), ...importParts].filter(Boolean).join("/");
71
- }
72
- // Check if it's a scope package
73
- if (importParts?.[0]?.startsWith("@")) {
74
- return importPath;
75
- }
76
- return importPath;
77
- }
78
- /**
79
- * Fetches registry data from one or more paths
80
- * @param paths - Array of registry paths to fetch
81
- * @param options - Options for fetching the registry
82
- * @returns Array of registry data
83
- */
84
- export async function fetchRegistry(paths, options = {}) {
85
- options = {
86
- useCache: true,
87
- ...options,
88
- };
89
- try {
90
- const results = await Promise.all(paths.map(async (path) => {
91
- const url = getRegistryUrl(path);
92
- // Check cache first if caching is enabled
93
- if (options.useCache && registryCache.has(url)) {
94
- return registryCache.get(url);
95
- }
96
- // Store the promise in the cache before awaiting if caching is enabled
97
- const fetchPromise = (async () => {
98
- const response = await fetch(url);
99
- if (!response.ok) {
100
- throw new Error(`Failed to fetch registry from ${url}. ${response.status} ${response.statusText}`);
101
- }
102
- return response.json();
103
- })();
104
- if (options.useCache) {
105
- registryCache.set(url, fetchPromise);
106
- }
107
- return fetchPromise;
108
- }));
109
- return results;
110
- }
111
- catch (error) {
112
- console.error(`Error fetching registry: ${error}`);
113
- throw error;
114
- }
115
- }
116
- /**
117
- * Gets the URL for a specific registry item
118
- * @param itemName - The name of the registry item
119
- * @param registryUrl - The base registry URL
120
- * @returns The URL for the specific registry item
121
- */
122
- export function getRegistryItemUrl(itemName, registryUrl) {
123
- const registryBaseUrl = registryUrl.replace(/\/registry\.json$/, "");
124
- return `${registryBaseUrl}/r/${itemName}.json`;
125
- }
126
- // Support CommonJS
127
- if (typeof module !== 'undefined') {
128
- module.exports = { getRegistryUrl, getRegistryItem, resolveImport, fetchRegistry, getRegistryItemUrl };
129
- }