page.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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>
  19. <strong className="text-foreground">Components</strong> — UI elements
  20. AI can create
  21. </li>
  22. <li>
  23. <strong className="text-foreground">Actions</strong> — Operations AI
  24. can trigger
  25. </li>
  26. <li>
  27. <strong className="text-foreground">Validation Functions</strong> —
  28. Custom validators for form inputs
  29. </li>
  30. </ul>
  31. <h2 className="text-xl font-semibold mt-12 mb-4">Creating a Catalog</h2>
  32. <Code lang="typescript">{`import { createCatalog } from '@json-render/core';
  33. import { z } from 'zod';
  34. const catalog = createCatalog({
  35. components: {
  36. // Define each component with its props schema
  37. Card: {
  38. props: z.object({
  39. title: z.string(),
  40. description: z.string().nullable(),
  41. padding: z.enum(['sm', 'md', 'lg']).default('md'),
  42. }),
  43. hasChildren: true, // Can contain other components
  44. },
  45. Metric: {
  46. props: z.object({
  47. label: z.string(),
  48. valuePath: z.string(), // JSON Pointer to data
  49. format: z.enum(['currency', 'percent', 'number']),
  50. }),
  51. },
  52. },
  53. actions: {
  54. submit_form: {
  55. params: z.object({
  56. formId: z.string(),
  57. }),
  58. description: 'Submit a form',
  59. },
  60. export_data: {
  61. params: z.object({
  62. format: z.enum(['csv', 'pdf', 'json']),
  63. }),
  64. },
  65. },
  66. validationFunctions: {
  67. isValidEmail: {
  68. description: 'Validates email format',
  69. },
  70. isPhoneNumber: {
  71. description: 'Validates phone number',
  72. },
  73. },
  74. });`}</Code>
  75. <h2 className="text-xl font-semibold mt-12 mb-4">Component Definition</h2>
  76. <p className="text-sm text-muted-foreground mb-4">
  77. Each component in the catalog has:
  78. </p>
  79. <Code lang="typescript">{`{
  80. props: z.object({...}), // Zod schema for props
  81. hasChildren?: boolean, // Can it have children?
  82. description?: string, // Help AI understand when to use it
  83. }`}</Code>
  84. <h2 className="text-xl font-semibold mt-12 mb-4">
  85. Generating AI Prompts
  86. </h2>
  87. <p className="text-sm text-muted-foreground mb-4">
  88. Use <code className="text-foreground">generateCatalogPrompt</code> to
  89. create a system prompt for AI:
  90. </p>
  91. <Code lang="typescript">{`import { generateCatalogPrompt } from '@json-render/core';
  92. const systemPrompt = generateCatalogPrompt(catalog);
  93. // Pass this to your AI model as the system prompt`}</Code>
  94. <h2 className="text-xl font-semibold mt-12 mb-4">Next</h2>
  95. <p className="text-sm text-muted-foreground">
  96. Learn how to{" "}
  97. <Link
  98. href="/docs/components"
  99. className="text-foreground hover:underline"
  100. >
  101. register React components
  102. </Link>{" "}
  103. for your catalog.
  104. </p>
  105. </article>
  106. );
  107. }