misoai-web 1.6.1 → 1.6.2

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.
Files changed (53) hide show
  1. package/dist/es/agent.js +4 -1
  2. package/dist/es/agent.js.map +1 -1
  3. package/dist/es/bridge-mode-browser.js +3 -3
  4. package/dist/es/bridge-mode.js +6 -3
  5. package/dist/es/bridge-mode.js.map +1 -1
  6. package/dist/es/chrome-extension.js +5 -2
  7. package/dist/es/chrome-extension.js.map +1 -1
  8. package/dist/es/index.js +320 -18
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/midscene-playground.js +4 -1
  11. package/dist/es/midscene-playground.js.map +1 -1
  12. package/dist/es/playground.js +4 -1
  13. package/dist/es/playground.js.map +1 -1
  14. package/dist/es/playwright.js +320 -18
  15. package/dist/es/playwright.js.map +1 -1
  16. package/dist/es/puppeteer-agent-launcher.js +320 -18
  17. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  18. package/dist/es/puppeteer.js +320 -18
  19. package/dist/es/puppeteer.js.map +1 -1
  20. package/dist/lib/agent.js +4 -1
  21. package/dist/lib/agent.js.map +1 -1
  22. package/dist/lib/bridge-mode-browser.js +3 -3
  23. package/dist/lib/bridge-mode.js +6 -3
  24. package/dist/lib/bridge-mode.js.map +1 -1
  25. package/dist/lib/chrome-extension.js +5 -2
  26. package/dist/lib/chrome-extension.js.map +1 -1
  27. package/dist/lib/index.js +320 -18
  28. package/dist/lib/index.js.map +1 -1
  29. package/dist/lib/midscene-playground.js +4 -1
  30. package/dist/lib/midscene-playground.js.map +1 -1
  31. package/dist/lib/playground.js +4 -1
  32. package/dist/lib/playground.js.map +1 -1
  33. package/dist/lib/playwright.js +320 -18
  34. package/dist/lib/playwright.js.map +1 -1
  35. package/dist/lib/puppeteer-agent-launcher.js +320 -18
  36. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  37. package/dist/lib/puppeteer.js +320 -18
  38. package/dist/lib/puppeteer.js.map +1 -1
  39. package/dist/types/agent.d.ts +1 -1
  40. package/dist/types/bridge-mode-browser.d.ts +2 -2
  41. package/dist/types/bridge-mode.d.ts +2 -2
  42. package/dist/types/{browser-9b472ffb.d.ts → browser-f205f69d.d.ts} +1 -1
  43. package/dist/types/chrome-extension.d.ts +2 -2
  44. package/dist/types/index.d.ts +1 -1
  45. package/dist/types/midscene-server.d.ts +1 -1
  46. package/dist/types/{page-ed0ecb44.d.ts → page-c5452809.d.ts} +45 -0
  47. package/dist/types/playground.d.ts +2 -2
  48. package/dist/types/playwright.d.ts +1 -1
  49. package/dist/types/puppeteer-agent-launcher.d.ts +1 -1
  50. package/dist/types/puppeteer.d.ts +2 -2
  51. package/dist/types/utils.d.ts +1 -1
  52. package/dist/types/yaml.d.ts +1 -1
  53. package/package.json +2 -2
package/dist/es/index.js CHANGED
@@ -1280,6 +1280,7 @@ var PageTaskExecutor = class {
1280
1280
  actions: [],
1281
1281
  more_actions_needed_by_instruction: false,
1282
1282
  log: "",
1283
+ summary: "Loaded YAML workflow configuration",
1283
1284
  yamlString
1284
1285
  },
