@qvac/sdk 0.8.3 → 0.9.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 (216) hide show
  1. package/NOTICE +267 -63
  2. package/dist/client/api/diffusion.d.ts +32 -0
  3. package/dist/client/api/diffusion.js +103 -0
  4. package/dist/client/api/embed.d.ts +9 -3
  5. package/dist/client/api/embed.js +4 -1
  6. package/dist/client/api/finetune.d.ts +69 -0
  7. package/dist/client/api/finetune.js +139 -0
  8. package/dist/client/api/get-model-info.d.ts +1 -1
  9. package/dist/client/api/index.d.ts +4 -0
  10. package/dist/client/api/index.js +4 -0
  11. package/dist/client/api/rag.d.ts +1 -1
  12. package/dist/client/api/rag.js +1 -1
  13. package/dist/client/api/resume.d.ts +14 -0
  14. package/dist/client/api/resume.js +20 -0
  15. package/dist/client/api/suspend.d.ts +13 -0
  16. package/dist/client/api/suspend.js +19 -0
  17. package/dist/client/api/transcribe.d.ts +25 -17
  18. package/dist/client/api/transcribe.js +115 -35
  19. package/dist/client/rpc/bare-client.d.ts +5 -1
  20. package/dist/client/rpc/bare-client.js +70 -57
  21. package/dist/client/rpc/expo-rpc-client.d.ts +4 -0
  22. package/dist/client/rpc/expo-rpc-client.js +8 -0
  23. package/dist/client/rpc/node-rpc-client.d.ts +4 -0
  24. package/dist/client/rpc/node-rpc-client.js +8 -0
  25. package/dist/client/rpc/rpc-client.d.ts +13 -0
  26. package/dist/client/rpc/rpc-client.js +131 -1
  27. package/dist/examples/delegated-inference/composite.d.ts +2 -0
  28. package/dist/examples/delegated-inference/composite.js +99 -0
  29. package/dist/examples/diffusion-flux2-klein.d.ts +2 -0
  30. package/dist/examples/diffusion-flux2-klein.js +46 -0
  31. package/dist/examples/diffusion-simple.d.ts +2 -0
  32. package/dist/examples/diffusion-simple.js +17 -0
  33. package/dist/examples/diffusion-txt2img.d.ts +2 -0
  34. package/dist/examples/diffusion-txt2img.js +40 -0
  35. package/dist/examples/embed-p2p.js +2 -2
  36. package/dist/examples/finetune/llamacpp-finetune.d.ts +2 -0
  37. package/dist/examples/finetune/llamacpp-finetune.js +78 -0
  38. package/dist/examples/logging-streaming.js +1 -1
  39. package/dist/examples/mcp-websearch.js +2 -0
  40. package/dist/examples/ocr-fasttext.js +11 -0
  41. package/dist/examples/profiling/per-call.js +3 -3
  42. package/dist/examples/rag/rag-chromadb.js +2 -2
  43. package/dist/examples/rag/rag-hyperdb/pipeline.js +1 -1
  44. package/dist/examples/rag/rag-lancedb.js +2 -2
  45. package/dist/examples/rag/rag-sqlite.js +2 -2
  46. package/dist/examples/suspend-resume.d.ts +2 -0
  47. package/dist/examples/suspend-resume.js +52 -0
  48. package/dist/examples/transcription/parakeet-ctc-filesystem.js +3 -5
  49. package/dist/examples/transcription/parakeet-microphone-record.js +42 -33
  50. package/dist/examples/transcription/parakeet-sortformer.js +13 -3
  51. package/dist/examples/transcription/parakeet-tdt-filesystem.js +5 -7
  52. package/dist/examples/transcription/whispercpp-filesystem-streaming.d.ts +2 -0
  53. package/dist/examples/transcription/whispercpp-filesystem-streaming.js +99 -0
  54. package/dist/examples/transcription/whispercpp-microphone-record.js +78 -299
  55. package/dist/examples/transcription/whispercpp-prompt.js +11 -0
  56. package/dist/examples/translation/translation-llm.js +2 -2
  57. package/dist/examples/tts/supertonic-multilingual.d.ts +2 -0
  58. package/dist/examples/tts/supertonic-multilingual.js +56 -0
  59. package/dist/examples/tts/supertonic.js +12 -7
  60. package/dist/index.d.ts +3 -2
  61. package/dist/index.js +3 -2
  62. package/dist/logging/utils.js +1 -1
  63. package/dist/models/registry/models.d.ts +15176 -4264
  64. package/dist/models/registry/models.js +18657 -7404
  65. package/dist/models/update-models/codegen.js +2 -2
  66. package/dist/models/update-models/naming.js +26 -0
  67. package/dist/pear/pre.js +2 -0
  68. package/dist/polyfills/bare-globals.d.ts +2 -0
  69. package/dist/polyfills/bare-globals.js +4 -0
  70. package/dist/polyfills/bare-globals.noop.d.ts +2 -0
  71. package/dist/polyfills/bare-globals.noop.js +1 -0
  72. package/dist/profiling/exporters.js +16 -11
  73. package/dist/profiling/model-execution.d.ts +16 -0
  74. package/dist/profiling/model-execution.js +33 -0
  75. package/dist/schemas/common.d.ts +967 -198
  76. package/dist/schemas/common.js +16 -1
  77. package/dist/schemas/completion-stream.d.ts +14 -6
  78. package/dist/schemas/completion-stream.js +4 -3
  79. package/dist/schemas/download-asset.d.ts +7 -3
  80. package/dist/schemas/embed.d.ts +19 -0
  81. package/dist/schemas/embed.js +7 -0
  82. package/dist/schemas/engine-addon-map.js +4 -1
  83. package/dist/schemas/finetune.d.ts +620 -0
  84. package/dist/schemas/finetune.js +161 -0
  85. package/dist/schemas/get-model-info.d.ts +2 -0
  86. package/dist/schemas/get-model-info.js +1 -0
  87. package/dist/schemas/index.d.ts +5 -1
  88. package/dist/schemas/index.js +5 -1
  89. package/dist/schemas/llamacpp-config.d.ts +26 -6
  90. package/dist/schemas/llamacpp-config.js +12 -0
  91. package/dist/schemas/load-model.d.ts +4005 -1400
  92. package/dist/schemas/load-model.js +34 -1
  93. package/dist/schemas/model-src-utils.d.ts +10 -2
  94. package/dist/schemas/model-types.d.ts +19 -1
  95. package/dist/schemas/model-types.js +11 -0
  96. package/dist/schemas/ocr.d.ts +2 -0
  97. package/dist/schemas/plugin.d.ts +24 -3
  98. package/dist/schemas/plugin.js +14 -0
  99. package/dist/schemas/profiling.d.ts +4 -0
  100. package/dist/schemas/profiling.js +4 -0
  101. package/dist/schemas/registry.d.ts +18 -0
  102. package/dist/schemas/registry.js +2 -0
  103. package/dist/schemas/reload-config.d.ts +9 -1
  104. package/dist/schemas/resume.d.ts +10 -0
  105. package/dist/schemas/resume.js +7 -0
  106. package/dist/schemas/sdcpp-config.d.ts +327 -0
  107. package/dist/schemas/sdcpp-config.js +102 -0
  108. package/dist/schemas/sdk-config.d.ts +1225 -235
  109. package/dist/schemas/sdk-config.js +4 -0
  110. package/dist/schemas/sdk-errors-server.d.ts +2 -0
  111. package/dist/schemas/sdk-errors-server.js +12 -0
  112. package/dist/schemas/suspend.d.ts +10 -0
  113. package/dist/schemas/suspend.js +7 -0
  114. package/dist/schemas/text-to-speech.d.ts +187 -10
  115. package/dist/schemas/text-to-speech.js +12 -4
  116. package/dist/schemas/transcription-config.d.ts +16 -56
  117. package/dist/schemas/transcription-config.js +0 -2
  118. package/dist/schemas/transcription.d.ts +66 -6
  119. package/dist/schemas/transcription.js +29 -7
  120. package/dist/schemas/translate.d.ts +14 -4
  121. package/dist/schemas/translate.js +10 -2
  122. package/dist/schemas/translation-config.d.ts +30 -10
  123. package/dist/server/bare/delegate-rpc-client.js +3 -3
  124. package/dist/server/bare/hyperswarm.js +15 -3
  125. package/dist/server/bare/ops/embed.d.ts +8 -4
  126. package/dist/server/bare/ops/embed.js +15 -4
  127. package/dist/server/bare/ops/transcribe.d.ts +6 -2
  128. package/dist/server/bare/ops/transcribe.js +53 -1
  129. package/dist/server/bare/ops/translate.d.ts +4 -1
  130. package/dist/server/bare/ops/translate.js +28 -65
  131. package/dist/server/bare/ops/unload-model.js +2 -0
  132. package/dist/server/bare/plugins/index.d.ts +1 -0
  133. package/dist/server/bare/plugins/index.js +1 -0
  134. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +3 -1
  135. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +45 -9
  136. package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.d.ts +11 -0
  137. package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +112 -0
  138. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +175 -5
  139. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +45 -35
  140. package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +11 -1
  141. package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +9 -4
  142. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +17 -2
  143. package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +16 -15
  144. package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.d.ts +5 -7
  145. package/dist/server/bare/plugins/onnx-ocr/ops/ocr-stream.js +11 -3
  146. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +2 -0
  147. package/dist/server/bare/plugins/onnx-ocr/plugin.js +24 -19
  148. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +7 -2
  149. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +22 -97
  150. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +98 -9
  151. package/dist/server/bare/plugins/onnx-tts/plugin.js +85 -46
  152. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +30 -60
  153. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +49 -37
  154. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.d.ts +3 -0
  155. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +51 -0
  156. package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +278 -0
  157. package/dist/server/bare/plugins/sdcpp-generation/plugin.js +70 -0
  158. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +38 -2
  159. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +43 -22
  160. package/dist/server/bare/rag-hyperdb/handlers/ingest.js +2 -1
  161. package/dist/server/bare/rag-hyperdb/handlers/search.js +2 -1
  162. package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +7 -0
  163. package/dist/server/bare/registry/model-config-utils.js +3 -0
  164. package/dist/server/bare/registry/model-registry.d.ts +2 -2
  165. package/dist/server/bare/registry/model-registry.js +1 -1
  166. package/dist/server/bare/registry/registry-client.js +21 -0
  167. package/dist/server/bare/runtime-lifecycle.d.ts +28 -0
  168. package/dist/server/bare/runtime-lifecycle.js +132 -0
  169. package/dist/server/bare/types/addon-responses.d.ts +62 -0
  170. package/dist/server/bare/types/addon-responses.js +1 -0
  171. package/dist/server/env.js +3 -1
  172. package/dist/server/rpc/delegate-transport.js +1 -1
  173. package/dist/server/rpc/handle-request.js +50 -4
  174. package/dist/server/rpc/handler-registry.js +20 -1
  175. package/dist/server/rpc/handler-utils.d.ts +5 -3
  176. package/dist/server/rpc/handler-utils.js +52 -50
  177. package/dist/server/rpc/handlers/delete-cache.js +3 -0
  178. package/dist/server/rpc/handlers/diffusion-stream.d.ts +3 -0
  179. package/dist/server/rpc/handlers/diffusion-stream.js +4 -0
  180. package/dist/server/rpc/handlers/finetune.d.ts +3 -0
  181. package/dist/server/rpc/handlers/finetune.js +16 -0
  182. package/dist/server/rpc/handlers/index.d.ts +10 -0
  183. package/dist/server/rpc/handlers/index.js +10 -0
  184. package/dist/server/rpc/handlers/load-model/hyperdrive.js +24 -9
  185. package/dist/server/rpc/handlers/load-model/registry.d.ts +11 -0
  186. package/dist/server/rpc/handlers/load-model/registry.js +31 -4
  187. package/dist/server/rpc/handlers/plugin-dispatch.d.ts +1 -13
  188. package/dist/server/rpc/handlers/plugin-dispatch.js +21 -21
  189. package/dist/server/rpc/handlers/resume.d.ts +3 -0
  190. package/dist/server/rpc/handlers/resume.js +11 -0
  191. package/dist/server/rpc/handlers/suspend.d.ts +3 -0
  192. package/dist/server/rpc/handlers/suspend.js +11 -0
  193. package/dist/server/rpc/handlers/transcribe-stream.d.ts +1 -1
  194. package/dist/server/rpc/handlers/transcribe-stream.js +2 -2
  195. package/dist/server/rpc/handlers/transcribe.d.ts +3 -0
  196. package/dist/server/rpc/handlers/transcribe.js +4 -0
  197. package/dist/server/rpc/profiling/operation-metrics.js +107 -16
  198. package/dist/server/rpc/profiling/operation-wrappers.d.ts +1 -1
  199. package/dist/server/rpc/profiling/operation-wrappers.js +51 -19
  200. package/dist/server/rpc/progress-throttle.d.ts +8 -0
  201. package/dist/server/rpc/progress-throttle.js +47 -0
  202. package/dist/server/rpc/rpc-utils.d.ts +5 -0
  203. package/dist/server/rpc/rpc-utils.js +11 -0
  204. package/dist/server/utils/path-security.js +1 -1
  205. package/dist/server/utils/tool-integration.js +10 -0
  206. package/dist/server/utils/tool-parser.js +9 -5
  207. package/dist/server/worker-core.d.ts +2 -0
  208. package/dist/server/worker-core.js +26 -23
  209. package/dist/server/worker.js +2 -1
  210. package/dist/utils/encoding.d.ts +9 -0
  211. package/dist/utils/encoding.js +14 -0
  212. package/dist/utils/errors-server.d.ts +6 -0
  213. package/dist/utils/errors-server.js +11 -0
  214. package/package.json +36 -25
  215. package/dist/server/rpc/delegate-utils.d.ts +0 -2
  216. package/dist/server/rpc/delegate-utils.js +0 -5
