nstbrowser-ai-agent 0.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.
Files changed (119) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1321 -0
  3. package/bin/nstbrowser-ai-agent-darwin-arm64 +0 -0
  4. package/bin/nstbrowser-ai-agent-darwin-x64 +0 -0
  5. package/bin/nstbrowser-ai-agent-linux-arm64 +0 -0
  6. package/bin/nstbrowser-ai-agent-linux-x64 +0 -0
  7. package/bin/nstbrowser-ai-agent-win32-x64.exe +0 -0
  8. package/bin/nstbrowser-ai-agent.js +109 -0
  9. package/dist/action-policy.d.ts +14 -0
  10. package/dist/action-policy.d.ts.map +1 -0
  11. package/dist/action-policy.js +253 -0
  12. package/dist/action-policy.js.map +1 -0
  13. package/dist/actions.d.ts +18 -0
  14. package/dist/actions.d.ts.map +1 -0
  15. package/dist/actions.js +2037 -0
  16. package/dist/actions.js.map +1 -0
  17. package/dist/auth-cli.d.ts +2 -0
  18. package/dist/auth-cli.d.ts.map +1 -0
  19. package/dist/auth-cli.js +97 -0
  20. package/dist/auth-cli.js.map +1 -0
  21. package/dist/auth-vault.d.ts +36 -0
  22. package/dist/auth-vault.d.ts.map +1 -0
  23. package/dist/auth-vault.js +125 -0
  24. package/dist/auth-vault.js.map +1 -0
  25. package/dist/browser.d.ts +573 -0
  26. package/dist/browser.d.ts.map +1 -0
  27. package/dist/browser.js +2036 -0
  28. package/dist/browser.js.map +1 -0
  29. package/dist/confirmation.d.ts +8 -0
  30. package/dist/confirmation.d.ts.map +1 -0
  31. package/dist/confirmation.js +30 -0
  32. package/dist/confirmation.js.map +1 -0
  33. package/dist/daemon.d.ts +65 -0
  34. package/dist/daemon.d.ts.map +1 -0
  35. package/dist/daemon.js +589 -0
  36. package/dist/daemon.js.map +1 -0
  37. package/dist/diff.d.ts +18 -0
  38. package/dist/diff.d.ts.map +1 -0
  39. package/dist/diff.js +271 -0
  40. package/dist/diff.js.map +1 -0
  41. package/dist/domain-filter.d.ts +28 -0
  42. package/dist/domain-filter.d.ts.map +1 -0
  43. package/dist/domain-filter.js +149 -0
  44. package/dist/domain-filter.js.map +1 -0
  45. package/dist/encryption.d.ts +73 -0
  46. package/dist/encryption.d.ts.map +1 -0
  47. package/dist/encryption.js +171 -0
  48. package/dist/encryption.js.map +1 -0
  49. package/dist/ios-actions.d.ts +11 -0
  50. package/dist/ios-actions.d.ts.map +1 -0
  51. package/dist/ios-actions.js +228 -0
  52. package/dist/ios-actions.js.map +1 -0
  53. package/dist/ios-manager.d.ts +266 -0
  54. package/dist/ios-manager.d.ts.map +1 -0
  55. package/dist/ios-manager.js +1073 -0
  56. package/dist/ios-manager.js.map +1 -0
  57. package/dist/nstbrowser-actions.d.ts +10 -0
  58. package/dist/nstbrowser-actions.d.ts.map +1 -0
  59. package/dist/nstbrowser-actions.js +277 -0
  60. package/dist/nstbrowser-actions.js.map +1 -0
  61. package/dist/nstbrowser-client.d.ts +197 -0
  62. package/dist/nstbrowser-client.d.ts.map +1 -0
  63. package/dist/nstbrowser-client.js +454 -0
  64. package/dist/nstbrowser-client.js.map +1 -0
  65. package/dist/nstbrowser-errors.d.ts +28 -0
  66. package/dist/nstbrowser-errors.d.ts.map +1 -0
  67. package/dist/nstbrowser-errors.js +59 -0
  68. package/dist/nstbrowser-errors.js.map +1 -0
  69. package/dist/nstbrowser-profile-resolver.d.ts +89 -0
  70. package/dist/nstbrowser-profile-resolver.d.ts.map +1 -0
  71. package/dist/nstbrowser-profile-resolver.js +227 -0
  72. package/dist/nstbrowser-profile-resolver.js.map +1 -0
  73. package/dist/nstbrowser-types.d.ts +151 -0
  74. package/dist/nstbrowser-types.d.ts.map +1 -0
  75. package/dist/nstbrowser-types.js +5 -0
  76. package/dist/nstbrowser-types.js.map +1 -0
  77. package/dist/nstbrowser-utils.d.ts +71 -0
  78. package/dist/nstbrowser-utils.d.ts.map +1 -0
  79. package/dist/nstbrowser-utils.js +174 -0
  80. package/dist/nstbrowser-utils.js.map +1 -0
  81. package/dist/protocol.d.ts +26 -0
  82. package/dist/protocol.d.ts.map +1 -0
  83. package/dist/protocol.js +1245 -0
  84. package/dist/protocol.js.map +1 -0
  85. package/dist/snapshot.d.ts +67 -0
  86. package/dist/snapshot.d.ts.map +1 -0
  87. package/dist/snapshot.js +514 -0
  88. package/dist/snapshot.js.map +1 -0
  89. package/dist/state-utils.d.ts +77 -0
  90. package/dist/state-utils.d.ts.map +1 -0
  91. package/dist/state-utils.js +178 -0
  92. package/dist/state-utils.js.map +1 -0
  93. package/dist/stream-server.d.ts +117 -0
  94. package/dist/stream-server.d.ts.map +1 -0
  95. package/dist/stream-server.js +309 -0
  96. package/dist/stream-server.js.map +1 -0
  97. package/dist/types.d.ts +1121 -0
  98. package/dist/types.d.ts.map +1 -0
  99. package/dist/types.js +2 -0
  100. package/dist/types.js.map +1 -0
  101. package/package.json +83 -0
  102. package/scripts/analyze-api-coverage.js +205 -0
  103. package/scripts/analyze-cli-coverage.js +239 -0
  104. package/scripts/build-all-platforms.sh +68 -0
  105. package/scripts/check-version-sync.js +39 -0
  106. package/scripts/copy-native.js +36 -0
  107. package/scripts/download-nstbrowser-docs.js +152 -0
  108. package/scripts/generate-skills.sh +218 -0
  109. package/scripts/postinstall.js +231 -0
  110. package/scripts/sync-version.js +69 -0
  111. package/skills/nstbrowser-ai-agent/SKILL.md +759 -0
  112. package/skills/nstbrowser-ai-agent/references/batch-operations.md +414 -0
  113. package/skills/nstbrowser-ai-agent/references/nst-api-reference.md +960 -0
  114. package/skills/nstbrowser-ai-agent/references/profile-management.md +672 -0
  115. package/skills/nstbrowser-ai-agent/references/proxy-configuration.md +460 -0
  116. package/skills/nstbrowser-ai-agent/references/troubleshooting.md +773 -0
  117. package/skills/nstbrowser-ai-agent/templates/automated-workflow.sh +248 -0
  118. package/skills/nstbrowser-ai-agent/templates/batch-proxy-update.sh +257 -0
  119. package/skills/nstbrowser-ai-agent/templates/profile-setup.sh +248 -0
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for nstbrowser-ai-agent
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 = `nstbrowser-ai-agent-${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 = 'Nstbrowser/nstbrowser-ai-agent';
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, 'nstbrowser-ai-agent');
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
+ let npmBinDir;
191
+ try {
192
+ npmBinDir = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
193
+ } catch {
194
+ return;
195
+ }
196
+
197
+ const cmdShim = join(npmBinDir, 'nstbrowser-ai-agent.cmd');
198
+ const ps1Shim = join(npmBinDir, 'nstbrowser-ai-agent.ps1');
199
+
200
+ // Shims may not exist yet during postinstall (npm creates them after
201
+ // lifecycle scripts). If missing, fall back: the JS wrapper at
202
+ // bin/nstbrowser-ai-agent.js handles Windows correctly via child_process.spawn.
203
+ if (!existsSync(cmdShim)) {
204
+ return;
205
+ }
206
+
207
+ // Detect architecture so ARM64 Windows is handled correctly
208
+ const cpuArch = arch() === 'arm64' ? 'arm64' : 'x64';
209
+ const relativeBinaryPath = `node_modules\\nstbrowser-ai-agent\\bin\\nstbrowser-ai-agent-win32-${cpuArch}.exe`;
210
+ const absoluteBinaryPath = join(npmBinDir, relativeBinaryPath);
211
+
212
+ // Only rewrite shims if the native binary actually exists
213
+ if (!existsSync(absoluteBinaryPath)) {
214
+ return;
215
+ }
216
+
217
+ try {
218
+ const cmdContent = `@ECHO off\r\n"%~dp0${relativeBinaryPath}" %*\r\n`;
219
+ writeFileSync(cmdShim, cmdContent);
220
+
221
+ const ps1Content = `#!/usr/bin/env pwsh\r\n$basedir = Split-Path $MyInvocation.MyCommand.Definition -Parent\r\n& "$basedir\\${relativeBinaryPath}" $args\r\nexit $LASTEXITCODE\r\n`;
222
+ writeFileSync(ps1Shim, ps1Content);
223
+
224
+ console.log('✓ Optimized: shims point to native binary (zero overhead)');
225
+ } catch (err) {
226
+ console.log(`⚠ Could not optimize shims: ${err.message}`);
227
+ console.log(' CLI will work via Node.js wrapper (slightly slower startup)');
228
+ }
229
+ }
230
+
231
+ main().catch(console.error);
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Syncs the version from package.json to all other config files.
5
+ * Run this script before building or releasing.
6
+ */
7
+
8
+ import { execSync } from "child_process";
9
+ import { readFileSync, writeFileSync } from "fs";
10
+ import { dirname, join } from "path";
11
+ import { fileURLToPath } from "url";
12
+
13
+ const __dirname = dirname(fileURLToPath(import.meta.url));
14
+ const rootDir = join(__dirname, "..");
15
+ const cliDir = join(rootDir, "cli");
16
+
17
+ // Read version from package.json (single source of truth)
18
+ const packageJson = JSON.parse(
19
+ readFileSync(join(rootDir, "package.json"), "utf-8")
20
+ );
21
+ const version = packageJson.version;
22
+
23
+ console.log(`Syncing version ${version} to all config files...`);
24
+
25
+ // Update Cargo.toml
26
+ const cargoTomlPath = join(cliDir, "Cargo.toml");
27
+ let cargoToml = readFileSync(cargoTomlPath, "utf-8");
28
+ const cargoVersionRegex = /^version\s*=\s*"[^"]*"/m;
29
+ const newCargoVersion = `version = "${version}"`;
30
+
31
+ let cargoTomlUpdated = false;
32
+ if (cargoVersionRegex.test(cargoToml)) {
33
+ const oldMatch = cargoToml.match(cargoVersionRegex)?.[0];
34
+ if (oldMatch !== newCargoVersion) {
35
+ cargoToml = cargoToml.replace(cargoVersionRegex, newCargoVersion);
36
+ writeFileSync(cargoTomlPath, cargoToml);
37
+ console.log(` Updated cli/Cargo.toml: ${oldMatch} -> ${newCargoVersion}`);
38
+ cargoTomlUpdated = true;
39
+ } else {
40
+ console.log(` cli/Cargo.toml already up to date`);
41
+ }
42
+ } else {
43
+ console.error(" Could not find version field in cli/Cargo.toml");
44
+ process.exit(1);
45
+ }
46
+
47
+ // Update Cargo.lock to match Cargo.toml
48
+ if (cargoTomlUpdated) {
49
+ try {
50
+ execSync("cargo update -p nstbrowser-ai-agent --offline", {
51
+ cwd: cliDir,
52
+ stdio: "pipe",
53
+ });
54
+ console.log(` Updated cli/Cargo.lock`);
55
+ } catch {
56
+ // --offline may fail if package not in cache, try without it
57
+ try {
58
+ execSync("cargo update -p nstbrowser-ai-agent", {
59
+ cwd: cliDir,
60
+ stdio: "pipe",
61
+ });
62
+ console.log(` Updated cli/Cargo.lock`);
63
+ } catch (e) {
64
+ console.error(` Warning: Could not update Cargo.lock: ${e.message}`);
65
+ }
66
+ }
67
+ }
68
+
69
+ console.log("Version sync complete.");