@aivin-labs/cli 1.0.11 → 1.0.21

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 (88) hide show
  1. package/README.md +325 -288
  2. package/bin/cli.mjs +163 -17
  3. package/bin/lib/localPreview.mjs +437 -0
  4. package/bin/lib/openFile.mjs +235 -0
  5. package/bin/lib/previewCache.mjs +71 -0
  6. package/bin/lib/remote/atomicFile.mjs +32 -0
  7. package/bin/lib/remote/autoStart.mjs +2 -1
  8. package/bin/lib/remote/autoUpdate.mjs +12 -0
  9. package/bin/lib/remote/browserTunnel.mjs +47 -8
  10. package/bin/lib/remote/callLedger.mjs +94 -14
  11. package/bin/lib/remote/cdpPolicy.mjs +14 -2
  12. package/bin/lib/remote/client.mjs +1024 -808
  13. package/bin/lib/remote/cloudFiles.mjs +53 -0
  14. package/bin/lib/remote/codingAgents.mjs +2 -2
  15. package/bin/lib/remote/constants.mjs +261 -234
  16. package/bin/lib/remote/credentials.mjs +81 -4
  17. package/bin/lib/remote/daemonLock.mjs +57 -17
  18. package/bin/lib/remote/dailyBrowser.mjs +8 -2
  19. package/bin/lib/remote/desktop/castInput.mjs +98 -0
  20. package/bin/lib/remote/desktop/desktopCast.mjs +334 -0
  21. package/bin/lib/remote/desktop/desktopCastCaptureSource.mjs +598 -0
  22. package/bin/lib/remote/desktop/desktopCastSource.mjs +798 -0
  23. package/bin/lib/remote/desktop/desktopWebRtc.mjs +242 -0
  24. package/bin/lib/remote/desktop/fileAssociation.mjs +108 -0
  25. package/bin/lib/remote/desktop/index.mjs +58 -7
  26. package/bin/lib/remote/desktop/linux.mjs +1 -1
  27. package/bin/lib/remote/desktop/linuxTraySource.mjs +427 -427
  28. package/bin/lib/remote/desktop/mac.mjs +2 -2
  29. package/bin/lib/remote/desktop/macTraySource.mjs +293 -292
  30. package/bin/lib/remote/desktop/strings.mjs +28 -2
  31. package/bin/lib/remote/desktop/traySource.mjs +905 -527
  32. package/bin/lib/remote/desktop/webrtcRuntime.mjs +137 -0
  33. package/bin/lib/remote/desktop/webrtcWorker.mjs +181 -0
  34. package/bin/lib/remote/deviceProfile.mjs +1 -0
  35. package/bin/lib/remote/docText.mjs +85 -0
  36. package/bin/lib/remote/fileIndexer.mjs +773 -399
  37. package/bin/lib/remote/folderRules.mjs +143 -0
  38. package/bin/lib/remote/gitSafe.mjs +31 -0
  39. package/bin/lib/remote/gui/index.mjs +170 -19
  40. package/bin/lib/remote/gui/officeHostSource.mjs +635 -393
  41. package/bin/lib/remote/gui/windowsHost.mjs +12 -3
  42. package/bin/lib/remote/gui/windowsHostSource.mjs +461 -87
  43. package/bin/lib/remote/httpTransfer.mjs +64 -3
  44. package/bin/lib/remote/idempotency.mjs +49 -20
  45. package/bin/lib/remote/localPolicy.mjs +81 -9
  46. package/bin/lib/remote/mascot/ask.mjs +207 -42
  47. package/bin/lib/remote/mascot/askBlocksSource.mjs +286 -0
  48. package/bin/lib/remote/mascot/askHostSource.mjs +658 -512
  49. package/bin/lib/remote/mascot/blocks.mjs +201 -0
  50. package/bin/lib/remote/mascot/bot.mjs +54 -5
  51. package/bin/lib/remote/mascot/chartLayout.mjs +382 -0
  52. package/bin/lib/remote/mascot/diagramRender.mjs +154 -0
  53. package/bin/lib/remote/mascot/emojiSource.mjs +273 -0
  54. package/bin/lib/remote/mascot/fileChips.mjs +62 -0
  55. package/bin/lib/remote/mascot/hostSource.mjs +331 -52
  56. package/bin/lib/remote/mascot/hotkey.mjs +31 -7
  57. package/bin/lib/remote/mascot/images.mjs +111 -0
  58. package/bin/lib/remote/mascot/index.mjs +663 -493
  59. package/bin/lib/remote/mascot/lucideIcons.mjs +32 -0
  60. package/bin/lib/remote/mascot/mermaidBundle.mjs +28 -0
  61. package/bin/lib/remote/mascot/mood.mjs +57 -0
  62. package/bin/lib/remote/mascot/rigSource.mjs +648 -609
  63. package/bin/lib/remote/mascot/safeUrl.mjs +29 -0
  64. package/bin/lib/remote/mascot/strings.mjs +456 -375
  65. package/bin/lib/remote/mascot/ui.mjs +27 -7
  66. package/bin/lib/remote/multiUser.mjs +7 -2
  67. package/bin/lib/remote/notify.mjs +4 -1
  68. package/bin/lib/remote/office/index.mjs +12 -6
  69. package/bin/lib/remote/osSearch.mjs +107 -0
  70. package/bin/lib/remote/processes.mjs +5 -2
  71. package/bin/lib/remote/sandbox.mjs +26 -0
  72. package/bin/lib/remote/secretPaths.mjs +21 -0
  73. package/bin/lib/remote/sqliteDb.mjs +51 -0
  74. package/bin/lib/remote/tokenRotation.mjs +28 -0
  75. package/bin/lib/remote/toolHandlers.mjs +852 -741
  76. package/bin/lib/remote/watchBatcher.mjs +56 -0
  77. package/bin/lib/remoteControl.mjs +26 -26
  78. package/bin/lib/selfUpdate.mjs +12 -2
  79. package/bin/lib/update/binarySwap.mjs +15 -1
  80. package/bin/lib/update/state.mjs +10 -0
  81. package/docs/AIVIN_MASCOT.md +14 -0
  82. package/docs/CLI.md +1545 -1484
  83. package/docs/media/aivin-ecosystem.jpg +0 -0
  84. package/docs/media/aivin-mascot-live.gif +0 -0
  85. package/docs/media/aivin-mascot-live.png +0 -0
  86. package/docs/media/aivin-remote-architecture.svg +102 -0
  87. package/package.json +75 -71
  88. package/docs/media/aivin-mascot-states.mp4 +0 -0
