@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.
- package/README.md +328 -200
- package/dist/client/api/completion-stream.d.ts +15 -5
- package/dist/client/api/completion-stream.js +50 -14
- package/dist/client/api/embed.d.ts +17 -3
- package/dist/client/api/embed.js +0 -8
- package/dist/client/api/get-model-info.d.ts +1 -1
- package/dist/client/api/index.d.ts +0 -1
- package/dist/client/api/index.js +0 -1
- package/dist/client/api/load-model.d.ts +37 -11
- package/dist/client/api/load-model.js +29 -117
- package/dist/client/api/logging-stream.d.ts +6 -3
- package/dist/client/api/logging-stream.js +6 -3
- package/dist/client/api/unload-model.js +5 -2
- package/dist/client/config-loader/config-utils.d.ts +5 -0
- package/dist/client/config-loader/config-utils.js +20 -0
- package/dist/client/config-loader/resolve-config.bare.d.ts +9 -0
- package/dist/client/config-loader/resolve-config.bare.js +87 -0
- package/dist/client/config-loader/resolve-config.expo.d.ts +11 -0
- package/dist/client/config-loader/resolve-config.expo.js +62 -0
- package/dist/client/config-loader/resolve-config.node.d.ts +9 -0
- package/dist/client/config-loader/resolve-config.node.js +118 -0
- package/dist/client/init-hooks.d.ts +17 -3
- package/dist/client/init-hooks.js +37 -18
- package/dist/client/logging-stream-registry.d.ts +1 -1
- package/dist/client/logging-stream-registry.js +14 -13
- package/dist/client/rpc/bare-client.d.ts +10 -14
- package/dist/client/rpc/bare-client.js +28 -2
- package/dist/client/rpc/bare-rpc-client.d.ts +1 -1
- package/dist/client/rpc/bare-rpc-client.js +16 -13
- package/dist/client/rpc/expo-rpc-client.d.ts +2 -2
- package/dist/client/rpc/expo-rpc-client.js +15 -12
- package/dist/client/rpc/node-rpc-client.d.ts +1 -1
- package/dist/client/rpc/node-rpc-client.js +10 -7
- package/dist/client/rpc/rpc-client.js +16 -15
- package/dist/constants/audio.d.ts +1 -2
- package/dist/constants/audio.js +1 -17
- package/dist/examples/config/config-path.d.ts +8 -0
- package/dist/examples/config/config-path.js +13 -0
- package/dist/examples/config-reload.d.ts +2 -0
- package/dist/examples/config-reload.js +49 -0
- package/dist/examples/download-with-blind-relays.js +20 -20
- package/dist/examples/embed-hyperdrive.js +35 -3
- package/dist/examples/kv-cache-cleanup.js +1 -1
- package/dist/examples/kv-cache-custom-key.js +1 -1
- package/dist/examples/kv-cache-example.js +1 -1
- package/dist/examples/llamacpp-hyperdrive.js +1 -1
- package/dist/examples/llamacpp-sharded.js +1 -1
- package/dist/examples/logging-file-transport.d.ts +2 -0
- package/dist/examples/{llamacpp-file-logging.js ā logging-file-transport.js} +3 -7
- package/dist/examples/logging-streaming.d.ts +2 -0
- package/dist/examples/logging-streaming.js +75 -0
- package/dist/examples/mcp-websearch.d.ts +13 -0
- package/dist/examples/mcp-websearch.js +176 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/logging/addon.d.ts +6 -0
- package/dist/logging/addon.js +59 -0
- package/dist/logging/base-logger.js +24 -14
- package/dist/logging/client-logger.d.ts +3 -0
- package/dist/logging/client-logger.js +13 -0
- package/dist/logging/index.d.ts +6 -1
- package/dist/logging/index.js +6 -1
- package/dist/logging/logger.d.ts +0 -2
- package/dist/logging/logger.js +0 -3
- package/dist/logging/namespaces.d.ts +11 -0
- package/dist/logging/namespaces.js +11 -0
- package/dist/logging/registry.d.ts +26 -0
- package/dist/logging/registry.js +36 -0
- package/dist/logging/server-logger.d.ts +3 -0
- package/dist/logging/server-logger.js +16 -0
- package/dist/logging/stream-logger.d.ts +1 -1
- package/dist/logging/stream-logger.js +6 -3
- package/dist/logging/types.d.ts +2 -0
- package/dist/models/hyperdrive/models.d.ts +789 -51
- package/dist/models/hyperdrive/models.js +979 -200
- package/dist/schemas/common.d.ts +86 -23
- package/dist/schemas/common.js +0 -3
- package/dist/schemas/download-asset.d.ts +5 -5
- package/dist/schemas/embed.d.ts +3 -3
- package/dist/schemas/embed.js +9 -2
- package/dist/schemas/get-model-info.d.ts +2 -2
- package/dist/schemas/index.d.ts +5 -1
- package/dist/schemas/index.js +5 -1
- package/dist/schemas/json-schema.d.ts +16 -0
- package/dist/schemas/json-schema.js +2 -0
- package/dist/schemas/llamacpp-config.d.ts +5 -4
- package/dist/schemas/llamacpp-config.js +7 -5
- package/dist/schemas/load-model.d.ts +931 -211
- package/dist/schemas/load-model.js +7 -1
- package/dist/schemas/logging-stream.d.ts +10 -3
- package/dist/schemas/logging-stream.js +4 -3
- package/dist/schemas/mcp-adapter.d.ts +47 -0
- package/dist/schemas/mcp-adapter.js +1 -0
- package/dist/schemas/model-src-utils.d.ts +8 -6
- package/dist/schemas/model-src-utils.js +8 -3
- package/dist/schemas/reload-config.d.ts +344 -0
- package/dist/schemas/reload-config.js +42 -0
- package/dist/schemas/sdk-config.d.ts +22 -0
- package/dist/schemas/sdk-config.js +33 -0
- package/dist/schemas/sdk-errors-client.d.ts +4 -0
- package/dist/schemas/sdk-errors-client.js +20 -0
- package/dist/schemas/sdk-errors-server.d.ts +3 -0
- package/dist/schemas/sdk-errors-server.js +15 -0
- package/dist/schemas/tools.d.ts +3 -0
- package/dist/schemas/translation-config.d.ts +81 -0
- package/dist/schemas/translation-config.js +3 -4
- package/dist/schemas/whispercpp-config.d.ts +9 -1
- package/dist/schemas/whispercpp-config.js +2 -1
- package/dist/server/bare/addons/llamacpp/create-model.js +13 -4
- package/dist/server/bare/addons/llamacpp/handlers/embed.d.ts +9 -1
- package/dist/server/bare/addons/llamacpp/handlers/embed.js +18 -4
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +6 -4
- package/dist/server/bare/addons/load-model.js +10 -4
- package/dist/server/bare/addons/unload-model.js +6 -3
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +56 -37
- package/dist/server/bare/delegate-rpc-client.js +12 -10
- package/dist/server/bare/hyperswarm.js +7 -5
- package/dist/server/bare/rag-hyperdb/rag-manager.js +3 -1
- package/dist/server/bare/registry/config-registry.d.ts +13 -4
- package/dist/server/bare/registry/config-registry.js +42 -10
- package/dist/server/bare/registry/logging-stream-registry.d.ts +24 -7
- package/dist/server/bare/registry/logging-stream-registry.js +99 -20
- package/dist/server/bare/registry/model-registry.d.ts +3 -0
- package/dist/server/bare/registry/model-registry.js +9 -6
- package/dist/server/rpc/create-server.js +5 -3
- package/dist/server/rpc/handle-request.js +30 -16
- package/dist/server/rpc/handlers/cancelHandler.js +3 -1
- package/dist/server/rpc/handlers/completion-stream-delegated.js +4 -2
- package/dist/server/rpc/handlers/delete-cache.js +3 -1
- package/dist/server/rpc/handlers/download-asset.js +3 -1
- package/dist/server/rpc/handlers/embed.js +3 -1
- package/dist/server/rpc/handlers/index.d.ts +0 -1
- package/dist/server/rpc/handlers/index.js +0 -2
- package/dist/server/rpc/handlers/load-model/download-manager.js +4 -2
- package/dist/server/rpc/handlers/load-model/http.js +20 -18
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +21 -19
- package/dist/server/rpc/handlers/load-model/resolve.js +7 -5
- package/dist/server/rpc/handlers/load-model-delegated.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model-delegated.js +10 -8
- package/dist/server/rpc/handlers/load-model.js +55 -3
- package/dist/server/rpc/handlers/logging-stream.js +4 -4
- package/dist/server/rpc/handlers/provideHandler/connection.js +12 -10
- package/dist/server/rpc/handlers/provideHandler/handler.js +18 -16
- package/dist/server/rpc/handlers/provideHandler/proxy.js +8 -6
- package/dist/server/rpc/handlers/rag.js +3 -1
- package/dist/server/rpc/handlers/stopProvideHandler.js +3 -1
- package/dist/server/rpc/handlers/transcribe-stream.js +3 -1
- package/dist/server/rpc/handlers/translate.js +3 -1
- package/dist/server/rpc/handlers/unload-model.js +4 -2
- package/dist/server/utils/audio/decoder.d.ts +2 -1
- package/dist/server/utils/audio/decoder.js +49 -12
- package/dist/server/utils/cache.js +7 -5
- package/dist/server/utils/config-transform.d.ts +3 -0
- package/dist/server/utils/config-transform.js +21 -0
- package/dist/server/utils/index.d.ts +1 -0
- package/dist/server/utils/index.js +1 -0
- package/dist/server/worker.js +41 -16
- package/dist/utils/errors-client.d.ts +12 -0
- package/dist/utils/errors-client.js +20 -0
- package/dist/utils/errors-server.d.ts +9 -0
- package/dist/utils/errors-server.js +16 -0
- package/dist/utils/getProcessSafe.d.ts +7 -0
- package/dist/utils/getProcessSafe.js +17 -0
- package/dist/utils/mcp-adapter.d.ts +12 -0
- package/dist/utils/mcp-adapter.js +103 -0
- package/dist/utils/object.d.ts +2 -0
- package/dist/utils/object.js +3 -0
- package/dist/utils/runtime.d.ts +30 -0
- package/dist/utils/runtime.js +48 -0
- package/dist/utils/tool-helpers.d.ts +10 -2
- package/dist/utils/tool-helpers.js +24 -11
- package/package.json +47 -34
- package/dist/client/api/set-config.d.ts +0 -7
- package/dist/client/api/set-config.js +0 -20
- package/dist/client/config-manager.d.ts +0 -4
- package/dist/client/config-manager.js +0 -8
- package/dist/examples/llamacpp-file-logging.d.ts +0 -2
- package/dist/schemas/set-config.d.ts +0 -21
- package/dist/schemas/set-config.js +0 -14
- package/dist/server/rpc/handlers/set-config.d.ts +0 -3
- 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
|
-
|
|
32
|
+
logger.debug("returning cached bare rpc");
|
|
29
33
|
return rpcInstance;
|
|
30
34
|
}
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
+
logger.error("Failed to start IPC server:", err);
|
|
44
48
|
reject(err);
|
|
45
49
|
});
|
|
46
50
|
server.listen(SOCKET_PATH, () => {
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
+
logger.error("Worker process error:", err);
|
|
71
75
|
});
|
|
72
76
|
});
|
|
73
77
|
});
|
|
74
|
-
// Wait for RPC to initialize, then
|
|
78
|
+
// Wait for RPC to initialize, then send config
|
|
75
79
|
const rpc = await serverPromise;
|
|
76
|
-
|
|
77
|
-
await replayConfigIfCached(rpc);
|
|
80
|
+
await initializeConfig(rpc, resolveConfig);
|
|
78
81
|
return rpc;
|
|
79
82
|
}
|
|
80
83
|
// Clean up function
|
|
81
|
-
export
|
|
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,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
|
-
|
|
6
|
-
export
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
+
logger.info("Worklet started");
|
|
43
47
|
rpcInstance = new RPC(worklet.IPC, () => {
|
|
44
48
|
// Use this for async callbacks
|
|
45
49
|
});
|
|
46
|
-
|
|
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
|
-
|
|
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
|
|
62
|
-
|
|
63
|
+
}
|
|
64
|
+
export function close() {
|
|
65
|
+
logger.info("š§¹ Closing RPC client (Expo)");
|
|
63
66
|
rpcInstance = null;
|
|
64
67
|
rpcPromise = null;
|
|
65
|
-
}
|
|
68
|
+
}
|
|
@@ -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
|
-
|
|
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
|
|
97
|
-
|
|
99
|
+
export function close() {
|
|
100
|
+
logger.info("š§¹ Closing RPC client");
|
|
98
101
|
if (bareWorkerProc) {
|
|
99
|
-
|
|
102
|
+
logger.info("š»š« Killing bare worker process");
|
|
100
103
|
bareWorkerProc.kill("SIGTERM");
|
|
101
104
|
bareWorkerProc = null;
|
|
102
105
|
}
|
|
103
106
|
if (ipcServer) {
|
|
104
|
-
|
|
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 =
|
|
19
|
-
|
|
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
|
-
|
|
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 (
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
102
|
-
const
|
|
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 (
|
|
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
|
|
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
|
package/dist/constants/audio.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
export
|
|
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,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
|
-
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
//
|
|
17
|
-
//
|
|
18
|
-
|
|
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,
|
|
46
|
-
console.log(`
|
|
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
|
-
|
|
11
|
-
console.log("
|
|
12
|
-
|
|
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) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { getLogger } from "
|
|
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
|
});
|