@aivin-labs/cli 1.0.8 → 1.0.11

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 (51) hide show
  1. package/README.md +25 -0
  2. package/bin/assets/aivin-mascot.png +0 -0
  3. package/bin/cli.mjs +1912 -1780
  4. package/bin/lib/browserAutomation.mjs +232 -469
  5. package/bin/lib/localBrowser.mjs +345 -0
  6. package/bin/lib/remote/activityLog.mjs +1 -1
  7. package/bin/lib/remote/autoStart.mjs +174 -14
  8. package/bin/lib/remote/browserTunnel.mjs +142 -31
  9. package/bin/lib/remote/callLedger.mjs +1 -1
  10. package/bin/lib/remote/cdpPolicy.mjs +14 -1
  11. package/bin/lib/remote/client.mjs +87 -5
  12. package/bin/lib/remote/clipboard.mjs +138 -0
  13. package/bin/lib/remote/codingAgents.mjs +293 -0
  14. package/bin/lib/remote/constants.mjs +61 -0
  15. package/bin/lib/remote/dailyBrowser.mjs +1 -1
  16. package/bin/lib/remote/desktop/index.mjs +272 -0
  17. package/bin/lib/remote/desktop/linux.mjs +144 -0
  18. package/bin/lib/remote/desktop/linuxTraySource.mjs +427 -0
  19. package/bin/lib/remote/desktop/mac.mjs +187 -0
  20. package/bin/lib/remote/desktop/macTraySource.mjs +292 -0
  21. package/bin/lib/remote/desktop/strings.mjs +74 -0
  22. package/bin/lib/remote/desktop/traySource.mjs +527 -0
  23. package/bin/lib/remote/docText.mjs +1 -1
  24. package/bin/lib/remote/fileIndexer.mjs +1 -1
  25. package/bin/lib/remote/gui/index.mjs +93 -12
  26. package/bin/lib/remote/gui/windowsHostSource.mjs +280 -28
  27. package/bin/lib/remote/idempotency.mjs +1 -1
  28. package/bin/lib/remote/localPolicy.mjs +9 -2
  29. package/bin/lib/remote/mascot/adpcm.mjs +70 -0
  30. package/bin/lib/remote/mascot/ask.mjs +768 -0
  31. package/bin/lib/remote/mascot/askHostSource.mjs +512 -0
  32. package/bin/lib/remote/mascot/assets.mjs +825 -216
  33. package/bin/lib/remote/mascot/bot.mjs +372 -0
  34. package/bin/lib/remote/mascot/hostSource.mjs +498 -101
  35. package/bin/lib/remote/mascot/hotkey.mjs +66 -0
  36. package/bin/lib/remote/mascot/index.mjs +199 -28
  37. package/bin/lib/remote/mascot/labels.mjs +2 -3
  38. package/bin/lib/remote/mascot/rigSource.mjs +609 -0
  39. package/bin/lib/remote/mascot/strings.mjs +204 -18
  40. package/bin/lib/remote/mascot/ui.mjs +104 -0
  41. package/bin/lib/remote/mascot/voiceSource.mjs +584 -0
  42. package/bin/lib/remote/meeting/index.mjs +415 -0
  43. package/bin/lib/remote/meeting/recorder.mjs +109 -0
  44. package/bin/lib/remote/meeting/recorderSource.mjs +394 -0
  45. package/bin/lib/remote/meeting/transcribe.mjs +259 -0
  46. package/bin/lib/remote/tabGroups.mjs +209 -0
  47. package/bin/lib/remote/toolHandlers.mjs +15 -0
  48. package/docs/AIVIN_MASCOT.md +116 -0
  49. package/docs/CLI.md +142 -11
  50. package/docs/media/aivin-mascot-states.mp4 +0 -0
  51. package/package.json +1 -1
