sentienceapi 0.93.0 → 0.95.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.
- package/README.md +44 -3
- package/dist/asserts/expect.d.ts +159 -0
- package/dist/asserts/expect.d.ts.map +1 -0
- package/dist/asserts/expect.js +547 -0
- package/dist/asserts/expect.js.map +1 -0
- package/dist/asserts/index.d.ts +58 -0
- package/dist/asserts/index.d.ts.map +1 -0
- package/dist/asserts/index.js +70 -0
- package/dist/asserts/index.js.map +1 -0
- package/dist/asserts/query.d.ts +199 -0
- package/dist/asserts/query.d.ts.map +1 -0
- package/dist/asserts/query.js +288 -0
- package/dist/asserts/query.js.map +1 -0
- package/dist/backends/actions.d.ts +118 -0
- package/dist/backends/actions.d.ts.map +1 -0
- package/dist/backends/actions.js +262 -0
- package/dist/backends/actions.js.map +1 -0
- package/dist/backends/browser-use-adapter.d.ts +131 -0
- package/dist/backends/browser-use-adapter.d.ts.map +1 -0
- package/dist/backends/browser-use-adapter.js +219 -0
- package/dist/backends/browser-use-adapter.js.map +1 -0
- package/dist/backends/cdp-backend.d.ts +66 -0
- package/dist/backends/cdp-backend.d.ts.map +1 -0
- package/dist/backends/cdp-backend.js +273 -0
- package/dist/backends/cdp-backend.js.map +1 -0
- package/dist/backends/index.d.ts +80 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +100 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/protocol.d.ts +156 -0
- package/dist/backends/protocol.d.ts.map +1 -0
- package/dist/backends/protocol.js +16 -0
- package/dist/backends/protocol.js.map +1 -0
- package/dist/backends/sentience-context.d.ts +136 -0
- package/dist/backends/sentience-context.d.ts.map +1 -0
- package/dist/backends/sentience-context.js +354 -0
- package/dist/backends/sentience-context.js.map +1 -0
- package/dist/backends/snapshot.d.ts +184 -0
- package/dist/backends/snapshot.d.ts.map +1 -0
- package/dist/backends/snapshot.js +360 -0
- package/dist/backends/snapshot.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/dist/snapshot.d.ts +2 -0
- package/dist/snapshot.d.ts.map +1 -1
- package/dist/snapshot.js +50 -4
- package/dist/snapshot.js.map +1 -1
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/grid-utils.d.ts +37 -0
- package/dist/utils/grid-utils.d.ts.map +1 -0
- package/dist/utils/grid-utils.js +283 -0
- package/dist/utils/grid-utils.js.map +1 -0
- package/package.json +3 -1
- package/src/extension/content.js +35 -0
- package/src/extension/injected_api.js +9 -0
- package/src/extension/manifest.json +1 -1
- package/src/extension/pkg/sentience_core_bg.wasm +0 -0
- package/src/extension/release.json +47 -48
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Sentience TypeScript SDK
|
|
2
2
|
|
|
3
|
-
**Semantic
|
|
3
|
+
**Semantic snapshots and Jest-style assertions for reliable AI web agents with time-travel traces**
|
|
4
4
|
|
|
5
5
|
## 📦 Installation
|
|
6
6
|
|
|
@@ -19,6 +19,49 @@ npm install
|
|
|
19
19
|
npm run build
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## Jest for AI Web Agent
|
|
23
|
+
|
|
24
|
+
### Semantic snapshots and assertions that let agents act, verify, and know when they're done.
|
|
25
|
+
|
|
26
|
+
Use `AgentRuntime` to add Jest-style assertions to your agent loops. Verify browser state, check task completion, and get clear feedback on what's working:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { SentienceBrowser, AgentRuntime, urlContains, exists, allOf } from 'sentienceapi';
|
|
30
|
+
import { createTracer } from 'sentienceapi';
|
|
31
|
+
import { Page } from 'playwright';
|
|
32
|
+
|
|
33
|
+
// Create browser and tracer
|
|
34
|
+
const browser = await SentienceBrowser.create({ apiKey: process.env.SENTIENCE_API_KEY });
|
|
35
|
+
const tracer = await createTracer({ runId: 'my-run', uploadTrace: false });
|
|
36
|
+
|
|
37
|
+
// Create browser adapter for AgentRuntime
|
|
38
|
+
const browserAdapter = {
|
|
39
|
+
snapshot: async (_page: Page, options?: Record<string, any>) => {
|
|
40
|
+
return await browser.snapshot(options);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const runtime = new AgentRuntime(browserAdapter, browser.getPage(), tracer);
|
|
44
|
+
|
|
45
|
+
// Navigate and take snapshot
|
|
46
|
+
await browser.getPage().goto('https://example.com');
|
|
47
|
+
runtime.beginStep('Verify page loaded');
|
|
48
|
+
await runtime.snapshot();
|
|
49
|
+
|
|
50
|
+
// Run assertions (Jest-style)
|
|
51
|
+
runtime.assert(urlContains('example.com'), 'on_correct_domain');
|
|
52
|
+
runtime.assert(exists('role=heading'), 'has_heading');
|
|
53
|
+
runtime.assert(allOf([exists('role=button'), exists('role=link')]), 'has_interactive_elements');
|
|
54
|
+
|
|
55
|
+
// Check task completion
|
|
56
|
+
if (runtime.assertDone(exists("text~'Example'"), 'task_complete')) {
|
|
57
|
+
console.log('✅ Task completed!');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(`Task done: ${runtime.isTaskDone}`);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**See example:** [examples/agent-runtime-verification.ts](examples/agent-runtime-verification.ts)
|
|
64
|
+
|
|
22
65
|
## 🚀 Quick Start: Choose Your Abstraction Level
|
|
23
66
|
|
|
24
67
|
Sentience SDK offers **4 levels of abstraction** - choose based on your needs:
|
|
@@ -142,8 +185,6 @@ await browser.close();
|
|
|
142
185
|
|
|
143
186
|
---
|
|
144
187
|
|
|
145
|
-
## 🆕 What's New (2026-01-06)
|
|
146
|
-
|
|
147
188
|
### Human-like Typing
|
|
148
189
|
|
|
149
190
|
Add realistic delays between keystrokes to mimic human typing:
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expectation builder for assertion DSL.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the expect() builder that creates fluent assertions
|
|
5
|
+
* which compile to existing Predicate objects.
|
|
6
|
+
*
|
|
7
|
+
* Key classes:
|
|
8
|
+
* - ExpectBuilder: Fluent builder for element-based assertions
|
|
9
|
+
* - EventuallyConfig: Configuration for .eventually() retry logic
|
|
10
|
+
*
|
|
11
|
+
* The expect() function is the main entry point. It returns a builder that
|
|
12
|
+
* can be chained with matchers:
|
|
13
|
+
* expect(E({ role: "button" })).toExist()
|
|
14
|
+
* expect(E({ textContains: "Error" })).notToExist()
|
|
15
|
+
* expect.textPresent("Welcome")
|
|
16
|
+
*
|
|
17
|
+
* All builders compile to Predicate functions compatible with AgentRuntime.assert().
|
|
18
|
+
*/
|
|
19
|
+
import { Predicate, AssertOutcome, AssertContext } from '../verification';
|
|
20
|
+
import { ElementQuery, MultiQuery, MultiTextPredicate } from './query';
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for .eventually() retry logic.
|
|
23
|
+
*/
|
|
24
|
+
export interface EventuallyConfig {
|
|
25
|
+
/** Max time to wait (milliseconds, default 10000) */
|
|
26
|
+
timeout?: number;
|
|
27
|
+
/** Interval between retries (milliseconds, default 200) */
|
|
28
|
+
poll?: number;
|
|
29
|
+
/** Max number of retry attempts (default 3) */
|
|
30
|
+
maxRetries?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Fluent builder for element-based assertions.
|
|
34
|
+
*
|
|
35
|
+
* Created by expect(E(...)) or expect(inDominantList().nth(k)).
|
|
36
|
+
*
|
|
37
|
+
* Methods return Predicate functions that can be passed to runtime.assert().
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* expect(E({ role: "button" })).toExist()
|
|
41
|
+
* expect(E({ textContains: "Error" })).notToExist()
|
|
42
|
+
* expect(E({ role: "link" })).toBeVisible()
|
|
43
|
+
*/
|
|
44
|
+
export declare class ExpectBuilder {
|
|
45
|
+
private _query;
|
|
46
|
+
constructor(query: ElementQuery | MultiQuery | MultiTextPredicate);
|
|
47
|
+
/**
|
|
48
|
+
* Assert that at least one element matches the query.
|
|
49
|
+
*
|
|
50
|
+
* @returns Predicate function for use with runtime.assert()
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* await runtime.assert(
|
|
54
|
+
* expect(E({ role: "button", textContains: "Save" })).toExist(),
|
|
55
|
+
* "save_button_exists"
|
|
56
|
+
* );
|
|
57
|
+
*/
|
|
58
|
+
toExist(): Predicate;
|
|
59
|
+
/**
|
|
60
|
+
* Assert that NO elements match the query.
|
|
61
|
+
*
|
|
62
|
+
* Useful for asserting absence of error messages, loading indicators, etc.
|
|
63
|
+
*
|
|
64
|
+
* @returns Predicate function for use with runtime.assert()
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* await runtime.assert(
|
|
68
|
+
* expect(E({ textContains: "Error" })).notToExist(),
|
|
69
|
+
* "no_error_message"
|
|
70
|
+
* );
|
|
71
|
+
*/
|
|
72
|
+
notToExist(): Predicate;
|
|
73
|
+
/**
|
|
74
|
+
* Assert that element exists AND is visible (in_viewport=true, is_occluded=false).
|
|
75
|
+
*
|
|
76
|
+
* @returns Predicate function for use with runtime.assert()
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* await runtime.assert(
|
|
80
|
+
* expect(E({ textContains: "Checkout" })).toBeVisible(),
|
|
81
|
+
* "checkout_button_visible"
|
|
82
|
+
* );
|
|
83
|
+
*/
|
|
84
|
+
toBeVisible(): Predicate;
|
|
85
|
+
/**
|
|
86
|
+
* Assert that element's text contains the specified substring.
|
|
87
|
+
*
|
|
88
|
+
* @param text - Substring to search for (case-insensitive)
|
|
89
|
+
* @returns Predicate function for use with runtime.assert()
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* await runtime.assert(
|
|
93
|
+
* expect(inDominantList().nth(0)).toHaveTextContains("Show HN"),
|
|
94
|
+
* "first_item_is_show_hn"
|
|
95
|
+
* );
|
|
96
|
+
*/
|
|
97
|
+
toHaveTextContains(text: string): Predicate;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Main entry point for the assertion DSL.
|
|
101
|
+
*
|
|
102
|
+
* Use as a function to create element-based assertions:
|
|
103
|
+
* expect(E({ role: "button" })).toExist()
|
|
104
|
+
*
|
|
105
|
+
* Use static methods for global assertions:
|
|
106
|
+
* expect.textPresent("Welcome")
|
|
107
|
+
* expect.noText("Error")
|
|
108
|
+
*/
|
|
109
|
+
export declare const expect: ((query: ElementQuery | MultiQuery | MultiTextPredicate) => ExpectBuilder) & {
|
|
110
|
+
textPresent: (text: string) => Predicate;
|
|
111
|
+
noText: (text: string) => Predicate;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Wrapper that adds retry logic to a predicate.
|
|
115
|
+
*
|
|
116
|
+
* Created by withEventually(). Provides an async evaluate() method
|
|
117
|
+
* that retries the predicate with fresh snapshots.
|
|
118
|
+
*
|
|
119
|
+
* Note: TypeScript uses milliseconds for timeout/poll.
|
|
120
|
+
*/
|
|
121
|
+
export declare class EventuallyWrapper {
|
|
122
|
+
private _predicate;
|
|
123
|
+
private _config;
|
|
124
|
+
constructor(predicate: Predicate, config?: EventuallyConfig);
|
|
125
|
+
/**
|
|
126
|
+
* Evaluate predicate with retry logic.
|
|
127
|
+
*
|
|
128
|
+
* @param ctx - Initial assertion context
|
|
129
|
+
* @param snapshotFn - Async function to take fresh snapshots
|
|
130
|
+
* @returns Promise resolving to AssertOutcome
|
|
131
|
+
*/
|
|
132
|
+
evaluate(ctx: AssertContext, snapshotFn: () => Promise<AssertContext['snapshot']>): Promise<AssertOutcome>;
|
|
133
|
+
private sleep;
|
|
134
|
+
/** Get the configured timeout in milliseconds */
|
|
135
|
+
get timeout(): number;
|
|
136
|
+
/** Get the configured poll interval in milliseconds */
|
|
137
|
+
get poll(): number;
|
|
138
|
+
/** Get the configured max retries */
|
|
139
|
+
get maxRetries(): number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Wrap a predicate with retry logic.
|
|
143
|
+
*
|
|
144
|
+
* This is the TypeScript API for .eventually(). Returns a wrapper
|
|
145
|
+
* that provides an async evaluate() method for use with the runtime.
|
|
146
|
+
*
|
|
147
|
+
* @param predicate - Predicate to wrap
|
|
148
|
+
* @param config - Retry configuration (timeout/poll in milliseconds)
|
|
149
|
+
* @returns EventuallyWrapper with async evaluate() method
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* const wrapper = withEventually(
|
|
153
|
+
* expect(E({ role: "button" })).toExist(),
|
|
154
|
+
* { timeout: 5000, maxRetries: 10 }
|
|
155
|
+
* );
|
|
156
|
+
* const result = await wrapper.evaluate(ctx, runtime.snapshot);
|
|
157
|
+
*/
|
|
158
|
+
export declare function withEventually(predicate: Predicate, config?: EventuallyConfig): EventuallyWrapper;
|
|
159
|
+
//# sourceMappingURL=expect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/asserts/expect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAOvE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAoCD;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAiD;gBAEnD,KAAK,EAAE,YAAY,GAAG,UAAU,GAAG,kBAAkB;IAIjE;;;;;;;;;;OAUG;IACH,OAAO,IAAI,SAAS;IA+BpB;;;;;;;;;;;;OAYG;IACH,UAAU,IAAI,SAAS;IAiCvB;;;;;;;;;;OAUG;IACH,WAAW,IAAI,SAAS;IAgDxB;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;CA8C5C;AAqID;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,WACT,YAAY,GAAG,UAAU,GAAG,kBAAkB;wBAEhC,MAAM;mBACX,MAAM;CAExB,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,OAAO,CAA6B;gBAEhC,SAAS,EAAE,SAAS,EAAE,MAAM,GAAE,gBAAqB;IAS/D;;;;;;OAMG;IACG,QAAQ,CACZ,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,GACnD,OAAO,CAAC,aAAa,CAAC;IA8EzB,OAAO,CAAC,KAAK;IAIb,iDAAiD;IACjD,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,uDAAuD;IACvD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,qCAAqC;IACrC,IAAI,UAAU,IAAI,MAAM,CAEvB;CACF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,gBAAgB,GAAG,iBAAiB,CAEjG"}
|