D2Snap banner
webfuse-com webfuse-com

D2Snap

AI community

Description

Beyond Pixels: Exploring DOM Downsampling for LLM-Based Web Agents

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

D2Snap

![Example of downsampling on an image (top) and a DOM (bottom)](./.github/downsampling-example.png)

**D2Snap** is a first-of-its-kind DOM downsampling algorithm, designed for use with LLM-based web agents.

Integrate

D2Snap.d2Snap(
  dom: DOM,
  rE: number, rA: number, rT: number,
  options?: Options
): Promise<{
  html: string;
  meta: {};
}>

D2Snap.adaptiveD2Snap(
  dom: DOM,
  maxTokens: number = 4096,
  maxIterations: number = 5,
  options?: Options
): Promise<{
  html: string;
  meta: {};
  parameters: {};
  adaptiveIterations: number;
}>
type DOM = Document | Element | string;
type Options = {
  debug?: boolean;             // false
  attributeScoring?: {         // compare src/var.ATTRIBUTE_SCORING.ts
    [ name: string ]: number;
  };
  skipMarkdown?: boolean;      // false
  skipTextRank?: boolean;      // false
  uniqueIDs?: boolean;         // false
};

The attribute scoring lookup table supports wildcards for `aria` and `data` (`{aria-|data-}*`).

Browser

Module

npm install webfuse-com/D2Snap

Install [jsdom](https://github.com/jsdom/jsdom) to use the library with Node.js:

npm install jsdom
import * as D2Snap from "@webfuse-com/d2snap";

Example


  

Our Pizza

Margherita

A simple classic: mozzarella, tomatoes and basil. An everyday choice!

Add

Capricciosa

A rich taste: mozzarella, ham, mushrooms, artichokes and olives. A true fav