summaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'controllers')
-rw-r--r--controllers/instance.rb2
-rw-r--r--controllers/interfaces/eval.rb21
-rw-r--r--controllers/session.rb26
3 files changed, 22 insertions, 27 deletions
diff --git a/controllers/instance.rb b/controllers/instance.rb
index 503b388..80ac9be 100644
--- a/controllers/instance.rb
+++ b/controllers/instance.rb
@@ -55,7 +55,7 @@ module NanoBot
def load_cartridge!(path)
elected_path = if path.strip == '-'
- File.expand_path('../static/cartridges/default.yml', __dir__)
+ File.expand_path('../static/cartridges/baseline.yml', __dir__)
else
Components::Storage.cartridge_path(path)
end
diff --git a/controllers/interfaces/eval.rb b/controllers/interfaces/eval.rb
index af519ab..851770b 100644
--- a/controllers/interfaces/eval.rb
+++ b/controllers/interfaces/eval.rb
@@ -4,34 +4,21 @@ require 'pry'
require 'rainbow'
require_relative '../../logic/helpers/hash'
+require_relative '../../logic/cartridge/affixes'
module NanoBot
module Controllers
module Interfaces
module Eval
def self.evaluate(input, cartridge, session)
- prefix = build_prefix(cartridge)
- postfix = build_postfix(cartridge)
+ prefix = Logic::Cartridge::Affixes.get(cartridge, :eval, :output, :prefix)
+ suffix = Logic::Cartridge::Affixes.get(cartridge, :eval, :output, :suffix)
session.print(prefix) unless prefix.nil?
session.evaluate_and_print(input, mode: 'eval')
- session.print(postfix) unless postfix.nil?
- end
-
- def self.build_prefix(cartridge)
- eval_interface = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces eval])
- return nil if eval_interface.nil?
-
- eval_interface[:prefix]
- end
-
- def self.build_postfix(cartridge)
- eval_interface = Logic::Helpers::Hash.fetch(cartridge, %i[interfaces eval])
- return "\n" if eval_interface.nil? || !eval_interface.key?(:postfix) # default
-
- eval_interface[:postfix]
+ session.print(suffix) unless suffix.nil?
end
end
end
diff --git a/controllers/session.rb b/controllers/session.rb
index 1eb600d..d61fdd5 100644
--- a/controllers/session.rb
+++ b/controllers/session.rb
@@ -5,7 +5,10 @@ require 'babosa'
require 'fileutils'
require_relative '../logic/helpers/hash'
+require_relative '../logic/cartridge/streaming'
+require_relative '../logic/cartridge/interaction'
require_relative '../components/storage'
+require_relative '../components/adapter'
module NanoBot
module Controllers
@@ -56,24 +59,22 @@ module NanoBot
def evaluate_and_print(message, mode:)
behavior = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors interaction]) || {}
- @state[:history] << ({ who: 'user', message: })
+ @state[:history] << {
+ who: 'user',
+ message: Components::Adapter.apply(
+ :input, Logic::Cartridge::Interaction.input(@cartridge, mode.to_sym, message)
+ )
+ }
input = { behavior:, history: @state[:history] }
process(input, mode:)
end
- def streaming(interface)
- provider = @provider.settings.key?(:stream) ? @provider.settings[:stream] : true
- interface = interface.key?(:stream) ? interface[:stream] : true
-
- provider && interface
- end
-
def process(input, mode:)
interface = Logic::Helpers::Hash.fetch(@cartridge, [:interfaces, mode.to_sym]) || {}
- streaming = streaming(interface)
+ streaming = Logic::Cartridge::Streaming.enabled?(@cartridge, mode.to_sym)
input[:interface] = interface
@@ -81,7 +82,14 @@ module NanoBot
ready = false
@provider.evaluate(input) do |output, finished|
+ output = Logic::Cartridge::Interaction.output(
+ @cartridge, mode.to_sym, output, streaming, finished
+ )
+
+ output[:message] = Components::Adapter.apply(:output, output[:message])
+
updated_at = Time.now
+
if finished
@state[:history] << output
self.print(output[:message]) unless streaming