intuned-runtime 1.0.0__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.
Files changed (58) hide show
  1. cli/__init__.py +45 -0
  2. cli/commands/__init__.py +25 -0
  3. cli/commands/ai_source/__init__.py +4 -0
  4. cli/commands/ai_source/ai_source.py +10 -0
  5. cli/commands/ai_source/deploy.py +64 -0
  6. cli/commands/browser/__init__.py +3 -0
  7. cli/commands/browser/save_state.py +32 -0
  8. cli/commands/init.py +127 -0
  9. cli/commands/project/__init__.py +20 -0
  10. cli/commands/project/auth_session/__init__.py +5 -0
  11. cli/commands/project/auth_session/check.py +118 -0
  12. cli/commands/project/auth_session/create.py +96 -0
  13. cli/commands/project/auth_session/load.py +39 -0
  14. cli/commands/project/project.py +10 -0
  15. cli/commands/project/run.py +340 -0
  16. cli/commands/project/run_interface.py +265 -0
  17. cli/commands/project/type_check.py +86 -0
  18. cli/commands/project/upgrade.py +92 -0
  19. cli/commands/publish_packages.py +264 -0
  20. cli/logger.py +19 -0
  21. cli/utils/ai_source_project.py +31 -0
  22. cli/utils/code_tree.py +83 -0
  23. cli/utils/run_apis.py +147 -0
  24. cli/utils/unix_socket.py +55 -0
  25. intuned_runtime-1.0.0.dist-info/LICENSE +42 -0
  26. intuned_runtime-1.0.0.dist-info/METADATA +113 -0
  27. intuned_runtime-1.0.0.dist-info/RECORD +58 -0
  28. intuned_runtime-1.0.0.dist-info/WHEEL +4 -0
  29. intuned_runtime-1.0.0.dist-info/entry_points.txt +3 -0
  30. runtime/__init__.py +3 -0
  31. runtime/backend_functions/__init__.py +5 -0
  32. runtime/backend_functions/_call_backend_function.py +86 -0
  33. runtime/backend_functions/get_auth_session_parameters.py +30 -0
  34. runtime/browser/__init__.py +3 -0
  35. runtime/browser/launch_chromium.py +212 -0
  36. runtime/browser/storage_state.py +106 -0
  37. runtime/context/__init__.py +5 -0
  38. runtime/context/context.py +51 -0
  39. runtime/env.py +13 -0
  40. runtime/errors/__init__.py +21 -0
  41. runtime/errors/auth_session_errors.py +9 -0
  42. runtime/errors/run_api_errors.py +120 -0
  43. runtime/errors/trace_errors.py +3 -0
  44. runtime/helpers/__init__.py +5 -0
  45. runtime/helpers/extend_payload.py +9 -0
  46. runtime/helpers/extend_timeout.py +13 -0
  47. runtime/helpers/get_auth_session_parameters.py +14 -0
  48. runtime/py.typed +0 -0
  49. runtime/run/__init__.py +3 -0
  50. runtime/run/intuned_settings.py +38 -0
  51. runtime/run/playwright_constructs.py +19 -0
  52. runtime/run/run_api.py +233 -0
  53. runtime/run/traces.py +36 -0
  54. runtime/types/__init__.py +15 -0
  55. runtime/types/payload.py +7 -0
  56. runtime/types/run_types.py +177 -0
  57. runtime_helpers/__init__.py +5 -0
  58. runtime_helpers/py.typed +0 -0
