summaryrefslogtreecommitdiff
path: root/logic/providers/google/tools.rb
diff options
context:
space:
mode:
Diffstat (limited to 'logic/providers/google/tools.rb')
-rw-r--r--logic/providers/google/tools.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/logic/providers/google/tools.rb b/logic/providers/google/tools.rb
new file mode 100644
index 0000000..e1396d6
--- /dev/null
+++ b/logic/providers/google/tools.rb
@@ -0,0 +1,60 @@
+# 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