@qvac/sdk 0.5.0 → 0.6.1

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 (259) hide show
  1. package/README.md +48 -11
  2. package/bare-imports.json +35 -0
  3. package/dist/client/api/cancel.d.ts +12 -3
  4. package/dist/client/api/cancel.js +12 -3
  5. package/dist/client/api/get-model-info.d.ts +2 -2
  6. package/dist/client/api/get-model-info.js +2 -2
  7. package/dist/client/api/index.d.ts +2 -1
  8. package/dist/client/api/index.js +2 -1
  9. package/dist/client/api/load-model.js +6 -1
  10. package/dist/client/api/ocr.d.ts +31 -0
  11. package/dist/client/api/ocr.js +88 -0
  12. package/dist/client/api/rag.d.ts +215 -20
  13. package/dist/client/api/rag.js +382 -23
  14. package/dist/client/api/translate.js +10 -11
  15. package/dist/client/api/unload-model.js +1 -1
  16. package/dist/client/init-hooks.d.ts +4 -3
  17. package/dist/client/init-hooks.js +40 -31
  18. package/dist/client/rpc/bare-client.d.ts +1 -178
  19. package/dist/client/rpc/bare-client.js +42 -9
  20. package/dist/client/rpc/expo-rpc-client.js +57 -2
  21. package/dist/client/rpc/node-rpc-client.js +5 -1
  22. package/dist/client/rpc/rpc-client.d.ts +1 -1
  23. package/dist/client/rpc/rpc-client.js +11 -57
  24. package/dist/examples/config/blind-relay/blind-relay.config.d.ts +5 -0
  25. package/dist/examples/config/blind-relay/blind-relay.config.js +7 -0
  26. package/dist/examples/config/default/default.config.d.ts +8 -0
  27. package/dist/examples/config/default/default.config.js +6 -0
  28. package/dist/examples/default-config-usage.d.ts +17 -0
  29. package/dist/examples/default-config-usage.js +47 -0
  30. package/dist/examples/delegated-inference/consumer.js +1 -0
  31. package/dist/examples/download-with-blind-relays.js +4 -3
  32. package/dist/examples/embed-hyperdrive.js +4 -0
  33. package/dist/examples/kv-cache-custom-key.js +16 -1
  34. package/dist/examples/llamacpp-sharded.js +12 -3
  35. package/dist/examples/ocr-fasttext.d.ts +2 -0
  36. package/dist/examples/ocr-fasttext.js +52 -0
  37. package/dist/examples/quickstart.d.ts +2 -0
  38. package/dist/examples/quickstart.js +28 -0
  39. package/dist/examples/rag/rag-hyperdb/cancellation.d.ts +2 -0
  40. package/dist/examples/rag/rag-hyperdb/cancellation.js +75 -0
  41. package/dist/examples/rag/rag-hyperdb/ingest.d.ts +2 -0
  42. package/dist/examples/rag/{rag-hyperdb.js → rag-hyperdb/ingest.js} +10 -4
  43. package/dist/examples/rag/rag-hyperdb/pipeline.d.ts +2 -0
  44. package/dist/examples/rag/rag-hyperdb/pipeline.js +74 -0
  45. package/dist/examples/rag/rag-hyperdb/workspaces.d.ts +2 -0
  46. package/dist/examples/rag/rag-hyperdb/workspaces.js +178 -0
  47. package/dist/examples/translation/translation-bergamot-batch.d.ts +2 -0
  48. package/dist/examples/translation/translation-bergamot-batch.js +49 -0
  49. package/dist/examples/translation/translation-bergamot.d.ts +2 -0
  50. package/dist/examples/translation/translation-bergamot.js +39 -0
  51. package/dist/examples/translation/translation-indic.js +1 -0
  52. package/dist/examples/translation/translation-opus.js +1 -0
  53. package/dist/examples/translation/translation-stream.js +1 -0
  54. package/dist/expo/plugins/withMobileBundle.js +29 -10
  55. package/dist/index.d.ts +3 -2
  56. package/dist/index.js +3 -1
  57. package/dist/logging/addon.js +23 -7
  58. package/dist/logging/base-logger.js +2 -2
  59. package/dist/logging/client-logger.js +15 -4
  60. package/dist/logging/index.d.ts +1 -0
  61. package/dist/logging/index.js +1 -0
  62. package/dist/logging/logger.js +11 -3
  63. package/dist/logging/namespaces.d.ts +1 -0
  64. package/dist/logging/namespaces.js +1 -0
  65. package/dist/logging/registry.d.ts +5 -0
  66. package/dist/logging/registry.js +17 -5
  67. package/dist/logging/transport.js +2 -2
  68. package/dist/logging/utils.d.ts +2 -0
  69. package/dist/logging/utils.js +62 -0
  70. package/dist/models/hyperdrive/models.d.ts +1096 -178
  71. package/dist/models/hyperdrive/models.js +1476 -507
  72. package/dist/schemas/archive.d.ts +9 -0
  73. package/dist/schemas/archive.js +17 -0
  74. package/dist/schemas/cancel.d.ts +6 -0
  75. package/dist/schemas/cancel.js +5 -0
  76. package/dist/schemas/common.d.ts +582 -77
  77. package/dist/schemas/common.js +6 -1
  78. package/dist/schemas/delegate.d.ts +1 -0
  79. package/dist/schemas/delegate.js +1 -0
  80. package/dist/schemas/download-asset.d.ts +21 -9
  81. package/dist/schemas/get-model-info.d.ts +12 -10
  82. package/dist/schemas/get-model-info.js +9 -1
  83. package/dist/schemas/index.d.ts +6 -2
  84. package/dist/schemas/index.js +9 -2
  85. package/dist/schemas/llamacpp-config.d.ts +112 -8
  86. package/dist/schemas/llamacpp-config.js +40 -8
  87. package/dist/schemas/load-model.d.ts +2993 -525
  88. package/dist/schemas/load-model.js +88 -33
  89. package/dist/schemas/logging-stream.d.ts +2 -2
  90. package/dist/schemas/model-src-utils.d.ts +38 -16
  91. package/dist/schemas/model-src-utils.js +4 -8
  92. package/dist/schemas/model-types.d.ts +154 -0
  93. package/dist/schemas/model-types.js +140 -0
  94. package/dist/schemas/ocr.d.ts +88 -0
  95. package/dist/schemas/ocr.js +52 -0
  96. package/dist/schemas/rag.d.ts +183 -52
  97. package/dist/schemas/rag.js +148 -23
  98. package/dist/schemas/reload-config.d.ts +20 -8
  99. package/dist/schemas/reload-config.js +7 -5
  100. package/dist/schemas/runtime-context.d.ts +19 -0
  101. package/dist/schemas/runtime-context.js +7 -0
  102. package/dist/schemas/sdk-config.d.ts +697 -2
  103. package/dist/schemas/sdk-config.js +99 -1
  104. package/dist/schemas/sdk-errors-client.d.ts +1 -0
  105. package/dist/schemas/sdk-errors-client.js +5 -0
  106. package/dist/schemas/sdk-errors-server.d.ts +14 -0
  107. package/dist/schemas/sdk-errors-server.js +70 -0
  108. package/dist/schemas/shard.d.ts +21 -0
  109. package/dist/schemas/shard.js +17 -0
  110. package/dist/schemas/translate.d.ts +68 -23
  111. package/dist/schemas/translate.js +37 -11
  112. package/dist/schemas/translation-config.d.ts +272 -29
  113. package/dist/schemas/translation-config.js +63 -6
  114. package/dist/scripts/run-unit-tests.d.ts +2 -0
  115. package/dist/scripts/run-unit-tests.js +17 -0
  116. package/dist/server/bare/addons/llamacpp-completion/cache-logger.d.ts +6 -0
  117. package/dist/server/bare/addons/llamacpp-completion/cache-logger.js +34 -0
  118. package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/create-model.d.ts +1 -5
  119. package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/create-model.js +3 -26
  120. package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/handlers/completion-stream.js +26 -7
  121. package/dist/server/bare/addons/llamacpp-completion/index.d.ts +4 -0
  122. package/dist/server/bare/addons/llamacpp-completion/index.js +3 -0
  123. package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/kv-cache-utils.d.ts +4 -1
  124. package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/kv-cache-utils.js +43 -10
  125. package/dist/server/bare/addons/llamacpp-embedding/create-model.d.ts +8 -0
  126. package/dist/server/bare/addons/llamacpp-embedding/create-model.js +38 -0
  127. package/dist/server/bare/addons/llamacpp-embedding/index.d.ts +3 -0
  128. package/dist/server/bare/addons/llamacpp-embedding/index.js +2 -0
  129. package/dist/server/bare/addons/load-model.js +28 -24
  130. package/dist/server/bare/addons/{translation → nmtcpp-translation}/create-model.js +23 -8
  131. package/dist/server/bare/addons/{translation → nmtcpp-translation}/handlers/translate.js +35 -11
  132. package/dist/server/bare/addons/onnx-ocr/create-model.d.ts +10 -0
  133. package/dist/server/bare/addons/onnx-ocr/create-model.js +39 -0
  134. package/dist/server/bare/addons/onnx-ocr/handlers/ocr-stream.d.ts +10 -0
  135. package/dist/server/bare/addons/onnx-ocr/handlers/ocr-stream.js +109 -0
  136. package/dist/server/bare/addons/onnx-ocr/index.d.ts +3 -0
  137. package/dist/server/bare/addons/onnx-ocr/index.js +2 -0
  138. package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/create-model.js +2 -1
  139. package/dist/server/bare/delegate-rpc-client.js +19 -1
  140. package/dist/server/bare/rag-hyperdb/handlers/chunk.d.ts +3 -0
  141. package/dist/server/bare/rag-hyperdb/handlers/chunk.js +7 -0
  142. package/dist/server/bare/rag-hyperdb/handlers/close-workspace.d.ts +3 -0
  143. package/dist/server/bare/rag-hyperdb/handlers/close-workspace.js +9 -0
  144. package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +1 -1
  145. package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +9 -10
  146. package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.d.ts +3 -0
  147. package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.js +14 -0
  148. package/dist/server/bare/rag-hyperdb/handlers/ingest.d.ts +9 -0
  149. package/dist/server/bare/rag-hyperdb/handlers/ingest.js +18 -0
  150. package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.d.ts +3 -0
  151. package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.js +4 -0
  152. package/dist/server/bare/rag-hyperdb/handlers/reindex.d.ts +9 -0
  153. package/dist/server/bare/rag-hyperdb/handlers/reindex.js +16 -0
  154. package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +7 -4
  155. package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +13 -14
  156. package/dist/server/bare/rag-hyperdb/handlers/search.js +10 -10
  157. package/dist/server/bare/rag-hyperdb/index.d.ts +8 -1
  158. package/dist/server/bare/rag-hyperdb/index.js +8 -1
  159. package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +7 -0
  160. package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +39 -0
  161. package/dist/server/bare/rag-hyperdb/rag-workspace-manager.d.ts +15 -0
  162. package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +135 -0
  163. package/dist/server/bare/registry/config-registry.js +11 -0
  164. package/dist/server/bare/registry/logging-stream-registry.js +3 -3
  165. package/dist/server/bare/registry/model-config-registry.d.ts +4 -0
  166. package/dist/server/bare/registry/model-config-registry.js +15 -0
  167. package/dist/server/bare/registry/model-config-utils.d.ts +15 -0
  168. package/dist/server/bare/registry/model-config-utils.js +110 -0
  169. package/dist/server/bare/registry/model-registry.d.ts +6 -29
  170. package/dist/server/bare/registry/runtime-context-registry.d.ts +7 -0
  171. package/dist/server/bare/registry/runtime-context-registry.js +26 -0
  172. package/dist/server/bare/utils/loader-adapter.d.ts +7 -0
  173. package/dist/server/bare/utils/loader-adapter.js +9 -0
  174. package/dist/server/error-handlers.js +4 -2
  175. package/dist/server/rpc/handle-request.js +91 -9
  176. package/dist/server/rpc/handlers/cancelHandler.js +10 -1
  177. package/dist/server/rpc/handlers/completion-stream.js +1 -1
  178. package/dist/server/rpc/handlers/delete-cache.js +1 -1
  179. package/dist/server/rpc/handlers/embed.js +1 -1
  180. package/dist/server/rpc/handlers/get-model-info.d.ts +1 -1
  181. package/dist/server/rpc/handlers/get-model-info.js +22 -10
  182. package/dist/server/rpc/handlers/index.d.ts +4 -1
  183. package/dist/server/rpc/handlers/index.js +2 -0
  184. package/dist/server/rpc/handlers/load-model/download-manager.d.ts +11 -11
  185. package/dist/server/rpc/handlers/load-model/download-manager.js +36 -26
  186. package/dist/server/rpc/handlers/{load-model.d.ts → load-model/handler.d.ts} +2 -2
  187. package/dist/server/rpc/handlers/load-model/handler.js +179 -0
  188. package/dist/server/rpc/handlers/load-model/http.js +342 -33
  189. package/dist/server/rpc/handlers/load-model/hyperdrive.js +5 -3
  190. package/dist/server/rpc/handlers/load-model/index.d.ts +2 -2
  191. package/dist/server/rpc/handlers/load-model/index.js +2 -2
  192. package/dist/server/rpc/handlers/load-model/resolve.js +32 -3
  193. package/dist/server/rpc/handlers/load-model-delegated.js +6 -3
  194. package/dist/server/rpc/handlers/ocr-stream.d.ts +3 -0
  195. package/dist/server/rpc/handlers/ocr-stream.js +39 -0
  196. package/dist/server/rpc/handlers/rag.d.ts +2 -2
  197. package/dist/server/rpc/handlers/rag.js +107 -43
  198. package/dist/server/rpc/handlers/text-to-speech.js +1 -1
  199. package/dist/server/rpc/handlers/transcribe-stream.js +1 -1
  200. package/dist/server/rpc/handlers/translate.js +6 -15
  201. package/dist/server/utils/archive.d.ts +3 -0
  202. package/dist/server/utils/archive.js +171 -0
  203. package/dist/server/utils/audio/decoder.js +2 -2
  204. package/dist/server/utils/cache.d.ts +5 -5
  205. package/dist/server/utils/cache.js +6 -6
  206. package/dist/server/utils/config-transform.d.ts +2 -2
  207. package/dist/server/utils/config-transform.js +8 -6
  208. package/dist/server/utils/formatting.d.ts +13 -0
  209. package/dist/server/utils/formatting.js +26 -0
  210. package/dist/server/utils/gguf-tensor-extractor.d.ts +15 -0
  211. package/dist/server/utils/gguf-tensor-extractor.js +314 -0
  212. package/dist/server/utils/index.d.ts +3 -1
  213. package/dist/server/utils/index.js +3 -1
  214. package/dist/server/utils/shard-utils.d.ts +42 -16
  215. package/dist/server/utils/shard-utils.js +95 -7
  216. package/dist/server/worker.js +8 -3
  217. package/dist/utils/errors-base.d.ts +1 -1
  218. package/dist/utils/errors-base.js +2 -2
  219. package/dist/utils/errors-client.d.ts +12 -0
  220. package/dist/utils/errors-client.js +20 -0
  221. package/dist/utils/errors-server.d.ts +33 -0
  222. package/dist/utils/errors-server.js +55 -0
  223. package/package.json +42 -17
  224. package/dist/client/rpc/bare-rpc-client.d.ts +0 -4
  225. package/dist/client/rpc/bare-rpc-client.js +0 -94
  226. package/dist/examples/config/config-path.d.ts +0 -8
  227. package/dist/examples/config/config-path.js +0 -13
  228. package/dist/examples/rag/rag-hyperdb-workspaces.d.ts +0 -2
  229. package/dist/examples/rag/rag-hyperdb-workspaces.js +0 -106
  230. package/dist/examples/rag/rag-hyperdb.d.ts +0 -2
  231. package/dist/server/bare/addons/llamacpp/index.d.ts +0 -4
  232. package/dist/server/bare/addons/llamacpp/index.js +0 -3
  233. package/dist/server/bare/rag-hyperdb/rag-manager.d.ts +0 -5
  234. package/dist/server/bare/rag-hyperdb/rag-manager.js +0 -66
  235. package/dist/server/rpc/handlers/load-model.js +0 -111
  236. package/dist/server/utils/hash.d.ts +0 -5
  237. package/dist/server/utils/hash.js +0 -11
  238. package/dist/utils/getProcessSafe.d.ts +0 -7
  239. package/dist/utils/getProcessSafe.js +0 -17
  240. package/dist/utils/runtime.d.ts +0 -30
  241. package/dist/utils/runtime.js +0 -48
  242. /package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/handlers/completion-stream.d.ts +0 -0
  243. /package/dist/server/bare/addons/{llamacpp → llamacpp-embedding}/handlers/embed.d.ts +0 -0
  244. /package/dist/server/bare/addons/{llamacpp → llamacpp-embedding}/handlers/embed.js +0 -0
  245. /package/dist/server/bare/addons/{translation → nmtcpp-translation}/create-model.d.ts +0 -0
  246. /package/dist/server/bare/addons/{translation → nmtcpp-translation}/handlers/translate.d.ts +0 -0
  247. /package/dist/server/bare/addons/{translation → nmtcpp-translation}/index.d.ts +0 -0
  248. /package/dist/server/bare/addons/{translation → nmtcpp-translation}/index.js +0 -0
  249. /package/dist/server/bare/addons/{tts → onnx-tts}/create-model.d.ts +0 -0
  250. /package/dist/server/bare/addons/{tts → onnx-tts}/create-model.js +0 -0
  251. /package/dist/server/bare/addons/{tts → onnx-tts}/handlers/text-to-speech.d.ts +0 -0
  252. /package/dist/server/bare/addons/{tts → onnx-tts}/handlers/text-to-speech.js +0 -0
  253. /package/dist/server/bare/addons/{tts → onnx-tts}/index.d.ts +0 -0
  254. /package/dist/server/bare/addons/{tts → onnx-tts}/index.js +0 -0
  255. /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/create-model.d.ts +0 -0
  256. /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/handlers/transcribe-stream.d.ts +0 -0
  257. /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/handlers/transcribe-stream.js +0 -0
  258. /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/index.d.ts +0 -0
  259. /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/index.js +0 -0
