Smithery Schema Form
smithery/smithery-schema-formFreeBlock
A dynamic form component that renders form fields based on JSON Schema definitions.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/clavia-inc/openchat/main/public/r/smithery-schema-form.jsonSource
1"use client";23import { useForm } from "react-hook-form";4import { Button } from "@/components/ui/button";5import {6 Field,7 FieldDescription,8 FieldError,9 FieldLabel,10} from "@/components/ui/field";11import { Input } from "@/components/ui/input";12import {13 Select,14 SelectContent,15 SelectItem,16 SelectTrigger,17 SelectValue,18} from "@/components/ui/select";19import { Switch } from "@/components/ui/switch";20import { Textarea } from "@/components/ui/textarea";2122interface JSONSchema {23 type?: string;24 properties?: Record<string, JSONSchemaProperty>;25 required?: string[];26 additionalProperties?: boolean;27}2829interface JSONSchemaProperty {30 type?: string | string[];31 description?: string;32 enum?: string[];33 minimum?: number;34 maximum?: number;35 default?: unknown;36 items?: JSONSchemaProperty;37}3839interface SchemaFormProps {40 schema: unknown;41 onSubmit: (data: Record<string, unknown>) => void;42 isLoading?: boolean;43}4445export function SchemaForm({ schema, onSubmit, isLoading }: SchemaFormProps) {46 // Extract JSON schema from various formats47 const jsonSchema: JSONSchema =48 schema && typeof schema === "object" && "jsonSchema" in schema49 ? (schema as { jsonSchema: JSONSchema }).jsonSchema50 : (schema as JSONSchema) || {};5152 const {53 register,54 handleSubmit,55 formState: { errors },56 setValue,57 watch,58 } = useForm<Record<string, unknown>>({59 defaultValues: getDefaultValues(jsonSchema),60 });6162 const properties = jsonSchema.properties || {};63 const requiredFields = jsonSchema.required || [];6465 return (66 <form onSubmit={handleSubmit(onSubmit)} className="space-y-4">67 {Object.entries(properties).map(([name, property]) => {68 const isRequired = requiredFields.includes(name);69 return (70 <Field key={name}>71 <FieldLabel htmlFor={name}>72 {formatFieldName(name)}73 {isRequired && <span className="text-destructive ml-1">*</span>}74 </FieldLabel>75 {property.description && (76 <FieldDescription>{property.description}</FieldDescription>77 )}78 {renderField(name, property, register, setValue, watch, isRequired)}79 <FieldError errors={errors[name] ? [errors[name]] : undefined} />80 </Field>81 );82 })}83 <Button type="submit" disabled={isLoading} className="w-full">84 {isLoading ? "Executing..." : "Execute"}85 </Button>86 </form>87 );88}8990function renderField(91 name: string,92 property: JSONSchemaProperty,93 register: ReturnType<typeof useForm>["register"],94 setValue: ReturnType<typeof useForm>["setValue"],95// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from smithery
All 10 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Smitherysmithery | smithery | Blocks | Free | 9 deps · 11 files | |
| Smithery Connection Contextsmithery-connection-context | smithery | Blocks | Free | no deps | |
| Smithery Connectionssmithery-connections | smithery | Blocks | Free | 8 deps · 9 files | |
| Smithery Server Searchsmithery-server-search | smithery | Blocks | Free | 3 deps · 3 files | |
| Smithery Tokenssmithery-tokens | smithery | Blocks | Free | 3 deps | |
| Smithery Tool Cardsmithery-tool-card | smithery | Blocks | Free | 5 deps · 4 files | |
| Smithery Tool Detail Dialogsmithery-tool-detail-dialog | smithery | Blocks | Free | 5 deps · 3 files | |
| Smithery Tools Panelsmithery-tools-panel | smithery | Blocks | Free | 5 deps · 5 files |
