@litocodes/persona-test 1.2.0 → 1.2.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/index.js +13 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -144,22 +144,31 @@ async function runAgent(url, persona, options = {}) {
|
|
|
144
144
|
const actionHistory = [];
|
|
145
145
|
const failedIds = [];
|
|
146
146
|
let outcome = 'MAX_ACTIONS';
|
|
147
|
+
let actionCount = 0;
|
|
147
148
|
|
|
148
149
|
for (let step = 1; step <= persona.maxActions; step++) {
|
|
149
150
|
const html = await page.content();
|
|
150
151
|
const { domMap, elements, elementCount } = parsePage(html, failedIds);
|
|
151
152
|
|
|
152
|
-
if (elementCount === 0) {
|
|
153
|
+
if (elementCount === 0) {
|
|
154
|
+
console.log(` ⚠️ [${persona.name}] No elements found, scrolling...`);
|
|
155
|
+
await page.mouse.wheel(0, 300);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
153
158
|
|
|
154
159
|
const decision = await getAgentAction(domMap, persona, actionHistory);
|
|
160
|
+
actionCount++;
|
|
155
161
|
|
|
156
|
-
console.log(` 🤖 [${persona.name}] Step ${
|
|
162
|
+
console.log(` 🤖 [${persona.name}] Step ${actionCount}: ${decision.action} [${decision.elementId}] - ${decision.reason?.substring(0, 40)}`);
|
|
157
163
|
|
|
158
164
|
if (decision.action === 'done') { outcome = 'SUCCESS'; break; }
|
|
159
165
|
if (decision.action === 'quit') { outcome = 'ABANDONED'; break; }
|
|
160
166
|
|
|
161
167
|
const target = decision.elementId ? findElementById(elements, decision.elementId) : null;
|
|
162
|
-
if (!target)
|
|
168
|
+
if (!target) {
|
|
169
|
+
console.log(` ⚠️ [${persona.name}] Invalid element ID, skipping...`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
163
172
|
|
|
164
173
|
try {
|
|
165
174
|
const locator = page.locator(target.selector).first();
|
|
@@ -176,6 +185,7 @@ async function runAgent(url, persona, options = {}) {
|
|
|
176
185
|
if (actionHistory.length > 3) actionHistory.shift();
|
|
177
186
|
|
|
178
187
|
} catch (e) {
|
|
188
|
+
console.log(` ⚠️ [${persona.name}] Action failed: ${e.message.split('\n')[0].substring(0, 40)}`);
|
|
179
189
|
failedIds.push(decision.elementId);
|
|
180
190
|
}
|
|
181
191
|
|