@browserbasehq/stagehand 2.5.3-alpha-4994eabfa8016347ec001b40ceadb0c905403470 → 4.0.0-alpha-49bc5b68e4fbeb28a120b301b51c31a36db7d922

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/dist/index.d.ts +1367 -751
  2. package/dist/index.js +37087 -22062
  3. package/package.json +54 -78
  4. package/README.md +0 -165
  5. package/dist/evals/args.d.ts +0 -15
  6. package/dist/evals/cli.d.ts +0 -2
  7. package/dist/evals/core/summary.d.ts +0 -2
  8. package/dist/evals/datasets/osworld/adapter.d.ts +0 -22
  9. package/dist/evals/datasets/osworld/index.d.ts +0 -9
  10. package/dist/evals/datasets/osworld/types.d.ts +0 -54
  11. package/dist/evals/deterministic/bb.playwright.config.d.ts +0 -5
  12. package/dist/evals/deterministic/e2e.playwright.config.d.ts +0 -5
  13. package/dist/evals/deterministic/local.playwright.config.d.ts +0 -5
  14. package/dist/evals/deterministic/stagehand.config.d.ts +0 -3
  15. package/dist/evals/deterministic/tests/BrowserContext/addInitScript.test.d.ts +0 -1
  16. package/dist/evals/deterministic/tests/BrowserContext/cookies.test.d.ts +0 -1
  17. package/dist/evals/deterministic/tests/BrowserContext/multiPage.test.d.ts +0 -1
  18. package/dist/evals/deterministic/tests/BrowserContext/page.test.d.ts +0 -1
  19. package/dist/evals/deterministic/tests/BrowserContext/routing.test.d.ts +0 -1
  20. package/dist/evals/deterministic/tests/Errors/apiKeyError.test.d.ts +0 -1
  21. package/dist/evals/deterministic/tests/browserbase/contexts.test.d.ts +0 -1
  22. package/dist/evals/deterministic/tests/browserbase/downloads.test.d.ts +0 -1
  23. package/dist/evals/deterministic/tests/browserbase/sessions.test.d.ts +0 -1
  24. package/dist/evals/deterministic/tests/browserbase/uploads.test.d.ts +0 -1
  25. package/dist/evals/deterministic/tests/local/create.test.d.ts +0 -1
  26. package/dist/evals/deterministic/tests/local/downloads.test.d.ts +0 -1
  27. package/dist/evals/deterministic/tests/page/addInitScript.test.d.ts +0 -1
  28. package/dist/evals/deterministic/tests/page/addRemoveLocatorHandler.test.d.ts +0 -1
  29. package/dist/evals/deterministic/tests/page/addTags.test.d.ts +0 -1
  30. package/dist/evals/deterministic/tests/page/bringToFront.test.d.ts +0 -1
  31. package/dist/evals/deterministic/tests/page/content.test.d.ts +0 -1
  32. package/dist/evals/deterministic/tests/page/evaluate.test.d.ts +0 -1
  33. package/dist/evals/deterministic/tests/page/expose.test.d.ts +0 -1
  34. package/dist/evals/deterministic/tests/page/frames.test.d.ts +0 -1
  35. package/dist/evals/deterministic/tests/page/getBy.test.d.ts +0 -1
  36. package/dist/evals/deterministic/tests/page/livePageProxy.test.d.ts +0 -1
  37. package/dist/evals/deterministic/tests/page/navigation.test.d.ts +0 -1
  38. package/dist/evals/deterministic/tests/page/on.test.d.ts +0 -1
  39. package/dist/evals/deterministic/tests/page/pageContext.test.d.ts +0 -1
  40. package/dist/evals/deterministic/tests/page/reload.test.d.ts +0 -1
  41. package/dist/evals/deterministic/tests/page/waitFor.test.d.ts +0 -1
  42. package/dist/evals/env.d.ts +0 -13
  43. package/dist/evals/evaluator.d.ts +0 -29
  44. package/dist/evals/index.eval.d.ts +0 -1
  45. package/dist/evals/initStagehand.d.ts +0 -37
  46. package/dist/evals/llm_clients/hn_aisdk.d.ts +0 -2
  47. package/dist/evals/llm_clients/hn_customOpenAI.d.ts +0 -2
  48. package/dist/evals/llm_clients/hn_langchain.d.ts +0 -2
  49. package/dist/evals/logger.d.ts +0 -50
  50. package/dist/evals/scoring.d.ts +0 -25
  51. package/dist/evals/suites/gaia.d.ts +0 -2
  52. package/dist/evals/suites/onlineMind2Web.d.ts +0 -2
  53. package/dist/evals/suites/osworld.d.ts +0 -2
  54. package/dist/evals/suites/webbench.d.ts +0 -2
  55. package/dist/evals/suites/webvoyager.d.ts +0 -2
  56. package/dist/evals/taskConfig.d.ts +0 -33
  57. package/dist/evals/tasks/agent/all_recipes.d.ts +0 -2
  58. package/dist/evals/tasks/agent/apple_trade_in.d.ts +0 -2
  59. package/dist/evals/tasks/agent/apple_tv.d.ts +0 -2
  60. package/dist/evals/tasks/agent/arxiv_gpt_report.d.ts +0 -2
  61. package/dist/evals/tasks/agent/gaia.d.ts +0 -9
  62. package/dist/evals/tasks/agent/github.d.ts +0 -2
  63. package/dist/evals/tasks/agent/github_react_version.d.ts +0 -2
  64. package/dist/evals/tasks/agent/google_flights.d.ts +0 -2
  65. package/dist/evals/tasks/agent/google_maps.d.ts +0 -2
  66. package/dist/evals/tasks/agent/google_maps_2.d.ts +0 -2
  67. package/dist/evals/tasks/agent/google_maps_3.d.ts +0 -2
  68. package/dist/evals/tasks/agent/google_shopping.d.ts +0 -2
  69. package/dist/evals/tasks/agent/hotel_booking.d.ts +0 -2
  70. package/dist/evals/tasks/agent/hugging_face.d.ts +0 -2
  71. package/dist/evals/tasks/agent/iframe_form.d.ts +0 -2
  72. package/dist/evals/tasks/agent/iframe_form_multiple.d.ts +0 -2
  73. package/dist/evals/tasks/agent/kayak.d.ts +0 -2
  74. package/dist/evals/tasks/agent/kith.d.ts +0 -2
  75. package/dist/evals/tasks/agent/nba_trades.d.ts +0 -2
  76. package/dist/evals/tasks/agent/onlineMind2Web.d.ts +0 -2
  77. package/dist/evals/tasks/agent/osworld.d.ts +0 -2
  78. package/dist/evals/tasks/agent/sf_library_card.d.ts +0 -2
  79. package/dist/evals/tasks/agent/sf_library_card_multiple.d.ts +0 -2
  80. package/dist/evals/tasks/agent/sign_in.d.ts +0 -2
  81. package/dist/evals/tasks/agent/steam_games.d.ts +0 -2
  82. package/dist/evals/tasks/agent/trivago.d.ts +0 -2
  83. package/dist/evals/tasks/agent/ubereats.d.ts +0 -2
  84. package/dist/evals/tasks/agent/webbench.d.ts +0 -2
  85. package/dist/evals/tasks/agent/webvoyager.d.ts +0 -2
  86. package/dist/evals/tasks/agent/youtube.d.ts +0 -2
  87. package/dist/evals/tasks/allrecipes.d.ts +0 -2
  88. package/dist/evals/tasks/amazon_add_to_cart.d.ts +0 -2
  89. package/dist/evals/tasks/apple.d.ts +0 -2
  90. package/dist/evals/tasks/arxiv.d.ts +0 -2
  91. package/dist/evals/tasks/bidnet.d.ts +0 -2
  92. package/dist/evals/tasks/checkboxes.d.ts +0 -2
  93. package/dist/evals/tasks/combination_sauce.d.ts +0 -2
  94. package/dist/evals/tasks/costar.d.ts +0 -2
  95. package/dist/evals/tasks/csr_in_oopif.d.ts +0 -2
  96. package/dist/evals/tasks/csr_in_spif.d.ts +0 -2
  97. package/dist/evals/tasks/custom_dropdown.d.ts +0 -2
  98. package/dist/evals/tasks/dropdown.d.ts +0 -2
  99. package/dist/evals/tasks/expect_act_timeout.d.ts +0 -2
  100. package/dist/evals/tasks/extract_aigrant_companies.d.ts +0 -2
  101. package/dist/evals/tasks/extract_aigrant_targeted.d.ts +0 -2
  102. package/dist/evals/tasks/extract_aigrant_targeted_2.d.ts +0 -2
  103. package/dist/evals/tasks/extract_apartments.d.ts +0 -2
  104. package/dist/evals/tasks/extract_area_codes.d.ts +0 -2
  105. package/dist/evals/tasks/extract_baptist_health.d.ts +0 -2
  106. package/dist/evals/tasks/extract_capacitor_info.d.ts +0 -2
  107. package/dist/evals/tasks/extract_collaborators.d.ts +0 -2
  108. package/dist/evals/tasks/extract_csa.d.ts +0 -2
  109. package/dist/evals/tasks/extract_geniusee.d.ts +0 -2
  110. package/dist/evals/tasks/extract_geniusee_2.d.ts +0 -2
  111. package/dist/evals/tasks/extract_github_commits.d.ts +0 -2
  112. package/dist/evals/tasks/extract_github_stars.d.ts +0 -2
  113. package/dist/evals/tasks/extract_hamilton_weather.d.ts +0 -2
  114. package/dist/evals/tasks/extract_jfk_links.d.ts +0 -2
  115. package/dist/evals/tasks/extract_jstor_news.d.ts +0 -2
  116. package/dist/evals/tasks/extract_memorial_healthcare.d.ts +0 -2
  117. package/dist/evals/tasks/extract_nhl_stats.d.ts +0 -2
  118. package/dist/evals/tasks/extract_partners.d.ts +0 -2
  119. package/dist/evals/tasks/extract_press_releases.d.ts +0 -2
  120. package/dist/evals/tasks/extract_professional_info.d.ts +0 -2
  121. package/dist/evals/tasks/extract_public_notices.d.ts +0 -2
  122. package/dist/evals/tasks/extract_recipe.d.ts +0 -2
  123. package/dist/evals/tasks/extract_regulations_table.d.ts +0 -2
  124. package/dist/evals/tasks/extract_repo_name.d.ts +0 -2
  125. package/dist/evals/tasks/extract_resistor_info.d.ts +0 -2
  126. package/dist/evals/tasks/extract_rockauto.d.ts +0 -2
  127. package/dist/evals/tasks/extract_single_link.d.ts +0 -2
  128. package/dist/evals/tasks/extract_snowshoeing_destinations.d.ts +0 -2
  129. package/dist/evals/tasks/extract_staff_members.d.ts +0 -2
  130. package/dist/evals/tasks/extract_zillow.d.ts +0 -2
  131. package/dist/evals/tasks/google_flights.d.ts +0 -11
  132. package/dist/evals/tasks/heal_custom_dropdown.d.ts +0 -2
  133. package/dist/evals/tasks/heal_scroll_50.d.ts +0 -2
  134. package/dist/evals/tasks/heal_simple_google_search.d.ts +0 -2
  135. package/dist/evals/tasks/hidden_input_dropdown.d.ts +0 -2
  136. package/dist/evals/tasks/history.d.ts +0 -2
  137. package/dist/evals/tasks/homedepot.d.ts +0 -2
  138. package/dist/evals/tasks/iframe_form_filling.d.ts +0 -2
  139. package/dist/evals/tasks/iframe_hn.d.ts +0 -2
  140. package/dist/evals/tasks/iframe_same_proc.d.ts +0 -2
  141. package/dist/evals/tasks/iframe_scroll.d.ts +0 -2
  142. package/dist/evals/tasks/iframes_nested.d.ts +0 -2
  143. package/dist/evals/tasks/imdb_movie_details.d.ts +0 -2
  144. package/dist/evals/tasks/instructions.d.ts +0 -2
  145. package/dist/evals/tasks/ionwave.d.ts +0 -2
  146. package/dist/evals/tasks/ionwave_observe.d.ts +0 -2
  147. package/dist/evals/tasks/login.d.ts +0 -2
  148. package/dist/evals/tasks/multi_tab.d.ts +0 -2
  149. package/dist/evals/tasks/namespace_xpath.d.ts +0 -2
  150. package/dist/evals/tasks/nested_iframes_2.d.ts +0 -2
  151. package/dist/evals/tasks/nextChunk.d.ts +0 -2
  152. package/dist/evals/tasks/no_js_click.d.ts +0 -2
  153. package/dist/evals/tasks/nonsense_action.d.ts +0 -2
  154. package/dist/evals/tasks/observe_amazon_add_to_cart.d.ts +0 -2
  155. package/dist/evals/tasks/observe_github.d.ts +0 -2
  156. package/dist/evals/tasks/observe_iframes1.d.ts +0 -2
  157. package/dist/evals/tasks/observe_iframes2.d.ts +0 -2
  158. package/dist/evals/tasks/observe_simple_google_search.d.ts +0 -2
  159. package/dist/evals/tasks/observe_taxes.d.ts +0 -2
  160. package/dist/evals/tasks/observe_vantechjournal.d.ts +0 -2
  161. package/dist/evals/tasks/observe_yc_startup.d.ts +0 -2
  162. package/dist/evals/tasks/oopif_in_csr.d.ts +0 -2
  163. package/dist/evals/tasks/oopif_in_osr.d.ts +0 -2
  164. package/dist/evals/tasks/os_dropdown.d.ts +0 -2
  165. package/dist/evals/tasks/osr_in_oopif.d.ts +0 -2
  166. package/dist/evals/tasks/osr_in_spif.d.ts +0 -2
  167. package/dist/evals/tasks/panamcs.d.ts +0 -2
  168. package/dist/evals/tasks/peeler_complex.d.ts +0 -2
  169. package/dist/evals/tasks/peeler_simple.d.ts +0 -2
  170. package/dist/evals/tasks/prevChunk.d.ts +0 -2
  171. package/dist/evals/tasks/radio_btn.d.ts +0 -2
  172. package/dist/evals/tasks/rakuten_jp.d.ts +0 -2
  173. package/dist/evals/tasks/sciquest.d.ts +0 -2
  174. package/dist/evals/tasks/screenshot_cdp_toggle.d.ts +0 -9
  175. package/dist/evals/tasks/scroll_50.d.ts +0 -2
  176. package/dist/evals/tasks/scroll_75.d.ts +0 -2
  177. package/dist/evals/tasks/shadow_dom.d.ts +0 -2
  178. package/dist/evals/tasks/simple_google_search.d.ts +0 -2
  179. package/dist/evals/tasks/spif_in_csr.d.ts +0 -2
  180. package/dist/evals/tasks/spif_in_osr.d.ts +0 -2
  181. package/dist/evals/tasks/stock_x.d.ts +0 -2
  182. package/dist/evals/tasks/tab_handling.d.ts +0 -2
  183. package/dist/evals/tasks/ted_talk.d.ts +0 -2
  184. package/dist/evals/tasks/vanta_h.d.ts +0 -2
  185. package/dist/evals/tasks/vantechjournal.d.ts +0 -2
  186. package/dist/evals/tasks/wichita.d.ts +0 -2
  187. package/dist/evals/tasks/wikipedia.d.ts +0 -2
  188. package/dist/evals/utils/ScreenshotCollector.d.ts +0 -34
  189. package/dist/evals/utils/imageUtils.d.ts +0 -1
  190. package/dist/evals/utils.d.ts +0 -61
  191. package/dist/examples/2048.d.ts +0 -1
  192. package/dist/examples/actionable_observe_example.d.ts +0 -14
  193. package/dist/examples/cua-example.d.ts +0 -1
  194. package/dist/examples/custom_client_aisdk.d.ts +0 -1
  195. package/dist/examples/custom_client_langchain.d.ts +0 -1
  196. package/dist/examples/custom_client_openai.d.ts +0 -1
  197. package/dist/examples/example.d.ts +0 -1
  198. package/dist/examples/external_clients/aisdk.d.ts +0 -20
  199. package/dist/examples/external_clients/customOpenAI.d.ts +0 -18
  200. package/dist/examples/external_clients/langchain.d.ts +0 -9
  201. package/dist/examples/form_filling_sensible.d.ts +0 -1
  202. package/dist/examples/google_enter.d.ts +0 -6
  203. package/dist/examples/instructions.d.ts +0 -1
  204. package/dist/examples/integrations/exa.d.ts +0 -1
  205. package/dist/examples/integrations/supabase.d.ts +0 -1
  206. package/dist/examples/operator-example.d.ts +0 -8
  207. package/dist/examples/parameterizeApiKey.d.ts +0 -1
  208. package/dist/examples/popup.d.ts +0 -6
  209. package/dist/examples/wordle.d.ts +0 -1
  210. package/dist/lib/StagehandContext.d.ts +0 -25
  211. package/dist/lib/StagehandPage.d.ts +0 -103
  212. package/dist/lib/a11y/utils.d.ts +0 -144
  213. package/dist/lib/agent/AgentClient.d.ts +0 -20
  214. package/dist/lib/agent/AgentProvider.d.ts +0 -19
  215. package/dist/lib/agent/AnthropicCUAClient.d.ts +0 -56
  216. package/dist/lib/agent/GoogleCUAClient.d.ts +0 -63
  217. package/dist/lib/agent/OpenAICUAClient.d.ts +0 -65
  218. package/dist/lib/agent/StagehandAgent.d.ts +0 -15
  219. package/dist/lib/agent/tools/act.d.ts +0 -59
  220. package/dist/lib/agent/tools/ariaTree.d.ts +0 -11
  221. package/dist/lib/agent/tools/close.d.ts +0 -22
  222. package/dist/lib/agent/tools/extract.d.ts +0 -38
  223. package/dist/lib/agent/tools/fillform.d.ts +0 -37
  224. package/dist/lib/agent/tools/goto.d.ts +0 -29
  225. package/dist/lib/agent/tools/index.d.ts +0 -257
  226. package/dist/lib/agent/tools/navback.d.ts +0 -17
  227. package/dist/lib/agent/tools/screenshot.d.ts +0 -13
  228. package/dist/lib/agent/tools/scroll.d.ts +0 -23
  229. package/dist/lib/agent/tools/wait.d.ts +0 -18
  230. package/dist/lib/agent/utils/cuaKeyMapping.d.ts +0 -10
  231. package/dist/lib/agent/utils/imageCompression.d.ts +0 -53
  232. package/dist/lib/agent/utils/messageProcessing.d.ts +0 -13
  233. package/dist/lib/api.d.ts +0 -23
  234. package/dist/lib/browserbaseDefaults.d.ts +0 -9
  235. package/dist/lib/cache/ActionCache.d.ts +0 -62
  236. package/dist/lib/cache/BaseCache.d.ts +0 -66
  237. package/dist/lib/cache/LLMCache.d.ts +0 -22
  238. package/dist/lib/cache.d.ts +0 -29
  239. package/dist/lib/dom/build/scriptContent.d.ts +0 -1
  240. package/dist/lib/dom/elementCheckUtils.d.ts +0 -2
  241. package/dist/lib/dom/genDomScripts.d.ts +0 -1
  242. package/dist/lib/dom/index.d.ts +0 -2
  243. package/dist/lib/dom/process.d.ts +0 -17
  244. package/dist/lib/dom/utils.d.ts +0 -7
  245. package/dist/lib/dom/xpathUtils.d.ts +0 -14
  246. package/dist/lib/handlers/actHandler.d.ts +0 -33
  247. package/dist/lib/handlers/cuaAgentHandler.d.ts +0 -58
  248. package/dist/lib/handlers/extractHandler.d.ts +0 -54
  249. package/dist/lib/handlers/handlerUtils/actHandlerUtils.d.ts +0 -21
  250. package/dist/lib/handlers/observeHandler.d.ts +0 -40
  251. package/dist/lib/handlers/stagehandAgentHandler.d.ts +0 -27
  252. package/dist/lib/index.d.ts +0 -94
  253. package/dist/lib/inference.d.ts +0 -61
  254. package/dist/lib/inferenceLogUtils.d.ts +0 -12
  255. package/dist/lib/llm/AnthropicClient.d.ts +0 -21
  256. package/dist/lib/llm/CerebrasClient.d.ts +0 -22
  257. package/dist/lib/llm/GoogleClient.d.ts +0 -24
  258. package/dist/lib/llm/GroqClient.d.ts +0 -22
  259. package/dist/lib/llm/LLMClient.d.ts +0 -99
  260. package/dist/lib/llm/LLMProvider.d.ts +0 -13
  261. package/dist/lib/llm/OpenAIClient.d.ts +0 -20
  262. package/dist/lib/llm/aisdk.d.ts +0 -20
  263. package/dist/lib/logger.d.ts +0 -54
  264. package/dist/lib/mcp/connection.d.ts +0 -11
  265. package/dist/lib/mcp/utils.d.ts +0 -3
  266. package/dist/lib/prompt.d.ts +0 -14
  267. package/dist/lib/utils.d.ts +0 -68
  268. package/dist/lib/version.d.ts +0 -5
  269. package/dist/scripts/gen-version.d.ts +0 -1
  270. package/dist/scripts/run-evals.d.ts +0 -1
  271. package/dist/stagehand.config.d.ts +0 -3
  272. package/dist/types/act.d.ts +0 -50
  273. package/dist/types/agent.d.ts +0 -144
  274. package/dist/types/api.d.ts +0 -40
  275. package/dist/types/browser.d.ts +0 -10
  276. package/dist/types/context.d.ts +0 -117
  277. package/dist/types/evals.d.ts +0 -95
  278. package/dist/types/evaluator.d.ts +0 -40
  279. package/dist/types/llm.d.ts +0 -11
  280. package/dist/types/log.d.ts +0 -23
  281. package/dist/types/model.d.ts +0 -17
  282. package/dist/types/page.d.ts +0 -38
  283. package/dist/types/playwright.d.ts +0 -12
  284. package/dist/types/stagehand.d.ts +0 -330
  285. package/dist/types/stagehandApiErrors.d.ts +0 -18
  286. package/dist/types/stagehandErrors.d.ts +0 -104
@@ -1,257 +0,0 @@
1
- import { Stagehand } from "../../index";
2
- import { LogLine } from "@/types/log";
3
- export interface AgentToolOptions {
4
- executionModel?: string;
5
- logger?: (message: LogLine) => void;
6
- }
7
- export declare function createAgentTools(stagehand: Stagehand, options?: AgentToolOptions): {
8
- act: import("ai/dist").Tool<import("zod/v3").ZodObject<{
9
- action: import("zod/v3").ZodString;
10
- }, "strip", import("zod/v3").ZodTypeAny, {
11
- action?: string;
12
- }, {
13
- action?: string;
14
- }>, {
15
- success: boolean;
16
- error: string;
17
- isIframe: boolean;
18
- action?: undefined;
19
- playwrightArguments?: undefined;
20
- } | {
21
- success: boolean;
22
- action: string;
23
- isIframe: boolean;
24
- playwrightArguments: {
25
- description: string;
26
- method: string;
27
- arguments: string[];
28
- selector: string;
29
- };
30
- error?: undefined;
31
- } | {
32
- success: boolean;
33
- error: any;
34
- isIframe?: undefined;
35
- action?: undefined;
36
- playwrightArguments?: undefined;
37
- }> & {
38
- execute: (args: {
39
- action?: string;
40
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
41
- success: boolean;
42
- error: string;
43
- isIframe: boolean;
44
- action?: undefined;
45
- playwrightArguments?: undefined;
46
- } | {
47
- success: boolean;
48
- action: string;
49
- isIframe: boolean;
50
- playwrightArguments: {
51
- description: string;
52
- method: string;
53
- arguments: string[];
54
- selector: string;
55
- };
56
- error?: undefined;
57
- } | {
58
- success: boolean;
59
- error: any;
60
- isIframe?: undefined;
61
- action?: undefined;
62
- playwrightArguments?: undefined;
63
- }>;
64
- };
65
- ariaTree: import("ai/dist").Tool<import("zod/v3").ZodObject<{}, "strip", import("zod/v3").ZodTypeAny, {}, {}>, {
66
- content: string;
67
- pageUrl: string;
68
- }> & {
69
- execute: (args: {}, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
70
- content: string;
71
- pageUrl: string;
72
- }>;
73
- };
74
- close: import("ai/dist").Tool<import("zod/v3").ZodObject<{
75
- reasoning: import("zod/v3").ZodString;
76
- success: import("zod/v3").ZodBoolean;
77
- }, "strip", import("zod/v3").ZodTypeAny, {
78
- reasoning?: string;
79
- success?: boolean;
80
- }, {
81
- reasoning?: string;
82
- success?: boolean;
83
- }>, {
84
- success: boolean;
85
- reasoning: string;
86
- }> & {
87
- execute: (args: {
88
- reasoning?: string;
89
- success?: boolean;
90
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
91
- success: boolean;
92
- reasoning: string;
93
- }>;
94
- };
95
- extract: import("ai/dist").Tool<import("zod/v3").ZodObject<{
96
- instruction: import("zod/v3").ZodString;
97
- schema: import("zod/v3").ZodString;
98
- }, "strip", import("zod/v3").ZodTypeAny, {
99
- schema?: string;
100
- instruction?: string;
101
- }, {
102
- schema?: string;
103
- instruction?: string;
104
- }>, {
105
- success: boolean;
106
- data: any;
107
- timestamp: number;
108
- error?: undefined;
109
- } | {
110
- success: boolean;
111
- error: string;
112
- timestamp: number;
113
- data?: undefined;
114
- }> & {
115
- execute: (args: {
116
- schema?: string;
117
- instruction?: string;
118
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
119
- success: boolean;
120
- data: any;
121
- timestamp: number;
122
- error?: undefined;
123
- } | {
124
- success: boolean;
125
- error: string;
126
- timestamp: number;
127
- data?: undefined;
128
- }>;
129
- };
130
- fillForm: import("ai/dist").Tool<import("zod/v3").ZodObject<{
131
- fields: import("zod/v3").ZodArray<import("zod/v3").ZodObject<{
132
- action: import("zod/v3").ZodString;
133
- value: import("zod/v3").ZodString;
134
- }, "strip", import("zod/v3").ZodTypeAny, {
135
- value?: string;
136
- action?: string;
137
- }, {
138
- value?: string;
139
- action?: string;
140
- }>, "many">;
141
- }, "strip", import("zod/v3").ZodTypeAny, {
142
- fields?: {
143
- value?: string;
144
- action?: string;
145
- }[];
146
- }, {
147
- fields?: {
148
- value?: string;
149
- action?: string;
150
- }[];
151
- }>, {
152
- success: boolean;
153
- actions: import("@/types/stagehand").ActResult[];
154
- }> & {
155
- execute: (args: {
156
- fields?: {
157
- value?: string;
158
- action?: string;
159
- }[];
160
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
161
- success: boolean;
162
- actions: import("@/types/stagehand").ActResult[];
163
- }>;
164
- };
165
- goto: import("ai/dist").Tool<import("zod/v3").ZodObject<{
166
- url: import("zod/v3").ZodString;
167
- }, "strip", import("zod/v3").ZodTypeAny, {
168
- url?: string;
169
- }, {
170
- url?: string;
171
- }>, {
172
- success: boolean;
173
- url: string;
174
- error?: undefined;
175
- } | {
176
- success: boolean;
177
- error: any;
178
- url?: undefined;
179
- }> & {
180
- execute: (args: {
181
- url?: string;
182
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
183
- success: boolean;
184
- url: string;
185
- error?: undefined;
186
- } | {
187
- success: boolean;
188
- error: any;
189
- url?: undefined;
190
- }>;
191
- };
192
- navback: import("ai/dist").Tool<import("zod/v3").ZodObject<{
193
- reasoning: import("zod/v3").ZodString;
194
- }, "strip", import("zod/v3").ZodTypeAny, {
195
- reasoning?: string;
196
- }, {
197
- reasoning?: string;
198
- }>, {
199
- success: boolean;
200
- }> & {
201
- execute: (args: {
202
- reasoning?: string;
203
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
204
- success: boolean;
205
- }>;
206
- };
207
- screenshot: import("ai/dist").Tool<import("zod/v3").ZodObject<{}, "strip", import("zod/v3").ZodTypeAny, {}, {}>, {
208
- base64: string;
209
- timestamp: number;
210
- pageUrl: string;
211
- }> & {
212
- execute: (args: {}, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
213
- base64: string;
214
- timestamp: number;
215
- pageUrl: string;
216
- }>;
217
- };
218
- scroll: import("ai/dist").Tool<import("zod/v3").ZodObject<{
219
- pixels: import("zod/v3").ZodNumber;
220
- direction: import("zod/v3").ZodEnum<["up", "down"]>;
221
- }, "strip", import("zod/v3").ZodTypeAny, {
222
- direction?: "down" | "up";
223
- pixels?: number;
224
- }, {
225
- direction?: "down" | "up";
226
- pixels?: number;
227
- }>, {
228
- success: boolean;
229
- pixels: number;
230
- }> & {
231
- execute: (args: {
232
- direction?: "down" | "up";
233
- pixels?: number;
234
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
235
- success: boolean;
236
- pixels: number;
237
- }>;
238
- };
239
- wait: import("ai/dist").Tool<import("zod/v3").ZodObject<{
240
- timeMs: import("zod/v3").ZodNumber;
241
- }, "strip", import("zod/v3").ZodTypeAny, {
242
- timeMs?: number;
243
- }, {
244
- timeMs?: number;
245
- }>, {
246
- success: boolean;
247
- waited: number;
248
- }> & {
249
- execute: (args: {
250
- timeMs?: number;
251
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
252
- success: boolean;
253
- waited: number;
254
- }>;
255
- };
256
- };
257
- export type AgentTools = ReturnType<typeof createAgentTools>;
@@ -1,17 +0,0 @@
1
- import { z } from "zod/v3";
2
- import { Stagehand } from "../../index";
3
- export declare const createNavBackTool: (stagehand: Stagehand) => import("ai/dist").Tool<z.ZodObject<{
4
- reasoning: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
6
- reasoning?: string;
7
- }, {
8
- reasoning?: string;
9
- }>, {
10
- success: boolean;
11
- }> & {
12
- execute: (args: {
13
- reasoning?: string;
14
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
15
- success: boolean;
16
- }>;
17
- };
@@ -1,13 +0,0 @@
1
- import { z } from "zod/v3";
2
- import { Stagehand } from "../../index";
3
- export declare const createScreenshotTool: (stagehand: Stagehand) => import("ai/dist").Tool<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>, {
4
- base64: string;
5
- timestamp: number;
6
- pageUrl: string;
7
- }> & {
8
- execute: (args: {}, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
9
- base64: string;
10
- timestamp: number;
11
- pageUrl: string;
12
- }>;
13
- };
@@ -1,23 +0,0 @@
1
- import { z } from "zod/v3";
2
- import { Stagehand } from "../../index";
3
- export declare const createScrollTool: (stagehand: Stagehand) => import("ai/dist").Tool<z.ZodObject<{
4
- pixels: z.ZodNumber;
5
- direction: z.ZodEnum<["up", "down"]>;
6
- }, "strip", z.ZodTypeAny, {
7
- direction?: "down" | "up";
8
- pixels?: number;
9
- }, {
10
- direction?: "down" | "up";
11
- pixels?: number;
12
- }>, {
13
- success: boolean;
14
- pixels: number;
15
- }> & {
16
- execute: (args: {
17
- direction?: "down" | "up";
18
- pixels?: number;
19
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
20
- success: boolean;
21
- pixels: number;
22
- }>;
23
- };
@@ -1,18 +0,0 @@
1
- import { z } from "zod/v3";
2
- export declare const createWaitTool: () => import("ai/dist").Tool<z.ZodObject<{
3
- timeMs: z.ZodNumber;
4
- }, "strip", z.ZodTypeAny, {
5
- timeMs?: number;
6
- }, {
7
- timeMs?: number;
8
- }>, {
9
- success: boolean;
10
- waited: number;
11
- }> & {
12
- execute: (args: {
13
- timeMs?: number;
14
- }, options: import("ai/dist").ToolExecutionOptions) => PromiseLike<{
15
- success: boolean;
16
- waited: number;
17
- }>;
18
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * Universal key mapping utility for converting various key representations
3
- * to Playwright-compatible key names. Used by all CUA clients and handlers.
4
- */
5
- /**
6
- * Maps a key name from various formats to Playwright-compatible format
7
- * @param key The key name in any supported format
8
- * @returns The Playwright-compatible key name
9
- */
10
- export declare function mapKeyToPlaywright(key: string): string;
@@ -1,53 +0,0 @@
1
- import { AnthropicMessage, AnthropicToolResult, ResponseInputItem as OpenAIResponseInputItem } from "@/types/agent";
2
- import type { Content as GoogleContent } from "@google/genai";
3
- export type ResponseInputItem = AnthropicMessage | AnthropicToolResult;
4
- export type AnthropicResponseInputItem = AnthropicMessage | AnthropicToolResult;
5
- export type SupportedInputItem = AnthropicResponseInputItem | OpenAIResponseInputItem | GoogleContent;
6
- /**
7
- * Finds all items in the conversation history that contain images
8
- * @param items - Array of conversation items to check
9
- * @returns Array of indices where images were found
10
- */
11
- export declare function findItemsWithImages(items: ResponseInputItem[]): number[];
12
- /**
13
- * Compresses conversation history by removing images from older items
14
- * while keeping the most recent images intact
15
- * @param items - Array of conversation items to process
16
- * @param keepMostRecentCount - Number of most recent image-containing items to preserve (default: 2)
17
- * @returns Object with processed items
18
- */
19
- export declare function compressConversationImages(items: ResponseInputItem[], keepMostRecentCount?: number): {
20
- items: ResponseInputItem[];
21
- };
22
- /**
23
- * Finds all items in the conversation history that contain images (Google format)
24
- * @param items - Array of conversation items to check
25
- * @returns Array of indices where images were found
26
- */
27
- export declare function findGoogleItemsWithImages(items: GoogleContent[]): number[];
28
- /**
29
- * Finds all items in the conversation history that contain images (OpenAI format)
30
- * @param items - Array of conversation items to check
31
- * @returns Array of indices where images were found
32
- */
33
- export declare function findOpenAIItemsWithImages(items: OpenAIResponseInputItem[]): number[];
34
- /**
35
- * Compresses OpenAI conversation history by removing images from older items
36
- * while keeping the most recent images intact
37
- * @param items - Array of conversation items to process
38
- * @param keepMostRecentCount - Number of most recent image-containing items to preserve (default: 2)
39
- * @returns Object with processed items
40
- */
41
- export declare function compressOpenAIConversationImages(items: OpenAIResponseInputItem[], keepMostRecentCount?: number): {
42
- items: OpenAIResponseInputItem[];
43
- };
44
- /**
45
- * Compresses Google conversation history by removing images from older items
46
- * while keeping the most recent images intact
47
- * @param items - Array of conversation items to process
48
- * @param keepMostRecentCount - Number of most recent image-containing items to preserve (default: 2)
49
- * @returns Object with processed items
50
- */
51
- export declare function compressGoogleConversationImages(items: GoogleContent[], keepMostRecentCount?: number): {
52
- items: GoogleContent[];
53
- };
@@ -1,13 +0,0 @@
1
- import { type LanguageModelV1CallOptions } from "ai";
2
- export interface CompressionStats {
3
- originalSize: number;
4
- compressedSize: number;
5
- savedChars: number;
6
- compressionRatio: number;
7
- screenshotCount: number;
8
- ariaTreeCount: number;
9
- }
10
- export declare function processMessages(params: LanguageModelV1CallOptions): {
11
- processedPrompt: LanguageModelV1CallOptions["prompt"];
12
- stats: CompressionStats;
13
- };
package/dist/lib/api.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { z } from "zod/v3";
2
- import { StagehandAPIConstructorParams, StartSessionParams, StartSessionResult } from "../types/api";
3
- import { GotoOptions } from "../types/playwright";
4
- import { ActOptions, ActResult, AgentConfig, ExtractOptions, ExtractResult, ObserveOptions, ObserveResult } from "../types/stagehand";
5
- import { AgentExecuteOptions, AgentResult } from ".";
6
- export declare class StagehandAPI {
7
- private apiKey;
8
- private projectId;
9
- private sessionId?;
10
- private modelApiKey;
11
- private logger;
12
- private fetchWithCookies;
13
- constructor({ apiKey, projectId, logger }: StagehandAPIConstructorParams);
14
- init({ modelName, modelApiKey, domSettleTimeoutMs, verbose, debugDom, systemPrompt, selfHeal, waitForCaptchaSolves, actionTimeoutMs, browserbaseSessionCreateParams, browserbaseSessionID, }: StartSessionParams): Promise<StartSessionResult>;
15
- act(options: ActOptions | ObserveResult): Promise<ActResult>;
16
- extract<T extends z.AnyZodObject>(options: ExtractOptions<T>): Promise<ExtractResult<T>>;
17
- observe(options?: ObserveOptions): Promise<ObserveResult[]>;
18
- goto(url: string, options?: GotoOptions): Promise<void>;
19
- agentExecute(agentConfig: AgentConfig, executeOptions: AgentExecuteOptions): Promise<AgentResult>;
20
- end(): Promise<Response>;
21
- private execute;
22
- private request;
23
- }
@@ -1,9 +0,0 @@
1
- import Browserbase from "@browserbasehq/sdk";
2
- export type BrowserbaseSessionCreateParams = Omit<Browserbase.Sessions.SessionCreateParams, "projectId"> & {
3
- projectId?: string;
4
- };
5
- export declare const DEFAULT_BROWSERBASE_VIEWPORT: {
6
- readonly width: 1288;
7
- readonly height: 711;
8
- };
9
- export declare function applyDefaultBrowserSettingsViewport(params?: BrowserbaseSessionCreateParams): BrowserbaseSessionCreateParams;
@@ -1,62 +0,0 @@
1
- import { LogLine } from "../../types/log";
2
- import { BaseCache, CacheEntry } from "./BaseCache";
3
- export interface PlaywrightCommand {
4
- method: string;
5
- args: string[];
6
- }
7
- export interface ActionEntry extends CacheEntry {
8
- data: {
9
- playwrightCommand: PlaywrightCommand;
10
- componentString: string;
11
- xpaths: string[];
12
- newStepString: string;
13
- completed: boolean;
14
- previousSelectors: string[];
15
- action: string;
16
- };
17
- }
18
- /**
19
- * ActionCache handles logging and retrieving actions along with their Playwright commands.
20
- */
21
- export declare class ActionCache extends BaseCache<ActionEntry> {
22
- constructor(logger: (message: LogLine) => void, cacheDir?: string, cacheFile?: string);
23
- addActionStep({ url, action, previousSelectors, playwrightCommand, componentString, xpaths, newStepString, completed, requestId, }: {
24
- url: string;
25
- action: string;
26
- previousSelectors: string[];
27
- playwrightCommand: PlaywrightCommand;
28
- componentString: string;
29
- requestId: string;
30
- xpaths: string[];
31
- newStepString: string;
32
- completed: boolean;
33
- }): Promise<void>;
34
- /**
35
- * Retrieves all actions for a specific trajectory.
36
- * @param trajectoryId - Unique identifier for the trajectory.
37
- * @param requestId - The identifier for the current request.
38
- * @returns An array of TrajectoryEntry objects or null if not found.
39
- */
40
- getActionStep({ url, action, previousSelectors, requestId, }: {
41
- url: string;
42
- action: string;
43
- previousSelectors: string[];
44
- requestId: string;
45
- }): Promise<ActionEntry["data"] | null>;
46
- removeActionStep(cacheHashObj: {
47
- url: string;
48
- action: string;
49
- previousSelectors: string[];
50
- requestId: string;
51
- }): Promise<void>;
52
- /**
53
- * Clears all actions for a specific trajectory.
54
- * @param trajectoryId - Unique identifier for the trajectory.
55
- * @param requestId - The identifier for the current request.
56
- */
57
- clearAction(requestId: string): Promise<void>;
58
- /**
59
- * Resets the entire action cache.
60
- */
61
- resetCache(): Promise<void>;
62
- }
@@ -1,66 +0,0 @@
1
- import { LogLine } from "../../types/log";
2
- export interface CacheEntry {
3
- timestamp: number;
4
- data: unknown;
5
- requestId: string;
6
- }
7
- export interface CacheStore {
8
- [key: string]: CacheEntry;
9
- }
10
- export declare class BaseCache<T extends CacheEntry> {
11
- private readonly CACHE_MAX_AGE_MS;
12
- private readonly CLEANUP_PROBABILITY;
13
- protected cacheDir: string;
14
- protected cacheFile: string;
15
- protected lockFile: string;
16
- protected logger: (message: LogLine) => void;
17
- private readonly LOCK_TIMEOUT_MS;
18
- protected lockAcquired: boolean;
19
- protected lockAcquireFailures: number;
20
- protected requestIdToUsedHashes: {
21
- [key: string]: string[];
22
- };
23
- constructor(logger: (message: LogLine) => void, cacheDir?: string, cacheFile?: string);
24
- private setupProcessHandlers;
25
- protected ensureCacheDirectory(): void;
26
- protected createHash(data: unknown): string;
27
- protected sleep(ms: number): Promise<void>;
28
- acquireLock(): Promise<boolean>;
29
- releaseLock(): void;
30
- /**
31
- * Cleans up stale cache entries that exceed the maximum age.
32
- */
33
- cleanupStaleEntries(): Promise<void>;
34
- protected readCache(): CacheStore;
35
- protected writeCache(cache: CacheStore): void;
36
- /**
37
- * Retrieves data from the cache based on the provided options.
38
- * @param hashObj - The options used to generate the cache key.
39
- * @param requestId - The identifier for the current request.
40
- * @returns The cached data if available, otherwise null.
41
- */
42
- get(hashObj: Record<string, unknown> | string, requestId: string): Promise<T["data"] | null>;
43
- /**
44
- * Stores data in the cache based on the provided options and requestId.
45
- * @param hashObj - The options used to generate the cache key.
46
- * @param data - The data to be cached.
47
- * @param requestId - The identifier for the cache entry.
48
- */
49
- set(hashObj: Record<string, unknown>, data: T["data"], requestId: string): Promise<void>;
50
- delete(hashObj: Record<string, unknown>): Promise<void>;
51
- /**
52
- * Tracks the usage of a hash with a specific requestId.
53
- * @param requestId - The identifier for the current request.
54
- * @param hash - The cache key hash.
55
- */
56
- protected trackRequestIdUsage(requestId: string, hash: string): void;
57
- /**
58
- * Deletes all cache entries associated with a specific requestId.
59
- * @param requestId - The identifier for the request whose cache entries should be deleted.
60
- */
61
- deleteCacheForRequestId(requestId: string): Promise<void>;
62
- /**
63
- * Resets the entire cache by clearing the cache file.
64
- */
65
- resetCache(): void;
66
- }
@@ -1,22 +0,0 @@
1
- import { BaseCache, CacheEntry } from "./BaseCache";
2
- export declare class LLMCache extends BaseCache<CacheEntry> {
3
- constructor(logger: (message: {
4
- category?: string;
5
- message: string;
6
- level?: number;
7
- }) => void, cacheDir?: string, cacheFile?: string);
8
- /**
9
- * Overrides the get method to track used hashes by requestId.
10
- * @param options - The options used to generate the cache key.
11
- * @param requestId - The identifier for the current request.
12
- * @returns The cached data if available, otherwise null.
13
- */
14
- get<T>(options: Record<string, unknown>, requestId: string): Promise<T | null>;
15
- /**
16
- * Overrides the set method to include cache cleanup logic.
17
- * @param options - The options used to generate the cache key.
18
- * @param data - The data to be cached.
19
- * @param requestId - The identifier for the current request.
20
- */
21
- set(options: Record<string, unknown>, data: unknown, requestId: string): Promise<void>;
22
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * A file system cache to skip inference when repeating steps
3
- * It also acts as the source of truth for identifying previously seen actions and observations
4
- */
5
- declare class Cache {
6
- disabled: boolean;
7
- constructor({ disabled }?: {
8
- disabled?: boolean;
9
- });
10
- readObservations(): any;
11
- readActions(): any;
12
- writeObservations({ key, value, }: {
13
- key: string;
14
- value: {
15
- id: string;
16
- result: string;
17
- };
18
- }): void;
19
- writeActions({ key, value, }: {
20
- key: string;
21
- value: {
22
- id: string;
23
- result: string;
24
- };
25
- }): void;
26
- evictCache(): void;
27
- private initCache;
28
- }
29
- export default Cache;
@@ -1 +0,0 @@
1
- export declare const scriptContent = "(() => {\n // lib/dom/elementCheckUtils.ts\n function isElementNode(node) {\n return node.nodeType === Node.ELEMENT_NODE;\n }\n function isTextNode(node) {\n return node.nodeType === Node.TEXT_NODE && Boolean(node.textContent?.trim());\n }\n\n // lib/dom/xpathUtils.ts\n function getParentElement(node) {\n return isElementNode(node) ? node.parentElement : node.parentNode;\n }\n function getCombinations(attributes, size) {\n const results = [];\n function helper(start, combo) {\n if (combo.length === size) {\n results.push([...combo]);\n return;\n }\n for (let i = start; i < attributes.length; i++) {\n combo.push(attributes[i]);\n helper(i + 1, combo);\n combo.pop();\n }\n }\n helper(0, []);\n return results;\n }\n function isXPathFirstResultElement(xpath, target) {\n try {\n const result = document.evaluate(\n xpath,\n document.documentElement,\n null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,\n null\n );\n return result.snapshotItem(0) === target;\n } catch (error) {\n console.warn(`Invalid XPath expression: ${xpath}`, error);\n return false;\n }\n }\n function escapeXPathString(value) {\n if (value.includes(\"'\")) {\n if (value.includes('\"')) {\n return \"concat(\" + value.split(/('+)/).map((part) => {\n if (part === \"'\") {\n return `\"'\"`;\n } else if (part.startsWith(\"'\") && part.endsWith(\"'\")) {\n return `\"${part}\"`;\n } else {\n return `'${part}'`;\n }\n }).join(\",\") + \")\";\n } else {\n return `\"${value}\"`;\n }\n } else {\n return `'${value}'`;\n }\n }\n async function generateXPathsForElement(element) {\n if (!element) return [];\n const [complexXPath, standardXPath, idBasedXPath] = await Promise.all([\n generateComplexXPath(element),\n generateStandardXPath(element),\n generatedIdBasedXPath(element)\n ]);\n return [standardXPath, ...idBasedXPath ? [idBasedXPath] : [], complexXPath];\n }\n async function generateComplexXPath(element) {\n const parts = [];\n let currentElement = element;\n while (currentElement && (isTextNode(currentElement) || isElementNode(currentElement))) {\n if (isElementNode(currentElement)) {\n const el = currentElement;\n let selector = el.tagName.toLowerCase();\n const attributePriority = [\n \"data-qa\",\n \"data-component\",\n \"data-role\",\n \"role\",\n \"aria-role\",\n \"type\",\n \"name\",\n \"aria-label\",\n \"placeholder\",\n \"title\",\n \"alt\"\n ];\n const attributes = attributePriority.map((attr) => {\n let value = el.getAttribute(attr);\n if (attr === \"href-full\" && value) {\n value = el.getAttribute(\"href\");\n }\n return value ? { attr: attr === \"href-full\" ? \"href\" : attr, value } : null;\n }).filter((attr) => attr !== null);\n let uniqueSelector = \"\";\n for (let i = 1; i <= attributes.length; i++) {\n const combinations = getCombinations(attributes, i);\n for (const combo of combinations) {\n const conditions = combo.map((a) => `@${a.attr}=${escapeXPathString(a.value)}`).join(\" and \");\n const xpath2 = `//${selector}[${conditions}]`;\n if (isXPathFirstResultElement(xpath2, el)) {\n uniqueSelector = xpath2;\n break;\n }\n }\n if (uniqueSelector) break;\n }\n if (uniqueSelector) {\n parts.unshift(uniqueSelector.replace(\"//\", \"\"));\n break;\n } else {\n const parent = getParentElement(el);\n if (parent) {\n const siblings = Array.from(parent.children).filter(\n (sibling) => sibling.tagName === el.tagName\n );\n const index = siblings.indexOf(el) + 1;\n selector += siblings.length > 1 ? `[${index}]` : \"\";\n }\n parts.unshift(selector);\n }\n }\n currentElement = getParentElement(currentElement);\n }\n const xpath = \"//\" + parts.join(\"/\");\n return xpath;\n }\n async function generateStandardXPath(element) {\n const parts = [];\n while (element && (isTextNode(element) || isElementNode(element))) {\n let index = 0;\n let hasSameTypeSiblings = false;\n const siblings = element.parentElement ? Array.from(element.parentElement.childNodes) : [];\n for (let i = 0; i < siblings.length; i++) {\n const sibling = siblings[i];\n if (sibling.nodeType === element.nodeType && sibling.nodeName === element.nodeName) {\n index = index + 1;\n hasSameTypeSiblings = true;\n if (sibling.isSameNode(element)) {\n break;\n }\n }\n }\n if (element.nodeName !== \"#text\") {\n const tagName = element.nodeName.toLowerCase();\n const pathIndex = hasSameTypeSiblings ? `[${index}]` : \"\";\n parts.unshift(`${tagName}${pathIndex}`);\n }\n element = element.parentElement;\n }\n return parts.length ? `/${parts.join(\"/\")}` : \"\";\n }\n async function generatedIdBasedXPath(element) {\n if (isElementNode(element) && element.id) {\n return `//*[@id='${element.id}']`;\n }\n return null;\n }\n\n // types/stagehandErrors.ts\n var StagehandError = class extends Error {\n constructor(message) {\n super(message);\n this.name = this.constructor.name;\n }\n };\n var StagehandDomProcessError = class extends StagehandError {\n constructor(message) {\n super(`Error Processing Dom: ${message}`);\n }\n };\n\n // lib/dom/utils.ts\n function canElementScroll(elem) {\n if (typeof elem.scrollTo !== \"function\") {\n console.warn(\"canElementScroll: .scrollTo is not a function.\");\n return false;\n }\n try {\n const originalTop = elem.scrollTop;\n elem.scrollTo({\n top: originalTop + 100,\n left: 0,\n behavior: \"instant\"\n });\n if (elem.scrollTop === originalTop) {\n throw new StagehandDomProcessError(\"scrollTop did not change\");\n }\n elem.scrollTo({\n top: originalTop,\n left: 0,\n behavior: \"instant\"\n });\n return true;\n } catch (error) {\n console.warn(\"canElementScroll error:\", error.message || error);\n return false;\n }\n }\n function getNodeFromXpath(xpath) {\n return document.evaluate(\n xpath,\n document.documentElement,\n null,\n XPathResult.FIRST_ORDERED_NODE_TYPE,\n null\n ).singleNodeValue;\n }\n function waitForElementScrollEnd(element, idleMs = 100) {\n return new Promise((resolve) => {\n let scrollEndTimer;\n const handleScroll = () => {\n clearTimeout(scrollEndTimer);\n scrollEndTimer = window.setTimeout(() => {\n element.removeEventListener(\"scroll\", handleScroll);\n resolve();\n }, idleMs);\n };\n element.addEventListener(\"scroll\", handleScroll, { passive: true });\n handleScroll();\n });\n }\n\n // lib/dom/process.ts\n function getScrollableElements(topN) {\n const docEl = document.documentElement;\n const scrollableElements = [docEl];\n const allElements = document.querySelectorAll(\"*\");\n for (const elem of allElements) {\n const style = window.getComputedStyle(elem);\n const overflowY = style.overflowY;\n const isPotentiallyScrollable = overflowY === \"auto\" || overflowY === \"scroll\" || overflowY === \"overlay\";\n if (isPotentiallyScrollable) {\n const candidateScrollDiff = elem.scrollHeight - elem.clientHeight;\n if (candidateScrollDiff > 0 && canElementScroll(elem)) {\n scrollableElements.push(elem);\n }\n }\n }\n scrollableElements.sort((a, b) => b.scrollHeight - a.scrollHeight);\n if (topN !== void 0) {\n return scrollableElements.slice(0, topN);\n }\n return scrollableElements;\n }\n async function getScrollableElementXpaths(topN) {\n const scrollableElems = getScrollableElements(topN);\n const xpaths = [];\n for (const elem of scrollableElems) {\n const allXPaths = await generateXPathsForElement(elem);\n const firstXPath = allXPaths?.[0] || \"\";\n xpaths.push(firstXPath);\n }\n return xpaths;\n }\n (() => {\n const closedRoots = /* @__PURE__ */ new WeakMap();\n const nativeAttachShadow = Element.prototype.attachShadow;\n Element.prototype.attachShadow = function(init) {\n const root = nativeAttachShadow.call(this, init);\n if (init.mode === \"closed\") closedRoots.set(this, root);\n return root;\n };\n const backdoor = {\n getClosedRoot: (host) => closedRoots.get(host),\n queryClosed: (host, selector) => {\n const root = closedRoots.get(host);\n return root ? Array.from(root.querySelectorAll(selector)) : [];\n },\n xpathClosed: (host, xp) => {\n const root = closedRoots.get(host);\n if (!root) return [];\n const it = document.evaluate(\n xp,\n root,\n null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,\n null\n );\n const out = [];\n for (let i = 0; i < it.snapshotLength; ++i) {\n const n = it.snapshotItem(i);\n if (n) out.push(n);\n }\n return out;\n }\n };\n if (!(\"__stagehand__\" in window)) {\n Object.defineProperty(window, \"__stagehand__\", {\n value: backdoor,\n enumerable: false,\n writable: false,\n configurable: false\n });\n }\n })();\n window.getScrollableElementXpaths = getScrollableElementXpaths;\n window.getNodeFromXpath = getNodeFromXpath;\n window.waitForElementScrollEnd = waitForElementScrollEnd;\n})();\n";
@@ -1,2 +0,0 @@
1
- export declare function isElementNode(node: Node): node is Element;
2
- export declare function isTextNode(node: Node): node is Text;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export * from "./process";
2
- export * from "./utils";