diff --git a/src/main/index.ts b/src/main/index.ts index 422f20f..6c20418 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -65,7 +65,8 @@ import { getLlamaCppPty, validateLlamaCppProcess, checkLlamaCppUpdate, - updateLlamaCpp + updateLlamaCpp, + uninstallLlamaCpp } from './utils/llamacpp' import { @@ -907,6 +908,28 @@ if (!gotTheLock) { ipcMain.handle('llamacpp:logs', () => getLlamaCppLog()) ipcMain.handle('llamacpp:pty:connect', () => connectLlamaCppPtyPort()) + ipcMain.handle('llamacpp:uninstall', async () => { + try { + const info = getLlamaCppInfo() + await uninstallLlamaCpp() + sendToRenderer('status:llamacpp', null) + // Unregister OpenAI endpoint if it was running + if (info.url) { + sendToRenderer('connections:openai', { + action: 'remove', + url: `${info.url}/v1` + }) + setTimeout(() => sendToRenderer('models:refresh'), 500) + } + await setConfig({ llamaCpp: { ...CONFIG?.llamaCpp, enabled: false } }) + CONFIG = await getConfig() + return true + } catch (error) { + log.error('Failed to uninstall llamacpp:', error) + return false + } + }) + // Hugging Face models ipcMain.handle('huggingface:models:list', () => listModels()) ipcMain.handle('huggingface:models:dir', () => getModelsDir()) diff --git a/src/main/utils/llamacpp.ts b/src/main/utils/llamacpp.ts index 0677f7b..dd9084e 100644 --- a/src/main/utils/llamacpp.ts +++ b/src/main/utils/llamacpp.ts @@ -505,3 +505,18 @@ export const validateLlamaCppProcess = (): boolean => { lock.release() return false } + +/** + * Uninstall llama.cpp — stop the server and remove all downloaded binaries. + */ +export const uninstallLlamaCpp = async (): Promise => { + await stopLlamaCpp() + + const cacheBase = path.join(getUserDataPath(), 'llama.cpp') + if (fs.existsSync(cacheBase)) { + fs.rmSync(cacheBase, { recursive: true, force: true }) + log.info('Removed llama.cpp directory:', cacheBase) + } + + binaryPath = null +} diff --git a/src/preload/index.ts b/src/preload/index.ts index 21f2963..28d461c 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -175,6 +175,7 @@ const api = { }, checkLlamaCppUpdate: () => ipcRenderer.invoke('llamacpp:check-update'), updateLlamaCpp: () => ipcRenderer.invoke('llamacpp:update'), + uninstallLlamaCpp: () => ipcRenderer.invoke('llamacpp:uninstall'), // Hugging Face models listHfModels: () => ipcRenderer.invoke('huggingface:models:list'), diff --git a/src/renderer/src/lib/components/Main/Connections/GetStartedModal.svelte b/src/renderer/src/lib/components/Main/Connections/GetStartedModal.svelte index 074629f..262f8b1 100644 --- a/src/renderer/src/lib/components/Main/Connections/GetStartedModal.svelte +++ b/src/renderer/src/lib/components/Main/Connections/GetStartedModal.svelte @@ -67,7 +67,7 @@
{$i18n.t('main.getStarted.llamaCpp')} - {$i18n.t('common.experimental')} + {$i18n.t('common.experimental')}
{$i18n.t('main.getStarted.llamaCppDesc')}
diff --git a/src/renderer/src/lib/components/Main/Settings/InferenceRuntime.svelte b/src/renderer/src/lib/components/Main/Settings/InferenceRuntime.svelte index 6e1f859..717389c 100644 --- a/src/renderer/src/lib/components/Main/Settings/InferenceRuntime.svelte +++ b/src/renderer/src/lib/components/Main/Settings/InferenceRuntime.svelte @@ -11,6 +11,8 @@ let settingUp = $state(false) let loaded = $state(false) let setupStatus = $state('') + let uninstalling = $state(false) + let installing = $state(false) type UpdateStatus = 'idle' | 'checking' | 'available' | 'updating' | 'up-to-date' | 'error' let updateStatus = $state('idle') @@ -166,6 +168,8 @@ deleting = null } + const installed = $derived(!!lsInfo?.binaryPath) + const formatSize = (bytes: number): string => { if (bytes < 1024) return `${bytes} B` if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB` @@ -176,6 +180,37 @@ {#if !loaded}
{$i18n.t('common.loading')}
+{:else if !installed} +
+
+
+ {$i18n.t('settings.inference.notInstalled')} + {$i18n.t('common.experimental')} +
+
{$i18n.t('settings.inference.notInstalledDesc')}
+
+ +
{:else}
@@ -184,7 +219,7 @@
{$i18n.t('settings.inference.llamaServer')} - {$i18n.t('common.experimental')} + {$i18n.t('common.experimental')}
{$i18n.t('settings.inference.llamaServerDesc')} @@ -430,5 +465,38 @@ />
+ + {#if lsInfo?.binaryPath} +
+
+
{$i18n.t('settings.inference.uninstall')}
+
{$i18n.t('settings.inference.uninstallDesc')}
+
+ +
+ {/if} +
{/if} diff --git a/src/renderer/src/lib/i18n/locales/en-US/translation.json b/src/renderer/src/lib/i18n/locales/en-US/translation.json index 7f64ea6..5ca0a02 100644 --- a/src/renderer/src/lib/i18n/locales/en-US/translation.json +++ b/src/renderer/src/lib/i18n/locales/en-US/translation.json @@ -235,6 +235,11 @@ "settings.inference.updateAvailable": "Update available: {{version}}", "settings.inference.upToDate": "Up to date", "settings.inference.updating": "Updating…", + "settings.inference.uninstall": "Uninstall", + "settings.inference.uninstallDesc": "Remove llama.cpp binaries", + "settings.inference.uninstallConfirm": "This will stop llama-server and remove all downloaded binaries. Continue?", + "settings.inference.notInstalled": "llama.cpp is not installed", + "settings.inference.notInstalledDesc": "Download and set up llama.cpp for local model inference", "settings.models.downloadedModels": "Downloaded Models", "settings.models.noModels": "No models downloaded yet",