sentienceapi 0.90.2 → 0.90.6

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The SDK is open under ELv2; the core semantic geometry and reliability logic runs in Sentience-hosted services.
4
4
 
5
- ## Installation
5
+ ## 📦 Installation
6
6
 
7
7
  ```bash
8
8
  # Install from npm
@@ -18,11 +18,12 @@ npm install
18
18
  npm run build
19
19
  ```
20
20
 
21
- ## Quick Start: Choose Your Abstraction Level
21
+ ## 🚀 Quick Start: Choose Your Abstraction Level
22
22
 
23
23
  Sentience SDK offers **4 levels of abstraction** - choose based on your needs:
24
24
 
25
- ### 💬 Level 4: Conversational Agent (Highest Abstraction) - **NEW in v0.3.0**
25
+ <details open>
26
+ <summary><b>💬 Level 4: Conversational Agent (Highest Abstraction)</b> - NEW in v0.3.0</summary>
26
27
 
27
28
  Complete automation with natural conversation. Just describe what you want, and the agent plans and executes everything:
28
29
 
@@ -53,7 +54,10 @@ await browser.close();
53
54
  **Code reduction:** 99% less code - describe goals in natural language
54
55
  **Requirements:** OpenAI or Anthropic API key
55
56
 
56
- ### 🤖 Level 3: Agent (Natural Language Commands) - **Recommended for Most Users**
57
+ </details>
58
+
59
+ <details>
60
+ <summary><b>🤖 Level 3: Agent (Natural Language Commands)</b> - Recommended for Most Users</summary>
57
61
 
58
62
  Zero coding knowledge needed. Just write what you want in plain English:
59
63
 
@@ -81,7 +85,10 @@ await browser.close();
81
85
  **Code reduction:** 95-98% less code vs manual approach
82
86
  **Requirements:** OpenAI API key (or Anthropic for Claude)
83
87
 
84
- ### 🔧 Level 2: Direct SDK (Technical Control)
88
+ </details>
89
+
90
+ <details>
91
+ <summary><b>🔧 Level 2: Direct SDK (Technical Control)</b></summary>
85
92
 
86
93
  Full control with semantic selectors. For technical users who want precision:
87
94
 
@@ -109,7 +116,10 @@ await browser.close();
109
116
  **Code reduction:** Still 80% less code vs raw Playwright
110
117
  **Requirements:** Only Sentience API key
111
118
 
112
- ### ⚙️ Level 1: Raw Playwright (Maximum Control)
119
+ </details>
120
+
121
+ <details>
122
+ <summary><b>⚙️ Level 1: Raw Playwright (Maximum Control)</b></summary>
113
123
 
114
124
  For when you need complete low-level control (rare):
115
125
 
@@ -127,9 +137,12 @@ await browser.close();
127
137
  **When to use:** Very specific edge cases, custom browser configs
128
138
  **Tradeoffs:** No semantic intelligence, brittle selectors, more code
129
139
 
140
+ </details>
141
+
130
142
  ---
131
143
 
132
- ## Agent Execution Tracing (NEW in v0.3.1)
144
+ <details>
145
+ <summary><h2>📊 Agent Execution Tracing (NEW in v0.3.1)</h2></summary>
133
146
 
134
147
  Record complete agent execution traces for debugging, analysis, and replay. Traces capture every step, snapshot, LLM decision, and action in a structured JSONL format.
135
148
 
@@ -187,187 +200,18 @@ Each agent action generates multiple events:
187
200
  4. **action** - Executed action (type, element ID, success)
188
201
  5. **error** - Any failures (error message, retry attempt)
189
202
 
