返回 DeepSeek-Reasonix
useSessionComposerLifecycle.ts
根目录 / desktop / frontend / src / app-runtime / useSessionComposerLifecycle.ts
1 import { useEffect } from "react";
2
3 declare global {
4 interface Window {
5 __reasonixFlushSessionDraft?: () => Promise<void>;
6 __reasonixResumeSessionDraftEditing?: () => void;
7 }
8 }
9
10 /** The shell's historical callback names now belong only to formal input. */
11 export function useSessionComposerLifecycle() {
12 useEffect(() => {
13 const flush = async () => {
14 const input = await import("../lib/sessionComposerPersistence");
15 try {
16 await input.flushAllSessionComposers();
17 } catch (error) {
18 input.resumeSessionComposerEditing();
19 throw error;
20 }
21 };
22 const resume = () => {
23 void import("../lib/sessionComposerPersistence").then(input => input.resumeSessionComposerEditing());
24 };
25 window.__reasonixFlushSessionDraft = flush;
26 window.__reasonixResumeSessionDraftEditing = resume;
27 return () => {
28 if (window.__reasonixFlushSessionDraft === flush) delete window.__reasonixFlushSessionDraft;
29 if (window.__reasonixResumeSessionDraftEditing === resume) delete window.__reasonixResumeSessionDraftEditing;
30 };
31 }, []);
32 }
33
33 lines TYPESCRIPT