controllers/session.rb in nano-bots-1.0.1 vs controllers/session.rb in nano-bots-1.1.0
- old
+ new
@@ -9,10 +9,11 @@
require_relative '../logic/cartridge/safety'
require_relative '../logic/cartridge/streaming'
require_relative '../logic/cartridge/interaction'
require_relative '../logic/cartridge/fetch'
require_relative 'interfaces/tools'
+require_relative '../components/stream'
require_relative '../components/storage'
require_relative '../components/adapter'
require_relative '../components/crypto'
module NanoBot
@@ -54,16 +55,24 @@
def store_state!
File.write(@state_path, Components::Crypto.encrypt(JSON.generate(@state)))
end
def boot(mode:)
- return unless Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot instruction])
+ instruction = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot instruction])
+ return unless instruction
behavior = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors boot]) || {}
- input = { behavior:, history: [] }
+ @state[:history] << {
+ who: 'user',
+ mode: mode.to_s,
+ input: instruction,
+ message: instruction
+ }
+ input = { behavior:, history: @state[:history] }
+
process(input, mode:)
end
def evaluate_and_print(message, mode:)
behavior = Logic::Helpers::Hash.fetch(@cartridge, %i[behaviors interaction]) || {}
@@ -180,11 +189,15 @@
def flush
@stream.flush
end
- def print(content)
- @stream.write(content)
+ def print(content, meta = nil)
+ if @stream.is_a?(NanoBot::Components::Stream)
+ @stream.write(content, meta)
+ else
+ @stream.write(content)
+ end
end
end
end
end