nstbrowser-ai-agent 0.0.3 → 0.0.5

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 CHANGED
@@ -46,6 +46,9 @@ export NST_API_KEY="YOUR_API_KEY"
46
46
  Test your configuration:
47
47
 
48
48
  ```bash
49
+ # Check if NST agent is running
50
+ nstbrowser-ai-agent nst status
51
+
49
52
  # Check CLI version
50
53
  nstbrowser-ai-agent --version
51
54
 
@@ -129,6 +132,44 @@ pnpm link --global # Makes nstbrowser-ai-agent available globally
129
132
  nstbrowser-ai-agent install
130
133
  ```
131
134
 
135
+ ## Updates
136
+
137
+ ### Automatic Update Checks
138
+
139
+ The CLI automatically checks for updates once every 24 hours and notifies you when a new version is available.
140
+
141
+ **Disable automatic checks:**
142
+ ```bash
143
+ export NSTBROWSER_AI_AGENT_NO_UPDATE_CHECK=1
144
+ ```
145
+
146
+ ### Manual Update Check
147
+
148
+ Check for updates manually:
149
+
150
+ ```bash
151
+ # Human-readable output
152
+ nstbrowser-ai-agent update check
153
+
154
+ # JSON output
155
+ nstbrowser-ai-agent update check --json
156
+ ```
157
+
158
+ ### Updating
159
+
160
+ When an update is available:
161
+
162
+ ```bash
163
+ # If installed globally
164
+ npm install -g nstbrowser-ai-agent@latest
165
+
166
+ # If using npx
167
+ npx nstbrowser-ai-agent@latest
168
+
169
+ # If installed locally in project
170
+ npm install nstbrowser-ai-agent@latest
171
+ ```
172
+
132
173
  ### Linux Dependencies
133
174
 
134
175
  On Linux, install system dependencies:
@@ -185,6 +226,119 @@ nstbrowser-ai-agent click @e1
185
226
  nstbrowser-ai-agent close
