@kritchoff/agent-browser 1.0.0 → 1.0.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/package.json +3 -12
- package/bin/agent-browser-linux-x64 +0 -0
- package/scripts/copy-native.js +0 -36
- package/scripts/postinstall.js +0 -235
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kritchoff/agent-browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Headless browser automation CLI for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,18 +18,10 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"prepare": "husky",
|
|
20
20
|
"version:sync": "node scripts/sync-version.js",
|
|
21
|
-
"version": "npm run version:sync
|
|
21
|
+
"version": "npm run version:sync",
|
|
22
22
|
"build": "tsc",
|
|
23
|
-
"build:native": "npm run version:sync && cargo build --release --manifest-path cli/Cargo.toml && node scripts/copy-native.js",
|
|
24
|
-
"build:linux": "npm run version:sync && docker compose -f docker/docker-compose.yml run --rm build-linux",
|
|
25
|
-
"build:macos": "npm run version:sync && (cargo build --release --manifest-path cli/Cargo.toml --target aarch64-apple-darwin & cargo build --release --manifest-path cli/Cargo.toml --target x86_64-apple-darwin & wait) && cp cli/target/aarch64-apple-darwin/release/agent-browser bin/agent-browser-darwin-arm64 && cp cli/target/x86_64-apple-darwin/release/agent-browser bin/agent-browser-darwin-x64",
|
|
26
|
-
"build:windows": "npm run version:sync && docker compose -f docker/docker-compose.yml run --rm build-windows",
|
|
27
|
-
"build:all-platforms": "npm run version:sync && (npm run build:linux & npm run build:windows & wait) && npm run build:macos",
|
|
28
23
|
"build:docker": "docker build -t agent-browser-builder -f docker/Dockerfile.build .",
|
|
29
|
-
"
|
|
30
|
-
"fast-reset": "./scripts/fast_reset.sh",
|
|
31
|
-
"sdk": "./sdk.sh",
|
|
32
|
-
"release": "npm run version:sync && npm run build && npm run build:all-platforms && npm publish",
|
|
24
|
+
"release": "npm run version:sync && npm run build && npm publish",
|
|
33
25
|
"prepublishOnly": "npm run build",
|
|
34
26
|
"start": "node dist/daemon.js",
|
|
35
27
|
"dev": "tsx src/daemon.ts",
|
|
@@ -38,7 +30,6 @@
|
|
|
38
30
|
"format:check": "prettier --check 'src/**/*.ts'",
|
|
39
31
|
"test": "vitest run",
|
|
40
32
|
"test:watch": "vitest",
|
|
41
|
-
"postinstall": "node scripts/postinstall.js",
|
|
42
33
|
"changeset": "changeset",
|
|
43
34
|
"ci:version": "changeset version && pnpm run version:sync && pnpm install --no-frozen-lockfile",
|
|
44
35
|
"ci:publish": "pnpm run version:sync && pnpm run build && changeset publish"
|
|
Binary file
|
package/scripts/copy-native.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Copies the compiled Rust binary to bin/ with platform-specific naming
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { copyFileSync, existsSync, mkdirSync } from 'fs';
|
|
8
|
-
import { dirname, join } from 'path';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
import { platform, arch } from 'os';
|
|
11
|
-
|
|
12
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
const projectRoot = join(__dirname, '..');
|
|
14
|
-
|
|
15
|
-
const sourceExt = platform() === 'win32' ? '.exe' : '';
|
|
16
|
-
const sourcePath = join(projectRoot, `cli/target/release/agent-browser${sourceExt}`);
|
|
17
|
-
const binDir = join(projectRoot, 'bin');
|
|
18
|
-
|
|
19
|
-
// Determine platform suffix
|
|
20
|
-
const platformKey = `${platform()}-${arch()}`;
|
|
21
|
-
const ext = platform() === 'win32' ? '.exe' : '';
|
|
22
|
-
const targetName = `agent-browser-${platformKey}${ext}`;
|
|
23
|
-
const targetPath = join(binDir, targetName);
|
|
24
|
-
|
|
25
|
-
if (!existsSync(sourcePath)) {
|
|
26
|
-
console.error(`Error: Native binary not found at ${sourcePath}`);
|
|
27
|
-
console.error('Run "cargo build --release --manifest-path cli/Cargo.toml" first');
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!existsSync(binDir)) {
|
|
32
|
-
mkdirSync(binDir, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
copyFileSync(sourcePath, targetPath);
|
|
36
|
-
console.log(`✓ Copied native binary to ${targetPath}`);
|
package/scripts/postinstall.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Postinstall script for agent-browser
|
|
5
|
-
*
|
|
6
|
-
* Downloads the platform-specific native binary if not present.
|
|
7
|
-
* On global installs, patches npm's bin entry to use the native binary directly:
|
|
8
|
-
* - Windows: Overwrites .cmd/.ps1 shims
|
|
9
|
-
* - Mac/Linux: Replaces symlink to point to native binary
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync, writeFileSync, symlinkSync, lstatSync } from 'fs';
|
|
13
|
-
import { dirname, join } from 'path';
|
|
14
|
-
import { fileURLToPath } from 'url';
|
|
15
|
-
import { platform, arch } from 'os';
|
|
16
|
-
import { get } from 'https';
|
|
17
|
-
import { execSync } from 'child_process';
|
|
18
|
-
|
|
19
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
|
-
const projectRoot = join(__dirname, '..');
|
|
21
|
-
const binDir = join(projectRoot, 'bin');
|
|
22
|
-
|
|
23
|
-
// Platform detection
|
|
24
|
-
const platformKey = `${platform()}-${arch()}`;
|
|
25
|
-
const ext = platform() === 'win32' ? '.exe' : '';
|
|
26
|
-
const binaryName = `agent-browser-${platformKey}${ext}`;
|
|
27
|
-
const binaryPath = join(binDir, binaryName);
|
|
28
|
-
|
|
29
|
-
// Package info
|
|
30
|
-
const packageJson = JSON.parse(
|
|
31
|
-
(await import('fs')).readFileSync(join(projectRoot, 'package.json'), 'utf8')
|
|
32
|
-
);
|
|
33
|
-
const version = packageJson.version;
|
|
34
|
-
|
|
35
|
-
// GitHub release URL
|
|
36
|
-
const GITHUB_REPO = 'vercel-labs/agent-browser';
|
|
37
|
-
const DOWNLOAD_URL = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${binaryName}`;
|
|
38
|
-
|
|
39
|
-
async function downloadFile(url, dest) {
|
|
40
|
-
return new Promise((resolve, reject) => {
|
|
41
|
-
const file = createWriteStream(dest);
|
|
42
|
-
|
|
43
|
-
const request = (url) => {
|
|
44
|
-
get(url, (response) => {
|
|
45
|
-
// Handle redirects
|
|
46
|
-
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
47
|
-
request(response.headers.location);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (response.statusCode !== 200) {
|
|
52
|
-
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
response.pipe(file);
|
|
57
|
-
file.on('finish', () => {
|
|
58
|
-
file.close();
|
|
59
|
-
resolve();
|
|
60
|
-
});
|
|
61
|
-
}).on('error', (err) => {
|
|
62
|
-
unlinkSync(dest);
|
|
63
|
-
reject(err);
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
request(url);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function main() {
|
|
72
|
-
// Check if binary already exists
|
|
73
|
-
if (existsSync(binaryPath)) {
|
|
74
|
-
// Ensure binary is executable (npm doesn't preserve execute bit)
|
|
75
|
-
if (platform() !== 'win32') {
|
|
76
|
-
chmodSync(binaryPath, 0o755);
|
|
77
|
-
}
|
|
78
|
-
console.log(`✓ Native binary ready: ${binaryName}`);
|
|
79
|
-
|
|
80
|
-
// On global installs, fix npm's bin entry to use native binary directly
|
|
81
|
-
await fixGlobalInstallBin();
|
|
82
|
-
|
|
83
|
-
showPlaywrightReminder();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Ensure bin directory exists
|
|
88
|
-
if (!existsSync(binDir)) {
|
|
89
|
-
mkdirSync(binDir, { recursive: true });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
console.log(`Downloading native binary for ${platformKey}...`);
|
|
93
|
-
console.log(`URL: ${DOWNLOAD_URL}`);
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
await downloadFile(DOWNLOAD_URL, binaryPath);
|
|
97
|
-
|
|
98
|
-
// Make executable on Unix
|
|
99
|
-
if (platform() !== 'win32') {
|
|
100
|
-
chmodSync(binaryPath, 0o755);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
console.log(`✓ Downloaded native binary: ${binaryName}`);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
console.log(`⚠ Could not download native binary: ${err.message}`);
|
|
106
|
-
console.log(` The CLI will use Node.js fallback (slightly slower startup)`);
|
|
107
|
-
console.log('');
|
|
108
|
-
console.log('To build the native binary locally:');
|
|
109
|
-
console.log(' 1. Install Rust: https://rustup.rs');
|
|
110
|
-
console.log(' 2. Run: npm run build:native');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// On global installs, fix npm's bin entry to use native binary directly
|
|
114
|
-
// This avoids the /bin/sh error on Windows and provides zero-overhead execution
|
|
115
|
-
await fixGlobalInstallBin();
|
|
116
|
-
|
|
117
|
-
showPlaywrightReminder();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function showPlaywrightReminder() {
|
|
121
|
-
console.log('');
|
|
122
|
-
console.log('╔═══════════════════════════════════════════════════════════════════════════╗');
|
|
123
|
-
console.log('║ To download browser binaries, run: ║');
|
|
124
|
-
console.log('║ ║');
|
|
125
|
-
console.log('║ npx playwright install chromium ║');
|
|
126
|
-
console.log('║ ║');
|
|
127
|
-
console.log('║ On Linux, include system dependencies with: ║');
|
|
128
|
-
console.log('║ ║');
|
|
129
|
-
console.log('║ npx playwright install --with-deps chromium ║');
|
|
130
|
-
console.log('║ ║');
|
|
131
|
-
console.log('╚═══════════════════════════════════════════════════════════════════════════╝');
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Fix npm's bin entry on global installs to use the native binary directly.
|
|
136
|
-
* This provides zero-overhead CLI execution for global installs.
|
|
137
|
-
*/
|
|
138
|
-
async function fixGlobalInstallBin() {
|
|
139
|
-
if (platform() === 'win32') {
|
|
140
|
-
await fixWindowsShims();
|
|
141
|
-
} else {
|
|
142
|
-
await fixUnixSymlink();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Fix npm symlink on Mac/Linux global installs.
|
|
148
|
-
* Replace the symlink to the JS wrapper with a symlink to the native binary.
|
|
149
|
-
*/
|
|
150
|
-
async function fixUnixSymlink() {
|
|
151
|
-
// Get npm's global bin directory (npm prefix -g + /bin)
|
|
152
|
-
let npmBinDir;
|
|
153
|
-
try {
|
|
154
|
-
const prefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
|
|
155
|
-
npmBinDir = join(prefix, 'bin');
|
|
156
|
-
} catch {
|
|
157
|
-
return; // npm not available
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const symlinkPath = join(npmBinDir, 'agent-browser');
|
|
161
|
-
|
|
162
|
-
// Check if symlink exists (indicates global install)
|
|
163
|
-
try {
|
|
164
|
-
const stat = lstatSync(symlinkPath);
|
|
165
|
-
if (!stat.isSymbolicLink()) {
|
|
166
|
-
return; // Not a symlink, don't touch it
|
|
167
|
-
}
|
|
168
|
-
} catch {
|
|
169
|
-
return; // Symlink doesn't exist, not a global install
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Replace symlink to point directly to native binary
|
|
173
|
-
try {
|
|
174
|
-
unlinkSync(symlinkPath);
|
|
175
|
-
symlinkSync(binaryPath, symlinkPath);
|
|
176
|
-
console.log('✓ Optimized: symlink points to native binary (zero overhead)');
|
|
177
|
-
} catch (err) {
|
|
178
|
-
// Permission error or other issue - not critical, JS wrapper still works
|
|
179
|
-
console.log(`⚠ Could not optimize symlink: ${err.message}`);
|
|
180
|
-
console.log(' CLI will work via Node.js wrapper (slightly slower startup)');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Fix npm-generated shims on Windows global installs.
|
|
186
|
-
* npm generates shims that try to run /bin/sh, which doesn't exist on Windows.
|
|
187
|
-
* We overwrite them to invoke the native .exe directly.
|
|
188
|
-
*/
|
|
189
|
-
async function fixWindowsShims() {
|
|
190
|
-
// Check if this is a global install by looking for npm's global prefix
|
|
191
|
-
let npmBinDir;
|
|
192
|
-
try {
|
|
193
|
-
npmBinDir = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
|
|
194
|
-
} catch {
|
|
195
|
-
return; // Not a global install or npm not available
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// The shims are in the npm prefix directory (not prefix/bin on Windows)
|
|
199
|
-
const cmdShim = join(npmBinDir, 'agent-browser.cmd');
|
|
200
|
-
const ps1Shim = join(npmBinDir, 'agent-browser.ps1');
|
|
201
|
-
|
|
202
|
-
// Only fix if shims exist (indicates global install)
|
|
203
|
-
if (!existsSync(cmdShim)) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Path to native binary relative to npm prefix
|
|
208
|
-
const relativeBinaryPath = 'node_modules\\agent-browser\\bin\\agent-browser-win32-x64.exe';
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
// Overwrite .cmd shim
|
|
212
|
-
const cmdContent = `@ECHO off\r\n"%~dp0${relativeBinaryPath}" %*\r\n`;
|
|
213
|
-
writeFileSync(cmdShim, cmdContent);
|
|
214
|
-
|
|
215
|
-
// Overwrite .ps1 shim
|
|
216
|
-
const ps1Content = `#!/usr/bin/env pwsh
|
|
217
|
-
$basedir = Split-Path $MyInvocation.MyCommand.Definition -Parent
|
|
218
|
-
$exe = ""
|
|
219
|
-
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
|
220
|
-
$exe = ".exe"
|
|
221
|
-
}
|
|
222
|
-
& "$basedir/${relativeBinaryPath.replace(/\\/g, '/')}" $args
|
|
223
|
-
exit $LASTEXITCODE
|
|
224
|
-
`;
|
|
225
|
-
writeFileSync(ps1Shim, ps1Content);
|
|
226
|
-
|
|
227
|
-
console.log('✓ Optimized: shims point to native binary (zero overhead)');
|
|
228
|
-
} catch (err) {
|
|
229
|
-
// Permission error or other issue - not critical, JS wrapper still works
|
|
230
|
-
console.log(`⚠ Could not optimize shims: ${err.message}`);
|
|
231
|
-
console.log(' CLI will work via Node.js wrapper (slightly slower startup)');
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
main().catch(console.error);
|