@howaboua/pi-browser 0.0.13 → 0.0.15

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/package.json CHANGED
@@ -1,96 +1,95 @@
1
1
  {
2
- "name": "@howaboua/pi-browser",
3
- "version": "0.0.13",
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
- "biome.json",
38
- "changelog.ts"
39
- ],
40
- "scripts": {
41
- "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'",
42
- "check": "bun run lint && bun run typecheck",
43
- "prepack": "bun run check && bun run build",
44
- "typecheck": "tsgo --noEmit",
45
- "lint": "biome check .",
46
- "pack:dry": "npm pack --dry-run"
47
- },
48
- "peerDependencies": {
49
- "@howaboua/pi-codex-conversion": ">=4.0.7",
50
- "@earendil-works/pi-ai": ">=1.0.0",
51
- "@earendil-works/pi-coding-agent": ">=1.0.0",
52
- "typebox": "*",
53
- "@earendil-works/pi-tui": ">=1.0.0"
54
- },
55
- "peerDependenciesMeta": {
56
- "@howaboua/pi-codex-conversion": {
57
- "optional": true
58
- }
59
- },
60
- "devDependencies": {
61
- "@howaboua/pi-codex-conversion": "4.0.7",
62
- "@biomejs/biome": "^2.6.3",
63
- "@earendil-works/pi-ai": "1.4.0",
64
- "@earendil-works/pi-coding-agent": "1.4.0",
65
- "@types/node": "^26.6.5",
66
- "typebox": "1.4.3",
67
- "typescript": "^7.0.2"
68
- },
69
- "pi": {
70
- "extensions": [
71
- "./changelog.ts",
72
- "./extension.ts"
73
- ]
74
- },
75
- "engines": {
76
- "node": ">=22.19.0"
77
- },
78
- "bin": {
79
- "pi-browser-worker": "./dist/remote-worker.js"
80
- },
81
- "main": "./dist/index.js",
82
- "types": "./dist/index.d.ts",
83
- "exports": {
84
- "./voice-start": {
85
- "types": "./dist/src/browser/voice-start.d.ts",
86
- "import": "./dist/src/browser/voice-start.js"
87
- },
88
- ".": {
89
- "types": "./dist/index.d.ts",
90
- "import": "./dist/index.js"
91
- }
92
- },
93
- "publishConfig": {
94
- "access": "public"
95
- }
2
+ "name": "@howaboua/pi-browser",
3
+ "version": "0.0.15",
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.1.0",
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.1.0",
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.79.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
  }
