@howaboua/pi-durable-browser 0.0.0-stage → 0.9.1

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +52 -0
  3. package/README.md +86 -2
  4. package/dist/browser/artifact-store.d.ts +16 -0
  5. package/dist/browser/artifacts.d.ts +20 -0
  6. package/dist/browser/bounds.d.ts +4 -0
  7. package/dist/browser/config-store.d.ts +11 -0
  8. package/dist/browser/config.d.ts +7 -0
  9. package/dist/browser/help.d.ts +1 -0
  10. package/dist/browser/launcher.d.ts +1 -0
  11. package/dist/browser/operation-executor.d.ts +12 -0
  12. package/dist/browser/operation-input.d.ts +10 -0
  13. package/dist/browser/operation.d.ts +115 -0
  14. package/dist/browser/parse-operation.d.ts +6 -0
  15. package/dist/browser/parse-tab-operation.d.ts +3 -0
  16. package/dist/browser/remote-helper.d.ts +3 -0
  17. package/dist/browser/remote-process.d.ts +6 -0
  18. package/dist/browser/remote.d.ts +4 -0
  19. package/dist/browser/request.d.ts +8 -0
  20. package/dist/browser/routes.d.ts +15 -0
  21. package/dist/browser/runtime.d.ts +35 -0
  22. package/dist/browser/voice-start.d.ts +17 -0
  23. package/dist/browser/worker-client.d.ts +1 -0
  24. package/dist/browser/worker-server.d.ts +1 -0
  25. package/dist/browser/worker-socket.d.ts +11 -0
  26. package/dist/cdp/accessibility-snapshot.d.ts +11 -0
  27. package/dist/cdp/actions/click.d.ts +6 -0
  28. package/dist/cdp/actions/element.d.ts +22 -0
  29. package/dist/cdp/actions/fill.d.ts +8 -0
  30. package/dist/cdp/actions/key.d.ts +20 -0
  31. package/dist/cdp/actions/page.d.ts +7 -0
  32. package/dist/cdp/actions/screenshot.d.ts +14 -0
  33. package/dist/cdp/actions/selector.d.ts +2 -0
  34. package/dist/cdp/actions/type.d.ts +3 -0
  35. package/dist/cdp/actions/wait.d.ts +9 -0
  36. package/dist/cdp/client.d.ts +20 -0
  37. package/dist/cdp/discovery.d.ts +7 -0
  38. package/dist/cdp/evaluate.d.ts +3 -0
  39. package/dist/cdp/pages.d.ts +4 -0
  40. package/dist/cdp/serial.d.ts +1 -0
  41. package/dist/cdp/session.d.ts +27 -0
  42. package/dist/cdp/snapshot-contract.d.ts +38 -0
  43. package/dist/cdp/snapshot.d.ts +3 -0
  44. package/dist/cdp/tab-bridge.d.ts +26 -0
  45. package/dist/cdp/tabs.d.ts +32 -0
  46. package/dist/cdp/types.d.ts +22 -0
  47. package/dist/cdp/url.d.ts +1 -0
  48. package/dist/index.d.ts +119 -0
  49. package/dist/index.js +3951 -0
  50. package/dist/presentation.d.ts +43 -0
  51. package/dist/presentation.js +82 -0
  52. package/dist/remote-worker.d.ts +2 -0
  53. package/dist/remote-worker.js +3850 -0
  54. package/package.json +43 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Igor Warzocha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,52 @@
