Skip to content

Commit

Permalink
feat(packages/qllm-cli/src): add axios import and update check for ne…
Browse files Browse the repository at this point in the history
…w version (#60)
  • Loading branch information
raphaelmansuy authored Sep 5, 2024
1 parent fea02c5 commit 06c3c0d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/qllm-cli/src/qllm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { readFileSync } from "fs";
import { IOManager } from "./utils/io-manager";
import { askCommandAction } from "./commands/ask-command";
import { chatAction } from "./commands/chat-command";
import axios from "axios"; // Add axios import

import path from "path";

Expand All @@ -24,8 +25,28 @@ const VERSION = packageJson.version;

const ioManager = new IOManager();

async function checkForUpdates(currentVersion: string) {
try {
const response = await axios.get(`https://registry.npmjs.org/qllm`, { timeout: 2000 });
const latestVersion = response.data["dist-tags"].latest;

if (latestVersion !== currentVersion) {
const message = `You are using qllm version ${VERSION}. A new version is available! 🎉 You can update to the latest version (${latestVersion}).\nRun: npm install -g qllm`;
ioManager.displayInfo(message);
}
} catch (_error) {
// Ignore errors
}
}

export async function main() {
try {
// Check for updates at startup
const random = Math.random();
if (random < 0.30) {
await checkForUpdates(VERSION);
}

const configManager = CliConfigManager.getInstance();

await configManager.ensureConfigFileExists();
Expand Down

0 comments on commit 06c3c0d

Please sign in to comment.