fix(ark-assets): 方舟素材库 - 阻止图片 Agent Plan 误用 asset:// 可信素材
Agent Plan Seedream 与 Seedance 共用 /api/plan/v3,BaseURL 判断会把图片生成误判为视频可信素材路径。仅视频 mode/协议才同步或提交 asset://。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
b6bae4f957
commit
77f2c9d52c
7 files changed
+172
-10
No files matched your search
@@ -47,7 +47,8 @@ func withoutProviderAnalytics(ctx context.Context) context.Context {
|
||||
}
|
||||
|
||||
func (s *Service) prepareArkPrivateAssetReferences(ctx context.Context, userID string, input *canvasGenerationInput) error {
|
||||
if input == nil || !isArkPrivateAssetVideoConfig(input.Config) || !parseBool(input.Config.ArkPrivateAssetUpload, true) {
|
||||
// 可信素材 asset:// 仅方舟视频协议支持;Agent Plan Seedream 等图片渠道不能上传或改写。
|
||||
if input == nil || input.Mode != "video" || !isArkPrivateAssetVideoConfig(input.Config) || !parseBool(input.Config.ArkPrivateAssetUpload, true) {
|
||||
return nil
|
||||
}
|
||||
hasOwnedReference := false
|
||||
@@ -107,7 +108,12 @@ func (s *Service) prepareArkPrivateAssetReferences(ctx context.Context, userID s
|
||||
}
|
||||
|
||||
func isArkPrivateAssetVideoConfig(config providerConfig) bool {
|
||||
return config.InterfaceType == string(model.ChannelInterfaceVolcengineArkVideo) || isArkPlanVideoConfig(config)
|
||||
iface := strings.TrimSpace(config.InterfaceType)
|
||||
// Agent Plan 图片与视频共用 /api/plan/v3;图片协议不得进入可信素材同步。
|
||||
if iface == string(model.ChannelInterfaceVolcengineArkImage) || iface == "volcengine-ark-agent-plan-image" {
|
||||
return false
|
||||
}
|
||||
return iface == string(model.ChannelInterfaceVolcengineArkVideo) || iface == "volcengine-ark-agent-plan-video" || isArkPlanVideoConfig(config)
|
||||
}
|
||||
|
||||
func arkPrivateAssetAutomaticSyncEnabled(setting arkPrivateAssetSettingValue) (bool, error) {
|
||||
|
||||
@@ -2213,6 +2213,48 @@ func TestArkPlanConfigStaysSeparateFromSeedanceVideosEndpoint(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestArkPlanImageConfigDoesNotUseVideoAssetPath(t *testing.T) {
|
||||
imageConfig := providerConfig{
|
||||
InterfaceType: "volcengine-ark-agent-plan-image",
|
||||
BaseURL: "https://ark.cn-beijing.volces.com/api/plan/v3",
|
||||
Model: "doubao-seedream-4-0-250828",
|
||||
}
|
||||
if isArkPlanVideoConfig(imageConfig) {
|
||||
t.Fatal("agent plan image must not match isArkPlanVideoConfig")
|
||||
}
|
||||
if isArkPrivateAssetVideoConfig(imageConfig) {
|
||||
t.Fatal("agent plan image must not trigger ark private asset sync")
|
||||
}
|
||||
if isSeedanceVideoConfig(imageConfig) {
|
||||
t.Fatal("agent plan image must not match isSeedanceVideoConfig")
|
||||
}
|
||||
|
||||
videoConfig := providerConfig{
|
||||
InterfaceType: "volcengine-ark-agent-plan-video",
|
||||
BaseURL: "https://ark.cn-beijing.volces.com/api/plan/v3",
|
||||
Model: "doubao-seedance-1-5-pro-251215",
|
||||
}
|
||||
if !isArkPlanVideoConfig(videoConfig) || !isArkPrivateAssetVideoConfig(videoConfig) {
|
||||
t.Fatal("agent plan video should keep video/asset path")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareArkPrivateAssetReferencesSkipsImageMode(t *testing.T) {
|
||||
svc := &Service{}
|
||||
err := svc.prepareArkPrivateAssetReferences(context.Background(), "user-1", &canvasGenerationInput{
|
||||
Mode: "image",
|
||||
Config: providerConfig{
|
||||
InterfaceType: "volcengine-ark-agent-plan-image",
|
||||
BaseURL: "https://ark.cn-beijing.volces.com/api/plan/v3",
|
||||
ArkPrivateAssetUpload: "true",
|
||||
},
|
||||
ReferenceImages: []providerMedia{{StorageKey: "resource:res-1", URL: "https://example.com/ref.png"}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("prepareArkPrivateAssetReferences() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVolcengineArkVideoProtocolUsesContentTaskAndDownloadsResult(t *testing.T) {
|
||||
t.Setenv("CANVAS_ALLOW_PRIVATE_UPSTREAMS", "true")
|
||||
paths := make([]string, 0, 3)
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"infinite-canvas/backend/internal/model"
|
||||
)
|
||||
|
||||
func isPublicMediaURL(value string) bool {
|
||||
@@ -13,8 +15,8 @@ func isPublicMediaURL(value string) bool {
|
||||
}
|
||||
|
||||
func isSeedanceVideoConfig(config providerConfig) bool {
|
||||
model := strings.ToLower(config.Model)
|
||||
return strings.Contains(model, "seedance") || strings.Contains(model, "doubao-seedance") || isArkPlanVideoConfig(config)
|
||||
modelName := strings.ToLower(config.Model)
|
||||
return strings.Contains(modelName, "seedance") || strings.Contains(modelName, "doubao-seedance") || isArkPlanVideoConfig(config)
|
||||
}
|
||||
|
||||
func isGrokVideoConfig(config providerConfig) bool {
|
||||
@@ -22,7 +24,15 @@ func isGrokVideoConfig(config providerConfig) bool {
|
||||
}
|
||||
|
||||
func isArkPlanVideoConfig(config providerConfig) bool {
|
||||
return strings.Contains(strings.ToLower(config.BaseURL), "/api/plan/v3")
|
||||
if !strings.Contains(strings.ToLower(config.BaseURL), "/api/plan/v3") {
|
||||
return false
|
||||
}
|
||||
// Agent Plan 图片与视频共用 /api/plan/v3;按协议排除图片,避免 Seedream 误走视频/可信素材路径。
|
||||
iface := strings.TrimSpace(config.InterfaceType)
|
||||
if iface == string(model.ChannelInterfaceVolcengineArkImage) || iface == "volcengine-ark-agent-plan-image" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func normalizeImageQuality(value string) string {
|
||||
|
||||
Reference in new issue
Block a user