Sha256: 80dd0deb08db53df9910b39b6e275b5438c5ad9ba7aa3979fd3c333bdd40070b

Contents?: true

Size: 1.52 KB

Versions: 14

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

require 'json'
require 'babosa'

require_relative '../../helpers/hash'

module NanoBot
  module Logic
    module Google
      module Tools
        def self.prepare(cartridge, tools)
          applies = []

          tools = Marshal.load(Marshal.dump(tools))

          tools.each do |tool|
            tool = Helpers::Hash.symbolize_keys(tool)

            cartridge.each do |candidate|
              candidate_key = candidate[:name].to_slug.normalize.gsub('-', '_')
              tool_key = tool[:functionCall][:name].to_slug.normalize.gsub('-', '_')

              next unless candidate_key == tool_key

              source = {}

              source[:clojure] = candidate[:clojure] if candidate[:clojure]
              source[:fennel] = candidate[:fennel] if candidate[:fennel]
              source[:lua] = candidate[:lua] if candidate[:lua]

              applies << {
                label: candidate[:name],
                name: tool[:functionCall][:name],
                type: 'function',
                parameters: tool[:functionCall][:args],
                source:
              }
            end
          end

          raise 'missing tool' if applies.size != tools.size

          applies
        end

        def self.adapt(cartridge)
          output = {
            name: cartridge[:name],
            description: cartridge[:description]
          }

          output[:parameters] = (cartridge[:parameters] || { type: 'object', properties: {} })

          output
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
nano-bots-3.4.0 logic/providers/google/tools.rb
nano-bots-3.3.0 logic/providers/google/tools.rb
nano-bots-3.2.0 logic/providers/google/tools.rb
nano-bots-3.0.1 logic/providers/google/tools.rb
nano-bots-3.0.0 logic/providers/google/tools.rb
nano-bots-2.5.1 logic/providers/google/tools.rb
nano-bots-2.5.0 logic/providers/google/tools.rb
nano-bots-2.4.1 logic/providers/google/tools.rb
nano-bots-2.4.0 logic/providers/google/tools.rb
nano-bots-2.3.0 logic/providers/google/tools.rb
nano-bots-2.2.0 logic/providers/google/tools.rb
nano-bots-2.1.0 logic/providers/google/tools.rb
nano-bots-2.0.0 logic/providers/google/tools.rb
nano-bots-1.2.0 logic/providers/google/tools.rb