smooth-operator-mcp 3.0.4 → 3.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.
@@ -354,7 +354,7 @@ function truncateUtf8(value, maxBytes) {
354
354
  while (low < high) {
355
355
  const midpoint = Math.ceil((low + high) / 2);
356
356
  const candidate = decoder.decode(bytes.slice(0, midpoint));
357
- if (UTF8_ENCODER.encode(candidate).byteLength <= maxBytes) {
357
+ if (UTF8_ENCODER.encode(candidate).byteLength <= boundedMaxBytes) {
358
358
  low = midpoint;
359
359
  } else {
360
360
  high = midpoint - 1;
@@ -397,7 +397,7 @@ var SERVER_VERSION;
397
397
  var init_version = __esm({
398
398
  "src/server/version.ts"() {
399
399
  "use strict";
400
- SERVER_VERSION = "3.0.4";
400
+ SERVER_VERSION = "3.0.5";
401
401
  }
402
402
  });
403
403
 
@@ -4683,11 +4683,31 @@ var DEFAULT_TYPE = {
4683
4683
  rng: Math.random
4684
4684
  };
4685
4685
  function randomRange(min, max, rand = Math.random) {
4686
- return min + rand() * (max - min);
4686
+ const sample = rand();
4687
+ const boundedSample = Number.isFinite(sample) ? Math.min(1, Math.max(0, sample)) : 0;
4688
+ return min + boundedSample * (max - min);
4687
4689
  }
4688
- function sleep(ms) {
4689
- return new Promise((resolve7) => {
4690
- setTimeout(resolve7, Math.max(0, ms));
4690
+ function sleep(ms, signal) {
4691
+ if (signal?.aborted) {
4692
+ return Promise.reject(new Error("Operation aborted"));
4693
+ }
4694
+ return new Promise((resolve7, reject) => {
4695
+ let settled = false;
4696
+ const timer = setTimeout(() => finish(resolve7), Math.max(0, ms));
4697
+ const onAbort = () => finish(() => reject(new Error("Operation aborted")));
4698
+ const finish = (callback) => {
4699
+ if (settled) {
4700
+ return;
4701
+ }
4702
+ settled = true;
4703
+ clearTimeout(timer);
4704
+ signal?.removeEventListener("abort", onAbort);
4705
+ callback();
4706
+ };
4707
+ signal?.addEventListener("abort", onAbort, { once: true });
4708
+ if (signal?.aborted) {
4709
+ onAbort();
4710
+ }
4691
4711
  });
4692
4712
  }
4693
4713
  async function humanMouseMove(page, x1, y1, x2, y2, durationMs = 80, options = {}) {
@@ -4706,15 +4726,18 @@ async function humanType(page, text, options = {}) {
4706
4726
  const cfg = { ...DEFAULT_TYPE, ...options, rng };
4707
4727
  const keyboard = page.keyboard;
4708
4728
  for (const char of text) {
4729
+ if (cfg.signal?.aborted) {
4730
+ throw new Error("Operation aborted");
4731
+ }
4709
4732
  if (char === " ") {
4710
4733
  await keyboard.down("Space");
4711
4734
  await keyboard.up("Space");
4712
4735
  } else {
4713
4736
  await keyboard.type(char);
4714
4737
  }
4715
- await sleep(randomRange(cfg.minDelayMs, cfg.maxDelayMs, cfg.rng));
4738
+ await sleep(randomRange(cfg.minDelayMs, cfg.maxDelayMs, cfg.rng), cfg.signal);
4716
4739
  if (cfg.rng() < cfg.thinkPauseChance) {
4717
- await sleep(randomRange(cfg.thinkPauseMinMs, cfg.thinkPauseMaxMs, cfg.rng));
4740
+ await sleep(randomRange(cfg.thinkPauseMinMs, cfg.thinkPauseMaxMs, cfg.rng), cfg.signal);
4718
4741
  }
4719
4742
  }
4720
4743
  }
@@ -9436,6 +9459,7 @@ var BrowserService = class {
9436
9459
  try {
9437
9460
  await humanMouseMove(state.page, 0, 0, centerX, centerY, 80);
9438
9461
  } catch {
9462
+ throwIfAborted(signal);
9439
9463
  }
9440
9464
  }
9441
9465
  async clickTarget(state, target, button, clickCount, signal, frame = state.page.mainFrame(), pointerType = "mouse") {
@@ -9949,7 +9973,7 @@ var BrowserService = class {
9949
9973
  if (!nativeControlValueSet) {
9950
9974
  throwIfAborted(signal);
9951
9975
  if (this.stealthSettings().behaviorEnabled) {
9952
- await humanType(state.page, text);
9976
+ await humanType(state.page, text, { signal });
9953
9977
  } else {
9954
9978
  await state.page.keyboard.type(text);
9955
9979
  }