unit

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is retained for source compatibility with applications that registered units globally. New worker services clone it during construction and never share its mutable state.

Deprecated: create a Registry and pass it through worker.Options.UnitRegistry.

View Source
var ErrAlreadyRegistered = errors.New("unit already registered")

Functions

func DispatchID added in v1.2.11

func DispatchID(ctx context.Context) string

DispatchID returns the stable identity of the current node execution attempt. It is empty only when the caller supplied a legacy task without a dispatch_id. Units that perform external side effects should pass this value to the downstream system as its idempotency key.

func InputAs added in v1.2.11

func InputAs[T any](node *Node) (T, error)

InputAs 将当前 Unit Node 的输入读取为指定类型 T。 Node、Input 或 Input.Data 缺失时返回错误; 输入类型与 T 不一致时返回类型错误。

func InputObject added in v1.2.11

func InputObject(
	node *Node,
) (map[string]any, error)

InputObject 将当前 Unit Node 的输入读取为 object。 它对应 definition.InputModeObject 生成的 map[string]any。

输入存在但不是 object 时返回类型错误。

func InputObjectIfExists added in v1.2.11

func InputObjectIfExists(
	node *Node,
) (map[string]any, error)

InputObjectIfExists , 输入可以为空 , 其他等同 InputObject

func Register deprecated

func Register(name string, exec Executable) error

Deprecated: register on an application-owned Registry instead.

func RegisterFactory deprecated

func RegisterFactory(name string, factory Factory) error

Deprecated: register on an application-owned Registry instead.

func RegisterUnit deprecated

func RegisterUnit(name string, exec Executable) error

Deprecated: register on an application-owned Registry instead.

func RegisterUnitFactory deprecated

func RegisterUnitFactory(name string, factory Factory) error

Deprecated: register on an application-owned Registry instead.

Types

type ContextMap

type ContextMap map[string]*ExecutionResult

type ControlSignal

type ControlSignal string
const (
	ControlBreak    ControlSignal = "break"
	ControlContinue ControlSignal = "continue"
	ControlGoto     ControlSignal = "goto"
)

type ControlSignalError

type ControlSignalError struct {
	Signal ControlSignal
	Target string
}

func (*ControlSignalError) Error

func (e *ControlSignalError) Error() string

type Executable

type Executable interface {
	GetUnitMeta() *Unit
	Execute(ctx context.Context, state ContextMap, self *Node) (*ExecutionResult, error)
}

func Find deprecated

func Find(name string) (Executable, bool)

Deprecated: resolve from an application-owned Registry instead.

type ExecutableUnit

type ExecutableUnit = Executable

type ExecutionResult

type ExecutionResult struct {
	NodeName        string         `json:"node_name,omitempty"`
	Data            any            `json:"data,omitempty"`
	Variables       map[string]any `json:"variables,omitempty"`
	DeleteVariables []string       `json:"delete_variables,omitempty"`
	Stream          bool           `json:"stream,omitempty"`
	Raw             any            `json:"raw,omitempty"`
	Error           string         `json:"error,omitempty"`
	Control         ControlSignal  `json:"control,omitempty"`
	ControlTarget   string         `json:"control_target,omitempty"`
}

func SimpleResult

func SimpleResult(data any) *ExecutionResult

type Executor

type Executor struct {
	Registry    *Registry
	Credentials credential.Resolver
}

func NewExecutor

func NewExecutor(reg *Registry) *Executor

func NewExecutorWithCredentials

func NewExecutorWithCredentials(reg *Registry, credentials credential.Resolver) *Executor

func (*Executor) Execute

func (*Executor) Type

func (e *Executor) Type() executor.Type

type Factory

type Factory func() Executable

type Input

type Input struct {
	Data      any    `json:"data,omitempty"`
	DataType  string `json:"data_type,omitempty"`
	Slottable bool   `json:"slottable,omitempty"`
}

type Node

type Node struct {
	ID           string         `json:"id,omitempty"`
	Name         string         `json:"name,omitempty"`
	Input        *Input         `json:"input,omitempty"`
	Params       map[string]any `json:"params,omitempty"`
	ExportFields []string       `json:"export_fields,omitempty"`
}

type Registration

type Registration struct {
	Name    string
	Factory Factory
}

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Clone

func (r *Registry) Clone() *Registry

func (*Registry) Names

func (r *Registry) Names() []string

func (*Registry) New

func (r *Registry) New(name string) (Executable, bool)

func (*Registry) Register

func (r *Registry) Register(name string, factory Factory) error

func (*Registry) RegisterAll

func (r *Registry) RegisterAll(registrations ...Registration) error

RegisterAll validates the complete batch before changing the registry.

func (*Registry) RegisterInstance

func (r *Registry) RegisterInstance(name string, exec Executable) error

func (*Registry) RegisterOrReplace

func (r *Registry) RegisterOrReplace(name string, factory Factory) error

RegisterOrReplace makes replacement explicit for applications that support hot swapping. Normal startup composition should use Register.

func (*Registry) RegisterUnit

func (r *Registry) RegisterUnit(name string, exec Executable) error

func (*Registry) RegisterUnitFactory

func (r *Registry) RegisterUnitFactory(name string, factory Factory) error

func (*Registry) Registrations

func (r *Registry) Registrations() []Registration

Registrations returns a stable snapshot that can be installed into another registry without sharing mutable registry state.

type Unit

type Unit struct {
	ID          string `json:"id"`
	UnitName    string `json:"unit_name,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
	Status      string `json:"status,omitempty"`
	ErrMsg      string `json:"err_msg,omitempty"`
	OutputRef   string `json:"output_ref,omitempty"`
}

Jump to

Keyboard shortcuts

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