feat(image): integrate PoloX image editing workflows
Add WaveSpeed image editing and image tools plugins, canvas image editing workflows, layer selection, and Cloud Agent image tools with approval-safe transient references.
This commit is contained in:
1 parent
c7c37f2d4f
commit
6abaa7b45a
34 files changed
+2537
-75
No files matched your search
@@ -86,26 +86,28 @@ func (s *Service) cloudAgentModelIntent(userID, canvasID, arguments string) (*Mo
|
||||
}
|
||||
|
||||
type cloudAgentMediaArgs struct {
|
||||
DraftRunID string `json:"-"`
|
||||
Mode string `json:"mode"`
|
||||
Prompt string `json:"prompt"`
|
||||
LogicalModelID string `json:"logicalModelId"`
|
||||
ChannelID string `json:"channelId"`
|
||||
ChannelModelKey string `json:"channelModelKey"`
|
||||
Duration int `json:"durationSeconds"`
|
||||
Size string `json:"size"`
|
||||
Quality string `json:"quality"`
|
||||
VideoGenerateAudio *bool `json:"videoGenerateAudio"`
|
||||
SnapshotHash string `json:"snapshotHash"`
|
||||
NodeID string `json:"nodeId"`
|
||||
Title string `json:"title"`
|
||||
SourceNodeID string `json:"sourceNodeId"`
|
||||
ReferenceNodeIDs []string `json:"referenceNodeIds"`
|
||||
DraftRunID string `json:"-"`
|
||||
Mode string `json:"mode"`
|
||||
Prompt string `json:"prompt"`
|
||||
LogicalModelID string `json:"logicalModelId"`
|
||||
ChannelID string `json:"channelId"`
|
||||
ChannelModelKey string `json:"channelModelKey"`
|
||||
Duration int `json:"durationSeconds"`
|
||||
Size string `json:"size"`
|
||||
Quality string `json:"quality"`
|
||||
VideoGenerateAudio *bool `json:"videoGenerateAudio"`
|
||||
SnapshotHash string `json:"snapshotHash"`
|
||||
NodeID string `json:"nodeId"`
|
||||
Title string `json:"title"`
|
||||
SourceNodeID string `json:"sourceNodeId"`
|
||||
ReferenceNodeIDs []string `json:"referenceNodeIds"`
|
||||
ReferenceTransientIDs []string `json:"referenceTransientIds"`
|
||||
}
|
||||
|
||||
type cloudAgentMediaPlan struct {
|
||||
Args cloudAgentMediaArgs
|
||||
CallID string
|
||||
Args cloudAgentMediaArgs
|
||||
CallID string
|
||||
TransientReferences map[string]cloudAgentTransientReference
|
||||
}
|
||||
|
||||
// A resumed draft's incoming edges must describe the new approved inputs,
|
||||
@@ -206,7 +208,7 @@ func cloudAgentReference(repo *repository.Repository, userID string, node map[st
|
||||
return map[string]any{"id": node["id"], "name": node["title"], "storageKey": key, "type": resource.MimeType, "mimeType": resource.MimeType, "bytes": resource.Size, "width": resource.Width, "height": resource.Height, "durationMs": resource.DurationMs, "inputKind": descriptor.InputKind}, adapter.PayloadField, nil
|
||||
}
|
||||
|
||||
func cloudAgentMediaDocument(repo *repository.Repository, userID, canvasID string, args cloudAgentMediaArgs) (*model.CanvasProject, map[string]any, map[string]any, error) {
|
||||
func cloudAgentMediaDocument(repo *repository.Repository, userID, canvasID string, args cloudAgentMediaArgs, transient ...map[string]cloudAgentTransientReference) (*model.CanvasProject, map[string]any, map[string]any, error) {
|
||||
canvas, err := repo.CanvasProjectForUser(userID, canvasID)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
@@ -311,6 +313,20 @@ func cloudAgentMediaDocument(repo *repository.Repository, userID, canvasID strin
|
||||
list, _ := refs[payloadField].([]any)
|
||||
refs[payloadField] = append(list, ref)
|
||||
}
|
||||
if len(args.ReferenceTransientIDs) > 0 && len(transient) > 0 {
|
||||
available := map[string]cloudAgentTransientReference{}
|
||||
if len(transient) > 0 && transient[0] != nil {
|
||||
available = transient[0]
|
||||
}
|
||||
for _, id := range args.ReferenceTransientIDs {
|
||||
ref, ok := available[id]
|
||||
if !ok || !strings.HasPrefix(ref.MIMEType, "image/") || !strings.HasPrefix(ref.DataURL, "data:image/") {
|
||||
return nil, nil, nil, BadAuthRequest("临时参考图不存在、类型不匹配或已过期,请重新渲染标注")
|
||||
}
|
||||
list, _ := refs["referenceImages"].([]any)
|
||||
refs["referenceImages"] = append(list, map[string]any{"id": ref.ID, "name": ref.Name, "mimeType": ref.MIMEType, "dataUrl": ref.DataURL})
|
||||
}
|
||||
}
|
||||
return canvas, doc, refs, nil
|
||||
}
|
||||
|
||||
@@ -344,6 +360,14 @@ func validateCloudAgentMediaArgs(a cloudAgentMediaArgs, state *cloudAgentRuntime
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(a.ReferenceTransientIDs) > 4 {
|
||||
return BadAuthRequest("临时参考图最多 4 个")
|
||||
}
|
||||
for _, id := range a.ReferenceTransientIDs {
|
||||
if err := validateCloudAgentID(id, "临时参考图 ID", 120); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(a.Prompt) == "" {
|
||||
return BadAuthRequest("生成提示词不能为空")
|
||||
}
|
||||
@@ -482,7 +506,7 @@ func (s *Service) prepareCloudAgentMedia(run *model.CloudAgentExecution, state *
|
||||
if (a.LogicalModelID == "" && (a.ChannelID == "" || a.ChannelModelKey == "")) || (a.LogicalModelID != "" && (a.ChannelID != "" || a.ChannelModelKey != "")) {
|
||||
return CreateTaskRequest{}, nil, BadAuthRequest("请复制 model_list 的 selection:逻辑模型或系统渠道二选一,不得混用")
|
||||
}
|
||||
_, _, refs, err := cloudAgentMediaDocument(s.repo, run.UserID, state.Request.CanvasID, a)
|
||||
_, _, refs, err := cloudAgentMediaDocument(s.repo, run.UserID, state.Request.CanvasID, a, state.TransientReferences)
|
||||
if err != nil {
|
||||
return CreateTaskRequest{}, nil, err
|
||||
}
|
||||
@@ -520,7 +544,11 @@ func (s *Service) prepareCloudAgentMedia(run *model.CloudAgentExecution, state *
|
||||
metadata["videoEditOperation"] = operation
|
||||
}
|
||||
input["metadata"] = metadata
|
||||
return CreateTaskRequest{ProjectID: state.Request.CanvasID, Type: "canvas_" + a.Mode, Operation: operation, Prompt: a.Prompt, LogicalModelID: a.LogicalModelID, Model: a.ChannelModelKey, Input: input}, &cloudAgentMediaPlan{Args: a, CallID: call.ID}, nil
|
||||
transientSnapshot := map[string]cloudAgentTransientReference{}
|
||||
for id, ref := range state.TransientReferences {
|
||||
transientSnapshot[id] = ref
|
||||
}
|
||||
return CreateTaskRequest{ProjectID: state.Request.CanvasID, Type: "canvas_" + a.Mode, Operation: operation, Prompt: a.Prompt, LogicalModelID: a.LogicalModelID, Model: a.ChannelModelKey, Input: input}, &cloudAgentMediaPlan{Args: a, CallID: call.ID, TransientReferences: transientSnapshot}, nil
|
||||
}
|
||||
|
||||
func saveCloudAgentDocument(repo *repository.Repository, canvas *model.CanvasProject, doc map[string]any, policy RuntimePolicySetting) error {
|
||||
@@ -547,7 +575,7 @@ func saveCloudAgentDocument(repo *repository.Repository, canvas *model.CanvasPro
|
||||
// Called inside the same transaction as the task, charge reservation and Agent checkpoint.
|
||||
func createCloudAgentMediaNode(repo *repository.Repository, userID, canvasID string, plan *cloudAgentMediaPlan, task *model.Task, policy RuntimePolicySetting, recorder ...cloudAgentMutationRecorder) error {
|
||||
a := plan.Args
|
||||
canvas, doc, _, err := cloudAgentMediaDocument(repo, userID, canvasID, a)
|
||||
canvas, doc, _, err := cloudAgentMediaDocument(repo, userID, canvasID, a, plan.TransientReferences)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user