@qvac/sdk 0.22.0 → 0.24.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 (284) hide show
  1. package/NOTICE +194 -97
  2. package/README.md +29 -470
  3. package/dist/examples/asr/parakeet-sortformer.js +24 -14
  4. package/dist/examples/asr/parakeet-transcribepsy-filesystem.d.ts +2 -0
  5. package/dist/examples/asr/parakeet-transcribepsy-filesystem.js +105 -0
  6. package/dist/examples/asr/parakeet-unified-coreml.js +14 -9
  7. package/dist/examples/asr/whispercpp-prompt.js +9 -5
  8. package/dist/examples/assess-model-fit.d.ts +7 -9
  9. package/dist/examples/assess-model-fit.js +22 -43
  10. package/dist/examples/calc-tokens.d.ts +2 -0
  11. package/dist/examples/calc-tokens.js +21 -0
  12. package/dist/examples/classification/classify-image.js +11 -5
  13. package/dist/examples/completion-stop-reason.d.ts +3 -3
  14. package/dist/examples/completion-stop-reason.js +4 -4
  15. package/dist/examples/diffusion-flux3-klein.d.ts +2 -0
  16. package/dist/examples/diffusion-flux3-klein.js +102 -0
  17. package/dist/examples/diffusion-img2vid-ltx.js +7 -14
  18. package/dist/examples/diffusion-moss-image.d.ts +2 -0
  19. package/dist/examples/diffusion-moss-image.js +126 -0
  20. package/dist/examples/diffusion-qwen-image-21.d.ts +2 -0
  21. package/dist/examples/diffusion-qwen-image-21.js +115 -0
  22. package/dist/examples/diffusion-txt2vid-ltx.js +7 -14
  23. package/dist/examples/embed-multimodal.d.ts +2 -0
  24. package/dist/examples/embed-multimodal.js +80 -0
  25. package/dist/examples/embed-p2p.js +2 -2
  26. package/dist/examples/finetune/llamacpp-finetune.js +9 -4
  27. package/dist/examples/image/megaloc.d.ts +2 -0
  28. package/dist/examples/image/megaloc.js +37 -0
  29. package/dist/examples/llamacpp-multimodal.js +21 -1
  30. package/dist/examples/mcp-websearch.js +1 -1
  31. package/dist/examples/plugins.js +1 -1
  32. package/dist/examples/rag/rag-hyperdb/pipeline.js +2 -2
  33. package/dist/examples/rag/rag-turbovec.js +2 -2
  34. package/dist/examples/rerank.d.ts +2 -0
  35. package/dist/examples/rerank.js +33 -0
  36. package/dist/examples/sessions.d.ts +17 -0
  37. package/dist/examples/sessions.js +63 -0
  38. package/dist/examples/tools/llamacpp-deferred-tools.js +12 -8
  39. package/dist/examples/tools/llamacpp-tools-auto-dialect.js +4 -3
  40. package/dist/examples/tools/llamacpp-tools-gemma4.js +3 -3
  41. package/dist/examples/tools/llamacpp-tools-qwen35.js +4 -3
  42. package/dist/scripts/check-resource-collectors-packaging.js +7 -6
  43. package/dist/scripts/contract/build-contract.d.ts +2 -1
  44. package/dist/scripts/contract/build-contract.js +13 -1
  45. package/dist/scripts/contract/constants-registry.d.ts +19 -0
  46. package/dist/scripts/contract/constants-registry.js +9 -2
  47. package/dist/scripts/contract/method-shapes.d.ts +5 -0
  48. package/dist/scripts/contract/method-shapes.js +5 -0
  49. package/dist/scripts/enforce-inference-versions.d.ts +1 -1
  50. package/dist/scripts/enforce-inference-versions.js +28 -18
  51. package/dist/scripts/generate-bare-kit-runtimes.js +101 -69
  52. package/dist/src/client/api/assess-model-fit.d.ts +17 -17
  53. package/dist/src/client/api/assess-model-fit.js +19 -32
  54. package/dist/src/client/api/audio-edit.d.ts +5 -3
  55. package/dist/src/client/api/audio-edit.js +7 -5
  56. package/dist/src/client/api/audio-gen-result.js +136 -47
  57. package/dist/src/client/api/audio-gen.d.ts +40 -3
  58. package/dist/src/client/api/audio-gen.js +42 -5
  59. package/dist/src/client/api/audio-understand.d.ts +2 -2
  60. package/dist/src/client/api/audio-understand.js +4 -4
  61. package/dist/src/client/api/batch-completion.js +4 -3
  62. package/dist/src/client/api/bci-transcribe.js +3 -3
  63. package/dist/src/client/api/calc-tokens.d.ts +33 -0
  64. package/dist/src/client/api/calc-tokens.js +44 -0
  65. package/dist/src/client/api/cancel.d.ts +2 -2
  66. package/dist/src/client/api/cancel.js +3 -3
  67. package/dist/src/client/api/classify.d.ts +12 -5
  68. package/dist/src/client/api/classify.js +18 -6
  69. package/dist/src/client/api/client-request-id.d.ts +0 -15
  70. package/dist/src/client/api/client-request-id.js +15 -12
  71. package/dist/src/client/api/completion-stream.d.ts +9 -1
  72. package/dist/src/client/api/completion-stream.js +14 -3
  73. package/dist/src/client/api/decide.d.ts +1 -1
  74. package/dist/src/client/api/decide.js +3 -3
  75. package/dist/src/client/api/delete-cache.d.ts +9 -2
  76. package/dist/src/client/api/delete-cache.js +14 -4
  77. package/dist/src/client/api/diffusion.d.ts +38 -5
  78. package/dist/src/client/api/diffusion.js +42 -7
  79. package/dist/src/client/api/download-asset.js +3 -3
  80. package/dist/src/client/api/embed.d.ts +82 -29
  81. package/dist/src/client/api/embed.js +66 -21
  82. package/dist/src/client/api/finetune.js +3 -3
  83. package/dist/src/client/api/get-loaded-model-info.js +1 -1
  84. package/dist/src/client/api/get-model-info.d.ts +2 -2
  85. package/dist/src/client/api/get-model-info.js +3 -3
  86. package/dist/src/client/api/get-system-resources.d.ts +2 -2
  87. package/dist/src/client/api/get-system-resources.js +3 -3
  88. package/dist/src/client/api/heartbeat.d.ts +3 -2
  89. package/dist/src/client/api/heartbeat.js +4 -3
  90. package/dist/src/client/api/index.d.ts +8 -6
  91. package/dist/src/client/api/index.js +6 -4
  92. package/dist/src/client/api/invoke-plugin.d.ts +8 -2
  93. package/dist/src/client/api/invoke-plugin.js +18 -3
  94. package/dist/src/client/api/load-model.js +9 -6
  95. package/dist/src/client/api/logging-stream.d.ts +11 -2
  96. package/dist/src/client/api/logging-stream.js +12 -3
  97. package/dist/src/client/api/ocr.d.ts +5 -3
  98. package/dist/src/client/api/ocr.js +45 -22
  99. package/dist/src/client/api/rag.d.ts +1 -1
  100. package/dist/src/client/api/rag.js +3 -3
  101. package/dist/src/client/api/registry.d.ts +19 -8
  102. package/dist/src/client/api/registry.js +43 -17
  103. package/dist/src/client/api/rerank.d.ts +22 -0
  104. package/dist/src/client/api/rerank.js +39 -0
  105. package/dist/src/client/api/resume.d.ts +2 -1
  106. package/dist/src/client/api/resume.js +3 -3
  107. package/dist/src/client/api/rpc-server.d.ts +4 -4
  108. package/dist/src/client/api/rpc-server.js +12 -12
  109. package/dist/src/client/api/state.d.ts +2 -2
  110. package/dist/src/client/api/state.js +3 -3
  111. package/dist/src/client/api/subscribe-logs.d.ts +2 -2
  112. package/dist/src/client/api/subscribe-logs.js +4 -3
  113. package/dist/src/client/api/suspend.d.ts +4 -2
  114. package/dist/src/client/api/suspend.js +5 -4
  115. package/dist/src/client/api/text-to-speech.d.ts +14 -5
  116. package/dist/src/client/api/text-to-speech.js +86 -32
  117. package/dist/src/client/api/transcribe.d.ts +7 -3
  118. package/dist/src/client/api/transcribe.js +9 -3
  119. package/dist/src/client/api/translate.js +2 -2
  120. package/dist/src/client/api/unload-model.d.ts +19 -7
  121. package/dist/src/client/api/unload-model.js +31 -13
  122. package/dist/src/client/api/upscale.d.ts +6 -3
  123. package/dist/src/client/api/upscale.js +10 -5
  124. package/dist/src/client/api/vector-index.d.ts +51 -17
  125. package/dist/src/client/api/vector-index.js +101 -49
  126. package/dist/src/client/api/video-request.d.ts +5 -5
  127. package/dist/src/client/api/video.d.ts +3 -2
  128. package/dist/src/client/api/video.js +6 -5
  129. package/dist/src/client/api/vla.d.ts +9 -5
  130. package/dist/src/client/api/vla.js +17 -8
  131. package/dist/src/client/api/world-result.js +2 -2
  132. package/dist/src/client/api/world.d.ts +6 -6
  133. package/dist/src/client/api/world.js +6 -6
  134. package/dist/src/client/init-hooks.d.ts +6 -4
  135. package/dist/src/client/init-hooks.js +12 -15
  136. package/dist/src/client/logging-stream-registry.d.ts +6 -3
  137. package/dist/src/client/logging-stream-registry.js +36 -14
  138. package/dist/src/client/plugins-factory.d.ts +1 -1
  139. package/dist/src/client/plugins-factory.js +1 -1
  140. package/dist/src/client/rpc/bundle-stamp.d.ts +29 -0
  141. package/dist/src/client/rpc/bundle-stamp.js +75 -0
  142. package/dist/src/client/rpc/expo-home-dir.d.ts +2 -0
  143. package/dist/src/client/rpc/expo-home-dir.js +4 -0
  144. package/dist/src/client/rpc/expo-rpc-client.js +192 -138
  145. package/dist/src/client/rpc/node-rpc-client.js +324 -426
  146. package/dist/src/client/rpc/pear-runtime.d.ts +12 -0
  147. package/dist/src/client/rpc/pear-runtime.js +12 -0
  148. package/dist/src/client/rpc/rpc-client.d.ts +6 -4
  149. package/dist/src/client/rpc/rpc-client.js +168 -31
  150. package/dist/src/client/rpc/rpc-error.js +24 -2
  151. package/dist/src/client/rpc/unbundled-harness.d.ts +16 -0
  152. package/dist/src/client/rpc/unbundled-harness.js +27 -0
  153. package/dist/src/client/rpc/worker-failure.d.ts +27 -0
  154. package/dist/src/client/rpc/worker-failure.js +61 -0
  155. package/dist/src/client/session-registry.d.ts +75 -0
  156. package/dist/src/client/session-registry.js +149 -0
  157. package/dist/src/client/session.d.ts +125 -0
  158. package/dist/src/client/session.js +148 -0
  159. package/dist/src/commands/bundle/addons.d.ts +14 -0
  160. package/dist/src/commands/bundle/addons.js +65 -0
  161. package/dist/src/commands/bundle/constants.js +2 -0
  162. package/dist/src/commands/bundle/entry-gen.d.ts +1 -5
  163. package/dist/src/commands/bundle/entry-gen.js +18 -51
  164. package/dist/src/commands/bundle/index.d.ts +60 -14
  165. package/dist/src/commands/bundle/index.js +350 -126
  166. package/dist/src/commands/bundle/link.d.ts +58 -0
  167. package/dist/src/commands/bundle/link.js +135 -0
  168. package/dist/src/commands/bundle/node-support.d.ts +13 -0
  169. package/dist/src/commands/bundle/node-support.js +23 -0
  170. package/dist/src/commands/bundle/plugins.js +1 -1
  171. package/dist/src/commands/bundle/read-bundle.d.ts +9 -0
  172. package/dist/src/commands/bundle/read-bundle.js +27 -0
  173. package/dist/src/commands/bundle/resolve-sdk-import.d.ts +6 -0
  174. package/dist/src/commands/bundle/resolve-sdk-import.js +24 -28
  175. package/dist/src/commands/bundle/scratch.d.ts +35 -0
  176. package/dist/src/commands/bundle/scratch.js +178 -0
  177. package/dist/src/commands/bundle/targets.d.ts +14 -0
  178. package/dist/src/commands/bundle/targets.js +37 -0
  179. package/dist/src/commands/host-prebuilds/index.d.ts +8 -7
  180. package/dist/src/commands/host-prebuilds/index.js +13 -11
  181. package/dist/src/commands/index.d.ts +13 -12
  182. package/dist/src/commands/index.js +7 -7
  183. package/dist/src/commands/verify/abi.d.ts +21 -15
  184. package/dist/src/commands/verify/abi.js +12 -80
  185. package/dist/src/commands/verify/bare-kit-runtime.d.ts +20 -22
  186. package/dist/src/commands/verify/bare-kit-runtime.js +102 -150
  187. package/dist/src/commands/verify/bare-kit-runtimes.d.ts +10 -9
  188. package/dist/src/commands/verify/bare-kit-runtimes.js +21 -21
  189. package/dist/src/commands/verify/bundle-source.d.ts +1 -1
  190. package/dist/src/commands/verify/bundle-source.js +27 -23
  191. package/dist/src/commands/verify/engines-advice.d.ts +6 -12
  192. package/dist/src/commands/verify/engines-advice.js +9 -56
  193. package/dist/src/commands/verify/index.d.ts +34 -33
  194. package/dist/src/commands/verify/index.js +96 -204
  195. package/dist/src/commands/verify/node-modules-source.d.ts +1 -1
  196. package/dist/src/commands/verify/node-modules-source.js +1 -1
  197. package/dist/src/commands/verify/prebuilds.d.ts +4 -6
  198. package/dist/src/commands/verify/prebuilds.js +3 -4
  199. package/dist/src/commands/verify/resource-collectors.d.ts +0 -6
  200. package/dist/src/commands/verify/resource-collectors.js +3 -52
  201. package/dist/src/commands/verify/sidecar-runtime.d.ts +6 -0
  202. package/dist/src/commands/verify/sidecar-runtime.js +51 -0
  203. package/dist/src/expo/plugins/get-project-root.d.ts +1 -1
  204. package/dist/src/expo/plugins/withAndroidArchitecture.d.ts +1 -1
  205. package/dist/src/expo/plugins/withAndroidNdkVersion.d.ts +1 -1
  206. package/dist/src/expo/plugins/withAndroidNdkVersion.js +16 -10
  207. package/dist/src/expo/plugins/withBareKit.d.ts +59 -0
  208. package/dist/src/expo/plugins/withBareKit.js +204 -0
  209. package/dist/src/expo/plugins/withDeviceInfo.d.ts +1 -1
  210. package/dist/src/expo/plugins/withDeviceInfo.js +19 -5
  211. package/dist/src/expo/plugins/withMobileBundle.d.ts +5 -12
  212. package/dist/src/expo/plugins/withMobileBundle.js +38 -59
  213. package/dist/src/expo/plugins/withOpenCL.d.ts +1 -1
  214. package/dist/src/expo/plugins/withQvacSDK.d.ts +2 -1
  215. package/dist/src/expo/plugins/withQvacSDK.js +3 -0
  216. package/dist/src/index.d.ts +6 -5
  217. package/dist/src/index.js +10 -14
  218. package/dist/src/logging/addon.d.ts +1 -1
  219. package/dist/src/logging/base-logger.js +1 -1
  220. package/dist/src/logging/utils.js +11 -3
  221. package/dist/src/plugin-ids.d.ts +3 -1
  222. package/dist/src/plugin-ids.js +4 -0
  223. package/dist/src/schemas/public.d.ts +1 -1
  224. package/dist/src/schemas/public.js +1 -1
  225. package/dist/src/schemas/sdk-errors-client.d.ts +5 -6
  226. package/dist/src/schemas/sdk-errors-client.js +30 -36
  227. package/dist/src/schemas/sdk-errors-server.d.ts +12 -1
  228. package/dist/src/schemas/sdk-errors-server.js +65 -2
  229. package/dist/src/server/rpc/rpc-utils.d.ts +26 -0
  230. package/dist/src/server/rpc/rpc-utils.js +41 -0
  231. package/dist/src/utils/aggregate-events.d.ts +1 -1
  232. package/dist/src/utils/aggregate-events.js +2 -2
  233. package/dist/src/utils/errors-client.d.ts +37 -29
  234. package/dist/src/utils/errors-client.js +50 -41
  235. package/dist/src/utils/errors-server.d.ts +65 -1
  236. package/dist/src/utils/errors-server.js +122 -1
  237. package/dist/src/utils/mcp-adapter.d.ts +1 -1
  238. package/dist/src/utils/mcp-adapter.js +1 -1
  239. package/dist/src/utils/tool-helpers.js +1 -1
  240. package/dist/src/utils/withTimeout.js +34 -17
  241. package/dist/src/worker/handle-request.js +26 -21
  242. package/dist/src/worker/handler-utils.d.ts +2 -6
  243. package/dist/src/worker/handler-utils.js +2 -20
  244. package/dist/src/worker/index.d.ts +2 -4
  245. package/dist/src/worker/index.js +24 -34
  246. package/dist/src/worker/plugins/ggml-image-embedding.d.ts +2 -0
  247. package/dist/src/worker/plugins/ggml-image-embedding.js +1 -0
  248. package/dist/src/worker/plugins/llamacpp-rerank.d.ts +2 -0
  249. package/dist/src/worker/plugins/llamacpp-rerank.js +1 -0
  250. package/dist/src/worker/shim.d.ts +4 -0
  251. package/dist/src/worker/shim.js +7 -0
  252. package/dist/src/worker/start.d.ts +9 -0
  253. package/dist/src/worker/start.js +16 -0
  254. package/dist/src/worker/unbundled-shim.d.ts +2 -0
  255. package/dist/src/worker/unbundled-shim.js +4 -0
  256. package/docs/system-resources-support-matrix.md +27 -19
  257. package/package.json +91 -74
  258. package/src/electron-forge/index.cjs +65 -91
  259. package/dist/examples/model-fit-ui/server.d.ts +0 -24
  260. package/dist/examples/model-fit-ui/server.js +0 -221
  261. package/dist/src/client/rpc/ensure-worker-ready.d.ts +0 -9
  262. package/dist/src/client/rpc/ensure-worker-ready.js +0 -17
  263. package/dist/src/client/rpc/init-timeout.d.ts +0 -26
  264. package/dist/src/client/rpc/init-timeout.js +0 -25
  265. package/dist/src/client/rpc/worker-startup-error.d.ts +0 -12
  266. package/dist/src/client/rpc/worker-startup-error.js +0 -13
  267. package/dist/src/commands/bundle/bare-pack.d.ts +0 -21
  268. package/dist/src/commands/bundle/bare-pack.js +0 -77
  269. package/dist/src/commands/bundle/manifest.d.ts +0 -25
  270. package/dist/src/commands/bundle/manifest.js +0 -192
  271. package/dist/src/expo/plugins/link-addons.d.ts +0 -18
  272. package/dist/src/expo/plugins/link-addons.js +0 -65
  273. package/dist/src/pear/pre.d.ts +0 -21
  274. package/dist/src/pear/pre.js +0 -448
  275. package/dist/src/server/env.d.ts +0 -22
  276. package/dist/src/server/env.js +0 -59
  277. package/dist/src/server/utils/qvac-paths.d.ts +0 -2
  278. package/dist/src/server/utils/qvac-paths.js +0 -5
  279. package/dist/src/server/utils/worker-lock.d.ts +0 -3
  280. package/dist/src/server/utils/worker-lock.js +0 -67
  281. package/dist/src/worker/create-server.d.ts +0 -8
  282. package/dist/src/worker/create-server.js +0 -51
  283. package/dist/src/worker/lifecycle.d.ts +0 -23
  284. package/dist/src/worker/lifecycle.js +0 -149
