import type { SVGProps } from 'react' import type { JSX } from 'react' import { ToolResponse } from '@/tools/types' // Basic types export type BlockIcon = (props: SVGProps) => JSX.Element export type ParamType = 'string' | 'number' | 'boolean' | 'json' export type PrimitiveValueType = 'string' | 'number' | 'boolean' | 'json' | 'any' // Block classification export type BlockCategory = 'blocks' | 'tools' // SubBlock types export type SubBlockType = | 'short-input' // Single line input | 'long-input' // Multi-line input | 'dropdown' // Select menu | 'slider' // Range input | 'table' // Grid layout | 'code' // Code editor | 'switch' // Toggle button | 'tool-input' // Tool configuration | 'checkbox-list' // Multiple selection | 'condition-input' // Conditional logic | 'eval-input' // Evaluation input // Component width setting export type SubBlockLayout = 'full' | 'half' // Tool result extraction export type ExtractToolOutput = T extends ToolResponse ? T['output'] : never // Convert tool output to types export type ToolOutputToValueType = T extends Record ? { [K in keyof T]: T[K] extends string ? 'string' : T[K] extends number ? 'number' : T[K] extends boolean ? 'boolean' : T[K] extends object ? 'json' : 'any' } : never // Block output definition export type BlockOutput = | PrimitiveValueType | { [key: string]: PrimitiveValueType | Record } // Parameter validation rules export interface ParamConfig { type: ParamType required: boolean description?: string schema?: { type: string properties: Record required?: string[] additionalProperties?: boolean items?: { type: string properties?: Record required?: string[] additionalProperties?: boolean } } } // SubBlock configuration export interface SubBlockConfig { id: string title?: string type: SubBlockType layout?: SubBlockLayout options?: string[] | { label: string; id: string }[] min?: number max?: number columns?: string[] placeholder?: string password?: boolean connectionDroppable?: boolean hidden?: boolean value?: (params: Record) => string condition?: { field: string value: string | number | boolean and?: { field: string value: string | number | boolean } } } // Main block definition export interface BlockConfig { type: string name: string description: string category: BlockCategory longDescription?: string bgColor: string icon: BlockIcon subBlocks: SubBlockConfig[] tools: { access: string[] config?: { tool: (params: Record) => string } } inputs: Record outputs: { response: { type: ToolOutputToValueType> dependsOn?: { subBlockId: string condition: { whenEmpty: ToolOutputToValueType> whenFilled: 'json' } } } } } // Output configuration rules export interface OutputConfig { type: BlockOutput dependsOn?: { subBlockId: string condition: { whenEmpty: BlockOutput whenFilled: BlockOutput } } }