@aivin-labs/cli 1.0.11 → 1.0.13

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 (41) hide show
  1. package/README.md +16 -0
  2. package/bin/cli.mjs +67 -0
  3. package/bin/lib/remote/browserTunnel.mjs +47 -8
  4. package/bin/lib/remote/callLedger.mjs +73 -14
  5. package/bin/lib/remote/client.mjs +89 -8
  6. package/bin/lib/remote/cloudFiles.mjs +53 -0
  7. package/bin/lib/remote/constants.mjs +17 -0
  8. package/bin/lib/remote/dailyBrowser.mjs +8 -2
  9. package/bin/lib/remote/desktop/desktopCast.mjs +198 -0
  10. package/bin/lib/remote/desktop/desktopCastSource.mjs +514 -0
  11. package/bin/lib/remote/desktop/desktopWebRtc.mjs +95 -0
  12. package/bin/lib/remote/desktop/index.mjs +44 -7
  13. package/bin/lib/remote/desktop/linux.mjs +1 -1
  14. package/bin/lib/remote/desktop/linuxTraySource.mjs +434 -427
  15. package/bin/lib/remote/desktop/mac.mjs +2 -2
  16. package/bin/lib/remote/desktop/macTraySource.mjs +295 -292
  17. package/bin/lib/remote/desktop/traySource.mjs +541 -527
  18. package/bin/lib/remote/deviceProfile.mjs +1 -0
  19. package/bin/lib/remote/docText.mjs +85 -0
  20. package/bin/lib/remote/fileIndexer.mjs +757 -399
  21. package/bin/lib/remote/folderRules.mjs +140 -0
  22. package/bin/lib/remote/gui/index.mjs +126 -17
  23. package/bin/lib/remote/gui/windowsHost.mjs +9 -2
  24. package/bin/lib/remote/gui/windowsHostSource.mjs +194 -51
  25. package/bin/lib/remote/idempotency.mjs +49 -20
  26. package/bin/lib/remote/localPolicy.mjs +8 -2
  27. package/bin/lib/remote/mascot/askHostSource.mjs +18 -0
  28. package/bin/lib/remote/mascot/bot.mjs +29 -4
  29. package/bin/lib/remote/mascot/hostSource.mjs +4 -4
  30. package/bin/lib/remote/mascot/rigSource.mjs +12 -7
  31. package/bin/lib/remote/osSearch.mjs +107 -0
  32. package/bin/lib/remote/sqliteDb.mjs +51 -0
  33. package/bin/lib/remote/toolHandlers.mjs +788 -741
  34. package/bin/lib/remoteControl.mjs +26 -26
  35. package/docs/AIVIN_MASCOT.md +14 -0
  36. package/docs/CLI.md +1504 -1484
  37. package/docs/media/aivin-mascot-live.gif +0 -0
  38. package/docs/media/aivin-mascot-live.png +0 -0
  39. package/docs/media/aivin-remote-architecture.svg +102 -0
  40. package/package.json +71 -71
  41. package/docs/media/aivin-mascot-states.mp4 +0 -0
@@ -123,6 +123,7 @@ export function buildDeviceProfile(roots) {
123
123
  roots: roots.map((r) => path.resolve(r)),
124
124
  binaries: detectBinaries(),
125
125
  projects: detectProjects(roots),
126
+ desktop_cast: process.platform === 'win32',
126
127
  };
127
128
  }
128
129
 
@@ -95,6 +95,17 @@ export async function extractDocText(abs, size, maxChars = 600) {
95
95
  await handle.close();
96
96
  }
97
97
  }
98
+ if (ext === '.pdf') {
99
+ const handle = await fs.promises.open(abs, 'r');
100
+ try {
101
+ const readLen = Math.min(size, 2 * 1024 * 1024);
102
+ const buf = Buffer.alloc(readLen);
103
+ const { bytesRead } = await handle.read(buf, 0, readLen, 0);
104
+ return extractPdfText(buf.subarray(0, bytesRead), maxChars);
105
+ } finally {
106
+ await handle.close();
107
+ }
108
+ }
98
109
  if (!officeParts(ext, ['ppt/slides/slide1.xml']).length || size > MAX_ZIP_BYTES) return '';
