diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 9cd64f31..e099cd02 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -163,7 +163,11 @@ func magpieProviderJSON(shape string) any { var ms []map[string]any for _, m := range models { // reasoning lets Pi offer its thinking levels for the model - ms = append(ms, map[string]any{"id": m.ID, "name": m.Name, "reasoning": len(m.Efforts) > 0}) + e := map[string]any{"id": m.ID, "name": m.Name, "reasoning": len(m.Efforts) > 0} + if levels := piThinkingLevels(m.Efforts); levels != nil { + e["thinkingLevelMap"] = levels + } + ms = append(ms, e) } if ms == nil { ms = []map[string]any{} @@ -173,6 +177,22 @@ func magpieProviderJSON(shape string) any { return nil } +// piThinkingLevels is the thinkingLevelMap for a model's efforts. Pi offers +// xhigh and max only for models that map them, so without it a model whose +// top level is max stopped at high in Pi. +func piThinkingLevels(efforts []string) map[string]any { + var levels map[string]any + for _, e := range efforts { + if e == "xhigh" || e == "max" { + if levels == nil { + levels = map[string]any{} + } + levels[e] = e + } + } + return levels +} + func opencode(home, cfg string) *Agent { dir := filepath.Join(cfg, "opencode") path := filepath.Join(dir, "opencode.json") diff --git a/internal/agent/pi_test.go b/internal/agent/pi_test.go new file mode 100644 index 00000000..84a78d1e --- /dev/null +++ b/internal/agent/pi_test.go @@ -0,0 +1,23 @@ +package agent + +import ( + "reflect" + "testing" +) + +func TestPiThinkingLevels(t *testing.T) { + for _, c := range []struct { + efforts []string + want map[string]any + }{ + {[]string{"low", "high", "max"}, map[string]any{"max": "max"}}, + {[]string{"low", "medium", "high", "xhigh"}, map[string]any{"xhigh": "xhigh"}}, + {[]string{"none", "low", "high", "xhigh", "max"}, map[string]any{"xhigh": "xhigh", "max": "max"}}, + {[]string{"low", "medium", "high"}, nil}, + {nil, nil}, + } { + if got := piThinkingLevels(c.efforts); !reflect.DeepEqual(got, c.want) { + t.Errorf("%v: got %v, want %v", c.efforts, got, c.want) + } + } +}