@aivin-labs/cli 1.0.50 → 1.0.51

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
@@ -243,7 +243,7 @@ my-plugin/
243
243
  | :--- | :--- | :--- |
244
244
  | `SDK_ENDPOINT` | SDK gRPC connection | `sdk.aivin.cloud:443` |
245
245
  | `AIVIN_BASE_URL` | API endpoints (`deploy`, `test`, `login`) | `https://api.aivin.cloud` |
246
- | `AIVIN_WEB_URL` | Web dashboard & browser login | `https://brain.aivin.cloud` |
246
+ | `AIVIN_WEB_URL` | Web dashboard & browser login | `https://app.aivin.cloud` |
247
247
  | `LOCAL_TEST_PORT` | Local test HTTP port (`aivin start`) | `4001` |
248
248
  | `LOCAL_TEST_HOST` | Local test bind host | `127.0.0.1` |
249
249
  | `AIVIN_SANDBOX_WORKER` | Isolated thread execution | `false` |
package/bin/cli.mjs CHANGED
@@ -910,7 +910,7 @@ program
910
910
  // returns null - warn instead of silently opening the PRODUCTION web app's login page,
911
911
  // which would mint a key for the wrong server without any indication why.
912
912
  console.log(chalk.yellow(`⚠️ Couldn't reach ${resolvedBaseUrl} to resolve its web app URL - check the host is correct.`));
913
- console.log(chalk.yellow(` Falling back to the production web app (https://brain.aivin.cloud) - the key it mints will still be saved against ${resolvedBaseUrl}, likely NOT what you want.`));
913
+ console.log(chalk.yellow(` Falling back to the production web app (https://app.aivin.cloud) - the key it mints will still be saved against ${resolvedBaseUrl}, likely NOT what you want.`));
914
914
  }
915
915
  }
916
916
 
