@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.
- package/README.md +16 -0
- package/bin/cli.mjs +67 -0
- package/bin/lib/remote/browserTunnel.mjs +47 -8
- package/bin/lib/remote/callLedger.mjs +73 -14
- package/bin/lib/remote/client.mjs +89 -8
- package/bin/lib/remote/cloudFiles.mjs +53 -0
- package/bin/lib/remote/constants.mjs +17 -0
- package/bin/lib/remote/dailyBrowser.mjs +8 -2
- package/bin/lib/remote/desktop/desktopCast.mjs +198 -0
- package/bin/lib/remote/desktop/desktopCastSource.mjs +514 -0
- package/bin/lib/remote/desktop/desktopWebRtc.mjs +95 -0
- package/bin/lib/remote/desktop/index.mjs +44 -7
- package/bin/lib/remote/desktop/linux.mjs +1 -1
- package/bin/lib/remote/desktop/linuxTraySource.mjs +434 -427
- package/bin/lib/remote/desktop/mac.mjs +2 -2
- package/bin/lib/remote/desktop/macTraySource.mjs +295 -292
- package/bin/lib/remote/desktop/traySource.mjs +541 -527
- package/bin/lib/remote/deviceProfile.mjs +1 -0
- package/bin/lib/remote/docText.mjs +85 -0
- package/bin/lib/remote/fileIndexer.mjs +757 -399
- package/bin/lib/remote/folderRules.mjs +140 -0
- package/bin/lib/remote/gui/index.mjs +126 -17
- package/bin/lib/remote/gui/windowsHost.mjs +9 -2
- package/bin/lib/remote/gui/windowsHostSource.mjs +194 -51
- package/bin/lib/remote/idempotency.mjs +49 -20
- package/bin/lib/remote/localPolicy.mjs +8 -2
- package/bin/lib/remote/mascot/askHostSource.mjs +18 -0
- package/bin/lib/remote/mascot/bot.mjs +29 -4
- package/bin/lib/remote/mascot/hostSource.mjs +4 -4
- package/bin/lib/remote/mascot/rigSource.mjs +12 -7
- package/bin/lib/remote/osSearch.mjs +107 -0
- package/bin/lib/remote/sqliteDb.mjs +51 -0
- package/bin/lib/remote/toolHandlers.mjs +788 -741
- package/bin/lib/remoteControl.mjs +26 -26
- package/docs/AIVIN_MASCOT.md +14 -0
- package/docs/CLI.md +1504 -1484
- package/docs/media/aivin-mascot-live.gif +0 -0
- package/docs/media/aivin-mascot-live.png +0 -0
- package/docs/media/aivin-remote-architecture.svg +102 -0
- package/package.json +71 -71
- package/docs/media/aivin-mascot-states.mp4 +0 -0
|
@@ -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
|
+
}
|