@omercnet/paseo-shared-browser 0.4.2-next.129.1 → 0.4.2-next.145.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 CHANGED
@@ -72,24 +72,10 @@ paseo plugin install npm:@omercnet/paseo-shared-browser
72
72
  paseo plugin ls
73
73
  ```
74
74
 
75
- Or install from Git:
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`. For a local monorepo checkout:
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
- npm ci
179
- npm run typecheck
180
- npm run lint
181
- npm run format:check
182
- npm run test:unit
183
- npm run prepare:runtime
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
- `npm run test:smoke` launches the configured real Chromium runtime and exercises two viewers,
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 `^0.8.0 || ^0.9.0-beta.1`, which supports Paseo 0.8
196
- and the Paseo 0.9 beta line. The client surface uses React Native primitives and works in desktop,
197
- web, iOS, and Android Paseo clients.
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.
@@ -72,6 +72,7 @@ const CAPTURE_INTERVAL_READY = 250;
72
72
  const CAPTURE_INTERVAL_WAITING = 1_500;
73
73
  const MAX_VIEWER_LABEL_LENGTH = 64;
74
74
  const PILL_PRESENCE_POLL_MS = 2_000;
75
+ const AGENT_DIRECTORY_PAGE_LIMIT = 200;
75
76
  const MAX_URL_LENGTH = 8_192;
76
77
  const MAX_TEXT_LENGTH = 4_000;
77
78
  const BYTES_PER_KIBIBYTE = 1_024;
@@ -803,18 +804,33 @@ function CanvasPlaceholder({
803
804
  );
804
805
  }
805
806
 
