Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/model-pool-keep-members.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### English

- A dispatch-group seat lists every model its provider publishes, including a name another group already uses on a different provider.

### 中文

- 调度组座位会列出该供应商公布的全部模型,包括其他调度组已经在别的供应商上用过的同名模型。
3 changes: 3 additions & 0 deletions frontend/src/api/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export type ModelsResponse = {
type ModelFetchOptions = {
page?: number
pageSize?: number
/** Keep provider rows whose id is already an aggregation member. */
keepMembers?: boolean
}

type ModelsMemoryEntry = {
Expand All @@ -82,6 +84,7 @@ export function fetchModels(accountId?: string, refresh = false, view?: 'regiona
if (view) q.set('view', view)
if (options?.page != null) q.set('page', String(options.page))
if (options?.pageSize != null) q.set('page_size', String(options.pageSize))
if (options?.keepMembers) q.set('keep_members', '1')
const query = q.toString()
return api<ModelsResponse>(`/api/models${query ? `?${query}` : ''}`)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/ModelPoolEditorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function ModelPoolEditorPage() {
const [aggResult, providerResult, modelResult, accountResult] = await Promise.all([
fetchAggregations(),
fetchProviders(),
fetchModels(undefined, false, 'regional'),
fetchModels(undefined, false, 'regional', { keepMembers: true }),
fetchAccounts(),
])
if (cancelled) return
Expand Down
5 changes: 4 additions & 1 deletion internal/console/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func (h *Handler) HandleModelsAPI(w http.ResponseWriter, r *http.Request) {
return
}
data := h.decorateModels(r.Context(), h.filterModels(r, models))
if h.crossProviderPoolOn() && h.Control != nil {
// keep_members is the dispatch-group editor. The public list hides every
// provider row whose id is already an aggregation member, so a seat could
// not pick that same id on a different provider. The editor still needs it.
if h.crossProviderPoolOn() && h.Control != nil && r.URL.Query().Get("keep_members") != "1" {
data = control.MergeAggregationModels(r.Context(), h.Control.Aggregations, data)
}
if !h.crossProviderPoolOn() {
Expand Down
78 changes: 78 additions & 0 deletions internal/console/models_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package console

import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"sync/atomic"
"testing"

"github.com/caigee-cmd/cli2api/internal/accounts"
"github.com/caigee-cmd/cli2api/internal/control"
)

Expand Down Expand Up @@ -113,6 +115,82 @@ func TestHandleModelsAPIDefaultRemainsUnpaginated(t *testing.T) {
}
}

func TestHandleModelsAPIKeepMembersRetainsOtherProviders(t *testing.T) {
models := []map[string]any{
{"id": "glm-5.3-flash", "provider": "workbuddy", "region": "cn"},
{"id": "glm-5.3-flash", "provider": "opencode", "region": "go"},
{"id": "hy3", "provider": "opencode", "region": "go"},
}
pool := &atomic.Bool{}
pool.Store(true)
h := &Handler{
CrossProviderPool: pool,
Control: &control.Services{Aggregations: control.NewAggregations(memberHideStore{list: []accounts.Aggregation{{
ID: "glm-53-flash", Name: "glm-53-flash", Enabled: true,
Members: []accounts.AggregationMember{{Provider: "workbuddy", Model: "glm-5.3-flash"}},
}}})},
FetchDisplayModels: func(bool, string, control.CatalogMode) ([]map[string]any, error) {
return models, nil
},
}
hidden := modelIDs(t, h, "/api/models?view=regional")
if containsModel(hidden, "opencode", "glm-5.3-flash") || containsModel(hidden, "workbuddy", "glm-5.3-flash") {
t.Fatalf("public list hid neither provider row: %#v", hidden)
}
if !containsModel(hidden, "opencode", "hy3") {
t.Fatalf("unrelated model missing: %#v", hidden)
}
kept := modelIDs(t, h, "/api/models?view=regional&keep_members=1")
if !containsModel(kept, "opencode", "glm-5.3-flash") || !containsModel(kept, "workbuddy", "glm-5.3-flash") || !containsModel(kept, "opencode", "hy3") {
t.Fatalf("editor list = %#v", kept)
}
}

func modelIDs(t *testing.T, h *Handler, path string) []map[string]any {
t.Helper()
rec := httptest.NewRecorder()
h.HandleModelsAPI(rec, httptest.NewRequest(http.MethodGet, path, nil))
if rec.Code != http.StatusOK {
t.Fatalf("status = %d body = %s", rec.Code, rec.Body.String())
}
var body struct {
Data []map[string]any `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
return body.Data
}

func containsModel(models []map[string]any, provider, id string) bool {
for _, model := range models {
gotID, _ := model["id"].(string)
gotProvider, _ := model["provider"].(string)
if gotID == id && gotProvider == provider {
return true
}
}
return false
}

type memberHideStore struct {
list []accounts.Aggregation
}

func (s memberHideStore) ListAggregations(context.Context) ([]accounts.Aggregation, error) {
return s.list, nil
}
func (s memberHideStore) InsertAggregation(context.Context, accounts.Aggregation) (accounts.Aggregation, error) {
return accounts.Aggregation{}, nil
}
func (s memberHideStore) SaveAggregation(context.Context, accounts.Aggregation) (accounts.Aggregation, error) {
return accounts.Aggregation{}, nil
}
func (s memberHideStore) GetAggregation(context.Context, string) (accounts.Aggregation, error) {
return accounts.Aggregation{}, accounts.ErrAggregationNotFound
}
func (s memberHideStore) DeleteAggregation(context.Context, string) error { return nil }

func TestHandleModelsAPIRejectsInvalidPagination(t *testing.T) {
h := &Handler{FetchDisplayModels: func(bool, string, control.CatalogMode) ([]map[string]any, error) {
return []map[string]any{{"id": "model"}}, nil
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading