pycoze 0.1.254__py3-none-any.whl → 0.1.256__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pycoze/api/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ from .api import Api, api
2
+
3
+ tab = api.tab
4
+ window = api.window
5
+
6
+ # from ps_view import ViewCls, WebsiteViewCls, FileViewCls, DirectoryViewCls, WorkflowCls
pycoze/api/api.py ADDED
@@ -0,0 +1,9 @@
1
+ from .tab_cls import TabCls
2
+ from .window_cls import WindowCls
3
+
4
+ class Api:
5
+ def __init__(self) -> None:
6
+ self.tab = TabCls()
7
+ self.window = WindowCls()
8
+
9
+ oper = Api()
pycoze/api/tab_cls.py ADDED
@@ -0,0 +1,103 @@
1
+ import os
2
+ from pycoze import utils
3
+ from uuid import uuid4
4
+ from ps_view import ViewCls, WebsiteViewCls, FileViewCls, DirectoryViewCls, WorkflowCls
5
+ import time
6
+ from typing import Union
7
+
8
+
9
+ socket = utils.socket
10
+
11
+ class TabCls:
12
+
13
+ def open_path(self, item_path: str) -> FileViewCls | DirectoryViewCls:
14
+ if not os.path.isabs(item_path):
15
+ item_path = os.path.abspath(item_path)
16
+ if os.path.isdir(item_path):
17
+ return self.open_dir(item_path)
18
+ else:
19
+ return self.open_file(item_path)
20
+
21
+ def open_file(self, item_path: str) -> Union[FileViewCls, WebsiteViewCls, WorkflowCls]:
22
+ if not os.path.isabs(item_path):
23
+ item_path = os.path.abspath(item_path)
24
+ location = ["FileOrDir", item_path]
25
+ socket.post("add-tab", {"location": location, "name": os.path.basename(item_path)})
26
+ lower_suffix = item_path.lower().split(".")[-1]
27
+ if lower_suffix == 'workflow':
28
+ return WorkflowCls(location)
29
+ if len(location) > 1 and (location[0] == "Website" or location[1].endswith(".website") or location[1].endswith(".html") or location[1].endswith(".ipynb")):
30
+ return WebsiteViewCls(location)
31
+ return FileViewCls(location)
32
+
33
+ def open_dir(self, item_path: str) -> DirectoryViewCls:
34
+ if not os.path.isabs(item_path):
35
+ item_path = os.path.abspath(item_path)
36
+ location = ["FileOrDir", item_path]
37
+ socket.post("add-tab", {"location": location, "name": os.path.basename(item_path)})
38
+ return DirectoryViewCls(location)
39
+
40
+ def open_website(self, url: str, uid:str=None) -> WebsiteViewCls:
41
+ if uid is None:
42
+ uid = str(uuid4())
43
+ location = ["Website", url, uid]
44
+ socket.post("add-tab", {"location": location, "name": url})
45
+ return WebsiteViewCls(location)
46
+
47
+ def get_active(self) -> ViewCls:
48
+ result = socket.post_and_recv_result("get-active-tab", {})
49
+ return self._result_to_view(result)
50
+
51
+ def _result_to_view(self, result: list[str]) -> ViewCls:
52
+ if result[0] == "Website":
53
+ return WebsiteViewCls(result)
54
+ elif result[0] == "FileOrDir":
55
+ if os.path.isdir(result[1]):
56
+ return DirectoryViewCls(result)
57
+ else:
58
+ if result[1].lower().split(".")[-1] == 'workflow':
59
+ return WorkflowCls(result)
60
+ return FileViewCls(result)
61
+ return ViewCls(result)
62
+
63
+ def wait_for_tab_open(self, location: list[str] | ViewCls):
64
+ times = 0
65
+ while not self.is_tab_open(location):
66
+ time.sleep(0.01)
67
+ times += 1
68
+ if times > 1000:
69
+ raise Exception("Tab open timeout")
70
+
71
+ def get_all(self) -> list[ViewCls]:
72
+ results = socket.post_and_recv_result("get-all-tabs", {})
73
+ return [self._result_to_view(result) for result in results]
74
+
75
+ def close_tab(self, location: list[str] | ViewCls):
76
+ if isinstance(location, ViewCls):
77
+ location = location.location
78
+ self.wait_for_tab_open(location)
79
+ socket.post("close-tab", {"location": location})
80
+
81
+ def switch_tab(self, location: list[str] | ViewCls):
82
+ if isinstance(location, ViewCls):
83
+ location = location.location
84
+ self.wait_for_tab_open(location)
85
+ socket.post("switchTab", {"location": location})
86
+
87
+ def is_tab_open(self, location: list[str] | ViewCls):
88
+ if isinstance(location, ViewCls):
89
+ location = location.location
90
+ result = socket.post_and_recv_result("is-tab-open", {"location": location})
91
+ return result
92
+
93
+ def pin_tab(self, location: list[str] | ViewCls):
94
+ if isinstance(location, ViewCls):
95
+ location = location.location
96
+ self.wait_for_tab_open(location)
97
+ socket.post("pin-tab", {"location": location})
98
+
99
+ def unpin_tab(self, location: list[str] | ViewCls):
100
+ if isinstance(location, ViewCls):
101
+ location = location.location
102
+ self.wait_for_tab_open(location)
103
+ socket.post("unpin-tab", {"location": location})
@@ -0,0 +1,50 @@
1
+ import sys
2
+ import subprocess
3
+ import os
4
+ from ps_socket import socket
5
+ import time
6
+
7
+
8
+ class WindowCls:
9
+
10
+ def get_slected_text(self) -> str:
11
+ result = socket.post_and_recv_result("get-selected-text", {})
12
+ return result
13
+
14
+ def append_msg(self, message: str, type='info'):
15
+ if not isinstance(message, str):
16
+ message = repr(message)
17
+ socket.post("append-msg", {"message": message, "type": type})
18
+
19
+ def show_operation(self, text: str):
20
+ socket.post("show-operation", {"text": text})
21
+
22
+ def screenshot(self, name):
23
+ socket.post("screenshot", {"name": name})
24
+
25
+ def confirm(self, message: str) -> bool:
26
+ return socket.post_and_recv_result("confirm", {"message": message})
27
+
28
+ def maximize(self):
29
+ socket.post("maximize", {})
30
+
31
+ def open_file_with_system(self, file_path, wait: bool):
32
+ process_fn = subprocess.run if wait else subprocess.Popen
33
+ if sys.platform.startswith('linux'):
34
+ process_fn(['xdg-open', file_path])
35
+ elif sys.platform.startswith('darwin'):
36
+ process_fn(['open', file_path])
37
+ elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
38
+ os.startfile(file_path)
39
+ else:
40
+ raise OSError('Unsupported operating system')
41
+
42
+ def open_program(self, file_path, wait: bool):
43
+ process_fn = subprocess.run if wait else subprocess.Popen
44
+ process_fn([file_path])
45
+
46
+ def execute_javaScript(self, js_code: str):
47
+ result = socket.post_and_recv_result("executeJavaScript", {"code": js_code})
48
+ if not result["ok"]:
49
+ raise Exception(result["value"])
50
+ return result["value"] if "value" in result else None
pycoze/reference/bot.py CHANGED
@@ -10,7 +10,7 @@ from pycoze import utils
10
10
 