807
+ interface AgentDirectoryPage {
808
+ entries: Array<{ agent: { id: string; workspaceId?: string | undefined } }>;
809
+ pageInfo: { hasMore: boolean; nextCursor: string | null };
810
+ }
811
+
812
+ type AgentDirectoryUpdate =
813
+ | { kind: "remove"; agentId: string }
814
+ | { kind: "upsert"; agent: { id: string; workspaceId?: string | undefined } };
815
+ type AgentPlacement = { id: string; workspaceId: string };
816
+
806
817
  export function contributeSharedBrowserClient(client: PluginClientContext) {
807
- const agents = new Map<string, { id: string; workspaceId: string }>();
818
+ const agents = new Map<string, AgentPlacement>();
808
819
  const pills = new Map<string, { workspaceId: string; remove: () => void }>();
820
+ const lifetime = new AbortController();
809
821
  let openWorkspaceIds = new Set<string>();
810
822
  let refreshing = false;
811
823
  let stopped = false;
824
+ let directoryGeneration = 0;
825
+ let pendingDirectory: { generation: number; updates: AgentDirectoryUpdate[] } | null = null;
826
+ let unsubscribeDirectory: (() => void) | null = null;
827
+ let releaseDirectory: (() => Promise<void>) | null = null;
812
828
 
813
829
  const removePill = (agentId: string) => {
814
830
  pills.get(agentId)?.remove();
815
831
  pills.delete(agentId);
816
832
  };
817
- const syncPill = (agent: { id: string; workspaceId: string }) => {
833
+ const syncPill = (agent: AgentPlacement) => {
818
834
  const current = pills.get(agent.id);
819
835
  if (!openWorkspaceIds.has(agent.workspaceId)) {
820
836
  removePill(agent.id);
@@ -858,32 +874,94 @@ export function contributeSharedBrowserClient(client: PluginClientContext) {
858
874
  refreshing = false;
859
875
  }
860
876
  };
861
-
862
- const unsubscribe = client.paseo.agents.subscribe((update) => {
877
+ const applyUpdate = (target: Map<string, AgentPlacement>, update: AgentDirectoryUpdate) => {
878
+ if (update.kind === "remove") {
879
+ target.delete(update.agentId);
880
+ return;
881
+ }
882
+ const { id, workspaceId } = update.agent;
883
+ if (workspaceId) target.set(id, { id, workspaceId });
884
+ else target.delete(id);
885
+ };
886
+ const applyLiveUpdate = (update: AgentDirectoryUpdate) => {
887
+ if (stopped) return;
888
+ pendingDirectory?.updates.push(update);
889
+ applyUpdate(agents, update);
863
890
  if (update.kind === "remove") {
864
- agents.delete(update.agentId);
865
891
  removePill(update.agentId);
866
892
  return;
867
893
  }
868
894
  const { id, workspaceId } = update.agent;
869
895
  if (!workspaceId) {
870
- agents.delete(id);
871
896
  removePill(id);
872
897
  return;
873
898
  }
874
- const agent = { id, workspaceId };
875
- agents.set(id, agent);
876
- syncPill(agent);
899
+ syncPill({ id, workspaceId });
877
900
  void refreshPresence();
878
- });
879
- void client.paseo.agents
880
- .list()
881
- .then(async ({ entries }) => {
882
- for (const { agent } of entries) {
883
- if (agent.workspaceId)
884
- agents.set(agent.id, { id: agent.id, workspaceId: agent.workspaceId });
901
+ };
902
+ const replaceAgents = (next: Map<string, AgentPlacement>) => {
903
+ for (const agentId of agents.keys()) {
904
+ if (!next.has(agentId)) removePill(agentId);
905
+ }
906
+ agents.clear();
907
+ for (const [agentId, agent] of next) agents.set(agentId, agent);
908
+ syncAllPills();
909
+ };
910
+ const followSnapshot = async (snapshot: AgentDirectoryPage) => {
911
+ if (stopped) return;
912
+ const generation = ++directoryGeneration;
913
+ const transaction = { generation, updates: [] as AgentDirectoryUpdate[] };
914
+ pendingDirectory = transaction;
915
+ const next = new Map<string, AgentPlacement>();
916
+ for (const { agent } of snapshot.entries) {
917
+ if (agent.workspaceId) next.set(agent.id, { id: agent.id, workspaceId: agent.workspaceId });
918
+ }
919
+
920
+ try {
921
+ let cursor = snapshot.pageInfo.hasMore ? snapshot.pageInfo.nextCursor : null;
922
+ while (cursor) {
923
+ const page = await client.paseo.agents.list({
924
+ scope: "active",
925
+ page: { limit: AGENT_DIRECTORY_PAGE_LIMIT, cursor },
926
+ signal: lifetime.signal,
927
+ });
928
+ if (stopped || pendingDirectory?.generation !== generation) return;
929
+ for (const { agent } of page.entries) {
930
+ if (agent.workspaceId)
931
+ next.set(agent.id, { id: agent.id, workspaceId: agent.workspaceId });
932
+ }
933
+ cursor = page.pageInfo.hasMore ? page.pageInfo.nextCursor : null;
885
934
  }
935
+ if (stopped || pendingDirectory?.generation !== generation) return;
936
+ for (const update of transaction.updates) applyUpdate(next, update);
937
+ pendingDirectory = null;
938
+ replaceAgents(next);
886
939
  await refreshPresence();
940
+ } catch {
941
+ if (!stopped && pendingDirectory?.generation === generation) pendingDirectory = null;
942
+ }
943
+ };
944
+
945
+ void client.paseo.agents
946
+ .list({
947
+ scope: "active",
948
+ page: { limit: AGENT_DIRECTORY_PAGE_LIMIT },
949
+ subscribe: {},
950
+ signal: lifetime.signal,
951
+ })
952
+ .then(({ subscription }) => {
953
+ if (stopped) {
954
+ void subscription.release().catch(() => undefined);
955
+ return undefined;
956
+ }
957
+ releaseDirectory = subscription.release;
958
+ unsubscribeDirectory = subscription.subscribe({
959
+ snapshot: (snapshot) => void followSnapshot(snapshot),
960
+ update: (message) => {
961
+ if (message.type === "agent_update") applyLiveUpdate(message.payload);
962
+ },
963
+ });
964
+ return undefined;
887
965
  })
888
966
  .catch(() => undefined);
889
967
  const presenceTimer = setInterval(() => void refreshPresence(), PILL_PRESENCE_POLL_MS);
@@ -891,8 +969,12 @@ export function contributeSharedBrowserClient(client: PluginClientContext) {
891
969
  return () => {
892
970
  if (stopped) return;
893
971
  stopped = true;
972
+ directoryGeneration += 1;
973
+ pendingDirectory = null;
894
974
  clearInterval(presenceTimer);
895
- unsubscribe();
975
+ unsubscribeDirectory?.();
976
+ void releaseDirectory?.().catch(() => undefined);
977
+ lifetime.abort();
896
978
  for (const { remove } of pills.values()) remove();
897
979
  pills.clear();
898
980
  agents.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-shared-browser",
3
- "version": "0.4.2-next.129.1",
3
+ "version": "0.4.2-next.145.1",
4
4
  "description": "One real Chromium session per Paseo workspace, shared live across every connected client.",
5
5
  "keywords": [
6
6
  "browser",
@@ -38,40 +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
44
  "prepare:runtime": "node scripts/prepare-runtime.mjs",
43
- "test:unit": "node --test scripts/prepare-dependencies.test.mjs && vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/agent-access.test.ts",
44
- "test:smoke": "vitest run tests/browser.smoke.test.ts --testTimeout=30000",
45
- "check": "biome check --error-on-warnings .",
46
- "check:write": "biome check --write .",
47
- "test": "run-s test:ci:*",
48
- "test:ci:unit": "npm run test:unit",
49
- "build": "node ../.github/scripts/build-plugin.mjs"
45
+ "test": "vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/agent-access.test.ts tests/composer-pills.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 tests/composer-pills.test.ts",
47
+ "test:smoke": "vitest run tests/browser.smoke.test.ts --testTimeout=30000"
50
48
  },
51
49
  "dependencies": {
52
- "@getpaseo/plugin": "0.8.0",
50
+ "@getpaseo/plugin": "0.9.0",
53
51
  "@modelcontextprotocol/sdk": "1.30.0",
54
52
  "agent-browser": "0.37.1",
55
53
  "esbuild": "0.28.2",
56
54
  "zod": "4.4.3"
57
55
  },
58
56
  "devDependencies": {
59
- "@biomejs/biome": "^2.5.14",
60
- "@getpaseo/plugin": "0.9.0-beta.1",
61
- "@getpaseo/server": "0.9.0-beta.1",
62
- "@tanstack/react-query": "^5.90.11",
63
- "@types/node": "^22.0.0",
64
- "@types/react": "~19.2.0",
65
- "npm-run-all2": "^9.0.3",
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",
66
61
  "react": "19.1.0",
67
62
  "react-native": "0.81.5",
68
- "typescript": "^7.0.0",
63
+ "typescript": "^7.0.2",
69
64
  "vitest": "^5.0.0"
70
65
  },
71
66
  "engines": {
72
67
  "node": ">=24"
73
68
  },
74
- "packageManager": "npm@11.19.1",
69
+ "packageManager": "bun@1.4.2",
75
70
  "allowScripts": {
76
71
  "agent-browser": true,
77
72
  "esbuild@0.28.2": true
package/paseo-plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "shared-browser",
3
3
  "requirements": {
4
- "paseo": "^0.8.0 || ^0.9.0-beta.1"
4
+ "paseo": ">=0.9.0 <0.10.0"
5
5
  },
6
6
  "build": [["node", "scripts/prepare-dependencies.mjs"], ["npm", "run", "prepare:runtime"]]
7
7
  }
@@ -1,21 +1,58 @@
1
1
  import { execFileSync } from "node:child_process";
2
- import { existsSync } from "node:fs";
2
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
3
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
- const require = createRequire(from);
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
- execute(process.platform === "win32" ? "npm.cmd" : "npm", ["ci", "--include=dev"], {
17
- cwd: root,
18
- stdio: "inherit",
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
  }
@@ -12,12 +12,19 @@ import {
12
12
  symlink,
13
13
  writeFile,
14
14
  } from "node:fs/promises";
15
+ import { createRequire } from "node:module";
15
16
  import { arch, homedir, platform, userInfo } from "node:os";
16
17
  import { dirname, join, resolve } from "node:path";
17
18
  import { fileURLToPath } from "node:url";
18
19
  import { promisify } from "node:util";
19
20
  import { build } from "esbuild";
20
- import { resolveDependencyRoot } from "./prepare-dependencies.mjs";
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"], { encoding: "utf8" });
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"), { recursive: true, force: true });
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
@@ -93,6 +93,7 @@ export interface AgentBrowserRuntimeOptions {
93
93
  ipcDirectory: string;
94
94
  session: string;
95
95
  initialUrl?: string;
96
+ headed?: boolean;
96
97
  timeoutMs?: number;
97
98
  }
98
99
 
@@ -189,6 +190,7 @@ export class AgentBrowserRuntime {
189
190
  readonly ipcDirectory: string;
190
191
  readonly session: string;
191
192
  private readonly initialUrl: string;
193
+ private readonly headed: boolean;
192
194
  private readonly timeoutMs: number;
193
195
  private readonly environment: NodeJS.ProcessEnv;
194
196
  private connection: CdpConnection | null = null;
@@ -212,6 +214,7 @@ export class AgentBrowserRuntime {
212
214
  throw new AgentBrowserIncompatibleError("agent-browser session name is invalid");
213
215
  }
214
216
  this.session = options.session;
217
+ this.headed = options.headed ?? false;
215
218
  this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
216
219
  this.environment = runtimeEnvironment(this.ipcDirectory);
217
220
  this.initialUrl = options.initialUrl ?? "about:blank";
@@ -236,6 +239,7 @@ export class AgentBrowserRuntime {
236
239
  this.profilePath,
237
240
  "--executable-path",
238
241
  this.executablePath,
242
+ ...(this.headed ? ["--headed"] : []),
239
243
  ...(chromiumArguments ? ["--args", chromiumArguments] : []),
240
244
  "--json",
241
245
  "open",
@@ -669,9 +673,10 @@ export class AgentBrowserRuntime {
669
673
  if (!force) {
670
674
  try {
671
675
  await this.invoke(["--session", this.session, "--json", "close"]);
672
- } catch (error) {
676
+ } catch {
673
677
  this.stopping = false;
674
- throw error;
678
+ await this.shutdown(true);
679
+ return;
675
680
  }
676
681
  } else {
677
682
  const pid = await this.daemonPid();
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: { sessionId?: string; mutation?: boolean; timeoutMs?: number } = {},
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 = { method: message.method, params: message.params ?? {} };
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, { ...options, sessionId: this.sessionId });
230
+ return this.connection.send<T>(method, params, {
231
+ ...options,
232
+ sessionId: this.sessionId,
233
+ });
224
234
  }
225
235
 
226
236
  detach(): Promise<void> {
@@ -71,7 +71,9 @@ function asObject(value: JsonValue): Record<string, JsonValue> {
71
71
  }
72
72
 
73
73
  function textResult(value: JsonValue) {
74
- return { content: [{ type: "text" as const, text: JSON.stringify(value, null, 2) }] };
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({ name: "paseo-shared-browser", version: "0.2.2" });
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({ quality: z.enum(["low", "medium", "high"]).default("medium") }),
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({ type: "image", data: image.dataBase64, mimeType: image.mimeType });
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: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
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: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
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({ kind: z.literal("goto"), url: z.string().trim().min(1).max(8_192) }),
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: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
176
+ annotations: {
177
+ readOnlyHint: false,
178
+ destructiveHint: false,
179
+ idempotentHint: false,
180
+ },
155
181
  },
156
182
  async ({ action }) =>
157
- textResult(await client.request("navigate", { action: action as unknown as JsonValue })),
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: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
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: { readOnlyHint: false, destructiveHint: false, idempotentHint: false },
214
+ annotations: {
215
+ readOnlyHint: false,
216
+ destructiveHint: false,
217
+ idempotentHint: false,
218
+ },
181
219
  },
182
220
  async (viewport) =>
183
- textResult(await client.request("viewport", { viewport: viewport as unknown as JsonValue })),
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();
@@ -11,12 +11,18 @@ interface OwnedRuntime {
11
11
  runtimeId: string;
12
12
  runtime: AgentBrowserRuntime;
13
13
  }
14
+ interface RuntimeOwnerOptions {
15
+ initialUrl?: string;
16
+ headed?: boolean;
17
+ }
14
18
 
15
19
  function paseoHome(): string {
16
20
  return process.env.PASEO_HOME ?? join(homedir(), ".paseo");
17
21
  }
18
22
 
19
- export async function createRuntimeOwner(): Promise<RuntimeOwner<OwnedRuntime>> {
23
+ export async function createRuntimeOwner(
24
+ options: RuntimeOwnerOptions = {},
25
+ ): Promise<RuntimeOwner<OwnedRuntime>> {
20
26
  const root = join(paseoHome(), "plugin-data", "shared-browser");
21
27
  const ipcDirectory =
22
28
  process.platform === "win32"
@@ -46,7 +52,8 @@ export async function createRuntimeOwner(): Promise<RuntimeOwner<OwnedRuntime>>
46
52
  profilePath: join(root, "profiles", hash),
47
53
  ipcDirectory,
48
54
  session: `ws-${hash.slice(0, 16)}`,
49
- initialUrl: DEFAULT_BROWSER_URL,
55
+ initialUrl: options.initialUrl ?? DEFAULT_BROWSER_URL,
56
+ headed: options.headed ?? false,
50
57
  });
51
58
  await runtime.launch();
52
59
  return { runtimeId: randomUUID(), runtime };
@@ -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 & { method: "workspace.ensure"; epoch: number; workspaceId: string })
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 & { method: "workspace.archive"; epoch: number; workspaceId: string })
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 & { method: "ticket.issue"; epoch: number; ticket: string })
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 & { method: "agent.revoke"; epoch: number; agentId: string })
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
- | { id: string; ok: false; error: { code: RuntimeErrorCode; message: string } };
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 { id, version: RUNTIME_PROTOCOL_VERSION, method, token, bridgeId, epoch };
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,
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({ kind: z.literal("goto"), url: z.string().trim().min(1).max(8_192) }),
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") }),