@howaboua/pi-browser 0.0.8 → 0.0.9
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/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/biome.json +1 -1
- package/dist/index.js +21 -2
- package/dist/remote-worker.js +5 -5
- package/dist/src/browser/help.d.ts +1 -1
- package/dist/src/browser/help.js +11 -5
- package/dist/src/browser-tool.d.ts +1 -1
- package/dist/src/browser-tool.js +6 -2
- package/index.ts +25 -2
- package/package.json +8 -8
- package/src/browser/help.ts +11 -7
- package/src/browser-tool.ts +9 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ pi install npm:@howaboua/pi-browser
|
|
|
12
12
|
|
|
13
13
|
Requires Pi 1.0.0 or newer, Node.js 22.19 or newer, and a Chrome-family browser with remote debugging enabled at `chrome://inspect/#remote-debugging`.
|
|
14
14
|
|
|
15
|
-
Pi Codex 3.0.
|
|
15
|
+
Pi Codex 3.0.52 or newer is optional. Without it, Browser remains a normal top-level Pi tool. Do not load Pi Codex's example `browser.toml` custom tool alongside this extension.
|
|
16
16
|
|
|
17
17
|
## Use
|
|
18
18
|
|
package/biome.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,9 +16,28 @@ export default async function browserExtension(pi) {
|
|
|
16
16
|
configError = error instanceof Error ? error.message : String(error);
|
|
17
17
|
}
|
|
18
18
|
const runtime = new BrowserRuntime(routes);
|
|
19
|
-
|
|
19
|
+
let gpt = false;
|
|
20
|
+
const tool = createBrowserTool(runtime, () => gpt);
|
|
20
21
|
registerBrowserCommand(pi);
|
|
21
22
|
pi.registerTool(tool);
|
|
23
|
+
try {
|
|
24
|
+
const { registerGptPromptMode } = await import("@howaboua/pi-codex-conversion/prompt-mode");
|
|
25
|
+
registerGptPromptMode(pi, (active) => {
|
|
26
|
+
gpt = active;
|
|
27
|
+
return [tool];
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (!(error instanceof Error) ||
|
|
32
|
+
!("code" in error) ||
|
|
33
|
+
![
|
|
34
|
+
"ERR_MODULE_NOT_FOUND",
|
|
35
|
+
"MODULE_NOT_FOUND",
|
|
36
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
37
|
+
].includes(String(error.code)) ||
|
|
38
|
+
!error.message.includes(CODE_MODE_PACKAGE))
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
22
41
|
const registration = await registerBrowserInCodeMode(pi, tool);
|
|
23
42
|
pi.on("session_shutdown", async () => {
|
|
24
43
|
registration?.unregister();
|
|
@@ -37,7 +56,7 @@ async function registerBrowserInCodeMode(pi, tool) {
|
|
|
37
56
|
adaptToolForCodeMode(tool, {
|
|
38
57
|
kind: "freeform",
|
|
39
58
|
prepareInput: prepareBrowserInput,
|
|
40
|
-
|
|
59
|
+
discovery: "help",
|
|
41
60
|
}),
|
|
42
61
|
]);
|
|
43
62
|
}
|
package/dist/remote-worker.js
CHANGED
|
@@ -1729,16 +1729,16 @@ async function discardCachedResult(handle) {
|
|
|
1729
1729
|
}
|
|
1730
1730
|
|
|
1731
1731
|
// src/browser/help.ts
|
|
1732
|
-
function browserHelp(hosts = []) {
|
|
1732
|
+
function browserHelp(hosts = [], gpt = false) {
|
|
1733
1733
|
const routed = hosts.length > 0;
|
|
1734
1734
|
return {
|
|
1735
|
-
input: "Request={action,...fields}; Pi: {command:JSON.stringify(request)}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
|
|
1735
|
+
input: gpt ? "Request={action,...fields}; Pi {command:JSON.stringify(request)}; Code/Notebook JSON.stringify(request), JSON.parse(result)" : "Request={action,...fields}; Pi: {command:JSON.stringify(request)}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
|
|
1736
1736
|
...routed ? {
|
|
1737
|
-
host: `${hosts.join("|")} optional; keep a user-named host on every call and its refs/handles`
|
|
1737
|
+
host: `${hosts.join("|")}${gpt ? " optional; retain user-named host on every call + refs/handles" : " optional; keep a user-named host on every call and its refs/handles"}`
|
|
1738
1738
|
} : {},
|
|
1739
1739
|
refs: "tabs -> open; keep ref_id/id/cursors with their result",
|
|
1740
|
-
safety: "Ask before unfamiliar low-trust navigation or consequential action unless authorized; never close shared browser",
|
|
1741
|
-
batch: "{action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
|
|
1740
|
+
safety: gpt ? "Unless authorized, ask before unfamiliar low-trust navigation/consequential action; never close shared browser" : "Ask before unfamiliar low-trust navigation or consequential action unless authorized; never close shared browser",
|
|
1741
|
+
batch: gpt ? "{action_name:[{...fields}],...}; nonempty arrays, no item action; root host/response_length; independent only" : "{action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
|
|
1742
1742
|
actions: {
|
|
1743
1743
|
help: "",
|
|
1744
1744
|
tabs: "query? offset? owned_only? -> ref_id title url owned",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function browserHelp(hosts?: readonly string[]): Record<string, unknown>;
|
|
1
|
+
export declare function browserHelp(hosts?: readonly string[], gpt?: boolean): Record<string, unknown>;
|
package/dist/src/browser/help.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
export function browserHelp(hosts = []) {
|
|
1
|
+
export function browserHelp(hosts = [], gpt = false) {
|
|
2
2
|
const routed = hosts.length > 0;
|
|
3
3
|
return {
|
|
4
|
-
input:
|
|
4
|
+
input: gpt
|
|
5
|
+
? "Request={action,...fields}; Pi {command:JSON.stringify(request)}; Code/Notebook JSON.stringify(request), JSON.parse(result)"
|
|
6
|
+
: "Request={action,...fields}; Pi: {command:JSON.stringify(request)}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
|
|
5
7
|
...(routed
|
|
6
8
|
? {
|
|
7
|
-
host: `${hosts.join("|")} optional; keep a user-named host on every call and its refs/handles`,
|
|
9
|
+
host: `${hosts.join("|")}${gpt ? " optional; retain user-named host on every call + refs/handles" : " optional; keep a user-named host on every call and its refs/handles"}`,
|
|
8
10
|
}
|
|
9
11
|
: {}),
|
|
10
12
|
refs: "tabs -> open; keep ref_id/id/cursors with their result",
|
|
11
|
-
safety:
|
|
12
|
-
|
|
13
|
+
safety: gpt
|
|
14
|
+
? "Unless authorized, ask before unfamiliar low-trust navigation/consequential action; never close shared browser"
|
|
15
|
+
: "Ask before unfamiliar low-trust navigation or consequential action unless authorized; never close shared browser",
|
|
16
|
+
batch: gpt
|
|
17
|
+
? "{action_name:[{...fields}],...}; nonempty arrays, no item action; root host/response_length; independent only"
|
|
18
|
+
: "{action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
|
|
13
19
|
actions: {
|
|
14
20
|
help: "",
|
|
15
21
|
tabs: "query? offset? owned_only? -> ref_id title url owned",
|
|
@@ -3,6 +3,6 @@ import { BrowserRuntime } from "./browser/runtime.js";
|
|
|
3
3
|
export declare function prepareBrowserInput(input: unknown): {
|
|
4
4
|
command: string;
|
|
5
5
|
};
|
|
6
|
-
export declare function createBrowserTool(runtime: BrowserRuntime): import("@earendil-works/pi-coding-agent").ToolDefinition<Type.TObject<{
|
|
6
|
+
export declare function createBrowserTool(runtime: BrowserRuntime, isGpt?: () => boolean): import("@earendil-works/pi-coding-agent").ToolDefinition<Type.TObject<{
|
|
7
7
|
command: Type.TOptional<Type.TString>;
|
|
8
8
|
}>, unknown, any> & import("@earendil-works/pi-coding-agent").ToolDefinition<any, any, any>;
|
package/dist/src/browser-tool.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { browserHelp } from "./browser/help.js";
|
|
3
4
|
import { isRecordValue } from "./browser/parse-operation.js";
|
|
4
5
|
import { parseBrowserRequest } from "./browser/request.js";
|
|
5
6
|
import { BrowserRuntime } from "./browser/runtime.js";
|
|
@@ -21,7 +22,7 @@ export function prepareBrowserInput(input) {
|
|
|
21
22
|
parseBrowserRequest(input);
|
|
22
23
|
return { command: JSON.stringify(input) };
|
|
23
24
|
}
|
|
24
|
-
export function createBrowserTool(runtime) {
|
|
25
|
+
export function createBrowserTool(runtime, isGpt = () => false) {
|
|
25
26
|
return defineTool({
|
|
26
27
|
name: "browser",
|
|
27
28
|
label: "Browser",
|
|
@@ -31,7 +32,8 @@ export function createBrowserTool(runtime) {
|
|
|
31
32
|
}, { additionalProperties: false }),
|
|
32
33
|
prepareArguments: prepareBrowserInput,
|
|
33
34
|
async execute(_toolCallId, input, signal, onUpdate, ctx) {
|
|
34
|
-
const
|
|
35
|
+
const request = parseBrowserRequest(input.command);
|
|
36
|
+
let result = await runtime.execute(request, {
|
|
35
37
|
ownerId: ctx.sessionManager.getSessionId(),
|
|
36
38
|
signal: signal ?? new AbortController().signal,
|
|
37
39
|
onOperation(operation, index, total) {
|
|
@@ -53,6 +55,8 @@ export function createBrowserTool(runtime) {
|
|
|
53
55
|
});
|
|
54
56
|
},
|
|
55
57
|
});
|
|
58
|
+
if (isGpt() && "help" in request)
|
|
59
|
+
result = browserHelp(runtime.hosts, true);
|
|
56
60
|
return {
|
|
57
61
|
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
58
62
|
details: result,
|
package/index.ts
CHANGED
|
@@ -21,9 +21,32 @@ export default async function browserExtension(
|
|
|
21
21
|
configError = error instanceof Error ? error.message : String(error);
|
|
22
22
|
}
|
|
23
23
|
const runtime = new BrowserRuntime(routes);
|
|
24
|
-
|
|
24
|
+
let gpt = false;
|
|
25
|
+
const tool = createBrowserTool(runtime, () => gpt);
|
|
25
26
|
registerBrowserCommand(pi);
|
|
26
27
|
pi.registerTool(tool);
|
|
28
|
+
try {
|
|
29
|
+
const { registerGptPromptMode } = await import(
|
|
30
|
+
"@howaboua/pi-codex-conversion/prompt-mode"
|
|
31
|
+
);
|
|
32
|
+
registerGptPromptMode(pi, (active) => {
|
|
33
|
+
gpt = active;
|
|
34
|
+
return [tool];
|
|
35
|
+
});
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (
|
|
38
|
+
!(error instanceof Error) ||
|
|
39
|
+
!("code" in error) ||
|
|
40
|
+
![
|
|
41
|
+
"ERR_MODULE_NOT_FOUND",
|
|
42
|
+
"MODULE_NOT_FOUND",
|
|
43
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
44
|
+
].includes(String(error.code)) ||
|
|
45
|
+
!error.message.includes(CODE_MODE_PACKAGE)
|
|
46
|
+
)
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
|
|
27
50
|
const registration = await registerBrowserInCodeMode(pi, tool);
|
|
28
51
|
pi.on("session_shutdown", async () => {
|
|
29
52
|
registration?.unregister();
|
|
@@ -47,7 +70,7 @@ async function registerBrowserInCodeMode(
|
|
|
47
70
|
adaptToolForCodeMode(tool, {
|
|
48
71
|
kind: "freeform",
|
|
49
72
|
prepareInput: prepareBrowserInput,
|
|
50
|
-
|
|
73
|
+
discovery: "help",
|
|
51
74
|
}),
|
|
52
75
|
]);
|
|
53
76
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-browser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Logged-in browser inspection and control for Pi, Code Mode and Notebook Mode.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"pack:dry": "npm pack --dry-run"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@howaboua/pi-codex-conversion": ">=
|
|
48
|
+
"@howaboua/pi-codex-conversion": ">=4.0.2",
|
|
49
49
|
"@earendil-works/pi-ai": ">=1.0.0",
|
|
50
50
|
"@earendil-works/pi-coding-agent": ">=1.0.0",
|
|
51
51
|
"typebox": "*",
|
|
@@ -57,12 +57,12 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@howaboua/pi-codex-conversion": "
|
|
61
|
-
"@biomejs/biome": "^2.5.
|
|
62
|
-
"@earendil-works/pi-ai": "1.
|
|
63
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
64
|
-
"@types/node": "^26.
|
|
65
|
-
"typebox": "1.3.
|
|
60
|
+
"@howaboua/pi-codex-conversion": "4.0.2",
|
|
61
|
+
"@biomejs/biome": "^2.5.15",
|
|
62
|
+
"@earendil-works/pi-ai": "1.3.0",
|
|
63
|
+
"@earendil-works/pi-coding-agent": "1.3.0",
|
|
64
|
+
"@types/node": "^26.6.5",
|
|
65
|
+
"typebox": "1.3.37",
|
|
66
66
|
"typescript": "^7.0.2"
|
|
67
67
|
},
|
|
68
68
|
"pi": {
|
package/src/browser/help.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
export function browserHelp(
|
|
2
2
|
hosts: readonly string[] = [],
|
|
3
|
+
gpt = false,
|
|
3
4
|
): Record<string, unknown> {
|
|
4
5
|
const routed = hosts.length > 0;
|
|
5
6
|
return {
|
|
6
|
-
input:
|
|
7
|
-
"Request={action,...fields}; Pi
|
|
7
|
+
input: gpt
|
|
8
|
+
? "Request={action,...fields}; Pi {command:JSON.stringify(request)}; Code/Notebook JSON.stringify(request), JSON.parse(result)"
|
|
9
|
+
: "Request={action,...fields}; Pi: {command:JSON.stringify(request)}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
|
|
8
10
|
...(routed
|
|
9
11
|
? {
|
|
10
|
-
host: `${hosts.join("|")} optional; keep a user-named host on every call and its refs/handles`,
|
|
12
|
+
host: `${hosts.join("|")}${gpt ? " optional; retain user-named host on every call + refs/handles" : " optional; keep a user-named host on every call and its refs/handles"}`,
|
|
11
13
|
}
|
|
12
14
|
: {}),
|
|
13
15
|
refs: "tabs -> open; keep ref_id/id/cursors with their result",
|
|
14
|
-
safety:
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
safety: gpt
|
|
17
|
+
? "Unless authorized, ask before unfamiliar low-trust navigation/consequential action; never close shared browser"
|
|
18
|
+
: "Ask before unfamiliar low-trust navigation or consequential action unless authorized; never close shared browser",
|
|
19
|
+
batch: gpt
|
|
20
|
+
? "{action_name:[{...fields}],...}; nonempty arrays, no item action; root host/response_length; independent only"
|
|
21
|
+
: "{action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
|
|
18
22
|
actions: {
|
|
19
23
|
help: "",
|
|
20
24
|
tabs: "query? offset? owned_only? -> ref_id title url owned",
|
package/src/browser-tool.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { browserHelp } from "./browser/help.js";
|
|
3
4
|
import { isRecordValue } from "./browser/parse-operation.js";
|
|
4
5
|
import { parseBrowserRequest } from "./browser/request.js";
|
|
5
6
|
import { BrowserRuntime } from "./browser/runtime.js";
|
|
@@ -23,7 +24,10 @@ export function prepareBrowserInput(input: unknown): { command: string } {
|
|
|
23
24
|
return { command: JSON.stringify(input) };
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export function createBrowserTool(
|
|
27
|
+
export function createBrowserTool(
|
|
28
|
+
runtime: BrowserRuntime,
|
|
29
|
+
isGpt = () => false,
|
|
30
|
+
) {
|
|
27
31
|
return defineTool({
|
|
28
32
|
name: "browser",
|
|
29
33
|
label: "Browser",
|
|
@@ -38,7 +42,8 @@ export function createBrowserTool(runtime: BrowserRuntime) {
|
|
|
38
42
|
),
|
|
39
43
|
prepareArguments: prepareBrowserInput,
|
|
40
44
|
async execute(_toolCallId, input, signal, onUpdate, ctx) {
|
|
41
|
-
const
|
|
45
|
+
const request = parseBrowserRequest(input.command);
|
|
46
|
+
let result = await runtime.execute(request, {
|
|
42
47
|
ownerId: ctx.sessionManager.getSessionId(),
|
|
43
48
|
signal: signal ?? new AbortController().signal,
|
|
44
49
|
onOperation(operation, index, total) {
|
|
@@ -61,6 +66,8 @@ export function createBrowserTool(runtime: BrowserRuntime) {
|
|
|
61
66
|
});
|
|
62
67
|
},
|
|
63
68
|
});
|
|
69
|
+
if (isGpt() && "help" in request)
|
|
70
|
+
result = browserHelp(runtime.hosts, true);
|
|
64
71
|
return {
|
|
65
72
|
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
66
73
|
details: result,
|