react-native-executorch 0.10.4 → 0.10.6
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 +10 -1
- package/android/build.gradle.kts +4 -3
- package/ios/RnExecutorch.mm +15 -17
- package/lib/module/extensions/speech/utils/textPartitioner.js +18 -6
- package/lib/module/extensions/speech/utils/textPartitioner.js.map +1 -1
- package/lib/module/fetcher/fetcher.js +35 -122
- package/lib/module/fetcher/fetcher.js.map +1 -1
- package/lib/module/fetcher/telemetry.js +1 -1
- package/lib/module/index.js +12 -13
- package/lib/module/index.js.map +1 -1
- package/lib/module/models.js +4 -2
- package/lib/module/models.js.map +1 -1
- package/lib/typescript/src/extensions/speech/utils/textPartitioner.d.ts.map +1 -1
- package/lib/typescript/src/fetcher/fetcher.d.ts +3 -7
- package/lib/typescript/src/fetcher/fetcher.d.ts.map +1 -1
- package/lib/typescript/src/models.d.ts.map +1 -1
- package/package.json +9 -7
- package/react-native-executorch.podspec +8 -7
- package/scripts/download-libs.js +65 -24
- package/src/extensions/speech/utils/textPartitioner.ts +12 -3
- package/src/fetcher/fetcher.ts +38 -131
- package/src/fetcher/telemetry.ts +1 -1
- package/src/models.ts +6 -1
- package/third-party/README.md +2 -1
package/scripts/download-libs.js
CHANGED
|
@@ -76,7 +76,7 @@ const http = require('http');
|
|
|
76
76
|
const fs = require('fs');
|
|
77
77
|
const path = require('path');
|
|
78
78
|
const { spawnSync } = require('child_process');
|
|
79
|
-
const { createHash } = require('crypto');
|
|
79
|
+
const { createHash, randomBytes } = require('crypto');
|
|
80
80
|
const { Buffer } = require('buffer');
|
|
81
81
|
|
|
82
82
|
// ---- Config ----------------------------------------------------------------
|
|
@@ -324,16 +324,16 @@ function warnAboutPlatformAsymmetry({ backends }, targets) {
|
|
|
324
324
|
|
|
325
325
|
// ---- Target detection ------------------------------------------------------
|
|
326
326
|
|
|
327
|
+
// The iOS artifacts come down on every host, not only on macOS. Expo's
|
|
328
|
+
// fingerprint runtime version hashes the whole package root for both platforms,
|
|
329
|
+
// so a Mac install that held them and a Linux EAS builder that did not computed
|
|
330
|
+
// different Android runtime versions (#1509). They are ~10 MB compressed.
|
|
327
331
|
function detectTargets() {
|
|
328
332
|
if (process.env.RNET_TARGET) {
|
|
329
333
|
return [process.env.RNET_TARGET];
|
|
330
334
|
}
|
|
331
335
|
|
|
332
|
-
const targets = [];
|
|
333
|
-
if (process.platform === 'darwin') {
|
|
334
|
-
targets.push('ios');
|
|
335
|
-
}
|
|
336
|
-
targets.push('android-arm64-v8a');
|
|
336
|
+
const targets = ['ios', 'android-arm64-v8a'];
|
|
337
337
|
if (!process.env.RNET_NO_X86_64) {
|
|
338
338
|
targets.push('android-x86_64');
|
|
339
339
|
}
|
|
@@ -414,34 +414,59 @@ function ensureDir(dir) {
|
|
|
414
414
|
fs.mkdirSync(dir, { recursive: true });
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
+
// Writes to a temp file beside `dest` and renames it into place once complete.
|
|
418
|
+
// Package managers can run this postinstall for several copies of the package
|
|
419
|
+
// at once (a monorepo whose workspaces resolve it with different peers), all
|
|
420
|
+
// sharing CACHE_DIR. Writing `dest` directly let one copy truncate a checksum
|
|
421
|
+
// or tarball while another was reading it. The rename is atomic, so a reader
|
|
422
|
+
// sees either the previous file or the complete new one.
|
|
417
423
|
function download(url, dest) {
|
|
424
|
+
const tmp = `${dest}.${process.pid}-${randomBytes(4).toString('hex')}.tmp`;
|
|
418
425
|
return new Promise((resolve, reject) => {
|
|
419
|
-
const file = fs.createWriteStream(
|
|
426
|
+
const file = fs.createWriteStream(tmp);
|
|
427
|
+
const fail = (err) => {
|
|
428
|
+
// Close before removing: on Windows an open handle makes the unlink fail
|
|
429
|
+
// with EBUSY, which then replaces the real error with the cleanup's. And
|
|
430
|
+
// `force` covers the case where the file was never created. Rejects only
|
|
431
|
+
// once the temp file is gone, so a failed download leaves nothing behind.
|
|
432
|
+
file.close(() => {
|
|
433
|
+
fs.rmSync(tmp, { force: true });
|
|
434
|
+
reject(err);
|
|
435
|
+
});
|
|
436
|
+
};
|
|
420
437
|
const get = (currentUrl) => {
|
|
421
438
|
const client = currentUrl.startsWith('http://') ? http : https;
|
|
422
439
|
const headers = {};
|
|
423
440
|
if (process.env.GITHUB_TOKEN && currentUrl.includes('github.com')) {
|
|
424
441
|
headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
|
|
425
442
|
}
|
|
426
|
-
client
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
443
|
+
client
|
|
444
|
+
.get(currentUrl, { headers }, (res) => {
|
|
445
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
446
|
+
res.resume();
|
|
447
|
+
return get(res.headers.location);
|
|
448
|
+
}
|
|
449
|
+
if (res.statusCode !== 200) {
|
|
450
|
+
res.resume();
|
|
451
|
+
return fail(new Error(`HTTP ${res.statusCode} for ${currentUrl}`));
|
|
452
|
+
}
|
|
453
|
+
res.pipe(file);
|
|
454
|
+
file.on('finish', () =>
|
|
455
|
+
file.close((err) => {
|
|
456
|
+
if (err) return fail(err);
|
|
457
|
+
try {
|
|
458
|
+
fs.renameSync(tmp, dest);
|
|
459
|
+
resolve();
|
|
460
|
+
} catch (renameErr) {
|
|
461
|
+
fail(renameErr);
|
|
462
|
+
}
|
|
463
|
+
})
|
|
464
|
+
);
|
|
465
|
+
})
|
|
466
|
+
.on('error', fail);
|
|
436
467
|
};
|
|
437
468
|
get(url);
|
|
438
|
-
file.on('error',
|
|
439
|
-
// Close before removing: on Windows an open handle makes the unlink fail
|
|
440
|
-
// with EBUSY, which then replaces the real error with the cleanup's. And
|
|
441
|
-
// `force` covers the case where the file was never created.
|
|
442
|
-
file.close(() => fs.rmSync(dest, { force: true }));
|
|
443
|
-
reject(err);
|
|
444
|
-
});
|
|
469
|
+
file.on('error', fail);
|
|
445
470
|
});
|
|
446
471
|
}
|
|
447
472
|
|
|
@@ -546,6 +571,17 @@ function expandPattern(root, pattern) {
|
|
|
546
571
|
return candidates.filter((candidate) => fs.existsSync(candidate));
|
|
547
572
|
}
|
|
548
573
|
|
|
574
|
+
function removeAppleDoubleFiles(dir) {
|
|
575
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
576
|
+
const entryPath = path.join(dir, entry.name);
|
|
577
|
+
if (entry.name.startsWith('._')) {
|
|
578
|
+
fs.rmSync(entryPath, { recursive: true, force: true });
|
|
579
|
+
} else if (entry.isDirectory()) {
|
|
580
|
+
removeAppleDoubleFiles(entryPath);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
549
585
|
function extract(tarball, destDir) {
|
|
550
586
|
ensureDir(destDir);
|
|
551
587
|
// `-m` stamps extracted files with the extraction time instead of the mtime
|
|
@@ -639,6 +675,8 @@ async function main() {
|
|
|
639
675
|
console.log(` ✓ Done`);
|
|
640
676
|
}
|
|
641
677
|
|
|
678
|
+
removeAppleDoubleFiles(THIRD_PARTY_DIR);
|
|
679
|
+
|
|
642
680
|
// Belt and braces to core no longer carrying backends: this also clears
|
|
643
681
|
// binaries left by an EARLIER install that had the backend enabled.
|
|
644
682
|
pruneDisabledBackends(targets, config);
|
|
@@ -658,10 +696,13 @@ module.exports = {
|
|
|
658
696
|
ALL_BACKENDS,
|
|
659
697
|
ALL_LIBS,
|
|
660
698
|
BACKEND_FILES,
|
|
699
|
+
detectTargets,
|
|
661
700
|
FEATURE_MAP,
|
|
662
701
|
findUserConfig,
|
|
663
702
|
readUserConfig,
|
|
664
703
|
pruneDisabledBackends,
|
|
704
|
+
removeAppleDoubleFiles,
|
|
665
705
|
sha256,
|
|
666
706
|
extract,
|
|
707
|
+
download,
|
|
667
708
|
};
|
|
@@ -7,8 +7,8 @@ import { RnExecuTorchError } from '../../../core/error';
|
|
|
7
7
|
type Tag = 'eos' | 'pause' | 'whitespace';
|
|
8
8
|
|
|
9
9
|
// Punctuation Regex Patterns
|
|
10
|
-
const EOS_PATTERN = /[
|
|
11
|
-
const PAUSE_PATTERN = /[,:\u2014\u00AB\u00BB]/;
|
|
10
|
+
const EOS_PATTERN = /[.?!;…|।॥¿¡。.!?;]/;
|
|
11
|
+
const PAUSE_PATTERN = /[,:\u2014\u00AB\u00BB、,:〜~]/;
|
|
12
12
|
const WHITESPACE_PATTERN = /\s/;
|
|
13
13
|
|
|
14
14
|
// Standard Partitioning Constants
|
|
@@ -124,9 +124,18 @@ export function partition(text: string, limit: number, options?: PartitionOption
|
|
|
124
124
|
|
|
125
125
|
const breakpoints: { idx: number; tag: Tag }[] = [];
|
|
126
126
|
let charIdx = 0;
|
|
127
|
+
let lastBpIdx = -1;
|
|
127
128
|
for (const char of text) {
|
|
129
|
+
const endIdx = charIdx + char.length - 1;
|
|
128
130
|
const t = tagFromChar(char);
|
|
129
|
-
if (
|
|
131
|
+
if (endIdx - lastBpIdx > limit) {
|
|
132
|
+
breakpoints.push({ idx: charIdx - 1, tag: 'whitespace' });
|
|
133
|
+
lastBpIdx = charIdx - 1;
|
|
134
|
+
}
|
|
135
|
+
if (t) {
|
|
136
|
+
breakpoints.push({ idx: endIdx, tag: t });
|
|
137
|
+
lastBpIdx = endIdx;
|
|
138
|
+
}
|
|
130
139
|
charIdx += char.length;
|
|
131
140
|
}
|
|
132
141
|
|
package/src/fetcher/fetcher.ts
CHANGED
|
@@ -14,9 +14,11 @@ const IS_ANDROID = Platform.OS === 'android';
|
|
|
14
14
|
// Persistent, per-app directory where downloaded model assets are cached.
|
|
15
15
|
// iOS: internal DocumentDir (not CacheDir) so the OS won't evict large models
|
|
16
16
|
// between runs and force a costly re-download.
|
|
17
|
-
// Android: the app-private EXTERNAL files dir (getExternalFilesDir)
|
|
18
|
-
// system DownloadManager
|
|
19
|
-
//
|
|
17
|
+
// Android: the app-private EXTERNAL files dir (getExternalFilesDir). It was
|
|
18
|
+
// picked so the system DownloadManager could stage into it; that backend
|
|
19
|
+
// is gone, but every model already on disk lives here, so moving the
|
|
20
|
+
// cache now would silently orphan all of them and re-download multi-GB
|
|
21
|
+
// files. Falls back to DocumentDir if unmounted.
|
|
20
22
|
const ANDROID_DIRECTORY = RNBlobUtil.fs.dirs.SDCardDir || RNBlobUtil.fs.dirs.DocumentDir;
|
|
21
23
|
const RNE_DIRECTORY = IS_ANDROID
|
|
22
24
|
? `${ANDROID_DIRECTORY}/react-native-executorch`
|
|
@@ -31,9 +33,7 @@ export interface DownloadOptions {
|
|
|
31
33
|
onProgress?: (progress: number) => void;
|
|
32
34
|
/**
|
|
33
35
|
* Aborts the download. The bytes fetched so far are kept so a later
|
|
34
|
-
* {@link download} of the same source resumes instead of restarting
|
|
35
|
-
* Android without the optional background downloader, where the system
|
|
36
|
-
* DownloadManager discards a cancelled transfer.
|
|
36
|
+
* {@link download} of the same source resumes instead of restarting.
|
|
37
37
|
*/
|
|
38
38
|
signal?: AbortSignal;
|
|
39
39
|
/**
|
|
@@ -176,24 +176,6 @@ async function foldResumedChunkIntoPartial(
|
|
|
176
176
|
await RNBlobUtil.fs.unlink(chunkPath).catch(() => {});
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
// DownloadManager's byte counter is 64-bit, but blob-util reads it out of the
|
|
180
|
-
// cursor with `getInt`, so what reaches JS is the low 32 bits reinterpreted as
|
|
181
|
-
// a signed int: past 2 GB it arrives NEGATIVE and wraps every 4 GB after that.
|
|
182
|
-
// Multi-GB LLM models spend most of their download inside that range, which is
|
|
183
|
-
// what collapsed their progress bar. The counter only ever grows, so the
|
|
184
|
-
// discarded high bits can be rebuilt by counting how often the low ones wrap.
|
|
185
|
-
const UINT32 = 0x100000000;
|
|
186
|
-
function reassemble32BitCounter(): (raw: number) => number {
|
|
187
|
-
let wraps = 0;
|
|
188
|
-
let previous = 0;
|
|
189
|
-
return (raw) => {
|
|
190
|
-
const low = raw < 0 ? raw + UINT32 : raw;
|
|
191
|
-
if (low < previous) wraps += 1;
|
|
192
|
-
previous = low;
|
|
193
|
-
return low + wraps * UINT32;
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
179
|
// Reports absolute bytes for one file. `total` is 0 when the transfer does not
|
|
198
180
|
// know the length yet — the receiver keeps using whatever length it already
|
|
199
181
|
// had rather than treating the file as complete.
|
|
@@ -249,8 +231,7 @@ async function downloadUrl(url: string, cb: DownloadUrlCallbacks): Promise<strin
|
|
|
249
231
|
// something a later download would CONTINUE from: the staged `.partial` and,
|
|
250
232
|
// with the background downloader in play, a paused task holding resume data.
|
|
251
233
|
// Clear it, or "download it again" quietly resumes the very attempt the
|
|
252
|
-
// caller is trying to replace.
|
|
253
|
-
// here — it unlinks its own staging file before every transfer.
|
|
234
|
+
// caller is trying to replace.
|
|
254
235
|
await discardPartialDownload(dest);
|
|
255
236
|
} else if (await RNBlobUtil.fs.exists(dest)) {
|
|
256
237
|
// Cache hit — nothing to download.
|
|
@@ -296,30 +277,19 @@ async function startDownload(url: string, dest: string, entry: InFlightDownload)
|
|
|
296
277
|
};
|
|
297
278
|
|
|
298
279
|
// The optional background downloader wins on BOTH platforms when the app has
|
|
299
|
-
// it
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
// Without it each platform falls back to the best it can do on its own, and
|
|
303
|
-
// only iOS loses background transfers by doing so — blob-util's in-process
|
|
304
|
-
// reader is broken on Android (RonRadtke/react-native-blob-util#475: it stops
|
|
305
|
-
// after 8 KB), so the system DownloadManager is not a preference there but the
|
|
306
|
-
// only backend that works at all.
|
|
280
|
+
// it; without it both fall back to the same in-process stream. One mechanism
|
|
281
|
+
// plus one shared fallback, so a caller sees the same behavior everywhere.
|
|
307
282
|
const backgroundDownloader = loadBackgroundDownloader();
|
|
308
283
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
} else if (IS_ANDROID) {
|
|
313
|
-
path = await downloadUrlViaAndroidDownloadManager(url, dest, cb);
|
|
314
|
-
} else {
|
|
315
|
-
path = await downloadUrlViaIosStream(url, dest, cb);
|
|
316
|
-
}
|
|
284
|
+
const path = backgroundDownloader
|
|
285
|
+
? await downloadUrlViaBackgroundSession(backgroundDownloader, url, dest, cb)
|
|
286
|
+
: await downloadUrlViaStream(url, dest, cb);
|
|
317
287
|
|
|
318
|
-
// Neither backend is guaranteed to emit a last sample at 100%: blob-util
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
//
|
|
322
|
-
//
|
|
288
|
+
// Neither backend is guaranteed to emit a last sample at 100%: blob-util only
|
|
289
|
+
// started reporting the final event reliably in 0.25.0, and the background
|
|
290
|
+
// downloader throttles its own. Without this a finished file stays stuck a
|
|
291
|
+
// little short of its own size, and in a multi-file config that shortfall is
|
|
292
|
+
// what the user sees while the remaining files download.
|
|
323
293
|
const finalSize = await fileSize(path);
|
|
324
294
|
if (finalSize > 0) cb.onBytes?.(finalSize, finalSize);
|
|
325
295
|
|
|
@@ -347,72 +317,6 @@ function joinDownload(entry: InFlightDownload, cb: DownloadUrlCallbacks): Promis
|
|
|
347
317
|
});
|
|
348
318
|
}
|
|
349
319
|
|
|
350
|
-
// Android fallback used when that optional dependency is absent: the system
|
|
351
|
-
// DownloadManager streams to app-private external storage. blob-util's
|
|
352
|
-
// in-process reader cannot stand in for it — upstream #475 makes that path stop
|
|
353
|
-
// after 8 KB — and DownloadManager also handles files larger than 2 GB, keeps
|
|
354
|
-
// downloading while the app is in the background or killed, and resumes across
|
|
355
|
-
// transient network drops on its own, so no manual Range logic.
|
|
356
|
-
async function downloadUrlViaAndroidDownloadManager(
|
|
357
|
-
url: string,
|
|
358
|
-
dest: string,
|
|
359
|
-
cb: DownloadUrlCallbacks
|
|
360
|
-
): Promise<string> {
|
|
361
|
-
const tmp = `${dest}.downloading`;
|
|
362
|
-
await RNBlobUtil.fs.unlink(tmp).catch(() => {});
|
|
363
|
-
|
|
364
|
-
if (cb.signal?.aborted) throw abortError();
|
|
365
|
-
|
|
366
|
-
const task = RNBlobUtil.config({
|
|
367
|
-
addAndroidDownloads: {
|
|
368
|
-
useDownloadManager: true,
|
|
369
|
-
path: tmp,
|
|
370
|
-
notification: false,
|
|
371
|
-
mediaScannable: false,
|
|
372
|
-
mime: 'application/octet-stream',
|
|
373
|
-
},
|
|
374
|
-
}).fetch('GET', url);
|
|
375
|
-
|
|
376
|
-
const onAbort = () => task.cancel();
|
|
377
|
-
cb.signal?.addEventListener('abort', onAbort);
|
|
378
|
-
|
|
379
|
-
// DownloadManager reports total as -1 until the size is known; pass that on
|
|
380
|
-
// as 0 rather than echoing the received count, which would otherwise look
|
|
381
|
-
// like a file that is complete at every sample.
|
|
382
|
-
const absoluteBytes = reassemble32BitCounter();
|
|
383
|
-
task.progress({ count: 100 }, (received, total) => {
|
|
384
|
-
const tot = Number(total);
|
|
385
|
-
cb.onBytes?.(absoluteBytes(Number(received)), tot > 0 ? tot : 0);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
try {
|
|
389
|
-
await task;
|
|
390
|
-
} catch (e) {
|
|
391
|
-
await RNBlobUtil.fs.unlink(tmp).catch(() => {});
|
|
392
|
-
throw cb.signal?.aborted ? abortError() : e;
|
|
393
|
-
} finally {
|
|
394
|
-
cb.signal?.removeEventListener('abort', onAbort);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// DownloadManager doesn't surface an HTTP status; an empty file means failure.
|
|
398
|
-
const size = await fileSize(tmp);
|
|
399
|
-
if (size <= 0) {
|
|
400
|
-
await RNBlobUtil.fs.unlink(tmp).catch(() => {});
|
|
401
|
-
throw RnExecuTorchError('DOWNLOAD_FAILED', `Download of ${url} failed (empty response).`);
|
|
402
|
-
}
|
|
403
|
-
// A non-empty file is not necessarily a complete one, and DownloadManager
|
|
404
|
-
// gives us no status to check. Promoting a short file would cache it under
|
|
405
|
-
// its final name forever — the existence-only cache check can't tell the
|
|
406
|
-
// difference, and a truncated .pte only fails much later, at load.
|
|
407
|
-
const expected = await expectedBytesFor(url, cb.expectedBytes, cb.signal);
|
|
408
|
-
if (isTruncated(size, expected)) {
|
|
409
|
-
await RNBlobUtil.fs.unlink(tmp).catch(() => {});
|
|
410
|
-
throw incompleteError(url, size, expected);
|
|
411
|
-
}
|
|
412
|
-
await RNBlobUtil.fs.mv(tmp, dest);
|
|
413
|
-
return dest;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
320
|
// One background task per destination file, under an id that stays the same
|
|
417
321
|
// across app launches: that is what lets a later call adopt a transfer this
|
|
418
322
|
// process never started.
|
|
@@ -579,14 +483,19 @@ async function downloadUrlViaBackgroundSession(
|
|
|
579
483
|
return dest;
|
|
580
484
|
}
|
|
581
485
|
|
|
582
|
-
//
|
|
583
|
-
//
|
|
584
|
-
// suspended — iOS tears the connection down about a
|
|
585
|
-
//
|
|
586
|
-
//
|
|
587
|
-
// `canResume` is set to `false` on an
|
|
588
|
-
// if partial-file assembly ever fails.
|
|
589
|
-
|
|
486
|
+
// The fallback used on either platform when that optional dependency is absent:
|
|
487
|
+
// blob-util streams the response straight to disk, in process. It does NOT
|
|
488
|
+
// survive the app being suspended — iOS tears the connection down about a
|
|
489
|
+
// second later, and Android may kill the process outright — so an interrupted
|
|
490
|
+
// transfer is picked up by the next `download` call instead: it resumes from a
|
|
491
|
+
// `.partial` file via an HTTP Range request. `canResume` is set to `false` on an
|
|
492
|
+
// internal retry to avoid recursing forever if partial-file assembly ever fails.
|
|
493
|
+
//
|
|
494
|
+
// This path needs react-native-blob-util >=0.24.11 on Android. 0.24.10's reader
|
|
495
|
+
// stopped after exactly 8 KB with "Download interrupted"
|
|
496
|
+
// (RonRadtke/react-native-blob-util#475), which is why Android used the system
|
|
497
|
+
// DownloadManager until that fix shipped.
|
|
498
|
+
async function downloadUrlViaStream(
|
|
590
499
|
url: string,
|
|
591
500
|
dest: string,
|
|
592
501
|
cb: DownloadUrlCallbacks,
|
|
@@ -638,9 +547,9 @@ async function downloadUrlViaIosStream(
|
|
|
638
547
|
});
|
|
639
548
|
}
|
|
640
549
|
|
|
641
|
-
//
|
|
642
|
-
//
|
|
643
|
-
//
|
|
550
|
+
// blob-util floors the rate at one event per 250 ms regardless, so this only
|
|
551
|
+
// means a large file advances in ~1% steps instead of the 5% ones that made a
|
|
552
|
+
// multi-GB download look stalled between jumps.
|
|
644
553
|
task.progress({ count: 100 }, (received, total) => {
|
|
645
554
|
const recv = Number(received);
|
|
646
555
|
const tot = Number(total);
|
|
@@ -733,14 +642,14 @@ async function downloadUrlViaIosStream(
|
|
|
733
642
|
// once as a plain full download so correctness never depends on resume.
|
|
734
643
|
await RNBlobUtil.fs.unlink(part).catch(() => {});
|
|
735
644
|
await RNBlobUtil.fs.unlink(target).catch(() => {});
|
|
736
|
-
if (canResume) return
|
|
645
|
+
if (canResume) return downloadUrlViaStream(url, dest, cb, false);
|
|
737
646
|
throw assemblyErr;
|
|
738
647
|
}
|
|
739
648
|
|
|
740
649
|
if (restart) {
|
|
741
650
|
await RNBlobUtil.fs.unlink(part).catch(() => {});
|
|
742
651
|
await RNBlobUtil.fs.unlink(target).catch(() => {});
|
|
743
|
-
return
|
|
652
|
+
return downloadUrlViaStream(url, dest, cb, false);
|
|
744
653
|
}
|
|
745
654
|
|
|
746
655
|
// The transfer can also report success while the body was cut short — a
|
|
@@ -756,7 +665,7 @@ async function downloadUrlViaIosStream(
|
|
|
756
665
|
// start over rather than fail. A fresh transfer that overshoots is a wrong
|
|
757
666
|
// expectation instead, and falls through to be accepted.
|
|
758
667
|
await RNBlobUtil.fs.unlink(part).catch(() => {});
|
|
759
|
-
return
|
|
668
|
+
return downloadUrlViaStream(url, dest, cb, false);
|
|
760
669
|
}
|
|
761
670
|
if (isTruncated(assembled, expected)) {
|
|
762
671
|
// Short: keep the partial so the next call resumes and finishes it.
|
|
@@ -859,10 +768,8 @@ function substituteRemoteSources<T>(node: T, resolved: ReadonlyMap<string, strin
|
|
|
859
768
|
* and survive it being killed. The fetcher uses it automatically on both platforms
|
|
860
769
|
* when it is present, so the behavior is the same on each; nothing else changes.
|
|
861
770
|
*
|
|
862
|
-
* Without it
|
|
863
|
-
*
|
|
864
|
-
* and on iOS a streaming request that stops when the app is suspended and is
|
|
865
|
-
* resumed by the next `download` call.
|
|
771
|
+
* Without it both platforms fall back to the same streaming request, which stops
|
|
772
|
+
* when the app is suspended and is resumed by the next `download` call.
|
|
866
773
|
* @category Utils / Functions
|
|
867
774
|
* @typeParam T The shape of the value being resolved.
|
|
868
775
|
* @param source A URL, a local path, or any nested object/array holding them.
|
package/src/fetcher/telemetry.ts
CHANGED
|
@@ -10,7 +10,7 @@ const DOWNLOAD_EVENT_ENDPOINT = 'https://ai.swmansion.com/telemetry/downloads/ap
|
|
|
10
10
|
// self-referencing import would need package `exports` support in the consuming
|
|
11
11
|
// bundler to load at all. A wrong value here is analytics noise; a failed
|
|
12
12
|
// import would break the bundle.
|
|
13
|
-
const LIB_VERSION = '0.10.
|
|
13
|
+
const LIB_VERSION = '0.10.6';
|
|
14
14
|
|
|
15
15
|
// Anonymous analytics are on by default; apps opt out via setTelemetryEnabled.
|
|
16
16
|
let telemetryEnabled = true;
|
package/src/models.ts
CHANGED
|
@@ -922,10 +922,15 @@ const LFM2_5_EMBEDDING_350M_MLX_INT4: TextEmbedderModel = {
|
|
|
922
922
|
// =============================================================================
|
|
923
923
|
// Image Embeddings
|
|
924
924
|
// =============================================================================
|
|
925
|
+
// The exported image towers expect CLIP-normalized pixels (mean
|
|
926
|
+
// [0.48145466, 0.4578275, 0.40821073], std [0.26862954, 0.26130258, 0.27577711]).
|
|
925
927
|
const CLIP_IMAGE_EMBEDDINGS_OPTS = {
|
|
926
928
|
resizeMode: 'stretch' as const,
|
|
927
929
|
interpolation: 'linear' as const,
|
|
928
|
-
normalizeOpts: {
|
|
930
|
+
normalizeOpts: {
|
|
931
|
+
alpha: [1 / (255.0 * 0.26862954), 1 / (255.0 * 0.26130258), 1 / (255.0 * 0.27577711)],
|
|
932
|
+
beta: [-0.48145466 / 0.26862954, -0.4578275 / 0.26130258, -0.40821073 / 0.27577711],
|
|
933
|
+
},
|
|
929
934
|
};
|
|
930
935
|
const CLIP_VIT_BASE_PATCH32_IMAGE_XNNPACK_FP32: ImageEmbedderModel = {
|
|
931
936
|
modelPath: `${BASE_URL}-clip-vit-base-patch32/${NEXT_VERSION_TAG}/xnnpack/clip_vit_base_patch32_image_xnnpack_fp32.pte`,
|
package/third-party/README.md
CHANGED
|
@@ -16,7 +16,8 @@ Native ExecuTorch artifacts are split into **committed source** and
|
|
|
16
16
|
`scripts/download-libs.js` runs at **postinstall** and downloads the prebuilt
|
|
17
17
|
binaries from this repo's GitHub Releases (tag `v<package version>`), based on the
|
|
18
18
|
app's opted-in `backends` / `libs` / `features` (see the getting-started docs).
|
|
19
|
-
|
|
19
|
+
Both platforms' binaries are fetched on every host, so the package contents (and
|
|
20
|
+
Expo's fingerprint) do not depend on the OS that ran the install. It writes `rne-build-config.json`, which the podspec and `android/build.gradle.kts`
|
|
20
21
|
read to gate `RNE_ENABLE_*` and link only the requested backends.
|
|
21
22
|
|
|
22
23
|
Extracted layout the podspec / `android/CMakeLists.txt` expect:
|