MCPcopy Create free account
hub / github.com/GCWing/BitFun / useAssistantBootstrap

Function useAssistantBootstrap

src/web-ui/src/app/hooks/useAssistantBootstrap.ts:22–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22export function useAssistantBootstrap() {
23 const { t } = useI18n('notifications');
24 const activeAttemptRef = useRef<ActiveBootstrapAttempt | null>(null);
25 const pendingRequestRef = useRef<BootstrapRequest | null>(null);
26 const latestWorkspacePathRef = useRef<string | null>(null);
27 const inFlightWorkspacePathRef = useRef<string | null>(null);
28 const blockedNoticeShownRef = useRef<Set<string>>(new Set());
29 const requestBootstrapRef = useRef<(request: BootstrapRequest) => void>(() => {});
30
31 const drainPendingRequest = useCallback(() => {
32 const pending = pendingRequestRef.current;
33 if (!pending) {
34 return;
35 }
36
37 if (latestWorkspacePathRef.current !== pending.workspacePath) {
38 pendingRequestRef.current = null;
39 return;
40 }
41
42 pendingRequestRef.current = null;
43 requestBootstrapRef.current(pending);
44 }, []);
45
46 const clearActiveAttempt = useCallback(
47 (event: { sessionId?: string; turnId?: string }) => {
48 const activeAttempt = activeAttemptRef.current;
49 if (!activeAttempt) {
50 return;
51 }
52
53 if (event.sessionId !== activeAttempt.sessionId || event.turnId !== activeAttempt.turnId) {
54 return;
55 }
56
57 activeAttemptRef.current = null;
58 drainPendingRequest();
59 },
60 [drainPendingRequest]
61 );
62
63 useEffect(() => {
64 const unlistenCompleted = agentAPI.onDialogTurnCompleted(clearActiveAttempt);
65 const unlistenFailed = agentAPI.onDialogTurnFailed(clearActiveAttempt);
66 const unlistenCancelled = agentAPI.onDialogTurnCancelled(clearActiveAttempt);
67
68 return () => {
69 unlistenCompleted();
70 unlistenFailed();
71 unlistenCancelled();
72 };
73 }, [clearActiveAttempt]);
74
75 const handleEnsureResponse = useCallback(
76 (request: BootstrapRequest, response: EnsureAssistantBootstrapResponse): void => {
77 switch (response.status) {
78 case 'started':
79 if (!response.turnId) {

Callers 1

AppLayoutFunction · 0.90

Calls 15

useI18nFunction · 0.90
unlistenCompletedFunction · 0.85
unlistenFailedFunction · 0.85
onDialogTurnCompletedMethod · 0.80
onDialogTurnFailedMethod · 0.80
onDialogTurnCancelledMethod · 0.80
warnMethod · 0.80
debugMethod · 0.80
tFunction · 0.70
currentMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected