clerk-sdk 0.3.1__tar.gz → 0.3.3__tar.gz
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_sdk-0.3.1/clerk_sdk.egg-info → clerk_sdk-0.3.3}/PKG-INFO +1 -1
- clerk_sdk-0.3.3/clerk/decorator/task_decorator.py +89 -0
- clerk_sdk-0.3.3/clerk/exceptions/exceptions.py +40 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3/clerk_sdk.egg-info}/PKG-INFO +1 -1
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/setup.py +1 -1
- clerk_sdk-0.3.1/clerk/decorator/task_decorator.py +0 -68
- clerk_sdk-0.3.1/clerk/exceptions/exceptions.py +0 -13
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/LICENSE +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/MANIFEST.in +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/README.md +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/base.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/client.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/decorator/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/decorator/models.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/exceptions/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/exceptions/remote_device.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/action_model/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/action_model/model.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/action_model/utils.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/client.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/client_actor/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/client_actor/client_actor.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/client_actor/exception.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/client_actor/model.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/decorators/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/decorators/gui_automation.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/exceptions/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/exceptions/agent_manager.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/exceptions/modality/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/exceptions/modality/exc.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/exceptions/websocket.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/requirements.txt +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_actions/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_actions/actions.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_actions/base.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_actions/support.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_inspector/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_inspector/gui_vision.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_inspector/models.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_machine/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_machine/ai_recovery.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_machine/decorators.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_machine/exceptions.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_machine/models.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/gui_automation/ui_state_machine/state_machine.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/models/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/models/document.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/models/document_statuses.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/models/file.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/models/remote_device.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/models/response_model.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/models/ui_operator.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/utils/__init__.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/utils/logger.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk/utils/save_artifact.py +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk_sdk.egg-info/SOURCES.txt +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk_sdk.egg-info/dependency_links.txt +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk_sdk.egg-info/requires.txt +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/clerk_sdk.egg-info/top_level.txt +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/pyproject.toml +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/requirements.txt +0 -0
- {clerk_sdk-0.3.1 → clerk_sdk-0.3.3}/setup.cfg +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import pickle
|
|
2
|
+
import traceback
|
|
3
|
+
from typing import Callable, Optional
|
|
4
|
+
from functools import wraps
|
|
5
|
+
|
|
6
|
+
from clerk.exceptions.exceptions import ApplicationException
|
|
7
|
+
from .models import ClerkCodePayload
|
|
8
|
+
|
|
9
|
+
input_pkl: str = "/app/data/input/input.pkl"
|
|
10
|
+
output_pkl: str = "/app/data/output/output.pkl"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def clerk_code():
|
|
14
|
+
def decorator(func: Callable[[ClerkCodePayload], ClerkCodePayload]):
|
|
15
|
+
@wraps(func)
|
|
16
|
+
def wrapper(payload: Optional[ClerkCodePayload] = None) -> ClerkCodePayload:
|
|
17
|
+
# 1. Load payload from file if not provided
|
|
18
|
+
use_pickle = False
|
|
19
|
+
output = None
|
|
20
|
+
error_occurred = False
|
|
21
|
+
error_info = None
|
|
22
|
+
if payload is None:
|
|
23
|
+
use_pickle = True
|
|
24
|
+
try:
|
|
25
|
+
with open(input_pkl, "rb") as f:
|
|
26
|
+
raw_data = pickle.load(f)
|
|
27
|
+
payload = (
|
|
28
|
+
ClerkCodePayload.model_validate(raw_data)
|
|
29
|
+
if not isinstance(raw_data, ClerkCodePayload)
|
|
30
|
+
else raw_data
|
|
31
|
+
)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
error_occurred = True
|
|
34
|
+
error_info = ApplicationException(
|
|
35
|
+
type_=str(type(e)),
|
|
36
|
+
message=f"Failed to load and parse input pickle: {e}",
|
|
37
|
+
traceback=traceback.format_exc(),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# 2. Execute function
|
|
41
|
+
if not error_occurred:
|
|
42
|
+
try:
|
|
43
|
+
output = func(payload)
|
|
44
|
+
if not isinstance(output, ClerkCodePayload):
|
|
45
|
+
raise TypeError(
|
|
46
|
+
"Function must return a ClerkCodePayload instance."
|
|
47
|
+
)
|
|
48
|
+
except Exception as e:
|
|
49
|
+
error_occurred = True
|
|
50
|
+
error_info = ApplicationException(
|
|
51
|
+
type_=str(type(e)),
|
|
52
|
+
message=str(e),
|
|
53
|
+
traceback=traceback.format_exc(),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
# 3. write to output.pkl
|
|
57
|
+
try:
|
|
58
|
+
if use_pickle:
|
|
59
|
+
with open(output_pkl, "wb") as f:
|
|
60
|
+
if error_occurred:
|
|
61
|
+
pickle.dump(error_info, f)
|
|
62
|
+
elif isinstance(output, Exception):
|
|
63
|
+
pickle.dump(output, f)
|
|
64
|
+
else:
|
|
65
|
+
pickle.dump(output.model_dump(mode="json"), f)
|
|
66
|
+
except Exception as e:
|
|
67
|
+
# If writing output.pkl fails, try to write a minimal error
|
|
68
|
+
try:
|
|
69
|
+
with open(output_pkl, "wb") as f:
|
|
70
|
+
pickle.dump(
|
|
71
|
+
ApplicationException(
|
|
72
|
+
type_=str(type(e)),
|
|
73
|
+
message=f"Failed to write output pickle: {str(e)}",
|
|
74
|
+
traceback=traceback.format_exc(),
|
|
75
|
+
),
|
|
76
|
+
f,
|
|
77
|
+
)
|
|
78
|
+
except Exception:
|
|
79
|
+
pass # Last resort: do nothing if even this fails
|
|
80
|
+
|
|
81
|
+
# 4. Raise if error or return result
|
|
82
|
+
if isinstance(output, Exception):
|
|
83
|
+
raise output
|
|
84
|
+
|
|
85
|
+
return output
|
|
86
|
+
|
|
87
|
+
return wrapper
|
|
88
|
+
|
|
89
|
+
return decorator
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AppBaseException(Exception):
|
|
5
|
+
def __init__(
|
|
6
|
+
self,
|
|
7
|
+
*args,
|
|
8
|
+
type_: Optional[str] = None,
|
|
9
|
+
message: Optional[str] = None,
|
|
10
|
+
traceback: Optional[str] = None,
|
|
11
|
+
):
|
|
12
|
+
# If called with positional args (e.g., during unpickling or raise("msg")),
|
|
13
|
+
# treat args[0] as the message.
|
|
14
|
+
if args and message is None:
|
|
15
|
+
message = args[0]
|
|
16
|
+
|
|
17
|
+
# Always call base Exception with just the message so .args == (message,)
|
|
18
|
+
super().__init__(message)
|
|
19
|
+
|
|
20
|
+
# Store structured fields
|
|
21
|
+
self.type = type_ or self.__class__.__name__
|
|
22
|
+
self.message = message or ""
|
|
23
|
+
self.traceback = traceback
|
|
24
|
+
|
|
25
|
+
# (Optional) make pickling round-trip the extra fields explicitly
|
|
26
|
+
def __reduce__(self):
|
|
27
|
+
# Reconstruct with message-only (what Exception expects) and restore extras via state
|
|
28
|
+
return (
|
|
29
|
+
self.__class__,
|
|
30
|
+
(self.message,),
|
|
31
|
+
{"type": self.type, "traceback": self.traceback},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def __setstate__(self, state):
|
|
35
|
+
for k, v in state.items():
|
|
36
|
+
setattr(self, k, v)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ApplicationException(AppBaseException):
|
|
40
|
+
pass
|
|
@@ -13,7 +13,7 @@ gui_requirements = get_requirements("./clerk/gui_automation")
|
|
|
13
13
|
|
|
14
14
|
setup(
|
|
15
15
|
name="clerk-sdk",
|
|
16
|
-
version="0.3.
|
|
16
|
+
version="0.3.3",
|
|
17
17
|
description="Library for interacting with Clerk",
|
|
18
18
|
long_description=open("README.md").read(),
|
|
19
19
|
long_description_content_type="text/markdown",
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import pickle
|
|
3
|
-
import traceback
|
|
4
|
-
from typing import Callable, Optional
|
|
5
|
-
from functools import wraps
|
|
6
|
-
|
|
7
|
-
from clerk.exceptions.exceptions import ApplicationException
|
|
8
|
-
from .models import ClerkCodePayload
|
|
9
|
-
|
|
10
|
-
input_pkl: str = "/app/data/input/input.pkl"
|
|
11
|
-
output_pkl: str = "/app/data/output/output.pkl"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def clerk_code():
|
|
15
|
-
def decorator(func: Callable[[ClerkCodePayload], ClerkCodePayload]):
|
|
16
|
-
@wraps(func)
|
|
17
|
-
def wrapper(payload: Optional[ClerkCodePayload] = None) -> ClerkCodePayload:
|
|
18
|
-
# 1. Load payload from file if not provided
|
|
19
|
-
use_pickle = False
|
|
20
|
-
if payload is None:
|
|
21
|
-
use_pickle = True
|
|
22
|
-
try:
|
|
23
|
-
with open(input_pkl, "rb") as f:
|
|
24
|
-
raw_data = pickle.load(f)
|
|
25
|
-
payload = (
|
|
26
|
-
ClerkCodePayload.model_validate(raw_data)
|
|
27
|
-
if not isinstance(raw_data, ClerkCodePayload)
|
|
28
|
-
else raw_data
|
|
29
|
-
)
|
|
30
|
-
except Exception as e:
|
|
31
|
-
raise RuntimeError(
|
|
32
|
-
f"Failed to load and parse input pickle: {e}"
|
|
33
|
-
) from e
|
|
34
|
-
|
|
35
|
-
# 2. Execute function
|
|
36
|
-
try:
|
|
37
|
-
output = func(payload)
|
|
38
|
-
if not isinstance(output, ClerkCodePayload):
|
|
39
|
-
raise TypeError("Function must return a ClerkCodePayload instance.")
|
|
40
|
-
except Exception as e:
|
|
41
|
-
# parse no standard errors into the standard Application Error
|
|
42
|
-
output = ApplicationException(
|
|
43
|
-
type_=str(type(e)), message=str(e), traceback=traceback.format_exc()
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
# 3. write to output.pkl
|
|
47
|
-
try:
|
|
48
|
-
if use_pickle:
|
|
49
|
-
with open(output_pkl, "wb") as f:
|
|
50
|
-
if isinstance(output, Exception):
|
|
51
|
-
pickle.dump(output, f)
|
|
52
|
-
else:
|
|
53
|
-
pickle.dump(output.model_dump(mode="json"), f)
|
|
54
|
-
|
|
55
|
-
except Exception as e:
|
|
56
|
-
output = RuntimeError(f"Failed to write output pickle: {str(e)}")
|
|
57
|
-
with open(output_pkl, "wb") as f:
|
|
58
|
-
pickle.dump(output, f)
|
|
59
|
-
|
|
60
|
-
# 4. Raise if error or return result
|
|
61
|
-
if isinstance(output, Exception):
|
|
62
|
-
raise output
|
|
63
|
-
|
|
64
|
-
return output
|
|
65
|
-
|
|
66
|
-
return wrapper
|
|
67
|
-
|
|
68
|
-
return decorator
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class AppBaseException(Exception):
|
|
5
|
-
def __init__(self, type_: str, message: str, traceback: Optional[str] = None):
|
|
6
|
-
super().__init__(message)
|
|
7
|
-
self.type = type_
|
|
8
|
-
self.message = message
|
|
9
|
-
self.traceback = traceback
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class ApplicationException(AppBaseException):
|
|
13
|
-
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|