generator

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseNodeGenerator

type BaseNodeGenerator struct {
	// contains filtered or unexported fields
}

BaseNodeGenerator provides base node generator functionality

func NewBaseNodeGenerator

func NewBaseNodeGenerator(nodeType models.NodeType) *BaseNodeGenerator

func (*BaseNodeGenerator) GetSupportedType

func (g *BaseNodeGenerator) GetSupportedType() models.NodeType

type ClassifierNodeGenerator

type ClassifierNodeGenerator struct {
	*BaseNodeGenerator
	// contains filtered or unexported fields
}

ClassifierNodeGenerator generates classifier decision nodes

func NewClassifierNodeGenerator

func NewClassifierNodeGenerator() *ClassifierNodeGenerator

func (*ClassifierNodeGenerator) GenerateNode

func (g *ClassifierNodeGenerator) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates a classifier decision node

func (*ClassifierNodeGenerator) SetNodeMapping

func (g *ClassifierNodeGenerator) SetNodeMapping(nodes []models.Node)

SetNodeMapping sets node mapping for variable selector converter

type CodeNodeGenerator

type CodeNodeGenerator struct {
	*BaseNodeGenerator
	// contains filtered or unexported fields
}

CodeNodeGenerator generates code nodes

func NewCodeNodeGenerator

func NewCodeNodeGenerator() *CodeNodeGenerator

func (*CodeNodeGenerator) GenerateNode

func (g *CodeNodeGenerator) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates a code node

func (*CodeNodeGenerator) SetNodeMapping

func (g *CodeNodeGenerator) SetNodeMapping(nodes []models.Node)

SetNodeMapping sets node mapping for variable selector converter

type ConditionNodeGenerator

type ConditionNodeGenerator struct {
	*BaseNodeGenerator
	// contains filtered or unexported fields
}

ConditionNodeGenerator generates conditional branch nodes.

func NewConditionNodeGenerator

func NewConditionNodeGenerator() *ConditionNodeGenerator

func (*ConditionNodeGenerator) GenerateNode

func (g *ConditionNodeGenerator) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates a conditional branch node.

func (*ConditionNodeGenerator) SetNodeMapping

func (g *ConditionNodeGenerator) SetNodeMapping(nodes []models.Node)

SetNodeMapping sets node mapping for variable selector converter

type DifyApp

type DifyApp struct {
	Name                string `yaml:"name"`
	Description         string `yaml:"description"`
	Icon                string `yaml:"icon"`
	IconBackground      string `yaml:"icon_background"`
	Mode                string `yaml:"mode"`
	UseIconAsAnswerIcon bool   `yaml:"use_icon_as_answer_icon"`
}

DifyApp represents Dify application metadata

type DifyDepValue

type DifyDepValue struct {
	MarketplacePluginUniqueIdentifier string `yaml:"marketplace_plugin_unique_identifier"`
}

DifyDepValue represents dependency value

type DifyDependency

type DifyDependency struct {
	CurrentIdentifier interface{}  `yaml:"current_identifier"`
	Type              string       `yaml:"type"`
	Value             DifyDepValue `yaml:"value"`
}

DifyDependency represents a Dify dependency

type DifyEdge

type DifyEdge struct {
	Data         DifyEdgeData `yaml:"data"`
	ID           string       `yaml:"id"`
	Selected     bool         `yaml:"selected,omitempty"`
	Source       string       `yaml:"source"`
	SourceHandle string       `yaml:"sourceHandle"`
	Target       string       `yaml:"target"`
	TargetHandle string       `yaml:"targetHandle"`
	Type         string       `yaml:"type"`
	ZIndex       int          `yaml:"zIndex"`
}

DifyEdge represents a Dify connection - field order strictly follows official example

type DifyEdgeData

type DifyEdgeData struct {
	IsInIteration bool   `yaml:"isInIteration,omitempty"`
	IsInLoop      bool   `yaml:"isInLoop"`
	IterationID   string `yaml:"iteration_id,omitempty"`
	SourceType    string `yaml:"sourceType"`
	TargetType    string `yaml:"targetType"`
}

DifyEdgeData represents Dify connection data - field order strictly follows official example

type DifyFeatures

type DifyFeatures struct {
	FileUpload                    DifyFileUpload                    `yaml:"file_upload"`
	OpeningStatement              string                            `yaml:"opening_statement"`
	RetrieverResource             DifyRetrieverResource             `yaml:"retriever_resource"`
	SensitiveWordAvoidance        DifySensitiveWordAvoidance        `yaml:"sensitive_word_avoidance"`
	SpeechToText                  DifySpeechToText                  `yaml:"speech_to_text"`
	SuggestedQuestions            []string                          `yaml:"suggested_questions"`
	SuggestedQuestionsAfterAnswer DifySuggestedQuestionsAfterAnswer `yaml:"suggested_questions_after_answer"`
	TextToSpeech                  DifyTextToSpeech                  `yaml:"text_to_speech"`
}

