upfynai-code 2.7.5 → 2.8.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/src/launch.js CHANGED
@@ -3,6 +3,11 @@ import chalk from 'chalk';
3
3
  import { readConfig } from './config.js';
4
4
  import { getToken, validateToken } from './auth.js';
5
5
  import { startServer } from './server.js';
6
+ import { spawn } from 'child_process';
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname, join } from 'path';
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
11
 
7
12
  export async function openHosted() {
8
13
  const token = getToken();
@@ -31,24 +36,43 @@ export async function openHosted() {
31
36
  }
32
37
 
33
38
  export async function startLocal() {
34
- const token = getToken();
39
+ const config = readConfig();
40
+ const port = config.localPort || 3001;
35
41
 
36
- if (!token) {
37
- console.log(chalk.yellow('\n No account found. Run `uc login` first.\n'));
38
- process.exit(1);
39
- }
42
+ console.log(chalk.dim('\n Starting local server...'));
40
43
 
41
- console.log(chalk.dim('\n Validating session...'));
42
- const user = await validateToken();
44
+ // Try the new local-server package first
45
+ const localServerPath = join(__dirname, '../../local-server/index.js');
43
46
 
44
- if (!user) {
45
- console.log(chalk.yellow(' Session expired. Run `uc login` to re-authenticate.\n'));
46
- process.exit(1);
47
- }
47
+ try {
48
+ // Dynamically import the local server
49
+ process.env.PORT = String(port);
50
+ await import(localServerPath);
48
51
 
49
- const config = readConfig();
50
- const name = user.first_name || user.username;
51
- console.log(chalk.green(` Welcome back, ${chalk.bold(name)}!`));
52
+ // Auto-open browser after server starts
53
+ setTimeout(async () => {
54
+ const url = `http://localhost:${port}`;
55
+ console.log(chalk.dim(` Opening ${url} in browser...\n`));
56
+ await open(url);
57
+ }, 2000);
58
+ } catch (err) {
59
+ // Fallback: if local-server fails (missing deps), use the old proxy approach
60
+ console.log(chalk.dim(` Local server not available (${err.message}), falling back to proxy mode...`));
61
+
62
+ const token = getToken();
63
+ if (!token) {
64
+ console.log(chalk.yellow('\n No account found. Run `uc login` first.\n'));
65
+ process.exit(1);
66
+ }
52
67
 
53
- await startServer(config.localPort, config.serverUrl, token);
68
+ const user = await validateToken();
69
+ if (!user) {
70
+ console.log(chalk.yellow(' Session expired. Run `uc login` to re-authenticate.\n'));
71
+ process.exit(1);
72
+ }
73
+
74
+ const name = user.first_name || user.username;
75
+ console.log(chalk.green(` Welcome back, ${chalk.bold(name)}!`));
76
+ await startServer(port, config.serverUrl, token);
77
+ }
54
78
  }