nstantpage-agent 0.5.8 → 0.5.10

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/cli.js CHANGED
@@ -25,7 +25,7 @@ const program = new Command();
25
25
  program
26
26
  .name('nstantpage')
27
27
  .description('Local development agent for nstantpage.com — run projects on your machine, preview in the cloud')
28
- .version('0.5.8');
28
+ .version('0.5.9');
29
29
  program
30
30
  .command('login')
31
31
  .description('Authenticate with nstantpage.com')
@@ -24,7 +24,7 @@ import { getConfig, getProjectConfig, setProjectConfig, clearProjectConfig, getD
24
24
  import { TunnelClient } from '../tunnel.js';
25
25
  import { LocalServer } from '../localServer.js';
26
26
  import { PackageInstaller } from '../packageInstaller.js';
27
- const VERSION = '0.5.8';
27
+ const VERSION = '0.5.9';
28
28
  /**
29
29
  * Resolve the backend API base URL.
30
30
  * - If --backend is passed, use it
@@ -582,18 +582,35 @@ async function startAdditionalProject(projectId, opts) {
582
582
  // Ensure ports are clear for this project before starting
583
583
  cleanupPreviousAgent(projectId, allocated.apiPort, allocated.devPort);
584
584
  await new Promise(r => setTimeout(r, 50));
585
- // ── Phase 1: Fetch files + start API server in parallel ──────────
585
+ // ── Phase 1: API server + file fetch + tunnel connect (all parallel) ──
586
586
  progress('fetching-files', 'Fetching project files...');
587
587
  const localServer = new LocalServer({
588
588
  projectDir, projectId,
589
589
  apiPort: allocated.apiPort, devPort: allocated.devPort,
590
590
  });
591
- // Start API server immediately (doesn't need project files)
591
+ const tunnel = new TunnelClient({
592
+ gatewayUrl: opts.gatewayUrl,
593
+ token: opts.token,
594
+ projectId,
595
+ apiPort: allocated.apiPort,
596
+ devPort: allocated.devPort,
597
+ });
598
+ // Launch API server, tunnel, and file fetch all in parallel
592
599
  const apiServerPromise = localServer.start().then(() => {
593
600
  timings['api-server'] = Date.now() - t0;
594
601
  console.log(chalk.green(` ✓ API server on port ${allocated.apiPort} (${timings['api-server']}ms)`));
595
602
  });
596
- // Fetch project files concurrently with API server start
603
+ const tunnelPromise = (async () => {
604
+ try {
605
+ await tunnel.connect();
606
+ timings['tunnel'] = Date.now() - t0;
607
+ console.log(chalk.green(` ✓ Tunnel connected for project ${projectId} (${timings['tunnel']}ms)`));
608
+ }
609
+ catch (err) {
610
+ console.log(chalk.yellow(` ⚠ Tunnel: ${err.message}`));
611
+ tunnel.startBackgroundReconnect();
612
+ }
613
+ })();
597
614
  const fileStart = Date.now();
598
615
  try {
599
616
  await fetchProjectFiles(opts.backendUrl, projectId, projectDir, opts.token);
@@ -604,7 +621,7 @@ async function startAdditionalProject(projectId, opts) {
604
621
  console.log(chalk.yellow(` ⚠ Could not fetch files: ${err.message}`));
605
622
  progress('fetching-files', `Warning: ${err.message}`);
606
623
  }
607
- // Wait for API server before proceeding
624
+ // Wait for API server before proceeding (tunnel can keep connecting in background)
608
625
  await apiServerPromise;
609
626
  progress('starting-server', `API server ready`);
610
627
  // ── Phase 2: Install deps (if needed) ────────────────────────────
@@ -630,30 +647,7 @@ async function startAdditionalProject(projectId, opts) {
630
647
  else {
631
648
  progress('installing-deps', 'Dependencies already installed (cached)');
632
649
  }
633
- // ── Phase 3: Start dev server + connect tunnel in parallel ───────
634
- const tunnel = new TunnelClient({
635
- gatewayUrl: opts.gatewayUrl,
636
- token: opts.token,
637
- projectId,
638
- apiPort: allocated.apiPort,
639
- devPort: allocated.devPort,
640
- });
641
- // Connect tunnel immediately (don't wait for dev server — tunnel is needed for status updates)
642
- const tunnelPromise = (async () => {
643
- progress('connecting', 'Connecting tunnel to gateway...');
644
- try {
645
- await tunnel.connect();
646
- timings['tunnel'] = Date.now() - t0;
647
- console.log(chalk.green(` ✓ Tunnel connected for project ${projectId} (${timings['tunnel']}ms)`));
648
- progress('connecting', 'Tunnel connected');
649
- }
650
- catch (err) {
651
- console.log(chalk.yellow(` ⚠ Tunnel: ${err.message}`));
652
- tunnel.startBackgroundReconnect();
653
- progress('connecting', `Warning: ${err.message} — reconnecting`);
654
- }
655
- })();
656
- // Start dev server in parallel with tunnel connection
650
+ // ── Phase 3: Start dev server ────────────────────────────────────
657
651
  if (!opts.noDev) {
658
652
  if (installer.areDependenciesInstalled()) {
659
653
  progress('starting-dev', 'Starting dev server...');
@@ -675,7 +669,7 @@ async function startAdditionalProject(projectId, opts) {
675
669
  progress('starting-dev', 'Skipped — dependencies not installed');
676
670
  }
677
671
  }
678
- // Wait for tunnel to be connected
672
+ // Ensure tunnel is connected before declaring ready
679
673
  await tunnelPromise;
680
674
  // Register project with backend (non-blocking)
681
675
  fetch(`${opts.backendUrl}/api/agent/register`, {
@@ -592,7 +592,7 @@ export class LocalServer {
592
592
  connected: true,
593
593
  projectId: this.options.projectId,
594
594
  agent: {
595
- version: '0.5.8',
595
+ version: '0.5.9',
596
596
  hostname: os.hostname(),
597
597
  platform: `${os.platform()} ${os.arch()}`,
598
598
  },
package/dist/tunnel.js CHANGED
@@ -63,7 +63,7 @@ export class TunnelClient {
63
63
  // Send enhanced agent info with capabilities and deviceId
64
64
  this.send({
65
65
  type: 'agent-info',
66
- version: '0.5.8',
66
+ version: '0.5.9',
67
67
  hostname: os.hostname(),
68
68
  platform: `${os.platform()} ${os.arch()}`,
69
69
  deviceId: getDeviceId(),
@@ -163,11 +163,12 @@ export class TunnelClient {
163
163
  handleWsOpen(wsId, sessionId, _projectId) {
164
164
  const session = getTerminalSession(sessionId);
165
165
  if (!session) {
166
- // Session not found — send error and close
166
+ // Session not found — send a 'closed' event (not 'error') so
167
+ // the frontend stops reconnecting instead of showing a red banner.
167
168
  this.send({
168
169
  type: 'ws-data',
169
170
  wsId,
170
- data: JSON.stringify({ type: 'error', message: `Session ${sessionId} not found` }),
171
+ data: JSON.stringify({ type: 'closed', message: `Session ${sessionId} no longer exists`, sessionNotFound: true }),
171
172
  });
172
173
  this.send({ type: 'ws-close', wsId });
173
174
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nstantpage-agent",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Local development agent for nstantpage.com — run your projects locally, preview in the cloud. Replaces cloud containers for faster builds.",
5
5
  "type": "module",
6
6
  "bin": {