omowright 0.3.3 → 0.3.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.js CHANGED
@@ -24458,15 +24458,29 @@ async function emulateMedia(options = {}) {
24458
24458
  }
24459
24459
 
24460
24460
  // src/redact-value.ts
24461
+ var REMOVED_ANYWHERE_FROM_LENGTH = 4;
24461
24462
  function redactValue(error, value) {
24462
24463
  if (value.length === 0)
24463
24464
  return error;
24464
24465
  const replacement = `<redacted, ${value.length} chars>`;
24465
24466
  const forms = [...new Set([value, JSON.stringify(value).slice(1, -1)])].toSorted((left, right) => right.length - left.length).map((form) => form.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
24466
- const pattern = new RegExp(`(?<![\\p{L}\\p{N}])(?:${forms.join("|")})(?![\\p{L}\\p{N}])`, "gu");
24467
+ const anyForm = `(?:${forms.join("|")})`;
24468
+ const pattern = new RegExp(value.length >= REMOVED_ANYWHERE_FROM_LENGTH ? anyForm : `(?<![\\p{L}\\p{N}])${anyForm}(?![\\p{L}\\p{N}])`, "gu");
24467
24469
  const scrub = (text) => text.replace(pattern, replacement);
24468
- if (typeof error === "string")
24469
- return scrub(error);
24470
+ const scrubPayload = (payload) => {
24471
+ if (typeof payload === "string")
24472
+ return scrub(payload);
24473
+ if (payload === undefined || payload === null)
24474
+ return payload;
24475
+ try {
24476
+ const text = JSON.stringify(payload);
24477
+ return typeof text === "string" ? JSON.parse(scrub(text)) : payload;
24478
+ } catch {
24479
+ return `<redacted, unreadable ${typeof payload}>`;
24480
+ }
24481
+ };
24482
+ if (!(error instanceof Error))
24483
+ return scrubPayload(error);
24470
24484
  const seen = new Set;
24471
24485
  for (let link = error;link instanceof Error && !seen.has(link); link = link.cause) {
24472
24486
  seen.add(link);
@@ -24475,7 +24489,9 @@ function redactValue(error, value) {
24475
24489
  link.stack = scrub(link.stack);
24476
24490
  const data = Reflect.get(link, "data");
24477
24491
  if (data !== undefined)
24478
- Reflect.set(link, "data", JSON.parse(scrub(JSON.stringify(data) ?? "null")));
24492
+ Reflect.set(link, "data", scrubPayload(data));
24493
+ if (link.cause !== undefined && !(link.cause instanceof Error))
24494
+ link.cause = scrubPayload(link.cause);
24479
24495
  }
24480
24496
  return error;
24481
24497
  }
@@ -35703,7 +35719,7 @@ async function snapshotWithFrames(page, opts = {}) {
35703
35719
  // package.json
35704
35720
  var package_default = {
35705
35721
  name: "omowright",
35706
- version: "0.3.3",
35722
+ version: "0.3.5",
35707
35723
  description: "OmOWright browser automation for standard Chromium CDP endpoints.",
35708
35724
  keywords: [
35709
35725
  "accessibility-snapshot",
@@ -35754,7 +35770,7 @@ var package_default = {
35754
35770
  "test:cloak-profile": "bun test test/cloak-profile.test.ts test/cloak-profile.integration.test.ts",
35755
35771
  typecheck: "bun check --no-script --no-pretty -p tsconfig.json",
35756
35772
  "typecheck:control": "bun scripts/typecheck-control.ts",
35757
- check: "bun run typecheck:control && bun run typecheck && bun run lint && bun run fmt:check",
35773
+ check: "bun scripts/bsk-protocol.ts --check && bun run typecheck:control && bun run typecheck && bun run lint && bun run fmt:check",
35758
35774
  lint: "oxlint --deny-warnings src bin bridge test scripts && bun scripts/lint-ratchet.ts",
35759
35775
  "lint:ratchet:update": "bun scripts/lint-ratchet.ts --update",
35760
35776
  "lint:fix": "oxlint --fix src bin bridge test scripts",
@@ -37192,7 +37208,7 @@ function decodeResponse(line, rpcId, method) {
37192
37208
  }
37193
37209
  // src/bsk/targets.ts
37194
37210
  var REF_SHAPE = /^@?e\d+$/;
37195
- function resolveTarget(target) {
37211
+ function elementTarget(target) {
37196
37212
  if (typeof target === "string") {
37197
37213
  return REF_SHAPE.test(target) ? { ref: target } : { selector: target };
37198
37214
  }
@@ -37202,14 +37218,31 @@ function resolveTarget(target) {
37202
37218
  return { ref: spec.ref };
37203
37219
  if (typeof spec.selector === "string")
37204
37220
  return { selector: spec.selector };
37221
+ }
37222
+ return;
37223
+ }
37224
+ function resolveTarget(target) {
37225
+ const element = elementTarget(target);
37226
+ if (element)
37227
+ return element;
37228
+ if (target && typeof target === "object") {
37229
+ const spec = target;
37205
37230
  if (typeof spec.captureId === "string") {
37231
+ if (typeof spec.x !== "number" || typeof spec.y !== "number")
37232
+ throw new TypeError("a {captureId, x, y} target needs numeric x and y image coordinates");
37206
37233
  return { capture_id: spec.captureId, image_x: spec.x, image_y: spec.y };
37207
37234
  }
37208
37235
  }
37209
37236
  throw new TypeError("target must be a ref ('e3' / '@e3'), a CSS selector, or {captureId, x, y}");
37210
37237
  }
37211
- function optionalTarget(target) {
37212
- return target === undefined ? {} : resolveTarget(target);
37238
+ function resolveElementTarget(target) {
37239
+ const element = elementTarget(target);
37240
+ if (element)
37241
+ return element;
37242
+ throw new TypeError("target must be a ref ('e3' / '@e3') or a CSS selector");
37243
+ }
37244
+ function optionalElementTarget(target) {
37245
+ return target === undefined ? {} : resolveElementTarget(target);
37213
37246
  }
37214
37247
  function compact(params) {
37215
37248
  const out = {};
@@ -37219,13 +37252,22 @@ function compact(params) {
37219
37252
  return out;
37220
37253
  }
37221
37254
 
37255
+ // src/bsk/shared-tab.ts
37256
+ function sharedTab({ context, observation, expect, dependsOn, ...unknown }) {
37257
+ const extra = Object.keys(unknown);
37258
+ if (extra.length > 0) {
37259
+ throw new TypeError(`unknown option ${extra.map((key) => JSON.stringify(key)).join(", ")}: a shared-tab action takes { context, observation, expect, dependsOn } besides its own options`);
37260
+ }
37261
+ return { context_id: context, observation_id: observation, expect, depends_on: dependsOn };
37262
+ }
37263
+
37222
37264
  // src/bsk/screenshot.ts
37223
37265
  function fromBase64(value, field) {
37224
37266
  if (typeof value !== "string")
37225
37267
  throw new TypeError(`${field} is not base64 text`);
37226
37268
  return Buffer.from(value, "base64");
37227
37269
  }
37228
- async function captureScreenshot(session, { ref, tabId, fullPage = false, scope, timeoutMs, context, dependsOn } = {}) {
37270
+ async function captureScreenshot(session, { ref, tabId, fullPage = false, scope, timeoutMs, ...shared } = {}) {
37229
37271
  if (!fullPage) {
37230
37272
  const result = await session.tool("screenshot", { ref, tab_id: tabId });
37231
37273
  return {
@@ -37243,16 +37285,18 @@ async function captureScreenshot(session, { ref, tabId, fullPage = false, scope,
37243
37285
  scope,
37244
37286
  tab_id: tabId,
37245
37287
  timeout_ms: timeoutMs,
37246
- context_id: context,
37247
- depends_on: dependsOn
37288
+ ...sharedTab(shared)
37248
37289
  });
37249
- const buffer = await readCapture(session, readProperty(started, "capture_id"), readProperty(started, "byte_size"));
37290
+ const captureId = readProperty(started, "capture_id");
37291
+ if (typeof captureId !== "string")
37292
+ throw new TypeError("screenshot_full_page returned no capture_id");
37293
+ const buffer = await readCapture(session, captureId, readProperty(started, "byte_size"));
37250
37294
  return {
37251
37295
  buffer,
37252
37296
  width: readProperty(started, "width"),
37253
37297
  height: readProperty(started, "height"),
37254
37298
  format: readProperty(started, "format"),
37255
- captureId: readProperty(started, "capture_id"),
37299
+ captureId,
37256
37300
  scope: readProperty(started, "scope") ?? scope ?? null,
37257
37301
  tabId: readProperty(started, "tab_id"),
37258
37302
  dialogs: readProperty(started, "dialogs") ?? []
@@ -37283,19 +37327,85 @@ async function readCapture(session, captureId, byteSize) {
37283
37327
  return buffer;
37284
37328
  }
37285
37329
 
37330
+ // src/bsk/first-navigate.ts
37331
+ var BOOTSTRAP_REFUSAL = "The initial task tab changed; synchronize before acting";
37332
+ var BOOTSTRAP_SETTLE_TIMEOUT_MS = 1e4;
37333
+ var INITIAL_BLANK_URLS = new Set(["", "about:blank"]);
37334
+ function isBootstrapRefusal(error) {
37335
+ return error instanceof BskRpcError && error.code === "permission_denied" && error.message === BOOTSTRAP_REFUSAL && optionalProperty(error.data, "reason") === "cooperation_sync_required" && optionalProperty(error.data, "effect_state") === "none";
37336
+ }
37337
+ function taskTab(tabs, tabId) {
37338
+ const list = listOrEmpty(readProperty(tabs, "tabs"), "tab_list tabs");
37339
+ return tabId === undefined ? list.find((tab) => optionalProperty(tab, "active") === true) : list.find((tab) => optionalProperty(tab, "tab_id") === tabId);
37340
+ }
37341
+ async function settleInitialTab(session, refusal, tabId) {
37342
+ const waited = await session.waitForNavigation({
37343
+ ...tabId === undefined ? {} : { tabId },
37344
+ waitUntil: "load",
37345
+ timeoutMs: BOOTSTRAP_SETTLE_TIMEOUT_MS
37346
+ });
37347
+ const reached = optionalProperty(waited, "reached");
37348
+ const tab = taskTab(await session.tabList({ scope: "agent" }), tabId);
37349
+ const url = optionalProperty(tab, "url");
37350
+ if (reached === "load" && INITIAL_BLANK_URLS.has(url))
37351
+ return;
37352
+ const where = tab === undefined ? "no task tab is listed" : `tab ${String(optionalProperty(tab, "tab_id"))} is at ${url === "" ? "(no URL yet)" : String(url)}`;
37353
+ throw new BskRpcError(refusal.code, `${refusal.message}: the first navigate was refused before the task tab settled, and it was not sent again because wait_for_navigation reached ${JSON.stringify(reached)} and ${where}`, refusal.data);
37354
+ }
37355
+
37356
+ // src/bsk/dom-reads.ts
37357
+ function readNodes(session, target, { fields, maxNodes, maxBytes, tabId, timeoutMs, context } = {}) {
37358
+ return session.tool("read", {
37359
+ ...optionalElementTarget(target),
37360
+ fields,
37361
+ max_nodes: maxNodes,
37362
+ max_bytes: maxBytes,
37363
+ tab_id: tabId,
37364
+ timeout_ms: timeoutMs,
37365
+ context_id: context
37366
+ });
37367
+ }
37368
+ function extractItems(session, action, { target, itemSelector, fields, maxRows, maxColumns, maxBytes, targetId, tabId, timeoutMs } = {}) {
37369
+ return session.tool("extract", {
37370
+ action,
37371
+ ...optionalElementTarget(target),
37372
+ item_selector: itemSelector,
37373
+ fields,
37374
+ max_rows: maxRows,
37375
+ max_columns: maxColumns,
37376
+ max_bytes: maxBytes,
37377
+ target_id: targetId,
37378
+ tab_id: tabId,
37379
+ timeout_ms: timeoutMs
37380
+ });
37381
+ }
37382
+ function waitForElement(session, target, { state, pollMs, tabId, timeoutMs }) {
37383
+ return session.tool("wait_for_element", {
37384
+ ...resolveElementTarget(target),
37385
+ state,
37386
+ poll_ms: pollMs,
37387
+ tab_id: tabId,
37388
+ timeout_ms: timeoutMs
37389
+ });
37390
+ }
37391
+
37286
37392
  // src/bsk/session.ts
37287
37393
  var SESSION_STOP_TIMEOUT_MS = 3600000;
37288
- function sharedTab({ context, dependsOn, ...unknown }) {
37289
- const extra = Object.keys(unknown);
37290
- if (extra.length > 0) {
37291
- throw new TypeError(`unknown option ${extra.map((key) => JSON.stringify(key)).join(", ")}: a shared-tab action takes { context, dependsOn } besides its own options`);
37292
- }
37293
- return { context_id: context, depends_on: dependsOn };
37394
+ var text = (value) => typeof value === "string" ? value : undefined;
37395
+ function cooperateReply(reply) {
37396
+ const fields = typeof reply === "object" && reply !== null ? reply : {};
37397
+ const nested = optionalProperty(optionalProperty(reply, "observation"), "observation_id");
37398
+ return {
37399
+ ...fields,
37400
+ context_id: text(optionalProperty(reply, "context_id")),
37401
+ observation_id: text(optionalProperty(reply, "observation_id")) ?? text(nested)
37402
+ };
37294
37403
  }
37295
37404
 
37296
37405
  class BskSession {
37297
37406
  #client;
37298
37407
  #stopped = false;
37408
+ #acted = false;
37299
37409
  constructor(client, { sessionId, browserInstanceId = null, agentWindowId = null, interaction = null } = {}) {
37300
37410
  if (typeof sessionId !== "string" || sessionId.length === 0)
37301
37411
  throw new TypeError("BskSession requires a sessionId");
@@ -37311,6 +37421,14 @@ class BskSession {
37311
37421
  get stopped() {
37312
37422
  return this.#stopped;
37313
37423
  }
37424
+ #call(name, params) {
37425
+ return this.tool(name, params);
37426
+ }
37427
+ #act(name, params, shared) {
37428
+ const wire = { ...params, ...sharedTab(shared) };
37429
+ this.#acted = true;
37430
+ return this.tool(name, wire);
37431
+ }
37314
37432
  tool(name, params = {}) {
37315
37433
  if (this.#stopped)
37316
37434
  return Promise.reject(new Error(`BrowserSkill session ${this.sessionId} is stopped`));
@@ -37318,37 +37436,41 @@ class BskSession {
37318
37436
  idPrefix: name.replace(/_/g, "-")
37319
37437
  });
37320
37438
  }
37321
- cooperate(action, { tabId, timeoutMs, maxTokens } = {}) {
37322
- return this.tool("cooperate", { action, tab_id: tabId, timeout_ms: timeoutMs, max_tokens: maxTokens }).catch((error) => {
37439
+ cooperate(action, {
37440
+ tabId,
37441
+ timeoutMs,
37442
+ maxTokens,
37443
+ controlPolicy
37444
+ } = {}) {
37445
+ return this.#call("cooperate", {
37446
+ action,
37447
+ tab_id: tabId,
37448
+ timeout_ms: timeoutMs,
37449
+ max_tokens: maxTokens,
37450
+ control_policy: controlPolicy
37451
+ }).then(cooperateReply, (error) => {
37323
37452
  if (error instanceof BskRpcError && error.code === "unknown_method")
37324
- return { context_id: undefined, supported: false, ready: true };
37453
+ return { context_id: undefined, observation_id: undefined, supported: false, ready: true };
37325
37454
  throw error;
37326
37455
  });
37327
37456
  }
37328
- navigate(url, { tabId, waitUntil, timeoutMs, ...shared } = {}) {
37329
- return this.tool("navigate", {
37330
- url,
37331
- tab_id: tabId,
37332
- wait_until: waitUntil,
37333
- timeout_ms: timeoutMs,
37334
- ...sharedTab(shared)
37335
- });
37457
+ async navigate(url, { tabId, waitUntil, timeoutMs, ...shared } = {}) {
37458
+ const send = () => this.#act("navigate", { url, tab_id: tabId, wait_until: waitUntil, timeout_ms: timeoutMs }, shared);
37459
+ const first = !this.#acted && shared.context === undefined;
37460
+ try {
37461
+ return await send();
37462
+ } catch (error) {
37463
+ if (!first || !isBootstrapRefusal(error))
37464
+ throw error;
37465
+ await settleInitialTab(this, error, tabId);
37466
+ return send();
37467
+ }
37336
37468
  }
37337
37469
  back({ tabId, waitUntil, timeoutMs, ...shared } = {}) {
37338
- return this.tool("navigate_back", {
37339
- tab_id: tabId,
37340
- wait_until: waitUntil,
37341
- timeout_ms: timeoutMs,
37342
- ...sharedTab(shared)
37343
- });
37470
+ return this.#act("navigate_back", { tab_id: tabId, wait_until: waitUntil, timeout_ms: timeoutMs }, shared);
37344
37471
  }
37345
37472
  forward({ tabId, waitUntil, timeoutMs, ...shared } = {}) {
37346
- return this.tool("navigate_forward", {
37347
- tab_id: tabId,
37348
- wait_until: waitUntil,
37349
- timeout_ms: timeoutMs,
37350
- ...sharedTab(shared)
37351
- });
37473
+ return this.#act("navigate_forward", { tab_id: tabId, wait_until: waitUntil, timeout_ms: timeoutMs }, shared);
37352
37474
  }
37353
37475
  reload({
37354
37476
  tabId,
@@ -37357,13 +37479,7 @@ class BskSession {
37357
37479
  hard,
37358
37480
  ...shared
37359
37481
  } = {}) {
37360
- return this.tool("reload", {
37361
- tab_id: tabId,
37362
- wait_until: waitUntil,
37363
- timeout_ms: timeoutMs,
37364
- hard,
37365
- ...sharedTab(shared)
37366
- });
37482
+ return this.#act("reload", { tab_id: tabId, wait_until: waitUntil, timeout_ms: timeoutMs, hard }, shared);
37367
37483
  }
37368
37484
  observe({
37369
37485
  cursor,
@@ -37374,25 +37490,24 @@ class BskSession {
37374
37490
  probeHover,
37375
37491
  ...shared
37376
37492
  } = {}) {
37377
- return this.tool("observe", {
37493
+ return this.#act("observe", {
37378
37494
  cursor,
37379
37495
  tab_id: tabId,
37380
37496
  max_depth: maxDepth,
37381
37497
  max_tokens: maxTokens,
37382
37498
  debug_surfaces: debugSurfaces,
37383
- probe_hover: probeHover,
37384
- ...sharedTab(shared)
37385
- });
37499
+ probe_hover: probeHover
37500
+ }, shared);
37386
37501
  }
37387
37502
  snapshot({
37388
37503
  tabId,
37389
37504
  maxDepth,
37390
37505
  maxTokens
37391
37506
  } = {}) {
37392
- return this.tool("snapshot", { tab_id: tabId, max_depth: maxDepth, max_tokens: maxTokens });
37507
+ return this.#call("snapshot", { tab_id: tabId, max_depth: maxDepth, max_tokens: maxTokens });
37393
37508
  }
37394
37509
  getHtml({ ref, tabId, maxBytes } = {}) {
37395
- return this.tool("get_html", { ref, tab_id: tabId, max_bytes: maxBytes });
37510
+ return this.#call("get_html", { ref, tab_id: tabId, max_bytes: maxBytes });
37396
37511
  }
37397
37512
  screenshot(options) {
37398
37513
  return captureScreenshot(this, options);
@@ -37405,15 +37520,7 @@ class BskSession {
37405
37520
  timeoutMs,
37406
37521
  ...shared
37407
37522
  } = {}) {
37408
- return this.tool("click", {
37409
- ...resolveTarget(target),
37410
- button,
37411
- click_count: clickCount,
37412
- modifiers,
37413
- tab_id: tabId,
37414
- timeout_ms: timeoutMs,
37415
- ...sharedTab(shared)
37416
- });
37523
+ return this.#act("click", { ...resolveTarget(target), button, click_count: clickCount, modifiers, tab_id: tabId, timeout_ms: timeoutMs }, shared);
37417
37524
  }
37418
37525
  hover(target, {
37419
37526
  modifiers,
@@ -37422,30 +37529,16 @@ class BskSession {
37422
37529
  timeoutMs,
37423
37530
  ...shared
37424
37531
  } = {}) {
37425
- return this.tool("hover", {
37426
- ...resolveTarget(target),
37427
- modifiers,
37428
- settle_ms: settleMs,
37429
- tab_id: tabId,
37430
- timeout_ms: timeoutMs,
37431
- ...sharedTab(shared)
37432
- });
37532
+ return this.#act("hover", { ...resolveElementTarget(target), modifiers, settle_ms: settleMs, tab_id: tabId, timeout_ms: timeoutMs }, shared);
37433
37533
  }
37434
37534
  focus(target, { tabId, timeoutMs, ...shared } = {}) {
37435
- return this.tool("focus", { ...resolveTarget(target), tab_id: tabId, timeout_ms: timeoutMs, ...sharedTab(shared) });
37535
+ return this.#act("focus", { ...resolveElementTarget(target), tab_id: tabId, timeout_ms: timeoutMs }, shared);
37436
37536
  }
37437
37537
  blur(target, { tabId, timeoutMs, ...shared } = {}) {
37438
- return this.tool("blur", { ...resolveTarget(target), tab_id: tabId, timeout_ms: timeoutMs, ...sharedTab(shared) });
37538
+ return this.#act("blur", { ...resolveElementTarget(target), tab_id: tabId, timeout_ms: timeoutMs }, shared);
37439
37539
  }
37440
37540
  fill(target, value, { clearBefore, tabId, timeoutMs, ...shared } = {}) {
37441
- return this.tool("fill", {
37442
- ...resolveTarget(target),
37443
- value,
37444
- clear_before: clearBefore,
37445
- tab_id: tabId,
37446
- timeout_ms: timeoutMs,
37447
- ...sharedTab(shared)
37448
- }).catch((error) => {
37541
+ return this.#act("fill", { ...resolveElementTarget(target), value, clear_before: clearBefore, tab_id: tabId, timeout_ms: timeoutMs }, shared).catch((error) => {
37449
37542
  throw redactValue(error, value);
37450
37543
  });
37451
37544
  }
@@ -37457,32 +37550,18 @@ class BskSession {
37457
37550
  timeoutMs,
37458
37551
  ...shared
37459
37552
  } = {}) {
37460
- return this.tool("press", {
37461
- key,
37462
- ...optionalTarget(target),
37463
- modifiers,
37464
- hold_ms: holdMs,
37465
- tab_id: tabId,
37466
- timeout_ms: timeoutMs,
37467
- ...sharedTab(shared)
37468
- });
37553
+ return this.#act("press", { key, ...optionalElementTarget(target), modifiers, hold_ms: holdMs, tab_id: tabId, timeout_ms: timeoutMs }, shared);
37469
37554
  }
37470
37555
  select(target, values, { tabId, timeoutMs, ...shared } = {}) {
37471
- return this.tool("select", {
37472
- ...resolveTarget(target),
37556
+ return this.#act("select", {
37557
+ ...resolveElementTarget(target),
37473
37558
  values: Array.isArray(values) ? values : [values],
37474
37559
  tab_id: tabId,
37475
- timeout_ms: timeoutMs,
37476
- ...sharedTab(shared)
37477
- });
37560
+ timeout_ms: timeoutMs
37561
+ }, shared);
37478
37562
  }
37479
37563
  scrollTo(target, { tabId, timeoutMs, ...shared } = {}) {
37480
- return this.tool("scroll_to", {
37481
- ...resolveTarget(target),
37482
- tab_id: tabId,
37483
- timeout_ms: timeoutMs,
37484
- ...sharedTab(shared)
37485
- });
37564
+ return this.#act("scroll_to", { ...resolveElementTarget(target), tab_id: tabId, timeout_ms: timeoutMs }, shared);
37486
37565
  }
37487
37566
  wheel({
37488
37567
  deltaX = 0,
@@ -37493,50 +37572,83 @@ class BskSession {
37493
37572
  timeoutMs,
37494
37573
  ...shared
37495
37574
  } = {}) {
37496
- return this.tool("wheel", {
37497
- ...optionalTarget(target),
37575
+ return this.#act("wheel", {
37576
+ ...optionalElementTarget(target),
37498
37577
  delta_x: deltaX,
37499
37578
  delta_y: deltaY,
37500
37579
  modifiers,
37501
37580
  tab_id: tabId,
37502
- timeout_ms: timeoutMs,
37503
- ...sharedTab(shared)
37504
- });
37581
+ timeout_ms: timeoutMs
37582
+ }, shared);
37505
37583
  }
37506
- evaluate(expression, { tabId, awaitPromise, returnByValue, timeoutMs, ...shared } = {}) {
37507
- return this.tool("evaluate", {
37584
+ evaluate(expression, { tabId, awaitPromise, returnByValue, timeoutMs, unverified, ...shared } = {}) {
37585
+ return this.#act("evaluate", {
37508
37586
  expression,
37509
37587
  tab_id: tabId,
37510
37588
  await_promise: awaitPromise,
37511
37589
  return_by_value: returnByValue,
37512
37590
  timeout_ms: timeoutMs,
37513
- ...sharedTab(shared)
37514
- });
37591
+ unverified
37592
+ }, shared);
37593
+ }
37594
+ read(target, options) {
37595
+ return readNodes(this, target, options);
37596
+ }
37597
+ extract(action, options) {
37598
+ return extractItems(this, action, options);
37599
+ }
37600
+ waitForElement(target, options) {
37601
+ return waitForElement(this, target, options);
37602
+ }
37603
+ drag(source, {
37604
+ target,
37605
+ delta,
37606
+ mode,
37607
+ button,
37608
+ durationMs,
37609
+ holdMs,
37610
+ modifiers,
37611
+ tabId,
37612
+ timeoutMs,
37613
+ ...shared
37614
+ } = {}) {
37615
+ return this.#act("drag", {
37616
+ source,
37617
+ target,
37618
+ delta,
37619
+ mode,
37620
+ button,
37621
+ duration_ms: durationMs,
37622
+ hold_ms: holdMs,
37623
+ modifiers,
37624
+ tab_id: tabId,
37625
+ timeout_ms: timeoutMs
37626
+ }, shared);
37515
37627
  }
37516
37628
  tabList({ scope } = {}) {
37517
- return this.tool("tab_list", { scope });
37629
+ return this.#call("tab_list", { scope });
37518
37630
  }
37519
37631
  tabCreate({ url, active, index } = {}) {
37520
- return this.tool("tab_create", { url, active, index });
37632
+ return this.#call("tab_create", { url, active, index });
37521
37633
  }
37522
37634
  tabClose(tabId, shared = {}) {
37523
- return this.tool("tab_close", { tab_id: tabId, ...sharedTab(shared) });
37635
+ return this.#act("tab_close", { tab_id: tabId }, shared);
37524
37636
  }
37525
37637
  tabSelect(tabId) {
37526
- return this.tool("tab_select", { tab_id: tabId });
37638
+ return this.#call("tab_select", { tab_id: tabId });
37527
37639
  }
37528
37640
  tabBorrow(tabId, { confirmationTimeoutMs } = {}) {
37529
- return this.tool("tab_borrow", { tab_id: tabId, confirmation_timeout_ms: confirmationTimeoutMs });
37641
+ return this.#call("tab_borrow", { tab_id: tabId, confirmation_timeout_ms: confirmationTimeoutMs });
37530
37642
  }
37531
37643
  tabReturn(tabId) {
37532
- return this.tool("tab_return", { tab_id: tabId });
37644
+ return this.#call("tab_return", { tab_id: tabId });
37533
37645
  }
37534
37646
  waitForNavigation({
37535
37647
  tabId,
37536
37648
  waitUntil,
37537
37649
  timeoutMs
37538
37650
  } = {}) {
37539
- return this.tool("wait_for_navigation", { tab_id: tabId, wait_until: waitUntil, timeout_ms: timeoutMs });
37651
+ return this.#call("wait_for_navigation", { tab_id: tabId, wait_until: waitUntil, timeout_ms: timeoutMs });
37540
37652
  }
37541
37653
  requestHelp({
37542
37654
  prompt,
@@ -37545,13 +37657,13 @@ class BskSession {
37545
37657
  completionCriteria,
37546
37658
  tabId,
37547
37659
  timeoutMs
37548
- } = {}) {
37549
- return this.tool("request_help", {
37660
+ }) {
37661
+ return this.#call("request_help", {
37550
37662
  prompt,
37551
37663
  title,
37552
37664
  tab_id: tabId,
37553
37665
  timeout_ms: timeoutMs,
37554
- targets: targets?.map((t) => resolveTarget(t)),
37666
+ targets: targets?.map((t) => resolveElementTarget(t)),
37555
37667
  completion_criteria: completionCriteria
37556
37668
  });
37557
37669
  }
@@ -37562,7 +37674,7 @@ class BskSession {
37562
37674
  maxTextChars,
37563
37675
  includeStack
37564
37676
  } = {}) {
37565
- return this.tool("console", {
37677
+ return this.#call("console", {
37566
37678
  tab_id: tabId,
37567
37679
  since,
37568
37680
  limit,
@@ -37576,10 +37688,10 @@ class BskSession {
37576
37688
  limit,
37577
37689
  maxTextChars
37578
37690
  } = {}) {
37579
- return this.tool("network", { tab_id: tabId, since, limit, max_text_chars: maxTextChars });
37691
+ return this.#call("network", { tab_id: tabId, since, limit, max_text_chars: maxTextChars });
37580
37692
  }
37581
37693
  resize(width, height, shared = {}) {
37582
- return this.tool("window_resize", { width, height, ...sharedTab(shared) });
37694
+ return this.#act("window_resize", { width, height }, shared);
37583
37695
  }
37584
37696
  emulate({
37585
37697
  tabId,
@@ -37587,7 +37699,7 @@ class BskSession {
37587
37699
  overrides,
37588
37700
  ...shared
37589
37701
  } = {}) {
37590
- return this.tool("emulate", { tab_id: tabId, off, overrides, ...sharedTab(shared) });
37702
+ return this.#act("emulate", { tab_id: tabId, off, overrides }, shared);
37591
37703
  }
37592
37704
  async stop() {
37593
37705
  if (this.#stopped)
@@ -37753,11 +37865,13 @@ function buildSnapshotExpression(options = {}) {
37753
37865
  return { tree: result.tree, refs: result.refs || {}, css, error: result.error };
37754
37866
  })()`;
37755
37867
  }
37756
- async function bskSnapshot(session, { tabId, timeoutMs, context, dependsOn, ...snapshotOptions } = {}) {
37868
+ async function bskSnapshot(session, { tabId, timeoutMs, context, observation, expect, dependsOn, ...snapshotOptions } = {}) {
37757
37869
  const reply = await session.evaluate(buildSnapshotExpression(snapshotOptions), {
37758
37870
  tabId,
37759
37871
  timeoutMs,
37760
37872
  context,
37873
+ observation,
37874
+ expect,
37761
37875
  dependsOn,
37762
37876
  awaitPromise: false,
37763
37877
  returnByValue: true
@@ -2,6 +2,9 @@
2
2
  * Strips a value being entered (fill/type) out of the error its failure raised, so a secret typed
3
3
  * into a form never reaches an agent transcript (#335). The layers below (a CDP transport, the
4
4
  * BrowserSkill daemon) may quote the command they refused, raw or JSON-escaped, in the message,
5
- * the stack, a `data` payload or a cause; each is rewritten in place down the cause chain.
5
+ * the stack, a `data` payload or a cause of any type; each is rewritten in place down the cause chain.
6
+ * A value of four characters or more is removed even where it touches a letter or a digit
7
+ * (`field7<value>`); a shorter one is removed only as a whole token, because taking one or two
8
+ * letters out of every word would leave the message unreadable (fill("a") must keep "locator").
6
9
  */
7
10
  export declare function redactValue(error: unknown, value: string): unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omowright",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "OmOWright browser automation for standard Chromium CDP endpoints.",
5
5
  "keywords": [
6
6
  "accessibility-snapshot",
@@ -51,7 +51,7 @@
51
51
  "test:cloak-profile": "bun test test/cloak-profile.test.ts test/cloak-profile.integration.test.ts",
52
52
  "typecheck": "bun check --no-script --no-pretty -p tsconfig.json",
53
53
  "typecheck:control": "bun scripts/typecheck-control.ts",
54
- "check": "bun run typecheck:control && bun run typecheck && bun run lint && bun run fmt:check",
54
+ "check": "bun scripts/bsk-protocol.ts --check && bun run typecheck:control && bun run typecheck && bun run lint && bun run fmt:check",
55
55
  "lint": "oxlint --deny-warnings src bin bridge test scripts && bun scripts/lint-ratchet.ts",
56
56
  "lint:ratchet:update": "bun scripts/lint-ratchet.ts --update",
57
57
  "lint:fix": "oxlint --fix src bin bridge test scripts",