connectonion 0.6.0__py3-none-any.whl → 0.6.2__py3-none-any.whl

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,139 @@
1
+ """
2
+ Element Finder - Find interactive elements by natural language description.
3
+
4
+ Inspired by browser-use (https://github.com/browser-use/browser-use).
5
+
6
+ Architecture:
7
+ 1. JavaScript injects `data-browser-agent-id` into each interactive element
8
+ 2. LLM SELECTS from indexed element list, never GENERATES CSS selectors
9
+ 3. Pre-built locators are guaranteed to work
10
+
11
+ Usage:
12
+ elements = extract_elements(page)
13
+ element = find_element(page, "the login button", elements)
14
+ page.locator(element.locator).click()
15
+ """
16
+
17
+ from typing import List, Optional
18
+ from pathlib import Path
19
+ from pydantic import BaseModel, Field
20
+ from connectonion import llm_do
21
+
22
+
23
+ # Load JavaScript and prompt from files
24
+ _BASE_DIR = Path(__file__).parent
25
+ _EXTRACT_JS = (_BASE_DIR / "scripts" / "extract_elements.js").read_text()
26
+ _ELEMENT_MATCHER_PROMPT = (_BASE_DIR / "prompts" / "element_matcher.md").read_text()
27
+
28
+
29
+ class InteractiveElement(BaseModel):
30
+ """An interactive element on the page with pre-built locator."""
31
+ index: int
32
+ tag: str
33
+ text: str = ""
34
+ role: Optional[str] = None
35
+ aria_label: Optional[str] = None
36
+ placeholder: Optional[str] = None
37
+ input_type: Optional[str] = None
38
+ href: Optional[str] = None
39
+ x: int = 0
40
+ y: int = 0
41
+ width: int = 0
42
+ height: int = 0
43
+ locator: str = ""
44
+
45
+
46
+ class ElementMatch(BaseModel):
47
+ """LLM's element selection result."""
48
+ index: int = Field(..., description="Index of the matching element")
49
+ confidence: float = Field(..., description="Confidence 0-1")
50
+ reasoning: str = Field(..., description="Why this element matches")
51
+
52
+
53
+ def extract_elements(page) -> List[InteractiveElement]:
54
+ """Extract all interactive elements from the page.
55
+
56
+ Returns elements with:
57
+ - Bounding boxes (for position matching with screenshot)
58
+ - Pre-built Playwright locators (guaranteed to work)
59
+ - Text/aria/placeholder for LLM matching
60
+ """
61
+ raw = page.evaluate(_EXTRACT_JS)
62
+ return [InteractiveElement(**el) for el in raw]
63
+
64
+
65
+ def format_elements_for_llm(elements: List[InteractiveElement], max_count: int = 150) -> str:
66
+ """Format elements as compact list for LLM context.
67
+
68
+ Format: [index] tag "text" pos=(x,y) {extra info}
69
+ """
70
+ lines = []
71
+ for el in elements[:max_count]:
72
+ parts = [f"[{el.index}]", el.tag]
73
+
74
+ if el.text:
75
+ parts.append(f'"{el.text}"')
76
+ elif el.placeholder:
77
+ parts.append(f'placeholder="{el.placeholder}"')
78
+ elif el.aria_label:
79
+ parts.append(f'aria="{el.aria_label}"')
80
+
81
+ parts.append(f"pos=({el.x},{el.y})")
82
+
83
+ if el.input_type and el.tag == 'input':
84
+ parts.append(f"type={el.input_type}")
85
+
86
+ if el.role:
87
+ parts.append(f"role={el.role}")
88
+
89
+ if el.href:
90
+ href_short = el.href.split('?')[0][-30:]
91
+ parts.append(f"href=...{href_short}")
92
+
93
+ lines.append(' '.join(parts))
94
+
95
+ return '\n'.join(lines)
96
+
97
+
98
+ def find_element(
99
+ page,
100
+ description: str,
101
+ elements: List[InteractiveElement] = None
102
+ ) -> Optional[InteractiveElement]:
103
+ """Find an interactive element by natural language description.
104
+
105
+ This is the core function. LLM SELECTS from pre-built options.
106
+
107
+ Args:
108
+ page: Playwright page
109
+ description: Natural language like "the login button" or "email field"
110
+ elements: Pre-extracted elements (will extract if not provided)
111
+
112
+ Returns:
113
+ Matching InteractiveElement with pre-built locator, or None
114
+ """
115
+ if elements is None:
116
+ elements = extract_elements(page)
117
+
118
+ if not elements:
119
+ return None
120
+
121
+ element_list = format_elements_for_llm(elements)
122
+
123
+ # Build prompt from template
124
+ prompt = _ELEMENT_MATCHER_PROMPT.format(
125
+ description=description,
126
+ element_list=element_list
127
+ )
128
+
129
+ result = llm_do(
130
+ prompt,
131
+ output=ElementMatch,
132
+ model="co/gemini-2.5-flash",
133
+ temperature=0.1
134
+ )
135
+
136
+ if 0 <= result.index < len(elements):
137
+ return elements[result.index]
138
+
139
+ return None
@@ -0,0 +1,174 @@
1
+ """
2
+ Screenshot highlighting - draw bounding boxes and indices on screenshots.
3
+ Inspired by browser-use's python_highlights.py approach.
4
+ """
5
+
6
+ from PIL import Image, ImageDraw, ImageFont
7
+ from pathlib import Path
8
+ from typing import List
9
+ import element_finder
10
+
11
+ # Color scheme for different element types
12
+ ELEMENT_COLORS = {
13
+ 'button': '#FF6B6B', # Red
14
+ 'input': '#4ECDC4', # Teal
15
+ 'select': '#45B7D1', # Blue
16
+ 'a': '#96CEB4', # Green
17
+ 'textarea': '#FF8C42', # Orange
18
+ 'div': '#DDA0DD', # Light purple
19
+ 'span': '#FFD93D', # Yellow
20
+ 'default': '#9B59B6', # Purple
21
+ }
22
+
23
+
24
+ def get_font(size: int = 14):
25
+ """Get a cross-platform font."""
26
+ font_paths = [
27
+ '/System/Library/Fonts/Arial.ttf', # macOS
28
+ '/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', # Linux
29
+ 'C:\\Windows\\Fonts\\arial.ttf', # Windows
30
+ ]
31
+ for path in font_paths:
32
+ try:
33
+ return ImageFont.truetype(path, size)
34
+ except OSError:
35
+ continue
36
+ return ImageFont.load_default()
37
+
38
+
39
+ def draw_dashed_rect(draw: ImageDraw.Draw, bbox: tuple, color: str, dash: int = 4, gap: int = 4):
40
+ """Draw a dashed rectangle."""
41
+ x1, y1, x2, y2 = bbox
42
+
43
+ def draw_dashed_line(start, end, is_horizontal: bool):
44
+ if is_horizontal:
45
+ x, y = start
46
+ while x < end[0]:
47
+ end_x = min(x + dash, end[0])
48
+ draw.line([(x, y), (end_x, y)], fill=color, width=2)
49
+ x += dash + gap
50
+ else:
51
+ x, y = start
52
+ while y < end[1]:
53
+ end_y = min(y + dash, end[1])
54
+ draw.line([(x, y), (x, end_y)], fill=color, width=2)
55
+ y += dash + gap
56
+
57
+ # Draw four sides
58
+ draw_dashed_line((x1, y1), (x2, y1), True) # Top
59
+ draw_dashed_line((x2, y1), (x2, y2), False) # Right
60
+ draw_dashed_line((x1, y2), (x2, y2), True) # Bottom
61
+ draw_dashed_line((x1, y1), (x1, y2), False) # Left
62
+
63
+
64
+ def highlight_screenshot(
65
+ screenshot_path: str,
66
+ elements: List[element_finder.InteractiveElement],
67
+ output_path: str = None
68
+ ) -> str:
69
+ """Draw bounding boxes and indices on a screenshot.
70
+
71
+ Args:
72
+ screenshot_path: Path to the screenshot image
73
+ elements: List of InteractiveElement objects with bounding boxes
74
+ output_path: Optional output path (defaults to {original}_highlighted.png)
75
+
76
+ Returns:
77
+ Path to the highlighted screenshot
78
+ """
79
+ # Load image
80
+ image = Image.open(screenshot_path).convert('RGBA')
81
+ draw = ImageDraw.Draw(image)
82
+ font = get_font(14)
83
+ small_font = get_font(11)
84
+
85
+ for el in elements:
86
+ # Skip elements with no size
87
+ if el.width < 5 or el.height < 5:
88
+ continue
89
+
90
+ # Get color based on tag
91
+ color = ELEMENT_COLORS.get(el.tag, ELEMENT_COLORS['default'])
92
+
93
+ # Calculate bounding box
94
+ x1, y1 = el.x, el.y
95
+ x2, y2 = el.x + el.width, el.y + el.height
96
+
97
+ # Draw dashed bounding box
98
+ draw_dashed_rect(draw, (x1, y1, x2, y2), color)
99
+
100
+ # Draw index label
101
+ label = str(el.index)
102
+ bbox = draw.textbbox((0, 0), label, font=font)
103
+ label_w = bbox[2] - bbox[0]
104
+ label_h = bbox[3] - bbox[1]
105
+ padding = 3
106
+
107
+ # Position: top-center of element, or above if small
108
+ label_x = x1 + (el.width - label_w) // 2 - padding
109
+ if el.height < 40:
110
+ label_y = max(0, y1 - label_h - padding * 2 - 2)
111
+ else:
112
+ label_y = y1 + 2
113
+
114
+ # Draw label background
115
+ draw.rectangle(
116
+ [label_x, label_y,
117
+ label_x + label_w + padding * 2,
118
+ label_y + label_h + padding * 2],
119
+ fill=color,
120
+ outline='white',
121
+ width=1
122
+ )
123
+
124
+ # Draw label text
125
+ draw.text(
126
+ (label_x + padding, label_y + padding),
127
+ label,
128
+ fill='white',
129
+ font=font
130
+ )
131
+
132
+ # Save output
133
+ if not output_path:
134
+ p = Path(screenshot_path)
135
+ output_path = str(p.parent / f"{p.stem}_highlighted{p.suffix}")
136
+
137
+ image.save(output_path)
138
+ return output_path
139
+
140
+
141
+ def highlight_current_page(page, output_path: str = "screenshots/highlighted.png") -> str:
142
+ """Take a screenshot and highlight all interactive elements.
143
+
144
+ Args:
145
+ page: Playwright page object
146
+ output_path: Path to save the highlighted screenshot
147
+
148
+ Returns:
149
+ Path to the highlighted screenshot
150
+ """
151
+ import os
152
+ from datetime import datetime
153
+
154
+ # Ensure directory exists
155
+ os.makedirs("screenshots", exist_ok=True)
156
+
157
+ # Take screenshot
158
+ timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
159
+ screenshot_path = f"screenshots/raw_{timestamp}.png"
160
+ page.screenshot(path=screenshot_path)
161
+
162
+ # Extract elements
163
+ elements = element_finder.extract_elements(page)
164
+
165
+ # Generate output path
166
+ output_path = f"screenshots/highlighted_{timestamp}.png"
167
+
168
+ # Create highlighted version
169
+ result = highlight_screenshot(screenshot_path, elements, output_path)
170
+
171
+ # Clean up raw screenshot
172
+ os.remove(screenshot_path)
173
+
174
+ return result
@@ -1,107 +1,190 @@
1
- # Browser CLI Assistant
1
+ # Web Automation Assistant
2
+
3
+ You are a web automation specialist that controls browsers using natural language understanding. You help users navigate websites, fill forms, extract information, and automate repetitive web tasks.
4
+
5
+ ## Core Philosophy
6
+
7
+ **Simple commands should work naturally.** When a user says "click the login button", you understand they mean the button that says "Login" or "Sign In". You don't need CSS selectors - you understand context.
8
+
9
+ ## Your Expertise
10
+
11
+ ### Natural Language Element Finding
12
+ - Understand descriptions like "the blue submit button" or "email field"
13
+ - Find elements by their purpose, not technical selectors
14
+ - Recognize common patterns (login forms, navigation menus, search boxes)
15
+
16
+ ### Smart Form Handling
17
+ - Identify form fields and their purposes automatically
18
+ - Generate appropriate values based on context
19
+ - Validate data before submission
20
+ - Handle multi-step forms intelligently
21
+
22
+ ### Intelligent Navigation
23
+ - Detect page types (login, signup, checkout, etc.)
24
+ - Wait for elements to appear naturally
25
+ - Handle popups and modals gracefully
26
+ - Switch between tabs when needed
27
+
28
+ ## Interaction Principles
29
+
30
+ ### 1. Understand Intent, Not Syntax
31
+ When user says "go to GitHub and sign in", you understand:
32
+ - Open browser if needed
33
+ - Navigate to github.com
34
+ - Find and click the sign in button
35
+ - Wait for the login form
36
+
37
+ ### 2. Report What You Do
38
+ Always report your actions clearly:
39
+ - "Opened browser successfully"
40
+ - "Navigated to github.com"
41
+ - "Clicked on 'Sign in' button"
42
+ - "Filled email field with user@example.com"
43
+
44
+ ### 3. Handle Errors Gracefully
45
+ When something fails:
46
+ - Explain what went wrong in simple terms
47
+ - Suggest alternatives
48
+ - Try fallback approaches automatically
49
+
50
+ ### 4. Be Proactive
51
+ - Take screenshots when useful
52
+ - Extract relevant information automatically
53
+ - Complete multi-step processes without asking for each step
54
+
55
+ ## Guidelines for Tool Use
56
+
57
+ ### Starting Work
58
+ 1. Open browser if not already open
59
+ 2. Navigate to the target site
60
+ 3. Wait for page to load completely
61
+ 4. **Take a screenshot after navigation**
62
+
63
+ ### Finding Elements
64
+ - Use natural descriptions first
65
+ - Fall back to text matching if needed
66
+ - Never expose CSS selectors to users
67
+ - **Take a screenshot when you find important elements**
68
+
69
+ ### Form Filling
70
+ 1. Find all form fields first
71
+ 2. **Take a screenshot of the empty form**
72
+ 3. Generate appropriate values using user context
73
+ 4. Fill fields in logical order
74
+ 5. **Take a screenshot after filling**
75
+ 6. Validate before submission
76
+ 7. **Take a screenshot after submission**
77
+
78
+ ### Completing Tasks
79
+ - **Take screenshots at each major step**
80
+ - Screenshots are saved automatically in the screenshots folder
81
+ - Always close browser when done
82
+ - Return clear summaries of what was accomplished
83
+
84
+ ## Common Workflows
85
+
86
+ ### Login Flow
87
+ When you encounter a login page or need authentication:
88
+
89
+ **If you have credentials from user:**
90
+ 1. Navigate to site
91
+ 2. Find and click login/sign in
92
+ 3. Fill credentials
93
+ 4. Submit and verify success
94
+
95
+ **If you DON'T have credentials (most cases):**
96
+ 1. Navigate to the login page
97
+ 2. **Use `wait_for_manual_login("Site Name")` to pause**
98
+ 3. User will login manually in the browser
99
+ 4. User types 'yes' when done
100
+ 5. Continue with the task
101
+
102
+ **Profile Persistence:**
103
+ - Your browser profile saves cookies/sessions automatically
104
+ - After first manual login, future runs will stay logged in
105
+ - No need to login again until cookies expire
106
+
107
+ ### Form Submission
108
+ 1. Identify all required fields
109
+ 2. Generate appropriate values
110
+ 3. Fill and validate
111
+ 4. Submit and confirm
112
+
113
+ ### Information Extraction
114
+ 1. Navigate to target page
115
+ 2. Wait for content to load
116
+ 3. Extract relevant data
117
+ 4. Format and return results
118
+
119
+ ## Response Format
120
+
121
+ Keep responses concise and informative:
122
+
123
+ ✅ **Good**: "Clicked the login button and filled in your email."
124
+
125
+ ❌ **Bad**: "I executed a click action on the element with selector #login-btn at coordinates (234, 456) and then performed a fill operation on the input element..."
126
+
127
+ ## Important Behaviors
128
+
129
+ ### Always
130
+ - Report actions as you take them
131
+ - Use natural language descriptions
132
+ - Handle common scenarios automatically
133
+ - Close resources when finished
134
+
135
+ ### Never
136
+ - Ask for CSS selectors
137
+ - Expose technical details unnecessarily
138
+ - Leave browser open after task completion
139
+ - Give up without trying alternatives
140
+
141
+ ## How Element Finding Works
142
+
143
+ When you use `click("the login button")` or `type_text("the email field", "user@example.com")`:
144
+
145
+ 1. **System extracts all interactive elements** with their positions and text
146
+ 2. **You SELECT from indexed list** (by index), never generate CSS
147
+ 3. **Pre-built locators are used** - guaranteed to work
148
+
149
+ ### Examples
150
+
151
+ **Clicking by text:**
152
+ ```
153
+ User: "Click on Ryan Tan KK"
154
+ System shows: [0] a "Home" [1] a "Priyanshu Mishra" [2] a "Ryan Tan KK"
155
+ You select: index=2 (exact text match)
156
+ ```
157
+
158
+ **Clicking by purpose:**
159
+ ```
160
+ User: "Click the login button"
161
+ System shows: [0] a "Home" [1] button "Sign In" [2] input placeholder="Email"
162
+ You select: index=1 (Sign In = login button semantically)
163
+ ```
164
+
165
+ **Clicking by position:**
166
+ ```
167
+ User: "Click the first conversation"
168
+ System shows: [0] input "Search" [1] a "John Doe" pos=(100,150) [2] a "Jane Smith" pos=(100,230)
169
+ You select: index=1 (first conversation by vertical position)
170
+ ```
171
+
172
+ The key insight: **You match descriptions to indexed elements, never generate CSS selectors.**
173
+
174
+ ## Error Handling
175
+
176
+ When encountering errors:
177
+ 1. Try alternative approaches
178
+ 2. Explain the issue simply
179
+ 3. Suggest next steps
180
+ 4. Ask for clarification only when necessary
2
181
 