1285
1286
  cache: {
@@ -1381,6 +1382,7 @@ var PageTaskExecutor = class {
1381
1382
  actions: finalActions,
1382
1383
  more_actions_needed_by_instruction,
1383
1384
  log: log2,
1385
+ summary: planResult.summary || "Generated action plan from user instruction",
1384
1386
  yamlFlow: planResult.yamlFlow
1385
1387
  },
1386
1388
  cache: {
@@ -1436,6 +1438,7 @@ var PageTaskExecutor = class {
1436
1438
  actionType: actions[0].type,
1437
1439
  more_actions_needed_by_instruction: true,
1438
1440
  log: "",
1441
+ summary: action_summary || "Generated VLM action plan",
1439
1442
  yamlFlow: planResult.yamlFlow
1440
1443
  },
1441
1444
  cache: {
@@ -2030,7 +2033,7 @@ import { ifInBrowser as ifInBrowser2 } from "misoai-shared/utils";
2030
2033
  import semver from "semver";
2031
2034
 
2032
2035
  // package.json
2033
- var version = "1.6.1";
2036
+ var version = "1.6.2";
2034
2037
 
2035
2038
  // src/common/task-cache.ts
2036
2039
  var debug3 = getDebug3("cache");
@@ -3118,13 +3121,236 @@ import {
3118
3121
  } from "misoai-shared/fs";
3119
3122
  import { getDebug as getDebug5 } from "misoai-shared/logger";
3120
3123
  import { assert as assert8 } from "misoai-shared/utils";
3124
+
3125
+ // src/common/mouse-utils.ts
3126
+ function generateHumanMousePath(from, to, options = {}) {
3127
+ const {
3128
+ steps = 20,
3129
+ easing = "easeInOut"
3130
+ } = options;
3131
+ if (steps <= 1) {
3132
+ return [to];
3133
+ }
3134
+ const path = [];
3135
+ const controlPoint1 = {
3136
+ x: from.x + (to.x - from.x) * 0.25 + (Math.random() - 0.5) * 50,
3137
+ y: from.y + (to.y - from.y) * 0.25 + (Math.random() - 0.5) * 50
3138
+ };
3139
+ const controlPoint2 = {
3140
+ x: from.x + (to.x - from.x) * 0.75 + (Math.random() - 0.5) * 50,
3141
+ y: from.y + (to.y - from.y) * 0.75 + (Math.random() - 0.5) * 50
3142
+ };
3143
+ for (let i = 0; i <= steps; i++) {
3144
+ const t = i / steps;
3145
+ const easedT = applyEasing(t, easing);
3146
+ const point = calculateBezierPoint(from, controlPoint1, controlPoint2, to, easedT);
3147
+ path.push(point);
3148
+ }
3149
+ return path;
3150
+ }
3151
+ function calculateBezierPoint(p0, p1, p2, p3, t) {
3152
+ const oneMinusT = 1 - t;
3153
+ const oneMinusTSquared = oneMinusT * oneMinusT;
3154
+ const oneMinusTCubed = oneMinusTSquared * oneMinusT;
3155
+ const tSquared = t * t;
3156
+ const tCubed = tSquared * t;
3157
+ return {
3158
+ x: oneMinusTCubed * p0.x + 3 * oneMinusTSquared * t * p1.x + 3 * oneMinusT * tSquared * p2.x + tCubed * p3.x,
3159
+ y: oneMinusTCubed * p0.y + 3 * oneMinusTSquared * t * p1.y + 3 * oneMinusT * tSquared * p2.y + tCubed * p3.y
3160
+ };
3161
+ }
3162
+ function applyEasing(t, easing) {
3163
+ switch (easing) {
3164
+ case "linear":
3165
+ return t;
3166
+ case "easeIn":
3167
+ return t * t;
3168
+ case "easeOut":
3169
+ return 1 - (1 - t) * (1 - t);
3170
+ case "easeInOut":
3171
+ return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2;
3172
+ default:
3173
+ return t;
3174
+ }
3175
+ }
3176
+ function calculateStepDelay(totalDuration, currentStep, totalSteps) {
3177
+ const baseDelay = totalDuration / totalSteps;
3178
+ const variation = 0.3;
3179
+ const randomFactor = 1 + (Math.random() - 0.5) * variation;
3180
+ return Math.max(1, baseDelay * randomFactor);
3181
+ }
3182
+
3183
+ // src/common/visual-feedback.ts
3184
+ function getMousePointerScript(x, y, options = {}) {
3185
+ const {
3186
+ pointerSize = 20,
3187
+ pointerColor = "#ff4444",
3188
+ trailLength = 5,
3189
+ showTrail = true,
3190
+ animationDuration = 200
3191
+ } = options;
3192
+ return `
3193
+ (() => {
3194
+ // Create or update mouse pointer
3195
+ if (!window.misoaiMousePointer) {
3196
+ const pointer = document.createElement('div');
3197
+ pointer.id = 'misoai-mouse-pointer';
3198
+ pointer.style.cssText = \`
3199
+ position: fixed;
3200
+ width: ${pointerSize}px;
3201
+ height: ${pointerSize}px;
3202
+ background: ${pointerColor};
3203
+ border: 2px solid white;
3204
+ border-radius: 50%;
3205
+ pointer-events: none;
3206
+ z-index: 999999;
3207
+ box-shadow: 0 0 10px rgba(0,0,0,0.3);
3208
+ transition: all ${animationDuration}ms ease-out;
3209
+ transform: translate(-50%, -50%);
3210
+ \`;
3211
+ document.body.appendChild(pointer);
3212
+ window.misoaiMousePointer = pointer;
3213
+
3214
+ // Initialize trail array
3215
+ window.misoaiMouseTrail = [];
3216
+ }
3217
+
3218
+ const pointer = window.misoaiMousePointer;
3219
+ pointer.style.left = ${x}px;
3220
+ pointer.style.top = ${y}px;
3221
+
3222
+ ${showTrail ? getTrailScript(x, y, trailLength, pointerColor) : ""}
3223
+
3224
+ // Auto-hide after 3 seconds of inactivity
3225
+ clearTimeout(window.misoaiMouseTimeout);
3226
+ pointer.style.opacity = '1';
3227
+ window.misoaiMouseTimeout = setTimeout(() => {
3228
+ if (pointer) pointer.style.opacity = '0.3';
3229
+ }, 3000);
3230
+ })();
3231
+ `;
3232
+ }
3233
+ function getTrailScript(x, y, trailLength, color) {
3234
+ return `
3235
+ // Add current position to trail
3236
+ window.misoaiMouseTrail.push({ x: ${x}, y: ${y}, timestamp: Date.now() });
3237
+
3238
+ // Keep only recent trail points
3239
+ if (window.misoaiMouseTrail.length > ${trailLength}) {
3240
+ window.misoaiMouseTrail.shift();
3241
+ }
3242
+
3243
+ // Remove old trail elements
3244
+ document.querySelectorAll('.misoai-mouse-trail').forEach(el => el.remove());
3245
+
3246
+ // Create new trail elements
3247
+ window.misoaiMouseTrail.forEach((point, index) => {
3248
+ if (index === window.misoaiMouseTrail.length - 1) return; // Skip current position
3249
+
3250
+ const trailElement = document.createElement('div');
3251
+ trailElement.className = 'misoai-mouse-trail';
3252
+ const opacity = (index + 1) / window.misoaiMouseTrail.length * 0.6;
3253
+ const size = 8 + (index + 1) / window.misoaiMouseTrail.length * 8;
3254
+
3255
+ trailElement.style.cssText = \`
3256
+ position: fixed;
3257
+ width: \${size}px;
3258
+ height: \${size}px;
3259
+ background: ${color};
3260
+ border-radius: 50%;
3261
+ pointer-events: none;
3262
+ z-index: 999998;
3263
+ opacity: \${opacity};
3264
+ transform: translate(-50%, -50%);
3265
+ left: \${point.x}px;
3266
+ top: \${point.y}px;
3267
+ \`;
3268
+
3269
+ document.body.appendChild(trailElement);
3270
+
3271
+ // Auto-remove trail element after animation
3272
+ setTimeout(() => {
3273
+ if (trailElement.parentNode) {
3274
+ trailElement.parentNode.removeChild(trailElement);
3275
+ }
3276
+ }, 1000);
3277
+ });
3278
+ `;
3279
+ }
3280
+ function getClickAnimationScript(x, y) {
3281
+ return `
3282
+ (() => {
3283
+ const clickRipple = document.createElement('div');
3284
+ clickRipple.style.cssText = \`
3285
+ position: fixed;
3286
+ left: ${x}px;
3287
+ top: ${y}px;
3288
+ width: 0;
3289
+ height: 0;
3290
+ border: 2px solid #ff4444;
3291
+ border-radius: 50%;
3292
+ pointer-events: none;
3293
+ z-index: 999999;
3294
+ transform: translate(-50%, -50%);
3295
+ animation: misoai-click-ripple 0.6s ease-out forwards;
3296
+ \`;
3297
+
3298
+ // Add CSS animation if not exists
3299
+ if (!document.getElementById('misoai-click-styles')) {
3300
+ const style = document.createElement('style');
3301
+ style.id = 'misoai-click-styles';
3302
+ style.textContent = \`
3303
+ @keyframes misoai-click-ripple {
3304
+ 0% {
3305
+ width: 0;
3306
+ height: 0;
3307
+ opacity: 1;
3308
+ }
3309
+ 100% {
3310
+ width: 40px;
3311
+ height: 40px;
3312
+ opacity: 0;
3313
+ }
3314
+ }
3315
+ \`;
3316
+ document.head.appendChild(style);
3317
+ }
3318
+
3319
+ document.body.appendChild(clickRipple);
3320
+
3321
+ // Remove after animation
3322
+ setTimeout(() => {
3323
+ if (clickRipple.parentNode) {
3324
+ clickRipple.parentNode.removeChild(clickRipple);
3325
+ }
3326
+ }, 600);
3327
+ })();
3328
+ `;
3329
+ }
3330
+
3331
+ // src/puppeteer/base-page.ts
3121
3332
  var debugPage = getDebug5("web:page");
3122
3333
  var Page = class {
3123
3334
  constructor(underlyingPage, pageType, opts) {
3335
+ this.currentMousePosition = { x: 0, y: 0 };
3336
+ this.mouseMovementOptions = {
3337
+ steps: 15,
3338
+ duration: 300,
3339
+ easing: "easeInOut",
3340
+ showVisualFeedback: true
3341
+ };
3342
+ this.visualFeedbackOptions = {
3343
+ pointerSize: 16,
3344
+ pointerColor: "#ff4444",
3345
+ trailLength: 4,
3346
+ showTrail: true,
3347
+ animationDuration: 150
3348
+ };
3124
3349
  this.everMoved = false;
3125
3350
  this.underlyingPage = underlyingPage;
3126
3351
  this.pageType = pageType;
3127
3352
  this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT2;
3353
+ this.initializeMousePosition();
3128
3354
  }
3129
3355
  async evaluate(pageFunction, arg) {
3130
3356
  let result;
@@ -3143,9 +3369,76 @@ var Page = class {
3143
3369
  debugPage("evaluate function end");
3144
3370
  return result;
3145
3371
  }
3372
+ /**
3373
+ * Initialize mouse position to center of viewport
3374
+ */
3375
+ async initializeMousePosition() {
3376
+ try {
3377
+ const size = await this.size();
3378
+ this.currentMousePosition = {
3379
+ x: Math.floor(size.width / 2),
3380
+ y: Math.floor(size.height / 2)
3381
+ };
3382
+ } catch (error) {
3383
+ this.currentMousePosition = { x: 400, y: 300 };
3384
+ }
3385
+ }
3146
3386
  async evaluateJavaScript(script) {
3147
3387
  return this.evaluate(script);
3148
3388
  }
3389
+ /**
3390
+ * Show visual feedback for mouse pointer
3391
+ */
3392
+ async showMousePointer(x, y) {
3393
+ if (!this.mouseMovementOptions.showVisualFeedback)
3394
+ return;
3395
+ const script = getMousePointerScript(x, y, this.visualFeedbackOptions);
3396
+ try {
3397
+ await this.evaluate(script);
3398
+ } catch (error) {
3399
+ debugPage("Visual feedback error:", error);
3400
+ }
3401
+ }
3402
+ /**
3403
+ * Show click animation
3404
+ */
3405
+ async showClickAnimation(x, y) {
3406
+ if (!this.mouseMovementOptions.showVisualFeedback)
3407
+ return;
3408
+ const script = getClickAnimationScript(x, y);
3409
+ try {
3410
+ await this.evaluate(script);
3411
+ } catch (error) {
3412
+ debugPage("Click animation error:", error);
3413
+ }
3414
+ }
3415
+ /**
3416
+ * Move mouse with human-like movement and visual feedback
3417
+ */
3418
+ async moveMouseHumanLike(toX, toY, options) {
3419
+ const moveOptions = { ...this.mouseMovementOptions, ...options };
3420
+ const path = generateHumanMousePath(
3421
+ this.currentMousePosition,
3422
+ { x: toX, y: toY },
3423
+ moveOptions
3424
+ );
3425
+ for (let i = 0; i < path.length; i++) {
3426
+ const point = path[i];
3427
+ if (moveOptions.showVisualFeedback) {
3428
+ await this.showMousePointer(point.x, point.y);
3429
+ }
3430
+ await this.underlyingPage.mouse.move(point.x, point.y);
3431
+ this.currentMousePosition = point;
3432
+ if (i < path.length - 1) {
3433
+ const delay = calculateStepDelay(
3434
+ moveOptions.duration || 300,
3435
+ i,
3436
+ path.length
3437
+ );
3438
+ await sleep2(delay);
3439
+ }
3440
+ }
3441
+ }
3149
3442
  async waitForNavigation() {
3150
3443
  if (this.pageType === "puppeteer" || this.pageType === "playwright") {
3151
3444
  debugPage("waitForNavigation begin");
@@ -3235,7 +3528,8 @@ var Page = class {
3235
3528
  return {
3236
3529
  click: async (x, y, options) => {
3237
3530
  await this.mouse.move(x, y);
3238
- this.underlyingPage.mouse.click(x, y, {
3531
+ await this.showClickAnimation(x, y);
3532
+ await this.underlyingPage.mouse.click(x, y, {
3239
3533
  button: options?.button || "left",
3240
3534
  count: options?.count || 1
3241
3535
  });
@@ -3255,27 +3549,23 @@ var Page = class {
3255
3549
  },
3256
3550
  move: async (x, y) => {
3257
3551
  this.everMoved = true;
3258
- return this.underlyingPage.mouse.move(x, y);
3552
+ await this.moveMouseHumanLike(x, y);
3553
+ return Promise.resolve();
3259
3554
  },
3260
3555
  drag: async (from, to) => {
3261
3556
  if (this.pageType === "puppeteer") {
3262
- await this.underlyingPage.mouse.drag(
3263
- {
3264
- x: from.x,
3265
- y: from.y
3266
- },
3267
- {
3268
- x: to.x,
3269
- y: to.y
3270
- }
3271
- );
3557
+ await this.mouse.move(from.x, from.y);
3558
+ await this.underlyingPage.mouse.down();
3559
+ await this.moveMouseHumanLike(to.x, to.y, {
3560
+ duration: 500,
3561
+ // Slower for drag operations
3562
+ steps: 25
3563
+ });
3564
+ await this.underlyingPage.mouse.up();
3272
3565
  } else if (this.pageType === "playwright") {
3273
- await this.underlyingPage.mouse.move(
3274
- from.x,
3275
- from.y
3276
- );
3566
+ await this.mouse.move(from.x, from.y);
3277
3567
  await this.underlyingPage.mouse.down();
3278
- await this.underlyingPage.mouse.move(to.x, to.y);
3568
+ await this.mouse.move(to.x, to.y);
3279
3569
  await this.underlyingPage.mouse.up();
3280
3570
  }
3281
3571
  }
@@ -3338,6 +3628,18 @@ var Page = class {
3338
3628
  await this.mouse.move(targetX, targetY);
3339
3629
  }
3340
3630
  }
3631
+ /**
3632
+ * Configure mouse movement behavior
3633
+ */
3634
+ configureMouseMovement(options) {
3635
+ this.mouseMovementOptions = { ...this.mouseMovementOptions, ...options };
3636
+ }
3637
+ /**
3638
+ * Configure visual feedback
3639
+ */
3640
+ configureVisualFeedback(options) {
3641
+ this.visualFeedbackOptions = { ...this.visualFeedbackOptions, ...options };
3642
+ }
3341
3643
  async scrollUntilTop(startingPoint) {
3342
3644
  await this.moveToPointBeforeScroll(startingPoint);
3343
3645
  return this.mouse.wheel(0, -9999999);