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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ docs/*
!docs/ASYNC_IMAGE_TASKS.md
!docs/BATCH_IMAGE_MVP.md
!docs/COMPOSITE_GROUPS.md
!docs/openai-bps.md
!docs/openai-bps-sources.md
!docs/PLUGIN_DEVELOPMENT.md
!docs/channel-monitor-v2-safe-defaults.md
!docs/CODEX_PROBE_TEMPLATE.md
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.4
1.1.5
3 changes: 2 additions & 1 deletion backend/ent/channelmonitor/channelmonitor.go

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

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

4 changes: 2 additions & 2 deletions backend/ent/migrate/schema.go

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

2 changes: 1 addition & 1 deletion backend/ent/schema/channel_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (ChannelMonitor) Fields() []ent.Field {
MaxLen(100),
field.Enum("provider").
Values("openai", "anthropic", "gemini", "grok",
"antigravity", "kimi", "zhipu", "deepseek", "minimax", "opencode_go"),
"antigravity", "kimi", "zhipu", "deepseek", "minimax", "opencode_go", "openai_bps"),
// check_mode: 'probe' | 'quota' | 'quota_probe'
// probe - LLM 探活(默认,原有行为)
// quota - 仅查关联账号的用量/余额(零 LLM 成本;endpoint/api_key 可空)
Expand Down
2 changes: 1 addition & 1 deletion backend/ent/schema/channel_monitor_request_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (ChannelMonitorRequestTemplate) Fields() []ent.Field {
MaxLen(100),
field.Enum("provider").
Values("openai", "anthropic", "gemini", "grok",
"antigravity", "kimi", "zhipu", "deepseek", "minimax", "opencode_go"),
"antigravity", "kimi", "zhipu", "deepseek", "minimax", "opencode_go", "openai_bps"),
field.String("api_mode").
Default("chat_completions").
MaxLen(32).
Expand Down
2 changes: 1 addition & 1 deletion backend/ent/schema/user_platform_quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (UserPlatformQuota) Fields() []ent.Field {
// 此处为 ent 构建期约束,需与 service.AllowedQuotaPlatforms 保持同步。
switch s {
case "anthropic", "openai", "gemini", "antigravity", "grok",
"kimi", "zhipu", "deepseek", "minimax", "opencode_go":
"kimi", "zhipu", "deepseek", "minimax", "opencode_go", "openai_bps":
return nil
default:
return fmt.Errorf("platform %q is not allowed", s)
Expand Down
1 change: 1 addition & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/redis/go-redis/v9 v9.22.0
github.com/refraction-networking/utls v1.8.2
github.com/robfig/cron/v3 v3.0.1
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/shirou/gopsutil/v4 v4.25.6
github.com/shopspring/decimal v1.4.0
github.com/smartwalle/alipay/v3 v3.2.29
Expand Down
2 changes: 2 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/shirou/gopsutil/v4 v4.25.6 h1:kLysI2JsKorfaFPcYmcJqbzROzsBWEOAtw6A7dIfqXs=
Expand Down
1 change: 1 addition & 0 deletions backend/internal/domain/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
const (
PlatformAnthropic = "anthropic"
PlatformOpenAI = "openai"
PlatformOpenAIBPS = "openai_bps"
PlatformGemini = "gemini"
PlatformAntigravity = "antigravity"
PlatformGrok = "grok"
Expand Down
23 changes: 23 additions & 0 deletions backend/internal/handler/admin/account_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,9 @@ func (h *AccountHandler) PreviewFromCRS(c *gin.Context) {
// refreshSingleAccount refreshes credentials for a single OAuth account.
// Returns (updatedAccount, warning, error) where warning is used for Antigravity ProjectIDMissing scenario.
func (h *AccountHandler) refreshSingleAccount(ctx context.Context, account *service.Account) (*service.Account, string, error) {
if account.IsOpenAIBPS() {
return nil, "", infraerrors.BadRequest("BPS_MANUAL_TOKEN_ONLY", "Replace access_token in the BPS account settings; automatic refresh is unsupported")
}
if !account.IsOAuth() {
return nil, "", infraerrors.BadRequest("NOT_OAUTH", "cannot refresh non-OAuth account")
}
Expand Down Expand Up @@ -1666,6 +1669,10 @@ func (h *AccountHandler) ApplyOAuthCredentials(c *gin.Context) {
response.NotFound(c, "Account not found")
return
}
if existing.IsOpenAIBPS() {
response.BadRequest(c, "Replace access_token through the BPS account editor")
return
}
if !existing.IsOAuth() {
response.ErrorFrom(c, infraerrors.BadRequest("NOT_OAUTH", "cannot apply oauth credentials to non-OAuth account"))
return
Expand Down Expand Up @@ -2853,6 +2860,22 @@ func (h *AccountHandler) GetAvailableModels(c *gin.Context) {
return
}

if account.IsOpenAIBPS() {
ids := service.OpenAIBPSDefaultModels()
if mapping := account.GetModelMapping(); len(mapping) > 0 {
ids = make([]string, 0, len(mapping))
for id := range mapping {
ids = append(ids, id)
}
}
sort.Strings(ids)
models := make([]openai.Model, 0, len(ids))
for _, id := range ids {
models = append(models, openai.Model{ID: id, Object: "model", Type: "model", DisplayName: id})
}
response.Success(c, models)
return
}
// Handle OpenAI accounts
if account.IsOpenAI() {
// Prefer the shared, account-keyed upstream catalog. If discovery fails,
Expand Down
4 changes: 2 additions & 2 deletions backend/internal/handler/admin/channel_monitor_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewChannelMonitorHandler(monitorService *service.ChannelMonitorService) *Ch

type channelMonitorCreateRequest struct {
Name string `json:"name" binding:"required,max=100"`
Provider string `json:"provider" binding:"required,oneof=openai anthropic gemini grok antigravity kimi zhipu deepseek minimax opencode_go"`
Provider string `json:"provider" binding:"required,oneof=openai anthropic gemini grok antigravity kimi zhipu deepseek minimax opencode_go openai_bps"`
APIMode string `json:"api_mode" binding:"omitempty,oneof=chat_completions responses"`
Endpoint string `json:"endpoint" binding:"omitempty,max=500"`
APIKey string `json:"api_key" binding:"omitempty,max=2000"`
Expand All @@ -64,7 +64,7 @@ type channelMonitorCreateRequest struct {

type channelMonitorUpdateRequest struct {
Name *string `json:"name" binding:"omitempty,max=100"`
Provider *string `json:"provider" binding:"omitempty,oneof=openai anthropic gemini grok antigravity kimi zhipu deepseek minimax opencode_go"`
Provider *string `json:"provider" binding:"omitempty,oneof=openai anthropic gemini grok antigravity kimi zhipu deepseek minimax opencode_go openai_bps"`
APIMode *string `json:"api_mode" binding:"omitempty,oneof=chat_completions responses"`
Endpoint *string `json:"endpoint" binding:"omitempty,max=500"`
APIKey *string `json:"api_key" binding:"omitempty,max=2000"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewChannelMonitorRequestTemplateHandler(templateService *service.ChannelMon

type channelMonitorTemplateCreateRequest struct {
Name string `json:"name" binding:"required,max=100"`
Provider string `json:"provider" binding:"required,oneof=openai anthropic gemini grok"`
Provider string `json:"provider" binding:"required,oneof=openai openai_bps anthropic gemini grok"`
APIMode string `json:"api_mode" binding:"omitempty,oneof=chat_completions responses"`
Description string `json:"description" binding:"max=500"`
ExtraHeaders map[string]string `json:"extra_headers"`
Expand Down
6 changes: 3 additions & 3 deletions backend/internal/handler/admin/group_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func sanitizeUpdateGroupRequestForSimpleMode(req *UpdateGroupRequest) {
type CreateGroupRequest struct {
Name string `json:"name" binding:"required"`
Description string `json:"description"`
Platform string `json:"platform" binding:"omitempty,oneof=anthropic openai gemini antigravity grok kimi zhipu deepseek minimax opencode_go composite"`
Platform string `json:"platform" binding:"omitempty,oneof=anthropic openai gemini antigravity grok kimi zhipu deepseek minimax opencode_go openai_bps composite"`
RateMultiplier float64 `json:"rate_multiplier"`
IsExclusive bool `json:"is_exclusive"`
SubscriptionType string `json:"subscription_type" binding:"omitempty,oneof=standard subscription"`
Expand Down Expand Up @@ -258,7 +258,7 @@ type CreateGroupRequest struct {
type UpdateGroupRequest struct {
Name string `json:"name"`
Description *string `json:"description"`
Platform string `json:"platform" binding:"omitempty,oneof=anthropic openai gemini antigravity grok kimi zhipu deepseek minimax opencode_go composite"`
Platform string `json:"platform" binding:"omitempty,oneof=anthropic openai gemini antigravity grok kimi zhipu deepseek minimax opencode_go openai_bps composite"`
RateMultiplier *float64 `json:"rate_multiplier"`
IsExclusive *bool `json:"is_exclusive"`
Status string `json:"status" binding:"omitempty,oneof=active inactive"`
Expand Down Expand Up @@ -332,7 +332,7 @@ type UpdateGroupRequest struct {
type CompositeRouteRequest struct {
PublicModel string `json:"public_model" binding:"required"`
MatchType string `json:"match_type" binding:"omitempty,oneof=exact prefix"`
TargetPlatform string `json:"target_platform" binding:"required,oneof=anthropic openai gemini antigravity grok kimi zhipu deepseek minimax opencode_go"`
TargetPlatform string `json:"target_platform" binding:"required,oneof=anthropic openai gemini antigravity grok kimi zhipu deepseek minimax opencode_go openai_bps"`
UpstreamModel string `json:"upstream_model"`
Endpoint string `json:"endpoint" binding:"omitempty,oneof=any messages count_tokens responses chat_completions embeddings images gemini"`
Priority int `json:"priority"`
Expand Down
33 changes: 33 additions & 0 deletions backend/internal/handler/dto/account_mapper_redact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,36 @@ func TestAccountFromServiceShallow_NilCredentialsOmitsStatus(t *testing.T) {
require.Nil(t, got.Credentials)
require.Nil(t, got.CredentialsStatus)
}

func TestOpenAIBPSAccountDTORedactsTokenKeepsExpiry(t *testing.T) {
src := &service.Account{ID: 42, Platform: service.PlatformOpenAIBPS, Type: service.AccountTypeOAuth, Credentials: map[string]any{"access_token": "bps-test-secret", "chatgpt_account_id": "workspace", "expires_at": "2026-10-01T00:00:00Z"}}
dto := AccountFromServiceShallow(src)
require.NotContains(t, dto.Credentials, "access_token")
require.True(t, dto.CredentialsStatus["has_access_token"])
require.Equal(t, "workspace", dto.Credentials["chatgpt_account_id"])
require.Equal(t, "2026-10-01T00:00:00Z", dto.Credentials["expires_at"])
data, err := json.Marshal(dto)
require.NoError(t, err)
require.NotContains(t, string(data), "bps-test-secret")
}

func TestAccountFromServiceBPSCredentialStateFullAndLite(t *testing.T) {
now := time.Now().UTC()
source := &service.Account{ID: 42, Platform: service.PlatformOpenAIBPS, Type: service.AccountTypeOAuth, Status: service.StatusError, Schedulable: true, Credentials: map[string]any{"access_token": "private-bps-token", "chatgpt_account_id": "workspace", "expires_at": now.Add(time.Hour).Format(time.RFC3339)}, Extra: map[string]any{service.OpenAIBPSCredentialStateExtraKey: map[string]any{"status": "revoked", "error_code": "token_revoked", "observed_at": now.Format(time.RFC3339Nano), "managed_status_error": true, "credential_identity": "private-fingerprint"}}}
full := AccountFromService(source)
lite := AccountListItemFromAccount(full)
require.Equal(t, "revoked", full.BPSCredentialState.Status)
require.Equal(t, full.BPSCredentialState, lite.BPSCredentialState)
require.True(t, full.CredentialsStatus["has_access_token"])
require.NotContains(t, full.Credentials, "access_token")
require.NotContains(t, full.Extra, service.OpenAIBPSCredentialStateExtraKey)
data, err := json.Marshal(lite)
require.NoError(t, err)
require.NotContains(t, string(data), "private-bps-token")
require.NotContains(t, string(data), "private-fingerprint")
source.Extra = nil
source.Status = service.StatusActive
source.Credentials["expires_at"] = now.Add(-time.Hour).Format(time.RFC3339)
require.Equal(t, "expired", AccountFromService(source).BPSCredentialState.Status)
require.Equal(t, service.StatusActive, source.Status)
}
5 changes: 3 additions & 2 deletions backend/internal/handler/dto/mappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func AccountFromServiceShallow(a *service.Account) *Account {
Type: a.Type,
Credentials: redactedCreds,
CredentialsStatus: credsStatus,
BPSCredentialState: a.OpenAIBPSCredentialState(time.Now()),
Extra: extra,
OllamaCloudUsage: ollamaCloudUsage,
OpenCodeGoUsage: openCodeGoUsage,
Expand Down Expand Up @@ -423,7 +424,7 @@ func redactAccountManagedExtra(extra map[string]any) map[string]any {
continue
}
switch key {
case service.OllamaCloudUsageSessionExtraKey,
case service.OpenAIBPSCredentialStateExtraKey, service.OllamaCloudUsageSessionExtraKey,
service.OllamaCloudUsageAutoRefreshExtraKey,
service.OllamaCloudUsageSnapshotExtraKey,
service.OpenCodeGoUsageAutoRefreshExtraKey,
Expand Down Expand Up @@ -467,7 +468,7 @@ func AccountListItemFromAccount(a *Account) *AccountListItem {
}
return &AccountListItem{
ID: a.ID, Name: a.Name, Notes: a.Notes, Platform: a.Platform, Type: a.Type,
Credentials: a.Credentials, CredentialsStatus: a.CredentialsStatus, Extra: a.Extra,
Credentials: a.Credentials, CredentialsStatus: a.CredentialsStatus, Extra: a.Extra, BPSCredentialState: a.BPSCredentialState,
OllamaCloudUsage: a.OllamaCloudUsage, OpenCodeGoUsage: a.OpenCodeGoUsage, CodexTurnTickets: a.CodexTurnTickets, CodexTicketLatestEvent: a.CodexTicketLatestEvent,
ProxyID: a.ProxyID, ProxyFallbackOriginID: a.ProxyFallbackOriginID, ProxyFallbackOriginName: a.ProxyFallbackOriginName,
Concurrency: a.Concurrency, LoadFactor: a.LoadFactor, Priority: a.Priority, RateMultiplier: a.RateMultiplier,
Expand Down
2 changes: 2 additions & 0 deletions backend/internal/handler/dto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type Account struct {
// 的存在性通过 CredentialsStatus(has_<key>)暴露,原始值不返回前端。
Credentials map[string]any `json:"credentials"`
CredentialsStatus map[string]bool `json:"credentials_status,omitempty"`
BPSCredentialState *service.OpenAIBPSCredentialState `json:"bps_credential_state,omitempty"`
Extra map[string]any `json:"extra"`
OllamaCloudUsage *service.OllamaCloudUsageState `json:"ollama_cloud_usage,omitempty"`
OpenCodeGoUsage *service.OpenCodeGoUsageState `json:"opencode_go_usage,omitempty"`
Expand Down Expand Up @@ -341,6 +342,7 @@ type AccountListItem struct {

Credentials map[string]any `json:"credentials,omitempty"`
CredentialsStatus map[string]bool `json:"credentials_status,omitempty"`
BPSCredentialState *service.OpenAIBPSCredentialState `json:"bps_credential_state,omitempty"`
Extra map[string]any `json:"extra,omitempty"`
OllamaCloudUsage *service.OllamaCloudUsageState `json:"ollama_cloud_usage,omitempty"`
OpenCodeGoUsage *service.OpenCodeGoUsageState `json:"opencode_go_usage,omitempty"`
Expand Down
Loading
Loading