Skip to content

Commit 18d42ec

Browse files
author
Sentience Dev
committed
Merge pull request #79 from SentienceAPI/rerank_support
support for reranker
2 parents be2631d + f7fa1bb commit 18d42ec

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sentienceapi",
3-
"version": "0.90.12",
3+
"version": "0.90.14",
44
"description": "TypeScript SDK for Sentience AI Agent Browser Automation",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export interface Element {
3030
in_viewport: boolean;
3131
is_occluded: boolean;
3232
z_index: number;
33+
34+
// ML reranking metadata (optional - can be absent or null)
35+
rerank_index?: number; // 0-based, The rank after ML reranking
36+
heuristic_index?: number; // 0-based, Where it would have been without ML
37+
ml_probability?: number; // Confidence score from ONNX model (0.0 - 1.0)
38+
ml_score?: number; // Raw logit score (optional, for debugging)
3339
}
3440

3541
export interface Snapshot {

tests/snapshot.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,69 @@ describe('Snapshot', () => {
7575
}, 60000); // 60 seconds - browser startup can be slow
7676
});
7777

78+
describe('Element ML Fields', () => {
79+
it('should accept elements without ML reranking fields', () => {
80+
const element = {
81+
id: 1,
82+
role: 'button',
83+
text: 'Click me',
84+
importance: 100,
85+
bbox: { x: 10, y: 20, width: 100, height: 50 },
86+
visual_cues: { is_primary: true, background_color_name: 'blue', is_clickable: true },
87+
in_viewport: true,
88+
is_occluded: false,
89+
z_index: 0,
90+
};
91+
92+
expect(element.id).toBe(1);
93+
expect(element).not.toHaveProperty('rerank_index');
94+
expect(element).not.toHaveProperty('heuristic_index');
95+
expect(element).not.toHaveProperty('ml_probability');
96+
expect(element).not.toHaveProperty('ml_score');
97+
});
98+
99+
it('should accept elements with ML reranking fields', () => {
100+
const element = {
101+
id: 2,
102+
role: 'link',
103+
text: 'Learn more',
104+
importance: 80,
105+
bbox: { x: 15, y: 25, width: 120, height: 40 },
106+
visual_cues: { is_primary: false, background_color_name: 'white', is_clickable: true },
107+
in_viewport: true,
108+
is_occluded: false,
109+
z_index: 1,
110+
rerank_index: 0,
111+
heuristic_index: 5,
112+
ml_probability: 0.95,
113+
ml_score: 2.34,
114+
};
115+
116+
expect(element.rerank_index).toBe(0);
117+
expect(element.heuristic_index).toBe(5);
118+
expect(element.ml_probability).toBe(0.95);
119+
expect(element.ml_score).toBe(2.34);
120+
});
121+
122+
it('should accept elements with partial ML fields', () => {
123+
const element = {
124+
id: 3,
125+
role: 'textbox',
126+
text: null,
127+
importance: 60,
128+
bbox: { x: 20, y: 30, width: 200, height: 30 },
129+
visual_cues: { is_primary: false, background_color_name: null, is_clickable: true },
130+
in_viewport: true,
131+
is_occluded: false,
132+
z_index: 0,
133+
rerank_index: 1,
134+
ml_probability: 0.87,
135+
};
136+
137+
expect(element.rerank_index).toBe(1);
138+
expect(element).not.toHaveProperty('heuristic_index');
139+
expect(element.ml_probability).toBe(0.87);
140+
expect(element).not.toHaveProperty('ml_score');
141+
});
142+
});
143+

0 commit comments

Comments
 (0)