11
11
  bot_index = 0
12
12
 
13
- params = utils.read_params_file()
13
+ params = utils.params
14
14
 
15
15
  def ref_bot(bot_id, as_agent_tool=False, workspace_path=None):
16
16
  global bot_index
pycoze/reference/tool.py CHANGED
@@ -8,7 +8,7 @@ from .lib import ChangeDirectoryAndPath, ModuleManager, wrapped_func
8
8
  from pycoze import utils
9
9
 
10
10
 
11
- params = utils.read_params_file()
11
+ params = utils.params
12
12
 
13
13
  def ref_tools(tool_id, as_agent_tool=False, workspace_path=None):
14
14
  if workspace_path is None:
@@ -4,11 +4,11 @@ import importlib
4
4
  from langchain.agents import tool as to_agent_tool
5
5
  import types
6
6
  import langchain_core
7
- from .lib import ChangeDirectoryAndPath, ModuleManager, wrapped_func
7
+ from .lib import ModuleManager, wrapped_func
8
8
  from pycoze import utils
9
9
 
10
10
 
11
- params = utils.read_params_file()
11
+ params = utils.params
12
12
 
13
13
  def _ref_workflows(workflow_id, as_agent_tool=False, workspace_path=None):
14
14
  if workspace_path is None:
pycoze/ui/base.py CHANGED
@@ -4,7 +4,7 @@ import json
4
4
  import inspect
