@qvac/sdk 0.1.0-dev.1760648187.328e967

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 (287) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +301 -0
  3. package/dist/client/api/cancel.d.ts +25 -0
  4. package/dist/client/api/cancel.js +37 -0
  5. package/dist/client/api/completion-stream.d.ts +50 -0
  6. package/dist/client/api/completion-stream.js +103 -0
  7. package/dist/client/api/download-asset.d.ts +39 -0
  8. package/dist/client/api/download-asset.js +72 -0
  9. package/dist/client/api/embed.d.ts +11 -0
  10. package/dist/client/api/embed.js +24 -0
  11. package/dist/client/api/index.d.ts +13 -0
  12. package/dist/client/api/index.js +12 -0
  13. package/dist/client/api/load-model.d.ts +98 -0
  14. package/dist/client/api/load-model.js +154 -0
  15. package/dist/client/api/logging-stream.d.ts +21 -0
  16. package/dist/client/api/logging-stream.js +32 -0
  17. package/dist/client/api/ping.d.ts +11 -0
  18. package/dist/client/api/ping.js +18 -0
  19. package/dist/client/api/provide.d.ts +18 -0
  20. package/dist/client/api/provide.js +27 -0
  21. package/dist/client/api/rag.d.ts +42 -0
  22. package/dist/client/api/rag.js +97 -0
  23. package/dist/client/api/transcribe.d.ts +24 -0
  24. package/dist/client/api/transcribe.js +52 -0
  25. package/dist/client/api/translate.d.ts +47 -0
  26. package/dist/client/api/translate.js +114 -0
  27. package/dist/client/api/unload-model.d.ts +11 -0
  28. package/dist/client/api/unload-model.js +26 -0
  29. package/dist/client/index.d.ts +2 -0
  30. package/dist/client/index.js +1 -0
  31. package/dist/client/logging-stream-registry.d.ts +5 -0
  32. package/dist/client/logging-stream-registry.js +60 -0
  33. package/dist/client/rpc/bare-client.d.ts +112 -0
  34. package/dist/client/rpc/bare-client.js +82 -0
  35. package/dist/client/rpc/bare-rpc-client.d.ts +4 -0
  36. package/dist/client/rpc/bare-rpc-client.js +87 -0
  37. package/dist/client/rpc/expo-rpc-client.d.ts +3 -0
  38. package/dist/client/rpc/expo-rpc-client.js +57 -0
  39. package/dist/client/rpc/node-rpc-client.d.ts +9 -0
  40. package/dist/client/rpc/node-rpc-client.js +99 -0
  41. package/dist/client/rpc/rpc-client.d.ts +5 -0
  42. package/dist/client/rpc/rpc-client.js +91 -0
  43. package/dist/client/rpc/rpc-error.d.ts +19 -0
  44. package/dist/client/rpc/rpc-error.js +39 -0
  45. package/dist/constants/audio.d.ts +3 -0
  46. package/dist/constants/audio.js +17 -0
  47. package/dist/constants/index.d.ts +2 -0
  48. package/dist/constants/index.js +1 -0
  49. package/dist/examples/delegated-inference/consumer.d.ts +2 -0
  50. package/dist/examples/delegated-inference/consumer.js +56 -0
  51. package/dist/examples/delegated-inference/provider.d.ts +2 -0
  52. package/dist/examples/delegated-inference/provider.js +57 -0
  53. package/dist/examples/download-with-cancel.d.ts +2 -0
  54. package/dist/examples/download-with-cancel.js +46 -0
  55. package/dist/examples/embed-hyperdrive.d.ts +2 -0
  56. package/dist/examples/embed-hyperdrive.js +19 -0
  57. package/dist/examples/kv-cache-example.d.ts +2 -0
  58. package/dist/examples/kv-cache-example.js +74 -0
  59. package/dist/examples/llamacpp-file-logging.d.ts +2 -0
  60. package/dist/examples/llamacpp-file-logging.js +62 -0
  61. package/dist/examples/llamacpp-filesystem.d.ts +2 -0
  62. package/dist/examples/llamacpp-filesystem.js +40 -0
  63. package/dist/examples/llamacpp-http.d.ts +2 -0
  64. package/dist/examples/llamacpp-http.js +41 -0
  65. package/dist/examples/llamacpp-hyperdrive.d.ts +2 -0
  66. package/dist/examples/llamacpp-hyperdrive.js +39 -0
  67. package/dist/examples/llamacpp-multimodal.d.ts +2 -0
  68. package/dist/examples/llamacpp-multimodal.js +62 -0
  69. package/dist/examples/llamacpp-native-tools.d.ts +2 -0
  70. package/dist/examples/llamacpp-native-tools.js +64 -0
  71. package/dist/examples/llamacpp-tools-routing.d.ts +2 -0
  72. package/dist/examples/llamacpp-tools-routing.js +364 -0
  73. package/dist/examples/llamacpp-tools.d.ts +2 -0
  74. package/dist/examples/llamacpp-tools.js +81 -0
  75. package/dist/examples/multi-model-demo.d.ts +2 -0
  76. package/dist/examples/multi-model-demo.js +75 -0
  77. package/dist/examples/parallel-download.d.ts +2 -0
  78. package/dist/examples/parallel-download.js +21 -0
  79. package/dist/examples/rag/rag-chromadb.d.ts +2 -0
  80. package/dist/examples/rag/rag-chromadb.js +130 -0
  81. package/dist/examples/rag/rag-hyperdb-workspaces.d.ts +2 -0
  82. package/dist/examples/rag/rag-hyperdb-workspaces.js +106 -0
  83. package/dist/examples/rag/rag-hyperdb.d.ts +2 -0
  84. package/dist/examples/rag/rag-hyperdb.js +50 -0
  85. package/dist/examples/rag/rag-lancedb.d.ts +2 -0
  86. package/dist/examples/rag/rag-lancedb.js +95 -0
  87. package/dist/examples/rag/rag-sqlite.d.ts +2 -0
  88. package/dist/examples/rag/rag-sqlite.js +107 -0
  89. package/dist/examples/seed-hyperdrive.d.ts +2 -0
  90. package/dist/examples/seed-hyperdrive.js +21 -0
  91. package/dist/examples/translation/translation-indic.d.ts +2 -0
  92. package/dist/examples/translation/translation-indic.js +30 -0
  93. package/dist/examples/translation/translation-llm-context.d.ts +2 -0
  94. package/dist/examples/translation/translation-llm-context.js +30 -0
  95. package/dist/examples/translation/translation-llm.d.ts +2 -0
  96. package/dist/examples/translation/translation-llm.js +38 -0
  97. package/dist/examples/translation/translation-opus.d.ts +2 -0
  98. package/dist/examples/translation/translation-opus.js +30 -0
  99. package/dist/examples/translation/translation-stream.d.ts +2 -0
  100. package/dist/examples/translation/translation-stream.js +35 -0
  101. package/dist/examples/whispercpp-filesystem.d.ts +2 -0
  102. package/dist/examples/whispercpp-filesystem.js +43 -0
  103. package/dist/examples/whispercpp-microphone-record.d.ts +2 -0
  104. package/dist/examples/whispercpp-microphone-record.js +311 -0
  105. package/dist/expo/plugins/index.d.ts +5 -0
  106. package/dist/expo/plugins/index.js +5 -0
  107. package/dist/expo/plugins/withMobileBundle.d.ts +8 -0
  108. package/dist/expo/plugins/withMobileBundle.js +60 -0
  109. package/dist/expo/plugins/withOpenCL.d.ts +9 -0
  110. package/dist/expo/plugins/withOpenCL.js +118 -0
  111. package/dist/expo/plugins/withQvacSDK.d.ts +9 -0
  112. package/dist/expo/plugins/withQvacSDK.js +13 -0
  113. package/dist/index.d.ts +7 -0
  114. package/dist/index.js +8 -0
  115. package/dist/logging/base-logger.d.ts +7 -0
  116. package/dist/logging/base-logger.js +55 -0
  117. package/dist/logging/index.d.ts +4 -0
  118. package/dist/logging/index.js +2 -0
  119. package/dist/logging/logger.d.ts +5 -0
  120. package/dist/logging/logger.js +28 -0
  121. package/dist/logging/stream-logger.d.ts +3 -0
  122. package/dist/logging/stream-logger.js +9 -0
  123. package/dist/logging/transport.d.ts +3 -0
  124. package/dist/logging/transport.js +15 -0
  125. package/dist/logging/types.d.ts +18 -0
  126. package/dist/logging/types.js +1 -0
  127. package/dist/logging/utils.d.ts +4 -0
  128. package/dist/logging/utils.js +47 -0
  129. package/dist/models/hyperdrive/index.d.ts +2 -0
  130. package/dist/models/hyperdrive/index.js +2 -0
  131. package/dist/models/hyperdrive/models.d.ts +475 -0
  132. package/dist/models/hyperdrive/models.js +534 -0
  133. package/dist/schemas/cancel.d.ts +33 -0
  134. package/dist/schemas/cancel.js +25 -0
  135. package/dist/schemas/common.d.ts +626 -0
  136. package/dist/schemas/common.js +47 -0
  137. package/dist/schemas/completion-stream.d.ts +125 -0
  138. package/dist/schemas/completion-stream.js +53 -0
  139. package/dist/schemas/delegate.d.ts +9 -0
  140. package/dist/schemas/delegate.js +9 -0
  141. package/dist/schemas/download-asset.d.ts +75 -0
  142. package/dist/schemas/download-asset.js +43 -0
  143. package/dist/schemas/embed.d.ts +20 -0
  144. package/dist/schemas/embed.js +14 -0
  145. package/dist/schemas/error.d.ts +13 -0
  146. package/dist/schemas/error.js +35 -0
  147. package/dist/schemas/index.d.ts +19 -0
  148. package/dist/schemas/index.js +19 -0
  149. package/dist/schemas/llamacpp-config.d.ts +30 -0
  150. package/dist/schemas/llamacpp-config.js +39 -0
  151. package/dist/schemas/load-model.d.ts +1259 -0
  152. package/dist/schemas/load-model.js +108 -0
  153. package/dist/schemas/logging-stream.d.ts +27 -0
  154. package/dist/schemas/logging-stream.js +16 -0
  155. package/dist/schemas/ping.d.ts +11 -0
  156. package/dist/schemas/ping.js +8 -0
  157. package/dist/schemas/provide.d.ts +43 -0
  158. package/dist/schemas/provide.js +25 -0
  159. package/dist/schemas/rag.d.ts +159 -0
  160. package/dist/schemas/rag.js +78 -0
  161. package/dist/schemas/transcription.d.ts +24 -0
  162. package/dist/schemas/transcription.js +15 -0
  163. package/dist/schemas/translate.d.ts +82 -0
  164. package/dist/schemas/translate.js +42 -0
  165. package/dist/schemas/translation-config.d.ts +83 -0
  166. package/dist/schemas/translation-config.js +46 -0
  167. package/dist/schemas/unload-model.d.ts +19 -0
  168. package/dist/schemas/unload-model.js +13 -0
  169. package/dist/schemas/whispercpp-config.d.ts +25 -0
  170. package/dist/schemas/whispercpp-config.js +18 -0
  171. package/dist/server/bare/addons/cancel.d.ts +3 -0
  172. package/dist/server/bare/addons/cancel.js +12 -0
  173. package/dist/server/bare/addons/index.d.ts +4 -0
  174. package/dist/server/bare/addons/index.js +3 -0
  175. package/dist/server/bare/addons/llamacpp/create-model.d.ts +5 -0
  176. package/dist/server/bare/addons/llamacpp/create-model.js +57 -0
  177. package/dist/server/bare/addons/llamacpp/handlers/completion-stream.d.ts +3 -0
  178. package/dist/server/bare/addons/llamacpp/handlers/completion-stream.js +65 -0
  179. package/dist/server/bare/addons/llamacpp/handlers/embed.d.ts +4 -0
  180. package/dist/server/bare/addons/llamacpp/handlers/embed.js +40 -0
  181. package/dist/server/bare/addons/llamacpp/index.d.ts +4 -0
  182. package/dist/server/bare/addons/llamacpp/index.js +3 -0
  183. package/dist/server/bare/addons/llamacpp/kv-cache-utils.d.ts +19 -0
  184. package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +46 -0
  185. package/dist/server/bare/addons/load-model.d.ts +3 -0
  186. package/dist/server/bare/addons/load-model.js +55 -0
  187. package/dist/server/bare/addons/translation/create-model.d.ts +4 -0
  188. package/dist/server/bare/addons/translation/create-model.js +45 -0
  189. package/dist/server/bare/addons/translation/handlers/translate.d.ts +3 -0
  190. package/dist/server/bare/addons/translation/handlers/translate.js +86 -0
  191. package/dist/server/bare/addons/translation/index.d.ts +3 -0
  192. package/dist/server/bare/addons/translation/index.js +2 -0
  193. package/dist/server/bare/addons/unload-model.d.ts +3 -0
  194. package/dist/server/bare/addons/unload-model.js +20 -0
  195. package/dist/server/bare/addons/whispercpp/create-model.d.ts +6 -0
  196. package/dist/server/bare/addons/whispercpp/create-model.js +55 -0
  197. package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.d.ts +3 -0
  198. package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +42 -0
  199. package/dist/server/bare/addons/whispercpp/index.d.ts +3 -0
  200. package/dist/server/bare/addons/whispercpp/index.js +2 -0
  201. package/dist/server/bare/delegate-rpc-client.d.ts +4 -0
  202. package/dist/server/bare/delegate-rpc-client.js +70 -0
  203. package/dist/server/bare/hyperswarm.d.ts +7 -0
  204. package/dist/server/bare/hyperswarm.js +62 -0
  205. package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +3 -0
  206. package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +12 -0
  207. package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +6 -0
  208. package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +16 -0
  209. package/dist/server/bare/rag-hyperdb/handlers/search.d.ts +3 -0
  210. package/dist/server/bare/rag-hyperdb/handlers/search.js +15 -0
  211. package/dist/server/bare/rag-hyperdb/index.d.ts +5 -0
  212. package/dist/server/bare/rag-hyperdb/index.js +4 -0
  213. package/dist/server/bare/rag-hyperdb/rag-manager.d.ts +5 -0
  214. package/dist/server/bare/rag-hyperdb/rag-manager.js +61 -0
  215. package/dist/server/bare/registry/logging-stream-registry.d.ts +12 -0
  216. package/dist/server/bare/registry/logging-stream-registry.js +46 -0
  217. package/dist/server/bare/registry/model-registry.d.ts +64 -0
  218. package/dist/server/bare/registry/model-registry.js +95 -0
  219. package/dist/server/error-handlers.d.ts +4 -0
  220. package/dist/server/error-handlers.js +27 -0
  221. package/dist/server/http-server.d.ts +2 -0
  222. package/dist/server/http-server.js +189 -0
  223. package/dist/server/rpc/create-server.d.ts +4 -0
  224. package/dist/server/rpc/create-server.js +19 -0
  225. package/dist/server/rpc/handle-request.d.ts +12 -0
  226. package/dist/server/rpc/handle-request.js +220 -0
  227. package/dist/server/rpc/handlers/cancelHandler.d.ts +3 -0
  228. package/dist/server/rpc/handlers/cancelHandler.js +27 -0
  229. package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +3 -0
  230. package/dist/server/rpc/handlers/completion-stream-delegated.js +30 -0
  231. package/dist/server/rpc/handlers/completion-stream.d.ts +3 -0
  232. package/dist/server/rpc/handlers/completion-stream.js +52 -0
  233. package/dist/server/rpc/handlers/download-asset.d.ts +3 -0
  234. package/dist/server/rpc/handlers/download-asset.js +21 -0
  235. package/dist/server/rpc/handlers/embed.d.ts +3 -0
  236. package/dist/server/rpc/handlers/embed.js +21 -0
  237. package/dist/server/rpc/handlers/index.d.ts +23 -0
  238. package/dist/server/rpc/handlers/index.js +22 -0
  239. package/dist/server/rpc/handlers/load-model/download-manager.d.ts +31 -0
  240. package/dist/server/rpc/handlers/load-model/download-manager.js +88 -0
  241. package/dist/server/rpc/handlers/load-model/http.d.ts +3 -0
  242. package/dist/server/rpc/handlers/load-model/http.js +337 -0
  243. package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +4 -0
  244. package/dist/server/rpc/handlers/load-model/hyperdrive.js +332 -0
  245. package/dist/server/rpc/handlers/load-model/index.d.ts +4 -0
  246. package/dist/server/rpc/handlers/load-model/index.js +3 -0
  247. package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -0
  248. package/dist/server/rpc/handlers/load-model/resolve.js +121 -0
  249. package/dist/server/rpc/handlers/load-model-delegated.d.ts +3 -0
  250. package/dist/server/rpc/handlers/load-model-delegated.js +93 -0
  251. package/dist/server/rpc/handlers/load-model.d.ts +3 -0
  252. package/dist/server/rpc/handlers/load-model.js +41 -0
  253. package/dist/server/rpc/handlers/logging-stream.d.ts +3 -0
  254. package/dist/server/rpc/handlers/logging-stream.js +37 -0
  255. package/dist/server/rpc/handlers/provideHandler/connection.d.ts +3 -0
  256. package/dist/server/rpc/handlers/provideHandler/connection.js +25 -0
  257. package/dist/server/rpc/handlers/provideHandler/handler.d.ts +3 -0
  258. package/dist/server/rpc/handlers/provideHandler/handler.js +50 -0
  259. package/dist/server/rpc/handlers/provideHandler/proxy.d.ts +3 -0
  260. package/dist/server/rpc/handlers/provideHandler/proxy.js +22 -0
  261. package/dist/server/rpc/handlers/provideHandler.d.ts +2 -0
  262. package/dist/server/rpc/handlers/provideHandler.js +2 -0
  263. package/dist/server/rpc/handlers/rag.d.ts +3 -0
  264. package/dist/server/rpc/handlers/rag.js +67 -0
  265. package/dist/server/rpc/handlers/transcribe-stream.d.ts +3 -0
  266. package/dist/server/rpc/handlers/transcribe-stream.js +26 -0
  267. package/dist/server/rpc/handlers/translate.d.ts +3 -0
  268. package/dist/server/rpc/handlers/translate.js +51 -0
  269. package/dist/server/rpc/handlers/unload-model.d.ts +3 -0
  270. package/dist/server/rpc/handlers/unload-model.js +20 -0
  271. package/dist/server/rpc/index.d.ts +3 -0
  272. package/dist/server/rpc/index.js +2 -0
  273. package/dist/server/utils/audio/decoder.d.ts +4 -0
  274. package/dist/server/utils/audio/decoder.js +41 -0
  275. package/dist/server/utils/cache.d.ts +15 -0
  276. package/dist/server/utils/cache.js +32 -0
  277. package/dist/server/utils/hash.d.ts +5 -0
  278. package/dist/server/utils/hash.js +11 -0
  279. package/dist/server/utils/index.d.ts +5 -0
  280. package/dist/server/utils/index.js +4 -0
  281. package/dist/server/utils/model-path.d.ts +5 -0
  282. package/dist/server/utils/model-path.js +7 -0
  283. package/dist/server/worker.d.ts +6 -0
  284. package/dist/server/worker.js +77 -0
  285. package/dist/utils/withTimeout.d.ts +11 -0
  286. package/dist/utils/withTimeout.js +37 -0
  287. package/package.json +129 -0