@@ -0,0 +1,70 @@
1
+ /**
2
+ * IMA ADPCM cho âm thanh nói chuyện giữa máy và Aivin (30/10/2026): PCM16 mono → 4 bit / mẫu (nhỏ đi 4 lần; gửi nhị phân thay base64 thêm
3
+ * ~1/3) — không cần thư viện native như Opus. Mỗi đoạn tự giải được (đầu đoạn mang trạng thái bộ mã hoá), mất một đoạn không làm hỏng đoạn
4
+ * sau. Cùng thuật toán với BE (`device-agent/helper/AdpcmHelper.ts`).
5
+ *
6
+ * Một đoạn: [int16 LE dự đoán][uint8 chỉ số bước][uint8 cờ: bit 0 = số mẫu lẻ] + 2 mẫu / byte (nửa thấp trước).
7
+ */
8
+ export const VOICE_CODEC = 'ima-adpcm';
9
+
10
+ const INDEX_TABLE = [-1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8];
11
+ const STEP_TABLE = [
12
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157, 173,
13
+ 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
14
+ 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, 15289, 16818,
15
+ 18500, 20350, 22385, 24623, 27086, 29794, 32767,
16
+ ];
17
+ const HEADER = 4;
18
+ const clamp = (v, lo, hi) => (v < lo ? lo : v > hi ? hi : v);
19
+
20
+ /** Bộ mã hoá giữ trạng thái giữa các đoạn của một luồng (âm thanh liền mạch). */
21
+ export function createAdpcmEncoder() {
22
+ let pred = 0;
23
+ let index = 0;
24
+ return (pcm) => {
25
+ const n = Math.floor(pcm.length / 2);
26
+ const out = Buffer.alloc(HEADER + Math.ceil(n / 2));
27
+ out.writeInt16LE(pred, 0);
28
+ out[2] = index;
29
+ out[3] = n % 2;
30
+ for (let i = 0; i < n; i++) {
31
+ let step = STEP_TABLE[index];
32
+ let diff = pcm.readInt16LE(i * 2) - pred;
33
+ let nib = 0;
34
+ if (diff < 0) { nib = 8; diff = -diff; }
35
+ let delta = step >> 3;
36
+ if (diff >= step) { nib |= 4; diff -= step; delta += step; }
37
+ step >>= 1;
38
+ if (diff >= step) { nib |= 2; diff -= step; delta += step; }
39
+ step >>= 1;
40
+ if (diff >= step) { nib |= 1; delta += step; }
41
+ pred = clamp(nib & 8 ? pred - delta : pred + delta, -32768, 32767);
42
+ index = clamp(index + INDEX_TABLE[nib], 0, 88);
43
+ out[HEADER + (i >> 1)] |= i & 1 ? nib << 4 : nib;
44
+ }
45
+ return out;
46
+ };
47
+ }
48
+
49
+ /** Giải một đoạn → PCM16 mono. Đoạn hỏng / rỗng → Buffer rỗng. */
50
+ export function decodeAdpcm(data) {
51
+ const buf = Buffer.isBuffer(data) ? data : data instanceof ArrayBuffer ? Buffer.from(data) : ArrayBuffer.isView(data) ? Buffer.from(data.buffer, data.byteOffset, data.byteLength) : null;
52
+ if (!buf || buf.length < HEADER) return Buffer.alloc(0);
53
+ let pred = buf.readInt16LE(0);
54
+ let index = clamp(buf[2], 0, 88);
55
+ const n = (buf.length - HEADER) * 2 - (buf[3] & 1);
56
+ const out = Buffer.alloc(n * 2);
57
+ for (let i = 0; i < n; i++) {
58
+ const byte = buf[HEADER + (i >> 1)];
59
+ const nib = i & 1 ? byte >> 4 : byte & 15;
60
+ const step = STEP_TABLE[index];
61
+ let delta = step >> 3;
62
+ if (nib & 4) delta += step;
63
+ if (nib & 2) delta += step >> 1;
64
+ if (nib & 1) delta += step >> 2;
65
+ pred = clamp(nib & 8 ? pred - delta : pred + delta, -32768, 32767);
66
+ index = clamp(index + INDEX_TABLE[nib], 0, 88);
67
+ out.writeInt16LE(pred, i * 2);
68
+ }
69
+ return out;
70
+ }