1
+ Voice start, voice-only registration and object-input validation adapt Pi Stuff
2
+ revision e4aa5bb43c560b722829a5123b3f2e05d3d9a19d.
3
+ Voice automation requires explicit native BrowserRuntimeConfig here.
4
+
5
+ Applicable PR #552 changes adapted from howaboua-pi-stuff revision
6
+ 1338b66a1067c254fec46746ef96b6bd9456148b. TypeScript execution mode
7
+ and QuickJS Notebook are excluded. See docs/parity for native adaptations.
8
+
9
+ Source alignment inspected at Pi Stuff revision 7f3295e67a8e6146b2a6922b56a06fa4db5c3a32.
10
+ See docs/parity for carried changes and explicit native-environment exclusions.
11
+
12
+ Normalised atomic route persistence follows packages/pi-browser/src/browser/config.ts
13
+ as inspected at 12c4357b2c401fe9be8c6c82d2ae252c0f986937.
14
+ Modifications: explicit host-selected storage, private unique temporary files,
15
+ and no ambient Pi configuration path.
16
+
17
+ This package carries and adapts the CDP implementation, browser operations,
18
+ request grammar, bounds, lifecycle and managed SSH worker from:
19
+ https://github.com/IgorWarzocha/howaboua-pi-stuff/tree/b2006db9def12c373ae48e70044d30f7d6b7e34f/packages/pi-browser
20
+ Revision: b2006db9def12c373ae48e70044d30f7d6b7e34f
21
+
22
+ Foreground screenshot capture and discovery/input refresh incorporate:
23
+ Revision: 1feee20371e6455a50fcd1266a69a2e8b8719fa5
24
+ Revision: 69f50cf70e8a7b05c2349be6227f521b6504f80e
25
+
26
+ The source CDP implementation is based on:
27
+ https://github.com/pasky/chrome-cdp-skill
28
+
29
+ The upstream license follows unchanged.
30
+
31
+ MIT License
32
+
33
+ Copyright (c) 2026 pasky
34
+ Copyright (c) 2026 Igor Warzocha
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining a copy
37
+ of this software and associated documentation files (the "Software"), to deal
38
+ in the Software without restriction, including without limitation the rights
39
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40
+ copies of the Software, and to permit persons to whom the Software is
41
+ furnished to do so, subject to the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be included in all
44
+ copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,87 @@
1
- # Temporary Holding Version
1
+ # Durable Browser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Control an authenticated Chrome or Chromium browser through an ordinary Pi Durable tool registration. The browser keeps your existing login session. No Pi TUI or Code/Notebook adapter is required.
4
+
5
+ Requires Node 22.19 or newer and a browser with remote debugging enabled. The host explicitly authorizes native CDP connections, browser launch, SSH processes and a private state directory. Browser actions can change real accounts.
6
+
7
+ ## Install and register
8
+
9
+ ```sh
10
+ npm install https://github.com/IgorWarzocha/pi-durable-components/releases/download/v0.9.1/howaboua-pi-durable-browser-0.9.1.tgz
11
+ ```
12
+
13
+ Use the package with Pi Durable, pi-ai and Chord 1.4.0:
14
+
15
+ ```ts
16
+ import { join } from "node:path";
17
+ import { tmpdir } from "node:os";
18
+ import { createRegistry } from "@earendil-works/pi-durable";
19
+ import { createBrowserExtension, nodeArtifactStore } from "@howaboua/pi-durable-browser";
20
+
21
+ const stateDirectory = join(tmpdir(), "my-agent-browser");
22
+ const browser = createBrowserExtension({
23
+ stateDirectory,
24
+ artifacts: nodeArtifactStore(join(stateDirectory, "artifacts")),
25
+ });
26
+ const registry = createRegistry();
27
+ registry.install(browser.extension);
28
+ // Select the browser extension for the conversation in your Durable host.
29
+ // At host shutdown, after stopping new calls:
30
+ await browser.close();
31
+ ```
32
+
33
+ Call the registered tool with `{}` for help, or supply `{command: "help"}`. For example, `{command: '{"action":"tabs"}'}` lists tab references. Keep each result's tab reference, element IDs and continuation cursors together.
34
+
35
+ Screenshots bring the target tab to the foreground and can change browser focus. Other actions retain background rendering for owned tabs. Known `response_length` hints are ignored by actions that do not consume them. Snapshot reads validate the hint.
36
+
37
+ ## Files and lifetime
38
+
39
+ When Durable supplies `api.env`, screenshots and text continuation files use that environment's `.pi/browser` directory. Set `environmentArtifactDirectory` to change that path. Errors from the environment are reported, not redirected to the host filesystem. Without `api.env`, the explicitly supplied artifact store owns those files. Hosts may provide their own `BrowserArtifactStore`.
40
+
41
+ Private tab-ownership records and temporary SCP staging always use the configured native `stateDirectory`. Staging files are removed after transfer. Native CDP discovery may read local browser port files. The browser endpoint is independent of the conversation filesystem. To target a container or a different endpoint, supply `discover(signal)` and optionally `start(signal)` in the host config. Omitted callbacks use local discovery and launch.
42
+
43
+ CDP connections are reused by Durable conversation ID. Idle connections retire after 20 minutes. `stop` detaches automation without closing tabs. Host `close()` cancels and joins owned work. It does not close Chrome or its tabs. Connections do not survive process restart, but saved ownership survives reconnect while the browser endpoint and native state remain. A restarted browser makes restored tabs shared again.
44
+
45
+ Interrupted browser mutations may already have succeeded. The tool is replay-unsafe. Inspect the browser before repeating a consequential action.
46
+
47
+ ## Local discovery and SSH hosts
48
+
49
+ Local discovery uses `CDP_HOST` and `CDP_PORT`, defaulting to `127.0.0.1:9222`, then supported `DevToolsActivePort` locations. `CDP_PORT_FILE` supplies a custom port file. The `start` action can launch Chromium through a Linux systemd user session. `CDP_BROWSER`, `CDP_PROFILE_DIRECTORY`, `CDP_SYSTEMCTL` and `CDP_SYSTEMD_RUN` configure that native launch.
50
+
51
+ For SSH routing, pass routes parsed from a saved configuration. The package owns its JSON format, defaults, validation and normalized writes; the host selects the settings namespace and storage implementation.
52
+
53
+ Construct `createBrowserRouteConfigFileStore(absolutePath)` to opt into a native JSON file, or implement `BrowserRouteConfigStore` over the host's settings store. The path is explicit; Browser does not guess a home directory. A custom store's `write` must atomically replace the complete value. The native file store writes a uniquely named temporary file and renames it into place. Concurrent edits retain the source's last-writer-wins behavior; the package does not merge them or add revision checks.
54
+
55
+ `readBrowserRouteConfig(store)` returns the default local-only config when no value exists and rejects malformed saved config. `writeBrowserRouteConfig(store, config)` validates and normalizes before saving; no configured hosts removes the saved value. Rebuild or replace the runtime after a successful write to use the returned config. The host selects the path or storage namespace and owns the settings UI and storage lifecycle.
56
+
57
+ ```ts
58
+ import {
59
+ createBrowserRouteConfigFileStore,
60
+ parseBrowserRoutes,
61
+ readBrowserRouteConfig,
62
+ writeBrowserRouteConfig,
63
+ } from "@howaboua/pi-durable-browser";
64
+
65
+ // The host chooses and authorizes this native settings path.
66
+ const routeStore = createBrowserRouteConfigFileStore(settingsPath);
67
+ const saved = await readBrowserRouteConfig(routeStore);
68
+ const next = await writeBrowserRouteConfig(
69
+ routeStore,
70
+ { ...saved.config, hosts: [...saved.config.hosts, "laptop"] },
71
+ );
72
+ const routes = parseBrowserRoutes(next);
73
+ ```
74
+
75
+ Names must be SSH aliases already configured by the host. Routing is disabled unless configured. Use `host` on every follow-up call using remote references or continuation handles.
76
+
77
+ Remote hosts need Node, SSH access and their own CDP browser. The shipped worker deploys atomically to `~/.cache/pi-durable-browser/worker.mjs`, refusing to replace an unowned file. Its private socket daemon reuses connections and retires after 20 minutes. Worker sockets and artifacts use `pi-durable-browser` under the remote XDG runtime directory, or a user-scoped temporary directory. These paths and the deployment marker are distinct from Pi Browser's installed helper and state. Screenshots return through SCP into the invocation's artifact store, then the remote screenshot is removed. Text continuation handles stay on the selected remote host.
78
+
79
+ The CDP implementation derives from [pasky/chrome-cdp-skill](https://github.com/pasky/chrome-cdp-skill) and [pi-browser](https://github.com/IgorWarzocha/howaboua-pi-stuff/tree/b2006db9def12c373ae48e70044d30f7d6b7e34f/packages/pi-browser). See `NOTICE` for attribution.
80
+
81
+ ## Headless presentations
82
+
83
+ The browser-safe `@howaboua/pi-durable-browser/presentation` entry exports `browserCapability`, `browserSummary`, `browserDetail` and `createBrowserPresentationState`. The constructor projects an existing tool receipt into completed operation counts, screenshot paths, host routing and text continuation cursors.
84
+
85
+ Start with `createBrowserPresentationState(details)`. Its `detail` is `null`, meaning not acquired. Bind the capability once and select either presentation. A summary request for `detail` is a host callback, not a tool call. The host may publish the already recorded body on demand. Empty acquired results remain distinct from `null`.
86
+
87
+ These readonly receipt capabilities expose no actions or streams. They do not register tools, load artifacts, authenticate, or replay operations. The host owns binding, authorization and any ordinary tool invocation. Never repeat an interrupted side effect to populate a presentation.
@@ -0,0 +1,16 @@
1
+ import type { Context } from "@earendil-works/chord";
2
+ import { type ExecutionEnv } from "@earendil-works/pi-durable/env";
3
+ /** Artifact names are generated internally, never caller-supplied paths. */
4
+ export interface BrowserArtifactStore {
5
+ path(name: string): string;
6
+ write(name: string, data: string | Uint8Array): Promise<void>;
7
+ read(name: string): Promise<string>;
8
+ remove(name: string): Promise<void>;
9
+ entries(): Promise<readonly {
10
+ name: string;
11
+ mtimeMs: number;
12
+ }[]>;
13
+ }
14
+ export declare function nodeArtifactStore(directory: string): BrowserArtifactStore;
15
+ /** The invoking environment owns every model-visible file. No Node fallback. */
16
+ export declare function environmentArtifactStore(env: ExecutionEnv, directory: string, context: Context): Promise<BrowserArtifactStore>;
@@ -0,0 +1,20 @@
1
+ import type { BrowserArtifactStore } from "./artifact-store.ts";
2
+ export declare class BrowserArtifacts {
3
+ readonly store: BrowserArtifactStore;
4
+ constructor(store: BrowserArtifactStore);
5
+ screenshotTarget(request: {
6
+ ref_id: string;
7
+ id?: number | undefined;
8
+ selector?: string | undefined;
9
+ }): {
10
+ file: string;
11
+ write: (data: Uint8Array) => Promise<void>;
12
+ };
13
+ prune(now?: number): Promise<number>;
14
+ limitedText(base: Record<string, unknown>, field: string, value: string): Promise<Record<string, unknown>>;
15
+ readCachedResult(request: {
16
+ handle: string;
17
+ offset: number;
18
+ }): Promise<Record<string, unknown>>;
19
+ discardCachedResult(handle: string): Promise<Record<string, unknown>>;
20
+ }
@@ -0,0 +1,4 @@
1
+ import type { SnapshotResult } from "../cdp/snapshot-contract.ts";
2
+ import type { PageInfo } from "../cdp/types.ts";
3
+ export declare function boundTabs(pages: PageInfo[], query: string | undefined, offset: number, ownedOnly?: boolean): Record<string, unknown>;
4
+ export declare function boundSnapshot(page: SnapshotResult): Record<string, unknown>;
@@ -0,0 +1,11 @@
1
+ import { type BrowserRouteConfig } from "./config.ts";
2
+ /** Host-selected persistence; writes must replace the complete value atomically. */
3
+ export interface BrowserRouteConfigStore {
4
+ readonly id: string;
5
+ read(): Promise<string | undefined>;
6
+ write(text: string | undefined): Promise<void>;
7
+ }
8
+ /** A native path is used only when the host explicitly constructs this store. */
9
+ export declare function createBrowserRouteConfigFileStore(path: string): BrowserRouteConfigStore;
10
+ export declare function readBrowserRouteConfig(store: BrowserRouteConfigStore): Promise<BrowserRouteConfig>;
11
+ export declare function writeBrowserRouteConfig(store: BrowserRouteConfigStore, config: unknown): Promise<BrowserRouteConfig>;
@@ -0,0 +1,7 @@
1
+ export interface BrowserRouteConfig {
2
+ aliases: Record<string, string>;
3
+ hosts: string[];
4
+ remoteNodePath: string;
5
+ voiceOnly?: boolean;
6
+ }
7
+ export declare function normalizeBrowserRouteConfig(value: unknown): BrowserRouteConfig;
@@ -0,0 +1 @@
1
+ export declare function browserHelp(hosts?: readonly string[]): Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export declare function startBrowser(signal?: AbortSignal): Promise<string>;
@@ -0,0 +1,12 @@
1
+ import { BrowserCdpSession } from "../cdp/session.ts";
2
+ import { BrowserArtifacts } from "./artifacts.ts";
3
+ import { startBrowser } from "./launcher.ts";
4
+ import type { BrowserOperation } from "./operation.ts";
5
+ export declare class BrowserOperationExecutor {
6
+ private readonly cdp;
7
+ private readonly start;
8
+ constructor(cdp: BrowserCdpSession, start?: typeof startBrowser);
9
+ execute(operation: BrowserOperation, signal: AbortSignal | undefined, artifacts: BrowserArtifacts): Promise<Record<string, unknown>>;
10
+ private screenshot;
11
+ private tabResult;
12
+ }
@@ -0,0 +1,10 @@
1
+ import type { SnapshotResponseLength } from "../cdp/snapshot-contract.ts";
2
+ import type { BrowserAction } from "./operation.ts";
3
+ export declare function isRecordValue(value: unknown): value is Record<string, unknown>;
4
+ export declare function requiredString(value: unknown, field: string): string;
5
+ export declare function optionalString(value: unknown, field: string): string | undefined;
6
+ export declare function requiredRef(value: unknown, action: BrowserAction): string;
7
+ export declare function offset(value: unknown, field?: string, fallback?: number): number;
8
+ export declare function line(value: unknown): number;
9
+ export declare function elementId(value: unknown): number | undefined;
10
+ export declare function responseLength(value: unknown): SnapshotResponseLength;
@@ -0,0 +1,115 @@
1
+ import type { WaitCondition } from "../cdp/actions/wait.ts";
2
+ import type { SnapshotResponseLength } from "../cdp/snapshot-contract.ts";
3
+ export declare const BROWSER_ACTIONS: readonly ["help", "start", "tabs", "open", "show", "close", "find", "click", "type", "fill", "press", "wait", "screenshot", "html", "navigate", "evaluate", "network", "load_all", "raw", "read_result", "discard_result", "stop"];
4
+ export declare const OPERATION_ORDER: ("click" | "close" | "discard_result" | "evaluate" | "fill" | "find" | "html" | "load_all" | "navigate" | "network" | "open" | "press" | "raw" | "read_result" | "screenshot" | "show" | "start" | "stop" | "tabs" | "type" | "wait")[];
5
+ export type BrowserAction = (typeof BROWSER_ACTIONS)[number];
6
+ export type BrowserOperation = {
7
+ action: "start";
8
+ } | {
9
+ action: "tabs";
10
+ query?: string | undefined;
11
+ offset: number;
12
+ owned_only?: boolean | undefined;
13
+ } | {
14
+ action: "open";
15
+ ref_id: string;
16
+ lineno: number;
17
+ response_length: SnapshotResponseLength;
18
+ } | {
19
+ action: "open";
20
+ url: string;
21
+ } | {
22
+ action: "show" | "close";
23
+ ref_id: string;
24
+ } | {
25
+ action: "find";
26
+ ref_id: string;
27
+ pattern: string;
28
+ lineno: number;
29
+ response_length: SnapshotResponseLength;
30
+ } | {
31
+ action: "click";
32
+ ref_id: string;
33
+ id: number;
34
+ selector?: never;
35
+ x?: never;
36
+ y?: never;
37
+ } | {
38
+ action: "click";
39
+ ref_id: string;
40
+ id?: never;
41
+ selector: string;
42
+ x?: never;
43
+ y?: never;
44
+ } | {
45
+ action: "click";
46
+ ref_id: string;
47
+ id?: never;
48
+ selector?: never;
49
+ x: number;
50
+ y: number;
51
+ } | {
52
+ action: "type";
53
+ ref_id: string;
54
+ id?: number | undefined;
55
+ text: string;
56
+ } | ({
57
+ action: "fill";
58
+ ref_id: string;
59
+ value: string | boolean;
60
+ } & ({
61
+ id: number;
62
+ selector?: never;
63
+ } | {
64
+ selector: string;
65
+ id?: never;
66
+ })) | {
67
+ action: "press";
68
+ ref_id: string;
69
+ key: string;
70
+ } | ({
71
+ action: "wait";
72
+ ref_id: string;
73
+ timeout_ms: number;
74
+ } & WaitCondition) | {
75
+ action: "screenshot";
76
+ ref_id: string;
77
+ id?: number | undefined;
78
+ selector?: string | undefined;
79
+ } | {
80
+ action: "html";
81
+ ref_id: string;
82
+ id?: number | undefined;
83
+ selector?: string | undefined;
84
+ } | {
85
+ action: "navigate";
86
+ ref_id: string;
87
+ url: string;
88
+ } | {
89
+ action: "evaluate";
90
+ ref_id: string;
91
+ expression: string;
92
+ } | {
93
+ action: "network";
94
+ ref_id: string;
95
+ } | {
96
+ action: "load_all";
97
+ ref_id: string;
98
+ selector: string;
99
+ interval_ms: number;
100
+ } | {
101
+ action: "raw";
102
+ ref_id: string;
103
+ method: string;
104
+ params: Record<string, unknown>;
105
+ } | {
106
+ action: "read_result";
107
+ handle: string;
108
+ offset: number;
109
+ } | {
110
+ action: "discard_result";
111
+ handle: string;
112
+ } | {
113
+ action: "stop";
114
+ ref_id?: string | undefined;
115
+ };
@@ -0,0 +1,6 @@
1
+ export { isRecordValue } from "./operation-input.ts";
2
+ import { type BrowserOperation } from "./operation.ts";
3
+ export type ActionRequest = BrowserOperation | {
4
+ action: "help";
5
+ };
6
+ export declare function parseActionRequest(value: unknown): ActionRequest;
@@ -0,0 +1,3 @@
1
+ import type { BrowserAction, BrowserOperation } from "./operation.ts";
2
+ /** Validate tab effects after the envelope has rejected unknown fields and required a tab reference. */
3
+ export declare function parseTabOperation(action: BrowserAction, refId: string, value: Record<string, unknown>): BrowserOperation;
@@ -0,0 +1,3 @@
1
+ import type { BrowserRemoteCommand } from "./routes.ts";
2
+ export declare function remoteNodeCommand(command: BrowserRemoteCommand): string;
3
+ export declare function ensureRemoteHelper(host: string, command: BrowserRemoteCommand, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,6 @@
1
+ export interface ProcessResult {
2
+ code: number;
3
+ stderr: string;
4
+ stdout: string;
5
+ }
6
+ export declare function runProgram(command: string, args: string[], input: string | undefined, signal?: AbortSignal): Promise<ProcessResult>;
@@ -0,0 +1,4 @@
1
+ import type { BrowserArtifacts } from "./artifacts.ts";
2
+ import type { BrowserOperation } from "./operation.ts";
3
+ import type { BrowserRoute } from "./routes.ts";
4
+ export declare function executeRemoteBrowser(route: BrowserRoute, operations: BrowserOperation[], ownerId: string, signal: AbortSignal | undefined, artifacts: BrowserArtifacts, stateDirectory: string): Promise<Record<string, unknown>>;
@@ -0,0 +1,8 @@
1
+ import { type BrowserOperation } from "./operation.ts";
2
+ export type BrowserRequest = {
3
+ help: true;
4
+ } | {
5
+ operations: BrowserOperation[];
6
+ host?: string | undefined;
7
+ };
8
+ export declare function parseBrowserRequest(input: unknown): BrowserRequest;
@@ -0,0 +1,15 @@
1
+ export interface BrowserRemoteCommand {
2
+ nodePath: string;
3
+ }
4
+ export interface BrowserRoute {
5
+ local: boolean;
6
+ name: string;
7
+ remote?: BrowserRemoteCommand;
8
+ }
9
+ export declare class BrowserRoutes {
10
+ readonly names: readonly string[];
11
+ private readonly routes;
12
+ constructor(routes?: ReadonlyMap<string, BrowserRoute>);
13
+ resolve(name: string): BrowserRoute;
14
+ }
15
+ export declare function parseBrowserRoutes(value: unknown, currentHostname?: string): BrowserRoutes;
@@ -0,0 +1,35 @@
1
+ import type { BrowserArtifactStore } from "./artifact-store.ts";
2
+ import type { BrowserOperation } from "./operation.ts";
3
+ import type { BrowserRequest } from "./request.ts";
4
+ import { BrowserRoutes } from "./routes.ts";
5
+ export interface BrowserExecutionOptions {
6
+ ownerId?: string | undefined;
7
+ signal?: AbortSignal | undefined;
8
+ artifacts?: BrowserArtifactStore | undefined;
9
+ onOperation?(operation: BrowserOperation, index: number, total: number): void | Promise<void>;
10
+ }
11
+ export interface BrowserRuntimeConfig {
12
+ /** Explicit native private state. CDP ownership and SCP staging live here. */
13
+ stateDirectory: string;
14
+ artifacts: BrowserArtifactStore;
15
+ routes?: BrowserRoutes;
16
+ discover?: (signal?: AbortSignal) => Promise<string>;
17
+ start?: (signal?: AbortSignal) => Promise<string>;
18
+ }
19
+ export declare class BrowserRuntime {
20
+ readonly hosts: readonly string[];
21
+ private readonly defaultOwnerId;
22
+ private readonly lifetime;
23
+ private closing;
24
+ private readonly localSessions;
25
+ private readonly routes;
26
+ private readonly active;
27
+ private readonly config;
28
+ constructor(config: BrowserRuntimeConfig);
29
+ execute(request: BrowserRequest, options?: BrowserExecutionOptions): Promise<Record<string, unknown>>;
30
+ private run;
31
+ close(): Promise<void>;
32
+ private executeLocal;
33
+ private localSession;
34
+ private pruneLocalSessions;
35
+ }
@@ -0,0 +1,17 @@
1
+ import { type BrowserRuntimeConfig } from "./runtime.ts";
2
+ export interface BrowserVoiceStartOptions {
3
+ url: string;
4
+ host?: string;
5
+ provider: "codex" | "gippity" | "grok";
6
+ signal?: AbortSignal;
7
+ timeoutMs?: number;
8
+ }
9
+ export interface BrowserVoiceStartResult {
10
+ state: "listening" | "error" | "timeout";
11
+ url: string;
12
+ refId?: string;
13
+ status: string;
14
+ detail: string;
15
+ }
16
+ /** Start once in a new tab; disconnect automation without closing the tab. */
17
+ export declare function startBrowserVoice(options: BrowserVoiceStartOptions, config: BrowserRuntimeConfig): Promise<BrowserVoiceStartResult>;
@@ -0,0 +1 @@
1
+ export declare function requestBrowserWorker(input: string, entryPath: string, workerId: string, signal?: AbortSignal): Promise<Record<string, unknown>>;
@@ -0,0 +1 @@
1
+ export declare function serveBrowserWorker(workerId: string): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import type { Socket } from "node:net";
2
+ export type WorkerResponse = {
3
+ ok: true;
4
+ result: Record<string, unknown>;
5
+ } | {
6
+ ok: false;
7
+ error: string;
8
+ };
9
+ export declare function workerSocketPath(workerId: string): string;
10
+ export declare function ensureWorkerSocketDirectory(workerId: string): Promise<void>;
11
+ export declare function readLine(socket: Socket): Promise<string>;
@@ -0,0 +1,11 @@
1
+ import type { SnapshotElement, SnapshotLine } from "./snapshot-contract.ts";
2
+ import { type ElementRefs } from "./types.ts";
3
+ type InternalLine = SnapshotLine & {
4
+ kind: string;
5
+ };
6
+ /** Replace a tab's reference map while rendering the full accessibility tree. IDs never repeat within that map. */
7
+ export declare function renderAccessibilityTree(values: unknown[], elementRefs: ElementRefs): {
8
+ lines: InternalLine[];
9
+ elements: SnapshotElement[];
10
+ };
11
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { CdpConnection, ElementRefs } from "../types.ts";
2
+ import { type ElementPoint } from "./element.ts";
3
+ export declare function clickBackendNode(cdp: CdpConnection, sessionId: string, backendNodeId: number, signal?: AbortSignal): Promise<ElementPoint>;
4
+ export declare function clickSelector(cdp: CdpConnection, sessionId: string, selector: string, signal?: AbortSignal): Promise<string>;
5
+ export declare function clickRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, signal?: AbortSignal): Promise<string>;
6
+ export declare function clickCoordinates(cdp: CdpConnection, sessionId: string, x: number, y: number, signal?: AbortSignal): Promise<string>;
@@ -0,0 +1,22 @@
1
+ import type { CdpConnection, ElementRefs } from "../types.ts";
2
+ export interface ElementPoint {
3
+ x: number;
4
+ y: number;
5
+ tag: string;
6
+ text: string;
7
+ }
8
+ export interface ScreenshotClip {
9
+ x: number;
10
+ y: number;
11
+ width: number;
12
+ height: number;
13
+ scale: number;
14
+ }
15
+ export declare function requireElementRef(elementRefs: ElementRefs, id: number | string): {
16
+ id: number;
17
+ backendNodeId: number;
18
+ };
19
+ export declare function withBackendObject<T>(cdp: CdpConnection, sessionId: string, backendNodeId: number, action: (objectId: string) => Promise<T>, signal?: AbortSignal): Promise<T>;
20
+ export declare function scrollBackendIntoView(cdp: CdpConnection, sessionId: string, backendNodeId: number, signal?: AbortSignal): Promise<void>;
21
+ export declare function backendCenter(cdp: CdpConnection, sessionId: string, backendNodeId: number, scroll?: boolean, signal?: AbortSignal): Promise<ElementPoint>;
22
+ export declare function visibleElementClip(cdp: CdpConnection, sessionId: string, quad: number[], padding?: number, signal?: AbortSignal): Promise<ScreenshotClip>;
@@ -0,0 +1,8 @@
1
+ import type { CdpConnection, ElementRefs } from "../types.ts";
2
+ export declare function fillElement(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, target: {
3
+ id: number;
4
+ selector?: never;
5
+ } | {
6
+ selector: string;
7
+ id?: never;
8
+ }, value: string | boolean, signal?: AbortSignal): Promise<string>;
@@ -0,0 +1,20 @@
1
+ import type { CdpConnection } from "../types.ts";
2
+ declare const MODIFIERS: {
3
+ readonly Alt: 1;
4
+ readonly Control: 2;
5
+ readonly Meta: 4;
6
+ readonly Shift: 8;
7
+ };
8
+ type Modifier = keyof typeof MODIFIERS;
9
+ interface Key {
10
+ key: string;
11
+ code: string;
12
+ windowsVirtualKeyCode: number;
13
+ text?: string;
14
+ }
15
+ export declare function parseKeyChord(chord: string): {
16
+ modifiers: Modifier[];
17
+ key: Key;
18
+ };
19
+ export declare function pressKey(cdp: CdpConnection, sessionId: string, chord: string, signal?: AbortSignal): Promise<string>;
20
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { CdpConnection, ElementRefs } from "../types.ts";
2
+ export declare function html(cdp: CdpConnection, sessionId: string, selector?: string, signal?: AbortSignal): Promise<string>;
3
+ export declare function htmlRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, signal?: AbortSignal): Promise<string>;
4
+ export declare function navigate(cdp: CdpConnection, sessionId: string, url: string, signal?: AbortSignal): Promise<string>;
5
+ export declare function networkEntries(cdp: CdpConnection, sessionId: string, signal?: AbortSignal): Promise<string>;
6
+ export declare function loadAll(cdp: CdpConnection, sessionId: string, selector: string, intervalMs?: number, signal?: AbortSignal): Promise<string>;
7
+ export declare function rawCommand(cdp: CdpConnection, sessionId: string, method: string, params: Record<string, unknown>, signal?: AbortSignal): Promise<string>;
@@ -0,0 +1,14 @@
1
+ import type { CdpConnection, ElementRefs } from "../types.ts";
2
+ export interface ScreenshotTarget {
3
+ file: string;
4
+ write(data: Uint8Array): Promise<void>;
5
+ }
6
+ export interface ScreenshotCapture {
7
+ file: string;
8
+ dpr: number;
9
+ width?: number | undefined;
10
+ height?: number | undefined;
11
+ }
12
+ export declare function captureViewport(cdp: CdpConnection, sessionId: string, target: ScreenshotTarget, signal?: AbortSignal): Promise<ScreenshotCapture>;
13
+ export declare function captureSelector(cdp: CdpConnection, sessionId: string, selector: string, target: ScreenshotTarget, signal?: AbortSignal): Promise<ScreenshotCapture>;
14
+ export declare function captureRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, target: ScreenshotTarget, signal?: AbortSignal): Promise<ScreenshotCapture>;
@@ -0,0 +1,2 @@
1
+ import type { CdpConnection } from "../types.ts";
2
+ export declare function selectorBackendNode(cdp: CdpConnection, sessionId: string, selector: string, signal?: AbortSignal): Promise<number>;
@@ -0,0 +1,3 @@
1
+ import type { CdpConnection, ElementRefs } from "../types.ts";
2
+ export declare function typeAtFocus(cdp: CdpConnection, sessionId: string, text: string, signal?: AbortSignal): Promise<string>;
3
+ export declare function typeRef(cdp: CdpConnection, sessionId: string, elementRefs: ElementRefs, id: number | string, text: string, signal?: AbortSignal): Promise<string>;
@@ -0,0 +1,9 @@
1
+ import type { CdpConnection } from "../types.ts";
2
+ export type WaitCondition = {
3
+ selector: string;
4
+ } | {
5
+ text: string;
6
+ } | {
7
+ url_includes: string;
8
+ };
9
+ export declare function waitForCondition(cdp: CdpConnection, sessionId: string, condition: WaitCondition, timeoutMs: number, signal?: AbortSignal): Promise<string>;