@omercnet/paseo-shared-browser 4.1.12-next.513.1 → 4.1.12-next.516.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 +23 -5
- package/client/agent-access-settings.tsx +17 -3
- package/index.server.ts +80 -24
- package/package.json +1 -1
- package/server/supervisor.ts +27 -0
- package/shared/agent-access.ts +41 -3
package/README.md
CHANGED
|
@@ -135,7 +135,8 @@ jumps to the chosen workspace's browser panel.
|
|
|
135
135
|
|
|
136
136
|
The plugin automatically injects its stdio MCP adapter only when a new, non-internal agent is
|
|
137
137
|
created with a provider that accepts external MCP servers. Agents that already exist, resumed
|
|
138
|
-
sessions, imported sessions, and Paseo's internal agents are not modified
|
|
138
|
+
sessions, imported sessions, and Paseo's internal agents are not modified (the one exception is the labels list under
|
|
139
|
+
"listed" mode, which is applied at every interactive session open, resumed sessions included). Paseo's built-in OMP
|
|
139
140
|
provider accepts session MCP servers, so new OMP agents receive the adapter.
|
|
140
141
|
Pi agents also receive the adapter, but require Pi's optional MCP support to
|
|
141
142
|
launch it.
|
|
@@ -163,19 +164,36 @@ By default every new agent gets the adapter. Settings, under Shared Browser, can
|
|
|
163
164
|
|
|
164
165
|
- **Every new agent** (the default) injects the adapter into every new agent, as above.
|
|
165
166
|
- **Only the agents listed** injects it only into a new agent whose provider id is listed, or whose
|
|
166
|
-
workspace id or project id is listed
|
|
167
|
-
configuration means no agent.
|
|
167
|
+
workspace id or project id is listed, and into any agent that carries a listed label (below).
|
|
168
|
+
Separate entries with commas or new lines. An empty configuration means no agent.
|
|
169
|
+
|
|
170
|
+
**Labels.** An entry is a label key (`team`: any agent with that label) or `key=value` (`team=blue`:
|
|
171
|
+
that label with exactly that value). Matching is exact and case-sensitive. Labels are not on the
|
|
172
|
+
`agent.create` request, only on the session-open request, so this is decided there, and it works
|
|
173
|
+
differently from the other lists: a server returned from that hook lasts for that session only, while one
|
|
174
|
+
added in `agent.create` is stored on the agent. So an agent with a matching label gets the adapter in
|
|
175
|
+
every interactive session it opens (a new agent, a resume, a refresh, an import), each time with a fresh
|
|
176
|
+
ticket bound to that agent and its workspace; the tickets are revoked together when the agent is
|
|
177
|
+
archived, and an agent keeps at most eight bound tickets (the oldest is dropped first). Helper (background) agents, history sessions and sessions without a workspace are skipped. If
|
|
178
|
+
the ticket cannot be issued or bound the session opens without the tool and the log gets one line. In
|
|
179
|
+
"Every new agent" mode this does nothing, because every new agent already has the tool; an agent that
|
|
180
|
+
the create hook already gave a ticket is not given a second one.
|
|
181
|
+
|
|
182
|
+
Labels are a convenience for choosing agents, not a lock. Any connected client with write access, and any agent
|
|
183
|
+
that has Paseo tools, can set or delete labels on any agent, itself included, so a label does not keep an
|
|
184
|
+
untrusted agent away from the browser.
|
|
168
185
|
|
|
169
186
|
`agent.create` carries the provider and the working directory but no labels and no workspace id, so a
|
|
170
187
|
workspace or project is matched by directory: the workspace whose directory is the agent's directory or
|
|
171
188
|
the deepest one containing it. Both directories are normalized first (separators, `.` and `..` segments),
|
|
172
189
|
so a path that climbs out of a workspace does not match it. The lookup includes background workspaces. If
|
|
173
190
|
the list is longer than 20 pages of 200, or the lookup fails, those lists match nothing. Workspaces that
|
|
174
|
-
share a directory cannot be told apart, so listing any of them matches them all. Matching is lexical: nothing on disk is consulted, so symlinks are not resolved and letter case is not folded. The settings read has a 2 second deadline, and a read that is too slow is treated like an unreadable setting, so every new agent gets the tool. The workspace lookup has its own 2 second deadline, and a timeout there counts as no match. Either timeout logs one line, and a slow lookup never holds up agent creation. The check runs before the adapter, its credential or the supervisor are set up, so
|
|
191
|
+
share a directory cannot be told apart, so listing any of them matches them all. Matching is lexical: nothing on disk is consulted, so symlinks are not resolved and letter case is not folded. A path is only compared when it starts at a root (`/` or a drive such as `C:`); a relative workspace or agent directory never matches. Backslashes are read as separators and only drive paths are modelled, so a UNC path is not recognized and a literal backslash in a POSIX file name counts as a separator. The settings read has a 2 second deadline, and a read that is too slow is treated like an unreadable setting, so every new agent gets the tool. The workspace lookup has its own 2 second deadline, and a timeout there counts as no match. Either timeout logs one line, and a slow lookup never holds up agent creation. The check runs before the adapter, its credential or the supervisor are set up, so
|
|
175
192
|
an agent that is not allowed costs nothing. It applies to agents created after the setting is saved. A
|
|
176
193
|
setting that cannot be read or is invalid falls back to every new agent, and the plugin log gets one line
|
|
177
194
|
saying so. The settings screen reports an entry over 256 characters or a list over 200 entries instead of
|
|
178
|
-
cutting it off.
|
|
195
|
+
cutting it off. Changing the mode in the settings screen also saves the list text as typed, and shows
|
|
196
|
+
the error instead of saving when a list does not parse.
|
|
179
197
|
|
|
180
198
|
## Runtime environment overrides
|
|
181
199
|
|
|
@@ -16,11 +16,12 @@ const MODE_OPTIONS: readonly { label: string; value: AgentAccessMode }[] = [
|
|
|
16
16
|
{ label: "Only the agents listed below", value: "listed" },
|
|
17
17
|
];
|
|
18
18
|
|
|
19
|
-
type ListName = "providers" | "workspaces" | "projects";
|
|
19
|
+
type ListName = "providers" | "workspaces" | "projects" | "labels";
|
|
20
20
|
const NO_ERRORS: Record<ListName, string | null> = {
|
|
21
21
|
providers: null,
|
|
22
22
|
workspaces: null,
|
|
23
23
|
projects: null,
|
|
24
|
+
labels: null,
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
/** Settings screen: which new agents get the browser tool. */
|
|
@@ -29,6 +30,7 @@ export function AgentAccessSettings({ theme }: PluginSurfaceProps) {
|
|
|
29
30
|
const providers = useRef<SettingsInputHandle>(null);
|
|
30
31
|
const workspaces = useRef<SettingsInputHandle>(null);
|
|
31
32
|
const projects = useRef<SettingsInputHandle>(null);
|
|
33
|
+
const labels = useRef<SettingsInputHandle>(null);
|
|
32
34
|
// Errors belong to the revision they were found on; a newer revision (another client saved) clears them.
|
|
33
35
|
const [found, setFound] = useState<{
|
|
34
36
|
revision: string | null;
|
|
@@ -71,18 +73,21 @@ export function AgentAccessSettings({ theme }: PluginSurfaceProps) {
|
|
|
71
73
|
providers: parseEntries(providers.current?.getText() ?? ""),
|
|
72
74
|
workspaces: parseEntries(workspaces.current?.getText() ?? ""),
|
|
73
75
|
projects: parseEntries(projects.current?.getText() ?? ""),
|
|
76
|
+
labels: parseEntries(labels.current?.getText() ?? ""),
|
|
74
77
|
};
|
|
75
78
|
const errors = {
|
|
76
79
|
providers: parsed.providers.error,
|
|
77
80
|
workspaces: parsed.workspaces.error,
|
|
78
81
|
projects: parsed.projects.error,
|
|
82
|
+
labels: parsed.labels.error,
|
|
79
83
|
};
|
|
80
84
|
setFound({ revision: settings.revision, errors });
|
|
81
|
-
if (errors.providers || errors.workspaces || errors.projects) return null;
|
|
85
|
+
if (errors.providers || errors.workspaces || errors.projects || errors.labels) return null;
|
|
82
86
|
return {
|
|
83
87
|
providers: parsed.providers.entries,
|
|
84
88
|
workspaces: parsed.workspaces.entries,
|
|
85
89
|
projects: parsed.projects.entries,
|
|
90
|
+
labels: parsed.labels.entries,
|
|
86
91
|
};
|
|
87
92
|
};
|
|
88
93
|
return (
|
|
@@ -91,7 +96,7 @@ export function AgentAccessSettings({ theme }: PluginSurfaceProps) {
|
|
|
91
96
|
<SettingsCard key={settings.revision}>
|
|
92
97
|
<SettingsSelect
|
|
93
98
|
label="Browser tool for"
|
|
94
|
-
hint="
|
|
99
|
+
hint="Providers, workspaces and projects apply to agents created from now on; labels apply to every session of a labelled agent. With the lists empty, no agent gets the tool."
|
|
95
100
|
error={settings.saveError}
|
|
96
101
|
value={values.mode}
|
|
97
102
|
options={MODE_OPTIONS}
|
|
@@ -128,6 +133,15 @@ export function AgentAccessSettings({ theme }: PluginSurfaceProps) {
|
|
|
128
133
|
onChangeText={() => {}}
|
|
129
134
|
disabled={settings.saving}
|
|
130
135
|
/>
|
|
136
|
+
<SettingsInput
|
|
137
|
+
ref={labels}
|
|
138
|
+
label="Labels"
|
|
139
|
+
hint="A label key (team) or key=value (team=blue). An agent with a matching label gets the tool in every session, including after a resume. Labels pick agents for convenience; they do not keep an untrusted agent away from the browser, because any agent with Paseo tools can set its own labels."
|
|
140
|
+
initialValue={values.labels.join(", ")}
|
|
141
|
+
error={listErrors.labels}
|
|
142
|
+
onChangeText={() => {}}
|
|
143
|
+
disabled={settings.saving}
|
|
144
|
+
/>
|
|
131
145
|
<SettingsAction
|
|
132
146
|
label="Save the lists"
|
|
133
147
|
actionLabel="Save"
|
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,
|
|
@@ -38,6 +42,7 @@ import {
|
|
|
38
42
|
accessFromState,
|
|
39
43
|
agentAccessSettings,
|
|
40
44
|
agentGetsBrowser,
|
|
45
|
+
agentGetsBrowserByLabel,
|
|
41
46
|
DEFAULT_AGENT_ACCESS,
|
|
42
47
|
} from "./shared/agent-access";
|
|
43
48
|
import {
|
|
@@ -109,12 +114,30 @@ function mcpBundlePath(): string {
|
|
|
109
114
|
return join(resolveBrowserRuntimeRoot(paseoHome()), "shared-browser-mcp.cjs");
|
|
110
115
|
}
|
|
111
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
|
+
|
|
112
134
|
export default function contribute(server: PluginServerContext) {
|
|
113
135
|
server.registerSettings(browserDisplayPreferences);
|
|
114
136
|
const agentAccess = server.registerSettings(agentAccessSettings);
|
|
115
137
|
// The deadline covers the settings read alone: a setting that cannot be read in time is an unreadable
|
|
116
138
|
// setting, and that falls back to the default (every new agent).
|
|
117
|
-
|
|
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) => {
|
|
118
141
|
try {
|
|
119
142
|
const state = await withinDeadline(
|
|
120
143
|
Promise.resolve(agentAccess.read()),
|
|
@@ -122,16 +145,18 @@ export default function contribute(server: PluginServerContext) {
|
|
|
122
145
|
"the read timed out",
|
|
123
146
|
);
|
|
124
147
|
const access = accessFromState(state);
|
|
125
|
-
if (access === DEFAULT_AGENT_ACCESS) {
|
|
148
|
+
if (access === DEFAULT_AGENT_ACCESS && !quiet) {
|
|
126
149
|
console.warn(
|
|
127
150
|
`shared-browser: the agent-access setting is ${state?.status ?? "missing"}; every new agent gets the browser tool`,
|
|
128
151
|
);
|
|
129
152
|
}
|
|
130
153
|
return access;
|
|
131
154
|
} catch (error) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
}
|
|
135
160
|
return DEFAULT_AGENT_ACCESS;
|
|
136
161
|
}
|
|
137
162
|
};
|
|
@@ -187,32 +212,63 @@ export default function contribute(server: PluginServerContext) {
|
|
|
187
212
|
env: { ...request.env, [TICKET_ENV]: ticket },
|
|
188
213
|
config: {
|
|
189
214
|
...request.config,
|
|
190
|
-
mcpServers: {
|
|
191
|
-
...request.config.mcpServers,
|
|
192
|
-
[MCP_SERVER_ID]: {
|
|
193
|
-
type: "stdio",
|
|
194
|
-
command: process.execPath,
|
|
195
|
-
args: [mcpBundlePath()],
|
|
196
|
-
env: {
|
|
197
|
-
PASEO_HOME: paseoHome(),
|
|
198
|
-
[TICKET_ENV]: ticket,
|
|
199
|
-
ELECTRON_RUN_AS_NODE: "1",
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
},
|
|
215
|
+
mcpServers: { ...request.config.mcpServers, [MCP_SERVER_ID]: browserMcpServer(ticket) },
|
|
203
216
|
},
|
|
204
217
|
};
|
|
205
218
|
});
|
|
206
219
|
|
|
207
220
|
server.before("agent.session_open", async ({ request }) => {
|
|
208
|
-
if (request.reason !== "create") return request;
|
|
209
221
|
const ticket = request.env[TICKET_ENV];
|
|
210
|
-
if (
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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);
|
|
214
232
|
});
|
|
215
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
|
+
|
|
216
272
|
server.on("agent.archived", ({ agent }) => revokeAgentBrowserAccess(agent.id));
|
|
217
273
|
|
|
218
274
|
server.on("workspace.archived", ({ workspace }) => handleWorkspaceArchived(workspace.id));
|
package/package.json
CHANGED
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,19 @@ 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
|
+
if (dropped?.viewerToken) void this.browserPolicy.detach(dropped.viewerToken).catch(() => {});
|
|
665
|
+
}
|
|
642
666
|
return { bound: true };
|
|
643
667
|
}
|
|
644
668
|
|
|
645
669
|
private async revokeAgent(bridgeId: string, epoch: number, agentId: string): Promise<JsonValue> {
|
|
646
670
|
this.assertActiveBridge(bridgeId, epoch);
|
|
671
|
+
this.revokedAgents.set(agentId, { ticketSeq: this.ticketSeq, at: this.now() });
|
|
647
672
|
const tickets = this.agentTickets.get(agentId);
|
|
648
673
|
if (!tickets) return { revoked: 0 };
|
|
649
674
|
const viewers: string[] = [];
|
|
@@ -1166,6 +1191,8 @@ export class RuntimeSupervisor<Runtime extends RuntimeInstance = RuntimeInstance
|
|
|
1166
1191
|
for (const [ticket, binding] of this.agentBindings)
|
|
1167
1192
|
if (binding.agentId === null && binding.issuedAt <= deadline)
|
|
1168
1193
|
this.agentBindings.delete(ticket);
|
|
1194
|
+
for (const [agentId, revoked] of this.revokedAgents)
|
|
1195
|
+
if (revoked.at <= deadline) this.revokedAgents.delete(agentId);
|
|
1169
1196
|
}
|
|
1170
1197
|
|
|
1171
1198
|
private armBridgeTimeout(bridge: ActiveBridge): void {
|
package/shared/agent-access.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Which new agents get the Shared Browser tool.
|
|
3
3
|
*
|
|
4
4
|
* "all" injects the adapter into every new agent (the behaviour before this setting existed, and the
|
|
5
|
-
* default). "listed" injects it only when the new agent matches an entry of one of
|
|
6
|
-
* provider id, the id of its workspace,
|
|
7
|
-
* means no agent. Agents that already exist are never changed
|
|
5
|
+
* default). "listed" injects it only when the new agent matches an entry of one of four lists: its
|
|
6
|
+
* provider id, the id of its workspace, the id of its workspace's project, or one of its labels. An empty configuration
|
|
7
|
+
* means no agent. Agents that already exist are never changed, except that an agent chosen by label gets the tool in
|
|
8
|
+
* every interactive session it opens, resumed ones included.
|
|
8
9
|
*
|
|
9
10
|
* `agent.create` carries the provider and the working directory but no labels and no workspace id, so
|
|
10
11
|
* the workspace is found by matching the directory against the daemon's workspaces.
|
|
@@ -24,6 +25,7 @@ export const agentAccessSchema = z.object({
|
|
|
24
25
|
providers: entries,
|
|
25
26
|
workspaces: entries,
|
|
26
27
|
projects: entries,
|
|
28
|
+
labels: entries,
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
export type AgentAccess = z.output<typeof agentAccessSchema>;
|
|
@@ -41,6 +43,7 @@ export const DEFAULT_AGENT_ACCESS: AgentAccess = {
|
|
|
41
43
|
providers: [],
|
|
42
44
|
workspaces: [],
|
|
43
45
|
projects: [],
|
|
46
|
+
labels: [],
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
export function accessFromState(
|
|
@@ -87,6 +90,11 @@ export function normalizeDirectory(path: string): string {
|
|
|
87
90
|
return absolute ? `${drive}/${joined}` : joined;
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
/** True for a normalized path that starts at a root (`/` or a drive such as `C:/`). A relative path never matches a workspace. */
|
|
94
|
+
export function isAbsoluteDirectory(normalized: string): boolean {
|
|
95
|
+
return normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized);
|
|
96
|
+
}
|
|
97
|
+
|
|
90
98
|
/**
|
|
91
99
|
* The workspaces whose directory is the agent's directory, or the deepest directory that contains it.
|
|
92
100
|
* Several workspaces can share one directory, so this returns all of them.
|
|
@@ -96,11 +104,13 @@ export function workspacesForDirectory(
|
|
|
96
104
|
workspaces: readonly WorkspaceRef[],
|
|
97
105
|
): WorkspaceRef[] {
|
|
98
106
|
const target = normalizeDirectory(cwd);
|
|
107
|
+
if (!isAbsoluteDirectory(target)) return [];
|
|
99
108
|
let depth = -1;
|
|
100
109
|
let found: WorkspaceRef[] = [];
|
|
101
110
|
for (const workspace of workspaces) {
|
|
102
111
|
if (!workspace.workspaceDirectory) continue;
|
|
103
112
|
const directory = normalizeDirectory(workspace.workspaceDirectory);
|
|
113
|
+
if (!isAbsoluteDirectory(directory)) continue;
|
|
104
114
|
const prefix = directory.endsWith("/") ? directory : `${directory}/`;
|
|
105
115
|
if (target !== directory && !target.startsWith(prefix)) continue;
|
|
106
116
|
if (directory.length > depth) {
|
|
@@ -135,6 +145,34 @@ export async function agentGetsBrowser(
|
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
|
|
148
|
+
/**
|
|
149
|
+
* True when one entry of `entries` matches the agent's labels. An entry is a label key (`team`: the agent has that
|
|
150
|
+
* label, whatever its value) or `key=value` (the agent has that label with exactly that value). Matching is exact and
|
|
151
|
+
* case-sensitive. An entry with an empty key never matches.
|
|
152
|
+
*/
|
|
153
|
+
export function labelMatches(
|
|
154
|
+
entries: readonly string[],
|
|
155
|
+
labels: Readonly<Record<string, string>>,
|
|
156
|
+
): boolean {
|
|
157
|
+
return entries.some((entry) => {
|
|
158
|
+
const separator = entry.indexOf("=");
|
|
159
|
+
const key = separator < 0 ? entry : entry.slice(0, separator);
|
|
160
|
+
if (key === "" || !Object.hasOwn(labels, key)) return false;
|
|
161
|
+
return separator < 0 || labels[key] === entry.slice(separator + 1);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* True when an agent gets the browser tool because of its labels. Labels are only on the session-open request, not on
|
|
167
|
+
* agent.create, so this runs there. It applies to the "listed" mode only; in "all" every new agent already has the tool.
|
|
168
|
+
*/
|
|
169
|
+
export function agentGetsBrowserByLabel(
|
|
170
|
+
access: AgentAccess,
|
|
171
|
+
labels: Readonly<Record<string, string>>,
|
|
172
|
+
): boolean {
|
|
173
|
+
return access.mode === "listed" && labelMatches(access.labels, labels);
|
|
174
|
+
}
|
|
175
|
+
|
|
138
176
|
export const MAX_LIST_ENTRIES = MAX_ENTRIES;
|
|
139
177
|
export const MAX_LIST_ENTRY_LENGTH = MAX_ENTRY_LENGTH;
|
|
140
178
|
|