Skip to content

Commit cc26204

Browse files
committed
feat(ai): sync gateway providers and model discovery
Add provider account types and protocol-aware model discovery, and replace predefined models with editable model pools. Align provider icons with AI Gateway, preserve international Coding Plan restrictions, and filter account counts consistently with selectable accounts.
1 parent e8bcae0 commit cc26204

57 files changed

Lines changed: 3599 additions & 2664 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎agent/app/api/v2/agents.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ func (b *BaseApi) CreateAgentAccountModel(c *gin.Context) {
562562
}
563563

564564
// @Tags AI
565-
// @Summary Update model service model
565+
// @Summary Update model service models
566566
// @Accept json
567567
// @Param request body dto.AgentAccountModelUpdateReq true "request"
568568
// @Success 200

‎agent/app/dto/agents.go‎

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,13 @@ type AgentAccountVerifyModelUpdateReq struct {
317317
}
318318

319319
type AgentAccountModelDiscoverReq struct {
320-
Provider string `json:"provider" validate:"required"`
321-
BaseURL string `json:"baseURL" validate:"required"`
322-
APIKey string `json:"apiKey" validate:"required"`
323-
APIType string `json:"apiType" validate:"required"`
320+
AccountID uint `json:"accountId"`
321+
AccountType string `json:"accountType"`
322+
Provider string `json:"provider" validate:"required_without=AccountID"`
323+
BaseURL string `json:"baseURL" validate:"required_without=AccountID"`
324+
APIKey string `json:"apiKey" validate:"required_without=AccountID"`
325+
APIType string `json:"apiType" validate:"required_without=AccountID"`
326+
AuthMode string `json:"authMode"`
324327
}
325328

326329
type AgentAccountModelCreateReq struct {
@@ -330,8 +333,9 @@ type AgentAccountModelCreateReq struct {
330333
}
331334

332335
type AgentAccountModelUpdateReq struct {
333-
AccountID uint `json:"accountId" validate:"required"`
334-
Model AgentAccountModel `json:"model" validate:"required"`
336+
AccountID uint `json:"accountId" validate:"required"`
337+
Models []AgentAccountModel `json:"models" validate:"required,min=1"`
338+
VerifyModel string `json:"verifyModel"`
335339
}
336340

337341
type AgentAccountModelDeleteReq struct {
@@ -341,6 +345,7 @@ type AgentAccountModelDeleteReq struct {
341345
}
342346

343347
type AgentAccountCreateReq struct {
348+
AccountType string `json:"accountType"`
344349
Provider string `json:"provider" validate:"required"`
345350
Name string `json:"name" validate:"required"`
346351
APIKey string `json:"apiKey" validate:"required"`
@@ -355,6 +360,7 @@ type AgentAccountCreateReq struct {
355360
}
356361

357362
type AgentAccountUpdateReq struct {
363+
AccountType string `json:"accountType"`
358364
ID uint `json:"id" validate:"required"`
359365
Name string `json:"name" validate:"required"`
360366
APIKey string `json:"apiKey" validate:"required"`
@@ -385,17 +391,20 @@ type AgentAccountDeleteReq struct {
385391

386392
type AgentAccountSearch struct {
387393
PageInfo
388-
Provider string `json:"provider"`
389-
APIType string `json:"apiType"`
390-
TextOnly bool `json:"textOnly"`
391-
Name string `json:"name"`
394+
ExcludeCodingPlanProviders []string `json:"excludeCodingPlanProviders"`
395+
Provider string `json:"provider"`
396+
APIType string `json:"apiType"`
397+
TextOnly bool `json:"textOnly"`
398+
Name string `json:"name"`
392399
}
393400

394401
type AgentAccountProviderCountReq struct {
395-
Providers []string `json:"providers"`
402+
ExcludeCodingPlanProviders []string `json:"excludeCodingPlanProviders"`
403+
Providers []string `json:"providers"`
396404
}
397405

398406
type AgentAccountInfo struct {
407+
AccountType string `json:"accountType"`
399408
AppInstallID uint `json:"appInstallId"`
400409
ID uint `json:"id"`
401410
MasterAccountID uint `json:"masterAccountId"`
@@ -433,13 +442,14 @@ type ProviderAPIInfo struct {
433442
}
434443

435444
type ProviderInfo struct {
436-
Sort uint `json:"-"`
437-
Provider string `json:"provider"`
438-
DisplayName string `json:"displayName"`
439-
BaseURL string `json:"baseUrl"`
440-
DefaultAPIType string `json:"defaultApiType"`
441-
APITypes []ProviderAPIInfo `json:"apiTypes"`
442-
Models []ProviderModelInfo `json:"models"`
445+
AccountTypes []ProviderAccountTypeInfo `json:"accountTypes"`
446+
Sort uint `json:"-"`
447+
Provider string `json:"provider"`
448+
DisplayName string `json:"displayName"`
449+
BaseURL string `json:"baseUrl"`
450+
DefaultAPIType string `json:"defaultApiType"`
451+
APITypes []ProviderAPIInfo `json:"apiTypes"`
452+
Models []ProviderModelInfo `json:"models"`
443453
}
444454

445455
type AgentFeishuConfigReq struct {
@@ -852,3 +862,8 @@ type AgentSkillUninstallReq struct {
852862
AgentID uint `json:"agentId" validate:"required"`
853863
Name string `json:"name" validate:"required"`
854864
}
865+
866+
type ProviderAccountTypeInfo struct {
867+
Key string `json:"key"`
868+
APITypes []ProviderAPIInfo `json:"apiTypes"`
869+
}

‎agent/app/model/agent_account.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "time"
44

55
type AgentAccount struct {
66
BaseModel
7+
AccountType string `json:"accountType"`
78
AppInstallID uint `json:"appInstallId"`
89
Provider string `json:"provider"`
910
Name string `json:"name"`
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package provider
2+
3+
import (
4+
"strings"
5+
)
6+
7+
type AccountTypePreset struct {
8+
Key string `json:"key"`
9+
APIConfigs []APIConfig `json:"apiTypes"`
10+
}
11+
12+
func FindAccountType(provider, accountType string) (AccountTypePreset, bool) {
13+
meta, ok := catalog[provider]
14+
if !ok || len(meta.AccountTypes) == 0 {
15+
return AccountTypePreset{}, false
16+
}
17+
if accountType == "" {
18+
switch provider {
19+
case "bailian", "ark", "xiaomi":
20+
accountType = "payAsYouGo"
21+
case "kimi", "zai":
22+
accountType = "chinaApi"
23+
default:
24+
return meta.AccountTypes[0], true
25+
}
26+
}
27+
for _, item := range meta.AccountTypes {
28+
if item.Key == accountType {
29+
return item, true
30+
}
31+
}
32+
return AccountTypePreset{}, false
33+
}
34+
35+
func Purpose(apiType string) string {
36+
switch apiType {
37+
case "openai-completions", "openai-responses", "anthropic-messages", "gemini-generate-content":
38+
return "text"
39+
case "openai-embeddings":
40+
return "embedding"
41+
case "rerank":
42+
return "rerank"
43+
}
44+
if strings.HasSuffix(apiType, "-images") {
45+
return "image"
46+
}
47+
if strings.HasSuffix(apiType, "-transcriptions") {
48+
return "transcription"
49+
}
50+
if strings.HasSuffix(apiType, "-speech") {
51+
return "speech"
52+
}
53+
return ""
54+
}

0 commit comments

Comments
 (0)