llama_bot_rails 0.1.11 → 0.1.14

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -0
  3. data/app/channels/llama_bot_rails/chat_channel.rb +75 -73
  4. data/app/controllers/llama_bot_rails/agent_controller.rb +36 -32
  5. data/app/views/llama_bot_rails/agent/chat.html.erb +2 -1
  6. data/app/views/llama_bot_rails/agent/chat_ws.html.erb +11 -2
  7. data/bin/bundle +29 -0
  8. data/bin/bundle.lock +0 -0
  9. data/bin/bundler +29 -0
  10. data/bin/bundler.lock +0 -0
  11. data/bin/byebug +29 -0
  12. data/bin/coderay +29 -0
  13. data/bin/erb +29 -0
  14. data/bin/faker +29 -0
  15. data/bin/htmldiff +29 -0
  16. data/bin/irb +29 -0
  17. data/bin/ldiff +29 -0
  18. data/bin/nokogiri +29 -0
  19. data/bin/pry +29 -0
  20. data/bin/puma +29 -0
  21. data/bin/pumactl +29 -0
  22. data/bin/racc +29 -0
  23. data/bin/rackup +29 -0
  24. data/bin/rake +29 -0
  25. data/bin/rdoc +29 -0
  26. data/bin/ri +29 -0
  27. data/bin/rspec +29 -0
  28. data/bin/ruby-parse +29 -0
  29. data/bin/ruby-rewrite +29 -0
  30. data/bin/sprockets +29 -0
  31. data/bin/thor +29 -0
  32. data/lib/generators/llama_bot_rails/install/install_generator.rb +68 -0
  33. data/lib/generators/llama_bot_rails/install/templates/agent_state_builder.rb.erb +3 -3
  34. data/lib/llama_bot_rails/agent_auth.rb +158 -0
  35. data/lib/llama_bot_rails/agent_auth_2.rb +149 -0
  36. data/lib/llama_bot_rails/agent_state_builder.rb +6 -6
  37. data/lib/llama_bot_rails/controller_extensions.rb +40 -0
  38. data/lib/llama_bot_rails/engine.rb +8 -2
  39. data/lib/llama_bot_rails/llama_bot.rb +3 -0
  40. data/lib/llama_bot_rails/railtie.rb +6 -0
  41. data/lib/llama_bot_rails/route_helper.rb +117 -0
  42. data/lib/llama_bot_rails/version.rb +1 -1
  43. data/lib/llama_bot_rails.rb +64 -21
  44. metadata +31 -4
  45. data/bin/rails +0 -26
  46. data/bin/rubocop +0 -8
data/bin/ldiff ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'diff-lcs' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('diff-lcs', 'ldiff', version)
26
+ else
27
+ gem "diff-lcs", version
28
+ load Gem.bin_path("diff-lcs", "ldiff", version)
29
+ end
data/bin/nokogiri ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'nokogiri' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('nokogiri', 'nokogiri', version)
26
+ else
27
+ gem "nokogiri", version
28
+ load Gem.bin_path("nokogiri", "nokogiri", version)
29
+ end
data/bin/pry ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'pry' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('pry', 'pry', version)
26
+ else
27
+ gem "pry", version
28
+ load Gem.bin_path("pry", "pry", version)
29
+ end
data/bin/puma ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'puma' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('puma', 'puma', version)
26
+ else
27
+ gem "puma", version
28
+ load Gem.bin_path("puma", "puma", version)
29
+ end
data/bin/pumactl ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'puma' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('puma', 'pumactl', version)
26
+ else
27
+ gem "puma", version
28
+ load Gem.bin_path("puma", "pumactl", version)
29
+ end
data/bin/racc ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'racc' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('racc', 'racc', version)
26
+ else
27
+ gem "racc", version
28
+ load Gem.bin_path("racc", "racc", version)
29
+ end
data/bin/rackup ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'rackup' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('rackup', 'rackup', version)
26
+ else
27
+ gem "rackup", version
28
+ load Gem.bin_path("rackup", "rackup", version)
29
+ end
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('rake', 'rake', version)
26
+ else
27
+ gem "rake", version
28
+ load Gem.bin_path("rake", "rake", version)
29
+ end
data/bin/rdoc ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'rdoc' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('rdoc', 'rdoc', version)
26
+ else
27
+ gem "rdoc", version
28
+ load Gem.bin_path("rdoc", "rdoc", version)
29
+ end
data/bin/ri ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'rdoc' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('rdoc', 'ri', version)
26
+ else
27
+ gem "rdoc", version
28
+ load Gem.bin_path("rdoc", "ri", version)
29
+ end
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'rspec-core' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('rspec-core', 'rspec', version)
26
+ else
27
+ gem "rspec-core", version
28
+ load Gem.bin_path("rspec-core", "rspec", version)
29
+ end
data/bin/ruby-parse ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'parser' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('parser', 'ruby-parse', version)
26
+ else
27
+ gem "parser", version
28
+ load Gem.bin_path("parser", "ruby-parse", version)
29
+ end
data/bin/ruby-rewrite ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'parser' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('parser', 'ruby-rewrite', version)
26
+ else
27
+ gem "parser", version
28
+ load Gem.bin_path("parser", "ruby-rewrite", version)
29
+ end
data/bin/sprockets ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'sprockets' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('sprockets', 'sprockets', version)
26
+ else
27
+ gem "sprockets", version
28
+ load Gem.bin_path("sprockets", "sprockets", version)
29
+ end
data/bin/thor ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ Gem.use_gemdeps
12
+
13
+ version = ">= 0.a"
14
+
15
+ str = ARGV.first
16
+ if str
17
+ str = str.b[/\A_(.*)_\z/, 1]
18
+ if str and Gem::Version.correct?(str)
19
+ version = str
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ if Gem.respond_to?(:activate_bin_path)
25
+ load Gem.activate_bin_path('thor', 'thor', version)
26
+ else
27
+ gem "thor", version
28
+ load Gem.bin_path("thor", "thor", version)
29
+ end
@@ -63,6 +63,74 @@ module LlamaBotRails
63
63
  # Uncomment this line to use the builder in app/llama_bot/
