@aivin-labs/cli 1.0.46 → 1.0.50

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.
Files changed (38) hide show
  1. package/bin/cli.mjs +16 -5
  2. package/bin/lib/auth.mjs +24 -10
  3. package/bin/lib/projectEnv.mjs +27 -0
  4. package/bin/lib/remote/client.mjs +1412 -1162
  5. package/bin/lib/remote/confirmBarrier.mjs +45 -0
  6. package/bin/lib/remote/constants.mjs +7 -1
  7. package/bin/lib/remote/desktop/aivinIco.mjs +696 -0
  8. package/bin/lib/remote/desktop/castAuth.mjs +74 -69
  9. package/bin/lib/remote/desktop/castConsent.mjs +90 -0
  10. package/bin/lib/remote/desktop/castFileDrop.mjs +24 -0
  11. package/bin/lib/remote/desktop/castInput.mjs +89 -24
  12. package/bin/lib/remote/desktop/castTouchViewers.mjs +26 -0
  13. package/bin/lib/remote/desktop/desktopCast.mjs +28 -2
  14. package/bin/lib/remote/desktop/desktopCastSource.mjs +410 -121
  15. package/bin/lib/remote/desktop/desktopWebRtc.mjs +17 -1
  16. package/bin/lib/remote/desktop/index.mjs +5 -3
  17. package/bin/lib/remote/desktop/traySource.mjs +1289 -1274
  18. package/bin/lib/remote/desktop/webrtcWorker.mjs +3 -0
  19. package/bin/lib/remote/deviceProfile.mjs +2 -0
  20. package/bin/lib/remote/gui/index.mjs +485 -480
  21. package/bin/lib/remote/humanInput.mjs +117 -0
  22. package/bin/lib/remote/idempotency.mjs +19 -2
  23. package/bin/lib/remote/keepAwake.mjs +15 -9
  24. package/bin/lib/remote/localConfirm.mjs +26 -7
  25. package/bin/lib/remote/localPolicy.mjs +15 -2
  26. package/bin/lib/remote/mascot/ask.mjs +23 -4
  27. package/bin/lib/remote/mascot/askHostSource.mjs +10 -4
  28. package/bin/lib/remote/mascot/bot.mjs +5 -1
  29. package/bin/lib/remote/mascot/hostSource.mjs +8 -1
  30. package/bin/lib/remote/mascot/index.mjs +55 -51
  31. package/bin/lib/remote/mascot/rigSource.mjs +28 -2
  32. package/bin/lib/remote/policyCommand.mjs +16 -3
  33. package/bin/lib/remote/processes.mjs +231 -230
  34. package/bin/lib/remote/sandbox.mjs +6 -4
  35. package/bin/lib/remote/scheduler.mjs +164 -124
  36. package/bin/lib/remote/toolHandlers.mjs +3 -2
  37. package/bin/lib/remote/winTree.mjs +29 -0
  38. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -7,7 +7,8 @@ import path from 'path';
7
7
  import inquirer from 'inquirer';
8
8
  import { spawn } from 'child_process';
9
9
  import axios from 'axios';
10
- import dotenv from 'dotenv';
10
+ import { loadProjectEnv } from './lib/projectEnv.mjs';
11
+ import { requestCastStop } from './lib/remote/desktop/castAuth.mjs';
11
12
  import { fileURLToPath, pathToFileURL } from 'url';
12
13
  import { dirname } from 'path';
13
14
  import { createRequire } from 'module';
@@ -131,9 +132,8 @@ import {
131
132
  // didn't set them. `dotenv.config()` never overrides a variable that's already set, so a project's
132
133
  // own `.env` (or a real shell env var) always wins over the global context, exactly like before -
133
134
  // but nothing requires a project to have a `.env` at all anymore for the common single-context case.
134
- // `quiet: true` - otherwise dotenv prints an "injected env" tip line to stdout on every run, which
135
- // would corrupt `--json-output` mode (meant for clean, parseable JSON on stdout).
136
- dotenv.config({ quiet: true });
135
+ // Chỉ các lệnh làm việc trên dự án plugin mới đọc `.env` (xem projectEnv.mjs).
136
+ loadProjectEnv();
137
137
 
138
138
  {
139
139
  const selectedServer = process.env.AIVIN_BASE_URL
@@ -1447,6 +1447,17 @@ remoteCommand
1447
1447
  console.log(chalk.yellow('⏸ Đã tạm dừng — máy này từ chối mọi việc từ xa.'));
1448
1448
  });
1449
1449
 
1450
+ remoteCommand
1451
+ .command('disconnect')
1452
+ .description('Cut off whoever is viewing or controlling this screen; the next session must be allowed on this computer')
1453
+ .action(() => {
1454
+ if (!requestCastStop()) {
1455
+ console.log(chalk.gray('Không có ai đang xem màn hình máy này.'));
1456
+ return;
1457
+ }
1458
+ console.log(chalk.yellow('⏹ Đã gửi lệnh ngắt. Phiên xem sau phải bấm "Cho phép" trên máy này.'));
1459
+ });
1460
+
1450
1461
  remoteCommand
