mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 05:09:51 +08:00
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
34 lines
871 B
TypeScript
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 };
|
|
}
|