@@ -3,6 +3,7 @@ import { handleDownloadAsset } from "./download-asset";
3
3
  import { handleLoadModel } from "./load-model/index";
4
4
  import { handleUnloadModel } from "./unload-model";
5
5
  import { handleEmbed } from "./embed";
6
+ import { handleTranscribe } from "./transcribe";
6
7
  import { handleTranscribeStream } from "./transcribe-stream";
7
8
  import { provideHandler } from "./provideHandler";
8
9
  import { stopProvideHandler } from "./stopProvideHandler";
@@ -13,10 +14,14 @@ import { cancelHandler } from "./cancelHandler";
13
14
  import { handleDeleteCache } from "./delete-cache";
14
15
  import { handleTextToSpeech } from "./text-to-speech";
15
16
  import { handleGetModelInfo } from "./get-model-info";
17
+ import { handleFinetune } from "./finetune";
16
18
  import { handleOCRStream } from "./ocr-stream";
17
19
  import { handleHeartbeat } from "./heartbeat";
20
+ import { handleDiffusionStream } from "./diffusion-stream";
18
21
  import { handlePluginInvoke, handlePluginInvokeStream } from "./plugin-invoke";
19
22
  import { handleModelRegistryList, handleModelRegistrySearch, handleModelRegistryGetModel } from "./registry";
