participant

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmitParticipant

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

EmitParticipant publishes a named event to the event hub.

When Ack is true, it waits for the publish to be confirmed (using the participant timeout from the step context). If the ack times out:

  • OnTimeout == "skip" → returns success with ack:false in the result
  • OnTimeout == "" or "fail" (default) → returns an error

func NewEmit

func NewEmit(def model.Participant, hub *eventhub.Hub) *EmitParticipant

NewEmit constructs an EmitParticipant from a participant definition and a Hub reference. hub may be nil in tests that do not require real pub/sub.

func (*EmitParticipant) Execute

func (e *EmitParticipant) Execute(ctx context.Context, _ any) (any, error)

Execute publishes the configured event via the event hub and returns a structured result map: {event, payload, ack}.

The ctx passed by the engine already carries the participant's timeout deadline (from withStepTimeout). For ack mode, Execute uses that deadline directly through PublishAndWaitAck.

func (*EmitParticipant) WithDefinition

func (e *EmitParticipant) WithDefinition(def model.Participant) *EmitParticipant

WithDefinition returns a copy configured from def, preserving the Hub reference.

type ExecParticipant

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

ExecParticipant executes a shell command via sh -c, piping input to stdin and capturing stdout as the output value. It respects context cancellation/timeouts and injects additional environment variables on top of the current process environment.

func NewExec

func NewExec(def model.Participant, extraEnv map[string]string) *ExecParticipant

NewExec constructs an ExecParticipant from a participant definition and an optional map of extra environment variables (e.g. workflow env.* values). The extra variables are merged on top of the current process environment.

func (*ExecParticipant) Execute

func (e *ExecParticipant) Execute(ctx context.Context, input any) (any, error)

Execute runs the configured shell command. If input is non-nil it is written to the command's stdin: strings are written verbatim; all other values are JSON-marshalled first. Stdout is returned as the output string. If the command exits with a non-zero status the error includes the captured stderr.

func (*ExecParticipant) WithDefinition

func (e *ExecParticipant) WithDefinition(def model.Participant) *ExecParticipant

WithDefinition returns a copy configured from def while preserving the environment injection from the receiver.

type HTTPParticipant

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

HTTPParticipant executes an HTTP request built from the participant definition. It respects context cancellation/timeouts passed to Execute.

func NewHTTP

func NewHTTP(def model.Participant, client *http.Client) *HTTPParticipant

NewHTTP constructs an HTTPParticipant from a participant definition. An optional *http.Client may be supplied for testing; if nil the default client is used.

func (*HTTPParticipant) Execute

func (h *HTTPParticipant) Execute(ctx context.Context, input any) (any, error)

Execute builds and sends the configured HTTP request. If the participant definition has no body, input is used as the request body instead. Strings are written verbatim; all other values are JSON-marshalled. The raw response body is returned as a string on success. Non-2xx status codes are treated as errors.

func (*HTTPParticipant) WithDefinition

func (h *HTTPParticipant) WithDefinition(def model.Participant) *HTTPParticipant

WithDefinition returns a copy configured from def while preserving the HTTP client from the receiver. It is used when workflow runtime values are resolved dynamically (e.g. CEL-evaluated URL/headers/body).

type MCPExecutor

type MCPExecutor interface {
	Participant
	// SetServer configures the MCP server endpoint.
	SetServer(server string)
	// SetTool configures the MCP tool/operation to invoke.
	SetTool(tool string)
}

MCPExecutor is the interface that v2 MCP implementations must satisfy. It extends Participant with MCP-specific configuration so the engine can configure the server endpoint and operation before calling Execute.

type MCPParticipant

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

MCPParticipant provides a deterministic baseline implementation for the "mcp" participant type. It returns the configured server/tool and input.

func NewMCP

func NewMCP(def model.Participant) *MCPParticipant

NewMCP constructs an MCPParticipant from a participant definition.

func (*MCPParticipant) Execute

func (m *MCPParticipant) Execute(_ context.Context, input any) (any, error)

Execute returns a structured response with server/tool metadata.

func (*MCPParticipant) SetServer

func (m *MCPParticipant) SetServer(server string)

SetServer configures the MCP endpoint for future executions.

func (*MCPParticipant) SetTool

func (m *MCPParticipant) SetTool(tool string)

SetTool configures the tool/operation to be invoked on the MCP server.

type Participant

type Participant interface {
	Execute(ctx context.Context, input any) (any, error)
}

Participant is the execution interface that all participant types must implement.

func BuildOne

func BuildOne(def model.Participant, env map[string]string, runnerFn SubWorkflowRunnerFunc, hub *eventhub.Hub) (Participant, error)

BuildOne instantiates a single participant from its definition. Exported so the engine can build anonymous inline participants on the fly.

type Registry

type Registry map[string]Participant

Registry maps participant names to their Participant implementations. The engine resolves each flow step's participant name against this registry before invoking Execute.

func BuildRegistry

func BuildRegistry(wf *model.Workflow, env map[string]string, runnerFn SubWorkflowRunnerFunc, hub *eventhub.Hub) (Registry, error)

BuildRegistry constructs a Registry from the participants map in a workflow definition. Each participant definition is instantiated as the appropriate Participant implementation.

env is the process-level environment map (env.* values) forwarded to exec and workflow participants. runnerFn is the sub-workflow execution callback required by WorkflowParticipant; it must not be nil when any participant has type "workflow". hub is the event hub used by emit participants; it may be nil in unit tests that do not exercise emit.

type SubWorkflowRunnerFunc

type SubWorkflowRunnerFunc func(ctx context.Context, path string, inputs map[string]any, env map[string]string) (any, error)

SubWorkflowRunnerFunc is the signature for a function that can parse and execute a sub-workflow file end-to-end. The implementation is provided by the wiring layer (e.g. the CLI) so that the participant package does not need to import the engine package and create a circular dependency.

path is the file-system path to the sub-workflow YAML file. inputs are the evaluated key/value pairs mapped from the parent step input. env contains the inherited environment variable map (env.*).

The function returns the child workflow's output or an error.

type WorkflowParticipant

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

WorkflowParticipant executes a sub-workflow defined in a separate YAML file. It passes the evaluated step input as the child workflow's inputs, inherits the parent's environment variables, and returns the child's output as its own Execute result.

func NewWorkflow

func NewWorkflow(path string, env map[string]string, runnerFn SubWorkflowRunnerFunc) (*WorkflowParticipant, error)

NewWorkflow constructs a WorkflowParticipant. path is the file-system path to the referenced sub-workflow YAML file. env is the parent workflow's environment variable map, inherited by the child execution. runnerFn is called by Execute to parse and run the sub-workflow; it must not be nil.

func (*WorkflowParticipant) Execute

func (w *WorkflowParticipant) Execute(ctx context.Context, input any) (any, error)

Execute runs the referenced sub-workflow. input is the evaluated step input (typically a map[string]any produced by CEL evaluation). nil input results in an empty inputs map being passed to the child workflow. The child's output is returned directly as this step's output.

func (*WorkflowParticipant) WithPath

func (w *WorkflowParticipant) WithPath(path string) *WorkflowParticipant

WithPath returns a copy of the participant configured with a different workflow path, preserving env and runner function.

Jump to

Keyboard shortcuts

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