summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dslkeywords/file.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/dslkeywords/file.rb b/lib/dslkeywords/file.rb
index 81f5f29..08f8f48 100644
--- a/lib/dslkeywords/file.rb
+++ b/lib/dslkeywords/file.rb
@@ -221,13 +221,15 @@ module RCM
def evaluate_agent_processing!
raise MissingAgentInput, "File #{@file_path} does not exist for agent processing" unless ::File.file?(@file_path)
+ agent_definition, prompt_definition = agent_configuration!
+
if option :dry
info "Processing #{@file_path} with agent #{@agent_name} and prompt #{@prompt_name} - dry run!"
return
end
input = ::File.read(@file_path)
- output = run_agent!(input)
+ output = run_agent!(input, agent_definition, prompt_definition)
create_parent_directory! unless ::File.directory?(::File.dirname(@file_path))
write!(output)
end
@@ -261,12 +263,7 @@ module RCM
# rubocop:enable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
- def run_agent!(input)
- agent_definition = dsl.object!(AgentDefinition, @agent_name,
- error_class: DSL::NoSuchAgentDefinition, kind: 'agent')
- prompt_definition = dsl.object!(PromptDefinition, @prompt_name,
- error_class: DSL::NoSuchPromptDefinition, kind: 'prompt')
-
+ def run_agent!(input, agent_definition, prompt_definition)
Tempfile.create(['rcm-agent-input', '.txt']) do |tmp|
tmp.write(input)
tmp.flush
@@ -285,6 +282,13 @@ module RCM
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
+ def agent_configuration!
+ [
+ dsl.object!(AgentDefinition, @agent_name, error_class: DSL::NoSuchAgentDefinition, kind: 'agent'),
+ dsl.object!(PromptDefinition, @prompt_name, error_class: DSL::NoSuchPromptDefinition, kind: 'prompt')
+ ]
+ end
+
def render_agent_command(template, prompt_text, input_path)
command = template.dup
command.gsub!(/\bINPUT\b/, Shellwords.escape(input_path))