'use client' import { ChipSelect, ChipSwitch, ChipTag, chipFieldSurfaceClass, chipFieldTextClass, cn, FieldDivider, Label, } from '@sim/emcn' import { BookOpen, Pencil } from 'lucide-react' import { resolveIcon } from '@/components/workflow-preview/block-icons' import { formatReferences } from '@/components/workflow-preview/format-references' type FieldKind = 'select' | 'input' | 'textarea' | 'code' | 'slider' | 'toggle' interface InspectorField { label: string required?: boolean kind?: FieldKind /** Shown inside the control. For 'toggle', "on"/"off". For 'slider', the number. */ value?: string /** Muted placeholder when there's no value. */ placeholder?: string /** Slider fill, 0–100. */ percent?: number } interface InspectorTool { type: string name: string bgColor: string } interface BlockInspectorProps { /** Block name in the header, e.g. "Agent 1". */ name: string /** Block type, for the header icon. */ type?: string color?: string fields: InspectorField[] tools?: InspectorTool[] /** Render as a borderless panel filling its parent (the lightbox sidebar). */ embedded?: boolean } const NOOP = () => {} /** * Read-only facsimile of one configuration field, composed from emcn chip * chrome: `select`→{@link ChipSelect}, `toggle`→{@link ChipSwitch}; text fields * (`input`/`textarea`/`code`) render the value with `<...>`/`{{...}}` references * highlighted via {@link formatReferences} in the canonical chip field surface. * `slider` has no chip equivalent and stays a minimal app-token bar. */ function FieldControl({ field }: { field: InspectorField }) { const kind = field.kind ?? 'input' const value = field.value ?? '' const placeholder = field.placeholder ?? '—' if (kind === 'select') { return ( ) } if (kind === 'toggle') { const on = field.value === 'on' return ( ) } if (kind === 'slider') { const percent = field.percent ?? 50 return (
{field.value}
) } // input / textarea / code: read-only value with `<...>` block references and // `{{...}}` environment variables highlighted, in the canonical chip chrome. const content = value ? ( formatReferences(value) ) : ( {placeholder} ) if (kind === 'textarea' || kind === 'code') { return (
{content}
) } return (
{content}
) } function InspectorFieldRow({ field }: { field: InspectorField }) { return (
) } /** * A read-only facsimile of the editor's right-hand block inspector: the block * header, its configuration fields as static chip controls, and its * connections. Hand-authored per usage, like {@link WorkflowPreview} examples. */ export function BlockInspector({ name, type = 'agent', color = '#33C482', fields, tools, embedded = false, }: BlockInspectorProps) { const Icon = resolveIcon(type) const hasTools = Boolean(tools && tools.length > 0) return (
{Icon && }
{name}
{fields.map((field, i) => (
{i > 0 && }
))} {hasTools && (
{fields.length > 0 && }
{tools?.map((tool) => { const TIcon = resolveIcon(tool.type) return ( {TIcon && } {tool.name} ) })}
)}
) }