agentpage 0.0.42 → 0.0.44
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/dist/index.mjs +43 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -225,6 +225,43 @@ function isPotentialDomMutation(toolName, toolInput) {
|
|
|
225
225
|
].includes(action);
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
|
+
* 判定动作是否为"确定性推进"——比 isPotentialDomMutation 更窄。
|
|
229
|
+
*
|
|
230
|
+
* 包含以下必定产生可见状态变化或属于显式用户意图的动作:
|
|
231
|
+
* - 表单输入类:fill / type / select_option / clear / check / uncheck
|
|
232
|
+
* - 键盘动作类:press(Enter 提交、Tab 切焦等均属用户显式操作)
|
|
233
|
+
* - 导航类:navigate.*
|
|
234
|
+
* - 自定义工具:非 SDK 内置工具(dom/navigate/page_info/wait/evaluate)
|
|
235
|
+
* 均由开发者注册、模型有意调用,视为确定性推进
|
|
236
|
+
*
|
|
237
|
+
* click 不在此列——因为 click 可能点了但完全没效果(如点击无 click listener 的元素)。
|
|
238
|
+
*
|
|
239
|
+
* 用途:协议缺失计数重置与豁免。仅当本轮有"确定性推进"时才重置协议缺失计数器,
|
|
240
|
+
* 避免模型反复点击无效目标导致死循环。
|
|
241
|
+
*/
|
|
242
|
+
function isConfirmedProgressAction(toolName, toolInput) {
|
|
243
|
+
if (toolName === "navigate") return true;
|
|
244
|
+
if (![
|
|
245
|
+
"dom",
|
|
246
|
+
"navigate",
|
|
247
|
+
"page_info",
|
|
248
|
+
"wait",
|
|
249
|
+
"evaluate"
|
|
250
|
+
].includes(toolName)) return true;
|
|
251
|
+
if (toolName !== "dom") return false;
|
|
252
|
+
const action = getToolAction(toolInput);
|
|
253
|
+
if (!action) return false;
|
|
254
|
+
return [
|
|
255
|
+
"fill",
|
|
256
|
+
"type",
|
|
257
|
+
"select_option",
|
|
258
|
+
"clear",
|
|
259
|
+
"check",
|
|
260
|
+
"uncheck",
|
|
261
|
+
"press"
|
|
262
|
+
].includes(action);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
228
265
|
* 采集找不到元素任务。
|
|
229
266
|
*
|
|
230
267
|
* 返回 null 表示当前结果不属于“元素未找到”,
|
|
@@ -949,6 +986,7 @@ async function executeAgentLoop(params) {
|
|
|
949
986
|
}
|
|
950
987
|
let roundHasError = false;
|
|
951
988
|
let roundHasPotentialDomMutation = false;
|
|
989
|
+
let roundHasConfirmedProgress = false;
|
|
952
990
|
const executedTaskCalls = [];
|
|
953
991
|
const roundMissingTasks = [];
|
|
954
992
|
for (const tc of response.toolCalls) {
|
|
@@ -980,6 +1018,7 @@ async function executeAgentLoop(params) {
|
|
|
980
1018
|
if (missingTask) roundMissingTasks.push(missingTask);
|
|
981
1019
|
if (result.details && typeof result.details === "object") roundHasError = roundHasError || Boolean(result.details.error);
|
|
982
1020
|
if (!hasToolError(result) && isPotentialDomMutation(tc.name, tc.input)) roundHasPotentialDomMutation = true;
|
|
1021
|
+
if (!hasToolError(result) && isConfirmedProgressAction(tc.name, tc.input)) roundHasConfirmedProgress = true;
|
|
983
1022
|
if (tc.name === "page_info" && getToolAction(tc.input) === "snapshot") {
|
|
984
1023
|
pageContext.latestSnapshot = toContentString(result.content);
|
|
985
1024
|
recordSnapshotStats(pageContext.latestSnapshot);
|
|
@@ -1001,9 +1040,8 @@ async function executeAgentLoop(params) {
|
|
|
1001
1040
|
if (nextByHeuristic !== remainingInstruction) {
|
|
1002
1041
|
remainingInstruction = nextByHeuristic;
|
|
1003
1042
|
consecutiveNoProtocolRounds = 0;
|
|
1004
|
-
} else if (executedTaskCalls.length > 0)
|
|
1005
|
-
|
|
1006
|
-
}
|
|
1043
|
+
} else if (executedTaskCalls.length > 0) if (!roundHasConfirmedProgress || roundHasError) consecutiveNoProtocolRounds += 1;
|
|
1044
|
+
else consecutiveNoProtocolRounds = 0;
|
|
1007
1045
|
}
|
|
1008
1046
|
previousRoundModelOutput = parsedInstructionState.hasRemainingProtocol ? normalizeModelOutput(response.text) : `REMAINING: ${remainingInstruction || "DONE"}`;
|
|
1009
1047
|
lastRoundHadError = roundHasError;
|
|
@@ -1829,7 +1867,8 @@ function buildSystemPrompt(params = {}) {
|
|
|
1829
1867
|
"- Only interactive elements carry #hashID; others are context-only and cannot be targeted.",
|
|
1830
1868
|
"- Bracket tag may show ARIA role ([combobox], [slider]) as primary interaction hint.",
|
|
1831
1869
|
"- listeners=\"...\" = bound event handlers (abbrevs below). Prefer targets with matching listeners.",
|
|
1832
|
-
"- Click
|
|
1870
|
+
"- Click target MUST have click signal: listeners containing clk/pdn/mdn, or onclick attr, or native <a>/<button>, or role=button/link. NEVER click elements with only blr/fcs (focus/blur) — they are not click targets.",
|
|
1871
|
+
"- If the text you want to click has no click signal, look at its parent row/container or nearby sibling that does have clk listener.",
|
|
1833
1872
|
"- No-effect fallback: try nearest actionable sibling/ancestor in same semantic group instead of repeating.",
|
|
1834
1873
|
"- Batch fill/type/check/select_option freely within one round. A click always ends the round — send at most ONE click as the LAST action in a batch.",
|
|
1835
1874
|
"- Input order (MANDATORY): focus/click → fill/type/select_option per target. Multi-field: focus A→fill A→focus B→fill B.",
|