visual-overlay
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVisual Overlay for AgentPulse
AgentPulse视觉覆盖层
Add animated cursor, typing, and click effects to show users what the AI agent is doing.
为用户添加动画光标、打字和点击效果,展示AI Agent的操作过程。
Quick Start
快速开始
Add inside your :
VisualOverlayAgentPulseProvidertsx
import { AgentPulseProvider, VisualOverlay } from 'agentpulse';
function App() {
return (
<AgentPulseProvider endpoint="ws://localhost:3100/ws">
<VisualOverlay />
<MyApp />
</AgentPulseProvider>
);
}When an AI agent calls or , users see:
expose_setexpose_call- Animated cursor moving to the target element
- Character-by-character typing for text inputs
- Click ripple effects for button actions
在中添加:
AgentPulseProviderVisualOverlaytsx
import { AgentPulseProvider, VisualOverlay } from 'agentpulse';
function App() {
return (
<AgentPulseProvider endpoint="ws://localhost:3100/ws">
<VisualOverlay />
<MyApp />
</AgentPulseProvider>
);
}当AI Agent调用或时,用户将看到:
expose_setexpose_call- 动画光标移动到目标元素
- 文本输入的逐字打字效果
- 按钮操作的点击波纹效果
Configuration
配置选项
tsx
<VisualOverlay
enabled={true} // Master toggle (default: true)
cursor={true} // Show AI cursor (default: true)
clickRipple={true} // Show click effects (default: true)
typingAnimation={true} // Character-by-character typing (default: true)
typingSpeed={12} // Characters per second (default: 12)
/>tsx
<VisualOverlay
enabled={true} // 全局开关(默认值:true)
cursor={true} // 显示AI光标(默认值:true)
clickRipple={true} // 显示点击效果(默认值:true)
typingAnimation={true} // 逐字打字动画(默认值:true)
typingSpeed={12} // 每秒输入字符数(默认值:12)
/>Element Targeting
元素定位
The overlay finds elements using attributes.
data-agentpulse-id覆盖层通过属性查找元素。
data-agentpulse-idNaming Convention
命名规范
Format:
data-agentpulse-id="componentId-normalizedKey"Where = binding key with prefix removed, lowercased.
normalizedKeyset| Binding | Normalized Key | Attribute |
|---|---|---|
| | |
| | |
| | |
| | |
格式:
data-agentpulse-id="componentId-normalizedKey"其中 = 绑定键移除前缀后,转换为小写。
normalizedKeyset| 绑定方法 | 标准化键 | 属性值 |
|---|---|---|
| | |
| | |
| | |
| | |
Example
示例
tsx
function ContactForm() {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
useExpose('contact-form', {
setName: (v) => setName(v),
setEmail: (v) => setEmail(v),
submitForm: () => handleSubmit(),
});
return (
<form>
<input data-agentpulse-id="contact-form-name" value={name} />
<input data-agentpulse-id="contact-form-email" value={email} />
<button data-agentpulse-id="contact-form-submitform">Submit</button>
</form>
);
}tsx
function ContactForm() {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
useExpose('contact-form', {
setName: (v) => setName(v),
setEmail: (v) => setEmail(v),
submitForm: () => handleSubmit(),
});
return (
<form>
<input data-agentpulse-id="contact-form-name" value={name} />
<input data-agentpulse-id="contact-form-email" value={email} />
<button data-agentpulse-id="contact-form-submitform">Submit</button>
</form>
);
}Auto-Discovery Fallback Chain
自动发现回退机制
If is missing, the resolver tries (in order):
data-agentpulse-id[data-agentpulse-id="componentId-normalizedKey"]- Form container → input by name
[data-agentpulse-id="componentId"] - or
input[name="key"]textarea[name="key"] - or
getElementById(key)getElementById("componentId-key") - (case-insensitive)
input[placeholder*="key"] - (case-insensitive)
[aria-label*="key"] - Submit button detection for actions
submitForm - Open/close button detection for modal actions
如果缺少属性,解析器会按以下顺序尝试查找:
data-agentpulse-id[data-agentpulse-id="componentId-normalizedKey"]- 表单容器→ 通过name查找输入框
[data-agentpulse-id="componentId"] - 或
input[name="key"]textarea[name="key"] - 或
getElementById(key)getElementById("componentId-key") - (不区分大小写)
input[placeholder*="key"] - (不区分大小写)
[aria-label*="key"] - 为操作检测提交按钮
submitForm - 为模态框操作检测打开/关闭按钮
Custom CSS Selectors
自定义CSS选择器
For complex layouts where auto-discovery fails:
tsx
<VisualOverlay
targets={{
'contact-form': {
name: 'input[name="fullName"]',
email: 'input[type="email"]',
submit: 'button[type="submit"]',
},
'sidebar': {
toggle: '#sidebar-toggle',
},
}}
/>Or configure programmatically:
tsx
import { setAnimationConfig, clearAnimationConfig } from 'agentpulse';
setAnimationConfig({
'my-form': {
username: '#username-input',
password: '#password-input',
},
});
// Clear when done
clearAnimationConfig();对于自动发现失败的复杂布局:
tsx
<VisualOverlay
targets={{
'contact-form': {
name: 'input[name="fullName"]',
email: 'input[type="email"]',
submit: 'button[type="submit"]',
},
'sidebar': {
toggle: '#sidebar-toggle',
},
}}
/>或者通过编程方式配置:
tsx
import { setAnimationConfig, clearAnimationConfig } from 'agentpulse';
setAnimationConfig({
'my-form': {
username: '#username-input',
password: '#password-input',
},
});
// 使用完毕后清除
clearAnimationConfig();Common Patterns
常见模式
Form with Multiple Fields
多字段表单
tsx
useExpose('signup-form', {
setEmail: (v) => setEmail(v),
setPassword: (v) => setPassword(v),
submit: () => handleSubmit(),
});
// Add data attributes to each input
<input data-agentpulse-id="signup-form-email" />
<input data-agentpulse-id="signup-form-password" />
<button data-agentpulse-id="signup-form-submit">Sign Up</button>tsx
useExpose('signup-form', {
setEmail: (v) => setEmail(v),
setPassword: (v) => setPassword(v),
submit: () => handleSubmit(),
});
// 为每个输入框添加数据属性
<input data-agentpulse-id="signup-form-email" />
<input data-agentpulse-id="signup-form-password" />
<button data-agentpulse-id="signup-form-submit">Sign Up</button>Third-Party Component Libraries
第三方组件库
For MUI, Chakra, etc., wrap or pass the data attribute:
tsx
// MUI TextField
<TextField
inputProps={{ 'data-agentpulse-id': 'form-email' }}
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
// Or use CSS selector config
<VisualOverlay
targets={{
'form': {
email: '.MuiTextField-root input',
},
}}
/>对于MUI、Chakra等组件库,可包裹组件或传递数据属性:
tsx
// MUI TextField
<TextField
inputProps={{ 'data-agentpulse-id': 'form-email' }}
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
// 或使用CSS选择器配置
<VisualOverlay
targets={{
'form': {
email: '.MuiTextField-root input',
},
}}
/>Search Box
搜索框
tsx
useExpose('search', {
query,
setQuery,
search: () => performSearch(),
});
<input data-agentpulse-id="search-query" />
<button data-agentpulse-id="search-search">Search</button>tsx
useExpose('search', {
query,
setQuery,
search: () => performSearch(),
});
<input data-agentpulse-id="search-query" />
<button data-agentpulse-id="search-search">Search</button>Troubleshooting
故障排除
| Issue | Cause | Solution |
|---|---|---|
| Cursor goes to wrong element | Key mismatch | Check normalized key matches attribute |
| No animation on action | Missing attribute | Add |
| Animation on wrong form field | Duplicate attributes | Make each attribute unique per component |
| Third-party input not found | Nested DOM structure | Use CSS selector config |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 光标指向错误元素 | 键不匹配 | 检查标准化键是否与属性值匹配 |
| 操作时无动画 | 缺少属性 | 为元素添加 |
| 错误的表单字段触发动画 | 属性重复 | 确保每个组件的属性值唯一 |
| 第三方输入框未被找到 | DOM结构嵌套 | 使用CSS选择器配置 |
Debug Targeting
调试定位
Open browser console and look for resolver logs:
[TargetResolver] Found element for contact-form.name using selector: ...
[TargetResolver] Auto-discovered element for contact-form.email
[TargetResolver] No element found for contact-form.phone打开浏览器控制台,查看解析器日志:
[TargetResolver] Found element for contact-form.name using selector: ...
[TargetResolver] Auto-discovered element for contact-form.email
[TargetResolver] No element found for contact-form.phoneProcess
实施步骤
- Add VisualOverlay - Import and add inside AgentPulseProvider
- Identify target elements - Which inputs/buttons need animations?
- Add data attributes - Use
data-agentpulse-id="componentId-normalizedKey" - Test with agent - Call or
expose_setand verify animationsexpose_call - Configure fallbacks - Use CSS selectors for complex layouts
- 添加VisualOverlay - 导入并在AgentPulseProvider中添加该组件
- 确定目标元素 - 哪些输入框/按钮需要添加动画?
- 添加数据属性 - 使用格式
data-agentpulse-id="componentId-normalizedKey" - 与Agent配合测试 - 调用或
expose_set并验证动画效果expose_call - 配置回退方案 - 为复杂布局使用CSS选择器
More Details
更多详情
See for:
references/TARGETING_PATTERNS.md- Full fallback chain explanation
- Naming convention edge cases
- Third-party component strategies
- Debug techniques
请查看了解:
references/TARGETING_PATTERNS.md- 完整的回退机制说明
- 命名规范的边缘情况
- 第三方组件的适配策略
- 调试技巧