mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-22 01:35:24 -04:00
0be17fa1a7
- Changed the tool fetching mechanism to handle missing tools more effectively by introducing a batch fetch method. - Removed the pull command to streamline the CLI, focusing on tool references and their management. - Enhanced the list command to display available tool references and their statuses, improving user visibility into tool availability. - Updated the configuration structure to include new fields for tool references and their enabled status. This update improves the overall tool management experience in the CLI, making it more efficient and user-friendly.
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/langgenius/dify-plugin-daemon/cmd/dify_cli/config"
|
|
"github.com/langgenius/dify-plugin-daemon/cmd/dify_cli/tool"
|
|
"github.com/langgenius/dify-plugin-daemon/cmd/dify_cli/types"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var ListCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all available tools",
|
|
Long: `List all available tool references from the config.`,
|
|
Run: runList,
|
|
}
|
|
|
|
func runList(cmd *cobra.Command, args []string) {
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: config not found\n")
|
|
os.Exit(1)
|
|
}
|
|
|
|
if len(cfg.ToolReferences) == 0 {
|
|
fmt.Println("No tool references defined in config")
|
|
return
|
|
}
|
|
|
|
missingRefs := findMissingTools(cfg)
|
|
if len(missingRefs) > 0 {
|
|
fmt.Fprintf(os.Stderr, "Fetching %d tool(s) from server...\n", len(missingRefs))
|
|
tools, err := tool.FetchToolsBatch(cfg, missingRefs)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Warning: failed to fetch tools: %v\n", err)
|
|
} else {
|
|
cfg.Tools = append(cfg.Tools, tools...)
|
|
if err := config.Save(cfg); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Warning: failed to save config: %v\n", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
fmt.Println("Available tool references:")
|
|
for _, ref := range cfg.ToolReferences {
|
|
symName := config.GetReferenceSymlinkName(&ref)
|
|
toolDecl := config.FindToolByReference(cfg, &ref)
|
|
|
|
if toolDecl == nil {
|
|
fmt.Printf(" %s - (not cached)\n", symName)
|
|
continue
|
|
}
|
|
|
|
status := "[enabled]"
|
|
if toolDecl.Enabled != nil && !*toolDecl.Enabled {
|
|
status = "[disabled]"
|
|
}
|
|
|
|
desc := toolDecl.Description.LLM
|
|
if desc == "" {
|
|
desc = toolDecl.Description.Human.EnUS
|
|
}
|
|
if len(desc) > 60 {
|
|
desc = desc[:57] + "..."
|
|
}
|
|
|
|
fmt.Printf(" %s %s - %s\n", status, symName, desc)
|
|
}
|
|
}
|
|
|
|
func findMissingTools(cfg *types.DifyConfig) []types.ToolReference {
|
|
var missing []types.ToolReference
|
|
for _, ref := range cfg.ToolReferences {
|
|
if config.FindToolByReference(cfg, &ref) == nil {
|
|
missing = append(missing, ref)
|
|
}
|
|
}
|
|
return missing
|
|
}
|