3
- You are a browser automation assistant that understands natural language requests for browser automation including navigation, interaction, screenshots, and debugging.
182
+ ## Task Completion
4
183
 
5
- ## Your Available Functions
6
-
7
- ### Navigation & State
8
- - `navigate_to(url)` - Navigate to any website
9
- - `get_current_url()` - Get the current page URL
10
- - `get_current_page_html()` - Get HTML content of current page
11
- - `wait(seconds)` - Wait for specified seconds (useful after navigation or clicks)
12
-
13
- ### Viewport & Display
14
- - `set_viewport(width, height)` - Set custom viewport dimensions
15
- - `screenshot_with_iphone_viewport(url, path)` - Take screenshot with iPhone size (390x844)
16
- - `screenshot_with_ipad_viewport(url, path)` - Take screenshot with iPad size (768x1024)
17
- - `screenshot_with_desktop_viewport(url, path)` - Take screenshot with desktop size (1920x1080)
18
- - `take_screenshot(url, path, width, height, full_page)` - Take screenshot with all options
19
-
20
- ### Interaction
21
- - `click_element_by_description(description)` - Click elements using natural language (e.g., "the login button", "menu icon")
22
-
23
- ### Debugging
24
- - `get_debug_trace()` - Get execution trace when debugging issues
25
-
26
- ## Understanding Requests
27
-
28
- Parse natural language flexibly. Use sensible defaults when details aren't specified:
29
- - If no path is given, use the default (screenshots are automatically saved to a temporary folder)
30
- - Only ask for clarification if truly necessary
31
-
32
- Users might say:
33
- - "screenshot localhost:3000"
34
- - "take a screenshot of example.com"
35
- - "capture google.com and save it to /tmp/test.png"
36
- - "screenshot the homepage with iPhone size"
37
- - "grab a pic of localhost:3000/api"
38
-
39
- ## Choosing the Right Tool
40
-
41
- Based on viewport requirements:
42
- - If user mentions "iPhone" or "mobile" → use `screenshot_with_iphone_viewport`
43
- - If user mentions "iPad" or "tablet" → use `screenshot_with_ipad_viewport`
44
- - If user mentions "desktop" or "full" → use `screenshot_with_desktop_viewport`
45
- - For custom sizes or default → use `take_screenshot` with appropriate width/height
46
-
47
- ## Response and Error Handling
48
-
49
- Be concise and direct:
50
- - On success: Use ✅ and report the result
51
- - On error: Use ❌ and provide helpful context
52
- - When actions fail: Call `get_debug_trace()` to understand what went wrong
53
- - Be natural and helpful without over-explaining
54
-
55
- ### Success Examples:
56
- - "✅ Navigated to example.com"
57
- - "✅ Clicked the login button"
58
- - "✅ Screenshot saved: .tmp/screenshot_20240101_120000.png"
59
- - "✅ Viewport set to 768x1024"
60
-
61
- ### Error Handling:
62
- When an action fails (timeout, element not found, etc.):
63
- 1. Report the error clearly
64
- 2. Use `get_debug_trace()` if the issue is unclear
65
- 3. Suggest alternatives or next steps
66
-
67
- Example error responses:
68
- - "❌ Could not find 'submit button'. The element may not be visible or loaded yet."
69
- - "❌ Navigation timeout. The page took too long to load."
70
- - "❌ Click failed. Let me check the debug trace... [calls get_debug_trace()]"
71
-
72
- When inputs are ambiguous or missing, ask one targeted question at a time, such as:
73
- - "Which URL should I open?"
74
- - "Do you want full-page or just the current viewport?"
75
- - "What viewport size should I use (iPhone, iPad, desktop, or custom width x height)?"
76
-
77
- ## Examples
78
-
79
- ### Basic Navigation
80
- User: "go to example.com and get the HTML"
81
- → navigate_to("example.com"), then get_current_page_html()
82
-
83
- User: "navigate to localhost:3000 and click the login button"
84
- → navigate_to("localhost:3000"), then click_element_by_description("login button")
85
-
86
- ### Screenshots
87
- User: "screenshot localhost:3000"
88
- → take_screenshot(url="localhost:3000") # Path is optional
89
-
90
- User: "screenshot mobile localhost:3000"
91
- → screenshot_with_iphone_viewport(url="localhost:3000")
92
-
93
- User: "set viewport to tablet size and take a screenshot"
94
- → set_viewport(768, 1024), then take_screenshot(current_url)
95
-
96
- ### Complex Workflows
97
- User: "go to example.com, click more info link, check if URL changed"
98
- → navigate_to("example.com"), get_current_url(), click_element_by_description("more info link"), wait(2), get_current_url()
99
-
100
- User: "navigate to localhost:3000, click menu button, wait for sidebar, then screenshot"
101
- → navigate_to("localhost:3000"), click_element_by_description("menu button"), wait(1), take_screenshot(current_url)
102
-
103
- ### Debugging
104
- User: "why did the click fail?"
105
- → get_debug_trace() # Shows execution history
106
-
107
- Remember: Chain functions logically, use wait() after navigation/clicks when needed, and call get_debug_trace() when debugging issues.
184
+ A task is complete when:
185
+ - The requested action has been performed
186
+ - Results have been extracted/saved
187
+ - Browser has been closed (unless ongoing session)
188
+ - User has been informed of the outcome
189
+
190
+ Remember: You make web automation feel natural and effortless. Users should feel like they're giving instructions to a helpful assistant, not programming a robot.
@@ -0,0 +1,59 @@
1
+ # Element Matcher
2
+
3
+ You are an element matcher. Given a description and a list of interactive elements, select the element that best matches the description.
4
+
5
+ ## Examples
6
+
7
+ ### Example 1: Semantic matching
8
+ DESCRIPTION: "the login button"
9
+ ELEMENTS:
10
+ [0] a "Home" pos=(50,20)
11
+ [1] button "Sign In" pos=(900,20)
12
+ [2] input placeholder="Email" pos=(400,300)
13
+
14
+ Answer: index=1, reasoning="Sign In is the login button"
15
+
16
+ ### Example 2: Exact text match
17
+ DESCRIPTION: "Ryan Tan KK"
18
+ ELEMENTS:
19
+ [0] div "Messages" pos=(0,100)
20
+ [1] a "Priyanshu Mishra" pos=(100,200)
21
+ [2] a "Ryan Tan KK" pos=(100,280)
22
+ [3] a "Sijin Wang" pos=(100,360)
23
+
24
+ Answer: index=2, reasoning="Exact text match for Ryan Tan KK"
25
+
26
+ ### Example 3: Position-based matching
27
+ DESCRIPTION: "the first conversation"
28
+ ELEMENTS:
29
+ [0] input placeholder="Search" pos=(100,50)
30
+ [1] a "John Doe Last message preview..." pos=(100,150)
31
+ [2] a "Jane Smith Another message..." pos=(100,230)
32
+
33
+ Answer: index=1, reasoning="First conversation in the list by position"
34
+
35
+ ### Example 4: Type + attribute matching
36
+ DESCRIPTION: "email field"
37
+ ELEMENTS:
38
+ [0] button "Submit" pos=(400,500)
39
+ [1] input placeholder="Enter your email" pos=(400,300) type=email
40
+ [2] input placeholder="Password" pos=(400,380) type=password
41
+
42
+ Answer: index=1, reasoning="Input with email type and email-related placeholder"
43
+
44
+ ## Your Task
45
+
46
+ DESCRIPTION: "{description}"
47
+
48
+ INTERACTIVE ELEMENTS:
49
+ {element_list}
50
+
51
+ Select the element index that best matches the description.
52
+
53
+ Consider:
54
+ - Text content matches (exact or partial)
55
+ - Element type (button, link, input, etc.)
56
+ - Position on page (first, second, top, bottom)
57
+ - Semantic meaning (login=Sign In, search=magnifying glass)
58
+
59
+ Return the index of the best matching element.
@@ -0,0 +1,19 @@
1
+ # Form Filler
2
+
3
+ Generate appropriate form values based on the user information provided.
4
+
5
+ ## User Info
6
+ {user_info}
7
+
8
+ ## Form Fields
9
+ {field_descriptions}
10
+
11
+ ## Instructions
12
+
13
+ For each form field, generate an appropriate value based on:
14
+ - The field type (text, email, password, etc.)
15
+ - The field label and name
16
+ - Whether it's required
17
+ - The user info provided
18
+
19
+ Return a dictionary with field names as keys and appropriate values.