dialogs.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var dialogs_exports = {};
  20. __export(dialogs_exports, {
  21. default: () => dialogs_default,
  22. handleDialog: () => handleDialog
  23. });
  24. module.exports = __toCommonJS(dialogs_exports);
  25. var import_bundle = require("../../sdk/bundle");
  26. var import_tool = require("./tool");
  27. const handleDialog = (0, import_tool.defineTabTool)({
  28. capability: "core",
  29. schema: {
  30. name: "browser_handle_dialog",
  31. title: "Handle a dialog",
  32. description: "Handle a dialog",
  33. inputSchema: import_bundle.z.object({
  34. accept: import_bundle.z.boolean().describe("Whether to accept the dialog."),
  35. promptText: import_bundle.z.string().optional().describe("The text of the prompt in case of a prompt dialog.")
  36. }),
  37. type: "action"
  38. },
  39. handle: async (tab, params, response) => {
  40. response.setIncludeSnapshot();
  41. const dialogState = tab.modalStates().find((state) => state.type === "dialog");
  42. if (!dialogState)
  43. throw new Error("No dialog visible");
  44. tab.clearModalState(dialogState);
  45. await tab.waitForCompletion(async () => {
  46. if (params.accept)
  47. await dialogState.dialog.accept(params.promptText);
  48. else
  49. await dialogState.dialog.dismiss();
  50. });
  51. },
  52. clearsModalState: "dialog"
  53. });
  54. var dialogs_default = [
  55. handleDialog
  56. ];
  57. // Annotate the CommonJS export names for ESM import in node:
  58. 0 && (module.exports = {
  59. handleDialog
  60. });