Bläddra i källkod

feat: add description for plugin

Yeuoly 9 månader sedan
förälder
incheckning
01d7d16bb4

+ 4 - 0
internal/core/plugin_manager/remote_manager/hooks.go

@@ -271,6 +271,10 @@ func (s *DifyServer) onMessage(runtime *RemotePluginRuntime, message []byte) {
 			return
 		}
 
+		// fill in default values
+		runtime.Config.FillInDefaultValues()
+
+		// mark assets transferred
 		runtime.assets_transferred = true
 
 		runtime.checksum = runtime.calculateChecksum()

+ 7 - 3
internal/core/plugin_manager/remote_manager/server_test.go

@@ -146,9 +146,12 @@ func TestAcceptConnection(t *testing.T) {
 		PluginDeclarationWithoutAdvancedFields: plugin_entities.PluginDeclarationWithoutAdvancedFields{
 			Version: "1.0.0",
 			Type:    plugin_entities.PluginType,
-			Author:  "Yeuoly",
-			Name:    "ci_test",
-			Icon:    "test.svg",
+			Description: plugin_entities.I18nObject{
+				EnUS: "test",
+			},
+			Author: "Yeuoly",
+			Name:   "ci_test",
+			Icon:   "test.svg",
 			Label: plugin_entities.I18nObject{
 				EnUS: "ci_test",
 			},
@@ -213,6 +216,7 @@ func TestAcceptConnection(t *testing.T) {
 		return
 	case <-closed_chan:
 		// success
+
 		if !got_connection {
 			t.Errorf("failed to accept connection: %s", msg)
 			return

+ 2 - 0
internal/core/plugin_packager/decoder/decoder.go

@@ -291,6 +291,8 @@ func (p *PluginDecoderHelper) Manifest(decoder PluginDecoder) (plugin_entities.P
 		dec.Model = &plugin_dec
 	}
 
+	dec.FillInDefaultValues()
+
 	if err := dec.ManifestValidate(); err != nil {
 		return plugin_entities.PluginDeclaration{}, err
 	}

+ 2 - 0
internal/core/plugin_packager/manifest.yaml

@@ -3,6 +3,8 @@ type: plugin
 author: "Yeuoly"
 name: "neko"
 icon: test.svg
+description:
+  en_US: "test"
 label:
   en_US: "Neko"
 created_at: "2024-07-12T08:03:44.658609186Z"

+ 31 - 10
internal/types/entities/plugin_entities/plugin_declaration.go

@@ -133,16 +133,17 @@ type PluginExtensions struct {
 }
 
 type PluginDeclarationWithoutAdvancedFields struct {
-	Version   string                    `json:"version" yaml:"version,omitempty" validate:"required,version"`
-	Type      DifyManifestType          `json:"type" yaml:"type,omitempty" validate:"required,eq=plugin"`
-	Author    string                    `json:"author" yaml:"author,omitempty" validate:"omitempty,max=64"`
-	Name      string                    `json:"name" yaml:"name,omitempty" validate:"required,max=128"`
-	Icon      string                    `json:"icon" yaml:"icon,omitempty" validate:"required,max=128"`
-	Label     I18nObject                `json:"label" yaml:"label" validate:"required"`
-	CreatedAt time.Time                 `json:"created_at" yaml:"created_at,omitempty" validate:"required"`
-	Resource  PluginResourceRequirement `json:"resource" yaml:"resource,omitempty" validate:"required"`
-	Plugins   PluginExtensions          `json:"plugins" yaml:"plugins,omitempty" validate:"required"`
-	Meta      PluginMeta                `json:"meta" yaml:"meta,omitempty" validate:"required"`
+	Version     string                    `json:"version" yaml:"version,omitempty" validate:"required,version"`
+	Type        DifyManifestType          `json:"type" yaml:"type,omitempty" validate:"required,eq=plugin"`
+	Description I18nObject                `json:"description" yaml:"description" validate:"required"`
+	Label       I18nObject                `json:"label" yaml:"label" validate:"required"`
+	Author      string                    `json:"author" yaml:"author,omitempty" validate:"omitempty,max=64"`
+	Name        string                    `json:"name" yaml:"name,omitempty" validate:"required,max=128"`
+	Icon        string                    `json:"icon" yaml:"icon,omitempty" validate:"required,max=128"`
+	CreatedAt   time.Time                 `json:"created_at" yaml:"created_at,omitempty" validate:"required"`
+	Resource    PluginResourceRequirement `json:"resource" yaml:"resource,omitempty" validate:"required"`
+	Plugins     PluginExtensions          `json:"plugins" yaml:"plugins,omitempty" validate:"required"`
+	Meta        PluginMeta                `json:"meta" yaml:"meta,omitempty" validate:"required"`
 }
 
 type PluginDeclaration struct {
@@ -188,6 +189,22 @@ func (p *PluginDeclaration) ManifestValidate() error {
 	return nil
 }
 
+func (p *PluginDeclaration) FillInDefaultValues() {
+	if p.Tool != nil {
+		if p.Tool.Identity.Description == nil {
+			deep_copied_description := p.Description
+			p.Tool.Identity.Description = &deep_copied_description
+		}
+	}
+
+	if p.Model != nil {
+		if p.Model.Description == nil {
+			deep_copied_description := p.Description
+			p.Model.Description = &deep_copied_description
+		}
+	}
+}
+
 func init() {
 	// init validator
 	validators.GlobalEntitiesValidator.RegisterValidation("version", isVersion)
@@ -204,6 +221,8 @@ func UnmarshalPluginDeclarationFromYaml(data []byte) (*PluginDeclaration, error)
 		return nil, err
 	}
 
+	obj.FillInDefaultValues()
+
 	return &obj, nil
 }
 
@@ -217,5 +236,7 @@ func UnmarshalPluginDeclarationFromJSON(data []byte) (*PluginDeclaration, error)
 		return nil, err
 	}
 
+	obj.FillInDefaultValues()
+
 	return &obj, nil
 }

+ 5 - 2
internal/types/entities/plugin_entities/plugin_declaration_test.go

@@ -13,8 +13,11 @@ func preparePluginDeclaration() PluginDeclaration {
 		PluginDeclarationWithoutAdvancedFields: PluginDeclarationWithoutAdvancedFields{
 			Version: "0.0.1",
 			Type:    PluginType,
-			Name:    "test",
-			Icon:    "test.svg",
+			Description: I18nObject{
+				EnUS: "test",
+			},
+			Name: "test",
+			Icon: "test.svg",
 			Label: I18nObject{
 				EnUS: "test",
 			},

+ 1 - 1
internal/types/entities/plugin_entities/tool_declaration.go

@@ -162,7 +162,7 @@ func isToolLabel(fl validator.FieldLevel) bool {
 type ToolProviderIdentity struct {
 	Author      string      `json:"author" validate:"required"`
 	Name        string      `json:"name" validate:"required"`
-	Description I18nObject  `json:"description" validate:"required"`
+	Description *I18nObject `json:"description" validate:"omitempty"`
 	Icon        string      `json:"icon" validate:"required"`
 	Label       I18nObject  `json:"label" validate:"required"`
 	Tags        []ToolLabel `json:"tags" validate:"required,dive,tool_label"`