@@ -0,0 +1,201 @@
1
+ import { chartLayout } from './chartLayout.mjs';
2
+ import { lucidePath } from './lucideIcons.mjs';
3
+ import { safeWebUrl } from './safeUrl.mjs';
4
+ import { MascotText } from './strings.mjs';
5
+
6
+ /**
7
+ * Rich component của câu trả lời (`blocks` trong `device:chat_event` / `device:notify`) → lệnh cho cửa sổ linh vật (03/11/2026). BE đã giới hạn cỡ; ở đây chặn thêm vì
8
+ * cửa sổ dựng từng phần tử bằng PowerShell, gắn chữ đã dịch, tính độ rộng cột + hình biểu đồ, và gắn tệp ảnh sau khi daemon tải / dựng xong (images.mjs, diagramRender.mjs).
9
+ */
10
+ export const BlockType = Object.freeze({ TABLE: 'table', CARDS: 'cards', IMAGE: 'image', CHART: 'chart', DIAGRAM: 'diagram', WEBVIEW: 'webview', SCREENCAST: 'screencast', LINK_CARD: 'link_card', SOURCES: 'sources' });
11
+ const MAX_BLOCKS = 12;
12
+ const MAX_ROWS = 20;
13
+ const MAX_COLS = 8;
14
+ const MAX_CARDS = 12;
15
+ const MAX_TEXT = 300;
16
+ const MAX_DIAGRAM_CHARS = 20000;
17
+ const MAX_SOURCES = 8;
18
+ /** Bề rộng bảng trong ô đã nới rộng, ước lượng một ký tự chữ cỡ 12 (kể cả đậm) + lề hai bên một ô (askBlocksSource.mjs). */
19
+ const TABLE_WIDTH = 286;
20
+ const CHAR_WIDTH = 6.9;
21
+ const CELL_PADDING = 16;
22
+ /** Từ dài hơn thì chấp nhận xuống dòng giữa từ; chữ dài hơn không đòi thêm chỗ. */
23
+ const MIN_WORD_CHARS = 3;
24
+ const MAX_WORD_CHARS = 14;
25
+ const MAX_LINE_CHARS = 40;
26
+ /** Tên icon lạ: cùng icon dự phòng với thẻ trên web. */
27
+ const DEFAULT_CARD_ICON = 'sparkles';
28
+ const LINK_CARD_ICONS = Object.freeze({ video: 'play', file: 'file-text', link: 'external-link' });
29
+ const HEX_COLOR = /^#[0-9a-f]{6}$/i;
30
+ const ALIGNS = new Set(['left', 'center', 'right']);
31
+ /** Khoá tệp của sơ đồ trong bảng `files` của `withImageFiles` (URL ảnh là khoá của ảnh). */
32
+ const DIAGRAM_KEY = 'diagram:';
33
+
34
+ const str = (v) => (typeof v === 'string' ? v.trim().slice(0, MAX_TEXT) : typeof v === 'number' ? String(v) : '');
35
+
36
+ function normalizeCell(c) {
37
+ if (c?.covered === true) return { text: '', covered: true };
38
+ const span = Number.isInteger(c?.span) && c.span > 1 ? { span: Math.min(c.span, MAX_COLS) } : {};
39
+ const rowspan = Number.isInteger(c?.rowspan) && c.rowspan > 1 ? { rowspan: Math.min(c.rowspan, MAX_ROWS) } : {};
40
+ return {
41
+ text: str(c?.text), ...span, ...rowspan, ...(c?.bold === true ? { bold: true } : {}), ...(c?.italic === true ? { italic: true } : {}), ...(ALIGNS.has(c?.align) ? { align: c.align } : {}),
42
+ ...(HEX_COLOR.test(c?.bg) ? { bg: c.bg } : {}), ...(HEX_COLOR.test(c?.color) ? { color: c.color } : {}),
43
+ };
44
+ }
45
+
46
+ /**
47
+ * Độ rộng từng cột (px trên bề rộng `TABLE_WIDTH`, cửa sổ dùng làm tỉ lệ). Trước hết cột nào cũng đủ chỗ cho từ dài nhất của nó để không bẻ giữa từ / giữa số
48
+ * ("12.50 / 0.000"), chỗ còn lại chia theo độ dài chữ. Hết chỗ thì mới chia theo tỉ lệ phần tối thiểu. Hàng gộp ô không tính.
49
+ */
50
+ export function columnWeights(rows, cols) {
51
+ const plain = rows.filter((r) => !r.some((c) => c.span));
52
+ const measure = (col, read) => Math.max(0, ...plain.map((r) => read(r[col]?.text || '')));
53
+ const least = Array.from({ length: cols }, (_, col) => CELL_PADDING + CHAR_WIDTH * Math.max(MIN_WORD_CHARS, Math.min(MAX_WORD_CHARS, measure(col, (s) => Math.max(0, ...s.split(/[\s-]+/).map((w) => w.length))))));
54
+ const want = Array.from({ length: cols }, (_, col) => CELL_PADDING + CHAR_WIDTH * Math.min(MAX_LINE_CHARS, measure(col, (s) => s.length)));
55
+ const spare = TABLE_WIDTH - least.reduce((a, b) => a + b, 0);
56
+ if (spare <= 0) return least.map(Math.round);
57
+ const extra = want.map((w, i) => Math.max(0, w - least[i]));
58
+ const totalExtra = extra.reduce((a, b) => a + b, 0);
59
+ // Mọi cột đã đủ chỗ cho cả dòng: chia đều phần thừa.
60
+ return least.map((w, i) => Math.round(w + (totalExtra ? (spare * extra[i]) / totalExtra : spare / cols)));
61
+ }
62
+
63
+ function tableBlock(b, { t }) {
64
+ const rows = (Array.isArray(b.rows) ? b.rows : []).slice(0, MAX_ROWS).filter(Array.isArray).map((r) => r.slice(0, MAX_COLS).map(normalizeCell));
65
+ if (!rows.length) return null;
66
+ const cols = Math.min(MAX_COLS, Math.max(...rows.map((r) => r.reduce((n, c) => n + (c.span || 1), 0))));
67
+ const notes = [
68
+ b.more_rows > 0 ? t(MascotText.ASK_MORE_ROWS, { n: b.more_rows }) : '',
69
+ b.more_cols > 0 ? t(MascotText.ASK_MORE_COLS, { n: b.more_cols }) : '',
70
+ ].filter(Boolean);
71
+ return {
72
+ type: BlockType.TABLE, ...(str(b.title) ? { title: str(b.title) } : {}), header: b.header !== false, ...(b.plain === true ? { plain: true } : {}), cols, weights: columnWeights(rows, cols), rows,
73
+ ...(notes.length ? { note: notes.join(', ') } : {}),
74
+ };
75
+ }
76
+
77
+ function cardsBlock(b, { t }) {
78
+ const cards = (Array.isArray(b.cards) ? b.cards : []).slice(0, MAX_CARDS).filter((c) => str(c?.title)).map((c) => {
79
+ const image = safeWebUrl(c.image);
80
+ const tags = Array.isArray(c.tags) ? c.tags.map(str).filter(Boolean).slice(0, 4) : [];
81
+ return {
82
+ title: str(c.title), ...(str(c.text) ? { text: str(c.text) } : {}), ...(tags.length ? { tags } : {}), ...(str(c.footer) ? { footer: str(c.footer) } : {}),
83
+ icon_path: lucidePath(c.icon) || lucidePath(DEFAULT_CARD_ICON), ...(image ? { image } : {}),
84
+ };
85
+ });
86
+ if (!cards.length) return null;
87
+ return {
88
+ type: BlockType.CARDS, ...(str(b.title) ? { title: str(b.title) } : {}), cards,
89
+ ...(b.more > 0 ? { note: t(MascotText.ASK_MORE_CARDS, { n: b.more }) } : {}),
90
+ };
91
+ }
92
+
93
+ function imageBlock(b, { t }) {
94
+ const url = safeWebUrl(b.url);
95
+ if (!url) return null;
96
+ return { type: BlockType.IMAGE, url, ...(str(b.caption) ? { caption: str(b.caption) } : {}), open_text: str(b.caption) || t(MascotText.ASK_OPEN_IMAGE) };
97
+ }
98
+
99
+ function chartBlock(b, { t, lang }) {
100
+ const layout = chartLayout({ kind: b.kind, labels: (Array.isArray(b.labels) ? b.labels : []).map(str), series: Array.isArray(b.series) ? b.series.filter((s) => Array.isArray(s?.data)) : [] }, lang);
101
+ if (!layout) return null;
102
+ return {
103
+ type: BlockType.CHART, ...(str(b.title) ? { title: str(b.title) } : {}), layout,
104
+ ...(b.more > 0 ? { note: t(MascotText.ASK_MORE_POINTS, { n: b.more }) } : {}),
105
+ };
106
+ }
107
+
108
+ /** Sơ đồ: dựng xong thành ảnh, bấm mở phiên trên web để xem lớn (sơ đồ lớn thu vào ô hỏi sẽ khó đọc). Dựng hỏng → nút mở web. */
109
+ function diagramBlock(b, { t, webUrl }) {
110
+ if (typeof b.source !== 'string' || !b.source.trim() || b.source.length > MAX_DIAGRAM_CHARS) return null;
111
+ return { type: BlockType.DIAGRAM, source: b.source, ...(webUrl ? { url: webUrl } : {}), open_text: t(MascotText.ASK_OPEN_DIAGRAM) };
112
+ }
113
+
114
+ function webviewBlock(b, { t, sessionId }) {
115
+ if (typeof b.message_id !== 'string' || !b.message_id || !sessionId) return null;
116
+ return {
117
+ type: BlockType.WEBVIEW, session_id: sessionId, message_id: b.message_id, index: Number.isInteger(b.index) ? b.index : 0,
118
+ title: str(b.title) || t(MascotText.ASK_WEBVIEW_TITLE), action: t(MascotText.ASK_WEBVIEW_OPEN), icon_path: lucidePath('app-window'),
119
+ };
120
+ }
121
+
122
+ function screencastBlock(b, { t, webUrl }) {
123
+ if (!webUrl) return null;
124
+ const site = safeWebUrl(b.url);
125
+ return {
126
+ type: BlockType.LINK_CARD, title: str(b.title) || t(MascotText.ASK_SCREENCAST_TITLE), text: site ? new URL(site).hostname : t(MascotText.ASK_SCREENCAST_HINT),
127
+ url: webUrl, action: t(MascotText.ASK_OPEN_WEB), icon_path: lucidePath('globe'),
128
+ };
129
+ }
130
+
131
+ function linkCardBlock(b) {
132
+ const url = safeWebUrl(b.url);
133
+ if (!url || !str(b.title)) return null;
134
+ return {
135
+ type: BlockType.LINK_CARD, title: str(b.title), ...(str(b.text) ? { text: str(b.text) } : {}), url, ...(str(b.label) ? { action: str(b.label) } : {}),
136
+ icon_path: lucidePath(b.icon) || lucidePath(LINK_CARD_ICONS[b.kind] || LINK_CARD_ICONS.link),
137
+ };
138
+ }
139
+
140
+ function sourcesBlock(b, { t }) {
141
+ const items = (Array.isArray(b.items) ? b.items : []).slice(0, MAX_SOURCES).filter((i) => str(i?.name)).map((i) => {
142
+ const url = safeWebUrl(i.url);
143
+ return { name: str(i.name), ...(url ? { url } : {}) };
144
+ });
145
+ return items.length ? { type: BlockType.SOURCES, label: t(MascotText.ASK_SOURCES), items } : null;
146
+ }
147
+
148
+ const BUILDERS = Object.freeze({
149
+ [BlockType.TABLE]: tableBlock, [BlockType.CARDS]: cardsBlock, [BlockType.IMAGE]: imageBlock, [BlockType.CHART]: chartBlock, [BlockType.DIAGRAM]: diagramBlock,
150
+ [BlockType.WEBVIEW]: webviewBlock, [BlockType.SCREENCAST]: screencastBlock, [BlockType.LINK_CARD]: linkCardBlock, [BlockType.SOURCES]: sourcesBlock,
151
+ });
152
+
153
+ /** Khối BE gửi → khối gửi cửa sổ; loại lạ / rỗng bị bỏ. Không còn gì → null. `ctx`: `{ t, lang, webUrl (phiên trên web), sessionId }`. */
154
+ export function normalizeBlocks(raw, ctx) {
155
+ if (!Array.isArray(raw)) return null;
156
+ const out = raw.slice(0, MAX_BLOCKS).map((b) => {
157
+ const build = typeof b?.type === 'string' && Object.prototype.hasOwnProperty.call(BUILDERS, b.type) ? BUILDERS[b.type] : null;
158
+ return build ? build(b, ctx) : null;
159
+ }).filter(Boolean);
160
+ return out.length ? out : null;
161
+ }
162
+
163
+ /** Mọi tài nguyên cần tải / dựng trong các khối (URL ảnh, thẻ, `diagram:<mã>`), không trùng. */
164
+ export function imageUrlsOf(blocks) {
165
+ const urls = new Set();
166
+ for (const b of blocks || []) {
167
+ if (b.type === BlockType.IMAGE) urls.add(b.url);
168
+ if (b.type === BlockType.DIAGRAM) urls.add(`${DIAGRAM_KEY}${b.source}`);
169
+ if (b.type === BlockType.CARDS) for (const c of b.cards) if (c.image) urls.add(c.image);
170
+ }
171
+ return [...urls];
172
+ }
173
+
174
+ /** Khoá `imageUrlsOf` → mã sơ đồ, không phải sơ đồ → null. */
175
+ export function diagramSourceOf(key) {
176
+ return String(key).startsWith(DIAGRAM_KEY) ? String(key).slice(DIAGRAM_KEY.length) : null;
177
+ }
178
+
179
+ /**
180
+ * Gắn tệp đã tải (`files`: khoá → đường dẫn | null) vào các khối, bỏ cờ chờ. Khối ảnh / sơ đồ hỏng giữ lại không có `file`: cửa sổ vẽ thành nút mở link. Thẻ tải ảnh
181
+ * hỏng về icon. Sơ đồ đã xong thì bỏ mã nguồn, cửa sổ không cần.
182
+ */
183
+ export function withImageFiles(blocks, files) {
184
+ return blocks.map((b) => {
185
+ if (b.type === BlockType.IMAGE) return { ...b, done: true, ...(files.get(b.url) ? { file: files.get(b.url) } : {}) };
186
+ if (b.type === BlockType.DIAGRAM) {
187
+ const { source, ...rest } = b;
188
+ const file = files.get(`${DIAGRAM_KEY}${source}`);
189
+ return { ...rest, done: true, ...(file ? { file } : {}) };
190
+ }
191
+ if (b.type !== BlockType.CARDS) return b;
192
+ return {
193
+ ...b,
194
+ cards: b.cards.map((c) => {
195
+ if (!c.image) return c;
196
+ const { image, ...rest } = c;
197
+ return files.get(image) ? { ...rest, file: files.get(image) } : rest;
198
+ }),
199
+ };
200
+ });
201
+ }
@@ -67,10 +67,19 @@ export const BOT_FACES = Object.freeze({
67
67
  // Phản ứng (hostSource.mjs): xong sau khi lỗi → nhắm mắt thở phào; rảnh lâu sắp ngủ gật → ngáp.
68
68
  relief: { eyes: 'closed', mouth: 'smile' },
69
69
  yawn: { eyes: 'closed', mouth: 'open' },
70
+ // Cử chỉ biểu cảm mở rộng:
71
+ wink: { eyes: 'wink', mouth: 'grin' },
72
+ curious: { eyes: 'curious', mouth: 'hmm' },
73
+ star: { eyes: 'star', mouth: 'grin' },
74
+ // Theo emoji của câu trả lời (mood.mjs): xin lỗi / tiếc → mắt cụp, lông mày xếch trong, miệng mếu; ngượng (😅) → cười híp, miệng méo.
75
+ sad: { eyes: 'droop', mouth: 'frown' },
76
+ // Khóc (😭 / 😢): mắt cụp như buồn, miệng mếu há; nước mắt do rig vẽ (BOT_TEARS).
77
+ cry: { eyes: 'droop', mouth: 'wail' },
78
+ sheepish: { eyes: 'happy', mouth: 'hmm' },
70
79
  });
