@cloudverse/aix-cli 1.1.0 → 1.1.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/dist/http.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare function setTokenOverride(token: string | null): void;
2
+ export declare function setBaseUrl(url: string | null): void;
2
3
  export interface HttpConfig {
3
4
  baseUrl: string;
4
5
  token: string | null;
package/dist/http.js CHANGED
@@ -1,11 +1,15 @@
1
1
  const DEFAULT_BASE_URL = 'https://aix.cloudverse.ai';
2
2
  let tokenOverride = null;
3
+ let baseUrlOverride = null;
3
4
  export function setTokenOverride(token) {
4
5
  tokenOverride = token;
5
6
  }
7
+ export function setBaseUrl(url) {
8
+ baseUrlOverride = url ? url.replace(/\/$/, '') : null;
9
+ }
6
10
  export function getConfig() {
7
11
  return {
8
- baseUrl: (process.env.AIX_API_URL || DEFAULT_BASE_URL).replace(/\/$/, ''),
12
+ baseUrl: baseUrlOverride || (process.env.AIX_API_URL || DEFAULT_BASE_URL).replace(/\/$/, ''),
9
13
  token: tokenOverride || process.env.AIX_TOKEN || null,
10
14
  };
11
15
  }
@@ -19,17 +23,31 @@ export async function request(method, path, body) {
19
23
  if (config.token) {
20
24
  headers['Authorization'] = `Bearer ${config.token}`;
21
25
  }
22
- const res = await fetch(url, {
23
- method,
24
- headers,
25
- body: body ? JSON.stringify(body) : undefined,
26
- });
27
- let data;
26
+ let res;
28
27
  try {
29
- data = await res.json();
28
+ res = await fetch(url, {
29
+ method,
30
+ headers,
31
+ body: body ? JSON.stringify(body) : undefined,
32
+ });
33
+ }
34
+ catch (err) {
35
+ throw new Error(`Cannot connect to ${config.baseUrl}: ${err.message || err}`);
36
+ }
37
+ let data;
38
+ const contentType = res.headers.get('content-type') || '';
39
+ if (contentType.includes('application/json')) {
40
+ try {
41
+ data = await res.json();
42
+ }
43
+ catch {
44
+ data = { error: `Failed to parse JSON response (HTTP ${res.status})` };
45
+ }
30
46
  }
31
- catch {
32
- data = { error: `HTTP ${res.status}: ${res.statusText}` };
47
+ else {
48
+ const text = await res.text().catch(() => '');
49
+ data = { error: `Server returned non-JSON response (HTTP ${res.status})`, body: text.slice(0, 200) };
50
+ return { ok: false, status: res.status, data };
33
51
  }
34
52
  return { ok: res.ok, status: res.status, data };
35
53
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
- import { request, exitWithError, getConfig } from './http.js';
3
+ import { request, exitWithError, getConfig, setBaseUrl } from './http.js';
4
4
  import { formatDecision, formatExplanation, formatHealth, formatPolicy, formatCatalogStatus } from './formatters.js';
5
5
  import { loadTokens, saveTokens, clearTokens, refreshIfNeeded } from './auth.js';
6
6
  const program = new Command();
@@ -13,17 +13,30 @@ program
13
13
  .description('Authenticate with AIX via browser-based device login')
14
14
  .option('--api-url <url>', 'AIX server URL (default: https://aix.cloudverse.ai)')
15
15
  .action(async (opts) => {
16
+ if (opts.apiUrl) {
17
+ setBaseUrl(opts.apiUrl);
18
+ }
16
19
  const config = getConfig();
17
- const baseUrl = opts.apiUrl || config.baseUrl;
20
+ const baseUrl = config.baseUrl;
18
21
  console.log('\n\x1b[1mAIX Device Login\x1b[0m');
19
22
  console.log('─'.repeat(50));
20
- const startRes = await request('POST', '/api/auth/device/start', {
21
- cli_version: '1.0.0',
22
- });
23
+ console.log(` Server: ${baseUrl}\n`);
24
+ let startRes;
25
+ try {
26
+ startRes = await request('POST', '/api/auth/device/start', {
27
+ cli_version: '1.1.0',
28
+ });
29
+ }
30
+ catch (err) {
31
+ exitWithError(`Cannot connect to AIX server at ${baseUrl}`, `Network error: ${err.message}\n Try: aix login --api-url https://your-server-url`);
32
+ }
23
33
  if (!startRes.ok) {
24
34
  exitWithError('Failed to start device login', JSON.stringify(startRes.data, null, 2));
25
35
  }
26
36
  const { device_code, user_code, verification_uri, verification_uri_complete, interval, expires_in } = startRes.data;
37
+ if (!user_code || !verification_uri_complete || !device_code) {
38
+ exitWithError('Unexpected response from server (missing device login fields)', `Server may not support device login, or the URL is incorrect.\n Server: ${baseUrl}\n Response: ${JSON.stringify(startRes.data, null, 2)}\n Try: aix login --api-url https://your-server-url`);
39
+ }
27
40
  console.log(`\n Your verification code:\n`);
28
41
  console.log(` \x1b[1m\x1b[36m${user_code}\x1b[0m\n`);
29
42
  console.log(` Opening browser to:\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudverse/aix-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "AIX Brain Decision Engine CLI - decision-only surface for AI workload routing",
5
5
  "type": "module",
6
6
  "bin": {