Skip to content

Commit d37b76e

Browse files
authored
Merge pull request #62 from SentienceAPI/include_goal
include goal in snapshot call
2 parents c3e863a + c71fce2 commit d37b76e

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
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.0",
3+
"version": "0.90.1",
44
"description": "TypeScript SDK for Sentience AI Agent Browser Automation",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/agent.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ export class SentienceAgent {
159159
// 1. OBSERVE: Get refined semantic snapshot
160160
const startTime = Date.now();
161161

162-
const snapOpts = snapshotOptions || {};
163-
if (!snapOpts.limit) {
164-
snapOpts.limit = this.snapshotLimit;
165-
}
162+
const snapOpts = {
163+
...snapshotOptions,
164+
goal: snapshotOptions?.goal ?? goal,
165+
limit: snapshotOptions?.limit || this.snapshotLimit,
166+
};
166167

167168
const snap = await snapshot(this.browser, snapOpts);
168169

src/snapshot.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface SnapshotOptions {
1818
use_api?: boolean; // Force use of server-side API if True, local extension if False
1919
save_trace?: boolean; // Save raw_elements to JSON for benchmarking/training
2020
trace_path?: string; // Path to save trace file (default: "trace_{timestamp}.json")
21+
goal?: string; // Optional goal/task description for the snapshot
2122
}
2223

2324
/**
@@ -165,6 +166,7 @@ async function snapshotViaApi(
165166
raw_elements: rawResult.raw_elements || [], // Raw data needed for server processing
166167
url: rawResult.url || '',
167168
viewport: rawResult.viewport,
169+
goal: options.goal, // Optional goal/task description
168170
options: {
169171
limit: options.limit,
170172
filter: options.filter,

tests/snapshot.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,33 @@ describe('Snapshot', () => {
4545
await browser.close();
4646
}
4747
}, 60000); // 60 seconds - browser startup can be slow
48+
49+
it('should accept goal parameter', async () => {
50+
const browser = await createTestBrowser();
51+
52+
try {
53+
await browser.getPage().goto('https://example.com');
54+
await browser.getPage().waitForLoadState('networkidle');
55+
56+
// Test snapshot with goal
57+
const snap = await snapshot(browser, { goal: 'Find the main heading' });
58+
59+
expect(snap.status).toBe('success');
60+
expect(snap.url).toContain('example.com');
61+
expect(snap.elements.length).toBeGreaterThan(0);
62+
63+
// Verify snapshot works normally with goal parameter
64+
expect(snap.elements[0].id).toBeGreaterThanOrEqual(0);
65+
if (snap.elements.length > 0) {
66+
const element = snap.elements[0];
67+
expect(element.bbox.x).toBeGreaterThanOrEqual(0);
68+
expect(element.bbox.y).toBeGreaterThanOrEqual(0);
69+
expect(element.bbox.width).toBeGreaterThan(0);
70+
expect(element.bbox.height).toBeGreaterThan(0);
71+
}
72+
} finally {
73+
await browser.close();
74+
}
75+
}, 60000); // 60 seconds - browser startup can be slow
4876
});
4977

0 commit comments

Comments
 (0)