Skip to content

Commit 081e9e3

Browse files
Merge pull request #102 from pieces-app/feat-1.3.0
feat 1.3.0
2 parents a9e9ae3 + 07ac63d commit 081e9e3

File tree

7 files changed

+46
-37
lines changed

7 files changed

+46
-37
lines changed

lua/pieces/config.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ end
1717
local config = {}
1818

1919
config.os = get_os()
20-
if config.os == "WINDOW" or config.os == "MACOS" then
21-
config.host = "http://localhost:1000"
22-
else
23-
config.host = "http://localhost:5323"
24-
end
2520

2621

2722

rplugin/python3/pieces_python/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def update_sdks():
66
pip.main(["install","pieces_os_client","--upgrade"])
77

8-
8+
MIN_SDKS_VERSION = "4.1.0"
99
try:
1010
from pieces_os_client import __version__ as pieces_os_client_version
1111

@@ -16,7 +16,7 @@ def update_sdks():
1616
update_sdks()
1717
raise ModuleNotFoundError
1818

19-
if VersionChecker.compare(pieces_os_client_version,"4.0.3") < 0: # We need to be above 4.0.0
19+
if VersionChecker.compare(pieces_os_client_version,MIN_SDKS_VERSION) < 0: # We need to be above 4.0.0
2020
update_sdks()
2121
raise ModuleNotFoundError
2222
from .main import Pieces
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2.1"
1+
__version__ = "1.3.0"

rplugin/python3/pieces_python/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def add_context(self,args):
121121
)
122122
@pynvim.function("PiecesOpenPiecesOS", sync=True)
123123
def open_pieces_function(self, args = None):
124-
if Settings.is_loaded: return True
124+
if Settings.api_client.is_pos_stream_running: return True
125125
started = self.api_client.open_pieces_os()
126126
if started:
127127
BaseWebsocket.start_all()

rplugin/python3/pieces_python/settings.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
from typing import Optional
12
from pieces_os_client.wrapper import PiecesClient
23
from pieces_os_client.models.seeded_connector_connection import SeededConnectorConnection
34
from pieces_os_client.models.seeded_tracked_application import SeededTrackedApplication
5+
from pieces_os_client.wrapper.version_compatibility import VersionCheckResult
46
from ._version import __version__
57
import pynvim
68
import json
79
import urllib.request
810
import os
911

1012

13+
1114
class Settings:
1215
# Initialize class variables
1316
nvim:pynvim.Nvim
1417
host = ""
15-
is_loaded = False
1618
os:str
1719

1820
api_client:PiecesClient
21+
version_compatibility: Optional[VersionCheckResult] = None
1922

2023
@classmethod
2124
def set_model_name(cls,value):
@@ -38,12 +41,7 @@ def load_config(cls) -> None:
3841

3942
setattr(cls,config,out) # Setting up the host and the os
4043

