@opentiny/next-sdk 0.3.3 → 0.4.1
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/agent/AgentModelProvider.ts +78 -81
- package/agent/type.ts +6 -9
- package/agent/utils/getAISDKTools.ts +0 -1
- package/agent/utils/getBuiltinMcpTools.ts +7 -7
- package/core.ts +1 -3
- package/dist/SimulatorMask-BHVXyogh-iNUb4dyF.js +361 -0
- package/dist/agent/type.d.ts +4 -12
- package/dist/agent/utils/getBuiltinMcpTools.d.ts +3 -3
- package/dist/core.d.ts +1 -1
- package/dist/core.js +18 -18
- package/dist/index-CXK8CcKq.js +6076 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +57 -2783
- package/dist/initialize-builtin-WebMCP-rALfqS-o.js +6389 -0
- package/dist/page-tools/a11y/build.d.ts +11 -0
- package/dist/page-tools/a11y/constants.d.ts +9 -0
- package/dist/page-tools/a11y/search.d.ts +17 -0
- package/dist/page-tools/a11y/types.d.ts +104 -0
- package/dist/page-tools/a11y/utils.d.ts +34 -0
- package/dist/page-tools/a11y/vnode.d.ts +37 -0
- package/dist/page-tools/a11y-tree.d.ts +12 -0
- package/dist/page-tools/bridge.d.ts +0 -6
- package/dist/page-tools/constants.d.ts +22 -0
- package/dist/page-tools/context.d.ts +28 -0
- package/dist/page-tools/handlers/browserState.d.ts +8 -0
- package/dist/page-tools/handlers/click.d.ts +8 -0
- package/dist/page-tools/handlers/executeJavascript.d.ts +8 -0
- package/dist/page-tools/handlers/fill.d.ts +8 -0
- package/dist/page-tools/handlers/scroll.d.ts +8 -0
- package/dist/page-tools/handlers/searchTree.d.ts +8 -0
- package/dist/page-tools/handlers/select.d.ts +8 -0
- package/dist/page-tools/initialize-builtin-WebMCP.d.ts +1 -0
- package/dist/page-tools/page-agent-highlight/index.d.ts +9 -0
- package/dist/page-tools/page-agent-mask/SimulatorMask.d.ts +14 -0
- package/dist/page-tools/page-agent-mask/checkDarkMode.d.ts +5 -0
- package/dist/page-tools/page-agent-tool.d.ts +4 -0
- package/dist/page-tools/page-state-cache.d.ts +36 -0
- package/dist/page-tools/schema.d.ts +43 -0
- package/dist/page-tools/utils/dom.d.ts +6 -0
- package/dist/page-tools/utils/scroll.d.ts +15 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.js +744 -0
- package/dist/utils/builtinProxy.d.ts +1 -1
- package/index.ts +2 -19
- package/package.json +14 -18
- package/page-tools/a11y/build.ts +70 -0
- package/page-tools/a11y/constants.ts +110 -0
- package/page-tools/a11y/search.ts +129 -0
- package/page-tools/a11y/types.ts +108 -0
- package/page-tools/a11y/utils.ts +266 -0
- package/page-tools/a11y/vnode.ts +229 -0
- package/page-tools/a11y-tree.ts +13 -0
- package/page-tools/bridge.ts +49 -15
- package/page-tools/constants.ts +72 -0
- package/page-tools/context.ts +13 -0
- package/page-tools/handlers/browserState.ts +12 -0
- package/page-tools/handlers/click.ts +26 -0
- package/page-tools/handlers/executeJavascript.ts +22 -0
- package/page-tools/handlers/fill.ts +60 -0
- package/page-tools/handlers/scroll.ts +66 -0
- package/page-tools/handlers/searchTree.ts +30 -0
- package/page-tools/handlers/select.ts +34 -0
- package/page-tools/initialize-builtin-WebMCP.ts +20 -0
- package/page-tools/page-agent-highlight/index.ts +198 -0
- package/page-tools/page-agent-mask/SimulatorMask.module.css +14 -0
- package/page-tools/page-agent-mask/SimulatorMask.ts +279 -0
- package/page-tools/page-agent-mask/checkDarkMode.ts +181 -0
- package/page-tools/page-agent-mask/cursor-border.svg +3 -0
- package/page-tools/page-agent-mask/cursor-fill.svg +5 -0
- package/page-tools/page-agent-mask/cursor.module.css +70 -0
- package/page-tools/page-agent-prompt.md +139 -0
- package/page-tools/page-agent-tool.ts +175 -0
- package/page-tools/page-state-cache.ts +78 -0
- package/page-tools/schema.ts +51 -0
- package/page-tools/utils/dom.ts +155 -0
- package/page-tools/utils/scroll.ts +58 -0
- package/runtime.ts +13 -0
- package/utils/builtinProxy.ts +45 -13
- package/vite.config.runtime.ts +22 -0
- package/vite.config.ts +52 -8
- package/McpSdk.ts +0 -14
- package/WebAgent.ts +0 -5
- package/WebMcp.ts +0 -20
- package/Zod.ts +0 -1
- package/dist/AgentModelProvider-CwqOT28f.js +0 -4198
- package/dist/McpSdk.d.ts +0 -14
- package/dist/WebAgent.d.ts +0 -5
- package/dist/WebMcp.d.ts +0 -20
- package/dist/Zod.d.ts +0 -1
- package/dist/index.es.dev.js +0 -53427
- package/dist/index.es.js +0 -42147
- package/dist/index.umd.dev.js +0 -53820
- package/dist/index.umd.js +0 -814
- package/dist/mcpsdk@1.25.3.dev.js +0 -22621
- package/dist/mcpsdk@1.25.3.es.dev.js +0 -22619
- package/dist/mcpsdk@1.25.3.es.js +0 -16802
- package/dist/mcpsdk@1.25.3.js +0 -43
- package/dist/transport/ExtensionClientTransport.d.ts +0 -24
- package/dist/transport/ExtensionContentServerTransport.d.ts +0 -39
- package/dist/transport/ExtensionPageServerTransport.d.ts +0 -36
- package/dist/transport/messages.d.ts +0 -9
- package/dist/vite.config.mcpSdk.d.ts +0 -2
- package/dist/vite.config.webAgent.d.ts +0 -2
- package/dist/vite.config.webMcp.d.ts +0 -2
- package/dist/vite.config.webMcpFull.d.ts +0 -2
- package/dist/vite.config.zod.d.ts +0 -2
- package/dist/webagent.dev.js +0 -47597
- package/dist/webagent.es.dev.js +0 -47204
- package/dist/webagent.es.js +0 -37494
- package/dist/webagent.js +0 -634
- package/dist/webmcp-full.dev.js +0 -24430
- package/dist/webmcp-full.es.dev.js +0 -24426
- package/dist/webmcp-full.es.js +0 -18333
- package/dist/webmcp-full.js +0 -43
- package/dist/webmcp.dev.js +0 -1595
- package/dist/webmcp.es.dev.js +0 -1589
- package/dist/webmcp.es.js +0 -1406
- package/dist/webmcp.js +0 -1
- package/dist/zod@3.25.76.dev.js +0 -4037
- package/dist/zod@3.25.76.es.dev.js +0 -4033
- package/dist/zod@3.25.76.es.js +0 -2945
- package/dist/zod@3.25.76.js +0 -1
- package/transport/ExtensionClientTransport.ts +0 -100
- package/transport/ExtensionContentServerTransport.ts +0 -162
- package/transport/ExtensionPageServerTransport.ts +0 -149
- package/transport/messages.ts +0 -63
- package/vite-build-tsc.ts +0 -63
- package/vite-env.d.ts +0 -5
- package/vite.config.mcpSdk.ts +0 -28
- package/vite.config.webAgent.ts +0 -19
- package/vite.config.webMcp.ts +0 -40
- package/vite.config.webMcpFull.ts +0 -19
- package/vite.config.zod.ts +0 -23
- /package/dist/{vite-build-tsc.d.ts → vite.config.runtime.d.ts} +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { Motion } from 'ai-motion'
|
|
2
|
+
|
|
3
|
+
import { isPageDark } from './checkDarkMode'
|
|
4
|
+
|
|
5
|
+
const injectStyles = `
|
|
6
|
+
.webmcp-page-agent-cursor {
|
|
7
|
+
position: absolute;
|
|
8
|
+
width: var(--cursor-size, 75px);
|
|
9
|
+
height: var(--cursor-size, 75px);
|
|
10
|
+
pointer-events: none;
|
|
11
|
+
z-index: 10000;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.webmcp-page-agent-cursorBorder {
|
|
15
|
+
position: absolute;
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
background: linear-gradient(45deg, rgb(57, 182, 255), rgb(189, 69, 251));
|
|
19
|
+
mask-image: url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");
|
|
20
|
+
mask-size: 100% 100%;
|
|
21
|
+
mask-repeat: no-repeat;
|
|
22
|
+
|
|
23
|
+
transform-origin: center;
|
|
24
|
+
transform: rotate(-90deg) scale(0.8);
|
|
25
|
+
margin-left: -10px;
|
|
26
|
+
margin-top: -18px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.webmcp-page-agent-cursorFilling {
|
|
30
|
+
position: absolute;
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: 100%;
|
|
33
|
+
background: url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3e%3cdefs%3e%3c/defs%3e%3cg%20xmlns='http://www.w3.org/2000/svg'%20style='filter:%20drop-shadow(light-dark(rgba(0,%200,%200,%200.4),%20rgba(237,%20237,%20237,%200.4))%203px%204px%204px);'%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='%23ffffff'%20stroke='none'%20style='fill:%20%23ffffff;'/%3e%3c/g%3e%3c/svg%3e");
|
|
34
|
+
background-size: 100% 100%;
|
|
35
|
+
background-repeat: no-repeat;
|
|
36
|
+
|
|
37
|
+
transform-origin: center;
|
|
38
|
+
transform: rotate(-90deg) scale(0.8);
|
|
39
|
+
margin-left: -10px;
|
|
40
|
+
margin-top: -18px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.webmcp-page-agent-cursorRipple {
|
|
44
|
+
position: absolute;
|
|
45
|
+
width: 100%;
|
|
46
|
+
height: 100%;
|
|
47
|
+
pointer-events: none;
|
|
48
|
+
margin-left: -50%;
|
|
49
|
+
margin-top: -50%;
|
|
50
|
+
|
|
51
|
+
&::after {
|
|
52
|
+
content: '';
|
|
53
|
+
opacity: 0;
|
|
54
|
+
position: absolute;
|
|
55
|
+
inset: 0;
|
|
56
|
+
border: 4px solid rgba(57, 182, 255, 1);
|
|
57
|
+
border-radius: 50%;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.webmcp-page-agent-cursor.clicking .webmcp-page-agent-cursorRipple::after {
|
|
62
|
+
animation: webmcp-page-agent-cursor-ripple 300ms ease-out forwards;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@keyframes webmcp-page-agent-cursor-ripple {
|
|
66
|
+
0% {
|
|
67
|
+
transform: scale(0);
|
|
68
|
+
opacity: 1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
100% {
|
|
72
|
+
transform: scale(2);
|
|
73
|
+
opacity: 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.webmcp-page-agent-wrapper {
|
|
78
|
+
position: fixed;
|
|
79
|
+
inset: 0;
|
|
80
|
+
z-index: 2147483641;
|
|
81
|
+
/* 确保在所有元素之上,除了 panel */
|
|
82
|
+
cursor: wait;
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
|
|
85
|
+
display: none;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.webmcp-page-agent-wrapper.visible {
|
|
89
|
+
display: block;
|
|
90
|
+
}
|
|
91
|
+
`
|
|
92
|
+
|
|
93
|
+
export class SimulatorMask extends EventTarget {
|
|
94
|
+
shown: boolean = false
|
|
95
|
+
wrapper = document.createElement('div')
|
|
96
|
+
motion: Motion | null = null
|
|
97
|
+
|
|
98
|
+
#disposed = false
|
|
99
|
+
|
|
100
|
+
#cursor = document.createElement('div')
|
|
101
|
+
|
|
102
|
+
#currentCursorX = 0
|
|
103
|
+
#currentCursorY = 0
|
|
104
|
+
|
|
105
|
+
#targetCursorX = 0
|
|
106
|
+
#targetCursorY = 0
|
|
107
|
+
|
|
108
|
+
constructor() {
|
|
109
|
+
super()
|
|
110
|
+
// 注入样式,防止打包失败
|
|
111
|
+
document.head.appendChild(document.createElement('style')).textContent = injectStyles
|
|
112
|
+
this.wrapper.id = 'page-agent-runtime_simulator-mask'
|
|
113
|
+
this.wrapper.className = 'webmcp-page-agent-wrapper'
|
|
114
|
+
this.wrapper.setAttribute('data-browser-use-ignore', 'true')
|
|
115
|
+
this.wrapper.setAttribute('data-page-agent-ignore', 'true')
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const motion = new Motion({
|
|
119
|
+
mode: isPageDark() ? 'dark' : 'light',
|
|
120
|
+
styles: { position: 'absolute', inset: '0' }
|
|
121
|
+
})
|
|
122
|
+
this.motion = motion
|
|
123
|
+
this.wrapper.appendChild(motion.element)
|
|
124
|
+
motion.autoResize(this.wrapper)
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.warn('[SimulatorMask] Motion overlay unavailable:', e)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const stopEvent = (e: Event) => {
|
|
130
|
+
e.stopPropagation()
|
|
131
|
+
e.preventDefault()
|
|
132
|
+
}
|
|
133
|
+
;['click', 'mousedown', 'mouseup', 'mousemove', 'wheel', 'keydown', 'keyup'].forEach((eventName) =>
|
|
134
|
+
this.wrapper.addEventListener(eventName, stopEvent)
|
|
135
|
+
)
|
|
136
|
+
// Create AI cursor
|
|
137
|
+
this.#createCursor()
|
|
138
|
+
// this.show()
|
|
139
|
+
|
|
140
|
+
document.body.appendChild(this.wrapper)
|
|
141
|
+
|
|
142
|
+
this.#moveCursorToTarget()
|
|
143
|
+
|
|
144
|
+
// global events
|
|
145
|
+
// @note Mask should be isolated from the rest of the code.
|
|
146
|
+
// Global events are easier to manage and cleanup.
|
|
147
|
+
|
|
148
|
+
const movePointerToListener = (event: Event) => {
|
|
149
|
+
const { x, y } = (event as CustomEvent).detail
|
|
150
|
+
this.setCursorPosition(x, y)
|
|
151
|
+
}
|
|
152
|
+
const clickPointerListener = () => {
|
|
153
|
+
this.triggerClickAnimation()
|
|
154
|
+
}
|
|
155
|
+
const enablePassThroughListener = () => {
|
|
156
|
+
this.wrapper.style.pointerEvents = 'none'
|
|
157
|
+
}
|
|
158
|
+
const disablePassThroughListener = () => {
|
|
159
|
+
this.wrapper.style.pointerEvents = 'auto'
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
window.addEventListener('PageAgent::MovePointerTo', movePointerToListener)
|
|
163
|
+
window.addEventListener('PageAgent::ClickPointer', clickPointerListener)
|
|
164
|
+
window.addEventListener('PageAgent::EnablePassThrough', enablePassThroughListener)
|
|
165
|
+
window.addEventListener('PageAgent::DisablePassThrough', disablePassThroughListener)
|
|
166
|
+
|
|
167
|
+
this.addEventListener('dispose', () => {
|
|
168
|
+
window.removeEventListener('PageAgent::MovePointerTo', movePointerToListener)
|
|
169
|
+
window.removeEventListener('PageAgent::ClickPointer', clickPointerListener)
|
|
170
|
+
window.removeEventListener('PageAgent::EnablePassThrough', enablePassThroughListener)
|
|
171
|
+
window.removeEventListener('PageAgent::DisablePassThrough', disablePassThroughListener)
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#createCursor() {
|
|
176
|
+
this.#cursor.className = 'webmcp-page-agent-cursor'
|
|
177
|
+
|
|
178
|
+
// Create ripple effect container
|
|
179
|
+
const rippleContainer = document.createElement('div')
|
|
180
|
+
rippleContainer.className = 'webmcp-page-agent-cursorRipple'
|
|
181
|
+
this.#cursor.appendChild(rippleContainer)
|
|
182
|
+
|
|
183
|
+
// Create filling layer
|
|
184
|
+
const fillingLayer = document.createElement('div')
|
|
185
|
+
fillingLayer.className = 'webmcp-page-agent-cursorFilling'
|
|
186
|
+
this.#cursor.appendChild(fillingLayer)
|
|
187
|
+
|
|
188
|
+
// Create border layer
|
|
189
|
+
const borderLayer = document.createElement('div')
|
|
190
|
+
borderLayer.className = 'webmcp-page-agent-cursorBorder'
|
|
191
|
+
this.#cursor.appendChild(borderLayer)
|
|
192
|
+
|
|
193
|
+
this.wrapper.appendChild(this.#cursor)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#moveCursorToTarget() {
|
|
197
|
+
if (this.#disposed) return
|
|
198
|
+
|
|
199
|
+
const newX = this.#currentCursorX + (this.#targetCursorX - this.#currentCursorX) * 0.2
|
|
200
|
+
const newY = this.#currentCursorY + (this.#targetCursorY - this.#currentCursorY) * 0.2
|
|
201
|
+
|
|
202
|
+
const xDistance = Math.abs(newX - this.#targetCursorX)
|
|
203
|
+
if (xDistance > 0) {
|
|
204
|
+
if (xDistance < 2) {
|
|
205
|
+
this.#currentCursorX = this.#targetCursorX
|
|
206
|
+
} else {
|
|
207
|
+
this.#currentCursorX = newX
|
|
208
|
+
}
|
|
209
|
+
this.#cursor.style.left = `${this.#currentCursorX}px`
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const yDistance = Math.abs(newY - this.#targetCursorY)
|
|
213
|
+
if (yDistance > 0) {
|
|
214
|
+
if (yDistance < 2) {
|
|
215
|
+
this.#currentCursorY = this.#targetCursorY
|
|
216
|
+
} else {
|
|
217
|
+
this.#currentCursorY = newY
|
|
218
|
+
}
|
|
219
|
+
this.#cursor.style.top = `${this.#currentCursorY}px`
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
requestAnimationFrame(() => this.#moveCursorToTarget())
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
setCursorPosition(x: number, y: number) {
|
|
226
|
+
if (this.#disposed) return
|
|
227
|
+
|
|
228
|
+
this.#targetCursorX = x
|
|
229
|
+
this.#targetCursorY = y
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
triggerClickAnimation() {
|
|
233
|
+
if (this.#disposed) return
|
|
234
|
+
|
|
235
|
+
this.#cursor.classList.remove('clicking')
|
|
236
|
+
// Force reflow to restart animation
|
|
237
|
+
void this.#cursor.offsetHeight
|
|
238
|
+
this.#cursor.classList.add('clicking')
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
show() {
|
|
242
|
+
if (this.shown || this.#disposed) return
|
|
243
|
+
|
|
244
|
+
this.shown = true
|
|
245
|
+
this.motion?.start()
|
|
246
|
+
this.motion?.fadeIn()
|
|
247
|
+
|
|
248
|
+
this.wrapper.classList.add('visible')
|
|
249
|
+
|
|
250
|
+
// Initialize cursor position
|
|
251
|
+
this.#currentCursorX = window.innerWidth / 2
|
|
252
|
+
this.#currentCursorY = window.innerHeight / 2
|
|
253
|
+
this.#targetCursorX = this.#currentCursorX
|
|
254
|
+
this.#targetCursorY = this.#currentCursorY
|
|
255
|
+
this.#cursor.style.left = `${this.#currentCursorX}px`
|
|
256
|
+
this.#cursor.style.top = `${this.#currentCursorY}px`
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
hide() {
|
|
260
|
+
if (!this.shown || this.#disposed) return
|
|
261
|
+
|
|
262
|
+
this.shown = false
|
|
263
|
+
this.motion?.fadeOut()
|
|
264
|
+
this.motion?.pause()
|
|
265
|
+
|
|
266
|
+
this.#cursor.classList.remove('clicking')
|
|
267
|
+
|
|
268
|
+
setTimeout(() => {
|
|
269
|
+
this.wrapper.classList.remove('visible')
|
|
270
|
+
}, 800) // Match the animation duration
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
dispose() {
|
|
274
|
+
this.#disposed = true
|
|
275
|
+
this.motion?.dispose()
|
|
276
|
+
this.wrapper.remove()
|
|
277
|
+
this.dispatchEvent(new Event('dispose'))
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A comprehensive function to determine if the page is currently in a dark theme.
|
|
3
|
+
* Heuristic check. Only work for common patterns. Return false by default.
|
|
4
|
+
*/
|
|
5
|
+
export function isPageDark() {
|
|
6
|
+
try {
|
|
7
|
+
if (hasDarkModeClass()) return true
|
|
8
|
+
if (hasDarkModeDataAttribute()) return true
|
|
9
|
+
if (isColorSchemeDark()) return true
|
|
10
|
+
if (isBackgroundDark()) return true
|
|
11
|
+
if (isMainContentBackgroundDark()) return true
|
|
12
|
+
if (isTextColorLight()) return true
|
|
13
|
+
|
|
14
|
+
return false
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.warn('Error determining if page is dark:', error)
|
|
17
|
+
return false
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Checks for common dark mode CSS classes on the html or body elements.
|
|
23
|
+
*/
|
|
24
|
+
function hasDarkModeClass() {
|
|
25
|
+
const DEFAULT_DARK_MODE_CLASSES = ['dark', 'dark-mode', 'theme-dark', 'night', 'night-mode']
|
|
26
|
+
|
|
27
|
+
const htmlElement = document.documentElement
|
|
28
|
+
const bodyElement = document.body || document.documentElement // can be null in some cases
|
|
29
|
+
|
|
30
|
+
// Check class names on <html> and <body>
|
|
31
|
+
for (const className of DEFAULT_DARK_MODE_CLASSES) {
|
|
32
|
+
if (htmlElement.classList.contains(className) || bodyElement?.classList.contains(className)) {
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Some UI frameworks use data attributes to indicate theme
|
|
42
|
+
*/
|
|
43
|
+
function hasDarkModeDataAttribute() {
|
|
44
|
+
const htmlElement = document.documentElement
|
|
45
|
+
const bodyElement = document.body || document.documentElement // can be null in some cases
|
|
46
|
+
|
|
47
|
+
const dataAttrs = ['data-theme', 'data-color-mode', 'data-bs-theme', 'data-mui-color-scheme']
|
|
48
|
+
for (const attr of dataAttrs) {
|
|
49
|
+
const bodyValue = bodyElement?.getAttribute(attr)
|
|
50
|
+
const htmlValue = htmlElement.getAttribute(attr)
|
|
51
|
+
|
|
52
|
+
if (bodyValue?.toLowerCase() === 'dark' || htmlValue?.toLowerCase() === 'dark') {
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Checks the CSS `color-scheme` property and `<meta name="color-scheme">` tag.
|
|
62
|
+
* Only "dark"/"only dark" counts as dark; "light dark" is ambiguous and ignored.
|
|
63
|
+
*/
|
|
64
|
+
function isColorSchemeDark() {
|
|
65
|
+
// Check <meta name="color-scheme" content="dark">
|
|
66
|
+
const meta = document.querySelector<HTMLMetaElement>('meta[name="color-scheme"]')
|
|
67
|
+
const metaContent = meta?.content.toLowerCase()
|
|
68
|
+
if (metaContent === 'dark' || metaContent === 'only dark') return true
|
|
69
|
+
|
|
70
|
+
// Check the computed color-scheme CSS property on :root
|
|
71
|
+
const rootStyle = window.getComputedStyle(document.documentElement)
|
|
72
|
+
const colorScheme = rootStyle.getPropertyValue('color-scheme').trim().toLowerCase()
|
|
73
|
+
return colorScheme === 'dark' || colorScheme === 'only dark'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Checks the background color of the body element to determine if the page is dark.
|
|
78
|
+
*/
|
|
79
|
+
function isBackgroundDark() {
|
|
80
|
+
// We check both <html> and <body> because some pages set the color on <html>
|
|
81
|
+
const htmlStyle = window.getComputedStyle(document.documentElement)
|
|
82
|
+
const bodyStyle = window.getComputedStyle(document.body || document.documentElement)
|
|
83
|
+
|
|
84
|
+
// Get background colors
|
|
85
|
+
const htmlBgColor = htmlStyle.backgroundColor
|
|
86
|
+
const bodyBgColor = bodyStyle.backgroundColor
|
|
87
|
+
|
|
88
|
+
// The body's background might be transparent, in which case we should
|
|
89
|
+
// fall back to the html element's background.
|
|
90
|
+
if (isColorDark(bodyBgColor)) {
|
|
91
|
+
return true
|
|
92
|
+
} else if (bodyBgColor === 'transparent' || bodyBgColor.startsWith('rgba(0, 0, 0, 0)')) {
|
|
93
|
+
return isColorDark(htmlBgColor)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Checks if the text color on the body is light, which implies a dark background.
|
|
101
|
+
*/
|
|
102
|
+
function isTextColorLight() {
|
|
103
|
+
/** Luminance (0-255) above which body text is considered light */
|
|
104
|
+
const LIGHT_TEXT_LUMINANCE = 200
|
|
105
|
+
|
|
106
|
+
const bodyStyle = window.getComputedStyle(document.body || document.documentElement)
|
|
107
|
+
const luminance = getLuminance(bodyStyle.color)
|
|
108
|
+
|
|
109
|
+
// Light text has high luminance (e.g. white text on dark bg)
|
|
110
|
+
return luminance !== null && luminance > LIGHT_TEXT_LUMINANCE
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Checks the background color of major layout elements (#app, #root, etc.).
|
|
115
|
+
* Many SPAs render into a container that may have its own dark background while
|
|
116
|
+
* <body> remains transparent.
|
|
117
|
+
*/
|
|
118
|
+
function isMainContentBackgroundDark() {
|
|
119
|
+
const { innerWidth: vw, innerHeight: vh } = window
|
|
120
|
+
const minArea = vw * vh * 0.5
|
|
121
|
+
|
|
122
|
+
const selectors = ['#app', '#root', '#__next']
|
|
123
|
+
for (const selector of selectors) {
|
|
124
|
+
const el = document.querySelector(selector)
|
|
125
|
+
if (!el) continue
|
|
126
|
+
|
|
127
|
+
const rect = el.getBoundingClientRect()
|
|
128
|
+
if (rect.width * rect.height < minArea) continue
|
|
129
|
+
|
|
130
|
+
if (isColorDark(window.getComputedStyle(el).backgroundColor)) return true
|
|
131
|
+
}
|
|
132
|
+
return false
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// --- utils ---
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Parses an RGB or RGBA color string and returns an object with r, g, b properties.
|
|
139
|
+
* @param {string} colorString - e.g., "rgb(34, 34, 34)" or "rgba(0, 0, 0, 0.5)"
|
|
140
|
+
* @returns {{r: number, g: number, b: number}|null}
|
|
141
|
+
*/
|
|
142
|
+
function parseRgbColor(colorString: string) {
|
|
143
|
+
const rgbMatch = /rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(colorString)
|
|
144
|
+
if (!rgbMatch) {
|
|
145
|
+
return null // Not a valid rgb/rgba string
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
r: parseInt(rgbMatch[1]),
|
|
149
|
+
g: parseInt(rgbMatch[2]),
|
|
150
|
+
b: parseInt(rgbMatch[3]),
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Calculates the perceived luminance (0-255) of a CSS color string.
|
|
156
|
+
* @param {string} colorString - e.g., "rgb(50, 50, 50)" or "rgba(0, 0, 0, 0.5)"
|
|
157
|
+
* @returns {number|null} - The luminance, or null if the color is transparent or unparseable.
|
|
158
|
+
*/
|
|
159
|
+
function getLuminance(colorString: string): number | null {
|
|
160
|
+
if (!colorString || colorString === 'transparent' || colorString.startsWith('rgba(0, 0, 0, 0)')) {
|
|
161
|
+
return null // Transparent has no meaningful luminance
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const rgb = parseRgbColor(colorString)
|
|
165
|
+
if (!rgb) {
|
|
166
|
+
return null // Could not parse color
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Standard perceived luminance formula
|
|
170
|
+
return 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Determines if a color is "dark" based on its calculated luminance.
|
|
175
|
+
* @param {string} colorString - The CSS color string (e.g., "rgb(50, 50, 50)").
|
|
176
|
+
* @param {number} threshold - A value between 0 and 255. Colors with luminance below this will be considered dark. Default is 128.
|
|
177
|
+
*/
|
|
178
|
+
function isColorDark(colorString: string, threshold = 128) {
|
|
179
|
+
const luminance = getLuminance(colorString)
|
|
180
|
+
return luminance !== null && luminance < threshold
|
|
181
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none">
|
|
2
|
+
<g><path d="M 15 42 L 15 36.99 Q 15 31.99 23.7 31.99 L 28.05 31.99 Q 32.41 31.99 32.41 21.99 L 32.41 17 Q 32.41 12 41.09 16.95 L 76.31 37.05 Q 85 42 76.31 46.95 L 41.09 67.05 Q 32.41 72 32.41 62.01 L 32.41 57.01 Q 32.41 52.01 23.7 52.01 L 19.35 52.01 Q 15 52.01 15 47.01 Z" fill="none" stroke="#000000" stroke-width="6" stroke-miterlimit="10" style="stroke: light-dark(rgb(0, 0, 0), rgb(255, 255, 255));"/></g>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
|
2
|
+
<defs>
|
|
3
|
+
</defs>
|
|
4
|
+
<g xmlns="http://www.w3.org/2000/svg" style="filter: drop-shadow(light-dark(rgba(0, 0, 0, 0.4), rgba(237, 237, 237, 0.4)) 3px 4px 4px);"><path d="M 15 42 L 15 36.99 Q 15 31.99 23.7 31.99 L 28.05 31.99 Q 32.41 31.99 32.41 21.99 L 32.41 17 Q 32.41 12 41.09 16.95 L 76.31 37.05 Q 85 42 76.31 46.95 L 41.09 67.05 Q 32.41 72 32.41 62.01 L 32.41 57.01 Q 32.41 52.01 23.7 52.01 L 19.35 52.01 Q 15 52.01 15 47.01 Z" fill="#ffffff" stroke="none" style="fill: #ffffff;"/></g>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
.webmcp-page-agent-cursor {
|
|
2
|
+
position: absolute;
|
|
3
|
+
width: var(--cursor-size, 75px);
|
|
4
|
+
height: var(--cursor-size, 75px);
|
|
5
|
+
pointer-events: none;
|
|
6
|
+
z-index: 10000;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.webmcp-page-agent-cursorBorder {
|
|
10
|
+
position: absolute;
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
background: linear-gradient(45deg, rgb(57, 182, 255), rgb(189, 69, 251));
|
|
14
|
+
mask-image: url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%20fill='none'%3e%3cg%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='none'%20stroke='%23000000'%20stroke-width='6'%20stroke-miterlimit='10'%20style='stroke:%20light-dark(rgb(0,%200,%200),%20rgb(255,%20255,%20255));'/%3e%3c/g%3e%3c/svg%3e");
|
|
15
|
+
mask-size: 100% 100%;
|
|
16
|
+
mask-repeat: no-repeat;
|
|
17
|
+
|
|
18
|
+
transform-origin: center;
|
|
19
|
+
transform: rotate(-90deg) scale(0.8);
|
|
20
|
+
margin-left: -10px;
|
|
21
|
+
margin-top: -18px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.webmcp-page-agent-cursorFilling {
|
|
25
|
+
position: absolute;
|
|
26
|
+
width: 100%;
|
|
27
|
+
height: 100%;
|
|
28
|
+
background: url("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3e%3cdefs%3e%3c/defs%3e%3cg%20xmlns='http://www.w3.org/2000/svg'%20style='filter:%20drop-shadow(light-dark(rgba(0,%200,%200,%200.4),%20rgba(237,%20237,%20237,%200.4))%203px%204px%204px);'%3e%3cpath%20d='M%2015%2042%20L%2015%2036.99%20Q%2015%2031.99%2023.7%2031.99%20L%2028.05%2031.99%20Q%2032.41%2031.99%2032.41%2021.99%20L%2032.41%2017%20Q%2032.41%2012%2041.09%2016.95%20L%2076.31%2037.05%20Q%2085%2042%2076.31%2046.95%20L%2041.09%2067.05%20Q%2032.41%2072%2032.41%2062.01%20L%2032.41%2057.01%20Q%2032.41%2052.01%2023.7%2052.01%20L%2019.35%2052.01%20Q%2015%2052.01%2015%2047.01%20Z'%20fill='%23ffffff'%20stroke='none'%20style='fill:%20%23ffffff;'/%3e%3c/g%3e%3c/svg%3e");
|
|
29
|
+
background-size: 100% 100%;
|
|
30
|
+
background-repeat: no-repeat;
|
|
31
|
+
|
|
32
|
+
transform-origin: center;
|
|
33
|
+
transform: rotate(-90deg) scale(0.8);
|
|
34
|
+
margin-left: -10px;
|
|
35
|
+
margin-top: -18px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.webmcp-page-agent-cursorRipple {
|
|
39
|
+
position: absolute;
|
|
40
|
+
width: 100%;
|
|
41
|
+
height: 100%;
|
|
42
|
+
pointer-events: none;
|
|
43
|
+
margin-left: -50%;
|
|
44
|
+
margin-top: -50%;
|
|
45
|
+
|
|
46
|
+
&::after {
|
|
47
|
+
content: '';
|
|
48
|
+
opacity: 0;
|
|
49
|
+
position: absolute;
|
|
50
|
+
inset: 0;
|
|
51
|
+
border: 4px solid rgba(57, 182, 255, 1);
|
|
52
|
+
border-radius: 50%;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.webmcp-page-agent-cursor.clicking .webmcp-page-agent-cursorRipple::after {
|
|
57
|
+
animation: webmcp-page-agent-cursor-ripple 300ms ease-out forwards;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@keyframes webmcp-page-agent-cursor-ripple {
|
|
61
|
+
0% {
|
|
62
|
+
transform: scale(0);
|
|
63
|
+
opacity: 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
100% {
|
|
67
|
+
transform: scale(2);
|
|
68
|
+
opacity: 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
## 角色
|
|
2
|
+
|
|
3
|
+
你是浏览器页面的操作工具,你拥有识别网页内容,点击,填写,选择下拉框和滚动页面等功能。
|
|
4
|
+
|
|
5
|
+
在执行页面操作之前,你必须先调用`browserState`工具一次,根据最新的网页状态,再调用操作动作,比如 'click','fill','select' 等动作。
|
|
6
|
+
|
|
7
|
+
<intro>
|
|
8
|
+
你擅长以下任务:
|
|
9
|
+
1. 导航复杂网站并提取精确信息
|
|
10
|
+
2. 自动化表单提交和交互式网页操作
|
|
11
|
+
3. 收集和保存信息
|
|
12
|
+
4. 在代理循环中有效运行
|
|
13
|
+
5. 高效执行多样化的网页任务
|
|
14
|
+
</intro>
|
|
15
|
+
|
|
16
|
+
<input>
|
|
17
|
+
在每一步,你的输入将包括:
|
|
18
|
+
1. <agent_history>:一个按时间顺序排列的事件流,包括你之前的操作及其结果。
|
|
19
|
+
2. <agent_state>:当前的 <user_request> 和 <step_info>。
|
|
20
|
+
3. <browser_state>:当前 URL、页面标题、可交互元素总数以及语义化 YAML 树。
|
|
21
|
+
</input>
|
|
22
|
+
|
|
23
|
+
<browser_state>
|
|
24
|
+
|
|
25
|
+
浏览器状态包含以下内容:
|
|
26
|
+
|
|
27
|
+
- url: 当前查看页面的 URL。
|
|
28
|
+
- title: 当前查看页面的标题。
|
|
29
|
+
- 可交互元素总数:带有 `#N` 标记的元素数量。
|
|
30
|
+
- YAML 树:页面的语义化结构,格式如下:
|
|
31
|
+
|
|
32
|
+
```yaml
|
|
33
|
+
- region:
|
|
34
|
+
- main:
|
|
35
|
+
- button #9 [cursor=pointer] "产品文档"
|
|
36
|
+
- button #47 [selected] [cursor=pointer] "40元/月 2核CPU 2GB内存"
|
|
37
|
+
- radio #53 [checked] [cursor=pointer] "自动生成密码"
|
|
38
|
+
- button #74 [cursor=pointer] "立即购买"
|
|
39
|
+
- generic #6 [cf-uba="serviceList..Flexus云服务"] "Flexus云服务"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
节点格式说明:
|
|
43
|
+
- `- role #N [token1] [token2] "accessible name"`
|
|
44
|
+
- `role`:ARIA 语义角色(如 button/link/radio/heading/listitem/generic 等)
|
|
45
|
+
- `#N`:可交互元素的唯一操作索引,**只有带 `#N` 的节点才能被操作**,操作时将 N 作为 `index` 参数传入
|
|
46
|
+
- `[token]`:可选 token,包括状态标记(如 `[checked]` `[selected]` `[disabled]` `[cursor=pointer]`)和定制属性(如 `[cf-uba="..."]`)
|
|
47
|
+
- `"accessible name"`:元素的语义化名称,**用双引号包裹**(通过 aria-label/aria-labelledby/innerText 等计算得出);无名称的节点此字段省略
|
|
48
|
+
- 缩进表示父子关系
|
|
49
|
+
|
|
50
|
+
</browser_state>
|
|
51
|
+
|
|
52
|
+
<responseMode>
|
|
53
|
+
|
|
54
|
+
`page-agent-tool` 支持 `responseMode` 参数,用于控制操作后返回的页面状态形式:
|
|
55
|
+
|
|
56
|
+
- **`diff`**(默认):仅返回自上一次状态以来的增量 DOM 差异,极大节省 Token。
|
|
57
|
+
- **`full`**:返回当前视口中完整的语义化 ARIA YAML 树。
|
|
58
|
+
- **`both`**:同时返回全量树和增量差异。
|
|
59
|
+
|
|
60
|
+
执行 `click`、`fill`、`select`、`scroll` 操作后,工具默认自动以 `diff` 模式返回最新页面状态,无需再次手动调用 `browserState`。
|
|
61
|
+
|
|
62
|
+
</responseMode>
|
|
63
|
+
|
|
64
|
+
<browser_state_diff>
|
|
65
|
+
|
|
66
|
+
在交互过程中,为了提高效率和减少上下文占用,工具会生成页面的增量差异(Diff)信息。
|
|
67
|
+
Diff 格式示例如下:
|
|
68
|
+
```diff
|
|
69
|
+
- button #9: 产品文档
|
|
70
|
+
+ button #9: 产品文档 (已点击)
|
|
71
|
+
```
|
|
72
|
+
或者,当页面结构发生改变时,会展示新增或移除的节点差异。
|
|
73
|
+
|
|
74
|
+
### 页面状态获取四原则(重要,请严格遵守):
|
|
75
|
+
|
|
76
|
+
> 与业界 AI 编辑器(Cursor / Windsurf)按需读取文件而非全量加载的理念完全一致——**先精准搜索,再按需拉取全量**,将发送给大模型的 token 降至最低。
|
|
77
|
+
|
|
78
|
+
1. **按关键词精准搜索(最高优先级)**:当你已知要找什么类型的元素(如按钮、输入框、特定名称的链接)时,**优先使用 `searchTree` 动作**,传入 role 名称、元素文本或状态关键词搜索。它只返回命中行和上下文,token 消耗比全量树减少 80%+。
|
|
79
|
+
- 示例:查找所有按钮 → `{"action": "searchTree", "query": "button"}`
|
|
80
|
+
- 示例:查找含"提交"文本的节点 → `{"action": "searchTree", "query": "提交"}`
|
|
81
|
+
- 示例:查找已勾选的复选框 → `{"action": "searchTree", "query": "checked"}`
|
|
82
|
+
- 示例:精确定位某个 ref → `{"action": "searchTree", "query": "#5"}`
|
|
83
|
+
2. **首次获取全量**:首次进入页面、页面发生重大刷新、或 `searchTree` 无法找到所需信息时,调用 `browserState` 并指定 `responseMode` 为 `full` 或 `both` 获取完整 A11y 树。
|
|
84
|
+
3. **增量优先**:执行 `click`、`fill`、`select`、`scroll` 操作后,工具默认自动返回 `diff` 增量信息。优先阅读这些 Diff,以便快速确认操作是否生效。
|
|
85
|
+
4. **按需拉取全量**:如果增量 Diff 不足以支持下一步操作,或需要寻找不在 Diff 中的 `#N` 节点,且 `searchTree` 也无法定位时,再显式调用 `browserState` 拉取完整树。
|
|
86
|
+
|
|
87
|
+
</browser_state_diff>
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
<browser_rules>
|
|
92
|
+
在使用浏览器和浏览网页时严格遵守以下规则:
|
|
93
|
+
|
|
94
|
+
- 仅与分配有 `#N` 索引的元素进行交互,将 N 作为 `index` 参数传入。
|
|
95
|
+
- 仅使用明确出现在树中的 `#N` 索引,切勿猜测或沿用过期索引。
|
|
96
|
+
- 每次操作后 `#N` 索引会重新分配,不要使用旧的索引。
|
|
97
|
+
- 如果页面在执行操作后发生变化(例如输入文本操作),分析是否需要与新元素进行交互,例如从列表中选择正确的选项。
|
|
98
|
+
- 默认情况下,仅列出可见视口中的元素。如果你怀疑需要交互的相关内容在屏幕外,请使用滚动操作。仅在页面下方或上方还有更多像素时才滚动。
|
|
99
|
+
- 你可以使用 num_pages 参数滚动特定页数(例如,0.5 表示半页,2.0 表示两页)。
|
|
100
|
+
- 如果出现验证码,告诉用户你无法解决验证码。完成任务并请用户解决它。
|
|
101
|
+
- 如果缺少预期元素,尝试滚动或导航回退。
|
|
102
|
+
- 除非某些条件发生变化,否则不要重复同一操作超过 3 次。
|
|
103
|
+
- 如果你向输入字段填充文本且操作序列被中断,通常意味着某些内容发生了变化,例如下拉建议弹出。
|
|
104
|
+
- 如果 <user_request> 包含特定的页面信息,如产品类型、评分、价格、位置等,尝试应用过滤器以提高效率。
|
|
105
|
+
- <user_request> 是最终目标。如果用户指定了明确的步骤,它们始终具有最高优先级。
|
|
106
|
+
- 如果你向字段输入文本,可能需要按回车键、点击搜索按钮或从下拉列表中选择以完成操作。
|
|
107
|
+
- **不要通过 executeJavascript 向页面插入 DOM 元素**(如创建 div 显示调试信息)。这会污染页面结构并影响后续操作。如需读取数据,使用 return 语句返回结果即可。
|
|
108
|
+
- 如果操作返回中出现 `[校验提示]`,说明页面有表单校验错误未通过,请先根据提示修复错误后再继续操作。
|
|
109
|
+
- 如果操作后页面没有发生预期变化,优先检查是否有 `[校验提示]` 或 `[error]` token 的错误信息,而非重复操作。
|
|
110
|
+
- 如果不需要,不要登录页面。如果没有凭据,不要登录。
|
|
111
|
+
- 有两种类型的任务,首先思考你正在处理哪种类型的请求:
|
|
112
|
+
|
|
113
|
+
1. 非常具体的逐步说明:
|
|
114
|
+
|
|
115
|
+
- 非常精确地遵循它们,不要跳过步骤。尝试按要求完成所有内容。
|
|
116
|
+
|
|
117
|
+
2. 开放式任务。自己规划,在实现目标时保持创造性。
|
|
118
|
+
|
|
119
|
+
- 如果在开放式任务中陷入困境(例如登录或验证码),可以重新评估任务并尝试替代方法,例如有时即使页面的某些部分可访问或通过 Web 搜索获取一些信息,也会意外弹出登录框。
|
|
120
|
+
</browser_rules>
|
|
121
|
+
|
|
122
|
+
<capability>
|
|
123
|
+
- 你只能处理单页应用。不要跳出当前页面。
|
|
124
|
+
- 如果链接将在新页面中打开(例如,<a target="_blank">),不要点击该链接。
|
|
125
|
+
- 任务失败是可以接受的。
|
|
126
|
+
- 用户可能是错的。如果用户的请求无法实现、不适当,或者你没有足够的信息或工具来实现它。告诉用户提出更好的请求。
|
|
127
|
+
- 网页可能已损坏。所有网页或应用都有 bug。有些 bug 会使你的工作变得困难。鼓励你告诉用户当前页面的问题。你的反馈(包括失败)对用户很有价值。
|
|
128
|
+
- 过于努力可能有害。来回重复某些操作或在知识有限的情况下推动复杂程序可能导致不良结果和有害副作用。用户宁愿你以失败告终完成任务。
|
|
129
|
+
- 如果你对当前网页或任务没有相关知识。你必须要求用户提供具体说明和详细步骤。
|
|
130
|
+
</capability>
|
|
131
|
+
|
|
132
|
+
<task_completion_rules>
|
|
133
|
+
你必须在以下情况时结束任务:
|
|
134
|
+
|
|
135
|
+
- 当你完全完成用户请求时。
|
|
136
|
+
- 当你感到困惑或无法解决用户请求时。或者用户请求不清楚或包含不当内容。
|
|
137
|
+
- 如果绝对不可能继续。
|
|
138
|
+
|
|
139
|
+
</task_completion_rules>
|