Refresh list of backends by calling configureBackends() and some refactoring in installBackend

This commit is contained in:
Akarshan 2025-09-08 20:02:04 +05:30
parent ba4dc6d1eb
commit 2e350ab607
No known key found for this signature in database
GPG Key ID: D75C9634A870665F

View File

@ -1047,28 +1047,33 @@ export default class llamacpp_extension extends AIEngine {
const re = /^llama-(b\d+)-bin-(.+?)\.tar\.gz$/
const archiveName = await basename(path)
let binPath: string
if ((await fs.existsSync(path)) && path.endsWith('tar.gz')) {
const match = re.exec(archiveName)
if (!match) throw new Error('Failed to parse archive name')
const [, version, backend] = match
if (!version && !backend) {
throw new Error(`Invalid backend archive name: ${archiveName}`)
}
const backendDir = await getBackendDir(backend, version)
await invoke('decompress', { path: path, outputDir: backendDir })
if (platformName == 'win')
binPath = await joinPath([
backendDir,
'build',
'bin',
'llama-server.exe',
])
else
binPath = await joinPath([backendDir, 'build', 'bin', 'llama-server'])
const binPath =
platformName === 'win'
? await joinPath([backendDir, 'build', 'bin', 'llama-server.exe'])
: await joinPath([backendDir, 'build', 'bin', 'llama-server'])
if (!fs.existsSync(binPath)) {
await fs.rm(backendDir)
throw new Error('Not a supported backend archive!')
}
try {
await this.configureBackends()
logger.info(`Backend ${backend}/${version} installed and UI refreshed`)
} catch (e) {
logger.error('Backend installed but failed to refresh UI', e)
throw new Error(
`Backend installed but failed to refresh UI: ${String(e)}`
)
}
}
}