react-native-executorch 0.5.4 → 0.5.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.
Files changed (107) hide show
  1. package/common/rnexecutorch/models/speech_to_text/SpeechToText.cpp +5 -5
  2. package/common/rnexecutorch/models/speech_to_text/SpeechToText.h +3 -7
  3. package/common/rnexecutorch/models/speech_to_text/asr/ASR.cpp +3 -0
  4. package/common/rnexecutorch/models/speech_to_text/asr/ASR.h +12 -11
  5. package/common/rnexecutorch/models/speech_to_text/stream/HypothesisBuffer.cpp +2 -0
  6. package/common/rnexecutorch/models/speech_to_text/stream/HypothesisBuffer.h +6 -8
  7. package/common/rnexecutorch/models/speech_to_text/stream/OnlineASRProcessor.cpp +3 -0
  8. package/common/rnexecutorch/models/speech_to_text/stream/OnlineASRProcessor.h +6 -9
  9. package/package.json +1 -1
  10. package/lib/Error.js +0 -53
  11. package/lib/ThreadPool.d.ts +0 -10
  12. package/lib/ThreadPool.js +0 -28
  13. package/lib/common/Logger.d.ts +0 -8
  14. package/lib/common/Logger.js +0 -19
  15. package/lib/constants/directories.js +0 -2
  16. package/lib/constants/llmDefaults.d.ts +0 -6
  17. package/lib/constants/llmDefaults.js +0 -16
  18. package/lib/constants/modelUrls.d.ts +0 -223
  19. package/lib/constants/modelUrls.js +0 -322
  20. package/lib/constants/ocr/models.d.ts +0 -882
  21. package/lib/constants/ocr/models.js +0 -182
  22. package/lib/constants/ocr/symbols.js +0 -139
  23. package/lib/constants/sttDefaults.d.ts +0 -28
  24. package/lib/constants/sttDefaults.js +0 -68
  25. package/lib/controllers/LLMController.d.ts +0 -47
  26. package/lib/controllers/LLMController.js +0 -213
  27. package/lib/controllers/OCRController.js +0 -67
  28. package/lib/controllers/SpeechToTextController.d.ts +0 -56
  29. package/lib/controllers/SpeechToTextController.js +0 -349
  30. package/lib/controllers/VerticalOCRController.js +0 -70
  31. package/lib/hooks/computer_vision/useClassification.d.ts +0 -15
  32. package/lib/hooks/computer_vision/useClassification.js +0 -7
  33. package/lib/hooks/computer_vision/useImageEmbeddings.d.ts +0 -15
  34. package/lib/hooks/computer_vision/useImageEmbeddings.js +0 -7
  35. package/lib/hooks/computer_vision/useImageSegmentation.d.ts +0 -38
  36. package/lib/hooks/computer_vision/useImageSegmentation.js +0 -7
  37. package/lib/hooks/computer_vision/useOCR.d.ts +0 -20
  38. package/lib/hooks/computer_vision/useOCR.js +0 -41
  39. package/lib/hooks/computer_vision/useObjectDetection.d.ts +0 -15
  40. package/lib/hooks/computer_vision/useObjectDetection.js +0 -7
  41. package/lib/hooks/computer_vision/useStyleTransfer.d.ts +0 -15
  42. package/lib/hooks/computer_vision/useStyleTransfer.js +0 -7
  43. package/lib/hooks/computer_vision/useVerticalOCR.d.ts +0 -21
  44. package/lib/hooks/computer_vision/useVerticalOCR.js +0 -43
  45. package/lib/hooks/general/useExecutorchModule.d.ts +0 -13
  46. package/lib/hooks/general/useExecutorchModule.js +0 -7
  47. package/lib/hooks/natural_language_processing/useLLM.d.ts +0 -10
  48. package/lib/hooks/natural_language_processing/useLLM.js +0 -78
  49. package/lib/hooks/natural_language_processing/useSpeechToText.d.ts +0 -27
  50. package/lib/hooks/natural_language_processing/useSpeechToText.js +0 -49
  51. package/lib/hooks/natural_language_processing/useTextEmbeddings.d.ts +0 -16
  52. package/lib/hooks/natural_language_processing/useTextEmbeddings.js +0 -7
  53. package/lib/hooks/natural_language_processing/useTokenizer.d.ts +0 -17
  54. package/lib/hooks/natural_language_processing/useTokenizer.js +0 -52
  55. package/lib/hooks/useModule.js +0 -45
  56. package/lib/hooks/useNonStaticModule.d.ts +0 -20
  57. package/lib/hooks/useNonStaticModule.js +0 -49
  58. package/lib/index.d.ts +0 -48
  59. package/lib/index.js +0 -58
  60. package/lib/modules/BaseModule.js +0 -25
  61. package/lib/modules/BaseNonStaticModule.js +0 -14
  62. package/lib/modules/computer_vision/ClassificationModule.d.ts +0 -8
  63. package/lib/modules/computer_vision/ClassificationModule.js +0 -17
  64. package/lib/modules/computer_vision/ImageEmbeddingsModule.d.ts +0 -8
  65. package/lib/modules/computer_vision/ImageEmbeddingsModule.js +0 -17
  66. package/lib/modules/computer_vision/ImageSegmentationModule.d.ts +0 -11
  67. package/lib/modules/computer_vision/ImageSegmentationModule.js +0 -27
  68. package/lib/modules/computer_vision/OCRModule.d.ts +0 -14
  69. package/lib/modules/computer_vision/OCRModule.js +0 -17
  70. package/lib/modules/computer_vision/ObjectDetectionModule.d.ts +0 -9
  71. package/lib/modules/computer_vision/ObjectDetectionModule.js +0 -17
  72. package/lib/modules/computer_vision/StyleTransferModule.d.ts +0 -8
  73. package/lib/modules/computer_vision/StyleTransferModule.js +0 -17
  74. package/lib/modules/computer_vision/VerticalOCRModule.d.ts +0 -14
  75. package/lib/modules/computer_vision/VerticalOCRModule.js +0 -19
  76. package/lib/modules/general/ExecutorchModule.d.ts +0 -7
  77. package/lib/modules/general/ExecutorchModule.js +0 -14
  78. package/lib/modules/natural_language_processing/LLMModule.d.ts +0 -28
  79. package/lib/modules/natural_language_processing/LLMModule.js +0 -45
  80. package/lib/modules/natural_language_processing/SpeechToTextModule.d.ts +0 -24
  81. package/lib/modules/natural_language_processing/SpeechToTextModule.js +0 -36
  82. package/lib/modules/natural_language_processing/TextEmbeddingsModule.d.ts +0 -9
  83. package/lib/modules/natural_language_processing/TextEmbeddingsModule.js +0 -21
  84. package/lib/modules/natural_language_processing/TokenizerModule.d.ts +0 -12
  85. package/lib/modules/natural_language_processing/TokenizerModule.js +0 -30
  86. package/lib/native/NativeETInstaller.js +0 -2
  87. package/lib/native/NativeOCR.js +0 -2
  88. package/lib/native/NativeVerticalOCR.js +0 -2
  89. package/lib/native/RnExecutorchModules.d.ts +0 -7
  90. package/lib/native/RnExecutorchModules.js +0 -18
  91. package/lib/tsconfig.tsbuildinfo +0 -1
  92. package/lib/types/common.d.ts +0 -32
  93. package/lib/types/common.js +0 -25
  94. package/lib/types/imageSegmentation.js +0 -26
  95. package/lib/types/llm.d.ts +0 -46
  96. package/lib/types/llm.js +0 -9
  97. package/lib/types/objectDetection.js +0 -94
  98. package/lib/types/ocr.js +0 -1
  99. package/lib/types/stt.d.ts +0 -94
  100. package/lib/types/stt.js +0 -85
  101. package/lib/utils/ResourceFetcher.d.ts +0 -24
  102. package/lib/utils/ResourceFetcher.js +0 -305
  103. package/lib/utils/ResourceFetcherUtils.d.ts +0 -54
  104. package/lib/utils/ResourceFetcherUtils.js +0 -127
  105. package/lib/utils/llm.d.ts +0 -6
  106. package/lib/utils/llm.js +0 -72
  107. package/lib/utils/stt.js +0 -21