190
- **Example trace output:**
191
- ```jsonl
192
- {"v":1,"type":"run_start","ts":"2025-12-26T10:00:00.000Z","run_id":"abc-123","seq":1,"data":{"agent":"SentienceAgent","llm_model":"gpt-4o"}}
193
- {"v":1,"type":"step_start","ts":"2025-12-26T10:00:01.000Z","run_id":"abc-123","seq":2,"step_id":"step-1","data":{"step_index":1,"goal":"Click the search box","attempt":0,"url":"https://google.com"}}
194
- {"v":1,"type":"snapshot","ts":"2025-12-26T10:00:01.500Z","run_id":"abc-123","seq":3,"step_id":"step-1","data":{"url":"https://google.com","elements":[...]}}
195
- {"v":1,"type":"llm_response","ts":"2025-12-26T10:00:02.000Z","run_id":"abc-123","seq":4,"step_id":"step-1","data":{"model":"gpt-4o","prompt_tokens":250,"completion_tokens":10,"response_text":"CLICK(42)"}}
196
- {"v":1,"type":"action","ts":"2025-12-26T10:00:02.500Z","run_id":"abc-123","seq":5,"step_id":"step-1","data":{"action_type":"click","element_id":42,"success":true}}
197
- {"v":1,"type":"run_end","ts":"2025-12-26T10:00:03.000Z","run_id":"abc-123","seq":6,"data":{"steps":1}}
198
- ```
199
-
200
- ### Reading and Analyzing Traces
201
-
202
- ```typescript
203
- import * as fs from 'fs';
204
-
205
- // Read trace file
206
- const content = fs.readFileSync(`traces/${runId}.jsonl`, 'utf-8');
207
- const events = content.trim().split('\n').map(JSON.parse);
208
-
209
- console.log(`Total events: ${events.length}`);
210
-
211
- // Analyze events
212
- events.forEach(event => {
213
- console.log(`[${event.seq}] ${event.type} - ${event.ts}`);
214
- });
215
-
216
- // Filter by type
217
- const actions = events.filter(e => e.type === 'action');
218
- console.log(`Actions taken: ${actions.length}`);
219
-
220
- // Get token usage
221
- const llmEvents = events.filter(e => e.type === 'llm_response');
222
- const totalTokens = llmEvents.reduce((sum, e) => sum + (e.data.prompt_tokens || 0) + (e.data.completion_tokens || 0), 0);
223
- console.log(`Total tokens: ${totalTokens}`);
224
- ```
225
-
226
- ### Tracing Without Agent (Manual)
227
-
228
- You can also use the tracer directly for custom workflows:
229
-
230
- ```typescript
231
- import { Tracer, JsonlTraceSink } from 'sentienceapi';
232
- import { randomUUID } from 'crypto';
233
-
234
- const runId = randomUUID();
235
- const sink = new JsonlTraceSink(`traces/${runId}.jsonl`);
236
- const tracer = new Tracer(runId, sink);
237
-
238
- // Emit custom events
239
- tracer.emit('custom_event', {
240
- message: 'Something happened',
241
- details: { foo: 'bar' }
242
- });
243
-
244
- // Use convenience methods
245
- tracer.emitRunStart('MyAgent', 'gpt-4o');
246
- tracer.emitStepStart('step-1', 1, 'Do something');
247
- tracer.emitError('step-1', 'Something went wrong');
248
- tracer.emitRunEnd(1);
249
-
250
- // Flush to disk
251
- await tracer.close();
252
- ```
253
-
254
203
  ### Schema Compatibility
255
204
 
256
205
  Traces are **100% compatible** with Python SDK traces - use the same tools to analyze traces from both TypeScript and Python agents!
257
206
 
258
207
  **See full example:** [examples/agent-with-tracing.ts](examples/agent-with-tracing.ts)
259
208
 
260
- ---
261
-
262
- ## Agent Layer Examples
263
-
264
- ### Google Search (6 lines of code)
265
-
266
- ```typescript
267
- import { SentienceBrowser, SentienceAgent, OpenAIProvider } from 'sentienceapi';
268
-
269
- const browser = await SentienceBrowser.create({ apiKey: apiKey });
270
- const llm = new OpenAIProvider(openaiKey, 'gpt-4o-mini');
271
- const agent = new SentienceAgent(browser, llm);
272
-
273
- await browser.getPage().goto('https://www.google.com');
274
- await agent.act('Click the search box');
275
- await agent.act("Type 'mechanical keyboards' into the search field");
276
- await agent.act('Press Enter key');
277
- await agent.act('Click the first non-ad search result');
278
-
279
- await browser.close();
280
- ```
281
-
282
- **See full example:** [examples/agent-google-search.ts](examples/agent-google-search.ts)
283
-
284
- ### Using Anthropic Claude Instead of GPT
285
-
286
- ```typescript
287
- import { SentienceAgent, AnthropicProvider } from 'sentienceapi';
288
-
289
- // Swap OpenAI for Anthropic - same API!
290
- const llm = new AnthropicProvider(
291
- process.env.ANTHROPIC_API_KEY!,
292
- 'claude-3-5-sonnet-20241022'
293
- );
294
-
295
- const agent = new SentienceAgent(browser, llm);
296
- await agent.act('Click the search button'); // Works exactly the same
297
- ```
298
-
299
- **BYOB (Bring Your Own Brain):** OpenAI, Anthropic, or implement `LLMProvider` for any model.
300
-
301
- **See full example:** [examples/agent-with-anthropic.ts](examples/agent-with-anthropic.ts)
302
-
303
- ### Amazon Shopping (98% code reduction)
304
-
305
- **Before (manual approach):** 350 lines
306
- **After (agent layer):** 6 lines
307
-
308
- ```typescript
309
- await agent.act('Click the search box');
310
- await agent.act("Type 'wireless mouse' into the search field");
311
- await agent.act('Press Enter key');
312
- await agent.act('Click the first visible product in the search results');
313
- await agent.act("Click the 'Add to Cart' button");
314
- ```
315
-
316
- **See full example:** [examples/agent-amazon-shopping.ts](examples/agent-amazon-shopping.ts)
209
+ </details>
317
210
 
