@qvac/sdk 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +328 -200
  2. package/dist/client/api/completion-stream.d.ts +15 -5
  3. package/dist/client/api/completion-stream.js +50 -14
  4. package/dist/client/api/embed.d.ts +17 -3
  5. package/dist/client/api/embed.js +0 -8
  6. package/dist/client/api/get-model-info.d.ts +1 -1
  7. package/dist/client/api/index.d.ts +0 -1
  8. package/dist/client/api/index.js +0 -1
  9. package/dist/client/api/load-model.d.ts +37 -11
  10. package/dist/client/api/load-model.js +29 -117
  11. package/dist/client/api/logging-stream.d.ts +6 -3
  12. package/dist/client/api/logging-stream.js +6 -3
  13. package/dist/client/api/unload-model.js +5 -2
  14. package/dist/client/config-loader/config-utils.d.ts +5 -0
  15. package/dist/client/config-loader/config-utils.js +20 -0
  16. package/dist/client/config-loader/resolve-config.bare.d.ts +9 -0
  17. package/dist/client/config-loader/resolve-config.bare.js +87 -0
  18. package/dist/client/config-loader/resolve-config.expo.d.ts +11 -0
  19. package/dist/client/config-loader/resolve-config.expo.js +62 -0
  20. package/dist/client/config-loader/resolve-config.node.d.ts +9 -0
  21. package/dist/client/config-loader/resolve-config.node.js +118 -0
  22. package/dist/client/init-hooks.d.ts +17 -3
  23. package/dist/client/init-hooks.js +37 -18
  24. package/dist/client/logging-stream-registry.d.ts +1 -1
  25. package/dist/client/logging-stream-registry.js +14 -13
  26. package/dist/client/rpc/bare-client.d.ts +10 -14
  27. package/dist/client/rpc/bare-client.js +28 -2
  28. package/dist/client/rpc/bare-rpc-client.d.ts +1 -1
  29. package/dist/client/rpc/bare-rpc-client.js +16 -13
  30. package/dist/client/rpc/expo-rpc-client.d.ts +2 -2
  31. package/dist/client/rpc/expo-rpc-client.js +15 -12
  32. package/dist/client/rpc/node-rpc-client.d.ts +1 -1
  33. package/dist/client/rpc/node-rpc-client.js +10 -7
  34. package/dist/client/rpc/rpc-client.js +16 -15
  35. package/dist/constants/audio.d.ts +1 -2
  36. package/dist/constants/audio.js +1 -17
  37. package/dist/examples/config/config-path.d.ts +8 -0
  38. package/dist/examples/config/config-path.js +13 -0
  39. package/dist/examples/config-reload.d.ts +2 -0
  40. package/dist/examples/config-reload.js +49 -0
  41. package/dist/examples/download-with-blind-relays.js +20 -20
  42. package/dist/examples/embed-hyperdrive.js +35 -3
  43. package/dist/examples/kv-cache-cleanup.js +1 -1
  44. package/dist/examples/kv-cache-custom-key.js +1 -1
  45. package/dist/examples/kv-cache-example.js +1 -1
  46. package/dist/examples/llamacpp-hyperdrive.js +1 -1
  47. package/dist/examples/llamacpp-sharded.js +1 -1
  48. package/dist/examples/logging-file-transport.d.ts +2 -0
  49. package/dist/examples/{llamacpp-file-logging.js → logging-file-transport.js} +3 -7
  50. package/dist/examples/logging-streaming.d.ts +2 -0
  51. package/dist/examples/logging-streaming.js +75 -0
  52. package/dist/examples/mcp-websearch.d.ts +13 -0
  53. package/dist/examples/mcp-websearch.js +176 -0
  54. package/dist/index.d.ts +4 -4
  55. package/dist/index.js +2 -2
  56. package/dist/logging/addon.d.ts +6 -0
  57. package/dist/logging/addon.js +59 -0
  58. package/dist/logging/base-logger.js +24 -14
  59. package/dist/logging/client-logger.d.ts +3 -0
  60. package/dist/logging/client-logger.js +13 -0
  61. package/dist/logging/index.d.ts +6 -1
  62. package/dist/logging/index.js +6 -1
  63. package/dist/logging/logger.d.ts +0 -2
  64. package/dist/logging/logger.js +0 -3
  65. package/dist/logging/namespaces.d.ts +11 -0
  66. package/dist/logging/namespaces.js +11 -0
  67. package/dist/logging/registry.d.ts +26 -0
  68. package/dist/logging/registry.js +36 -0
  69. package/dist/logging/server-logger.d.ts +3 -0
  70. package/dist/logging/server-logger.js +16 -0
  71. package/dist/logging/stream-logger.d.ts +1 -1
  72. package/dist/logging/stream-logger.js +6 -3
  73. package/dist/logging/types.d.ts +2 -0
  74. package/dist/models/hyperdrive/models.d.ts +789 -51
  75. package/dist/models/hyperdrive/models.js +979 -200
  76. package/dist/schemas/common.d.ts +86 -23
  77. package/dist/schemas/common.js +0 -3
  78. package/dist/schemas/download-asset.d.ts +5 -5
  79. package/dist/schemas/embed.d.ts +3 -3
  80. package/dist/schemas/embed.js +9 -2
  81. package/dist/schemas/get-model-info.d.ts +2 -2
  82. package/dist/schemas/index.d.ts +5 -1
  83. package/dist/schemas/index.js +5 -1
  84. package/dist/schemas/json-schema.d.ts +16 -0
  85. package/dist/schemas/json-schema.js +2 -0
  86. package/dist/schemas/llamacpp-config.d.ts +5 -4
  87. package/dist/schemas/llamacpp-config.js +7 -5
  88. package/dist/schemas/load-model.d.ts +931 -211
  89. package/dist/schemas/load-model.js +7 -1
  90. package/dist/schemas/logging-stream.d.ts +10 -3
  91. package/dist/schemas/logging-stream.js +4 -3
  92. package/dist/schemas/mcp-adapter.d.ts +47 -0
  93. package/dist/schemas/mcp-adapter.js +1 -0
  94. package/dist/schemas/model-src-utils.d.ts +8 -6
  95. package/dist/schemas/model-src-utils.js +8 -3
  96. package/dist/schemas/reload-config.d.ts +344 -0
  97. package/dist/schemas/reload-config.js +42 -0
  98. package/dist/schemas/sdk-config.d.ts +22 -0
  99. package/dist/schemas/sdk-config.js +33 -0
  100. package/dist/schemas/sdk-errors-client.d.ts +4 -0
  101. package/dist/schemas/sdk-errors-client.js +20 -0
  102. package/dist/schemas/sdk-errors-server.d.ts +3 -0
  103. package/dist/schemas/sdk-errors-server.js +15 -0
  104. package/dist/schemas/tools.d.ts +3 -0
  105. package/dist/schemas/translation-config.d.ts +81 -0
  106. package/dist/schemas/translation-config.js +3 -4
  107. package/dist/schemas/whispercpp-config.d.ts +9 -1
  108. package/dist/schemas/whispercpp-config.js +2 -1
  109. package/dist/server/bare/addons/llamacpp/create-model.js +13 -4
  110. package/dist/server/bare/addons/llamacpp/handlers/embed.d.ts +9 -1
  111. package/dist/server/bare/addons/llamacpp/handlers/embed.js +18 -4
  112. package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +6 -4
  113. package/dist/server/bare/addons/load-model.js +10 -4
  114. package/dist/server/bare/addons/unload-model.js +6 -3
  115. package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +56 -37
  116. package/dist/server/bare/delegate-rpc-client.js +12 -10
  117. package/dist/server/bare/hyperswarm.js +7 -5
  118. package/dist/server/bare/rag-hyperdb/rag-manager.js +3 -1
  119. package/dist/server/bare/registry/config-registry.d.ts +13 -4
  120. package/dist/server/bare/registry/config-registry.js +42 -10
  121. package/dist/server/bare/registry/logging-stream-registry.d.ts +24 -7
  122. package/dist/server/bare/registry/logging-stream-registry.js +99 -20
  123. package/dist/server/bare/registry/model-registry.d.ts +3 -0
  124. package/dist/server/bare/registry/model-registry.js +9 -6
  125. package/dist/server/rpc/create-server.js +5 -3
  126. package/dist/server/rpc/handle-request.js +30 -16
  127. package/dist/server/rpc/handlers/cancelHandler.js +3 -1
  128. package/dist/server/rpc/handlers/completion-stream-delegated.js +4 -2
  129. package/dist/server/rpc/handlers/delete-cache.js +3 -1
  130. package/dist/server/rpc/handlers/download-asset.js +3 -1
  131. package/dist/server/rpc/handlers/embed.js +3 -1
  132. package/dist/server/rpc/handlers/index.d.ts +0 -1
  133. package/dist/server/rpc/handlers/index.js +0 -2
  134. package/dist/server/rpc/handlers/load-model/download-manager.js +4 -2
  135. package/dist/server/rpc/handlers/load-model/http.js +20 -18
  136. package/dist/server/rpc/handlers/load-model/hyperdrive.js +21 -19
  137. package/dist/server/rpc/handlers/load-model/resolve.js +7 -5
  138. package/dist/server/rpc/handlers/load-model-delegated.d.ts +2 -2
  139. package/dist/server/rpc/handlers/load-model-delegated.js +10 -8
  140. package/dist/server/rpc/handlers/load-model.js +55 -3
  141. package/dist/server/rpc/handlers/logging-stream.js +4 -4
  142. package/dist/server/rpc/handlers/provideHandler/connection.js +12 -10
  143. package/dist/server/rpc/handlers/provideHandler/handler.js +18 -16
  144. package/dist/server/rpc/handlers/provideHandler/proxy.js +8 -6
  145. package/dist/server/rpc/handlers/rag.js +3 -1
  146. package/dist/server/rpc/handlers/stopProvideHandler.js +3 -1
  147. package/dist/server/rpc/handlers/transcribe-stream.js +3 -1
  148. package/dist/server/rpc/handlers/translate.js +3 -1
  149. package/dist/server/rpc/handlers/unload-model.js +4 -2
  150. package/dist/server/utils/audio/decoder.d.ts +2 -1
  151. package/dist/server/utils/audio/decoder.js +49 -12
  152. package/dist/server/utils/cache.js +7 -5
  153. package/dist/server/utils/config-transform.d.ts +3 -0
  154. package/dist/server/utils/config-transform.js +21 -0
  155. package/dist/server/utils/index.d.ts +1 -0
  156. package/dist/server/utils/index.js +1 -0
  157. package/dist/server/worker.js +41 -16
  158. package/dist/utils/errors-client.d.ts +12 -0
  159. package/dist/utils/errors-client.js +20 -0
  160. package/dist/utils/errors-server.d.ts +9 -0
  161. package/dist/utils/errors-server.js +16 -0
  162. package/dist/utils/getProcessSafe.d.ts +7 -0
  163. package/dist/utils/getProcessSafe.js +17 -0
  164. package/dist/utils/mcp-adapter.d.ts +12 -0
  165. package/dist/utils/mcp-adapter.js +103 -0
  166. package/dist/utils/object.d.ts +2 -0
  167. package/dist/utils/object.js +3 -0
  168. package/dist/utils/runtime.d.ts +30 -0
  169. package/dist/utils/runtime.js +48 -0
  170. package/dist/utils/tool-helpers.d.ts +10 -2
  171. package/dist/utils/tool-helpers.js +24 -11
  172. package/package.json +47 -34
  173. package/dist/client/api/set-config.d.ts +0 -7
  174. package/dist/client/api/set-config.js +0 -20
  175. package/dist/client/config-manager.d.ts +0 -4
  176. package/dist/client/config-manager.js +0 -8
  177. package/dist/examples/llamacpp-file-logging.d.ts +0 -2
  178. package/dist/schemas/set-config.d.ts +0 -21
  179. package/dist/schemas/set-config.js +0 -14
  180. package/dist/server/rpc/handlers/set-config.d.ts +0 -3
  181. package/dist/server/rpc/handlers/set-config.js +0 -18
