clerk-sdk 0.4.15__py3-none-any.whl → 0.4.16.dev0__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.
clerk/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  from .client import Clerk
2
2
 
3
3
 
4
- __version__ = "0.4.14"
4
+ __version__ = "0.4.16.dev0"
@@ -2,7 +2,7 @@ import asyncio
2
2
  import functools
3
3
  import os
4
4
  import time
5
- from typing import Callable, Union
5
+ from typing import Any, Callable, Dict, Sequence, Union
6
6
 
7
7
  from websockets.asyncio.client import connect, ClientConnection
8
8
  from websockets.protocol import State
@@ -24,13 +24,6 @@ global_ws: Union[ClientConnection, None] = None
24
24
  clerk_client = RPAClerk()
25
25
  wss_uri = "wss://agent-manager.f-one.group/action"
26
26
 
27
- REMOTE_DEVICE_ALLOCATION_TIMEOUT = int(
28
- os.getenv("REMOTE_DEVICE_ALLOCATION_TIMEOUT", 60)
29
- )
30
- REMOTE_DEVICE_ALLOCATION_MAX_TRIES = int(
31
- os.getenv("REMOTE_DEVICE_ALLOCATION_MAX_TRIES", 60)
32
- )
33
-
34
27
 
35
28
  async def connect_to_ws(uri: str) -> ClientConnection:
36
29
  # Same knobs as before, just via the new connect()
@@ -54,46 +47,7 @@ async def reconnect_ws():
54
47
  global_ws = await connect_to_ws(uri)
55
48
 
56
49
 
57
- def _allocate_remote_device(
58
- clerk_client: RPAClerk, group_name: str, run_id: str
59
- ) -> RemoteDevice:
60
- remote_device = None
61
- retries = 0
62
-
63
- while True:
64
- try:
65
- remote_device = clerk_client.allocate_remote_device(
66
- group_name=group_name, run_id=run_id
67
- )
68
- os.environ["REMOTE_DEVICE_ID"] = remote_device.id
69
- os.environ["REMOTE_DEVICE_NAME"] = remote_device.name
70
- logger.debug(f"Remote device allocated: {remote_device.name}")
71
- return remote_device
72
-
73
- except NoClientsAvailable:
74
- logger.warning(
75
- f"No clients are available for {group_name} group. Initiating a {REMOTE_DEVICE_ALLOCATION_TIMEOUT} seconds wait. Retry count: {retries}"
76
- )
77
- if retries >= REMOTE_DEVICE_ALLOCATION_MAX_TRIES:
78
- raise ClientAvailabilityTimeout(
79
- f"No clients available for {group_name} group after {REMOTE_DEVICE_ALLOCATION_TIMEOUT * REMOTE_DEVICE_ALLOCATION_MAX_TRIES} seconds"
80
- )
81
- time.sleep(REMOTE_DEVICE_ALLOCATION_TIMEOUT)
82
- retries += 1
83
-
84
-
85
- def _deallocate_target(
86
- clerk_client: RPAClerk, remote_device: RemoteDevice, run_id: str
87
- ):
88
- clerk_client.deallocate_remote_device(remote_device=remote_device, run_id=run_id)
89
- logger.debug("Remote device deallocated")
90
- os.environ.pop("REMOTE_DEVICE_ID", None)
91
- os.environ.pop("REMOTE_DEVICE_NAME", None)
92
-
93
-
94
- def gui_automation(
95
- reserve_client: bool = False,
96
- ):
50
+ def gui_automation():
97
51
  """
98
52
  Decorator that:
99
53
  • Allocates a remote device,
@@ -101,22 +55,22 @@ def gui_automation(
101
55
  • Passes control to the wrapped function,
102
56
  • Cleans everything up afterwards.
103
57
  """
104
- group_name: str | None = os.getenv("REMOTE_DEVICE_GROUP")
105
- if not group_name:
106
- raise ValueError("REMOTE_DEVICE_GROUP environmental variable is required.")
58
+ remote_device_name: str | None = os.getenv("REMOTE_DEVICE_NAME")
59
+
60
+ if not remote_device_name:
61
+ raise ValueError("REMOTE_DEVICE_NAME environmental variable is required.")
62
+
63
+ wss_token = clerk_client.get_wss_token()
107
64
 
108
65
  def decorator(func: Callable):
109
66
  @functools.wraps(func)
110
- def wrapper(payload: ClerkCodePayload, *args, **kwargs):
67
+ def wrapper(
68
+ payload: ClerkCodePayload, *args: Sequence[Any], **kwargs: Dict[str, Any]
69
+ ):
111
70
  global global_ws
112
71
 
113
- force_deallocate = False
114
72
  os.environ["_document_id"] = payload.document.id
115
- os.environ["_run_id"] = payload.run_id
116
-
117
- remote_device = _allocate_remote_device(
118
- clerk_client, group_name, payload.run_id
119
- )
73
+ os.environ["_run_id"] = payload.run_id or ""
120
74
 
121
75
  # Create a dedicated loop for the WebSocket work
122
76
  event_loop = asyncio.new_event_loop()
