diff --git a/internal/logic/billing/scope.go b/internal/logic/billing/scope.go index 02b5716..34bef8b 100644 --- a/internal/logic/billing/scope.go +++ b/internal/logic/billing/scope.go @@ -25,13 +25,13 @@ func CheckScope(scope string, relayMode string) bool { case ScopeReadOnly: // read_only 仅允许 GET /models return relayMode == "" - case ScopeChatOnly: + case ScopeChatOnly, "chat": return relayMode == "chat_completions" || relayMode == "completions" || relayMode == "claude_messages" - case ScopeEmbeddingsOnly: + case ScopeEmbeddingsOnly, "embedding": return relayMode == "embeddings" - case ScopeImagesOnly: + case ScopeImagesOnly, "image": return relayMode == "images_generations" - case ScopeAudioOnly: + case ScopeAudioOnly, "audio": return relayMode == "audio" || relayMode == "tts" || relayMode == "stt" default: // custom scope: 以逗号分隔的模式列表 diff --git a/internal/logic/billing/scope_test.go b/internal/logic/billing/scope_test.go index cda6fad..948b38a 100644 --- a/internal/logic/billing/scope_test.go +++ b/internal/logic/billing/scope_test.go @@ -27,6 +27,18 @@ func TestCheckScope(t *testing.T) { {"read_only allows empty mode (models GET)", ScopeReadOnly, "", true}, {"audio_only allows audio", ScopeAudioOnly, "audio", true}, {"audio_only denies chat", ScopeAudioOnly, "chat_completions", false}, + // short alias scope names (sent by frontend) + {"chat alias allows chat_completions", "chat", "chat_completions", true}, + {"chat alias allows completions", "chat", "completions", true}, + {"chat alias allows claude_messages", "chat", "claude_messages", true}, + {"chat alias denies embeddings", "chat", "embeddings", false}, + {"embedding alias allows embeddings", "embedding", "embeddings", true}, + {"embedding alias denies chat", "embedding", "chat_completions", false}, + {"image alias allows images_generations", "image", "images_generations", true}, + {"image alias denies chat", "image", "chat_completions", false}, + {"audio alias allows audio", "audio", "audio", true}, + {"audio alias allows tts", "audio", "tts", true}, + {"audio alias denies chat", "audio", "chat_completions", false}, } for _, tt := range tests { diff --git a/internal/logic/relay/provider.go b/internal/logic/relay/provider.go index d2a4128..857e9a0 100644 --- a/internal/logic/relay/provider.go +++ b/internal/logic/relay/provider.go @@ -402,7 +402,8 @@ func (p *DataProviderImpl) RecordAudit(ctx context.Context, record *common.Audit tntReq, tntResp = truncateBody(tntReq, maxBodyLen), truncateBody(tntResp, maxBodyLen) // 仅审计级别为 all 时记录请求头和响应头 - var requestHeadersJSON, responseHeadersJSON string + requestHeadersJSON := "null" + responseHeadersJSON := "null" if globalLevel == lcommon.AuditLevelFull { if record.RequestHeaders != nil { b, _ := json.Marshal(record.RequestHeaders) @@ -415,7 +416,7 @@ func (p *DataProviderImpl) RecordAudit(ctx context.Context, record *common.Audit } // 序列化转发路径追踪 - var forwardingTraceJSON string + forwardingTraceJSON := "null" if record.ForwardingTrace != nil { if b, err := json.Marshal(record.ForwardingTrace); err == nil { forwardingTraceJSON = string(b)