import {
  BROWSER_SYSTEM_PROMPT,
  BROWSER_TOOL_DESCRIPTION
} from "./chunk-2HMEZZKK.js";
import {
  executeBrowserTask
} from "./chunk-RDMI5MI7.js";
import {
  __export
} from "./chunk-PZ5AY32C.js";

// tools/browser/openai.ts
var openai_exports = {};
__export(openai_exports, {
  browserTool: () => browserTool,
  createBrowserTool: () => createBrowserTool,
  execute: () => execute,
  formatResult: () => formatResult,
  getSystemPrompt: () => getSystemPrompt
});
var browserTool = {
  type: "function",
  function: {
    name: "browser_task",
    description: BROWSER_TOOL_DESCRIPTION,
    parameters: {
      type: "object",
      properties: {
        task: {
          type: "string",
          description: 'Natural language description of what to do (e.g., "Test checkout flow for buying a pineapple")'
        },
        url: {
          type: "string",
          description: "Starting URL (e.g., https://3000-xyz.e2b.dev). Required if navigating to a specific page."
        },
        maxSteps: {
          type: "number",
          description: "Maximum number of browser actions to take (1-50). Default: 10. Use 15-30 for complex flows.",
          default: 10
        },
        region: {
          type: "string",
          enum: ["sfo", "lon"],
          description: "Browserless region: sfo (US West Coast) or lon (Europe). Default: sfo.",
          default: "sfo"
        }
      },
      required: ["task"]
    }
  }
};
async function execute(input, config) {
  const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
  return executeBrowserTask(parsedInput, config);
}
function formatResult(result) {
  if (result.success) {
    const parts = [
      "\u2705 Browser task completed successfully",
      `Steps taken: ${result.stepsTaken ?? 0}`,
      result.executionTimeMs ? `Execution time: ${result.executionTimeMs}ms` : null,
      "",
      "Result:",
      result.result || "Task completed"
    ];
    return parts.filter(Boolean).join("\n");
  }
  return `\u274C Browser task failed: ${result.error || "Unknown error"}`;
}
function getSystemPrompt() {
  return BROWSER_SYSTEM_PROMPT;
}
function createBrowserTool(config) {
  return Object.assign({}, browserTool, {
    execute: async (input) => {
      return execute(input, config);
    },
    formatResult: (result) => {
      return formatResult(result);
    },
    getSystemPrompt: () => {
      return getSystemPrompt();
    }
  });
}

export {
  browserTool,
  execute,
  formatResult,
  getSystemPrompt,
  createBrowserTool,
  openai_exports
};
//# sourceMappingURL=chunk-3I5KHU25.js.map