arcane-os 0.93.0 → 0.94.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.
@@ -82,6 +82,7 @@ runtime layouts.
82
82
  | `arcane-os/core/image` | Native image Core service with independent runtime preparation and retained model ownership. |
83
83
  | `arcane-os/core/speech` | Independent injected STT/TTS engine loading, request cancellation and joined Core service lifetime. |
84
84
  | `arcane-os/local-ai/whisper` | Retained native Whisper model, complete recordings and joined helper lifetime. |
85
+ | `arcane-os/local-ai/kokoro` | Retained native Kokoro synthesis using the existing ONNX/model-resource owners and a compiled phonemization/Opus helper. |
85
86
  | `arcane-os/local-ai/whisper/build` | First-party persistent helper build against selected installed Whisper headers and libraries. |
86
87
  | `arcane-os/local-ai/whisper/openvino-build` | Optional Windows x64 Intel NPU encoder runtime producer using selected installed sources and toolchain. |
87
88
  | `arcane-os/ai/core-model-assets` | Complete stored browser model members projected through Core into native working files. |
@@ -469,6 +470,12 @@ The remaining data-only subpaths are eight JSON Schemas and package metadata.
469
470
  | `createLocalImageService()` | function | `arcane-os/core/image` | Core local images | Node Core with selected stable-diffusion.cpp requirements |
470
471
  | `createLocalImageService default export` | function | `arcane-os/core/image` | Core local images | Same native image service factory |
471
472
  | `createSpeechService()` | function | `arcane-os/core/speech` | Core native speech | Node Core with explicitly supplied speech engines |
473
+ | `createNativeKokoroRuntime()` | function | `arcane-os/local-ai/kokoro` | Core native speech | Node with matching prepared helper/data, selected model resources and an existing ONNX owner |
474
+ | `createNativeKokoroRuntime default export` | function | `arcane-os/local-ai/kokoro` | Core native speech | Same retained native Kokoro factory |
475
+ | `KOKORO_MODEL` | constant | `arcane-os/local-ai/kokoro` | Core native speech | Selected upstream model identifier |
476
+ | `KOKORO_REVISION` | constant | `arcane-os/local-ai/kokoro` | Core native speech | Selected upstream model revision |
477
+ | `KOKORO_SAMPLE_RATE` | constant | `arcane-os/local-ai/kokoro` | Core native speech | Native PCM sample rate |
478
+ | `KOKORO_VOICES` | constant | `arcane-os/local-ai/kokoro` | Core native speech | Complete 28-voice US/GB selection |
472
479
  | `createWhisperRuntime()` | function | `arcane-os/local-ai/whisper` | Core native speech | Node with a prepared matching helper, runtime, decoder and selected model |
473
480
  | `createWhisperRuntime default export` | function | `arcane-os/local-ai/whisper` | Core native speech | Same retained native engine factory |
474
481
  | `buildWhisperHelper()` | function | `arcane-os/local-ai/whisper/build` | Core native speech | Node with installed CMake/C++17 toolchain and matching Whisper source/runtime |
@@ -8842,6 +8849,118 @@ selected model and native engine.
8842
8849
  The default export from `arcane-os/core/image` is the same
8843
8850
  `createLocalImageService` factory and lifecycle described above.
8844
8851
 
