feat(platform): Agent 与媒体能力 - 完善角色卡、音频协议与任务恢复链路
This commit is contained in:
1 parent
a8f83fedd5
commit
5650da6d31
91 files changed
+3438
-380
No files matched your search
@@ -33,14 +33,15 @@ func BuiltinRegistry() *Registry {
|
||||
PatchFields: editableNodeFields("metadata.content", "Markdown 正文", "Markdown 正文"),
|
||||
},
|
||||
generatedMediaDescriptor("image", "2", "图片", 720, 405, "image", ConnectionPolicy{
|
||||
CanSource: true, CanTarget: true, CanReference: true, AcceptedInputKinds: []string{"text", "image"},
|
||||
CanSource: true, CanTarget: true, CanReference: true, AcceptedInputKinds: []string{"text", "image", "character"},
|
||||
}),
|
||||
generatedMediaDescriptor("video", "2", "视频", 720, 405, "video", ConnectionPolicy{
|
||||
CanSource: true, CanTarget: true, CanReference: true, AcceptedInputKinds: []string{"text", "image", "video", "audio"},
|
||||
CanSource: true, CanTarget: true, CanReference: true, AcceptedInputKinds: []string{"text", "image", "video", "audio", "character"},
|
||||
}),
|
||||
generatedMediaDescriptor("audio", "2", "音频", 340, 120, "audio", ConnectionPolicy{
|
||||
CanSource: true, CanTarget: true, CanReference: true, MaxInputCount: 1, AcceptedInputKinds: []string{"text"},
|
||||
CanSource: true, CanTarget: true, CanReference: true, MaxInputCount: 1, AcceptedInputKinds: []string{"text", "character"},
|
||||
}),
|
||||
characterDescriptor(),
|
||||
{
|
||||
Type: "frame", Version: "1", Label: "背板", DefaultWidth: 760, DefaultHeight: 520,
|
||||
Purpose: "在画布上建立可移动、可折叠的视觉分区,用来归组相关节点;背板本身不承载创作正文或生成结果。",
|
||||
@@ -105,6 +106,25 @@ func BuiltinRegistry() *Registry {
|
||||
return registry
|
||||
}
|
||||
|
||||
// characterDescriptor 是角色卡能力:画布上是 text + metadata.workflowKind=character 的节点,
|
||||
// 设定、三视图与声音都来自账号内的角色资产而非节点正文。它可以被发现、精读、连线和引用,
|
||||
// 但不能用 add_node 凭空创建:必须经 canvas_create_character 用真实图片/音频建角色资产,名称和设定只随角色资产更新。
|
||||
func characterDescriptor() Descriptor {
|
||||
return Descriptor{
|
||||
Type: "character", Version: "1", Label: "角色卡", DefaultWidth: 264, DefaultHeight: 352,
|
||||
Purpose: "引用账号角色库中的角色资产,统一提供角色设定、三视图/形象图和绑定声音,用来保持人物在多次生成中的一致性。",
|
||||
GoodFor: []string{"图片或视频生成时锁定人物外观", "多镜头保持同一角色一致", "角色配音时使用绑定声音", "只取角色文字设定作为提示词来源"},
|
||||
NotIdealFor: []string{"临时一次性的人物描述(直接写进提示词或文本节点)", "用 add_node 新建(应使用 canvas_create_character 打包形象图片与声音)", "承载普通正文(节点正文不是角色设定)"},
|
||||
Tradeoffs: []string{"设定与媒体随角色资产版本变化,提交时会校验版本", "未绑定形象或声音时对应引用不可用,需先读取 character.imageReference/audioReference"},
|
||||
Actions: []string{"read_character", "use_as_reference", "use_as_text_source"},
|
||||
InputKind: "character",
|
||||
Connection: ConnectionPolicy{CanSource: true, CanReference: true},
|
||||
CanUpdate: true,
|
||||
PatchFields: positionPatchFields(),
|
||||
Variant: &NodeVariant{BaseType: "text", WorkflowKind: "character"},
|
||||
}
|
||||
}
|
||||
|
||||
func generatedMediaDescriptor(nodeType, version, label string, width, height float64, generationMode string, connection ConnectionPolicy) Descriptor {
|
||||
semantics := generatedMediaSemantics(nodeType)
|
||||
return Descriptor{
|
||||
|
||||
@@ -34,6 +34,14 @@ type PatchField struct {
|
||||
MaxRunes int
|
||||
}
|
||||
|
||||
// NodeVariant 表示同一底层节点类型按 metadata.workflowKind 标记出的独立能力,
|
||||
// 例如 text + workflowKind=character 的角色卡。变体可被发现、读取、引用和连线,
|
||||
// 但不是可直接创建的节点类型:add_node 的 nodeType 枚举和 Resolve 都不会返回变体。
|
||||
type NodeVariant struct {
|
||||
BaseType string
|
||||
WorkflowKind string
|
||||
}
|
||||
|
||||
// Descriptor is the server-owned canvas contract. Agent tools, creation,
|
||||
// persistence and state projection all consume this registry; no caller owns a
|
||||
// second node allow-list.
|
||||
@@ -58,6 +66,7 @@ type Descriptor struct {
|
||||
ProjectionField string
|
||||
PatchFields map[string]PatchField
|
||||
CreateMetadata func(content string) map[string]any
|
||||
Variant *NodeVariant
|
||||
}
|
||||
|
||||
func (d Descriptor) Metadata(content string) map[string]any {
|
||||
@@ -170,6 +179,8 @@ func inputKindLabel(kind string) string {
|
||||
return "视频"
|
||||
case "audio":
|
||||
return "音频"
|
||||
case "character":
|
||||
return "角色卡"
|
||||
default:
|
||||
return "文本"
|
||||
}
|
||||
|
||||
@@ -9,12 +9,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const SetVersion = "canvas-capabilities/v4"
|
||||
const SetVersion = "canvas-capabilities/v5"
|
||||
|
||||
type Registry struct{ descriptors map[string]Descriptor }
|
||||
type Registry struct {
|
||||
descriptors map[string]Descriptor
|
||||
// variants 按 baseType+workflowKind 索引,只能通过 ResolveNode 命中,
|
||||
// 不会出现在 Resolve/Types 中,因此不会变成可 add_node 的节点类型。
|
||||
variants map[string]string
|
||||
}
|
||||
|
||||
func variantKey(baseType, workflowKind string) string { return baseType + "\x00" + workflowKind }
|
||||
|
||||
func NewRegistry(descriptors []Descriptor) (*Registry, error) {
|
||||
items := make(map[string]Descriptor, len(descriptors))
|
||||
variants := map[string]string{}
|
||||
generationModes := make(map[string]string, len(descriptors))
|
||||
for _, descriptor := range descriptors {
|
||||
descriptor.Type = normalizeType(descriptor.Type)
|
||||
@@ -95,9 +103,30 @@ func NewRegistry(descriptors []Descriptor) (*Registry, error) {
|
||||
if _, exists := items[descriptor.Type]; exists {
|
||||
return nil, fmt.Errorf("duplicate canvas capability %q", descriptor.Type)
|
||||
}
|
||||
if descriptor.Variant != nil {
|
||||
variant := &NodeVariant{BaseType: normalizeType(descriptor.Variant.BaseType), WorkflowKind: strings.TrimSpace(descriptor.Variant.WorkflowKind)}
|
||||
descriptor.Variant = variant
|
||||
if variant.BaseType == "" || variant.WorkflowKind == "" || variant.BaseType == descriptor.Type {
|
||||
return nil, fmt.Errorf("capability %q has invalid node variant", descriptor.Type)
|
||||
}
|
||||
if descriptor.GenerationMode != "" || descriptor.CreateMetadata != nil {
|
||||
return nil, fmt.Errorf("capability variant %q cannot be created or generated directly", descriptor.Type)
|
||||
}
|
||||
key := variantKey(variant.BaseType, variant.WorkflowKind)
|
||||
if existing, exists := variants[key]; exists {
|
||||
return nil, fmt.Errorf("node variant %s/%s is registered by both %q and %q", variant.BaseType, variant.WorkflowKind, existing, descriptor.Type)
|
||||
}
|
||||
variants[key] = descriptor.Type
|
||||
}
|
||||
items[descriptor.Type] = cloneDescriptor(descriptor)
|
||||
}
|
||||
return &Registry{descriptors: items}, nil
|
||||
for key, variantType := range variants {
|
||||
base := items[variantType].Variant.BaseType
|
||||
if baseDescriptor, ok := items[base]; !ok || baseDescriptor.Variant != nil {
|
||||
return nil, fmt.Errorf("capability variant %q extends unknown base type %q", variantType, strings.SplitN(key, "\x00", 2)[0])
|
||||
}
|
||||
}
|
||||
return &Registry{descriptors: items, variants: variants}, nil
|
||||
}
|
||||
|
||||
func (r *Registry) Resolve(nodeType string) (Descriptor, bool) {
|
||||
@@ -105,12 +134,24 @@ func (r *Registry) Resolve(nodeType string) (Descriptor, bool) {
|
||||
return Descriptor{}, false
|
||||
}
|
||||
d, ok := r.descriptors[normalizeType(nodeType)]
|
||||
if !ok {
|
||||
if !ok || d.Variant != nil {
|
||||
return Descriptor{}, false
|
||||
}
|
||||
d = cloneDescriptor(d)
|
||||
return d, ok
|
||||
}
|
||||
|
||||
// ResolveNode 按真实画布节点解析能力:先匹配 type+metadata.workflowKind 变体(如角色卡),
|
||||
// 否则回落到底层类型。读取、连线、引用等拿到节点本身的调用方都应走这里。
|
||||
func (r *Registry) ResolveNode(nodeType, workflowKind string) (Descriptor, bool) {
|
||||
if r == nil {
|
||||
return Descriptor{}, false
|
||||
}
|
||||
if variantType, ok := r.variants[variantKey(normalizeType(nodeType), strings.TrimSpace(workflowKind))]; ok {
|
||||
return cloneDescriptor(r.descriptors[variantType]), true
|
||||
}
|
||||
return r.Resolve(nodeType)
|
||||
}
|
||||
func (r *Registry) List() []Descriptor {
|
||||
if r == nil {
|
||||
return nil
|
||||
@@ -122,11 +163,15 @@ func (r *Registry) List() []Descriptor {
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].Type < out[j].Type })
|
||||
return out
|
||||
}
|
||||
|
||||
// Types 只返回可直接创建的底层节点类型;变体通过 List 被发现,但不能作为 add_node 的 nodeType。
|
||||
func (r *Registry) Types() []string {
|
||||
items := r.List()
|
||||
out := make([]string, 0, len(items))
|
||||
for _, d := range items {
|
||||
out = append(out, d.Type)
|
||||
if d.Variant == nil {
|
||||
out = append(out, d.Type)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -199,6 +244,10 @@ func cloneDescriptor(descriptor Descriptor) Descriptor {
|
||||
patchFields[key] = field
|
||||
}
|
||||
descriptor.PatchFields = patchFields
|
||||
if descriptor.Variant != nil {
|
||||
variant := *descriptor.Variant
|
||||
descriptor.Variant = &variant
|
||||
}
|
||||
return descriptor
|
||||
}
|
||||
|
||||
@@ -222,6 +271,7 @@ type hashDescriptor struct {
|
||||
ProjectionKind string
|
||||
ProjectionField string
|
||||
PatchFields []hashPatchField
|
||||
Variant *NodeVariant
|
||||
}
|
||||
|
||||
type hashConnectionPolicy struct {
|
||||
@@ -265,6 +315,7 @@ func registryHashItems(descriptors []Descriptor) []hashDescriptor {
|
||||
ProjectionKind: descriptor.ProjectionKind, ProjectionField: descriptor.ProjectionField,
|
||||
Connection: hashConnectionPolicy{CanSource: descriptor.Connection.CanSource, CanTarget: descriptor.Connection.CanTarget, CanReference: descriptor.Connection.CanReference, AcceptedInputKinds: descriptor.Connection.AcceptedInputKinds, RejectedInputKinds: descriptor.Connection.RejectedInputKinds, MaxInputCount: descriptor.Connection.MaxInputCount},
|
||||
CanUpdate: descriptor.CanUpdate, SummaryFields: descriptor.SummaryFields, DetailFields: descriptor.DetailFields, PatchFields: patchFields,
|
||||
Variant: descriptor.Variant,
|
||||
})
|
||||
}
|
||||
return items
|
||||
|
||||
Reference in new issue
Block a user