Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
package service
|
||||
|
||||
import "strings"
|
||||
|
||||
const featureKeyCodexImageGenerationBridge = "codex_image_generation_bridge"
|
||||
|
||||
const (
|
||||
featureKeyCodexImageGenerationExplicitToolPolicy = "codex_image_generation_explicit_tool_policy"
|
||||
|
||||
codexImageGenerationExplicitToolPolicyAllow = "allow"
|
||||
codexImageGenerationExplicitToolPolicyStrip = "strip"
|
||||
)
|
||||
|
||||
func boolOverridePtr(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
func boolOverrideFromMap(values map[string]any, keys ...string) *bool {
|
||||
if values == nil {
|
||||
return nil
|
||||
}
|
||||
for _, key := range keys {
|
||||
if v, ok := values[key].(bool); ok {
|
||||
return boolOverridePtr(v)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func stringOverrideFromMap(values map[string]any, keys ...string) (string, bool) {
|
||||
if values == nil {
|
||||
return "", false
|
||||
}
|
||||
for _, key := range keys {
|
||||
if v, ok := values[key].(string); ok {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func normalizeCodexImageGenerationExplicitToolPolicy(value string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case codexImageGenerationExplicitToolPolicyStrip, "remove", "drop":
|
||||
return codexImageGenerationExplicitToolPolicyStrip
|
||||
default:
|
||||
return codexImageGenerationExplicitToolPolicyAllow
|
||||
}
|
||||
}
|
||||
|
||||
func platformBoolOverride(values map[string]any, key string, platform string) *bool {
|
||||
if values == nil {
|
||||
return nil
|
||||
}
|
||||
if v, ok := values[key].(bool); ok {
|
||||
return boolOverridePtr(v)
|
||||
}
|
||||
raw, ok := values[key].(map[string]any)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
platform = strings.TrimSpace(platform)
|
||||
if platform == "" {
|
||||
return nil
|
||||
}
|
||||
if v, ok := raw[platform].(bool); ok {
|
||||
return boolOverridePtr(v)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CodexImageGenerationBridgeOverride returns the channel-level override for Codex
|
||||
// image_generation bridge injection. Nil means follow the global/account policy.
|
||||
func (c *Channel) CodexImageGenerationBridgeOverride(platform string) *bool {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return platformBoolOverride(c.FeaturesConfig, featureKeyCodexImageGenerationBridge, platform)
|
||||
}
|
||||
|
||||
// CodexImageGenerationBridgeOverride returns the account-level override for Codex
|
||||
// image_generation bridge injection. Nil means follow the channel/global policy.
|
||||
func (a *Account) CodexImageGenerationBridgeOverride() *bool {
|
||||
if a == nil || a.Platform != PlatformOpenAI || a.Extra == nil {
|
||||
return nil
|
||||
}
|
||||
if override := boolOverrideFromMap(a.Extra, featureKeyCodexImageGenerationBridge, "codex_image_generation_bridge_enabled"); override != nil {
|
||||
return override
|
||||
}
|
||||
openaiConfig, _ := a.Extra[PlatformOpenAI].(map[string]any)
|
||||
return boolOverrideFromMap(openaiConfig, featureKeyCodexImageGenerationBridge, "codex_image_generation_bridge_enabled")
|
||||
}
|
||||
|
||||
// CodexImageGenerationExplicitToolPolicy returns the account-level policy for
|
||||
// client-provided Codex /responses image_generation tools. Unknown or unset
|
||||
// values default to allow to preserve existing behavior.
|
||||
func (a *Account) CodexImageGenerationExplicitToolPolicy() string {
|
||||
if a == nil || a.Platform != PlatformOpenAI || a.Extra == nil {
|
||||
return codexImageGenerationExplicitToolPolicyAllow
|
||||
}
|
||||
if policy, ok := stringOverrideFromMap(a.Extra, featureKeyCodexImageGenerationExplicitToolPolicy); ok {
|
||||
return normalizeCodexImageGenerationExplicitToolPolicy(policy)
|
||||
}
|
||||
openaiConfig, _ := a.Extra[PlatformOpenAI].(map[string]any)
|
||||
if policy, ok := stringOverrideFromMap(openaiConfig, featureKeyCodexImageGenerationExplicitToolPolicy); ok {
|
||||
return normalizeCodexImageGenerationExplicitToolPolicy(policy)
|
||||
}
|
||||
return codexImageGenerationExplicitToolPolicyAllow
|
||||
}
|
||||
Reference in New Issue
Block a user