DifyFeatures represents Dify feature configuration

type DifyFileUpload

type DifyFileUpload struct {
	AllowedFileExtensions    []string             `yaml:"allowed_file_extensions"`
	AllowedFileTypes         []string             `yaml:"allowed_file_types"`
	AllowedFileUploadMethods []string             `yaml:"allowed_file_upload_methods"`
	Enabled                  bool                 `yaml:"enabled"`
	FileUploadConfig         DifyFileUploadConfig `yaml:"fileUploadConfig"`
	Image                    DifyImageConfig      `yaml:"image"`
	NumberLimits             int                  `yaml:"number_limits"`
}

DifyFileUpload represents file upload configuration

type DifyFileUploadConfig

type DifyFileUploadConfig struct {
	AudioFileSizeLimit      int `yaml:"audio_file_size_limit"`
	BatchCountLimit         int `yaml:"batch_count_limit"`
	FileSizeLimit           int `yaml:"file_size_limit"`
	ImageFileSizeLimit      int `yaml:"image_file_size_limit"`
	VideoFileSizeLimit      int `yaml:"video_file_size_limit"`
	WorkflowFileUploadLimit int `yaml:"workflow_file_upload_limit"`
}

DifyFileUploadConfig represents detailed file upload configuration

type DifyGenerator

type DifyGenerator struct {
	*common.BaseGenerator
	// contains filtered or unexported fields
}

DifyGenerator Dify DSL generator

func NewDifyGenerator

func NewDifyGenerator() *DifyGenerator

func (*DifyGenerator) Generate

func (g *DifyGenerator) Generate(unifiedDSL *models.UnifiedDSL) ([]byte, error)

Generate generates Dify DSL from unified DSL

func (*DifyGenerator) Validate

func (g *DifyGenerator) Validate(unifiedDSL *models.UnifiedDSL) error

Validate validates if the unified DSL meets Dify platform requirements

type DifyGraph

type DifyGraph struct {
	Edges []DifyEdge `yaml:"edges"`
	Nodes []DifyNode `yaml:"nodes"`
}

DifyGraph represents Dify graph structure

type DifyImageConfig

type DifyImageConfig struct {
	Enabled         bool     `yaml:"enabled"`
	NumberLimits    int      `yaml:"number_limits"`
	TransferMethods []string `yaml:"transfer_methods"`
}

DifyImageConfig represents image configuration

type DifyNode

type DifyNode struct {
	Data             DifyNodeData `yaml:"data"`
	Height           float64      `yaml:"height,omitempty"`
	ID               string       `yaml:"id"`
	Position         DifyPosition `yaml:"position"`
	PositionAbsolute DifyPosition `yaml:"positionAbsolute"`
	Selected         bool         `yaml:"selected"`
	SourcePosition   string       `yaml:"sourcePosition"`
	TargetPosition   string       `yaml:"targetPosition"`
	Type             string       `yaml:"type"`
	Width            float64      `yaml:"width,omitempty"`

	// Iteration node specific fields
	ParentID   string `yaml:"parentId,omitempty"`
	Draggable  *bool  `yaml:"draggable,omitempty"`  // Use pointer type, only shown when explicitly set
	Selectable *bool  `yaml:"selectable,omitempty"` // Use pointer type, only shown when explicitly set
	ZIndex     int    `yaml:"zIndex,omitempty"`
}

DifyNode represents a Dify node - field order consistent with official example

type DifyNodeData