318
211
  ---
319
212
 
320
- ## Installation for Agent Layer
321
-
322
- ```bash
323
- # Install core SDK
324
- npm install sentienceapi
325
-
326
- # Install LLM provider (choose one or both)
327
- npm install openai # For GPT-4, GPT-4o, GPT-4o-mini
328
- npm install @anthropic-ai/sdk # For Claude 3.5 Sonnet
329
-
330
- # Set API keys
331
- export SENTIENCE_API_KEY="your-sentience-key"
332
- export OPENAI_API_KEY="your-openai-key" # OR
333
- export ANTHROPIC_API_KEY="your-anthropic-key"
334
- ```
335
-
336
- ---
337
-
338
- ## Direct SDK Quick Start
339
-
340
- ```typescript
341
- import { SentienceBrowser, snapshot, find, click } from './src';
342
-
343
- async function main() {
344
- const browser = new SentienceBrowser();
345
-
346
- try {
347
- await browser.start();
348
-
349
- await browser.goto('https://example.com');
350
- await browser.getPage().waitForLoadState('networkidle');
351
-
352
- // Take snapshot - captures all interactive elements
353
- const snap = await snapshot(browser);
354
- console.log(`Found ${snap.elements.length} elements`);
355
-
356
- // Find and click a link using semantic selectors
357
- const link = find(snap, 'role=link text~"More information"');
358
- if (link) {
359
- const result = await click(browser, link.id);
360
- console.log(`Click success: ${result.success}`);
361
- }
362
- } finally {
363
- await browser.close();
364
- }
365
- }
366
-
367
- main();
368
- ```
369
-
370
- ## Real-World Example: Amazon Shopping Bot
213
+ <details>
214
+ <summary><h2>💼 Real-World Example: Amazon Shopping Bot</h2></summary>
371
215
 
372
216
  This example demonstrates navigating Amazon, finding products, and adding items to cart:
373
217
 
