ValidateInput 验证工具输入
(tool Tool, input map[string]any)
| 121 | |
| 122 | // ValidateInput 验证工具输入 |
| 123 | func ValidateInput(tool Tool, input map[string]any) error { |
| 124 | schema := tool.InputSchema() |
| 125 | if schema == nil { |
| 126 | return nil // 没有schema,跳过验证 |
| 127 | } |
| 128 | |
| 129 | // TODO: 使用jsonschema库进行验证 |
| 130 | // 这里先做简单的required字段检查 |
| 131 | if required, ok := schema["required"].([]any); ok { |
| 132 | for _, field := range required { |
| 133 | fieldName := field.(string) |
| 134 | if _, exists := input[fieldName]; !exists { |
| 135 | return fmt.Errorf("missing required field: %s", fieldName) |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | // ToolCallRecordBuilder 工具调用记录构建器 |
| 144 | type ToolCallRecordBuilder struct { |
nothing calls this directly
no test coverage detected