@predicatelabs/sdk 0.99.9

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 (302) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +252 -0
  3. package/dist/actions.d.ts +185 -0
  4. package/dist/actions.d.ts.map +1 -0
  5. package/dist/actions.js +1120 -0
  6. package/dist/actions.js.map +1 -0
  7. package/dist/agent-runtime.d.ts +352 -0
  8. package/dist/agent-runtime.d.ts.map +1 -0
  9. package/dist/agent-runtime.js +1170 -0
  10. package/dist/agent-runtime.js.map +1 -0
  11. package/dist/agent.d.ts +164 -0
  12. package/dist/agent.d.ts.map +1 -0
  13. package/dist/agent.js +408 -0
  14. package/dist/agent.js.map +1 -0
  15. package/dist/asserts/expect.d.ts +159 -0
  16. package/dist/asserts/expect.d.ts.map +1 -0
  17. package/dist/asserts/expect.js +547 -0
  18. package/dist/asserts/expect.js.map +1 -0
  19. package/dist/asserts/index.d.ts +58 -0
  20. package/dist/asserts/index.d.ts.map +1 -0
  21. package/dist/asserts/index.js +70 -0
  22. package/dist/asserts/index.js.map +1 -0
  23. package/dist/asserts/query.d.ts +199 -0
  24. package/dist/asserts/query.d.ts.map +1 -0
  25. package/dist/asserts/query.js +288 -0
  26. package/dist/asserts/query.js.map +1 -0
  27. package/dist/backends/actions.d.ts +119 -0
  28. package/dist/backends/actions.d.ts.map +1 -0
  29. package/dist/backends/actions.js +291 -0
  30. package/dist/backends/actions.js.map +1 -0
  31. package/dist/backends/browser-use-adapter.d.ts +131 -0
  32. package/dist/backends/browser-use-adapter.d.ts.map +1 -0
  33. package/dist/backends/browser-use-adapter.js +219 -0
  34. package/dist/backends/browser-use-adapter.js.map +1 -0
  35. package/dist/backends/cdp-backend.d.ts +66 -0
  36. package/dist/backends/cdp-backend.d.ts.map +1 -0
  37. package/dist/backends/cdp-backend.js +273 -0
  38. package/dist/backends/cdp-backend.js.map +1 -0
  39. package/dist/backends/index.d.ts +80 -0
  40. package/dist/backends/index.d.ts.map +1 -0
  41. package/dist/backends/index.js +101 -0
  42. package/dist/backends/index.js.map +1 -0
  43. package/dist/backends/protocol.d.ts +156 -0
  44. package/dist/backends/protocol.d.ts.map +1 -0
  45. package/dist/backends/protocol.js +16 -0
  46. package/dist/backends/protocol.js.map +1 -0
  47. package/dist/backends/sentience-context.d.ts +143 -0
  48. package/dist/backends/sentience-context.d.ts.map +1 -0
  49. package/dist/backends/sentience-context.js +359 -0
  50. package/dist/backends/sentience-context.js.map +1 -0
  51. package/dist/backends/snapshot.d.ts +188 -0
  52. package/dist/backends/snapshot.d.ts.map +1 -0
  53. package/dist/backends/snapshot.js +360 -0
  54. package/dist/backends/snapshot.js.map +1 -0
  55. package/dist/browser.d.ts +154 -0
  56. package/dist/browser.d.ts.map +1 -0
  57. package/dist/browser.js +920 -0
  58. package/dist/browser.js.map +1 -0
  59. package/dist/canonicalization.d.ts +126 -0
  60. package/dist/canonicalization.d.ts.map +1 -0
  61. package/dist/canonicalization.js +161 -0
  62. package/dist/canonicalization.js.map +1 -0
  63. package/dist/captcha/strategies.d.ts +12 -0
  64. package/dist/captcha/strategies.d.ts.map +1 -0
  65. package/dist/captcha/strategies.js +43 -0
  66. package/dist/captcha/strategies.js.map +1 -0
  67. package/dist/captcha/types.d.ts +45 -0
  68. package/dist/captcha/types.d.ts.map +1 -0
  69. package/dist/captcha/types.js +12 -0
  70. package/dist/captcha/types.js.map +1 -0
  71. package/dist/cli.d.ts +5 -0
  72. package/dist/cli.d.ts.map +1 -0
  73. package/dist/cli.js +422 -0
  74. package/dist/cli.js.map +1 -0
  75. package/dist/conversational-agent.d.ts +123 -0
  76. package/dist/conversational-agent.d.ts.map +1 -0
  77. package/dist/conversational-agent.js +341 -0
  78. package/dist/conversational-agent.js.map +1 -0
  79. package/dist/cursor-policy.d.ts +41 -0
  80. package/dist/cursor-policy.d.ts.map +1 -0
  81. package/dist/cursor-policy.js +81 -0
  82. package/dist/cursor-policy.js.map +1 -0
  83. package/dist/debugger.d.ts +28 -0
  84. package/dist/debugger.d.ts.map +1 -0
  85. package/dist/debugger.js +107 -0
  86. package/dist/debugger.js.map +1 -0
  87. package/dist/expect.d.ts +16 -0
  88. package/dist/expect.d.ts.map +1 -0
  89. package/dist/expect.js +67 -0
  90. package/dist/expect.js.map +1 -0
  91. package/dist/failure-artifacts.d.ts +95 -0
  92. package/dist/failure-artifacts.d.ts.map +1 -0
  93. package/dist/failure-artifacts.js +805 -0
  94. package/dist/failure-artifacts.js.map +1 -0
  95. package/dist/generator.d.ts +16 -0
  96. package/dist/generator.d.ts.map +1 -0
  97. package/dist/generator.js +205 -0
  98. package/dist/generator.js.map +1 -0
  99. package/dist/index.d.ts +37 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +160 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/inspector.d.ts +13 -0
  104. package/dist/inspector.d.ts.map +1 -0
  105. package/dist/inspector.js +153 -0
  106. package/dist/inspector.js.map +1 -0
  107. package/dist/llm-provider.d.ts +144 -0
  108. package/dist/llm-provider.d.ts.map +1 -0
  109. package/dist/llm-provider.js +460 -0
  110. package/dist/llm-provider.js.map +1 -0
  111. package/dist/ordinal.d.ts +90 -0
  112. package/dist/ordinal.d.ts.map +1 -0
  113. package/dist/ordinal.js +249 -0
  114. package/dist/ordinal.js.map +1 -0
  115. package/dist/overlay.d.ts +63 -0
  116. package/dist/overlay.d.ts.map +1 -0
  117. package/dist/overlay.js +102 -0
  118. package/dist/overlay.js.map +1 -0
  119. package/dist/protocols/browser-protocol.d.ts +79 -0
  120. package/dist/protocols/browser-protocol.d.ts.map +1 -0
  121. package/dist/protocols/browser-protocol.js +9 -0
  122. package/dist/protocols/browser-protocol.js.map +1 -0
  123. package/dist/query.d.ts +66 -0
  124. package/dist/query.d.ts.map +1 -0
  125. package/dist/query.js +482 -0
  126. package/dist/query.js.map +1 -0
  127. package/dist/read.d.ts +47 -0
  128. package/dist/read.d.ts.map +1 -0
  129. package/dist/read.js +128 -0
  130. package/dist/read.js.map +1 -0
  131. package/dist/recorder.d.ts +44 -0
  132. package/dist/recorder.d.ts.map +1 -0
  133. package/dist/recorder.js +262 -0
  134. package/dist/recorder.js.map +1 -0
  135. package/dist/runtime-agent.d.ts +72 -0
  136. package/dist/runtime-agent.d.ts.map +1 -0
  137. package/dist/runtime-agent.js +357 -0
  138. package/dist/runtime-agent.js.map +1 -0
  139. package/dist/screenshot.d.ts +17 -0
  140. package/dist/screenshot.d.ts.map +1 -0
  141. package/dist/screenshot.js +40 -0
  142. package/dist/screenshot.js.map +1 -0
  143. package/dist/snapshot-diff.d.ts +23 -0
  144. package/dist/snapshot-diff.d.ts.map +1 -0
  145. package/dist/snapshot-diff.js +119 -0
  146. package/dist/snapshot-diff.js.map +1 -0
  147. package/dist/snapshot.d.ts +47 -0
  148. package/dist/snapshot.d.ts.map +1 -0
  149. package/dist/snapshot.js +358 -0
  150. package/dist/snapshot.js.map +1 -0
  151. package/dist/textSearch.d.ts +64 -0
  152. package/dist/textSearch.d.ts.map +1 -0
  153. package/dist/textSearch.js +113 -0
  154. package/dist/textSearch.js.map +1 -0
  155. package/dist/tools/context.d.ts +18 -0
  156. package/dist/tools/context.d.ts.map +1 -0
  157. package/dist/tools/context.js +40 -0
  158. package/dist/tools/context.js.map +1 -0
  159. package/dist/tools/defaults.d.ts +5 -0
  160. package/dist/tools/defaults.d.ts.map +1 -0
  161. package/dist/tools/defaults.js +368 -0
  162. package/dist/tools/defaults.js.map +1 -0
  163. package/dist/tools/filesystem.d.ts +12 -0
  164. package/dist/tools/filesystem.d.ts.map +1 -0
  165. package/dist/tools/filesystem.js +137 -0
  166. package/dist/tools/filesystem.js.map +1 -0
  167. package/dist/tools/index.d.ts +5 -0
  168. package/dist/tools/index.d.ts.map +1 -0
  169. package/dist/tools/index.js +15 -0
  170. package/dist/tools/index.js.map +1 -0
  171. package/dist/tools/registry.d.ts +38 -0
  172. package/dist/tools/registry.d.ts.map +1 -0
  173. package/dist/tools/registry.js +100 -0
  174. package/dist/tools/registry.js.map +1 -0
  175. package/dist/tracing/cloud-sink.d.ts +189 -0
  176. package/dist/tracing/cloud-sink.d.ts.map +1 -0
  177. package/dist/tracing/cloud-sink.js +1067 -0
  178. package/dist/tracing/cloud-sink.js.map +1 -0
  179. package/dist/tracing/index-schema.d.ts +231 -0
  180. package/dist/tracing/index-schema.d.ts.map +1 -0
  181. package/dist/tracing/index-schema.js +235 -0
  182. package/dist/tracing/index-schema.js.map +1 -0
  183. package/dist/tracing/index.d.ts +12 -0
  184. package/dist/tracing/index.d.ts.map +1 -0
  185. package/dist/tracing/index.js +28 -0
  186. package/dist/tracing/index.js.map +1 -0
  187. package/dist/tracing/indexer.d.ts +20 -0
  188. package/dist/tracing/indexer.d.ts.map +1 -0
  189. package/dist/tracing/indexer.js +347 -0
  190. package/dist/tracing/indexer.js.map +1 -0
  191. package/dist/tracing/jsonl-sink.d.ts +51 -0
  192. package/dist/tracing/jsonl-sink.d.ts.map +1 -0
  193. package/dist/tracing/jsonl-sink.js +329 -0
  194. package/dist/tracing/jsonl-sink.js.map +1 -0
  195. package/dist/tracing/sink.d.ts +25 -0
  196. package/dist/tracing/sink.d.ts.map +1 -0
  197. package/dist/tracing/sink.js +15 -0
  198. package/dist/tracing/sink.js.map +1 -0
  199. package/dist/tracing/tracer-factory.d.ts +102 -0
  200. package/dist/tracing/tracer-factory.d.ts.map +1 -0
  201. package/dist/tracing/tracer-factory.js +375 -0
  202. package/dist/tracing/tracer-factory.js.map +1 -0
  203. package/dist/tracing/tracer.d.ts +140 -0
  204. package/dist/tracing/tracer.d.ts.map +1 -0
  205. package/dist/tracing/tracer.js +336 -0
  206. package/dist/tracing/tracer.js.map +1 -0
  207. package/dist/tracing/types.d.ts +203 -0
  208. package/dist/tracing/types.d.ts.map +1 -0
  209. package/dist/tracing/types.js +8 -0
  210. package/dist/tracing/types.js.map +1 -0
  211. package/dist/types.d.ts +422 -0
  212. package/dist/types.d.ts.map +1 -0
  213. package/dist/types.js +6 -0
  214. package/dist/types.js.map +1 -0
  215. package/dist/utils/action-executor.d.ts +25 -0
  216. package/dist/utils/action-executor.d.ts.map +1 -0
  217. package/dist/utils/action-executor.js +121 -0
  218. package/dist/utils/action-executor.js.map +1 -0
  219. package/dist/utils/browser-evaluator.d.ts +76 -0
  220. package/dist/utils/browser-evaluator.d.ts.map +1 -0
  221. package/dist/utils/browser-evaluator.js +130 -0
  222. package/dist/utils/browser-evaluator.js.map +1 -0
  223. package/dist/utils/browser.d.ts +30 -0
  224. package/dist/utils/browser.d.ts.map +1 -0
  225. package/dist/utils/browser.js +75 -0
  226. package/dist/utils/browser.js.map +1 -0
  227. package/dist/utils/element-filter.d.ts +76 -0
  228. package/dist/utils/element-filter.d.ts.map +1 -0
  229. package/dist/utils/element-filter.js +195 -0
  230. package/dist/utils/element-filter.js.map +1 -0
  231. package/dist/utils/grid-utils.d.ts +37 -0
  232. package/dist/utils/grid-utils.d.ts.map +1 -0
  233. package/dist/utils/grid-utils.js +283 -0
  234. package/dist/utils/grid-utils.js.map +1 -0
  235. package/dist/utils/llm-interaction-handler.d.ts +41 -0
  236. package/dist/utils/llm-interaction-handler.d.ts.map +1 -0
  237. package/dist/utils/llm-interaction-handler.js +171 -0
  238. package/dist/utils/llm-interaction-handler.js.map +1 -0
  239. package/dist/utils/llm-response-builder.d.ts +56 -0
  240. package/dist/utils/llm-response-builder.d.ts.map +1 -0
  241. package/dist/utils/llm-response-builder.js +130 -0
  242. package/dist/utils/llm-response-builder.js.map +1 -0
  243. package/dist/utils/selector-utils.d.ts +12 -0
  244. package/dist/utils/selector-utils.d.ts.map +1 -0
  245. package/dist/utils/selector-utils.js +32 -0
  246. package/dist/utils/selector-utils.js.map +1 -0
  247. package/dist/utils/snapshot-event-builder.d.ts +28 -0
  248. package/dist/utils/snapshot-event-builder.d.ts.map +1 -0
  249. package/dist/utils/snapshot-event-builder.js +88 -0
  250. package/dist/utils/snapshot-event-builder.js.map +1 -0
  251. package/dist/utils/snapshot-processor.d.ts +27 -0
  252. package/dist/utils/snapshot-processor.d.ts.map +1 -0
  253. package/dist/utils/snapshot-processor.js +47 -0
  254. package/dist/utils/snapshot-processor.js.map +1 -0
  255. package/dist/utils/trace-event-builder.d.ts +122 -0
  256. package/dist/utils/trace-event-builder.d.ts.map +1 -0
  257. package/dist/utils/trace-event-builder.js +365 -0
  258. package/dist/utils/trace-event-builder.js.map +1 -0
  259. package/dist/utils/trace-file-manager.d.ts +70 -0
  260. package/dist/utils/trace-file-manager.d.ts.map +1 -0
  261. package/dist/utils/trace-file-manager.js +194 -0
  262. package/dist/utils/trace-file-manager.js.map +1 -0
  263. package/dist/utils/zod.d.ts +5 -0
  264. package/dist/utils/zod.d.ts.map +1 -0
  265. package/dist/utils/zod.js +80 -0
  266. package/dist/utils/zod.js.map +1 -0
  267. package/dist/utils.d.ts +8 -0
  268. package/dist/utils.d.ts.map +1 -0
  269. package/dist/utils.js +13 -0
  270. package/dist/utils.js.map +1 -0
  271. package/dist/verification.d.ts +194 -0
  272. package/dist/verification.d.ts.map +1 -0
  273. package/dist/verification.js +530 -0
  274. package/dist/verification.js.map +1 -0
  275. package/dist/vision-executor.d.ts +18 -0
  276. package/dist/vision-executor.d.ts.map +1 -0
  277. package/dist/vision-executor.js +60 -0
  278. package/dist/vision-executor.js.map +1 -0
  279. package/dist/visual-agent.d.ts +120 -0
  280. package/dist/visual-agent.d.ts.map +1 -0
  281. package/dist/visual-agent.js +796 -0
  282. package/dist/visual-agent.js.map +1 -0
  283. package/dist/wait.d.ts +35 -0
  284. package/dist/wait.d.ts.map +1 -0
  285. package/dist/wait.js +76 -0
  286. package/dist/wait.js.map +1 -0
  287. package/package.json +94 -0
  288. package/spec/README.md +72 -0
  289. package/spec/SNAPSHOT_V1.md +208 -0
  290. package/spec/sdk-types.md +259 -0
  291. package/spec/snapshot.schema.json +148 -0
  292. package/src/extension/background.js +104 -0
  293. package/src/extension/content.js +162 -0
  294. package/src/extension/injected_api.js +1399 -0
  295. package/src/extension/manifest.json +36 -0
  296. package/src/extension/pkg/README.md +1340 -0
  297. package/src/extension/pkg/package.json +15 -0
  298. package/src/extension/pkg/sentience_core.d.ts +51 -0
  299. package/src/extension/pkg/sentience_core.js +371 -0
  300. package/src/extension/pkg/sentience_core_bg.wasm +0 -0
  301. package/src/extension/pkg/sentience_core_bg.wasm.d.ts +10 -0
  302. package/src/extension/release.json +116 -0
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Assertion DSL for Sentience SDK.
4
+ *
5
+ * This module provides a Playwright/Cypress-like assertion API for verifying
6
+ * browser state in agent verification loops.
7
+ *
8
+ * Main exports:
9
+ * - E: Element query builder (filters elements by role, text, href, etc.)
10
+ * - expect: Expectation builder (creates predicates from queries)
11
+ * - inDominantList: Query over dominant group elements (ordinal access)
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { E, expect, inDominantList } from '@anthropic/sentience-ts/asserts';
16
+ *
17
+ * // Basic presence assertions
18
+ * await runtime.assert(
19
+ * expect(E({ role: "button", textContains: "Save" })).toExist(),
20
+ * "save_button_visible"
21
+ * );
22
+ *
23
+ * // Visibility assertions
24
+ * await runtime.assert(
25
+ * expect(E({ textContains: "Checkout" })).toBeVisible(),
26
+ * "checkout_visible"
27
+ * );
28
+ *
29
+ * // Global text assertions
30
+ * await runtime.assert(
31
+ * expect.textPresent("Welcome back"),
32
+ * "user_logged_in"
33
+ * );
34
+ * await runtime.assert(
35
+ * expect.noText("Error"),
36
+ * "no_error_message"
37
+ * );
38
+ *
39
+ * // Ordinal assertions on dominant group
40
+ * await runtime.assert(
41
+ * expect(inDominantList().nth(0)).toHaveTextContains("Show HN"),
42
+ * "first_item_is_show_hn"
43
+ * );
44
+ *
45
+ * // Task completion
46
+ * await runtime.assertDone(
47
+ * expect.textPresent("Order confirmed"),
48
+ * "checkout_complete"
49
+ * );
50
+ * ```
51
+ *
52
+ * The DSL compiles to existing Predicate functions, so it works seamlessly
53
+ * with AgentRuntime.assert() and assertDone().
54
+ */
55
+ Object.defineProperty(exports, "__esModule", { value: true });
56
+ exports.withEventually = exports.EventuallyWrapper = exports.ExpectBuilder = exports.expect = exports.inDominantList = exports.MultiQuery = exports.ListQuery = exports.ElementQuery = exports.E = void 0;
57
+ // Query builders
58
+ var query_1 = require("./query");
59
+ Object.defineProperty(exports, "E", { enumerable: true, get: function () { return query_1.E; } });
60
+ Object.defineProperty(exports, "ElementQuery", { enumerable: true, get: function () { return query_1.ElementQuery; } });
61
+ Object.defineProperty(exports, "ListQuery", { enumerable: true, get: function () { return query_1.ListQuery; } });
62
+ Object.defineProperty(exports, "MultiQuery", { enumerable: true, get: function () { return query_1.MultiQuery; } });
63
+ Object.defineProperty(exports, "inDominantList", { enumerable: true, get: function () { return query_1.inDominantList; } });
64
+ // Expectation builders
65
+ var expect_1 = require("./expect");
66
+ Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return expect_1.expect; } });
67
+ Object.defineProperty(exports, "ExpectBuilder", { enumerable: true, get: function () { return expect_1.ExpectBuilder; } });
68
+ Object.defineProperty(exports, "EventuallyWrapper", { enumerable: true, get: function () { return expect_1.EventuallyWrapper; } });
69
+ Object.defineProperty(exports, "withEventually", { enumerable: true, get: function () { return expect_1.withEventually; } });
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/asserts/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;;;AAEH,iBAAiB;AACjB,iCAAiF;AAAxE,0FAAA,CAAC,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,kGAAA,SAAS,OAAA;AAAE,mGAAA,UAAU,OAAA;AAAE,uGAAA,cAAc,OAAA;AAG/D,uBAAuB;AACvB,mCAAoF;AAA3E,gGAAA,MAAM,OAAA;AAAE,uGAAA,aAAa,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,wGAAA,cAAc,OAAA"}
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Element query builders for assertion DSL.
3
+ *
4
+ * This module provides the E() query builder and dominant-group list operations
5
+ * for creating element queries that compile to existing Predicates.
6
+ *
7
+ * Key classes:
8
+ * - ElementQuery: Pure data object for filtering elements (E())
9
+ * - ListQuery: Query over dominant-group elements (inDominantList())
10
+ * - MultiQuery: Represents multiple elements from ListQuery.top(n)
11
+ *
12
+ * All queries work with existing Snapshot fields only:
13
+ * id, role, text, bbox, doc_y, group_key, group_index,
14
+ * dominant_group_key, in_viewport, is_occluded, href
15
+ */
16
+ import { Element, Snapshot } from '../types';
17
+ /**
18
+ * Options for creating an ElementQuery via E().
19
+ */
20
+ export interface EOptions {
21
+ /** ARIA role to match (e.g., "button", "textbox", "link") */
22
+ role?: string;
23
+ /** Text to match exactly (alias for text, best-effort) */
24
+ name?: string;
25
+ /** Exact text match */
26
+ text?: string;
27
+ /** Substring match against text (case-insensitive) */
28
+ textContains?: string;
29
+ /** Substring match against href (case-insensitive) */
30
+ hrefContains?: string;
31
+ /** Filter by viewport visibility */
32
+ inViewport?: boolean;
33
+ /** Filter by occlusion state */
34
+ occluded?: boolean;
35
+ /** Exact match against group_key */
36
+ group?: string;
37
+ /** True = must be in dominant group */
38
+ inDominantGroup?: boolean;
39
+ }
40
+ /**
41
+ * Pure query object for filtering elements.
42
+ *
43
+ * This is the data representation of an E() call. It does not execute
44
+ * anything - it just stores the filter criteria.
45
+ *
46
+ * @example
47
+ * E({ role: "button", textContains: "Save" })
48
+ * E({ role: "link", hrefContains: "/cart" })
49
+ * E({ inViewport: true, occluded: false })
50
+ */
51
+ export declare class ElementQuery {
52
+ role?: string;
53
+ name?: string;
54
+ text?: string;
55
+ textContains?: string;
56
+ hrefContains?: string;
57
+ inViewport?: boolean;
58
+ occluded?: boolean;
59
+ group?: string;
60
+ inDominantGroup?: boolean;
61
+ _groupIndex?: number;
62
+ _fromDominantList: boolean;
63
+ constructor(options?: EOptions);
64
+ /**
65
+ * Check if element matches this query criteria.
66
+ *
67
+ * @param element - Element to check
68
+ * @param snapshot - Snapshot (needed for dominant_group_key comparison)
69
+ * @returns True if element matches all criteria
70
+ */
71
+ matches(element: Element, snapshot?: Snapshot | null): boolean;
72
+ /**
73
+ * Find all elements matching this query in the snapshot.
74
+ *
75
+ * @param snapshot - Snapshot to search
76
+ * @returns Array of matching elements, sorted by doc_y (top to bottom)
77
+ */
78
+ findAll(snapshot: Snapshot): Element[];
79
+ /**
80
+ * Find first matching element.
81
+ *
82
+ * @param snapshot - Snapshot to search
83
+ * @returns First matching element or null
84
+ */
85
+ findFirst(snapshot: Snapshot): Element | null;
86
+ }
87
+ /**
88
+ * Interface for the E function with static convenience methods.
89
+ */
90
+ interface EFunction {
91
+ (options?: EOptions): ElementQuery;
92
+ /** Query for submit-like buttons */
93
+ submit: () => ElementQuery;
94
+ /** Query for search input boxes */
95
+ searchBox: () => ElementQuery;
96
+ /** Query for links with optional text filter */
97
+ link: (options?: {
98
+ textContains?: string;
99
+ }) => ElementQuery;
100
+ }
101
+ /**
102
+ * Create an element query.
103
+ *
104
+ * This is the main entry point for building element queries.
105
+ * It returns a pure data object that can be used with expect().
106
+ *
107
+ * @param options - Query filter options
108
+ * @returns ElementQuery object
109
+ *
110
+ * @example
111
+ * E({ role: "button", textContains: "Save" })
112
+ * E({ role: "link", hrefContains: "/checkout" })
113
+ * E({ inViewport: true, occluded: false })
114
+ */
115
+ export declare const E: EFunction;
116
+ /**
117
+ * Internal predicate for MultiQuery text checks.
118
+ * Used by expect() to evaluate multi-element text assertions.
119
+ */
120
+ export interface MultiTextPredicate {
121
+ multiQuery: MultiQuery;
122
+ text: string;
123
+ checkType: 'any_contains';
124
+ }
125
+ /**
126
+ * Represents multiple elements from a dominant list query.
127
+ *
128
+ * Created by ListQuery.top(n) to represent the first n elements
129
+ * in a dominant group.
130
+ *
131
+ * @example
132
+ * inDominantList().top(5) // First 5 items in dominant group
133
+ */
134
+ export declare class MultiQuery {
135
+ limit: number;
136
+ _parentListQuery?: ListQuery;
137
+ constructor(limit: number, parentListQuery?: ListQuery);
138
+ /**
139
+ * Create a predicate that checks if any element's text contains the substring.
140
+ *
141
+ * @param text - Substring to search for
142
+ * @returns Predicate that can be used with expect()
143
+ */
144
+ anyTextContains(text: string): MultiTextPredicate;
145
+ }
146
+ /**
147
+ * Query over elements in the dominant group.
148
+ *
149
+ * Provides ordinal access to dominant-group elements via .nth(k)
150
+ * and range access via .top(n).
151
+ *
152
+ * Created by inDominantList().
153
+ *
154
+ * @example
155
+ * inDominantList().nth(0) // First item in dominant group
156
+ * inDominantList().top(5) // First 5 items
157
+ */
158
+ export declare class ListQuery {
159
+ /**
160
+ * Select element at specific index in the dominant group.
161
+ *
162
+ * @param index - 0-based index in the dominant group
163
+ * @returns ElementQuery targeting the element at that position
164
+ *
165
+ * @example
166
+ * inDominantList().nth(0) // First item
167
+ * inDominantList().nth(2) // Third item
168
+ */
169
+ nth(index: number): ElementQuery;
170
+ /**
171
+ * Select the first n elements in the dominant group.
172
+ *
173
+ * @param n - Number of elements to select
174
+ * @returns MultiQuery representing the first n elements
175
+ *
176
+ * @example
177
+ * inDominantList().top(5) // First 5 items
178
+ */
179
+ top(n: number): MultiQuery;
180
+ }
181
+ /**
182
+ * Create a query over elements in the dominant group.
183
+ *
184
+ * The dominant group is the most common group_key in the snapshot,
185
+ * typically representing the main content list (search results,
186
+ * news feed items, product listings, etc.).
187
+ *
188
+ * @returns ListQuery for chaining .nth(k) or .top(n)
189
+ *
190
+ * @example
191
+ * inDominantList().nth(0) // First item in dominant group
192
+ * inDominantList().top(5) // First 5 items
193
+ *
194
+ * // With expect():
195
+ * expect(inDominantList().nth(0)).toHaveTextContains("Show HN")
196
+ */
197
+ export declare function inDominantList(): ListQuery;
198
+ export {};
199
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/asserts/query.ts"],"names":[],"mapp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E;IAOtC;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI;CAI9C;AAED;;GAEG;AACH,UAAU,SAAS;IACjB,CAAC,OAAO,CAAC,EAAE,QAAQ,GAAG,YAAY,CAAC;IACnC,oCAAoC;IACpC,MAAM,EAAE,MAAM,YAAY,CAAC;IAC3B,mCAAmC;IACnC,SAAS,EAAE,MAAM,YAAY,CAAC;IAC9B,gDAAgD;IAChD,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,YAAY,CAAC;CAC7D;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,CAAC,EAAE,SA8Bf,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,cAAc,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,qBAAa,UAAU;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,SAAS,CAAC;gBAEjB,KAAK,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS;IAKtD;;;;;OAKG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB;CAOlD;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS;IACpB;;;;;;;;;OASG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAOhC;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,UAAU;CAG3B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,IAAI,SAAS,CAE1C"}
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+ /**
3
+ * Element query builders for assertion DSL.
4
+ *
5
+ * This module provides the E() query builder and dominant-group list operations
6
+ * for creating element queries that compile to existing Predicates.
7
+ *
8
+ * Key classes:
9
+ * - ElementQuery: Pure data object for filtering elements (E())
10
+ * - ListQuery: Query over dominant-group elements (inDominantList())
11
+ * - MultiQuery: Represents multiple elements from ListQuery.top(n)
12
+ *
13
+ * All queries work with existing Snapshot fields only:
14
+ * id, role, text, bbox, doc_y, group_key, group_index,
15
+ * dominant_group_key, in_viewport, is_occluded, href
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ListQuery = exports.MultiQuery = exports.E = exports.ElementQuery = void 0;
19
+ exports.inDominantList = inDominantList;
20
+ /**
21
+ * Pure query object for filtering elements.
22
+ *
23
+ * This is the data representation of an E() call. It does not execute
24
+ * anything - it just stores the filter criteria.
25
+ *
26
+ * @example
27
+ * E({ role: "button", textContains: "Save" })
28
+ * E({ role: "link", hrefContains: "/cart" })
29
+ * E({ inViewport: true, occluded: false })
30
+ */
31
+ class ElementQuery {
32
+ constructor(options = {}) {
33
+ this._fromDominantList = false;
34
+ this.role = options.role;
35
+ this.name = options.name;
36
+ this.text = options.text;
37
+ this.textContains = options.textContains;
38
+ this.hrefContains = options.hrefContains;
39
+ this.inViewport = options.inViewport;
40
+ this.occluded = options.occluded;
41
+ this.group = options.group;
42
+ this.inDominantGroup = options.inDominantGroup;
43
+ }
44
+ /**
45
+ * Check if element matches this query criteria.
46
+ *
47
+ * @param element - Element to check
48
+ * @param snapshot - Snapshot (needed for dominant_group_key comparison)
49
+ * @returns True if element matches all criteria
50
+ */
51
+ matches(element, snapshot) {
52
+ // Role filter
53
+ if (this.role !== undefined) {
54
+ if (element.role !== this.role) {
55
+ return false;
56
+ }
57
+ }
58
+ // Text exact match (name is alias for text)
59
+ const textToMatch = this.text ?? this.name;
60
+ if (textToMatch !== undefined) {
61
+ const elementText = element.text || '';
62
+ if (elementText !== textToMatch) {
63
+ return false;
64
+ }
65
+ }
66
+ // Text contains (substring, case-insensitive)
67
+ if (this.textContains !== undefined) {
68
+ const elementText = element.text || '';
69
+ if (!elementText.toLowerCase().includes(this.textContains.toLowerCase())) {
70
+ return false;
71
+ }
72
+ }
73
+ // Href contains (substring)
74
+ if (this.hrefContains !== undefined) {
75
+ const elementHref = element.href || '';
76
+ if (!elementHref.toLowerCase().includes(this.hrefContains.toLowerCase())) {
77
+ return false;
78
+ }
79
+ }
80
+ // In viewport filter
81
+ if (this.inViewport !== undefined) {
82
+ if (element.in_viewport !== this.inViewport) {
83
+ return false;
84
+ }
85
+ }
86
+ // Occluded filter
87
+ if (this.occluded !== undefined) {
88
+ if (element.is_occluded !== this.occluded) {
89
+ return false;
90
+ }
91
+ }
92
+ // Group key exact match
93
+ if (this.group !== undefined) {
94
+ if (element.group_key !== this.group) {
95
+ return false;
96
+ }
97
+ }
98
+ // In dominant group check
99
+ if (this.inDominantGroup !== undefined) {
100
+ if (this.inDominantGroup) {
101
+ // Element must be in dominant group
102
+ if (!snapshot) {
103
+ return false;
104
+ }
105
+ if (element.group_key !== snapshot.dominant_group_key) {
106
+ return false;
107
+ }
108
+ }
109
+ else {
110
+ // Element must NOT be in dominant group
111
+ if (snapshot && element.group_key === snapshot.dominant_group_key) {
112
+ return false;
113
+ }
114
+ }
115
+ }
116
+ // Group index filter (from ListQuery.nth())
117
+ if (this._groupIndex !== undefined) {
118
+ if (element.group_index !== this._groupIndex) {
119
+ return false;
120
+ }
121
+ }
122
+ // Dominant list filter (from inDominantList())
123
+ if (this._fromDominantList) {
124
+ if (!snapshot) {
125
+ return false;
126
+ }
127
+ if (element.group_key !== snapshot.dominant_group_key) {
128
+ return false;
129
+ }
130
+ }
131
+ return true;
132
+ }
133
+ /**
134
+ * Find all elements matching this query in the snapshot.
135
+ *
136
+ * @param snapshot - Snapshot to search
137
+ * @returns Array of matching elements, sorted by doc_y (top to bottom)
138
+ */
139
+ findAll(snapshot) {
140
+ const matches = snapshot.elements.filter(el => this.matches(el, snapshot));
141
+ // Sort by doc_y for consistent ordering (top to bottom)
142
+ matches.sort((a, b) => (a.doc_y ?? a.bbox.y) - (b.doc_y ?? b.bbox.y));
143
+ return matches;
144
+ }
145
+ /**
146
+ * Find first matching element.
147
+ *
148
+ * @param snapshot - Snapshot to search
149
+ * @returns First matching element or null
150
+ */
151
+ findFirst(snapshot) {
152
+ const matches = this.findAll(snapshot);
153
+ return matches.length > 0 ? matches[0] : null;
154
+ }
155
+ }
156
+ exports.ElementQuery = ElementQuery;
157
+ /**
158
+ * Create an element query.
159
+ *
160
+ * This is the main entry point for building element queries.
161
+ * It returns a pure data object that can be used with expect().
162
+ *
163
+ * @param options - Query filter options
164
+ * @returns ElementQuery object
165
+ *
166
+ * @example
167
+ * E({ role: "button", textContains: "Save" })
168
+ * E({ role: "link", hrefContains: "/checkout" })
169
+ * E({ inViewport: true, occluded: false })
170
+ */
171
+ exports.E = Object.assign(function (options = {}) {
172
+ return new ElementQuery(options);
173
+ }, {
174
+ /**
175
+ * Query for submit-like buttons.
176
+ * Matches buttons with text like "Submit", "Save", "Continue", etc.
177
+ */
178
+ submit: function () {
179
+ return new ElementQuery({ role: 'button', textContains: 'submit' });
180
+ },
181
+ /**
182
+ * Query for search input boxes.
183
+ * Matches textbox/combobox with search-related names.
184
+ */
185
+ searchBox: function () {
186
+ return new ElementQuery({ role: 'textbox', name: 'search' });
187
+ },
188
+ /**
189
+ * Query for links with optional text filter.
190
+ *
191
+ * @param options - Optional text filter
192
+ */
193
+ link: function (options) {
194
+ return new ElementQuery({ role: 'link', textContains: options?.textContains });
195
+ },
196
+ });
197
+ /**
198
+ * Represents multiple elements from a dominant list query.
199
+ *
200
+ * Created by ListQuery.top(n) to represent the first n elements
201
+ * in a dominant group.
202
+ *
203
+ * @example
204
+ * inDominantList().top(5) // First 5 items in dominant group
205
+ */
206
+ class MultiQuery {
207
+ constructor(limit, parentListQuery) {
208
+ this.limit = limit;
209
+ this._parentListQuery = parentListQuery;
210
+ }
211
+ /**
212
+ * Create a predicate that checks if any element's text contains the substring.
213
+ *
214
+ * @param text - Substring to search for
215
+ * @returns Predicate that can be used with expect()
216
+ */
217
+ anyTextContains(text) {
218
+ return {
219
+ multiQuery: this,
220
+ text,
221
+ checkType: 'any_contains',
222
+ };
223
+ }
224
+ }
225
+ exports.MultiQuery = MultiQuery;
226
+ /**
227
+ * Query over elements in the dominant group.
228
+ *
229
+ * Provides ordinal access to dominant-group elements via .nth(k)
230
+ * and range access via .top(n).
231
+ *
232
+ * Created by inDominantList().
233
+ *
234
+ * @example
235
+ * inDominantList().nth(0) // First item in dominant group
236
+ * inDominantList().top(5) // First 5 items
237
+ */
238
+ class ListQuery {
239
+ /**
240
+ * Select element at specific index in the dominant group.
241
+ *
242
+ * @param index - 0-based index in the dominant group
243
+ * @returns ElementQuery targeting the element at that position
244
+ *
245
+ * @example
246
+ * inDominantList().nth(0) // First item
247
+ * inDominantList().nth(2) // Third item
248
+ */
249
+ nth(index) {
250
+ const query = new ElementQuery();
251
+ query._groupIndex = index;
252
+ query._fromDominantList = true;
253
+ return query;
254
+ }
255
+ /**
256
+ * Select the first n elements in the dominant group.
257
+ *
258
+ * @param n - Number of elements to select
259
+ * @returns MultiQuery representing the first n elements
260
+ *
261
+ * @example
262
+ * inDominantList().top(5) // First 5 items
263
+ */
264
+ top(n) {
265
+ return new MultiQuery(n, this);
266
+ }
267
+ }
268
+ exports.ListQuery = ListQuery;
269
+ /**
270
+ * Create a query over elements in the dominant group.
271
+ *
272
+ * The dominant group is the most common group_key in the snapshot,
273
+ * typically representing the main content list (search results,
274
+ * news feed items, product listings, etc.).
275
+ *
276
+ * @returns ListQuery for chaining .nth(k) or .top(n)
277
+ *
278
+ * @example
279
+ * inDominantList().nth(0) // First item in dominant group
280
+ * inDominantList().top(5) // First 5 items
281
+ *
282
+ * // With expect():
283
+ * expect(inDominantList().nth(0)).toHaveTextContains("Show HN")
284
+ */
285
+ function inDominantList() {
286
+ return new ListQuery();
287
+ }
288
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/asserts/query.ts"],"names":[],"mappings":";AAA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ACH,MAAa,SAAS;IACpB;;;;;;;;;OASG;IACH,GAAG,CAAC,KAAa;QACf,MAAM,KAAK,GAAG,IAAI,YAAY,EAAE,CAAC;QACjC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;QAC1B,KAAK,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,CAAS;QACX,OAAO,IAAI,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;CACF;AA9BD,8BA8BC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,cAAc;IAC5B,OAAO,IAAI,SAAS,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Backend-agnostic actions for browser-use integration.
3
+ *
4
+ * These actions work with any BrowserBackend implementation,
5
+ * enabling Sentience grounding with browser-use or other frameworks.
6
+ *
7
+ * Usage with browser-use:
8
+ * import { BrowserUseAdapter } from './backends/browser-use-adapter';
9
+ * import { click, typeText, scroll } from './backends/actions';
10
+ *
11
+ * const adapter = new BrowserUseAdapter(session);
12
+ * const backend = await adapter.createBackend();
13
+ *
14
+ * // Take snapshot and click element
15
+ * const snap = await snapshot(backend);
16
+ * const element = find(snap, 'role=button[name="Submit"]');
17
+ * await click(backend, element.bbox);
18
+ */
19
+ import type { ActionResult, BBox } from '../types';
20
+ import type { BrowserBackend, MouseButton } from './protocol';
21
+ import type { CursorPolicy } from '../cursor-policy';
22
+ /**
23
+ * Target type for coordinate resolution.
24
+ * Can be a BBox (clicks center), {x, y} object, or [x, y] tuple.
25
+ */
26
+ export type ClickTarget = BBox | {
27
+ x: number;
28
+ y: number;
29
+ width?: number;
30
+ height?: number;
31
+ } | [number, number];
32
+ /**
33
+ * Scroll behavior for scrollToElement.
34
+ */
35
+ export type ScrollBehavior = 'smooth' | 'instant' | 'auto';
36
+ /**
37
+ * Vertical alignment for scrollToElement.
38
+ */
39
+ export type ScrollBlock = 'start' | 'center' | 'end' | 'nearest';
40
+ /**
41
+ * Click at coordinates using the backend.
42
+ *
43
+ * @param backend - BrowserBackend implementation
44
+ * @param target - Click target - BBox (clicks center), dict with x/y, or (x, y) tuple
45
+ * @param button - Mouse button to click
46
+ * @param clickCount - Number of clicks (1=single, 2=double)
47
+ * @param moveFirst - Whether to move mouse to position before clicking
48
+ * @returns ActionResult with success status
49
+ *
50
+ * @example
51
+ * // Click at coordinates
52
+ * await click(backend, [100, 200]);
53
+ *
54
+ * // Click element bbox center
55
+ * await click(backend, element.bbox);
56
+ *
57
+ * // Double-click
58
+ * await click(backend, element.bbox, 'left', 2);
59
+ */
60
+ export declare function click(backend: BrowserBackend, target: ClickTarget, button?: MouseButton, clickCount?: number, moveFirst?: boolean, cursorPolicy?: CursorPolicy): Promise<ActionResult>;
61
+ /**
62
+ * Type text, optionally clicking a target first.
63
+ *
64
+ * @param backend - BrowserBackend implementation
65
+ * @param text - Text to type
66
+ * @param target - Optional click target before typing (BBox, dict, or tuple)
67
+ * @param clearFirst - If true, select all and delete before typing
68
+ * @returns ActionResult with success status
69
+ *
70
+ * @example
71
+ * // Type into focused element
72
+ * await typeText(backend, 'Hello World');
73
+ *
74
+ * // Click input then type
75
+ * await typeText(backend, 'search query', searchBox.bbox);
76
+ *
77
+ * // Clear and type
78
+ * await typeText(backend, 'new value', input.bbox, true);
79
+ */
80
+ export declare function typeText(backend: BrowserBackend, text: string, target?: ClickTarget, clearFirst?: boolean): Promise<ActionResult>;
81
+ /**
82
+ * Scroll the page or element.
83
+ *
84
+ * @param backend - BrowserBackend implementation
85
+ * @param deltaY - Scroll amount (positive=down, negative=up)
86
+ * @param target - Optional position for scroll (defaults to viewport center)
87
+ * @returns ActionResult with success status
88
+ *
89
+ * @example
90
+ * // Scroll down 300px
91
+ * await scroll(backend, 300);
92
+ *
93
+ * // Scroll up 500px
94
+ * await scroll(backend, -500);
95
+ *
96
+ * // Scroll at specific position
97
+ * await scroll(backend, 200, [500, 300]);
98
+ */
99
+ export declare function scroll(backend: BrowserBackend, deltaY?: number, target?: ClickTarget): Promise<ActionResult>;
100
+ /**
101
+ * Scroll element into view using JavaScript scrollIntoView.
102
+ *
103
+ * @param backend - BrowserBackend implementation
104
+ * @param elementId - Element ID from snapshot (requires sentience_registry)
105
+ * @param behavior - Scroll behavior
106
+ * @param block - Vertical alignment
107
+ * @returns ActionResult with success status
108
+ */
109
+ export declare function scrollToElement(backend: BrowserBackend, elementId: number, behavior?: ScrollBehavior, block?: ScrollBlock): Promise<ActionResult>;
110
+ /**
111
+ * Wait for page to reach stable state.
112
+ *
113
+ * @param backend - BrowserBackend implementation
114
+ * @param state - Target document.readyState
115
+ * @param timeoutMs - Maximum wait time
116
+ * @returns ActionResult with success status
117
+ */
118
+ export declare function waitForStable(backend: BrowserBackend, state?: 'interactive' | 'complete', timeoutMs?: number): Promise<ActionResult>;
119
+ //# sourceMappingURL=actions.d.ts.map