Widget Renderer
inferencesh/widgetsFreeBlock
Renders declarative UI nodes (forms, buttons, cards) from agent tool outputs.
Live preview
live · rendered by the registry
Rendered by inferencesh on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.inference.sh/r/widgets.jsonSource
1"use client"23import { Markdown } from "@/lib/pretext-md/react"4import { Badge } from "@/components/ui/badge"5import { Button } from "@/components/ui/button"6import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"7import { Checkbox } from "@/components/ui/checkbox"8import { Input } from "@/components/ui/input"9import { Label } from "@/components/ui/label"10import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"11import type { Widget, WidgetAction, WidgetFormData, WidgetNode } from "@/components/infsh/agent/widget-types"12import { cn } from "@/lib/utils"13import React, { createContext, useContext, useState } from "react"1415// Use the shared form data type16type FormData = WidgetFormData1718// Local variant types (shadcn doesn't export the Props types)19type ButtonVariant = "default" | "secondary" | "outline" | "ghost" | "destructive" | "link"20type BadgeVariant = "default" | "secondary" | "outline" | "destructive"2122const toButtonVariant = (v?: string): ButtonVariant => {23 if (v === "default" || v === "secondary" || v === "outline" || v === "ghost" || v === "destructive" || v === "link") {24 return v25 }26 return "default"27}2829const toBadgeVariant = (v?: string): BadgeVariant => {30 if (v === "default" || v === "secondary" || v === "outline" || v === "destructive") {31 return v32 }33 return "default"34}3536// Context for handling widget actions37type WidgetContextValue = {38 onAction: (action: WidgetAction, formData?: FormData) => void39 formData: FormData40 setFormValue: (name: string, value: string | boolean) => void41 isDisabled: boolean42 loadingActionType: string | null43}4445const WidgetContext = createContext<WidgetContextValue | null>(null)4647const useWidgetContext = () => {48 const ctx = useContext(WidgetContext)49 if (!ctx) throw new Error("useWidgetContext must be used within WidgetRenderer")50 return ctx51}5253// Helper to map text variant to CSS classes54const toTextClasses = (variant?: string): string => {55 switch (variant) {56 case "muted":57 return "text-xs text-muted-foreground"58 case "bold":59 return "text-sm font-medium"60 case "title":61 return "text-sm font-medium"62 case "small":63 return "text-xs"64 default:65 return "text-sm"66 }67}6869// Helper to map size to font size classes70const toSizeClasses = (size?: string): string => {71 switch (size) {72 case "xs": return "text-xs"73 case "sm": return "text-sm"74 case "md": return "text-base"75// … truncated
What it pulls in
Other registry items
Files it writes
More from inferencesh
All 14 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Agent Chatagent | inferencesh | Blocks | Free | 1 dep | |
| Chat UI Primitiveschat | inferencesh | Blocks | Free | 1 dep · 15 files | |
| Code Blockcode-block | inferencesh | Blocks | Free | no deps · 7 files | |
| Markdown Renderer (legacy)markdown | inferencesh | Blocks | Free | 2 deps · 2 files | |
| pretext-mdpretext-md | inferencesh | Blocks | Free | 4 deps · 10 files | |
| Sidebar Lightsidebar-light | inferencesh | Blocks | Free | no deps | |
| Stepssteps | inferencesh | Blocks | Free | no deps · 2 files | |
| Table of Contentstable-of-contents | inferencesh | Blocks | Free | no deps |
