llama_bot_rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +249 -0
  4. data/Rakefile +8 -0
  5. data/app/assets/config/llama_bot_rails_manifest.js +1 -0
  6. data/app/assets/javascripts/llama_bot_rails/application.js +7 -0
  7. data/app/assets/javascripts/llama_bot_rails/chat.js +13 -0
  8. data/app/assets/stylesheets/llama_bot_rails/application.css +15 -0
  9. data/app/channels/llama_bot_rails/application_cable/channel.rb +8 -0
  10. data/app/channels/llama_bot_rails/application_cable/connection.rb +13 -0
  11. data/app/channels/llama_bot_rails/chat_channel.rb +306 -0
  12. data/app/controllers/llama_bot_rails/agent_controller.rb +72 -0
  13. data/app/controllers/llama_bot_rails/application_controller.rb +4 -0
  14. data/app/helpers/llama_bot_rails/application_helper.rb +4 -0
  15. data/app/javascript/channels/consumer.js +4 -0
  16. data/app/jobs/llama_bot_rails/application_job.rb +4 -0
  17. data/app/models/llama_bot_rails/application_record.rb +5 -0
  18. data/app/views/layouts/llama_bot_rails/application.html.erb +17 -0
  19. data/app/views/llama_bot_rails/agent/chat.html.erb +962 -0
  20. data/bin/rails +26 -0
  21. data/bin/rubocop +8 -0
  22. data/config/initializers/llama_bot_rails.rb +2 -0
  23. data/config/routes.rb +6 -0
  24. data/lib/llama_bot_rails/agent_state_builder.rb +17 -0
  25. data/lib/llama_bot_rails/engine.rb +23 -0
  26. data/lib/llama_bot_rails/llama_bot.rb +25 -0
  27. data/lib/llama_bot_rails/tools/rails_console_tool.rb +20 -0
  28. data/lib/llama_bot_rails/version.rb +3 -0
  29. data/lib/llama_bot_rails.rb +10 -0
  30. data/lib/tasks/llama_bot_rails_tasks.rake +4 -0
  31. metadata +128 -0
