import type { SVGProps } from 'react' import type { JSX } from 'react' import { ToolResponse } from '@/tools/types' // Basic type definitions for block components export type BlockIcon = (props: SVGProps) => JSX.Element export type BlockCategory = 'blocks' | 'tools' export type ParamType = 'string' | 'number' | 'boolean' | 'json' export type PrimitiveValueType = 'string' | 'number' | 'boolean' | 'json' | 'any' // Sub-block configuration types export type SubBlockType = | 'short-input' | 'long-input' | 'dropdown' | 'slider' | 'table' | 'code' | 'switch' | 'tool-input' | 'checkbox-list' | 'condition-input' | 'eval-input' export type SubBlockLayout = 'full' | 'half' // Tool output type utilities export type ExtractToolOutput = T extends ToolResponse ? T['output'] : never 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 configuration interfaces and types export type BlockOutput = | PrimitiveValueType | { [key: string]: PrimitiveValueType | Record } 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 } } } 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 } } } export interface BlockConfig { type: string toolbar: { title: string description: string bgColor: string icon: BlockIcon category: BlockCategory } tools: { access: string[] config?: { tool: (params: Record) => string } } workflow: { subBlocks: SubBlockConfig[] inputs: Record outputs: { response: { type: ToolOutputToValueType> dependsOn?: { subBlockId: string condition: { whenEmpty: ToolOutputToValueType> whenFilled: 'json' } } } } } } export interface OutputConfig { type: BlockOutput dependsOn?: { subBlockId: string condition: { whenEmpty: BlockOutput whenFilled: BlockOutput } } }