71
80
 
72
- export const BOT_EYES = Object.freeze(['open', 'focus', 'up', 'wide', 'happy', 'closed', 'sad', 'dizzy']);
73
- export const BOT_MOUTHS = Object.freeze(['smile', 'flat', 'hmm', 'open', 'grin', 'wobble', 'talk']);
81
+ export const BOT_EYES = Object.freeze(['open', 'focus', 'up', 'wide', 'happy', 'closed', 'sad', 'dizzy', 'wink', 'curious', 'star', 'droop']);
82
+ export const BOT_MOUTHS = Object.freeze(['smile', 'flat', 'hmm', 'open', 'grin', 'wobble', 'talk', 'frown', 'wail']);
74
83
 
75
84
  /**
76
85
  * Thông số chuyển động theo trạng thái (đơn vị bot / độ / Hz). Giá trị hiện tại luôn trượt dần về đích nên đổi trạng thái không giật.
@@ -101,6 +110,8 @@ const pill = (w, h, blink) => `<Rectangle Canvas.Left="${-w / 2}" Canvas.Top="${
101
110
 
102
111
  /** Mắt xoắn ốc (chóng mặt): các nửa vòng tròn nối nhau to dần quanh (0,0); rig quay `spin` (BOT_SPINS). */
103
112
  const spiral = (spin) => `<Path Data="M0,0 A1.6,1.6 0 0 1 3.2,0 A3.2,3.2 0 0 1 -3.2,0 A4.8,4.8 0 0 1 6.4,0 A6.4,6.4 0 0 1 -6.4,0" ${glowStroke(2.4)} Fill="{x:Null}"><Path.RenderTransform><RotateTransform x:Name="${spin}"/></Path.RenderTransform></Path>`;
