feat: 添加会话关闭功能及确认对话框,更新相关国际化文本

This commit is contained in:
catlog22
2026-02-20 20:48:24 +08:00
parent d6bf941113
commit aa9f23782a
8 changed files with 136 additions and 9 deletions

View File

@@ -285,6 +285,13 @@ export const useSessionManagerStore = create<SessionManagerStore>()(
shellKind: session.shellKind,
};
// Map shellKind to preferredShell for API
const mapShellKind = (kind: string): 'bash' | 'pwsh' | 'cmd' => {
if (kind === 'pwsh' || kind === 'powershell') return 'pwsh';
if (kind === 'cmd') return 'cmd';
return 'bash'; // 'git-bash', 'wsl-bash', or fallback
};
try {
// Close existing session
await closeCliSession(terminalId, projectPath ?? undefined);
@@ -293,7 +300,7 @@ export const useSessionManagerStore = create<SessionManagerStore>()(
const result = await createCliSession(
{
workingDir: sessionConfig.workingDir,
preferredShell: sessionConfig.shellKind === 'powershell' ? 'pwsh' : 'bash',
preferredShell: mapShellKind(sessionConfig.shellKind),
tool: sessionConfig.tool,
model: sessionConfig.model,
resumeKey: sessionConfig.resumeKey,
@@ -325,6 +332,35 @@ export const useSessionManagerStore = create<SessionManagerStore>()(
throw error;
}
},
closeSession: async (terminalId: string) => {
const projectPath = selectProjectPath(useWorkflowStore.getState());
const cliStore = useCliSessionStore.getState();
try {
// Call backend API to terminate PTY session
await closeCliSession(terminalId, projectPath ?? undefined);
// Remove session from cliSessionStore
cliStore.removeSession(terminalId);
// Remove terminal meta
set(
(state) => {
const nextMetas = { ...state.terminalMetas };
delete nextMetas[terminalId];
return { terminalMetas: nextMetas };
},
false,
'closeSession'
);
} catch (error) {
if (import.meta.env.DEV) {
console.error('[SessionManager] closeSession error:', error);
}
throw error;
}
},
}),
{ name: 'SessionManagerStore' }
)