rl-simulator-core 1.0.3 → 1.0.5

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.d.mts CHANGED
@@ -297,7 +297,7 @@ async function runAgent({ targetUrl, taskInput, sessionId, simulatedUserKnownInf
297
297
 
298
298
  // 2. Launch Browser
299
299
  const browser = await chromium.launch({
300
- headless: true, // Visible for demo/debug
300
+ headless: false, // Visible for demo/debug
301
301
  args: ['--start-maximized'] // Attempt to maximize
302
302
  });
303
303
 
@@ -433,7 +433,7 @@ function getFormattedDate() {
433
433
  * @param {string} targetServer - The URL of the backend task service
434
434
  * @param {string} taskId - The ID of the task to run
435
435
  */
436
- async function runTaskLoop(targetWeb, targetServer, taskId) {
436
+ async function runTaskLoop(targetWeb, targetServer, taskId, agentRunner = runAgent) {
437
437
  const results = [];
438
438
  const datetime = getFormattedDate();
439
439
  const folderName = `${taskId}_${datetime}`;
@@ -454,7 +454,7 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
454
454
  for (let i = 1; i <= 5; i++) {
455
455
  console.log(`\n=== Starting Iteration ${i}/5 ===`);
456
456
  try {
457
- const data = await executeSingleCycle(targetWeb, targetServer, taskId, i);
457
+ const data = await executeSingleCycle(targetWeb, targetServer, taskId, i, agentRunner);
458
458
  const { sessionId, agentMessages, ...rest } = data;
459
459
 
460
460
  // Create session subdirectory
@@ -485,8 +485,25 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
485
485
  }
486
486
 
487
487
  // Save final-results.json (Consolidated)
488
+ // Aggregate results
489
+ results.filter(r => r.verifyResult);
490
+ const scores = results.map(r => r.verifyResult?.score || 0);
491
+ const successCount = scores.filter(s => s === 1).length;
492
+ const total = 5; // Fixed 5 iterations
493
+
494
+ const rate = `${successCount}/${total}`;
495
+ const summary = {
496
+ rate,
497
+ score: scores
498
+ };
499
+
500
+ const finalOutput = {
501
+ summary,
502
+ results
503
+ };
504
+
488
505
  const finalResultPath = path.join(outputDir, 'final-results.json');
489
- fs.writeFileSync(finalResultPath, JSON.stringify(results, null, 2));
506
+ fs.writeFileSync(finalResultPath, JSON.stringify(finalOutput, null, 2));
490
507
  console.log(`Saved consolidated results to ${finalResultPath}`);
491
508
 
492
509
  // Zip the results
@@ -503,10 +520,14 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
503
520
  console.error("Failed to create zip:", zipError);
504
521
  }
505
522
 
506
- return zipPath;
523
+ return {
524
+ rate,
525
+ zipPath,
526
+ taskId
527
+ };
507
528
  }
508
529
 
509
- async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
530
+ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration, agentRunner) {
510
531
  const fetchJson = async (url, opts) => {
511
532
  const res = await fetch(url, opts);
512
533
  if (!res.ok) {
@@ -537,7 +558,7 @@ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
537
558
 
538
559
  // 3. Run Agent
539
560
  console.log("Running Agent...");
540
- const agentResult = await runAgent({
561
+ const agentResult = await agentRunner({
541
562
  taskInput: TaskJson.task.instruction,
542
563
  targetUrl: targetWeb,
543
564
  sessionId: sessionId,
package/dist/index.d.ts CHANGED
@@ -297,7 +297,7 @@ async function runAgent({ targetUrl, taskInput, sessionId, simulatedUserKnownInf
297
297
 
298
298
  // 2. Launch Browser
299
299
  const browser = await chromium.launch({
300
- headless: true, // Visible for demo/debug
300
+ headless: false, // Visible for demo/debug
301
301
  args: ['--start-maximized'] // Attempt to maximize
302
302
  });
303
303
 
@@ -433,7 +433,7 @@ function getFormattedDate() {
433
433
  * @param {string} targetServer - The URL of the backend task service
434
434
  * @param {string} taskId - The ID of the task to run
435
435
  */
436
- async function runTaskLoop(targetWeb, targetServer, taskId) {
436
+ async function runTaskLoop(targetWeb, targetServer, taskId, agentRunner = runAgent) {
437
437
  const results = [];
438
438
  const datetime = getFormattedDate();
439
439
  const folderName = `${taskId}_${datetime}`;
@@ -454,7 +454,7 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
454
454
  for (let i = 1; i <= 5; i++) {
455
455
  console.log(`\n=== Starting Iteration ${i}/5 ===`);
456
456
  try {
457
- const data = await executeSingleCycle(targetWeb, targetServer, taskId, i);
457
+ const data = await executeSingleCycle(targetWeb, targetServer, taskId, i, agentRunner);
458
458
  const { sessionId, agentMessages, ...rest } = data;
459
459
 
460
460
  // Create session subdirectory
@@ -485,8 +485,25 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
485
485
  }
486
486
 
487
487
  // Save final-results.json (Consolidated)
488
+ // Aggregate results
489
+ results.filter(r => r.verifyResult);
490
+ const scores = results.map(r => r.verifyResult?.score || 0);
491
+ const successCount = scores.filter(s => s === 1).length;
492
+ const total = 5; // Fixed 5 iterations
493
+
494
+ const rate = `${successCount}/${total}`;
495
+ const summary = {
496
+ rate,
497
+ score: scores
498
+ };
499
+
500
+ const finalOutput = {
501
+ summary,
502
+ results
503
+ };
504
+
488
505
  const finalResultPath = path.join(outputDir, 'final-results.json');
489
- fs.writeFileSync(finalResultPath, JSON.stringify(results, null, 2));
506
+ fs.writeFileSync(finalResultPath, JSON.stringify(finalOutput, null, 2));
490
507
  console.log(`Saved consolidated results to ${finalResultPath}`);
491
508
 
492
509
  // Zip the results
@@ -503,10 +520,14 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
503
520
  console.error("Failed to create zip:", zipError);
504
521
  }
505
522
 
506
- return zipPath;
523
+ return {
524
+ rate,
525
+ zipPath,
526
+ taskId
527
+ };
507
528
  }
508
529
 
509
- async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
530
+ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration, agentRunner) {
510
531
  const fetchJson = async (url, opts) => {
511
532
  const res = await fetch(url, opts);
512
533
  if (!res.ok) {
@@ -537,7 +558,7 @@ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
537
558
 
538
559
  // 3. Run Agent
539
560
  console.log("Running Agent...");
540
- const agentResult = await runAgent({
561
+ const agentResult = await agentRunner({
541
562
  taskInput: TaskJson.task.instruction,
542
563
  targetUrl: targetWeb,
543
564
  sessionId: sessionId,
package/dist/index.js CHANGED
@@ -302,7 +302,7 @@ async function runAgent({ targetUrl, taskInput, sessionId, simulatedUserKnownInf
302
302
  console.log(`\u{1F4C1} \u521B\u5EFA\u622A\u56FE\u76EE\u5F55: ${screenshotsDir}`);
303
303
  }
304
304
  const browser = await import_playwright.chromium.launch({
305
- headless: true,
305
+ headless: false,
306
306
  // Visible for demo/debug
307
307
  args: ["--start-maximized"]
308
308
  // Attempt to maximize
@@ -405,7 +405,7 @@ function getFormattedDate() {
405
405
  const pad = (n) => String(n).padStart(2, "0");
406
406
  return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
407
407
  }
408
- async function runTaskLoop(targetWeb, targetServer, taskId) {
408
+ async function runTaskLoop(targetWeb, targetServer, taskId, agentRunner = runAgent) {
409
409
  const results = [];
410
410
  const datetime = getFormattedDate();
411
411
  const folderName = `${taskId}_${datetime}`;
@@ -421,7 +421,7 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
421
421
  console.log(`
422
422
  === Starting Iteration ${i}/5 ===`);
423
423
  try {
424
- const data = await executeSingleCycle(targetWeb, targetServer, taskId, i);
424
+ const data = await executeSingleCycle(targetWeb, targetServer, taskId, i, agentRunner);
425
425
  const { sessionId, agentMessages, ...rest } = data;
426
426
  const sessionDir = import_path3.default.join(outputDir, sessionId);
427
427
  if (!import_fs2.default.existsSync(sessionDir)) {
@@ -442,8 +442,24 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
442
442
  results.push({ iteration: i, error: e.message });
443
443
  }
444
444
  }
445
+ const validResults = results.filter((r) => r.verifyResult);
446
+ const scores = results.map((r) => {
447
+ var _a;
448
+ return ((_a = r.verifyResult) == null ? void 0 : _a.score) || 0;
449
+ });
450
+ const successCount = scores.filter((s) => s === 1).length;
451
+ const total = 5;
452
+ const rate = `${successCount}/${total}`;
453
+ const summary = {
454
+ rate,
455
+ score: scores
456
+ };
457
+ const finalOutput = {
458
+ summary,
459
+ results
460
+ };
445
461
  const finalResultPath = import_path3.default.join(outputDir, "final-results.json");
446
- import_fs2.default.writeFileSync(finalResultPath, JSON.stringify(results, null, 2));
462
+ import_fs2.default.writeFileSync(finalResultPath, JSON.stringify(finalOutput, null, 2));
447
463
  console.log(`Saved consolidated results to ${finalResultPath}`);
448
464
  console.log("Packaging results into ZIP...");
449
465
  const zipName = `${folderName}.zip`;
@@ -457,9 +473,13 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
457
473
  } catch (zipError) {
458
474
  console.error("Failed to create zip:", zipError);
459
475
  }
460
- return zipPath;
476
+ return {
477
+ rate,
478
+ zipPath,
479
+ taskId
480
+ };
461
481
  }
462
- async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
482
+ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration, agentRunner) {
463
483
  const fetchJson = async (url, opts) => {
464
484
  const res = await fetch(url, opts);
465
485
  if (!res.ok) {
@@ -483,7 +503,7 @@ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
483
503
  body: JSON.stringify({ task_id: taskId, session_id: sessionId })
484
504
  });
485
505
  console.log("Running Agent...");
486
- const agentResult = await runAgent({
506
+ const agentResult = await agentRunner({
487
507
  taskInput: TaskJson.task.instruction,
488
508
  targetUrl: targetWeb,
489
509
  sessionId,
package/dist/index.mjs CHANGED
@@ -268,7 +268,7 @@ async function runAgent({ targetUrl, taskInput, sessionId, simulatedUserKnownInf
268
268
  console.log(`\u{1F4C1} \u521B\u5EFA\u622A\u56FE\u76EE\u5F55: ${screenshotsDir}`);
269
269
  }
270
270
  const browser = await chromium.launch({
271
- headless: true,
271
+ headless: false,
272
272
  // Visible for demo/debug
273
273
  args: ["--start-maximized"]
274
274
  // Attempt to maximize
@@ -371,7 +371,7 @@ function getFormattedDate() {
371
371
  const pad = (n) => String(n).padStart(2, "0");
372
372
  return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}_${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
373
373
  }
374
- async function runTaskLoop(targetWeb, targetServer, taskId) {
374
+ async function runTaskLoop(targetWeb, targetServer, taskId, agentRunner = runAgent) {
375
375
  const results = [];
376
376
  const datetime = getFormattedDate();
377
377
  const folderName = `${taskId}_${datetime}`;
@@ -387,7 +387,7 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
387
387
  console.log(`
388
388
  === Starting Iteration ${i}/5 ===`);
389
389
  try {
390
- const data = await executeSingleCycle(targetWeb, targetServer, taskId, i);
390
+ const data = await executeSingleCycle(targetWeb, targetServer, taskId, i, agentRunner);
391
391
  const { sessionId, agentMessages, ...rest } = data;
392
392
  const sessionDir = path3.join(outputDir, sessionId);
393
393
  if (!fs2.existsSync(sessionDir)) {
@@ -408,8 +408,24 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
408
408
  results.push({ iteration: i, error: e.message });
409
409
  }
410
410
  }
411
+ const validResults = results.filter((r) => r.verifyResult);
412
+ const scores = results.map((r) => {
413
+ var _a;
414
+ return ((_a = r.verifyResult) == null ? void 0 : _a.score) || 0;
415
+ });
416
+ const successCount = scores.filter((s) => s === 1).length;
417
+ const total = 5;
418
+ const rate = `${successCount}/${total}`;
419
+ const summary = {
420
+ rate,
421
+ score: scores
422
+ };
423
+ const finalOutput = {
424
+ summary,
425
+ results
426
+ };
411
427
  const finalResultPath = path3.join(outputDir, "final-results.json");
412
- fs2.writeFileSync(finalResultPath, JSON.stringify(results, null, 2));
428
+ fs2.writeFileSync(finalResultPath, JSON.stringify(finalOutput, null, 2));
413
429
  console.log(`Saved consolidated results to ${finalResultPath}`);
414
430
  console.log("Packaging results into ZIP...");
415
431
  const zipName = `${folderName}.zip`;
@@ -423,9 +439,13 @@ async function runTaskLoop(targetWeb, targetServer, taskId) {
423
439
  } catch (zipError) {
424
440
  console.error("Failed to create zip:", zipError);
425
441
  }
426
- return zipPath;
442
+ return {
443
+ rate,
444
+ zipPath,
445
+ taskId
446
+ };
427
447
  }
428
- async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
448
+ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration, agentRunner) {
429
449
  const fetchJson = async (url, opts) => {
430
450
  const res = await fetch(url, opts);
431
451
  if (!res.ok) {
@@ -449,7 +469,7 @@ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
449
469
  body: JSON.stringify({ task_id: taskId, session_id: sessionId })
450
470
  });
451
471
  console.log("Running Agent...");
452
- const agentResult = await runAgent({
472
+ const agentResult = await agentRunner({
453
473
  taskInput: TaskJson.task.instruction,
454
474
  targetUrl: targetWeb,
455
475
  sessionId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rl-simulator-core",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
package/src/index.js CHANGED
@@ -25,7 +25,7 @@ function getFormattedDate() {
25
25
  * @param {string} targetServer - The URL of the backend task service
26
26
  * @param {string} taskId - The ID of the task to run
27
27
  */
28
- export async function runTaskLoop(targetWeb, targetServer, taskId) {
28
+ export async function runTaskLoop(targetWeb, targetServer, taskId, agentRunner = runAgent) {
29
29
  const results = [];
30
30
  const datetime = getFormattedDate();
31
31
  const folderName = `${taskId}_${datetime}`;
@@ -46,7 +46,7 @@ export async function runTaskLoop(targetWeb, targetServer, taskId) {
46
46
  for (let i = 1; i <= 5; i++) {
47
47
  console.log(`\n=== Starting Iteration ${i}/5 ===`);
48
48
  try {
49
- const data = await executeSingleCycle(targetWeb, targetServer, taskId, i);
49
+ const data = await executeSingleCycle(targetWeb, targetServer, taskId, i, agentRunner);
50
50
  const { sessionId, agentMessages, ...rest } = data;
51
51
 
52
52
  // Create session subdirectory
@@ -77,8 +77,25 @@ export async function runTaskLoop(targetWeb, targetServer, taskId) {
77
77
  }
78
78
 
79
79
  // Save final-results.json (Consolidated)
80
+ // Aggregate results
81
+ const validResults = results.filter(r => r.verifyResult);
82
+ const scores = results.map(r => r.verifyResult?.score || 0);
83
+ const successCount = scores.filter(s => s === 1).length;
84
+ const total = 5; // Fixed 5 iterations
85
+
86
+ const rate = `${successCount}/${total}`;
87
+ const summary = {
88
+ rate,
89
+ score: scores
90
+ };
91
+
92
+ const finalOutput = {
93
+ summary,
94
+ results
95
+ };
96
+
80
97
  const finalResultPath = path.join(outputDir, 'final-results.json');
81
- fs.writeFileSync(finalResultPath, JSON.stringify(results, null, 2));
98
+ fs.writeFileSync(finalResultPath, JSON.stringify(finalOutput, null, 2));
82
99
  console.log(`Saved consolidated results to ${finalResultPath}`);
83
100
 
84
101
  // Zip the results
@@ -95,10 +112,14 @@ export async function runTaskLoop(targetWeb, targetServer, taskId) {
95
112
  console.error("Failed to create zip:", zipError);
96
113
  }
97
114
 
98
- return zipPath;
115
+ return {
116
+ rate,
117
+ zipPath,
118
+ taskId
119
+ };
99
120
  }
100
121
 
101
- async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
122
+ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration, agentRunner) {
102
123
  const fetchJson = async (url, opts) => {
103
124
  const res = await fetch(url, opts);
104
125
  if (!res.ok) {
@@ -129,7 +150,7 @@ async function executeSingleCycle(targetWeb, targetServer, taskId, iteration) {
129
150
 
130
151
  // 3. Run Agent
131
152
  console.log("Running Agent...");
132
- const agentResult = await runAgent({
153
+ const agentResult = await agentRunner({
133
154
  taskInput: TaskJson.task.instruction,
134
155
  targetUrl: targetWeb,
135
156
  sessionId: sessionId,
package/src/runner.js CHANGED
@@ -15,7 +15,7 @@ async function runAgent({ targetUrl, taskInput, sessionId, simulatedUserKnownInf
15
15
 
16
16
  // 2. Launch Browser
17
17
  const browser = await chromium.launch({
18
- headless: true, // Visible for demo/debug
18
+ headless: false, // Visible for demo/debug
19
19
  args: ['--start-maximized'] // Attempt to maximize
20
20
  });
21
21
 
package/.env DELETED
@@ -1,3 +0,0 @@
1
- ARK_API_KEY=efa2ecef-c5eb-44e1-8853-86c592d7cdc2
2
- EP=ep-20251205145158-pxg57
3
- BASE_URL=https://ark.cn-beijing.volces.com/api/v3