瀏覽代碼

fix: tool parameter validator

Yeuoly 10 月之前
父節點
當前提交
2c1cc8c721

+ 11 - 0
internal/types/entities/plugin_entities/config.go

@@ -123,6 +123,17 @@ func isScope(fl validator.FieldLevel) bool {
 			return false
 		}
 	}
+	if tool_parameter, ok := parent.(ToolParameter); ok {
+		if tool_parameter.Type == TOOL_PARAMETER_TYPE_APP_SELECTOR {
+			return isAppSelectorScope(fl)
+		} else if tool_parameter.Type == TOOL_PARAMETER_TYPE_MODEL_SELECTOR {
+			return isModelConfigScope(fl)
+		} else if tool_parameter.Type == TOOL_PARAMETER_TYPE_TOOL_SELECTOR {
+			return isToolSelectorScope(fl)
+		} else {
+			return false
+		}
+	}
 	return false
 }
 

+ 40 - 1
internal/types/entities/plugin_entities/tool_declaration_test.go

@@ -1100,7 +1100,46 @@ func TestAppSelectorScopeToolProvider_Validate(t *testing.T) {
 		}
 	],
 	"tools": [
-	
+		{
+			"identity": {
+				"author": "author",
+				"name": "tool",
+				"label": {
+					"en_US": "label",
+					"zh_Hans": "标签",
+					"pt_BR": "etiqueta"
+				}
+			},
+			"description": {
+				"human": {
+					"en_US": "description",
+					"zh_Hans": "描述",
+					"pt_BR": "descrição"
+				},
+				"llm": "description"
+			},
+			"parameters": [
+				{
+					"name": "parameter-app-selector",
+					"label": {
+						"en_US": "label",
+						"zh_Hans": "标签",
+						"pt_BR": "etiqueta"
+					},
+					"human_description": {
+						"en_US": "description",
+						"zh_Hans": "描述",
+						"pt_BR": "descrição"
+					},
+					"type": "app-selector",
+					"form": "llm",
+					"scope": "all",
+					"required": true,
+					"default": "default",
+					"options": []
+				}
+			]
+		}
 	]
 }
 	`