Merge pull request #77 from continuedev/update-notification
feat: notify of available updates
This commit is contained in:
commit
2ee4471df8
3 changed files with 94 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
|
||||
import { BaseLlmApi } from "@continuedev/openai-adapters";
|
||||
import { Box, Text } from "ink";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { loadAuthConfig } from "../auth/workos.js";
|
||||
import { initialize } from "../config.js";
|
||||
import { introMessage } from "../intro.js";
|
||||
|
|
@ -15,6 +15,7 @@ import { useOrganizationSelector } from "./hooks/useOrganizationSelector.js";
|
|||
import LoadingAnimation from "./LoadingAnimation.js";
|
||||
import OrganizationSelector from "./OrganizationSelector.js";
|
||||
import Timer from "./Timer.js";
|
||||
import UpdateNotification from "./UpdateNotification.js";
|
||||
import UserInput from "./UserInput.js";
|
||||
|
||||
interface TUIChatProps {
|
||||
|
|
@ -239,7 +240,15 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
onFileAttached={handleFileAttached}
|
||||
disabled={showOrgSelector || showConfigSelector || !!loginPrompt}
|
||||
/>
|
||||
<Box marginRight={2} justifyContent="flex-end">
|
||||
<Box
|
||||
marginRight={2}
|
||||
justifyContent="space-between"
|
||||
flexDirection="row"
|
||||
marginLeft={2}
|
||||
>
|
||||
<Box>
|
||||
<UpdateNotification />
|
||||
</Box>
|
||||
<Text color="gray">● Continue CLI</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
|
|
|
|||
40
src/ui/UpdateNotification.tsx
Normal file
40
src/ui/UpdateNotification.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { Text } from "ink";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { compareVersions, getLatestVersion, getVersion } from "../version.js";
|
||||
|
||||
const UpdateNotification: React.FC = () => {
|
||||
const [updateAvailable, setUpdateAvailable] = useState(false);
|
||||
const [latestVersion, setLatestVersion] = useState<string>("");
|
||||
const [currentVersion] = useState(getVersion());
|
||||
|
||||
useEffect(() => {
|
||||
const checkForUpdate = async () => {
|
||||
try {
|
||||
const latest = await getLatestVersion();
|
||||
if (latest) {
|
||||
setLatestVersion(latest);
|
||||
const comparison = compareVersions(currentVersion, latest);
|
||||
setUpdateAvailable(comparison === "older");
|
||||
}
|
||||
} catch (error) {
|
||||
// Silently fail - we don't want to interrupt the user experience
|
||||
console.debug("Failed to check for updates:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// Check for updates but don't block
|
||||
checkForUpdate();
|
||||
}, [currentVersion]);
|
||||
|
||||
if (!updateAvailable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Text color="dim">
|
||||
Update available: v{latestVersion} (npm i -g @continuedev/cli)
|
||||
</Text>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateNotification;
|
||||
|
|
@ -14,3 +14,46 @@ export function getVersion(): string {
|
|||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
export async function getLatestVersion(): Promise<string | null> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
"https://registry.npmjs.org/@continuedev/cli/latest"
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data.version;
|
||||
} catch (error) {
|
||||
console.warn("Warning: Could not fetch latest version from npm registry");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function compareVersions(
|
||||
current: string,
|
||||
latest: string
|
||||
): "newer" | "same" | "older" {
|
||||
if (current === "unknown" || latest === "unknown") {
|
||||
return "same";
|
||||
}
|
||||
|
||||
// Simple semantic version comparison
|
||||
const parseVersion = (version: string) => {
|
||||
const parts = version.replace(/^v/, "").split(".").map(part => parseInt(part, 10));
|
||||
return { major: parts[0] || 0, minor: parts[1] || 0, patch: parts[2] || 0 };
|
||||
};
|
||||
|
||||
const currentParts = parseVersion(current);
|
||||
const latestParts = parseVersion(latest);
|
||||
|
||||
if (currentParts.major > latestParts.major) return "newer";
|
||||
if (currentParts.major < latestParts.major) return "older";
|
||||
if (currentParts.minor > latestParts.minor) return "newer";
|
||||
if (currentParts.minor < latestParts.minor) return "older";
|
||||
if (currentParts.patch > latestParts.patch) return "newer";
|
||||
if (currentParts.patch < latestParts.patch) return "older";
|
||||
|
||||
return "same";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue