hypha-debugger 0.1.1 → 0.1.3

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Element interaction actions: click, input, select, scroll.
3
+ * Adapted from @page-agent/page-controller (MIT License).
4
+ */
5
+ import type { InteractiveElementDomNode } from "./types.js";
6
+ export declare function getElementByIndex(selectorMap: Map<number, InteractiveElementDomNode>, index: number): HTMLElement;
7
+ export declare function scrollIntoViewIfNeeded(element: HTMLElement): Promise<void>;
8
+ export declare function clickElement(element: HTMLElement): Promise<void>;
9
+ export declare function inputTextElement(element: HTMLElement, text: string): Promise<void>;
10
+ export declare function selectOptionElement(selectElement: HTMLSelectElement, optionText: string): Promise<void>;
11
+ export declare function scrollVertically(down: boolean, scroll_amount: number, element?: HTMLElement | null): Promise<string>;
12
+ export declare function scrollHorizontally(right: boolean, scroll_amount: number, element?: HTMLElement | null): Promise<string>;
@@ -0,0 +1,31 @@
1
+ import type { FlatDomTree, InteractiveElementDomNode } from "./types.js";
2
+ export declare function resolveViewportExpansion(viewportExpansion?: number): number;
3
+ export interface DomConfig {
4
+ viewportExpansion?: number;
5
+ interactiveBlacklist?: (Element | (() => Element))[];
6
+ interactiveWhitelist?: (Element | (() => Element))[];
7
+ includeAttributes?: string[];
8
+ highlightOpacity?: number;
9
+ highlightLabelOpacity?: number;
10
+ }
11
+ export declare function getFlatTree(config: DomConfig): FlatDomTree;
12
+ interface TreeNode {
13
+ type: "text" | "element";
14
+ parent: TreeNode | null;
15
+ children: TreeNode[];
16
+ isVisible: boolean;
17
+ text?: string;
18
+ tagName?: string;
19
+ attributes?: Record<string, string>;
20
+ isInteractive?: boolean;
21
+ isTopElement?: boolean;
22
+ isNew?: boolean;
23
+ highlightIndex?: number;
24
+ extra?: Record<string, any>;
25
+ }
26
+ export declare function flatTreeToString(flatTree: FlatDomTree, includeAttributes?: string[]): string;
27
+ export declare const getAllTextTillNextClickableElement: (node: TreeNode, maxDepth?: number) => string;
28
+ export declare function getSelectorMap(flatTree: FlatDomTree): Map<number, InteractiveElementDomNode>;
29
+ export declare function getElementTextMap(simplifiedHTML: string): Map<number, string>;
30
+ export declare function cleanUpHighlights(): void;
31
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * PageController: manages DOM state and element interactions.
3
+ * Adapted from @page-agent/page-controller (MIT License).
4
+ *
5
+ * This wraps the smart DOM analysis (interactive element detection,
6
+ * indexed element map) and provides an API for external agents.
7
+ */
8
+ import * as dom from "./dom.js";
9
+ export interface PageControllerConfig extends dom.DomConfig {
10
+ }
11
+ export interface BrowserState {
12
+ url: string;
13
+ title: string;
14
+ header: string;
15
+ content: string;
16
+ footer: string;
17
+ element_count: number;
18
+ }
19
+ export interface ActionResult {
20
+ success: boolean;
21
+ message: string;
22
+ }
23
+ export declare class PageController {
24
+ private config;
25
+ private flatTree;
26
+ private selectorMap;
27
+ private elementTextMap;
28
+ private simplifiedHTML;
29
+ private isIndexed;
30
+ constructor(config?: PageControllerConfig);
31
+ /**
32
+ * Get structured browser state for LLM consumption.
33
+ * Builds the DOM tree, highlights interactive elements, and returns
34
+ * a simplified text representation with numeric indices.
35
+ */
36
+ getBrowserState(): Promise<BrowserState>;
37
+ /**
38
+ * Update DOM tree, returns simplified HTML for LLM.
39
+ */
40
+ updateTree(): Promise<string>;
41
+ cleanUpHighlights(): Promise<void>;
42
+ private assertIndexed;
43
+ /** Clean up highlights after performing an action. */
44
+ private cleanUpAfterAction;
45
+ clickElement(index: number): Promise<ActionResult>;
46
+ inputText(index: number, text: string): Promise<ActionResult>;
47
+ selectOption(index: number, optionText: string): Promise<ActionResult>;
48
+ scroll(options: {
49
+ direction: "up" | "down" | "left" | "right";
50
+ amount?: number;
51
+ index?: number;
52
+ }): Promise<ActionResult>;
53
+ dispose(): void;
54
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Page info utilities: viewport, scroll position, page dimensions.
3
+ * Adapted from @page-agent/page-controller (MIT License).
4
+ */
5
+ export interface PageScrollInfo {
6
+ viewport_width: number;
7
+ viewport_height: number;
8
+ page_width: number;
9
+ page_height: number;
10
+ scroll_x: number;
11
+ scroll_y: number;
12
+ pixels_above: number;
13
+ pixels_below: number;
14
+ pages_above: number;
15
+ pages_below: number;
16
+ total_pages: number;
17
+ current_page_position: number;
18
+ pixels_left: number;
19
+ pixels_right: number;
20
+ }
21
+ export declare function getPageScrollInfo(): PageScrollInfo;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Flat DOM tree types, adapted from @page-agent/page-controller.
3
+ * Original: https://github.com/alibaba/page-agent (MIT License)
4
+ */
5
+ export interface FlatDomTree {
6
+ rootId: string;
7
+ map: Record<string, DomNode>;
8
+ }
9
+ export type DomNode = TextDomNode | ElementDomNode | InteractiveElementDomNode;
10
+ export interface TextDomNode {
11
+ type: "TEXT_NODE";
12
+ text: string;
13
+ isVisible: boolean;
14
+ [key: string]: unknown;
15
+ }
16
+ export interface ElementDomNode {
17
+ tagName: string;
18
+ attributes?: Record<string, string>;
19
+ xpath?: string;
20
+ children?: string[];
21
+ isVisible?: boolean;
22
+ isTopElement?: boolean;
23
+ isInViewport?: boolean;
24
+ isNew?: boolean;
25
+ isInteractive?: false;
26
+ highlightIndex?: number;
27
+ extra?: Record<string, any>;
28
+ [key: string]: unknown;
29
+ }
30
+ export interface InteractiveElementDomNode {
31
+ tagName: string;
32
+ attributes?: Record<string, string>;
33
+ xpath?: string;
34
+ children?: string[];
35
+ isVisible?: boolean;
36
+ isTopElement?: boolean;
37
+ isInViewport?: boolean;
38
+ isInteractive: true;
39
+ highlightIndex: number;
40
+ ref: HTMLElement;
41
+ [key: string]: unknown;
42
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Get the current browser state: page info, scroll position, and a
3
+ * simplified HTML representation with all interactive elements indexed
4
+ * as [0], [1], [2], etc. Use the indices to call click_element_by_index,
5
+ * input_text, select_option, or scroll.
6
+ */
7
+ export declare function getBrowserState(viewport_only?: boolean): Promise<{
8
+ url: string;
9
+ title: string;
10
+ header: string;
11
+ content: string;
12
+ footer: string;
13
+ element_count: number;
14
+ }>;
15
+ export declare namespace getBrowserState {
16
+ var __schema__: {
17
+ name: string;
18
+ description: string;
19
+ parameters: {
20
+ type: string;
21
+ properties: {
22
+ viewport_only: {
23
+ type: string;
24
+ description: string;
25
+ };
26
+ };
27
+ };
28
+ };
29
+ }
30
+ /**
31
+ * Click an interactive element by its index from get_browser_state.
32
+ */
33
+ export declare function clickElementByIndex(index: number): Promise<{
34
+ success: boolean;
35
+ message: string;
36
+ }>;
37
+ export declare namespace clickElementByIndex {
38
+ var __schema__: {
39
+ name: string;
40
+ description: string;
41
+ parameters: {
42
+ type: string;
43
+ properties: {
44
+ index: {
45
+ type: string;
46
+ description: string;
47
+ };
48
+ };
49
+ required: string[];
50
+ };
51
+ };
52
+ }
53
+ /**
54
+ * Type text into an input, textarea, or contenteditable element by index.
55
+ */
56
+ export declare function inputText(index: number, text: string): Promise<{
57
+ success: boolean;
58
+ message: string;
59
+ }>;
60
+ export declare namespace inputText {
61
+ var __schema__: {
62
+ name: string;
63
+ description: string;
64
+ parameters: {
65
+ type: string;
66
+ properties: {
67
+ index: {
68
+ type: string;
69
+ description: string;
70
+ };
71
+ text: {
72
+ type: string;
73
+ description: string;
74
+ };
75
+ };
76
+ required: string[];
77
+ };
78
+ };
79
+ }
80
+ /**
81
+ * Select a dropdown option by element index and option text.
82
+ */
83
+ export declare function selectOption(index: number, option_text: string): Promise<{
84
+ success: boolean;
85
+ message: string;
86
+ }>;
87
+ export declare namespace selectOption {
88
+ var __schema__: {
89
+ name: string;
90
+ description: string;
91
+ parameters: {
92
+ type: string;
93
+ properties: {
94
+ index: {
95
+ type: string;
96
+ description: string;
97
+ };
98
+ option_text: {
99
+ type: string;
100
+ description: string;
101
+ };
102
+ };
103
+ required: string[];
104
+ };
105
+ };
106
+ }
107
+ /**
108
+ * Scroll the page or a specific scrollable container.
109
+ */
110
+ export declare function scroll(direction: "up" | "down" | "left" | "right", amount?: number, index?: number): Promise<{
111
+ success: boolean;
112
+ message: string;
113
+ }>;
114
+ export declare namespace scroll {
115
+ var __schema__: {
116
+ name: string;
117
+ description: string;
118
+ parameters: {
119
+ type: string;
120
+ properties: {
121
+ direction: {
122
+ type: string;
123
+ enum: string[];
124
+ description: string;
125
+ };
126
+ amount: {
127
+ type: string;
128
+ description: string;
129
+ };
130
+ index: {
131
+ type: string;
132
+ description: string;
133
+ };
134
+ };
135
+ required: string[];
136
+ };
137
+ };
138
+ }
139
+ /**
140
+ * Remove all visual element highlights/labels from the page.
141
+ */
142
+ export declare function removeHighlights(): Promise<{
143
+ success: boolean;
144
+ message: string;
145
+ }>;
146
+ export declare namespace removeHighlights {
147
+ var __schema__: {
148
+ name: string;
149
+ description: string;
150
+ parameters: {
151
+ type: string;
152
+ properties: {};
153
+ };
154
+ };
155
+ }
156
+ /**
157
+ * Dispose the page controller (for cleanup).
158
+ */
159
+ export declare function disposeController(): void;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Animated AI cursor overlay.
3
+ * Shows a smooth-moving cursor with click ripple animation.
4
+ * Adapted from @page-agent/page-controller (MIT License).
5
+ *
6
+ * The cursor is injected as a fixed overlay and listens for
7
+ * custom events dispatched by the page-controller actions.
8
+ */
9
+ export declare class AICursor {
10
+ private container;
11
+ private cursor;
12
+ private currentX;
13
+ private currentY;
14
+ private targetX;
15
+ private targetY;
16
+ private animating;
17
+ private visible;
18
+ private hideTimeout;
19
+ constructor();
20
+ moveTo(x: number, y: number): void;
21
+ private animateLoop;
22
+ triggerClickAnimation(): void;
23
+ destroy(): void;
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypha-debugger",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Injectable debugger for web pages and AI agents, powered by Hypha RPC",
5
5
  "type": "module",
6
6
  "main": "dist/hypha-debugger.js",