diff --git a/docs/docs.json b/docs/docs.json index fa1f5049a..baf2caee3 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -59,7 +59,8 @@ "/core/concepts", "/core/workforce", "/core/models", - "/core/tools" + "/core/tools", + "workers" ] }, { diff --git a/resources/scripts/download.js b/resources/scripts/download.js index 6307e38aa..f77115815 100644 --- a/resources/scripts/download.js +++ b/resources/scripts/download.js @@ -27,11 +27,44 @@ export async function downloadWithRedirects(url, destinationPath) { reject(new Error(`Download failed: ${response.statusCode} ${response.statusMessage}`)) return } + const file = fs.createWriteStream(destinationPath) + let downloadedBytes = 0 + const expectedBytes = parseInt(response.headers['content-length'] || '0') + + response.on('data', (chunk) => { + downloadedBytes += chunk.length + }) + response.pipe(file) + file.on('finish', () => { + file.close(() => { + clearTimeout(timeout); + + // Verify the download is complete + if (expectedBytes > 0 && downloadedBytes !== expectedBytes) { + fs.unlinkSync(destinationPath) + reject(new Error(`Download incomplete: received ${downloadedBytes} bytes, expected ${expectedBytes}`)) + return + } + + // Check if file exists and has size > 0 + const stats = fs.statSync(destinationPath) + if (stats.size === 0) { + fs.unlinkSync(destinationPath) + reject(new Error('Downloaded file is empty')) + return + } + + resolve() + }) + }) + + file.on('error', (err) => { clearTimeout(timeout); - resolve() + fs.unlinkSync(destinationPath) + reject(err) }) }) .on('error', (err) => { diff --git a/resources/scripts/install-bun.js b/resources/scripts/install-bun.js index 4803999a0..0b3df6d38 100644 --- a/resources/scripts/install-bun.js +++ b/resources/scripts/install-bun.js @@ -65,33 +65,44 @@ async function downloadBunBinary(bun_download_url,platform, arch, version = DEFA // Extract the zip file using adm-zip console.log(`Extracting ${packageName} to ${binDir}...`) const zip = new AdmZip(tempFilename) - zip.extractAllTo(tempdir, true) - - // Move files using Node.js fs - const sourceDir = path.join(tempdir, packageName.split('.')[0]) - const files = fs.readdirSync(sourceDir) - - for (const file of files) { - const sourcePath = path.join(sourceDir, file) - const destPath = path.join(binDir, file) - - fs.copyFileSync(sourcePath, destPath) - fs.unlinkSync(sourcePath) - - // Set executable permissions for non-Windows platforms - if (platform !== 'win32') { - try { - // 755 permission: rwxr-xr-x - fs.chmodSync(destPath, '755') - } catch (error) { - console.warn(`Warning: Failed to set executable permissions: ${error.message}`) + + // Get all entries and find the bun binary + const entries = zip.getEntries() + let bunFound = false + + for (const entry of entries) { + const entryName = entry.entryName + // Look for the bun binary (could be in root or in a subdirectory) + if (entryName === 'bun' || entryName === 'bun.exe' || + entryName.endsWith('/bun') || entryName.endsWith('/bun.exe') || + entryName.endsWith('\\bun') || entryName.endsWith('\\bun.exe')) { + + // Extract just the binary name + const fileName = path.basename(entryName) + const destPath = path.join(binDir, fileName) + + // Extract the specific file + zip.extractEntryTo(entry, binDir, false, true) + + // Set executable permissions for non-Windows platforms + if (platform !== 'win32' && fileName === 'bun') { + try { + fs.chmodSync(destPath, '755') + } catch (error) { + console.warn(`Warning: Failed to set executable permissions: ${error.message}`) + } } + + bunFound = true } } + + if (!bunFound) { + throw new Error('bun binary not found in archive') + } // Clean up fs.unlinkSync(tempFilename) - fs.rmSync(sourceDir, { recursive: true }) console.log(`Successfully installed bun ${version} for ${platformKey}`) return true diff --git a/resources/scripts/install-uv.js b/resources/scripts/install-uv.js index 1837fcc21..9a8a1dcdf 100644 --- a/resources/scripts/install-uv.js +++ b/resources/scripts/install-uv.js @@ -89,23 +89,21 @@ async function downloadUvBinary( // handle tar.gz file await tar.x({ file: tempFilename, - cwd: tempdir, + cwd: binDir, + strip: 1, z: true, + filter: (path) => { + // Only extract the uv binary + return path.endsWith('uv') || path.endsWith('uv.exe'); + } }); - // Move files using Node.js fs - const sourceDir = path.join(tempdir, packageName.split(".")[0]); - const files = fs.readdirSync(sourceDir); - for (const file of files) { - const sourcePath = path.join(sourceDir, file); - const destPath = path.join(binDir, file); - fs.copyFileSync(sourcePath, destPath); - fs.unlinkSync(sourcePath); - - // Set executable permissions for non-Windows platforms - if (platform !== "win32") { + // Set executable permissions for non-Windows platforms + if (platform !== "win32") { + const uvPath = path.join(binDir, "uv"); + if (fs.existsSync(uvPath)) { try { - fs.chmodSync(destPath, "755"); + fs.chmodSync(uvPath, "755"); } catch (error) { console.warn( `Warning: Failed to set executable permissions: ${error.message}` @@ -116,7 +114,6 @@ async function downloadUvBinary( // Clean up fs.unlinkSync(tempFilename); - fs.rmSync(sourceDir, { recursive: true }); } console.log(`Successfully installed uv ${version} for ${platform}-${arch}`);