@howaboua/pi-browser 0.0.5 → 0.0.6

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @howaboua/pi-browser
2
2
 
3
+ ## 0.0.6
4
+
5
+ - Requires Pi 1.0.0 or later.
6
+
7
+ Browser now uses help-first discovery in ordinary Pi and Structured mode. Native calls accept help and single or batched JSON requests through `command`, matching Code and Notebook. Existing object calls remain supported.
8
+
3
9
  ## 0.0.5
4
10
 
5
11
  - Browser snapshots now include link destinations.
package/README.md CHANGED
@@ -10,19 +10,19 @@ The extension is the TypeScript counterpart of Pi Codex's browser custom tool. I
10
10
  pi install npm:@howaboua/pi-browser
11
11
  ```
12
12
 
13
- Requires Pi 0.84.3 or newer, Node.js 22.19 or newer, and a Chrome-family browser with remote debugging enabled at `chrome://inspect/#remote-debugging`.
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
15
  Pi Codex 3.0.25 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
 
19
- In normal Pi, call `browser` with `action: "help"` before first use. In Code or Notebook Mode, start with:
19
+ In normal Pi, call `browser` with `command: "help"` before first use, then send JSON request strings in `command`. Existing object requests remain accepted. In Code or Notebook Mode, start with:
20
20
 
21
21
  ```js
22
22
  await tools.browser("help")
23
23
  ```
24
24
 
25
- Normal Pi exposes the single-action contract. Code and Notebook Mode also accept batched freeform requests. A common route is `tabs`, then `open`, then `click` or `type` with the returned `ref_id` and element ID.
25
+ All modes accept single-action and batched requests described by help. A common route is `tabs`, then `open`, then `click` or `type` with the returned `ref_id` and element ID.
26
26
 
27
27
  Long Code and Notebook calls use the normal `exec` and `wait` lifecycle. Cancellation stops pending CDP work, though an already dispatched browser mutation may still take effect.
28
28
 
@@ -32,7 +32,7 @@ Ownership survives extension reloads and managed-worker restarts while the brows
32
32
 
33
33
  ## Host routing
34
34
 
35
- In Pi's interactive TUI, run `/browser`, add the SSH host names, identify the current machine, then save. Pi reloads the extension with the corresponding `host` choices. Advanced settings expose the remote Node command, which defaults to `node`.
35
+ In Pi's interactive TUI, run `/browser`, add the SSH host names, identify the current machine, then save. Browser help lists the configured `host` choices. Advanced settings expose the remote Node command, which defaults to `node`.
36
36
 
37
37
  Each name must be an existing SSH alias. On first use, the extension atomically installs or updates its managed worker at `~/.pi/agent/pi-browser-worker.mjs` on that host, then invokes it against the host's local CDP browser. No package installation is required on routed machines. Screenshots return through SCP and the remote artifact is removed. Keep `host` on follow-up calls that use a returned ref, screenshot, or continuation handle. Settings are stored in `pi-browser.json` under Pi's agent directory; `PI_BROWSER_CONFIG` overrides that storage path.
38
38
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BrowserRoutes, loadBrowserRoutes } from "./src/browser/routes.js";
2
2
  import { BrowserRuntime } from "./src/browser/runtime.js";
3
3
  import { registerBrowserCommand } from "./src/browser/settings.js";
4
- import { createBrowserTool, prepareBrowserCodeModeInput, } from "./src/browser-tool.js";
4
+ import { createBrowserTool, prepareBrowserInput } from "./src/browser-tool.js";
5
5
  export { createBrowserTool } from "./src/browser-tool.js";
6
6
  const CODE_MODE_PACKAGE = "@howaboua/pi-codex-conversion";
7
7
  const CODE_MODE_MODULE = `${CODE_MODE_PACKAGE}/code-mode`;
