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

Function initializeFlowChat

src/web-ui/src/app/layout/AppLayout.tsx:291–400  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

289 React.useEffect(() => {
290 let cancelled = false;
291 const initializeFlowChat = async () => {
292 if (!currentWorkspace?.rootPath) return;
293
294 // Remote session index and turns live under ~/.bitfun/remote_ssh/... (local disk).
295 // Always initialize FlowChat so historical sessions list even when SSH is not connected yet.
296 try {
297 const explicitPreferredMode =
298 sessionStorage.getItem('bitfun:flowchat:preferredMode') ||
299 undefined;
300 if (explicitPreferredMode) {
301 sessionStorage.removeItem('bitfun:flowchat:preferredMode');
302 }
303
304 const initializationPreferredMode =
305 currentWorkspace.workspaceKind === WorkspaceKind.Assistant
306 ? 'Claw'
307 : explicitPreferredMode;
308
309 const flowChatManager = FlowChatManager.getInstance();
310 const hasHistoricalSessions = await flowChatManager.initialize(
311 currentWorkspace.rootPath,
312 initializationPreferredMode,
313 currentWorkspace.workspaceKind === WorkspaceKind.Remote
314 ? currentWorkspace.connectionId
315 : undefined,
316 currentWorkspace.workspaceKind === WorkspaceKind.Remote
317 ? currentWorkspace.sshHost
318 : undefined
319 );
320 if (cancelled) {
321 return;
322 }
323
324 let sessionId: string | undefined;
325 const { flowChatStore } = await import('@/flow_chat/store/FlowChatStore');
326 if (cancelled) {
327 return;
328 }
329 if (!hasHistoricalSessions) {
330 const initialSessionMode =
331 currentWorkspace.workspaceKind === WorkspaceKind.Assistant
332 ? 'Claw'
333 : explicitPreferredMode || 'agentic';
334 sessionId = await flowChatManager.createChatSession({}, initialSessionMode);
335 if (cancelled) {
336 return;
337 }
338 }
339
340 const activeSessionId = sessionId || flowChatStore.getState().activeSessionId;
341 if (currentWorkspace.workspaceKind === WorkspaceKind.Assistant && activeSessionId) {
342 ensureAssistantBootstrapForWorkspace(currentWorkspace, activeSessionId);
343 }
344
345 const pendingDescription = sessionStorage.getItem('pendingProjectDescription');
346 if (pendingDescription && pendingDescription.trim()) {
347 sessionStorage.removeItem('pendingProjectDescription');
348

Callers 1

AppLayoutFunction · 0.85

Calls 9

trimMethod · 0.80
createChatSessionMethod · 0.65
getStateMethod · 0.65
sendMessageMethod · 0.65
tFunction · 0.50
getInstanceMethod · 0.45
initializeMethod · 0.45
errorMethod · 0.45
successMethod · 0.45

Tested by

no test coverage detected