@bendyline/gezel-capacitor 0.0.0-stage → 0.1.0

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 (121) hide show
  1. package/LICENSE +21 -0
  2. package/Package.swift +26 -0
  3. package/README.md +230 -2
  4. package/android/build.gradle +30 -0
  5. package/android/src/main/AndroidManifest.xml +1 -0
  6. package/android/src/main/java/com/bendyline/gezel/capacitor/GezelKnowledgePlugin.java +153 -0
  7. package/android/src/main/java/com/bendyline/gezel/capacitor/GezelOfflineSpeechPlugin.java +216 -0
  8. package/android/src/main/java/com/bendyline/gezel/capacitor/GezelRuntimePlugin.java +84 -0
  9. package/android/src/main/java/com/bendyline/gezel/capacitor/KnowledgeFiles.java +101 -0
  10. package/android/src/main/java/com/bendyline/gezel/capacitor/SpeechModels.java +230 -0
  11. package/android/src/main/java/com/bendyline/gezel/speech/SpeechRuntime.java +38 -0
  12. package/dist/index.d.ts +561 -0
  13. package/dist/index.js +7512 -0
  14. package/dist/knowledge-worker.js +211 -0
  15. package/dist/licenses/npm/manifest.json +76 -0
  16. package/dist/licenses/npm/texts/1583809bf1155510d2961f94aa9bca6dc4b44b6f59fd773de33bd6c20860d781.txt +29 -0
  17. package/dist/licenses/npm/texts/1cd39aa4a566eba49eb206b969ef423295e79b50503df567bbdb2e8877d78892.txt +8 -0
  18. package/dist/licenses/npm/texts/3f1189b28e3866e0d979968d466b78f813f76827cfdca1fbb124cc0a5c8841f8.txt +21 -0
  19. package/dist/licenses/npm/texts/5b37224c080cdcc97c871ada971c224e9926370fe74f11b539aa1cf9f3b1aca1.txt +21 -0
  20. package/dist/licenses/npm/texts/c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4.txt +201 -0
  21. package/dist/sqlite3.wasm +0 -0
  22. package/embedding-manifest.json +210 -0
  23. package/ios/Sources/GezelCapacitor/GezelKnowledgePlugin.swift +200 -0
  24. package/ios/Sources/GezelCapacitor/GezelOfflineSpeechPlugin.swift +484 -0
  25. package/ios/Sources/GezelCapacitor/GezelRuntimePlugin.swift +102 -0
  26. package/kokoro-lexicon/LICENSE +202 -0
  27. package/kokoro-lexicon/lexicon-gb-en.txt.gz +0 -0
  28. package/kokoro-lexicon/lexicon-us-en.txt.gz +0 -0
  29. package/native/android/LICENSE-gezel.txt +21 -0
  30. package/native/android/PUBLIC-DISTRIBUTION.md +97 -0
  31. package/native/android/THIRD_PARTY_LICENSES/LICENSE-arm-optimized-routines-MIT-OR-Apache-2.0.txt +249 -0
  32. package/native/android/THIRD_PARTY_LICENSES/LICENSE-cpp-httplib-MIT.txt +22 -0
  33. package/native/android/THIRD_PARTY_LICENSES/LICENSE-fp16-MIT.txt +11 -0
  34. package/native/android/THIRD_PARTY_LICENSES/LICENSE-ggml-MIT.txt +21 -0
  35. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-llamafile-sgemm-MIT.txt +21 -0
  36. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-openvino-APACHE.txt +201 -0
  37. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-pillow-MIT-CMU.txt +30 -0
  38. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-rotate-bits-MIT.txt +21 -0
  39. package/native/android/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-unicode-data-Unicode-3.0.txt +39 -0
  40. package/native/android/THIRD_PARTY_LICENSES/LICENSE-nlohmann-json-MIT.txt +21 -0
  41. package/native/android/THIRD_PARTY_LICENSES/LICENSE-nvidia-cub-BSD-3-Clause.txt +24 -0
  42. package/native/android/THIRD_PARTY_LICENSES/LICENSE-vulkan-headers-Apache-2.0-OR-MIT.txt +33 -0
  43. package/native/android/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-APACHE.txt +201 -0
  44. package/native/android/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-cjson-MIT.txt +32 -0
  45. package/native/android/THIRD_PARTY_LICENSES/LICENSE-yarn-MIT.txt +21 -0
  46. package/native/android/THIRD_PARTY_LICENSES/manifest.json +21 -0
  47. package/native/android/engine-manifest.json +88 -0
  48. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.aar +0 -0
  49. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.aar.sha256 +1 -0
  50. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.pom +8 -0
  51. package/native/android/maven/com/bendyline/gezel/gezel-llama/0.1.57/gezel-llama-0.1.57.pom.sha256 +1 -0
  52. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar +0 -0
  53. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.md5 +1 -0
  54. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.sha1 +1 -0
  55. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.sha256 +1 -0
  56. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57-sources.jar.sha512 +1 -0
  57. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar +0 -0
  58. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.md5 +1 -0
  59. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.sha1 +1 -0
  60. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.sha256 +1 -0
  61. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.aar.sha512 +1 -0
  62. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module +118 -0
  63. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.md5 +1 -0
  64. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.sha1 +1 -0
  65. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.sha256 +1 -0
  66. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.module.sha512 +1 -0
  67. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom +51 -0
  68. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.md5 +1 -0
  69. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.sha1 +1 -0
  70. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.sha256 +1 -0
  71. package/native/android/maven/com/bendyline/gezel/gezel-runtime/0.1.57/gezel-runtime-0.1.57.pom.sha512 +1 -0
  72. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml +13 -0
  73. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.md5 +1 -0
  74. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.sha1 +1 -0
  75. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.sha256 +1 -0
  76. package/native/android/maven/com/bendyline/gezel/gezel-runtime/maven-metadata.xml.sha512 +1 -0
  77. package/native/android/sdk-manifest.json +98 -0
  78. package/native/ios/GezelLlama.xcframework/Info.plist +47 -0
  79. package/native/ios/GezelLlama.xcframework/ios-arm64/Headers/gezel_llama.h +290 -0
  80. package/native/ios/GezelLlama.xcframework/ios-arm64/Headers/module.modulemap +9 -0
  81. package/native/ios/GezelLlama.xcframework/ios-arm64/libGezelLlama.a +0 -0
  82. package/native/ios/GezelLlama.xcframework/ios-arm64-simulator/Headers/gezel_llama.h +290 -0
  83. package/native/ios/GezelLlama.xcframework/ios-arm64-simulator/Headers/module.modulemap +9 -0
  84. package/native/ios/GezelLlama.xcframework/ios-arm64-simulator/libGezelLlama.a +0 -0
  85. package/native/ios/LICENSE-gezel.txt +21 -0
  86. package/native/ios/LICENSE-ggml.txt +21 -0
  87. package/native/ios/LICENSE-llama-cpp.txt +21 -0
  88. package/native/ios/PUBLIC-DISTRIBUTION.md +97 -0
  89. package/native/ios/Package.swift +17 -0
  90. package/native/ios/Sources/GezelModelStorage/MobileModelStore.swift +286 -0
  91. package/native/ios/Sources/GezelModelStorage/ModelDownloadHTTP.swift +55 -0
  92. package/native/ios/Sources/GezelModelStorage/ModelDownloadSource.swift +46 -0
  93. package/native/ios/Sources/GezelModelStorage/ModelDownloads.swift +289 -0
  94. package/native/ios/Sources/GezelModelStorage/PrivacyInfo.xcprivacy +32 -0
  95. package/native/ios/Sources/GezelRuntime/AppleFoundationProvider.swift +292 -0
  96. package/native/ios/Sources/GezelRuntime/AppleNativeTools.swift +152 -0
  97. package/native/ios/Sources/GezelRuntime/GezelNativeRuntime.swift +1349 -0
  98. package/native/ios/Sources/GezelRuntime/NativeCall.swift +35 -0
  99. package/native/ios/Sources/GezelRuntime/PrivacyInfo.xcprivacy +31 -0
  100. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-arm-optimized-routines-MIT-OR-Apache-2.0.txt +249 -0
  101. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-cpp-httplib-MIT.txt +22 -0
  102. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-fp16-MIT.txt +11 -0
  103. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-ggml-MIT.txt +21 -0
  104. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-llamafile-sgemm-MIT.txt +21 -0
  105. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-openvino-APACHE.txt +201 -0
  106. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-pillow-MIT-CMU.txt +30 -0
  107. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-rotate-bits-MIT.txt +21 -0
  108. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-llama-cpp-unicode-data-Unicode-3.0.txt +39 -0
  109. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-nlohmann-json-MIT.txt +21 -0
  110. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-nvidia-cub-BSD-3-Clause.txt +24 -0
  111. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-vulkan-headers-Apache-2.0-OR-MIT.txt +33 -0
  112. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-APACHE.txt +201 -0
  113. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-vulkan-loader-cjson-MIT.txt +32 -0
  114. package/native/ios/THIRD_PARTY_LICENSES/LICENSE-yarn-MIT.txt +21 -0
  115. package/native/ios/THIRD_PARTY_LICENSES/manifest.json +21 -0
  116. package/native/ios/engine-manifest.json +102 -0
  117. package/native/ios/sdk-manifest.json +89 -0
  118. package/package.json +94 -3
  119. package/scripts/embedding-package.d.mts +23 -0
  120. package/scripts/embedding-package.mjs +185 -0
  121. package/scripts/stage-native.mjs +168 -0