5
5
 
6
6
 
7
- params = utils.read_params_file()
7
+ params = utils.params
8
8
 
9
9
 
10
10
  def get_ui():
pycoze/utils/__init__.py CHANGED
@@ -1,5 +1,9 @@
1
1
  from .arg import read_arg
2
2
  from .env import read_params_file, params, read_json_file
3
+ from .socket import TcpSocket, socket, socket_subscribe
3
4
  from .text_or_file import to_text
4
5
 
5
- __all__ = [read_arg, read_params_file, params, read_json_file, to_text]
6
+ __all__ = [read_arg,
7
+ read_params_file, params, read_json_file,
8
+ TcpSocket, socket, socket_subscribe,
9
+ to_text]
pycoze/utils/socket.py CHANGED
@@ -1,10 +1,11 @@
1
1
  import socket
2
2
  import json
3
3
  import uuid
4
+ from pycoze import utils
4
5
 
5
6
 
6
- tcp_port = read_arg("tcp_port")
7
-
7
+ params = utils.params
8
+ tcp_port = params["tcpPort"]
8
9
 
9
10
 
10
11
  class TcpSocket:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycoze
3
- Version: 0.1.254
3
+ Version: 0.1.256
4
4
  Summary: Package for pycoze only!
5
5
  Author: Yuan Jie Xiong
6
6
  Author-email: aiqqqqqqq@qq.com
@@ -5,6 +5,10 @@ pycoze/ai/llm/__init__.py,sha256=5_AnOrzXI2V6ZZsLUWW1v5ATRWmJy53JLN9jfSZQXCg,249
5
5
  pycoze/ai/llm/chat.py,sha256=izriC7nCp5qeJRqcUVQBVqTHiH6MJS77ROzGBJufdNI,5133
6
6
  pycoze/ai/llm/text_to_image_prompt.py,sha256=0bx2C_YRvjAo7iphHGp1-pmGKsKqwur7dM0t3SiA8kA,3398
7
7
  pycoze/ai/llm/think.py,sha256=sUgTBdGzcZtL3r-Wx8M3lDuVUmDVz8g3qC0VU8uiKAI,5143
8
+ pycoze/api/__init__.py,sha256=c4COCanllUOYJ6-P3cu8jjuiirxODmTwJQvDkkRwfC8,151
9
+ pycoze/api/api.py,sha256=6c75iq44ryedNTGfKrOKxfA1-6eF7l77PjuNg1J6_1k,191
10
+ pycoze/api/tab_cls.py,sha256=0HYzi0At7j2xjMPPDXw9lH5psYKxaPrDCO11cM6razw,4205
11
+ pycoze/api/window_cls.py,sha256=OTVZH1izCasx8a7NPFaS6w-21gZX5jE36aO7Y_MX_mQ,1766
8
12
  pycoze/bot/__init__.py,sha256=JxnRoCCqx_LFyVb3pLu0qYCsH8ZLuAaMXAtvVUuCHuE,78
9
13
  pycoze/bot/agent_chat.py,sha256=ARXXsIVCTpmBojz2C4BR69nB0QhM6gkEngL3iq34JPo,4178
10
14
  pycoze/bot/bot.py,sha256=_qmUTZ09FmRLifHrW5stDZWGVK6yuMEMBC3fmeYJnqk,844
@@ -16,22 +20,22 @@ pycoze/bot/agent/agent_types/__init__.py,sha256=zmU2Kmrv5mCdfg-QlPn2H6pWxbGeq8s7
16
20
  pycoze/bot/agent/agent_types/const.py,sha256=BfUKPrhAHREoMLHuFNG2bCIEkC1-f7K0LEqNg4RwiRE,70
17
21
  pycoze/bot/agent/agent_types/openai_func_call_agent.py,sha256=6aKnUQDINyUaCW24oa9Qjkm5w3ctZ6lxAgcE4m9YHwE,6701
18
22
  pycoze/reference/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
