@omercnet/paseo-shared-browser 0.4.2-next.118.1 → 0.4.2-next.133.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.
- package/README.md +13 -29
- package/client/browser.tsx +15 -15
- package/index.client.tsx +1 -1
- package/index.server.ts +1 -1
- package/package.json +12 -14
- package/paseo-plugin.json +2 -5
- package/scripts/prepare-dependencies.mjs +46 -9
- package/scripts/prepare-runtime.mjs +18 -6
- package/server/agent-browser-runtime.ts +19 -30
- package/server/browser-policy.ts +10 -10
- package/server/browser.ts +5 -5
- package/server/cdp.ts +13 -3
- package/server/mcp-entry.ts +57 -15
- package/server/runtime-protocol.ts +33 -6
- package/server/supervisor-client.ts +4 -4
- package/server/supervisor.ts +4 -4
- package/shared/browser.ts +4 -1
package/README.md
CHANGED
|
@@ -72,24 +72,10 @@ paseo plugin install npm:@omercnet/paseo-shared-browser
|
|
|
72
72
|
paseo plugin ls
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
paseo plugin add omercnet/paseo-plugins:paseo-shared-browser
|
|
79
|
-
paseo plugin ls
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
Installation runs `npm ci --include=dev` and `npm run prepare:runtime` on the daemon host. The
|
|
83
|
-
preparation step installs the pinned browser runtime and builds both `supervisor.cjs` and
|
|
75
|
+
When Paseo acquires the npm package, it runs the `npm run prepare:runtime` build hook automatically. The
|
|
76
|
+
hook installs the pinned browser runtime and builds both `supervisor.cjs` and
|
|
84
77
|
`shared-browser-mcp.cjs` under
|
|
85
|
-
`$PASEO_HOME/plugin-data/shared-browser/runtime`.
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
cd paseo-plugins/paseo-shared-browser
|
|
89
|
-
npm ci --include=dev
|
|
90
|
-
npm run prepare:runtime
|
|
91
|
-
paseo plugin install "$PWD"
|
|
92
|
-
```
|
|
78
|
+
`$PASEO_HOME/plugin-data/shared-browser/runtime`.
|
|
93
79
|
|
|
94
80
|
The build requires Node.js 24 or newer and npm on the daemon host. On Linux x64, macOS, and
|
|
95
81
|
Windows, runtime preparation installs and stages the platform's Chrome for Testing distribution. On
|
|
@@ -175,23 +161,21 @@ User-supplied `AGENT_BROWSER_*` variables are deliberately ignored.
|
|
|
175
161
|
## Develop
|
|
176
162
|
|
|
177
163
|
```bash
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
paseo plugin install "$PWD"
|
|
185
|
-
paseo plugin reload shared-browser
|
|
164
|
+
bun install
|
|
165
|
+
bun run typecheck
|
|
166
|
+
bun run lint
|
|
167
|
+
bun run format:check
|
|
168
|
+
bun run test:unit
|
|
169
|
+
bun run prepare:runtime
|
|
186
170
|
```
|
|
187
171
|
|
|
188
|
-
`
|
|
172
|
+
`bun run test:smoke` launches the configured real Chromium runtime and exercises two viewers,
|
|
189
173
|
control handoff, reconnect, stale-frame rejection, viewport changes, device emulation, profile
|
|
190
174
|
persistence, and archive teardown.
|
|
191
175
|
|
|
192
176
|
Release Please maintains the version, changelog, component tag, and GitHub release from
|
|
193
177
|
Conventional Commits in the monorepo.
|
|
194
178
|
|
|
195
|
-
Both the Paseo daemon and app must satisfy
|
|
196
|
-
and
|
|
197
|
-
|
|
179
|
+
Both the Paseo daemon and app must satisfy `>=0.8.0 <0.10.0`, which supports Paseo 0.8
|
|
180
|
+
and Paseo 0.9. The client surface uses React Native primitives and works in desktop, web, iOS,
|
|
181
|
+
and Android Paseo clients.
|
package/client/browser.tsx
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
1
|
import {
|
|
3
2
|
type PluginClientContext,
|
|
4
3
|
type PluginWorkspacePanelProps,
|
|
5
4
|
useRpc,
|
|
6
5
|
} from "@getpaseo/plugin/client";
|
|
7
6
|
import { Icon, Modal, ScrollView, TextInput } from "@getpaseo/plugin/client/react-native";
|
|
8
|
-
import {
|
|
7
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
8
|
+
import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
9
9
|
import {
|
|
10
10
|
ActivityIndicator,
|
|
11
|
+
type GestureResponderEvent,
|
|
11
12
|
Image,
|
|
13
|
+
type LayoutChangeEvent,
|
|
12
14
|
PanResponder,
|
|
13
15
|
Pressable,
|
|
16
|
+
type StyleProp,
|
|
14
17
|
StyleSheet,
|
|
15
18
|
Text,
|
|
16
|
-
View,
|
|
17
|
-
type GestureResponderEvent,
|
|
18
|
-
type LayoutChangeEvent,
|
|
19
|
-
type StyleProp,
|
|
20
19
|
type TextInputProps,
|
|
21
20
|
type TextStyle,
|
|
21
|
+
View,
|
|
22
22
|
type ViewStyle,
|
|
23
23
|
} from "react-native";
|
|
24
24
|
import {
|
|
25
|
-
DEVICE_PRESETS,
|
|
26
|
-
MAX_VIEWPORT,
|
|
27
|
-
MIN_VIEWPORT,
|
|
28
25
|
acquireControlRpc,
|
|
29
26
|
applyDevicePresetRpc,
|
|
30
27
|
attachBrowserRpc,
|
|
28
|
+
type BrowserFrame,
|
|
29
|
+
type BrowserInputEvent,
|
|
30
|
+
type BrowserState,
|
|
31
31
|
captureBrowserRpc,
|
|
32
|
+
DEVICE_PRESETS,
|
|
33
|
+
type DevicePresetId,
|
|
32
34
|
detachBrowserRpc,
|
|
35
|
+
didBrowserRuntimeRestart,
|
|
36
|
+
isBrowserStateCurrent,
|
|
33
37
|
listOpenBrowserWorkspacesRpc,
|
|
38
|
+
MAX_VIEWPORT,
|
|
39
|
+
MIN_VIEWPORT,
|
|
34
40
|
navigateBrowserRpc,
|
|
35
41
|
releaseControlRpc,
|
|
36
42
|
resizeBrowserRpc,
|
|
37
43
|
sendBrowserInputRpc,
|
|
38
|
-
didBrowserRuntimeRestart,
|
|
39
|
-
isBrowserStateCurrent,
|
|
40
|
-
type BrowserFrame,
|
|
41
|
-
type BrowserInputEvent,
|
|
42
|
-
type BrowserState,
|
|
43
|
-
type DevicePresetId,
|
|
44
44
|
} from "../shared/browser";
|
|
45
45
|
|
|
46
46
|
const SPACE = {
|
package/index.client.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
-
import {
|
|
2
|
+
import { contributeSharedBrowserClient, SharedBrowserPanel } from "./client/browser";
|
|
3
3
|
|
|
4
4
|
export default function contribute(client: PluginClientContext) {
|
|
5
5
|
client.addWorkspacePanel({
|
package/index.server.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
1
|
import { randomBytes } from "node:crypto";
|
|
3
2
|
import { homedir } from "node:os";
|
|
4
3
|
import { join } from "node:path";
|
|
4
|
+
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
5
5
|
import {
|
|
6
6
|
bindAgentTicket,
|
|
7
7
|
cleanupBrowserServer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omercnet/paseo-shared-browser",
|
|
3
|
-
"version": "0.4.2-next.
|
|
3
|
+
"version": "0.4.2-next.133.1",
|
|
4
4
|
"description": "One real Chromium session per Paseo workspace, shared live across every connected client.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -38,37 +38,35 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
+
"check": "biome check .",
|
|
42
|
+
"check:write": "biome check --write .",
|
|
41
43
|
"typecheck": "tsc --noEmit",
|
|
42
|
-
"lint": "oxlint --deny-warnings .",
|
|
43
|
-
"format": "oxfmt --ignore-path .formatignore .",
|
|
44
|
-
"format:check": "oxfmt --check --ignore-path .formatignore .",
|
|
45
44
|
"prepare:runtime": "node scripts/prepare-runtime.mjs",
|
|
46
|
-
"test
|
|
45
|
+
"test": "vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/agent-access.test.ts",
|
|
46
|
+
"test:unit": "vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/agent-access.test.ts",
|
|
47
47
|
"test:smoke": "vitest run tests/browser.smoke.test.ts --testTimeout=30000"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@getpaseo/plugin": "0.
|
|
50
|
+
"@getpaseo/plugin": "0.9.0",
|
|
51
51
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
52
52
|
"agent-browser": "0.37.1",
|
|
53
53
|
"esbuild": "0.28.2",
|
|
54
54
|
"zod": "4.4.3"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@
|
|
58
|
-
"@tanstack/react-query": "^5.
|
|
59
|
-
"@types/node": "^
|
|
60
|
-
"@types/react": "
|
|
61
|
-
"oxfmt": "0.66.0",
|
|
62
|
-
"oxlint": "1.81.0",
|
|
57
|
+
"@biomejs/biome": "^2.5.10",
|
|
58
|
+
"@tanstack/react-query": "^5.102.3",
|
|
59
|
+
"@types/node": "^24.10.1",
|
|
60
|
+
"@types/react": "^19.2.18",
|
|
63
61
|
"react": "19.1.0",
|
|
64
62
|
"react-native": "0.81.5",
|
|
65
|
-
"typescript": "^7.0.
|
|
63
|
+
"typescript": "^7.0.2",
|
|
66
64
|
"vitest": "^5.0.0"
|
|
67
65
|
},
|
|
68
66
|
"engines": {
|
|
69
67
|
"node": ">=24"
|
|
70
68
|
},
|
|
71
|
-
"packageManager": "
|
|
69
|
+
"packageManager": "bun@1.4.2",
|
|
72
70
|
"allowScripts": {
|
|
73
71
|
"agent-browser": true,
|
|
74
72
|
"esbuild@0.28.2": true
|
package/paseo-plugin.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "shared-browser",
|
|
3
3
|
"requirements": {
|
|
4
|
-
"paseo": "
|
|
4
|
+
"paseo": ">=0.8.0 <0.10.0"
|
|
5
5
|
},
|
|
6
|
-
"build": [
|
|
7
|
-
["node", "scripts/prepare-dependencies.mjs"],
|
|
8
|
-
["npm", "run", "prepare:runtime"]
|
|
9
|
-
]
|
|
6
|
+
"build": [["node", "scripts/prepare-dependencies.mjs"], ["npm", "run", "prepare:runtime"]]
|
|
10
7
|
}
|
|
@@ -1,21 +1,58 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
|
|
7
7
|
const projectRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
8
8
|
|
|
9
|
+
function loadRootCatalog(root) {
|
|
10
|
+
for (let directory = root; ; directory = dirname(directory)) {
|
|
11
|
+
const manifestPath = join(directory, "package.json");
|
|
12
|
+
if (existsSync(manifestPath)) {
|
|
13
|
+
const catalog = JSON.parse(readFileSync(manifestPath, "utf8")).catalog;
|
|
14
|
+
if (catalog) return catalog;
|
|
15
|
+
}
|
|
16
|
+
if (directory === dirname(directory)) return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function stageManifest(root, catalog, install) {
|
|
21
|
+
const manifestPath = join(root, "package.json");
|
|
22
|
+
const source = readFileSync(manifestPath, "utf8");
|
|
23
|
+
const manifest = JSON.parse(source);
|
|
24
|
+
|
|
25
|
+
for (const [name, spec] of Object.entries(manifest.dependencies)) {
|
|
26
|
+
if (spec !== "catalog:") continue;
|
|
27
|
+
if (typeof catalog[name] !== "string") throw new Error(`Missing catalog entry for ${name}`);
|
|
28
|
+
manifest.dependencies[name] = catalog[name];
|
|
29
|
+
}
|
|
30
|
+
delete manifest.devDependencies;
|
|
31
|
+
|
|
32
|
+
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
33
|
+
try {
|
|
34
|
+
install();
|
|
35
|
+
} finally {
|
|
36
|
+
writeFileSync(manifestPath, source);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
9
40
|
export function resolveDependencyRoot(packageName, from = import.meta.url) {
|
|
10
|
-
|
|
11
|
-
return dirname(require.resolve(`${packageName}/package.json`));
|
|
41
|
+
return dirname(createRequire(from).resolve(`${packageName}/package.json`));
|
|
12
42
|
}
|
|
13
|
-
export function prepareDependencies(root = projectRoot, execute = execFileSync) {
|
|
14
|
-
if (!existsSync(join(root, "package-lock.json"))) return false;
|
|
15
43
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
44
|
+
export function prepareDependencies(root = projectRoot, execute = execFileSync) {
|
|
45
|
+
const catalog = loadRootCatalog(root);
|
|
46
|
+
if (!catalog) return false;
|
|
47
|
+
stageManifest(root, catalog, () => {
|
|
48
|
+
execute(
|
|
49
|
+
process.platform === "win32" ? "npm.cmd" : "npm",
|
|
50
|
+
["install", "--omit=dev", "--ignore-scripts", "--no-package-lock", "--workspaces=false"],
|
|
51
|
+
{
|
|
52
|
+
cwd: root,
|
|
53
|
+
stdio: "inherit",
|
|
54
|
+
},
|
|
55
|
+
);
|
|
19
56
|
});
|
|
20
57
|
return true;
|
|
21
58
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { resolveDependencyRoot } from "./prepare-dependencies.mjs";
|
|
2
|
-
import { build } from "esbuild";
|
|
3
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { constants } from "node:fs";
|
|
4
3
|
import {
|
|
5
4
|
access,
|
|
6
5
|
chmod,
|
|
@@ -13,11 +12,19 @@ import {
|
|
|
13
12
|
symlink,
|
|
14
13
|
writeFile,
|
|
15
14
|
} from "node:fs/promises";
|
|
16
|
-
import {
|
|
15
|
+
import { createRequire } from "node:module";
|
|
17
16
|
import { arch, homedir, platform, userInfo } from "node:os";
|
|
18
17
|
import { dirname, join, resolve } from "node:path";
|
|
19
|
-
import { promisify } from "node:util";
|
|
20
18
|
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { promisify } from "node:util";
|
|
20
|
+
import { build } from "esbuild";
|
|
21
|
+
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
|
|
24
|
+
function resolveDependencyRoot(packageName) {
|
|
25
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
26
|
+
return dirname(packageJsonPath);
|
|
27
|
+
}
|
|
21
28
|
|
|
22
29
|
const execFileAsync = promisify(execFile);
|
|
23
30
|
const expectedVersion = "0.37.1";
|
|
@@ -54,7 +61,9 @@ async function requireExecutable(path, label) {
|
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
async function validateAgentBrowser(path) {
|
|
57
|
-
const { stdout } = await execFileAsync(path, ["--version"], {
|
|
64
|
+
const { stdout } = await execFileAsync(path, ["--version"], {
|
|
65
|
+
encoding: "utf8",
|
|
66
|
+
});
|
|
58
67
|
const version = stdout.match(/\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?/)?.[0];
|
|
59
68
|
if (version !== expectedVersion) {
|
|
60
69
|
throw new Error(`Expected agent-browser ${expectedVersion}, received ${version ?? "unknown"}`);
|
|
@@ -185,7 +194,10 @@ async function installChromium() {
|
|
|
185
194
|
if (!releaseDir) throw new Error("agent-browser install did not produce a Chromium release");
|
|
186
195
|
const chrome = installedChromiumExecutable(releaseDir);
|
|
187
196
|
await requireExecutable(chrome, "Installed Chromium executable");
|
|
188
|
-
await cp(releaseDir, join(stagingRoot, "chromium"), {
|
|
197
|
+
await cp(releaseDir, join(stagingRoot, "chromium"), {
|
|
198
|
+
recursive: true,
|
|
199
|
+
force: true,
|
|
200
|
+
});
|
|
189
201
|
if (hostPlatform === "darwin") {
|
|
190
202
|
// chrome can't be a symlink to the .app's real binary here: macOS dyld
|
|
191
203
|
// resolves @executable_path from the invoked path's own directory, so a
|
|
@@ -3,14 +3,14 @@ import { chmod, mkdir, readFile, rm } from "node:fs/promises";
|
|
|
3
3
|
import { isAbsolute, resolve } from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import {
|
|
6
|
+
attachToTarget,
|
|
6
7
|
CdpConnection,
|
|
7
|
-
|
|
8
|
+
type CdpEvent,
|
|
9
|
+
type CdpSession,
|
|
10
|
+
type CdpTarget,
|
|
8
11
|
CdpUnavailableError,
|
|
9
12
|
CdpUnknownOutcomeError,
|
|
10
|
-
attachToTarget,
|
|
11
13
|
listPageTargets,
|
|
12
|
-
type CdpEvent,
|
|
13
|
-
type CdpTarget,
|
|
14
14
|
} from "./cdp";
|
|
15
15
|
|
|
16
16
|
const execFileAsync = promisify(execFile);
|
|
@@ -164,9 +164,7 @@ function parseJsonOutput(stdout: string): unknown {
|
|
|
164
164
|
for (const line of lines) {
|
|
165
165
|
try {
|
|
166
166
|
return JSON.parse(line);
|
|
167
|
-
} catch {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
167
|
+
} catch {}
|
|
170
168
|
}
|
|
171
169
|
throw new AgentBrowserIncompatibleError("agent-browser returned invalid JSON");
|
|
172
170
|
}
|
|
@@ -508,9 +506,7 @@ export class AgentBrowserRuntime {
|
|
|
508
506
|
|
|
509
507
|
async mouseMove(x: number, y: number): Promise<void> {
|
|
510
508
|
this.assertPoint(x, y);
|
|
511
|
-
await (
|
|
512
|
-
await this.requirePage()
|
|
513
|
-
).send(
|
|
509
|
+
await (await this.requirePage()).send(
|
|
514
510
|
"Input.dispatchMouseEvent",
|
|
515
511
|
{
|
|
516
512
|
type: "mouseMoved",
|
|
@@ -530,9 +526,7 @@ export class AgentBrowserRuntime {
|
|
|
530
526
|
clickCount = 1,
|
|
531
527
|
): Promise<void> {
|
|
532
528
|
this.assertPoint(x, y);
|
|
533
|
-
await (
|
|
534
|
-
await this.requirePage()
|
|
535
|
-
).send(
|
|
529
|
+
await (await this.requirePage()).send(
|
|
536
530
|
"Input.dispatchMouseEvent",
|
|
537
531
|
{
|
|
538
532
|
type: "mousePressed",
|
|
@@ -549,9 +543,7 @@ export class AgentBrowserRuntime {
|
|
|
549
543
|
|
|
550
544
|
async mouseUp(x: number, y: number, button: MouseButton = "left", clickCount = 1): Promise<void> {
|
|
551
545
|
this.assertPoint(x, y);
|
|
552
|
-
await (
|
|
553
|
-
await this.requirePage()
|
|
554
|
-
).send(
|
|
546
|
+
await (await this.requirePage()).send(
|
|
555
547
|
"Input.dispatchMouseEvent",
|
|
556
548
|
{
|
|
557
549
|
type: "mouseReleased",
|
|
@@ -568,9 +560,7 @@ export class AgentBrowserRuntime {
|
|
|
568
560
|
|
|
569
561
|
async wheel(x: number, y: number, deltaX: number, deltaY: number): Promise<void> {
|
|
570
562
|
this.assertPoint(x, y);
|
|
571
|
-
await (
|
|
572
|
-
await this.requirePage()
|
|
573
|
-
).send(
|
|
563
|
+
await (await this.requirePage()).send(
|
|
574
564
|
"Input.dispatchMouseEvent",
|
|
575
565
|
{
|
|
576
566
|
type: "mouseWheel",
|
|
@@ -590,9 +580,7 @@ export class AgentBrowserRuntime {
|
|
|
590
580
|
}
|
|
591
581
|
|
|
592
582
|
async keyDown(key: string, code = key): Promise<void> {
|
|
593
|
-
await (
|
|
594
|
-
await this.requirePage()
|
|
595
|
-
).send(
|
|
583
|
+
await (await this.requirePage()).send(
|
|
596
584
|
"Input.dispatchKeyEvent",
|
|
597
585
|
{
|
|
598
586
|
type: "keyDown",
|
|
@@ -606,9 +594,11 @@ export class AgentBrowserRuntime {
|
|
|
606
594
|
}
|
|
607
595
|
|
|
608
596
|
async keyUp(key: string, code = key): Promise<void> {
|
|
609
|
-
await (
|
|
610
|
-
|
|
611
|
-
|
|
597
|
+
await (await this.requirePage()).send(
|
|
598
|
+
"Input.dispatchKeyEvent",
|
|
599
|
+
{ type: "keyUp", key, code },
|
|
600
|
+
{ mutation: true },
|
|
601
|
+
);
|
|
612
602
|
this.heldKeys.delete(key);
|
|
613
603
|
}
|
|
614
604
|
|
|
@@ -617,9 +607,7 @@ export class AgentBrowserRuntime {
|
|
|
617
607
|
points: Array<{ x: number; y: number; id?: number }>,
|
|
618
608
|
): Promise<void> {
|
|
619
609
|
for (const point of points) this.assertPoint(point.x, point.y);
|
|
620
|
-
await (
|
|
621
|
-
await this.requirePage()
|
|
622
|
-
).send(
|
|
610
|
+
await (await this.requirePage()).send(
|
|
623
611
|
"Input.dispatchTouchEvent",
|
|
624
612
|
{
|
|
625
613
|
type,
|
|
@@ -681,9 +669,10 @@ export class AgentBrowserRuntime {
|
|
|
681
669
|
if (!force) {
|
|
682
670
|
try {
|
|
683
671
|
await this.invoke(["--session", this.session, "--json", "close"]);
|
|
684
|
-
} catch
|
|
672
|
+
} catch {
|
|
685
673
|
this.stopping = false;
|
|
686
|
-
|
|
674
|
+
await this.shutdown(true);
|
|
675
|
+
return;
|
|
687
676
|
}
|
|
688
677
|
} else {
|
|
689
678
|
const pid = await this.daemonPid();
|
package/server/browser-policy.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type { RpcInput } from "@getpaseo/plugin";
|
|
2
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
type applyDevicePresetRpc,
|
|
5
|
+
type BrowserFrame,
|
|
6
|
+
type BrowserInputEvent,
|
|
7
|
+
type BrowserState,
|
|
5
8
|
DEFAULT_VIEWPORT,
|
|
9
|
+
DEVICE_PRESETS,
|
|
10
|
+
type DevicePresetId,
|
|
6
11
|
FRAME_MAX_BYTES,
|
|
7
12
|
MAX_VIEWPORT,
|
|
8
13
|
MIN_VIEWPORT,
|
|
9
14
|
mapDisplayedPoint,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
sendBrowserInputRpc,
|
|
14
|
-
type BrowserFrame,
|
|
15
|
-
type BrowserInputEvent,
|
|
16
|
-
type BrowserState,
|
|
17
|
-
type DevicePresetId,
|
|
15
|
+
type navigateBrowserRpc,
|
|
16
|
+
type resizeBrowserRpc,
|
|
17
|
+
type sendBrowserInputRpc,
|
|
18
18
|
type Viewport,
|
|
19
19
|
} from "../shared/browser";
|
|
20
20
|
import type { JsonValue } from "./runtime-protocol";
|
package/server/browser.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
2
|
-
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
3
1
|
import { spawn } from "node:child_process";
|
|
4
2
|
import { randomUUID } from "node:crypto";
|
|
5
3
|
import { access } from "node:fs/promises";
|
|
6
4
|
import { homedir } from "node:os";
|
|
7
5
|
import { join } from "node:path";
|
|
8
|
-
import {
|
|
6
|
+
import type { RpcInput, RpcOutput } from "@getpaseo/plugin";
|
|
7
|
+
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
8
|
+
import type {
|
|
9
9
|
acquireControlRpc,
|
|
10
10
|
applyDevicePresetRpc,
|
|
11
11
|
attachBrowserRpc,
|
|
@@ -18,15 +18,15 @@ import {
|
|
|
18
18
|
sendBrowserInputRpc,
|
|
19
19
|
} from "../shared/browser";
|
|
20
20
|
import type { JsonValue } from "./runtime-protocol";
|
|
21
|
-
import { SupervisorClient } from "./supervisor-client";
|
|
22
21
|
import { resolveSupervisorPaths } from "./supervisor";
|
|
22
|
+
import { SupervisorClient } from "./supervisor-client";
|
|
23
23
|
|
|
24
|
-
export { SessionManager, normalizeBrowserUrl } from "./browser-policy";
|
|
25
24
|
export type {
|
|
26
25
|
BrowserRuntimeClient,
|
|
27
26
|
SessionManagerOptions,
|
|
28
27
|
WorkspaceValidator,
|
|
29
28
|
} from "./browser-policy";
|
|
29
|
+
export { normalizeBrowserUrl, SessionManager } from "./browser-policy";
|
|
30
30
|
|
|
31
31
|
type AttachInput = RpcInput<typeof attachBrowserRpc>;
|
|
32
32
|
type AttachOutput = RpcOutput<typeof attachBrowserRpc>;
|
package/server/cdp.ts
CHANGED
|
@@ -102,7 +102,11 @@ export class CdpConnection extends EventEmitter {
|
|
|
102
102
|
async send<T = unknown>(
|
|
103
103
|
method: string,
|
|
104
104
|
params: Record<string, unknown> = {},
|
|
105
|
-
options: {
|
|
105
|
+
options: {
|
|
106
|
+
sessionId?: string;
|
|
107
|
+
mutation?: boolean;
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
} = {},
|
|
106
110
|
): Promise<T> {
|
|
107
111
|
if (!this.isOpen) throw new CdpUnavailableError("CDP connection is closed");
|
|
108
112
|
const id = this.nextId++;
|
|
@@ -173,7 +177,10 @@ export class CdpConnection extends EventEmitter {
|
|
|
173
177
|
return;
|
|
174
178
|
}
|
|
175
179
|
if (message.method) {
|
|
176
|
-
const event: CdpEvent = {
|
|
180
|
+
const event: CdpEvent = {
|
|
181
|
+
method: message.method,
|
|
182
|
+
params: message.params ?? {},
|
|
183
|
+
};
|
|
177
184
|
if (message.sessionId) event.sessionId = message.sessionId;
|
|
178
185
|
this.emit("event", event);
|
|
179
186
|
this.emit(message.method, event.params, event.sessionId);
|
|
@@ -220,7 +227,10 @@ export class CdpSession extends EventEmitter {
|
|
|
220
227
|
params: Record<string, unknown> = {},
|
|
221
228
|
options: { mutation?: boolean; timeoutMs?: number } = {},
|
|
222
229
|
): Promise<T> {
|
|
223
|
-
return this.connection.send<T>(method, params, {
|
|
230
|
+
return this.connection.send<T>(method, params, {
|
|
231
|
+
...options,
|
|
232
|
+
sessionId: this.sessionId,
|
|
233
|
+
});
|
|
224
234
|
}
|
|
225
235
|
|
|
226
236
|
detach(): Promise<void> {
|
package/server/mcp-entry.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
1
|
import { homedir } from "node:os";
|
|
4
2
|
import { join } from "node:path";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import type { JsonValue } from "./runtime-protocol";
|
|
7
|
-
import { AgentSupervisorClient } from "./supervisor-client";
|
|
8
7
|
import { resolveSupervisorPaths } from "./supervisor";
|
|
8
|
+
import { AgentSupervisorClient } from "./supervisor-client";
|
|
9
9
|
|
|
10
10
|
const TICKET_ENV = "PASEO_SHARED_BROWSER_TICKET";
|
|
11
11
|
const MIN_VIEWPORT = { width: 320, height: 480 } as const;
|
|
@@ -71,7 +71,9 @@ function asObject(value: JsonValue): Record<string, JsonValue> {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
function textResult(value: JsonValue) {
|
|
74
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
content: [{ type: "text" as const, text: JSON.stringify(value, null, 2) }],
|
|
76
|
+
};
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
async function main(): Promise<void> {
|
|
@@ -83,7 +85,10 @@ async function main(): Promise<void> {
|
|
|
83
85
|
});
|
|
84
86
|
await client.open();
|
|
85
87
|
|
|
86
|
-
const server = new McpServer({
|
|
88
|
+
const server = new McpServer({
|
|
89
|
+
name: "paseo-shared-browser",
|
|
90
|
+
version: "0.2.2",
|
|
91
|
+
});
|
|
87
92
|
|
|
88
93
|
server.registerTool(
|
|
89
94
|
"shared_browser_status",
|
|
@@ -100,7 +105,9 @@ async function main(): Promise<void> {
|
|
|
100
105
|
{
|
|
101
106
|
description:
|
|
102
107
|
"Capture the current shared browser frame and state. Capture before sending input.",
|
|
103
|
-
inputSchema: z.object({
|
|
108
|
+
inputSchema: z.object({
|
|
109
|
+
quality: z.enum(["low", "medium", "high"]).default("medium"),
|
|
110
|
+
}),
|
|
104
111
|
annotations: { readOnlyHint: true, idempotentHint: true },
|
|
105
112
|
},
|
|
106
113
|
async ({ quality }) => {
|
|
@@ -113,7 +120,11 @@ async function main(): Promise<void> {
|
|
|
113
120
|
if (frame && typeof frame === "object" && !Array.isArray(frame)) {
|
|
114
121
|
const image = frame as Record<string, JsonValue>;
|
|
115
122
|
if (typeof image.dataBase64 === "string" && typeof image.mimeType === "string")
|
|
116
|
-
content.push({
|
|
123
|
+
content.push({
|
|
124
|
+
type: "image",
|
|
125
|
+
data: image.dataBase64,
|
|
126
|
+
mimeType: image.mimeType,
|
|
127
|
+
});
|
|
117
128
|
}
|
|
118
129
|
return { content };
|
|
119
130
|
},
|
|
@@ -125,7 +136,11 @@ async function main(): Promise<void> {
|
|
|
125
136
|
description:
|
|
126
137
|
"Acquire browser control if no human or other viewer currently holds it. Forced takeover is unavailable.",
|
|
127
138
|
inputSchema: z.object({}),
|
|
128
|
-
annotations: {
|
|
139
|
+
annotations: {
|
|
140
|
+
readOnlyHint: false,
|
|
141
|
+
destructiveHint: false,
|
|
142
|
+
idempotentHint: false,
|
|
143
|
+
},
|
|
129
144
|
},
|
|
130
145
|
async () => textResult(await client.request("acquire-control", {})),
|
|
131
146
|
);
|
|
@@ -135,7 +150,11 @@ async function main(): Promise<void> {
|
|
|
135
150
|
{
|
|
136
151
|
description: "Release this agent's browser control lease.",
|
|
137
152
|
inputSchema: z.object({}),
|
|
138
|
-
annotations: {
|
|
153
|
+
annotations: {
|
|
154
|
+
readOnlyHint: false,
|
|
155
|
+
destructiveHint: false,
|
|
156
|
+
idempotentHint: false,
|
|
157
|
+
},
|
|
139
158
|
},
|
|
140
159
|
async () => textResult(await client.request("release-control", {})),
|
|
141
160
|
);
|
|
@@ -145,16 +164,27 @@ async function main(): Promise<void> {
|
|
|
145
164
|
description: "Navigate the shared browser using the agent's current observed state.",
|
|
146
165
|
inputSchema: z.object({
|
|
147
166
|
action: z.discriminatedUnion("kind", [
|
|
148
|
-
z.object({
|
|
167
|
+
z.object({
|
|
168
|
+
kind: z.literal("goto"),
|
|
169
|
+
url: z.string().trim().min(1).max(8_192),
|
|
170
|
+
}),
|
|
149
171
|
z.object({ kind: z.literal("back") }),
|
|
150
172
|
z.object({ kind: z.literal("forward") }),
|
|
151
173
|
z.object({ kind: z.literal("reload") }),
|
|
152
174
|
]),
|
|
153
175
|
}),
|
|
154
|
-
annotations: {
|
|
176
|
+
annotations: {
|
|
177
|
+
readOnlyHint: false,
|
|
178
|
+
destructiveHint: false,
|
|
179
|
+
idempotentHint: false,
|
|
180
|
+
},
|
|
155
181
|
},
|
|
156
182
|
async ({ action }) =>
|
|
157
|
-
textResult(
|
|
183
|
+
textResult(
|
|
184
|
+
await client.request("navigate", {
|
|
185
|
+
action: action as unknown as JsonValue,
|
|
186
|
+
}),
|
|
187
|
+
),
|
|
158
188
|
);
|
|
159
189
|
|
|
160
190
|
server.registerTool(
|
|
@@ -163,7 +193,11 @@ async function main(): Promise<void> {
|
|
|
163
193
|
description:
|
|
164
194
|
"Send one input event using the exact frame returned by the latest capture. Stale frames are rejected.",
|
|
165
195
|
inputSchema: z.object({ event: inputEventSchema }),
|
|
166
|
-
annotations: {
|
|
196
|
+
annotations: {
|
|
197
|
+
readOnlyHint: false,
|
|
198
|
+
destructiveHint: false,
|
|
199
|
+
idempotentHint: false,
|
|
200
|
+
},
|
|
167
201
|
},
|
|
168
202
|
async ({ event }) =>
|
|
169
203
|
textResult(await client.request("input", { event: event as unknown as JsonValue })),
|
|
@@ -177,10 +211,18 @@ async function main(): Promise<void> {
|
|
|
177
211
|
width: z.number().int().min(MIN_VIEWPORT.width).max(MAX_VIEWPORT.width),
|
|
178
212
|
height: z.number().int().min(MIN_VIEWPORT.height).max(MAX_VIEWPORT.height),
|
|
179
213
|
}),
|
|
180
|
-
annotations: {
|
|
214
|
+
annotations: {
|
|
215
|
+
readOnlyHint: false,
|
|
216
|
+
destructiveHint: false,
|
|
217
|
+
idempotentHint: false,
|
|
218
|
+
},
|
|
181
219
|
},
|
|
182
220
|
async (viewport) =>
|
|
183
|
-
textResult(
|
|
221
|
+
textResult(
|
|
222
|
+
await client.request("viewport", {
|
|
223
|
+
viewport: viewport as unknown as JsonValue,
|
|
224
|
+
}),
|
|
225
|
+
),
|
|
184
226
|
);
|
|
185
227
|
|
|
186
228
|
const transport = new StdioServerTransport();
|
|
@@ -41,7 +41,11 @@ export type AgentBrowserOperation =
|
|
|
41
41
|
export type RuntimeRequest =
|
|
42
42
|
| (AdminRequestBase & { method: "bridge.claim"; takeover?: boolean })
|
|
43
43
|
| (AdminRequestBase & { method: "bridge.heartbeat"; epoch: number })
|
|
44
|
-
| (AdminRequestBase & {
|
|
44
|
+
| (AdminRequestBase & {
|
|
45
|
+
method: "workspace.ensure";
|
|
46
|
+
epoch: number;
|
|
47
|
+
workspaceId: string;
|
|
48
|
+
})
|
|
45
49
|
| (AdminRequestBase & {
|
|
46
50
|
method: "workspace.request";
|
|
47
51
|
epoch: number;
|
|
@@ -49,14 +53,22 @@ export type RuntimeRequest =
|
|
|
49
53
|
operation: string;
|
|
50
54
|
input: JsonValue;
|
|
51
55
|
})
|
|
52
|
-
| (AdminRequestBase & {
|
|
56
|
+
| (AdminRequestBase & {
|
|
57
|
+
method: "workspace.archive";
|
|
58
|
+
epoch: number;
|
|
59
|
+
workspaceId: string;
|
|
60
|
+
})
|
|
53
61
|
| (AdminRequestBase & {
|
|
54
62
|
method: "browser.request";
|
|
55
63
|
epoch: number;
|
|
56
64
|
operation: string;
|
|
57
65
|
input: JsonValue;
|
|
58
66
|
})
|
|
59
|
-
| (AdminRequestBase & {
|
|
67
|
+
| (AdminRequestBase & {
|
|
68
|
+
method: "ticket.issue";
|
|
69
|
+
epoch: number;
|
|
70
|
+
ticket: string;
|
|
71
|
+
})
|
|
60
72
|
| (AdminRequestBase & {
|
|
61
73
|
method: "ticket.bind";
|
|
62
74
|
epoch: number;
|
|
@@ -64,7 +76,11 @@ export type RuntimeRequest =
|
|
|
64
76
|
agentId: string;
|
|
65
77
|
workspaceId: string;
|
|
66
78
|
})
|
|
67
|
-
| (AdminRequestBase & {
|
|
79
|
+
| (AdminRequestBase & {
|
|
80
|
+
method: "agent.revoke";
|
|
81
|
+
epoch: number;
|
|
82
|
+
agentId: string;
|
|
83
|
+
})
|
|
68
84
|
| (RuntimeRequestBase & {
|
|
69
85
|
method: "agent.request";
|
|
70
86
|
ticket: string;
|
|
@@ -76,7 +92,11 @@ export type RuntimeResult = BridgeLease | RuntimeDescriptor | JsonValue | { arch
|
|
|
76
92
|
|
|
77
93
|
export type RuntimeResponse =
|
|
78
94
|
| { id: string; ok: true; result: RuntimeResult }
|
|
79
|
-
| {
|
|
95
|
+
| {
|
|
96
|
+
id: string;
|
|
97
|
+
ok: false;
|
|
98
|
+
error: { code: RuntimeErrorCode; message: string };
|
|
99
|
+
};
|
|
80
100
|
|
|
81
101
|
export type RuntimeErrorCode =
|
|
82
102
|
| "AUTHENTICATION_FAILED"
|
|
@@ -145,7 +165,14 @@ export function parseRuntimeRequest(value: unknown): RuntimeRequest {
|
|
|
145
165
|
};
|
|
146
166
|
const epoch = requireInteger(value, "epoch");
|
|
147
167
|
if (method === "bridge.heartbeat")
|
|
148
|
-
return {
|
|
168
|
+
return {
|
|
169
|
+
id,
|
|
170
|
+
version: RUNTIME_PROTOCOL_VERSION,
|
|
171
|
+
method,
|
|
172
|
+
token,
|
|
173
|
+
bridgeId,
|
|
174
|
+
epoch,
|
|
175
|
+
};
|
|
149
176
|
if (method === "workspace.ensure" || method === "workspace.archive")
|
|
150
177
|
return {
|
|
151
178
|
id,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { readFile, stat } from "node:fs/promises";
|
|
2
3
|
import { createConnection, type Socket } from "node:net";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
4
|
import {
|
|
5
|
-
RUNTIME_PROTOCOL_VERSION,
|
|
6
|
-
RuntimeProtocolError,
|
|
7
|
-
isRuntimeResponse,
|
|
8
5
|
type AgentBrowserOperation,
|
|
9
6
|
type BridgeLease,
|
|
7
|
+
isRuntimeResponse,
|
|
10
8
|
type JsonValue,
|
|
9
|
+
RUNTIME_PROTOCOL_VERSION,
|
|
11
10
|
type RuntimeDescriptor,
|
|
11
|
+
RuntimeProtocolError,
|
|
12
12
|
type RuntimeRequest,
|
|
13
13
|
type RuntimeResponse,
|
|
14
14
|
type RuntimeResult,
|
package/server/supervisor.ts
CHANGED
|
@@ -7,15 +7,15 @@ import type { BrowserFrame, BrowserInputEvent, BrowserState, Viewport } from "..
|
|
|
7
7
|
import { SessionManager } from "./browser-policy";
|
|
8
8
|
import { CdpUnknownOutcomeError } from "./cdp";
|
|
9
9
|
import {
|
|
10
|
+
type BridgeLease,
|
|
10
11
|
DEFAULT_BRIDGE_HEARTBEAT_MS,
|
|
11
12
|
DEFAULT_BRIDGE_TIMEOUT_MS,
|
|
12
13
|
DEFAULT_ORPHAN_GRACE_MS,
|
|
13
|
-
RUNTIME_PROTOCOL_VERSION,
|
|
14
|
-
RuntimeProtocolError,
|
|
15
|
-
parseRuntimeRequest,
|
|
16
|
-
type BridgeLease,
|
|
17
14
|
type JsonValue,
|
|
15
|
+
parseRuntimeRequest,
|
|
16
|
+
RUNTIME_PROTOCOL_VERSION,
|
|
18
17
|
type RuntimeDescriptor,
|
|
18
|
+
RuntimeProtocolError,
|
|
19
19
|
type RuntimeRequest,
|
|
20
20
|
type RuntimeResponse,
|
|
21
21
|
type RuntimeResult,
|
package/shared/browser.ts
CHANGED
|
@@ -206,7 +206,10 @@ export const navigateBrowserRpc = defineRpc({
|
|
|
206
206
|
controlToken: opaqueTokenSchema,
|
|
207
207
|
expected: expectedStateSchema,
|
|
208
208
|
action: z.discriminatedUnion("kind", [
|
|
209
|
-
z.object({
|
|
209
|
+
z.object({
|
|
210
|
+
kind: z.literal("goto"),
|
|
211
|
+
url: z.string().trim().min(1).max(8_192),
|
|
212
|
+
}),
|
|
210
213
|
z.object({ kind: z.literal("back") }),
|
|
211
214
|
z.object({ kind: z.literal("forward") }),
|
|
212
215
|
z.object({ kind: z.literal("reload") }),
|