-
Notifications
You must be signed in to change notification settings - Fork 580
feat: add Node.js npx installation method and simplify setup process #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { execSync } from "child_process"; | ||
| import { chmodSync, createWriteStream } from "fs"; | ||
| import fetch from "node-fetch"; | ||
| import { tmpdir } from "os"; | ||
| import { join } from "path"; | ||
|
|
||
| const BASE_URL = "https://downloads.getmaxim.ai"; | ||
|
|
||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
| // Parse transport version from command line arguments | ||
| function parseTransportVersion() { | ||
| const args = process.argv.slice(2); | ||
| let transportVersion = "latest"; // Default to latest | ||
|
|
||
| // Find --transport-version argument | ||
| const versionArgIndex = args.findIndex(arg => arg.startsWith("--transport-version")); | ||
|
|
||
| if (versionArgIndex !== -1) { | ||
| const versionArg = args[versionArgIndex]; | ||
|
|
||
| if (versionArg.includes("=")) { | ||
| // Format: --transport-version=v1.2.3 | ||
| transportVersion = versionArg.split("=")[1]; | ||
| } else if (versionArgIndex + 1 < args.length) { | ||
| // Format: --transport-version v1.2.3 | ||
| transportVersion = args[versionArgIndex + 1]; | ||
| } | ||
|
|
||
| // Remove the transport-version arguments from args array so they don't get passed to the binary | ||
| if (versionArg.includes("=")) { | ||
| args.splice(versionArgIndex, 1); | ||
| } else { | ||
| args.splice(versionArgIndex, 2); | ||
| } | ||
| } | ||
|
|
||
| return { version: validateTransportVersion(transportVersion), remainingArgs: args }; | ||
| } | ||
|
|
||
| // Validate transport version format | ||
| function validateTransportVersion(version) { | ||
| if (version === "latest") { | ||
| return version; | ||
| } | ||
|
|
||
| // Check if version matches v{x.x.x} format | ||
| const versionRegex = /^v\d+\.\d+\.\d+$/; | ||
| if (versionRegex.test(version)) { | ||
| return version; | ||
| } | ||
|
|
||
| console.error(`Invalid transport version format: ${version}`); | ||
| console.error(`Transport version must be either "latest" or in format v1.2.3`); | ||
| process.exit(1); | ||
| } | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
|
|
||
| const { version: VERSION, remainingArgs } = parseTransportVersion(); | ||
|
|
||
| function getPlatformArchAndBinary() { | ||
| const platform = process.platform; | ||
| const arch = process.arch; | ||
|
|
||
| let platformDir; | ||
| let archDir; | ||
| let binaryName; | ||
|
|
||
| if (platform === "darwin") { | ||
| platformDir = "darwin"; | ||
| if (arch === "arm64") archDir = "arm64"; | ||
| else archDir = "amd64"; | ||
| binaryName = "bifrost-http"; | ||
| } else if (platform === "linux") { | ||
| platformDir = "linux"; | ||
| if (arch === "x64") archDir = "amd64"; | ||
| else if (arch === "ia32") archDir = "386"; | ||
| else archDir = arch; // fallback | ||
| binaryName = "bifrost-http"; | ||
| } else if (platform === "win32") { | ||
| platformDir = "windows"; | ||
| if (arch === "x64") archDir = "amd64"; | ||
| else if (arch === "ia32") archDir = "386"; | ||
| else archDir = arch; // fallback | ||
| binaryName = "bifrost-http.exe"; | ||
| } else { | ||
| console.error(`Unsupported platform/arch: ${platform}/${arch}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| return { platformDir, archDir, binaryName }; | ||
| } | ||
|
|
||
| async function downloadBinary(url, dest) { | ||
| const res = await fetch(url); | ||
|
|
||
| if (!res.ok) { | ||
| console.error(`Download failed: ${res.status} ${res.statusText}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const fileStream = createWriteStream(dest); | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
| await new Promise((resolve, reject) => { | ||
| res.body.pipe(fileStream); | ||
| res.body.on("error", reject); | ||
| fileStream.on("finish", resolve); | ||
| }); | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
|
|
||
| chmodSync(dest, 0o755); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
|
|
||
| (async () => { | ||
| const { platformDir, archDir, binaryName } = getPlatformArchAndBinary(); | ||
| const binaryPath = join(tmpdir(), binaryName); | ||
|
|
||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
| // The download URL now matches the CI pipeline's S3 structure with arch | ||
| // Example: https://downloads.getmaxim.ai/bifrost/latest/darwin/arm64/bifrost | ||
| const downloadUrl = `${BASE_URL}/bifrost/${VERSION}/${platformDir}/${archDir}/${binaryName}`; | ||
|
|
||
| try { | ||
| await downloadBinary(downloadUrl, binaryPath); | ||
| } catch (error) { | ||
| console.error(`❌ Failed to download binary from ${downloadUrl}:`, error.message); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Get command-line arguments to pass to the binary (excluding --transport-version) | ||
| const args = remainingArgs.join(" "); | ||
|
|
||
| // Execute the binary, forwarding the arguments | ||
| try { | ||
| execSync(`${binaryPath} ${args}`, { stdio: "inherit" }); | ||
| } catch (error) { | ||
| // The child process will have already printed its error message. | ||
| // Exit with the same status code as the child process. | ||
| process.exit(error.status || 1); | ||
| } | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
| })(); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "name": "@maximhq/bifrost", | ||
| "version": "1.0.1", | ||
| "description": "High-performance AI gateway CLI - connect to 10+ providers through a single API", | ||
| "keywords": ["ai", "gateway", "openai", "anthropic", "cli", "bifrost"], | ||
| "homepage": "https://github.com/maximhq/bifrost", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/maximhq/bifrost.git" | ||
| }, | ||
| "license": "Apache-2.0", | ||
| "author": "Maxim HQ", | ||
| "engines": { | ||
| "node": ">=18.0.0" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "bin": { | ||
| "bifrost": "bin.js" | ||
| }, | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
| "type": "module", | ||
| "dependencies": {} | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
| } | ||
|
Pratham-Mishra04 marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.