- pycoze/reference/bot.py,sha256=BDflTV3zYoZqWnJpD5lMM_1vU_5b20M3XiFt1p-RHWM,2427
23
+ pycoze/reference/bot.py,sha256=EQUngYFn5K7DdQWsPHKOXOsrMAz-3nMjiZEPc3yHfvo,2415
20
24
  pycoze/reference/lib.py,sha256=0xQJTLTHedGzQBsjuTFNBVqYc4-8Yl65gGCrAhWyOX8,2155
21
- pycoze/reference/tool.py,sha256=9OxHawxjkh6S8eAOlGNrbfhkk5oRlRc7LBpnV6RmhYI,1722
22
- pycoze/reference/workflow.py,sha256=xIxv4EAeIR663bRfXkLhgBC0OhfMs5RdfvdORI80CoQ,2068
25
+ pycoze/reference/tool.py,sha256=CYUS95M_XGnUcl4uWayjzKOM9jGpylS7vWJ66JfNTjI,1710
26
+ pycoze/reference/workflow.py,sha256=2EcqN9xefI_c2wHjwmMrUUakM50FPoSVH5_qEedqT8k,2032
23
27
  pycoze/ui/__init__.py,sha256=uaXet23wUk64TcZjpBX8qOx4aUhwA_ucrmcxy7Q4Qr4,929
24
- pycoze/ui/base.py,sha256=sbBZGMUtlosWHQJpxMULa1bGByeSlcldtE9QXNyiJmM,1093
28
+ pycoze/ui/base.py,sha256=bz9mHZwIXA8LErEHTIonH347u6LP7rxV2EADMMjNZos,1081
25
29
  pycoze/ui/color.py,sha256=cT9Ib8uNzkOKxyW0IwVj46o4LwdB1xgNCj1_Rou9d_4,854
26
30
  pycoze/ui/typ.py,sha256=NpT0FrbHvByOszBZMFtroRp7I7pN-38tYz_zPOPejF4,1723
27
31
  pycoze/ui/ui_def.py,sha256=lGWZGpzRoegP34D562PvK0EJHrmVZrlHW1JjsIG9A9Q,4521
28
- pycoze/utils/__init__.py,sha256=6bQ3erQHKVOUk4ylyC-6PCASbAV0pYFQfC_f1KqkbUw,191
32
+ pycoze/utils/__init__.py,sha256=H-2KRUsUG47owL0sbD1KwDOuRm-j_0K4RkeNhzr7ISo,319
29
33
  pycoze/utils/arg.py,sha256=jop1tBfe5hYkHW1NSpCeaZBEznkgguBscj_7M2dWfrs,503
30
34
  pycoze/utils/env.py,sha256=5pWlXfM1F5ZU9hhv1rHlDEanjEW5wf0nbyez9bNRqqA,559
31
- pycoze/utils/socket.py,sha256=CpyyC-zgibi_GvTeHP14VlqIfC7QuRE6BNbQH3Hb45c,2370
35
+ pycoze/utils/socket.py,sha256=yyYgx7G40x58sV466OQH0vj3i55xgR3uMDEjbQMbGks,2413
32
36
  pycoze/utils/text_or_file.py,sha256=gpxZVWt2DW6YiEg_MnMuwg36VNf3TX383QD_1oZNB0Y,551
33
- pycoze-0.1.254.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
34
- pycoze-0.1.254.dist-info/METADATA,sha256=hD65Lc7e26JX0Th3OYDX8OFcJPZcQCR90fy9doVnkno,699
35
- pycoze-0.1.254.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
36
- pycoze-0.1.254.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
37
- pycoze-0.1.254.dist-info/RECORD,,
37
+ pycoze-0.1.256.dist-info/LICENSE,sha256=QStd_Qsd0-kAam_-sOesCIp_uKrGWeoKwt9M49NVkNU,1090
38
+ pycoze-0.1.256.dist-info/METADATA,sha256=UFuAyV9kjFN62yPq0kVYFc3rJwRbMPwAx9OYDysFdA4,699
39
+ pycoze-0.1.256.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
40
+ pycoze-0.1.256.dist-info/top_level.txt,sha256=76dPeDhKvOCleL3ZC5gl1-y4vdS1tT_U1hxWVAn7sFo,7
41
+ pycoze-0.1.256.dist-info/RECORD,,