2023-11-30 07:50:49 +08:00
|
|
|
import requests
|
2023-11-30 07:57:24 +08:00
|
|
|
import os
|
2023-12-18 09:17:32 +08:00
|
|
|
import json
|
2023-11-30 07:50:49 +08:00
|
|
|
from functools import wraps
|
|
|
|
|
2023-12-08 18:28:36 +08:00
|
|
|
BASE_SERVER_URL = os.environ.get("DEVCHAT_IDE_SERVICE_URL", "http://localhost:3000")
|
|
|
|
|
2023-11-30 07:50:49 +08:00
|
|
|
|
|
|
|
def rpc_call(f):
|
|
|
|
@wraps(f)
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
function_name = f.__name__
|
|
|
|
url = f"{BASE_SERVER_URL}/{function_name}"
|
|
|
|
|
|
|
|
data = dict(zip(f.__code__.co_varnames, args))
|
|
|
|
data.update(kwargs)
|
2023-12-08 18:28:36 +08:00
|
|
|
headers = {"Content-Type": "application/json"}
|
2023-12-08 11:13:17 +08:00
|
|
|
|
2023-11-30 07:50:49 +08:00
|
|
|
response = requests.post(url, json=data, headers=headers)
|
2023-12-08 11:13:17 +08:00
|
|
|
|
2023-11-30 07:50:49 +08:00
|
|
|
if response.status_code != 200:
|
|
|
|
raise Exception(f"Server error: {response.status_code}")
|
|
|
|
|
|
|
|
response_data = response.json()
|
2023-12-08 18:28:36 +08:00
|
|
|
if "error" in response_data:
|
2023-11-30 07:50:49 +08:00
|
|
|
raise Exception(f"Server returned an error: {response_data['error']}")
|
2023-12-08 18:28:36 +08:00
|
|
|
return response_data["result"]
|
2023-11-30 07:50:49 +08:00
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
@rpc_call
|
|
|
|
def get_lsp_brige_port():
|
2023-12-08 18:28:36 +08:00
|
|
|
pass
|
2023-12-18 09:17:32 +08:00
|
|
|
|
|
|
|
@rpc_call
|
|
|
|
def install_python_env(command_name: str, requirements_file: str) -> str:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@rpc_call
|
|
|
|
def update_slash_commands():
|
|
|
|
pass
|
|
|
|
|
|
|
|
@rpc_call
|
|
|
|
def open_folder(folder: str):
|
|
|
|
pass
|