@nexface/tools 0.1.18 → 0.1.20

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.
@@ -13,6 +13,7 @@ export declare class PageController {
13
13
  private readonly limits;
14
14
  private readonly animator;
15
15
  private readonly executions;
16
+ inputObserver: ((element: Element, command: PageCommand) => void) | undefined;
16
17
  constructor(limits: ExecutionLimits, animator: ActionFeedback);
17
18
  beginExecution(executionId: string, registry: SnapshotRegistry): void;
18
19
  cancelExecution(executionId: string): void;
@@ -291,6 +291,7 @@ export class PageController {
291
291
  limits;
292
292
  animator;
293
293
  executions = new Map();
294
+ inputObserver;
294
295
  constructor(limits, animator) {
295
296
  this.limits = limits;
296
297
  this.animator = animator;
@@ -678,6 +679,8 @@ export class PageController {
678
679
  }
679
680
  ensureActionable(element);
680
681
  this.requireStillActive(record);
682
+ if (command.method === "fill")
683
+ this.inputObserver?.(element, command);
681
684
  const result = this.performAction(element, command);
682
685
  this.recordCompletedAction(record, command);
683
686
  return result;
@@ -0,0 +1,11 @@
1
+ import type { ExecutionResult, PageCommand } from "./types.js";
2
+ type Feedback = NonNullable<ExecutionResult["inputFeedback"]>;
3
+ export declare class InputObservation {
4
+ private readonly maxResultChars;
5
+ private readonly edits;
6
+ constructor(maxResultChars: number);
7
+ record(element: Element, command: PageCommand): void;
8
+ read(): Feedback;
9
+ clear(): void;
10
+ }
11
+ export {};
@@ -0,0 +1,65 @@
1
+ import { isAgentIgnored } from "./dom.js";
2
+ const sensitive = (element) => isAgentIgnored(element) ||
3
+ (element instanceof HTMLInputElement && ["password", "file", "hidden"].includes(element.type));
4
+ // Scoped to one execution; no DOM references are included in the receipt.
5
+ export class InputObservation {
6
+ maxResultChars;
7
+ edits = new Map();
8
+ constructor(maxResultChars) {
9
+ this.maxResultChars = maxResultChars;
10
+ }
11
+ record(element, command) {
12
+ if (command.method !== "fill")
13
+ return;
14
+ this.edits.delete(element);
15
+ this.edits.set(element, {
16
+ callIndex: command.commandSeq,
17
+ value: sensitive(element) ? "" : String(command.args[0] ?? ""),
18
+ redacted: sensitive(element),
19
+ });
20
+ }
21
+ read() {
22
+ const feedback = [];
23
+ let budget = Math.floor(this.maxResultChars / 4);
24
+ for (const [element, edit] of this.edits) {
25
+ const entry = { callIndex: edit.callIndex };
26
+ try {
27
+ if (edit.redacted || sensitive(element))
28
+ entry.unavailable = "redacted";
29
+ else if (!element.isConnected)
30
+ entry.unavailable = "detached";
31
+ else {
32
+ const observed = element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement
33
+ ? element.value
34
+ : element instanceof HTMLElement && element.isContentEditable
35
+ ? (element.textContent ?? "")
36
+ : undefined;
37
+ if (observed === undefined)
38
+ entry.unavailable = "not-readable";
39
+ else {
40
+ entry.requestedValue = edit.value.slice(0, 256);
41
+ entry.observedValue = observed.slice(0, 256);
42
+ entry.valueMatches = observed === edit.value;
43
+ if (observed.length > 256 || edit.value.length > 256)
44
+ entry.truncated = true;
45
+ }
46
+ }
47
+ }
48
+ catch {
49
+ delete entry.requestedValue;
50
+ delete entry.observedValue;
51
+ delete entry.valueMatches;
52
+ entry.unavailable = "not-readable";
53
+ }
54
+ const size = JSON.stringify(entry).length + 1;
55
+ if (size > budget)
56
+ break;
57
+ budget -= size;
58
+ feedback.push(entry);
59
+ }
60
+ return feedback;
61
+ }
62
+ clear() {
63
+ this.edits.clear();
64
+ }
65
+ }
@@ -415,7 +415,7 @@ function renderTree(nodes, context) {
415
415
  const name = node.name ? ` ${JSON.stringify(normalizeText(node.name))}` : "";
416
416
  const state = serializeState(node.state);
417
417
  const scrollability = serializeScrollability(node.scrollable);
418
- const nextRef = (node.actionable || node.scrollable) && (!node.genericAction || context.genericRefs < 64)
418
+ const nextRef = (node.actionable || node.scrollable) && (!node.genericAction || context.genericRefs < 150)
419
419
  ? `@${context.refs.size + 1}`
420
420
  : undefined;
421
421
  const refText = nextRef ? ` [ref=${nextRef}]` : "";
@@ -3,6 +3,7 @@ import { AgentToolError } from "../runtime.js";
3
3
  import { validateAgentToolInput } from "../shared/schema.js";
4
4
  import { getSnapshotTool, executeActionTool, applyActionTool } from "../shared/page-tools.js";
5
5
  export { getSnapshotTool, executeActionTool, applyActionTool } from "../shared/page-tools.js";
6
+ import { InputObservation } from "./input-observation.js";
6
7
  import { PageController } from "./controller.js";
7
8
  import { ActionFeedback } from "./feedback.js";
8
9
  import { createSnapshot } from "./snapshot.js";
@@ -288,6 +289,8 @@ export function createBrowserToolset(options = {}) {
288
289
  const onAbort = () => cancel();
289
290
  signal.addEventListener("abort", onAbort, { once: true });
290
291
  const tracker = startPageTransitionTracker(mode);
292
+ const inputs = new InputObservation(limits.maxResultChars);
293
+ controller.inputObserver = (element, command) => inputs.record(element, command);
291
294
  feedback.listener = onFeedback;
292
295
  feedback.assertActive = assertActive;
293
296
  let result;
@@ -353,10 +356,21 @@ export function createBrowserToolset(options = {}) {
353
356
  throw new AgentToolError("EXECUTION_OUTCOME_UNKNOWN", error instanceof Error ? error.message : "Browser execution failed.", { refsExpired: true });
354
357
  }
355
358
  finally {
356
- feedback.listener = undefined;
357
- feedback.assertActive = undefined;
358
- tracker.dispose();
359
- signal.removeEventListener("abort", onAbort);
359
+ try {
360
+ if (result) {
361
+ const inputFeedback = inputs.read();
362
+ if (inputFeedback.length)
363
+ result.inputFeedback = inputFeedback;
364
+ }
365
+ }
366
+ finally {
367
+ controller.inputObserver = undefined;
368
+ inputs.clear();
369
+ feedback.listener = undefined;
370
+ feedback.assertActive = undefined;
371
+ tracker.dispose();
372
+ signal.removeEventListener("abort", onAbort);
373
+ }
360
374
  }
361
375
  };
362
376
  const executeCode = {
@@ -94,6 +94,14 @@ export interface ExecutionResult {
94
94
  statement?: string;
95
95
  };
96
96
  snapshot?: PageSnapshot;
97
+ inputFeedback?: {
98
+ callIndex: number;
99
+ requestedValue?: string;
100
+ observedValue?: string;
101
+ valueMatches?: boolean;
102
+ unavailable?: "detached" | "redacted" | "not-readable";
103
+ truncated?: boolean;
104
+ }[];
97
105
  snapshotUnavailable?: boolean;
98
106
  postSnapshotTimedOut?: boolean;
99
107
  refsExpired?: boolean;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@nexface/tools",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
+ "types": "./dist/index.d.ts",
5
6
  "exports": {
6
7
  ".": {
7
8
  "types": "./dist/index.d.ts",