plugin.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package main
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "github.com/langgenius/dify-plugin-daemon/cmd/commandline/plugin"
  6. "github.com/spf13/cobra"
  7. )
  8. var (
  9. pluginInitCommand = &cobra.Command{
  10. Use: "init",
  11. Short: "Init",
  12. Long: "Init",
  13. Run: func(c *cobra.Command, args []string) {
  14. plugin.InitPlugin()
  15. },
  16. }
  17. pluginPackageCommand = &cobra.Command{
  18. Use: "package plugin_path [-o output_path]",
  19. Short: "Package",
  20. Long: "Package plugins",
  21. Run: func(cmd *cobra.Command, args []string) {
  22. if len(args) < 1 {
  23. fmt.Println("Error: plugin_path is required")
  24. return
  25. }
  26. inputPath := args[0]
  27. // using filename of input_path as output_path if not specified
  28. outputPath := ""
  29. if cmd.Flag("output_path") != nil {
  30. outputPath = cmd.Flag("output_path").Value.String()
  31. } else {
  32. outputPath = filepath.Base(inputPath) + ".difypkg"
  33. }
  34. plugin.PackagePlugin(inputPath, outputPath)
  35. },
  36. }
  37. pluginChecksumCommand = &cobra.Command{
  38. Use: "checksum plugin_path",
  39. Short: "Checksum",
  40. Long: "Calculate the checksum of the plugin, you need specify the plugin path or .difypkg file path",
  41. Run: func(cmd *cobra.Command, args []string) {
  42. if len(args) < 1 {
  43. fmt.Println("Error: plugin_path is required")
  44. return
  45. }
  46. pluginPath := args[0]
  47. plugin.CalculateChecksum(pluginPath)
  48. },
  49. }
  50. // NOTE: tester is deprecated, maybe, in several months, we will support this again
  51. // pluginTestCommand = &cobra.Command{
  52. // Use: "test [-i inputs] [-t timeout] package_path invoke_type invoke_action",
  53. // Short: "",
  54. // Long: "Test runs the given plugin package locally, and you can specify the inputs using json format, if not specified, will use default inputs\n" +
  55. // "type: invoke type, available values: \n" +
  56. // "[\n" +
  57. // " tool, model, endpoint\n" +
  58. // "]\n" +
  59. // "action: invoke action, available values: \n" +
  60. // "[\n" +
  61. // " invoke_tool, validate_tool_credentials, \n" +
  62. // " invoke_endpoint\n" +
  63. // " invoke_llm, invoke_text_embedding, invoke_rerank, invoke_tts, invoke_speech2text, invoke_moderation, \n" +
  64. // " validate_provider_credentials, validate_model_credentials, get_tts_model_voices, \n" +
  65. // " get_text_embedding_num_tokens, get_ai_model_schemas, get_llm_num_tokens\n" +
  66. // "]\n",
  67. // Run: func(cmd *cobra.Command, args []string) {
  68. // if len(args) < 3 {
  69. // log.Error("invalid args, please specify package_path, invoke_type, invoke_action")
  70. // return
  71. // }
  72. // // get package path
  73. // package_path_str := args[0]
  74. // // get invoke type
  75. // invoke_type_str := args[1]
  76. // // get invoke action
  77. // invoke_action_str := args[2]
  78. // // get inputs if specified
  79. // inputs := map[string]any{}
  80. // if cmd.Flag("inputs") != nil {
  81. // inputs_str := cmd.Flag("inputs").Value.String()
  82. // err := json.Unmarshal([]byte(inputs_str), &inputs)
  83. // if err != nil {
  84. // log.Error("failed to unmarshal inputs, inputs: %s, error: %v", inputs_str, err)
  85. // return
  86. // }
  87. // }
  88. // // parse flag
  89. // timeout := ""
  90. // if cmd.Flag("timeout") != nil {
  91. // timeout = cmd.Flag("timeout").Value.String()
  92. // }
  93. )
  94. func init() {
  95. pluginCommand.AddCommand(pluginInitCommand)
  96. pluginCommand.AddCommand(pluginPackageCommand)
  97. pluginCommand.AddCommand(pluginChecksumCommand)
  98. // pluginCommand.AddCommand(pluginTestCommand)
  99. // pluginTestCommand.Flags().StringP("inputs", "i", "", "inputs")
  100. // pluginTestCommand.Flags().StringP("timeout", "t", "", "timeout")
  101. }