llama_bot_rails 0.1.8 → 0.1.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a6895de16432a4a2200c1623a25c68c09897b2a6fb3bf55977a2824f3578310
4
- data.tar.gz: c39ee31cf9fa2166de1d48434ab3228a6db960328a6565826242e57e5a22a678
3
+ metadata.gz: '0850d756a8d86153485d9fdbcb9a0154834e646050da9169b3269d7937d6760f'
4
+ data.tar.gz: c5276496549f2b055ec08dbfdf2615b47d431437f1d62845ff8b6c5d8baa0f7c
5
5
  SHA512:
6
- metadata.gz: 9711a2a8cfe8e485210b84314860eb098113de321ccfd1a93be15608240312d45ff54d852b965eb60f0d84b530620e856d837d28dc7a8b8a3f958e470859b6a2
7
- data.tar.gz: e175b5d7df84b42fff07dec9a0daed0384bf77891fc42611ab83ba087131b879a97aec66b77d154ccd9c5f89ed3db2df3e53052d0a937f5e80c8b84cc778c34e
6
+ metadata.gz: 13c32b136629c642fb149a85197b445495e4c40f80a68402e5b7ab5f76d255b514a5584059df1e9bbe883f68a912c12d9de6811aed4de7f2d55d4ace6f23e432
7
+ data.tar.gz: b0d26dad8ee336083c702301c7ba36a6aa5926c65220ea205af6dec0abc941366c4af5de0126ed580251673fc935c693de717dc779ffbe0ba1f0f1d8d82e0dab
@@ -133,10 +133,9 @@ module LlamaBotRails
133
133
  # Forward the processed data to the LlamaBot Backend Socket
134
134
  message = data["message"]
135
135
 
136
- # 1. Instantiate the builder
137
136
  builder = state_builder_class.new(
138
- params: { message: data["message"] },
139
- context: { thread_id: data["thread_id"], api_token: @api_token }
137
+ params: data,
138
+ context: { api_token: @api_token }
140
139
  )
141
140
 
142
141
  # 2. Construct the LangGraph-ready state
@@ -171,7 +170,27 @@ module LlamaBotRails
171
170
  private
172
171
 
173
172
  def state_builder_class
174
- LlamaBotRails.config.state_builder_class.constantize
173
+ builder_class_name = LlamaBotRails.config.state_builder_class || 'LlamaBotRails::AgentStateBuilder'
174
+
175
+ begin
176
+ builder_class_name.constantize
177
+ rescue NameError => e
178
+ # If it's not the default class, try to manually load from app/llama_bot
179
+ if builder_class_name != 'LlamaBotRails::AgentStateBuilder'
180
+ llama_bot_file = Rails.root.join("app", "llama_bot", "agent_state_builder.rb")
181
+ if llama_bot_file.exist?
182
+ Rails.logger.info "[LlamaBot] Autoload failed, attempting to manually load #{llama_bot_file}"
183
+ begin
184
+ load llama_bot_file.to_s
185
+ return builder_class_name.constantize
186
+ rescue => load_error
187
+ Rails.logger.error "[LlamaBot] Manual load failed: #{load_error.message}"
188
+ end
189
+ end
190
+ end
191
+
192
+ raise NameError, "Could not load state builder class '#{builder_class_name}'. Make sure it's defined in app/llama_bot/agent_state_builder.rb or is available in your autoload paths. Original error: #{e.message}"
193
+ end
175
194
  end
176
195
 
177
196
  def setup_external_websocket(connection_id)
@@ -85,8 +85,8 @@ module LlamaBotRails
85
85
 
86
86
  # 1. Instantiate the builder
87
87
  builder = state_builder_class.new(
88
- params: { message: params[:message] },
89
- context: { thread_id: params[:thread_id], api_token: @api_token }
88
+ params: params,
89
+ context: { api_token: @api_token }
90
90
  )
91
91
 
92
92
  # 2. Construct the LangGraph-ready state
@@ -14,9 +14,15 @@ module LlamaBotRails
14
14
  end
15
15
  end
16
16
 
17
- def create_config_file
18
- empty_directory "config/llama_bot"
19
- copy_file "agent_prompt.txt", "config/llama_bot/agent_prompt.txt"
17
+ def create_agent_prompt
18
+ empty_directory "app/llama_bot/prompts"
19
+ copy_file "agent_prompt.txt", "app/llama_bot/prompts/agent_prompt.txt"
20
+ end
21
+
22
+ def create_agent_state_builder
23
+ empty_directory "app/llama_bot"
24
+ template "agent_state_builder.rb.erb", "app/llama_bot/agent_state_builder.rb"
25
+ say_status("created", "app/llama_bot/agent_state_builder.rb", :green)
20
26
  end
21
27
 
22
28
  def mount_engine
@@ -46,9 +52,17 @@ module LlamaBotRails
46
52
  def create_initializer
47
53
  create_file "config/initializers/llama_bot_rails.rb", <<~RUBY
48
54
  Rails.application.configure do
49
- config.llama_bot_rails.websocket_url = ENV.fetch("LLAMABOT_WEBSOCKET_URL", "ws://localhost:8000/ws")
50
- config.llama_bot_rails.llamabot_api_url = ENV.fetch("LLAMABOT_API_URL", "http://localhost:8000")
55
+ config.llama_bot_rails.websocket_url = ENV.fetch("LLAMABOT_WEBSOCKET_URL", "ws://localhost:8000/ws")
56
+ config.llama_bot_rails.llamabot_api_url = ENV.fetch("LLAMABOT_API_URL", "http://localhost:8000")
51
57
  config.llama_bot_rails.enable_console_tool = !Rails.env.production?
