workflow

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

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

func BuildGraphFromJSON(data []byte) (*Graph, error)

BuildGraphFromJSON Graph represents a directed graph structure with nodes and edges.

func NewDSLGraph

func NewDSLGraph() *Graph

func (*Graph) AddBranch

func (g *Graph) AddBranch(name string, exec NodeFunc, branch BranchFunc)

func (*Graph) AddEdge

func (g *Graph) AddEdge(from, to string)

func (*Graph) AddNode

func (g *Graph) AddNode(name string, node *Node)

func (*Graph) Branch

func (g *Graph) Branch(name string, fn NodeFunc, branch BranchFunc) *Graph

func (*Graph) Loop

func (g *Graph) Loop(name string, fn NodeFunc, cond LoopCondFunc) *Graph

func (*Graph) OnAfter

func (g *Graph) OnAfter(fn func(string, any, error, ContextMap)) *Graph

func (*Graph) OnBefore

func (g *Graph) OnBefore(fn func(string, ContextMap)) *Graph

func (*Graph) Parallel

func (g *Graph) Parallel(name string, fns ...NodeFunc) *Graph

func (*Graph) Run

func (g *Graph) Run(ctx context.Context, start string, state ContextMap) error

func (*Graph) RunWithDSL

func (g *Graph) RunWithDSL(ctx context.Context, state ContextMap) error

func (*Graph) StartWith

func (g *Graph) StartWith(name string, fn NodeFunc) *Graph

func (*Graph) Then

func (g *Graph) Then(name string, fn NodeFunc) *Graph

type GraphJSON

type GraphJSON struct {
	Nodes map[string]NodeJSON `json:"nodes"`
	Edges map[string][]string `json:"edges"`
}

type Input

type Input struct {
	Data      any    `json:"data,omitempty"`      //最终输出
	DataType  string `json:"data_type,omitempty"` // plaintext, json, json_array,socket
	Slottable bool   `json:"slottable,omitempty"` // 是否是可插槽的
}

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 NodeJSON

type NodeJSON struct {
	UnitID string         `json:"unit_id"`
	Name   string         `json:"name"`
	Input  *Input         `json:"input,omitempty"`
	Params map[string]any `json:"params,omitempty"`
}

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) FindUnit

func (r *UnitRepository) FindUnit(name string) (*Unit, error)

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 方法

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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