|
1 | 1 | # these are placeholders |
2 | 2 | # all these symbols will be available in browsergym actions |
3 | | -from typing import Literal |
| 3 | +import json |
| 4 | +from typing import Any, Literal |
4 | 5 |
|
5 | 6 | import playwright.sync_api |
6 | 7 |
|
|
24 | 25 | inspect.getsource(). |
25 | 26 | """ |
26 | 27 |
|
| 28 | +def send_response_to_wav( |
| 29 | + performed_operation: Literal["RETRIEVE", "MUTATE", "NAVIGATE"], |
| 30 | + status: Literal["SUCCESS", "ACTION_NOT_ALLOWED_ERROR", "NOT_FOUND_ERROR", "PERMISSION_DENIED_ERROR", "DATA_VALIDATION_ERROR", "UNKNOWN_ERROR"], |
| 31 | + retrieved_data: list[str | int | float | bool | dict[str, Any] | None] | None = None, |
| 32 | + error_details: str | None = None, |
| 33 | +): |
| 34 | + """Send the final response. |
| 35 | + Args: |
| 36 | + performed_operation: The overall type of work performed to attain the task objective. |
| 37 | + - RETRIEVE: Use when retrieving data is the main objective of the task |
| 38 | + - MUTATE: Use when creating, updating, or deleting data is the main objective of the task |
| 39 | + - NAVIGATE: Use when navigating or browsing to show a specific page or location is the main objective of the task |
| 40 | + status: The outcome of the task execution. |
| 41 | + - SUCCESS: Use when the task objective was fully achieved |
| 42 | + - ACTION_NOT_ALLOWED_ERROR: Use when the platform does not support the requested action |
| 43 | + - NOT_FOUND_ERROR: Use when the target entity or resource could not be located after retry attempts |
| 44 | + - PERMISSION_DENIED_ERROR: Use when the current user lacks permission to perform the action |
| 45 | + - DATA_VALIDATION_ERROR: Use when required input data was missing or invalid |
| 46 | + - UNKNOWN_ERROR: Use when an unexpected failure doesn't match other categories |
| 47 | + retrieved_data: Array of items for 'retrieve' operations, null for 'mutate' and 'navigate' operations. |
| 48 | + Returns empty array if no items found. All items must be the same type (either all primitives of the same type, or all objects with the same keys). |
| 49 | + Use appropriate data type formats (e.g., numbers for amounts/counts, true/false for booleans, not strings). |
| 50 | + For list of objects, the user instruction contains the format specification. |
| 51 | + error_details: Null when status is 'SUCCESS'. Otherwise, explains what failed, why it failed, and what was attempted. |
| 52 | +
|
| 53 | + Examples: |
| 54 | + send_response_to_wav("RETRIEVE", "SUCCESS", ["The city was built in 1751."]) |
| 55 | + send_response_to_wav("RETRIEVE", "SUCCESS", [{"name": "John Doe", "age": 30}]) |
| 56 | + send_response_to_wav("RETRIEVE", "SUCCESS", [0,3]) |
| 57 | + send_response_to_wav("RETRIEVE", "ACTION_NOT_ALLOWED_ERROR", None) |
| 58 | + send_response_to_wav("RETRIEVE", "NOT_FOUND_ERROR", None, "No city found.") |
| 59 | + send_response_to_wav("MUTATE", "SUCCESS", None) |
| 60 | + send_response_to_wav("MUTATE", "PERMISSION_DENIED_ERROR", None, "User lacks permission to build a city.") |
| 61 | + send_response_to_wav("NAVIGATE", "SUCCESS", None) |
| 62 | + send_response_to_wav("NAVIGATE", "DATA_VALIDATION_ERROR", None, "Invalid city name.") |
| 63 | + send_response_to_wav("NAVIGATE", "UNKNOWN_ERROR", None, "Unexpected error.") |
| 64 | +
|
| 65 | + """ |
| 66 | + final_response_dict = { |
| 67 | + "performed_operation": performed_operation, |
| 68 | + "status": status, |
| 69 | + "retrieved_data": retrieved_data, |
| 70 | + "error_details": error_details, |
| 71 | + } |
| 72 | + text = json.dumps(final_response_dict) |
| 73 | + send_message_to_user(text) |
| 74 | + |
27 | 75 |
|
28 | 76 | def send_msg_to_user(text: str): |
29 | 77 | """ |
|
0 commit comments