Class: Roast::Workflow::StepLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/roast/workflow/step_loader.rb

Overview

Handles loading and instantiation of workflow steps

Defined Under Namespace

Classes: StepExecutionError, StepLoaderError, StepNotFoundError

Constant Summary collapse

DEFAULT_MODEL =
"gpt-4o-mini"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow, config_hash, context_path, phase: :steps) ⇒ StepLoader

Returns a new instance of StepLoader.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/roast/workflow/step_loader.rb', line 27

def initialize(workflow, config_hash, context_path, phase: :steps)
  # Support both old and new initialization patterns
  @context = if workflow.is_a?(WorkflowContext)
    workflow
  else
    WorkflowContext.new(
      workflow: workflow,
      config_hash: config_hash,
      context_path: context_path,
    )
  end
  @phase = phase
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



23
24
25
# File 'lib/roast/workflow/step_loader.rb', line 23

def context
  @context
end

#phaseObject (readonly)

Returns the value of attribute phase.



23
24
25
# File 'lib/roast/workflow/step_loader.rb', line 23

def phase
  @phase
end

Instance Method Details

#load(step_name, step_key: nil, is_last_step: nil, **options) ⇒ BaseStep

Finds and loads a step by name

Parameters:

  • step_name (String, StepName)

    The name of the step to load

  • step_key (String) (defaults to: nil)

    The configuration key for the step (optional)

  • options (Hash)

    Additional options for step loading

Returns:

  • (BaseStep)

    The loaded step instance



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/roast/workflow/step_loader.rb', line 47

def load(step_name, step_key: nil, is_last_step: nil, **options)
  name = step_name.is_a?(Roast::ValueObjects::StepName) ? step_name : Roast::ValueObjects::StepName.new(step_name)

  # Get step config for per-step path
  step_config = config_hash[name.to_s] || {}
  per_step_path = step_config["path"]

  # First check for a prompt step (contains spaces)
  if name.plain_text?
    step = StepFactory.create(workflow, name, options)
    # Use step_key for configuration if provided, otherwise use name
    config_key = step_key || name.to_s
    configure_step(step, config_key, is_last_step:)
    return step
  end

  # Look for Ruby or shell script file in various locations
  step_file_info = find_step_file(name.to_s, per_step_path)
  if step_file_info
    case step_file_info[:type]
    when :ruby
      return load_ruby_step(step_file_info[:path], name.to_s, is_last_step:)
    when :shell
      return load_shell_script_step(step_file_info[:path], name.to_s, step_key, is_last_step:)
    end
  end

  # Look for step directory
  step_directory = find_step_directory(name.to_s, per_step_path)
  unless step_directory
    raise StepNotFoundError.new("Step directory or file not found: #{name}", step_name: name.to_s)
  end

  # Use factory to create the appropriate step instance
  step = StepFactory.create(workflow, name, options.merge(context_path: step_directory))
  configure_step(step, name.to_s, is_last_step:)
  step
end