@omercnet/paseo-shared-browser 4.1.12 → 4.2.0
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/OVERVIEW.md +1 -1
- package/README.md +40 -2
- package/client/agent-access-settings.tsx +157 -0
- package/client/browser-canvas-keyboard-web.test.ts +185 -2
- package/client/browser-canvas-keyboard-web.ts +48 -8
- package/client/browser-input-queue.test.ts +32 -0
- package/client/browser-input-queue.ts +12 -0
- package/index.client.tsx +8 -0
- package/index.server.ts +145 -29
- package/npm-shrinkwrap.json +41 -37
- package/package.json +5 -5
- package/paseo-plugin.json +1 -1
- package/server/supervisor.ts +28 -0
- package/server/workspace-list.ts +42 -0
- package/shared/agent-access.ts +204 -0
package/index.server.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
PluginHookContext,
|
|
6
|
+
PluginServerContext,
|
|
7
|
+
PluginSessionOpenRequest,
|
|
8
|
+
} from "@getpaseo/plugin/server";
|
|
5
9
|
import {
|
|
6
10
|
bindAgentTicket,
|
|
7
11
|
cleanupBrowserServer,
|
|
@@ -33,6 +37,14 @@ import {
|
|
|
33
37
|
revokeAgentBrowserAccess,
|
|
34
38
|
} from "./server/browser";
|
|
35
39
|
import { resolveBrowserRuntimeRoot } from "./server/runtime-path";
|
|
40
|
+
import { listAllWorkspaces } from "./server/workspace-list";
|
|
41
|
+
import {
|
|
42
|
+
accessFromState,
|
|
43
|
+
agentAccessSettings,
|
|
44
|
+
agentGetsBrowser,
|
|
45
|
+
agentGetsBrowserByLabel,
|
|
46
|
+
DEFAULT_AGENT_ACCESS,
|
|
47
|
+
} from "./shared/agent-access";
|
|
36
48
|
import {
|
|
37
49
|
acquireControlRpc,
|
|
38
50
|
applyDevicePresetRpc,
|
|
@@ -63,25 +75,34 @@ import { readBrowserVideoRpc } from "./shared/browser-video";
|
|
|
63
75
|
const TICKET_ENV = "PASEO_SHARED_BROWSER_TICKET";
|
|
64
76
|
const MCP_SERVER_ID = "shared-browser";
|
|
65
77
|
const TICKET_ISSUE_TIMEOUT_MS = 2_000;
|
|
78
|
+
const ACCESS_DECISION_TIMEOUT_MS = 2_000;
|
|
66
79
|
|
|
67
|
-
|
|
80
|
+
/** The result of `work`, or a rejection when it has not settled within `ms`. */
|
|
81
|
+
async function withinDeadline<T>(work: Promise<T>, ms: number, message: string): Promise<T> {
|
|
68
82
|
let timer: NodeJS.Timeout | undefined;
|
|
69
83
|
try {
|
|
70
|
-
await Promise.race([
|
|
71
|
-
|
|
84
|
+
return await Promise.race([
|
|
85
|
+
work,
|
|
72
86
|
new Promise<never>((_, reject) => {
|
|
73
|
-
timer = setTimeout(
|
|
74
|
-
() => reject(new Error("Shared Browser ticket issuance timed out")),
|
|
75
|
-
TICKET_ISSUE_TIMEOUT_MS,
|
|
76
|
-
);
|
|
87
|
+
timer = setTimeout(() => reject(new Error(message)), ms);
|
|
77
88
|
timer.unref();
|
|
78
89
|
}),
|
|
79
90
|
]);
|
|
91
|
+
} finally {
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function issueTicketWithinDeadline(ticket: string): Promise<boolean> {
|
|
97
|
+
try {
|
|
98
|
+
await withinDeadline(
|
|
99
|
+
issueAgentTicket(ticket),
|
|
100
|
+
TICKET_ISSUE_TIMEOUT_MS,
|
|
101
|
+
"Shared Browser ticket issuance timed out",
|
|
102
|
+
);
|
|
80
103
|
return true;
|
|
81
104
|
} catch {
|
|
82
105
|
return false;
|
|
83
|
-
} finally {
|
|
84
|
-
clearTimeout(timer);
|
|
85
106
|
}
|
|
86
107
|
}
|
|
87
108
|
|
|
@@ -93,8 +114,67 @@ function mcpBundlePath(): string {
|
|
|
93
114
|
return join(resolveBrowserRuntimeRoot(paseoHome()), "shared-browser-mcp.cjs");
|
|
94
115
|
}
|
|
95
116
|
|
|
117
|
+
/** Fields of the session-open request that only newer Paseo releases send. */
|
|
118
|
+
interface OptionalOpenFields {
|
|
119
|
+
labels?: Readonly<Record<string, string>>;
|
|
120
|
+
background?: boolean;
|
|
121
|
+
mcpServers?: Record<string, unknown>;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The stdio server entry that runs the browser adapter for one ticket. */
|
|
125
|
+
function browserMcpServer(ticket: string) {
|
|
126
|
+
return {
|
|
127
|
+
type: "stdio" as const,
|
|
128
|
+
command: process.execPath,
|
|
129
|
+
args: [mcpBundlePath()],
|
|
130
|
+
env: { PASEO_HOME: paseoHome(), [TICKET_ENV]: ticket, ELECTRON_RUN_AS_NODE: "1" },
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
96
134
|
export default function contribute(server: PluginServerContext) {
|
|
97
135
|
server.registerSettings(browserDisplayPreferences);
|
|
136
|
+
const agentAccess = server.registerSettings(agentAccessSettings);
|
|
137
|
+
// The deadline covers the settings read alone: a setting that cannot be read in time is an unreadable
|
|
138
|
+
// setting, and that falls back to the default (every new agent).
|
|
139
|
+
// `quiet` is for the session-open path, which runs on every open: the fallback is still taken, without a log line each time.
|
|
140
|
+
const readAccess = async (quiet = false) => {
|
|
141
|
+
try {
|
|
142
|
+
const state = await withinDeadline(
|
|
143
|
+
Promise.resolve(agentAccess.read()),
|
|
144
|
+
ACCESS_DECISION_TIMEOUT_MS,
|
|
145
|
+
"the read timed out",
|
|
146
|
+
);
|
|
147
|
+
const access = accessFromState(state);
|
|
148
|
+
if (access === DEFAULT_AGENT_ACCESS && !quiet) {
|
|
149
|
+
console.warn(
|
|
150
|
+
`shared-browser: the agent-access setting is ${state?.status ?? "missing"}; every new agent gets the browser tool`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return access;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!quiet) {
|
|
156
|
+
console.warn(
|
|
157
|
+
`shared-browser: the agent-access setting could not be read (${error instanceof Error ? error.message : "error"}); every new agent gets the browser tool`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return DEFAULT_AGENT_ACCESS;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
// The workspace lookup has its own deadline; a timeout or any other failure there is no match.
|
|
164
|
+
const lookupWorkspaces = async (paseo: PluginHookContext["paseo"]) => {
|
|
165
|
+
try {
|
|
166
|
+
return await withinDeadline(
|
|
167
|
+
listAllWorkspaces(paseo),
|
|
168
|
+
ACCESS_DECISION_TIMEOUT_MS,
|
|
169
|
+
"the workspace lookup timed out",
|
|
170
|
+
);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.warn(
|
|
173
|
+
`shared-browser: the workspace lookup failed (${error instanceof Error ? error.message : "error"}); the agent is not matched to a workspace or project`,
|
|
174
|
+
);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
98
178
|
server.handle(attachBrowserRpc, handleAttachBrowser);
|
|
99
179
|
server.handle(detachBrowserRpc, handleDetachBrowser);
|
|
100
180
|
server.handle(closeBrowserRpc, handleCloseBrowser);
|
|
@@ -118,8 +198,13 @@ export default function contribute(server: PluginServerContext) {
|
|
|
118
198
|
server.handle(resizeBrowserRpc, handleResizeBrowser);
|
|
119
199
|
server.handle(applyDevicePresetRpc, handleApplyDevicePreset);
|
|
120
200
|
server.handle(sendBrowserInputRpc, handleSendBrowserInput);
|
|
121
|
-
server.before("agent.create", async ({ request }) => {
|
|
201
|
+
server.before("agent.create", async ({ request }, context) => {
|
|
122
202
|
if (request.config.internal) return request;
|
|
203
|
+
// Decide before any ticket or supervisor work, so an agent that is not allowed costs nothing.
|
|
204
|
+
const allowed = await agentGetsBrowser(await readAccess(), request.config, () =>
|
|
205
|
+
lookupWorkspaces(context.paseo),
|
|
206
|
+
);
|
|
207
|
+
if (!allowed) return request;
|
|
123
208
|
const ticket = randomBytes(32).toString("base64url");
|
|
124
209
|
if (!(await issueTicketWithinDeadline(ticket))) return request;
|
|
125
210
|
return {
|
|
@@ -127,32 +212,63 @@ export default function contribute(server: PluginServerContext) {
|
|
|
127
212
|
env: { ...request.env, [TICKET_ENV]: ticket },
|
|
128
213
|
config: {
|
|
129
214
|
...request.config,
|
|
130
|
-
mcpServers: {
|
|
131
|
-
...request.config.mcpServers,
|
|
132
|
-
[MCP_SERVER_ID]: {
|
|
133
|
-
type: "stdio",
|
|
134
|
-
command: process.execPath,
|
|
135
|
-
args: [mcpBundlePath()],
|
|
136
|
-
env: {
|
|
137
|
-
PASEO_HOME: paseoHome(),
|
|
138
|
-
[TICKET_ENV]: ticket,
|
|
139
|
-
ELECTRON_RUN_AS_NODE: "1",
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
215
|
+
mcpServers: { ...request.config.mcpServers, [MCP_SERVER_ID]: browserMcpServer(ticket) },
|
|
143
216
|
},
|
|
144
217
|
};
|
|
145
218
|
});
|
|
146
219
|
|
|
147
220
|
server.before("agent.session_open", async ({ request }) => {
|
|
148
|
-
if (request.reason !== "create") return request;
|
|
149
221
|
const ticket = request.env[TICKET_ENV];
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
222
|
+
if (request.reason === "create" && ticket) {
|
|
223
|
+
if (request.purpose !== "interactive" || !request.workspaceId) return request;
|
|
224
|
+
await bindAgentTicket(ticket, request.agentId, request.workspaceId);
|
|
225
|
+
const { [TICKET_ENV]: _ticket, ...environment } = request.env;
|
|
226
|
+
return { ...request, env: environment };
|
|
227
|
+
}
|
|
228
|
+
// The env ticket is the only signal that the create hook already stored the server on this agent: the host sends
|
|
229
|
+
// mcpServers as {} to out-of-process plugins, so that field says nothing about what is stored.
|
|
230
|
+
if (ticket) return request;
|
|
231
|
+
return injectByLabel(request);
|
|
154
232
|
});
|
|
155
233
|
|
|
234
|
+
// Labels are on the session-open request but not on agent.create, so an agent chosen by label is handled here, in every
|
|
235
|
+
// interactive session of an agent that carries a matching label: a server returned from this hook lasts for that session
|
|
236
|
+
// only (unlike one added in agent.create, which is stored on the agent), so each open issues and binds a fresh ticket.
|
|
237
|
+
// Agents that gave no label, helpers, and sessions without a workspace are returned at once. Nothing here throws: a
|
|
238
|
+
// failure leaves the session without the tool instead of failing it.
|
|
239
|
+
const injectByLabel = async (request: PluginSessionOpenRequest) => {
|
|
240
|
+
// Older Paseo releases (0.13) do not send labels, a background flag or MCP servers on this request, so this does nothing there.
|
|
241
|
+
const { labels, background, mcpServers } = request as PluginSessionOpenRequest &
|
|
242
|
+
OptionalOpenFields;
|
|
243
|
+
if (request.purpose !== "interactive" || background === true || !request.workspaceId)
|
|
244
|
+
return request;
|
|
245
|
+
if (!labels || Object.keys(labels).length === 0) return request;
|
|
246
|
+
if (!agentGetsBrowserByLabel(await readAccess(true), labels)) return request;
|
|
247
|
+
const ticket = randomBytes(32).toString("base64url");
|
|
248
|
+
if (!(await issueTicketWithinDeadline(ticket))) {
|
|
249
|
+
console.warn(
|
|
250
|
+
"shared-browser: could not issue a browser ticket for a labelled agent; the session opens without it",
|
|
251
|
+
);
|
|
252
|
+
return request;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
await withinDeadline(
|
|
256
|
+
bindAgentTicket(ticket, request.agentId, request.workspaceId),
|
|
257
|
+
TICKET_ISSUE_TIMEOUT_MS,
|
|
258
|
+
"Shared Browser ticket binding timed out",
|
|
259
|
+
);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.warn(
|
|
262
|
+
`shared-browser: could not bind the browser ticket for a labelled agent (${error instanceof Error ? error.message : "error"}); the session opens without it`,
|
|
263
|
+
);
|
|
264
|
+
return request;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
...request,
|
|
268
|
+
mcpServers: { ...mcpServers, [MCP_SERVER_ID]: browserMcpServer(ticket) },
|
|
269
|
+
} as PluginSessionOpenRequest;
|
|
270
|
+
};
|
|
271
|
+
|
|
156
272
|
server.on("agent.archived", ({ agent }) => revokeAgentBrowserAccess(agent.id));
|
|
157
273
|
|
|
158
274
|
server.on("workspace.archived", ({ workspace }) => handleWorkspaceArchived(workspace.id));
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omercnet/paseo-shared-browser",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@omercnet/paseo-shared-browser",
|
|
9
|
-
"version": "4.
|
|
9
|
+
"version": "4.2.0",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@getpaseo/plugin": "0.
|
|
11
|
+
"@getpaseo/plugin": "0.17.0-beta.1",
|
|
12
12
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
13
13
|
"agent-browser": "0.43.0",
|
|
14
14
|
"esbuild": "0.28.2",
|
|
@@ -545,22 +545,22 @@
|
|
|
545
545
|
}
|
|
546
546
|
},
|
|
547
547
|
"node_modules/@getpaseo/client": {
|
|
548
|
-
"version": "0.
|
|
549
|
-
"resolved": "https://registry.npmjs.org/@getpaseo/client/-/client-0.
|
|
550
|
-
"integrity": "sha512
|
|
548
|
+
"version": "0.17.0-beta.1",
|
|
549
|
+
"resolved": "https://registry.npmjs.org/@getpaseo/client/-/client-0.17.0-beta.1.tgz",
|
|
550
|
+
"integrity": "sha512-+/1vctpcgVVCIRkcHxrVUxqhwbwOdHNhzb2sMjOXFXpcZqONishS4Z3ikR3U4E3U0WZM/nh0GbewZ9HEHjNFMQ==",
|
|
551
551
|
"license": "Apache-2.0",
|
|
552
552
|
"peer": true,
|
|
553
553
|
"dependencies": {
|
|
554
|
-
"@getpaseo/protocol": "0.
|
|
555
|
-
"@getpaseo/relay": "0.
|
|
554
|
+
"@getpaseo/protocol": "0.17.0-beta.1",
|
|
555
|
+
"@getpaseo/relay": "0.17.0-beta.1",
|
|
556
556
|
"ws": "^8.20.0",
|
|
557
557
|
"zod": "^4.4.3"
|
|
558
558
|
}
|
|
559
559
|
},
|
|
560
560
|
"node_modules/@getpaseo/plugin": {
|
|
561
|
-
"version": "0.
|
|
562
|
-
"resolved": "https://registry.npmjs.org/@getpaseo/plugin/-/plugin-0.
|
|
563
|
-
"integrity": "sha512-
|
|
561
|
+
"version": "0.17.0-beta.1",
|
|
562
|
+
"resolved": "https://registry.npmjs.org/@getpaseo/plugin/-/plugin-0.17.0-beta.1.tgz",
|
|
563
|
+
"integrity": "sha512-1tU0f/1wGSRtYVv2cyCyjOAHUomE0XTFcR2MSEdT7Iyxv94q6NEK0tb53Qygt7d7lv/kVHU3G9AlFdoHxd9fXw==",
|
|
564
564
|
"license": "Apache-2.0",
|
|
565
565
|
"dependencies": {
|
|
566
566
|
"@agentclientprotocol/sdk": "^1.4.0",
|
|
@@ -568,8 +568,8 @@
|
|
|
568
568
|
"use-sync-external-store": "^1.6.0"
|
|
569
569
|
},
|
|
570
570
|
"peerDependencies": {
|
|
571
|
-
"@getpaseo/client": "0.
|
|
572
|
-
"@getpaseo/protocol": "0.
|
|
571
|
+
"@getpaseo/client": "0.17.0-beta.1",
|
|
572
|
+
"@getpaseo/protocol": "0.17.0-beta.1",
|
|
573
573
|
"react": ">=19.1.0 <20",
|
|
574
574
|
"react-native": ">=0.81.5",
|
|
575
575
|
"zod": "^4.4.3"
|
|
@@ -581,9 +581,9 @@
|
|
|
581
581
|
}
|
|
582
582
|
},
|
|
583
583
|
"node_modules/@getpaseo/protocol": {
|
|
584
|
-
"version": "0.
|
|
585
|
-
"resolved": "https://registry.npmjs.org/@getpaseo/protocol/-/protocol-0.
|
|
586
|
-
"integrity": "sha512-
|
|
584
|
+
"version": "0.17.0-beta.1",
|
|
585
|
+
"resolved": "https://registry.npmjs.org/@getpaseo/protocol/-/protocol-0.17.0-beta.1.tgz",
|
|
586
|
+
"integrity": "sha512-vCb+WV944xEvuat4I4jQMRa5UX1bwkEe2QJF2RjPnSrkywt0WqwK69E7R5WYMRWIdM6lZ7rlK8jeh5oMgaZjew==",
|
|
587
587
|
"license": "Apache-2.0",
|
|
588
588
|
"peer": true,
|
|
589
589
|
"dependencies": {
|
|
@@ -592,9 +592,9 @@
|
|
|
592
592
|
}
|
|
593
593
|
},
|
|
594
594
|
"node_modules/@getpaseo/relay": {
|
|
595
|
-
"version": "0.
|
|
596
|
-
"resolved": "https://registry.npmjs.org/@getpaseo/relay/-/relay-0.
|
|
597
|
-
"integrity": "sha512-
|
|
595
|
+
"version": "0.17.0-beta.1",
|
|
596
|
+
"resolved": "https://registry.npmjs.org/@getpaseo/relay/-/relay-0.17.0-beta.1.tgz",
|
|
597
|
+
"integrity": "sha512-jEQB8jxkEJtA7w9ez4RrFbp7xmE8VHLkhHieP9PgBAVThNaERtqbgVnkTBjCle7ZpaQhq/eippZYsDK28U5c0w==",
|
|
598
598
|
"license": "Apache-2.0",
|
|
599
599
|
"peer": true,
|
|
600
600
|
"dependencies": {
|
|
@@ -607,9 +607,9 @@
|
|
|
607
607
|
}
|
|
608
608
|
},
|
|
609
609
|
"node_modules/@hono/node-server": {
|
|
610
|
-
"version": "2.1.
|
|
611
|
-
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.
|
|
612
|
-
"integrity": "sha512-
|
|
610
|
+
"version": "2.1.11",
|
|
611
|
+
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.11.tgz",
|
|
612
|
+
"integrity": "sha512-KzKz9vl4vvr1vgLHamj+g5uonbrj5NwAdO3yzOS6cd2HjALVeOgTgeZOyAzNxejbkfOOPIcvuf/Tg8l1pEFLog==",
|
|
613
613
|
"license": "MIT",
|
|
614
614
|
"engines": {
|
|
615
615
|
"node": ">=20"
|
|
@@ -1145,9 +1145,9 @@
|
|
|
1145
1145
|
}
|
|
1146
1146
|
},
|
|
1147
1147
|
"node_modules/express-rate-limit": {
|
|
1148
|
-
"version": "8.7.
|
|
1149
|
-
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.
|
|
1150
|
-
"integrity": "sha512-
|
|
1148
|
+
"version": "8.7.5",
|
|
1149
|
+
"resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.5.tgz",
|
|
1150
|
+
"integrity": "sha512-wi+v38cx2EqD0JnhE/e74o5tFqKWUOAPFJIgyEiqJ8v2MNpoOAA3kI2hXYOI+YM+HE5yqbdAlVxm2GqOIeYOgA==",
|
|
1151
1151
|
"license": "MIT",
|
|
1152
1152
|
"dependencies": {
|
|
1153
1153
|
"debug": "^4.4.3",
|
|
@@ -1320,9 +1320,9 @@
|
|
|
1320
1320
|
}
|
|
1321
1321
|
},
|
|
1322
1322
|
"node_modules/hono": {
|
|
1323
|
-
"version": "4.13.
|
|
1324
|
-
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.
|
|
1325
|
-
"integrity": "sha512-
|
|
1323
|
+
"version": "4.13.19",
|
|
1324
|
+
"resolved": "https://registry.npmjs.org/hono/-/hono-4.13.19.tgz",
|
|
1325
|
+
"integrity": "sha512-KmXvQAXwcAHV+muzbIwoJ23niEB5nMoDVr9WcRkU8mvjUECm/1+7v4Jgp7P7a+H6MLFrh+vXrGonGrGS+RQfkA==",
|
|
1326
1326
|
"license": "MIT",
|
|
1327
1327
|
"engines": {
|
|
1328
1328
|
"node": ">=16.9.0"
|
|
@@ -1429,9 +1429,9 @@
|
|
|
1429
1429
|
"license": "ISC"
|
|
1430
1430
|
},
|
|
1431
1431
|
"node_modules/jose": {
|
|
1432
|
-
"version": "6.2.
|
|
1433
|
-
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.
|
|
1434
|
-
"integrity": "sha512-
|
|
1432
|
+
"version": "6.2.18",
|
|
1433
|
+
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.18.tgz",
|
|
1434
|
+
"integrity": "sha512-doV4thUwgkrycJH4yLeqwTGIIZphHl+pk7CPReuMIhYhncmgzdko85MaCG4YQFTxqMFr1/oEH32tZuKKovcDEg==",
|
|
1435
1435
|
"license": "MIT",
|
|
1436
1436
|
"funding": {
|
|
1437
1437
|
"url": "https://github.com/sponsors/panva"
|
|
@@ -1553,9 +1553,9 @@
|
|
|
1553
1553
|
}
|
|
1554
1554
|
},
|
|
1555
1555
|
"node_modules/object-inspect": {
|
|
1556
|
-
"version": "1.
|
|
1557
|
-
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.
|
|
1558
|
-
"integrity": "sha512-
|
|
1556
|
+
"version": "1.14.0",
|
|
1557
|
+
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.14.0.tgz",
|
|
1558
|
+
"integrity": "sha512-IVgHNlp/jwQX271+Xzoq9LZNTWXxZK+cEOrGBOBxXNbn7fapnZ+Ts6TVMgNOuAezwG2wdtnMX97tTPK6VEnuOQ==",
|
|
1559
1559
|
"license": "MIT",
|
|
1560
1560
|
"engines": {
|
|
1561
1561
|
"node": ">= 0.4"
|
|
@@ -1707,9 +1707,9 @@
|
|
|
1707
1707
|
}
|
|
1708
1708
|
},
|
|
1709
1709
|
"node_modules/router": {
|
|
1710
|
-
"version": "2.
|
|
1711
|
-
"resolved": "https://registry.npmjs.org/router/-/router-2.
|
|
1712
|
-
"integrity": "sha512-
|
|
1710
|
+
"version": "2.3.0",
|
|
1711
|
+
"resolved": "https://registry.npmjs.org/router/-/router-2.3.0.tgz",
|
|
1712
|
+
"integrity": "sha512-bpowRfGjEPe8t9R6fJIzhwmyCGAXwKvxBUsgJm+bJukwdcWmUXbMo7p22w7aYmQBPQTUMNqMV39YX0kMou3z8w==",
|
|
1713
1713
|
"license": "MIT",
|
|
1714
1714
|
"dependencies": {
|
|
1715
1715
|
"debug": "^4.4.0",
|
|
@@ -1720,6 +1720,10 @@
|
|
|
1720
1720
|
},
|
|
1721
1721
|
"engines": {
|
|
1722
1722
|
"node": ">= 18"
|
|
1723
|
+
},
|
|
1724
|
+
"funding": {
|
|
1725
|
+
"type": "opencollective",
|
|
1726
|
+
"url": "https://opencollective.com/express"
|
|
1723
1727
|
}
|
|
1724
1728
|
},
|
|
1725
1729
|
"node_modules/safer-buffer": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omercnet/paseo-shared-browser",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "One real Chromium session per Paseo workspace, shared live across every connected client.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"browser",
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"check:write": "biome check --write .",
|
|
51
51
|
"typecheck": "tsc --noEmit",
|
|
52
52
|
"prepare:runtime": "node scripts/prepare-runtime.mjs",
|
|
53
|
-
"test": "vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/chromium-release.test.ts tests/prepare-runtime.test.ts tests/agent-access.test.ts tests/agent-input-safety.test.ts tests/tabs.test.ts tests/tabs-runtime-loss.test.ts tests/composer-pills.test.ts tests/sidebar.test.ts tests/pointer-mapping.test.ts tests/frame-lifecycle.test.ts tests/viewport-resync.test.ts client server shared",
|
|
54
|
-
"test:unit": "vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/chromium-release.test.ts tests/prepare-runtime.test.ts tests/agent-access.test.ts tests/agent-input-safety.test.ts tests/tabs.test.ts tests/tabs-runtime-loss.test.ts tests/composer-pills.test.ts tests/sidebar.test.ts tests/pointer-mapping.test.ts tests/frame-lifecycle.test.ts tests/viewport-resync.test.ts client server shared",
|
|
53
|
+
"test": "vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/chromium-release.test.ts tests/prepare-runtime.test.ts tests/agent-access.test.ts tests/agent-filter.test.ts tests/workspace-list.test.ts tests/agent-input-safety.test.ts tests/tabs.test.ts tests/tabs-runtime-loss.test.ts tests/composer-pills.test.ts tests/sidebar.test.ts tests/pointer-mapping.test.ts tests/frame-lifecycle.test.ts tests/viewport-resync.test.ts client server shared",
|
|
54
|
+
"test:unit": "vitest run tests/contracts.test.ts tests/lease.test.ts tests/runtime-lifecycle.test.ts tests/chromium-release.test.ts tests/prepare-runtime.test.ts tests/agent-access.test.ts tests/agent-filter.test.ts tests/workspace-list.test.ts tests/agent-input-safety.test.ts tests/tabs.test.ts tests/tabs-runtime-loss.test.ts tests/composer-pills.test.ts tests/sidebar.test.ts tests/pointer-mapping.test.ts tests/frame-lifecycle.test.ts tests/viewport-resync.test.ts client server shared",
|
|
55
55
|
"test:smoke": "vitest run tests/browser.smoke.test.ts tests/browser.drag-cancel.smoke.test.ts tests/xvfb.smoke.test.ts tests/browser.failed-open.smoke.test.ts tests/browser.background-tab.smoke.test.ts --testTimeout=30000",
|
|
56
56
|
"test:tabs": "vitest run tests/browser-tabs.smoke.test.ts --testTimeout=30000",
|
|
57
57
|
"test:video": "vitest run tests/video.smoke.test.ts --testTimeout=30000"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@getpaseo/plugin": "0.
|
|
60
|
+
"@getpaseo/plugin": "0.17.0-beta.1",
|
|
61
61
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
62
62
|
"agent-browser": "0.43.0",
|
|
63
63
|
"esbuild": "0.28.2",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@biomejs/biome": "^2.5.10",
|
|
68
|
-
"@getpaseo/server": "0.
|
|
68
|
+
"@getpaseo/server": "0.17.0-beta.1",
|
|
69
69
|
"@tanstack/react-query": "^5.102.3",
|
|
70
70
|
"@types/node": "^24.10.1",
|
|
71
71
|
"@types/react": "^19.2.18",
|
package/paseo-plugin.json
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"id": "shared-browser",
|
|
3
3
|
"description": "One real Chromium session per Paseo workspace, shared live across every connected client.",
|
|
4
4
|
"icon": "icon.png",
|
|
5
|
-
"requirements": { "paseo": "^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0" },
|
|
5
|
+
"requirements": { "paseo": "^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0" },
|
|
6
6
|
"build": [["node", "scripts/prepare-dependencies.mjs"], ["npm", "run", "prepare:runtime"]]
|
|
7
7
|
}
|
package/server/supervisor.ts
CHANGED
|
@@ -57,6 +57,14 @@ const MAX_GLOBAL_MEDIA_IN_FLIGHT = 48;
|
|
|
57
57
|
const MAX_HEARTBEATS_IN_FLIGHT = 1;
|
|
58
58
|
const AGENT_TICKET_TTL_MS = 10 * 60_000;
|
|
59
59
|
const MAX_UNBOUND_AGENT_TICKETS = 256;
|
|
60
|
+
// A session-open hook issues and then binds a ticket in two requests, so an agent archived between them must not
|
|
61
|
+
// get a ticket bound after its revocation took its snapshot. Revocation records the agent with the last ticket
|
|
62
|
+
// sequence number issued so far, and a later bind of any ticket at or below that number is refused; tickets issued
|
|
63
|
+
// afterwards (the agent was restored) bind normally. A record is kept as long as an unbound ticket could still be
|
|
64
|
+
// older than it, which is the unbound ticket lifetime.
|
|
65
|
+
// Every interactive open of a label-selected agent binds a fresh ticket, so one agent keeps at most this many; the
|
|
66
|
+
// oldest is dropped first.
|
|
67
|
+
const MAX_BOUND_TICKETS_PER_AGENT = 8;
|
|
60
68
|
type SupervisorTimer = NodeJS.Timeout;
|
|
61
69
|
|
|
62
70
|
export interface RuntimeInstance {
|
|
@@ -101,6 +109,7 @@ interface ActiveBridge {
|
|
|
101
109
|
|
|
102
110
|
interface AgentBinding {
|
|
103
111
|
issuedAt: number;
|
|
112
|
+
seq: number;
|
|
104
113
|
ticket: string;
|
|
105
114
|
agentId: string | null;
|
|
106
115
|
workspaceId: string | null;
|
|
@@ -138,6 +147,8 @@ export class RuntimeSupervisor<Runtime extends RuntimeInstance = RuntimeInstance
|
|
|
138
147
|
private readonly agentRequestContext = new AsyncLocalStorage<AgentPublicationContext>();
|
|
139
148
|
private readonly agentBindings = new Map<string, AgentBinding>();
|
|
140
149
|
private readonly agentTickets = new Map<string, Set<string>>();
|
|
150
|
+
private readonly revokedAgents = new Map<string, { ticketSeq: number; at: number }>();
|
|
151
|
+
private ticketSeq = 0;
|
|
141
152
|
private activeBridge: ActiveBridge | null = null;
|
|
142
153
|
private nextEpoch = 0;
|
|
143
154
|
private bridgeTimer: SupervisorTimer | null = null;
|
|
@@ -605,6 +616,7 @@ export class RuntimeSupervisor<Runtime extends RuntimeInstance = RuntimeInstance
|
|
|
605
616
|
this.agentBindings.set(ticket, {
|
|
606
617
|
ticket,
|
|
607
618
|
issuedAt: this.now(),
|
|
619
|
+
seq: ++this.ticketSeq,
|
|
608
620
|
agentId: null,
|
|
609
621
|
workspaceId: null,
|
|
610
622
|
tabId: null,
|
|
@@ -631,6 +643,11 @@ export class RuntimeSupervisor<Runtime extends RuntimeInstance = RuntimeInstance
|
|
|
631
643
|
if (this.archived.has(workspaceId)) this.workspaceArchived(workspaceId);
|
|
632
644
|
if (binding.agentId && (binding.agentId !== agentId || binding.workspaceId !== workspaceId))
|
|
633
645
|
throw new RuntimeProtocolError("AUTHENTICATION_FAILED", "Agent ticket is already bound");
|
|
646
|
+
const revoked = this.revokedAgents.get(agentId);
|
|
647
|
+
if (revoked && binding.seq <= revoked.ticketSeq) {
|
|
648
|
+
this.agentBindings.delete(ticket);
|
|
649
|
+
throw new RuntimeProtocolError("AUTHENTICATION_FAILED", "Agent was revoked");
|
|
650
|
+
}
|
|
634
651
|
binding.agentId = agentId;
|
|
635
652
|
binding.workspaceId = workspaceId;
|
|
636
653
|
let tickets = this.agentTickets.get(agentId);
|
|
@@ -639,11 +656,20 @@ export class RuntimeSupervisor<Runtime extends RuntimeInstance = RuntimeInstance
|
|
|
639
656
|
this.agentTickets.set(agentId, tickets);
|
|
640
657
|
}
|
|
641
658
|
tickets.add(ticket);
|
|
659
|
+
for (const oldest of tickets) {
|
|
660
|
+
if (tickets.size <= MAX_BOUND_TICKETS_PER_AGENT) break;
|
|
661
|
+
tickets.delete(oldest);
|
|
662
|
+
const dropped = this.agentBindings.get(oldest);
|
|
663
|
+
this.agentBindings.delete(oldest);
|
|
664
|
+
console.warn("[shared-browser] agent ticket cap reached; dropped the oldest bound ticket");
|
|
665
|
+
if (dropped?.viewerToken) void this.browserPolicy.detach(dropped.viewerToken).catch(() => {});
|
|
666
|
+
}
|
|
642
667
|
return { bound: true };
|
|
643
668
|
}
|
|
644
669
|
|
|
645
670
|
private async revokeAgent(bridgeId: string, epoch: number, agentId: string): Promise<JsonValue> {
|
|
646
671
|
this.assertActiveBridge(bridgeId, epoch);
|
|
672
|
+
this.revokedAgents.set(agentId, { ticketSeq: this.ticketSeq, at: this.now() });
|
|
647
673
|
const tickets = this.agentTickets.get(agentId);
|
|
648
674
|
if (!tickets) return { revoked: 0 };
|
|
649
675
|
const viewers: string[] = [];
|
|
@@ -1166,6 +1192,8 @@ export class RuntimeSupervisor<Runtime extends RuntimeInstance = RuntimeInstance
|
|
|
1166
1192
|
for (const [ticket, binding] of this.agentBindings)
|
|
1167
1193
|
if (binding.agentId === null && binding.issuedAt <= deadline)
|
|
1168
1194
|
this.agentBindings.delete(ticket);
|
|
1195
|
+
for (const [agentId, revoked] of this.revokedAgents)
|
|
1196
|
+
if (revoked.at <= deadline) this.revokedAgents.delete(agentId);
|
|
1169
1197
|
}
|
|
1170
1198
|
|
|
1171
1199
|
private armBridgeTimeout(bridge: ActiveBridge): void {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { WorkspaceRef } from "../shared/agent-access";
|
|
2
|
+
|
|
3
|
+
export const WORKSPACE_PAGE_SIZE = 200;
|
|
4
|
+
export const WORKSPACE_PAGE_LIMIT = 20;
|
|
5
|
+
|
|
6
|
+
interface WorkspacePage {
|
|
7
|
+
entries: readonly WorkspaceRef[];
|
|
8
|
+
pageInfo: { nextCursor?: string | null; hasMore: boolean };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface WorkspaceLister {
|
|
12
|
+
workspaces: {
|
|
13
|
+
list(options: {
|
|
14
|
+
filter: { includeBackground: true };
|
|
15
|
+
page: { limit: number; cursor?: string };
|
|
16
|
+
}): Promise<WorkspacePage>;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Every workspace the daemon knows, background ones included. An access decision made from a partial
|
|
22
|
+
* list could match a shallower workspace than the agent is really in, so a list that is still
|
|
23
|
+
* incomplete after the page limit is an error, and the caller counts it as a failed lookup.
|
|
24
|
+
*/
|
|
25
|
+
export async function listAllWorkspaces(
|
|
26
|
+
paseo: WorkspaceLister,
|
|
27
|
+
pageLimit: number = WORKSPACE_PAGE_LIMIT,
|
|
28
|
+
): Promise<WorkspaceRef[]> {
|
|
29
|
+
const workspaces: WorkspaceRef[] = [];
|
|
30
|
+
let cursor: string | undefined;
|
|
31
|
+
for (let page = 0; page < pageLimit; page += 1) {
|
|
32
|
+
const result = await paseo.workspaces.list({
|
|
33
|
+
filter: { includeBackground: true },
|
|
34
|
+
page: { limit: WORKSPACE_PAGE_SIZE, ...(cursor ? { cursor } : {}) },
|
|
35
|
+
});
|
|
36
|
+
workspaces.push(...result.entries);
|
|
37
|
+
if (!result.pageInfo.hasMore) return workspaces;
|
|
38
|
+
cursor = result.pageInfo.nextCursor ?? undefined;
|
|
39
|
+
if (!cursor) throw new Error("Workspace list reports more pages but gave no cursor");
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Workspace list is longer than ${pageLimit} pages`);
|
|
42
|
+
}
|