import { z } from "zod/v4"; export const singleValueDisplayConfigSchema = z.object({ type: z .literal("singleValue") .describe("Display type discriminator — must be 'singleValue' when displayType is singleValue"), jsonPath: z .string() .min(1) .describe( "JSONPath expression to extract the value from the API response (e.g. $.data.count, $.items[0].name, $.status). Use $ for the root object.", ), label: z .string() .describe("Human-readable label shown alongside the extracted value (e.g. 'CPU Temperature', 'Total Users')"), unit: z .string() .describe("Unit suffix displayed after the value (e.g. '°C', '%', 'GB'). Leave empty string if no unit is needed."), valueSize: z .enum(["sm", "md", "lg", "xl"]) .optional() .describe( "Font size of the displayed value: 'sm' (small), 'md' (medium), 'lg' (large, default), 'xl' (extra large)", ), labelPosition: z .enum(["above", "below"]) .optional() .describe("Position of the label relative to the value: 'above' or 'below' (default: below)"), }); const keyValueMappingSchema = z.object({ label: z.string().min(1).describe("Label for this key-value pair (e.g. 'CPU', 'Memory', 'Uptime')"), jsonPath: z .string() .min(1) .describe( "JSONPath expression to extract this value from the API response (e.g. $.cpu.percent, $.memory.used). Use $ for the root object.", ), unit: z .string() .describe("Unit suffix for this value (e.g. '%', 'GB', 'ms'). Leave empty string if no unit is needed."), }); export const keyValueDisplayConfigSchema = z.object({ type: z.literal("keyValue").describe("Display type discriminator — must be 'keyValue' when displayType is keyValue"), mappings: z .array(keyValueMappingSchema) .min(1) .describe("Array of label/jsonPath/unit mappings — each entry becomes one labeled value in the widget"), layout: z .enum(["list", "grid"]) .optional() .describe("Layout style: 'list' (vertical stack, default) or 'grid' (multi-column grid)"), columns: z .number() .int() .min(1) .max(3) .optional() .describe("Number of columns when layout is 'grid' (1–3, default: 2)"), }); const tableColumnSchema = z.object({ header: z.string().min(1).describe("Column header text shown in the table (e.g. 'Name', 'Status', 'Size')"), jsonPath: z .string() .min(1) .describe( "JSONPath expression relative to each row object to extract the cell value (e.g. $.name, $.status, $.size). Do not include the array path here — that goes in tablePath.", ), }); export const tableDisplayConfigSchema = z.object({ type: z.literal("table").describe("Display type discriminator — must be 'table' when displayType is table"), tablePath: z .string() .min(1) .describe( "JSONPath expression to the array of row objects in the API response (e.g. $.data.items, $.results, $.users[*])", ), columns: z .array(tableColumnSchema) .min(1) .describe("Column definitions — each column has a header and a jsonPath relative to each row"), striped: z .boolean() .optional() .describe("Whether to alternate row background colors for readability (default: true)"), compact: z.boolean().optional().describe("Whether to use compact row spacing (default: false)"), }); const statGridItemSchema = z.object({ label: z.string().min(1).describe("Label for this stat card (e.g. 'Movies', 'Series', 'Episodes')"), jsonPath: z .string() .min(1) .describe( "JSONPath expression to extract the stat value from the API response (e.g. $.library.movies, $.counts.series)", ), unit: z.string().describe("Unit suffix for the stat (e.g. '', 'GB', '%'). Leave empty string if no unit is needed."), color: z .string() .optional() .describe("Mantine color name for the stat card (e.g. 'blue', 'green', 'red', 'orange', 'violet'). Default: blue"), }); export const statGridDisplayConfigSchema = z.object({ type: z.literal("statGrid").describe("Display type discriminator — must be 'statGrid' when displayType is statGrid"), items: z .array(statGridItemSchema) .min(1) .describe("Array of stat cards — each item shows a labeled value in a colored card"), columns: z.number().int().min(1).max(4).optional().describe("Number of columns in the stat grid (1–4, default: 2)"), cardStyle: z .enum(["filled", "outline", "subtle"]) .optional() .describe( "Visual style of stat cards: 'filled' (solid background, default), 'outline' (border only), 'subtle' (light tint)", ), }); const progressBarItemSchema = z.object({ label: z.string().min(1).describe("Label for this progress bar (e.g. 'Disk Usage', 'Memory', 'Quota')"), valuePath: z .string() .min(1) .describe( "JSONPath expression to extract the current value (numerator) from the API response (e.g. $.disk.used, $.memory.used_bytes)", ), maxPath: z .string() .optional() .describe( "JSONPath expression to extract the maximum value (denominator). If omitted, defaults to 100. Use for ratios like used/total (e.g. $.disk.total)", ), unit: z .string() .describe("Unit suffix shown alongside values (e.g. 'GB', 'MB', '%'). Leave empty string if no unit is needed."), color: z .string() .optional() .describe("Mantine color name for the progress bar fill (e.g. 'blue', 'green', 'red'). Default: blue"), }); export const progressBarsDisplayConfigSchema = z.object({ type: z .literal("progressBars") .describe("Display type discriminator — must be 'progressBars' when displayType is progressBars"), bars: z .array(progressBarItemSchema) .min(1) .describe("Array of progress bar definitions — each bar shows value/max as a visual progress indicator"), showPercentage: z.boolean().optional().describe("Whether to display the percentage next to each bar (default: true)"), barSize: z .enum(["sm", "md", "lg"]) .optional() .describe("Height of progress bars: 'sm' (small), 'md' (medium, default), 'lg' (large)"), }); const statusIndicatorItemSchema = z.object({ label: z.string().min(1).describe("Label for this status indicator (e.g. 'Web Server', 'Database', 'API')"), jsonPath: z .string() .min(1) .describe( "JSONPath expression to extract the status value from the API response (e.g. $.services.web.status, $.health.database)", ), goodValues: z .array(z.string()) .min(1) .describe( "Array of string values considered 'healthy/good' — case-insensitive match (e.g. ['online', 'up', 'true', 'healthy', 'ok'])", ), }); export const statusIndicatorDisplayConfigSchema = z.object({ type: z .literal("statusIndicator") .describe("Display type discriminator — must be 'statusIndicator' when displayType is statusIndicator"), items: z .array(statusIndicatorItemSchema) .min(1) .describe("Array of status indicators — each shows a green dot if the value matches goodValues, red otherwise"), layout: z .enum(["list", "grid"]) .optional() .describe("Layout style: 'list' (vertical, default) or 'grid' (multi-column)"), dotSize: z .enum(["sm", "md", "lg"]) .optional() .describe("Size of status dots: 'sm' (small), 'md' (medium, default), 'lg' (large)"), }); const countGridItemSchema = z.object({ label: z.string().min(1).describe("Label for this count (e.g. 'Movies', 'Shows', 'Albums')"), jsonPath: z .string() .min(1) .describe( "JSONPath expression to extract the count value from the API response (e.g. $.counts.movies, $.stats.total)", ), unit: z.string().describe("Unit suffix for the count (e.g. '', 'items'). Leave empty string if no unit is needed."), }); export const countGridDisplayConfigSchema = z.object({ type: z .literal("countGrid") .describe("Display type discriminator — must be 'countGrid' when displayType is countGrid"), items: z .array(countGridItemSchema) .min(1) .describe("Array of count items — each shows a number with a label in a simple grid (no colors)"), columns: z.number().int().min(2).max(4).optional().describe("Number of columns in the count grid (2–4, default: 2)"), valueSize: z .enum(["sm", "md", "lg"]) .optional() .describe("Font size of count values: 'sm' (small), 'md' (medium, default), 'lg' (large)"), }); export const rawDisplayConfigSchema = z.object({ type: z.literal("raw").describe("Display type discriminator — must be 'raw' when displayType is raw"), jsonPath: z .string() .min(1) .describe( "JSONPath expression to extract the data to display (e.g. $ for entire response, $.data, $.result). The extracted value is pretty-printed as JSON.", ), maxHeight: z .number() .int() .min(50) .max(1000) .optional() .describe("Maximum height of the raw JSON display area in pixels (50–1000, default: 300)"), });