@@ -0,0 +1,103 @@
1
+ import { completionStreamResponseSchema, } from "../../schemas/index.js";
2
+ import { stream as streamRpc } from "../rpc/rpc-client.js";
3
+ /**
4
+ * Generates completion from a language model based on conversation history.
5
+ *
6
+ * @param params - The completion parameters
7
+ * @param params.modelId - The identifier of the model to use for completion
8
+ * @param params.history - Array of conversation messages with role, content, and optional attachments
9
+ * @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true
10
+ * @param params.tools - Optional array of tools that can be used by the model
11
+ * @param params.kvCache - Optional boolean to enable KV cache for faster subsequent completions
12
+ * @returns Object with tokenStream generator, text promise, and stats promise
13
+ * @example
14
+ * ```typescript
15
+ * // Streaming mode
16
+ * const result = completion({
17
+ * modelId: "llama-2",
18
+ * history: [
19
+ * { role: "user", content: "Hello, how are you?" }
20
+ * ],
21
+ * stream: true,
22
+ * });
23
+ *
24
+ * for await (const token of result.tokenStream) {
25
+ * console.log(token);
26
+ * }
27
+ *
28
+ * const stats = await result.stats;
29
+ * console.log("Performance:", stats);
30
+ *
31
+ * // Non-streaming mode
32
+ * const response = completion({
33
+ * modelId: "llama-2",
34
+ * history: [
35
+ * { role: "user", content: "What is the capital of France?" }
36
+ * ],
37
+ * stream: false,
38
+ * });
39
+ *
40
+ * const text = await response.text;
41
+ * const stats = await response.stats;
42
+ * console.log(text);
43
+ * console.log(stats);
44
+ * ```
45
+ */
46
+ export function completion(params) {
47
+ const request = {
48
+ type: "completionStream",
49
+ ...params,
50
+ stream: params.stream ?? true,
51
+ };
52
+ let stats;
53
+ let statsResolver = () => { };
54
+ const statsPromise = new Promise((resolve) => {
55
+ statsResolver = resolve;
56
+ });
57
+ if (params.stream) {
58
+ const tokenStream = (async function* () {
59
+ for await (const response of streamRpc(request)) {
60
+ if (response.type === "completionStream") {
61
+ const streamResponse = completionStreamResponseSchema.parse(response);
62
+ if (!streamResponse.done) {
63
+ yield streamResponse.token;
64
+ }
65
+ else {
66
+ stats = streamResponse.stats;
67
+ statsResolver(stats);
68
+ }
69
+ }
70
+ }
71
+ })();
72
+ const textPromise = Promise.resolve("");
73
+ return {
74
+ tokenStream,
75
+ text: textPromise,
76
+ stats: statsPromise,
77
+ };
78
+ }
79
+ else {
80
+ const tokenStream = (async function* () {
81
+ //Empty generator for non-streaming mode
82
+ })();
83
+ const textPromise = (async () => {
84
+ let buffer = "";
85
+ for await (const response of streamRpc(request)) {
86
+ if (response.type === "completionStream") {
87
+ const streamResponse = completionStreamResponseSchema.parse(response);
88
+ buffer += streamResponse.token;
89
+ if (streamResponse.done) {
90
+ stats = streamResponse.stats;
91
+ statsResolver(stats);
92
+ }
93
+ }
94
+ }
95
+ return buffer;
96
+ })();
97
+ return {
98
+ tokenStream,
99
+ text: textPromise,
100
+ stats: statsPromise,
101
+ };
102
+ }
103
+ }
@@ -0,0 +1,39 @@
1
+ import { type DownloadAssetOptions as BaseDownloadAssetOptions } from "../../schemas/index";
2
+ export type DownloadAssetOptions = BaseDownloadAssetOptions;
3
+ /**
4
+ * Downloads an asset (model file) without loading it into memory.
5
+ *
6
+ * This function is specifically designed for download-only operations and
7
+ * doesn't accept runtime configuration options like modelConfig or delegate.
8
+ * Use this for download-only operations instead of loadModel for better semantic clarity.
9
+ *
10
+ * @param options - Download configuration including:
11
+ * - assetSrc: The location from which the asset is downloaded (local path, remote URL, or Hyperdrive URL)
12
+ * - seed: Optional boolean for hyperdrive seeding
13
+ * - onProgress: Optional callback for download progress
14
+ *
15
+ * @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID)
16
+ *
17
+ * @throws {Error} When asset download fails, with details in the error message
18
+ * @throws {Error} When streaming ends unexpectedly (only when using onProgress)
19
+ * @throws {Error} When receiving an invalid response type from the server
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Download model without loading
24
+ * const assetId = await downloadAsset({
25
+ * assetSrc: "/path/to/model.gguf",
26
+ * seed: true
27
+ * });
28
+ *
29
+ * // Download with progress tracking
30
+ * const assetId = await downloadAsset({
31
+ * assetSrc: "pear://key123/model.gguf",
32
+ * onProgress: (progress) => {
33
+ * console.log(`Downloaded: ${progress.percentage}%`);
34
+ * }
35
+ * });
36
+ * ```
37
+ */
38
+ export declare function downloadAsset(options: DownloadAssetOptions): Promise<string>;
39
+ //# sourceMappingURL=download-asset.d.ts.map
@@ -0,0 +1,72 @@
1
+ import { send, stream } from "../rpc/rpc-client.js";
2
+ import { downloadAssetRequestSchema, } from "../../schemas/index.js";
3
+ /**
4
+ * Downloads an asset (model file) without loading it into memory.
5
+ *
6
+ * This function is specifically designed for download-only operations and
7
+ * doesn't accept runtime configuration options like modelConfig or delegate.
8
+ * Use this for download-only operations instead of loadModel for better semantic clarity.
9
+ *
10
+ * @param options - Download configuration including:
11
+ * - assetSrc: The location from which the asset is downloaded (local path, remote URL, or Hyperdrive URL)
12
+ * - seed: Optional boolean for hyperdrive seeding
13
+ * - onProgress: Optional callback for download progress
14
+ *
15
+ * @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID)
16
+ *
17
+ * @throws {Error} When asset download fails, with details in the error message
18
+ * @throws {Error} When streaming ends unexpectedly (only when using onProgress)
19
+ * @throws {Error} When receiving an invalid response type from the server
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Download model without loading
24
+ * const assetId = await downloadAsset({
25
+ * assetSrc: "/path/to/model.gguf",
26
+ * seed: true
27
+ * });
28
+ *
29
+ * // Download with progress tracking
30
+ * const assetId = await downloadAsset({
31
+ * assetSrc: "pear://key123/model.gguf",
32
+ * onProgress: (progress) => {
33
+ * console.log(`Downloaded: ${progress.percentage}%`);
34
+ * }
35
+ * });
36
+ * ```
37
+ */
38
+ export async function downloadAsset(options) {
39
+ const { assetSrc } = options;
40
+ const request = downloadAssetRequestSchema.parse({
41
+ type: "downloadAsset",
42
+ assetSrc: assetSrc,
43
+ withProgress: !!options.onProgress,
44
+ seed: options.seed,
45
+ });
46
+ if (options.onProgress) {
47
+ // Use streaming for progress updates
48
+ for await (const response of stream(request)) {
49
+ if (response.type === "modelProgress") {
50
+ options.onProgress(response);
51
+ }
52
+ else if (response.type === "downloadAsset") {
53
+ if (!response.success) {
54
+ throw new Error(response.error ?? "Failed to download asset");
55
+ }
56
+ return response.assetId ?? assetSrc;
57
+ }
58
+ }
59
+ throw new Error("Stream ended without final response");
60
+ }
61
+ else {
62
+ // Use regular send for simple downloading
63
+ const response = await send(request);
64
+ if (response.type !== "downloadAsset") {
65
+ throw new Error("Invalid response type");
66
+ }
67
+ if (!response.success) {
68
+ throw new Error(response.error ?? "Failed to download asset");
69
+ }
70
+ return response.assetId ?? assetSrc;
71
+ }
72
+ }
@@ -0,0 +1,11 @@
1
+ import { type EmbedParams } from "../../schemas/index";
2
+ /**
3
+ * Generates embeddings for a given text using a specified model.
4
+ *
5
+ * @param params - The parameters for the embedding
6
+ * @param params.modelId - The identifier of the embedding model to use
7
+ * @param params.text - The input text to embed
8
+ * @throws {Error} When the response type is invalid or when the embedding fails
9
+ */
10
+ export declare function embed(params: EmbedParams): Promise<number[]>;
11
+ //# sourceMappingURL=embed.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { send } from "../rpc/rpc-client.js";
2
+ import {} from "../../schemas/index.js";
3
+ /**
4
+ * Generates embeddings for a given text using a specified model.
5
+ *
6
+ * @param params - The parameters for the embedding
7
+ * @param params.modelId - The identifier of the embedding model to use
8
+ * @param params.text - The input text to embed
9
+ * @throws {Error} When the response type is invalid or when the embedding fails
10
+ */
11
+ export async function embed(params) {
12
+ const request = {
13
+ type: "embed",
14
+ ...params,
15
+ };
16
+ const response = await send(request);
17
+ if (response.type !== "embed") {
18
+ throw new Error("Invalid response type");
19
+ }
20
+ if (!response.success) {
21
+ throw new Error(response.error ?? "Failed to embed");
22
+ }
23
+ return response.embedding;
24
+ }
@@ -0,0 +1,13 @@
1
+ export { loadModel } from "./load-model";
2
+ export { downloadAsset } from "./download-asset";
3
+ export { completion } from "./completion-stream";
4
+ export { unloadModel } from "./unload-model";
5
+ export { loggingStream } from "./logging-stream";
6
+ export { ping } from "./ping";
7
+ export { transcribe, transcribeStream } from "./transcribe";
8
+ export { embed } from "./embed";
9
+ export { translate } from "./translate";
10
+ export { cancel } from "./cancel";
11
+ export { startQVACProvider } from "./provide";
12
+ export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag";
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ export { loadModel } from "./load-model.js";
2
+ export { downloadAsset } from "./download-asset.js";
3
+ export { completion } from "./completion-stream.js";
4
+ export { unloadModel } from "./unload-model.js";
5
+ export { loggingStream } from "./logging-stream.js";
6
+ export { ping } from "./ping.js";
7
+ export { transcribe, transcribeStream } from "./transcribe.js";
8
+ export { embed } from "./embed.js";
9
+ export { translate } from "./translate.js";
10
+ export { cancel } from "./cancel.js";
11
+ export { startQVACProvider } from "./provide.js";
12
+ export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag.js";
@@ -0,0 +1,98 @@
1
+ import { type Logger } from "../../logging/index";
2
+ import { type LoadModelOptions as BaseLoadModelOptions } from "../../schemas/index";
3
+ export type LoadModelOptions = BaseLoadModelOptions & {
4
+ logger?: Logger;
5
+ };
6
+ /**
7
+ * Loads a machine learning model from a local path, remote URL, or Hyperdrive key.
8
+ *
9
+ * This function supports three model types: LLM (Large Language Model), Whisper (speech recognition),
10
+ * and embeddings. It can handle both local file paths and Hyperdrive URLs (pear://).
11
+ *
12
+ * When `onProgress` is provided, the function uses streaming to provide real-time download progress.
13
+ * Otherwise, it uses a simple request-response pattern for faster execution.
14
+ *
15
+ * @param options - An object that defines all configuration parameters required for loading the model, including:
16
+ * - modelSrc: The location from which the model weights are fetched (local path, remote URL, or Hyperdrive URL)
17
+ * - modelType: The type of model ("llm", "whisper", "embeddings", or "nmt")
18
+ * - modelConfig: Model-specific configuration options
19
+ * - projectionModelSrc: (LLM only) Projection model source for multimodal models
20
+ * - vadModelSrc: (Whisper only) VAD model source for voice activity detection
21
+ *
22
+ * @returns Promise that resolves to the model ID (either the provided modelSrc or a generated ID)
23
+ *
24
+ * @throws {Error} When model loading fails, with details in the error message
25
+ * @throws {Error} When streaming ends unexpectedly (only when using onProgress)
26
+ * @throws {Error} When receiving an invalid response type from the server
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // Local file path - absolute path
31
+ * const localModelId = await loadModel({
32
+ * modelSrc: "/home/user/models/llama-7b.gguf",
33
+ * modelType: "llm",
34
+ * modelConfig: { contextSize: 2048 }
35
+ * });
36
+ *
37
+ * // Local file path - relative path
38
+ * const relativeModelId = await loadModel({
39
+ * modelSrc: "./models/whisper-base.gguf",
40
+ * modelType: "whisper"
41
+ * });
42
+ *
43
+ * // Hyperdrive URL with key and path
44
+ * const hyperdriveId = await loadModel({
45
+ * modelSrc: "pear://<hyperdrive-key>/llama-7b.gguf",
46
+ * modelType: "llm",
47
+ * modelConfig: { contextSize: 2048 }
48
+ * });
49
+ *
50
+ * // Remote HTTP/HTTPS URL with progress tracking
51
+ * const remoteId = await loadModel({
52
+ * modelSrc: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf",
53
+ * modelType: "llm",
54
+ * onProgress: (progress) => {
55
+ * console.log(`Downloaded: ${progress.percentage}%`);
56
+ * }
57
+ * });
58
+ *
59
+ * // Multimodal model with projection
60
+ * const multimodalId = await loadModel({
61
+ * modelSrc: "https://huggingface.co/.../main-model.gguf",
62
+ * modelType: "llm",
63
+ * projectionModelSrc: "https://huggingface.co/.../projection-model.gguf",
64
+ * modelConfig: { ctx_size: 512 },
65
+ * onProgress: (progress) => {
66
+ * console.log(`Loading: ${progress.percentage}%`);
67
+ * }
68
+ * });
69
+ *
70
+ * // Whisper with VAD model
71
+ * const whisperId = await loadModel({
72
+ * modelSrc: "https://huggingface.co/.../whisper-model.gguf",
73
+ * modelType: "whisper",
74
+ * vadModelSrc: "https://huggingface.co/.../vad-model.bin",
75
+ * modelConfig: {
76
+ * mode: "caption",
77
+ * output_format: "plaintext",
78
+ * min_seconds: 2,
79
+ * max_seconds: 6
80
+ * }
81
+ * });
82
+ *
83
+ * // Load with automatic logging - logs from the model will be forwarded to your logger
84
+ * import { getLogger } from "../../logging/index";
85
+ * const logger = getLogger("my-app");
86
+ *
87
+ * const modelId = await loadModel({
88
+ * modelSrc: "/path/to/model.gguf",
89
+ * modelType: "llm",
90
+ * logger // Pass logger in options
91
+ * });
92
+ *
93
+ * // Now any logs from the model operations will appear in your logger automatically
94
+ * // No need to manually manage logging streams!
95
+ * ```
96
+ */
97
+ export declare function loadModel(options: LoadModelOptions): Promise<string>;
98
+ //# sourceMappingURL=load-model.d.ts.map
@@ -0,0 +1,154 @@
1
+ import { send, stream } from "../rpc/rpc-client.js";
2
+ import {} from "../../logging/index.js";
3
+ import { startLoggingStreamForModel } from "../logging-stream-registry.js";
4
+ import { loadModelRequestSchema, } from "../../schemas/index.js";
5
+ /**
6
+ * Loads a machine learning model from a local path, remote URL, or Hyperdrive key.
7
+ *
8
+ * This function supports three model types: LLM (Large Language Model), Whisper (speech recognition),
9
+ * and embeddings. It can handle both local file paths and Hyperdrive URLs (pear://).
10
+ *
11
+ * When `onProgress` is provided, the function uses streaming to provide real-time download progress.
12
+ * Otherwise, it uses a simple request-response pattern for faster execution.
13
+ *
14
+ * @param options - An object that defines all configuration parameters required for loading the model, including:
15
+ * - modelSrc: The location from which the model weights are fetched (local path, remote URL, or Hyperdrive URL)
16
+ * - modelType: The type of model ("llm", "whisper", "embeddings", or "nmt")
17
+ * - modelConfig: Model-specific configuration options
18
+ * - projectionModelSrc: (LLM only) Projection model source for multimodal models
19
+ * - vadModelSrc: (Whisper only) VAD model source for voice activity detection
20
+ *
21
+ * @returns Promise that resolves to the model ID (either the provided modelSrc or a generated ID)
22
+ *
23
+ * @throws {Error} When model loading fails, with details in the error message
24
+ * @throws {Error} When streaming ends unexpectedly (only when using onProgress)
25
+ * @throws {Error} When receiving an invalid response type from the server
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // Local file path - absolute path
30
+ * const localModelId = await loadModel({
31
+ * modelSrc: "/home/user/models/llama-7b.gguf",
32
+ * modelType: "llm",
33
+ * modelConfig: { contextSize: 2048 }
34
+ * });
35
+ *
36
+ * // Local file path - relative path
37
+ * const relativeModelId = await loadModel({
38
+ * modelSrc: "./models/whisper-base.gguf",
39
+ * modelType: "whisper"
40
+ * });
41
+ *
42
+ * // Hyperdrive URL with key and path
43
+ * const hyperdriveId = await loadModel({
44
+ * modelSrc: "pear://<hyperdrive-key>/llama-7b.gguf",
45
+ * modelType: "llm",
46
+ * modelConfig: { contextSize: 2048 }
47
+ * });
48
+ *
49
+ * // Remote HTTP/HTTPS URL with progress tracking
50
+ * const remoteId = await loadModel({
51
+ * modelSrc: "https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf",
52
+ * modelType: "llm",
53
+ * onProgress: (progress) => {
54
+ * console.log(`Downloaded: ${progress.percentage}%`);
55
+ * }
56
+ * });
57
+ *
58
+ * // Multimodal model with projection
59
+ * const multimodalId = await loadModel({
60
+ * modelSrc: "https://huggingface.co/.../main-model.gguf",
61
+ * modelType: "llm",
62
+ * projectionModelSrc: "https://huggingface.co/.../projection-model.gguf",
63
+ * modelConfig: { ctx_size: 512 },
64
+ * onProgress: (progress) => {
65
+ * console.log(`Loading: ${progress.percentage}%`);
66
+ * }
67
+ * });
68
+ *
69
+ * // Whisper with VAD model
70
+ * const whisperId = await loadModel({
71
+ * modelSrc: "https://huggingface.co/.../whisper-model.gguf",
72
+ * modelType: "whisper",
73
+ * vadModelSrc: "https://huggingface.co/.../vad-model.bin",
74
+ * modelConfig: {
75
+ * mode: "caption",
76
+ * output_format: "plaintext",
77
+ * min_seconds: 2,
78
+ * max_seconds: 6
79
+ * }
80
+ * });
81
+ *
82
+ * // Load with automatic logging - logs from the model will be forwarded to your logger
83
+ * import { getLogger } from "../../logging/index.js";
84
+ * const logger = getLogger("my-app");
85
+ *
86
+ * const modelId = await loadModel({
87
+ * modelSrc: "/path/to/model.gguf",
88
+ * modelType: "llm",
89
+ * logger // Pass logger in options
90
+ * });
91
+ *
92
+ * // Now any logs from the model operations will appear in your logger automatically
93
+ * // No need to manually manage logging streams!
94
+ * ```
95
+ */
96
+ export async function loadModel(options) {
97
+ const { logger, modelSrc } = options;
98
+ const request = loadModelRequestSchema.parse({
99
+ type: "loadModel",
100
+ modelSrc: modelSrc,
101
+ projectionModelSrc: options.modelType === "llm" ? options.projectionModelSrc : undefined,
102
+ vadModelSrc: options.modelType === "whisper" ? options.vadModelSrc : undefined,
103
+ withProgress: !!options.onProgress,
104
+ seed: options.seed,
105
+ modelType: options.modelType,
106
+ modelConfig: options.modelConfig ?? {},
107
+ delegate: options.delegate,
108
+ });
109
+ if (options.onProgress) {
110
+ // Use streaming for progress updates
111
+ for await (const response of stream(request)) {
112
+ if (response.type === "modelProgress") {
113
+ options.onProgress(response);
114
+ }
115
+ else if (response.type === "loadModel") {
116
+ if (!response.success) {
117
+ throw new Error(response.error ?? "Failed to load model");
118
+ }
119
+ const modelId = response.modelId ?? modelSrc;
120
+ // Start logging stream in the background if logger is provided, catch to avoid failing the entire loadModel operation
121
+ if (logger) {
122
+ try {
123
+ startLoggingStreamForModel(modelId, logger);
124
+ }
125
+ catch (error) {
126
+ console.warn(`Failed to start logging stream for model ${modelId}:`, error);
127
+ }
128
+ }
129
+ return modelId;
130
+ }
131
+ }
132
+ throw new Error("Stream ended without final response");
133
+ }
134
+ else {
135
+ // Use regular send for simple loading
136
+ const response = await send(request);
137
+ if (response.type !== "loadModel") {
138
+ throw new Error("Invalid response type");
139
+ }
140
+ if (!response.success) {
141
+ throw new Error(response.error ?? "Failed to load model");
142
+ }
143
+ const modelId = response.modelId ?? modelSrc;
144
+ if (logger) {
145
+ try {
146
+ startLoggingStreamForModel(modelId, logger);
147
+ }
148
+ catch (error) {
149
+ console.warn(`Failed to start logging stream for model ${modelId}:`, error);
150
+ }
151
+ }
152
+ return modelId;
153
+ }
154
+ }
@@ -0,0 +1,21 @@
1
+ import type { LoggingStreamResponse, LoggingParams } from "../../schemas/logging-stream";
2
+ /**
3
+ * Opens a logging stream for a specific model to receive real-time logs.
4
+ *
5
+ * @param params - The arguments for the logging stream
6
+ * @param params.modelId - The unique identifier of the model to stream logs for
7
+ * @returns AsyncGenerator yielding logging stream responses
8
+ * @throws {Error} When the response type is invalid or when the stream fails
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Open a logging stream for a model
13
+ * const logStream = loggingStream({ modelId: 'my-model-id' });
14
+ *
15
+ * for await (const logMessage of logStream) {
16
+ * console.log(`[${logMessage.level}] ${logMessage.namespace}: ${logMessage.message}`);
17
+ * }
18
+ * ```
19
+ */
20
+ export declare function loggingStream(params: LoggingParams): AsyncGenerator<LoggingStreamResponse>;
21
+ //# sourceMappingURL=logging-stream.d.ts.map
@@ -0,0 +1,32 @@
1
+ import { stream } from "../rpc/rpc-client.js";
2
+ /**
3
+ * Opens a logging stream for a specific model to receive real-time logs.
4
+ *
5
+ * @param params - The arguments for the logging stream
6
+ * @param params.modelId - The unique identifier of the model to stream logs for
7
+ * @returns AsyncGenerator yielding logging stream responses
8
+ * @throws {Error} When the response type is invalid or when the stream fails
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // Open a logging stream for a model
13
+ * const logStream = loggingStream({ modelId: 'my-model-id' });
14
+ *
15
+ * for await (const logMessage of logStream) {
16
+ * console.log(`[${logMessage.level}] ${logMessage.namespace}: ${logMessage.message}`);
17
+ * }
18
+ * ```
19
+ */
20
+ export async function* loggingStream(params) {
21
+ const request = {
22
+ type: "loggingStream",
23
+ ...params,
24
+ };
25
+ const responseStream = stream(request);
26
+ for await (const response of responseStream) {
27
+ if (response.type !== "loggingStream") {
28
+ throw new Error("Invalid response type");
29
+ }
30
+ yield response;
31
+ }
32
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sends a ping request to the server and returns the pong response.
3
+ *
4
+ * @returns A promise that resolves to a pong response containing a number.
5
+ * @throws {Error} When the response type is not "pong".
6
+ */
7
+ export declare function ping(): Promise<{
8
+ type: "pong";
9
+ number: number;
10
+ }>;
11
+ //# sourceMappingURL=ping.d.ts.map
@@ -0,0 +1,18 @@
1
+ import {} from "../../schemas/index.js";
2
+ import { send } from "../rpc/rpc-client.js";
3
+ /**
4
+ * Sends a ping request to the server and returns the pong response.
5
+ *
6
+ * @returns A promise that resolves to a pong response containing a number.
7
+ * @throws {Error} When the response type is not "pong".
8
+ */
9
+ export async function ping() {
10
+ const request = {
11
+ type: "ping",
12
+ };
13
+ const response = await send(request);
14
+ if (response.type !== "pong") {
15
+ throw new Error("Invalid response type");
16
+ }
17
+ return response;
18
+ }
@@ -0,0 +1,18 @@
1
+ import { type ProvideParams } from "../../schemas/index";
2
+ /**
3
+ * Starts a provider service that offers QVAC capabilities to remote peers.
4
+ * The provider's keypair can be controlled via the seed option or QVAC_HYPERSWARM_SEED environment variable.
5
+ *
6
+ * @param options - Options object with required topic, optional seed, and optional firewall config
7
+ * @param options.topic - Topic hex string for peer discovery
8
+ * @param options.firewall - Optional firewall configuration to allow/deny specific public keys
9
+ * @returns A promise that resolves to the provide response containing success status and public key
10
+ * @throws {Error} When the response type is not "provide" or the request fails
11
+ */
12
+ export declare function startQVACProvider(params: ProvideParams): Promise<{
13
+ type: "provide";
14
+ success: boolean;
15
+ error?: string | undefined;
16
+ publicKey?: string | undefined;
17
+ }>;
18
+ //# sourceMappingURL=provide.d.ts.map
@@ -0,0 +1,27 @@
1
+ import {} from "../../schemas/index.js";
2
+ import { send } from "../rpc/rpc-client.js";
3
+ /**
4
+ * Starts a provider service that offers QVAC capabilities to remote peers.
5
+ * The provider's keypair can be controlled via the seed option or QVAC_HYPERSWARM_SEED environment variable.
6
+ *
7
+ * @param options - Options object with required topic, optional seed, and optional firewall config
8
+ * @param options.topic - Topic hex string for peer discovery
9
+ * @param options.firewall - Optional firewall configuration to allow/deny specific public keys
10
+ * @returns A promise that resolves to the provide response containing success status and public key
11
+ * @throws {Error} When the response type is not "provide" or the request fails
12
+ */
13
+ export async function startQVACProvider(params) {
14
+ const request = {
15
+ type: "provide",
16
+ topic: params.topic,
17
+ firewall: params.firewall,
18
+ };
19
+ const response = await send(request);
20
+ if (response.type !== "provide") {
21
+ throw new Error("Invalid response type");
22
+ }
23
+ if (response.error) {
24
+ throw new Error(response.error);
25
+ }
26
+ return response;
27
+ }