From 40c0395fb1302fad4f5f05f061bd59b344365880 Mon Sep 17 00:00:00 2001 From: Huarch Date: Fri, 17 Jul 2026 15:12:15 +0800 Subject: [PATCH] fix(style): validate layer style configuration --- .opencode/tools/apply_layer_style.ts | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/.opencode/tools/apply_layer_style.ts b/.opencode/tools/apply_layer_style.ts index 39fbd16..95e183b 100644 --- a/.opencode/tools/apply_layer_style.ts +++ b/.opencode/tools/apply_layer_style.ts @@ -28,8 +28,11 @@ export default tool({ .describe("Classification method."), segments: tool.schema .number() + .int() + .min(2) + .max(10) .optional() - .describe("Number of segments."), + .describe("Number of rendered intervals, from 2 to 10."), min_size: tool.schema .number() .optional() @@ -54,9 +57,9 @@ export default tool({ .enum(["single", "gradient", "rainbow", "custom"]) .optional() .describe("Color strategy."), - single_palette_index: tool.schema.number().optional(), - gradient_palette_index: tool.schema.number().optional(), - rainbow_palette_index: tool.schema.number().optional(), + single_palette_index: tool.schema.number().int().min(0).max(6).optional(), + gradient_palette_index: tool.schema.number().int().min(0).max(2).optional(), + rainbow_palette_index: tool.schema.number().int().min(0).max(1).optional(), show_labels: tool.schema .boolean() .optional() @@ -65,7 +68,7 @@ export default tool({ .boolean() .optional() .describe("Whether to show ids."), - opacity: tool.schema.number().optional().describe("Opacity in [0, 1]."), + opacity: tool.schema.number().min(0).max(1).optional().describe("Opacity in [0, 1]."), adjust_width_by_property: tool.schema .boolean() .optional() @@ -73,11 +76,11 @@ export default tool({ custom_breaks: tool.schema .array(tool.schema.number()) .optional() - .describe("Custom break values."), + .describe("Strictly increasing boundaries. Length must equal segments + 1."), custom_colors: tool.schema .array(tool.schema.string()) .optional() - .describe("Custom rgba colors."), + .describe("Custom CSS colors. Length must equal segments."), }) .optional() .describe( @@ -87,8 +90,24 @@ export default tool({ async execute(args) { const layerLabel = args.layer_id === "junctions" ? "节点" : "管道"; if (args.reset_to_default) { - return `已将${layerLabel}图层重置为默认样式。`; + return `已提交${layerLabel}图层默认样式重置请求。`; } - return `已对${layerLabel}图层应用样式。`; + const style = args.style_config; + if (style?.custom_breaks) { + if ( + style.custom_breaks.some( + (value, index, values) => index > 0 && value <= values[index - 1], + ) + ) { + throw new Error("custom_breaks must be strictly increasing"); + } + if (style.segments && style.custom_breaks.length !== style.segments + 1) { + throw new Error("custom_breaks length must equal segments + 1"); + } + } + if (style?.segments && style.custom_colors && style.custom_colors.length !== style.segments) { + throw new Error("custom_colors length must equal segments"); + } + return `已提交${layerLabel}图层样式请求。`; }, });