@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,25 @@
1
+ import RPC from "bare-rpc";
2
+ import { createRpcProxy } from "./proxy.js";
3
+ export function setupConnectionHandlers(swarm) {
4
+ console.log("👂 Setting up connection listener...");
5
+ swarm.on("close", () => {
6
+ console.log("🔗 Connection closed!");
7
+ });
8
+ swarm.on("connection", (conn) => {
9
+ console.log("🔗 Connection event triggered!");
10
+ const peerPubkey = conn.remotePublicKey?.toString("hex");
11
+ console.log(`📡 New connection established from: ${peerPubkey?.substring(0, 16)}...`);
12
+ console.log("🔐 Full peer public key:", peerPubkey);
13
+ // Create RPC instance for this connection (as server)
14
+ console.log("⚙️ Creating RPC instance for connection...");
15
+ new RPC(conn, createRpcProxy());
16
+ console.log("✅ RPC instance created successfully");
17
+ conn.on("close", () => {
18
+ console.log(`🔌 Connection closed for peer: ${peerPubkey?.substring(0, 16)}`);
19
+ });
20
+ conn.on("error", (err) => {
21
+ console.error(`❌ Connection error for peer ${peerPubkey?.substring(0, 16)}:`, err);
22
+ });
23
+ });
24
+ console.log("✅ Connection listener set up");
25
+ }
@@ -0,0 +1,3 @@
1
+ import type { ProvideRequest, ProvideResponse } from "../../../../schemas/provide";
2
+ export declare function provideHandler(request: ProvideRequest): Promise<ProvideResponse>;
3
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1,50 @@
1
+ import { getSwarm } from "../../../bare/hyperswarm.js";
2
+ import { setupConnectionHandlers } from "./connection.js";
3
+ export async function provideHandler(request) {
4
+ const swarm = getSwarm({
5
+ firewallConfig: request.firewall,
6
+ });
7
+ console.log("🚀 Provide request received:", request);
8
+ console.log("🔍 Swarm keyPair exists:", !!swarm.keyPair);
9
+ console.log("🔍 Swarm publicKey:", swarm.keyPair?.publicKey?.toString("hex")?.substring(0, 16));
10
+ try {
11
+ console.log("⚡ Starting provide handler execution");
12
+ const pubKey = swarm.keyPair.publicKey;
13
+ console.log("🔑 Got public key:", pubKey.toString("hex"));
14
+ // Use provided topic from hex string
15
+ const topic = Buffer.from(request.topic, "hex");
16
+ // Join topic as server (provider)
17
+ console.log("🌐 Joining topic as server...");
18
+ const discovery = swarm.join(topic, { server: true, client: false });
19
+ console.log("📡 Discovery object created:", !!discovery);
20
+ // Wait for the topic to be fully announced on the DHT
21
+ console.log("⏳ Waiting for topic announcement...");
22
+ await discovery.flushed();
23
+ console.log(`✅ Topic announced: ${topic.toString("hex")}`);
24
+ // Wait for connections
25
+ console.log("⏳ Waiting for swarm flush...");
26
+ await swarm.flush();
27
+ console.log(`🎯 Ready to accept connections on topic: ${topic.toString("hex").substring(0, 16)}...`);
28
+ // Handle incoming connections
29
+ setupConnectionHandlers(swarm);
30
+ console.log("🏁 About to return success response...");
31
+ const response = {
32
+ type: "provide",
33
+ success: true,
34
+ publicKey: pubKey.toString("hex"),
35
+ };
36
+ console.log("📤 Returning response:", response);
37
+ return response;
38
+ }
39
+ catch (error) {
40
+ console.error("❌ Error in provide handler:", error);
41
+ console.error("❌ Error stack:", error instanceof Error ? error.stack : "No stack trace");
42
+ const errorResponse = {
43
+ type: "provide",
44
+ success: false,
45
+ error: error instanceof Error ? error.message : "Unknown error",
46
+ };
47
+ console.log("📤 Returning error response:", errorResponse);
48
+ return errorResponse;
49
+ }
50
+ }
@@ -0,0 +1,3 @@
1
+ import type RPC from "bare-rpc";
2
+ export declare function createRpcProxy(): (rpcRequest: RPC.IncomingRequest) => Promise<void>;
3
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1,22 @@
1
+ import { handleRequest } from "../../handle-request.js";
2
+ // Proxies RPC requests to the main handler: handleRequest
3
+ export function createRpcProxy() {
4
+ return async (rpcRequest) => {
5
+ console.log("📬 RPC request callback triggered!");
6
+ console.log("📦 Raw RPC request data:", rpcRequest.data?.toString());
7
+ try {
8
+ console.log("🚀 Calling handleRequest...");
9
+ await handleRequest(rpcRequest);
10
+ console.log("✅ handleRequest completed successfully");
11
+ }
12
+ catch (error) {
13
+ console.error("❌ Error:", error instanceof Error ? error.message : error);
14
+ const errorResponse = JSON.stringify({
15
+ type: "error",
16
+ error: error instanceof Error ? error.message : "Unknown error",
17
+ });
18
+ console.log("📤 Sending error response:", errorResponse);
19
+ rpcRequest.reply(errorResponse, "utf-8");
20
+ }
21
+ };
22
+ }
@@ -0,0 +1,2 @@
1
+ export { provideHandler } from "./provideHandler/handler";
2
+ //# sourceMappingURL=provideHandler.d.ts.map
@@ -0,0 +1,2 @@
1
+ // Re-export the provideHandler from the refactored provideHandler modules
2
+ export { provideHandler } from "./provideHandler/handler.js";
@@ -0,0 +1,3 @@
1
+ import type { RagRequest, RagResponse } from "../../../schemas/index";
2
+ export declare function handleRag(request: RagRequest): Promise<RagResponse>;
3
+ //# sourceMappingURL=rag.d.ts.map
@@ -0,0 +1,67 @@
1
+ import { saveEmbeddings, search, deleteEmbeddings, } from "../../bare/rag-hyperdb/index.js";
2
+ export async function handleRag(request) {
3
+ try {
4
+ switch (request.operation) {
5
+ case "saveEmbeddings": {
6
+ const result = await saveEmbeddings(request);
7
+ return {
8
+ type: "rag",
9
+ operation: request.operation,
10
+ success: true,
11
+ processed: result.processed,
12
+ droppedIndices: result.droppedIndices,
13
+ };
14
+ }
15
+ case "search": {
16
+ const results = await search(request);
17
+ return {
18
+ type: "rag",
19
+ operation: request.operation,
20
+ success: true,
21
+ results,
22
+ };
23
+ }
24
+ case "deleteEmbeddings": {
25
+ const success = await deleteEmbeddings(request);
26
+ return {
27
+ type: "rag",
28
+ operation: request.operation,
29
+ success,
30
+ };
31
+ }
32
+ default: {
33
+ throw new Error(`Unknown RAG operation`);
34
+ }
35
+ }
36
+ }
37
+ catch (error) {
38
+ console.error("Error in RAG handler:", error);
39
+ const baseError = {
40
+ type: "rag",
41
+ success: false,
42
+ error: error instanceof Error ? error.message : "Unknown error",
43
+ };
44
+ switch (request.operation) {
45
+ case "saveEmbeddings":
46
+ return {
47
+ ...baseError,
48
+ operation: request.operation,
49
+ processed: [],
50
+ droppedIndices: [],
51
+ };
52
+ case "search":
53
+ return {
54
+ ...baseError,
55
+ operation: request.operation,
56
+ results: [],
57
+ };
58
+ case "deleteEmbeddings":
59
+ return {
60
+ ...baseError,
61
+ operation: request.operation,
62
+ };
63
+ default:
64
+ throw error;
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,3 @@
1
+ import type { TranscribeStreamRequest, TranscribeStreamResponse } from "../../../schemas/index";
2
+ export declare function handleTranscribeStream(request: TranscribeStreamRequest): AsyncGenerator<TranscribeStreamResponse>;
3
+ //# sourceMappingURL=transcribe-stream.d.ts.map
@@ -0,0 +1,26 @@
1
+ import { transcribeStream } from "../../bare/addons/whispercpp/index.js";
2
+ export async function* handleTranscribeStream(request) {
3
+ const { modelId, audioChunk } = request;
4
+ try {
5
+ // Stream transcription results in real-time
6
+ for await (const textChunk of transcribeStream({ audioChunk, modelId })) {
7
+ yield {
8
+ type: "transcribeStream",
9
+ text: textChunk,
10
+ };
11
+ }
12
+ // Signal completion
13
+ yield {
14
+ type: "transcribeStream",
15
+ done: true,
16
+ };
17
+ }
18
+ catch (error) {
19
+ console.error("Error during transcription:", error);
20
+ yield {
21
+ type: "transcribeStream",
22
+ text: "",
23
+ error: error instanceof Error ? error.message : "Unknown error",
24
+ };
25
+ }
26
+ }
@@ -0,0 +1,3 @@
1
+ import type { TranslateRequest, TranslateResponse } from "../../../schemas/index";
2
+ export declare function handleTranslate(request: TranslateRequest): AsyncGenerator<TranslateResponse>;
3
+ //# sourceMappingURL=translate.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { translate } from "../../bare/addons/translation/index.js";
2
+ export async function* handleTranslate(request) {
3
+ const { modelId, text, stream, modelType } = request;
4
+ const from = request.modelType === "llm" ? request.from : undefined;
5
+ const to = request.modelType === "llm" ? request.to : undefined;
6
+ const context = request.modelType === "llm" ? request.context : undefined;
7
+ try {
8
+ const generator = translate({
9
+ modelId,
10
+ text,
11
+ from,
12
+ to: to,
13
+ stream,
14
+ modelType,
15
+ context,
16
+ });
17
+ let stats;
18
+ let done = false;
19
+ let buffer = "";
20
+ while (!done) {
21
+ const result = await generator.next();
22
+ if (result.done) {
23
+ stats = result.value;
24
+ done = true;
25
+ }
26
+ else {
27
+ buffer += result.value;
28
+ if (stream) {
29
+ yield {
30
+ type: "translate",
31
+ token: result.value,
32
+ };
33
+ }
34
+ }
35
+ }
36
+ yield {
37
+ type: "translate",
38
+ token: buffer,
39
+ done: true,
40
+ stats,
41
+ };
42
+ }
43
+ catch (error) {
44
+ console.error("Error during translation:", error);
45
+ yield {
46
+ type: "translate",
47
+ token: "",
48
+ error: error instanceof Error ? error.message : "Unknown error",
49
+ };
50
+ }
51
+ }
@@ -0,0 +1,3 @@
1
+ import type { UnloadModelRequest, UnloadModelResponse } from "../../../schemas/index";
2
+ export declare function handleUnloadModel(request: UnloadModelRequest): Promise<UnloadModelResponse>;
3
+ //# sourceMappingURL=unload-model.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { unloadModel } from "../../bare/addons/index.js";
2
+ export async function handleUnloadModel(request) {
3
+ const { modelId, clearStorage } = request;
4
+ try {
5
+ console.log("Unloading model", modelId);
6
+ await unloadModel({ modelId, clearStorage });
7
+ return {
8
+ type: "unloadModel",
9
+ success: true,
10
+ };
11
+ }
12
+ catch (error) {
13
+ console.error("Error during model unload:", error);
14
+ return {
15
+ type: "unloadModel",
16
+ success: false,
17
+ error: error instanceof Error ? error.message : "Unknown error",
18
+ };
19
+ }
20
+ }
@@ -0,0 +1,3 @@
1
+ export { createBareKitRPCServer, createIPCClient } from "./create-server";
2
+ export { handleRequest, type BareRPCRequest } from "./handle-request";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { createBareKitRPCServer, createIPCClient } from "./create-server.js";
2
+ export { handleRequest } from "./handle-request.js";
@@ -0,0 +1,4 @@
1
+ import { Readable } from "bare-stream";
2
+ export declare function needsDecoding(filePath: string): boolean;
3
+ export declare function decodeAudioToStream(inputPath: string): Promise<Readable>;
4
+ //# sourceMappingURL=decoder.d.ts.map
@@ -0,0 +1,41 @@
1
+ import fs from "bare-fs";
2
+ import path from "bare-path";
3
+ import GSTDecoder from "@qvac/decoder-audio";
4
+ import { Readable } from "bare-stream";
5
+ import { FORMATS_NEEDING_DECODE } from "../../../constants/audio.js";
6
+ export function needsDecoding(filePath) {
7
+ const ext = path.extname(filePath).toLowerCase();
8
+ return FORMATS_NEEDING_DECODE.includes(ext);
9
+ }
10
+ export async function decodeAudioToStream(inputPath) {
11
+ const decoder = new GSTDecoder({
12
+ config: {
13
+ audioFormat: "encoded",
14
+ },
15
+ });
16
+ try {
17
+ await decoder.load();
18
+ const audioStream = fs.createReadStream(inputPath);
19
+ const response = await decoder.run(audioStream);
20
+ const outputStream = new Readable({
21
+ read() { },
22
+ });
23
+ response
24
+ .onUpdate((output) => {
25
+ const bytes = new Uint8Array(output.outputArray);
26
+ outputStream.push(Buffer.from(bytes));
27
+ })
28
+ .onFinish(() => {
29
+ outputStream.push(null);
30
+ })
31
+ .await()
32
+ .catch((error) => {
33
+ outputStream.destroy(error instanceof Error ? error : new Error(String(error)));
34
+ });
35
+ return outputStream;
36
+ }
37
+ catch (error) {
38
+ console.error("Decoding failed:", error instanceof Error ? error.message : String(error));
39
+ throw error;
40
+ }
41
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Creates and returns cache directory path for the specified subdirectory
3
+ * @param subDir - Subdirectory name (e.g., "models", "kv-cache")
4
+ * @returns Full path to the cache directory
5
+ */
6
+ export declare function getCacheDir(subDir: string): string;
7
+ /**
8
+ * Legacy function for backward compatibility - gets models cache directory
9
+ */
10
+ export declare function getModelsCacheDir(): string;
11
+ /**
12
+ * Gets KV cache directory
13
+ */
14
+ export declare function getKVCacheDir(): string;
15
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1,32 @@
1
+ import fs from "bare-fs";
2
+ import path from "bare-path";
3
+ import { getEnv } from "../worker.js";
4
+ /**
5
+ * Creates and returns cache directory path for the specified subdirectory
6
+ * @param subDir - Subdirectory name (e.g., "models", "kv-cache")
7
+ * @returns Full path to the cache directory
8
+ */
9
+ export function getCacheDir(subDir) {
10
+ const homeDir = getEnv().HOME_DIR;
11
+ const cacheDir = path.join(homeDir, ".qvac", subDir);
12
+ // Ensure cache directory exists
13
+ try {
14
+ fs.mkdirSync(cacheDir, { recursive: true });
15
+ }
16
+ catch (error) {
17
+ console.error(`Error creating cache directory (${subDir}):`, error instanceof Error ? error.message : String(error));
18
+ }
19
+ return cacheDir;
20
+ }
21
+ /**
22
+ * Legacy function for backward compatibility - gets models cache directory
23
+ */
24
+ export function getModelsCacheDir() {
25
+ return getCacheDir("models");
26
+ }
27
+ /**
28
+ * Gets KV cache directory
29
+ */
30
+ export function getKVCacheDir() {
31
+ return getCacheDir("kv-cache");
32
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generate a short hash (16 characters) from any input string
3
+ */
4
+ export declare function generateShortHash(input: string): string;
5
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./audio/decoder";
2
+ export * from "./cache";
3
+ export * from "./hash";
4
+ export * from "./model-path";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ export * from "./audio/decoder.js";
2
+ export * from "./cache.js";
3
+ export * from "./hash.js";
4
+ export * from "./model-path.js";
@@ -0,0 +1,5 @@
1
+ export declare function parseModelPath(modelPath: string): {
2
+ dirPath: string;
3
+ basePath: string;
4
+ };
5
+ //# sourceMappingURL=model-path.d.ts.map
@@ -0,0 +1,7 @@
1
+ import path from "bare-path";
2
+ export function parseModelPath(modelPath) {
3
+ return {
4
+ dirPath: path.dirname(modelPath),
5
+ basePath: path.basename(modelPath),
6
+ };
7
+ }
@@ -0,0 +1,6 @@
1
+ export declare function getEnv(): {
2
+ HOME_DIR: string;
3
+ QVAC_IPC_SOCKET_PATH?: string | undefined;
4
+ };
5
+ export declare function ensureRPCSetup(): void;
6
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1,77 @@
1
+ import process from "bare-process";
2
+ import { createBareKitRPCServer, createIPCClient, } from "./rpc/create-server.js";
3
+ import { z } from "zod";
4
+ import { destroySwarm } from "./bare/hyperswarm.js";
5
+ console.log("🐻 Hello from Bare");
6
+ console.log("Arguments to worker:", process.argv);
7
+ const defaultHomeDir = process.env["HOME"] || process.env["USERPROFILE"] || "/tmp";
8
+ let envConfig = { HOME_DIR: defaultHomeDir };
9
+ let hasRPCConfig = false;
10
+ // Try to parse any argument as JSON config (fail gracefully)
11
+ if (process.argv[2]) {
12
+ try {
13
+ const rpcArgs = JSON.parse(process.argv[2]);
14
+ envConfig = { ...envConfig, ...rpcArgs };
15
+ hasRPCConfig = true;
16
+ console.log("Parsed RPC configuration from arguments");
17
+ }
18
+ catch {
19
+ // Not JSON or invalid - use defaults (direct mode)
20
+ console.log("Using default configuration (direct mode)");
21
+ }
22
+ }
23
+ const validatedEnv = z
24
+ .object({
25
+ QVAC_IPC_SOCKET_PATH: z.string().optional(),
26
+ HOME_DIR: z.string(),
27
+ })
28
+ .parse(envConfig);
29
+ export function getEnv() {
30
+ return {
31
+ ...process.env,
32
+ ...validatedEnv,
33
+ };
34
+ }
35
+ let rpcInitialized = false;
36
+ export function ensureRPCSetup() {
37
+ if (rpcInitialized)
38
+ return;
39
+ try {
40
+ const ipcSocketPath = validatedEnv.QVAC_IPC_SOCKET_PATH;
41
+ if (ipcSocketPath) {
42
+ console.log(`Running in desktop mode, connecting to IPC socket: ${ipcSocketPath}`);
43
+ // Connect to the IPC server (Named Pipe or Unix Socket)
44
+ const rpc = createIPCClient(ipcSocketPath);
45
+ console.log("Desktop IPC client created?", !!rpc);
46
+ }
47
+ else {
48
+ console.log("Running in BareKit IPC mode");
49
+ // Start the standard RPC server with BareKit IPC for mobile
50
+ createBareKitRPCServer();
51
+ }
52
+ console.log("Bare worker started and listening for RPC requests");
53
+ console.log("Working directory:", process.cwd());
54
+ rpcInitialized = true;
55
+ }
56
+ catch (error) {
57
+ console.error("Worker error:", error);
58
+ process.exit(1);
59
+ }
60
+ }
61
+ // Auto-setup RPC only if we successfully parsed RPC configuration
62
+ if (hasRPCConfig) {
63
+ ensureRPCSetup();
64
+ }
65
+ else {
66
+ console.log("Running in direct mode - RPC setup will be lazy");
67
+ }
68
+ process.on("SIGTERM", () => {
69
+ console.log("🐻 Bare worker SIGTERM received, cleaning up...");
70
+ destroySwarm()
71
+ .then(() => {
72
+ process.exit(0);
73
+ })
74
+ .catch((err) => {
75
+ throw err;
76
+ });
77
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Wraps a promise with an optional timeout
3
+ * If no timeout is provided, returns the original promise unchanged
4
+ */
5
+ export declare function withTimeout<T>(promise: Promise<T>, timeoutMs?: number): Promise<T>;
6
+ /**
7
+ * Wraps an async generator with optional timeout per iteration
8
+ * If no timeout is provided, returns the original generator unchanged
9
+ */
10
+ export declare function withTimeoutStream<T>(generator: AsyncGenerator<T>, timeoutMs?: number): AsyncGenerator<T>;
11
+ //# sourceMappingURL=withTimeout.d.ts.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Creates a timeout promise that rejects after the specified duration
3
+ */
4
+ function createTimeoutPromise(timeoutMs) {
5
+ return new Promise((_, reject) => {
6
+ setTimeout(() => {
7
+ reject(new Error(`Operation timeout after ${timeoutMs}ms`));
8
+ }, timeoutMs);
9
+ });
10
+ }
11
+ /**
12
+ * Wraps a promise with an optional timeout
13
+ * If no timeout is provided, returns the original promise unchanged
14
+ */
15
+ export async function withTimeout(promise, timeoutMs) {
16
+ if (timeoutMs === undefined) {
17
+ return promise;
18
+ }
19
+ const timeoutPromise = createTimeoutPromise(timeoutMs);
20
+ return Promise.race([promise, timeoutPromise]);
21
+ }
22
+ /**
23
+ * Wraps an async generator with optional timeout per iteration
24
+ * If no timeout is provided, returns the original generator unchanged
25
+ */
26
+ export async function* withTimeoutStream(generator, timeoutMs) {
27
+ if (timeoutMs === undefined) {
28
+ yield* generator;
29
+ return;
30
+ }
31
+ for await (const item of generator) {
32
+ const itemPromise = Promise.resolve(item);
33
+ const timeoutPromise = createTimeoutPromise(timeoutMs);
34
+ const result = await Promise.race([itemPromise, timeoutPromise]);
35
+ yield result;
36
+ }
37
+ }