Skip to content

Commit

Permalink
Merge pull request #102 from pieces-app/feat-1.3.0
Browse files Browse the repository at this point in the history
feat 1.3.0
  • Loading branch information
bishoy-at-pieces authored Dec 18, 2024
2 parents a9e9ae3 + 07ac63d commit 081e9e3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 37 deletions.
5 changes: 0 additions & 5 deletions lua/pieces/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
4 changes: 2 additions & 2 deletions rplugin/python3/pieces_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rplugin/python3/pieces_python/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.1"
__version__ = "1.3.0"
2 changes: 1 addition & 1 deletion rplugin/python3/pieces_python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 5 additions & 7 deletions rplugin/python3/pieces_python/settings.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
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
import urllib.request
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):
Expand All @@ -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",
Expand Down
32 changes: 12 additions & 20 deletions rplugin/python3/pieces_python/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
26 changes: 25 additions & 1 deletion rplugin/python3/pieces_python/utils.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 081e9e3

Please sign in to comment.