data/bin/rails ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path("..", __dir__)
6
+ ENGINE_PATH = File.expand_path("../lib/llama_bot_rails/engine", __dir__)
7
+ APP_PATH = File.expand_path("../spec/dummy/config/application", __dir__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
11
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
12
+
13
+ require "rails"
14
+ # Pick the frameworks you want:
15
+ require "active_model/railtie"
16
+ require "active_job/railtie"
17
+ require "active_record/railtie"
18
+ require "active_storage/engine"
19
+ require "action_controller/railtie"
20
+ # require "action_mailer/railtie"
21
+ # require "action_mailbox/engine"
22
+ # require "action_text/engine"
23
+ require "action_view/railtie"
24
+ require "action_cable/engine"
25
+ # require "rails/test_unit/railtie"
26
+ require "rails/engine/commands"
data/bin/rubocop ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ require "bundler/setup"
4
+
5
+ # explicit rubocop config increases performance slightly while avoiding config confusion.
6
+ ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__))
7
+
8
+ load Gem.bin_path("rubocop", "rubocop")
@@ -0,0 +1,2 @@
1
+ # Ensure LlamaBotRails files are loaded
2
+ Rails.application.config.paths.add 'lib', eager_load: true
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ LlamaBotRails::Engine.routes.draw do
2
+ post "agent/command", to: "agent#command"
3
+ get "agent/chat", to: "agent#chat"
4
+ get "agent/threads", to: "agent#threads"
5
+ get "agent/chat-history/:thread_id", to: "agent#chat_history"
6
+ end
@@ -0,0 +1,17 @@
1
+ module LlamaBotRails
2
+ class AgentStateBuilder
3
+ def initialize(params:, context:)
4
+ @params = params
5
+ @context = context
6
+ end
7
+
8
+ def build
9
+ {
10
+ user_message: @params[:message], # Rails param from JS/chat UI
11
+ thread_id: @context[:thread_id],
12
+ api_token: @context[:api_token],
13
+ agent_name: "llamabot" #Very important. This routes to the appropriate LangGraph agent as defined in langgraph.json
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module LlamaBotRails
2
+ require 'llama_bot_rails/agent_state_builder'
3
+
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace LlamaBotRails
6
+
7
+ config.generators do |g|
8
+ g.test_framework :rspec
9
+ g.fixture_replacement :factory_bot
10
+ g.factory_bot dir: 'spec/factories'
11
+ end
12
+
13
+ config.llama_bot_rails = ActiveSupport::OrderedOptions.new
14
+
15
+ initializer "llama_bot_rails.assets.precompile" do |app|
16
+ app.config.assets.precompile += %w( llama_bot_rails/application.js )
17
+ end
18
+
19
+ initializer "llama_bot_rails.defaults" do |app|
20
+ app.config.llama_bot_rails.state_builder_class = "LlamaBotRails::AgentStateBuilder"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module LlamaBotRails
6
+ class LlamaBot
7
+ def self.get_threads
8
+ uri = URI('http://localhost:8000/threads')
9
+ response = Net::HTTP.get_response(uri)
10
+ JSON.parse(response.body)
11
+ rescue => e
12
+ Rails.logger.error "Error fetching threads: #{e.message}"
13
+ []
14
+ end
15
+
16
+ def self.get_chat_history(thread_id)
17
+ uri = URI("http://localhost:8000/chat-history/#{thread_id}")
18
+ response = Net::HTTP.get_response(uri)
19
+ JSON.parse(response.body)
20
+ rescue => e
21
+ Rails.logger.error "Error fetching chat history: #{e.message}"
22
+ []
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module LlamaBotRails
2
+ module Tools
3
+ class RailsConsoleTool
4
+ tool_name "rails_console"
5
+ description "Run a Rails console through MCP Tool calling"
6
+
7
+ arguments do
8
+ required(:command).filled(:string).description("The ruby code to run")
9
+ end
10
+
11
+ def call(command:)
12
+ # VERY basic, sandbox for real use!
13
+ result = eval(command)
14
+ { result: result.inspect }
15
+ rescue => e
16
+ { error: e.class.name, message: e.message }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module LlamaBotRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "llama_bot_rails/version"
2
+ require "llama_bot_rails/engine"
3
+
4
+ module LlamaBotRails
5
+ class << self
6
+ def config
7
+ Rails.application.config.llama_bot_rails
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :llama_bot_rails do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llama_bot_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kody Kendall
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '7.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '7.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: actioncable
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '7.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: async-websocket
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: async-http
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ description: LlamaBotRails is a gem that turns your existing Rails App into an AI
69
+ Agent by connecting it to an open source LangGraph agent, LlamaBot.
70
+ email:
71
+ - kody@llamapress.ai
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - app/assets/config/llama_bot_rails_manifest.js
80
+ - app/assets/javascripts/llama_bot_rails/application.js
81
+ - app/assets/javascripts/llama_bot_rails/chat.js
82
+ - app/assets/stylesheets/llama_bot_rails/application.css
83
+ - app/channels/llama_bot_rails/application_cable/channel.rb
84
+ - app/channels/llama_bot_rails/application_cable/connection.rb
85
+ - app/channels/llama_bot_rails/chat_channel.rb
86
+ - app/controllers/llama_bot_rails/agent_controller.rb
87
+ - app/controllers/llama_bot_rails/application_controller.rb
88
+ - app/helpers/llama_bot_rails/application_helper.rb
89
+ - app/javascript/channels/consumer.js
90
+ - app/jobs/llama_bot_rails/application_job.rb
91
+ - app/models/llama_bot_rails/application_record.rb
92
+ - app/views/layouts/llama_bot_rails/application.html.erb
93
+ - app/views/llama_bot_rails/agent/chat.html.erb
94
+ - bin/rails
95
+ - bin/rubocop
96
+ - config/initializers/llama_bot_rails.rb
97
+ - config/routes.rb
98
+ - lib/llama_bot_rails.rb
99
+ - lib/llama_bot_rails/agent_state_builder.rb
100
+ - lib/llama_bot_rails/engine.rb
101
+ - lib/llama_bot_rails/llama_bot.rb
102
+ - lib/llama_bot_rails/tools/rails_console_tool.rb
103
+ - lib/llama_bot_rails/version.rb
104
+ - lib/tasks/llama_bot_rails_tasks.rake
105
+ homepage: https://llamapress.ai
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ homepage_uri: https://llamapress.ai
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.6.7
125
+ specification_version: 4
126
+ summary: LlamaBotRails is a gem that turns your existing Rails App into an AI Agent
127
+ by connecting it to an open source LangGraph agent, LlamaBot.
128
+ test_files: []