@@ -1,127 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- import { getInfoAsync, makeDirectoryAsync, } from 'expo-file-system';
5
- import { RNEDirectory } from '../constants/directories';
6
- import { Asset } from 'expo-asset';
7
- import { Logger } from '../common/Logger';
8
- export var ResourceFetcherUtils;
9
- (function (ResourceFetcherUtils) {
10
- function getType(source) {
11
- if (typeof source === 'object') {
12
- return 0 /* SourceType.OBJECT */;
13
- }
14
- else if (typeof source === 'number') {
15
- const uri = Asset.fromModule(source).uri;
16
- if (!uri.includes('://')) {
17
- return 2 /* SourceType.RELEASE_MODE_FILE */;
18
- }
19
- return 3 /* SourceType.DEV_MODE_FILE */;
20
- }
21
- else {
22
- // typeof source == 'string'
23
- if (source.startsWith('file://')) {
24
- return 1 /* SourceType.LOCAL_FILE */;
25
- }
26
- return 4 /* SourceType.REMOTE_FILE */;
27
- }
28
- }
29
- ResourceFetcherUtils.getType = getType;
30
- async function getFilesSizes(sources) {
31
- const results = [];
32
- let totalLength = 0;
33
- let previousFilesTotalLength = 0;
34
- for (const source of sources) {
35
- const type = await ResourceFetcherUtils.getType(source);
36
- let length = 0;
37
- if (type === 4 /* SourceType.REMOTE_FILE */ && typeof source === 'string') {
38
- try {
39
- const response = await fetch(source, { method: 'HEAD' });
40
- if (!response.ok) {
41
- Logger.warn(`Failed to fetch HEAD for ${source}: ${response.status}`);
42
- continue;
43
- }
44
- const contentLength = response.headers.get('content-length');
45
- if (!contentLength) {
46
- Logger.warn(`No content-length header for ${source}`);
47
- }
48
- length = contentLength ? parseInt(contentLength, 10) : 0;
49
- previousFilesTotalLength = totalLength;
50
- totalLength += length;
51
- }
52
- catch (error) {
53
- Logger.warn(`Error fetching HEAD for ${source}:`, error);
54
- continue;
55
- }
56
- }
57
- results.push({ source, type, length, previousFilesTotalLength });
58
- }
59
- return { results, totalLength };
60
- }
61
- ResourceFetcherUtils.getFilesSizes = getFilesSizes;
62
- function removeFilePrefix(uri) {
63
- return uri.startsWith('file://') ? uri.slice(7) : uri;
64
- }
65
- ResourceFetcherUtils.removeFilePrefix = removeFilePrefix;
66
- function hashObject(jsonString) {
67
- let hash = 0;
68
- for (let i = 0; i < jsonString.length; i++) {
69
- // eslint-disable-next-line no-bitwise
70
- hash = (hash << 5) - hash + jsonString.charCodeAt(i);
71
- // eslint-disable-next-line no-bitwise
72
- hash |= 0;
73
- }
74
- // eslint-disable-next-line no-bitwise
75
- return (hash >>> 0).toString();
76
- }
77
- ResourceFetcherUtils.hashObject = hashObject;
78
- function calculateDownloadProgress(totalLength, previousFilesTotalLength, currentFileLength, setProgress) {
79
- return (progress) => {
80
- if (progress === 1 &&
81
- previousFilesTotalLength === totalLength - currentFileLength) {
82
- setProgress(1);
83
- return;
84
- }
85
- // Avoid division by zero
86
- if (totalLength === 0) {
87
- setProgress(0);
88
- return;
89
- }
90
- const baseProgress = previousFilesTotalLength / totalLength;
91
- const scaledProgress = progress * (currentFileLength / totalLength);
92
- const updatedProgress = baseProgress + scaledProgress;
93
- setProgress(updatedProgress);
94
- };
95
- }
96
- ResourceFetcherUtils.calculateDownloadProgress = calculateDownloadProgress;
97
- /*
98
- * Increments the Hugging Face download counter if the URI points to a Software Mansion Hugging Face repo.
99
- * More information: https://huggingface.co/docs/hub/models-download-stats
100
- */
101
- async function triggerHuggingFaceDownloadCounter(uri) {
102
- const url = new URL(uri);
103
- if (url.host === 'huggingface.co' &&
104
- url.pathname.startsWith('/software-mansion/')) {
105
- const baseUrl = `${url.protocol}//${url.host}${url.pathname.split('resolve')[0]}`;
106
- fetch(`${baseUrl}resolve/main/config.json`, { method: 'HEAD' });
107
- }
108
- }
109
- ResourceFetcherUtils.triggerHuggingFaceDownloadCounter = triggerHuggingFaceDownloadCounter;
110
- async function createDirectoryIfNoExists() {
111
- if (!(await checkFileExists(RNEDirectory))) {
112
- await makeDirectoryAsync(RNEDirectory, { intermediates: true });
113
- }
114
- }
115
- ResourceFetcherUtils.createDirectoryIfNoExists = createDirectoryIfNoExists;
116
- async function checkFileExists(fileUri) {
117
- const fileInfo = await getInfoAsync(fileUri);
118
- return fileInfo.exists;
119
- }
120
- ResourceFetcherUtils.checkFileExists = checkFileExists;
121
- function getFilenameFromUri(uri) {
122
- let cleanUri = uri.replace(/^https?:\/\//, '');
123
- cleanUri = cleanUri.split('#')?.[0] ?? cleanUri;
124
- return cleanUri.replace(/[^a-zA-Z0-9._-]/g, '_');
125
- }
126
- ResourceFetcherUtils.getFilenameFromUri = getFilenameFromUri;
127
- })(ResourceFetcherUtils || (ResourceFetcherUtils = {}));
@@ -1,6 +0,0 @@
1
- import { ToolCall } from '../types/llm';
2
- import { Schema } from 'jsonschema';
3
- import * as zCore from 'zod/v4/core';
4
- export declare const parseToolCall: (message: string) => ToolCall[];
5
- export declare const getStructuredOutputPrompt: <T extends zCore.$ZodType>(responseSchema: T | Schema) => string;
6
- export declare const fixAndValidateStructuredOutput: <T extends zCore.$ZodType>(output: string, responseSchema: T | Schema) => zCore.output<T>;
package/lib/utils/llm.js DELETED
@@ -1,72 +0,0 @@
1
- import * as z from 'zod/v4';
2
- import { Validator } from 'jsonschema';
3
- import { jsonrepair } from 'jsonrepair';
4
- import { DEFAULT_STRUCTURED_OUTPUT_PROMPT } from '../constants/llmDefaults';
5
- import * as zCore from 'zod/v4/core';
6
- import { Logger } from '../common/Logger';
7
- export const parseToolCall = (message) => {
8
- try {
9
- const unparsedToolCalls = message.match('\\[(.|\\s)*\\]');
10
- if (!unparsedToolCalls) {
11
- throw Error('Regex did not match array.');
12
- }
13
- const parsedMessage = JSON.parse(unparsedToolCalls[0]);
14
- const results = [];
15
- for (const tool of parsedMessage) {
16
- if ('name' in tool &&
17
- typeof tool.name === 'string' &&
18
- 'arguments' in tool &&
19
- tool.arguments !== null &&
20
- typeof tool.arguments === 'object') {
21
- results.push({
22
- toolName: tool.name,
23
- arguments: tool.arguments,
24
- });
25
- }
26
- }
27
- return results;
28
- }
29
- catch (e) {
30
- Logger.error(e);
31
- return [];
32
- }
33
- };
34
- const filterObjectKeys = (obj, keysToRemove) => {
35
- const entries = Object.entries(obj);
36
- const filteredEntries = entries.filter(([key, _]) => !keysToRemove.includes(key));
37
- return Object.fromEntries(filteredEntries);
38
- };
39
- export const getStructuredOutputPrompt = (responseSchema) => {
40
- const schemaObject = responseSchema instanceof zCore.$ZodType
41
- ? filterObjectKeys(z.toJSONSchema(responseSchema), [
42
- '$schema',
43
- 'additionalProperties',
44
- ])
45
- : responseSchema;
46
- const schemaString = JSON.stringify(schemaObject);
47
- return DEFAULT_STRUCTURED_OUTPUT_PROMPT(schemaString);
48
- };
49
- const extractBetweenBrackets = (text) => {
50
- const startIndex = text.search(/[\\{\\[]/); // First occurrence of either { or [
51
- const openingBracket = text[startIndex];
52
- const closingBracket = openingBracket === '{' ? '}' : ']';
53
- if (!openingBracket)
54
- throw Error("Couldn't find JSON in text");
55
- return text.slice(text.indexOf(openingBracket), text.lastIndexOf(closingBracket) + 1);
56
- };
57
- // this is a bit hacky typing
58
- export const fixAndValidateStructuredOutput = (output, responseSchema) => {
59
- const extractedOutput = extractBetweenBrackets(output);
60
- const repairedOutput = jsonrepair(extractedOutput);
61
- const outputJSON = JSON.parse(repairedOutput);
62
- if (responseSchema instanceof zCore.$ZodType) {
63
- return z.parse(responseSchema, outputJSON);
64
- }
65
- else {
66
- const validator = new Validator();
67
- validator.validate(outputJSON, responseSchema, {
68
- throwAll: true,
69
- });
70
- return outputJSON;
71
- }
72
- };
package/lib/utils/stt.js DELETED
@@ -1,21 +0,0 @@
1
- export const longCommonInfPref = (seq1, seq2, hammingDistThreshold) => {
2
- let maxInd = 0;
3
- let maxLength = 0;
4
- for (let i = 0; i < seq1.length; i++) {
5
- let j = 0;
6
- let hammingDist = 0;
7
- while (j < seq2.length &&
8
- i + j < seq1.length &&
9
- (seq1[i + j] === seq2[j] || hammingDist < hammingDistThreshold)) {
10
- if (seq1[i + j] !== seq2[j]) {
11
- hammingDist++;
12
- }
13
- j++;
14
- }
15
- if (j >= maxLength) {
16
- maxLength = j;
17
- maxInd = i;
18
- }
19
- }
20
- return maxInd;
21
- };