runtime/run/traces.py ADDED
@@ -0,0 +1,36 @@
1
+ import os
2
+ from os import environ
3
+ from typing import Optional
4
+
5
+ import requests
6
+
7
+ from ..errors import TraceNotFoundError
8
+
9
+
10
+ def get_trace_file_path(run_id: str, attempt_number: Optional[str] = "") -> str:
11
+ file_name = f'{run_id}{attempt_number if attempt_number is not None else ""}'
12
+ traces_dir = environ.get("TRACES_DIRECTORY", "")
13
+ return os.path.join(traces_dir, f"{file_name}.zip")
14
+
15
+
16
+ def upload_trace(run_id: str, attempt_number: Optional[str], trace_signed_url: str):
17
+ trace_file_path = get_trace_file_path(run_id, attempt_number)
18
+
19
+ if not os.path.exists(trace_file_path):
20
+ raise TraceNotFoundError()
21
+
22
+ file_size = os.path.getsize(trace_file_path)
23
+
24
+ with open(trace_file_path, "rb") as trace_file:
25
+ upload_trace_res = requests.put(trace_signed_url, headers={"Content-Length": str(file_size)}, data=trace_file)
26
+
27
+ return upload_trace_res
28
+
29
+
30
+ def delete_trace(run_id: str, attempt_number: Optional[str]):
31
+ trace_file_path = get_trace_file_path(run_id, attempt_number)
32
+
33
+ if not os.path.exists(trace_file_path):
34
+ raise TraceNotFoundError()
35
+
36
+ os.remove(trace_file_path)
@@ -0,0 +1,15 @@
1
+ from .payload import Payload
2
+ from .run_types import PayloadToAppend
3
+ from .run_types import RunAutomationErrorResult
4
+ from .run_types import RunAutomationResult
5
+ from .run_types import RunAutomationSuccessResult
6
+ from .run_types import RunBody
7
+
8
+ __all__ = [
9
+ "Payload",
10
+ "RunBody",
11
+ "RunAutomationResult",
12
+ "RunAutomationErrorResult",
13
+ "RunAutomationSuccessResult",
14
+ "PayloadToAppend",
15
+ ]
@@ -0,0 +1,7 @@
1
+ from typing import Any
2
+ from typing import TypedDict
3
+
4
+
5
+ class Payload(TypedDict):
6
+ api: str
7
+ parameters: dict[str, Any]
@@ -0,0 +1,177 @@
1
+ from enum import Enum
2
+ from typing import Any
3
+ from typing import Dict
4
+ from typing import List
5
+ from typing import Literal
6
+ from typing import Optional
7
+ from typing import Union
8
+
9
+ from pydantic import BaseModel
10
+ from pydantic import ConfigDict
11
+ from pydantic import Field
12
+ from pydantic.alias_generators import to_camel
13
+
14
+
15
+ class CamelBaseModel(BaseModel):
16
+ model_config = ConfigDict(
17
+ alias_generator=to_camel,
18
+ populate_by_name=True,
19
+ )
20
+
21
+
22
+ class ProxyConfig(CamelBaseModel):
23
+ server: str
24
+ username: str
25
+ password: str
26
+
27
+
28
+ class SameSite(str, Enum):
29
+ STRICT = "Strict"
30
+ LAX = "Lax"
31
+ NONE = "None"
32
+
33
+
34
+ class Cookie(CamelBaseModel):
35
+ name: str
36
+ value: str
37
+ domain: str
38
+ path: str
39
+ expires: float
40
+ http_only: bool
41
+ secure: bool
42
+ same_site: SameSite
43
+
44
+
45
+ class StorageItem(CamelBaseModel):
46
+ name: str
47
+ value: str
48
+
49
+
50
+ class Origin(CamelBaseModel):
51
+ origin: str
52
+ local_storage: List[StorageItem]
53
+
54
+
55
+ class SessionStorageOrigin(CamelBaseModel):
56
+ origin: str
57
+ session_storage: List[StorageItem]
58
+
59
+
60
+ class StorageState(CamelBaseModel):
61
+ cookies: List[Cookie]
62
+ origins: List[Origin]
63
+ session_storage: Optional[List[SessionStorageOrigin]]
64
+
65
+
66
+ class FileSession(CamelBaseModel):
67
+ type: Literal["file"] = "file"
68
+ path: str
69
+
70
+
71
+ class StateSession(CamelBaseModel):
72
+ type: Literal["state"] = "state"
73
+ state: Optional[Optional[StorageState]]
74
+
75
+
76
+ RunApiSession = Union[FileSession, StateSession]
77
+
78
+
79
+ class RunBody(CamelBaseModel):
80
+ params: dict[str, Any] | None = None
81
+ functions_token: str | None = None
82
+ proxy: Optional[ProxyConfig] = None
83
+ session: Optional[StorageState] = None
84
+
85
+
86
+ class StandaloneRunOptions(CamelBaseModel):
87
+ environment: Literal["standalone"] = "standalone"
88
+ headless: bool = True
89
+ proxy: Optional[ProxyConfig] = None
90
+
91
+
92
+ class CDPRunOptions(CamelBaseModel):
93
+ environment: Literal["cdp"] = "cdp"
94
+ cdp_address: str
95
+
96
+
97
+ class AutomationFunction(CamelBaseModel):
98
+ name: str
99
+ params: Optional[Any] = None
100
+
101
+
102
+ class TracingEnabled(CamelBaseModel):
103
+ enabled: Literal[True] = True
104
+ file_path: str
105
+
106
+
107
+ class TracingDisabled(CamelBaseModel):
108
+ enabled: Literal[False] = False
109
+
110
+
111
+ class Auth(CamelBaseModel):
112
+ session: RunApiSession
113
+ run_check: bool = False
114
+
115
+
116
+ class IntunedRunContext(CamelBaseModel):
117
+ job_id: str | None = None
118
+ job_run_id: str | None = None
119
+ run_id: str | None = None
120
+ auth_session_id: str | None = None
121
+
122
+
123
+ class RunApiParameters(CamelBaseModel):
124
+ automation_function: AutomationFunction
125
+ tracing: Union[TracingEnabled, TracingDisabled] = Field(default_factory=TracingDisabled)
126
+ auth: Optional[Auth] = None
127
+ run_options: Union[StandaloneRunOptions, CDPRunOptions] = Field(default_factory=StandaloneRunOptions)
128
+ retrieve_session: bool = False
129
+ functions_token: str | None = None
130
+ context: Optional[IntunedRunContext] = None
131
+
132
+
133
+ class RunApiResultOk(CamelBaseModel):
134
+ result: Any
135
+ extended_payloads: Optional[List[Any]] # Payload type
136
+
137
+
138
+ class RunApiResultWithSessionOk(RunApiResultOk):
139
+ session: Dict[str, Any] # IntunedStorageState type
140
+
141
+
142
+ class PayloadToAppend(CamelBaseModel):
143
+ api_name: str
144
+ parameters: Dict[str, Any]
145
+
146
+
147
+ class RunAutomationSuccessResult(CamelBaseModel):
148
+ result: Any
149
+ payload_to_append: Optional[list[PayloadToAppend]] = Field(default_factory=list[PayloadToAppend])
150
+ session: Optional[StorageState] = None
151
+
152
+
153
+ class RunAutomationErrorResult(CamelBaseModel):
154
+ error: str
155
+ message: str
156
+ status: Optional[int]
157
+ details: Optional[Any]
158
+ additional_fields: Dict[str, Any] = Field(default_factory=dict)
159
+
160
+
161
+ RunAutomationResult = Union[RunAutomationSuccessResult, RunAutomationErrorResult]
162
+
163
+
164
+ class RunAutomationResponse(CamelBaseModel):
165
+ status: int
166
+ body: RunAutomationResult
167
+
168
+
169
+ class JobPayload(CamelBaseModel):
170
+ headers: Dict[str, str] = Field(default_factory=dict)
171
+ original_payload: dict[Any, Any]
172
+ payload: RunBody
173
+ start_time: int
174
+ function_name: str
175
+ receipt_handle: str
176
+ trace_signed_url: str | None = None
177
+ session: StorageState | None = None
@@ -0,0 +1,5 @@
1
+ from runtime.helpers import extend_payload
2
+ from runtime.helpers import extend_timeout
3
+ from runtime.helpers.get_auth_session_parameters import get_auth_session_parameters
4
+
5
+ __all__ = ["extend_payload", "extend_timeout", "get_auth_session_parameters"]
File without changes