8852
+ ## createNativeKokoroRuntime()
8853
+
8854
+ ### Overview and signature
8855
+
8856
+ The named export from `arcane-os/local-ai/kokoro` composes the selected Kokoro
8857
+ FP32 graph with the host's existing native ONNX owner, model-resource owner
8858
+ and prepared persistent phonemization/Opus helper. Construction starts no
8859
+ native work and acquires no model or runtime.
8860
+
8861
+ ```javascript
8862
+ createNativeKokoroRuntime({
8863
+ onnx, modelAssets, runtime, prepare, modelId = 'kokoro',
8864
+ model = KOKORO_MODEL, revision = KOKORO_REVISION, dtype = 'fp32',
8865
+ paths, assetProjectionId, resourcePaths, sessionOptions,
8866
+ executionPreference = 'gpu', executionTarget, signal, onEvent
8867
+ } = {})
8868
+ ```
8869
+
8870
+ Supply the existing `onnx` runtime or a `prepare` callback that provides it.
8871
+ `runtime` describes the matching native helper and data. `paths` supplies
8872
+ complete prepared graph/tokenizer/voice resources; a completed
8873
+ `assetProjectionId` instead retains projected resources through `modelAssets`.
8874
+ The selected model/revision/FP32 contract is fixed by this frontend.
8875
+ See [native Kokoro](native-speech.md) for exact resource mappings, preparation,
8876
+ runtime distribution and model ownership.
8877
+
8878
+ ### Members and results
8879
+
8880
+ - `current()` returns complete model/lifecycle state, execution configuration,
8881
+ current request, queue, progress, error, default voice and supported voices.
8882
+ - `subscribe(listener,{replay=true,signal}={})` returns an unsubscribe function
8883
+ and replays current state by default.
8884
+ - `load(options={})` activates the selected resources, retaining omitted
8885
+ selections. Explicit projection/resource mapping or execution-target changes
8886
+ join prior native retirement before loading the new activation.
8887
+ - `synthesize(request,{signal,onProgress,requestId=null}={})` requires a loaded
8888
+ activation. `request` contains the complete `input` string, optional `model`
8889
+ matching `modelId`, `voice` (default `af_heart`), positive finite `speed`
8890
+ (default `1`) and `responseFormat` (`wav` by default, `opus` or `ogg`).
8891
+ The result is `{audioBase64,contentType,sampleRate,channels,model,voice,speed}`;
8892
+ content type is `audio/wav` or `audio/ogg; codecs=opus`, with mono 24kHz PCM
8893
+ synthesis. The full input is processed in ordered model segments.
8894
+ - `unload()` retires the activation and joins owned native work. `close()`
8895
+ permanently closes the engine and releases its state subscriptions.
8896
+
8897
+ Queued requests retain order. Cancelling a queued request removes only that
8898
+ request. Active cancellation waits for actual helper/session retirement;
8899
+ surviving requests resume with the same accepted provider configuration.
8900
+ The ONNX owner may need a running native call to return before its worker exits.
8901
+ Readiness is lost while that retirement/reload occurs. Errors retain the actual
8902
+ engine and cleanup failures; unsupported explicit voices or formats are never
8903
+ substituted. No audio is played by this engine.
8904
+
8905
+ ### Example
8906
+
8907
+ ```javascript
8908
+ import {createNativeKokoroRuntime} from 'arcane-os/local-ai/kokoro';
8909
+
8910
+ // The host supplies its existing ONNX owner and already prepared resources.
8911
+ async function narrateMoonGoat({onnx, runtime, paths}) {
8912
+ const voice = createNativeKokoroRuntime({
8913
+ onnx, runtime, paths, executionPreference: 'cpu'
8914
+ });
8915
+ try {
8916
+ await voice.load();
8917
+ return await voice.synthesize({
8918
+ input: 'Captain Goat has landed. Guard the moon cheese!',
8919
+ voice: 'af_heart', responseFormat: 'wav'
8920
+ });
8921
+ } finally {
8922
+ await voice.close();
8923
+ }
8924
+ }
8925
+ ```
8926
+
8927
+ Changing `voice` to `bf_emma` selects British English. `responseFormat: 'opus'`
8928
+ selects Ogg Opus encoding. GPU/physical-device selection uses the existing
8929
+ [ONNX execution contract](local-ai.md#physical-execution-targets); an accepted
8930
+ provider configuration is separate from observed hardware execution.
8931
+ The SDK publishes a Windows x64 helper archive. Other platforms need a matching
8932
+ custom helper distribution and supported native ONNX host. Native helper
8933
+ production and platform execution evidence remain separate.
8934
+
8935
+ ## createNativeKokoroRuntime default export
8936
+
8937
+ The default export from `arcane-os/local-ai/kokoro` is the same
8938
+ `createNativeKokoroRuntime` factory with identical inputs, results and lifetime.
8939
+
8940
+ ## KOKORO_MODEL
8941
+
8942
+ Named string export from `arcane-os/local-ai/kokoro`, with value
8943
+ `onnx-community/Kokoro-82M-v1.0-ONNX`. It identifies this frontend's model family
8944
+ for matching graph, tokenizer and voice resource selection.
8945
+
8946
+ ## KOKORO_REVISION
8947
+
8948
+ Named string export from `arcane-os/local-ai/kokoro`, with value
8949
+ `1939ad2a8e416c0acfeecc08a694d14ef25f2231`. Resource preparation uses this
8950
+ upstream revision with `KOKORO_MODEL`.
8951
+
8952
+ ## KOKORO_SAMPLE_RATE
8953
+
8954
+ Named number export from `arcane-os/local-ai/kokoro`, with value `24000`.
8955
+ It describes the engine's mono PCM synthesis rate in samples per second.
8956
+
8957
+ ## KOKORO_VOICES
8958
+
8959
+ Named array export from `arcane-os/local-ai/kokoro` containing all 28 supported
8960
+ US/GB voice identifiers. The engine uses `af_heart` when the caller omits
8961
+ `voice`; an explicit unsupported selection reports an error. Use this complete
8962
+ array to populate a native Kokoro voice selector.
8963
+
8845
8964
  ## createWhisperRuntime()
8846
8965
 
8847
8966
  ### Overview
@@ -9018,6 +9137,13 @@ The returned object has `name: 'speech'`, `current`, `subscribe`, `close`,
9018
9137
  Core RPC methods. The context supplies `signal`, `requestId` and `emit`.
9019
9138
  The service publishes synchronous accepted `Thinking` before waiting for
9020
9139
  its role's load, then forwards the engine's complete progress and result.
9140
+ - `methods['speech.load'](request,context)` and
9141
+ `methods['speech.unload'](request,context)` route explicit activation to the
9142
+ explicit `role: 'stt' | 'tts'` and forward the remaining activation
9143
+ fields and result through that role's configured engine. A startup load remains owned independently of callers
9144
+ waiting for it. The browser facade exposes `Arcane.speech.load(request,options)`
9145
+ and `unload(request,options)` with `signal`, `onRequest` and no elapsed-time
9146
+ cutoff. See [activation routing](native-speech.md) for selection and errors.
9021
9147
  - `close()` and its `drain()` alias stop acceptance, abort the service lifetime,
9022
9148
  close both engines concurrently and await startup and request work. Repeated
9023
9149
  calls share one promise. `dispose()` also releases event subscriptions.
@@ -9123,7 +9249,8 @@ import createLocalAIService from 'arcane-os/core/local-ai';
9123
9249
  ### Overview
9124
9250
 
9125
9251
  Reuses matching managed runtimes or installs complete selected
9126
- llama.cpp/Ollama/ONNX/image distributions or NeMo libraries in an explicitly supplied directory.
9252
+ llama.cpp/Ollama/ONNX/image distributions, NeMo libraries or native Kokoro
9253
+ helper/data trees in an explicitly supplied directory.
9127
9254
 
9128
9255
  ### Signature and result
9129
9256
 
@@ -9146,6 +9273,12 @@ trees remain intact while a fresh installation is prepared. See
9146
9273
  Image requirements also accept `backend` and
9147
9274
  `models`; their pinned default runtime, CPU/Metal selection and separate model
9148
9275
  preparation are described in [local image generation](local-image-generation.md).
9276
+ `kokoro-native` returns `helperExecutable`, `espeakDataDirectory` and
9277
+ `libraryDirectory`. Windows x64 defaults to the helper archive from the
9278
+ installed SDK's numeric release; an explicit `url` or `helperRoot` selects a
9279
+ complete custom distribution. The data directory is the parent of
9280
+ `espeak-ng-data`. Helper preparation loads no Kokoro graph and keeps the
9281
+ existing ONNX/model-resource owners separate. See [native speech](native-speech.md).
9149
9282
  Matching concurrent
9150
9283
  installs share their work. Downloads retain runtime libraries and surface
9151
9284
  network/archive failures; cancellation and operation events remain observable.
@@ -9189,6 +9322,10 @@ The corrected Windows x64 ONNX selection retains its
9189
9322
  is relocated with the other runtime paths; bundling introduces no separate
9190
9323
  runtime selection. See [ONNX runtime preparation](local-ai.md#development).
9191
9324
 
9325
+ Kokoro bundling retains the complete helper/data tree and relocates
9326
+ `helperExecutable`, `espeakDataDirectory` and `libraryDirectory`. Its selected
9327
+ ONNX runtime and model resources retain their existing independent ownership.
9328
+
9192
9329
  Image records relocate the complete library, binding and variant paths. Model
9193
9330
  URL descriptors retain their original acquisition metadata for preparation
9194
9331
  after launch. Runtime-contained native model paths become artifact-relative;
@@ -11683,10 +11820,11 @@ the message or response callback payload.
11683
11820
 
11684
11821
  **Node and Browser; Cloud transport.** Uses standard Fetch and cancellation,
11685
11822
  without DOM, browser profiles, user singletons, or storage initialization.
11686
- Import starts no request. HTTP `429` whose message contains `overload`
11687
- (case-insensitive) waits
11688
- `3000` milliseconds and retries the complete request; other HTTP failures
11689
- throw their complete parsed JSON or text bodies. A missing key throws
11823
+ Import starts no request. Rejected Fetch and all HTTP `429`/`529` share three
11824
+ retries. Quota recovery honors `Retry-After`, otherwise waits `3000`, `6000`,
11825
+ or `12000` milliseconds by retry number. Active same-endpoint/credential calls
11826
+ share quota cooldown and paced dispatch. Complete error bodies remain unchanged
11827
+ on exhaustion; other HTTP failures are not retried. A missing key throws
11690
11828
  `AI_PROVIDER_NOT_CONFIGURED`; a missing model throws `TypeError`. `signal`
11691
11829
  cancellation during transport, body reading, retry waiting,
11692
11830
  or callback settlement prevents successful return and uses
@@ -11836,21 +11974,24 @@ Ordinary TWiN callers use `fetchRequest()` instead.
11836
11974
  ### Signature and result
11837
11975
 
11838
11976
  ```text
11839
- async fetchHTTPResponse(url,options)
11977
+ async fetchHTTPResponse(url,options,{onRetry=null}={})
11840
11978
  ```
11841
11979
 
11842
11980
  Returns the successful Fetch `Response` without consuming its body. Both URL
11843
11981
  and Fetch options are caller-supplied; this helper adds no key, model, or
11844
11982
  request envelope. Non-success responses are read completely as JSON when the
11845
- content type contains `application/json`, otherwise as text. Only status 429
11846
- with an overload message repeats after 3000 ms; other error bodies are thrown.
11983
+ content type contains `application/json`, otherwise as text. Rejected Fetch
11984
+ and all `429`/`529` share three retries with complete terminal errors.
11985
+ `429` honors `Retry-After` or exponential delay and coordinates a transient
11986
+ same-endpoint/credential cooldown. See [shared request behavior](ai/twin-cloud.md#shared-request-behavior).
11847
11987
 
11848
11988
  ### Availability and normalization
11849
11989
 
11850
11990
  **Node and Browser.** Exported from `arcane-os/ai/twin-cloud` for shared SDK
11851
- integration. `options.signal` cancels Fetch and the overload wait and is checked
11991
+ integration. `options.signal` cancels Fetch and recovery/pacing waits and is checked
11852
11992
  after response/error-body reads. Cancellation uses
11853
- `ARCANE_AI_REQUEST_ABORTED`. Overload warnings use the existing shared logger.
11993
+ `ARCANE_AI_REQUEST_ABORTED`. Retry warnings use the existing shared logger;
11994
+ `onRetry` observes complete waiting/requesting records outside the payload.
11854
11995
 
11855
11996
  ### Example
11856
11997
 
@@ -11870,7 +12011,7 @@ Shared complete JSON-body reader built on `fetchHTTPResponse()`.
11870
12011
  ### Signature and result
11871
12012
 
11872
12013
  ```text
11873
- async fetchJSONResponse(url,options)
12014
+ async fetchJSONResponse(url,options,{onRetry=null}={})
11874
12015
  ```
11875
12016
 
11876
12017
  Returns the full parsed JSON value. A successful response whose content type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arcane-os",
3
- "version": "0.93.0",
3
+ "version": "0.94.0",
4
4
  "description": "Arcane OS JavaScript SDK, project-local CLI, browser runtime, and repository-portable application packager.",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -89,6 +89,7 @@
89
89
  "./local-ai/decisions": "./src/local-ai/decisions.mjs",
90
90
  "./local-ai/image": "./src/local-ai/image-runtime.mjs",
91
91
  "./local-ai/whisper": "./src/local-ai/whisper/index.mjs",
92
+ "./local-ai/kokoro": "./src/local-ai/kokoro/index.mjs",
92
93
  "./local-ai/whisper/build": "./src/local-ai/whisper/build.mjs",
93
94
  "./local-ai/whisper/openvino-build": "./src/local-ai/whisper/openvino-build.mjs",
94
95
  "./integrated-provider": "./src/integrated-provider-loader.mjs",
@@ -277,12 +277,12 @@
277
277
  "type": "array",
278
278
  "items": {
279
279
  "oneOf": [
280
- { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp", "whisper.cpp"] },
280
+ { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp", "whisper.cpp", "kokoro-native"] },
281
281
  {
282
282
  "type": "object",
283
283
  "required": ["id"],
284
284
  "properties": {
285
- "id": { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp"] },
285
+ "id": { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp", "kokoro-native"] },
286
286
  "version": { "type": "string" },
287
287
  "url": { "type": "string" },
288
288
  "backend": { "type": "string", "description": "llama.cpp: auto, cpu or cuda. Image runtimes: auto, metal or cpu." },
@@ -156,12 +156,12 @@
156
156
  "type": "array",
157
157
  "items": {
158
158
  "oneOf": [
159
- { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp", "whisper.cpp"] },
159
+ { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp", "whisper.cpp", "kokoro-native"] },
160
160
  {
161
161
  "type": "object",
162
162
  "required": ["id"],
163
163
  "properties": {
164
- "id": { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp"] },
164
+ "id": { "enum": ["llama.cpp", "ollama", "onnx", "stable-diffusion.cpp", "kokoro-native"] },
165
165
  "version": { "type": "string" },
166
166
  "url": { "type": "string" },
167
167
  "backend": { "type": "string", "description": "llama.cpp: auto, cpu or cuda. Image runtimes: auto, metal or cpu." },
@@ -44,8 +44,8 @@ function waitForLoad(task, signal) {
44
44
  /** Hosts supply selected engines; this service owns their independent lifetimes. */
45
45
  export function createSpeechService({stt, tts, signal} = {}) {
46
46
  const roles = {
47
- stt: {engine: stt, operation: 'transcribe', state: null, loading: null, unsubscribe: null},
48
- tts: {engine: tts, operation: 'synthesize', state: null, loading: null, unsubscribe: null}
47
+ stt: {engine: stt, operation: 'transcribe', state: null, loading: null, changing: null, unsubscribe: null},
48
+ tts: {engine: tts, operation: 'synthesize', state: null, loading: null, changing: null, unsubscribe: null}
49
49
  };
50
50
  for (const [name, role] of Object.entries(roles)) {
51
51
  if (role.engine == null) {
@@ -124,6 +124,36 @@ export function createSpeechService({stt, tts, signal} = {}) {
124
124
  publish();
125
125
  }
126
126
 
127
+ function observeRoleTask(name, task, startup = false) {
128
+ const role = roles[name];
129
+ role.changing = task;
130
+ // Explicit load cancellation belongs to that caller's wait, not another
131
+ // inference request. Only the service-owned startup is a shared wait.
132
+ role.loading = startup ? task : null;
133
+ jobs.add(task);
134
+ function settled(error, failed) {
135
+ jobs.delete(task);
136
+ // An older startup or activation must not replace the selected state.
137
+ if (role.loading === task) role.loading = null;
138
+ if (role.changing !== task) return;
139
+ role.changing = null;
140
+ if (closed) return;
141
+ if (failed && startup && !closing) {
142
+ roleFailed(name, error);
143
+ } else {
144
+ role.state = role.engine.current();
145
+ publish();
146
+ }
147
+ }
148
+ task.then(
149
+ function speechRoleSettled() { settled(undefined, false); },
150
+ function speechRoleFailed(error) { settled(error, true); }
151
+ ).catch(function speechRoleObserverFailed(error) {
152
+ console.error('Speech role state observer failed.', error);
153
+ });
154
+ return task;
155
+ }
156
+
127
157
  function startRole(name) {
128
158
  const role = roles[name];
129
159
  if (!role.engine || closing) {
@@ -142,34 +172,60 @@ export function createSpeechService({stt, tts, signal} = {}) {
142
172
  roleFailed(name, error);
143
173
  return;
144
174
  }
175
+ // Replay can synchronously select an activation or close the service.
176
+ if (role.changing || closing || closed) return;
145
177
  const task = Promise.resolve().then(
146
178
  async function loadSpeechEngine() {
147
179
  lifetimeSignal.throwIfAborted();
148
- await role.engine.load(
180
+ if (role.changing !== task) return;
181
+ return role.engine.load(
149
182
  {signal: lifetimeSignal}
150
183
  );
151
- if (!closed) {
152
- role.state = role.engine.current();
153
- publish();
154
- }
155
- }
156
- );
157
- role.loading = task;
158
- task.then(
159
- function speechEngineLoaded() {
160
- role.loading = null;
161
- },
162
- function speechEngineLoadFailed(error) {
163
- role.loading = null;
164
- if (!closing) {
165
- roleFailed(name, error);
166
- }
167
- }
168
- ).catch(
169
- function speechLoadObserverFailed(error) {
170
- console.error('Speech load state observer failed.', error);
171
184
  }
172
185
  );
186
+ observeRoleTask(name, task, true);
187
+ }
188
+
189
+ function changeRole(operation, parameters, request) {
190
+ if (closing || closed) {
191
+ throw failure('CORE_CLOSING', 'The speech service is closing.');
192
+ }
193
+ if (!parameters || !is.object(parameters) || is.array(parameters)
194
+ || !['stt', 'tts'].includes(parameters.role)) {
195
+ throw failure('SPEECH_ROLE_INVALID', 'Select the stt or tts speech role.');
196
+ }
197
+ const {role: name, ...selection} = parameters;
198
+ const role = roles[name];
199
+ const operationSignal = request.signal
200
+ ? AbortSignal.any([lifetimeSignal, request.signal]) : lifetimeSignal;
201
+ operationSignal.throwIfAborted();
202
+ if (!role.engine) {
203
+ throw failure('SPEECH_ENGINE_UNAVAILABLE', `No ${name} speech engine is configured.`);
204
+ }
205
+ if (!is.function(role.engine[operation])) {
206
+ throw failure('SPEECH_OPERATION_UNAVAILABLE', `The ${name} speech engine does not support ${operation}().`);
207
+ }
208
+ let acknowledgementFailed = false;
209
+ let acknowledgementError;
210
+ const task = Promise.resolve().then(async function changeSpeechRole() {
211
+ if (acknowledgementFailed) throw acknowledgementError;
212
+ operationSignal.throwIfAborted();
213
+ const result = await role.engine[operation]({...selection, signal: operationSignal});
214
+ operationSignal.throwIfAborted();
215
+ return result;
216
+ });
217
+ // Retain ownership before an acknowledgement observer can close or reenter.
218
+ observeRoleTask(name, task);
219
+ try {
220
+ request.emit?.('speech.progress', {
221
+ requestId: request.requestId, role: name, operation,
222
+ status: 'Thinking', progress: {phase: 'accepted'}
223
+ });
224
+ } catch (error) {
225
+ acknowledgementFailed = true;
226
+ acknowledgementError = error;
227
+ }
228
+ return task;
173
229
  }
174
230
 
175
231
  function invoke(name, parameters, request) {
@@ -340,6 +396,12 @@ export function createSpeechService({stt, tts, signal} = {}) {
340
396
  },
341
397
  methods: {
342
398
  'speech.status': current,
399
+ 'speech.load': function load(parameters, request = {}) {
400
+ return changeRole('load', parameters, request);
401
+ },
402
+ 'speech.unload': function unload(parameters, request = {}) {
403
+ return changeRole('unload', parameters, request);
404
+ },
343
405
  'speech.transcribe': function transcribe(parameters, request = {}) {
344
406
  return invoke('stt', parameters, request);
345
407
  },
@@ -8,7 +8,17 @@ import {SDXL_BASE_1_0_MODEL} from './image-models/sdxl.mjs';
8
8
  import {normalizeWhisperRuntimeRequirement} from './whisper/config.mjs';
9
9
 
10
10
  const is = new Is(false);
11
- export const LOCAL_AI_RUNTIME_IDS = ['llama.cpp', 'ollama', 'onnx', 'stable-diffusion.cpp', 'whisper.cpp'];
11
+ export const LOCAL_AI_RUNTIME_IDS = ['llama.cpp', 'ollama', 'onnx', 'stable-diffusion.cpp', 'whisper.cpp', 'kokoro-native'];
12
+
13
+ /** Describe the selected helper without acquiring it or selecting model assets. */
14
+ export function normalizeKokoroRuntimeRequirement(record) {
15
+ for (const field of ['helperRoot', 'helperExecutable', 'espeakDataDirectory', 'libraryDirectory']) {
16
+ if (record[field] !== undefined && (!is.string(record[field]) || record[field] === '')) {
17
+ throw new ArcaneError(ERROR_CODES.usage, `kokoro-native ${field} must be a nonempty path.`);
18
+ }
19
+ }
20
+ return {...record};
21
+ }
12
22
 
13
23
  /** Select a llama distribution without discovering hardware or acquiring it. */
14
24
  export function normalizeLlamaRuntimeRequirement(record) {
@@ -79,6 +89,7 @@ export function normalizeLocalAIConfig(value) {
79
89
  if (record.id === 'llama.cpp') return normalizeLlamaRuntimeRequirement(record);
80
90
  if (record.id === 'stable-diffusion.cpp') return normalizeImageRuntimeRequirement(record);
81
91
  if (record.id === 'whisper.cpp') return normalizeWhisperRuntimeRequirement(record);
92
+ if (record.id === 'kokoro-native') return normalizeKokoroRuntimeRequirement(record);
82
93
  return {...record};
83
94
  });
84
95
  return {...value, runtimes};
@@ -9,7 +9,9 @@ import {normalizeLocalAIConfig} from './config.mjs';
9
9
  import {discoverLocalAIRuntimes} from './discover.mjs';
10
10
  import {ensureLocalAIRuntimes} from './install.mjs';
11
11
  import {createWhisperRuntime} from './whisper/index.mjs';
12
+ import {createNativeKokoroRuntime} from './kokoro/index.mjs';
12
13
  import {createExecutionDeviceCatalog} from './execution-devices.mjs';
14
+ import {ArcaneError, ERROR_CODES} from '../errors.mjs';
13
15
 
14
16
  /** Local engines share the ordinary app-service development transport. */
15
17
  export function createDevelopmentLocalAI({
@@ -24,7 +26,7 @@ export function createDevelopmentLocalAI({
24
26
  const localConfig = {
25
27
  ...selected,
26
28
  runtimes: selected.runtimes.filter(function selectedChatRuntime(requirement) {
27
- return requirement.id !== 'stable-diffusion.cpp' && requirement.id !== 'whisper.cpp';
29
+ return !['stable-diffusion.cpp', 'whisper.cpp', 'kokoro-native'].includes(requirement.id);
28
30
  })
29
31
  };
30
32
  const service = createLocalAIService(
@@ -48,7 +50,7 @@ export function createDevelopmentLocalAI({
48
50
  return requirement.id === 'stable-diffusion.cpp';
49
51
  });
50
52
  if (imageSelected || selected.runtimes.some(function selectedProjectedRuntime(requirement) {
51
- return ['onnx', 'llama.cpp'].includes(requirement.id);
53
+ return ['onnx', 'llama.cpp', 'kokoro-native'].includes(requirement.id);
52
54
  })) {
53
55
  modelAssets = createModelAssetService({appRoot});
54
56
  definitions.push(modelAssets);
@@ -71,8 +73,13 @@ export function createDevelopmentLocalAI({
71
73
  const whisperRequirement = selected.runtimes.find(function selectedWhisperRuntime(requirement) {
72
74
  return requirement.id === 'whisper.cpp';
73
75
  });
76
+ const kokoroRequirement = selected.runtimes.find(function selectedKokoroRuntime(requirement) {
77
+ return requirement.id === 'kokoro-native';
78
+ });
79
+ let stt;
80
+ let tts;
74
81
  if (whisperRequirement) {
75
- const stt = createWhisperRuntime(
82
+ stt = createWhisperRuntime(
76
83
  {
77
84
  modelId: whisperRequirement.modelId,
78
85
  temporaryDirectory: path.join(appRoot, '.arcane', 'speech', 'whisper'),
@@ -85,7 +92,49 @@ export function createDevelopmentLocalAI({
85
92
  }
86
93
  }
87
94
  );
88
- speechService = createSpeechService({stt, signal});
95
+ }
96
+ if (kokoroRequirement) {
97
+ tts = createNativeKokoroRuntime({
98
+ modelId: kokoroRequirement.modelId,
99
+ model: kokoroRequirement.model,
100
+ revision: kokoroRequirement.revision,
101
+ dtype: kokoroRequirement.dtype,
102
+ paths: kokoroRequirement.paths,
103
+ assetProjectionId: kokoroRequirement.assetProjectionId,
104
+ resourcePaths: kokoroRequirement.resourcePaths,
105
+ sessionOptions: kokoroRequirement.sessionOptions,
106
+ executionPreference: kokoroRequirement.executionPreference,
107
+ executionTarget: kokoroRequirement.executionTarget,
108
+ modelAssets, signal, onEvent,
109
+ async prepare({signal: activationSignal}) {
110
+ if (!localConfig.runtimes.some(function selectedONNX(requirement) { return requirement.id === 'onnx'; })) {
111
+ throw new ArcaneError(ERROR_CODES.targetUnavailable, 'Native Kokoro requires an explicitly selected onnx runtime.');
112
+ }
113
+ const preparation = new AbortController();
114
+ const preparationSignal = AbortSignal.any([activationSignal, preparation.signal]);
115
+ function preparationFailed(error) {
116
+ preparation.abort(error);
117
+ throw error;
118
+ }
119
+ // Helper acquisition and the existing ONNX owner's startup are
120
+ // independent. Join both before native activation can continue.
121
+ const outcomes = await Promise.allSettled([
122
+ waitForKokoroONNX(preparationSignal).catch(preparationFailed),
123
+ ensureLocalAIRuntimes({
124
+ runtimes: [kokoroRequirement], directory, signal: preparationSignal, onEvent
125
+ }).catch(preparationFailed)
126
+ ]);
127
+ const failures = outcomes.filter(function failed(result) { return result.status === 'rejected'; })
128
+ .map(function cause(result) { return result.reason; });
129
+ if (failures.length === 1) throw failures[0];
130
+ if (failures.length) throw new AggregateError(failures, 'Native Kokoro preparation failed.');
131
+ preparationSignal.throwIfAborted();
132
+ return {onnx: outcomes[0].value, runtime: outcomes[1].value[0]};
133
+ }
134
+ });
135
+ }
136
+ if (stt || tts) {
137
+ speechService = createSpeechService({stt, tts, signal});
89
138
  definitions.push(speechService);
90
139
  }
91
140
  const core = createDevelopmentCore(
@@ -101,6 +150,24 @@ export function createDevelopmentLocalAI({
101
150
  }
102
151
  }
103
152
  );
153
+ function waitForKokoroONNX(activationSignal) {
154
+ activationSignal.throwIfAborted();
155
+ let cancel;
156
+ const cancelled = new Promise(function observePreparationCancellation(_resolve, reject) {
157
+ cancel = function stopWaitingForONNX() { reject(activationSignal.reason); };
158
+ activationSignal.addEventListener('abort', cancel, {once: true});
159
+ });
160
+ const ready = core.ready.then(async function existingONNXOwner(runtime) {
161
+ activationSignal.throwIfAborted();
162
+ const owner = await runtime.getService('local-ai');
163
+ activationSignal.throwIfAborted();
164
+ return owner.getONNXRuntime();
165
+ });
166
+ // Cancel this selected activation's wait without stopping the shared owner.
167
+ return Promise.race([ready, cancelled]).finally(function releaseONNXWait() {
168
+ activationSignal.removeEventListener('abort', cancel);
169
+ });
170
+ }
104
171
  function current() {
105
172
  return {
106
173
  ...core.current(),