page.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import Link from "next/link";
  2. import { Code } from "@/components/code";
  3. export const metadata = {
  4. title: "Catalog | json-render",
  5. };
  6. export default function CatalogPage() {
  7. return (
  8. <article>
  9. <h1 className="text-3xl font-bold mb-4">Catalog</h1>
  10. <p className="text-muted-foreground mb-8">
  11. The catalog defines what AI can generate. It&apos;s your guardrail.
  12. </p>
  13. <h2 className="text-xl font-semibold mt-12 mb-4">What is a Catalog?</h2>
  14. <p className="text-sm text-muted-foreground mb-4">
  15. A catalog is a schema that defines:
  16. </p>
  17. <ul className="list-disc list-inside text-sm text-muted-foreground space-y-1 mb-4">
  18. <li><strong className="text-foreground">Components</strong> — UI elements AI can create</li>
  19. <li><strong className="text-foreground">Actions</strong> — Operations AI can trigger</li>
  20. <li><strong className="text-foreground">Validation Functions</strong> — Custom validators for form inputs</li>
  21. </ul>
  22. <h2 className="text-xl font-semibold mt-12 mb-4">Creating a Catalog</h2>
  23. <Code lang="typescript">{`import { createCatalog } from '@json-render/core';
  24. import { z } from 'zod';
  25. const catalog = createCatalog({
  26. components: {
  27. // Define each component with its props schema
  28. Card: {
  29. props: z.object({
  30. title: z.string(),
  31. description: z.string().nullable(),
  32. padding: z.enum(['sm', 'md', 'lg']).default('md'),
  33. }),
  34. hasChildren: true, // Can contain other components
  35. },
  36. Metric: {
  37. props: z.object({
  38. label: z.string(),
  39. valuePath: z.string(), // JSON Pointer to data
  40. format: z.enum(['currency', 'percent', 'number']),
  41. }),
  42. },
  43. },
  44. actions: {
  45. submit_form: {
  46. params: z.object({
  47. formId: z.string(),
  48. }),
  49. description: 'Submit a form',
  50. },
  51. export_data: {
  52. params: z.object({
  53. format: z.enum(['csv', 'pdf', 'json']),
  54. }),
  55. },
  56. },
  57. validationFunctions: {
  58. isValidEmail: {
  59. description: 'Validates email format',
  60. },
  61. isPhoneNumber: {
  62. description: 'Validates phone number',
  63. },
  64. },
  65. });`}</Code>
  66. <h2 className="text-xl font-semibold mt-12 mb-4">Component Definition</h2>
  67. <p className="text-sm text-muted-foreground mb-4">
  68. Each component in the catalog has:
  69. </p>
  70. <Code lang="typescript">{`{
  71. props: z.object({...}), // Zod schema for props
  72. hasChildren?: boolean, // Can it have children?
  73. description?: string, // Help AI understand when to use it
  74. }`}</Code>
  75. <h2 className="text-xl font-semibold mt-12 mb-4">Generating AI Prompts</h2>
  76. <p className="text-sm text-muted-foreground mb-4">
  77. Use <code className="text-foreground">generateCatalogPrompt</code> to create a system prompt for AI:
  78. </p>
  79. <Code lang="typescript">{`import { generateCatalogPrompt } from '@json-render/core';
  80. const systemPrompt = generateCatalogPrompt(catalog);
  81. // Pass this to your AI model as the system prompt`}</Code>
  82. <h2 className="text-xl font-semibold mt-12 mb-4">Next</h2>
  83. <p className="text-sm text-muted-foreground">
  84. Learn how to <Link href="/docs/components" className="text-foreground hover:underline">register React components</Link> for your catalog.
  85. </p>
  86. </article>
  87. );
  88. }