Files
DeepTutor/web/hooks/useMasteryOpening.ts
Bingxi Zhao (Frank) c547a5a31c fix: resolve verified learning, ingestion and delivery regressions
Bind mastery drafts before their opening turn and preserve stored session modes.
Track chat duration from submission through terminal completion. Run async reading
extensions on their event loop and allow retries after cancellable timeouts.
Allow first uploads into empty LlamaIndex knowledge bases, preserve Telegram
thread routing, parse embedding Retry-After dates, and enforce robots rules and
host pacing during documentation crawls, including redirects.

Fixes #1461
Fixes #1458
Fixes #1451
Fixes #1448
Fixes #1392
Fixes #1429
Refs #1435, #1412

Reuses contributions from PRs #1462, #1452 and #1403.

Co-authored-by: sjagadee <srini.jagadeesh@gmail.com>
Co-authored-by: AoHanBei <dongaohan21@gmail.com>
Co-authored-by: Gao-Chenkai <DevChenkai@outlook.com>
2026-09-15 20:06:57 +08:00

55 lines
1.4 KiB
TypeScript

"use client";
import { useEffect, useRef } from "react";
import { useTranslation } from "react-i18next";
import { consumePendingPrompt } from "@/lib/pending-prompt";
import {
MASTERY_OPENING_SCOPE,
masteryOpeningMessage,
type MasteryMode,
} from "@/lib/mastery-mode";
/** Keep the opening pending until the route's session can accept a turn. */
export function useMasteryOpening({
pathId,
topicReady,
hasMessages,
sessionLoading,
sessionError,
sessionMode,
isStreaming,
submit,
}: {
pathId: string;
topicReady: boolean;
hasMessages: boolean;
sessionLoading: boolean;
sessionError: string | null;
sessionMode: MasteryMode;
isStreaming: boolean;
submit: (content: string) => boolean;
}) {
const { t } = useTranslation();
const openingSentRef = useRef("");
useEffect(() => {
if (!topicReady || hasMessages || sessionLoading || sessionError)
return;
if (isStreaming || openingSentRef.current === pathId) return;
const opening =
consumePendingPrompt(MASTERY_OPENING_SCOPE).trim() ||
masteryOpeningMessage(sessionMode, t);
// Study mode has no automatic opening. Latch only after submitting.
if (opening && submit(opening)) openingSentRef.current = pathId;
}, [
hasMessages,
pathId,
sessionError,
sessionLoading,
sessionMode,
isStreaming,
submit,
t,
topicReady,
]);
}