23
+ import { handleSuspend } from "./suspend";
24
+ import { handleResume } from "./resume";
20
25
  export declare const handlers: {
21
26
  heartbeat: typeof handleHeartbeat;
22
27
  completionStream: typeof handleCompletionStream;
@@ -25,6 +30,7 @@ export declare const handlers: {
25
30
  loadModel: typeof handleLoadModel;
26
31
  unloadModel: typeof handleUnloadModel;
27
32
  embed: typeof handleEmbed;
33
+ transcribe: typeof handleTranscribe;
28
34
  transcribeStream: typeof handleTranscribeStream;
29
35
  provide: typeof provideHandler;
30
36
  stopProvide: typeof stopProvideHandler;
@@ -34,11 +40,15 @@ export declare const handlers: {
34
40
  cancel: typeof cancelHandler;
35
41
  textToSpeech: typeof handleTextToSpeech;
36
42
  getModelInfo: typeof handleGetModelInfo;
43
+ finetune: typeof handleFinetune;
37
44
  ocrStream: typeof handleOCRStream;
45
+ diffusionStream: typeof handleDiffusionStream;
38
46
  pluginInvoke: typeof handlePluginInvoke;
39
47
  pluginInvokeStream: typeof handlePluginInvokeStream;
40
48
  modelRegistryList: typeof handleModelRegistryList;
41
49
  modelRegistrySearch: typeof handleModelRegistrySearch;
42
50
  modelRegistryGetModel: typeof handleModelRegistryGetModel;
51
+ suspend: typeof handleSuspend;
52
+ resume: typeof handleResume;
43
53
  };
44
54
  //# sourceMappingURL=index.d.ts.map
@@ -3,6 +3,7 @@ import { handleDownloadAsset } from "./download-asset.js";
3
3
  import { handleLoadModel } from "./load-model/index.js";
4
4
  import { handleUnloadModel } from "./unload-model.js";
5
5
  import { handleEmbed } from "./embed.js";
6
+ import { handleTranscribe } from "./transcribe.js";
6
7
  import { handleTranscribeStream } from "./transcribe-stream.js";
7
8
  import { provideHandler } from "./provideHandler.js";
8
9
  import { stopProvideHandler } from "./stopProvideHandler.js";
@@ -13,10 +14,14 @@ import { cancelHandler } from "./cancelHandler.js";
13
14
  import { handleDeleteCache } from "./delete-cache.js";
14
15
  import { handleTextToSpeech } from "./text-to-speech.js";
15
16
  import { handleGetModelInfo } from "./get-model-info.js";
17
+ import { handleFinetune } from "./finetune.js";
16
18
  import { handleOCRStream } from "./ocr-stream.js";
17
19
  import { handleHeartbeat } from "./heartbeat.js";
20
+ import { handleDiffusionStream } from "./diffusion-stream.js";
18
21
  import { handlePluginInvoke, handlePluginInvokeStream } from "./plugin-invoke.js";
19
22
  import { handleModelRegistryList, handleModelRegistrySearch, handleModelRegistryGetModel, } from "./registry.js";
23
+ import { handleSuspend } from "./suspend.js";
24
+ import { handleResume } from "./resume.js";
20
25
  export const handlers = {
21
26
  heartbeat: handleHeartbeat,
22
27
  completionStream: handleCompletionStream,
@@ -25,6 +30,7 @@ export const handlers = {
25
30
  loadModel: handleLoadModel,
26
31
  unloadModel: handleUnloadModel,
27
32
  embed: handleEmbed,
33
+ transcribe: handleTranscribe,
28
34
  transcribeStream: handleTranscribeStream,
29
35
  provide: provideHandler,
30
36
  stopProvide: stopProvideHandler,
@@ -34,10 +40,14 @@ export const handlers = {
34
40
  cancel: cancelHandler,
35
41
  textToSpeech: handleTextToSpeech,
36
42
  getModelInfo: handleGetModelInfo,
43
+ finetune: handleFinetune,
37
44
  ocrStream: handleOCRStream,
45
+ diffusionStream: handleDiffusionStream,
38
46
  pluginInvoke: handlePluginInvoke,
39
47
  pluginInvokeStream: handlePluginInvokeStream,
40
48
  modelRegistryList: handleModelRegistryList,
41
49
  modelRegistrySearch: handleModelRegistrySearch,
42
50
  modelRegistryGetModel: handleModelRegistryGetModel,
51
+ suspend: handleSuspend,
52
+ resume: handleResume,
43
53
  };
@@ -12,6 +12,7 @@ import { getActiveDownload, registerDownload, unregisterDownload, createHyperdri
12
12
  import { getSDKConfig } from "../../../bare/registry/config-registry.js";
13
13
  import { FileNotFoundError, ChecksumValidationFailedError, DownloadCancelledError, HyperdriveDownloadFailedError, ModelLoadFailedError, NoBlobFoundError, } from "../../../../utils/errors-server.js";
14
14
  import { getServerLogger } from "../../../../logging/index.js";
15
+ import { registerSwarm, unregisterSwarm, registerCorestore, unregisterCorestore, } from "../../../bare/runtime-lifecycle.js";
15
16
  const logger = getServerLogger();
16
17
  function getCorestoreDir(hyperdriveKey) {
17
18
  return path.join(getEnv().HOME_DIR, ".qvac", "corestore", hyperdriveKey);
@@ -40,21 +41,35 @@ async function setupHyperdrive(hyperdriveKey, corestoreDir) {
40
41
  });
41
42
  swarm.join(drive.discoveryKey, { server: false, client: true });
42
43
  swarm.flush().then(doneFindingPeers, doneFindingPeers);
44
+ registerCorestore(corestore, {
45
+ label: `hyperdrive:${hyperdriveKey}`,
46
+ createdAt: Date.now(),
47
+ });
48
+ registerSwarm(swarm, {
49
+ label: `hyperdrive:${hyperdriveKey}`,
50
+ createdAt: Date.now(),
51
+ });
43
52
  return { corestore, drive, swarm, corestoreDir };
44
53
  }
45
54
  async function cleanupHyperdrive(setup) {
46
55
  logger.debug("🧹 Cleaning up hyperdrive setup");
47
- if (!setup.swarm.suspended) {
48
- try {
49
- await setup.swarm.suspend();
50
- }
51
- catch {
52
- // If suspend fails, continue with cleanup
56
+ try {
57
+ if (!setup.swarm.suspended) {
58
+ try {
59
+ await setup.swarm.suspend();
60
+ }
61
+ catch (error) {
62
+ logger.debug("⚠️ Swarm suspend failed during cleanup:", error instanceof Error ? error.message : String(error));
63
+ }
53
64
  }
65
+ await setup.swarm.destroy();
66
+ await setup.drive.close();
67
+ await setup.corestore.close();
68
+ }
69
+ finally {
70
+ unregisterSwarm(setup.swarm);
71
+ unregisterCorestore(setup.corestore);
54
72
  }
55
- await setup.swarm.destroy();
56
- await setup.drive.close();
57
- await setup.corestore.close();
58
73
  }
59
74
  export async function deleteCorestoreDirectory(corestoreDir) {
60
75
  logger.info(`🗑️ DELETING corestore directory... ${corestoreDir}`);
@@ -1,5 +1,16 @@
1
1
  import type { ModelProgressUpdate } from "../../../../schemas/index";
2
+ import { type RegistryItem } from "../../../../models/registry/index";
2
3
  import type { DownloadMetricsHooks } from "./types";
4
+ /**
5
+ * Find companion ONNX data file in registry.
6
+ * ONNX models with external data may use either .onnx_data or .onnx.data.
7
+ */
8
+ export declare function findOnnxCompanionDataFile(registryPath: string): RegistryItem | undefined;
9
+ /**
10
+ * Resolve the main ONNX registry path from a companion data registry path.
11
+ * Supports both .onnx_data and .onnx.data naming conventions.
12
+ */
13
+ export declare function getPairedOnnxRegistryPath(registryPath: string): string | undefined;
3
14
  /**
4
15
  * Download a model from the QVAC Registry.
5
16
  *
@@ -277,13 +277,26 @@ async function downloadShardedFilesFromRegistry(registryPath, registrySource, ca
277
277
  }
278
278
  /**
279
279
  * Find companion ONNX data file in registry.
280
- * ONNX models with external data have a .onnx file and a .onnx_data file.
280
+ * ONNX models with external data may use either .onnx_data or .onnx.data.
281
281
  */
282
- function findOnnxCompanionDataFile(registryPath) {
282
+ export function findOnnxCompanionDataFile(registryPath) {
283
283
  if (!registryPath.endsWith(".onnx"))
284
284
  return undefined;
285
- const dataPath = registryPath + "_data";
286
- return getModelByPath(dataPath);
285
+ return (getModelByPath(`${registryPath}_data`) ??
286
+ getModelByPath(`${registryPath}.data`));
287
+ }
288
+ /**
289
+ * Resolve the main ONNX registry path from a companion data registry path.
290
+ * Supports both .onnx_data and .onnx.data naming conventions.
291
+ */
292
+ export function getPairedOnnxRegistryPath(registryPath) {
293
+ if (registryPath.endsWith(".onnx_data")) {
294
+ return registryPath.slice(0, -"_data".length);
295
+ }
296
+ if (registryPath.endsWith(".onnx.data")) {
297
+ return registryPath.slice(0, -".data".length);
298
+ }
299
+ return undefined;
287
300
  }
288
301
  /**
289
302
  * Download ONNX model with companion data file from registry.
@@ -430,6 +443,20 @@ export async function downloadModelFromRegistry(registryPath, registrySource, pr
430
443
  const shardInfo = detectShardedModel(filename);
431
444
  // Look up model metadata from our generated models.ts
432
445
  const modelMetadata = getModelByPath(registryPath);
446
+ // ONNX external data: check if already present in paired ONNX cache directory.
447
+ // Avoids redundant single-file downloads when the companion .onnx download already placed it.
448
+ const pairedOnnxRegistryPath = getPairedOnnxRegistryPath(registryPath);
449
+ if (pairedOnnxRegistryPath) {
450
+ const onnxRegistryPath = pairedOnnxRegistryPath;
451
+ const onnxCacheKey = generateShortHash(onnxRegistryPath);
452
+ const pairedPath = getOnnxModelPath(onnxCacheKey, filename);
453
+ const validated = await validateCachedFile(pairedPath, filename, modelMetadata?.expectedSize || 0, modelMetadata?.sha256Checksum, hooks);
454
+ if (validated) {
455
+ logger.info(`✅ ONNX data file found in paired cache: ${validated}`);
456
+ hooks?.markCacheHit();
457
+ return validated;
458
+ }
459
+ }
433
460
  if (shardInfo.isSharded) {
434
461
  const cacheKey = generateShortHash(registryPath);
435
462
  const localShardMeta = modelMetadata?.shardMetadata;
@@ -1,15 +1,3 @@
1
- /**
2
- * Dispatches a request to a plugin handler and returns a Promise.
3
- * Use for non-streaming (reply) handlers.
4
- *
5
- * @throws PluginHandlerTypeMismatchError if the handler is streaming
6
- */
7
1
  export declare function dispatchPluginReply<TRequest, TResponse>(modelId: string, handlerName: string, request: TRequest): Promise<TResponse>;
8
- /**
9
- * Dispatches a request to a plugin handler and returns an AsyncGenerator.
10
- * Use for streaming handlers.
11
- *
12
- * @throws PluginHandlerTypeMismatchError if the handler is not streaming
13
- */
14
- export declare function dispatchPluginStream<TRequest, TResponse>(modelId: string, handlerName: string, request: TRequest): AsyncGenerator<TResponse>;
2
+ export declare function dispatchPluginStream<TRequest, TResponse>(modelId: string, handlerName: string, request: TRequest, inputStream?: AsyncIterable<Buffer>): AsyncGenerator<TResponse>;
15
3
  //# sourceMappingURL=plugin-dispatch.d.ts.map
@@ -2,10 +2,7 @@ import { getModelEntry } from "../../bare/registry/model-registry.js";
2
2
  import { getPlugin } from "../../plugins/index.js";
3
3
  import { profileReplyHandler, profileStreamHandler, } from "../profiling/index.js";
4
4
  import { ModelNotFoundError, ModelIsDelegatedError, PluginNotFoundError, PluginHandlerNotFoundError, PluginHandlerTypeMismatchError, } from "../../../utils/errors-server.js";
5
- /**
6
- * Resolves the plugin handler and returns both the result and streaming flag.
7
- */
8
- function resolvePluginHandler(modelId, handlerName, request) {
5
+ function resolvePluginHandlerDef(modelId, handlerName) {
9
6
  const entry = getModelEntry(modelId);
10
7
  if (!entry) {
11
8
  throw new ModelNotFoundError(modelId);
@@ -22,17 +19,15 @@ function resolvePluginHandler(modelId, handlerName, request) {
22
19
  const availableHandlers = Object.keys(plugin.handlers);
23
20
  throw new PluginHandlerNotFoundError(entry.local.modelType, handlerName, availableHandlers);
24
21
  }
22
+ return handlerDef;
23
+ }
24
+ function resolvePluginHandler(modelId, handlerName, request) {
25
+ const handlerDef = resolvePluginHandlerDef(modelId, handlerName);
25
26
  return {
26
27
  result: handlerDef.handler(request),
27
28
  streaming: handlerDef.streaming,
28
29
  };
29
30
  }
30
- /**
31
- * Dispatches a request to a plugin handler and returns a Promise.
32
- * Use for non-streaming (reply) handlers.
33
- *
34
- * @throws PluginHandlerTypeMismatchError if the handler is streaming
35
- */
36
31
  export async function dispatchPluginReply(modelId, handlerName, request) {
37
32
  return profileReplyHandler({ op: handlerName, request }, async () => {
38
33
  const { result, streaming } = resolvePluginHandler(modelId, handlerName, request);
@@ -42,18 +37,23 @@ export async function dispatchPluginReply(modelId, handlerName, request) {
42
37
  return result;
43
38
  });
44
39
  }
45
- /**
46
- * Dispatches a request to a plugin handler and returns an AsyncGenerator.
47
- * Use for streaming handlers.
48
- *
49
- * @throws PluginHandlerTypeMismatchError if the handler is not streaming
50
- */
51
- export async function* dispatchPluginStream(modelId, handlerName, request) {
40
+ export async function* dispatchPluginStream(modelId, handlerName, request, inputStream) {
52
41
  yield* profileStreamHandler({ op: handlerName, request }, async function* () {
53
- const { result, streaming } = resolvePluginHandler(modelId, handlerName, request);
54
- if (!streaming) {
55
- throw new PluginHandlerTypeMismatchError(handlerName, "streaming", "reply");
42
+ const handlerDef = resolvePluginHandlerDef(modelId, handlerName);
43
+ if (inputStream) {
44
+ if (!handlerDef.duplex) {
45
+ throw new PluginHandlerTypeMismatchError(handlerName, "duplex", handlerDef.streaming ? "streaming" : "reply");
46
+ }
47
+ yield* handlerDef.handler(request, inputStream);
48
+ }
49
+ else {
50
+ if (handlerDef.duplex) {
51
+ throw new PluginHandlerTypeMismatchError(handlerName, "streaming", "duplex");
52
+ }
53
+ if (!handlerDef.streaming) {
54
+ throw new PluginHandlerTypeMismatchError(handlerName, "streaming", "reply");
55
+ }
56
+ yield* handlerDef.handler(request);
56
57
  }
57
- yield* result;
58
58
  });
59
59
  }
@@ -0,0 +1,3 @@
1
+ import type { ResumeResponse } from "../../../schemas/index";
2
+ export declare function handleResume(): Promise<ResumeResponse>;
3
+ //# sourceMappingURL=resume.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { resumeRuntime } from "../../bare/runtime-lifecycle.js";
2
+ import { LifecycleResumeFailedError } from "../../../utils/errors-server.js";
3
+ export async function handleResume() {
4
+ try {
5
+ await resumeRuntime();
6
+ return { type: "resume" };
7
+ }
8
+ catch (error) {
9
+ throw new LifecycleResumeFailedError(error instanceof Error ? error.message : String(error), error);
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ import type { SuspendResponse } from "../../../schemas/index";
2
+ export declare function handleSuspend(): Promise<SuspendResponse>;
3
+ //# sourceMappingURL=suspend.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { suspendRuntime } from "../../bare/runtime-lifecycle.js";
2
+ import { LifecycleSuspendFailedError } from "../../../utils/errors-server.js";
3
+ export async function handleSuspend() {
4
+ try {
5
+ await suspendRuntime();
6
+ return { type: "suspend" };
7
+ }
8
+ catch (error) {
9
+ throw new LifecycleSuspendFailedError(error instanceof Error ? error.message : String(error), error);
10
+ }
11
+ }
@@ -1,3 +1,3 @@
1
1
  import type { TranscribeStreamRequest, TranscribeStreamResponse } from "../../../schemas/index";
2
- export declare function handleTranscribeStream(request: TranscribeStreamRequest): AsyncGenerator<TranscribeStreamResponse>;
2
+ export declare function handleTranscribeStream(request: TranscribeStreamRequest, inputStream: AsyncIterable<Buffer>): AsyncGenerator<TranscribeStreamResponse>;
3
3
  //# sourceMappingURL=transcribe-stream.d.ts.map
@@ -1,4 +1,4 @@
1
1
  import { dispatchPluginStream } from "./plugin-dispatch.js";
2
- export async function* handleTranscribeStream(request) {
3
- yield* dispatchPluginStream(request.modelId, "transcribeStream", request);
2
+ export async function* handleTranscribeStream(request, inputStream) {
3
+ yield* dispatchPluginStream(request.modelId, "transcribeStream", request, inputStream);
4
4
  }
@@ -0,0 +1,3 @@
1
+ import type { TranscribeRequest, TranscribeResponse } from "../../../schemas/index";
2
+ export declare function handleTranscribe(request: TranscribeRequest): AsyncGenerator<TranscribeResponse>;
3
+ //# sourceMappingURL=transcribe.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { dispatchPluginStream } from "./plugin-dispatch.js";
2
+ export async function* handleTranscribe(request) {
3
+ yield* dispatchPluginStream(request.modelId, "transcribe", request);
4
+ }
@@ -2,6 +2,8 @@
2
2
  * Declarative extraction of operation-level metrics from request/response data.
3
3
  * Used by operation wrappers to capture handler-specific profiling events.
4
4
  */
5
+ import {} from "../../../schemas/index.js";
6
+ import { readModelExecutionMs } from "../../../profiling/model-execution.js";
5
7
  const metricsRegistry = new Map();
6
8
  function extractDownloadStatsGauges(stats, gauges) {
7
9
  if (stats?.downloadTimeMs !== undefined) {
@@ -72,15 +74,16 @@ registerOperationMetrics({
72
74
  kind: "handler",
73
75
  getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
74
76
  fromFinalChunk: (res) => {
75
- if (!res.stats)
76
- return undefined;
77
77
  const gauges = {};
78
- if (res.stats.timeToFirstToken !== undefined)
78
+ if (res.stats?.timeToFirstToken !== undefined)
79
79
  gauges["timeToFirstToken"] = res.stats.timeToFirstToken;
80
- if (res.stats.tokensPerSecond !== undefined)
80
+ if (res.stats?.tokensPerSecond !== undefined)
81
81
  gauges["tokensPerSecond"] = res.stats.tokensPerSecond;
82
- if (res.stats.cacheTokens !== undefined)
82
+ if (res.stats?.cacheTokens !== undefined)
83
83
  gauges["cacheTokens"] = res.stats.cacheTokens;
84
+ const modelExecMs = readModelExecutionMs(res);
85
+ if (modelExecMs !== undefined)
86
+ gauges["modelExecutionTime"] = modelExecMs;
84
87
  return Object.keys(gauges).length > 0 ? gauges : undefined;
85
88
  },
86
89
  });
@@ -89,13 +92,27 @@ registerOperationMetrics({
89
92
  kind: "handler",
90
93
  getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
91
94
  fromFinalChunk: (res) => {
92
- if (!res.stats)
93
- return undefined;
94
95
  const gauges = {};
95
- if (res.stats.processedTokens !== undefined)
96
- gauges["processedTokens"] = res.stats.processedTokens;
97
- if (res.stats.processingTime !== undefined)
98
- gauges["processingTime"] = res.stats.processingTime;
96
+ const modelExecMs = readModelExecutionMs(res);
97
+ if (modelExecMs !== undefined)
98
+ gauges["modelExecutionTime"] = modelExecMs;
99
+ // Common stats
100
+ if (res.stats?.totalTime !== undefined)
101
+ gauges["totalTime"] = res.stats.totalTime;
102
+ if (res.stats?.totalTokens !== undefined)
103
+ gauges["totalTokens"] = res.stats.totalTokens;
104
+ if (res.stats?.tokensPerSecond !== undefined)
105
+ gauges["tokensPerSecond"] = res.stats.tokensPerSecond;
106
+ if (res.stats?.timeToFirstToken !== undefined)
107
+ gauges["timeToFirstToken"] = res.stats.timeToFirstToken;
108
+ // NMT-specific
109
+ if (res.stats?.decodeTime !== undefined)
110
+ gauges["decodeTime"] = res.stats.decodeTime;
111
+ if (res.stats?.encodeTime !== undefined)
112
+ gauges["encodeTime"] = res.stats.encodeTime;
113
+ // LLM-specific
114
+ if (res.stats?.cacheTokens !== undefined)
115
+ gauges["cacheTokens"] = res.stats.cacheTokens;
99
116
  return Object.keys(gauges).length > 0 ? gauges : undefined;
100
117
  },
101
118
  });
@@ -103,31 +120,105 @@ registerOperationMetrics({
103
120
  op: "transcribeStream",
104
121
  kind: "handler",
105
122
  getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
123
+ fromFinalChunk: (res) => {
124
+ const gauges = {};
125
+ const modelExecMs = readModelExecutionMs(res);
126
+ if (modelExecMs !== undefined)
127
+ gauges["modelExecutionTime"] = modelExecMs;
128
+ // Common stats
129
+ if (res.stats?.audioDuration !== undefined)
130
+ gauges["audioDuration"] = res.stats.audioDuration;
131
+ if (res.stats?.realTimeFactor !== undefined)
132
+ gauges["realTimeFactor"] = res.stats.realTimeFactor;
133
+ if (res.stats?.tokensPerSecond !== undefined)
134
+ gauges["tokensPerSecond"] = res.stats.tokensPerSecond;
135
+ if (res.stats?.totalTokens !== undefined)
136
+ gauges["totalTokens"] = res.stats.totalTokens;
137
+ if (res.stats?.totalSegments !== undefined)
138
+ gauges["totalSegments"] = res.stats.totalSegments;
139
+ // whisper-specific timings
140
+ if (res.stats?.whisperEncodeTime !== undefined)
141
+ gauges["whisperEncodeTime"] = res.stats.whisperEncodeTime;
142
+ if (res.stats?.whisperDecodeTime !== undefined)
143
+ gauges["whisperDecodeTime"] = res.stats.whisperDecodeTime;
144
+ // parakeet-specific timings
145
+ if (res.stats?.encoderTime !== undefined)
146
+ gauges["encoderTime"] = res.stats.encoderTime;
147
+ if (res.stats?.decoderTime !== undefined)
148
+ gauges["decoderTime"] = res.stats.decoderTime;
149
+ if (res.stats?.melSpecTime !== undefined)
150
+ gauges["melSpecTime"] = res.stats.melSpecTime;
151
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
152
+ },
106
153
  });
107
154
  registerOperationMetrics({
108
155
  op: "textToSpeech",
109
156
  kind: "handler",
110
157
  getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
158
+ fromFinalChunk: (res) => {
159
+ const gauges = {};
160
+ const modelExecMs = readModelExecutionMs(res);
161
+ if (modelExecMs !== undefined)
162
+ gauges["modelExecutionTime"] = modelExecMs;
163
+ if (res.stats?.audioDuration !== undefined)
164
+ gauges["audioDuration"] = res.stats.audioDuration;
165
+ if (res.stats?.totalSamples !== undefined)
166
+ gauges["totalSamples"] = res.stats.totalSamples;
167
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
168
+ },
111
169
  });
112
170
  registerOperationMetrics({
113
171
  op: "embed",
114
172
  kind: "handler",
115
173
  getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
174
+ fromResult: (res) => {
175
+ const gauges = {};
176
+ const modelExecMs = readModelExecutionMs(res);
177
+ if (modelExecMs !== undefined)
178
+ gauges["modelExecutionTime"] = modelExecMs;
179
+ if (res.stats?.totalTime !== undefined)
180
+ gauges["totalTime"] = res.stats.totalTime;
181
+ if (res.stats?.tokensPerSecond !== undefined)
182
+ gauges["tokensPerSecond"] = res.stats.tokensPerSecond;
183
+ if (res.stats?.totalTokens !== undefined)
184
+ gauges["totalTokens"] = res.stats.totalTokens;
185
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
186
+ },
116
187
  });
117
188
  registerOperationMetrics({
118
189
  op: "ocrStream",
119
190
  kind: "handler",
120
191
  getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
121
192
  fromFinalChunk: (res) => {
122
- if (!res.stats)
123
- return undefined;
124
193
  const gauges = {};
125
- if (res.stats.detectionTime !== undefined)
194
+ if (res.stats?.detectionTime !== undefined)
126
195
  gauges["detectionTime"] = res.stats.detectionTime;
127
- if (res.stats.recognitionTime !== undefined)
196
+ if (res.stats?.recognitionTime !== undefined)
128
197
  gauges["recognitionTime"] = res.stats.recognitionTime;
129
- if (res.stats.totalTime !== undefined)
198
+ if (res.stats?.totalTime !== undefined)
130
199
  gauges["totalTime"] = res.stats.totalTime;
200
+ const modelExecMs = readModelExecutionMs(res);
201
+ if (modelExecMs !== undefined)
202
+ gauges["modelExecutionTime"] = modelExecMs;
203
+ return Object.keys(gauges).length > 0 ? gauges : undefined;
204
+ },
205
+ });
206
+ registerOperationMetrics({
207
+ op: "diffusionStream",
208
+ kind: "handler",
209
+ getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
210
+ fromFinalChunk: (res) => {
211
+ if (!res.stats)
212
+ return undefined;
213
+ const gauges = {};
214
+ if (res.stats.generationMs !== undefined)
215
+ gauges["generationMs"] = res.stats.generationMs;
216
+ if (res.stats.totalSteps !== undefined)
217
+ gauges["totalSteps"] = res.stats.totalSteps;
218
+ if (res.stats.totalImages !== undefined)
219
+ gauges["totalImages"] = res.stats.totalImages;
220
+ if (res.stats.totalPixels !== undefined)
221
+ gauges["totalPixels"] = res.stats.totalPixels;
131
222
  return Object.keys(gauges).length > 0 ? gauges : undefined;
132
223
  },
133
224
  });
@@ -14,5 +14,5 @@ export interface ProfiledStreamOptions<TRequest> {
14
14
  perCall?: PerCallProfiling;
15
15
  }
16
16
  export declare function profileReplyHandler<TRequest, TResponse>(options: ProfiledReplyOptions<TRequest>, handler: () => Promise<TResponse>): Promise<TResponse>;
17
- export declare function profileStreamHandler<TRequest, TResponse>(options: ProfiledStreamOptions<TRequest>, handler: () => AsyncGenerator<TResponse>): AsyncGenerator<TResponse>;
17
+ export declare function profileStreamHandler<TRequest, TResponse, TReturn = unknown>(options: ProfiledStreamOptions<TRequest>, handler: () => AsyncGenerator<TResponse, TReturn>): AsyncGenerator<TResponse, TReturn>;
18
18
  //# sourceMappingURL=operation-wrappers.d.ts.map