@aivin-labs/cli 1.0.34 → 1.0.37
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/bin/cli.mjs +1 -2
- package/bin/lib/remote/client.mjs +6 -2
- package/bin/lib/remote/credentials.mjs +68 -10
- package/bin/lib/remote/desktop/traySource.mjs +31 -8
- package/bin/lib/remote/mascot/ask.mjs +5 -4
- package/bin/lib/remote/mascot/askHostSource.mjs +1 -0
- package/bin/lib/remote/mascot/index.mjs +4 -4
- package/bin/lib/servers.mjs +10 -1
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -834,9 +834,8 @@ program
|
|
|
834
834
|
.command('server [target]')
|
|
835
835
|
.description('Show or switch the active Aivin server (cloud, vn, local, or a URL)')
|
|
836
836
|
.option('--force', 'Switch servers without asking before stopping the current remote connection')
|
|
837
|
-
.action(async (target,
|
|
837
|
+
.action(async (target, options) => {
|
|
838
838
|
try {
|
|
839
|
-
const options = command.opts();
|
|
840
839
|
const current = normalizeServerUrl(process.env.AIVIN_BASE_URL || readActiveServer() || DEFAULT_AIVIN_BASE_URL);
|
|
841
840
|
if (!target) {
|
|
842
841
|
console.log(`Máy chủ đang chọn: ${serverLabel(current)} (${current})`);
|
|
@@ -14,7 +14,7 @@ import { configureProxy, proxyAgentFor } from './netProxy.mjs';
|
|
|
14
14
|
import { createKeepAwake } from './keepAwake.mjs';
|
|
15
15
|
import { createPolicyGuard, describeCall, evaluateLocalPolicy } from './localPolicy.mjs';
|
|
16
16
|
import { ConfirmResult, createLocalConfirmer } from './localConfirm.mjs';
|
|
17
|
-
import { clearDeviceCredentials, credentialsFromEnv, listDevices, loadDeviceCredentials, pairDevice, pairDeviceWithCode, readStoredTokenFresh, saveDeviceCredentials } from './credentials.mjs';
|
|
17
|
+
import { clearDeviceCredentials, confirmServerCredentialMigration, credentialsFromEnv, listDevices, loadDeviceCredentials, pairDevice, pairDeviceWithCode, readStoredTokenFresh, saveDeviceCredentials } from './credentials.mjs';
|
|
18
18
|
import { ensureMemoryLoaded, memoryStats, stopWatchingMemory, watchMemoryDir } from './deviceMemory.mjs';
|
|
19
19
|
import { buildCatalog, buildDeviceProfile } from './deviceProfile.mjs';
|
|
20
20
|
import { createFileIndex, indexRootsFor } from './fileIndexer.mjs';
|
|
@@ -884,7 +884,11 @@ export async function startRemoteClient(options = {}) {
|
|
|
884
884
|
|
|
885
885
|
// Chưa nối thì thôi: lần chào khi nối mang theo hồ sơ mới.
|
|
886
886
|
announceProfile = () => (socket.connected ? announce() : undefined);
|
|
887
|
-
socket.on('connect', guarded('connect', async () => {
|
|
887
|
+
socket.on('connect', guarded('connect', async () => {
|
|
888
|
+
confirmServerCredentialMigration(serverUrl);
|
|
889
|
+
await announce();
|
|
890
|
+
flushUnsent();
|
|
891
|
+
}));
|
|
888
892
|
let serverKicks = 0;
|
|
889
893
|
socket.on('disconnect', guarded('disconnect', (reason) => {
|
|
890
894
|
if (stopped) return;
|
|
@@ -40,6 +40,7 @@ function readStore() {
|
|
|
40
40
|
try { const raw = fs.readFileSync(DEVICE_CREDENTIALS_FILE, 'utf8'); return { raw, data: JSON.parse(raw) }; }
|
|
41
41
|
catch { return null; }
|
|
42
42
|
}
|
|
43
|
+
const isLegacyServerAlias = (source, target) => String(source || '').trim().replace(/\/+$/, '') !== target;
|
|
43
44
|
function resolveCredentialServer(serverUrl) {
|
|
44
45
|
if (serverUrl) return resolveServerUrl(serverUrl);
|
|
45
46
|
const configured = process.env.AIVIN_BASE_URL || process.env.AIVIN_SERVER || readActiveServer();
|
|
@@ -54,15 +55,27 @@ function readRecord(serverUrl) {
|
|
|
54
55
|
const url = resolveCredentialServer(serverUrl); const file = readStore();
|
|
55
56
|
if (!file?.data) return null;
|
|
56
57
|
if (file.data.servers && typeof file.data.servers === 'object') {
|
|
57
|
-
const
|
|
58
|
-
|
|
58
|
+
const key = serverKey(url);
|
|
59
|
+
const data = file.data.servers[key];
|
|
60
|
+
if (data) return { raw: file.raw, data, store: file.data, serverUrl: url };
|
|
61
|
+
// A pre-migration beta record is eligible once. loadDeviceCredentials moves it to
|
|
62
|
+
// legacy_servers before trying it at production, so a rejected token won't loop.
|
|
63
|
+
const alias = Object.entries(file.data.servers).find(([, record]) => {
|
|
64
|
+
if (!record?.server_url) return false;
|
|
65
|
+
try { return resolveServerUrl(record.server_url) === url && isLegacyServerAlias(record.server_url, url); } catch { return false; }
|
|
66
|
+
});
|
|
67
|
+
if (alias) return { raw: file.raw, data: alias[1], store: file.data, serverUrl: url, legacyAlias: true, sourceKey: alias[0] };
|
|
68
|
+
return null;
|
|
59
69
|
}
|
|
60
|
-
if (file.data.device_id && resolveServerUrl(file.data.server_url || DEFAULT_SERVER_URL) === url)
|
|
61
|
-
return {
|
|
70
|
+
if (file.data.device_id && resolveServerUrl(file.data.server_url || DEFAULT_SERVER_URL) === url)
|
|
71
|
+
return {
|
|
72
|
+
raw: file.raw, data: file.data, store: file.data, legacy: true, serverUrl: url,
|
|
73
|
+
...(isLegacyServerAlias(file.data.server_url || DEFAULT_SERVER_URL, url) ? { legacyAlias: true, sourceKey: `legacy:${file.data.server_url || DEFAULT_SERVER_URL}` } : {}),
|
|
74
|
+
};
|
|
62
75
|
return null;
|
|
63
76
|
}
|
|
64
|
-
function writeRecord(record, serverUrl) {
|
|
65
|
-
const url = resolveCredentialServer(serverUrl || record.server_url); const current = readStore()?.data;
|
|
77
|
+
function writeRecord(record, serverUrl, currentOverride) {
|
|
78
|
+
const url = resolveCredentialServer(serverUrl || record.server_url); const current = currentOverride || readStore()?.data;
|
|
66
79
|
let store;
|
|
67
80
|
if (current?.servers && typeof current.servers === 'object') store = { ...current, servers: { ...current.servers } };
|
|
68
81
|
else {
|
|
@@ -94,6 +107,20 @@ export function loadDeviceCredentials(serverUrl) {
|
|
|
94
107
|
if (cached?.raw === raw && cached.token) return { ...data, server_url: url, device_token: cached.token };
|
|
95
108
|
const token = openToken({ ...data, token_account: data.token_account || data.device_id });
|
|
96
109
|
if (!token) return null;
|
|
110
|
+
if (rec.legacyAlias) {
|
|
111
|
+
const store = rec.store.servers
|
|
112
|
+
? { ...rec.store, servers: { ...rec.store.servers }, legacy_servers: { ...(rec.store.legacy_servers || {}) } }
|
|
113
|
+
: { version: 2, servers: {}, legacy_servers: {} };
|
|
114
|
+
const oldRecord = rec.store.servers ? store.servers[rec.sourceKey] : rec.store;
|
|
115
|
+
if (rec.store.servers) delete store.servers[rec.sourceKey];
|
|
116
|
+
if (oldRecord) {
|
|
117
|
+
const { server_url: oldUrl, ...backup } = oldRecord;
|
|
118
|
+
store.legacy_servers[rec.sourceKey] = { ...backup, legacy_server_url: oldUrl || rec.data.server_url || DEFAULT_SERVER_URL };
|
|
119
|
+
}
|
|
120
|
+
const { previous_sealed: _previous, policy_sealed_at: _policy, ...migrated } = data;
|
|
121
|
+
saveDeviceCredentials({ ...migrated, server_url: url, device_token: token }, { storeOverride: store });
|
|
122
|
+
return { ...readRecord(url)?.data, server_url: url, device_token: token };
|
|
123
|
+
}
|
|
97
124
|
opened.set(key, { raw, token });
|
|
98
125
|
const retrySeal = !data.seal_failed || Date.now() - Number(data.seal_failed.at || 0) > SEAL_RETRY_MS;
|
|
99
126
|
if (data.device_token && preferredTokenStore() !== TokenStoreKind.FILE && retrySeal) {
|
|
@@ -102,7 +129,35 @@ export function loadDeviceCredentials(serverUrl) {
|
|
|
102
129
|
}
|
|
103
130
|
return { ...data, server_url: url, device_token: token };
|
|
104
131
|
}
|
|
105
|
-
|
|
132
|
+
|
|
133
|
+
/** Once production accepts the migrated token, discard its sealed beta backup. */
|
|
134
|
+
export function confirmServerCredentialMigration(serverUrl) {
|
|
135
|
+
const url = resolveServerUrl(serverUrl);
|
|
136
|
+
const file = readStore();
|
|
137
|
+
if (!file?.data) return false;
|
|
138
|
+
const servers = { ...(file.data.servers || {}) };
|
|
139
|
+
const legacy = { ...(file.data.legacy_servers || {}) };
|
|
140
|
+
let removed = false;
|
|
141
|
+
for (const records of [servers, legacy]) {
|
|
142
|
+
for (const [key, record] of Object.entries(records)) {
|
|
143
|
+
try {
|
|
144
|
+
const sourceUrl = record?.legacy_server_url || record?.server_url;
|
|
145
|
+
if (sourceUrl && resolveServerUrl(sourceUrl) === url && isLegacyServerAlias(sourceUrl, url)) {
|
|
146
|
+
forgetToken({ ...record, token_account: record.token_account || record.device_id });
|
|
147
|
+
forgetPrevious(record.previous_sealed);
|
|
148
|
+
delete records[key];
|
|
149
|
+
removed = true;
|
|
150
|
+
}
|
|
151
|
+
} catch { /* leave malformed legacy entries for manual recovery */ }
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!removed) return false;
|
|
155
|
+
const store = { ...file.data, servers, legacy_servers: legacy };
|
|
156
|
+
writeFileAtomic(DEVICE_CREDENTIALS_FILE, `${JSON.stringify(store, null, 2)}\n`);
|
|
157
|
+
try { fs.chmodSync(DEVICE_CREDENTIALS_FILE, 0o600); } catch { /* Windows ACL follows the user profile */ }
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
export function saveDeviceCredentials(creds, { previousToken, storeOverride } = {}) {
|
|
106
161
|
const url = resolveCredentialServer(creds.server_url); const key = serverKey(url); const account = tokenAccount(creds.device_id, url);
|
|
107
162
|
const { device_token: token, token_store: _s, token_enc: _e, seal_failed: _f, ...rest } = creds;
|
|
108
163
|
for (const f of DISK_OWNED_FIELDS) delete rest[f]; delete rest.token_account;
|
|
@@ -115,7 +170,8 @@ export function saveDeviceCredentials(creds, { previousToken } = {}) {
|
|
|
115
170
|
if (previousToken) kept.previous_sealed = sealPrevious(previousToken, creds.device_id, url);
|
|
116
171
|
}
|
|
117
172
|
const sealed = sealToken(token, { account }); const { fallback_reason: reason, ...stored } = sealed;
|
|
118
|
-
const
|
|
173
|
+
const record = { ...rest, server_url: url, token_account: account, ...stored, ...kept, ...(reason ? { seal_failed: { at: Date.now(), reason } } : {}) };
|
|
174
|
+
const raw = writeRecord(record, url, storeOverride);
|
|
119
175
|
opened.set(key, { raw, token }); return reason || null;
|
|
120
176
|
}
|
|
121
177
|
export function pendingPreviousToken(serverUrl) { return openPrevious(readRecord(serverUrl)?.data?.previous_sealed); }
|
|
@@ -153,7 +209,7 @@ export function clearDeviceCredentials(onlyToken, serverUrl) {
|
|
|
153
209
|
forgetToken({ ...rec.data, token_account: rec.data.token_account || rec.data.device_id }); forgetPrevious(rec.data.previous_sealed);
|
|
154
210
|
const store = rec.store?.servers ? { ...rec.store, servers: { ...rec.store.servers } } : { version: 2, servers: {} };
|
|
155
211
|
delete store.servers[serverKey(url)];
|
|
156
|
-
if (Object.keys(store.servers).length) {
|
|
212
|
+
if (Object.keys(store.servers).length || Object.keys(store.legacy_servers || {}).length) {
|
|
157
213
|
const raw = JSON.stringify(store, null, 2) + '\n'; writeFileAtomic(DEVICE_CREDENTIALS_FILE, raw);
|
|
158
214
|
try { fs.chmodSync(DEVICE_CREDENTIALS_FILE, 0o600); } catch { /* Windows ACL follows the user profile */ }
|
|
159
215
|
} else { try { fs.unlinkSync(DEVICE_CREDENTIALS_FILE); } catch { /* already clear */ } }
|
|
@@ -162,7 +218,9 @@ export function clearDeviceCredentials(onlyToken, serverUrl) {
|
|
|
162
218
|
}
|
|
163
219
|
export function clearAllDeviceCredentials() {
|
|
164
220
|
const store = readStore()?.data;
|
|
165
|
-
const records = store?.servers
|
|
221
|
+
const records = store?.servers
|
|
222
|
+
? [...Object.values(store.servers), ...Object.values(store.legacy_servers || {})]
|
|
223
|
+
: store?.device_id ? [store] : [];
|
|
166
224
|
for (const rec of records) { forgetToken({ ...rec, token_account: rec.token_account || rec.device_id }); forgetPrevious(rec.previous_sealed); }
|
|
167
225
|
try { fs.unlinkSync(DEVICE_CREDENTIALS_FILE); } catch { /* already clear */ }
|
|
168
226
|
opened.clear(); return true;
|
|
@@ -389,6 +389,7 @@ namespace AivinDesktop {
|
|
|
389
389
|
int delay = FirstDelay;
|
|
390
390
|
int fast = 0;
|
|
391
391
|
bool pairing = false;
|
|
392
|
+
bool rePairPromptPending = false;
|
|
392
393
|
bool wasPaired;
|
|
393
394
|
bool quitting = false;
|
|
394
395
|
Form pairForm;
|
|
@@ -434,12 +435,12 @@ namespace AivinDesktop {
|
|
|
434
435
|
|
|
435
436
|
menu.Items.AddRange(new ToolStripItem[] {
|
|
436
437
|
open,
|
|
438
|
+
mascot,
|
|
439
|
+
pause,
|
|
437
440
|
quickSeparator,
|
|
438
|
-
quickChat,
|
|
439
441
|
quickVoice,
|
|
442
|
+
quickChat,
|
|
440
443
|
new ToolStripSeparator(),
|
|
441
|
-
mascot,
|
|
442
|
-
pause,
|
|
443
444
|
serverMenu,
|
|
444
445
|
new ToolStripSeparator(),
|
|
445
446
|
startup,
|
|
@@ -509,9 +510,14 @@ namespace AivinDesktop {
|
|
|
509
510
|
if (SwapIfExeReplaced()) return;
|
|
510
511
|
bool paired = HasPairedServer();
|
|
511
512
|
if (paired && !wasPaired) Balloon(cfg.T("connected"), ToolTipIcon.Info);
|
|
513
|
+
if (!paired && wasPaired) rePairPromptPending = true;
|
|
512
514
|
wasPaired = paired;
|
|
513
515
|
if (child == null && paired && DateTime.Now >= nextStart && LockHolder() == 0) StartChild(null);
|
|
514
516
|
Refresh();
|
|
517
|
+
if (rePairPromptPending && child == null && !pairing && pairForm == null && !tray.ContextMenuStrip.Visible) {
|
|
518
|
+
rePairPromptPending = false;
|
|
519
|
+
ShowPair();
|
|
520
|
+
}
|
|
515
521
|
}
|
|
516
522
|
|
|
517
523
|
/**
|
|
@@ -840,6 +846,7 @@ namespace AivinDesktop {
|
|
|
840
846
|
|
|
841
847
|
static string PlatformUrl() {
|
|
842
848
|
string api = CurrentServerUrl();
|
|
849
|
+
api = CanonicalServerUrl(api);
|
|
843
850
|
try {
|
|
844
851
|
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
|
|
845
852
|
using (WebClient client = new WebClient()) {
|
|
@@ -854,8 +861,7 @@ namespace AivinDesktop {
|
|
|
854
861
|
}
|
|
855
862
|
}
|
|
856
863
|
} catch { }
|
|
857
|
-
if (api == "https://api.aivin.vn") return "https://
|
|
858
|
-
if (api == "https://beta-api.aivin.vn") return "https://beta.aivin.vn";
|
|
864
|
+
if (api == "https://api.aivin.vn") return "https://app.aivin.vn";
|
|
859
865
|
if (api == "https://api.aivin.cloud") return "https://brain.aivin.cloud";
|
|
860
866
|
return "https://brain.aivin.cloud";
|
|
861
867
|
}
|
|
@@ -951,23 +957,40 @@ namespace AivinDesktop {
|
|
|
951
957
|
try {
|
|
952
958
|
if (File.Exists(ServerFile)) {
|
|
953
959
|
Match selected = Regex.Match(File.ReadAllText(ServerFile), "\"server_url\"\\s*:\\s*\"([^\"]+)\"");
|
|
954
|
-
if (selected.Success)
|
|
960
|
+
if (selected.Success) {
|
|
961
|
+
string saved = selected.Groups[1].Value.TrimEnd('/');
|
|
962
|
+
string canonical = CanonicalServerUrl(saved);
|
|
963
|
+
if (!string.Equals(saved, canonical, StringComparison.OrdinalIgnoreCase)) {
|
|
964
|
+
try {
|
|
965
|
+
string tmp = ServerFile + ".tmp";
|
|
966
|
+
File.WriteAllText(tmp, "{\"server_url\":\"" + canonical + "\"}\r\n", new UTF8Encoding(false));
|
|
967
|
+
if (File.Exists(ServerFile)) File.Replace(tmp, ServerFile, null); else File.Move(tmp, ServerFile);
|
|
968
|
+
} catch { }
|
|
969
|
+
}
|
|
970
|
+
return canonical;
|
|
971
|
+
}
|
|
955
972
|
}
|
|
956
973
|
if (File.Exists(CredsFile)) {
|
|
957
974
|
Match legacy = Regex.Match(File.ReadAllText(CredsFile), "\"server_url\"\\s*:\\s*\"([^\"]+)\"");
|
|
958
|
-
if (legacy.Success) return legacy.Groups[1].Value.TrimEnd('/');
|
|
975
|
+
if (legacy.Success) return CanonicalServerUrl(legacy.Groups[1].Value.TrimEnd('/'));
|
|
959
976
|
}
|
|
960
977
|
} catch { }
|
|
961
978
|
return "https://api.aivin.cloud";
|
|
962
979
|
}
|
|
963
980
|
|
|
981
|
+
static string CanonicalServerUrl(string url) {
|
|
982
|
+
if (string.Equals(url, "https://beta-api.aivin.vn", StringComparison.OrdinalIgnoreCase)) return "https://api.aivin.vn";
|
|
983
|
+
if (string.Equals(url, "https://beta-api.aivin.cloud", StringComparison.OrdinalIgnoreCase)) return "https://api.aivin.cloud";
|
|
984
|
+
return url;
|
|
985
|
+
}
|
|
986
|
+
|
|
964
987
|
static bool HasPairedServer() {
|
|
965
988
|
try {
|
|
966
989
|
if (!File.Exists(CredsFile)) return false;
|
|
967
990
|
string url = CurrentServerUrl();
|
|
968
991
|
string json = File.ReadAllText(CredsFile);
|
|
969
992
|
foreach (Match m in Regex.Matches(json, "\"server_url\"\\s*:\\s*\"([^\"]+)\""))
|
|
970
|
-
if (string.Equals(m.Groups[1].Value.TrimEnd('/'), url, StringComparison.OrdinalIgnoreCase)) return true;
|
|
993
|
+
if (string.Equals(CanonicalServerUrl(m.Groups[1].Value.TrimEnd('/')), url, StringComparison.OrdinalIgnoreCase)) return true;
|
|
971
994
|
} catch { }
|
|
972
995
|
return false;
|
|
973
996
|
}
|
|
@@ -96,14 +96,15 @@ export const FORM_SKIP_ID = '__skip__';
|
|
|
96
96
|
/** Link mo tren trinh duyet khi chu may bam vao thong bao phien lam viec. */
|
|
97
97
|
export function webUrlForSession(sessionId, serverUrl = '') {
|
|
98
98
|
if (!sessionId) return null;
|
|
99
|
-
let base = 'https://
|
|
99
|
+
let base = 'https://app.aivin.vn';
|
|
100
100
|
if (serverUrl) {
|
|
101
101
|
try {
|
|
102
102
|
const u = new URL(serverUrl);
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
const host = ['api.aivin.vn', 'beta-api.aivin.vn'].includes(u.hostname.toLowerCase())
|
|
104
|
+
? 'app.aivin.vn'
|
|
105
|
+
: u.hostname.replace(/-api\./, '.').replace(/^api\./, '');
|
|
105
106
|
const proto = u.protocol === 'wss:' ? 'https:' : u.protocol === 'ws:' ? 'http:' : u.protocol;
|
|
106
|
-
base = `${proto}//${host}${u.port ? `:${u.port}` : ''}`;
|
|
107
|
+
base = `${proto}//${host}${u.port && host !== 'app.aivin.vn' ? `:${u.port}` : ''}`;
|
|
107
108
|
} catch {}
|
|
108
109
|
}
|
|
109
110
|
return `${base}/?session_id=${encodeURIComponent(sessionId)}`;
|
|
@@ -617,6 +617,7 @@ function Handle($m) {
|
|
|
617
617
|
# aivin ui: the user just asked for the mascot from a terminal -> show it and open the ask box ready to type.
|
|
618
618
|
'open_ask' { $script:userHidden = $false; ApplyVisibility; if (-not $script:askFocused) { OpenAsk }; return }
|
|
619
619
|
'voice_toggle' { $script:userHidden = $false; ApplyVisibility; VoiceToggle; return }
|
|
620
|
+
'quick_voice' { $script:userHidden = $false; ApplyVisibility; if (-not $script:voiceLive) { PeekAsk; StartVoice }; return }
|
|
620
621
|
# Debug only (AIVIN_MASCOT_DEBUG): show the ask box WITHOUT taking keyboard focus, to look at it / screenshot it.
|
|
621
622
|
'ask_preview' { if ($env:AIVIN_MASCOT_DEBUG) { PeekAsk }; return }
|
|
622
623
|
# Debug/docs preview of the real file-drag UI, using the same tray, face and hint code as DragEnter without requiring Explorer.
|
|
@@ -34,12 +34,12 @@ export const MascotState = Object.freeze({
|
|
|
34
34
|
});
|
|
35
35
|
export const LogStatus = Object.freeze({ RUN: 'run', OK: 'ok', FAIL: 'fail', INFO: 'info', WARN: 'warn' });
|
|
36
36
|
/** Lệnh gửi cửa sổ / sự kiện cửa sổ gửi về (một dòng JSON mỗi lệnh). */
|
|
37
|
-
export const HostCommand = Object.freeze({ STATE: 'state', MAIN: 'main', LOG: 'log', GUI: 'gui', SHOW: 'show', QUIT: 'quit', OPEN_ASK: 'open_ask', VOICE_TOGGLE: 'voice_toggle', GESTURE: 'gesture', NOTIFY_FREQ: 'notify_freq' });
|
|
37
|
+
export const HostCommand = Object.freeze({ STATE: 'state', MAIN: 'main', LOG: 'log', GUI: 'gui', SHOW: 'show', QUIT: 'quit', OPEN_ASK: 'open_ask', QUICK_VOICE: 'quick_voice', VOICE_TOGGLE: 'voice_toggle', GESTURE: 'gesture', NOTIFY_FREQ: 'notify_freq' });
|
|
38
38
|
|
|
39
39
|
/** `aivin ui` (terminal khác) chạm tệp này → daemon đang chạy hiện linh vật + mở ô hỏi (mascot/ui.mjs). */
|
|
40
40
|
export const MASCOT_SHOW_FILE = path.join(REMOTE_CONFIG_DIR, 'mascot-show');
|
|
41
41
|
export const MASCOT_HIDE_FILE = path.join(REMOTE_CONFIG_DIR, 'mascot-hide');
|
|
42
|
-
/** Mục "Quick voice" của khay chạm tệp này → daemon hiện linh vật +
|
|
42
|
+
/** Mục "Quick voice" của khay chạm tệp này → daemon hiện linh vật + bắt đầu voice. Xử lý xong xoá luôn: daemon khởi động lại không được tự mở mic. */
|
|
43
43
|
export const MASCOT_VOICE_FILE = path.join(REMOTE_CONFIG_DIR, 'mascot-voice');
|
|
44
44
|
/** Phím tắt cửa sổ linh vật đang giữ thật (`{ chat, voice }`, tổ hợp đầu tiên còn trống) — khay đọc để hiện cạnh mục menu; cửa sổ đóng thì xoá. */
|
|
45
45
|
export const MASCOT_HOTKEYS_FILE = path.join(REMOTE_CONFIG_DIR, 'mascot-hotkeys.json');
|
|
@@ -392,7 +392,7 @@ export function createMascot({
|
|
|
392
392
|
|
|
393
393
|
/**
|
|
394
394
|
* `aivin ui` / khay: bật lại nếu đang tắt, hiện linh vật (kể cả đang "ẩn tới khi có việc"), rồi `command`: mở ô hỏi để gõ ngay (mặc định)
|
|
395
|
-
* hoặc
|
|
395
|
+
* hoặc bắt đầu voice (Quick voice).
|
|
396
396
|
*/
|
|
397
397
|
function wake(command = HostCommand.OPEN_ASK) {
|
|
398
398
|
if (closed) return;
|
|
@@ -434,7 +434,7 @@ export function createMascot({
|
|
|
434
434
|
try {
|
|
435
435
|
const voiceAt = fs.statSync(voiceFile).mtimeMs;
|
|
436
436
|
fs.rmSync(voiceFile, { force: true });
|
|
437
|
-
if (voiceAt > voiceSeenAt) wake(HostCommand.
|
|
437
|
+
if (voiceAt > voiceSeenAt) wake(HostCommand.QUICK_VOICE);
|
|
438
438
|
} catch {}
|
|
439
439
|
const shared = takeAttachRequests(attachDir, now());
|
|
440
440
|
if (shared.length) {
|
package/bin/lib/servers.mjs
CHANGED
|
@@ -25,6 +25,10 @@ export function resolveServerUrl(input, { fallback = DEFAULT_SERVER_URL } = {})
|
|
|
25
25
|
try { url = new URL(candidate); } catch { throw new Error(`Máy chủ không hợp lệ: ${raw}`); }
|
|
26
26
|
if (url.username || url.password) throw new Error('URL máy chủ không được chứa username hoặc password.');
|
|
27
27
|
const host = url.hostname.toLowerCase();
|
|
28
|
+
// Migrate the retired Vietnam beta endpoint to production. The device credential migration
|
|
29
|
+
// below keeps the old sealed record until production accepts the token.
|
|
30
|
+
if (host === 'beta-api.aivin.vn') return 'https://api.aivin.vn';
|
|
31
|
+
if (host === 'beta-api.aivin.cloud') return 'https://api.aivin.cloud';
|
|
28
32
|
const loopback = host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]';
|
|
29
33
|
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback)) {
|
|
30
34
|
throw new Error('Chỉ localhost mới được dùng HTTP; máy chủ khác phải dùng HTTPS.');
|
|
@@ -48,7 +52,12 @@ export function serverKey(serverUrl) {
|
|
|
48
52
|
export function readActiveServer() {
|
|
49
53
|
try {
|
|
50
54
|
const value = JSON.parse(fs.readFileSync(SERVER_CONFIG_FILE, 'utf8'))?.server_url;
|
|
51
|
-
|
|
55
|
+
if (!value) return null;
|
|
56
|
+
const normalized = resolveServerUrl(value);
|
|
57
|
+
if (String(value).trim().replace(/\/+$/, '') !== normalized) {
|
|
58
|
+
try { setActiveServer(normalized); } catch { /* old value is still readable */ }
|
|
59
|
+
}
|
|
60
|
+
return normalized;
|
|
52
61
|
} catch { return null; }
|
|
53
62
|
}
|
|
54
63
|
|