64
64
  #
65
65
  # config.llama_bot_rails.state_builder_class = "#{app_name}::AgentStateBuilder"
66
+
67
+ # ------------------------------------------------------------------------
68
+ # Custom User Resolver
69
+ # ------------------------------------------------------------------------
70
+ # The gem uses `warden.user` by default.
71
+ # Uncomment this line to use a custom user resolver in app/llama_bot/
72
+ # Example: if you don't use Devise, uncomment and tweak:
73
+ #
74
+ # LlamaBotRails.user_resolver = ->(user_id) do
75
+ # # Try to find a User model, fallback to nil if not found
76
+ # if defined?(Devise)
77
+ # default_scope = Devise.default_scope # e.g., :user
78
+ # user_class = Devise.mappings[default_scope].to
79
+ # user_class.find_by(id: user_id)
80
+ # else
81
+ # Rails.logger.warn("[[LlamaBot]] Implement a user_resolver! in your app to resolve the user from the user_id.")
82
+ # nil
83
+ # end
84
+ # end
85
+
86
+ # ------------------------------------------------------------------------
87
+ # Custom Current User Resolver
88
+ # ------------------------------------------------------------------------
89
+ # Default (Devise / Warden); returns nil if Devise absent
90
+ #
91
+ # LlamaBotRails.current_user_resolver = ->(env) do
92
+ # # Try to find a User model, fallback to nil if not found
93
+ # if defined?(Devise)
94
+ # env['warden']&.user
95
+ # else
96
+ # Rails.logger.warn("[[LlamaBot]] Implement a current_user_resolver! in your app to resolve the current user from the environment.")
97
+ # nil
98
+ # end
99
+ # end
100
+
101
+ # ------------------------------------------------------------------------
102
+ # Custom Sign-in Method
103
+ # ------------------------------------------------------------------------
104
+ # Lambda that receives Rack env and user_id, and sets the user in the warden session
105
+ # Default sign-in method is configured for Devise with Warden.
106
+ #
107
+ # LlamaBotRails.sign_in_method = ->(env, user) do
108
+ # env['warden']&.set_user(user)
109
+ # end
110
+
111
+ # ------------------------------------------------------------------------
112
+ # Alternative Examples for Non-Devise Apps
113
+ # ------------------------------------------------------------------------
114
+ # Example: if you don't use Devise, uncomment and tweak:
115
+ #
116
+ # LlamaBotRails.user_resolver = ->(user_id) do
117
+ # # Rack session example
118
+ # if user_id
119
+ # User.find_by(id: user_id)
120
+ # end
121
+ # end
122
+ #
123
+ # LlamaBotRails.current_user_resolver = ->(env) do
124
+ # # Rack session example
125
+ # if id = env['rack.session'][:user_id]
126
+ # User.find_by(id: id)
127
+ # end
128
+ # end
129
+ #
130
+ # LlamaBotRails.sign_in_method = ->(env, user) do
131
+ # # Set user in rack session
132
+ # env['rack.session'][:user_id] = user&.id
133
+ # end
66
134
  end
67
135
  RUBY
68
136
  end
@@ -11,9 +11,9 @@ module <%= app_name %>
11
11
 
12
12
  def build
13
13
  {
14
- message: @params[:message], # Rails param from JS/chat UI. This is the user's message to the agent.
15
- thread_id: @context[:thread_id], # This is the thread id for the agent. It is used to track the conversation history.
16
- api_token: @context[:api_token], # This is an authenticated API token for the agent, so that it can authenticate with us. (It may need access to resources on our Rails app, such as the Rails Console.)
14
+ message: @params["message"], # Rails param from JS/chat UI. This is the user's message to the agent.
15
+ thread_id: @params["thread_id"], # This is the thread id for the agent. It is used to track the conversation history.
16
+ api_token: @context["api_token"], # This is an authenticated API token for the agent, so that it can authenticate with us. (It may need access to resources on our Rails app, such as the Rails Console.)
17
17
  agent_prompt: LlamaBotRails.agent_prompt_text, # System prompt instructions for the agent. Can be customized in app/llama_bot/prompts/agent_prompt.txt
18
18
  agent_name: "llamabot" # This routes to the appropriate LangGraph agent as defined in LlamaBot/langgraph.json, and enables us to access different agents on our LlamaBot server.
19
19
  }