@aivin-labs/cli 1.0.28 → 1.0.31
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 +8 -51
- package/bin/cli.mjs +66 -12
- package/bin/lib/context.mjs +61 -113
- package/bin/lib/remote/autoStart.mjs +2 -2
- package/bin/lib/remote/client.mjs +38 -29
- package/bin/lib/remote/credentials.mjs +138 -152
- package/bin/lib/remote/desktop/desktopCastSource.mjs +8 -2
- package/bin/lib/remote/desktop/index.mjs +27 -8
- package/bin/lib/remote/desktop/strings.mjs +30 -4
- package/bin/lib/remote/desktop/traySource.mjs +1227 -976
- package/bin/lib/remote/desktop/uninstall.mjs +1 -1
- package/bin/lib/remote/mascot/strings.mjs +2 -2
- package/bin/lib/remote/tokenRotation.mjs +3 -3
- package/bin/lib/remote/tokenStore.mjs +4 -4
- package/bin/lib/servers.mjs +69 -0
- package/docs/AIVIN_MASCOT.md +3 -3
- package/docs/CLI.md +1600 -1576
- package/docs/media/aivin-mascot-live.gif +0 -0
- package/docs/media/aivin-mascot-live.png +0 -0
- package/docs/media/aivin-mission-flow.png +0 -0
- package/docs/media/cli-capabilities.png +0 -0
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { spawn } from 'child_process';
|
|
|
5
5
|
import { REMOTE_CONFIG_DIR } from '../constants.mjs';
|
|
6
6
|
import { lockHolder } from '../daemonLock.mjs';
|
|
7
7
|
import { disableAutoStart, uninstallDesktopApp } from '../autoStart.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import { clearAllDeviceCredentials, loadDeviceCredentials, unpairDevice } from '../credentials.mjs';
|
|
9
9
|
import { isStandaloneBinary } from '../../update/versions.mjs';
|
|
10
10
|
import { launcherExePath } from './index.mjs';
|
|
11
11
|
|
|
@@ -282,7 +282,7 @@ const STRINGS = {
|
|
|
282
282
|
[MascotText.UI_SHOWN]: "Linh vật Aivin đã hiện trên màn hình — gõ hoặc bấm mic để hỏi.",
|
|
283
283
|
[MascotText.UI_STARTING]: "Đang bật Aivin trên máy này…",
|
|
284
284
|
[MascotText.UI_STARTED]: "Đã bật Aivin chạy nền — linh vật hiện trong giây lát.",
|
|
285
|
-
[MascotText.UI_NOT_PAIRED]: "Máy này chưa kết nối Aivin.
|
|
285
|
+
[MascotText.UI_NOT_PAIRED]: "Máy này chưa kết nối Aivin. Bấm biểu tượng Aivin ở khay hệ thống rồi chọn ‘Đăng nhập để kết nối’.",
|
|
286
286
|
[MascotText.UI_START_FAILED]: "Chưa bật được Aivin chạy nền — chạy: aivin remote start",
|
|
287
287
|
},
|
|
288
288
|
en: {
|
|
@@ -418,7 +418,7 @@ const STRINGS = {
|
|
|
418
418
|
[MascotText.UI_SHOWN]: "The Aivin mascot is on screen — type or click the mic to ask.",
|
|
419
419
|
[MascotText.UI_STARTING]: "Starting Aivin on this computer…",
|
|
420
420
|
[MascotText.UI_STARTED]: "Aivin is running in the background — the mascot shows up in a moment.",
|
|
421
|
-
[MascotText.UI_NOT_PAIRED]: "This computer is not connected to Aivin
|
|
421
|
+
[MascotText.UI_NOT_PAIRED]: "This computer is not connected to Aivin. Click the Aivin system tray icon and choose ‘Sign in to connect’.",
|
|
422
422
|
[MascotText.UI_START_FAILED]: "Could not start Aivin in the background — run: aivin remote start",
|
|
423
423
|
},
|
|
424
424
|
};
|
|
@@ -8,8 +8,8 @@ import { confirmTokenRotation, revertTokenRotation } from './credentials.mjs';
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/** Chào thành công bằng `token` → token cũ (nếu còn giữ) hết cần. Không ném. */
|
|
11
|
-
export function settleRotation(token) {
|
|
12
|
-
try { return confirmTokenRotation(token); } catch { return false; }
|
|
11
|
+
export function settleRotation(token, serverUrl) {
|
|
12
|
+
try { return confirmTokenRotation(token, serverUrl); } catch { return false; }
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -18,7 +18,7 @@ export function settleRotation(token) {
|
|
|
18
18
|
*/
|
|
19
19
|
export function fallBackToPreviousToken({ creds, socket, isStopped = () => false, delayMs = 1000, revert = revertTokenRotation }) {
|
|
20
20
|
let previous;
|
|
21
|
-
try { previous = revert(creds.device_token); } catch { previous = null; }
|
|
21
|
+
try { previous = revert(creds.device_token, creds.server_url); } catch { previous = null; }
|
|
22
22
|
if (!previous) return false;
|
|
23
23
|
creds.device_token = previous;
|
|
24
24
|
socket.auth = { ...socket.auth, device_token: previous };
|
|
@@ -62,8 +62,8 @@ export function openToken(record) {
|
|
|
62
62
|
if (record.device_token) return record.device_token;
|
|
63
63
|
try {
|
|
64
64
|
if (record.token_store === TokenStoreKind.DPAPI && record.token_enc) return run('powershell.exe', [...PS, DPAPI_UNPROTECT], record.token_enc) || null;
|
|
65
|
-
if (record.token_store === TokenStoreKind.KEYCHAIN) return run('/usr/bin/security', ['find-generic-password', '-a', record.device_id, '-s', SERVICE, '-w']) || null;
|
|
66
|
-
if (record.token_store === TokenStoreKind.LIBSECRET) return run('secret-tool', ['lookup', 'service', SERVICE, 'account', record.device_id]) || null;
|
|
65
|
+
if (record.token_store === TokenStoreKind.KEYCHAIN) return run('/usr/bin/security', ['find-generic-password', '-a', record.token_account || record.device_id, '-s', SERVICE, '-w']) || null;
|
|
66
|
+
if (record.token_store === TokenStoreKind.LIBSECRET) return run('secret-tool', ['lookup', 'service', SERVICE, 'account', record.token_account || record.device_id]) || null;
|
|
67
67
|
} catch { /* không giải được */ }
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
@@ -71,7 +71,7 @@ export function openToken(record) {
|
|
|
71
71
|
/** Xoá token khỏi kho hệ điều hành (DPAPI / tệp thường: xoá tệp là đủ). */
|
|
72
72
|
export function forgetToken(record) {
|
|
73
73
|
try {
|
|
74
|
-
if (record?.token_store === TokenStoreKind.KEYCHAIN) run('/usr/bin/security', ['delete-generic-password', '-a', record.device_id, '-s', SERVICE]);
|
|
75
|
-
if (record?.token_store === TokenStoreKind.LIBSECRET) run('secret-tool', ['clear', 'service', SERVICE, 'account', record.device_id]);
|
|
74
|
+
if (record?.token_store === TokenStoreKind.KEYCHAIN) run('/usr/bin/security', ['delete-generic-password', '-a', record.token_account || record.device_id, '-s', SERVICE]);
|
|
75
|
+
if (record?.token_store === TokenStoreKind.LIBSECRET) run('secret-tool', ['clear', 'service', SERVICE, 'account', record.token_account || record.device_id]);
|
|
76
76
|
} catch { /* không có thì thôi */ }
|
|
77
77
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { createHash } from 'crypto';
|
|
5
|
+
import { writeFileAtomic } from './remote/atomicFile.mjs';
|
|
6
|
+
|
|
7
|
+
export const SERVER_CONFIG_FILE = path.join(process.env.AIVIN_REMOTE_HOME || path.join(os.homedir(), '.aivin'), 'server.json');
|
|
8
|
+
export const DEFAULT_SERVER_URL = 'https://api.aivin.cloud';
|
|
9
|
+
|
|
10
|
+
export function resolveServerUrl(input, { fallback = DEFAULT_SERVER_URL } = {}) {
|
|
11
|
+
const raw = String(input ?? '').trim();
|
|
12
|
+
if (!raw) return resolveServerUrl(fallback);
|
|
13
|
+
const alias = raw.toLowerCase();
|
|
14
|
+
if (alias === 'cloud') return 'https://api.aivin.cloud';
|
|
15
|
+
if (alias === 'vn') return 'https://api.aivin.vn';
|
|
16
|
+
const local = alias.match(/^local(?::(\d+))?$/);
|
|
17
|
+
if (local) {
|
|
18
|
+
const port = Number(local[1] || 3001);
|
|
19
|
+
if (port < 1 || port > 65535) throw new Error('Cổng local phải nằm trong khoảng 1–65535.');
|
|
20
|
+
return `http://localhost:${port}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const candidate = /^[a-z][a-z\d+.-]*:\/\//i.test(raw) ? raw : `https://${raw}`;
|
|
24
|
+
let url;
|
|
25
|
+
try { url = new URL(candidate); } catch { throw new Error(`Máy chủ không hợp lệ: ${raw}`); }
|
|
26
|
+
if (url.username || url.password) throw new Error('URL máy chủ không được chứa username hoặc password.');
|
|
27
|
+
const host = url.hostname.toLowerCase();
|
|
28
|
+
const loopback = host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]';
|
|
29
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback)) {
|
|
30
|
+
throw new Error('Chỉ localhost mới được dùng HTTP; máy chủ khác phải dùng HTTPS.');
|
|
31
|
+
}
|
|
32
|
+
for (const domain of ['aivin.cloud', 'aivin.vn']) {
|
|
33
|
+
if (host === domain) return `https://api.${domain}`;
|
|
34
|
+
if (host.endsWith(`.${domain}`)) {
|
|
35
|
+
const first = host.slice(0, -(domain.length + 1)).split('.').at(-1);
|
|
36
|
+
if (!/(^|-)api$/.test(first)) return `https://api.${domain}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
url.hash = '';
|
|
40
|
+
url.search = '';
|
|
41
|
+
return url.toString().replace(/\/+$/, '');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function serverKey(serverUrl) {
|
|
45
|
+
return createHash('sha256').update(resolveServerUrl(serverUrl)).digest('hex').slice(0, 24);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function readActiveServer() {
|
|
49
|
+
try {
|
|
50
|
+
const value = JSON.parse(fs.readFileSync(SERVER_CONFIG_FILE, 'utf8'))?.server_url;
|
|
51
|
+
return value ? resolveServerUrl(value) : null;
|
|
52
|
+
} catch { return null; }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function setActiveServer(serverUrl) {
|
|
56
|
+
const normalized = resolveServerUrl(serverUrl);
|
|
57
|
+
fs.mkdirSync(path.dirname(SERVER_CONFIG_FILE), { recursive: true });
|
|
58
|
+
writeFileAtomic(SERVER_CONFIG_FILE, `${JSON.stringify({ server_url: normalized }, null, 2)}\n`, { mode: 0o600 });
|
|
59
|
+
try { fs.chmodSync(SERVER_CONFIG_FILE, 0o600); } catch { /* Windows ACL follows the user profile */ }
|
|
60
|
+
return normalized;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function serverLabel(serverUrl) {
|
|
64
|
+
const url = resolveServerUrl(serverUrl);
|
|
65
|
+
if (url === 'https://api.aivin.cloud') return 'Cloud';
|
|
66
|
+
if (url === 'https://api.aivin.vn') return 'VN';
|
|
67
|
+
if (url.startsWith('http://localhost:') || url.startsWith('http://127.0.0.1:')) return 'Local';
|
|
68
|
+
return new URL(url).host;
|
|
69
|
+
}
|
package/docs/AIVIN_MASCOT.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Aivin mascot
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img src="media/aivin-mascot-live.gif" alt="The
|
|
4
|
+
<img src="media/aivin-mascot-live.gif" alt="The live Aivin mascot ask box showing a conversation and the mascot" width="720" />
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
The Aivin mascot is the floating Windows interface for Aivin Remote. It shows what the agent is doing, accepts typed or spoken questions, and gives access to recent activity without opening the web app.
|
|
8
8
|
|
|
9
|
-
The animation above is
|
|
9
|
+
The animation above is an enlarged capture of the real WPF ask box and mascot, cropped to remove excess space. It shows the live conversation and the mascot's file attachment states.
|
|
10
10
|
|
|
11
11
|
## How it connects to Aivin
|
|
12
12
|
|
|
@@ -34,7 +34,7 @@ To show the mascot and open its ask box directly, run:
|
|
|
34
34
|
aivin ui
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
If the listener is not running, `aivin ui` starts it in the background. If the computer has not been paired, the
|
|
37
|
+
If the listener is not running, `aivin ui` starts it in the background. If the computer has not been paired, click the Aivin system tray icon and choose **Sign in to connect**. Aivin opens the usual browser sign-in, links this computer, then starts the listener. The one-time pairing code remains available as a fallback from Aivin Web.
|
|
38
38
|
|
|
39
39
|
## Using the mascot
|
|
40
40
|
|