@qvac/sdk 0.3.0 โ 0.4.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 +22 -0
- package/dist/client/api/cancel.d.ts +1 -1
- package/dist/client/api/cancel.js +4 -3
- package/dist/client/api/completion-stream.d.ts +24 -32
- package/dist/client/api/completion-stream.js +142 -50
- package/dist/client/api/delete-cache.js +3 -2
- package/dist/client/api/download-asset.d.ts +3 -3
- package/dist/client/api/download-asset.js +12 -17
- package/dist/client/api/embed.d.ts +1 -1
- package/dist/client/api/embed.js +4 -3
- package/dist/client/api/get-model-info.d.ts +29 -0
- package/dist/client/api/get-model-info.js +14 -0
- package/dist/client/api/index.d.ts +3 -0
- package/dist/client/api/index.js +3 -0
- package/dist/client/api/load-model.d.ts +3 -3
- package/dist/client/api/load-model.js +13 -22
- package/dist/client/api/logging-stream.d.ts +1 -1
- package/dist/client/api/logging-stream.js +3 -2
- package/dist/client/api/ping.d.ts +1 -1
- package/dist/client/api/ping.js +3 -2
- package/dist/client/api/provide.d.ts +1 -1
- package/dist/client/api/provide.js +4 -3
- package/dist/client/api/rag.d.ts +3 -3
- package/dist/client/api/rag.js +13 -12
- package/dist/client/api/set-config.d.ts +7 -0
- package/dist/client/api/set-config.js +20 -0
- package/dist/client/api/stop-provider.d.ts +1 -1
- package/dist/client/api/stop-provider.js +4 -3
- package/dist/client/api/text-to-speech.d.ts +7 -0
- package/dist/client/api/text-to-speech.js +58 -0
- package/dist/client/api/transcribe.d.ts +4 -2
- package/dist/client/api/transcribe.js +9 -5
- package/dist/client/api/translate.d.ts +1 -1
- package/dist/client/api/translate.js +3 -2
- package/dist/client/api/unload-model.d.ts +5 -1
- package/dist/client/api/unload-model.js +14 -4
- package/dist/client/config-manager.d.ts +4 -0
- package/dist/client/config-manager.js +8 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/init-hooks.d.ts +6 -0
- package/dist/client/init-hooks.js +37 -0
- package/dist/client/rpc/bare-client.d.ts +69 -0
- package/dist/client/rpc/bare-client.js +5 -4
- package/dist/client/rpc/bare-rpc-client.js +7 -3
- package/dist/client/rpc/expo-rpc-client.d.ts +1 -0
- package/dist/client/rpc/expo-rpc-client.js +9 -1
- package/dist/client/rpc/node-rpc-client.d.ts +1 -1
- package/dist/client/rpc/node-rpc-client.js +22 -9
- package/dist/client/rpc/rpc-client.d.ts +1 -0
- package/dist/client/rpc/rpc-client.js +20 -1
- package/dist/examples/cache-management.d.ts +2 -0
- package/dist/examples/cache-management.js +97 -0
- package/dist/examples/delegated-inference/consumer.js +2 -2
- package/dist/examples/download-with-blind-relays.d.ts +2 -0
- package/dist/examples/download-with-blind-relays.js +48 -0
- package/dist/examples/download-with-cancel.js +3 -4
- package/dist/examples/embed-hyperdrive.js +0 -1
- package/dist/examples/kv-cache-cleanup.js +0 -1
- package/dist/examples/kv-cache-custom-key.js +0 -1
- package/dist/examples/kv-cache-example.js +0 -1
- package/dist/examples/llamacpp-file-logging.js +0 -1
- package/dist/examples/llamacpp-filesystem.js +2 -2
- package/dist/examples/llamacpp-http.js +0 -1
- package/dist/examples/llamacpp-hyperdrive.js +0 -1
- package/dist/examples/llamacpp-multimodal.js +0 -1
- package/dist/examples/llamacpp-native-tools.js +118 -36
- package/dist/examples/llamacpp-sharded.d.ts +2 -0
- package/dist/examples/llamacpp-sharded.js +44 -0
- package/dist/examples/multi-model-demo.js +0 -1
- package/dist/examples/parallel-download.js +2 -2
- package/dist/examples/rag/rag-chromadb.js +0 -1
- package/dist/examples/rag/rag-hyperdb-workspaces.js +0 -1
- package/dist/examples/rag/rag-hyperdb.js +0 -1
- package/dist/examples/rag/rag-lancedb.js +0 -1
- package/dist/examples/rag/rag-sqlite.js +0 -1
- package/dist/examples/text-to-speech.d.ts +3 -0
- package/dist/examples/text-to-speech.js +137 -0
- package/dist/examples/translation/translation-indic.js +3 -1
- package/dist/examples/translation/translation-llm-context.js +0 -1
- package/dist/examples/translation/translation-llm.js +2 -2
- package/dist/examples/translation/translation-opus.js +3 -1
- package/dist/examples/translation/translation-stream.js +0 -1
- package/dist/examples/whispercpp-filesystem.js +32 -5
- package/dist/examples/whispercpp-microphone-record.js +9 -9
- package/dist/examples/whispercpp-prompt.d.ts +2 -0
- package/dist/examples/whispercpp-prompt.js +68 -0
- package/dist/expo/plugins/withMobileBundle.js +9 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/models/hyperdrive/models.d.ts +1916 -100
- package/dist/models/hyperdrive/models.js +2042 -102
- package/dist/schemas/common.d.ts +413 -58
- package/dist/schemas/common.js +9 -0
- package/dist/schemas/completion-stream.d.ts +26 -22
- package/dist/schemas/completion-stream.js +9 -23
- package/dist/schemas/download-asset.d.ts +77 -2
- package/dist/schemas/download-asset.js +15 -4
- package/dist/schemas/get-model-info.d.ts +100 -0
- package/dist/schemas/get-model-info.js +40 -0
- package/dist/schemas/index.d.ts +7 -0
- package/dist/schemas/index.js +7 -0
- package/dist/schemas/llamacpp-config.d.ts +2 -1
- package/dist/schemas/llamacpp-config.js +3 -4
- package/dist/schemas/load-model.d.ts +2316 -266
- package/dist/schemas/load-model.js +157 -10
- package/dist/schemas/model-src-utils.d.ts +98 -0
- package/dist/schemas/model-src-utils.js +31 -0
- package/dist/schemas/sdk-errors-client.d.ts +25 -0
- package/dist/schemas/sdk-errors-client.js +111 -0
- package/dist/schemas/sdk-errors-server.d.ts +55 -0
- package/dist/schemas/sdk-errors-server.js +271 -0
- package/dist/schemas/set-config.d.ts +21 -0
- package/dist/schemas/set-config.js +14 -0
- package/dist/schemas/text-to-speech.d.ts +34 -0
- package/dist/schemas/text-to-speech.js +25 -0
- package/dist/schemas/tools.d.ts +62 -0
- package/dist/schemas/tools.js +43 -0
- package/dist/schemas/transcription.d.ts +25 -2
- package/dist/schemas/transcription.js +12 -1
- package/dist/schemas/translation-config.d.ts +33 -5
- package/dist/schemas/translation-config.js +18 -1
- package/dist/schemas/unload-model.d.ts +2 -0
- package/dist/schemas/unload-model.js +2 -0
- package/dist/schemas/whispercpp-config.d.ts +55 -18
- package/dist/schemas/whispercpp-config.js +63 -15
- package/dist/server/bare/addons/cancel.js +2 -1
- package/dist/server/bare/addons/llamacpp/create-model.d.ts +9 -2
- package/dist/server/bare/addons/llamacpp/create-model.js +23 -23
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.d.ts +10 -2
- package/dist/server/bare/addons/llamacpp/handlers/completion-stream.js +62 -43
- package/dist/server/bare/addons/llamacpp/handlers/embed.js +3 -2
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.d.ts +1 -1
- package/dist/server/bare/addons/llamacpp/kv-cache-utils.js +6 -2
- package/dist/server/bare/addons/load-model.js +59 -28
- package/dist/server/bare/addons/translation/create-model.d.ts +5 -1
- package/dist/server/bare/addons/translation/create-model.js +17 -25
- package/dist/server/bare/addons/translation/handlers/translate.js +10 -1
- package/dist/server/bare/addons/tts/create-model.d.ts +10 -0
- package/dist/server/bare/addons/tts/create-model.js +25 -0
- package/dist/server/bare/addons/tts/handlers/text-to-speech.d.ts +3 -0
- package/dist/server/bare/addons/tts/handlers/text-to-speech.js +87 -0
- package/dist/server/bare/addons/tts/index.d.ts +3 -0
- package/dist/server/bare/addons/tts/index.js +2 -0
- package/dist/server/bare/addons/unload-model.js +21 -3
- package/dist/server/bare/addons/whispercpp/create-model.d.ts +5 -1
- package/dist/server/bare/addons/whispercpp/create-model.js +13 -32
- package/dist/server/bare/addons/whispercpp/handlers/transcribe-stream.js +41 -20
- package/dist/server/bare/delegate-rpc-client.js +3 -2
- package/dist/server/bare/hyperswarm.d.ts +3 -0
- package/dist/server/bare/hyperswarm.js +22 -1
- package/dist/server/bare/rag-hyperdb/rag-manager.js +2 -3
- package/dist/server/bare/registry/config-registry.d.ts +5 -0
- package/dist/server/bare/registry/config-registry.js +39 -0
- package/dist/server/bare/registry/model-registry.d.ts +13 -0
- package/dist/server/bare/registry/model-registry.js +24 -7
- package/dist/server/rpc/handle-request.js +42 -3
- package/dist/server/rpc/handlers/completion-stream-delegated.js +2 -1
- package/dist/server/rpc/handlers/completion-stream.js +11 -4
- package/dist/server/rpc/handlers/download-asset.js +2 -3
- package/dist/server/rpc/handlers/get-model-info.d.ts +3 -0
- package/dist/server/rpc/handlers/get-model-info.js +148 -0
- package/dist/server/rpc/handlers/index.d.ts +4 -0
- package/dist/server/rpc/handlers/index.js +6 -0
- package/dist/server/rpc/handlers/load-model/http.js +51 -10
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +336 -156
- package/dist/server/rpc/handlers/load-model/index.js +1 -1
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +1 -1
- package/dist/server/rpc/handlers/load-model/resolve.js +10 -6
- package/dist/server/rpc/handlers/load-model-delegated.js +7 -4
- package/dist/server/rpc/handlers/load-model.js +19 -1
- package/dist/server/rpc/handlers/provideHandler/handler.js +2 -1
- package/dist/server/rpc/handlers/rag.js +0 -3
- package/dist/server/rpc/handlers/set-config.d.ts +3 -0
- package/dist/server/rpc/handlers/set-config.js +18 -0
- package/dist/server/rpc/handlers/stopProvideHandler.js +3 -1
- package/dist/server/rpc/handlers/text-to-speech.d.ts +3 -0
- package/dist/server/rpc/handlers/text-to-speech.js +7 -0
- package/dist/server/rpc/handlers/transcribe-stream.js +6 -2
- package/dist/server/rpc/handlers/unload-model.js +7 -0
- package/dist/server/utils/cache.d.ts +13 -8
- package/dist/server/utils/cache.js +69 -14
- package/dist/server/utils/checksum.d.ts +2 -0
- package/dist/server/utils/checksum.js +24 -0
- package/dist/server/utils/index.d.ts +2 -0
- package/dist/server/utils/index.js +2 -0
- package/dist/server/utils/shard-utils.d.ts +22 -0
- package/dist/server/utils/shard-utils.js +37 -0
- package/dist/server/utils/tool-integration.d.ts +13 -0
- package/dist/server/utils/tool-integration.js +43 -0
- package/dist/server/utils/tool-parser.d.ts +7 -0
- package/dist/server/utils/tool-parser.js +244 -0
- package/dist/utils/errors-base.d.ts +3 -0
- package/dist/utils/errors-base.js +13 -0
- package/dist/utils/errors-client.d.ts +107 -0
- package/dist/utils/errors-client.js +186 -0
- package/dist/utils/errors-server.d.ts +146 -0
- package/dist/utils/errors-server.js +253 -0
- package/dist/utils/tool-helpers.d.ts +17 -0
- package/dist/utils/tool-helpers.js +99 -0
- package/package.json +12 -8
- package/dist/examples/llamacpp-tools-routing.d.ts +0 -2
- package/dist/examples/llamacpp-tools-routing.js +0 -364
- package/dist/examples/llamacpp-tools.d.ts +0 -2
- package/dist/examples/llamacpp-tools.js +0 -81
- package/dist/server/http-server.d.ts +0 -2
- package/dist/server/http-server.js +0 -189
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { send, stream } from "../rpc/rpc-client.js";
|
|
2
2
|
import {} from "../../logging/index.js";
|
|
3
3
|
import { startLoggingStreamForModel } from "../logging-stream-registry.js";
|
|
4
|
-
import {
|
|
4
|
+
import { loadModelOptionsToRequestSchema, } from "../../schemas/index.js";
|
|
5
|
+
import { ModelLoadFailedError, StreamEndedError, InvalidResponseError, } from "../../utils/errors-client.js";
|
|
5
6
|
/**
|
|
6
7
|
* Loads a machine learning model from a local path, remote URL, or Hyperdrive key.
|
|
7
8
|
*
|
|
@@ -20,9 +21,9 @@ import { loadModelRequestSchema, } from "../../schemas/index.js";
|
|
|
20
21
|
*
|
|
21
22
|
* @returns Promise that resolves to the model ID (either the provided modelSrc or a generated ID)
|
|
22
23
|
*
|
|
23
|
-
* @throws {
|
|
24
|
-
* @throws {
|
|
25
|
-
* @throws {
|
|
24
|
+
* @throws {QvacErrorBase} When model loading fails, with details in the error message
|
|
25
|
+
* @throws {QvacErrorBase} When streaming ends unexpectedly (only when using onProgress)
|
|
26
|
+
* @throws {QvacErrorBase} When receiving an invalid response type from the server
|
|
26
27
|
*
|
|
27
28
|
* @example
|
|
28
29
|
* ```typescript
|
|
@@ -94,18 +95,8 @@ import { loadModelRequestSchema, } from "../../schemas/index.js";
|
|
|
94
95
|
* ```
|
|
95
96
|
*/
|
|
96
97
|
export async function loadModel(options) {
|
|
97
|
-
const { logger
|
|
98
|
-
const request =
|
|
99
|
-
type: "loadModel",
|
|
100
|
-
modelSrc: modelSrc,
|
|
101
|
-
projectionModelSrc: options.modelType === "llm" ? options.projectionModelSrc : undefined,
|
|
102
|
-
vadModelSrc: options.modelType === "whisper" ? options.vadModelSrc : undefined,
|
|
103
|
-
withProgress: !!options.onProgress,
|
|
104
|
-
seed: options.seed,
|
|
105
|
-
modelType: options.modelType,
|
|
106
|
-
modelConfig: options.modelConfig ?? {},
|
|
107
|
-
delegate: options.delegate,
|
|
108
|
-
});
|
|
98
|
+
const { logger } = options;
|
|
99
|
+
const request = loadModelOptionsToRequestSchema.parse(options);
|
|
109
100
|
if (options.onProgress) {
|
|
110
101
|
// Use streaming for progress updates
|
|
111
102
|
for await (const response of stream(request)) {
|
|
@@ -114,9 +105,9 @@ export async function loadModel(options) {
|
|
|
114
105
|
}
|
|
115
106
|
else if (response.type === "loadModel") {
|
|
116
107
|
if (!response.success) {
|
|
117
|
-
throw new
|
|
108
|
+
throw new ModelLoadFailedError(response.error);
|
|
118
109
|
}
|
|
119
|
-
const modelId = response.modelId
|
|
110
|
+
const modelId = response.modelId;
|
|
120
111
|
// Start logging stream in the background if logger is provided, catch to avoid failing the entire loadModel operation
|
|
121
112
|
if (logger) {
|
|
122
113
|
try {
|
|
@@ -129,18 +120,18 @@ export async function loadModel(options) {
|
|
|
129
120
|
return modelId;
|
|
130
121
|
}
|
|
131
122
|
}
|
|
132
|
-
throw new
|
|
123
|
+
throw new StreamEndedError();
|
|
133
124
|
}
|
|
134
125
|
else {
|
|
135
126
|
// Use regular send for simple loading
|
|
136
127
|
const response = await send(request);
|
|
137
128
|
if (response.type !== "loadModel") {
|
|
138
|
-
throw new
|
|
129
|
+
throw new InvalidResponseError("loadModel");
|
|
139
130
|
}
|
|
140
131
|
if (!response.success) {
|
|
141
|
-
throw new
|
|
132
|
+
throw new ModelLoadFailedError(response.error);
|
|
142
133
|
}
|
|
143
|
-
const modelId = response.modelId
|
|
134
|
+
const modelId = response.modelId;
|
|
144
135
|
if (logger) {
|
|
145
136
|
try {
|
|
146
137
|
startLoggingStreamForModel(modelId, logger);
|
|
@@ -5,7 +5,7 @@ import type { LoggingStreamResponse, LoggingParams } from "../../schemas/logging
|
|
|
5
5
|
* @param params - The arguments for the logging stream
|
|
6
6
|
* @param params.modelId - The unique identifier of the model to stream logs for
|
|
7
7
|
* @returns AsyncGenerator yielding logging stream responses
|
|
8
|
-
* @throws {
|
|
8
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the stream fails
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { stream } from "../rpc/rpc-client.js";
|
|
2
|
+
import { InvalidResponseError } from "../../utils/errors-client.js";
|
|
2
3
|
/**
|
|
3
4
|
* Opens a logging stream for a specific model to receive real-time logs.
|
|
4
5
|
*
|
|
5
6
|
* @param params - The arguments for the logging stream
|
|
6
7
|
* @param params.modelId - The unique identifier of the model to stream logs for
|
|
7
8
|
* @returns AsyncGenerator yielding logging stream responses
|
|
8
|
-
* @throws {
|
|
9
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the stream fails
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```typescript
|
|
@@ -25,7 +26,7 @@ export async function* loggingStream(params) {
|
|
|
25
26
|
const responseStream = stream(request);
|
|
26
27
|
for await (const response of responseStream) {
|
|
27
28
|
if (response.type !== "loggingStream") {
|
|
28
|
-
throw new
|
|
29
|
+
throw new InvalidResponseError("loggingStream");
|
|
29
30
|
}
|
|
30
31
|
yield response;
|
|
31
32
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Sends a ping request to the server and returns the pong response.
|
|
3
3
|
*
|
|
4
4
|
* @returns A promise that resolves to a pong response containing a number.
|
|
5
|
-
* @throws {
|
|
5
|
+
* @throws {QvacErrorBase} When the response type is not "pong".
|
|
6
6
|
*/
|
|
7
7
|
export declare function ping(): Promise<{
|
|
8
8
|
type: "pong";
|
package/dist/client/api/ping.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {} from "../../schemas/index.js";
|
|
2
2
|
import { send } from "../rpc/rpc-client.js";
|
|
3
|
+
import { InvalidResponseError } from "../../utils/errors-client.js";
|
|
3
4
|
/**
|
|
4
5
|
* Sends a ping request to the server and returns the pong response.
|
|
5
6
|
*
|
|
6
7
|
* @returns A promise that resolves to a pong response containing a number.
|
|
7
|
-
* @throws {
|
|
8
|
+
* @throws {QvacErrorBase} When the response type is not "pong".
|
|
8
9
|
*/
|
|
9
10
|
export async function ping() {
|
|
10
11
|
const request = {
|
|
@@ -12,7 +13,7 @@ export async function ping() {
|
|
|
12
13
|
};
|
|
13
14
|
const response = await send(request);
|
|
14
15
|
if (response.type !== "pong") {
|
|
15
|
-
throw new
|
|
16
|
+
throw new InvalidResponseError("pong");
|
|
16
17
|
}
|
|
17
18
|
return response;
|
|
18
19
|
}
|
|
@@ -7,7 +7,7 @@ import { type ProvideParams } from "../../schemas/index";
|
|
|
7
7
|
* @param options.topic - Topic hex string for peer discovery
|
|
8
8
|
* @param options.firewall - Optional firewall configuration to allow/deny specific public keys
|
|
9
9
|
* @returns A promise that resolves to the provide response containing success status and public key
|
|
10
|
-
* @throws {
|
|
10
|
+
* @throws {QvacErrorBase} When the response type is not "provide" or the request fails
|
|
11
11
|
*/
|
|
12
12
|
export declare function startQVACProvider(params: ProvideParams): Promise<{
|
|
13
13
|
type: "provide";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {} from "../../schemas/index.js";
|
|
2
2
|
import { send } from "../rpc/rpc-client.js";
|
|
3
|
+
import { InvalidResponseError, ProviderStartFailedError, } from "../../utils/errors-client.js";
|
|
3
4
|
/**
|
|
4
5
|
* Starts a provider service that offers QVAC capabilities to remote peers.
|
|
5
6
|
* The provider's keypair can be controlled via the seed option or QVAC_HYPERSWARM_SEED environment variable.
|
|
@@ -8,7 +9,7 @@ import { send } from "../rpc/rpc-client.js";
|
|
|
8
9
|
* @param options.topic - Topic hex string for peer discovery
|
|
9
10
|
* @param options.firewall - Optional firewall configuration to allow/deny specific public keys
|
|
10
11
|
* @returns A promise that resolves to the provide response containing success status and public key
|
|
11
|
-
* @throws {
|
|
12
|
+
* @throws {QvacErrorBase} When the response type is not "provide" or the request fails
|
|
12
13
|
*/
|
|
13
14
|
export async function startQVACProvider(params) {
|
|
14
15
|
const request = {
|
|
@@ -18,10 +19,10 @@ export async function startQVACProvider(params) {
|
|
|
18
19
|
};
|
|
19
20
|
const response = await send(request);
|
|
20
21
|
if (response.type !== "provide") {
|
|
21
|
-
throw new
|
|
22
|
+
throw new InvalidResponseError("provide");
|
|
22
23
|
}
|
|
23
24
|
if (response.error) {
|
|
24
|
-
throw new
|
|
25
|
+
throw new ProviderStartFailedError(response.error);
|
|
25
26
|
}
|
|
26
27
|
return response;
|
|
27
28
|
}
|
package/dist/client/api/rag.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { RagSearchResult, RagSaveEmbeddingsParams, RagSearchParams, RagDele
|
|
|
8
8
|
* @param params.chunk - Whether to chunk the documents before embedding (default: false)
|
|
9
9
|
* @param params.chunkOpts - Options for chunking documents
|
|
10
10
|
* @param params.workspace - Optional workspace for isolated storage
|
|
11
|
-
* @throws {
|
|
11
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the operation fails
|
|
12
12
|
* @returns The processed results and dropped indices
|
|
13
13
|
*/
|
|
14
14
|
export declare function ragSaveEmbeddings(params: RagSaveEmbeddingsParams): Promise<{
|
|
@@ -24,7 +24,7 @@ export declare function ragSaveEmbeddings(params: RagSaveEmbeddingsParams): Prom
|
|
|
24
24
|
* @param params.topK - Number of top results to retrieve (default: 5)
|
|
25
25
|
* @param params.n - Number of centroids to use for IVF index search (default: 3)
|
|
26
26
|
* @param params.workspace - Optional workspace for isolated storage
|
|
27
|
-
* @throws {
|
|
27
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the operation fails
|
|
28
28
|
* @returns Array of search results with id, content, and score
|
|
29
29
|
*/
|
|
30
30
|
export declare function ragSearch(params: RagSearchParams): Promise<RagSearchResult[]>;
|
|
@@ -35,7 +35,7 @@ export declare function ragSearch(params: RagSearchParams): Promise<RagSearchRes
|
|
|
35
35
|
* @param params.modelId - The identifier of the embedding model (must match workspace model)
|
|
36
36
|
* @param params.ids - Array of document IDs to delete
|
|
37
37
|
* @param params.workspace - Optional workspace for isolated storage
|
|
38
|
-
* @throws {
|
|
38
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the operation fails
|
|
39
39
|
* @returns boolean indicating success
|
|
40
40
|
*/
|
|
41
41
|
export declare function ragDeleteEmbeddings(params: RagDeleteEmbeddingsParams): Promise<true>;
|
package/dist/client/api/rag.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { send } from "../rpc/rpc-client.js";
|
|
2
|
+
import { InvalidResponseError, InvalidOperationError, RAGSaveFailedError, RAGSearchFailedError, RAGDeleteFailedError, } from "../../utils/errors-client.js";
|
|
2
3
|
// ============== Save Embeddings ==============
|
|
3
4
|
/**
|
|
4
5
|
* Saves document embeddings in the RAG vector database.
|
|
@@ -9,7 +10,7 @@ import { send } from "../rpc/rpc-client.js";
|
|
|
9
10
|
* @param params.chunk - Whether to chunk the documents before embedding (default: false)
|
|
10
11
|
* @param params.chunkOpts - Options for chunking documents
|
|
11
12
|
* @param params.workspace - Optional workspace for isolated storage
|
|
12
|
-
* @throws {
|
|
13
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the operation fails
|
|
13
14
|
* @returns The processed results and dropped indices
|
|
14
15
|
*/
|
|
15
16
|
export async function ragSaveEmbeddings(params) {
|
|
@@ -20,13 +21,13 @@ export async function ragSaveEmbeddings(params) {
|
|
|
20
21
|
};
|
|
21
22
|
const response = await send(request);
|
|
22
23
|
if (response.type !== "rag") {
|
|
23
|
-
throw new
|
|
24
|
+
throw new InvalidResponseError("rag");
|
|
24
25
|
}
|
|
25
26
|
if (!response.success) {
|
|
26
|
-
throw new
|
|
27
|
+
throw new RAGSaveFailedError(response.error);
|
|
27
28
|
}
|
|
28
29
|
if (response.operation !== "saveEmbeddings") {
|
|
29
|
-
throw new
|
|
30
|
+
throw new InvalidOperationError();
|
|
30
31
|
}
|
|
31
32
|
return {
|
|
32
33
|
processed: response.processed,
|
|
@@ -43,7 +44,7 @@ export async function ragSaveEmbeddings(params) {
|
|
|
43
44
|
* @param params.topK - Number of top results to retrieve (default: 5)
|
|
44
45
|
* @param params.n - Number of centroids to use for IVF index search (default: 3)
|
|
45
46
|
* @param params.workspace - Optional workspace for isolated storage
|
|
46
|
-
* @throws {
|
|
47
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the operation fails
|
|
47
48
|
* @returns Array of search results with id, content, and score
|
|
48
49
|
*/
|
|
49
50
|
export async function ragSearch(params) {
|
|
@@ -56,13 +57,13 @@ export async function ragSearch(params) {
|
|
|
56
57
|
};
|
|
57
58
|
const response = await send(request);
|
|
58
59
|
if (response.type !== "rag") {
|
|
59
|
-
throw new
|
|
60
|
+
throw new InvalidResponseError("rag");
|
|
60
61
|
}
|
|
61
62
|
if (!response.success) {
|
|
62
|
-
throw new
|
|
63
|
+
throw new RAGSearchFailedError(response.error);
|
|
63
64
|
}
|
|
64
65
|
if (response.operation !== "search") {
|
|
65
|
-
throw new
|
|
66
|
+
throw new InvalidOperationError();
|
|
66
67
|
}
|
|
67
68
|
return response.results;
|
|
68
69
|
}
|
|
@@ -74,7 +75,7 @@ export async function ragSearch(params) {
|
|
|
74
75
|
* @param params.modelId - The identifier of the embedding model (must match workspace model)
|
|
75
76
|
* @param params.ids - Array of document IDs to delete
|
|
76
77
|
* @param params.workspace - Optional workspace for isolated storage
|
|
77
|
-
* @throws {
|
|
78
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the operation fails
|
|
78
79
|
* @returns boolean indicating success
|
|
79
80
|
*/
|
|
80
81
|
export async function ragDeleteEmbeddings(params) {
|
|
@@ -85,13 +86,13 @@ export async function ragDeleteEmbeddings(params) {
|
|
|
85
86
|
};
|
|
86
87
|
const response = await send(request);
|
|
87
88
|
if (response.type !== "rag") {
|
|
88
|
-
throw new
|
|
89
|
+
throw new InvalidResponseError("rag");
|
|
89
90
|
}
|
|
90
91
|
if (!response.success) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new RAGDeleteFailedError(response.error);
|
|
92
93
|
}
|
|
93
94
|
if (response.operation !== "deleteEmbeddings") {
|
|
94
|
-
throw new
|
|
95
|
+
throw new InvalidOperationError();
|
|
95
96
|
}
|
|
96
97
|
return response.success;
|
|
97
98
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {} from "../../schemas/index.js";
|
|
2
|
+
import { send } from "../rpc/rpc-client.js";
|
|
3
|
+
import { setCachedConfig } from "../config-manager.js";
|
|
4
|
+
import { InvalidResponseError, SetConfigFailedError, } from "../../utils/errors-client.js";
|
|
5
|
+
export const setConfig = async (config) => {
|
|
6
|
+
// Cache config client-side for automatic replay on worker restart
|
|
7
|
+
setCachedConfig(config);
|
|
8
|
+
const request = {
|
|
9
|
+
type: "setConfig",
|
|
10
|
+
config,
|
|
11
|
+
};
|
|
12
|
+
const response = await send(request);
|
|
13
|
+
if (response.type !== "setConfig") {
|
|
14
|
+
throw new InvalidResponseError("setConfig");
|
|
15
|
+
}
|
|
16
|
+
if (!response.success) {
|
|
17
|
+
throw new SetConfigFailedError(response.error);
|
|
18
|
+
}
|
|
19
|
+
return response;
|
|
20
|
+
};
|
|
@@ -5,7 +5,7 @@ import { type StopProvideParams } from "../../schemas/index";
|
|
|
5
5
|
* @param options - Options object with required topic
|
|
6
6
|
* @param options.topic - Topic hex string to leave
|
|
7
7
|
* @returns A promise that resolves to the stop provide response containing success status
|
|
8
|
-
* @throws {
|
|
8
|
+
* @throws {QvacErrorBase} When the response type is not "stopProvide" or the request fails
|
|
9
9
|
*/
|
|
10
10
|
export declare function stopQVACProvider(params: StopProvideParams): Promise<{
|
|
11
11
|
type: "stopProvide";
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {} from "../../schemas/index.js";
|
|
2
2
|
import { send } from "../rpc/rpc-client.js";
|
|
3
|
+
import { InvalidResponseError, ProviderStopFailedError, } from "../../utils/errors-client.js";
|
|
3
4
|
/**
|
|
4
5
|
* Stops a running provider service and leaves the specified topic.
|
|
5
6
|
*
|
|
6
7
|
* @param options - Options object with required topic
|
|
7
8
|
* @param options.topic - Topic hex string to leave
|
|
8
9
|
* @returns A promise that resolves to the stop provide response containing success status
|
|
9
|
-
* @throws {
|
|
10
|
+
* @throws {QvacErrorBase} When the response type is not "stopProvide" or the request fails
|
|
10
11
|
*/
|
|
11
12
|
export async function stopQVACProvider(params) {
|
|
12
13
|
const request = {
|
|
@@ -15,10 +16,10 @@ export async function stopQVACProvider(params) {
|
|
|
15
16
|
};
|
|
16
17
|
const response = await send(request);
|
|
17
18
|
if (response.type !== "stopProvide") {
|
|
18
|
-
throw new
|
|
19
|
+
throw new InvalidResponseError("stopProvide");
|
|
19
20
|
}
|
|
20
21
|
if (response.error) {
|
|
21
|
-
throw new
|
|
22
|
+
throw new ProviderStopFailedError(response.error);
|
|
22
23
|
}
|
|
23
24
|
return response;
|
|
24
25
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TtsClientParams } from "../../schemas/index";
|
|
2
|
+
export declare function textToSpeech(params: TtsClientParams): {
|
|
3
|
+
bufferStream: AsyncGenerator<number>;
|
|
4
|
+
buffer: Promise<number[]>;
|
|
5
|
+
done: Promise<boolean>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=text-to-speech.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ttsResponseSchema, } from "../../schemas/index.js";
|
|
2
|
+
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
3
|
+
export function textToSpeech(params) {
|
|
4
|
+
const request = {
|
|
5
|
+
type: "textToSpeech",
|
|
6
|
+
modelId: params.modelId,
|
|
7
|
+
inputType: params.inputType,
|
|
8
|
+
text: params.text,
|
|
9
|
+
stream: params.stream,
|
|
10
|
+
};
|
|
11
|
+
let doneResolver = () => { };
|
|
12
|
+
const donePromise = new Promise((resolve) => {
|
|
13
|
+
doneResolver = resolve;
|
|
14
|
+
});
|
|
15
|
+
if (params.stream) {
|
|
16
|
+
const bufferStream = (async function* () {
|
|
17
|
+
for await (const response of streamRpc(request)) {
|
|
18
|
+
if (response.type === "textToSpeech") {
|
|
19
|
+
const streamResponse = ttsResponseSchema.parse(response);
|
|
20
|
+
if (streamResponse.buffer.length > 0) {
|
|
21
|
+
yield* streamResponse.buffer;
|
|
22
|
+
}
|
|
23
|
+
if (streamResponse.done) {
|
|
24
|
+
doneResolver(true);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})();
|
|
29
|
+
return {
|
|
30
|
+
bufferStream,
|
|
31
|
+
buffer: Promise.resolve([]),
|
|
32
|
+
done: donePromise,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const bufferStream = (async function* () {
|
|
37
|
+
//Empty generator for non-streaming mode
|
|
38
|
+
})();
|
|
39
|
+
const bufferPromise = (async () => {
|
|
40
|
+
let buffer = [];
|
|
41
|
+
for await (const response of streamRpc(request)) {
|
|
42
|
+
if (response.type === "textToSpeech") {
|
|
43
|
+
const streamResponse = ttsResponseSchema.parse(response);
|
|
44
|
+
buffer = buffer.concat(streamResponse.buffer);
|
|
45
|
+
if (streamResponse.done) {
|
|
46
|
+
doneResolver(true);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return buffer;
|
|
51
|
+
})();
|
|
52
|
+
return {
|
|
53
|
+
bufferStream,
|
|
54
|
+
buffer: bufferPromise,
|
|
55
|
+
done: donePromise,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -6,8 +6,9 @@ import { type TranscribeClientParams } from "../../schemas/index";
|
|
|
6
6
|
* @param params - The arguments for the transcription
|
|
7
7
|
* @param params.modelId - The identifier of the transcription model to use
|
|
8
8
|
* @param params.audioChunk - Audio input as either a file path (string) or audio buffer
|
|
9
|
+
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
9
10
|
* @yields {string} Text chunks as they are transcribed
|
|
10
|
-
* @throws {
|
|
11
|
+
* @throws {QvacErrorBase} When transcription fails with an error message
|
|
11
12
|
*/
|
|
12
13
|
export declare function transcribeStream(params: TranscribeClientParams): AsyncGenerator<string, void, unknown>;
|
|
13
14
|
/**
|
|
@@ -17,8 +18,9 @@ export declare function transcribeStream(params: TranscribeClientParams): AsyncG
|
|
|
17
18
|
* @param params - The arguments for the transcription
|
|
18
19
|
* @param params.modelId - The identifier of the transcription model to use
|
|
19
20
|
* @param params.audioChunk - Audio input as either a file path (string) or audio buffer
|
|
21
|
+
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
20
22
|
* @returns {Promise<string>} The complete transcribed text
|
|
21
|
-
* @throws {
|
|
23
|
+
* @throws {QvacErrorBase} When transcription fails (propagated from transcribeStream)
|
|
22
24
|
*/
|
|
23
25
|
export declare function transcribe(params: TranscribeClientParams): Promise<string>;
|
|
24
26
|
//# sourceMappingURL=transcribe.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { transcribeStreamResponseSchema, } from "../../schemas/index.js";
|
|
2
2
|
import { stream } from "../rpc/rpc-client.js";
|
|
3
|
+
import { TranscriptionFailedError } from "../../utils/errors-client.js";
|
|
3
4
|
/**
|
|
4
5
|
* This function streams audio transcription results in real-time, yielding
|
|
5
6
|
* text chunks as they become available from the model.
|
|
@@ -7,22 +8,24 @@ import { stream } from "../rpc/rpc-client.js";
|
|
|
7
8
|
* @param params - The arguments for the transcription
|
|
8
9
|
* @param params.modelId - The identifier of the transcription model to use
|
|
9
10
|
* @param params.audioChunk - Audio input as either a file path (string) or audio buffer
|
|
11
|
+
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
10
12
|
* @yields {string} Text chunks as they are transcribed
|
|
11
|
-
* @throws {
|
|
13
|
+
* @throws {QvacErrorBase} When transcription fails with an error message
|
|
12
14
|
*/
|
|
13
15
|
export async function* transcribeStream(params) {
|
|
14
16
|
const request = {
|
|
15
17
|
type: "transcribeStream",
|
|
16
18
|
modelId: params.modelId,
|
|
17
19
|
audioChunk: typeof params.audioChunk === "string"
|
|
18
|
-
?
|
|
19
|
-
: params.audioChunk.toString("base64"),
|
|
20
|
+
? { type: "filePath", value: params.audioChunk }
|
|
21
|
+
: { type: "base64", value: params.audioChunk.toString("base64") },
|
|
22
|
+
...(params.prompt && { prompt: params.prompt }),
|
|
20
23
|
};
|
|
21
24
|
for await (const response of stream(request)) {
|
|
22
25
|
if (response.type === "transcribeStream") {
|
|
23
26
|
const streamResponse = transcribeStreamResponseSchema.parse(response);
|
|
24
27
|
if (streamResponse.error) {
|
|
25
|
-
throw new
|
|
28
|
+
throw new TranscriptionFailedError(streamResponse.error);
|
|
26
29
|
}
|
|
27
30
|
if (streamResponse.text) {
|
|
28
31
|
yield streamResponse.text;
|
|
@@ -40,8 +43,9 @@ export async function* transcribeStream(params) {
|
|
|
40
43
|
* @param params - The arguments for the transcription
|
|
41
44
|
* @param params.modelId - The identifier of the transcription model to use
|
|
42
45
|
* @param params.audioChunk - Audio input as either a file path (string) or audio buffer
|
|
46
|
+
* @param params.prompt - Optional initial prompt to guide the transcription
|
|
43
47
|
* @returns {Promise<string>} The complete transcribed text
|
|
44
|
-
* @throws {
|
|
48
|
+
* @throws {QvacErrorBase} When transcription fails (propagated from transcribeStream)
|
|
45
49
|
*/
|
|
46
50
|
export async function transcribe(params) {
|
|
47
51
|
let fullText = "";
|
|
@@ -10,7 +10,7 @@ import { type TranslateClientParams, type TranslationStats } from "../../schemas
|
|
|
10
10
|
* @param params.to - Target language code
|
|
11
11
|
* @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true.
|
|
12
12
|
* @returns Object with tokenStream generator and text/stats properties
|
|
13
|
-
* @throws {
|
|
13
|
+
* @throws {QvacErrorBase} When translation fails with an error message or when language detection fails
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
16
|
* // Streaming mode (default)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
2
2
|
import { translateResponseSchema, } from "../../schemas/index.js";
|
|
3
3
|
import { detectOne } from "@qvac/langdetect-text";
|
|
4
|
+
import { TranslationFailedError } from "../../utils/errors-client.js";
|
|
4
5
|
/**
|
|
5
6
|
* Translates text from one language to another using a specified translation model.
|
|
6
7
|
* Supports both NMT (Neural Machine Translation) and LLM models.
|
|
@@ -12,7 +13,7 @@ import { detectOne } from "@qvac/langdetect-text";
|
|
|
12
13
|
* @param params.to - Target language code
|
|
13
14
|
* @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true.
|
|
14
15
|
* @returns Object with tokenStream generator and text/stats properties
|
|
15
|
-
* @throws {
|
|
16
|
+
* @throws {QvacErrorBase} When translation fails with an error message or when language detection fails
|
|
16
17
|
* @example
|
|
17
18
|
* ```typescript
|
|
18
19
|
* // Streaming mode (default)
|
|
@@ -48,7 +49,7 @@ export function translate(params) {
|
|
|
48
49
|
if (modelType === "llm") {
|
|
49
50
|
const detected = detectOne(params.text);
|
|
50
51
|
if (detected.code === "und" || detected.language === "Undetermined") {
|
|
51
|
-
throw new
|
|
52
|
+
throw new TranslationFailedError("Could not detect the source language. Please specify the 'from' parameter explicitly.");
|
|
52
53
|
}
|
|
53
54
|
sourceLanguage = detected.language;
|
|
54
55
|
}
|
|
@@ -2,10 +2,14 @@ import { type UnloadModelParams } from "../../schemas/index";
|
|
|
2
2
|
/**
|
|
3
3
|
* Unloads a previously loaded model from the server.
|
|
4
4
|
*
|
|
5
|
+
* When the last model is unloaded (no more models remain), this function
|
|
6
|
+
* automatically closes the RPC connection, allowing the process to exit
|
|
7
|
+
* naturally without requiring manual cleanup.
|
|
8
|
+
*
|
|
5
9
|
* @param params - The parameters for unloading the model
|
|
6
10
|
* @param params.modelId - The unique identifier of the model to unload
|
|
7
11
|
* @param params.clearStorage - Whether to clear the storage for the model
|
|
8
|
-
* @throws {
|
|
12
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the unload operation fails
|
|
9
13
|
*/
|
|
10
14
|
export declare function unloadModel(params: UnloadModelParams): Promise<void>;
|
|
11
15
|
//# sourceMappingURL=unload-model.d.ts.map
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import {} from "../../schemas/index.js";
|
|
2
|
-
import { send } from "../rpc/rpc-client.js";
|
|
2
|
+
import { send, close } from "../rpc/rpc-client.js";
|
|
3
3
|
import { stopLoggingStreamForModel } from "../logging-stream-registry.js";
|
|
4
|
+
import { InvalidResponseError, ModelUnloadFailedError, } from "../../utils/errors-client.js";
|
|
4
5
|
/**
|
|
5
6
|
* Unloads a previously loaded model from the server.
|
|
6
7
|
*
|
|
8
|
+
* When the last model is unloaded (no more models remain), this function
|
|
9
|
+
* automatically closes the RPC connection, allowing the process to exit
|
|
10
|
+
* naturally without requiring manual cleanup.
|
|
11
|
+
*
|
|
7
12
|
* @param params - The parameters for unloading the model
|
|
8
13
|
* @param params.modelId - The unique identifier of the model to unload
|
|
9
14
|
* @param params.clearStorage - Whether to clear the storage for the model
|
|
10
|
-
* @throws {
|
|
15
|
+
* @throws {QvacErrorBase} When the response type is invalid or when the unload operation fails
|
|
11
16
|
*/
|
|
12
17
|
export async function unloadModel(params) {
|
|
13
18
|
const request = {
|
|
@@ -17,10 +22,15 @@ export async function unloadModel(params) {
|
|
|
17
22
|
};
|
|
18
23
|
const response = await send(request);
|
|
19
24
|
if (response.type !== "unloadModel") {
|
|
20
|
-
throw new
|
|
25
|
+
throw new InvalidResponseError("unloadModel");
|
|
21
26
|
}
|
|
22
27
|
if (!response.success) {
|
|
23
|
-
throw new
|
|
28
|
+
throw new ModelUnloadFailedError(params.modelId);
|
|
24
29
|
}
|
|
25
30
|
stopLoggingStreamForModel(params.modelId);
|
|
31
|
+
// Auto-close when no models remain AND no providers are active
|
|
32
|
+
if (!response.hasActiveModels && !response.hasActiveProviders) {
|
|
33
|
+
console.log("๐งน No models or providers active, automatically closing RPC connection...");
|
|
34
|
+
await close();
|
|
35
|
+
}
|
|
26
36
|
}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { send, stream } from "./rpc/rpc-client";
|
|
1
|
+
export { send, stream, close } from "./rpc/rpc-client";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { send, stream } from "./rpc/rpc-client.js";
|
|
1
|
+
export { send, stream, close } from "./rpc/rpc-client.js";
|