{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package workflow\n\n## Variables\n\n```go\nvar DefaultHandlerFactory func() []WorkflowHandler\n```\nDefaultHandlerFactory is a function that returns a slice of default WorkflowHandler instances. It is set by the setup package via an init function to break the import cycle between the root workflow package and the handlers package. Import \"github.com/GoCodeAlone/workflow/setup\" (typically as a blank import) to register the default factories.\n\n```go\nvar DefaultTriggerFactory func() []interfaces.Trigger\n```\nDefaultTriggerFactory is a function that returns a slice of default Trigger instances. It is set by the setup package.\n\n## Types\n\n```go\ntype Engine interface {\n\tRegisterWorkflowHandler(handler WorkflowHandler)\n\tRegisterTrigger(trigger interfaces.Trigger)\n\tAddModuleType(moduleType string, factory ModuleFactory)\n\tBuildFromConfig(cfg *config.WorkflowConfig) error\n\tStart(ctx context.Context) error\n\tStop(ctx context.Context) error\n\tTriggerWorkflow(ctx context.Context, workflowType string, action string, data map[string]any) error\n}\n```\n\n```go\ntype EngineBuilder struct {\n\t// contains filtered or unexported fields\n}\n```\nEngineBuilder provides a fluent API for constructing a fully-configured StdEngine. It encapsulates the boilerplate of registering workflow handlers, triggers, dynamic components, and plugins so that CLI tools, MCP servers, and other consumers can initialise an engine in a few lines.\n\nImport the setup package to register default handler and trigger factories:\n\n\timport (\n\t    \"github.com/GoCodeAlone/workflow\"\n\t    _ \"github.com/GoCodeAlone/workflow/setup\"\n\t)\n\n\tengine, err := workflow.NewEngineBuilder().\n\t    WithAllDefaults().\n\t    Build()\n\n```go\nfunc NewEngineBuilder() *EngineBuilder\n```\nNewEngineBuilder creates a new EngineBuilder with no defaults configured. Call With\\* methods to add capabilities, then Build() to create the engine.\n\n```go\nfunc (b *EngineBuilder) Build() (*StdEngine, error)\n```\nBuild creates a fully-configured StdEngine from the builder's settings. It returns an error if any plugin fails to load.\n\n```go\nfunc (b *EngineBuilder) BuildAndConfigure() (*StdEngine, error)\n```\nBuildAndConfigure creates a fully-configured StdEngine and loads configuration from the file path set via WithConfigPath(). Returns an error if no config path was set or the file cannot be loaded.\n\n```go\nfunc (b *EngineBuilder) BuildFromConfig(cfg *config.WorkflowConfig) (*StdEngine, error)\n```\nBuildFromConfig creates a fully-configured StdEngine and then loads and applies the configuration from the given WorkflowConfig.\n\n```go\nfunc (b *EngineBuilder) RunUntilSignal(cfg *config.WorkflowConfig) error\n```\nRunUntilSignal is a convenience method for CLI tools that creates the engine, loads config, starts it, and blocks until a termination signal (SIGINT/SIGTERM) is received. It handles graceful shutdown automatically.\n\n```go\nfunc (b *EngineBuilder) WithAllDefaults() *EngineBuilder\n```\nWithAllDefaults is a convenience method that enables default handlers, default triggers, and dynamic components. Requires importing the setup package: import \\_ \"github.com/GoCodeAlone/workflow/setup\"\n\n```go\nfunc (b *EngineBuilder) WithApplication(app modular.Application) *EngineBuilder\n```\nWithApplication sets a custom modular.Application on the builder. If not called, Build() creates a default StdApplication.\n\n```go\nfunc (b *EngineBuilder) WithConfigPath(path string) *EngineBuilder\n```\nWithConfigPath stores a config file path for use with BuildAndConfigure().\n\n```go\nfunc (b *EngineBuilder) WithDefaultHandlers() *EngineBuilder\n```\nWithDefaultHandlers registers all built-in workflow handlers: HTTP, Messaging, StateMachine, Scheduler, Integration, Pipeline, Event, Platform. Requires importing the setup package: import \\_ \"github.com/GoCodeAlone/workflow/setup\"\n\n```go\nfunc (b *EngineBuilder) WithDefaultTriggers() *EngineBuilder\n```\nWithDefaultTriggers registers all built-in triggers: HTTP, Event, Schedule, EventBus, Reconciliation. Requires importing the setup package: import \\_ \"github.com/GoCodeAlone/workflow/setup\"\n\n```go\nfunc (b *EngineBuilder) WithDynamicComponents() *EngineBuilder\n```\nWithDynamicComponents sets up the dynamic interpreter pool, component registry, and loader for scripting support.\n\n```go\nfunc (b *EngineBuilder) WithHandler(handler WorkflowHandler) *EngineBuilder\n```\nWithHandler adds a custom workflow handler to the engine.\n\n```go\nfunc (b *EngineBuilder) WithLogger(logger modular.Logger) *EngineBuilder\n```\nWithLogger sets a custom logger on the builder. If not called, Build() creates a default slog.Logger writing to stdout.\n\n```go\nfunc (b *EngineBuilder) WithPlugin(p plugin.EnginePlugin) *EngineBuilder\n```\nWithPlugin adds a plugin to be loaded during Build().\n\n```go\nfunc (b *EngineBuilder) WithPluginLoader(loader *plugin.PluginLoader) *EngineBuilder\n```\nWithPluginLoader sets a custom plugin loader on the engine.\n\n```go\nfunc (b *EngineBuilder) WithPlugins(plugins ...plugin.EnginePlugin) *EngineBuilder\n```\nWithPlugins adds multiple plugins to be loaded during Build().\n\n```go\nfunc (b *EngineBuilder) WithTrigger(trigger interfaces.Trigger) *EngineBuilder\n```\nWithTrigger adds a custom trigger to the engine.\n\n```go\ntype EngineBuilderFunc func(cfg *config.WorkflowConfig, logger *slog.Logger) (*StdEngine, modular.Application, error)\n```\nEngineBuilderFunc is called by the manager to create and configure an engine from a parsed workflow config. The caller is responsible for registering workflow handlers, dynamic components, and other setup. The function must call BuildFromConfig on the engine before returning.\n\n```go\ntype ManagedEngine struct {\n\tWorkflowID uuid.UUID\n\tEngine     *StdEngine\n\tApp        modular.Application\n\tStatus     string // \"running\", \"stopped\", \"error\"\n\tStartedAt  time.Time\n\tError      error\n\t// contains filtered or unexported fields\n}\n```\nManagedEngine holds a running workflow engine along with its metadata.\n\n```go\nfunc (me *ManagedEngine) GetEngine() module.TriggerWorkflower\n```\nGetEngine returns the underlying engine, satisfying the module.triggerableEngine interface so the CrossWorkflowRouter can trigger workflows via duck-typing.\n\n```go\ntype ModuleFactory func(name string, config map[string]any) modular.Module\n```\nModuleFactory is a function that creates a module from a name and configuration\n\n```go\ntype PipelineAdder interface {\n\tAddPipeline(name string, p interfaces.PipelineRunner)\n}\n```\nPipelineAdder is implemented by workflow handlers that can receive named pipelines. This allows the engine to add pipelines without importing the handlers package.\n\n```go\ntype RoutePipelineSetter interface {\n\tSetRoutePipeline(routePath string, pipeline interfaces.PipelineRunner)\n}\n```\nbuildPipelineSteps creates PipelineStep instances from step configurations. RoutePipelineSetter is implemented by handlers (QueryHandler, CommandHandler) that support per-route pipelines.\n\n```go\ntype StartStopModule interface {\n\tmodular.Module\n\tStart(ctx context.Context) error\n\tStop(ctx context.Context) error\n}\n```\nStartStopModule extends the basic Module interface with lifecycle methods\n\n```go\ntype StdEngine struct {\n\t// contains filtered or unexported fields\n}\n```\nStdEngine represents the workflow execution engine\n\n```go\nfunc NewStdEngine(app modular.Application, logger modular.Logger) *StdEngine\n```\nNewStdEngine creates a new workflow engine\n\n```go\nfunc (e *StdEngine) AddModuleType(moduleType string, factory ModuleFactory)\n```\nAddModuleType registers a factory function for a module type\n\n```go\nfunc (e *StdEngine) AddStepType(stepType string, factory module.StepFactory)\n```\nAddStepType registers a pipeline step factory for the given step type.\n\n```go\nfunc (e *StdEngine) App() modular.Application\n```\nApp returns the underlying modular.Application.\n\n```go\nfunc (e *StdEngine) BuildFromApplicationConfig(appCfg *config.ApplicationConfig) error\n```\nBuildFromApplicationConfig loads a multi-workflow application config and builds the engine from all referenced workflow configs. Each workflow config file is parsed independently, and their modules are merged into the shared module registry. Module name conflicts across workflow files produce a clear error.\n\nThis is the entry point for the application-level multi-workflow feature:\n\n\tapplication:\n\t  name: chat-platform\n\t  workflows:\n\t    - file: workflows/main-loop.yaml\n\t    - file: workflows/queue-assignment.yaml\n\nAll pipelines defined across workflow files share a single engine and can call each other using step.workflow\\_call.\n\n```go\nfunc (e *StdEngine) BuildFromConfig(cfg *config.WorkflowConfig) error\n```\nBuildFromConfig builds a workflow from configuration\n\n```go\nfunc (e *StdEngine) ConfigHash() string\n```\nConfigHash returns the SHA-256 hash of the most recently loaded config. Format: \"sha256:\\\u003chex\u003e\". Empty until BuildFromConfig is called.\n\n```go\nfunc (e *StdEngine) ExecutePipeline(ctx context.Context, name string, data map[string]any) (map[string]any, error)\n```\nExecutePipeline runs a named pipeline synchronously and returns its structured output. For use by Go callers (gRPC servers, tests) that don't need HTTP request/response threading.\n\nIf the pipeline uses step.pipeline\\_output, the explicitly marked output is returned. Otherwise, the pipeline's merged Current state is returned.\n\nThis goes through TriggerWorkflow so all trigger paths share the same execution code, including StepOutputs preservation via PipelineContextHolder.\n\n```go\nfunc (e *StdEngine) ExecutePipelineContext(ctx context.Context, name string, data map[string]any) (*interfaces.PipelineContext, error)\n```\nExecutePipelineContext runs a named pipeline and returns the full PipelineContext, including StepOutputs for each step. This is intended for test harnesses that need per-step output inspection. For production callers, use ExecutePipeline instead.\n\nThis goes through TriggerWorkflow so all trigger paths share the same execution code. The PipelineContextHolder captures the full context.\n\n```go\nfunc (e *StdEngine) GetApp() modular.Application\n```\nGetApp returns the underlying modular Application.\n\n```go\nfunc (e *StdEngine) GetPipeline(name string) (*module.Pipeline, bool)\n```\nGetPipeline returns the named pipeline from the engine's pipeline registry. Returns nil and false if no pipeline with the given name exists. This is useful for CLI tools (e.g., wfctl pipeline run) that need to execute a pipeline directly without starting the HTTP server.\n\n```go\nfunc (e *StdEngine) GetStepRegistry() interfaces.StepRegistrar\n```\nGetStepRegistry returns the engine's pipeline step registry.\n\n```go\nfunc (e *StdEngine) LoadPlugin(p plugin.EnginePlugin) error\n```\nLoadPlugin loads an EnginePlugin into the engine.\n\n```go\nfunc (e *StdEngine) LoadPluginWithOverride(p plugin.EnginePlugin) error\n```\nLoadPluginWithOverride loads an EnginePlugin into the engine, allowing it to override existing module, step, trigger, handler, deploy target, and sidecar provider registrations. When a duplicate type is encountered, the new factory replaces the previous one and a warning is logged, instead of returning an error. This is intended for external plugins that intentionally replace built-in defaults (e.g., replacing a mock step with a production implementation, or swapping out deploy targets/sidecar providers).\n\n```go\nfunc (e *StdEngine) LoadedPlugins() []plugin.EnginePlugin\n```\nLoadedPlugins returns all engine plugins that were loaded via LoadPlugin.\n\n```go\nfunc (e *StdEngine) PluginLoader() *plugin.PluginLoader\n```\nPluginLoader returns the engine's plugin loader, creating it lazily if needed.\n\n```go\nfunc (e *StdEngine) ReconfigureModules(ctx context.Context, changes []config.ModuleConfigChange) ([]string, error)\n```\nReconfigureModules attempts to reconfigure only the specified modules without a full engine restart. Returns modules that could not be reconfigured.\n\n```go\nfunc (e *StdEngine) RegisterTrigger(trigger interfaces.Trigger)\n```\nRegisterTrigger registers a trigger with the engine\n\n```go\nfunc (e *StdEngine) RegisterTriggerConfigWrapper(triggerType string, wrapper plugin.TriggerConfigWrapperFunc)\n```\nRegisterTriggerConfigWrapper registers a function that converts flat pipeline trigger config into the native format for a given trigger type.\n\n```go\nfunc (e *StdEngine) RegisterTriggerType(triggerType string, triggerName string)\n```\nRegisterTriggerType registers a mapping from a trigger config type key (e.g., \"reconciliation\") to a trigger Name() (e.g., \"trigger.reconciliation\"). This is used for triggers registered directly via RegisterTrigger() rather than through a plugin's TriggerFactories().\n\n```go\nfunc (e *StdEngine) RegisterWorkflowHandler(handler WorkflowHandler)\n```\nRegisterWorkflowHandler adds a workflow handler to the engine\n\n```go\nfunc (e *StdEngine) RegisteredModuleTypes() []string\n```\nRegisteredModuleTypes returns the sorted list of module type names registered with this engine (via AddModuleType or LoadPlugin).\n\n```go\nfunc (e *StdEngine) RegisteredStepTypes() []string\n```\nRegisteredStepTypes returns the sorted list of pipeline step type names registered with this engine (via AddStepType or LoadPlugin).\n\n```go\nfunc (e *StdEngine) RegisteredTriggerTypes() []string\n```\nRegisteredTriggerTypes returns the sorted list of trigger type keys registered with this engine (via RegisterTriggerType or LoadPlugin).\n\n```go\nfunc (e *StdEngine) SecretsResolver() *secrets.MultiResolver\n```\nSecretsResolver returns the engine's multi-provider secrets resolver.\n\n```go\nfunc (e *StdEngine) SetDynamicLoader(loader *dynamic.Loader)\n```\nSetDynamicLoader sets the dynamic component loader on the engine and propagates it to any loaded plugins that support it.\n\n```go\nfunc (e *StdEngine) SetDynamicRegistry(registry *dynamic.ComponentRegistry)\n```\nSetDynamicRegistry sets the dynamic component registry on the engine and propagates it to any loaded plugins that support it.\n\n```go\nfunc (e *StdEngine) SetPluginInstaller(installer *plugin.PluginInstaller)\n```\nSetPluginInstaller sets the plugin installer on the engine, enabling auto-installation of required plugins during validateRequirements.\n\n```go\nfunc (e *StdEngine) SetPluginLoader(loader *plugin.PluginLoader)\n```\nSetPluginLoader sets a custom plugin loader on the engine.\n\n```go\nfunc (e *StdEngine) Start(ctx context.Context) error\n```\nStart starts all modules and triggers\n\n```go\nfunc (e *StdEngine) Stop(ctx context.Context) error\n```\nStop stops all modules and triggers\n\n```go\nfunc (e *StdEngine) TriggerWorkflow(ctx context.Context, workflowType string, action string, data map[string]any) error\n```\nTriggerWorkflow starts a workflow based on a trigger\n\n```go\nfunc (e *StdEngine) Triggers() []interfaces.Trigger\n```\nTriggers returns the engine's registered triggers.\n\n```go\ntype WorkflowEngineManager struct {\n\t// contains filtered or unexported fields\n}\n```\nWorkflowEngineManager manages multiple concurrent workflow engine instances.\n\n```go\nfunc NewWorkflowEngineManager(wfStore store.WorkflowStore, linkStore store.CrossWorkflowLinkStore, logger *slog.Logger, engineBuilder EngineBuilderFunc) *WorkflowEngineManager\n```\nNewWorkflowEngineManager creates a new manager for workflow engine instances. The engineBuilder function is called to create each new engine instance, allowing the caller to register handlers and configure the dynamic system.\n\n```go\nfunc (m *WorkflowEngineManager) DeployWorkflow(ctx context.Context, workflowID uuid.UUID) error\n```\nDeployWorkflow loads config from the store, creates an isolated engine, and starts it.\n\n```go\nfunc (m *WorkflowEngineManager) GetStatus(workflowID uuid.UUID) (*WorkflowStatus, error)\n```\nGetStatus returns the runtime status of a workflow.\n\n```go\nfunc (m *WorkflowEngineManager) ListActive() []WorkflowStatus\n```\nListActive returns the status of all running workflows.\n\n```go\nfunc (m *WorkflowEngineManager) ReloadWorkflow(ctx context.Context, workflowID uuid.UUID) error\n```\nReloadWorkflow stops and redeploys a workflow.\n\n```go\nfunc (m *WorkflowEngineManager) Router() *module.CrossWorkflowRouter\n```\nRouter returns the cross-workflow event router.\n\n```go\nfunc (m *WorkflowEngineManager) StopAll(ctx context.Context) error\n```\nStopAll gracefully stops all running engines.\n\n```go\nfunc (m *WorkflowEngineManager) StopWorkflow(ctx context.Context, workflowID uuid.UUID) error\n```\nStopWorkflow gracefully stops a running engine.\n\n```go\ntype WorkflowHandler interface {\n\t// CanHandle returns true if this handler can process the given workflow type\n\tCanHandle(workflowType string) bool\n\n\t// ConfigureWorkflow sets up the workflow from configuration\n\tConfigureWorkflow(app modular.Application, workflowConfig any) error\n\n\t// ExecuteWorkflow executes a workflow with the given action and input data\n\tExecuteWorkflow(ctx context.Context, workflowType string, action string, data map[string]any) (map[string]any, error)\n}\n```\nWorkflowHandler interface for handling different workflow types\n\n```go\ntype WorkflowStatus struct {\n\tWorkflowID  uuid.UUID     `json:\"workflow_id\"`\n\tStatus      string        `json:\"status\"`\n\tStartedAt   time.Time     `json:\"started_at\"`\n\tUptime      time.Duration `json:\"uptime\"`\n\tError       string        `json:\"error,omitempty\"`\n\tModuleCount int           `json:\"module_count\"`\n}\n```\nWorkflowStatus describes the current runtime state of a managed workflow.\n\n","path":"github.com/GoCodeAlone/workflow","name":"workflow","synopsis":"","isRedistributable":true}
