mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-04-28 03:30:06 +00:00
Initial commit of eigent-main
This commit is contained in:
commit
723df5a03e
1144 changed files with 103478 additions and 0 deletions
45
resources/scripts/download.js
Normal file
45
resources/scripts/download.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// @ts-check
|
||||
import https from 'https'
|
||||
import fs from 'fs'
|
||||
|
||||
/**
|
||||
* Downloads a file from a URL with redirect handling
|
||||
* @param {string} url The URL to download from
|
||||
* @param {string} destinationPath The path to save the file to
|
||||
* @returns {Promise<void>} Promise that resolves when download is complete
|
||||
*/
|
||||
export async function downloadWithRedirects(url, destinationPath) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutMs = 3 * 60 * 1000; // 3 minutes
|
||||
const timeout = setTimeout(() => {
|
||||
reject(new Error(`timeout(${timeoutMs / 1000} seconds)`));
|
||||
}, timeoutMs);
|
||||
|
||||
const request = (url) => {
|
||||
https
|
||||
.get(url, (response) => {
|
||||
if (response.statusCode == 301 || response.statusCode == 302) {
|
||||
request(response.headers.location)
|
||||
return
|
||||
}
|
||||
if (response.statusCode !== 200) {
|
||||
clearTimeout(timeout);
|
||||
reject(new Error(`Download failed: ${response.statusCode} ${response.statusMessage}`))
|
||||
return
|
||||
}
|
||||
const file = fs.createWriteStream(destinationPath)
|
||||
response.pipe(file)
|
||||
file.on('finish', () => {
|
||||
clearTimeout(timeout);
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
.on('error', (err) => {
|
||||
clearTimeout(timeout);
|
||||
reject(err)
|
||||
})
|
||||
}
|
||||
request(url)
|
||||
})
|
||||
}
|
||||
|
||||
175
resources/scripts/install-bun.js
Normal file
175
resources/scripts/install-bun.js
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import os from 'os'
|
||||
import { execSync } from 'child_process'
|
||||
import AdmZip from 'adm-zip'
|
||||
import { downloadWithRedirects } from './download.js'
|
||||
|
||||
// Base URL for downloading bun binaries
|
||||
const BUN_RELEASE_BASE_URL = 'https://github.com/oven-sh/bun/releases/download'
|
||||
const DEFAULT_BUN_VERSION = '1.2.9' // Default fallback version
|
||||
|
||||
// Mapping of platform+arch to binary package name
|
||||
const BUN_PACKAGES = {
|
||||
'darwin-arm64': 'bun-darwin-aarch64.zip',
|
||||
'darwin-x64': 'bun-darwin-x64.zip',
|
||||
'win32-x64': 'bun-windows-x64.zip',
|
||||
'win32-x64-baseline': 'bun-windows-x64-baseline.zip',
|
||||
'linux-x64': 'bun-linux-x64.zip',
|
||||
'linux-x64-baseline': 'bun-linux-x64-baseline.zip',
|
||||
'linux-arm64': 'bun-linux-aarch64.zip',
|
||||
// MUSL variants
|
||||
'linux-musl-x64': 'bun-linux-x64-musl.zip',
|
||||
'linux-musl-x64-baseline': 'bun-linux-x64-musl-baseline.zip',
|
||||
'linux-musl-arm64': 'bun-linux-aarch64-musl.zip'
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads and extracts the bun binary for the specified platform and architecture
|
||||
* @param {string} platform Platform to download for (e.g., 'darwin', 'win32', 'linux')
|
||||
* @param {string} arch Architecture to download for (e.g., 'x64', 'arm64')
|
||||
* @param {string} version Version of bun to download
|
||||
* @param {boolean} isMusl Whether to use MUSL variant for Linux
|
||||
* @param {boolean} isBaseline Whether to use baseline variant
|
||||
*/
|
||||
async function downloadBunBinary(bun_download_url,platform, arch, version = DEFAULT_BUN_VERSION, isMusl = false, isBaseline = false) {
|
||||
let platformKey = isMusl ? `${platform}-musl-${arch}` : `${platform}-${arch}`
|
||||
if (isBaseline) {
|
||||
platformKey += '-baseline'
|
||||
}
|
||||
const packageName = BUN_PACKAGES[platformKey]
|
||||
|
||||
if (!packageName) {
|
||||
console.error(`No binary available for ${platformKey}`)
|
||||
return false
|
||||
}
|
||||
|
||||
// Create output directory structure
|
||||
const binDir = path.join(os.homedir(), '.eigent', 'bin')
|
||||
// Ensure directories exist
|
||||
fs.mkdirSync(binDir, { recursive: true })
|
||||
|
||||
// Download URL for the specific binary
|
||||
const downloadUrl = `${bun_download_url}/bun-v${version}/${packageName}`
|
||||
const tempdir = os.tmpdir()
|
||||
// Create a temporary file for the downloaded binary
|
||||
const tempFilename = path.join(tempdir, packageName)
|
||||
|
||||
try {
|
||||
console.log(`Downloading bun ${version} for ${platformKey}...`)
|
||||
console.log(`URL: ${downloadUrl}`)
|
||||
|
||||
// Use the new download function
|
||||
await downloadWithRedirects(downloadUrl, tempFilename)
|
||||
|
||||
// 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}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
fs.unlinkSync(tempFilename)
|
||||
fs.rmSync(sourceDir, { recursive: true })
|
||||
|
||||
console.log(`Successfully installed bun ${version} for ${platformKey}`)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error(`Error installing bun for ${platformKey}: ${error.message}`)
|
||||
// Clean up temporary file if it exists
|
||||
if (fs.existsSync(tempFilename)) {
|
||||
fs.unlinkSync(tempFilename)
|
||||
}
|
||||
|
||||
// Check if binDir is empty and remove it if so
|
||||
try {
|
||||
const files = fs.readdirSync(binDir)
|
||||
if (files.length === 0) {
|
||||
fs.rmSync(binDir, { recursive: true })
|
||||
console.log(`Removed empty directory: ${binDir}`)
|
||||
}
|
||||
} catch (cleanupError) {
|
||||
console.warn(`Warning: Failed to clean up directory: ${cleanupError.message}`)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects current platform and architecture
|
||||
*/
|
||||
function detectPlatformAndArch() {
|
||||
const platform = os.platform()
|
||||
const arch = os.arch()
|
||||
const isMusl = platform === 'linux' && detectIsMusl()
|
||||
const isBaseline = platform === 'win32'
|
||||
|
||||
return { platform, arch, isMusl, isBaseline }
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to detect if running on MUSL libc
|
||||
*/
|
||||
function detectIsMusl() {
|
||||
try {
|
||||
// Simple check for Alpine Linux which uses MUSL
|
||||
const output = execSync('cat /etc/os-release').toString()
|
||||
return output.toLowerCase().includes('alpine')
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function to install bun
|
||||
*/
|
||||
async function installBun() {
|
||||
// Get the latest version if no specific version is provided
|
||||
const version = DEFAULT_BUN_VERSION
|
||||
console.log(`Using bun version: ${version}`)
|
||||
|
||||
const { platform, arch, isMusl, isBaseline } = detectPlatformAndArch()
|
||||
|
||||
console.log(
|
||||
`Installing bun ${version} for ${platform}-${arch}${isMusl ? ' (MUSL)' : ''}${isBaseline ? ' (baseline)' : ''}...`
|
||||
)
|
||||
|
||||
const isInstalled = await downloadBunBinary(BUN_RELEASE_BASE_URL,platform, arch, version, isMusl, isBaseline)
|
||||
if(!isInstalled){
|
||||
console.log('Downloading bun from gitcode.com')
|
||||
await downloadBunBinary('https://gitcode.com/CherryHQ/bun/releases/download',platform, arch, version, isMusl, isBaseline)
|
||||
}
|
||||
}
|
||||
|
||||
// Run the installation
|
||||
installBun()
|
||||
.then(() => {
|
||||
console.log('Installation successful')
|
||||
process.exit(0)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Installation failed:', error)
|
||||
process.exit(1)
|
||||
})
|
||||
216
resources/scripts/install-uv.js
Normal file
216
resources/scripts/install-uv.js
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
// @ts-check
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import { execSync } from "child_process";
|
||||
import * as tar from "tar";
|
||||
import AdmZip from "adm-zip";
|
||||
import { downloadWithRedirects } from "./download.js";
|
||||
|
||||
// Base URL for downloading uv binaries
|
||||
const UV_RELEASE_BASE_URL = "https://github.com/astral-sh/uv/releases/download";
|
||||
const DEFAULT_UV_VERSION = "0.6.14";
|
||||
|
||||
// Mapping of platform+arch to binary package name
|
||||
const UV_PACKAGES = {
|
||||
"darwin-arm64": "uv-aarch64-apple-darwin.tar.gz",
|
||||
"darwin-x64": "uv-x86_64-apple-darwin.tar.gz",
|
||||
"win32-arm64": "uv-aarch64-pc-windows-msvc.zip",
|
||||
"win32-ia32": "uv-i686-pc-windows-msvc.zip",
|
||||
"win32-x64": "uv-x86_64-pc-windows-msvc.zip",
|
||||
"linux-arm64": "uv-aarch64-unknown-linux-gnu.tar.gz",
|
||||
"linux-ia32": "uv-i686-unknown-linux-gnu.tar.gz",
|
||||
"linux-ppc64": "uv-powerpc64-unknown-linux-gnu.tar.gz",
|
||||
"linux-ppc64le": "uv-powerpc64le-unknown-linux-gnu.tar.gz",
|
||||
"linux-s390x": "uv-s390x-unknown-linux-gnu.tar.gz",
|
||||
"linux-x64": "uv-x86_64-unknown-linux-gnu.tar.gz",
|
||||
"linux-armv7l": "uv-armv7-unknown-linux-gnueabihf.tar.gz",
|
||||
// MUSL variants
|
||||
"linux-musl-arm64": "uv-aarch64-unknown-linux-musl.tar.gz",
|
||||
"linux-musl-ia32": "uv-i686-unknown-linux-musl.tar.gz",
|
||||
"linux-musl-x64": "uv-x86_64-unknown-linux-musl.tar.gz",
|
||||
"linux-musl-armv6l": "uv-arm-unknown-linux-musleabihf.tar.gz",
|
||||
"linux-musl-armv7l": "uv-armv7-unknown-linux-musleabihf.tar.gz",
|
||||
};
|
||||
|
||||
/**
|
||||
* Downloads and extracts the uv binary for the specified platform and architecture
|
||||
* @param {string} platform Platform to download for (e.g., 'darwin', 'win32', 'linux')
|
||||
* @param {string} arch Architecture to download for (e.g., 'x64', 'arm64')
|
||||
* @param {string} version Version of uv to download
|
||||
* @param {boolean} isMusl Whether to use MUSL variant for Linux
|
||||
*/
|
||||
async function downloadUvBinary(
|
||||
uv_download_url,
|
||||
platform,
|
||||
arch,
|
||||
version = DEFAULT_UV_VERSION,
|
||||
isMusl = false
|
||||
) {
|
||||
console.log('[START] downloadUvBinary:', uv_download_url);
|
||||
const platformKey = isMusl
|
||||
? `${platform}-musl-${arch}`
|
||||
: `${platform}-${arch}`;
|
||||
const packageName = UV_PACKAGES[platformKey];
|
||||
|
||||
if (!packageName) {
|
||||
console.error(`No binary available for ${platformKey}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create output directory structure
|
||||
const binDir = path.join(os.homedir(), ".eigent", "bin");
|
||||
// Ensure directories exist
|
||||
fs.mkdirSync(binDir, { recursive: true });
|
||||
|
||||
// Download URL for the specific binary
|
||||
const downloadUrl = `${uv_download_url}/${version}/${packageName}`;
|
||||
const tempdir = os.tmpdir();
|
||||
const tempFilename = path.join(tempdir, packageName);
|
||||
|
||||
try {
|
||||
console.log(`Downloading uv ${version} for ${platformKey}...`);
|
||||
console.log(`URL: ${downloadUrl}`);
|
||||
|
||||
await downloadWithRedirects(downloadUrl, tempFilename);
|
||||
|
||||
console.log(`Extracting ${packageName} to ${binDir}...`);
|
||||
|
||||
if (packageName.endsWith(".zip")) {
|
||||
// use adm-zip to handle zip file
|
||||
const zip = new AdmZip(tempFilename);
|
||||
zip.extractAllTo(binDir, true);
|
||||
fs.unlinkSync(tempFilename);
|
||||
console.log(
|
||||
`Successfully installed uv ${version} for ${platform}-${arch}`
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
// handle tar.gz file
|
||||
await tar.x({
|
||||
file: tempFilename,
|
||||
cwd: tempdir,
|
||||
z: 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 {
|
||||
fs.chmodSync(destPath, "755");
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`Warning: Failed to set executable permissions: ${error.message}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
fs.unlinkSync(tempFilename);
|
||||
fs.rmSync(sourceDir, { recursive: true });
|
||||
}
|
||||
|
||||
console.log(`Successfully installed uv ${version} for ${platform}-${arch}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(`Error installing uv for ${platformKey}: ${error.message}`);
|
||||
if (fs.existsSync(tempFilename)) {
|
||||
fs.unlinkSync(tempFilename);
|
||||
}
|
||||
|
||||
// Check if binDir is empty and remove it if so
|
||||
try {
|
||||
const files = fs.readdirSync(binDir);
|
||||
if (files.length === 0) {
|
||||
fs.rmSync(binDir, { recursive: true });
|
||||
console.log(`Removed empty directory: ${binDir}`);
|
||||
}
|
||||
} catch (cleanupError) {
|
||||
console.warn(
|
||||
`Warning: Failed to clean up directory: ${cleanupError.message}`
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects current platform and architecture
|
||||
*/
|
||||
function detectPlatformAndArch() {
|
||||
const platform = os.platform();
|
||||
const arch = os.arch();
|
||||
const isMusl = platform === "linux" && detectIsMusl();
|
||||
|
||||
return { platform, arch, isMusl };
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to detect if running on MUSL libc
|
||||
*/
|
||||
function detectIsMusl() {
|
||||
try {
|
||||
// Simple check for Alpine Linux which uses MUSL
|
||||
const output = execSync("cat /etc/os-release").toString();
|
||||
return output.toLowerCase().includes("alpine");
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function to install uv
|
||||
*/
|
||||
async function installUv() {
|
||||
// Get the latest version if no specific version is provided
|
||||
const version = DEFAULT_UV_VERSION;
|
||||
console.log(`Using uv version: ${version}`);
|
||||
|
||||
const { platform, arch, isMusl } = detectPlatformAndArch();
|
||||
|
||||
console.log(
|
||||
`Installing uv ${version} for ${platform}-${arch}${
|
||||
isMusl ? " (MUSL)" : ""
|
||||
}...`
|
||||
);
|
||||
|
||||
let isInstalled = await downloadUvBinary(
|
||||
UV_RELEASE_BASE_URL,
|
||||
platform,
|
||||
arch,
|
||||
version,
|
||||
isMusl
|
||||
);
|
||||
if (!isInstalled) {
|
||||
console.log("Downloading uv from gitcode.com");
|
||||
isInstalled = await downloadUvBinary(
|
||||
"https://gitcode.com/CherryHQ/uv/releases/download",
|
||||
platform,
|
||||
arch,
|
||||
version,
|
||||
isMusl
|
||||
);
|
||||
console.log("Downloading uv from gitcode.com ####", isInstalled);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the installation
|
||||
installUv()
|
||||
.then(() => {
|
||||
console.log("Installation successful");
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Installation failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue