mirror of
https://github.com/langgenius/dify-plugin-daemon.git
synced 2026-08-27 22:30:15 -04:00
c952664139
* feat(plugin): add version requirement functionality to plugin initialization - Introduced a new `version_require` sub-menu to handle minimal Dify version input. - Updated the plugin initialization process to include the new version requirement. - Enhanced the `PluginMeta` struct to store the minimal Dify version. - Added validation for the minimal Dify version input to ensure correctness. * fix(plugin): rename MinimalDifyVersion to MinimumDifyVersion for consistency - Updated the `PluginMeta` struct to change the field name from `MinimalDifyVersion` to `MinimumDifyVersion`. - Adjusted the plugin initialization logic to reflect the new field name, ensuring proper handling of version requirements.
87 lines
1.9 KiB
Go
87 lines
1.9 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
|
|
}
|