oira666_pi-browser-agent 0.0.22 → 0.0.24

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/EVERGREEN.md CHANGED
@@ -22,7 +22,9 @@ public `ExtensionAPI` and `ToolDefinition` types from the package root.
22
22
  `pi.registerTool` uses TypeBox parameters, execute's AbortSignal, text/image
23
23
  content, persisted details, outputSchema, structuredContent and isError.
24
24
  `ctx.ui.setStatus` and `notify` report connectivity with delayed outage warnings.
25
- The host TypeBox peer dependency must remain compatible with Pi's validator.
25
+ Tool parameters use JSON Schema-compatible TypeBox constructs; Pi 1.5.0 validates
26
+ and coerces arguments with `@earendil-works/pi-schema`, not TypeBox validation.
27
+ Runtime schema imports already use `typebox`, not the legacy pi-ai re-exports.
26
28
  ## Internal Pi APIs
27
29
  None in runtime code: no deep imports, private fields or undocumented Pi hooks.
28
30
  The compatibility test uses the exported `discoverAndLoadExtensions` loader.
@@ -51,10 +53,10 @@ bridge task execution, result/error persistence, cross-process history and clean
51
53
  A live EVERGREEN_E2E_MODEL call must discover and execute browser_list_tasks even
52
54
  without Chrome. Settings/state are isolated; provider credentials are reused.
53
55
  These tests protect available tools, working forwarding and durable inspection,
54
- not merely individual helper outputs. Tested against latest Pi 1.4.0.
56
+ not merely individual helper outputs. Tested against latest Pi 1.5.0.
55
57
 
56
58
  ## Relevant changelog topics
57
59
  Watch extension lifecycle/reload, tool registration and execution signatures,
58
- AbortSignal propagation, TypeBox validation, text/image result formats,
60
+ AbortSignal propagation, JSON Schema validation/coercion, text/image result formats,
59
61
  outputSchema/structuredContent/isError, session serialization, UI status APIs,
60
62
  CLI JSON events, provider transport and SDK extension loading.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-browser-agent
2
2
 
3
- Tested against Pi 1.4.0
3
+ Tested against Pi 1.5.0
4
4
 
5
5
  `pi-browser-agent` is a pi extension that starts a local WebSocket broker and registers a browser-driving tool suite for `browser-agent-ext`.
6
6
 
@@ -74,6 +74,18 @@ The full toolkit registered for the session is:
74
74
  - `browser_wait_for`
75
75
  - `browser_clear_site_data`
76
76
 
77
+ ## JavaScript input safety
78
+
79
+ `browser_evaluate_js` and `browser_run_js` send every supplied script to the Chrome extension's configured AI provider. The extension translates source into a validated plan rather than executing it in the page. Clicks, focus, typing, keys, shortcuts and scrolling use the input backend selected in extension settings, either CDP or Python. It scrolls off-screen targets into view before interacting, then reads their coordinates again. CDP works without the Python service installed. Only the Python backend needs that service and can affect the foreground desktop.
80
+
81
+ This is a bounded JavaScript translation interface, not an arbitrary JavaScript runtime. Supported actions and fixed DOM reads preserve the plan's result. Unsupported code, invalid model responses, missing provider configuration, cancellation and native-input failures return errors. They never fall back to `element.click()`, synthetic events or direct DOM input. Requesting remote object handles or disabling promise awaiting is unsupported. Console capture is limited to entries represented by the translated plan.
82
+
83
+ The default script timeout is 120 seconds to include model translation and native input. In Jev mode, translation uses the configured helper LLM, not the Jev choice endpoint. In normal mode it uses the configured browser LLM.
84
+
85
+ Both decision modes can report a CAPTCHA through the manual-handoff choice. The task ends with `status: "paused"`, `manualRequired: true` and a screenshot handoff when capture succeeds. No solver model or native input runs after that choice. Complete the challenge yourself, then start a new task. This is not automatic CAPTCHA solving.
86
+
87
+ Use the dedicated inspection tools for HTML, styles, accessibility and other general page inspection. Their trusted internal inspection functions do not go through AI translation. The `world` option does not enable direct page-code execution.
88
+
77
89
  ## Configuration
78
90
 
79
91
  Environment variables:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oira666_pi-browser-agent",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Pi browser agent broker skeleton with lazy browser tool registration",
@@ -29,7 +29,7 @@
29
29
  "typebox": "*"
30
30
  },
