environment.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package debugging_runtime
  2. import (
  3. "fmt"
  4. "regexp"
  5. "github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
  6. )
  7. var (
  8. authorRegex = regexp.MustCompile(`^[a-z0-9_-]{1,64}$`)
  9. pluginNameRegex = regexp.MustCompile(`^[a-z0-9_-]{1,64}$`)
  10. )
  11. func (r *RemotePluginRuntime) Identity() (plugin_entities.PluginUniqueIdentifier, error) {
  12. // copy a new declaration
  13. // check original author is alphanumeric
  14. if !authorRegex.MatchString(r.Config.Author) {
  15. return "", fmt.Errorf("author must be alphanumeric and less than 64 characters: ^[a-z0-9_-]{1,64}$")
  16. }
  17. if !pluginNameRegex.MatchString(r.Config.Name) {
  18. return "", fmt.Errorf("plugin name must be alphanumeric and less than 64 characters: ^[a-z0-9_-]{1,64}$")
  19. }
  20. config := r.Config
  21. config.Author = r.tenantId
  22. checksum, _ := r.Checksum()
  23. return plugin_entities.NewPluginUniqueIdentifier(fmt.Sprintf("%s@%s", config.Identity(), checksum))
  24. }
  25. func (r *RemotePluginRuntime) Cleanup() {
  26. // no cleanup needed
  27. }
  28. func (r *RemotePluginRuntime) WaitStarted() <-chan bool {
  29. r.waitChanLock.Lock()
  30. defer r.waitChanLock.Unlock()
  31. ch := make(chan bool)
  32. r.waitStartedChan = append(r.waitStartedChan, ch)
  33. return ch
  34. }
  35. func (r *RemotePluginRuntime) WaitStopped() <-chan bool {
  36. r.waitChanLock.Lock()
  37. defer r.waitChanLock.Unlock()
  38. ch := make(chan bool)
  39. r.waitStoppedChan = append(r.waitStoppedChan, ch)
  40. return ch
  41. }