diff --git a/lua/pieces/config.lua b/lua/pieces/config.lua index 9f4bc63..c7c8716 100644 --- a/lua/pieces/config.lua +++ b/lua/pieces/config.lua @@ -17,11 +17,6 @@ end local config = {} config.os = get_os() -if config.os == "WINDOW" or config.os == "MACOS" then - config.host = "http://localhost:1000" -else - config.host = "http://localhost:5323" -end diff --git a/rplugin/python3/pieces_python/__init__.py b/rplugin/python3/pieces_python/__init__.py index 5048aaf..1fe3960 100644 --- a/rplugin/python3/pieces_python/__init__.py +++ b/rplugin/python3/pieces_python/__init__.py @@ -5,7 +5,7 @@ def update_sdks(): pip.main(["install","pieces_os_client","--upgrade"]) - +MIN_SDKS_VERSION = "4.1.0" try: from pieces_os_client import __version__ as pieces_os_client_version @@ -16,7 +16,7 @@ def update_sdks(): update_sdks() raise ModuleNotFoundError - if VersionChecker.compare(pieces_os_client_version,"4.0.3") < 0: # We need to be above 4.0.0 + if VersionChecker.compare(pieces_os_client_version,MIN_SDKS_VERSION) < 0: # We need to be above 4.0.0 update_sdks() raise ModuleNotFoundError from .main import Pieces diff --git a/rplugin/python3/pieces_python/_version.py b/rplugin/python3/pieces_python/_version.py index 182d923..4e3d205 100644 --- a/rplugin/python3/pieces_python/_version.py +++ b/rplugin/python3/pieces_python/_version.py @@ -1 +1 @@ -__version__ = "1.2.1" +__version__ = "1.3.0" diff --git a/rplugin/python3/pieces_python/main.py b/rplugin/python3/pieces_python/main.py index 54c7b1b..e9debf8 100644 --- a/rplugin/python3/pieces_python/main.py +++ b/rplugin/python3/pieces_python/main.py @@ -121,7 +121,7 @@ def add_context(self,args): ) @pynvim.function("PiecesOpenPiecesOS", sync=True) def open_pieces_function(self, args = None): - if Settings.is_loaded: return True + if Settings.api_client.is_pos_stream_running: return True started = self.api_client.open_pieces_os() if started: BaseWebsocket.start_all() diff --git a/rplugin/python3/pieces_python/settings.py b/rplugin/python3/pieces_python/settings.py index 89bbc71..6ee5cf6 100644 --- a/rplugin/python3/pieces_python/settings.py +++ b/rplugin/python3/pieces_python/settings.py @@ -1,6 +1,8 @@ +from typing import Optional from pieces_os_client.wrapper import PiecesClient from pieces_os_client.models.seeded_connector_connection import SeededConnectorConnection from pieces_os_client.models.seeded_tracked_application import SeededTrackedApplication +from pieces_os_client.wrapper.version_compatibility import VersionCheckResult from ._version import __version__ import pynvim import json @@ -8,14 +10,15 @@ import os + class Settings: # Initialize class variables nvim:pynvim.Nvim host = "" - is_loaded = False os:str api_client:PiecesClient + version_compatibility: Optional[VersionCheckResult] = None @classmethod def set_model_name(cls,value): @@ -38,12 +41,7 @@ def load_config(cls) -> None: setattr(cls,config,out) # Setting up the host and the os - if not cls.host: - if 'linux' == cls.os: - cls.host = "http://127.0.0.1:5323" - else: - cls.host = "http://127.0.0.1:1000" - cls.api_client = PiecesClient(cls.host, + cls.api_client = PiecesClient( seeded_connector=SeededConnectorConnection( application=SeededTrackedApplication( name = "VIM", diff --git a/rplugin/python3/pieces_python/startup.py b/rplugin/python3/pieces_python/startup.py index 11696e5..93b2911 100644 --- a/rplugin/python3/pieces_python/startup.py +++ b/rplugin/python3/pieces_python/startup.py @@ -14,11 +14,10 @@ from pieces_os_client.models.conversation import Conversation from pieces_os_client.models.asset import Asset from .file_map import file_map -from .utils import on_copilot_message +from .utils import check_compatibility, on_copilot_message + -PIECES_OS_MIN_VERSION = "10.1.12" # Minium version (10.1.12) -PIECES_OS_MAX_VERSION = "11.0.0" # Maxium version (11.0.0) class Startup: @classmethod @@ -37,44 +36,37 @@ def startup(cls): AuthWS(Settings.api_client, Auth.on_user_callback) AssetsIdentifiersWS(Settings.api_client,cls.update_lua_assets,cls.delete_lua_asset) ConversationWS(Settings.api_client,cls.update_lua_conversations,cls.delete_lua_conversation) - health_ws = HealthWS(Settings.api_client, cls.on_message, cls.on_startup, on_close=lambda x,y,z:cls.on_close()) + health_ws = HealthWS(Settings.api_client, cls.on_message, cls.on_startup,on_close=lambda x,y,z: cls.on_close()) if Settings.api_client.is_pieces_running(): health_ws.start() - else: - Settings.is_loaded = False @classmethod def on_message(cls, message): - if message == "OK": - Settings.is_loaded = True - else: - Settings.is_loaded = False + pass + + @staticmethod + def on_close(): + Settings.api_client.is_pos_stream_running = False @classmethod def on_startup(cls, ws): - result = VersionChecker(PIECES_OS_MIN_VERSION, - PIECES_OS_MAX_VERSION, - Settings.api_client.version).version_check() - if result.compatible: + compatiable = check_compatibility() + if compatiable: if not Settings.load_settings().get("version"): Settings.update_settings(version=__version__) + if Settings.load_settings().get("version") != __version__: Settings.nvim.async_call(Settings.nvim.command, 'call PiecesRunRemotePlugins()') Settings.update_settings(version = __version__) + Settings.api_client.model_name = Settings.load_settings().get("model_name","GPT-4o Chat Model") BaseWebsocket.start_all() Settings.api_client.copilot.ask_stream_ws.on_message_callback = on_copilot_message Settings.api_client.copilot._return_on_message = lambda: None else: - Settings.is_loaded = False BaseWebsocket.close_all() - plugin = "Pieces OS" if result.update == UpdateEnum.PiecesOS else "the Neovim Pieces plugin" - Settings.nvim.async_call(Settings.nvim.err_write, f"Please update {plugin}\n") - @staticmethod - def on_close(): - Settings.is_loaded = False @classmethod def update_lua_assets(cls,asset:Asset): diff --git a/rplugin/python3/pieces_python/utils.py b/rplugin/python3/pieces_python/utils.py index 2236206..9fd97e9 100644 --- a/rplugin/python3/pieces_python/utils.py +++ b/rplugin/python3/pieces_python/utils.py @@ -1,9 +1,13 @@ from pieces_os_client.wrapper.basic_identifier.chat import BasicChat from pieces_os_client.wrapper.websockets import HealthWS +from pieces_os_client.wrapper.version_compatibility import UpdateEnum, VersionChecker from .settings import Settings import os import webbrowser +PIECES_OS_MIN_VERSION = "11.0.0" # Minium version (11.0.0) +PIECES_OS_MAX_VERSION = "12.0.0" # Maxium version (12.0.0) + def convert_to_lua_table(python_dict): """ Convert a Python dictionary to a Lua table representation. @@ -58,10 +62,30 @@ def on_copilot_message(message): """) return # TODO: Add a better error message +def check_compatibility(notify_if_pos_off = False): + if not Settings.version_compatibility: + if not Settings.api_client.is_pieces_running(): + if notify_if_pos_off: Settings.nvim.exec_lua("require('pieces.utils').notify_pieces_os()") + return False + + Settings.version_compatibility = VersionChecker( + PIECES_OS_MIN_VERSION, + PIECES_OS_MAX_VERSION, + Settings.api_client.version).version_check() + + if not Settings.version_compatibility.compatible: + plugin = "Pieces OS" if Settings.version_compatibility.update == UpdateEnum.PiecesOS else "the Neovim Pieces plugin" + Settings.nvim.async_call(Settings.nvim.err_write, f"Please update {plugin}\n") + return False + else: + return True def is_pieces_opened(func): def wrapper(*args, **kwargs): - if Settings.is_loaded: + if not check_compatibility(True): + return + + if Settings.api_client.is_pos_stream_running: return func(*args, **kwargs) else: # Run the health request to check if the server is running