parser

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: 15 Imported by: 0

Documentation

Overview

Package parser provides functionality for parsing Coze DSL nodes

Index

Constants

View Source
const (
	ResponseFormatText     = "0"
	ResponseFormatJSON     = "2"
	ResponseFormatMarkdown = "1" // Ignored in conversion
)

ResponseFormat constants for Coze LLM nodes

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseNodeParser

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

BaseNodeParser provides the base implementation for Coze node parsing.

func NewBaseNodeParser

func NewBaseNodeParser(nodeType string, variableRefSystem *models.VariableReferenceSystem) *BaseNodeParser

func (*BaseNodeParser) GetSupportedType

func (p *BaseNodeParser) GetSupportedType() string

GetSupportedType returns the supported node type.

func (*BaseNodeParser) ParseNode

func (p *BaseNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode performs basic node parsing with default implementation.

func (*BaseNodeParser) ValidateNode

func (p *BaseNodeParser) ValidateNode(cozeNode CozeNode) error

ValidateNode performs basic node validation.

type ClassifierNodeParser

type ClassifierNodeParser struct {
	*BaseNodeParser
}

ClassifierNodeParser handles parsing of classifier (intent detection) nodes

func NewClassifierNodeParser

func NewClassifierNodeParser(variableRefSystem *models.VariableReferenceSystem) *ClassifierNodeParser

NewClassifierNodeParser creates a classifier node parser instance

func (*ClassifierNodeParser) GetSupportedType

func (p *ClassifierNodeParser) GetSupportedType() string

GetSupportedType returns the supported node type

func (*ClassifierNodeParser) ParseNode

func (p *ClassifierNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode converts a Coze classifier node to unified DSL format

type CodeNodeParser

type CodeNodeParser struct {
	*BaseNodeParser
}

CodeNodeParser handles Coze code node parsing.

func (*CodeNodeParser) ParseNode

func (p *CodeNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode parses Coze code node and converts code format.

type ConfigParser

type ConfigParser interface {
	// ParseConfig parses node-specific configuration.
	ParseConfig(nodeData map[string]interface{}) (models.NodeConfig, error)
}

ConfigParser defines the interface for configuration parsing.

type CozeDSL

type CozeDSL struct {
	WorkflowID     string         `yaml:"workflowid" json:"workflowid"`
	Name           string         `yaml:"name" json:"name"`
	Description    string         `yaml:"description" json:"description"`
	Version        string         `yaml:"version" json:"version"`
	CreateTime     int64          `yaml:"createtime" json:"createtime"`
	UpdateTime     int64          `yaml:"updatetime" json:"updatetime"`
	Schema         CozeSchema     `yaml:"schema" json:"schema"`
	Nodes          []CozeNode     `yaml:"nodes" json:"nodes"`
	Edges          []CozeRootEdge `yaml:"edges" json:"edges"`
	Metadata       CozeMetadata   `yaml:"metadata" json:"metadata"`
	Dependencies   []CozeDep      `yaml:"dependencies" json:"dependencies"`
	ExportFormat   string         `yaml:"exportformat" json:"exportformat"`
	SerializedData string         `yaml:"serializeddata" json:"serializeddata"`
}

CozeDSL represents the root structure of Coze DSL

type CozeDataMeta

type CozeDataMeta struct {
	Title       string `yaml:"title" json:"title"`
	Description string `yaml:"description" json:"description"`
	Icon        string `yaml:"icon" json:"icon"`
	Subtitle    string `yaml:"subTitle" json:"subTitle"`
	MainColor   string `yaml:"maincolor" json:"maincolor"`
}

CozeDataMeta contains data metadata

type CozeDep

type CozeDep struct {
	Metadata     CozeDepMetadata `yaml:"metadata" json:"metadata"`
	ResourceID   string          `yaml:"resource_id" json:"resource_id"`
	ResourceName string          `yaml:"resource_name" json:"resource_name"`
	ResourceType string          `yaml:"resource_type" json:"resource_type"`
}

CozeDep represents dependency information

type CozeDepMetadata

type CozeDepMetadata struct {
	NodeType string `yaml:"node_type" json:"node_type"`
}

CozeDepMetadata contains dependency metadata

type CozeEdge

type CozeEdge struct {
	FromNode string `yaml:"sourceNodeID" json:"sourceNodeID"`
	FromPort string `yaml:"sourcePortID" json:"sourcePortID"`
	ToNode   string `yaml:"targetNodeID" json:"targetNodeID"`
	ToPort   string `yaml:"targetPortID" json:"targetPortID"`
}

CozeEdge represents connection between nodes (schema format)

type CozeExit

type CozeExit struct {
	TerminatePlan string `yaml:"terminateplan" json:"terminateplan"`
}

CozeExit contains exit configuration for end nodes

type CozeInput

type CozeInput struct {
	Type  string         `yaml:"type" json:"type"`
	Value CozeInputValue `yaml:"value" json:"value"`
}

CozeInput represents input configuration

type CozeInputContent

type CozeInputContent struct {
	BlockID string `yaml:"blockID" json:"blockID"`
	Name    string `yaml:"name" json:"name"`
	Source  string `yaml:"source" json:"source"`
}

CozeInputContent represents input content

type CozeInputParam

type CozeInputParam struct {
	Name  string    `yaml:"name" json:"name"`
	Input CozeInput `yaml:"input" json:"input"`
}

CozeInputParam represents input parameter

type CozeInputValue

type CozeInputValue struct {
	Content CozeInputContent `yaml:"content" json:"content"`
	RawMeta CozeRawMeta      `yaml:"rawMeta" json:"rawMeta"`
	Type    string           `yaml:"type" json:"type"`
}

CozeInputValue represents input value

type CozeInputs

type CozeInputs struct {
	InputParameters []CozeInputParam `yaml:"inputParameters" json:"inputParameters"`
}

CozeInputs contains node inputs

type CozeMetadata

type CozeMetadata struct {
	ContentType string `yaml:"content_type" json:"content_type"`
	CreatorID   string `yaml:"creator_id" json:"creator_id"`
	Mode        string `yaml:"mode" json:"mode"`
	SpaceID     string `yaml:"space_id" json:"space_id"`
}

CozeMetadata contains workflow metadata

type CozeNode

type CozeNode struct {
	ID      string        `yaml:"id" json:"id"`
	Type    string        `yaml:"type" json:"type"`
	Meta    CozeNodeMeta  `yaml:"meta" json:"meta"`
	Data    CozeNodeData  `yaml:"data" json:"data"`
	Blocks  []interface{} `yaml:"blocks" json:"blocks"`
	Edges   []interface{} `yaml:"edges" json:"edges"`
	Version string        `yaml:"version" json:"version"`
}

CozeNode represents a node in the workflow

type CozeNodeData

type CozeNodeData struct {
	Meta    CozeDataMeta    `yaml:"meta" json:"meta"`
	Outputs []CozeOutput    `yaml:"outputs,omitempty" json:"outputs,omitempty"`
	Inputs  *CozeNodeInputs `yaml:"inputs,omitempty" json:"inputs,omitempty"`
	Size    interface{}     `yaml:"size" json:"size"`
}

CozeNodeData contains node configuration data

type CozeNodeInput

type CozeNodeInput struct {
	Type  string             `yaml:"Type" json:"Type"`
	Value CozeNodeInputValue `yaml:"Value" json:"Value"`
}

CozeNodeInput represents node input

type CozeNodeInputContent

type CozeNodeInputContent struct {
	BlockID string `yaml:"blockID" json:"blockID"`
	Name    string `yaml:"name" json:"name"`
	Source  string `yaml:"source" json:"source"`
}

CozeNodeInputContent represents node input content

type CozeNodeInputParam

type CozeNodeInputParam struct {
	Name      string        `yaml:"name" json:"name"`
	Input     CozeNodeInput `yaml:"input" json:"input"`
	Left      interface{}   `yaml:"left" json:"left"`
	Right     interface{}   `yaml:"right" json:"right"`
	Variables []interface{} `yaml:"variables" json:"variables"`
}

CozeNodeInputParam represents node input parameter

type CozeNodeInputRawMeta

type CozeNodeInputRawMeta struct {
	Type int `yaml:"type" json:"type"`
}

CozeNodeInputRawMeta contains node input raw metadata

type CozeNodeInputValue

type CozeNodeInputValue struct {
	Type    string               `yaml:"type" json:"type"`
	Content CozeNodeInputContent `yaml:"content" json:"content"`
	RawMeta CozeNodeInputRawMeta `yaml:"rawmeta" json:"rawmeta"`
}

CozeNodeInputValue represents node input value

type CozeNodeInputs

type CozeNodeInputs struct {
	InputParameters    []CozeNodeInputParam `yaml:"inputParameters,omitempty" json:"inputParameters,omitempty"`
	InputParametersAlt []CozeNodeInputParam `yaml:"inputparameters,omitempty" json:"inputparameters,omitempty"` // Alternative lowercase version
	Branches           []interface{}        `yaml:"branches,omitempty" json:"branches,omitempty"`               // For selector nodes
	SettingOnError     interface{}          `yaml:"settingonerror" json:"settingonerror"`
	NodeBatchInfo      interface{}          `yaml:"nodebatchinfo" json:"nodebatchinfo"`
	LLMParam           interface{}          `yaml:"llmparam" json:"llmparam"`
	OutputEmitter      interface{}          `yaml:"outputemitter" json:"outputemitter"`
	Exit               *CozeExit            `yaml:"exit,omitempty" json:"exit,omitempty"`
	LLM                interface{}          `yaml:"llm" json:"llm"`
	Loop               interface{}          `yaml:"loop" json:"loop"`
	Selector           interface{}          `yaml:"selector" json:"selector"`
	TextProcessor      interface{}          `yaml:"textprocessor" json:"textprocessor"`
	SubWorkflow        interface{}          `yaml:"subworkflow" json:"subworkflow"`
	IntentDetector     interface{}          `yaml:"intentdetector" json:"intentdetector"`
	DatabaseNode       interface{}          `yaml:"databasenode" json:"databasenode"`
	HTTPRequestNode    interface{}          `yaml:"httprequestnode" json:"httprequestnode"`
	Knowledge          interface{}          `yaml:"knowledge" json:"knowledge"`
	CodeRunner         interface{}          `yaml:"coderunner" json:"coderunner"`
	PluginAPIParam     interface{}          `yaml:"pluginapiparam" json:"pluginapiparam"`
	VariableAggregator interface{}          `yaml:"variableaggregator" json:"variableaggregator"`
	VariableAssigner   interface{}          `yaml:"variableassigner" json:"variableassigner"`
	QA                 interface{}          `yaml:"qa" json:"qa"`
	Batch              interface{}          `yaml:"batch" json:"batch"`
	Comment            interface{}          `yaml:"comment" json:"comment"`
	InputReceiver      interface{}          `yaml:"inputreceiver" json:"inputreceiver"`
}

CozeNodeInputs contains node inputs for the main nodes section

type CozeNodeMeta

type CozeNodeMeta struct {
	Position CozePosition `yaml:"position" json:"position"`
}

CozeNodeMeta contains node positioning metadata

type CozeNodeMetaInfo

type CozeNodeMetaInfo struct {
	Description string `yaml:"description" json:"description"`
	Icon        string `yaml:"icon" json:"icon"`
	SubTitle    string `yaml:"subTitle" json:"subTitle"`
	Title       string `yaml:"title" json:"title"`
}

CozeNodeMetaInfo contains node metadata info

type CozeOutput

type CozeOutput struct {
	Name     string      `yaml:"name" json:"name"`
	Required bool        `yaml:"required" json:"required"`
	Type     string      `yaml:"type" json:"type"`
	Schema   interface{} `yaml:"schema,omitempty" json:"schema,omitempty"` // Flexible schema support for arrays, objects, etc.
}

CozeOutput represents node output specification

type CozeOutputSchema

type CozeOutputSchema struct {
	Type   string      `yaml:"type,omitempty" json:"type,omitempty"`
	Schema interface{} `yaml:"schema,omitempty" json:"schema,omitempty"` // Flexible schema support
	Name   string      `yaml:"name,omitempty" json:"name,omitempty"`
}

CozeOutputSchema represents output schema information - support flexible schema formats

type CozeParser

type CozeParser struct {
	*common.BaseParser
	// contains filtered or unexported fields
}

CozeParser parses Coze DSL to unified format.

func NewCozeParser

func NewCozeParser() *CozeParser

func (*CozeParser) Parse

func (p *CozeParser) Parse(data []byte) (*models.UnifiedDSL, error)

Parse parses Coze DSL to unified format.

func (*CozeParser) SetVerbose

func (p *CozeParser) SetVerbose(verbose bool)

SetVerbose sets the verbose mode for debugging output

func (*CozeParser) Validate

func (p *CozeParser) Validate(data []byte) error

Validate validates Coze DSL format.

type CozePosition

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

CozePosition represents node position

type CozeRawMeta

type CozeRawMeta struct {
	Type int `yaml:"type" json:"type"`
}

CozeRawMeta contains raw metadata

type CozeRootEdge

type CozeRootEdge struct {
	FromNode string `yaml:"from_node" json:"from_node"`
	FromPort string `yaml:"from_port" json:"from_port"`
	ToNode   string `yaml:"to_node" json:"to_node"`
	ToPort   string `yaml:"to_port" json:"to_port"`
}

CozeRootEdge represents connection between nodes (root level format)

type CozeSchema

type CozeSchema struct {
	Edges    []CozeSchemaEdge `yaml:"edges" json:"edges"`
	Nodes    []CozeSchemaNode `yaml:"nodes" json:"nodes"`
	Versions CozeVersions     `yaml:"versions" json:"versions"`
}

CozeSchema contains schema information

type CozeSchemaEdge

type CozeSchemaEdge struct {
	SourceNodeID string `yaml:"sourceNodeID" json:"sourceNodeID"`
	SourcePortID string `yaml:"sourcePortID,omitempty" json:"sourcePortID,omitempty"`
	TargetNodeID string `yaml:"targetNodeID" json:"targetNodeID"`
	TargetPortID string `yaml:"targetPortID,omitempty" json:"targetPortID,omitempty"`
}

CozeSchemaEdge represents schema edge

type CozeSchemaNode

type CozeSchemaNode struct {
	Data   CozeSchemaNodeData `yaml:"data" json:"data"`
	ID     string             `yaml:"id" json:"id"`
	Meta   CozeNodeMeta       `yaml:"meta" json:"meta"`
	Type   string             `yaml:"type" json:"type"`
	Blocks []interface{}      `yaml:"blocks,omitempty" json:"blocks,omitempty"` // For iteration nodes
	Edges  []interface{}      `yaml:"edges,omitempty" json:"edges,omitempty"`   // For iteration nodes
}

CozeSchemaNode represents schema node

type CozeSchemaNodeData

type CozeSchemaNodeData struct {
	NodeMeta          CozeNodeMetaInfo `yaml:"nodeMeta" json:"nodeMeta"`
	Outputs           []CozeOutput     `yaml:"outputs,omitempty" json:"outputs,omitempty"`
	TriggerParameters []CozeOutput     `yaml:"trigger_parameters,omitempty" json:"trigger_parameters,omitempty"`
	Inputs            *CozeInputs      `yaml:"inputs,omitempty" json:"inputs,omitempty"`
	TerminatePlan     string           `yaml:"terminatePlan,omitempty" json:"terminatePlan,omitempty"`
}

CozeSchemaNodeData contains schema node data

type CozeVersions

type CozeVersions struct {
	Loop string `yaml:"loop" json:"loop"`
}

CozeVersions contains version information

type EndNodeParser

type EndNodeParser struct {
	*BaseNodeParser
	// contains filtered or unexported fields
}

EndNodeParser parses Coze end nodes.

func (*EndNodeParser) GetSupportedType

func (p *EndNodeParser) GetSupportedType() string

GetSupportedType returns supported node type.

func (*EndNodeParser) ParseNode

func (p *EndNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode parses Coze end node.

func (*EndNodeParser) SetSkippedNodeIDs

func (p *EndNodeParser) SetSkippedNodeIDs(skippedNodeIDs map[string]bool)

SetSkippedNodeIDs sets skipped node IDs.

func (*EndNodeParser) ValidateNode

func (p *EndNodeParser) ValidateNode(cozeNode CozeNode) error

ValidateNode validates Coze end node.

type IterationNodeParser

type IterationNodeParser struct {
	*BaseNodeParser
}

IterationNodeParser parses Coze iteration nodes.

func NewIterationNodeParser

func NewIterationNodeParser(variableRefSystem *models.VariableReferenceSystem) *IterationNodeParser

func (*IterationNodeParser) GetSupportedType

func (p *IterationNodeParser) GetSupportedType() string

GetSupportedType returns the supported node type.

func (*IterationNodeParser) ParseNode

func (p *IterationNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode parses a Coze iteration node into unified DSL.

type LLMNodeParser

type LLMNodeParser struct {
	*BaseNodeParser
}

LLMNodeParser parses Coze LLM nodes.

func NewLLMNodeParser

func NewLLMNodeParser(variableRefSystem *models.VariableReferenceSystem) *LLMNodeParser

func (*LLMNodeParser) GetSupportedType

func (p *LLMNodeParser) GetSupportedType() string

GetSupportedType returns the supported node type.

func (*LLMNodeParser) ParseNode

func (p *LLMNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode parses a Coze LLM node into unified DSL.

type NodeParser

type NodeParser interface {
	// GetSupportedType returns the supported node type.
	GetSupportedType() string

	// ParseNode parses a node.
	ParseNode(cozeNode CozeNode) (*models.Node, error)

	// ValidateNode validates node data.
	ValidateNode(cozeNode CozeNode) error
}

NodeParser defines the interface for Coze node parsing.

func NewCodeNodeParser

func NewCodeNodeParser(variableRefSystem *models.VariableReferenceSystem) NodeParser

func NewEndNodeParser

func NewEndNodeParser(vrs *models.VariableReferenceSystem) NodeParser

type NodeParserFactory

type NodeParserFactory interface {
	// CreateParser creates a parser.
	CreateParser(nodeType string, variableRefSystem *models.VariableReferenceSystem) (NodeParser, error)

	// GetSupportedTypes returns supported node types.
	GetSupportedTypes() []string
}

NodeParserFactory defines the interface for node parser factory.

type ParserFactory

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

ParserFactory creates Coze node parsers.

func NewParserFactory

func NewParserFactory() *ParserFactory

func (*ParserFactory) CreateParser

func (f *ParserFactory) CreateParser(nodeType string, variableRefSystem *models.VariableReferenceSystem) (NodeParser, error)

CreateParser creates a parser.

func (*ParserFactory) CreateParserWithFallback

func (f *ParserFactory) CreateParserWithFallback(nodeType string, variableRefSystem *models.VariableReferenceSystem) (NodeParser, bool, error)

CreateParserWithFallback creates a parser with graceful fallback support

func (*ParserFactory) GetSupportedTypes

func (f *ParserFactory) GetSupportedTypes() []string

GetSupportedTypes returns supported node types.

func (*ParserFactory) ParseNodeWithFallback

func (f *ParserFactory) ParseNodeWithFallback(cozeNode CozeNode, variableRefSystem *models.VariableReferenceSystem) (*models.Node, bool, error)

ParseNodeWithFallback parses a node using fallback mechanism

func (*ParserFactory) Register

func (f *ParserFactory) Register(nodeType string, creator func(*models.VariableReferenceSystem) NodeParser)

Register registers a parser.

type SelectorNodeParser

type SelectorNodeParser struct {
	*BaseNodeParser
}

SelectorNodeParser parses Coze selector nodes.

func NewSelectorNodeParser

func NewSelectorNodeParser(variableRefSystem *models.VariableReferenceSystem) *SelectorNodeParser

func (*SelectorNodeParser) GetSupportedType

func (p *SelectorNodeParser) GetSupportedType() string

GetSupportedType returns the supported node type.

func (*SelectorNodeParser) ParseNode

func (p *SelectorNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode parses a Coze selector node into unified DSL.

type StartNodeParser

type StartNodeParser struct {
	*BaseNodeParser
}

StartNodeParser parses start nodes.

func NewStartNodeParser

func NewStartNodeParser(variableRefSystem *models.VariableReferenceSystem) *StartNodeParser

func (*StartNodeParser) ParseNode

func (p *StartNodeParser) ParseNode(cozeNode CozeNode) (*models.Node, error)

ParseNode parses start node.

Jump to

Keyboard shortcuts

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