@@ -349,6 +349,18 @@ export class InvalidAudioInputError extends QvacErrorBase {
349
349
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.INVALID_AUDIO_INPUT, details ? [details] : undefined, cause));
350
350
  }
351
351
  }
352
+ export class AudioEncodeFailedError extends QvacErrorBase {
353
+ format;
354
+ details;
355
+ constructor(format, details, cause) {
356
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.AUDIO_ENCODE_FAILED, details ? [format, details] : [format], cause));
357
+ this.format = format;
358
+ this.details = details;
359
+ }
360
+ toErrorResponseFields() {
361
+ return { format: this.format, ...(this.details !== undefined && { details: this.details }) };
362
+ }
363
+ }
352
364
  // ============== RAG Operation Errors ==============
353
365
  export class RAGSaveFailedError extends QvacErrorBase {
354
366
  constructor(details, cause) {
@@ -491,6 +503,33 @@ export class InvalidDeleteCacheParamsError extends QvacErrorBase {
491
503
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.INVALID_DELETE_CACHE_PARAMS, undefined, cause));
492
504
  }
493
505
  }
506
+ export class InvalidSeedFromParamsError extends QvacErrorBase {
507
+ constructor(cause) {
508
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.INVALID_SEED_FROM_PARAMS, undefined, cause));
509
+ }
510
+ }
511
+ export class KvCacheSeedSourceNotFoundError extends QvacErrorBase {
512
+ seedFrom;
513
+ modelId;
514
+ constructor(seedFrom, modelId, cause) {
515
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.KV_CACHE_SEED_SOURCE_NOT_FOUND, [seedFrom, modelId], cause));
516
+ this.seedFrom = seedFrom;
517
+ this.modelId = modelId;
518
+ }
519
+ toErrorResponseFields() {
520
+ return { seedFrom: this.seedFrom, modelId: this.modelId };
521
+ }
522
+ }
523
+ export class KvCacheSeedSharingDisabledError extends QvacErrorBase {
524
+ modelId;
525
+ constructor(modelId, cause) {
526
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.KV_CACHE_SEED_SHARING_DISABLED, [modelId], cause));
527
+ this.modelId = modelId;
528
+ }
529
+ toErrorResponseFields() {
530
+ return { modelId: this.modelId };
531
+ }
532
+ }
494
533
  export class CacheDirNotAbsoluteError extends QvacErrorBase {
495
534
  constructor(cause) {
496
535
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.CACHE_DIR_NOT_ABSOLUTE, undefined, cause));
@@ -544,6 +583,17 @@ export class RAGWorkspaceNotOpenError extends QvacErrorBase {
544
583
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.RAG_WORKSPACE_NOT_OPEN, [workspace], cause));
545
584
  }