1451
1462
  .command('mascot [action] [combo]')
1452
1463
  .description('The Aivin mascot floating on screen while the listener runs (Windows): on | off — no argument shows the current setting; hotkey [combo|off|default] — the key combination for voice (default Alt+Shift+Space; off turns off both keys), with --chat the one that opens the ask box to type (default Alt+Space)')
@@ -1537,7 +1548,7 @@ remoteCommand
1537
1548
 
1538
1549
  remoteCommand
1539
1550
  .command('policy [action] [value]')
1540
- .description('Rules enforced on this computer itself (Aivin cannot change them): which steps need a click on this computer, tools turned off, extra blocked commands')
1551
+ .description('Rules enforced on this computer itself (Aivin cannot change them): which steps need a click on this computer, tools turned off, extra blocked commands, whether viewing this screen needs a click here (cast ask|unattended|off)')
1541
1552
  .action(async (action, value) => {
1542
1553
  try {
1543
1554
  await runPolicyCommand(action, value);
package/bin/lib/auth.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import { exec } from 'child_process';
2
+ import { execFile } from 'child_process';
3
3
  import http from 'http';
4
4
  import os from 'os';
5
5
  import { randomBytes } from 'crypto';
@@ -21,16 +21,30 @@ export function saveGlobalApiKey(apiKey, baseUrl = process.env.AIVIN_BASE_URL ||
21
21
  return saveActiveContext(baseUrl, apiKey, identity);
22
22
  }
23
23
 
24
+ /**
25
+ * Lệnh mở trình duyệt, không qua shell: URL có thể do máy chủ trả về nên không được ghép vào chuỗi lệnh. Chỉ http(s); sai thì null.
26
+ */
27
+ export function browserCommand(url, platform = process.platform, systemRoot = process.env.SystemRoot || 'C:\\Windows') {
28
+ let href;
29
+ try {
30
+ const parsed = new URL(url);
31
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;
32
+ href = parsed.href;
33
+ } catch {
34
+ return null;
35
+ }
36
+ if (platform === 'win32') return { file: `${systemRoot}\\System32\\rundll32.exe`, args: ['url.dll,FileProtocolHandler', href] };
37
+ return { file: platform === 'darwin' ? 'open' : 'xdg-open', args: [href] };
38
+ }
39
+
24
40
  export function openBrowser(url) {
25
- const platform = process.platform;
26
- const command =
27
- platform === 'win32' ? `start "" "${url}"` : platform === 'darwin' ? `open "${url}"` : `xdg-open "${url}"`;
28
- exec(command, (error) => {
29
- if (error) {
30
- console.log(chalk.yellow('Could not open a browser automatically - open this URL manually:'));
31
- console.log(chalk.cyan(` ${url}`));
32
- }
33
- });
41
+ const showManually = () => {
42
+ console.log(chalk.yellow('Could not open a browser automatically - open this URL manually:'));
43
+ console.log(chalk.cyan(` ${url}`));
44
+ };
45
+ const command = browserCommand(url);
46
+ if (!command) return showManually();
47
+ execFile(command.file, command.args, (error) => { if (error) showManually(); });
34
48
  }
35
49
 
36
50
  /**
@@ -0,0 +1,27 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import dotenv from 'dotenv';
4
+
5
+ /** Chỉ lệnh làm việc trên một dự án plugin mới đọc `.env` của thư mục hiện tại. Tệp này có thể đến từ repo vừa tải về hay tệp zip vừa giải nén. */
6
+ const PROJECT_COMMANDS = new Set(['create', 'init', 'validate', 'start', 'deploy', 'test', 'plugin', 'connector', 'pluginstore', 'mcp']);
7
+ /** Biến đổi cách CLI tin cậy mạng, chỗ lưu khoá, nguồn cập nhật: chỉ nhận từ môi trường thật, không nhận từ tệp trong dự án. */
8
+ const NEVER_FROM_PROJECT = /^(NODE_|AIVIN_(?!BASE_URL$|CLI_SDK_VERSION$|TRIGGER_TIMEOUT_MS$)|(HTTP|HTTPS|ALL|NO)_PROXY$)/i;
9
+
10
+ export function projectEnvEntries(argv, parsed) {
11
+ const command = argv.find((arg) => !arg.startsWith('-'));
12
+ if (!PROJECT_COMMANDS.has(command)) return {};
13
+ return Object.fromEntries(Object.entries(parsed).filter(([key]) => !NEVER_FROM_PROJECT.test(key)));
14
+ }
15
+
16
+ /** Không đè biến đã có sẵn trong môi trường thật. */
17
+ export function loadProjectEnv({ argv = process.argv.slice(2), env = process.env, file = path.resolve('.env') } = {}) {
18
+ let text;
19
+ try {
20
+ text = fs.readFileSync(file, 'utf8');
21
+ } catch {
22
+ return;
23
+ }
24
+ for (const [key, value] of Object.entries(projectEnvEntries(argv, dotenv.parse(text)))) {
25
+ if (env[key] === undefined) env[key] = value;
26
+ }
27
+ }