Browse Source

add plugin type

Yeuoly 1 year ago
parent
commit
c6d627fc02

+ 6 - 0
internal/core/plugin_manager/aws_manager/run.go

@@ -1,5 +1,7 @@
 package aws_manager
 
+import "github.com/langgenius/dify-plugin-daemon/internal/types/entities"
+
 func (r *AWSPluginRuntime) StartPlugin() error {
 
 	return nil
@@ -8,3 +10,7 @@ func (r *AWSPluginRuntime) StartPlugin() error {
 func (r *AWSPluginRuntime) Wait() (<-chan bool, error) {
 	return nil, nil
 }
+
+func (r *AWSPluginRuntime) Type() entities.PluginRuntimeType {
+	return entities.PLUGIN_RUNTIME_TYPE_AWS
+}

+ 4 - 0
internal/core/plugin_manager/local_manager/run.go

@@ -28,6 +28,10 @@ func (r *LocalPluginRuntime) init() {
 	r.State.Status = entities.PLUGIN_RUNTIME_STATUS_LAUNCHING
 }
 
+func (r *LocalPluginRuntime) Type() entities.PluginRuntimeType {
+	return entities.PLUGIN_RUNTIME_TYPE_LOCAL
+}
+
 func (r *LocalPluginRuntime) StartPlugin() error {
 	defer log.Info("plugin %s stopped", r.Config.Identity())
 

+ 1 - 1
internal/core/plugin_manager/remote_manager/connection_key.go

@@ -15,7 +15,7 @@ import (
  * Therefore, we need to a key-value pair to connect a random string to a tenant.
  *
  * $random_key => $tenant_id, $user_id
- * $tenant_id => $random_id
+ * $tenant_id => $random_key
  *
  * It's a double mapping for each key, therefore a transaction is needed.
  * */

+ 5 - 0
internal/core/plugin_manager/remote_manager/run.go

@@ -4,6 +4,7 @@ import (
 	"time"
 
 	"github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager/plugin_errors"
+	"github.com/langgenius/dify-plugin-daemon/internal/types/entities"
 	"github.com/langgenius/dify-plugin-daemon/internal/types/entities/plugin_entities"
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/log"
 	"github.com/langgenius/dify-plugin-daemon/internal/utils/parser"
@@ -26,6 +27,10 @@ func (r *RemotePluginRuntime) Stop() {
 	r.conn.Close()
 }
 
+func (r *RemotePluginRuntime) Type() entities.PluginRuntimeType {
+	return entities.PLUGIN_RUNTIME_TYPE_REMOTE
+}
+
 func (r *RemotePluginRuntime) StartPlugin() error {
 	var exit_error error
 

+ 10 - 0
internal/types/entities/runtime.go

@@ -26,6 +26,7 @@ type (
 		Configuration() *plugin_entities.PluginDeclaration
 		RuntimeState() *PluginRuntimeState
 		Wait() (<-chan bool, error)
+		Type() PluginRuntimeType
 	}
 
 	PluginRuntimeSessionIOInterface interface {
@@ -50,6 +51,14 @@ func (r *PluginRuntime) RuntimeState() *PluginRuntimeState {
 	return &r.State
 }
 
+type PluginRuntimeType string
+
+const (
+	PLUGIN_RUNTIME_TYPE_LOCAL  PluginRuntimeType = "local"
+	PLUGIN_RUNTIME_TYPE_REMOTE PluginRuntimeType = "remote"
+	PLUGIN_RUNTIME_TYPE_AWS    PluginRuntimeType = "aws"
+)
+
 type PluginRuntimeState struct {
 	Restarts     int        `json:"restarts"`
 	Status       string     `json:"status"`
@@ -57,6 +66,7 @@ type PluginRuntimeState struct {
 	ActiveAt     *time.Time `json:"active_at"`
 	StoppedAt    *time.Time `json:"stopped_at"`
 	Verified     bool       `json:"verified"`
+	TenantID     string     `json:"tenant_id"`
 }
 
 const (