page.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 (with props and optional slots)
  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">Functions</strong> — Custom
  28. validation or transformation functions
  29. </li>
  30. </ul>
  31. <h2 className="text-xl font-semibold mt-12 mb-4">Creating a Catalog</h2>
  32. <Code lang="typescript">{`import { defineCatalog } from '@json-render/core';
  33. import { schema } from '@json-render/react';
  34. import { z } from 'zod';
  35. const catalog = defineCatalog(schema, {
  36. components: {
  37. // Define each component with its props schema
  38. Card: {
  39. props: z.object({
  40. title: z.string(),
  41. description: z.string().nullable(),
  42. padding: z.enum(['sm', 'md', 'lg']).nullable(),
  43. }),
  44. slots: ["default"], // Can contain other components
  45. description: "Container card for grouping content",
  46. },
  47. Metric: {
  48. props: z.object({
  49. label: z.string(),
  50. valuePath: z.string(), // JSON Pointer to data
  51. format: z.enum(['currency', 'percent', 'number']),
  52. }),
  53. description: "Display a single metric value",
  54. },
  55. },
  56. actions: {
  57. submit_form: {
  58. params: z.object({
  59. formId: z.string(),
  60. }),
  61. description: 'Submit a form',
  62. },
  63. export_data: {
  64. params: z.object({
  65. format: z.enum(['csv', 'pdf', 'json']),
  66. }),
  67. description: 'Export data in various formats',
  68. },
  69. },
  70. });`}</Code>
  71. <h2 className="text-xl font-semibold mt-12 mb-4">Component Definition</h2>
  72. <p className="text-sm text-muted-foreground mb-4">
  73. Each component in the catalog has:
  74. </p>
  75. <Code lang="typescript">{`{
  76. props: z.object({...}), // Zod schema for props (use .nullable() for optional)
  77. slots?: string[], // Named slots for children (e.g., ["default"])
  78. description?: string, // Help AI understand when to use it
  79. }`}</Code>
  80. <p className="text-sm text-muted-foreground mt-4 mb-4">
  81. Use{" "}
  82. <code className="text-foreground">slots: [&quot;default&quot;]</code>{" "}
  83. for components that can contain children. The slot name corresponds to
  84. where child elements are rendered.
  85. </p>
  86. <h2 className="text-xl font-semibold mt-12 mb-4">
  87. Generating AI Prompts
  88. </h2>
  89. <p className="text-sm text-muted-foreground mb-4">
  90. Use the <code className="text-foreground">catalog.prompt()</code> method
  91. to generate a system prompt for AI:
  92. </p>
  93. <Code lang="typescript">{`// Generate a system prompt from your catalog
  94. const systemPrompt = catalog.prompt();
  95. // Or with custom rules for the AI
  96. const customPrompt = catalog.prompt({
  97. customRules: [
  98. "Always use Card as the root element for forms",
  99. "Group related inputs in a Stack with direction=vertical",
  100. ],
  101. });
  102. // Pass this to your AI model as the system prompt`}</Code>
  103. <h2 className="text-xl font-semibold mt-12 mb-4">Next</h2>
  104. <p className="text-sm text-muted-foreground">
  105. Learn how to{" "}
  106. <Link href="/docs/registry" className="text-foreground hover:underline">
  107. register components
  108. </Link>{" "}
  109. in your registry.
  110. </p>
  111. </article>
  112. );
  113. }