@@ -428,50 +272,38 @@ async function main() {
428
272
  main();
429
273
  ```
430
274
 
431
- **See the complete tutorial**: [Amazon Shopping Guide](../docs/AMAZON_SHOPPING_GUIDE.md)
432
-
433
- ## Running Examples
434
-
435
- **⚠️ Important**: You cannot use `node` directly to run TypeScript files. Use one of these methods:
275
+ **📖 See the complete tutorial:** [Amazon Shopping Guide](../docs/AMAZON_SHOPPING_GUIDE.md)
436
276
 
437
- ### Option 1: Using npm scripts (recommended)
438
- ```bash
439
- npm run example:hello
440
- npm run example:basic
441
- npm run example:query
442
- npm run example:wait
443
- ```
277
+ </details>
444
278
 
445
- ### Option 2: Using ts-node directly
446
- ```bash
447
- npx ts-node examples/hello.ts
448
- # or if ts-node is installed globally:
449
- ts-node examples/hello.ts
450
- ```
279
+ ---
451
280
 
452
- ### Option 3: Compile then run
453
- ```bash
454
- npm run build
455
- # Then use compiled JavaScript from dist/
456
- ```
281
+ ## 📚 Core Features
457
282
 
458
- ## Core Features
283
+ <details>
284
+ <summary><h3>🌐 Browser Control</h3></summary>
459
285
 
460
- ### Browser Control
461
286
  - **`SentienceBrowser`** - Playwright browser with Sentience extension pre-loaded
462
287
  - **`browser.goto(url)`** - Navigate with automatic extension readiness checks
463
288
  - Automatic bot evasion and stealth mode
464
289
  - Configurable headless/headed mode
465
290
 
466
- ### Snapshot - Intelligent Page Analysis
467
- - **`snapshot(browser, options?)`** - Capture page state with AI-ranked elements
291
+ </details>
292
+
293
+ <details>
294
+ <summary><h3>📸 Snapshot - Intelligent Page Analysis</h3></summary>
295
+
296
+ **`snapshot(browser, options?)`** - Capture page state with AI-ranked elements
297
+
298
+ Features:
468
299
  - Returns semantic elements with roles, text, importance scores, and bounding boxes
469
300
  - Optional screenshot capture (PNG/JPEG)
301
+ - Optional visual overlay to see what elements are detected
470
302
  - TypeScript types for type safety
471
303
 
472
304
  **Example:**
473
305
  ```typescript
474
- const snap = await snapshot(browser, { screenshot: true });
306
+ const snap = await snapshot(browser, { screenshot: true, show_overlay: true });
475
307
 
476
308
  // Access structured data
477
309
  console.log(`URL: ${snap.url}`);
@@ -484,7 +316,11 @@ for (const element of snap.elements) {
484
316
  }
485
317
  ```
486
318
 
487
- ### Query Engine - Semantic Element Selection
319
+ </details>
320
+
321
+ <details>
322
+ <summary><h3>🔍 Query Engine - Semantic Element Selection</h3></summary>
323
+
488
324
  - **`query(snapshot, selector)`** - Find all matching elements
489
325
  - **`find(snapshot, selector)`** - Find single best match (by importance)
490
326
  - Powerful query DSL with multiple operators
@@ -514,7 +350,11 @@ const firstRow = query(snap, 'bbox.y<600');
514
350
 
515
351
  **📖 [Complete Query DSL Guide](docs/QUERY_DSL.md)** - All operators, fields, and advanced patterns
516
352
 
517
- ### Actions - Interact with Elements
353
+ </details>
354
+
355
+ <details>
356
+ <summary><h3>👆 Actions - Interact with Elements</h3></summary>
357
+
518
358
  - **`click(browser, elementId)`** - Click element by ID
519
359
  - **`clickRect(browser, rect)`** - Click at center of rectangle (coordinate-based)
520
360
  - **`typeText(browser, elementId, text)`** - Type into input fields
@@ -554,7 +394,11 @@ if (element) {
554
394
  }
555
395
  ```
556
396
 
557
- ### Wait & Assertions
397
+ </details>
398
+
399
+ <details>
400
+ <summary><h3>⏱️ Wait & Assertions</h3></summary>
401
+
558
402
  - **`waitFor(browser, selector, timeout?, interval?, useApi?)`** - Wait for element to appear
559
403
  - **`expect(browser, selector)`** - Assertion helper with fluent API
560
404
 
@@ -587,11 +431,55 @@ await expect(browser, 'role=button').toHaveText('Submit');
587
431
  await expect(browser, 'role=link').toHaveCount(10);
588
432
  ```
589
433
 
590
- ### Content Reading
591
- - **`read(browser, options?)`** - Extract page content
592
- - `format: "text"` - Plain text extraction
593
- - `format: "markdown"` - High-quality markdown conversion (uses Turndown)
594
- - `format: "raw"` - Cleaned HTML (default)
434
+ </details>
435
+
436
+ <details>
437
+ <summary><h3>🎨 Visual Overlay - Debug Element Detection</h3></summary>
438
+
439
+ - **`showOverlay(browser, elements, targetElementId?)`** - Display visual overlay highlighting elements
440
+ - **`clearOverlay(browser)`** - Clear overlay manually
441
+
442
+ Show color-coded borders around detected elements to debug, validate, and understand what Sentience sees:
443
+
444
+ ```typescript
445
+ import { showOverlay, clearOverlay } from 'sentienceapi';
446
+
447
+ // Take snapshot once
448
+ const snap = await snapshot(browser);
449
+
450
+ // Show overlay anytime without re-snapshotting
451
+ await showOverlay(browser, snap); // Auto-clears after 5 seconds
452
+
453
+ // Highlight specific target element in red
454
+ const button = find(snap, 'role=button text~"Submit"');
455
+ await showOverlay(browser, snap, button.id);
456
+
457
+ // Clear manually before 5 seconds
458
+ await new Promise(resolve => setTimeout(resolve, 2000));
459
+ await clearOverlay(browser);
460
+ ```
461
+
462
+ **Color Coding:**
463
+ - 🔴 Red: Target element
464
+ - 🔵 Blue: Primary elements (`is_primary=true`)
465
+ - 🟢 Green: Regular interactive elements
466
+
467
+ **Visual Indicators:**
468
+ - Border thickness/opacity scales with importance
469
+ - Semi-transparent fill
470
+ - Importance badges
471
+ - Star icons for primary elements
472
+ - Auto-clear after 5 seconds
473
+
474
+ </details>
475
+
476
+ <details>
477
+ <summary><h3>📄 Content Reading</h3></summary>
478
+
479
+ **`read(browser, options?)`** - Extract page content
480
+ - `format: "text"` - Plain text extraction
481
+ - `format: "markdown"` - High-quality markdown conversion (uses Turndown)
482
+ - `format: "raw"` - Cleaned HTML (default)
595
483
 
596
484
  **Example:**
597
485
  ```typescript
@@ -606,11 +494,15 @@ const result = await read(browser, { format: 'text' });
606
494
  console.log(result.content); // Plain text
607
495
  ```
608
496
 
609
- ### Screenshots
610
- - **`screenshot(browser, options?)`** - Standalone screenshot capture
611
- - Returns base64-encoded data URL
612
- - PNG or JPEG format
613
- - Quality control for JPEG (1-100)
497
+ </details>
498
+
499
+ <details>
500
+ <summary><h3>📷 Screenshots</h3></summary>
501
+
502
+ **`screenshot(browser, options?)`** - Standalone screenshot capture
503
+ - Returns base64-encoded data URL
504
+ - PNG or JPEG format
505
+ - Quality control for JPEG (1-100)
614
506
 
615
507
  **Example:**
616
508
  ```typescript
@@ -629,7 +521,14 @@ writeFileSync('screenshot.png', imageData);
629
521
  const dataUrl = await screenshot(browser, { format: 'jpeg', quality: 85 });
630
522
  ```
631
523
 
632
- ## Element Properties
524
+ </details>
525
+
526
+ ---
527
+
528
+ ## 📋 Reference
529
+
530
+ <details>
531
+ <summary><h3>Element Properties</h3></summary>
633
532
 
634
533
  Elements returned by `snapshot()` have the following properties:
635
534
 
@@ -645,7 +544,10 @@ element.is_occluded // Is element covered by other elements?
645
544
  element.z_index // CSS stacking order
646
545
  ```
647
546
 
648
- ## Query DSL Reference
547
+ </details>
548
+
549
+ <details>
550
+ <summary><h3>Query DSL Reference</h3></summary>
649
551
 
650
552
  ### Basic Operators
651
553
 
@@ -668,38 +570,14 @@ element.z_index // CSS stacking order
668
570
  - **Position**: `bbox.x`, `bbox.y`, `bbox.width`, `bbox.height`
669
571
  - **Layering**: `z_index`
670
572
 
671
- ## Examples
672
-
673
- See the `examples/` directory for complete working examples:
674
-
675
- ### Agent Layer (Level 3 - Natural Language)
676
- - **`agent-google-search.ts`** - Google search automation with natural language commands
677
- - **`agent-amazon-shopping.ts`** - Amazon shopping bot (6 lines vs 350 lines manual code)
678
- - **`agent-with-anthropic.ts`** - Using Anthropic Claude instead of OpenAI GPT
679
-
680
- ### Direct SDK (Level 2 - Technical Control)
681
- - **`hello.ts`** - Extension bridge verification
682
- - **`basic-agent.ts`** - Basic snapshot and element inspection
683
- - **`query-demo.ts`** - Query engine demonstrations
684
- - **`wait-and-click.ts`** - Waiting for elements and performing actions
685
- - **`read-markdown.ts`** - Content extraction and markdown conversion
686
-
687
- ## Testing
688
-
689
- ```bash
690
- # Run all tests
691
- npm test
692
-
693
- # Run with coverage
694
- npm run test:coverage
573
+ </details>
695
574
 
696
- # Run specific test file
697
- npm test -- snapshot.test.ts
698
- ```
575
+ ---
699
576
 
700
- ## Configuration
577
+ ## ⚙️ Configuration
701
578
 
702
- ### Viewport Size
579
+ <details>
580
+ <summary><h3>Viewport Size</h3></summary>
703
581
 
704
582
  Default viewport is **1280x800** pixels. You can customize it using Playwright's API:
705
583
 
@@ -713,7 +591,10 @@ await browser.getPage().setViewportSize({ width: 1920, height: 1080 });
713
591
  await browser.goto('https://example.com');
714
592
  ```
715
593
 
716
- ### Headless Mode
594
+ </details>
595
+
596
+ <details>
597
+ <summary><h3>Headless Mode</h3></summary>
717
598
 
718
599
  ```typescript
719
600
  // Headed mode (shows browser window)
@@ -726,7 +607,10 @@ const browser = new SentienceBrowser(undefined, undefined, true);
726
607
  const browser = new SentienceBrowser(); // headless=true if CI=true, else false
727
608
  ```
728
609
 
729
- ### Residential Proxy Support
610
+ </details>
611
+
612
+ <details>
613
+ <summary><h3>🌍 Residential Proxy Support</h3></summary>
730
614
 
731
615
  For users running from datacenters (AWS, DigitalOcean, etc.), you can configure a residential proxy to prevent IP-based detection by Cloudflare, Akamai, and other anti-bot services.
732
616
 
@@ -771,20 +655,12 @@ await agent.act('Navigate to example.com');
771
655
  The SDK automatically adds WebRTC leak protection flags when a proxy is configured, preventing your real datacenter IP from being exposed via WebRTC even when using proxies.
772
656
 
773
657
  **HTTPS Certificate Handling:**
774
- The SDK automatically ignores HTTPS certificate errors when a proxy is configured, as residential proxies often use self-signed certificates for SSL interception. This ensures seamless navigation to HTTPS sites through the proxy.
775
-
776
- **Example:**
777
- ```bash
778
- # Run with proxy via environment variable
779
- SENTIENCE_PROXY=http://user:pass@proxy.com:8000 npm run example:proxy
780
-
781
- # Or via command line argument
782
- ts-node examples/proxy-example.ts --proxy=http://user:pass@proxy.com:8000
783
- ```
658
+ The SDK automatically ignores HTTPS certificate errors when a proxy is configured, as residential proxies often use self-signed certificates for SSL interception.
784
659
 
785
- **Note:** The proxy is configured at the browser level, so all traffic (including the Chrome extension) routes through the proxy. No changes to the extension are required.
660
+ </details>
786
661
 
787
- ### Authentication Session Injection
662
+ <details>
663
+ <summary><h3>🔐 Authentication Session Injection</h3></summary>
788
664
 
789
665
  Inject pre-recorded authentication sessions (cookies + localStorage) to start your agent already logged in, bypassing login screens, 2FA, and CAPTCHAs. This saves tokens and reduces costs by eliminating login steps.
790
666
 
@@ -833,7 +709,14 @@ await browser3.start();
833
709
 
834
710
  See `examples/auth-injection-agent.ts` for complete examples.
835
711
 
836
- ## Best Practices
712
+ </details>
713
+
714
+ ---
715
+
716
+ ## 💡 Best Practices
717
+
718
+ <details>
719
+ <summary>Click to expand best practices</summary>
837
720
 
838
721
  ### 1. Wait for Dynamic Content
839
722
  ```typescript
@@ -889,7 +772,14 @@ try {
889
772
  }
890
773
  ```
891
774
 
892
- ## Troubleshooting
775
+ </details>
776
+
777
+ ---
778
+
779
+ ## 🛠️ Troubleshooting
780
+
781
+ <details>
782
+ <summary>Click to expand common issues and solutions</summary>
893
783
 
894
784
  ### "Extension failed to load"
895
785
  **Solution:** Build the extension first:
@@ -915,18 +805,91 @@ npm run example:hello
915
805
  ### Button not clickable
916
806
  **Solutions:**
917
807
  - Check visibility: `element.in_viewport && !element.is_occluded`
918
- - Scroll to element: `await browser.getPage().evaluate(\`window.sentience_registry[${element.id}].scrollIntoView()\`)`
808
+ - Scroll to element: ``await browser.getPage().evaluate(`window.sentience_registry[${element.id}].scrollIntoView()`)``
809
+
810
+ </details>
811
+
812
+ ---
813
+
814
+ ## 💻 Examples & Testing
815
+
816
+ <details>
817
+ <summary><h3>Agent Layer Examples (Level 3 - Natural Language)</h3></summary>
818
+
819
+ - **`agent-google-search.ts`** - Google search automation with natural language commands
820
+ - **`agent-amazon-shopping.ts`** - Amazon shopping bot (6 lines vs 350 lines manual code)
821
+ - **`agent-with-anthropic.ts`** - Using Anthropic Claude instead of OpenAI GPT
822
+ - **`agent-with-tracing.ts`** - Agent execution tracing for debugging and analysis
919
823
 
920
- ## Documentation
824
+ </details>
825
+
826
+ <details>
827
+ <summary><h3>Direct SDK Examples (Level 2 - Technical Control)</h3></summary>
828
+
829
+ - **`hello.ts`** - Extension bridge verification
830
+ - **`basic-agent.ts`** - Basic snapshot and element inspection
831
+ - **`query-demo.ts`** - Query engine demonstrations
832
+ - **`wait-and-click.ts`** - Waiting for elements and performing actions
833
+ - **`read-markdown.ts`** - Content extraction and markdown conversion
834
+
835
+ </details>
836
+
837
+ <details>
838
+ <summary><h3>Running Examples</h3></summary>
839
+
840
+ **⚠️ Important**: You cannot use `node` directly to run TypeScript files. Use one of these methods:
841
+
842
+ ### Option 1: Using npm scripts (recommended)
843
+ ```bash
844
+ npm run example:hello
845
+ npm run example:basic
846
+ npm run example:query
847
+ npm run example:wait
848
+ ```
849
+
850
+ ### Option 2: Using ts-node directly
851
+ ```bash
852
+ npx ts-node examples/hello.ts
853
+ # or if ts-node is installed globally:
854
+ ts-node examples/hello.ts
855
+ ```
856
+
857
+ ### Option 3: Compile then run
858
+ ```bash
859
+ npm run build
860
+ # Then use compiled JavaScript from dist/
861
+ ```
862
+
863
+ </details>
864
+
865
+ <details>
866
+ <summary><h3>Testing</h3></summary>
867
+
868
+ ```bash
869
+ # Run all tests
870
+ npm test
871
+
872
+ # Run with coverage
873
+ npm run test:coverage
874
+
875
+ # Run specific test file
876
+ npm test -- snapshot.test.ts
877
+ ```
878
+
879
+ </details>
880
+
881
+ ---
882
+
883
+ ## 📖 Documentation
921
884
 
922
885
  - **📖 [Amazon Shopping Guide](../docs/AMAZON_SHOPPING_GUIDE.md)** - Complete tutorial with real-world example
923
886
  - **📖 [Query DSL Guide](docs/QUERY_DSL.md)** - Advanced query patterns and operators
924
887
  - **📄 [API Contract](../spec/SNAPSHOT_V1.md)** - Snapshot API specification
925
888
  - **📄 [Type Definitions](../spec/sdk-types.md)** - TypeScript/Python type definitions
926
889
 
927
- ## License
890
+ ---
928
891
 
929
- 📜 **License**
892
+ ## 📜 License
930
893
 
931
894
  This SDK is licensed under the **Elastic License 2.0 (ELv2)**.
932
895
 
@@ -936,11 +899,10 @@ The Elastic License 2.0 allows you to use, modify, and distribute this SDK for i
936
899
 
937
900
  - This SDK is a **client-side library** that communicates with proprietary Sentience services and browser components.
938
901
 
939
- - The Sentience backend services (including semantic geometry grounding, ranking, visual cues, and trace processing) are **not open source** and are governed by Sentiences Terms of Service.
902
+ - The Sentience backend services (including semantic geometry grounding, ranking, visual cues, and trace processing) are **not open source** and are governed by Sentience's Terms of Service.
940
903
 
941
- - Use of this SDK does **not** grant rights to operate, replicate, or reimplement Sentiences hosted services.
904
+ - Use of this SDK does **not** grant rights to operate, replicate, or reimplement Sentience's hosted services.
942
905
 
943
906
  For commercial usage, hosted offerings, or enterprise deployments, please contact Sentience to obtain a commercial license.
944
907
 
945
908
  See the full license text in [`LICENSE`](./LICENSE.md).
946
-