@@ -1,3 +1,3 @@
1
- import type { RagRequest, RagResponse } from "../../../schemas/index";
2
- export declare function handleRag(request: RagRequest): Promise<RagResponse>;
1
+ import type { RagRequest, RagResponse, RagProgressUpdate } from "../../../schemas/index";
2
+ export declare function handleRag(request: RagRequest, onProgress?: (update: RagProgressUpdate) => void): Promise<RagResponse>;
3
3
  //# sourceMappingURL=rag.d.ts.map
@@ -1,11 +1,43 @@
1
- import { saveEmbeddings, search, deleteEmbeddings, } from "../../bare/rag-hyperdb/index.js";
2
- import { getServerLogger } from "../../../logging/index.js";
3
- const logger = getServerLogger();
4
- export async function handleRag(request) {
5
- try {
6
- switch (request.operation) {
7
- case "saveEmbeddings": {
8
- const result = await saveEmbeddings(request);
1
+ import { chunk, ingest, reindex, saveEmbeddings, search, deleteEmbeddings, listWorkspaces, closeWorkspace, deleteWorkspace, DEFAULT_WORKSPACE, registerRagOperation, unregisterRagOperation, } from "../../bare/rag-hyperdb/index.js";
2
+ function createHandlerOptions(operation, workspace, onProgress) {
3
+ const signal = registerRagOperation(workspace, operation);
4
+ const options = { signal };
5
+ if (onProgress) {
6
+ options.onProgress = (stage, current, total) => onProgress({
7
+ type: "rag:progress",
8
+ operation,
9
+ workspace,
10
+ stage,
11
+ current,
12
+ total,
13
+ timestamp: Date.now(),
14
+ });
15
+ }
16
+ return options;
17
+ }
18
+ function omitOnProgress(obj) {
19
+ const { onProgress, withProgress, ...rest } = obj;
20
+ void onProgress;
21
+ void withProgress;
22
+ return rest;
23
+ }
24
+ export async function handleRag(request, onProgress) {
25
+ switch (request.operation) {
26
+ case "chunk": {
27
+ const chunks = await chunk(request);
28
+ return {
29
+ type: "rag",
30
+ operation: request.operation,
31
+ success: true,
32
+ chunks,
33
+ };
34
+ }
35
+ case "ingest": {
36
+ const workspace = request.workspace ?? DEFAULT_WORKSPACE;
37
+ const handlerOptions = createHandlerOptions("ingest", workspace, onProgress);
38
+ const params = omitOnProgress(request);
39
+ try {
40
+ const result = await ingest(params, handlerOptions);
9
41
  return {
10
42
  type: "rag",
11
43
  operation: request.operation,
@@ -14,53 +46,85 @@ export async function handleRag(request) {
14
46
  droppedIndices: result.droppedIndices,
15
47
  };
16
48
  }
17
- case "search": {
18
- const results = await search(request);
49
+ finally {
50
+ unregisterRagOperation(workspace);
51
+ }
52
+ }
53
+ case "saveEmbeddings": {
54
+ const workspace = request.workspace ?? DEFAULT_WORKSPACE;
55
+ const handlerOptions = createHandlerOptions("saveEmbeddings", workspace, onProgress);
56
+ const params = omitOnProgress(request);
57
+ try {
58
+ const processed = await saveEmbeddings(params, handlerOptions);
19
59
  return {
20
60
  type: "rag",
21
61
  operation: request.operation,
22
62
  success: true,
23
- results,
63
+ processed,
24
64
  };
25
65
  }
26
- case "deleteEmbeddings": {
27
- const success = await deleteEmbeddings(request);
66
+ finally {
67
+ unregisterRagOperation(workspace);
68
+ }
69
+ }
70
+ case "search": {
71
+ const results = await search(request);
72
+ return {
73
+ type: "rag",
74
+ operation: request.operation,
75
+ success: true,
76
+ results,
77
+ };
78
+ }
79
+ case "deleteEmbeddings": {
80
+ await deleteEmbeddings(request);
81
+ return {
82
+ type: "rag",
83
+ operation: request.operation,
84
+ success: true,
85
+ };
86
+ }
87
+ case "reindex": {
88
+ const workspace = request.workspace ?? DEFAULT_WORKSPACE;
89
+ const handlerOptions = createHandlerOptions("reindex", workspace, onProgress);
90
+ const params = omitOnProgress(request);
91
+ try {
92
+ const result = await reindex(params, handlerOptions);
28
93
  return {
29
94
  type: "rag",
30
95
  operation: request.operation,
31
- success,
96
+ success: true,
97
+ result,
32
98
  };
33
99
  }
100
+ finally {
101
+ unregisterRagOperation(workspace);
102
+ }
34
103
  }
35
- }
36
- catch (error) {
37
- logger.error("Error in RAG handler:", error);
38
- const baseError = {
39
- type: "rag",
40
- success: false,
41
- error: error instanceof Error ? error.message : "Unknown error",
42
- };
43
- switch (request.operation) {
44
- case "saveEmbeddings":
45
- return {
46
- ...baseError,
47
- operation: request.operation,
48
- processed: [],
49
- droppedIndices: [],
50
- };
51
- case "search":
52
- return {
53
- ...baseError,
54
- operation: request.operation,
55
- results: [],
56
- };
57
- case "deleteEmbeddings":
58
- return {
59
- ...baseError,
60
- operation: request.operation,
61
- };
62
- default:
63
- throw error;
104
+ case "listWorkspaces": {
105
+ const workspaces = listWorkspaces();
106
+ return {
107
+ type: "rag",
108
+ operation: request.operation,
109
+ success: true,
110
+ workspaces,
111
+ };
112
+ }
113
+ case "closeWorkspace": {
114
+ await closeWorkspace(request);
115
+ return {
116
+ type: "rag",
117
+ operation: request.operation,
118
+ success: true,
119
+ };
120
+ }
121
+ case "deleteWorkspace": {
122
+ await deleteWorkspace(request);
123
+ return {
124
+ type: "rag",
125
+ operation: request.operation,
126
+ success: true,
127
+ };
64
128
  }
65
129
  }
66
130
  }
@@ -1,4 +1,4 @@
1
- import { textToSpeech } from "../../bare/addons/tts/index.js";
1
+ import { textToSpeech } from "../../bare/addons/onnx-tts/index.js";
2
2
  export async function* handleTextToSpeech(request) {
3
3
  const stream = textToSpeech(request);
4
4
  for await (const response of stream) {
@@ -1,4 +1,4 @@
1
- import { transcribeStream } from "../../bare/addons/whispercpp/index.js";
1
+ import { transcribeStream } from "../../bare/addons/whispercpp-transcription/index.js";
2
2
  import { getServerLogger } from "../../../logging/index.js";
3
3
  const logger = getServerLogger();
4
4
  export async function* handleTranscribeStream(request) {
@@ -1,21 +1,12 @@
1
- import { translate } from "../../bare/addons/translation/index.js";
1
+ import { translate } from "../../bare/addons/nmtcpp-translation/index.js";
2
2
  import { getServerLogger } from "../../../logging/index.js";
3
3
  const logger = getServerLogger();
4
4
  export async function* handleTranslate(request) {
5
- const { modelId, text, stream, modelType } = request;
6
- const from = request.modelType === "llm" ? request.from : undefined;
7
- const to = request.modelType === "llm" ? request.to : undefined;
8
- const context = request.modelType === "llm" ? request.context : undefined;
9
5
  try {
10
- const generator = translate({
11
- modelId,
12
- text,
13
- from,
14
- to: to,
15
- stream,
16
- modelType,
17
- context,
18
- });
6
+ // Remove the 'type' field from request and pass the rest to translate
7
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
+ const { type, ...translateParams } = request;
9
+ const generator = translate(translateParams);
19
10
  let stats;
20
11
  let done = false;
21
12
  let buffer = "";
@@ -27,7 +18,7 @@ export async function* handleTranslate(request) {
27
18
  }
28
19
  else {
29
20
  buffer += result.value;
30
- if (stream) {
21
+ if (translateParams.stream) {
31
22
  yield {
32
23
  type: "translate",
33
24
  token: result.value,
@@ -0,0 +1,3 @@
1
+ export declare function isArchiveUrl(url: string): boolean;
2
+ export declare function extractAndValidateShardedArchive(archivePath: string, extractDir: string, signal?: AbortSignal): Promise<string>;
3
+ //# sourceMappingURL=archive.d.ts.map
@@ -0,0 +1,171 @@
1
+ import { promises as fsPromises } from "bare-fs";
2
+ import path from "bare-path";
3
+ import fs from "bare-fs";
4
+ import { createGunzip } from "bare-zlib";
5
+ import tarStream from "tar-stream";
6
+ import { detectShardedModel, generateShardFilenames, extractTensorsFromShards, validateShardedModelCache, } from "./shard-utils.js";
7
+ import { ModelLoadFailedError, ArchiveExtractionFailedError, ArchiveUnsupportedTypeError, ArchiveMissingShardsError, DownloadCancelledError, } from "../../utils/errors-server.js";
8
+ import { getServerLogger } from "../../logging/index.js";
9
+ import { SUPPORTED_ARCHIVE_EXTENSIONS, filenameToArchiveTypeSchema, } from "../../schemas/archive.js";
10
+ const logger = getServerLogger();
11
+ // Gzip magic bytes: 1f 8b 08
12
+ const GZIP_MAGIC_0 = 0x1f;
13
+ const GZIP_MAGIC_1 = 0x8b;
14
+ const GZIP_MAGIC_2 = 0x08;
15
+ export function isArchiveUrl(url) {
16
+ const filename = url.split("/").pop()?.split("?")[0]?.toLowerCase() || "";
17
+ return SUPPORTED_ARCHIVE_EXTENSIONS.some((ext) => filename.endsWith(ext));
18
+ }
19
+ // Whitelist of model file extensions to extract from archives
20
+ const ALLOWED_MODEL_EXTENSIONS = [".gguf", ".tensors.txt"];
21
+ function isModelFile(entryName) {
22
+ const basename = path.basename(entryName);
23
+ // Skip resource forks (._filename)
24
+ if (basename.startsWith("._")) {
25
+ return false;
26
+ }
27
+ return ALLOWED_MODEL_EXTENSIONS.some((ext) => basename.toLowerCase().endsWith(ext));
28
+ }
29
+ async function isGzip(archivePath) {
30
+ return new Promise((resolve, reject) => {
31
+ const stream = fs.createReadStream(archivePath, { start: 0, end: 2 });
32
+ const chunks = [];
33
+ stream.on("data", (chunk) => {
34
+ chunks.push(chunk);
35
+ });
36
+ stream.on("end", () => {
37
+ stream.destroy();
38
+ const buffer = Buffer.concat(chunks);
39
+ // Check for gzip magic bytes
40
+ const isGzipped = buffer[0] === GZIP_MAGIC_0 &&
41
+ buffer[1] === GZIP_MAGIC_1 &&
42
+ buffer[2] === GZIP_MAGIC_2;
43
+ resolve(isGzipped);
44
+ });
45
+ stream.on("error", reject);
46
+ });
47
+ }
48
+ async function extractArchive(archivePath, extractDir, signal) {
49
+ const parseResult = filenameToArchiveTypeSchema.safeParse(archivePath);
50
+ const extensionType = parseResult.success ? parseResult.data : null;
51
+ if (!extensionType) {
52
+ throw new ArchiveUnsupportedTypeError(archivePath);
53
+ }
54
+ if (signal?.aborted) {
55
+ throw new DownloadCancelledError();
56
+ }
57
+ // Detect actual format from magic bytes (extension might be wrong)
58
+ const isGzipped = await isGzip(archivePath);
59
+ const actualType = isGzipped ? "tar.gz" : "tar";
60
+ if (actualType !== extensionType) {
61
+ logger.warn(`⚠️ Archive extension suggests ${extensionType} but content is ${actualType}`);
62
+ }
63
+ await fsPromises.mkdir(extractDir, { recursive: true });
64
+ await extractTarStream(archivePath, extractDir, isGzipped, signal);
65
+ }
66
+ async function extractTarStream(archivePath, extractDir, useGunzip, signal) {
67
+ const extract = tarStream.extract();
68
+ const gunzip = useGunzip ? createGunzip() : null;
69
+ return new Promise((resolve, reject) => {
70
+ let aborted = false;
71
+ let readStream = null;
72
+ const cleanup = () => {
73
+ aborted = true;
74
+ readStream?.destroy();
75
+ gunzip?.destroy();
76
+ extract.destroy();
77
+ };
78
+ if (signal) {
79
+ signal.addEventListener("abort", () => {
80
+ cleanup();
81
+ reject(new DownloadCancelledError());
82
+ });
83
+ }
84
+ extract.on("entry", (header, stream, next) => {
85
+ if (aborted) {
86
+ stream.resume();
87
+ return;
88
+ }
89
+ if (!isModelFile(header.name)) {
90
+ stream.resume();
91
+ next();
92
+ return;
93
+ }
94
+ const filePath = path.join(extractDir, header.name);
95
+ if (header.type === "file") {
96
+ const dir = path.dirname(filePath);
97
+ fs.mkdirSync(dir, { recursive: true });
98
+ const writeStream = fs.createWriteStream(filePath);
99
+ stream.pipe(writeStream);
100
+ writeStream.on("finish", next);
101
+ writeStream.on("error", reject);
102
+ }
103
+ else {
104
+ stream.on("end", next);
105
+ stream.resume();
106
+ }
107
+ });
108
+ extract.on("finish", resolve);
109
+ extract.on("error", reject);
110
+ if (gunzip) {
111
+ gunzip.on("error", reject);
112
+ }
113
+ readStream = fs.createReadStream(archivePath);
114
+ if (gunzip) {
115
+ readStream.pipe(gunzip).pipe(extract);
116
+ }
117
+ else {
118
+ readStream.pipe(extract);
119
+ }
120
+ });
121
+ }
122
+ export async function extractAndValidateShardedArchive(archivePath, extractDir, signal) {
123
+ // Check if shards already extracted
124
+ try {
125
+ const existingFiles = await fsPromises.readdir(extractDir);
126
+ const existingShard = existingFiles.find((f) => detectShardedModel(String(f)).isSharded);
127
+ if (existingShard) {
128
+ const isComplete = await validateShardedModelCache(extractDir, String(existingShard));
129
+ if (isComplete) {
130
+ logger.info(`✅ Archive already extracted: ${extractDir}`);
131
+ const shardFilenames = generateShardFilenames(String(existingShard));
132
+ return path.join(extractDir, shardFilenames[0]);
133
+ }
134
+ logger.warn(`⚠️ Incomplete extraction found, re-extracting archive`);
135
+ }
136
+ }
137
+ catch {
138
+ // Directory doesn't exist, proceed with extraction
139
+ }
140
+ logger.info(`Extracting archive: ${path.basename(archivePath)}`);
141
+ try {
142
+ await extractArchive(archivePath, extractDir, signal);
143
+ }
144
+ catch (error) {
145
+ throw new ArchiveExtractionFailedError(archivePath, error);
146
+ }
147
+ const files = await fsPromises.readdir(extractDir);
148
+ const shardedFile = files.find((f) => detectShardedModel(String(f)).isSharded);
149
+ if (!shardedFile) {
150
+ throw new ModelLoadFailedError(`No sharded model files found in archive. Expected pattern: *-00001-of-0000X.*`);
151
+ }
152
+ const shardedFileName = String(shardedFile);
153
+ const shardInfo = detectShardedModel(shardedFileName);
154
+ if (!shardInfo.baseFilename) {
155
+ throw new ModelLoadFailedError(`Could not extract base filename from sharded model: ${shardedFileName}`);
156
+ }
157
+ const shardFilenames = generateShardFilenames(shardedFileName);
158
+ for (const shardFilename of shardFilenames) {
159
+ const filePath = path.join(extractDir, shardFilename);
160
+ try {
161
+ await fsPromises.access(filePath);
162
+ }
163
+ catch {
164
+ throw new ArchiveMissingShardsError(shardFilename);
165
+ }
166
+ }
167
+ // Generate tensors.txt if it doesn't exist
168
+ await extractTensorsFromShards(extractDir, shardedFileName);
169
+ logger.info(`Archive extracted to ${extractDir} successfully: ${files.length} files`);
170
+ return path.join(extractDir, shardFilenames[0]);
171
+ }
@@ -52,12 +52,12 @@ export async function decodeAudioToStream(inputPath, audioFormat = "s16le") {
52
52
  }
53
53
  }
54
54
  })
55
- .onError((errorMessage) => {
55
+ .onError((error) => {
56
56
  if (!hasEnded) {
57
57
  hasEnded = true;
58
58
  clearTimeout(timeoutId);
59
59
  setImmediate(() => void decoder.unload());
60
- outputStream.destroy(new Error(errorMessage));
60
+ outputStream.destroy(error);
61
61
  }
62
62
  });
63
63
  response.await().catch((error) => {
@@ -1,7 +1,7 @@
1
- import type { ShardMetadata } from "./shard-utils";
2
- export declare const getCacheDir: (subDir: string) => string;
3
- export declare const getModelsCacheDir: () => string;
4
- export declare const getKVCacheDir: () => string;
1
+ import type { ShardFileMetadata } from "../../schemas/index";
2
+ export declare function getCacheDir(subDir: string): string;
3
+ export declare function getModelsCacheDir(): string;
4
+ export declare function getKVCacheDir(): string;
5
5
  /**
6
6
  * Get cache directory for sharded model
7
7
  * Returns: cache/sharded/<hyperdriveKey>/
@@ -16,5 +16,5 @@ export declare function getShardPath(hyperdriveKey: string, shardFilename: strin
16
16
  * Check if all shards exist and are valid (size + checksum check)
17
17
  * Returns array of missing/invalid shard indices (0-based)
18
18
  */
19
- export declare function checkShardCompleteness(hyperdriveKey: string, shardFilenames: readonly string[], shardMetadata: readonly ShardMetadata[]): Promise<number[]>;
19
+ export declare function checkShardCompleteness(hyperdriveKey: string, shardFilenames: readonly string[], shardMetadata: readonly ShardFileMetadata[]): Promise<number[]>;
20
20
  //# sourceMappingURL=cache.d.ts.map
@@ -5,7 +5,7 @@ import { getConfiguredCacheDir } from "../bare/registry/config-registry.js";
5
5
  import { calculateFileChecksum } from "./checksum.js";
6
6
  import { getServerLogger } from "../../logging/index.js";
7
7
  const logger = getServerLogger();
8
- export const getCacheDir = (subDir) => {
8
+ export function getCacheDir(subDir) {
9
9
  const homeDir = getEnv().HOME_DIR;
10
10
  const cacheDir = path.join(homeDir, ".qvac", subDir);
11
11
  try {
@@ -15,8 +15,8 @@ export const getCacheDir = (subDir) => {
15
15
  logger.error(`Error creating cache directory (${subDir}):`, error instanceof Error ? error.message : String(error));
16
16
  }
17
17
  return cacheDir;
18
- };
19
- export const getModelsCacheDir = () => {
18
+ }
19
+ export function getModelsCacheDir() {
20
20
  const configuredDir = getConfiguredCacheDir();
21
21
  try {
22
22
  fs.mkdirSync(configuredDir, { recursive: true });
@@ -25,10 +25,10 @@ export const getModelsCacheDir = () => {
25
25
  logger.error(`Error creating models cache directory:`, error instanceof Error ? error.message : String(error));
26
26
  }
27
27
  return configuredDir;
28
- };
29
- export const getKVCacheDir = () => {
28
+ }
29
+ export function getKVCacheDir() {
30
30
  return getCacheDir("kv-cache");
31
- };
31
+ }
32
32
  /**
33
33
  * Get cache directory for sharded model
34
34
  * Returns: cache/sharded/<hyperdriveKey>/
@@ -1,3 +1,3 @@
1
- import type { ModelType } from "../../schemas/index";
2
- export declare function transformConfigForReload(modelType: ModelType, config: unknown): unknown;
1
+ import { type ModelTypeInput } from "../../schemas/index";
2
+ export declare function transformConfigForReload(modelType: ModelTypeInput, config: unknown): unknown;
3
3
  //# sourceMappingURL=config-transform.d.ts.map
@@ -1,6 +1,8 @@
1
+ import { normalizeModelType, ModelType, } from "../../schemas/index.js";
1
2
  export function transformConfigForReload(modelType, config) {
2
- switch (modelType) {
3
- case "whisper": {
3
+ const canonicalType = normalizeModelType(modelType);
4
+ switch (canonicalType) {
5
+ case ModelType.whispercppTranscription: {
4
6
  const whisperConfig = config;
5
7
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
8
  const { contextParams, miscConfig, ...whisperParams } = whisperConfig;
@@ -9,10 +11,10 @@ export function transformConfigForReload(modelType, config) {
9
11
  ...(miscConfig && { miscConfig }),
10
12
  };
11
13
  }
12
- case "llm":
13
- case "embeddings":
14
- case "nmt":
15
- case "tts":
14
+ case ModelType.llamacppCompletion:
15
+ case ModelType.llamacppEmbedding:
16
+ case ModelType.nmtcppTranslation:
17
+ case ModelType.onnxTts:
16
18
  // Return as-is for now
17
19
  return config;
18
20
  default:
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Generate a short hash (16 characters) from any input string
3
+ */
4
+ export declare function generateShortHash(input: string): string;
5
+ /**
6
+ * Calculate progress percentage with bounds checking and consistent formatting
7
+ * @param current - Current progress value
8
+ * @param total - Total value
9
+ * @param decimals - Number of decimal places (default: 2)
10
+ * @returns Percentage clamped between 0-100 with fixed decimal places
11
+ */
12
+ export declare function calculatePercentage(current: number, total: number, decimals?: number): number;
13
+ //# sourceMappingURL=formatting.d.ts.map
@@ -0,0 +1,26 @@
1
+ import crypto from "bare-crypto";
2
+ /**
3
+ * Generate a short hash (16 characters) from any input string
4
+ */
5
+ export function generateShortHash(input) {
6
+ const hash = crypto
7
+ .createHash("sha256")
8
+ .update(Buffer.from(input, "utf8"))
9
+ .digest("hex");
10
+ return hash.substring(0, 16);
11
+ }
12
+ /**
13
+ * Calculate progress percentage with bounds checking and consistent formatting
14
+ * @param current - Current progress value
15
+ * @param total - Total value
16
+ * @param decimals - Number of decimal places (default: 2)
17
+ * @returns Percentage clamped between 0-100 with fixed decimal places
18
+ */
19
+ export function calculatePercentage(current, total, decimals = 2) {
20
+ if (total <= 0 || current < 0) {
21
+ return 0;
22
+ }
23
+ const rawPercentage = (current / total) * 100;
24
+ const clampedPercentage = Math.min(Math.max(rawPercentage, 0), 100);
25
+ return Number(clampedPercentage.toFixed(decimals));
26
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Extract tensor names from all GGUF shards and write to {baseFilename}.tensors.txt
3
+ * Required for sharded models to enable incremental/async loading
4
+ * @throws ModelLoadFailedError if any shard fails extraction
5
+ */
6
+ export declare function extractAndWriteTensorsFile(shardDir: string, shardFilenames: string[], baseFilename: string): Promise<string>;
7
+ /**
8
+ * Check if a file has a valid GGUF header structure.
9
+ * Returns true if the header parses successfully and contains tensor metadata.
10
+ *
11
+ * NOTE: This only validates the header structure, NOT that tensor data exists.
12
+ * A file can have a valid header but be incomplete.
13
+ */
14
+ export declare function hasValidGGUFHeader(filePath: string): Promise<boolean>;
15
+ //# sourceMappingURL=gguf-tensor-extractor.d.ts.map