diff --git a/.gitignore b/.gitignore index b17bc1754..a8107fa93 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,8 @@ local .qwen/* .trae/* .claude-code-router/* +.codebuddy/* +.zed/* CLAUDE.local.md # vitest diff --git a/electron-builder.yml b/electron-builder.yml index 6b7056ed3..8fd4b6a6f 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -125,16 +125,20 @@ afterSign: scripts/notarize.js artifactBuildCompleted: scripts/artifact-build-completed.js releaseInfo: releaseNotes: | + ✨ 新功能: + - 支持在对话中显示 AI 生成的图片 + - 代码编辑工具支持更多终端类型 + - 新增 Azure AI 服务支持 + - 新增通义千问 Plus 模型 + 🐛 问题修复: - - 修复 Anthropic API URL 处理,移除尾部斜杠并添加端点路径处理 - - 修复 MessageEditor 缺少 QuickPanelProvider 包装的问题 - - 修复 MiniWindow 高度问题 + - 修复翻译功能中选中文本未正确使用的问题 + - 修复文件管理中空格键误删文件的问题 + - 修复部分 AI 服务连接不稳定的问题 + - 修复翻译页面长文本显示异常 + - 优化列表显示样式 🚀 性能优化: - - 优化输入栏提及模型状态缓存,在渲染间保持状态 - - 重构网络搜索参数支持模型内置搜索,新增 OpenAI Chat 和 OpenRouter 支持 - - 🔧 重构改进: - - 更新 HeroUIProvider 导入路径,改善上下文管理 - - 更新依赖项和 VSCode 开发环境配置 - - 升级 @cherrystudio/ai-core 到 v1.0.0-alpha.17 + - 提升输入框响应速度 + - 优化模型切换性能 + - 改进翻译功能的引用和邮件格式处理 diff --git a/eslint.config.mjs b/eslint.config.mjs index 8eda2e6fa..f9e6c0750 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -48,6 +48,27 @@ export default defineConfig([ '@eslint-react/no-children-to-array': 'off' } }, + { + ignores: [ + 'node_modules/**', + 'build/**', + 'dist/**', + 'out/**', + 'local/**', + '.yarn/**', + '.gitignore', + 'scripts/cloudflare-worker.js', + 'src/main/integration/nutstore/sso/lib/**', + 'src/main/integration/cherryin/index.js', + 'src/main/integration/nutstore/sso/lib/**', + 'src/renderer/src/ui/**', + 'packages/**/dist' + ] + }, + // turn off oxlint supported rules. + ...oxlint.configs['flat/eslint'], + ...oxlint.configs['flat/typescript'], + ...oxlint.configs['flat/unicorn'], { // LoggerService Custom Rules - only apply to src directory files: ['src/**/*.{ts,tsx,js,jsx}'], @@ -110,25 +131,4 @@ export default defineConfig([ 'i18n/no-template-in-t': 'warn' } }, - { - ignores: [ - 'node_modules/**', - 'build/**', - 'dist/**', - 'out/**', - 'local/**', - '.yarn/**', - '.gitignore', - 'scripts/cloudflare-worker.js', - 'src/main/integration/nutstore/sso/lib/**', - 'src/main/integration/cherryin/index.js', - 'src/main/integration/nutstore/sso/lib/**', - 'src/renderer/src/ui/**', - 'packages/**/dist' - ] - }, - // turn off oxlint supported rules. - ...oxlint.configs['flat/eslint'], - ...oxlint.configs['flat/typescript'], - ...oxlint.configs['flat/unicorn'] ]) diff --git a/package.json b/package.json index d2eee548c..e5486419e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "CherryStudio", - "version": "1.6.0-rc.2", + "version": "1.6.0-rc.3", "private": true, "description": "A powerful AI assistant for producer.", "main": "./out/main/index.js", diff --git a/packages/shared/IpcChannel.ts b/packages/shared/IpcChannel.ts index ecfc9b967..e3ee5edf2 100644 --- a/packages/shared/IpcChannel.ts +++ b/packages/shared/IpcChannel.ts @@ -324,6 +324,10 @@ export enum IpcChannel { // CodeTools CodeTools_Run = 'code-tools:run', + CodeTools_GetAvailableTerminals = 'code-tools:get-available-terminals', + CodeTools_SetCustomTerminalPath = 'code-tools:set-custom-terminal-path', + CodeTools_GetCustomTerminalPath = 'code-tools:get-custom-terminal-path', + CodeTools_RemoveCustomTerminalPath = 'code-tools:remove-custom-terminal-path', // OCR OCR_ocr = 'ocr:ocr', diff --git a/packages/shared/config/constant.ts b/packages/shared/config/constant.ts index 3dc2a45a6..9ce35e3a5 100644 --- a/packages/shared/config/constant.ts +++ b/packages/shared/config/constant.ts @@ -219,3 +219,242 @@ export enum codeTools { openaiCodex = 'openai-codex', iFlowCli = 'iflow-cli' } + +export enum terminalApps { + systemDefault = 'Terminal', + iterm2 = 'iTerm2', + kitty = 'kitty', + alacritty = 'Alacritty', + wezterm = 'WezTerm', + ghostty = 'Ghostty', + tabby = 'Tabby', + // Windows terminals + windowsTerminal = 'WindowsTerminal', + powershell = 'PowerShell', + cmd = 'CMD', + wsl = 'WSL' +} + +export interface TerminalConfig { + id: string + name: string + bundleId?: string + customPath?: string // For user-configured terminal paths on Windows +} + +export interface TerminalConfigWithCommand extends TerminalConfig { + command: (directory: string, fullCommand: string) => { command: string; args: string[] } +} + +export const MACOS_TERMINALS: TerminalConfig[] = [ + { + id: terminalApps.systemDefault, + name: 'Terminal', + bundleId: 'com.apple.Terminal' + }, + { + id: terminalApps.iterm2, + name: 'iTerm2', + bundleId: 'com.googlecode.iterm2' + }, + { + id: terminalApps.kitty, + name: 'kitty', + bundleId: 'net.kovidgoyal.kitty' + }, + { + id: terminalApps.alacritty, + name: 'Alacritty', + bundleId: 'org.alacritty' + }, + { + id: terminalApps.wezterm, + name: 'WezTerm', + bundleId: 'com.github.wez.wezterm' + }, + { + id: terminalApps.ghostty, + name: 'Ghostty', + bundleId: 'com.mitchellh.ghostty' + }, + { + id: terminalApps.tabby, + name: 'Tabby', + bundleId: 'org.tabby' + } +] + +export const WINDOWS_TERMINALS: TerminalConfig[] = [ + { + id: terminalApps.cmd, + name: 'Command Prompt' + }, + { + id: terminalApps.powershell, + name: 'PowerShell' + }, + { + id: terminalApps.windowsTerminal, + name: 'Windows Terminal' + }, + { + id: terminalApps.wsl, + name: 'WSL (Ubuntu/Debian)' + }, + { + id: terminalApps.alacritty, + name: 'Alacritty' + }, + { + id: terminalApps.wezterm, + name: 'WezTerm' + } +] + +export const WINDOWS_TERMINALS_WITH_COMMANDS: TerminalConfigWithCommand[] = [ + { + id: terminalApps.cmd, + name: 'Command Prompt', + command: (_: string, fullCommand: string) => ({ + command: 'cmd', + args: ['/c', 'start', 'cmd', '/k', fullCommand] + }) + }, + { + id: terminalApps.powershell, + name: 'PowerShell', + command: (_: string, fullCommand: string) => ({ + command: 'cmd', + args: ['/c', 'start', 'powershell', '-NoExit', '-Command', `& '${fullCommand}'`] + }) + }, + { + id: terminalApps.windowsTerminal, + name: 'Windows Terminal', + command: (_: string, fullCommand: string) => ({ + command: 'wt', + args: ['cmd', '/k', fullCommand] + }) + }, + { + id: terminalApps.wsl, + name: 'WSL (Ubuntu/Debian)', + command: (_: string, fullCommand: string) => { + // Start WSL in a new window and execute the batch file from within WSL using cmd.exe + // The batch file will run in Windows context but output will be in WSL terminal + return { + command: 'cmd', + args: ['/c', 'start', 'wsl', '-e', 'bash', '-c', `cmd.exe /c '${fullCommand}' ; exec bash`] + } + } + }, + { + id: terminalApps.alacritty, + name: 'Alacritty', + customPath: '', // Will be set by user in settings + command: (_: string, fullCommand: string) => ({ + command: 'alacritty', // Will be replaced with customPath if set + args: ['-e', 'cmd', '/k', fullCommand] + }) + }, + { + id: terminalApps.wezterm, + name: 'WezTerm', + customPath: '', // Will be set by user in settings + command: (_: string, fullCommand: string) => ({ + command: 'wezterm', // Will be replaced with customPath if set + args: ['start', 'cmd', '/k', fullCommand] + }) + } +] + +export const MACOS_TERMINALS_WITH_COMMANDS: TerminalConfigWithCommand[] = [ + { + id: terminalApps.systemDefault, + name: 'Terminal', + bundleId: 'com.apple.Terminal', + command: (directory: string, fullCommand: string) => ({ + command: 'sh', + args: [ + '-c', + `open -na Terminal && sleep 0.5 && osascript -e 'tell application "Terminal" to activate' -e 'tell application "Terminal" to do script "cd '${directory.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}' && clear && ${fullCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}" in front window'` + ] + }) + }, + { + id: terminalApps.iterm2, + name: 'iTerm2', + bundleId: 'com.googlecode.iterm2', + command: (directory: string, fullCommand: string) => ({ + command: 'sh', + args: [ + '-c', + `open -na iTerm && sleep 0.8 && osascript -e 'on waitUntilRunning()\n repeat 50 times\n tell application "System Events"\n if (exists process "iTerm2") then exit repeat\n end tell\n delay 0.1\n end repeat\nend waitUntilRunning\n\nwaitUntilRunning()\n\ntell application "iTerm2"\n if (count of windows) = 0 then\n create window with default profile\n delay 0.3\n else\n tell current window\n create tab with default profile\n end tell\n delay 0.3\n end if\n tell current session of current window to write text "cd '${directory.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}' && clear && ${fullCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"\n activate\nend tell'` + ] + }) + }, + { + id: terminalApps.kitty, + name: 'kitty', + bundleId: 'net.kovidgoyal.kitty', + command: (directory: string, fullCommand: string) => ({ + command: 'sh', + args: [ + '-c', + `cd "${directory}" && open -na kitty --args --directory="${directory}" sh -c "${fullCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}; exec \\$SHELL" && sleep 0.5 && osascript -e 'tell application "kitty" to activate'` + ] + }) + }, + { + id: terminalApps.alacritty, + name: 'Alacritty', + bundleId: 'org.alacritty', + command: (directory: string, fullCommand: string) => ({ + command: 'sh', + args: [ + '-c', + `open -na Alacritty --args --working-directory "${directory}" -e sh -c "${fullCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}; exec \\$SHELL" && sleep 0.5 && osascript -e 'tell application "Alacritty" to activate'` + ] + }) + }, + { + id: terminalApps.wezterm, + name: 'WezTerm', + bundleId: 'com.github.wez.wezterm', + command: (directory: string, fullCommand: string) => ({ + command: 'sh', + args: [ + '-c', + `open -na WezTerm --args start --new-tab --cwd "${directory}" -- sh -c "${fullCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}; exec \\$SHELL" && sleep 0.5 && osascript -e 'tell application "WezTerm" to activate'` + ] + }) + }, + { + id: terminalApps.ghostty, + name: 'Ghostty', + bundleId: 'com.mitchellh.ghostty', + command: (directory: string, fullCommand: string) => ({ + command: 'sh', + args: [ + '-c', + `cd "${directory}" && open -na Ghostty --args --working-directory="${directory}" -e sh -c "${fullCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}; exec \\$SHELL" && sleep 0.5 && osascript -e 'tell application "Ghostty" to activate'` + ] + }) + }, + { + id: terminalApps.tabby, + name: 'Tabby', + bundleId: 'org.tabby', + command: (directory: string, fullCommand: string) => ({ + command: 'sh', + args: [ + '-c', + `if pgrep -x "Tabby" > /dev/null; then + open -na Tabby --args open && sleep 0.3 + else + open -na Tabby --args open && sleep 2 + fi && osascript -e 'tell application "Tabby" to activate' -e 'set the clipboard to "cd \\"${directory.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}\\" && clear && ${fullCommand.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"' -e 'tell application "System Events" to tell process "Tabby" to keystroke "v" using {command down}' -e 'tell application "System Events" to key code 36'` + ] + }) + } +] diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 30a02f8bd..b770e7def 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -834,6 +834,16 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) { // CodeTools ipcMain.handle(IpcChannel.CodeTools_Run, codeToolsService.run) + ipcMain.handle(IpcChannel.CodeTools_GetAvailableTerminals, () => codeToolsService.getAvailableTerminalsForPlatform()) + ipcMain.handle(IpcChannel.CodeTools_SetCustomTerminalPath, (_, terminalId: string, path: string) => + codeToolsService.setCustomTerminalPath(terminalId, path) + ) + ipcMain.handle(IpcChannel.CodeTools_GetCustomTerminalPath, (_, terminalId: string) => + codeToolsService.getCustomTerminalPath(terminalId) + ) + ipcMain.handle(IpcChannel.CodeTools_RemoveCustomTerminalPath, (_, terminalId: string) => + codeToolsService.removeCustomTerminalPath(terminalId) + ) // OCR ipcMain.handle(IpcChannel.OCR_ocr, (_, file: SupportedOcrFile, provider: OcrProvider) => diff --git a/src/main/services/CodeToolsService.ts b/src/main/services/CodeToolsService.ts index 1372bf1f8..74fca367f 100644 --- a/src/main/services/CodeToolsService.ts +++ b/src/main/services/CodeToolsService.ts @@ -3,11 +3,20 @@ import os from 'node:os' import path from 'node:path' import { loggerService } from '@logger' -import { isWin } from '@main/constant' +import { isMac, isWin } from '@main/constant' import { removeEnvProxy } from '@main/utils' import { isUserInChina } from '@main/utils/ipService' import { getBinaryName } from '@main/utils/process' -import { codeTools } from '@shared/config/constant' +import { + codeTools, + MACOS_TERMINALS, + MACOS_TERMINALS_WITH_COMMANDS, + terminalApps, + TerminalConfig, + TerminalConfigWithCommand, + WINDOWS_TERMINALS, + WINDOWS_TERMINALS_WITH_COMMANDS +} from '@shared/config/constant' import { spawn } from 'child_process' import { promisify } from 'util' @@ -22,7 +31,10 @@ interface VersionInfo { class CodeToolsService { private versionCache: Map = new Map() + private terminalsCache: { terminals: TerminalConfig[]; timestamp: number } | null = null + private customTerminalPaths: Map = new Map() // Store user-configured terminal paths private readonly CACHE_DURATION = 1000 * 60 * 30 // 30 minutes cache + private readonly TERMINALS_CACHE_DURATION = 1000 * 60 * 5 // 5 minutes cache for terminals constructor() { this.getBunPath = this.getBunPath.bind(this) @@ -32,6 +44,23 @@ class CodeToolsService { this.getVersionInfo = this.getVersionInfo.bind(this) this.updatePackage = this.updatePackage.bind(this) this.run = this.run.bind(this) + + if (isMac || isWin) { + this.preloadTerminals() + } + } + + /** + * Preload available terminals in background + */ + private async preloadTerminals(): Promise { + try { + logger.info('Preloading available terminals...') + await this.getAvailableTerminals() + logger.info('Terminal preloading completed') + } catch (error) { + logger.warn('Terminal preloading failed:', error as Error) + } } public async getBunPath() { @@ -75,10 +104,258 @@ class CodeToolsService { } } + /** + * Check if a single terminal is available + */ + private async checkTerminalAvailability(terminal: TerminalConfig): Promise { + try { + if (isMac && terminal.bundleId) { + // macOS: Check if application is installed via bundle ID with timeout + const { stdout } = await execAsync(`mdfind "kMDItemCFBundleIdentifier == '${terminal.bundleId}'"`, { + timeout: 3000 + }) + if (stdout.trim()) { + return terminal + } + } else if (isWin) { + // Windows: Check terminal availability + return await this.checkWindowsTerminalAvailability(terminal) + } else { + // TODO: Check if terminal is available in linux + await execAsync(`which ${terminal.id}`, { timeout: 2000 }) + return terminal + } + } catch (error) { + logger.debug(`Terminal ${terminal.id} not available:`, error as Error) + } + return null + } + + /** + * Check Windows terminal availability (simplified - user configured paths) + */ + private async checkWindowsTerminalAvailability(terminal: TerminalConfig): Promise { + try { + switch (terminal.id) { + case terminalApps.cmd: + // CMD is always available on Windows + return terminal + + case terminalApps.powershell: + // Check for PowerShell in PATH + try { + await execAsync('powershell -Command "Get-Host"', { timeout: 3000 }) + return terminal + } catch { + try { + await execAsync('pwsh -Command "Get-Host"', { timeout: 3000 }) + return terminal + } catch { + return null + } + } + + case terminalApps.windowsTerminal: + // Check for Windows Terminal via where command (doesn't launch the terminal) + try { + await execAsync('where wt', { timeout: 3000 }) + return terminal + } catch { + return null + } + + case terminalApps.wsl: + // Check for WSL + try { + await execAsync('wsl --status', { timeout: 3000 }) + return terminal + } catch { + return null + } + + default: + // For other terminals (Alacritty, WezTerm), check if user has configured custom path + return await this.checkCustomTerminalPath(terminal) + } + } catch (error) { + logger.debug(`Windows terminal ${terminal.id} not available:`, error as Error) + return null + } + } + + /** + * Check if user has configured custom path for terminal + */ + private async checkCustomTerminalPath(terminal: TerminalConfig): Promise { + // Check if user has configured custom path + const customPath = this.customTerminalPaths.get(terminal.id) + if (customPath && fs.existsSync(customPath)) { + try { + await execAsync(`"${customPath}" --version`, { timeout: 3000 }) + return { ...terminal, customPath } + } catch { + return null + } + } + + // Fallback to PATH check + try { + const command = terminal.id === terminalApps.alacritty ? 'alacritty' : 'wezterm' + await execAsync(`${command} --version`, { timeout: 3000 }) + return terminal + } catch { + return null + } + } + + /** + * Set custom path for a terminal (called from settings UI) + */ + public setCustomTerminalPath(terminalId: string, path: string): void { + logger.info(`Setting custom path for terminal ${terminalId}: ${path}`) + this.customTerminalPaths.set(terminalId, path) + // Clear terminals cache to force refresh + this.terminalsCache = null + } + + /** + * Get custom path for a terminal + */ + public getCustomTerminalPath(terminalId: string): string | undefined { + return this.customTerminalPaths.get(terminalId) + } + + /** + * Remove custom path for a terminal + */ + public removeCustomTerminalPath(terminalId: string): void { + logger.info(`Removing custom path for terminal ${terminalId}`) + this.customTerminalPaths.delete(terminalId) + // Clear terminals cache to force refresh + this.terminalsCache = null + } + + /** + * Get available terminals (with caching and parallel checking) + */ + private async getAvailableTerminals(): Promise { + const now = Date.now() + + // Check cache first + if (this.terminalsCache && now - this.terminalsCache.timestamp < this.TERMINALS_CACHE_DURATION) { + logger.info(`Using cached terminals list (${this.terminalsCache.terminals.length} terminals)`) + return this.terminalsCache.terminals + } + + logger.info('Checking available terminals in parallel...') + const startTime = Date.now() + + // Get terminal list based on platform + const terminalList = isWin ? WINDOWS_TERMINALS : MACOS_TERMINALS + + // Check all terminals in parallel + const terminalPromises = terminalList.map((terminal) => this.checkTerminalAvailability(terminal)) + + try { + // Wait for all checks to complete with a global timeout + const results = await Promise.allSettled( + terminalPromises.map((p) => + Promise.race([p, new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 5000))]) + ) + ) + + const availableTerminals: TerminalConfig[] = [] + results.forEach((result, index) => { + if (result.status === 'fulfilled' && result.value) { + availableTerminals.push(result.value as TerminalConfig) + } else if (result.status === 'rejected') { + logger.debug(`Terminal check failed for ${MACOS_TERMINALS[index].id}:`, result.reason) + } + }) + + const endTime = Date.now() + logger.info( + `Terminal availability check completed in ${endTime - startTime}ms, found ${availableTerminals.length} terminals` + ) + + // Cache the results + this.terminalsCache = { + terminals: availableTerminals, + timestamp: now + } + + return availableTerminals + } catch (error) { + logger.error('Error checking terminal availability:', error as Error) + // Return cached result if available, otherwise empty array + return this.terminalsCache?.terminals || [] + } + } + + /** + * Get terminal config by ID, fallback to system default + */ + private async getTerminalConfig(terminalId?: string): Promise { + const availableTerminals = await this.getAvailableTerminals() + const terminalCommands = isWin ? WINDOWS_TERMINALS_WITH_COMMANDS : MACOS_TERMINALS_WITH_COMMANDS + const defaultTerminal = isWin ? terminalApps.cmd : terminalApps.systemDefault + + if (terminalId) { + let requestedTerminal = terminalCommands.find( + (t) => t.id === terminalId && availableTerminals.some((at) => at.id === t.id) + ) + + if (requestedTerminal) { + // Apply custom path if configured + const customPath = this.customTerminalPaths.get(terminalId) + if (customPath && isWin) { + requestedTerminal = this.applyCustomPath(requestedTerminal, customPath) + } + return requestedTerminal + } else { + logger.warn(`Requested terminal ${terminalId} not available, falling back to system default`) + } + } + + // Fallback to system default Terminal + const systemTerminal = terminalCommands.find( + (t) => t.id === defaultTerminal && availableTerminals.some((at) => at.id === t.id) + ) + if (systemTerminal) { + return systemTerminal + } + + // If even system Terminal is not found, return the first available + const firstAvailable = terminalCommands.find((t) => availableTerminals.some((at) => at.id === t.id)) + if (firstAvailable) { + return firstAvailable + } + + // Last resort fallback + return terminalCommands.find((t) => t.id === defaultTerminal)! + } + + /** + * Apply custom path to terminal configuration + */ + private applyCustomPath(terminal: TerminalConfigWithCommand, customPath: string): TerminalConfigWithCommand { + return { + ...terminal, + customPath, + command: (directory: string, fullCommand: string) => { + const originalCommand = terminal.command(directory, fullCommand) + return { + ...originalCommand, + command: customPath // Replace command with custom path + } + } + } + } + private async isPackageInstalled(cliTool: string): Promise { const executableName = await this.getCliExecutableName(cliTool) const binDir = path.join(os.homedir(), '.cherrystudio', 'bin') - const executablePath = path.join(binDir, executableName + (process.platform === 'win32' ? '.exe' : '')) + const executablePath = path.join(binDir, executableName + (isWin ? '.exe' : '')) // Ensure bin directory exists if (!fs.existsSync(binDir)) { @@ -105,7 +382,7 @@ class CodeToolsService { try { const executableName = await this.getCliExecutableName(cliTool) const binDir = path.join(os.homedir(), '.cherrystudio', 'bin') - const executablePath = path.join(binDir, executableName + (process.platform === 'win32' ? '.exe' : '')) + const executablePath = path.join(binDir, executableName + (isWin ? '.exe' : '')) const { stdout } = await execAsync(`"${executablePath}" --version`, { timeout: 10000 }) // Extract version number from output (format may vary by tool) @@ -191,6 +468,17 @@ class CodeToolsService { } } + /** + * Get available terminals for the current platform + */ + public async getAvailableTerminalsForPlatform(): Promise { + if (isMac || isWin) { + return this.getAvailableTerminals() + } + // For other platforms, return empty array for now + return [] + } + /** * Update a CLI tool to the latest version */ @@ -202,10 +490,9 @@ class CodeToolsService { const bunInstallPath = path.join(os.homedir(), '.cherrystudio') const registryUrl = await this.getNpmRegistryUrl() - const installEnvPrefix = - process.platform === 'win32' - ? `set "BUN_INSTALL=${bunInstallPath}" && set "NPM_CONFIG_REGISTRY=${registryUrl}" &&` - : `export BUN_INSTALL="${bunInstallPath}" && export NPM_CONFIG_REGISTRY="${registryUrl}" &&` + const installEnvPrefix = isWin + ? `set "BUN_INSTALL=${bunInstallPath}" && set "NPM_CONFIG_REGISTRY=${registryUrl}" &&` + : `export BUN_INSTALL="${bunInstallPath}" && export NPM_CONFIG_REGISTRY="${registryUrl}" &&` const updateCommand = `${installEnvPrefix} "${bunPath}" install -g ${packageName}` logger.info(`Executing update command: ${updateCommand}`) @@ -241,7 +528,7 @@ class CodeToolsService { _model: string, directory: string, env: Record, - options: { autoUpdateToLatest?: boolean } = {} + options: { autoUpdateToLatest?: boolean; terminal?: string } = {} ) { logger.info(`Starting CLI tool launch: ${cliTool} in directory: ${directory}`) logger.debug(`Environment variables:`, Object.keys(env)) @@ -251,7 +538,7 @@ class CodeToolsService { const bunPath = await this.getBunPath() const executableName = await this.getCliExecutableName(cliTool) const binDir = path.join(os.homedir(), '.cherrystudio', 'bin') - const executablePath = path.join(binDir, executableName + (process.platform === 'win32' ? '.exe' : '')) + const executablePath = path.join(binDir, executableName + (isWin ? '.exe' : '')) logger.debug(`Package name: ${packageName}`) logger.debug(`Bun path: ${bunPath}`) @@ -295,7 +582,13 @@ class CodeToolsService { // Build environment variable prefix (based on platform) const buildEnvPrefix = (isWindows: boolean) => { - if (Object.keys(env).length === 0) return '' + if (Object.keys(env).length === 0) { + logger.info('No environment variables to set') + return '' + } + + logger.info('Setting environment variables:', Object.keys(env)) + logger.info('Environment variable values:', env) if (isWindows) { // Windows uses set command @@ -304,13 +597,29 @@ class CodeToolsService { .join(' && ') } else { // Unix-like systems use export command - return Object.entries(env) - .map(([key, value]) => `export ${key}="${value.replace(/"/g, '\\"')}"`) + const validEntries = Object.entries(env).filter(([key, value]) => { + if (!key || key.trim() === '') { + return false + } + if (value === undefined || value === null) { + return false + } + return true + }) + + const envCommands = validEntries + .map(([key, value]) => { + const sanitizedValue = String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"') + const exportCmd = `export ${key}="${sanitizedValue}"` + logger.info(`Setting env var: ${key}="${sanitizedValue}"`) + logger.info(`Export command: ${exportCmd}`) + return exportCmd + }) .join(' && ') + return envCommands } } - // Build command to execute let baseCommand = isWin ? `"${executablePath}"` : `"${bunPath}" "${executablePath}"` // Add configuration parameters for OpenAI Codex @@ -351,20 +660,20 @@ class CodeToolsService { switch (platform) { case 'darwin': { - // macOS - Use osascript to launch terminal and execute command directly, without showing startup command + // macOS - Support multiple terminals const envPrefix = buildEnvPrefix(false) + const command = envPrefix ? `${envPrefix} && ${baseCommand}` : baseCommand + // Combine directory change with the main command to ensure they execute in the same shell session const fullCommand = `cd '${directory.replace(/'/g, "\\'")}' && clear && ${command}` - terminalCommand = 'osascript' - terminalArgs = [ - '-e', - `tell application "Terminal" - do script "${fullCommand.replace(/"/g, '\\"')}" - activate -end tell` - ] + const terminalConfig = await this.getTerminalConfig(options.terminal) + logger.info(`Using terminal: ${terminalConfig.name} (${terminalConfig.id})`) + + const { command: cmd, args } = terminalConfig.command(directory, fullCommand) + terminalCommand = cmd + terminalArgs = args break } case 'win32': { @@ -424,9 +733,23 @@ end tell` throw new Error(`Failed to create launch script: ${error}`) } - // Launch bat file - Use safest start syntax, no title parameter - terminalCommand = 'cmd' - terminalArgs = ['/c', 'start', batFilePath] + // Use selected terminal configuration + const terminalConfig = await this.getTerminalConfig(options.terminal) + logger.info(`Using terminal: ${terminalConfig.name} (${terminalConfig.id})`) + + // Get command and args from terminal configuration + // Pass the bat file path as the command to execute + const fullCommand = batFilePath + const { command: cmd, args } = terminalConfig.command(directory, fullCommand) + + // Override if it's a custom terminal with a custom path + if (terminalConfig.customPath) { + terminalCommand = terminalConfig.customPath + terminalArgs = args + } else { + terminalCommand = cmd + terminalArgs = args + } // Set cleanup task (delete temp file after 5 minutes) setTimeout(() => { diff --git a/src/preload/index.ts b/src/preload/index.ts index cd241237b..af1cac21a 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -1,7 +1,7 @@ import { electronAPI } from '@electron-toolkit/preload' import { SpanEntity, TokenUsage } from '@mcp-trace/trace-core' import { SpanContext } from '@opentelemetry/api' -import { UpgradeChannel } from '@shared/config/constant' +import { TerminalConfig, UpgradeChannel } from '@shared/config/constant' import type { LogLevel, LogSourceWithContext } from '@shared/config/logger' import type { FileChangeEvent } from '@shared/config/types' import { IpcChannel } from '@shared/IpcChannel' @@ -439,8 +439,16 @@ const api = { model: string, directory: string, env: Record, - options?: { autoUpdateToLatest?: boolean } - ) => ipcRenderer.invoke(IpcChannel.CodeTools_Run, cliTool, model, directory, env, options) + options?: { autoUpdateToLatest?: boolean; terminal?: string } + ) => ipcRenderer.invoke(IpcChannel.CodeTools_Run, cliTool, model, directory, env, options), + getAvailableTerminals: (): Promise => + ipcRenderer.invoke(IpcChannel.CodeTools_GetAvailableTerminals), + setCustomTerminalPath: (terminalId: string, path: string): Promise => + ipcRenderer.invoke(IpcChannel.CodeTools_SetCustomTerminalPath, terminalId, path), + getCustomTerminalPath: (terminalId: string): Promise => + ipcRenderer.invoke(IpcChannel.CodeTools_GetCustomTerminalPath, terminalId), + removeCustomTerminalPath: (terminalId: string): Promise => + ipcRenderer.invoke(IpcChannel.CodeTools_RemoveCustomTerminalPath, terminalId) }, ocr: { ocr: (file: SupportedOcrFile, provider: OcrProvider): Promise => diff --git a/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts b/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts index e2aa5063a..f813f6baf 100644 --- a/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts +++ b/src/renderer/src/aiCore/chunk/AiSdkToChunkAdapter.ts @@ -13,16 +13,6 @@ import { ToolCallChunkHandler } from './handleToolCallChunk' const logger = loggerService.withContext('AiSdkToChunkAdapter') -export interface CherryStudioChunk { - type: 'text-delta' | 'text-complete' | 'tool-call' | 'tool-result' | 'finish' | 'error' - text?: string - toolCall?: any - toolResult?: any - finishReason?: string - usage?: any - error?: any -} - /** * AI SDK 到 Cherry Studio Chunk 适配器类 * 处理 fullStream 到 Cherry Studio chunk 的转换 diff --git a/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts b/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts index 57cd974a2..39aefc6a5 100644 --- a/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts +++ b/src/renderer/src/aiCore/chunk/handleToolCallChunk.ts @@ -298,8 +298,29 @@ export class ToolCallChunkHandler { type: ChunkType.MCP_TOOL_COMPLETE, responses: [toolResponse] }) + + const images: string[] = [] + for (const content of toolResponse.response?.content || []) { + if (content.type === 'image' && content.data) { + images.push(`data:${content.mimeType};base64,${content.data}`) + } + } + + if (images.length) { + this.onChunk({ + type: ChunkType.IMAGE_CREATED + }) + this.onChunk({ + type: ChunkType.IMAGE_COMPLETE, + image: { + type: 'base64', + images: images + } + }) + } } } + handleToolError( chunk: { type: 'tool-error' diff --git a/src/renderer/src/aiCore/middleware/AiSdkMiddlewareBuilder.ts b/src/renderer/src/aiCore/middleware/AiSdkMiddlewareBuilder.ts index eabdf1815..1f18e49ba 100644 --- a/src/renderer/src/aiCore/middleware/AiSdkMiddlewareBuilder.ts +++ b/src/renderer/src/aiCore/middleware/AiSdkMiddlewareBuilder.ts @@ -140,7 +140,17 @@ export function buildAiSdkMiddlewares(config: AiSdkMiddlewareConfig): LanguageMo return builder.build() } -const tagNameArray = ['think', 'thought', 'reasoning'] +const tagName = { + reasoning: 'reasoning', + think: 'think', + thought: 'thought' +} + +function getReasoningTagName(modelId: string | undefined): string { + if (modelId?.includes('gpt-oss')) return tagName.reasoning + if (modelId?.includes('gemini')) return tagName.thought + return tagName.think +} /** * 添加provider特定的中间件 @@ -156,7 +166,7 @@ function addProviderSpecificMiddlewares(builder: AiSdkMiddlewareBuilder, config: case 'openai': case 'azure-openai': { if (config.enableReasoning) { - const tagName = config.model?.id.includes('gemini') ? tagNameArray[1] : tagNameArray[0] + const tagName = getReasoningTagName(config.model?.id.toLowerCase()) builder.add({ name: 'thinking-tag-extraction', middleware: extractReasoningMiddleware({ tagName }) @@ -168,13 +178,6 @@ function addProviderSpecificMiddlewares(builder: AiSdkMiddlewareBuilder, config: // Gemini特定中间件 break case 'aws-bedrock': { - if (config.model?.id.includes('gpt-oss')) { - const tagName = tagNameArray[2] - builder.add({ - name: 'thinking-tag-extraction', - middleware: extractReasoningMiddleware({ tagName }) - }) - } break } default: diff --git a/src/renderer/src/aiCore/provider/providerConfig.ts b/src/renderer/src/aiCore/provider/providerConfig.ts index 654b06114..33116272e 100644 --- a/src/renderer/src/aiCore/provider/providerConfig.ts +++ b/src/renderer/src/aiCore/provider/providerConfig.ts @@ -213,7 +213,8 @@ export function providerToAiSdkConfig( options: { ...options, name: actualProvider.id, - ...extraOptions + ...extraOptions, + includeUsage: true } } } diff --git a/src/renderer/src/aiCore/utils/options.ts b/src/renderer/src/aiCore/utils/options.ts index dec475fc8..d151b5702 100644 --- a/src/renderer/src/aiCore/utils/options.ts +++ b/src/renderer/src/aiCore/utils/options.ts @@ -84,6 +84,7 @@ export function buildProviderOptions( case 'openai': case 'openai-chat': case 'azure': + case 'azure-responses': providerSpecificOptions = { ...buildOpenAIProviderOptions(assistant, model, capabilities), serviceTier: serviceTierSetting diff --git a/src/renderer/src/aiCore/utils/websearch.ts b/src/renderer/src/aiCore/utils/websearch.ts index e95f3e60c..2fda7c1b1 100644 --- a/src/renderer/src/aiCore/utils/websearch.ts +++ b/src/renderer/src/aiCore/utils/websearch.ts @@ -44,7 +44,7 @@ function mapMaxResultToOpenAIContextSize(maxResults: number): OpenAISearchConfig export function buildProviderBuiltinWebSearchConfig( providerId: BaseProviderId, webSearchConfig: CherryWebSearchConfig -): WebSearchPluginConfig { +): WebSearchPluginConfig | undefined { switch (providerId) { case 'openai': { return { @@ -99,7 +99,7 @@ export function buildProviderBuiltinWebSearchConfig( } } default: { - throw new Error(`Unsupported provider: ${providerId}`) + return {} } } } diff --git a/src/renderer/src/assets/styles/markdown.css b/src/renderer/src/assets/styles/markdown.css index 395247c0b..c01d9b63e 100644 --- a/src/renderer/src/assets/styles/markdown.css +++ b/src/renderer/src/assets/styles/markdown.css @@ -76,6 +76,10 @@ list-style: initial; } +.markdown ol { + list-style: decimal; +} + .markdown ul, .markdown ol { padding-left: 1.5em; diff --git a/src/renderer/src/components/Popups/SaveToKnowledgePopup.tsx b/src/renderer/src/components/Popups/SaveToKnowledgePopup.tsx index 9a7d7ee93..b7c02cd4e 100644 --- a/src/renderer/src/components/Popups/SaveToKnowledgePopup.tsx +++ b/src/renderer/src/components/Popups/SaveToKnowledgePopup.tsx @@ -255,7 +255,9 @@ const PopupContainer: React.FC = ({ source, title, resolve }) => { try { if (isNoteMode) { const note = source.data as NotesTreeNode - const content = await window.api.file.read(note.id + '.md') + const content = note.externalPath + ? await window.api.file.readExternal(note.externalPath) + : await window.api.file.read(note.id + '.md') logger.debug('Note content:', content) await addNote(content) savedCount = 1 diff --git a/src/renderer/src/config/models/reasoning.ts b/src/renderer/src/config/models/reasoning.ts index bbbc69078..74bddd289 100644 --- a/src/renderer/src/config/models/reasoning.ts +++ b/src/renderer/src/config/models/reasoning.ts @@ -225,6 +225,8 @@ export function isSupportedThinkingTokenQwenModel(model?: Model): boolean { 'qwen-plus-2025-04-28', 'qwen-plus-0714', 'qwen-plus-2025-07-14', + 'qwen-plus-2025-07-28', + 'qwen-plus-2025-09-11', 'qwen-turbo', 'qwen-turbo-latest', 'qwen-turbo-0428', @@ -410,13 +412,14 @@ export const THINKING_TOKEN_MAP: Record = 'gemini-.*-pro.*$': { min: 128, max: 32768 }, // Qwen models + // qwen-plus-x 系列自 qwen-plus-2025-07-28 后模型最长思维链变为 81_920, qwen-plus 模型于 2025.9.16 同步变更 'qwen3-235b-a22b-thinking-2507$': { min: 0, max: 81_920 }, 'qwen3-30b-a3b-thinking-2507$': { min: 0, max: 81_920 }, - 'qwen-plus-2025-07-28$': { min: 0, max: 81_920 }, - 'qwen-plus-latest$': { min: 0, max: 81_920 }, + 'qwen-plus-2025-07-14$': { min: 0, max: 38_912 }, + 'qwen-plus-2025-04-28$': { min: 0, max: 38_912 }, 'qwen3-1\\.7b$': { min: 0, max: 30_720 }, 'qwen3-0\\.6b$': { min: 0, max: 30_720 }, - 'qwen-plus.*$': { min: 0, max: 38_912 }, + 'qwen-plus.*$': { min: 0, max: 81_920 }, 'qwen-turbo.*$': { min: 0, max: 38_912 }, 'qwen-flash.*$': { min: 0, max: 81_920 }, 'qwen3-(?!max).*$': { min: 1024, max: 38_912 }, diff --git a/src/renderer/src/hooks/useCodeTools.ts b/src/renderer/src/hooks/useCodeTools.ts index db8b21bbe..4d1527ed9 100644 --- a/src/renderer/src/hooks/useCodeTools.ts +++ b/src/renderer/src/hooks/useCodeTools.ts @@ -8,7 +8,8 @@ import { setCurrentDirectory, setEnvironmentVariables, setSelectedCliTool, - setSelectedModel + setSelectedModel, + setSelectedTerminal } from '@renderer/store/codeTools' import { Model } from '@renderer/types' import { codeTools } from '@shared/config/constant' @@ -35,6 +36,14 @@ export const useCodeTools = () => { [dispatch] ) + // 设置选择的终端 + const setTerminal = useCallback( + (terminal: string) => { + dispatch(setSelectedTerminal(terminal)) + }, + [dispatch] + ) + // 设置环境变量 const setEnvVars = useCallback( (envVars: string) => { @@ -105,6 +114,7 @@ export const useCodeTools = () => { // 状态 selectedCliTool: codeToolsState.selectedCliTool, selectedModel: selectedModel, + selectedTerminal: codeToolsState.selectedTerminal, environmentVariables: environmentVariables, directories: codeToolsState.directories, currentDirectory: codeToolsState.currentDirectory, @@ -113,6 +123,7 @@ export const useCodeTools = () => { // 操作函数 setCliTool, setModel, + setTerminal, setEnvVars, addDir, removeDir, diff --git a/src/renderer/src/hooks/useKnowledge.ts b/src/renderer/src/hooks/useKnowledge.ts index c07e49eb2..ca9d5466e 100644 --- a/src/renderer/src/hooks/useKnowledge.ts +++ b/src/renderer/src/hooks/useKnowledge.ts @@ -67,7 +67,8 @@ export const useKnowledge = (baseId: string) => { // 添加笔记 const addNote = async (content: string) => { await dispatch(addNoteThunk(baseId, content)) - checkAllBases() + // 确保数据库写入完成后再触发队列检查 + setTimeout(() => KnowledgeQueue.checkAllBases(), 100) } // 添加URL diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json index 2362a135b..af2cdccc3 100644 --- a/src/renderer/src/i18n/locales/en-us.json +++ b/src/renderer/src/i18n/locales/en-us.json @@ -743,6 +743,10 @@ "bun_required_message": "Bun environment is required to run CLI tools", "cli_tool": "CLI Tool", "cli_tool_placeholder": "Select the CLI tool to use", + "custom_path": "Custom path", + "custom_path_error": "Failed to set custom terminal path", + "custom_path_required": "Custom path required for this terminal", + "custom_path_set": "Custom terminal path set successfully", "description": "Quickly launch multiple code CLI tools to improve development efficiency", "env_vars_help": "Enter custom environment variables (one per line, format: KEY=value)", "environment_variables": "Environment Variables", @@ -761,7 +765,10 @@ "model_placeholder": "Select the model to use", "model_required": "Please select a model", "select_folder": "Select Folder", + "set_custom_path": "Set custom terminal path", "supported_providers": "Supported Providers", + "terminal": "Terminal", + "terminal_placeholder": "Select terminal application", "title": "Code Tools", "update_options": "Update Options", "working_directory": "Working Directory" diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json index da0a1be0c..51abaf733 100644 --- a/src/renderer/src/i18n/locales/zh-cn.json +++ b/src/renderer/src/i18n/locales/zh-cn.json @@ -743,6 +743,10 @@ "bun_required_message": "运行 CLI 工具需要安装 Bun 环境", "cli_tool": "CLI 工具", "cli_tool_placeholder": "选择要使用的 CLI 工具", + "custom_path": "自定义路径", + "custom_path_error": "设置自定义终端路径失败", + "custom_path_required": "此终端需要设置自定义路径", + "custom_path_set": "自定义终端路径设置成功", "description": "快速启动多个代码 CLI 工具,提高开发效率", "env_vars_help": "输入自定义环境变量(每行一个,格式:KEY=value)", "environment_variables": "环境变量", @@ -761,7 +765,10 @@ "model_placeholder": "选择要使用的模型", "model_required": "请选择模型", "select_folder": "选择文件夹", + "set_custom_path": "设置自定义终端路径", "supported_providers": "支持的服务商", + "terminal": "终端", + "terminal_placeholder": "选择终端应用", "title": "代码工具", "update_options": "更新选项", "working_directory": "工作目录" diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json index fb9b45270..b290d1115 100644 --- a/src/renderer/src/i18n/locales/zh-tw.json +++ b/src/renderer/src/i18n/locales/zh-tw.json @@ -743,6 +743,10 @@ "bun_required_message": "運行 CLI 工具需要安裝 Bun 環境", "cli_tool": "CLI 工具", "cli_tool_placeholder": "選擇要使用的 CLI 工具", + "custom_path": "自訂路徑", + "custom_path_error": "設定自訂終端機路徑失敗", + "custom_path_required": "此終端機需要設定自訂路徑", + "custom_path_set": "自訂終端機路徑設定成功", "description": "快速啟動多個程式碼 CLI 工具,提高開發效率", "env_vars_help": "輸入自定義環境變數(每行一個,格式:KEY=value)", "environment_variables": "環境變數", @@ -761,7 +765,10 @@ "model_placeholder": "選擇要使用的模型", "model_required": "請選擇模型", "select_folder": "選擇資料夾", + "set_custom_path": "設定自訂終端機路徑", "supported_providers": "支援的供應商", + "terminal": "終端機", + "terminal_placeholder": "選擇終端機應用程式", "title": "程式碼工具", "update_options": "更新選項", "working_directory": "工作目錄" diff --git a/src/renderer/src/i18n/translate/el-gr.json b/src/renderer/src/i18n/translate/el-gr.json index edee87491..192bd3bb6 100644 --- a/src/renderer/src/i18n/translate/el-gr.json +++ b/src/renderer/src/i18n/translate/el-gr.json @@ -743,6 +743,10 @@ "bun_required_message": "Για τη λειτουργία του εργαλείου CLI πρέπει να εγκαταστήσετε το περιβάλλον Bun", "cli_tool": "Εργαλείο CLI", "cli_tool_placeholder": "Επιλέξτε το CLI εργαλείο που θέλετε να χρησιμοποιήσετε", + "custom_path": "Προσαρμοσμένη διαδρομή", + "custom_path_error": "Η ρύθμιση της προσαρμοσμένης διαδρομής τερματικού απέτυχε", + "custom_path_required": "Αυτό το τερματικό απαιτεί τη ρύθμιση προσαρμοσμένης διαδρομής", + "custom_path_set": "Η προσαρμοσμένη διαδρομή τερματικού ορίστηκε με επιτυχία", "description": "Εκκίνηση γρήγορα πολλών εργαλείων CLI κώδικα, για αύξηση της αποδοτικότητας ανάπτυξης", "env_vars_help": "Εισαγάγετε προσαρμοσμένες μεταβλητές περιβάλλοντος (μία ανά γραμμή, με τη μορφή: KEY=value)", "environment_variables": "Μεταβλητές περιβάλλοντος", @@ -761,7 +765,10 @@ "model_placeholder": "Επιλέξτε το μοντέλο που θα χρησιμοποιήσετε", "model_required": "Επιλέξτε μοντέλο", "select_folder": "Επιλογή φακέλου", + "set_custom_path": "Ρύθμιση προσαρμοσμένης διαδρομής τερματικού", "supported_providers": "υποστηριζόμενοι πάροχοι", + "terminal": "τερματικό", + "terminal_placeholder": "Επιλέξτε εφαρμογή τερματικού", "title": "Εργαλεία κώδικα", "update_options": "Ενημέρωση επιλογών", "working_directory": "κατάλογος εργασίας" diff --git a/src/renderer/src/i18n/translate/es-es.json b/src/renderer/src/i18n/translate/es-es.json index 6b69bfad2..70819f46a 100644 --- a/src/renderer/src/i18n/translate/es-es.json +++ b/src/renderer/src/i18n/translate/es-es.json @@ -743,6 +743,10 @@ "bun_required_message": "Se requiere instalar el entorno Bun para ejecutar la herramienta de línea de comandos", "cli_tool": "Herramienta de línea de comandos", "cli_tool_placeholder": "Seleccione la herramienta de línea de comandos que desea utilizar", + "custom_path": "Ruta personalizada", + "custom_path_error": "Error al establecer la ruta de terminal personalizada", + "custom_path_required": "此终端需要设置自定义路径", + "custom_path_set": "Configuración de ruta de terminal personalizada exitosa", "description": "Inicia rápidamente múltiples herramientas de línea de comandos para código, aumentando la eficiencia del desarrollo", "env_vars_help": "Introduzca variables de entorno personalizadas (una por línea, formato: CLAVE=valor)", "environment_variables": "Variables de entorno", @@ -761,7 +765,10 @@ "model_placeholder": "Seleccionar el modelo que se va a utilizar", "model_required": "Seleccione el modelo", "select_folder": "Seleccionar carpeta", + "set_custom_path": "Establecer ruta de terminal personalizada", "supported_providers": "Proveedores de servicios compatibles", + "terminal": "terminal", + "terminal_placeholder": "Seleccionar aplicación de terminal", "title": "Herramientas de código", "update_options": "Opciones de actualización", "working_directory": "directorio de trabajo" diff --git a/src/renderer/src/i18n/translate/fr-fr.json b/src/renderer/src/i18n/translate/fr-fr.json index 646ba6734..68e4b4f56 100644 --- a/src/renderer/src/i18n/translate/fr-fr.json +++ b/src/renderer/src/i18n/translate/fr-fr.json @@ -743,6 +743,10 @@ "bun_required_message": "L'exécution de l'outil en ligne de commande nécessite l'installation de l'environnement Bun", "cli_tool": "Outil CLI", "cli_tool_placeholder": "Sélectionnez l'outil CLI à utiliser", + "custom_path": "Chemin personnalisé", + "custom_path_error": "Échec de la définition du chemin de terminal personnalisé", + "custom_path_required": "Ce terminal nécessite la configuration d’un chemin personnalisé", + "custom_path_set": "Paramétrage personnalisé du chemin du terminal réussi", "description": "Lancer rapidement plusieurs outils CLI de code pour améliorer l'efficacité du développement", "env_vars_help": "Saisissez les variables d'environnement personnalisées (une par ligne, format : KEY=value)", "environment_variables": "variables d'environnement", @@ -761,7 +765,10 @@ "model_placeholder": "Sélectionnez le modèle à utiliser", "model_required": "Veuillez sélectionner le modèle", "select_folder": "Sélectionner le dossier", + "set_custom_path": "Définir un chemin de terminal personnalisé", "supported_providers": "fournisseurs pris en charge", + "terminal": "Terminal", + "terminal_placeholder": "Choisir une application de terminal", "title": "Outils de code", "update_options": "Options de mise à jour", "working_directory": "répertoire de travail" diff --git a/src/renderer/src/i18n/translate/ja-jp.json b/src/renderer/src/i18n/translate/ja-jp.json index 3e6b732b2..c84293f55 100644 --- a/src/renderer/src/i18n/translate/ja-jp.json +++ b/src/renderer/src/i18n/translate/ja-jp.json @@ -743,6 +743,10 @@ "bun_required_message": "CLI ツールを実行するには Bun 環境が必要です", "cli_tool": "CLI ツール", "cli_tool_placeholder": "使用する CLI ツールを選択してください", + "custom_path": "カスタムパス", + "custom_path_error": "カスタムターミナルパスの設定に失敗しました", + "custom_path_required": "この端末にはカスタムパスを設定する必要があります", + "custom_path_set": "カスタムターミナルパスの設定が成功しました", "description": "開発効率を向上させるために、複数のコード CLI ツールを迅速に起動します", "env_vars_help": "環境変数を設定して、CLI ツールの実行時に使用します。各変数は 1 行ごとに設定してください。", "environment_variables": "環境変数", @@ -761,7 +765,10 @@ "model_placeholder": "使用するモデルを選択してください", "model_required": "モデルを選択してください", "select_folder": "フォルダを選択", + "set_custom_path": "カスタムターミナルパスを設定", "supported_providers": "サポートされているプロバイダー", + "terminal": "端末", + "terminal_placeholder": "ターミナルアプリを選択", "title": "コードツール", "update_options": "更新オプション", "working_directory": "作業ディレクトリ" diff --git a/src/renderer/src/i18n/translate/pt-pt.json b/src/renderer/src/i18n/translate/pt-pt.json index 7ca5065a1..3beec46d1 100644 --- a/src/renderer/src/i18n/translate/pt-pt.json +++ b/src/renderer/src/i18n/translate/pt-pt.json @@ -743,6 +743,10 @@ "bun_required_message": "Executar a ferramenta CLI requer a instalação do ambiente Bun", "cli_tool": "Ferramenta de linha de comando", "cli_tool_placeholder": "Selecione a ferramenta de linha de comando a ser utilizada", + "custom_path": "Caminho personalizado", + "custom_path_error": "Falha ao definir caminho de terminal personalizado", + "custom_path_required": "Este terminal requer a definição de um caminho personalizado", + "custom_path_set": "Configuração personalizada do caminho do terminal bem-sucedida", "description": "Inicie rapidamente várias ferramentas de linha de comando de código, aumentando a eficiência do desenvolvimento", "env_vars_help": "Insira variáveis de ambiente personalizadas (uma por linha, formato: CHAVE=valor)", "environment_variables": "variáveis de ambiente", @@ -761,7 +765,10 @@ "model_placeholder": "Selecione o modelo a ser utilizado", "model_required": "Selecione o modelo", "select_folder": "Selecionar pasta", + "set_custom_path": "Definir caminho personalizado do terminal", "supported_providers": "Provedores de serviço suportados", + "terminal": "terminal", + "terminal_placeholder": "Selecionar aplicativo de terminal", "title": "Ferramenta de código", "update_options": "Opções de atualização", "working_directory": "diretório de trabalho" diff --git a/src/renderer/src/i18n/translate/ru-ru.json b/src/renderer/src/i18n/translate/ru-ru.json index c6b7ad8b2..3898379f0 100644 --- a/src/renderer/src/i18n/translate/ru-ru.json +++ b/src/renderer/src/i18n/translate/ru-ru.json @@ -743,6 +743,10 @@ "bun_required_message": "Запуск CLI-инструментов требует установки среды Bun", "cli_tool": "Инструмент", "cli_tool_placeholder": "Выберите CLI-инструмент для использования", + "custom_path": "Пользовательский путь", + "custom_path_error": "Не удалось задать пользовательский путь терминала", + "custom_path_required": "Этот терминал требует установки пользовательского пути", + "custom_path_set": "Пользовательский путь терминала успешно установлен", "description": "Быстро запускает несколько CLI-инструментов для кода, повышая эффективность разработки", "env_vars_help": "Установите переменные окружения для использования при запуске CLI-инструментов. Каждая переменная должна быть на отдельной строке в формате KEY=value", "environment_variables": "Переменные окружения", @@ -761,7 +765,10 @@ "model_placeholder": "Выберите модель для использования", "model_required": "Пожалуйста, выберите модель", "select_folder": "Выберите папку", + "set_custom_path": "Настройка пользовательского пути терминала", "supported_providers": "Поддерживаемые поставщики", + "terminal": "терминал", + "terminal_placeholder": "Выбор приложения терминала", "title": "Инструменты кода", "update_options": "Параметры обновления", "working_directory": "Рабочая директория" diff --git a/src/renderer/src/pages/code/CodeToolsPage.tsx b/src/renderer/src/pages/code/CodeToolsPage.tsx index 3485ad401..bb15871e4 100644 --- a/src/renderer/src/pages/code/CodeToolsPage.tsx +++ b/src/renderer/src/pages/code/CodeToolsPage.tsx @@ -1,6 +1,7 @@ import AiProvider from '@renderer/aiCore' import { Navbar, NavbarCenter } from '@renderer/components/app/Navbar' import ModelSelector from '@renderer/components/ModelSelector' +import { isMac, isWin } from '@renderer/config/constant' import { isEmbeddingModel, isRerankModel, isTextToImageModel } from '@renderer/config/models' import { getProviderLogo } from '@renderer/config/providers' import { useCodeTools } from '@renderer/hooks/useCodeTools' @@ -14,9 +15,9 @@ import { useAppDispatch, useAppSelector } from '@renderer/store' import { setIsBunInstalled } from '@renderer/store/mcp' import { Model } from '@renderer/types' import { getClaudeSupportedProviders } from '@renderer/utils/provider' -import { codeTools } from '@shared/config/constant' -import { Alert, Avatar, Button, Checkbox, Input, Popover, Select, Space } from 'antd' -import { ArrowUpRight, Download, HelpCircle, Terminal, X } from 'lucide-react' +import { codeTools, terminalApps, TerminalConfig } from '@shared/config/constant' +import { Alert, Avatar, Button, Checkbox, Input, Popover, Select, Space, Tooltip } from 'antd' +import { ArrowUpRight, Download, FolderOpen, HelpCircle, Terminal, X } from 'lucide-react' import { FC, useCallback, useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' @@ -42,12 +43,14 @@ const CodeToolsPage: FC = () => { const { selectedCliTool, selectedModel, + selectedTerminal, environmentVariables, directories, currentDirectory, canLaunch, setCliTool, setModel, + setTerminal, setEnvVars, setCurrentDir, removeDir, @@ -58,6 +61,9 @@ const CodeToolsPage: FC = () => { const [isLaunching, setIsLaunching] = useState(false) const [isInstallingBun, setIsInstallingBun] = useState(false) const [autoUpdateToLatest, setAutoUpdateToLatest] = useState(false) + const [availableTerminals, setAvailableTerminals] = useState([]) + const [isLoadingTerminals, setIsLoadingTerminals] = useState(false) + const [terminalCustomPaths, setTerminalCustomPaths] = useState>({}) const modelPredicate = useCallback( (m: Model) => { @@ -119,6 +125,26 @@ const CodeToolsPage: FC = () => { } }, [dispatch]) + // 获取可用终端 + const loadAvailableTerminals = useCallback(async () => { + if (!isMac && !isWin) return // 仅 macOS 和 Windows 支持 + + try { + setIsLoadingTerminals(true) + const terminals = await window.api.codeTools.getAvailableTerminals() + setAvailableTerminals(terminals) + logger.info( + `Found ${terminals.length} available terminals:`, + terminals.map((t) => t.name) + ) + } catch (error) { + logger.error('Failed to load available terminals:', error as Error) + setAvailableTerminals([]) + } finally { + setIsLoadingTerminals(false) + } + }, []) + // 安装 bun const handleInstallBun = async () => { try { @@ -179,11 +205,37 @@ const CodeToolsPage: FC = () => { // 执行启动操作 const executeLaunch = async (env: Record) => { window.api.codeTools.run(selectedCliTool, selectedModel?.id!, currentDirectory, env, { - autoUpdateToLatest + autoUpdateToLatest, + terminal: selectedTerminal }) window.toast.success(t('code.launch.success')) } + // 设置终端自定义路径 + const handleSetCustomPath = async (terminalId: string) => { + try { + const result = await window.api.file.select({ + properties: ['openFile'], + filters: [ + { name: 'Executable', extensions: ['exe'] }, + { name: 'All Files', extensions: ['*'] } + ] + }) + + if (result && result.length > 0) { + const path = result[0].path + await window.api.codeTools.setCustomTerminalPath(terminalId, path) + setTerminalCustomPaths((prev) => ({ ...prev, [terminalId]: path })) + window.toast.success(t('code.custom_path_set')) + // Reload terminals to reflect changes + loadAvailableTerminals() + } + } catch (error) { + logger.error('Failed to set custom terminal path:', error as Error) + window.toast.error(t('code.custom_path_error')) + } + } + // 处理启动 const handleLaunch = async () => { const validation = validateLaunch() @@ -216,6 +268,11 @@ const CodeToolsPage: FC = () => { checkBunInstallation() }, [checkBunInstallation]) + // 页面加载时获取可用终端 + useEffect(() => { + loadAvailableTerminals() + }, [loadAvailableTerminals]) + return ( @@ -350,6 +407,47 @@ const CodeToolsPage: FC = () => {
{t('code.env_vars_help')}
+ {/* 终端选择 (macOS 和 Windows) */} + {(isMac || isWin) && availableTerminals.length > 0 && ( + +
{t('code.terminal')}
+ +