{cause}
\",\n \"fix_notes\": \" placeholder \", # placeholder value - will not work without a fix note\n \"knowledge\": False,\n \"major_problem\": False,\n \"impact\": f\"{impact}\",\n \"active\": False,\n \"sys_domain_path\": \"/\",\n \"short_description\": f\"{short_description} {problem_hashtag}\",\n \"known_error\": False,\n \"description\": f\"{description}\",\n \"sla_due\": \"2021-04-11 17:39:07\",\n \"closed_at\": \"\",\n \"resolution_code\": \"fix_applied\",\n \"urgency\": f\"{urgency}\",\n \"assigned_to\": f\"{user_sys_id}\",\n \"active\": True,\n }\n\n result = table_api_call(\n instance=instance,\n table=\"problem\",\n json=problem_cfg,\n method=\"POST\",\n )[\"result\"]\n\n if return_number:\n return result[\"sys_id\"], result[\"number\"]\n\n return result[\"sys_id\"]","source_hash":"404afdbb05023af559733eceafd6ca91beda088acfecb48fba5bdf38b5720f53","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.problem.create_problem","uri":"program://WorkArena/function/src.browsergym.workarena.api.problem.create_problem#L9-L90","kind":"function","name":"create_problem","path":"src/browsergym/workarena/api/problem.py","language":"python","start_line":9,"end_line":90,"context_start_line":1,"context_end_line":90,"code":"import faker\n\nfake = faker.Faker()\n\nfrom ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef create_problem(\n instance: SNowInstance,\n priority: str,\n user_sys_id: str,\n problem_hashtag: str,\n short_description: str = None,\n return_number: bool = False,\n) -> list[str]:\n \"\"\"\n Create a problem with a random cause, description, and short description. The problem is assigned to a user and\n is created with a hashtag.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to create the problem in\n priority: str\n The priority of the problem\n user_sys_id: str\n The sys_id of the user to assign the problem to\n problem_hashtag: str\n The name of the hashtag for the problem\n short_description: str\n The short description of the problem (optional). if not provided, a random one will be generated\n return_number: bool\n whether or not to return the problem number that was created\n\n Returns:\n --------\n sys_id of the problem\n problem_number (optional)\n\n \"\"\"\n cause = fake.sentence()\n description = fake.text()\n if short_description is None:\n short_description = fake.sentence(4)\n\n # Priority is a read-only field defined by a combo of impact and urgency. The mapping is as follows:\n # https://docs.servicenow.com/bundle/washingtondc-it-service-management/page/product/problem-management/concept/prioritise-problems.html\n priority_to_impact_and_urgency = {\n 1: (1, 1),\n 2: (1, 2),\n 3: (1, 3),\n 4: (2, 3),\n 5: (3, 3),\n }\n\n impact, urgency = priority_to_impact_and_urgency[priority]\n\n problem_cfg = {\n \"made_sla\": True,\n \"upon_reject\": \"cancel\",\n \"cause_notes\": f\"{cause}
\",\n \"fix_notes\": \" placeholder \", # placeholder value - will not work without a fix note\n \"knowledge\": False,\n \"major_problem\": False,\n \"impact\": f\"{impact}\",\n \"active\": False,\n \"sys_domain_path\": \"/\",\n \"short_description\": f\"{short_description} {problem_hashtag}\",\n \"known_error\": False,\n \"description\": f\"{description}\",\n \"sla_due\": \"2021-04-11 17:39:07\",\n \"closed_at\": \"\",\n \"resolution_code\": \"fix_applied\",\n \"urgency\": f\"{urgency}\",\n \"assigned_to\": f\"{user_sys_id}\",\n \"active\": True,\n }\n\n result = table_api_call(\n instance=instance,\n table=\"problem\",\n json=problem_cfg,\n method=\"POST\",\n )[\"result\"]\n\n if return_number:\n return result[\"sys_id\"], result[\"number\"]\n\n return result[\"sys_id\"]","source_hash":"404afdbb05023af559733eceafd6ca91beda088acfecb48fba5bdf38b5720f53","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.report","uri":"program://WorkArena/module/src.browsergym.workarena.api.report#L1-L183","kind":"module","name":"src.browsergym.workarena.api.report","path":"src/browsergym/workarena/api/report.py","language":"python","start_line":1,"end_line":183,"context_start_line":1,"context_end_line":183,"code":"import numpy as np\n\nfrom ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef create_report(\n instance: SNowInstance,\n table: str,\n filter_hashtag: str,\n field: str,\n plot_title: str,\n filter_field: str = \"short_description\",\n random: np.random = None,\n) -> list[str]:\n \"\"\"\n Create a report for for the given table using a filter (str added to the short description).\n The report is created with a random color palette and colors and a random plot type (pie or bar).\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to create the category in\n table: str\n The name of the table used to make the plot\n field: str\n The field of the table used to make the plot\n filter_hashtag: str\n The name of the hashtag to filter the table with\n plot_title: str\n The title of the plot\n\n Returns:\n --------\n sys_id: str; sys_id of the report created\n plot_title: str; The title of the plot\n\n \"\"\"\n # select a random color palette for the plot\n color_palettes = table_api_call(\n instance=instance,\n table=\"pa_chart_color_schemes\",\n params={\n \"sysparm_fields\": \"sys_id\",\n },\n method=\"GET\",\n )[\"result\"]\n\n color_palette_sys_id = random.choice(color_palettes)[\"sys_id\"]\n\n # Get available colors to eventually randomly select from them\n colors = table_api_call(\n instance=instance,\n table=\"sys_report_color\",\n params={\n \"sysparm_fields\": \"sys_id\",\n },\n method=\"GET\",\n )[\"result\"]\n\n # Select a random plot type\n plot_types = [\"pie\", \"bar\"]\n plot_type = random.choice(plot_types)\n\n report_params = {\n \"show_data_label_position_middle\": False,\n \"display_row_lines\": False,\n \"is_published\": False,\n \"chart_title_y_position\": \"0\",\n \"gauge_autoscale\": True,\n \"type\": f\"{plot_type}\",\n \"formatting_configuration\": {\n \"table\": \"incident\",\n \"stringFormattingProperties\": {},\n \"durationFormattingProperties\": {},\n \"dateFormattingProperties\": {},\n \"numberFormattingProperties\": {},\n },\n \"apply_alias\": False,\n \"chart_border_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"custom_chart_title_position\": False,\n \"other_threshold\": \"-2\",\n \"y_axis_title_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"show_legend_border\": False,\n \"donut_width_percent\": \"30\",\n \"y_axis_title_size\": \"12\",\n \"legend_border_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"y_axis_label_bold\": False,\n \"chart_title_size\": \"16\",\n \"x_axis_label_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"active\": True,\n \"source_type\": \"table\",\n \"x_axis_title_bold\": True,\n \"x_axis_opposite\": False,\n \"chart_height\": \"450\",\n \"legend_border_radius\": \"0\",\n \"field\": field,\n \"show_geographical_label\": False,\n \"legend_horizontal_alignment\": \"center\",\n \"interval\": \"year\",\n \"show_zero\": False,\n \"y_axis_grid_width\": \"1\",\n \"chart_subtitle_size\": \"14\",\n \"x_axis_display_grid\": False,\n \"show_chart_total\": False,\n \"chart_subtitle_style\": \"normal\",\n \"chart_title_style\": \"normal\",\n \"x_axis_grid_width\": \"1\",\n \"x_axis_label_tilt\": \"0\",\n \"show_chart_title\": \"report\",\n \"title_vertical_alignment\": \"top\",\n \"legend_border_width\": \"1\",\n \"compute_percent\": \"aggregate\",\n \"show_marker\": False,\n \"sys_scope\": \"global\",\n \"map\": \"93b8a3a2d7101200bd4a4ebfae61033a\",\n \"use_color_heatmap\": False,\n \"use_null_in_trend\": False,\n \"y_axis_label_tilt\": \"0\",\n \"table\": table,\n \"legend_vertical_alignment\": \"bottom\",\n \"x_axis_label_bold\": False,\n \"no_bulk_migration\": False,\n \"filter\": f\"{filter_field}LIKE{filter_hashtag}\",\n \"display_column_lines\": False,\n \"x_axis_allow_decimals\": True,\n \"custom_chart_size\": False,\n \"title_horizontal_alignment\": \"center\",\n \"bar_unstack\": False,\n \"y_axis_allow_decimals\": True,\n \"chart_width\": \"600\",\n \"x_axis_title_size\": \"12\",\n \"y_axis_opposite\": False,\n \"y_axis_title_bold\": True,\n \"decimal_precision\": \"2\",\n \"y_axis_label_size\": \"11\",\n \"x_axis_grid_color\": f\"{random.choice(colors)['sys_id']}\",\n \"legend_align_columns\": True,\n \"field_list\": \"active,short_description,incident_state,business_duration,calendar_duration,description,caller_id,location,closed_by,impact,cmdb_ci,priority,assigned_to,activity_due,task_effective_number,company,escalation,sys_created_on,closed_at,child_incidents,state,assignment_group,category,number,business_stc\",\n \"is_scheduled\": False,\n \"others\": True,\n \"x_axis_title_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"aggregation_source\": \"no_override\",\n \"chart_title_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"y_axis_grid_dotted\": False,\n \"chart_size\": \"large\",\n \"legend_items_left_align\": False,\n \"show_chart_data_label\": False,\n \"y_axis_grid_color\": f\"{random.choice(colors)['sys_id']}\",\n \"allow_data_label_overlap\": False,\n \"chart_border_radius\": \"0\",\n \"title\": plot_title,\n \"exp_report_attrs\": True,\n \"aggregate\": \"COUNT\",\n \"y_axis_display_grid\": True,\n \"score_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"axis_max_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"b0d449b3d7332100fa6c0c12ce610383\"\n \"is_real_time\": False,\n \"show_empty\": False,\n \"direction\": \"minimize\",\n \"display_grid\": False,\n \"chart_border_width\": \"1\",\n \"funnel_neck_percent\": \"30\",\n \"show_legend\": True,\n \"set_color\": \"one_color\",\n \"color_palette\": f\"{color_palette_sys_id}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"x_axis_label_size\": \"11\",\n \"show_chart_border\": False,\n \"x_axis_grid_dotted\": False,\n \"chart_title_x_position\": \"0\",\n \"pivot_expanded\": True,\n }\n\n result = table_api_call(\n instance=instance,\n table=\"sys_report\",\n # The cmdb_model_category is the sys_id for the hardware category; computer in this case\n json=report_params,\n method=\"POST\",\n wait_for_record=True,\n )[\"result\"]\n\n return result[\"sys_id\"], plot_title","source_hash":"9cd49370ce26284f465e3966efcee20252b943bd6841b59d51c56f9741a5a5e1","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.report.create_report","uri":"program://WorkArena/function/src.browsergym.workarena.api.report.create_report#L7-L183","kind":"function","name":"create_report","path":"src/browsergym/workarena/api/report.py","language":"python","start_line":7,"end_line":183,"context_start_line":1,"context_end_line":183,"code":"import numpy as np\n\nfrom ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef create_report(\n instance: SNowInstance,\n table: str,\n filter_hashtag: str,\n field: str,\n plot_title: str,\n filter_field: str = \"short_description\",\n random: np.random = None,\n) -> list[str]:\n \"\"\"\n Create a report for for the given table using a filter (str added to the short description).\n The report is created with a random color palette and colors and a random plot type (pie or bar).\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to create the category in\n table: str\n The name of the table used to make the plot\n field: str\n The field of the table used to make the plot\n filter_hashtag: str\n The name of the hashtag to filter the table with\n plot_title: str\n The title of the plot\n\n Returns:\n --------\n sys_id: str; sys_id of the report created\n plot_title: str; The title of the plot\n\n \"\"\"\n # select a random color palette for the plot\n color_palettes = table_api_call(\n instance=instance,\n table=\"pa_chart_color_schemes\",\n params={\n \"sysparm_fields\": \"sys_id\",\n },\n method=\"GET\",\n )[\"result\"]\n\n color_palette_sys_id = random.choice(color_palettes)[\"sys_id\"]\n\n # Get available colors to eventually randomly select from them\n colors = table_api_call(\n instance=instance,\n table=\"sys_report_color\",\n params={\n \"sysparm_fields\": \"sys_id\",\n },\n method=\"GET\",\n )[\"result\"]\n\n # Select a random plot type\n plot_types = [\"pie\", \"bar\"]\n plot_type = random.choice(plot_types)\n\n report_params = {\n \"show_data_label_position_middle\": False,\n \"display_row_lines\": False,\n \"is_published\": False,\n \"chart_title_y_position\": \"0\",\n \"gauge_autoscale\": True,\n \"type\": f\"{plot_type}\",\n \"formatting_configuration\": {\n \"table\": \"incident\",\n \"stringFormattingProperties\": {},\n \"durationFormattingProperties\": {},\n \"dateFormattingProperties\": {},\n \"numberFormattingProperties\": {},\n },\n \"apply_alias\": False,\n \"chart_border_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"custom_chart_title_position\": False,\n \"other_threshold\": \"-2\",\n \"y_axis_title_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"show_legend_border\": False,\n \"donut_width_percent\": \"30\",\n \"y_axis_title_size\": \"12\",\n \"legend_border_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"y_axis_label_bold\": False,\n \"chart_title_size\": \"16\",\n \"x_axis_label_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"active\": True,\n \"source_type\": \"table\",\n \"x_axis_title_bold\": True,\n \"x_axis_opposite\": False,\n \"chart_height\": \"450\",\n \"legend_border_radius\": \"0\",\n \"field\": field,\n \"show_geographical_label\": False,\n \"legend_horizontal_alignment\": \"center\",\n \"interval\": \"year\",\n \"show_zero\": False,\n \"y_axis_grid_width\": \"1\",\n \"chart_subtitle_size\": \"14\",\n \"x_axis_display_grid\": False,\n \"show_chart_total\": False,\n \"chart_subtitle_style\": \"normal\",\n \"chart_title_style\": \"normal\",\n \"x_axis_grid_width\": \"1\",\n \"x_axis_label_tilt\": \"0\",\n \"show_chart_title\": \"report\",\n \"title_vertical_alignment\": \"top\",\n \"legend_border_width\": \"1\",\n \"compute_percent\": \"aggregate\",\n \"show_marker\": False,\n \"sys_scope\": \"global\",\n \"map\": \"93b8a3a2d7101200bd4a4ebfae61033a\",\n \"use_color_heatmap\": False,\n \"use_null_in_trend\": False,\n \"y_axis_label_tilt\": \"0\",\n \"table\": table,\n \"legend_vertical_alignment\": \"bottom\",\n \"x_axis_label_bold\": False,\n \"no_bulk_migration\": False,\n \"filter\": f\"{filter_field}LIKE{filter_hashtag}\",\n \"display_column_lines\": False,\n \"x_axis_allow_decimals\": True,\n \"custom_chart_size\": False,\n \"title_horizontal_alignment\": \"center\",\n \"bar_unstack\": False,\n \"y_axis_allow_decimals\": True,\n \"chart_width\": \"600\",\n \"x_axis_title_size\": \"12\",\n \"y_axis_opposite\": False,\n \"y_axis_title_bold\": True,\n \"decimal_precision\": \"2\",\n \"y_axis_label_size\": \"11\",\n \"x_axis_grid_color\": f\"{random.choice(colors)['sys_id']}\",\n \"legend_align_columns\": True,\n \"field_list\": \"active,short_description,incident_state,business_duration,calendar_duration,description,caller_id,location,closed_by,impact,cmdb_ci,priority,assigned_to,activity_due,task_effective_number,company,escalation,sys_created_on,closed_at,child_incidents,state,assignment_group,category,number,business_stc\",\n \"is_scheduled\": False,\n \"others\": True,\n \"x_axis_title_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"aggregation_source\": \"no_override\",\n \"chart_title_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"y_axis_grid_dotted\": False,\n \"chart_size\": \"large\",\n \"legend_items_left_align\": False,\n \"show_chart_data_label\": False,\n \"y_axis_grid_color\": f\"{random.choice(colors)['sys_id']}\",\n \"allow_data_label_overlap\": False,\n \"chart_border_radius\": \"0\",\n \"title\": plot_title,\n \"exp_report_attrs\": True,\n \"aggregate\": \"COUNT\",\n \"y_axis_display_grid\": True,\n \"score_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"axis_max_color\": f\"{random.choice(colors)['sys_id']}\", # default: \"b0d449b3d7332100fa6c0c12ce610383\"\n \"is_real_time\": False,\n \"show_empty\": False,\n \"direction\": \"minimize\",\n \"display_grid\": False,\n \"chart_border_width\": \"1\",\n \"funnel_neck_percent\": \"30\",\n \"show_legend\": True,\n \"set_color\": \"one_color\",\n \"color_palette\": f\"{color_palette_sys_id}\", # default: \"65b30218a9fe3dba0120df8611520d97\"\n \"x_axis_label_size\": \"11\",\n \"show_chart_border\": False,\n \"x_axis_grid_dotted\": False,\n \"chart_title_x_position\": \"0\",\n \"pivot_expanded\": True,\n }\n\n result = table_api_call(\n instance=instance,\n table=\"sys_report\",\n # The cmdb_model_category is the sys_id for the hardware category; computer in this case\n json=report_params,\n method=\"POST\",\n wait_for_record=True,\n )[\"result\"]\n\n return result[\"sys_id\"], plot_title","source_hash":"9cd49370ce26284f465e3966efcee20252b943bd6841b59d51c56f9741a5a5e1","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.cost_center","uri":"program://WorkArena/module/src.browsergym.workarena.api.cost_center#L1-L19","kind":"module","name":"src.browsergym.workarena.api.cost_center","path":"src/browsergym/workarena/api/cost_center.py","language":"python","start_line":1,"end_line":19,"context_start_line":1,"context_end_line":19,"code":"import warnings\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef get_cost_center_sysid(instance, cost_center_name):\n \"\"\"Get the sys_id of a cost center by its name\"\"\"\n sys_id = table_api_call(\n instance=instance,\n table=\"cmn_cost_center\",\n params={\"sysparm_query\": f\"name={cost_center_name}\", \"sysparm_fields\": \"sys_id\"},\n )[\"result\"][0]\n\n return sys_id","source_hash":"f25146421287d540d4da7c0c62903b36a8b6b47630ee8dfb86031286c68d12cc","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.cost_center.get_cost_center_sysid","uri":"program://WorkArena/function/src.browsergym.workarena.api.cost_center.get_cost_center_sysid#L11-L19","kind":"function","name":"get_cost_center_sysid","path":"src/browsergym/workarena/api/cost_center.py","language":"python","start_line":11,"end_line":19,"context_start_line":1,"context_end_line":19,"code":"import warnings\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef get_cost_center_sysid(instance, cost_center_name):\n \"\"\"Get the sys_id of a cost center by its name\"\"\"\n sys_id = table_api_call(\n instance=instance,\n table=\"cmn_cost_center\",\n params={\"sysparm_query\": f\"name={cost_center_name}\", \"sysparm_fields\": \"sys_id\"},\n )[\"result\"][0]\n\n return sys_id","source_hash":"f25146421287d540d4da7c0c62903b36a8b6b47630ee8dfb86031286c68d12cc","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.ui_themes","uri":"program://WorkArena/module/src.browsergym.workarena.api.ui_themes#L1-L35","kind":"module","name":"src.browsergym.workarena.api.ui_themes","path":"src/browsergym/workarena/api/ui_themes.py","language":"python","start_line":1,"end_line":35,"context_start_line":1,"context_end_line":35,"code":"\"\"\"\nUtility functions for UI themes\n\n\"\"\"\n\nfrom .utils import table_api_call\n\n\ndef get_workarena_theme_variants(instance):\n \"\"\"\n Get the list of available WorkArena UI themes\n\n Parameters:\n -----------\n instance: SNowInstance\n The ServiceNow instance to get the UI themes from\n\n Returns:\n --------\n list[dict]\n The list of available WorkArena UI themes and their information\n\n \"\"\"\n themes = table_api_call(\n instance=instance,\n table=\"m2m_theme_style\",\n params={\n \"sysparm_query\": \"style.type=variant\",\n \"sysparm_fields\": \"theme.name,theme.sys_id,style.name,style.sys_id\",\n \"sysparm_display_value\": True,\n },\n method=\"GET\",\n )[\"result\"]\n themes = [t for t in themes if t[\"theme.name\"] == \"WorkArena\"]\n return themes","source_hash":"f47f07867a875add020395f9135b289245d2098631b5666f84d15c5e7ddef74b","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.ui_themes.get_workarena_theme_variants","uri":"program://WorkArena/function/src.browsergym.workarena.api.ui_themes.get_workarena_theme_variants#L9-L35","kind":"function","name":"get_workarena_theme_variants","path":"src/browsergym/workarena/api/ui_themes.py","language":"python","start_line":9,"end_line":35,"context_start_line":1,"context_end_line":35,"code":"\"\"\"\nUtility functions for UI themes\n\n\"\"\"\n\nfrom .utils import table_api_call\n\n\ndef get_workarena_theme_variants(instance):\n \"\"\"\n Get the list of available WorkArena UI themes\n\n Parameters:\n -----------\n instance: SNowInstance\n The ServiceNow instance to get the UI themes from\n\n Returns:\n --------\n list[dict]\n The list of available WorkArena UI themes and their information\n\n \"\"\"\n themes = table_api_call(\n instance=instance,\n table=\"m2m_theme_style\",\n params={\n \"sysparm_query\": \"style.type=variant\",\n \"sysparm_fields\": \"theme.name,theme.sys_id,style.name,style.sys_id\",\n \"sysparm_display_value\": True,\n },\n method=\"GET\",\n )[\"result\"]\n themes = [t for t in themes if t[\"theme.name\"] == \"WorkArena\"]\n return themes","source_hash":"f47f07867a875add020395f9135b289245d2098631b5666f84d15c5e7ddef74b","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.utils","uri":"program://WorkArena/module/src.browsergym.workarena.api.utils#L1-L174","kind":"module","name":"src.browsergym.workarena.api.utils","path":"src/browsergym/workarena/api/utils.py","language":"python","start_line":1,"end_line":174,"context_start_line":1,"context_end_line":174,"code":"import requests\n\nfrom ..instance import SNowInstance\n\nfrom requests.exceptions import HTTPError\nfrom time import sleep\n\n# ServiceNow API configuration\nSNOW_API_HEADERS = {\"Content-Type\": \"application/json\", \"Accept\": \"application/json\"}\n\n\ndef table_api_call(\n instance: SNowInstance,\n table: str,\n data: dict = {},\n params: dict = {},\n json: dict = {},\n method: str = \"GET\",\n wait_for_record: bool = False,\n max_retries: int = 5,\n raise_on_wait_expired: bool = True,\n) -> dict:\n \"\"\"\n Make a call to the ServiceNow Table API\n\n Parameters:\n -----------\n instance: SNowInstance\n The ServiceNow instance to interact with\n table: str\n The name of the table to interact with\n data: dict\n The data to send with the request\n params: dict\n The parameters to pass to the API\n json: dict\n The JSON data to send with the request\n method: str\n The HTTP method to use (GET, POST, PUT, DELETE).\n wait_for_record: bool\n If True, will wait up to 2 seconds for the record to be present before returning\n max_retries: int\n The number of retries to attempt before failing\n raise_on_wait_expired: bool\n If True, will raise an exception if the record is not found after max_retries.\n Otherwise, will return an empty result.\n\n Returns:\n --------\n dict\n The JSON response from the API\n\n \"\"\"\n\n # Query API\n response = requests.request(\n method=method,\n url=instance.snow_url + f\"/api/now/table/{table}\",\n auth=instance.snow_credentials,\n headers=SNOW_API_HEADERS,\n data=data,\n params=params,\n json=json,\n )\n if method == \"POST\":\n sys_id = response.json()[\"result\"][\"sys_id\"]\n data = {}\n params = {\"sysparm_query\": f\"sys_id={sys_id}\"}\n\n # Check for HTTP success code (fail otherwise)\n response.raise_for_status()\n\n record_exists = False\n num_retries = 0\n if method == \"POST\" or wait_for_record:\n while not record_exists:\n sleep(0.5)\n get_response = table_api_call(\n instance=instance,\n table=table,\n params=params,\n json=json,\n data=data,\n method=\"GET\",\n )\n record_exists = len(get_response[\"result\"]) > 0\n num_retries += 1\n if num_retries > max_retries:\n if raise_on_wait_expired:\n raise HTTPError(f\"Record not found after {max_retries} retries\")\n else:\n return {\"result\": []}\n if method == \"GET\":\n response = get_response\n\n if method != \"DELETE\":\n # Decode the JSON response into a dictionary if necessary\n # When using wait_for_record=True, the response is already a dict as it is a recursive call\n if type(response) == dict:\n return response\n else:\n return response.json()\n else:\n return response\n\n\ndef table_column_info(instance: SNowInstance, table: str) -> dict:\n \"\"\"\n Get the column information for a ServiceNow table\n\n Parameters:\n -----------\n table: str\n The name of the table to interact with\n\n Returns:\n --------\n dict\n The JSON response from the API\n\n \"\"\"\n # Query the Meta API to get most of the column info (e.g., valid choices)\n response = requests.get(\n url=instance.snow_url + f\"/api/now/ui/meta/{table}\",\n auth=instance.snow_credentials,\n headers=SNOW_API_HEADERS,\n )\n response.raise_for_status()\n meta_info = response.json()[\"result\"][\"columns\"]\n\n # Clean column value choices\n for info in meta_info.values():\n if info.get(\"choices\", None):\n info[\"choices\"] = {c[\"value\"]: c[\"label\"] for c in info[\"choices\"]}\n\n # Query the sys_dictionnary table to find more info (e.g., is this column dependent on another)\n sys_dict_info = table_api_call(\n instance=instance,\n table=\"sys_dictionary\",\n params={\n \"sysparm_query\": f\"name={table}\",\n \"sysparm_fields\": \"element,dependent_on_field\",\n },\n )\n sys_dict_info = {d[\"element\"]: d for d in sys_dict_info[\"result\"]}\n\n # Merge information\n for k, v in meta_info.items():\n v.update(sys_dict_info.get(k, {}))\n\n return meta_info\n\n\ndef db_delete_from_table(instance: SNowInstance, sys_id: str, table: str) -> None:\n \"\"\"\n Delete an entry from a ServiceNow table using its sys_id\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the entry to delete\n table: str\n The name of the table to delete from\n\n \"\"\"\n # Query API\n response = requests.delete(\n url=instance.snow_url + f\"/api/now/table/{table}/{sys_id}\",\n auth=instance.snow_credentials,\n headers=SNOW_API_HEADERS,\n )\n\n # Check for HTTP code 200 (fail otherwise)\n response.raise_for_status()","source_hash":"b2e954d6b0ba8e20b20d5c27e4fa8f2b4002fba9be1894bfe02af36abea910d5","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.utils.table_api_call","uri":"program://WorkArena/function/src.browsergym.workarena.api.utils.table_api_call#L12-L104","kind":"function","name":"table_api_call","path":"src/browsergym/workarena/api/utils.py","language":"python","start_line":12,"end_line":104,"context_start_line":1,"context_end_line":124,"code":"import requests\n\nfrom ..instance import SNowInstance\n\nfrom requests.exceptions import HTTPError\nfrom time import sleep\n\n# ServiceNow API configuration\nSNOW_API_HEADERS = {\"Content-Type\": \"application/json\", \"Accept\": \"application/json\"}\n\n\ndef table_api_call(\n instance: SNowInstance,\n table: str,\n data: dict = {},\n params: dict = {},\n json: dict = {},\n method: str = \"GET\",\n wait_for_record: bool = False,\n max_retries: int = 5,\n raise_on_wait_expired: bool = True,\n) -> dict:\n \"\"\"\n Make a call to the ServiceNow Table API\n\n Parameters:\n -----------\n instance: SNowInstance\n The ServiceNow instance to interact with\n table: str\n The name of the table to interact with\n data: dict\n The data to send with the request\n params: dict\n The parameters to pass to the API\n json: dict\n The JSON data to send with the request\n method: str\n The HTTP method to use (GET, POST, PUT, DELETE).\n wait_for_record: bool\n If True, will wait up to 2 seconds for the record to be present before returning\n max_retries: int\n The number of retries to attempt before failing\n raise_on_wait_expired: bool\n If True, will raise an exception if the record is not found after max_retries.\n Otherwise, will return an empty result.\n\n Returns:\n --------\n dict\n The JSON response from the API\n\n \"\"\"\n\n # Query API\n response = requests.request(\n method=method,\n url=instance.snow_url + f\"/api/now/table/{table}\",\n auth=instance.snow_credentials,\n headers=SNOW_API_HEADERS,\n data=data,\n params=params,\n json=json,\n )\n if method == \"POST\":\n sys_id = response.json()[\"result\"][\"sys_id\"]\n data = {}\n params = {\"sysparm_query\": f\"sys_id={sys_id}\"}\n\n # Check for HTTP success code (fail otherwise)\n response.raise_for_status()\n\n record_exists = False\n num_retries = 0\n if method == \"POST\" or wait_for_record:\n while not record_exists:\n sleep(0.5)\n get_response = table_api_call(\n instance=instance,\n table=table,\n params=params,\n json=json,\n data=data,\n method=\"GET\",\n )\n record_exists = len(get_response[\"result\"]) > 0\n num_retries += 1\n if num_retries > max_retries:\n if raise_on_wait_expired:\n raise HTTPError(f\"Record not found after {max_retries} retries\")\n else:\n return {\"result\": []}\n if method == \"GET\":\n response = get_response\n\n if method != \"DELETE\":\n # Decode the JSON response into a dictionary if necessary\n # When using wait_for_record=True, the response is already a dict as it is a recursive call\n if type(response) == dict:\n return response\n else:\n return response.json()\n else:\n return response\n\n\ndef table_column_info(instance: SNowInstance, table: str) -> dict:\n \"\"\"\n Get the column information for a ServiceNow table\n\n Parameters:\n -----------\n table: str\n The name of the table to interact with\n\n Returns:\n --------\n dict\n The JSON response from the API\n\n \"\"\"\n # Query the Meta API to get most of the column info (e.g., valid choices)\n response = requests.get(\n url=instance.snow_url + f\"/api/now/ui/meta/{table}\",","source_hash":"b2e954d6b0ba8e20b20d5c27e4fa8f2b4002fba9be1894bfe02af36abea910d5","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.utils.table_column_info","uri":"program://WorkArena/function/src.browsergym.workarena.api.utils.table_column_info#L107-L151","kind":"function","name":"table_column_info","path":"src/browsergym/workarena/api/utils.py","language":"python","start_line":107,"end_line":151,"context_start_line":87,"context_end_line":171,"code":" num_retries += 1\n if num_retries > max_retries:\n if raise_on_wait_expired:\n raise HTTPError(f\"Record not found after {max_retries} retries\")\n else:\n return {\"result\": []}\n if method == \"GET\":\n response = get_response\n\n if method != \"DELETE\":\n # Decode the JSON response into a dictionary if necessary\n # When using wait_for_record=True, the response is already a dict as it is a recursive call\n if type(response) == dict:\n return response\n else:\n return response.json()\n else:\n return response\n\n\ndef table_column_info(instance: SNowInstance, table: str) -> dict:\n \"\"\"\n Get the column information for a ServiceNow table\n\n Parameters:\n -----------\n table: str\n The name of the table to interact with\n\n Returns:\n --------\n dict\n The JSON response from the API\n\n \"\"\"\n # Query the Meta API to get most of the column info (e.g., valid choices)\n response = requests.get(\n url=instance.snow_url + f\"/api/now/ui/meta/{table}\",\n auth=instance.snow_credentials,\n headers=SNOW_API_HEADERS,\n )\n response.raise_for_status()\n meta_info = response.json()[\"result\"][\"columns\"]\n\n # Clean column value choices\n for info in meta_info.values():\n if info.get(\"choices\", None):\n info[\"choices\"] = {c[\"value\"]: c[\"label\"] for c in info[\"choices\"]}\n\n # Query the sys_dictionnary table to find more info (e.g., is this column dependent on another)\n sys_dict_info = table_api_call(\n instance=instance,\n table=\"sys_dictionary\",\n params={\n \"sysparm_query\": f\"name={table}\",\n \"sysparm_fields\": \"element,dependent_on_field\",\n },\n )\n sys_dict_info = {d[\"element\"]: d for d in sys_dict_info[\"result\"]}\n\n # Merge information\n for k, v in meta_info.items():\n v.update(sys_dict_info.get(k, {}))\n\n return meta_info\n\n\ndef db_delete_from_table(instance: SNowInstance, sys_id: str, table: str) -> None:\n \"\"\"\n Delete an entry from a ServiceNow table using its sys_id\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the entry to delete\n table: str\n The name of the table to delete from\n\n \"\"\"\n # Query API\n response = requests.delete(\n url=instance.snow_url + f\"/api/now/table/{table}/{sys_id}\",\n auth=instance.snow_credentials,\n headers=SNOW_API_HEADERS,\n )","source_hash":"b2e954d6b0ba8e20b20d5c27e4fa8f2b4002fba9be1894bfe02af36abea910d5","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.utils.db_delete_from_table","uri":"program://WorkArena/function/src.browsergym.workarena.api.utils.db_delete_from_table#L154-L174","kind":"function","name":"db_delete_from_table","path":"src/browsergym/workarena/api/utils.py","language":"python","start_line":154,"end_line":174,"context_start_line":134,"context_end_line":174,"code":" info[\"choices\"] = {c[\"value\"]: c[\"label\"] for c in info[\"choices\"]}\n\n # Query the sys_dictionnary table to find more info (e.g., is this column dependent on another)\n sys_dict_info = table_api_call(\n instance=instance,\n table=\"sys_dictionary\",\n params={\n \"sysparm_query\": f\"name={table}\",\n \"sysparm_fields\": \"element,dependent_on_field\",\n },\n )\n sys_dict_info = {d[\"element\"]: d for d in sys_dict_info[\"result\"]}\n\n # Merge information\n for k, v in meta_info.items():\n v.update(sys_dict_info.get(k, {}))\n\n return meta_info\n\n\ndef db_delete_from_table(instance: SNowInstance, sys_id: str, table: str) -> None:\n \"\"\"\n Delete an entry from a ServiceNow table using its sys_id\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the entry to delete\n table: str\n The name of the table to delete from\n\n \"\"\"\n # Query API\n response = requests.delete(\n url=instance.snow_url + f\"/api/now/table/{table}/{sys_id}\",\n auth=instance.snow_credentials,\n headers=SNOW_API_HEADERS,\n )\n\n # Check for HTTP code 200 (fail otherwise)\n response.raise_for_status()","source_hash":"b2e954d6b0ba8e20b20d5c27e4fa8f2b4002fba9be1894bfe02af36abea910d5","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.system_properties","uri":"program://WorkArena/module/src.browsergym.workarena.api.system_properties#L1-L66","kind":"module","name":"src.browsergym.workarena.api.system_properties","path":"src/browsergym/workarena/api/system_properties.py","language":"python","start_line":1,"end_line":66,"context_start_line":1,"context_end_line":66,"code":"from .utils import table_api_call\n\n\ndef set_sys_property(instance, property_name: str, value: str):\n \"\"\"\n Set a sys_property in the instance.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to set the property in\n property_name: str\n The name of the property to set\n value: str\n The value to set for the property\n\n \"\"\"\n\n property = table_api_call(\n instance=instance,\n table=\"sys_properties\",\n params={\"sysparm_query\": f\"name={property_name}\", \"sysparm_fields\": \"sys_id\"},\n )[\"result\"]\n\n if not property:\n property_sysid = \"\"\n method = \"POST\"\n else:\n property_sysid = \"/\" + property[0][\"sys_id\"]\n method = \"PUT\"\n\n property = table_api_call(\n instance=instance,\n table=f\"sys_properties{property_sysid}\",\n method=method,\n json={\"name\": property_name, \"value\": value},\n )\n\n # Verify that the property was updated\n assert property[\"result\"][\"value\"] == value, f\"Error setting {property_name}.\"\n\n\ndef get_sys_property(instance, property_name: str) -> str:\n \"\"\"\n Get a sys_property from the instance.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to get the property from\n property_name: str\n The name of the property to get\n\n Returns:\n --------\n str\n The value of the property\n\n \"\"\"\n property_value = table_api_call(\n instance=instance,\n table=\"sys_properties\",\n params={\"sysparm_query\": f\"name={property_name}\", \"sysparm_fields\": \"value\"},\n )[\"result\"][0][\"value\"]\n\n return property_value","source_hash":"f83cac1ee5137c7f36b6440639a94d76daa5fb6c9e196107e5005a613a412a1e","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.system_properties.set_sys_property","uri":"program://WorkArena/function/src.browsergym.workarena.api.system_properties.set_sys_property#L4-L40","kind":"function","name":"set_sys_property","path":"src/browsergym/workarena/api/system_properties.py","language":"python","start_line":4,"end_line":40,"context_start_line":1,"context_end_line":60,"code":"from .utils import table_api_call\n\n\ndef set_sys_property(instance, property_name: str, value: str):\n \"\"\"\n Set a sys_property in the instance.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to set the property in\n property_name: str\n The name of the property to set\n value: str\n The value to set for the property\n\n \"\"\"\n\n property = table_api_call(\n instance=instance,\n table=\"sys_properties\",\n params={\"sysparm_query\": f\"name={property_name}\", \"sysparm_fields\": \"sys_id\"},\n )[\"result\"]\n\n if not property:\n property_sysid = \"\"\n method = \"POST\"\n else:\n property_sysid = \"/\" + property[0][\"sys_id\"]\n method = \"PUT\"\n\n property = table_api_call(\n instance=instance,\n table=f\"sys_properties{property_sysid}\",\n method=method,\n json={\"name\": property_name, \"value\": value},\n )\n\n # Verify that the property was updated\n assert property[\"result\"][\"value\"] == value, f\"Error setting {property_name}.\"\n\n\ndef get_sys_property(instance, property_name: str) -> str:\n \"\"\"\n Get a sys_property from the instance.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to get the property from\n property_name: str\n The name of the property to get\n\n Returns:\n --------\n str\n The value of the property\n\n \"\"\"\n property_value = table_api_call(","source_hash":"f83cac1ee5137c7f36b6440639a94d76daa5fb6c9e196107e5005a613a412a1e","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.system_properties.get_sys_property","uri":"program://WorkArena/function/src.browsergym.workarena.api.system_properties.get_sys_property#L43-L66","kind":"function","name":"get_sys_property","path":"src/browsergym/workarena/api/system_properties.py","language":"python","start_line":43,"end_line":66,"context_start_line":23,"context_end_line":66,"code":" )[\"result\"]\n\n if not property:\n property_sysid = \"\"\n method = \"POST\"\n else:\n property_sysid = \"/\" + property[0][\"sys_id\"]\n method = \"PUT\"\n\n property = table_api_call(\n instance=instance,\n table=f\"sys_properties{property_sysid}\",\n method=method,\n json={\"name\": property_name, \"value\": value},\n )\n\n # Verify that the property was updated\n assert property[\"result\"][\"value\"] == value, f\"Error setting {property_name}.\"\n\n\ndef get_sys_property(instance, property_name: str) -> str:\n \"\"\"\n Get a sys_property from the instance.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to get the property from\n property_name: str\n The name of the property to get\n\n Returns:\n --------\n str\n The value of the property\n\n \"\"\"\n property_value = table_api_call(\n instance=instance,\n table=\"sys_properties\",\n params={\"sysparm_query\": f\"name={property_name}\", \"sysparm_fields\": \"value\"},\n )[\"result\"][0][\"value\"]\n\n return property_value","source_hash":"f83cac1ee5137c7f36b6440639a94d76daa5fb6c9e196107e5005a613a412a1e","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.change_request","uri":"program://WorkArena/module/src.browsergym.workarena.api.change_request#L1-L87","kind":"module","name":"src.browsergym.workarena.api.change_request","path":"src/browsergym/workarena/api/change_request.py","language":"python","start_line":1,"end_line":87,"context_start_line":1,"context_end_line":87,"code":"import faker\nimport numpy as np\n\nfake = faker.Faker()\n\nfrom datetime import datetime, timedelta\n\nfrom .category import get_categories\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_change_request(\n instance: SNowInstance,\n user_sys_id: str,\n impact: int,\n risk: int,\n start_date: datetime = \"\",\n end_date: datetime = \"\",\n hashtag: str = \"\",\n short_description: str = None,\n random: np.random = None,\n) -> list[str]:\n \"\"\"\n Create a change request\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to create the change request in\n user_sys_id: str\n The sys_id of the user to assign the problem to\n impact: str\n The impact of the change request; ranges from 1 (high) to 3 (low)\n risk: str\n The risk of the change request; ranges from 2 (high) to 4 (low)\n start_date: datetime.datetime\n The start date of the change request; empty if not set\n end_date: datetime.datetime\n The end date of the change request; empty if not set\n hashtag: str\n The name of the hashtag for the change request. If \"\", no hashtag will be added\n short_description: str\n The short description of the change request. If None, a random sentence will be generated\n random: np.random\n The random number generator\n\n Returns:\n --------\n sys_id of the change request\n number of the change request\n\n \"\"\"\n if short_description is None:\n short_description = fake.sentence(4)\n categories = get_categories(instance=instance, list_name=\"change_request\")\n category = random.choice(categories)\n\n cfg = {\n \"reason\": \"broken\",\n \"upon_reject\": \"cancel\",\n \"type\": \"emergency\",\n \"state\": \"-5\",\n \"phase\": \"requested\",\n \"impact\": str(impact),\n \"active\": \"true\",\n \"short_description\": short_description + \" \" + hashtag,\n \"assigned_to\": user_sys_id,\n \"start_date\": str(start_date),\n \"end_date\": str(end_date),\n \"upon_approval\": \"proceed\",\n \"justification\": fake.sentence(),\n \"implementation_plan\": fake.sentence(),\n \"phase_state\": \"open\",\n \"risk\": str(risk),\n \"cab_required\": \"false\",\n \"category\": category,\n }\n result = table_api_call(\n instance=instance,\n table=\"change_request\",\n method=\"POST\",\n json=cfg,\n )[\"result\"]\n\n return result[\"sys_id\"], result[\"number\"]","source_hash":"f59e6e3f6df1d3c5ae25aa359dad6d80cfc1f03998a01e2f8e27a3850a260c2c","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.change_request.create_change_request","uri":"program://WorkArena/function/src.browsergym.workarena.api.change_request.create_change_request#L14-L87","kind":"function","name":"create_change_request","path":"src/browsergym/workarena/api/change_request.py","language":"python","start_line":14,"end_line":87,"context_start_line":1,"context_end_line":87,"code":"import faker\nimport numpy as np\n\nfake = faker.Faker()\n\nfrom datetime import datetime, timedelta\n\nfrom .category import get_categories\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_change_request(\n instance: SNowInstance,\n user_sys_id: str,\n impact: int,\n risk: int,\n start_date: datetime = \"\",\n end_date: datetime = \"\",\n hashtag: str = \"\",\n short_description: str = None,\n random: np.random = None,\n) -> list[str]:\n \"\"\"\n Create a change request\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to create the change request in\n user_sys_id: str\n The sys_id of the user to assign the problem to\n impact: str\n The impact of the change request; ranges from 1 (high) to 3 (low)\n risk: str\n The risk of the change request; ranges from 2 (high) to 4 (low)\n start_date: datetime.datetime\n The start date of the change request; empty if not set\n end_date: datetime.datetime\n The end date of the change request; empty if not set\n hashtag: str\n The name of the hashtag for the change request. If \"\", no hashtag will be added\n short_description: str\n The short description of the change request. If None, a random sentence will be generated\n random: np.random\n The random number generator\n\n Returns:\n --------\n sys_id of the change request\n number of the change request\n\n \"\"\"\n if short_description is None:\n short_description = fake.sentence(4)\n categories = get_categories(instance=instance, list_name=\"change_request\")\n category = random.choice(categories)\n\n cfg = {\n \"reason\": \"broken\",\n \"upon_reject\": \"cancel\",\n \"type\": \"emergency\",\n \"state\": \"-5\",\n \"phase\": \"requested\",\n \"impact\": str(impact),\n \"active\": \"true\",\n \"short_description\": short_description + \" \" + hashtag,\n \"assigned_to\": user_sys_id,\n \"start_date\": str(start_date),\n \"end_date\": str(end_date),\n \"upon_approval\": \"proceed\",\n \"justification\": fake.sentence(),\n \"implementation_plan\": fake.sentence(),\n \"phase_state\": \"open\",\n \"risk\": str(risk),\n \"cab_required\": \"false\",\n \"category\": category,\n }\n result = table_api_call(\n instance=instance,\n table=\"change_request\",\n method=\"POST\",\n json=cfg,\n )[\"result\"]\n\n return result[\"sys_id\"], result[\"number\"]","source_hash":"f59e6e3f6df1d3c5ae25aa359dad6d80cfc1f03998a01e2f8e27a3850a260c2c","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.knowledge","uri":"program://WorkArena/module/src.browsergym.workarena.api.knowledge#L1-L29","kind":"module","name":"src.browsergym.workarena.api.knowledge","path":"src/browsergym/workarena/api/knowledge.py","language":"python","start_line":1,"end_line":29,"context_start_line":1,"context_end_line":29,"code":"from ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef give_kb_read_permissions(admin_instance, user_sys_id, user_name, kb_sys_id, kb_name):\n # Need admin permissions to give KB permissions to the user\n\n # Create user criteria\n user_criteria_data = {\n \"user\": user_sys_id,\n \"name\": f\"{user_name} read KB\",\n \"short_description\": f\"Let {user_name} read {kb_name}\",\n }\n criteria_response = table_api_call(\n instance=admin_instance, table=\"user_criteria\", json=user_criteria_data, method=\"POST\"\n )[\"result\"]\n criteria_sys_id = criteria_response[\"sys_id\"]\n\n # Add user criteria entry to allow users to access the ADHOC KB\n kb_uc_can_read_mtom_data = {\n \"user_criteria\": criteria_sys_id,\n \"kb_knowledge_base\": kb_sys_id,\n }\n _ = table_api_call(\n instance=admin_instance,\n table=\"kb_uc_can_read_mtom\",\n json=kb_uc_can_read_mtom_data,\n method=\"POST\",\n )[\"result\"]","source_hash":"94fbcd0d7c02f4df5998ebdea8b57047d07ab588fc0c3a278f69f77eed40a034","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.knowledge.give_kb_read_permissions","uri":"program://WorkArena/function/src.browsergym.workarena.api.knowledge.give_kb_read_permissions#L5-L29","kind":"function","name":"give_kb_read_permissions","path":"src/browsergym/workarena/api/knowledge.py","language":"python","start_line":5,"end_line":29,"context_start_line":1,"context_end_line":29,"code":"from ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef give_kb_read_permissions(admin_instance, user_sys_id, user_name, kb_sys_id, kb_name):\n # Need admin permissions to give KB permissions to the user\n\n # Create user criteria\n user_criteria_data = {\n \"user\": user_sys_id,\n \"name\": f\"{user_name} read KB\",\n \"short_description\": f\"Let {user_name} read {kb_name}\",\n }\n criteria_response = table_api_call(\n instance=admin_instance, table=\"user_criteria\", json=user_criteria_data, method=\"POST\"\n )[\"result\"]\n criteria_sys_id = criteria_response[\"sys_id\"]\n\n # Add user criteria entry to allow users to access the ADHOC KB\n kb_uc_can_read_mtom_data = {\n \"user_criteria\": criteria_sys_id,\n \"kb_knowledge_base\": kb_sys_id,\n }\n _ = table_api_call(\n instance=admin_instance,\n table=\"kb_uc_can_read_mtom\",\n json=kb_uc_can_read_mtom_data,\n method=\"POST\",\n )[\"result\"]","source_hash":"94fbcd0d7c02f4df5998ebdea8b57047d07ab588fc0c3a278f69f77eed40a034","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.user","uri":"program://WorkArena/module/src.browsergym.workarena.api.user#L1-L156","kind":"module","name":"src.browsergym.workarena.api.user","path":"src/browsergym/workarena/api/user.py","language":"python","start_line":1,"end_line":156,"context_start_line":1,"context_end_line":156,"code":"from faker import Faker\nimport numpy as np\nimport time\n\nfake = Faker()\n\nfrom ..instance import SNowInstance\nfrom .ui_themes import get_workarena_theme_variants\nfrom .utils import table_api_call\n\n\ndef create_user(\n instance: SNowInstance,\n first_name: str = None,\n last_name: str = None,\n user_name: str = None,\n return_full_response: bool = False,\n user_roles: list[str] = [\"admin\"],\n random: np.random = np.random,\n) -> list[str]:\n \"\"\"\n Create a user with a random username and password with an admin role\n\n Parameters:\n -----------\n first_name: str\n The first name of the user, defaults to a random first name\n last_name: str\n The last name of the user, defaults to a random last name\n user_name: str\n The user name of the user, defaults to first_name.last_name\n user_roles: list[str]\n The roles to assign to the user, defaults to ['admin']\n\n Returns:\n --------\n username, password, sys_id\n\n \"\"\"\n user_idx = str(random.randint(1000, 9999))\n user_password = \"aStrongPassword!\"\n first_name = fake.first_name() if not first_name else first_name\n last_name = fake.last_name() if not last_name else last_name\n\n # Create user\n user_data = {\n \"user_name\": f\"{first_name}.{last_name}.{user_idx}\" if not user_name else user_name,\n \"first_name\": first_name,\n \"last_name\": last_name,\n \"email\": f\"{first_name}.{last_name}.{user_idx}@workarena.com\".lower(),\n \"user_password\": user_password,\n \"active\": True,\n }\n user_params = {\"sysparm_input_display_value\": True}\n user_response = table_api_call(\n instance=instance, table=\"sys_user\", json=user_data, params=user_params, method=\"POST\"\n )[\"result\"]\n user_name = user_response[\"user_name\"]\n user_sys_id = user_response[\"sys_id\"]\n\n # Get role sys_id's\n for role in user_roles:\n role_sys_id = table_api_call(\n instance=instance,\n table=\"sys_user_role\",\n params={\"sysparm_query\": f\"name={role}\", \"sysparm_fields\": \"sys_id\"},\n method=\"GET\",\n )[\"result\"][0][\"sys_id\"]\n\n # Give admin permissions\n association_data = {\"user\": user_sys_id, \"role\": role_sys_id}\n table_api_call(\n instance=instance, table=\"sys_user_has_role\", json=association_data, method=\"POST\"\n )\n\n # Randomly pick a UI theme and set it for the user\n themes = get_workarena_theme_variants(instance)\n theme = random.choice(themes)\n set_user_preference(\n instance, \"glide.ui.polaris.theme.variant\", theme[\"style.sys_id\"], user=user_sys_id\n )\n if return_full_response:\n return user_response\n return user_name, user_password, user_sys_id\n\n\ndef set_user_preference(instance: SNowInstance, key: str, value: str, user=None) -> dict:\n \"\"\"\n Set a user preference in the ServiceNow instance\n\n Parameters:\n -----------\n key: str\n The name of the preference\n value: str\n The value of the preference\n user: str\n The sys_id of the user. If None, the preference will be set globally.\n\n Returns:\n --------\n dict\n The preference that was set\n\n \"\"\"\n if user is None:\n # make it global\n user = \"\"\n system = True\n else:\n system = False\n\n # Try to get the preference's sys_id\n preference = table_api_call(\n instance=instance,\n table=\"sys_user_preference\",\n params={\"sysparm_query\": f\"name={key},user={user}\", \"sysparm_fields\": \"sys_id\"},\n )[\"result\"]\n\n if not preference:\n # ... The preference key doesn't exist, create it\n pref_sysid = \"\"\n method = \"POST\"\n else:\n # ... The preference key exists, update it\n pref_sysid = \"/\" + preference[0][\"sys_id\"]\n method = \"PUT\"\n\n property = table_api_call(\n instance=instance,\n table=f\"sys_user_preference{pref_sysid}\",\n method=method,\n json={\n \"name\": key,\n \"value\": value,\n \"user\": user,\n \"system\": system,\n \"description\": \"Updated by WorkArena\",\n },\n )[\"result\"]\n\n # Verify that the property was updated\n property[\"user\"] = (\n property[\"user\"].get(\"value\") if isinstance(property[\"user\"], dict) else property[\"user\"]\n )\n assert (\n property[\"value\"] == value\n ), f\"Error setting system property {key}, incorrect value {property['value']}, while expecting {value}.\"\n assert (\n property[\"user\"] == user\n ), f\"Error setting system property {key}, incorrect user {property['user']}, while expecting {user}.\"\n assert (\n property[\"system\"] == str(system).lower()\n ), f\"Error setting {key}, incorrect system {property['system']}, while expecting {system}.\"\n\n return property","source_hash":"98bc7caf8445540bb0ebae75e319e2bf9b27fcee24c2302c55ffa20900bd6899","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.user.create_user","uri":"program://WorkArena/function/src.browsergym.workarena.api.user.create_user#L12-L84","kind":"function","name":"create_user","path":"src/browsergym/workarena/api/user.py","language":"python","start_line":12,"end_line":84,"context_start_line":1,"context_end_line":104,"code":"from faker import Faker\nimport numpy as np\nimport time\n\nfake = Faker()\n\nfrom ..instance import SNowInstance\nfrom .ui_themes import get_workarena_theme_variants\nfrom .utils import table_api_call\n\n\ndef create_user(\n instance: SNowInstance,\n first_name: str = None,\n last_name: str = None,\n user_name: str = None,\n return_full_response: bool = False,\n user_roles: list[str] = [\"admin\"],\n random: np.random = np.random,\n) -> list[str]:\n \"\"\"\n Create a user with a random username and password with an admin role\n\n Parameters:\n -----------\n first_name: str\n The first name of the user, defaults to a random first name\n last_name: str\n The last name of the user, defaults to a random last name\n user_name: str\n The user name of the user, defaults to first_name.last_name\n user_roles: list[str]\n The roles to assign to the user, defaults to ['admin']\n\n Returns:\n --------\n username, password, sys_id\n\n \"\"\"\n user_idx = str(random.randint(1000, 9999))\n user_password = \"aStrongPassword!\"\n first_name = fake.first_name() if not first_name else first_name\n last_name = fake.last_name() if not last_name else last_name\n\n # Create user\n user_data = {\n \"user_name\": f\"{first_name}.{last_name}.{user_idx}\" if not user_name else user_name,\n \"first_name\": first_name,\n \"last_name\": last_name,\n \"email\": f\"{first_name}.{last_name}.{user_idx}@workarena.com\".lower(),\n \"user_password\": user_password,\n \"active\": True,\n }\n user_params = {\"sysparm_input_display_value\": True}\n user_response = table_api_call(\n instance=instance, table=\"sys_user\", json=user_data, params=user_params, method=\"POST\"\n )[\"result\"]\n user_name = user_response[\"user_name\"]\n user_sys_id = user_response[\"sys_id\"]\n\n # Get role sys_id's\n for role in user_roles:\n role_sys_id = table_api_call(\n instance=instance,\n table=\"sys_user_role\",\n params={\"sysparm_query\": f\"name={role}\", \"sysparm_fields\": \"sys_id\"},\n method=\"GET\",\n )[\"result\"][0][\"sys_id\"]\n\n # Give admin permissions\n association_data = {\"user\": user_sys_id, \"role\": role_sys_id}\n table_api_call(\n instance=instance, table=\"sys_user_has_role\", json=association_data, method=\"POST\"\n )\n\n # Randomly pick a UI theme and set it for the user\n themes = get_workarena_theme_variants(instance)\n theme = random.choice(themes)\n set_user_preference(\n instance, \"glide.ui.polaris.theme.variant\", theme[\"style.sys_id\"], user=user_sys_id\n )\n if return_full_response:\n return user_response\n return user_name, user_password, user_sys_id\n\n\ndef set_user_preference(instance: SNowInstance, key: str, value: str, user=None) -> dict:\n \"\"\"\n Set a user preference in the ServiceNow instance\n\n Parameters:\n -----------\n key: str\n The name of the preference\n value: str\n The value of the preference\n user: str\n The sys_id of the user. If None, the preference will be set globally.\n\n Returns:\n --------\n dict\n The preference that was set\n","source_hash":"98bc7caf8445540bb0ebae75e319e2bf9b27fcee24c2302c55ffa20900bd6899","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.user.set_user_preference","uri":"program://WorkArena/function/src.browsergym.workarena.api.user.set_user_preference#L87-L156","kind":"function","name":"set_user_preference","path":"src/browsergym/workarena/api/user.py","language":"python","start_line":87,"end_line":156,"context_start_line":67,"context_end_line":156,"code":" method=\"GET\",\n )[\"result\"][0][\"sys_id\"]\n\n # Give admin permissions\n association_data = {\"user\": user_sys_id, \"role\": role_sys_id}\n table_api_call(\n instance=instance, table=\"sys_user_has_role\", json=association_data, method=\"POST\"\n )\n\n # Randomly pick a UI theme and set it for the user\n themes = get_workarena_theme_variants(instance)\n theme = random.choice(themes)\n set_user_preference(\n instance, \"glide.ui.polaris.theme.variant\", theme[\"style.sys_id\"], user=user_sys_id\n )\n if return_full_response:\n return user_response\n return user_name, user_password, user_sys_id\n\n\ndef set_user_preference(instance: SNowInstance, key: str, value: str, user=None) -> dict:\n \"\"\"\n Set a user preference in the ServiceNow instance\n\n Parameters:\n -----------\n key: str\n The name of the preference\n value: str\n The value of the preference\n user: str\n The sys_id of the user. If None, the preference will be set globally.\n\n Returns:\n --------\n dict\n The preference that was set\n\n \"\"\"\n if user is None:\n # make it global\n user = \"\"\n system = True\n else:\n system = False\n\n # Try to get the preference's sys_id\n preference = table_api_call(\n instance=instance,\n table=\"sys_user_preference\",\n params={\"sysparm_query\": f\"name={key},user={user}\", \"sysparm_fields\": \"sys_id\"},\n )[\"result\"]\n\n if not preference:\n # ... The preference key doesn't exist, create it\n pref_sysid = \"\"\n method = \"POST\"\n else:\n # ... The preference key exists, update it\n pref_sysid = \"/\" + preference[0][\"sys_id\"]\n method = \"PUT\"\n\n property = table_api_call(\n instance=instance,\n table=f\"sys_user_preference{pref_sysid}\",\n method=method,\n json={\n \"name\": key,\n \"value\": value,\n \"user\": user,\n \"system\": system,\n \"description\": \"Updated by WorkArena\",\n },\n )[\"result\"]\n\n # Verify that the property was updated\n property[\"user\"] = (\n property[\"user\"].get(\"value\") if isinstance(property[\"user\"], dict) else property[\"user\"]\n )\n assert (\n property[\"value\"] == value\n ), f\"Error setting system property {key}, incorrect value {property['value']}, while expecting {value}.\"\n assert (\n property[\"user\"] == user\n ), f\"Error setting system property {key}, incorrect user {property['user']}, while expecting {user}.\"\n assert (\n property[\"system\"] == str(system).lower()\n ), f\"Error setting {key}, incorrect system {property['system']}, while expecting {system}.\"\n\n return property","source_hash":"98bc7caf8445540bb0ebae75e319e2bf9b27fcee24c2302c55ffa20900bd6899","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.requests","uri":"program://WorkArena/module/src.browsergym.workarena.api.requests#L1-L155","kind":"module","name":"src.browsergym.workarena.api.requests","path":"src/browsergym/workarena/api/requests.py","language":"python","start_line":1,"end_line":155,"context_start_line":1,"context_end_line":155,"code":"\"\"\"\nAPI to interact with requests in ServiceNow\n\n\"\"\"\n\nimport json\n\nfrom collections import defaultdict\n\nfrom .utils import SNowInstance, table_api_call, db_delete_from_table\n\n\ndef delete_request(instance: SNowInstance, sys_id: str) -> None:\n \"\"\"\n Deletes a request from an instance along with all its items and their options\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the request to delete\n\n \"\"\"\n # Delete all items\n for item in get_request_items(instance, sys_id):\n # Delete all options for each item\n for option in item[\"options\"].values():\n db_delete_from_table(\n instance,\n option[\"sys_ids\"][\"sc_item_option_mtom\"],\n \"sc_item_option_mtom\",\n )\n db_delete_from_table(instance, option[\"sys_ids\"][\"sc_item_option\"], \"sc_item_option\")\n db_delete_from_table(instance, item[\"sys_id\"], \"sc_req_item\")\n\n # Delete the request\n db_delete_from_table(instance, sys_id, \"sc_request\")\n\n\ndef get_all_requests(instance: SNowInstance, since_minutes: int = 99999999999) -> list:\n \"\"\"\n Retrives a list of all requests from an instance\n\n Parameters:\n -----------\n since_minutes: int\n The number of minutes to look back for requests (used to avoid getting too many requests)\n\n Returns:\n --------\n list\n A list of all requests from an instance (as dicts)\n\n \"\"\"\n # Filter for requests that were created in the time frame\n query = f\"sys_created_on>=javascript:gs.minutesAgoStart({since_minutes})\"\n\n # Get all requests\n requests_ = table_api_call(\n instance, table=\"sc_request\", method=\"GET\", params={\"sysparm_query\": query}\n )[\"result\"]\n\n # For each request, get the items that were ordered\n for request in requests_:\n request[\"items\"] = get_request_items(instance, request[\"sys_id\"])\n\n return requests_\n\n\ndef get_request_by_id(instance: SNowInstance, sysid: str) -> dict:\n \"\"\"\n Get a request by its sys_id\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to get the request from\n sysid: str\n The sys_id of the request to get\n\n Returns:\n --------\n dict\n A dictionary containing the details of the request\n\n \"\"\"\n # Get the request\n request = table_api_call(\n instance,\n table=f\"sc_request\",\n method=\"GET\",\n params={\"sysparm_query\": f\"sys_id={sysid}\"},\n )[\"result\"]\n\n if len(request) == 0:\n return None\n request = request[0]\n\n # Get the items that were ordered\n request[\"items\"] = get_request_items(instance, request[\"sys_id\"])\n\n return request\n\n\ndef get_request_items(instance: SNowInstance, sys_id: str) -> list[dict]:\n \"\"\"\n Get all items that were ordered as part of a request\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the request to get items for\n\n Returns:\n --------\n list\n A list of dicts containing the items\n\n \"\"\"\n # Get all items in the request\n items = table_api_call(\n instance=instance,\n table=\"sc_req_item\",\n params={\n \"sysparm_query\": f\"request={sys_id}\",\n \"sysparm_fields\": \",\".join(\n [\n \"sys_id\",\n \"short_description\",\n \"quantity\",\n ]\n ),\n },\n )[\"result\"]\n\n # For each item, get the options that were selected (if there are any)\n for item in items:\n options = table_api_call(\n instance=instance,\n table=\"sc_item_option_mtom\",\n params={\n \"sysparm_query\": f\"request_item={item['sys_id']}\",\n \"sysparm_fields\": \",\".join(\n [\n \"sc_item_option.value\",\n \"sc_item_option.item_option_new.question_text\",\n ]\n ),\n },\n )[\"result\"]\n item[\"options\"] = {\n opt[\"sc_item_option.item_option_new.question_text\"]: opt[\"sc_item_option.value\"]\n for opt in options\n }\n\n return items","source_hash":"cf6bd04d3926d47474e3f77fa5c7ba8e8a6e37ef8e874814693f9886b55af7ef","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.requests.delete_request","uri":"program://WorkArena/function/src.browsergym.workarena.api.requests.delete_request#L13-L36","kind":"function","name":"delete_request","path":"src/browsergym/workarena/api/requests.py","language":"python","start_line":13,"end_line":36,"context_start_line":1,"context_end_line":56,"code":"\"\"\"\nAPI to interact with requests in ServiceNow\n\n\"\"\"\n\nimport json\n\nfrom collections import defaultdict\n\nfrom .utils import SNowInstance, table_api_call, db_delete_from_table\n\n\ndef delete_request(instance: SNowInstance, sys_id: str) -> None:\n \"\"\"\n Deletes a request from an instance along with all its items and their options\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the request to delete\n\n \"\"\"\n # Delete all items\n for item in get_request_items(instance, sys_id):\n # Delete all options for each item\n for option in item[\"options\"].values():\n db_delete_from_table(\n instance,\n option[\"sys_ids\"][\"sc_item_option_mtom\"],\n \"sc_item_option_mtom\",\n )\n db_delete_from_table(instance, option[\"sys_ids\"][\"sc_item_option\"], \"sc_item_option\")\n db_delete_from_table(instance, item[\"sys_id\"], \"sc_req_item\")\n\n # Delete the request\n db_delete_from_table(instance, sys_id, \"sc_request\")\n\n\ndef get_all_requests(instance: SNowInstance, since_minutes: int = 99999999999) -> list:\n \"\"\"\n Retrives a list of all requests from an instance\n\n Parameters:\n -----------\n since_minutes: int\n The number of minutes to look back for requests (used to avoid getting too many requests)\n\n Returns:\n --------\n list\n A list of all requests from an instance (as dicts)\n\n \"\"\"\n # Filter for requests that were created in the time frame\n query = f\"sys_created_on>=javascript:gs.minutesAgoStart({since_minutes})\"\n","source_hash":"cf6bd04d3926d47474e3f77fa5c7ba8e8a6e37ef8e874814693f9886b55af7ef","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.requests.get_all_requests","uri":"program://WorkArena/function/src.browsergym.workarena.api.requests.get_all_requests#L39-L66","kind":"function","name":"get_all_requests","path":"src/browsergym/workarena/api/requests.py","language":"python","start_line":39,"end_line":66,"context_start_line":19,"context_end_line":86,"code":" sys_id: str\n The sys_id of the request to delete\n\n \"\"\"\n # Delete all items\n for item in get_request_items(instance, sys_id):\n # Delete all options for each item\n for option in item[\"options\"].values():\n db_delete_from_table(\n instance,\n option[\"sys_ids\"][\"sc_item_option_mtom\"],\n \"sc_item_option_mtom\",\n )\n db_delete_from_table(instance, option[\"sys_ids\"][\"sc_item_option\"], \"sc_item_option\")\n db_delete_from_table(instance, item[\"sys_id\"], \"sc_req_item\")\n\n # Delete the request\n db_delete_from_table(instance, sys_id, \"sc_request\")\n\n\ndef get_all_requests(instance: SNowInstance, since_minutes: int = 99999999999) -> list:\n \"\"\"\n Retrives a list of all requests from an instance\n\n Parameters:\n -----------\n since_minutes: int\n The number of minutes to look back for requests (used to avoid getting too many requests)\n\n Returns:\n --------\n list\n A list of all requests from an instance (as dicts)\n\n \"\"\"\n # Filter for requests that were created in the time frame\n query = f\"sys_created_on>=javascript:gs.minutesAgoStart({since_minutes})\"\n\n # Get all requests\n requests_ = table_api_call(\n instance, table=\"sc_request\", method=\"GET\", params={\"sysparm_query\": query}\n )[\"result\"]\n\n # For each request, get the items that were ordered\n for request in requests_:\n request[\"items\"] = get_request_items(instance, request[\"sys_id\"])\n\n return requests_\n\n\ndef get_request_by_id(instance: SNowInstance, sysid: str) -> dict:\n \"\"\"\n Get a request by its sys_id\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to get the request from\n sysid: str\n The sys_id of the request to get\n\n Returns:\n --------\n dict\n A dictionary containing the details of the request\n\n \"\"\"\n # Get the request","source_hash":"cf6bd04d3926d47474e3f77fa5c7ba8e8a6e37ef8e874814693f9886b55af7ef","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.requests.get_request_by_id","uri":"program://WorkArena/function/src.browsergym.workarena.api.requests.get_request_by_id#L69-L101","kind":"function","name":"get_request_by_id","path":"src/browsergym/workarena/api/requests.py","language":"python","start_line":69,"end_line":101,"context_start_line":49,"context_end_line":121,"code":" --------\n list\n A list of all requests from an instance (as dicts)\n\n \"\"\"\n # Filter for requests that were created in the time frame\n query = f\"sys_created_on>=javascript:gs.minutesAgoStart({since_minutes})\"\n\n # Get all requests\n requests_ = table_api_call(\n instance, table=\"sc_request\", method=\"GET\", params={\"sysparm_query\": query}\n )[\"result\"]\n\n # For each request, get the items that were ordered\n for request in requests_:\n request[\"items\"] = get_request_items(instance, request[\"sys_id\"])\n\n return requests_\n\n\ndef get_request_by_id(instance: SNowInstance, sysid: str) -> dict:\n \"\"\"\n Get a request by its sys_id\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to get the request from\n sysid: str\n The sys_id of the request to get\n\n Returns:\n --------\n dict\n A dictionary containing the details of the request\n\n \"\"\"\n # Get the request\n request = table_api_call(\n instance,\n table=f\"sc_request\",\n method=\"GET\",\n params={\"sysparm_query\": f\"sys_id={sysid}\"},\n )[\"result\"]\n\n if len(request) == 0:\n return None\n request = request[0]\n\n # Get the items that were ordered\n request[\"items\"] = get_request_items(instance, request[\"sys_id\"])\n\n return request\n\n\ndef get_request_items(instance: SNowInstance, sys_id: str) -> list[dict]:\n \"\"\"\n Get all items that were ordered as part of a request\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the request to get items for\n\n Returns:\n --------\n list\n A list of dicts containing the items\n\n \"\"\"\n # Get all items in the request\n items = table_api_call(\n instance=instance,","source_hash":"cf6bd04d3926d47474e3f77fa5c7ba8e8a6e37ef8e874814693f9886b55af7ef","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.requests.get_request_items","uri":"program://WorkArena/function/src.browsergym.workarena.api.requests.get_request_items#L104-L155","kind":"function","name":"get_request_items","path":"src/browsergym/workarena/api/requests.py","language":"python","start_line":104,"end_line":155,"context_start_line":84,"context_end_line":155,"code":"\n \"\"\"\n # Get the request\n request = table_api_call(\n instance,\n table=f\"sc_request\",\n method=\"GET\",\n params={\"sysparm_query\": f\"sys_id={sysid}\"},\n )[\"result\"]\n\n if len(request) == 0:\n return None\n request = request[0]\n\n # Get the items that were ordered\n request[\"items\"] = get_request_items(instance, request[\"sys_id\"])\n\n return request\n\n\ndef get_request_items(instance: SNowInstance, sys_id: str) -> list[dict]:\n \"\"\"\n Get all items that were ordered as part of a request\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the request to get items for\n\n Returns:\n --------\n list\n A list of dicts containing the items\n\n \"\"\"\n # Get all items in the request\n items = table_api_call(\n instance=instance,\n table=\"sc_req_item\",\n params={\n \"sysparm_query\": f\"request={sys_id}\",\n \"sysparm_fields\": \",\".join(\n [\n \"sys_id\",\n \"short_description\",\n \"quantity\",\n ]\n ),\n },\n )[\"result\"]\n\n # For each item, get the options that were selected (if there are any)\n for item in items:\n options = table_api_call(\n instance=instance,\n table=\"sc_item_option_mtom\",\n params={\n \"sysparm_query\": f\"request_item={item['sys_id']}\",\n \"sysparm_fields\": \",\".join(\n [\n \"sc_item_option.value\",\n \"sc_item_option.item_option_new.question_text\",\n ]\n ),\n },\n )[\"result\"]\n item[\"options\"] = {\n opt[\"sc_item_option.item_option_new.question_text\"]: opt[\"sc_item_option.value\"]\n for opt in options\n }\n\n return items","source_hash":"cf6bd04d3926d47474e3f77fa5c7ba8e8a6e37ef8e874814693f9886b55af7ef","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.incident","uri":"program://WorkArena/module/src.browsergym.workarena.api.incident#L1-L45","kind":"module","name":"src.browsergym.workarena.api.incident","path":"src/browsergym/workarena/api/incident.py","language":"python","start_line":1,"end_line":45,"context_start_line":1,"context_end_line":45,"code":"from faker import Faker\nfrom ..instance import SNowInstance\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\n\ndef create_incident(\n instance: SNowInstance,\n incident_number: int,\n caller_sys_id: str,\n category: str,\n impact: int,\n urgency: int,\n priority: int,\n incident_hastag: str = None,\n assigned_to: str = None,\n):\n incident_config = {\n \"task_effective_number\": incident_number,\n \"number\": incident_number,\n \"state\": 2,\n \"knowledge\": False,\n \"impact\": impact,\n \"active\": True,\n \"priority\": priority,\n \"caller_id\": caller_sys_id,\n \"short_description\": incident_hastag if incident_hastag else \" \".join(fake.words(5)),\n \"description\": \" \".join(fake.words(10)),\n \"incident_state\": 2,\n \"urgency\": urgency,\n \"severity\": 3,\n \"category\": category,\n }\n if assigned_to:\n incident_config[\"assigned_to\"] = assigned_to\n\n incident_response = table_api_call(\n instance=instance,\n table=\"incident\",\n json=incident_config,\n method=\"POST\",\n )[\"result\"]\n return incident_response","source_hash":"6d56a9b1ed9c07d1f27e04ee8fe20c00904c30fbfb9bda24469cdda689680a7d","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.incident.create_incident","uri":"program://WorkArena/function/src.browsergym.workarena.api.incident.create_incident#L9-L45","kind":"function","name":"create_incident","path":"src/browsergym/workarena/api/incident.py","language":"python","start_line":9,"end_line":45,"context_start_line":1,"context_end_line":45,"code":"from faker import Faker\nfrom ..instance import SNowInstance\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\n\ndef create_incident(\n instance: SNowInstance,\n incident_number: int,\n caller_sys_id: str,\n category: str,\n impact: int,\n urgency: int,\n priority: int,\n incident_hastag: str = None,\n assigned_to: str = None,\n):\n incident_config = {\n \"task_effective_number\": incident_number,\n \"number\": incident_number,\n \"state\": 2,\n \"knowledge\": False,\n \"impact\": impact,\n \"active\": True,\n \"priority\": priority,\n \"caller_id\": caller_sys_id,\n \"short_description\": incident_hastag if incident_hastag else \" \".join(fake.words(5)),\n \"description\": \" \".join(fake.words(10)),\n \"incident_state\": 2,\n \"urgency\": urgency,\n \"severity\": 3,\n \"category\": category,\n }\n if assigned_to:\n incident_config[\"assigned_to\"] = assigned_to\n\n incident_response = table_api_call(\n instance=instance,\n table=\"incident\",\n json=incident_config,\n method=\"POST\",\n )[\"result\"]\n return incident_response","source_hash":"6d56a9b1ed9c07d1f27e04ee8fe20c00904c30fbfb9bda24469cdda689680a7d","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.expense_line","uri":"program://WorkArena/module/src.browsergym.workarena.api.expense_line#L1-L89","kind":"module","name":"src.browsergym.workarena.api.expense_line","path":"src/browsergym/workarena/api/expense_line.py","language":"python","start_line":1,"end_line":89,"context_start_line":1,"context_end_line":89,"code":"import json\nimport time\n\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .cost_center import get_cost_center_sysid\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_expense_line(\n instance: SNowInstance,\n amount: float,\n number: str,\n date: str,\n short_description: str = None,\n expense_hashtag: str = \"\",\n task_sys_id: str = None,\n cost_center_sys_id: str = None,\n summary_type: str = \"run_business\",\n user_sys_id: str = None,\n):\n \"\"\"Create a hardware asset -computer model- and assign it to a user\n Args:\n --------\n instance (SNowInstance):\n The instance to create the hardware asset in\n amount (float):\n The amount of the expense line\n number (str):\n The number of the expense line\n date (str):\n The date of the expense line\n short_description (str):\n The short description of the expense line; if None, a random one will be generated\n expense_hashtag (str):\n The hashtag of the expense line (added to the short description)\n task_sys_id (str):\n The sys id of the task to file the expense line under\n cost_center_sys_id (str):\n The sys id of the cost center to file the expense line under\n summary_type (str):\n The summary type of the expense line (choice of \"run_business\", \"grow_business\", \"transform_business\")\n user_sys_id (str):\n The sys_id of the user to assign the hardware asset to. If None, the hardware asset is not assigned to any user\n Returns:\n --------\n sys_id (str):\n The sys_id of the created expense_line\n expense_line_number (str):\n The number of the created expense_line\n \"\"\"\n if cost_center_sys_id is None:\n # sys_id of the engineering cost center\n cost_center_sys_id = table_api_call(\n instance=instance,\n table=\"cmn_cost_center\",\n params={\"sysparm_query\": \"name=Engineering\"},\n )[\"result\"][0][\"sys_id\"]\n\n if short_description is None:\n short_description = fake.sentence(4)\n\n expense_cfg = {\n \"date\": date,\n \"base_expense\": \"\",\n \"short_description\": short_description + \" \" + expense_hashtag,\n \"summary_type\": summary_type,\n \"summary_type\": \"run_business\",\n \"type\": \"one-time\",\n \"number\": f\"{number}\",\n \"task\": f\"{task_sys_id}\",\n \"state\": \"processed\",\n \"amount\": f\"{amount}\",\n \"cost_center\": f\"{cost_center_sys_id}\",\n \"user\": f\"{user_sys_id}\",\n }\n\n result = table_api_call(\n instance=instance,\n table=\"fm_expense_line\",\n json=expense_cfg,\n method=\"POST\",\n )[\"result\"]\n\n return result[\"sys_id\"], result[\"number\"]","source_hash":"31f22c9e0ca79ae2178200d8b1f5e6a38f386c1573dedc0d64d4ef5c323843c9","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.expense_line.create_expense_line","uri":"program://WorkArena/function/src.browsergym.workarena.api.expense_line.create_expense_line#L14-L89","kind":"function","name":"create_expense_line","path":"src/browsergym/workarena/api/expense_line.py","language":"python","start_line":14,"end_line":89,"context_start_line":1,"context_end_line":89,"code":"import json\nimport time\n\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .cost_center import get_cost_center_sysid\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_expense_line(\n instance: SNowInstance,\n amount: float,\n number: str,\n date: str,\n short_description: str = None,\n expense_hashtag: str = \"\",\n task_sys_id: str = None,\n cost_center_sys_id: str = None,\n summary_type: str = \"run_business\",\n user_sys_id: str = None,\n):\n \"\"\"Create a hardware asset -computer model- and assign it to a user\n Args:\n --------\n instance (SNowInstance):\n The instance to create the hardware asset in\n amount (float):\n The amount of the expense line\n number (str):\n The number of the expense line\n date (str):\n The date of the expense line\n short_description (str):\n The short description of the expense line; if None, a random one will be generated\n expense_hashtag (str):\n The hashtag of the expense line (added to the short description)\n task_sys_id (str):\n The sys id of the task to file the expense line under\n cost_center_sys_id (str):\n The sys id of the cost center to file the expense line under\n summary_type (str):\n The summary type of the expense line (choice of \"run_business\", \"grow_business\", \"transform_business\")\n user_sys_id (str):\n The sys_id of the user to assign the hardware asset to. If None, the hardware asset is not assigned to any user\n Returns:\n --------\n sys_id (str):\n The sys_id of the created expense_line\n expense_line_number (str):\n The number of the created expense_line\n \"\"\"\n if cost_center_sys_id is None:\n # sys_id of the engineering cost center\n cost_center_sys_id = table_api_call(\n instance=instance,\n table=\"cmn_cost_center\",\n params={\"sysparm_query\": \"name=Engineering\"},\n )[\"result\"][0][\"sys_id\"]\n\n if short_description is None:\n short_description = fake.sentence(4)\n\n expense_cfg = {\n \"date\": date,\n \"base_expense\": \"\",\n \"short_description\": short_description + \" \" + expense_hashtag,\n \"summary_type\": summary_type,\n \"summary_type\": \"run_business\",\n \"type\": \"one-time\",\n \"number\": f\"{number}\",\n \"task\": f\"{task_sys_id}\",\n \"state\": \"processed\",\n \"amount\": f\"{amount}\",\n \"cost_center\": f\"{cost_center_sys_id}\",\n \"user\": f\"{user_sys_id}\",\n }\n\n result = table_api_call(\n instance=instance,\n table=\"fm_expense_line\",\n json=expense_cfg,\n method=\"POST\",\n )[\"result\"]\n\n return result[\"sys_id\"], result[\"number\"]","source_hash":"31f22c9e0ca79ae2178200d8b1f5e6a38f386c1573dedc0d64d4ef5c323843c9","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.category","uri":"program://WorkArena/module/src.browsergym.workarena.api.category#L1-L74","kind":"module","name":"src.browsergym.workarena.api.category","path":"src/browsergym/workarena/api/category.py","language":"python","start_line":1,"end_line":74,"context_start_line":1,"context_end_line":74,"code":"import warnings\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_category(\n instance: SNowInstance,\n list_name: str,\n category_name: str = None,\n) -> list[str]:\n \"\"\"\n NOTE: This function creates a new category in the given list. Because categories are in a drop-down list, adding more\n categories will make the list longer and this will affect the difficulty of the task. Use only if you are certain you know\n what you are doing.\n\n Create a category for a given list\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to create the category in\n list_name: str\n The name of the list to create the category for (e.g. problem, incident, etc.)\n category_name: str\n The name of the category to create, defaults to a random category name\n\n Returns:\n --------\n category_name, sys_id\n\n \"\"\"\n warnings.warn(\n \"This function creates a new category in the given list. Because categories are in a drop-down list, adding more \"\n \"categories will make the list longer and this will affect the difficulty of the task. Use only if you are certain you know \"\n \"what you are doing.\",\n UserWarning,\n )\n\n if category_name is None:\n category_name = fake.word() + \"-\" + fake.word()\n\n # Create category\n category_data = {\n \"name\": list_name,\n \"element\": \"category\",\n \"value\": category_name,\n }\n result = table_api_call(\n instance=instance,\n table=\"sys_choice\",\n json=category_data,\n method=\"POST\",\n wait_for_record=True,\n )[\"result\"]\n\n sys_id = result[\"sys_id\"]\n\n return category_name, sys_id\n\n\ndef get_categories(instance, list_name):\n \"\"\"Get the name of the categories for a given list name\"\"\"\n categories = table_api_call(\n instance=instance,\n table=\"sys_choice\",\n params={\"sysparm_query\": f\"name={list_name}^element=category\", \"sysparm_fields\": \"value\"},\n )[\"result\"]\n\n return categories","source_hash":"e288b03e745ab3465609d932eface1369bbff4f7c1fc79a19c56bf0c967219f0","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.category.create_category","uri":"program://WorkArena/function/src.browsergym.workarena.api.category.create_category#L11-L63","kind":"function","name":"create_category","path":"src/browsergym/workarena/api/category.py","language":"python","start_line":11,"end_line":63,"context_start_line":1,"context_end_line":74,"code":"import warnings\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_category(\n instance: SNowInstance,\n list_name: str,\n category_name: str = None,\n) -> list[str]:\n \"\"\"\n NOTE: This function creates a new category in the given list. Because categories are in a drop-down list, adding more\n categories will make the list longer and this will affect the difficulty of the task. Use only if you are certain you know\n what you are doing.\n\n Create a category for a given list\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to create the category in\n list_name: str\n The name of the list to create the category for (e.g. problem, incident, etc.)\n category_name: str\n The name of the category to create, defaults to a random category name\n\n Returns:\n --------\n category_name, sys_id\n\n \"\"\"\n warnings.warn(\n \"This function creates a new category in the given list. Because categories are in a drop-down list, adding more \"\n \"categories will make the list longer and this will affect the difficulty of the task. Use only if you are certain you know \"\n \"what you are doing.\",\n UserWarning,\n )\n\n if category_name is None:\n category_name = fake.word() + \"-\" + fake.word()\n\n # Create category\n category_data = {\n \"name\": list_name,\n \"element\": \"category\",\n \"value\": category_name,\n }\n result = table_api_call(\n instance=instance,\n table=\"sys_choice\",\n json=category_data,\n method=\"POST\",\n wait_for_record=True,\n )[\"result\"]\n\n sys_id = result[\"sys_id\"]\n\n return category_name, sys_id\n\n\ndef get_categories(instance, list_name):\n \"\"\"Get the name of the categories for a given list name\"\"\"\n categories = table_api_call(\n instance=instance,\n table=\"sys_choice\",\n params={\"sysparm_query\": f\"name={list_name}^element=category\", \"sysparm_fields\": \"value\"},\n )[\"result\"]\n\n return categories","source_hash":"e288b03e745ab3465609d932eface1369bbff4f7c1fc79a19c56bf0c967219f0","truncated":false} {"repo_id":"WorkArena","entity_id":"py:src.browsergym.workarena.api.category.get_categories","uri":"program://WorkArena/function/src.browsergym.workarena.api.category.get_categories#L66-L74","kind":"function","name":"get_categories","path":"src/browsergym/workarena/api/category.py","language":"python","start_line":66,"end_line":74,"context_start_line":46,"context_end_line":74,"code":"\n # Create category\n category_data = {\n \"name\": list_name,\n \"element\": \"category\",\n \"value\": category_name,\n }\n result = table_api_call(\n instance=instance,\n table=\"sys_choice\",\n json=category_data,\n method=\"POST\",\n wait_for_record=True,\n )[\"result\"]\n\n sys_id = result[\"sys_id\"]\n\n return category_name, sys_id\n\n\ndef get_categories(instance, list_name):\n \"\"\"Get the name of the categories for a given list name\"\"\"\n categories = table_api_call(\n instance=instance,\n table=\"sys_choice\",\n params={\"sysparm_query\": f\"name={list_name}^element=category\", \"sysparm_fields\": \"value\"},\n )[\"result\"]\n\n return categories","source_hash":"e288b03e745ab3465609d932eface1369bbff4f7c1fc79a19c56bf0c967219f0","truncated":false} {"repo_id":"WorkArena","entity_id":"py:scripts.extract_finetuning_traces","uri":"program://WorkArena/module/scripts.extract_finetuning_traces#L1-L131","kind":"module","name":"scripts.extract_finetuning_traces","path":"scripts/extract_finetuning_traces.py","language":"python","start_line":1,"end_line":131,"context_start_line":1,"context_end_line":131,"code":"\"\"\"\nA demonstration of how observation/action traces can be extracted\nfor WorkArena tasks without modifying the task code.\n\nAuthor: Alexandre Drouin (alexandre.drouin@servicenow.com)\n\nNotes:\n- This approach relies on monkey patching the playwright actions to log the actions and observations.\n It has not been tested for parallel execution. It might work with multiprocessing, but it will for\n sure not work with multithreading.\n\n\"\"\"\n\nimport importlib\nimport logging\nimport os\nimport pickle\nimport playwright.sync_api as playwright_sync\n\nfrom browsergym.core.env import BrowserEnv\nfrom browsergym.workarena import ALL_WORKARENA_TASKS\nfrom collections import defaultdict\nfrom tenacity import retry, stop_after_attempt, wait_fixed\nfrom time import time\n\n\nN_PER_TASK = 10\n\n\ndef monkey_patch_playwright(observation_callback, trace_storage):\n \"\"\"\n A function that overrides the default playwright actions to log the actions and observations.\n\n Parameters:\n ------------\n observation_callback: callable\n A function that returns the observation of the environment.\n trace_storage: list\n A list to store the trace of the actions and observations.\n These will be appended in-place.\n\n \"\"\"\n\n def wrapper(func, interface):\n def wrapped(*args, **kwargs):\n # Get the observation\n obs = observation_callback()\n\n # Get the BID of the element on which we are acting.\n if interface.__name__ == \"Locator\":\n # Get the locator\n locator = args[0]\n # Get the BID\n bid = locator.element_handle().evaluate('(el) => el.getAttribute(\"bid\")')\n elif interface.__name__ == \"Keyboard\":\n # Get the BID of the element\n bid = \"keyboard\"\n else:\n # Get the BID of the element\n bid = args[0].evaluate('(el) => el.getAttribute(\"bid\")')\n\n logging.info(f\"Action: {func.__name__} BID: {bid} -- Args: {args[1:]} {kwargs}\")\n trace_storage.append(\n {\n \"obs\": obs,\n \"action\": func.__name__,\n \"args\": args[1:],\n \"kwargs\": kwargs,\n \"bid\": bid,\n \"time\": time(),\n }\n )\n\n # Resume action\n return func(*args, **kwargs)\n\n return wrapped\n\n # Interfaces and actions we want to monkey patch\n importlib.reload(playwright_sync)\n from playwright.sync_api import Page, Frame, Locator, Keyboard, ElementHandle\n\n # TODO: Make sure the list of interfaces and actions is exhaustive\n # It covers all that is used in WorkArena cheats as of April 11, 2024\n interfaces = [Page, Frame, Locator, Keyboard, ElementHandle]\n actions = [\"click\", \"select_option\", \"set_checked\", \"fill\", \"press\", \"type\", \"down\", \"up\"]\n\n for interface in interfaces:\n for action in actions:\n if hasattr(interface, action):\n setattr(interface, action, wrapper(getattr(interface, action), interface))\n print(f\"Monkey patched {interface.__name__}.{action}\")\n\n\n@retry(stop=stop_after_attempt(3), wait=wait_fixed(2))\ndef extract_trace(task_cls, headless=True):\n \"\"\"\n Extracts the trace of actions and observations for a given task.\n\n Parameters:\n ------------\n task_cls: class\n The class of the task to extract the trace from.\n\n \"\"\"\n # Instantiate a new environment\n env = BrowserEnv(task_entrypoint=task_cls, headless=headless, slow_mo=1000)\n\n # Setup customized tracing\n trace = []\n monkey_patch_playwright(observation_callback=env._get_obs, trace_storage=trace)\n\n env.reset()\n env.task.cheat(env.page, env.chat.messages)\n env.close()\n\n return trace\n\n\nif __name__ == \"__main__\":\n os.makedirs(\"trace_profiling\", exist_ok=True)\n\n task_traces = defaultdict(list)\n for task in ALL_WORKARENA_TASKS:\n print(\"Task:\", task)\n for i in range(N_PER_TASK):\n print(f\"Extracting trace {i+1}/{N_PER_TASK}\")\n trace = extract_trace(task, headless=True)\n task_traces[task].append(trace)\n\n pickle.dump(task_traces, open(\"trace_profiling/task_traces.pkl\", \"wb\"))","source_hash":"076442bd033a07c06f90d578a41a35f67c11cc26f25dd7d23b3b4e694930c05c","truncated":false} {"repo_id":"WorkArena","entity_id":"py:scripts.extract_finetuning_traces.monkey_patch_playwright","uri":"program://WorkArena/function/scripts.extract_finetuning_traces.monkey_patch_playwright#L30-L92","kind":"function","name":"monkey_patch_playwright","path":"scripts/extract_finetuning_traces.py","language":"python","start_line":30,"end_line":92,"context_start_line":10,"context_end_line":112,"code":" sure not work with multithreading.\n\n\"\"\"\n\nimport importlib\nimport logging\nimport os\nimport pickle\nimport playwright.sync_api as playwright_sync\n\nfrom browsergym.core.env import BrowserEnv\nfrom browsergym.workarena import ALL_WORKARENA_TASKS\nfrom collections import defaultdict\nfrom tenacity import retry, stop_after_attempt, wait_fixed\nfrom time import time\n\n\nN_PER_TASK = 10\n\n\ndef monkey_patch_playwright(observation_callback, trace_storage):\n \"\"\"\n A function that overrides the default playwright actions to log the actions and observations.\n\n Parameters:\n ------------\n observation_callback: callable\n A function that returns the observation of the environment.\n trace_storage: list\n A list to store the trace of the actions and observations.\n These will be appended in-place.\n\n \"\"\"\n\n def wrapper(func, interface):\n def wrapped(*args, **kwargs):\n # Get the observation\n obs = observation_callback()\n\n # Get the BID of the element on which we are acting.\n if interface.__name__ == \"Locator\":\n # Get the locator\n locator = args[0]\n # Get the BID\n bid = locator.element_handle().evaluate('(el) => el.getAttribute(\"bid\")')\n elif interface.__name__ == \"Keyboard\":\n # Get the BID of the element\n bid = \"keyboard\"\n else:\n # Get the BID of the element\n bid = args[0].evaluate('(el) => el.getAttribute(\"bid\")')\n\n logging.info(f\"Action: {func.__name__} BID: {bid} -- Args: {args[1:]} {kwargs}\")\n trace_storage.append(\n {\n \"obs\": obs,\n \"action\": func.__name__,\n \"args\": args[1:],\n \"kwargs\": kwargs,\n \"bid\": bid,\n \"time\": time(),\n }\n )\n\n # Resume action\n return func(*args, **kwargs)\n\n return wrapped\n\n # Interfaces and actions we want to monkey patch\n importlib.reload(playwright_sync)\n from playwright.sync_api import Page, Frame, Locator, Keyboard, ElementHandle\n\n # TODO: Make sure the list of interfaces and actions is exhaustive\n # It covers all that is used in WorkArena cheats as of April 11, 2024\n interfaces = [Page, Frame, Locator, Keyboard, ElementHandle]\n actions = [\"click\", \"select_option\", \"set_checked\", \"fill\", \"press\", \"type\", \"down\", \"up\"]\n\n for interface in interfaces:\n for action in actions:\n if hasattr(interface, action):\n setattr(interface, action, wrapper(getattr(interface, action), interface))\n print(f\"Monkey patched {interface.__name__}.{action}\")\n\n\n@retry(stop=stop_after_attempt(3), wait=wait_fixed(2))\ndef extract_trace(task_cls, headless=True):\n \"\"\"\n Extracts the trace of actions and observations for a given task.\n\n Parameters:\n ------------\n task_cls: class\n The class of the task to extract the trace from.\n\n \"\"\"\n # Instantiate a new environment\n env = BrowserEnv(task_entrypoint=task_cls, headless=headless, slow_mo=1000)\n\n # Setup customized tracing\n trace = []\n monkey_patch_playwright(observation_callback=env._get_obs, trace_storage=trace)\n","source_hash":"076442bd033a07c06f90d578a41a35f67c11cc26f25dd7d23b3b4e694930c05c","truncated":false} {"repo_id":"WorkArena","entity_id":"py:scripts.extract_finetuning_traces.extract_trace","uri":"program://WorkArena/function/scripts.extract_finetuning_traces.extract_trace#L96-L117","kind":"function","name":"extract_trace","path":"scripts/extract_finetuning_traces.py","language":"python","start_line":96,"end_line":117,"context_start_line":76,"context_end_line":131,"code":"\n return wrapped\n\n # Interfaces and actions we want to monkey patch\n importlib.reload(playwright_sync)\n from playwright.sync_api import Page, Frame, Locator, Keyboard, ElementHandle\n\n # TODO: Make sure the list of interfaces and actions is exhaustive\n # It covers all that is used in WorkArena cheats as of April 11, 2024\n interfaces = [Page, Frame, Locator, Keyboard, ElementHandle]\n actions = [\"click\", \"select_option\", \"set_checked\", \"fill\", \"press\", \"type\", \"down\", \"up\"]\n\n for interface in interfaces:\n for action in actions:\n if hasattr(interface, action):\n setattr(interface, action, wrapper(getattr(interface, action), interface))\n print(f\"Monkey patched {interface.__name__}.{action}\")\n\n\n@retry(stop=stop_after_attempt(3), wait=wait_fixed(2))\ndef extract_trace(task_cls, headless=True):\n \"\"\"\n Extracts the trace of actions and observations for a given task.\n\n Parameters:\n ------------\n task_cls: class\n The class of the task to extract the trace from.\n\n \"\"\"\n # Instantiate a new environment\n env = BrowserEnv(task_entrypoint=task_cls, headless=headless, slow_mo=1000)\n\n # Setup customized tracing\n trace = []\n monkey_patch_playwright(observation_callback=env._get_obs, trace_storage=trace)\n\n env.reset()\n env.task.cheat(env.page, env.chat.messages)\n env.close()\n\n return trace\n\n\nif __name__ == \"__main__\":\n os.makedirs(\"trace_profiling\", exist_ok=True)\n\n task_traces = defaultdict(list)\n for task in ALL_WORKARENA_TASKS:\n print(\"Task:\", task)\n for i in range(N_PER_TASK):\n print(f\"Extracting trace {i+1}/{N_PER_TASK}\")\n trace = extract_trace(task, headless=True)\n task_traces[task].append(trace)\n\n pickle.dump(task_traces, open(\"trace_profiling/task_traces.pkl\", \"wb\"))","source_hash":"076442bd033a07c06f90d578a41a35f67c11cc26f25dd7d23b3b4e694930c05c","truncated":false} {"repo_id":"WorkArena","entity_id":"py:scripts.extract_finetuning_traces.wrapper","uri":"program://WorkArena/function/scripts.extract_finetuning_traces.wrapper#L44-L77","kind":"function","name":"wrapper","path":"scripts/extract_finetuning_traces.py","language":"python","start_line":44,"end_line":77,"context_start_line":24,"context_end_line":97,"code":"from time import time\n\n\nN_PER_TASK = 10\n\n\ndef monkey_patch_playwright(observation_callback, trace_storage):\n \"\"\"\n A function that overrides the default playwright actions to log the actions and observations.\n\n Parameters:\n ------------\n observation_callback: callable\n A function that returns the observation of the environment.\n trace_storage: list\n A list to store the trace of the actions and observations.\n These will be appended in-place.\n\n \"\"\"\n\n def wrapper(func, interface):\n def wrapped(*args, **kwargs):\n # Get the observation\n obs = observation_callback()\n\n # Get the BID of the element on which we are acting.\n if interface.__name__ == \"Locator\":\n # Get the locator\n locator = args[0]\n # Get the BID\n bid = locator.element_handle().evaluate('(el) => el.getAttribute(\"bid\")')\n elif interface.__name__ == \"Keyboard\":\n # Get the BID of the element\n bid = \"keyboard\"\n else:\n # Get the BID of the element\n bid = args[0].evaluate('(el) => el.getAttribute(\"bid\")')\n\n logging.info(f\"Action: {func.__name__} BID: {bid} -- Args: {args[1:]} {kwargs}\")\n trace_storage.append(\n {\n \"obs\": obs,\n \"action\": func.__name__,\n \"args\": args[1:],\n \"kwargs\": kwargs,\n \"bid\": bid,\n \"time\": time(),\n }\n )\n\n # Resume action\n return func(*args, **kwargs)\n\n return wrapped\n\n # Interfaces and actions we want to monkey patch\n importlib.reload(playwright_sync)\n from playwright.sync_api import Page, Frame, Locator, Keyboard, ElementHandle\n\n # TODO: Make sure the list of interfaces and actions is exhaustive\n # It covers all that is used in WorkArena cheats as of April 11, 2024\n interfaces = [Page, Frame, Locator, Keyboard, ElementHandle]\n actions = [\"click\", \"select_option\", \"set_checked\", \"fill\", \"press\", \"type\", \"down\", \"up\"]\n\n for interface in interfaces:\n for action in actions:\n if hasattr(interface, action):\n setattr(interface, action, wrapper(getattr(interface, action), interface))\n print(f\"Monkey patched {interface.__name__}.{action}\")\n\n\n@retry(stop=stop_after_attempt(3), wait=wait_fixed(2))\ndef extract_trace(task_cls, headless=True):\n \"\"\"","source_hash":"076442bd033a07c06f90d578a41a35f67c11cc26f25dd7d23b3b4e694930c05c","truncated":false} {"repo_id":"WorkArena","entity_id":"py:scripts.extract_finetuning_traces.wrapped","uri":"program://WorkArena/function/scripts.extract_finetuning_traces.wrapped#L45-L75","kind":"function","name":"wrapped","path":"scripts/extract_finetuning_traces.py","language":"python","start_line":45,"end_line":75,"context_start_line":25,"context_end_line":95,"code":"\n\nN_PER_TASK = 10\n\n\ndef monkey_patch_playwright(observation_callback, trace_storage):\n \"\"\"\n A function that overrides the default playwright actions to log the actions and observations.\n\n Parameters:\n ------------\n observation_callback: callable\n A function that returns the observation of the environment.\n trace_storage: list\n A list to store the trace of the actions and observations.\n These will be appended in-place.\n\n \"\"\"\n\n def wrapper(func, interface):\n def wrapped(*args, **kwargs):\n # Get the observation\n obs = observation_callback()\n\n # Get the BID of the element on which we are acting.\n if interface.__name__ == \"Locator\":\n # Get the locator\n locator = args[0]\n # Get the BID\n bid = locator.element_handle().evaluate('(el) => el.getAttribute(\"bid\")')\n elif interface.__name__ == \"Keyboard\":\n # Get the BID of the element\n bid = \"keyboard\"\n else:\n # Get the BID of the element\n bid = args[0].evaluate('(el) => el.getAttribute(\"bid\")')\n\n logging.info(f\"Action: {func.__name__} BID: {bid} -- Args: {args[1:]} {kwargs}\")\n trace_storage.append(\n {\n \"obs\": obs,\n \"action\": func.__name__,\n \"args\": args[1:],\n \"kwargs\": kwargs,\n \"bid\": bid,\n \"time\": time(),\n }\n )\n\n # Resume action\n return func(*args, **kwargs)\n\n return wrapped\n\n # Interfaces and actions we want to monkey patch\n importlib.reload(playwright_sync)\n from playwright.sync_api import Page, Frame, Locator, Keyboard, ElementHandle\n\n # TODO: Make sure the list of interfaces and actions is exhaustive\n # It covers all that is used in WorkArena cheats as of April 11, 2024\n interfaces = [Page, Frame, Locator, Keyboard, ElementHandle]\n actions = [\"click\", \"select_option\", \"set_checked\", \"fill\", \"press\", \"type\", \"down\", \"up\"]\n\n for interface in interfaces:\n for action in actions:\n if hasattr(interface, action):\n setattr(interface, action, wrapper(getattr(interface, action), interface))\n print(f\"Monkey patched {interface.__name__}.{action}\")\n\n\n@retry(stop=stop_after_attempt(3), wait=wait_fixed(2))","source_hash":"076442bd033a07c06f90d578a41a35f67c11cc26f25dd7d23b3b4e694930c05c","truncated":false} {"repo_id":"WorkArena","entity_id":"py:scripts.make_human_eval_curriculum","uri":"program://WorkArena/module/scripts.make_human_eval_curriculum#L1-L54","kind":"module","name":"scripts.make_human_eval_curriculum","path":"scripts/make_human_eval_curriculum.py","language":"python","start_line":1,"end_line":54,"context_start_line":1,"context_end_line":54,"code":"\"\"\"\nHuman Evaluation - Create the curriculum for all humans\n\nNote: This script separates the tasks among 14 evaluators.\n A 15th one was added subsequently to solve tasks that\n had not been completed by the initial 14 (e.g., due\n to some issues with the annotation UI).\n\n\"\"\"\n\nimport random\n\nfrom browsergym.workarena import get_all_tasks_humans\n\n\ntasks_l2 = get_all_tasks_humans(filter=\"l2\", meta_seed=42)\ntasks_l3 = get_all_tasks_humans(filter=\"l3\", meta_seed=42)\n\ntasks = tasks_l2 + tasks_l3\nrandom.shuffle(tasks)\n\nannotators = [\n \"darwiche\",\n \"parikh\",\n \"marchand\",\n \"paquet\",\n \"nayak\",\n \"huang\",\n \"subbaraj\",\n \"williams\",\n \"li\",\n \"marcotte\",\n \"rancourt\",\n \"prince_tremblay\",\n \"ashok\",\n \"bajaj\",\n]\nrandom.shuffle(annotators)\n\nprint(\"Number of tasks: \", len(tasks))\nprint(\"Number of annotators: \", len(annotators))\n\ntasks_by_annotator = {}\nn_base_assignment = len(tasks) // len(annotators)\nn_extra_assignment = len(tasks) % len(annotators)\nfor i, annotator in enumerate(annotators):\n n_assignments = n_base_assignment + (1 if i < n_extra_assignment else 0)\n tasks_by_annotator[annotator] = tasks[:n_assignments]\n tasks = tasks[n_assignments:]\n print(f\"{annotator}: {n_assignments}\")\n\n with open(f\"{annotator}.tasks\", \"w\") as f:\n for task in tasks_by_annotator[annotator]:\n f.write(f\"{task[0].__name__},{task[1]}\\n\")","source_hash":"df7880bbaa73cee59cf9cb52bfd0294adac2ed5013dca5eb2b882f352d31bd14","truncated":false} {"repo_id":"WorkArena","entity_id":"file:make_human_eval_curriculum.py","uri":"program://WorkArena/file/make_human_eval_curriculum.py","kind":"file","name":"make_human_eval_curriculum.py","path":"make_human_eval_curriculum.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import random\n\nfrom browsergym.workarena import get_all_tasks_humans\n\n\ntasks_l2 = get_all_tasks_humans(filter=\"l2\", meta_seed=42)\ntasks_l3 = get_all_tasks_humans(filter=\"l3\", meta_seed=42)\n\ntasks = tasks_l2 + tasks_l3\nrandom.shuffle(tasks)\n\nannotators = [\n \"darwiche\",\n \"parikh\",\n \"marchand\",\n \"paquet\",\n \"nayal\",\n \"huang\",\n \"subbaraj\",\n \"williams\",\n \"li\",","source_hash":"1f7ccff0b33ab5c2d69833890944dcb13b14ac9e898372ca156638b7b6c4128b","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_utils.py","uri":"program://WorkArena/file/tests/test_utils.py","kind":"file","name":"tests/test_utils.py","path":"tests/test_utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import pytest\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\n\nfrom playwright.sync_api import Page\n\nfrom browsergym.workarena.instance import SNowInstance\nfrom browsergym.workarena.utils import ui_login, url_login\n\n\n@pytest.mark.parametrize(\"login_func\", [ui_login, url_login])\ndef test_login_correct_credentials(login_func, page: Page):\n \"\"\"\n Test logging into the instance with the correct credentials\n\n \"\"\"\n # Log in with correct credentials\n instance = SNowInstance()\n login_func(instance=instance, page=page)\n","source_hash":"5252b4090cc44cfacee58149af6f716acd0ac364ed5805cb264964cb7d17ff3e","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_compositional_utils.py","uri":"program://WorkArena/file/tests/test_compositional_utils.py","kind":"file","name":"tests/test_compositional_utils.py","path":"tests/test_compositional_utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from copy import deepcopy\nimport json\nimport numpy as np\nimport pytest\n\nfrom browsergym.workarena.tasks.compositional.utils.knapsack import KnapsackInstanceGenarator\nfrom browsergym.workarena.tasks.compositional.utils.infeasible_configs import (\n get_infeasible_form_config,\n get_infeasible_service_catalog_config,\n get_infeasible_filter_config,\n get_infeasible_sort_config,\n)\nfrom browsergym.workarena.config import (\n CREATE_USER_CONFIG_PATH,\n ORDER_APPLE_MAC_BOOK_PRO15_TASK_CONFIG_PATH,\n FILTER_USER_LIST_CONFIG_PATH,\n SORT_USER_LIST_CONFIG_PATH,\n)\n\n\n@pytest.mark.parametrize(","source_hash":"cc8b41d48bbadc4534d35bffce3669ce72f838b210224f0577c63c9a7eab58c4","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_task_general.py","uri":"program://WorkArena/file/tests/test_task_general.py","kind":"file","name":"tests/test_task_general.py","path":"tests/test_task_general.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTests that are not specific to any particular kind of task.\n\n\"\"\"\n\nimport json\nimport logging\nimport pickle\nimport pytest\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\n\nfrom playwright.sync_api import Page, TimeoutError\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\n\nfrom browsergym.workarena import ATOMIC_TASKS\n\n\n@retry(\n stop=stop_after_attempt(5),","source_hash":"4c38cb8bc12dc807c183f4bfdf8783bbc9c07fb1724f60b3470079c09ccaae22","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_task_setup.py","uri":"program://WorkArena/file/tests/test_task_setup.py","kind":"file","name":"tests/test_task_setup.py","path":"tests/test_task_setup.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTests that are not specific to any particular kind of task.\n\n\"\"\"\n\nimport pytest\nimport json\nimport logging\nimport random\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\nfrom playwright.sync_api import Page, TimeoutError\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\nfrom browsergym.workarena.config import ORDER_APPLE_WATCH_TASK_CONFIG_PATH\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.service_catalog import OrderAppleWatchTask\n\n\n@retry(","source_hash":"4e5551b1de660838ff5af8b8c2cab3675f5247b19a7ddb9ba53f756eaa789368","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_compositional.py","uri":"program://WorkArena/file/tests/test_compositional.py","kind":"file","name":"tests/test_compositional.py","path":"tests/test_compositional.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTests that are not specific to any particular kind of task.\n\n\"\"\"\n\nimport logging\n\nimport pytest\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\n\nfrom playwright.sync_api import Page, TimeoutError\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\nfrom browsergym.workarena import ALL_COMPOSITIONAL_TASKS, get_all_tasks_agents\n\nAGENT_L2_SAMPLED_SET = get_all_tasks_agents(filter=\"l2\")\n\nAGENT_L2_SAMPLED_TASKS, AGENT_L2_SEEDS = [sampled_set[0] for sampled_set in AGENT_L2_SAMPLED_SET], [\n sampled_set[1] for sampled_set in AGENT_L2_SAMPLED_SET\n]","source_hash":"8dead70013571e730165285f0cebcec54f7e0ad2daac826ab412b3e1718d8b10","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_validate.py","uri":"program://WorkArena/file/tests/test_validate.py","kind":"file","name":"tests/test_validate.py","path":"tests/test_validate.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTests that are not specific to any particular kind of task.\n\n\"\"\"\n\nimport pytest\nimport json\nimport logging\nimport random\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\nfrom playwright.sync_api import Page, TimeoutError\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\nfrom browsergym.workarena.config import ORDER_APPLE_WATCH_TASK_CONFIG_PATH\n\nfrom browsergym.workarena.tasks.service_catalog import OrderAppleWatchTask\nfrom browsergym.workarena.tasks.scripts.validate import validate_configs\n\n\n@retry(","source_hash":"138d4862430c4d257eb804c0ffa1f736f1c24084202f313e536e25109c07cb76","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_random_config_generation.py","uri":"program://WorkArena/file/tests/test_random_config_generation.py","kind":"file","name":"tests/test_random_config_generation.py","path":"tests/test_random_config_generation.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTests that are not specific to any particular kind of task.\n\n\"\"\"\n\nimport json\nimport logging\nimport pickle\nimport pytest\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\n\nfrom playwright.sync_api import Page, TimeoutError\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\n\nfrom browsergym.workarena.tasks.form import (\n CreateChangeRequestTask,\n CreateHardwareAssetTask,\n CreateIncidentTask,\n CreateProblemTask,","source_hash":"9f0ef34db444b4c05ba4f0dc8da685508f6faf715a90abb2420d8e6ca1dae05f","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_snow_instance.py","uri":"program://WorkArena/file/tests/test_snow_instance.py","kind":"file","name":"tests/test_snow_instance.py","path":"tests/test_snow_instance.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTest that the ServiceNow instance is reachable and that the credentials are correct\n\n\"\"\"\n\nimport pytest\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\n\nfrom playwright.sync_api import Page\n\nfrom browsergym.workarena.instance import SNowInstance\nfrom browsergym.workarena.utils import ui_login\n\n\ndef test_check_is_reachable():\n \"\"\"\n Test that the ServiceNow instance is reachable\n\n \"\"\"","source_hash":"9dca26d12894068c3708ceee65556c0650474fecf03fb2a1cd84cb41ed5ab204","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/utils.py","uri":"program://WorkArena/file/tests/utils.py","kind":"file","name":"tests/utils.py","path":"tests/utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":13,"code":"import browsergym.core\nimport logging\nimport playwright.sync_api\nimport pytest\n\n\n# setup code, executed ahead of first test\n@pytest.fixture(scope=\"session\", autouse=True)\ndef setup_playwright(playwright: playwright.sync_api.Playwright):\n # bugfix: re-use pytest-playwright's playwright instance in browsergym\n # https://github.com/microsoft/playwright-python/issues/2053\n browsergym.core._set_global_playwright(playwright)\n logging.info(\"Browsergym is using the playwright instance provided by pytest-playwright.\")","source_hash":"e86ea963482bc9b60610380eb17a5289a6989cf2cad509f0245eb3ed6023c11d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_api.py","uri":"program://WorkArena/file/tests/test_api.py","kind":"file","name":"tests/test_api.py","path":"tests/test_api.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import numpy as np\nimport pytest\nimport random\n\nfrom time import sleep\n\nfrom browsergym.workarena.instance import SNowInstance\nfrom browsergym.workarena.api.utils import table_api_call\nfrom browsergym.workarena.api.user import create_user, set_user_preference\n\n\n@pytest.mark.parametrize(\"system\", [True, False])\ndef test_set_user_preference(system):\n admin_instance = SNowInstance()\n\n # Create a user to get a sys_id\n if not system:\n uname, pwd, sysid = create_user(SNowInstance())\n user_instance = SNowInstance(snow_credentials=(uname, pwd))\n user = sysid\n else:","source_hash":"b5b5c97cfc4898ce304231bcdc0002e7242067ca2b99c14451a9c646d5cc9466","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_task_from_config.py","uri":"program://WorkArena/file/tests/test_task_from_config.py","kind":"file","name":"tests/test_task_from_config.py","path":"tests/test_task_from_config.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTests that are not specific to any particular kind of task.\n\n\"\"\"\n\nimport pytest\nimport json\nimport logging\nimport random\n\n# bugfix: use same playwright instance in browsergym and pytest\nfrom utils import setup_playwright\nfrom playwright.sync_api import Page, TimeoutError\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\nfrom browsergym.workarena.config import (\n # navigation tasks\n ALL_MENU_PATH,\n IMPERSONATION_CONFIG_PATH,\n # form tasks\n CREATE_CHANGE_REQUEST_CONFIG_PATH,\n CREATE_HARDWARE_CONFIG_PATH,","source_hash":"93ab706a8739729d28edb6f8bed9a25568412315c56e4fbde873a76bd5bc8b54","truncated":false} {"repo_id":"WorkArena","entity_id":"file:tests/test_filter_list_task.py","uri":"program://WorkArena/file/tests/test_filter_list_task.py","kind":"file","name":"tests/test_filter_list_task.py","path":"tests/test_filter_list_task.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import pytest\nfrom playwright.sync_api import Page\nfrom browsergym.workarena.tasks.list import FilterIncidentListTask\n\n\n# These are all the same ways to express the same filter query (empty string) in ServiceNow.\n@pytest.mark.parametrize(\n \"query\",\n [\n \"assigned_toEMPTYSTRING^short_descriptionISEMPTY^description=This is a beautiful incident\",\n \"assigned_toISEMPTY^short_descriptionEMPTYSTRING^description=This is a beautiful incident^\",\n \"assigned_toISEMPTY^short_descriptionISEMPTY^description=This is a beautiful incident\",\n \"assigned_toEMPTYSTRING^short_descriptionEMPTYSTRING^description=This is a beautiful incident^\",\n \"assigned_to=^short_description=^description=This is a beautiful incident\",\n ],\n)\n@pytest.mark.slow\ndef test_validate_filter_list_task(page: Page, query):\n fixed_config = {\n \"filter_columns\": [\n \"short_description\",","source_hash":"dbcf38e837ea0255a0b0626633ee622a4a912d7a310f437fb1dc44c984cb6102","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/wa_action_traces.py","uri":"program://WorkArena/file/src/wa_action_traces.py","kind":"file","name":"src/wa_action_traces.py","path":"src/wa_action_traces.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nA demonstration of how action traces (with observations) can be extracted\nfor WorkArena tasks without modifying the task code.\n\nAuthor: Alexandre Drouin (alexandre.drouin@servicenow.com)\n\nNotes:\n- This approach relies on monkey patching the playwright actions to log the actions and observations.\n It has not been tested for parallel execution. It might work with multiprocessing, but it will for\n sure not work with multithreading.\n\n\"\"\"\n\nimport importlib\nimport logging\nimport os\nimport pickle\nimport playwright.sync_api as playwright_sync\n\nfrom browsergym.core.env import BrowserEnv\nfrom browsergym.workarena import ALL_WORKARENA_TASKS","source_hash":"1054d7dd5f1d54040e1490e1641067ca454306ef20f9ff184b20114b1c52e378","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/workarena_test.py","uri":"program://WorkArena/file/src/workarena_test.py","kind":"file","name":"src/workarena_test.py","path":"src/workarena_test.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from browsergym.core.env import BrowserEnv\nfrom browsergym.workarena import get_all_tasks_agents\n\nAGENT_L2_SAMPLED_SET = get_all_tasks_agents(filter=\"l2\")\n\nAGENT_L2_SAMPLED_TASKS, AGENT_L2_SEEDS = [sampled_set[0] for sampled_set in AGENT_L2_SAMPLED_SET], [\n sampled_set[1] for sampled_set in AGENT_L2_SAMPLED_SET\n]\nfrom time import sleep\n\nfor task, seed in zip(AGENT_L2_SAMPLED_TASKS, AGENT_L2_SEEDS):\n print(\"Task:\", task)\n\n # Instantiate a new environment\n env = BrowserEnv(task_entrypoint=task, headless=False, slow_mo=1000)\n env.reset()\n\n # Cheat functions use Playwright to automatically solve the task\n env.chat.add_message(role=\"assistant\", msg=\"On it. Please wait...\")\n\n for i in range(len(env.task)):","source_hash":"df01d22c5f230a99b5ac148770824ab29ba8f81799b5091383f31016af20c1aa","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/config.py","uri":"program://WorkArena/file/src/browsergym/workarena/config.py","kind":"file","name":"src/browsergym/workarena/config.py","path":"src/browsergym/workarena/config.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from importlib import resources\nfrom json import load as json_load\nfrom os.path import exists\n\nfrom ..workarena import data_files\nfrom ..workarena.tasks import utils\n\n# ServiceNow configuration\nSNOW_DATA_LOOKBACK_MINUTES = 5\nSNOW_BROWSER_TIMEOUT = 30000 # Milliseconds\nSNOW_JS_UTILS_FILEPATH = str(resources.files(utils).joinpath(\"js_utils.js\"))\nSNOW_SUPPORTED_RELEASES = [\"washingtondc\"]\n\n# Path to the Menu navigation task configuration\nALL_MENU_PATH = str(resources.files(data_files).joinpath(\"task_configs/all_menu.json\"))\n\n# Path to the dashboard/report retrieval task configurations\nDASHBOARD_RETRIEVAL_MINMAX_CONFIG_PATH = str(\n resources.files(data_files).joinpath(\"task_configs/dashboard_retrieval_minmax_task.json\")\n)\nDASHBOARD_RETRIEVAL_VALUE_CONFIG_PATH = str(","source_hash":"166c78b25dc1d447b69b67c69e711825fb10d1390257455d2a1359fa0372b515","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/instance.py","uri":"program://WorkArena/file/src/browsergym/workarena/instance.py","kind":"file","name":"src/browsergym/workarena/instance.py","path":"src/browsergym/workarena/instance.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport os\nimport requests\nimport re\n\nfrom playwright.sync_api import sync_playwright\nfrom typing import Optional\n\nfrom .config import SNOW_BROWSER_TIMEOUT, REPORT_FILTER_PROPERTY\n\n\nclass SNowInstance:\n \"\"\"\n Utility class to access a ServiceNow instance.\n\n \"\"\"\n\n def __init__(\n self,\n snow_url: Optional[str] = None,\n snow_credentials: Optional[tuple[str, str]] = None,","source_hash":"a4b95806b2aef860b060fcdf60edb0d0161cdaefe7e6332ddc765da699420f8d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/install.py","uri":"program://WorkArena/file/src/browsergym/workarena/install.py","kind":"file","name":"src/browsergym/workarena/install.py","path":"src/browsergym/workarena/install.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import html\nimport json\nimport logging\nimport re\nimport tenacity\n\nfrom datetime import datetime\nfrom playwright.sync_api import sync_playwright\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\nfrom requests import HTTPError\nfrom time import sleep\n\nfrom .api.system_properties import get_sys_property, set_sys_property\nfrom .api.ui_themes import get_workarena_theme_variants\nfrom .api.user import create_user\nfrom .api.utils import table_api_call, table_column_info\nfrom .config import (\n # for knowledge base setup\n KB_FILEPATH,\n KB_NAME,\n PROTOCOL_KB_FILEPATH,","source_hash":"0fd98c8e65756ca0e4d0999ca13bd54988d08dc1ec00ffd6a1a7d20334b4dd8c","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/__init__.py","uri":"program://WorkArena/file/src/browsergym/workarena/__init__.py","kind":"file","name":"src/browsergym/workarena/__init__.py","path":"src/browsergym/workarena/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"__version__ = \"0.4.4\"\n\nimport inspect\nfrom logging import warning\n\nimport numpy as np\nfrom browsergym.core.registration import register_task\n\nfrom .tasks.comp_building_block import CompositionalBuildingBlockTask\nfrom .tasks.compositional import (\n AGENT_CURRICULUM_L2,\n AGENT_CURRICULUM_L3,\n ALL_COMPOSITIONAL_TASKS,\n ALL_COMPOSITIONAL_TASKS_L2,\n ALL_COMPOSITIONAL_TASKS_L3,\n HUMAN_CURRICULUM_L2,\n HUMAN_CURRICULUM_L3,\n)\nfrom .tasks.compositional.base import CompositionalTask, HumanEvalTask\nfrom .tasks.compositional.update_task import __TASKS__ as UPDATE_TASKS\nfrom .tasks.dashboard import __TASKS__ as DASHBOARD_TASKS","source_hash":"82abf1fd2570ab7d4253e4f55e834ff440d9b238af5203025d2ee56c7fee73ce","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/utils.py","uri":"program://WorkArena/file/src/browsergym/workarena/utils.py","kind":"file","name":"src/browsergym/workarena/utils.py","path":"src/browsergym/workarena/utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nGeneral utiilty functions\n\n\"\"\"\n\nimport playwright.sync_api\n\nfrom browsergym.workarena.instance import SNowInstance\n\nfrom urllib import parse\n\n\ndef impersonate_user(username: str, page: playwright.sync_api.Page):\n \"\"\"\n Impersonate a user in the ServiceNow interface\n\n Parameters:\n -----------\n username: str\n The username of the user to impersonate\n page: playwright.sync_api.Page","source_hash":"983e91a95b9afa6d7e98a3354461a5504bb5b3aba7d1923d6b96533cdee0d616","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/human_eval/tool.py","uri":"program://WorkArena/file/src/browsergym/workarena/human_eval/tool.py","kind":"file","name":"src/browsergym/workarena/human_eval/tool.py","path":"src/browsergym/workarena/human_eval/tool.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nWorkArena Human Evaluation Tool\n\nKnown issues:\n * Blocking page interaction: We can't block loading until validation is done because some validation\n functions require the page to be loaded. This means the user might act\n while validation is ongoing. However, they would need to be very quick to\n cause issues.\n\n\"\"\"\n\nimport argparse\nimport json\nimport logging\nimport os\nimport random\nimport tenacity\n\nfrom time import sleep, time\n\nfrom browsergym.core.env import BrowserEnv","source_hash":"4b03ea02b367bc478e3cb4607a6ea4c25f21a37e39a3ed5fded39c3d103ced4d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/base.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/base.py","kind":"file","name":"src/browsergym/workarena/tasks/base.py","path":"src/browsergym/workarena/tasks/base.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nA bunch of base classes\n\n\"\"\"\n\nimport logging\n\nimport numpy as np\nimport playwright.sync_api\n\nfrom abc import ABC, abstractmethod\nfrom copy import deepcopy\nfrom typing import List, Optional, Tuple\nfrom uuid import uuid4\nfrom urllib import parse\n\nfrom browsergym.core.task import AbstractBrowserTask\nfrom ..api.user import create_user\nfrom ..api.utils import table_api_call\nfrom ..config import SNOW_BROWSER_TIMEOUT, SNOW_JS_UTILS_FILEPATH\nfrom ..utils import url_login","source_hash":"22487f03923dffd69c1c540272754c127941837bb7407403d88fcd6c6bc3e921","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/send_chat_message.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/send_chat_message.py","kind":"file","name":"src/browsergym/workarena/tasks/send_chat_message.py","path":"src/browsergym/workarena/tasks/send_chat_message.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from typing import Tuple\nfrom playwright.sync_api import Page\n\nfrom .base import AbstractServiceNowTask\nfrom .comp_building_block import CompositionalBuildingBlockTask\n\nfrom ..instance import SNowInstance\n\n\nclass SendChatMessageTask(AbstractServiceNowTask, CompositionalBuildingBlockTask):\n \"\"\"Task to send a chat message in the chat. Only used as a compositional building block for the cheat function.\n Args:\n --------\n message (str):\n The message to send in the chat\n answer_format (str):\n The type of answer to generate. Choice of total_return_only, total_return_and_investments, investments_only, cleanup, cleanup_and_return\n \"\"\"\n\n def __init__(\n self,","source_hash":"f32592044303a6ffeb794e101fddab8edc8f57a66384e0206f2e3ae4e95cde33","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/service_catalog.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/service_catalog.py","kind":"file","name":"src/browsergym/workarena/tasks/service_catalog.py","path":"src/browsergym/workarena/tasks/service_catalog.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTasks that require interacting with the service catalog\n\n\"\"\"\n\nimport json\nimport logging\nfrom typing import List\nimport numpy as np\nimport playwright.sync_api\n\nfrom playwright.sync_api import Page\nimport re\nfrom time import sleep\nfrom urllib import parse\n\nfrom .base import AbstractServiceNowTask\nfrom .utils.form import fill_text\n\nfrom ..api.requests import (\n get_request_by_id,","source_hash":"8355f689de0f1c0c983d867abe4c048c9bac831f120b212366a0b84a2956a1a0","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/form.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/form.py","kind":"file","name":"src/browsergym/workarena/tasks/form.py","path":"src/browsergym/workarena/tasks/form.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import inspect\nimport json\nimport logging\nimport playwright.sync_api\nimport re\n\nfrom collections import OrderedDict\nfrom english_words import get_english_words_set\nfrom faker import Faker\n\nfake = Faker()\nfrom playwright.sync_api._generated import Page\nfrom tenacity import retry, stop_after_delay, retry_if_exception_type\nfrom time import sleep\nfrom typing import List, Tuple\nfrom urllib import parse\n\nfrom .base import AbstractServiceNowTask\nfrom .comp_building_block import CompositionalBuildingBlockTask\n\nfrom ..api.utils import (","source_hash":"fecd3bc99fb37196e2e6fe952ba926d413f351f2057cc1155859b9e90868ce73","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/list.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/list.py","kind":"file","name":"src/browsergym/workarena/tasks/list.py","path":"src/browsergym/workarena/tasks/list.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTasks related to lists\n\n\"\"\"\n\nimport itertools\nimport json\nimport logging\nimport playwright.sync_api\nimport re\n\nfrom playwright.sync_api import Page\nfrom tenacity import retry, retry_if_exception_type, stop_after_delay\nfrom typing import List, Tuple\nfrom urllib import parse\nfrom warnings import warn\n\nfrom .comp_building_block import CompositionalBuildingBlockTask\n\nfrom ..api.utils import table_api_call, table_column_info\nfrom ..config import (","source_hash":"ede6fd175268a0bcc5188722ba5dbf1356c298dc81a3903338fa333b5a751da3","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/mark_duplicate_problem.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/mark_duplicate_problem.py","kind":"file","name":"src/browsergym/workarena/tasks/mark_duplicate_problem.py","path":"src/browsergym/workarena/tasks/mark_duplicate_problem.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\n\nfrom playwright.sync_api import Page\nfrom typing import Tuple\n\nfrom .base import AbstractServiceNowTask\nfrom .comp_building_block import CompositionalBuildingBlockTask\n\nfrom ..api.utils import table_api_call\n\n\nclass SetProblemAsDuplicateTask(AbstractServiceNowTask, CompositionalBuildingBlockTask):\n \"\"\"\n Set a problem as duplicate, assuming we start on the problems list view.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to use.\n start_rel_url: str\n The relative URL of the task list.","source_hash":"db39cfa32b82e3b864204cf9f63591f8a076a3818a27dcf92bf0be9a906a05f1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/navigation.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/navigation.py","kind":"file","name":"src/browsergym/workarena/tasks/navigation.py","path":"src/browsergym/workarena/tasks/navigation.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTasks related to basic menu navigation.\n\n\"\"\"\n\nimport json\nimport playwright.sync_api\nimport re\n\nfrom importlib import resources\nfrom playwright.sync_api import Page\nfrom urllib import parse\nfrom typing import List, Tuple\n\nfrom ..api.utils import table_api_call\nfrom .base import AbstractServiceNowTask\nfrom ..config import ALL_MENU_PATH, IMPERSONATION_CONFIG_PATH\nfrom ..instance import SNowInstance\nfrom ..utils import impersonate_user\n\n","source_hash":"63cd03a4bf31040f2ef734ae756d16e957f8a9a4595205be8d03bba65ea0385b","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/knowledge.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/knowledge.py","kind":"file","name":"src/browsergym/workarena/tasks/knowledge.py","path":"src/browsergym/workarena/tasks/knowledge.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nTasks related to knowledge bases.\n\n\"\"\"\n\nimport json\nimport logging\nimport re\n\nfrom playwright.sync_api import Page\nfrom typing import Tuple\nfrom urllib import parse\n\nfrom .base import AbstractServiceNowTask\nfrom .comp_building_block import CompositionalBuildingBlockTask\nfrom .utils.utils import check_url_suffix_match\n\nfrom ..api.utils import table_api_call\nfrom ..config import KB_FILEPATH, KB_CONFIG_PATH, KB_NAME, SNOW_BROWSER_TIMEOUT\nfrom ..install import check_knowledge_base\nfrom ..instance import SNowInstance","source_hash":"900363942ec3a69b4c6d195495919d0e3a99796230c32273a33579f2a100e8a5","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/comp_building_block.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/comp_building_block.py","kind":"file","name":"src/browsergym/workarena/tasks/comp_building_block.py","path":"src/browsergym/workarena/tasks/comp_building_block.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":4,"code":"class CompositionalBuildingBlockTask:\n \"\"\"Base class for compositional building block tasks. Used to exclude these tasks from the list of tasks that are tested like atomic tasks\"\"\"\n\n pass","source_hash":"2e0dca6c05abc730077b95db3cde8bf1bbddbbb99f269981bc8ee35de483c0a1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/dashboard.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/dashboard.py","kind":"file","name":"src/browsergym/workarena/tasks/dashboard.py","path":"src/browsergym/workarena/tasks/dashboard.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport logging\nimport numpy as np\nimport playwright.sync_api\nimport re\n\nfrom abc import ABC, abstractmethod\nfrom tenacity import retry, stop_after_attempt, wait_fixed\nfrom typing import List, Tuple\nfrom urllib import parse\n\nfrom .base import AbstractServiceNowTask\nfrom .comp_building_block import CompositionalBuildingBlockTask\nfrom .utils.utils import check_url_suffix_match\n\nfrom ..api.utils import table_api_call, table_column_info\nfrom ..config import (\n DASHBOARD_RETRIEVAL_MINMAX_CONFIG_PATH,\n DASHBOARD_RETRIEVAL_VALUE_CONFIG_PATH,\n REPORT_RETRIEVAL_MINMAX_CONFIG_PATH,\n REPORT_RETRIEVAL_VALUE_CONFIG_PATH,","source_hash":"9e7cb3ac8e97b48cca0e79a5d6bc4ced3d220890da86d9bcf28618286b6bb180","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/utils/private_tasks.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/utils/private_tasks.py","kind":"file","name":"src/browsergym/workarena/tasks/utils/private_tasks.py","path":"src/browsergym/workarena/tasks/utils/private_tasks.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport time\nfrom ...api.utils import table_api_call\nfrom playwright.sync_api import Page\n\n\ndef create_private_task_and_get_sys_id(\n instance,\n page: Page,\n private_task_id: str,\n task_info: str,\n short_description: str,\n user_sys_id: str = None,\n) -> None:\n \"\"\"\n Create a private task in the ServiceNow instance to store the task information. Used for level 3 tasks.\n Sets the sys_id of the private task to the sys_id attribute of the task.\n Returns the sys_id of the private task.\n Parameters:\n ----------\n instance: SNowInstance","source_hash":"afb67d4a704cb99759da2fad2ba7942e3d2af2172500d5c54b374b978f4a6072","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/utils/debug.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/utils/debug.py","kind":"file","name":"src/browsergym/workarena/tasks/utils/debug.py","path":"src/browsergym/workarena/tasks/utils/debug.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import playwright.sync_api\n\n\n# TODO: is this used?\ndef debug_task(task, random_seed=3):\n with playwright.sync_api.sync_playwright() as p:\n browser = p.chromium.launch_persistent_context(\n user_data_dir=\"/tmp/workarena_cromium_user_data\",\n headless=False, # Set headless=True for a non-GUI mode\n )\n (page,) = browser.pages\n\n try:\n task.setup(seed=random_seed, page=page)\n valid_res = task.validate(page, [])\n assert valid_res is False\n task.cheat()\n assert task.validate(page, []) is True\n finally:\n task.teardown()\n browser.close()","source_hash":"104cbb46dd844f0928acf9b4b3acbfbb4c2eb65e6b0e9fcf56e33b06f9ec6c80","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/utils/form.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/utils/form.py","kind":"file","name":"src/browsergym/workarena/tasks/utils/form.py","path":"src/browsergym/workarena/tasks/utils/form.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import time\nfrom ...config import SNOW_BROWSER_TIMEOUT\n\n\ndef fill_text(page, input_field, value, iframe=None):\n \"\"\"\n Fills the value of text field, while handling autocomplete menus.\n\n Parameters\n ----------\n page : playwright.sync_api.page.Page\n The page object\n input_field : playwright locator\n The locator of the input field\n value : str\n The value to fill in\n iframe : playwright locator, optional\n The locator of the iframe that contains the input field, by default None\n\n \"\"\"\n if iframe is None:","source_hash":"80274f4247c19de30aff1fb0e2dcbb46b32a40ad68df7b8ece581072f5f489c2","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/utils/utils.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/utils/utils.py","kind":"file","name":"src/browsergym/workarena/tasks/utils/utils.py","path":"src/browsergym/workarena/tasks/utils/utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import logging\nimport playwright.sync_api\n\nfrom urllib import parse\n\n\ndef check_url_suffix_match(page: playwright.sync_api.Page, expected_url: str, task) -> bool:\n \"\"\"\n Check if the current page URL matches the expected URL\n \"\"\"\n expected_url = parse.unquote(expected_url)\n expected_url_suffix = parse.urlparse(expected_url).path\n\n page_url = page.evaluate(\"window.location.href\")\n page_url = parse.unquote(page_url)\n page_suffix = parse.urlparse(page_url).path\n if expected_url_suffix not in page_suffix:\n logging.debug(f\"Not in the expected URL for {task.__class__.__name__}, but in {page.url}\")\n return False\n return True\n","source_hash":"c500fe9e313080deeac5f9f574b04df0c61f777925dd3b957e9988d72c4c2fd9","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/utils/string.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/utils/string.py","kind":"file","name":"src/browsergym/workarena/tasks/utils/string.py","path":"src/browsergym/workarena/tasks/utils/string.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":15,"code":"\"\"\"\nVarious utility functions for string manipulation.\n\n\"\"\"\n\n\ndef generate_trigrams(word):\n return [word[i : i + 3] for i in range(len(word) - 2)]\n\n\ndef share_tri_gram(str1, str2):\n tri_grams1 = set(generate_trigrams(str1))\n tri_grams2 = set(generate_trigrams(str2))\n\n return bool(tri_grams1.intersection(tri_grams2))","source_hash":"8abe7f0120fd41214c67d92e1e8dac9d25d1b927efff044e1fa9f104b3933f82","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/manage_change_request_schedule.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/manage_change_request_schedule.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/manage_change_request_schedule.py","path":"src/browsergym/workarena/tasks/compositional/manage_change_request_schedule.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import re\n\nfrom datetime import datetime, timedelta\nfrom faker import Faker\nfrom typing import List, Tuple\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom browsergym.workarena.tasks.form import (\n EditChangeRequestScheduleTask,\n)\n\nfrom .base import HumanEvalTask\nfrom .filter_and_do import FilterAndDoTask\n\nfrom ..base import AbstractServiceNowTask\n\nfrom ...api.change_request import create_change_request\nfrom ...api.utils import table_api_call, db_delete_from_table","source_hash":"534a3f95ef7b9b38e0beae70dcf508ec8e07ac5a2c80485d6f0bcc003b96d726","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/base.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/base.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/base.py","path":"src/browsergym/workarena/tasks/compositional/base.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport time\nimport warnings\n\nfrom typing import List, Tuple\nfrom playwright.sync_api._generated import Page\n\nfrom browsergym.workarena.config import PROTOCOL_KB_FILEPATH\n\nfrom .update_task import UpdatePrivateTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..navigation import AllMenuTask\n\nfrom ...instance import SNowInstance\n\n\nclass CompositionalTask(AbstractServiceNowTask):\n # Final private task instructions\n final_private_task_instructions = 'Don\\'t forget to mark this task as \"Closed - complete\" once successfully completed. If the task appears infeasible, mark the task as \"Closed - skipped\" .'\n","source_hash":"7886617e904ebd9beb942d97ecf49b63fec9ac82ee7b361ef8d4730d31021e29","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/navigate_and_do.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/navigate_and_do.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/navigate_and_do.py","path":"src/browsergym/workarena/tasks/compositional/navigate_and_do.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\n\nfrom faker import Faker\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom browsergym.workarena.tasks.form import (\n CreateChangeRequestTask,\n CreateHardwareAssetTask,\n CreateIncidentTask,\n CreateProblemTask,\n CreateUserTask,\n)\nfrom browsergym.workarena.tasks.list import (\n FilterAssetListTask,\n FilterChangeRequestListTask,\n FilterHardwareListTask,\n FilterIncidentListTask,\n FilterServiceCatalogItemListTask,","source_hash":"868e03fc5047cdf1390c7697fd657323daadc799674ab14e287fc0e3bcb793d0","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_create_incident.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_create_incident.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_create_incident.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_create_incident.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import random\nfrom playwright.sync_api._generated import Page\nfrom typing import Tuple\n\nfrom .dash_do_base import DashboardRetrieveIncidentAndDoTask, DashDoFinalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask, SingleChartMeanMedianModeRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.form import CreateIncidentTask\n\n\nclass DashboardRetrieveIncidentAndCreateIncidentTask(DashboardRetrieveIncidentAndDoTask):\n def __init__(\n self,\n instance: SNowInstance = None,\n seed: int = None,","source_hash":"b2a7a4e83b2921ef9ccb4ce55bb984e21c8a858dffdc05b7949878e2242fc3b1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/work_assignment.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/work_assignment.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/work_assignment.py","path":"src/browsergym/workarena/tasks/compositional/work_assignment.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from typing import Tuple\nfrom faker import Faker\nimport random\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom .base import CompositionalTask, HumanEvalTask\n\nfrom ...api.incident import create_incident\nfrom ...api.user import create_user\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ..base import AbstractServiceNowTask\nfrom ..list import FilterIncidentListTask\nfrom ..form import EditIncidentTask\nfrom ..knowledge import KnowledgeBaseSearchTask\nfrom ..navigation import AllMenuTask\n\nfrom ...instance import SNowInstance\n","source_hash":"ccc158e2d1b1c6341fcdc0b76197f53a2c1f4ef51f906d5e7d4ebba3b212192b","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/mark_duplicate_problems.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/mark_duplicate_problems.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/mark_duplicate_problems.py","path":"src/browsergym/workarena/tasks/compositional/mark_duplicate_problems.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from faker import Faker\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom .base import HumanEvalTask\nfrom .filter_and_do import FilterAndDoTask\n\nfrom ..mark_duplicate_problem import SetProblemAsDuplicateTask\nfrom ..base import AbstractServiceNowTask\n\nfrom ...api.problem import create_problem\nfrom ...api.utils import db_delete_from_table, table_api_call\nfrom ...config import (\n # Expected columns for the different lists\n EXPECTED_PROBLEM_COLUMNS_PATH,\n)\nfrom ...instance import SNowInstance\n\n","source_hash":"8b7214660d1c91fbe2bff460dca2f615c6b2c49eb9ac4812eef6cf719279219d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_request_item_infeasible.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_request_item_infeasible.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_request_item_infeasible.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_request_item_infeasible.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import random\nfrom playwright.sync_api._generated import Page\nfrom typing import Tuple\n\nfrom .dash_do_base import DashboardRetrieveIncidentAndDoInfeasibleTask, DashDoFinalTask\nfrom .utils.infeasible_configs import get_infeasible_form_config\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.form import CreateItemRequestTask\n\n\nclass DashboardRetrieveIncidentAndRequestItemInfeasibleTask(\n DashboardRetrieveIncidentAndDoInfeasibleTask\n):\n def __init__(","source_hash":"af34c7a219bdc75386f2e0b8035c1973df2c02f01df6fb7bcaed7c05b21f2d32","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/find_and_order_item.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/find_and_order_item.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/find_and_order_item.py","path":"src/browsergym/workarena/tasks/compositional/find_and_order_item.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from faker import Faker\n\nfake = Faker()\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.send_chat_message import SendChatMessageGenericTask\nfrom browsergym.workarena.tasks.service_catalog import (\n OrderDeveloperLaptopTask,\n OrderIpadMiniTask,\n OrderIpadProTask,\n OrderSalesLaptopTask,\n OrderStandardLaptopTask,\n OrderAppleWatchTask,\n OrderAppleMacBookPro15Task,\n OrderDevelopmentLaptopPCTask,\n OrderLoanerLaptopTask,\n)\n\nfrom .base import HumanEvalTask\nfrom .filter_and_do import FilterAndDoTask\n","source_hash":"e1be18989429dbd38dd52ad077daf39c46de40fb70a965d00097c6ad9ac7e55c","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/maximize_investment_return.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/maximize_investment_return.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/maximize_investment_return.py","path":"src/browsergym/workarena/tasks/compositional/maximize_investment_return.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import re\n\nfrom faker import Faker\nfrom typing import List, Tuple\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom browsergym.workarena.tasks.send_chat_message import SendChatMessageForBudgetAllocationTask\n\nfrom .base import HumanEvalTask\nfrom .delete_record import DeleteExpenseLineKnapsack\nfrom .filter_and_do import FilterAndDoTask\nfrom .utils.knapsack import KnapsackInstanceGenarator\n\nfrom ..base import AbstractServiceNowTask\n\nfrom ...api.expense_line import create_expense_line\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...config import (","source_hash":"07388f930f329cdcef0f1520ea22a3877782dd9822f17fbe8e6eeb4d32aea040","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_create_problem_infeasible.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_create_problem_infeasible.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_create_problem_infeasible.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_create_problem_infeasible.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from playwright.sync_api._generated import Page\nfrom typing import Tuple\n\nfrom .dash_do_base import DashboardRetrieveIncidentAndDoInfeasibleTask, DashDoFinalTask\nfrom .utils.infeasible_configs import get_infeasible_form_config\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.form import CreateProblemTask\n\n\nclass DashboardRetrieveIncidentAndCreateProblemInfeasibleTask(\n DashboardRetrieveIncidentAndDoInfeasibleTask\n):\n def __init__(\n self,","source_hash":"5d4995b7a7fccdc2664ba359fc3dc02df2a57f4db5b2d27ab636b42c69116106","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/workload_balancing.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/workload_balancing.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/workload_balancing.py","path":"src/browsergym/workarena/tasks/compositional/workload_balancing.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import faker\n\nfake = faker.Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom .base import CompositionalTask, HumanEvalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import WorkLoadBalancingMinMaxRetrievalTask\nfrom ..form import EditProblemTask\nfrom ..knowledge import KnowledgeBaseSearchTask\nfrom ..list import FilterProblemListForWorkLoadBalancingTask\nfrom ..navigation import AllMenuTask\nfrom ..send_chat_message import SendChatMessageGenericTask\n\nfrom ...api.problem import create_problem\nfrom ...api.report import create_report\nfrom ...api.user import create_user\nfrom ...api.utils import db_delete_from_table, table_api_call\nfrom ...instance import SNowInstance","source_hash":"8b3329e010934390c7d0fd964efd68c3845cfa7aa43e58d3a511972476abed51","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/onboard_user.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/onboard_user.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/onboard_user.py","path":"src/browsergym/workarena/tasks/compositional/onboard_user.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\n\nfrom playwright.sync_api._generated import Page\n\nfrom .base import CompositionalTask, HumanEvalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..form import CreateUserTask, CreateHardwareAssetTask\nfrom ..knowledge import KnowledgeBaseSearchTask\nfrom ..navigation import AllMenuTask\nfrom ..service_catalog import OrderAppleMacBookPro15Task\n\nfrom ...instance import SNowInstance\nfrom ...config import CREATE_USER_CONFIG_PATH, CREATE_HARDWARE_CONFIG_PATH\n\n\nclass OnBoardUserTask(CompositionalTask, HumanEvalTask):\n def __init__(\n self,\n seed: int = None,\n instance: SNowInstance = None,","source_hash":"67668f5a73e3374ba315c822de2358f0f61bfd1615ec95d477b91428360cd4f1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_base.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_base.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_base.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_base.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nDashboard retrieval and do action comp tasks\n\"\"\"\n\nimport json\nfrom functools import partial\nimport random\nimport numpy as np\nfrom typing import List\n\nfrom faker import Faker\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom .base import CompositionalTask, InfeasibleCompositionalTask, HumanEvalTask\nfrom .utils.infeasible_configs import get_infeasible_service_catalog_config\nfrom ..base import AbstractServiceNowTask\nfrom ..knowledge import KnowledgeBaseSearchTask\n","source_hash":"8a1c60c15c547f10495ede3d2b3392107d62ffcbb29a6d6830b18faec0f8cdf2","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/warranty_check.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/warranty_check.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/warranty_check.py","path":"src/browsergym/workarena/tasks/compositional/warranty_check.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport time\nfrom faker import Faker\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom .base import CompositionalTask, HumanEvalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..knowledge import KnowledgeBaseSearchTask\nfrom ..list import ExtractListInfoTask, FilterHardwareListTask\nfrom ..navigation import AllMenuTask\n\nfrom ...api.computer_asset import create_computer_asset\nfrom ...api.user import create_user\nfrom ...api.utils import db_delete_from_table, table_api_call\nfrom ...instance import SNowInstance\n\n","source_hash":"d044e5d7aeb33ea3993ef8b8a3553d9ef2c649bf6b7f6cd0268596b8ced95299","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/offboard_user.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/offboard_user.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/offboard_user.py","path":"src/browsergym/workarena/tasks/compositional/offboard_user.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\n\nfrom faker import Faker\n\nfake = Faker()\nfrom playwright.sync_api._generated import Page\n\nfrom .base import CompositionalTask, HumanEvalTask\nfrom .delete_record import DeleteUserTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..form import EditHardwareAssetTask\nfrom ..knowledge import KnowledgeBaseSearchTask\nfrom ..list import FilterHardwareListTask\nfrom ..navigation import AllMenuTask\n\nfrom ...api.computer_asset import create_computer_asset\nfrom ...api.user import create_user\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n","source_hash":"87909b53265ff49c92db26bd07d448ff07d2880b8498fe0b705982ea187e7f07","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/edit_knowledge_base.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/edit_knowledge_base.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/edit_knowledge_base.py","path":"src/browsergym/workarena/tasks/compositional/edit_knowledge_base.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import html\nimport json\nimport random\n\nfrom faker import Faker\nfrom playwright.sync_api._generated import Page\nfrom typing import Tuple\n\nfake = Faker()\n\nfrom ...api.knowledge import give_kb_read_permissions\nfrom ...api.utils import table_api_call\nfrom ..base import AbstractServiceNowTask\nfrom .base import CompositionalTask\nfrom ...config import KB_FILEPATH, PROTOCOL_KB_NAME\nfrom ...instance import SNowInstance\nfrom ..knowledge import KnowledgeBaseSearchTask, AddCommentToKnowledgeArticleTask\nfrom ..navigation import AllMenuTask\n\n\nclass EditKnowledgeBaseTask(CompositionalTask):","source_hash":"6ca95ca5f04d0ac472b7e92d05072f8e7f10a5cc7d63c91a48f7f515eab1b0f1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/update_task.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/update_task.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/update_task.py","path":"src/browsergym/workarena/tasks/compositional/update_task.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from playwright.sync_api import Page\nfrom typing import List, Tuple\n\nfrom ..base import AbstractServiceNowTask\nfrom ..comp_building_block import CompositionalBuildingBlockTask\nfrom ..utils.utils import check_url_suffix_match\nfrom ..utils.private_tasks import create_private_task_and_get_sys_id\n\nfrom ...api.utils import db_delete_from_table, table_api_call\n\n\nclass UpdatePrivateTask(AbstractServiceNowTask, CompositionalBuildingBlockTask):\n \"\"\"\n Set a private task to complete, assuming we start on the task viewed as form.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to use.\n start_rel_url: str\n The relative URL of the task list.","source_hash":"9f58656d60965701a0484fda0f9cb87d58f2fe642d13932c41988f60c806af81","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/__init__.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/__init__.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/__init__.py","path":"src/browsergym/workarena/tasks/compositional/__init__.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from .utils.curriculum import AGENT_CURRICULUM, HUMAN_CURRICULUM\n\nALL_COMPOSITIONAL_TASKS = []\n\nfor category, items in AGENT_CURRICULUM.items():\n category_tasks = []\n for task in items[\"buckets\"]:\n category_tasks += task\n ALL_COMPOSITIONAL_TASKS += category_tasks\n\n\ndef specialize_task_class_to_level(task_cls, level):\n \"\"\"\n Function to hardcode the level for the tasks\n \"\"\"\n new_name = f\"{task_cls.__name__}L{level}\"\n patched_cls = f\"\"\"\nclass {new_name}(task_cls):\n def __init__(self, **kwargs):\n super().__init__(level={level}, **kwargs)\n\"\"\"","source_hash":"ce06e5db7a30c146529c50fce2b87e4098ad680b0d087d0f35272dfc7fcdacce","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_catalog_infeasible.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_catalog_infeasible.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_catalog_infeasible.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_catalog_infeasible.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from .dash_do_base import DashboardRetrieveCatalogAndDoInfeasibleTask, DashDoFinalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask, SingleChartMeanMedianModeRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...config import (\n ORDER_DEVELOPER_LAPTOP_TASK_CONFIG_PATH,\n ORDER_IPAD_MINI_TASK_CONFIG_PATH,\n ORDER_IPAD_PRO_TASK_CONFIG_PATH,\n ORDER_SALES_LAPTOP_TASK_CONFIG_PATH,\n ORDER_STANDARD_LAPTOP_TASK_CONFIG_PATH,\n ORDER_APPLE_WATCH_TASK_CONFIG_PATH,\n ORDER_APPLE_MAC_BOOK_PRO15_TASK_CONFIG_PATH,\n ORDER_DEVELOPMENT_LAPTOP_PC_TASK_CONFIG_PATH,\n ORDER_LOANER_LAPTOP_TASK_CONFIG_PATH,\n)\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.service_catalog import (","source_hash":"a875ec76d7ec237ac26b25f88e0682fa36725ad1602a4b57fa7110fa7bf2159d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_catalog.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_catalog.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_catalog.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_catalog.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from .dash_do_base import DashboardRetrieveCatalogAndDoTask, DashDoFinalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask, SingleChartMeanMedianModeRetrievalTask\n\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.service_catalog import (\n OrderDeveloperLaptopTask,\n OrderIpadMiniTask,\n OrderIpadProTask,\n OrderSalesLaptopTask,\n OrderStandardLaptopTask,\n OrderAppleWatchTask,\n OrderAppleMacBookPro15Task,\n OrderDevelopmentLaptopPCTask,\n OrderLoanerLaptopTask,\n)\n\n\nclass DashboardRetrieveCatalogAndOrderDeveloperLaptopTask(DashboardRetrieveCatalogAndDoTask):","source_hash":"701dcb7459dbfa6b14fa2f8be02c74e6720ba1450613105bb2b89bc4c4168412","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_create_incident_infeasible.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_create_incident_infeasible.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_create_incident_infeasible.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_create_incident_infeasible.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import random\nfrom playwright.sync_api._generated import Page\nfrom typing import Tuple\n\nfrom .dash_do_base import DashboardRetrieveIncidentAndDoInfeasibleTask, DashDoFinalTask\nfrom .utils.infeasible_configs import get_infeasible_form_config\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.form import CreateIncidentTask\n\n\nclass DashboardRetrieveIncidentAndCreateIncidentInfeasibleTask(\n DashboardRetrieveIncidentAndDoInfeasibleTask\n):\n def __init__(","source_hash":"71c09c00c32516f1ea1ef39de8434d3e7a6d0f22b68ad9e631db5be2807d6365","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/filter_and_do.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/filter_and_do.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/filter_and_do.py","path":"src/browsergym/workarena/tasks/compositional/filter_and_do.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from faker import Faker\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom browsergym.workarena.tasks.knowledge import KnowledgeBaseSearchTask\nfrom browsergym.workarena.tasks.list import FilterListTask\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\n\nfrom .base import CompositionalTask\n\nfrom ..base import AbstractServiceNowTask\n\nfrom ...instance import SNowInstance\n\n\nclass FilterAndDoTask(CompositionalTask):\n def __init__(\n self,\n seed: int,","source_hash":"3c742a70117463a5777dc98a2235c9d00afd493bb98ab5d0bd6a4a14ed955c71","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_filter.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_filter.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_filter.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_filter.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import random\nfrom playwright.sync_api._generated import Page\n\nfrom .dash_do_base import DashboardRetrieveIncidentAndDoTask, DashDoFinalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask, SingleChartMeanMedianModeRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.list import (\n FilterAssetListTask,\n FilterHardwareListTask,\n FilterIncidentListTask,\n FilterUserListTask,\n)\n\n\nclass DashboardRetrieveIncidentAndFilterListTask(DashboardRetrieveIncidentAndDoTask):","source_hash":"48450d0d404f550a36aee922eb1d800e18b7cd426813bcd7cb187312b9087562","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/expense_management.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/expense_management.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/expense_management.py","path":"src/browsergym/workarena/tasks/compositional/expense_management.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import re\n\nfrom datetime import timedelta\nfrom faker import Faker\nfrom typing import List, Tuple\n\nfake = Faker()\n\nfrom playwright.sync_api._generated import Page\n\nfrom .base import HumanEvalTask\nfrom .delete_record import DeleteExpenseLineExpenseManagementTask\nfrom .filter_and_do import FilterAndDoTask\n\nfrom ..base import AbstractServiceNowTask\n\nfrom ...api.change_request import create_change_request\nfrom ...api.expense_line import create_expense_line\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...config import (\n # Expected columns for the different lists","source_hash":"f7d6e90f4b175c33c688ddc498d5d47628cf8ecfb3717f9d1ebc2fe630864b00","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_request_item.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_request_item.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_request_item.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_request_item.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import random\nfrom playwright.sync_api._generated import Page\nfrom typing import Tuple\n\nfrom .dash_do_base import DashboardRetrieveIncidentAndDoTask, DashDoFinalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask, SingleChartMeanMedianModeRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.form import CreateItemRequestTask\n\n\nclass DashboardRetrieveIncidentAndRequestItemTask(DashboardRetrieveIncidentAndDoTask):\n def __init__(\n self,\n instance: SNowInstance = None,\n seed: int = None,","source_hash":"877787fd3fe6fa5c65d1feecb4ad4b3e378c96a506795ad86f5c81a81b8287e5","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/navigate_and_do_infeasible.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/navigate_and_do_infeasible.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/navigate_and_do_infeasible.py","path":"src/browsergym/workarena/tasks/compositional/navigate_and_do_infeasible.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from faker import Faker\n\nfake = Faker()\nfrom functools import partial\n\nfrom playwright.sync_api._generated import Page\n\nfrom browsergym.workarena.tasks.form import (\n CreateChangeRequestTask,\n CreateHardwareAssetTask,\n CreateIncidentTask,\n CreateProblemTask,\n CreateUserTask,\n)\nfrom browsergym.workarena.tasks.list import (\n FilterAssetListTask,\n FilterChangeRequestListTask,\n FilterHardwareListTask,\n FilterIncidentListTask,\n FilterServiceCatalogItemListTask,\n FilterUserListTask,","source_hash":"c35ae061a5a24a1be9492997d7c4b77d9732107855975c4b2a1822f9f39f2ef7","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/delete_record.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/delete_record.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/delete_record.py","path":"src/browsergym/workarena/tasks/compositional/delete_record.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import faker\n\nfaker = faker.Faker()\nimport json\n\nfrom playwright.sync_api import Page\nfrom typing import List, Tuple\n\nfrom .base import AbstractServiceNowTask\n\nfrom ..utils.utils import check_url_suffix_match\n\nfrom ...api.utils import db_delete_from_table, table_api_call\n\n\nclass DeleteRecordTask(AbstractServiceNowTask):\n \"\"\"\n Delete a record from a list.\n\n Parameters:\n -----------","source_hash":"7d7b3fa5da6967ad0b039724e8b80dddf277c3d67f324999308ebe00423bdce8","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/dash_do_create_problem.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/dash_do_create_problem.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/dash_do_create_problem.py","path":"src/browsergym/workarena/tasks/compositional/dash_do_create_problem.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from playwright.sync_api._generated import Page\nfrom typing import Tuple\n\nfrom .dash_do_base import DashboardRetrieveIncidentAndDoTask, DashDoFinalTask\n\nfrom ..base import AbstractServiceNowTask\nfrom ..dashboard import SingleChartMinMaxRetrievalTask, SingleChartMeanMedianModeRetrievalTask\n\nfrom ...api.utils import table_api_call, db_delete_from_table\nfrom ...instance import SNowInstance\n\nfrom browsergym.workarena.tasks.navigation import AllMenuTask\nfrom browsergym.workarena.tasks.form import CreateProblemTask\n\n\nclass DashboardRetrieveIncidentAndCreateProblemTask(DashboardRetrieveIncidentAndDoTask):\n def __init__(\n self,\n instance: SNowInstance = None,\n seed: int = None,\n fixed_config: list[AbstractServiceNowTask] = None,","source_hash":"70b5aec310455cc3b12a49aa43caa9f4f0502df556c9da9dd6eb20d7ed308ccb","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/utils/knapsack.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/utils/knapsack.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/utils/knapsack.py","path":"src/browsergym/workarena/tasks/compositional/utils/knapsack.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import numpy as np\n\n\nclass KnapsackInstanceGenarator:\n \"\"\"\n Generates a knapsack instance with the given number of items and maximum capacity, and solves it.\n The instance is guaranteed to have a unique optimal solution in \"random\" or \"single_item\" mode .\n\n Args:\n - random: Random number generator\n - num_items: Number of items\n - max_capacity: Maximum capacity of the knapsack\n - mode: Mode of generation. Choice of \"random\", \"trivial\", \"single_item\", \"single_item_uniform\", \"n_items\"\n - random: Randomly generate the instance and return it; guaranteed to have a unique optimal solution\n - trivial: Generate a trivial instance with all items fitting in the knapsack; return the instance\n - single_item: Generate an instance where the optimal solution has only one item\n - n_items: Generate an instance with all items having uniform weight and value; n items fitting in the knapsack\n - single_item_uniform: Generate an instance with all items having uniform weight and value; optimal solution has only one item and it can be any\n - num_items_in_solution: Number of items in the optimal solution. Required for \"n_items\" mode.\n - default_return: Default return value for investments having uniform weight and value. Required for \"n_items\" and \"single_item_uniform\" modes.\n \"\"\"","source_hash":"4f9cc1b89b2984e98bc08cfae22997ee1e4a94cc53ad73c7711004df69eff519","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/utils/infeasible_configs.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/utils/infeasible_configs.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/utils/infeasible_configs.py","path":"src/browsergym/workarena/tasks/compositional/utils/infeasible_configs.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import numpy as np\n\nfrom faker import Faker\n\nfake = Faker()\n\n\ndef get_infeasible_form_config(config, random: np.random, provide_reason: bool = True):\n \"\"\"\n Get an infeasible form config from a feasible config by replacing the name of one of the task_fields with a random word\n\n Args:\n --------\n config (dict):\n The feasible form config to be transformed into an infeasible one\n random (np.random):\n The random number generator to use\n provide_reason (bool):\n Whether to provide a reason for the infeasibility. If False, the list of reasons will be [\"\"] so that\n any infeasibility can be detected by the absence of a reason\n","source_hash":"881c8ede4723e531ab1325fe43ad19a05436b59348e1669260d8ef6c2558fb2d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/compositional/utils/curriculum.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/compositional/utils/curriculum.py","kind":"file","name":"src/browsergym/workarena/tasks/compositional/utils/curriculum.py","path":"src/browsergym/workarena/tasks/compositional/utils/curriculum.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"# from .edit_knowledge_base import __TASKS__ as EDIT_KNOWLEDGE_BASE_TASKS, __L2_TASKS__ as EDIT_KNOWLEDGE_BASE_L2_TASKS, __L3_TASKS__ as EDIT_KNOWLEDGE_BASE_L3TASKS\nfrom ..dash_do_catalog import (\n DASH_AND_ORDER,\n DASH_COMPUTE_MEAN_AND_ORDER,\n DASH_COMPUTE_MEDIAN_AND_ORDER,\n DASH_COMPUTE_MODE_AND_ORDER,\n)\nfrom ..dash_do_create_incident import DASH_AND_CREATE_INCIDENT, DASH_COMPUTE_AND_CREATE_INCIDENT\nfrom ..dash_do_create_problem import DASH_AND_CREATE_PROBLEM, DASH_COMPUTE_AND_CREATE_PROBLEM\nfrom ..dash_do_filter import (\n DASH_COMPUTE_MIN_FILTER_LIST,\n DASH_COMPUTE_MAX_FILTER_LIST,\n DASH_COMPUTE_MEAN_FILTER_LIST,\n DASH_COMPUTE_MEDIAN_FILTER_LIST,\n DASH_COMPUTE_MODE_FILTER_LIST,\n)\nfrom ..dash_do_request_item import (\n DASH_AND_REQUEST,\n DASH_COMPUTE_MEAN_AND_REQUEST,\n DASH_COMPUTE_MEDIAN_AND_REQUEST,\n DASH_COMPUTE_MODE_AND_REQUEST,","source_hash":"6659cf2e29de7ef9f818f36ff73483189a601b4278ae9287f4b0402dfb660730","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/service_catalog.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/service_catalog.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/service_catalog.py","path":"src/browsergym/workarena/tasks/scripts/service_catalog.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport multiprocessing\nimport random\nimport re\n\nfrom itertools import product, combinations\nfrom browsergym.workarena.tasks.service_catalog import META_CONFIGS\nfrom browsergym.workarena.config import (\n ORDER_DEVELOPER_LAPTOP_TASK_CONFIG_PATH,\n ORDER_IPAD_MINI_TASK_CONFIG_PATH,\n ORDER_IPAD_PRO_TASK_CONFIG_PATH,\n ORDER_SALES_LAPTOP_TASK_CONFIG_PATH,\n ORDER_STANDARD_LAPTOP_TASK_CONFIG_PATH,\n ORDER_APPLE_WATCH_TASK_CONFIG_PATH,\n ORDER_APPLE_MAC_BOOK_PRO15_TASK_CONFIG_PATH,\n ORDER_DEVELOPMENT_LAPTOP_PC_TASK_CONFIG_PATH,\n ORDER_LOANER_LAPTOP_TASK_CONFIG_PATH,\n)\nfrom browsergym.workarena.tasks.service_catalog import __TASKS__\n\n# The number of configurations to generate per item, as described in the WorkArena paper","source_hash":"fe396541611f89489d460897fa115b76b4d12a68ae7ef40ee11279e7c87c1ee4","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/generate_dashboard_configs.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/generate_dashboard_configs.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/generate_dashboard_configs.py","path":"src/browsergym/workarena/tasks/scripts/generate_dashboard_configs.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nGenerate configurations for the report and dashboard tasks\n\nNotes: sometimes it crashes (e.g., timeout, etc.). Just relaunch and it will be fine.\n\n\"\"\"\n\nimport json\nimport multiprocessing\nimport random\nimport tenacity\n\nfrom functools import partial\nfrom playwright.sync_api import sync_playwright\n\nfrom browsergym.workarena.api.utils import table_api_call, table_column_info\nfrom browsergym.workarena.config import (\n REPORT_DATE_FILTER,\n REPORT_PATCH_FLAG,\n REPORT_RETRIEVAL_MINMAX_CONFIG_PATH,\n REPORT_RETRIEVAL_VALUE_CONFIG_PATH,","source_hash":"af67032d1d67d699dfe66ffc5c84cdc7ddf3b98b7925a0556a2bade0ea989647","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/validate.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/validate.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/validate.py","path":"src/browsergym/workarena/tasks/scripts/validate.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport logging\nimport multiprocessing\n\nfrom browsergym.workarena.config import (\n # navigation tasks\n ALL_MENU_PATH,\n IMPERSONATION_CONFIG_PATH,\n # form tasks\n CREATE_CHANGE_REQUEST_CONFIG_PATH,\n CREATE_HARDWARE_CONFIG_PATH,\n CREATE_INCIDENT_CONFIG_PATH,\n CREATE_PROBLEM_CONFIG_PATH,\n CREATE_USER_CONFIG_PATH,\n # list tasks\n FILTER_ASSET_LIST_CONFIG_PATH,\n FILTER_CHANGE_REQUEST_LIST_CONFIG_PATH,\n FILTER_HARDWARE_LIST_CONFIG_PATH,\n FILTER_INCIDENT_LIST_CONFIG_PATH,\n FILTER_SERVICE_CATALOG_ITEM_LIST_CONFIG_PATH,\n FILTER_USER_LIST_CONFIG_PATH,","source_hash":"438497344b6348df0f9bafc5cfc75d3afe616d26b1725ce28bf066ddd487bde1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/extract_all_menu_items.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/extract_all_menu_items.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/extract_all_menu_items.py","path":"src/browsergym/workarena/tasks/scripts/extract_all_menu_items.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport os\n\nfrom playwright.sync_api import sync_playwright\n\n\n# Load environment variables\nSNOW_INSTANCE_URL = os.getenv(\"SNOW_INSTANCE_URL\")\nSNOW_INSTANCE_UNAME = os.getenv(\"SNOW_INSTANCE_UNAME\")\nSNOW_INSTANCE_PWD = os.getenv(\"SNOW_INSTANCE_PWD\")\n\n# ==================================================================================================================\n# This file is a script that extracts all the menu tasks from the ServiceNow instance. It uses #\n# Playwright to navigate to the ServiceNow instance, log in, and extract all the menu items. It then saves #\n# menu items to a JSON file. The extracted menu items can be used to create tasks for the WorkArena benchmark. #\n# ==================================================================================================================\n\n\nif __name__ == \"__main__\":\n\n base_paths = []","source_hash":"bcfc5ae58d3a4578900ba61a477d01f5aa7f66edf885375dc6884b2aa2a68f3c","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/list.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/list.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/list.py","path":"src/browsergym/workarena/tasks/scripts/list.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport multiprocessing\nimport random\nimport re\n\nfrom browsergym.workarena.tasks.list import __TASKS__\nfrom playwright.sync_api import sync_playwright\nfrom tqdm import tqdm\n\n# Split between filter and sort tasks\nFILTER_TASKS = [\n task for task in __TASKS__ if re.compile(r\"^Filter\\w+ListTask$\").match(task.__name__)\n]\nSORT_TASKS = [task for task in __TASKS__ if re.compile(r\"^Sort\\w+ListTask$\").match(task.__name__)]\n\n\ndef generate_sort_task_configs(task_class, num_configs_per_field_count=50):\n name = task_class.__name__\n name = re.sub(\"(.)([A-Z][a-z]+)\", r\"\\1_\\2\", name)\n task_name = re.sub(\"([a-z0-9])([A-Z])\", r\"\\1_\\2\", name).lower()\n all_configs = []","source_hash":"0b2f69bd41ea291c121f9c964fbe3a656f53306642f6aac1cef3ca6431966133","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/navigation.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/navigation.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/navigation.py","path":"src/browsergym/workarena/tasks/scripts/navigation.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\n\nfrom browsergym.workarena.api.utils import table_api_call, SNowInstance\n\nNUM_CONFIGS = 650 # number of impersonation tasks in the paper\n\n\ndef get_all_impersonation_users():\n instance = SNowInstance()\n candidate_users = [\n u[\"first_name\"] + \" \" + u[\"last_name\"]\n for u in table_api_call(\n instance=instance,\n table=\"sys_user\",\n params={\"sysparm_query\": \"user_name!=admin\"},\n )[\"result\"]\n if u[\"first_name\"].strip() and u[\"last_name\"].strip()\n ]\n\n return candidate_users\n","source_hash":"d862081a85ba01dd98a705fdf7f313b8ba228d293e120b237d136245a61a8ad1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/knowledge.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/knowledge.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/knowledge.py","path":"src/browsergym/workarena/tasks/scripts/knowledge.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport random\n\nfrom browsergym.workarena.api.utils import SNowInstance\nfrom browsergym.workarena.config import KB_FILEPATH, KB_CONFIG_PATH\nfrom browsergym.workarena.tasks.knowledge import KnowledgeBaseSearchTask\nfrom playwright.sync_api import sync_playwright\nfrom tenacity import retry, stop_after_attempt\nfrom tqdm import tqdm\n\n\ndef generate_all_kb_configs(instance=None, num_configs=1000) -> list[dict]:\n \"\"\"Generate all possible KB configs\"\"\"\n instance = instance if instance is not None else SNowInstance()\n with open(KB_FILEPATH, \"r\") as f:\n kb_entries = json.load(f)\n all_configs = []\n for kb_entry in kb_entries:\n for question in kb_entry[\"questions\"]:\n config = {\n \"item\": kb_entry[\"item\"],","source_hash":"42bbf7018f62eaf8d7862b431484c68cd8ccbce2fa1fb14b282251f2103a41da","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/tasks/scripts/generate_forms.py","uri":"program://WorkArena/file/src/browsergym/workarena/tasks/scripts/generate_forms.py","kind":"file","name":"src/browsergym/workarena/tasks/scripts/generate_forms.py","path":"src/browsergym/workarena/tasks/scripts/generate_forms.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport logging\nimport multiprocessing\nimport re\n\nfrom browsergym.workarena.tasks.form import __TASKS__\nfrom playwright.sync_api import sync_playwright\nfrom tenacity import retry, stop_after_attempt, retry_if_exception_type\nfrom tqdm import tqdm\n\n\ndef camel_to_snake(name):\n \"\"\"Convert camel case to snake case.\"\"\"\n name = re.sub(\"(.)([A-Z][a-z]+)\", r\"\\1_\\2\", name)\n return re.sub(\"([a-z0-9])([A-Z])\", r\"\\1_\\2\", name).lower()\n\n\ndef generate_form_task_configs(task_name, task_class, num_configs=1):\n \"\"\"Generate forms by using random setup and validating the feasibility of the task; also ensure that the task is new.\"\"\"\n\n @retry(","source_hash":"c27a971356f9790770401d19aaca904b9cfd54d2b239b527628615becab8b0cd","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/computer_asset.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/computer_asset.py","kind":"file","name":"src/browsergym/workarena/api/computer_asset.py","path":"src/browsergym/workarena/api/computer_asset.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport numpy as np\nimport time\n\nfrom faker import Faker\n\nfake = Faker()\n\nfrom ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef create_computer_asset(\n instance: SNowInstance,\n asset_tag: str,\n warranty_expiration_date: str = None,\n user_sys_id: str = None,\n computer_model_info: dict = None,\n random: np.random = None,\n):\n \"\"\"Create a hardware asset -computer model- and assign it to a user","source_hash":"ffe646fd6da6f4b6daa0f1ead6141a6f60c4726abf9df804c9458c9f145cbc43","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/requested_items.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/requested_items.py","kind":"file","name":"src/browsergym/workarena/api/requested_items.py","path":"src/browsergym/workarena/api/requested_items.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import faker\n\nfake = faker.Faker()\n\nfrom ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef create_requested_item(\n instance: SNowInstance,\n user_sys_id: str,\n system_name: str,\n quantity: int = 1,\n short_description: str = None,\n) -> list[str]:\n \"\"\"\n Create a requested item for a given user\n\n Parameters:\n -----------\n instance: SNowInstance","source_hash":"8345f4b00d6ff1b010cf3f637e9013a9272d50d34e4c3e78ec3e841f9678b30d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/problem.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/problem.py","kind":"file","name":"src/browsergym/workarena/api/problem.py","path":"src/browsergym/workarena/api/problem.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import faker\n\nfake = faker.Faker()\n\nfrom ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef create_problem(\n instance: SNowInstance,\n priority: str,\n user_sys_id: str,\n problem_hashtag: str,\n short_description: str = None,\n return_number: bool = False,\n) -> list[str]:\n \"\"\"\n Create a problem with a random cause, description, and short description. The problem is assigned to a user and\n is created with a hashtag.\n\n Parameters:","source_hash":"404afdbb05023af559733eceafd6ca91beda088acfecb48fba5bdf38b5720f53","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/report.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/report.py","kind":"file","name":"src/browsergym/workarena/api/report.py","path":"src/browsergym/workarena/api/report.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import numpy as np\n\nfrom ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef create_report(\n instance: SNowInstance,\n table: str,\n filter_hashtag: str,\n field: str,\n plot_title: str,\n filter_field: str = \"short_description\",\n random: np.random = None,\n) -> list[str]:\n \"\"\"\n Create a report for for the given table using a filter (str added to the short description).\n The report is created with a random color palette and colors and a random plot type (pie or bar).\n\n Parameters:\n -----------","source_hash":"9cd49370ce26284f465e3966efcee20252b943bd6841b59d51c56f9741a5a5e1","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/cost_center.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/cost_center.py","kind":"file","name":"src/browsergym/workarena/api/cost_center.py","path":"src/browsergym/workarena/api/cost_center.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":19,"code":"import warnings\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef get_cost_center_sysid(instance, cost_center_name):\n \"\"\"Get the sys_id of a cost center by its name\"\"\"\n sys_id = table_api_call(\n instance=instance,\n table=\"cmn_cost_center\",\n params={\"sysparm_query\": f\"name={cost_center_name}\", \"sysparm_fields\": \"sys_id\"},\n )[\"result\"][0]\n\n return sys_id","source_hash":"f25146421287d540d4da7c0c62903b36a8b6b47630ee8dfb86031286c68d12cc","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/ui_themes.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/ui_themes.py","kind":"file","name":"src/browsergym/workarena/api/ui_themes.py","path":"src/browsergym/workarena/api/ui_themes.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nUtility functions for UI themes\n\n\"\"\"\n\nfrom .utils import table_api_call\n\n\ndef get_workarena_theme_variants(instance):\n \"\"\"\n Get the list of available WorkArena UI themes\n\n Parameters:\n -----------\n instance: SNowInstance\n The ServiceNow instance to get the UI themes from\n\n Returns:\n --------\n list[dict]\n The list of available WorkArena UI themes and their information","source_hash":"f47f07867a875add020395f9135b289245d2098631b5666f84d15c5e7ddef74b","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/utils.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/utils.py","kind":"file","name":"src/browsergym/workarena/api/utils.py","path":"src/browsergym/workarena/api/utils.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import requests\n\nfrom ..instance import SNowInstance\n\nfrom requests.exceptions import HTTPError\nfrom time import sleep\n\n# ServiceNow API configuration\nSNOW_API_HEADERS = {\"Content-Type\": \"application/json\", \"Accept\": \"application/json\"}\n\n\ndef table_api_call(\n instance: SNowInstance,\n table: str,\n data: dict = {},\n params: dict = {},\n json: dict = {},\n method: str = \"GET\",\n wait_for_record: bool = False,\n max_retries: int = 5,\n raise_on_wait_expired: bool = True,","source_hash":"b2e954d6b0ba8e20b20d5c27e4fa8f2b4002fba9be1894bfe02af36abea910d5","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/system_properties.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/system_properties.py","kind":"file","name":"src/browsergym/workarena/api/system_properties.py","path":"src/browsergym/workarena/api/system_properties.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from .utils import table_api_call\n\n\ndef set_sys_property(instance, property_name: str, value: str):\n \"\"\"\n Set a sys_property in the instance.\n\n Parameters:\n -----------\n instance: SNowInstance\n The instance to set the property in\n property_name: str\n The name of the property to set\n value: str\n The value to set for the property\n\n \"\"\"\n\n property = table_api_call(\n instance=instance,\n table=\"sys_properties\",","source_hash":"f83cac1ee5137c7f36b6440639a94d76daa5fb6c9e196107e5005a613a412a1e","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/change_request.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/change_request.py","kind":"file","name":"src/browsergym/workarena/api/change_request.py","path":"src/browsergym/workarena/api/change_request.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import faker\nimport numpy as np\n\nfake = faker.Faker()\n\nfrom datetime import datetime, timedelta\n\nfrom .category import get_categories\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_change_request(\n instance: SNowInstance,\n user_sys_id: str,\n impact: int,\n risk: int,\n start_date: datetime = \"\",\n end_date: datetime = \"\",\n hashtag: str = \"\",","source_hash":"f59e6e3f6df1d3c5ae25aa359dad6d80cfc1f03998a01e2f8e27a3850a260c2c","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/knowledge.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/knowledge.py","kind":"file","name":"src/browsergym/workarena/api/knowledge.py","path":"src/browsergym/workarena/api/knowledge.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from ..instance import SNowInstance\nfrom .utils import table_api_call\n\n\ndef give_kb_read_permissions(admin_instance, user_sys_id, user_name, kb_sys_id, kb_name):\n # Need admin permissions to give KB permissions to the user\n\n # Create user criteria\n user_criteria_data = {\n \"user\": user_sys_id,\n \"name\": f\"{user_name} read KB\",\n \"short_description\": f\"Let {user_name} read {kb_name}\",\n }\n criteria_response = table_api_call(\n instance=admin_instance, table=\"user_criteria\", json=user_criteria_data, method=\"POST\"\n )[\"result\"]\n criteria_sys_id = criteria_response[\"sys_id\"]\n\n # Add user criteria entry to allow users to access the ADHOC KB\n kb_uc_can_read_mtom_data = {\n \"user_criteria\": criteria_sys_id,","source_hash":"94fbcd0d7c02f4df5998ebdea8b57047d07ab588fc0c3a278f69f77eed40a034","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/user.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/user.py","kind":"file","name":"src/browsergym/workarena/api/user.py","path":"src/browsergym/workarena/api/user.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from faker import Faker\nimport numpy as np\nimport time\n\nfake = Faker()\n\nfrom ..instance import SNowInstance\nfrom .ui_themes import get_workarena_theme_variants\nfrom .utils import table_api_call\n\n\ndef create_user(\n instance: SNowInstance,\n first_name: str = None,\n last_name: str = None,\n user_name: str = None,\n return_full_response: bool = False,\n user_roles: list[str] = [\"admin\"],\n random: np.random = np.random,\n) -> list[str]:\n \"\"\"","source_hash":"98bc7caf8445540bb0ebae75e319e2bf9b27fcee24c2302c55ffa20900bd6899","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/requests.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/requests.py","kind":"file","name":"src/browsergym/workarena/api/requests.py","path":"src/browsergym/workarena/api/requests.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nAPI to interact with requests in ServiceNow\n\n\"\"\"\n\nimport json\n\nfrom collections import defaultdict\n\nfrom .utils import SNowInstance, table_api_call, db_delete_from_table\n\n\ndef delete_request(instance: SNowInstance, sys_id: str) -> None:\n \"\"\"\n Deletes a request from an instance along with all its items and their options\n\n Parameters:\n -----------\n sys_id: str\n The sys_id of the request to delete\n","source_hash":"cf6bd04d3926d47474e3f77fa5c7ba8e8a6e37ef8e874814693f9886b55af7ef","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/incident.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/incident.py","kind":"file","name":"src/browsergym/workarena/api/incident.py","path":"src/browsergym/workarena/api/incident.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"from faker import Faker\nfrom ..instance import SNowInstance\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\n\ndef create_incident(\n instance: SNowInstance,\n incident_number: int,\n caller_sys_id: str,\n category: str,\n impact: int,\n urgency: int,\n priority: int,\n incident_hastag: str = None,\n assigned_to: str = None,\n):\n incident_config = {\n \"task_effective_number\": incident_number,","source_hash":"6d56a9b1ed9c07d1f27e04ee8fe20c00904c30fbfb9bda24469cdda689680a7d","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/expense_line.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/expense_line.py","kind":"file","name":"src/browsergym/workarena/api/expense_line.py","path":"src/browsergym/workarena/api/expense_line.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import json\nimport time\n\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .cost_center import get_cost_center_sysid\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_expense_line(\n instance: SNowInstance,\n amount: float,\n number: str,\n date: str,\n short_description: str = None,\n expense_hashtag: str = \"\",\n task_sys_id: str = None,","source_hash":"31f22c9e0ca79ae2178200d8b1f5e6a38f386c1573dedc0d64d4ef5c323843c9","truncated":false} {"repo_id":"WorkArena","entity_id":"file:src/browsergym/workarena/api/category.py","uri":"program://WorkArena/file/src/browsergym/workarena/api/category.py","kind":"file","name":"src/browsergym/workarena/api/category.py","path":"src/browsergym/workarena/api/category.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"import warnings\nfrom faker import Faker\n\nfake = Faker()\n\nfrom .utils import table_api_call\n\nfrom ..instance import SNowInstance\n\n\ndef create_category(\n instance: SNowInstance,\n list_name: str,\n category_name: str = None,\n) -> list[str]:\n \"\"\"\n NOTE: This function creates a new category in the given list. Because categories are in a drop-down list, adding more\n categories will make the list longer and this will affect the difficulty of the task. Use only if you are certain you know\n what you are doing.\n\n Create a category for a given list","source_hash":"e288b03e745ab3465609d932eface1369bbff4f7c1fc79a19c56bf0c967219f0","truncated":false} {"repo_id":"WorkArena","entity_id":"file:scripts/extract_finetuning_traces.py","uri":"program://WorkArena/file/scripts/extract_finetuning_traces.py","kind":"file","name":"scripts/extract_finetuning_traces.py","path":"scripts/extract_finetuning_traces.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nA demonstration of how observation/action traces can be extracted\nfor WorkArena tasks without modifying the task code.\n\nAuthor: Alexandre Drouin (alexandre.drouin@servicenow.com)\n\nNotes:\n- This approach relies on monkey patching the playwright actions to log the actions and observations.\n It has not been tested for parallel execution. It might work with multiprocessing, but it will for\n sure not work with multithreading.\n\n\"\"\"\n\nimport importlib\nimport logging\nimport os\nimport pickle\nimport playwright.sync_api as playwright_sync\n\nfrom browsergym.core.env import BrowserEnv\nfrom browsergym.workarena import ALL_WORKARENA_TASKS","source_hash":"076442bd033a07c06f90d578a41a35f67c11cc26f25dd7d23b3b4e694930c05c","truncated":false} {"repo_id":"WorkArena","entity_id":"file:scripts/make_human_eval_curriculum.py","uri":"program://WorkArena/file/scripts/make_human_eval_curriculum.py","kind":"file","name":"scripts/make_human_eval_curriculum.py","path":"scripts/make_human_eval_curriculum.py","language":"python","start_line":1,"end_line":1,"context_start_line":1,"context_end_line":21,"code":"\"\"\"\nHuman Evaluation - Create the curriculum for all humans\n\nNote: This script separates the tasks among 14 evaluators.\n A 15th one was added subsequently to solve tasks that\n had not been completed by the initial 14 (e.g., due\n to some issues with the annotation UI).\n\n\"\"\"\n\nimport random\n\nfrom browsergym.workarena import get_all_tasks_humans\n\n\ntasks_l2 = get_all_tasks_humans(filter=\"l2\", meta_seed=42)\ntasks_l3 = get_all_tasks_humans(filter=\"l3\", meta_seed=42)\n\ntasks = tasks_l2 + tasks_l3\nrandom.shuffle(tasks)\n","source_hash":"df7880bbaa73cee59cf9cb52bfd0294adac2ed5013dca5eb2b882f352d31bd14","truncated":false}