546
585
  }
586
+ /** A RAG operation on a workspace that another session's operation is using. */
587
+ export class RAGWorkspaceBusyError extends QvacErrorBase {
588
+ workspace;
589
+ constructor(workspace, cause) {
590
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.RAG_WORKSPACE_BUSY, [workspace], cause));
591
+ this.workspace = workspace;
592
+ }
593
+ toErrorResponseFields() {
594
+ return { workspace: this.workspace };
595
+ }
596
+ }
547
597
  // ============== RPC Errors (Server-side) ==============
548
598
  export class RPCNoDataReceivedError extends QvacErrorBase {
549
599
  constructor(cause) {
@@ -618,6 +668,65 @@ export class LifecycleResumeFailedError extends QvacErrorBase {
618
668
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.LIFECYCLE_RESUME_FAILED, details ? [details] : undefined, cause));
619
669
  }
620
670
  }
671
+ export class SessionIdConflictError extends QvacErrorBase {
672
+ sessionId;
673
+ constructor(sessionId, cause) {
674
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.SESSION_ID_CONFLICT, [sessionId], cause));
675
+ this.sessionId = sessionId;
676
+ }
677
+ toErrorResponseFields() {
678
+ return { sessionId: this.sessionId };
679
+ }
680
+ }
681
+ export class SessionNotOpenError extends QvacErrorBase {
682
+ sessionId;
683
+ constructor(sessionId, cause) {
684
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.SESSION_NOT_OPEN, [sessionId], cause));
685
+ this.sessionId = sessionId;
686
+ }
687
+ toErrorResponseFields() {
688
+ return { sessionId: this.sessionId };
689
+ }
690
+ }
691
+ /** A `reloadConfig` on a model another session holds a lease on. */
692
+ export class ModelLeasedError extends QvacErrorBase {
693
+ modelId;
694
+ leaseCount;
695
+ constructor(modelId, leaseCount, cause) {
696
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.MODEL_LEASED, [modelId, String(leaseCount)], cause));
697
+ this.modelId = modelId;
698
+ this.leaseCount = leaseCount;
699
+ }
700
+ toErrorResponseFields() {
701
+ return { modelId: this.modelId, leaseCount: this.leaseCount };
702
+ }
703
+ }
704
+ export class OwnerOnlyError extends QvacErrorBase {
705
+ operation;
706
+ sessionId;
707
+ constructor(operation, sessionId, cause) {
708
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.OWNER_ONLY, [operation, sessionId], cause));
709
+ this.operation = operation;
710
+ this.sessionId = sessionId;
711
+ }
712
+ toErrorResponseFields() {
713
+ return { operation: this.operation, sessionId: this.sessionId };
714
+ }
715
+ }
716
+ /**
717
+ * A load whose configuration hash names a model that a reload has since
718
+ * reconfigured, from a session that holds no lease on it.
719
+ */
720
+ export class ModelReconfiguredError extends QvacErrorBase {
721
+ modelId;
722
+ constructor(modelId, cause) {
723
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.MODEL_RECONFIGURED, [modelId], cause));
724
+ this.modelId = modelId;
725
+ }
726
+ toErrorResponseFields() {
727
+ return { modelId: this.modelId };
728
+ }
729
+ }
621
730
  export class LifecycleOperationBlockedError extends QvacErrorBase {
622
731
  constructor(requestType, lifecycleState) {
623
732
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.LIFECYCLE_OPERATION_BLOCKED, [
@@ -640,4 +749,16 @@ export class ModelRegistryQueryFailedError extends QvacErrorBase {
640
749
  super(createErrorOptions(SDK_SERVER_ERROR_CODES.QVAC_MODEL_REGISTRY_QUERY_FAILED, details ? [details] : undefined, cause));
641
750
  }
642
751
  }
643
- export { RpcServerOperationError } from '@qvac/inference/surface';
752
+ export class ModelRegistryModelNotFoundError extends QvacErrorBase {
753
+ registrySource;
754
+ registryPath;
755
+ constructor(registrySource, registryPath, cause) {
756
+ super(createErrorOptions(SDK_SERVER_ERROR_CODES.QVAC_MODEL_REGISTRY_MODEL_NOT_FOUND, [registrySource, registryPath], cause));
757
+ this.registrySource = registrySource;
758
+ this.registryPath = registryPath;
759
+ }
760
+ toErrorResponseFields() {
761
+ return { registrySource: this.registrySource, registryPath: this.registryPath };
762
+ }
763
+ }
764
+ export { RpcServerOperationError, ModelRegistryBusyError } from '@qvac/inference/surface';
@@ -1,6 +1,6 @@
1
1
  import type { Tool } from '@qvac/inference/surface';
2
2
  import type { McpClientInput } from '@qvac/inference/surface';
3
- import type { ToolHandler } from './tool-helpers.js';
3
+ import type { ToolHandler } from '../utils/tool-helpers.js';
4
4
  export type { McpClient, McpClientInput } from '@qvac/inference/surface';
5
5
  export type ToolHandlerMap = Map<string, ToolHandler>;
6
6
  export type McpToolsResult = {
@@ -1,4 +1,4 @@
1
- import { mapValues } from './object.js';
1
+ import { mapValues } from '../utils/object.js';
2
2
  const VALID_TYPES = ['string', 'number', 'integer', 'boolean', 'object', 'array', 'null'];
3
3
  function isValidType(value) {
4
4
  if (Array.isArray(value))
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { toolSchema } from '@qvac/inference/surface';
3
- import { InvalidToolsArrayError, InvalidToolSchemaError } from './errors-client.js';
3
+ import { InvalidToolsArrayError, InvalidToolSchemaError } from '../utils/errors-client.js';
4
4
  // Zod's integer bounds; they add nothing a tool grammar needs.
5
5
  const SAFE_INTEGER_BOUNDS = new Set([Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]);
6
6
  function dropSafeIntegerBounds(node) {
@@ -8,16 +8,6 @@ export class OperationTimeoutError extends Error {
8
8
  this.name = 'OperationTimeoutError';
9
9
  }
10
10
  }
11
- /**
12
- * Creates a timeout promise that rejects after the specified duration
13
- */
14
- function createTimeoutPromise(timeoutMs) {
15
- return new Promise((_, reject) => {
16
- setTimeout(() => {
17
- reject(new OperationTimeoutError(timeoutMs));
18
- }, timeoutMs);
19
- });
20
- }
21
11
  /**
22
12
  * Wraps a promise with an optional timeout
23
13
  * If no timeout is provided, returns the original promise unchanged
@@ -26,8 +16,18 @@ export async function withTimeout(promise, timeoutMs) {
26
16
  if (timeoutMs === undefined) {
27
17
  return promise;
28
18
  }
29
- const timeoutPromise = createTimeoutPromise(timeoutMs);
30
- return Promise.race([promise, timeoutPromise]);
19
+ let timer;
20
+ try {
21
+ return await Promise.race([
22
+ promise,
23
+ new Promise((_, reject) => {
24
+ timer = setTimeout(() => reject(new OperationTimeoutError(timeoutMs)), timeoutMs);
25
+ })
26
+ ]);
27
+ }
28
+ finally {
29
+ clearTimeout(timer);
30
+ }
31
31
  }
32
32
  /**
33
33
  * Wraps an async generator with optional timeout per iteration
@@ -38,10 +38,27 @@ export async function* withTimeoutStream(generator, timeoutMs) {
38
38
  yield* generator;
39
39
  return;
40
40
  }
41
- for await (const item of generator) {
42
- const itemPromise = Promise.resolve(item);
43
- const timeoutPromise = createTimeoutPromise(timeoutMs);
44
- const result = await Promise.race([itemPromise, timeoutPromise]);
45
- yield result;
41
+ let timedOut = false;
42
+ try {
43
+ while (true) {
44
+ const result = await withTimeout(generator.next(), timeoutMs);
45
+ if (result.done)
46
+ return;
47
+ yield result.value;
48
+ }
49
+ }
50
+ catch (error) {
51
+ timedOut = error instanceof OperationTimeoutError;
52
+ throw error;
53
+ }
54
+ finally {
55
+ const closing = generator.return(undefined);
56
+ if (timedOut) {
57
+ // return() queues behind a pending next(); waiting would hide the timeout.
58
+ void closing.catch(() => { });
59
+ }
60
+ else {
61
+ await closing;
62
+ }
46
63
  }
47
64
  }
@@ -2,9 +2,9 @@ import { PROFILING_KEY, nowMs } from '@qvac/inference/surface';
2
2
  import { send, stream, duplex, dispatchTransport } from '@qvac/inference/engine';
3
3
  import { sendErrorResponse, sendStreamErrorResponse } from '../server/error-handlers.js';
4
4
  import { PluginHandlerTypeMismatchError } from '../utils/errors-server.js';
5
- import { handleInitConfig, isInitConfigMessage, handleShutdown, isShutdownMessage } from './handler-utils.js';
5
+ import { handleInitConfig, isInitConfigMessage } from './handler-utils.js';
6
6
  import { createServerProfiler } from '../server/rpc/profiling/index.js';
7
- import { isTerminalChunk } from '../server/rpc/rpc-utils.js';
7
+ import { createResponseStreamLoggingErrors, isTerminalChunk, signalOnCancelOrStreamClose } from '../server/rpc/rpc-utils.js';
8
8
  import { createProgressThrottle } from '../server/rpc/progress-throttle.js';
9
9
  export async function handleRequest(req) {
10
10
  let profiler;
@@ -27,10 +27,6 @@ export async function handleRequest(req) {
27
27
  handleInitConfig(req, jsonData);
28
28
  return;
29
29
  }
30
- if (isShutdownMessage(jsonData)) {
31
- await handleShutdown(req);
32
- return;
33
- }
34
30
  const { data: cleanData, profilingMeta } = extractProfilingMeta(jsonData);
35
31
  profiler = createServerProfiler(profilingMeta);
36
32
  profiler.markRequestParsed(jsonParseMs);
@@ -40,29 +36,29 @@ export async function handleRequest(req) {
40
36
  attachProfilingMetaToRequest(request, profilingMeta);
41
37
  transport = dispatchTransport(request);
42
38
  if (transport === 'stream' || transport === 'progress') {
43
- await streamToWire(req, request, profiler, transport === 'progress');
39
+ await streamToResponse(req, request, profiler, transport === 'progress');
44
40
  }
45
41
  else if (transport === 'duplex') {
46
42
  throw new PluginHandlerTypeMismatchError(request.type, 'reply or stream', 'duplex');
47
43
  }
48
44
  else {
49
45
  profiler.startHandler();
50
- const response = await send(request);
46
+ const response = await send(request, transportOptions(req));
51
47
  profiler.endHandler();
52
48
  req.reply(profiler.serialize(response, true), 'utf-8');
53
49
  }
54
50
  }
55
51
  catch (error) {
56
52
  if (transport === 'stream' || transport === 'progress') {
57
- sendStreamErrorResponse(req.createResponseStream(), error, profiler);
53
+ sendStreamErrorResponse(createResponseStreamLoggingErrors(req), error, profiler);
58
54
  }
59
55
  else {
60
56
  sendErrorResponse(req, error, profiler);
61
57
  }
62
58
  }
63
59
  }
64
- async function streamToWire(req, request, profiler, throttleProgress) {
65
- const wire = req.createResponseStream();
60
+ async function streamToResponse(req, request, profiler, throttleProgress) {
61
+ const responseStream = createResponseStreamLoggingErrors(req);
66
62
  profiler.startHandler();
67
63
  let sentFinalChunk = false;
68
64
  // A progress stream (a reply op that streams because of `withProgress`) can
@@ -71,22 +67,23 @@ async function streamToWire(req, request, profiler, throttleProgress) {
71
67
  // through immediately and are never throttled.
72
68
  const throttle = throttleProgress
73
69
  ? createProgressThrottle((updates) => {
74
- wire.write(updates.map((u) => profiler.serialize(u, false)).join('\n') + '\n', 'utf-8');
70
+ responseStream.write(updates.map((u) => profiler.serialize(u, false)).join('\n') + '\n', 'utf-8');
75
71
  })
76
72
  : undefined;
77
73
  try {
78
- for await (const response of stream(request)) {
74
+ const signal = signalOnCancelOrStreamClose(req, responseStream);
75
+ for await (const response of stream(request, { signal })) {
79
76
  if (isTerminalChunk(response)) {
80
77
  throttle?.flush();
81
78
  profiler.endHandler();
82
- wire.write(profiler.serialize(response, true) + '\n', 'utf-8');
79
+ responseStream.write(profiler.serialize(response, true) + '\n', 'utf-8');
83
80
  sentFinalChunk = true;
84
81
  }
85
82
  else if (throttle) {
86
83
  throttle.push(response);
87
84
  }
88
85
  else {
89
- wire.write(profiler.serialize(response, false) + '\n', 'utf-8');
86
+ responseStream.write(profiler.serialize(response, false) + '\n', 'utf-8');
90
87
  }
91
88
  }
92
89
  if (!sentFinalChunk) {
@@ -94,20 +91,20 @@ async function streamToWire(req, request, profiler, throttleProgress) {
94
91
  profiler.endHandler();
95
92
  const trailer = profiler.serialize();
96
93
  if (trailer) {
97
- wire.write(trailer + '\n', 'utf-8');
94
+ responseStream.write(trailer + '\n', 'utf-8');
98
95
  }
99
96
  }
100
- wire.end();
97
+ responseStream.end();
101
98
  }
102
99
  catch (error) {
103
100
  throttle?.flush();
104
101
  profiler.endHandler();
105
- sendStreamErrorResponse(wire, error, profiler);
102
+ sendStreamErrorResponse(responseStream, error, profiler);
106
103
  }
107
104
  }
108
105
  async function handleDuplexRequest(req) {
109
106
  const rpcInput = req.createRequestStream();
110
- const rpcOutput = req.createResponseStream();
107
+ const rpcOutput = createResponseStreamLoggingErrors(req);
111
108
  let profiler;
112
109
  try {
113
110
  const firstChunk = await new Promise((resolve, reject) => {
@@ -131,9 +128,9 @@ async function handleDuplexRequest(req) {
131
128
  profiler.markRequestParsed(jsonParseMs);
132
129
  const request = cleanData;
133
130
  attachProfilingMetaToRequest(request, profilingMeta);
134
- const session = await duplex(request);
131
+ const session = await duplex(request, { signal: signalOnCancelOrStreamClose(req, rpcOutput) });
135
132
  // Feed the remaining RPC input into the engine's input stream, and forward
136
- // the engine's newline-framed responses back out to the wire.
133
+ // the engine's newline-framed responses back out to the response stream.
137
134
  rpcInput.on('data', (chunk) => session.requestStream.write(chunk));
138
135
  rpcInput.on('end', () => session.requestStream.end());
139
136
  rpcInput.on('error', () => session.requestStream.destroy());
@@ -157,6 +154,14 @@ async function handleDuplexRequest(req) {
157
154
  sendStreamErrorResponse(rpcOutput, error, profiler);
158
155
  }
159
156
  }
157
+ /**
158
+ * `req.signal` aborts when the client cancels the request, as a call that
159
+ * times out does, and when the client goes away. The engine cancels the
160
+ * request's work when it aborts.
161
+ */
162
+ function transportOptions(req) {
163
+ return req.signal ? { signal: req.signal } : {};
164
+ }
160
165
  function attachProfilingMetaToRequest(request, profilingMeta) {
161
166
  if (!profilingMeta)
162
167
  return;
@@ -2,15 +2,11 @@ import { type QvacConfig, type RuntimeContext } from '@qvac/inference/surface';
2
2
  import type RPC from 'bare-rpc';
3
3
  type InitConfigMessage = {
4
4
  type: '__init_config';
5
- config: QvacConfig;
5
+ config?: QvacConfig;
6
6
  runtimeContext?: RuntimeContext;
7
+ homeDir?: string;
7
8
  };
8
9
  export declare function isInitConfigMessage(data: unknown): data is InitConfigMessage;
9
10
  export declare function handleInitConfig(req: RPC.IncomingRequest, data: InitConfigMessage): void;
10
- type ShutdownMessage = {
11
- type: '__shutdown__';
12
- };
13
- export declare function isShutdownMessage(data: unknown): data is ShutdownMessage;
14
- export declare function handleShutdown(req: RPC.IncomingRequest): Promise<void>;
15
11
  export {};
16
12
  //# sourceMappingURL=handler-utils.d.ts.map
@@ -1,10 +1,11 @@
1
1
  import {} from '@qvac/inference/surface';
2
- import { setConfig, setRuntimeContext } from '@qvac/inference/engine';
2
+ import { initialize, setConfig, setRuntimeContext } from '@qvac/inference/engine';
3
3
  export function isInitConfigMessage(data) {
4
4
  return (typeof data === 'object' && data !== null && 'type' in data && data.type === '__init_config');
5
5
  }
6
6
  export function handleInitConfig(req, data) {
7
7
  try {
8
+ initialize({ homeDir: data.homeDir });
8
9
  if (data.config) {
9
10
  setConfig(data.config);
10
11
  }
@@ -20,22 +21,3 @@ export function handleInitConfig(req, data) {
20
21
  }), 'utf-8');
21
22
  }
22
23
  }
23
- export function isShutdownMessage(data) {
24
- return (typeof data === 'object' &&
25
- data !== null &&
26
- 'type' in data &&
27
- data.type === '__shutdown__');
28
- }
29
- export async function handleShutdown(req) {
30
- try {
31
- const { cleanupForTerminate } = await import('./lifecycle.js');
32
- await cleanupForTerminate();
33
- req.reply(JSON.stringify({ success: true }), 'utf-8');
34
- }
35
- catch (error) {
36
- req.reply(JSON.stringify({
37
- success: false,
38
- error: error instanceof Error ? error.message : String(error)
39
- }), 'utf-8');
40
- }
41
- }
@@ -1,5 +1,3 @@
1
- /**
2
- * Default worker entry point that registers ALL built-in plugins.
3
- */
4
- export {};
1
+ import type { Duplex } from 'bare-stream';
2
+ export default function start(ipc: Duplex, ready: () => void): import("../worker/start.js").StopWorker;
5
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,11 +1,8 @@
1
- /**
2
- * Default worker entry point that registers ALL built-in plugins.
3
- */
4
- import { initializeWorker, ensureRPCSetup } from './lifecycle.js';
5
- import { getServerLogger } from '../logging/index.js';
6
- import { registerPlugins } from '@qvac/inference/plugins';
1
+ import { startWorker } from '../worker/start.js';
7
2
  import { llmPlugin } from '@qvac/inference/llamacpp-completion/plugin';
8
3
  import { decisionPlugin } from '@qvac/inference/llamacpp-decision/plugin';
4
+ import { rerankPlugin } from '@qvac/inference/llamacpp-rerank/plugin';
5
+ import { imageEmbeddingPlugin } from '@qvac/inference/ggml-image-embedding/plugin';
9
6
  import { embeddingsPlugin } from '@qvac/inference/llamacpp-embedding/plugin';
10
7
  import { whisperPlugin } from '@qvac/inference/whispercpp-transcription/plugin';
11
8
  import { bciPlugin } from '@qvac/inference/bci-whispercpp-transcription/plugin';
@@ -18,32 +15,25 @@ import { diffusionPlugin } from '@qvac/inference/sdcpp-generation/plugin';
18
15
  import { audioGenPlugin } from '@qvac/inference/audiogen-ggml/plugin';
19
16
  import { vlaPlugin } from '@qvac/inference/ggml-vla/plugin';
20
17
  import { classificationPlugin } from '@qvac/inference/ggml-classification/plugin';
21
- const { hasRPCConfig } = initializeWorker();
22
- const logger = getServerLogger();
23
- logger.info('🐻 Hello from Bare');
24
- registerPlugins([
25
- llmPlugin,
26
- embeddingsPlugin,
27
- decisionPlugin,
28
- whisperPlugin,
29
- bciPlugin,
30
- parakeetPlugin,
31
- mossTranscribePlugin,
32
- nmtPlugin,
33
- ttsPlugin,
34
- ocrPlugin,
35
- diffusionPlugin,
36
- audioGenPlugin,
37
- vlaPlugin,
38
- classificationPlugin
39
- ]);
40
- logger.info(hasRPCConfig
41
- ? 'Parsed RPC configuration from arguments'
42
- : 'Using default configuration (direct mode)');
43
- // Auto-setup RPC only if we successfully parsed RPC configuration
44
- if (hasRPCConfig) {
45
- ensureRPCSetup();
46
- }
47
- else {
48
- logger.info('Running in direct mode - RPC setup will be lazy');
18
+ export default function start(ipc, ready) {
19
+ return startWorker(ipc, ready, {
20
+ plugins: [
21
+ llmPlugin,
22
+ embeddingsPlugin,
23
+ imageEmbeddingPlugin,
24
+ decisionPlugin,
25
+ rerankPlugin,
26
+ whisperPlugin,
27
+ bciPlugin,
28
+ parakeetPlugin,
29
+ mossTranscribePlugin,
30
+ nmtPlugin,
31
+ ttsPlugin,
32
+ ocrPlugin,
33
+ diffusionPlugin,
34
+ audioGenPlugin,
35
+ vlaPlugin,
36
+ classificationPlugin
37
+ ]
38
+ });
49
39
  }
@@ -0,0 +1,2 @@
1
+ export * from '@qvac/inference/ggml-image-embedding/plugin';
2
+ //# sourceMappingURL=ggml-image-embedding.d.ts.map
@@ -0,0 +1 @@
1
+ export * from '@qvac/inference/ggml-image-embedding/plugin';
@@ -0,0 +1,2 @@
1
+ export * from '@qvac/inference/llamacpp-rerank/plugin';
2
+ //# sourceMappingURL=llamacpp-rerank.d.ts.map
@@ -0,0 +1 @@
1
+ export * from '@qvac/inference/llamacpp-rerank/plugin';
@@ -0,0 +1,4 @@
1
+ import type { Duplex } from 'bare-stream';
2
+ /** bare-stow's process runtime over `medium`, around the entry at `entryPath`. */
3
+ export declare function runEntry(medium: Duplex, entryPath: string): Promise<void>;
4
+ //# sourceMappingURL=shim.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { attach } from 'bare-stow-runtime/process';
2
+ import { pathToFileURL } from 'bare-url';
3
+ /** bare-stow's process runtime over `medium`, around the entry at `entryPath`. */
4
+ export function runEntry(medium, entryPath) {
5
+ const ipc = attach(medium);
6
+ return ipc.run(() => import(pathToFileURL(entryPath).href), ipc);
7
+ }
@@ -0,0 +1,9 @@
1
+ import type { Duplex } from 'bare-stream';
2
+ import type { QvacPlugin, RpcServerProvider } from '@qvac/inference/surface';
3
+ export interface WorkerOptions {
4
+ plugins: readonly QvacPlugin[];
5
+ rpcServerProvider?: RpcServerProvider | undefined;
6
+ }
7
+ export type StopWorker = () => Promise<void>;
8
+ export declare function startWorker(ipc: Duplex, ready: () => void, options: WorkerOptions): StopWorker;
9
+ //# sourceMappingURL=start.d.ts.map
@@ -0,0 +1,16 @@
1
+ import { close as closeEngine } from '@qvac/inference/engine';
2
+ import { registerPlugins } from '@qvac/inference/plugins';
3
+ import { registerRpcServerProvider } from '@qvac/inference/rpc-server-provider';
4
+ import { handleRequest } from '../worker/handle-request.js';
5
+ import { createWorkerRpc } from '../server/rpc/rpc-utils.js';
6
+ import { getServerLogger } from '../logging/index.js';
7
+ const logger = getServerLogger();
8
+ export function startWorker(ipc, ready, options) {
9
+ registerPlugins(options.plugins);
10
+ if (options.rpcServerProvider)
11
+ registerRpcServerProvider(options.rpcServerProvider);
12
+ createWorkerRpc(ipc, handleRequest);
13
+ logger.info(`Worker ready with ${options.plugins.length} plugins`);
14
+ ready();
15
+ return closeEngine;
16
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=unbundled-shim.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { runEntry } from '../worker/shim.js';
2
+ if (!Bare.IPC)
3
+ throw new Error('The unbundled worker runs under bare-sidecar, which opens Bare.IPC');
4
+ await runEntry(Bare.IPC, Bare.argv[2]);