surf-cli 2.17.0 → 2.19.0

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.
@@ -51,7 +51,7 @@ function formatToolContent(result, log = () => {}, options = {}) {
51
51
 
52
52
  if (!result) return text("OK");
53
53
 
54
- if (result.session || Array.isArray(result.sessions) || Object.hasOwn(result, "targetClosed")) {
54
+ if (result.session || Array.isArray(result.sessions) || Array.isArray(result.removed) || Object.hasOwn(result, "targetClosed")) {
55
55
  return text(JSON.stringify(result, null, 2));
56
56
  }
57
57
 
@@ -462,13 +462,37 @@ function formatToolContent(result, log = () => {}, options = {}) {
462
462
  }
463
463
 
464
464
  // Strip internal fields before JSON output
465
- const { _resolvedTabId, _hint, ...cleanResult } = result;
465
+ const { _resolvedTabId, _resolvedWindowId, _hint, ...cleanResult } = result;
466
466
  if (_hint) {
467
467
  return text(JSON.stringify(cleanResult) + `\n[hint] ${_hint}`);
468
468
  }
469
469
  return text(JSON.stringify(cleanResult));
470
470
  }
471
471
 
472
+ /**
473
+ * Readiness expectations accept both CLI flag spelling (--url-prefix) and
474
+ * socket API spelling (urlPrefix). Empty values are dropped.
475
+ */
476
+ function readinessExpectations(a) {
477
+ const pick = (...keys) => {
478
+ for (const key of keys) {
479
+ const value = a[key];
480
+ if (typeof value === "string" && value.trim() !== "") return value;
481
+ }
482
+ return undefined;
483
+ };
484
+ const expect = {
485
+ selector: pick("selector"),
486
+ text: pick("text"),
487
+ urlPrefix: pick("urlPrefix", "url-prefix"),
488
+ emptyText: pick("emptyText", "empty-text"),
489
+ };
490
+ for (const key of Object.keys(expect)) {
491
+ if (expect[key] === undefined) delete expect[key];
492
+ }
493
+ return expect;
494
+ }
495
+
472
496
  /**
473
497
  * Map computer action to extension message
474
498
  */
@@ -871,10 +895,23 @@ function mapToolToMessage(tool, args, tabId) {
871
895
  return { type: "WAIT_FOR_URL", pattern: a.pattern || a.url, timeout: a.timeout, ...baseMsg };
872
896
  case "wait.dom":
873
897
  return { type: "WAIT_FOR_DOM_STABLE", stable: a.stable || 100, timeout: a.timeout || 5000, ...baseMsg };
898
+ case "wait.ready":
899
+ return {
900
+ type: "WAIT_FOR_READY",
901
+ expect: readinessExpectations(a),
902
+ timeout: a.timeout,
903
+ interval: a.interval,
904
+ accept: a.accept,
905
+ ...baseMsg,
906
+ };
907
+ case "page.readiness":
908
+ return { type: "PAGE_READINESS", expect: readinessExpectations(a), ...baseMsg };
874
909
  case "wait.load":
875
910
  return { type: "WAIT_FOR_LOAD", timeout: a.timeout || 30000, ...baseMsg };
876
911
  case "frame.list":
877
912
  return { type: "GET_FRAMES", ...baseMsg };
913
+ case "frame.diagnose":
914
+ return { type: "FRAME_DIAGNOSE", ...baseMsg };
878
915
  case "frame.switch":
879
916
  return {
880
917
  type: "FRAME_SWITCH",
@@ -1280,4 +1317,4 @@ function mapToolToMessage(tool, args, tabId) {
1280
1317
  }
1281
1318
  }
1282
1319
 
1283
- module.exports = { mapToolToMessage, mapComputerAction, formatToolContent, formatToolError, buildProviderUploadMessage };
1320
+ module.exports = { mapToolToMessage, mapComputerAction, formatToolContent, formatToolError, buildProviderUploadMessage, readinessExpectations };
@@ -15,6 +15,9 @@ const QUEUE_TIMEOUT_MS = 60000;
15
15
  const DEFAULT_DEADLINE_MS = 60000;
16
16
  const MAX_DEADLINE_MS = 50 * 60 * 1000;
17
17
  const CLEANUP_GRACE_MS = 60000;
18
+ const READINESS_DEFAULT_TIMEOUT_MS = 20000;
19
+ const READINESS_MAX_TIMEOUT_MS = 120000;
20
+ const READINESS_DEADLINE_GRACE_MS = 5000;
18
21
  const PROVIDER_DEFAULT_TIMEOUT_SECONDS = {
19
22
  ai: 300,
20
23
  aistudio: 300,
@@ -29,6 +32,13 @@ const PROVIDER_DEFAULT_TIMEOUT_SECONDS = {
29
32
  };
30
33
 
31
34
  function resolveRequestDeadlineMs(tool, args = {}) {
35
+ if (tool === "wait.ready") {
36
+ const requestedMs = Number(args?.timeout);
37
+ const timeoutMs = Number.isFinite(requestedMs) && requestedMs > 0
38
+ ? Math.min(requestedMs, READINESS_MAX_TIMEOUT_MS)
39
+ : READINESS_DEFAULT_TIMEOUT_MS;
40
+ return timeoutMs + READINESS_DEADLINE_GRACE_MS;
41
+ }
32
42
  const defaultSeconds = PROVIDER_DEFAULT_TIMEOUT_SECONDS[tool];
33
43
  if (defaultSeconds === undefined) return DEFAULT_DEADLINE_MS;
34
44
  const rawTimeout = tool === "playbook.run" && args && typeof args === "object" && !Array.isArray(args)