agent-web-interface 4.2.0 → 4.4.0

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 (265) hide show
  1. package/dist/src/browser/connection-utils.d.ts +48 -0
  2. package/dist/src/browser/connection-utils.d.ts.map +1 -0
  3. package/dist/src/browser/connection-utils.js +129 -0
  4. package/dist/src/browser/connection-utils.js.map +1 -0
  5. package/dist/src/browser/index.d.ts +3 -1
  6. package/dist/src/browser/index.d.ts.map +1 -1
  7. package/dist/src/browser/index.js +2 -1
  8. package/dist/src/browser/index.js.map +1 -1
  9. package/dist/src/browser/session-manager.d.ts +1 -89
  10. package/dist/src/browser/session-manager.d.ts.map +1 -1
  11. package/dist/src/browser/session-manager.js +1 -116
  12. package/dist/src/browser/session-manager.js.map +1 -1
  13. package/dist/src/browser/session-manager.types.d.ts +90 -0
  14. package/dist/src/browser/session-manager.types.d.ts.map +1 -0
  15. package/dist/src/browser/session-manager.types.js +7 -0
  16. package/dist/src/browser/session-manager.types.js.map +1 -0
  17. package/dist/src/form/constraint-extraction.d.ts +31 -0
  18. package/dist/src/form/constraint-extraction.d.ts.map +1 -0
  19. package/dist/src/form/constraint-extraction.js +110 -0
  20. package/dist/src/form/constraint-extraction.js.map +1 -0
  21. package/dist/src/form/field-extractor.d.ts.map +1 -1
  22. package/dist/src/form/field-extractor.js +3 -444
  23. package/dist/src/form/field-extractor.js.map +1 -1
  24. package/dist/src/form/field-state-extractor.d.ts +22 -0
  25. package/dist/src/form/field-state-extractor.d.ts.map +1 -0
  26. package/dist/src/form/field-state-extractor.js +55 -0
  27. package/dist/src/form/field-state-extractor.js.map +1 -0
  28. package/dist/src/form/form-actions.d.ts +45 -0
  29. package/dist/src/form/form-actions.d.ts.map +1 -0
  30. package/dist/src/form/form-actions.js +108 -0
  31. package/dist/src/form/form-actions.js.map +1 -0
  32. package/dist/src/form/form-detector.d.ts +0 -36
  33. package/dist/src/form/form-detector.d.ts.map +1 -1
  34. package/dist/src/form/form-detector.js +11 -376
  35. package/dist/src/form/form-detector.js.map +1 -1
  36. package/dist/src/form/input-clustering.d.ts +15 -0
  37. package/dist/src/form/input-clustering.d.ts.map +1 -0
  38. package/dist/src/form/input-clustering.js +61 -0
  39. package/dist/src/form/input-clustering.js.map +1 -0
  40. package/dist/src/form/intent-inference.d.ts +28 -0
  41. package/dist/src/form/intent-inference.d.ts.map +1 -0
  42. package/dist/src/form/intent-inference.js +137 -0
  43. package/dist/src/form/intent-inference.js.map +1 -0
  44. package/dist/src/form/purpose-inference.d.ts +50 -0
  45. package/dist/src/form/purpose-inference.d.ts.map +1 -0
  46. package/dist/src/form/purpose-inference.js +313 -0
  47. package/dist/src/form/purpose-inference.js.map +1 -0
  48. package/dist/src/form/submit-detection.d.ts +36 -0
  49. package/dist/src/form/submit-detection.d.ts.map +1 -0
  50. package/dist/src/form/submit-detection.js +101 -0
  51. package/dist/src/form/submit-detection.js.map +1 -0
  52. package/dist/src/form/types.d.ts +2 -2
  53. package/dist/src/index.js +65 -48
  54. package/dist/src/index.js.map +1 -1
  55. package/dist/src/observation/observation-accumulator.d.ts +1 -1
  56. package/dist/src/observation/observation-accumulator.js +1 -1
  57. package/dist/src/observation/observer-script.d.ts +1 -1
  58. package/dist/src/observation/observer-script.d.ts.map +1 -1
  59. package/dist/src/observation/observer-script.js +129 -7
  60. package/dist/src/observation/observer-script.js.map +1 -1
  61. package/dist/src/query/disambiguation.d.ts +18 -0
  62. package/dist/src/query/disambiguation.d.ts.map +1 -0
  63. package/dist/src/query/disambiguation.js +123 -0
  64. package/dist/src/query/disambiguation.js.map +1 -0
  65. package/dist/src/query/fuzzy-match.d.ts +17 -0
  66. package/dist/src/query/fuzzy-match.d.ts.map +1 -0
  67. package/dist/src/query/fuzzy-match.js +34 -0
  68. package/dist/src/query/fuzzy-match.js.map +1 -0
  69. package/dist/src/query/index.d.ts +3 -0
  70. package/dist/src/query/index.d.ts.map +1 -1
  71. package/dist/src/query/index.js +6 -0
  72. package/dist/src/query/index.js.map +1 -1
  73. package/dist/src/query/query-engine.d.ts +0 -35
  74. package/dist/src/query/query-engine.d.ts.map +1 -1
  75. package/dist/src/query/query-engine.js +9 -309
  76. package/dist/src/query/query-engine.js.map +1 -1
  77. package/dist/src/query/scoring.d.ts +52 -0
  78. package/dist/src/query/scoring.d.ts.map +1 -0
  79. package/dist/src/query/scoring.js +162 -0
  80. package/dist/src/query/scoring.js.map +1 -0
  81. package/dist/src/server/mcp-server.d.ts.map +1 -1
  82. package/dist/src/server/mcp-server.js +29 -1
  83. package/dist/src/server/mcp-server.js.map +1 -1
  84. package/dist/src/snapshot/element-resolver.d.ts +50 -18
  85. package/dist/src/snapshot/element-resolver.d.ts.map +1 -1
  86. package/dist/src/snapshot/element-resolver.js +180 -101
  87. package/dist/src/snapshot/element-resolver.js.map +1 -1
  88. package/dist/src/snapshot/extractors/ax-extractor.d.ts +1 -1
  89. package/dist/src/snapshot/extractors/ax-extractor.d.ts.map +1 -1
  90. package/dist/src/snapshot/extractors/ax-extractor.js +4 -1
  91. package/dist/src/snapshot/extractors/ax-extractor.js.map +1 -1
  92. package/dist/src/snapshot/extractors/index.d.ts +1 -1
  93. package/dist/src/snapshot/extractors/index.d.ts.map +1 -1
  94. package/dist/src/snapshot/extractors/index.js +1 -1
  95. package/dist/src/snapshot/extractors/index.js.map +1 -1
  96. package/dist/src/snapshot/extractors/region-resolver.d.ts.map +1 -1
  97. package/dist/src/snapshot/extractors/region-resolver.js +8 -0
  98. package/dist/src/snapshot/extractors/region-resolver.js.map +1 -1
  99. package/dist/src/snapshot/extractors/types.d.ts +8 -0
  100. package/dist/src/snapshot/extractors/types.d.ts.map +1 -1
  101. package/dist/src/snapshot/extractors/types.js +16 -0
  102. package/dist/src/snapshot/extractors/types.js.map +1 -1
  103. package/dist/src/snapshot/frame-context.d.ts +68 -0
  104. package/dist/src/snapshot/frame-context.d.ts.map +1 -0
  105. package/dist/src/snapshot/frame-context.js +131 -0
  106. package/dist/src/snapshot/frame-context.js.map +1 -0
  107. package/dist/src/snapshot/heading-index.d.ts +28 -0
  108. package/dist/src/snapshot/heading-index.d.ts.map +1 -0
  109. package/dist/src/snapshot/heading-index.js +108 -0
  110. package/dist/src/snapshot/heading-index.js.map +1 -0
  111. package/dist/src/snapshot/index.d.ts +5 -3
  112. package/dist/src/snapshot/index.d.ts.map +1 -1
  113. package/dist/src/snapshot/index.js +3 -2
  114. package/dist/src/snapshot/index.js.map +1 -1
  115. package/dist/src/snapshot/kind-mapping.d.ts +30 -0
  116. package/dist/src/snapshot/kind-mapping.d.ts.map +1 -0
  117. package/dist/src/snapshot/kind-mapping.js +114 -0
  118. package/dist/src/snapshot/kind-mapping.js.map +1 -0
  119. package/dist/src/snapshot/node-filter.d.ts +31 -0
  120. package/dist/src/snapshot/node-filter.d.ts.map +1 -0
  121. package/dist/src/snapshot/node-filter.js +137 -0
  122. package/dist/src/snapshot/node-filter.js.map +1 -0
  123. package/dist/src/snapshot/node-synthesizer.d.ts +62 -0
  124. package/dist/src/snapshot/node-synthesizer.d.ts.map +1 -0
  125. package/dist/src/snapshot/node-synthesizer.js +185 -0
  126. package/dist/src/snapshot/node-synthesizer.js.map +1 -0
  127. package/dist/src/snapshot/snapshot-compiler.d.ts +2 -36
  128. package/dist/src/snapshot/snapshot-compiler.d.ts.map +1 -1
  129. package/dist/src/snapshot/snapshot-compiler.js +28 -520
  130. package/dist/src/snapshot/snapshot-compiler.js.map +1 -1
  131. package/dist/src/snapshot/snapshot.types.d.ts +7 -2
  132. package/dist/src/snapshot/snapshot.types.d.ts.map +1 -1
  133. package/dist/src/snapshot/snapshot.types.js +9 -0
  134. package/dist/src/snapshot/snapshot.types.js.map +1 -1
  135. package/dist/src/state/actionables-filter.d.ts +5 -0
  136. package/dist/src/state/actionables-filter.d.ts.map +1 -1
  137. package/dist/src/state/actionables-filter.js +22 -3
  138. package/dist/src/state/actionables-filter.js.map +1 -1
  139. package/dist/src/state/diff-engine.js +3 -3
  140. package/dist/src/state/diff-engine.js.map +1 -1
  141. package/dist/src/state/element-registry.d.ts.map +1 -1
  142. package/dist/src/state/element-registry.js +6 -4
  143. package/dist/src/state/element-registry.js.map +1 -1
  144. package/dist/src/state/hash-utils.d.ts +24 -0
  145. package/dist/src/state/hash-utils.d.ts.map +1 -0
  146. package/dist/src/state/hash-utils.js +41 -0
  147. package/dist/src/state/hash-utils.js.map +1 -0
  148. package/dist/src/state/layer-detector.d.ts.map +1 -1
  149. package/dist/src/state/layer-detector.js +15 -286
  150. package/dist/src/state/layer-detector.js.map +1 -1
  151. package/dist/src/state/layer-detectors/drawer-detector.d.ts +32 -0
  152. package/dist/src/state/layer-detectors/drawer-detector.d.ts.map +1 -0
  153. package/dist/src/state/layer-detectors/drawer-detector.js +96 -0
  154. package/dist/src/state/layer-detectors/drawer-detector.js.map +1 -0
  155. package/dist/src/state/layer-detectors/index.d.ts +10 -0
  156. package/dist/src/state/layer-detectors/index.d.ts.map +1 -0
  157. package/dist/src/state/layer-detectors/index.js +10 -0
  158. package/dist/src/state/layer-detectors/index.js.map +1 -0
  159. package/dist/src/state/layer-detectors/modal-detector.d.ts +30 -0
  160. package/dist/src/state/layer-detectors/modal-detector.d.ts.map +1 -0
  161. package/dist/src/state/layer-detectors/modal-detector.js +127 -0
  162. package/dist/src/state/layer-detectors/modal-detector.js.map +1 -0
  163. package/dist/src/state/layer-detectors/popover-detector.d.ts +20 -0
  164. package/dist/src/state/layer-detectors/popover-detector.d.ts.map +1 -0
  165. package/dist/src/state/layer-detectors/popover-detector.js +76 -0
  166. package/dist/src/state/layer-detectors/popover-detector.js.map +1 -0
  167. package/dist/src/state/layer-detectors/toast-detector.d.ts +24 -0
  168. package/dist/src/state/layer-detectors/toast-detector.d.ts.map +1 -0
  169. package/dist/src/state/layer-detectors/toast-detector.js +48 -0
  170. package/dist/src/state/layer-detectors/toast-detector.js.map +1 -0
  171. package/dist/src/state/region-mapping.d.ts +13 -0
  172. package/dist/src/state/region-mapping.d.ts.map +1 -0
  173. package/dist/src/state/region-mapping.js +25 -0
  174. package/dist/src/state/region-mapping.js.map +1 -0
  175. package/dist/src/state/state-manager.d.ts.map +1 -1
  176. package/dist/src/state/state-manager.js +8 -192
  177. package/dist/src/state/state-manager.js.map +1 -1
  178. package/dist/src/state/state-renderer.d.ts.map +1 -1
  179. package/dist/src/state/state-renderer.js +16 -2
  180. package/dist/src/state/state-renderer.js.map +1 -1
  181. package/dist/src/state/types.d.ts +8 -4
  182. package/dist/src/state/types.d.ts.map +1 -1
  183. package/dist/src/state/url-sanitization.d.ts +22 -0
  184. package/dist/src/state/url-sanitization.d.ts.map +1 -0
  185. package/dist/src/state/url-sanitization.js +60 -0
  186. package/dist/src/state/url-sanitization.js.map +1 -0
  187. package/dist/src/state/value-masking.d.ts +36 -0
  188. package/dist/src/state/value-masking.d.ts.map +1 -0
  189. package/dist/src/state/value-masking.js +86 -0
  190. package/dist/src/state/value-masking.js.map +1 -0
  191. package/dist/src/tools/action-context.d.ts +60 -0
  192. package/dist/src/tools/action-context.d.ts.map +1 -0
  193. package/dist/src/tools/action-context.js +78 -0
  194. package/dist/src/tools/action-context.js.map +1 -0
  195. package/dist/src/tools/action-stabilization.d.ts +48 -0
  196. package/dist/src/tools/action-stabilization.d.ts.map +1 -0
  197. package/dist/src/tools/action-stabilization.js +87 -0
  198. package/dist/src/tools/action-stabilization.js.map +1 -0
  199. package/dist/src/tools/browser-tools.d.ts +8 -146
  200. package/dist/src/tools/browser-tools.d.ts.map +1 -1
  201. package/dist/src/tools/browser-tools.js +13 -689
  202. package/dist/src/tools/browser-tools.js.map +1 -1
  203. package/dist/src/tools/canvas-tools.d.ts +32 -0
  204. package/dist/src/tools/canvas-tools.d.ts.map +1 -0
  205. package/dist/src/tools/canvas-tools.js +370 -0
  206. package/dist/src/tools/canvas-tools.js.map +1 -0
  207. package/dist/src/tools/effect-tracker.d.ts +25 -0
  208. package/dist/src/tools/effect-tracker.d.ts.map +1 -0
  209. package/dist/src/tools/effect-tracker.js +69 -0
  210. package/dist/src/tools/effect-tracker.js.map +1 -0
  211. package/dist/src/tools/execute-action.d.ts +1 -31
  212. package/dist/src/tools/execute-action.d.ts.map +1 -1
  213. package/dist/src/tools/execute-action.js +7 -276
  214. package/dist/src/tools/execute-action.js.map +1 -1
  215. package/dist/src/tools/form-tools.d.ts +4 -6
  216. package/dist/src/tools/form-tools.d.ts.map +1 -1
  217. package/dist/src/tools/form-tools.js +10 -42
  218. package/dist/src/tools/form-tools.js.map +1 -1
  219. package/dist/src/tools/index.d.ts +6 -4
  220. package/dist/src/tools/index.d.ts.map +1 -1
  221. package/dist/src/tools/index.js +21 -10
  222. package/dist/src/tools/index.js.map +1 -1
  223. package/dist/src/tools/interaction-tools.d.ts +46 -0
  224. package/dist/src/tools/interaction-tools.d.ts.map +1 -0
  225. package/dist/src/tools/interaction-tools.js +138 -0
  226. package/dist/src/tools/interaction-tools.js.map +1 -0
  227. package/dist/src/tools/navigation-detection.d.ts +31 -0
  228. package/dist/src/tools/navigation-detection.d.ts.map +1 -0
  229. package/dist/src/tools/navigation-detection.js +46 -0
  230. package/dist/src/tools/navigation-detection.js.map +1 -0
  231. package/dist/src/tools/navigation-tools.d.ts +57 -0
  232. package/dist/src/tools/navigation-tools.d.ts.map +1 -0
  233. package/dist/src/tools/navigation-tools.js +178 -0
  234. package/dist/src/tools/navigation-tools.js.map +1 -0
  235. package/dist/src/tools/observation-tools.d.ts +53 -0
  236. package/dist/src/tools/observation-tools.d.ts.map +1 -0
  237. package/dist/src/tools/observation-tools.js +247 -0
  238. package/dist/src/tools/observation-tools.js.map +1 -0
  239. package/dist/src/tools/response-builder.js +2 -2
  240. package/dist/src/tools/response-builder.js.map +1 -1
  241. package/dist/src/tools/stale-element-retry.d.ts +37 -0
  242. package/dist/src/tools/stale-element-retry.d.ts.map +1 -0
  243. package/dist/src/tools/stale-element-retry.js +68 -0
  244. package/dist/src/tools/stale-element-retry.js.map +1 -0
  245. package/dist/src/tools/state-manager-registry.d.ts +26 -0
  246. package/dist/src/tools/state-manager-registry.d.ts.map +1 -0
  247. package/dist/src/tools/state-manager-registry.js +39 -0
  248. package/dist/src/tools/state-manager-registry.js.map +1 -0
  249. package/dist/src/tools/tool-context.d.ts +53 -0
  250. package/dist/src/tools/tool-context.d.ts.map +1 -0
  251. package/dist/src/tools/tool-context.js +119 -0
  252. package/dist/src/tools/tool-context.js.map +1 -0
  253. package/dist/src/tools/tool-result.types.d.ts +16 -1
  254. package/dist/src/tools/tool-result.types.d.ts.map +1 -1
  255. package/dist/src/tools/tool-result.types.js +11 -0
  256. package/dist/src/tools/tool-result.types.js.map +1 -1
  257. package/dist/src/tools/tool-schemas.d.ts +358 -146
  258. package/dist/src/tools/tool-schemas.d.ts.map +1 -1
  259. package/dist/src/tools/tool-schemas.js +142 -19
  260. package/dist/src/tools/tool-schemas.js.map +1 -1
  261. package/dist/src/tools/viewport-tools.d.ts +36 -0
  262. package/dist/src/tools/viewport-tools.d.ts.map +1 -0
  263. package/dist/src/tools/viewport-tools.js +105 -0
  264. package/dist/src/tools/viewport-tools.js.map +1 -0
  265. package/package.json +1 -1
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Purpose Inference
3
+ *
4
+ * Infers the semantic purpose of form fields based on input type,
5
+ * autocomplete attributes, label text, and naming patterns.
6
+ *
7
+ * Priority order:
8
+ * 1. input type attribute
9
+ * 2. autocomplete attribute
10
+ * 3. aria-label / label text
11
+ * 4. placeholder
12
+ * 5. name attribute patterns
13
+ *
14
+ * @module form/purpose-inference
15
+ */
16
+ /**
17
+ * Mapping from input type to semantic type
18
+ */
19
+ export const INPUT_TYPE_TO_SEMANTIC = {
20
+ email: 'email',
21
+ tel: 'phone',
22
+ password: 'password',
23
+ url: 'url',
24
+ search: 'search',
25
+ date: 'date',
26
+ 'datetime-local': 'date',
27
+ time: 'date',
28
+ month: 'date',
29
+ week: 'date',
30
+ number: 'quantity',
31
+ file: 'file',
32
+ color: 'color',
33
+ };
34
+ /**
35
+ * Mapping from autocomplete attribute to semantic type
36
+ */
37
+ export const AUTOCOMPLETE_TO_SEMANTIC = {
38
+ email: 'email',
39
+ tel: 'phone',
40
+ 'tel-national': 'phone',
41
+ 'tel-local': 'phone',
42
+ password: 'password',
43
+ 'new-password': 'password',
44
+ 'current-password': 'password',
45
+ username: 'username',
46
+ name: 'full_name',
47
+ 'given-name': 'first_name',
48
+ 'family-name': 'last_name',
49
+ 'additional-name': 'name',
50
+ nickname: 'username',
51
+ 'street-address': 'street',
52
+ 'address-line1': 'street',
53
+ 'address-line2': 'address',
54
+ 'address-level1': 'state',
55
+ 'address-level2': 'city',
56
+ 'postal-code': 'zip',
57
+ country: 'country',
58
+ 'country-name': 'country',
59
+ 'cc-number': 'card_number',
60
+ 'cc-exp': 'card_expiry',
61
+ 'cc-exp-month': 'card_expiry',
62
+ 'cc-exp-year': 'card_expiry',
63
+ 'cc-csc': 'card_cvv',
64
+ bday: 'date_of_birth',
65
+ 'bday-day': 'date_of_birth',
66
+ 'bday-month': 'date_of_birth',
67
+ 'bday-year': 'date_of_birth',
68
+ url: 'url',
69
+ photo: 'file',
70
+ };
71
+ /**
72
+ * Keywords for semantic type inference from labels
73
+ */
74
+ export const LABEL_KEYWORDS = {
75
+ email: ['email', 'e-mail', 'mail address'],
76
+ phone: ['phone', 'telephone', 'mobile', 'cell', 'contact number'],
77
+ password: ['password', 'passcode', 'pin'],
78
+ password_confirm: ['confirm password', 'repeat password', 'retype password', 're-enter password'],
79
+ name: ['name', 'full name'],
80
+ first_name: ['first name', 'given name', 'forename'],
81
+ last_name: ['last name', 'surname', 'family name'],
82
+ full_name: ['full name', 'your name', 'customer name'],
83
+ username: ['username', 'user name', 'user id', 'login', 'account name'],
84
+ address: ['address', 'location'],
85
+ street: ['street', 'address line', 'street address'],
86
+ city: ['city', 'town', 'locality'],
87
+ state: ['state', 'province', 'region'],
88
+ zip: ['zip', 'postal code', 'postcode', 'zip code'],
89
+ country: ['country', 'nation'],
90
+ card_number: ['card number', 'credit card', 'debit card', 'card #'],
91
+ card_expiry: ['expiry', 'expiration', 'exp date', 'valid thru'],
92
+ card_cvv: ['cvv', 'cvc', 'security code', 'card verification'],
93
+ date: ['date', 'when'],
94
+ date_of_birth: ['birth', 'dob', 'birthday', 'date of birth'],
95
+ quantity: ['quantity', 'qty', 'amount', 'count', 'number of'],
96
+ price: ['price', 'cost', 'amount', 'total'],
97
+ search: ['search', 'find', 'lookup', 'query'],
98
+ comment: ['comment', 'note', 'remarks', 'feedback'],
99
+ message: ['message', 'text', 'content', 'body'],
100
+ url: ['url', 'website', 'link', 'web address'],
101
+ file: ['file', 'upload', 'attachment', 'document'],
102
+ color: ['color', 'colour'],
103
+ selection: ['select', 'choose', 'option'],
104
+ toggle: ['enable', 'disable', 'turn on', 'turn off'],
105
+ consent: ['agree', 'consent', 'accept', 'terms', 'privacy', 'subscribe'],
106
+ unknown: [],
107
+ };
108
+ /**
109
+ * Name patterns for semantic type inference.
110
+ * Maps common naming patterns (camelCase, snake_case, kebab-case) to semantic types.
111
+ */
112
+ export const NAME_PATTERNS = {
113
+ // Email patterns
114
+ email: 'email',
115
+ emailaddress: 'email',
116
+ email_address: 'email',
117
+ 'email-address': 'email',
118
+ useremail: 'email',
119
+ user_email: 'email',
120
+ // Phone patterns
121
+ phone: 'phone',
122
+ phonenumber: 'phone',
123
+ phone_number: 'phone',
124
+ 'phone-number': 'phone',
125
+ tel: 'phone',
126
+ telephone: 'phone',
127
+ mobile: 'phone',
128
+ // Password patterns
129
+ password: 'password',
130
+ passwd: 'password',
131
+ pass: 'password',
132
+ confirmpassword: 'password_confirm',
133
+ confirm_password: 'password_confirm',
134
+ passwordconfirm: 'password_confirm',
135
+ // Name patterns
136
+ firstname: 'first_name',
137
+ first_name: 'first_name',
138
+ 'first-name': 'first_name',
139
+ givenname: 'first_name',
140
+ lastname: 'last_name',
141
+ last_name: 'last_name',
142
+ 'last-name': 'last_name',
143
+ familyname: 'last_name',
144
+ fullname: 'full_name',
145
+ full_name: 'full_name',
146
+ // Username
147
+ username: 'username',
148
+ user_name: 'username',
149
+ userid: 'username',
150
+ user_id: 'username',
151
+ // Address
152
+ streetaddress: 'street',
153
+ street_address: 'street',
154
+ addressline: 'street',
155
+ address_line: 'street',
156
+ city: 'city',
157
+ state: 'state',
158
+ province: 'state',
159
+ zip: 'zip',
160
+ zipcode: 'zip',
161
+ zip_code: 'zip',
162
+ postalcode: 'zip',
163
+ postal_code: 'zip',
164
+ country: 'country',
165
+ // Payment
166
+ cardnumber: 'card_number',
167
+ card_number: 'card_number',
168
+ ccnumber: 'card_number',
169
+ cc_number: 'card_number',
170
+ cvv: 'card_cvv',
171
+ cvc: 'card_cvv',
172
+ expiry: 'card_expiry',
173
+ expiration: 'card_expiry',
174
+ // Dates
175
+ dateofbirth: 'date_of_birth',
176
+ date_of_birth: 'date_of_birth',
177
+ dob: 'date_of_birth',
178
+ birthday: 'date_of_birth',
179
+ birthdate: 'date_of_birth',
180
+ };
181
+ /**
182
+ * Extract semantic type from naming patterns.
183
+ *
184
+ * @param label - The accessible label
185
+ * @param testId - Optional test ID attribute
186
+ * @returns Object with inferred type and signal description
187
+ */
188
+ export function extractNamePatterns(label, testId) {
189
+ // Normalize label to check against patterns
190
+ const normalizedLabel = label.toLowerCase().replace(/[^a-z0-9_-]/g, '');
191
+ // Check label against patterns
192
+ for (const [pattern, type] of Object.entries(NAME_PATTERNS)) {
193
+ if (normalizedLabel.includes(pattern)) {
194
+ return { type, signal: `label matches pattern "${pattern}"` };
195
+ }
196
+ }
197
+ // Check test_id against patterns
198
+ if (testId) {
199
+ const normalizedTestId = testId.toLowerCase().replace(/[^a-z0-9_-]/g, '');
200
+ for (const [pattern, type] of Object.entries(NAME_PATTERNS)) {
201
+ if (normalizedTestId.includes(pattern)) {
202
+ return { type, signal: `test_id matches pattern "${pattern}"` };
203
+ }
204
+ }
205
+ }
206
+ return { type: 'unknown', signal: '' };
207
+ }
208
+ /**
209
+ * Infer the semantic purpose of a field.
210
+ */
211
+ export function inferPurpose(node) {
212
+ const inferredFrom = [];
213
+ let semanticType = 'unknown';
214
+ let confidence = 0;
215
+ // Priority 1: Input type attribute (high confidence)
216
+ const inputType = node.attributes?.input_type;
217
+ if (inputType && INPUT_TYPE_TO_SEMANTIC[inputType]) {
218
+ semanticType = INPUT_TYPE_TO_SEMANTIC[inputType];
219
+ confidence = 0.95;
220
+ inferredFrom.push(`input_type="${inputType}"`);
221
+ }
222
+ // Priority 2: Autocomplete attribute (high confidence)
223
+ const autocomplete = node.attributes?.autocomplete;
224
+ if (autocomplete && AUTOCOMPLETE_TO_SEMANTIC[autocomplete]) {
225
+ const autoType = AUTOCOMPLETE_TO_SEMANTIC[autocomplete];
226
+ if (semanticType === 'unknown' || confidence < 0.9) {
227
+ semanticType = autoType;
228
+ confidence = Math.max(confidence, 0.9);
229
+ inferredFrom.push(`autocomplete="${autocomplete}"`);
230
+ }
231
+ }
232
+ // Priority 3-5: Label, placeholder, aria-label (medium confidence)
233
+ // Note: node.label is the computed accessible name which includes aria-label,
234
+ // aria-labelledby, and other ARIA labeling mechanisms
235
+ if (semanticType === 'unknown' || confidence < 0.8) {
236
+ const textSources = [
237
+ { text: node.label, source: 'label', confidence: 0.7 },
238
+ { text: node.attributes?.placeholder, source: 'placeholder', confidence: 0.65 },
239
+ ];
240
+ for (const { text, source, confidence: sourceConfidence } of textSources) {
241
+ if (!text)
242
+ continue;
243
+ const lowerText = text.toLowerCase();
244
+ for (const [type, keywords] of Object.entries(LABEL_KEYWORDS)) {
245
+ if (type === 'unknown')
246
+ continue;
247
+ for (const keyword of keywords) {
248
+ if (lowerText.includes(keyword)) {
249
+ if (semanticType === 'unknown' || confidence < sourceConfidence) {
250
+ semanticType = type;
251
+ confidence = Math.max(confidence, sourceConfidence);
252
+ inferredFrom.push(`${source} contains "${keyword}"`);
253
+ }
254
+ break;
255
+ }
256
+ }
257
+ if (semanticType !== 'unknown' && confidence >= 0.7)
258
+ break;
259
+ }
260
+ if (semanticType !== 'unknown' && confidence >= 0.7)
261
+ break;
262
+ }
263
+ }
264
+ // Priority 6: Name attribute patterns (low confidence: 0.5)
265
+ // Detect naming conventions like camelCase (firstName), snake_case (first_name),
266
+ // or kebab-case (first-name) that may indicate field purpose
267
+ if (semanticType === 'unknown' || confidence < 0.5) {
268
+ const testId = node.attributes?.test_id ?? '';
269
+ const namePatterns = extractNamePatterns(node.label, testId);
270
+ if (namePatterns.type !== 'unknown') {
271
+ semanticType = namePatterns.type;
272
+ confidence = Math.max(confidence, 0.5);
273
+ inferredFrom.push(namePatterns.signal);
274
+ }
275
+ }
276
+ // Fallback based on node kind
277
+ if (semanticType === 'unknown') {
278
+ switch (node.kind) {
279
+ case 'checkbox':
280
+ semanticType = 'toggle';
281
+ confidence = 0.5;
282
+ inferredFrom.push('node kind is checkbox');
283
+ break;
284
+ case 'radio':
285
+ semanticType = 'selection';
286
+ confidence = 0.5;
287
+ inferredFrom.push('node kind is radio');
288
+ break;
289
+ case 'select':
290
+ case 'combobox':
291
+ semanticType = 'selection';
292
+ confidence = 0.5;
293
+ inferredFrom.push(`node kind is ${node.kind}`);
294
+ break;
295
+ case 'textarea':
296
+ semanticType = 'message';
297
+ confidence = 0.4;
298
+ inferredFrom.push('node kind is textarea');
299
+ break;
300
+ case 'slider':
301
+ semanticType = 'quantity';
302
+ confidence = 0.4;
303
+ inferredFrom.push('node kind is slider');
304
+ break;
305
+ }
306
+ }
307
+ return {
308
+ semantic_type: semanticType,
309
+ confidence,
310
+ inferred_from: inferredFrom.length > 0 ? inferredFrom : ['no signals found'],
311
+ };
312
+ }
313
+ //# sourceMappingURL=purpose-inference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purpose-inference.js","sourceRoot":"","sources":["../../../src/form/purpose-inference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAsC;IACvE,KAAK,EAAE,OAAO;IACd,GAAG,EAAE,OAAO;IACZ,QAAQ,EAAE,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AAY,KAAK,SAAS,EAAE,CAAC;QAC/B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,UAAU;gBACb,YAAY,GAAG,QAAQ,CAAC;gBACxB,UAAU,GAAG,GAAG,CAAC;gBACjB,YAAY,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;gBAC3C,MAAM;YACR,KAAK,OAAO;gBACV,YAAY,GAAG,WAAW,CAAC;gBAC3B,UAAU,GAAG,GAAG,CAAC;gBACjB,YAAY,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;gBACxC,MAAM;YACR,KAAK,QAAQ,CAAC;YACd,KAAK,UAAU;gBACb,YAAY,GAAG,WAAW,CAAC;gBAC3B,UAAU,GAAG,GAAG,CAAC;gBACjB,YAAY,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC/C,MAAM;YACR,KAAK,UAAU;gBACb,YAAY,GAAG,SAAS,CAAC;gBACzB,UAAU,GAAG,GAAG,CAAC;gBACjB,YAAY,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;gBAC3C,MAAM;YACR,KAAK,QAAQ;gBACX,YAAY,GAAG,UAAU,CAAC;gBAC1B,UAAU,GAAG,GAAG,CAAC;gBACjB,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;gBACzC,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO;QACL,aAAa,EAAE,YAAY;QAC3B,UAAU;QACV,aAAa,EAAE,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC;KAC7E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Submit Button Detection
3
+ *
4
+ * Detects submit buttons associated with forms or input clusters
5
+ * using keyword matching and spatial proximity.
6
+ *
7
+ * @module form/submit-detection
8
+ */
9
+ import type { BaseSnapshot, ReadableNode } from '../snapshot/snapshot.types.js';
10
+ /**
11
+ * Submit button keywords
12
+ */
13
+ export declare const SUBMIT_KEYWORDS: string[];
14
+ /**
15
+ * Find a submit button associated with a form.
16
+ */
17
+ export declare function findSubmitButton(snapshot: BaseSnapshot, formNode: ReadableNode, fieldEids: string[], isNodeWithinForm: (node: ReadableNode, formNode: ReadableNode, snapshot: BaseSnapshot) => boolean, computeClusterBbox: (nodes: ReadableNode[]) => {
18
+ x: number;
19
+ y: number;
20
+ width: number;
21
+ height: number;
22
+ } | undefined): ReadableNode | undefined;
23
+ /**
24
+ * Find a submit button near a cluster of inputs.
25
+ */
26
+ export declare function findSubmitButtonNearCluster(snapshot: BaseSnapshot, cluster: ReadableNode[], computeClusterBbox: (nodes: ReadableNode[]) => {
27
+ x: number;
28
+ y: number;
29
+ width: number;
30
+ height: number;
31
+ } | undefined): ReadableNode | undefined;
32
+ /**
33
+ * Check if a button looks like a submit button.
34
+ */
35
+ export declare function isSubmitButton(button: ReadableNode): boolean;
36
+ //# sourceMappingURL=submit-detection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit-detection.d.ts","sourceRoot":"","sources":["../../../src/form/submit-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAGhF;;GAEG;AACH,eAAO,MAAM,eAAe,UAkB3B,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,MAAM,EAAE,EACnB,gBAAgB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,KAAK,OAAO,EACjG,kBAAkB,EAAE,CAClB,KAAK,EAAE,YAAY,EAAE,KAClB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GACvE,YAAY,GAAG,SAAS,CAyB1B;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,YAAY,EAAE,EACvB,kBAAkB,EAAE,CAClB,KAAK,EAAE,YAAY,EAAE,KAClB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GACvE,YAAY,GAAG,SAAS,CA8B1B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAgB5D"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Submit Button Detection
3
+ *
4
+ * Detects submit buttons associated with forms or input clusters
5
+ * using keyword matching and spatial proximity.
6
+ *
7
+ * @module form/submit-detection
8
+ */
9
+ import { BUTTON_KINDS } from './form-actions.js';
10
+ /**
11
+ * Submit button keywords
12
+ */
13
+ export const SUBMIT_KEYWORDS = [
14
+ 'submit',
15
+ 'send',
16
+ 'continue',
17
+ 'next',
18
+ 'save',
19
+ 'apply',
20
+ 'confirm',
21
+ 'add to',
22
+ 'sign in',
23
+ 'log in',
24
+ 'sign up',
25
+ 'register',
26
+ 'search',
27
+ 'buy',
28
+ 'checkout',
29
+ 'purchase',
30
+ 'subscribe',
31
+ ];
32
+ /**
33
+ * Find a submit button associated with a form.
34
+ */
35
+ export function findSubmitButton(snapshot, formNode, fieldEids, isNodeWithinForm, computeClusterBbox) {
36
+ const buttons = snapshot.nodes.filter((n) => BUTTON_KINDS.has(n.kind));
37
+ for (const button of buttons) {
38
+ // Check if button is within form's scope
39
+ if (!isNodeWithinForm(button, formNode, snapshot)) {
40
+ continue;
41
+ }
42
+ // Check if button label suggests submission
43
+ if (isSubmitButton(button)) {
44
+ return button;
45
+ }
46
+ }
47
+ // Also check buttons near the fields
48
+ if (fieldEids.length > 0) {
49
+ const fieldNodes = fieldEids
50
+ .map((eid) => snapshot.nodes.find((n) => n.node_id === eid))
51
+ .filter((n) => n !== undefined);
52
+ return findSubmitButtonNearCluster(snapshot, fieldNodes, computeClusterBbox);
53
+ }
54
+ return undefined;
55
+ }
56
+ /**
57
+ * Find a submit button near a cluster of inputs.
58
+ */
59
+ export function findSubmitButtonNearCluster(snapshot, cluster, computeClusterBbox) {
60
+ if (cluster.length === 0)
61
+ return undefined;
62
+ const buttons = snapshot.nodes.filter((n) => BUTTON_KINDS.has(n.kind));
63
+ const clusterBbox = computeClusterBbox(cluster);
64
+ if (!clusterBbox)
65
+ return undefined;
66
+ // Find buttons near the cluster
67
+ const nearbyButtons = buttons.filter((button) => {
68
+ if (!button.layout?.bbox)
69
+ return false;
70
+ const btnBbox = button.layout.bbox;
71
+ // Check if button is below or to the right of the cluster
72
+ const isNearX = btnBbox.x >= clusterBbox.x - 100 && btnBbox.x <= clusterBbox.x + clusterBbox.width + 100;
73
+ const isNearY = btnBbox.y >= clusterBbox.y - 50 && btnBbox.y <= clusterBbox.y + clusterBbox.height + 150;
74
+ return isNearX && isNearY;
75
+ });
76
+ // Find the best submit button candidate
77
+ for (const button of nearbyButtons) {
78
+ if (isSubmitButton(button)) {
79
+ return button;
80
+ }
81
+ }
82
+ return undefined;
83
+ }
84
+ /**
85
+ * Check if a button looks like a submit button.
86
+ */
87
+ export function isSubmitButton(button) {
88
+ const label = button.label.toLowerCase();
89
+ // Check for submit keywords
90
+ for (const keyword of SUBMIT_KEYWORDS) {
91
+ if (label.includes(keyword)) {
92
+ return true;
93
+ }
94
+ }
95
+ // Check for type="submit" attribute
96
+ if (button.attributes?.input_type === 'submit') {
97
+ return true;
98
+ }
99
+ return false;
100
+ }
101
+ //# sourceMappingURL=submit-detection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"submit-detection.js","sourceRoot":"","sources":["../../../src/form/submit-detection.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MAAM,CAAC,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAoB;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IAEzC,4BAA4B;IAC5B,KAAK,MAAM,OAAO,IAAI,eAAe,EAAE,CAAC;QACtC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,oCAAoC;IACpC,IAAI,MAAM,CAAC,UAAU,EAAE,UAAU,KAAK,QAAQ,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -276,7 +276,7 @@ export interface ObservedEffect {
276
276
  confidence: number;
277
277
  }
278
278
  /**
279
- * Response from get_form_understanding tool.
279
+ * Response from get_form tool.
280
280
  */
281
281
  export interface FormUnderstandingResponse {
282
282
  /** Page ID */
@@ -289,7 +289,7 @@ export interface FormUnderstandingResponse {
289
289
  form_count: number;
290
290
  }
291
291
  /**
292
- * Response from get_field_context tool.
292
+ * Response from get_field tool.
293
293
  */
294
294
  export interface FieldContextResponse {
295
295
  /** The requested field */