sentienceapi 0.90.1
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/LICENSE.md +43 -0
- package/README.md +946 -0
- package/dist/actions.d.ts +54 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +349 -0
- package/dist/actions.js.map +1 -0
- package/dist/agent.d.ts +157 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +437 -0
- package/dist/agent.js.map +1 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +622 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +174 -0
- package/dist/cli.js.map +1 -0
- package/dist/conversational-agent.d.ts +123 -0
- package/dist/conversational-agent.d.ts.map +1 -0
- package/dist/conversational-agent.js +327 -0
- package/dist/conversational-agent.js.map +1 -0
- package/dist/expect.d.ts +16 -0
- package/dist/expect.d.ts.map +1 -0
- package/dist/expect.js +66 -0
- package/dist/expect.js.map +1 -0
- package/dist/generator.d.ts +16 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +205 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/dist/inspector.d.ts +13 -0
- package/dist/inspector.d.ts.map +1 -0
- package/dist/inspector.js +147 -0
- package/dist/inspector.js.map +1 -0
- package/dist/llm-provider.d.ts +60 -0
- package/dist/llm-provider.d.ts.map +1 -0
- package/dist/llm-provider.js +106 -0
- package/dist/llm-provider.js.map +1 -0
- package/dist/query.d.ts +8 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +337 -0
- package/dist/query.js.map +1 -0
- package/dist/read.d.ts +40 -0
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +86 -0
- package/dist/read.js.map +1 -0
- package/dist/recorder.d.ts +44 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +256 -0
- package/dist/recorder.js.map +1 -0
- package/dist/screenshot.d.ts +17 -0
- package/dist/screenshot.d.ts.map +1 -0
- package/dist/screenshot.js +37 -0
- package/dist/screenshot.js.map +1 -0
- package/dist/snapshot.d.ts +23 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +187 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/tracing/cloud-sink.d.ts +74 -0
- package/dist/tracing/cloud-sink.d.ts.map +1 -0
- package/dist/tracing/cloud-sink.js +262 -0
- package/dist/tracing/cloud-sink.js.map +1 -0
- package/dist/tracing/index.d.ts +12 -0
- package/dist/tracing/index.d.ts.map +1 -0
- package/dist/tracing/index.js +28 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/jsonl-sink.d.ts +41 -0
- package/dist/tracing/jsonl-sink.d.ts.map +1 -0
- package/dist/tracing/jsonl-sink.js +168 -0
- package/dist/tracing/jsonl-sink.js.map +1 -0
- package/dist/tracing/sink.d.ts +24 -0
- package/dist/tracing/sink.d.ts.map +1 -0
- package/dist/tracing/sink.js +15 -0
- package/dist/tracing/sink.js.map +1 -0
- package/dist/tracing/tracer-factory.d.ts +57 -0
- package/dist/tracing/tracer-factory.d.ts.map +1 -0
- package/dist/tracing/tracer-factory.js +274 -0
- package/dist/tracing/tracer-factory.js.map +1 -0
- package/dist/tracing/tracer.d.ts +74 -0
- package/dist/tracing/tracer.d.ts.map +1 -0
- package/dist/tracing/tracer.js +131 -0
- package/dist/tracing/tracer.js.map +1 -0
- package/dist/tracing/types.d.ts +63 -0
- package/dist/tracing/types.d.ts.map +1 -0
- package/dist/tracing/types.js +8 -0
- package/dist/tracing/types.js.map +1 -0
- package/dist/types.d.ts +110 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +29 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +74 -0
- package/dist/utils.js.map +1 -0
- package/dist/wait.d.ts +20 -0
- package/dist/wait.d.ts.map +1 -0
- package/dist/wait.js +63 -0
- package/dist/wait.js.map +1 -0
- package/package.json +72 -0
- package/spec/README.md +72 -0
- package/spec/SNAPSHOT_V1.md +208 -0
- package/spec/sdk-types.md +259 -0
- package/spec/snapshot.schema.json +148 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions - matches spec/sdk-types.md
|
|
3
|
+
*/
|
|
4
|
+
export interface BBox {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
export interface Viewport {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
}
|
|
14
|
+
export interface VisualCues {
|
|
15
|
+
is_primary: boolean;
|
|
16
|
+
background_color_name: string | null;
|
|
17
|
+
is_clickable: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface Element {
|
|
20
|
+
id: number;
|
|
21
|
+
role: string;
|
|
22
|
+
text: string | null;
|
|
23
|
+
importance: number;
|
|
24
|
+
bbox: BBox;
|
|
25
|
+
visual_cues: VisualCues;
|
|
26
|
+
in_viewport: boolean;
|
|
27
|
+
is_occluded: boolean;
|
|
28
|
+
z_index: number;
|
|
29
|
+
}
|
|
30
|
+
export interface Snapshot {
|
|
31
|
+
status: "success" | "error";
|
|
32
|
+
timestamp?: string;
|
|
33
|
+
url: string;
|
|
34
|
+
viewport?: Viewport;
|
|
35
|
+
elements: Element[];
|
|
36
|
+
screenshot?: string;
|
|
37
|
+
screenshot_format?: "png" | "jpeg";
|
|
38
|
+
error?: string;
|
|
39
|
+
requires_license?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface ActionResult {
|
|
42
|
+
success: boolean;
|
|
43
|
+
duration_ms: number;
|
|
44
|
+
outcome?: "navigated" | "dom_updated" | "no_change" | "error";
|
|
45
|
+
url_changed?: boolean;
|
|
46
|
+
snapshot_after?: Snapshot;
|
|
47
|
+
error?: {
|
|
48
|
+
code: string;
|
|
49
|
+
reason: string;
|
|
50
|
+
recovery_hint?: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export interface WaitResult {
|
|
54
|
+
found: boolean;
|
|
55
|
+
element?: Element;
|
|
56
|
+
duration_ms: number;
|
|
57
|
+
timeout: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface QuerySelectorObject {
|
|
60
|
+
role?: string;
|
|
61
|
+
text?: string;
|
|
62
|
+
name?: string;
|
|
63
|
+
clickable?: boolean;
|
|
64
|
+
isPrimary?: boolean;
|
|
65
|
+
importance?: number | {
|
|
66
|
+
min?: number;
|
|
67
|
+
max?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export type QuerySelector = string | QuerySelectorObject;
|
|
71
|
+
/**
|
|
72
|
+
* Cookie definition for storage state injection.
|
|
73
|
+
* Matches Playwright's cookie format for storage_state.
|
|
74
|
+
*/
|
|
75
|
+
export interface Cookie {
|
|
76
|
+
name: string;
|
|
77
|
+
value: string;
|
|
78
|
+
domain: string;
|
|
79
|
+
path?: string;
|
|
80
|
+
expires?: number;
|
|
81
|
+
httpOnly?: boolean;
|
|
82
|
+
secure?: boolean;
|
|
83
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* LocalStorage item for a specific origin.
|
|
87
|
+
* Playwright stores localStorage as an array of {name, value} objects.
|
|
88
|
+
*/
|
|
89
|
+
export interface LocalStorageItem {
|
|
90
|
+
name: string;
|
|
91
|
+
value: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Storage state for a specific origin (localStorage).
|
|
95
|
+
* Represents localStorage data for a single domain.
|
|
96
|
+
*/
|
|
97
|
+
export interface OriginStorage {
|
|
98
|
+
origin: string;
|
|
99
|
+
localStorage: LocalStorageItem[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Complete browser storage state (cookies + localStorage).
|
|
103
|
+
* This is the format used by Playwright's storage_state() method.
|
|
104
|
+
* Can be saved to/loaded from JSON files for session injection.
|
|
105
|
+
*/
|
|
106
|
+
export interface StorageState {
|
|
107
|
+
cookies: Cookie[];
|
|
108
|
+
origins: OriginStorage[];
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for Sentience SDK
|
|
3
|
+
*/
|
|
4
|
+
import { BrowserContext } from 'playwright';
|
|
5
|
+
/**
|
|
6
|
+
* Save current browser storage state (cookies + localStorage) to a file.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for capturing a logged-in session to reuse later.
|
|
9
|
+
*
|
|
10
|
+
* @param context - Playwright BrowserContext
|
|
11
|
+
* @param filePath - Path to save the storage state JSON file
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { SentienceBrowser, saveStorageState } from 'sentience-ts';
|
|
16
|
+
*
|
|
17
|
+
* const browser = new SentienceBrowser();
|
|
18
|
+
* await browser.start();
|
|
19
|
+
*
|
|
20
|
+
* // User logs in manually or via agent
|
|
21
|
+
* await browser.getPage().goto('https://example.com');
|
|
22
|
+
* // ... login happens ...
|
|
23
|
+
*
|
|
24
|
+
* // Save session for later
|
|
25
|
+
* await saveStorageState(browser.getContext(), 'auth.json');
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function saveStorageState(context: BrowserContext, filePath: string): Promise<void>;
|
|
29
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for Sentience SDK
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.saveStorageState = saveStorageState;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
/**
|
|
43
|
+
* Save current browser storage state (cookies + localStorage) to a file.
|
|
44
|
+
*
|
|
45
|
+
* This is useful for capturing a logged-in session to reuse later.
|
|
46
|
+
*
|
|
47
|
+
* @param context - Playwright BrowserContext
|
|
48
|
+
* @param filePath - Path to save the storage state JSON file
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { SentienceBrowser, saveStorageState } from 'sentience-ts';
|
|
53
|
+
*
|
|
54
|
+
* const browser = new SentienceBrowser();
|
|
55
|
+
* await browser.start();
|
|
56
|
+
*
|
|
57
|
+
* // User logs in manually or via agent
|
|
58
|
+
* await browser.getPage().goto('https://example.com');
|
|
59
|
+
* // ... login happens ...
|
|
60
|
+
*
|
|
61
|
+
* // Save session for later
|
|
62
|
+
* await saveStorageState(browser.getContext(), 'auth.json');
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
async function saveStorageState(context, filePath) {
|
|
66
|
+
const storageState = await context.storageState();
|
|
67
|
+
const dir = path.dirname(filePath);
|
|
68
|
+
if (!fs.existsSync(dir)) {
|
|
69
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
70
|
+
}
|
|
71
|
+
fs.writeFileSync(filePath, JSON.stringify(storageState, null, 2));
|
|
72
|
+
console.log(`✅ [Sentience] Saved storage state to ${filePath}`);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BH,4CAWC;AArCD,uCAAyB;AACzB,2CAA6B;AAE7B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACI,KAAK,UAAU,gBAAgB,CACpC,OAAuB,EACvB,QAAgB;IAEhB,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAClE,OAAO,CAAC,GAAG,CAAC,wCAAwC,QAAQ,EAAE,CAAC,CAAC;AAClE,CAAC"}
|
package/dist/wait.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wait functionality
|
|
3
|
+
*/
|
|
4
|
+
import { SentienceBrowser } from './browser';
|
|
5
|
+
import { WaitResult, QuerySelector } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Wait for element matching selector to appear
|
|
8
|
+
*
|
|
9
|
+
* @param browser - SentienceBrowser instance
|
|
10
|
+
* @param selector - String DSL or dict query
|
|
11
|
+
* @param timeout - Maximum time to wait (milliseconds). Default: 10000ms (10 seconds)
|
|
12
|
+
* @param interval - Polling interval (milliseconds). If undefined, auto-detects:
|
|
13
|
+
* - 250ms for local extension (useApi=false, fast)
|
|
14
|
+
* - 1500ms for remote API (useApi=true or default, network latency)
|
|
15
|
+
* @param useApi - Force use of server-side API if true, local extension if false.
|
|
16
|
+
* If undefined, uses API if apiKey is set, otherwise uses local extension.
|
|
17
|
+
* @returns WaitResult
|
|
18
|
+
*/
|
|
19
|
+
export declare function waitFor(browser: SentienceBrowser, selector: QuerySelector, timeout?: number, interval?: number, useApi?: boolean): Promise<WaitResult>;
|
|
20
|
+
//# sourceMappingURL=wait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAW,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7D;;;;;;;;;;;;GAYG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,aAAa,EACvB,OAAO,GAAE,MAAc,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,UAAU,CAAC,CA6CrB"}
|
package/dist/wait.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Wait functionality
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.waitFor = waitFor;
|
|
7
|
+
const snapshot_1 = require("./snapshot");
|
|
8
|
+
const query_1 = require("./query");
|
|
9
|
+
/**
|
|
10
|
+
* Wait for element matching selector to appear
|
|
11
|
+
*
|
|
12
|
+
* @param browser - SentienceBrowser instance
|
|
13
|
+
* @param selector - String DSL or dict query
|
|
14
|
+
* @param timeout - Maximum time to wait (milliseconds). Default: 10000ms (10 seconds)
|
|
15
|
+
* @param interval - Polling interval (milliseconds). If undefined, auto-detects:
|
|
16
|
+
* - 250ms for local extension (useApi=false, fast)
|
|
17
|
+
* - 1500ms for remote API (useApi=true or default, network latency)
|
|
18
|
+
* @param useApi - Force use of server-side API if true, local extension if false.
|
|
19
|
+
* If undefined, uses API if apiKey is set, otherwise uses local extension.
|
|
20
|
+
* @returns WaitResult
|
|
21
|
+
*/
|
|
22
|
+
async function waitFor(browser, selector, timeout = 10000, interval, useApi) {
|
|
23
|
+
// Auto-detect optimal interval based on API usage
|
|
24
|
+
if (interval === undefined) {
|
|
25
|
+
// Determine if using API
|
|
26
|
+
const willUseApi = useApi !== undefined
|
|
27
|
+
? useApi
|
|
28
|
+
: (browser.getApiKey() !== undefined);
|
|
29
|
+
if (willUseApi) {
|
|
30
|
+
interval = 1500; // Longer interval for API calls (network latency)
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
interval = 250; // Shorter interval for local extension (fast)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const startTime = Date.now();
|
|
37
|
+
while (Date.now() - startTime < timeout) {
|
|
38
|
+
// Take snapshot (may be local extension or remote API)
|
|
39
|
+
const snap = await (0, snapshot_1.snapshot)(browser, { use_api: useApi });
|
|
40
|
+
// Try to find element
|
|
41
|
+
const element = (0, query_1.find)(snap, selector);
|
|
42
|
+
if (element) {
|
|
43
|
+
const durationMs = Date.now() - startTime;
|
|
44
|
+
return {
|
|
45
|
+
found: true,
|
|
46
|
+
element,
|
|
47
|
+
duration_ms: durationMs,
|
|
48
|
+
timeout: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Wait before next poll
|
|
52
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
53
|
+
}
|
|
54
|
+
// Timeout
|
|
55
|
+
const durationMs = Date.now() - startTime;
|
|
56
|
+
return {
|
|
57
|
+
found: false,
|
|
58
|
+
element: undefined,
|
|
59
|
+
duration_ms: durationMs,
|
|
60
|
+
timeout: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=wait.js.map
|
package/dist/wait.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait.js","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAoBH,0BAmDC;AAnED,yCAAsC;AACtC,mCAA+B;AAE/B;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,OAAO,CAC3B,OAAyB,EACzB,QAAuB,EACvB,UAAkB,KAAK,EACvB,QAAiB,EACjB,MAAgB;IAEhB,kDAAkD;IAClD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,yBAAyB;QACzB,MAAM,UAAU,GAAG,MAAM,KAAK,SAAS;YACrC,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,SAAS,CAAC,CAAC;QACxC,IAAI,UAAU,EAAE,CAAC;YACf,QAAQ,GAAG,IAAI,CAAC,CAAC,kDAAkD;QACrE,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,GAAG,CAAC,CAAC,8CAA8C;QAChE,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,OAAO,EAAE,CAAC;QACxC,uDAAuD;QACvD,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAE1D,sBAAsB;QACtB,MAAM,OAAO,GAAG,IAAA,YAAI,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAErC,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YAC1C,OAAO;gBACL,KAAK,EAAE,IAAI;gBACX,OAAO;gBACP,WAAW,EAAE,UAAU;gBACvB,OAAO,EAAE,KAAK;aACf,CAAC;QACJ,CAAC;QAED,wBAAwB;QACxB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,UAAU;IACV,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IAC1C,OAAO;QACL,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,SAAS;QAClB,WAAW,EAAE,UAAU;QACvB,OAAO,EAAE,IAAI;KACd,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sentienceapi",
|
|
3
|
+
"version": "0.90.1",
|
|
4
|
+
"description": "TypeScript SDK for Sentience AI Agent Browser Automation",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"prepare": "npm run build",
|
|
11
|
+
"prepublishOnly": "npm test && npm run build",
|
|
12
|
+
"example:hello": "ts-node examples/hello.ts",
|
|
13
|
+
"example:basic": "ts-node examples/basic-agent.ts",
|
|
14
|
+
"example:agent-google": "ts-node examples/agent-google-search.ts",
|
|
15
|
+
"example:agent-amazon": "ts-node examples/agent-amazon-shopping.ts",
|
|
16
|
+
"example:agent-claude": "ts-node examples/agent-with-anthropic.ts",
|
|
17
|
+
"example:conversational-google": "ts-node examples/conversational-google-search.ts",
|
|
18
|
+
"example:conversational-amazon": "ts-node examples/conversational-amazon-shopping.ts",
|
|
19
|
+
"example:tracing": "ts-node examples/agent-with-tracing.ts",
|
|
20
|
+
"example:trace-replay": "ts-node examples/trace-replay-demo.ts",
|
|
21
|
+
"example:cloud-tracing": "ts-node examples/cloud-tracing-agent.ts",
|
|
22
|
+
"cli": "ts-node src/cli.ts"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"sentience": "./dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"playwright": "^1.40.0",
|
|
29
|
+
"turndown": "^7.2.2",
|
|
30
|
+
"uuid": "^9.0.0",
|
|
31
|
+
"zod": "^3.22.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/jest": "^29.5.14",
|
|
35
|
+
"@types/node": "^20.0.0",
|
|
36
|
+
"@types/turndown": "^5.0.3",
|
|
37
|
+
"@types/uuid": "^9.0.0",
|
|
38
|
+
"jest": "^29.0.0",
|
|
39
|
+
"ts-jest": "^29.0.0",
|
|
40
|
+
"ts-node": "^10.9.0",
|
|
41
|
+
"typescript": "^5.0.0"
|
|
42
|
+
},
|
|
43
|
+
"optionalDependencies": {
|
|
44
|
+
"openai": "^4.0.0",
|
|
45
|
+
"@anthropic-ai/sdk": "^0.20.0"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"spec",
|
|
50
|
+
"README.md",
|
|
51
|
+
"LICENSE"
|
|
52
|
+
],
|
|
53
|
+
"keywords": [
|
|
54
|
+
"browser-automation",
|
|
55
|
+
"playwright",
|
|
56
|
+
"ai-agent",
|
|
57
|
+
"web-automation",
|
|
58
|
+
"sentience"
|
|
59
|
+
],
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "https://github.com/SentienceAPI/sentience-ts.git"
|
|
63
|
+
},
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/SentienceAPI/sentience-ts/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/SentienceAPI/sentience-ts#readme",
|
|
68
|
+
"license": "MIT",
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=20.0.0"
|
|
71
|
+
}
|
|
72
|
+
}
|
package/spec/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Sentience API Specification
|
|
2
|
+
|
|
3
|
+
This directory contains the **single source of truth** for the API contract between the Chrome extension and SDKs.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
- **`snapshot.schema.json`** - JSON Schema for snapshot response validation
|
|
8
|
+
- **`SNAPSHOT_V1.md`** - Human-readable snapshot API contract
|
|
9
|
+
- **`sdk-types.md`** - SDK-level type definitions (ActionResult, WaitResult, TraceStep)
|
|
10
|
+
|
|
11
|
+
## Purpose
|
|
12
|
+
|
|
13
|
+
These specifications ensure:
|
|
14
|
+
1. **Consistency**: Both Python and TypeScript SDKs implement the same contract
|
|
15
|
+
2. **Validation**: SDKs can validate extension responses
|
|
16
|
+
3. **Type Safety**: Strong typing in both languages
|
|
17
|
+
4. **Documentation**: Clear reference for developers
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### For SDK Developers
|
|
22
|
+
|
|
23
|
+
1. **Read** `SNAPSHOT_V1.md` for human-readable contract
|
|
24
|
+
2. **Use** `snapshot.schema.json` for JSON Schema validation
|
|
25
|
+
3. **Reference** `sdk-types.md` for SDK-level types
|
|
26
|
+
|
|
27
|
+
### For Extension Developers
|
|
28
|
+
|
|
29
|
+
1. **Ensure** extension output matches `snapshot.schema.json`
|
|
30
|
+
2. **Update** schema when adding new fields
|
|
31
|
+
3. **Version** schema for breaking changes
|
|
32
|
+
|
|
33
|
+
## Versioning
|
|
34
|
+
|
|
35
|
+
- **v1.0.0**: Initial stable version (Day 1)
|
|
36
|
+
- Future versions: Increment major version for breaking changes
|
|
37
|
+
- SDKs should validate version and handle compatibility
|
|
38
|
+
|
|
39
|
+
## Validation
|
|
40
|
+
|
|
41
|
+
Both SDKs should validate extension responses:
|
|
42
|
+
|
|
43
|
+
**Python**:
|
|
44
|
+
```python
|
|
45
|
+
import jsonschema
|
|
46
|
+
from spec.snapshot.schema import load_schema
|
|
47
|
+
|
|
48
|
+
schema = load_schema()
|
|
49
|
+
jsonschema.validate(snapshot_data, schema)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**TypeScript**:
|
|
53
|
+
```typescript
|
|
54
|
+
import Ajv from 'ajv';
|
|
55
|
+
import schema from './spec/snapshot.schema.json';
|
|
56
|
+
|
|
57
|
+
const ajv = new Ajv();
|
|
58
|
+
const validate = ajv.compile(schema);
|
|
59
|
+
validate(snapshot_data);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Testing
|
|
63
|
+
|
|
64
|
+
- Validate against real extension output
|
|
65
|
+
- Test with edge cases (empty pages, many elements, errors)
|
|
66
|
+
- Verify type coercion and defaults
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
**Last Updated**: Day 1 Implementation
|
|
71
|
+
**Status**: ✅ Stable
|
|
72
|
+
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Sentience Snapshot API Contract v1
|
|
2
|
+
|
|
3
|
+
**Version**: 1.0.0
|
|
4
|
+
**Last Updated**: [Current Date]
|
|
5
|
+
**Status**: Stable
|
|
6
|
+
|
|
7
|
+
This document defines the **single source of truth** for the snapshot data structure returned by `window.sentience.snapshot()`. Both Python and TypeScript SDKs must implement this contract exactly.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
The snapshot API returns a structured representation of the current page state, including:
|
|
12
|
+
- All interactive elements with semantic roles
|
|
13
|
+
- Element positions (bounding boxes)
|
|
14
|
+
- Importance scores (AI-optimized ranking)
|
|
15
|
+
- Visual cues (primary actions, colors, clickability)
|
|
16
|
+
- Optional screenshot
|
|
17
|
+
|
|
18
|
+
## Response Structure
|
|
19
|
+
|
|
20
|
+
### Top-Level Object
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
{
|
|
24
|
+
status: "success" | "error",
|
|
25
|
+
timestamp?: string, // ISO 8601
|
|
26
|
+
url: string,
|
|
27
|
+
viewport?: { width: number, height: number },
|
|
28
|
+
elements: Element[],
|
|
29
|
+
screenshot?: string, // Base64 data URL
|
|
30
|
+
screenshot_format?: "png" | "jpeg",
|
|
31
|
+
error?: string, // If status is "error"
|
|
32
|
+
requires_license?: boolean // If license required
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Element Object
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
{
|
|
40
|
+
id: number, // REQUIRED: Unique identifier (registry index)
|
|
41
|
+
role: string, // REQUIRED: Semantic role
|
|
42
|
+
text: string | null, // Text content, aria-label, or placeholder
|
|
43
|
+
importance: number, // REQUIRED: Importance score (-300 to ~1800)
|
|
44
|
+
bbox: BBox, // REQUIRED: Bounding box
|
|
45
|
+
visual_cues: VisualCues, // REQUIRED: Visual analysis
|
|
46
|
+
in_viewport: boolean, // Is element visible in viewport
|
|
47
|
+
is_occluded: boolean, // Is element covered by overlay
|
|
48
|
+
z_index: number // CSS z-index (0 if auto)
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### BBox (Bounding Box)
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
{
|
|
56
|
+
x: number, // Left edge in pixels
|
|
57
|
+
y: number, // Top edge in pixels
|
|
58
|
+
width: number, // Width in pixels
|
|
59
|
+
height: number // Height in pixels
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### VisualCues
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
{
|
|
67
|
+
is_primary: boolean, // Visually prominent primary action
|
|
68
|
+
background_color_name: string | null, // Named color from palette
|
|
69
|
+
is_clickable: boolean // Has pointer cursor or actionable role
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Field Details
|
|
74
|
+
|
|
75
|
+
### `id` (required)
|
|
76
|
+
- **Type**: `integer`
|
|
77
|
+
- **Description**: Unique element identifier, corresponds to index in `window.sentience_registry`
|
|
78
|
+
- **Usage**: Used for actions like `click(id)`
|
|
79
|
+
- **Stability**: May change between page loads (not persistent)
|
|
80
|
+
|
|
81
|
+
### `role` (required)
|
|
82
|
+
- **Type**: `string`
|
|
83
|
+
- **Values**: `"button"`, `"link"`, `"textbox"`, `"searchbox"`, `"checkbox"`, `"radio"`, `"combobox"`, `"image"`, `"generic"`
|
|
84
|
+
- **Description**: Semantic role inferred from HTML tag, ARIA attributes, and context
|
|
85
|
+
- **Usage**: Primary filter for query engine
|
|
86
|
+
|
|
87
|
+
### `text` (optional)
|
|
88
|
+
- **Type**: `string | null`
|
|
89
|
+
- **Description**: Text content extracted from element:
|
|
90
|
+
- `aria-label` if present
|
|
91
|
+
- `value` or `placeholder` for inputs
|
|
92
|
+
- `alt` for images
|
|
93
|
+
- `innerText` for other elements (truncated to 100 chars)
|
|
94
|
+
- **Usage**: Text matching in query engine
|
|
95
|
+
|
|
96
|
+
### `importance` (required)
|
|
97
|
+
- **Type**: `integer`
|
|
98
|
+
- **Range**: -300 to ~1800
|
|
99
|
+
- **Description**: AI-optimized importance score calculated from:
|
|
100
|
+
- Role priority (inputs: 1000, buttons: 500, links: 100)
|
|
101
|
+
- Area score (larger elements score higher, capped at 200)
|
|
102
|
+
- Visual prominence (+200 for primary actions)
|
|
103
|
+
- Viewport/occlusion penalties (-500 off-screen, -800 occluded)
|
|
104
|
+
- **Usage**: Ranking and filtering elements
|
|
105
|
+
|
|
106
|
+
### `bbox` (required)
|
|
107
|
+
- **Type**: `BBox` object
|
|
108
|
+
- **Description**: Element position and size in viewport coordinates
|
|
109
|
+
- **Coordinates**: Relative to viewport (0,0) at top-left
|
|
110
|
+
- **Usage**: Spatial queries, visual grounding, click coordinates
|
|
111
|
+
|
|
112
|
+
### `visual_cues` (required)
|
|
113
|
+
- **Type**: `VisualCues` object
|
|
114
|
+
- **Description**: Visual analysis results
|
|
115
|
+
- **Fields**:
|
|
116
|
+
- `is_primary`: True if element is visually prominent primary action
|
|
117
|
+
- `background_color_name`: Nearest named color (32-color palette) or null
|
|
118
|
+
- `is_clickable`: True if element has pointer cursor or actionable role
|
|
119
|
+
|
|
120
|
+
### `in_viewport` (optional)
|
|
121
|
+
- **Type**: `boolean`
|
|
122
|
+
- **Description**: True if element is visible in current viewport
|
|
123
|
+
- **Default**: `true` (if not present, assume visible)
|
|
124
|
+
|
|
125
|
+
### `is_occluded` (optional)
|
|
126
|
+
- **Type**: `boolean`
|
|
127
|
+
- **Description**: True if element is covered by another element
|
|
128
|
+
- **Default**: `false` (if not present, assume not occluded)
|
|
129
|
+
|
|
130
|
+
### `z_index` (optional)
|
|
131
|
+
- **Type**: `integer`
|
|
132
|
+
- **Description**: CSS z-index value (0 if "auto" or not set)
|
|
133
|
+
- **Default**: `0`
|
|
134
|
+
|
|
135
|
+
## Element Sorting
|
|
136
|
+
|
|
137
|
+
Elements in the `elements` array are sorted by:
|
|
138
|
+
1. **Primary sort**: `importance` (descending) - most important first
|
|
139
|
+
2. **Secondary sort**: `bbox.y` (ascending) - top-to-bottom reading order (if limit applied)
|
|
140
|
+
|
|
141
|
+
## Example Response
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"status": "success",
|
|
146
|
+
"timestamp": "2025-01-20T10:30:00Z",
|
|
147
|
+
"url": "https://example.com",
|
|
148
|
+
"viewport": {
|
|
149
|
+
"width": 1280,
|
|
150
|
+
"height": 800
|
|
151
|
+
},
|
|
152
|
+
"elements": [
|
|
153
|
+
{
|
|
154
|
+
"id": 42,
|
|
155
|
+
"role": "button",
|
|
156
|
+
"text": "Sign In",
|
|
157
|
+
"importance": 850,
|
|
158
|
+
"bbox": {
|
|
159
|
+
"x": 100,
|
|
160
|
+
"y": 200,
|
|
161
|
+
"width": 120,
|
|
162
|
+
"height": 40
|
|
163
|
+
},
|
|
164
|
+
"visual_cues": {
|
|
165
|
+
"is_primary": true,
|
|
166
|
+
"background_color_name": "blue",
|
|
167
|
+
"is_clickable": true
|
|
168
|
+
},
|
|
169
|
+
"in_viewport": true,
|
|
170
|
+
"is_occluded": false,
|
|
171
|
+
"z_index": 0
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Error Response
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"status": "error",
|
|
182
|
+
"error": "Headless mode requires a valid license key...",
|
|
183
|
+
"requires_license": true
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## SDK Implementation Requirements
|
|
188
|
+
|
|
189
|
+
Both Python and TypeScript SDKs must:
|
|
190
|
+
|
|
191
|
+
1. **Validate** snapshot response against this schema
|
|
192
|
+
2. **Parse** all required fields correctly
|
|
193
|
+
3. **Handle** optional fields gracefully (defaults)
|
|
194
|
+
4. **Type-check** all fields (Pydantic for Python, TypeScript types for TS)
|
|
195
|
+
5. **Preserve** field names exactly (no renaming)
|
|
196
|
+
|
|
197
|
+
## Versioning
|
|
198
|
+
|
|
199
|
+
- **v1.0.0**: Initial stable version
|
|
200
|
+
- Future versions will increment major version for breaking changes
|
|
201
|
+
- SDKs should validate version and handle compatibility
|
|
202
|
+
|
|
203
|
+
## Related Documents
|
|
204
|
+
|
|
205
|
+
- `snapshot.schema.json` - JSON Schema validation
|
|
206
|
+
- Extension implementation: `sentience-chrome/injected_api.js`
|
|
207
|
+
- WASM implementation: `sentience-chrome/src/lib.rs`
|
|
208
|
+
|