113
+ /** Mắt ngôi sao 4 cánh phát sáng (hào hứng / ăn mừng). */
114
+ const starEye = `<Path Data="M0,-6.5 Q1.2,-1.2 6.5,0 Q1.2,1.2 0,6.5 Q-1.2,1.2 -6.5,0 Q-1.2,-1.2 0,-6.5 Z" ${glowStroke(2.2)} Fill="${GLOW}"/>`;
104
115
  /** Tên các RotateTransform của mắt xoắn ốc (rigSource.mjs quay khi chóng mặt). */
105
116
  export const BOT_SPINS = Object.freeze(['SpinL', 'SpinR']);
106
117
 
@@ -108,15 +119,34 @@ export const BOT_SPINS = Object.freeze(['SpinL', 'SpinR']);
108
119
  const EYE_SHAPES = {
109
120
  open: [pill(10, 14, 'BlinkL'), pill(10, 14, 'BlinkR')],
110
121
  focus: [pill(10, 8, 'BlinkFL'), pill(10, 8, 'BlinkFR')],
111
- up: [`<Canvas Canvas.Left="2" Canvas.Top="-3.5">${pill(9, 12)}</Canvas>`],
122
+ up: [
123
+ `<Canvas Canvas.Left="2" Canvas.Top="-3.5">${pill(9, 12, 'BlinkUL')}</Canvas>`,
124
+ `<Canvas Canvas.Left="2" Canvas.Top="-3.5">${pill(9, 12, 'BlinkUR')}</Canvas>`,
125
+ ],
112
126
  wide: [pill(12.5, 16, 'BlinkWL'), pill(12.5, 16, 'BlinkWR')],
113
127
  happy: [`<Path Data="M-8,3 Q0,-8 8,3" ${glowStroke()} Fill="{x:Null}"/>`],
114
128
  closed: [`<Path Data="M-7,0 Q0,5 7,0" ${glowStroke()} Fill="{x:Null}"/>`],
115
129
  sad: [`<Path Data="M-7,3 Q-1,-5 7,-1" ${glowStroke()} Fill="{x:Null}"/>`, `<Path Data="M-7,-1 Q1,-5 7,3" ${glowStroke()} Fill="{x:Null}"/>`],
116
130
  dizzy: [spiral('SpinL'), spiral('SpinR')],
131
+ wink: [`<Path Data="M-8,3 Q0,-8 8,3" ${glowStroke()} Fill="{x:Null}"/>`, pill(10, 14, 'BlinkWnkR')],
132
+ curious: [pill(10, 8, 'BlinkCurL'), pill(12.5, 16, 'BlinkCurR')],
133
+ star: [starEye],
134
+ // Buồn / xin lỗi: mắt thấp hơn, lông mày xếch lên ở phía trong (hai đầu gần nhau cao hơn).
135
+ droop: [
136
+ `<Canvas Canvas.Top="1.5">${pill(10, 11, 'BlinkDrL')}</Canvas><Path Data="M-6.5,-8 L4.5,-11.5" ${glowStroke(2.6)}/>`,
137
+ `<Canvas Canvas.Top="1.5">${pill(10, 11, 'BlinkDrR')}</Canvas><Path Data="M-4.5,-11.5 L6.5,-8" ${glowStroke(2.6)}/>`,
138
+ ],
117
139
  };
