ttp-agent-sdk 2.33.4 → 2.34.0

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
@@ -410,6 +410,227 @@ The tool uses `html2canvas` to render the DOM:
410
410
  - **Cross-Origin**: The tool handles cross-origin images when possible (`useCORS: true`).
411
411
  - **Browser Compatibility**: Requires modern browsers with Canvas API support (Chrome 66+, Firefox 60+, Safari 11.1+, Edge 79+).
412
412
 
413
+ ## Scroll Tool (`scroll_to_element`)
414
+
415
+ The `scroll_to_element` tool allows AI agents to scroll the page in three different ways: scrolling to a specific element, relative scrolling (up/down), or scrolling to an absolute position.
416
+
417
+ ### Scroll Modes
418
+
419
+ The tool supports three scroll modes with the following priority order:
420
+
421
+ 1. **Element Scrolling** (highest priority) - Scroll to a specific element by CSS selector
422
+ 2. **Relative Scrolling** - Scroll up or down by a specified number of pixels
423
+ 3. **Absolute Position Scrolling** - Scroll to specific x/y coordinates
424
+
425
+ ### 1. Scroll to Element
426
+
427
+ Scroll to a specific element on the page using a CSS selector.
428
+
429
+ **Example: Scroll to element**
430
+ ```javascript
431
+ // The agent can call this tool with:
432
+ {
433
+ tool: "scroll_to_element",
434
+ params: {
435
+ selector: "#contact-section", // CSS selector
436
+ position: "center", // 'center', 'top', or 'bottom'
437
+ behavior: "smooth" // 'smooth' or 'instant'
438
+ }
439
+ }
440
+ ```
441
+
442
+ **Example: Scroll element to top**
443
+ ```javascript
444
+ {
445
+ tool: "scroll_to_element",
446
+ params: {
447
+ selector: ".header",
448
+ position: "top", // Scrolls element to top of viewport
449
+ behavior: "smooth"
450
+ }
451
+ }
452
+ ```
453
+
454
+ ### 2. Relative Scrolling (Scroll Up/Down)
455
+
456
+ Scroll the page up or down by a specified number of pixels. This is useful for incremental scrolling or scrolling by viewport height.
457
+
458
+ **Example: Scroll down (default 500px)**
459
+ ```javascript
460
+ {
461
+ tool: "scroll_to_element",
462
+ params: {
463
+ direction: "down",
464
+ amount: 500, // Pixels to scroll (default: 500)
465
+ behavior: "smooth"
466
+ }
467
+ }
468
+ ```
469
+
470
+ **Example: Scroll up (custom amount)**
471
+ ```javascript
472
+ {
473
+ tool: "scroll_to_element",
474
+ params: {
475
+ direction: "up",
476
+ amount: 500, // Scroll up 500 pixels
477
+ behavior: "smooth"
478
+ }
479
+ }
480
+ ```
481
+
482
+ **Example: Scroll down by viewport height**
483
+ ```javascript
484
+ {
485
+ tool: "scroll_to_element",
486
+ params: {
487
+ direction: "down",
488
+ amount: window.innerHeight, // Scroll one viewport height
489
+ behavior: "smooth"
490
+ }
491
+ }
492
+ ```
493
+
494
+ **Features:**
495
+ - Automatically prevents scrolling beyond page boundaries (won't scroll below 0 or above max scroll)
496
+ - Returns `atTop` and `atBottom` flags to indicate if scroll limits were reached
497
+ - Respects smooth/instant scrolling behavior
498
+
499
+ ### 3. Absolute Position Scrolling
500
+
501
+ Scroll to specific x/y coordinates on the page.
502
+
503
+ **Example: Scroll to absolute position**
504
+ ```javascript
505
+ {
506
+ tool: "scroll_to_element",
507
+ params: {
508
+ x: 0, // Horizontal position (optional)
509
+ y: 1000, // Vertical position
510
+ behavior: "smooth"
511
+ }
512
+ }
513
+ ```
514
+
515
+ **Example: Scroll to top of page**
516
+ ```javascript
517
+ {
518
+ tool: "scroll_to_element",
519
+ params: {
520
+ x: 0,
521
+ y: 0,
522
+ behavior: "instant" // Instant scroll to top
523
+ }
524
+ }
525
+ ```
526
+
527
+ ### Tool Parameters
528
+
529
+ | Parameter | Type | Required | Default | Description |
530
+ |-----------|------|----------|---------|-------------|
531
+ | `selector` | string | No* | - | CSS selector for element to scroll to. Takes highest priority if provided. |
532
+ | `position` | string | No | `'center'` | Position for element scrolling: `'center'`, `'top'`, or `'bottom'`. Only used with `selector`. |
533
+ | `direction` | string | No* | - | Direction for relative scrolling: `'up'` or `'down'`. Only used if no `selector` provided. |
534
+ | `amount` | number | No | `500` | Pixels to scroll for relative scrolling. Only used with `direction`. |
535
+ | `x` | number | No* | - | Horizontal scroll position. Only used if no `selector` or `direction` provided. |
536
+ | `y` | number | No* | - | Vertical scroll position. Only used if no `selector` or `direction` provided. |
537
+ | `behavior` | string | No | `'smooth'` | Scroll behavior: `'smooth'` or `'instant'`. |
538
+
539
+ \* At least one of `selector`, `direction`, or `x`/`y` must be provided.
540
+
541
+ ### Return Values
542
+
543
+ The tool returns different result objects depending on the scroll mode:
544
+
545
+ **Element Scrolling Result:**
546
+ ```javascript
547
+ {
548
+ success: true,
549
+ scrollType: "element",
550
+ selector: "#contact-section",
551
+ elementPosition: {
552
+ top: 1200, // Element's position after scroll
553
+ left: 0
554
+ }
555
+ }
556
+ ```
557
+
558
+ **Relative Scrolling Result:**
559
+ ```javascript
560
+ {
561
+ success: true,
562
+ scrollType: "relative",
563
+ direction: "down",
564
+ amount: 300,
565
+ scrolledFrom: { y: 500 }, // Starting scroll position
566
+ scrolledTo: { y: 800 }, // Final scroll position
567
+ atTop: false, // True if scrolled to top
568
+ atBottom: false // True if scrolled to bottom
569
+ }
570
+ ```
571
+
572
+ **Absolute Position Scrolling Result:**
573
+ ```javascript
574
+ {
575
+ success: true,
576
+ scrollType: "position",
577
+ scrolledTo: {
578
+ x: 0,
579
+ y: 1000
580
+ }
581
+ }
582
+ ```
583
+
584
+ **Error Result:**
585
+ ```javascript
586
+ {
587
+ success: false,
588
+ error: "Element not found: #missing-element"
589
+ }
590
+ ```
591
+
592
+ ### Priority Order
593
+
594
+ The tool checks parameters in this order:
595
+
596
+ 1. **`selector`** - If provided, scrolls to element (ignores `direction` and `x`/`y`)
597
+ 2. **`direction`** - If no `selector`, checks for `direction: 'up'` or `'down'` (ignores `x`/`y`)
598
+ 3. **`x`/`y`** - If no `selector` or `direction`, uses absolute position scrolling
599
+
600
+ ### Use Cases
601
+
602
+ **Scroll to specific section:**
603
+ ```javascript
604
+ { selector: "#pricing", position: "top" }
605
+ ```
606
+
607
+ **Scroll down to see more content:**
608
+ ```javascript
609
+ { direction: "down", amount: 500 }
610
+ ```
611
+
612
+ **Scroll up to previous content:**
613
+ ```javascript
614
+ { direction: "up", amount: 300 }
615
+ ```
616
+
617
+ **Scroll to top of page:**
618
+ ```javascript
619
+ { y: 0, behavior: "instant" }
620
+ ```
621
+
622
+ **Scroll to bottom of page:**
623
+ ```javascript
624
+ { y: document.documentElement.scrollHeight, behavior: "smooth" }
625
+ ```
626
+
627
+ ### Important Notes
628
+
629
+ - **Boundary Protection**: Relative scrolling automatically prevents scrolling beyond page boundaries
630
+ - **Backward Compatible**: Existing code using `selector` or `x`/`y` continues to work unchanged
631
+ - **Smooth Scrolling**: Default behavior is smooth scrolling (500ms wait time). Use `behavior: "instant"` for immediate scrolling (100ms wait time)
632
+ - **Element Not Found**: If selector doesn't match any element, returns error without scrolling
633
+
413
634
  ## Examples
414
635
 
415
636
  See the `examples/` directory for complete usage examples: