feat(xai): support namespace tools and enhance tool normalization logic

- Added `namespace` tool type support, enabling nested tools to be normalized and moved to the top level.
- Refactored tool normalization logic into `normalizeXAITool` for reusability and clarity.
- Updated `xai_executor` test cases to validate namespace tool handling and nested tool normalization.
This commit is contained in:
Luis Pater
2026-05-17 15:02:36 +08:00
parent 8b3670b8dd
commit 74cb53dee1
4 changed files with 129 additions and 3 deletions
@@ -49,6 +49,42 @@ func TestWithXAIBuiltinsAddsVideoModel(t *testing.T) {
}
}
func TestValidateModelsCatalogAllowsMissingSections(t *testing.T) {
data := validTestModelsCatalog()
data.XAI = nil
if err := validateModelsCatalog(data); err != nil {
t.Fatalf("validateModelsCatalog() error = %v", err)
}
}
func TestValidateModelsCatalogRejectsInvalidDefinitions(t *testing.T) {
data := validTestModelsCatalog()
data.Claude = []*ModelInfo{{ID: ""}}
if err := validateModelsCatalog(data); err == nil {
t.Fatal("expected invalid model definition error")
}
}
func validTestModelsCatalog() *staticModelsJSON {
models := []*ModelInfo{{ID: "test-model"}}
return &staticModelsJSON{
Claude: models,
Gemini: models,
Vertex: models,
GeminiCLI: models,
AIStudio: models,
CodexFree: models,
CodexTeam: models,
CodexPlus: models,
CodexPro: models,
Kimi: models,
Antigravity: models,
XAI: models,
}
}
func findModelInfo(models []*ModelInfo, id string) *ModelInfo {
for _, model := range models {
if model != nil && model.ID == id {
+2 -1
View File
@@ -349,7 +349,8 @@ func validateModelsCatalog(data *staticModelsJSON) error {
func validateModelSection(section string, models []*ModelInfo) error {
if len(models) == 0 {
return fmt.Errorf("%s section is empty", section)
log.Warnf("models catalog: %s section is empty, continuing without those model definitions", section)
return nil
}
seen := make(map[string]struct{}, len(models))