31
31
  "devDependencies": {
32
- "@earendil-works/pi-coding-agent": "1.4.0",
32
+ "@earendil-works/pi-coding-agent": "1.5.0",
33
33
  "@types/node": "^26.6.5",
34
34
  "@types/ws": "^8.18.2",
35
35
  "typebox": "^1.4.3",
@@ -24,8 +24,8 @@ const PLACEHOLDER_TOOL_SPECS = [
24
24
  ['browser_get_network', 'Inspect network requests from the browser.'],
25
25
  ['browser_get_accessibility_tree', 'Read the accessibility tree.'],
26
26
  ['browser_get_performance_metrics', 'Read performance metrics.'],
27
- ['browser_evaluate_js', 'Evaluate a JavaScript expression in the page.'],
28
- ['browser_run_js', 'Run longer JavaScript in the page.'],
27
+ ['browser_evaluate_js', 'AI-translate a JavaScript expression into validated native input and page reads.'],
28
+ ['browser_run_js', 'AI-translate JavaScript into validated native input and page reads.'],
29
29
  ['browser_create_tab', 'Create a new browser tab.'],
30
30
  ['browser_list_tabs', 'List browser tabs.'],
31
31
  ['browser_switch_tab', 'Switch to a browser tab.'],
@@ -225,7 +225,7 @@ function createRequestTool(options: {
225
225
  parameters: options.parameters,
226
226
  // `signal` is pi's cancellation handle (Escape). Accepting it here is what
227
227
  // lets an aborted call return at once instead of blocking until the
228
- // per-tool timeout (15s eval / 30s run_js / navigation budgets) expires.
228
+ // per-tool timeout, including AI script translation, expires.
229
229
  async execute(
230
230
  _toolCallId: string,
231
231
  params: Record<string, unknown>,
@@ -282,8 +282,8 @@ function createRequestTool(options: {
282
282
 
283
283
  export const browserEvaluateJsDefinition = {
284
284
  name: 'browser_evaluate_js',
285
- description: 'Evaluate a JavaScript expression in the page and return the value.',
286
- promptSnippet: 'Evaluate JavaScript in the current browser page.',
285
+ description: 'Translate a JavaScript expression with the configured browser AI model, then execute its validated native-input/read plan. Clicks, typing, keys and scrolling use the input backend selected in extension settings, either CDP or Python, with off-screen targets scrolled into view first. Unsupported JavaScript is rejected, never executed directly. Requires a configured browser AI provider.',
286
+ promptSnippet: 'Translate a JavaScript expression into validated native input and page reads.',
287
287
  parameters: Type.Object({
288
288
  tab_id: Type.Optional(Type.Number()),
289
289
  use_active_tab: Type.Optional(Type.Boolean()),
@@ -291,14 +291,14 @@ export const browserEvaluateJsDefinition = {
291
291
  await_promise: Type.Optional(Type.Boolean({ default: true })),
292
292
  return_by_value: Type.Optional(Type.Boolean({ default: true })),
293
293
  world: Type.Optional(Type.Literal('main', { default: 'main' })),
294
- timeout_ms: Type.Optional(Type.Number({ minimum: 1, default: 15_000 })),
294
+ timeout_ms: Type.Optional(Type.Number({ minimum: 1, default: 120_000 })),
295
295
  }),
296
296
  } as const;
297
297
 
298
298
  export const browserRunJsDefinition = {
299
299
  name: 'browser_run_js',
300
- description: 'Run a longer JavaScript program in the page context and optionally capture console output.',
301
- promptSnippet: 'Run longer JavaScript in the browser page.',
300
+ description: 'Translate a JavaScript program with the configured browser AI model, then execute its validated native-input/read plan. All input uses the backend selected in extension settings, either CDP or Python; off-screen targets are scrolled into view first. Supports a bounded set of actions and reads, not arbitrary page JavaScript. Unsupported code fails without direct JavaScript execution.',
301
+ promptSnippet: 'Translate JavaScript into validated native input and page reads.',
302
302
  parameters: Type.Object({
303
303
  tab_id: Type.Optional(Type.Number()),
304
304
  use_active_tab: Type.Optional(Type.Boolean()),
@@ -306,7 +306,7 @@ export const browserRunJsDefinition = {
306
306
  args: Type.Optional(Type.Array(Type.Unknown())),
307
307
  return_by_value: Type.Optional(Type.Boolean({ default: true })),
308
308
  world: Type.Optional(Type.Literal('main', { default: 'main' })),
309
- timeout_ms: Type.Optional(Type.Number({ minimum: 1, default: 30_000 })),
309
+ timeout_ms: Type.Optional(Type.Number({ minimum: 1, default: 120_000 })),
310
310
  capture_console: Type.Optional(Type.Boolean({ default: true })),
311
311
  }),
312
312
  } as const;
@@ -421,12 +421,12 @@ export const browserClearSiteDataDefinition = {
421
421
 
422
422
  export const createBrowserEvaluateJsTool = createRequestTool({
423
423
  ...browserEvaluateJsDefinition,
424
- timeoutFromParams: (params) => Number(params.timeout_ms ?? 15_000) + 1_000,
424
+ timeoutFromParams: (params) => Number(params.timeout_ms ?? 120_000) + 1_000,
425
425
  });
426
426
 
427
427
  export const createBrowserRunJsTool = createRequestTool({
428
428
  ...browserRunJsDefinition,
429
- timeoutFromParams: (params) => Number(params.timeout_ms ?? 30_000) + 1_000,
429
+ timeoutFromParams: (params) => Number(params.timeout_ms ?? 120_000) + 1_000,
430
430
  });
431
431
 
432
432
  export const createBrowserCreateTabTool = createRequestTool({
@@ -13,7 +13,7 @@ interface ToolResult {
13
13
  details: Record<string, unknown>;
14
14
  }
15
15
 
16
- const TERMINAL_TASK_STATUSES = new Set(['done', 'error', 'stopped', 'rejected']);
16
+ const TERMINAL_TASK_STATUSES = new Set(['done', 'error', 'stopped', 'rejected', 'paused']);
17
17
 
18
18
  function terminalStatusOf(data: any): string | null {
19
19
  if (typeof data?.status === 'string' && TERMINAL_TASK_STATUSES.has(data.status)) {
@@ -67,6 +67,8 @@ function statusText(status: string): string {
67
67
  switch (status) {
68
68
  case 'done':
69
69
  return 'completed';
70
+ case 'paused':
71
+ return 'paused for manual input';
70
72
  case 'stopped':
71
73
  return 'stopped';
72
74
  case 'error':
@@ -19,6 +19,15 @@ import {
19
19
  createBrowserSwitchTabTool,
20
20
  } from '../../src/tools/browser_js_navigation_tools.ts';
21
21
 
22
+ test('JavaScript tools disclose AI translation and native-only input instead of arbitrary page execution', () => {
23
+ for (const definition of [browserEvaluateJsDefinition, browserRunJsDefinition]) {
24
+ assert.match(definition.description, /configured browser AI model/);
25
+ assert.match(definition.description, /CDP or Python/);
26
+ assert.match(definition.description, /Unsupported/);
27
+ assert.match(definition.description, /off-screen/);
28
+ }
29
+ });
30
+
22
31
  function textOf(result: any): string {
23
32
  return result.content[0]?.text || '';
24
33
  }
@@ -92,6 +101,17 @@ test('browser_evaluate_js forwards timeout-aware requests, defaults to the activ
92
101
  assert.match(textOf(result), /Full output:/);
93
102
  });
94
103
 
104
+ test('script transport defaults allow 120 seconds for AI translation plus bridge overhead', async () => {
105
+ const budgets: number[] = [];
106
+ const broker = createBrokerStub(async (_type, _params, options) => {
107
+ budgets.push(options.timeoutMs ?? 0);
108
+ return { v: 1, kind: 'response', id: 'script-budget', ok: true, data: { tabId: 7, value: 1 } };
109
+ });
110
+ await createBrowserEvaluateJsTool(broker).execute('evaluate-budget', { expression: '1' });
111
+ await createBrowserRunJsTool(broker).execute('program-budget', { code: 'return 1;' });
112
+ assert.deepEqual(budgets, [121_000, 121_000]);
113
+ });
114
+
95
115
  test('browser_run_js returns structured bridge failures instead of throwing', async () => {
96
116
  const broker = createBrokerStub(async () => ({
97
117
  v: 1,
@@ -84,6 +84,32 @@ function textOf(result: any): string {
84
84
  return result.content[0]?.text || '';
85
85
  }
86
86
 
87
+ test('browser_run_task preserves a manual CAPTCHA pause without claiming completion', async () => {
88
+ const { broker } = await createBroker();
89
+ const socket = await connectBridge(broker, async (frame, ws) => {
90
+ if (frame.type !== 'browser_run_task') return;
91
+ ws.send(JSON.stringify({ v: 1, kind: 'response', id: frame.id, ok: true, data: {
92
+ status: 'paused', reason: 'manual_captcha', manualRequired: true, success: false,
93
+ message: 'Complete the CAPTCHA manually, then start a new task.',
94
+ handoff: { type: 'manual_captcha', screenshotCaptured: false },
95
+ } }));
96
+ });
97
+ try {
98
+ const tools = createToolHarness(broker);
99
+ const result = await tools.get('browser_run_task').execute('manual-captcha', { task: 'Open the form' });
100
+ assert.equal(result.details.ok, true);
101
+ assert.equal(result.details.success, false);
102
+ assert.equal(result.details.status, 'paused');
103
+ assert.equal(result.details.result.manualRequired, true);
104
+ assert.match(textOf(result), /paused for manual input/);
105
+ const history = await broker.taskStore.read(String(result.details.taskId));
106
+ assert.equal(history.at(-1)?.status, 'paused');
107
+ } finally {
108
+ socket.close();
109
+ await broker.stop();
110
+ }
111
+ });
112
+
87
113
  test('browser_run_task happy path targets the active tab and records useful history', async () => {
88
114
  const { broker } = await createBroker();
89
115
  let receivedRequest: any;