@@ -4,6 +4,10 @@ import { createServer } from "bare-net";
4
4
  import os from "bare-os";
5
5
  import path from "bare-path";
6
6
  import process from "bare-process";
7
+ import { initializeConfig } from "../init-hooks.js";
8
+ import { resolveConfig } from "../config-loader/resolve-config.bare.js";
9
+ import { getClientLogger } from "../../logging/index.js";
10
+ const logger = getClientLogger();
7
11
  let rpcInstance = null;
8
12
  let ipcServer = null;
9
13
  let childProcess = null;
@@ -25,14 +29,14 @@ else {
25
29
  const SOCKET_PATH = path.join(os.tmpdir(), `qvac-worker-${process.pid}.sock`);
26
30
  export async function getRPC() {
27
31
  if (rpcInstance) {
28
- console.log("returning cached bare rpc");
32
+ logger.debug("returning cached bare rpc");
29
33
  return rpcInstance;
30
34
  }
31
- console.log("initRPC for bare runtime with socket:", SOCKET_PATH);
35
+ logger.info("initRPC for bare runtime with socket:", SOCKET_PATH);
32
36
  // Start IPC server (Unix socket)
33
37
  const serverPromise = new Promise((resolve, reject) => {
34
38
  const server = createServer((socket) => {
35
- console.log("Worker connected via IPC socket");
39
+ logger.info("Worker connected via IPC socket");
36
40
  // Create RPC instance using the socket
37
41
  rpcInstance = new RPC(socket, () => {
38
42
  // Use this for async callbacks
@@ -40,14 +44,14 @@ export async function getRPC() {
40
44
  resolve(rpcInstance);
41
45
  });
42
46
  server.on("error", (err) => {
43
- console.error("Failed to start IPC server:", err);
47
+ logger.error("Failed to start IPC server:", err);
44
48
  reject(err);
45
49
  });
46
50
  server.listen(SOCKET_PATH, () => {
47
- console.log(`IPC server listening on ${SOCKET_PATH}`);
51
+ logger.info(`IPC server listening on ${SOCKET_PATH}`);
48
52
  ipcServer = server;
49
53
  // Spawn the worker process only after the socket is listening
50
- console.log("Spawning worker at:", WORKER_PATH);
54
+ logger.debug("Spawning worker at:", WORKER_PATH);
51
55
  childProcess = spawn("bare", [
52
56
  WORKER_PATH,
53
57
  JSON.stringify({
@@ -58,7 +62,7 @@ export async function getRPC() {
58
62
  stdio: ["inherit", "inherit", "inherit"],
59
63
  });
60
64
  childProcess.on("exit", (code) => {
61
- console.log("Worker process exited with code:", code);
65
+ logger.info("Worker process exited with code:", code);
62
66
  // Clean up
63
67
  rpcInstance = null;
64
68
  if (ipcServer) {
@@ -67,18 +71,17 @@ export async function getRPC() {
67
71
  }
68
72
  });
69
73
  childProcess.on("error", (err) => {
70
- console.error("Worker process error:", err);
74
+ logger.error("Worker process error:", err);
71
75
  });
72
76
  });
73
77
  });
74
- // Wait for RPC to initialize, then replay config
78
+ // Wait for RPC to initialize, then send config
75
79
  const rpc = await serverPromise;
76
- const { replayConfigIfCached } = await import("../init-hooks.js");
77
- await replayConfigIfCached(rpc);
80
+ await initializeConfig(rpc, resolveConfig);
78
81
  return rpc;
79
82
  }
80
83
  // Clean up function
81
- export const cleanup = () => {
84
+ export function cleanup() {
82
85
  if (childProcess) {
83
86
  childProcess.kill();
84
87
  childProcess = null;
@@ -88,4 +91,4 @@ export const cleanup = () => {
88
91
  ipcServer = null;
89
92
  }
90
93
  rpcInstance = null;
91
- };
94
+ }
@@ -1,4 +1,4 @@
1
1
  import RPC from "bare-rpc";
2
- export declare const getRPC: () => Promise<RPC>;
3
- export declare const close: () => void;
2
+ export declare function getRPC(): Promise<RPC>;
3
+ export declare function close(): void;
4
4
  //# sourceMappingURL=expo-rpc-client.d.ts.map
@@ -1,9 +1,13 @@
1
1
  import RPC from "bare-rpc";
2
2
  import { RPCConnectionFailedError } from "../../utils/errors-client.js";
3
+ import { initializeConfig } from "../init-hooks.js";
4
+ import { resolveConfig } from "../config-loader/resolve-config.expo.js";
5
+ import { getClientLogger } from "../../logging/index.js";
6
+ const logger = getClientLogger();
3
7
  let rpcInstance = null;
4
8
  let rpcPromise = null;
5
- console.log("EXPO RPC Client bundle");
6
- export const getRPC = async () => {
9
+ logger.debug("EXPO RPC Client bundle");
10
+ export async function getRPC() {
7
11
  if (rpcInstance) {
8
12
  return rpcInstance;
9
13
  }
@@ -14,7 +18,7 @@ export const getRPC = async () => {
14
18
  const { Paths } = await import("expo-file-system");
15
19
  const bareKitModule = await import("react-native-bare-kit");
16
20
  const worklet = new bareKitModule.Worklet();
17
- console.log("Starting worklet");
21
+ logger.debug("Starting worklet");
18
22
  // Load the mobile bundle - this will be generated by the Expo plugin
19
23
  // using the user's installed bare library versions
20
24
  let mobileBundle;
@@ -28,7 +32,7 @@ export const getRPC = async () => {
28
32
  const message = "Failed to load mobile worker bundle. Make sure the QVAC Expo plugin is configured. " +
29
33
  `Add '@qvac/sdk/expo-plugin' to your app.json plugins array. ` +
30
34
  `Error: ${String(error)}`;
31
- console.error(message);
35
+ logger.error(message);
32
36
  throw new RPCConnectionFailedError(message, error instanceof Error ? error : undefined);
33
37
  }
34
38
  worklet.start("worker.bundle", mobileBundle, [
@@ -39,27 +43,26 @@ export const getRPC = async () => {
39
43
  HOME_DIR: Paths.document.uri.replace("file://", ""),
40
44
  }),
41
45
  ]);
42
- console.log("Worklet started");
46
+ logger.info("Worklet started");
43
47
  rpcInstance = new RPC(worklet.IPC, () => {
44
48
  // Use this for async callbacks
45
49
  });
46
- const { replayConfigIfCached } = await import("../init-hooks.js");
47
- await replayConfigIfCached(rpcInstance);
50
+ await initializeConfig(rpcInstance, resolveConfig);
48
51
  return rpcInstance;
49
52
  })();
50
53
  try {
51
54
  return await rpcPromise;
52
55
  }
53
56
  catch (error) {
54
- console.error(`Failed to initialize RPC: ${String(error)}`);
57
+ logger.error(`Failed to initialize RPC: ${String(error)}`);
55
58
  throw error;
56
59
  }
57
60
  finally {
58
61
  rpcPromise = null;
59
62
  }
60
- };
61
- export const close = () => {
62
- console.log("🧹 Closing RPC client (Expo)");
63
+ }
64
+ export function close() {
65
+ logger.info("🧹 Closing RPC client (Expo)");
63
66
  rpcInstance = null;
64
67
  rpcPromise = null;
65
- };
68
+ }
@@ -5,5 +5,5 @@ export declare function getRPC(): {
5
5
  createResponseStream: () => AsyncGenerator<unknown, void, unknown>;
6
6
  };
7
7
  };
8
- export declare const close: () => void;
8
+ export declare function close(): void;
9
9
  //# sourceMappingURL=node-rpc-client.d.ts.map
@@ -5,6 +5,10 @@ import os from "node:os";
5
5
  import path from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { RPCRequestNotSentError } from "../../utils/errors-client.js";
8
+ import { initializeConfig } from "../init-hooks.js";
9
+ import { resolveConfig } from "../config-loader/resolve-config.node.js";
10
+ import { getClientLogger } from "../../logging/index.js";
11
+ const logger = getClientLogger();
8
12
  const __filename = fileURLToPath(import.meta.url);
9
13
  const __dirname = path.dirname(__filename);
10
14
  let rpcInstance = null;
@@ -50,8 +54,7 @@ async function ensureRPC() {
50
54
  });
51
55
  });
52
56
  const rpc = await rpcPromise;
53
- const { replayConfigIfCached } = await import("../init-hooks.js");
54
- await replayConfigIfCached(rpc);
57
+ await initializeConfig(rpc, resolveConfig);
55
58
  return rpc;
56
59
  }
57
60
  const mockRPC = {
@@ -93,20 +96,20 @@ const mockRPC = {
93
96
  export function getRPC() {
94
97
  return mockRPC;
95
98
  }
96
- export const close = () => {
97
- console.log("🧹 Closing RPC client");
99
+ export function close() {
100
+ logger.info("🧹 Closing RPC client");
98
101
  if (bareWorkerProc) {
99
- console.log("šŸ»šŸ”« Killing bare worker process");
102
+ logger.info("šŸ»šŸ”« Killing bare worker process");
100
103
  bareWorkerProc.kill("SIGTERM");
101
104
  bareWorkerProc = null;
102
105
  }
103
106
  if (ipcServer) {
104
- console.log("šŸ”Œ Closing IPC server");
107
+ logger.info("šŸ”Œ Closing IPC server");
105
108
  ipcServer.close();
106
109
  ipcServer = null;
107
110
  }
108
111
  rpcInstance = null;
109
112
  rpcPromise = null;
110
- };
113
+ }
111
114
  // Register cleanup handlers for the parent process
112
115
  process.once("exit", close);
@@ -1,6 +1,9 @@
1
1
  import { requestSchema, responseSchema, } from "../../schemas/index.js";
2
2
  import { RPCError } from "./rpc-error.js";
3
3
  import { withTimeout, withTimeoutStream } from "../../utils/withTimeout.js";
4
+ import { isReactNative, isBare } from "../../utils/runtime.js";
5
+ import { getClientLogger } from "../../logging/index.js";
6
+ const logger = getClientLogger();
4
7
  let rpcInstance = null;
5
8
  let commandCounter = 0;
6
9
  function getNextCommandId() {
@@ -15,28 +18,26 @@ function checkAndThrowError(response) {
15
18
  async function getRPC() {
16
19
  if (rpcInstance)
17
20
  return rpcInstance;
18
- const isRN = typeof navigator !== "undefined" && navigator.product === "ReactNative";
19
- // Detect Bare runtime - Bare exposes global Bare object
20
- // TODO we can use something like https://www.npmjs.com/package/which-runtime at some point
21
- const isBare = typeof globalThis !== "undefined" && "Bare" in globalThis;
21
+ const isRN = isReactNative();
22
+ const isBareRuntime = isBare();
22
23
  // TODO Lots of type unsafe hacks to make this work cross platform
23
24
  if (isRN) {
24
- console.log("React Native runtime detected");
25
+ logger.debug("React Native runtime detected");
25
26
  // Only import expo client for React Native - Metro won't bundle the Node client
26
27
  const expoRPCClientPath = "./expo-rpc-client";
27
28
  const mod = (await import(expoRPCClientPath));
28
29
  rpcInstance = await (typeof mod === "function" ? mod() : mod.getRPC());
29
30
  return rpcInstance;
30
31
  }
31
- else if (isBare) {
32
- console.log("Bare runtime detected");
32
+ else if (isBareRuntime) {
33
+ logger.debug("Bare runtime detected");
33
34
  // Use dynamic import for Bare client
34
35
  const mod = await import("./bare-client.js");
35
- rpcInstance = mod.getRPC();
36
+ rpcInstance = (await mod.getRPC());
36
37
  return rpcInstance;
37
38
  }
38
39
  else {
39
- console.log("Node runtime detected");
40
+ logger.debug("Node runtime detected");
40
41
  // Use dynamic import for Node client to prevent Metro from bundling it
41
42
  const mod = await import("./node-rpc-client.js");
42
43
  rpcInstance = mod.getRPC();
@@ -50,7 +51,7 @@ export async function send(request, rpc, options) {
50
51
  // TODO temp for debugging, find a better solution to exclude large payloads
51
52
  // Log request type and basic info, avoid logging large payloads
52
53
  if (request.type === "transcribeStream") {
53
- console.log("RPC Client sending:", {
54
+ logger.debug("RPC Client sending:", {
54
55
  type: request.type,
55
56
  modelId: request.modelId,
56
57
  audioChunkType: request.audioChunk.type,
@@ -58,13 +59,13 @@ export async function send(request, rpc, options) {
58
59
  });
59
60
  }
60
61
  else {
61
- console.log("RPC Client sending:", request);
62
+ logger.debug("RPC Client sending:", request);
62
63
  }
63
64
  const payload = JSON.stringify(parsedRequest);
64
65
  req.send(payload, "utf-8");
65
66
  const response = await withTimeout(req.reply("utf-8"), options?.timeout);
66
67
  const resPayload = responseSchema.parse(JSON.parse(response?.toString() || "{}"));
67
- console.log("ResPayload", { type: resPayload.type });
68
+ logger.debug("ResPayload", { type: resPayload.type });
68
69
  checkAndThrowError(resPayload);
69
70
  return resPayload;
70
71
  }
@@ -98,13 +99,13 @@ export async function* stream(request, rpc, options = {}) {
98
99
  export async function close() {
99
100
  if (!rpcInstance)
100
101
  return;
101
- const isRN = typeof navigator !== "undefined" && navigator.product === "ReactNative";
102
- const isBare = typeof globalThis !== "undefined" && "Bare" in globalThis;
102
+ const isRN = isReactNative();
103
+ const isBareRuntime = isBare();
103
104
  if (isRN) {
104
105
  const mod = (await import("./expo-rpc-client.js"));
105
106
  mod.close();
106
107
  }
107
- else if (isBare) {
108
+ else if (isBareRuntime) {
108
109
  // Bare runs in-process (no separate worker), so no cleanup needed
109
110
  }
110
111
  else {
@@ -1,3 +1,2 @@
1
- export declare const FORMATS_NEEDING_DECODE: readonly [".mp3", ".m4a", ".ogg", ".flac", ".aac", ".wav"];
2
- export declare const SUPPORTED_AUDIO_FORMATS: readonly [".mp3", ".m4a", ".ogg", ".wav", ".flac", ".aac", ".raw"];
1
+ export { FORMATS_NEEDING_DECODE, SUPPORTED_AUDIO_FORMATS, } from "@qvac/decoder-audio/constants";
3
2
  //# sourceMappingURL=audio.d.ts.map
@@ -1,17 +1 @@
1
- export const FORMATS_NEEDING_DECODE = [
2
- ".mp3",
3
- ".m4a",
4
- ".ogg",
5
- ".flac",
6
- ".aac",
7
- ".wav",
8
- ];
9
- export const SUPPORTED_AUDIO_FORMATS = [
10
- ".mp3",
11
- ".m4a",
12
- ".ogg",
13
- ".wav",
14
- ".flac",
15
- ".aac",
16
- ".raw",
17
- ];
1
+ export { FORMATS_NEEDING_DECODE, SUPPORTED_AUDIO_FORMATS, } from "@qvac/decoder-audio/constants.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Helper to get the config file path for examples.
3
+ *
4
+ * Note: This is Node.js-only (uses 'url' and 'path' modules).
5
+ * For Bare runtime, place your config file in the project root and let the SDK auto-discover it.
6
+ */
7
+ export declare function getConfigPath(importMetaUrl: string, configFileName: string): string;
8
+ //# sourceMappingURL=config-path.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { fileURLToPath } from "url";
2
+ import { dirname, join } from "path";
3
+ /**
4
+ * Helper to get the config file path for examples.
5
+ *
6
+ * Note: This is Node.js-only (uses 'url' and 'path' modules).
7
+ * For Bare runtime, place your config file in the project root and let the SDK auto-discover it.
8
+ */
9
+ export function getConfigPath(importMetaUrl, configFileName) {
10
+ const __filename = fileURLToPath(importMetaUrl);
11
+ const __dirname = dirname(__filename);
12
+ return join(__dirname, "config", configFileName);
13
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config-reload.d.ts.map
@@ -0,0 +1,49 @@
1
+ import { WHISPER_TINY, loadModel, transcribe, unloadModel } from "../index";
2
+ // Parse command line arguments
3
+ const args = process.argv.slice(2);
4
+ if (!args[0]) {
5
+ console.error("Usage: bun run examples/config-reload.ts <audio-file-path>");
6
+ process.exit(1);
7
+ }
8
+ const audioFilePath = args[0];
9
+ try {
10
+ // Initial load with English language
11
+ console.log("Loading Whisper model with English config...");
12
+ const modelId = await loadModel({
13
+ modelSrc: WHISPER_TINY,
14
+ modelType: "whisper",
15
+ modelConfig: {
16
+ language: "en",
17
+ },
18
+ });
19
+ // Transcribe with English config
20
+ console.log("Transcribing audio with English config...");
21
+ const englishText = await transcribe({
22
+ modelId,
23
+ audioChunk: audioFilePath,
24
+ });
25
+ console.log(`Transcription (EN): ${englishText}`);
26
+ console.log();
27
+ // Hot reload config - change language and temperature
28
+ console.log("Hot reloading config (changing language and temperature)...");
29
+ const reloadedId = await loadModel({
30
+ modelId,
31
+ modelType: "whisper",
32
+ modelConfig: {
33
+ language: "es", // Change to Spanish
34
+ },
35
+ });
36
+ console.log(`Config reloaded, same model ID: ${reloadedId === modelId}`);
37
+ // Transcribe again with updated config
38
+ console.log("Transcribing with updated config...");
39
+ const spanishText = await transcribe({
40
+ modelId,
41
+ audioChunk: audioFilePath,
42
+ });
43
+ console.log(`Transcription (ES): ${spanishText}`);
44
+ await unloadModel({ modelId });
45
+ }
46
+ catch (error) {
47
+ console.error("āŒ Error:", error);
48
+ process.exit(1);
49
+ }
@@ -1,26 +1,25 @@
1
- import { downloadAsset, setConfig, close, LLAMA_3_2_1B_INST_Q4_0, } from "@qvac/sdk";
2
- // āš ļø IMPORTANT: These are MOCK relay public keys for demonstration only
3
- // To use blind relays in production:
4
- // 1. Run your own relay servers using hyperswarm
5
- // 2. Use well-known public relays from trusted sources
6
- // 3. Never rely on example/mock keys for production use
7
- const MOCK_RELAY_PUBLIC_KEYS = [
8
- "0000000000000000000000000000000000000000000000000000000000000001",
9
- "0000000000000000000000000000000000000000000000000000000000000002",
10
- "0000000000000000000000000000000000000000000000000000000000000003",
11
- ];
1
+ // Set config path before importing SDK - the SDK loads config during initialization
2
+ // This example uses a config file that defines blind relay public keys for improved P2P connectivity
3
+ // Blind relays help establish connections through NAT/firewalls by acting as intermediaries
4
+ import { getConfigPath } from "./config/config-path.js";
5
+ process.env["QVAC_CONFIG_PATH"] = getConfigPath(import.meta.url, "qvac.config.json");
6
+ import { downloadAsset, close, LLAMA_3_2_1B_INST_Q4_0, loadModel, getModelInfo, unloadModel, } from "@qvac/sdk";
12
7
  console.log(`šŸš€ Download with Blind Relays Example`);
13
8
  console.log(`${"=".repeat(60)}\n`);
14
- console.log(`āš ļø Using MOCK relay keys - replace with real relays!\n`);
15
9
  try {
16
- // Configure SDK to use blind relays for improved connectivity
17
- // Blind relays help with NAT traversal and firewall bypassing
18
- await setConfig({
19
- swarmRelays: MOCK_RELAY_PUBLIC_KEYS,
20
- });
21
- console.log(`āœ… Configured ${MOCK_RELAY_PUBLIC_KEYS.length} blind relays`);
10
+ // Config is loaded from examples/config/qvac.config.json (set via QVAC_CONFIG_PATH above)
11
+ // The config contains swarmRelays - an array of Hyperswarm relay public keys
12
+ // These relays help with NAT traversal and firewall bypassing for P2P downloads
22
13
  console.log(`šŸ“„ Starting model download from Hyperdrive...\n`);
23
14
  const startTime = Date.now();
15
+ const modelId = await loadModel({
16
+ modelSrc: LLAMA_3_2_1B_INST_Q4_0,
17
+ modelType: "llm",
18
+ });
19
+ console.log(`Model loaded with ID: ${modelId}`);
20
+ const firstStatus = await getModelInfo(LLAMA_3_2_1B_INST_Q4_0);
21
+ console.log(`First status: ${JSON.stringify(firstStatus)}`);
22
+ await unloadModel({ modelId });
24
23
  // Download model with progress tracking
25
24
  await downloadAsset({
26
25
  assetSrc: LLAMA_3_2_1B_INST_Q4_0,
@@ -42,7 +41,8 @@ try {
42
41
  }
43
42
  catch (error) {
44
43
  console.error("āŒ Error:", error);
45
- console.log(`\nIf download failed, ensure you're using valid relay public keys`);
46
- console.log(` Mock keys in this example won't work in practice!`);
44
+ console.log(`\nIf download failed, check the relay public keys in:`);
45
+ console.log(` examples/config/qvac.config.json`);
46
+ console.log(` (Mock keys in this example won't work in practice!)`);
47
47
  process.exit(1);
48
48
  }
@@ -1,4 +1,11 @@
1
1
  import { embed, GTE_LARGE_FP16, loadModel, unloadModel } from "@qvac/sdk";
2
+ function cosineSimilarity(vecA, vecB) {
3
+ let dotProduct = 0;
4
+ for (let i = 0; i < vecA.length; i++) {
5
+ dotProduct += vecA[i] * vecB[i];
6
+ }
7
+ return dotProduct;
8
+ }
2
9
  try {
3
10
  const modelId = await loadModel({
4
11
  modelSrc: GTE_LARGE_FP16,
@@ -7,9 +14,34 @@ try {
7
14
  console.log(progress);
8
15
  },
9
16
  });
10
- const embedding = await embed({ modelId, text: "Hello, world!" });
11
- console.log("Embedding (first 20 elements)", embedding.slice(0, 20));
12
- console.log("Embeddings length", embedding.length);
17
+ console.log("\nšŸ“ Example 1: Single Text Embedding");
18
+ console.log("=".repeat(50));
19
+ const singleEmbedding = await embed({ modelId, text: "Hello, world!" });
20
+ console.log("Input: 'Hello, world!'");
21
+ console.log("Embedding dimensions:", singleEmbedding.length);
22
+ console.log("First 10 values:", singleEmbedding.slice(0, 10));
23
+ console.log("\nšŸ“ Example 2: Batch Text Embeddings");
24
+ console.log("=".repeat(50));
25
+ const texts = [
26
+ "The quick brown fox jumps over the lazy dog",
27
+ "A fast auburn fox leaps over a sleepy canine",
28
+ "Python is a programming language",
29
+ ];
30
+ const batchEmbeddings = await embed({ modelId, text: texts });
31
+ console.log("Input: Array of", texts.length, "texts");
32
+ console.log("Output: Array of", batchEmbeddings.length, "embeddings");
33
+ const [emb1, emb2, emb3] = batchEmbeddings;
34
+ if (!emb1 || !emb2 || !emb3) {
35
+ throw new Error("Expected 3 embeddings");
36
+ }
37
+ console.log("Each embedding dimensions:", emb1.length);
38
+ console.log("\nšŸ” Similarity Analysis");
39
+ console.log("=".repeat(50));
40
+ const similarity1 = cosineSimilarity(emb1, emb2);
41
+ const similarity2 = cosineSimilarity(emb1, emb3);
42
+ console.log("Similarity between texts 1 and 2 (similar meaning):", similarity1.toFixed(4));
43
+ console.log("Similarity between texts 1 and 3 (different topics):", similarity2.toFixed(4));
44
+ console.log("\nšŸ’” Higher values indicate more similar meanings");
13
45
  await unloadModel({ modelId, clearStorage: false });
14
46
  }
15
47
  catch (error) {
@@ -9,7 +9,7 @@ try {
9
9
  modelConfig: {
10
10
  device: "gpu",
11
11
  ctx_size: 2048,
12
- verbosity: VERBOSITY.SILENT,
12
+ verbosity: VERBOSITY.ERROR,
13
13
  },
14
14
  });
15
15
  // Create some cached sessions
@@ -14,7 +14,7 @@ try {
14
14
  modelConfig: {
15
15
  device: "gpu",
16
16
  ctx_size: 2048,
17
- verbosity: VERBOSITY.SILENT,
17
+ verbosity: VERBOSITY.ERROR,
18
18
  },
19
19
  });
20
20
  // Prompt 1 with cache key "session-a" (first time - no cache exists)
@@ -7,7 +7,7 @@ try {
7
7
  modelConfig: {
8
8
  device: "gpu",
9
9
  ctx_size: 2048,
10
- verbosity: VERBOSITY.SILENT,
10
+ verbosity: VERBOSITY.ERROR,
11
11
  },
12
12
  });
13
13
  console.log("🧠 Testing KV Cache functionality...\n");
@@ -14,7 +14,7 @@ try {
14
14
  modelConfig: {
15
15
  device: "gpu",
16
16
  ctx_size: 2048,
17
- verbosity: VERBOSITY.SILENT,
17
+ verbosity: VERBOSITY.ERROR,
18
18
  },
19
19
  });
20
20
  const history = [
@@ -6,7 +6,7 @@ try {
6
6
  modelConfig: {
7
7
  device: "gpu",
8
8
  ctx_size: 2048,
9
- verbosity: VERBOSITY.SILENT,
9
+ verbosity: VERBOSITY.ERROR,
10
10
  },
11
11
  onProgress: (progress) => {
12
12
  if (progress.shardInfo) {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logging-file-transport.d.ts.map
@@ -1,8 +1,6 @@
1
- import { getLogger } from "../logging/index.js";
2
- import { loadModel, completion, unloadModel } from "../client/api/index.js";
1
+ import { getLogger, loadModel, completion, unloadModel, LLAMA_3_2_1B_INST_Q4_0, VERBOSITY, } from "@qvac/sdk";
3
2
  import { writeFileSync, appendFileSync } from "fs";
4
3
  import { join } from "path";
5
- import { LLAMA_3_2_1B_INST_Q4_0 } from "../models/hyperdrive/index.js";
6
4
  try {
7
5
  const logFile = join(process.cwd(), "model-logs.txt");
8
6
  // Clear previous logs
@@ -10,6 +8,7 @@ try {
10
8
  // Create logger with file transport
11
9
  const logger = getLogger("llm-file-demo", {
12
10
  level: "debug",
11
+ enableConsole: false, // Disable console output (logs go to file only). Set to true for both console + file
13
12
  transports: [
14
13
  // File transport - append logs to file
15
14
  (level, namespace, message) => {
@@ -17,10 +16,6 @@ try {
17
16
  const logLine = `[${timestamp}] ${level.toUpperCase()} ${namespace}: ${message}\n`;
18
17
  appendFileSync(logFile, logLine);
19
18
  },
20
- // Console transport for immediate feedback
21
- (level, namespace, message) => {
22
- console.log(`šŸ” [${level.toUpperCase()}] ${namespace}: ${message}`);
23
- },
24
19
  ],
25
20
  });
26
21
  logger.info("Starting model demo with file logging");
@@ -31,6 +26,7 @@ try {
31
26
  modelConfig: {
32
27
  ctx_size: 2048,
33
28
  temp: 0.7,
29
+ verbosity: VERBOSITY.DEBUG,
34
30
  },
35
31
  logger, // All model logs will be captured
36
32
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logging-streaming.d.ts.map