bundle.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package bundle_entities
  2. import (
  3. "encoding/json"
  4. "github.com/langgenius/dify-plugin-daemon/pkg/entities/manifest_entities"
  5. "github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
  6. "gopkg.in/yaml.v3"
  7. )
  8. type Bundle struct {
  9. Name string `json:"name" yaml:"name" validate:"required"`
  10. Labels plugin_entities.I18nObject `json:"labels" yaml:"labels" validate:"required"`
  11. Description plugin_entities.I18nObject `json:"description" yaml:"description" validate:"required"`
  12. Icon string `json:"icon" yaml:"icon" validate:"required"`
  13. Version manifest_entities.Version `json:"version" yaml:"version" validate:"required,version"`
  14. Author string `json:"author" yaml:"author" validate:"required"`
  15. Type manifest_entities.DifyManifestType `json:"type" yaml:"type" validate:"required,eq=bundle"`
  16. Dependencies []Dependency `json:"dependencies" yaml:"dependencies" validate:"required"`
  17. Tags []manifest_entities.PluginTag `json:"tags" yaml:"tags" validate:"omitempty,dive,plugin_tag,max=128"`
  18. }
  19. // for api, avoid pydantic validation error
  20. func (b *Bundle) MarshalJSON() ([]byte, error) {
  21. type alias Bundle
  22. p := alias(*b)
  23. if p.Tags == nil {
  24. p.Tags = []manifest_entities.PluginTag{}
  25. }
  26. return json.Marshal(p)
  27. }
  28. // for unmarshal yaml
  29. func (b *Bundle) UnmarshalYAML(node *yaml.Node) error {
  30. // avoid nil tags
  31. type alias Bundle
  32. p := &struct {
  33. *alias `yaml:",inline"`
  34. }{
  35. alias: (*alias)(b),
  36. }
  37. if err := node.Decode(p); err != nil {
  38. return err
  39. }
  40. if p.Tags == nil {
  41. p.Tags = []manifest_entities.PluginTag{}
  42. }
  43. return nil
  44. }