agentpage 0.0.42 → 0.0.43
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 +31 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -225,6 +225,32 @@ 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
|
+
* - 导航类:navigate.*
|
|
233
|
+
*
|
|
234
|
+
* click 不在此列——因为 click 可能点了但完全没效果(如点击无 click listener 的元素)。
|
|
235
|
+
*
|
|
236
|
+
* 用途:协议缺失豁免。仅当本轮有"确定性推进"时才豁免协议缺失计数,
|
|
237
|
+
* 避免模型反复点击无效目标导致死循环。
|
|
238
|
+
*/
|
|
239
|
+
function isConfirmedProgressAction(toolName, toolInput) {
|
|
240
|
+
if (toolName === "navigate") return true;
|
|
241
|
+
if (toolName !== "dom") return false;
|
|
242
|
+
const action = getToolAction(toolInput);
|
|
243
|
+
if (!action) return false;
|
|
244
|
+
return [
|
|
245
|
+
"fill",
|
|
246
|
+
"type",
|
|
247
|
+
"select_option",
|
|
248
|
+
"clear",
|
|
249
|
+
"check",
|
|
250
|
+
"uncheck"
|
|
251
|
+
].includes(action);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
228
254
|
* 采集找不到元素任务。
|
|
229
255
|
*
|
|
230
256
|
* 返回 null 表示当前结果不属于“元素未找到”,
|
|
@@ -949,6 +975,7 @@ async function executeAgentLoop(params) {
|
|
|
949
975
|
}
|
|
950
976
|
let roundHasError = false;
|
|
951
977
|
let roundHasPotentialDomMutation = false;
|
|
978
|
+
let roundHasConfirmedProgress = false;
|
|
952
979
|
const executedTaskCalls = [];
|
|
953
980
|
const roundMissingTasks = [];
|
|
954
981
|
for (const tc of response.toolCalls) {
|
|
@@ -980,6 +1007,7 @@ async function executeAgentLoop(params) {
|
|
|
980
1007
|
if (missingTask) roundMissingTasks.push(missingTask);
|
|
981
1008
|
if (result.details && typeof result.details === "object") roundHasError = roundHasError || Boolean(result.details.error);
|
|
982
1009
|
if (!hasToolError(result) && isPotentialDomMutation(tc.name, tc.input)) roundHasPotentialDomMutation = true;
|
|
1010
|
+
if (!hasToolError(result) && isConfirmedProgressAction(tc.name, tc.input)) roundHasConfirmedProgress = true;
|
|
983
1011
|
if (tc.name === "page_info" && getToolAction(tc.input) === "snapshot") {
|
|
984
1012
|
pageContext.latestSnapshot = toContentString(result.content);
|
|
985
1013
|
recordSnapshotStats(pageContext.latestSnapshot);
|
|
@@ -1002,7 +1030,7 @@ async function executeAgentLoop(params) {
|
|
|
1002
1030
|
remainingInstruction = nextByHeuristic;
|
|
1003
1031
|
consecutiveNoProtocolRounds = 0;
|
|
1004
1032
|
} else if (executedTaskCalls.length > 0) {
|
|
1005
|
-
if (!
|
|
1033
|
+
if (!roundHasConfirmedProgress || roundHasError) consecutiveNoProtocolRounds += 1;
|
|
1006
1034
|
}
|
|
1007
1035
|
}
|
|
1008
1036
|
previousRoundModelOutput = parsedInstructionState.hasRemainingProtocol ? normalizeModelOutput(response.text) : `REMAINING: ${remainingInstruction || "DONE"}`;
|
|
@@ -1829,7 +1857,8 @@ function buildSystemPrompt(params = {}) {
|
|
|
1829
1857
|
"- Only interactive elements carry #hashID; others are context-only and cannot be targeted.",
|
|
1830
1858
|
"- Bracket tag may show ARIA role ([combobox], [slider]) as primary interaction hint.",
|
|
1831
1859
|
"- listeners=\"...\" = bound event handlers (abbrevs below). Prefer targets with matching listeners.",
|
|
1832
|
-
"- Click
|
|
1860
|
+
"- 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.",
|
|
1861
|
+
"- 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
1862
|
"- No-effect fallback: try nearest actionable sibling/ancestor in same semantic group instead of repeating.",
|
|
1834
1863
|
"- 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
1864
|
"- Input order (MANDATORY): focus/click → fill/type/select_option per target. Multi-field: focus A→fill A→focus B→fill B.",
|