Explorar o código

add label to manifest

Yeuoly hai 11 meses
pai
achega
c8c023521d

+ 3 - 0
cmd/commandline/init.go

@@ -95,6 +95,9 @@ func (m model) createPlugin() {
 		Resource: plugin_entities.PluginResourceRequirement{
 			Permission: &permission,
 		},
+		Label: plugin_entities.I18nObject{
+			EnUS: m.subMenus[SUB_MENU_KEY_PROFILE].(profile).Name(),
+		},
 	}
 
 	manifest.Meta = plugin_entities.PluginMeta{

+ 8 - 4
cmd/commandline/profile.go

@@ -5,6 +5,7 @@ import (
 
 	ti "github.com/charmbracelet/bubbles/textinput"
 	tea "github.com/charmbracelet/bubbletea"
+	"github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
 )
 
 type profile struct {
@@ -47,10 +48,13 @@ func (p profile) View() string {
 	return s
 }
 
-func (p *profile) checkEmpty() bool {
+func (p *profile) checkRule() bool {
 	if p.inputs[p.cursor].Value() == "" {
 		p.warning = "Name and author cannot be empty"
 		return false
+	} else if p.cursor == 0 && !plugin_entities.PluginNameRegex.MatchString(p.inputs[p.cursor].Value()) {
+		p.warning = "Plugin name must be 1-128 characters long, and can only contain letters, numbers, dashes and underscores"
+		return false
 	} else {
 		p.warning = ""
 	}
@@ -67,7 +71,7 @@ func (p profile) Update(msg tea.Msg) (subMenu, subMenuEvent, tea.Cmd) {
 			return p, SUB_MENU_EVENT_NONE, tea.Quit
 		case "down":
 			// check if empty
-			if !p.checkEmpty() {
+			if !p.checkRule() {
 				return p, SUB_MENU_EVENT_NONE, nil
 			}
 
@@ -77,7 +81,7 @@ func (p profile) Update(msg tea.Msg) (subMenu, subMenuEvent, tea.Cmd) {
 				p.cursor = 0
 			}
 		case "up":
-			if !p.checkEmpty() {
+			if !p.checkRule() {
 				return p, SUB_MENU_EVENT_NONE, nil
 			}
 
@@ -86,7 +90,7 @@ func (p profile) Update(msg tea.Msg) (subMenu, subMenuEvent, tea.Cmd) {
 				p.cursor = len(p.inputs) - 1
 			}
 		case "enter":
-			if !p.checkEmpty() {
+			if !p.checkRule() {
 				return p, SUB_MENU_EVENT_NONE, nil
 			}
 

+ 4 - 1
internal/cluster/plugin_test.go

@@ -42,7 +42,10 @@ func getRandomPluginRuntime() fakePlugin {
 	return fakePlugin{
 		PluginRuntime: plugin_entities.PluginRuntime{
 			Config: plugin_entities.PluginDeclaration{
-				Name:      uuid.New().String(),
+				Name: uuid.New().String(),
+				Label: plugin_entities.I18nObject{
+					EnUS: "label",
+				},
 				Version:   "0.0.1",
 				Type:      plugin_entities.PluginType,
 				Author:    "Yeuoly",

+ 2 - 0
internal/core/plugin_manager/aws_manager/packager_test_plugin/manifest.yaml

@@ -2,6 +2,8 @@ version: 0.0.1
 type: plugin
 author: "Yeuoly"
 name: "jina"
+label:
+  en_US: "Jina"
 created_at: "2024-07-12T08:03:44.658609186Z"
 resource:
   memory: 1048576

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

@@ -135,10 +135,13 @@ func TestAcceptConnection(t *testing.T) {
 
 	// send handshake
 	handle_shake_message := parser.MarshalJsonBytes(&plugin_entities.PluginDeclaration{
-		Version:   "1.0.0",
-		Type:      plugin_entities.PluginType,
-		Author:    "Yeuoly",
-		Name:      "ci_test",
+		Version: "1.0.0",
+		Type:    plugin_entities.PluginType,
+		Author:  "Yeuoly",
+		Name:    "ci_test",
+		Label: plugin_entities.I18nObject{
+			EnUS: "ci_test",
+		},
 		CreatedAt: time.Now(),
 		Resource: plugin_entities.PluginResourceRequirement{
 			Memory:     1,

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

@@ -2,6 +2,8 @@ version: 0.0.1
 type: plugin
 author: "Yeuoly"
 name: "Neko"
+label:
+  en_US: "Neko"
 created_at: "2024-07-12T08:03:44.658609186Z"
 resource:
   memory: 1048576

+ 4 - 3
internal/types/entities/plugin_entities/basic_type.go

@@ -7,9 +7,10 @@ import (
 )
 
 type I18nObject struct {
-	EnUS   string `json:"en_US" validate:"required,gt=0,lt=1024"`
-	ZhHans string `json:"zh_Hans" validate:"lt=1024"`
-	PtBr   string `json:"pt_BR" validate:"lt=1024"`
+	EnUS   string `json:"en_US" yaml:"en_US" validate:"required,gt=0,lt=1024"`
+	JaJp   string `json:"ja_JP" yaml:"ja_JP" validate:"lt=1024"`
+	ZhHans string `json:"zh_Hans" yaml:"zh_Hans" validate:"lt=1024"`
+	PtBr   string `json:"pt_BR" yaml:"pt_BR" validate:"lt=1024"`
 }
 
 func isBasicType(fl validator.FieldLevel) bool {

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

@@ -136,6 +136,7 @@ type PluginDeclaration struct {
 	Type      DifyManifestType             `json:"type" yaml:"type,omitempty" validate:"required,eq=plugin"`
 	Author    string                       `json:"author" yaml:"author,omitempty" validate:"required,max=128"`
 	Name      string                       `json:"name" yaml:"name,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   []string                     `json:"plugins" yaml:"plugins,omitempty" validate:"required,dive,max=128"`
@@ -147,13 +148,19 @@ type PluginDeclaration struct {
 }
 
 var (
-	plugin_declaration_version_regex = regexp.MustCompile(`^\d{1,4}(\.\d{1,4}){1,3}(-\w{1,16})?$`)
+	PluginNameRegex               = regexp.MustCompile(`^[a-zA-Z0-9_-]{1,128}$`)
+	PluginDeclarationVersionRegex = regexp.MustCompile(`^\d{1,4}(\.\d{1,4}){1,3}(-\w{1,16})?$`)
 )
 
 func isVersion(fl validator.FieldLevel) bool {
 	// version format must be like x.x.x, at least 2 digits and most 5 digits, and it can be ends with a letter
 	value := fl.Field().String()
-	return plugin_declaration_version_regex.MatchString(value)
+	return PluginDeclarationVersionRegex.MatchString(value)
+}
+
+func isPluginName(fl validator.FieldLevel) bool {
+	value := fl.Field().String()
+	return PluginNameRegex.MatchString(value)
 }
 
 func (p *PluginDeclaration) Identity() string {
@@ -179,6 +186,7 @@ func (p *PluginDeclaration) ManifestValidate() error {
 func init() {
 	// init validator
 	validators.GlobalEntitiesValidator.RegisterValidation("version", isVersion)
+	validators.GlobalEntitiesValidator.RegisterValidation("plugin_name", isPluginName)
 }
 
 func UnmarshalPluginDeclarationFromYaml(data []byte) (*PluginDeclaration, error) {

+ 6 - 3
internal/types/entities/plugin_entities/plugin_declaration_test.go

@@ -10,9 +10,12 @@ import (
 
 func preparePluginDeclaration() PluginDeclaration {
 	return PluginDeclaration{
-		Version:   "0.0.1",
-		Type:      PluginType,
-		Name:      "test",
+		Version: "0.0.1",
+		Type:    PluginType,
+		Name:    "test",
+		Label: I18nObject{
+			EnUS: "test",
+		},
 		Author:    "test",
 		CreatedAt: time.Now(),
 		Resource: PluginResourceRequirement{