58
+
59
+ # ------------------------------------------------------------------------
60
+ # Custom State Builder
61
+ # ------------------------------------------------------------------------
62
+ # The gem uses `LlamaBotRails::AgentStateBuilder` by default.
63
+ # Uncomment this line to use the builder in app/llama_bot/
64
+ #
65
+ # config.llama_bot_rails.state_builder_class = "#{app_name}::AgentStateBuilder"
52
66
  end
53
67
  RUBY
54
68
  end
@@ -56,6 +70,12 @@ module LlamaBotRails
56
70
  def finish
57
71
  say "\n✅ LlamaBotRails installed! Visit http://localhost:3000/llama_bot/agent/chat\n", :green
58
72
  end
73
+
74
+ private
75
+
76
+ def app_name
77
+ Rails.application.class.module_parent_name
78
+ end
59
79
  end
60
80
  end
61
81
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Customize the params sent to your LangGraph agent here.
4
+ # Uncomment the line in the initializer to activate this builder.
5
+ module <%= app_name %>
6
+ class AgentStateBuilder
7
+ def initialize(params:, context:)
8
+ @params = params
9
+ @context = context
10
+ end
11
+
12
+ def build
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.)
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
+ 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
+ }
20
+ end
21
+ end
22
+ end
@@ -13,9 +13,9 @@ module LlamaBotRails
13
13
  def build
14
14
  {
15
15
  message: @params[:message], # Rails param from JS/chat UI. This is the user's message to the agent.
16
- thread_id: @context[:thread_id], # This is the thread id for the agent. It is used to track the conversation history.
16
+ thread_id: @params[:thread_id], # This is the thread id for the agent. It is used to track the conversation history.
17
17
  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.)
18
- agent_prompt: LlamaBotRails.agent_prompt_text, # System prompt instructions for the agent. Can be customized in config/agent_prompt.txt
18
+ agent_prompt: LlamaBotRails.agent_prompt_text, # System prompt instructions for the agent. Can be customized in app/llama_bot/prompts/agent_prompt.txt
19
19
  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.
20
20
  }
21
21
  end
@@ -20,7 +20,7 @@ module LlamaBotRails
20
20
  end
21
21
 
22
22
  initializer "llama_bot_rails.defaults" do |app|
23
- app.config.llama_bot_rails.state_builder_class = "LlamaBotRails::AgentStateBuilder"
23
+ app.config.llama_bot_rails.state_builder_class ||= "LlamaBotRails::AgentStateBuilder"
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,19 @@
1
+ module LlamaBotRails
2
+ class Railtie < ::Rails::Railtie
3
+ config.before_configuration do |app|
4
+ llama_bot_path = Rails.root.join("app", "llama_bot")
5
+
6
+ # Add to autoload paths if it exists and isn't already included
7
+ if llama_bot_path.exist? && !app.config.autoload_paths.include?(llama_bot_path.to_s)
8
+ app.config.autoload_paths << llama_bot_path.to_s
9
+ Rails.logger&.info "[LlamaBot] Added #{llama_bot_path} to autoload_paths"
10
+ end
11
+
12
+ # Add to eager load paths if it exists and isn't already included
13
+ if llama_bot_path.exist? && !app.config.eager_load_paths.include?(llama_bot_path.to_s)
14
+ app.config.eager_load_paths << llama_bot_path.to_s
15
+ Rails.logger&.info "[LlamaBot] Added #{llama_bot_path} to eager_load_paths"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module LlamaBotRails
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "llama_bot_rails/version"
2
2
  require "llama_bot_rails/engine"
3
3
  require "llama_bot_rails/llama_bot"
4
+ require "llama_bot_rails/railtie"
4
5
 
5
6
  module LlamaBotRails
6
7
  class << self
@@ -9,7 +10,7 @@ module LlamaBotRails
9
10
  end
10
11
 
11
12
  def agent_prompt_path
12
- Rails.root.join("config", "llama_bot", "agent_prompt.txt")
13
+ Rails.root.join("app", "llama_bot", "prompts", "agent_prompt.txt")
13
14
  end
14
15
 
15
16
  def agent_prompt_text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llama_bot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kody Kendall
@@ -124,10 +124,12 @@ files:
124
124
  - config/routes.rb
125
125
  - lib/generators/llama_bot_rails/install/install_generator.rb
126
126
  - lib/generators/llama_bot_rails/install/templates/agent_prompt.txt
127
+ - lib/generators/llama_bot_rails/install/templates/agent_state_builder.rb.erb
127
128
  - lib/llama_bot_rails.rb
128
129
  - lib/llama_bot_rails/agent_state_builder.rb
129
130
  - lib/llama_bot_rails/engine.rb
130
131
  - lib/llama_bot_rails/llama_bot.rb
132
+ - lib/llama_bot_rails/railtie.rb
131
133
  - lib/llama_bot_rails/tools/rails_console_tool.rb
132
134
  - lib/llama_bot_rails/version.rb
133
135
  - lib/tasks/llama_bot_rails_tasks.rake