|
@@ -2,13 +2,9 @@ package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "os"
|
|
|
"path/filepath"
|
|
|
|
|
|
- initPkg "github.com/langgenius/dify-plugin-daemon/cmd/commandline/init"
|
|
|
- "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/decoder"
|
|
|
- "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_packager/packager"
|
|
|
- "github.com/langgenius/dify-plugin-daemon/internal/utils/log"
|
|
|
+ "github.com/langgenius/dify-plugin-daemon/cmd/commandline/plugin"
|
|
|
"github.com/spf13/cobra"
|
|
|
)
|
|
|
|
|
@@ -18,7 +14,7 @@ var (
|
|
|
Short: "Init",
|
|
|
Long: "Init",
|
|
|
Run: func(c *cobra.Command, args []string) {
|
|
|
- initPkg.InitPlugin()
|
|
|
+ plugin.InitPlugin()
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -41,27 +37,7 @@ var (
|
|
|
outputPath = filepath.Base(inputPath) + ".difypkg"
|
|
|
}
|
|
|
|
|
|
- decoder, err := decoder.NewFSPluginDecoder(inputPath)
|
|
|
- if err != nil {
|
|
|
- log.Error("failed to create plugin decoder , plugin path: %s, error: %v", inputPath, err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- packager := packager.NewPackager(decoder)
|
|
|
- zipFile, err := packager.Pack()
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- log.Error("failed to package plugin %v", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- err = os.WriteFile(outputPath, zipFile, 0644)
|
|
|
- if err != nil {
|
|
|
- log.Error("failed to write package file %v", err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- log.Info("plugin packaged successfully, output path: %s", outputPath)
|
|
|
+ plugin.PackagePlugin(inputPath, outputPath)
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -76,71 +52,10 @@ var (
|
|
|
}
|
|
|
|
|
|
pluginPath := args[0]
|
|
|
- var pluginDecoder decoder.PluginDecoder
|
|
|
- if stat, err := os.Stat(pluginPath); err == nil {
|
|
|
- if stat.IsDir() {
|
|
|
- pluginDecoder, err = decoder.NewFSPluginDecoder(pluginPath)
|
|
|
- if err != nil {
|
|
|
- log.Error("failed to create plugin decoder, plugin path: %s, error: %v", pluginPath, err)
|
|
|
- return
|
|
|
- }
|
|
|
- } else {
|
|
|
- bytes, err := os.ReadFile(pluginPath)
|
|
|
- if err != nil {
|
|
|
- log.Error("failed to read plugin file, plugin path: %s, error: %v", pluginPath, err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- pluginDecoder, err = decoder.NewZipPluginDecoder(bytes)
|
|
|
- if err != nil {
|
|
|
- log.Error("failed to create plugin decoder, plugin path: %s, error: %v", pluginPath, err)
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Error("failed to get plugin file info, plugin path: %s, error: %v", pluginPath, err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- checksum, err := pluginDecoder.Checksum()
|
|
|
- if err != nil {
|
|
|
- log.Error("failed to calculate checksum, plugin path: %s, error: %v", pluginPath, err)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- log.Info("plugin checksum: %s", checksum)
|
|
|
+ plugin.CalculateChecksum(pluginPath)
|
|
|
},
|
|
|
}
|
|
|
|
|
|
- pluginPermissionCommand = &cobra.Command{
|
|
|
- Use: "permission",
|
|
|
- Short: "Permission",
|
|
|
- Long: `Permission, available values:
|
|
|
-tools - allow plugin to call tools
|
|
|
-models - allow plugin to call models
|
|
|
-models.llm - allow plugin to call llm
|
|
|
-models.text_embedding - allow plugin to call text_embedding model
|
|
|
-models.rerank - allow plugin to call rerank model
|
|
|
-models.tts - allow plugin to call tts
|
|
|
-models.speech2text - allow plugin to call speech2text
|
|
|
-models.moderation - allow plugin to call moderation
|
|
|
-apps - allow plugin to call apps
|
|
|
-storage - allow plugin to use storage
|
|
|
-endpoint - allow plugin to register endpoint`,
|
|
|
- }
|
|
|
-
|
|
|
- pluginPermissionAddCommand = &cobra.Command{
|
|
|
- Use: "add permission",
|
|
|
- Short: "",
|
|
|
- Long: "Add permission to plugin, you can find the available permission by running `dify plugin permission`",
|
|
|
- }
|
|
|
-
|
|
|
- pluginPermissionDropCommand = &cobra.Command{
|
|
|
- Use: "drop permission",
|
|
|
- Short: "",
|
|
|
- Long: "Drop permission from plugin, you can find the available permission by running `dify plugin permission`",
|
|
|
- }
|
|
|
-
|
|
|
// NOTE: tester is deprecated, maybe, in several months, we will support this again
|
|
|
// pluginTestCommand = &cobra.Command{
|
|
|
// Use: "test [-i inputs] [-t timeout] package_path invoke_type invoke_action",
|
|
@@ -185,66 +100,13 @@ endpoint - allow plugin to register endpoint`,
|
|
|
// timeout = cmd.Flag("timeout").Value.String()
|
|
|
// }
|
|
|
|
|
|
- // // get invoke_type and invoke_action
|
|
|
- // invoke_type := access_types.PluginAccessType(invoke_type_str)
|
|
|
- // if !invoke_type.IsValid() {
|
|
|
- // log.Error("invalid invoke type: %s", invoke_type_str)
|
|
|
- // return
|
|
|
- // }
|
|
|
- // invoke_action := access_types.PluginAccessAction(invoke_action_str)
|
|
|
- // if !invoke_action.IsValid() {
|
|
|
- // log.Error("invalid invoke action: %s", invoke_action_str)
|
|
|
- // return
|
|
|
- // }
|
|
|
-
|
|
|
- // // init routine pool
|
|
|
- // routine.InitPool(1024)
|
|
|
-
|
|
|
- // // clean working directory when test finished
|
|
|
- // defer os.RemoveAll("./working")
|
|
|
-
|
|
|
- // // init testing config
|
|
|
- // config := &app.Config{
|
|
|
- // PluginWorkingPath: "./working/cwd",
|
|
|
- // PluginStoragePath: "./working/storage",
|
|
|
- // PluginMediaCachePath: "./working/media_cache",
|
|
|
- // ProcessCachingPath: "./working/subprocesses",
|
|
|
- // Platform: app.PLATFORM_LOCAL,
|
|
|
- // }
|
|
|
- // config.SetDefault()
|
|
|
-
|
|
|
- // // init oss
|
|
|
- // oss := local.NewLocalStorage("./storage")
|
|
|
-
|
|
|
- // // init plugin manager
|
|
|
- // plugin_manager := plugin_manager.InitGlobalManager(oss, config)
|
|
|
-
|
|
|
- // response, err := plugin_manager.TestPlugin(package_path_str, inputs, invoke_type, invoke_action, timeout)
|
|
|
- // if err != nil {
|
|
|
- // log.Error("failed to test plugin, package_path: %s, error: %v", package_path_str, err)
|
|
|
- // return
|
|
|
- // }
|
|
|
-
|
|
|
- // for response.Next() {
|
|
|
- // item, err := response.Read()
|
|
|
- // if err != nil {
|
|
|
- // log.Error("failed to read response item, error: %v", err)
|
|
|
- // return
|
|
|
- // }
|
|
|
- // log.Info("%v", parser.MarshalJson(item))
|
|
|
- // }
|
|
|
- // },
|
|
|
- // }
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
|
pluginCommand.AddCommand(pluginInitCommand)
|
|
|
pluginCommand.AddCommand(pluginPackageCommand)
|
|
|
pluginCommand.AddCommand(pluginChecksumCommand)
|
|
|
- pluginCommand.AddCommand(pluginPermissionCommand)
|
|
|
// pluginCommand.AddCommand(pluginTestCommand)
|
|
|
// pluginTestCommand.Flags().StringP("inputs", "i", "", "inputs")
|
|
|
// pluginTestCommand.Flags().StringP("timeout", "t", "", "timeout")
|
|
|
- pluginPermissionCommand.AddCommand(pluginPermissionAddCommand)
|
|
|
- pluginPermissionCommand.AddCommand(pluginPermissionDropCommand)
|
|
|
}
|