This PR adds a Captain Assistant **Overview** page to show some KPI metrics (conversations handled, auto-resolution, handoff, hours saved, reopen-after-resolve, conversation depth) with trend deltas vs the previous window, a real knowledge card, and a lazily-loaded, cached LLM welcome summary. ### Highlights - **Two contextual banners** on the overview: - **Inbox banner** — prompts the user to connect an inbox when the assistant has none, so it can actually do work. - **Coverage banner** — warns when FAQ coverage is below 85% with more than 100 responses pending review, linking straight to the pending queue. Dismissal persists per-assistant for 24h via localStorage. - **Batched stats builder** (`Captain::AssistantStatsBuilder`) computes both windows in single FILTER-aggregated scans to cut round trips, behind new `stats`/`summary` endpoints. - **Cards included but intentionally left dummy / not rendered yet:** `ResponseQualityCard` (flagged responses) and `CreditUsageCard` (credit usage + daily chart). Credits are an account-wide counter with no per-assistant or daily history, so there is no real data to back them yet; they ship in the codebase but are not wired into the page. ### Index migration - Replaces `index_messages_on_sender_type_and_sender_id` with `index_messages_on_sender_and_created` `(sender_type, sender_id, created_at)`. - **Why it helps:** the per-assistant windowed lookups filter `sender_*` *and* a `created_at` range. The old 2-column index matched every lifetime row for the assistant and filtered the time slice at the heap (~89% of rows discarded); adding `created_at` as a range column lets Postgres scan only the window, and fixes the row-count estimate so the planner picks a hash join over a nested loop on `reporting_events`. - **Why dropping the old index is safe:** the new index is a left-prefix superset `(sender_type, sender_id, ...)`, so every query the old one served is still served. No code references it by name, and dropping it keeps write amplification on `messages` neutral. Built/dropped with `CONCURRENTLY` and `if_not_exists`/`if_exists` guards. ## Preview <img width="2572" height="1754" alt="CleanShot 2026-06-29 at 22 38 51@2x" src="https://github.com/user-attachments/assets/3798d09e-7850-48e4-b2cd-508533f15cea" /> ## Banners #### Inbox connect alert <img width="2178" height="612" alt="CleanShot 2026-06-30 at 14 26 55@2x" src="https://github.com/user-attachments/assets/373c371c-bb7d-4291-a0f9-620673078302" /> #### Coverage alert <img width="2178" height="612" alt="CleanShot 2026-06-30 at 14 25 41@2x" src="https://github.com/user-attachments/assets/e12d6308-11b6-4ba2-88a2-8a3077dd3e8f" /> --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
76 lines
2.5 KiB
Vue
76 lines
2.5 KiB
Vue
<script setup>
|
|
import { computed, ref, watch } from 'vue';
|
|
import { useRoute } from 'vue-router';
|
|
import CaptainAssistant from 'dashboard/api/captain/assistant';
|
|
import MessageFormatter from 'shared/helpers/MessageFormatter.js';
|
|
|
|
const props = defineProps({
|
|
range: {
|
|
type: String,
|
|
default: '30',
|
|
},
|
|
});
|
|
|
|
const route = useRoute();
|
|
const assistantId = computed(() => route.params.assistantId);
|
|
|
|
// Markdown summary generated by the model from the assistant's stats (served by
|
|
// the captain/assistants/:id/summary endpoint). Numbers are emphasised with
|
|
// **bold** so we can highlight them (see prose-strong styling below).
|
|
const welcomeMarkdown = ref('');
|
|
const isLoading = ref(false);
|
|
|
|
const fetchSummary = async () => {
|
|
isLoading.value = true;
|
|
try {
|
|
const { data } = await CaptainAssistant.getSummary({
|
|
assistantId: assistantId.value,
|
|
range: props.range,
|
|
});
|
|
welcomeMarkdown.value = data.message ?? '';
|
|
} catch {
|
|
welcomeMarkdown.value = '';
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
};
|
|
|
|
watch([() => props.range, assistantId], fetchSummary, { immediate: true });
|
|
|
|
// Render through the shared markdown formatter (html disabled, so it is safe)
|
|
// used everywhere else for Captain output, instead of a bespoke parser. It
|
|
// handles paragraphs, line breaks, links, lists and emphasis consistently.
|
|
const formattedSummary = computed(
|
|
() => new MessageFormatter(welcomeMarkdown.value).formattedMessage
|
|
);
|
|
</script>
|
|
|
|
<!-- eslint-disable-next-line vue/no-root-v-if -->
|
|
<template>
|
|
<div v-if="isLoading || welcomeMarkdown" class="flex flex-col gap-3">
|
|
<div class="flex items-center gap-1.5 text-n-slate-10">
|
|
<span class="i-lucide-sparkles size-3.5" />
|
|
<span class="text-xs">
|
|
{{ $t('CAPTAIN.OVERVIEW.WELCOME.LABEL') }}
|
|
</span>
|
|
</div>
|
|
<div
|
|
v-if="isLoading"
|
|
class="flex flex-col gap-5"
|
|
:aria-label="$t('CAPTAIN.OVERVIEW.WELCOME.LOADING')"
|
|
>
|
|
<div class="flex flex-col gap-2.5">
|
|
<div class="w-full h-5 rounded bg-n-slate-3 animate-pulse" />
|
|
<div class="w-11/12 h-5 rounded bg-n-slate-3 animate-pulse" />
|
|
<div class="w-4/6 h-5 rounded bg-n-slate-3 animate-pulse" />
|
|
</div>
|
|
<div class="w-5/6 h-5 rounded bg-n-slate-3 animate-pulse" />
|
|
</div>
|
|
<div
|
|
v-else
|
|
v-dompurify-html="formattedSummary"
|
|
class="max-w-none prose prose-p:text-lg prose-p:leading-relaxed prose-p:mt-0 prose-p:mb-3 last:prose-p:mb-0 prose-strong:font-bold prose-strong:tabular-nums prose-strong:text-n-brand text-n-slate-12"
|
|
/>
|
|
</div>
|
|
</template>
|