@rigstate/cli 0.7.13 → 0.7.15
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/index.cjs +4 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/daemon/factory.ts +2 -3
- package/src/utils/config.ts +3 -63
package/package.json
CHANGED
package/src/daemon/factory.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GuardianDaemon } from './core.js';
|
|
2
|
-
import { getApiKey, getApiUrl,
|
|
2
|
+
import { getApiKey, getApiUrl, getProjectId } from '../utils/config.js';
|
|
3
3
|
import { loadManifest } from '../utils/manifest.js';
|
|
4
4
|
import { DaemonConfig } from './types.js';
|
|
5
5
|
|
|
@@ -12,8 +12,7 @@ export async function createDaemon(options: {
|
|
|
12
12
|
noBridge?: boolean;
|
|
13
13
|
verbose?: boolean;
|
|
14
14
|
}): Promise<GuardianDaemon> {
|
|
15
|
-
|
|
16
|
-
const apiUrl = await discoverApiUrl();
|
|
15
|
+
const apiUrl = getApiUrl();
|
|
17
16
|
|
|
18
17
|
let projectId = options.project;
|
|
19
18
|
|
package/src/utils/config.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Conf from 'conf';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import chalk from 'chalk';
|
|
2
4
|
|
|
3
5
|
interface RigstateConfig {
|
|
4
6
|
apiKey?: string;
|
|
@@ -9,7 +11,7 @@ interface RigstateConfig {
|
|
|
9
11
|
const config = new Conf<RigstateConfig>({
|
|
10
12
|
projectName: 'rigstate-cli',
|
|
11
13
|
defaults: {
|
|
12
|
-
apiUrl: '
|
|
14
|
+
apiUrl: 'https://app.rigstate.com',
|
|
13
15
|
},
|
|
14
16
|
});
|
|
15
17
|
|
|
@@ -48,12 +50,6 @@ export function setProjectId(projectId: string): void {
|
|
|
48
50
|
config.set('projectId', projectId);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
// Basic check if a port is open - simplistic implementation for now
|
|
52
|
-
// In a real scenario, we might want to actually ping /api/health
|
|
53
|
-
// But for getApiUrl which is synchronous, we cannot easily do async checks.
|
|
54
|
-
// So we will stick to the config/env value, BUT we will expose a separate
|
|
55
|
-
// async function `discoverApiUrl` that the Daemon calls on startup.
|
|
56
|
-
|
|
57
53
|
/**
|
|
58
54
|
* Get the API URL (Synchronous)
|
|
59
55
|
* Priority: Environment variable > Stored config > Production default
|
|
@@ -72,62 +68,6 @@ export function getApiUrl(): string {
|
|
|
72
68
|
return 'https://app.rigstate.com';
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
/**
|
|
76
|
-
* Discovers the active local API URL (Async)
|
|
77
|
-
* Scans ports 3000-3010 to find a responding Rigstate server.
|
|
78
|
-
*/
|
|
79
|
-
export async function discoverApiUrl(): Promise<string> {
|
|
80
|
-
const configuredUrl = getApiUrl();
|
|
81
|
-
|
|
82
|
-
// Dynamic import to avoid top-level await issues
|
|
83
|
-
const { default: axios } = await import('axios');
|
|
84
|
-
const { default: chalk } = await import('chalk');
|
|
85
|
-
|
|
86
|
-
console.log(chalk.gray(`🔍 Discovering local Rigstate API URL... Configured: ${configuredUrl}`));
|
|
87
|
-
|
|
88
|
-
// If not localhost, trust the config
|
|
89
|
-
if (!configuredUrl.includes('localhost') && !configuredUrl.includes('127.0.0.1')) {
|
|
90
|
-
console.log(chalk.gray(` Configured URL is not localhost, trusting: ${configuredUrl}`));
|
|
91
|
-
return configuredUrl;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Try to find the real port
|
|
95
|
-
const ports = [3000, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010];
|
|
96
|
-
|
|
97
|
-
for (const port of ports) {
|
|
98
|
-
const url = `http://localhost:${port}`;
|
|
99
|
-
try {
|
|
100
|
-
console.log(chalk.gray(` Attempting to connect to ${url}/api/v1/system/health...`));
|
|
101
|
-
// Try the health endpoint
|
|
102
|
-
await axios.get(`${url}/api/v1/system/health`, { timeout: 800 });
|
|
103
|
-
|
|
104
|
-
console.log(chalk.green(` ✅ Found Rigstate API at ${url}`));
|
|
105
|
-
if (url !== configuredUrl) {
|
|
106
|
-
console.log(chalk.gray(` Updating stored API URL from ${configuredUrl} to ${url}`));
|
|
107
|
-
// Update config for next time
|
|
108
|
-
setApiUrl(url);
|
|
109
|
-
}
|
|
110
|
-
return url;
|
|
111
|
-
} catch (e: any) {
|
|
112
|
-
// Check if it's a 404 on the health endpoint - if so, it might still be our server
|
|
113
|
-
// But we prefer a positive match on health.
|
|
114
|
-
if (axios.isAxiosError(e) && e.response && e.response.status === 404) {
|
|
115
|
-
console.log(chalk.yellow(` ⚠️ ${url} responded with 404, but might still be a Rigstate server. Skipping for now.`));
|
|
116
|
-
} else if (axios.isAxiosError(e) && e.code === 'ECONNABORTED') {
|
|
117
|
-
console.log(chalk.gray(` Connection to ${url} timed out.`));
|
|
118
|
-
} else if (axios.isAxiosError(e) && e.code === 'ECONNREFUSED') {
|
|
119
|
-
console.log(chalk.gray(` Connection to ${url} refused.`));
|
|
120
|
-
} else {
|
|
121
|
-
console.log(chalk.gray(` Failed to connect to ${url}: ${e.message}`));
|
|
122
|
-
}
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
console.log(chalk.yellow(` ❌ No local Rigstate API found on scanned ports. Falling back to Rigstate Cloud.`));
|
|
128
|
-
return 'https://app.rigstate.com';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
71
|
/**
|
|
132
72
|
* Set the API URL
|
|
133
73
|
*/
|