Merge remote-tracking branch 'origin/feat/coach-frame' into release/v1.40.2

This commit is contained in:
Marc-André Bombeck committed 2026-10-05 07:16:09 +02:00
commit 57a889ef3c
34 files changed
+2659 -428

No files matched your search

+2 -54
View File
@@ -24,8 +24,8 @@ import {
useCoachConversationHistory,
useDeleteCoachConversationWithUndo,
} from "@/components/insights/coach-panel/use-coach";
import type { CoachConversationDTO } from "@/lib/ai/coach/types";
import { useCoachLaunch } from "@/lib/insights/coach-launch-context";
import { groupConversationsByRecency } from "@/lib/insights/coach-conversation-groups";
import { useDebouncedValue } from "@/hooks/use-debounced-value";
import { useAiCapabilityAnswer } from "@/hooks/use-ai-capability";
import { useLoadMoreSentinel } from "@/hooks/use-load-more-sentinel";
@@ -58,58 +58,6 @@ import { cn } from "@/lib/utils";
* wrapper matches the Coach page so the two surfaces share one chrome.
*/
type RecencyGroupId = "today" | "yesterday" | "thisWeek" | "earlier";
interface RecencyGroup {
id: RecencyGroupId;
labelKey: string;
conversations: CoachConversationDTO[];
}
/**
* Bucket conversations by LOCAL calendar recency. `updatedAt` is an ISO
* string; comparisons run against local day boundaries so "Today" tracks
* the user's own midnight, not UTC.
*/
function groupByRecency(conversations: CoachConversationDTO[]): RecencyGroup[] {
const now = new Date();
const startOfToday = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
).getTime();
const startOfYesterday = startOfToday - 24 * 60 * 60 * 1000;
// "This week" = the six days before yesterday (a rolling 7-day window
// that already excludes today + yesterday, which have their own groups).
const startOfWeek = startOfToday - 6 * 24 * 60 * 60 * 1000;
const groups: Record<RecencyGroupId, CoachConversationDTO[]> = {
today: [],
yesterday: [],
thisWeek: [],
earlier: [],
};
for (const conversation of conversations) {
const updated = new Date(conversation.updatedAt).getTime();
if (updated >= startOfToday) groups.today.push(conversation);
else if (updated >= startOfYesterday) groups.yesterday.push(conversation);
else if (updated >= startOfWeek) groups.thisWeek.push(conversation);
else groups.earlier.push(conversation);
}
return (
[
{ id: "today", labelKey: "insights.coach.history.groupToday" },
{ id: "yesterday", labelKey: "insights.coach.history.groupYesterday" },
{ id: "thisWeek", labelKey: "insights.coach.history.groupThisWeek" },
{ id: "earlier", labelKey: "insights.coach.history.groupEarlier" },
] as const
)
.map((g) => ({ ...g, conversations: groups[g.id] }))
.filter((g) => g.conversations.length > 0);
}
function CoachConversationsBody({ readOnly }: { readOnly: boolean }) {
const { t, locale } = useTranslations();
const [openId, setOpenId] = useState<string | null>(null);
@@ -139,7 +87,7 @@ function CoachConversationsBody({ readOnly }: { readOnly: boolean }) {
);
const isSearching = debouncedFilter.trim().length > 0;
const groups = useMemo(() => groupByRecency(visible), [visible]);
const groups = useMemo(() => groupConversationsByRecency(visible), [visible]);
// Same callback-ref pattern as the rail: a `useState` setter (not a plain
// `useRef`) so the sentinel hook's `root` re-fires its effect once the
+23
View File
@@ -81,6 +81,13 @@ import { coachScopeSourceSchema } from "@/lib/ai/coach/types";
* this is a prefill, not an auto-send.
* Both are ignored once `?c=` or `?doc=` pin an existing/scoped thread — scope
* only ever applies to a fresh conversation's first turn.
*
* The conversations panel on the right of the thread carries the history,
* New chat and the settings gear (the composer's `+` menu is gone). Picking a
* conversation or starting a new one rewrites `?c=` in place, so a reload
* stays on the open thread. `?settings=data` (the link from Settings → Coach)
* opens the gear on "What I can see"; the param is consumed on mount and
* dropped from the URL so a reload does not reopen the overlay.
*/
function CoachPageBody() {
const searchParams = useSearchParams();
@@ -118,6 +125,21 @@ function CoachPageBody() {
: null;
const seedPrefill = freshChat ? searchParams.get("ask") : null;
// Read once: the panel consumes it on mount, then the URL loses it.
const [openSettingsOnData] = useState(
() => searchParams.get("settings") === "data",
);
useEffect(() => {
if (!openSettingsOnData) return;
const url = new URL(window.location.href);
url.searchParams.delete("settings");
window.history.replaceState(
window.history.state,
"",
url.pathname + url.search,
);
}, [openSettingsOnData]);
// #781 — a navigation away mid-reply recorded the interrupted conversation
// (see `COACH_INTERRUPTED_STORAGE_KEY` in `use-coach.ts`). Returning to the
// Coach reopens that thread — where the persisted `cancelled` marker shows
@@ -200,6 +222,7 @@ function CoachPageBody() {
// unread coach-initiated exception and the interrupted first-turn
// resume (#781, whose conversation id never reached the client).
autoOpenMostRecent={hasUnreadCoachMessage || resumeInterruptedLatest}
openSettingsOnData={openSettingsOnData}
/>
);
}