@@ -125,8 +79,8 @@ def gui_automation(
125
79
  try:
126
80
  task = event_loop.create_task(
127
81
  connect_to_ws(
128
- f"{wss_uri}/{remote_device.name}/publisher"
129
- f"?token={remote_device.wss_token}"
82
+ f"{wss_uri}/{remote_device_name}/publisher"
83
+ f"?token={wss_token}"
130
84
  )
131
85
  )
132
86
  global_ws = event_loop.run_until_complete(task)
@@ -138,18 +92,11 @@ def gui_automation(
138
92
  global_ws = None
139
93
  raise WebSocketConnectionFailed()
140
94
 
141
- except Exception as e:
142
- force_deallocate = True
95
+ except Exception:
143
96
  raise
144
97
  finally:
145
98
  os.environ.pop("_run_id", None)
146
99
  os.environ.pop("_document_id", None)
147
- if not reserve_client or force_deallocate:
148
- _deallocate_target(clerk_client, remote_device, payload.run_id)
149
- else:
150
- logger.warning(
151
- f"The client stayed reserved for the this run id: {payload.run_id}"
152
- )
153
100
 
154
101
  if global_ws and global_ws.state is State.OPEN:
155
102
  close_task = event_loop.create_task(close_ws_connection(global_ws))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clerk-sdk
3
- Version: 0.4.15
3
+ Version: 0.4.16.dev0
4
4
  Summary: Library for interacting with Clerk
5
5
  Home-page: https://github.com/F-ONE-Group/clerk_pypi
6
6
  Author: F-ONE Group
@@ -1,4 +1,4 @@
1
- clerk/__init__.py,sha256=xGgrQuxBmA5NdRf4kuLF14MHSYwPsVBcmuyxvPhL6TU,51
1
+ clerk/__init__.py,sha256=6KE-7b4AAmpoWge6Ecko_0Spe4J7BC3YRdmmlEmsUFQ,56
2
2
  clerk/base.py,sha256=lbFTdpdDfsmYIQUFH93S1aw0-L6GNJwAcubW1tdMFX4,3967
3
3
  clerk/client.py,sha256=RdOvC23WK9ZtIXDOYaoSFk9debh3UTmstBXjAswAH6E,4981
4
4
  clerk/decorator/__init__.py,sha256=yGGcS17VsZ7cZ-hVGCm3I3vGDJMiJIAqmDGzriIi0DI,65
@@ -17,7 +17,7 @@ clerk/gui_automation/client_actor/client_actor.py,sha256=D2mQAHitF5x-dZzt70ZPw_f
17
17
  clerk/gui_automation/client_actor/exception.py,sha256=zdnImHZ88yf52Xq3aMHivEU3aJg-r2c-r8x8XZnI3ic,407
18
18
  clerk/gui_automation/client_actor/model.py,sha256=wVpFCi1w2kh4kAV8oNx489vf_SLUQnqhc02rFD5NIJA,6335
19
19
  clerk/gui_automation/decorators/__init__.py,sha256=OCgXStEumscgT-RyVy5OKS7ml1w9y-lEnjCVnxuRnQs,43
20
- clerk/gui_automation/decorators/gui_automation.py,sha256=6BVT74n4JsPJmD_G_b_MNfEvq3WZAukWbQcAOX2aDPM,5770
20
+ clerk/gui_automation/decorators/gui_automation.py,sha256=CwfDmTP9d4BOEsQS4_YGwOoz1gbDwYsA-JVnXz25Cto,3680
21
21
  clerk/gui_automation/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  clerk/gui_automation/exceptions/agent_manager.py,sha256=KFWFWQ7X_8Z9XG__SMzb1jKI3yNoVTPJAXzW5O-fSXc,101
23
23
  clerk/gui_automation/exceptions/websocket.py,sha256=-MdwSwlf1hbnu55aDgk3L1znkTZ6xJS6po5VpEGD9ck,117
@@ -45,8 +45,8 @@ clerk/models/ui_operator.py,sha256=mKTJUFZgv7PeEt5oys28HVZxHOJsofmRQOcRpqj0dbU,2
45
45
  clerk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
46
  clerk/utils/logger.py,sha256=NrMIlJfVmRjjRw_N_Jngkl0qqv7btXUbg5wxcRmFEH4,3800
47
47
  clerk/utils/save_artifact.py,sha256=94aYkYNVGcSUaSWZmdjiY6Oc-3yCKb2XWCZ56IAXQqk,1158
48
- clerk_sdk-0.4.15.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
49
- clerk_sdk-0.4.15.dist-info/METADATA,sha256=5a82iUvHTK2T885B0pUGQMu2px-RzRIUxMKxH8sSd9w,9937
50
- clerk_sdk-0.4.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
- clerk_sdk-0.4.15.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
52
- clerk_sdk-0.4.15.dist-info/RECORD,,
48
+ clerk_sdk-0.4.16.dev0.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
49
+ clerk_sdk-0.4.16.dev0.dist-info/METADATA,sha256=U8QlEn0ANQxSkmowBLby6M8IJL-BKHkXxkQ5BL6lLhc,9942
50
+ clerk_sdk-0.4.16.dev0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
+ clerk_sdk-0.4.16.dev0.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
52
+ clerk_sdk-0.4.16.dev0.dist-info/RECORD,,