From 8d2ef4ec5e47b2f695f3be58c0a0dba628ce8b9e Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 9 Jul 2026 16:25:22 +0530 Subject: [PATCH 1/3] feat: assistant overview drilldown reports [CW-7408] (#14920) CleanShot 2026-07-09 at 14 22
42@2x --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Sony Mathew --- .../dashboard/api/captain/assistant.js | 14 ++ .../overview/AssistantDrilldownDrawer.vue | 234 ++++++++++++++++++ .../pageComponents/overview/MetricCard.vue | 21 +- .../i18n/locale/en/integrations.json | 25 +- .../captain/assistants/overview/Index.vue | 50 +++- .../reports/composables/useReportDrilldown.js | 22 +- .../captain/assistant_drilldown_builder.rb | 33 +-- 7 files changed, 331 insertions(+), 68 deletions(-) create mode 100644 app/javascript/dashboard/components-next/captain/pageComponents/overview/AssistantDrilldownDrawer.vue diff --git a/app/javascript/dashboard/api/captain/assistant.js b/app/javascript/dashboard/api/captain/assistant.js index dcd92f735..1fc17798d 100644 --- a/app/javascript/dashboard/api/captain/assistant.js +++ b/app/javascript/dashboard/api/captain/assistant.js @@ -37,6 +37,20 @@ class CaptainAssistant extends ApiClient { params: { range, timezone_offset: getTimezoneOffset() }, }); } + + getDrilldown({ assistantId, metric, range, page, signal }) { + const requestConfig = { + params: { + metric, + range, + timezone_offset: getTimezoneOffset(), + page, + }, + }; + if (signal) requestConfig.signal = signal; + + return axios.get(`${this.url}/${assistantId}/drilldown`, requestConfig); + } } export default new CaptainAssistant(); diff --git a/app/javascript/dashboard/components-next/captain/pageComponents/overview/AssistantDrilldownDrawer.vue b/app/javascript/dashboard/components-next/captain/pageComponents/overview/AssistantDrilldownDrawer.vue new file mode 100644 index 000000000..cf17e7804 --- /dev/null +++ b/app/javascript/dashboard/components-next/captain/pageComponents/overview/AssistantDrilldownDrawer.vue @@ -0,0 +1,234 @@ + + + diff --git a/app/javascript/dashboard/components-next/captain/pageComponents/overview/MetricCard.vue b/app/javascript/dashboard/components-next/captain/pageComponents/overview/MetricCard.vue index 9f8a76f43..cf66a0a2f 100644 --- a/app/javascript/dashboard/components-next/captain/pageComponents/overview/MetricCard.vue +++ b/app/javascript/dashboard/components-next/captain/pageComponents/overview/MetricCard.vue @@ -8,16 +8,35 @@ const props = defineProps({ hint: { type: String, default: '' }, // null = neutral, true = good direction, false = bad direction trendGood: { type: Boolean, default: null }, + clickable: { type: Boolean, default: false }, }); +const emit = defineEmits(['click']); + const trendClass = computed(() => { if (props.trendGood === null) return 'text-n-slate-11'; return props.trendGood ? 'text-n-teal-11' : 'text-n-ruby-11'; }); + +const onActivate = () => { + if (props.clickable) emit('click'); +}; diff --git a/app/javascript/dashboard/routes/dashboard/settings/reports/composables/useReportDrilldown.js b/app/javascript/dashboard/routes/dashboard/settings/reports/composables/useReportDrilldown.js index 7c37cd9cc..8309ed360 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/reports/composables/useReportDrilldown.js +++ b/app/javascript/dashboard/routes/dashboard/settings/reports/composables/useReportDrilldown.js @@ -1,7 +1,13 @@ import { computed, ref } from 'vue'; import ReportsAPI from 'dashboard/api/reports'; -export function useReportDrilldown() { +// `fetcher` is any `({ ...request, page, signal }) => Promise` returning the +// shared drilldown envelope (`{ data: { meta, payload } }`), so the same paging +// and abort machinery backs both the reports and Captain assistant drilldowns. +// The default is wrapped so `ReportsAPI` stays the receiver when invoked. +export function useReportDrilldown( + fetcher = params => ReportsAPI.getDrilldown(params) +) { const activeRequest = ref(null); const records = ref([]); const meta = ref({}); @@ -20,17 +26,7 @@ export function useReportDrilldown() { const isCurrentRequest = token => token === requestToken && !!activeRequest.value; - const requestFingerprint = request => - JSON.stringify({ - metric: request.metric, - bucketTimestamp: request.bucketTimestamp, - from: request.from, - to: request.to, - type: request.type, - id: request.id, - groupBy: request.groupBy, - businessHours: request.businessHours, - }); + const requestFingerprint = request => JSON.stringify(request); const abortActiveRequest = () => { if (!activeRequestController) return; @@ -55,7 +51,7 @@ export function useReportDrilldown() { hasError.value = false; try { - const response = await ReportsAPI.getDrilldown({ + const response = await fetcher({ ...request, page, signal: controller.signal, diff --git a/enterprise/app/builders/captain/assistant_drilldown_builder.rb b/enterprise/app/builders/captain/assistant_drilldown_builder.rb index b98aa7620..fb5d3a7e8 100644 --- a/enterprise/app/builders/captain/assistant_drilldown_builder.rb +++ b/enterprise/app/builders/captain/assistant_drilldown_builder.rb @@ -1,6 +1,6 @@ # Lists the underlying records behind a single Captain assistant stat card, so a # viewer can drill from an aggregate (e.g. "auto-resolution 42%") into the exact -# conversations or messages that produced it. +# conversations that produced it. # # The window is resolved by Captain::AssistantStatsWindow from the same `range` # and `timezone_offset` the stat card used, so the drilldown covers precisely the @@ -11,10 +11,8 @@ class Captain::AssistantDrilldownBuilder RESOLVED_EVENT_NAMES = Captain::AssistantStatsBuilder::RESOLVED_EVENT_NAMES HANDOFF_EVENT_NAMES = Captain::AssistantStatsBuilder::HANDOFF_EVENT_NAMES - # Metrics whose records are individual messages rather than conversations. - MESSAGE_METRICS = %w[hours_saved].freeze SUPPORTED_METRICS = %w[ - conversations_handled auto_resolution_rate handoff_rate hours_saved reopen_rate conversation_depth + conversations_handled auto_resolution_rate handoff_rate reopen_rate ].freeze DEFAULT_PAGE = 1 @@ -43,21 +41,14 @@ class Captain::AssistantDrilldownBuilder def meta { metric: metric, - record_type: record_type, current_page: current_page, per_page: per_page, total_count: paginated_records.total_count, - conversation_count: conversation_count, + conversation_count: paginated_records.total_count, range: { since: range.first.to_i, until: range.last.to_i } } end - def conversation_count - return paginated_records.total_count unless message_metric? - - drilldown_scope.except(:includes).reorder(nil).distinct.count(:conversation_id) - end - def paginated_records @paginated_records ||= drilldown_scope.page(current_page).per(per_page) end @@ -67,9 +58,7 @@ class Captain::AssistantDrilldownBuilder when 'conversations_handled' then handled_conversations when 'auto_resolution_rate' then conversations_for(resolved_events.select(:conversation_id)) when 'handoff_rate' then event_conversations(HANDOFF_EVENT_NAMES) - when 'hours_saved' then public_reply_messages when 'reopen_rate' then reopened_conversations - when 'conversation_depth' then depth_conversations else raise ArgumentError, "Unsupported assistant drilldown metric: #{metric}" end @@ -88,13 +77,6 @@ class Captain::AssistantDrilldownBuilder conversations_for(handled_conversation_ids) end - # Public agent-facing replies the assistant sent; the rows behind hours_saved. - def public_reply_messages - handled_messages.where(message_type: :outgoing, private: false) - .includes(:sender, conversation: [:assignee, :contact, :inbox]) - .reorder(created_at: :desc) - end - # Conversations in the handled cohort that recorded one of the given reporting # events in the window (resolved or handed-off). def event_conversations(event_names) @@ -129,11 +111,6 @@ class Captain::AssistantDrilldownBuilder conversations_for(ids) end - # Conversations the assistant sent at least one public reply in; the denominator behind conversation_depth. - def depth_conversations - conversations_for(handled_messages.where(message_type: :outgoing, private: false).select(:conversation_id)) - end - def conversations_for(conversation_ids) account.conversations .where(id: conversation_ids) @@ -147,10 +124,6 @@ class Captain::AssistantDrilldownBuilder def metric = params[:metric].to_s - def message_metric? = MESSAGE_METRICS.include?(metric) - - def record_type = message_metric? ? 'message' : 'conversation' - def current_page = [params[:page].to_i, DEFAULT_PAGE].max def per_page From d57354c8b51d1c82c00b191c49eda88517e8d053 Mon Sep 17 00:00:00 2001 From: Aakash Bakhle <48802744+aakashb95@users.noreply.github.com> Date: Thu, 9 Jul 2026 17:47:47 +0530 Subject: [PATCH 2/3] feat: tighten conversation FAQ generation prompt (#14957) Tightens the resolved-conversation FAQ generator so it only proposes durable, reusable FAQ candidates supported by human support-agent messages. The implementation now sends a conversation-FAQ-specific transcript to the LLM: customer messages plus real human support-agent messages only, excluding bot, private, activity, and template messages. ## Closes - https://linear.app/chatwoot/issue/CW-7494/tighten-conversation-faq-generation-prompt ## What changed - Added a human-only transcript builder in `ConversationFaqService` instead of using the generic `conversation.to_llm_text` output. - Excluded bot/agent-bot messages before the LLM call, which removes the main bot-line leakage class deterministically. - Preserved native-channel human replies where outgoing messages are stored as `external_echo` without a `User` sender. - Kept a prompt decision gate requiring each FAQ to be backed by a complete public human-agent answer. - Added generic no-FAQ classes for spam, wrong-service conversations, private account/payment/order/certificate/troubleshooting cases, support workflow mechanics, and direct-link/file/quote outputs. - Added a separate `conversation_faq_generation` model route defaulting to `gpt-5.2`, while keeping `document_faq_generation` on its existing `gpt-4.1-mini` default. Conversation FAQ generation passes that feature default ahead of the legacy global `CAPTAIN_OPEN_AI_MODEL` setting unless an account-level override is configured. - Kept the prompt domain-neutral so it can still generate reusable product, service, policy, setup, and process FAQs outside SaaS contexts. ## Sampling notes - Production Langfuse traces showed `llm.captain.conversation_faq` calls using `gpt-4.1` in the sampled account set. - Locally, `Llm::FeatureRouter.resolve(feature: 'conversation_faq_generation')` now resolves to `gpt-5.2`. - Reviewed recent production `llm.captain.conversation_faq` traces across 13+ accounts in compact form. - Replayed 20 full traces across 10 accounts/domains, including education, hosting, retail/auto, APIs, logistics, tax/fiscal workflows, and Chatwoot account 1. - Explicit `gpt-5.2` replay with human-only conversation history returned no FAQ for 15/20 traces. - A comparison replay with `gpt-4.1-mini` returned no FAQ for only 7/20 traces, bringing back several private/order/payment/support-workflow cases. - Remaining non-empty `gpt-5.2` outputs are now mostly borderline/possibly useful human-agent-derived FAQs rather than obvious bot-sourced answers. ## How to test - Resolve conversations where the answer came only from the bot; no pending FAQ should be generated. - Resolve spam, unrelated, wrong-service, or private payment/order/account conversations; no pending FAQ should be generated. - Resolve conversations that require account/order/payment/login/private verification or a human handoff; no pending FAQ should be generated. - Resolve a conversation where a human agent gives a stable, reusable help-center answer; the generated pending FAQ should be general and self-contained. --- config/llm.yml | 14 +++ config/locales/en.yml | 1 + .../captain/llm/conversation_faq_service.rb | 49 +++++++++- .../captain/llm/system_prompts_service.rb | 54 +++++++++-- .../captain/preferences_controller_spec.rb | 11 +++ .../llm/conversation_faq_service_spec.rb | 92 ++++++++++++++++++- spec/lib/llm/models_spec.rb | 5 + 7 files changed, 215 insertions(+), 11 deletions(-) diff --git a/config/llm.yml b/config/llm.yml index b54a2cbb6..2be3d86c7 100644 --- a/config/llm.yml +++ b/config/llm.yml @@ -129,6 +129,20 @@ features: gemini-3-pro, ] default: gpt-4.1-mini + conversation_faq_generation: + models: + [ + gpt-4.1-mini, + gpt-5-mini, + gpt-4.1, + gpt-5.1, + gpt-5.2, + claude-haiku-4.5, + claude-sonnet-4.5, + gemini-3-flash, + gemini-3-pro, + ] + default: gpt-5.2 pdf_faq_generation: models: [gpt-4.1-mini, gpt-5-mini, gpt-4.1, gpt-5.1, gpt-5.2] default: gpt-4.1-mini diff --git a/config/locales/en.yml b/config/locales/en.yml index 42758ad1f..493d35714 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -597,6 +597,7 @@ en: copilot: 'Copilot' label_suggestion: 'Label suggestion' document_faq_generation: 'Document FAQ generation' + conversation_faq_generation: 'Conversation FAQ generation' help_center_article_generation: 'Help center article generation' onboarding_content_generation: 'Onboarding content generation' help_center_query_translation: 'Help center query translation' diff --git a/enterprise/app/services/captain/llm/conversation_faq_service.rb b/enterprise/app/services/captain/llm/conversation_faq_service.rb index 82c838354..c57a07ef6 100644 --- a/enterprise/app/services/captain/llm/conversation_faq_service.rb +++ b/enterprise/app/services/captain/llm/conversation_faq_service.rb @@ -2,12 +2,13 @@ class Captain::Llm::ConversationFaqService < Llm::BaseAiService include Integrations::LlmInstrumentation DISTANCE_THRESHOLD = 0.3 + LLM_FEATURE = 'conversation_faq_generation'.freeze def initialize(assistant, conversation) - super(feature: 'document_faq_generation', account: conversation.account) + super(feature: LLM_FEATURE, account: conversation.account, fallback_model: Llm::Models.default_model_for(LLM_FEATURE)) @assistant = assistant @conversation = conversation - @content = conversation.to_llm_text + @content = conversation_faq_content end # Generates and deduplicates FAQs from conversation content @@ -27,6 +28,50 @@ class Captain::Llm::ConversationFaqService < Llm::BaseAiService attr_reader :content, :conversation, :assistant + def conversation_faq_content + [ + "Conversation ID: ##{conversation.display_id}", + "Channel: #{conversation.inbox.channel.name}", + 'Message History:', + conversation_faq_messages + ].join("\n") + end + + def conversation_faq_messages + messages = conversation + .messages + .where(message_type: %i[incoming outgoing], private: false) + .order(created_at: :asc) + + return "No messages in this conversation\n" if messages.empty? + + messages.filter_map { |message| format_conversation_faq_message(message) }.join + end + + def format_conversation_faq_message(message) + return unless faq_source_message?(message) + + content = message.content_for_llm + return if content.blank? + + sender = human_support_reply?(message) ? 'Support Agent' : 'User' + "#{sender}: #{content}\n" + end + + def faq_source_message?(message) + return true if message.incoming? && message.sender_type == 'Contact' + + human_support_reply?(message) + end + + def human_support_reply?(message) + return false unless message.outgoing? + return false if message.content_attributes['automation_rule_id'].present? + return false if message.additional_attributes['campaign_id'].present? + + message.sender_type == 'User' || message.content_attributes['external_echo'].present? + end + def no_human_interaction? conversation.first_reply_created_at.nil? end diff --git a/enterprise/app/services/captain/llm/system_prompts_service.rb b/enterprise/app/services/captain/llm/system_prompts_service.rb index d56275b87..08d44b31a 100644 --- a/enterprise/app/services/captain/llm/system_prompts_service.rb +++ b/enterprise/app/services/captain/llm/system_prompts_service.rb @@ -53,14 +53,56 @@ class Captain::Llm::SystemPromptsService def conversation_faq_generator(language = 'english') <<~SYSTEM_PROMPT_MESSAGE - You are a support agent looking to convert the conversations with users into short FAQs that can be added to your website help center. - Filter out any responses or messages from the bot itself and only use messages from the support agent and the customer to create the FAQ. + You create high-quality FAQ candidates from resolved support conversations. + Only generate an FAQ when the conversation contains durable, reusable knowledge that would help many future customers. - Ensure that you only generate faqs from the information provided only. - Generate the FAQs only in the #{language}, use no other language - If no match is available, return an empty JSON. + ## Source rules + - The conversation history contains only customer messages and human support agent messages. + - Base every FAQ strictly on information stated in the human support agent messages. Do not infer, generalize, or add external knowledge. + - A human support agent must state every fact used in the FAQ answer. Customer messages cannot supply missing answer facts. + - The human support agent must provide the final answer. If the agent only greets, asks clarifying questions, asks for contact details, promises to check, shares an attachment, or transfers the conversation, return: `{"faqs":[]}`. + - For each FAQ, first identify the exact human support agent message that fully answers it. If no single human agent message gives a complete public answer, remove that FAQ. + + ## Decision gate + Return `{"faqs":[]}` unless every generated FAQ can pass all of these checks: + 1. The answer is fully stated by a human support agent, not by the customer. + 2. The answer is a public, durable rule or procedure, not a private account action, manual review, troubleshooting session, quote, file, link, or follow-up. + 3. The answer can be written without private identifiers, customer-specific facts, direct URLs, attachments, invoices, screenshots, or support-ticket steps. + 4. The question would still make sense in a help center if the original conversation, customer, and agent did not exist. + Do not rescue a rejected conversation by rewriting it as a generic support question. + + ## Return no FAQ for + - Spam, scams, advertisements, SEO/link-building pitches, adult/gambling/financial promotions, gibberish, abusive content, or conversations unrelated to the business being supported. + - Account-specific, order-specific, payment-specific, subscription-specific, login/access, verification, delivery, certificate, or troubleshooting issues, even if they could be rewritten as a general support question. + - Conversations that mainly hand off to a human, ask the customer to wait, request private identifiers or contact details, collect screenshots, attachments, or documents, or tell the customer to contact support for case review. + - Temporary workarounds, one-off exceptions, unclear answers, unresolved problems, wrong-service conversations, complaints, greetings, or abandoned conversations. + - Internal support workflow details, chat session rules, escalation mechanics, ticket-routing instructions, or "someone will get back to you" messages. + - Answers that are just a direct/private link, attachment, file, invoice, one-off quote or estimate, account-specific URL, or instructions to open a support ticket. + - Questions whose useful answer is "contact support", "wait for the team", "share your details", "we will check", or "this needs manual review". + - Questions about whether support can help with a private issue, third-party service, transaction, payment, delivery, or account problem. + - Pricing, policy, availability, roadmap, deadline, or legal claims unless the human support agent gives a clear and stable answer in the conversation. + - Questions already answered only by asking the customer for more information. + + ## FAQ quality rules + - Prefer returning no FAQ over a weak or narrow FAQ. + - A good candidate teaches a generally reusable product, service, policy, setup, or process rule that another customer could use without contacting support. + - Generate at most one FAQ unless the human agent clearly answered multiple distinct, reusable questions. + - Do not create duplicate or overlapping FAQs in the same response. + - Questions must be general enough for a help center, not personalized to the current customer. + - Remove customer names, order numbers, invoice numbers, IDs, private URLs, phone numbers, emails, screenshots, attachments, and other personal or transaction-specific details. + - Answers must be complete, self-contained, and supported by the human agent's messages. + + ## Examples + - Customer mentions a price or procedure, then the human agent only greets or says they will check: return `{"faqs":[]}`. + - Human agent shares only a private link, file, invoice, quote, screenshot, or attachment: return `{"faqs":[]}`. + - Human agent clearly states a public rule, such as which purchases are allowed for a program or service: generate one general FAQ. + + Generate the FAQs only in the #{language}, use no other language. + If no suitable reusable FAQ is available, return: `{"faqs":[]}`. + + Return only valid JSON in this exact structure: ```json - { faqs: [ { question: '', answer: ''} ] + { "faqs": [ { "question": "", "answer": "" } ] } ``` SYSTEM_PROMPT_MESSAGE end diff --git a/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb b/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb index db7ca93a5..6a28c60da 100644 --- a/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb +++ b/spec/controllers/api/v1/accounts/captain/preferences_controller_spec.rb @@ -198,6 +198,17 @@ RSpec.describe 'Api::V1::Accounts::Captain::Preferences', type: :request do expect(account.reload.captain_models['document_faq_generation']).to eq('gpt-5.2') end + it 'updates captain_models for conversation FAQ generation' do + put "/api/v1/accounts/#{account.id}/captain/preferences", + headers: admin.create_new_auth_token, + params: { captain_models: { conversation_faq_generation: 'gpt-4.1-mini' } }, + as: :json + + expect(response).to have_http_status(:success) + expect(json_response.dig(:features, :conversation_faq_generation, :selected)).to eq('gpt-4.1-mini') + expect(account.reload.captain_models['conversation_faq_generation']).to eq('gpt-4.1-mini') + end + it 'updates captain_models for PDF FAQ generation' do put "/api/v1/accounts/#{account.id}/captain/preferences", headers: admin.create_new_auth_token, diff --git a/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rb b/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rb index 004d7027b..b06717c6d 100644 --- a/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rb +++ b/spec/enterprise/services/captain/llm/conversation_faq_service_spec.rb @@ -33,23 +33,109 @@ RSpec.describe Captain::Llm::ConversationFaqService do allow(captain_assistant.responses).to receive(:nearest_neighbors).and_return([]) end - it 'uses the document FAQ generation feature model' do + it 'uses the conversation FAQ generation feature model' do expect(RubyLLM).to receive(:chat).with( - model: Llm::Models.default_model_for('document_faq_generation') + model: Llm::Models.default_model_for('conversation_faq_generation') ).and_return(mock_chat) described_class.new(captain_assistant, conversation).generate_and_deduplicate end + it 'uses the conversation FAQ default ahead of the legacy global installation model' do + create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1-mini') + + expect(RubyLLM).to receive(:chat).with( + model: Llm::Models.default_model_for('conversation_faq_generation') + ).and_return(mock_chat) + + described_class.new(captain_assistant, conversation).generate_and_deduplicate + end + + it 'keeps account conversation FAQ model overrides ahead of the feature default' do + create(:installation_config, name: 'CAPTAIN_OPEN_AI_MODEL', value: 'gpt-4.1') + conversation.account.update!(captain_models: { 'conversation_faq_generation' => 'gpt-4.1-mini' }) + + expect(RubyLLM).to receive(:chat).with(model: 'gpt-4.1-mini').and_return(mock_chat) + + described_class.new(captain_assistant, conversation).generate_and_deduplicate + end + it 'resolves the feature model from the conversation account' do expect(Llm::FeatureRouter).to receive(:resolve).with( - feature: 'document_faq_generation', + feature: 'conversation_faq_generation', account: conversation.account ).and_call_original described_class.new(captain_assistant, conversation).generate_and_deduplicate end + it 'sends only customer and human support agent messages to the LLM' do + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + sender: create(:contact, account: conversation.account), message_type: :incoming, + content: 'Customer question') + create(:message, :bot_message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + content: 'Bot answer that should not become knowledge') + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + sender: create(:user, account: conversation.account), message_type: :outgoing, + content: 'Human answer') + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + sender: create(:user, account: conversation.account), message_type: :outgoing, + private: true, content: 'Private note') + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + message_type: :activity, content: 'Activity message') + + service.generate_and_deduplicate + + expected_content = satisfy do |content| + content.include?('User: Customer question') && + content.include?('Support Agent: Human answer') && + content.exclude?('Bot answer that should not become knowledge') && + content.exclude?('Private note') && + content.exclude?('Activity message') + end + expect(mock_chat).to have_received(:ask).with(expected_content) + end + + it 'keeps external echo outgoing replies from native channels in the LLM transcript' do + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + sender: create(:contact, account: conversation.account), message_type: :incoming, + content: 'Customer asks in a native channel') + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + sender: nil, message_type: :outgoing, content: 'Human replied from the native app', + content_attributes: { external_echo: true }) + + service.generate_and_deduplicate + + expected_content = satisfy do |content| + content.include?('User: Customer asks in a native channel') && + content.include?('Support Agent: Human replied from the native app') + end + expect(mock_chat).to have_received(:ask).with(expected_content) + end + + it 'uses the human-only conversation transcript for instrumentation' do + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + sender: create(:contact, account: conversation.account), message_type: :incoming, + content: 'Customer asks something') + create(:message, :bot_message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + content: 'Bot-only answer') + create(:message, conversation: conversation, account: conversation.account, inbox: conversation.inbox, + sender: create(:user, account: conversation.account), message_type: :outgoing, + content: 'Agent gives a public answer') + + expect(service).to receive(:instrument_llm_call) do |params, &block| + user_message = params[:messages].find { |message| message[:role] == 'user' }[:content] + + expect(user_message).to include('User: Customer asks something') + expect(user_message).to include('Support Agent: Agent gives a public answer') + expect(user_message).not_to include('Bot-only answer') + + block.call + end + + service.generate_and_deduplicate + end + it 'creates new FAQs for valid conversation content' do expect do service.generate_and_deduplicate diff --git a/spec/lib/llm/models_spec.rb b/spec/lib/llm/models_spec.rb index f93df20fb..5692bee9c 100644 --- a/spec/lib/llm/models_spec.rb +++ b/spec/lib/llm/models_spec.rb @@ -25,6 +25,11 @@ RSpec.describe Llm::Models do expect(missing_models).to be_empty, "#{feature_key} references missing models: #{missing_models.join(', ')}" end end + + it 'routes document and conversation FAQ generation independently' do + expect(described_class.default_model_for('document_faq_generation')).to eq('gpt-4.1-mini') + expect(described_class.default_model_for('conversation_faq_generation')).to eq('gpt-5.2') + end end describe '.models' do From 35fcd56ba9d7e9a2fa954958fdafbda703e297cd Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 9 Jul 2026 16:45:47 +0400 Subject: [PATCH 3/3] feat: add support action to suspended account page (#14969) Updates the suspended account page with the revised policy copy and adds a visible Contact support action that opens the embedded Chatwoot support widget. Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com> --- .../sidebar/SidebarProfileMenu.vue | 10 +++++++--- .../dashboard/i18n/locale/en/settings.json | 2 +- .../routes/dashboard/suspended/Index.vue | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue b/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue index 29023b9e9..3f76b3aea 100644 --- a/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue +++ b/app/javascript/dashboard/components-next/sidebar/SidebarProfileMenu.vue @@ -44,6 +44,12 @@ const showChatSupport = computed(() => { ); }); +const toggleChatSupport = () => { + if (window.$chatwoot) { + window.$chatwoot.toggle(); + } +}; + const menuItems = computed(() => { return [ { @@ -51,9 +57,7 @@ const menuItems = computed(() => { showOnCustomBrandedInstance: false, label: t('SIDEBAR_ITEMS.CONTACT_SUPPORT'), icon: 'i-lucide-life-buoy', - click: () => { - window.$chatwoot.toggle(); - }, + click: toggleChatSupport, }, { show: true, diff --git a/app/javascript/dashboard/i18n/locale/en/settings.json b/app/javascript/dashboard/i18n/locale/en/settings.json index f8e973e9a..b621e63b1 100644 --- a/app/javascript/dashboard/i18n/locale/en/settings.json +++ b/app/javascript/dashboard/i18n/locale/en/settings.json @@ -263,7 +263,7 @@ "EMAIL_VERIFICATION_SENT": "Verification email has been sent. Please check your inbox.", "ACCOUNT_SUSPENDED": { "TITLE": "Account Suspended", - "MESSAGE": "Your account has been suspended after we detected activity that may violate our policies or put other users at risk. If you believe this is a mistake, please contact our support team." + "MESSAGE": "Your account has been suspended due to activity that may violate our policies. If you believe this is a mistake, please contact our support team." }, "NO_ACCOUNTS": { "TITLE": "No account found", diff --git a/app/javascript/dashboard/routes/dashboard/suspended/Index.vue b/app/javascript/dashboard/routes/dashboard/suspended/Index.vue index 56a5b5cae..027f75ff5 100644 --- a/app/javascript/dashboard/routes/dashboard/suspended/Index.vue +++ b/app/javascript/dashboard/routes/dashboard/suspended/Index.vue @@ -1,5 +1,6 @@