export default function SchemaPreview( { state, definitions } ) { function generateSchema() { const properties = {}; ( state.blocks || [] ).forEach( ( block ) => { const def = definitions[ block.block_type ]; if ( ! def ) { return; } // Standard filters. const availableFilters = def.filters || {}; Object.entries( block.config.filters || {} ).forEach( ( [ key, filterConfig ] ) => { if ( ! filterConfig.enabled || ! availableFilters[ key ] ) { return; } const prop = { ...availableFilters[ key ] }; if ( filterConfig.description ) { prop.description = filterConfig.description; } properties[ key ] = prop; } ); // Taxonomy filters. Object.entries( block.config.taxonomies || {} ).forEach( ( [ taxSlug, taxConfig ] ) => { if ( ! taxConfig.as_filter ) { return; } const prop = { type: 'string', description: `Filter by ${ taxSlug }`, }; if ( taxConfig.terms && taxConfig.terms.length > 0 ) { prop.enum = taxConfig.terms; } properties[ taxSlug ] = prop; } ); // Meta key filters — mirrors server-side get_input_schema_properties(). const TYPE_MAP = { NUMERIC: 'number', DECIMAL: 'number', UNSIGNED: 'number' }; const FORMAT_MAP = { NUMERIC: 'integer (e.g. 29)', UNSIGNED: 'positive integer (e.g. 100)', DECIMAL: 'decimal (e.g. 29.99)', DATE: 'date (YYYY-MM-DD)', DATETIME: 'date-time (YYYY-MM-DDTHH:MM:SS)', TIME: 'time (HH:MM:SS)', }; const ARRAY_OPS = [ 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ]; const EXISTS_OPS = [ 'EXISTS', 'NOT EXISTS' ]; Object.entries( block.config.meta_keys || {} ).forEach( ( [ metaKey, metaConfig ] ) => { if ( ! metaConfig.as_filter ) { return; } const metaType = metaConfig.type || 'CHAR'; const compare = metaConfig.compare || [ '=' ]; const schemaType = TYPE_MAP[ metaType ] || 'string'; const baseSchema = { type: schemaType }; if ( FORMAT_MAP[ metaType ] ) { baseSchema.format = FORMAT_MAP[ metaType ]; } const hasArrayOps = compare.some( ( c ) => ARRAY_OPS.includes( c ) ); const hasScalarOps = compare.some( ( c ) => ! ARRAY_OPS.includes( c ) && ! EXISTS_OPS.includes( c ) ); const hasExistsOnly = ! hasArrayOps && ! hasScalarOps; let valueSchema; if ( hasArrayOps && hasScalarOps ) { valueSchema = { oneOf: [ { ...baseSchema }, { type: 'array', items: { ...baseSchema } } ] }; } else if ( hasArrayOps ) { valueSchema = { type: 'array', items: { ...baseSchema } }; } else { valueSchema = { ...baseSchema }; } const itemRequired = hasExistsOnly ? [ 'compare' ] : [ 'value', 'compare' ]; const itemProperties = { compare: { type: 'string', enum: compare }, }; if ( ! hasExistsOnly ) { itemProperties.value = valueSchema; } properties[ metaKey ] = { type: 'array', items: { type: 'object', properties: itemProperties, required: itemRequired, }, description: `Filter by ${ metaKey }`, }; } ); } ); return { name: state.tool_name || 'untitled_tool', description: state.description || '', inputSchema: { type: 'object', properties: Object.keys( properties ).length > 0 ? properties : {}, }, }; } const schema = generateSchema(); return (

Schema Preview

What the AI will see

				{ JSON.stringify( schema, null, 2 ) }
			
); }