AI Assistant: Download & install aiassistantserver for supported OSes

Change-Id: I87e0ec1613c30252fc5db608af42319d844add0b
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Lukasz Papierkowski
2024-08-29 17:18:30 +02:00
committed by lie
parent 2ef2a44445
commit c347fecf2e

View File

@@ -14,7 +14,6 @@ local Action = require("Action")
Hooks = {} Hooks = {}
AutoSuggestionDelay = 2000 AutoSuggestionDelay = 2000
ServerName = "qtaiassistantserver" ServerName = "qtaiassistantserver"
ServerReleasesURL = "https://qtaiassistant.gitlab-pages.qt.io/qtails/releases/" .. ServerName .. ".json"
InlineChatActive = false InlineChatActive = false
local function collectSuggestions(responseTable) local function collectSuggestions(responseTable)
@@ -78,89 +77,68 @@ local function createInitOptions()
} }
end end
local function filter(tbl, callback)
for i = #tbl, 1, -1 do
if not callback(tbl[i]) then
table.remove(tbl, i)
end
end
end
local function installOrUpdateServer() local function installOrUpdateServer()
-- TODO: Support Windows and Mac OS
local data = a.wait(fetch({ local data = a.wait(fetch({
url = ServerReleasesURL, url = "https://qtccache.qt.io/QtAIAssistant/LatestRelease",
convertToTable = true convertToTable = true
})) }))
if data == nil or data["assets"] == nil then if not data then
print("Failed to fetch release data.") print("Failed to fetch release data.")
return return
end end
local links = data["assets"]["links"] local id = string.format("%.0f", data["id"])
if type(links) == "table" and #links > 0 then print("Found version:", id)
local tag_name = data["tag_name"]
print("Found tag name:", tag_name)
local lspPkgInfo = Install.packageInfo(ServerName) local lspPkgInfo = Install.packageInfo(ServerName)
if not lspPkgInfo or lspPkgInfo.version ~= tag_name then if not lspPkgInfo or lspPkgInfo.version ~= id then
local osTr = { mac = "darwin", windows = "win32", linux = "linux" } local osTr = { mac = "macos", windows = "windows", linux = "ubuntu" }
local archTr = { unknown = "", x86 = "ia32", x86_64 = "x64", itanium = "", arm = "", arm64 = "arm64" } local os = osTr[Utils.HostOsInfo.os]
local extTr = { mac = "gz", windows = "zip", linux = "tar.gz" }
local os = osTr[Utils.HostOsInfo.os]
if os ~= "linux" then print("Attempt to download server for: ", Utils.HostOsInfo.os)
print("Currently unsupported OS:", Utils.HostOsInfo.os)
return local expectedFileName = "project-build-" .. os
local asset = nil
for _, a in ipairs(data["assets"]) do
if string.find(a.name, expectedFileName, 1, true) then
asset = a
break
end end
local arch = archTr[Utils.HostOsInfo.architecture]
local ext = extTr[Utils.HostOsInfo.os]
local expectedFileName = ServerName .. "-" .. tag_name .. "-" .. os .. "-" .. arch .. "." .. ext
filter(links, function(asset)
return string.find(asset.name, expectedFileName, 1, true) == 1
end)
if #links == 0 then
print("No assets found for this platform. Expected file base name:", expectedFileName)
return
end
print("Using link:", links[1].url)
local res, err = a.wait(Install.install(
"Do you want to install the qtaiassistantserver?", {
name = "qtaiassistantserver",
url = links[1].url,
version = tag_name
}))
if not res then
mm.writeFlashing("Failed to install qtaiassistantserver: " .. err)
return
end
lspPkgInfo = Install.packageInfo("qtaiassistantserver")
print("Installed:", lspPkgInfo.name, " version:", lspPkgInfo.version, " at:", lspPkgInfo.path)
end end
local base_name = "qtaiassistantserver-" .. tag_name if not asset then
local binary = base_name .. "-linux-x64" print("No assets found for this platform. Expected file base name:", expectedFileName)
if Utils.HostOsInfo.isWindowsHost() then return
binary = base_name .. "-windows-x64.exe"
end end
Settings.binary:setValue(lspPkgInfo.path:resolvePath(binary)) local assetId = string.format("%.0f", asset["id"])
Settings:apply() local downloadUrl = "https://qtccache.qt.io/QtAIAssistant/Asset?assetId=" .. assetId
print("Using download URL:", downloadUrl)
else local res, err = a.wait(Install.install(
print("No links found in the release data.") "Do you want to install the " .. ServerName .. "?", {
name = ServerName,
url = downloadUrl,
version = id
}))
if not res then
mm.writeFlashing("Failed to install " .. ServerName .. ": " .. err .. ". Please make sure you have 7z installed for package extraction.")
return
end
lspPkgInfo = Install.packageInfo(ServerName)
print("Installed:", lspPkgInfo.name, " version:", lspPkgInfo.version, " at:", lspPkgInfo.path)
end end
local binary = ServerName
if Utils.HostOsInfo.isWindowsHost() then
binary = binary .. ".exe"
end
Settings.binary:setValue(lspPkgInfo.path:resolvePath(binary))
Settings:apply()
end end
IsTryingToInstall = false IsTryingToInstall = false