186
227
  ```
187
228
 
229
+ ### Profile Specification for Browser Actions
230
+
231
+ **All browser actions** (open, click, fill, type, etc.) support specifying a profile name or ID. The CLI will automatically handle profile resolution and browser startup.
232
+
233
+ #### Profile Resolution Priority
234
+
235
+ When you specify a profile for a browser action, the system follows these rules:
236
+
237
+ 1. **Check running browsers** - First, it looks for a browser already running with the specified name or ID
238
+ - If multiple browsers match a name, the earliest started browser is used
239
+ - Profile IDs always uniquely match a single browser
240
+
241
+ 2. **Start browser if not running** - If the profile exists but isn't running, the browser is automatically started
242
+
243
+ 3. **Create profile if name doesn't exist** - If you specify a profile **name** that doesn't exist, a new profile is automatically created
244
+ - This makes it easy to create profiles on-the-fly
245
+
246
+ 4. **Error if ID doesn't exist** - If you specify a profile **ID** that doesn't exist, an error is thrown
247
+ - Profile IDs are expected to be exact matches
248
+
249
+ 5. **Use once browser if no profile specified** - If no profile is specified:
250
+ - Uses an existing "once" (temporary) browser if one is running
251
+ - Otherwise creates a new temporary browser
252
+ - Temporary browsers don't persist session data
253
+
254
+ #### UUID Format Auto-Detection
255
+
256
+ **Important:** The system automatically detects UUID format in profile names and treats them as profile IDs.
257
+
258
+ ```bash
259
+ # These are equivalent (UUID format detected):
260
+ nstbrowser-ai-agent open https://example.com --nst-profile "ef2b083a-8f77-4a7f-8441-a8d56bbd832b"
261
+ nstbrowser-ai-agent open https://example.com --nst-profile-id "ef2b083a-8f77-4a7f-8441-a8d56bbd832b"
262
+
263
+ # Also works with environment variables:
264
+ export NST_PROFILE="ef2b083a-8f77-4a7f-8441-a8d56bbd832b" # Treated as ID
265
+ ```
266
+
267
+ This means:
268
+ - You can use `--nst-profile` with either names or IDs
269
+ - UUID format (8-4-4-4-12 hex digits) is automatically recognized
270
+ - Case-insensitive: both lowercase and uppercase UUIDs work
271
+ - Prevents accidental profile creation when you meant to use an ID
272
+
273
+ #### Specifying Profiles
274
+
275
+ You can specify profiles in three ways:
276
+
277
+ **1. Environment Variables (Global Default)**
278
+ ```bash
279
+ export NST_PROFILE="my-profile" # Use profile name
280
+ # OR
281
+ export NST_PROFILE_ID="abc-123-def" # Use profile ID
282
+
283
+ # All browser actions will use this profile
284
+ nstbrowser-ai-agent open https://example.com
285
+ nstbrowser-ai-agent click "#button"
286
+ ```
287
+
288
+ **2. Command-Line Flags (Per-Action)**
289
+ ```bash
290
+ # By profile name
291
+ nstbrowser-ai-agent open https://example.com --nst-profile "my-profile"
292
+ nstbrowser-ai-agent click "#button" --nst-profile "my-profile"
293
+
294
+ # By profile ID
295
+ nstbrowser-ai-agent open https://example.com --nst-profile-id "abc-123-def"
296
+ nstbrowser-ai-agent fill "#email" "test@test.com" --nst-profile-id "abc-123-def"
297
+
298
+ # UUID format auto-detected (treated as ID)
299
+ nstbrowser-ai-agent open https://example.com --nst-profile "ef2b083a-8f77-4a7f-8441-a8d56bbd832b"
300
+ ```
301
+
302
+ **3. Mixed Approach**
303
+ ```bash
304
+ # Set default profile
305
+ export NST_PROFILE="default-profile"
306
+
307
+ # Most commands use the default
308
+ nstbrowser-ai-agent open https://example.com
309
+
310
+ # Override for specific commands
311
+ nstbrowser-ai-agent click "#button" --nst-profile "other-profile"
312
+ ```
313
+
314
+ #### Examples
315
+
316
+ **Auto-create profile on first use:**
317
+ ```bash
318
+ # This will create "test-profile" if it doesn't exist
319
+ nstbrowser-ai-agent open https://example.com --nst-profile "test-profile"
320
+ nstbrowser-ai-agent click "#login" --nst-profile "test-profile"
321
+ ```
322
+
323
+ **Use existing profile by ID:**
324
+ ```bash
325
+ # List profiles to find ID
326
+ nstbrowser-ai-agent profile list
327
+
328
+ # Use specific profile ID
329
+ nstbrowser-ai-agent open https://example.com --nst-profile-id "abc-123-def"
330
+ ```
331
+
332
+ **Reuse running browser:**
333
+ ```bash
334
+ # Start a browser with a profile
335
+ nstbrowser-ai-agent open https://example.com --nst-profile "my-profile"
336
+
337
+ # Later commands automatically connect to the same running browser
338
+ nstbrowser-ai-agent click "#button" --nst-profile "my-profile"
339
+ # No restart needed - uses existing browser!
340
+ ```
341
+
188
342
  ## Default Provider
189
343
 
190
344
  By default, nstbrowser-ai-agent uses **Nstbrowser** as the browser provider. This means you don't need to specify `-p nst` every time - it's automatic.
@@ -495,6 +649,20 @@ Configuration is stored in `~/.nst-ai-agent/config.json` and takes priority over
495
649
 
496
650
  **Priority order:** Config file > Environment variables > Defaults
497
651
 
652
+ ### Check NST Agent Status
653
+
654
+ Verify that NST agent is running and responsive:
655
+
656
+ ```bash
657
+ # Check NST agent status
658
+ nstbrowser-ai-agent nst status
659
+
660
+ # JSON output
661
+ nstbrowser-ai-agent nst status --json
662
+ ```
663
+
664
+ This command uses the `/api/agent/agent/info` endpoint to verify the NST service is accessible.
665
+
498
666
  ## Persistent Profiles
499
667
 
500
668
  By default, browser state (cookies, localStorage, login sessions) is ephemeral and lost when the browser closes. Use `--profile` to persist state across browser restarts:
Binary file
Binary file
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAqBpE,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EAsIT,MAAM,YAAY,CAAC;AAQpB;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC,GAAG,IAAI,GAClD,IAAI,CAEN;AAQD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAqDzE;AAKD,wBAAgB,gBAAgB,IAAI,IAAI,CAuBvC;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6CjG"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAwBpE,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EAsIT,MAAM,YAAY,CAAC;AAQpB;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC,GAAG,IAAI,GAClD,IAAI,CAEN;AAQD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAqDzE;AAKD,wBAAgB,gBAAgB,IAAI,IAAI,CAuBvC;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CA2DjG"}
package/dist/actions.js CHANGED
@@ -2,6 +2,9 @@ import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { mkdirSync } from 'node:fs';
4
4
  import { getAppDir } from './daemon.js';
5
+ import { resolveBrowserProfile, extractProfileOptions } from './browser-profile-resolver.js';
6
+ import { NstbrowserClient } from './nstbrowser-client.js';
7
+ import { loadNstConfig } from './config-loader.js';
5
8
  import { checkPolicy, describeAction, getActionCategory, loadPolicyFile, initPolicyReloader, reloadPolicyIfChanged, } from './action-policy.js';
6
9
  import { requestConfirmation, getAndRemovePending } from './confirmation.js';
7
10
  import { getAuthProfile, updateLastLogin } from './auth-vault.js';
@@ -111,6 +114,17 @@ export async function executeCommand(command, browser) {
111
114
  confirmation_id: confirmationId,
112
115
  });
113
116
  }
117
+ // === Profile-Aware Browser Action Handling ===
118
+ // Check if this is a browser action command that needs profile resolution
119
+ // Skip launch command as it already handles its own profile resolution
120
+ if (command.action !== 'launch' &&
121
+ command.action !== 'state_list' &&
122
+ command.action !== 'state_show' &&
123
+ command.action !== 'state_clean' &&
124
+ command.action !== 'state_clear' &&
125
+ command.action !== 'state_rename') {
126
+ await ensureBrowserWithProfile(command, browser);
127
+ }
114
128
  return await dispatchAction(command, browser);
115
129
  }
116
130
  catch (error) {
@@ -118,6 +132,68 @@ export async function executeCommand(command, browser) {
118
132
  return errorResponse(command.id, message);
119
133
  }
120
134
  }
135
+ /**
136
+ * Ensure browser is launched with the correct profile before executing an action
137
+ * Implements the unified profile resolution logic for all browser actions
138
+ */
139
+ async function ensureBrowserWithProfile(command, browser) {
140
+ const cmdWithProfile = command;
141
+ // Check if command has profile specifications or environment variables are set
142
+ const hasProfileSpec = !!cmdWithProfile.nstProfileName ||
143
+ !!cmdWithProfile.nstProfileId ||
144
+ !!process.env.NST_PROFILE ||
145
+ !!process.env.NST_PROFILE_ID;
146
+ // Only proceed with profile resolution if:
147
+ // 1. Profile is explicitly specified in the command OR
148
+ // 2. Environment variables are set OR
149
+ // 3. We're using NST provider (default or explicit)
150
+ const provider = process.env.NSTBROWSER_AI_AGENT_PROVIDER;
151
+ const isNstProvider = !provider || provider === 'nst'; // Default is NST
152
+ if (!hasProfileSpec && !isNstProvider) {
153
+ // Not NST provider and no profile specified, skip profile resolution
154
+ return;
155
+ }
156
+ // If browser is not launched or needs reconnection, launch with profile
157
+ if (!browser.isLaunched()) {
158
+ const config = loadNstConfig();
159
+ if (!config) {
160
+ // NST not configured, skip profile resolution (will use local browser)
161
+ if (process.env.NSTBROWSER_AI_AGENT_DEBUG === '1') {
162
+ console.error('[DEBUG] NST not configured, skipping profile resolution');
163
+ }
164
+ return;
165
+ }
166
+ // Launch browser with profile resolution
167
+ const client = new NstbrowserClient(config.host, config.port, config.apiKey);
168
+ try {
169
+ const profileOptions = extractProfileOptions(cmdWithProfile, config.host, config.port, config.apiKey);
170
+ const resolved = await resolveBrowserProfile(client, profileOptions);
171
+ if (process.env.NSTBROWSER_AI_AGENT_DEBUG === '1') {
172
+ console.error('[DEBUG] Resolved profile for action:', {
173
+ action: command.action,
174
+ profileId: resolved.profileId,
175
+ profileName: resolved.profileName,
176
+ isOnce: resolved.isOnce,
177
+ wasCreated: resolved.wasCreated,
178
+ });
179
+ }
180
+ // Launch browser with the resolved profile
181
+ await browser.launch({
182
+ id: command.id,
183
+ action: 'launch',
184
+ provider: 'nst',
185
+ nstProfileId: resolved.profileId,
186
+ nstProfileName: resolved.profileName,
187
+ });
188
+ }
189
+ catch (error) {
190
+ if (process.env.NSTBROWSER_AI_AGENT_DEBUG === '1') {
191
+ console.error('[DEBUG] Profile resolution failed:', error);
192
+ }
193
+ throw error;
194
+ }
195
+ }
196
+ }
121
197
  /**
122
198
  * Dispatch a command to its handler after policy checks have passed.
123
199
  */