@agenticmail/enterprise 0.5.78 → 0.5.79
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/dist/chunk-7RNT4O5T.js +15198 -0
- package/dist/chunk-AGFOJCSB.js +2191 -0
- package/dist/chunk-F4GSFCM3.js +898 -0
- package/dist/chunk-PZA7YOJE.js +898 -0
- package/dist/chunk-Q3V7VZFQ.js +2191 -0
- package/dist/chunk-RRFB6G6M.js +15198 -0
- package/dist/chunk-VX3VFMVB.js +409 -0
- package/dist/cli.js +1 -1
- package/dist/dashboard/pages/agent-detail.js +313 -1
- package/dist/index.js +4 -3
- package/dist/pw-ai-KPETTB25.js +2212 -0
- package/dist/routes-PDHMCIXU.js +6676 -0
- package/dist/runtime-7HW4GX5L.js +48 -0
- package/dist/runtime-XXDCZZIK.js +48 -0
- package/dist/server-FMP4BFGW.js +12 -0
- package/dist/server-JRHDUNII.js +12 -0
- package/dist/setup-O5FPRLK4.js +20 -0
- package/dist/setup-S4Z4PPIJ.js +20 -0
- package/package.json +15 -2
- package/src/agent-tools/common.ts +25 -0
- package/src/agent-tools/index.ts +3 -0
- package/src/agent-tools/schema/typebox.ts +25 -0
- package/src/agent-tools/tools/browser-tool.schema.ts +112 -0
- package/src/agent-tools/tools/browser-tool.ts +388 -0
- package/src/agent-tools/tools/gateway.ts +126 -0
- package/src/agent-tools/tools/nodes-utils.ts +80 -0
- package/src/browser/bridge-auth-registry.ts +34 -0
- package/src/browser/bridge-server.ts +93 -0
- package/src/browser/cdp.helpers.ts +180 -0
- package/src/browser/cdp.ts +466 -0
- package/src/browser/chrome.executables.ts +625 -0
- package/src/browser/chrome.profile-decoration.ts +198 -0
- package/src/browser/chrome.ts +349 -0
- package/src/browser/client-actions-core.ts +259 -0
- package/src/browser/client-actions-observe.ts +184 -0
- package/src/browser/client-actions-state.ts +284 -0
- package/src/browser/client-actions-types.ts +16 -0
- package/src/browser/client-actions-url.ts +11 -0
- package/src/browser/client-actions.ts +4 -0
- package/src/browser/client-fetch.ts +253 -0
- package/src/browser/client.ts +337 -0
- package/src/browser/config.ts +296 -0
- package/src/browser/constants.ts +8 -0
- package/src/browser/control-auth.ts +94 -0
- package/src/browser/control-service.ts +81 -0
- package/src/browser/csrf.ts +87 -0
- package/src/browser/enterprise-compat.ts +518 -0
- package/src/browser/extension-relay.ts +834 -0
- package/src/browser/http-auth.ts +63 -0
- package/src/browser/navigation-guard.ts +50 -0
- package/src/browser/paths.ts +49 -0
- package/src/browser/profiles-service.ts +187 -0
- package/src/browser/profiles.ts +113 -0
- package/src/browser/proxy-files.ts +41 -0
- package/src/browser/pw-ai-module.ts +52 -0
- package/src/browser/pw-ai-state.ts +9 -0
- package/src/browser/pw-ai.ts +65 -0
- package/src/browser/pw-role-snapshot.ts +434 -0
- package/src/browser/pw-session.ts +810 -0
- package/src/browser/pw-tools-core.activity.ts +68 -0
- package/src/browser/pw-tools-core.downloads.ts +281 -0
- package/src/browser/pw-tools-core.interactions.ts +646 -0
- package/src/browser/pw-tools-core.responses.ts +124 -0
- package/src/browser/pw-tools-core.shared.ts +70 -0
- package/src/browser/pw-tools-core.snapshot.ts +213 -0
- package/src/browser/pw-tools-core.state.ts +209 -0
- package/src/browser/pw-tools-core.storage.ts +128 -0
- package/src/browser/pw-tools-core.trace.ts +37 -0
- package/src/browser/pw-tools-core.ts +8 -0
- package/src/browser/resolved-config-refresh.ts +59 -0
- package/src/browser/routes/agent.act.shared.ts +52 -0
- package/src/browser/routes/agent.act.ts +575 -0
- package/src/browser/routes/agent.debug.ts +149 -0
- package/src/browser/routes/agent.shared.ts +143 -0
- package/src/browser/routes/agent.snapshot.ts +333 -0
- package/src/browser/routes/agent.storage.ts +451 -0
- package/src/browser/routes/agent.ts +13 -0
- package/src/browser/routes/basic.ts +202 -0
- package/src/browser/routes/dispatcher.ts +126 -0
- package/src/browser/routes/index.ts +11 -0
- package/src/browser/routes/path-output.ts +1 -0
- package/src/browser/routes/tabs.ts +217 -0
- package/src/browser/routes/types.ts +26 -0
- package/src/browser/routes/utils.ts +73 -0
- package/src/browser/screenshot.ts +54 -0
- package/src/browser/server-context.ts +688 -0
- package/src/browser/server-context.types.ts +65 -0
- package/src/browser/server-lifecycle.ts +48 -0
- package/src/browser/server-middleware.ts +37 -0
- package/src/browser/server.ts +110 -0
- package/src/browser/target-id.ts +30 -0
- package/src/browser/trash.ts +21 -0
- package/src/dashboard/pages/agent-detail.js +313 -1
- package/src/engine/agent-routes.ts +46 -0
- package/src/security/external-content.ts +299 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Server } from "node:http";
|
|
2
|
+
import type { AddressInfo } from "node:net";
|
|
3
|
+
import express from "express";
|
|
4
|
+
|
|
5
|
+
import { deleteBridgeAuthForPort, setBridgeAuthForPort } from "./bridge-auth-registry.js";
|
|
6
|
+
import type { ResolvedBrowserConfig } from "./config.js";
|
|
7
|
+
import { registerBrowserRoutes } from "./routes/index.js";
|
|
8
|
+
import type { BrowserRouteRegistrar } from "./routes/types.js";
|
|
9
|
+
import {
|
|
10
|
+
type BrowserServerState,
|
|
11
|
+
createBrowserRouteContext,
|
|
12
|
+
type ProfileContext,
|
|
13
|
+
} from "./server-context.js";
|
|
14
|
+
import {
|
|
15
|
+
import { isLoopbackHost } from "./enterprise-compat.js";
|
|
16
|
+
installBrowserAuthMiddleware,
|
|
17
|
+
installBrowserCommonMiddleware,
|
|
18
|
+
} from "./server-middleware.js";
|
|
19
|
+
|
|
20
|
+
export type BrowserBridge = {
|
|
21
|
+
server: Server;
|
|
22
|
+
port: number;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
state: BrowserServerState;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export async function startBrowserBridgeServer(params: {
|
|
28
|
+
resolved: ResolvedBrowserConfig;
|
|
29
|
+
host?: string;
|
|
30
|
+
port?: number;
|
|
31
|
+
authToken?: string;
|
|
32
|
+
authPassword?: string;
|
|
33
|
+
onEnsureAttachTarget?: (profile: ProfileContext["profile"]) => Promise<void>;
|
|
34
|
+
}): Promise<BrowserBridge> {
|
|
35
|
+
const host = params.host ?? "127.0.0.1";
|
|
36
|
+
if (!isLoopbackHost(host)) {
|
|
37
|
+
throw new Error(`bridge server must bind to loopback host (got ${host})`);
|
|
38
|
+
}
|
|
39
|
+
const port = params.port ?? 0;
|
|
40
|
+
|
|
41
|
+
const app = express();
|
|
42
|
+
installBrowserCommonMiddleware(app);
|
|
43
|
+
|
|
44
|
+
const authToken = params.authToken?.trim() || undefined;
|
|
45
|
+
const authPassword = params.authPassword?.trim() || undefined;
|
|
46
|
+
if (!authToken && !authPassword) {
|
|
47
|
+
throw new Error("bridge server requires auth (authToken/authPassword missing)");
|
|
48
|
+
}
|
|
49
|
+
installBrowserAuthMiddleware(app, { token: authToken, password: authPassword });
|
|
50
|
+
|
|
51
|
+
const state: BrowserServerState = {
|
|
52
|
+
server: null as unknown as Server,
|
|
53
|
+
port,
|
|
54
|
+
resolved: params.resolved,
|
|
55
|
+
profiles: new Map(),
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const ctx = createBrowserRouteContext({
|
|
59
|
+
getState: () => state,
|
|
60
|
+
onEnsureAttachTarget: params.onEnsureAttachTarget,
|
|
61
|
+
});
|
|
62
|
+
registerBrowserRoutes(app as unknown as BrowserRouteRegistrar, ctx);
|
|
63
|
+
|
|
64
|
+
const server = await new Promise<Server>((resolve, reject) => {
|
|
65
|
+
const s = app.listen(port, host, () => resolve(s));
|
|
66
|
+
s.once("error", reject);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const address = server.address() as AddressInfo | null;
|
|
70
|
+
const resolvedPort = address?.port ?? port;
|
|
71
|
+
state.server = server;
|
|
72
|
+
state.port = resolvedPort;
|
|
73
|
+
state.resolved.controlPort = resolvedPort;
|
|
74
|
+
|
|
75
|
+
setBridgeAuthForPort(resolvedPort, { token: authToken, password: authPassword });
|
|
76
|
+
|
|
77
|
+
const baseUrl = `http://${host}:${resolvedPort}`;
|
|
78
|
+
return { server, port: resolvedPort, baseUrl, state };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function stopBrowserBridgeServer(server: Server): Promise<void> {
|
|
82
|
+
try {
|
|
83
|
+
const address = server.address() as AddressInfo | null;
|
|
84
|
+
if (address?.port) {
|
|
85
|
+
deleteBridgeAuthForPort(address.port);
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
// ignore
|
|
89
|
+
}
|
|
90
|
+
await new Promise<void>((resolve) => {
|
|
91
|
+
server.close(() => resolve());
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
|
|
3
|
+
import { getChromeExtensionRelayAuthHeaders } from "./extension-relay.js";
|
|
4
|
+
import { isLoopbackHost, rawDataToString } from "./enterprise-compat.js";
|
|
5
|
+
|
|
6
|
+
export { isLoopbackHost };
|
|
7
|
+
|
|
8
|
+
type CdpResponse = {
|
|
9
|
+
id: number;
|
|
10
|
+
result?: unknown;
|
|
11
|
+
error?: { message?: string };
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type Pending = {
|
|
15
|
+
resolve: (value: unknown) => void;
|
|
16
|
+
reject: (err: Error) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type CdpSendFn = (
|
|
20
|
+
method: string,
|
|
21
|
+
params?: Record<string, unknown>,
|
|
22
|
+
sessionId?: string,
|
|
23
|
+
) => Promise<unknown>;
|
|
24
|
+
|
|
25
|
+
export function getHeadersWithAuth(url: string, headers: Record<string, string> = {}) {
|
|
26
|
+
const relayHeaders = getChromeExtensionRelayAuthHeaders(url);
|
|
27
|
+
const mergedHeaders = { ...relayHeaders, ...headers };
|
|
28
|
+
try {
|
|
29
|
+
const parsed = new URL(url);
|
|
30
|
+
const hasAuthHeader = Object.keys(mergedHeaders).some(
|
|
31
|
+
(key) => key.toLowerCase() === "authorization",
|
|
32
|
+
);
|
|
33
|
+
if (hasAuthHeader) {
|
|
34
|
+
return mergedHeaders;
|
|
35
|
+
}
|
|
36
|
+
if (parsed.username || parsed.password) {
|
|
37
|
+
const auth = Buffer.from(`${parsed.username}:${parsed.password}`).toString("base64");
|
|
38
|
+
return { ...mergedHeaders, Authorization: `Basic ${auth}` };
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
// ignore
|
|
42
|
+
}
|
|
43
|
+
return mergedHeaders;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function appendCdpPath(cdpUrl: string, path: string): string {
|
|
47
|
+
const url = new URL(cdpUrl);
|
|
48
|
+
const basePath = url.pathname.replace(/\/$/, "");
|
|
49
|
+
const suffix = path.startsWith("/") ? path : `/${path}`;
|
|
50
|
+
url.pathname = `${basePath}${suffix}`;
|
|
51
|
+
return url.toString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function createCdpSender(ws: WebSocket) {
|
|
55
|
+
let nextId = 1;
|
|
56
|
+
const pending = new Map<number, Pending>();
|
|
57
|
+
|
|
58
|
+
const send: CdpSendFn = (
|
|
59
|
+
method: string,
|
|
60
|
+
params?: Record<string, unknown>,
|
|
61
|
+
sessionId?: string,
|
|
62
|
+
) => {
|
|
63
|
+
const id = nextId++;
|
|
64
|
+
const msg = { id, method, params, sessionId };
|
|
65
|
+
ws.send(JSON.stringify(msg));
|
|
66
|
+
return new Promise<unknown>((resolve, reject) => {
|
|
67
|
+
pending.set(id, { resolve, reject });
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const closeWithError = (err: Error) => {
|
|
72
|
+
for (const [, p] of pending) {
|
|
73
|
+
p.reject(err);
|
|
74
|
+
}
|
|
75
|
+
pending.clear();
|
|
76
|
+
try {
|
|
77
|
+
ws.close();
|
|
78
|
+
} catch {
|
|
79
|
+
// ignore
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
ws.on("error", (err) => {
|
|
84
|
+
closeWithError(err instanceof Error ? err : new Error(String(err)));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
ws.on("message", (data) => {
|
|
88
|
+
try {
|
|
89
|
+
const parsed = JSON.parse(rawDataToString(data)) as CdpResponse;
|
|
90
|
+
if (typeof parsed.id !== "number") {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const p = pending.get(parsed.id);
|
|
94
|
+
if (!p) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
pending.delete(parsed.id);
|
|
98
|
+
if (parsed.error?.message) {
|
|
99
|
+
p.reject(new Error(parsed.error.message));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
p.resolve(parsed.result);
|
|
103
|
+
} catch {
|
|
104
|
+
// ignore
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
ws.on("close", () => {
|
|
109
|
+
closeWithError(new Error("CDP socket closed"));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return { send, closeWithError };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function fetchJson<T>(url: string, timeoutMs = 1500, init?: RequestInit): Promise<T> {
|
|
116
|
+
const res = await fetchChecked(url, timeoutMs, init);
|
|
117
|
+
return (await res.json()) as T;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function fetchChecked(url: string, timeoutMs = 1500, init?: RequestInit): Promise<Response> {
|
|
121
|
+
const ctrl = new AbortController();
|
|
122
|
+
const t = setTimeout(ctrl.abort.bind(ctrl), timeoutMs);
|
|
123
|
+
try {
|
|
124
|
+
const headers = getHeadersWithAuth(url, (init?.headers as Record<string, string>) || {});
|
|
125
|
+
const res = await fetch(url, { ...init, headers, signal: ctrl.signal });
|
|
126
|
+
if (!res.ok) {
|
|
127
|
+
throw new Error(`HTTP ${res.status}`);
|
|
128
|
+
}
|
|
129
|
+
return res;
|
|
130
|
+
} finally {
|
|
131
|
+
clearTimeout(t);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function fetchOk(url: string, timeoutMs = 1500, init?: RequestInit): Promise<void> {
|
|
136
|
+
await fetchChecked(url, timeoutMs, init);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function withCdpSocket<T>(
|
|
140
|
+
wsUrl: string,
|
|
141
|
+
fn: (send: CdpSendFn) => Promise<T>,
|
|
142
|
+
opts?: { headers?: Record<string, string>; handshakeTimeoutMs?: number },
|
|
143
|
+
): Promise<T> {
|
|
144
|
+
const headers = getHeadersWithAuth(wsUrl, opts?.headers ?? {});
|
|
145
|
+
const handshakeTimeoutMs =
|
|
146
|
+
typeof opts?.handshakeTimeoutMs === "number" && Number.isFinite(opts.handshakeTimeoutMs)
|
|
147
|
+
? Math.max(1, Math.floor(opts.handshakeTimeoutMs))
|
|
148
|
+
: 5000;
|
|
149
|
+
const ws = new WebSocket(wsUrl, {
|
|
150
|
+
handshakeTimeout: handshakeTimeoutMs,
|
|
151
|
+
...(Object.keys(headers).length ? { headers } : {}),
|
|
152
|
+
});
|
|
153
|
+
const { send, closeWithError } = createCdpSender(ws);
|
|
154
|
+
|
|
155
|
+
const openPromise = new Promise<void>((resolve, reject) => {
|
|
156
|
+
ws.once("open", () => resolve());
|
|
157
|
+
ws.once("error", (err) => reject(err));
|
|
158
|
+
ws.once("close", () => reject(new Error("CDP socket closed")));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
await openPromise;
|
|
163
|
+
} catch (err) {
|
|
164
|
+
closeWithError(err instanceof Error ? err : new Error(String(err)));
|
|
165
|
+
throw err;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
return await fn(send);
|
|
170
|
+
} catch (err) {
|
|
171
|
+
closeWithError(err instanceof Error ? err : new Error(String(err)));
|
|
172
|
+
throw err;
|
|
173
|
+
} finally {
|
|
174
|
+
try {
|
|
175
|
+
ws.close();
|
|
176
|
+
} catch {
|
|
177
|
+
// ignore
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|