Class: Roast::Workflow::StepLoader
- Inherits:
-
Object
- Object
- Roast::Workflow::StepLoader
- 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
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#phase ⇒ Object
readonly
Returns the value of attribute phase.
Instance Method Summary collapse
-
#initialize(workflow, config_hash, context_path, phase: :steps) ⇒ StepLoader
constructor
A new instance of StepLoader.
-
#load(step_name, step_key: nil, is_last_step: nil, **options) ⇒ BaseStep
Finds and loads a step by name.
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
#context ⇒ Object (readonly)
Returns the value of attribute context.
23 24 25 |
# File 'lib/roast/workflow/step_loader.rb', line 23 def context @context end |
#phase ⇒ Object (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
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, **) 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, ) # 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, .merge(context_path: step_directory)) configure_step(step, name.to_s, is_last_step:) step end |