type DifyNodeData struct {
	// Code node specific fields - in standard example order (code field first)
	Code         string `yaml:"code,omitempty"`
	CodeLanguage string `yaml:"code_language,omitempty"`

	// Common fields - in standard example order
	Desc     string `yaml:"desc"`
	Selected bool   `yaml:"selected"`
	Title    string `yaml:"title"`
	Type     string `yaml:"type"`

	// Iteration node specific fields - in standard example order
	ErrorHandleMode   string   `yaml:"error_handle_mode,omitempty"`
	Height            float64  `yaml:"height,omitempty"`
	IsParallel        *bool    `yaml:"is_parallel,omitempty"`
	IteratorInputType string   `yaml:"iterator_input_type,omitempty"`
	IteratorSelector  []string `yaml:"iterator_selector,omitempty"`
	OutputSelector    []string `yaml:"output_selector,omitempty"`
	OutputType        string   `yaml:"output_type,omitempty"`
	ParallelNums      int      `yaml:"parallel_nums,omitempty"`
	StartNodeID       string   `yaml:"start_node_id,omitempty"`
	Width             float64  `yaml:"width,omitempty"`

	// Iteration internal node specific fields - in standard example order
	IsInIteration bool   `yaml:"isInIteration,omitempty"`
	IsInLoop      *bool  `yaml:"isInLoop,omitempty"`
	IterationID   string `yaml:"iteration_id,omitempty"`

	// Code node output fields
	Outputs interface{} `yaml:"outputs,omitempty"`

	// Code node variable fields
	Variables interface{} `yaml:"variables,omitempty"`

	// LLM node specific fields
	Context        map[string]interface{}   `yaml:"context,omitempty"`
	Model          map[string]interface{}   `yaml:"model,omitempty"`
	PromptTemplate []map[string]interface{} `yaml:"prompt_template,omitempty"`
	Vision         map[string]interface{}   `yaml:"vision,omitempty"`

	// Other fields
	Dependencies string                 `yaml:"dependencies,omitempty"`
	Config       map[string]interface{} `yaml:"config,omitempty"`

	// Conditional node specific fields
	Cases []map[string]interface{} `yaml:"cases,omitempty"`

	// Classifier node specific fields
	Classes               []map[string]interface{} `yaml:"classes,omitempty"`
	Instruction           string                   `yaml:"instruction,omitempty"`  // Single instruction
	Instructions          string                   `yaml:"instructions,omitempty"` // Keep empty string, consistent with Dify instance
	QueryVariableSelector []string                 `yaml:"query_variable_selector,omitempty"`
	Topics                []string                 `yaml:"topics,omitempty"`
}

DifyNodeData represents Dify node data - field order strictly follows official example

type DifyOutput

type DifyOutput struct {
	Variable      string   `yaml:"variable"`
	ValueSelector []string `yaml:"value_selector"`
	ValueType     string   `yaml:"value_type"`
	Type          string   `yaml:"type,omitempty"`
}

DifyOutput represents Dify output definition

type DifyPosition

type DifyPosition struct {
	X float64 `yaml:"x"`
	Y float64 `yaml:"y"`
}

DifyPosition represents Dify position information

type DifyRetrieverResource

type DifyRetrieverResource struct {
	Enabled bool `yaml:"enabled"`
}

DifyRetrieverResource represents retriever resource configuration

type DifyRootStructure

type DifyRootStructure struct {
	App          DifyApp          `yaml:"app"`
	Dependencies []DifyDependency `yaml:"dependencies"`
	Kind         string           `yaml:"kind"`
	Version      string           `yaml:"version"`
	Workflow     DifyWorkflow     `yaml:"workflow"`
}

DifyRootStructure represents the Dify root structure

type DifySensitiveWordAvoidance

type DifySensitiveWordAvoidance struct {
	Enabled bool `yaml:"enabled"`
}

DifySensitiveWordAvoidance represents sensitive word avoidance configuration

type DifySpeechToText

type DifySpeechToText struct {
	Enabled bool `yaml:"enabled"`
}

DifySpeechToText represents speech-to-text configuration

type DifySuggestedQuestionsAfterAnswer

type DifySuggestedQuestionsAfterAnswer struct {
	Enabled bool `yaml:"enabled"`
}

DifySuggestedQuestionsAfterAnswer represents suggested questions after answer configuration

type DifyTextToSpeech

type DifyTextToSpeech struct {
	Enabled  bool   `yaml:"enabled"`
	Language string `yaml:"language"`
	Voice    string `yaml:"voice"`
}

DifyTextToSpeech represents text-to-speech configuration

type DifyVariable

type DifyVariable struct {
	Label     string   `yaml:"label"`
	MaxLength int      `yaml:"max_length,omitempty"`
	Options   []string `yaml:"options"`
	Required  bool     `yaml:"required"`
	Type      string   `yaml:"type"`
	Variable  string   `yaml:"variable"`
}

DifyVariable represents Dify variable definition - field order consistent with official example

type DifyWorkflow

type DifyWorkflow struct {
	ConversationVariables []interface{} `yaml:"conversation_variables"`
	EnvironmentVariables  []interface{} `yaml:"environment_variables"`
	Features              DifyFeatures  `yaml:"features"`
	Graph                 DifyGraph     `yaml:"graph"`
}

DifyWorkflow represents a Dify workflow

type EdgeGenerator

type EdgeGenerator struct {
	// contains filtered or unexported fields
}

EdgeGenerator generates connections

func NewEdgeGenerator

func NewEdgeGenerator() *EdgeGenerator

func (*EdgeGenerator) GenerateEdges

func (g *EdgeGenerator) GenerateEdges(edges []models.Edge, nodes []models.Node) ([]DifyEdge, error)

GenerateEdges generates Dify connections

func (*EdgeGenerator) GenerateEdgesWithIDMapping

func (g *EdgeGenerator) GenerateEdgesWithIDMapping(edges []models.Edge, nodes []models.Node, nodeIDMapping map[string]string) ([]DifyEdge, error)

