Files
DeepTutor/web/features/chat/controllers/useChatRouteSession.ts
Bingxi Zhao (Frank) 6e6e56aedb release: v1.6.3
Ship the breaking front- and back-end runtime and route refactor,
learner and guardian flows, grounded reading, knowledge and parser
updates, and recoverable long-running streams.

Release notes: assets/releases/ver1-6-3.md
2026-09-02 04:09:11 +08:00

34 lines
871 B
TypeScript

"use client";
import { useParams, useRouter } from "next/navigation";
import { useMemo } from "react";
export function routeSessionId(value: string | undefined): string | null {
const normalized = value?.trim() ?? "";
return normalized || null;
}
export function shouldRevalidateCachedSession(input: {
routeSessionId: string | null;
selectedSessionId: string | null;
hasCachedMessages: boolean;
isStreaming: boolean;
}): boolean {
return Boolean(
input.routeSessionId &&
input.hasCachedMessages &&
!input.isStreaming &&
input.routeSessionId === input.selectedSessionId,
);
}
export function useChatRouteSession() {
const params = useParams<{ sessionId?: string }>();
const router = useRouter();
const sessionId = useMemo(
() => routeSessionId(params.sessionId),
[params.sessionId],
);
return { router, sessionId };
}