118
140
  /** Tên các ScaleTransform chớp mắt (rigSource.mjs đặt ScaleY). */
119
- export const BOT_BLINKS = Object.freeze(['BlinkL', 'BlinkR', 'BlinkFL', 'BlinkFR', 'BlinkWL', 'BlinkWR']);
141
+ export const BOT_BLINKS = Object.freeze([
142
+ 'BlinkL', 'BlinkR',
143
+ 'BlinkFL', 'BlinkFR',
144
+ 'BlinkUL', 'BlinkUR',
145
+ 'BlinkWL', 'BlinkWR',
146
+ 'BlinkWnkR',
147
+ 'BlinkCurL', 'BlinkCurR',
148
+ 'BlinkDrL', 'BlinkDrR',
149
+ ]);
120
150
 
121
151
  const eyeSide = (side) => BOT_EYES.map((n) => {
122
152
  const [left, right] = EYE_SHAPES[n];
@@ -131,8 +161,20 @@ const MOUTH_SHAPES = {
131
161
  grin: `<Path Data="M-8,-2.5 C-4,-3.6 4,-3.6 8,-2.5 C7.4,4.6 3.8,7.6 0,7.6 C-3.8,7.6 -7.4,4.6 -8,-2.5 Z" Fill="${GLOW}" Stroke="${GLOW}" StrokeThickness="2.2" StrokeLineJoin="Round"/>`,
132
162
  wobble: `<Path Data="M-6.5,2 C-4.5,-0.8 -2,-0.8 0,1.4 C2,3.6 4.5,3.6 6.5,0.8" ${glowStroke(3.6)} Fill="{x:Null}"/>`,
133
163
  talk: `<Ellipse Canvas.Left="-5" Canvas.Top="-4" Width="10" Height="8" Fill="${GLOW}" RenderTransformOrigin="0.5,0.5"><Ellipse.RenderTransform><ScaleTransform x:Name="MouthTalkScale"/></Ellipse.RenderTransform></Ellipse>`,
164
+ frown: `<Path Data="M-5.5,2.4 C-3.5,-1.6 3.5,-1.6 5.5,2.4" ${glowStroke(4)} Fill="{x:Null}"/>`,
165
+ // Khóc: miệng mếu há (đáy phẳng, đỉnh cong lên).
166
+ wail: `<Path Data="M-5.5,3 C-4.5,-3 4.5,-3 5.5,3 Z" Fill="${GLOW}" Stroke="${GLOW}" StrokeThickness="2" StrokeLineJoin="Round"/>`,
134
167
  };
135
168
 
169
+ /**
170
+ * Nước mắt (khóc): mỗi mắt 2 giọt so le, rơi từ dưới mắt xuống ngang miệng rồi tan; rig dời `TearMove*` + chỉnh độ mờ từng giọt, cả cụm
171
+ * `Tears` ẩn khi không khóc. Nằm trong `EyeLook` nên đi theo hướng nhìn của mắt.
172
+ */
173
+ export const BOT_TEARS = Object.freeze(['L0', 'L1', 'R0', 'R1']);
174
+ const TEAR = { x: 17, y: 5, color: '#E6FBFF' };
175
+ const tearDrop = (id) => `<Path x:Name="Tear${id}" Canvas.Left="${id[0] === 'L' ? -TEAR.x : TEAR.x}" Canvas.Top="${TEAR.y}" Data="M0,-4.6 Q3.7,1.1 0,4 Q-3.7,1.1 0,-4.6 Z" Fill="${TEAR.color}" Opacity="0"><Path.RenderTransform><TranslateTransform x:Name="TearMove${id}"/></Path.RenderTransform></Path>`;
176
+ const TEARS_XAML = `<Canvas x:Name="Tears" Visibility="Collapsed">${BOT_TEARS.map(tearDrop).join('')}</Canvas>`;
177
+
136
178
  const R = BOT_RIG;
137
179
  const V = R.visor;
138
180
  const F = R.face;
@@ -245,7 +287,7 @@ const THINK_XAML = `<Canvas x:Name="Think" Opacity="0" IsHitTestVisible="False">
245
287
  ${thinkCircle(TK.x - TK.w / 2 - 16, TK.y + TK.h / 2 + 20, 4)}
246
288
  ${thinkCircle(TK.x - TK.w / 2 - 5, TK.y + TK.h / 2 + 9, 6.2)}
247
289
  <Border Canvas.Left="${TK.x - TK.w / 2}" Canvas.Top="${TK.y - TK.h / 2}" Width="${TK.w}" Height="${TK.h}" CornerRadius="${TK.h / 2}" Background="White" BorderBrush="#D5DBE6" BorderThickness="1.2"/>
248
- ${[0, 1, 2].map((i) => `<Ellipse x:Name="ThinkDot${i}" Canvas.Left="${TK.x - TK.gap - TK.dot / 2 + i * TK.gap}" Canvas.Top="${TK.y - TK.dot / 2}" Width="${TK.dot}" Height="${TK.dot}" Fill="#3491FA"/>`).join('\n ')}
290
+ ${[0, 1, 2].map((i) => `<Ellipse x:Name="ThinkDot${i}" Canvas.Left="${TK.x - TK.gap - TK.dot / 2 + i * TK.gap}" Canvas.Top="${TK.y - TK.dot / 2}" Width="${TK.dot}" Height="${TK.dot}" Fill="#722ED1"/>`).join('\n ')}
249
291
  </Canvas>`;
250
292
 
251
293
  /** Tia lấp lánh (xong việc): sao bốn cánh vàng / xanh xen kẽ; rig đặt vị trí / cỡ / góc xoay. */
@@ -335,6 +377,12 @@ export const BOT_XAML = `<Canvas x:Name="Stage" Width="${S}" Height="${S}">
335
377
  <TranslateTransform X="${F.x}" Y="${F.y}"/>
336
378
  </TransformGroup></Canvas.RenderTransform>
337
379
  <Canvas.Effect><DropShadowEffect BlurRadius="7" ShadowDepth="0" Opacity="0.8" Color="${GLOW}"/></Canvas.Effect>
380
+ <Ellipse x:Name="BlushL" Canvas.Left="${-F.eyeDx - 4}" Canvas.Top="${F.eyeY + 8.5}" Width="8" Height="4" Fill="#FFA39E" Opacity="0">
381
+ <Ellipse.Effect><BlurEffect Radius="2.5"/></Ellipse.Effect>
382
+ </Ellipse>
383
+ <Ellipse x:Name="BlushR" Canvas.Left="${F.eyeDx - 4}" Canvas.Top="${F.eyeY + 8.5}" Width="8" Height="4" Fill="#FFA39E" Opacity="0">
384
+ <Ellipse.Effect><BlurEffect Radius="2.5"/></Ellipse.Effect>
385
+ </Ellipse>
338
386
  <Canvas><Canvas.RenderTransform><TranslateTransform x:Name="EyeLook"/></Canvas.RenderTransform>
339
387
  <Canvas x:Name="EyeL" Canvas.Left="${-F.eyeDx}" Canvas.Top="${F.eyeY}"><Canvas.RenderTransform><ScaleTransform x:Name="EyeMorphL"/></Canvas.RenderTransform>
340
388
  ${eyeSide('L')}
@@ -342,6 +390,7 @@ export const BOT_XAML = `<Canvas x:Name="Stage" Width="${S}" Height="${S}">
342
390
  <Canvas x:Name="EyeR" Canvas.Left="${F.eyeDx}" Canvas.Top="${F.eyeY}"><Canvas.RenderTransform><ScaleTransform x:Name="EyeMorphR"/></Canvas.RenderTransform>
343
391
  ${eyeSide('R')}
344
392
  </Canvas>
393
+ ${TEARS_XAML}
345
394
  </Canvas>
346
395
  <Canvas x:Name="Mouth" Canvas.Top="${F.mouthY}"><Canvas.RenderTransform><ScaleTransform x:Name="MouthMorph"/></Canvas.RenderTransform>
347
396
  ${BOT_MOUTHS.map((n) => `<Canvas x:Name="Mouth_${n}" Visibility="Collapsed">${MOUTH_SHAPES[n]}</Canvas>`).join('\n ')}