@howaboua/pi-browser 0.0.13 → 0.0.14
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 +6 -0
- package/dist/extension.js +2 -2
- package/dist/remote-worker.js +88 -32
- package/dist/src/browser/artifacts.js +99 -39
- package/dist/src/browser/help.js +5 -5
- package/dist/src/browser-registration.d.ts +4 -2
- package/dist/src/browser-registration.js +1 -1
- package/dist/src/browser-tool-definition.d.ts +7 -5
- package/dist/src/browser-tool-definition.js +5 -4
- package/dist/src/browser-tool.d.ts +2 -3
- package/dist/src/browser-tool.js +2 -2
- package/extension.ts +4 -5
- package/package.json +93 -94
- package/src/browser/artifacts.ts +114 -48
- package/src/browser/help.ts +5 -5
- package/src/browser-registration.ts +11 -7
- package/src/browser-tool-definition.ts +29 -12
- package/src/browser-tool.ts +2 -2
- package/biome.json +0 -31
- package/changelog.ts +0 -337
package/package.json
CHANGED
|
@@ -1,96 +1,95 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
2
|
+
"name": "@howaboua/pi-browser",
|
|
3
|
+
"version": "0.0.14",
|
|
4
|
+
"description": "Logged-in browser inspection and control for Pi, Code Mode and Notebook Mode.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Igor Warzocha",
|
|
8
|
+
"homepage": "https://github.com/IgorWarzocha/howaboua-pi-stuff/tree/main/packages/pi-browser#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/IgorWarzocha/howaboua-pi-stuff.git",
|
|
12
|
+
"directory": "packages/pi-browser"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/IgorWarzocha/howaboua-pi-stuff/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"pi-package",
|
|
19
|
+
"pi-extension",
|
|
20
|
+
"pi",
|
|
21
|
+
"browser",
|
|
22
|
+
"chrome",
|
|
23
|
+
"cdp",
|
|
24
|
+
"code-mode"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/**/*.js",
|
|
28
|
+
"dist/**/*.d.ts",
|
|
29
|
+
"extension.ts",
|
|
30
|
+
"index.ts",
|
|
31
|
+
"remote-worker.ts",
|
|
32
|
+
"src",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"CHANGELOG.md",
|
|
36
|
+
"tsconfig.json"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && bun build remote-worker.ts --target=node --format=esm --outfile=dist/remote-worker.js --banner='// @howaboua/pi-browser managed worker'",
|
|
40
|
+
"check": "bun run lint && bun run typecheck",
|
|
41
|
+
"prepack": "bun run check && bun run build",
|
|
42
|
+
"typecheck": "tsrs --noEmit",
|
|
43
|
+
"lint": "bun run format:check && oxlint --type-aware",
|
|
44
|
+
"pack:dry": "npm pack --dry-run",
|
|
45
|
+
"format:check": "oxfmt --check '**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,json,jsonc,json5,css}'"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"@howaboua/pi-codex-conversion": ">=5.0.2",
|
|
49
|
+
"@earendil-works/pi-ai": ">=1.0.0",
|
|
50
|
+
"@earendil-works/pi-coding-agent": ">=1.5.0",
|
|
51
|
+
"@earendil-works/pi-tui": ">=1.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"@howaboua/pi-codex-conversion": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@howaboua/pi-codex-conversion": "5.0.2",
|
|
60
|
+
"@earendil-works/pi-ai": "1.6.0",
|
|
61
|
+
"@earendil-works/pi-coding-agent": "1.6.0",
|
|
62
|
+
"@types/node": "^26.6.6",
|
|
63
|
+
"typescript": "^7.0.2",
|
|
64
|
+
"oxfmt": "^0.78.0"
|
|
65
|
+
},
|
|
66
|
+
"pi": {
|
|
67
|
+
"extensions": [
|
|
68
|
+
"./extension.ts"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=22.19.0"
|
|
73
|
+
},
|
|
74
|
+
"bin": {
|
|
75
|
+
"pi-browser-worker": "./dist/remote-worker.js"
|
|
76
|
+
},
|
|
77
|
+
"main": "./dist/index.js",
|
|
78
|
+
"types": "./dist/index.d.ts",
|
|
79
|
+
"exports": {
|
|
80
|
+
"./voice-start": {
|
|
81
|
+
"types": "./dist/src/browser/voice-start.d.ts",
|
|
82
|
+
"import": "./dist/src/browser/voice-start.js"
|
|
83
|
+
},
|
|
84
|
+
".": {
|
|
85
|
+
"types": "./dist/index.d.ts",
|
|
86
|
+
"import": "./dist/index.js"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"publishConfig": {
|
|
90
|
+
"access": "public"
|
|
91
|
+
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"@earendil-works/pi-schema": "1.6.0"
|
|
94
|
+
}
|
|
96
95
|
}
|
package/src/browser/artifacts.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mkdir,
|
|
3
|
+
open,
|
|
3
4
|
readdir,
|
|
4
5
|
readFile,
|
|
5
6
|
rm,
|
|
@@ -12,6 +13,8 @@ import { join } from "node:path";
|
|
|
12
13
|
const RESULT_TTL_MS = 60 * 60 * 1_000;
|
|
13
14
|
const SCREENSHOT_TTL_MS = 24 * 60 * 60 * 1_000;
|
|
14
15
|
const TEXT_BUDGET_BYTES = 32_000;
|
|
16
|
+
// At least one byte per UTF-16 unit, plus one unit of surrogate lookahead.
|
|
17
|
+
const RESULT_READ_BYTES = 2 * (TEXT_BUDGET_BYTES - 2 + 1);
|
|
15
18
|
|
|
16
19
|
export function artifactDirectory(): string {
|
|
17
20
|
return process.env["XDG_RUNTIME_DIR"]
|
|
@@ -19,8 +22,11 @@ export function artifactDirectory(): string {
|
|
|
19
22
|
: join(tmpdir(), `browser-tool-${process.getuid?.() ?? "user"}`);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
function resultPath(handle: string): string {
|
|
23
|
-
return join(
|
|
25
|
+
function resultPath(handle: string, legacy = false): string {
|
|
26
|
+
return join(
|
|
27
|
+
artifactDirectory(),
|
|
28
|
+
`result-${handle}.${legacy ? "txt" : "utf16le"}`,
|
|
29
|
+
);
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
export async function screenshotPath(request: {
|
|
@@ -50,19 +56,14 @@ export async function pruneArtifacts(now = Date.now()): Promise<number> {
|
|
|
50
56
|
try {
|
|
51
57
|
names = await readdir(artifactDirectory());
|
|
52
58
|
} catch (error) {
|
|
53
|
-
if (
|
|
54
|
-
error &&
|
|
55
|
-
typeof error === "object" &&
|
|
56
|
-
"code" in error &&
|
|
57
|
-
error.code === "ENOENT"
|
|
58
|
-
) {
|
|
59
|
-
return 0;
|
|
60
|
-
}
|
|
59
|
+
if (isMissing(error)) return 0;
|
|
61
60
|
throw error;
|
|
62
61
|
}
|
|
63
62
|
let removed = 0;
|
|
64
63
|
for (const name of names.filter((candidate) =>
|
|
65
|
-
/^(?:result-[a-f0-9-]{36}\.txt|browser-.*\.png)$/.test(
|
|
64
|
+
/^(?:result-[a-f0-9-]{36}\.(?:txt|utf16le)|browser-.*\.png)$/.test(
|
|
65
|
+
candidate,
|
|
66
|
+
),
|
|
66
67
|
)) {
|
|
67
68
|
const path = join(artifactDirectory(), name);
|
|
68
69
|
try {
|
|
@@ -74,14 +75,7 @@ export async function pruneArtifacts(now = Date.now()): Promise<number> {
|
|
|
74
75
|
removed++;
|
|
75
76
|
}
|
|
76
77
|
} catch (error) {
|
|
77
|
-
if (
|
|
78
|
-
!error ||
|
|
79
|
-
typeof error !== "object" ||
|
|
80
|
-
!("code" in error) ||
|
|
81
|
-
error.code !== "ENOENT"
|
|
82
|
-
) {
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
78
|
+
if (!isMissing(error)) throw error;
|
|
85
79
|
}
|
|
86
80
|
}
|
|
87
81
|
return removed;
|
|
@@ -90,26 +84,47 @@ export async function pruneArtifacts(now = Date.now()): Promise<number> {
|
|
|
90
84
|
function chunkForJson(
|
|
91
85
|
value: string,
|
|
92
86
|
offset = 0,
|
|
93
|
-
budget = TEXT_BUDGET_BYTES,
|
|
94
87
|
): { text: string; end: number } {
|
|
95
88
|
let bytes = 2;
|
|
96
89
|
let end = offset;
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
90
|
+
while (end < value.length) {
|
|
91
|
+
const point = value.codePointAt(end)!;
|
|
92
|
+
const next = jsonCharacterBytes(point);
|
|
93
|
+
if (bytes + next > TEXT_BUDGET_BYTES) break;
|
|
100
94
|
bytes += next;
|
|
101
|
-
end +=
|
|
95
|
+
end += point > 0xffff ? 2 : 1;
|
|
102
96
|
}
|
|
103
97
|
return { text: value.slice(offset, end), end };
|
|
104
98
|
}
|
|
105
99
|
|
|
100
|
+
function jsonCharacterBytes(point: number): number {
|
|
101
|
+
if (point < 0x20) {
|
|
102
|
+
return point === 8 ||
|
|
103
|
+
point === 9 ||
|
|
104
|
+
point === 10 ||
|
|
105
|
+
point === 12 ||
|
|
106
|
+
point === 13
|
|
107
|
+
? 2
|
|
108
|
+
: 6;
|
|
109
|
+
}
|
|
110
|
+
if (point === 0x22 || point === 0x5c) return 2;
|
|
111
|
+
if (point < 0x80) return 1;
|
|
112
|
+
if (point < 0x800) return 2;
|
|
113
|
+
if (point >= 0xd800 && point <= 0xdfff) return 6;
|
|
114
|
+
return point <= 0xffff ? 3 : 4;
|
|
115
|
+
}
|
|
116
|
+
|
|
106
117
|
async function cacheResult(value: string): Promise<string> {
|
|
107
118
|
const handle = crypto.randomUUID();
|
|
108
119
|
await mkdir(artifactDirectory(), {
|
|
109
120
|
recursive: true,
|
|
110
121
|
mode: 0o700,
|
|
111
122
|
});
|
|
112
|
-
|
|
123
|
+
// Fixed-width code units allow seeks at every accepted JS string offset.
|
|
124
|
+
await writeFile(resultPath(handle), value, {
|
|
125
|
+
encoding: "utf16le",
|
|
126
|
+
mode: 0o600,
|
|
127
|
+
});
|
|
113
128
|
return handle;
|
|
114
129
|
}
|
|
115
130
|
|
|
@@ -131,48 +146,99 @@ export async function limitedText(
|
|
|
131
146
|
};
|
|
132
147
|
}
|
|
133
148
|
|
|
149
|
+
function checkOffset(offset: number, length: number): void {
|
|
150
|
+
if (offset > length) {
|
|
151
|
+
throw new Error(`offset ${offset} exceeds result length ${length}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function readResultPage(path: string, offset: number) {
|
|
156
|
+
const file = await open(path, "r");
|
|
157
|
+
try {
|
|
158
|
+
const { size } = await file.stat();
|
|
159
|
+
if (size % 2)
|
|
160
|
+
throw new Error("Cached result is incomplete; rerun the original action");
|
|
161
|
+
const length = size / 2;
|
|
162
|
+
checkOffset(offset, length);
|
|
163
|
+
const position = offset * 2;
|
|
164
|
+
const bytes = Buffer.allocUnsafe(
|
|
165
|
+
Math.min(size - position, RESULT_READ_BYTES),
|
|
166
|
+
);
|
|
167
|
+
let used = 0;
|
|
168
|
+
while (used < bytes.length) {
|
|
169
|
+
const { bytesRead } = await file.read(
|
|
170
|
+
bytes,
|
|
171
|
+
used,
|
|
172
|
+
bytes.length - used,
|
|
173
|
+
position + used,
|
|
174
|
+
);
|
|
175
|
+
if (!bytesRead)
|
|
176
|
+
throw new Error(
|
|
177
|
+
"Cached result is incomplete; rerun the original action",
|
|
178
|
+
);
|
|
179
|
+
used += bytesRead;
|
|
180
|
+
}
|
|
181
|
+
const chunk = chunkForJson(bytes.toString("utf16le"));
|
|
182
|
+
return { text: chunk.text, end: offset + chunk.end, length };
|
|
183
|
+
} finally {
|
|
184
|
+
await file.close();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function isMissing(error: unknown): boolean {
|
|
189
|
+
return (
|
|
190
|
+
!!error &&
|
|
191
|
+
typeof error === "object" &&
|
|
192
|
+
"code" in error &&
|
|
193
|
+
error.code === "ENOENT"
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
134
197
|
export async function readCachedResult(request: {
|
|
135
198
|
handle: string;
|
|
136
199
|
offset: number;
|
|
137
200
|
}): Promise<Record<string, unknown>> {
|
|
138
|
-
|
|
201
|
+
const { handle, offset } = request;
|
|
202
|
+
let path = resultPath(handle);
|
|
203
|
+
let page;
|
|
139
204
|
try {
|
|
140
|
-
|
|
205
|
+
page = await readResultPage(path, offset);
|
|
141
206
|
} catch (error) {
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
207
|
+
if (!isMissing(error)) throw error;
|
|
208
|
+
// Let handles issued by the previous worker finish during their short TTL.
|
|
209
|
+
path = resultPath(handle, true);
|
|
210
|
+
let value: string;
|
|
211
|
+
try {
|
|
212
|
+
value = await readFile(path, "utf8");
|
|
213
|
+
} catch (legacyError) {
|
|
214
|
+
if (!isMissing(legacyError)) throw legacyError;
|
|
148
215
|
throw new Error(
|
|
149
|
-
`result handle not found: ${
|
|
216
|
+
`result handle not found: ${handle}; check the host or rerun the original action`,
|
|
150
217
|
);
|
|
151
218
|
}
|
|
152
|
-
|
|
219
|
+
checkOffset(offset, value.length);
|
|
220
|
+
page = { ...chunkForJson(value, offset), length: value.length };
|
|
153
221
|
}
|
|
154
|
-
|
|
155
|
-
throw new Error(
|
|
156
|
-
`offset ${request.offset} exceeds result length ${value.length}`,
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
const chunk = chunkForJson(value, request.offset);
|
|
160
|
-
const complete = chunk.end >= value.length;
|
|
222
|
+
const complete = page.end >= page.length;
|
|
161
223
|
if (complete) {
|
|
162
|
-
await rm(
|
|
224
|
+
await rm(path, { force: true });
|
|
163
225
|
}
|
|
164
226
|
return {
|
|
165
|
-
handle
|
|
166
|
-
offset
|
|
167
|
-
text:
|
|
227
|
+
handle,
|
|
228
|
+
offset,
|
|
229
|
+
text: page.text,
|
|
168
230
|
complete,
|
|
169
|
-
...(complete ? {} : { next_offset:
|
|
231
|
+
...(complete ? {} : { next_offset: page.end }),
|
|
170
232
|
};
|
|
171
233
|
}
|
|
172
234
|
|
|
173
235
|
export async function discardCachedResult(
|
|
174
236
|
handle: string,
|
|
175
237
|
): Promise<Record<string, unknown>> {
|
|
176
|
-
await
|
|
238
|
+
await Promise.all(
|
|
239
|
+
[resultPath(handle), resultPath(handle, true)].map((path) =>
|
|
240
|
+
rm(path, { force: true }),
|
|
241
|
+
),
|
|
242
|
+
);
|
|
177
243
|
return { discarded: handle };
|
|
178
244
|
}
|
package/src/browser/help.ts
CHANGED
|
@@ -7,18 +7,18 @@ export function browserHelp(
|
|
|
7
7
|
input: "{action,...fields}",
|
|
8
8
|
...(routed
|
|
9
9
|
? {
|
|
10
|
-
host: `${hosts.join("|")}${gpt ? " optional; user-named host→
|
|
10
|
+
host: `${hosts.join("|")}${gpt ? " optional; user-named host→all calls; refs/handles stay with host" : " optional; keep the user-named host on every call and reuse refs or handles only on their host"}`,
|
|
11
11
|
}
|
|
12
12
|
: {}),
|
|
13
13
|
refs: gpt
|
|
14
14
|
? "tabs→open; ref_id/id/cursors stay with result"
|
|
15
15
|
: "tabs -> open; keep ref_id/id/cursors with their result",
|
|
16
16
|
safety: gpt
|
|
17
|
-
? "
|
|
18
|
-
: "
|
|
17
|
+
? "MUST ask before unfamiliar low-trust navigation or consequential action unless authorised. MUST NOT close shared browser"
|
|
18
|
+
: "Unless authorised, MUST ask before unfamiliar low-trust navigation or consequential action. MUST NOT close a shared browser",
|
|
19
19
|
batch: gpt
|
|
20
|
-
? "{action_name:[{...fields}],...}; nonempty arrays;
|
|
21
|
-
: "{action_name:[{...fields}],...}
|
|
20
|
+
? "Independent only: {action_name:[{...fields}],...}; nonempty arrays; root host/response_length; omit item action"
|
|
21
|
+
: "Batch independent actions only: {action_name:[{...fields}],...}. Nonempty arrays; host and response_length at root; omit item action",
|
|
22
22
|
actions: {
|
|
23
23
|
help: "",
|
|
24
24
|
tabs: "query? offset? owned_only? -> ref_id title url owned",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { defineTool, ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type {
|
|
2
|
+
import type { obj, opt, str } from "@earendil-works/pi-schema";
|
|
3
3
|
import { BrowserRoutes, loadBrowserRoutes } from "./browser/routes.js";
|
|
4
4
|
import { BrowserRuntime } from "./browser/runtime.js";
|
|
5
5
|
import { registerBrowserCommand } from "./browser/settings.js";
|
|
@@ -13,7 +13,12 @@ const CODE_MODE_MODULE = `${CODE_MODE_PACKAGE}/code-mode`;
|
|
|
13
13
|
|
|
14
14
|
export default async function browserExtension(
|
|
15
15
|
pi: ExtensionAPI,
|
|
16
|
-
sdk: {
|
|
16
|
+
sdk: {
|
|
17
|
+
defineTool: typeof defineTool;
|
|
18
|
+
obj: typeof obj;
|
|
19
|
+
opt: typeof opt;
|
|
20
|
+
str: typeof str;
|
|
21
|
+
},
|
|
17
22
|
): Promise<void> {
|
|
18
23
|
let configError: string | undefined;
|
|
19
24
|
let routes: BrowserRoutes;
|
|
@@ -29,9 +34,8 @@ export default async function browserExtension(
|
|
|
29
34
|
registerBrowserCommand(pi);
|
|
30
35
|
pi.registerTool(tool);
|
|
31
36
|
try {
|
|
32
|
-
const { registerGptPromptMode } =
|
|
33
|
-
"@howaboua/pi-codex-conversion/prompt-mode"
|
|
34
|
-
);
|
|
37
|
+
const { registerGptPromptMode } =
|
|
38
|
+
await import("@howaboua/pi-codex-conversion/prompt-mode");
|
|
35
39
|
registerGptPromptMode(pi, (active) => {
|
|
36
40
|
gpt = active;
|
|
37
41
|
return [tool];
|
|
@@ -65,7 +69,7 @@ export default async function browserExtension(
|
|
|
65
69
|
async function registerBrowserInCodeMode(
|
|
66
70
|
pi: ExtensionAPI,
|
|
67
71
|
tool: ReturnType<typeof createBrowserTool>,
|
|
68
|
-
sdk: {
|
|
72
|
+
sdk: { obj: typeof obj },
|
|
69
73
|
) {
|
|
70
74
|
try {
|
|
71
75
|
const { adaptToolForCodeMode, registerCodeModeExtensionTools } =
|
|
@@ -74,7 +78,7 @@ async function registerBrowserInCodeMode(
|
|
|
74
78
|
adaptToolForCodeMode(
|
|
75
79
|
{
|
|
76
80
|
...tool,
|
|
77
|
-
parameters: sdk.
|
|
81
|
+
parameters: sdk.obj({}, { open: true }),
|
|
78
82
|
},
|
|
79
83
|
{
|
|
80
84
|
prepareInput: prepareBrowserInput,
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { defineTool as definePiTool } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Static,
|
|
4
|
+
obj as schemaObj,
|
|
5
|
+
opt as schemaOpt,
|
|
6
|
+
str as schemaStr,
|
|
7
|
+
} from "@earendil-works/pi-schema";
|
|
3
8
|
import { browserHelp } from "./browser/help.js";
|
|
4
9
|
import { isRecordValue } from "./browser/parse-operation.js";
|
|
5
10
|
import { parseBrowserRequest } from "./browser/request.js";
|
|
@@ -27,25 +32,37 @@ export function prepareBrowserInput(input: unknown): { command: string } {
|
|
|
27
32
|
export function createBrowserTool(
|
|
28
33
|
{
|
|
29
34
|
defineTool,
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
obj,
|
|
36
|
+
opt,
|
|
37
|
+
str,
|
|
38
|
+
}: {
|
|
39
|
+
defineTool: typeof definePiTool;
|
|
40
|
+
obj: typeof schemaObj;
|
|
41
|
+
opt: typeof schemaOpt;
|
|
42
|
+
str: typeof schemaStr;
|
|
43
|
+
},
|
|
32
44
|
runtime: BrowserRuntime,
|
|
33
45
|
isGpt = () => false,
|
|
34
46
|
) {
|
|
47
|
+
const parameters = obj(
|
|
48
|
+
{
|
|
49
|
+
command: opt(str({ description: "help or JSON request" })),
|
|
50
|
+
},
|
|
51
|
+
{ open: false },
|
|
52
|
+
);
|
|
35
53
|
return defineTool({
|
|
36
54
|
name: "browser",
|
|
37
55
|
label: "Browser",
|
|
38
56
|
description: "Control logged-in browser",
|
|
39
|
-
parameters
|
|
40
|
-
{
|
|
41
|
-
command: Type.Optional(
|
|
42
|
-
Type.String({ description: "help or JSON request" }),
|
|
43
|
-
),
|
|
44
|
-
},
|
|
45
|
-
{ additionalProperties: false },
|
|
46
|
-
),
|
|
57
|
+
parameters,
|
|
47
58
|
prepareArguments: prepareBrowserInput,
|
|
48
|
-
async execute(
|
|
59
|
+
async execute(
|
|
60
|
+
_toolCallId,
|
|
61
|
+
input: Static<typeof parameters>,
|
|
62
|
+
signal,
|
|
63
|
+
onUpdate,
|
|
64
|
+
ctx,
|
|
65
|
+
) {
|
|
49
66
|
const request = parseBrowserRequest(input.command);
|
|
50
67
|
let result = await runtime.execute(request, {
|
|
51
68
|
ownerId: ctx.sessionManager.getSessionId(),
|
package/src/browser-tool.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { obj, opt, str } from "@earendil-works/pi-schema";
|
|
3
3
|
import type { BrowserRuntime } from "./browser/runtime.js";
|
|
4
4
|
import { createBrowserTool as createTool } from "./browser-tool-definition.js";
|
|
5
5
|
|
|
@@ -7,5 +7,5 @@ export function createBrowserTool(
|
|
|
7
7
|
runtime: BrowserRuntime,
|
|
8
8
|
isGpt = () => false,
|
|
9
9
|
) {
|
|
10
|
-
return createTool({ defineTool,
|
|
10
|
+
return createTool({ defineTool, obj, opt, str }, runtime, isGpt);
|
|
11
11
|
}
|
package/biome.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/2.6.3/schema.json",
|
|
3
|
-
"vcs": {
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"clientKind": "git",
|
|
6
|
-
"useIgnoreFile": false
|
|
7
|
-
},
|
|
8
|
-
"files": {
|
|
9
|
-
"includes": [
|
|
10
|
-
"**",
|
|
11
|
-
"!node_modules",
|
|
12
|
-
"!dist",
|
|
13
|
-
"!coverage",
|
|
14
|
-
"!package-lock.json"
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
"formatter": {
|
|
18
|
-
"enabled": true,
|
|
19
|
-
"indentStyle": "tab"
|
|
20
|
-
},
|
|
21
|
-
"linter": {
|
|
22
|
-
"enabled": false
|
|
23
|
-
},
|
|
24
|
-
"javascript": {
|
|
25
|
-
"formatter": {
|
|
26
|
-
"quoteStyle": "double",
|
|
27
|
-
"semicolons": "always",
|
|
28
|
-
"trailingCommas": "all"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|