@qvac/sdk 0.4.1 → 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/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 +48 -11
- 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 +46 -33
- 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
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config loader for Bare runtime
|
|
3
|
+
* Uses bare-fs and bare-path modules
|
|
4
|
+
*/
|
|
5
|
+
import fs from "bare-fs";
|
|
6
|
+
import path from "bare-path";
|
|
7
|
+
import process from "bare-process";
|
|
8
|
+
import { validateConfig, parseJsonConfig, } from "./config-utils.js";
|
|
9
|
+
import { ConfigFileParseFailedError } from "../../utils/errors-client.js";
|
|
10
|
+
import { getClientLogger } from "../../logging/index.js";
|
|
11
|
+
const logger = getClientLogger();
|
|
12
|
+
function findProjectRoot() {
|
|
13
|
+
return process.cwd();
|
|
14
|
+
}
|
|
15
|
+
function fileExists(filePath) {
|
|
16
|
+
return fs.existsSync(filePath);
|
|
17
|
+
}
|
|
18
|
+
function readFile(filePath) {
|
|
19
|
+
const result = fs.readFileSync(filePath, "utf-8");
|
|
20
|
+
return typeof result === "string" ? result : result.toString("utf-8");
|
|
21
|
+
}
|
|
22
|
+
function loadJsonConfig(filePath) {
|
|
23
|
+
const content = readFile(filePath);
|
|
24
|
+
const parsed = parseJsonConfig(content, filePath);
|
|
25
|
+
return validateConfig(parsed);
|
|
26
|
+
}
|
|
27
|
+
async function loadJsConfig(filePath) {
|
|
28
|
+
try {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
30
|
+
const configModule = await import(filePath);
|
|
31
|
+
return validateConfig(configModule.default || configModule);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new ConfigFileParseFailedError(filePath, error instanceof Error ? error.message : String(error), error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function findConfigFile(searchDir) {
|
|
38
|
+
const configFiles = [
|
|
39
|
+
{ name: "qvac.config.ts", type: "ts" },
|
|
40
|
+
{ name: "qvac.config.js", type: "js" },
|
|
41
|
+
{ name: "qvac.config.json", type: "json" },
|
|
42
|
+
];
|
|
43
|
+
for (const { name, type } of configFiles) {
|
|
44
|
+
const filePath = path.resolve(searchDir, name);
|
|
45
|
+
if (fileExists(filePath)) {
|
|
46
|
+
return { path: filePath, type };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolution order for Bare:
|
|
53
|
+
* 1. QVAC_CONFIG_PATH environment variable
|
|
54
|
+
* 2. Config file in project root (qvac.config.ts, qvac.config.js, qvac.config.json)
|
|
55
|
+
* 3. SDK defaults
|
|
56
|
+
*/
|
|
57
|
+
export async function resolveConfig() {
|
|
58
|
+
const configPath = process.env["QVAC_CONFIG_PATH"];
|
|
59
|
+
if (configPath) {
|
|
60
|
+
const normalizedPath = path.resolve(configPath);
|
|
61
|
+
if (fileExists(normalizedPath)) {
|
|
62
|
+
const ext = normalizedPath.endsWith(".json")
|
|
63
|
+
? "json"
|
|
64
|
+
: normalizedPath.endsWith(".ts")
|
|
65
|
+
? "ts"
|
|
66
|
+
: "js";
|
|
67
|
+
const config = ext === "json"
|
|
68
|
+
? loadJsonConfig(normalizedPath)
|
|
69
|
+
: await loadJsConfig(normalizedPath);
|
|
70
|
+
logger.info(`✅ Loaded config from: ${normalizedPath}`);
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const projectRoot = findProjectRoot();
|
|
75
|
+
if (projectRoot) {
|
|
76
|
+
const configFile = findConfigFile(projectRoot);
|
|
77
|
+
if (configFile) {
|
|
78
|
+
const config = configFile.type === "json"
|
|
79
|
+
? loadJsonConfig(configFile.path)
|
|
80
|
+
: await loadJsConfig(configFile.path);
|
|
81
|
+
logger.info(`✅ Loaded config from: ${configFile.path}`);
|
|
82
|
+
return config;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
logger.info("ℹ️ No config file found, using SDK defaults");
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type QvacConfig } from "./config-utils";
|
|
2
|
+
/**
|
|
3
|
+
* Resolution order for Expo:
|
|
4
|
+
* 1. QVAC_CONFIG_PATH environment variable (if set)
|
|
5
|
+
* 2. Default Expo path: ${Paths.document.uri}qvac.config.json
|
|
6
|
+
* 3. SDK defaults
|
|
7
|
+
*
|
|
8
|
+
* Note: Only JSON config files are supported in React Native
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveConfig(): Promise<QvacConfig | undefined>;
|
|
11
|
+
//# sourceMappingURL=resolve-config.expo.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config loader for Expo/React Native runtime
|
|
3
|
+
* Only uses expo-file-system - no Node.js or Bare imports
|
|
4
|
+
*/
|
|
5
|
+
import { File, Paths } from "expo-file-system";
|
|
6
|
+
import { validateConfig, parseJsonConfig, } from "./config-utils.js";
|
|
7
|
+
import { getClientLogger } from "../../logging/index.js";
|
|
8
|
+
const logger = getClientLogger();
|
|
9
|
+
function fileExists(filePath) {
|
|
10
|
+
try {
|
|
11
|
+
const file = new File(filePath);
|
|
12
|
+
return file.exists;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async function readFile(filePath) {
|
|
19
|
+
const file = new File(filePath);
|
|
20
|
+
return await file.text();
|
|
21
|
+
}
|
|
22
|
+
async function loadJsonConfig(filePath) {
|
|
23
|
+
const content = await readFile(filePath);
|
|
24
|
+
const parsed = parseJsonConfig(content, filePath);
|
|
25
|
+
return validateConfig(parsed);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolution order for Expo:
|
|
29
|
+
* 1. QVAC_CONFIG_PATH environment variable (if set)
|
|
30
|
+
* 2. Default Expo path: ${Paths.document.uri}qvac.config.json
|
|
31
|
+
* 3. SDK defaults
|
|
32
|
+
*
|
|
33
|
+
* Note: Only JSON config files are supported in React Native
|
|
34
|
+
*/
|
|
35
|
+
export async function resolveConfig() {
|
|
36
|
+
// Check environment variable first
|
|
37
|
+
const configPath = typeof process !== "undefined"
|
|
38
|
+
? process.env?.["QVAC_CONFIG_PATH"]
|
|
39
|
+
: undefined;
|
|
40
|
+
if (configPath) {
|
|
41
|
+
if (fileExists(configPath)) {
|
|
42
|
+
logger.info(`✅ Loaded config from: ${configPath}`);
|
|
43
|
+
return await loadJsonConfig(configPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Try default Expo document directory path
|
|
47
|
+
try {
|
|
48
|
+
const documentDir = Paths.document.uri;
|
|
49
|
+
if (documentDir) {
|
|
50
|
+
const defaultExpoConfigPath = `${documentDir}qvac.config.json`;
|
|
51
|
+
if (fileExists(defaultExpoConfigPath)) {
|
|
52
|
+
logger.info(`✅ Loaded config from: ${defaultExpoConfigPath}`);
|
|
53
|
+
return await loadJsonConfig(defaultExpoConfigPath);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Paths not available
|
|
59
|
+
}
|
|
60
|
+
logger.info("ℹ️ No config file found, using SDK defaults");
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type QvacConfig } from "./config-utils";
|
|
2
|
+
/**
|
|
3
|
+
* Resolution order for Node.js:
|
|
4
|
+
* 1. QVAC_CONFIG_PATH environment variable
|
|
5
|
+
* 2. Config file in project root (qvac.config.ts, qvac.config.js, qvac.config.json)
|
|
6
|
+
* 3. SDK defaults
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveConfig(): Promise<QvacConfig | undefined>;
|
|
9
|
+
//# sourceMappingURL=resolve-config.node.d.ts.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config loader for Node.js runtime
|
|
3
|
+
* Uses Node.js fs/promises and path modules
|
|
4
|
+
*/
|
|
5
|
+
import { promises as fs } from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { pathToFileURL } from "url";
|
|
8
|
+
import { validateConfig, parseJsonConfig, } from "./config-utils.js";
|
|
9
|
+
import { ConfigFileParseFailedError } from "../../utils/errors-client.js";
|
|
10
|
+
import { getClientLogger } from "../../logging/index.js";
|
|
11
|
+
const logger = getClientLogger();
|
|
12
|
+
async function findProjectRoot() {
|
|
13
|
+
try {
|
|
14
|
+
let currentDir = path.resolve(process.cwd());
|
|
15
|
+
const root = path.parse(currentDir).root;
|
|
16
|
+
while (currentDir !== root) {
|
|
17
|
+
try {
|
|
18
|
+
const packageJsonPath = path.join(currentDir, "package.json");
|
|
19
|
+
await fs.access(packageJsonPath);
|
|
20
|
+
return currentDir;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
const parentDir = path.dirname(currentDir);
|
|
24
|
+
if (parentDir === currentDir) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
currentDir = parentDir;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Fall through
|
|
33
|
+
}
|
|
34
|
+
return process.cwd();
|
|
35
|
+
}
|
|
36
|
+
async function fileExists(filePath) {
|
|
37
|
+
try {
|
|
38
|
+
await fs.access(filePath);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function readFile(filePath) {
|
|
46
|
+
return await fs.readFile(filePath, { encoding: "utf-8" });
|
|
47
|
+
}
|
|
48
|
+
async function loadJsonConfig(filePath) {
|
|
49
|
+
const content = await readFile(filePath);
|
|
50
|
+
const parsed = parseJsonConfig(content, filePath);
|
|
51
|
+
return validateConfig(parsed);
|
|
52
|
+
}
|
|
53
|
+
async function loadJsConfig(filePath) {
|
|
54
|
+
try {
|
|
55
|
+
let importPath = filePath;
|
|
56
|
+
// Windows requires file:// URLs for dynamic imports
|
|
57
|
+
if (process.platform === "win32" && !process.env["JEST_WORKER_ID"]) {
|
|
58
|
+
importPath = pathToFileURL(filePath).toString();
|
|
59
|
+
}
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
61
|
+
const configModule = await import(importPath);
|
|
62
|
+
return validateConfig(configModule.default || configModule);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new ConfigFileParseFailedError(filePath, error instanceof Error ? error.message : String(error), error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function findConfigFile(searchDir) {
|
|
69
|
+
const configFiles = [
|
|
70
|
+
{ name: "qvac.config.ts", type: "ts" },
|
|
71
|
+
{ name: "qvac.config.js", type: "js" },
|
|
72
|
+
{ name: "qvac.config.json", type: "json" },
|
|
73
|
+
];
|
|
74
|
+
for (const { name, type } of configFiles) {
|
|
75
|
+
const filePath = path.resolve(searchDir, name);
|
|
76
|
+
if (await fileExists(filePath)) {
|
|
77
|
+
return { path: filePath, type };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolution order for Node.js:
|
|
84
|
+
* 1. QVAC_CONFIG_PATH environment variable
|
|
85
|
+
* 2. Config file in project root (qvac.config.ts, qvac.config.js, qvac.config.json)
|
|
86
|
+
* 3. SDK defaults
|
|
87
|
+
*/
|
|
88
|
+
export async function resolveConfig() {
|
|
89
|
+
const configPath = process.env["QVAC_CONFIG_PATH"];
|
|
90
|
+
if (configPath) {
|
|
91
|
+
const normalizedPath = path.resolve(configPath);
|
|
92
|
+
if (await fileExists(normalizedPath)) {
|
|
93
|
+
const ext = normalizedPath.endsWith(".json")
|
|
94
|
+
? "json"
|
|
95
|
+
: normalizedPath.endsWith(".ts")
|
|
96
|
+
? "ts"
|
|
97
|
+
: "js";
|
|
98
|
+
const config = ext === "json"
|
|
99
|
+
? await loadJsonConfig(normalizedPath)
|
|
100
|
+
: await loadJsConfig(normalizedPath);
|
|
101
|
+
logger.info(`✅ Loaded config from: ${normalizedPath}`);
|
|
102
|
+
return config;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const projectRoot = await findProjectRoot();
|
|
106
|
+
if (projectRoot) {
|
|
107
|
+
const configFile = await findConfigFile(projectRoot);
|
|
108
|
+
if (configFile) {
|
|
109
|
+
const config = configFile.type === "json"
|
|
110
|
+
? await loadJsonConfig(configFile.path)
|
|
111
|
+
: await loadJsConfig(configFile.path);
|
|
112
|
+
logger.info(`✅ Loaded config from: ${configFile.path}`);
|
|
113
|
+
return config;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
logger.info("ℹ️ No config file found, using SDK defaults");
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
import type { QvacConfig } from "../schemas/index";
|
|
2
|
+
type ResolveConfigFn = () => Promise<QvacConfig | undefined>;
|
|
3
|
+
interface RPCClient {
|
|
4
|
+
request(command: number): any;
|
|
5
|
+
}
|
|
1
6
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
7
|
+
* Loads configuration from file and sends it to the worker during initialization.
|
|
8
|
+
* Config is loaded once and becomes immutable on the worker side.
|
|
9
|
+
*
|
|
10
|
+
* @param rpc - The RPC client instance
|
|
11
|
+
* @param resolveConfig - Runtime-specific config resolver function
|
|
4
12
|
*/
|
|
5
|
-
export declare
|
|
13
|
+
export declare function initializeConfig(rpc: RPCClient, resolveConfig: ResolveConfigFn): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Legacy function for backward compatibility
|
|
16
|
+
* @deprecated Use initializeConfig instead
|
|
17
|
+
*/
|
|
18
|
+
export declare function replayConfigIfCached(): void;
|
|
19
|
+
export {};
|
|
6
20
|
//# sourceMappingURL=init-hooks.d.ts.map
|
|
@@ -1,37 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getClientLogger, setGlobalLogLevel, setGlobalConsoleOutput, } from "../logging/index.js";
|
|
2
|
+
const logger = getClientLogger();
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
4
|
+
* Loads configuration from file and sends it to the worker during initialization.
|
|
5
|
+
* Config is loaded once and becomes immutable on the worker side.
|
|
6
|
+
*
|
|
7
|
+
* @param rpc - The RPC client instance
|
|
8
|
+
* @param resolveConfig - Runtime-specific config resolver function
|
|
5
9
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const config = getCachedConfig();
|
|
10
|
+
export async function initializeConfig(rpc, resolveConfig) {
|
|
11
|
+
const config = await resolveConfig();
|
|
9
12
|
if (!config) {
|
|
10
|
-
|
|
13
|
+
// No config found - worker will use defaults
|
|
11
14
|
return;
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
// Apply logger settings on client
|
|
17
|
+
if (config.loggerLevel !== undefined) {
|
|
18
|
+
setGlobalLogLevel(config.loggerLevel);
|
|
19
|
+
}
|
|
20
|
+
if (config.loggerConsoleOutput !== undefined) {
|
|
21
|
+
setGlobalConsoleOutput(config.loggerConsoleOutput);
|
|
22
|
+
}
|
|
23
|
+
logger.info("📦 Initializing config:", config);
|
|
14
24
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
// Send config to worker via internal init message
|
|
26
|
+
// This bypasses the normal RPC flow since it's part of initialization
|
|
27
|
+
const initMessage = {
|
|
28
|
+
type: "__init_config",
|
|
17
29
|
config,
|
|
18
30
|
};
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
20
32
|
const req = rpc.request(1);
|
|
21
33
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
22
|
-
req.send(JSON.stringify(
|
|
34
|
+
req.send(JSON.stringify(initMessage), "utf8");
|
|
23
35
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
24
36
|
const response = await req.reply("utf8");
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
|
|
26
38
|
const parsed = JSON.parse(response.toString());
|
|
27
|
-
if (
|
|
28
|
-
|
|
39
|
+
if (!parsed.success) {
|
|
40
|
+
logger.error("❌ Failed to initialize config:", parsed.error);
|
|
29
41
|
}
|
|
30
42
|
else {
|
|
31
|
-
|
|
43
|
+
logger.info("✅ Config successfully initialized");
|
|
32
44
|
}
|
|
33
45
|
}
|
|
34
46
|
catch (error) {
|
|
35
|
-
|
|
47
|
+
logger.error("❌ Error initializing config:", error);
|
|
36
48
|
}
|
|
37
|
-
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Legacy function for backward compatibility
|
|
52
|
+
* @deprecated Use initializeConfig instead
|
|
53
|
+
*/
|
|
54
|
+
export function replayConfigIfCached() {
|
|
55
|
+
logger.warn("⚠️ replayConfigIfCached is deprecated and has no effect. Config is now loaded from file during initialization.");
|
|
56
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Logger } from "../logging/index";
|
|
2
|
-
export declare function startLoggingStreamForModel(modelId: string,
|
|
2
|
+
export declare function startLoggingStreamForModel(modelId: string, modelLogger: Logger): void;
|
|
3
3
|
export declare function stopLoggingStreamForModel(modelId: string): void;
|
|
4
4
|
export declare function hasActiveStreamForModel(modelId: string): boolean;
|
|
5
5
|
//# sourceMappingURL=logging-stream-registry.d.ts.map
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {} from "../logging/index.js";
|
|
1
|
+
import { getClientLogger } from "../logging/index.js";
|
|
2
2
|
import { loggingStream } from "./api/logging-stream.js";
|
|
3
|
+
const logger = getClientLogger();
|
|
3
4
|
const activeStreams = new Map();
|
|
4
|
-
export function startLoggingStreamForModel(modelId,
|
|
5
|
+
export function startLoggingStreamForModel(modelId, modelLogger) {
|
|
5
6
|
if (activeStreams.has(modelId)) {
|
|
6
|
-
|
|
7
|
+
logger.warn(`Logging stream already active for model ${modelId}`);
|
|
7
8
|
return;
|
|
8
9
|
}
|
|
9
|
-
const streamIterator = loggingStream({ modelId });
|
|
10
|
-
activeStreams.set(modelId, { logger, streamIterator });
|
|
10
|
+
const streamIterator = loggingStream({ id: modelId });
|
|
11
|
+
activeStreams.set(modelId, { logger: modelLogger, streamIterator });
|
|
11
12
|
try {
|
|
12
13
|
void (async () => {
|
|
13
14
|
try {
|
|
@@ -15,24 +16,24 @@ export function startLoggingStreamForModel(modelId, logger) {
|
|
|
15
16
|
const logLevel = logMessage.level;
|
|
16
17
|
switch (logLevel) {
|
|
17
18
|
case "error":
|
|
18
|
-
|
|
19
|
+
modelLogger.error(`[${logMessage.namespace}]`, logMessage.message);
|
|
19
20
|
break;
|
|
20
21
|
case "warn":
|
|
21
|
-
|
|
22
|
+
modelLogger.warn(`[${logMessage.namespace}]`, logMessage.message);
|
|
22
23
|
break;
|
|
23
24
|
case "info":
|
|
24
|
-
|
|
25
|
+
modelLogger.info(`[${logMessage.namespace}]`, logMessage.message);
|
|
25
26
|
break;
|
|
26
27
|
case "debug":
|
|
27
|
-
|
|
28
|
+
modelLogger.debug(`[${logMessage.namespace}]`, logMessage.message);
|
|
28
29
|
break;
|
|
29
30
|
default:
|
|
30
|
-
|
|
31
|
+
modelLogger.info(`[${logMessage.namespace}]`, logMessage.message);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
catch (error) {
|
|
35
|
-
|
|
36
|
+
logger.error(`Logging stream error for model ${modelId}:`, error);
|
|
36
37
|
}
|
|
37
38
|
finally {
|
|
38
39
|
activeStreams.delete(modelId);
|
|
@@ -40,7 +41,7 @@ export function startLoggingStreamForModel(modelId, logger) {
|
|
|
40
41
|
})();
|
|
41
42
|
}
|
|
42
43
|
catch (error) {
|
|
43
|
-
|
|
44
|
+
logger.error(`Failed to start logging stream for model ${modelId}:`, error);
|
|
44
45
|
activeStreams.delete(modelId);
|
|
45
46
|
throw error;
|
|
46
47
|
}
|
|
@@ -52,7 +53,7 @@ export function stopLoggingStreamForModel(modelId) {
|
|
|
52
53
|
// Terminate the stream iterator - this will close the RPC connection
|
|
53
54
|
// and the server-side async generator will automatically terminate
|
|
54
55
|
void stream.streamIterator.return(undefined);
|
|
55
|
-
|
|
56
|
+
logger.debug(`Stopped logging stream for model ${modelId}`);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
export function hasActiveStreamForModel(modelId) {
|
|
@@ -44,6 +44,11 @@ export declare function stream<T extends Request>(request: T): AsyncGenerator<{
|
|
|
44
44
|
type: "textToSpeech";
|
|
45
45
|
buffer: number[];
|
|
46
46
|
done: boolean;
|
|
47
|
+
} | {
|
|
48
|
+
type: "loadModel";
|
|
49
|
+
success: boolean;
|
|
50
|
+
modelId?: string | undefined;
|
|
51
|
+
error?: string | undefined;
|
|
47
52
|
} | {
|
|
48
53
|
type: "modelProgress";
|
|
49
54
|
downloaded: number;
|
|
@@ -58,11 +63,6 @@ export declare function stream<T extends Request>(request: T): AsyncGenerator<{
|
|
|
58
63
|
overallTotal: number;
|
|
59
64
|
overallPercentage: number;
|
|
60
65
|
} | undefined;
|
|
61
|
-
} | {
|
|
62
|
-
type: "loadModel";
|
|
63
|
-
success: boolean;
|
|
64
|
-
modelId?: string | undefined;
|
|
65
|
-
error?: string | undefined;
|
|
66
66
|
} | {
|
|
67
67
|
type: "downloadAsset";
|
|
68
68
|
success: boolean;
|
|
@@ -71,11 +71,11 @@ export declare function stream<T extends Request>(request: T): AsyncGenerator<{
|
|
|
71
71
|
} | {
|
|
72
72
|
type: "embed";
|
|
73
73
|
success: boolean;
|
|
74
|
-
embedding: number[];
|
|
74
|
+
embedding: number[] | number[][];
|
|
75
75
|
error?: string | undefined;
|
|
76
76
|
} | {
|
|
77
77
|
type: "loggingStream";
|
|
78
|
-
|
|
78
|
+
id: string;
|
|
79
79
|
level: "error" | "warn" | "info" | "debug" | "off";
|
|
80
80
|
namespace: string;
|
|
81
81
|
message: string;
|
|
@@ -146,10 +146,6 @@ export declare function stream<T extends Request>(request: T): AsyncGenerator<{
|
|
|
146
146
|
success: boolean;
|
|
147
147
|
operation: "deleteEmbeddings";
|
|
148
148
|
error?: string | undefined;
|
|
149
|
-
} | {
|
|
150
|
-
type: "setConfig";
|
|
151
|
-
success: boolean;
|
|
152
|
-
error?: string | undefined;
|
|
153
149
|
} | {
|
|
154
150
|
type: "getModelInfo";
|
|
155
151
|
modelInfo: {
|
|
@@ -159,7 +155,7 @@ export declare function stream<T extends Request>(request: T): AsyncGenerator<{
|
|
|
159
155
|
hyperbeeKey: string;
|
|
160
156
|
expectedSize: number;
|
|
161
157
|
sha256Checksum: string;
|
|
162
|
-
addon: "llm" | "whisper" | "embeddings" | "nmt" | "
|
|
158
|
+
addon: "llm" | "whisper" | "embeddings" | "nmt" | "tts" | "vad";
|
|
163
159
|
isCached: boolean;
|
|
164
160
|
isLoaded: boolean;
|
|
165
161
|
cacheFiles: {
|
|
@@ -180,11 +176,11 @@ export declare function stream<T extends Request>(request: T): AsyncGenerator<{
|
|
|
180
176
|
}[] | undefined;
|
|
181
177
|
};
|
|
182
178
|
}, void, any>;
|
|
183
|
-
export declare function getRPC(): {
|
|
179
|
+
export declare function getRPC(): Promise<{
|
|
184
180
|
request(): {
|
|
185
181
|
send(payload: string): void;
|
|
186
182
|
reply(): Promise<Buffer<ArrayBuffer>>;
|
|
187
183
|
createResponseStream(): AsyncGenerator<Buffer<ArrayBuffer>, void, unknown>;
|
|
188
184
|
};
|
|
189
|
-
}
|
|
185
|
+
}>;
|
|
190
186
|
//# sourceMappingURL=bare-client.d.ts.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { handlers } from "../../server/rpc/handlers/index.js";
|
|
2
2
|
import { RPCNoHandlerError, RPCRequestNotSentError, } from "../../utils/errors-client.js";
|
|
3
|
+
import { initializeConfig } from "../init-hooks.js";
|
|
4
|
+
import { setSDKConfig } from "../../server/bare/registry/config-registry.js";
|
|
5
|
+
import { resolveConfig } from "../config-loader/resolve-config.bare.js";
|
|
3
6
|
// Get the handler for a request type
|
|
4
7
|
const getHandler = (type) => {
|
|
5
8
|
const handler = handlers[type];
|
|
@@ -97,6 +100,22 @@ const createMockRPCRequest = () => {
|
|
|
97
100
|
if (!requestData) {
|
|
98
101
|
throw new RPCRequestNotSentError();
|
|
99
102
|
}
|
|
103
|
+
// Handle special internal config initialization message
|
|
104
|
+
if (typeof requestData === "object" &&
|
|
105
|
+
"type" in requestData &&
|
|
106
|
+
requestData.type === "__init_config") {
|
|
107
|
+
try {
|
|
108
|
+
const configData = requestData;
|
|
109
|
+
setSDKConfig(configData.config);
|
|
110
|
+
return Buffer.from(JSON.stringify({ success: true }));
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
return Buffer.from(JSON.stringify({
|
|
114
|
+
success: false,
|
|
115
|
+
error: error instanceof Error ? error.message : String(error),
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
100
119
|
const response = await send(requestData);
|
|
101
120
|
return Buffer.from(JSON.stringify(response));
|
|
102
121
|
},
|
|
@@ -110,10 +129,17 @@ const createMockRPCRequest = () => {
|
|
|
110
129
|
},
|
|
111
130
|
};
|
|
112
131
|
};
|
|
113
|
-
|
|
114
|
-
|
|
132
|
+
let configInitialized = false;
|
|
133
|
+
export async function getRPC() {
|
|
134
|
+
const mockRPC = {
|
|
115
135
|
request() {
|
|
116
136
|
return createMockRPCRequest();
|
|
117
137
|
},
|
|
118
138
|
};
|
|
139
|
+
// Initialize config once on first call
|
|
140
|
+
if (!configInitialized) {
|
|
141
|
+
await initializeConfig(mockRPC, resolveConfig);
|
|
142
|
+
configInitialized = true;
|
|
143
|
+
}
|
|
144
|
+
return mockRPC;
|
|
119
145
|
}
|