package/bin/lib/auth.mjs CHANGED
@@ -58,7 +58,7 @@ export function openBrowser(url) {
58
58
  export async function browserLogin() {
59
59
  // Defaults to the production web app - override with AIVIN_WEB_URL only if you're pointing at a
60
60
  // local/dev/staging frontend instead.
61
- const webBaseUrl = process.env.AIVIN_WEB_URL || 'https://brain.aivin.cloud';
61
+ const webBaseUrl = process.env.AIVIN_WEB_URL || 'https://app.aivin.cloud';
62
62
 
63
63
  const state = randomBytes(16).toString('hex');
64
64
  let resolveKey, rejectKey;
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import os from 'os';
4
4
  import axios from 'axios';
5
5
  import { execFileSync } from 'child_process';
6
- import { readActiveServer, resolveServerUrl, serverKey, setActiveServer } from './servers.mjs';
6
+ import { readActiveServer, resolveServerUrl, serverKey, setActiveServer, webUrlForServer } from './servers.mjs';
7
7
 
8
8
  export const GLOBAL_CREDENTIALS_PATH = path.join(os.homedir(), '.aivin', 'credentials');
9
9
  export const DEFAULT_AIVIN_BASE_URL = 'https://api.aivin.cloud';
@@ -19,7 +19,7 @@ export function deriveSdkEndpoint(baseUrl) {
19
19
  export async function fetchWebUrl(baseUrl) {
20
20
  try {
21
21
  const res = await axios.get(`${resolveServerUrl(baseUrl)}/setting/lang/default`, { timeout: 5000 });
22
- return typeof res.data?.app_url === 'string' && res.data.app_url ? res.data.app_url : null;
22
+ return typeof res.data?.app_url === 'string' && res.data.app_url ? webUrlForServer(baseUrl, res.data.app_url) : null;
23
23
  } catch { return null; }
24
24
  }
25
25
 
@@ -94,4 +94,4 @@ export function saveActiveContext(baseUrl, apiKey, identity = {}) {
94
94
  writeCredentialStore(store);
95
95
  setActiveServer(normalized);
96
96
  return store.contexts[serverKey(normalized)].sdk_endpoint;
97
- }
97
+ }
@@ -4,6 +4,7 @@ import path from 'path';
4
4
  import axios from 'axios';
5
5
  import { createHash } from 'crypto';
6
6
  import { fetchWebUrl } from './context.mjs';
7
+ import { defaultWebUrl } from './servers.mjs';
7
8
  import { startPreviewServer } from './localPreview.mjs';
8
9
  import { missionAuthHeaders, missionServerUrl, resolveWorkspace } from './workspace.mjs';
9
10
  import { spawn } from 'child_process';
@@ -21,7 +22,7 @@ import { mascotLang } from './remote/mascot/strings.mjs';
21
22
 
22
23
  export const OPEN_INDEX_FILE = path.join(os.homedir(), '.aivin', 'opened-files.json');
23
24
  const MAX_INDEX_ENTRIES = 500;
24
- const DEFAULT_WEB_URL = 'https://brain.aivin.cloud';
25
+ const DEFAULT_WEB_URL = 'https://app.aivin.cloud';
25
26
 
26
27
  export const OpenDisplay = Object.freeze({ WINDOW: 'window', TAB: 'tab', NONE: 'none' });
27
28
 
@@ -175,7 +176,7 @@ function showUrl(url, mode) {
175
176
  }
176
177
 
177
178
  async function resolveWebUrl(serverUrl) {
178
- return process.env.AIVIN_WEB_URL || (await fetchWebUrl(serverUrl)) || DEFAULT_WEB_URL;
179
+ return process.env.AIVIN_WEB_URL || (await fetchWebUrl(serverUrl)) || defaultWebUrl(serverUrl) || DEFAULT_WEB_URL;
179
180
  }
180
181
 
181
182
  /**
@@ -217,6 +217,22 @@ namespace AivinDesktop {
217
217
  }
218
218
  }
219
219
 
220
+ // WinForms không tính Padding của mục vào bề rộng cửa sổ menu, nên mục rộng hơn cửa sổ; menu con lại đặt theo bề rộng mục nên bị hở xa menu cha.
221
+ class SubmenuItem : ToolStripMenuItem {
222
+ public SubmenuItem(string text) : base(text) { }
223
+
224
+ protected override Point DropDownLocation {
225
+ get {
226
+ Point location = base.DropDownLocation;
227
+ if (Owner == null) return location;
228
+ int overflow = Bounds.Right - Owner.ClientSize.Width;
229
+ // Menu con bật sang trái (sát mép phải màn hình) thì không dính phần thừa này.
230
+ if (overflow > 0 && location.X > Owner.PointToScreen(Bounds.Location).X) location.X -= overflow;
231
+ return location;
232
+ }
233
+ }
234
+ }
235
+
220
236
  class ModernMenuRenderer : ToolStripProfessionalRenderer {
221
237
  static readonly Color ClrBorder = Color.FromArgb(229, 230, 235);
222
238
  static readonly Color ClrHover = Color.FromArgb(242, 243, 245);
@@ -426,7 +442,8 @@ namespace AivinDesktop {
426
442
  mascot = Item(cfg.T("mascot"), delegate { ToggleMascot(); });
427
443
  pause = Item("", delegate { TogglePause(); });
428
444
  terminal = Item(cfg.T("terminal"), delegate { OpenTerminal(); });
429
- serverMenu = Item(cfg.T("server"), delegate { });
445
+ serverMenu = new SubmenuItem(cfg.T("server"));
446
+ serverMenu.Padding = new Padding(16, 6, 24, 6);
430
447
  serverCloud = Item(cfg.T("serverCloud"), delegate { ChangeServer("https://api.aivin.cloud"); });
431
448
  serverVn = Item(cfg.T("serverVn"), delegate { ChangeServer("https://api.aivin.vn"); });
432
449
  serverLocal = Item(cfg.T("serverLocal"), delegate { ChangeServer("http://localhost:3001"); });
@@ -932,6 +949,9 @@ namespace AivinDesktop {
932
949
  static string PlatformUrl() {
933
950
  string api = CurrentServerUrl();
934
951
  api = CanonicalServerUrl(api);
952
+ string apiZone = null;
953
+ Uri apiUri;
954
+ if (Uri.TryCreate(api, UriKind.Absolute, out apiUri)) apiZone = AivinZone(apiUri.Host);
935
955
  try {
936
956
  ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
937
957
  using (WebClient client = new WebClient()) {
@@ -942,13 +962,20 @@ namespace AivinDesktop {
942
962
  if (appUrl.Success) {
943
963
  string value = Regex.Unescape(appUrl.Groups[1].Value);
944
964
  Uri uri;
945
- if (Uri.TryCreate(value, UriKind.Absolute, out uri) && uri.Scheme == Uri.UriSchemeHttps) return uri.ToString().TrimEnd('/');
965
+ // May chu Aivin chinh thuc chi duoc mo web cung goc ten mien (api.aivin.vn khong mo *.aivin.cloud).
966
+ if (Uri.TryCreate(value, UriKind.Absolute, out uri) && uri.Scheme == Uri.UriSchemeHttps && (apiZone == null || AivinZone(uri.Host) == apiZone)) return uri.ToString().TrimEnd('/');
946
967
  }
947
968
  }
948
969
  } catch { }
949
- if (api == "https://api.aivin.vn") return "https://app.aivin.vn";
950
- if (api == "https://api.aivin.cloud") return "https://brain.aivin.cloud";
951
- return "https://brain.aivin.cloud";
970
+ if (apiZone == "aivin.vn") return "https://app.aivin.vn";
971
+ return "https://app.aivin.cloud";
972
+ }
973
+
974
+ static string AivinZone(string host) {
975
+ string value = host.ToLowerInvariant();
976
+ foreach (string zone in new string[] { "aivin.vn", "aivin.cloud" })
977
+ if (value == zone || value.EndsWith("." + zone, StringComparison.Ordinal)) return zone;
978
+ return null;
952
979
  }
953
980
 
954
981
  static string BrowserPath(string browser) {
@@ -45,6 +45,36 @@ export function resolveServerUrl(input, { fallback = DEFAULT_SERVER_URL } = {})
45
45
  return url.toString().replace(/\/+$/, '');
46
46
  }
47
47
 
48
+ const AIVIN_WEB_BY_ZONE = Object.freeze({
49
+ 'aivin.vn': 'https://app.aivin.vn',
50
+ 'aivin.cloud': 'https://app.aivin.cloud',
51
+ });
52
+
53
+ function aivinZone(hostname) {
54
+ const host = hostname.toLowerCase();
55
+ return Object.keys(AIVIN_WEB_BY_ZONE).find((zone) => host === zone || host.endsWith(`.${zone}`)) || null;
56
+ }
57
+
58
+ /** Web mặc định theo gốc tên miền của máy chủ Aivin; null với máy chủ tự dựng / localhost. */
59
+ export function defaultWebUrl(serverUrl) {
60
+ try {
61
+ return AIVIN_WEB_BY_ZONE[aivinZone(new URL(resolveServerUrl(serverUrl)).hostname)] || null;
62
+ } catch { return null; }
63
+ }
64
+
65
+ /**
66
+ * Chọn địa chỉ web từ `app_url` máy chủ khai. Máy chủ Aivin chính thức chỉ được dùng web cùng gốc tên miền:
67
+ * các máy chủ có thể dùng chung cấu hình nên `app_url` của api.aivin.vn có thể là brain.aivin.cloud.
68
+ */
69
+ export function webUrlForServer(serverUrl, appUrl) {
70
+ const fallback = defaultWebUrl(serverUrl);
71
+ if (!fallback) return appUrl || null;
72
+ try {
73
+ if (aivinZone(new URL(appUrl).hostname) === aivinZone(new URL(fallback).hostname)) return appUrl;
74
+ } catch { /* app_url hỏng thì dùng web mặc định */ }
75
+ return fallback;
76
+ }
77
+
48
78
  export function serverKey(serverUrl) {
49
79
  return createHash('sha256').update(resolveServerUrl(serverUrl)).digest('hex').slice(0, 24);
50
80
  }
@@ -75,4 +105,4 @@ export function serverLabel(serverUrl) {
75
105
  if (url === 'https://api.aivin.vn') return 'VN';
76
106
  if (url.startsWith('http://localhost:') || url.startsWith('http://127.0.0.1:')) return 'Local';
77
107
  return new URL(url).host;
78
- }
108
+ }
package/docs/CLI.md CHANGED
@@ -965,7 +965,7 @@ Options:
965
965
  aivin login
966
966
  ```
967
967
 
968
- Opens your default browser to the platform's actual login page (`https://brain.aivin.cloud`) with
968
+ Opens your default browser to the platform's actual login page (`https://app.aivin.cloud`) with
969
969
  a one-time state token and a `localhost` callback URL. Log in exactly the way you normally would in the
970
970
  browser - custom-domain org, password, Google, OTP, whatever applies to your account. Once you
971
971
  confirm on the "Aivin CLI wants to create an API Key" prompt that appears after login, a fresh key
@@ -1585,7 +1585,7 @@ machine picks it up automatically - there's no per-project credential to manage.
1585
1585
  | -------------------- | -------------------------------------------------- | ----------------------------- | ---------------------------------------------------------------- |
1586
1586
  | `SDK_ENDPOINT` | SDK calls, `aivin start` | `sdk.aivin.cloud:443` | Point `main()`'s SDK calls at a local/dev/staging backend instead of production. Staging: `sdk.aivin.vn:50052` (dedicated Cloudflare Tunnel TLS port - production goes through a load balancer on the standard 443 port instead, a different setup). |
1587
1587
  | `AIVIN_BASE_URL` | `deploy`, `test`, `plugin make/convert/trigger`, `login --basic` | `https://api.aivin.cloud` | Only for a self-hosted or staging instance. Staging: `https://api.aivin.vn`. |
1588
- | `AIVIN_WEB_URL` | `login` (browser flow) | `https://brain.aivin.cloud` | Only for a self-hosted or staging instance. |
1588
+ | `AIVIN_WEB_URL` | `login` (browser flow) | `https://app.aivin.cloud` | Only for a self-hosted or staging instance. |
1589
1589
  | `LOCAL_TEST_PORT` | `aivin start` | `4001` | Only if `4001` is already taken on your machine. |
1590
1590
  | `LOCAL_TEST_HOST` | `aivin start` | `127.0.0.1` | Loopback-only by default (`/invoke` has no auth) - only widen this if you deliberately want another device on your network to reach it. See [sdk repo's SECURITY.md](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/SECURITY.md). |
1591
1591
  | `AIVIN_SANDBOX_WORKER` | `aivin start`, deployed containers | `false` | Set `true` to run `src/main.ts` inside an isolated `worker_threads.Worker` (no direct access to the container's secret, restricted fs/child_process) instead of loading it in-process. Off by default - see [sdk repo's worker-sandbox.md](https://github.com/aivin-labs/AIVIN-SDK/blob/main/docs/draft/plugins/worker-sandbox.md). |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aivin-labs/cli",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "description": "aivin CLI - scaffold, run, and deploy Aivin plugins built on @aivin-labs/sdk",
5
5
  "type": "module",
6
6
  "bin": {