plugin.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package models
  2. import (
  3. "github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
  4. "github.com/langgenius/dify-plugin-daemon/internal/utils/parser"
  5. )
  6. type Plugin struct {
  7. Model
  8. // PluginUniqueIdentifier is a unique identifier for the plugin, it contains version and checksum
  9. PluginUniqueIdentifier string `json:"plugin_unique_identifier" gorm:"index;size:127"`
  10. // PluginID is the id of the plugin, only plugin name is considered
  11. PluginID string `json:"id" gorm:"index;size:127"`
  12. Refers int `json:"refers" gorm:"default:0"`
  13. InstallType plugin_entities.PluginRuntimeType `json:"install_type" gorm:"size:127;index"`
  14. ManifestType plugin_entities.DifyManifestType `json:"manifest_type" gorm:"size:127"`
  15. Declaration string `json:"declaration" gorm:"type:text;size:65535"`
  16. }
  17. func (p *Plugin) GetDeclaration() (*plugin_entities.PluginDeclaration, error) {
  18. declaration, err := parser.UnmarshalJson[plugin_entities.PluginDeclaration](p.Declaration)
  19. if err != nil {
  20. return nil, err
  21. }
  22. return &declaration, nil
  23. }
  24. type ServerlessRuntimeType string
  25. const (
  26. SERVERLESS_RUNTIME_TYPE_AWS_LAMBDA ServerlessRuntimeType = "aws_lambda"
  27. )
  28. type ServerlessRuntime struct {
  29. Model
  30. PluginUniqueIdentifier string `json:"plugin_unique_identifier" gorm:"size:127;unique"`
  31. FunctionURL string `json:"function_url" gorm:"size:255"`
  32. FunctionName string `json:"function_name" gorm:"size:127"`
  33. Type ServerlessRuntimeType `json:"type" gorm:"size:127"`
  34. Declaration string `json:"declaration" gorm:"type:text;size:65535"`
  35. Checksum string `json:"checksum" gorm:"size:127;index"`
  36. }
  37. func (p *ServerlessRuntime) GetDeclaration() (*plugin_entities.PluginDeclaration, error) {
  38. declaration, err := parser.UnmarshalJson[plugin_entities.PluginDeclaration](p.Declaration)
  39. if err != nil {
  40. return nil, err
  41. }
  42. return &declaration, nil
  43. }
  44. func (p *ServerlessRuntime) SetDeclaration(declaration *plugin_entities.PluginDeclaration) {
  45. p.Declaration = parser.MarshalJson(declaration)
  46. }