From 94e87a8b852f0c651bdbdf09158f0a9769c0ed98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Mata?= Date: Fri, 19 Dec 2025 16:30:21 +0100 Subject: [PATCH] Demo warning in `/chat` UI (#466) * Add demo warning to /chat * Missed two files! * Function calling works now, update message --- app/controllers/application_controller.rb | 18 ++++++++++++++++ app/controllers/sessions_controller.rb | 26 ++++++----------------- app/views/chats/index.html.erb | 6 ++++++ app/views/chats/new.html.erb | 6 ++++++ app/views/chats/show.html.erb | 6 ++++++ app/views/shared/_demo_warning.html.erb | 13 ++++++++++++ config/locales/views/chats/en.yml | 6 ++++++ 7 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 app/views/shared/_demo_warning.html.erb create mode 100644 config/locales/views/chats/en.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 260579d17..d63adfa8a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,8 @@ class ApplicationController < ActionController::Base before_action :set_default_chat before_action :set_active_storage_url_options + helper_method :demo_config, :demo_host_match?, :show_demo_warning? + private def detect_os user_agent = request.user_agent @@ -35,4 +37,20 @@ class ApplicationController < ActionController::Base port: request.optional_port } end + + def demo_config + Rails.application.config_for(:demo) + rescue RuntimeError, Errno::ENOENT, Psych::SyntaxError + nil + end + + def demo_host_match?(demo = demo_config) + return false unless demo.is_a?(Hash) && demo["hosts"].present? + + demo["hosts"].include?(request.host) + end + + def show_demo_warning? + demo_host_match? + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index fed96b56e..c9904ea6b 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -5,19 +5,13 @@ class SessionsController < ApplicationController layout "auth" def new - begin - demo = Rails.application.config_for(:demo) - @prefill_demo_credentials = demo_host_match?(demo) - if @prefill_demo_credentials - @email = params[:email].presence || demo["email"] - @password = params[:password].presence || demo["password"] - else - @email = params[:email] - @password = params[:password] - end - rescue RuntimeError, Errno::ENOENT, Psych::SyntaxError - # Demo config file missing or malformed - disable demo credential prefilling - @prefill_demo_credentials = false + demo = demo_config + @prefill_demo_credentials = demo_host_match?(demo) + + if @prefill_demo_credentials + @email = params[:email].presence || demo["email"] + @password = params[:password].presence || demo["password"] + else @email = params[:email] @password = params[:password] end @@ -91,10 +85,4 @@ class SessionsController < ApplicationController def set_session @session = Current.user.sessions.find(params[:id]) end - - def demo_host_match?(demo) - return false unless demo.present? && demo["hosts"].present? - - demo["hosts"].include?(request.host) - end end diff --git a/app/views/chats/index.html.erb b/app/views/chats/index.html.erb index 0f4507483..1225f3fbc 100644 --- a/app/views/chats/index.html.erb +++ b/app/views/chats/index.html.erb @@ -1,6 +1,12 @@
<%= turbo_frame_tag chat_frame do %>
+ <% if show_demo_warning? %> + <%= render "shared/demo_warning", + title: t("chats.demo_banner_title"), + message: t("chats.demo_banner_message") %> + <% end %> + <% if @chats.any? %>
diff --git a/app/views/chats/new.html.erb b/app/views/chats/new.html.erb index 8bee54293..f1017c2dc 100644 --- a/app/views/chats/new.html.erb +++ b/app/views/chats/new.html.erb @@ -2,6 +2,12 @@
<%= render "chats/chat_nav", chat: @chat %> + <% if show_demo_warning? %> + <%= render "shared/demo_warning", + title: t("chats.demo_banner_title"), + message: t("chats.demo_banner_message") %> + <% end %> +
<%= render "chats/ai_greeting" %>
diff --git a/app/views/chats/show.html.erb b/app/views/chats/show.html.erb index 945507f79..f9b170dbe 100644 --- a/app/views/chats/show.html.erb +++ b/app/views/chats/show.html.erb @@ -7,6 +7,12 @@
<%= render "chats/chat_nav", chat: @chat %> + + <% if show_demo_warning? %> + <%= render "shared/demo_warning", + title: t("chats.demo_banner_title"), + message: t("chats.demo_banner_message") %> + <% end %>
diff --git a/app/views/shared/_demo_warning.html.erb b/app/views/shared/_demo_warning.html.erb new file mode 100644 index 000000000..e1d003dac --- /dev/null +++ b/app/views/shared/_demo_warning.html.erb @@ -0,0 +1,13 @@ +<%# locals: title:, message: %> +
+
+
+ <%= icon "info", size: "sm", color: "blue-600" %> +
+
+

<%= title %>

+

<%= message %>

+
+
+
+ diff --git a/config/locales/views/chats/en.yml b/config/locales/views/chats/en.yml new file mode 100644 index 000000000..26c4c9a7d --- /dev/null +++ b/config/locales/views/chats/en.yml @@ -0,0 +1,6 @@ +--- +en: + chats: + demo_banner_title: "Demo Mode Active" + demo_banner_message: "You are using an open-weights Qwen3 LLM with credits provided by Cloudflare Workers AI. Result may vary since the codebase was mostly tested on `gpt-4.1` but your tokens don't go anywhere else to be trained with! 🤖" +