From 9dfc663b38ece2d64ec9c8e4922a1b2af98c1310 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Wed, 25 Nov 2026 09:55:05 +0000 Subject: [PATCH] feat(admin): expose model vision capability in admin meta view --- admin.go | 2 ++ modelmeta.go | 23 ++++++++++++++++++----- modelmeta_test.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/admin.go b/admin.go index b595e75..14f4445 100644 --- a/admin.go +++ b/admin.go @@ -566,6 +566,7 @@ type adminModelMetaView struct { ContextTokens *int `json:"contextTokens,omitempty"` InputPerMTokUSD *float64 `json:"inputPerMTokUsd,omitempty"` OutputPerMTokUSD *float64 `json:"outputPerMTokUsd,omitempty"` + Vision *bool `json:"vision,omitempty"` } // buildAdminModelMetaView converts resolveModelMeta's result into the @@ -574,6 +575,7 @@ type adminModelMetaView struct { // do this). func buildAdminModelMetaView(meta resolvedModelMeta) adminModelMetaView { var v adminModelMetaView + v.Vision = meta.Vision if meta.ContextKnown { ctx := meta.ContextTokens v.ContextTokens = &ctx diff --git a/modelmeta.go b/modelmeta.go index d446985..a060cef 100644 --- a/modelmeta.go +++ b/modelmeta.go @@ -34,6 +34,8 @@ const freeTierSuffix = ":free" // field, since a free model's cost fields are legitimately zero AND // known (ModelMetaConfig.Free). type resolvedModelMeta struct { + // Vision is the operator's explicit modelMeta.vision; nil means unset. + Vision *bool ContextTokens int InputCostPerMTokMicroUSD int64 OutputCostPerMTokMicroUSD int64 @@ -71,6 +73,7 @@ type resolvedModelMeta struct { // entry. func resolveModelMeta(provider, model string, cfg map[string]*ModelMetaConfig, discoveredContext int, discoveredKnown bool) resolvedModelMeta { var out resolvedModelMeta + out.Vision = configuredVision(provider, model, cfg) override := lookupModelMetaConfig(provider, model, cfg) builtin, builtinOK := builtinModelMetaTable[model] @@ -190,15 +193,25 @@ func lookupModelMetaConfig(provider, model string, cfg map[string]*ModelMetaConf // deployments keep today's behaviour. The exact "provider/model" key wins // over the bare key only when it sets Vision itself. func modelVisionCapable(provider, model string, cfg map[string]*ModelMetaConfig) bool { - if v, ok := cfg[provider+"/"+model]; ok && v != nil && v.Vision != nil { - return *v.Vision - } - if v, ok := cfg[model]; ok && v != nil && v.Vision != nil { - return *v.Vision + if v := configuredVision(provider, model, cfg); v != nil { + return *v } return true } +// configuredVision returns the explicitly configured Vision value, or nil +// when no applicable modelMeta entry sets it. Exact "provider/model" wins +// over the bare key only when it sets Vision itself. +func configuredVision(provider, model string, cfg map[string]*ModelMetaConfig) *bool { + if v, ok := cfg[provider+"/"+model]; ok && v != nil && v.Vision != nil { + return v.Vision + } + if v, ok := cfg[model]; ok && v != nil && v.Vision != nil { + return v.Vision + } + return nil +} + // resolveAliasModelMeta applies modelMeta's alias-inheritance rule // (feature v0.23): an alias inherits its target's fully resolved // metadata (resolveModelMeta against the alias's resolved provider/ diff --git a/modelmeta_test.go b/modelmeta_test.go index b8a11b2..a747707 100644 --- a/modelmeta_test.go +++ b/modelmeta_test.go @@ -509,3 +509,36 @@ func TestModelMetaConfig_VisionJSONRoundTrip(t *testing.T) { t.Errorf("unset vision must be omitted from JSON, got %s", out) } } + +func TestAdminModelMetaView_Vision(t *testing.T) { + t.Parallel() + yes, no := true, false + cfg := map[string]*ModelMetaConfig{ + "p/seen": {Vision: &yes}, + "p/blind": {Vision: &no}, + "p/other": {ContextTokens: 1000}, + } + cases := []struct { + want *bool + model string + wantJSON bool + }{ + {&yes, "seen", true}, + {&no, "blind", true}, + {nil, "other", false}, + {nil, "absent", false}, + } + for _, c := range cases { + view := buildAdminModelMetaView(resolveModelMeta("p", c.model, cfg, 0, false)) + if (view.Vision == nil) != (c.want == nil) || (c.want != nil && *view.Vision != *c.want) { + t.Fatalf("%s: Vision = %v, want %v", c.model, view.Vision, c.want) + } + raw, err := json.Marshal(view) + if err != nil { + t.Fatal(err) + } + if got := strings.Contains(string(raw), `"vision"`); got != c.wantJSON { + t.Fatalf("%s: json %s, vision present = %v, want %v", c.model, raw, got, c.wantJSON) + } + } +}