@@ -0,0 +1,38 @@
1
+ package com.bendyline.gezel.speech;
2
+
3
+ /**
4
+ * Binding for libGezelSpeech (native/mobile/speech). The library ships in the
5
+ * optional gezel-speech AAR; without it {@link #available()} is false and no
6
+ * other method may be called.
7
+ */
8
+ public final class SpeechRuntime {
9
+ /** Matches GEZEL_SPEECH_ABI in gezel_speech.h. */
10
+ public static final int ABI = 3;
11
+ private static final String UNAVAILABLE;
12
+ static {
13
+ String reason = null;
14
+ try {
15
+ System.loadLibrary("GezelSpeech");
16
+ if (abi() != ABI) reason = "This app's speech engine does not match its plugin.";
17
+ } catch (UnsatisfiedLinkError missing) {
18
+ reason = "This app was built without the offline speech engine.";
19
+ }
20
+ UNAVAILABLE = reason;
21
+ }
22
+ private SpeechRuntime() {}
23
+ /** Null when the engine can run, else why not. */
24
+ public static String unavailableReason() { return UNAVAILABLE; }
25
+ public static boolean available() { return UNAVAILABLE == null; }
26
+ static native int abi();
27
+ public static native long create();
28
+ public static native void begin(long engine);
29
+ public static native void cancel(long engine);
30
+ public static native void release(long engine);
31
+ public static native void destroy(long engine);
32
+ /** Timed transcript as UTF-8 JSON; see gezel_speech_transcribe_json. */
33
+ public static native byte[] transcribe(long engine, String model, byte[] pcm16, String language, String prompt, boolean words);
34
+ /** {24 kHz samples, per-token durations (empty when the model has none)}. */
35
+ public static native float[][] kokoro(long engine, String model, String voices, int voice, int[] tokens, float speed);
36
+ /** A knowledge query's unit vector: mean-pooled, normalized hidden states. */
37
+ public static native float[] embed(long engine, String model, long[] ids);
38
+ }
@@ -0,0 +1,561 @@
1
+ import * as _bendyline_gezel_app_sdk_browser from '@bendyline/gezel-app-sdk/browser';
2
+ import { GezelApp, EmbeddingConnection, EmbeddingOptions, KnowledgeState, KnowledgeClient, KnowledgeRetrieveInput } from '@bendyline/gezel-app-sdk/browser';
3
+ export { selectModel } from '@bendyline/gezel-app-sdk/browser';
4
+ import { NativeInferencePlugin } from '@bendyline/gezel/mobile-inference';
5
+ import { MobileProviderId, MobileModel, MobileModelSourceIdentity, MobileModelSource, MobileModelDownload, MobileCatalogEntry } from '@bendyline/gezel/mobile-providers';
6
+ import { KokoroPlannedUtterance } from '@bendyline/gezel/kokoro';
7
+ import { PluginListenerHandle } from '@capacitor/core';
8
+
9
+ /** App-owned native runtime. Model IDs are opaque; JavaScript never supplies paths. */
10
+ interface GezelRuntimePlugin extends NativeInferencePlugin {
11
+ prepareProvider(options: {
12
+ providerId: MobileProviderId;
13
+ }): Promise<void>;
14
+ cancelProviderPreparation(options: {
15
+ providerId: MobileProviderId;
16
+ }): Promise<void>;
17
+ releaseModel(): Promise<void>;
18
+ importModel(): Promise<{
19
+ model: MobileModel | null;
20
+ }>;
21
+ selectModel(options: {
22
+ id: string;
23
+ }): Promise<{
24
+ model: MobileModel;
25
+ }>;
26
+ removeModel(options: {
27
+ id: string;
28
+ }): Promise<void>;
29
+ resolveModelSource(options: {
30
+ source: MobileModelSourceIdentity;
31
+ }): Promise<{
32
+ source: MobileModelSource;
33
+ }>;
34
+ cancelModelSourceResolution(): Promise<void>;
35
+ listModelDownloads(): Promise<{
36
+ downloads: MobileModelDownload[];
37
+ }>;
38
+ startModelDownload(options: {
39
+ source: MobileModelSource;
40
+ name: string;
41
+ }): Promise<{
42
+ download: MobileModelDownload;
43
+ }>;
44
+ resumeModelDownload(options: {
45
+ id: string;
46
+ }): Promise<{
47
+ download: MobileModelDownload;
48
+ }>;
49
+ cancelModelDownload(options: {
50
+ id: string;
51
+ }): Promise<void>;
52
+ removeModelDownload(options: {
53
+ id: string;
54
+ }): Promise<void>;
55
+ /**
56
+ * Describe one photo with an installed llama.cpp vision model and the
57
+ * projector downloaded beside it as its own library entry. Builds that
58
+ * predate the vision bridge do not have it.
59
+ */
60
+ describeImage?(options: {
61
+ requestId: string;
62
+ modelId: string;
63
+ projectorId: string;
64
+ /** Base64 image bytes; the native side decodes, orients, and sizes them. */
65
+ image: string;
66
+ system?: string;
67
+ user: string;
68
+ maxTokens?: number;
69
+ }): Promise<{
70
+ status: 'ok' | 'cancelled';
71
+ description?: string;
72
+ }>;
73
+ }
74
+
75
+ /** In-process Fetch transport. No HTTP listener, network fallback, or product service. */
76
+ declare function connectRuntime(plugin: GezelRuntimePlugin): GezelApp<'portable'>;
77
+
78
+ declare const mobileCatalog: readonly MobileCatalogEntry[];
79
+ declare const mobileCatalogVersion: string;
80
+ interface MobileModelManagerOptions {
81
+ catalog?: readonly MobileCatalogEntry[];
82
+ pollIntervalMs?: number;
83
+ preparationTimeoutMs?: number;
84
+ }
85
+ /** Model ownership, identity checks, preparation and cancellation formerly repeated by hosts. */
86
+ declare function createMobileModelManager(runtime: GezelRuntimePlugin, options?: MobileModelManagerOptions): _bendyline_gezel_app_sdk_browser.ModelManager;
87
+
88
+ declare function connectEmbeddingRuntime(runtime: GezelRuntimePlugin, options?: MobileModelManagerOptions): EmbeddingConnection;
89
+ declare function createRuntimeEmbedding(runtime: GezelRuntimePlugin, options?: MobileModelManagerOptions & Pick<EmbeddingOptions, 'onState'>): {
90
+ readonly state: _bendyline_gezel_app_sdk_browser.EmbeddingState;
91
+ setEnabled(value: boolean): Promise<void>;
92
+ reconnect(): Promise<void>;
93
+ suspend(): Promise<void>;
94
+ resume(): void;
95
+ close(): Promise<void>;
96
+ models: {
97
+ list: (opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<_bendyline_gezel_app_sdk_browser.ModelDescriptor[]>;
98
+ inspect: (id: string, opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<_bendyline_gezel_app_sdk_browser.ModelDescriptor | null>;
99
+ prepare: (id: string, opts?: _bendyline_gezel_app_sdk_browser.PrepareModelOptions) => Promise<_bendyline_gezel_app_sdk_browser.ModelDescriptor>;
100
+ };
101
+ knowledge: {
102
+ state: (opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<_bendyline_gezel_app_sdk_browser.KnowledgeState>;
103
+ update: (action: Parameters<_bendyline_gezel_app_sdk_browser.KnowledgeClient["update"]>[0], opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<void>;
104
+ retrieve: (query: Parameters<_bendyline_gezel_app_sdk_browser.KnowledgeClient["retrieve"]>[0], opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<{
105
+ reranked: boolean;
106
+ passages: {
107
+ uri: string;
108
+ title: string;
109
+ text: string;
110
+ catalogId: string;
111
+ version: string;
112
+ }[];
113
+ }>;
114
+ };
115
+ streamText(request: _bendyline_gezel_app_sdk_browser.TextRequest, opts?: _bendyline_gezel_app_sdk_browser.TextOptions): Promise<{
116
+ type: "done";
117
+ text: string;
118
+ cancelled: boolean;
119
+ finishReason: string | null;
120
+ model: string;
121
+ usage: _bendyline_gezel_app_sdk_browser.ChatCompletionResponse["usage"] | null;
122
+ appliedMaxTokens: number | null;
123
+ }>;
124
+ };
125
+
126
+ /**
127
+ * Speech models a phone can download. The Whisper files and Kokoro voices are
128
+ * the pinned files of `@bendyline/gezel/speech-models` (desktop), repeated
129
+ * here because that entry reads the file system; speech-catalog.test.ts holds
130
+ * the two in step. Kokoro differs only in weights: desktop's fp32 export is
131
+ * 326 MB, so phones take the int8 export of the same timestamped model, which
132
+ * keeps word timings and every voice.
133
+ */
134
+ interface MobileSpeechFile {
135
+ /** Path inside the model folder, `/`-separated. */
136
+ readonly name: string;
137
+ readonly url: string;
138
+ readonly sha256: string;
139
+ readonly size: number;
140
+ }
141
+ interface MobileSpeechVoice {
142
+ readonly id: string;
143
+ readonly label: string;
144
+ /** BCP 47 tag. */
145
+ readonly language: string;
146
+ readonly gender: 'female' | 'male';
147
+ }
148
+ interface MobileSpeechModel {
149
+ readonly id: string;
150
+ readonly kind: 'stt' | 'tts';
151
+ readonly label: string;
152
+ readonly description: string;
153
+ readonly recommended: boolean;
154
+ readonly license: string;
155
+ readonly licenseUrl: string;
156
+ /** The file the engine loads: Whisper weights, or Kokoro's ONNX graph. */
157
+ readonly model: string;
158
+ readonly files: readonly MobileSpeechFile[];
159
+ /** Kokoro only; each voice is `voices/<id>.bin`. */
160
+ readonly voices?: readonly MobileSpeechVoice[];
161
+ }
162
+ declare const KOKORO_MOBILE_MODEL_FILE = "onnx/model_quantized.onnx";
163
+ declare const KOKORO_SAMPLE_RATE = 24000;
164
+ declare const MOBILE_SPEECH_MODELS: readonly MobileSpeechModel[];
165
+ declare const KOKORO_DEFAULT_VOICE = "af_heart";
166
+ declare function mobileSpeechModel(id: string): MobileSpeechModel | undefined;
167
+ declare function speechDownloadBytes(model: MobileSpeechModel): number;
168
+
169
+ /**
170
+ * Offline speech on this device: Whisper dictation and Kokoro narration.
171
+ *
172
+ * The native GezelOfflineSpeech plugin runs the engines and stores verified model
173
+ * files; this module chooses files from the catalog, normalizes audio, and
174
+ * plans Kokoro's phonemes in JavaScript with the same dictionaries the desktop
175
+ * daemon uses (no eSpeak NG). Nothing downloads or loads a model until a
176
+ * caller asks.
177
+ */
178
+ type MobileSpeechErrorCode = 'unavailable' | 'model-missing' | 'busy' | 'cancelled' | 'paused' | 'interrupted' | 'verification' | 'invalid-input' | 'resources' | 'storage' | 'failed';
179
+ declare class MobileSpeechError extends Error {
180
+ readonly code: MobileSpeechErrorCode;
181
+ constructor(message: string, code: MobileSpeechErrorCode);
182
+ }
183
+ interface NativeToken {
184
+ start: number;
185
+ end: number;
186
+ text: string;
187
+ }
188
+ interface NativeSegment {
189
+ start: number;
190
+ end: number;
191
+ text: string;
192
+ tokens?: NativeToken[];
193
+ }
194
+ /** App-owned native speech. Model ids and file names are validated natively; JavaScript never supplies paths. */
195
+ interface GezelOfflineSpeechPlugin {
196
+ status(): Promise<{
197
+ available: boolean;
198
+ reason?: string;
199
+ models: {
200
+ id: string;
201
+ files: string[];
202
+ }[];
203
+ downloading?: string;
204
+ }>;
205
+ install(options: {
206
+ id: string;
207
+ files: readonly MobileSpeechFile[];
208
+ }): Promise<{
209
+ id: string;
210
+ }>;
211
+ cancelInstall(): Promise<void>;
212
+ remove(options: {
213
+ id: string;
214
+ }): Promise<void>;
215
+ transcribe(options: {
216
+ requestId: string;
217
+ model: string;
218
+ file: string;
219
+ /** Base64 mono 16 kHz PCM16. */
220
+ audio: string;
221
+ language?: string;
222
+ prompt?: string;
223
+ words?: boolean;
224
+ }): Promise<{
225
+ language: string | null;
226
+ segments: NativeSegment[];
227
+ durationMs: number;
228
+ }>;
229
+ synthesize(options: {
230
+ requestId: string;
231
+ model: string;
232
+ file: string;
233
+ voices: string;
234
+ voice: number;
235
+ tokens: readonly number[];
236
+ speed: number;
237
+ }): Promise<{
238
+ pcm: string;
239
+ sampleRate: number;
240
+ durations: number[];
241
+ durationMs: number;
242
+ }>;
243
+ cancel(options: {
244
+ requestId: string;
245
+ }): Promise<void>;
246
+ /** Free loaded models now instead of after the idle timeout. */
247
+ release(): Promise<void>;
248
+ addListener(event: 'speechDownload', listener: (event: {
249
+ id: string;
250
+ receivedBytes: number;
251
+ totalBytes: number;
252
+ }) => void): Promise<PluginListenerHandle>;
253
+ }
254
+ declare const GezelOfflineSpeech: GezelOfflineSpeechPlugin;
255
+ interface MobileSpeechStatus {
256
+ /** The engine is in this build and can load. */
257
+ readonly available: boolean;
258
+ readonly reason?: string;
259
+ /** Models whose every catalog file is installed and verified. */
260
+ readonly installed: ReadonlySet<string>;
261
+ readonly downloading?: string;
262
+ }
263
+ interface MobileSpeechDownloadProgress {
264
+ readonly phase: 'downloading' | 'retrying';
265
+ readonly receivedBytes: number;
266
+ readonly totalBytes: number;
267
+ /** While retrying: seconds until the next attempt. */
268
+ readonly retryInSeconds?: number;
269
+ }
270
+ interface MobileSpeechWord {
271
+ /** Seconds from the start of the take. */
272
+ readonly start: number;
273
+ readonly end: number;
274
+ readonly text: string;
275
+ }
276
+ interface MobileSpeechSegment {
277
+ readonly start: number;
278
+ readonly end: number;
279
+ readonly text: string;
280
+ readonly words?: readonly MobileSpeechWord[];
281
+ }
282
+ interface MobileSpeechTranscript {
283
+ /** Trimmed; empty when the take held no speech. */
284
+ readonly text: string;
285
+ readonly language: string | null;
286
+ readonly segments: readonly MobileSpeechSegment[];
287
+ readonly durationMs: number;
288
+ }
289
+ interface MobileSpeechWordTiming {
290
+ readonly textStart: number;
291
+ readonly textEnd: number;
292
+ readonly startSec: number;
293
+ readonly endSec: number;
294
+ }
295
+ /** One independently playable piece of a synthesis, usually a sentence. */
296
+ interface MobileSpeechChunk {
297
+ readonly index: number;
298
+ readonly pcm: Float32Array;
299
+ readonly sampleRate: number;
300
+ readonly durationSec: number;
301
+ /** UTF-16 range of the request text this chunk speaks. */
302
+ readonly textStart: number;
303
+ readonly textEnd: number;
304
+ readonly wordTimings?: readonly MobileSpeechWordTiming[];
305
+ }
306
+ interface MobileSpeechSynthesis {
307
+ readonly voice: string;
308
+ readonly model: string;
309
+ readonly sampleRate: number;
310
+ readonly durationSec: number;
311
+ readonly chunks: number;
312
+ }
313
+ interface MobileSpeechOptions {
314
+ /** Kokoro's pronunciation dictionary as text, for American (`us`) or British (`gb`) voices. */
315
+ lexicon(language: 'us' | 'gb'): Promise<string>;
316
+ plugin?: GezelOfflineSpeechPlugin;
317
+ /** Waits before each retry of an interrupted download that saved no new bytes. */
318
+ downloadRetryDelaysMs?: readonly number[];
319
+ }
320
+ /** Plugin rejections carry a string `code`; anything else is a plain failure. */
321
+ declare function mobileSpeechError(error: unknown): MobileSpeechError;
322
+ /**
323
+ * Mono 16 kHz PCM16 from an uncompressed PCM WAV take, as Whisper wants it.
324
+ * The same normalization as `speechPcm16` in `@bendyline/gezel/runtime`,
325
+ * which this module does not import because that entry is large.
326
+ */
327
+ declare function wavToPcm16(wav: Uint8Array): Uint8Array;
328
+ /**
329
+ * Words from Whisper's timed sub-word tokens: a token that starts with a
330
+ * space begins a word; any other (`'re`, punctuation) continues the last one.
331
+ */
332
+ declare function whisperWords(tokens: readonly NativeToken[]): MobileSpeechWord[];
333
+ /** Sentences with their offsets: Gezel's split on `[.!?…]` followed by whitespace. */
334
+ declare function splitSentences(text: string): {
335
+ text: string;
336
+ start: number;
337
+ end: number;
338
+ }[];
339
+ /** Word times from per-token durations; inconsistent metadata yields none rather than wrong times. */
340
+ declare function kokoroWordTimings(utterance: Pick<KokoroPlannedUtterance, 'tokens' | 'words'>, predictions: readonly number[], sampleCount: number): MobileSpeechWordTiming[] | undefined;
341
+ declare function createMobileSpeech(options: MobileSpeechOptions): {
342
+ models: readonly MobileSpeechModel[];
343
+ status(): Promise<MobileSpeechStatus>;
344
+ /**
345
+ * Download and verify a model. An interrupted transfer resumes where it
346
+ * stopped; only attempts that save nothing new spend the retry budget.
347
+ */
348
+ install(id: string, { signal, onProgress, }?: {
349
+ signal?: AbortSignal;
350
+ onProgress?: (progress: MobileSpeechDownloadProgress) => void;
351
+ }): Promise<void>;
352
+ remove(id: string): Promise<void>;
353
+ transcribe(input: {
354
+ wav: Uint8Array;
355
+ model: string;
356
+ language?: string;
357
+ prompt?: string;
358
+ /** Add word times to each segment. */
359
+ words?: boolean;
360
+ signal?: AbortSignal;
361
+ }): Promise<MobileSpeechTranscript>;
362
+ /** Speak `text` sentence by sentence, handing each chunk over as soon as it is ready. */
363
+ synthesize(input: {
364
+ text: string;
365
+ voice?: string;
366
+ speed?: number;
367
+ model?: string;
368
+ signal?: AbortSignal;
369
+ onChunk?: (chunk: MobileSpeechChunk) => void;
370
+ onProgress?: (completedCharacters: number, totalCharacters: number) => void;
371
+ }): Promise<MobileSpeechSynthesis>;
372
+ /** Free loaded models now; the plugin also frees them after two idle minutes. */
373
+ release(): Promise<void>;
374
+ };
375
+ type MobileSpeech = ReturnType<typeof createMobileSpeech>;
376
+
377
+ /** One installable catalog version, pinned the way the daemon's installer trusts it. */
378
+ interface MobileKnowledgeCatalog {
379
+ readonly id: string;
380
+ readonly publisherId: string;
381
+ readonly name: string;
382
+ readonly description: string;
383
+ readonly language: string;
384
+ readonly license: string;
385
+ readonly licenseUrl?: string;
386
+ readonly category?: string;
387
+ readonly version: string;
388
+ readonly huggingface: {
389
+ readonly repo: string;
390
+ readonly revision: string;
391
+ readonly path: string;
392
+ };
393
+ readonly sha256: string;
394
+ readonly archiveBytes: number;
395
+ readonly documents: number;
396
+ readonly chunks: number;
397
+ readonly embeddingProfile: {
398
+ readonly id: string;
399
+ readonly modelRepo: string;
400
+ };
401
+ }
402
+ /** A profile's query model: the files its catalogs' searches embed questions with. */
403
+ interface MobileQueryModel {
404
+ readonly id: string;
405
+ readonly queryInstruction: string;
406
+ readonly pooling: string;
407
+ readonly normalized: boolean;
408
+ readonly dimensions: number;
409
+ readonly maxTokens: number;
410
+ /** The ONNX graph and tokenizer among `files`. */
411
+ readonly model: string;
412
+ readonly tokenizer: string;
413
+ readonly files: readonly {
414
+ name: string;
415
+ url: string;
416
+ sha256: string;
417
+ size: number;
418
+ }[];
419
+ }
420
+ /** The Gilde knowledge catalogs this SDK release can install (scripts/refresh-knowledge-catalog.ts). */
421
+ declare const mobileKnowledgeCatalogs: readonly MobileKnowledgeCatalog[];
422
+ declare const mobileKnowledgeCatalogVersion: string;
423
+ declare const mobileQueryModels: readonly MobileQueryModel[];
424
+ /** Where a profile's query model lives in the store (`multilingual-e5-small@2` → `query-multilingual-e5-small-2`). */
425
+ declare function queryModelStoreId(profileId: string): string;
426
+ /** The immutable Hugging Face download for a pinned version (inference catalog-source.ts). */
427
+ declare function knowledgeCatalogUrl(catalog: MobileKnowledgeCatalog): string;
428
+
429
+ /** App-owned knowledge archive store. JavaScript names catalogs; native code owns paths. */
430
+ interface GezelKnowledgePlugin {
431
+ info(): Promise<{
432
+ /** Where the worker reads archives in byte ranges; the root of the store. */
433
+ baseUrl: string;
434
+ /** Installed archives: each file is `<version>/catalog.gezk`. */
435
+ catalogs: {
436
+ id: string;
437
+ files: string[];
438
+ }[];
439
+ downloading?: string;
440
+ }>;
441
+ install(options: {
442
+ id: string;
443
+ version: string;
444
+ url: string;
445
+ sha256: string;
446
+ size: number;
447
+ }): Promise<{
448
+ id: string;
449
+ }>;
450
+ /** A profile's query model, into the same store under `queryModelStoreId`. */
451
+ installModel(options: {
452
+ id: string;
453
+ files: readonly {
454
+ name: string;
455
+ url: string;
456
+ sha256: string;
457
+ size: number;
458
+ }[];
459
+ }): Promise<{
460
+ id: string;
461
+ }>;
462
+ /** A query's unit vector from an installed query model. */
463
+ embed(options: {
464
+ model: string;
465
+ file: string;
466
+ ids: readonly number[];
467
+ }): Promise<{
468
+ vector: number[];
469
+ }>;
470
+ cancelInstall(): Promise<void>;
471
+ remove(options: {
472
+ id: string;
473
+ }): Promise<void>;
474
+ addListener(event: 'knowledgeDownload', listener: (event: {
475
+ id: string;
476
+ receivedBytes: number;
477
+ totalBytes: number;
478
+ }) => void): Promise<PluginListenerHandle>;
479
+ }
480
+
481
+ interface KnowledgeWorkerUrls {
482
+ /** `knowledge-worker.js` from this package, served by the app. */
483
+ workerUrl: string | URL;
484
+ /** `sqlite3.wasm` from this package, served by the app. */
485
+ wasmUrl: string | URL;
486
+ }
487
+
488
+ declare const GezelKnowledge: GezelKnowledgePlugin;
489
+ type Action = Parameters<KnowledgeClient['update']>[0];
490
+ type Retrieval = Awaited<ReturnType<KnowledgeClient['retrieve']>>;
491
+ interface MobileKnowledgeOptions extends KnowledgeWorkerUrls {
492
+ plugin?: GezelKnowledgePlugin;
493
+ /** Catalogs the person turned off; an installed catalog is on unless listed. */
494
+ readDisabled(): readonly string[];
495
+ writeDisabled(ids: readonly string[]): void;
496
+ /** Waits before each retry of an interrupted download that saved no new bytes. */
497
+ downloadRetryDelaysMs?: readonly number[];
498
+ }
499
+ /**
500
+ * Knowledge catalogs on this device, behind the App SDK's knowledge contract
501
+ * (`state`, `update`, `retrieve`) with the daemon routes' semantics
502
+ * (inference/src/http/routes/v1-knowledge.ts). Search is the daemon's own
503
+ * `searchUnifiedCatalogs` over the daemon's catalog host, run in a worker that
504
+ * reads each verified `.gezk` archive in place. Each catalog's query model
505
+ * downloads with it and embeds questions natively; until it is installed the
506
+ * catalog is searched by keyword, as on a desktop that has not cached it.
507
+ */
508
+ declare function createMobileKnowledge(options: MobileKnowledgeOptions): {
509
+ state: () => Promise<KnowledgeState>;
510
+ update: (action: Action) => Promise<void>;
511
+ retrieve: (query: KnowledgeRetrieveInput, opts?: {
512
+ signal?: AbortSignal;
513
+ }) => Promise<Retrieval>;
514
+ /** Stop the worker; the next request starts it again. */
515
+ release(): void;
516
+ };
517
+ type MobileKnowledge = ReturnType<typeof createMobileKnowledge>;
518
+
519
+ declare const GezelRuntime: GezelRuntimePlugin;
520
+ /** Connect the ordinary App SDK client to this app's on-device runtime. */
521
+ declare function connect(): _bendyline_gezel_app_sdk_browser.GezelApp<"portable">;
522
+
523
+ /** Opt-in wrapper; construction and setEnabled(true) do not touch native services. */
524
+ declare function createMobileEmbedding(options?: Parameters<typeof createRuntimeEmbedding>[1]): {
525
+ readonly state: _bendyline_gezel_app_sdk_browser.EmbeddingState;
526
+ setEnabled(value: boolean): Promise<void>;
527
+ reconnect(): Promise<void>;
528
+ suspend(): Promise<void>;
529
+ resume(): void;
530
+ close(): Promise<void>;
531
+ models: {
532
+ list: (opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<_bendyline_gezel_app_sdk_browser.ModelDescriptor[]>;
533
+ inspect: (id: string, opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<_bendyline_gezel_app_sdk_browser.ModelDescriptor | null>;
534
+ prepare: (id: string, opts?: _bendyline_gezel_app_sdk_browser.PrepareModelOptions) => Promise<_bendyline_gezel_app_sdk_browser.ModelDescriptor>;
535
+ };
536
+ knowledge: {
537
+ state: (opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<_bendyline_gezel_app_sdk_browser.KnowledgeState>;
538
+ update: (action: Parameters<_bendyline_gezel_app_sdk_browser.KnowledgeClient["update"]>[0], opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<void>;
539
+ retrieve: (query: Parameters<_bendyline_gezel_app_sdk_browser.KnowledgeClient["retrieve"]>[0], opts?: _bendyline_gezel_app_sdk_browser.RequestOptions) => Promise<{
540
+ reranked: boolean;
541
+ passages: {
542
+ uri: string;
543
+ title: string;
544
+ text: string;
545
+ catalogId: string;
546
+ version: string;
547
+ }[];
548
+ }>;
549
+ };
550
+ streamText(request: _bendyline_gezel_app_sdk_browser.TextRequest, opts?: _bendyline_gezel_app_sdk_browser.TextOptions): Promise<{
551
+ type: "done";
552
+ text: string;
553
+ cancelled: boolean;
554
+ finishReason: string | null;
555
+ model: string;
556
+ usage: _bendyline_gezel_app_sdk_browser.ChatCompletionResponse["usage"] | null;
557
+ appliedMaxTokens: number | null;
558
+ }>;
559
+ };
560
+
561
+ export { GezelKnowledge, type GezelKnowledgePlugin, GezelOfflineSpeech, type GezelOfflineSpeechPlugin, GezelRuntime, type GezelRuntimePlugin, KOKORO_DEFAULT_VOICE, KOKORO_MOBILE_MODEL_FILE, KOKORO_SAMPLE_RATE, type KnowledgeWorkerUrls, MOBILE_SPEECH_MODELS, type MobileKnowledge, type MobileKnowledgeCatalog, type MobileKnowledgeOptions, type MobileModelManagerOptions, type MobileQueryModel, type MobileSpeech, type MobileSpeechChunk, type MobileSpeechDownloadProgress, MobileSpeechError, type MobileSpeechErrorCode, type MobileSpeechFile, type MobileSpeechModel, type MobileSpeechOptions, type MobileSpeechSegment, type MobileSpeechStatus, type MobileSpeechSynthesis, type MobileSpeechTranscript, type MobileSpeechVoice, type MobileSpeechWord, type MobileSpeechWordTiming, connect, connectEmbeddingRuntime, connectRuntime, createMobileEmbedding, createMobileKnowledge, createMobileModelManager, createMobileSpeech, createRuntimeEmbedding, knowledgeCatalogUrl, kokoroWordTimings, mobileCatalog, mobileCatalogVersion, mobileKnowledgeCatalogVersion, mobileKnowledgeCatalogs, mobileQueryModels, mobileSpeechError, mobileSpeechModel, queryModelStoreId, speechDownloadBytes, splitSentences, wavToPcm16, whisperWords };