Documentation
¶
Index ¶
- Variables
- func RegisterUnit(name string, unit ExecutableUnit)
- func Test_Json_To_Graph()
- type BranchFunc
- type ContextMap
- type ExecutableUnit
- type ExecutionResult
- type Graph
- func (g *Graph) AddBranch(name string, exec NodeFunc, branch BranchFunc)
- func (g *Graph) AddEdge(from, to string)
- func (g *Graph) AddNode(name string, node *Node)
- func (g *Graph) Branch(name string, fn NodeFunc, branch BranchFunc) *Graph
- func (g *Graph) Loop(name string, fn NodeFunc, cond LoopCondFunc) *Graph
- func (g *Graph) OnAfter(fn func(string, any, error, ContextMap)) *Graph
- func (g *Graph) OnBefore(fn func(string, ContextMap)) *Graph
- func (g *Graph) Parallel(name string, fns ...NodeFunc) *Graph
- func (g *Graph) Run(ctx context.Context, start string, state ContextMap) error
- func (g *Graph) RunWithDSL(ctx context.Context, state ContextMap) error
- func (g *Graph) StartWith(name string, fn NodeFunc) *Graph
- func (g *Graph) Then(name string, fn NodeFunc) *Graph
- type GraphJSON
- type Input
- type LoopCondFunc
- type Node
- type NodeFunc
- type NodeJSON
- type Unit
- type UnitRepository
- func (r *UnitRepository) FindUnit(name string) (*Unit, error)
- func (r *UnitRepository) ParsePhaseUnits(jsonData []byte, typeField string) ([]Unit, error)
- func (r *UnitRepository) ParsePhaseUnitsFromMap(rawList []map[string]any) ([]Unit, error)
- func (r *UnitRepository) RegisterUnit(name string, unit any)
Constants ¶
This section is empty.
Variables ¶
View Source
var UnitRegistry = map[string]ExecutableUnit{}
Functions ¶
func RegisterUnit ¶
func RegisterUnit(name string, unit ExecutableUnit)
func Test_Json_To_Graph ¶
func Test_Json_To_Graph()
Types ¶
type BranchFunc ¶
type BranchFunc func(result *ExecutionResult, state ContextMap) string
type ContextMap ¶
type ContextMap map[string]*ExecutionResult
type ExecutableUnit ¶
type ExecutableUnit interface {
GetUnitMeta() *Unit
Execute(ctx context.Context, state ContextMap, self *Node) (*ExecutionResult, error)
}
func FindUnit ¶
func FindUnit(name string) (ExecutableUnit, bool)
type ExecutionResult ¶
type ExecutionResult struct {
NodeName string `json:"node_name,omitempty"`
Data any `json:"data,omitempty"`
Stream bool `json:"stream,omitempty"`
Raw any `json:"raw,omitempty"`
Error string `json:"error,omitempty"`
}
func SimpleResult ¶
func SimpleResult(data any) *ExecutionResult
type Graph ¶
type Graph struct {
Nodes map[string]*Node
Edges map[string][]string
Hooks struct {
Before func(name string, state ContextMap)
After func(name string, result any, err error, state ContextMap)
}
// contains filtered or unexported fields
}
func BuildGraphFromJSON ¶
BuildGraphFromJSON Graph represents a directed graph structure with nodes and edges.
func NewDSLGraph ¶
func NewDSLGraph() *Graph
func (*Graph) RunWithDSL ¶
func (g *Graph) RunWithDSL(ctx context.Context, state ContextMap) error
type LoopCondFunc ¶
type LoopCondFunc func(state ContextMap) bool
type Node ¶
type Node struct {
ID string
Name string
Input *Input
Execute NodeFunc
Branch BranchFunc // 可选分支函数
Parallel bool // 是否并行节点
LoopCond func(ContextMap) bool // 可选循环条件
ExportFields []string // 导出字段,用于供下游引用
}
type NodeFunc ¶
type NodeFunc func(ctx context.Context, state ContextMap, self *Node) (*ExecutionResult, error)
type Unit ¶
type Unit struct {
ID string `json:"id"`
UnitName string `json:"unit_name,omitempty"`
DisplayName string `json:"display_name,omitempty"` // UI 显示名(如“调用接口”)
Status string `json:"status,omitempty"`
ErrMsg string `json:"err_msg,omitempty"` // 如果失败,存错误
OutputRef string `json:"output_ref,omitempty"` // 输出导出的字段名(用于 UI 显示)
}
type UnitRepository ¶
type UnitRepository struct {
Mappings map[string]reflect.Type // 存储所有单元的映射关系
// contains filtered or unexported fields
}
func (*UnitRepository) ParsePhaseUnits ¶
func (r *UnitRepository) ParsePhaseUnits(jsonData []byte, typeField string) ([]Unit, error)
func (*UnitRepository) ParsePhaseUnitsFromMap ¶
func (r *UnitRepository) ParsePhaseUnitsFromMap(rawList []map[string]any) ([]Unit, error)
func (*UnitRepository) RegisterUnit ¶
func (r *UnitRepository) RegisterUnit(name string, unit any)
region // deprecated: 使用 RegisterUnit 和 FindUnit 方法
Click to show internal directories.
Click to hide internal directories.