This repository was archived by the owner on Jun 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
Use updates.codegate.ai for /versions instead of GitHub #1264
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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 |
---|---|---|
|
@@ -59,6 +59,10 @@ class Config: | |
server_key: str = "server.key" | ||
force_certs: bool = False | ||
|
||
# Update configuration. | ||
use_update_service: bool = False | ||
update_service_url: str = "https://updates.codegate.ai/api/v1/version" | ||
|
||
max_fim_hash_lifetime: int = 60 * 5 # Time in seconds. Default is 5 minutes. | ||
|
||
# Min value is 0 (max similarity), max value is 2 (orthogonal) | ||
|
@@ -165,6 +169,8 @@ def from_file(cls, config_path: Union[str, Path]) -> "Config": | |
force_certs=config_data.get("force_certs", cls.force_certs), | ||
prompts=prompts_config, | ||
provider_urls=provider_urls, | ||
use_update_service=config_data.get("use_update_service", cls.use_update_service), | ||
update_service_url=config_data.get("update_service_url", cls.update_service_url), | ||
) | ||
except yaml.YAMLError as e: | ||
raise ConfigurationError(f"Failed to parse config file: {e}") | ||
|
@@ -209,11 +215,17 @@ def from_env(cls) -> "Config": | |
if "CODEGATE_SERVER_KEY" in os.environ: | ||
config.server_key = os.environ["CODEGATE_SERVER_KEY"] | ||
if "CODEGATE_FORCE_CERTS" in os.environ: | ||
config.force_certs = os.environ["CODEGATE_FORCE_CERTS"] | ||
config.force_certs = cls.__bool_from_string(os.environ["CODEGATE_FORCE_CERTS"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix for a bug I spotted while working on this part of the code: |
||
if "CODEGATE_DB_PATH" in os.environ: | ||
config.db_path = os.environ["CODEGATE_DB_PATH"] | ||
if "CODEGATE_VEC_DB_PATH" in os.environ: | ||
config.vec_db_path = os.environ["CODEGATE_VEC_DB_PATH"] | ||
if "CODEGATE_USE_UPDATE_SERVICE" in os.environ: | ||
config.use_update_service = cls.__bool_from_string( | ||
os.environ["CODEGATE_USE_UPDATE_SERVICE"] | ||
) | ||
if "CODEGATE_UPDATE_SERVICE_URL" in os.environ: | ||
config.update_service_url = os.environ["CODEGATE_UPDATE_SERVICE_URL"] | ||
|
||
# Load provider URLs from environment variables | ||
for provider in DEFAULT_PROVIDER_URLS.keys(): | ||
|
@@ -246,6 +258,8 @@ def load( | |
force_certs: Optional[bool] = None, | ||
db_path: Optional[str] = None, | ||
vec_db_path: Optional[str] = None, | ||
use_update_service: Optional[bool] = None, | ||
update_service_url: Optional[str] = None, | ||
) -> "Config": | ||
"""Load configuration with priority resolution. | ||
|
||
|
@@ -274,6 +288,8 @@ def load( | |
force_certs: Optional flag to force certificate generation | ||
db_path: Optional path to the main SQLite database file | ||
vec_db_path: Optional path to the vector SQLite database file | ||
use_update_service: Optional flag to enable the update service | ||
update_service_url: Optional URL for the update service | ||
|
||
Returns: | ||
Config: Resolved configuration | ||
|
@@ -326,6 +342,10 @@ def load( | |
config.db_path = env_config.db_path | ||
if "CODEGATE_VEC_DB_PATH" in os.environ: | ||
config.vec_db_path = env_config.vec_db_path | ||
if "CODEGATE_USE_UPDATE_SERVICE" in os.environ: | ||
config.use_update_service = env_config.use_update_service | ||
if "CODEGATE_UPDATE_SERVICE_URL" in os.environ: | ||
config.update_service_url = env_config.update_service_url | ||
|
||
# Override provider URLs from environment | ||
for provider, url in env_config.provider_urls.items(): | ||
|
@@ -366,6 +386,10 @@ def load( | |
config.vec_db_path = vec_db_path | ||
if force_certs is not None: | ||
config.force_certs = force_certs | ||
if use_update_service is not None: | ||
config.use_update_service = use_update_service | ||
if update_service_url is not None: | ||
config.update_service_url = update_service_url | ||
|
||
# Set the __config class attribute | ||
Config.__config = config | ||
|
@@ -375,3 +399,7 @@ def load( | |
@classmethod | ||
def get_config(cls) -> "Config": | ||
return cls.__config | ||
|
||
@staticmethod | ||
def __bool_from_string(raw_value) -> bool: | ||
return raw_value.lower() == "true" |
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,54 @@ | ||
from enum import Enum | ||
|
||
import cachetools.func | ||
import requests | ||
import structlog | ||
|
||
from codegate.db.connection import DbReader | ||
|
||
logger = structlog.get_logger("codegate") | ||
|
||
|
||
# Enum representing whether the request is coming from the front-end or the back-end. | ||
class Origin(Enum): | ||
FrontEnd = "FE" | ||
BackEnd = "BE" | ||
|
||
|
||
class UpdateClient: | ||
def __init__(self, update_url: str, current_version: str, db_reader: DbReader): | ||
self.__update_url = update_url | ||
self.__current_version = current_version | ||
self.__db_reader = db_reader | ||
self.__instance_id = None | ||
|
||
async def get_latest_version(self, origin: Origin) -> str: | ||
""" | ||
Retrieves the latest version of CodeGate from updates.codegate.ai | ||
""" | ||
logger.info(f"Fetching latest version from {self.__update_url}") | ||
instance_id = await self.__get_instance_id() | ||
return self.__fetch_latest_version(instance_id, origin) | ||
|
||
@cachetools.func.ttl_cache(maxsize=128, ttl=20 * 60) | ||
def __fetch_latest_version(self, instance_id: str, origin: Origin) -> str: | ||
headers = { | ||
"X-Instance-ID": instance_id, | ||
"User-Agent": f"codegate/{self.__current_version} {origin.value}", | ||
} | ||
|
||
try: | ||
response = requests.get(self.__update_url, headers=headers, timeout=10) | ||
# Throw if the request was not successful. | ||
response.raise_for_status() | ||
return response.json()["version"] | ||
except Exception as e: | ||
logger.error(f"Error fetching latest version from f{self.__update_url}: {e}") | ||
return "unknown" | ||
|
||
# Lazy load the instance ID from the DB. | ||
async def __get_instance_id(self): | ||
if self.__instance_id is None: | ||
instance_data = await self.__db_reader.get_instance() | ||
self.__instance_id = instance_data[0].id | ||
return self.__instance_id |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes like this were the result of applying the linter.