alita-sdk 0.3.156__py3-none-any.whl → 0.3.157__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.
- alita_sdk/tools/postman/api_wrapper.py +306 -239
- {alita_sdk-0.3.156.dist-info → alita_sdk-0.3.157.dist-info}/METADATA +1 -1
- {alita_sdk-0.3.156.dist-info → alita_sdk-0.3.157.dist-info}/RECORD +6 -6
- {alita_sdk-0.3.156.dist-info → alita_sdk-0.3.157.dist-info}/WHEEL +0 -0
- {alita_sdk-0.3.156.dist-info → alita_sdk-0.3.157.dist-info}/licenses/LICENSE +0 -0
- {alita_sdk-0.3.156.dist-info → alita_sdk-0.3.157.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,8 @@
|
|
1
|
+
import copy
|
1
2
|
import json
|
2
3
|
import logging
|
3
4
|
import re
|
4
|
-
from typing import Any, Dict, List, Optional
|
5
|
+
from typing import Any, Dict, List, Optional, Tuple
|
5
6
|
from traceback import format_exc
|
6
7
|
|
7
8
|
import requests
|
@@ -234,6 +235,18 @@ PostmanMoveRequest = create_model(
|
|
234
235
|
description="New folder path", default=None))
|
235
236
|
)
|
236
237
|
|
238
|
+
PostmanGetRequest = create_model(
|
239
|
+
"PostmanGetRequest",
|
240
|
+
request_path=(str, Field(
|
241
|
+
description="The path to the request (e.g., 'API/Users/Get User' or 'applications/recommendations')"))
|
242
|
+
)
|
243
|
+
|
244
|
+
PostmanGetRequestScript = create_model(
|
245
|
+
"PostmanGetRequestScript",
|
246
|
+
request_path=(str, Field(description="Path to the request (folder/requestName)")),
|
247
|
+
script_type=(str, Field(description="The type of script to retrieve: 'test' or 'prerequest'", default="prerequest"))
|
248
|
+
)
|
249
|
+
|
237
250
|
|
238
251
|
class PostmanApiWrapper(BaseToolApiWrapper):
|
239
252
|
"""Wrapper for Postman API."""
|
@@ -283,8 +296,14 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
283
296
|
return {}
|
284
297
|
|
285
298
|
except requests.exceptions.RequestException as e:
|
286
|
-
|
287
|
-
|
299
|
+
error_details = ""
|
300
|
+
if hasattr(e, 'response') and e.response is not None:
|
301
|
+
try:
|
302
|
+
error_details = f" Response content: {e.response.text}"
|
303
|
+
except:
|
304
|
+
error_details = f" Response status: {e.response.status_code}"
|
305
|
+
logger.error(f"Request failed: {e}{error_details}")
|
306
|
+
raise ToolException(f"Postman API request failed: {str(e)}{error_details}")
|
288
307
|
except json.JSONDecodeError as e:
|
289
308
|
logger.error(f"Failed to decode JSON response: {e}")
|
290
309
|
raise ToolException(
|
@@ -321,6 +340,20 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
321
340
|
"args_schema": PostmanGetFolderRequests,
|
322
341
|
"ref": self.get_folder_requests
|
323
342
|
},
|
343
|
+
{
|
344
|
+
"name": "get_request",
|
345
|
+
"mode": "get_request",
|
346
|
+
"description": "Get a specific request by path",
|
347
|
+
"args_schema": PostmanGetRequest,
|
348
|
+
"ref": self.get_request
|
349
|
+
},
|
350
|
+
{
|
351
|
+
"name": "get_request_script",
|
352
|
+
"mode": "get_request_script",
|
353
|
+
"description": "Get the test or pre-request script content for a specific request",
|
354
|
+
"args_schema": PostmanGetRequestScript,
|
355
|
+
"ref": self.get_request_script
|
356
|
+
},
|
324
357
|
{
|
325
358
|
"name": "search_requests",
|
326
359
|
"mode": "search_requests",
|
@@ -891,35 +924,60 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
891
924
|
logger.error(f"Exception when creating folder: {stacktrace}")
|
892
925
|
raise ToolException(f"Unable to create folder '{name}': {str(e)}")
|
893
926
|
|
927
|
+
def _get_folder_id(self, folder_path: str) -> str:
|
928
|
+
"""Helper method to get folder ID by path."""
|
929
|
+
collection = self._make_request(
|
930
|
+
'GET', f'/collections/{self.collection_id}')
|
931
|
+
collection_data = collection["collection"]
|
932
|
+
|
933
|
+
# Find the folder
|
934
|
+
folders = self.analyzer.find_folders_by_path(
|
935
|
+
collection_data["item"], folder_path)
|
936
|
+
if not folders:
|
937
|
+
raise ToolException(f"Folder '{folder_path}' not found")
|
938
|
+
|
939
|
+
folder = folders[0]
|
940
|
+
|
941
|
+
# Get the folder ID
|
942
|
+
folder_id = folder.get("id")
|
943
|
+
if not folder_id:
|
944
|
+
# If ID is not available directly, try to use the item ID
|
945
|
+
if "_postman_id" in folder:
|
946
|
+
folder_id = folder["_postman_id"]
|
947
|
+
else:
|
948
|
+
raise ToolException(f"Folder ID not found for '{folder_path}'")
|
949
|
+
|
950
|
+
return folder_id
|
951
|
+
|
894
952
|
def update_folder(self, folder_path: str, name: str = None,
|
895
953
|
description: str = None, auth: Dict = None, **kwargs) -> str:
|
896
|
-
"""Update folder properties."""
|
954
|
+
"""Update folder properties using the direct folder endpoint."""
|
897
955
|
try:
|
898
|
-
# Get
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
# Find the folder
|
904
|
-
folders = self.analyzer.find_folders_by_path(
|
905
|
-
collection_data["item"], folder_path)
|
906
|
-
if not folders:
|
907
|
-
raise ToolException(f"Folder '{folder_path}' not found")
|
908
|
-
|
909
|
-
folder = folders[0]
|
910
|
-
|
911
|
-
# Update fields if provided
|
956
|
+
# Get the folder ID
|
957
|
+
folder_id = self._get_folder_id(folder_path)
|
958
|
+
|
959
|
+
# Create update payload
|
960
|
+
folder_update = {}
|
912
961
|
if name:
|
913
|
-
|
962
|
+
folder_update["name"] = name
|
914
963
|
if description is not None:
|
915
|
-
|
964
|
+
folder_update["description"] = description
|
916
965
|
if auth is not None:
|
917
|
-
|
918
|
-
|
919
|
-
#
|
920
|
-
|
921
|
-
|
922
|
-
|
966
|
+
folder_update["auth"] = auth
|
967
|
+
|
968
|
+
# Only update if we have properties to change
|
969
|
+
if folder_update:
|
970
|
+
# Update folder using the direct API endpoint
|
971
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/folders/{folder_id}',
|
972
|
+
json=folder_update)
|
973
|
+
return json.dumps({"success": True, "message": f"Folder '{folder_path}' updated successfully"}, indent=2)
|
974
|
+
else:
|
975
|
+
return json.dumps({"success": True, "message": f"No changes requested for folder '{folder_path}'"}, indent=2)
|
976
|
+
except Exception as e:
|
977
|
+
stacktrace = format_exc()
|
978
|
+
logger.error(f"Exception when updating folder: {stacktrace}")
|
979
|
+
raise ToolException(
|
980
|
+
f"Unable to update folder '{folder_path}': {str(e)}")
|
923
981
|
except Exception as e:
|
924
982
|
stacktrace = format_exc()
|
925
983
|
logger.error(f"Exception when updating folder: {stacktrace}")
|
@@ -1063,24 +1121,18 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1063
1121
|
def update_request_name(self, request_path: str, name: str, **kwargs) -> str:
|
1064
1122
|
"""Update request name."""
|
1065
1123
|
try:
|
1066
|
-
# Get
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
collection_data["item"], request_path)
|
1074
|
-
if not request_item:
|
1075
|
-
raise ToolException(f"Request '{request_path}' not found")
|
1076
|
-
|
1077
|
-
# Update name
|
1078
|
-
request_item["name"] = name
|
1124
|
+
# Get request item and ID
|
1125
|
+
request_item, request_id, _ = self._get_request_item_and_id(request_path)
|
1126
|
+
|
1127
|
+
# Create update payload
|
1128
|
+
request_update = {
|
1129
|
+
"name": name
|
1130
|
+
}
|
1079
1131
|
|
1080
|
-
# Update
|
1081
|
-
response = self._make_request('PUT', f'/collections/{self.collection_id}',
|
1082
|
-
json=
|
1083
|
-
return json.dumps({"message": f"Request '{request_path}' name updated successfully"}, indent=2)
|
1132
|
+
# Update the name field
|
1133
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1134
|
+
json=request_update)
|
1135
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' name updated successfully"}, indent=2)
|
1084
1136
|
except Exception as e:
|
1085
1137
|
stacktrace = format_exc()
|
1086
1138
|
logger.error(f"Exception when updating request name: {stacktrace}")
|
@@ -1090,24 +1142,18 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1090
1142
|
def update_request_method(self, request_path: str, method: str, **kwargs) -> str:
|
1091
1143
|
"""Update request HTTP method."""
|
1092
1144
|
try:
|
1093
|
-
# Get
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
collection_data["item"], request_path)
|
1101
|
-
if not request_item:
|
1102
|
-
raise ToolException(f"Request '{request_path}' not found")
|
1103
|
-
|
1104
|
-
# Update method
|
1105
|
-
request_item["request"]["method"] = method.upper()
|
1145
|
+
# Get request item and ID
|
1146
|
+
request_item, request_id, _ = self._get_request_item_and_id(request_path)
|
1147
|
+
|
1148
|
+
# Create update payload
|
1149
|
+
request_update = {
|
1150
|
+
"method": method.upper()
|
1151
|
+
}
|
1106
1152
|
|
1107
|
-
# Update
|
1108
|
-
response = self._make_request('PUT', f'/collections/{self.collection_id}',
|
1109
|
-
json=
|
1110
|
-
return json.dumps({"message": f"Request '{request_path}' method updated successfully"}, indent=2)
|
1153
|
+
# Update the method field
|
1154
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1155
|
+
json=request_update)
|
1156
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' method updated successfully"}, indent=2)
|
1111
1157
|
except Exception as e:
|
1112
1158
|
stacktrace = format_exc()
|
1113
1159
|
logger.error(f"Exception when updating request method: {stacktrace}")
|
@@ -1117,51 +1163,63 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1117
1163
|
def update_request_url(self, request_path: str, url: str, **kwargs) -> str:
|
1118
1164
|
"""Update request URL."""
|
1119
1165
|
try:
|
1120
|
-
# Get
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
collection_data["item"], request_path)
|
1128
|
-
if not request_item:
|
1129
|
-
raise ToolException(f"Request '{request_path}' not found")
|
1130
|
-
|
1131
|
-
# Update URL
|
1132
|
-
request_item["request"]["url"] = url
|
1166
|
+
# Get request item and ID
|
1167
|
+
request_item, request_id, _ = self._get_request_item_and_id(request_path)
|
1168
|
+
|
1169
|
+
# Create update payload
|
1170
|
+
request_update = {
|
1171
|
+
"url": url
|
1172
|
+
}
|
1133
1173
|
|
1134
|
-
# Update
|
1135
|
-
response = self._make_request('PUT', f'/collections/{self.collection_id}',
|
1136
|
-
json=
|
1137
|
-
return json.dumps({"message": f"Request '{request_path}' URL updated successfully"}, indent=2)
|
1174
|
+
# Update the URL field
|
1175
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1176
|
+
json=request_update)
|
1177
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' URL updated successfully"}, indent=2)
|
1138
1178
|
except Exception as e:
|
1139
1179
|
stacktrace = format_exc()
|
1140
1180
|
logger.error(f"Exception when updating request URL: {stacktrace}")
|
1141
1181
|
raise ToolException(
|
1142
1182
|
f"Unable to update request '{request_path}' URL: {str(e)}")
|
1143
1183
|
|
1184
|
+
def _get_request_item_and_id(self, request_path: str) -> Tuple[Dict, str, Dict]:
|
1185
|
+
"""Helper method to get request item and ID by path. Returns (request_item, request_id, collection_data)."""
|
1186
|
+
collection = self._make_request(
|
1187
|
+
'GET', f'/collections/{self.collection_id}')
|
1188
|
+
collection_data = collection["collection"]
|
1189
|
+
|
1190
|
+
# Find the request
|
1191
|
+
request_item = self.analyzer.find_request_by_path(
|
1192
|
+
collection_data["item"], request_path)
|
1193
|
+
if not request_item:
|
1194
|
+
raise ToolException(f"Request '{request_path}' not found")
|
1195
|
+
|
1196
|
+
# Get the request ID
|
1197
|
+
request_id = request_item.get("id")
|
1198
|
+
if not request_id:
|
1199
|
+
# If ID is not available directly, try to use the full item ID path
|
1200
|
+
if "_postman_id" in request_item:
|
1201
|
+
request_id = request_item["_postman_id"]
|
1202
|
+
else:
|
1203
|
+
raise ToolException(f"Request ID not found for '{request_path}'")
|
1204
|
+
|
1205
|
+
return request_item, request_id, collection_data
|
1206
|
+
|
1144
1207
|
def update_request_description(self, request_path: str, description: str, **kwargs) -> str:
|
1145
1208
|
"""Update request description."""
|
1146
1209
|
try:
|
1147
|
-
# Get
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
if not request_item:
|
1156
|
-
raise ToolException(f"Request '{request_path}' not found")
|
1157
|
-
|
1158
|
-
# Update description
|
1159
|
-
request_item["request"]["description"] = description
|
1210
|
+
# Get request item and ID
|
1211
|
+
request_item, request_id, _ = self._get_request_item_and_id(request_path)
|
1212
|
+
|
1213
|
+
# For description update, we need to properly format the payload
|
1214
|
+
# according to Postman API requirements
|
1215
|
+
request_update = {
|
1216
|
+
"description": description
|
1217
|
+
}
|
1160
1218
|
|
1161
|
-
# Update
|
1162
|
-
response = self._make_request('PUT', f'/collections/{self.collection_id}',
|
1163
|
-
json=
|
1164
|
-
return json.dumps({"message": f"Request '{request_path}' description updated successfully"}, indent=2)
|
1219
|
+
# Update only the description field
|
1220
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1221
|
+
json=request_update)
|
1222
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' description updated successfully"}, indent=2)
|
1165
1223
|
except Exception as e:
|
1166
1224
|
stacktrace = format_exc()
|
1167
1225
|
logger.error(f"Exception when updating request description: {stacktrace}")
|
@@ -1171,24 +1229,18 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1171
1229
|
def update_request_headers(self, request_path: str, headers: List[Dict], **kwargs) -> str:
|
1172
1230
|
"""Update request headers."""
|
1173
1231
|
try:
|
1174
|
-
# Get
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
collection_data["item"], request_path)
|
1182
|
-
if not request_item:
|
1183
|
-
raise ToolException(f"Request '{request_path}' not found")
|
1184
|
-
|
1185
|
-
# Update headers
|
1186
|
-
request_item["request"]["header"] = headers
|
1232
|
+
# Get request item and ID
|
1233
|
+
request_item, request_id, _ = self._get_request_item_and_id(request_path)
|
1234
|
+
|
1235
|
+
# Create update payload
|
1236
|
+
request_update = {
|
1237
|
+
"header": headers
|
1238
|
+
}
|
1187
1239
|
|
1188
|
-
# Update
|
1189
|
-
response = self._make_request('PUT', f'/collections/{self.collection_id}',
|
1190
|
-
json=
|
1191
|
-
return json.dumps({"message": f"Request '{request_path}' headers updated successfully"}, indent=2)
|
1240
|
+
# Update the headers field
|
1241
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1242
|
+
json=request_update)
|
1243
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' headers updated successfully"}, indent=2)
|
1192
1244
|
except Exception as e:
|
1193
1245
|
stacktrace = format_exc()
|
1194
1246
|
logger.error(f"Exception when updating request headers: {stacktrace}")
|
@@ -1198,24 +1250,18 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1198
1250
|
def update_request_body(self, request_path: str, body: Dict, **kwargs) -> str:
|
1199
1251
|
"""Update request body."""
|
1200
1252
|
try:
|
1201
|
-
# Get
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
collection_data["item"], request_path)
|
1209
|
-
if not request_item:
|
1210
|
-
raise ToolException(f"Request '{request_path}' not found")
|
1211
|
-
|
1212
|
-
# Update body
|
1213
|
-
request_item["request"]["body"] = body
|
1253
|
+
# Get request item and ID
|
1254
|
+
request_item, request_id, _ = self._get_request_item_and_id(request_path)
|
1255
|
+
|
1256
|
+
# Create update payload
|
1257
|
+
request_update = {
|
1258
|
+
"body": body
|
1259
|
+
}
|
1214
1260
|
|
1215
|
-
# Update
|
1216
|
-
response = self._make_request('PUT', f'/collections/{self.collection_id}',
|
1217
|
-
json=
|
1218
|
-
return json.dumps({"message": f"Request '{request_path}' body updated successfully"}, indent=2)
|
1261
|
+
# Update the body field
|
1262
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1263
|
+
json=request_update)
|
1264
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' body updated successfully"}, indent=2)
|
1219
1265
|
except Exception as e:
|
1220
1266
|
stacktrace = format_exc()
|
1221
1267
|
logger.error(f"Exception when updating request body: {stacktrace}")
|
@@ -1225,24 +1271,18 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1225
1271
|
def update_request_auth(self, request_path: str, auth: Dict, **kwargs) -> str:
|
1226
1272
|
"""Update request authentication."""
|
1227
1273
|
try:
|
1228
|
-
# Get
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
collection_data["item"], request_path)
|
1236
|
-
if not request_item:
|
1237
|
-
raise ToolException(f"Request '{request_path}' not found")
|
1238
|
-
|
1239
|
-
# Update auth
|
1240
|
-
request_item["request"]["auth"] = auth
|
1274
|
+
# Get request item and ID
|
1275
|
+
request_item, request_id, _ = self._get_request_item_and_id(request_path)
|
1276
|
+
|
1277
|
+
# Create update payload
|
1278
|
+
request_update = {
|
1279
|
+
"auth": auth
|
1280
|
+
}
|
1241
1281
|
|
1242
|
-
# Update
|
1243
|
-
response = self._make_request('PUT', f'/collections/{self.collection_id}',
|
1244
|
-
json=
|
1245
|
-
return json.dumps({"message": f"Request '{request_path}' auth updated successfully"}, indent=2)
|
1282
|
+
# Update the auth field
|
1283
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1284
|
+
json=request_update)
|
1285
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' auth updated successfully"}, indent=2)
|
1246
1286
|
except Exception as e:
|
1247
1287
|
stacktrace = format_exc()
|
1248
1288
|
logger.error(f"Exception when updating request auth: {stacktrace}")
|
@@ -1252,35 +1292,34 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1252
1292
|
def update_request_tests(self, request_path: str, tests: str, **kwargs) -> str:
|
1253
1293
|
"""Update request test scripts."""
|
1254
1294
|
try:
|
1255
|
-
# Get
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
if
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
return json.dumps({"message": f"Request '{request_path}' tests updated successfully"}, indent=2)
|
1295
|
+
# Get the request ID
|
1296
|
+
_, request_id, _ = self._get_request_item_and_id(request_path)
|
1297
|
+
|
1298
|
+
# Get current request to preserve existing data
|
1299
|
+
current_request = self._make_request('GET', f'/collections/{self.collection_id}/requests/{request_id}')
|
1300
|
+
request_data = current_request.get("data", {})
|
1301
|
+
|
1302
|
+
# Prepare the events array - preserve any non-test events
|
1303
|
+
events = [event for event in request_data.get("events", []) if event.get("listen") != "test"]
|
1304
|
+
|
1305
|
+
# Add the new test script
|
1306
|
+
events.append({
|
1307
|
+
"listen": "test",
|
1308
|
+
"script": {
|
1309
|
+
"type": "text/javascript",
|
1310
|
+
"exec": tests.strip().split('\n')
|
1311
|
+
}
|
1312
|
+
})
|
1313
|
+
|
1314
|
+
# Update the events array in the request data
|
1315
|
+
request_data["events"] = events
|
1316
|
+
|
1317
|
+
# Update the request using the individual request endpoint
|
1318
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1319
|
+
json=request_data)
|
1320
|
+
|
1321
|
+
logger.info(f"Test script updated successfully for request '{request_path}'")
|
1322
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' tests updated successfully"}, indent=2)
|
1284
1323
|
except Exception as e:
|
1285
1324
|
stacktrace = format_exc()
|
1286
1325
|
logger.error(f"Exception when updating request tests: {stacktrace}")
|
@@ -1290,35 +1329,34 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1290
1329
|
def update_request_pre_script(self, request_path: str, pre_request_script: str, **kwargs) -> str:
|
1291
1330
|
"""Update request pre-request scripts."""
|
1292
1331
|
try:
|
1293
|
-
# Get
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
if
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
return json.dumps({"message": f"Request '{request_path}' pre-script updated successfully"}, indent=2)
|
1332
|
+
# Get the request ID
|
1333
|
+
_, request_id, _ = self._get_request_item_and_id(request_path)
|
1334
|
+
|
1335
|
+
# Get current request to preserve existing data
|
1336
|
+
current_request = self._make_request('GET', f'/collections/{self.collection_id}/requests/{request_id}')
|
1337
|
+
request_data = current_request.get("data", {})
|
1338
|
+
|
1339
|
+
# Prepare the events array - preserve any non-prerequest events
|
1340
|
+
events = [event for event in request_data.get("events", []) if event.get("listen") != "prerequest"]
|
1341
|
+
|
1342
|
+
# Add the new prerequest script
|
1343
|
+
events.append({
|
1344
|
+
"listen": "prerequest",
|
1345
|
+
"script": {
|
1346
|
+
"type": "text/javascript",
|
1347
|
+
"exec": pre_request_script.strip().split('\n')
|
1348
|
+
}
|
1349
|
+
})
|
1350
|
+
|
1351
|
+
# Update the events array in the request data
|
1352
|
+
request_data["events"] = events
|
1353
|
+
|
1354
|
+
# Update the request using the individual request endpoint
|
1355
|
+
response = self._make_request('PUT', f'/collections/{self.collection_id}/requests/{request_id}',
|
1356
|
+
json=request_data)
|
1357
|
+
|
1358
|
+
logger.info(f"Pre-request script updated successfully for request '{request_path}'")
|
1359
|
+
return json.dumps({"success": True, "message": f"Request '{request_path}' pre-script updated successfully"}, indent=2)
|
1322
1360
|
except Exception as e:
|
1323
1361
|
stacktrace = format_exc()
|
1324
1362
|
logger.error(f"Exception when updating request pre-script: {stacktrace}")
|
@@ -1444,41 +1482,70 @@ class PostmanApiWrapper(BaseToolApiWrapper):
|
|
1444
1482
|
# HELPER METHODS
|
1445
1483
|
# =================================================================
|
1446
1484
|
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1485
|
+
def get_request(self, request_path: str, **kwargs) -> str:
|
1486
|
+
"""Get a specific request by path.
|
1487
|
+
|
1488
|
+
Uses the _get_request_item_and_id helper to find the request and then fetches complete
|
1489
|
+
information using the Postman API endpoint for individual requests.
|
1490
|
+
"""
|
1453
1491
|
try:
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
logger.error(f"Failed to decode JSON response: {e}")
|
1492
|
+
# Get request item and ID
|
1493
|
+
_, request_id, _ = self._get_request_item_and_id(request_path)
|
1494
|
+
|
1495
|
+
# Fetch the complete request information from the API
|
1496
|
+
response = self._make_request(
|
1497
|
+
'GET', f'/collections/{self.collection_id}/requests/{request_id}'
|
1498
|
+
)
|
1499
|
+
|
1500
|
+
return json.dumps(response, indent=2)
|
1501
|
+
except Exception as e:
|
1502
|
+
stacktrace = format_exc()
|
1503
|
+
logger.error(f"Exception when getting request: {stacktrace}")
|
1467
1504
|
raise ToolException(
|
1468
|
-
f"
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
if
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1505
|
+
f"Unable to get request '{request_path}': {str(e)}")
|
1506
|
+
|
1507
|
+
def get_request_script(self, request_path: str, script_type: str = "prerequest", **kwargs) -> str:
|
1508
|
+
"""
|
1509
|
+
Get the script (pre-request or test) for a request by path.
|
1510
|
+
|
1511
|
+
Args:
|
1512
|
+
request_path: Path to the request within the collection
|
1513
|
+
script_type: The type of script to retrieve ("prerequest" or "test")
|
1514
|
+
|
1515
|
+
Returns:
|
1516
|
+
The script content as JSON string, or an error message if the script doesn't exist
|
1517
|
+
"""
|
1518
|
+
try:
|
1519
|
+
# Get the request ID and fetch current request data
|
1520
|
+
_, request_id, _ = self._get_request_item_and_id(request_path)
|
1521
|
+
|
1522
|
+
# Get current request to have the latest version with updated scripts
|
1523
|
+
current_request = self._make_request('GET', f'/collections/{self.collection_id}/requests/{request_id}')
|
1524
|
+
request_data = current_request.get("data", {})
|
1525
|
+
|
1526
|
+
# Find the script by type
|
1527
|
+
script_content = None
|
1528
|
+
for event in request_data.get("events", []):
|
1529
|
+
if event.get("listen") == script_type:
|
1530
|
+
script = event.get("script", {})
|
1531
|
+
exec_content = script.get("exec", [])
|
1532
|
+
if isinstance(exec_content, list):
|
1533
|
+
script_content = "\n".join(exec_content)
|
1534
|
+
else:
|
1535
|
+
script_content = str(exec_content)
|
1536
|
+
break
|
1537
|
+
|
1538
|
+
if script_content is None:
|
1539
|
+
return json.dumps({"success": False, "message": f"No {script_type} script found for request '{request_path}'"}, indent=2)
|
1540
|
+
|
1541
|
+
return json.dumps({
|
1542
|
+
"success": True,
|
1543
|
+
"script_type": script_type,
|
1544
|
+
"script_content": script_content,
|
1545
|
+
"request_path": request_path
|
1546
|
+
}, indent=2)
|
1547
|
+
|
1548
|
+
except Exception as e:
|
1549
|
+
stacktrace = format_exc()
|
1550
|
+
logger.error(f"Exception when getting request {script_type} script: {stacktrace}")
|
1551
|
+
raise ToolException(f"Unable to get {script_type} script for request '{request_path}': {str(e)}")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: alita_sdk
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.157
|
4
4
|
Summary: SDK for building langchain agents using resources from Alita
|
5
5
|
Author-email: Artem Rozumenko <artyom.rozumenko@gmail.com>, Mikalai Biazruchka <mikalai_biazruchka@epam.com>, Roman Mitusov <roman_mitusov@epam.com>, Ivan Krakhmaliuk <lifedjik@gmail.com>
|
6
6
|
License-Expression: Apache-2.0
|
@@ -273,7 +273,7 @@ alita_sdk/tools/pandas/statsmodels/descriptive.py,sha256=APdofBnEiRhMrn6tLKwH076
|
|
273
273
|
alita_sdk/tools/pandas/statsmodels/hypothesis_testing.py,sha256=fdNAayMB3W7avMfKJCcbf2_P54vUXbq8KVebOB48348,10508
|
274
274
|
alita_sdk/tools/pandas/statsmodels/regression.py,sha256=Y1pWK4u_qzrfA740K-FX0nZ5FREGGPk8mfvykPIYoiI,9164
|
275
275
|
alita_sdk/tools/postman/__init__.py,sha256=W0HdtACnTZw6tnzj7_qY_X5RoRyX3czcUSVaZJjBW-Y,4236
|
276
|
-
alita_sdk/tools/postman/api_wrapper.py,sha256=
|
276
|
+
alita_sdk/tools/postman/api_wrapper.py,sha256=G6pfCzZUok25qHkiZQvte7lrPYF3gbZX01jx0Si9MN8,66869
|
277
277
|
alita_sdk/tools/postman/postman_analysis.py,sha256=2d-Oi2UORosIePIUyncSONw9hY7dw8Zc7BQvCd4aqpg,45115
|
278
278
|
alita_sdk/tools/pptx/__init__.py,sha256=LNSTQk0BncfdWLXAOGX2WXezG3D4qSEuYwLpokmF9iM,3438
|
279
279
|
alita_sdk/tools/pptx/pptx_wrapper.py,sha256=yyCYcTlIY976kJ4VfPo4dyxj4yeii9j9TWP6W8ZIpN8,29195
|
@@ -317,8 +317,8 @@ alita_sdk/tools/zephyr_enterprise/api_wrapper.py,sha256=Ir3zHljhbZQJRJJQOBzS_GL5
|
|
317
317
|
alita_sdk/tools/zephyr_enterprise/zephyr_enterprise.py,sha256=hV9LIrYfJT6oYp-ZfQR0YHflqBFPsUw2Oc55HwK0H48,6809
|
318
318
|
alita_sdk/tools/zephyr_scale/__init__.py,sha256=2NTcdrfkx4GSegqyXhsPLsEpc4FlACuDy85b0fk6cAo,4572
|
319
319
|
alita_sdk/tools/zephyr_scale/api_wrapper.py,sha256=UHVQUVqcBc3SZvDfO78HSuBzwAsRw2cCDQa-xMOzndE,68663
|
320
|
-
alita_sdk-0.3.
|
321
|
-
alita_sdk-0.3.
|
322
|
-
alita_sdk-0.3.
|
323
|
-
alita_sdk-0.3.
|
324
|
-
alita_sdk-0.3.
|
320
|
+
alita_sdk-0.3.157.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
321
|
+
alita_sdk-0.3.157.dist-info/METADATA,sha256=IO3yoKg0xK703bmf11i1s-ifXSEuaWvZ6al0kqK6r9U,18667
|
322
|
+
alita_sdk-0.3.157.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
323
|
+
alita_sdk-0.3.157.dist-info/top_level.txt,sha256=0vJYy5p_jK6AwVb1aqXr7Kgqgk3WDtQ6t5C-XI9zkmg,10
|
324
|
+
alita_sdk-0.3.157.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|