mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 07:21:00 +08:00
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>
55 lines
1.4 KiB
TypeScript
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,
|
|
]);
|
|
}
|