GenerateEdgesWithIDMapping generates Dify connections using ID mapping

type EndNodeGenerator

type EndNodeGenerator struct {
	*BaseNodeGenerator
}

EndNodeGenerator generates end nodes

func NewEndNodeGenerator

func NewEndNodeGenerator() *EndNodeGenerator

func (*EndNodeGenerator) GenerateNode

func (g *EndNodeGenerator) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates an end node

func (*EndNodeGenerator) GenerateNodeWithWorkflowContext

func (g *EndNodeGenerator) GenerateNodeWithWorkflowContext(node models.Node, workflow *models.Workflow) (DifyNode, error)

GenerateNodeWithWorkflowContext generates an end node (with workflow context)

type IterationNodeGenerator

type IterationNodeGenerator struct {
	*BaseNodeGenerator
	// contains filtered or unexported fields
}

IterationNodeGenerator iteration node generator

func NewIterationNodeGenerator

func NewIterationNodeGenerator() *IterationNodeGenerator

func (*IterationNodeGenerator) GenerateIterationNodes

func (g *IterationNodeGenerator) GenerateIterationNodes(node models.Node) ([]DifyNode, error)

GenerateIterationNodes generates complete iteration node structure (including child nodes)

func (*IterationNodeGenerator) GenerateNode

func (g *IterationNodeGenerator) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates iteration node

func (*IterationNodeGenerator) SetNodeMapping

func (g *IterationNodeGenerator) SetNodeMapping(nodes []models.Node)

SetNodeMapping sets node mapping for variable selector converter and internal nodeMapping

type LLMNodeGenerator

type LLMNodeGenerator struct {
	*BaseNodeGenerator
	// contains filtered or unexported fields
}

LLMNodeGenerator generates LLM nodes

func NewLLMNodeGenerator

func NewLLMNodeGenerator() *LLMNodeGenerator

func (*LLMNodeGenerator) GenerateNode

func (g *LLMNodeGenerator) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates an LLM node

func (*LLMNodeGenerator) SetNodeMapping

func (g *LLMNodeGenerator) SetNodeMapping(nodes []models.Node)

SetNodeMapping sets node mapping

type NodeGenerator

type NodeGenerator interface {
	// GenerateNode generates a specific type of Dify node
	GenerateNode(node models.Node) (DifyNode, error)

	// GetSupportedType returns the supported node type
	GetSupportedType() models.NodeType
}

NodeGenerator defines the node generator interface

type NodeGeneratorFactory

type NodeGeneratorFactory struct {
	// contains filtered or unexported fields
}

NodeGeneratorFactory provides node generator factory functionality

func NewNodeGeneratorFactory

func NewNodeGeneratorFactory() *NodeGeneratorFactory

func (*NodeGeneratorFactory) GenerateNode

func (f *NodeGeneratorFactory) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates a node (convenience method)

func (*NodeGeneratorFactory) GetGenerator

func (f *NodeGeneratorFactory) GetGenerator(nodeType models.NodeType) (NodeGenerator, error)

GetGenerator returns the node generator for the specified type

func (*NodeGeneratorFactory) GetSupportedTypes

func (f *NodeGeneratorFactory) GetSupportedTypes() []models.NodeType

GetSupportedTypes returns all supported node types

func (*NodeGeneratorFactory) SetNodeMapping

func (f *NodeGeneratorFactory) SetNodeMapping(nodes []models.Node)

SetNodeMapping sets node mapping for all supported generators

type StartNodeGenerator

type StartNodeGenerator struct {
	*BaseNodeGenerator
}

StartNodeGenerator generates start nodes

func NewStartNodeGenerator

func NewStartNodeGenerator() *StartNodeGenerator

func (*StartNodeGenerator) GenerateNode

func (g *StartNodeGenerator) GenerateNode(node models.Node) (DifyNode, error)

GenerateNode generates a start node

type VariableSelectorConverter

type VariableSelectorConverter struct {
	// contains filtered or unexported fields
}

VariableSelectorConverter converts variable selectors

func NewVariableSelectorConverter

func NewVariableSelectorConverter() *VariableSelectorConverter

func (*VariableSelectorConverter) ConvertVariableReference

func (c *VariableSelectorConverter) ConvertVariableReference(ref *models.VariableReference) ([]string, error)

ConvertVariableReference converts variable reference to Dify variable selector

func (*VariableSelectorConverter) SetIterationContext

func (c *VariableSelectorConverter) SetIterationContext(iterationNodeID string)

SetIterationContext sets current iteration context for handling iteration-node-start references

func (*VariableSelectorConverter) SetNodeMapping

func (c *VariableSelectorConverter) SetNodeMapping(nodes []models.Node)

SetNodeMapping sets node mapping

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL