@agentproto/adapter-browser 0.1.0-alpha.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/LICENSE +21 -0
- package/dist/index.d.ts +164 -0
- package/dist/index.mjs +307 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeremy André and agentproto contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
interface BrowserAdapterHandle {
|
|
2
|
+
/** Stable identifier — "camofox" | "bureau" | "chromium" */
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
defaultPort: number;
|
|
7
|
+
/** Path used for health probing, e.g. "/health" */
|
|
8
|
+
healthPath: string;
|
|
9
|
+
/**
|
|
10
|
+
* Where this adapter runs. Defaults to "local" when absent.
|
|
11
|
+
* MVP: each adapter declares exactly one location.
|
|
12
|
+
*/
|
|
13
|
+
location?: "local" | "cloud";
|
|
14
|
+
/**
|
|
15
|
+
* How to obtain / install the underlying binary or service.
|
|
16
|
+
* Informational for now; T9 will wire these into `ensure`.
|
|
17
|
+
*/
|
|
18
|
+
install?: BrowserAdapterInstall[];
|
|
19
|
+
/**
|
|
20
|
+
* Post-install configuration prompts. Structurally compatible with the
|
|
21
|
+
* prompt-arm of AIP-45 `AgentCliSetupStep` (type-import not taken to keep
|
|
22
|
+
* this package dep-free of `@agentproto/driver-agent-cli`).
|
|
23
|
+
*
|
|
24
|
+
* Note: `persist.env` here is a SUBSET of the `env` arm of the AIP-45 union
|
|
25
|
+
* (`{ env: string }`). The union also supports `secret_slug` and `cmd` arms
|
|
26
|
+
* which are not represented here. Extend toward the full union if those
|
|
27
|
+
* variants become necessary rather than adding a single-line Extract<>.
|
|
28
|
+
*/
|
|
29
|
+
config?: BrowserAdapterConfigStep[];
|
|
30
|
+
/**
|
|
31
|
+
* Platform constraints. Mirrors `AgentCliRequires` from AIP-45 but
|
|
32
|
+
* redeclared here to avoid the dep (same rationale as `config`).
|
|
33
|
+
*/
|
|
34
|
+
requires?: BrowserAdapterRequires;
|
|
35
|
+
/**
|
|
36
|
+
* Typed runtime knobs. Mirrors `AgentCliOption` (minimal subset).
|
|
37
|
+
* Not wired into `ensure` until T9.
|
|
38
|
+
*/
|
|
39
|
+
options?: BrowserAdapterOption[];
|
|
40
|
+
/**
|
|
41
|
+
* Ensure the service is up and return a live instance descriptor.
|
|
42
|
+
* Idempotent: if already healthy, returns immediately with wasAlreadyRunning: true.
|
|
43
|
+
*/
|
|
44
|
+
ensure(opts: BrowserAdapterStartOptions): Promise<BrowserAdapterInstance>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* One entry in `BrowserAdapterHandle.install`.
|
|
48
|
+
*
|
|
49
|
+
* - "path" — binary already on the system at a known path (or on PATH).
|
|
50
|
+
* - "download" — fetch a release archive and extract a binary.
|
|
51
|
+
* - "curl" — pipe through a shell installer script.
|
|
52
|
+
* - "vendored" — shipped inside this monorepo / npm package.
|
|
53
|
+
* - "cloud" — adapter is a remote URL, not a local process.
|
|
54
|
+
*/
|
|
55
|
+
interface BrowserAdapterInstall {
|
|
56
|
+
method: "path" | "download" | "curl" | "vendored" | "cloud";
|
|
57
|
+
/** For "download" / "curl" / "cloud" — the source URL. */
|
|
58
|
+
url?: string;
|
|
59
|
+
/** Optional SHA-256 hex digest to verify a downloaded artifact. */
|
|
60
|
+
verify_sha256?: string;
|
|
61
|
+
/** For "cloud" — env-var name that holds the auth token (e.g. "BROWSER_SERVICE_KEY"). */
|
|
62
|
+
secret?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* One post-install configuration prompt.
|
|
66
|
+
*
|
|
67
|
+
* Structurally matches the "prompt" arm of AIP-45 `AgentCliSetupStep`.
|
|
68
|
+
* `persist.env` is the only persist form supported here (MVP): the captured
|
|
69
|
+
* value is injected as an env var on every subsequent `ensure` call (T9).
|
|
70
|
+
*/
|
|
71
|
+
interface BrowserAdapterConfigStep {
|
|
72
|
+
id: string;
|
|
73
|
+
kind: "prompt";
|
|
74
|
+
prompt: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
type?: "text" | "select" | "boolean" | "secret";
|
|
77
|
+
default?: string;
|
|
78
|
+
options?: string[];
|
|
79
|
+
/** Where the captured value lands so `ensure` can reuse it. */
|
|
80
|
+
persist?: {
|
|
81
|
+
/** Env-var name to inject on every spawn. */
|
|
82
|
+
env: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Platform constraints for this adapter. */
|
|
86
|
+
interface BrowserAdapterRequires {
|
|
87
|
+
/**
|
|
88
|
+
* Hard OS constraint: the adapter is **unavailable** on platforms not listed
|
|
89
|
+
* here (Node `process.platform` values, e.g. `"linux"`). Absence means the
|
|
90
|
+
* adapter is available everywhere.
|
|
91
|
+
*/
|
|
92
|
+
os?: string[];
|
|
93
|
+
/** Allowed CPU architectures (Node `process.arch` values). */
|
|
94
|
+
arch?: string[];
|
|
95
|
+
/**
|
|
96
|
+
* OS platforms on which the **native launcher path** (e.g. launchd plist) is
|
|
97
|
+
* available. This is NOT a hard availability constraint — the adapter still
|
|
98
|
+
* works on other platforms when a `SERVE_CMD` env var or `opts.launchCmd`
|
|
99
|
+
* override is provided. Absence means no platform-specific native launcher.
|
|
100
|
+
*/
|
|
101
|
+
nativeLaunchOs?: string[];
|
|
102
|
+
}
|
|
103
|
+
/** Minimal subset of AIP-45 `AgentCliOption` — typed runtime knob. */
|
|
104
|
+
interface BrowserAdapterOption {
|
|
105
|
+
id: string;
|
|
106
|
+
type: "boolean" | "integer" | "string" | "enum";
|
|
107
|
+
description?: string;
|
|
108
|
+
/** Required when type === "enum". */
|
|
109
|
+
enum?: string[];
|
|
110
|
+
default?: boolean | number | string;
|
|
111
|
+
/** Env vars to merge when the option is active. */
|
|
112
|
+
env?: Record<string, string>;
|
|
113
|
+
}
|
|
114
|
+
interface BrowserAdapterStartOptions {
|
|
115
|
+
port?: number;
|
|
116
|
+
/** For adapters that depend on Camofox (e.g. bureau): override the Camofox port (default 9377). */
|
|
117
|
+
camofoxPort?: number;
|
|
118
|
+
/** Override the launch command (shell string). Takes precedence over env vars. */
|
|
119
|
+
launchCmd?: string;
|
|
120
|
+
/** Additional env vars forwarded to the spawned process. */
|
|
121
|
+
env?: Record<string, string>;
|
|
122
|
+
timeoutMs?: number;
|
|
123
|
+
log?: (s: string) => void;
|
|
124
|
+
/**
|
|
125
|
+
* Where to run the adapter. Defaults to `handle.location ?? "local"`.
|
|
126
|
+
* - `"local"` — spawn the process on the current machine (existing behaviour).
|
|
127
|
+
* - `"cloud"` — health-check a remote endpoint; no process is spawned.
|
|
128
|
+
* Requires `baseUrl` to be set.
|
|
129
|
+
*/
|
|
130
|
+
location?: "local" | "cloud";
|
|
131
|
+
/**
|
|
132
|
+
* Base URL of the remote service when `location === "cloud"`.
|
|
133
|
+
* Example: `"https://browser-service.example.com"`.
|
|
134
|
+
* Required (and only used) when `location === "cloud"`.
|
|
135
|
+
*/
|
|
136
|
+
baseUrl?: string;
|
|
137
|
+
}
|
|
138
|
+
interface BrowserAdapterInstance {
|
|
139
|
+
id: string;
|
|
140
|
+
port: number;
|
|
141
|
+
baseUrl: string;
|
|
142
|
+
/**
|
|
143
|
+
* PID of the spawned process. May be `undefined` when the service is managed
|
|
144
|
+
* externally (e.g. launchd) — do NOT use this to kill the process in that case.
|
|
145
|
+
*/
|
|
146
|
+
pid?: number;
|
|
147
|
+
wasAlreadyRunning: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Best-effort stop. Sends SIGTERM to `pid` if known; otherwise a no-op
|
|
150
|
+
* (externally-managed services must be stopped via their own manager).
|
|
151
|
+
*/
|
|
152
|
+
stop(): Promise<void>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
declare const camofoxAdapter: BrowserAdapterHandle;
|
|
156
|
+
|
|
157
|
+
declare const bureauAdapter: BrowserAdapterHandle;
|
|
158
|
+
|
|
159
|
+
declare const chromiumAdapter: BrowserAdapterHandle;
|
|
160
|
+
|
|
161
|
+
declare const browserAdapters: Record<string, BrowserAdapterHandle>;
|
|
162
|
+
declare function getBrowserAdapter(id: string): BrowserAdapterHandle | undefined;
|
|
163
|
+
|
|
164
|
+
export { type BrowserAdapterHandle, type BrowserAdapterInstance, type BrowserAdapterStartOptions, browserAdapters, bureauAdapter, camofoxAdapter, chromiumAdapter, getBrowserAdapter };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { platform, homedir } from 'os';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { readFile } from 'fs/promises';
|
|
5
|
+
import { ensureBrowserProcess } from '@agentproto/browser-process';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @agentproto/adapter-browser v0.1.0-alpha
|
|
9
|
+
* Browser service adapters — Camofox + Bureau process handles.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
async function loadPersistedEnv(adapterId) {
|
|
13
|
+
const base = process.env["AGENTPROTO_HOME"] ?? join(homedir(), ".agentproto");
|
|
14
|
+
const ledgerPath = join(base, "browser-adapters", `${adapterId}.json`);
|
|
15
|
+
try {
|
|
16
|
+
const raw = await readFile(ledgerPath, "utf8");
|
|
17
|
+
const parsed = JSON.parse(raw);
|
|
18
|
+
return parsed.envValues ?? {};
|
|
19
|
+
} catch {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function makeStop(pid, processGroup) {
|
|
24
|
+
return async () => {
|
|
25
|
+
if (!pid) return;
|
|
26
|
+
if (processGroup) {
|
|
27
|
+
try {
|
|
28
|
+
process.kill(-pid, "SIGTERM");
|
|
29
|
+
return;
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
process.kill(pid, "SIGTERM");
|
|
35
|
+
} catch {
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function resolveLaunch(cfg) {
|
|
40
|
+
const { handle, opts, label } = cfg;
|
|
41
|
+
const port = opts.port ?? handle.defaultPort;
|
|
42
|
+
const timeoutMs = opts.timeoutMs ?? 6e4;
|
|
43
|
+
const log = opts.log;
|
|
44
|
+
const location = opts.location ?? handle.location ?? "local";
|
|
45
|
+
const persistedEnv = await loadPersistedEnv(handle.id);
|
|
46
|
+
const resolvedExtraEnv = typeof cfg.extraEnv === "function" ? cfg.extraEnv(port) : cfg.extraEnv;
|
|
47
|
+
if (location === "cloud") {
|
|
48
|
+
const cloudBase = opts.baseUrl;
|
|
49
|
+
if (!cloudBase) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`[${label}] location="cloud" requires opts.baseUrl (the remote service base URL).`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const healthUrl = cloudBase.replace(/\/$/, "") + handle.healthPath;
|
|
55
|
+
log?.(`[${label}] cloud mode \u2014 health-checking ${healthUrl}`);
|
|
56
|
+
const result2 = await ensureBrowserProcess({
|
|
57
|
+
kind: handle.id,
|
|
58
|
+
healthUrl,
|
|
59
|
+
launch: () => null,
|
|
60
|
+
timeoutMs,
|
|
61
|
+
intervalMs: 1e3,
|
|
62
|
+
log
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
id: handle.id,
|
|
66
|
+
port,
|
|
67
|
+
baseUrl: result2.baseUrl,
|
|
68
|
+
pid: void 0,
|
|
69
|
+
wasAlreadyRunning: result2.wasAlreadyRunning,
|
|
70
|
+
stop: async () => {
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const result = await ensureBrowserProcess({
|
|
75
|
+
kind: handle.id,
|
|
76
|
+
healthUrl: `http://127.0.0.1:${port}${handle.healthPath}`,
|
|
77
|
+
launch() {
|
|
78
|
+
const cmd = cfg.resolveLocalCmd();
|
|
79
|
+
if (!cmd) {
|
|
80
|
+
const nativePlatforms = handle.requires?.nativeLaunchOs;
|
|
81
|
+
const platformHint = nativePlatforms && !nativePlatforms.includes(platform()) ? ` (native launcher only available on ${nativePlatforms.join(", ")}; set the relevant SERVE_CMD env var on ${platform()} or pass opts.launchCmd)` : "";
|
|
82
|
+
throw new Error(
|
|
83
|
+
`[${label}] service is not running on :${port} and no launch command is available.${platformHint}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
log?.(`[${label}] starting: ${[cmd.file, ...cmd.args].join(" ")}`);
|
|
87
|
+
if (cmd.isLaunchctl) {
|
|
88
|
+
spawn(cmd.file, cmd.args, {
|
|
89
|
+
detached: true,
|
|
90
|
+
stdio: "ignore",
|
|
91
|
+
env: { ...process.env, ...persistedEnv, ...opts.env, ...resolvedExtraEnv }
|
|
92
|
+
}).unref();
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const child = spawn(cmd.file, cmd.args, {
|
|
96
|
+
detached: true,
|
|
97
|
+
stdio: "ignore",
|
|
98
|
+
env: { ...process.env, ...persistedEnv, ...opts.env, ...resolvedExtraEnv },
|
|
99
|
+
...cmd.cwd ? { cwd: cmd.cwd } : {}
|
|
100
|
+
});
|
|
101
|
+
child.unref();
|
|
102
|
+
return child;
|
|
103
|
+
},
|
|
104
|
+
timeoutMs,
|
|
105
|
+
intervalMs: 1e3,
|
|
106
|
+
log
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
id: handle.id,
|
|
110
|
+
port,
|
|
111
|
+
baseUrl: result.baseUrl,
|
|
112
|
+
pid: result.pid,
|
|
113
|
+
wasAlreadyRunning: result.wasAlreadyRunning,
|
|
114
|
+
stop: makeStop(result.pid, cfg.killProcessGroup ?? false)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/adapters/camofox.ts
|
|
119
|
+
function resolveCmd(launchCmd, env) {
|
|
120
|
+
if (launchCmd) return { file: "/bin/sh", args: ["-c", launchCmd] };
|
|
121
|
+
const envCmd = env?.CAMOFOX_SERVE_CMD ?? process.env.CAMOFOX_SERVE_CMD;
|
|
122
|
+
if (envCmd) return { file: "/bin/sh", args: ["-c", envCmd] };
|
|
123
|
+
if (platform() === "darwin")
|
|
124
|
+
return { file: "launchctl", args: ["start", "com.agentik.camofox"], isLaunchctl: true };
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
var camofoxAdapter = {
|
|
128
|
+
id: "camofox",
|
|
129
|
+
name: "Camofox (stealth Firefox headless)",
|
|
130
|
+
description: "Camofox headless stealth Firefox REST API on :9377. Exposes /sessions, /tabs, and /health. Required dependency for the bureau adapter.",
|
|
131
|
+
defaultPort: 9377,
|
|
132
|
+
healthPath: "/health",
|
|
133
|
+
location: "local",
|
|
134
|
+
install: [
|
|
135
|
+
{
|
|
136
|
+
method: "vendored"
|
|
137
|
+
// Shipped via the agentik launchd plist on macOS; on other platforms
|
|
138
|
+
// install camofox separately and point CAMOFOX_SERVE_CMD at it.
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
requires: {
|
|
142
|
+
// nativeLaunchOs ≠ hard constraint: the adapter is available on all
|
|
143
|
+
// platforms. This field only signals that the built-in launchd path
|
|
144
|
+
// (com.agentik.camofox) exists on macOS; elsewhere CAMOFOX_SERVE_CMD
|
|
145
|
+
// or opts.launchCmd must be provided.
|
|
146
|
+
nativeLaunchOs: ["darwin"]
|
|
147
|
+
},
|
|
148
|
+
config: [
|
|
149
|
+
{
|
|
150
|
+
id: "camofox-serve-cmd",
|
|
151
|
+
kind: "prompt",
|
|
152
|
+
prompt: "Shell command to start camofox (leave blank on macOS when using the com.agentik.camofox launchd plist)",
|
|
153
|
+
description: "Required on non-macOS hosts. On macOS this overrides the default `launchctl start com.agentik.camofox` path.",
|
|
154
|
+
type: "text",
|
|
155
|
+
persist: { env: "CAMOFOX_SERVE_CMD" }
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
async ensure(opts) {
|
|
159
|
+
return resolveLaunch({
|
|
160
|
+
handle: this,
|
|
161
|
+
opts,
|
|
162
|
+
label: "camofox",
|
|
163
|
+
resolveLocalCmd: () => resolveCmd(opts.launchCmd, opts.env)
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/adapters/bureau.ts
|
|
169
|
+
function resolveBureauCmd(launchCmd, env) {
|
|
170
|
+
const cmd = launchCmd ?? env?.BUREAU_SERVE_CMD ?? process.env.BUREAU_SERVE_CMD;
|
|
171
|
+
if (cmd) return { file: "/bin/sh", args: ["-c", cmd] };
|
|
172
|
+
return { file: "bureau", args: ["serve"] };
|
|
173
|
+
}
|
|
174
|
+
var bureauAdapter = {
|
|
175
|
+
id: "bureau",
|
|
176
|
+
name: "Bureau (Camofox + MCP capability server)",
|
|
177
|
+
description: "Bureau capability server on :8830. Orchestrates Camofox headless first, then spawns bureau serve which exposes browser tools as MCP-over-HTTP.",
|
|
178
|
+
defaultPort: 8830,
|
|
179
|
+
healthPath: "/health",
|
|
180
|
+
location: "local",
|
|
181
|
+
install: [
|
|
182
|
+
{
|
|
183
|
+
method: "path"
|
|
184
|
+
// `bureau` CLI must be on PATH (e.g. installed via `npm i -g @agentik/bureau`
|
|
185
|
+
// or linked from the monorepo workspace bin).
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
config: [
|
|
189
|
+
// bureau inherits camofox's CAMOFOX_SERVE_CMD implicitly — camofoxAdapter.ensure
|
|
190
|
+
// is called first inside `ensure` and reads that env var itself.
|
|
191
|
+
{
|
|
192
|
+
id: "bureau-serve-cmd",
|
|
193
|
+
kind: "prompt",
|
|
194
|
+
prompt: "Shell command to start bureau (leave blank to use `bureau serve` on PATH)",
|
|
195
|
+
type: "text",
|
|
196
|
+
persist: { env: "BUREAU_SERVE_CMD" }
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: "bureau-port",
|
|
200
|
+
kind: "prompt",
|
|
201
|
+
prompt: "Port bureau should listen on",
|
|
202
|
+
type: "text",
|
|
203
|
+
default: "8830",
|
|
204
|
+
persist: { env: "BUREAU_PORT" }
|
|
205
|
+
}
|
|
206
|
+
],
|
|
207
|
+
async ensure(opts) {
|
|
208
|
+
const timeoutMs = opts.timeoutMs ?? 6e4;
|
|
209
|
+
const log = opts.log;
|
|
210
|
+
const cam = await camofoxAdapter.ensure({
|
|
211
|
+
port: opts.camofoxPort ?? 9377,
|
|
212
|
+
launchCmd: void 0,
|
|
213
|
+
env: opts.env,
|
|
214
|
+
timeoutMs,
|
|
215
|
+
log
|
|
216
|
+
});
|
|
217
|
+
return resolveLaunch({
|
|
218
|
+
handle: this,
|
|
219
|
+
opts,
|
|
220
|
+
label: "bureau",
|
|
221
|
+
resolveLocalCmd: () => resolveBureauCmd(opts.launchCmd, opts.env),
|
|
222
|
+
// PORT must reflect the resolved port — extraEnv receives it as a factory arg.
|
|
223
|
+
extraEnv: (port) => ({
|
|
224
|
+
CAMOFOX_URL: cam.baseUrl,
|
|
225
|
+
PORT: String(port)
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// src/adapters/chromium.ts
|
|
232
|
+
function resolveCmd2(launchCmd, env, log) {
|
|
233
|
+
if (launchCmd) return { file: "/bin/sh", args: ["-c", launchCmd] };
|
|
234
|
+
const envCmd = env?.CHROMIUM_SERVE_CMD ?? process.env.CHROMIUM_SERVE_CMD;
|
|
235
|
+
if (envCmd) return { file: "/bin/sh", args: ["-c", envCmd] };
|
|
236
|
+
const cwd = resolveCwd(env, log);
|
|
237
|
+
return { file: "/bin/sh", args: ["-c", "pnpm --filter=@browser/service start"], cwd };
|
|
238
|
+
}
|
|
239
|
+
function resolveCwd(env, log) {
|
|
240
|
+
const explicit = env?.CHROMIUM_SERVE_CWD ?? process.env.CHROMIUM_SERVE_CWD;
|
|
241
|
+
if (explicit) return explicit;
|
|
242
|
+
log?.(
|
|
243
|
+
"[chromium] warning: CHROMIUM_SERVE_CWD is not set; relying on daemon cwd for `pnpm --filter=@browser/service start`. Set CHROMIUM_SERVE_CWD or run the daemon from the repo root, or override with CHROMIUM_SERVE_CMD."
|
|
244
|
+
);
|
|
245
|
+
return void 0;
|
|
246
|
+
}
|
|
247
|
+
var chromiumAdapter = {
|
|
248
|
+
id: "chromium",
|
|
249
|
+
name: "Chromium Browser Service",
|
|
250
|
+
description: "Heavy Chromium webservice (projects/browser/apps/service) on :3200. Exposes /healthz, /readyz, REST session routes, and a CDP WebSocket proxy.",
|
|
251
|
+
defaultPort: 3200,
|
|
252
|
+
healthPath: "/healthz",
|
|
253
|
+
location: "local",
|
|
254
|
+
install: [
|
|
255
|
+
{
|
|
256
|
+
method: "path"
|
|
257
|
+
// Local: `pnpm --filter=@browser/service start` from the monorepo root,
|
|
258
|
+
// or set CHROMIUM_SERVE_CMD / CHROMIUM_SERVE_CWD to point at a custom launcher.
|
|
259
|
+
// Cloud variant (future — not yet wired into ensure):
|
|
260
|
+
// method: "cloud", url: process.env.BROWSER_SERVICE_URL, secret: "BROWSER_SERVICE_KEY"
|
|
261
|
+
}
|
|
262
|
+
],
|
|
263
|
+
config: [
|
|
264
|
+
{
|
|
265
|
+
id: "chromium-serve-cmd",
|
|
266
|
+
kind: "prompt",
|
|
267
|
+
prompt: "Shell command to start the browser service (default: pnpm --filter=@browser/service start)",
|
|
268
|
+
description: "Override CHROMIUM_SERVE_CMD. When blank, the default pnpm filter command is used and CHROMIUM_SERVE_CWD must point to the monorepo root.",
|
|
269
|
+
type: "text",
|
|
270
|
+
persist: { env: "CHROMIUM_SERVE_CMD" }
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
id: "chromium-serve-cwd",
|
|
274
|
+
kind: "prompt",
|
|
275
|
+
prompt: "Working directory for the browser service (monorepo root required for the pnpm filter command)",
|
|
276
|
+
type: "text",
|
|
277
|
+
persist: { env: "CHROMIUM_SERVE_CWD" }
|
|
278
|
+
}
|
|
279
|
+
// Future cloud step (T9+):
|
|
280
|
+
// { id: "chromium-cloud-url", kind: "prompt", prompt: "Remote browser-service URL", type: "text", persist: { env: "BROWSER_SERVICE_URL" } },
|
|
281
|
+
// { id: "chromium-cloud-token", kind: "prompt", prompt: "X-Internal-Key token", type: "secret", persist: { env: "BROWSER_SERVICE_KEY" } },
|
|
282
|
+
],
|
|
283
|
+
async ensure(opts) {
|
|
284
|
+
return resolveLaunch({
|
|
285
|
+
handle: this,
|
|
286
|
+
opts,
|
|
287
|
+
label: "chromium",
|
|
288
|
+
resolveLocalCmd: () => resolveCmd2(opts.launchCmd, opts.env, opts.log),
|
|
289
|
+
// Kill the whole process group so the pnpm-forked node child is not orphaned.
|
|
290
|
+
killProcessGroup: true
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/index.ts
|
|
296
|
+
var browserAdapters = {
|
|
297
|
+
camofox: camofoxAdapter,
|
|
298
|
+
bureau: bureauAdapter,
|
|
299
|
+
chromium: chromiumAdapter
|
|
300
|
+
};
|
|
301
|
+
function getBrowserAdapter(id) {
|
|
302
|
+
return browserAdapters[id];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export { browserAdapters, bureauAdapter, camofoxAdapter, chromiumAdapter, getBrowserAdapter };
|
|
306
|
+
//# sourceMappingURL=index.mjs.map
|
|
307
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/resolve-launch.ts","../src/adapters/camofox.ts","../src/adapters/bureau.ts","../src/adapters/chromium.ts","../src/index.ts"],"names":["result","platform","resolveCmd"],"mappings":";;;;;;;;;;;AAgBA,eAAe,iBAAiB,SAAA,EAAoD;AAClF,EAAA,MAAM,IAAA,GAAO,QAAQ,GAAA,CAAI,iBAAiB,KAAK,IAAA,CAAK,OAAA,IAAW,aAAa,CAAA;AAC5E,EAAA,MAAM,aAAa,IAAA,CAAK,IAAA,EAAM,kBAAA,EAAoB,CAAA,EAAG,SAAS,CAAA,KAAA,CAAO,CAAA;AACrE,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,MAAM,QAAA,CAAS,UAAA,EAAY,MAAM,CAAA;AAC7C,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC7B,IAAA,OAAO,MAAA,CAAO,aAAa,EAAC;AAAA,EAC9B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAC;AAAA,EACV;AACF;AA2CA,SAAS,QAAA,CAAS,KAAyB,YAAA,EAA4C;AACrF,EAAA,OAAO,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,UAAA;AAAA,MACP,eAAA,EAAiB,MAAMA,WAAAA,CAAW,IAAA,CAAK,WAAW,IAAA,CAAK,GAAA,EAAK,KAAK,GAAG,CAAA;AAAA;AAAA,MAEpE,gBAAA,EAAkB;AAAA,KACnB,CAAA;AAAA,EACH;AACF;;;AC9EO,IAAM,eAAA,GAAwD;AAAA,EACnE,OAAA,EAAS,cAAA;AAAA,EACT,MAAA,EAAQ,aAAA;AAAA,EACR,QAAA,EAAU;AACZ;AAEO,SAAS,kBAAkB,EAAA,EAA8C;AAC9E,EAAA,OAAO,gBAAgB,EAAE,CAAA;AAC3B","file":"index.mjs","sourcesContent":["import { spawn } from \"node:child_process\"\nimport { platform, homedir } from \"node:os\"\nimport { join } from \"node:path\"\nimport { readFile } from \"node:fs/promises\"\nimport { ensureBrowserProcess } from \"@agentproto/browser-process\"\nimport type { BrowserAdapterHandle, BrowserAdapterStartOptions, BrowserAdapterInstance } from \"../types.js\"\n\n// ── Persisted config ledger ───────────────────────────────────────────────────\n\n/**\n * Best-effort read of the persisted env values written by\n * `agentproto browser install`. Returns `{}` on any read/parse failure.\n *\n * Path: `$AGENTPROTO_HOME/browser-adapters/<adapterId>.json`\n * (same convention as the CLI's `browserAdapterLedgerPath()`).\n */\nasync function loadPersistedEnv(adapterId: string): Promise<Record<string, string>> {\n const base = process.env[\"AGENTPROTO_HOME\"] ?? join(homedir(), \".agentproto\")\n const ledgerPath = join(base, \"browser-adapters\", `${adapterId}.json`)\n try {\n const raw = await readFile(ledgerPath, \"utf8\")\n const parsed = JSON.parse(raw) as { envValues?: Record<string, string> }\n return parsed.envValues ?? {}\n } catch {\n return {}\n }\n}\n\n// ─── Config ───────────────────────────────────────────────────────────────────\n\nexport interface ResolveLaunchConfig {\n handle: Pick<BrowserAdapterHandle, \"id\" | \"defaultPort\" | \"healthPath\" | \"location\" | \"requires\">\n opts: BrowserAdapterStartOptions\n /**\n * Short label used in log and error messages (e.g. \"camofox\", \"bureau\").\n * Typically matches `handle.id`.\n */\n label: string\n /**\n * Returns the local launch command, or `null` when no command is resolvable.\n * The returned object may carry `isLaunchctl: true` for launchers (like\n * launchctl) that exit immediately and are not the real managed process — in\n * that case the child is spawned for its side-effect only and `pid` stays\n * undefined in the resulting instance.\n * `cwd` is forwarded to the spawned child when present.\n */\n resolveLocalCmd(): {\n file: string\n args: string[]\n isLaunchctl?: boolean\n cwd?: string\n } | null\n /**\n * Extra env vars merged into the spawned process env (after `opts.env`).\n * Accepts either a plain record or a factory that receives the resolved port\n * (useful when the port must be baked into an env var like `PORT`).\n */\n extraEnv?: Record<string, string> | ((port: number) => Record<string, string>)\n /**\n * When `true`, stop() sends SIGTERM to the whole process group (`-pid`),\n * falling back to the direct pid on failure. Use for adapters that spawn\n * through `sh -c` and need to terminate pnpm-forked child processes.\n * Default: false (direct-pid SIGTERM only).\n */\n killProcessGroup?: boolean\n}\n\n// ─── Helpers ──────────────────────────────────────────────────────────────────\n\nfunction makeStop(pid: number | undefined, processGroup: boolean): () => Promise<void> {\n return async () => {\n if (!pid) return\n if (processGroup) {\n try {\n process.kill(-pid, \"SIGTERM\")\n return\n } catch {\n // group already gone — fall through to direct pid\n }\n }\n try {\n process.kill(pid, \"SIGTERM\")\n } catch {\n // process may have already exited — ignore\n }\n }\n}\n\n// ─── Core ─────────────────────────────────────────────────────────────────────\n\n/**\n * Shared launch/health-check logic for all three browser adapters.\n *\n * Two execution paths:\n * - **local** — resolves a launch command and spawns a detached child process,\n * then polls health (existing behaviour, unchanged).\n * - **cloud** — health-checks `opts.baseUrl` directly; no process is spawned.\n */\nexport async function resolveLaunch(cfg: ResolveLaunchConfig): Promise<BrowserAdapterInstance> {\n const { handle, opts, label } = cfg\n const port = opts.port ?? handle.defaultPort\n const timeoutMs = opts.timeoutMs ?? 60_000\n const log = opts.log\n const location = opts.location ?? handle.location ?? \"local\"\n\n // Persisted config from `agentproto browser install` — merged as lowest-priority\n // env so that opts.env (explicit caller overrides) always wins.\n const persistedEnv = await loadPersistedEnv(handle.id)\n\n const resolvedExtraEnv =\n typeof cfg.extraEnv === \"function\" ? cfg.extraEnv(port) : cfg.extraEnv\n\n // ── Cloud path ──────────────────────────────────────────────────────────────\n if (location === \"cloud\") {\n const cloudBase = opts.baseUrl\n if (!cloudBase) {\n throw new Error(\n `[${label}] location=\"cloud\" requires opts.baseUrl (the remote service base URL).`\n )\n }\n const healthUrl = cloudBase.replace(/\\/$/, \"\") + handle.healthPath\n log?.(`[${label}] cloud mode — health-checking ${healthUrl}`)\n const result = await ensureBrowserProcess({\n kind: handle.id,\n healthUrl,\n launch: () => null,\n timeoutMs,\n intervalMs: 1000,\n log,\n })\n return {\n id: handle.id,\n port,\n baseUrl: result.baseUrl,\n pid: undefined,\n wasAlreadyRunning: result.wasAlreadyRunning,\n stop: async () => {},\n }\n }\n\n // ── Local path ──────────────────────────────────────────────────────────────\n const result = await ensureBrowserProcess({\n kind: handle.id,\n healthUrl: `http://127.0.0.1:${port}${handle.healthPath}`,\n launch() {\n const cmd = cfg.resolveLocalCmd()\n if (!cmd) {\n const nativePlatforms = handle.requires?.nativeLaunchOs\n const platformHint =\n nativePlatforms && !nativePlatforms.includes(platform())\n ? ` (native launcher only available on ${nativePlatforms.join(\", \")}; ` +\n `set the relevant SERVE_CMD env var on ${platform()} or pass opts.launchCmd)`\n : \"\"\n throw new Error(\n `[${label}] service is not running on :${port} and no launch command is available.${platformHint}`\n )\n }\n log?.(`[${label}] starting: ${[cmd.file, ...cmd.args].join(\" \")}`)\n if (cmd.isLaunchctl) {\n // Launcher exits immediately — spawn for side-effect only; pid stays undefined.\n spawn(cmd.file, cmd.args, {\n detached: true,\n stdio: \"ignore\",\n env: { ...process.env, ...persistedEnv, ...opts.env, ...resolvedExtraEnv },\n }).unref()\n return null\n }\n const child = spawn(cmd.file, cmd.args, {\n detached: true,\n stdio: \"ignore\",\n env: { ...process.env, ...persistedEnv, ...opts.env, ...resolvedExtraEnv },\n ...(cmd.cwd ? { cwd: cmd.cwd } : {}),\n })\n child.unref()\n return child\n },\n timeoutMs,\n intervalMs: 1000,\n log,\n })\n\n return {\n id: handle.id,\n port,\n baseUrl: result.baseUrl,\n pid: result.pid,\n wasAlreadyRunning: result.wasAlreadyRunning,\n stop: makeStop(result.pid, cfg.killProcessGroup ?? false),\n }\n}\n","import { platform } from \"node:os\"\nimport type { BrowserAdapterHandle, BrowserAdapterStartOptions, BrowserAdapterInstance } from \"../types.js\"\nimport { resolveLaunch } from \"../lib/resolve-launch.js\"\n\nfunction resolveCmd(\n launchCmd: string | undefined,\n env: Record<string, string> | undefined\n): { file: string; args: string[]; isLaunchctl?: boolean } | null {\n if (launchCmd) return { file: \"/bin/sh\", args: [\"-c\", launchCmd] }\n const envCmd = env?.CAMOFOX_SERVE_CMD ?? process.env.CAMOFOX_SERVE_CMD\n if (envCmd) return { file: \"/bin/sh\", args: [\"-c\", envCmd] }\n if (platform() === \"darwin\")\n return { file: \"launchctl\", args: [\"start\", \"com.agentik.camofox\"], isLaunchctl: true }\n return null\n}\n\nexport const camofoxAdapter: BrowserAdapterHandle = {\n id: \"camofox\",\n name: \"Camofox (stealth Firefox headless)\",\n description:\n \"Camofox headless stealth Firefox REST API on :9377. Exposes /sessions, /tabs, and /health. Required dependency for the bureau adapter.\",\n defaultPort: 9377,\n healthPath: \"/health\",\n\n location: \"local\",\n\n install: [\n {\n method: \"vendored\",\n // Shipped via the agentik launchd plist on macOS; on other platforms\n // install camofox separately and point CAMOFOX_SERVE_CMD at it.\n },\n ],\n\n requires: {\n // nativeLaunchOs ≠ hard constraint: the adapter is available on all\n // platforms. This field only signals that the built-in launchd path\n // (com.agentik.camofox) exists on macOS; elsewhere CAMOFOX_SERVE_CMD\n // or opts.launchCmd must be provided.\n nativeLaunchOs: [\"darwin\"],\n },\n\n config: [\n {\n id: \"camofox-serve-cmd\",\n kind: \"prompt\",\n prompt: \"Shell command to start camofox (leave blank on macOS when using the com.agentik.camofox launchd plist)\",\n description:\n \"Required on non-macOS hosts. On macOS this overrides the default `launchctl start com.agentik.camofox` path.\",\n type: \"text\",\n persist: { env: \"CAMOFOX_SERVE_CMD\" },\n },\n ],\n\n async ensure(opts: BrowserAdapterStartOptions): Promise<BrowserAdapterInstance> {\n return resolveLaunch({\n handle: this,\n opts,\n label: \"camofox\",\n resolveLocalCmd: () => resolveCmd(opts.launchCmd, opts.env),\n })\n },\n}\n","import type { BrowserAdapterHandle, BrowserAdapterStartOptions, BrowserAdapterInstance } from \"../types.js\"\nimport { resolveLaunch } from \"../lib/resolve-launch.js\"\nimport { camofoxAdapter } from \"./camofox.js\"\n\nfunction resolveBureauCmd(\n launchCmd: string | undefined,\n env: Record<string, string> | undefined\n): { file: string; args: string[] } {\n const cmd = launchCmd ?? env?.BUREAU_SERVE_CMD ?? process.env.BUREAU_SERVE_CMD\n if (cmd) return { file: \"/bin/sh\", args: [\"-c\", cmd] }\n // Default: `bureau serve` assumed on PATH (installed globally or via the workspace bin).\n return { file: \"bureau\", args: [\"serve\"] }\n}\n\nexport const bureauAdapter: BrowserAdapterHandle = {\n id: \"bureau\",\n name: \"Bureau (Camofox + MCP capability server)\",\n description:\n \"Bureau capability server on :8830. Orchestrates Camofox headless first, then \" +\n \"spawns bureau serve which exposes browser tools as MCP-over-HTTP.\",\n defaultPort: 8830,\n healthPath: \"/health\",\n\n location: \"local\",\n\n install: [\n {\n method: \"path\",\n // `bureau` CLI must be on PATH (e.g. installed via `npm i -g @agentik/bureau`\n // or linked from the monorepo workspace bin).\n },\n ],\n\n config: [\n // bureau inherits camofox's CAMOFOX_SERVE_CMD implicitly — camofoxAdapter.ensure\n // is called first inside `ensure` and reads that env var itself.\n {\n id: \"bureau-serve-cmd\",\n kind: \"prompt\",\n prompt: \"Shell command to start bureau (leave blank to use `bureau serve` on PATH)\",\n type: \"text\",\n persist: { env: \"BUREAU_SERVE_CMD\" },\n },\n {\n id: \"bureau-port\",\n kind: \"prompt\",\n prompt: \"Port bureau should listen on\",\n type: \"text\",\n default: \"8830\",\n persist: { env: \"BUREAU_PORT\" },\n },\n ],\n\n async ensure(opts: BrowserAdapterStartOptions): Promise<BrowserAdapterInstance> {\n const timeoutMs = opts.timeoutMs ?? 60_000\n const log = opts.log\n\n // Camofox must be up before bureau serve can start.\n const cam = await camofoxAdapter.ensure({\n port: opts.camofoxPort ?? 9377,\n launchCmd: undefined,\n env: opts.env,\n timeoutMs,\n log,\n })\n\n return resolveLaunch({\n handle: this,\n opts,\n label: \"bureau\",\n resolveLocalCmd: () => resolveBureauCmd(opts.launchCmd, opts.env),\n // PORT must reflect the resolved port — extraEnv receives it as a factory arg.\n extraEnv: (port) => ({\n CAMOFOX_URL: cam.baseUrl,\n PORT: String(port),\n }),\n })\n },\n}\n","import type { BrowserAdapterHandle, BrowserAdapterStartOptions, BrowserAdapterInstance } from \"../types.js\"\nimport { resolveLaunch } from \"../lib/resolve-launch.js\"\n\nfunction resolveCmd(\n launchCmd: string | undefined,\n env: Record<string, string> | undefined,\n log: ((s: string) => void) | undefined\n): { file: string; args: string[]; cwd?: string } {\n if (launchCmd) return { file: \"/bin/sh\", args: [\"-c\", launchCmd] }\n const envCmd = env?.CHROMIUM_SERVE_CMD ?? process.env.CHROMIUM_SERVE_CMD\n if (envCmd) return { file: \"/bin/sh\", args: [\"-c\", envCmd] }\n\n // Default pnpm filter command — requires the workspace root as cwd.\n const cwd = resolveCwd(env, log)\n return { file: \"/bin/sh\", args: [\"-c\", \"pnpm --filter=@browser/service start\"], cwd }\n}\n\n/**\n * Resolve the working directory for the spawned browser-service process.\n *\n * Priority: CHROMIUM_SERVE_CWD from caller env > same var from process env >\n * undefined (spawn inherits the daemon's own cwd, which is the pnpm workspace\n * root when the daemon was started normally). When the default pnpm --filter\n * command is used and no cwd is resolvable, a warning is emitted — pnpm needs\n * the workspace root to match the filter.\n */\nfunction resolveCwd(\n env: Record<string, string> | undefined,\n log: ((s: string) => void) | undefined\n): string | undefined {\n const explicit = env?.CHROMIUM_SERVE_CWD ?? process.env.CHROMIUM_SERVE_CWD\n if (explicit) return explicit\n log?.(\n \"[chromium] warning: CHROMIUM_SERVE_CWD is not set; relying on daemon cwd for \" +\n \"`pnpm --filter=@browser/service start`. Set CHROMIUM_SERVE_CWD or run the daemon \" +\n \"from the repo root, or override with CHROMIUM_SERVE_CMD.\"\n )\n return undefined\n}\n\nexport const chromiumAdapter: BrowserAdapterHandle = {\n id: \"chromium\",\n name: \"Chromium Browser Service\",\n description:\n \"Heavy Chromium webservice (projects/browser/apps/service) on :3200. Exposes /healthz, /readyz, REST session routes, and a CDP WebSocket proxy.\",\n defaultPort: 3200,\n healthPath: \"/healthz\",\n\n location: \"local\",\n\n install: [\n {\n method: \"path\",\n // Local: `pnpm --filter=@browser/service start` from the monorepo root,\n // or set CHROMIUM_SERVE_CMD / CHROMIUM_SERVE_CWD to point at a custom launcher.\n // Cloud variant (future — not yet wired into ensure):\n // method: \"cloud\", url: process.env.BROWSER_SERVICE_URL, secret: \"BROWSER_SERVICE_KEY\"\n },\n ],\n\n config: [\n {\n id: \"chromium-serve-cmd\",\n kind: \"prompt\",\n prompt: \"Shell command to start the browser service (default: pnpm --filter=@browser/service start)\",\n description:\n \"Override CHROMIUM_SERVE_CMD. When blank, the default pnpm filter command is used and \" +\n \"CHROMIUM_SERVE_CWD must point to the monorepo root.\",\n type: \"text\",\n persist: { env: \"CHROMIUM_SERVE_CMD\" },\n },\n {\n id: \"chromium-serve-cwd\",\n kind: \"prompt\",\n prompt: \"Working directory for the browser service (monorepo root required for the pnpm filter command)\",\n type: \"text\",\n persist: { env: \"CHROMIUM_SERVE_CWD\" },\n },\n // Future cloud step (T9+):\n // { id: \"chromium-cloud-url\", kind: \"prompt\", prompt: \"Remote browser-service URL\", type: \"text\", persist: { env: \"BROWSER_SERVICE_URL\" } },\n // { id: \"chromium-cloud-token\", kind: \"prompt\", prompt: \"X-Internal-Key token\", type: \"secret\", persist: { env: \"BROWSER_SERVICE_KEY\" } },\n ],\n\n async ensure(opts: BrowserAdapterStartOptions): Promise<BrowserAdapterInstance> {\n return resolveLaunch({\n handle: this,\n opts,\n label: \"chromium\",\n resolveLocalCmd: () => resolveCmd(opts.launchCmd, opts.env, opts.log),\n // Kill the whole process group so the pnpm-forked node child is not orphaned.\n killProcessGroup: true,\n })\n },\n}\n","export type {\n BrowserAdapterHandle,\n BrowserAdapterStartOptions,\n BrowserAdapterInstance,\n} from \"./types.js\"\n\nexport { camofoxAdapter } from \"./adapters/camofox.js\"\nexport { bureauAdapter } from \"./adapters/bureau.js\"\nexport { chromiumAdapter } from \"./adapters/chromium.js\"\n\nimport { camofoxAdapter } from \"./adapters/camofox.js\"\nimport { bureauAdapter } from \"./adapters/bureau.js\"\nimport { chromiumAdapter } from \"./adapters/chromium.js\"\nimport type { BrowserAdapterHandle } from \"./types.js\"\n\nexport const browserAdapters: Record<string, BrowserAdapterHandle> = {\n camofox: camofoxAdapter,\n bureau: bureauAdapter,\n chromium: chromiumAdapter,\n}\n\nexport function getBrowserAdapter(id: string): BrowserAdapterHandle | undefined {\n return browserAdapters[id]\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/adapter-browser",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "@agentproto/adapter-browser — browser service adapters for agentproto. Manages Camofox (stealth Firefox) and Bureau (Camofox + MCP capability server) as first-class process handles: health-check, idempotent launch, structured stop.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"browser",
|
|
8
|
+
"camofox",
|
|
9
|
+
"bureau",
|
|
10
|
+
"adapter"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://agentproto.sh",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/agentproto/ts",
|
|
16
|
+
"directory": "adapters/browser"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/agentproto/ts/issues"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "dist/index.mjs",
|
|
24
|
+
"module": "dist/index.mjs",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.mjs",
|
|
30
|
+
"default": "./dist/index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": "./package.json"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@agentproto/browser-process": "0.1.0-alpha.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^25.6.2",
|
|
47
|
+
"tsup": "^8.5.1",
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
|
+
"vitest": "^3.2.4",
|
|
50
|
+
"@agentproto/tooling": "0.1.0-alpha.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"dev": "tsup --watch",
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"clean": "rm -rf dist",
|
|
56
|
+
"check-types": "tsc --noEmit",
|
|
57
|
+
"test": "vitest run --passWithNoTests",
|
|
58
|
+
"test:watch": "vitest"
|
|
59
|
+
}
|
|
60
|
+
}
|