@@ -36,7 +36,7 @@ async function registerBrowserInCodeMode(pi, tool) {
36
36
  return registerCodeModeExtensionTools(pi, () => [
37
37
  adaptToolForCodeMode(tool, {
38
38
  kind: "freeform",
39
- prepareInput: prepareBrowserCodeModeInput,
39
+ prepareInput: prepareBrowserInput,
40
40
  usage: 'await tools.browser("help") // Logged-in browser; help before other actions',
41
41
  }),
42
42
  ]);
@@ -1729,13 +1729,13 @@ async function discardCachedResult(handle) {
1729
1729
  function browserHelp(hosts = []) {
1730
1730
  const routed = hosts.length > 0;
1731
1731
  return {
1732
- input: "Request={action,...fields}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
1732
+ input: "Request={action,...fields}; Pi: {command:JSON.stringify(request)}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
1733
1733
  ...routed ? {
1734
1734
  host: `${hosts.join("|")} optional; keep a user-named host on every call and its refs/handles`
1735
1735
  } : {},
1736
1736
  refs: "tabs -> open; keep ref_id/id/cursors with their result",
1737
1737
  safety: "Ask before unfamiliar low-trust navigation or consequential action unless authorized; never close shared browser",
1738
- batch: "Code/Notebook: {action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
1738
+ batch: "{action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
1739
1739
  actions: {
1740
1740
  tabs: "query? offset? owned_only? -> ref_id title url owned",
1741
1741
  open: "ref_id lineno? | url; new tabs open in background",
@@ -1,7 +1,7 @@
1
1
  export function browserHelp(hosts = []) {
2
2
  const routed = hosts.length > 0;
3
3
  return {
4
- input: "Request={action,...fields}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
4
+ input: "Request={action,...fields}; Pi: {command:JSON.stringify(request)}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
5
5
  ...(routed
6
6
  ? {
7
7
  host: `${hosts.join("|")} optional; keep a user-named host on every call and its refs/handles`,
@@ -9,7 +9,7 @@ export function browserHelp(hosts = []) {
9
9
  : {}),
10
10
  refs: "tabs -> open; keep ref_id/id/cursors with their result",
11
11
  safety: "Ask before unfamiliar low-trust navigation or consequential action unless authorized; never close shared browser",
12
- batch: "Code/Notebook: {action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
12
+ batch: "{action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
13
13
  actions: {
14
14
  tabs: "query? offset? owned_only? -> ref_id title url owned",
15
15
  open: "ref_id lineno? | url; new tabs open in background",
@@ -1,58 +1,8 @@
1
- import { BROWSER_ACTIONS } from "./browser/operation.js";
1
+ import { Type } from "typebox";
2
2
  import { BrowserRuntime } from "./browser/runtime.js";
3
- interface BrowserToolParams {
4
- action: (typeof BROWSER_ACTIONS)[number];
5
- }
6
- export declare function prepareBrowserCodeModeInput(input: unknown): BrowserToolParams;
7
- export declare function createBrowserTool(runtime: BrowserRuntime): import("@earendil-works/pi-coding-agent").ToolDefinition<import("typebox").TUnion<[import("typebox").TObject<{
8
- [x: string]: import("typebox").TSchema;
9
- }>, import("typebox").TObject<{
10
- [x: string]: import("typebox").TSchema;
11
- }>, import("typebox").TObject<{
12
- [x: string]: import("typebox").TSchema;
13
- }>, import("typebox").TObject<{
14
- [x: string]: import("typebox").TSchema;
15
- }>, import("typebox").TObject<{
16
- [x: string]: import("typebox").TSchema;
17
- }>, import("typebox").TObject<{
18
- [x: string]: import("typebox").TSchema;
19
- }>, import("typebox").TObject<{
20
- [x: string]: import("typebox").TSchema;
21
- }>, import("typebox").TObject<{
22
- [x: string]: import("typebox").TSchema;
23
- }>, import("typebox").TObject<{
24
- [x: string]: import("typebox").TSchema;
25
- }>, import("typebox").TObject<{
26
- [x: string]: import("typebox").TSchema;
27
- }>, import("typebox").TObject<{
28
- [x: string]: import("typebox").TSchema;
29
- }>, import("typebox").TObject<{
30
- [x: string]: import("typebox").TSchema;
31
- }>, import("typebox").TObject<{
32
- [x: string]: import("typebox").TSchema;
33
- }>, ...import("typebox").TObject<{
34
- [x: string]: import("typebox").TSchema;
35
- }>[], import("typebox").TObject<{
36
- [x: string]: import("typebox").TSchema;
37
- }>, import("typebox").TObject<{
38
- [x: string]: import("typebox").TSchema;
39
- }>, import("typebox").TObject<{
40
- [x: string]: import("typebox").TSchema;
41
- }>, import("typebox").TObject<{
42
- [x: string]: import("typebox").TSchema;
43
- }>, import("typebox").TObject<{
44
- [x: string]: import("typebox").TSchema;
45
- }>, import("typebox").TObject<{
46
- [x: string]: import("typebox").TSchema;
47
- }>, import("typebox").TObject<{
48
- [x: string]: import("typebox").TSchema;
49
- }>, import("typebox").TObject<{
50
- [x: string]: import("typebox").TSchema;
51
- }>, import("typebox").TObject<{
52
- [x: string]: import("typebox").TSchema;
53
- }>, import("typebox").TObject<{
54
- [x: string]: import("typebox").TSchema;
55
- }>, import("typebox").TObject<{
56
- [x: string]: import("typebox").TSchema;
57
- }>]>, unknown, any> & import("@earendil-works/pi-coding-agent").ToolDefinition<any, any, any>;
58
- export {};
3
+ export declare function prepareBrowserInput(input: unknown): {
4
+ command: string;
5
+ };
6
+ export declare function createBrowserTool(runtime: BrowserRuntime): import("@earendil-works/pi-coding-agent").ToolDefinition<Type.TObject<{
7
+ command: Type.TString;
8
+ }>, unknown, any> & import("@earendil-works/pi-coding-agent").ToolDefinition<any, any, any>;
@@ -1,37 +1,32 @@
1
1
  import { defineTool } from "@earendil-works/pi-coding-agent";
2
- import { BROWSER_ACTIONS } from "./browser/operation.js";
2
+ import { Type } from "typebox";
3
+ import { isRecordValue } from "./browser/parse-operation.js";
3
4
  import { parseBrowserRequest } from "./browser/request.js";
4
5
  import { BrowserRuntime } from "./browser/runtime.js";
5
- import { browserParameters } from "./browser-parameters.js";
6
- const preparedBrowserRequest = Symbol("preparedBrowserRequest");
7
- export function prepareBrowserCodeModeInput(input) {
8
- // Freeform requests can batch operations that the normal Pi schema does not
9
- // expose. Carry the parsed request beside a schema-valid adapter input.
10
- const prepared = { action: "help" };
11
- Object.defineProperty(prepared, preparedBrowserRequest, {
12
- value: parseBrowserRequest(input),
13
- });
14
- return prepared;
15
- }
16
- function isPreparedBrowserInput(input) {
17
- return (typeof input === "object" &&
18
- input !== null &&
19
- preparedBrowserRequest in input);
20
- }
21
- function browserRequest(input) {
22
- return isPreparedBrowserInput(input)
23
- ? input[preparedBrowserRequest]
24
- : parseBrowserRequest(input);
6
+ export function prepareBrowserInput(input) {
7
+ if (typeof input === "string")
8
+ return { command: input };
9
+ if (!isRecordValue(input)) {
10
+ throw new Error("browser input must be a command envelope or JSON request");
11
+ }
12
+ if (Object.hasOwn(input, "command")) {
13
+ if (typeof input["command"] !== "string") {
14
+ throw new Error('browser command must be "help" or a JSON request string');
15
+ }
16
+ return { ...input, command: input["command"] };
17
+ }
18
+ // Resume old object calls without changing their stored history representation.
19
+ return { command: JSON.stringify(input) };
25
20
  }
26
21
  export function createBrowserTool(runtime) {
27
- const parameters = browserParameters(runtime.hosts);
28
22
  return defineTool({
29
23
  name: "browser",
30
24
  label: "Browser",
31
25
  description: "Control logged-in browser; call help before other actions",
32
- parameters,
26
+ parameters: Type.Object({ command: Type.String({ description: "help or JSON request" }) }, { additionalProperties: false }),
27
+ prepareArguments: prepareBrowserInput,
33
28
  async execute(_toolCallId, input, signal, onUpdate, ctx) {
34
- const result = await runtime.execute(browserRequest(input), {
29
+ const result = await runtime.execute(parseBrowserRequest(input.command), {
35
30
  ownerId: ctx.sessionManager.getSessionId(),
36
31
  signal: signal ?? new AbortController().signal,
37
32
  onOperation(operation, index, total) {
package/index.ts CHANGED
@@ -2,10 +2,7 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import { BrowserRoutes, loadBrowserRoutes } from "./src/browser/routes.js";
3
3
  import { BrowserRuntime } from "./src/browser/runtime.js";
4
4
  import { registerBrowserCommand } from "./src/browser/settings.js";
5
- import {
6
- createBrowserTool,
7
- prepareBrowserCodeModeInput,
8
- } from "./src/browser-tool.js";
5
+ import { createBrowserTool, prepareBrowserInput } from "./src/browser-tool.js";
9
6
 
10
7
  export { createBrowserTool } from "./src/browser-tool.js";
11
8
 
@@ -49,7 +46,7 @@ async function registerBrowserInCodeMode(
49
46
  return registerCodeModeExtensionTools(pi, () => [
50
47
  adaptToolForCodeMode(tool, {
51
48
  kind: "freeform",
52
- prepareInput: prepareBrowserCodeModeInput,
49
+ prepareInput: prepareBrowserInput,
53
50
  usage:
54
51
  'await tools.browser("help") // Logged-in browser; help before other actions',
55
52
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-browser",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Logged-in browser inspection and control for Pi, Code Mode and Notebook Mode.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,11 +46,11 @@
46
46
  "pack:dry": "npm pack --dry-run"
47
47
  },
48
48
  "peerDependencies": {
49
- "@howaboua/pi-codex-conversion": ">=3.0.40",
50
- "@earendil-works/pi-ai": ">=0.84.3",
51
- "@earendil-works/pi-coding-agent": ">=0.84.3",
49
+ "@howaboua/pi-codex-conversion": ">=3.0.43",
50
+ "@earendil-works/pi-ai": ">=1.0.0",
51
+ "@earendil-works/pi-coding-agent": ">=1.0.0",
52
52
  "typebox": "*",
53
- "@earendil-works/pi-tui": "*"
53
+ "@earendil-works/pi-tui": ">=1.0.0"
54
54
  },
55
55
  "peerDependenciesMeta": {
56
56
  "@howaboua/pi-codex-conversion": {
@@ -58,10 +58,10 @@
58
58
  }
59
59
  },
60
60
  "devDependencies": {
61
- "@howaboua/pi-codex-conversion": "3.0.40",
61
+ "@howaboua/pi-codex-conversion": "3.0.43",
62
62
  "@biomejs/biome": "^2.5.10",
63
- "@earendil-works/pi-ai": "0.99.1",
64
- "@earendil-works/pi-coding-agent": "0.99.1",
63
+ "@earendil-works/pi-ai": "1.0.0",
64
+ "@earendil-works/pi-coding-agent": "1.0.0",
65
65
  "@types/node": "^26.2.0",
66
66
  "tsx": "^4.23.12",
67
67
  "typebox": "1.3.18",
@@ -4,7 +4,7 @@ export function browserHelp(
4
4
  const routed = hosts.length > 0;
5
5
  return {
6
6
  input:
7
- "Request={action,...fields}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
7
+ "Request={action,...fields}; Pi: {command:JSON.stringify(request)}; Code/Notebook: JSON.stringify(request), JSON.parse(result)",
8
8
  ...(routed
9
9
  ? {
10
10
  host: `${hosts.join("|")} optional; keep a user-named host on every call and its refs/handles`,
@@ -14,7 +14,7 @@ export function browserHelp(
14
14
  safety:
15
15
  "Ask before unfamiliar low-trust navigation or consequential action unless authorized; never close shared browser",
16
16
  batch:
17
- "Code/Notebook: {action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
17
+ "{action_name:[{...fields}],...}; nonempty arrays; items omit action; host/response_length at request root; independent only",
18
18
  actions: {
19
19
  tabs: "query? offset? owned_only? -> ref_id title url owned",
20
20
  open: "ref_id lineno? | url; new tabs open in background",
@@ -1,52 +1,38 @@
1
1
  import { defineTool } from "@earendil-works/pi-coding-agent";
2
- import { BROWSER_ACTIONS } from "./browser/operation.js";
3
- import { type BrowserRequest, parseBrowserRequest } from "./browser/request.js";
2
+ import { Type } from "typebox";
3
+ import { isRecordValue } from "./browser/parse-operation.js";
4
+ import { parseBrowserRequest } from "./browser/request.js";
4
5
  import { BrowserRuntime } from "./browser/runtime.js";
5
- import { browserParameters } from "./browser-parameters.js";
6
6
 
7
- interface BrowserToolParams {
8
- action: (typeof BROWSER_ACTIONS)[number];
9
- }
10
-
11
- const preparedBrowserRequest = Symbol("preparedBrowserRequest");
12
-
13
- interface PreparedBrowserInput {
14
- [preparedBrowserRequest]: BrowserRequest;
15
- }
16
-
17
- export function prepareBrowserCodeModeInput(input: unknown): BrowserToolParams {
18
- // Freeform requests can batch operations that the normal Pi schema does not
19
- // expose. Carry the parsed request beside a schema-valid adapter input.
20
- const prepared: BrowserToolParams = { action: "help" };
21
- Object.defineProperty(prepared, preparedBrowserRequest, {
22
- value: parseBrowserRequest(input),
23
- });
24
- return prepared;
25
- }
26
-
27
- function isPreparedBrowserInput(input: unknown): input is PreparedBrowserInput {
28
- return (
29
- typeof input === "object" &&
30
- input !== null &&
31
- preparedBrowserRequest in input
32
- );
33
- }
34
-
35
- function browserRequest(input: unknown): BrowserRequest {
36
- return isPreparedBrowserInput(input)
37
- ? input[preparedBrowserRequest]
38
- : parseBrowserRequest(input);
7
+ export function prepareBrowserInput(input: unknown): { command: string } {
8
+ if (typeof input === "string") return { command: input };
9
+ if (!isRecordValue(input)) {
10
+ throw new Error("browser input must be a command envelope or JSON request");
11
+ }
12
+ if (Object.hasOwn(input, "command")) {
13
+ if (typeof input["command"] !== "string") {
14
+ throw new Error(
15
+ 'browser command must be "help" or a JSON request string',
16
+ );
17
+ }
18
+ return { ...input, command: input["command"] };
19
+ }
20
+ // Resume old object calls without changing their stored history representation.
21
+ return { command: JSON.stringify(input) };
39
22
  }
40
23
 
41
24
  export function createBrowserTool(runtime: BrowserRuntime) {
42
- const parameters = browserParameters(runtime.hosts);
43
25
  return defineTool({
44
26
  name: "browser",
45
27
  label: "Browser",
46
28
  description: "Control logged-in browser; call help before other actions",
47
- parameters,
29
+ parameters: Type.Object(
30
+ { command: Type.String({ description: "help or JSON request" }) },
31
+ { additionalProperties: false },
32
+ ),
33
+ prepareArguments: prepareBrowserInput,
48
34
  async execute(_toolCallId, input, signal, onUpdate, ctx) {
49
- const result = await runtime.execute(browserRequest(input), {
35
+ const result = await runtime.execute(parseBrowserRequest(input.command), {
50
36
  ownerId: ctx.sessionManager.getSessionId(),
51
37
  signal: signal ?? new AbortController().signal,
52
38
  onOperation(operation, index, total) {
@@ -1,52 +0,0 @@
1
- import { type TSchema, Type } from "typebox";
2
- export declare function browserParameters(hosts: readonly string[]): Type.TUnion<[Type.TObject<{
3
- [x: string]: TSchema;
4
- }>, Type.TObject<{
5
- [x: string]: TSchema;
6
- }>, Type.TObject<{
7
- [x: string]: TSchema;
8
- }>, Type.TObject<{
9
- [x: string]: TSchema;
10
- }>, Type.TObject<{
11
- [x: string]: TSchema;
12
- }>, Type.TObject<{
13
- [x: string]: TSchema;
14
- }>, Type.TObject<{
15
- [x: string]: TSchema;
16
- }>, Type.TObject<{
17
- [x: string]: TSchema;
18
- }>, Type.TObject<{
19
- [x: string]: TSchema;
20
- }>, Type.TObject<{
21
- [x: string]: TSchema;
22
- }>, Type.TObject<{
23
- [x: string]: TSchema;
24
- }>, Type.TObject<{
25
- [x: string]: TSchema;
26
- }>, Type.TObject<{
27
- [x: string]: TSchema;
28
- }>, ...Type.TObject<{
29
- [x: string]: TSchema;
30
- }>[], Type.TObject<{
31
- [x: string]: TSchema;
32
- }>, Type.TObject<{
33
- [x: string]: TSchema;
34
- }>, Type.TObject<{
35
- [x: string]: TSchema;
36
- }>, Type.TObject<{
37
- [x: string]: TSchema;
38
- }>, Type.TObject<{
39
- [x: string]: TSchema;
40
- }>, Type.TObject<{
41
- [x: string]: TSchema;
42
- }>, Type.TObject<{
43
- [x: string]: TSchema;
44
- }>, Type.TObject<{
45
- [x: string]: TSchema;
46
- }>, Type.TObject<{
47
- [x: string]: TSchema;
48
- }>, Type.TObject<{
49
- [x: string]: TSchema;
50
- }>, Type.TObject<{
51
- [x: string]: TSchema;
52
- }>]>;
@@ -1,142 +0,0 @@
1
- import { StringEnum } from "@earendil-works/pi-ai";
2
- import { Type } from "typebox";
3
- export function browserParameters(hosts) {
4
- const route = hosts.length > 0
5
- ? {
6
- host: Type.Optional(StringEnum(hosts)),
7
- }
8
- : {};
9
- const request = (properties) => Type.Object({ ...route, ...properties }, { additionalProperties: false });
10
- const refId = Type.String({
11
- minLength: 1,
12
- });
13
- const elementId = Type.Integer({
14
- minimum: 1,
15
- });
16
- const responseLength = StringEnum(["short", "medium", "long"]);
17
- const handle = Type.String({
18
- minLength: 1,
19
- });
20
- const fillValue = Type.Union([Type.String(), Type.Boolean()]);
21
- const timeout = Type.Optional(Type.Integer({ minimum: 1, maximum: 60_000 }));
22
- return Type.Union([
23
- request({ action: StringEnum(["help", "start"]) }),
24
- request({
25
- action: Type.Literal("tabs"),
26
- query: Type.Optional(Type.String({ minLength: 1 })),
27
- offset: Type.Optional(Type.Integer({ minimum: 0 })),
28
- owned_only: Type.Optional(Type.Boolean()),
29
- }),
30
- request({
31
- action: Type.Literal("open"),
32
- ref_id: refId,
33
- lineno: Type.Optional(Type.Integer({ minimum: 1 })),
34
- response_length: Type.Optional(responseLength),
35
- }),
36
- request({
37
- action: Type.Literal("open"),
38
- url: Type.String({ minLength: 1 }),
39
- }),
40
- request({
41
- action: Type.Literal("find"),
42
- ref_id: refId,
43
- pattern: Type.String({ minLength: 1 }),
44
- lineno: Type.Optional(Type.Integer({ minimum: 1 })),
45
- response_length: Type.Optional(responseLength),
46
- }),
47
- request({
48
- action: StringEnum(["show", "close"]),
49
- ref_id: refId,
50
- }),
51
- request({ action: Type.Literal("click"), ref_id: refId, id: elementId }),
52
- request({
53
- action: Type.Literal("click"),
54
- ref_id: refId,
55
- selector: Type.String({ minLength: 1 }),
56
- }),
57
- request({
58
- action: Type.Literal("click"),
59
- ref_id: refId,
60
- x: Type.Number(),
61
- y: Type.Number(),
62
- }),
63
- request({
64
- action: Type.Literal("type"),
65
- ref_id: refId,
66
- id: Type.Optional(elementId),
67
- text: Type.String({ minLength: 1 }),
68
- }),
69
- request({
70
- action: Type.Literal("fill"),
71
- ref_id: refId,
72
- id: elementId,
73
- value: fillValue,
74
- }),
75
- request({
76
- action: Type.Literal("fill"),
77
- ref_id: refId,
78
- selector: Type.String({ minLength: 1 }),
79
- value: fillValue,
80
- }),
81
- request({
82
- action: Type.Literal("press"),
83
- ref_id: refId,
84
- key: Type.String({ minLength: 1 }),
85
- }),
86
- ...["selector", "text", "url_includes"].map((condition) => request({
87
- action: Type.Literal("wait"),
88
- ref_id: refId,
89
- [condition]: Type.String({ minLength: 1 }),
90
- timeout_ms: timeout,
91
- })),
92
- request({
93
- action: StringEnum(["screenshot", "html"]),
94
- ref_id: refId,
95
- }),
96
- request({
97
- action: StringEnum(["screenshot", "html"]),
98
- ref_id: refId,
99
- id: elementId,
100
- }),
101
- request({
102
- action: StringEnum(["screenshot", "html"]),
103
- ref_id: refId,
104
- selector: Type.String({ minLength: 1 }),
105
- }),
106
- request({
107
- action: Type.Literal("navigate"),
108
- ref_id: refId,
109
- url: Type.String({ minLength: 1 }),
110
- }),
111
- request({
112
- action: Type.Literal("evaluate"),
113
- ref_id: refId,
114
- expression: Type.String({ minLength: 1 }),
115
- }),
116
- request({ action: Type.Literal("network"), ref_id: refId }),
117
- request({
118
- action: Type.Literal("load_all"),
119
- ref_id: refId,
120
- selector: Type.String({ minLength: 1 }),
121
- interval_ms: Type.Optional(Type.Integer({ minimum: 0, maximum: 60_000 })),
122
- }),
123
- request({
124
- action: Type.Literal("raw"),
125
- ref_id: refId,
126
- method: Type.String({ minLength: 1 }),
127
- params: Type.Optional(Type.Object({}, { additionalProperties: true })),
128
- }),
129
- request({
130
- action: Type.Literal("read_result"),
131
- handle,
132
- offset: Type.Optional(Type.Integer({ minimum: 0 })),
133
- }),
134
- request({ action: Type.Literal("discard_result"), handle }),
135
- request({
136
- action: Type.Literal("stop"),
137
- ref_id: Type.Optional(refId),
138
- }),
139
- ], {
140
- description: "ref_id: tab from tabs; id: element from open/find; handle: continuation from browser; fill value: replacement text/option or checkbox/radio boolean",
141
- });
142
- }
@@ -1,153 +0,0 @@
1
- import { StringEnum } from "@earendil-works/pi-ai";
2
- import { type TSchema, Type } from "typebox";
3
-
4
- export function browserParameters(hosts: readonly string[]) {
5
- const route: Record<string, TSchema> =
6
- hosts.length > 0
7
- ? {
8
- host: Type.Optional(StringEnum(hosts)),
9
- }
10
- : {};
11
- const request = (properties: Record<string, TSchema>) =>
12
- Type.Object({ ...route, ...properties }, { additionalProperties: false });
13
- const refId = Type.String({
14
- minLength: 1,
15
- });
16
- const elementId = Type.Integer({
17
- minimum: 1,
18
- });
19
- const responseLength = StringEnum(["short", "medium", "long"] as const);
20
- const handle = Type.String({
21
- minLength: 1,
22
- });
23
- const fillValue = Type.Union([Type.String(), Type.Boolean()]);
24
- const timeout = Type.Optional(Type.Integer({ minimum: 1, maximum: 60_000 }));
25
- return Type.Union(
26
- [
27
- request({ action: StringEnum(["help", "start"] as const) }),
28
- request({
29
- action: Type.Literal("tabs"),
30
- query: Type.Optional(Type.String({ minLength: 1 })),
31
- offset: Type.Optional(Type.Integer({ minimum: 0 })),
32
- owned_only: Type.Optional(Type.Boolean()),
33
- }),
34
- request({
35
- action: Type.Literal("open"),
36
- ref_id: refId,
37
- lineno: Type.Optional(Type.Integer({ minimum: 1 })),
38
- response_length: Type.Optional(responseLength),
39
- }),
40
- request({
41
- action: Type.Literal("open"),
42
- url: Type.String({ minLength: 1 }),
43
- }),
44
- request({
45
- action: Type.Literal("find"),
46
- ref_id: refId,
47
- pattern: Type.String({ minLength: 1 }),
48
- lineno: Type.Optional(Type.Integer({ minimum: 1 })),
49
- response_length: Type.Optional(responseLength),
50
- }),
51
- request({
52
- action: StringEnum(["show", "close"] as const),
53
- ref_id: refId,
54
- }),
55
- request({ action: Type.Literal("click"), ref_id: refId, id: elementId }),
56
- request({
57
- action: Type.Literal("click"),
58
- ref_id: refId,
59
- selector: Type.String({ minLength: 1 }),
60
- }),
61
- request({
62
- action: Type.Literal("click"),
63
- ref_id: refId,
64
- x: Type.Number(),
65
- y: Type.Number(),
66
- }),
67
- request({
68
- action: Type.Literal("type"),
69
- ref_id: refId,
70
- id: Type.Optional(elementId),
71
- text: Type.String({ minLength: 1 }),
72
- }),
73
- request({
74
- action: Type.Literal("fill"),
75
- ref_id: refId,
76
- id: elementId,
77
- value: fillValue,
78
- }),
79
- request({
80
- action: Type.Literal("fill"),
81
- ref_id: refId,
82
- selector: Type.String({ minLength: 1 }),
83
- value: fillValue,
84
- }),
85
- request({
86
- action: Type.Literal("press"),
87
- ref_id: refId,
88
- key: Type.String({ minLength: 1 }),
89
- }),
90
- ...(["selector", "text", "url_includes"] as const).map((condition) =>
91
- request({
92
- action: Type.Literal("wait"),
93
- ref_id: refId,
94
- [condition]: Type.String({ minLength: 1 }),
95
- timeout_ms: timeout,
96
- }),
97
- ),
98
- request({
99
- action: StringEnum(["screenshot", "html"] as const),
100
- ref_id: refId,
101
- }),
102
- request({
103
- action: StringEnum(["screenshot", "html"] as const),
104
- ref_id: refId,
105
- id: elementId,
106
- }),
107
- request({
108
- action: StringEnum(["screenshot", "html"] as const),
109
- ref_id: refId,
110
- selector: Type.String({ minLength: 1 }),
111
- }),
112
- request({
113
- action: Type.Literal("navigate"),
114
- ref_id: refId,
115
- url: Type.String({ minLength: 1 }),
116
- }),
117
- request({
118
- action: Type.Literal("evaluate"),
119
- ref_id: refId,
120
- expression: Type.String({ minLength: 1 }),
121
- }),
122
- request({ action: Type.Literal("network"), ref_id: refId }),
123
- request({
124
- action: Type.Literal("load_all"),
125
- ref_id: refId,
126
- selector: Type.String({ minLength: 1 }),
127
- interval_ms: Type.Optional(
128
- Type.Integer({ minimum: 0, maximum: 60_000 }),
129
- ),
130
- }),
131
- request({
132
- action: Type.Literal("raw"),
133
- ref_id: refId,
134
- method: Type.String({ minLength: 1 }),
135
- params: Type.Optional(Type.Object({}, { additionalProperties: true })),
136
- }),
137
- request({
138
- action: Type.Literal("read_result"),
139
- handle,
140
- offset: Type.Optional(Type.Integer({ minimum: 0 })),
141
- }),
142
- request({ action: Type.Literal("discard_result"), handle }),
143
- request({
144
- action: Type.Literal("stop"),
145
- ref_id: Type.Optional(refId),
146
- }),
147
- ],
148
- {
149
- description:
150
- "ref_id: tab from tabs; id: element from open/find; handle: continuation from browser; fill value: replacement text/option or checkbox/radio boolean",
151
- },
152
- );
153
- }