Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Discover external assistant agents from models endpoint (#3674)

Juan José Mata01bd2542d70b
diff --git a/.env.example b/.env.example
index 53dcb8950b..6123a6c685 100644
--- a/.env.example
+++ b/.env.example
@@ -96,7 +96,8 @@ OPENAI_URI_BASE=
# ASSISTANT_TYPE=external
# EXTERNAL_ASSISTANT_URL=https://your-agent-host/v1/chat/completions
# EXTERNAL_ASSISTANT_TOKEN=your-api-token # pipelock:ignore
-# EXTERNAL_ASSISTANT_AGENT_ID=main
+# EXTERNAL_ASSISTANT_MODEL=openclaw/main # Defaults to openclaw/main
+# EXTERNAL_ASSISTANT_AGENT_ID=main # Legacy; used only when no model is selected
# EXTERNAL_ASSISTANT_SESSION_KEY=agent:main:main
diff --git a/app/controllers/settings/hostings_controller.rb b/app/controllers/settings/hostings_controller.rb
index 37abed4f6d..09c1e8d16c 100644
--- a/app/controllers/settings/hostings_controller.rb
+++ b/app/controllers/settings/hostings_controller.rb
@@ -55,6 +55,8 @@ class Settings::HostingsController < ApplicationController
# monthly request caps when a key is configured
@rentcast_usage = Provider::Registry.get_provider(:rentcast)&.usage
@realie_usage = Provider::Registry.get_provider(:realie)&.usage
+
+ load_external_assistant_models
end
def update
@@ -248,21 +250,17 @@ class Settings::HostingsController < ApplicationController
Setting.public_send("#{key}=", parsed)
end
- if hosting_params.key?(:external_assistant_url)
- Setting.external_assistant_url = hosting_params[:external_assistant_url]
- end
-
- update_encrypted_setting(:external_assistant_token)
-
- if hosting_params.key?(:external_assistant_agent_id)
- Setting.external_assistant_agent_id = hosting_params[:external_assistant_agent_id]
- end
+ reselect_external_agent = update_external_assistant_settings!
update_assistant_type
update_categorization_provider
update_categorization_tuning
- redirect_to settings_hosting_path, notice: t(".success")
+ if reselect_external_agent
+ redirect_to settings_hosting_path, alert: t("settings.hostings.assistant_settings.external_agent_reselect")
+ else
+ redirect_to settings_hosting_path, notice: t(".success")
+ end
rescue Setting::ValidationError => error
# Preserve user-submitted OpenAI config so the form re-renders with their
# input intact (issue #1824). The form auto-submits on blur, so a partial
@@ -275,6 +273,9 @@ class Settings::HostingsController < ApplicationController
@jev_endpoint_input = hosting_params[:jev_endpoint] if hosting_params.key?(:jev_endpoint)
@jev_model_input = hosting_params[:jev_model] if hosting_params.key?(:jev_model)
flash.now[:alert] = error.message
+ # Nothing was saved, so reload the agent options from the stored config;
+ # otherwise the 422 page shows an empty, disabled agent dropdown.
+ load_external_assistant_models
render :show, status: :unprocessable_entity
end
@@ -286,6 +287,7 @@ class Settings::HostingsController < ApplicationController
def disconnect_external_assistant
Setting.external_assistant_url = nil
Setting.external_assistant_token = nil
+ Setting.external_assistant_model = nil
Setting.external_assistant_agent_id = nil
Current.family.update!(assistant_type: "builtin") unless ENV["ASSISTANT_TYPE"].present?
redirect_to settings_hosting_path, notice: t(".external_assistant_disconnected")
@@ -298,7 +300,96 @@ class Settings::HostingsController < ApplicationController
# Strong parameters for the self-hosting settings form.
def hosting_params
return ActionController::Parameters.new unless params.key?(:setting)
- params.require(:setting).permit(:onboarding_state, :require_email_confirmation, :invite_only_default_family_id, :brand_fetch_client_id, :brand_fetch_high_res_logos, :twelve_data_api_key, :tiingo_api_key, :eodhd_api_key, :alpha_vantage_api_key, :tinkoff_invest_api_key, :mansa_api_key, :rentcast_api_key, :realie_api_key, :openai_access_token, :openai_uri_base, :openai_model, :openai_json_mode, :anthropic_access_token, :anthropic_base_url, :anthropic_model, :jev_api_key, :jev_endpoint, :jev_model, :llm_provider, :llm_context_window, :llm_max_response_tokens, :llm_max_items_per_call, :openai_request_timeout, :ai_response_timeout, :exchange_rate_provider, :securities_provider, :syncs_include_pending, :auto_sync_enabled, :auto_sync_time, :external_assistant_url, :external_assistant_token, :external_assistant_agent_id, securities_providers: [])
+ params.require(:setting).permit(:onboarding_state, :require_email_confirmation, :invite_only_default_family_id, :brand_fetch_client_id, :brand_fetch_high_res_logos, :twelve_data_api_key, :tiingo_api_key, :eodhd_api_key, :alpha_vantage_api_key, :tinkoff_invest_api_key, :mansa_api_key, :rentcast_api_key, :realie_api_key, :openai_access_token, :openai_uri_base, :openai_model, :openai_json_mode, :anthropic_access_token, :anthropic_base_url, :anthropic_model, :jev_api_key, :jev_endpoint, :jev_model, :llm_provider, :llm_context_window, :llm_max_response_tokens, :llm_max_items_per_call, :openai_request_timeout, :ai_response_timeout, :exchange_rate_provider, :securities_provider, :syncs_include_pending, :auto_sync_enabled, :auto_sync_time, :external_assistant_url, :external_assistant_token, :external_assistant_model, securities_providers: [])
+ end
+
+ def load_external_assistant_models
+ @external_assistant_models = []
+ @external_assistant_catalog_error = nil
+ effective_type = ENV["ASSISTANT_TYPE"].presence || Current.family.assistant_type
+ return unless effective_type == "external"
+
+ config = Assistant::External.config
+ return unless config.url.present? && config.token.present?
+
+ # Rendered synchronously, so keep a stalled gateway from holding the page.
+ @external_assistant_models = Assistant::External::ModelCatalog.new(
+ url: config.url,
+ token: config.token,
+ open_timeout: 3,
+ read_timeout: 5
+ ).models
+ rescue Assistant::External::ModelCatalog::Error => error
+ @external_assistant_catalog_error = error.message
+ end
+
+ # Validates the submitted endpoint, token and agent together before any of
+ # them is written, so a rejected change leaves the stored config untouched.
+ # Returns true when the connection changed and the old agent must be reselected.
+ def update_external_assistant_settings!
+ keys = %i[external_assistant_url external_assistant_token external_assistant_model]
+ return false unless keys.any? { |key| hosting_params.key?(key) }
+
+ current = Assistant::External.config
+ url = ENV["EXTERNAL_ASSISTANT_URL"].presence || submitted_external_assistant_url(current.url)
+ token = ENV["EXTERNAL_ASSISTANT_TOKEN"].presence || submitted_external_assistant_token(current.token)
+ connection_changed = url != current.url || token != current.token
+
+ model_submitted = hosting_params.key?(:external_assistant_model)
+ model = model_submitted ? hosting_params[:external_assistant_model].presence : Setting.external_assistant_model.presence
+ raise Setting::ValidationError, t("settings.hostings.assistant_settings.external_agent_required") if model_submitted && model.blank?
+
+ reselect = false
+ if model_submitted
+ unless external_assistant_model_ids(url, token).include?(model)
+ raise Setting::ValidationError, t("settings.hostings.assistant_settings.external_agent_invalid") unless connection_changed
+
+ # The agent list on the page came from the previous connection. Save
+ # the new connection, but never pair it with an agent it does not offer.
+ model = nil
+ reselect = true
+ end
+ elsif connection_changed && model.present? && ENV["EXTERNAL_ASSISTANT_MODEL"].blank?
+ available = begin
+ external_assistant_model_ids(url, token)
+ rescue Setting::ValidationError
+ []
+ end
+ unless available.include?(model)
+ model = nil
+ reselect = true
+ end
+ end
+
+ Setting.transaction do
+ Setting.external_assistant_url = hosting_params[:external_assistant_url] if hosting_params.key?(:external_assistant_url)
+ update_encrypted_setting(:external_assistant_token)
+ if model_submitted || reselect
+ Setting.external_assistant_model = model
+ Setting.external_assistant_agent_id = nil
+ end
+ end
+
+ reselect
+ end
+
+ def submitted_external_assistant_url(current_url)
+ return current_url unless hosting_params.key?(:external_assistant_url)
+
+ hosting_params[:external_assistant_url].presence
+ end
+
+ def submitted_external_assistant_token(current_token)
+ return current_token unless hosting_params.key?(:external_assistant_token)
+
+ value = hosting_params[:external_assistant_token].to_s.strip
+ value == "********" ? current_token : value.presence
+ end
+
+ def external_assistant_model_ids(url, token)
+ Assistant::External::ModelCatalog.new(url: url, token: token).models.pluck(:id)
+ rescue Assistant::External::ModelCatalog::Error => error
+ raise Setting::ValidationError, t("settings.hostings.assistant_settings.agent_discovery_error", error: error.message)
end
# Family-scoped, like assistant_type: it decides whose transaction data is
diff --git a/app/models/assistant/external.rb b/app/models/assistant/external.rb
index f2e2006416..1ce2c2eb87 100644
--- a/app/models/assistant/external.rb
+++ b/app/models/assistant/external.rb
@@ -1,5 +1,5 @@
class Assistant::External < Assistant::Base
- Config = Struct.new(:url, :token, :agent_id, :session_key, keyword_init: true)
+ Config = Struct.new(:url, :token, :model, :agent_id, :session_key, keyword_init: true)
MAX_CONVERSATION_MESSAGES = 20
class << self
@@ -8,7 +8,7 @@ class Assistant::External < Assistant::Base
end
def configured?
- config.url.present? && config.token.present?
+ config.url.present? && config.token.present? && config.model.present?
end
def available_for?(user)
@@ -27,10 +27,41 @@ class Assistant::External < Assistant::Base
Config.new(
url: ENV["EXTERNAL_ASSISTANT_URL"].presence || Setting.external_assistant_url.presence,
token: ENV["EXTERNAL_ASSISTANT_TOKEN"].presence || Setting.external_assistant_token.presence,
- agent_id: ENV["EXTERNAL_ASSISTANT_AGENT_ID"].presence || Setting.external_assistant_agent_id.presence || "main",
+ model: selected_model || legacy_model,
+ agent_id: routing_agent_id,
session_key: ENV.fetch("EXTERNAL_ASSISTANT_SESSION_KEY", "agent:main:main")
)
end
+
+ private
+ # Explicitly selected model (env or Settings), or nil when only legacy config exists.
+ def selected_model
+ ENV["EXTERNAL_ASSISTANT_MODEL"].presence || Setting.external_assistant_model.presence
+ end
+
+ # Pre-discovery installs routed with X-Agent-Id and defaulted to "main"
+ # when nothing was set. Keep that default so URL + token installs keep working.
+ def legacy_model
+ legacy = ENV["EXTERNAL_ASSISTANT_AGENT_ID"].presence || Setting.external_assistant_agent_id.presence || "main"
+ return legacy if legacy.start_with?("openclaw")
+
+ "openclaw/#{legacy}"
+ end
+
+ # The routing header always follows the model that is sent. A legacy
+ # EXTERNAL_ASSISTANT_AGENT_ID only applies while no model is selected.
+ def routing_agent_id
+ model = selected_model
+ return ENV["EXTERNAL_ASSISTANT_AGENT_ID"].presence || agent_id_for(legacy_model) if model.blank?
+
+ agent_id_for(model)
+ end
+
+ def agent_id_for(model)
+ return "main" if model.blank? || model.in?([ "openclaw", "openclaw/default" ])
+
+ model.delete_prefix("openclaw/").presence || "main"
+ end
end
def respond_to(message, assistant_message: nil)
@@ -83,6 +114,7 @@ class Assistant::External < Assistant::Base
Assistant::External::Client.new(
url: self.class.config.url,
token: self.class.config.token,
+ model: self.class.config.model,
agent_id: self.class.config.agent_id,
session_key: self.class.config.session_key
)
diff --git a/app/models/assistant/external/client.rb b/app/models/assistant/external/client.rb
index ec2559a3f4..c204449e37 100644
--- a/app/models/assistant/external/client.rb
+++ b/app/models/assistant/external/client.rb
@@ -18,9 +18,10 @@ class Assistant::External::Client
SocketError
].freeze
- def initialize(url:, token:, agent_id: "main", session_key: "agent:main:main")
+ def initialize(url:, token:, model: "openclaw", agent_id: "main", session_key: "agent:main:main")
@url = url
@token = token # pipelock:ignore Credential in URL
+ @model = model
@agent_id = agent_id
@session_key = session_key
end
@@ -156,7 +157,7 @@ class Assistant::External::Client
request["X-Session-Key"] = @session_key
payload = {
- model: @agent_id,
+ model: @model,
messages: messages,
stream: true
}
diff --git a/app/models/assistant/external/model_catalog.rb b/app/models/assistant/external/model_catalog.rb
new file mode 100644
index 0000000000..1c0a44d77b
--- /dev/null
+++ b/app/models/assistant/external/model_catalog.rb
@@ -0,0 +1,75 @@
+require "net/http"
+require "uri"
+require "json"
+
+class Assistant::External::ModelCatalog
+ Error = Class.new(StandardError)
+ CONNECTION_ERRORS = [
+ *Assistant::External::Client::TRANSIENT_ERRORS,
+ Timeout::Error,
+ OpenSSL::SSL::SSLError,
+ IOError,
+ SystemCallError
+ ].freeze
+
+ def initialize(url:, token:, open_timeout: 5, read_timeout: 10)
+ @url = url
+ @token = token
+ @open_timeout = open_timeout
+ @read_timeout = read_timeout
+ end
+
+ def models
+ uri = models_uri
+ request = Net::HTTP::Get.new(uri.request_uri)
+ request["Authorization"] = "Bearer #{@token}"
+ request["Accept"] = "application/json"
+
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: @open_timeout, read_timeout: @read_timeout) do |http|
+ http.request(request)
+ end
+
+ raise Error, "Agent discovery returned HTTP #{response.code}." unless response.is_a?(Net::HTTPSuccess)
+
+ payload = JSON.parse(response.body)
+ entries = payload.is_a?(Hash) ? payload["data"] : nil
+ unless entries.is_a?(Array) && entries.all? { |entry| entry.is_a?(Hash) }
+ raise Error, "Agent discovery returned an invalid response."
+ end
+
+ entries.filter_map do |model|
+ id = model["id"].to_s
+ next if id.blank?
+
+ { id: id, label: agent_label(id) }
+ end
+ rescue JSON::ParserError, URI::InvalidURIError => e
+ raise Error, "Agent discovery returned an invalid response: #{e.message}"
+ rescue *CONNECTION_ERRORS => e
+ raise Error, "Agent discovery is unavailable: #{e.message}"
+ end
+
+ private
+ def models_uri
+ uri = URI(@url)
+ raise URI::InvalidURIError, "only HTTP and HTTPS endpoints are supported" unless uri.is_a?(URI::HTTP)
+
+ path = uri.path.sub(%r{/chat/completions/?\z}, "/models")
+ raise URI::InvalidURIError, "endpoint must end in /chat/completions" if path == uri.path
+
+ uri.path = path
+ uri.query = nil
+ uri.fragment = nil
+ uri
+ end
+
+ def agent_label(id)
+ case id
+ when "openclaw", "openclaw/default"
+ I18n.t("assistant.external.model_catalog.default_agent_label", id: id)
+ when %r{\Aopenclaw/(.+)\z}
+ I18n.t("assistant.external.model_catalog.named_agent_label", name: $1, id: id)
+ else id
+ end
+ end
+end
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 65dab3c163..b7de3f3b42 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -40,6 +40,7 @@ class Setting < RailsSettings::Base
field :ai_response_timeout, type: :integer, default: ENV["AI_RESPONSE_TIMEOUT"]&.to_i
field :external_assistant_url, type: :string
field :external_assistant_token, type: :string
+ field :external_assistant_model, type: :string
field :external_assistant_agent_id, type: :string
field :brand_fetch_client_id, type: :string, default: ENV["BRAND_FETCH_CLIENT_ID"]
field :brand_fetch_high_res_logos, type: :boolean, default: ENV.fetch("BRAND_FETCH_HIGH_RES_LOGOS", "false") == "true"
diff --git a/app/views/recurring_transactions/index.html.erb b/app/views/recurring_transactions/index.html.erb
index 882f61aae4..4fad76c3c7 100644
--- a/app/views/recurring_transactions/index.html.erb
+++ b/app/views/recurring_transactions/index.html.erb
@@ -40,21 +40,15 @@
</div>
<% unless @family.recurring_transactions_disabled? %>
- <div class="p-4 bg-container-inset border border-secondary rounded-lg">
- <div class="flex items-start gap-2">
- <%= icon "info", class: "w-5 h-5 text-link mt-0.5 flex-shrink-0" %>
- <div>
- <p class="text-sm font-medium text-primary mb-2"><%= t("recurring_transactions.info.title") %></p>
- <p class="text-xs text-secondary mb-2"><%= t("recurring_transactions.info.manual_description") %></p>
- <p class="text-xs text-secondary mb-1"><%= t("recurring_transactions.info.automatic_description") %></p>
- <ul class="list-disc list-inside text-xs text-secondary space-y-0.5 ml-2">
- <% t("recurring_transactions.info.triggers").each do |trigger| %>
- <li><%= trigger %></li>
- <% end %>
- </ul>
- </div>
- </div>
- </div>
+ <%= render DS::Alert.new(title: t("recurring_transactions.info.title"), variant: :info) do %>
+ <p><%= t("recurring_transactions.info.manual_description") %></p>
+ <p><%= t("recurring_transactions.info.automatic_description") %></p>
+ <ul class="list-disc list-inside space-y-0.5">
+ <% t("recurring_transactions.info.triggers").each do |trigger| %>
+ <li><%= trigger %></li>
+ <% end %>
+ </ul>
+ <% end %>
<% if @suggested.any? %>
<%= render "recurring_transactions/suggested_series", suggested: @suggested %>
diff --git a/app/views/settings/hostings/_assistant_settings.html.erb b/app/views/settings/hostings/_assistant_settings.html.erb
index 37e5bbc65a..edf4c953d8 100644
--- a/app/views/settings/hostings/_assistant_settings.html.erb
+++ b/app/views/settings/hostings/_assistant_settings.html.erb
@@ -31,6 +31,17 @@
data: { "auto-submit-form-target": "auto" } } %>
<% end %>
<% if effective_type == "external" %>
+
+ <div data-testid="external-assistant-info">
+ <%= render DS::Alert.new(title: t(".external_info.title"), variant: :info) do %>
+ <ul class="list-disc list-inside space-y-1">
+ <% t(".external_info.items").each do |item| %>
+ <li><%= item %></li>
+ <% end %>
+ </ul>
+ <% end %>
+ </div>
+
<div class="flex items-center gap-2 text-sm mb-4">
<% if Assistant::External.configured? %>
<span class="inline-block w-2 h-2 rounded-full bg-success"></span>
@@ -96,17 +107,19 @@
data: { "auto-submit-form-target": "auto" } %>
<p class="text-xs text-secondary mt-1"><%= t(".token_help") %></p>
- <%= form.text_field :external_assistant_agent_id,
- label: t(".agent_id_label"),
- placeholder: t(".agent_id_placeholder"),
- value: Assistant::External.config.agent_id,
- autocomplete: "off",
- autocapitalize: "none",
- spellcheck: "false",
- inputmode: "text",
- disabled: ENV["EXTERNAL_ASSISTANT_AGENT_ID"].present?,
- data: { "auto-submit-form-target": "auto" } %>
+ <% model_options = Array(@external_assistant_models).map { |agent| [agent[:label], agent[:id]] } %>
+ <% selected_model = Assistant::External.config.model %>
+ <%= form.select :external_assistant_model,
+ options_for_select(model_options, selected_model),
+ { label: t(".agent_id_label"), include_blank: false },
+ { aria: { required: true }, disabled: ENV["EXTERNAL_ASSISTANT_MODEL"].present? || model_options.empty?,
+ data: { "auto-submit-form-target": "auto" } } %>
<p class="text-xs text-secondary mt-1"><%= t(".agent_id_help") %></p>
+ <% if @external_assistant_catalog_error.present? %>
+ <p class="text-xs text-destructive mt-1"><%= t(".agent_discovery_error", error: @external_assistant_catalog_error) %></p>
+ <% elsif !Assistant::External.configured? %>
+ <p class="text-xs text-secondary mt-1"><%= t(".agent_discovery_configure_first") %></p>
+ <% end %>
<% end %>
<% end %>
</div>
diff --git a/config/locales/models/assistant/en.yml b/config/locales/models/assistant/en.yml
new file mode 100644
index 0000000000..7799893812
--- /dev/null
+++ b/config/locales/models/assistant/en.yml
@@ -0,0 +1,7 @@
+---
+en:
+ assistant:
+ external:
+ model_catalog:
+ default_agent_label: "Default agent (%{id})"
+ named_agent_label: "%{name} (%{id})"
diff --git a/config/locales/views/settings/hostings/en.yml b/config/locales/views/settings/hostings/en.yml
index 146dd6d5e4..b337694979 100644
--- a/config/locales/views/settings/hostings/en.yml
+++ b/config/locales/views/settings/hostings/en.yml
@@ -77,9 +77,21 @@ en:
token_label: API Token
token_placeholder: Enter the token from your agent provider
token_help: The authentication token provided by your external agent. This is sent as a Bearer token with each request.
- agent_id_label: Agent ID (Optional)
+ agent_id_label: Agent (Required)
agent_id_placeholder: "main (default)"
- agent_id_help: Routes to a specific agent when the provider hosts multiple. Leave blank for the default.
+ agent_id_help: Sure loads this list from the endpoint's /v1/models response. The selected agent controls routing; its underlying model is managed by the external service.
+ agent_discovery_configure_first: Save a valid endpoint URL and API token to load available agents.
+ external_agent_required: Select an external agent before saving.
+ external_agent_invalid: Select an agent returned by the configured endpoint.
+ external_agent_reselect: The endpoint changed and the previously selected agent is not available there. Select an agent from the new endpoint.
+ agent_discovery_error: "Could not load agents: %{error}"
+ external_info:
+ title: External AI configuration
+ items:
+ - Enter the full OpenAI-compatible endpoint URL ending in /v1/chat/completions.
+ - Sure discovers available agents from /v1/models after the endpoint and token are saved.
+ - The external service chooses the model behind each agent; Sure only selects the agent route.
+ - Authentication, endpoint, or agent errors are returned by the external service. Check its logs when a request fails.
disconnect_title: External connection
disconnect_description: Remove the external assistant connection and switch back to the builtin assistant.
disconnect_button: Disconnect
diff --git a/docs/hosting/ai.md b/docs/hosting/ai.md
index 7904811a36..959b58bb4f 100644
--- a/docs/hosting/ai.md
+++ b/docs/hosting/ai.md
@@ -1684,6 +1684,29 @@ throttle('chats/create', limit: 10, period: 1.minute) do |req|
end
```
+## External chat assistant
+
+The External assistant delegates chat to a remote OpenAI-compatible agent gateway. It is separate from the Builtin LLM provider described above.
+
+Configure it in **Settings → Self-Hosting → AI Assistant**, or with:
+
+```bash
+ASSISTANT_TYPE=external
+EXTERNAL_ASSISTANT_URL=https://your-agent-host/v1/chat/completions
+EXTERNAL_ASSISTANT_TOKEN=your-gateway-token # pipelock:ignore
+EXTERNAL_ASSISTANT_MODEL=openclaw/main
+```
+
+Configuration behavior:
+
+- `EXTERNAL_ASSISTANT_URL` is the full chat-completions endpoint. Sure sends requests to this URL verbatim; it does not append `/v1/chat/completions`.
+- The Settings form requires an agent selection. After the URL and token are saved, Sure requests the sibling `/v1/models` endpoint and shows the returned entries as agent choices. If you change the endpoint or token and the previously selected agent is not offered there, Sure saves the new connection and asks you to pick an agent again.
+- The selected value is sent as the OpenAI-compatible `model` routing value, such as `openclaw/main`. This selects an external agent. It does not select or change the LLM configured behind that agent.
+- The gateway must return standard streaming chat-completion events (`choices[0].delta.content`) followed by `data: [DONE]`.
+- An authentication, endpoint, or agent-selection failure comes from the external gateway. Check the gateway's response and logs when Sure reports an HTTP error.
+
+Upgrading: deployments that set only the URL and token keep working. When no agent is selected, Sure uses `openclaw/main`, which matches the previous implicit `main` agent. `EXTERNAL_ASSISTANT_AGENT_ID` is still read for existing deployments and maps to `openclaw/<id>` until an agent is selected. Once a model is selected in Settings or with `EXTERNAL_ASSISTANT_MODEL`, the agent routing header always follows that model. New configurations should use `EXTERNAL_ASSISTANT_MODEL`.
+
## Resources
- [OpenAI Documentation](https://platform.openai.com/docs)
@@ -1705,4 +1728,4 @@ For issues with AI features:
---
-**Last Updated:** August 2026
+**Last Updated:** September 2026
diff --git a/test/controllers/settings/hostings_controller_test.rb b/test/controllers/settings/hostings_controller_test.rb
index aefdf22103..f0d1708527 100644
--- a/test/controllers/settings/hostings_controller_test.rb
+++ b/test/controllers/settings/hostings_controller_test.rb
@@ -27,7 +27,7 @@ class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
teardown do
# These tests persist global Setting.* values; reset them so state can't
# leak into later (order-dependent) tests.
- %i[anthropic_access_token anthropic_base_url anthropic_model jev_api_key jev_endpoint jev_model llm_provider twelve_data_api_key openai_access_token openai_request_timeout ai_response_timeout external_assistant_token rentcast_api_key realie_api_key].each do |key|
+ %i[anthropic_access_token anthropic_base_url anthropic_model jev_api_key jev_endpoint jev_model llm_provider twelve_data_api_key openai_access_token openai_request_timeout ai_response_timeout external_assistant_url external_assistant_token external_assistant_model external_assistant_agent_id rentcast_api_key realie_api_key].each do |key|
Setting.public_send("#{key}=", nil)
end
end
@@ -632,23 +632,188 @@ class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
test "can update external assistant settings" do
with_self_hosting do
+ Assistant::External::ModelCatalog.any_instance.stubs(:models).returns([
+ { id: "openclaw/finance-bot", label: "finance-bot (openclaw/finance-bot)" }
+ ])
patch settings_hosting_url, params: { setting: {
- external_assistant_url: "https://agent.example.com/v1/chat",
+ external_assistant_url: "https://agent.example.com/v1/chat/completions",
external_assistant_token: "my-secret-token",
- external_assistant_agent_id: "finance-bot"
+ external_assistant_model: "openclaw/finance-bot"
} }
assert_redirected_to settings_hosting_url
- assert_equal "https://agent.example.com/v1/chat", Setting.external_assistant_url
+ assert_equal "https://agent.example.com/v1/chat/completions", Setting.external_assistant_url
assert_equal "my-secret-token", Setting.external_assistant_token
- assert_equal "finance-bot", Setting.external_assistant_agent_id
+ assert_equal "openclaw/finance-bot", Setting.external_assistant_model
end
ensure
Setting.external_assistant_url = nil
Setting.external_assistant_token = nil
+ Setting.external_assistant_model = nil
+ end
+
+ test "external assistant panel is hidden for builtin and shown for external" do
+ with_self_hosting do
+ get settings_hosting_url
+ assert_response :success
+ assert_select "[data-testid='external-assistant-info']", count: 0
+
+ users(:family_admin).family.update!(assistant_type: "external")
+ Assistant::External::ModelCatalog.any_instance.stubs(:models).returns([])
+
+ get settings_hosting_url
+ assert_response :success
+ assert_select "[data-testid='external-assistant-info']", count: 1
+ end
+ end
+
+ test "external agent dropdown uses discovered model ids" do
+ with_self_hosting do
+ users(:family_admin).family.update!(assistant_type: "external")
+ Setting.external_assistant_url = "https://agent.example.com/v1/chat/completions"
+ Setting.external_assistant_token = "secret"
+ Setting.external_assistant_model = "openclaw/research"
+ Assistant::External::ModelCatalog.any_instance.stubs(:models).returns([
+ { id: "openclaw/main", label: "main (openclaw/main)" },
+ { id: "openclaw/research", label: "research (openclaw/research)" }
+ ])
+
+ get settings_hosting_url
+
+ assert_response :success
+ assert_select "select[name='setting[external_assistant_model]'][aria-required='true']" do
+ assert_select "option[value='']", count: 0
+ assert_select "option[value='openclaw/main']", text: /main/
+ assert_select "option[selected][value='openclaw/research']", text: /research/
+ end
+ end
+ ensure
+ Setting.external_assistant_url = nil
+ Setting.external_assistant_token = nil
+ Setting.external_assistant_model = nil
+ end
+
+ test "rejects an external agent not returned by discovery" do
+ with_self_hosting do
+ Setting.external_assistant_url = "https://agent.example.com/v1/chat/completions"
+ Setting.external_assistant_token = "secret"
+ Assistant::External::ModelCatalog.any_instance.stubs(:models).returns([
+ { id: "openclaw/main", label: "main (openclaw/main)" }
+ ])
+
+ patch settings_hosting_url, params: { setting: { external_assistant_model: "openclaw/missing" } }
+
+ assert_response :unprocessable_entity
+ assert_nil Setting.external_assistant_model
+ assert_equal "Select an agent returned by the configured endpoint.", flash[:alert]
+ end
+ end
+
+ test "validation error page keeps the discovered agent options" do
+ with_self_hosting do
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => nil, "EXTERNAL_ASSISTANT_TOKEN" => nil, "EXTERNAL_ASSISTANT_MODEL" => nil) do
+ users(:family_admin).family.update!(assistant_type: "external")
+ Setting.external_assistant_url = "https://agent.example.com/v1/chat/completions"
+ Setting.external_assistant_token = "secret"
+ Setting.external_assistant_model = "openclaw/main"
+ Assistant::External::ModelCatalog.any_instance.stubs(:models).returns([
+ { id: "openclaw/main", label: "main (openclaw/main)" },
+ { id: "openclaw/research", label: "research (openclaw/research)" }
+ ])
+
+ patch settings_hosting_url, params: { setting: { external_assistant_model: "openclaw/missing" } }
+
+ assert_response :unprocessable_entity
+ assert_select "select[name='setting[external_assistant_model]']:not([disabled])" do
+ assert_select "option[selected][value='openclaw/main']"
+ assert_select "option[value='openclaw/research']"
+ end
+ end
+ end
+ ensure
+ Setting.external_assistant_url = nil
+ Setting.external_assistant_token = nil
+ Setting.external_assistant_model = nil
+ end
+
+ test "rejected external assistant changes leave stored settings untouched" do
+ with_self_hosting do
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => nil, "EXTERNAL_ASSISTANT_TOKEN" => nil, "EXTERNAL_ASSISTANT_MODEL" => nil) do
+ Setting.external_assistant_url = "https://old.example.com/v1/chat/completions"
+ Setting.external_assistant_token = "old-secret"
+ Setting.external_assistant_model = "openclaw/main"
+ Assistant::External::ModelCatalog.any_instance.stubs(:models)
+ .raises(Assistant::External::ModelCatalog::Error, "Agent discovery returned HTTP 401.")
+
+ patch settings_hosting_url, params: { setting: {
+ external_assistant_url: "https://new.example.com/v1/chat/completions",
+ external_assistant_token: "new-secret",
+ external_assistant_model: "openclaw/main"
+ } }
+
+ assert_response :unprocessable_entity
+ assert_equal "https://old.example.com/v1/chat/completions", Setting.external_assistant_url
+ assert_equal "old-secret", Setting.external_assistant_token
+ assert_equal "openclaw/main", Setting.external_assistant_model
+ end
+ end
+ ensure
+ Setting.external_assistant_url = nil
+ Setting.external_assistant_token = nil
+ Setting.external_assistant_model = nil
+ end
+
+ test "changing the endpoint clears an agent the new endpoint does not offer" do
+ with_self_hosting do
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => nil, "EXTERNAL_ASSISTANT_TOKEN" => nil, "EXTERNAL_ASSISTANT_MODEL" => nil) do
+ Setting.external_assistant_url = "https://old.example.com/v1/chat/completions"
+ Setting.external_assistant_token = "secret"
+ Setting.external_assistant_model = "openclaw/research"
+ Setting.external_assistant_agent_id = "research"
+ Assistant::External::ModelCatalog.any_instance.stubs(:models).returns([
+ { id: "openclaw/main", label: "main (openclaw/main)" }
+ ])
+
+ patch settings_hosting_url, params: { setting: {
+ external_assistant_url: "https://new.example.com/v1/chat/completions",
+ external_assistant_token: "********",
+ external_assistant_model: "openclaw/research"
+ } }
+
+ assert_redirected_to settings_hosting_url
+ assert_equal I18n.t("settings.hostings.assistant_settings.external_agent_reselect"), flash[:alert]
+ assert_equal "https://new.example.com/v1/chat/completions", Setting.external_assistant_url
+ assert_equal "secret", Setting.external_assistant_token
+ assert_nil Setting.external_assistant_model
+ assert_nil Setting.external_assistant_agent_id
+ end
+ end
+ ensure
+ Setting.external_assistant_url = nil
+ Setting.external_assistant_token = nil
+ Setting.external_assistant_model = nil
Setting.external_assistant_agent_id = nil
end
+ test "settings page shows a discovery error instead of failing on TLS errors" do
+ with_self_hosting do
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => nil, "EXTERNAL_ASSISTANT_TOKEN" => nil, "EXTERNAL_ASSISTANT_MODEL" => nil) do
+ users(:family_admin).family.update!(assistant_type: "external")
+ Setting.external_assistant_url = "https://agent.example.com/v1/chat/completions"
+ Setting.external_assistant_token = "secret"
+ stub_request(:get, "https://agent.example.com/v1/models").to_raise(OpenSSL::SSL::SSLError)
+
+ get settings_hosting_url
+
+ assert_response :success
+ assert_select "p.text-destructive", text: /Could not load agents/
+ end
+ end
+ ensure
+ Setting.external_assistant_url = nil
+ Setting.external_assistant_token = nil
+ end
+
test "does not overwrite token with masked placeholder" do
with_self_hosting do
Setting.external_assistant_token = "real-secret"
@@ -695,7 +860,7 @@ class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
ensure
Setting.external_assistant_url = nil
Setting.external_assistant_token = nil
- Setting.external_assistant_agent_id = nil
+ Setting.external_assistant_model = nil
end
test "disconnect external assistant requires admin" do
diff --git a/test/models/assistant/external/client_test.rb b/test/models/assistant/external/client_test.rb
index 74f2258ea8..3e37f25d1b 100644
--- a/test/models/assistant/external/client_test.rb
+++ b/test/models/assistant/external/client_test.rb
@@ -5,6 +5,7 @@ class Assistant::External::ClientTest < ActiveSupport::TestCase
@client = Assistant::External::Client.new(
url: "http://localhost:18789/v1/chat",
token: "test-token",
+ model: "openclaw/test-agent",
agent_id: "test-agent"
)
end
@@ -98,7 +99,7 @@ class Assistant::External::ClientTest < ActiveSupport::TestCase
) { |_| }
body = JSON.parse(capture[0].body)
- assert_equal "test-agent", body["model"]
+ assert_equal "openclaw/test-agent", body["model"]
assert_equal true, body["stream"]
assert_equal 3, body["messages"].size
assert_equal "sure-family-42", body["user"]
diff --git a/test/models/assistant/external/model_catalog_test.rb b/test/models/assistant/external/model_catalog_test.rb
new file mode 100644
index 0000000000..db68b95c35
--- /dev/null
+++ b/test/models/assistant/external/model_catalog_test.rb
@@ -0,0 +1,70 @@
+require "test_helper"
+
+class Assistant::External::ModelCatalogTest < ActiveSupport::TestCase
+ test "discovers gateway agents from the OpenAI models endpoint" do
+ request = stub_request(:get, "https://agent.example.com/v1/models")
+ .with(headers: { "Authorization" => "Bearer secret", "Accept" => "application/json" })
+ .to_return(
+ status: 200,
+ headers: { "Content-Type" => "application/json" },
+ body: { object: "list", data: [
+ { id: "openclaw" },
+ { id: "openclaw/default" },
+ { id: "openclaw/main" },
+ { id: "openclaw/research" }
+ ] }.to_json
+ )
+
+ models = Assistant::External::ModelCatalog.new(
+ url: "https://agent.example.com/v1/chat/completions",
+ token: "secret"
+ ).models
+
+ assert_requested request
+ assert_equal %w[openclaw openclaw/default openclaw/main openclaw/research], models.pluck(:id)
+ assert_equal "research (openclaw/research)", models.last[:label]
+ end
+
+ test "requires a full chat completions endpoint" do
+ catalog = Assistant::External::ModelCatalog.new(url: "https://agent.example.com", token: "secret")
+
+ error = assert_raises(Assistant::External::ModelCatalog::Error) { catalog.models }
+ assert_includes error.message, "endpoint must end in /chat/completions"
+ end
+
+ test "labels default agents through locale keys" do
+ stub_request(:get, "https://agent.example.com/v1/models")
+ .to_return(status: 200, body: { data: [ { id: "openclaw" } ] }.to_json)
+
+ models = Assistant::External::ModelCatalog.new(url: "https://agent.example.com/v1/chat/completions", token: "secret").models
+
+ assert_equal I18n.t("assistant.external.model_catalog.default_agent_label", id: "openclaw"), models.first[:label]
+ assert_equal "Default agent (openclaw)", models.first[:label]
+ end
+
+ test "rejects invalid models response shapes" do
+ [
+ [ { data: [] } ],
+ { data: { id: "openclaw/main" } },
+ { data: [ { id: "openclaw/main" }, nil ] },
+ { data: [ 1 ] },
+ { object: "list" }
+ ].each do |body|
+ stub_request(:get, "https://agent.example.com/v1/models").to_return(status: 200, body: body.to_json)
+ catalog = Assistant::External::ModelCatalog.new(url: "https://agent.example.com/v1/chat/completions", token: "secret")
+
+ error = assert_raises(Assistant::External::ModelCatalog::Error, "expected #{body.inspect} to be rejected") { catalog.models }
+ assert_equal "Agent discovery returned an invalid response.", error.message
+ end
+ end
+
+ test "wraps TLS and low-level connection failures as catalog errors" do
+ [ OpenSSL::SSL::SSLError, EOFError, Errno::ETIMEDOUT ].each do |error_class|
+ stub_request(:get, "https://agent.example.com/v1/models").to_raise(error_class)
+ catalog = Assistant::External::ModelCatalog.new(url: "https://agent.example.com/v1/chat/completions", token: "secret")
+
+ error = assert_raises(Assistant::External::ModelCatalog::Error) { catalog.models }
+ assert_includes error.message, "Agent discovery is unavailable"
+ end
+ end
+end
diff --git a/test/models/assistant/external_config_test.rb b/test/models/assistant/external_config_test.rb
index 77f2a342db..25b3be61db 100644
--- a/test/models/assistant/external_config_test.rb
+++ b/test/models/assistant/external_config_test.rb
@@ -4,6 +4,7 @@ class Assistant::ExternalConfigTest < ActiveSupport::TestCase
test "config reads URL from environment with priority over Setting" do
with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://from-env/v1/chat") do
assert_equal "http://from-env/v1/chat", Assistant::External.config.url
+ assert_equal "openclaw/main", Assistant::External.config.model
assert_equal "main", Assistant::External.config.agent_id
assert_equal "agent:main:main", Assistant::External.config.session_key
end
@@ -22,12 +23,13 @@ class Assistant::ExternalConfigTest < ActiveSupport::TestCase
Setting.external_assistant_token = nil
end
- test "config reads agent_id with custom value" do
+ test "config reads external model and derives the routing agent id" do
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://example.com/v1/chat",
"EXTERNAL_ASSISTANT_TOKEN" => "test-token",
- "EXTERNAL_ASSISTANT_AGENT_ID" => "finance-bot"
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/finance-bot"
) do
+ assert_equal "openclaw/finance-bot", Assistant::External.config.model
assert_equal "finance-bot", Assistant::External.config.agent_id
assert_equal "test-token", Assistant::External.config.token
end
@@ -45,7 +47,7 @@ class Assistant::ExternalConfigTest < ActiveSupport::TestCase
test "available_for? allows any user when no allowlist is set" do
user = OpenStruct.new(email: "[email protected]")
- with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://x", "EXTERNAL_ASSISTANT_TOKEN" => "t", "EXTERNAL_ASSISTANT_ALLOWED_EMAILS" => nil) do
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://x", "EXTERNAL_ASSISTANT_TOKEN" => "t", "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main", "EXTERNAL_ASSISTANT_ALLOWED_EMAILS" => nil) do
assert Assistant::External.available_for?(user)
end
end
@@ -53,7 +55,7 @@ class Assistant::ExternalConfigTest < ActiveSupport::TestCase
test "available_for? restricts to allowlisted emails" do
allowed = OpenStruct.new(email: "[email protected]")
denied = OpenStruct.new(email: "[email protected]")
- with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://x", "EXTERNAL_ASSISTANT_TOKEN" => "t", "EXTERNAL_ASSISTANT_ALLOWED_EMAILS" => "[email protected], [email protected]") do
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://x", "EXTERNAL_ASSISTANT_TOKEN" => "t", "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main", "EXTERNAL_ASSISTANT_ALLOWED_EMAILS" => "[email protected], [email protected]") do
assert Assistant::External.available_for?(allowed)
assert_not Assistant::External.available_for?(denied)
end
@@ -86,8 +88,39 @@ class Assistant::ExternalConfigTest < ActiveSupport::TestCase
assert_not Assistant::External.configured?
end
- with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://x", "EXTERNAL_ASSISTANT_TOKEN" => "t") do
+ # URL + token installs keep the pre-discovery implicit "main" agent.
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://x", "EXTERNAL_ASSISTANT_TOKEN" => "t", "EXTERNAL_ASSISTANT_MODEL" => nil, "EXTERNAL_ASSISTANT_AGENT_ID" => nil) do
+ assert Assistant::External.configured?
+ assert_equal "openclaw/main", Assistant::External.config.model
+ end
+
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => "http://x", "EXTERNAL_ASSISTANT_TOKEN" => "t", "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main") do
assert Assistant::External.configured?
end
end
+
+ test "legacy agent id maps to a model only while no model is selected" do
+ with_env_overrides("EXTERNAL_ASSISTANT_MODEL" => nil, "EXTERNAL_ASSISTANT_AGENT_ID" => "finance-bot") do
+ assert_equal "openclaw/finance-bot", Assistant::External.config.model
+ assert_equal "finance-bot", Assistant::External.config.agent_id
+ end
+
+ with_env_overrides("EXTERNAL_ASSISTANT_MODEL" => "openclaw/research", "EXTERNAL_ASSISTANT_AGENT_ID" => "finance-bot") do
+ assert_equal "openclaw/research", Assistant::External.config.model
+ assert_equal "research", Assistant::External.config.agent_id
+ end
+ end
+
+ test "selected model wins over a stale stored legacy agent id" do
+ Setting.external_assistant_agent_id = "old-bot"
+ Setting.external_assistant_model = "openclaw/new-bot"
+
+ with_env_overrides("EXTERNAL_ASSISTANT_MODEL" => nil, "EXTERNAL_ASSISTANT_AGENT_ID" => nil) do
+ assert_equal "openclaw/new-bot", Assistant::External.config.model
+ assert_equal "new-bot", Assistant::External.config.agent_id
+ end
+ ensure
+ Setting.external_assistant_agent_id = nil
+ Setting.external_assistant_model = nil
+ end
end
diff --git a/test/models/assistant_test.rb b/test/models/assistant_test.rb
index 5f3367d0c5..3ad3e43a95 100644
--- a/test/models/assistant_test.rb
+++ b/test/models/assistant_test.rb
@@ -352,7 +352,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://localhost:18789/v1/chat",
- "EXTERNAL_ASSISTANT_TOKEN" => "test-token"
+ "EXTERNAL_ASSISTANT_TOKEN" => "test-token",
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main"
) do
assistant_message = pending_assistant_message
@@ -372,7 +373,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => nil,
- "EXTERNAL_ASSISTANT_TOKEN" => nil
+ "EXTERNAL_ASSISTANT_TOKEN" => nil,
+ "EXTERNAL_ASSISTANT_MODEL" => nil
) do
# Ensure Settings are also cleared to avoid test pollution from
# other tests that may have set these values in the same process.
@@ -401,7 +403,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://localhost:18789/v1/chat",
- "EXTERNAL_ASSISTANT_TOKEN" => "test-token"
+ "EXTERNAL_ASSISTANT_TOKEN" => "test-token",
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main"
) do
assert_no_difference "AssistantMessage.count" do
assistant.respond_to(@message)
@@ -429,7 +432,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://localhost:18789/v1/chat",
- "EXTERNAL_ASSISTANT_TOKEN" => "test-token"
+ "EXTERNAL_ASSISTANT_TOKEN" => "test-token",
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main"
) do
assert_no_difference "AssistantMessage.count" do
assistant.respond_to(@message)
@@ -452,7 +456,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://localhost:18789/v1/chat",
- "EXTERNAL_ASSISTANT_TOKEN" => "test-token"
+ "EXTERNAL_ASSISTANT_TOKEN" => "test-token",
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main"
) do
assistant.respond_to(@message)
@@ -468,7 +473,7 @@ class AssistantTest < ActiveSupport::TestCase
@chat.user.family.update!(assistant_type: "external")
# Phase 1: Without config, errors gracefully
- with_env_overrides("EXTERNAL_ASSISTANT_URL" => nil, "EXTERNAL_ASSISTANT_TOKEN" => nil) do
+ with_env_overrides("EXTERNAL_ASSISTANT_URL" => nil, "EXTERNAL_ASSISTANT_TOKEN" => nil, "EXTERNAL_ASSISTANT_MODEL" => nil) do
Setting.external_assistant_url = nil
Setting.external_assistant_token = nil
Setting.clear_cache
@@ -495,7 +500,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://localhost:18789/v1/chat",
- "EXTERNAL_ASSISTANT_TOKEN" => "test-token"
+ "EXTERNAL_ASSISTANT_TOKEN" => "test-token",
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main"
) do
assistant = Assistant::External.new(@chat)
assistant_message = pending_assistant_message
@@ -525,7 +531,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://localhost:18789/v1/chat",
- "EXTERNAL_ASSISTANT_TOKEN" => "test-token"
+ "EXTERNAL_ASSISTANT_TOKEN" => "test-token",
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main"
) do
assistant.respond_to(@message)
@@ -543,7 +550,8 @@ class AssistantTest < ActiveSupport::TestCase
with_env_overrides(
"EXTERNAL_ASSISTANT_URL" => "http://localhost:18789/v1/chat",
- "EXTERNAL_ASSISTANT_TOKEN" => "test-token"
+ "EXTERNAL_ASSISTANT_TOKEN" => "test-token",
+ "EXTERNAL_ASSISTANT_MODEL" => "openclaw/main"
) do
assistant_message = pending_assistant_message
assistant.respond_to(@message, assistant_message: assistant_message)
diff --git a/test/models/user_test.rb b/test/models/user_test.rb
index 8e484355fa..b44e20bd7f 100644
--- a/test/models/user_test.rb
+++ b/test/models/user_test.rb
@@ -321,7 +321,7 @@ class UserTest < ActiveSupport::TestCase
test "ai_available? returns true when openai access token set in settings" do
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
previous = Setting.openai_access_token
- with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil do
+ with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil, EXTERNAL_ASSISTANT_MODEL: nil do
Setting.openai_access_token = nil
assert_not @user.ai_available?
@@ -336,7 +336,7 @@ class UserTest < ActiveSupport::TestCase
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
previous = Setting.openai_access_token
@user.family.update!(assistant_type: "external")
- with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: "http://localhost:18789/v1/chat", EXTERNAL_ASSISTANT_TOKEN: "test-token" do
+ with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: "http://localhost:18789/v1/chat", EXTERNAL_ASSISTANT_TOKEN: "test-token", EXTERNAL_ASSISTANT_MODEL: "openclaw/main" do
Setting.openai_access_token = nil
assert @user.ai_available?
end
@@ -348,7 +348,7 @@ class UserTest < ActiveSupport::TestCase
test "ai_available? returns false when external assistant is configured but family type is builtin" do
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
previous = Setting.openai_access_token
- with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: "http://localhost:18789/v1/chat", EXTERNAL_ASSISTANT_TOKEN: "test-token" do
+ with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: "http://localhost:18789/v1/chat", EXTERNAL_ASSISTANT_TOKEN: "test-token", EXTERNAL_ASSISTANT_MODEL: "openclaw/main" do
Setting.openai_access_token = nil
assert_not @user.ai_available?
end
@@ -360,7 +360,7 @@ class UserTest < ActiveSupport::TestCase
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
previous = Setting.openai_access_token
@user.family.update!(assistant_type: "external")
- with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: "http://localhost:18789/v1/chat", EXTERNAL_ASSISTANT_TOKEN: "test-token", EXTERNAL_ASSISTANT_ALLOWED_EMAILS: "[email protected]" do
+ with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: "http://localhost:18789/v1/chat", EXTERNAL_ASSISTANT_TOKEN: "test-token", EXTERNAL_ASSISTANT_MODEL: "openclaw/main", EXTERNAL_ASSISTANT_ALLOWED_EMAILS: "[email protected]" do
Setting.openai_access_token = nil
assert_not @user.ai_available?
end
@@ -413,7 +413,7 @@ class UserTest < ActiveSupport::TestCase
test "new member defaults show_ai_sidebar to false when AI is not available" do
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
previous = Setting.openai_access_token
- with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil do
+ with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil, EXTERNAL_ASSISTANT_MODEL: nil do
Setting.openai_access_token = nil
user = User.new(
family: families(:empty),
@@ -432,7 +432,7 @@ class UserTest < ActiveSupport::TestCase
test "new admin defaults show_ai_sidebar to true even when AI is not available" do
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
previous = Setting.openai_access_token
- with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil do
+ with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil, EXTERNAL_ASSISTANT_MODEL: nil do
Setting.openai_access_token = nil
user = User.new(
family: families(:empty),
@@ -464,7 +464,7 @@ class UserTest < ActiveSupport::TestCase
test "new guest defaults show_ai_sidebar to false when AI is not available" do
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
previous = Setting.openai_access_token
- with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil do
+ with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil, EXTERNAL_ASSISTANT_MODEL: nil do
Setting.openai_access_token = nil
user = User.new(
family: families(:empty),