mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-22 09:45:27 -04:00
888ad788bc
* refactor: introduce local plugin control panel and cleanup environment setup process * fix: args * refactor: new local runtime * temp: stash work for refactor on RemotePluginServer * refactor: unify local runtime lifetime and sperate init environment process * chore: add missing files * stash * refactor: local plugin lifetime control * refactor: complete installation process of control panel * refactor: adapt service layer to new controlpanel * refactor: pluginManager.Install * fix: add routine wrap to InstallServerless, avoid blocking main thread * feat: reinstall serverless runtime * chore: add comments to Reinstall and update confusing naming * refactor: unify install plugin service * refactor: add labels to debugging runtime * refactor: add getters to plugin manager * refactor: split install service to decode/install_task/install service * ??? * refactor: adapt controllers * refactor: session write * refactor: session runtime * Refine install task orchestration (#501) * refactor: installing task * refactor cluster management, decouple lifetime management and cluster * fix cli test command * fix: cleanup TODO comments and implement GracefulStop for instance * feat: add logger to control panel * fix: multiple nil references * refactor: better lifetime control * refactor: better cycle interval * fix(LocalPluginRuntime): prevent returning err when it's not error * fix: avoid adding empty PipExtraArgs * fix: missing errors in Environment init * fix: add truncateMessage to avoid db explosion * cleanup: better lifecycle management * fix: init status at the beginning of installation * optimize: GracefulStop for pluginInstance * refactor: tests * refactor: centralize routine labels (#504) * cleanup: RoutineKey * fix: init routine pool * fix: correctly handle cluster register error * fix: memory leak * fix: add \n to instance write * fix(installer.go): set success to true after succeed for defer func * refactor * fix: missing cwd in testutils * fix: scaleup default runtime nums to 1 when testing * fix: localruntime appconfig in testing module * Update internal/core/local_runtime/load_balancing.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * fix: more efficiency implement in installer_local.go * fix: returns after failing in onDebuggingRuntimeDisconnected * fix: returns after failing in onDebuggingRuntimeDisconnected * fix: splits tests * refactor: naming * refactor: manifest.VersionX * fix: adapt SetDefault to tests * fix: enforce use constants in DBType * fix: generate * fix: linter * cleanup tests * refactor: change package to * cleanup: useless codes * Update internal/cluster/plugin.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * cleanup * refactor: decouple connection_key management from debugging_time * refactor: confused naming * feat: recycle resources to adapt to https://github.com/langgenius/dify-plugin-daemon/pull/500 * refactor: confusing redirecting * fix: support get serverless runtime * fix: race condition in Launching * fix: avoid ManifestValidate in first step of debugging handshake * fix: adding ReleaseAllLocks to finalizers * wtf: what a beautiful code * refactor: rename Stream.Async to Stream.Process * fix: kill process if daed instance was detected * fix: correctly handle failures * fix: consistence of difference interfaces * fix: add stacktrace to panic * fix: only trigger once event * fix: ensure plugin runtime was shutdown * feat: cleanup install tasks * fix: add scale logs --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
182 lines
5.9 KiB
Go
182 lines
5.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"strconv"
|
|
|
|
"github.com/langgenius/dify-plugin-daemon/cmd/commandline/bundle"
|
|
"github.com/langgenius/dify-plugin-daemon/pkg/entities/bundle_entities"
|
|
"github.com/langgenius/dify-plugin-daemon/pkg/utils/log"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
bundleCreateCommand = &cobra.Command{
|
|
Use: "init",
|
|
Short: "Create a bundle",
|
|
Long: "Create a bundle",
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundle.InitBundle()
|
|
},
|
|
}
|
|
|
|
bundleAnalyzeCommand = &cobra.Command{
|
|
Use: "analyze [bundle_path]",
|
|
Short: "List all dependencies",
|
|
Long: "List all dependencies in the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
bundle.ListDependencies(bundlePath)
|
|
},
|
|
}
|
|
|
|
bundleAppendDependencyCommand = &cobra.Command{
|
|
Use: "append",
|
|
Short: "Append a dependency",
|
|
Long: "Append a dependency",
|
|
}
|
|
|
|
bundleAppendGithubDependencyCommand = &cobra.Command{
|
|
Use: "github [bundle_path]",
|
|
Short: "Append a github dependency",
|
|
Long: "Append a github dependency to the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
repoPattern := c.Flag("repo_pattern").Value.String()
|
|
githubPattern, err := bundle_entities.NewGithubRepoPattern(repoPattern)
|
|
if err != nil {
|
|
log.Error("Invalid github repo pattern: %v", err)
|
|
return
|
|
}
|
|
bundle.AddGithubDependency(bundlePath, githubPattern)
|
|
},
|
|
}
|
|
|
|
bundleAppendMarketplaceDependencyCommand = &cobra.Command{
|
|
Use: "marketplace [bundle_path]",
|
|
Short: "Append a marketplace dependency",
|
|
Long: "Append a marketplace dependency to the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
marketplacePatternString := c.Flag("marketplace_pattern").Value.String()
|
|
marketplacePattern, err := bundle_entities.NewMarketplacePattern(marketplacePatternString)
|
|
if err != nil {
|
|
log.Error("Invalid marketplace pattern: %v", err)
|
|
return
|
|
}
|
|
bundle.AddMarketplaceDependency(bundlePath, marketplacePattern)
|
|
},
|
|
}
|
|
|
|
bundleAppendPackageDependencyCommand = &cobra.Command{
|
|
Use: "package [bundle_path]",
|
|
Short: "Append a local package dependency",
|
|
Long: "Append a local package dependency to the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
packagePath := c.Flag("package_path").Value.String()
|
|
bundle.AddPackageDependency(bundlePath, packagePath)
|
|
},
|
|
}
|
|
|
|
bundleRegenerateCommand = &cobra.Command{
|
|
Use: "regenerate [bundle_path]",
|
|
Short: "Regenerate the bundle",
|
|
Long: "Regenerate the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
bundle.RegenerateBundle(bundlePath)
|
|
},
|
|
}
|
|
|
|
bundleRemoveDependencyCommand = &cobra.Command{
|
|
Use: "remove [bundle_path]",
|
|
Short: "Remove a dependency",
|
|
Long: "Remove a dependency from the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
index := c.Flag("index").Value.String()
|
|
indexInt, err := strconv.Atoi(index)
|
|
if err != nil {
|
|
log.Error("Invalid index: %v", err)
|
|
return
|
|
}
|
|
bundle.RemoveDependency(bundlePath, indexInt)
|
|
},
|
|
}
|
|
|
|
bundleBumpVersionCommand = &cobra.Command{
|
|
Use: "bump [bundle_path]",
|
|
Short: "Bump the version of the bundle",
|
|
Long: "Bump the version of the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
targetVersion := c.Flag("target_version").Value.String()
|
|
bundle.BumpVersion(bundlePath, targetVersion)
|
|
},
|
|
}
|
|
|
|
bundlePackageCommand = &cobra.Command{
|
|
Use: "package [bundle_path]",
|
|
Short: "Package the bundle",
|
|
Long: "Package the specified bundle",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
bundlePath := args[0]
|
|
// using filename of input_path as output_path if not specified
|
|
outputPath := ""
|
|
|
|
if c.Flag("output_path").Value.String() != "" {
|
|
outputPath = c.Flag("output_path").Value.String()
|
|
} else {
|
|
base := filepath.Base(bundlePath)
|
|
if base == "." || base == "/" {
|
|
fmt.Println("Error: invalid input path, you should specify the path outside of bundle directory")
|
|
return
|
|
}
|
|
outputPath = base + ".difybndl"
|
|
}
|
|
|
|
bundle.PackageBundle(bundlePath, outputPath)
|
|
},
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
bundleCommand.AddCommand(bundleCreateCommand)
|
|
bundleCommand.AddCommand(bundleAppendDependencyCommand)
|
|
bundleAppendDependencyCommand.AddCommand(bundleAppendGithubDependencyCommand)
|
|
bundleAppendDependencyCommand.AddCommand(bundleAppendMarketplaceDependencyCommand)
|
|
bundleAppendDependencyCommand.AddCommand(bundleAppendPackageDependencyCommand)
|
|
bundleCommand.AddCommand(bundleRemoveDependencyCommand)
|
|
bundleCommand.AddCommand(bundleRegenerateCommand)
|
|
bundleCommand.AddCommand(bundleBumpVersionCommand)
|
|
bundleCommand.AddCommand(bundlePackageCommand)
|
|
bundleCommand.AddCommand(bundleAnalyzeCommand)
|
|
|
|
bundleAppendGithubDependencyCommand.Flags().StringP("repo_pattern", "r", "", "github repo pattern")
|
|
bundleAppendGithubDependencyCommand.MarkFlagRequired("repo_pattern")
|
|
|
|
bundleAppendMarketplaceDependencyCommand.Flags().StringP("marketplace_pattern", "m", "", "marketplace pattern")
|
|
bundleAppendMarketplaceDependencyCommand.MarkFlagRequired("marketplace_pattern")
|
|
|
|
bundleAppendPackageDependencyCommand.Flags().StringP("package_path", "p", "", "path to the package")
|
|
bundleAppendPackageDependencyCommand.MarkFlagRequired("package_path")
|
|
|
|
bundleRemoveDependencyCommand.Flags().StringP("index", "i", "", "index of the dependency")
|
|
bundleRemoveDependencyCommand.MarkFlagRequired("index")
|
|
|
|
bundleBumpVersionCommand.Flags().StringP("target_version", "t", "", "target version")
|
|
bundleBumpVersionCommand.MarkFlagRequired("target_version")
|
|
|
|
bundlePackageCommand.Flags().StringP("output_path", "o", "", "output path")
|
|
}
|