oira666_pi-browser-agent 0.0.22 → 0.0.23
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/README.md +12 -0
- package/package.json +1 -1
- package/src/tools/_register.ts +2 -2
- package/src/tools/browser_js_navigation_tools.ts +9 -9
- package/src/tools/browser_task_tools.ts +3 -1
- package/tests/tools/browser-js-navigation-tools.test.ts +20 -0
- package/tests/tools/browser-task-tools.test.ts +26 -0
package/README.md
CHANGED
|
@@ -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
package/src/tools/_register.ts
CHANGED
|
@@ -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', '
|
|
28
|
-
['browser_run_js', '
|
|
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
|
|
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: '
|
|
286
|
-
promptSnippet: '
|
|
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:
|
|
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: '
|
|
301
|
-
promptSnippet: '
|
|
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:
|
|
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 ??
|
|
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 ??
|
|
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;
|