Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/web-ui/src/app/components/NavPanel/NavSearchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useMyAgentStore } from '@/app/scenes/my-agent/myAgentStore';
import { useNurseryStore } from '@/app/scenes/profile/nurseryStore';
import { flowChatStore } from '@/flow_chat/store/FlowChatStore';
import { findWorkspaceForSession } from '@/flow_chat/utils/workspaceScope';
import { openMainSession } from '@/flow_chat/services/openBtwSession';
import { openMainSession } from '@/flow_chat/services/sessionActivation';
import type { FlowChatState, Session } from '@/flow_chat/types/flow-chat';
import type { SessionMetadata } from '@/shared/types/session-history';
import type { WorkspaceInfo } from '@/shared/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { createLogger } from '@/shared/utils/logger';
import { useAgentCanvasStore } from '@/app/components/panels/content-canvas/stores';
import {
openBtwSessionInAuxPane,
openMainSession,
selectActiveBtwSessionTab,
} from '@/flow_chat/services/openBtwSession';
} from '@/flow_chat/services/btwSessionPane';
import { openMainSession } from '@/flow_chat/services/sessionActivation';
import {
dispatchHistorySessionOpenIntent,
shouldShowHistorySessionOpenIntent,
Expand All @@ -47,7 +47,6 @@ import type {
BackgroundSubagentActivityItem,
} from '@/flow_chat/utils/backgroundSubagentActivity';
import { computeFixedPopoverPosition } from '@/shared/utils/fixedPopoverViewport';
import { sessionAPI } from '@/infrastructure/api/service-api/SessionAPI';
import { confirmWarning } from '@/component-library/components/ConfirmDialog/confirmService';
import { scheduleAfterStartupPaint, scheduleAfterStartupSignal } from '@/shared/utils/startupTaskScheduling';
import {
Expand Down Expand Up @@ -803,15 +802,13 @@ const SessionsSection: React.FC<SessionsSectionProps> = ({
);
if (!confirmed) return;
try {
await sessionAPI.archiveSession(sessionId, workspacePath || '', remoteConnectionId || undefined, remoteSshHost || undefined);
// Remove from in-memory state only — do NOT delete from disk
flowChatManager.discardLocalSession(sessionId);
await flowChatManager.archiveChatSession(sessionId);
window.dispatchEvent(new CustomEvent('bitfun:session-archived'));
} catch (err) {
log.error('Failed to archive session', err);
}
},
[workspacePath, remoteConnectionId, remoteSshHost, t]
[t]
);

const handleStartEdit = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { workspaceAPI } from '@/infrastructure/api';
import { agentAPI } from '@/infrastructure/api/service-api/AgentAPI';
import { notificationService } from '@/shared/notification-system';
import { flowChatManager } from '@/flow_chat/services/FlowChatManager';
import { openMainSession } from '@/flow_chat/services/openBtwSession';
import { openMainSession } from '@/flow_chat/services/sessionActivation';
import {
getHistorySessionOpenTransitionSnapshot,
subscribeHistorySessionOpenTransition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,10 @@ const WorkspaceSessionBatchModal: React.FC<WorkspaceSessionBatchModalProps> = ({
setActionKind('archive');
try {
const results = await Promise.allSettled(
selectedIds.map(sessionId =>
sessionAPI.archiveSession(
sessionId,
workspacePath,
remoteConnectionId || undefined,
remoteSshHost || undefined
)
)
selectedIds.map(sessionId => flowChatManager.archiveChatSession(sessionId))
);
const successCount = results.filter(result => result.status === 'fulfilled').length;
if (successCount > 0) {
selectedIds.forEach(sessionId => {
flowChatManager.discardLocalSession(sessionId);
});
await refreshWorkspaceSessions();
window.dispatchEvent(new CustomEvent('bitfun:session-archived'));
notificationService.success(t('nav.sessions.archivedAll', { count: successCount }), { duration: 3000 });
Expand All @@ -251,8 +241,6 @@ const WorkspaceSessionBatchModal: React.FC<WorkspaceSessionBatchModalProps> = ({
}, [
loadSessions,
refreshWorkspaceSessions,
remoteConnectionId,
remoteSshHost,
selectedCount,
selectedSessionIds,
t,
Expand All @@ -274,32 +262,23 @@ const WorkspaceSessionBatchModal: React.FC<WorkspaceSessionBatchModalProps> = ({
const deletionPlan = getDeletionPlan(selectedSessionIds, sessions);
setActionKind('delete');
try {
const results = await Promise.allSettled(
deletionPlan.allIds.map(sessionId =>
sessionAPI.deleteSession(
sessionId,
workspacePath,
remoteConnectionId || undefined,
remoteSshHost || undefined
)
)
);
const successIds = new Set<string>();
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
successIds.add(deletionPlan.allIds[index]);
}
});

const removableRootIds = deletionPlan.rootIds.filter(rootId => {
for (const rootId of deletionPlan.rootIds) {
const cascadeIds = getDeletionPlan(new Set([rootId]), sessions).allIds;
return cascadeIds.every(id => successIds.has(id));
});
try {
await flowChatManager.deleteChatSession(rootId);
cascadeIds.forEach(id => successIds.add(id));
} catch (error) {
log.error('Failed to delete selected root session', {
error,
rootSessionId: rootId,
workspacePath,
});
}
}

if (removableRootIds.length > 0) {
removableRootIds.forEach(sessionId => {
flowChatManager.discardLocalSession(sessionId);
});
if (successIds.size > 0) {
await refreshWorkspaceSessions();
notificationService.success(t('nav.sessions.deletedSelected', { count: successIds.size }), { duration: 3000 });
}
Expand All @@ -316,8 +295,6 @@ const WorkspaceSessionBatchModal: React.FC<WorkspaceSessionBatchModalProps> = ({
}, [
loadSessions,
refreshWorkspaceSessions,
remoteConnectionId,
remoteSshHost,
selectedCount,
selectedSessionIds,
sessions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { useCanvasStore } from './stores';
import { useTabLifecycle, useKeyboardShortcuts, usePanelTabCoordinator } from './hooks';
import type { AnchorPosition } from './types';
import { TAB_EVENTS } from './types';
import { openMainSession, selectActiveBtwSessionTab } from '@/flow_chat/services/openBtwSession';
import { selectActiveBtwSessionTab } from '@/flow_chat/services/btwSessionPane';
import { openMainSession } from '@/flow_chat/services/sessionActivation';
import { isSamePath } from '@/shared/utils/pathUtils';
import './ContentCanvas.scss';
export interface ContentCanvasProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { reviewPlatformAPI, systemAPI, type ReviewPlatformAccount, type ReviewPl
import { createLogger } from '@/shared/utils/logger';
import { notificationService } from '@/shared/notification-system';
import { i18nService } from '@/infrastructure/i18n';
import { openMainSession } from '@/flow_chat/services/openBtwSession';
import { openMainSession } from '@/flow_chat/services/sessionActivation';
import { flowChatStore } from '@/flow_chat/store/FlowChatStore';
import type { FlowToolItem, Session } from '@/flow_chat/types/flow-chat';
import { findLatestCodeReviewResult, summarizeCodeReviewResult } from '@/flow_chat/utils/reviewSessionSummary';
Expand Down
9 changes: 6 additions & 3 deletions src/web-ui/src/app/layout/FloatingMiniChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from 'lucide-react';
import { flowChatStore } from '../../flow_chat/store/FlowChatStore';
import { syncSessionToModernStore } from '../../flow_chat/services/storeSync';
import { activateMainSession } from '../../flow_chat/services/sessionActivation';
import { useToolbarModeContext } from '../../flow_chat/components/toolbar-mode/ToolbarModeContext';
import type { FlowChatState } from '../../flow_chat/types/flow-chat';
import { compareSessionsForDisplay } from '../../flow_chat/utils/sessionOrdering';
Expand Down Expand Up @@ -113,9 +114,11 @@ export const FloatingMiniChat: React.FC = () => {
const handleSwitchSession = useCallback((e: React.MouseEvent, sessionId: string) => {
e.stopPropagation();
e.preventDefault();
flowChatStore.switchSession(sessionId);
syncSessionToModernStore(sessionId);
setShowSessionPicker(false);
void activateMainSession(sessionId).then((activated) => {
if (activated) {
setShowSessionPicker(false);
}
});
}, []);

const handleCancel = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useTranslation } from 'react-i18next';
import { IconButton, Textarea } from '@/component-library';
import { ModelSelector } from '@/flow_chat/components/ModelSelector';
import { flowChatManager } from '@/flow_chat/services/FlowChatManager';
import { openMainSession } from '@/flow_chat/services/openBtwSession';
import { openMainSession } from '@/flow_chat/services/sessionActivation';
import { useImeEnterGuard } from '@/flow_chat/hooks/useImeEnterGuard';
import { useWorkspaceContext } from '@/infrastructure/contexts/WorkspaceContext';
import { notificationService } from '@/shared/notification-system';
Expand Down
15 changes: 9 additions & 6 deletions src/web-ui/src/app/services/openAgentCompanionSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import type { Session } from '@/flow_chat/types/flow-chat';
const mocks = vi.hoisted(() => ({
openBtwSessionInAuxPane: vi.fn(),
openMainSession: vi.fn(() => Promise.resolve()),
switchSession: vi.fn(),
activateMainSession: vi.fn(() => Promise.resolve(true)),
sessions: new Map<string, Session>(),
}));

vi.mock('@/flow_chat/services/openBtwSession', () => ({
vi.mock('@/flow_chat/services/btwSessionPane', () => ({
openBtwSessionInAuxPane: (...args: unknown[]) => mocks.openBtwSessionInAuxPane(...args),
}));

vi.mock('@/flow_chat/services/sessionActivation', () => ({
openMainSession: (...args: unknown[]) => mocks.openMainSession(...args),
activateMainSession: (...args: unknown[]) => mocks.activateMainSession(...args),
}));

vi.mock('@/flow_chat/store/FlowChatStore', () => ({
Expand All @@ -20,7 +24,6 @@ vi.mock('@/flow_chat/store/FlowChatStore', () => ({
getState: () => ({
sessions: mocks.sessions,
}),
switchSession: (...args: unknown[]) => mocks.switchSession(...args),
}),
},
}));
Expand All @@ -43,7 +46,7 @@ describe('openAgentCompanionSession', () => {
beforeEach(() => {
mocks.openBtwSessionInAuxPane.mockClear();
mocks.openMainSession.mockClear();
mocks.switchSession.mockClear();
mocks.activateMainSession.mockClear();
mocks.sessions.clear();
});

Expand All @@ -64,7 +67,7 @@ describe('openAgentCompanionSession', () => {
parentSessionId: 'parent-session',
workspacePath: 'D:/workspace/project',
});
expect(mocks.switchSession).not.toHaveBeenCalled();
expect(mocks.activateMainSession).not.toHaveBeenCalled();
});

it('keeps regular sessions on the main chat route', async () => {
Expand All @@ -73,7 +76,7 @@ describe('openAgentCompanionSession', () => {
const opened = await openAgentCompanionSession('session-1');

expect(opened).toBe(true);
expect(mocks.switchSession).toHaveBeenCalledWith('session-1');
expect(mocks.activateMainSession).toHaveBeenCalledWith('session-1');
expect(mocks.openMainSession).not.toHaveBeenCalled();
expect(mocks.openBtwSessionInAuxPane).not.toHaveBeenCalled();
});
Expand Down
6 changes: 3 additions & 3 deletions src/web-ui/src/app/services/openAgentCompanionSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FlowChatStore } from '@/flow_chat/store/FlowChatStore';
import { openBtwSessionInAuxPane, openMainSession } from '@/flow_chat/services/openBtwSession';
import { openBtwSessionInAuxPane } from '@/flow_chat/services/btwSessionPane';
import { activateMainSession, openMainSession } from '@/flow_chat/services/sessionActivation';
import { resolveSessionRelationship } from '@/flow_chat/utils/sessionMetadata';

export async function openAgentCompanionSession(sessionId: string): Promise<boolean> {
Expand All @@ -22,6 +23,5 @@ export async function openAgentCompanionSession(sessionId: string): Promise<bool
return true;
}

flowChatStore.switchSession(sessionId);
return true;
return activateMainSession(sessionId);
}
2 changes: 1 addition & 1 deletion src/web-ui/src/flow_chat/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { createLogger } from '@/shared/utils/logger';
import { Tooltip, IconButton, confirmWarning } from '@/component-library';
import { PendingQueuePanel } from './PendingQueuePanel';
import { useAgentCanvasStore } from '@/app/components/panels/content-canvas/stores';
import { openBtwSessionInAuxPane, selectActiveBtwSessionTab } from '../services/openBtwSession';
import { openBtwSessionInAuxPane, selectActiveBtwSessionTab } from '../services/btwSessionPane';
import { resolveSessionRelationship } from '../utils/sessionMetadata';
import {
DEFAULT_CHAT_INPUT_MODE_CONFIG_PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { parsePullRequestUrl } from '@/shared/utils/pullRequestLinks';
import { createBackgroundCommandOutputTab, createReviewPlatformPullRequestDetailTab } from '@/shared/utils/tabUtils';
import { isAcpFlowSession } from '../../utils/acpSession';
import { flowChatStore } from '../../store/FlowChatStore';
import { openBtwSessionInAuxPane } from '../../services/openBtwSession';
import { openBtwSessionInAuxPane } from '../../services/btwSessionPane';
import { resolveThreadGoalHeaderTitle } from '../../utils/threadGoalDisplay';
import {
findDialogTurn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ vi.mock('../../services/BtwThreadService', () => ({
createBtwChildSession: vi.fn(),
}));

vi.mock('../../services/openBtwSession', () => ({
vi.mock('../../services/btwSessionPane', () => ({
openBtwSessionInAuxPane: vi.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { notificationService } from '../../../shared/notification-system';
import { createLogger } from '@/shared/utils/logger';
import { runWithConcurrencyLimit } from '@/shared/utils/runWithConcurrencyLimit';
import { createBtwChildSession } from '../../services/BtwThreadService';
import { openBtwSessionInAuxPane } from '../../services/openBtwSession';
import { openBtwSessionInAuxPane } from '../../services/btwSessionPane';
import {
buildDeepReviewLaunchFromSessionFiles,
buildDeepReviewPreviewFromSessionFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ vi.mock('../../store/FlowChatStore', () => ({
},
}));

vi.mock('../../services/openBtwSession', () => ({
vi.mock('../../services/btwSessionPane', () => ({
ensureBtwSessionAvailable: (...args: unknown[]) => ensureBtwSessionAvailableMock(...args),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { taskCollapseStateManager } from '../../store/TaskCollapseStateManager';
import { SmoothHeightCollapse } from '../modern/SmoothHeightCollapse';
import { FlowChatStore } from '../../store/FlowChatStore';
import { getSubagentProjectionState } from '../../utils/subagentProjection';
import { ensureBtwSessionAvailable } from '../../services/openBtwSession';
import { ensureBtwSessionAvailable } from '../../services/btwSessionPane';
import './SubagentProjectionView.scss';

interface SubagentProjectionViewProps {
Expand Down
10 changes: 6 additions & 4 deletions src/web-ui/src/flow_chat/components/toolbar-mode/ToolbarMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from 'lucide-react';
import { useToolbarModeContext } from './ToolbarModeContext';
import { flowChatStore } from '../../store/FlowChatStore';
import { syncSessionToModernStore } from '../../services/storeSync';
import { activateMainSession } from '../../services/sessionActivation';
import { FlowChatState } from '../../types/flow-chat';
import { compareSessionsForDisplay } from '../../utils/sessionOrdering';
import { createLogger } from '@/shared/utils/logger';
Expand Down Expand Up @@ -235,9 +235,11 @@ export const ToolbarMode: React.FC = () => {
const handleSwitchSession = useCallback((e: React.MouseEvent, sessionId: string) => {
e.stopPropagation();
e.preventDefault();
flowChatStore.switchSession(sessionId);
syncSessionToModernStore(sessionId);
setShowSessionPicker(false);
void activateMainSession(sessionId).then((activated) => {
if (activated) {
setShowSessionPicker(false);
}
});
}, []);

const handleCancel = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { agentAPI } from '@/infrastructure/api';
import { createLogger } from '@/shared/utils/logger';
import { createBtwChildSession } from '../../services/BtwThreadService';
import { closeBtwSessionInAuxPane, openBtwSessionInAuxPane } from '../../services/openBtwSession';
import { closeBtwSessionInAuxPane, openBtwSessionInAuxPane } from '../../services/btwSessionPane';
import { FlowChatManager } from '../../services/FlowChatManager';
import { flowChatStore } from '../../store/FlowChatStore';
import { insertReviewSessionSummaryMarker } from '../../services/ReviewSessionMarkerService';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ vi.mock('./BtwThreadService', () => ({
createBtwChildSession: (...args: any[]) => mockCreateBtwChildSession(...args),
}));

vi.mock('./openBtwSession', () => ({
vi.mock('./btwSessionPane', () => ({
closeBtwSessionInAuxPane: (...args: any[]) => mockCloseBtwSessionInAuxPane(...args),
openBtwSessionInAuxPane: (...args: any[]) => mockOpenBtwSessionInAuxPane(...args),
}));
Expand Down
Loading
Loading