99
110
  return clean(officeText(await fs.promises.readFile(abs), ext), maxChars);
100
111
  } catch {
@@ -115,3 +126,77 @@ export function wellFormed(text) {
115
126
  export function isDocFile(abs) {
116
127
  return DOC_EXTENSIONS.has(path.extname(abs).toLowerCase());
117
128
  }
129
+
130
+ function unescapePdfString(s) {
131
+ return String(s || '')
132
+ .replace(/\\([()\\])/g, '$1')
133
+ .replace(/\\n/g, '\n')
134
+ .replace(/\\r/g, '\r')
135
+ .replace(/\\t/g, '\t')
136
+ .replace(/\\([0-7]{1,3})/g, (_, oct) => String.fromCharCode(parseInt(oct, 8)));
137
+ }
138
+
139
+ /** Trích xuất nội dung văn bản từ các stream PDF (hỗ trợ cả stream nén FlateDecode và uncompressed). */
140
+ function extractPdfText(buf, maxChars) {
141
+ if (!buf || buf.length < 8) return '';
142
+ const str = buf.toString('latin1');
143
+ const textPieces = [];
144
+ let totalLen = 0;
145
+
146
+ const streamRe = /stream\r?\n([\s\S]*?)\r?\nendstream/g;
147
+ let m;
148
+ while ((m = streamRe.exec(str)) !== null) {
149
+ if (totalLen >= maxChars * 2) break;
150
+ const streamStart = m.index + m[0].indexOf('\n') + 1;
151
+ const streamEnd = m.index + m[0].lastIndexOf('endstream');
152
+ const streamRaw = buf.subarray(streamStart, Math.max(streamStart, streamEnd));
153
+ const dictSlice = str.slice(Math.max(0, m.index - 300), m.index);
154
+ let decoded = '';
155
+ if (/\/FlateDecode/i.test(dictSlice)) {
156
+ try { decoded = zlib.inflateSync(streamRaw).toString('latin1'); }
157
+ catch { try { decoded = zlib.inflateRawSync(streamRaw).toString('latin1'); } catch { decoded = ''; } }
158
+ } else {
159
+ decoded = streamRaw.toString('latin1');
160
+ }
161
+
162
+ if (!decoded || (!decoded.includes('BT') && !decoded.includes('Tj') && !decoded.includes('TJ'))) continue;
163
+
164
+ const tjRe = /\(((?:[^)\\]|\\.)*)\)\s*(?:Tj|'|")/g;
165
+ let tm;
166
+ while ((tm = tjRe.exec(decoded)) !== null) {
167
+ const parsed = unescapePdfString(tm[1]);
168
+ if (parsed.trim()) {
169
+ textPieces.push(parsed.trim());
170
+ totalLen += parsed.length;
171
+ if (totalLen >= maxChars * 2) break;
172
+ }
173
+ }
174
+
175
+ const arrayTjRe = /\[((?:[^\]\\]|\\.)*)\]\s*TJ/g;
176
+ let am;
177
+ while ((am = arrayTjRe.exec(decoded)) !== null) {
178
+ const innerStr = am[1];
179
+ const innerRe = /\(((?:[^)\\]|\\.)*)\)/g;
180
+ let im;
181
+ while ((im = innerRe.exec(innerStr)) !== null) {
182
+ const parsed = unescapePdfString(im[1]);
183
+ if (parsed.trim()) {
184
+ textPieces.push(parsed.trim());
185
+ totalLen += parsed.length;
186
+ if (totalLen >= maxChars * 2) break;
187
+ }
188
+ }
189
+ }
190
+ }
191
+
192
+ if (!textPieces.length) {
193
+ const rawTj = /\(((?:[^)\\]|\\.)*)\)\s*Tj/g;
194
+ let rm;
195
+ while ((rm = rawTj.exec(str)) !== null) {
196
+ const parsed = unescapePdfString(rm[1]);
197
+ if (parsed.trim()) textPieces.push(parsed.trim());
198
+ }
199
+ }
200
+
201
+ return clean(textPieces.join(' '), maxChars);
202
+ }