@@ -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(artifactDirectory(), `result-${handle}.txt`);
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(candidate),
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
- for (const character of value.slice(offset)) {
98
- const next = Buffer.byteLength(JSON.stringify(character)) - 2;
99
- if (bytes + next > budget) break;
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 += character.length;
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
- await writeFile(resultPath(handle), value, { mode: 0o600 });
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
- let value: string;
201
+ const { handle, offset } = request;
202
+ let path = resultPath(handle);
203
+ let page;
139
204
  try {
140
- value = await readFile(resultPath(request.handle), "utf8");
205
+ page = await readResultPage(path, offset);
141
206
  } catch (error) {
142
- if (
143
- error &&
144
- typeof error === "object" &&
145
- "code" in error &&
146
- error.code === "ENOENT"
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: ${request.handle}; check the host or rerun the original action`,
216
+ `result handle not found: ${handle}; check the host or rerun the original action`,
150
217
  );
151
218
  }
152
- throw error;
219
+ checkOffset(offset, value.length);
220
+ page = { ...chunkForJson(value, offset), length: value.length };
153
221
  }
154
- if (request.offset > value.length) {
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(resultPath(request.handle), { force: true });
224
+ await rm(path, { force: true });
163
225
  }
164
226
  return {
165
- handle: request.handle,
166
- offset: request.offset,
167
- text: chunk.text,
227
+ handle,
228
+ offset,
229
+ text: page.text,
168
230
  complete,
169
- ...(complete ? {} : { next_offset: chunk.end }),
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 rm(resultPath(handle), { force: true });
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
  }
@@ -1,24 +1,19 @@
1
1
  export function browserHelp(
2
2
  hosts: readonly string[] = [],
3
- gpt = false,
4
3
  ): Record<string, unknown> {
5
4
  const routed = hosts.length > 0;
6
5
  return {
7
6
  input: "{action,...fields}",
8
7
  ...(routed
9
8
  ? {
10
- host: `${hosts.join("|")}${gpt ? " optional; user-named host→retain EVERY call+refs/handles" : " optional; keep a user-named host on every call and its refs/handles"}`,
9
+ host: `${hosts.join("|")} optional; user-named host→all calls; refs/handles stay with host`,
11
10
  }
12
11
  : {}),
13
- refs: gpt
14
- ? "tabs→open; ref_id/id/cursors stay with result"
15
- : "tabs -> open; keep ref_id/id/cursors with their result",
16
- safety: gpt
17
- ? "Unfamiliar low-trust navigation/consequential action→ask UNLESS authorised; 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; omit 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",
12
+ refs: "tabs→open; ref_id/id/cursors stay with result",
13
+ safety:
14
+ "MUST ask before unfamiliar low-trust navigation or consequential action unless authorised. MUST NOT close shared browser",
15
+ batch:
16
+ "Independent only: {action_name:[{...fields}],...}; nonempty arrays; root host/response_length; omit item action",
22
17
  actions: {
23
18
  help: "",
24
19
  tabs: "query? offset? owned_only? -> ref_id title url owned",
@@ -111,7 +111,10 @@ async function manageAdvanced(
111
111
  ]);
112
112
  if (!selected || selected === BACK) return config;
113
113
  const value = (
114
- await ctx.ui.input("Remote Node path", config.remoteNodePath)
114
+ await ctx.ui.input(
115
+ "Node.js executable on SSH hosts",
116
+ config.remoteNodePath,
117
+ )
115
118
  )?.trim();
116
119
  if (!value) continue;
117
120
  try {
@@ -150,7 +153,7 @@ async function openBrowserSettings(
150
153
  if (!config) return;
151
154
  while (true) {
152
155
  const hosts = `Hosts · ${config.hosts.length ? config.hosts.join(", ") : "local only"}`;
153
- const machine = `This machine · ${currentMachineRoute(config) ?? "unnamed local"}`;
156
+ const machine = `Local host name for routing · ${currentMachineRoute(config) ?? "unnamed local"}`;
154
157
  const selected = await ctx.ui.select("Browser settings", [
155
158
  hosts,
156
159
  machine,
@@ -164,10 +167,10 @@ async function openBrowserSettings(
164
167
  continue;
165
168
  }
166
169
  if (selected === machine) {
167
- const route = await ctx.ui.select("This machine", [
168
- "Unnamed local browser",
169
- ...config.hosts,
170
- ]);
170
+ const route = await ctx.ui.select(
171
+ "Which listed host should open locally instead of over SSH?",
172
+ ["Unnamed local browser", ...config.hosts],
173
+ );
171
174
  if (route) {
172
175
  config = setCurrentMachineRoute(
173
176
  config,
@@ -1,5 +1,5 @@
1
1
  import type { defineTool, ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import type { Type } from "typebox";
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: { defineTool: typeof defineTool; Type: typeof Type },
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;
@@ -24,31 +29,9 @@ export default async function browserExtension(
24
29
  configError = error instanceof Error ? error.message : String(error);
25
30
  }
26
31
  const runtime = new BrowserRuntime(routes);
27
- let gpt = false;
28
- const tool = createBrowserTool(sdk, runtime, () => gpt);
32
+ const tool = createBrowserTool(sdk, runtime);
29
33
  registerBrowserCommand(pi);
30
34
  pi.registerTool(tool);
31
- try {
32
- const { registerGptPromptMode } = await import(
33
- "@howaboua/pi-codex-conversion/prompt-mode"
34
- );
35
- registerGptPromptMode(pi, (active) => {
36
- gpt = active;
37
- return [tool];
38
- });
39
- } catch (error) {
40
- if (
41
- !(error instanceof Error) ||
42
- !("code" in error) ||
43
- ![
44
- "ERR_MODULE_NOT_FOUND",
45
- "MODULE_NOT_FOUND",
46
- "ERR_PACKAGE_PATH_NOT_EXPORTED",
47
- ].includes(String(error.code)) ||
48
- !error.message.includes(CODE_MODE_PACKAGE)
49
- )
50
- throw error;
51
- }
52
35
 
53
36
  const registration = await registerBrowserInCodeMode(pi, tool, sdk);
54
37
  pi.on("session_shutdown", async () => {
@@ -65,7 +48,7 @@ export default async function browserExtension(
65
48
  async function registerBrowserInCodeMode(
66
49
  pi: ExtensionAPI,
67
50
  tool: ReturnType<typeof createBrowserTool>,
68
- sdk: { Type: typeof Type },
51
+ sdk: { obj: typeof obj },
69
52
  ) {
70
53
  try {
71
54
  const { adaptToolForCodeMode, registerCodeModeExtensionTools } =
@@ -74,7 +57,7 @@ async function registerBrowserInCodeMode(
74
57
  adaptToolForCodeMode(
75
58
  {
76
59
  ...tool,
77
- parameters: sdk.Type.Object({}, { additionalProperties: true }),
60
+ parameters: sdk.obj({}, { open: true }),
78
61
  },
79
62
  {
80
63
  prepareInput: prepareBrowserInput,
@@ -1,6 +1,10 @@
1
1
  import type { defineTool as definePiTool } from "@earendil-works/pi-coding-agent";
2
- import type { Type as SchemaType } from "typebox";
3
- import { browserHelp } from "./browser/help.js";
2
+ import type {
3
+ Static,
4
+ obj as schemaObj,
5
+ opt as schemaOpt,
6
+ str as schemaStr,
7
+ } from "@earendil-works/pi-schema";
4
8
  import { isRecordValue } from "./browser/parse-operation.js";
5
9
  import { parseBrowserRequest } from "./browser/request.js";
6
10
  import type { BrowserRuntime } from "./browser/runtime.js";
@@ -27,27 +31,38 @@ export function prepareBrowserInput(input: unknown): { command: string } {
27
31
  export function createBrowserTool(
28
32
  {
29
33
  defineTool,
30
- Type,
31
- }: { defineTool: typeof definePiTool; Type: typeof SchemaType },
34
+ obj,
35
+ opt,
36
+ str,
37
+ }: {
38
+ defineTool: typeof definePiTool;
39
+ obj: typeof schemaObj;
40
+ opt: typeof schemaOpt;
41
+ str: typeof schemaStr;
42
+ },
32
43
  runtime: BrowserRuntime,
33
- isGpt = () => false,
34
44
  ) {
45
+ const parameters = obj(
46
+ {
47
+ command: opt(str({ description: "help or JSON request" })),
48
+ },
49
+ { open: false },
50
+ );
35
51
  return defineTool({
36
52
  name: "browser",
37
53
  label: "Browser",
38
54
  description: "Control logged-in browser",
39
- parameters: Type.Object(
40
- {
41
- command: Type.Optional(
42
- Type.String({ description: "help or JSON request" }),
43
- ),
44
- },
45
- { additionalProperties: false },
46
- ),
55
+ parameters,
47
56
  prepareArguments: prepareBrowserInput,
48
- async execute(_toolCallId, input, signal, onUpdate, ctx) {
57
+ async execute(
58
+ _toolCallId,
59
+ input: Static<typeof parameters>,
60
+ signal,
61
+ onUpdate,
62
+ ctx,
63
+ ) {
49
64
  const request = parseBrowserRequest(input.command);
50
- let result = await runtime.execute(request, {
65
+ const result = await runtime.execute(request, {
51
66
  ownerId: ctx.sessionManager.getSessionId(),
52
67
  signal: signal ?? new AbortController().signal,
53
68
  onOperation(operation, index, total) {
@@ -70,8 +85,6 @@ export function createBrowserTool(
70
85
  });
71
86
  },
72
87
  });
73
- if (isGpt() && "help" in request)
74
- result = browserHelp(runtime.hosts, true);
75
88
  return {
76
89
  content: [{ type: "text", text: JSON.stringify(result) }],
77
90
  details: result,
@@ -1,11 +1,8 @@
1
1
  import { defineTool } from "@earendil-works/pi-coding-agent";
2
- import { Type } from "typebox";
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
 
6
- export function createBrowserTool(
7
- runtime: BrowserRuntime,
8
- isGpt = () => false,
9
- ) {
10
- return createTool({ defineTool, Type }, runtime, isGpt);
6
+ export function createBrowserTool(runtime: BrowserRuntime) {
7
+ return createTool({ defineTool, obj, opt, str }, runtime);
11
8
  }