From 77add9046c197c31255ee0f25480e5ce8b219b2f Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Wed, 18 Dec 2024 00:31:46 +0200 Subject: [PATCH 1/5] feat 1.3.0 --- lua/pieces/config.lua | 5 ----- rplugin/python3/pieces_python/__init__.py | 4 ++-- rplugin/python3/pieces_python/main.py | 2 +- rplugin/python3/pieces_python/settings.py | 8 +------- rplugin/python3/pieces_python/startup.py | 13 ++----------- rplugin/python3/pieces_python/utils.py | 2 +- 6 files changed, 7 insertions(+), 27 deletions(-) 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/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..2a75f24 100644 --- a/rplugin/python3/pieces_python/settings.py +++ b/rplugin/python3/pieces_python/settings.py @@ -12,7 +12,6 @@ class Settings: # Initialize class variables nvim:pynvim.Nvim host = "" - is_loaded = False os:str api_client:PiecesClient @@ -38,12 +37,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 2ee5d83..46baa7f 100644 --- a/rplugin/python3/pieces_python/startup.py +++ b/rplugin/python3/pieces_python/startup.py @@ -37,18 +37,13 @@ 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) 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 @classmethod def on_startup(cls, ws): @@ -66,14 +61,10 @@ def on_startup(cls, ws): 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..b9f6052 100644 --- a/rplugin/python3/pieces_python/utils.py +++ b/rplugin/python3/pieces_python/utils.py @@ -61,7 +61,7 @@ def on_copilot_message(message): def is_pieces_opened(func): def wrapper(*args, **kwargs): - if Settings.is_loaded: + if Settings.api_client.is_pos_stream_running: return func(*args, **kwargs) else: # Run the health request to check if the server is running From 3207335ea65177cf0d2ed8e25378c9c805df2025 Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Wed, 18 Dec 2024 00:39:21 +0200 Subject: [PATCH 2/5] bump POS version --- rplugin/python3/pieces_python/_version.py | 2 +- rplugin/python3/pieces_python/startup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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/startup.py b/rplugin/python3/pieces_python/startup.py index 46baa7f..59865e1 100644 --- a/rplugin/python3/pieces_python/startup.py +++ b/rplugin/python3/pieces_python/startup.py @@ -17,8 +17,8 @@ from .utils import 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) +PIECES_OS_MIN_VERSION = "11.0.0" # Minium version (11.0.0) +PIECES_OS_MAX_VERSION = "12.0.0" # Maxium version (12.0.0) class Startup: @classmethod From b67cd45398bae79cf8b34aef507654a3671dd909 Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Wed, 18 Dec 2024 19:42:04 +0200 Subject: [PATCH 3/5] fix version compatibility check --- rplugin/python3/pieces_python/settings.py | 2 ++ rplugin/python3/pieces_python/startup.py | 6 +++--- rplugin/python3/pieces_python/utils.py | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/rplugin/python3/pieces_python/settings.py b/rplugin/python3/pieces_python/settings.py index 2a75f24..3e78b1c 100644 --- a/rplugin/python3/pieces_python/settings.py +++ b/rplugin/python3/pieces_python/settings.py @@ -1,6 +1,7 @@ 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 @@ -15,6 +16,7 @@ class Settings: os:str api_client:PiecesClient + version_compatibility: VersionCheckResult @classmethod def set_model_name(cls,value): diff --git a/rplugin/python3/pieces_python/startup.py b/rplugin/python3/pieces_python/startup.py index 59865e1..7ef095f 100644 --- a/rplugin/python3/pieces_python/startup.py +++ b/rplugin/python3/pieces_python/startup.py @@ -47,10 +47,10 @@ def on_message(cls, message): @classmethod def on_startup(cls, ws): - result = VersionChecker(PIECES_OS_MIN_VERSION, + Settings.version_compatibility = VersionChecker(PIECES_OS_MIN_VERSION, PIECES_OS_MAX_VERSION, Settings.api_client.version).version_check() - if result.compatible: + if Settings.version_compatibility.compatible: if not Settings.load_settings().get("version"): Settings.update_settings(version=__version__) if Settings.load_settings().get("version") != __version__: @@ -62,7 +62,7 @@ def on_startup(cls, ws): Settings.api_client.copilot._return_on_message = lambda: None else: BaseWebsocket.close_all() - plugin = "Pieces OS" if result.update == UpdateEnum.PiecesOS else "the Neovim Pieces plugin" + 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") diff --git a/rplugin/python3/pieces_python/utils.py b/rplugin/python3/pieces_python/utils.py index b9f6052..1c69c7e 100644 --- a/rplugin/python3/pieces_python/utils.py +++ b/rplugin/python3/pieces_python/utils.py @@ -1,5 +1,6 @@ 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 from .settings import Settings import os import webbrowser @@ -61,6 +62,11 @@ def on_copilot_message(message): def is_pieces_opened(func): def wrapper(*args, **kwargs): + if Settings.version_compatibility: + 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 + if Settings.api_client.is_pos_stream_running: return func(*args, **kwargs) else: From 813baaec1113ac272889022799d83bf593a258dc Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Wed, 18 Dec 2024 19:46:05 +0200 Subject: [PATCH 4/5] fix multi version check --- rplugin/python3/pieces_python/startup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rplugin/python3/pieces_python/startup.py b/rplugin/python3/pieces_python/startup.py index 7ef095f..d774467 100644 --- a/rplugin/python3/pieces_python/startup.py +++ b/rplugin/python3/pieces_python/startup.py @@ -53,8 +53,10 @@ def on_startup(cls, ws): if Settings.version_compatibility.compatible: 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() From 87110dc299f6d23fd3f5ad1a63038962f16ebcc8 Mon Sep 17 00:00:00 2001 From: bishoy-at-pieces Date: Wed, 18 Dec 2024 21:39:26 +0200 Subject: [PATCH 5/5] fix hanging if POS is not running --- rplugin/python3/pieces_python/settings.py | 4 +++- rplugin/python3/pieces_python/startup.py | 19 ++++++++--------- rplugin/python3/pieces_python/utils.py | 26 +++++++++++++++++++---- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/rplugin/python3/pieces_python/settings.py b/rplugin/python3/pieces_python/settings.py index 3e78b1c..6ee5cf6 100644 --- a/rplugin/python3/pieces_python/settings.py +++ b/rplugin/python3/pieces_python/settings.py @@ -1,3 +1,4 @@ +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 @@ -9,6 +10,7 @@ import os + class Settings: # Initialize class variables nvim:pynvim.Nvim @@ -16,7 +18,7 @@ class Settings: os:str api_client:PiecesClient - version_compatibility: VersionCheckResult + version_compatibility: Optional[VersionCheckResult] = None @classmethod def set_model_name(cls,value): diff --git a/rplugin/python3/pieces_python/startup.py b/rplugin/python3/pieces_python/startup.py index d774467..8ac2bef 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 = "11.0.0" # Minium version (11.0.0) -PIECES_OS_MAX_VERSION = "12.0.0" # Maxium version (12.0.0) class Startup: @classmethod @@ -37,7 +36,7 @@ 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) + 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() @@ -45,12 +44,14 @@ def startup(cls): def on_message(cls, message): pass + @staticmethod + def on_close(): + Settings.api_client.is_pos_stream_running = False + @classmethod def on_startup(cls, ws): - Settings.version_compatibility = VersionChecker(PIECES_OS_MIN_VERSION, - PIECES_OS_MAX_VERSION, - Settings.api_client.version).version_check() - if Settings.version_compatibility.compatible: + compatiable = check_compatibility() + if compatiable: if not Settings.load_settings().get("version"): Settings.update_settings(version=__version__) @@ -64,8 +65,6 @@ def on_startup(cls, ws): Settings.api_client.copilot._return_on_message = lambda: None else: BaseWebsocket.close_all() - 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") @classmethod diff --git a/rplugin/python3/pieces_python/utils.py b/rplugin/python3/pieces_python/utils.py index 1c69c7e..9fd97e9 100644 --- a/rplugin/python3/pieces_python/utils.py +++ b/rplugin/python3/pieces_python/utils.py @@ -1,10 +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 +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. @@ -59,12 +62,27 @@ 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.version_compatibility: - 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") + if not check_compatibility(True): return if Settings.api_client.is_pos_stream_running: