@mercuryo-ai/agentbrowse 0.2.50

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 (301) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +335 -0
  3. package/dist/assistive-runtime.d.ts +110 -0
  4. package/dist/assistive-runtime.d.ts.map +1 -0
  5. package/dist/assistive-runtime.js +79 -0
  6. package/dist/assistive-runtime.test-support.d.ts +7 -0
  7. package/dist/assistive-runtime.test-support.d.ts.map +1 -0
  8. package/dist/assistive-runtime.test-support.js +106 -0
  9. package/dist/assistive-stagehand.d.ts +12 -0
  10. package/dist/assistive-stagehand.d.ts.map +1 -0
  11. package/dist/assistive-stagehand.js +10 -0
  12. package/dist/browser-session-state.d.ts +95 -0
  13. package/dist/browser-session-state.d.ts.map +1 -0
  14. package/dist/browser-session-state.js +279 -0
  15. package/dist/client-bindings.d.ts +10 -0
  16. package/dist/client-bindings.d.ts.map +1 -0
  17. package/dist/client-bindings.js +18 -0
  18. package/dist/client.d.ts +49 -0
  19. package/dist/client.d.ts.map +1 -0
  20. package/dist/client.js +63 -0
  21. package/dist/command-api-tracing.d.ts +20 -0
  22. package/dist/command-api-tracing.d.ts.map +1 -0
  23. package/dist/command-api-tracing.js +149 -0
  24. package/dist/command-name.d.ts +3 -0
  25. package/dist/command-name.d.ts.map +1 -0
  26. package/dist/command-name.js +11 -0
  27. package/dist/commands/act.d.ts +43 -0
  28. package/dist/commands/act.d.ts.map +1 -0
  29. package/dist/commands/act.js +1107 -0
  30. package/dist/commands/action-acceptance.d.ts +93 -0
  31. package/dist/commands/action-acceptance.d.ts.map +1 -0
  32. package/dist/commands/action-acceptance.js +1938 -0
  33. package/dist/commands/action-artifacts.d.ts +33 -0
  34. package/dist/commands/action-artifacts.d.ts.map +1 -0
  35. package/dist/commands/action-artifacts.js +104 -0
  36. package/dist/commands/action-execution-guards.d.ts +5 -0
  37. package/dist/commands/action-execution-guards.d.ts.map +1 -0
  38. package/dist/commands/action-execution-guards.js +3 -0
  39. package/dist/commands/action-executor-helpers.d.ts +21 -0
  40. package/dist/commands/action-executor-helpers.d.ts.map +1 -0
  41. package/dist/commands/action-executor-helpers.js +265 -0
  42. package/dist/commands/action-executor.d.ts +14 -0
  43. package/dist/commands/action-executor.d.ts.map +1 -0
  44. package/dist/commands/action-executor.js +46 -0
  45. package/dist/commands/action-fallbacks.d.ts +6 -0
  46. package/dist/commands/action-fallbacks.d.ts.map +1 -0
  47. package/dist/commands/action-fallbacks.js +43 -0
  48. package/dist/commands/action-result-resolution.d.ts +17 -0
  49. package/dist/commands/action-result-resolution.d.ts.map +1 -0
  50. package/dist/commands/action-result-resolution.js +132 -0
  51. package/dist/commands/action-value-projection.d.ts +32 -0
  52. package/dist/commands/action-value-projection.d.ts.map +1 -0
  53. package/dist/commands/action-value-projection.js +151 -0
  54. package/dist/commands/attach.d.ts +41 -0
  55. package/dist/commands/attach.d.ts.map +1 -0
  56. package/dist/commands/attach.js +103 -0
  57. package/dist/commands/browse-actions.d.ts +4 -0
  58. package/dist/commands/browse-actions.d.ts.map +1 -0
  59. package/dist/commands/browse-actions.js +4 -0
  60. package/dist/commands/browser-status.d.ts +57 -0
  61. package/dist/commands/browser-status.d.ts.map +1 -0
  62. package/dist/commands/browser-status.js +243 -0
  63. package/dist/commands/click-action-executor.d.ts +12 -0
  64. package/dist/commands/click-action-executor.d.ts.map +1 -0
  65. package/dist/commands/click-action-executor.js +111 -0
  66. package/dist/commands/click-activation-policy.d.ts +5 -0
  67. package/dist/commands/click-activation-policy.d.ts.map +1 -0
  68. package/dist/commands/click-activation-policy.js +13 -0
  69. package/dist/commands/close.d.ts +26 -0
  70. package/dist/commands/close.d.ts.map +1 -0
  71. package/dist/commands/close.js +124 -0
  72. package/dist/commands/datepicker-action-executor.d.ts +12 -0
  73. package/dist/commands/datepicker-action-executor.d.ts.map +1 -0
  74. package/dist/commands/datepicker-action-executor.js +218 -0
  75. package/dist/commands/descriptor-validation.d.ts +27 -0
  76. package/dist/commands/descriptor-validation.d.ts.map +1 -0
  77. package/dist/commands/descriptor-validation.js +192 -0
  78. package/dist/commands/extract-scope-resolution.d.ts +20 -0
  79. package/dist/commands/extract-scope-resolution.d.ts.map +1 -0
  80. package/dist/commands/extract-scope-resolution.js +109 -0
  81. package/dist/commands/extract-scoped-dialog-text.d.ts +3 -0
  82. package/dist/commands/extract-scoped-dialog-text.d.ts.map +1 -0
  83. package/dist/commands/extract-scoped-dialog-text.js +210 -0
  84. package/dist/commands/extract-snapshot-sanitizer.d.ts +5 -0
  85. package/dist/commands/extract-snapshot-sanitizer.d.ts.map +1 -0
  86. package/dist/commands/extract-snapshot-sanitizer.js +98 -0
  87. package/dist/commands/extract-stagehand-executor.d.ts +17 -0
  88. package/dist/commands/extract-stagehand-executor.d.ts.map +1 -0
  89. package/dist/commands/extract-stagehand-executor.js +112 -0
  90. package/dist/commands/extract.d.ts +57 -0
  91. package/dist/commands/extract.d.ts.map +1 -0
  92. package/dist/commands/extract.js +668 -0
  93. package/dist/commands/interaction-kernel.d.ts +46 -0
  94. package/dist/commands/interaction-kernel.d.ts.map +1 -0
  95. package/dist/commands/interaction-kernel.js +215 -0
  96. package/dist/commands/launch.d.ts +41 -0
  97. package/dist/commands/launch.d.ts.map +1 -0
  98. package/dist/commands/launch.js +182 -0
  99. package/dist/commands/navigate.d.ts +31 -0
  100. package/dist/commands/navigate.d.ts.map +1 -0
  101. package/dist/commands/navigate.js +202 -0
  102. package/dist/commands/observe-accessibility.d.ts +22 -0
  103. package/dist/commands/observe-accessibility.d.ts.map +1 -0
  104. package/dist/commands/observe-accessibility.js +566 -0
  105. package/dist/commands/observe-display-label.d.ts +4 -0
  106. package/dist/commands/observe-display-label.d.ts.map +1 -0
  107. package/dist/commands/observe-display-label.js +26 -0
  108. package/dist/commands/observe-dom-label-contract.d.ts +2 -0
  109. package/dist/commands/observe-dom-label-contract.d.ts.map +1 -0
  110. package/dist/commands/observe-dom-label-contract.js +564 -0
  111. package/dist/commands/observe-fallback-semantics.d.ts +6 -0
  112. package/dist/commands/observe-fallback-semantics.d.ts.map +1 -0
  113. package/dist/commands/observe-fallback-semantics.js +86 -0
  114. package/dist/commands/observe-inventory.d.ts +149 -0
  115. package/dist/commands/observe-inventory.d.ts.map +1 -0
  116. package/dist/commands/observe-inventory.js +3545 -0
  117. package/dist/commands/observe-label-policy.d.ts +8 -0
  118. package/dist/commands/observe-label-policy.d.ts.map +1 -0
  119. package/dist/commands/observe-label-policy.js +21 -0
  120. package/dist/commands/observe-page-state.d.ts +11 -0
  121. package/dist/commands/observe-page-state.d.ts.map +1 -0
  122. package/dist/commands/observe-page-state.js +89 -0
  123. package/dist/commands/observe-persistence.d.ts +15 -0
  124. package/dist/commands/observe-persistence.d.ts.map +1 -0
  125. package/dist/commands/observe-persistence.js +238 -0
  126. package/dist/commands/observe-projection.d.ts +119 -0
  127. package/dist/commands/observe-projection.d.ts.map +1 -0
  128. package/dist/commands/observe-projection.js +726 -0
  129. package/dist/commands/observe-protected.d.ts +6 -0
  130. package/dist/commands/observe-protected.d.ts.map +1 -0
  131. package/dist/commands/observe-protected.js +31 -0
  132. package/dist/commands/observe-semantics.d.ts +10 -0
  133. package/dist/commands/observe-semantics.d.ts.map +1 -0
  134. package/dist/commands/observe-semantics.js +535 -0
  135. package/dist/commands/observe-signals.d.ts +48 -0
  136. package/dist/commands/observe-signals.d.ts.map +1 -0
  137. package/dist/commands/observe-signals.js +461 -0
  138. package/dist/commands/observe-stagehand.d.ts +49 -0
  139. package/dist/commands/observe-stagehand.d.ts.map +1 -0
  140. package/dist/commands/observe-stagehand.js +94 -0
  141. package/dist/commands/observe-surfaces.d.ts +11 -0
  142. package/dist/commands/observe-surfaces.d.ts.map +1 -0
  143. package/dist/commands/observe-surfaces.js +290 -0
  144. package/dist/commands/observe.d.ts +113 -0
  145. package/dist/commands/observe.d.ts.map +1 -0
  146. package/dist/commands/observe.js +556 -0
  147. package/dist/commands/screenshot.d.ts +37 -0
  148. package/dist/commands/screenshot.d.ts.map +1 -0
  149. package/dist/commands/screenshot.js +269 -0
  150. package/dist/commands/select-action-executor.d.ts +10 -0
  151. package/dist/commands/select-action-executor.d.ts.map +1 -0
  152. package/dist/commands/select-action-executor.js +156 -0
  153. package/dist/commands/semantic-observe-lexical.d.ts +31 -0
  154. package/dist/commands/semantic-observe-lexical.d.ts.map +1 -0
  155. package/dist/commands/semantic-observe-lexical.js +186 -0
  156. package/dist/commands/semantic-observe.d.ts +37 -0
  157. package/dist/commands/semantic-observe.d.ts.map +1 -0
  158. package/dist/commands/semantic-observe.js +1339 -0
  159. package/dist/commands/structured-grid-action-executor.d.ts +3 -0
  160. package/dist/commands/structured-grid-action-executor.d.ts.map +1 -0
  161. package/dist/commands/structured-grid-action-executor.js +4 -0
  162. package/dist/commands/target-resolution.d.ts +4 -0
  163. package/dist/commands/target-resolution.d.ts.map +1 -0
  164. package/dist/commands/target-resolution.js +33 -0
  165. package/dist/commands/text-input-action-executor.d.ts +5 -0
  166. package/dist/commands/text-input-action-executor.d.ts.map +1 -0
  167. package/dist/commands/text-input-action-executor.js +116 -0
  168. package/dist/commands/user-actionable.d.ts +4 -0
  169. package/dist/commands/user-actionable.d.ts.map +1 -0
  170. package/dist/commands/user-actionable.js +216 -0
  171. package/dist/control-semantics.d.ts +30 -0
  172. package/dist/control-semantics.d.ts.map +1 -0
  173. package/dist/control-semantics.js +419 -0
  174. package/dist/diagnostics.d.ts +132 -0
  175. package/dist/diagnostics.d.ts.map +1 -0
  176. package/dist/diagnostics.js +120 -0
  177. package/dist/index.d.ts +5 -0
  178. package/dist/index.d.ts.map +1 -0
  179. package/dist/index.js +350 -0
  180. package/dist/library.d.ts +17 -0
  181. package/dist/library.d.ts.map +1 -0
  182. package/dist/library.js +14 -0
  183. package/dist/output.d.ts +32 -0
  184. package/dist/output.d.ts.map +1 -0
  185. package/dist/output.js +33 -0
  186. package/dist/owned-browser.d.ts +12 -0
  187. package/dist/owned-browser.d.ts.map +1 -0
  188. package/dist/owned-browser.js +69 -0
  189. package/dist/owned-process.d.ts +19 -0
  190. package/dist/owned-process.d.ts.map +1 -0
  191. package/dist/owned-process.js +145 -0
  192. package/dist/playwright-runtime.d.ts +43 -0
  193. package/dist/playwright-runtime.d.ts.map +1 -0
  194. package/dist/playwright-runtime.js +339 -0
  195. package/dist/protected-fill-browser.d.ts +22 -0
  196. package/dist/protected-fill-browser.d.ts.map +1 -0
  197. package/dist/protected-fill-browser.js +52 -0
  198. package/dist/protected-fill.d.ts +82 -0
  199. package/dist/protected-fill.d.ts.map +1 -0
  200. package/dist/protected-fill.js +20 -0
  201. package/dist/runtime-metrics.d.ts +27 -0
  202. package/dist/runtime-metrics.d.ts.map +1 -0
  203. package/dist/runtime-metrics.js +66 -0
  204. package/dist/runtime-page-state.d.ts +11 -0
  205. package/dist/runtime-page-state.d.ts.map +1 -0
  206. package/dist/runtime-page-state.js +62 -0
  207. package/dist/runtime-protected-state.d.ts +14 -0
  208. package/dist/runtime-protected-state.d.ts.map +1 -0
  209. package/dist/runtime-protected-state.js +148 -0
  210. package/dist/runtime-resolution.d.ts +9 -0
  211. package/dist/runtime-resolution.d.ts.map +1 -0
  212. package/dist/runtime-resolution.js +19 -0
  213. package/dist/runtime-state.d.ts +251 -0
  214. package/dist/runtime-state.d.ts.map +1 -0
  215. package/dist/runtime-state.js +599 -0
  216. package/dist/secrets/catalog-applicability.d.ts +5 -0
  217. package/dist/secrets/catalog-applicability.d.ts.map +1 -0
  218. package/dist/secrets/catalog-applicability.js +59 -0
  219. package/dist/secrets/field-policy.d.ts +3 -0
  220. package/dist/secrets/field-policy.d.ts.map +1 -0
  221. package/dist/secrets/field-policy.js +3 -0
  222. package/dist/secrets/fill-ordering.d.ts +10 -0
  223. package/dist/secrets/fill-ordering.d.ts.map +1 -0
  224. package/dist/secrets/fill-ordering.js +41 -0
  225. package/dist/secrets/form-matcher.d.ts +60 -0
  226. package/dist/secrets/form-matcher.d.ts.map +1 -0
  227. package/dist/secrets/form-matcher.js +948 -0
  228. package/dist/secrets/protected-artifact-guard.d.ts +39 -0
  229. package/dist/secrets/protected-artifact-guard.d.ts.map +1 -0
  230. package/dist/secrets/protected-artifact-guard.js +44 -0
  231. package/dist/secrets/protected-bindings.d.ts +14 -0
  232. package/dist/secrets/protected-bindings.d.ts.map +1 -0
  233. package/dist/secrets/protected-bindings.js +29 -0
  234. package/dist/secrets/protected-exact-value-redaction.d.ts +14 -0
  235. package/dist/secrets/protected-exact-value-redaction.d.ts.map +1 -0
  236. package/dist/secrets/protected-exact-value-redaction.js +360 -0
  237. package/dist/secrets/protected-field-semantics.d.ts +9 -0
  238. package/dist/secrets/protected-field-semantics.d.ts.map +1 -0
  239. package/dist/secrets/protected-field-semantics.js +154 -0
  240. package/dist/secrets/protected-field-values.d.ts +15 -0
  241. package/dist/secrets/protected-field-values.d.ts.map +1 -0
  242. package/dist/secrets/protected-field-values.js +131 -0
  243. package/dist/secrets/protected-fill.d.ts +47 -0
  244. package/dist/secrets/protected-fill.d.ts.map +1 -0
  245. package/dist/secrets/protected-fill.js +446 -0
  246. package/dist/secrets/protected-value-adapters.d.ts +4 -0
  247. package/dist/secrets/protected-value-adapters.d.ts.map +1 -0
  248. package/dist/secrets/protected-value-adapters.js +118 -0
  249. package/dist/secrets/types.d.ts +70 -0
  250. package/dist/secrets/types.d.ts.map +1 -0
  251. package/dist/secrets/types.js +30 -0
  252. package/dist/session.d.ts +19 -0
  253. package/dist/session.d.ts.map +1 -0
  254. package/dist/session.js +120 -0
  255. package/dist/solver/browser-launcher.d.ts +14 -0
  256. package/dist/solver/browser-launcher.d.ts.map +1 -0
  257. package/dist/solver/browser-launcher.js +799 -0
  258. package/dist/solver/config.d.ts +18 -0
  259. package/dist/solver/config.d.ts.map +1 -0
  260. package/dist/solver/config.js +67 -0
  261. package/dist/solver/fingerprint.d.ts +9 -0
  262. package/dist/solver/fingerprint.d.ts.map +1 -0
  263. package/dist/solver/fingerprint.js +96 -0
  264. package/dist/solver/profile-manager.d.ts +8 -0
  265. package/dist/solver/profile-manager.d.ts.map +1 -0
  266. package/dist/solver/profile-manager.js +74 -0
  267. package/dist/solver/turnstile-challenge.d.ts +3 -0
  268. package/dist/solver/turnstile-challenge.d.ts.map +1 -0
  269. package/dist/solver/turnstile-challenge.js +173 -0
  270. package/dist/solver/types.d.ts +67 -0
  271. package/dist/solver/types.d.ts.map +1 -0
  272. package/dist/solver/types.js +1 -0
  273. package/dist/stagehand-runtime.d.ts +4 -0
  274. package/dist/stagehand-runtime.d.ts.map +1 -0
  275. package/dist/stagehand-runtime.js +10 -0
  276. package/dist/stagehand.d.ts +15 -0
  277. package/dist/stagehand.d.ts.map +1 -0
  278. package/dist/stagehand.js +19 -0
  279. package/dist/testing.d.ts +5 -0
  280. package/dist/testing.d.ts.map +1 -0
  281. package/dist/testing.js +4 -0
  282. package/dist/update-check.d.ts +14 -0
  283. package/dist/update-check.d.ts.map +1 -0
  284. package/dist/update-check.js +182 -0
  285. package/dist/workflow-session-state.d.ts +30 -0
  286. package/dist/workflow-session-state.d.ts.map +1 -0
  287. package/dist/workflow-session-state.js +74 -0
  288. package/docs/README.md +25 -0
  289. package/docs/api-reference.md +242 -0
  290. package/docs/assistive-runtime.md +148 -0
  291. package/docs/configuration.md +287 -0
  292. package/docs/getting-started.md +237 -0
  293. package/docs/integration-checklist.md +36 -0
  294. package/docs/protected-fill.md +112 -0
  295. package/docs/testing.md +50 -0
  296. package/docs/troubleshooting.md +71 -0
  297. package/examples/README.md +18 -0
  298. package/examples/attach.ts +27 -0
  299. package/examples/basic.ts +36 -0
  300. package/examples/extract.ts +50 -0
  301. package/package.json +83 -0
@@ -0,0 +1,290 @@
1
+ import { locatorCandidateKey } from '../runtime-state.js';
2
+ const HIGH_SIGNAL_SCOPE_KINDS = new Set([
3
+ 'form',
4
+ 'dialog',
5
+ 'listbox',
6
+ 'menu',
7
+ 'grid',
8
+ 'tabpanel',
9
+ 'popover',
10
+ 'dropdown',
11
+ 'datepicker',
12
+ 'floating-panel',
13
+ 'sticky-panel',
14
+ ]);
15
+ const SNAPSHOT_SCOPE_KINDS = new Set([
16
+ 'dialog',
17
+ 'listbox',
18
+ 'menu',
19
+ 'grid',
20
+ 'tabpanel',
21
+ 'popover',
22
+ 'dropdown',
23
+ 'datepicker',
24
+ 'floating-panel',
25
+ 'sticky-panel',
26
+ ]);
27
+ export const OUTPUT_LEADING_TARGET_LIMIT = 20;
28
+ function inferExtractScopeLifetime(kind, locatorCandidates) {
29
+ const normalizedKind = (kind ?? '').trim().toLowerCase();
30
+ if (SNAPSHOT_SCOPE_KINDS.has(normalizedKind)) {
31
+ return 'snapshot';
32
+ }
33
+ if (normalizedKind === 'form') {
34
+ return locatorCandidates.length > 0 ? 'durable' : 'snapshot';
35
+ }
36
+ return 'snapshot';
37
+ }
38
+ export function selectScopesForOutput(scopes, targets, preferredScopeRefs) {
39
+ if (scopes.length === 0) {
40
+ return [];
41
+ }
42
+ const linkedScopeRefs = new Set(targets
43
+ .slice(0, OUTPUT_LEADING_TARGET_LIMIT)
44
+ .map((target) => target.surfaceRef)
45
+ .filter((value) => typeof value === 'string' && value.length > 0));
46
+ const explicitlyPreferredScopeRefs = new Set([...(preferredScopeRefs ?? [])].filter((value) => typeof value === 'string' && value.length > 0));
47
+ const scopeByRef = new Map(scopes.map((scope) => [scope.ref, scope]));
48
+ const includedScopeRefs = new Set([...linkedScopeRefs, ...explicitlyPreferredScopeRefs]);
49
+ for (const scopeRef of [...includedScopeRefs]) {
50
+ let parentSurfaceRef = scopeByRef.get(scopeRef)?.parentSurfaceRef;
51
+ while (parentSurfaceRef) {
52
+ if (includedScopeRefs.has(parentSurfaceRef)) {
53
+ break;
54
+ }
55
+ includedScopeRefs.add(parentSurfaceRef);
56
+ parentSurfaceRef = scopeByRef.get(parentSurfaceRef)?.parentSurfaceRef;
57
+ }
58
+ }
59
+ const scored = scopes
60
+ .map((scope) => {
61
+ const directlyLinked = linkedScopeRefs.has(scope.ref);
62
+ const explicitlyPreferred = explicitlyPreferredScopeRefs.has(scope.ref);
63
+ const disambiguatingAncestor = includedScopeRefs.has(scope.ref);
64
+ if (!disambiguatingAncestor) {
65
+ return null;
66
+ }
67
+ const scopeTargets = targets.filter((target) => target.surfaceRef === scope.ref);
68
+ const kind = (scope.kind ?? '').toLowerCase();
69
+ const overlayLike = HIGH_SIGNAL_SCOPE_KINDS.has(kind);
70
+ const linkedCount = scopeTargets.length;
71
+ const interactionRich = scopeTargets.some((target) => target.allowedActions.includes('fill') ||
72
+ target.allowedActions.includes('select') ||
73
+ target.acceptancePolicy === 'selection' ||
74
+ target.acceptancePolicy === 'date-selection');
75
+ let score = 0;
76
+ if (explicitlyPreferred)
77
+ score += 160;
78
+ if (directlyLinked)
79
+ score += 100;
80
+ if (!directlyLinked && !explicitlyPreferred)
81
+ score += 40;
82
+ if (overlayLike)
83
+ score += 60;
84
+ if (interactionRich)
85
+ score += 30;
86
+ score += Math.min(linkedCount, 6) * 5;
87
+ return { scope, score };
88
+ })
89
+ .filter((entry) => entry !== null)
90
+ .filter(({ score }) => score > 0)
91
+ .sort((left, right) => right.score - left.score || left.scope.ref.localeCompare(right.scope.ref));
92
+ if (scored.length > 0) {
93
+ return scored.slice(0, 12).map(({ scope }) => scope);
94
+ }
95
+ return [];
96
+ }
97
+ export function buildSurfaceRef(target) {
98
+ if (!target.surfaceKind && !target.surfaceSelector && !target.surfaceLabel) {
99
+ return undefined;
100
+ }
101
+ const frameKey = target.framePath?.join('>') ?? 'top';
102
+ return [
103
+ target.pageSignature ?? 'unknown-page',
104
+ frameKey,
105
+ target.surfaceKind ?? 'surface',
106
+ target.surfaceSelector ?? '',
107
+ target.surfaceLabel ?? '',
108
+ ].join('|');
109
+ }
110
+ function normalizeSurfaceText(value) {
111
+ const normalized = value?.replace(/\s+/g, ' ').trim();
112
+ return normalized ? normalized : undefined;
113
+ }
114
+ function semanticFormContextLabel(target) {
115
+ for (const node of [
116
+ target.context?.landmark,
117
+ target.context?.container,
118
+ target.context?.group,
119
+ target.context?.item,
120
+ ]) {
121
+ const kind = (node?.kind ?? '').trim().toLowerCase();
122
+ if (kind !== 'form') {
123
+ continue;
124
+ }
125
+ return normalizeSurfaceText(node?.label ?? node?.text);
126
+ }
127
+ return undefined;
128
+ }
129
+ export function buildSyntheticFormSurfaceId(target) {
130
+ const pageKey = normalizeSurfaceText(target.pageSignature);
131
+ if (!pageKey) {
132
+ return undefined;
133
+ }
134
+ const formKey = normalizeSurfaceText(target.formSelector) ?? semanticFormContextLabel(target)?.toLowerCase();
135
+ if (!formKey) {
136
+ return undefined;
137
+ }
138
+ const frameKey = target.framePath?.join('>') ??
139
+ (normalizeSurfaceText(target.frameUrl)
140
+ ? `url:${normalizeSurfaceText(target.frameUrl)}`
141
+ : 'top');
142
+ return `${pageKey}|${frameKey}|form|${formKey}`;
143
+ }
144
+ export function surfaceReplacementKey(surface) {
145
+ const pageKey = surface.pageSignature ?? surface.pageRef;
146
+ const frameKey = surface.framePath?.join('>') ?? 'top';
147
+ const kindKey = (surface.kind ?? 'surface').toLowerCase();
148
+ const labelKey = (surface.label ?? '').trim().toLowerCase();
149
+ return `${pageKey}|${frameKey}|${kindKey}|${labelKey}`;
150
+ }
151
+ export function summarizeContext(context) {
152
+ if (!context)
153
+ return undefined;
154
+ const parts = [];
155
+ const pushIfDistinct = (value) => {
156
+ const normalized = normalizeSurfaceText(value);
157
+ if (!normalized || parts.includes(normalized)) {
158
+ return;
159
+ }
160
+ parts.push(normalized);
161
+ };
162
+ pushIfDistinct(context.item?.label ?? context.item?.text ?? context.item?.kind);
163
+ pushIfDistinct(context.group?.label ?? context.group?.text ?? context.group?.kind);
164
+ if (parts.length === 0) {
165
+ pushIfDistinct(context.container?.label ?? context.container?.text ?? context.container?.kind);
166
+ }
167
+ if (parts.length === 0 || context.landmark?.label || context.landmark?.text) {
168
+ pushIfDistinct(context.landmark?.label ?? context.landmark?.text ?? context.landmark?.kind);
169
+ }
170
+ if (parts.length === 0 && context.hintText) {
171
+ pushIfDistinct(context.hintText);
172
+ }
173
+ if (parts.length === 0)
174
+ return undefined;
175
+ return parts.join(' / ');
176
+ }
177
+ export function pushUniqueLocatorCandidate(acc, candidate) {
178
+ if (!candidate)
179
+ return;
180
+ const key = locatorCandidateKey(candidate);
181
+ if (acc.some((existing) => locatorCandidateKey(existing) === key)) {
182
+ return;
183
+ }
184
+ acc.push(candidate);
185
+ }
186
+ function surfaceRoleFromKind(kind) {
187
+ const normalized = (kind ?? '').trim().toLowerCase();
188
+ switch (normalized) {
189
+ case 'card':
190
+ return 'article';
191
+ case 'article':
192
+ case 'dialog':
193
+ case 'listbox':
194
+ case 'menu':
195
+ case 'grid':
196
+ case 'tabpanel':
197
+ case 'group':
198
+ case 'region':
199
+ case 'listitem':
200
+ case 'row':
201
+ case 'form':
202
+ return normalized;
203
+ case 'fieldset':
204
+ return 'group';
205
+ case 'section':
206
+ return 'region';
207
+ default:
208
+ return undefined;
209
+ }
210
+ }
211
+ function collectSurfaceLocatorCandidates(target) {
212
+ const candidates = [];
213
+ const selectors = [target.surfaceSelector, ...(target.surfaceSelectors ?? [])].filter((value) => typeof value === 'string' && value.length > 0);
214
+ for (const selector of selectors) {
215
+ pushUniqueLocatorCandidate(candidates, {
216
+ strategy: selector.startsWith('xpath=') ? 'xpath' : 'css',
217
+ value: selector,
218
+ scope: 'root',
219
+ });
220
+ }
221
+ const surfaceRole = surfaceRoleFromKind(target.surfaceKind);
222
+ if (surfaceRole) {
223
+ pushUniqueLocatorCandidate(candidates, target.surfaceLabel
224
+ ? { strategy: 'role', value: surfaceRole, name: target.surfaceLabel }
225
+ : undefined);
226
+ pushUniqueLocatorCandidate(candidates, { strategy: 'role', value: surfaceRole });
227
+ }
228
+ return candidates;
229
+ }
230
+ export function collectSurfaceDescriptors(pageRef, targets) {
231
+ const descriptors = new Map();
232
+ for (const target of targets) {
233
+ const surfaceId = target.surfaceRef;
234
+ if (!surfaceId) {
235
+ continue;
236
+ }
237
+ const existing = descriptors.get(surfaceId);
238
+ const locatorCandidates = existing ? [...existing.locatorCandidates] : [];
239
+ for (const candidate of collectSurfaceLocatorCandidates(target)) {
240
+ pushUniqueLocatorCandidate(locatorCandidates, candidate);
241
+ }
242
+ descriptors.set(surfaceId, {
243
+ surfaceId,
244
+ pageRef,
245
+ framePath: existing?.framePath ?? target.framePath,
246
+ frameUrl: existing?.frameUrl ?? target.frameUrl,
247
+ kind: existing?.kind ?? target.surfaceKind ?? 'surface',
248
+ label: existing?.label && existing.label !== 'Active surface'
249
+ ? existing.label
250
+ : (target.surfaceLabel ?? target.surfaceKind ?? existing?.label ?? 'Active surface'),
251
+ lifecycle: 'live',
252
+ availability: { state: 'available' },
253
+ locatorCandidates,
254
+ createdAt: existing?.createdAt ?? Date.now(),
255
+ pageSignature: existing?.pageSignature ?? target.pageSignature,
256
+ extractScopeLifetime: inferExtractScopeLifetime(existing?.kind ?? target.surfaceKind ?? 'surface', locatorCandidates),
257
+ });
258
+ }
259
+ for (const target of targets) {
260
+ const surfaceId = buildSyntheticFormSurfaceId(target);
261
+ if (!surfaceId) {
262
+ continue;
263
+ }
264
+ const existing = descriptors.get(surfaceId);
265
+ const locatorCandidates = existing ? [...existing.locatorCandidates] : [];
266
+ const formSelector = target.formSelector?.trim();
267
+ if (formSelector) {
268
+ pushUniqueLocatorCandidate(locatorCandidates, {
269
+ strategy: formSelector.startsWith('xpath=') ? 'xpath' : 'css',
270
+ value: formSelector,
271
+ scope: 'root',
272
+ });
273
+ }
274
+ descriptors.set(surfaceId, {
275
+ surfaceId,
276
+ pageRef,
277
+ framePath: existing?.framePath ?? target.framePath,
278
+ frameUrl: existing?.frameUrl ?? target.frameUrl,
279
+ kind: 'form',
280
+ label: existing?.label ?? semanticFormContextLabel(target) ?? 'Form',
281
+ lifecycle: 'live',
282
+ availability: { state: 'available' },
283
+ locatorCandidates,
284
+ createdAt: existing?.createdAt ?? Date.now(),
285
+ pageSignature: existing?.pageSignature ?? target.pageSignature,
286
+ extractScopeLifetime: inferExtractScopeLifetime('form', locatorCandidates),
287
+ });
288
+ }
289
+ return [...descriptors.values()];
290
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * browse observe ["<instruction>"] — Discover available actions on the page.
3
+ */
4
+ import type { BrowserCommandSession } from "../browser-session-state.js";
5
+ import { type BrowseResult } from "../output.js";
6
+ import { type CompactObservedFillableForm, type CompactObservedScope, type CompactObservedSignal, type CompactObservedTarget } from "./observe-projection.js";
7
+ import { toStagehandDescriptor } from "./observe-stagehand.js";
8
+ /** Stable top-level error codes returned by `observe(...)`. */
9
+ export declare const OBSERVE_ERROR_CODES: readonly ["browser_connection_failed", "observe_failed", "protected_observe_blocked"];
10
+ /** Stable outcome categories emitted by `observe(...)`. */
11
+ export declare const OBSERVE_OUTCOME_TYPES: readonly ["blocked", "observation_completed", "protected_exposure_active"];
12
+ export type ObserveErrorCode = (typeof OBSERVE_ERROR_CODES)[number];
13
+ export type ObserveOutcomeType = (typeof OBSERVE_OUTCOME_TYPES)[number];
14
+ export type ObserveExecutionMode = "deterministic_dom" | "goal_heuristic_shortlist" | "goal_assistive_rerank" | "goal_assistive_stagehand";
15
+ /** Flat target entry returned from `observe(...)`. */
16
+ export type ObserveTarget = CompactObservedTarget;
17
+ /** Grouped scope entry returned from `observe(...)`. */
18
+ export type ObserveScope = CompactObservedScope;
19
+ /** Protected-fill form binding returned from `observe(...)`. */
20
+ export type ObserveFillableForm = CompactObservedFillableForm;
21
+ /** Page-level signal entry returned from `observe(...)`. */
22
+ export type ObserveSignal = CompactObservedSignal;
23
+ type ObserveSuccessPayload = BrowseResult & {
24
+ success: true;
25
+ observationMode: ObserveExecutionMode;
26
+ scopes?: ObserveScope[];
27
+ targets?: ObserveTarget[];
28
+ signals?: ObserveSignal[];
29
+ fillableForms?: ObserveFillableForm[];
30
+ };
31
+ type ObserveFailurePayload = {
32
+ error: ObserveErrorCode;
33
+ outcomeType: Extract<ObserveOutcomeType, "blocked" | "protected_exposure_active">;
34
+ message: string;
35
+ reason: string;
36
+ pageRef?: string;
37
+ blockedPath?: "goal-rerank" | "stagehand-fallback";
38
+ fallbackReason?: "deterministic-observe-empty" | "deterministic-observe-failed" | "dom-rerank-empty";
39
+ deterministicObserveError?: string;
40
+ fillRef?: string;
41
+ requestId?: string;
42
+ activatedAt?: string;
43
+ exposureReason?: string;
44
+ };
45
+ export type ObserveSuccessResult = ObserveSuccessPayload & {
46
+ success: true;
47
+ observationMode: ObserveExecutionMode;
48
+ scopes: ObserveScope[];
49
+ targets: ObserveTarget[];
50
+ signals: ObserveSignal[];
51
+ fillableForms: ObserveFillableForm[];
52
+ targetCount: number;
53
+ scopeCount: number;
54
+ projectedTargetCount: number;
55
+ };
56
+ /** Failed observe result with a stable top-level error code. */
57
+ export type ObserveFailureResult = {
58
+ success: false;
59
+ } & ObserveFailurePayload;
60
+ export type ObserveResult = ObserveSuccessResult | ObserveFailureResult;
61
+ export declare const __testDomTargetCollection: {
62
+ collectDomTargetsFromDocument: (context: {
63
+ evaluate<T>(pageFunction: string): Promise<T>;
64
+ }, options?: import("./observe-inventory.js").DomTargetCollectionOptions & {
65
+ framePath?: string[];
66
+ frameUrl?: string;
67
+ }) => Promise<import("./observe-inventory.js").DomObservedTarget[]>;
68
+ inferStructuredCellVariantFromEvidence: typeof import("./observe-inventory.js").inferStructuredCellVariantFromEvidence;
69
+ inferDirectionalControlFallbackFromEvidence: typeof import("./observe-inventory.js").inferDirectionalControlFallbackFromEvidence;
70
+ locatorDomSignatureScript: string;
71
+ };
72
+ export declare const __testStagehandDescriptor: {
73
+ toStagehandDescriptor: typeof toStagehandDescriptor;
74
+ normalizeStagehandSelector: typeof import("./observe-inventory.js").normalizeStagehandSelector;
75
+ readStagehandDomFacts: (locator: import("playwright-core").Locator) => Promise<{
76
+ kind?: string;
77
+ role?: string;
78
+ placeholder?: string;
79
+ inputName?: string;
80
+ inputType?: string;
81
+ autocomplete?: string;
82
+ ariaAutocomplete?: string;
83
+ value?: string;
84
+ text?: string;
85
+ currentValue?: string;
86
+ states?: Record<string, string | boolean | number>;
87
+ } | null>;
88
+ readStagehandDomFactsInBrowser: (element: Element) => {
89
+ kind?: string;
90
+ role?: string;
91
+ placeholder?: string;
92
+ inputName?: string;
93
+ inputType?: string;
94
+ autocomplete?: string;
95
+ ariaAutocomplete?: string;
96
+ value?: string;
97
+ text?: string;
98
+ currentValue?: string;
99
+ states?: Record<string, string | boolean | number>;
100
+ } | null;
101
+ stagehandDomFactsScript: string;
102
+ };
103
+ /**
104
+ * Observes the current page and returns the current target inventory.
105
+ *
106
+ * The success payload always includes a flat `targets` array for direct
107
+ * consumption and grouped `scopes` for richer container-aware workflows.
108
+ */
109
+ export declare function observeBrowser(session: BrowserCommandSession, instruction?: string): Promise<ObserveResult>;
110
+ /** CLI wrapper for `observeBrowser(...)` that persists the observed runtime state. */
111
+ export declare function observe(session: BrowserCommandSession, instruction?: string): Promise<void>;
112
+ export {};
113
+ //# sourceMappingURL=observe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/commands/observe.ts"],"names":[],"mappings":"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"}