41-
if not cls.host:
42-
if 'linux' == cls.os:
43-
cls.host = "http://127.0.0.1:5323"
44-
else:
45-
cls.host = "http://127.0.0.1:1000"
46-
cls.api_client = PiecesClient(cls.host,
44+
cls.api_client = PiecesClient(
4745
seeded_connector=SeededConnectorConnection(
4846
application=SeededTrackedApplication(
4947
name = "VIM",

rplugin/python3/pieces_python/startup.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
from pieces_os_client.models.conversation import Conversation
1515
from pieces_os_client.models.asset import Asset
1616
from .file_map import file_map
17-
from .utils import on_copilot_message
17+
from .utils import check_compatibility, on_copilot_message
18+
1819

1920

20-
PIECES_OS_MIN_VERSION = "10.1.12" # Minium version (10.1.12)
21-
PIECES_OS_MAX_VERSION = "11.0.0" # Maxium version (11.0.0)
2221

2322
class Startup:
2423
@classmethod
@@ -37,44 +36,37 @@ def startup(cls):
3736
AuthWS(Settings.api_client, Auth.on_user_callback)
3837
AssetsIdentifiersWS(Settings.api_client,cls.update_lua_assets,cls.delete_lua_asset)
3938
ConversationWS(Settings.api_client,cls.update_lua_conversations,cls.delete_lua_conversation)
40-
health_ws = HealthWS(Settings.api_client, cls.on_message, cls.on_startup, on_close=lambda x,y,z:cls.on_close())
39+
health_ws = HealthWS(Settings.api_client, cls.on_message, cls.on_startup,on_close=lambda x,y,z: cls.on_close())
4140
if Settings.api_client.is_pieces_running():
4241
health_ws.start()
43-
else:
44-
Settings.is_loaded = False
4542

4643
@classmethod
4744
def on_message(cls, message):
48-
if message == "OK":
49-
Settings.is_loaded = True
50-
else:
51-
Settings.is_loaded = False
45+
pass
46+
47+
@staticmethod
48+
def on_close():
49+
Settings.api_client.is_pos_stream_running = False
5250

5351
@classmethod
5452
def on_startup(cls, ws):
55-
result = VersionChecker(PIECES_OS_MIN_VERSION,
56-
PIECES_OS_MAX_VERSION,
57-
Settings.api_client.version).version_check()
58-
if result.compatible:
53+
compatiable = check_compatibility()
54+
if compatiable:
5955
if not Settings.load_settings().get("version"):
6056
Settings.update_settings(version=__version__)
57+
6158
if Settings.load_settings().get("version") != __version__:
6259
Settings.nvim.async_call(Settings.nvim.command, 'call PiecesRunRemotePlugins()')
6360
Settings.update_settings(version = __version__)
6461

62+
6563
Settings.api_client.model_name = Settings.load_settings().get("model_name","GPT-4o Chat Model")
6664
BaseWebsocket.start_all()
6765
Settings.api_client.copilot.ask_stream_ws.on_message_callback = on_copilot_message
6866
Settings.api_client.copilot._return_on_message = lambda: None
6967
else:
70-
Settings.is_loaded = False
7168
BaseWebsocket.close_all()
72-
plugin = "Pieces OS" if result.update == UpdateEnum.PiecesOS else "the Neovim Pieces plugin"
73-
Settings.nvim.async_call(Settings.nvim.err_write, f"Please update {plugin}\n")
7469

75-
@staticmethod
76-
def on_close():
77-
Settings.is_loaded = False
7870

7971
@classmethod
8072
def update_lua_assets(cls,asset:Asset):

rplugin/python3/pieces_python/utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
from pieces_os_client.wrapper.basic_identifier.chat import BasicChat
22
from pieces_os_client.wrapper.websockets import HealthWS
3+
from pieces_os_client.wrapper.version_compatibility import UpdateEnum, VersionChecker
34
from .settings import Settings
45
import os
56
import webbrowser
67

8+
PIECES_OS_MIN_VERSION = "11.0.0" # Minium version (11.0.0)
9+
PIECES_OS_MAX_VERSION = "12.0.0" # Maxium version (12.0.0)
10+
711
def convert_to_lua_table(python_dict):
812
"""
913
Convert a Python dictionary to a Lua table representation.
@@ -58,10 +62,30 @@ def on_copilot_message(message):
5862
""")
5963
return # TODO: Add a better error message
6064

65+
def check_compatibility(notify_if_pos_off = False):
66+
if not Settings.version_compatibility:
67+
if not Settings.api_client.is_pieces_running():
68+
if notify_if_pos_off: Settings.nvim.exec_lua("require('pieces.utils').notify_pieces_os()")
69+
return False
70+
71+
Settings.version_compatibility = VersionChecker(
72+
PIECES_OS_MIN_VERSION,
73+
PIECES_OS_MAX_VERSION,
74+
Settings.api_client.version).version_check()
75+
76+
if not Settings.version_compatibility.compatible:
77+
plugin = "Pieces OS" if Settings.version_compatibility.update == UpdateEnum.PiecesOS else "the Neovim Pieces plugin"
78+
Settings.nvim.async_call(Settings.nvim.err_write, f"Please update {plugin}\n")
79+
return False
80+
else:
81+
return True
6182

6283
def is_pieces_opened(func):
6384
def wrapper(*args, **kwargs):
64-
if Settings.is_loaded:
85+
if not check_compatibility(True):
86+
return
87+
88+
if Settings.api_client.is_pos_stream_running:
6589
return func(*args, **kwargs)
6690
else:
6791
# Run the health request to check if the server is running

0 commit comments

Comments
 (0)