|
| 1 | +/** |
| 2 | + * Type definitions for Sentience Chrome Extension API |
| 3 | + * |
| 4 | + * This file defines the global window.sentience API that is injected |
| 5 | + * by the Sentience Chrome Extension into every page. |
| 6 | + * |
| 7 | + * These types allow TypeScript code to call window.sentience methods |
| 8 | + * without using 'as any' casts. |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * Sentience Chrome Extension API |
| 13 | + * |
| 14 | + * The actual return types match the SDK's types.ts definitions, |
| 15 | + * but we use 'any' here to avoid conflicts between browser context |
| 16 | + * and Node.js context types. |
| 17 | + */ |
| 18 | +interface SentienceAPI { |
| 19 | + /** |
| 20 | + * Take a snapshot of the current page |
| 21 | + * |
| 22 | + * Extracts interactive elements with semantic understanding, |
| 23 | + * scores them by importance, and returns structured data. |
| 24 | + * |
| 25 | + * @param options Snapshot configuration options |
| 26 | + * @returns Promise resolving to snapshot data |
| 27 | + * |
| 28 | + * @example |
| 29 | + * ```typescript |
| 30 | + * // Basic snapshot |
| 31 | + * const result = await window.sentience.snapshot(); |
| 32 | + * console.log(result.elements); // Top 50 elements |
| 33 | + * |
| 34 | + * // With options |
| 35 | + * const result = await window.sentience.snapshot({ |
| 36 | + * limit: 100, |
| 37 | + * screenshot: true, |
| 38 | + * filter: { min_area: 50 } |
| 39 | + * }); |
| 40 | + * ``` |
| 41 | + */ |
| 42 | + snapshot(options?: any): Promise<any>; |
| 43 | + |
| 44 | + /** |
| 45 | + * Click an element by its ID |
| 46 | + * |
| 47 | + * @param id Element ID from snapshot |
| 48 | + * @returns true if click succeeded, false otherwise |
| 49 | + */ |
| 50 | + click(id: number): boolean; |
| 51 | + |
| 52 | + /** |
| 53 | + * Get readable text from the page |
| 54 | + * |
| 55 | + * @param options Read options |
| 56 | + * @returns Extracted text content |
| 57 | + */ |
| 58 | + read(options?: any): any; |
| 59 | + |
| 60 | + /** |
| 61 | + * Internal: WASM module reference (may not be exposed) |
| 62 | + * @internal |
| 63 | + */ |
| 64 | + _wasmModule?: any; |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * Extend the global Window interface |
| 69 | + */ |
| 70 | +declare global { |
| 71 | + interface Window { |
| 72 | + /** |
| 73 | + * Sentience Chrome Extension API |
| 74 | + * |
| 75 | + * This API is injected by the Sentience extension and provides |
| 76 | + * programmatic access to semantic web page analysis. |
| 77 | + */ |
| 78 | + sentience: SentienceAPI; |
| 79 | + |
| 80 | + /** |
| 81 | + * Internal: Element registry for click tracking |
| 82 | + * @internal |
| 83 | + */ |
| 84 | + sentience_registry: HTMLElement[]; |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +// This export makes this a module (required for declaration merging) |
| 89 | +export {}; |
0 commit comments