"use client"; import { motion } from "framer-motion"; import { useState, useEffect } from "react"; interface OutputField { name: string; type: "string" | "number" | "boolean" | "object" | "array"; description?: string; } interface OutputSchemaPanelProps { nodeId: string; currentSchema: OutputField[]; onUpdate: (schema: OutputField[]) => void; } export default function OutputSchemaPanel({ nodeId, currentSchema, onUpdate }: OutputSchemaPanelProps) { const [schema, setSchema] = useState(currentSchema || []); useEffect(() => { const timeoutId = setTimeout(() => { onUpdate(schema); }, 500); return () => clearTimeout(timeoutId); }, [schema, onUpdate]); const addField = () => { setSchema([ ...schema, { name: `field${schema.length + 1}`, type: "string", }, ]); }; const updateField = (index: number, updates: Partial) => { setSchema( schema.map((field, i) => (i === index ? { ...field, ...updates } : field)) ); }; const removeField = (index: number) => { setSchema(schema.filter((_, i) => i !== index)); }; const generateTypeScriptInterface = () => { if (schema.length === 0) return 'interface Output {\n // No fields defined\n}'; const fields = schema.map(f => { const typeStr = f.type === 'array' ? 'any[]' : f.type; const desc = f.description ? ` // ${f.description}\n` : ''; return `${desc} ${f.name}: ${typeStr};`; }).join('\n'); return `interface ${nodeId.replace(/-/g, '_')}_Output {\n${fields}\n}`; }; return (

Output Schema

{schema.length === 0 ? (

Define the shape of this node's output

) : (
{schema.map((field, index) => (
{/* Field Name */} updateField(index, { name: e.target.value })} placeholder="fieldName" className="px-10 py-6 bg-white border border-border-faint rounded-6 text-body-small text-accent-black font-mono focus:outline-none focus:border-heat-100 transition-colors" /> {/* Field Type */}
{/* Remove Button */}
{/* Field Description */} updateField(index, { description: e.target.value })} placeholder="Field description (optional)" className="w-full px-10 py-6 bg-white border border-border-faint rounded-6 text-body-small text-black-alpha-48 focus:outline-none focus:border-heat-100 transition-colors" />
))}
)} {/* TypeScript Preview */} {schema.length > 0 && (
              {generateTypeScriptInterface()}
            

Access fields: state.variables.{nodeId}.fieldName

)}
); }