mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-07-22 01:35:24 -04:00
ee540bc220
* feat: enhance plugin initialization with configurable parameters - Added new flags for plugin initialization, allowing users to specify author, name, description, and various permissions. - Implemented InitPluginWithFlags function to handle the new parameters and validate input. - Introduced methods to set category, language, and minimal Dify version within the plugin model. - Enhanced profile management by adding methods to set author and name directly. - Improved category and language selection with dedicated setter methods. * add enum * add tests
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
ti "github.com/charmbracelet/bubbles/textinput"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/langgenius/dify-plugin-daemon/pkg/entities/manifest_entities"
|
|
)
|
|
|
|
type versionRequire struct {
|
|
minimalDifyVersion ti.Model
|
|
|
|
warning string
|
|
}
|
|
|
|
func newVersionRequire() versionRequire {
|
|
minimalDifyVersion := ti.New()
|
|
minimalDifyVersion.Placeholder = "Minimal Dify version"
|
|
minimalDifyVersion.CharLimit = 128
|
|
minimalDifyVersion.Prompt = "Minimal Dify version (press Enter to next step): "
|
|
minimalDifyVersion.Focus()
|
|
|
|
return versionRequire{
|
|
minimalDifyVersion: minimalDifyVersion,
|
|
}
|
|
}
|
|
|
|
func (p versionRequire) MinimalDifyVersion() string {
|
|
return p.minimalDifyVersion.Value()
|
|
}
|
|
|
|
func (p versionRequire) View() string {
|
|
s := fmt.Sprintf("Edit minimal Dify version requirement, leave it blank by default\n%s\n", p.minimalDifyVersion.View())
|
|
if p.warning != "" {
|
|
s += fmt.Sprintf("\033[31m%s\033[0m\n", p.warning)
|
|
}
|
|
return s
|
|
}
|
|
|
|
func (p *versionRequire) checkRule() bool {
|
|
if p.minimalDifyVersion.Value() == "" {
|
|
p.warning = ""
|
|
return true
|
|
}
|
|
|
|
_, err := manifest_entities.NewVersion(p.minimalDifyVersion.Value())
|
|
if err != nil {
|
|
p.warning = "Invalid minimal Dify version"
|
|
return false
|
|
}
|
|
|
|
p.warning = ""
|
|
return true
|
|
}
|
|
|
|
func (p versionRequire) Update(msg tea.Msg) (subMenu, subMenuEvent, tea.Cmd) {
|
|
var cmds []tea.Cmd
|
|
|
|
switch msg := msg.(type) {
|
|
case tea.KeyMsg:
|
|
switch msg.String() {
|
|
case "ctrl+c":
|
|
return p, SUB_MENU_EVENT_NONE, tea.Quit
|
|
case "enter":
|
|
// check if empty
|
|
if !p.checkRule() {
|
|
return p, SUB_MENU_EVENT_NONE, nil
|
|
}
|
|
return p, SUB_MENU_EVENT_NEXT, nil
|
|
}
|
|
}
|
|
|
|
// update view
|
|
var cmd tea.Cmd
|
|
p.minimalDifyVersion, cmd = p.minimalDifyVersion.Update(msg)
|
|
if cmd != nil {
|
|
cmds = append(cmds, cmd)
|
|
}
|
|
|
|
return p, SUB_MENU_EVENT_NONE, tea.Batch(cmds...)
|
|
}
|
|
|
|
func (p versionRequire) Init() tea.Cmd {
|
|
return nil
|
|
}
|
|
|
|
func (p *versionRequire) SetMinimalDifyVersion(version string) {
|
|
p.minimalDifyVersion.SetValue(version)
|
|
}
|