mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-22 01:35:24 -04:00
31d7c7417e
* feat: introduce 'run' command for local plugin execution - Added a new command `run` to launch plugins locally, allowing communication through stdin/stdout. - Removed the previous `test` command and its associated functionality to streamline the plugin testing process. * feat: enhance 'run' command with TCP support - Introduced a new `RunPluginPayload` structure to encapsulate plugin execution parameters. - Added TCP communication mode to the `run` command, allowing multiple client connections. - Updated command flags to configure run mode and logging options. - Implemented client handling and server creation for both stdin/stdout and TCP modes. * docs: improve comments in RunPlugin function for clarity - Enhanced comments to provide clearer explanations of the plugin decoding process and the creation of client streams for both stdin/stdout and TCP modes. - Updated comments to reflect the functionality and behavior of the plugin execution flow. * refactor: update command structure and enhance plugin invocation handling - Changed the command structure to add `runPluginCommand` under `pluginCommand` for better organization. - Introduced `InvokePluginPayload` type to encapsulate plugin invocation details. - Enhanced `RunPlugin` function to handle responses and errors more effectively, including logging to stdout. - Updated client handling to support session management and improved error handling during plugin invocation. - Renamed TCP server creation function for consistency. * feat: enhance plugin response handling and logging capabilities - Added a new flag `--response-format` to specify the output format (text or json) for plugin responses. - Introduced a `logger` to manage logging output to stdout with timestamps and file information. - Updated `logResponse` and `systemLog` functions to handle different response formats. - Enhanced `handleClient` and `RunPlugin` functions to utilize the new response format feature. - Implemented signal handling to clean up temporary directories on shutdown. * feat: enhance plugin response structure and logging - Added `InvokeID` to `InvokePluginPayload` and `GenericResponse` for better tracking of plugin invocations. - Updated `logResponse` to include `InvokeID` in error responses for improved debugging. - Enhanced client handling in `handleClient` to log plugin readiness and received requests. - Refactored client stream creation for better readability and consistency. * feat: add plugin invoke end response type and logging - Introduced `GENERIC_RESPONSE_TYPE_PLUGIN_INVOKE_END` to enhance response tracking for plugin invocations. - Updated `handleClient` to log the end of plugin invocation, improving visibility into the plugin lifecycle. * chore: remove fullfeature tags
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/langgenius/dify-plugin-daemon/cmd/commandline/run"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
/*
|
|
Test is a very important component of Dify plugins, to ensure every plugin is working as expected
|
|
We must provide a way to make the test a pipeline and use standard CI/CD tools to run the tests
|
|
|
|
However, developers prefer to write test codes in language like Python, it's hard to enforce them to use Go
|
|
and what we need is actually a way to launch plugins locally
|
|
|
|
It makes things easier, the command should be `run`, instead of `test`, user could use `dify plugin run <plugin_id>`
|
|
to launch and test it through stdin/stdout
|
|
*/
|
|
|
|
var (
|
|
runPluginPayload run.RunPluginPayload
|
|
)
|
|
|
|
var (
|
|
runPluginCommand = &cobra.Command{
|
|
Use: "run [plugin_package_path]",
|
|
Short: "run",
|
|
Long: "Launch a plugin locally and communicate through stdin/stdout or TCP",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(c *cobra.Command, args []string) {
|
|
runPluginPayload.PluginPath = args[0]
|
|
// launch plugin
|
|
run.RunPlugin(runPluginPayload)
|
|
},
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
pluginCommand.AddCommand(runPluginCommand)
|
|
|
|
runPluginCommand.Flags().StringVarP(&runPluginPayload.RunMode, "mode", "m", "stdio", "run mode, stdio or tcp")
|
|
runPluginCommand.Flags().BoolVarP(&runPluginPayload.EnableLogs, "enable-logs", "l", false, "enable logs")
|
|
runPluginCommand.Flags().StringVarP(&runPluginPayload.ResponseFormat, "response-format", "r", "text", "response format, text or json")
|
|
}
|